//
// Copyright IBM Corp. 2016, 2018
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//

//-----------------------------
// Slider
//-----------------------------

@import '../../globals/scss/vars';
@import '../../globals/scss/helper-mixins';
@import '../../globals/scss/typography';
@import '../../globals/scss/vendor/@rocketsoftware/elements/scss/import-once/import-once';
@import '../form/form';
@import '../text-input/text-input';

/// Slider styles
/// @access private
/// @group slider
@mixin slider {
  .#{$prefix}--slider-container {
    display: flex;
    align-items: center;
    user-select: none;
  }

  .#{$prefix}--slider {
    position: relative;
    width: 100%;
    min-width: rem(200px);
    max-width: rem(640px);
    margin: 0 $carbon--spacing-05;
  }

  .#{$prefix}--slider__range-label {
    @include type-style('code-02');

    color: $text-01;
    white-space: nowrap;

    &:last-of-type {
      margin-right: $carbon--spacing-05;
    }
  }

  .#{$prefix}--slider__track {
    position: absolute;
    width: 100%;
    height: rem(2px);
    background: $ui-03;
    transform: translate(0%, -50%);
    cursor: pointer;

    // Windows, Firefox HCM Fix
    @media screen and (-ms-high-contrast: active),
      screen and (prefers-contrast) {
      // `ButtonText` is a CSS2 system color to help improve colors in HCM
      border: 1px solid transparent;
    }
  }

  .#{$prefix}--slider__track:before {
    position: absolute;
    top: rem(-5px);
    left: 50%;
    display: inline-block;
    width: rem(2px);
    height: rem(4px);
    background: $ui-03;
    transform: translate(-50%, 0);
    content: '';
  }

  .#{$prefix}--slider__filled-track {
    position: absolute;
    width: 100%;
    height: rem(2px);
    background: $ui-05;
    transform: translate(0%, -50%);
    transform-origin: left;
    transition: background $duration--fast-02 motion(standard, productive);
    pointer-events: none;

    // Windows, Firefox HCM Fix
    @media screen and (-ms-high-contrast: active),
      screen and (prefers-contrast) {
      // `ButtonText` is a CSS2 system color to help improve colors in HCM
      border: 1px solid transparent;
    }
  }

  .#{$prefix}--slider__thumb {
    position: absolute;
    top: 0;
    z-index: 3;
    width: rem(14px);
    height: rem(14px);
    background: $ui-05;
    border-radius: 50%;
    outline: none;
    box-shadow: inset 0 0 0 1px transparent, inset 0 0 0 2px transparent;
    transform: translate(-50%, -50%);
    cursor: pointer;
    transition: transform $duration--fast-02 motion(standard, productive),
      background $duration--fast-02 motion(standard, productive),
      box-shadow $duration--fast-02 motion(standard, productive);

    &:hover {
      // 20px / 14px = 1.4286
      transform: translate(-50%, -50%) scale(1.4286);
    }

    &:focus {
      background-color: $interactive-04;
      box-shadow: inset 0 0 0 2px $interactive-04, inset 0 0 0 3px $ui-01;
      // 20px / 14px = 1.4286
      transform: translate(-50%, -50%) scale(1.4286);

      // Firefox HCM Fix
      @media screen and (prefers-contrast) {
        outline-style: dotted;
      }
    }

    &:active {
      box-shadow: inset 0 0 0 2px $interactive-04;
      transform: translate(-50%, -50%) scale(1.4286);
    }

    // Windows, Firefox HCM Fix
    @media screen and (-ms-high-contrast: active),
      screen and (prefers-contrast) {
      // `ButtonText` is a CSS2 system color to help improve colors in HCM
      outline: 1px solid ButtonText;
    }
  }

  .#{$prefix}--slider__input {
    display: none;
  }

  .#{$prefix}--slider-text-input,
  .#{$prefix}-slider-text-input {
    width: rem(64px);
    height: rem(40px);
    text-align: center;
    -moz-appearance: textfield;

    &::-webkit-outer-spin-button,
    &::-webkit-inner-spin-button {
      display: none;
    }
  }

  .#{$prefix}--slider__thumb:focus ~ .#{$prefix}--slider__filled-track {
    background-color: $interactive-04;
  }

  // Disabled state
  .#{$prefix}--label--disabled
    ~ .#{$prefix}--slider-container
    > .#{$prefix}--slider__range-label {
    color: $disabled-02;
  }

  .#{$prefix}--slider--disabled .#{$prefix}--slider__thumb {
    background-color: $ui-03;

    &:hover {
      transform: translate(-50%, -50%);
      cursor: not-allowed;
    }

    &:focus {
      background-color: $ui-03;
      outline: none;
      box-shadow: none;
      transform: translate(-50%, -50%);
    }

    &:active {
      background: $ui-03;
      transform: translate(-50%, -50%);
    }
  }

  .#{$prefix}--slider--disabled .#{$prefix}--slider__track,
  .#{$prefix}--slider--disabled .#{$prefix}--slider__filled-track,
  .#{$prefix}--slider--disabled
    .#{$prefix}--slider__thumb:focus
    ~ .#{$prefix}--slider__filled-track {
    background-color: $ui-03;
    cursor: not-allowed;
  }

  .#{$prefix}--slider--disabled
    ~ .#{$prefix}--form-item
    .#{$prefix}--slider-text-input,
  .#{$prefix}--slider--disabled ~ .#{$prefix}--slider-text-input {
    color: $disabled-02;
    background-color: $disabled-01;
    border: none;
    cursor: not-allowed;
    transition: none;

    &:active,
    &:focus,
    &:hover {
      color: $disabled-02;
      outline: none;
    }
  }

  // Skeleton state
  .#{$prefix}--slider-container.#{$prefix}--skeleton
    .#{$prefix}--slider__range-label {
    @include skeleton;

    width: rem(20px);
    height: rem(12px);
  }

  .#{$prefix}--slider-container.#{$prefix}--skeleton
    .#{$prefix}--slider__track {
    cursor: default;
    pointer-events: none;
  }

  .#{$prefix}--slider-container.#{$prefix}--skeleton
    .#{$prefix}--slider__thumb {
    left: 50%;
    cursor: default;
    pointer-events: none;
  }
}

@include exports('slider') {
  @include slider;
}
