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__tachybase_components__ from "@tachybase/components";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__application_index_mjs__ from "../../application/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__icon_index_mjs__ from "../../icon/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__ from "../../schema-component/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_antd_menu_MenuItemInitializers_index_mjs__ from "../../schema-component/antd/menu/MenuItemInitializers/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__style_theme_index_mjs__ from "../../style/theme/index.mjs";
const PageMenuItem = ()=>{
    const { insert } = (0, __WEBPACK_EXTERNAL_MODULE__application_index_mjs__.useSchemaInitializer)();
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    const options = (0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(__WEBPACK_EXTERNAL_MODULE__tachybase_schema__.SchemaOptionsContext);
    const { theme } = (0, __WEBPACK_EXTERNAL_MODULE__style_theme_index_mjs__.useGlobalTheme)();
    const { styles } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_antd_menu_MenuItemInitializers_index_mjs__.useStyles)();
    const handleClick = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)(async ()=>{
        const values = await (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.FormDialog)(t('Add page'), ()=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.SchemaComponentOptions, {
                scope: options.scope,
                components: {
                    ...options.components
                },
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_components__.FormLayout, {
                    layout: 'vertical',
                    children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.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'
                                }
                            }
                        }
                    })
                })
            }), theme).open({
            initialValues: {}
        });
        const { title, icon } = values;
        insert({
            type: 'void',
            title,
            'x-component': 'Menu.Item',
            'x-decorator': 'ACLMenuItemProvider',
            'x-component-props': {
                icon
            },
            'x-server-hooks': [
                {
                    type: 'onSelfCreate',
                    method: 'bindMenuToRole'
                },
                {
                    type: 'onSelfSave',
                    method: 'extractTextToLocale'
                }
            ],
            properties: {
                page: {
                    type: 'void',
                    'x-component': 'Page',
                    'x-async': true,
                    properties: {
                        [(0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.uid)()]: {
                            type: 'void',
                            'x-component': 'Grid',
                            'x-initializer': 'page:addBlock',
                            properties: {}
                        }
                    }
                }
            }
        });
    }, [
        insert,
        options.components,
        options.scope,
        t,
        theme
    ]);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__application_index_mjs__.SchemaInitializerItem, {
        icon: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__icon_index_mjs__.Icon, {
            type: 'FileOutlined'
        }),
        title: t('Create page'),
        onClick: handleClick,
        className: styles.menuItem
    });
};
export { PageMenuItem };
