@import "../../../theme/global";

$slider-height:                    3rem !default;
$slider-width:                     $slider-height * 4 !default;
$slider-track-height:              0.5rem !default;
$slider-border-radius:             $slider-height / 2 !default;
$slider-handle-width:              2.4rem !default;
$slider-handle-height:             2.4rem !default;

:host {
  box-sizing: content-box !important;
  width: 100%; /* Full-width */
  text-align: center;
  padding: 1rem 0;
}
:host(:focus) {
  outline: none;
}
:host(.lar-slider-disabled) {
  pointer-events: none;
  opacity: 0.3;
  filter: grayscale(0.4);
}

:host(.lar-slider-vertical) input {
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
  margin-top: $slider-width/2 - $slider-handle-width/2;
}
input {
  display: inline-block;
  box-sizing: content-box !important;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  background: transparent;
  width: $slider-width;
  height: $slider-handle-height;
  padding: 0;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

// Track styles - WebKit
input::-webkit-slider-runnable-track {
  width: 100%;
  height: $slider-track-height;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.08);
  border-radius: calc(#{$slider-track-height} / 2);
  box-shadow:
    inset 0 1px 2px rgba(0, 0, 0, 0.1),
    0 1px 0 rgba(255, 255, 255, 0.05);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

// Track styles - Firefox
input::-moz-range-track {
  width: 100%;
  height: $slider-track-height;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.08);
  border-radius: calc(#{$slider-track-height} / 2);
  box-shadow:
    inset 0 1px 2px rgba(0, 0, 0, 0.1),
    0 1px 0 rgba(255, 255, 255, 0.05);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

// Thumb styles - WebKit
input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: $slider-handle-width;
  height: $slider-handle-height;
  margin-top: calc((#{$slider-track-height} - #{$slider-handle-height}) / 2);
  cursor: grab;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.9);
  background: $background-color;
  box-shadow:
    0 2px 8px -1px rgba(0, 0, 0, 0.15),
    0 4px 16px -2px rgba(0, 0, 0, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.5),
    inset 0 -1px 2px rgba(0, 0, 0, 0.1);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

input::-webkit-slider-thumb:hover {
  transform: scale(1.1);
  box-shadow:
    0 4px 12px -1px rgba(0, 0, 0, 0.2),
    0 6px 20px -2px rgba(0, 0, 0, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.6),
    inset 0 -1px 2px rgba(0, 0, 0, 0.12);
}

input::-webkit-slider-thumb:active {
  cursor: grabbing;
  transform: scale(1.05);
  box-shadow:
    0 2px 6px -1px rgba(0, 0, 0, 0.12),
    0 3px 12px -2px rgba(0, 0, 0, 0.08),
    inset 0 1px 3px rgba(0, 0, 0, 0.15);
}

// Thumb styles - Firefox
input::-moz-range-thumb {
  width: $slider-handle-width;
  height: $slider-handle-height;
  cursor: grab;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.9);
  background: $background-color;
  box-shadow:
    0 2px 8px -1px rgba(0, 0, 0, 0.15),
    0 4px 16px -2px rgba(0, 0, 0, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.5),
    inset 0 -1px 2px rgba(0, 0, 0, 0.1);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

input::-moz-range-thumb:hover {
  transform: scale(1.1);
  box-shadow:
    0 4px 12px -1px rgba(0, 0, 0, 0.2),
    0 6px 20px -2px rgba(0, 0, 0, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.6),
    inset 0 -1px 2px rgba(0, 0, 0, 0.12);
}

input::-moz-range-thumb:active {
  cursor: grabbing;
  transform: scale(1.05);
  box-shadow:
    0 2px 6px -1px rgba(0, 0, 0, 0.12),
    0 3px 12px -2px rgba(0, 0, 0, 0.08),
    inset 0 1px 3px rgba(0, 0, 0, 0.15);
}

@mixin generate-slider-color($color-name) {
  $value: map-get($colors, $color-name);
  $base: map-get($value, base);
  $base-rgb: color-to-rgb-list($base);

  // Track with gradient fill
  :host(.lar-color-#{$color-name}) input::-webkit-slider-runnable-track {
    background: linear-gradient(
      to right,
      lar-color($color-name, base),
      lar-color($color-name, tint) 50%,
      rgba(0, 0, 0, 0.08)
    );
    box-shadow:
      inset 0 1px 3px rgba(0, 0, 0, 0.15),
      0 1px 0 rgba(255, 255, 255, 0.1);
  }

  :host(.lar-color-#{$color-name}) input::-moz-range-track {
    background: linear-gradient(
      to right,
      lar-color($color-name, base),
      lar-color($color-name, tint) 50%,
      rgba(0, 0, 0, 0.08)
    );
    box-shadow:
      inset 0 1px 3px rgba(0, 0, 0, 0.15),
      0 1px 0 rgba(255, 255, 255, 0.1);
  }

  // Thumb with color indicator
  :host(.lar-color-#{$color-name}) input::-webkit-slider-thumb {
    border-color: lar-color($color-name, base);
    box-shadow:
      0 0 0 3px rgba(var(--lar-color-#{$color-name}-rgb, #{$base-rgb}), 0.2),
      0 2px 8px -1px rgba(var(--lar-color-#{$color-name}-rgb, #{$base-rgb}), 0.3),
      0 4px 16px -2px rgba(var(--lar-color-#{$color-name}-rgb, #{$base-rgb}), 0.2),
      inset 0 1px 0 rgba(255, 255, 255, 0.5),
      inset 0 -1px 2px rgba(0, 0, 0, 0.1);
  }

  :host(.lar-color-#{$color-name}) input::-webkit-slider-thumb:hover {
    border-color: lar-color($color-name, shade);
    box-shadow:
      0 0 0 4px rgba(var(--lar-color-#{$color-name}-rgb, #{$base-rgb}), 0.25),
      0 4px 12px -1px rgba(var(--lar-color-#{$color-name}-rgb, #{$base-rgb}), 0.4),
      0 6px 20px -2px rgba(var(--lar-color-#{$color-name}-rgb, #{$base-rgb}), 0.3),
      inset 0 1px 0 rgba(255, 255, 255, 0.6),
      inset 0 -1px 2px rgba(0, 0, 0, 0.12);
  }

  :host(.lar-color-#{$color-name}) input::-webkit-slider-thumb:active {
    border-color: lar-color($color-name, shade);
    box-shadow:
      0 0 0 2px rgba(var(--lar-color-#{$color-name}-rgb, #{$base-rgb}), 0.3),
      0 2px 6px -1px rgba(var(--lar-color-#{$color-name}-rgb, #{$base-rgb}), 0.35),
      0 3px 12px -2px rgba(var(--lar-color-#{$color-name}-rgb, #{$base-rgb}), 0.25),
      inset 0 1px 3px rgba(0, 0, 0, 0.15);
  }

  :host(.lar-color-#{$color-name}) input::-moz-range-thumb {
    border-color: lar-color($color-name, base);
    box-shadow:
      0 0 0 3px rgba(var(--lar-color-#{$color-name}-rgb, #{$base-rgb}), 0.2),
      0 2px 8px -1px rgba(var(--lar-color-#{$color-name}-rgb, #{$base-rgb}), 0.3),
      0 4px 16px -2px rgba(var(--lar-color-#{$color-name}-rgb, #{$base-rgb}), 0.2),
      inset 0 1px 0 rgba(255, 255, 255, 0.5),
      inset 0 -1px 2px rgba(0, 0, 0, 0.1);
  }

  :host(.lar-color-#{$color-name}) input::-moz-range-thumb:hover {
    border-color: lar-color($color-name, shade);
    box-shadow:
      0 0 0 4px rgba(var(--lar-color-#{$color-name}-rgb, #{$base-rgb}), 0.25),
      0 4px 12px -1px rgba(var(--lar-color-#{$color-name}-rgb, #{$base-rgb}), 0.4),
      0 6px 20px -2px rgba(var(--lar-color-#{$color-name}-rgb, #{$base-rgb}), 0.3),
      inset 0 1px 0 rgba(255, 255, 255, 0.6),
      inset 0 -1px 2px rgba(0, 0, 0, 0.12);
  }

  :host(.lar-color-#{$color-name}) input::-moz-range-thumb:active {
    border-color: lar-color($color-name, shade);
    box-shadow:
      0 0 0 2px rgba(var(--lar-color-#{$color-name}-rgb, #{$base-rgb}), 0.3),
      0 2px 6px -1px rgba(var(--lar-color-#{$color-name}-rgb, #{$base-rgb}), 0.35),
      0 3px 12px -2px rgba(var(--lar-color-#{$color-name}-rgb, #{$base-rgb}), 0.25),
      inset 0 1px 3px rgba(0, 0, 0, 0.15);
  }
}

@each $color-name, $value in $colors {
   @include generate-slider-color($color-name);
}
