// Top Bar Component
import { useAuthStore } from '@/stores/authStore';
import { useNavigate } from 'react-router-dom';
import Button from '@/components/shared/Button';
import './TopBar.css';

export default function TopBar() {
  const { user, logout } = useAuthStore();
  const navigate = useNavigate();

  const handleLogout = async () => {
    await logout();
    navigate('/login');
  };

  return (
    <header className="topbar">
      <div className="topbar__left">
        <h1 className="topbar__title">DBIS Admin Console</h1>
      </div>
      <div className="topbar__right">
        <div className="topbar__user">
          <span className="topbar__user-name">{user?.name || 'User'}</span>
          <span className="topbar__user-role">{user?.role || ''}</span>
        </div>
        <Button variant="ghost" size="small" onClick={handleLogout}>
          Logout
        </Button>
      </div>
    </header>
  );
}

