import React from 'react';
import isReactElement from './is-react-element';
var customChecker;
/**
 *  Sets customChecker which will be used for all components.
 *
 * @param providedChecker {Function} - Checker function
 */

export function overrideComponentTypeChecker(providedChecker) {
  customChecker = providedChecker;
}
/**
 * Returns true if the provided element is a component of the provided type.
 *
 * @param reactElementType {string | JSXElementConstructor<any>} - the type of a React Element
 * @param reactElement {ReactElement} - any React Element (not a real DOM node)
 */

export function defaultChecker(reactElementType, reactElement) {
  if (process.env.NODE_ENV !== 'production') {
    // https://github.com/gaearon/react-hot-loader/blob/v3.0.0-beta.7/docs/Known%20Limitations.md#checking-element-types
    reactElementType = /*#__PURE__*/React.createElement(reactElementType).type; // eslint-disable-line no-param-reassign
  }

  return isReactElement(reactElement) && reactElement.type === reactElementType;
}
/**
 * Executes customChecker if it's set or defaultChecker.
 *
 * @param reactElementType {string | JSXElementConstructor<any>} - the type of a React Element
 * @param reactElement {ReactElement} - any React Element (not a real DOM node)
 */

export default function isComponentOfType(reactElementType, reactElement) {
  return customChecker ? customChecker(reactElementType, reactElement) : defaultChecker(reactElementType, reactElement);
}