/**
 * Notifications store — owns notification list and toast integration.
 *
 * Extracted from App.svelte inline state (Phase 2).
 */

// ── Types ─────────────────────────────────────────────────────────────────

export interface Notification {
  id: number;
  message: string;
  type: 'success' | 'warning' | 'info' | 'error';
  time: string;
}

// ── State ─────────────────────────────────────────────────────────────────

let notifications = $state<Notification[]>([
  { id: 1, message: 'Agent completed: wake scheduler implemented', type: 'success', time: '2m ago' },
  { id: 2, message: 'Context pressure: 78% on agent-orchestrator', type: 'warning', time: '5m ago' },
  { id: 3, message: 'PTY daemon connected', type: 'info', time: '12m ago' },
]);

let nextId = $state(100);

// ── Public API ────────────────────────────────────────────────────────────

export function getNotifications(): Notification[] {
  return notifications;
}

export function getNotifCount(): number {
  return notifications.length;
}

export function addNotification(message: string, type: Notification['type'] = 'info'): void {
  const now = new Date();
  const time = `${now.getHours()}:${String(now.getMinutes()).padStart(2, '0')}`;
  const id = nextId++;
  notifications = [{ id, message, type, time }, ...notifications].slice(0, 100);
}

export function removeNotification(id: number): void {
  notifications = notifications.filter(n => n.id !== id);
}

export function clearAll(): void {
  notifications = [];
}
