import './_commonjsHelpers-0c4b6f40.js';
import './_to-object-a4107da3.js';
import './es6.string.iterator-c990c18c.js';
import './core.get-iterator-method-e1de7503.js';
import './web.dom.iterable-4439f05a.js';
import React from 'react';
import 'prop-types';
import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col';
import Card from 'react-bootstrap/Card';
import { m as moment } from './moment-b6f49411.js';
import 'react-dom';
import { i as imageUrlBuilder } from './index-51a80699.js';
import { L as LazyLoad } from './index-6c12bdd5.js';
import './slicedToArray-641f241f.js';
import { A as AuthorComponent } from './AuthorComponent-8ffd4679.js';
import Badge from 'react-bootstrap/Badge';

var urlFor = function urlFor(source, client) {
  var builder = 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 = props.index,
      source = props.source;

  return React.createElement(
    Col,
    { md: 12, lg: 12, key: index },
    React.createElement(
      Card,
      { style: { boxShadow: 'none', borderBottom: '1px solid #aaa', paddingBottom: '1rem' } },
      React.createElement(
        'div',
        { style: { display: 'flex', flex: '1 0 auto', paddingBottom: '1rem' } },
        coverImage && React.createElement(
          'div',
          { style: { display: 'flex', flexDirection: 'column', justifyContent: 'center' } },
          React.createElement(
            'a',
            { href: '/view/' + link },
            React.createElement(
              LazyLoad,
              { height: imageHeight },
              React.createElement(Card.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.createElement(
            'div',
            { className: 'mb-2 sanityDisplayLabel displayLabelThumb' },
            source
          )
        ),
        React.createElement(
          Card.Body,
          { style: { padding: '0.5rem' } },
          section ? React.createElement(
            Badge,
            { variant: 'success' },
            section.name
          ) : '',
          React.createElement(
            Card.Title,
            { style: { color: '#121212', fontSize: '1.1rem' } },
            React.createElement(
              'a',
              { href: '/view/' + link },
              React.createElement(
                'span',
                null,
                title
              )
            ),
            React.createElement('br', null)
          ),
          React.createElement(
            'div',
            { style: { float: 'left' } },
            source && !coverImage && React.createElement(
              'div',
              { className: 'content-category-label' },
              React.createElement(
                'div',
                { className: 'mb-1 sanityDisplayLabel displayLabelThumb' },
                source
              )
            ),
            React.createElement(
              'p',
              { style: { color: '#484848', fontSize: '.9rem', fontWeight: '600' }, className: 'mb-0' },
              moment(published).format('MMMM DD, YYYY ')
            ),
            author.length > 0 && React.createElement(
              LazyLoad,
              { height: 50 },
              React.createElement(AuthorComponent, { key: index.toString(), index: index, authors: author })
            )
          )
        )
      ),
      React.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 = props.index;

  return React.createElement(
    Col,
    { md: 12, lg: 6, style: { display: 'flex', flex: '1 0 auto' }, key: index },
    React.createElement(
      Card,
      null,
      React.createElement(
        'a',
        { href: '/view/' + link },
        coverImage && React.createElement(
          LazyLoad,
          { height: imageHeight },
          React.createElement(Card.Img, { variant: 'top', src: renderCardImage({ coverImage: coverImage, imageHeight: imageHeight, imageWidth: imageWidth, client: client, Settings: Settings }), alt: title })
        ),
        React.createElement(
          Card.Body,
          null,
          section && section.name ? React.createElement(
            Badge,
            { variant: 'success' },
            section && section.name
          ) : '',
          React.createElement(
            Card.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.createElement(
    Row,
    null,
    data && data.length ? data.map(function (row, index) {
      if (variant === 'stack') {
        return row.url && row.url.current && React.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.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.createElement(
      'div',
      null,
      React.createElement(
        'h5',
        null,
        React.createElement(
          'em',
          { className: 'pl-3' },
          'New content coming soon, please check back later.'
        )
      )
    ),
    React.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        '
    )
  );
};

export default IssueContentDeck;
