"use strict";
var __webpack_require__ = {};
(()=>{
    __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__, {
    useFilterableFields: ()=>useFilterableFields,
    FilterActionDesigner: ()=>FilterActionDesigner,
    FilterableFieldsSchemaSettingsItem: ()=>FilterableFieldsSchemaSettingsItem
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
require("react");
const schema_namespaceObject = require("@tachybase/schema");
const external_react_i18next_namespaceObject = require("react-i18next");
const external_index_js_namespaceObject = require("../../index.js");
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 useFilterableFields = (collectionName)=>{
    var _fields_filter;
    const { getCollectionFields, getInterface } = (0, index_js_namespaceObject.useCollectionManager_deprecated)();
    const fields = getCollectionFields(collectionName);
    return null == fields ? void 0 : null === (_fields_filter = fields.filter) || void 0 === _fields_filter ? void 0 : _fields_filter.call(fields, (field)=>{
        if (!field.interface) return false;
        const fieldInterface = getInterface(field.interface);
        if (!(null == fieldInterface ? void 0 : fieldInterface.filterable)) return false;
        return true;
    });
};
const FilterableFieldsSchemaSettingsItem = ()=>{
    var _fieldSchema_xcomponentprops;
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { dn } = (0, external_index_js_namespaceObject.useDesignable)();
    const { name } = (0, index_js_namespaceObject.useCollection_deprecated)();
    const fields = useFilterableFields(name);
    const compile = (0, external_hooks_index_js_namespaceObject.useCompile)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const nonfilterable = (null == fieldSchema ? void 0 : null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops.nonfilterable) || [];
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_settings_index_js_namespaceObject.SchemaSettingsItemGroup, {
        title: t('Filterable fields'),
        children: fields.map((field)=>{
            var _field_uiSchema;
            const checked = !nonfilterable.includes(field.name);
            return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_settings_index_js_namespaceObject.SchemaSettingsSwitchItem, {
                checked: checked,
                title: compile(null == field ? void 0 : null === (_field_uiSchema = field.uiSchema) || void 0 === _field_uiSchema ? void 0 : _field_uiSchema.title),
                onChange: (value)=>{
                    var _fieldSchema_xcomponentprops;
                    fieldSchema['x-component-props'] = (null == fieldSchema ? void 0 : fieldSchema['x-component-props']) || {};
                    const nonfilterable = (null == fieldSchema ? void 0 : null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops.nonfilterable) || [];
                    if (value) {
                        const index = nonfilterable.indexOf(field.name);
                        nonfilterable.splice(index, 1);
                    } else nonfilterable.push(field.name);
                    fieldSchema['x-component-props'].nonfilterable = nonfilterable;
                    dn.emit('patch', {
                        schema: {
                            ['x-uid']: fieldSchema['x-uid'],
                            'x-component-props': {
                                ...fieldSchema['x-component-props']
                            }
                        }
                    });
                    dn.refresh();
                }
            }, field.name);
        })
    });
};
const FilterActionDesigner = (props)=>{
    var _fieldSchema_xcomponentprops;
    const field = (0, schema_namespaceObject.useField)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { dn } = (0, external_index_js_namespaceObject.useDesignable)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_schema_settings_index_js_namespaceObject.GeneralSchemaDesigner, {
        ...props,
        disableInitializer: true,
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(FilterableFieldsSchemaSettingsItem, {}),
            /*#__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.SchemaSettingsModalItem, {
                title: t('Edit button'),
                schema: {
                    type: 'object',
                    title: t('Edit button'),
                    properties: {
                        title: {
                            'x-decorator': 'FormItem',
                            'x-component': 'Input',
                            title: t('Button title'),
                            default: fieldSchema.title,
                            'x-component-props': {}
                        },
                        icon: {
                            'x-decorator': 'FormItem',
                            'x-component': 'IconPicker',
                            title: t('Button icon'),
                            default: null == fieldSchema ? void 0 : null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops.icon,
                            'x-component-props': {}
                        }
                    }
                },
                onSubmit: (param)=>{
                    let { title, icon } = param;
                    fieldSchema.title = title;
                    field.title = title;
                    field.componentProps.icon = icon;
                    fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {};
                    fieldSchema['x-component-props'].icon = icon;
                    dn.emit('patch', {
                        schema: {
                            ['x-uid']: fieldSchema['x-uid'],
                            title,
                            'x-component-props': {
                                ...fieldSchema['x-component-props']
                            }
                        }
                    });
                    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: (s)=>'Space' === s['x-component'] || 'ActionBar' === s['x-component']
            })
        ]
    });
};
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
});
