"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__, {
    TableColumnDesigner: ()=>TableColumnDesigner
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
require("react");
const schema_namespaceObject = require("@tachybase/schema");
const external_lodash_namespaceObject = require("lodash");
var external_lodash_default = /*#__PURE__*/ __webpack_require__.n(external_lodash_namespaceObject);
const index_js_namespaceObject = require("../../../collection-manager/index.js");
const external_schema_settings_index_js_namespaceObject = require("../../../schema-settings/index.js");
const external_hooks_index_js_namespaceObject = require("../../hooks/index.js");
const external_action_index_js_namespaceObject = require("../action/index.js");
const useLabelFields = (collectionName)=>{
    var _targetFields_filter_map, _targetFields_filter, _targetFields_filter1;
    const compile = (0, external_hooks_index_js_namespaceObject.useCompile)();
    const { getCollectionFields } = (0, index_js_namespaceObject.useCollectionManager_deprecated)();
    if (!collectionName) return [];
    const targetFields = getCollectionFields(collectionName);
    return null == targetFields ? void 0 : null === (_targetFields_filter1 = targetFields.filter) || void 0 === _targetFields_filter1 ? void 0 : null === (_targetFields_filter = _targetFields_filter1.call(targetFields, (field)=>!(null == field ? void 0 : field.target) && 'boolean' !== field.type)) || void 0 === _targetFields_filter ? void 0 : null === (_targetFields_filter_map = _targetFields_filter.map) || void 0 === _targetFields_filter_map ? void 0 : _targetFields_filter_map.call(_targetFields_filter, (field)=>{
        var _field_uiSchema;
        return {
            value: field.name,
            label: compile((null == field ? void 0 : null === (_field_uiSchema = field.uiSchema) || void 0 === _field_uiSchema ? void 0 : _field_uiSchema.title) || field.name)
        };
    });
};
const TableColumnDesigner = (props)=>{
    var _collectionField_uiSchema, _fieldSchema_xcomponentprops_fieldNames, _fieldSchema_xcomponentprops;
    const { uiSchema, fieldSchema, collectionField } = props;
    const field = (0, schema_namespaceObject.useField)();
    const columnSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { dn } = (0, external_hooks_index_js_namespaceObject.useDesignable)();
    const initialValue = {
        title: null == columnSchema ? void 0 : columnSchema.title
    };
    const options = useLabelFields(null == collectionField ? void 0 : collectionField.target);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_schema_settings_index_js_namespaceObject.GeneralSchemaDesigner, {
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_settings_index_js_namespaceObject.SchemaSettingsPopupItem, {
                title: '编辑',
                schema: {
                    title: '编辑字段',
                    'x-component': 'Action.Modal',
                    'x-component-props': {
                        width: 520
                    },
                    'x-decorator': 'Form',
                    'x-decorator-props': {
                        initialValue
                    },
                    type: 'void',
                    properties: {
                        title: {
                            'x-decorator': 'FormItem',
                            'x-component': 'Input',
                            title: '字段标题',
                            'x-component-props': {},
                            description: "原字段标题：".concat(null == collectionField ? void 0 : null === (_collectionField_uiSchema = collectionField.uiSchema) || void 0 === _collectionField_uiSchema ? void 0 : _collectionField_uiSchema.title)
                        },
                        footer: {
                            type: 'void',
                            'x-component': 'Action.Modal.Footer',
                            properties: {
                                cancel: {
                                    type: 'void',
                                    title: '{{t("Cancel")}}',
                                    'x-component': 'Action',
                                    'x-component-props': {
                                        useAction () {
                                            const ctx = (0, external_action_index_js_namespaceObject.useActionContext)();
                                            return {
                                                async run () {
                                                    ctx.setVisible(false);
                                                }
                                            };
                                        }
                                    }
                                },
                                submit: {
                                    type: 'void',
                                    title: 'Submit',
                                    'x-component': 'Action',
                                    'x-component-props': {
                                        type: 'primary',
                                        useAction () {
                                            const form = (0, schema_namespaceObject.useForm)();
                                            const ctx = (0, external_action_index_js_namespaceObject.useActionContext)();
                                            return {
                                                async run () {
                                                    const { title } = form.values;
                                                    if (title) {
                                                        field.title = title;
                                                        columnSchema.title = title;
                                                        dn.emit('patch', {
                                                            schema: {
                                                                'x-uid': columnSchema['x-uid'],
                                                                title: columnSchema.title
                                                            }
                                                        });
                                                    }
                                                    ctx.setVisible(false);
                                                    dn.refresh();
                                                }
                                            };
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }),
            (null == collectionField ? void 0 : collectionField.target) && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_settings_index_js_namespaceObject.SchemaSettingsSelectItem, {
                title: '标题字段',
                options: options,
                value: null == fieldSchema ? void 0 : null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : null === (_fieldSchema_xcomponentprops_fieldNames = _fieldSchema_xcomponentprops['fieldNames']) || void 0 === _fieldSchema_xcomponentprops_fieldNames ? void 0 : _fieldSchema_xcomponentprops_fieldNames['label'],
                onChange: (label)=>{
                    var _fieldSchema_xcomponentprops;
                    const fieldNames = {
                        ...null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops['fieldNames'],
                        label
                    };
                    external_lodash_default().set(fieldSchema, 'x-component-props.fieldNames', fieldNames);
                    field.query(".*.".concat(fieldSchema.name)).take((f)=>{
                        f.componentProps.fieldNames = fieldNames;
                    });
                    dn.emit('patch', {
                        schema: {
                            'x-uid': fieldSchema['x-uid'],
                            'x-component-props': {
                                fieldNames
                            }
                        }
                    });
                    dn.refresh();
                }
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_settings_index_js_namespaceObject.SchemaSettingsDivider, {}),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_settings_index_js_namespaceObject.SchemaSettingsRemove, {
                removeParentsIfNoChildren: true,
                breakRemoveOn: {
                    'x-component': 'Grid'
                }
            })
        ]
    });
};
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
});
