"use strict";

exports.__esModule = true;
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _searchUiSiteSearchConnector = _interopRequireDefault(require("@elastic/search-ui-site-search-connector"));
var _reactSearchUi = require("@elastic/react-search-ui");
var _discourse = _interopRequireDefault(require("./discourse"));
var _utils = require("./utils");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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); }
var apiConnector = new _searchUiSiteSearchConnector["default"]({
  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({}, (0, _utils.getResultsByKey)(results), {
      discourse: []
    }),
    reset: reset
  };
};
var SearchProvider = function SearchProvider(_ref2) {
  var children = _ref2.children;
  return /*#__PURE__*/_react["default"].createElement(_reactSearchUi.SearchProvider, {
    config: config
  }, /*#__PURE__*/_react["default"].createElement(_reactSearchUi.WithSearch, {
    mapContextToProps: mapContextToProps
  }, function (props) {
    return /*#__PURE__*/_react["default"].createElement(_discourse["default"], props, children);
  }));
};
var _default = exports["default"] = SearchProvider;