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 } from './extends-eb69e8ac.js';
import './web.dom.iterable-4439f05a.js';
import React__default from 'react';
import './index-a9e53f80.js';
import 'prop-types';
import 'react-bootstrap/Card';
import './moment-e2f9b20c.js';
import 'next/router';
import './isSymbol-807e927e.js';
import './debounce-1a993acf.js';
import './index.es-29c1cef5.js';
import 'react-dom';
import './visibility-sensor-0baa4eea.js';
import './index-73819142.js';
import './index-5f9f807a.js';
import './main-e4a934b2.js';
import './entities-7cc3bf45.js';
import { _ as _slicedToArray } from './slicedToArray-641f241f.js';
import './stringify-4330ccdc.js';
import { a as _asyncToGenerator, r as regenerator } from './asyncToGenerator-502f13b4.js';
import './_set-species-3f8319f5.js';
import './Segment.js';
import './Beam.js';
import './AdSlot.js';
import './ADInfeed-892282a8.js';
import './lodash-17fdfebb.js';
import './ADlgInfeed-4cc9ead9.js';
import './getContentCategory-15dcc413.js';
import './AuthorComponent-34b16174.js';
import 'react-bootstrap';
import './timeDifferenceCalc.js';
import QueueDeckExpanded from './QueueDeckExpanded.js';

var _this = undefined;

var PubSection = function PubSection(props) {
  var pubSection = props.pubSection,
      tocUrl = props.tocUrl;

  return React__default.createElement(
    'div',
    { id: 'pubSection' },
    pubSection.publication && pubSection.publication.name && React__default.createElement(
      'h2',
      null,
      pubSection.publication.name
    ),
    React__default.createElement(
      'p',
      null,
      React__default.createElement(
        'a',
        { id: 'back', href: tocUrl ? tocUrl : 'toc' },
        'Back to Table of Contents'
      )
    ),
    React__default.createElement(QueueDeckExpanded, _extends({ dataRecord: pubSection.articles }, props))
  );
};

PubSection.getInitialProps = function () {
  var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(ctx, client) {
    var _ctx$query, publication, issue, section, res, params, query, _ref2, _ref3, pubSection;

    return regenerator.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            _ctx$query = ctx.query, publication = _ctx$query.publication, issue = _ctx$query.issue, section = _ctx$query.section, res = ctx.res;
            params = {
              publication: publication,
              section: section
            };
            query = '*[_type == \'publicationSection\'\n    && defined(parent)\n    && parent->identifier == $publication\n    && identifier == $section] {\n      ...,\n      parent->,\n      \'articles\': *[_type == \'article\'\n      \t&& !(_id in path("drafts.**")) \n\t\t    && defined(title) \n\t\t    && defined(url) \n\t\t    && is_visible \n\t\t    && defined(published) \n        && dateTime(published) <= dateTime(now())\n        && passwordLock != true\n        && references(^._id)] {\n          ...,\n          contentCategory->,\n          authorMapping[]->,\n        },\n      \'publication\': *[_type == \'publication\'\n        && identifier.current == $publication] [0]\n    }';
            _context.next = 5;
            return client.fetch(query, params);

          case 5:
            _ref2 = _context.sent;
            _ref3 = _slicedToArray(_ref2, 1);
            pubSection = _ref3[0];

            if (pubSection) {
              _context.next = 11;
              break;
            }

            res.statusCode = 404;
            return _context.abrupt('return', { show404: true });

          case 11:
            return _context.abrupt('return', { publication: publication, issue: issue, section: section, pubSection: pubSection });

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

  return function (_x, _x2) {
    return _ref.apply(this, arguments);
  };
}();

export default PubSection;
