@use 'sass:math';
@use '@ly-js/theme-chalk/mixins/config' as *;
@use '@ly-js/theme-chalk/mixins/mixins' as *;

@include b(loading) {
  position: relative;
  font-size: 0;
  vertical-align: middle;

  @include e(spinner) {
    display: inline-block;
    position: relative;
    width: 32px;
    max-width: 100%;
    height: 32px;
    max-height: 100%;
    animation: ly-rotate 0.8s linear infinite;
    vertical-align: middle;

    @include m(spinner) {
      animation-timing-function: steps(12);
    }

    @include m(circular) {
      animation-duration: 2s;
    }
  }

  @include e(circular) {
    display: block;
    width: 100%;
    height: 100%;

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

  @include e(line) {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;

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

  @include e(text) {
    display: inline-block;
    color: #969799;
    font-size: 16px;
    vertical-align: middle;
  }
  &__spinner + &__text {
    margin-left: 8px;
  }

  @include m(vertical) {
    display: flex;
    flex-direction: column;
    align-items: center;

    .ly-loading__spinner + .ly-loading__text {
      margin: 8px 0 0;
    }
  }
}

@keyframes ly-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 ly-rotate {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

@for $i from 1 through 12 {
  .ly-loading__line--#{$i} {
    transform: rotate($i * 30deg);
    opacity: 1 - math.div(0.75, 12) * ($i - 1);
  }
}
