import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import "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__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE_classnames__ from "classnames";
const ReadPretty = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.observer)((props)=>{
    var _field_dataSource, _props_treeData;
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    const { placeholder } = props;
    const prefixCls = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_components__.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, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.isArr)(value) ? value : [];
            return (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.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, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Tag, {
            children: placeholder
        });
        return selected.map((param, key)=>{
            let { value, label } = param;
            return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Tag, {
                children: findLabel(value, dataSource) || label || placeholder
            }, key);
        });
    };
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
        className: (0, __WEBPACK_EXTERNAL_MODULE_classnames__["default"])(prefixCls, props.className),
        style: props.style,
        children: getLabels()
    });
}, {
    displayName: 'ReadPretty'
});
export { ReadPretty };
