import './_commonjsHelpers-0c4b6f40.js';
import './_to-object-ded78eb9.js';
import './es6.string.iterator-9b2af4a5.js';
import './_library-528f1934.js';
import './_iter-detect-59409a32.js';
import './core.get-iterator-method-54d2e411.js';
import './web.dom.iterable-8956f9a5.js';
import React__default, { useRef, useEffect } from 'react';
import './index-0e45a0b2.js';
import 'prop-types';
import './isSymbol-807e927e.js';
import './debounce-1a993acf.js';
import './main-5d1e4bd3.js';
import './stringify-008c8802.js';
import './slicedToArray-7021e5df.js';
import './asyncToGenerator-7c654f36.js';
import './_set-species-cede29f8.js';
import Segment from './Segment.js';
import './Beam.js';
import './AdSlot.js';
import ListGroup from 'react-bootstrap/ListGroup';
import ADWebcast from './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 = useRef(null);
  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 })
        );
      } 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);

export default LeftNav$1;
export { LeftNav };
