import React, { useState } from "react";
import { Link, useLocation } from "react-router-dom";
import { primaryNav, footerNavGroups } from "../data/navLinks";
import { Bars3Icon, XMarkIcon } from "@heroicons/react/24/outline";

interface MarketingLayoutProps {
  children: React.ReactNode;
}

const MarketingLayout: React.FC<MarketingLayoutProps> = ({ children }) => {
  const [mobileOpen, setMobileOpen] = useState(false);
  const location = useLocation();

  const toggleMobile = () => setMobileOpen((prev) => !prev);
  const closeMobile = () => setMobileOpen(false);

  return (
    <div className="min-h-screen flex flex-col bg-gradient-to-b from-white via-gray-50 to-white text-gray-900">
      <header className="sticky top-0 z-[1100] backdrop-blur-xl bg-white/95 border-b border-gray-200 shadow-sm">
        <div className="max-w-6xl mx-auto px-6 py-4 flex items-center justify-between">
          <Link to="/" className="flex items-center gap-3" onClick={closeMobile}>
            <img
              src="/images/logo/IGNY8_LIGHT_LOGO.png"
              alt="IGNY8"
              className="h-10 w-auto"
            />
          </Link>

          <nav className="hidden lg:flex items-center gap-8 text-sm font-medium">
            {primaryNav.map((link) => {
              const isActive = location.pathname === link.path;
              return (
                <Link
                  key={link.name}
                  to={link.path}
                  className={`transition hover:text-[var(--color-primary)] ${isActive ? "text-[var(--color-primary)] font-semibold" : "text-gray-700"}`}
                >
                  {link.name}
                </Link>
              );
            })}
          </nav>

          <div className="hidden lg:flex items-center gap-4">
            <a
              href="https://app.igny8.com/login"
              className="text-sm font-medium text-gray-700 hover:text-gray-900 transition"
            >
              Log in
            </a>
            <a
              href="https://app.igny8.com/signup"
              className="inline-flex items-center justify-center rounded-full bg-gradient-to-r from-[var(--color-primary)] to-[var(--color-primary-dark)] hover:from-[var(--color-primary-dark)] hover:to-[var(--color-primary)] text-white px-5 py-2 text-sm font-semibold transition shadow-md shadow-[var(--color-primary)]/30"
            >
              Start Free
            </a>
          </div>

          <button
            className="lg:hidden inline-flex items-center justify-center rounded-lg border border-gray-200 p-2 text-gray-700"
            onClick={toggleMobile}
            aria-label="Toggle navigation"
          >
            {mobileOpen ? <XMarkIcon className="h-6 w-6" /> : <Bars3Icon className="h-6 w-6" />}
          </button>
        </div>

        {mobileOpen && (
          <div className="lg:hidden border-t border-gray-200 bg-white backdrop-blur-xl">
            <nav className="px-6 py-4 flex flex-col gap-3">
              {primaryNav.map((link) => (
                <Link
                  key={link.name}
                  to={link.path}
                  onClick={closeMobile}
                  className="text-sm font-medium text-gray-700 hover:text-gray-900 transition"
                >
                  {link.name}
                </Link>
              ))}
            </nav>
            <div className="px-6 pb-6 flex flex-col gap-3">
              <a
                href="https://app.igny8.com/login"
                className="text-sm font-medium text-gray-700 hover:text-gray-900 transition"
                onClick={closeMobile}
              >
                Log in
              </a>
              <a
                href="https://app.igny8.com/signup"
                className="inline-flex items-center justify-center rounded-full bg-gradient-to-r from-[var(--color-primary)] to-[var(--color-primary-dark)] hover:from-[var(--color-primary-dark)] hover:to-[var(--color-primary)] text-white px-5 py-2 text-sm font-semibold transition shadow-md shadow-[var(--color-primary)]/30"
                onClick={closeMobile}
              >
                Start Free
              </a>
            </div>
          </div>
        )}
      </header>

      <main className="flex-1">{children}</main>

      <footer className="bg-gradient-to-br from-[#0d1b2a] via-[#142b3f] to-[#0d1b2a] border-t border-[var(--color-primary)]/20">
        <div className="max-w-6xl mx-auto px-6 py-16 grid grid-cols-1 md:grid-cols-4 gap-12">
          <div className="space-y-4">
            <Link to="/" className="inline-flex items-center gap-3">
              <img
                src="/images/logo/IGNY8_DARK_LOGO.png"
                alt="IGNY8"
                className="h-10 w-auto"
              />
            </Link>
            <p className="text-sm text-gray-300 max-w-xs">
              Automate keyword intelligence, clustering, content production, and image creation in one unified growth engine.
            </p>
            <div className="text-xs text-gray-400">
              © {new Date().getFullYear()} Igny8 Labs. All rights reserved.
            </div>
          </div>

          {footerNavGroups.map((group) => (
            <div key={group.title}>
              <h4 className="text-sm font-semibold text-white uppercase tracking-wide mb-4">
                {group.title}
              </h4>
              <ul className="space-y-3 text-sm text-gray-300">
                {group.links.map((link) => (
                  <li key={link.name}>
                    <Link to={link.path} className="hover:text-[var(--color-primary)] transition">
                      {link.name}
                    </Link>
                  </li>
                ))}
              </ul>
            </div>
          ))}
        </div>
        <div className="border-t border-[var(--color-primary)]/20 py-6 px-6 text-center text-xs text-gray-400">
          Built for marketers who automate growth with AI.
        </div>
      </footer>
    </div>
  );
};

export default MarketingLayout;

