"use client";

import React, { useState } from "react";
import Link from "next/link";
import Image from "next/image";

const Header = () => {
  const [isMenuOpen, setIsMenuOpen] = useState(false);

  const closeAllMenus = () => {
    setIsMenuOpen(false);
  };

  return (
    <header className="sticky bg-white top-0 z-50 shadow-sm">
      <div className="container max-w-7xl mx-auto px-4 sm:px-6">
        <div className="flex justify-between items-center py-3 sm:py-4">
          {/* Logo */}
          <div className="flex-shrink-0">
            <Link href="/" onClick={closeAllMenus} className="flex items-center">
              <div className="relative w-80 h-18 mr-3 rounded overflow-hidden">
                <Image
                  src="/images/logo.png"
                  alt="CMC Logo"
                  fill
                  className="object-fill"
                  priority
                />
              </div>
            </Link>
          </div>

          {/* Desktop Navigation */}
          <nav className="hidden lg:flex items-start space-x-8">
            {["/", "/about", "/events", "/education-training", "/research", "/blogs", "/teamMember", "/career", "/contact"].map((href, idx) => (
              <Link
                key={idx}
                href={href}
                className="text-blue-900 hover:text-red-600 transition-colors font-medium"
                onClick={closeAllMenus}
              >
                {href === "/" ? "Home" :
                 href === "/about" ? "About" :
                 href === "/events" ? "Events" :
                 href === "/education-training" ? "Education" :
                 href === "/research" ? "Research" :
                 href === "/blogs" ? "Blogs" :
                 href === "/teamMember" ? "Team Member" :
                 href === "/career" ? "Career" :
                 href === "/contact" ? "Contact Us" : ""}
              </Link>
            ))}
          </nav>

          {/* Mobile menu button */}
          <button
            className="lg:hidden p-2 text-blue-900 hover:text-red-600 transition-colors"
            onClick={() => setIsMenuOpen(!isMenuOpen)}
          >
            <svg
              className="w-6 h-6"
              fill="none"
              stroke="currentColor"
              viewBox="0 0 24 24"
            >
              {isMenuOpen ? (
                <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>
      </div>

      {/* Mobile Menu */}
      {isMenuOpen && (
        <div className="lg:hidden bg-gray-100 border-t border-blue-900">
          <nav className="px-4 py-4">
            <ul className="space-y-4">
              {["/", "/about", "/events", "/blogs", "/career", "/contact", "/teamMember"].map((href, idx) => (
                <li key={idx}>
                  <Link
                    href={href}
                    className="block font-medium py-2 text-blue-900 hover:text-red-600 transition-colors"
                    onClick={closeAllMenus}
                  >
                    {href === "/" ? "Home" :
                     href === "/about" ? "About" :
                     href === "/events" ? "Events" :
                     href === "/blogs" ? "Blogs" :
                     href === "/career" ? "Career" :
                     href === "/contact" ? "Contact" :
                     href === "/teamMember" ? "Team Member" : ""}
                  </Link>
                </li>
              ))}
            </ul>
          </nav>
        </div>
      )}
    </header>
  );
};

export default Header;
