/*
 *  Usage:
 *
      <div class="sk-wave">
        <div class="sk-rect sk-rect1"></div>
        <div class="sk-rect sk-rect2"></div>
        <div class="sk-rect sk-rect3"></div>
        <div class="sk-rect sk-rect4"></div>
        <div class="sk-rect sk-rect5"></div>
      </div>
 *
 */
@import "../variables";

$spinkit-wave-child-count: 5 !default;
$spinkit-wave-width: $spinkit-size * 1.25;
$spinkit-wave-height: $spinkit-size;
$spinkit-wave-margin: $spinkit-spinner-margin;
$spinkit-wave-background-color: $spinkit-spinner-color;
$spinkit-wave-animation-duration: 1.2s !default;
$spinkit-wave-animation-delay-range: 0.4s !default;
$spinkit-wave-css-export: true !default;

@keyframes sk-waveStretchDelay {
  0%, 40%, 100% { transform: scaleY(0.4) }
  20% { transform: scaleY(1.0) }
}

@mixin sk-wave-size(
  $width: $spinkit-wave-width,
  $height: $spinkit-wave-height,
  $child-count: $spinkit-wave-child-count
) {
  width: $width;
  height: $height;
  font-size: $width / $child-count;

  .sk-rect {
    width: $width / $child-count * 0.6;
  }
}

@mixin sk-wave-color(
  $color: $spinkit-wave-background-color
) {
  .sk-rect {
    background-color: $color;
  }
}

@mixin sk-wave-style(
  $width: $spinkit-wave-width,
  $height: $spinkit-wave-height,
  $color: $spinkit-wave-background-color,
  $margin: $spinkit-wave-margin,
  $child-count: $spinkit-wave-child-count
) {
  margin: $margin;

  @include sk-wave-size(
    $width: $width,
    $height: $height,
    $child-count: $child-count
  );

  @include sk-wave-color(
    $color: $color
  );
}

@mixin sk-wave (
  $width: $spinkit-wave-width,
  $height: $spinkit-wave-height,
  $color: $spinkit-wave-background-color,
  $margin: $spinkit-wave-margin,
  $duration: $spinkit-wave-animation-duration,
  $delay-range: $spinkit-wave-animation-delay-range,
  $child-count: $spinkit-wave-child-count
) {
  text-align: center;

  .sk-rect {
    height: 100%;
    display: inline-block;
    animation: sk-waveStretchDelay $duration infinite ease-in-out;

    &:first-child {
      // fix issue with last rect flowing onto next line
      margin-left: -4px;
    }
  }

  @for $i from 1 through $child-count {
    .sk-rect#{$i} { animation-delay: - $duration + $delay-range / ($child-count - 1) * ($i - 1); }
  }

  @include sk-wave-style(
    $width: $width,
    $height: $height,
    $color: $color,
    $margin: $margin,
    $child-count: $child-count
  );
}

@if ($spinkit-wave-css-export) {
  .sk-wave {
    @include sk-wave;
  }
}
