{"size": 1400, "ext": "js", "max_stars_repo_path": "_src/assets/js/dom/edit.js", "max_stars_repo_name": "SanchezGloria/To-Do-List", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "_src/assets/js/dom/edit.js", "max_issues_repo_name": "SanchezGloria/To-Do-List", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "_src/assets/js/dom/edit.js", "max_forks_repo_name": "SanchezGloria/To-Do-List", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.3333333333, "max_line_length": 88, "alphanum_fraction": 0.6378571429}
import helpers from './helpers.js';

const editEl = document.querySelector('.js-edit');

// open

const open = (card, list) => {
  // title
  const titleEl = document.querySelector('.js-edit-title');
  titleEl.value = card.title;
  // description
  const descriptionEl = document.querySelector('.js-edit-description');
  descriptionEl.value = card.description;
  // list
  const listEl = document.querySelector('.js-edit-list');
  listEl.innerHTML = list.title;
  // tags
  renderTags(card.tags);
  // modal
  editEl.classList.add('show');
  editEl.classList.remove('d-none');
};

const renderTags = (tags) => {
  const tagsEl = document.querySelector('.js-edit-tags');
  tagsEl.innerHTML = '';
  tags.forEach((tag) => {
    helpers.appendElement(tagsEl, {
      tag: 'span',
      class: 'badge badge-secondary bg-success mr-1',
      text: tag,
    });
  });
};

// close button

const close = (ev) => {
  if (ev) {
    ev.stopPropagation();
  }
  editEl.classList.remove('show');
};

document.querySelector('.js-edit-close').addEventListener('click', close);
document.querySelector('.js-edit-overlay').addEventListener('click', close);

// modal

const preventEditClosing = (ev) => {
  ev.stopPropagation();
};

document.querySelector('.js-edit-modal').addEventListener('click', preventEditClosing);

export default {
  open,
  close,
};
