function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
import React from "react";
import SiteSearchAPIConnector from "@elastic/search-ui-site-search-connector";
import { SearchProvider as ElasticSearchProvider, WithSearch } from "@elastic/react-search-ui";
import DiscourseSearch from "./discourse";
import { getResultsByKey } from "./utils";
var apiConnector = new SiteSearchAPIConnector({
  engineKey: "BZL_aEiLAebVKkcm3eFr",
  documentType: "page"
});
var config = {
  apiConnector: apiConnector,
  initialState: {
    resultsPerPage: 100
  },
  searchQuery: {
    result_fields: {
      title: {
        snippet: {
          size: 100,
          fallback: true
        }
      },
      url: {
        raw: {}
      },
      description: {
        snippet: {
          size: 100,
          fallback: true
        }
      }
    }
  },
  alwaysSearchOnInitialLoad: false
};
var mapContextToProps = function mapContextToProps(_ref) {
  var searchTerm = _ref.searchTerm,
    setSearchTerm = _ref.setSearchTerm,
    results = _ref.results,
    reset = _ref.reset;
  return {
    searchTerm: searchTerm,
    setSearchTerm: setSearchTerm,
    results: _extends({}, getResultsByKey(results), {
      discourse: []
    }),
    reset: reset
  };
};
var SearchProvider = function SearchProvider(_ref2) {
  var children = _ref2.children;
  return /*#__PURE__*/React.createElement(ElasticSearchProvider, {
    config: config
  }, /*#__PURE__*/React.createElement(WithSearch, {
    mapContextToProps: mapContextToProps
  }, function (props) {
    return /*#__PURE__*/React.createElement(DiscourseSearch, props, children);
  }));
};
export default SearchProvider;