import Image from "next/image";
import Link from "next/link";
import { localizedPath, type ArticleCardDto, type Locale } from "@alterra/shared";
import { fill } from "@/lib/propertyCopy";
import { formatDate, type InsightsCopy } from "@/lib/insightsCopy";

export default function ArticleCard({ article, lang, copy, large = false }: { article: ArticleCardDto; lang: Locale; copy: InsightsCopy; large?: boolean }) {
  return (
    <article className={`group ${large ? "grid gap-8 lg:grid-cols-[1.4fr_1fr] lg:items-center lg:gap-14" : ""}`}>
      <Link href={localizedPath(lang, `/insights/${article.slug}`)} className="relative block aspect-[3/2] overflow-hidden bg-moss" tabIndex={-1} aria-hidden>
        {article.coverImage && (
          <Image
            src={article.coverImage}
            alt=""
            fill
            sizes={large ? "(min-width: 1024px) 58vw, 100vw" : "(min-width: 1024px) 33vw, (min-width: 768px) 50vw, 100vw"}
            className="object-cover transition-transform duration-[1.6s] group-hover:scale-[1.05]"
          />
        )}
      </Link>
      <div className={large ? "" : "mt-6"}>
        <p className="eyebrow flex flex-wrap items-center gap-x-3 gap-y-1 text-[0.6rem] text-gold-ink">
          {copy.categories[article.category]}
          <span className="text-stone">·</span>
          <span className="text-stone">{formatDate(article.publishedAt, lang)}</span>
        </p>
        <h3 className={`mt-3 font-serif leading-snug transition-colors group-hover:text-forest ${large ? "text-4xl md:text-5xl" : "text-2xl"}`}>
          <Link href={localizedPath(lang, `/insights/${article.slug}`)}>{article.title}</Link>
        </h3>
        <p className={`mt-3 text-stone ${large ? "text-lg" : "text-sm"}`}>{article.excerpt}</p>
        <p className="mt-4 text-xs tracking-wide text-stone">{fill(copy.readingTime, { n: article.readingMinutes })}</p>
      </div>
    </article>
  );
}
