"use client";

import Image from "next/image";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { Icon, icons } from "./Icon";
import SectionLink from "./SectionLink";

const columns = [
  {
    title: "Solutions",
    links: [
      { href: "/display-native-contextual", label: "Display, native & contextual" },
      { href: "/video-monetization", label: "Video monetization" },
      { href: "/commerce-affiliate", label: "Commerce & affiliate" },
      { href: "/email-social", label: "Email & social" },
      { href: "/mobile-apps", label: "Mobile & apps" },
      { href: "/solutions", label: "All solutions" },
    ],
  },
  {
    title: "AI & Search",
    links: [
      { href: "/ai-site-search", label: "Direqt AI Site Search" },
      { href: "/ai-search#p-searchgpt-connect-widget", label: "SearchGPT Connect Widget" },
      { href: "/ai-search#p-branded-and-white-label-search", label: "Branded search" },
      { href: "/ai-search#p-content-licensing-and-ai-distribution", label: "Content licensing" },
    ],
  },
  {
    title: "Resources",
    links: [
      { href: "#demos", label: "Live demos" },
      { href: "/publishers", label: "By publisher type" },
      { href: "/customer-feedback", label: "Customer feedback" },
      { href: "/faq", label: "FAQs" },
      { href: "#support", label: "Integration & support" },
    ],
  },
  {
    title: "Company",
    links: [
      { href: "/about", label: "About us" },
      { href: "/contact?cta=footer-contact", label: "Contact us" },
      { href: "/login", label: "Publisher login" },
    ],
  },
];

const legal = [
  { href: "/terms", label: "Terms of service" },
  { href: "/privacy", label: "Privacy policy" },
  { href: "/program-policies", label: "Program policies" },
  { href: "/cookie-policy", label: "Cookie policy" },
];

export default function Footer() {
  const pathname = usePathname().replace(/\/$/, "") || "/";
  // Section links are same-page anchors on the home page and point back to it elsewhere
  const href = (h: string) => (h.startsWith("#") && pathname !== "/" ? `/${h}` : h);
  return (
    <footer className="mz-footer">
      <div className="mz-wrap">
        <div className="mz-footer__top">
          <div className="mz-footer__brand">
            <Link className="mz-brand" href="/">
              <Image src="/images/monetize-logo.svg" alt="Monetize.com" width={171} height={28} unoptimized />
            </Link>
            <p>Monetization and audience engagement solutions for publishers, from the AdMedia family of brands.</p>
            <ul className="mz-footer__contact">
              <li>
                <Icon>{icons.mobile}</Icon>
                <a href="tel:+18002487730">1 (800) 248-7730</a>
              </li>
              <li>
                <Icon>{icons.email}</Icon>
                <a href="mailto:info@monetize.com">info@monetize.com</a>
              </li>
              <li>
                <Icon>{icons.building}</Icon>
                <address>
                  6320 Canoga Ave. Suite 200
                  <br />
                  Woodland Hills, CA 91367
                </address>
              </li>
            </ul>
            <Link className="mz-btn mz-btn--white mz-footer__cta" href="/contact?cta=footer#apply" data-open-apply data-cta="footer">Start Monetizing</Link>
          </div>

          <nav className="mz-footer__cols" aria-label="Footer">
            {columns.map((col) => (
              <div key={col.title}>
                <h2>{col.title}</h2>
                {col.links.map((l) => (
                  <SectionLink key={l.label} href={href(l.href)}>{l.label}</SectionLink>
                ))}
              </div>
            ))}
          </nav>
        </div>

        <div className="mz-footer__bottom">
          <p>{`\u00A9 ${new Date().getFullYear()} Monetize.com by AdMedia. All rights reserved.`}</p>
          <nav className="mz-footer__legal" aria-label="Legal">
            {legal.map((l) => (
              <Link key={l.href} href={l.href}>{l.label}</Link>
            ))}
          </nav>
          <a
            className="mz-footer__social"
            href="https://www.linkedin.com/company/monetizesolutions/"
            aria-label="Monetize.com on LinkedIn"
            rel="noopener"
            target="_blank"
          >
            <svg viewBox="0 0 24 24" aria-hidden="true">
              <path d="M4.98 3.5a2.5 2.5 0 1 1 0 5 2.5 2.5 0 0 1 0-5ZM3 9.5h4v11H3v-11Zm6.5 0h3.8v1.6h.1c.5-.9 1.8-1.9 3.7-1.9 4 0 4.7 2.6 4.7 6v5.3h-4v-4.7c0-1.1 0-2.6-1.6-2.6s-1.8 1.2-1.8 2.5v4.8h-4v-11Z" />
            </svg>
          </a>
        </div>
      </div>
    </footer>
  );
}
