import { a as _asyncToGenerator, r as regenerator } from './asyncToGenerator-7f8f9219.js';
import { _ as _slicedToArray } from './slicedToArray-be2f7a22.js';
import { _ as _extends } from './extends-60e0e1c6.js';
import React from 'react';
import QueueDeckExpanded from './QueueDeckExpanded.js';
import './_commonjsHelpers-0c4b6f40.js';
import './es6.string.iterator-bc33758b.js';
import './_to-object-b50e61c3.js';
import './web.dom.iterable-4109ff68.js';
import './_library-528f1934.js';
import './core.get-iterator-method-133dfacd.js';
import './_iter-detect-7e5e5ce2.js';
import './_object-pie-133f504a.js';
import './toConsumableArray-6d9a4616.js';
import 'react-bootstrap';
import './urlFor.js';
import './index-0dbff1d1.js';
import './index.es-c6222053.js';
import './moment-bc12cb97.js';
import './visibility-sensor-f40c2564.js';
import 'react-dom';
import './index-2446af28.js';
import './events-6c3a7a63.js';
import 'prop-types';
import 'next/router';
import './index-35bdcc81.js';
import './main-b5c5aac1.js';
import './entities-932b50cf.js';
import './ADInfeed-f20eb524.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-59c8f690.js';
import './Segment.js';
import './AuthorComponent-5ae7409f.js';
import './lodash-f97fd99a.js';
import './ADlgInfeed-c85a91b1.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.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;
