import { invariant } from "../../invariant";
import { warning } from "../../dev-warning";
import checkIsValidInnerRef from "../check-is-valid-inner-ref";
import useDevSetupWarning from "../use-dev-setup-warning";

function isBoolean(value) {
  return typeof value === "boolean";
}

function runChecks(args, checks) {
  checks.forEach((check) => check(args));
}

const shared = [
  function required({ props }) {
    invariant(props.droppableId, "A Droppable requires a droppableId prop");
    invariant(
      typeof props.droppableId === "string",
      `A Droppable requires a [string] droppableId. Provided: [${typeof props.droppableId}]`
    );
  },
  function boolean({ props }) {
    invariant(isBoolean(props.isDropDisabled), "isDropDisabled must be a boolean");
    invariant(isBoolean(props.isCombineEnabled), "isCombineEnabled must be a boolean");
    invariant(isBoolean(props.ignoreContainerClipping), "ignoreContainerClipping must be a boolean");
  },
  function ref({ getDroppableRef }) {
    checkIsValidInnerRef(getDroppableRef());
  }
];
const standard = [
  function placeholder({ props, getPlaceholderRef }) {
    if (!props.placeholder) {
      return;
    }
    const ref = getPlaceholderRef();
    if (ref) {
      return;
    }
    warning(`
      Droppable setup issue [droppableId: "${props.droppableId}"]:
      DroppableProvided > placeholder could not be found.

      Please be sure to add the {provided.placeholder} React Node as a child of your Droppable.
      More information: https://github.com/atlassian/react-beautiful-dnd/blob/master/docs/api/droppable.md
    `);
  }
];
const virtual = [
  function hasClone({ props }) {
    invariant(props.renderClone, "Must provide a clone render function (renderClone) for virtual lists");
  },
  function hasNoPlaceholder({ getPlaceholderRef }) {
    invariant(!getPlaceholderRef(), "Expected virtual list to not have a placeholder");
  }
];
export default function useValidation(args) {
  useDevSetupWarning(() => {
    // wrapping entire block for better minification
    runChecks(args, shared);
    if (args.props.mode === "standard") {
      runChecks(args, standard);
    }
    if (args.props.mode === "virtual") {
      runChecks(args, virtual);
    }
  });
}
