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 createSwitchSettingsItem(options) {
    const { name, useVisible, schemaKey, title, type = 'common', defaultValue: propsDefaultValue, useDefaultValue = __WEBPACK_EXTERNAL_MODULE__util_mjs__.useHookDefault } = options;
    return {
        name,
        useVisible,
        type: 'switch',
        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 compile = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useCompile)();
            const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
            const { fieldSchema: tableColumnSchema } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useColumnSchema)() || {};
            return {
                title: 'function' == typeof title ? title(t) : compile(title),
                checked: !!__WEBPACK_EXTERNAL_MODULE_lodash__["default"].get(fieldSchema, schemaKey, defaultValue),
                onChange (v) {
                    const newSchema = (0, __WEBPACK_EXTERNAL_MODULE__util_mjs__.getNewSchema)({
                        fieldSchema,
                        schemaKey,
                        value: v
                    });
                    if (tableColumnSchema) {
                        dn.emit('patch', {
                            schema: newSchema
                        });
                        dn.refresh();
                    } else dn.deepMerge(newSchema);
                }
            };
        }
    };
}
export { createSwitchSettingsItem };
