import{d}from"./datatables-CdFC5o1t.js";import{r as l,g as i}from"./api-DZ3cXm1m.js";import"./bootstrap.esm-Bb7dPm-H.js";import"jquery";import"./datatables-bbQliV7G.js";/* empty css                                  */const a=()=>window.iysConfig||{};let r=null;$(document).ready(function(){u(),y()});function u(){const e=$("#iysSyncTable").data("records-url");r=$("#iysSyncTable").DataTable({...d.getDefaultConfig(),serverSide:!0,ajax:{url:e,type:"GET",data:function(t){t["filter[status]"]=$('[data-filter="status"]').val()||"",t["filter[iys_type]"]=$('[data-filter="iys_type"]').val()||""},beforeSend:function(t){t.setRequestHeader("Authorization",`Bearer ${i()}`)},error:async function(t){t.status===401&&await l()&&r.ajax.reload()}},columns:[{data:"client",name:"client"},{data:"iys_type",name:"iys_type"},{data:"recipient",name:"recipient"},{data:"recipient_type",name:"recipient_type"},{data:"granted",name:"granted",render:function(t){return t?`<span class="badge bg-success">${a().translations.onay}</span>`:`<span class="badge bg-secondary">${a().translations.ret}</span>`}},{data:"status",name:"status",render:function(t){const n={synced:["bg-success",a().translations.status_synced],pending:["bg-warning text-dark",a().translations.status_pending],failed:["bg-danger",a().translations.status_failed],blocked_at_iys:["bg-dark",a().translations.status_blocked]},[s,c]=n[t]||["bg-secondary",t];return`<span class="badge ${s}">${c}</span>`}},{data:"synced_at",name:"synced_at",render:t=>t||'<span class="text-muted">-</span>'}],order:[[6,"desc"]]}),$('[data-filter="status"], [data-filter="iys_type"]').on("change",()=>r.ajax.reload())}function y(){var e,t;(e=document.getElementById("iysTestBtn"))==null||e.addEventListener("click",f),(t=document.getElementById("iysSyncBtn"))==null||t.addEventListener("click",p)}async function o(e){return await fetch(e,{method:"POST",headers:{Authorization:`Bearer ${i()}`,"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})})}async function f(e){const t=e.currentTarget;t.disabled=!0;try{const s=await(await o(a().routes.testConnection)).json();window.alert(s.success?a().translations.test_ok:a().translations.test_failed)}catch{window.alert(a().translations.error)}finally{t.disabled=!1}}async function p(e){const t=e.currentTarget;t.disabled=!0;try{(await o(a().routes.triggerSync)).ok?window.alert(a().translations.sync_started):window.alert(a().translations.error)}catch{window.alert(a().translations.error)}finally{t.disabled=!1}}
