/* Bernard Health SeniorCare V1.7.2 — corrección puntual botón Añadir personal */
(function(){
  'use strict';

  if(window.__staffAddButtonFixV172) return;
  window.__staffAddButtonFixV172=true;

  document.addEventListener('click',function(event){
    const addBtn=event.target.closest?.('#showStaffForm');
    if(addBtn){
      event.preventDefault();
      event.stopImmediatePropagation();
      const form=document.getElementById('staffFormFinal');
      if(!form){
        window.showToast?.('No se pudo abrir el formulario de personal.');
        return;
      }
      form.reset();
      if(form.elements.staffId) form.elements.staffId.value='';
      form.classList.remove('hidden');
      form.scrollIntoView({behavior:'smooth',block:'start'});
      form.querySelector('[name="name"]')?.focus({preventScroll:true});
      return;
    }

    const cancelBtn=event.target.closest?.('#cancelStaffFinal');
    if(cancelBtn){
      event.preventDefault();
      event.stopImmediatePropagation();
      const form=document.getElementById('staffFormFinal');
      if(form){
        form.classList.add('hidden');
        form.reset();
        if(form.elements.staffId) form.elements.staffId.value='';
      }
    }
  },true);
})();
