import React, { 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 Search from './Search.js';
import { N as NavFooter } from './NavFooter-c29526b7.js';
import Segment from './Segment.js';
import './slicedToArray-be2f7a22.js';
import './_commonjsHelpers-0c4b6f40.js';
import './web.dom.iterable-4109ff68.js';
import './es6.string.iterator-bc33758b.js';
import './_to-object-b50e61c3.js';
import './core.get-iterator-method-133dfacd.js';
import 'react-bootstrap/Form';
import 'react-bootstrap/FormControl';
import 'react-bootstrap/Button';
import './asyncToGenerator-7f8f9219.js';
import './_library-528f1934.js';
import './_iter-detect-7e5e5ce2.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[needsegmentsupport="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.createElement(
        'a',
        { target: blank ? '_blank' : '_self', needsegmentsupport: needSegmentSupport ? 'true' : '', key: key, href: url || '#', className: className },
        name
      );
    }

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

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