"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = (module)=>{
        var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __webpack_require__.d = (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 = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (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__, {
    getDatePickerLabels: ()=>getDatePickerLabels,
    useLabelUiSchemaV2: ()=>useLabelUiSchemaV2,
    useLabelUiSchema: ()=>useLabelUiSchema,
    getTabFormatValue: ()=>getTabFormatValue,
    isSubMode: ()=>isSubMode,
    isShowFilePicker: ()=>isShowFilePicker,
    getLabelFormatValue: ()=>getLabelFormatValue,
    flatData: ()=>flatData
});
const external_react_namespaceObject = require("react");
var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
const schema_namespaceObject = require("@tachybase/schema");
const client_namespaceObject = require("@tachybase/utils/client");
const external_antd_namespaceObject = require("antd");
const index_js_namespaceObject = require("../../../collection-manager/index.js");
const useLabelUiSchemaV2 = ()=>{
    const { getCollectionJoinField } = (0, index_js_namespaceObject.useCollectionManager_deprecated)();
    return (collectionName, label)=>{
        if (!collectionName) return;
        const labelField = getCollectionJoinField("".concat(collectionName, ".").concat(label));
        return null == labelField ? void 0 : labelField.uiSchema;
    };
};
const useLabelUiSchema = (collectionName, label)=>{
    const { getCollectionJoinField } = (0, index_js_namespaceObject.useCollectionManager_deprecated)();
    if (!collectionName) return;
    const labelField = getCollectionJoinField("".concat(collectionName, ".").concat(label));
    return null == labelField ? void 0 : labelField.uiSchema;
};
const getDatePickerLabels = (props)=>{
    const format = (0, client_namespaceObject.getDefaultFormat)(props);
    const m = (0, client_namespaceObject.str2moment)(props.value, props);
    const labels = m && m.isValid() ? m.format(format) : props.value;
    return (0, schema_namespaceObject.isArr)(labels) ? labels.join('~') : labels;
};
const toArr = (v)=>{
    if (!v) return [];
    return Array.isArray(v) ? v : [
        v
    ];
};
const getLabelFormatValue = function(labelUiSchema, value) {
    let isTag = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : false;
    const options = null == labelUiSchema ? void 0 : labelUiSchema.enum;
    if (Array.isArray(options) && value) {
        const values = toArr(value).map((val)=>{
            const opt = options.find((option)=>option.value === val);
            if (isTag) return external_react_default().createElement(external_antd_namespaceObject.Tag, {
                color: null == opt ? void 0 : opt.color
            }, null == opt ? void 0 : opt.label);
            return null == opt ? void 0 : opt.label;
        });
        return isTag ? values : values.join(', ');
    }
    switch(null == labelUiSchema ? void 0 : labelUiSchema['x-component']){
        case 'DatePicker':
            return getDatePickerLabels({
                ...null == labelUiSchema ? void 0 : labelUiSchema['x-component-props'],
                value
            });
        default:
            return value;
    }
};
const getTabFormatValue = (labelUiSchema, value, tagColor)=>{
    const options = null == labelUiSchema ? void 0 : labelUiSchema.enum;
    if (Array.isArray(options) && value) {
        const values = toArr(value).map((val)=>{
            const opt = options.find((option)=>option.value === val);
            return external_react_default().createElement(external_antd_namespaceObject.Tag, {
                color: tagColor || (null == opt ? void 0 : opt.color)
            }, null == opt ? void 0 : opt.label);
        });
        return values;
    }
    switch(null == labelUiSchema ? void 0 : labelUiSchema['x-component']){
        case 'DatePicker':
            return external_react_default().createElement(external_antd_namespaceObject.Tag, {
                color: tagColor
            }, getDatePickerLabels({
                ...null == labelUiSchema ? void 0 : labelUiSchema['x-component-props'],
                value
            }));
        default:
            return external_react_default().createElement(external_antd_namespaceObject.Tag, {
                color: tagColor
            }, value);
    }
};
function flatData(data) {
    const newArr = [];
    for(let i = 0; i < data.length; i++){
        const children = data[i]['children'];
        if (Array.isArray(children)) newArr.push(...flatData(children));
        newArr.push({
            ...data[i]
        });
    }
    return newArr;
}
function isShowFilePicker(labelUiSchema) {
    return (null == labelUiSchema ? void 0 : labelUiSchema['x-component']) === 'Preview';
}
function isSubMode(field) {
    var _field_xcomponentprops, _field_componentProps;
    const mode = (null == (_field_xcomponentprops = field['x-component-props']) ? void 0 : _field_xcomponentprops.mode) || (null == (_field_componentProps = field.componentProps) ? void 0 : _field_componentProps.mode);
    return [
        'Nester',
        'SubTable',
        'PopoverNester'
    ].includes(mode);
}
exports.flatData = __webpack_exports__.flatData;
exports.getDatePickerLabels = __webpack_exports__.getDatePickerLabels;
exports.getLabelFormatValue = __webpack_exports__.getLabelFormatValue;
exports.getTabFormatValue = __webpack_exports__.getTabFormatValue;
exports.isShowFilePicker = __webpack_exports__.isShowFilePicker;
exports.isSubMode = __webpack_exports__.isSubMode;
exports.useLabelUiSchema = __webpack_exports__.useLabelUiSchema;
exports.useLabelUiSchemaV2 = __webpack_exports__.useLabelUiSchemaV2;
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
    "flatData",
    "getDatePickerLabels",
    "getLabelFormatValue",
    "getTabFormatValue",
    "isShowFilePicker",
    "isSubMode",
    "useLabelUiSchema",
    "useLabelUiSchemaV2"
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
Object.defineProperty(exports, '__esModule', {
    value: true
});
