'use strict';

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

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }

require('./_commonjsHelpers-06173234.js');
require('./_to-object-329a650b.js');
require('./es6.string.iterator-cc0bbaa4.js');
require('./_library-dd23b178.js');
require('./_iter-detect-60b2f026.js');
require('./core.get-iterator-method-f62321d4.js');
require('./_object-pie-68c5bcbc.js');
require('./extends-60837c34.js');
require('./web.dom.iterable-a0e279c1.js');
var React = require('react');
var React__default = _interopDefault(React);
require('./index-8bf6c863.js');
require('prop-types');
require('./isSymbol-04666465.js');
require('./debounce-eb287781.js');
require('./main-02daeefe.js');
require('./slicedToArray-8f385299.js');
require('./stringify-7c5aff47.js');
require('./asyncToGenerator-533d476a.js');
require('./_set-species-f92c67c5.js');
var Segment = require('./Segment.js');
require('./Beam.js');
require('./AdSlot.js');
var ListGroup = _interopDefault(require('react-bootstrap/ListGroup'));
var ADWebcast = require('./ADWebcast.js');

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[needsegmentsupport="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.createElement(
        'a',
        { target: subRow.blank ? '_blank' : '_self', needsegmentsupport: subRow.needSegmentSupport ? 'true' : '', href: subRow.url },
        subRow.name
      );
    }

    return React__default.createElement(
      'a',
      { href: subRow.url || '#', target: subRow.blank ? '_blank' : '_self', needsegmentsupport: subRow.needSegmentSupport ? 'true' : '' },
      subRow.name
    );
  };

  return React__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.createElement(
          'div',
          { key: index },
          React__default.createElement(ADWebcast, { webcastAd: row, refreshFlag: row.refreshFlag ? row.refreshFlag : false })
        );
      } else {
        return React__default.createElement(
          'nav',
          { key: index, 'aria-label': 'Secondary' },
          React__default.createElement(
            'div',
            { style: { display: 'flex', justifyContent: 'space-between', flexWrap: 'wrap' }, className: 'secondary-nav-title list-group-item active' },
            React__default.createElement(
              'span',
              { className: 'mr-1', style: { display: 'inline-block', fontWeight: 'bold', fontSize: '1rem' } },
              row.name
            ),
            row.url && SeeAll && React__default.createElement(
              'span',
              { style: { marginLeft: 'auto', display: 'inline-block' } },
              React__default.createElement(
                'a',
                { style: { color: 'white', fontSize: '.6rem' }, href: row.url },
                'See All ',
                '>'
              )
            )
          ),
          React__default.createElement(
            'ul',
            { style: sideNavStyles },
            row.subQuery && row.subQuery.map(function (subRow, subIndex) {
              return React__default.createElement(
                ListGroup.Item,
                { as: 'li', key: subIndex + '_2' },
                renderListGroupItem(subRow)
              );
            })
          )
        );
      }
    })
  );
};

var LeftNav$1 = React__default.memo(LeftNav);

exports.LeftNav = LeftNav;
exports.default = LeftNav$1;
