"use client";
import { useState } from "react";
import Link from "next/link";
import Image from "next/image";
import { usePathname } from "next/navigation";

export default function Navbar() {
  const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);
  const pathname = usePathname();

  const navLinks = [
    { name: "About Us", href: "/about" },
    { name: "The Candidate", href: "/candidate" },
    { name: "The Approach", href: "/approach" },
    { name: "Contact", href: "/contact" },
  ];

  const isActive = (path: string) => pathname === path;

  return (
    <nav className="fixed top-0 left-0 w-full bg-white/95 backdrop-blur-md shadow-md z-50">
      <div className="container mx-auto px-6 py-4">
        <div className="flex items-center justify-between">
          {/* Left: Logo */}
          <Link href="/" className="flex items-center space-x-2">
            <div className="relative w-10 h-10 md:w-12 md:h-12">
              <Image
                src="/images/tbm_logo.png"
                alt="TBM Lagos Logo"
                width={72}
                height={72}
                className="object-contain"
                priority
              />
            </div>
            <span className="text-sm hidden sm:inline text-gray-600">
              | Movement for Change
            </span>
          </Link>

          {/* Desktop Navigation */}
          <div className="hidden md:flex items-center space-x-8">
            {navLinks.map((link) => (
              <Link
                key={link.href}
                href={link.href}
                className={`text-gray-700 hover:text-blue-700 transition text-sm ${
                  isActive(link.href)
                    ? "text-blue-700 text-sm font-semibold"
                    : ""
                }`}
              >
                {link.name}
              </Link>
            ))}
            {/* Webapp Button */}
            <Link
              href="/webapp"
              className="bg-blue-700 text-white text-sm px-5 py-2 rounded-lg hover:bg-blue-800 transition font-semibold"
            >
              Launch WebApp
            </Link>
          </div>

          {/* Mobile menu button */}
          <button
            className="md:hidden text-gray-700 focus:outline-none"
            onClick={() => setIsMobileMenuOpen(!isMobileMenuOpen)}
          >
            <svg
              className="w-6 h-6"
              fill="none"
              stroke="currentColor"
              viewBox="0 0 24 24"
            >
              {isMobileMenuOpen ? (
                <path
                  strokeLinecap="round"
                  strokeLinejoin="round"
                  strokeWidth={2}
                  d="M6 18L18 6M6 6l12 12"
                />
              ) : (
                <path
                  strokeLinecap="round"
                  strokeLinejoin="round"
                  strokeWidth={2}
                  d="M4 6h16M4 12h16M4 18h16"
                />
              )}
            </svg>
          </button>
        </div>

        {/* Mobile Menu */}
        {isMobileMenuOpen && (
          <div className="md:hidden mt-4 pb-4 space-y-3">
            {navLinks.map((link) => (
              <Link
                key={link.href}
                href={link.href}
                className={`block text-gray-700 hover:text-blue-700 py-2 ${
                  isActive(link.href) ? "text-blue-800 font-semibold" : ""
                }`}
                onClick={() => setIsMobileMenuOpen(false)}
              >
                {link.name}
              </Link>
            ))}
            <Link
              href="/webapp"
              className="block bg-blue-700 text-white px-4 py-2 rounded-lg text-center hover:bg-blue-800 transition"
              onClick={() => setIsMobileMenuOpen(false)}
            >
              Launch WebApp
            </Link>
          </div>
        )}
      </div>
    </nav>
  );
}
