import react from "react";
import { isArr } from "@tachybase/schema";
import { getDefaultFormat, str2moment } from "@tego/client";
import { Tag } from "antd";
import { useCollectionManager_deprecated } from "../../../collection-manager/index.mjs";
const useLabelUiSchema = (collectionField, label)=>{
    const { getCollectionJoinField } = useCollectionManager_deprecated();
    if (!collectionField) return;
    const labelField = getCollectionJoinField("".concat(collectionField.target, ".").concat(label));
    return null == labelField ? void 0 : labelField.uiSchema;
};
const getDatePickerLabels = (props)=>{
    const format = getDefaultFormat(props);
    const m = str2moment(props.value, props);
    const labels = m && m.isValid() ? m.format(format) : props.value;
    return isArr(labels) ? labels.join('~') : labels;
};
const getLabelFormatValue = function(labelUiSchema, value) {
    let isTag = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : false;
    if (Array.isArray(null == labelUiSchema ? void 0 : labelUiSchema.enum) && value) {
        const opt = labelUiSchema.enum.find((option)=>option.value === value);
        if (isTag) return react.createElement(Tag, {
            color: null == opt ? void 0 : opt.color
        }, null == opt ? void 0 : opt.label);
        return null == opt ? void 0 : opt.label;
    }
    switch(null == labelUiSchema ? void 0 : labelUiSchema['x-component']){
        case 'DatePicker':
            return getDatePickerLabels({
                ...null == labelUiSchema ? void 0 : labelUiSchema['x-component-props'],
                value
            });
        default:
            return value;
    }
};
export { getDatePickerLabels, getLabelFormatValue, useLabelUiSchema };
