import{M as C}from"./bootstrap.esm-Bb7dPm-H.js";import{d as f}from"./datatables-I6jthWPb.js";import{g as j,r as S}from"./api-DZ3cXm1m.js";import{i as b}from"./tooltip-manager-D9RaGGY4.js";import"./datatables-Bo82YvhT.js";/* empty css                                  */document.addEventListener("DOMContentLoaded",function(){const{translations:n,pageConfig:h}=window,u=t=>{const a={active:["success",n.status_active],revoked:["secondary",n.status_revoked],pending:["warning",n.status_pending],accepted:["success",n.status_accepted],expired:["dark",n.status_expired]},[e,s]=a[t]||["light",t];return`<span class="badge bg-${e}">${s}</span>`},_=t=>{const a=t.permissions_count??(Array.isArray(t.permissions)?t.permissions.length:0),e=n.permissions_count.replace(":count",a);return`<button type="button"
                        class="btn btn-sm btn-outline-secondary inspect-perms"
                        data-perms='${JSON.stringify(t.permissions||[]).replace(/'/g,"&apos;")}'>
                    <i class="fas fa-list me-1"></i>${e}
                </button>`},w=document.getElementById("authorizationPermissionsModal"),p=w?new C(w):null;function x(){document.querySelectorAll(".inspect-perms").forEach(t=>{t.addEventListener("click",function(){const a=JSON.parse(this.getAttribute("data-perms")||"[]"),e=document.getElementById("authorizationPermissionsList");e.innerHTML=a.length?a.map(s=>`<li class="list-group-item"><code>${s}</code></li>`).join(""):'<li class="list-group-item text-muted">—</li>',p==null||p.show()})})}async function v(t,a,e){var E,I;if(!confirm(a))return;let s=j();const z=i=>fetch(t,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Bearer ${i}`}});let c=await z(s);if(c.status===401){const i=await S();i&&(c=await z(i))}let o;try{o=await c.json()}catch{o={}}if(c.ok&&o.success)(E=window.showSuccess)==null||E.call(window,o.message),e==null||e();else{const i=o.message||"Request failed";(I=window.showError)==null||I.call(window,i)}}function m(t){document.querySelectorAll(`#${t} .revoke-authorization`).forEach(a=>{a.addEventListener("click",function(){const e=this.getAttribute("data-id"),s=h.routes.revoke.replace("__ID__",e);v(s,n.confirm_revoke,()=>{r==null||r.ajax.reload(),d==null||d.ajax.reload()})})}),document.querySelectorAll(`#${t} .resend-invitation`).forEach(a=>{a.addEventListener("click",function(){const e=this.getAttribute("data-id"),s=h.routes.resend.replace("__ID__",e);v(s,n.confirm_resend,()=>{l==null||l.ajax.reload()})})})}const g=t=>({url:t,type:"POST",headers:{Authorization:"Bearer "+j()},dataSrc:"data"});let r=null,d=null,l=null;const y=document.getElementById("authorizationsOutgoing");y&&(r=$("#authorizationsOutgoing").DataTable({...f.getDefaultConfig(),serverSide:!1,searching:!0,order:[[0,"desc"]],ajax:g(y.getAttribute("data-records-url")),columns:[{data:"id",width:"80px",render:t=>`<span class="badge bg-secondary">#${t}</span>`},{data:"user_name"},{data:"user_email"},{data:null,orderable:!1,render:(t,a,e)=>_(e)},{data:"status",width:"110px",render:t=>u(t)},{data:"created_at",width:"160px",render:t=>`<small class="text-muted">${t||"-"}</small>`},{data:null,width:"90px",orderable:!1,searchable:!1,render:(t,a,e)=>e.status!=="active"?"":`<button type="button"
                                        class="btn btn-sm btn-outline-danger revoke-authorization"
                                        data-id="${e.id}"
                                        data-bs-toggle="tooltip"
                                        title="${n.buttons_revoke}">
                                    <i class="fas fa-ban"></i>
                                </button>`}],drawCallback:function(){b(),x(),m("authorizationsOutgoing")}}));const k=document.getElementById("authorizationsIncoming");k&&(d=$("#authorizationsIncoming").DataTable({...f.getDefaultConfig(),serverSide:!1,searching:!0,order:[[0,"desc"]],ajax:g(k.getAttribute("data-records-url")),columns:[{data:"id",width:"80px",render:t=>`<span class="badge bg-secondary">#${t}</span>`},{data:"owner_name"},{data:"owner_email"},{data:null,orderable:!1,render:(t,a,e)=>_(e)},{data:"status",width:"110px",render:t=>u(t)},{data:"created_at",width:"160px",render:t=>`<small class="text-muted">${t||"-"}</small>`},{data:null,width:"90px",orderable:!1,searchable:!1,render:(t,a,e)=>e.status!=="active"?"":`<button type="button"
                                        class="btn btn-sm btn-outline-danger revoke-authorization"
                                        data-id="${e.id}"
                                        data-bs-toggle="tooltip"
                                        title="${n.buttons_revoke}">
                                    <i class="fas fa-ban"></i>
                                </button>`}],drawCallback:function(){b(),x(),m("authorizationsIncoming")}}));const A=document.getElementById("authorizationInvitations");A&&(l=$("#authorizationInvitations").DataTable({...f.getDefaultConfig(),serverSide:!1,searching:!0,order:[[0,"desc"]],ajax:g(A.getAttribute("data-records-url")),columns:[{data:"id",width:"80px",render:t=>`<span class="badge bg-secondary">#${t}</span>`},{data:"invitee_email"},{data:"status",width:"110px",render:t=>u(t)},{data:"permissions_count",width:"120px",render:t=>n.permissions_count.replace(":count",t)},{data:"expires_at",width:"160px",render:t=>`<small class="text-muted">${t||"-"}</small>`},{data:"token_tail",width:"120px",render:t=>t?`<code class="small">…${t}</code>`:"-"},{data:"created_at",width:"160px",render:t=>`<small class="text-muted">${t||"-"}</small>`},{data:null,width:"90px",orderable:!1,searchable:!1,render:(t,a,e)=>e.status!=="pending"?"":`<button type="button"
                                        class="btn btn-sm btn-outline-primary resend-invitation"
                                        data-id="${e.id}"
                                        data-bs-toggle="tooltip"
                                        title="${n.buttons_resend}">
                                    <i class="fas fa-paper-plane"></i>
                                </button>`}],drawCallback:function(){b(),m("authorizationInvitations")}}))});
