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

export default PublicationDeck;
