import React from "react";
import ErrorBoundary from "./error-boundary";
import preset from "../../screen-reader-message-preset";
import App from "./app";
import useUniqueContextId, { reset as resetContextId } from "./use-unique-context-id";
import { reset as resetUniqueIds } from "../use-unique-id";

// Reset any context that gets persisted across server side renders
export function resetServerContext() {
  resetContextId();
  resetUniqueIds();
}

export default function DragDropContext(props) {
  const contextId = useUniqueContextId();
  const dragHandleUsageInstructions = props.dragHandleUsageInstructions || preset.dragHandleUsageInstructions;

  // We need the error boundary to be on the outside of App
  // so that it can catch any errors caused by App
  return /*#__PURE__*/ React.createElement(ErrorBoundary, null, (setCallbacks) =>
    /*#__PURE__*/ React.createElement(
      App,
      {
        nonce: props.nonce,
        contextId: contextId,
        setCallbacks: setCallbacks,
        dragHandleUsageInstructions: dragHandleUsageInstructions,
        enableDefaultSensors: props.enableDefaultSensors,
        sensors: props.sensors,
        onBeforeCapture: props.onBeforeCapture,
        onBeforeDragStart: props.onBeforeDragStart,
        onDragStart: props.onDragStart,
        onDragUpdate: props.onDragUpdate,
        onDragEnd: props.onDragEnd
      },
      props.children
    )
  );
}
