"use client"; /** * True while either wizard is generating. The in-page mode switch reads this * and hides itself, so a loading run can't be swapped out mid-flight — the * loading screen owns the page until it finishes or is cancelled. */ import { useSyncExternalStore } from "react"; let busy = false; const listeners = new Set<() => void>(); export const wizardBusy = { subscribe(listener: () => void): () => void { listeners.add(listener); return () => listeners.delete(listener); }, getSnapshot(): boolean { return busy; }, getServerSnapshot(): boolean { return false; }, set(value: boolean): void { if (busy === value) return; busy = value; listeners.forEach((listener) => listener()); }, }; export function useWizardBusy(): boolean { return useSyncExternalStore(wizardBusy.subscribe, wizardBusy.getSnapshot, wizardBusy.getServerSnapshot); }