"use client"; import type { ChatStatus } from "ai"; import { ArrowUp, Building2, CalendarRange, ChevronDown, Hand, Mic, Plus, Square, Stethoscope, UserPlus, X, } from "lucide-react"; import { type ChangeEvent, type KeyboardEvent, type ReactNode, useCallback, useRef, useState, } from "react"; import { AddPatientDialog } from "@/components/chat/add-patient-dialog"; import { DropdownMenu, DropdownMenuContent, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { cn } from "@/lib/utils"; type ChatInputProps = { onSubmit: (text: string) => void; status: ChatStatus; onStop?: () => void; }; type Option = { value: string; label: string }; const ACCESS_OPTIONS: Option[] = [ { value: "standard", label: "Standard access" }, { value: "break-glass", label: "Break-glass (emergency)" }, { value: "read-only", label: "Read-only" }, ]; const RESPONSE_OPTIONS: Option[] = [ { value: "concise", label: "Concise" }, { value: "detailed", label: "Detailed" }, { value: "comprehensive", label: "Comprehensive" }, ]; const SPECIALTY_OPTIONS: Option[] = [ { value: "internal-medicine", label: "Internal Medicine" }, { value: "cardiology", label: "Cardiology" }, { value: "pediatrics", label: "Pediatrics" }, { value: "emergency", label: "Emergency" }, { value: "all", label: "All specialties" }, ]; const FACILITY_OPTIONS: Option[] = [ { value: "main-hospital", label: "Main Hospital" }, { value: "north-clinic", label: "North Clinic" }, { value: "telehealth", label: "Telehealth" }, ]; const TIME_OPTIONS: Option[] = [ { value: "30d", label: "Last 30 days" }, { value: "12m", label: "Last 12 months" }, { value: "5y", label: "Last 5 years" }, { value: "all", label: "All time" }, ]; const iconButton = "flex size-8 items-center justify-center rounded-lg text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"; const pillButton = "flex h-8 items-center gap-1.5 rounded-lg px-2 text-sm text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"; const contextPill = "flex h-7 items-center gap-1.5 rounded-md px-2 text-[13px] text-muted-foreground transition-colors hover:bg-foreground/5 hover:text-foreground"; function SelectPill({ ariaLabel, triggerClassName, chevronClassName, icon, prefix, value, onValueChange, options, align = "start", }: { ariaLabel: string; triggerClassName: string; chevronClassName: string; icon: ReactNode; prefix?: string; value: string; onValueChange: (value: string) => void; options: Option[]; align?: "start" | "center" | "end"; }) { const selected = options.find((option) => option.value === value); return ( } > {icon} {prefix ? ( {prefix} ) : null} {selected?.label} {options.map((option) => ( {option.label} ))} ); } export function ChatInput({ onSubmit, status, onStop }: ChatInputProps) { const [value, setValue] = useState(""); const [files, setFiles] = useState([]); const [access, setAccess] = useState("standard"); const [responseMode, setResponseMode] = useState("detailed"); const [specialty, setSpecialty] = useState("internal-medicine"); const [facility, setFacility] = useState("main-hospital"); const [timeRange, setTimeRange] = useState("12m"); const [addOpen, setAddOpen] = useState(false); // Bumped on each open so the dialog remounts with a fresh file number + form. const [addKey, setAddKey] = useState(0); const fileInputRef = useRef(null); const isGenerating = status === "submitted" || status === "streaming"; const canSend = (value.trim().length > 0 || files.length > 0) && !isGenerating; const submit = useCallback(() => { const trimmed = value.trim(); if ((!trimmed && files.length === 0) || isGenerating) { return; } const parts: string[] = []; if (trimmed) { parts.push(trimmed); } if (files.length > 0) { parts.push(`[Attached: ${files.map((file) => file.name).join(", ")}]`); } onSubmit(parts.join("\n\n")); setValue(""); setFiles([]); }, [value, files, isGenerating, onSubmit]); const handleKeyDown = useCallback( (event: KeyboardEvent) => { if ( event.key === "Enter" && !event.shiftKey && !event.nativeEvent.isComposing ) { event.preventDefault(); submit(); } }, [submit] ); const handleFilesSelected = useCallback( (event: ChangeEvent) => { const selected = event.target.files; if (selected && selected.length > 0) { setFiles((prev) => [...prev, ...Array.from(selected)]); } // Reset so picking the same file again still fires onChange. event.target.value = ""; }, [] ); const removeFile = useCallback((index: number) => { setFiles((prev) => prev.filter((_, i) => i !== index)); }, []); return ( <>
{ event.preventDefault(); submit(); }} className="w-full overflow-hidden rounded-[28px] border border-border/60 bg-[oklch(0.195_0.006_277)] shadow-sm" > {/* Top (lighter) card: textarea + toolbar, with a slightly smaller bottom radius */}