"use client"; import type { ReactNode } from "react"; import type { UndoAction } from "@/uhm/lib/useEditorState"; import type { EditorMode } from "@/uhm/lib/editor/session/sessionTypes"; type Props = { mode: EditorMode; setMode: (mode: EditorMode) => void; entityStatus?: string | null; onUndo: () => void; onCommit: () => void; onSubmit: () => void; onRestoreCommit: (commitId: string) => void; isSaving: boolean; isSubmitting: boolean; sectionTitle: string; sectionStatus: string; commitTitle: string; commitNote: string; onCommitTitleChange: (title: string) => void; onCommitNoteChange: (note: string) => void; commitCount: number; hasHeadCommit: boolean; headCommitId: string | null; latestCommitLabel: string | null; commits: Array<{ id: string; created_at?: string; edit_summary: string; user_id: string; }>; changesCount: number; undoStack: UndoAction[]; createdEntities: Array<{ id: string; name: string; }>; createdGeometries: Array<{ id: string | number; geometryType: string; semanticType?: string | null; entityNames: string[]; }>; width?: number; }; export default function Editor({ mode, setMode, entityStatus, onUndo, onCommit, onSubmit, onRestoreCommit, isSaving, isSubmitting, sectionTitle, sectionStatus, commitTitle, commitNote, onCommitTitleChange, onCommitNoteChange, commitCount, hasHeadCommit, headCommitId, latestCommitLabel, commits, changesCount, undoStack, createdEntities, createdGeometries, width = 280, }: Props) { const toggleMode = (newMode: EditorMode) => { if (mode === newMode) { setMode("idle"); } else { setMode(newMode); } }; const recentUndoLabels = (() => { const seen = new Set(); const labels: string[] = []; for (let i = undoStack.length - 1; i >= 0 && labels.length < 8; i -= 1) { const label = formatUndoLabel(undoStack[i]); if (seen.has(label)) continue; seen.add(label); labels.push(label); } return labels.reverse(); })(); const formatCommitTitle = (commit: Props["commits"][number]) => commit.edit_summary?.trim() || `Commit ${commit.id.slice(0, 8)}`; const modeButtonStyle = (btnMode: EditorMode) => ({ padding: "8px 10px", borderRadius: 6, border: "1px solid #334155", background: mode === btnMode ? "#16a34a" : "#111827", color: "white", cursor: "pointer", fontWeight: 800, fontSize: 12, minHeight: 34, boxSizing: "border-box", }) as const; const primaryButtonStyle = ({ width: "100%", padding: "8px 10px", borderRadius: 6, border: "none", cursor: "pointer", fontWeight: 850, fontSize: 12, }) as const; return (
Editor
{sectionTitle}
Status: {sectionStatus}
Commits: {commitCount}
{latestCommitLabel ? ( {latestCommitLabel} ) : ( Chưa có head commit )}
Mode: {mode}
{entityStatus ? (
{entityStatus}
) : null}
onCommitTitleChange(event.target.value)} placeholder="Commit title" disabled={isSaving || isSubmitting} style={textInputStyle} />