// ──────────────────────────────────────────────────────────────────────────
// Client-sichere Konstanten des Creator-Management-Moduls.
// Kein Prisma-/Server-Import — darf in Client-Komponenten verwendet werden.
// ──────────────────────────────────────────────────────────────────────────

// Aktuell integrierte Plattformen (weitere sind vorbereitet).
export const PLATFORMS = ["twitch", "youtube", "tiktok", "instagram", "discord"] as const;
export type PlatformKey = (typeof PLATFORMS)[number];

export type MetricDef = { key: string; label: string; short: string };

export type PlatformMeta = {
  key: PlatformKey;
  label: string;
  color: string;
  followerLabel: string; // wie der Haupt-Reichweitenwert heißt
  metrics: MetricDef[]; // zusätzliche getrackte Kennzahlen
};

export const PLATFORM_META: Record<PlatformKey, PlatformMeta> = {
  twitch: {
    key: "twitch",
    label: "Twitch",
    color: "#b69cff",
    followerLabel: "Follower",
    metrics: [
      { key: "liveViewers", label: "Zuschauer live", short: "Live" },
      { key: "avgViewers", label: "Ø Zuschauer", short: "Ø Zush." },
      { key: "peakViewers", label: "Peak Zuschauer", short: "Peak" },
      { key: "streamsPerWeek", label: "Streams / Woche", short: "Streams/W" },
    ],
  },
  youtube: {
    key: "youtube",
    label: "YouTube",
    color: "#ff5c5c",
    followerLabel: "Abonnenten",
    metrics: [
      { key: "views", label: "Aufrufe gesamt", short: "Views" },
      { key: "videos", label: "Videos", short: "Videos" },
      { key: "avgViews", label: "Ø Aufrufe / Video", short: "Ø Views" },
    ],
  },
  tiktok: {
    key: "tiktok",
    label: "TikTok",
    color: "#7ee7e0",
    followerLabel: "Follower",
    metrics: [
      { key: "likes", label: "Likes gesamt", short: "Likes" },
      { key: "views", label: "Aufrufe gesamt", short: "Views" },
      { key: "postsPerWeek", label: "Posts / Woche", short: "Posts/W" },
    ],
  },
  instagram: {
    key: "instagram",
    label: "Instagram",
    color: "#ff9fd7",
    followerLabel: "Follower",
    metrics: [
      { key: "posts", label: "Beiträge", short: "Posts" },
      { key: "engagement", label: "Engagement-Rate %", short: "Eng. %" },
    ],
  },
  discord: {
    key: "discord",
    label: "Discord",
    color: "#8aa0ff",
    followerLabel: "Mitglieder",
    metrics: [{ key: "online", label: "Ø online", short: "Ø online" }],
  },
};

export function isPlatform(x: string): x is PlatformKey {
  return (PLATFORMS as readonly string[]).includes(x);
}

// ── Pipeline / Status ──────────────────────────────────────────────────────

export type CreatorStatusKey =
  | "OBSERVING"
  | "CONTACTING"
  | "CONVERSATION"
  | "ONBOARDING"
  | "TRIAL"
  | "ACTIVE"
  | "INACTIVE"
  | "FORMER"
  | "BLOCKED";

export type StatusMeta = {
  value: CreatorStatusKey;
  label: string;
  color: string;
  hint: string;
  // pipeline: erscheint als Spalte im Pipeline-Board (echte Fortschrittsstufen)
  pipeline: boolean;
};

export const STATUSES: StatusMeta[] = [
  { value: "OBSERVING", label: "Beobachtung", color: "#9ed7ff", hint: "Gefunden & potenziell interessant", pipeline: true },
  { value: "CONTACTING", label: "Kontaktaufnahme", color: "#38bdf8", hint: "Erster Kontakt hergestellt", pipeline: true },
  { value: "CONVERSATION", label: "Gespräch", color: "#c8bcff", hint: "Zeigt Interesse", pipeline: true },
  { value: "ONBOARDING", label: "Onboarding", color: "#ffc36b", hint: "In der Aufnahmephase", pipeline: true },
  { value: "TRIAL", label: "Probephase", color: "#ffd76b", hint: "Teil des Netzwerks, in Bewertung", pipeline: true },
  { value: "ACTIVE", label: "Aktiv", color: "#7ee787", hint: "Vollwertiger Teil des Netzwerks", pipeline: true },
  { value: "INACTIVE", label: "Inaktiv", color: "#8aa0c8", hint: "Beziehung besteht, aktuell inaktiv", pipeline: false },
  { value: "FORMER", label: "Ehemalig", color: "#6b7a99", hint: "Zusammenarbeit beendet", pipeline: false },
  { value: "BLOCKED", label: "Blockiert", color: "#ff7a9c", hint: "Nicht mehr berücksichtigen", pipeline: false },
];

export const statusMeta = (s: string): StatusMeta => STATUSES.find((x) => x.value === s) ?? STATUSES[0];
export const PIPELINE_STATUSES = STATUSES.filter((s) => s.pipeline);

// ── Kategorien & Content-Typ ───────────────────────────────────────────────

export const CATEGORIES: { value: string; label: string }[] = [
  { value: "gaming", label: "Gaming" },
  { value: "just_chatting", label: "Just Chatting" },
  { value: "entertainment", label: "Entertainment" },
  { value: "irl", label: "IRL" },
  { value: "education", label: "Education" },
  { value: "other", label: "Sonstige" },
];

export const GAME_CATEGORIES: { value: string; label: string }[] = [
  { value: "gta_rp", label: "GTA RP" },
  { value: "minecraft", label: "Minecraft" },
  { value: "survival", label: "Survival" },
  { value: "shooter", label: "Shooter" },
  { value: "simulation", label: "Simulation" },
  { value: "strategy", label: "Strategie" },
  { value: "variety", label: "Variety Gaming" },
];

export type ContentTypeKey = "STREAMER" | "YOUTUBER" | "SHORTFORM" | "HYBRID";
export const CONTENT_TYPES: { value: ContentTypeKey; label: string }[] = [
  { value: "STREAMER", label: "Streamer" },
  { value: "YOUTUBER", label: "YouTuber" },
  { value: "SHORTFORM", label: "Shortform Creator" },
  { value: "HYBRID", label: "Hybrid Creator" },
];

export const CONTACT_METHODS: { value: string; label: string }[] = [
  { value: "discord", label: "Discord" },
  { value: "twitch", label: "Twitch" },
  { value: "email", label: "E-Mail" },
  { value: "instagram", label: "Instagram" },
  { value: "event", label: "Event" },
  { value: "other", label: "Sonstiges" },
];

export const labelOf = (list: { value: string; label: string }[], v: string | null | undefined) =>
  (v ? list.find((x) => x.value === v)?.label : null) ?? null;

// ── Helfer für Zahlen ──────────────────────────────────────────────────────

export function fnum(n: number | null | undefined): string {
  if (n == null) return "—";
  const abs = Math.abs(n);
  if (abs >= 1_000_000) return `${(n / 1_000_000).toFixed(1).replace(/\.0$/, "")}M`;
  if (abs >= 1_000) return `${(n / 1_000).toFixed(1).replace(/\.0$/, "")}K`;
  return String(Math.round(n));
}

// ── Timeline / Events ──────────────────────────────────────────────────────

export const EVENT_META: Record<string, { label: string; color: string; icon: string }> = {
  STATUS: { label: "Status", color: "#c8bcff", icon: "trending" },
  CONTACT: { label: "Kontakt", color: "#9ed7ff", icon: "mail" },
  PLATFORM: { label: "Plattform", color: "#7ee7e0", icon: "at" },
  SNAPSHOT: { label: "Statistik", color: "#7ee787", icon: "trending" },
  ONBOARDING: { label: "Onboarding", color: "#ffc36b", icon: "check" },
  PROJECT: { label: "Projekt", color: "#ff9fd7", icon: "projects" },
  NOTE: { label: "Notiz", color: "#8aa0c8", icon: "edit" },
  SYSTEM: { label: "System", color: "#6b7a99", icon: "settings" },
};
