"use client"; import { House } from "lucide-react"; import { useTransition } from "react"; import { toast } from "sonner"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { switchHouseholdAction } from "@/features/households/actions"; import type { HouseholdSummary } from "@/features/households/types"; import { tr } from "@/i18n/tr"; /** Üst bar aktif hane seçici. Seçim sunucuda doğrulanır ve cookie'ye yazılır. */ export function HouseholdSwitcher({ households, activeId, }: { households: HouseholdSummary[]; activeId: string | undefined; }) { const [pending, startTransition] = useTransition(); const current = households.find((h) => h.id === activeId); if (households.length === 0) return null; function onChange(id: string) { if (id === activeId) return; startTransition(async () => { const result = await switchHouseholdAction(id); if (result.ok) toast.success(tr.household.switched(result.data.name)); else toast.error(result.error); }); } return ( ); }