"use client"; import { useRef, useState } from "react"; import { ChevronDown, FileText, X } from "lucide-react"; import { ContentEditor, type ContentEditorRef } from "../../editor"; import { Button } from "@multica/ui/components/ui/button"; import { cn } from "@multica/ui/lib/utils"; import { useT } from "../../i18n"; interface InstructionsEditorProps { /** Markdown source. Used both as default value when expanded and as * preview text when collapsed. */ value: string; /** Fires on every keystroke (debounced inside ContentEditor). */ onChange: (value: string) => void; /** Optional placeholder override. Defaults to the i18n "click to write" * copy; the create dialog passes the duplicate-specific string for * agents being cloned. */ placeholder?: string; } /** * Collapsible Instructions field for the create-agent dialog. Stays compact * until the user wants to write — most agents only need instructions when * they're being authored carefully, not on every quick-create. * * Two states: * collapsed → small clickable card, shows a preview of `value` (or the * placeholder when empty). One click expands. * expanded → full ContentEditor (markdown, bubble menu, mention support, * attachment upload). "Collapse" button on the right of the * header tucks it back; value is preserved. */ export function InstructionsEditor({ value, onChange, placeholder, }: InstructionsEditorProps) { const { t } = useT("agents"); const [expanded, setExpanded] = useState(false); const editorRef = useRef(null); const label = t(($) => $.create_dialog.instructions.label); const resolvedPlaceholder = placeholder ?? t(($) => $.create_dialog.instructions.placeholder_blank); const expand = () => { setExpanded(true); // Focus on next tick so the editor mounts first. setTimeout(() => editorRef.current?.focus(), 0); }; if (!expanded) { return (
{label}
); } return (
{label}
$.create_dialog.instructions.editor_placeholder)} className="min-h-[160px] max-h-[320px] overflow-y-auto px-3 py-2.5 text-sm" showBubbleMenu={true} disableMentions={true} />
); }