"use client";

import { useState, useEffect } from "react";
import { motion, AnimatePresence } from "framer-motion";
import { Menu, X } from "lucide-react";
import Link from "next/link";

const navLinks = [
  { href: "#products", label: "Products" },
  { href: "#how-it-works", label: "How It Works" },
  { href: "#solutions", label: "Solutions" },
  { href: "#government", label: "Government" },
  { href: "#contact", label: "Contact" },
];

export default function Navbar() {
  const [isScrolled, setIsScrolled] = useState(false);
  const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);

  useEffect(() => {
    const handleScroll = () => setIsScrolled(window.scrollY > 20);
    window.addEventListener("scroll", handleScroll);
    return () => window.removeEventListener("scroll", handleScroll);
  }, []);

  return (
    <motion.header
      initial={{ y: -100 }}
      animate={{ y: 0 }}
      transition={{ duration: 0.5, ease: "easeOut" }}
      className={`fixed top-0 left-0 right-0 z-50 transition-all duration-300 ${
        isScrolled ? "glass shadow-lg" : "bg-transparent"
      }`}
    >
      <nav className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
        <div className="flex items-center justify-between h-16 lg:h-20">
          <Link href="#" className="flex items-center gap-2">
            <span className="text-2xl font-bold text-[#0f172a]">Sasium</span>
          </Link>

          <div className="hidden md:flex items-center gap-8">
            {navLinks.map((link) => (
              <Link
                key={link.href}
                href={link.href}
                className="text-[#64748b] hover:text-[#2563eb] font-medium transition-colors"
              >
                {link.label}
              </Link>
            ))}
          </div>

          <div className="hidden md:flex items-center gap-3">
            <Link
              href="#contact"
              className="px-4 py-2 text-[#2563eb] font-medium hover:bg-[#2563eb]/10 rounded-lg transition-colors"
            >
              Request Demo
            </Link>
            <Link
              href="#contact"
              className="px-5 py-2.5 bg-[#2563eb] text-white font-medium rounded-lg hover:bg-[#1d4ed8] transition-colors shadow-lg shadow-[#2563eb]/25"
            >
              Government Partnerships
            </Link>
          </div>

          <button
            className="md:hidden p-2 text-[#0f172a]"
            onClick={() => setIsMobileMenuOpen(!isMobileMenuOpen)}
            aria-label="Toggle menu"
          >
            {isMobileMenuOpen ? <X size={24} /> : <Menu size={24} />}
          </button>
        </div>
      </nav>

      <AnimatePresence>
        {isMobileMenuOpen && (
          <motion.div
            initial={{ opacity: 0, height: 0 }}
            animate={{ opacity: 1, height: "auto" }}
            exit={{ opacity: 0, height: 0 }}
            className="md:hidden glass border-t border-[#e2e8f0]"
          >
            <div className="px-4 py-4 space-y-2">
              {navLinks.map((link) => (
                <Link
                  key={link.href}
                  href={link.href}
                  className="block py-2 text-[#64748b] hover:text-[#2563eb] font-medium"
                  onClick={() => setIsMobileMenuOpen(false)}
                >
                  {link.label}
                </Link>
              ))}
              <div className="pt-4 space-y-2 border-t border-[#e2e8f0]">
                <Link
                  href="#contact"
                  className="block py-2 text-[#2563eb] font-medium"
                  onClick={() => setIsMobileMenuOpen(false)}
                >
                  Request Demo
                </Link>
                <Link
                  href="#contact"
                  className="block py-3 bg-[#2563eb] text-white text-center font-medium rounded-lg"
                  onClick={() => setIsMobileMenuOpen(false)}
                >
                  Government Partnerships
                </Link>
              </div>
            </div>
          </motion.div>
        )}
      </AnimatePresence>
    </motion.header>
  );
}
