import { jsx } from "react/jsx-runtime";
import { useCallback, useContext } from "react";
import { FormLayout } from "@tachybase/components";
import { SchemaOptionsContext } from "@tachybase/schema";
import { useTranslation } from "react-i18next";
import { useAPIClient } from "../../api-client/hooks/useAPIClient.mjs";
import { SchemaInitializerItem, useSchemaInitializer } from "../../application/index.mjs";
import { Icon } from "../../icon/index.mjs";
import { FormDialog, SchemaComponent, SchemaComponentOptions } from "../../schema-component/index.mjs";
import { useStyles } from "../../schema-component/antd/menu/MenuItemInitializers/index.mjs";
import { useGlobalTheme } from "../../style/theme/index.mjs";
const UploadMenuItem = ()=>{
    const { insert } = useSchemaInitializer();
    const { t } = useTranslation();
    const options = useContext(SchemaOptionsContext);
    const { theme } = useGlobalTheme();
    const { styles } = useStyles();
    useAPIClient();
    const handleClick = useCallback(async ()=>{
        const values = await FormDialog(t('Load menu config'), ()=>/*#__PURE__*/ jsx(SchemaComponentOptions, {
                scope: options.scope,
                components: {
                    ...options.components
                },
                children: /*#__PURE__*/ jsx(FormLayout, {
                    layout: 'vertical',
                    children: /*#__PURE__*/ jsx(SchemaComponent, {
                        schema: {
                            type: 'object',
                            title: t('Load menu config'),
                            properties: {
                                title: {
                                    'x-decorator': 'FormItem',
                                    'x-component': 'Input',
                                    title: t('Menu item title'),
                                    required: true,
                                    'x-component-props': {}
                                },
                                bindMenuToRole: {
                                    type: 'boolean',
                                    title: '{{ t("Automatically assign permissions to all matching roles") }}',
                                    'x-decorator': 'FormItem',
                                    'x-component': 'Checkbox',
                                    default: true
                                },
                                file: {
                                    type: 'object',
                                    title: '{{ t("File") }}',
                                    required: true,
                                    'x-decorator': 'FormItem',
                                    'x-component': 'Upload.Attachment',
                                    'x-component-props': {
                                        action: 'attachments:create',
                                        multiple: false
                                    }
                                }
                            }
                        }
                    })
                })
            }), theme).open({
            initialValues: {}
        });
        const { title, icon } = values;
    }, [
        insert,
        options.components,
        options.scope,
        t,
        theme
    ]);
    return /*#__PURE__*/ jsx(SchemaInitializerItem, {
        className: styles.menuItem,
        icon: /*#__PURE__*/ jsx(Icon, {
            type: 'UploadOutlined'
        }),
        title: t('Load menu config'),
        onClick: handleClick
    });
};
export { UploadMenuItem };
