/**
 * WorthDoing.ai
 * Author: Simon-Pierre Boucher
 * Contact: contact@spboucher.ai
 * File: src/components/wd/badges.tsx
 * Description: Status/phase badges — color always paired with a text label, never color alone.
 */
import { cn } from "@/lib/utils";

const HYPOTHESIS_STYLES: Record<string, string> = {
  proposed: "bg-secondary text-ink-soft",
  investigating: "bg-tele/10 text-tele",
  supported: "bg-verdict/10 text-verdict",
  validated: "bg-verdict/15 text-verdict",
  weakened: "bg-signal/12 text-signal",
  rejected: "bg-rust/10 text-rust",
};

export function HypothesisBadge({ status }: { status: string }) {
  return (
    <span
      className={cn(
        "inline-flex items-center rounded-full px-2 py-0.5 font-mono text-[10px] uppercase tracking-wider",
        HYPOTHESIS_STYLES[status] ?? "bg-secondary text-ink-soft",
      )}
    >
      {status}
    </span>
  );
}

const PHASE_LABELS: Record<string, string> = {
  scouting: "Scouting",
  investigating: "Investigating",
  skeptic: "Skeptic phase",
  synthesizing: "Synthesizing",
  done: "Done",
};

const PHASE_STYLES: Record<string, string> = {
  scouting: "bg-tele/10 text-tele",
  investigating: "bg-verdict/10 text-verdict",
  skeptic: "bg-signal/12 text-signal",
  synthesizing: "bg-ink/8 text-ink",
  done: "bg-secondary text-ink-soft",
};

export function PhaseBadge({ phase, live }: { phase: string; live?: boolean }) {
  return (
    <span
      className={cn(
        "inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 font-mono text-[11px] uppercase tracking-wider",
        PHASE_STYLES[phase] ?? "bg-secondary text-ink-soft",
      )}
    >
      {live && <span className="wd-live-dot h-1.5 w-1.5 rounded-full bg-current" />}
      {PHASE_LABELS[phase] ?? phase}
    </span>
  );
}

const STATUS_STYLES: Record<string, string> = {
  pending: "bg-secondary text-ink-soft",
  running: "bg-verdict/10 text-verdict",
  completed: "bg-ink/8 text-ink",
  failed: "bg-rust/10 text-rust",
  cancelled: "bg-secondary text-ink-soft",
};

export function InvestigationStatusBadge({ status, live }: { status: string; live?: boolean }) {
  return (
    <span
      className={cn(
        "inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 font-mono text-[11px] uppercase tracking-wider",
        STATUS_STYLES[status] ?? "bg-secondary text-ink-soft",
      )}
    >
      {live && status === "running" && <span className="wd-live-dot h-1.5 w-1.5 rounded-full bg-current" />}
      {status}
    </span>
  );
}

export function EvidenceKindBadge({ kind }: { kind: string }) {
  const styles: Record<string, string> = {
    support: "bg-verdict/10 text-verdict",
    contradict: "bg-rust/10 text-rust",
    context: "bg-secondary text-ink-soft",
  };
  return (
    <span
      className={cn(
        "inline-flex items-center rounded-full px-2 py-0.5 font-mono text-[10px] uppercase tracking-wider",
        styles[kind] ?? styles.context,
      )}
    >
      {kind}
    </span>
  );
}
