/**
 * Page-scoped primary action for the global topbar CTA.
 *
 * Each route declares its own primary action ("Add Provider",
 * "New Tracker", etc.) by calling `topbarAction.set({...})`
 * inside its `onMount`, and clears it on teardown. The layout
 * reads `topbarAction.current` and renders the button.
 *
 * Falls back to the default "New tracker" CTA when no action is
 * registered (set by the layout itself).
 */
export interface TopbarAction {
	/** Visible label, e.g. "Add Provider". */
	label: string;
	/** Optional href — renders as <a>. Mutually exclusive with onclick. */
	href?: string;
	/** Optional click handler — renders as <button>. */
	onclick?: () => void;
	/** Optional MDI/NavIcon name for the leading glyph (default: mdiPlus). */
	icon?: string;
}

let action = $state<TopbarAction | null>(null);

export const topbarAction = {
	get current(): TopbarAction | null {
		return action;
	},
	set(next: TopbarAction | null) {
		action = next;
	},
	clear() {
		action = null;
	},
};
