"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__, {
    fieldComponentSettingsItem: ()=>fieldComponentSettingsItem
});
const schema_namespaceObject = require("@tachybase/schema");
const external_lodash_namespaceObject = require("lodash");
var external_lodash_default = /*#__PURE__*/ __webpack_require__.n(external_lodash_namespaceObject);
const external_react_i18next_namespaceObject = require("react-i18next");
const index_js_namespaceObject = require("../../schema-component/index.js");
const CollectionFieldProvider_js_namespaceObject = require("../collection-field/CollectionFieldProvider.js");
const DataSourceManagerProvider_js_namespaceObject = require("../data-source/DataSourceManagerProvider.js");
const fieldComponentSettingsItem = {
    name: 'fieldComponent',
    type: 'select',
    useVisible () {
        const collectionField = (0, CollectionFieldProvider_js_namespaceObject.useCollectionField)();
        const dm = (0, DataSourceManagerProvider_js_namespaceObject.useDataSourceManager)();
        if (!collectionField) return false;
        const collectionInterface = dm.collectionFieldInterfaceManager.getFieldInterface(null == collectionField ? void 0 : collectionField.interface);
        return Array.isArray(null == collectionInterface ? void 0 : collectionInterface.componentOptions) && collectionInterface.componentOptions.length > 1 && collectionInterface.componentOptions.filter((item)=>!item.useVisible || item.useVisible()).length > 1;
    },
    useComponentProps () {
        var _collectionInterface_componentOptions_filter, _collectionInterface_componentOptions, _fieldSchema_xcomponentprops, _options_;
        const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
        const field = (0, schema_namespaceObject.useField)();
        const schema = (0, schema_namespaceObject.useFieldSchema)();
        const collectionField = (0, CollectionFieldProvider_js_namespaceObject.useCollectionField)();
        const dm = (0, DataSourceManagerProvider_js_namespaceObject.useDataSourceManager)();
        const collectionInterface = dm.collectionFieldInterfaceManager.getFieldInterface(null == collectionField ? void 0 : collectionField.interface);
        const { fieldSchema: tableColumnSchema } = (0, index_js_namespaceObject.useColumnSchema)();
        const fieldSchema = tableColumnSchema || schema;
        const { dn } = (0, index_js_namespaceObject.useDesignable)();
        const compile = (0, index_js_namespaceObject.useCompile)();
        const options = (null == collectionInterface ? void 0 : null === (_collectionInterface_componentOptions = collectionInterface.componentOptions) || void 0 === _collectionInterface_componentOptions ? void 0 : null === (_collectionInterface_componentOptions_filter = _collectionInterface_componentOptions.filter((item)=>!item.useVisible || item.useVisible())) || void 0 === _collectionInterface_componentOptions_filter ? void 0 : _collectionInterface_componentOptions_filter.map((item)=>({
                label: compile(item.label),
                value: item.value,
                useProps: item.useProps
            }))) || [];
        return {
            title: t('Field component'),
            options,
            value: (null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops['component']) || (null === (_options_ = options[0]) || void 0 === _options_ ? void 0 : _options_.value),
            onChange (component) {
                var _componentOptions_useProps;
                const componentOptions = options.find((item)=>item.value === component);
                const componentProps = {
                    component,
                    ...(null == componentOptions ? void 0 : null === (_componentOptions_useProps = componentOptions.useProps) || void 0 === _componentOptions_useProps ? void 0 : _componentOptions_useProps.call(componentOptions)) || {}
                };
                external_lodash_default().set(fieldSchema, 'x-component-props', componentProps);
                field.componentProps = componentProps;
                dn.emit('patch', {
                    schema: {
                        ['x-uid']: fieldSchema['x-uid'],
                        'x-component-props': componentProps
                    }
                });
            }
        };
    }
};
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
});
