/* 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('cgvCheck'),
        createAccountButton = document.getElementById('btnCreateAccount');
  createAccountButton.disabled = !checkTerms.checked;
}

const updateMeet = () => {
  const meetOption1 = document.getElementById('userMeetOptionReal'),
  meetOption2 = document.getElementById('userMeetOptionVirtual'),
  meetOption3 = document.getElementById('userMeetOptionHybrid'),
  meetLocation = document.getElementById('userTandemMeetLocation');
  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("offSideMenu"),
  sideMenu = document.getElementById("secondNav");
  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('townRadius'),
  rangeValue = document.getElementById('townRadiusValue');
  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);
});
