import Link from "next/link";
import { getCurrentAssociate } from "@/lib/identity";
import { clearIdentity } from "@/lib/actions/identity";
import { Button } from "@/components/ui/button";

export async function Navbar() {
  const associate = await getCurrentAssociate();

  return (
    <header className="border-b bg-background">
      <div className="mx-auto flex max-w-5xl items-center justify-between px-4 py-3">
        <Link href="/" className="font-semibold tracking-tight">
          🛒 Product Picker
        </Link>
        <div className="flex items-center gap-3 text-sm">
          {associate ? (
            <>
              <span className="text-muted-foreground">
                Connecté en tant que <strong>{associate}</strong>
              </span>
              <form action={clearIdentity}>
                <Button type="submit" variant="ghost" size="sm">
                  Changer
                </Button>
              </form>
            </>
          ) : (
            <Link href="/qui-es-tu" className="text-muted-foreground underline">
              Qui es-tu ?
            </Link>
          )}
        </div>
      </div>
    </header>
  );
}
