import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_utils_client__ from "@tachybase/utils/client";
import * as __WEBPACK_EXTERNAL_MODULE_antd__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__ from "../../../collection-manager/index.mjs";
const useLabelUiSchema = (collectionField, label)=>{
    const { getCollectionJoinField } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.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 = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_utils_client__.getDefaultFormat)(props);
    const m = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_utils_client__.str2moment)(props.value, props);
    const labels = m && m.isValid() ? m.format(format) : props.value;
    return (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.isArr)(labels) ? labels.join('~') : labels;
};
const getLabelFormatValue = function(labelUiSchema, value) {
    let isTag = arguments.length > 2 && void 0 !== arguments[2] && arguments[2];
    if (Array.isArray(null == labelUiSchema ? void 0 : labelUiSchema.enum) && value) {
        const opt = labelUiSchema.enum.find((option)=>option.value === value);
        if (isTag) return __WEBPACK_EXTERNAL_MODULE_react__["default"].createElement(__WEBPACK_EXTERNAL_MODULE_antd__.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 };
