'use strict';

var React = require('react');
var Row = require('react-bootstrap/Row');
var Col = require('react-bootstrap/Col');
var Button = require('react-bootstrap/Button');
var Card = require('react-bootstrap/Card');
var index = require('./index-eadd5035.js');
var urlFor = require('./urlFor.js');
var lodash = require('./lodash-f0783643.js');
require('./_commonjsHelpers-06173234.js');
require('react-dom');
require('prop-types');
require('./slicedToArray-067dd3bc.js');
require('./web.dom.iterable-d98303e0.js');
require('./core.get-iterator-method-5643aa10.js');
require('./extends-be0d85bc.js');
require('./index-d48b231c.js');

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

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
var Row__default = /*#__PURE__*/_interopDefaultLegacy(Row);
var Col__default = /*#__PURE__*/_interopDefaultLegacy(Col);
var Button__default = /*#__PURE__*/_interopDefaultLegacy(Button);
var Card__default = /*#__PURE__*/_interopDefaultLegacy(Card);

var PublicationDeck = function PublicationDeck(props) {
  var data = props.data,
      _props$imageHeight = props.imageHeight,
      imageHeight = _props$imageHeight === undefined ? null : _props$imageHeight,
      _props$imageWidth = props.imageWidth,
      imageWidth = _props$imageWidth === undefined ? null : _props$imageWidth,
      _props$imageFit = props.imageFit,
      imageFit = _props$imageFit === undefined ? null : _props$imageFit,
      href = props.href,
      website = props.website,
      client = props.client;

  var regPubs = data.filter(function (a) {
    return typeof a.is_legacy === 'undefined' || a.is_legacy === false;
  });
  var legacyPubs = data.filter(function (a) {
    return a.is_legacy === true;
  });

  var sortedLegacyPubs = lodash.lodash.sortBy(legacyPubs, [function (o) {
    return o.childIssue && o.childIssue.year ? o.childIssue.year : null;
  }]);

  var sortedRegPubs = lodash.lodash.sortBy(regPubs, [function (o) {
    return o.childIssue && o.childIssue.year ? o.childIssue.year : null;
  }]);

  var renderCardImage = function renderCardImage(thumbnail) {
    if (thumbnail && thumbnail.asset) {
      var url = urlFor({ client: client, source: thumbnail, imageHeight: imageHeight, imageWidth: imageWidth, imageFit: imageFit });
      return url;
    } else {
      return website.logo;
    }
  };

  if (sortedRegPubs && sortedRegPubs.length || sortedLegacyPubs && sortedLegacyPubs.length) {
    return React__default['default'].createElement(
      'div',
      { className: 'publication-wrapper', style: { paddingBottom: '150px' } },
      sortedRegPubs && sortedRegPubs.length > 0 && React__default['default'].createElement(
        Row__default['default'],
        { className: 'regular-publication-wrapper' },
        sortedRegPubs.map(function (row, index$1) {
          return row.identifier && row.identifier.current && React__default['default'].createElement(
            Col__default['default'],
            { xs: 6, sm: 6, md: 6, lg: 4, style: { display: 'flex', flex: '1 0 auto' }, key: index$1 },
            React__default['default'].createElement(
              Card__default['default'],
              { className: 'block-card', style: { width: '200px' } },
              React__default['default'].createElement(
                'a',
                { href: href + '/' + row.identifier.current },
                row.childIssue && row.childIssue.thumbnail ? React__default['default'].createElement(
                  index.LazyLoad,
                  { height: imageHeight },
                  React__default['default'].createElement(Card__default['default'].Img, { variant: 'top', src: renderCardImage(row.childIssue.thumbnail), style: { objectFit: 'contain', maxHeight: '200px', maxWidth: '200px' } })
                ) : React__default['default'].createElement('p', { className: 'placeholder-tag' }),
                React__default['default'].createElement(
                  Card__default['default'].Body,
                  { style: { paddingTop: '0', paddingBottom: '2.75rem' } },
                  React__default['default'].createElement(
                    Card__default['default'].Title,
                    null,
                    row.name
                  ),
                  React__default['default'].createElement(
                    Button__default['default'],
                    { style: { position: 'absolute', bottom: '1rem', margin: '0px', width: '78%' }, variant: 'secondary' },
                    'Browse Issues'
                  )
                )
              ),
              React__default['default'].createElement(
                'style',
                { jsx: 'true' },
                '\n                        .lazyload-placeholder {\n                          padding: 0 1.25rem 2.75rem;\n                        }\n                        .placeholder-tag {\n                          min-height: 200px;\n                        }\n                      '
              )
            )
          );
        })
      ),
      sortedLegacyPubs && sortedLegacyPubs.length > 0 && React__default['default'].createElement(
        React__default['default'].Fragment,
        null,
        React__default['default'].createElement(
          'div',
          { className: 'legacy-publication-title' },
          React__default['default'].createElement(
            'h2',
            null,
            'Legacy'
          ),
          React__default['default'].createElement('hr', null)
        ),
        React__default['default'].createElement(
          Row__default['default'],
          { className: 'legacy-publication-wrapper' },
          sortedLegacyPubs.map(function (row, index$1) {
            return row.identifier && row.identifier.current && React__default['default'].createElement(
              Col__default['default'],
              { xs: 6, sm: 6, md: 6, lg: 4, style: { display: 'flex', flex: '1 0 auto' }, key: index$1 },
              React__default['default'].createElement(
                Card__default['default'],
                { className: 'block-card', style: { width: '200px' } },
                React__default['default'].createElement(
                  'a',
                  { href: href + '/' + row.identifier.current },
                  row.childIssue && row.childIssue.thumbnail ? React__default['default'].createElement(
                    index.LazyLoad,
                    { height: imageHeight },
                    React__default['default'].createElement(Card__default['default'].Img, { variant: 'top', src: renderCardImage(row.childIssue.thumbnail), style: { objectFit: 'contain', maxHeight: '200px', maxWidth: '200px' } })
                  ) : React__default['default'].createElement('p', { className: 'placeholder-tag' }),
                  React__default['default'].createElement(
                    Card__default['default'].Body,
                    { style: { paddingTop: '0', paddingBottom: '2.75rem' } },
                    React__default['default'].createElement(
                      Card__default['default'].Title,
                      null,
                      row.name
                    ),
                    React__default['default'].createElement(
                      Button__default['default'],
                      { style: { position: 'absolute', bottom: '1rem', margin: '0px', width: '78%' }, variant: 'secondary' },
                      'Browse Issues'
                    )
                  )
                ),
                React__default['default'].createElement(
                  'style',
                  { jsx: 'true' },
                  '\n                          .lazyload-placeholder {\n                            padding: 0 1.25rem 2.75rem;\n                          }\n                          .placeholder-tag {\n                            min-height: 200px;\n                          }\n                        '
                )
              )
            );
          })
        )
      )
    );
  } else {
    return React__default['default'].createElement(
      'div',
      null,
      React__default['default'].createElement(
        'h5',
        null,
        React__default['default'].createElement(
          'em',
          { className: 'pl-3' },
          'New content coming soon, please check back later.'
        )
      )
    );
  }
};

module.exports = PublicationDeck;
