"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetchViewsFromCube = fetchViewsFromCube;
const get_cube_platform_meta_1 = require("./get-cube-platform-meta");
const manual_biz_view_config_urls_1 = require("../url/manual-biz-view-config-urls");
const process_user_cube_config_1 = require("./process-user-cube-config");
const EMPTY_VIEWS = { views: {}, viewOrder: [] };
/**
 * 源码未配业务 URL：getList → 按 tableId 读 `components[].config.tableView` → `ViewsData`。
 */
async function fetchViewsFromCube(tableId, bizRequestConfig) {
    if (!tableId) {
        return { views: EMPTY_VIEWS, userCubeConfigRowId: '' };
    }
    const meta = (0, get_cube_platform_meta_1.getCubePlatformMeta)(tableId, bizRequestConfig);
    if (!meta) {
        return { views: EMPTY_VIEWS, userCubeConfigRowId: '' };
    }
    try {
        const { userCubeConfig, userCubeConfigRowId } = await (0, process_user_cube_config_1.loadUserCubeConfigFromPlatform)(meta, bizRequestConfig);
        const views = (0, manual_biz_view_config_urls_1.normalizeViewsResponse)((0, process_user_cube_config_1.readTableViewFromComponents)(userCubeConfig.components, tableId));
        return { views, userCubeConfigRowId };
    }
    catch {
        return { views: EMPTY_VIEWS, userCubeConfigRowId: '' };
    }
}
