'use strict';

var asyncToGenerator = require('./asyncToGenerator-65df6bf8.js');
var slicedToArray = require('./slicedToArray-067dd3bc.js');
var _extends = require('./extends-be0d85bc.js');
var React = require('react');
var reactTwitterEmbed = require('react-twitter-embed');
var ImageSlider = require('./ImageSlider-294d3fc0.js');
require('./defineProperty-e0fb52c5.js');
var reactSocialIcons = require('./react-social-icons-af932527.js');
var moment = require('./moment-aca40de1.js');
var QueueDeckExpanded = require('./QueueDeckExpanded.js');
var Breadcrumbs = require('./Breadcrumbs.js');
var Feature = require('./Feature.js');
var urlFor = require('./urlFor.js');
var getSerializers = require('./index-ee8ef012.js');
var BlockContent = require('./BlockContent-9ebd251f.js');
var checkSisterSite = require('./checkSisterSite-c3a4ac98.js');
require('./_commonjsHelpers-06173234.js');
require('./core.get-iterator-method-5643aa10.js');
require('./web.dom.iterable-d98303e0.js');
require('./_library-dd23b178.js');
require('./_set-species-0c7864a2.js');
require('./_iter-detect-b1df62f0.js');
require('prop-types');
require('./smoothscroll-99df7f93.js');
require('./toConsumableArray-d7797c2b.js');
require('react-bootstrap');
require('./index.es-f3e47207.js');
require('./visibility-sensor-eb2c5b69.js');
require('react-dom');
require('./index-fc2f1ca2.js');
require('./events-1b438fe7.js');
require('next/router');
require('./index-eadd5035.js');
require('./main-1ec1de84.js');
require('./entities-df1aed86.js');
require('./ADInfeed-3a68b356.js');
require('react-bootstrap/Card');
require('./AdSlot.js');
require('./debounce-d4a2369b.js');
require('./isSymbol-03abbdf0.js');
require('./toNumber-5e1fac58.js');
require('./Beam.js');
require('./stringify-f7a37a8d.js');
require('./Segment.js');
require('./AuthorComponent-39b37d84.js');
require('./lodash-f0783643.js');
require('./ADlgInfeed-d88a0250.js');
require('./getContentCategory-f38a4c00.js');
require('./timeDifferenceCalc.js');
require('./index-d48b231c.js');
require('react-bootstrap/Breadcrumb');
require('react-bootstrap/Carousel');
require('./index-187c967e.js');
require('./urlForFile-5084fc48.js');
require('./typeof-220bbf73.js');
require('./_is-array-54228b29.js');
require('./brightcove-react-player-loader.es-a195642e.js');
require('./_object-to-array-9337ba83.js');
require('./keys-e982b3fa.js');
require('./_object-sap-d1978572.js');
require('react-bootstrap/Modal');
require('react-bootstrap/Button');
require('react-bootstrap/Form');
require('react-ga');
require('./GroupDeck.js');
require('./SocialShare.js');
require('next/head');
require('react-share');
require('react-bootstrap/Pagination');
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 _this = undefined;

var checkIsFacebookGroup = function checkIsFacebookGroup(url) {
  return (/www\.facebook\.com\/groups/.test(url)
  );
};

var PartnerDetails = function PartnerDetails(_ref) {
  var posts = _ref.posts,
      query = _ref.query,
      params = _ref.params,
      features = _ref.features,
      currentPage = _ref.currentPage,
      partnerDetails = _ref.partnerDetails,
      client = _ref.client,
      Settings = _ref.Settings,
      pageview = _ref.pageview,
      page = _ref.page,
      nextPagePostsCount = _ref.nextPagePostsCount;

  var description = partnerDetails && partnerDetails.description ? partnerDetails.description.filter(function (block) {
    return block._type !== 'slideshows' ? block : null;
  }) : null;
  return React__default['default'].createElement(
    React__default['default'].Fragment,
    null,
    React__default['default'].createElement(Breadcrumbs, null),
    React__default['default'].createElement(
      'div',
      { className: 'partners-page' },
      React__default['default'].createElement(
        'div',
        { className: 'my-5 partner-logo-wrap', style: { display: 'flex', justifyContent: 'space-between' } },
        partnerDetails.thumbnail && partnerDetails.thumbnail.link ? React__default['default'].createElement(
          'a',
          _extends._extends({
            className: 'partners-logo',
            style: { width: '25%', minWidth: '25%' },
            href: partnerDetails.thumbnail.link,
            target: partnerDetails.thumbnail.blank ? '_blank' : ''
          }, checkSisterSite.checkSisterSite(partnerDetails.thumbnail.link) ? {} : { rel: 'noopener noreferrer' }),
          React__default['default'].createElement(
            'figure',
            { style: { width: '100%', textAlign: 'center', marginTop: '2rem' } },
            React__default['default'].createElement('img', {
              alt: partnerDetails.thumbnail && partnerDetails.thumbnail.alt ? partnerDetails.thumbnail.alt : partnerDetails.name,
              style: { maxWidth: '100%' },
              src: partnerDetails.thumbnail ? urlFor({ client: client, source: partnerDetails.thumbnail.asset }) : ''
            }),
            partnerDetails.thumbnail && partnerDetails.thumbnail.caption && React__default['default'].createElement(
              'figcaption',
              null,
              partnerDetails.thumbnail.caption
            )
          )
        ) : React__default['default'].createElement(
          'figure',
          { className: 'partners-logo', style: { width: '25%', minWidth: '25%', textAlign: 'center' } },
          React__default['default'].createElement('img', {
            alt: partnerDetails.thumbnail && partnerDetails.thumbnail.alt ? partnerDetails.thumbnail.alt : partnerDetails.name,
            style: { maxWidth: '100%' },
            src: partnerDetails.thumbnail ? urlFor({ client: client, source: partnerDetails.thumbnail.asset }) : ''
          }),
          partnerDetails.thumbnail && partnerDetails.thumbnail.caption && React__default['default'].createElement(
            'figcaption',
            null,
            partnerDetails.thumbnail.caption
          )
        ),
        React__default['default'].createElement(
          'style',
          { jsx: 'true' },
          '\n            @media screen and (max-width: 768px) {\n              .partners-logo {\n                width: 100%;\n                min-width: 100%;\n              }\n              .partner-logo-wrap {\n                flex-wrap: wrap;\n              }\n              .block-content-partners {\n                padding-left: 0 !important;\n              }\n            }\n          '
        ),
        (partnerDetails.description || partnerDetails.linkedin || partnerDetails.instagram || partnerDetails.youtube && partnerDetails.youtubeIcon || partnerDetails.twitter && partnerDetails.twitterIcon || partnerDetails.facebook && !partnerDetails.twitterIcon) && React__default['default'].createElement(
          'div',
          { className: 'block-content-partners my-4', style: { maxWidth: '100%', paddingLeft: '2rem', flex: '1 1 auto' } },
          partnerDetails.description && React__default['default'].createElement(BlockContent.BlockContent, _extends._extends({ serializers: getSerializers.getSerializers(client), blocks: description, imageOptions: { w: 320, h: 240, fit: 'max' } }, client.config())),
          (partnerDetails.linkedin || partnerDetails.instagram || partnerDetails.youtube && partnerDetails.youtubeIcon || partnerDetails.twitter && partnerDetails.twitterIcon || partnerDetails.facebook && !partnerDetails.twitterIcon) && React__default['default'].createElement(
            'div',
            null,
            React__default['default'].createElement(
              'p',
              { className: 'd-inline-block font-weight-bold' },
              'Connect with us:'
            ),
            '  ',
            partnerDetails.linkedin && React__default['default'].createElement(reactSocialIcons.reactSocialIcons_1, _extends._extends({
              url: '' + partnerDetails.linkedin + (partnerDetails.linkedin.slice(-1) === '/' ? '' : '/') + 'posts/?feedView=all',
              target: '_blank'
            }, checkSisterSite.checkSisterSite('' + partnerDetails.linkedin + (partnerDetails.linkedin.slice(-1) === '/' ? '' : '/') + 'posts/?feedView=all') ? {} : { rel: 'noopener noreferrer' }, {
              style: { height: 30, width: 30 }
            })),
            partnerDetails.instagram && React__default['default'].createElement(reactSocialIcons.reactSocialIcons_1, _extends._extends({
              url: '' + partnerDetails.instagram + (partnerDetails.instagram.slice(-1) === '/' ? '' : '/'),
              target: '_blank'
            }, checkSisterSite.checkSisterSite('' + partnerDetails.instagram + (partnerDetails.instagram.slice(-1) === '/' ? '' : '/')) ? {} : { rel: 'noopener noreferrer' }, {
              style: { height: 30, width: 30, marginLeft: '0.25rem' }
            })),
            partnerDetails.youtube && partnerDetails.youtubeIcon && React__default['default'].createElement(reactSocialIcons.reactSocialIcons_1, _extends._extends({
              url: partnerDetails.youtube,
              target: '_blank'
            }, checkSisterSite.checkSisterSite(partnerDetails.youtube) ? {} : { rel: 'noopener noreferrer' }, {
              style: { height: 30, width: 30, marginLeft: '0.25rem' }
            })),
            partnerDetails.twitter && partnerDetails.twitterIcon && React__default['default'].createElement(reactSocialIcons.reactSocialIcons_1, _extends._extends({
              url: partnerDetails.twitter,
              target: '_blank'
            }, checkSisterSite.checkSisterSite(partnerDetails.twitter) ? {} : { rel: 'noopener noreferrer' }, {
              style: { height: 30, width: 30, marginLeft: '0.25rem' }
            })),
            partnerDetails.facebook && !partnerDetails.twitterIcon && React__default['default'].createElement(reactSocialIcons.reactSocialIcons_1, _extends._extends({
              url: partnerDetails.facebook,
              target: '_blank'
            }, checkSisterSite.checkSisterSite(partnerDetails.facebook) ? {} : { rel: 'noopener noreferrer' }, {
              style: { height: 30, width: 30, marginLeft: '0.25rem' }
            }))
          )
        )
      ),
      partnerDetails.affiliates && partnerDetails.affiliates[0] && partnerDetails.affiliates[0].slides && React__default['default'].createElement(
        'div',
        { className: 'mb-4', style: { padding: '0 15px' } },
        partnerDetails.affiliates[0].title && React__default['default'].createElement(
          'h2',
          { className: 'bb-gold' },
          partnerDetails.affiliates[0].title
        ),
        React__default['default'].createElement(ImageSlider.ImageSlider, { client: client, data: partnerDetails.affiliates[0] })
      ),
      features.length > 0 && React__default['default'].createElement(
        'div',
        { className: ' mb-5' },
        React__default['default'].createElement(Feature, { dataset: features, client: client })
      ),
      (partnerDetails.twitter || partnerDetails.facebook && !checkIsFacebookGroup(partnerDetails.facebook)) && React__default['default'].createElement(
        'div',
        { className: 'mb-5', style: { width: '100%', maxWidth: '100%', textAlign: 'center', padding: '15px', border: '2px solid #aaa', borderRadius: '15px' } },
        partnerDetails.twitter && !partnerDetails.twitterIcon ? React__default['default'].createElement(reactTwitterEmbed.TwitterTimelineEmbed, { sourceType: 'url', url: partnerDetails.twitter, options: { height: 400 } }) : partnerDetails.facebook && React__default['default'].createElement(
          ImageSlider.Facebook,
          { appId: ' ' },
          React__default['default'].createElement(ImageSlider.Page, _extends._extends({
            href: partnerDetails.facebook
          }, checkSisterSite.checkSisterSite(partnerDetails.facebook) ? {} : { rel: 'noopener noreferrer' }, {
            tabs: 'timeline',
            width: '500',
            height: '500'
          }))
        )
      ),
      React__default['default'].createElement(
        'div',
        null,
        posts && posts.length > 0 && React__default['default'].createElement(
          React__default['default'].Fragment,
          null,
          React__default['default'].createElement(
            'h2',
            { className: 'bb-gold mb-2' },
            'Latest from ',
            partnerDetails.name
          ),
          React__default['default'].createElement('hr', null)
        ),
        React__default['default'].createElement(QueueDeckExpanded, {
          client: client,
          mapping: Settings.mapping,
          dataRecord: posts,
          query: query,
          params: params,
          currentPage: currentPage,
          seoPaginate: true,
          columns: 'rotate',
          variant: 'top',
          page: page,
          autoScroll: true,
          defaultImage: Settings.logo,
          showPublished: true,
          showCategory: true,
          pageview: pageview,
          nextPagePostsCount: nextPagePostsCount
        })
      )
    )
  );
};

PartnerDetails.returnGetInitialProps = function () {
  var _ref2 = asyncToGenerator._asyncToGenerator( /*#__PURE__*/asyncToGenerator.regenerator.mark(function _callee(identifier, partnerPageUrl, partnerDocumentGroupID, params, currentPage, client) {
    var category = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;

    var today, featureQuery, partnerQuery, taxonomyQuery, _ref3, _ref4, features, partnerDetails, taxonomyDetails, articlesQuery, itemsPerPage, articles, nextPagePostsCount;

    return asyncToGenerator.regenerator.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            today = moment.moment().utc().format();
            featureQuery = '*[_type == \'feature\' && is_active == true && feature_url == \'/' + partnerPageUrl + '/' + (category ? category + '/' : null) + identifier + '\'] | order(_updatedAt asc)[0..5]{\n      ...,\n       \'feature_img\' : feature_img.asset->\n      }';
            partnerQuery = '*[_type == \'documentGroup\' \n      && !(_id in path("drafts.**"))\n      && references(\'' + partnerDocumentGroupID + '\')\n      && identifier.current == \'' + identifier + '\'] | order(name asc) [0] {\n        pixelTrackingCode->,\n        description,\n          name,\n          identifier,\n          thumbnail{ ..., asset-> },\n          twitter,\n          facebook,\n          linkedin,\n          instagram,\n          twitterIcon,\n          youtube,\n          youtubeIcon,\n          "affiliates": description[_type==\'slideshows\']{\n            ...,\n            slides->{...}\n          }\n      }';


            if (category) {
              // if partners page has a sub category such as onclive
              // e.g. /sap-partner/[category]/[partner]

              partnerQuery = '*[_type == \'documentGroup\' && !(_id in path("drafts.**")) && identifier.current == \'' + category + '\' && references(\'' + partnerDocumentGroupID + '\')] [0] {\n    ...,\n    \'partner\': *[_type == \'documentGroup\' && identifier.current == \'' + identifier + '\' && references(^._id)] [0] {\n      pixelTrackingCode->,\n          description,\n          name,\n          identifier,\n          thumbnail{ ..., asset-> },\n          twitter,\n          facebook,\n          linkedin,\n          instagram,\n          twitterIcon,\n          youtube,\n          youtubeIcon,\n          "affiliates": description[_type==\'slideshows\']{\n            ...,\n            slides->{...}\n          }\n    \n    }\n  }';
            }

            taxonomyQuery = '*[_type == \'documentGroup\' \n      && !(_id in path("drafts.**"))\n      && references(\'' + partnerDocumentGroupID + '\')\n      && isShow != false\n      && identifier.current == \'' + identifier + '\'] [0] {\n          \'id\': _id,\n          \'title\': name\n      }';

            if (category) {
              taxonomyQuery = '*[_type == \'documentGroup\' \n     && !(_id in path("drafts.**"))\n     && isShow != false\n     && identifier.current == \'' + identifier + '\' && references(*[_type == \'documentGroup\' && identifier.current == \'' + category + '\' && references(\'' + partnerDocumentGroupID + '\')]._id)] [0] {\n         \'id\': _id,\n         \'title\': name\n     }';
            }
            _context.next = 8;
            return asyncToGenerator._Promise.all([client.fetch(featureQuery), client.fetch(partnerQuery), client.fetch(taxonomyQuery)]);

          case 8:
            _ref3 = _context.sent;
            _ref4 = slicedToArray._slicedToArray(_ref3, 3);
            features = _ref4[0];
            partnerDetails = _ref4[1];
            taxonomyDetails = _ref4[2];
            articlesQuery = '*[_type == \'article\' && !(_id in path("drafts.**")) && defined(title) && is_visible == true && defined(url) && dateTime(published) <= dateTime(\'' + today + '\') && passwordLocked != true && references(\'' + taxonomyDetails.id + '\')] | order(published desc)[$from...$to]{\n          title,\n          summary,\n          thumbnail{ ..., asset-> },\n      url,\n      published,\n      contentCategory->,\n      \'pageNumber\': ' + currentPage + '\n    }';
            itemsPerPage = params.itemsPerPage ? params.itemsPerPage : params.from && params.to ? parseInt(params.to) - parseInt(params.from) : 10;
            _context.next = 17;
            return client.fetch(articlesQuery, params);

          case 17:
            articles = _context.sent;
            _context.next = 20;
            return client.fetch('count(' + articlesQuery + ')', _extends._extends({}, params, { from: params.to, to: params.to + itemsPerPage }));

          case 20:
            nextPagePostsCount = _context.sent;

            // need to exclude slideshows from body due to the affiliate slider
            if (partnerDetails && partnerDetails.description) {
              partnerDetails.description = partnerDetails.description.filter(function (block) {
                return block._type !== 'slideshows';
              });
            }

            return _context.abrupt('return', {
              articles: articles,
              taxonomyDetails: taxonomyDetails,
              partnerDetails: category ? partnerDetails.partner : partnerDetails,
              features: features,
              featureQuery: featureQuery,
              partnerQuery: partnerQuery,
              taxonomyQuery: taxonomyQuery,
              articlesQuery: articlesQuery,
              nextPagePostsCount: nextPagePostsCount
            });

          case 23:
          case 'end':
            return _context.stop();
        }
      }
    }, _callee, _this);
  }));

  return function (_x, _x2, _x3, _x4, _x5, _x6) {
    return _ref2.apply(this, arguments);
  };
}();

module.exports = PartnerDetails;
