@import "../common/typography/text.mixins.scss";

$switch-width: 36px !default;
$switch-height: 24px !default;
$switch-bar-height: 14px !default;
$switch-thumb-size: 20px !default;
@mixin novo-switch-style($thumb, $track) {
  // Can make the checked version style different (same for now)
  &[aria-checked="true"] {
    .novo-switch-thumb {
      background-color: $thumb;
    }
    .novo-switch-bar {
      background-color: $track;
    }
  }
}

:host {
  display: flex;
  align-items: center;
  // margin: 15px;
  white-space: nowrap;
  cursor: pointer;
  outline: none;
  user-select: none;
  @include ease("all", "swift-ease-in-out");
  * {
    box-sizing: border-box;
  }
  > div {
    display: flex;
    align-items: center;
  }
  .novo-switch-container {
    cursor: grab;
    width: $switch-width;
    height: $switch-height;
    position: relative;
    user-select: none;
    margin: 0 8px;
  }
  &:not(.novo-switch-disabled) {
    &.novo-switch-dragging .novo-switch-container,
    .novo-switch-dragging {
      cursor: grabbing;
    }
  }
  .novo-switch-label {
    border: 0 transparent;
  }
  .novo-switch-bar {
    left: 1px;
    width: $switch-width - 2px;
    top: calc($switch-height / 2) - calc($switch-bar-height / 2);
    height: $switch-bar-height;
    border-radius: 8px;
    position: absolute;
  }
  .novo-switch-thumb-container {
    top: calc($switch-height / 2) - calc($switch-thumb-size / 2);
    left: 0;
    width: $switch-width - $switch-thumb-size;
    position: absolute;
    transform: translate3d(0, 0, 0);
    z-index: z(default);
  }
  &[aria-checked="true"] .novo-switch-thumb-container {
    transform: translate3d(100%, 0, 0);
  }
  .novo-switch-thumb {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    left: 0;
    top: 0;
    outline: none;
    height: $switch-thumb-size;
    width: $switch-thumb-size;
    border-radius: 50%;
    box-shadow: $shadow-1; // todo
    color: getContrastColor("light");

    .novo-icon {
      color: inherit;
    }
  }
  &:not(.novo-switch-dragging) {
    .novo-switch-bar,
    .novo-switch-thumb,
    .novo-switch-thumb-container {
      @include ease("all", "swift-ease-in-out");
      transition-property: transform, background-color, color;
    }
    .novo-switch-bar,
    .novo-switch-thumb {
      transition-delay: 0.05s;
    }
  }
  &.novo-switch-disabled {
    opacity: 0.4;
    cursor: not-allowed;
    .novo-switch-container {
      cursor: not-allowed;
      pointer-events: none;
    }
  }

  // Base color: $ocean
  // @include novo-switch-style($ocean, lighten($ocean, 18%));
  // Loop through analytics colors and make a switch color class for each
  @include theme-colors() using ($name, $color, $contrast, $tint, $shade, $pale) {
    &.#{$name} {
      @include novo-switch-style($color, lighten($color, 18%));
      &[aria-checked="true"] {
        .novo-switch-thumb {
          color: getContrastColor($name);
        }
      }
    }
  }

  &.dark {
    @include novo-switch-style($dark, darken($dark, 5%));
  }
  &.light {
    @include novo-switch-style(darken($light, 3%), $light);
  }

  .novo-switch-thumb {
    background-color: $light;
  }
  .novo-switch-bar {
    background-color: lighten($light, 10%);
  }

  &:focus {
    .novo-switch-label:not(:empty) {
      border: 1px dotted $light;
    }
  }
}
