import"./DsnmJJEf.js";import{p as ie,i as C,m as q,u as de,e as X,f as w,a as _,b as le,j as S,g as e,d as c,r as u,s as b,t as z,h as E,c as I,q as F}from"./BfUaJvxP.js";import{d as ue,s as G,a as O}from"./Bci9YmGs.js";import{i as M}from"./C8yDvkQM.js";import{t as fe,e as R,i as J,b as ce,s as y}from"./CuIpA3jY.js";import{s as A}from"./VWvGCFra.js";import{i as g}from"./CF1ujZlL.js";import{c as ve}from"./zW8yuyTa.js";import{L as me}from"./BeSnoT4y.js";import{C as pe}from"./fmRQoJYL.js";import{C as _e}from"./DZHO7bvc.js";import{B as be,C as ge}from"./DACluBxm.js";import{M as xe}from"./C2b-SQuU.js";var he=I('<div class="flex shrink-0 items-center gap-2"><!> <div class="flex shrink-0 overflow-hidden rounded-md border border-border text-[11px] font-medium"><button type="button"><!></button> <button type="button"><!></button> <button type="button"><!></button></div></div>'),ye=I('<div class="flex items-center justify-between border-t border-border px-4 py-2"><span> </span> <!></div> <!>',1),Ne=I('<div class="flex items-center justify-center py-8"><!></div>'),Se=I('<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>'),Ee=I('<div class="space-y-3"></div>');function ze(K,D){ie(D,!0);const H=(t,s=F)=>{const r=E(()=>B(s())),o=E(()=>$(s()));var a=he(),n=c(a);{var m=p=>{ge(p,{size:14,class:"text-purple-500"})};M(n,p=>{e(o)&&p(m)})}var l=b(n,2),f=c(l),N=c(f);_e(N,{size:14}),u(f);var d=b(f,2),x=c(d);be(x,{size:14}),u(d);var i=b(d,2),h=c(i);xe(h,{size:14}),u(i),u(l),u(a),z((p,P,j,ae,oe,ne)=>{A(f,1,`flex items-center justify-center px-2 py-1.5 transition-colors
					${e(r)==="allowed"?"bg-green-500 text-white":"text-muted-foreground hover:bg-muted"}`),y(f,"title",p),y(f,"aria-label",P),A(d,1,`flex items-center justify-center border-x border-border px-2 py-1.5 transition-colors
					${e(r)==="denied"?"bg-red-400 text-white":"text-muted-foreground hover:bg-muted"}`),y(d,"title",j),y(d,"aria-label",ae),A(i,1,`flex items-center justify-center px-2 py-1.5 transition-colors
					${e(r)==="unset"?"bg-muted text-foreground":"text-muted-foreground hover:bg-muted"}`),y(i,"title",oe),y(i,"aria-label",ne)},[()=>g.t("ADMIN_NEXT.ALLOWED"),()=>g.t("ADMIN_NEXT.ALLOWED"),()=>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")]),O("click",f,()=>L(s(),e(r)==="allowed"?"unset":"allowed")),O("click",d,()=>L(s(),e(r)==="denied"?"unset":"denied")),O("click",i,()=>L(s(),"unset")),_(t,a)},W=(t,s=F,r=F)=>{var o=ye(),a=w(o),n=c(a),m=c(n,!0);u(n);var l=b(n,2);H(l,()=>s().name),u(a);var f=b(a,2);{var N=d=>{var x=X(),i=w(x);R(i,17,()=>s().children,J,(h,p)=>{W(h,()=>e(p),()=>r()+1)}),_(d,x)};M(f,d=>{s().children&&d(N)})}z(()=>{ce(a,`padding-left: ${16+r()*24}px`),A(n,1,`text-sm ${r()>0?"text-muted-foreground":"text-foreground"}`),G(m,s().label)}),_(t,o)};let T=C(q([])),k=C(!0),v=C(q(new Set));async function Q(){S(k,!0);try{S(T,await ve(),!0);for(const t of e(T))e(v).add(t.name);S(v,new Set(e(v)),!0)}catch{fe.error(g.t("ADMIN_NEXT.PERMISSIONS_FIELD.FAILED_TO_LOAD_PERMISSIONS"))}finally{S(k,!1)}}function U(t){return JSON.parse(JSON.stringify(t))}function Y(){try{return JSON.parse(JSON.stringify(D.value))}catch{return{}}}function B(t){const s=t.split(".");let r=Y();for(const o of s)if(r&&typeof r=="object")r=r[o];else return"unset";return r===!0?"allowed":r===!1?"denied":"unset"}const Z=E(()=>B("admin.super")==="allowed");function $(t){return!e(Z)||t==="admin.super"?!1:t.startsWith("admin.")||t.startsWith("site.")}function L(t,s){const r=t.split("."),o=U(D.value);let a=o;for(let m=0;m<r.length-1;m++){const l=r[m];(typeof a[l]!="object"||a[l]===null)&&(a[l]={}),a=a[l]}const n=r[r.length-1];s==="allowed"?a[n]=!0:s==="denied"?a[n]=!1:delete a[n],D.onchange(o)}function ee(t){e(v).has(t)?e(v).delete(t):e(v).add(t),S(v,new Set(e(v)),!0)}de(()=>{Q()});var V=X(),te=w(V);{var re=t=>{var s=Ne(),r=c(s);me(r,{size:20,class:"animate-spin text-muted-foreground"}),u(s),_(t,s)},se=t=>{var s=Ee();R(s,21,()=>e(T),J,(r,o)=>{var a=Se(),n=c(a),m=c(n);{let i=E(()=>e(v).has(e(o).name)?"":"-rotate-90");pe(m,{size:14,get class(){return`shrink-0 text-muted-foreground transition-transform ${e(i)??""}`}})}var l=b(m,2),f=c(l,!0);u(l),u(n);var N=b(n,2);{var d=i=>{var h=X(),p=w(h);R(p,17,()=>e(o).children,J,(P,j)=>{W(P,()=>e(j),()=>0)}),_(i,h)},x=E(()=>e(v).has(e(o).name)&&e(o).children);M(N,i=>{e(x)&&i(d)})}u(a),z(()=>G(f,e(o).label)),O("click",n,()=>ee(e(o).name)),_(r,a)}),u(s),_(t,s)};M(te,t=>{e(k)?t(re):t(se,-1)})}_(K,V),le()}ue(["click"]);export{ze as P};
