"use client";

import {
  MapPin,
  Phone,
  Clock,
  Navigation,
} from "lucide-react";

import { useLanguage } from "@/lib/i18n";
import { restaurant } from "@/lib/data";
import { SectionHeading } from "@/components/section-heading";

export function Location() {
  const { t } = useLanguage();

  return (
    <section className="border-t border-border/60 bg-card/40">
      <div className="mx-auto max-w-7xl px-4 py-20 md:px-8 md:py-24">
        <SectionHeading
          tag={t("location.tag")}
          title={t("location.title")}
          align="left"
        />

        <div className="mt-10 grid gap-8 lg:grid-cols-2">
          {/* INFORMATIONS */}
          <div className="space-y-5">
            <InfoRow
              icon={MapPin}
              label={t("location.address")}
              value={restaurant.address}
            />

            <InfoRow
              icon={Phone}
              label={t("location.phone")}
              value={restaurant.phone}
              href={`tel:${restaurant.phoneRaw}`}
            />

            <InfoRow
              icon={Clock}
              label={t("location.hours")}
              value={t("location.hoursValue")}
            />

            {/* BOUTON GOOGLE MAPS */}
            <a
              href={`https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(
                restaurant.mapsQuery
              )}`}
              target="_blank"
              rel="noopener noreferrer"
              className="inline-flex items-center gap-2 rounded-full bg-primary px-6 py-3 text-sm font-semibold text-primary-foreground transition-opacity hover:opacity-90"
            >
              <Navigation className="h-4 w-4" />
              {t("location.directions")}
            </a>
          </div>

          {/* CARTE */}
          <div className="min-h-80 overflow-hidden rounded-xl border border-border">
            <iframe
              title="Localisation de Happy Hours Abidjan"
              src={`https://www.google.com/maps?q=${encodeURIComponent(
                restaurant.mapsQuery
              )}&output=embed`}
              className="h-full min-h-80 w-full border-0"
              loading="lazy"
              allowFullScreen
              referrerPolicy="strict-origin-when-cross-origin"
            />
          </div>
        </div>
      </div>
    </section>
  );
}

function InfoRow({
  icon: Icon,
  label,
  value,
  href,
}: {
  icon: React.ComponentType<{ className?: string }>;
  label: string;
  value: string;
  href?: string;
}) {
  return (
    <div className="flex gap-4 rounded-xl border border-border bg-card p-5">
      {/* ICÔNE */}
      <div className="flex h-11 w-11 shrink-0 items-center justify-center rounded-full bg-primary/10 text-primary">
        <Icon className="h-5 w-5" />
      </div>

      {/* INFORMATIONS */}
      <div>
        <span className="text-xs uppercase tracking-wider text-muted-foreground">
          {label}
        </span>

        {href ? (
          <a
            href={href}
            className="mt-0.5 block font-medium text-foreground hover:text-primary"
          >
            {value}
          </a>
        ) : (
          <p className="mt-0.5 font-medium text-foreground">
            {value}
          </p>
        )}
      </div>
    </div>
  );
}