import React from "react";
import ConnectedDraggable from "./connected-draggable";
import useRequiredContext from "../use-required-context";
import DroppableContext from "../context/droppable-context"; // We can use this to render a draggable with more control

/* eslint-disable no-func-assign */
function _extends() {
  return (
    (_extends = Object.assign
      ? Object.assign.bind()
      : function (n) {
          for (var e = 1; e < arguments.length; e++) {
            var t = arguments[e];
            for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
          }
          return n;
        }),
    _extends.apply(null, arguments)
  );
}

// We can use this to render a draggable with more control
// It is used by a Droppable to render a clone
export function PrivateDraggable(props) {
  const droppableContext = useRequiredContext(DroppableContext);
  // The droppable can render a clone of the draggable item.
  // In that case we unmount the existing dragging item
  const isUsingCloneFor = droppableContext.isUsingCloneFor;
  if (isUsingCloneFor === props.draggableId && !props.isClone) {
    return null;
  }
  return /*#__PURE__*/ React.createElement(ConnectedDraggable, props);
}

// What we give to consumers
export function PublicDraggable(props) {
  // default values for props
  const isEnabled = typeof props.isDragDisabled === "boolean" ? !props.isDragDisabled : true;
  const canDragInteractiveElements = Boolean(props.disableInteractiveElementBlocking);
  const shouldRespectForcePress = Boolean(props.shouldRespectForcePress);
  return /*#__PURE__*/ React.createElement(
    PrivateDraggable,
    _extends({}, props, {
      isClone: false,
      isEnabled: isEnabled,
      canDragInteractiveElements: canDragInteractiveElements,
      shouldRespectForcePress: shouldRespectForcePress
    })
  );
}
