"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isTileInPagedExport = exports.getPagedExportOrphanHomeTabUuid = exports.resolveExportTabs = void 0;
/**
 * Resolves which dashboard tabs a per-tab export renders, in dashboard order.
 * null = "all tabs" → non-hidden only; explicit selection honors hidden tabs.
 */
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));
};
exports.resolveExportTabs = resolveExportTabs;
/**
 * 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.
 */
const getPagedExportOrphanHomeTabUuid = (resolvedTabUuids) => resolvedTabUuids[0] ?? null;
exports.getPagedExportOrphanHomeTabUuid = getPagedExportOrphanHomeTabUuid;
/**
 * 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.
 */
const isTileInPagedExport = (tile, resolvedTabUuids) => tile.tabUuid
    ? resolvedTabUuids.includes(tile.tabUuid)
    : (0, exports.getPagedExportOrphanHomeTabUuid)(resolvedTabUuids) !== null;
exports.isTileInPagedExport = isTileInPagedExport;
//# sourceMappingURL=exportTabs.js.map