import { FaCircleUser } from 'react-icons/fa6';

import { InDoorIcon } from '@/components/Icons';
import { useAuth } from '@/context/AuthContext';
import { useConceptNavigation } from '@/context/NagivationContext';
import useDropdown from '@/hooks/useDropdown';

import NavigationButton from './NavigationButton';
import UserDropdown from './UserDropdown';

function UserMenu() {
  const router = useConceptNavigation();
  const { user } = useAuth();
  const menu = useDropdown();

  const navigateLogin = () => router.push('/login');
  return (
  <div ref={menu.ref} className='h-full'>
    {!user ?
    <NavigationButton
      description='Перейти на страницу логина'
      icon={<InDoorIcon />}
      onClick={navigateLogin}
    /> : null}
    {user ?
    <NavigationButton
      description={`Пользователь ${user?.username}`}
      icon={<FaCircleUser size='1.5rem' />}
      onClick={menu.toggle}
    /> : null}
    {(user && menu.isActive) ?
    <UserDropdown
      hideDropdown={() => menu.hide()}
    /> : null}
  </div>);
}

export default UserMenu;