"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _framerMotion = require("framer-motion");
var _Empty = _interopRequireDefault(require("../Media/Empty"));
var _LoadingWrap = require("./LoadingWrap");
var _spinner_black = _interopRequireDefault(require("../../../styles/assets/icon/spinner_black.svg"));
var _framer = require("../..\\utils\\framer");
var _check = _interopRequireDefault(require("../../../styles/assets/icon/check.svg"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const Loading = ({
  cssStyle,
  visible: _visible = true,
  spring: _spring = false,
  background: _background = '',
  type: _type = 'circle',
  status: _status = 'normal',
  size: _size = 'default'
}) => {
  const loadingMotion = (0, _framerMotion.useAnimation)();
  const checkAnim = (0, _framerMotion.useAnimation)();
  const seq = async () => {
    switch (_status) {
      case 'loading':
        loadingMotion.start(_framer.show);
        break;
      case 'ok':
        await loadingMotion.start(_framer.fade);
        await checkAnim.start(_framer.show);
        await checkAnim.start(_framer.fade);
        break;
      default:
        break;
    }
  };
  (0, _react.useEffect)(() => {
    seq();
  }, [_status]);
  let sizeNumber = 30;
  if (typeof _size === 'string') {
    if (parseInt(_size, 10).toString() === _size) {
      sizeNumber = parseInt(_size, 10);
    } else {
      switch (_size) {
        case 'default':
          sizeNumber = 30;
          break;
        case 'large':
          sizeNumber = 54;
          break;
        case 'small':
          sizeNumber = 22;
          break;
        default:
          sizeNumber = 30;
          break;
      }
    }
  } else {
    sizeNumber = _size;
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_LoadingWrap.LoadingWrap, {
    size: sizeNumber,
    children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Empty.default, {
      cssStyle: cssStyle,
      background: _background,
      children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_framerMotion.motion.div, {
        className: _type,
        animate: loadingMotion,
        children: [_type === 'circle' && /*#__PURE__*/(0, _jsxRuntime.jsx)(_framerMotion.motion.img, {
          animate: {
            scale: _spring ? [1.01, 1.03, 1, 1.02, 1] : [1, 1, 1, 1, 1],
            rotate: [0, 90, 180, 270, 360]
          },
          transition: {
            type: 'spring',
            damping: 20,
            stiffness: 50,
            repeat: Infinity
          },
          src: _spinner_black.default,
          style: {
            opacity: _visible ? 1 : 0
          },
          className: "iconSpinner"
        }), _type === 'dots' && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
          children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_framerMotion.motion.div, {
            className: "dot",
            animate: {
              scaleY: [0.85, 0.8, 0.9, 0.8, 0.85],
              y: [1, 3.5, 1, -1.5, 1]
            },
            transition: {
              duration: 1,
              repeat: Infinity
            },
            style: {
              opacity: _visible ? 1 : 0
            }
          }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_framerMotion.motion.div, {
            className: "dot",
            animate: {
              scaleY: [0.85, 0.8, 0.9, 0.8, 0.85],
              y: [1, 3.5, 1, -1.5, 1]
            },
            transition: {
              duration: 1,
              repeat: Infinity,
              delay: 0.2
            },
            style: {
              x: -15,
              opacity: _visible ? 1 : 0
            }
          }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_framerMotion.motion.div, {
            className: "dot",
            animate: {
              scaleY: [0.85, 0.8, 0.9, 0.8, 0.85],
              y: [1, 3.5, 1, -1.5, 1]
            },
            transition: {
              duration: 1,
              repeat: Infinity,
              delay: 0.4
            },
            style: {
              x: 15,
              opacity: _visible ? 1 : 0
            }
          })]
        })]
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_framerMotion.motion.img, {
        className: "check",
        animate: checkAnim,
        src: _check.default,
        style: {
          marginTop: _type === 'circle' ? -40 : 0
        }
      })]
    })
  });
};
var _default = Loading;
exports.default = _default;