'use strict';

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

var _extends = require('./extends-be0d85bc.js');
var React = require('react');
var Container = require('react-bootstrap/Container');
var Nav = require('react-bootstrap/Nav');
var Navbar = require('react-bootstrap/Navbar');
var NavDropdown = require('react-bootstrap/NavDropdown');
var checkSisterSite = require('./checkSisterSite-c3a4ac98.js');
var Search = require('./Search.js');
var NavFooter = require('./NavFooter-fa5fae05.js');
var Segment = require('./Segment.js');
require('./_commonjsHelpers-06173234.js');
require('./core.get-iterator-method-5643aa10.js');
require('./slicedToArray-067dd3bc.js');
require('./web.dom.iterable-d98303e0.js');
require('react-bootstrap/Form');
require('react-bootstrap/FormControl');
require('react-bootstrap/Button');
require('./asyncToGenerator-65df6bf8.js');
require('./_library-dd23b178.js');
require('./_set-species-0c7864a2.js');
require('./_iter-detect-b1df62f0.js');

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

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
var Container__default = /*#__PURE__*/_interopDefaultLegacy(Container);
var Nav__default = /*#__PURE__*/_interopDefaultLegacy(Nav);
var Navbar__default = /*#__PURE__*/_interopDefaultLegacy(Navbar);
var NavDropdown__default = /*#__PURE__*/_interopDefaultLegacy(NavDropdown);

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 = React.useRef(null);

  React.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['default'].createElement(
        'a',
        _extends._extends({
          target: blank ? '_blank' : '_self'
        }, needSegmentSupport ? { 'data-need-segment-support': 'true' } : {}, {
          key: key,
          href: url || '#',
          className: className
        }, checkSisterSite.checkSisterSite(url) ? {} : { rel: 'noopener noreferrer' }),
        name
      );
    }

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

  return React__default['default'].createElement(
    React__default['default'].Fragment,
    { ref: sfRef },
    React__default['default'].createElement(
      Navbar__default['default'],
      { className: 'top-nav', expand: 'xl' },
      React__default['default'].createElement(
        Container__default['default'],
        null,
        React__default['default'].createElement(
          Nav__default['default'],
          { className: 'justify-content-center', style: { margin: '0 auto' } },
          React__default['default'].createElement(
            Nav__default['default'].Item,
            null,
            React__default['default'].createElement(
              'a',
              { href: '/' },
              React__default['default'].createElement('img', { src: logo, style: { height: '55px' }, alt: website.title ? website.title : website.name ? website.name : 'Website Logo' })
            )
          )
        )
      )
    ),
    React__default['default'].createElement(
      Navbar__default['default'],
      { className: 'bottom-nav', variant: 'dark', expand: 'xl', bg: 'primary', sticky: 'top' },
      React__default['default'].createElement(
        Container__default['default'],
        { className: 'mobile-nav position-relative' },
        mobileLogo && React__default['default'].createElement(
          'a',
          { href: '/', className: 'mobile-logo' },
          React__default['default'].createElement('img', { src: mobileLogo })
        ),
        React__default['default'].createElement(Navbar__default['default'].Toggle, { 'aria-controls': 'basic-navbar-nav' }),
        React__default['default'].createElement(
          Navbar__default['default'].Collapse,
          { id: 'basic-navbar-nav' },
          React__default['default'].createElement(
            Nav__default['default'],
            { className: 'mr-auto' },
            dataObject && dataObject.map(function (row, index) {
              if (row.subQuery.length > 0) {
                return React__default['default'].createElement(
                  'div',
                  null,
                  React__default['default'].createElement(
                    NavDropdown__default['default'],
                    { 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['default'].createElement(NavDropdown__default['default'].Divider, { key: subIndex });
                      } else {
                        return getLink(ddRow.url, 'dropdown-item', ddRow.name, subIndex, ddRow.blank, ddRow.needSegmentSupport);
                      }
                    })
                  ),
                  React__default['default'].createElement(
                    'noscript',
                    null,
                    React__default['default'].createElement(
                      'div',
                      null,
                      row.subQuery && row.subQuery.map(function (ddRow, subIndex) {
                        if (ddRow.type === 'divider') {
                          return React__default['default'].createElement(NavDropdown__default['default'].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['default'].createElement(Search, null)
        ),
        subNav && React__default['default'].createElement(
          Navbar__default['default'].Collapse,
          { id: 'basic-navbar-sub' },
          React__default['default'].createElement(
            Nav__default['default'],
            { className: 'mr-auto' },
            subNav && subNav.map(function (row, index) {
              if (row.subQuery && row.subQuery.length > 0) {
                return row.name ? React__default['default'].createElement(
                  'div',
                  null,
                  React__default['default'].createElement(
                    NavDropdown__default['default'],
                    { 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['default'].createElement(NavDropdown__default['default'].Divider, { key: subIndex });
                      } else {
                        if (ddRow.url && ddRow.name) {
                          return ddRow.url && ddRow.name ? React__default['default'].createElement(
                            'a',
                            _extends._extends({
                              key: subIndex
                            }, ddRow.needSegmentSupport ? { 'data-need-segment-support': 'true' } : {}, {
                              href: ddRow.url,
                              target: ddRow.blank ? '_blank' : '_self',
                              className: 'dropdown-item'
                            }, checkSisterSite.checkSisterSite(ddRow.url) ? {} : { rel: 'noopener noreferrer' }),
                            ddRow.name
                          ) : null;
                        } else return null;
                      }
                    })
                  ),
                  React__default['default'].createElement(
                    'noscript',
                    null,
                    React__default['default'].createElement(
                      'div',
                      null,
                      row.subQuery && row.subQuery.map(function (ddRow, subIndex) {
                        if (ddRow.type === 'divider') {
                          return React__default['default'].createElement(NavDropdown__default['default'].Divider, { key: subIndex });
                        } else {
                          if (ddRow.url && ddRow.name) {
                            return ddRow.url && ddRow.name ? React__default['default'].createElement(
                              'a',
                              _extends._extends({
                                key: subIndex
                              }, ddRow.needSegmentSupport ? { 'data-need-segment-support': 'true' } : {}, {
                                href: ddRow.url,
                                target: ddRow.blank ? '_blank' : '_self',
                                className: 'dropdown-item'
                              }, checkSisterSite.checkSisterSite(ddRow.url) ? {} : { rel: 'noopener noreferrer' }),
                              ddRow.name
                            ) : null;
                          } else return null;
                        }
                      })
                    )
                  )
                ) : null;
              } else {
                return row.url && row.name ? React__default['default'].createElement(
                  'a',
                  _extends._extends({
                    key: index
                  }, row.needSegmentSupport ? { 'data-need-segment-support': 'true' } : {}, {
                    href: row.url,
                    target: row.blank ? '_blank' : '_self',
                    className: 'nav-link'
                  }, checkSisterSite.checkSisterSite(row.url) ? {} : { rel: 'noopener noreferrer' }),
                  row.name
                ) : null;
              }
            })
          )
        ),
        website && React__default['default'].createElement(
          Navbar__default['default'].Collapse,
          { id: 'basic-navbar-sub' },
          React__default['default'].createElement(
            Nav__default['default'],
            { className: 'mr-auto' },
            React__default['default'].createElement(NavFooter.NavFooter, { website: website })
          )
        )
      )
    ),
    React__default['default'].createElement(
      'noscript',
      null,
      React__default['default'].createElement(
        'style',
        { jsx: 'true' },
        '\n          .navbar .collapse {\n            display: block;\n          }\n        '
      )
    ),
    React__default['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      '
    )
  );
};

exports.NavDvm = NavDvm;
exports['default'] = NavDvm;
