@function sui_form_range_make_long_shadow($color, $size) {
  $val:  $sui-a-form-range-track-height 0 0 $size $color;

  @for $i from 0 through 600 {
    $val: #{$val}, rem($i) 0 0 $size #{$color};
  }

  @return inset 0 0 0 rem(3) white, $val;
}

@function sui_form_range_thumb_focus($color) {
  @return 0 0 0 rem(2) rgba($color, .25);
}

@mixin suiFormRangeThumbFocus($color) {
  &:focus {
    &::-webkit-slider-thumb {
      box-shadow: sui_form_range_thumb_focus($color), sui_form_range_make_long_shadow($sui-color-brand-denim-300, -$sui-a-form-range-track-empty-height);
    }

    &::-moz-range-thumb {
      box-shadow: sui_form_range_thumb_focus($color), inset 0 0 0 rem(3) $sui-color-brand-denim-100;
    }

    &::-ms-thumb {
      box-shadow: sui_form_range_thumb_focus($color), inset 0 0 0 rem(3) $sui-color-brand-denim-100;
    }
  }
}

@mixin suiFormRangeStructure() {
  -webkit-appearance: none;
  padding: 0;

  // Target only Google Chrome:29 and Later & Opera:16 and Later
  @media screen and (-webkit-min-device-pixel-ratio: 0) and (min-resolution: .001dpcm) {
    outline: none;
    width: 100%;
    height: $sui-a-form-range-thumb-height + $sui-a-form-range-track-height + $sui-a-form-range-track-border-width;
    line-height: $sui-a-form-range-thumb-height + $sui-a-form-range-track-height + $sui-a-form-range-track-border-width;
    background-color: transparent;
    background-repeat: no-repeat;
    border-radius: $sui-border-radius-rounded;
    cursor: pointer;
    -webkit-appearance: none;
    overflow: hidden;
  }

  &:focus {
    box-shadow: none;
    outline: none;
  }

  @include suiFormRangeThumbFocus($sui-color-primary);

  /* Chrome */

  &::-webkit-slider-thumb {
    height: $sui-a-form-range-thumb-height + $sui-a-form-range-track-border-width;
    width: $sui-a-form-range-thumb-width + $sui-a-form-range-track-border-width;
    -webkit-appearance: none;
    border-radius: $sui-border-radius-rounded;
    box-shadow: sui_form_range_make_long_shadow($sui-color-brand-denim-300, -$sui-a-form-range-track-empty-height);
    margin-top: -$sui-a-form-range-track-empty-height;
    cursor: pointer;
    border-width: $sui-a-form-range-track-border-width;
    border-style: solid;
    position: relative;
  }

  &::-webkit-slider-runnable-track {
    content: '';
    height: $sui-a-form-range-track-height;
    pointer-events: none;
    border-radius: $sui-border-radius-rounded;
  }

  /* Moz */
  &::-moz-range-thumb {
    -webkit-appearance: none;
    height: $sui-a-form-range-thumb-height;
    width: $sui-a-form-range-thumb-width;
    border-radius: $sui-border-radius-rounded;
    cursor: pointer;
    border-width: $sui-a-form-range-track-border-width;
    border-style: solid;
    box-shadow: inset 0 0 0 rem(3) $sui-color-brand-denim-100;
  }

  &::-moz-range-progress {
    width: 100%;
    height: $sui-a-form-range-track-height;
    cursor: pointer;
    border-radius: $sui-border-radius-rounded;
  }

  &::-moz-range-track {
    width: 100%;
    height: $sui-a-form-range-track-height;
    cursor: pointer;
    border-radius: $sui-border-radius-rounded;
  }

  /* Edge */
  &::-ms-thumb {
    height: $sui-a-form-range-thumb-height;
    width: $sui-a-form-range-thumb-width;
    border-radius: $sui-border-radius-rounded;
    box-shadow: inset 0 0 0 rem(3) $sui-color-brand-denim-100;
    border-width: $sui-a-form-range-track-border-width;
    border-style: solid;
  }

  &::-ms-track {
    transition: 0.2s;
    width: 100%;
    height: $sui-a-form-range-track-height;
    cursor: pointer;
    background: transparent;
    border-color: transparent;

    /* leave room for the larger thumb to overflow with a transparent border */
    color: transparent;
    border-width: $sui-size-xs 0;
  }

  &::-ms-fill-lower {
    border-radius: $sui-border-radius-rounded;
  }

  &::-ms-fill-upper {
    border-radius: $sui-border-radius-rounded;
  }
}

@mixin suiFormRangeColor($color) {
  @include suiFormRangeThumbFocus($color);

  /* Chrome */

  &::-webkit-slider-thumb {
    border-color: $color;
    background: $color;
  }

  &::-webkit-slider-runnable-track {
    background: $color;
  }

  /* Moz */
  &::-moz-range-thumb {
    border-color: $color;
    background: $color;
  }

  &::-moz-range-progress {
    background: $color;
  }

  &::-moz-range-track {
    background: $sui-color-brand-denim-300;
  }

  /* Edge */
  &::-ms-thumb {
    background: $color;
    border-color: $color;
  }

  &::-ms-track {
    background: transparent;
    border-color: transparent;
    color: transparent;
  }

  &::-ms-fill-lower {
    background: $color;
  }

  &::-ms-fill-upper {
    background: $sui-color-brand-denim-300;
  }
}

@mixin suiFormRangeValueColor ($color, $color-text) {
  background-color: $color;
  color: $color-text;
}

@mixin suiFormRangeDisabled() {
  [disabled] &,
  .as--disabled &,
  &.as--disabled,
  &[disabled] {
    cursor: not-allowed;
    pointer-events: none;

    @include suiFormRangeColor($sui-color-brand-denim-300);
  }
}
