@import "../../scss/_bootstrap-extended/include";
@import "nouislider/dist/nouislider";

$noUiSlider-handle-color: var(--#{$prefix}white) !default;
$noUiSlider-handle-width: 1.375rem !default;
$noUiSlider-handle-height: 1.375rem !default;
$noUiSlider-bar-height: .375rem !default;
$noUiSlider-vertical-height: 13.125rem !default;
$noUiSlider-tick-size: .5rem !default;
$noUiSlider-tick-label-font-size: $font-size-sm !default;
$noUiSlider-line-color: var(--#{$prefix}primary-bg-subtle);
$noUiSlider-disabled-line-color: var(--#{$prefix}gray-100);
$noUiSlider-tick-label-color: var(--#{$prefix}secondary-color);


.noUi-target {
  --#{$prefix}noUi-base-color: var(--#{$prefix}primary);
  --#{$prefix}noUi-thumb-shadow: var(--#{$prefix}primary-rgb);
  --#{$prefix}popover-bg: #{$popover-bg};
  --#{$prefix}noUiSlider-line-color: #{$noUiSlider-line-color};
  position: relative;
  border-width: 0;
  background: var(--#{$prefix}noUiSlider-line-color);

  box-shadow: none;
  &,
  & * {
    box-sizing: border-box;
    touch-action: none;
    user-select: none;
  }

  /* Handles and cursors */
  .noUi-draggable {
    cursor: ew-resize;
  }

  /* Tooltips */
  .noUi-tooltip {
    position: absolute;
    display: block;
    border-color: var(--#{$prefix}border-color);
    @include border-radius(.25rem);
    background: var(--#{$prefix}base-color);
    color: var(--#{$prefix}paper-bg);
    font-size: $small-font-size;
    line-height: 1;
    padding-block: .282rem;
    padding-inline: .625rem;
    text-align: center;
    transition: transform .2s;
  }

  /* Slider size and handle placement */

  /* Horizontal layout */
  &.noUi-horizontal {
    block-size: $noUiSlider-bar-height;
    .noUi-handle.noUi-active .noUi-tooltip {
      transform: translate(-50%, 10%) scale(.8, .8);
    }
    .noUi-handle {
      block-size: $noUiSlider-handle-height;
      inline-size: $noUiSlider-handle-width;
      inset-block-start: -.5rem;
      inset-inline: auto calc(-#{$noUiSlider-handle-width} * .5);
    }
    .noUi-pips-horizontal {
      padding-block: (($noUiSlider-handle-height - $noUiSlider-bar-height) * .5 + .375rem) 0;
      padding-inline: 0;
    }
    .noUi-value-horizontal {
      padding-block-start: .125rem;
      transform: translate(-50%, 50%);

      :dir(rtl) & {
        transform: translate(50%, 50%);
      }
    }

    .noUi-marker-horizontal.noUi-marker {
      block-size: $noUiSlider-tick-size;
      inline-size: 1px;
    }
    .noUi-tooltip {
      inset-block-end: 125%;
      transform: translate(-50%, -20%);
    }
  }

  /* Vertical layout */
  &.noUi-vertical {
    inline-size: $noUiSlider-bar-height;
    .noUi-origin {
      inline-size: 0;
    }

    .noUi-handle {
      &.noUi-active .noUi-tooltip {
        transform: translate(10%, -50%) scale(.8, .8);
        :dir(rtl) & {
          transform: translate(-10%, -50%) scale(.8, .8);
        }
      }
      block-size: $noUiSlider-handle-width;
      inline-size: $noUiSlider-handle-height;
      inset-block-end: -(calc($noUiSlider-handle-height - .375rem));
      inset-inline-end: -(($noUiSlider-handle-height * .34) + .05);
      :dir(rtl) & {
        inset-inline-start: -(($noUiSlider-handle-height * .35) + .05);
      }
    }
    .noUi-draggable {
      cursor: ns-resize;
    }
    .noUi-pips-vertical {
      padding-block: 0;
      padding-inline: (($noUiSlider-handle-height - $noUiSlider-bar-height) * .5 + .375rem) 0;
    }
    .noUi-value-vertical {
      padding-inline-start: $noUiSlider-tick-size + .375rem;
    }
    .noUi-marker-vertical.noUi-marker {
      block-size: 1px;
      inline-size: $noUiSlider-tick-size;
    }
    .noUi-tooltip {
      inset-inline: auto 125%;
      transform: translate(-10%, -50%);
      :dir(rtl) & {
        transform: translate(10%, -50%);
      }
    }
  }
  .noUi-handle {
    border-width: .25rem;
    border-color: var(--#{$prefix}noUi-base-color);
    @include border-radius(var(--#{$prefix}border-radius-pill));
    backface-visibility: hidden;
    background: $noUiSlider-handle-color;
    box-shadow: 0 0 0 1px rgb(var(--#{$prefix}pure-black) / 10%), var(--#{$prefix}floating-component-shadow);
    cursor: pointer;
    outline: none;
    @include transition(all .2s);

    &::before,
    &::after {
      display: none;
    }

    &.noUi-active {
      transform: scale(1.4, 1.4);
    }
  }
  .noUi-touch-area {
    block-size: 100%;
    inline-size: 100%;
  }
  &.noUi-state-tap {
    .noUi-connect,
    .noUi-origin {
      transition:
        inset-block-start .3s,
        inset-inline-end .3s,
        inset-block-end .3s,
        inset-inline-start .3s;
    }
  }

  /* Disabled state */
  &[disabled] {
    opacity: .45;
    .noUi-handle {
      box-shadow: 0 0 0 1px rgb(var(--#{$prefix}pure-black) / 5%);
    }
  }
  &[disabled],
  [disabled].noUi-handle,
  &[disabled] .noUi-handle {
    cursor: not-allowed;
    pointer-events: none;
  }

  /* Base */
  .noUi-pips {
    position: absolute;
    color: var(--#{$prefix}secondary-color);
    &,
    & * {
      box-sizing: border-box;
    }
  }

  /* Values */
  .noUi-value {
    position: absolute;
    color: $noUiSlider-tick-label-color;
    font-size: $noUiSlider-tick-label-font-size;
    white-space: nowrap;
  }

  /* Markings */
  .noUi-marker {
    position: absolute;
    background: $noUiSlider-tick-label-color;
  }

  .noUi-base {
    .noUi-connect {
      background: var(--#{$prefix}noUi-base-color);
    }
    .noUi-handle {
      &:hover {
        box-shadow: 0 0 0 .5rem rgba(var(--#{$prefix}noUi-thumb-shadow), .16);
      }

      &:active,
      &:focus {
        box-shadow: 0 0 0 .8125rem rgba(var(--#{$prefix}noUi-thumb-shadow), .16);
      }
    }
  }
}


@each $state in map-keys($theme-colors) {
  .noUi-#{$state} {
    --#{$prefix}noUi-base-color: var(--#{$prefix}#{$state});
    --#{$prefix}noUi-thumb-shadow: var(--#{$prefix}#{$state}-rgb);
    --#{$prefix}noUiSlider-line-color: var(--#{$prefix}#{$state}-bg-subtle);
  }
}
