"use strict";
/**
 * 日期格式文本提取器
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractDateText = extractDateText;
exports.extractDateTimeText = extractDateTimeText;
const date_1 = require("../../cn-table-cell-format/formats/utils/date");
const constants_1 = require("../../cn-table-cell-format/constants");
/**
 * 日期文本提取器
 */
function extractDateText(value, column, _record, dateAdapterLocale) {
    var _a, _b, _c, _d, _e, _f;
    // 处理带 children 的情况（如日期范围选择器）
    if (Array.isArray(column === null || column === void 0 ? void 0 : column.children) && column.children.length > 0) {
        if (Array.isArray(value) && value.length === 2) {
            const startFormatted = (0, date_1.formatDate)(value[0], (_a = column === null || column === void 0 ? void 0 : column.dateInterv) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_DATE_INTERV, (_b = column === null || column === void 0 ? void 0 : column.dateFormat) !== null && _b !== void 0 ? _b : constants_1.DEFAULT_DATE_FORMAT, dateAdapterLocale);
            const endFormatted = (0, date_1.formatDate)(value[1], (_c = column === null || column === void 0 ? void 0 : column.dateInterv) !== null && _c !== void 0 ? _c : constants_1.DEFAULT_DATE_INTERV, (_d = column === null || column === void 0 ? void 0 : column.dateFormat) !== null && _d !== void 0 ? _d : constants_1.DEFAULT_DATE_FORMAT, dateAdapterLocale);
            return `${startFormatted} - ${endFormatted}`;
        }
        return '';
    }
    // 普通日期字段
    if (value) {
        return (0, date_1.formatDate)(value, (_e = column === null || column === void 0 ? void 0 : column.dateInterv) !== null && _e !== void 0 ? _e : constants_1.DEFAULT_DATE_INTERV, (_f = column === null || column === void 0 ? void 0 : column.dateFormat) !== null && _f !== void 0 ? _f : constants_1.DEFAULT_DATE_FORMAT, dateAdapterLocale);
    }
    return '';
}
/**
 * 日期时间文本提取器
 */
function extractDateTimeText(value, column, _record, dateAdapterLocale) {
    var _a, _b;
    if (!value) {
        return '';
    }
    return (0, date_1.formatDateTime)(value, {
        interv: (_a = column === null || column === void 0 ? void 0 : column.dateInterv) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_DATE_INTERV,
        hasSecond: (_b = column === null || column === void 0 ? void 0 : column.hasSecond) !== null && _b !== void 0 ? _b : true,
        adapterLocale: dateAdapterLocale,
    });
}
