@import '../variables';
$loading-size: 5rem;

@keyframes ball-scale-ripple-multiple {
  0% {
    transform: scale(0.1);
    opacity: 1;
  }

  70% {
    transform: scale(1);
    opacity: 0.7;
  }

  100% {
    opacity: 0.0;
  }
}

@function delay($interval, $count, $index) {
  @return ($index * $interval) - ($interval * $count);
}

@mixin ball-scale-ripple-multiple ($n:3, $start:0) {
  @for $i from $start through $n {
    .loading-element-item:nth-child(#{$i}) {
      animation-delay: delay(1s, $n, $i - 1);
    }
  }
}

.loading {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1rem 0;
  opacity: 0;
  transition: opacity .3s linear;

  &.active {
    opacity: 1;
  }

  &-element {
    height: $loading-size;
    position: relative;

    @include ball-scale-ripple-multiple();

    &-item {
      position: absolute;
      left: -$loading-size/2;
      width: $loading-size;
      height: $loading-size;
      border-radius: 100%;
      border: 2px solid $brand-primary;
      animation-fill-mode: both;
      animation: ball-scale-ripple-multiple 1.25s 0s infinite cubic-bezier(.21,.53,.56,.8);
    }
  }
}
