import"../chunks/DsnmJJEf.js";import{o as Nt}from"../chunks/vrwecVo1.js";import{p as ht,h as g,m as J,e as At,f as W,a as N,b as Ct,i as xt,o as Tt,$ as Et,g as e,j as r,k as O,d as c,s as y,r as f,c as C,t as k}from"../chunks/Dyk1ealw.js";import{e as It,s as M}from"../chunks/DEEYSJdk.js";import{i as U}from"../chunks/cYAxD0tk.js";import{h as Ot,s as z}from"../chunks/BGzpdNMV.js";import{i as u,b as yt}from"../chunks/CVq-Ik9t.js";import"../chunks/DXU0JJLc.js";import{g as St,s as Dt}from"../chunks/qUUXgf4g.js";import{d as bt}from"../chunks/CGX1Ds8Z.js";import{B as Ft}from"../chunks/Dz6ZcA6N.js";import{c as kt}from"../chunks/DfqTMdwm.js";import{a as q,c as Mt,s as Ut,h as Lt,v as jt}from"../chunks/BsWaFq0J.js";import{A as Q}from"../chunks/CSqm5qMx.js";import{B as Gt}from"../chunks/CqOTUmYS.js";import{S as Xt}from"../chunks/LlHyE11H.js";import{U as wt}from"../chunks/3uypKVWt.js";import{t as L}from"../chunks/CDBVw774.js";import{L as Y}from"../chunks/BkBShXgg.js";import{S as Bt}from"../chunks/lqkrpXLb.js";var $t=C('<p class="mt-0.5 text-xs text-muted-foreground"> </p>'),zt=C("<!> ",1),qt=C("<div><div><div><h1> </h1> <!></div> <!></div></div>"),Kt=C('<div class="flex flex-1 items-center justify-center"><!></div>'),Pt=C('<div class="flex-1 overflow-y-auto"><div class="px-6 py-6"><!></div></div>'),Rt=C('<div class="flex flex-1 items-center justify-center text-sm text-muted-foreground"> </div>'),Vt=C('<div class="flex h-full flex-col"><!> <!> <!></div>');function me(Z,tt){ht(tt,!0);const et=O(()=>yt.isSuperAdmin),rt=O(()=>kt("config"));let d=g(null),a=g(J({})),v=g(J({})),j=g("{}"),G=g(""),X=g(!0),E=g(!1),w=g(!1);const K=O(()=>q(e(a))!==e(j));let st=O(()=>!e(d)||!Lt(e(d).fields,e(a)));async function at(){r(X,!0);try{const[t,o]=await Promise.all([St("accounts"),bt().catch(()=>null)]);r(a,t.data??{},!0),r(j,q(e(a)),!0),r(G,t.etag,!0),r(d,o,!0)}catch(t){(t&&typeof t=="object"&&"status"in t?t.status:0)===403?r(w,!0):L.error(u.t("ADMIN_NEXT.ACCOUNTS_CONFIG.FAILED_TO_LOAD"))}finally{r(X,!1)}}function ot(t,o){const h=t.split("."),x={...e(a)};let i=x;for(let T=0;T<h.length-1;T++){const n=h[T];typeof i[n]!="object"||i[n]===null?i[n]={}:i[n]={...i[n]},i=i[n]}i[h[h.length-1]]=o,r(a,x,!0);const S=e(d)?jt(e(d).fields,t,x):null;if(S)r(v,{...e(v),[t]:S},!0);else if(e(v)[t]){const{[t]:T,...n}=e(v);r(v,n,!0)}}async function P(){if(r(v,e(d)?Mt(e(d).fields,e(a)):{},!0),Object.keys(e(v)).length>0){Ut();return}r(E,!0);try{const t=await Dt("accounts",e(a),e(G));r(a,t.data??e(a),!0),r(j,q(e(a)),!0),r(G,t.etag,!0),L.success(u.t("ADMIN_NEXT.ACCOUNTS_CONFIG.SAVED"))}catch(t){(t&&typeof t=="object"&&"status"in t?t.status:0)===409?L.error(u.t("ADMIN_NEXT.ACCOUNTS_CONFIG.MODIFIED_ELSEWHERE")):L.error(u.t("ADMIN_NEXT.ACCOUNTS_CONFIG.FAILED_TO_SAVE"))}finally{r(E,!1)}}function it(t){(t.metaKey||t.ctrlKey)&&t.key==="s"&&(t.preventDefault(),e(K)&&!e(E)&&P())}Nt(()=>{at()});var R=At();Ot("l0fj7g",t=>{xt(o=>{Et.title=o??""},[()=>u.t("ADMIN_NEXT.ACCOUNTS_CONFIG.PAGE_TITLE")])}),It("keydown",Tt,it);var nt=W(R);{var lt=t=>{Q(t,{})},ct=t=>{Q(t,{})},ft=t=>{var o=Vt(),h=c(o);Xt(h,{noBorder:!0,children:(s,m)=>{let _=()=>(m?.()).scrolled;var D=qt(),B=c(D),$=c(B),b=c($),dt=c(b,!0);f(b);var ut=y(b,2);{var vt=A=>{var I=$t(),V=c(I,!0);f(I),k(F=>M(V,F),[()=>u.t("ADMIN_NEXT.ACCOUNTS_CONFIG.SUBTITLE")]),N(A,I)};U(ut,A=>{_()||A(vt)})}f($);var mt=y($,2);{let A=O(()=>!e(K)||e(E)||!e(st)||!e(rt));Gt(mt,{size:"sm",get disabled(){return e(A)},onclick:P,children:(I,V)=>{var F=zt(),H=W(F);{var _t=p=>{Y(p,{size:14,class:"animate-spin"})},pt=p=>{Bt(p,{size:14})};U(H,p=>{e(E)?p(_t):p(pt,-1)})}var gt=y(H);k(p=>M(gt,` ${p??""}`),[()=>u.t("ADMIN_NEXT.SAVE")]),N(I,F)},$$slots:{default:!0}})}f(B),f(D),k(A=>{z(D,1,`px-6 transition-[padding] duration-200 ${_()?"py-2":"pt-6 pb-3"}`),z(B,1,`flex items-center justify-between ${_()?"min-h-6":"min-h-8"}`),z(b,1,`font-semibold tracking-tight text-foreground transition-[font-size] duration-200 ${_()?"text-sm":"text-xl"}`),M(dt,A)},[()=>u.t("ADMIN_NEXT.ACCOUNTS_CONFIG.TITLE")]),N(s,D)},$$slots:{default:!0}});var x=y(h,2);wt(x,{});var i=y(x,2);{var S=l=>{var s=Kt(),m=c(s);Y(m,{size:24,class:"animate-spin text-muted-foreground"}),f(s),N(l,s)},T=l=>{var s=Pt(),m=c(s),_=c(m);Ft(_,{get fields(){return e(d).fields},get data(){return e(a)},onchange:ot,get errors(){return e(v)}}),f(m),f(s),N(l,s)},n=l=>{var s=Rt(),m=c(s,!0);f(s),k(_=>M(m,_),[()=>u.t("ADMIN_NEXT.ACCOUNTS_CONFIG.NO_FIELDS")]),N(l,s)};U(i,l=>{e(X)?l(S):e(d)?l(T,1):l(n,-1)})}f(o),N(t,o)};U(nt,t=>{!e(et)&&!e(w)?t(lt):e(w)?t(ct,1):t(ft,-1)})}N(Z,R),Ct()}export{me as component};
