"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__, {
    defaultSettingItems: ()=>defaultSettingItems
});
const external_react_namespaceObject = require("react");
const schema_namespaceObject = require("@tachybase/schema");
const external_file_saver_namespaceObject = require("file-saver");
const external_react_i18next_namespaceObject = require("react-i18next");
const index_js_namespaceObject = require("../../api-client/index.js");
const external_schema_component_index_js_namespaceObject = require("../../schema-component/index.js");
const defaultSettingItems = [
    {
        name: 'designer',
        type: 'itemGroup',
        hideIfNoChildren: true,
        useComponentProps () {
            const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
            return {
                title: t('Debug tools')
            };
        },
        children: [
            {
                name: 'dump',
                type: 'item',
                useComponentProps () {
                    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                    const api = (0, index_js_namespaceObject.useAPIClient)();
                    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                    return {
                        onClick: async ()=>{
                            const KEYS = [
                                'name',
                                'x-uid',
                                '_isJSONSchemaObject',
                                'version',
                                'x-index',
                                'x-async'
                            ];
                            const deleteUid = (s)=>{
                                KEYS.forEach((key)=>delete s[key]);
                                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['x-uid'] + '.schema.json');
                        },
                        title: t('Dump')
                    };
                }
            },
            {
                name: 'load',
                type: 'modal',
                useComponentProps () {
                    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                    const { refresh } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
                    const api = (0, index_js_namespaceObject.useAPIClient)();
                    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                    const dn = (0, external_react_namespaceObject.useMemo)(()=>{
                        const dn = (0, external_schema_component_index_js_namespaceObject.createDesignable)({
                            t,
                            api,
                            refresh,
                            current: fieldSchema.parent
                        });
                        dn.loadAPIClientEvents();
                        return dn;
                    }, [
                        t,
                        api,
                        refresh,
                        fieldSchema
                    ]);
                    return {
                        schema: {
                            type: 'object',
                            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
                                    }
                                }
                            }
                        },
                        title: t('Load'),
                        onSubmit: async (param)=>{
                            let { file } = param;
                            const { data } = await api.request({
                                url: file.url,
                                baseURL: '/'
                            });
                            const s = null != data ? data : {};
                            dn.insertBeforeEnd(s);
                        }
                    };
                }
            },
            {
                name: 'edit',
                type: 'modal',
                useComponentProps () {
                    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                    const { refresh } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
                    const api = (0, index_js_namespaceObject.useAPIClient)();
                    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                    const dn = (0, external_react_namespaceObject.useMemo)(()=>{
                        const dn = (0, external_schema_component_index_js_namespaceObject.createDesignable)({
                            t,
                            api,
                            refresh,
                            current: fieldSchema.parent
                        });
                        dn.loadAPIClientEvents();
                        return dn;
                    }, [
                        t,
                        api,
                        refresh,
                        fieldSchema
                    ]);
                    return {
                        width: '800px',
                        asyncGetInitialValues: async ()=>{
                            const { data } = await api.request({
                                url: "/uiSchemas:getJsonSchema/".concat(fieldSchema['x-uid'], "?includeAsyncNode=true")
                            });
                            return {
                                schema: JSON.stringify((null == data ? void 0 : data.data) || {}, null, 2)
                            };
                        },
                        schema: ()=>({
                                type: 'object',
                                title: t('Edit'),
                                properties: {
                                    schema: {
                                        type: 'string',
                                        title: '{{ t("Schema") }}',
                                        required: true,
                                        'x-decorator': 'FormItem',
                                        'x-component': 'CodeMirror',
                                        'x-component-props': {
                                            defaultLanguage: 'json',
                                            height: '500px'
                                        }
                                    }
                                }
                            }),
                        title: t('Edit'),
                        onSubmit: async (param)=>{
                            let { schema } = param;
                            dn.emit('patch', {
                                schema: JSON.parse(schema)
                            });
                            dn.refresh();
                        }
                    };
                }
            },
            {
                name: 'values',
                type: 'modal',
                useComponentProps () {
                    const form = (0, schema_namespaceObject.useForm)();
                    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
                    return {
                        width: '800px',
                        schema: ()=>({
                                type: 'object',
                                title: t('Values'),
                                properties: {
                                    values: {
                                        type: 'string',
                                        title: '{{ t("Schema") }}',
                                        default: JSON.stringify(form.values, null, 2),
                                        'x-decorator': 'FormItem',
                                        'x-component': 'CodeMirror',
                                        'x-component-props': {
                                            defaultLanguage: 'json',
                                            height: '500px'
                                        }
                                    }
                                }
                            }),
                        title: t('Values'),
                        onSubmit: ()=>{}
                    };
                }
            },
            {
                name: 'divider',
                type: 'divider'
            }
        ]
    }
];
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
});
