import { Link } from "react-router-dom";
import { Clock, Facebook, Mail, MapPin, Phone } from "lucide-react";
import { useLocale } from "@/i18n/LocaleContext";
import { siteSettings } from "@/content/site-settings";
import { UI } from "@/i18n/translations";
import { getPath, type PageKey } from "@/i18n/routes";

const QUICK_LINKS: PageKey[] = ["municipality", "community", "businesses", "events"];

export function Footer() {
  const { t, locale } = useLocale();
  const year = new Date().getFullYear();
  const logo = (window as any).__CASCA_SITE__?.logo?.src || "";

  return (
    <footer className="bg-footer text-footer-foreground mt-12">
      <div className="container grid gap-10 py-14 md:grid-cols-2 lg:grid-cols-4">
        <div className="space-y-4">
          <div className="flex items-center gap-3">
            {logo && <img src={logo} alt="" width={48} height={48} className="h-12 w-12 object-contain" />}
            <span className="font-display italic text-lg leading-tight">
              {t(siteSettings.municipality.name)}
            </span>
          </div>
          {siteSettings.social.facebook && (
            <a
              href={siteSettings.social.facebook}
              target="_blank"
              rel="noopener noreferrer"
              aria-label="Facebook"
              className="inline-flex h-9 w-9 items-center justify-center rounded-sm bg-[hsl(220_85%_45%)] text-white hover:opacity-90 transition-opacity"
            >
              <Facebook className="h-4 w-4" aria-hidden />
            </a>
          )}
        </div>

        <div>
          <h2 className="font-display text-lg mb-3">{t(UI.footer.address)}</h2>
          <p className="text-footer-muted-foreground whitespace-pre-line text-sm leading-relaxed inline-flex items-start gap-2">
            <MapPin className="h-4 w-4 mt-0.5 shrink-0" aria-hidden />
            <span>{t(siteSettings.contact.address)}</span>
          </p>
        </div>

        <div>
          <h2 className="font-display text-lg mb-3">{t(UI.footer.contact)}</h2>
          <ul className="space-y-2 text-sm text-footer-muted-foreground">
            <li>
              <a href={`tel:${siteSettings.contact.phone.replace(/[^0-9+]/g, "")}`} className="inline-flex items-center gap-2 hover:text-footer-foreground transition-colors">
                <Phone className="h-4 w-4" aria-hidden />
                {siteSettings.contact.phone}
              </a>
            </li>
            <li>
              <a href={`mailto:${siteSettings.contact.email}`} className="inline-flex items-center gap-2 hover:text-footer-foreground transition-colors break-all">
                <Mail className="h-4 w-4 shrink-0" aria-hidden />
                {siteSettings.contact.email}
              </a>
            </li>
            <li className="inline-flex items-start gap-2">
              <Clock className="h-4 w-4 mt-0.5 shrink-0" aria-hidden />
              <span>
                <span className="block font-medium text-footer-foreground/90">{t(UI.footer.hours)}</span>
                {t(siteSettings.contact.hours)}
              </span>
            </li>
          </ul>
        </div>

        <div>
          <h2 className="font-display text-lg mb-3">{t(UI.footer.quick)}</h2>
          <ul className="space-y-2 text-sm">
            {QUICK_LINKS.map((key) => (
              <li key={key}>
                <Link reloadDocument to={getPath(key, locale)} className="text-footer-muted-foreground hover:text-footer-foreground transition-colors">
                  {t(UI.nav[key])}
                </Link>
              </li>
            ))}
          </ul>
        </div>
      </div>

      <div className="border-t border-white/10">
        <div className="container py-5 text-xs text-footer-muted-foreground flex flex-wrap items-center justify-between gap-2">
          <p>
            © {year} {t(siteSettings.municipality.name)}. {t(UI.footer.rights)}
          </p>
        </div>
      </div>
    </footer>
  );
}