
document.addEventListener('DOMContentLoaded', () => {
  // Functions to open and close a modal
  function openModal($el) {
    $el.classList.add('is-active');
  }

  function closeModal($el) {
    $el.classList.remove('is-active');
  }

  function closeAllModals() {
    (document.querySelectorAll('.modal') || []).forEach(($modal) => {
      closeModal($modal);
    });
  }

  // Add a click event on buttons to open a specific modal
  (document.querySelectorAll('.js-modal-trigger') || []).forEach(($trigger) => {
    const modal = $trigger.dataset.target;
    const $target = document.getElementById(modal);

    $trigger.addEventListener('click', () => {
      openModal($target);
    });
  });

  // Add a click event on various child elements to close the parent modal
  (document.querySelectorAll('.modal-background, .modal-close, .modal-card-head .delete, .modal-card-foot .button') || []).forEach(($close) => {
    const $target = $close.closest('.modal');

    $close.addEventListener('click', () => {
      closeModal($target);
    });
  });

  // Add a keyboard event to close all modals
  document.addEventListener('keydown', (event) => {
    const e = event || window.event;

    if (e.keyCode === 27) { // Escape key
      closeAllModals();
    }
  });
});

document.addEventListener('DOMContentLoaded', () => {
  (document.querySelectorAll('.notification .delete') || []).forEach(($delete) => {
    const $notification = $delete.parentNode;

    $delete.addEventListener('click', () => {
      $notification.parentNode.removeChild($notification);
    });
  });
});

document.addEventListener('DOMContentLoaded', function () {

  // Get all "navbar-burger" elements
  var $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0);

  // Check if there are any navbar burgers
  if ($navbarBurgers.length > 0) {

    // Add a click event on each of them
    $navbarBurgers.forEach(function ($el) {
      $el.addEventListener('click', function () {

        // Get the target from the "data-target" attribute
        var target = $el.dataset.target;
        var $target = document.getElementById(target);

        // console.log("el : " + $el)
        // console.log($el)
        // console.log("target : " + target)
        // console.log(target)
        // console.log("$target : " + $target)
        // console.log($target)

        // Toggle the class on both the "navbar-burger" and the "navbar-menu"
        $el.classList.toggle('is-active');
        $target.classList.toggle('is-active');

      });
    });
  }
});


// const bulmaCollapsibleInstances = bulmaCollapsible.attach('.is-collapsible');

document.addEventListener('DOMContentLoaded', function() {
    const bulmaCollapsibleInstances = bulmaCollapsible.attach('.is-collapsible');
	let cardToggles2 = document.getElementsByClassName('card-header-icon');
    //console.log(cardToggles2)
	for (let i = 0; i < cardToggles2.length; i++) {
		cardToggles2[i].addEventListener('click', e => {

            var element = e.currentTarget.parentElement.childNodes[3].childNodes[1].childNodes[1]

            if(bulmaCollapsibleInstances[i].collapsed() == true){
                element.classList.replace('fa-angle-up','fa-angle-down')
            }
            else{
                element.classList.replace('fa-angle-down','fa-angle-up')
            }
		});
	}
});