@import "../../themes/ionic.globals.md";

// Material Design Range
// --------------------------------------------------

/// @prop - Padding top/bottom of the range
$range-md-padding-vertical:                  8px !default;

/// @prop - Padding start/end of the range
$range-md-padding-horizontal:                8px !default;

/// @prop - Height of the range slider
$range-md-slider-height:                     42px !default;

/// @prop - Width of the area that will select the range knob
$range-md-hit-width:                         42px !default;

/// @prop - Height of the area that will select the range knob
$range-md-hit-height:                        $range-md-slider-height !default;

/// @prop - Height of the range bar
$range-md-bar-height:                        2px !default;

/// @prop - Background of the range bar
$range-md-bar-background-color:              #bdbdbd !default;

/// @prop - Background of the active range bar
$range-md-bar-active-background-color:       color($colors-md, primary) !default;

/// @prop - Width of the range knob
$range-md-knob-width:                        18px !default;

/// @prop - Height of the range knob
$range-md-knob-height:                       $range-md-knob-width !default;

/// @prop - Background of the range knob
$range-md-knob-background-color:             $range-md-bar-active-background-color !default;

/// @prop - Background of the range knob when the value is the minimum
$range-md-knob-min-background-color:         $background-md-color !default;

/// @prop - Border of the range knob when the value is the minimum
$range-md-knob-min-border:                   2px solid $range-md-bar-background-color !default;

/// @prop - Width of the range tick
$range-md-tick-width:                        2px !default;

/// @prop - Height of the range tick
$range-md-tick-height:                       $range-md-tick-width !default;

/// @prop - Border radius of the range tick
$range-md-tick-border-radius:                50% !default;

/// @prop - Background of the range tick
$range-md-tick-background-color:             #000 !default;

/// @prop - Background of the active range tick
$range-md-tick-active-background-color:      $range-md-tick-background-color !default;

/// @prop - Background of the range pin
$range-md-pin-background-color:              $range-md-bar-active-background-color !default;

/// @prop - Color of the range pin
$range-md-pin-color:                         color-contrast($colors-md, $range-md-bar-active-background-color) !default;

/// @prop - Font size of the range pin
$range-md-pin-font-size:                     12px !default;

/// @prop - Padding top/bottom of the range pin
$range-md-pin-padding-vertical:              8px !default;

/// @prop - Padding start/end of the range pin
$range-md-pin-padding-horizontal:            0 !default;

/// @prop - Background of the range pin when the value is the minimum
$range-md-pin-min-background-color:          $range-md-bar-background-color !default;


.range-md {
  @include padding($range-md-padding-vertical, $range-md-padding-horizontal);
}

.range-md [range-left] {
  @include margin(0, 12px, 0, 0);
}

.range-md [range-right] {
  @include margin(0, 0, 0, 12px);
}

.range-md.range-has-pin {
  @include padding($range-md-padding-vertical + $range-md-pin-font-size + $range-md-pin-padding-vertical, null, null, null);
}

.range-md .range-slider {
  height: $range-md-slider-height;
}

.range-md .range-bar {
  @include position(($range-md-slider-height / 2), null, null, 0);

  position: absolute;

  width: 100%;
  height: $range-md-bar-height;

  background: $range-md-bar-background-color;

  pointer-events: none;
}

.range-md.range-pressed .range-bar-active {
  will-change: left, right;
}

.range-md.range-pressed .range-knob-handle {
  will-change: left;
}

.range-md .range-bar-active {
  bottom: 0;

  width: auto;

  background: $range-md-bar-active-background-color;
}

.range-md .range-knob-handle {
  @include position(($range-md-slider-height / 2), null, null, 0);
  @include margin(-($range-md-hit-height / 2), null, null, -($range-md-hit-width / 2));
  @include text-align(center);

  position: absolute;

  width: $range-md-hit-width;
  height: $range-md-hit-height;
}

.range-md .range-knob {
  @include position(($range-md-hit-height / 2) - ($range-md-knob-height / 2) + ($range-md-bar-height / 2),
          null, null, ($range-md-hit-width / 2) - ($range-md-knob-width / 2));
  @include border-radius(50%);

  position: absolute;

  z-index: 2;

  width: $range-md-knob-width;
  height: $range-md-knob-height;

  background: $range-md-knob-background-color;

  transform: scale(.67);
  transition-duration: 120ms;
  transition-property: transform, background-color, border;
  transition-timing-function: ease;

  pointer-events: none;
}

.range-md .range-tick {
  @include margin-horizontal(-($range-md-tick-width / 2), null);
  @include border-radius($range-md-tick-border-radius);

  position: absolute;

  top: ($range-md-hit-height / 2) - ($range-md-tick-height / 2) + ($range-md-bar-height / 2);

  z-index: 1;

  width: $range-md-tick-width;
  height: $range-md-tick-height;

  background: $range-md-tick-background-color;

  pointer-events: none;
}

.range-md .range-tick-active {
  background: $range-md-tick-active-background-color;
}

.range-md .range-pin {
  @include padding($range-md-pin-padding-vertical, $range-md-pin-padding-horizontal);
  @include text-align(center);
  @include border-radius(50%);
  @include transform(translate3d(0, 28px, 0), scale(.01));

  position: relative;
  top: -20px;
  display: inline-block;

  min-width: 28px;
  height: 28px;

  font-size: $range-md-pin-font-size;

  color: $range-md-pin-color;

  background: $range-md-pin-background-color;

  transition: transform 120ms ease, background-color 120ms ease;

  &::before {
    @include position(3px, null, null, 50%);
    @include border-radius(50%, 50%, 50%, 0);
    @include margin-horizontal(-13px, null);

    position: absolute;

    z-index: -1;

    width: 26px;
    height: 26px;

    background: $range-md-pin-background-color;

    content: "";
    transform: rotate(-45deg);
    transition: background-color 120ms ease;
  }
}

.range-md .range-knob-pressed .range-pin {
  @include transform(translate3d(0, 0, 0), scale(1));
}

.range-md:not(.range-has-pin) .range-knob-pressed .range-knob {
  transform: scale(1);
}

@mixin md-range-min() {
  .range-md .range-knob-min.range-knob-min {
    .range-knob {
      border: $range-md-knob-min-border;
      background: $range-md-knob-min-background-color;
    }

    .range-pin,
    .range-pin::before {
      color: color-contrast($colors-md, $range-md-pin-min-background-color);
      background: $range-md-pin-min-background-color;
    }
  }
}

@include md-range-min();

.range-md.range-disabled {
  .range-bar-active {
    background-color: $range-md-bar-background-color;
  }

  .range-knob {
    outline: 5px solid #fff;
    background-color: $range-md-bar-background-color;
    transform: scale(.55);
  }

}


// Generate Material Design Range Colors
// --------------------------------------------------

@each $color-name, $color-base, $color-contrast in get-colors($colors-md) {

  .range-md-#{$color-name} {
    @include md-range-min();

    .range-bar-active,
    .range-knob,
    .range-pin,
    .range-pin::before {
      background: $color-base;
    }
  }

}
