// Importar as variáveis de cor do sistema
@import "../tokens/color-tokens";

@mixin matcha-slider-theme($theme) {
  $color-functions: (
    red: getRed,
    pink: getPink,
    purple: getPurple,
    deep-purple: getDeepPurple,
    indigo: getIndigo,
    blue: getBlue,
    light-blue: getLightBlue,
    cyan: getCyan,
    teal: getTeal,
    green: getGreen,
    light-green: getLightGreen,
    lime: getLime,
    yellow: getYellow,
    amber: getAmber,
    orange: getOrange,
    deep-orange: getDeepOrange,
    brown: getBrown,
    grey: getGrey,
    blue-grey: getBlueGrey,
    primary: getPrimary,
    accent: getAccent,
    success: getSuccess,
    warn: getWarn,
    danger: getDanger,
    info: getInfo,
    disabled: getDisabled,
  );

.matcha-slider {

  // Default accent color
  &[data-color="accent"] {
    .selection-bar {
      background-color: getAccent($theme);
    }

    .pointer {
      background-color: getAccent($theme);

      &.focused {
        box-shadow: 0 0 0 4px getAccent($theme);
      }

      &:hover {
        box-shadow: 0 0 0 4px rgba(getAccent($theme), 0.24);
      }

      &:active {
        box-shadow: 0 0 0 4px rgba(getAccent($theme), 0.24);
      }
    }
  }

  .slider-track {
    background-color: getDisabled($theme);
  }

  // Dynamic colors
  @each $colorName, $colorFn in $color-functions {
    &[data-color="#{'' + $colorName}"] {
      .selection-bar {
        background-color: call(#{$colorFn}, $theme);
      }

      .pointer {
        background-color: call(#{$colorFn}, $theme);

        &.focused {
          box-shadow: 0 0 0 4px call(#{$colorFn}, $theme);
        }

        &:hover {
          box-shadow: 0 0 0 4px rgba(call(#{$colorFn}, $theme), 0.24);
        }

        &:active {
          box-shadow: 0 0 0 4px rgba(call(#{$colorFn}, $theme), 0.24);
        }
      }
    }
  }

  // Disabled state
  &.disabled {
    background-color: transparent !important;

    .selection-bar {
      background-color: getDisabled($theme);
    }

    .pointer {
      background-color: getDisabled($theme);
    }

    .tick-value,
    .pointer-label,
    .floor-label,
    .ceil-label {
      color: getDisabled($theme);
    }
  }
}
}

.matcha-slider {
  position: relative;
  width: 100%;
  padding: 20px 0;
  user-select: none;
  background-color: transparent; // Sempre transparente por padrão

  .slider-track {
    position: relative;
    height: 4px;
    border-radius: 2px;
    cursor: pointer;
    margin: 0 10px;
  }

  .selection-bar {
    position: absolute;
    height: 100%;
    background-color: var(--color-accent);
    border-radius: 2px;
    transition: all 0.2s ease;
  }

  .pointer {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 32px;
    height: 32px;
    background-color: var(--color-accent);
    border-radius: 50%;
    cursor: grab;
    border: 4px solid var(--color-bg);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);

    &:hover {
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1), 0 0 0 2px rgba(var(--color-accent-rgb), 0.24);
    }

    &:active {
      cursor: grabbing;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1), 0 0 0 2px rgba(var(--color-accent-rgb), 0.24);
    }

    &:focus {
      outline: none;
      box-shadow: 0 0 0 2px var(--color-accent);
    }

    &.focused {
      box-shadow: 0 0 0 2px var(--color-accent);
    }
  }

  .pointer-label {
    position: absolute;
    top: -24px;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--color-surface);
    color: var(--color-fg);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 16px;
    font-weight: 400;
    white-space: nowrap;
  }

  .tick {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);

    .tick-value {
      position: absolute;
      top: 15px;
      left: 50%;
      transform: translateX(-50%);
      font-size: 16px;
      color: var(--color-fg-muted);
      white-space: nowrap;
    }
  }

  .limit-labels {
    display: flex;
    justify-content: space-between;
    margin: 8px 10px 0;
    top: -18px;
    position: relative;
    font-size: 16px;
    color: var(--color-fg-muted);

    .color-placeholder {
      color: var(--color-fg-muted);
    }
  }

  // Disabled state
  &.disabled {
    opacity: 0.6;
    pointer-events: none;
    background-color: transparent !important; // Força background transparente

    .slider-track {
      cursor: not-allowed;
      background-color: $color-base-blue-grey-100; // #E2E7E9
    }

    .pointer {
      cursor: not-allowed;
    }
  }

  // Range specific styles
  &.range {
    .pointer {
      &.low-pointer {
        z-index: 2;
      }

      &.high-pointer {
        z-index: 1;
      }
    }
  }

  // Dragging state
  &.dragging {
    .pointer {
      cursor: grabbing !important;
      transform: translate(-50%, -50%) scale(1.1);
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    }

    .selection-bar {
      transition: none;
      background-color: $color-base-blue-grey-300;
    }
  }


  // Focus styles for accessibility
  .pointer:focus-visible {
    outline-offset: 2px;
  }

  // High contrast mode support
  @media (prefers-contrast: high) {
    .pointer {
      border-width: 3px;
    }

    .selection-bar {
      border: 1px solid var(--color-fg);
    }
  }

  // Reduced motion support
  @media (prefers-reduced-motion: reduce) {

    .pointer,
    .selection-bar {
      transition: none;
    }
  }
}