"use client"; import { useState } from "react"; import { Button } from "@/components/ui/button"; import { SheetFooter } from "@/components/ui/sheet"; import { hiveReasonText } from "@/lib/hive/reason-text"; import { describeHiveOps } from "@/lib/hive/describe"; import type { HiveCatalog } from "@/lib/hive/types"; import { HiveSheetShell } from "./hive-sheet-shell"; import type { HiveConflict } from "./use-hive-mutation"; import { SAVE_FAILED_TEXT } from "./use-sheet-submit"; export interface HiveConflictSheetProps { conflict: HiveConflict | null; catalog: HiveCatalog; onResolve: (action: "retry" | "discard") => Promise; } /** Spec section 11: the hive changed meanwhile; the own ops are shown on the current state. */ export function HiveConflictSheet({ conflict, catalog, onResolve }: HiveConflictSheetProps) { const [busy, setBusy] = useState(false); const [error, setError] = useState(null); async function resolve(action: "retry" | "discard") { setBusy(true); setError(null); try { await onResolve(action); } catch { setError(SAVE_FAILED_TEXT); } finally { setBusy(false); } } const preview = conflict?.preview; const failedOp = conflict && preview && !preview.ok ? conflict.ops.slice(preview.opIndex, preview.opIndex + 1) : []; return ( { // Closing counts as discard, but not while a request is running. if (!open && !busy) void resolve("discard"); }} title="Die Beute wurde inzwischen geändert" description="Jemand anderes hat den Aufbau verändert. Deine Änderung wurde noch nicht gespeichert." > {conflict && preview ? (
{preview.ok ? (

Deine Änderung auf dem neuen Stand: {describeHiveOps(conflict.ops, conflict.current.state, catalog)}

) : (

Deine Änderung passt nicht mehr:{" "} {describeHiveOps(failedOp, conflict.current.state, catalog) || "Schritt " + (preview.opIndex + 1)}. {hiveReasonText(preview.reason)}

)} {error ? (

{error}

) : null}
) : null}
); }