import { Play, Search, Sparkles } from "lucide-react"; import { FormEvent, useState } from "react"; import { lookupDrug } from "../api"; type FormValues = { name: string; drug_name: string; structure_input: string; structure_format: "smiles" | "inchi"; target_name: string; indication: string; mechanism: string; patent_text: string; }; const DEFAULT_VALUES: FormValues = { name: "EGFR follow-up", drug_name: "Gefitinib", structure_input: "CCOc1ccc2nc(S(N)(=O)=O)sc2c1", structure_format: "smiles", target_name: "EGFR", indication: "oncology", mechanism: "kinase inhibition", patent_text: "Avoid sulfonamide substitutions and keep Tanimoto similarity below 0.95.", }; export function ProjectForm({ onRun, disabled, }: { onRun: (payload: Record) => void; disabled: boolean; }) { const [values, setValues] = useState(DEFAULT_VALUES); const [referenceStructureSvg, setReferenceStructureSvg] = useState(""); const [lookupStatus, setLookupStatus] = useState<"idle" | "loading" | "loaded" | "failed">("idle"); const [lookupError, setLookupError] = useState(null); function updateValue(name: keyof FormValues, value: string) { setValues((current) => ({ ...current, [name]: value })); } function submit(event: FormEvent) { event.preventDefault(); onRun({ ...values, }); } async function handleLookup() { if (!values.drug_name.trim()) return; setLookupStatus("loading"); setLookupError(null); try { const result = await lookupDrug(values.drug_name); setValues((current) => ({ ...current, name: current.name.trim() ? current.name : `${result.drug_name} follow-up`, drug_name: result.drug_name, structure_input: result.structure_input, structure_format: result.structure_format, target_name: result.target_name, indication: result.indication, mechanism: result.mechanism, })); setReferenceStructureSvg(result.structure_svg); setLookupStatus("loaded"); } catch (err) { setLookupStatus("failed"); setLookupError(err instanceof Error ? err.message : "Drug lookup failed"); } } return (
Molecular design input

Project Input

{lookupStatus === "loaded" &&

Drug context loaded into target fields.

} {lookupError &&

{lookupError}

} {referenceStructureSvg && (
Reference structure {values.drug_name}
)}