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 Lottie from "lottie-react";
import React, { useMemo } from "react";
import { useAsyncLottieData } from "./useAsyncLottieData";
/**
 * 工厂：根据动态 import 与默认配置生成一个标准的 Lottie 包装组件。
 *
 * 用于消除 lotties/ 与 Robot/lotties/ 下大量结构完全相同的 Lottie 包装组件
 * （只有 `import('./xxx.json')` 与 displayName/默认尺寸不同）。
 */ export function createLottieComponent(options) {
    var loadJson = options.loadJson, defaultSize = options.defaultSize, _options_dataTestId = options.dataTestId, dataTestId = _options_dataTestId === void 0 ? 'lottie-mock' : _options_dataTestId, defaultFallback = options.defaultFallback, displayName = options.displayName;
    var Component = function Component(props) {
        var _props_autoplay = props.autoplay, autoplay = _props_autoplay === void 0 ? true : _props_autoplay, _props_loop = props.loop, loop = _props_loop === void 0 ? true : _props_loop, className = props.className, style = props.style, _props_size = props.size, size = _props_size === void 0 ? defaultSize : _props_size, fallback = props.fallback;
        // loadJson 是工厂闭包变量，引用稳定；使用 useMemo 让 useAsyncLottieData 的 deps 稳定
        var stableLoad = useMemo(function() {
            return loadJson;
        }, []);
        var animationData = useAsyncLottieData(stableLoad);
        var containerStyle = _object_spread({
            width: size,
            height: size,
            display: 'flex',
            justifyContent: 'center',
            alignItems: 'center'
        }, style);
        if (animationData === null || animationData === undefined) {
            if (fallback !== undefined) {
                return /*#__PURE__*/ React.createElement(React.Fragment, null, fallback);
            }
            if (defaultFallback !== undefined) {
                return /*#__PURE__*/ React.createElement(React.Fragment, null, defaultFallback);
            }
            return /*#__PURE__*/ React.createElement("div", {
                style: containerStyle,
                className: className,
                "aria-hidden": true
            });
        }
        return /*#__PURE__*/ React.createElement(Lottie, {
            style: containerStyle,
            className: className,
            "data-testid": dataTestId,
            "aria-hidden": "true",
            animationData: animationData,
            loop: loop,
            autoplay: autoplay
        });
    };
    if (displayName) {
        Component.displayName = displayName;
    }
    return Component;
}
