import{d as m}from"./datatables-I6jthWPb.js";import{r as d,g as u}from"./api-DZ3cXm1m.js";import"./bootstrap.esm-Bb7dPm-H.js";import"./datatables-Bo82YvhT.js";/* empty css                                  */const s=()=>window.campaignSendConfig;let o=null;$(document).ready(function(){f(),p()});function f(){if(!document.getElementById("recipientsTable"))return;const t=$("#recipientsTable").data("records-url");o=$("#recipientsTable").DataTable({...m.getDefaultConfig(),ajax:{url:t,type:"GET",beforeSend:e=>e.setRequestHeader("Authorization",`Bearer ${u()}`),error:async function(e){e.status===401&&await d()&&o.ajax.reload()}},order:[[3,"desc"]],columns:[{data:"email"},{data:"name",render:e=>e||'<span class="text-muted">—</span>'},{data:"status",render:e=>{const a={queued:["bg-secondary","fa-clock"],sent:["bg-success","fa-check"],failed:["bg-danger","fa-times"],bounced:["bg-warning","fa-exclamation-triangle"]},[n,c]=a[e]||["bg-secondary","fa-question"];return`<span class="badge ${n}"><i class="fas ${c} me-1"></i>${e}</span>`}},{data:"sent_at",render:e=>e||'<span class="text-muted">—</span>'},{data:"opened_at",render:(e,a,n)=>e?`${e}${n.opened_count>1?` <small class="text-muted">(×${n.opened_count})</small>`:""}`:'<span class="text-muted">—</span>'},{data:"clicked_at",render:(e,a,n)=>e?`${e}${n.click_count>1?` <small class="text-muted">(×${n.click_count})</small>`:""}`:'<span class="text-muted">—</span>'},{data:"last_error",render:e=>e?`<span class="text-danger small" title="${l(e)}">${l(e.substring(0,60))}...</span>`:'<span class="text-muted">—</span>'}]})}function p(){var t,e,a;(t=document.getElementById("btnConfirmSend"))==null||t.addEventListener("click",g),(e=document.getElementById("btnSendTest"))==null||e.addEventListener("click",b),(a=document.getElementById("btnConfirmCancel"))==null||a.addEventListener("click",y)}async function g(){const t=await i(s().routes.send),e=await t.json().catch(()=>null);t.ok&&(e!=null&&e.success)?(alert(e.message||s().translations.send_dispatched),window.location.reload()):alert((e==null?void 0:e.error)||s().translations.send_failed)}async function b(){const t=document.getElementById("formSendTest"),e=new FormData(t),a=Object.fromEntries(e.entries()),n=document.getElementById("sendTestResult"),c=await i(s().routes.sendTest,JSON.stringify(a)),r=await c.json().catch(()=>null);c.ok&&(r!=null&&r.success)?n.innerHTML=`<div class="alert alert-success small">${s().translations.test_sent}</div>`:n.innerHTML=`<div class="alert alert-danger small">${(r==null?void 0:r.error)||s().translations.send_failed}</div>`}async function y(){const t=await i(s().routes.cancel),e=await t.json().catch(()=>null);t.ok&&(e!=null&&e.success)?(alert(e.message||s().translations.cancel_done),window.location.reload()):alert((e==null?void 0:e.error)||s().translations.send_failed)}async function i(t,e=null){const a={method:"POST",headers:{Authorization:`Bearer ${u()}`,Accept:"application/json","Content-Type":"application/json"}};e&&(a.body=e);let n=await fetch(t,a);if(n.status===401){const c=await d();c&&(a.headers.Authorization=`Bearer ${c}`,n=await fetch(t,a))}return n}function l(t){return String(t).replace(/[&<>"']/g,e=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[e])}
