"use client"; import { useState } from "react"; import CommitTreePopup from "@/components/CommitTreePopup"; import { UndoAction } from "@/lib/useEditorState"; import type { EditorMode } from "@/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; isOpeningSection: boolean; sectionTitle: string; sectionStatus: string; selectedSectionId: string; editorUserId: string; sectionOptions: Array<{ id: string; title: string; state?: { status?: string; }; }>; newSectionTitle: string; commitTitle: string; commitNote: string; onEditorUserIdChange: (userId: string) => void; onSelectedSectionIdChange: (sectionId: string) => void; onNewSectionTitleChange: (title: string) => void; onCommitTitleChange: (title: string) => void; onCommitNoteChange: (note: string) => void; onOpenSection: () => void; onCreateSection: () => void; commitCount: number; hasHeadCommit: boolean; headCommitId: string | null; latestCommitLabel: string | null; commits: Array<{ id: string; parent_commit_id: string | null; restored_from_commit_id: string | null; commit_no: number; kind: string; created_by: string; created_at: string; title: string | null; }>; 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, isOpeningSection, sectionTitle, sectionStatus, selectedSectionId, editorUserId, sectionOptions, newSectionTitle, commitTitle, commitNote, onEditorUserIdChange, onSelectedSectionIdChange, onNewSectionTitleChange, onCommitTitleChange, onCommitNoteChange, onOpenSection, onCreateSection, commitCount, hasHeadCommit, headCommitId, latestCommitLabel, commits, changesCount, undoStack, createdEntities, createdGeometries, }: Props) { // Bật/tắt popup cây commit. const [isCommitTreeOpen, setIsCommitTreeOpen] = useState(false); const formatCommitTitle = (commit: Props["commits"][number]) => commit.title?.trim() || `Commit #${commit.commit_no}`; 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"}
Section
onEditorUserIdChange(event.target.value)} placeholder="User ID" style={{ width: "100%", marginBottom: "8px", padding: "7px", borderRadius: "4px", border: "1px solid #334155", background: "#111827", color: "white", boxSizing: "border-box", }} disabled={isOpeningSection} /> onNewSectionTitleChange(event.target.value)} placeholder="Tên section mới" style={{ width: "100%", marginTop: "10px", padding: "7px", borderRadius: "4px", border: "1px solid #334155", background: "#111827", color: "white", boxSizing: "border-box", }} disabled={isOpeningSection} />
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 || sectionStatus === "submitted"} style={{ width: "100%", marginTop: "8px", padding: "7px", borderRadius: "4px", border: "1px solid #334155", background: "#111827", color: "white", boxSizing: "border-box", }} />