"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = function(module) {
        var getter = module && module.__esModule ? function() {
            return module['default'];
        } : function() {
            return module;
        };
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __webpack_require__.d = function(exports1, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
(()=>{
    __webpack_require__.r = function(exports1) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    GetMenuItemsContext: ()=>GetMenuItemsContext,
    useMenuItem: ()=>useMenuItem,
    useCollectMenuItems: ()=>useCollectMenuItems,
    useCollectMenuItem: ()=>useCollectMenuItem,
    GetMenuItemContext: ()=>GetMenuItemContext
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const external_lodash_namespaceObject = require("lodash");
var external_lodash_default = /*#__PURE__*/ __webpack_require__.n(external_lodash_namespaceObject);
const GetMenuItemContext = /*#__PURE__*/ (0, external_react_namespaceObject.createContext)(null);
GetMenuItemContext.displayName = 'GetMenuItemContext';
const GetMenuItemsContext = /*#__PURE__*/ (0, external_react_namespaceObject.createContext)(null);
GetMenuItemsContext.displayName = 'GetMenuItemsContext';
const useCollectMenuItem = ()=>(0, external_react_namespaceObject.useContext)(GetMenuItemContext) || {};
const useCollectMenuItems = ()=>(0, external_react_namespaceObject.useContext)(GetMenuItemsContext) || {};
const useMenuItem = ()=>{
    const list = (0, external_react_namespaceObject.useRef)([]);
    const renderItems = (0, external_react_namespaceObject.useRef)(null);
    const shouldRerender = (0, external_react_namespaceObject.useRef)(false);
    const Component = (0, external_react_namespaceObject.useCallback)((param)=>{
        let { limitCount } = param;
        if (!shouldRerender.current) return null;
        shouldRerender.current = false;
        if (renderItems.current) return renderItems.current();
        if (limitCount && list.current.length > limitCount) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(jsx_runtime_namespaceObject.Fragment, {
            children: list.current.slice(0, limitCount).map((Com, index)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Com, {}, index))
        });
        return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(jsx_runtime_namespaceObject.Fragment, {
            children: list.current.map((Com, index)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Com, {}, index))
        });
    }, []);
    const getMenuItems = (0, external_react_namespaceObject.useCallback)((Com)=>{
        const items = [];
        const pushMenuItem = (item)=>{
            items.push(item);
            items.sort((a, b)=>(a.order || 0) - (b.order || 0));
        };
        shouldRerender.current = true;
        renderItems.current = ()=>{
            const notDeleteItems = items.filter((item)=>item.notdelete).map((item)=>external_lodash_default().omit(item, 'notdelete'));
            items.length = 0;
            items.push(...notDeleteItems);
            return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(GetMenuItemsContext.Provider, {
                value: {
                    pushMenuItem
                },
                children: Com()
            });
        };
        return items;
    }, []);
    const getMenuItem = (0, external_react_namespaceObject.useCallback)((Com)=>{
        const item = {};
        const collectMenuItem = (menuItem)=>{
            Object.assign(item, menuItem);
        };
        shouldRerender.current = true;
        list.current.push(()=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(GetMenuItemContext.Provider, {
                value: {
                    collectMenuItem
                },
                children: Com()
            }));
        return item;
    }, []);
    const clean = (0, external_react_namespaceObject.useCallback)(()=>{
        list.current = [];
    }, []);
    return {
        Component,
        getMenuItems,
        getMenuItem,
        clean
    };
};
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
