<script>
  if (!window.customElements.get('server-selector')) {
    customElements.define('server-selector', class extends HTMLElement {
      connectedCallback() {
        const serverSelector = this.querySelector('#server_selector');
        const globalServerSelector = this.querySelector('#global_server_selector');
        const euServerAlert = this.querySelector('#eu_server_alert');
        const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
        const usTimezones = /^(?:America\/(?:New_York|Detroit|Kentucky|Indiana|Chicago|Menominee|North_Dakota|Denver|Boise|Phoenix|Los_Angeles|Anchorage|Juneau|Sitka|Metlakatla|Yakutat|Nome|Adak)|Pacific\/Honolulu)/;

        if (!serverSelector.classList.contains('hidden')) {
          return
        }

        if (usTimezones.test(timezone)) {
          serverSelector.classList.remove('hidden');
        } else if (timezone.includes('Europe')) {
          globalServerSelector.classList.remove('hidden');
          euServerAlert?.classList?.remove('hidden');
        } else {
          globalServerSelector.classList.remove('hidden');
        }
      }
    });
  }
</script>
