"use client"; import { useState } from "react"; import { Button } from "@/components/ui"; import { refineHomework } from "@/lib/client-api"; import { useI18n } from "@/lib/i18n"; /** * Follow-up actions for one finished piece of homework: shorter, more detail, * or back to the original. Used on the make result and the corrected version * of a check. */ export function FollowUpBar({ text, context, onReplace, onRestore, canRestore, }: { text: string; context?: string; onReplace: (next: string) => void; onRestore?: () => void; canRestore?: boolean; }) { const { t } = useI18n(); const [busy, setBusy] = useState<"shorter" | "more" | null>(null); const [failed, setFailed] = useState(false); const run = async (instruction: "shorter" | "more") => { if (busy) return; setBusy(instruction); setFailed(false); try { const next = await refineHomework({ instruction, text, context }); onReplace(next); } catch { setFailed(true); } finally { setBusy(null); } }; return (
{busy ? {t("homework.followup.working")} : null} {canRestore && onRestore ? ( ) : null} {failed ? {t("homework.followup.failed")} : null}
); }