function i(o,e){let n=document.getElementById("erp-toast-area");n||(n=document.createElement("div"),n.id="erp-toast-area",n.className="erp-toast-area position-fixed bottom-0 end-0 p-3",n.style.zIndex="1080",document.body.appendChild(n));const t=document.createElement("div");t.className="erp-toast alert shadow-sm small mb-2 "+(e==="danger"?"alert-danger":"alert-success"),t.setAttribute("role","status"),t.textContent=o,n.appendChild(t),setTimeout(()=>{t.classList.add("opacity-50"),setTimeout(()=>t.remove(),4e3)},6e3)}function u(o){return document.querySelectorAll(`input[type="checkbox"][form="${o}"]:checked`).length}document.addEventListener("DOMContentLoaded",()=>{document.querySelectorAll("[data-erp-select-page]").forEach(e=>{e.addEventListener("click",()=>{const n=e.getAttribute("data-erp-select-page"),t=n?document.querySelector(n):null,r=t instanceof HTMLFormElement?t.getAttribute("id"):null;r&&document.querySelectorAll(`input[type="checkbox"][form="${r}"]`).forEach(l=>{l.checked=!0})})}),document.querySelectorAll('button[type="submit"][form][data-bulk-confirm]').forEach(e=>{e.addEventListener("click",n=>{const t=e.getAttribute("form");if(!t)return;const r=u(t);if(r===0){n.preventDefault();const a=window.__erpBulkMessages?.noneSelected??"Select at least one row.";i(a,"danger");return}const c=(e.getAttribute("data-bulk-confirm")??"").replace("__COUNT__",String(r));if(!window.confirm(c)){n.preventDefault();return}const s=e.getAttribute("data-bulk-confirm-value"),d=document.getElementById(t);if(d&&s){const a=d.querySelector('input[name="confirmation"]');a&&(a.value=s)}})});const o=document.getElementById("erp-bulk-result");if(o)try{const e=JSON.parse(o.textContent),n=(e.succeeded||[]).length,t=(e.failures||[]).length,r=e.label??"",c=(window.__erpBulkToastTemplate??":label — :ok ok, :fail failed.").replace(":label",r).replace(":ok",String(n)).replace(":fail",String(t));i(c,t>0?"danger":"success")}catch{}document.addEventListener("keydown",e=>{if(e.key!=="?"||e.ctrlKey||e.metaKey||e.altKey)return;const n=e.target&&e.target.tagName||"";if(["INPUT","TEXTAREA","SELECT"].includes(String(n)))return;e.preventDefault();const t=document.getElementById("erp-speed-hints");t&&window.alert(t.textContent)})});
