"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__, {
    getDatePickerLabels: ()=>getDatePickerLabels,
    flatData: ()=>flatData,
    getTabFormatValue: ()=>getTabFormatValue,
    useLabelUiSchemaV2: ()=>useLabelUiSchemaV2,
    useLabelUiSchema: ()=>useLabelUiSchema,
    isShowFilePicker: ()=>isShowFilePicker,
    getLabelFormatValue: ()=>getLabelFormatValue,
    isSubMode: ()=>isSubMode
});
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];
    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 ? void 0 : _field_xcomponentprops.mode) || (null === (_field_componentProps = field.componentProps) || void 0 === _field_componentProps ? void 0 : _field_componentProps.mode);
    return [
        'Nester',
        'SubTable',
        'PopoverNester'
    ].includes(mode);
}
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
});
