import { isDashboardItemVisualization, isDashboardItemVisualizationContent, } from "../../../types/commonTypes.js";
import { loadInsight } from "../../widgets/common/loadInsight.js";
const size = { xl: { gridHeight: 22, gridWidth: 12 } };
export const EmptyDashboardLayout = {
    type: "IDashboardLayout",
    sections: [],
};
export async function dashboardInitialize(ctx, items) {
    if (!items) {
        return {
            dashboard: undefined,
            insights: [],
        };
    }
    const layoutItems = [];
    const insights = [];
    for (let i = 0; i < items.length; i++) {
        const item = items[i];
        if (isDashboardItemVisualization(item)) {
            const insight = await loadInsight(ctx, item.visualization);
            insights.push(insight);
            layoutItems.push(buildInitialItem(insight, i));
        }
        if (isDashboardItemVisualizationContent(item)) {
            const insight = item.visualizationContent;
            insights.push(insight);
            layoutItems.push(buildInitialItem(insight, i));
        }
    }
    const dashboard = buildInitialDashboard(layoutItems);
    return {
        dashboard,
        insights,
    };
}
function buildInitialDashboard(items) {
    const ref = {
        type: "analyticalDashboard",
        identifier: "",
    };
    return {
        type: "IDashboard",
        layout: {
            type: "IDashboardLayout",
            sections: [
                {
                    header: {},
                    type: "IDashboardLayoutSection",
                    items,
                },
            ],
        },
        shareStatus: "private",
        created: "",
        updated: "",
        title: "",
        description: "",
        ref,
        uri: ref.identifier,
        identifier: ref.identifier,
    };
}
function buildInitialItem(insight, i) {
    return {
        type: "IDashboardLayoutItem",
        size,
        widget: {
            type: "insight",
            title: insight.insight.title,
            description: "",
            localIdentifier: `${insight.insight.identifier}_${i}`,
            insight: insight.insight.ref,
            identifier: insight.insight.identifier,
            uri: insight.insight.uri,
            ref: insight.insight.ref,
            ignoreDashboardFilters: [],
            drills: [],
        },
    };
}
//# sourceMappingURL=dashboardInitialize.js.map