import './_commonjsHelpers-0c4b6f40.js';
import './core.get-iterator-method-86d4db69.js';
import './_library-528f1934.js';
import './_iter-detect-130ee549.js';
import './toConsumableArray-32282905.js';
import './_object-pie-33c40e79.js';
import { _ as _extends } from './extends-a4230287.js';
import './web.dom.iterable-f8f967cd.js';
import React from 'react';
import './index-1819118a.js';
import 'prop-types';
import 'react-bootstrap/Card';
import './moment-b6f49411.js';
import 'next/router';
import './isSymbol-1981418f.js';
import './debounce-9207d8ee.js';
import './toNumber-2f7a84cd.js';
import './index.es-c6222053.js';
import 'react-dom';
import './visibility-sensor-f40c2564.js';
import { _ as _slicedToArray } from './slicedToArray-67a08c9c.js';
import './index-51a80699.js';
import './urlFor.js';
import './index-6c12bdd5.js';
import './main-43ca42fe.js';
import './entities-7cc3bf45.js';
import './stringify-70b72959.js';
import { a as _asyncToGenerator, r as regenerator } from './asyncToGenerator-7bf8bc4d.js';
import './Segment.js';
import './Beam.js';
import './AdSlot.js';
import './ADInfeed-6c0ed45b.js';
import './lodash-ec8c6b48.js';
import './ADlgInfeed-e9e1808e.js';
import './getContentCategory-15dcc413.js';
import './AuthorComponent-37ebc2bd.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.createElement(
    'div',
    { id: 'pubSection' },
    pubSection.publication && pubSection.publication.name && React.createElement(
      'h2',
      null,
      pubSection.publication.name
    ),
    React.createElement(
      'p',
      null,
      React.createElement(
        'a',
        { id: 'back', href: tocUrl ? tocUrl : 'toc' },
        'Back to Table of Contents'
      )
    ),
    React.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;
