import"./DsnmJJEf.js";import{p as le,f as z,d,r as s,s as f,g as e,t as Y,a as b,b as ue,k as p,e as ne,c as R,h as re,m as de,u as Ne,j as F}from"./Dyk1ealw.js";import{d as ce,s as M,a as V}from"./DEEYSJdk.js";import{i as O}from"./cYAxD0tk.js";import{b as be,s as S,e as ae,t as Se}from"./CDBVw774.js";import{i as g}from"./CVq-Ik9t.js";import{h as De}from"./CGX1Ds8Z.js";import{p as ye}from"./BsWaFq0J.js";import{t as Te}from"./2qAQxj2q.js";import{s as K}from"./BGzpdNMV.js";import{C as ie}from"./CXjCfMTZ.js";import{B as Me}from"./BORSyOY6.js";import{M as Ae}from"./C2FhRtnA.js";import{C as fe}from"./DUu1CTgB.js";import{U as me}from"./CVSsPV09.js";import{L as Le}from"./BkBShXgg.js";import{C as Oe}from"./BLVpITD9.js";var Re=R('<span class="inline-flex"><!></span>'),we=R('<div class="flex items-center justify-between border-t border-border px-4 py-2"><span> </span> <div class="flex shrink-0 items-center gap-2"><!> <!> <div class="flex shrink-0 overflow-hidden rounded-md border border-border text-[0.6875rem] font-medium"><button type="button"><!></button> <button type="button"><!></button> <button type="button"><!></button></div></div></div> <!>',1);function ve(q,t){le(t,!0);const E=p(()=>{const r=t.action.name.split(".");let a=t.value;for(const m of r)if(a&&typeof a=="object")a=a[m];else return"unset";return a===!0?"allowed":a===!1?"denied":"unset"}),w=p(()=>t.superAdmin&&t.action.name!=="admin.super"&&(t.action.name.startsWith("admin.")||t.action.name.startsWith("site."))||t.apiSuper&&t.action.name!=="api.super"&&t.action.name.startsWith("api.")),u=p(()=>t.inherited?.[t.action.name]),P=p(()=>e(E)==="unset"&&e(u)?.state==="allowed"),C=p(()=>e(E)==="unset"&&e(u)?.state==="denied"),G=p(()=>e(E)==="allowed"&&e(u)?.state==="denied"||e(E)==="denied"&&e(u)?.state==="allowed"),D=p(()=>{if(!e(u))return"";const r=e(u).groups.join(", ");return e(G)?g.t("ADMIN_NEXT.PERMISSIONS_FIELD.OVERRIDES_GROUP",{groups:r}):e(u).state==="allowed"?g.t("ADMIN_NEXT.PERMISSIONS_FIELD.INHERITED_ALLOWED",{groups:r}):g.t("ADMIN_NEXT.PERMISSIONS_FIELD.INHERITED_DENIED",{groups:r})});var k=we(),A=z(k),L=d(A),Q=d(L,!0);s(L);var W=f(L,2),H=d(W);{var Z=r=>{fe(r,{size:14,class:"text-purple-500"})};O(H,r=>{e(w)&&r(Z)})}var X=f(H,2);{var $=r=>{var a=Re(),m=d(a);{let v=p(()=>e(G)?"text-amber-500":"text-muted-foreground/70");me(m,{size:14,get class(){return e(v)}})}s(a),Y(()=>{S(a,"title",e(D)),S(a,"aria-label",e(D))}),b(r,a)};O(X,r=>{e(u)&&r($)})}var U=f(X,2),h=d(U),n=d(h);ie(n,{size:14}),s(h);var i=f(h,2),o=d(i);Me(o,{size:14}),s(i);var l=f(i,2),_=d(l);Ae(_,{size:14}),s(l),s(U),s(W),s(A);var x=f(A,2);{var c=r=>{var a=ne(),m=z(a);ae(m,17,()=>t.action.children,v=>v.name,(v,N)=>{{let y=p(()=>t.depth+1);ve(v,{get action(){return e(N)},get depth(){return e(y)},get value(){return t.value},get superAdmin(){return t.superAdmin},get apiSuper(){return t.apiSuper},get inherited(){return t.inherited},get onToggle(){return t.onToggle}})}}),b(r,a)};O(x,r=>{t.action.children&&r(c)})}Y((r,a,m,v,N,y)=>{be(A,`padding-left: ${16+t.depth*24}px`),K(L,1,`text-sm ${t.depth>0?"text-muted-foreground":"text-foreground"}`),M(Q,t.action.label),K(h,1,`flex items-center justify-center px-2 py-1.5 transition-colors
					${e(E)==="allowed"?"bg-green-500 text-white":e(P)?"bg-green-500/15 text-green-600 ring-1 ring-inset ring-green-500/30 dark:text-green-400":"text-muted-foreground hover:bg-muted"}`),S(h,"title",r),S(h,"aria-label",a),K(i,1,`flex items-center justify-center border-x border-border px-2 py-1.5 transition-colors
					${e(E)==="denied"?"bg-red-400 text-white":e(C)?"bg-red-400/15 text-red-500 ring-1 ring-inset ring-red-400/30 dark:text-red-400":"text-muted-foreground hover:bg-muted"}`),S(i,"title",m),S(i,"aria-label",v),K(l,1,`flex items-center justify-center px-2 py-1.5 transition-colors
					${e(E)==="unset"?"bg-muted text-foreground":"text-muted-foreground hover:bg-muted"}`),S(l,"title",N),S(l,"aria-label",y)},[()=>e(P)?e(D):g.t("ADMIN_NEXT.ALLOWED"),()=>g.t("ADMIN_NEXT.ALLOWED"),()=>e(C)?e(D):g.t("ADMIN_NEXT.DENIED"),()=>g.t("ADMIN_NEXT.DENIED"),()=>g.t("ADMIN_NEXT.PERMISSIONS_FIELD.NOT_SET"),()=>g.t("ADMIN_NEXT.PERMISSIONS_FIELD.NOT_SET")]),V("click",h,()=>t.onToggle(t.action.name,e(E)==="allowed"?"unset":"allowed")),V("click",i,()=>t.onToggle(t.action.name,e(E)==="denied"?"unset":"denied")),V("click",l,()=>t.onToggle(t.action.name,"unset")),b(q,k),ue()}ce(["click"]);var Pe=R('<div class="flex items-center justify-center py-8"><!></div>'),ke=R('<div class="mb-3 rounded-lg border border-border bg-muted/20 px-4 py-3"><p class="text-xs text-muted-foreground"> </p> <div class="mt-2.5 flex flex-wrap items-center gap-x-5 gap-y-2 text-xs text-muted-foreground"><span class="inline-flex items-center gap-1.5"><span class="inline-flex h-5 w-5 items-center justify-center rounded bg-green-500 text-white"><!></span> </span> <span class="inline-flex items-center gap-1.5"><span class="inline-flex h-5 w-5 items-center justify-center rounded bg-green-500/15 text-green-600 ring-1 ring-inset ring-green-500/30 dark:text-green-400"><!></span> </span> <span class="inline-flex items-center gap-1.5"><!> </span> <span class="inline-flex items-center gap-1.5"><!> </span></div></div>'),Xe=R('<div class="overflow-hidden rounded-lg border border-border"><div class="flex cursor-pointer items-center gap-2 bg-muted/30 px-4 py-2.5"><!> <span class="text-sm font-semibold text-foreground"> </span></div> <!></div>'),je=R('<!> <div class="space-y-3"></div>',1);function tt(q,t){le(t,!0);let E=re(de([])),w=re(!0),u=re(de(new Set));function P(n){return n==="site"?0:n==="api"?1:n==="admin"?3:2}async function C(){F(w,!0);try{const n=await De();F(E,[...n].sort((i,o)=>P(i.name)-P(o.name)),!0);for(const i of e(E))i.name!=="admin"&&e(u).add(i.name);F(u,new Set(e(u)),!0)}catch{Se.error(g.t("ADMIN_NEXT.PERMISSIONS_FIELD.FAILED_TO_LOAD_PERMISSIONS"))}finally{F(w,!1)}}function G(n){return JSON.parse(JSON.stringify(n))}function D(n,i){const o=i.split(".");let l=n;for(const _ of o)if(l&&typeof l=="object")l=l[_];else return;return l}function k(n,i=e(E)){for(const o of i){if(o.name===n)return o;if(o.children){const l=k(n,o.children);if(l)return l}}return null}function A(n){return(k(n)?.children??[]).map(i=>i.name.split(".").pop())}const L=p(()=>!!t.inherited&&Object.keys(t.inherited).length>0),Q=p(()=>D(t.value,"admin.super")===!0),W=p(()=>D(t.value,"api.super")===!0);function H(n,i){const o=n.split("."),l=G(Te(t.value));let _=l;for(let c=0;c<o.length-1;c++){const r=o[c],a=_[r];if(typeof a=="boolean"){const m={};for(const v of A(o.slice(0,c+1).join(".")))m[v]=a;_[r]=m}else(typeof a!="object"||a===null)&&(_[r]={});_=_[r]}const x=o[o.length-1];i==="allowed"?_[x]=!0:i==="denied"?_[x]=!1:delete _[x],t.onchange(ye(l))}function Z(n){e(u).has(n)?e(u).delete(n):e(u).add(n),F(u,new Set(e(u)),!0)}Ne(()=>{C()});var X=ne(),$=z(X);{var U=n=>{var i=Pe(),o=d(i);Le(o,{size:20,class:"animate-spin text-muted-foreground"}),s(i),b(n,i)},h=n=>{var i=je(),o=z(i);{var l=x=>{var c=ke(),r=d(c),a=d(r,!0);s(r);var m=f(r,2),v=d(m),N=d(v),y=d(N);ie(y,{size:12}),s(N);var ee=f(N);s(v);var j=f(v,2),I=d(j),B=d(I);ie(B,{size:12}),s(I);var te=f(I);s(j);var T=f(j,2),J=d(T);me(J,{size:14,class:"text-amber-500"});var ge=f(J);s(T);var se=f(T,2),oe=d(se);fe(oe,{size:14,class:"text-purple-500"});var _e=f(oe);s(se),s(m),s(c),Y((Ee,pe,xe,Ie,he)=>{M(a,Ee),M(ee,` ${pe??""}`),M(te,` ${xe??""}`),M(ge,` ${Ie??""}`),M(_e,` ${he??""}`)},[()=>g.t("ADMIN_NEXT.PERMISSIONS_FIELD.LEGEND_INTRO"),()=>g.t("ADMIN_NEXT.PERMISSIONS_FIELD.LEGEND_DIRECT"),()=>g.t("ADMIN_NEXT.PERMISSIONS_FIELD.LEGEND_INHERITED"),()=>g.t("ADMIN_NEXT.PERMISSIONS_FIELD.LEGEND_OVERRIDE"),()=>g.t("ADMIN_NEXT.PERMISSIONS_FIELD.LEGEND_SUPER")]),b(x,c)};O(o,x=>{e(L)&&x(l)})}var _=f(o,2);ae(_,21,()=>e(E),x=>x.name,(x,c)=>{var r=Xe(),a=d(r),m=d(a);{let I=p(()=>e(u).has(e(c).name)?"":"-rotate-90");Oe(m,{size:14,get class(){return`shrink-0 text-muted-foreground transition-transform ${e(I)??""}`}})}var v=f(m,2),N=d(v,!0);s(v),s(a);var y=f(a,2);{var ee=I=>{var B=ne(),te=z(B);ae(te,17,()=>e(c).children,T=>T.name,(T,J)=>{ve(T,{get action(){return e(J)},depth:0,get value(){return t.value},get superAdmin(){return e(Q)},get apiSuper(){return e(W)},get inherited(){return t.inherited},onToggle:H})}),b(I,B)},j=p(()=>e(u).has(e(c).name)&&e(c).children);O(y,I=>{e(j)&&I(ee)})}s(r),Y(I=>M(N,I),[()=>e(c).name==="admin"?g.t("ADMIN_NEXT.PERMISSIONS_FIELD.ADMIN_LEGACY"):e(c).label]),V("click",a,()=>Z(e(c).name)),b(x,r)}),s(_),b(n,i)};O($,n=>{e(w)?n(U):n(h,-1)})}b(q,X),ue()}ce(["click"]);export{tt as P};
