import Link from "next/link";
import { cardPrice, productHref, type ProductCard } from "@/app/(site)/_lib/products";

/**
 * A product in the catalogue grid (markup of the static catalogue's cards). The design's
 * two text lines are the short description and the price ("Request a quote" for
 * products whose price is on request).
 */
export function ProductCardItem({ p, pageLang = "en" }: { p: ProductCard; pageLang?: string }) {
  const price = cardPrice(p.price, pageLang);
  return (
    <article className="product-card" lang={p.language && p.language !== pageLang ? p.language : undefined}>
      <Link href={productHref(p.slug)} className="product-card-link">
        <div className="product-card-image">
          {p.thumbnail?.url && <img src={p.thumbnail.url} alt={p.thumbnail.alt ?? ""} width="400" height="300" loading="lazy" />}
        </div>
        <div className="product-card-body">
          <h3 className="product-card-title">{p.name}</h3>
          {p.shortDescription && <p className="product-card-desc">{p.shortDescription}</p>}
          <p className="product-card-desc">
            {price ? (
              <>
                {price.market && (
                  <>
                    <s className="text-[#8a94a3]">{price.market}</s>{" "}
                  </>
                )}
                <strong className="font-semibold text-ink">{price.text}</strong>
              </>
            ) : (
              "Request a quote"
            )}
          </p>
        </div>
      </Link>
    </article>
  );
}
