@import "../mixins/_vendor-prefixes.less";

/**
 * Spinner - Rectangle bar spinner/loader animation
 *
 * Note: Uses color tokens (@text-muted; @spinner-color) and @size-* tokens where applicable.
 *
 * Intentionally hardcoded values:
 * - Spinner dimensions (50px, 40px, 30px, 60px, 45px): Component-specific sizes
 * - Padding values (45px, 35px, 11px): Component-specific positioning offsets
 * - Negative margins (-25px, -15px, -28px): Centering calculations (half of width/height)
 * - Bar width (6px): Spinner bar width (off-grid)
 * - Animation duration (1.2s) and delays (-1.1s to -0.8s): Animation timing
 * - Transform scale (0.5): Size reduction for button variant
 * - RGBA background: Semi-transparent overlay
 * - Percentages and unitless scale values: Animation and transform values
 */

c8y-rectangle-spinner,
.c8y-rectangle-spinner {
  position: relative;
  display: block;
  padding-top: 45px;
  min-width: 50px;
  min-height: 40px;
  color: @text-muted;
  text-align: center;
  font-size: @font-size-base;

  .spinner {
    left: 50%;
    margin-left: -25px;
  }

  &.spinner-xs {
    padding-top: 35px;
    min-width: 30px;
    min-height: 30px;

    .spinner {
      margin-left: -15px;
    }
  }

  &.spinner-inline {
    display: inline-block;
    padding-top: 11px;
    padding-left: 50px;
    vertical-align: middle;
    text-align: left;

    .spinner {
      left: 0;
      margin-left: 0;
    }

    &.spinner-xs {
      padding-top: @size-5;
      padding-left: 35px;
    }
  }
}

.spinner {
  position: absolute;
  top: 0;
  left: 0;
  margin: 0 auto;
  width: 50px;
  height: 40px;
  text-align: center;
  font-size: @size-10;
  opacity: 0.5;

  &.spinner-xs,
  .spinner-xs & {
    width: 30px;
    height: 30px;

    > div {
      margin: 0;
      width: @size-4;
    }
  }
}

.spinner > div {
  display: inline-block;
  margin-right: 1px;
  width: 6px;
  height: 100%;
  background-color: @spinner-color;
  animation: stretchdelay 1.2s infinite ease-in-out;
}

.spinner .rect2 {
  animation-delay: -1.1s;
}

.spinner .rect3 {
  animation-delay: -1s;
}

.spinner .rect4 {
  animation-delay: -0.9s;
}

.spinner .rect5 {
  animation-delay: -0.8s;
}

@keyframes stretchdelay {
  0%,
  40%,
  100% {
    transform: scaleY(0.4);
  }

  20% {
    transform: scaleY(1);
  }
}

.spinner-panel-wrapper {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  height: 100%;
  background-color: rgba(255, 255, 255, 0.7);

  .grid-stack-item & {
    right: @size-10;
    left: @size-10;
  }

  .spinner {
    top: 0;
    left: 50%;
    margin-left: -25px;
  }
}

.spinner-inline-wrapper {
  position: relative;
  display: inline-block;
  width: 60px;
  vertical-align: middle;

  .spinner {
    transform: translateY(-50%);
  }
}

.spinner-btn {
  position: relative;
  display: inline-block;
  width: 45px;
  transform: scale(0.5) translateY(-28px);
}
