import "server-only"; import { getRegistry } from "@/modules/_core"; import type { SerializedWidgetMeta } from "@/modules/_core/registry"; import type { DashboardLayout, PresetId } from "./dashboard"; import { computePresetLayoutFromMetas } from "./dashboard"; /** Build a layout matching one of the design's three dashboard arrangements * using the live module registry. Server-only — the registry is empty on * the client. */ export function computePresetLayout(preset: PresetId): DashboardLayout { const { widgets } = getRegistry(); if (widgets.length === 0) return { version: 1, widgets: [] }; const sorted = [...widgets].sort((a, b) => a.defaultPriority - b.defaultPriority); const metas: SerializedWidgetMeta[] = sorted.map((w) => ({ id: w.id, title: w.title, description: w.description, category: w.category, defaultSize: w.defaultSize, minSize: w.minSize, maxSize: w.maxSize, defaultConfig: w.defaultConfig, })); return computePresetLayoutFromMetas(preset, metas); } export function computeDefaultLayout(): DashboardLayout { return computePresetLayout("classic"); }