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