"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _reactRedux = require("react-redux");

var _redux = require("redux");

var _search = _interopRequireDefault(require("../components/search"));

var actions = _interopRequireWildcard(require("../actions"));

var found = _interopRequireWildcard(require("../selectors/found"));

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function mapProps(state) {
  return {
    activeItem: found.selectActiveItem(state),
    // Used for highlight in list
    base: state.base,
    components: found.selectPatterns(state).map(pattern => {
      if (pattern.href.startsWith('.')) {
        return pattern;
      }

      pattern.href = `.${pattern.href}`;
      return pattern;
    }),
    // List of components matching state.components
    docs: found.selectDocs(state).map(doc => {
      if (doc.href.startsWith('.')) {
        return doc;
      }

      doc.href = `.${doc.href}`;
      return doc;
    }),
    // List of docs matching state.search
    enabled: state.searchEnabled,
    // If search is to be displayed
    legend: found.selectLegend(state),
    shortcuts: state.shortcuts,
    // Reference to global shortcuts for help texts
    suggestion: found.selectSuggestion(state),
    // The backdrop search suggestion string
    value: state.searchValue // The synchronous search input value

  };
}

function mapDispatch(dispatch) {
  return (0, _redux.bindActionCreators)({
    onChange: e => actions.search({
      persist: false,
      perform: false,
      value: e.target.value
    }),
    onClear: () => actions.search({
      persist: true,
      perform: true,
      value: ""
    }),
    onClick: () => actions.toggleSearch({
      focus: true
    }),
    onClickOutside: () => actions.toggleSearch({
      focus: false
    }),
    onClose: () => actions.toggleSearch({
      focus: false
    }),
    onComplete: value => actions.search({
      persist: true,
      perform: true,
      value
    }),
    onFocus: () => actions.toggleSearch({
      focus: true
    }),
    onMount: () => actions.toggleSearch({
      sync: true
    }),
    onNavigate: item => {
      const pathname = `${item.contentType}/${item.id}`;
      return actions.patchLocation({
        pathname,
        query: {
          "search-enabled": false
        }
      });
    },
    onSubmit: e => {
      e.preventDefault();
      return actions.search({
        persist: true,
        perform: true,
        value: e.target.search.value
      });
    },
    onUp: () => actions.searchPreview("up"),
    onDown: () => actions.searchPreview("down"),
    onActivate: index => actions.searchPreview(index),
    onStop: e => actions.search({
      persist: true,
      perform: true,
      value: e.target.value
    })
  }, dispatch);
}

var _default = (0, _reactRedux.connect)(mapProps, mapDispatch)(_search.default);

exports.default = _default;
//# sourceMappingURL=search.js.map