"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = function(module) {
        var getter = module && module.__esModule ? function() {
            return module['default'];
        } : function() {
            return module;
        };
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __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__, {
    XlsxEditFieldAction: ()=>XlsxEditFieldAction
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const components_namespaceObject = require("@tachybase/components");
const schema_namespaceObject = require("@tachybase/schema");
const external_lodash_namespaceObject = require("lodash");
const external_react_i18next_namespaceObject = require("react-i18next");
const index_js_namespaceObject = require("../../../api-client/index.js");
const external_record_provider_index_js_namespaceObject = require("../../../record-provider/index.js");
const external_schema_component_index_js_namespaceObject = require("../../../schema-component/index.js");
const external_action_hooks_js_namespaceObject = require("../../action-hooks.js");
const external_hooks_index_js_namespaceObject = require("../../hooks/index.js");
const useDialect_js_namespaceObject = require("../../hooks/useDialect.js");
var useDialect_js_default = /*#__PURE__*/ __webpack_require__.n(useDialect_js_namespaceObject);
const external_components_index_js_namespaceObject = require("../components/index.js");
const external_setUpdateXlsxCollectionField_js_namespaceObject = require("./setUpdateXlsxCollectionField.js");
const XlsxEditFieldAction = (props)=>{
    const { scope, getContainer, record, parentItem: parentRecord, children, handleUiSchemaChange, ...otherProps } = props;
    const { getInterface, collections, getCollection } = (0, external_hooks_index_js_namespaceObject.useCollectionManager_deprecated)();
    const [visible, setVisible] = (0, external_react_namespaceObject.useState)(false);
    const [schema, setSchema] = (0, external_react_namespaceObject.useState)({});
    (0, index_js_namespaceObject.useAPIClient)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const compile = (0, external_schema_component_index_js_namespaceObject.useCompile)();
    const [data, setData] = (0, external_react_namespaceObject.useState)({
        record
    });
    const { isDialect } = useDialect_js_default()();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_record_provider_index_js_namespaceObject.RecordProvider, {
        record: record,
        parent: parentRecord,
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_schema_component_index_js_namespaceObject.ActionContextProvider, {
            value: {
                visible,
                setVisible
            },
            children: [
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("a", {
                    ...otherProps,
                    onClick: async ()=>{
                        setData(record);
                        const interfaceConf = getInterface(record.interface);
                        const defaultValues = (0, external_lodash_namespaceObject.cloneDeep)(record) || {};
                        if (!(null == defaultValues ? void 0 : defaultValues.reverseField)) {
                            var _interfaceConf_default;
                            defaultValues.autoCreateReverseField = false;
                            defaultValues.reverseField = null == interfaceConf ? void 0 : null === (_interfaceConf_default = interfaceConf.default) || void 0 === _interfaceConf_default ? void 0 : _interfaceConf_default.reverseField;
                            (0, external_lodash_namespaceObject.set)(defaultValues.reverseField, 'name', record.name);
                            (0, external_lodash_namespaceObject.set)(defaultValues, 'uiSchema.title', record.uiSchema.title);
                        }
                        const schema = getSchema({
                            ...interfaceConf,
                            default: defaultValues
                        }, record, compile, getContainer);
                        setSchema(schema);
                        setVisible(true);
                    },
                    children: children || t('Edit')
                }),
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_component_index_js_namespaceObject.SchemaComponent, {
                    schema: schema,
                    components: {
                        ...external_components_index_js_namespaceObject,
                        ArrayTable: components_namespaceObject.ArrayTable
                    },
                    scope: {
                        getContainer,
                        useCancelAction: external_action_hooks_js_namespaceObject.useCancelAction,
                        showReverseFieldConfig: !(null == data ? void 0 : data.reverseField),
                        isDialect,
                        setUpdateXlsxCollectionField: external_setUpdateXlsxCollectionField_js_namespaceObject.setUpdateXlsxCollectionField,
                        disabledJSONB: true,
                        createMainOnly: true,
                        ...scope
                    }
                })
            ]
        })
    });
};
const getSchema = (schema, record, compile, getContainer)=>{
    if (!schema) return;
    const properties = (0, external_lodash_namespaceObject.cloneDeep)(schema.properties);
    if (null == properties ? void 0 : properties.name) properties.name['x-disabled'] = true;
    if (true === schema.hasDefaultValue) {
        properties['defaultValue'] = (0, external_lodash_namespaceObject.cloneDeep)(schema.default) || {};
        properties.defaultValue.required = false;
        properties['defaultValue']['title'] = compile('{{ t("Default value") }}');
        properties['defaultValue']['x-decorator'] = 'FormItem';
        properties['defaultValue']['x-reactions'] = [
            {
                dependencies: [
                    'uiSchema.x-component-props.gmt',
                    'uiSchema.x-component-props.showTime',
                    'uiSchema.x-component-props.dateFormat',
                    'uiSchema.x-component-props.timeFormat'
                ],
                fulfill: {
                    state: {
                        componentProps: {
                            gmt: '{{$deps[0]}}',
                            showTime: '{{$deps[1]}}',
                            dateFormat: '{{$deps[2]}}',
                            timeFormat: '{{$deps[3]}}'
                        }
                    }
                }
            },
            {
                dependencies: [
                    'primaryKey',
                    'unique',
                    'autoIncrement'
                ],
                when: '{{$deps[0]||$deps[1]||$deps[2]}}',
                fulfill: {
                    state: {
                        hidden: true,
                        value: void 0
                    }
                },
                otherwise: {
                    state: {
                        hidden: false
                    }
                }
            }
        ];
    }
    return {
        type: 'object',
        properties: {
            [(0, schema_namespaceObject.uid)()]: {
                type: 'void',
                'x-component': 'Action.Drawer',
                'x-component-props': {
                    getContainer: getContainer
                },
                'x-decorator': 'Form',
                'x-decorator-props': {
                    useValues (options) {
                        return (0, index_js_namespaceObject.useRequest)(()=>Promise.resolve({
                                data: (0, external_lodash_namespaceObject.cloneDeep)((0, external_lodash_namespaceObject.omit)(schema.default, [
                                    'uiSchema.rawTitle'
                                ]))
                            }), options);
                    }
                },
                title: "".concat(compile(record.uiSchema.title), " - ").concat(compile('{{ t("Edit field") }}')),
                properties: {
                    summary: {
                        type: 'void',
                        'x-component': 'FieldSummary',
                        'x-component-props': {
                            schemaKey: schema.name
                        }
                    },
                    ...properties,
                    description: {
                        type: 'string',
                        title: '{{t("Description")}}',
                        'x-decorator': 'FormItem',
                        'x-component': 'Input.TextArea'
                    },
                    footer: {
                        type: 'void',
                        'x-component': 'Action.Drawer.Footer',
                        properties: {
                            action1: {
                                title: '{{ t("Cancel") }}',
                                'x-component': 'Action',
                                'x-use-component-props': 'useCancelActionProps'
                            },
                            action2: {
                                title: '{{ t("Submit") }}',
                                'x-component': 'Action',
                                'x-component-props': {
                                    type: 'primary'
                                },
                                'x-use-component-props': 'setUpdateXlsxCollectionField'
                            }
                        }
                    }
                }
            }
        }
    };
};
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
});
