import { useQuery } from '@tanstack/react-query'; import { BookOpen, Bot, ChevronRight, Layers, NotebookPen, Pencil, RotateCcw, Trash2 } from 'lucide-react'; import { useEffect, useState, type ReactNode } from 'react'; import { toast } from 'sonner'; import { api, errorMessage } from '@/lib/api'; import { qk, useRefresh } from '@/lib/queries'; import type { Template } from '@/lib/types'; import { cx, plural } from '@/lib/util'; import { Badge, Button, Dialog, Field, IconButton, Input, Section, Segmented, Select, Skeleton, Textarea, useConfirm } from '@/ui'; /* ------------------------------ shared text editor ------------------------------ */ /** A collapsible row holding one block of instructions, with save and reset. */ function InstructionRow({ label, text, builtin, customized, onSave }: { label: string; text: string; builtin: string; customized: boolean; onSave: (text: string | null) => Promise }) { const [open, setOpen] = useState(false); const [value, setValue] = useState(text); const [busy, setBusy] = useState(false); useEffect(() => setValue(text), [text]); const dirty = value.trim() !== text.trim(); const save = async (next: string | null) => { setBusy(true); try { await onSave(next); toast.success(next === null ? 'Back to the built-in wording' : 'Saved'); } catch (e) { toast.error(errorMessage(e)); } finally { setBusy(false); } }; return (
  • {open && (