function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
function _object_spread(target) {
    for(var i = 1; i < arguments.length; i++){
        var source = arguments[i] != null ? arguments[i] : {};
        var ownKeys = Object.keys(source);
        if (typeof Object.getOwnPropertySymbols === "function") {
            ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
                return Object.getOwnPropertyDescriptor(source, sym).enumerable;
            }));
        }
        ownKeys.forEach(function(key) {
            _define_property(target, key, source[key]);
        });
    }
    return target;
}
import { ConfigProvider } from "antd";
import classNames from "clsx";
import { isString } from "lodash-es";
import React, { useContext } from "react";
import { TextLoading } from "../lotties";
import Indicator from "./Indicator";
import { prefixCls, useStyle } from "./style";
/**
 * Loading 组件 - 加载动画组件
 *
 * 该组件提供加载动画效果，支持多种显示模式：
 * - 基础模式：仅显示加载动画和可选的提示文本
 * - 嵌套模式：当提供 children 时，会在内容上方显示加载遮罩
 * - 进度模式：当提供 percent 时，显示进度圆环
 *
 * @component
 * @description 加载动画组件，支持自定义指示器、提示文本、进度显示和嵌套模式
 * @example
 * ```tsx
 * import { Loading } from './Components/Loading';
 *
 * function App() {
 *   return (
 *     <div>
 *       <Loading {...props} />
 *     </div>
 *   );
 * }
 * ```
 *
 * @returns {React.ReactElement} 渲染的加载动画组件
 */ export var Loading = function Loading(param) {
    var className = param.className, wrapperClassName = param.wrapperClassName, style = param.style, indicator = param.indicator, tip = param.tip, _param_spinning = param.spinning, spinning = _param_spinning === void 0 ? true : _param_spinning, children = param.children, styles = param.styles, size = param.size, percent = param.percent;
    var context = useContext(ConfigProvider.ConfigContext);
    var baseCls = context === null || context === void 0 ? void 0 : context.getPrefixCls(prefixCls);
    var _useStyle = useStyle(baseCls), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
    var isNestedPattern = React.useMemo(function() {
        return !!children;
    }, [
        children
    ]);
    var mergedSize = size !== null && size !== void 0 ? size : isNestedPattern ? 32 : '1em';
    var showPercent = percent !== undefined && percent !== null;
    var showTip = tip !== false && tip !== null && (showPercent || tip !== undefined);
    var text = tip !== null && tip !== void 0 ? tip : showPercent ? "".concat(percent, "%") : undefined;
    var tipElement = isNestedPattern && isString(text) ? /*#__PURE__*/ React.createElement(TextLoading, {
        text: text,
        className: classNames("".concat(baseCls, "-tip"), hashId),
        style: styles === null || styles === void 0 ? void 0 : styles.tip
    }) : /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(baseCls, "-tip"), hashId),
        style: styles === null || styles === void 0 ? void 0 : styles.tip
    }, text);
    var _obj;
    var loadingElement = /*#__PURE__*/ React.createElement("div", {
        className: classNames(baseCls, hashId, className, (_obj = {}, _define_property(_obj, "".concat(baseCls, "-with-tip"), !!tip), _define_property(_obj, "".concat(baseCls, "-with-children"), isNestedPattern), _obj)),
        style: _object_spread({
            fontSize: mergedSize
        }, styles === null || styles === void 0 ? void 0 : styles.root, style)
    }, /*#__PURE__*/ React.createElement(Indicator, {
        size: mergedSize,
        indicator: indicator,
        percent: percent,
        style: styles === null || styles === void 0 ? void 0 : styles.indicator
    }), showTip ? tipElement : null);
    if (isNestedPattern) {
        return wrapSSR(/*#__PURE__*/ React.createElement("div", {
            className: classNames("".concat(baseCls, "-nested-pattern"), hashId, wrapperClassName, spinning && "".concat(baseCls, "-spinning")),
            style: styles === null || styles === void 0 ? void 0 : styles.wrapper
        }, spinning ? loadingElement : null, /*#__PURE__*/ React.createElement("div", {
            className: classNames("".concat(baseCls, "-container"), hashId)
        }, children)));
    }
    return wrapSSR(loadingElement);
};
