import { _ as _asyncToGenerator, r as regenerator, a as _Promise } from './asyncToGenerator-958ef5fc.js';
import { _ as _slicedToArray } from './slicedToArray-6ebcbfea.js';
import { _ as _extends } from './extends-6d8e3924.js';
import React__default from 'react';
import { TwitterTimelineEmbed } from 'react-twitter-embed';
import { I as ImageSlider, F as Facebook, P as Page } from './ImageSlider-f84174cb.js';
import './defineProperty-23a8f8cd.js';
import { r as reactSocialIcons_1 } from './react-social-icons-9be47857.js';
import './moment-bc12cb97.js';
import QueueDeckExpanded from './QueueDeckExpandedPaginated.js';
import Breadcrumbs from './Breadcrumbs.js';
import Feature from './Feature.js';
import urlFor from './urlFor.js';
import { g as getSerializers } from './index-995ce566.js';
import { B as BlockContent } from './BlockContent-1e73bd2c.js';
import './_commonjsHelpers-0c4b6f40.js';
import './core.get-iterator-method-ea258bb1.js';
import './web.dom.iterable-ab4dea5c.js';
import './_library-528f1934.js';
import './_iter-detect-98db3b07.js';
import './_object-pie-133f504a.js';
import 'prop-types';
import './smoothscroll-fa4e3f8c.js';
import './toConsumableArray-f7074d7c.js';
import 'react-bootstrap';
import './index-f0fc23eb.js';
import './events-6c3a7a63.js';
import 'next/router';
import './index-755f2cc2.js';
import 'react-dom';
import './lodash-f97fd99a.js';
import './main-1894c974.js';
import './entities-6d9154b4.js';
import './ADInfeed-7af1f934.js';
import 'react-bootstrap/Card';
import './AdSlot.js';
import './debounce-533d9748.js';
import './isSymbol-a7e9aafe.js';
import './toNumber-5aeba6e7.js';
import './Beam.js';
import './stringify-2b084bee.js';
import './Segment.js';
import './AuthorComponent-11adff02.js';
import './ADlgInfeed-ebcafb85.js';
import './getContentCategory-15dcc413.js';
import './timeDifferenceCalc.js';
import './Pagination-194dd03f.js';
import 'react-bootstrap/Button';
import './index.esm-1bd8a0a8.js';
import './iconBase-ccc56b97.js';
import './index-3f5c03b2.js';
import 'react-bootstrap/Breadcrumb';
import 'react-bootstrap/Carousel';
import './index-c7e2ac95.js';
import './util-8ed16d48.js';
import './urlForFile-b69adffc.js';
import './typeof-e9fc0c5d.js';
import './_is-array-8d21b9e3.js';
import './brightcove-react-player-loader.es-57a70a56.js';
import 'react-bootstrap/Modal';
import 'react-bootstrap/Form';
import './GroupDeck.js';
import './SocialShare.js';
import 'next/head';
import 'react-share';
import './_object-to-array-2300e51b.js';
import 'react-bootstrap/Pagination';
import 'react-bootstrap/Row';
import 'react-bootstrap/Col';
import './inherits-a6ba2ec4.js';
import './_object-sap-7cee6f84.js';
import './define-property-5f1bda73.js';
import './index.esm-eb1e8e80.js';
import 'react-bootstrap/Figure';
import 'react-bootstrap/OverlayTrigger';
import 'react-bootstrap/Tooltip';
import 'react-bootstrap/Popover';

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.createElement(
    React__default.Fragment,
    null,
    React__default.createElement(Breadcrumbs, null),
    React__default.createElement(
      'div',
      { className: 'partners-page' },
      React__default.createElement(
        'div',
        { className: 'my-5 partner-logo-wrap', style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center' } },
        partnerDetails.thumbnail && partnerDetails.thumbnail.link ? React__default.createElement(
          'a',
          { className: 'partners-logo', style: { width: '25%', minWidth: '25%' }, href: partnerDetails.thumbnail.link, target: partnerDetails.thumbnail.blank ? '_blank' : '' },
          React__default.createElement(
            'figure',
            { style: { width: '100%', textAlign: 'center' } },
            React__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.createElement(
              'figcaption',
              null,
              partnerDetails.thumbnail.caption
            )
          )
        ) : React__default.createElement(
          'figure',
          { className: 'partners-logo', style: { width: '25%', minWidth: '25%', textAlign: 'center' } },
          React__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.createElement(
            'figcaption',
            null,
            partnerDetails.thumbnail.caption
          )
        ),
        React__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.createElement(
          'div',
          { className: 'block-content-partners my-4', style: { maxWidth: '100%', paddingLeft: '2rem', flex: '1 1 auto' } },
          partnerDetails.description && React__default.createElement(BlockContent, _extends({ serializers: 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.createElement(
            'div',
            null,
            React__default.createElement(
              'p',
              { className: 'd-inline-block font-weight-bold' },
              'Connect with us:'
            ),
            '  ',
            partnerDetails.linkedin && React__default.createElement(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.createElement(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.createElement(
        'div',
        { className: 'mb-4', style: { padding: '0 15px' } },
        partnerDetails.affiliates[0].title && React__default.createElement(
          'h2',
          { className: 'bb-gold' },
          partnerDetails.affiliates[0].title
        ),
        React__default.createElement(ImageSlider, { client: client, data: partnerDetails.affiliates[0] })
      ),
      features.length > 0 && React__default.createElement(
        'div',
        { className: ' mb-5' },
        React__default.createElement(Feature, { dataset: features, client: client })
      ),
      (partnerDetails.twitter || partnerDetails.facebook && !checkIsFacebookGroup(partnerDetails.facebook)) && React__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.createElement(TwitterTimelineEmbed, { sourceType: 'url', url: partnerDetails.twitter, options: { height: 400 } }) : partnerDetails.facebook && React__default.createElement(
          Facebook,
          { appId: ' ' },
          React__default.createElement(Page, { href: partnerDetails.facebook, tabs: 'timeline', width: '500', height: '500' })
        )
      ),
      React__default.createElement(
        'div',
        null,
        posts && posts.length > 0 && React__default.createElement(
          React__default.Fragment,
          null,
          React__default.createElement(
            'h2',
            { className: 'bb-gold mb-2' },
            'Latest from ',
            partnerDetails.name
          ),
          React__default.createElement('hr', null)
        ),
        React__default.createElement(QueueDeckExpanded, {
          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( /*#__PURE__*/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 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        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          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 _Promise.all([client.fetch(featureQuery), client.fetch(partnerQuery), client.fetch(taxonomyQuery)]);

          case 7:
            _ref3 = _context.sent;
            _ref4 = _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 _Promise.all([client.fetch(articlesQuery, params), client.fetch(totalArticlesCountQuery)]);

          case 19:
            _ref5 = _context.sent;
            _ref6 = _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);
  };
}();

export default PartnerDetails;
