/* eslint-disable i18next/no-literal-string */ import { useState, useRef, useEffect, type KeyboardEvent } from "react"; import { motion, AnimatePresence } from "framer-motion"; interface TerminalLine { id: string; type: "input" | "output" | "system"; text: string; timestamp: number; } interface TerminalProps { lines?: TerminalLine[]; onCommand?: (command: string) => void; height?: string | number; readOnly?: boolean; } export function Terminal({ lines: externalLines, onCommand, height = 280, readOnly = false, }: TerminalProps) { const [localLines, setLocalLines] = useState([]); const [input, setInput] = useState(""); const [history, setHistory] = useState([]); const [historyIndex, setHistoryIndex] = useState(-1); const endRef = useRef(null); const inputRef = useRef(null); const lines = externalLines ?? localLines; useEffect(() => { endRef.current?.scrollIntoView({ behavior: "smooth" }); }, [lines]); const handleKeyDown = (e: KeyboardEvent) => { if (e.key === "Enter" && input.trim()) { const cmd = input.trim(); const newLine: TerminalLine = { id: `cmd-${Date.now()}`, type: "input", text: `$ ${cmd}`, timestamp: Date.now(), }; setLocalLines((prev) => [...prev, newLine]); setHistory((prev) => [...prev, cmd]); setHistoryIndex(-1); setInput(""); onCommand?.(cmd); // No demo mode — if no onCommand is provided, the terminal is read-only } else if (e.key === "ArrowUp") { e.preventDefault(); if (history.length > 0) { const newIdx = historyIndex < history.length - 1 ? historyIndex + 1 : historyIndex; setHistoryIndex(newIdx); setInput(history[history.length - 1 - newIdx] || ""); } } else if (e.key === "ArrowDown") { e.preventDefault(); if (historyIndex > 0) { const newIdx = historyIndex - 1; setHistoryIndex(newIdx); setInput(history[history.length - 1 - newIdx] || ""); } else { setHistoryIndex(-1); setInput(""); } } }; return ( {/* Terminal Header */}