/**
 * Resolves which dashboard tabs a per-tab export renders, in dashboard order.
 * null = "all tabs" → non-hidden only; explicit selection honors hidden tabs.
 */
export const resolveExportTabs = (tabs, selectedTabs) => {
    const ordered = [...tabs].sort((a, b) => a.order - b.order);
    if (selectedTabs === null)
        return ordered.filter((t) => !t.hidden);
    return ordered.filter((t) => selectedTabs.includes(t.uuid));
};
/**
 * Orders tiles the way the dashboard reads: tabs left to right (by `order`),
 * then top-to-bottom / left-to-right within each tab. Orphan (no-tab) tiles
 * sort with the first tab, matching where per-tab exports render them.
 */
export const sortTilesByDashboardOrder = (tiles, tabs) => {
    const tabPositions = new Map([...tabs]
        .sort((a, b) => a.order - b.order)
        .map((t, index) => [t.uuid, index]));
    const position = (tile) => (tile.tabUuid ? tabPositions.get(tile.tabUuid) : undefined) ?? 0;
    return [...tiles].sort((a, b) => position(a) - position(b) || a.y - b.y || a.x - b.x);
};
/**
 * The tab that hosts orphan (legacy, no-tab) tiles in a per-tab export: the
 * first tab in resolved render order. Orphans render on this tab's page.
 * Null when nothing renders. Keying on the first RESOLVED tab (not the literal
 * first dashboard tab) keeps orphans visible when the first tab is hidden or
 * unselected.
 */
export const getPagedExportOrphanHomeTabUuid = (resolvedTabUuids) => resolvedTabUuids[0] ?? null;
/**
 * Whether a tile is rendered by a per-tab (css-paged) export for the given
 * resolved tab selection. A tabbed tile renders iff its tab is resolved; an
 * orphan (legacy, no-tab) tile renders iff there is an orphan-home tab. Backend
 * and frontend both call this so their awaited-tile sets stay in lock-step —
 * disagreement makes screenshot readiness hang.
 */
export const isTileInPagedExport = (tile, resolvedTabUuids) => tile.tabUuid
    ? resolvedTabUuids.includes(tile.tabUuid)
    : getPagedExportOrphanHomeTabUuid(resolvedTabUuids) !== null;
//# sourceMappingURL=exportTabs.js.map