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_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE_antd__ from "antd";
import "file-saver";
import * as __WEBPACK_EXTERNAL_MODULE__index_mjs__ from "../../index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__application_schema_initializer_SchemaInitializer_mjs__ from "../../application/schema-initializer/SchemaInitializer.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__hooks_useGetAriaLabelOfSchemaInitializer_mjs__ from "../hooks/useGetAriaLabelOfSchemaInitializer.mjs";
const TabPaneInitializers = (props)=>{
    const { designable, insertBeforeEnd } = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useDesignable)();
    (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    const { message } = __WEBPACK_EXTERNAL_MODULE_antd__.App.useApp();
    const { isCreate, isBulkEdit, options } = props;
    const { gridInitializer } = options;
    const { getAriaLabel } = (0, __WEBPACK_EXTERNAL_MODULE__hooks_useGetAriaLabelOfSchemaInitializer_mjs__.useGetAriaLabelOfSchemaInitializer)();
    const record = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useRecord)();
    const useSubmitAction = ()=>{
        const form = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useForm)();
        const ctx = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useActionContext)();
        let initializer = gridInitializer;
        if (!initializer) {
            initializer = 'popup:common:addBlock';
            if (isCreate || !record) initializer = 'popup:addNew:addBlock';
            else if (isBulkEdit) initializer = 'popup:bulkEdit:addBlock';
        }
        return {
            async run () {
                await form.submit();
                const { title, icon } = form.values;
                insertBeforeEnd({
                    type: 'void',
                    title,
                    'x-component': 'Tabs.TabPane',
                    'x-designer': 'Tabs.Designer',
                    'x-component-props': {
                        icon
                    },
                    properties: {
                        grid: {
                            type: 'void',
                            'x-component': 'Grid',
                            'x-initializer': initializer,
                            properties: {}
                        }
                    }
                });
                await form.reset();
                ctx.setVisible(false);
            }
        };
    };
    const schema = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
            type: 'void',
            properties: {
                fixStyle: {
                    type: 'void',
                    'x-component': 'div',
                    'x-component-props': {
                        style: {
                            display: 'flex'
                        }
                    },
                    properties: {
                        action1: {
                            type: 'void',
                            'x-component': 'Action',
                            'x-component-props': {
                                icon: 'PlusOutlined',
                                style: {
                                    borderColor: 'var(--colorSettings)',
                                    color: 'var(--colorSettings)'
                                },
                                type: 'dashed',
                                'aria-label': getAriaLabel()
                            },
                            title: '{{t("Add tab")}}',
                            properties: {
                                drawer1: {
                                    'x-decorator': 'Form',
                                    'x-component': 'Action.Modal',
                                    'x-component-props': {
                                        width: 520
                                    },
                                    type: 'void',
                                    title: '{{t("Add tab")}}',
                                    properties: {
                                        title: {
                                            title: '{{t("Tab name")}}',
                                            required: true,
                                            'x-component': 'Input',
                                            'x-decorator': 'FormItem'
                                        },
                                        icon: {
                                            title: '{{t("Icon")}}',
                                            'x-component': 'IconPicker',
                                            'x-decorator': 'FormItem'
                                        },
                                        footer: {
                                            'x-component': 'Action.Modal.Footer',
                                            type: 'void',
                                            properties: {
                                                cancel: {
                                                    title: '{{t("Cancel")}}',
                                                    'x-component': 'Action',
                                                    'x-component-props': {
                                                        useAction: ()=>{
                                                            const ctx = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useActionContext)();
                                                            return {
                                                                async run () {
                                                                    ctx.setVisible(false);
                                                                }
                                                            };
                                                        }
                                                    }
                                                },
                                                submit: {
                                                    title: '{{t("Submit")}}',
                                                    'x-component': 'Action',
                                                    'x-component-props': {
                                                        type: 'primary',
                                                        useAction: useSubmitAction
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }), []);
    if (!designable) return null;
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__index_mjs__.SchemaComponent, {
        schema: schema
    });
};
const TabPaneInitializersForCreateFormBlock = (props)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(TabPaneInitializers, {
        ...props,
        isCreate: true
    });
const TabPaneInitializersForBulkEditFormBlock = (props)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(TabPaneInitializers, {
        ...props,
        isBulkEdit: true
    });
const tabPaneInitializers_deprecated = new __WEBPACK_EXTERNAL_MODULE__application_schema_initializer_SchemaInitializer_mjs__.SchemaInitializer({
    name: 'TabPaneInitializers',
    Component: TabPaneInitializers,
    popover: false
});
const tabPaneInitializersForRecordBlock = new __WEBPACK_EXTERNAL_MODULE__application_schema_initializer_SchemaInitializer_mjs__.SchemaInitializer({
    name: 'TabPaneInitializersForCreateFormBlock',
    Component: TabPaneInitializersForCreateFormBlock,
    popover: false
});
const tabPaneInitializersForBulkEditFormBlock = new __WEBPACK_EXTERNAL_MODULE__application_schema_initializer_SchemaInitializer_mjs__.SchemaInitializer({
    name: 'TabPaneInitializersForBulkEditFormBlock',
    Component: TabPaneInitializersForBulkEditFormBlock,
    popover: false
});
export { TabPaneInitializers, TabPaneInitializersForBulkEditFormBlock, TabPaneInitializersForCreateFormBlock, tabPaneInitializersForBulkEditFormBlock, tabPaneInitializersForRecordBlock, tabPaneInitializers_deprecated };
