/**
 *
 * @ai-apps/angular v2.152.0 | _loading.scss
 *
 * Copyright 2014, 2023 IBM
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0

 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


//
// Copyright IBM Corp. 2016, 2018
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//

@use '../../config' as *;
@use '../../motion' as *;
@use '../../spacing' as *;
@use '../../theme' as *;
@use '../../utilities/component-reset';
@use '../../utilities/convert';
@use '../../utilities/z-index' as *;
@use 'vars' as *;
@use 'functions' as *;
@use 'animation';

/// Loading styles
/// @access private
/// @group loading
@mixin loading {
  .#{$prefix}--loading {
    @include component-reset.reset;
    @include animation.spin;

    width: $loading-size;
    height: $loading-size;
  }

  // Animation (Spin by default)
  .#{$prefix}--loading__svg {
    fill: transparent;
  }

  .#{$prefix}--loading__svg circle {
    stroke-dasharray: $circumference $circumference;
    stroke-linecap: butt;
    stroke-width: 10;
  }

  .#{$prefix}--loading__stroke {
    stroke: $interactive;
    stroke-dashoffset: loading-progress($circumference, 81);
  }

  .#{$prefix}--loading--small .#{$prefix}--loading__stroke {
    stroke-dashoffset: loading-progress($circumference, 48);
  }

  .#{$prefix}--loading--stop {
    @include animation.stop;
  }

  .#{$prefix}--loading--small {
    width: convert.rem(16px);
    height: convert.rem(16px);

    circle {
      stroke-width: 16;
    }
  }

  .#{$prefix}--loading--small .#{$prefix}--loading__svg {
    stroke: $interactive;
  }

  .#{$prefix}--loading__background {
    stroke: $layer-accent;
    stroke-dashoffset: -22;
  }

  // Negative values for `stroke-dashoffset` are not supported in Safari
  @media not all and (min-resolution: 0.001dpcm) {
    @supports (-webkit-appearance: none) and (stroke-color: transparent) {
      circle.#{$prefix}--loading__background {
        stroke-dasharray: 265;
        stroke-dashoffset: 0;
      }
    }
  }

  .#{$prefix}--loading-overlay {
    position: fixed;
    z-index: z('overlay');
    top: 0;
    left: 0;
    display: flex;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
    background-color: $overlay;
    transition: background-color $duration-slow-02 motion(standard, expressive);
  }

  .#{$prefix}--loading-overlay--stop {
    display: none;
  }

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

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

  @keyframes rotate-end-p1 {
    100% {
      transform: rotate(360deg);
    }
  }

  @keyframes rotate-end-p2 {
    100% {
      transform: rotate(-360deg);
    }
  }

  /* Stroke animations */
  @keyframes init-stroke {
    0% {
      stroke-dashoffset: loading-progress($circumference, 0);
    }

    100% {
      stroke-dashoffset: loading-progress($circumference, 81);
    }
  }

  @keyframes stroke-end {
    0% {
      stroke-dashoffset: loading-progress($circumference, 81);
    }

    100% {
      stroke-dashoffset: loading-progress($circumference, 0);
    }
  }
}
