@use 'sass:map';

@use 'mixins/mixins' as *;
@use 'mixins/utils' as *;
@use 'mixins/var' as *;
@use 'common/var' as *;

$slider-height: () !default;
$slider-height: map.merge(
  (
    'large': 24px,
    'default': 20px,
    'small': 16px,
  ),
  $slider-height
);

$slider: () !default;
$slider: map.merge(
  (
    'main-bg-color': getCssVar('color-primary'),
    'runway-bg-color': getCssVar('color-neutral-3'),
    'stop-bg-color': getCssVar('color-white'),
    'disabled-color': getCssVar('color-neutral-5'),
    'border-radius': 4px,
    'height': 4px,
    'button-size': 16px,
    'button-wrapper-size': 24px,
    'button-wrapper-offset': -12px,
  ),
  $slider
);

@include b(slider) {
  @include set-component-css-var('slider', $slider);
}

@include b(slider) {
  width: 100%;
  height: map.get($slider-height, 'default');
  display: flex;
  align-items: center;

  @include e(runway) {
    flex: 1;
    height: 4px;
    background-color: getCssVar('slider-runway-bg-color');
    border-radius: getCssVar('slider-border-radius');
    position: relative;
    cursor: pointer;

    &.show-input {
      margin-right: 16px;
      width: auto;
    }

    &.is-disabled {
      cursor: default;
      opacity: 0.5;

      .#{$namespace}-slider__bar {
        background-color: getCssVar('slider-disabled-color');
      }

      .#{$namespace}-slider__button {
        background-color: getCssVar('slider-disabled-color');
      }

      .#{$namespace}-slider__button-wrapper {
        &:hover,
        &.hover {
          cursor: not-allowed;
        }

        &.dragging {
          cursor: not-allowed;
        }
      }

      .#{$namespace}-slider__button {
        &:hover,
        &.hover,
        &.dragging {
          transform: scale(1);
        }

        &:hover,
        &.hover {
          cursor: not-allowed;
        }

        &.dragging {
          cursor: not-allowed;
        }
      }
    }
  }

  @include e(input) {
    flex-shrink: 0;
    width: 128px;
  }

  @include e(bar) {
    height: 4px;
    background-color: getCssVar('slider-main-bg-color');
    border-top-left-radius: getCssVar('slider-border-radius');
    border-bottom-left-radius: getCssVar('slider-border-radius');
    position: absolute;
  }

  @include e(button-wrapper) {
    height: map.get($slider-height, 'default');
    width: map.get($slider-height, 'default');
    position: absolute;
    z-index: 1;
    top: map.get($slider-height, 'default') * -0.5 + 2px;
    transform: translateX(-50%);
    background-color: transparent;
    text-align: center;
    user-select: none;
    line-height: normal;
    outline: none;
    @include utils-vertical-center;

    &:hover,
    &.hover {
      cursor: grab;
    }

    &.dragging {
      cursor: grabbing;
    }
  }

  @include e(button) {
    display: block;
    width: map.get($slider-height, 'default');
    height: map.get($slider-height, 'default');
    vertical-align: middle;
    background-color: getCssVar('color-primary');
    border-radius: 50%;
    box-sizing: border-box;
    transition: getCssVar('transition-duration-fast');
    user-select: none;

    &:hover,
    &.hover,
    &.dragging {
      transform: scale(1.2);
    }

    &:hover,
    &.hover {
      cursor: grab;
    }

    &.dragging {
      cursor: grabbing;
    }
  }

  @include e(stop) {
    position: absolute;
    height: 4px;
    width: 4px;
    border-radius: getCssVar('border-radius-sm');
    background-color: getCssVar('slider-stop-bg-color');
    transform: translateX(-50%);
  }

  @include e(marks) {
    top: 0;
    left: 12px;
    width: 18px;
    height: 100%;

    @include e(marks-text) {
      position: absolute;
      transform: translateX(-50%);
      font-size: 14px;
      color: getCssVar('color-neutral-7');
      margin-top: 15px;
    }
  }

  @include when(vertical) {
    flex-direction: column;
    width: 4px;

    .#{$namespace}-slider__runway {
      width: 4px;
      height: 100%;
      margin: 0 16px;
    }
    .#{$namespace}-slider__bar {
      width: 4px;
      height: auto;
      border-radius: 0 0 4px 4px;
    }
    .#{$namespace}-slider__button-wrapper {
      top: auto;
      left: map.get($slider-height, 'default') * -0.5 + 2px;
      transform: translateY(50%);
    }
    .#{$namespace}-slider__stop {
      transform: translateY(50%);
    }

    @include e(marks-text) {
      margin-top: 0;
      left: 16px;
      transform: translateY(50%);
    }

    @each $size in (large, small) {
      @include m($size) {
        @include e(button-wrapper) {
          left: map.get($slider-height, $size) * -0.5 + 2px;
        }
      }
    }
  }

  @each $size in (large, small) {
    @include m($size) {
      height: map.get($slider-height, $size);

      @include e(button-wrapper) {
        height: map.get($slider-height, $size);
        width: map.get($slider-height, $size);
        top: map.get($slider-height, $size) * -0.5 + 2px;
      }

      @include e(button) {
        width: map.get($slider-height, $size);
        height: map.get($slider-height, $size);
      }
    }
  }

  @include m(with-input) {
    height: auto;
  }
}
