"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "Loading", {
    enumerable: true,
    get: function() {
        return Loading;
    }
});
var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
var _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
var _object_spread = require("@swc/helpers/_/_object_spread");
var _object_spread_props = require("@swc/helpers/_/_object_spread_props");
var _object_without_properties = require("@swc/helpers/_/_object_without_properties");
var _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
var _classnames = /*#__PURE__*/ _interop_require_default._(require("classnames"));
var _iconsreact = require("@nutui/icons-react");
var _lottie = /*#__PURE__*/ _interop_require_default._(require("../lottie"));
var _typings = require("../../utils/typings");
var _mergeprops = require("../../utils/merge-props");
// 方便以后扩展设置为键值对形式
var loadingMap = {
    circular: _iconsreact.Loading1,
    spinner: _iconsreact.Loading
};
var defaultProps = (0, _object_spread_props._)((0, _object_spread._)({}, _typings.ComponentDefaults), {
    // 对比一下,个人感觉还是Loading1比较好看一些,所以用它作为了默认的loading图标
    type: 'circular',
    direction: 'horizontal',
    lottieProps: {}
});
var defaultLottieProps = {
    loop: true,
    autoplay: true
};
var Loading = /*#__PURE__*/ _react.default.forwardRef(function(props, ref) {
    var _ref = (0, _object_spread._)({}, defaultProps, props), className = _ref.className, style = _ref.style, children = _ref.children, direction = _ref.direction, icon = _ref.icon, lottieProps = _ref.lottieProps, rest = (0, _object_without_properties._)(_ref, [
        "className",
        "style",
        "children",
        "direction",
        "icon",
        "lottieProps"
    ]);
    var loadingLottieRef = (0, _react.useRef)(null);
    // @ts-ignore
    // const loadingLottieRef: React.MutableRefObject<LottieProps | null> =
    //   useRef()
    var mergedLottieProps = (0, _mergeprops.mergeProps)(defaultLottieProps, lottieProps);
    _react.default.useImperativeHandle(ref, function() {
        return loadingLottieRef;
    });
    var classPrefix = 'nut-loading';
    var getLoadingIcon = function getLoadingIcon() {
        if (!rest.jsonData) {
            console.warn('Lottie animation requires jsonData prop');
        }
        if (rest.type === 'lottie') {
            return /*#__PURE__*/ _react.default.createElement(_lottie.default, (0, _object_spread_props._)((0, _object_spread._)({}, mergedLottieProps), {
                ref: loadingLottieRef,
                source: rest.jsonData
            }));
        }
        var LoadingIcon = loadingMap[rest.type] || _iconsreact.Loading1;
        return /*#__PURE__*/ _react.default.createElement(LoadingIcon, {
            className: "".concat(classPrefix, "-icon")
        });
    };
    var iconboxClassName = function iconboxClassName() {
        if (rest.type === 'lottie') return "".concat(classPrefix, "-lottie-box");
        return "".concat(classPrefix, "-icon-box");
    };
    return /*#__PURE__*/ _react.default.createElement("div", {
        className: (0, _classnames.default)(classPrefix, direction === 'vertical' ? "".concat(classPrefix, "-vertical") : '', className),
        style: style
    }, /*#__PURE__*/ _react.default.createElement("div", {
        className: iconboxClassName()
    }, icon || getLoadingIcon()), children ? /*#__PURE__*/ _react.default.createElement("div", {
        className: "".concat(classPrefix, "-text")
    }, children) : null);
});
Loading.displayName = 'NutLoading';
