// Shared shape of the remote-driven broadcast JSON (see HOME-SPEC.md).
// One hosted file is the source of truth for everything Luke pushes to every
// install: the broadcast strip, the welcome video, community links, and the
// latest pack version. Client + server both import these types, so keep this
// file free of node imports.

export interface BroadcastStripData {
  show: boolean;
  badge?: string;
  headline?: string;
  body?: string;
  ctaLabel?: string;
  ctaUrl?: string;
  accent?: string; // "gold" (default) | "plum" | "violet" | "emerald"
}

export interface WelcomeVideoData {
  show: boolean;
  version: number; // bump to re-show the modal to everyone
  title?: string;
  subtitle?: string;
  embedUrl?: string;
}

export interface BroadcastLink {
  label: string;
  url: string;
}

export interface LatestPackInfo {
  version?: string;
  packUrl?: string;
}

export interface BroadcastPayload {
  version?: string; // bump to re-show a dismissed broadcast strip
  broadcast?: BroadcastStripData;
  welcomeVideo?: WelcomeVideoData;
  links?: BroadcastLink[];
  latest?: LatestPackInfo | null;
  source?: "remote" | "fallback";
}

// localStorage keys — single definition so the modal, the strip, and the
// dashboard never drift apart.
export const WELCOME_SEEN_KEY = "mm-welcome-seen";
export const BROADCAST_DISMISSED_KEY = "mm-broadcast-dismissed";

/** Map a broadcast accent name onto a theme token so it recolours per theme. */
export function accentVar(accent?: string): string {
  switch ((accent ?? "gold").toLowerCase()) {
    case "plum":
    case "magenta":
    case "pink":
      return "var(--plum)";
    case "violet":
    case "purple":
    case "rust":
      return "var(--rust)";
    case "emerald":
    case "green":
      return "var(--emerald)";
    default:
      return "var(--gold)";
  }
}
