import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE_file_saver__ from "file-saver";
import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__api_client_index_mjs__ from "../../api-client/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__ from "../../schema-component/index.mjs";
const defaultSettingItems = [
    {
        name: 'designer',
        type: 'itemGroup',
        hideIfNoChildren: true,
        useComponentProps () {
            const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
            return {
                title: t('Debug tools')
            };
        },
        children: [
            {
                name: 'dump',
                type: 'item',
                useComponentProps () {
                    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
                    const api = (0, __WEBPACK_EXTERNAL_MODULE__api_client_index_mjs__.useAPIClient)();
                    const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.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, __WEBPACK_EXTERNAL_MODULE_file_saver__.saveAs)(blob, fieldSchema['x-uid'] + '.schema.json');
                        },
                        title: t('Dump')
                    };
                }
            },
            {
                name: 'load',
                type: 'modal',
                useComponentProps () {
                    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
                    const { refresh } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useDesignable)();
                    const api = (0, __WEBPACK_EXTERNAL_MODULE__api_client_index_mjs__.useAPIClient)();
                    const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
                    const dn = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
                        const dn = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.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, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
                    const { refresh } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useDesignable)();
                    const api = (0, __WEBPACK_EXTERNAL_MODULE__api_client_index_mjs__.useAPIClient)();
                    const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
                    const dn = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
                        const dn = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.createDesignable)({
                            t,
                            api,
                            refresh,
                            current: fieldSchema.parent
                        });
                        dn.loadAPIClientEvents();
                        return dn;
                    }, [
                        t,
                        api,
                        refresh,
                        fieldSchema
                    ]);
                    const { data } = (0, __WEBPACK_EXTERNAL_MODULE__api_client_index_mjs__.useRequest)(async ()=>{
                        const { data } = await api.request({
                            url: "/uiSchemas:getJsonSchema/".concat(fieldSchema['x-uid'], "?includeAsyncNode=true")
                        });
                        return data;
                    });
                    return {
                        width: '800px',
                        disabled: !data,
                        schema: ()=>{
                            if (!data) return {
                                title: t('Edit loading.')
                            };
                            return {
                                type: 'object',
                                title: t('Edit'),
                                properties: {
                                    schema: {
                                        type: 'string',
                                        title: '{{ t("Schema") }}',
                                        required: true,
                                        default: JSON.stringify((null == data ? void 0 : data.data) || {}, null, 2),
                                        'x-decorator': 'FormItem',
                                        'x-component': 'CodeMirror',
                                        'x-component-props': {
                                            defaultLanguage: 'json',
                                            height: '500px'
                                        }
                                    }
                                }
                            };
                        },
                        title: data ? t('Edit') : t('Loading'),
                        onSubmit: async (param)=>{
                            let { schema } = param;
                            dn.emit('patch', {
                                schema: JSON.parse(schema)
                            });
                            dn.refresh();
                        }
                    };
                }
            },
            {
                name: 'values',
                type: 'modal',
                useComponentProps () {
                    const form = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useForm)();
                    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.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'
            }
        ]
    }
];
export { defaultSettingItems };
