export const bootstrapNavCloser = () => {
  const closeNav = (navSelector) => {
    const nav = document.getElementById(navSelector)
    if (nav) {
      if (nav.classList.contains('show')) {
        nav.classList.remove('show')
      }
    }
  }

  document.addEventListener('click', (e) => {
    const nav = document.querySelector('.navbar-toggler').dataset['bsTarget'].substring(1)

    if (e.target.attributes.id) {
      if (!e.target.attributes.id.textContent.matchAll([nav, 'dropdown'])) {
        closeNav(nav)
      }
    } else {
      closeNav(nav)
    }
  })
}