"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useCardConfig = void 0;
const react_1 = __importDefault(require("react"));
/**
 * 卡片配置 Hook
 * 处理卡片视图的字段显示配置
 */
const useCardConfig = ({ viewConfig, viewColumns, maxFields, }) => {
    var _a;
    // 卡片配置
    const cardConfig = ((_a = viewConfig.custom) === null || _a === void 0 ? void 0 : _a.cardConfig) || {};
    const showFieldTitle = cardConfig.showFieldTitle !== undefined ? cardConfig.showFieldTitle : true;
    const cardFieldOrder = cardConfig.fieldOrder || viewColumns.map((col) => col.dataIndex);
    const cardVisibleFields = cardConfig.visibleFields || viewColumns.map((col) => col.dataIndex);
    // 根据配置过滤和排序字段；未传 maxFields 时不限制数量，展示全部可见字段
    const displayColumns = react_1.default.useMemo(() => {
        const orderedColumns = cardFieldOrder
            .map((dataIndex) => viewColumns.find((col) => col.dataIndex === dataIndex))
            .filter((col) => col != null && cardVisibleFields.includes(col.dataIndex));
        return maxFields != null && maxFields > 0 ? orderedColumns.slice(0, maxFields) : orderedColumns;
    }, [viewColumns, cardFieldOrder, cardVisibleFields, maxFields]);
    return {
        showFieldTitle,
        cardFieldOrder,
        cardVisibleFields,
        displayColumns,
    };
};
exports.useCardConfig = useCardConfig;
exports.default = exports.useCardConfig;
