'use strict';

require('./_commonjsHelpers-06173234.js');
require('./_to-object-329a650b.js');
require('./es6.string.iterator-cc0bbaa4.js');
require('./_library-dd23b178.js');
require('./_iter-detect-60b2f026.js');
require('./toConsumableArray-9a3476fe.js');
require('./core.get-iterator-method-f62321d4.js');
require('./_object-pie-68c5bcbc.js');
var _extends = require('./extends-0a918631.js');
require('./web.dom.iterable-a0e279c1.js');
var React = require('react');
require('./index-e08f00ce.js');
require('prop-types');
require('react-bootstrap/Card');
require('./moment-ca3bd9fb.js');
require('next/router');
require('./isSymbol-04666465.js');
require('./debounce-529c8d06.js');
require('./toNumber-36d1e7e5.js');
require('./index.es-f3e47207.js');
require('react-dom');
require('./visibility-sensor-eb2c5b69.js');
require('./index-b5eb3ff8.js');
require('./index-9d365128.js');
require('./main-7b5e57b0.js');
require('./entities-310b46ee.js');
var slicedToArray = require('./slicedToArray-8f385299.js');
require('./stringify-7c5aff47.js');
var asyncToGenerator = require('./asyncToGenerator-140e5f89.js');
require('./Segment.js');
require('./Beam.js');
require('./AdSlot.js');
require('./ADInfeed-cc30d063.js');
require('./lodash-7fd85bcf.js');
require('./ADlgInfeed-2a757ee9.js');
require('./getContentCategory-f38a4c00.js');
require('./AuthorComponent-ac8972ce.js');
require('react-bootstrap');
require('./timeDifferenceCalc.js');
var QueueDeckExpanded = require('./QueueDeckExpanded.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);

var _this = undefined;

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

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

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

    return asyncToGenerator.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._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);
  };
}();

module.exports = PubSection;
