@use "../../themes/mixins" as mixins;
@use "../../themes/functions.color" as colors;

// Spinner: Common Styles
// --------------------------------------------------

:host {
  /**
   * @prop --ion-spinner-color: Color of the spinner
   *
   * @prop --ion-spinner-lines-stroke-width: Stroke width of the `lines` spinner
   * @prop --ion-spinner-lines-small-stroke-width: Stroke width of the `lines-small` spinner
   * @prop --ion-spinner-lines-sharp-stroke-width: Stroke width of the `lines-sharp` spinner
   * @prop --ion-spinner-lines-sharp-small-stroke-width: Stroke width of the `lines-sharp-small` spinner
   * @prop --ion-spinner-crescent-stroke-width: Stroke width of the `crescent` spinner
   * @prop --ion-spinner-dots-stroke-width: Stroke width of the `dots` spinner
   * @prop --ion-spinner-circular-stroke-width: Stroke width of the `circular` spinner
   *
   * Sizes
   * @prop --ion-spinner-size-xsmall-width: Width of the `xsmall` spinner
   * @prop --ion-spinner-size-xsmall-height: Height of the `xsmall` spinner
   * @prop --ion-spinner-size-small-width: Width of the `small` spinner
   * @prop --ion-spinner-size-small-height: Height of the `small` spinner
   * @prop --ion-spinner-size-medium-width: Width of the `medium` spinner
   * @prop --ion-spinner-size-medium-height: Height of the `medium` spinner
   * @prop --ion-spinner-size-large-width: Width of the `large` spinner
   * @prop --ion-spinner-size-large-height: Height of the `large` spinner
   * @prop --ion-spinner-size-xlarge-width: Width of the `xlarge` spinner
   * @prop --ion-spinner-size-xlarge-height: Height of the `xlarge` spinner
   */

  display: inline-block;
  position: relative;

  color: var(--ion-spinner-color);

  user-select: none;
}

:host(.ion-color) {
  color: colors.current-color(base);
}

svg {
  @include mixins.transform-origin(center);

  position: absolute;

  /**
   * Do not use @include position
   * as the alignment of the elements with
   * a spinner should not be RTL aware.
   */
  top: 0;
  /* stylelint-disable-next-line property-disallowed-list */
  left: 0;

  width: 100%;
  height: 100%;

  transform: translateZ(0);
}

// Spinner Names
// --------------------------------------------------

// lines / lines-small / lines-sharp / lines-sharp-small
:host(.spinner-name-lines) line,
:host(.spinner-name-lines-small) line,
:host(.spinner-name-lines-sharp) line,
:host(.spinner-name-lines-sharp-small) line {
  stroke-linecap: round;
  stroke: currentColor;
}

:host(.spinner-name-lines) svg,
:host(.spinner-name-lines-small) svg,
:host(.spinner-name-lines-sharp) svg,
:host(.spinner-name-lines-sharp-small) svg {
  animation: spinner-fade-out 1s linear infinite;
}

:host(.spinner-name-lines) line {
  stroke-width: var(--ion-spinner-lines-stroke-width);
}

:host(.spinner-name-lines-small) line {
  stroke-width: var(--ion-spinner-lines-small-stroke-width);
}

:host(.spinner-name-lines-sharp) line {
  stroke-width: var(--ion-spinner-lines-sharp-stroke-width);
}

:host(.spinner-name-lines-sharp-small) line {
  stroke-width: var(--ion-spinner-lines-sharp-small-stroke-width);
}

// bubbles
:host(.spinner-name-bubbles) svg {
  animation: spinner-scale-out 1s linear infinite;
  fill: currentColor;
}

// circles
:host(.spinner-name-circles) svg {
  animation: spinner-fade-out 1s linear infinite;
  fill: currentColor;
}

:host(.spinner-name-crescent) circle {
  fill: transparent;
  stroke-width: var(--ion-spinner-crescent-stroke-width);
  stroke-dasharray: 128px;
  stroke-dashoffset: 82px;
  stroke: currentColor;
}

// crescent
:host(.spinner-name-crescent) svg {
  animation: spinner-rotate 1s linear infinite;
}

// dots
:host(.spinner-name-dots) circle {
  stroke-width: var(--ion-spinner-dots-stroke-width);
  fill: currentColor;
}

:host(.spinner-name-dots) svg {
  animation: spinner-dots 1s linear infinite;
}

// circular
:host(.spinner-name-circular) svg {
  animation: spinner-circular linear infinite;
}

:host(.spinner-name-circular) circle {
  animation: spinner-circular-inner ease-in-out infinite;
  stroke: currentColor;
  stroke-dasharray: 80px, 200px;
  stroke-dashoffset: 0px;
  stroke-width: var(--ion-spinner-circular-stroke-width);
  fill: none;
}

// Spinner Sizes
// --------------------------------------------------

:host(.spinner-size-xsmall) {
  width: var(--ion-spinner-size-xsmall-width);
  height: var(--ion-spinner-size-xsmall-height);
}

:host(.spinner-size-small) {
  width: var(--ion-spinner-size-small-width);
  height: var(--ion-spinner-size-small-height);
}

:host(.spinner-size-medium) {
  width: var(--ion-spinner-size-medium-width);
  height: var(--ion-spinner-size-medium-height);
}

:host(.spinner-size-large) {
  width: var(--ion-spinner-size-large-width);
  height: var(--ion-spinner-size-large-height);
}

:host(.spinner-size-xlarge) {
  width: var(--ion-spinner-size-xlarge-width);
  height: var(--ion-spinner-size-xlarge-height);
}

// Spinner States
// --------------------------------------------------

// Paused
:host(.spinner-paused),
:host(.spinner-paused) svg,
:host(.spinner-paused) circle {
  animation-play-state: paused;
}

// Animation Keyframes
// --------------------------------------------------

@keyframes spinner-fade-out {
  0% {
    opacity: 1;
  }

  100% {
    opacity: 0;
  }
}

@keyframes spinner-scale-out {
  0% {
    transform: scale(1, 1);
  }

  100% {
    transform: scale(0, 0);
  }
}

@keyframes spinner-rotate {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

@keyframes spinner-dots {
  0% {
    transform: scale(1, 1);

    opacity: 0.9;
  }

  50% {
    transform: scale(0.4, 0.4);

    opacity: 0.3;
  }

  100% {
    transform: scale(1, 1);

    opacity: 0.9;
  }
}

@keyframes spinner-circular {
  100% {
    transform: rotate(360deg);
  }
}

@keyframes spinner-circular-inner {
  0% {
    stroke-dasharray: 1px, 200px;
    stroke-dashoffset: 0px;
  }
  50% {
    stroke-dasharray: 100px, 200px;
    stroke-dashoffset: -15px;
  }
  100% {
    stroke-dasharray: 100px, 200px;
    stroke-dashoffset: -125px;
  }
}
