"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__, {
    AssociationFilterItem: ()=>AssociationFilterItem
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const schema_namespaceObject = require("@tachybase/schema");
const icons_namespaceObject = require("@ant-design/icons");
const external_antd_namespaceObject = require("antd");
const external_classnames_namespaceObject = require("classnames");
var external_classnames_default = /*#__PURE__*/ __webpack_require__.n(external_classnames_namespaceObject);
const index_js_namespaceObject = require("../__builtins__/index.js");
const withDynamicSchemaProps_js_namespaceObject = require("../../../application/hoc/withDynamicSchemaProps.js");
const external_common_index_js_namespaceObject = require("../../common/index.js");
const external_hooks_index_js_namespaceObject = require("../../hooks/index.js");
const external_input_index_js_namespaceObject = require("../input/index.js");
const external_record_picker_index_js_namespaceObject = require("../record-picker/index.js");
const external_AssociationFilter_js_namespaceObject = require("./AssociationFilter.js");
const external_AssociationFilter_Item_style_js_namespaceObject = require("./AssociationFilter.Item.style.js");
var external_AssociationFilter_Item_style_js_default = /*#__PURE__*/ __webpack_require__.n(external_AssociationFilter_Item_style_js_namespaceObject);
const { Panel } = external_antd_namespaceObject.Collapse;
const AssociationFilterItem = (0, withDynamicSchemaProps_js_namespaceObject.withDynamicSchemaProps)((props)=>{
    var _fieldSchema_xcomponentprops_fieldNames, _fieldSchema_xcomponentprops, _collectionField_uiSchema;
    const { wrapSSR, componentCls, hashId } = external_AssociationFilter_Item_style_js_default()();
    const { token } = (0, index_js_namespaceObject.useToken)();
    const collectionField = external_AssociationFilter_js_namespaceObject.AssociationFilter.useAssociationField();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const Designer = (0, external_hooks_index_js_namespaceObject.useDesigner)();
    const compile = (0, external_hooks_index_js_namespaceObject.useCompile)();
    const { list, onSelected, handleSearchInput: _handleSearchInput, params, run, valueKey: _valueKey, labelKey: _labelKey, defaultCollapse } = (0, external_hooks_index_js_namespaceObject.useProps)(props);
    const [searchVisible, setSearchVisible] = (0, external_react_namespaceObject.useState)(false);
    const defaultActiveKeyCollapse = (0, external_react_namespaceObject.useMemo)(()=>defaultCollapse && (null == collectionField ? void 0 : collectionField.name) ? [
            collectionField.name
        ] : [], []);
    const valueKey = _valueKey || (null == collectionField ? void 0 : collectionField.targetKey) || 'id';
    const labelKey = _labelKey || (null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : null === (_fieldSchema_xcomponentprops_fieldNames = _fieldSchema_xcomponentprops.fieldNames) || void 0 === _fieldSchema_xcomponentprops_fieldNames ? void 0 : _fieldSchema_xcomponentprops_fieldNames.label) || valueKey;
    const fieldNames = {
        title: labelKey || valueKey,
        key: valueKey
    };
    const [expandedKeys, setExpandedKeys] = (0, external_react_namespaceObject.useState)([]);
    const [selectedKeys, setSelectedKeys] = (0, external_react_namespaceObject.useState)([]);
    const [autoExpandParent, setAutoExpandParent] = (0, external_react_namespaceObject.useState)(true);
    const labelUiSchema = (0, external_record_picker_index_js_namespaceObject.useLabelUiSchema)(collectionField, (null == fieldNames ? void 0 : fieldNames.title) || 'label');
    if (!collectionField) return null;
    const onExpand = (expandedKeysValue)=>{
        setExpandedKeys(expandedKeysValue);
        setAutoExpandParent(false);
    };
    const onSelect = (selectedKeysValue)=>{
        setSelectedKeys(selectedKeysValue);
        onSelected(selectedKeysValue);
    };
    const handleSearchToggle = (e)=>{
        var _params_;
        const filter = null == params ? void 0 : null === (_params_ = params[0]) || void 0 === _params_ ? void 0 : _params_.filter;
        if (searchVisible || filter) run({
            ...null == params ? void 0 : params[0],
            filter: void 0
        });
        setSearchVisible(!searchVisible);
        e.stopPropagation();
    };
    const handleSearchClick = (e)=>{
        e.stopPropagation();
    };
    const handleSearchInput = (e)=>{
        _handleSearchInput(e);
    };
    var _fieldSchema_title;
    const title = null !== (_fieldSchema_title = fieldSchema.title) && void 0 !== _fieldSchema_title ? _fieldSchema_title : null == collectionField ? void 0 : null === (_collectionField_uiSchema = collectionField.uiSchema) || void 0 === _collectionField_uiSchema ? void 0 : _collectionField_uiSchema.title;
    return wrapSSR(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_common_index_js_namespaceObject.SortableItem, {
        className: external_classnames_default()(componentCls, hashId, 'tb-block-item', props.className, 'SortableItem'),
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Designer, {}),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Collapse, {
                defaultActiveKey: defaultActiveKeyCollapse,
                ghost: true,
                expandIcon: searchVisible ? ()=>null : void 0,
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Panel, {
                    className: "Panel",
                    header: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_antd_namespaceObject.Row, {
                        className: "headerRow",
                        style: {
                            borderBottom: searchVisible ? "1px solid ".concat(token.colorBorder) : 'none'
                        },
                        gutter: 5,
                        children: [
                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Col, {
                                title: compile(title),
                                className: "headerCol",
                                children: searchVisible ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Input, {
                                    bordered: false,
                                    autoFocus: true,
                                    placeholder: "Search...",
                                    className: "search",
                                    onClick: handleSearchClick,
                                    onChange: handleSearchInput
                                }) : compile(title)
                            }),
                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Col, {
                                style: {
                                    flex: '0 0 auto'
                                },
                                children: searchVisible ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icons_namespaceObject.CloseOutlined, {
                                    className: "CloseOutlined",
                                    onClick: handleSearchToggle
                                }) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icons_namespaceObject.SearchOutlined, {
                                    className: "SearchOutlined",
                                    onClick: handleSearchToggle
                                })
                            })
                        ]
                    }),
                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Tree, {
                        className: "Tree",
                        onExpand: onExpand,
                        expandedKeys: expandedKeys,
                        autoExpandParent: autoExpandParent,
                        treeData: list,
                        onSelect: onSelect,
                        fieldNames: fieldNames,
                        titleRender: (node)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_input_index_js_namespaceObject.EllipsisWithTooltip, {
                                ellipsis: true,
                                children: (0, external_record_picker_index_js_namespaceObject.getLabelFormatValue)(labelUiSchema, compile(node[labelKey]))
                            }),
                        selectedKeys: selectedKeys,
                        blockNode: true
                    })
                }, defaultActiveKeyCollapse[0])
            })
        ]
    }));
}, {
    displayName: 'AssociationFilterItem'
});
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
});
