import React__default, { useRef, useEffect } from 'react';
import ListGroup from 'react-bootstrap/ListGroup';
import ADWebcast from './ADWebcast.js';
import Segment from './Segment.js';
import { c as checkSisterSite } from './checkSisterSite-a7218fda.js';
import './slicedToArray-6ebcbfea.js';
import './_commonjsHelpers-0c4b6f40.js';
import './web.dom.iterable-ab4dea5c.js';
import './core.get-iterator-method-ea258bb1.js';
import './AdSlot.js';
import './extends-6d8e3924.js';
import './_object-pie-133f504a.js';
import 'prop-types';
import './index-5cc7b406.js';
import './debounce-533d9748.js';
import './isSymbol-a7e9aafe.js';
import './toNumber-5aeba6e7.js';
import './Beam.js';
import './stringify-2b084bee.js';
import './asyncToGenerator-64822ccc.js';
import './_library-528f1934.js';
import './_set-species-2cd9340f.js';
import './_iter-detect-98db3b07.js';
import './main-754d4992.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,
          rel: checkSisterSite(subRow.url) ? '' : 'noopener noreferrer' },
        subRow.name
      );
    }

    return React__default.createElement(
      'a',
      {
        href: subRow.url || '#',
        target: subRow.blank ? '_blank' : '_self',
        needsegmentsupport: subRow.needSegmentSupport ? 'true' : '',
        rel: checkSisterSite(subRow.url) ? '' : 'noopener noreferrer' },
      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, rel: checkSisterSite(row.url) ? '' : 'noopener noreferrer' },
                '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 { LeftNav, LeftNav$1 as default };
