@import '../scss/init.scss';

// https://css-tricks.com/styling-cross-browser-compatible-range-inputs-css/
@mixin resetRangeInput() {
  -webkit-appearance: none; /* Hides the slider so that custom slider can be made */
  width: 100%; /* Specific width is required for Firefox. */
  background: transparent; /* Otherwise white in Chrome */
  &:focus {
    outline: none;
  }
  &::-webkit-slider-thumb {
    -webkit-appearance: none;
  }
  &::-ms-track {
    width: 100%;
    cursor: pointer;
    /* Hides the slider so custom styles can be added */
    background: transparent;
    border-color: transparent;
    color: transparent;
  }
  &::-ms-tooltip {
    display: none;
  }
  &::-moz-range-track {
    visibility: hidden;
  }
  &::-moz-range-thumb {
    border: none;
  }
}

@mixin styleRangeInputThumb() {
  &::-webkit-slider-thumb { @content; }
  &::-moz-range-thumb { @content; }
  &::-ms-thumb { @content; }
}

.rangeInput {
  // Thumb position and thumb width are relative.
  // If we change thumb width, we have to change javascript too.
  $thumbWidth: 28px;
  -webkit-tap-highlight-colo: transparent;

  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;

  &_input {
    position: absolute;
    z-index: 3;
    @include resetRangeInput;
    @include styleRangeInputThumb {
      @include circle($thumbWidth/2);
      background-color: $c_primary;
      border: $thumbWidth/4 solid lighten($c_primary, 40%);
      box-sizing: content-box;
    };
  }

  &_track {
    height: 4px;
    position: relative;

    &_front, &_bg, &_marks {
      width: 100%;
      height: 100%;
      position: absolute;
      top: 0;
      left: 0;
    }

    &_marks {
      z-index: 2;
    }

    &_front {
      background-color: $c_primary;
      width: 100%;
      transform: scaleX(0);
      transform-origin: 0 0;
      z-index: 1;
    }

    &_bg {
      background-color: $grey-300;
    }
  }

  &_tooltip {
    width: 32px;
    height: 32px;
    margin-left: -32px/2 + $thumbWidth/2;
    position: absolute;
    z-index: 2;
    visibility: hidden;
    &_content {
      display: none;
    }
  }

  &_input:active ~ &_tooltip {
    visibility: visible;
  }
}

.rangeInput--circle {
  .rangeInput_tooltip_content {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background-color: rgba($c_primary, 0.5);
    transform: scale(0);
    transition: transform 225ms;
  }

  .rangeInput_input:active ~ .rangeInput_tooltip .rangeInput_tooltip_content {
    transform: scale(1);
  }
}

.rangeInput--bubble {
  .rangeInput_tooltip {
    bottom: 20px;
  }

  .rangeInput_tooltip_content {
    position: absolute;
    width: 100%;
    height: 100%;
    @include center;

    color: white;
    font-size: $s_font_caption;
    -moz-user-select: none;
    -webkit-user-select: none;
    -ms-user-select: none;

    opacity: 0;
    transform: scale(0);
    transform-origin: 50% 100%;
    transition-duration: 125ms;

    &::after {
      content: '';
      position: absolute;
      z-index: -1;
      width: 100%;
      height: 100%;
      top: 0;
      left: 0;
      background-color: $c_primary;
      border-radius: 50% 50% 50% 0;
      transform: rotate(-45deg);
    }
  }

  .rangeInput_input:active ~ .rangeInput_tooltip .rangeInput_tooltip_content {
    opacity: 1;
    transform: scale(1);
  }
}

.rangeInput_input[disabled] ~ .rangeInput_track_front {
  background-color: $grey-300;
}

.rangeInput_input[disabled] {
  cursor: not-allowed;
  @include styleRangeInputThumb {
    background-color: $grey-300;
  };
}
