"use strict";
var __webpack_require__ = {};
(()=>{
    __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__, {
    ContextMenuButtonProvider: ()=>ContextMenuButtonProvider,
    ContextMenuProvider: ()=>ContextMenuProvider
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const icons_namespaceObject = require("@ant-design/icons");
const external_ahooks_namespaceObject = require("ahooks");
const external_antd_namespaceObject = require("antd");
const index_js_namespaceObject = require("../../application/index.js");
const external_schema_component_index_js_namespaceObject = require("../../schema-component/index.js");
const external_pinned_list_index_js_namespaceObject = require("../pinned-list/index.js");
const external_useContextMenu_js_namespaceObject = require("./useContextMenu.js");
const STORAGE_KEYS = {
    SHOW_SCROLL_AREA: 'show-scroll-area',
    CONTEXT_MENU_ENABLED: 'context-menu-enabled'
};
const ContextMenuProvider = (param)=>{
    let { children } = param;
    const [enable, setEnable] = (0, external_ahooks_namespaceObject.useLocalStorageState)(STORAGE_KEYS.CONTEXT_MENU_ENABLED, {
        defaultValue: true
    });
    const [showScrollArea, setShowScrollArea] = (0, external_ahooks_namespaceObject.useLocalStorageState)(STORAGE_KEYS.SHOW_SCROLL_AREA, {
        defaultValue: false
    });
    const contextItems = (0, index_js_namespaceObject.useApp)().pluginContextMenu.get();
    const [position, setPosition] = (0, external_react_namespaceObject.useState)({
        x: 0,
        y: 0
    });
    const items = [];
    const contextItemsSorted = Object.values(contextItems).sort((a, b)=>(a.sort || 0) - (b.sort || 0));
    contextItemsSorted.forEach((item)=>{
        const { actionProps, title, icon } = item.useLoadMethod({
            enable,
            setEnable,
            showScrollArea,
            setShowScrollArea,
            position
        });
        items.push({
            label: title,
            key: title,
            icon: icon,
            onClick: actionProps.onClick
        });
    });
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_useContextMenu_js_namespaceObject.ContextMenuContext.Provider, {
        value: {
            contextMenuEnabled: enable,
            setContextMenuEnable: setEnable,
            showScrollArea,
            setShowScrollArea,
            position
        },
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Dropdown, {
            menu: {
                items
            },
            trigger: enable ? [
                'contextMenu'
            ] : [],
            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                onContextMenu: (e)=>{
                    setPosition({
                        x: e.clientX,
                        y: e.clientY
                    });
                },
                children: children
            })
        })
    });
};
const ContextMenuButton = ()=>{
    const { contextMenuEnabled, setContextMenuEnable } = (0, external_useContextMenu_js_namespaceObject.useContextMenu)();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.FloatButton, {
        type: contextMenuEnabled ? 'primary' : 'default',
        icon: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icons_namespaceObject.ToolOutlined, {}),
        onClick: ()=>setContextMenuEnable(!contextMenuEnabled)
    });
};
const ContextMenuButtonProvider = (props)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_pinned_list_index_js_namespaceObject.PinnedPluginListProvider, {
        items: {
            cm: {
                order: 90,
                component: 'ContextMenuButton',
                pin: true,
                isPublic: true,
                belongTo: 'hoverbutton'
            }
        },
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_component_index_js_namespaceObject.SchemaComponentOptions, {
            components: {
                ContextMenuButton
            },
            children: props.children
        })
    });
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
});
