import { claudeStore } from "$lib/stores/claude";
import { NOTIFICATION_SOUNDS, type NotificationType } from "./types";

export function sendTerminalNotification(type: NotificationType, message?: string): void {
  const sound = NOTIFICATION_SOUNDS[type];
  const title = sound.phrase;

  // Create a formatted notification message
  const separator = "═".repeat(50);
  const timestamp = new Date().toLocaleTimeString();

  let emoji = "";
  let color = "";

  switch (type) {
    case "success":
      emoji = "✨";
      color = "\x1b[32m"; // Green
      break;
    case "error":
      emoji = "❌";
      color = "\x1b[31m"; // Red
      break;
    case "permission":
      emoji = "🔐";
      color = "\x1b[33m"; // Yellow
      break;
    case "connection":
      emoji = "🔗";
      color = "\x1b[36m"; // Cyan
      break;
    case "task_start":
      emoji = "🚀";
      color = "\x1b[34m"; // Blue
      break;
  }

  const reset = "\x1b[0m";

  // Format the notification
  const notification = `
${color}${separator}${reset}
${emoji} ${color}NOTIFICATION${reset} - ${timestamp}
${color}${title}${reset}
${message || ""}
${color}${separator}${reset}`;

  // Add to terminal as a special system message
  claudeStore.addLine("system", notification);
}
