import type { Metadata } from "next";
import { notFound } from "next/navigation";
import {
  SiteClosingCta,
  SiteEmptyState,
  SiteMetaRow,
  SitePageHero,
  SiteShell,
} from "@/components/site/site-shell";
import { resolveRequestTenant } from "@/core/tenant/request-tenant";
import { studioPageMetadata } from "@/core/tenant/studio-metadata";
import { listPublishedAwards } from "@/services/award-service";
import { getArchitectProfile } from "@/services/profile-service";

export async function generateMetadata(): Promise<Metadata> {
  const resolved = await resolveRequestTenant();
  if (!resolved.ok) return { title: "Awards", robots: { index: false } };
  return studioPageMetadata(
    resolved.context.studioName,
    "Awards",
    `Competitions, certifications, and honors for ${resolved.context.studioName}.`,
  );
}

export default async function TenantAwardsPage() {
  const resolved = await resolveRequestTenant();
  if (!resolved.ok) notFound();

  const [{ profile }, awards] = await Promise.all([
    getArchitectProfile(resolved.context),
    listPublishedAwards(resolved.context),
  ]);

  return (
    <SiteShell
      studioName={resolved.context.studioName}
      location={profile?.location}
      active="awards"
    >
      <main>
        <SitePageHero
          eyebrow="Recognition"
          title="Awards"
          description={`Competitions, certifications, and honors for ${resolved.context.studioName}.`}
        />

        <section className="studio-container pb-16 pt-10 sm:pb-20 sm:pt-12">
          {awards.length === 0 ? (
            <SiteEmptyState
              title="Recognition forthcoming"
              description="Published awards and honors will appear here as the studio’s portfolio of recognition grows."
            />
          ) : (
            <ul className="divide-y divide-[var(--archi-line)] border-y border-[var(--archi-line)]">
              {awards.map((award) => (
                <li
                  key={award.id}
                  className="grid gap-3 py-10 sm:grid-cols-[7rem_1fr] sm:gap-12 lg:py-14"
                >
                  <p className="font-[family-name:var(--font-display)] text-sm tracking-[0.18em] text-[var(--archi-gold)] uppercase">
                    {award.year ?? "—"}
                  </p>
                  <div>
                    <h2 className="font-[family-name:var(--font-display)] text-[clamp(1.5rem,4vw,2.25rem)] tracking-tight sm:text-4xl">
                      {award.title}
                    </h2>
                    <SiteMetaRow
                      className="mt-3"
                      items={[award.organization, award.category]}
                    />
                    {award.description ? (
                      <p className="mt-5 max-w-2xl whitespace-pre-wrap text-base leading-8 text-[var(--archi-ink-muted)]">
                        {award.description}
                      </p>
                    ) : null}
                  </div>
                </li>
              ))}
            </ul>
          )}
        </section>

        <SiteClosingCta studioName={resolved.context.studioName} />
      </main>
    </SiteShell>
  );
}
