(() => {
  const dialog = document.getElementById('issue-dialog');
  const form = document.getElementById('issue-form');
  if (!dialog || !form) return;
  const dateInput = form.querySelector('input[name="assigned_on"]');
  if (dateInput && !dateInput.value) dateInput.value = new Date().toISOString().slice(0, 10);
  document.querySelectorAll('[data-issue-action]').forEach(button => {
    button.addEventListener('click', () => {
      form.action = button.dataset.issueAction;
      const target = document.getElementById('issue-return-to');
      if (target) target.value = button.dataset.returnTo || 'detail';
      dialog.showModal();
    });
  });
})();
