"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizeTokenValue = normalizeTokenValue;
const normalize_select_value_1 = require("./normalize-select-value");
const normalize_cascader_and_tree_value_1 = require("./normalize-cascader-and-tree-value");
const normalize_time_value_1 = require("./normalize-time-value");
const normalize_date_value_1 = require("./normalize-date-value");
const normalize_employee_value_1 = require("./normalize-employee-value");
const normalize_department_value_1 = require("./normalize-department-value");
const normalize_input_value_1 = require("./normalize-input-value");
const normalize_number_value_1 = require("./normalize-number-value");
const normalize_bank_input_value_1 = require("./normalize-bank-input-value");
/**
 * 根据组件类型和 props 配置，标准化 token 的 value
 * @param token - translate 接口返回的 token
 * @param schema - Formily schema 配置
 * @returns 标准化后的 token
 */
function normalizeTokenValue(token, schema) {
    if (token.queryType !== 'STRUCTURED' || !token.columnName) {
        return token;
    }
    const fieldConfig = schema[token.columnName];
    if (!fieldConfig) {
        return token;
    }
    const columnType = token.columnType || fieldConfig['x-component'];
    const componentProps = fieldConfig['x-component-props'] || {};
    // 根据组件类型进行标准化处理
    let normalizedValue = token.value;
    switch (columnType) {
        case 'Input':
        case 'CnInput':
        case 'TextArea':
        case 'CnTextArea':
        case 'CnBatchInput':
            normalizedValue = (0, normalize_input_value_1.normalizeInputValue)(token.value, componentProps);
            break;
        case 'CnBankInput':
            normalizedValue = (0, normalize_bank_input_value_1.normalizeBankInputValue)(token.value);
            break;
        case 'Select':
        case 'CnAsyncSelect':
        case 'RadioGroup':
        case 'CnRadioGroup':
        case 'CnComplexRadio':
        case 'CheckboxGroup':
        case 'CnCheckboxGroup':
        case 'CnComplexCheckbox':
            normalizedValue = (0, normalize_select_value_1.normalizeSelectValue)(token.value, componentProps);
            break;
        case 'CascaderSelect':
        case 'CnCascaderSelect':
        case 'TreeSelect':
        case 'CnTreeSelect':
            normalizedValue = (0, normalize_cascader_and_tree_value_1.normalizeCascaderAndTreeValue)(token.value, componentProps);
            break;
        case 'TimePicker':
        case 'CnTimePickerPro':
        case 'RangeTimePicker':
        case 'CnRangeTimePickerPro':
            normalizedValue = (0, normalize_time_value_1.normalizeTimeValue)(token.value, componentProps);
            break;
        case 'DatePicker':
        case 'CnDatePickerPro':
        case 'RangePicker':
        case 'CnRangeDatePickerPro':
            normalizedValue = (0, normalize_date_value_1.normalizeDateValue)(token.value, componentProps);
            break;
        case 'EmployeeSelect':
        case 'CnEmployeeSelect':
            // 传入 options，以便在标准化时设置 nickName
            normalizedValue = (0, normalize_employee_value_1.normalizeEmployeeValue)(token.value, componentProps, token.options);
            break;
        case 'DepartmentSelect':
        case 'CnDepartmentSelect':
            normalizedValue = (0, normalize_department_value_1.normalizeDepartmentValue)(token.value, componentProps);
            break;
        case 'NumberPicker':
        case 'CnNumberPicker':
        case 'CnPercentInput':
        case 'CnRangeNumnerPicker':
        case 'CnProgress':
        case 'CnRating':
            normalizedValue = (0, normalize_number_value_1.normalizeNumberValue)(token.value, componentProps);
            break;
        default:
            // 其他组件类型保持原样
            // TODO: 地址、币种金额、开关
            break;
    }
    return {
        ...token,
        value: normalizedValue,
    };
}
