@import "../../core/style/variables";

// TODO(jelbourn): This goes away.
@import "../../core/style/default-theme";

$switch-width: 36px !default;
$switch-height: $baseline-grid * 3 !default;
$switch-bar-height: 14px !default;
$switch-thumb-size: 20px !default;

md-switch {
  display: flex;
  align-items: center;

  margin: 15px;
  white-space: nowrap;
  cursor: pointer;
  outline: none;
  user-select: none;

  * {
    box-sizing: border-box;
  }

  .md-switch-container {
    cursor: grab;
    width: $switch-width;
    height: $switch-height;
    position: relative;
    user-select: none;
    margin-right: 8px;
  }

  // If the user moves his mouse off the switch, stil display grabbing cursor
  &:not([disabled]) {
    .md-switch-dragging,
    &.md-switch-dragging .md-switch-container {
      cursor: grabbing;
    }
  }

  .md-switch-label {
    border: 0 transparent;
  }

  .md-switch-bar {
    left: 1px;
    width: $switch-width - 2px;
    top: $switch-height / 2 - $switch-bar-height / 2;
    height: $switch-bar-height;
    border-radius: 8px;
    position: absolute;
  }

  .md-switch-thumb-container {
    top: $switch-height / 2 - $switch-thumb-size / 2;
    left: 0;
    width: $switch-width - $switch-thumb-size;
    position: absolute;
    transform: translate3d(0,0,0);
    z-index: 1;
  }

  &[aria-checked="true"] .md-switch-thumb-container {
    transform: translate3d(100%, 0, 0);
  }

  .md-switch-thumb {
    position: absolute;
    margin: 0;
    left: 0;
    top: 0;
    outline: none;
    height: $switch-thumb-size;
    width: $switch-thumb-size;
    border-radius: 50%;
    box-shadow: $whiteframe-shadow-z1;

    // todo
    .md-ripple-container {
      position: absolute;
      display: block;
      width: auto;
      height: auto;
      left: -$switch-thumb-size;
      top: -$switch-thumb-size;
      right: -$switch-thumb-size;
      bottom: -$switch-thumb-size;
    }
  }

  &:not(.md-switch-dragging) {
    .md-switch-bar,
    .md-switch-thumb-container,
    .md-switch-thumb {
      transition: $swift-ease-in-out;
      transition-property: transform, background-color;
    }
    .md-switch-bar,
    .md-switch-thumb {
      transition-delay: 0.05s;
    }
  }

}

// TODO(jelbourn): Why are these not defined in terms of the theme?
@media screen and (-ms-high-contrast: active) {
  md-switch .md-switch-bar {
    background-color: #666;
  }
  md-switch[aria-checked="true"] .md-switch-bar {
    background-color: #9E9E9E;
  }
  md-switch.md-default-theme .md-switch-thumb {
    background-color: #fff;
  }
}


// THEME

md-switch {
  .md-switch-thumb {
    background-color: md-color($md-background, 50);
  }
  .md-switch-bar {
    background-color: md-color($md-background, 500);
  }

  &[aria-checked="true"] {
    .md-switch-thumb {
      background-color: md-color($md-accent);
    }
    .md-switch-bar {
      background-color: md-color($md-accent, 0.5);
    }

    &.md-primary {
      .md-switch-thumb {
        background-color: md-color($md-primary);
      }
      .md-switch-bar {
        background-color: md-color($md-primary, 0.5);
      }
    }

    &.md-warn {
      .md-switch-thumb {
        background-color: md-color($md-warn);
      }
      .md-switch-bar {
        background-color: md-color($md-warn, 0.5);
      }
    }
  }

  &[disabled] {
    .md-switch-thumb {
      background-color: md-color($md-background, 400);
    }
    .md-switch-bar {
      background-color: md-color($md-foreground, divider);
    }
  }

  &:focus {
    .md-switch-label:not(:empty) {
      border: 1px dotted md-color($md-foreground, text);
    }
  }
}
