"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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
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: _objectSpread(_objectSpread({}, (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;