import './_commonjsHelpers-0c4b6f40.js';
import './core.get-iterator-method-86d4db69.js';
import './_library-528f1934.js';
import './_iter-detect-130ee549.js';
import './toConsumableArray-32282905.js';
import './_object-pie-33c40e79.js';
import { _ as _extends } from './extends-a4230287.js';
import './_object-sap-8b8ea5a9.js';
import './inherits-91a2c374.js';
import './define-property-6d26cb48.js';
import './web.dom.iterable-f8f967cd.js';
import './typeof-f1b7564e.js';
import './_is-array-4df618a6.js';
import React from 'react';
import './index-1819118a.js';
import 'prop-types';
import 'react-bootstrap/Row';
import 'react-bootstrap/Col';
import 'react-bootstrap/Card';
import { m as moment } from './moment-b6f49411.js';
import 'next/router';
import './isSymbol-1981418f.js';
import './debounce-9207d8ee.js';
import './toNumber-2f7a84cd.js';
import './index.es-c6222053.js';
import 'react-dom';
import './visibility-sensor-f40c2564.js';
import { _ as _slicedToArray } from './slicedToArray-67a08c9c.js';
import './index-51a80699.js';
import urlFor from './urlFor.js';
import './index-6c12bdd5.js';
import './main-43ca42fe.js';
import './entities-7cc3bf45.js';
import './stringify-70b72959.js';
import { a as _asyncToGenerator, r as regenerator, _ as _Promise } from './asyncToGenerator-7bf8bc4d.js';
import './Segment.js';
import './Beam.js';
import './AdSlot.js';
import './ADInfeed-6c0ed45b.js';
import './lodash-ec8c6b48.js';
import './ADlgInfeed-e9e1808e.js';
import './getContentCategory-15dcc413.js';
import './AuthorComponent-37ebc2bd.js';
import 'react-bootstrap/Button';
import { B as BlockContent } from './BlockContent-d05b5b23.js';
import { r as reactSocialIcons_1 } from './react-social-icons-3822f1ce.js';
import './index-c7e2ac95.js';
import './smoothscroll-0cd4c7a6.js';
import './GroupDeck.js';
import 'react-bootstrap';
import './timeDifferenceCalc.js';
import QueueDeckExpanded from './QueueDeckExpanded.js';
import './iconBase-602d52fe.js';
import './index.esm-55f22b35.js';
import { g as getSerializers } from './index-5f19922f.js';
import './util-7700fc59.js';
import './brightcove-react-player-loader.es-4abff0b1.js';
import 'next/head';
import 'react-share';
import './SocialShare.js';
import './_object-to-array-c54dd835.js';
import 'react-bootstrap/Pagination';
import 'react-bootstrap/Figure';
import 'react-bootstrap/OverlayTrigger';
import 'react-bootstrap/Tooltip';
import 'react-bootstrap/Popover';
import 'react-script-tag';
import 'react-bootstrap/Carousel';
import Feature from './Feature.js';
import 'react-bootstrap/Breadcrumb';
import Breadcrumbs from './Breadcrumbs.js';
import { I as ImageSlider, T as TwitterTimelineEmbed } from './ImageSlider-522a2cd0.js';
import { FacebookProvider, Page } from 'react-facebook';

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;


  var description = partnerDetails && partnerDetails.description ? partnerDetails.description.filter(function (block) {
    return block._type !== 'slideshows' ? block : null;
  }) : null;
  return React.createElement(
    React.Fragment,
    null,
    React.createElement(Breadcrumbs, null),
    React.createElement(
      'div',
      { className: 'partners-page' },
      React.createElement(
        'div',
        { className: 'my-5 partner-logo-wrap', style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center' } },
        partnerDetails.thumbnail && partnerDetails.thumbnail.link ? React.createElement(
          'a',
          { className: 'partners-logo', style: { width: '25%', minWidth: '25%' }, href: partnerDetails.thumbnail.link, target: partnerDetails.thumbnail.blank ? '_blank' : '' },
          React.createElement(
            'figure',
            { style: { width: '100%', textAlign: 'center' } },
            React.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.createElement(
              'figcaption',
              null,
              partnerDetails.thumbnail.caption
            )
          )
        ) : React.createElement(
          'figure',
          { className: 'partners-logo', style: { width: '25%', minWidth: '25%', textAlign: 'center' } },
          React.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.createElement(
            'figcaption',
            null,
            partnerDetails.thumbnail.caption
          )
        ),
        React.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.createElement(
          'div',
          { className: 'block-content-partners my-4', style: { maxWidth: '100%', paddingLeft: '2rem', flex: '1 1 auto' } },
          partnerDetails.description && React.createElement(BlockContent, _extends({ serializers: getSerializers(client), blocks: description, imageOptions: { w: 320, h: 240, fit: 'max' } }, client.config())),
          (partnerDetails.linkedin || partnerDetails.twitter && partnerDetails.facebook || !partnerDetails.twitter && partnerDetails.facebook && checkIsFacebookGroup(partnerDetails.facebook)) && React.createElement(
            'div',
            null,
            React.createElement(
              'p',
              { className: 'd-inline-block font-weight-bold' },
              'Connect with us:'
            ),
            '  ',
            partnerDetails.linkedin && React.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.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.createElement(
        'div',
        { className: 'mb-4', style: { padding: '0 15px' } },
        partnerDetails.affiliates[0].title && React.createElement(
          'h2',
          { className: 'bb-gold' },
          partnerDetails.affiliates[0].title
        ),
        React.createElement(ImageSlider, { client: client, data: partnerDetails.affiliates[0] })
      ),
      features.length > 0 && React.createElement(
        'div',
        { className: ' mb-5' },
        React.createElement(Feature, { dataset: features, client: client })
      ),
      (partnerDetails.twitter || partnerDetails.facebook && !checkIsFacebookGroup(partnerDetails.facebook)) && React.createElement(
        'div',
        { className: 'mb-5', style: { width: '100%', maxWidth: '100%', textAlign: 'center', padding: '15px', border: '2px solid #aaa', borderRadius: '15px' } },
        partnerDetails.twitter ? React.createElement(TwitterTimelineEmbed, { sourceType: 'url', url: partnerDetails.twitter, options: { height: 400 } }) : partnerDetails.facebook && React.createElement(
          FacebookProvider,
          { appId: ' ' },
          React.createElement(Page, { href: partnerDetails.facebook, tabs: 'timeline', width: '500', height: '500' })
        )
      ),
      React.createElement(
        'div',
        null,
        posts && posts.length > 0 && React.createElement(
          React.Fragment,
          null,
          React.createElement(
            'h2',
            { className: 'bb-gold mb-2' },
            'Latest from ',
            partnerDetails.name
          ),
          React.createElement('hr', null)
        ),
        React.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
        })
      )
    )
  );
};

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 today, featureQuery, partnerQuery, taxonomyQuery, _ref3, _ref4, features, partnerDetails, taxonomyDetails, articlesQuery, articles;

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

          case 8:
            _ref3 = _context.sent;
            _ref4 = _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    }';
            _context.next = 16;
            return client.fetch(articlesQuery, params);

          case 16:
            articles = _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 });

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

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

export default PartnerDetails;
