import Link from "next/link";
import { getCurrentUser } from "@/lib/api/auth";
import { UserMenu } from "@/components/layout/user-menu";
import { FOCUS_RING_CLASSES } from "@/components/ui/styles";
import { cn } from "@/lib/utils";

/**
 * Server Component: reads the httpOnly session cookie server-side (never
 * exposed to client JS) and calls Laravel /auth/me to resolve who's logged
 * in. Only the interactive dropdown (UserMenu) needs "use client" — the
 * guest links and the auth check itself stay server-rendered.
 */
export async function AuthStatus() {
  const user = await getCurrentUser();

  if (!user) {
    return (
      <div className="flex items-center gap-3 text-sm font-medium">
        <Link
          href="/login"
          className={cn("rounded transition-colors hover:text-kolabora-primary", FOCUS_RING_CLASSES)}
        >
          Log in
        </Link>
        <Link
          href="/register"
          className={cn(
            "rounded-full bg-kolabora-primary px-4 py-2 text-kolabora-neutral-white transition-opacity hover:opacity-90",
            FOCUS_RING_CLASSES,
          )}
        >
          Register
        </Link>
      </div>
    );
  }

  return <UserMenu name={user.name} role={user.role} />;
}
