import { _ as _extends } from './extends-2f4448b8.js';
import React__default, { useRef, useEffect } from 'react';
import Container from 'react-bootstrap/Container';
import Nav from 'react-bootstrap/Nav';
import Navbar from 'react-bootstrap/Navbar';
import NavDropdown from 'react-bootstrap/NavDropdown';
import { c as checkSisterSite } from './checkSisterSite-a7218fda.js';
import Search from './Search.js';
import { N as NavFooter } from './NavFooter-4bcffccb.js';
import Segment from './Segment.js';
import './_commonjsHelpers-0c4b6f40.js';
import './core.get-iterator-method-95db387d.js';
import './slicedToArray-72ed566b.js';
import './web.dom.iterable-3fffc027.js';
import 'react-bootstrap/Form';
import 'react-bootstrap/FormControl';
import 'react-bootstrap/Button';
import './asyncToGenerator-1ebeb135.js';
import './_library-528f1934.js';
import './_set-species-7d3317b7.js';
import './_iter-detect-2f89237f.js';

var NavDvm = function NavDvm(props) {
  var logo = props.logo,
      mobileLogo = props.mobileLogo,
      dataObject = props.dataObject,
      subNav = props.subNav,
      _props$website = props.website,
      website = _props$website === undefined ? {} : _props$website;


  var sfRef = useRef(null);

  useEffect(function () {
    // this adds ?eKey=xxx or ?anonymousid=xxx for forms that's outside - eg) formstack forms
    // for tracking same user
    setTimeout(function () {
      var segmentLinks = sfRef.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 newRef = Segment.getURL(href, { needSegmentSupport: true });
        link.setAttribute('href', newRef);
      }
    }, 1000);
  }, []);

  var getLink = function getLink(url, className, name, key, blank) {
    var needSegmentSupport = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;

    if (url && (url.includes('https://') || url.includes('http://'))) {
      return React__default.createElement(
        'a',
        _extends({
          target: blank ? '_blank' : '_self'
        }, needSegmentSupport ? { 'data-need-segment-support': 'true' } : {}, {
          key: key,
          href: url || '#',
          className: className
        }, checkSisterSite(url) ? {} : { rel: 'noopener noreferrer' }),
        name
      );
    }

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

  return React__default.createElement(
    React__default.Fragment,
    { ref: sfRef },
    React__default.createElement(
      Navbar,
      { className: 'top-nav', expand: 'xl' },
      React__default.createElement(
        Container,
        null,
        React__default.createElement(
          Nav,
          { className: 'justify-content-center', style: { margin: '0 auto' } },
          React__default.createElement(
            Nav.Item,
            null,
            React__default.createElement(
              'a',
              { href: '/' },
              React__default.createElement('img', { src: logo, style: { height: '55px' }, alt: website.title ? website.title : website.name ? website.name : 'Website Logo' })
            )
          )
        )
      )
    ),
    React__default.createElement(
      Navbar,
      { className: 'bottom-nav', variant: 'dark', expand: 'xl', bg: 'primary', sticky: 'top' },
      React__default.createElement(
        Container,
        { className: 'mobile-nav position-relative' },
        mobileLogo && React__default.createElement(
          'a',
          { href: '/', className: 'mobile-logo' },
          React__default.createElement('img', { src: mobileLogo })
        ),
        React__default.createElement(Navbar.Toggle, { 'aria-controls': 'basic-navbar-nav' }),
        React__default.createElement(
          Navbar.Collapse,
          { id: 'basic-navbar-nav' },
          React__default.createElement(
            Nav,
            { className: 'mr-auto' },
            dataObject && dataObject.map(function (row, index) {
              if (row.subQuery.length > 0) {
                return React__default.createElement(
                  'div',
                  null,
                  React__default.createElement(
                    NavDropdown,
                    { key: index, title: row.name, id: 'basic-nav-dropdown', renderMenuOnMount: true },
                    row.subQuery && row.subQuery.map(function (ddRow, subIndex) {
                      if (ddRow.type === 'divider') {
                        return React__default.createElement(NavDropdown.Divider, { key: subIndex });
                      } else {
                        return getLink(ddRow.url, 'dropdown-item', ddRow.name, subIndex, ddRow.blank, ddRow.needSegmentSupport);
                      }
                    })
                  ),
                  React__default.createElement(
                    'noscript',
                    null,
                    React__default.createElement(
                      'div',
                      null,
                      row.subQuery && row.subQuery.map(function (ddRow, subIndex) {
                        if (ddRow.type === 'divider') {
                          return React__default.createElement(NavDropdown.Divider, { key: subIndex });
                        } else {
                          return getLink(ddRow.url, 'dropdown-item', ddRow.name, subIndex, ddRow.blank, ddRow.needSegmentSupport);
                        }
                      })
                    )
                  )
                );
              } else {
                return getLink(row.url, 'nav-link', row.name, index, row.blank, row.needSegmentSupport);
              }
            })
          ),
          React__default.createElement(Search, null)
        ),
        subNav && React__default.createElement(
          Navbar.Collapse,
          { id: 'basic-navbar-sub' },
          React__default.createElement(
            Nav,
            { className: 'mr-auto' },
            subNav && subNav.map(function (row, index) {
              if (row.subQuery && row.subQuery.length > 0) {
                return row.name ? React__default.createElement(
                  'div',
                  null,
                  React__default.createElement(
                    NavDropdown,
                    { key: index, title: row.name, id: 'basic-nav-dropdown', renderMenuOnMount: true },
                    row.subQuery && row.subQuery.map(function (ddRow, subIndex) {
                      if (ddRow.type === 'divider') {
                        return React__default.createElement(NavDropdown.Divider, { key: subIndex });
                      } else {
                        if (ddRow.url && ddRow.name) {
                          return ddRow.url && ddRow.name ? React__default.createElement(
                            'a',
                            _extends({
                              key: subIndex
                            }, ddRow.needSegmentSupport ? { 'data-need-segment-support': 'true' } : {}, {
                              href: ddRow.url,
                              target: ddRow.blank ? '_blank' : '_self',
                              className: 'dropdown-item'
                            }, checkSisterSite(ddRow.url) ? {} : { rel: 'noopener noreferrer' }),
                            ddRow.name
                          ) : null;
                        } else return null;
                      }
                    })
                  ),
                  React__default.createElement(
                    'noscript',
                    null,
                    React__default.createElement(
                      'div',
                      null,
                      row.subQuery && row.subQuery.map(function (ddRow, subIndex) {
                        if (ddRow.type === 'divider') {
                          return React__default.createElement(NavDropdown.Divider, { key: subIndex });
                        } else {
                          if (ddRow.url && ddRow.name) {
                            return ddRow.url && ddRow.name ? React__default.createElement(
                              'a',
                              _extends({
                                key: subIndex
                              }, ddRow.needSegmentSupport ? { 'data-need-segment-support': 'true' } : {}, {
                                href: ddRow.url,
                                target: ddRow.blank ? '_blank' : '_self',
                                className: 'dropdown-item'
                              }, checkSisterSite(ddRow.url) ? {} : { rel: 'noopener noreferrer' }),
                              ddRow.name
                            ) : null;
                          } else return null;
                        }
                      })
                    )
                  )
                ) : null;
              } else {
                return row.url && row.name ? React__default.createElement(
                  'a',
                  _extends({
                    key: index
                  }, row.needSegmentSupport ? { 'data-need-segment-support': 'true' } : {}, {
                    href: row.url,
                    target: row.blank ? '_blank' : '_self',
                    className: 'nav-link'
                  }, checkSisterSite(row.url) ? {} : { rel: 'noopener noreferrer' }),
                  row.name
                ) : null;
              }
            })
          )
        ),
        website && React__default.createElement(
          Navbar.Collapse,
          { id: 'basic-navbar-sub' },
          React__default.createElement(
            Nav,
            { className: 'mr-auto' },
            React__default.createElement(NavFooter, { website: website })
          )
        )
      )
    ),
    React__default.createElement(
      'noscript',
      null,
      React__default.createElement(
        'style',
        { jsx: 'true' },
        '\n          .navbar .collapse {\n            display: block;\n          }\n        '
      )
    ),
    React__default.createElement(
      'style',
      { jsx: 'true' },
      '\n        .mobile-logo {\n          display: none;\n          position: absolute;\n          left: 50%;\n          top: 0;\n          height: 40px;\n          transform: translateX(-50%);\n        }\n        .mobile-logo img {\n          height: 100%;\n        }\n        @media screen and (max-width: 1192px) {\n          .mobile-logo {\n            display: block;\n          }\n          .top-nav {\n            display: none;\n          }\n          .navbar-expand-lg .show#basic-navbar-sub {\n            display: block;\n          }\n          .navbar .mobile-nav .navbar-collapse.show {\n            padding-bottom: 20px;\n            border-bottom: 0.5px solid white;\n            margin-bottom: 15px;\n          }\n          .navbar .mobile-nav .navbar-collapse .form-inline {\n            margin: 5px 0px;\n          }\n          .navbar .mobile-nav .navbar-collapse:last-child {\n            border-bottom: none;\n            margin-bottom: 0px;\n            padding-bottom: 0px;\n          }\n          .navbar .mobile-nav .navbar-collapse .nav-footer ul {\n            list-style-type: none;\n            padding: inherit;\n            margin-bottom: 0rem;\n          }\n          .navbar .mobile-nav .navbar-collapse .nav-footer .nav-link {\n            text-transform: capitalize !important;\n            font-weight: 300;\n          }\n          .navbar .mobile-nav .dropdown-item:focus {\n            background-color: #696969;\n          }\n          .navbar .mobile-nav .dropdown-menu .dropdown-item {\n            color: white;\n          }\n          .navbar .mobile-nav .dropdown-menu {\n            background: inherit;\n            border: none;\n          }\n        }\n        @media screen and (max-width: 991px) {\n          .dropdown-menu {\n            max-height: 315px;\n            overflow: auto;\n          }\n          ::-webkit-scrollbar {\n            width: 10px;\n          }\n          ::-webkit-scrollbar-thumb {\n            border-radius: 4px;\n            background-color: rgba(214, 214, 214, 0.8);\n            box-shadow: 0 0 1px rgba(255, 255, 255, 0.5);\n            -webkit-box-shadow: 0 0 1px rgba(255, 255, 255, 0.5);\n          }\n        }\n        @media screen and (min-width: 1200px) {\n          #basic-navbar-sub {\n            display: none !important;\n          }\n          .navbar .mobile-nav .dropdown-menu .dropdown-item {\n            color: #696969;\n          }\n          .navbar .mobile-nav .dropdown-menu {\n            background: white;\n            border: 1 px solid #708090;\n          }\n        }\n      '
    )
  );
};

export { NavDvm, NavDvm as default };
