"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
require("@emotion/react");
const React = require("react");
const jsxRuntime = require("@emotion/react/jsx-runtime");
const LoadingWrap = require("./LoadingWrap.js");
const check = require("../../../assets/icon/check.svg.js");
const spinner_black = require("../../../assets/icon/spinner_black.svg.js");
const framer = require("../../../utils/framer.js");
const useAnimation = require("../../../node_modules/.pnpm/framer-motion@6.5.1_react-dom@17.0.2_react@17.0.2/node_modules/framer-motion/dist/es/animation/use-animation.js");
const motion = require("../../../node_modules/.pnpm/framer-motion@6.5.1_react-dom@17.0.2_react@17.0.2/node_modules/framer-motion/dist/es/render/dom/motion.js");
const Loading = ({
  cssStyle,
  visible = true,
  spring = false,
  type = "circle",
  status = "loading",
  size = "default",
  duration = 1
}) => {
  const loadingMotion = useAnimation.useAnimation();
  const checkAnim = useAnimation.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;
    }
  };
  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;
  }
  const InnerLoading = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
    /* @__PURE__ */ jsxRuntime.jsxs(motion.motion.div, { className: type, animate: loadingMotion, children: [
      type === "circle" && /* @__PURE__ */ jsxRuntime.jsx(
        motion.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,
            duration
          },
          src: spinner_black,
          style: { opacity: visible ? 1 : 0 },
          className: "iconSpinner"
        }
      ),
      type === "dots" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
        /* @__PURE__ */ jsxRuntime.jsx(
          motion.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,
              repeat: Infinity
            },
            style: { opacity: visible ? 1 : 0 }
          }
        ),
        /* @__PURE__ */ jsxRuntime.jsx(
          motion.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,
              repeat: Infinity,
              delay: 0.2
            },
            style: { x: -15, opacity: visible ? 1 : 0 }
          }
        ),
        /* @__PURE__ */ jsxRuntime.jsx(
          motion.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,
              repeat: Infinity,
              delay: 0.4
            },
            style: { x: 15, opacity: visible ? 1 : 0 }
          }
        )
      ] })
    ] }),
    /* @__PURE__ */ jsxRuntime.jsx(motion.motion.img, { className: "check", animate: checkAnim, src: check })
  ] });
  return /* @__PURE__ */ jsxRuntime.jsx(
    LoadingWrap.InnerLoadingWrap,
    {
      css: cssStyle,
      size: sizeNumber,
      type,
      status,
      children: InnerLoading
    }
  );
};
exports.Loading = Loading;
//# sourceMappingURL=index.js.map
