"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = function(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 = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
(()=>{
    __webpack_require__.r = function(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__, {
    tabPaneInitializers: ()=>tabPaneInitializers,
    tabPaneInitializersForRecordBlock: ()=>tabPaneInitializersForRecordBlock,
    tabPaneInitializers_deprecated: ()=>tabPaneInitializers_deprecated,
    TabPaneInitializersForCreateFormBlock: ()=>TabPaneInitializersForCreateFormBlock,
    TabPaneInitializersForBulkEditFormBlock: ()=>TabPaneInitializersForBulkEditFormBlock,
    TabPaneInitializers: ()=>TabPaneInitializers,
    tabPaneInitializersForBulkEditFormBlock: ()=>tabPaneInitializersForBulkEditFormBlock
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const schema_namespaceObject = require("@tachybase/schema");
const external_antd_namespaceObject = require("antd");
require("file-saver");
const external_index_js_namespaceObject = require("../../index.js");
const SchemaInitializer_js_namespaceObject = require("../../application/schema-initializer/SchemaInitializer.js");
const useGetAriaLabelOfSchemaInitializer_js_namespaceObject = require("../hooks/useGetAriaLabelOfSchemaInitializer.js");
const TabPaneInitializers = (props)=>{
    const { designable, insertBeforeEnd } = (0, external_index_js_namespaceObject.useDesignable)();
    (0, schema_namespaceObject.useFieldSchema)();
    const { message } = external_antd_namespaceObject.App.useApp();
    const { isCreate, isBulkEdit, options } = props;
    const { gridInitializer } = options;
    const { getAriaLabel } = (0, useGetAriaLabelOfSchemaInitializer_js_namespaceObject.useGetAriaLabelOfSchemaInitializer)();
    const record = (0, external_index_js_namespaceObject.useRecord)();
    const useSubmitAction = ()=>{
        const form = (0, schema_namespaceObject.useForm)();
        const ctx = (0, external_index_js_namespaceObject.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, external_react_namespaceObject.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, external_index_js_namespaceObject.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, jsx_runtime_namespaceObject.jsx)(external_index_js_namespaceObject.SchemaComponent, {
        schema: schema
    });
};
const TabPaneInitializersForCreateFormBlock = (props)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(TabPaneInitializers, {
        ...props,
        isCreate: true
    });
const TabPaneInitializersForBulkEditFormBlock = (props)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(TabPaneInitializers, {
        ...props,
        isBulkEdit: true
    });
const commonOptions = {
    Component: TabPaneInitializers,
    popover: false
};
const tabPaneInitializers_deprecated = new SchemaInitializer_js_namespaceObject.SchemaInitializer({
    name: 'TabPaneInitializers',
    Component: TabPaneInitializers,
    popover: false
});
const tabPaneInitializers = new SchemaInitializer_js_namespaceObject.SchemaInitializer({
    name: 'popup:addTab',
    ...commonOptions
});
const tabPaneInitializersForRecordBlock = new SchemaInitializer_js_namespaceObject.SchemaInitializer({
    name: 'TabPaneInitializersForCreateFormBlock',
    Component: TabPaneInitializersForCreateFormBlock,
    popover: false
});
const tabPaneInitializersForBulkEditFormBlock = new SchemaInitializer_js_namespaceObject.SchemaInitializer({
    name: 'TabPaneInitializersForBulkEditFormBlock',
    Component: TabPaneInitializersForBulkEditFormBlock,
    popover: false
});
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
