import React__default from 'react';
import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col';
import Button from 'react-bootstrap/Button';
import Card from 'react-bootstrap/Card';
import { L as LazyLoad } from './index-755f2cc2.js';
import urlFor from './urlFor.js';
import { l as lodash } from './lodash-f97fd99a.js';
import './_commonjsHelpers-0c4b6f40.js';
import 'react-dom';
import 'prop-types';
import './slicedToArray-72ed566b.js';
import './web.dom.iterable-3fffc027.js';
import './core.get-iterator-method-95db387d.js';
import './extends-2f4448b8.js';
import './index-3f5c03b2.js';

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.sortBy(legacyPubs, [function (o) {
    return o.childIssue && o.childIssue.year ? o.childIssue.year : null;
  }]);

  var sortedRegPubs = 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.createElement(
      'div',
      { className: 'publication-wrapper', style: { paddingBottom: '150px' } },
      sortedRegPubs && sortedRegPubs.length > 0 && React__default.createElement(
        Row,
        { className: 'regular-publication-wrapper' },
        sortedRegPubs.map(function (row, index) {
          return row.identifier && row.identifier.current && React__default.createElement(
            Col,
            { xs: 6, sm: 6, md: 6, lg: 4, style: { display: 'flex', flex: '1 0 auto' }, key: index },
            React__default.createElement(
              Card,
              { className: 'block-card', style: { width: '200px' } },
              React__default.createElement(
                'a',
                { href: href + '/' + row.identifier.current },
                row.childIssue && row.childIssue.thumbnail ? React__default.createElement(
                  LazyLoad,
                  { height: imageHeight },
                  React__default.createElement(Card.Img, { variant: 'top', src: renderCardImage(row.childIssue.thumbnail), style: { objectFit: 'contain', maxHeight: '200px', maxWidth: '200px' } })
                ) : React__default.createElement('p', { className: 'placeholder-tag' }),
                React__default.createElement(
                  Card.Body,
                  { style: { paddingTop: '0', paddingBottom: '2.75rem' } },
                  React__default.createElement(
                    Card.Title,
                    null,
                    row.name
                  ),
                  React__default.createElement(
                    Button,
                    { style: { position: 'absolute', bottom: '1rem', margin: '0px', width: '78%' }, variant: 'secondary' },
                    'Browse Issues'
                  )
                )
              ),
              React__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.createElement(
        React__default.Fragment,
        null,
        React__default.createElement(
          'div',
          { className: 'legacy-publication-title' },
          React__default.createElement(
            'h2',
            null,
            'Legacy'
          ),
          React__default.createElement('hr', null)
        ),
        React__default.createElement(
          Row,
          { className: 'legacy-publication-wrapper' },
          sortedLegacyPubs.map(function (row, index) {
            return row.identifier && row.identifier.current && React__default.createElement(
              Col,
              { xs: 6, sm: 6, md: 6, lg: 4, style: { display: 'flex', flex: '1 0 auto' }, key: index },
              React__default.createElement(
                Card,
                { className: 'block-card', style: { width: '200px' } },
                React__default.createElement(
                  'a',
                  { href: href + '/' + row.identifier.current },
                  row.childIssue && row.childIssue.thumbnail ? React__default.createElement(
                    LazyLoad,
                    { height: imageHeight },
                    React__default.createElement(Card.Img, { variant: 'top', src: renderCardImage(row.childIssue.thumbnail), style: { objectFit: 'contain', maxHeight: '200px', maxWidth: '200px' } })
                  ) : React__default.createElement('p', { className: 'placeholder-tag' }),
                  React__default.createElement(
                    Card.Body,
                    { style: { paddingTop: '0', paddingBottom: '2.75rem' } },
                    React__default.createElement(
                      Card.Title,
                      null,
                      row.name
                    ),
                    React__default.createElement(
                      Button,
                      { style: { position: 'absolute', bottom: '1rem', margin: '0px', width: '78%' }, variant: 'secondary' },
                      'Browse Issues'
                    )
                  )
                ),
                React__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.createElement(
      'div',
      null,
      React__default.createElement(
        'h5',
        null,
        React__default.createElement(
          'em',
          { className: 'pl-3' },
          'New content coming soon, please check back later.'
        )
      )
    );
  }
};

export { PublicationDeck as default };
