import Link from "next/link";
import { Coins } from "lucide-react";
import { getCurrentUser } from "@/lib/session";
import { Button } from "@/components/ui/button";
import { ListemButonu } from "@/components/manuel-liste/listem-butonu";
import { SignOutButton } from "./sign-out-button";

export async function UserNav() {
  const u = await getCurrentUser();

  // Manuel liste localStorage'ta yaşadığı için Listem girişsiz de çalışır
  if (!u) {
    return (
      <div className="flex items-center gap-2">
        <ListemButonu />
        <Button
          asChild
          className="h-12 cursor-pointer rounded-full bg-slate-900 px-7 text-base font-medium text-white transition-colors duration-200 hover:bg-slate-700"
        >
          <Link href="/giris">Giriş yap</Link>
        </Button>
      </div>
    );
  }

  return (
    <div className="flex items-center gap-2">
      <ListemButonu />
      <Link
        href="/paket"
        className="inline-flex h-12 items-center gap-2 whitespace-nowrap rounded-full border border-slate-200 bg-white px-5 text-sm font-semibold text-slate-700 transition-colors duration-200 hover:border-slate-300 hover:bg-slate-50"
        title="Kredilerin — yüklemek için tıkla"
      >
        <Coins className="size-4 text-amber-500" aria-hidden />
        {u.creditBalance} kredi
      </Link>
      <SignOutButton />
    </div>
  );
}
