import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "./ui/dialog"; import { Button } from "./ui/button"; import { Badge } from "./ui/badge"; import { AlertTriangle, Check, Clock, Layers, Layout } from "lucide-react"; import type { LocalSpellbook } from "@/services/db"; import type { ParsedSpellbook } from "@/types/spell"; import { compareSpellbookVersions } from "@/lib/spellbook-manager"; import { useProfile } from "@/hooks/useProfile"; interface ConflictResolutionDialogProps { open: boolean; onOpenChange: (open: boolean) => void; localSpellbook: LocalSpellbook; networkSpellbook: ParsedSpellbook; onResolve: (choice: "local" | "network") => void; } export function ConflictResolutionDialog({ open, onOpenChange, localSpellbook, networkSpellbook, onResolve, }: ConflictResolutionDialogProps) { const comparison = compareSpellbookVersions( { createdAt: localSpellbook.createdAt, content: localSpellbook.content, eventId: localSpellbook.eventId, }, { created_at: networkSpellbook.event?.created_at || 0, content: networkSpellbook.content, id: networkSpellbook.event?.id || "", }, ); const authorProfile = useProfile(networkSpellbook.event?.pubkey); const formatDate = (timestamp: number) => { const date = new Date(timestamp); return date.toLocaleString(undefined, { month: "short", day: "numeric", year: "numeric", hour: "numeric", minute: "2-digit", }); }; const handleResolve = (choice: "local" | "network") => { onResolve(choice); onOpenChange(false); }; return ( Spellbook Conflict Detected Your local version differs from the network version. Choose which version to keep.
{/* Local Version */}

Local Version

{comparison.newerVersion === "local" && ( Newer )}
{formatDate(comparison.differences.lastModified.local)}
{comparison.differences.workspaceCount.local} workspaces
{comparison.differences.windowCount.local} windows
{localSpellbook.isPublished ? ( Published ) : ( Local Only )}
{/* Network Version */}

Network Version

{comparison.newerVersion === "network" && ( Newer )}
{formatDate(comparison.differences.lastModified.network)}
{comparison.differences.workspaceCount.network} workspaces
{comparison.differences.windowCount.network} windows
{authorProfile && (
by {authorProfile.name || "Unknown"}
)}

What happens when you choose?

  • Local: Keep your local changes and discard network version
  • Network: Replace local with network version (local changes lost)
); }