'use strict';

var React = require('react');
var Row = require('react-bootstrap/Row');
var Col = require('react-bootstrap/Col');
var Card = require('react-bootstrap/Card');
var Badge = require('react-bootstrap/Badge');
var index = require('./index-eadd5035.js');
var index$1 = require('./index-efca863c.js');
var moment = require('./moment-aca40de1.js');
var AuthorComponent = require('./AuthorComponent-c21aac7f.js');
require('./_commonjsHelpers-06173234.js');
require('react-dom');
require('prop-types');
require('./slicedToArray-5d1bc3b3.js');
require('./web.dom.iterable-46657b5c.js');
require('./es6.string.iterator-c2573ffd.js');
require('./_to-object-6de10e57.js');
require('./core.get-iterator-method-f474eacc.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 Card__default = /*#__PURE__*/_interopDefaultLegacy(Card);
var Badge__default = /*#__PURE__*/_interopDefaultLegacy(Badge);

var urlFor = function urlFor(source, client) {
  var builder = index$1.imageUrlBuilder(client);
  return builder.image(source).auto('format');
};

var renderCardImage = function renderCardImage(props) {
  var coverImage = props.coverImage,
      imageHeight = props.imageHeight,
      imageWidth = props.imageWidth,
      client = props.client,
      Settings = props.Settings;

  if (coverImage && coverImage.asset) {
    var url = urlFor(coverImage, client);
    if (imageHeight) url = url.height(imageHeight);
    if (imageWidth) url = url.width(imageWidth);
    return url.url();
  } else {
    return Settings.logo;
  }
};

var PublicationDeckStack = function PublicationDeckStack(props) {
  var title = props.title,
      coverImage = props.coverImage,
      link = props.link,
      published = props.published,
      author = props.author,
      summary = props.summary,
      section = props.section,
      imageHeight = props.imageHeight,
      imageWidth = props.imageWidth,
      client = props.client,
      Settings = props.Settings,
      index$1 = props.index,
      source = props.source;

  return React__default['default'].createElement(
    Col__default['default'],
    { md: 12, lg: 12, key: index$1 },
    React__default['default'].createElement(
      Card__default['default'],
      { style: { boxShadow: 'none', borderBottom: '1px solid #aaa', paddingBottom: '1rem' } },
      React__default['default'].createElement(
        'div',
        { style: { display: 'flex', flex: '1 0 auto', paddingBottom: '1rem' } },
        coverImage && React__default['default'].createElement(
          'div',
          { style: { display: 'flex', flexDirection: 'column', justifyContent: 'center' } },
          React__default['default'].createElement(
            'a',
            { href: '/view/' + link },
            React__default['default'].createElement(
              index.LazyLoad,
              { height: imageHeight },
              React__default['default'].createElement(Card__default['default'].Img, {
                variant: 'right',
                src: renderCardImage({ coverImage: coverImage, imageHeight: imageHeight, imageWidth: imageWidth, client: client, Settings: Settings }),
                alt: title,
                style: { width: '170px', height: 'auto', objectFit: 'contain', padding: '0.25rem', float: 'left' }
              })
            )
          ),
          source && React__default['default'].createElement(
            'div',
            { className: 'mb-2 sanityDisplayLabel displayLabelThumb' },
            source
          )
        ),
        React__default['default'].createElement(
          Card__default['default'].Body,
          { style: { padding: '0.5rem' } },
          section ? React__default['default'].createElement(
            Badge__default['default'],
            { variant: 'success' },
            section.name
          ) : '',
          React__default['default'].createElement(
            Card__default['default'].Title,
            { style: { color: '#121212', fontSize: '1.1rem' } },
            React__default['default'].createElement(
              'a',
              { href: '/view/' + link },
              React__default['default'].createElement(
                'span',
                null,
                title
              )
            ),
            React__default['default'].createElement('br', null)
          ),
          React__default['default'].createElement(
            'div',
            { style: { float: 'left' } },
            source && !coverImage && React__default['default'].createElement(
              'div',
              { className: 'content-category-label' },
              React__default['default'].createElement(
                'div',
                { className: 'mb-1 sanityDisplayLabel displayLabelThumb' },
                source
              )
            ),
            React__default['default'].createElement(
              'p',
              { style: { color: '#484848', fontSize: '.9rem', fontWeight: '600' }, className: 'mb-0' },
              moment.moment(published).format('MMMM DD, YYYY ')
            ),
            author.length > 0 && React__default['default'].createElement(
              index.LazyLoad,
              { height: 50 },
              React__default['default'].createElement(AuthorComponent.AuthorComponent, { key: index$1.toString(), index: index$1, authors: author })
            )
          )
        )
      ),
      React__default['default'].createElement(
        'p',
        { style: { paddingLeft: '0.5rem' } },
        summary
      )
    )
  );
};

var PublicationDeckBlock = function PublicationDeckBlock(props) {
  var title = props.title,
      coverImage = props.coverImage,
      link = props.link,
      section = props.section,
      imageHeight = props.imageHeight,
      imageWidth = props.imageWidth,
      client = props.client,
      Settings = props.Settings,
      index$1 = props.index;

  return React__default['default'].createElement(
    Col__default['default'],
    { md: 12, lg: 6, style: { display: 'flex', flex: '1 0 auto' }, key: index$1 },
    React__default['default'].createElement(
      Card__default['default'],
      null,
      React__default['default'].createElement(
        'a',
        { href: '/view/' + link },
        coverImage && React__default['default'].createElement(
          index.LazyLoad,
          { height: imageHeight },
          React__default['default'].createElement(Card__default['default'].Img, { variant: 'top', src: renderCardImage({ coverImage: coverImage, imageHeight: imageHeight, imageWidth: imageWidth, client: client, Settings: Settings }), alt: title })
        ),
        React__default['default'].createElement(
          Card__default['default'].Body,
          null,
          section && section.name ? React__default['default'].createElement(
            Badge__default['default'],
            { variant: 'success' },
            section && section.name
          ) : '',
          React__default['default'].createElement(
            Card__default['default'].Title,
            null,
            title
          )
        )
      )
    )
  );
};

var IssueContentDeck = function IssueContentDeck(props) {
  var data = props.data,
      imageHeight = props.imageHeight,
      imageWidth = props.imageWidth,
      website = props.website,
      client = props.client,
      _props$variant = props.variant,
      variant = _props$variant === undefined ? 'block' : _props$variant;

  return React__default['default'].createElement(
    Row__default['default'],
    null,
    data && data.length ? data.map(function (row, index) {
      if (variant === 'stack') {
        return row.url && row.url.current && React__default['default'].createElement(PublicationDeckStack, {
          index: index,
          title: row.title,
          coverImage: row.thumbnail,
          link: row.url.current,
          section: row.issueSection,
          Settings: website,
          imageHeight: imageHeight,
          imageWidth: imageWidth,
          client: client,
          source: row.source,
          published: row.published,
          author: row.authorMapping && row.authorMapping.length > 0 ? row.authorMapping : [],
          summary: row.summary
        });
      }
      return React__default['default'].createElement(PublicationDeckBlock, {
        index: index,
        title: row.title,
        coverImage: row.thumbnail,
        link: row.url.current,
        section: row.issueSection,
        Settings: website,
        imageHeight: imageHeight,
        imageWidth: imageWidth,
        client: client
      });
    }) : 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.'
        )
      )
    ),
    React__default['default'].createElement(
      'style',
      { jsx: 'true' },
      '\n          .displayLabelThumb {\n            margin: 0 auto;\n            margin-top: -1.25rem;\n            background-color: white;\n            position: relative;\n          }\n          .content-category-label {\n            margin: 0.5rem 0;\n            display: block;\n          }\n          .sanityDisplayLabel {\n            margin: 0.5rem 0;\n            border: 1px solid black;\n            width: 100%;\n            display: inline;\n            max-width: 240px;\n            padding: 5px;\n            color: #484848;\n            border-radius: 2px;\n          }\n        '
    )
  );
};

module.exports = IssueContentDeck;
