"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__, {
    EditCustomDefaultValue: ()=>EditCustomDefaultValue,
    FilterCustomVariableInput: ()=>FilterCustomVariableInput
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const schema_namespaceObject = require("@tachybase/schema");
const external_ahooks_namespaceObject = require("ahooks");
const external_react_i18next_namespaceObject = require("react-i18next");
const index_js_namespaceObject = require("../schema-component/index.js");
const external_SchemaSettings_js_namespaceObject = require("./SchemaSettings.js");
const external_VariableInput_index_js_namespaceObject = require("./VariableInput/index.js");
const EditCustomDefaultValue = ()=>{
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const { dn } = (0, index_js_namespaceObject.useDesignable)();
    const field = (0, schema_namespaceObject.useField)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    fieldSchema['collectionName'];
    const title = fieldSchema.title;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_SchemaSettings_js_namespaceObject.SchemaSettingsModalItem, {
        title: t('Set default value'),
        schema: {
            type: 'void',
            title: t('Set default value'),
            properties: {
                default: {
                    title,
                    'x-decorator': 'FormItem',
                    'x-component': FilterCustomVariableInput,
                    'x-component-props': {
                        fieldSchema
                    }
                }
            }
        },
        onSubmit: (param)=>{
            let { default: { value = null } } = param;
            field.setValue(value);
            fieldSchema['default'] = value;
            fieldSchema['x-component-props'] = {
                ...fieldSchema['x-component-props'],
                defaultValue: value
            };
            dn.emit('patch', {
                schema: {
                    'x-uid': fieldSchema['x-uid'],
                    ['x-component-props']: fieldSchema['x-component-props'],
                    default: fieldSchema.default
                }
            });
            dn.refresh();
        }
    }, "set field default value");
};
const FilterCustomVariableInput = (props)=>{
    var _fieldSchema_xcomponentprops;
    const { value, onChange, fieldSchema } = props;
    const { currentUserSettings } = (0, external_VariableInput_index_js_namespaceObject.useCurrentUserVariable)({
        collectionField: {
            uiSchema: fieldSchema
        },
        uiSchema: fieldSchema
    });
    const { datetimeSettings } = (0, external_VariableInput_index_js_namespaceObject.useDatetimeVariable)({
        operator: null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops['filter-operator'],
        schema: fieldSchema,
        noDisabled: true
    });
    const options = (0, external_react_namespaceObject.useMemo)(()=>[
            currentUserSettings,
            datetimeSettings
        ].filter(Boolean), [
        datetimeSettings,
        currentUserSettings
    ]);
    const schema = {
        ...fieldSchema,
        'x-component': fieldSchema['x-component'] || 'Input',
        'x-decorator': '',
        title: '',
        name: 'value'
    };
    const componentProps = fieldSchema['x-component-props'] || {};
    const handleChange = (0, external_ahooks_namespaceObject.useMemoizedFn)(onChange);
    (0, external_react_namespaceObject.useEffect)(()=>{
        if (fieldSchema.default) handleChange({
            value: fieldSchema.default
        });
    }, [
        fieldSchema.default,
        handleChange
    ]);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.VariableScopeProvider, {
        scope: options,
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_VariableInput_index_js_namespaceObject.VariableInput, {
            ...componentProps,
            renderSchemaComponent: ()=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.SchemaComponent, {
                    schema: schema
                }),
            fieldNames: {},
            value: null == value ? void 0 : value.value,
            scope: options,
            onChange: (v)=>{
                onChange({
                    value: v
                });
            },
            shouldChange: (0, external_VariableInput_index_js_namespaceObject.getShouldChange)({})
        })
    });
};
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
});
