text: function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  
  /** @jsx h */
  import { h, render } from 'preact';
  import cx from 'classnames';
  import connectHits from '../../connectors/hits/connectHits';
  import Hits from '../../components/Hits/Hits';
  import defaultTemplates from './defaultTemplates';
  import { prepareTemplateProps, getContainerNode, createDocumentationMessageGenerator } from '../../lib/utils';
  import { component } from '../../lib/suit';
  import { withInsights, withInsightsListener } from '../../lib/insights';
  var withUsage = createDocumentationMessageGenerator({
    name: 'hits'
  });
  var suit = component('Hits');
  var HitsWithInsightsListener = withInsightsListener(Hits);
  
  var renderer = function renderer(_ref) {
    var renderState = _ref.renderState,
        cssClasses = _ref.cssClasses,
        containerNode = _ref.containerNode,
        templates = _ref.templates;
    return function (_ref2, isFirstRendering) {
      var receivedHits = _ref2.hits,
          results = _ref2.results,
          instantSearchInstance = _ref2.instantSearchInstance,
          insights = _ref2.insights,
          bindEvent = _ref2.bindEvent;
  
      if (isFirstRendering) {
        renderState.templateProps = prepareTemplateProps({
          defaultTemplates: defaultTemplates,
          templatesConfig: instantSearchInstance.templatesConfig,
          templates: templates
        });
        return;
      }
  
      render(h(HitsWithInsightsListener, {
        cssClasses: cssClasses,
        hits: receivedHits,
        results: results,
        templateProps: renderState.templateProps,
        insights: insights,
        sendEvent: function sendEvent(event) {
          instantSearchInstance.sendEventToInsights(event);
        },
        bindEvent: bindEvent
      }), containerNode);
    };
  };
  
  var hits = function hits(widgetParams) {
    var _ref3 = widgetParams || {},
        container = _ref3.container,
        escapeHTML = _ref3.escapeHTML,
        transformItems = _ref3.transformItems,
        _ref3$templates = _ref3.templates,
        templates = _ref3$templates === void 0 ? {} : _ref3$templates,
        _ref3$cssClasses = _ref3.cssClasses,
        userCssClasses = _ref3$cssClasses === void 0 ? {} : _ref3$cssClasses;
  
    if (!container) {
      throw new Error(withUsage('The `container` option is required.'));
    }
  
    var containerNode = getContainerNode(container);
    var cssClasses = {
      root: cx(suit(), userCssClasses.root),
      emptyRoot: cx(suit({
        modifierName: 'empty'
      }), userCssClasses.emptyRoot),
      list: cx(suit({
        descendantName: 'list'
      }), userCssClasses.list),
      item: cx(suit({
        descendantName: 'item'
      }), userCssClasses.item)
    };
    var specializedRenderer = renderer({
      containerNode: containerNode,
      cssClasses: cssClasses,
      renderState: {},
      templates: templates
    });
    var makeWidget = withInsights(connectHits)(specializedRenderer, function () {
      return render(null, containerNode);
    });
    return _objectSpread(_objectSpread({}, makeWidget({
      escapeHTML: escapeHTML,
      transformItems: transformItems
    })), {}, {
      $$widgetType: 'ais.hits'
    });
  };
  
  export default hits;