@import '../../common/style/common.less';

.hanzo-loading {
  z-index: 0;
  font-size: 0;
  line-height: 0;
  position: relative;
  vertical-align: middle;

  &__spinner {
    z-index: -1;
    width: 30px;
    height: 30px;
    position: relative;
    display: inline-block;
    box-sizing: border-box;
    vertical-align: middle;
    animation: hanzo-rotate 0.8s linear infinite;

    // compatible for 1.x, users may set width or height in root element
    max-width: 100%;
    max-height: 100%;

    &--spinner {
      animation-timing-function: steps(12);

      i {
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        position: absolute;

        &::before {
          width: 2px;
          height: 25%;
          content: ' ';
          display: block;
          margin: 0 auto;
          border-radius: 40%;
          background-color: currentColor;
        }
      }
    }

    &--circular {
      animation-duration: 2s;
    }
  }

  &__circular {
    width: 100%;
    height: 100%;

    circle {
      stroke: currentColor;
      stroke-width: 3;
      stroke-linecap: round;
      animation: hanzo-circular 1.5s ease-in-out infinite;
    }
  }

  &__text {
    display: inline-block;
    vertical-align: middle;
    color: @loading-text-color;
    font-size: @loading-text-font-size;
    line-height: @loading-text-line-height;
    margin-left: 10px;
  }

  &--vertical {
    display: flex;
    align-items: center;
    flex-direction: column;

    .hanzo-loading__text {
      margin-left: 0;
      margin-top: 10px;
    }
  }
}

@keyframes hanzo-circular {
  0% {
    stroke-dasharray: 1, 200;
    stroke-dashoffset: 0;
  }

  50% {
    stroke-dasharray: 90, 150;
    stroke-dashoffset: -40;
  }

  100% {
    stroke-dasharray: 90, 150;
    stroke-dashoffset: -120;
  }
}

@keyframes hanzo-rotate {
    from {
      transform: rotate(0deg);
    }
  
    to {
      transform: rotate(360deg);
    }
  }

.generate-spinner(@n, @i: 1) when (@i =< @n) {
  .hanzo-loading__spinner--spinner i:nth-of-type(@{i}) {
    opacity: 1 - (0.75 / 12) * (@i - 1);
    transform: rotate(@i * 30deg);
  }
  .generate-spinner(@n, (@i + 1));
}
.generate-spinner(12);
