"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__, {
    ReadPretty: ()=>ReadPretty
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
require("react");
const components_namespaceObject = require("@tachybase/components");
const schema_namespaceObject = require("@tachybase/schema");
const external_antd_namespaceObject = require("antd");
const external_classnames_namespaceObject = require("classnames");
var external_classnames_default = /*#__PURE__*/ __webpack_require__.n(external_classnames_namespaceObject);
const ReadPretty = (0, schema_namespaceObject.observer)((props)=>{
    var _field_dataSource, _props_treeData;
    const field = (0, schema_namespaceObject.useField)();
    const { placeholder } = props;
    const prefixCls = (0, components_namespaceObject.usePrefixCls)('description-tree-select', props);
    const dataSource = (null == field ? void 0 : null === (_field_dataSource = field.dataSource) || void 0 === _field_dataSource ? void 0 : _field_dataSource.length) ? field.dataSource : (null == props ? void 0 : null === (_props_treeData = props.treeData) || void 0 === _props_treeData ? void 0 : _props_treeData.length) ? props.treeData : [];
    const getSelected = ()=>{
        const value = props.value;
        if (props.multiple) {
            if (props.labelInValue) return (0, schema_namespaceObject.isArr)(value) ? value : [];
            return (0, schema_namespaceObject.isArr)(value) ? value.map((val)=>({
                    label: val,
                    value: val
                })) : [];
        }
        if (props.labelInValue) return value ? [
            value
        ] : [];
        return value ? [
            {
                label: value,
                value
            }
        ] : [];
    };
    const findLabel = (value, dataSource)=>{
        for(let i = 0; i < (null == dataSource ? void 0 : dataSource.length); i++){
            const item = dataSource[i];
            if ((null == item ? void 0 : item.value) === value) return null == item ? void 0 : item.label;
            {
                const childLabel = findLabel(value, null == item ? void 0 : item.children);
                if (childLabel) return childLabel;
            }
        }
    };
    const getLabels = ()=>{
        const selected = getSelected();
        if (!(null == selected ? void 0 : selected.length)) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Tag, {
            children: placeholder
        });
        return selected.map((param, key)=>{
            let { value, label } = param;
            return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Tag, {
                children: findLabel(value, dataSource) || label || placeholder
            }, key);
        });
    };
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
        className: external_classnames_default()(prefixCls, props.className),
        style: props.style,
        children: getLabels()
    });
}, {
    displayName: 'ReadPretty'
});
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
});
