import Link from "next/link";
import type { ArticleSummary } from "@/types/articles";
import { formatArticleDate } from "@/lib/articles";

export default function ArticleCard({ article }: { article: ArticleSummary }) {
  const dateLabel = formatArticleDate(article.date_added);
  const kind = article.f_type === "B" ? "Blog" : "Article";

  return (
    <Link
      href={`/articles/${encodeURIComponent(article.slug)}`}
      className="immersive-card group flex h-full flex-col overflow-hidden p-6 lg:p-7"
    >
      <div className="immersive-label mb-3 flex flex-wrap items-center gap-2 !text-[hsl(var(--primary))]">
        <span>{kind}</span>
        {dateLabel ? (
          <span className="text-[hsl(var(--muted-foreground))]">• {dateLabel}</span>
        ) : null}
      </div>
      <h3 className="font-heading mb-2 text-lg font-medium tracking-tight transition-colors group-hover:text-[hsl(var(--primary))]">
        {article.title}
      </h3>
      {article.excerpt ? (
        <p className="mb-4 line-clamp-3 text-sm leading-relaxed text-[hsl(var(--muted-foreground))]">
          {article.excerpt}
        </p>
      ) : null}
      {article.categories.length > 0 ? (
        <div className="mt-auto flex flex-wrap gap-2">
          {article.categories.slice(0, 3).map((category) => (
            <span
              key={category.id}
              className="rounded-full border border-white/10 px-2.5 py-1 text-xs text-[hsl(var(--muted-foreground))]"
            >
              {category.name}
            </span>
          ))}
        </div>
      ) : null}
    </Link>
  );
}
