import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash";
import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__ from "../../schema-component/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__util_mjs__ from "./util.mjs";
function createModalSettingsItem(options) {
    const { name, parentSchemaKey, valueKeys, schema, title, useSubmit = __WEBPACK_EXTERNAL_MODULE__util_mjs__.useHookDefault, useVisible, defaultValue: propsDefaultValue, useDefaultValue = __WEBPACK_EXTERNAL_MODULE__util_mjs__.useHookDefault, width, type = 'common' } = options;
    return {
        name,
        type: 'actionModal',
        useVisible,
        useComponentProps () {
            const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__util_mjs__.useSchemaByType)(type);
            const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useDesignable)();
            const defaultValue = useDefaultValue(propsDefaultValue);
            const values = parentSchemaKey ? __WEBPACK_EXTERNAL_MODULE_lodash__["default"].get(fieldSchema, parentSchemaKey) : void 0;
            const compile = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useCompile)();
            const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
            const onSubmit = useSubmit();
            const { fieldSchema: tableColumnSchema } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useColumnSchema)() || {};
            return {
                title: 'function' == typeof title ? title(t) : compile(title),
                width,
                schema: schema({
                    ...defaultValue,
                    ...values
                }),
                onSubmit (values) {
                    const newSchema = (0, __WEBPACK_EXTERNAL_MODULE__util_mjs__.getNewSchema)({
                        fieldSchema,
                        parentSchemaKey: parentSchemaKey,
                        value: values,
                        valueKeys
                    });
                    if (tableColumnSchema) {
                        dn.emit('patch', {
                            schema: newSchema
                        });
                        dn.refresh();
                    } else dn.deepMerge(newSchema);
                    return null == onSubmit ? void 0 : onSubmit(values);
                }
            };
        }
    };
}
export { createModalSettingsItem };
