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