@use "../../styles/mixins";

@mixin thumb-styles() {
  cursor: var(--custom-cursor, pointer);

  transform: scale(1);

  width: 0.75rem;
  height: 0.75rem;
  border: none;
  border-radius: 50%;

  background: var(--slider-color);

  transition: transform 0.25s ease-in-out;

  &:hover {
    transform: scale(1.2);
  }
}

.RangeSlider {
  --slider-color: var(--color-primary);

  margin: 0.5rem 0 0;
  margin-inline-start: 1rem;
  margin-inline-end: 1rem;

  &.disabled {
    --slider-color: var(--color-text-secondary);

    pointer-events: none;
  }

  &.readOnly {
    pointer-events: none;
  }

  .slider-top-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.625rem;

    .value-min,
    .value-max,
    .value {
      flex-shrink: 0;
      margin-left: 1rem;
      color: var(--color-text-secondary);
    }

    .value-min,
    .value-max {
      margin-left: 0;
    }

    &[dir="rtl"] {
      .value {
        margin-right: 1rem;
        margin-left: 0;
      }
    }
  }

  .slider-main {
    position: relative;
    z-index: 1;

    &::before {
      content: "";

      position: absolute;
      z-index: -1;
      top: 0.3125rem;
      left: 0;

      width: 100%;
      height: 0.125rem;
      border-radius: 0.125rem;

      opacity: 0.5;
      background-color: var(--color-borders);
    }
  }

  .slider-fill-track {
    pointer-events: none;

    position: absolute;
    top: 0.3125rem;
    left: 0;

    width: 100%;
    height: 0.125rem;
    border-radius: 0.125rem;

    background-color: var(--slider-color);
  }

  &.bold {
    .slider-main::before {
      top: 0.25rem;
      height: 0.25rem;
    }

    .slider-fill-track {
      top: 0.25rem;
      height: 0.25rem;
    }
  }

  // Reset range input browser styles
  @include mixins.reset-range();

  // Apply custom styles
  input[type="range"] {
    // Note that while we're repeating code here, that's
    // necessary as you can't comma-separate these type of selectors.
    // Browsers will drop the entire selector if it doesn't understand a part of it.
    &::-webkit-slider-thumb {
      @include thumb-styles();
    }

    &::-moz-range-thumb {
      @include thumb-styles();
    }

    &::-ms-thumb {
      @include thumb-styles();
    }
  }

  .slider-options {
    display: grid;
    grid-auto-columns: 1fr;
    grid-auto-flow: column;
    grid-template-rows: auto;
  }

  .slider-option {
    cursor: var(--custom-cursor, pointer);

    font-size: 0.8125rem;
    color: var(--color-text-secondary);
    text-align: center;

    transition: color 0.2s ease;

    &:hover,
    &.active {
      color: var(--color-text);
    }

    &.active {
      font-weight: var(--font-weight-medium);
    }

    &:first-child {
      text-align: left;
    }

    &:last-child {
      text-align: right;
    }
  }
}
