import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_components__ from "@tachybase/components";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE_antd_style__ from "antd-style";
import * as __WEBPACK_EXTERNAL_MODULE_classnames__ from "classnames";
import * as __WEBPACK_EXTERNAL_MODULE__application_index_mjs__ from "../../../application/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__block_provider_hooks_useFormActiveFields_mjs__ from "../../../block-provider/hooks/useFormActiveFields.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__built_in_acl_index_mjs__ from "../../../built-in/acl/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__data_source_index_mjs__ from "../../../data-source/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_settings_index_mjs__ from "../../../schema-settings/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__variables_index_mjs__ from "../../../variables/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__variables_hooks_useContextVariable_mjs__ from "../../../variables/hooks/useContextVariable.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__block_item_index_mjs__ from "../block-item/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__input_shared_mjs__ from "../input/shared.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__FormItem_FilterFormDesigner_mjs__ from "./FormItem.FilterFormDesigner.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__hooks_useLazyLoadDisplayAssociationFieldsOfForm_mjs__ from "./hooks/useLazyLoadDisplayAssociationFieldsOfForm.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__hooks_useParseDefaultValue_mjs__ from "./hooks/useParseDefaultValue.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__SchemaSettingOptions_mjs__ from "./SchemaSettingOptions.mjs";
function _tagged_template_literal(strings, raw) {
    if (!raw) raw = strings.slice(0);
    return Object.freeze(Object.defineProperties(strings, {
        raw: {
            value: Object.freeze(raw)
        }
    }));
}
function _templateObject() {
    const data = _tagged_template_literal([
        "\n      & .ant-space {\n        flex-wrap: wrap;\n      }\n    "
    ]);
    _templateObject = function() {
        return data;
    };
    return data;
}
function _templateObject1() {
    const data = _tagged_template_literal([
        "\n      > .ant-formily-item-label {\n        display: none;\n      }\n    "
    ]);
    _templateObject1 = function() {
        return data;
    };
    return data;
}
function _templateObject2() {
    const data = _tagged_template_literal([
        "\n      display: flex;\n      flex-direction: row;\n      align-items: baseline;\n    "
    ]);
    _templateObject2 = function() {
        return data;
    };
    return data;
}
const useStyles = (0, __WEBPACK_EXTERNAL_MODULE_antd_style__.createStyles)((param)=>{
    let { css } = param;
    return {
        space: css(_templateObject()),
        hide: css(_templateObject1()),
        row: css(_templateObject2())
    };
});
const FormItem = (props)=>{
    var _schema_xdecoratorprops;
    const { styles } = useStyles();
    const { layoutDirection: selfLayoutDirection } = props;
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    const schema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    const contextVariable = (0, __WEBPACK_EXTERNAL_MODULE__variables_hooks_useContextVariable_mjs__["default"])();
    const variables = (0, __WEBPACK_EXTERNAL_MODULE__variables_index_mjs__.useVariables)();
    const { addActiveFieldName } = (0, __WEBPACK_EXTERNAL_MODULE__block_provider_hooks_useFormActiveFields_mjs__.useFormActiveFields)() || {};
    const { layoutDirection } = (0, __WEBPACK_EXTERNAL_MODULE__data_source_index_mjs__.useContextConfigSetting)();
    const finishLayoutDirection = null != selfLayoutDirection ? selfLayoutDirection : layoutDirection;
    (0, __WEBPACK_EXTERNAL_MODULE__SchemaSettingOptions_mjs__.useEnsureOperatorsValid)();
    (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
        null == variables || variables.registerVariable(contextVariable);
    }, [
        contextVariable
    ]);
    (0, __WEBPACK_EXTERNAL_MODULE__hooks_useParseDefaultValue_mjs__["default"])();
    (0, __WEBPACK_EXTERNAL_MODULE__hooks_useLazyLoadDisplayAssociationFieldsOfForm_mjs__["default"])();
    (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
        null == addActiveFieldName || addActiveFieldName(schema.name);
    }, [
        addActiveFieldName,
        schema.name
    ]);
    var _schema_xdecoratorprops_showTitle;
    const showTitle = null === (_schema_xdecoratorprops_showTitle = null === (_schema_xdecoratorprops = schema['x-decorator-props']) || void 0 === _schema_xdecoratorprops ? void 0 : _schema_xdecoratorprops.showTitle) || void 0 === _schema_xdecoratorprops_showTitle || _schema_xdecoratorprops_showTitle;
    const extra = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
        if ('string' == typeof field.description) {
            const desc = field.description.trim();
            if (!desc) return;
            return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                dangerouslySetInnerHTML: {
                    __html: (0, __WEBPACK_EXTERNAL_MODULE__input_shared_mjs__.HTMLEncode)(desc).split('\n').join('<br/>')
                }
            });
        }
        var _field_description;
        return null !== (_field_description = field.description) && void 0 !== _field_description ? _field_description : void 0;
    }, [
        field.description
    ]);
    const className = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>(0, __WEBPACK_EXTERNAL_MODULE_classnames__["default"])(styles.space, {
            [styles.hide]: false === showTitle
        }, {
            [styles.row]: 'row' === finishLayoutDirection
        }), [
        showTitle
    ]);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__data_source_index_mjs__.CollectionFieldProvider, {
        allowNull: true,
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__block_item_index_mjs__.BlockItem, {
            className: 'tb-form-item',
            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__built_in_acl_index_mjs__.ACLCollectionFieldProvider, {
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_components__.FormItem, {
                    className: className,
                    ...props,
                    extra: extra
                })
            })
        })
    });
};
FormItem.displayName = 'FormItem';
FormItem.Designer = function() {
    const app = (0, __WEBPACK_EXTERNAL_MODULE__application_index_mjs__.useApp)();
    const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    const settingsName = "FormItemSettings:".concat(fieldSchema['x-interface']);
    const defaultActionSettings = 'FormItemSettings';
    const hasFieldItem = app.schemaSettingsManager.has(settingsName);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_settings_index_mjs__.GeneralSchemaDesigner, {
        schemaSettings: hasFieldItem ? settingsName : defaultActionSettings
    });
};
function isFileCollection(collection) {
    return (null == collection ? void 0 : collection.template) === 'file';
}
FormItem.FilterFormDesigner = __WEBPACK_EXTERNAL_MODULE__FormItem_FilterFormDesigner_mjs__.FilterFormDesigner;
export { FormItem, isFileCollection };
