"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__, {
    TabsDesigner: ()=>TabsDesigner
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
require("react");
const schema_namespaceObject = require("@tachybase/schema");
const external_antd_namespaceObject = require("antd");
const external_file_saver_namespaceObject = require("file-saver");
const external_react_i18next_namespaceObject = require("react-i18next");
const external_index_js_namespaceObject = require("../../index.js");
const external_index_js_namespaceObject_1 = require("../../../index.js");
const TabsDesigner = ()=>{
    const field = (0, schema_namespaceObject.useField)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { dn } = (0, external_index_js_namespaceObject.useDesignable)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const api = (0, external_index_js_namespaceObject_1.useAPIClient)();
    const { message } = external_antd_namespaceObject.App.useApp();
    const actionField = (0, schema_namespaceObject.useField)();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_index_js_namespaceObject_1.GeneralSchemaDesigner, {
        disableInitializer: true,
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_js_namespaceObject_1.SchemaSettingsModalItem, {
                title: t('Edit'),
                schema: {
                    type: 'object',
                    title: t('Edit tab'),
                    properties: {
                        title: {
                            title: t('Tab name'),
                            required: true,
                            'x-decorator': 'FormItem',
                            'x-component': 'Input',
                            'x-component-props': {}
                        },
                        icon: {
                            title: t('Icon'),
                            'x-decorator': 'FormItem',
                            'x-component': 'IconPicker',
                            'x-component-props': {}
                        }
                    }
                },
                initialValues: {
                    title: field.title,
                    icon: field.componentProps.icon
                },
                onSubmit: (param)=>{
                    let { title, icon } = param;
                    const props = fieldSchema['x-component-props'] || {};
                    fieldSchema.title = title;
                    field.title = title;
                    props.icon = icon;
                    field.componentProps.icon = icon;
                    fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {};
                    fieldSchema['x-component-props'].icon = icon;
                    dn.emit('patch', {
                        schema: {
                            ['x-uid']: fieldSchema['x-uid'],
                            title,
                            ['x-component-props']: props
                        }
                    });
                    dn.refresh();
                }
            }, "edit"),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_js_namespaceObject_1.SchemaSettingsItem, {
                title: t('Dump'),
                onClick: async ()=>{
                    const deleteUid = (s)=>{
                        delete s['name'];
                        delete s['x-uid'];
                        Object.keys(s.properties || {}).forEach((key)=>{
                            deleteUid(s.properties[key]);
                        });
                    };
                    const { data } = await api.request({
                        url: "/uiSchemas:getJsonSchema/".concat(fieldSchema['x-uid'], "?includeAsyncNode=true")
                    });
                    const s = (null == data ? void 0 : data.data) || {};
                    deleteUid(s);
                    const blob = new Blob([
                        JSON.stringify(s, null, 2)
                    ], {
                        type: 'application/json'
                    });
                    (0, external_file_saver_namespaceObject.saveAs)(blob, fieldSchema.parent['x-uid'] + '.schema.json');
                    message.success('Save successful!');
                }
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_js_namespaceObject_1.SchemaSettingsModalItem, {
                title: t('Load'),
                schema: {
                    'x-decorator': 'Form',
                    'x-component': 'Action.Modal',
                    'x-component-props': {
                        width: 520
                    },
                    type: 'void',
                    title: t('Load'),
                    properties: {
                        file: {
                            type: 'object',
                            title: '{{ t("File") }}',
                            required: true,
                            'x-decorator': 'FormItem',
                            'x-component': 'Upload.Attachment',
                            'x-component-props': {
                                action: 'attachments:create',
                                multiple: false
                            }
                        }
                    }
                },
                onSubmit: async (param)=>{
                    let { file } = param;
                    var _actionField;
                    var _data;
                    null !== (_data = (_actionField = actionField).data) && void 0 !== _data || (_actionField.data = {});
                    actionField.data.loading = true;
                    const { data } = await api.request({
                        url: file.url,
                        baseURL: '/'
                    });
                    const s = null != data ? data : {};
                    dn.insertAfterEnd(s);
                    actionField.data.loading = false;
                }
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_js_namespaceObject_1.SchemaSettingsDivider, {}),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_js_namespaceObject_1.SchemaSettingsRemove, {})
        ]
    });
};
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
});
