import { _ as _extends } from './extends-60e0e1c6.js';
import { _ as _typeof } from './typeof-a286cf0c.js';
import { _ as _inherits, a as _classCallCheck, b as _possibleConstructorReturn, c as _Object$getPrototypeOf, d as _createClass } from './inherits-a41fe93f.js';
import React__default from 'react';
import PropTypes from 'prop-types';
import { InstantSearch, Configure, SearchBox, RefinementList, Hits, Pagination } from 'react-instantsearch-dom';
import { DropdownButton } from 'react-bootstrap';
import { i as imageUrlBuilder } from './index-0dbff1d1.js';
import { m as moment } from './moment-bc12cb97.js';
import { L as LazyLoad } from './index-755f2cc2.js';
import './_commonjsHelpers-0c4b6f40.js';
import './_to-object-b50e61c3.js';
import './_object-pie-133f504a.js';
import './es6.string.iterator-bc33758b.js';
import './web.dom.iterable-4109ff68.js';
import './_is-array-3e99e06e.js';
import './_library-528f1934.js';
import './_object-sap-f353c2a9.js';
import './define-property-fe54dc9f.js';
import 'react-dom';

var AlgoliaSearch = function (_React$Component) {
  _inherits(AlgoliaSearch, _React$Component);

  function AlgoliaSearch() {
    _classCallCheck(this, AlgoliaSearch);

    return _possibleConstructorReturn(this, (AlgoliaSearch.__proto__ || _Object$getPrototypeOf(AlgoliaSearch)).apply(this, arguments));
  }

  _createClass(AlgoliaSearch, [{
    key: 'Deck',
    value: function Deck(props) {
      var _props$propsObj = props.propsObj,
          styles = _props$propsObj.styles,
          client = _props$propsObj.client;

      var builder = imageUrlBuilder(client);
      var hit = props.hit;
      return React__default.createElement(
        'div',
        { key: hit.url, className: styles.article },
        React__default.createElement(
          'a',
          { href: '/view/' + hit.url, style: this.props.variant === 'right' ? { flexDirection: 'row-reverse' } : {} },
          React__default.createElement(
            'div',
            { className: styles.thumb },
            React__default.createElement(
              'figure',
              null,
              React__default.createElement(
                LazyLoad,
                null,
                React__default.createElement('img', {
                  src: hit.thumbnail && hit.thumbnail.asset ? builder.image(hit.thumbnail).url() : hit.thumbnail && _typeof(hit.thumbnail === 'string') ? hit.thumbnail : this.props.defaultImage
                })
              )
            )
          ),
          React__default.createElement(
            'div',
            { className: styles.info, style: this.props.variant === 'right' ? { padding: '0 1rem 0 0' } : { padding: ' 0 0 0 1rem' } },
            React__default.createElement(
              'h2',
              null,
              hit.title
            ),
            hit.pubDateSort && React__default.createElement(
              'p',
              { className: styles.published },
              moment(hit.pubDateSort).format('MMMM Do YYYY')
            ),
            hit.authorMapping && hit.authorMapping.length > 0 && React__default.createElement(
              'p',
              { className: styles.author },
              hit.authorMapping.map(function (author) {
                return React__default.createElement(
                  'span',
                  null,
                  author.displayName
                );
              })
            ),
            hit.summary && React__default.createElement('p', { dangerouslySetInnerHTML: { __html: hit.summary }, className: styles.summary })
          )
        )
      );
    }
  }, {
    key: 'render',
    value: function render() {
      var _this2 = this;

      var propsObj = {
        styles: this.props.deckStyles,
        client: this.props.sanityClient
      };
      return React__default.createElement(
        React__default.Fragment,
        null,
        React__default.createElement(
          InstantSearch,
          _extends({
            searchClient: this.props.searchClient,
            resultsState: this.props.resultsState,
            onSearchStateChange: this.props.onSearchStateChange,
            searchState: this.props.searchState,
            createURL: this.props.createURL,
            indexName: this.props.indexName,
            onSearchParameters: this.props.onSearchParameters
          }, this.props),
          React__default.createElement(Configure, { hitsPerPage: this.props.hitsPerPage || 20 }),
          React__default.createElement(SearchBox, null),
          this.props.refinementAttributes && React__default.createElement(
            'div',
            { className: 'search_refinement' },
            this.props.refinementAttributes.map(function (item, index) {
              return React__default.createElement(
                DropdownButton,
                { title: item.title },
                React__default.createElement(RefinementList, { showMore: item.showMore, limit: item.limit, showMoreLimit: item.showMoreLimit, attribute: item.attribute })
              );
            })
          ),
          React__default.createElement(
            'div',
            { className: 'AlgoliaResults' },
            React__default.createElement(Hits, { hitComponent: function hitComponent(hit) {
                return _this2.Deck(_extends({}, hit, { propsObj: propsObj }));
              } })
          ),
          React__default.createElement(Pagination, null)
        ),
        React__default.createElement(
          'style',
          { jsx: 'true' },
          '\n          .AlgoliaResults {\n            padding-left: 15px;\n            margin-top: 3rem;\n          }\n\n          .search_refinement {\n            display: flex;\n            margin: 2rem 0;\n          }\n\n          .search_refinement > div {\n            padding-right: 1rem;\n            max-height: 500px;\n          }\n\n          .ais-Hits-list {\n            margin: 0;\n            list-style: none;\n            padding-inline-start: 0;\n          }\n          .ais-Pagination-list {\n            list-style: none;\n          }\n          .ais-Pagination-list {\n            -webkit-box-pack: center;\n            -ms-flex-pack: center;\n            justify-content: center;\n          }\n          .ais-Pagination-item + .ais-Pagination-item {\n            margin-left: 0.3rem;\n          }\n          .ais-Pagination-link {\n            padding: 0.3rem 0.6rem;\n            display: block;\n            border: 1px solid var(--search-primary);\n            border-radius: 5px;\n            transition: background-color 0.2s ease-out;\n          }\n          .ais-Pagination-link:focus,\n          .ais-Pagination-link:hover {\n            background-color: var(--search-secondary);\n            color: #fff;\n          }\n          .ais-Pagination-item--disabled .ais-Pagination-link {\n            opacity: 0.6;\n            cursor: not-allowed;\n            color: var(--search-secondary);\n          }\n          .ais-Pagination-item--disabled .ais-Pagination-link:focus,\n          .ais-Pagination-item--disabled .ais-Pagination-link:hover {\n            color: #fff;\n            background-color: var(--search-secondary);\n          }\n          .ais-Pagination-item--selected .ais-Pagination-link {\n            color: #fff;\n            background-color: var(--search-primary);\n            border-color: var(--search-primary);\n          }\n          .ais-Pagination-item--selected .ais-Pagination-link:focus,\n          .ais-Pagination-item--selected .ais-Pagination-link:hover {\n            color: #fff;\n          }\n          .ais-Pagination-list,\n          .ais-Results-list {\n            margin: 0;\n            padding: 0;\n            list-style: none;\n          }\n          .ais-Pagination-list,\n          .ais-PoweredBy,\n          .ais-RangeInput-form,\n          .ais-RatingMenu-link {\n            display: -webkit-box;\n            display: -ms-flexbox;\n            display: flex;\n            -webkit-box-align: center;\n            -ms-flex-align: center;\n            align-items: center;\n          }\n\n          .ais-RefinementList-item {\n            list-style: none;\n            margin: 0;\n            padding: 0;\n          }\n          .ais-RefinementList-list {\n            margin: 0;\n            padding: 0 1rem;\n            width: max-content;\n          }\n          .ais-SearchBox-form {\n            width: 100%;\n            border-radius: 5px;\n            height: 48px;\n          }\n          .ais-SearchBox-input {\n            padding: 0.5rem;\n            border-radius: 5px;\n            width: calc(100% - 150px);\n            height: 48px;\n            border: 0;\n            border: 0.5px solid var(--search-secondary);\n          }\n\n          .ais-SearchBox-submit {\n            width: 78px;\n            border-radius: 5px;\n            padding: 7px;\n            margin-left: 5px;\n            height: 48px;\n            background-color: var(--search-primary);\n            border: 0.5px solid var(--search-secondary);\n          }\n\n          .ais-SearchBox-submit > svg {\n            fill: #fff;\n          }\n          .search_refinement > .dropdown > button {\n            background-color: var(--search-primary);\n            border-color: var(--search-primary);\n          }\n\n          .ais-SearchBox-reset {\n            height: 48px;\n            width: 48px;\n            color: #fff;\n            background-color: var(--search-primary);\n            border: 0;\n            margin-left: 5px;\n            border-radius: 5px;\n            border: 0.5px solid var(--search-secondary);\n          }\n\n          .ais-SearchBox-reset > svg {\n            fill: #fff;\n          }\n          .ais-RefinementList-checkbox {\n            margin-right: 5px;\n          }\n\n          .ais-RefinementList-showMore {\n            padding: 0.5rem;\n            border: 0;\n            background-color: var(--search-primary);\n            border-color: var(--search-primary);\n            color: #fff;\n            border: 1px solid;\n            border-radius: 5px;\n            margin-left: 1rem;\n          }\n        '
        )
      );
    }
  }]);

  return AlgoliaSearch;
}(React__default.Component);

AlgoliaSearch.propTypes = {
  searchState: PropTypes.object,
  resultsState: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
  onSearchStateChange: PropTypes.func,
  createURL: PropTypes.func,
  indexName: PropTypes.string,
  searchClient: PropTypes.object,
  refinementAttributes: PropTypes.array
};

export default AlgoliaSearch;
