'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _extends = require('./extends-be0d85bc.js');
var React = require('react');
var ListGroup = require('react-bootstrap/ListGroup');
var ADWebcast = require('./ADWebcast.js');
var Segment = require('./Segment.js');
var checkSisterSite = require('./checkSisterSite-c3a4ac98.js');
require('./_commonjsHelpers-06173234.js');
require('./core.get-iterator-method-5643aa10.js');
require('./slicedToArray-067dd3bc.js');
require('./web.dom.iterable-d98303e0.js');
require('./AdSlot.js');
require('prop-types');
require('./index-fc2f1ca2.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-65df6bf8.js');
require('./_library-dd23b178.js');
require('./_set-species-0c7864a2.js');
require('./_iter-detect-b1df62f0.js');
require('./main-1ec1de84.js');

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

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
var ListGroup__default = /*#__PURE__*/_interopDefaultLegacy(ListGroup);

var LeftNav = function LeftNav(props) {
  var leftItems = props.leftItems,
      _props$fixedHeight = props.fixedHeight,
      fixedHeight = _props$fixedHeight === undefined ? false : _props$fixedHeight,
      _props$SeeAll = props.SeeAll,
      SeeAll = _props$SeeAll === undefined ? true : _props$SeeAll;

  var sideNavStyles = void 0;
  if (fixedHeight) {
    sideNavStyles = {
      maxHeight: '194px',
      overflowY: 'scroll',
      paddingLeft: '0'
    };
  } else {
    sideNavStyles = {
      paddingLeft: '0'
    };
  }

  var checkUrlIsExternal = function checkUrlIsExternal(url) {
    if (/(http|https?)([^\s]+)/g.test(url)) {
      return true;
    }
    return false;
  };

  var leftNavRef = React.useRef(null);
  React.useEffect(function () {
    setTimeout(function () {
      var segmentLinks = leftNavRef.current.querySelectorAll('a[data-need-segment-support="true"]');
      for (var i = 0; i < segmentLinks.length; i++) {
        var link = segmentLinks[i];
        var href = link.getAttribute('href');
        var newHref = Segment.getURL(href, { needSegmentSupport: true });
        link.setAttribute('href', newHref);
      }
    }, 1000);
  }, []);

  var renderListGroupItem = function renderListGroupItem(subRow) {
    if (checkUrlIsExternal(subRow.url)) {
      return React__default['default'].createElement(
        'a',
        _extends._extends({
          target: subRow.blank ? '_blank' : '_self'
        }, subRow.needSegmentSupport ? { 'data-need-segment-support': 'true' } : {}, {
          href: subRow.url
        }, checkSisterSite.checkSisterSite(subRow.url) ? {} : { rel: 'noopener noreferrer' }),
        subRow.name
      );
    }

    return React__default['default'].createElement(
      'a',
      _extends._extends({
        href: subRow.url || '#',
        target: subRow.blank ? '_blank' : '_self'
      }, subRow.needSegmentSupport ? { 'data-need-segment-support': 'true' } : {}, checkSisterSite.checkSisterSite(subRow.url) ? {} : { rel: 'noopener noreferrer' }),
      subRow.name
    );
  };

  return React__default['default'].createElement(
    'section',
    { ref: leftNavRef },
    leftItems && leftItems.map(function (row, index) {
      //  Showing webcast AD between spotlight and sub navigation when "webcastAD" is passed from site within "leftItems"
      //  Since Webcast Ad should be between spotlight and sub navigation it should be passed as the second element of leftItems array from site level.
      //  Webcast AD should have atleast adUnit , networkID, and "_type" as "webcastAD"
      if (row._type && row._type === 'webcastAD' && row.adUnit) {
        return React__default['default'].createElement(
          'div',
          { key: index },
          React__default['default'].createElement(ADWebcast, { webcastAd: row, refreshFlag: row.refreshFlag ? row.refreshFlag : false })
        );
      } else {
        return React__default['default'].createElement(
          'nav',
          { key: index, 'aria-label': 'Secondary' },
          React__default['default'].createElement(
            'div',
            { style: { display: 'flex', justifyContent: 'space-between', flexWrap: 'wrap' }, className: 'secondary-nav-title list-group-item active' },
            React__default['default'].createElement(
              'span',
              { className: 'mr-1', style: { display: 'inline-block', fontWeight: 'bold', fontSize: '1rem' } },
              row.name
            ),
            row.url && SeeAll && React__default['default'].createElement(
              'span',
              { style: { marginLeft: 'auto', display: 'inline-block' } },
              React__default['default'].createElement(
                'a',
                _extends._extends({ style: { color: 'white', fontSize: '.6rem' }, href: row.url }, checkSisterSite.checkSisterSite(row.url) ? {} : { rel: 'noopener noreferrer' }),
                'See All ',
                '>'
              )
            )
          ),
          React__default['default'].createElement(
            'ul',
            { style: sideNavStyles },
            row.subQuery && row.subQuery.map(function (subRow, subIndex) {
              return React__default['default'].createElement(
                ListGroup__default['default'].Item,
                { as: 'li', key: subIndex + '_2' },
                renderListGroupItem(subRow)
              );
            })
          )
        );
      }
    })
  );
};

var LeftNav$1 = React__default['default'].memo(LeftNav);

exports.LeftNav = LeftNav;
exports['default'] = LeftNav$1;
