"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = (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 = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (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__, {
    LinkMenuItem: ()=>LinkMenuItem
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const components_namespaceObject = require("@tachybase/components");
const schema_namespaceObject = require("@tachybase/schema");
const external_react_i18next_namespaceObject = require("react-i18next");
const index_js_namespaceObject = require("../../application/index.js");
const external_icon_index_js_namespaceObject = require("../../icon/index.js");
const external_schema_component_index_js_namespaceObject = require("../../schema-component/index.js");
const MenuItemInitializers_index_js_namespaceObject = require("../../schema-component/antd/menu/MenuItemInitializers/index.js");
const theme_index_js_namespaceObject = require("../../style/theme/index.js");
const LinkMenuItem = ()=>{
    const { insert } = (0, index_js_namespaceObject.useSchemaInitializer)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const options = (0, external_react_namespaceObject.useContext)(schema_namespaceObject.SchemaOptionsContext);
    const { theme } = (0, theme_index_js_namespaceObject.useGlobalTheme)();
    const { styles } = (0, MenuItemInitializers_index_js_namespaceObject.useStyles)();
    const handleClick = (0, external_react_namespaceObject.useCallback)(async ()=>{
        const values = await (0, external_schema_component_index_js_namespaceObject.FormDialog)(t('Add link'), ()=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_component_index_js_namespaceObject.SchemaComponentOptions, {
                scope: options.scope,
                components: {
                    ...options.components
                },
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(components_namespaceObject.FormLayout, {
                    layout: 'vertical',
                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_component_index_js_namespaceObject.SchemaComponent, {
                        schema: {
                            properties: {
                                title: {
                                    title: t('Menu item title'),
                                    required: true,
                                    'x-component': 'Input',
                                    'x-decorator': 'FormItem'
                                },
                                icon: {
                                    title: t('Icon'),
                                    'x-component': 'IconPicker',
                                    'x-decorator': 'FormItem'
                                },
                                href: {
                                    title: t('Link'),
                                    'x-component': 'Input',
                                    'x-decorator': 'FormItem'
                                }
                            }
                        }
                    })
                })
            }), theme).open({
            initialValues: {}
        });
        const { title, href, icon } = values;
        insert({
            type: 'void',
            title,
            'x-component': 'Menu.URL',
            'x-decorator': 'ACLMenuItemProvider',
            'x-component-props': {
                icon,
                href
            },
            'x-server-hooks': [
                {
                    type: 'onSelfCreate',
                    method: 'bindMenuToRole'
                },
                {
                    type: 'onSelfSave',
                    method: 'extractTextToLocale'
                }
            ]
        });
    }, [
        insert,
        options.components,
        options.scope,
        t,
        theme
    ]);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.SchemaInitializerItem, {
        className: styles.menuItem,
        icon: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_icon_index_js_namespaceObject.Icon, {
            type: 'GlobalOutlined'
        }),
        title: t('Create link'),
        onClick: handleClick
    });
};
exports.LinkMenuItem = __webpack_exports__.LinkMenuItem;
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
    "LinkMenuItem"
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
Object.defineProperty(exports, '__esModule', {
    value: true
});
