import { useState } from "react";
import { Plus } from "lucide-react";
import { useWallets } from "@/lib/queries";
import { WalletCard } from "./components/WalletCard";
import { CreateWalletDialog } from "./components/CreateWalletDialog";

export function WalletsPage() {
  const { data: wallets, isLoading } = useWallets();
  const [createOpen, setCreateOpen] = useState(false);

  return (
    <div className="space-y-4">
      <div className="flex items-center justify-between">
        <h1 className="text-2xl font-semibold">Billeteras</h1>
        <button
          type="button"
          onClick={() => setCreateOpen(true)}
          className="inline-flex items-center gap-2 rounded-lg bg-primary px-3 py-1.5 text-sm font-medium text-primary-foreground hover:bg-primary/90 transition-colors cursor-pointer"
        >
          <Plus className="size-4" />
          Nueva billetera
        </button>
      </div>

      {isLoading ? (
        <p className="text-sm text-muted-foreground">Cargando...</p>
      ) : wallets && wallets.length > 0 ? (
        <div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
          {wallets.map((wallet) => (
            <WalletCard key={wallet.id} wallet={wallet} />
          ))}
        </div>
      ) : (
        <p className="text-sm text-muted-foreground">
          No hay billeteras. Creá una para empezar.
        </p>
      )}

      <CreateWalletDialog open={createOpen} onOpenChange={setCreateOpen} />
    </div>
  );
}
