function snapshotFallback(logEntry) {
  const before = logEntry.snapshotBefore;
  const after = logEntry.snapshotAfter;
  if (before === void 0 && after === void 0) return null;
  if (before === null && after === null) return null;
  return { before: before ?? null, after: after ?? null };
}
function extractUndoPayload(logEntry) {
  if (!logEntry) return null;
  const rawPayload = logEntry.commandPayload ?? logEntry.payload;
  if (!rawPayload || typeof rawPayload !== "object" || Array.isArray(rawPayload)) {
    return snapshotFallback(logEntry);
  }
  const payload = rawPayload;
  if (payload.undo) return payload.undo;
  if (payload.value && typeof payload.value === "object" && payload.value.undo) {
    return payload.value.undo;
  }
  for (const [key, value] of Object.entries(payload)) {
    if (key === "__redoInput") continue;
    if (value && typeof value === "object" && "undo" in value) {
      const undo = value.undo;
      if (undo !== void 0) return undo ?? null;
    }
  }
  return snapshotFallback(logEntry);
}
export {
  extractUndoPayload
};
//# sourceMappingURL=undo.js.map
