import { getTranslations } from "next-intl/server";
import { restaurant } from "@/content/restaurant";
import { dayHoursLabel } from "@/lib/hours";
import { Reveal } from "@/components/Reveal";
import { PhoneIcon, WhatsAppIcon, MailIcon, PinIcon } from "@/components/icons";

export default async function ContactPage() {
  const t = await getTranslations("footer");
  const tVisit = await getTranslations("visit");
  const tContact = await getTranslations("contactPage");

  const methods: { icon: React.ReactNode; label: string; value: string; href: string; external?: boolean }[] = [
    {
      icon: <PhoneIcon />,
      label: tContact("call"),
      value: restaurant.phone,
      href: `tel:${restaurant.phone.replace(/\s/g, "")}`,
    },
    {
      icon: <WhatsAppIcon />,
      label: "WhatsApp",
      value: restaurant.phone,
      href: `https://wa.me/${restaurant.whatsapp.replace(/\D/g, "")}`,
    },
    {
      icon: <MailIcon />,
      label: tContact("email"),
      value: restaurant.email,
      href: `mailto:${restaurant.email}`,
    },
    {
      icon: <PinIcon />,
      label: tContact("address"),
      value: `${restaurant.address.street}, ${restaurant.address.postalCode} ${restaurant.address.city}`,
      href: restaurant.address.mapsUrl,
      external: true,
    },
  ];

  return (
    <div className="mx-auto max-w-5xl px-6 py-20">
      <Reveal className="text-center">
        <p className="eyebrow text-brass">La Tavola Italiana</p>
        <h1 className="mt-3 font-serif text-4xl italic text-ivory">{t("contact")}</h1>
        <p className="mt-2 text-ivory-dim">{tContact("subtitle")}</p>
      </Reveal>

      <div className="mt-12 grid gap-4 sm:grid-cols-2">
        {methods.map((m, i) => (
          <Reveal key={m.label} delay={i * 60}>
            <a
              href={m.href}
              target={m.external ? "_blank" : undefined}
              rel={m.external ? "noopener" : undefined}
              className="group flex items-center gap-4 overflow-hidden rounded-2xl border border-ivory/10 bg-espresso-light p-5 transition hover:border-brass/40"
            >
              <span className="flex h-11 w-11 shrink-0 items-center justify-center rounded-full bg-tomato/15 text-tomato transition group-hover:bg-tomato group-hover:text-ivory">
                {m.icon}
              </span>
              <span className="min-w-0">
                <span className="eyebrow block text-ivory-dim/60">{m.label}</span>
                <span className="block truncate text-ivory">{m.value}</span>
              </span>
            </a>
          </Reveal>
        ))}
      </div>

      <div className="mt-16 grid gap-10 md:grid-cols-2">
        <Reveal className="overflow-hidden rounded-2xl border border-ivory/10 grayscale contrast-125 transition hover:grayscale-0">
          <iframe
            title="map"
            src={`https://www.google.com/maps?q=${encodeURIComponent(
              `${restaurant.address.street}, ${restaurant.address.postalCode} ${restaurant.address.city}`
            )}&output=embed`}
            className="h-72 w-full border-0 md:h-full"
            loading="lazy"
          />
        </Reveal>

        <Reveal delay={100}>
          <p className="eyebrow text-brass">{tVisit("hours")}</p>
          <ul className="mt-3 space-y-1.5 text-sm text-ivory-dim">
            {restaurant.hours.map((h) => (
              <li key={h.day} className="flex justify-between gap-6 border-b border-ivory/10 py-1.5">
                <span className="capitalize">{h.day}</span>
                <span className="whitespace-nowrap tabular-nums">{dayHoursLabel(h)}</span>
              </li>
            ))}
          </ul>

          <div className="mt-8 grid grid-cols-2 gap-6">
            <div>
              <p className="eyebrow text-brass">{tVisit("parking")}</p>
              <p className="mt-2 text-sm text-ivory-dim">{tVisit("parkingInfo")}</p>
            </div>
            <div>
              <p className="eyebrow text-brass">{tVisit("transit")}</p>
              <p className="mt-2 text-sm text-ivory-dim">{tVisit("transitInfo")}</p>
            </div>
          </div>
        </Reveal>
      </div>
    </div>
  );
}
