'use strict';

var slicedToArray = require('./slicedToArray-067dd3bc.js');
var React = require('react');
var Router = require('next/router');
var Container = require('react-bootstrap/Container');
var ADGutter = require('./ADGutter.js');
var AD728x90 = require('./AD728x90.js');
var Header = require('./Header.js');
var Column1 = require('./Column1.js');
var Column2 = require('./Column2.js');
var Column3 = require('./Column3.js');
var NavMagazine = require('./NavMagazine.js');
var NavNative = require('./NavNative.js');
var NavDvm = require('./NavDvm.js');
var HamMagazine = require('./HamMagazine.js');
require('./_commonjsHelpers-06173234.js');
require('./web.dom.iterable-d98303e0.js');
require('./core.get-iterator-method-5643aa10.js');
require('./AdSlot.js');
require('./extends-7c86182f.js');
require('./_object-pie-083f2dd6.js');
require('prop-types');
require('./index-d2a6ef75.js');
require('./events-1b438fe7.js');
require('./debounce-d4a2369b.js');
require('./isSymbol-03abbdf0.js');
require('./toNumber-5e1fac58.js');
require('./Beam.js');
require('./stringify-f7a37a8d.js');
require('./asyncToGenerator-77821af0.js');
require('./_library-dd23b178.js');
require('./_iter-detect-b1df62f0.js');
require('./Segment.js');
require('./main-6054981e.js');
require('next/head');
require('react-bootstrap/Row');
require('react-bootstrap/Col');
require('./SideFooter.js');
require('./react-social-icons-2c5c389a.js');
require('./get-5839e5b5.js');
require('./eq-5fc26c07.js');
require('./checkSisterSite-b29833b2.js');
require('./ConferenceBanner-213003ce.js');
require('./ADSponsoredResources.js');
require('./LeftNav.js');
require('react-bootstrap/ListGroup');
require('./ADWebcast.js');
require('./PageFilter.js');
require('react-bootstrap');
require('react-bootstrap/Nav');
require('react-bootstrap/Navbar');
require('react-bootstrap/NavDropdown');
require('./index.esm-c1e16606.js');
require('./iconBase-be4097c0.js');
require('./index.esm-d81454e7.js');
require('./NavFooter-880e9d87.js');
require('./index.esm-f59ef5b4.js');
require('./SocialSearchComponent-ca9c0c45.js');
require('./SocialIcons.js');
require('react-bootstrap/Form');
require('react-bootstrap/FormControl');
require('react-bootstrap/Button');
require('./Search.js');

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

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
var Container__default = /*#__PURE__*/_interopDefaultLegacy(Container);

// Main
var TemplateNormal = function TemplateNormal(props) {
  var config = props.config,
      title = props.title,
      keywords = props.keywords,
      description = props.description,
      website = props.website,
      horizontalAD = props.config.horizontalAD,
      showFilter = props.showFilter,
      filterParams = props.filterParams,
      filters = props.filters,
      defaultFilter = props.defaultFilter,
      showRightAd = props.showRightAd,
      sponsoredFlag = props.sponsoredFlag,
      _props$noTitle = props.noTitle,
      noTitle = _props$noTitle === undefined ? false : _props$noTitle;

  var router = Router.useRouter();

  var _useState = React.useState(0),
      _useState2 = slicedToArray._slicedToArray(_useState, 2),
      currentPage = _useState2[0],
      setCurrentPage = _useState2[1];

  React.useEffect(function () {
    router.asPath && router.asPath.split('?').forEach(function (item) {
      if (item.includes('page=')) {
        setCurrentPage(item.split('=')[1]);
      } else {
        setCurrentPage(0);
      }
    });
  }, [router]);
  var navigation = function navigation() {
    switch (config.navComponent) {
      case 'magazine':
        return React__default["default"].createElement(NavMagazine["default"], { logo: website.logo, mobileLogo: website.mobileLogo, dataObject: config.navItems, subNav: config.leftItems, website: website });
      case 'native':
        return React__default["default"].createElement(NavNative.NavNative, { logo: website.logo, dataObject: config.navItems, subNav: config.leftItems, website: website });
      case 'dvm':
        return React__default["default"].createElement(NavDvm.NavDvm, { logo: website.logo, dataObject: config.navItems, mobileLogo: website.logo, subNav: config.leftItems, website: website });
      case 'hamburgerNav':
        return React__default["default"].createElement(HamMagazine.HamMagazine, {
          socialFooterNav: true,
          logo: website.logo,
          dataObject: config.navItems,
          mobileLogo: website.logo,
          subNav: config.leftItems,
          website: website.siteSettingCache,
          showLogin: website.showLogin
        });
      default:
        return React__default["default"].createElement('noNav', null);
    }
  };

  var adTargeting = { desktop: {}, mobile: {} };
  if (horizontalAD.targeting) {
    adTargeting = horizontalAD.targeting;
  }
  if (website.sponsoredAd) {
    website.sponsoredAd['targeting'] = adTargeting;
  }
  if (website.gutterAd) {
    website.gutterAd['targeting'] = adTargeting;
  }
  function layout() {
    switch (config.columns) {
      case '1':
        return React__default["default"].createElement(
          Column1.Column1,
          { title: title },
          props.children
        );
      case '2':
        return React__default["default"].createElement(
          Column2.Column2,
          { title: title, rightItems: config.rightItems, website: website },
          props.children
        );
      case '3':
        return React__default["default"].createElement(
          Column3.Column3,
          {
            title: title,
            leftItems: config.leftItems,
            rightItems: config.rightItems,
            website: website,
            showFilter: showFilter,
            getParams: filterParams,
            filters: filters,
            defaultFilter: defaultFilter,
            showRightAd: showRightAd,
            logo: website.brandLogo },
          props.children
        );
      default:
        return React__default["default"].createElement('noLayout', null);
    }
  }

  return React__default["default"].createElement(
    'section',
    null,
    noTitle ? React__default["default"].createElement(Header["default"], {
      isLiveSite: config.isLiveSite,
      keyword: keywords,
      description: description + ('' + (router && router.query && router.query.page ? '| Page ' + router.query.page : ''))
    }) : React__default["default"].createElement(Header["default"], {
      title: title ? title + ' ' + (currentPage !== 0 ? '| Page ' + currentPage + ' ' : router && router.query && router.query.page ? '| Page ' + router.query.page + ' ' : '') + '| ' + website.title : website.title + ' ' + (currentPage !== 0 ? '| Page ' + currentPage + ' ' : router && router.query && router.query.page ? '| Page ' + router.query.page + ' ' : ''),
      isLiveSite: config.isLiveSite,
      keyword: keywords,
      description: description + ('' + (router && router.query && router.query.page ? '| Page ' + router.query.page : ''))
    }),
    navigation(),
    sponsoredFlag ? React__default["default"].createElement('div', { style: { height: '50px' } }) : React__default["default"].createElement(
      React__default["default"].Fragment,
      null,
      horizontalAD && horizontalAD.networkID && horizontalAD.adUnit && React__default["default"].createElement(
        Container__default["default"],
        null,
        React__default["default"].createElement(AD728x90, { networkID: horizontalAD.networkID, adUnit: horizontalAD.adUnit, targeting: adTargeting })
      )
    ),
    website.gutterAd && !sponsoredFlag && React__default["default"].createElement(ADGutter, { title: 'gutter-ad', gutterAd: website.gutterAd }),
    React__default["default"].createElement(
      Container__default["default"],
      null,
      layout()
    )
  );
};

module.exports = TemplateNormal;
