import { useKeyboard } from "@opentui/solid"; import { onMount, onCleanup } from "solid-js"; import type { StateConflictResolution } from "../../../src/core/types.js"; import { useKeyboardNav } from "../context/keyboard.js"; interface ConflictOverlayProps { localTimestamp: Date; remoteTimestamp: Date; onResolve: (resolution: StateConflictResolution) => void; } function formatTimestamp(date: Date): string { const y = date.getFullYear(); const mo = (date.getMonth() + 1).toString().padStart(2, "0"); const d = date.getDate().toString().padStart(2, "0"); const h = date.getHours().toString().padStart(2, "0"); const m = date.getMinutes().toString().padStart(2, "0"); return `${y}-${mo}-${d} ${h}:${m}`; } export function ConflictOverlay(props: ConflictOverlayProps) { const { setOverlayActive } = useKeyboardNav(); onMount(() => setOverlayActive(true)); onCleanup(() => setOverlayActive(false)); useKeyboard((event) => { event.preventDefault(); const key = event.name.toLowerCase(); if (key === "l") { props.onResolve("local"); } else if (key === "s") { props.onResolve("server"); } else if (key === "y") { props.onResolve("yolo"); } }); return ( State Conflict Detected Both local and server state exist. {` Local: ${formatTimestamp(props.localTimestamp)}`} {` Server: ${formatTimestamp(props.remoteTimestamp)}`} [L] Keep Local [S] Use Server [Y] Yolo Merge Yolo Merge combines both — safe for most cases ); }