import htmlparser2 from 'htmlparser2';
import processNodes from './processNodes';

/**
 * Parses a HTML string and returns a list of React components generated from it
 *
 * @param {String} html The HTML to convert into React component
 * @param {Object} options Options to pass
 * @returns {Array} List of top level React elements
 */
export default function HtmlParser(html) {
  var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
    _ref$decodeEntities = _ref.decodeEntities,
    decodeEntities = _ref$decodeEntities === void 0 ? true : _ref$decodeEntities,
    transform = _ref.transform,
    _ref$preprocessNodes = _ref.preprocessNodes,
    preprocessNodes = _ref$preprocessNodes === void 0 ? function (nodes) {
      return nodes;
    } : _ref$preprocessNodes;
  var nodes = preprocessNodes(htmlparser2.parseDOM(html, {
    decodeEntities: decodeEntities
  }));
  return processNodes(nodes, transform);
}