'use strict';

var asyncToGenerator = require('./asyncToGenerator-77821af0.js');
var slicedToArray = require('./slicedToArray-067dd3bc.js');
var _extends = require('./extends-7c86182f.js');
var React = require('react');
var reactTwitterEmbed = require('react-twitter-embed');
var ImageSlider = require('./ImageSlider-6c00b878.js');
require('./defineProperty-e0fb52c5.js');
var reactSocialIcons = require('./react-social-icons-af932527.js');
require('./moment-aca40de1.js');
var QueueDeckExpandedPaginated = require('./QueueDeckExpandedPaginated.js');
var Breadcrumbs = require('./Breadcrumbs.js');
var Feature = require('./Feature.js');
var urlFor = require('./urlFor.js');
var getSerializers = require('./index-eb1c583d.js');
var BlockContent = require('./BlockContent-9ebd251f.js');
require('./_commonjsHelpers-06173234.js');
require('./core.get-iterator-method-5643aa10.js');
require('./web.dom.iterable-d98303e0.js');
require('./_library-dd23b178.js');
require('./_iter-detect-b1df62f0.js');
require('./_object-pie-083f2dd6.js');
require('prop-types');
require('./smoothscroll-99df7f93.js');
require('./toConsumableArray-d7797c2b.js');
require('react-bootstrap');
require('./index-fc2f1ca2.js');
require('./events-1b438fe7.js');
require('next/router');
require('./index-eadd5035.js');
require('react-dom');
require('./lodash-f0783643.js');
require('./main-f1c77adb.js');
require('./entities-df1aed86.js');
require('./ADInfeed-81006615.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('./ADlgInfeed-0db07099.js');
require('./getContentCategory-f38a4c00.js');
require('./timeDifferenceCalc.js');
require('./Pagination-30bb1ca1.js');
require('react-bootstrap/Button');
require('./index.esm-d51c9ac6.js');
require('./iconBase-be4097c0.js');
require('./index-d48b231c.js');
require('react-bootstrap/Breadcrumb');
require('react-bootstrap/Carousel');
require('./index-187c967e.js');
require('./util-93a37fd0.js');
require('./urlForFile-29d3815a.js');
require('./typeof-567e31ff.js');
require('./_is-array-54228b29.js');
require('./brightcove-react-player-loader.es-a195642e.js');
require('react-bootstrap/Modal');
require('react-bootstrap/Form');
require('react-ga');
require('./GroupDeck.js');
require('./SocialShare.js');
require('next/head');
require('react-share');
require('./_object-to-array-ce86cae7.js');
require('react-bootstrap/Pagination');
require('react-bootstrap/Row');
require('react-bootstrap/Col');
require('./inherits-de66ea16.js');
require('./_object-sap-d1978572.js');
require('./define-property-e8404b64.js');
require('./index.esm-d81454e7.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,
      totalPostsCount = _ref.totalPostsCount,
      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,
      needLargePaginateButtons = _ref.needLargePaginateButtons;

  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', alignItems: 'center' } },
        partnerDetails.thumbnail && partnerDetails.thumbnail.link ? React__default['default'].createElement(
          'a',
          { className: 'partners-logo', style: { width: '25%', minWidth: '25%' }, href: partnerDetails.thumbnail.link, target: partnerDetails.thumbnail.blank ? '_blank' : '' },
          React__default['default'].createElement(
            'figure',
            { style: { width: '100%', 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(
          '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.twitter && partnerDetails.facebook || !partnerDetails.twitter && partnerDetails.facebook && checkIsFacebookGroup(partnerDetails.facebook)) && 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: partnerDetails.description, imageOptions: { w: 320, h: 240, fit: 'max' } }, client.config())),
          (partnerDetails.linkedin || partnerDetails.twitter && partnerDetails.facebook || !partnerDetails.twitter && partnerDetails.facebook && checkIsFacebookGroup(partnerDetails.facebook)) && 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, {
              url: '' + partnerDetails.linkedin + (partnerDetails.linkedin.slice(-1) === '/' ? '' : '/') + 'posts/?feedView=all',
              target: '_blank',
              rel: 'noopener noreferrer',
              style: { height: 30, width: 30 }
            }),
            (partnerDetails.twitter && partnerDetails.facebook || !partnerDetails.twitter && partnerDetails.facebook && checkIsFacebookGroup(partnerDetails.facebook)) && React__default['default'].createElement(reactSocialIcons.reactSocialIcons_1, { url: partnerDetails.facebook, target: '_blank', 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 ? 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, { href: partnerDetails.facebook, 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(QueueDeckExpandedPaginated, {
          client: client,
          mapping: Settings.mapping,
          dataRecord: posts,
          totalDataCount: totalPostsCount,
          query: query,
          params: params,
          currentPage: currentPage,
          seoPaginate: true,
          columns: 'rotate',
          variant: 'top',
          page: page,
          needLargePaginateButtons: needLargePaginateButtons,
          defaultImage: Settings.logo,
          showPublished: true,
          showCategory: true,
          pageview: pageview
        })
      )
    )
  );
};

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 featureQuery, partnerQuery, taxonomyQuery, _ref3, _ref4, features, partnerDetails, taxonomyDetails, articlesQueryFilters, articlesQuerySorts, articlesQueryProjection, articlesQuery, totalArticlesCountQuery, _ref5, _ref6, articles, totalArticlesCount;

    return asyncToGenerator.regenerator.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            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          "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          "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 = 7;
            return asyncToGenerator._Promise.all([client.fetch(featureQuery), client.fetch(partnerQuery), client.fetch(taxonomyQuery)]);

          case 7:
            _ref3 = _context.sent;
            _ref4 = slicedToArray._slicedToArray(_ref3, 3);
            features = _ref4[0];
            partnerDetails = _ref4[1];
            taxonomyDetails = _ref4[2];
            articlesQueryFilters = '[\n    _type == \'article\' \n    && !(_id in path("drafts.**")) \n    && defined(title) \n    && is_visible == true \n    && defined(url) \n    && published <= now()\n    && passwordLocked != true \n    && references(\'' + taxonomyDetails.id + '\')\n  ]';
            articlesQuerySorts = 'order(published desc)[$from...$to]';
            articlesQueryProjection = '{\n    title,\n    summary,\n    thumbnail{ ..., asset-> },\n    url,\n    published,\n    contentCategory->\n  }';
            articlesQuery = ['*'].concat(articlesQueryFilters).concat(articlesQuerySorts).concat(articlesQueryProjection).join('|');
            totalArticlesCountQuery = 'count(' + ['*'].concat(articlesQueryFilters).join('|') + ')';
            _context.next = 19;
            return asyncToGenerator._Promise.all([client.fetch(articlesQuery, params), client.fetch(totalArticlesCountQuery)]);

          case 19:
            _ref5 = _context.sent;
            _ref6 = slicedToArray._slicedToArray(_ref5, 2);
            articles = _ref6[0];
            totalArticlesCount = _ref6[1];


            // 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,
              totalArticlesCount: totalArticlesCount,
              taxonomyDetails: taxonomyDetails,
              partnerDetails: category ? partnerDetails.partner : partnerDetails,
              features: features,
              featureQuery: featureQuery,
              partnerQuery: partnerQuery,
              taxonomyQuery: taxonomyQuery,
              articlesQuery: articlesQuery
            });

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

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

module.exports = PartnerDetails;
