"use client"; import { setCurrentSubject } from "@/lib/current-subject"; import { chatProfileChoice, chatProfileDisplayName, chatProfileSelectedId, chatSessionSubjectLocked, type ChatProfileCatalogStatus, type ChatProfilePickerRow, } from "@/lib/chat-profile-picker-model"; import type { ChartLibraryRecord, ChatSession } from "@/lib/home-types"; import { SubjectSwitcher } from "@/components/subject-switcher"; export type ChatProfilePickerProps = { readonly session: ChatSession; readonly library: readonly ChartLibraryRecord[]; readonly status: ChatProfileCatalogStatus; readonly requestInFlight: boolean; readonly onBindEmpty: (chartProfileId: string) => Promise; readonly onOpenNew: (chartProfileId: string) => Promise; readonly onReload: () => void; }; export function ChatProfilePicker({ session, library, status, requestInFlight, onBindEmpty, onOpenNew, onReload, }: ChatProfilePickerProps) { const label = chatProfileDisplayName({ session, status, library }); const selectedId = chatProfileSelectedId(session); const locked = chatSessionSubjectLocked(session); const deleted = status === "ready" && Boolean(selectedId) && selectedId !== "self" && !library.some((record) => ( record.role === "other" && record.id === selectedId )); async function choose(row: ChatProfilePickerRow): Promise { const choice = chatProfileChoice({ session, chartProfileId: row.id, requestInFlight, libraryReady: status === "ready", selectable: row.complete, }); if (choice.action === "ignore") return false; setCurrentSubject(choice.chartProfileId); if (choice.action === "bind") return onBindEmpty(choice.chartProfileId); return onOpenNew(choice.chartProfileId); } return ( ); }