import Link from 'next/link';
import { auth } from '@/lib/auth';
import { RocketIcon, getButtonClassName } from '@/components/ui';
import { ThemeToggle } from './ThemeToggle';
import { UserMenu } from './UserMenu';
import { WorkshopsDropdown } from './WorkshopsDropdown';
import { NavLinks } from './NavLinks';

export async function Header() {
  const session = await auth();
  const isAuthenticated = !!session?.user;

  return (
    <header className="sticky top-0 z-50 border-b border-border bg-card/80 backdrop-blur-sm">
      <div className="mx-auto flex h-16 max-w-7xl items-center justify-between px-4">
        <Link href="/" className="flex items-center gap-2">
          <RocketIcon className="h-7 w-7 shrink-0 text-primary" />
          <span className="text-xl font-bold text-foreground">Workshop Manager</span>
        </Link>

        <nav className="flex items-center gap-4">
          {isAuthenticated && (
            <>
              <NavLinks />
              <WorkshopsDropdown />
            </>
          )}

          <ThemeToggle />

          {isAuthenticated ? (
            <UserMenu
              userName={session.user?.name}
              userEmail={session.user?.email ?? ''}
            />
          ) : (
            <Link
              href="/login"
              className={getButtonClassName({ size: 'sm' })}
            >
              Connexion
            </Link>
          )}
        </nav>
      </div>
    </header>
  );
}
