
import React, { useState, useEffect } from 'react';
import type { DashboardView } from '../../types';

interface NavbarProps {
  activeView: DashboardView;
  onViewChange: (view: DashboardView) => void;
  onLogout: () => void;
  onBackToCoordinatorHub?: () => void;
}

const Navbar: React.FC<NavbarProps> = ({ activeView, onViewChange, onLogout, onBackToCoordinatorHub }) => {
  const [isScrolled, setIsScrolled] = useState(false);

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

  const menuItems: { id: DashboardView; label: string }[] = [
    { id: 'HOME', label: 'HOME' },
    { id: 'EVENTS', label: 'EVENTS' },
    { id: 'REGISTRATIONS', label: 'REGISTRATIONS' },
    { id: 'PROFILE', label: 'PROFILE' },
    { id: 'ABOUT', label: 'ABOUT' },
    { id: 'CONTACT', label: 'CONTACT' },
  ];

  return (
    <nav className={`fixed top-4 left-1/2 -translate-x-1/2 w-[92%] max-w-7xl z-[100] transition-all duration-500 px-6 md:px-8 py-3 rounded-2xl flex items-center justify-between border ${
      isScrolled 
        ? 'bg-white/75 backdrop-blur-lg border-white/30 shadow-lg shadow-black/5' 
        : 'bg-black/20 backdrop-blur-md border-white/10 shadow-md'
    }`}>
      {/* Brand Logo (Top Left) */}
      <div 
        className="flex items-center cursor-pointer group transition-transform hover:scale-105" 
        onClick={() => onViewChange('HOME')}
      >
        <div className="transition-all duration-300">
          <img 
            src="/Rit-logo.png" 
            alt="RIT Logo" 
            className="h-10 w-auto object-contain transition-all duration-300 filter drop-shadow-[0_1px_2px_rgba(255,255,255,0.1)]"
          />
        </div>
      </div>

      {/* Nav Links & Logout (Right Side) */}
      <div className="flex items-center gap-8 md:gap-12">
        <div className="hidden md:flex items-center gap-8">
          {onBackToCoordinatorHub && (
            <button
              onClick={onBackToCoordinatorHub}
              className={`text-[10px] font-black tracking-[0.2em] px-4 py-1.5 rounded-lg transition-all border border-[#f97316] text-[#f97316] hover:bg-[#f97316] hover:text-white`}
            >
              COORDINATOR HUB
            </button>
          )}
          {menuItems.map((item) => (
            <button
              key={item.id}
              onClick={() => onViewChange(item.id)}
              className={`text-xs font-serif tracking-[0.2em] transition-all relative py-1 ${
                activeView === item.id 
                  ? 'text-[#f97316]' 
                  : isScrolled ? 'text-slate-800 hover:text-[#f97316]' : 'text-white hover:text-[#f97316]'
              }`}
            >
              {item.label}
              {activeView === item.id && (
                <span className="absolute -bottom-1 left-0 w-full h-[1px] bg-[#f97316]"></span>
              )}
            </button>
          ))}
        </div>

        <button 
          onClick={onLogout} 
          className={`text-[10px] font-black tracking-[0.2em] px-6 py-2 rounded-full transition-all border bg-[#f97316] text-white border-[#f97316] hover:bg-[#ea580c] hover:border-[#ea580c]`}
        >
          LOG OUT
        </button>
      </div>
    </nav>
  );
};

export default Navbar;

