import '../bolt-select/bolt-select';

const boltSelect = document.querySelector('bolt-select');

boltSelect.addEventListener('choice', function(e) {
  var url = e.detail.choice.value;
  if (url && window.location.href !== url) {
    window.location = url; // redirect
  }
});

import '../bolt-select/bolt-select';

const boltSelect = document.querySelector('bolt-select');
let shouldOpenInNewWindow = false;

boltSelect.addEventListener('mousedown', function(e) {
  if (e.metaKey === true) {
    shouldOpenInNewWindow = true;
  } else {
    shouldOpenInNewWindow = false;
  }
});

boltSelect.addEventListener('choice', function(e) {
  var url = e.detail.choice.value;
  if (url && window.location.href !== url) {
    // open Bolt version selected in a new tab (vs same tab) if the CMD / meta key is held
    if (shouldOpenInNewWindow) {
      window.open(url, '_blank');
    } else {
      window.location = url;
    }
  }
});

update Bolt version selector to open up in a new window if the CMD key is pressed down