import"./bootstrap.esm-Bb7dPm-H.js";import{d as g}from"./datatables-CdFC5o1t.js";import{i as p}from"./tooltip-manager-D9RaGGY4.js";import"jquery";import"./datatables-bbQliV7G.js";/* empty css                                  */document.addEventListener("DOMContentLoaded",function(){const s=document.getElementById("emailCampaigns");if(!s)return;const u=s.getAttribute("data-records-url"),{permissions:l,routes:o}=window,f=$("#emailCampaigns").DataTable({...g.getDefaultConfig(),serverSide:!0,searching:!1,dom:'<"d-flex align-items-center mb-3"<"d-flex align-items-center"l>>t<"d-flex justify-content-between align-items-center mt-3"<"d-flex align-items-center"i><"d-flex align-items-center"p>>',ajax:{url:u,type:"GET",headers:{Authorization:"Bearer "+document.querySelector('meta[name="api-token"]').getAttribute("content")},data:function(t){var e,a;t.status=((e=document.getElementById("filterStatus"))==null?void 0:e.value)||"",t.email_marketing_list_id=((a=document.getElementById("filterList"))==null?void 0:a.value)||""}},columns:[{data:"name",name:"name"},{data:"subject",name:"subject"},{data:"status",name:"status",render:function(t){return`<span class="badge bg-${{draft:"secondary",scheduled:"info",sending:"warning",sent:"success",paused:"dark",failed:"danger"}[t]||"secondary"}">${t}</span>`}},{data:"scheduled_at",name:"scheduled_at"},{data:"sent_at",name:"sent_at"},{data:"sent_count",name:"sent_count"},{data:"open_count",name:"open_count"},{data:"click_count",name:"click_count"},{data:"id",name:"actions",orderable:!1,searchable:!1,render:function(t){var a,n,d,r,c,m;const e=[];if((a=l.emailCampaigns)!=null&&a.update){const i=o.emailCampaigns.edit.replace(":id",t);e.push(`
                            <a href="${i}"
                               class="btn btn-sm btn-outline-primary d-inline-flex align-items-center justify-content-center"
                               style="width: 32px; height: 32px;"
                               data-bs-toggle="tooltip"
                               title="${((d=(n=window.translations)==null?void 0:n.buttons)==null?void 0:d.edit)||"Edit"}">
                                <i class="fas fa-edit"></i>
                            </a>`)}if((r=l.emailCampaigns)!=null&&r.delete){const i=o.emailCampaigns.delete.replace(":id",t);e.push(`
                            <button type="button"
                                    class="btn btn-sm btn-outline-danger d-inline-flex align-items-center justify-content-center ms-1 delete-campaign"
                                    style="width: 32px; height: 32px;"
                                    data-id="${t}"
                                    data-url="${i}"
                                    data-bs-toggle="tooltip"
                                    title="${((m=(c=window.translations)==null?void 0:c.buttons)==null?void 0:m.delete)||"Delete"}">
                                <i class="fas fa-trash"></i>
                            </button>`)}return e.length?`<div class="d-inline-flex">${e.join("")}</div>`:'<span class="text-muted">-</span>'}}],drawCallback:function(){p()}});["filterStatus","filterList"].forEach(t=>{const e=document.getElementById(t);e&&e.addEventListener("change",()=>f.ajax.reload())}),document.body.addEventListener("click",async function(t){const e=t.target.closest(".delete-campaign");if(!e)return;const a=e.getAttribute("data-url");(await fetch(a,{method:"DELETE",headers:{Authorization:"Bearer "+document.querySelector('meta[name="api-token"]').getAttribute("content")}})).ok&&$("#emailCampaigns").DataTable().ajax.reload(null,!1)})});
