import React, { useState, useRef, useEffect } from 'react'; import Login from './Login'; interface HeaderProps { onViewChange: (view: 'AI' | 'FAQ' | 'Documentation' | 'Credits') => void; showDivs: boolean; toggleDivs: () => void; showHistoryModelsToggle: boolean; showToggle: boolean; } const Header: React.FC = ({ onViewChange, showDivs, toggleDivs, showHistoryModelsToggle, showToggle, }) => { const [menuOpen, setMenuOpen] = useState(false); const dropdownRef = useRef(null); const toggleRef = useRef(null); // Toggle menu state const toggleMenu = () => { setMenuOpen((prevMenuOpen) => !prevMenuOpen); }; // Handle button click const buttonClicked = (page: "AI" | "Documentation" | "FAQ" | "Credits") => { onViewChange(page); setMenuOpen(false); // Close the menu when a button is clicked }; // Effect to handle clicks outside of the dropdown useEffect(() => { const handleClickOutside = (event: MouseEvent) => { if ( dropdownRef.current && !dropdownRef.current.contains(event.target as Node) && toggleRef.current && !toggleRef.current.contains(event.target as Node) ) { setMenuOpen(false); } }; document.addEventListener('mousedown', handleClickOutside); return () => { document.removeEventListener('mousedown', handleClickOutside); }; }, []); return ( <>
{showToggle && showHistoryModelsToggle && ( )}
{/* AI logo or text */}
); }; export default Header;