/* eslint-disable no-undef */

const logo = document.querySelector('.navbar-brand > a')

function removeSecretNav () {
  const elements = document.getElementsByClassName('secret-nav')
  while (elements.length > 0) {
    elements[0].parentNode.removeChild(elements[0])
  }
}

fetch('/web/dms/api/auth/status')
  .then((response) => {
    if (response.url === 'https://swlab.bwg.co.kr/web/dms/login') {
      removeSecretNav()
      logo.setAttribute('href', 'https://swlab.bwg.co.kr')
    } else {
      logo.setAttribute('href', 'https://swlab.bwg.co.kr/web/dms/home')
    }
  })
  .catch((error) => {
    console.error('Error checking login status:', error)
    removeSecretNav()
  })
