"use client"; import { 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; type_id?: string | null; }>; createdGeometries: Array<{ id: string | number; geometryType: string; semanticType?: string | null; entityNames: string[]; }>; }; 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, }: Props) { const formatCommitTitle = (commit: Props["commits"][number]) => commit.edit_summary?.trim() || `Commit ${commit.id.slice(0, 8)}`; const toggleMode = (newMode: EditorMode) => { if (mode === newMode) { setMode("idle"); // bấm lại → tắt } else { setMode(newMode); // chuyển mode } }; // Lấy tối đa 8 tác vụ mới nhất, bỏ trùng nhãn (cùng loại/cùng id) 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 getButtonStyle = (btnMode: EditorMode) => ({ width: "100%", padding: "8px", marginBottom: "6px", border: "none", cursor: "pointer", background: mode === btnMode ? "#4caf50" : "#222", color: "white", borderRadius: "4px", }); return (

Editor

{sectionTitle}
Status: {sectionStatus}
Commits: {commitCount}
{latestCommitLabel || "Chưa có commit"}
Project
Mode: {mode}
{mode === "add-line" ? (
Click để thêm điểm, Enter để hoàn tất, Esc để hủy.
) : null} {mode === "add-path" ? (
Click để thêm điểm, Enter để hoàn tất, Esc để hủy.
) : null} {mode === "add-circle" ? (
Giữ chuột trái kéo để mở bán kính, thả chuột để hoàn tất.
) : null} {entityStatus ? (
{entityStatus}
) : null}
onCommitTitleChange(event.target.value)} placeholder="Commit title" disabled={isSaving || isSubmitting} style={{ width: "100%", marginTop: "8px", padding: "7px", borderRadius: "4px", border: "1px solid #334155", background: "#111827", color: "white", boxSizing: "border-box", }} />