{"size": 1635, "ext": "js", "max_stars_repo_path": "_src/assets/js/_collapsibles.js", "max_stars_repo_name": "carolcesp/awesome-profile-card", "max_stars_repo_stars_event_min_datetime": "2020-07-24T18:36:07.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-24T18:36:07.000Z", "max_issues_repo_path": "_src/assets/js/_collapsibles.js", "max_issues_repo_name": "carolcesp/awesome-profile-card", "max_issues_repo_issues_event_min_datetime": "2021-01-30T20:34:42.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-30T20:34:42.000Z", "max_forks_repo_path": "_src/assets/js/_collapsibles.js", "max_forks_repo_name": "carolcesp/awesome-profile-card", "max_forks_repo_forks_event_min_datetime": "2019-02-25T09:05:35.000Z", "max_forks_repo_forks_event_max_datetime": "2019-06-14T10:02:48.000Z"}
{"max_stars_count": 1, "max_issues_count": 1, "max_forks_count": 4, "avg_line_length": 34.7872340426, "max_line_length": 205, "alphanum_fraction": 0.7272171254}
'use strict';

const collapButtons = document.querySelectorAll('.form--btn');
const collapContainer = document.querySelector('.section');

// Función encargada de modificar el icono arrow de un desplegable
function arrows(element){
  const icon = element.querySelector('.fas');
  if(icon.classList.contains('fa-chevron-down')){
    element.innerHTML = `<i class="fas fa-chevron-up"></i>`;
  } else {
    element.innerHTML = `<i class="fas fa-chevron-down"></i>`;
  }
}

// Función encargada de cerrar todos los collapsibles y los cerrados tienen arrow-down
function closeAllCollapsibles() {
  for (const closeCollap of collapButtons) {
    closeCollap.parentElement.classList.remove('collapsible--visible');

    const iconArrow = closeCollap.querySelector('.form--btn_icon');

    iconArrow.innerHTML = `<i class="fas fa-chevron-down"></i>`;
  }
}

/*Función encargada de abrir el objeto clickado y de cerrar las que no tienen el evento. A su vez en el que está ocurriendo el evento se le pone arrow-up, y si se le quita el evento se le pone arrow-down*/
function updateCollapsibles(e) {
  const parent = e.currentTarget.parentElement;
  const iconArrow = e.currentTarget.querySelector('.form--btn_icon');

  // cerrar el abierto
  if (parent.classList.contains('collapsible--visible')) {
    parent.classList.remove('collapsible--visible');
  } else {
    // abrir uno nuevo
    closeAllCollapsibles();
    parent.classList.add('collapsible--visible');
  }
  arrows(iconArrow);
}

//Añade a todos los colapsables un click event listener
for (const collap of collapButtons) {
  collap.addEventListener('click', updateCollapsibles);
}
