import type { Metadata } from "next";
import { notFound } from "next/navigation";
import { SitePageHero, SiteShell } from "@/components/site/site-shell";
import { resolveRequestTenant } from "@/core/tenant/request-tenant";
import { studioPageMetadata } from "@/core/tenant/studio-metadata";
import { getArchitectProfile } from "@/services/profile-service";
import TenantContactForm from "./contact-form";

export async function generateMetadata(): Promise<Metadata> {
  const resolved = await resolveRequestTenant();
  if (!resolved.ok) return { title: "Contact", robots: { index: false } };
  return studioPageMetadata(
    resolved.context.studioName,
    "Contact",
    `Inquire with ${resolved.context.studioName} about a project or collaboration.`,
  );
}

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

  const { profile } = await getArchitectProfile(resolved.context);

  return (
    <SiteShell
      studioName={resolved.context.studioName}
      location={profile?.location}
      active="contact"
    >
      <main>
        <SitePageHero
          eyebrow="Inquire"
          title="Contact"
          description={`Your message is delivered only to ${resolved.context.studioName}${
            profile?.location ? ` in ${profile.location}` : ""
          }. Tell us about the site, program, or ambition.`}
        />
        <TenantContactForm
          studioName={resolved.context.studioName}
          profile={
            profile
              ? {
                  publicEmail: profile.publicEmail,
                  phone: profile.phone,
                  whatsapp: profile.whatsapp,
                  businessHours: profile.businessHours,
                  location: profile.location,
                  mapEmbedUrl: profile.mapEmbedUrl,
                  socialLinks: profile.socialLinks,
                }
              : null
          }
        />
      </main>
    </SiteShell>
  );
}
