const compareSignatures = (prev, next) => {
  const prevSignature = self.__PREFRESH__.getSignature(prev) || {};
  const nextSignature = self.__PREFRESH__.getSignature(next) || {};

  if (
    prevSignature.key !== nextSignature.key ||
    self.__PREFRESH__.computeKey(prevSignature) !==
      self.__PREFRESH__.computeKey(nextSignature) ||
    nextSignature.forceReset
  ) {
    self.__PREFRESH__.replaceComponent(prev, next, true);
  } else {
    self.__PREFRESH__.replaceComponent(prev, next, false);
  }
};

const flush = () => {
  const pending = [...self.__PREFRESH__.getPendingUpdates()];
  self.__PREFRESH__.flush();

  if (pending.length > 0) {
    pending.forEach(([prev, next]) => {
      compareSignatures(prev, next);
    });
  }
};

const isComponent = exportValue => {
  if (typeof exportValue === 'function') {
    if (
      exportValue.prototype != null &&
      exportValue.prototype.isReactComponent
    ) {
      return true;
    }

    const name = exportValue.name || exportValue.displayName;
    return (
      typeof name === 'string' && name[0] && name[0] == name[0].toUpperCase()
    );
  }
  return false;
};

exports.flush=flush;
exports.isComponent=isComponent;