import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
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";
var Loading = function Loading(_ref) {
  var cssStyle = _ref.cssStyle,
    _ref$visible = _ref.visible,
    visible = _ref$visible === void 0 ? true : _ref$visible,
    _ref$spring = _ref.spring,
    spring = _ref$spring === void 0 ? false : _ref$spring,
    _ref$background = _ref.background,
    background = _ref$background === void 0 ? '' : _ref$background,
    _ref$type = _ref.type,
    type = _ref$type === void 0 ? 'circle' : _ref$type,
    _ref$status = _ref.status,
    status = _ref$status === void 0 ? 'normal' : _ref$status,
    _ref$size = _ref.size,
    size = _ref$size === void 0 ? 'default' : _ref$size;
  var loadingMotion = useAnimation();
  var checkAnim = useAnimation();
  var seq = /*#__PURE__*/function () {
    var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
      return _regeneratorRuntime().wrap(function _callee$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              _context.t0 = status;
              _context.next = _context.t0 === 'loading' ? 3 : _context.t0 === 'ok' ? 5 : 12;
              break;
            case 3:
              loadingMotion.start(show);
              return _context.abrupt("break", 13);
            case 5:
              _context.next = 7;
              return loadingMotion.start(fade);
            case 7:
              _context.next = 9;
              return checkAnim.start(show);
            case 9:
              _context.next = 11;
              return checkAnim.start(fade);
            case 11:
              return _context.abrupt("break", 13);
            case 12:
              return _context.abrupt("break", 13);
            case 13:
            case "end":
              return _context.stop();
          }
        }
      }, _callee);
    }));
    return function seq() {
      return _ref2.apply(this, arguments);
    };
  }();
  useEffect(function () {
    seq();
  }, [status]);
  var 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;