import { _ as _asyncToGenerator, r as regenerator } from './asyncToGenerator-1ebeb135.js';
import { _ as _slicedToArray } from './slicedToArray-72ed566b.js';
import { _ as _extends } from './extends-2f4448b8.js';
import React__default from 'react';
import QueueDeckExpanded from './QueueDeckExpanded.js';
import './_commonjsHelpers-0c4b6f40.js';
import './core.get-iterator-method-95db387d.js';
import './web.dom.iterable-3fffc027.js';
import './_library-528f1934.js';
import './_set-species-7d3317b7.js';
import './_iter-detect-2f89237f.js';
import './toConsumableArray-e6f28e5c.js';
import 'react-bootstrap';
import './urlFor.js';
import './index-3f5c03b2.js';
import './index.es-a6137319.js';
import './moment-48faeb9c.js';
import './visibility-sensor-72fd8f8b.js';
import 'react-dom';
import './index-5cc7b406.js';
import 'prop-types';
import 'next/router';
import './index-755f2cc2.js';
import './main-dde1592e.js';
import './entities-6d9154b4.js';
import './ADInfeed-c7606b73.js';
import 'react-bootstrap/Card';
import './AdSlot.js';
import './debounce-533d9748.js';
import './isSymbol-a7e9aafe.js';
import './toNumber-5aeba6e7.js';
import './Beam.js';
import './stringify-1e2a5946.js';
import './Segment.js';
import './AuthorComponent-d9653ae5.js';
import './lodash-f97fd99a.js';
import './ADlgInfeed-1dabd239.js';
import './getContentCategory-15dcc413.js';
import './timeDifferenceCalc.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 { PubSection as default };
