/* tooltips */
function initTooltips(section) {
  const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]');
  const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl));
}

function checkTermsandConditions(){
  const checkTerms = document.getElementById('cgv-check'),
        createAccountButton = document.getElementById('btn-create-account');
  createAccountButton.disabled = !checkTerms.checked;
}

const updateMeet = () => {
  const meetOption1 = document.getElementById('user-meetoption-real'),
  meetOption2 = document.getElementById('user-meetoption-virtual'),
  meetOption3 = document.getElementById('user-meetoption-hybrid'),
  meetLocation = document.getElementById('user-tandemmeet-location');
  if (meetLocation) {
    meetLocation.style.display = (meetOption1?.checked || meetOption3?.checked) ? 'block' : 'none';
    [meetOption1, meetOption2, meetOption3].forEach(option => {
      if (option) {
        option.addEventListener('change', updateMeet);
      }}
    );
  }
};

const toggleMenus = ({ matches }) => {
  const offMenu = document.getElementById("offside-menu"),
  sideMenu = document.getElementById("second-nav");
  if(offMenu && sideMenu){
    offMenu.style.display = matches ? "block" : "none";
    sideMenu.style.display = matches ? "none" : "block";
    mediaQuery.addEventListener('change', toggleMenus);
  }
};

const radiusUpdate = () => {
  const rangeInput = document.getElementById('town-radius'),
  rangeValue = document.getElementById('town-radius-value');
  if (rangeInput && rangeValue) {
    rangeInput.addEventListener('input', () => {
      rangeValue.textContent = rangeInput.value;
    });
  }
};

document.addEventListener("DOMContentLoaded", function() {
  mediaQuery = window.matchMedia("(max-width: 992px)");

  radiusUpdate();
  updateMeet();
  initTooltips(document);
  toggleMenus(mediaQuery);
});
