import React from 'react';
import { useScrollEffects } from '@/lib/hooks/useScrollEffects';
import { mergeClasses as cn } from '@/lib/styles/designSystem';
import { Logo } from './navbar/Logo';
import { NavLinks } from './navbar/NavLinks';
import { ActionButtons } from './navbar/ActionButtons';
import { MobileMenuButton } from './navbar/MobileMenuButton';
import { MobileMenu } from './MobileMenu';
import type { Translation } from '@/types/i18n';

interface ModernNavigationProps {
  translations: Translation['navigation'];
  languageSwitcher: React.ReactElement;
}

export const ModernNavigation: React.FC<ModernNavigationProps> = ({ 
  translations, 
  languageSwitcher 
}) => {
  const { scrolled } = useScrollEffects();
  const [mobileMenuOpen, setMobileMenuOpen] = React.useState(false);

  // Fermer le menu mobile lors du redimensionnement
  React.useEffect(() => {
    const handleResize = () => {
      if (window.innerWidth >= 768) {
        setMobileMenuOpen(false);
      }
    };

    window.addEventListener('resize', handleResize);
    return () => window.removeEventListener('resize', handleResize);
  }, []);

  // Empêcher le scroll du body quand le menu mobile est ouvert
  React.useEffect(() => {
    if (mobileMenuOpen) {
      document.body.style.overflow = 'hidden';
    } else {
      document.body.style.overflow = 'unset';
    }

    return () => {
      document.body.style.overflow = 'unset';
    };
  }, [mobileMenuOpen]);

  return (
    <>
      {/* Navigation Bar - Design fixe moderne */}
      <nav 
        className={cn(
          'fixed top-0 left-0 right-0 z-50',
          'shadow-banquise-lg border-b'
        )}
        style={{
          backgroundColor: 'var(--banquise-blue-800)',
          borderBottomColor: 'var(--banquise-blue-700)'
        }}
      >
        <div className="max-w-7xl mx-auto">
          <div className="flex justify-between items-center px-4 sm:px-6 lg:px-8 h-16">
            
            {/* Logo Section */}
            <Logo scrolled={false} />

            {/* Navigation Links (Desktop) */}
            <NavLinks 
              translations={translations}
              scrolled={false}
              className="flex-1 justify-center ml-8"
            />

            {/* Action Buttons (Desktop) */}
            <ActionButtons 
              scrolled={false}
              languageSwitcher={languageSwitcher}
            />

            {/* Mobile Menu Button */}
            <MobileMenuButton
              isOpen={mobileMenuOpen}
              onClick={() => setMobileMenuOpen(!mobileMenuOpen)}
            />
          </div>
        </div>

        {/* Effet de bordure dégradée moderne */}
        <div className="absolute bottom-0 left-0 right-0">
          <div className="h-px bg-gradient-to-r from-transparent via-banquise-blue-200/40 to-transparent" />
        </div>
      </nav>

      {/* Spacer pour compenser la navbar fixed */}
      <div className="h-16" />

      {/* Menu Mobile */}
      <MobileMenu
        isOpen={mobileMenuOpen}
        onClose={() => setMobileMenuOpen(false)}
        translations={translations}
      />
    </>
  );
};
