import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE__ant_design_icons__ from "@ant-design/icons";
import * as __WEBPACK_EXTERNAL_MODULE_ahooks__ from "ahooks";
import * as __WEBPACK_EXTERNAL_MODULE_antd__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE__application_index_mjs__ from "../../application/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__ from "../../schema-component/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__pinned_list_index_mjs__ from "../pinned-list/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__useContextMenu_mjs__ from "./useContextMenu.mjs";
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, __WEBPACK_EXTERNAL_MODULE_ahooks__.useLocalStorageState)(STORAGE_KEYS.CONTEXT_MENU_ENABLED, {
        defaultValue: true
    });
    const [showScrollArea, setShowScrollArea] = (0, __WEBPACK_EXTERNAL_MODULE_ahooks__.useLocalStorageState)(STORAGE_KEYS.SHOW_SCROLL_AREA, {
        defaultValue: false
    });
    const contextItems = (0, __WEBPACK_EXTERNAL_MODULE__application_index_mjs__.useApp)().pluginContextMenu.get();
    const [position, setPosition] = (0, __WEBPACK_EXTERNAL_MODULE_react__.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, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__useContextMenu_mjs__.ContextMenuContext.Provider, {
        value: {
            contextMenuEnabled: enable,
            setContextMenuEnable: setEnable,
            showScrollArea,
            setShowScrollArea,
            position
        },
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Dropdown, {
            menu: {
                items
            },
            trigger: enable ? [
                'contextMenu'
            ] : [],
            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                onContextMenu: (e)=>{
                    setPosition({
                        x: e.clientX,
                        y: e.clientY
                    });
                },
                children: children
            })
        })
    });
};
const ContextMenuButton = ()=>{
    const { contextMenuEnabled, setContextMenuEnable } = (0, __WEBPACK_EXTERNAL_MODULE__useContextMenu_mjs__.useContextMenu)();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.FloatButton, {
        type: contextMenuEnabled ? 'primary' : 'default',
        icon: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__ant_design_icons__.ToolOutlined, {}),
        onClick: ()=>setContextMenuEnable(!contextMenuEnabled)
    });
};
const ContextMenuButtonProvider = (props)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__pinned_list_index_mjs__.PinnedPluginListProvider, {
        items: {
            cm: {
                order: 90,
                component: 'ContextMenuButton',
                pin: true,
                isPublic: true,
                belongTo: 'hoverbutton'
            }
        },
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.SchemaComponentOptions, {
            components: {
                ContextMenuButton
            },
            children: props.children
        })
    });
export { ContextMenuButtonProvider, ContextMenuProvider };
