import Link from "next/link";
import type { Locale } from "@/i18n/routes";
import { publicPath } from "@/i18n/routes";
import type { Project } from "@/lib/models";
import { getDict } from "@/i18n/dictionaries";

function statusTone(status: string): "live" | "warm" | "muted" {
  const s = status.toLowerCase();
  if (s.startsWith("aktiv") || s.startsWith("live") || s === "running") return "live";
  if (s.includes("early") || s.includes("draft") || s.includes("hardening")) return "warm";
  return "muted";
}

export function ProjectCard({
  project,
  locale,
  showStance = false,
}: {
  project: Project;
  locale: Locale;
  showStance?: boolean;
}) {
  const dict = getDict(locale);
  const href = publicPath(locale, "projectItem", project.slug);
  const tone = statusTone(project.status);
  return (
    <article className="ascii-box group flex flex-col gap-3 transition-colors hover:border-accent">
      <header className="flex items-start justify-between gap-3">
        <div className="flex items-center gap-2">
          <span className="font-mono text-xs text-muted">{project.number}</span>
          <span className={`badge badge--${tone}`}>{project.status}</span>
        </div>
        <span className="font-mono text-xs text-muted">{project.category}</span>
      </header>
      <h3 className="text-lg font-semibold">
        <Link href={href} className="hover:text-accent">
          {project.slug}
        </Link>
      </h3>
      <p className="text-sm text-[var(--fg)]">{project.summary}</p>
      {showStance && project.stance ? (
        <p className="border-l-2 border-accent pl-3 text-xs italic text-muted">{project.stance}</p>
      ) : null}
      <footer className="mt-auto flex flex-wrap items-center gap-2 pt-2 font-mono text-xs text-muted">
        <span>{project.stack.split("·")[0]?.trim() ?? project.stack}</span>
        <span className="ml-auto">
          <Link href={href} className="text-accent hover:underline">
            {dict.actions.openProject} →
          </Link>
        </span>
      </footer>
    </article>
  );
}
