"use server";

import { queryScenarioMeasures } from "./measuresQuery";
import type { Measure } from "@/lib/reporting/measures";
import { emptyTagFilter, type TagFilter } from "@/lib/reporting/viewState";

/**
 * Server action behind the "where the money goes" panel. Runs the grouped
 * measures query directly on the server — no API round-trip — so the panel
 * background-loads while the rest of the page is interactive. Honours the
 * view-wide tag filter so the spend breakdown matches the filtered figures.
 */
export async function loadScenarioMeasures(
  portfolioId: number,
  scenarioId: number | "default",
  tags: TagFilter = emptyTagFilter(),
): Promise<Measure[]> {
  return queryScenarioMeasures(portfolioId, scenarioId, tags);
}
