"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__, {
    Cascader: ()=>Cascader,
    default: ()=>Cascader_rslib_entry_
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
require("react");
const schema_namespaceObject = require("@tachybase/schema");
const icons_namespaceObject = require("@ant-design/icons");
const external_antd_namespaceObject = require("antd");
const external_lodash_namespaceObject = require("lodash");
const index_js_namespaceObject = require("../../../api-client/index.js");
const external_defaultFieldNames_js_namespaceObject = require("./defaultFieldNames.js");
const external_ReadPretty_js_namespaceObject = require("./ReadPretty.js");
const useDefDataSource = (options)=>{
    const field = (0, schema_namespaceObject.useField)();
    return (0, index_js_namespaceObject.useRequest)(()=>Promise.resolve({
            data: field.dataSource || []
        }), options);
};
const useDefLoadData = (props)=>null == props ? void 0 : props.loadData;
const Cascader = (0, schema_namespaceObject.connect)((props)=>{
    const field = (0, schema_namespaceObject.useField)();
    const { value, onChange, labelInValue, useDataSource = useDefDataSource, useLoadData = useDefLoadData, changeOnSelectLast, changeOnSelect, maxLevel, ...others } = props;
    const fieldNames = {
        ...external_defaultFieldNames_js_namespaceObject.defaultFieldNames,
        ...props.fieldNames
    };
    const loadData = useLoadData(props);
    const { loading, run } = useDataSource({
        onSuccess (data) {
            field.dataSource = (null == data ? void 0 : data.data) || [];
        }
    });
    const toValue = ()=>(0, schema_namespaceObject.toArr)(value).map((item)=>{
            if ('object' == typeof item) return item[fieldNames.value];
            return item;
        });
    const displayRender = (labels, selectedOptions)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Space, {
            split: '/',
            children: labels.map((label, index)=>{
                if (selectedOptions[index]) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                    children: label
                }, index);
                const item = (0, schema_namespaceObject.toArr)(value).filter(Boolean).find((item)=>item[fieldNames.value] === label);
                return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                    children: (null == item ? void 0 : item[fieldNames.label]) || label
                }, index);
            })
        });
    const handelDropDownVisible = (value)=>{
        var _field_dataSource;
        if (value && !(null === (_field_dataSource = field.dataSource) || void 0 === _field_dataSource ? void 0 : _field_dataSource.length)) run();
    };
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Cascader, {
        loading: loading,
        ...others,
        options: field.dataSource,
        loadData: loadData,
        changeOnSelect: (0, external_lodash_namespaceObject.isBoolean)(changeOnSelectLast) ? !changeOnSelectLast : changeOnSelect,
        value: toValue(),
        fieldNames: fieldNames,
        displayRender: displayRender,
        onDropdownVisibleChange: handelDropDownVisible,
        onChange: (value, selectedOptions)=>{
            value && labelInValue ? onChange(selectedOptions.map((option)=>(0, external_lodash_namespaceObject.omit)(option, [
                    fieldNames.children
                ]))) : onChange(value);
        }
    });
}, (0, schema_namespaceObject.mapProps)({
    dataSource: 'options'
}, (props, field)=>({
        ...props,
        suffixIcon: (null == field ? void 0 : field['loading']) || (null == field ? void 0 : field['validating']) ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icons_namespaceObject.LoadingOutlined, {}) : props.suffixIcon
    })), (0, schema_namespaceObject.mapReadPretty)(external_ReadPretty_js_namespaceObject.ReadPretty));
const Cascader_rslib_entry_ = Cascader;
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
});
