import React, { useEffect } from 'react';
import { motion, useAnimation } from 'framer-motion';
import Empty from "../Media/Empty";
import { LoadingWrap } from "./LoadingWrap";
import iconSpinner from "../../../styles/assets/icon/spinner_black.svg";
import { fade, show } from "../..\\utils\\framer";
import check from "../../../styles/assets/icon/check.svg";
import { jsx as _jsx } from "react/jsx-runtime";
import { Fragment as _Fragment } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
const Loading = ({
  cssStyle,
  visible: _visible = true,
  spring: _spring = false,
  background: _background = '',
  type: _type = 'circle',
  status: _status = 'normal',
  size: _size = 'default'
}) => {
  const loadingMotion = useAnimation();
  const checkAnim = useAnimation();
  const seq = async () => {
    switch (_status) {
      case 'loading':
        loadingMotion.start(show);
        break;
      case 'ok':
        await loadingMotion.start(fade);
        await checkAnim.start(show);
        await checkAnim.start(fade);
        break;
      default:
        break;
    }
  };
  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__*/_jsx(LoadingWrap, {
    size: sizeNumber,
    children: /*#__PURE__*/_jsxs(Empty, {
      cssStyle: cssStyle,
      background: _background,
      children: [/*#__PURE__*/_jsxs(motion.div, {
        className: _type,
        animate: loadingMotion,
        children: [_type === 'circle' && /*#__PURE__*/_jsx(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: iconSpinner,
          style: {
            opacity: _visible ? 1 : 0
          },
          className: "iconSpinner"
        }), _type === 'dots' && /*#__PURE__*/_jsxs(_Fragment, {
          children: [/*#__PURE__*/_jsx(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__*/_jsx(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__*/_jsx(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__*/_jsx(motion.img, {
        className: "check",
        animate: checkAnim,
        src: check,
        style: {
          marginTop: _type === 'circle' ? -40 : 0
        }
      })]
    })
  });
};
export default Loading;