import Link from "next/link";
import { PageShell } from "@/components/page";
import { SHOWCASE } from "@/lib/mock";
import { prisma } from "@/lib/prisma";
import { isWholesale } from "@/lib/roles";
import { readSession } from "@/lib/session";

export default async function ShowcasePage() {
  const session = await readSession();
  const lots = await prisma.auction.findMany({
    where: { wholesaleOnly: false },
    orderBy: { endsAt: "asc" },
    take: 8,
  });
  const visibleLots = lots.filter((lot) => !lot.wholesaleOnly || isWholesale(session));

  return (
    <PageShell
      wide
      eyebrow="On view"
      title="Stones from the floor"
      lede="Members share certified lots and collector stones. Bid on timed auctions, or open a deal room from a profile."
    >
      <div className="showcase-grid">
        {SHOWCASE.map((stone) => (
          <article key={stone.title} className="showcase-card">
            {/* eslint-disable-next-line @next/next/no-img-element */}
            <img src={stone.image} alt="" />
            <div>
              <p className="eg-eyebrow">{stone.origin} · {stone.treatment}</p>
              <h3>{stone.title}</h3>
              <p className="mt-1 text-sm text-muted">{stone.owner}</p>
            </div>
          </article>
        ))}
        {visibleLots.map((lot) => (
          <Link key={lot.id} href={`/auctions/${lot.id}`} className="showcase-card">
            {lot.imageUrl ? (
              // eslint-disable-next-line @next/next/no-img-element
              <img src={lot.imageUrl} alt="" />
            ) : (
              <div className="lot-card__placeholder" style={{ height: 180 }} />
            )}
            <div>
              <p className="eg-eyebrow">{lot.origin || "Origin on request"} · {lot.status}</p>
              <h3>{lot.title}</h3>
              <p className="mt-1 text-sm text-muted">Current ${lot.currentBid.toLocaleString()}</p>
            </div>
          </Link>
        ))}
      </div>
      <p className="mt-8 text-sm text-muted">
        Live bidding lives on{" "}
        <Link href="/auctions" className="text-primary">
          weekly auctions
        </Link>
        .
      </p>
    </PageShell>
  );
}
