'use strict';

var _extends = require('./extends-be0d85bc.js');
var slicedToArray = require('./slicedToArray-067dd3bc.js');
var React = require('react');
var BlockContent = require('./BlockContent-96b44364.js');
var getSerializers = require('./index-1c8109ca.js');
var index = require('./index-4d21663c.js');
var Router = require('next/router');
var Button = require('react-bootstrap/Button');
var checkSisterSite = require('./checkSisterSite-c3a4ac98.js');
require('./_commonjsHelpers-06173234.js');
require('./core.get-iterator-method-5643aa10.js');
require('./web.dom.iterable-d98303e0.js');
require('prop-types');
require('./index-d48b231c.js');
require('react-bootstrap');
require('./urlFor.js');
require('./index-7435b964.js');
require('./index-187c967e.js');
require('./Beam.js');
require('./stringify-f7a37a8d.js');
require('./asyncToGenerator-65df6bf8.js');
require('./_library-dd23b178.js');
require('./_set-species-0c7864a2.js');
require('./_iter-detect-b1df62f0.js');
require('./Segment.js');
require('./main-812888f1.js');
require('./urlForFile-5084fc48.js');
require('./index-65621b6c.js');
require('react-dom');
require('./typeof-220bbf73.js');
require('./_is-array-54228b29.js');
require('./brightcove-react-player-loader.es-35faab67.js');
require('./_object-to-array-9337ba83.js');
require('./keys-e982b3fa.js');
require('./_object-sap-d1978572.js');
require('react-bootstrap/Modal');
require('react-bootstrap/Form');
require('react-ga');
require('./GroupDeck.js');
require('./smoothscroll-99df7f93.js');
require('./moment-f730814d.js');
require('./SocialShare.js');
require('next/head');
require('react-share');
require('./toConsumableArray-d7797c2b.js');
require('react-bootstrap/Pagination');
require('./entities-df1aed86.js');
require('./AdSlot.js');
require('./debounce-d4a2369b.js');
require('./isSymbol-03abbdf0.js');
require('./toNumber-5e1fac58.js');
require('react-bootstrap/Row');
require('react-bootstrap/Col');
require('./inherits-e47b5342.js');
require('./define-property-e8404b64.js');
require('./index.esm-d81454e7.js');
require('./iconBase-be4097c0.js');
require('react-bootstrap/Figure');
require('react-bootstrap/OverlayTrigger');
require('react-bootstrap/Tooltip');
require('react-bootstrap/Popover');

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

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
var Button__default = /*#__PURE__*/_interopDefaultLegacy(Button);

var ExternalResources = function ExternalResources(props) {
  var resources = props.resources,
      display = props.display,
      client = props.client,
      _props$cta = props.cta,
      cta = _props$cta === undefined ? 'Learn More' : _props$cta,
      _props$url = props.url,
      url = _props$url === undefined ? 'resources' : _props$url,
      _props$recentTitle = props.recentTitle,
      recentTitle = _props$recentTitle === undefined ? 'Recent' : _props$recentTitle,
      _props$archiveTitle = props.archiveTitle,
      archiveTitle = _props$archiveTitle === undefined ? 'Archive' : _props$archiveTitle,
      _props$dispalyThumb = props.dispalyThumb,
      dispalyThumb = _props$dispalyThumb === undefined ? true : _props$dispalyThumb,
      _props$dateFormat = props.dateFormat,
      dateFormat = _props$dateFormat === undefined ? 'MMMM Do YYYY, h:mm a z' : _props$dateFormat,
      _props$showToggles = props.showToggles,
      showToggles = _props$showToggles === undefined ? true : _props$showToggles;

  var _useState = React.useState(display && (display === 'recent' || display === 'archived') ? display : 'recent'),
      _useState2 = slicedToArray._slicedToArray(_useState, 2),
      active = _useState2[0],
      setActive = _useState2[1];

  var router = Router.useRouter();
  React.useEffect(function () {
    router.push(router.pathname, '/' + url + '?display=' + active, { shallow: true });
  }, [active]);
  return React__default["default"].createElement(
    'div',
    { id: 'resources' },
    showToggles && React__default["default"].createElement(
      'div',
      { id: 'toggles' },
      React__default["default"].createElement(
        'div',
        { onClick: function onClick() {
            return setActive(function () {
              return 'recent';
            });
          }, className: active === 'recent' ? 'active' : '' },
        recentTitle
      ),
      React__default["default"].createElement(
        'div',
        { onClick: function onClick() {
            return setActive(function () {
              return 'archived';
            });
          }, className: active === 'archived' ? 'active' : '' },
        archiveTitle
      )
    ),
    resources[active].length > 0 ? resources[active].map(function (r) {
      var destination = r.destination ? r.destination : '';
      return React__default["default"].createElement(
        'div',
        { key: r._id, className: 'resource' },
        dispalyThumb && React__default["default"].createElement(
          'div',
          { id: 'thumb' },
          React__default["default"].createElement(
            'a',
            _extends._extends({ href: destination, target: '_blank' }, checkSisterSite.checkSisterSite(destination) ? {} : { rel: 'noopener noreferrer' }),
            React__default["default"].createElement('img', { src: r.thumbnail })
          )
        ),
        React__default["default"].createElement(
          'div',
          { id: 'details' },
          React__default["default"].createElement(
            'a',
            _extends._extends({ href: destination, target: '_blank' }, checkSisterSite.checkSisterSite(destination) ? {} : { rel: 'noopener noreferrer' }),
            React__default["default"].createElement(
              'p',
              { id: 'title' },
              r.title
            ),
            r.intro && React__default["default"].createElement(
              'div',
              { id: 'intro' },
              React__default["default"].createElement(BlockContent.BlockContent, _extends._extends({ serializers: getSerializers.getSerializers(client), blocks: r.intro }, client.config()))
            ),
            React__default["default"].createElement(
              'div',
              { id: 'date' },
              React__default["default"].createElement(
                'p',
                { style: { fontWeight: 'bold' } },
                'Date:'
              ),
              React__default["default"].createElement(
                'p',
                null,
                index.momentTimezone.tz(r.displayDate, 'America/New_York').format(dateFormat),
                ' ',
                r.endDate && '- ' + index.momentTimezone.tz(r.endDate, 'America/New_York').format(dateFormat)
              )
            ),
            r.speakers && React__default["default"].createElement(
              'div',
              { id: 'speakers' },
              React__default["default"].createElement(
                'p',
                { style: { fontWeight: 'bold' } },
                'Speakers:'
              ),
              React__default["default"].createElement(BlockContent.BlockContent, _extends._extends({ serializers: getSerializers.getSerializers(client), blocks: r.speakers }, client.config()))
            ),
            r.location && React__default["default"].createElement(
              'div',
              { id: 'location' },
              React__default["default"].createElement(
                'p',
                { style: { fontWeight: 'bold' } },
                'Location:'
              ),
              r.location
            ),
            r.sponsor && React__default["default"].createElement(
              'div',
              { id: 'sponsor' },
              React__default["default"].createElement(
                'p',
                { style: { fontWeight: 'bold' } },
                'Sponsors:'
              ),
              r.sponsor
            )
          ),
          React__default["default"].createElement(
            Button__default["default"],
            _extends._extends({ id: 'cta', variant: 'secondary', href: destination, target: '_blank' }, checkSisterSite.checkSisterSite(destination) ? {} : { rel: 'noopener noreferrer' }),
            cta
          )
        )
      );
    }) : React__default["default"].createElement(
      'p',
      null,
      'No content available.'
    ),
    React__default["default"].createElement(
      'style',
      { jsx: true },
      '\n        .resource {\n          display: flex;\n          position: relative;\n          margin: 0 0 1rem 0;\n        }\n        .resource #thumb {\n          box-sizing: border-box;\n          padding: 0.5rem;\n          width: 25%;\n        }\n        .resource #thumb img {\n          width: 100%;\n        }\n        .resource #details {\n          box-sizing: border-box;\n          padding: 0.5rem;\n          width: 75%;\n        }\n        #resources .resource p {\n          margin: 0;\n        }\n        #toggles {\n          display: flex;\n          margin: 0 0 1rem 0;\n        }\n        #toggles > div {\n          padding: 0.5rem;\n          cursor: pointer;\n        }\n        #toggles > div:hover {\n          font-weight: bold;\n          border-bottom: 2px solid #cecece;\n        }\n        #toggles > div.active {\n          font-weight: bold;\n          border-bottom: 2px solid var(--primary);\n        }\n        .resource #title {\n          font-weight: bold;\n          font-size: 1.25rem;\n        }\n        .resource #date,\n        .resource #speakers,\n        .resource #location,\n        .resource #sponsor,\n        .resource #cta {\n          margin: 1rem 0 0 0;\n        }\n      '
    )
  );
};

module.exports = ExternalResources;
