import './_commonjsHelpers-0c4b6f40.js';
import './_to-object-a4107da3.js';
import './es6.string.iterator-c990c18c.js';
import './_library-528f1934.js';
import './_iter-detect-5d49a330.js';
import './toConsumableArray-43aa614d.js';
import './core.get-iterator-method-e1de7503.js';
import './_object-pie-33c40e79.js';
import { _ as _extends, a as _Object$assign } from './extends-6f2fcc99.js';
import './_object-sap-964b6feb.js';
import './inherits-75d45541.js';
import './define-property-8af5f002.js';
import './web.dom.iterable-4439f05a.js';
import './typeof-af9c50d8.js';
import './_is-array-58e95429.js';
import React from 'react';
import './index-acfb8079.js';
import 'prop-types';
import 'react-bootstrap/Row';
import 'react-bootstrap/Col';
import './moment-b6f49411.js';
import { useRouter } from 'next/router';
import './isSymbol-1981418f.js';
import './debounce-9207d8ee.js';
import './toNumber-2f7a84cd.js';
import 'react-dom';
import './index-51a80699.js';
import './index-6c12bdd5.js';
import './main-747e7d25.js';
import './entities-7cc3bf45.js';
import './slicedToArray-641f241f.js';
import './stringify-4330ccdc.js';
import { a as _asyncToGenerator, r as regenerator } from './asyncToGenerator-fc1c2e29.js';
import './Segment.js';
import './Beam.js';
import './AdSlot.js';
import { B as BlockContent } from './BlockContent-d05b5b23.js';
import './index-c7e2ac95.js';
import './smoothscroll-0cd4c7a6.js';
import './GroupDeck.js';
import 'react-bootstrap';
import './iconBase-602d52fe.js';
import './index.esm-3fdda599.js';
import { g as getSerializers } from './index-52068e2b.js';
import './util-7700fc59.js';
import './brightcove-react-player-loader.es-4abff0b1.js';
import Head from 'next/head';
import 'react-share';
import './SocialShare.js';
import './_object-to-array-7e804fce.js';
import 'react-bootstrap/Pagination';
import 'react-bootstrap/Button';
import 'react-bootstrap/Figure';

var _this = undefined;

var blocksToText = function blocksToText(blocks) {
  var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

  var defaults = { nonTextBehavior: 'remove' };
  var options = _Object$assign({}, defaults, opts);
  return blocks.map(function (block) {
    if (block._type !== 'block' || !block.children) {
      return options.nonTextBehavior === 'remove' ? '' : '[' + block._type + ' block]';
    }
    return block.children.map(function (child) {
      return child.text;
    }).join('');
  }).join('\n\n');
};

var setMetaDescription = function setMetaDescription(data, router) {
  var metaDescription = blocksToText(data);
  if (router && router.asPath) {
    var queryParms = router.asPath.split('?')[1];
    if (queryParms) {
      var pageNumber = queryParms.split('&').reduce(function (acc, item) {
        if (item.startsWith('page=')) {
          if (item.split('=')[1]) {
            acc = item.split('=')[1];
            return acc;
          }
          return acc;
        }
        return acc;
      }, '');
      if (pageNumber && pageNumber !== '') {
        metaDescription = blocksToText(data) + '| Page ' + pageNumber;
      }
    }
  }
  return React.createElement(
    Head,
    null,
    React.createElement('meta', { name: 'description', content: metaDescription, key: 'description' })
  );
};

var TaxonomyDescription = function TaxonomyDescription(_ref) {
  var data = _ref.data,
      client = _ref.client;

  var router = useRouter();
  return data && data.length > 0 && React.createElement(
    'section',
    { className: 'taxonomy-description' },
    setMetaDescription(data, router),
    React.createElement(BlockContent, _extends({ serializers: getSerializers(client), blocks: data, imageOptions: { w: 320, h: 240, fit: 'max' } }, client.config()))
  );
};

TaxonomyDescription.getDescription = function () {
  var _ref2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
    var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
    var client = arguments[1];
    var query, summary;
    return regenerator.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            query = '*[_type == \'taxonomy\' && identifier == \'' + url + '\'][0].summary';
            summary = [];
            _context.prev = 2;
            _context.next = 5;
            return client.fetch(query);

          case 5:
            summary = _context.sent;
            _context.next = 11;
            break;

          case 8:
            _context.prev = 8;
            _context.t0 = _context['catch'](2);

            console.error(_context.t0);

          case 11:
            return _context.abrupt('return', summary);

          case 12:
          case 'end':
            return _context.stop();
        }
      }
    }, _callee, _this, [[2, 8]]);
  }));

  return function () {
    return _ref2.apply(this, arguments);
  };
}();

export default TaxonomyDescription;
