import { useState } from "react"; import { Link } from "react-router-dom"; import type { AiCitation } from "@ledger/shared"; import { api } from "../lib/api"; import { EmptyState } from "./EmptyState"; import { PageHeader } from "./PageHeader"; export function AskAiPage() { const [question, setQuestion] = useState(""); const [answer, setAnswer] = useState<{ answer: string; citations: AiCitation[]; disabled?: boolean } | null>(null); const [loading, setLoading] = useState(false); async function submit(event: React.FormEvent) { event.preventDefault(); if (!question.trim()) return; setLoading(true); try { const response = await api.post<{ answer: string; citations: AiCitation[]; disabled?: boolean }>("/api/ai/answers", { question }); setAnswer(response); } catch (error) { setAnswer({ answer: error instanceof Error ? error.message : "Could not answer this question.", citations: [] }); } finally { setLoading(false); } } return (