@shumai-one/shumai 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/{chunk-hzr8100w.js → chunk-088e1ath.js} +1 -1
- package/bin/{chunk-myd3wg9a.js → chunk-0e8xg41c.js} +1 -1
- package/bin/{chunk-ghjhyajn.js → chunk-0ttr4a6b.js} +1 -1
- package/bin/{chunk-ty88m3yg.js → chunk-18kgmvme.js} +1 -1
- package/bin/{chunk-h82r29wm.js → chunk-1dt700ws.js} +1 -1
- package/bin/chunk-1ya6vx4k.js +1 -0
- package/bin/{chunk-eez1yncf.js → chunk-3584j9fc.js} +1 -1
- package/bin/{chunk-b9j5575n.js → chunk-3m6ch1x5.js} +1 -1
- package/bin/{chunk-r5rpdhed.js → chunk-4437dnfa.js} +1 -1
- package/bin/{chunk-hz9stgvn.js → chunk-4frhvsy0.js} +1 -1
- package/bin/{chunk-d9btz95y.js → chunk-4mq874m3.js} +1 -1
- package/bin/{chunk-y7jz31ay.js → chunk-57nqvcg7.js} +1 -1
- package/bin/{chunk-jb6d142z.js → chunk-58hdvwj2.js} +1 -1
- package/bin/{chunk-cw8z9w5c.js → chunk-62sj29j8.js} +1 -1
- package/bin/{chunk-13d525jm.js → chunk-6devq6jh.js} +1 -1
- package/bin/{chunk-dz33q4v1.js → chunk-6ns2vhbd.js} +1 -1
- package/bin/{chunk-m9sp00a9.js → chunk-6v6c2921.js} +1 -1
- package/bin/{chunk-y12ah7c6.js → chunk-a5fsqkt7.js} +1 -1
- package/bin/{chunk-12npypek.js → chunk-ar6kq7hh.js} +1 -1
- package/bin/{chunk-35mpp84e.js → chunk-asgxtqf0.js} +1 -1
- package/bin/{chunk-ydk3edsw.js → chunk-c0vbj8za.js} +1 -1
- package/bin/{chunk-fhq5m9ya.js → chunk-c4wnhekn.js} +1 -1
- package/bin/{chunk-dckdnqc0.js → chunk-dcmfn4hs.js} +1 -1
- package/bin/{chunk-6bgbx563.js → chunk-dvkzhpxx.js} +1 -1
- package/bin/chunk-dy79b8kd.js +1 -0
- package/bin/{chunk-mcd7zas7.js → chunk-ehhsezbj.js} +1 -1
- package/bin/{chunk-cgsxyw07.js → chunk-ehvyq65t.js} +1 -1
- package/bin/{chunk-n5v48hz5.js → chunk-g21k2awz.js} +1 -1
- package/bin/chunk-g9f9nzcc.js +1 -0
- package/bin/{chunk-1yt1gsyy.js → chunk-gzzfta3s.js} +1 -1
- package/bin/{chunk-p5v22g5n.js → chunk-kvqp50dm.js} +1 -1
- package/bin/{chunk-fyssg02c.js → chunk-m2dtwvg0.js} +1 -1
- package/bin/{chunk-3btc8a0p.js → chunk-m5cpsm28.js} +1 -1
- package/bin/{chunk-meyvvmgk.js → chunk-nbfcknsq.js} +1 -1
- package/bin/chunk-qcf3tb72.js +1 -0
- package/bin/chunk-rgfh5apb.js +1 -0
- package/bin/{chunk-smcn7ep7.js → chunk-rh1hs8wa.js} +1 -1
- package/bin/{chunk-zbma2zeh.js → chunk-rpxayeqd.js} +1 -1
- package/bin/{chunk-g8h1e1kh.js → chunk-rsdpycdr.js} +1 -1
- package/bin/{chunk-tf8q7h6b.js → chunk-s33pcxn0.js} +1 -1
- package/bin/{chunk-yfe6hkzk.js → chunk-s978ftze.js} +1 -1
- package/bin/{chunk-7wb3dga5.js → chunk-s9svhjv6.js} +1 -1
- package/bin/{chunk-czny5thj.js → chunk-t597y392.js} +1 -1
- package/bin/{chunk-vbbn4hth.js → chunk-tcp4q15p.js} +1 -1
- package/bin/{chunk-51h2bgpf.js → chunk-vre5andt.js} +1 -1
- package/bin/{chunk-dx0wz749.js → chunk-vsefjzzj.js} +3 -3
- package/bin/chunk-wf32n1s3.js +1 -0
- package/bin/{chunk-32japja5.js → chunk-xyh5dkr5.js} +1 -1
- package/bin/{chunk-0tf15vee.js → chunk-xyk7vk42.js} +1 -1
- package/bin/{chunk-qhzat67w.js → chunk-yd1k76na.js} +1 -1
- package/bin/{chunk-n1b3pt17.js → chunk-yfm9xwes.js} +1 -1
- package/bin/{chunk-0vtk7wrf.js → chunk-z7p7s55t.js} +1 -1
- package/bin/{chunk-m7dp8rqv.js → chunk-zf2h3w7t.js} +1 -1
- package/bin/chunk-zkep4r7d.js +1 -0
- package/bin/{chunk-edjtb7pk.js → chunk-zp5b1mb6.js} +1 -1
- package/bin/shumai-app.html +1 -1
- package/bin/shumai-app.js +311 -311
- package/package.json +7 -7
- package/bin/chunk-3ewmtf1c.js +0 -1
- package/bin/chunk-9wk11jtz.js +0 -1
- package/bin/chunk-a1crhhzy.js +0 -1
- package/bin/chunk-dz4fdrmk.js +0 -1
- package/bin/chunk-tvr5rm1g.js +0 -1
- package/bin/chunk-v2x9915x.js +0 -1
- package/bin/chunk-x8hky9td.js +0 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{V,D,h,$e,N,y,u,Ds,S,L,t,o,Q,Z,B,Rc,ze,A,I,xr,zn,Sr,O,Ct,Pe,ve,vt,er,eo,Wo,fi,vo,pe,Ut,we,Yo,Ne,C,fs,E,Ce,Ie,Te,he,ge,Ae,K,Vt,n,Pa,zA,wf,VA,QA,xf,KA,ad,JA,XA,Mm,km,t0,r0,i0,a0,l0,c0,d0,f0,p0,m0,g0,A0,_0,y0,b0,Nm,v0,Dm,w0,Om,x0,Fm,S0,Lm,E0,Zm,C0,Bm,I0,Um,T0,zm,M0,k0,R0,jm,P0,N0,D0,qm,Hm,$m,Gm,O0,F0,j0,q0,V0,Y0,cd,ud,Km,J0,X0,Wm,e_,t_,Ym,r_,Cf,Jm,Xm,n_,s_,dd,c_,u_,d_,h_,x_,S_,E_,C_,th,T_,M_,k_,R_,P_,N_,De,O_,L_,Z_,B_,z_,G_,V_,Q_,K_,oh,Y_,J_,ny,sy,lh,Zc,my,yy,by,vy,xy,Sy,Iy,My,Zy,By,at,Uy,zy,$y,Gy,Vy,Wy,Of,hh,Xy,yl,ob,sb,Lf,ab,lb,_h,fb,yh,pb,mb,Zf,Ab,bh,_b,vh,yb,wb,xb,Eb,Bf,Ib,Mb,wh,Pb,Nb,zs,Jo,Gb,Qb,Eh,Na,_d,Yb,Jb,Ch,rv,zf,Mh,kh,bl,ov,yd,Rh,Ph,av,lv,cv,Nh,fv,pv,wv,xv,Pv,Nv,Dv,Bh,Ov,Fv,Zv,Bv,Uh,Kv,Wv,Yv,Jv,Xv,ew,tw,rw,nw,ow,sw,iw,lw,jh,uw,dw,fw,Aw,_w,yw,bw,vw,ww,Tw,Rw,Lw,Zw,Bw,Uw,ep,zw,jw,$h,qw,Hw,$w,Gw,Vw,Gh,Vh,Qw,Kw,Ww,Yw,Qh,Jw,Kh,Xw,ex,Wh,Hc,xd,tx,rx,Yh,nx,ox,sx,ix,ax,lx,cx,ux,dx,px,mx,tp,rp,bx,vx,wx,eg,xx,Sx,Ex,Cx,Ix,Sd,Tx,kx,Rx,Px,Nx,Ox,wl,Fx,Zx,Bx,Ux,zx,jx,Kx,Wx,eS,ug,tS,fg,pg,Cd,aS,lS,cS,lp,cp,pS,mS,AS,bS,vS,hg,wS,SS,jS,gg,qS,HS,_g,$S,GS,VS,KS,eE,tE,Fa,La,Za,rE,nE,oE,iE,uE,dE,mE,Cg,IE,TE,ME,kE,Tg,Mg,kg,Rg,RE,Pg,Ng,Dg,Og,PE,NE,FE,ZE,Zg,_p,UE,jE,qE,$E,yp,bp,vp,wp,KE,Md,kd,Rd,Pd,Nd,YE,JE,Dd,XE,Od,eC,Fd,tC,xp,Tl,Sp,rC,nC,lC,cC,Ld,Ep,Ml,Gg,Vg,kC,RC,xo,PC,qs,Wg,Rp,Xg,eA,JC,tA,rA,XC,rI,nI,oA,sI,aI,sA,fI,iA,pI,mI,hI,gI,Gc,Dp,lA,TI,MI,cA,kI,RI,PI,NI,DI,OI,FI,LI,ZI,BI,UI,zI,jI,qI,HI,YI,JI,XI,eT,tT,rT,nT,oT,sT,iT,aT,lT,cT,uT,dT,fT,pT,mT,hT,gT,yT,xT,kT,PT,NT,DT,OT,FT,_A,ZT,HT,$T,GT,yA,VT,QT,KT,JT,wA,s1,f1,p1,m1,h1,xA,g1,x1,S1,E1,C1,I1,T1,M1,k1,R1,Je,Xe,et,tt,rt,nt,ot,st,ue,ae,fe,qe,le,It,q,ce,Dt,M,f,te,R,Ve,ro,ru,nu,CA,ou,ia,IA,Hs,TA,Ua,MA,su,So,Eo,Kr,kn,be,ht,gt,At,wi,W,Me,Le,Ze,Be,Ue,ne,vr,lr,Ar,ut,Tt,Mt,Ot,xt,nf}from"./chunk-dx0wz749.js";import{Uo}from"./chunk-edjtb7pk.js";import{Mo,_r}from"./chunk-b9j5575n.js";import{Ql,Kl}from"./chunk-dz33q4v1.js";import{Qs,io,ma,Bo,vn,Wl,Qa,Oi,Yl}from"./chunk-35mpp84e.js";import{Jl}from"./chunk-qhzat67w.js";import{Rn,Pn,Nn,wr,Et,yt}from"./chunk-12npypek.js";import{ha}from"./chunk-ghjhyajn.js";import{Io}from"./chunk-eez1yncf.js";import{To}from"./chunk-7wb3dga5.js";import{Vn,ao}from"./chunk-3btc8a0p.js";import{fr}from"./chunk-6bgbx563.js";import{lo}from"./chunk-d9btz95y.js";import{dn}from"./chunk-czny5thj.js";import{co}from"./chunk-80qz30dc.js";import{Nr}from"./chunk-r5rpdhed.js";var Js=[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8",key:"7n84p3"}]],Ya=I("at-sign",Js);var tr=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M7 3v18",key:"bbkbws"}],["path",{d:"M3 7.5h4",key:"zfgn84"}],["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 16.5h4",key:"1230mu"}],["path",{d:"M17 3v18",key:"in4fa5"}],["path",{d:"M17 7.5h4",key:"myr1c1"}],["path",{d:"M17 16.5h4",key:"go4c1d"}]],Ja=I("film",tr);var ar=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]],ca=I("globe",ar);var sr=[["path",{d:"m2 21 9.6-9.6",key:"9l79m3"}],["path",{d:"m7.5 15.5 2.3 2.3a1 1 0 0 1 0 1.4l-2.1 2.1a1 1 0 0 1-1.4 0L4 19",key:"fw8biw"}],["circle",{cx:"15.5",cy:"7.5",r:"5.5",key:"4wxmhb"}]],Xt=I("key",sr);var rr=[["rect",{width:"7",height:"9",x:"3",y:"3",rx:"1",key:"10lvy0"}],["rect",{width:"7",height:"5",x:"14",y:"3",rx:"1",key:"16une8"}],["rect",{width:"7",height:"9",x:"14",y:"12",rx:"1",key:"1hutg5"}],["rect",{width:"7",height:"5",x:"3",y:"16",rx:"1",key:"ldoo1y"}]],Ma=I("layout-dashboard",rr);var or=[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]],es=I("maximize-2",or);var ir=[["path",{d:"M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719",key:"1sd12s"}]],ts=I("message-circle",ir);var nr=[["path",{d:"M12 2v20",key:"t6zp3m"}],["path",{d:"m15 19-3 3-3-3",key:"11eu04"}],["path",{d:"m19 9 3 3-3 3",key:"1mg7y2"}],["path",{d:"M2 12h20",key:"9i4pu4"}],["path",{d:"m5 9-3 3 3 3",key:"j64kie"}],["path",{d:"m9 5 3-3 3 3",key:"l8vdw6"}]],as=I("move",nr);var dr=[["path",{d:"M15.39 4.39a1 1 0 0 0 1.68-.474 2.5 2.5 0 1 1 3.014 3.015 1 1 0 0 0-.474 1.68l1.683 1.682a2.414 2.414 0 0 1 0 3.414L19.61 15.39a1 1 0 0 1-1.68-.474 2.5 2.5 0 1 0-3.014 3.015 1 1 0 0 1 .474 1.68l-1.683 1.682a2.414 2.414 0 0 1-3.414 0L8.61 19.61a1 1 0 0 0-1.68.474 2.5 2.5 0 1 1-3.014-3.015 1 1 0 0 0 .474-1.68l-1.683-1.682a2.414 2.414 0 0 1 0-3.414L4.39 8.61a1 1 0 0 1 1.68.474 2.5 2.5 0 1 0 3.014-3.015 1 1 0 0 1-.474-1.68l1.683-1.682a2.414 2.414 0 0 1 3.414 0z",key:"w46dr5"}]],Nt=I("puzzle",dr);var cr=[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]],ua=I("refresh-cw",cr);var mr=[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]],ss=I("send",mr);var ur=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],rs=I("shield-check",ur);var pr=[["path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5",key:"ftymec"}],["rect",{x:"2",y:"6",width:"14",height:"12",rx:"2",key:"158x01"}]],pa=I("video",pr);var gr=[["path",{d:"M15.914 4a1.5 1.5 0 00-2.474-1.561l-9 9A1.5 1.5 0 005.5 14h4.002a.5.5 0 01.471.666L8.086 20a1.5 1.5 0 002.475 1.56l9-9A1.5 1.5 0 0018.5 10h-3.997a.5.5 0 01-.472-.667z",key:"1v7up4"}]],qt=I("zap",gr);var hr=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"11",x2:"11",y1:"8",y2:"14",key:"1vmskp"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],os=I("zoom-in",hr);var br=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],is=I("zoom-out",br);S();S();var yr=fs("group/field flex w-full gap-3 data-[invalid=true]:text-destructive",{variants:{orientation:{vertical:["flex-col [&>*]:w-full [&>.sr-only]:w-auto"],horizontal:["flex-row items-center","[&>[data-slot=field-label]]:flex-auto","has-[>[data-slot=field-content]]:items-start has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px"],responsive:["flex-col @md/field-group:flex-row @md/field-group:items-center [&>*]:w-full @md/field-group:[&>*]:w-auto [&>.sr-only]:w-auto","@md/field-group:[&>[data-slot=field-label]]:flex-auto","@md/field-group:has-[>[data-slot=field-content]]:items-start @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px"]}},defaultVariants:{orientation:"vertical"}});function Oe({className:e,orientation:r="vertical",...a}){return t("div",{role:"group","data-slot":"field","data-orientation":r,className:C(yr({orientation:r}),e),...a})}function Qe({className:e,...r}){return t(W,{"data-slot":"field-label",className:C("group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50","has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col has-[>[data-slot=field]]:rounded-md has-[>[data-slot=field]]:border [&>*]:data-[slot=field]:p-4","has-data-[state=checked]:border-primary has-data-[state=checked]:bg-primary/5 dark:has-data-[state=checked]:bg-primary/10",e),...r})}function aa({className:e,...r}){return t("p",{"data-slot":"field-description",className:C("text-sm leading-normal font-normal text-muted-foreground group-has-[[data-orientation=horizontal]]/field:text-balance","last:mt-0 nth-last-2:-mt-1 [[data-variant=legend]+&]:-mt-1.5","[&>a]:underline [&>a]:underline-offset-4 [&>a:hover]:text-primary",e),...r})}function We({className:e,children:r,errors:a,...l}){let s=N(()=>{if(r)return r;if(!a?.length)return null;let d=[...new Map(a.map((c)=>[c?.message,c])).values()];if(d?.length==1)return d[0]?.message;return t("ul",{className:"ml-4 flex list-disc flex-col gap-1",children:d.map((c,g)=>c?.message&&t("li",{children:c.message},g))})},[r,a]);if(!s)return null;return t("div",{role:"alert","data-slot":"field-error",className:C("text-sm font-normal text-destructive",e),...l,children:s})}function ns({update:e,notify:r,unwatched:a}){return{link:l,unlink:s,propagate:d,checkDirty:c,shallowPropagate:g};function l(p,b,x){let m=b.depsTail;if(m!==void 0&&m.dep===p)return;let i=m!==void 0?m.nextDep:b.deps;if(i!==void 0&&i.dep===p){i.version=x,b.depsTail=i;return}let v=p.subsTail;if(v!==void 0&&v.version===x&&v.sub===b)return;let w=b.depsTail=p.subsTail={version:x,dep:p,sub:b,prevDep:m,nextDep:i,prevSub:v,nextSub:void 0};if(i!==void 0)i.prevDep=w;if(m!==void 0)m.nextDep=w;else b.deps=w;if(v!==void 0)v.nextSub=w;else p.subs=w}function s(p,b=p.sub){let{dep:x,prevDep:m,nextDep:i,nextSub:v,prevSub:w}=p;if(i!==void 0)i.prevDep=m;else b.depsTail=m;if(m!==void 0)m.nextDep=i;else b.deps=i;if(v!==void 0)v.prevSub=w;else x.subsTail=w;if(w!==void 0)w.nextSub=v;else if((x.subs=v)===void 0)a(x);return i}function d(p){let b=p.nextSub,x;e:do{let m=p.sub,i=m.flags;if(!(i&60))m.flags=i|32;else if(!(i&12))i=0;else if(!(i&4))m.flags=i&-9|32;else if(!(i&48)&&_(p,m))m.flags=i|40,i&=1;else i=0;if(i&2)r(m);if(i&1){let v=m.subs;if(v!==void 0){let w=(p=v).nextSub;if(w!==void 0)x={value:b,prev:x},b=w;continue}}if((p=b)!==void 0){b=p.nextSub;continue}while(x!==void 0)if(p=x.value,x=x.prev,p!==void 0){b=p.nextSub;continue e}break}while(!0)}function c(p,b){let x,m=0,i=!1;e:do{let v=p.dep,w=v.flags;if(b.flags&16)i=!0;else if((w&17)===17){if(e(v)){let k=v.subs;if(k.nextSub!==void 0)g(k);i=!0}}else if((w&33)===33){if(p.nextSub!==void 0||p.prevSub!==void 0)x={value:p,prev:x};p=v.deps,b=v,++m;continue}if(!i){let k=p.nextDep;if(k!==void 0){p=k;continue}}while(m--){let k=b.subs,z=k.nextSub!==void 0;if(z)p=x.value,x=x.prev;else p=k;if(i){if(e(b)){if(z)g(k);b=p.sub;continue}i=!1}else b.flags&=-33;b=p.sub;let J=p.nextDep;if(J!==void 0){p=J;continue e}}return i}while(!0)}function g(p){do{let b=p.sub,x=b.flags;if((x&48)===32){if(b.flags=x|16,(x&6)===2)r(b)}}while((p=p.nextSub)!==void 0)}function _(p,b){let x=b.depsTail;while(x!==void 0){if(x===p)return!0;x=x.prevDep}return!1}}function sa(e,r,a){let l=typeof e==="object",s=l?e:void 0;return{next:(l?e.next:e)?.bind(s),error:(l?e.error:r)?.bind(s),complete:(l?e.complete:a)?.bind(s)}}var Da=[],ga=0,{link:ls,unlink:Cr,propagate:kr,checkDirty:cs,shallowPropagate:ds}=ns({update(e){return e._update()},notify(e){Da[Aa++]=e,e.flags&=-3},unwatched(e){if(e.depsTail!==void 0)e.depsTail=void 0,e.flags=17,va(e)}}),fa=0,Aa=0,St,Ia=0;function Ge(e){try{++Ia,e()}finally{if(!--Ia)Ta()}}function va(e){let r=e.depsTail,a=r!==void 0?r.nextDep:e.deps;while(a!==void 0)a=Cr(a,e)}function Ta(){if(Ia>0)return;while(fa<Aa){let e=Da[fa];Da[fa++]=void 0,e.notify()}fa=0,Aa=0}function ba(e,r){let a=typeof e==="function",l=e,s={_snapshot:a?void 0:e,subs:void 0,subsTail:void 0,deps:void 0,depsTail:void 0,flags:a?0:1,get(){if(St!==void 0)ls(s,St,ga);return s._snapshot},subscribe(d){let c=sa(d),g={current:!1},_=Mr(()=>{if(s.get(),!g.current)g.current=!0;else c.next?.(s._snapshot)});return{unsubscribe:()=>{_.stop()}}},_update(d){let c=St,g=r?.compare??Object.is;if(a)St=s,++ga,s.depsTail=void 0;else if(d===void 0)return!1;if(a)s.flags=5;try{let _=s._snapshot,p=typeof d==="function"?d(_):d===void 0&&a?l(_):d;if(_===void 0||!g(_,p))return s._snapshot=p,!0;return!1}finally{if(St=c,a)s.flags&=-5;va(s)}}};if(a)s.flags=17,s.get=function(){let d=s.flags;if(d&16||d&32&&cs(s.deps,s)){if(s._update()){let c=s.subs;if(c!==void 0)ds(c)}}else if(d&32)s.flags=d&-33;if(St!==void 0)ls(s,St,ga);return s._snapshot};else s.set=function(d){if(s._update(d)){let c=s.subs;if(c!==void 0)kr(c),ds(c),Ta()}};return s}function Mr(e){let r=()=>{let l=St;St=a,++ga,a.depsTail=void 0,a.flags=6;try{return e()}finally{St=l,a.flags&=-5,va(a)}},a={deps:void 0,depsTail:void 0,subs:void 0,subsTail:void 0,flags:6,notify(){let l=this.flags;if(l&16||l&32&&cs(this.deps,this))r();else this.flags=2},stop(){this.flags=0,this.depsTail=void 0,va(this)}};return r(),a}var Ea=class{constructor(e,r){if(this.atom=ba(e),this.get=this.get.bind(this),this.setState=this.setState.bind(this),this.subscribe=this.subscribe.bind(this),r)this.actions=r(this)}setState(e){this.atom.set(e)}get state(){return this.atom.get()}get(){return this.state}subscribe(e){return this.atom.subscribe(sa(e))}},ms=class{constructor(e){this.atom=ba(e)}get state(){return this.atom.get()}get(){return this.state}subscribe(e){return this.atom.subscribe(sa(e))}};function kt(e,r){if(typeof e==="function")return new ms(e);if(r)return new Ea(e,r);return new Ea(e)}var us=class{constructor(e,r){if(this.fn=e,this.options=r,this.lastExecutionTime=0,this.isPending=!1,this.maybeExecute=(...a)=>{let l=Date.now()-this.lastExecutionTime;if(this.options.leading&&l>=this.options.wait)this.execute(...a);else if(this.lastArgs=a,!this.timeoutId&&this.options.trailing){let s=this.options.wait-l;this.isPending=!0,this.timeoutId=setTimeout(()=>{if(this.lastArgs!==void 0)this.execute(...this.lastArgs)},s)}},this.execute=(...a)=>{this.fn(...a),this.options.onExecute?.(a,this),this.lastExecutionTime=Date.now(),this.clearTimeout(),this.lastArgs=void 0,this.isPending=!1},this.flush=()=>{if(this.isPending&&this.lastArgs)this.execute(...this.lastArgs)},this.cancel=()=>{this.clearTimeout(),this.lastArgs=void 0,this.isPending=!1},this.clearTimeout=()=>{if(this.timeoutId)clearTimeout(this.timeoutId),this.timeoutId=void 0},this.options.leading===void 0&&this.options.trailing===void 0)this.options.leading=!0,this.options.trailing=!0}};function Va(e,r){return new us(e,r).maybeExecute}var Ra=class{#o=!0;#t;#e;#m;#a;#n;#s;#l;#u=0;#f=5;#i=!1;#d=!1;#r=null;#p=()=>{this.debugLog("Connected to event bus"),this.#n=!0,this.#i=!1,this.debugLog("Emitting queued events",this.#a),this.#a.forEach((e)=>this.emitEventToBus(e)),this.#a=[],this.stopConnectLoop(),this.#e().removeEventListener("tanstack-connect-success",this.#p)};#c=()=>{if(this.#u<this.#f){this.#u++,this.dispatchCustomEvent("tanstack-connect",{});return}this.#e().removeEventListener("tanstack-connect",this.#c),this.#d=!0,this.debugLog("Max retries reached, giving up on connection"),this.stopConnectLoop()};#g=()=>{if(this.#i)return;this.#i=!0,this.#e().addEventListener("tanstack-connect-success",this.#p),this.#c()};constructor({pluginId:e,debug:r=!1,enabled:a=!0,reconnectEveryMs:l=300}){this.#t=e,this.#o=a,this.#e=this.getGlobalTarget,this.#m=r,this.debugLog(" Initializing event subscription for plugin",this.#t),this.#a=[],this.#n=!1,this.#d=!1,this.#s=null,this.#l=l}startConnectLoop(){if(this.#s!==null||this.#n)return;this.debugLog(`Starting connect loop (every ${this.#l}ms)`),this.#s=setInterval(this.#c,this.#l)}stopConnectLoop(){if(this.#i=!1,this.#s===null)return;clearInterval(this.#s),this.#s=null,this.#a=[],this.debugLog("Stopped connect loop")}debugLog(...e){if(this.#m)console.log(`\uD83C\uDF34 [tanstack-devtools:${this.#t}-plugin]`,...e)}getGlobalTarget(){if(typeof globalThis<"u"&&globalThis.__TANSTACK_EVENT_TARGET__)return this.debugLog("Using global event target"),globalThis.__TANSTACK_EVENT_TARGET__;if(typeof window<"u"&&typeof window.addEventListener<"u")return this.debugLog("Using window as event target"),window;let e=typeof EventTarget<"u"?new EventTarget:void 0;if(typeof e>"u"||typeof e.addEventListener>"u")return this.debugLog("No event mechanism available, running in non-web environment"),{addEventListener:()=>{},removeEventListener:()=>{},dispatchEvent:()=>!1};return this.debugLog("Using new EventTarget as fallback"),e}getPluginId(){return this.#t}dispatchCustomEventShim(e,r){try{let a=new Event(e,{detail:r});this.#e().dispatchEvent(a)}catch(a){this.debugLog("Failed to dispatch shim event")}}dispatchCustomEvent(e,r){try{this.#e().dispatchEvent(new CustomEvent(e,{detail:r}))}catch(a){this.dispatchCustomEventShim(e,r)}}emitEventToBus(e){this.debugLog("Emitting event to client bus",e),this.dispatchCustomEvent("tanstack-dispatch-event",e)}createEventPayload(e,r){return{type:`${this.#t}:${e}`,payload:r,pluginId:this.#t}}emit(e,r){if(!this.#o){this.debugLog("Event bus client is disabled, not emitting event",e,r);return}if(this.#r)this.debugLog("Emitting event to internal event target",e,r),this.#r.dispatchEvent(new CustomEvent(`${this.#t}:${e}`,{detail:this.createEventPayload(e,r)}));if(this.#d){this.debugLog("Previously failed to connect, not emitting to bus");return}if(!this.#n){if(this.debugLog("Bus not available, will be pushed as soon as connected"),this.#a.push(this.createEventPayload(e,r)),typeof CustomEvent<"u"&&!this.#i)this.#g(),this.startConnectLoop();return}return this.emitEventToBus(this.createEventPayload(e,r))}on(e,r,a){let l=a?.withEventTarget??!1,s=`${this.#t}:${e}`;if(l){if(!this.#r)this.#r=new EventTarget;this.#r.addEventListener(s,(c)=>{r(c.detail)})}if(!this.#o)return this.debugLog("Event bus client is disabled, not registering event",s),()=>{};let d=(c)=>{this.debugLog("Received event from bus",c.detail),r(c.detail)};return this.#e().addEventListener(s,d),this.debugLog("Registered event to bus",s),()=>{if(l)this.#r?.removeEventListener(s,d);this.#e().removeEventListener(s,d)}}onAll(e){if(!this.#o)return this.debugLog("Event bus client is disabled, not registering event"),()=>{};let r=(a)=>{let l=a.detail;e(l)};return this.#e().addEventListener("tanstack-devtools-global",r),()=>this.#e().removeEventListener("tanstack-devtools-global",r)}onAllPluginEvents(e){if(!this.#o)return this.debugLog("Event bus client is disabled, not registering event"),()=>{};let r=(a)=>{let l=a.detail;if(this.#t&&l.pluginId!==this.#t)return;e(l)};return this.#e().addEventListener("tanstack-devtools-global",r),()=>this.#e().removeEventListener("tanstack-devtools-global",r)}};class ps extends Ra{constructor(){super({pluginId:"form-devtools",reconnectEveryMs:1000})}}var mt=new ps;function Ft(e,r){return typeof e==="function"?e(r):e}function Yt(e,r){return _a(r).reduce((l,s)=>{if(l===null)return null;if(typeof l<"u")return l[s];return},e)}function Gt(e,r,a){let l=_a(r);function s(d){if(!l.length)return Ft(a,d);let c=l.shift();if(typeof c==="string"||typeof c==="number"&&!Array.isArray(d)){if(typeof d==="object"){if(d===null)d={};return{...d,[c]:s(d[c])}}return{[c]:s()}}if(Array.isArray(d)&&typeof c==="number"){let g=d.slice(0,c);return[...g.length?g:Array(c),s(d[c]),...d.slice(c+1)]}return[...Array(c),s()]}return s(e)}function ja(e,r){let a=_a(r);function l(s){if(!s)return;if(a.length===1){let c=a[0];if(Array.isArray(s)&&typeof c==="number")return s.filter((p,b)=>b!==c);let{[c]:g,..._}=s;return _}let d=a.shift();if(typeof d==="string"||typeof d==="number"&&!Array.isArray(s)){if(typeof s==="object")return{...s,[d]:l(s[d])}}if(typeof d==="number"){if(Array.isArray(s)){if(d>=s.length)return s;let c=s.slice(0,d);return[...c.length?c:Array(d),l(s[d]),...s.slice(d+1)]}}throw Error("It seems we have created an infinite loop in deleteBy. ")}return l(e)}var gs=46,Ba=91,qa=93,hs=48,Fr=57;function _a(e){if(Array.isArray(e))return[...e];if(typeof e!=="string")throw Error("Path must be a string.");let r=e.length,a=[],l=r>0&&e.charCodeAt(0)===Ba?1:0,s=!0,d=-1;for(let c=l;c<=r;c++){let g=c<r?e.charCodeAt(c):-1;if(c===r||g===gs||g===Ba||g===qa){let _=c-l;if(_>0){let p=s&&(_===1||e.charCodeAt(l)!==hs),b=e.slice(l,c);if(p){let x=parseInt(b,10);if(_<=15||String(x)===b)a.push(x);else a.push(b)}else a.push(b)}else if(d!==qa&&!(d===-1&&g===qa)&&!(d===g&&(g===gs||g===Ba)))a.push("");l=c+1,s=!0}else if(g<hs||g>Fr)s=!1;d=g}if(!a.length)a.push("");return a}function Oa(e){return!(Array.isArray(e)&&e.length===0)}function Pt(e,r){let a=(l)=>l.validators.filter(Boolean).map((s)=>({cause:s.cause,validate:s.fn}));return r.validationLogic({form:r.form,group:r.group,validators:r.validators,event:{type:e,fieldName:r.fieldName,async:!1},runValidation:a})}function Rt(e,r){let{asyncDebounceMs:a}=r,{onBlurAsyncDebounceMs:l,onChangeAsyncDebounceMs:s,onDynamicAsyncDebounceMs:d}=r.validators||{},c=a??0,g=(_)=>_.validators.filter(Boolean).map((p)=>{let b=p?.cause||e,x=c;switch(b){case"change":x=s??c;break;case"blur":x=l??c;break;case"dynamic":x=d??c;break;case"submit":x=0;break}if(e==="submit")x=0;return{cause:b,validate:p.fn,debounceMs:x}});return r.validationLogic({form:r.form,group:r.group,validators:r.validators,event:{type:e,fieldName:r.fieldName,async:!0},runValidation:g})}var Jt=(e)=>!!e&&typeof e==="object"&&("fields"in e);function pt(e,r){if(Object.is(e,r))return!0;if(typeof e!=="object"||e===null||typeof r!=="object"||r===null)return!1;if(e instanceof Date&&r instanceof Date)return e.getTime()===r.getTime();if(e instanceof Map&&r instanceof Map){if(e.size!==r.size)return!1;for(let[s,d]of e)if(!r.has(s)||!Object.is(d,r.get(s)))return!1;return!0}if(e instanceof Set&&r instanceof Set){if(e.size!==r.size)return!1;for(let s of e)if(!r.has(s))return!1;return!0}let a=Object.keys(e),l=Object.keys(r);if(a.length!==l.length)return!1;if(a.length===0&&!Array.isArray(e)&&!Array.isArray(r)&&(Object.getPrototypeOf(e)!==Object.prototype||Object.getPrototypeOf(r)!==Object.prototype))return!1;for(let s of a)if(!l.includes(s)||!pt(e[s],r[s]))return!1;return!0}var ea=({newFormValidatorError:e,isPreviousErrorFromFormValidator:r,previousErrorValue:a})=>{if(e)return{newErrorValue:e,newSource:"form"};if(r)return{newErrorValue:void 0,newSource:void 0};if(a)return{newErrorValue:a,newSource:"field"};return{newErrorValue:void 0,newSource:void 0}},Wt=({formLevelError:e,fieldLevelError:r})=>{if(r)return{newErrorValue:r,newSource:"field"};if(e)return{newErrorValue:e,newSource:"form"};return{newErrorValue:void 0,newSource:void 0}};function it(e,r){if(e===void 0||e===null)return r;return{...e,...r}}var zt=256,xa=[],ya;while(zt--)xa[zt]=(zt+256).toString(16).substring(1);function ra(){let e=0,r,a="";if(!ya||zt+16>256){ya=Array(256),e=256;while(e--)ya[e]=256*Math.random()|0;e=0,zt=0}for(;e<16;e++){if(r=ya[zt+e],e===6)a+=xa[r&15|64];else if(e===8)a+=xa[r&63|128];else a+=xa[r];if(e&1&&e>1&&e<11)a+="-"}return zt++,a}var $a=Va((e)=>mt.emit("form-state",{id:e.formId,state:e.store.state}),{wait:300});function Ht(e){if(e===null||typeof e!=="object")return e;if(e instanceof Date)return new Date(e.getTime());if(Array.isArray(e)){let a=[];for(let l=0;l<e.length;l++)a[l]=Ht(e[l]);return a}if(e instanceof Map){let a=new Map;return e.forEach((l,s)=>{a.set(s,Ht(l))}),a}if(e instanceof Set){let a=new Set;return e.forEach((l)=>{a.add(Ht(l))}),a}let r={};for(let a in e)if(Object.prototype.hasOwnProperty.call(e,a))r[a]=Ht(e[a]);return r}function _t(e,r){return r===e||r.startsWith(`${e}.`)||r.startsWith(`${e}[`)}var ft=(e)=>{if(!e.validators)return e.runValidation({validators:[],form:e.form});let r=e.event.async,a=r?void 0:{fn:e.validators.onMount,cause:"mount"},l={fn:r?e.validators.onChangeAsync:e.validators.onChange,cause:"change"},s={fn:r?e.validators.onBlurAsync:e.validators.onBlur,cause:"blur"},d={fn:r?e.validators.onSubmitAsync:e.validators.onSubmit,cause:"submit"},c=r?void 0:{fn:()=>{return},cause:"server"};switch(e.event.type){case"mount":return e.runValidation({validators:[a],form:e.form});case"submit":return e.runValidation({validators:[l,s,d,c],form:e.form});case"server":return e.runValidation({validators:[],form:e.form});case"blur":return e.runValidation({validators:[s,c],form:e.form});case"change":return e.runValidation({validators:[l,c],form:e.form});default:throw Error(`Unknown validation event type: ${e.event.type}`)}};function Dr(e,r){let a=new Map;for(let l of e){let s=l.path??[],d=r,c="";for(let g=0;g<s.length;g++){let _=s[g];if(_===void 0)continue;let p=typeof _==="object"?_.key:_,b=Number(p);if(Array.isArray(d)&&!Number.isNaN(b))c+=`[${b}]`;else c+=(g>0?".":"")+String(p);if(typeof d==="object"&&d!==null)d=d[p];else d=void 0}a.set(c,(a.get(c)??[]).concat(l))}return Object.fromEntries(a)}var vs=(e,r)=>{let a=Dr(e,r);return{form:a,fields:a}},Lt={validate({value:e,validationSource:r},a){let l=a["~standard"].validate(e);if(l instanceof Promise)throw Error("async function passed to sync validator");if(!l.issues)return;if(r==="field")return l.issues;return vs(l.issues,e)},async validateAsync({value:e,validationSource:r},a){let l=await a["~standard"].validate(e);if(!l.issues)return;if(r==="field")return l.issues;return vs(l.issues,e)}},ta=(e)=>!!e&&("~standard"in e);var lt={isValidating:!1,isTouched:!1,isBlurred:!1,isDirty:!1,isPristine:!0,isValid:!0,isDefaultValue:!0,errors:[],errorMap:{},errorSourceMap:{},_arrayVersion:0,_pendingValidationsCount:0};function Bt(e){function r(x){let m=e.getFieldMeta(x)??lt;e.setFieldMeta(x,{...m,_arrayVersion:(m._arrayVersion||0)+1})}function a(x,m,i){r(x);let v=g(x,m,"move",i),w=Math.min(m,i),k=Math.max(m,i);for(let J=w;J<=k;J++)v.push(c(x,J));let z=Object.keys(e.fieldInfo).reduce((J,H)=>{if(H.startsWith(c(x,m)))J.set(H,e.getFieldMeta(H));return J},new Map);p(v,m<i?"up":"down"),Object.keys(e.fieldInfo).filter((J)=>J.startsWith(c(x,i))).forEach((J)=>{let H=J.replace(c(x,i),c(x,m)),ie=z.get(H);if(ie)e.setFieldMeta(J,ie)})}function l(x,m){r(x);let i=g(x,m,"remove");p(i,"up")}function s(x,m,i){r(x),g(x,m,"swap",i).forEach((w)=>{if(!w.toString().startsWith(c(x,m)))return;let k=w.toString().replace(c(x,m),c(x,i)),[z,J]=[e.getFieldMeta(w),e.getFieldMeta(k)];if(z)e.setFieldMeta(k,z);if(J)e.setFieldMeta(w,J)})}function d(x,m){r(x);let i=g(x,m,"insert");p(i,"down"),i.forEach((v)=>{if(v.toString().startsWith(c(x,m)))e.setFieldMeta(v,b())})}function c(x,m){return`${x}[${m}]`}function g(x,m,i,v){let w=[c(x,m)];switch(i){case"swap":w.push(c(x,v));break;case"move":{let[k,z]=[Math.min(m,v),Math.max(m,v)];for(let J=k;J<=z;J++)w.push(c(x,J));break}default:{let k=e.getFieldValue(x),z=Array.isArray(k)?k.length:0;for(let J=m+1;J<z;J++)w.push(c(x,J));break}}return Object.keys(e.fieldInfo).filter((k)=>w.some((z)=>k.startsWith(z)))}function _(x,m){return x.replace(/\[(\d+)\]/,(i,v)=>{let w=parseInt(v,10);return`[${m==="up"?w+1:Math.max(0,w-1)}]`})}function p(x,m){(m==="up"?x:[...x].reverse()).forEach((v)=>{let w=_(v.toString(),m),k=e.getFieldMeta(w);if(k)e.setFieldMeta(v,k);else e.setFieldMeta(v,b())})}let b=()=>lt;return{bumpArrayVersion:r,handleArrayMove:a,handleArrayRemove:l,handleArraySwap:s,handleArrayInsert:d}}function Ka(e){return{values:e.values??{},errorMap:e.errorMap??{},fieldMetaBase:e.fieldMetaBase??{},formGroupStateBase:e.formGroupStateBase??{},isSubmitted:e.isSubmitted??!1,isSubmitting:e.isSubmitting??!1,isValidating:e.isValidating??!1,submissionAttempts:e.submissionAttempts??0,isSubmitSuccessful:e.isSubmitSuccessful??!1,validationMetaMap:e.validationMetaMap??{onChange:void 0,onBlur:void 0,onSubmit:void 0,onMount:void 0,onServer:void 0,onDynamic:void 0}}}class na{constructor(e){this.options={},this.fieldInfo={},this.formGroupApis=new Set,this.mount=()=>{let s=this.store.subscribe(()=>{$a(this)}),d=mt.on("request-form-state",(b)=>{if(b.payload.id===this._formId)mt.emit("form-api",{id:this._formId,state:this.store.state,options:this.options})}),c=mt.on("request-form-reset",(b)=>{if(b.payload.id===this._formId)this.reset()}),g=mt.on("request-form-force-submit",(b)=>{if(b.payload.id===this._formId)this._devtoolsSubmissionOverride=!0,this.handleSubmit(),this._devtoolsSubmissionOverride=!1}),_=()=>{g(),c(),d(),s.unsubscribe(),mt.emit("form-unmounted",{id:this._formId})};this.options.listeners?.onMount?.({formApi:this});let{onMount:p}=this.options.validators||{};if(mt.emit("form-api",{id:this._formId,state:this.store.state,options:this.options}),!p)return _;return this.validateSync("mount"),_},this.update=(s)=>{if(!s)return;let d=this.options;this.options=s;let c=s.defaultValues&&!pt(s.defaultValues,d.defaultValues)&&!this.state.isTouched,g=!pt(s.defaultState,d.defaultState)&&!this.state.isTouched;if(!c&&!g)return;if(Ge(()=>{this.baseStore.setState(()=>Ka(Object.assign({},this.state,g?s.defaultState:{},c?{values:s.defaultValues}:{})))}),c){let _=Bt(this);for(let p of Object.keys(this.fieldInfo))if(Array.isArray(this.getFieldValue(p)))_.bumpArrayVersion(p)}mt.emit("form-api",{id:this._formId,state:this.store.state,options:this.options})},this.reset=(s,d)=>{let{fieldMeta:c}=this.state,g=this.resetFieldMeta(c);if(s&&!d?.keepDefaultValues)this.options={...this.options,defaultValues:s};this.baseStore.setState(()=>{let _=s??this.options.defaultValues??this.options.defaultState?.values;if(!s)Object.values(this.fieldInfo).forEach((p)=>{if(p.instance&&p.instance.options.defaultValue!==void 0)_=Gt(_,p.instance.name,p.instance.options.defaultValue)});return Ka({...this.options.defaultState,values:_,fieldMetaBase:g})})},this.validateAllFields=async(s)=>{let d=[];return Ge(()=>{Object.values(this.fieldInfo).forEach((g)=>{if(!g.instance)return;let _=g.instance;if(d.push(Promise.resolve().then(()=>_.validate(s,{skipFormValidation:!0,skipGroupValidation:!0}))),!g.instance.store.state.meta.isTouched)g.instance.setMeta((p)=>({...p,isTouched:!0}))})}),(await Promise.all(d)).flat()},this.validateArrayFieldsStartingFrom=async(s,d,c)=>{let g=this.getFieldValue(s),_=Array.isArray(g)?Math.max(g.length-1,0):null,p=[`${s}[${d}]`];for(let i=d+1;i<=(_??0);i++)p.push(`${s}[${i}]`);let b=Object.keys(this.fieldInfo).filter((i)=>p.some((v)=>i.startsWith(v))),x=[];return Ge(()=>{b.forEach((i)=>{x.push(Promise.resolve().then(()=>this.validateField(i,c)))})}),(await Promise.all(x)).flat()},this.validateField=(s,d)=>{let c=this.fieldInfo[s]?.instance;if(!c){let{hasErrored:g}=this.validateSync(d);if(g&&!this.options.asyncAlways)return this.getFieldMeta(s)?.errors??[];return this.validateAsync(d).then(()=>this.getFieldMeta(s)?.errors??[])}if(!c.store.state.meta.isTouched)c.setMeta((g)=>({...g,isTouched:!0}));return c.validate(d)},this.validateSync=(s,d)=>{let c=Pt(s,{...this.options,form:this,group:d?.group,validationLogic:this.options.validationLogic||ft}),g=!1,_={};return Ge(()=>{for(let x of c){if(!x.validate)continue;let m=this.runValidator({validate:x.validate,value:{value:this.state.values,formApi:this,validationSource:"form"},type:"validate"}),{formError:i,fieldErrors:v}=wa(m),w=oa(x.cause),k=new Set([...Object.keys(this.state.fieldMeta),...Object.keys(v||{})]);if(d?.filterFieldNames)k=new Set([...k].filter(d.filterFieldNames));for(let z of k){if(this.baseStore.state.fieldMetaBase[z]===void 0&&!v?.[z])continue;let J=this.getFieldMeta(z)??lt,{errorMap:H,errorSourceMap:ie}=J,oe=v?.[z],{newErrorValue:T,newSource:P}=ea({newFormValidatorError:oe,isPreviousErrorFromFormValidator:ie?.[w]==="form",previousErrorValue:H?.[w]});if(P==="form")_[z]={..._[z],[w]:oe};if(H?.[w]!==T)this.setFieldMeta(z,(j=lt)=>({...j,errorMap:{...j.errorMap,[w]:T},errorSourceMap:{...j.errorSourceMap,[w]:P}}))}if(!d?.dontUpdateFormErrorMap){if(this.state.errorMap?.[w]!==i)this.baseStore.setState((z)=>({...z,errorMap:{...z.errorMap,[w]:i}}))}if(i||v)g=!0}if(d?.dontUpdateFormErrorMap)return;let p=oa("submit");if(this.state.errorMap?.[p]&&s!=="submit"&&!g)this.baseStore.setState((x)=>({...x,errorMap:{...x.errorMap,[p]:void 0}}));let b=oa("server");if(this.state.errorMap?.[b]&&s!=="server"&&!g)this.baseStore.setState((x)=>({...x,errorMap:{...x.errorMap,[b]:void 0}}))}),{hasErrored:g,fieldsErrorMap:_}},this.validateAsync=async(s,d)=>{let c=Rt(s,{...this.options,form:this,group:d?.group,validationLogic:this.options.validationLogic||ft});if(!this.state.isFormValidating)this.baseStore.setState((x)=>({...x,isFormValidating:!0}));let g=[],_;for(let x of c){if(!x.validate)continue;let m=oa(x.cause);this.state.validationMetaMap[m]?.lastAbortController.abort();let v=new AbortController;this.state.validationMetaMap[m]={lastAbortController:v},g.push(new Promise(async(w)=>{let k;try{k=await new Promise((T,P)=>{setTimeout(async()=>{if(v.signal.aborted)return T(void 0);try{T(await this.runValidator({validate:x.validate,value:{value:this.state.values,formApi:this,validationSource:"form",signal:v.signal},type:"validateAsync"}))}catch(j){P(j)}},x.debounceMs)})}catch(T){k=T}let{formError:z,fieldErrors:J}=wa(k);if(J)_=_?{..._,...J}:J;let H=oa(x.cause),ie=new Set([...Object.keys(this.state.fieldMeta),...Object.keys(_||{})]),oe=Array.from(ie);if(d?.filterFieldNames)oe=oe.filter(d.filterFieldNames);for(let T of oe){if(this.baseStore.state.fieldMetaBase[T]===void 0&&!_?.[T])continue;let P=this.getFieldMeta(T)??lt,{errorMap:j,errorSourceMap:X}=P,F=_?.[T],{newErrorValue:Y,newSource:ye}=ea({newFormValidatorError:F,isPreviousErrorFromFormValidator:X?.[H]==="form",previousErrorValue:j?.[H]});if(j?.[H]!==Y)this.setFieldMeta(T,(me=lt)=>({...me,errorMap:{...me.errorMap,[H]:Y},errorSourceMap:{...me.errorSourceMap,[H]:ye}}))}if(!d?.dontUpdateFormErrorMap)this.baseStore.setState((T)=>({...T,errorMap:{...T.errorMap,[H]:z}}));w(_?{fieldErrors:_,errorMapKey:H}:void 0)}))}let p=[],b={};if(g.length){p=await Promise.all(g);for(let x of p)if(x?.fieldErrors){let{errorMapKey:m}=x;for(let[i,v]of Object.entries(x.fieldErrors)){let k={...b[i]||{},[m]:v};b[i]=k}}}return this.baseStore.setState((x)=>({...x,isFormValidating:!1})),b},this.validate=(s,d)=>{let{hasErrored:c,fieldsErrorMap:g}=this.validateSync(s,d);if(c&&!this.options.asyncAlways)return g;return this.validateAsync(s,d)},this._handleSubmit=async(s)=>{this.baseStore.setState((g)=>({...g,isSubmitted:!1,submissionAttempts:g.submissionAttempts+1,isSubmitSuccessful:!1})),Ge(()=>{Object.values(this.fieldInfo).forEach((g)=>{if(!g.instance)return;if(!g.instance.store.state.meta.isTouched)g.instance.setMeta((_)=>({..._,isTouched:!0}))})});let d=s??this.options.onSubmitMeta;if(!this.state.canSubmit&&!this._devtoolsSubmissionOverride){if(this.baseStore.state.submissionAttempts<=1){this.options.onSubmitInvalid?.({value:this.state.values,formApi:this,meta:d});return}}this.baseStore.setState((g)=>({...g,isSubmitting:!0}));let c=()=>{this.baseStore.setState((g)=>({...g,isSubmitting:!1}))};if(await this.validateAllFields("submit"),!this.state.isFieldsValid){c(),this.options.onSubmitInvalid?.({value:this.state.values,formApi:this,meta:d}),mt.emit("form-submission",{id:this._formId,submissionAttempt:this.state.submissionAttempts,successful:!1,stage:"validateAllFields",errors:Object.values(this.state.fieldMeta).map((g)=>g.errors).flat()});return}if(await this.validate("submit"),!this.state.isValid){c(),this.options.onSubmitInvalid?.({value:this.state.values,formApi:this,meta:d}),mt.emit("form-submission",{id:this._formId,submissionAttempt:this.state.submissionAttempts,successful:!1,stage:"validate",errors:this.state.errors});return}Ge(()=>{Object.values(this.fieldInfo).forEach((g)=>{g.instance?.triggerOnSubmitListener()})}),this.options.listeners?.onSubmit?.({formApi:this,meta:d});try{await this.options.onSubmit?.({value:this.state.values,formApi:this,meta:d}),Ge(()=>{this.baseStore.setState((g)=>({...g,isSubmitted:!0,isSubmitSuccessful:!0})),mt.emit("form-submission",{id:this._formId,submissionAttempt:this.state.submissionAttempts,successful:!0}),c()})}catch(g){throw this.baseStore.setState((_)=>({..._,isSubmitSuccessful:!1})),mt.emit("form-submission",{id:this._formId,submissionAttempt:this.state.submissionAttempts,successful:!1,stage:"inflight",onError:g}),c(),g}},this.getFieldValue=(s)=>Yt(this.state.values,s),this.getFieldMeta=(s)=>this.state.fieldMeta[s],this.getFormGroupMeta=(s)=>this.formGroupMetaDerived.state[s],this.getFieldInfo=(s)=>this.fieldInfo[s]||={instance:null,validationMetaMap:{onChange:void 0,onBlur:void 0,onSubmit:void 0,onMount:void 0,onServer:void 0,onDynamic:void 0}},this.setFieldMeta=(s,d)=>{this.baseStore.setState((c)=>({...c,fieldMetaBase:{...c.fieldMetaBase,[s]:Ft(d,c.fieldMetaBase[s])}}))},this.resetFieldMeta=(s)=>Object.keys(s).reduce((d,c)=>{let g=c;return d[g]=lt,d},{}),this.setFieldValue=(s,d,c)=>{let g=c?.dontUpdateMeta??!1,_=c?.dontRunListeners??!1,p=c?.dontValidate??!1;if(Ge(()=>{if(!g)this.setFieldMeta(s,(b)=>({...b,isTouched:!0,isDirty:!0,errorMap:{...b?.errorMap,onMount:void 0}}));this.baseStore.setState((b)=>({...b,values:Gt(b.values,s,d)}))}),!_)this.getFieldInfo(s).instance?.triggerOnChangeListener();if(!p)this.validateField(s,"change")},this.deleteField=(s)=>{let c=[...Object.keys(this.fieldInfo).filter((g)=>{let _=s.toString();return g.startsWith(`${_}.`)||g.startsWith(`${_}[`)}),s];this.baseStore.setState((g)=>{let _={...g};return c.forEach((p)=>{_.values=ja(_.values,p),delete this.fieldInfo[p],delete _.fieldMetaBase[p]}),_})},this.pushFieldValue=(s,d,c)=>{this.setFieldValue(s,(g)=>[...Array.isArray(g)?g:[],d],c),Bt(this).bumpArrayVersion(s)},this.insertFieldValue=async(s,d,c,g)=>{this.setFieldValue(s,(p)=>[...p.slice(0,d),c,...p.slice(d)],it(g,{dontValidate:!0}));let _=g?.dontValidate??!1;if(!_)await this.validateField(s,"change");if(Bt(this).handleArrayInsert(s,d),!_)await this.validateArrayFieldsStartingFrom(s,d,"change")},this.replaceFieldValue=async(s,d,c,g)=>{if(this.setFieldValue(s,(p)=>p.map((b,x)=>x===d?c:b),it(g,{dontValidate:!0})),Bt(this).bumpArrayVersion(s),!(g?.dontValidate??!1))await this.validateField(s,"change"),await this.validateArrayFieldsStartingFrom(s,d,"change")},this.removeFieldValue=async(s,d,c)=>{let g=this.getFieldValue(s),_=Array.isArray(g)?Math.max(g.length-1,0):null;if(this.setFieldValue(s,(b)=>b.filter((x,m)=>m!==d),it(c,{dontValidate:!0})),Bt(this).handleArrayRemove(s,d),_!==null){let b=`${s}[${_}]`;this.deleteField(b)}if(!(c?.dontValidate??!1))await this.validateField(s,"change"),await this.validateArrayFieldsStartingFrom(s,d,"change")},this.swapFieldValues=(s,d,c,g)=>{if(this.setFieldValue(s,(p)=>{let b=p[d],x=p[c];return Gt(Gt(p,`${d}`,x),`${c}`,b)},it(g,{dontValidate:!0})),Bt(this).handleArraySwap(s,d,c),!(g?.dontValidate??!1))this.validateField(s,"change"),this.validateField(`${s}[${d}]`,"change"),this.validateField(`${s}[${c}]`,"change")},this.moveFieldValues=(s,d,c,g)=>{if(this.setFieldValue(s,(p)=>{let b=[...p];return b.splice(c,0,b.splice(d,1)[0]),b},it(g,{dontValidate:!0})),Bt(this).handleArrayMove(s,d,c),!(g?.dontValidate??!1))this.validateField(s,"change"),this.validateField(`${s}[${d}]`,"change"),this.validateField(`${s}[${c}]`,"change")},this.clearFieldValues=(s,d)=>{let c=this.getFieldValue(s),g=Array.isArray(c)?Math.max(c.length-1,0):null;if(this.setFieldValue(s,[],it(d,{dontValidate:!0})),Bt(this).bumpArrayVersion(s),g!==null)for(let p=0;p<=g;p++){let b=`${s}[${p}]`;this.deleteField(b)}if(!(d?.dontValidate??!1))this.validateField(s,"change")},this.resetField=(s)=>{this.baseStore.setState((d)=>{let c=this.getFieldInfo(s).instance?.options.defaultValue,g=Yt(this.options.defaultValues,s),_=c??g;return{...d,fieldMetaBase:{...d.fieldMetaBase,[s]:lt},values:_!==void 0?Gt(d.values,s,_):d.values}})},this.setErrorMap=(s)=>{Ge(()=>{Object.entries(s).forEach(([d,c])=>{let g=d;if(Jt(c)){let{formError:_,fieldErrors:p}=wa(c);for(let b of Object.keys(this.fieldInfo)){if(!this.getFieldMeta(b))continue;this.setFieldMeta(b,(m)=>({...m,errorMap:{...m.errorMap,[g]:p?.[b]},errorSourceMap:{...m.errorSourceMap,[g]:"form"}}))}this.baseStore.setState((b)=>({...b,errorMap:{...b.errorMap,[g]:_}}))}else this.baseStore.setState((_)=>({..._,errorMap:{..._.errorMap,[g]:c}}))})})},this.getAllErrors=()=>({form:{errors:this.state.errors,errorMap:this.state.errorMap},fields:Object.entries(this.state.fieldMeta).reduce((s,[d,c])=>{if(Object.keys(c).length&&c.errors.length)s[d]={errors:c.errors,errorMap:c.errorMap};return s},{})}),this.parseValuesWithSchema=(s)=>Lt.validate({value:this.state.values,validationSource:"form"},s),this.parseValuesWithSchemaAsync=(s)=>Lt.validateAsync({value:this.state.values,validationSource:"form"},s),this.timeoutIds={validations:{},listeners:{},formListeners:{}},this._formId=e?.formId??ra(),this._devtoolsSubmissionOverride=!1;let r=Ka({...e?.defaultState,values:e?.defaultValues??e?.defaultState?.values});if(e?.transform){r=e.transform({state:r}).state;for(let s of Object.keys(r.errorMap)){let d=r.errorMap[s];if(d===void 0||!Jt(d))continue;for(let c of Object.keys(d.fields)){let g=d.fields[c];if(g===void 0)continue;let _=r.fieldMetaBase[c];r.fieldMetaBase[c]={isTouched:!1,isValidating:!1,isBlurred:!1,isDirty:!1,_arrayVersion:0,_pendingValidationsCount:0,..._??{},errorSourceMap:{..._?.errorSourceMap??{},onChange:"form"},errorMap:{..._?.errorMap??{},[s]:g}}}}}this.baseStore=kt(r);let a=void 0;this.fieldMetaDerived=kt((s)=>{let d=this.baseStore.get(),c=0,g={};for(let _ of Object.keys(d.fieldMetaBase)){let p=d.fieldMetaBase[_],b=a?.fieldMetaBase[_],x=s?.[_],m=Yt(d.values,_),i=x?.errors;if(!b||p.errorMap!==b.errorMap){i=Object.values(p.errorMap??{}).filter((J)=>J!==void 0);let z=this.getFieldInfo(_)?.instance;if(!z||!z.options.disableErrorFlat)i=i.flat(1)}let v=!Oa(i),w=!p.isDirty,k=pt(m,this.getFieldInfo(_)?.instance?.options.defaultValue??Yt(this.options.defaultValues,_));if(x&&x.isPristine===w&&x.isValid===v&&x.isDefaultValue===k&&x.errors===i&&p===b){g[_]=x,c++;continue}g[_]={...p,errors:i??[],isPristine:w,isValid:v,isDefaultValue:k}}if(!Object.keys(d.fieldMetaBase).length)return g;if(s&&c===Object.keys(d.fieldMetaBase).length)return s;return a=this.baseStore.get(),g}),this.formGroupMetaDerived=kt((s)=>{let d=this.baseStore.get(),c=this.fieldMetaDerived.get(),g={};for(let _ of this.formGroupApis){let p=_.name,b=d.formGroupStateBase[p]??{isSubmitted:!1,isSubmitting:!1,isValidating:!1,submissionAttempts:0,isSubmitSuccessful:!1},x=c[p],m=!1,i=!0,v=!1,w=!1,k=!0,z=!1;for(let Ee in c){if(Ee===p)continue;if(!_t(p,Ee))continue;let Fe=c[Ee];if(!Fe)continue;if(Fe.isValidating)m=!0;if(!Fe.isValid)i=!1;if(Fe.isTouched)v=!0;if(Fe.isBlurred)w=!0;if(!Fe.isDefaultValue)k=!1;if(Fe.isDirty)z=!0}let J=!z,H=!!m||b.isValidating,ie=x?.errorMap??{},oe=x?.errorSourceMap??{},T=Boolean(ie.onMount||Object.entries(c).some(([Ee,Fe])=>Fe&&Ee!==p&&_t(p,Ee)&&Fe.errorMap.onMount)),P=s?.[p],j=P?.errors??[];if(!P||P.__srcErrorMap!==ie)j=Object.values(ie).reduce((Ee,Fe)=>{if(Fe===void 0)return Ee;if(Fe&&typeof Fe==="object"&&"fields"in Fe){let se=Fe.group;if(se!==void 0)Ee.push(se);return Ee}return Ee.push(Fe),Ee},[]);let X=j.length===0,F=i&&X,Y=_.options.canSubmitWhenInvalid??!1,ye=b.submissionAttempts===0&&!v&&!T||!H&&!b.isSubmitting&&F||Y;if(P&&P.errorMap===ie&&P.errorSourceMap===oe&&P.errors===j&&P.isFieldsValidating===m&&P.isFieldsValid===i&&P.isGroupValid===X&&P.isValid===F&&P.canSubmit===ye&&P.isTouched===v&&P.isBlurred===w&&P.isPristine===J&&P.isDefaultValue===k&&P.isDirty===z&&P.isValidating===H&&P.isSubmitting===b.isSubmitting&&P.isSubmitted===b.isSubmitted&&P.submissionAttempts===b.submissionAttempts&&P.isSubmitSuccessful===b.isSubmitSuccessful){g[p]=P;continue}let me={...b,errorMap:ie,errorSourceMap:oe,_arrayVersion:x?._arrayVersion??0,isTouched:v,isBlurred:w,isDirty:z,isPristine:J,isDefaultValue:k,isValid:F,errors:j,isValidating:H,isFieldsValidating:m,isFieldsValid:i,isGroupValid:X,canSubmit:ye};Object.defineProperty(me,"__srcErrorMap",{value:ie,enumerable:!1,configurable:!0}),g[p]=me}return g});let l=void 0;this.store=kt((s)=>{let d=this.baseStore.get(),c=this.fieldMetaDerived.get(),g=Object.values(c).filter(Boolean),_=g.some((X)=>X.isValidating),p=g.every((X)=>X.isValid),b=g.some((X)=>X.isTouched),x=g.some((X)=>X.isBlurred),m=g.every((X)=>X.isDefaultValue),i=b&&d.errorMap?.onMount,v=g.some((X)=>X.isDirty),w=!v,k=Boolean(d.errorMap?.onMount||g.some((X)=>X?.errorMap?.onMount)),z=!!_,J=s?.errors??[];if(!l||d.errorMap!==l.errorMap)J=Object.values(d.errorMap).reduce((X,F)=>{if(F===void 0)return X;if(F&&Jt(F))return X.push(F.form),X;return X.push(F),X},[]);let H=J.length===0,ie=p&&H,oe=this.options.canSubmitWhenInvalid??!1,T=d.submissionAttempts===0&&!b&&!k||!z&&!d.isSubmitting&&ie||oe,P=d.errorMap;if(i)J=J.filter((X)=>X!==d.errorMap.onMount),P=Object.assign(P,{onMount:void 0});if(s&&l&&s.errorMap===P&&s.fieldMeta===this.fieldMetaDerived.state&&s.errors===J&&s.isFieldsValidating===_&&s.isFieldsValid===p&&s.isFormValid===H&&s.isValid===ie&&s.canSubmit===T&&s.isTouched===b&&s.isBlurred===x&&s.isPristine===w&&s.isDefaultValue===m&&s.isDirty===v&&pt(l,d))return s;let j={...d,errorMap:P,fieldMeta:this.fieldMetaDerived.state,errors:J,isFieldsValidating:_,isFieldsValid:p,isFormValid:H,isValid:ie,canSubmit:T,isTouched:b,isBlurred:x,isPristine:w,isDefaultValue:m,isDirty:v};return l=this.baseStore.get(),j}),this.handleSubmit=this.handleSubmit.bind(this),this.update(e||{})}get state(){return this.store.state}get formId(){return this._formId}runValidator(e){if(ta(e.validate))return Lt[e.type](e.value,e.validate);return e.validate(e.value)}handleSubmit(e){return this._handleSubmit(e)}}function wa(e){if(e){if(Jt(e)){let r=wa(e.form).formError,a=e.fields;return{formError:r,fieldErrors:a}}return{formError:e}}return{formError:void 0}}function oa(e){switch(e){case"submit":return"onSubmit";case"blur":return"onBlur";case"mount":return"onMount";case"server":return"onServer";case"dynamic":return"onDynamic";case"change":default:return"onChange"}}class jt{constructor(e){this.options={},this.mount=()=>{if(this.options.defaultValue!==void 0&&!this.getMeta().isTouched)this.form.setFieldValue(this.name,this.options.defaultValue,{dontUpdateMeta:!0});let r=this.getInfo();r.instance=this,this.update(this.options);let{onMount:a}=this.options.validators||{};if(a){let l=this.runValidator({validate:a,value:{value:this.state.value,fieldApi:this,validationSource:"field"},type:"validate"});if(l)this.setMeta((s)=>({...s,errorMap:{...s?.errorMap,onMount:l},errorSourceMap:{...s?.errorSourceMap,onMount:"field"}}))}return this.options.listeners?.onMount?.({value:this.state.value,fieldApi:this}),()=>{for(let[s,d]of Object.entries(this.timeoutIds.validations))if(d)clearTimeout(d),this.timeoutIds.validations[s]=null;for(let[s,d]of Object.entries(this.timeoutIds.listeners))if(d)clearTimeout(d),this.timeoutIds.listeners[s]=null;for(let[s,d]of Object.entries(this.timeoutIds.formListeners))if(d)clearTimeout(d),this.timeoutIds.formListeners[s]=null;let l=this.form.fieldInfo[this.name];if(!l)return;if(l.instance!==this)return;for(let[s,d]of Object.entries(l.validationMetaMap))d?.lastAbortController.abort(),l.validationMetaMap[s]=void 0;this.form.baseStore.setState((s)=>({...s,fieldMetaBase:{...s.fieldMetaBase,[this.name]:{...lt,isTouched:s.fieldMetaBase[this.name]?.isTouched??lt.isTouched,isBlurred:s.fieldMetaBase[this.name]?.isBlurred??lt.isBlurred,isDirty:s.fieldMetaBase[this.name]?.isDirty??lt.isDirty}}})),l.instance=null,this.options.listeners?.onUnmount?.({value:this.state.value,fieldApi:this}),this.form.options.listeners?.onFieldUnmount?.({formApi:this.form,fieldApi:this})}},this.update=(r)=>{if(this.options=r,this.name=r.name,!this.state.meta.isTouched&&this.options.defaultValue!==void 0){let a=this.form.getFieldValue(this.name);if(!pt(a,r.defaultValue))this.form.setFieldValue(this.name,r.defaultValue,{dontUpdateMeta:!0,dontValidate:!0,dontRunListeners:!0})}if(!this.form.getFieldMeta(this.name))this.form.setFieldMeta(this.name,this.state.meta)},this.getValue=()=>this.form.getFieldValue(this.name),this.setValue=(r,a)=>{if(this.form.setFieldValue(this.name,r,it(a,{dontRunListeners:!0,dontValidate:!0})),!a?.dontRunListeners)this.triggerOnChangeListener();if(!a?.dontValidate)this.validate("change")},this.getMeta=()=>this.store.state.meta,this.setMeta=(r)=>this.form.setFieldMeta(this.name,r),this.getInfo=()=>this.form.getFieldInfo(this.name),this.pushValue=(r,a)=>{if(this.form.pushFieldValue(this.name,r,it(a,{dontRunListeners:!0})),!a?.dontRunListeners)this.triggerOnChangeListener()},this.insertValue=(r,a,l)=>{if(this.form.insertFieldValue(this.name,r,a,it(l,{dontRunListeners:!0})),!l?.dontRunListeners)this.triggerOnChangeListener()},this.replaceValue=(r,a,l)=>{if(this.form.replaceFieldValue(this.name,r,a,it(l,{dontRunListeners:!0})),!l?.dontRunListeners)this.triggerOnChangeListener()},this.removeValue=(r,a)=>{if(this.form.removeFieldValue(this.name,r,it(a,{dontRunListeners:!0})),!a?.dontRunListeners)this.triggerOnChangeListener()},this.swapValues=(r,a,l)=>{if(this.form.swapFieldValues(this.name,r,a,it(l,{dontRunListeners:!0})),!l?.dontRunListeners)this.triggerOnChangeListener()},this.moveValue=(r,a,l)=>{if(this.form.moveFieldValues(this.name,r,a,it(l,{dontRunListeners:!0})),!l?.dontRunListeners)this.triggerOnChangeListener()},this.clearValues=(r)=>{if(this.form.clearFieldValues(this.name,it(r,{dontRunListeners:!0})),!r?.dontRunListeners)this.triggerOnChangeListener()},this.getLinkedFields=(r)=>{let a=Object.values(this.form.fieldInfo),l=[];for(let s of a){if(!s.instance)continue;if(!(s.instance instanceof jt))continue;let{onChangeListenTo:d,onBlurListenTo:c}=s.instance.options.validators||{};if(r==="change"&&d?.includes(this.name))l.push(s.instance);if(r==="blur"&&c?.includes(this.name))l.push(s.instance)}return l},this.validateSync=(r,a)=>{let l=Pt(r,{...this.options,form:this.form,fieldName:this.name,validationLogic:this.form.options.validationLogic||ft}),d=this.getLinkedFields(r).reduce((_,p)=>{let b=Pt(r,{...p.options,form:p.form,fieldName:p.name,validationLogic:p.form.options.validationLogic||ft});return b.forEach((x)=>{x.field=p}),_.concat(b)},[]),c=!1;Ge(()=>{let _=(p,b)=>{let x=la(b.cause),m=b.validate?bs(p.runValidator({validate:b.validate,value:{value:p.store.state.value,validationSource:"field",fieldApi:p},type:"validate"})):void 0,i=a[x],{newErrorValue:v,newSource:w}=Wt({formLevelError:i,fieldLevelError:m});if(p.state.meta.errorMap?.[x]!==v)p.setMeta((k)=>({...k,errorMap:{...k.errorMap,[x]:v},errorSourceMap:{...k.errorSourceMap,[x]:w}}));if(v)c=!0};for(let p of l)_(this,p);for(let p of d){if(!p.validate)continue;_(p.field,p)}});let g=la("submit");if(this.state.meta.errorMap?.[g]&&r!=="submit"&&!c)this.setMeta((_)=>({..._,errorMap:{..._.errorMap,[g]:void 0},errorSourceMap:{..._.errorSourceMap,[g]:void 0}}));return{hasErrored:c}},this.validateAsync=async(r,a)=>{let l=Rt(r,{...this.options,form:this.form,fieldName:this.name,validationLogic:this.form.options.validationLogic||ft}),s=await a,c=this.getLinkedFields(r).reduce((i,v)=>{let w=Rt(r,{...v.options,form:v.form,fieldName:v.name,validationLogic:v.form.options.validationLogic||ft});return w.forEach((k)=>{k.field=v}),i.concat(w)},[]),g=[],_=[],p=l.some((i)=>i.validate),b=Array.from(new Set(c.filter((i)=>i.validate).map((i)=>i.field)));Ge(()=>{if(p)this.startValidation();for(let i of b)i.startValidation()});let x=(i,v,w)=>{let k=la(v.cause),z=i.getInfo();z.validationMetaMap[k]?.lastAbortController.abort();let H=new AbortController;z.validationMetaMap[k]={lastAbortController:H},w.push(new Promise(async(ie)=>{let oe;try{oe=await new Promise((F,Y)=>{if(i.timeoutIds.validations[v.cause])clearTimeout(i.timeoutIds.validations[v.cause]),i.endValidation();i.timeoutIds.validations[v.cause]=setTimeout(async()=>{if(H.signal.aborted)return F(void 0);try{F(await this.runValidator({validate:v.validate,value:{value:i.store.state.value,fieldApi:i,signal:H.signal,validationSource:"field"},type:"validateAsync"}))}catch(ye){Y(ye)}},v.debounceMs)})}catch(F){oe=F}if(H.signal.aborted)return ie(void 0);let T=bs(oe),P=s[i.name]?.[k],{newErrorValue:j,newSource:X}=Wt({formLevelError:P,fieldLevelError:T});if(i.getInfo().instance!==i)return ie(void 0);i.setMeta((F)=>({...F,errorMap:{...F?.errorMap,[k]:j},errorSourceMap:{...F.errorSourceMap,[k]:X}})),ie(j)}))};for(let i of l){if(!i.validate)continue;x(this,i,g)}for(let i of c){if(!i.validate)continue;x(i.field,i,_)}let m=[];if(g.length||_.length)m=await Promise.all(g),await Promise.all(_);return Ge(()=>{if(p)this.endValidation();for(let i of b)i.endValidation()}),m.filter(Boolean)},this.validate=(r,a)=>{if(!this.state.meta.isTouched)return[];let l=a?.skipGroupValidation?[]:Array.from(this.form.formGroupApis).filter((x)=>this.name.startsWith(x.name)),d=((a?.skipFormValidation)?{fieldsErrorMap:{}}:this.form.validateSync(r)).fieldsErrorMap[this.name]??{};if(!a?.skipFormValidation)for(let x of l){if(x.state.meta.submissionAttempts===0)continue;let{fieldsErrorMap:m}=this.form.validateSync(r,{group:x,dontUpdateFormErrorMap:!0,filterFieldNames:(i)=>_t(x.name,i)});d={...d,...m[this.name]??{}}}let{hasErrored:c}=this.validateSync(r,d),g=new WeakMap;for(let x of l){let{hasErrored:m}=x.validateSync(r,{},{skipRelatedFieldValidation:!0});g.set(x,m)}if(c&&!this.options.asyncAlways){this.getInfo().validationMetaMap[la(r)]?.lastAbortController.abort();let x=[];for(let m of l)m.getInfo().validationMetaMap[la(r)]?.lastAbortController.abort(),x.push(m.state.meta.errors);return[...this.state.meta.errors,...x.flat()]}let _=a?.skipFormValidation?Promise.resolve({}):this.form.validateAsync(r),p=this.validateAsync(r,_),b=[];for(let x of l){if(g.get(x)&&!x.options.asyncAlways)continue;b.push(x.validateAsync(r,_,{skipRelatedFieldValidation:!0}))}if(b.length===0)return p;return Promise.all([p,...b]).then((x)=>x.flat())},this.handleChange=(r)=>{this.setValue(r)},this.handleBlur=()=>{if(!this.state.meta.isTouched)this.setMeta((a)=>({...a,isTouched:!0}));if(!this.state.meta.isBlurred)this.setMeta((a)=>({...a,isBlurred:!0}));this.validate("blur"),this.triggerOnBlurListener()},this.setErrorMap=(r)=>{this.setMeta((a)=>({...a,errorMap:{...a.errorMap,...r}}))},this.parseValueWithSchema=(r)=>Lt.validate({value:this.state.value,validationSource:"field"},r),this.parseValueWithSchemaAsync=(r)=>Lt.validateAsync({value:this.state.value,validationSource:"field"},r),this.triggerOnBlurListener=()=>{let r=this.form.options.listeners?.onBlurDebounceMs;if(r&&r>0){if(this.timeoutIds.formListeners.blur)clearTimeout(this.timeoutIds.formListeners.blur);this.timeoutIds.formListeners.blur=setTimeout(()=>{this.form.options.listeners?.onBlur?.({formApi:this.form,fieldApi:this})},r)}else this.form.options.listeners?.onBlur?.({formApi:this.form,fieldApi:this});let a=this.options.listeners?.onBlurDebounceMs;if(a&&a>0){if(this.timeoutIds.listeners.blur)clearTimeout(this.timeoutIds.listeners.blur);this.timeoutIds.listeners.blur=setTimeout(()=>{this.options.listeners?.onBlur?.({value:this.state.value,fieldApi:this})},a)}else this.options.listeners?.onBlur?.({value:this.state.value,fieldApi:this})},this.triggerOnChangeListener=()=>{let r=this.form.options.listeners?.onChangeDebounceMs;if(r&&r>0){if(this.timeoutIds.formListeners.change)clearTimeout(this.timeoutIds.formListeners.change);this.timeoutIds.formListeners.change=setTimeout(()=>{this.form.options.listeners?.onChange?.({formApi:this.form,fieldApi:this})},r)}else this.form.options.listeners?.onChange?.({formApi:this.form,fieldApi:this});let a=this.options.listeners?.onChangeDebounceMs;if(a&&a>0){if(this.timeoutIds.listeners.change)clearTimeout(this.timeoutIds.listeners.change);this.timeoutIds.listeners.change=setTimeout(()=>{this.options.listeners?.onChange?.({value:this.state.value,fieldApi:this})},a)}else this.options.listeners?.onChange?.({value:this.state.value,fieldApi:this});for(let l of this.form.formGroupApis)if(_t(l.name,this.name))l.triggerOnChangeListener()},this.triggerOnSubmitListener=()=>{this.options.listeners?.onSubmit?.({value:this.state.value,fieldApi:this})},this.form=e.form,this.name=e.name,this.options=e,this.timeoutIds={validations:{},listeners:{},formListeners:{}},this.store=kt((r)=>{this.form.store.get();let a=this.form.getFieldMeta(this.name)??{...lt,...e.defaultMeta},l=this.form.getFieldValue(this.name);if(!a.isTouched&&l===void 0&&this.options.defaultValue!==void 0&&!pt(l,this.options.defaultValue))l=this.options.defaultValue;if(r&&r.value===l&&r.meta===a)return r;return{value:l,meta:a}})}get state(){return this.store.state}runValidator(e){if(ta(e.validate))return Lt[e.type](e.value,e.validate);return e.validate(e.value)}startValidation(){this.setMeta((e)=>{let r=e._pendingValidationsCount+1;return{...e,_pendingValidationsCount:r,isValidating:r>0&&!e.isValidating?!0:e.isValidating}})}endValidation(){this.setMeta((e)=>{let r=Math.max(0,e._pendingValidationsCount-1);return{...e,_pendingValidationsCount:r,isValidating:r===0&&e.isValidating?!1:e.isValidating}})}}function bs(e){if(e)return e;return}function la(e){switch(e){case"submit":return"onSubmit";case"blur":return"onBlur";case"mount":return"onMount";case"server":return"onServer";case"dynamic":return"onDynamic";case"change":default:return"onChange"}}function za(e){return{isSubmitted:e.isSubmitted??!1,isSubmitting:e.isSubmitting??!1,isValidating:e.isValidating??!1,submissionAttempts:e.submissionAttempts??0,isSubmitSuccessful:e.isSubmitSuccessful??!1}}function xs(e){return{...lt,...e,errors:[],isPristine:!0,isValid:!0,isDefaultValue:!0,isFieldsValidating:!1,isFieldsValid:!0,isGroupValid:!0,canSubmit:!0,isSubmitting:!1,isSubmitted:!1,isValidating:!1,submissionAttempts:0,isSubmitSuccessful:!1}}class Zt{constructor(e){this.options={},this.setFormGroupState=(r)=>{this.form.baseStore.setState((a)=>{let l=a.formGroupStateBase[this.name]??za({});return{...a,formGroupStateBase:{...a.formGroupStateBase,[this.name]:r(l)}}})},this._lastDistributedFieldNames={},this.update=(r)=>{if(this.options=r,this.name=r.name,!this.state.meta.isTouched&&this.options.defaultValue!==void 0){let a=this.form.getFieldValue(this.name);if(!pt(a,r.defaultValue))this.form.setFieldValue(this.name,r.defaultValue,{dontUpdateMeta:!0,dontValidate:!0,dontRunListeners:!0})}if(!this.form.getFieldMeta(this.name))this.form.setFieldMeta(this.name,{...lt,...this.options.defaultMeta})},this.mount=()=>{this.update(this.options),this.form.formGroupApis.add(this),this.fieldInfo.instance=this,this.form.baseStore.setState((a)=>({...a,formGroupStateBase:{...a.formGroupStateBase,[this.name]:a.formGroupStateBase[this.name]??za({...this.options.defaultState})}}));let{onMount:r}=this.options.validators||{};if(r){let a=this.runValidator({validate:r,value:{value:this.state.value,groupApi:this,validationSource:"form"},type:"validate"}),l=a,s=void 0;if(Ga(a))l=a.group,s=a.fields;let d=Ha(l);if(d)this.setMeta((c)=>({...c,errorMap:{...c.errorMap,onMount:d},errorSourceMap:{...c.errorSourceMap,onMount:"field"}}));this.distributeFieldErrors("onMount",s)}return this.options.listeners?.onMount?.({value:this.state.value,groupApi:this}),()=>{for(let[a,l]of Object.entries(this.timeoutIds.validations))if(l)clearTimeout(l),this.timeoutIds.validations[a]=null;for(let[a,l]of Object.entries(this.timeoutIds.listeners))if(l)clearTimeout(l),this.timeoutIds.listeners[a]=null;for(let[a,l]of Object.entries(this.timeoutIds.formListeners))if(l)clearTimeout(l),this.timeoutIds.formListeners[a]=null;if(this.fieldInfo.instance!==this)return;for(let[a,l]of Object.entries(this.fieldInfo.validationMetaMap))l?.lastAbortController.abort(),this.fieldInfo.validationMetaMap[a]=void 0;this.form.formGroupApis.delete(this),this.form.baseStore.setState((a)=>({...a,formGroupStateBase:{...a.formGroupStateBase,[this.name]:za({})}})),this.fieldInfo.instance=null,this.options.listeners?.onUnmount?.({value:this.state.value,groupApi:this})}},this.setValue=(r,a)=>{if(this.form.setFieldValue(this.name,r,it(a,{dontRunListeners:!0,dontValidate:!0})),!a?.dontRunListeners)this.triggerOnChangeListener();if(!a?.dontValidate)this.validate("change")},this.getMeta=()=>this.store.state.meta,this.setMeta=(r)=>this.form.setFieldMeta(this.name,r),this.getInfo=()=>this.fieldInfo,this.getRelatedFields=()=>{let r=Object.values(this.form.fieldInfo),a=[];for(let l of r){if(!l.instance)continue;if(!(l.instance instanceof jt))continue;if(l.instance.name.startsWith(this.name))a.push(l.instance)}return a},this.getRelatedFieldMetasDerived=()=>{let r=Object.entries(this.form.fieldMetaDerived.state),a=[];for(let[l,s]of r){if(l===this.name)continue;if(_t(this.name,l))a.push({...s,name:l})}return a},this.buildChildFieldName=(r)=>{if(r==="")return this.name;if(r.startsWith("["))return`${this.name}${r}`;return`${this.name}.${r}`},this.distributeFieldErrors=(r,a)=>{let l=this._lastDistributedFieldNames[r]??new Set,s=new Set;if(a)for(let[g,_]of Object.entries(a)){if(_===void 0||_===null||_===!1)continue;s.add(this.buildChildFieldName(g))}let d=new Set([...l,...s]),c=!1;for(let g of d){let _=g.startsWith(this.name+"[")?g.slice(this.name.length):g.slice(this.name.length+1),p=a?.[_],b=this.form.getFieldMeta(g);if(!b&&!p)continue;let x=b?.errorMap[r],m=b?.errorSourceMap[r]==="form",{newErrorValue:i,newSource:v}=ea({newFormValidatorError:p,isPreviousErrorFromFormValidator:m,previousErrorValue:x});if(i)c=!0;if(x===i&&b?.errorSourceMap[r]===v)continue;this.form.setFieldMeta(g,(w=lt)=>({...w,errorMap:{...w.errorMap,[r]:i},errorSourceMap:{...w.errorSourceMap,[r]:v}}))}return this._lastDistributedFieldNames[r]=s,c},this.validateSync=(r,a,l={})=>{let s=Pt(r,{...this.options,form:this.form,group:this,validationLogic:this.options.validationLogic||this.form.options.validationLogic||ft}),c=(l.skipRelatedFieldValidation?[]:this.getRelatedFields()).reduce((p,b)=>{let x=Pt(r,{...b.options,form:b.form,validationLogic:b.form.options.validationLogic||ft});return x.forEach((m)=>{m.field=b}),p.concat(x)},[]),g=!1;Ge(()=>{let p=(b,x)=>{let m=Sa(x.cause),i=b===this,v=void 0;if(x.validate)v=b.runValidator({validate:x.validate,value:{value:b.store.state.value,validationSource:i?"form":"field",...b instanceof Zt?{groupApi:b}:{fieldApi:b}},type:"validate"});let w=v,k=void 0;if(i&&Ga(v))w=v.group,k=v.fields;let z=Ha(w),J=a[m],{newErrorValue:H,newSource:ie}=Wt({formLevelError:J,fieldLevelError:z});if(b.state.meta.errorMap?.[m]!==H)b.setMeta((oe)=>({...oe,errorMap:{...oe.errorMap,[m]:H},errorSourceMap:{...oe.errorSourceMap,[m]:ie}}));if(H)g=!0;if(i){if(this.distributeFieldErrors(m,k))g=!0}};for(let b of s)p(this,b);for(let b of c){if(!b.validate)continue;p(b.field,b)}});let _=Sa("submit");if(this.state.meta.errorMap?.[_]&&r!=="submit"&&!g)this.setMeta((p)=>({...p,errorMap:{...p.errorMap,[_]:void 0},errorSourceMap:{...p.errorSourceMap,[_]:void 0}}));return{hasErrored:g}},this.validateAsync=async(r,a,l={})=>{let s=Rt(r,{...this.options,form:this.form,group:this,validationLogic:this.options.validationLogic||this.form.options.validationLogic||ft}),d=await a,c=l.skipRelatedFieldValidation?[]:this.getRelatedFields(),g=c.reduce((i,v)=>{let w=Rt(r,{...v.options,form:v.form,validationLogic:v.form.options.validationLogic||ft});return w.forEach((k)=>{k.field=v}),i.concat(w)},[]),_=[],p=[],b=s.some((i)=>i.validate)||g.some((i)=>i.validate);if(b){if(!this.state.meta.isValidating)this.setMeta((i)=>({...i,isValidating:!0}));for(let i of c)i.setMeta((v)=>({...v,isValidating:!0}))}let x=(i,v,w)=>{let k=Sa(v.cause),z=i.getInfo();z.validationMetaMap[k]?.lastAbortController.abort();let H=new AbortController;z.validationMetaMap[k]={lastAbortController:H};let ie=i===this;w.push(new Promise(async(oe)=>{let T;try{T=await new Promise((me,Ee)=>{if(i.timeoutIds.validations[v.cause])clearTimeout(i.timeoutIds.validations[v.cause]);i.timeoutIds.validations[v.cause]=setTimeout(async()=>{if(H.signal.aborted)return me(void 0);try{me(await this.runValidator({validate:v.validate,value:{value:i.store.state.value,signal:H.signal,validationSource:ie?"form":"field",...i instanceof Zt?{groupApi:i}:{fieldApi:i}},type:"validateAsync"}))}catch(Fe){Ee(Fe)}},v.debounceMs)})}catch(me){T=me}if(H.signal.aborted)return oe(void 0);let P=T,j=void 0;if(ie&&Ga(T))P=T.group,j=T.fields;let X=Ha(P),F=d[i.name]?.[k],{newErrorValue:Y,newSource:ye}=Wt({formLevelError:F,fieldLevelError:X});if(i.getInfo().instance!==i)return oe(void 0);if(i.setMeta((me)=>({...me,errorMap:{...me?.errorMap,[k]:Y},errorSourceMap:{...me.errorSourceMap,[k]:ye}})),ie)this.distributeFieldErrors(k,j);oe(Y)}))};for(let i of s){if(!i.validate)continue;x(this,i,_)}for(let i of g){if(!i.validate)continue;x(i.field,i,p)}let m=[];if(_.length||p.length)m=await Promise.all(_),await Promise.all(p);if(b){this.setMeta((i)=>({...i,isValidating:!1}));for(let i of c)i.setMeta((v)=>({...v,isValidating:!1}))}return m.filter(Boolean)},this.validateAllFields=async(r)=>{let a=[];return Ge(()=>{Object.values(this.getRelatedFields()).forEach((s)=>{if(a.push(Promise.resolve().then(()=>s.validate(r,{skipFormValidation:!0,skipGroupValidation:!0}))),!s.store.state.meta.isTouched)s.setMeta((d)=>({...d,isTouched:!0}))})}),(await Promise.all(a)).flat()},this.validateArrayFieldsStartingFrom=(r,a,l)=>this.form.validateArrayFieldsStartingFrom(r,a,l),this.validateField=(r,a)=>this.form.validateField(r,a),this.getFieldValue=(r)=>this.form.getFieldValue(r),this.getFieldMeta=(r)=>this.form.getFieldMeta(r),this.setFieldMeta=(r,a)=>this.form.setFieldMeta(r,a),this.setFieldValue=(r,a)=>this.form.setFieldValue(r,a),this.deleteField=(r)=>this.form.deleteField(r),this.pushFieldValue=(r,a)=>this.form.pushFieldValue(r,a),this.insertFieldValue=(r,a,l)=>this.form.insertFieldValue(r,a,l),this.replaceFieldValue=(r,a,l)=>this.form.replaceFieldValue(r,a,l),this.swapFieldValues=(r,a,l)=>this.form.swapFieldValues(r,a,l),this.moveFieldValues=(r,a,l)=>this.form.moveFieldValues(r,a,l),this.clearFieldValues=(r)=>this.form.clearFieldValues(r),this.resetField=(r)=>this.form.resetField(r),this.removeFieldValue=(r,a)=>this.form.removeFieldValue(r,a),this.areRelatedFieldsValid=()=>Object.values(this.getRelatedFields()).every((r)=>r.state.meta.isValid),this.validate=(r,a)=>{let{fieldsErrorMap:l}=a?.skipFormValidation?{fieldsErrorMap:{}}:this.form.validateSync(r,{dontUpdateFormErrorMap:!0,filterFieldNames:(c)=>_t(this.name,c)}),{hasErrored:s}=this.validateSync(r,l[this.name]??{},{skipRelatedFieldValidation:a?.skipRelatedFieldValidation});if(s&&!this.options.asyncAlways)return this.getInfo().validationMetaMap[Sa(r)]?.lastAbortController.abort(),this.state.meta.errors;let d=a?.skipFormValidation?Promise.resolve({}):this.form.validateAsync(r,{dontUpdateFormErrorMap:!0,filterFieldNames:(c)=>_t(this.name,c)});return this.validateAsync(r,d,{skipRelatedFieldValidation:a?.skipRelatedFieldValidation})},this.triggerOnChangeListener=()=>{let r=this.form.options.listeners?.onChangeGroupDebounceMs;if(r&&r>0){if(this.timeoutIds.formListeners.change)clearTimeout(this.timeoutIds.formListeners.change);this.timeoutIds.formListeners.change=setTimeout(()=>{this.form.options.listeners?.onChangeGroup?.({formApi:this.form,groupApi:this})},r)}else this.form.options.listeners?.onChangeGroup?.({formApi:this.form,groupApi:this});let a=this.options.listeners?.onChangeDebounceMs;if(a&&a>0){if(this.timeoutIds.listeners.change)clearTimeout(this.timeoutIds.listeners.change);this.timeoutIds.listeners.change=setTimeout(()=>{this.options.listeners?.onChange?.({value:this.state.value,groupApi:this})},a)}else this.options.listeners?.onChange?.({value:this.state.value,groupApi:this})},this.triggerOnSubmitListener=()=>{this.options.listeners?.onSubmit?.({value:this.state.value,groupApi:this})},this._handleSubmit=async(r)=>{this.setFormGroupState((s)=>({...s,isSubmitted:!1,submissionAttempts:s.submissionAttempts+1,isSubmitSuccessful:!1})),Ge(()=>{Object.values(this.getRelatedFields()).forEach((s)=>{if(!s.state.meta.isTouched)s.setMeta((d)=>({...d,isTouched:!0}))})});let a=r??this.options.onSubmitMeta;this.setFormGroupState((s)=>({...s,isSubmitting:!0}));let l=()=>{this.setFormGroupState((s)=>({...s,isSubmitting:!1}))};if(await this.validateAllFields("submit"),!this.areRelatedFieldsValid()){l(),this.options.onGroupSubmitInvalid?.({value:this.state.value,groupApi:this,meta:a});return}if(await this.validate("submit",{skipRelatedFieldValidation:!0}),!this.areRelatedFieldsValid()||!this.state.meta.isValid){l(),this.options.onGroupSubmitInvalid?.({value:this.state.value,groupApi:this,meta:a});return}Ge(()=>{Object.values(this.getRelatedFields()).forEach((s)=>{s.options.listeners?.onGroupSubmit?.({value:s.state.value,fieldApi:s})})}),this.options.listeners?.onSubmit?.({groupApi:this,value:this.state.value});try{await this.options.onGroupSubmit?.({value:this.state.value,groupApi:this,meta:a}),Ge(()=>{this.setFormGroupState((s)=>({...s,isSubmitted:!0,isSubmitSuccessful:!0})),l()})}catch(s){throw this.setFormGroupState((d)=>({...d,isSubmitSuccessful:!1})),l(),s}},this.form=e.form,this.name=e.name,this.options=e,this.timeoutIds={validations:{},listeners:{},formListeners:{}},this.fieldInfo={instance:null,validationMetaMap:{onChange:void 0,onBlur:void 0,onSubmit:void 0,onMount:void 0,onServer:void 0,onDynamic:void 0}},this.store=kt((r)=>{this.form.formGroupMetaDerived.get(),this.form.baseStore.get();let a=this.form.getFormGroupMeta(this.name)??xs(e.defaultMeta),l=this.form.getFieldValue(this.name);if(!a.isTouched&&l===void 0&&this.options.defaultValue!==void 0&&!pt(l,this.options.defaultValue))l=this.options.defaultValue;if(r&&r.value===l&&r.meta===a)return r;return{value:l,meta:a}}),this.handleSubmit=this.handleSubmit.bind(this)}get state(){return this.store.state}runValidator(e){if(ta(e.validate)){let r=Lt[e.type](e.value,e.validate);if(e.type==="validate")return ys(r);return r.then(ys)}return e.validate(e.value)}handleSubmit(e){return this._handleSubmit(e)}}function Ha(e){if(e)return e;return}function Ga(e){return!!e&&typeof e==="object"&&"fields"in e}function ys(e){if(!e||typeof e!=="object")return e;if(!("form"in e)&&!("fields"in e))return e;let{form:r,fields:a,...l}=e;return{...l,group:r,fields:a}}function Sa(e){switch(e){case"submit":return"onSubmit";case"blur":return"onBlur";case"mount":return"onMount";case"server":return"onServer";case"dynamic":return"onDynamic";case"change":default:return"onChange"}}function Wa(e,r){if(!r)return;let a=Object.assign({},e,{state:Ht(e.state)});if(r(a),a.fieldInfo!==e.fieldInfo)e.fieldInfo=a.fieldInfo;if(a.options!==e.options)e.options=a.options;let s=Object.keys({values:null,validationMetaMap:null,fieldMetaBase:null,formGroupStateBase:null,isSubmitting:null,isSubmitted:null,isValidating:null,submissionAttempts:null,isSubmitSuccessful:null,_force_re_eval:null}).reduce((d,c)=>{if(e.state[c]!==a.state[c])d[c]=a.state[c];return d},{});return Ge(()=>{if(Object.keys(s).length)e.baseStore.setState((d)=>({...d,...s}));if(a.state.errorMap!==e.state.errorMap)e.setErrorMap(a.state.errorMap)}),a}S();function Ir(e,r){return e===r}function Re(e,r=(l)=>l,a){let l=a?.compare??Ir,s=D((c)=>{let{unsubscribe:g}=e.subscribe(c);return g},[e]),d=D(()=>e.get(),[e]);return Rc(s,d,d,r,l)}var da=(e,r=(l)=>l,a)=>Re(e,r,{compare:a});S();S();S();var wt=typeof window<"u"?$e:h;function Tr(e){let[r,a]=u(()=>({form:e.form,name:e.name})),[l,s]=u(()=>new jt({...e})),d=l;if(r.form!==e.form||r.name!==e.name)d=new jt({...e}),s(d),a({form:e.form,name:e.name});let c=Re(d.store,e.mode==="array"?(v)=>v.meta._arrayVersion||0:(v)=>v.value),g=Re(d.store,(v)=>v.meta.isTouched),_=Re(d.store,(v)=>v.meta.isBlurred),p=Re(d.store,(v)=>v.meta.isDirty),b=Re(d.store,(v)=>v.meta.errorMap),x=Re(d.store,(v)=>v.meta.errorSourceMap),m=Re(d.store,(v)=>v.meta.isValidating),i=N(()=>({...d,get state(){return{value:e.mode==="array"?d.state.value:c,get meta(){return{...d.state.meta,isTouched:g,isBlurred:_,isDirty:p,errorMap:b,errorSourceMap:x,isValidating:m}}}}}),[d,e.mode,c,g,_,p,b,x,m]);return wt(d.mount,[d]),wt(()=>{d.update(e)}),i}var _s=({children:e,...r})=>{let a=Tr(r),l=N(()=>Ft(e,a),[e,a]);return t(L,{children:l})};S();S();function ws(){return u(()=>ra())[0]}var Er=V,Ns=Ds.split(".")[0]==="17"?ws:Er.useId;S();function Vr(e){let[r,a]=u(()=>({form:e.form,name:e.name})),[l,s]=u(()=>new Zt({...e}));if(r.form!==e.form||r.name!==e.name)s(new Zt({...e})),a({form:e.form,name:e.name});let d=Re(l.store,(T)=>T.value),c=Re(l.store,(T)=>T.meta.isTouched),g=Re(l.store,(T)=>T.meta.isBlurred),_=Re(l.store,(T)=>T.meta.isDirty),p=Re(l.store,(T)=>T.meta.errorMap),b=Re(l.store,(T)=>T.meta.errorSourceMap),x=Re(l.store,(T)=>T.meta.isValidating),m=Re(l.store,(T)=>T.meta.isSubmitting),i=Re(l.store,(T)=>T.meta.isSubmitted),v=Re(l.store,(T)=>T.meta.submissionAttempts),w=Re(l.store,(T)=>T.meta.isSubmitSuccessful),k=Re(l.store,(T)=>T.meta.canSubmit),z=Re(l.store,(T)=>T.meta.isValid),J=Re(l.store,(T)=>T.meta.isFieldsValid),H=Re(l.store,(T)=>T.meta.isFieldsValidating),ie=Re(l.store,(T)=>T.meta.isGroupValid),oe=N(()=>({...l,handleSubmit:(...j)=>l._handleSubmit(...j),get state(){return{...l.state,value:d,get meta(){return{...l.state.meta,isTouched:c,isBlurred:g,isDirty:_,errorMap:p,errorSourceMap:b,isValidating:x,isSubmitting:m,isSubmitted:i,submissionAttempts:v,isSubmitSuccessful:w,canSubmit:k,isValid:z,isFieldsValid:J,isFieldsValidating:H,isGroupValid:ie}}}}}),[l,d,c,g,_,p,b,x,m,i,v,w,k,z,J,H,ie]);return wt(l.mount,[l]),wt(()=>{l.update(e)}),oe}var Ss=({children:e,...r})=>{let a=Vr(r),l=N(()=>Ft(e,a),[e,a]);return t(L,{children:l})};function Lr({form:e,selector:r=(l)=>l,children:a}){let l=Re(e.store,r);return t(L,{children:Ft(a,l)})}function $t(e){let r=Ns(),[a,l]=u(e?.formId),[s,d]=u(()=>new na({...e,formId:e?.formId??r}));if(a!==e?.formId){let _=e?.formId??r;d(new na({...e,formId:_})),l(_)}let c=N(()=>{let _={...s,handleSubmit:(...p)=>s._handleSubmit(...p),get formId(){return s._formId},get state(){return s.store.state}};return _.Field=function(b){return t(_s,{...b,form:s})},_.FormGroup=function(b){return t(Ss,{...b,form:s})},_.Subscribe=function(b){return t(Lr,{form:s,selector:b.selector,children:b.children})},_},[s]);wt(s.mount,[]),wt(()=>{s.update(e)});let g=y(!1);return wt(()=>{if(!g.current)return;if(!e?.transform)return;Wa(s,e.transform)},[s,e?.transform]),wt(()=>{g.current=!0}),c}S();var Pr=R({name:f().min(1,Fx()),type:Ve(["chat","autofill","embedding"]),permission:Ve(["owner","editor","reviewer"]),avatar:f().optional(),providerId:f().optional(),modelId:f().optional(),soul:f().optional(),thinkingLevel:nu.optional(),systemPrompt:f().optional(),skills:te(f()).optional(),mcpServerIds:te(f()).optional(),deniedTools:te(f()).optional()}),Rr=[{id:"bash",name:()=>y0(),description:()=>_0()},{id:"read_skill",name:()=>k0(),description:()=>M0()},{id:"read_asset",name:()=>zm(),description:()=>T0()},{id:"list_assets",name:()=>Bm(),description:()=>C0()},{id:"create_folder",name:()=>Dm(),description:()=>v0()},{id:"create_file",name:()=>Nm(),description:()=>b0()},{id:"create_version",name:()=>Om(),description:()=>w0()},{id:"generate_image",name:()=>Lm(),description:()=>S0()},{id:"generate_video",name:()=>Zm(),description:()=>E0()},{id:"rename_asset",name:()=>jm(),description:()=>R0()},{id:"move_assets",name:()=>Um(),description:()=>I0()},{id:"delete_asset",name:()=>Fm(),description:()=>x0()}];function ks({isOpen:e,onClose:r,teamId:a,type:l,initialValues:s,title:d}){let c=Q(),{canAdmin:g}=Dt(),{data:_}=Z({queryKey:["teams",a,"providers"],queryFn:async()=>{let G=await A.api.teams[":teamId"].providers.$get({param:{teamId:a}});if(!G.ok)throw Error("Failed to fetch providers");return await G.json()},enabled:e}),{data:p}=Z({queryKey:["teams",a,"skills"],queryFn:async()=>{let G=await A.api.teams[":teamId"].skills.$get({param:{teamId:a}});if(!G.ok)throw Error("Failed to fetch skills");return await G.json()},enabled:e}),b=p?.skills||[],{data:x}=Z({queryKey:["teams",a,"mcp","servers"],queryFn:async()=>{let G=await A.api.teams[":teamId"].mcp.servers.$get({param:{teamId:a}});if(!G.ok)throw Error("Failed to fetch MCP servers");return await G.json()},enabled:e}),m=x?.servers||[],i=N(()=>Pr.superRefine((G,ee)=>{if(G.type==="chat"||G.type==="autofill"){if(!G.providerId)ee.addIssue({code:ro.custom,message:kE(),path:["providerId"]});if(!G.modelId)ee.addIssue({code:ro.custom,message:Ex(),path:["modelId"]})}}),[]),v=$t({defaultValues:{name:s?.name||"",type:s?.type||l||"chat",permission:s?.permission||"reviewer",avatar:s?.avatarPreset||s?.avatar||ru[0].id,providerId:s?.providerId||"",modelId:s?.modelId||"",soul:s?.soul||"",thinkingLevel:s?.thinkingLevel||"off",systemPrompt:s?.systemPrompt||"",skills:s?.skills?.map((G)=>G.skillId)||[],mcpServerIds:s?.mcpServerIds||[],deniedTools:s?.deniedTools??[...CA]},validators:{onChange:i},onSubmit:async({value:G})=>{try{if(s?.id)await Fe.mutateAsync({id:s.id,values:G});else await Ee.mutateAsync(G)}catch{}}}),w=da(v.store,(G)=>G.values.providerId),{data:k,isLoading:z}=Z({queryKey:["teams",a,"providers",w,"models"],queryFn:async()=>{let G=await A.api.providers[":id"].models.$get({param:{id:w}});if(!G.ok)throw Error("Failed to fetch models");return await G.json()},enabled:!!w&&e}),[J,H]=u(""),[ie,oe]=u(!1),T=N(()=>{if(!_)return[];return[..._].sort((G,ee)=>G.name.toLowerCase().localeCompare(ee.name.toLowerCase()))},[_]),P=N(()=>{if(!J.trim())return T;let G=J.toLowerCase();return T.filter((ee)=>ee.name.toLowerCase().includes(G))},[T,J]),[j,X]=u(""),[F,Y]=u(!1),ye=N(()=>{if(!k)return[];return[...k].sort((G,ee)=>{let xe=(G.name||G.modelId).toLowerCase(),de=(ee.name||ee.modelId).toLowerCase();return xe.localeCompare(de)})},[k]),me=N(()=>{if(!j.trim())return ye;let G=j.toLowerCase();return ye.filter((ee)=>ee.modelId.toLowerCase().includes(G)||ee.name&&ee.name.toLowerCase().includes(G))},[ye,j]),Ee=B({mutationFn:async(G)=>{let ee=await A.api.teams[":teamId"].agents.$post({param:{teamId:a},json:G});if(!ee.ok)throw Error("Failed to create agent");return await ee.json()},onSuccess:()=>{r(),c.invalidateQueries({queryKey:["agents",a]}),M.success(l0())},onError:(G)=>{M.error(zs({message:G.message}))}}),Fe=B({mutationFn:async({id:G,values:ee})=>{let xe=await A.api.agents[":agentId"].$put({param:{agentId:G},json:ee});if(!xe.ok)throw Error("Failed to update agent");return await xe.json()},onSuccess:()=>{r(),c.invalidateQueries({queryKey:["agents",a]}),M.success(Gm())},onError:(G)=>{M.error(zs({message:G.message}))}});h(()=>{if(e)v.reset(),H(""),oe(!1),X(""),Y(!1)},[e,s,l]);let se=da(v.store,(G)=>G.values.type),ke=se==="chat"||se==="autofill",je=se==="chat",He=(G)=>G.map((ee)=>{if(typeof ee==="string")return{message:ee};if(ee&&typeof ee==="object"&&"message"in ee)return{message:String(ee.message)};return{message:String(ee||"")}});return t(ue,{open:e,onOpenChange:r,children:o(ae,{className:"sm:max-w-3xl h-[90vh] flex flex-col p-0 overflow-hidden",children:[o(fe,{className:"p-6 pb-2 flex-shrink-0",children:[t(le,{children:d}),t(It,{children:K_()})]}),o("form",{onSubmit:(G)=>{G.preventDefault(),G.stopPropagation(),v.handleSubmit()},className:"flex-1 flex flex-col min-h-0 overflow-hidden",children:[t(ce,{className:"flex-1 min-h-0",children:o("div",{className:"p-6 pt-2 space-y-6",children:[o("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[t(v.Field,{name:"name",children:(G)=>{let ee=!!G.state.meta.errors.length&&G.state.meta.isTouched;return o(Oe,{"data-invalid":ee,children:[t(Qe,{children:d0()}),t(q,{value:G.state.value,onBlur:G.handleBlur,onChange:(xe)=>G.handleChange(xe.target.value),placeholder:f0(),"aria-invalid":ee}),ee&&t(We,{errors:He(G.state.meta.errors)})]})}}),t(v.Field,{name:"type",children:(G)=>o(Oe,{children:[t(Qe,{children:D0()}),o(Le,{value:G.state.value,onValueChange:(ee)=>G.handleChange(ee),disabled:!0,children:[t(Be,{className:"bg-muted/50",children:t(Ze,{})}),o(Ue,{children:[t(ne,{value:"chat",children:Hm()}),t(ne,{value:"autofill",children:qm()}),t(ne,{value:"embedding",children:$m()})]})]})]})}),je&&t(v.Field,{name:"permission",children:(G)=>o(Oe,{children:[t(Qe,{children:Dp()}),o(Le,{value:G.state.value||"reviewer",onValueChange:(ee)=>G.handleChange(ee),disabled:!g,children:[t(Be,{children:t(Ze,{})}),o(Ue,{children:[t(ne,{value:"reviewer",children:Fa()}),t(ne,{value:"editor",children:La()}),t(ne,{value:"owner",children:Za()})]})]})]})}),t(v.Field,{name:"avatar",children:(G)=>o(Oe,{className:"md:col-span-2",children:[t(Qe,{children:a0()}),o("div",{className:"flex flex-wrap gap-4 mt-2",children:[ru.map((ee)=>{let xe=G.state.value===ee.id;return t("button",{type:"button",onClick:()=>G.handleChange(ee.id),className:C("relative w-14 h-14 rounded-full overflow-hidden border-2 transition-all hover:scale-105",xe?"border-primary ring-2 ring-primary ring-offset-2":"border-border hover:border-muted-foreground"),children:t("img",{src:ee.preview,className:"w-full h-full object-cover",alt:uE()})},ee.id)}),G.state.value&&!ru.some((ee)=>ee.id===G.state.value)&&t("button",{type:"button",className:"relative w-14 h-14 rounded-full overflow-hidden border-2 border-primary ring-2 ring-primary ring-offset-2 scale-105",children:t("img",{src:G.state.value,className:"w-full h-full object-cover",alt:Iy()})})]})]})})]}),ke&&o(L,{children:[o("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6 p-4 bg-muted/50 rounded-xl border border-border",children:[t(v.Field,{name:"providerId",children:(G)=>{let ee=!!G.state.meta.errors.length&&G.state.meta.isTouched,xe=_?.find((de)=>de.id===G.state.value);return o(Oe,{"data-invalid":ee,children:[t(Qe,{children:IE()}),o(ht,{open:ie,onOpenChange:(de)=>{if(oe(de),!de)H("")},modal:!0,children:[t(gt,{asChild:!0,children:o(E,{type:"button",variant:"outline",role:"combobox","aria-expanded":ie,"aria-invalid":ee,className:C("w-full justify-between font-normal h-10 px-3 bg-background border-border hover:bg-accent/50",ee&&"border-destructive ring-destructive"),children:[t("span",{className:"truncate",children:xe?t("span",{className:"font-medium text-foreground truncate",children:xe.name}):t("span",{className:"text-muted-foreground",children:nI()})}),t(ve,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),o(At,{className:"w-[--radix-popover-trigger-width] min-w-[320px] max-h-[360px] p-0 flex flex-col overflow-hidden",align:"start",side:"bottom",sideOffset:4,onWheel:(de)=>de.stopPropagation(),children:[o("div",{className:"relative p-2 pb-1.5 border-b border-border shrink-0",children:[t(Ut,{className:"absolute left-4.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-muted-foreground"}),t(q,{placeholder:Xg(),value:J,onChange:(de)=>H(de.target.value),className:"pl-8 h-8 text-xs bg-muted/40",autoFocus:!0})]}),t(ce,{className:"w-full p-1",style:{height:P.length===0?"96px":`${Math.min(P.length*38+8,256)}px`},onWheel:(de)=>de.stopPropagation(),children:P.length===0?t("div",{className:"flex items-center justify-center h-full py-6 text-xs text-muted-foreground",children:cS()}):t("div",{className:"space-y-0.5 pr-2",children:P.map((de)=>{let Ke=G.state.value===de.id;return o("div",{onClick:()=>{G.handleChange(de.id),v.setFieldValue("modelId",""),X(""),oe(!1),H("")},className:C("flex items-center justify-between px-2.5 py-2 rounded-md text-xs cursor-pointer transition-colors",Ke?"bg-accent text-accent-foreground font-medium":"hover:bg-muted/60 text-foreground"),children:[t("span",{className:"truncate flex-1 pr-2",children:de.name}),Ke&&t(Pe,{className:"w-4 h-4 text-primary shrink-0"})]},de.id)})})})]})]}),ee&&t(We,{errors:He(G.state.meta.errors)})]})}}),t(v.Field,{name:"modelId",children:(G)=>{let ee=!!G.state.meta.errors.length&&G.state.meta.isTouched,xe=k?.find((de)=>de.id===G.state.value);return o(Oe,{"data-invalid":ee,children:[o(Qe,{className:"flex items-center gap-2",children:[bx(),z&&t(O,{className:"w-3 h-3 animate-spin"})]}),o(ht,{open:F,onOpenChange:(de)=>{if(Y(de),!de)X("")},modal:!0,children:[t(gt,{asChild:!0,children:o(E,{type:"button",variant:"outline",role:"combobox","aria-expanded":F,"aria-invalid":ee,disabled:!w||z,className:C("w-full justify-between font-normal h-10 px-3 bg-background border-border hover:bg-accent/50",ee&&"border-destructive ring-destructive"),children:[t("span",{className:"truncate flex items-center gap-2",children:xe?o(L,{children:[t("span",{className:"truncate font-medium text-foreground",children:xe.name||xe.modelId}),xe.name&&xe.name!==xe.modelId&&t(be,{variant:"secondary",className:"font-mono text-[10px] px-1.5 py-0 shrink-0",children:xe.modelId})]}):t("span",{className:"text-muted-foreground",children:XC()})}),t(ve,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),o(At,{className:"w-[--radix-popover-trigger-width] min-w-[320px] max-h-[360px] p-0 flex flex-col overflow-hidden",align:"start",side:"bottom",sideOffset:4,onWheel:(de)=>de.stopPropagation(),children:[o("div",{className:"relative p-2 pb-1.5 border-b border-border shrink-0",children:[t(Ut,{className:"absolute left-4.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-muted-foreground"}),t(q,{placeholder:Rp(),value:j,onChange:(de)=>X(de.target.value),className:"pl-8 h-8 text-xs bg-muted/40",autoFocus:!0})]}),t(ce,{className:"w-full p-1",style:{height:me.length===0?"96px":`${Math.min(me.length*38+8,256)}px`},onWheel:(de)=>de.stopPropagation(),children:me.length===0?t("div",{className:"flex items-center justify-center h-full py-6 text-xs text-muted-foreground",children:Cd()}):t("div",{className:"space-y-0.5 pr-2",children:me.map((de)=>{let Ke=G.state.value===de.id;return o("div",{onClick:()=>{G.handleChange(de.id),Y(!1),X("")},className:C("flex items-center justify-between px-2.5 py-2 rounded-md text-xs cursor-pointer transition-colors",Ke?"bg-accent text-accent-foreground font-medium":"hover:bg-muted/60 text-foreground"),children:[t("div",{className:"min-w-0 flex-1 pr-2",children:o("div",{className:"flex items-center gap-2",children:[t("span",{className:"truncate",children:de.name||de.modelId}),de.name&&de.name!==de.modelId&&o("span",{className:"font-mono text-[10px] text-muted-foreground truncate",children:["(",de.modelId,")"]}),de.config?.reasoning&&t(be,{variant:"outline",className:"text-[9px] px-1 py-0 h-4 gap-0.5 bg-primary/10 text-primary border-primary/20 shrink-0",children:t(qt,{className:"w-2.5 h-2.5"})})]})}),Ke&&t(Pe,{className:"w-4 h-4 text-primary shrink-0"})]},de.id)})})})]})]}),ee&&t(We,{errors:He(G.state.meta.errors)})]})}}),t("div",{className:"md:col-span-2",children:t(v.Field,{name:"thinkingLevel",children:(G)=>{let ee={off:PT(),low:OT(),medium:FT(),high:NT()};return o(Oe,{children:[t(Qe,{children:DT()}),o(Le,{value:G.state.value,onValueChange:(xe)=>G.handleChange(xe),children:[t(Be,{children:t(Ze,{})}),t(Ue,{children:nu.options.map((xe)=>t(ne,{value:xe,children:ee[xe]||xe},xe))})]})]})}})})]}),t(v.Field,{name:"soul",children:(G)=>o(Oe,{children:[t(Qe,{children:g0()}),t(wi,{value:G.state.value,onBlur:G.handleBlur,onChange:(ee)=>G.handleChange(ee.target.value),placeholder:A0(),className:"min-h-[120px]"})]})}),o("div",{className:"space-y-4",children:[o(W,{className:"text-base font-bold flex items-center gap-2",children:[t(Nt,{className:"w-5 h-5 text-primary"}),lA()]}),t("div",{className:"space-y-2",children:t(v.Field,{name:"skills",children:(G)=>o(L,{children:[b.map((ee)=>{let xe=G.state.value?.includes(ee.id)||!1;return o("div",{className:"flex items-center justify-between p-3 bg-muted/30 border border-border rounded-lg",children:[o("div",{className:"flex items-center gap-3",children:[t(Nt,{className:"w-4 h-4 text-muted-foreground"}),o("div",{className:"flex flex-col",children:[t("span",{className:"text-sm font-medium",children:ee.name}),ee.description&&t("span",{className:"text-[10px] text-muted-foreground line-clamp-1",children:ee.description})]})]}),o("div",{className:"flex items-center gap-2",children:[t("span",{className:"text-xs text-muted-foreground",children:xe?Bf():Lf()}),t(Me,{checked:xe,onCheckedChange:(de)=>{if(de)G.handleChange([...G.state.value||[],ee.id]);else G.handleChange((G.state.value||[]).filter((Ke)=>Ke!==ee.id))}})]})]},ee.id)}),b.length===0&&t("div",{className:"text-center py-8 border-2 border-dashed border-border rounded-xl",children:t("p",{className:"text-sm text-muted-foreground",children:pS()})})]})})})]}),o("div",{className:"space-y-4 border-t border-border pt-6",children:[o(W,{className:"text-base font-bold flex items-center gap-2",children:[t(vn,{className:"w-5 h-5 text-primary"}),Hc()]}),t("div",{className:"space-y-2",children:t(v.Field,{name:"mcpServerIds",children:(G)=>o(L,{children:[m.map((ee)=>{let xe=G.state.value?.includes(ee.id)||!1,de=ee.status==="needs_auth"||!ee.hasCredential&&ee.authType==="oauth";return o("div",{className:"flex items-center justify-between p-3 bg-muted/30 border border-border rounded-lg",children:[o("div",{className:"flex items-center gap-3",children:[t(vn,{className:"w-4 h-4 text-muted-foreground"}),o("div",{className:"flex flex-col",children:[o("div",{className:"flex items-center gap-2",children:[t("span",{className:"text-sm font-medium",children:ee.name}),o(be,{variant:"outline",className:"text-[10px]",children:[ee.toolCount??0," tools"]}),de&&t(be,{variant:"secondary",className:"text-[10px] bg-amber-500/10 text-amber-600 border-amber-500/20",children:Yh()})]}),t("span",{className:"text-[10px] font-mono text-muted-foreground line-clamp-1",children:ee.url})]})]}),o("div",{className:"flex items-center gap-2",children:[t("span",{className:"text-xs text-muted-foreground",children:xe?Bf():Lf()}),t(Me,{checked:xe,onCheckedChange:(Ke)=>{if(Ke)G.handleChange([...G.state.value||[],ee.id]);else G.handleChange((G.state.value||[]).filter((bt)=>bt!==ee.id))}})]})]},ee.id)}),m.length===0&&t("div",{className:"text-center py-6 border-2 border-dashed border-border rounded-xl",children:t("p",{className:"text-xs text-muted-foreground",children:pg()})})]})})})]}),o("div",{className:"space-y-4 border-t border-border pt-6",children:[o(W,{className:"text-base font-bold flex items-center gap-2",children:[t(To,{className:"w-5 h-5 text-primary"}),P0()]}),t("p",{className:"text-xs text-muted-foreground",children:N0()}),t("div",{className:"space-y-2",children:t(v.Field,{name:"deniedTools",children:(G)=>{let ee=G.state.value||[];return t(L,{children:Rr.map((xe)=>{let de=!ee.includes(xe.id);return o("div",{className:"flex items-center justify-between p-3 bg-muted/30 border border-border rounded-lg",children:[o("div",{className:"flex items-center gap-3",children:[t(To,{className:"w-4 h-4 text-muted-foreground"}),o("div",{className:"flex flex-col",children:[t("span",{className:"text-sm font-medium",children:xe.name()}),t("span",{className:"text-[10px] text-muted-foreground line-clamp-1",children:xe.description()})]})]}),o("div",{className:"flex items-center gap-2",children:[t("span",{className:"text-xs text-muted-foreground",children:de?Bf():Lf()}),t(Me,{checked:de,disabled:!g,onCheckedChange:(Ke)=>{if(Ke)G.handleChange(ee.filter((bt)=>bt!==xe.id));else G.handleChange([...ee,xe.id])}})]})]},xe.id)})})}})})]})]})]})}),o(qe,{className:"p-6 pt-4 border-t border-border flex-shrink-0",children:[t(E,{variant:"outline",onClick:r,type:"button",children:De()}),t(v.Subscribe,{selector:(G)=>[G.canSubmit,G.isSubmitting],children:([G,ee])=>o(E,{type:"submit",className:"bg-primary hover:bg-primary/90 text-primary-foreground min-w-[120px]",disabled:!G||ee||Ee.isPending||Fe.isPending,children:[(ee||Ee.isPending||Fe.isPending)&&t(O,{className:"w-4 h-4 animate-spin mr-2"}),s?qs():my()]})})]})]})]})})}var Br=[{type:"chat",label:"Chat",icon:vo},{type:"autofill",label:"Autofill",icon:qt},{type:"embedding",label:"Embedding",icon:io}];function Ms({teamId:e}){let r=Q(),{canAdmin:a}=Dt(),[l,s]=u(!1),[d,c]=u("chat"),[g,_]=u(null),[p,b]=u(null),[x,m]=u(!1),[i,v]=u({chat:!0,autofill:!0,embedding:!0}),w=(T)=>{if(T==="chat")return Hm();if(T==="autofill")return qm();return $m()},{data:k=[],isLoading:z}=Z({queryKey:["agents",e],queryFn:async()=>{let T=await A.api.teams[":teamId"].agents.$get({param:{teamId:e}});if(!T.ok)throw Error("failed to fetch agents");return[...await T.json()].sort((j,X)=>X.id.localeCompare(j.id))}}),J=B({mutationFn:async(T)=>{if(!(await A.api.agents[":agentId"].$delete({param:{agentId:T}})).ok)throw Error("failed to delete agent")},onSuccess:()=>{m(!1),r.invalidateQueries({queryKey:["agents",e]}),M.success(c0())},onError:(T)=>{M.error(T.message)}}),H=B({mutationFn:async({agentId:T,permission:P})=>{let j=await A.api.agents[":agentId"].permission.$patch({param:{agentId:T},json:{permission:P}});if(!j.ok)throw Error(bl());return j.json()},onSuccess:()=>{r.invalidateQueries({queryKey:["agents",e]})},onError:(T)=>{M.error(T.message||bl())}}),ie=B({mutationFn:async(T)=>{let P=await A.api.agents[":agentId"].$put({param:{agentId:T.agentId},json:{name:T.name,type:T.type,enabled:T.enabled,avatar:T.avatar,providerId:T.providerId,modelId:T.modelId,thinkingLevel:T.thinkingLevel,systemPrompt:T.systemPrompt,soul:T.soul,skills:T.skills,deniedTools:T.deniedTools}});if(!P.ok)throw Error("failed to update agent");return P.json()},onSuccess:()=>{r.invalidateQueries({queryKey:["agents",e]}),M.success(Gm())},onError:(T)=>{M.error(T.message)}}),oe=(T)=>{v((P)=>({...P,[T]:!P[T]}))};return o(L,{children:[(l||g)&&t(ks,{isOpen:!0,title:g?_h({name:g.name}):xy({type:w(d)}),onClose:()=>{s(!1),_(null)},teamId:e,type:d,initialValues:g||void 0}),t(Je,{open:x,onOpenChange:m,children:o(Xe,{children:[o(et,{children:[t(rt,{children:dd()}),t(nt,{children:zy({name:p?.name??""})})]}),o(tt,{children:[t(st,{children:De()}),t(ot,{className:"bg-destructive hover:bg-destructive/90 text-white",onClick:(T)=>{if(J.isPending){T.preventDefault();return}if(p)J.mutate(p.id)},children:J.isPending?t(O,{className:"w-4 h-4 animate-spin"}):Uy()})]})]})}),z&&k.length===0?t("div",{className:"flex items-center justify-center p-12",children:t(O,{className:"w-8 h-8 animate-spin text-muted-foreground"})}):o("div",{className:"space-y-6 max-w-5xl mx-auto relative",children:[z&&t("div",{className:"absolute top-0 right-0 p-2",children:t(O,{className:"w-4 h-4 animate-spin text-muted-foreground"})}),Br.map((T)=>{let P=k.filter((F)=>F.type===T.type),j=T.icon,X=T.type==="autofill"||T.type==="embedding";return o("div",{className:"bg-card rounded-xl border border-border overflow-hidden",children:[o("div",{className:C("px-6 py-4 flex items-center justify-between",!X&&"cursor-pointer hover:bg-muted/50 transition-colors"),onClick:!X?()=>oe(T.type):void 0,children:[o("div",{className:"flex items-center gap-2",children:[t("h3",{className:"font-semibold text-foreground",children:T.type==="chat"?L_():T.type==="autofill"?h_():yb()}),!X&&t(be,{variant:"secondary",className:"h-5 px-1.5 min-w-[1.25rem] text-[10px]",children:P.length})]}),o("div",{className:"flex items-center gap-2",children:[!(X&&P.length>0)&&t(E,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-full bg-primary/10 text-primary hover:bg-primary/20",onClick:(F)=>{F.stopPropagation(),c(T.type),s(!0)},children:t(pe,{className:"w-4 h-4"})}),!X&&t(ve,{className:C("w-5 h-5 text-muted-foreground transition-transform duration-200",i[T.type]?"rotate-180":"")})]})]}),(X||i[T.type])&&t("div",{className:"px-6 pb-6 pt-2 space-y-3",children:o("div",{className:"grid grid-cols-1 gap-4",children:[P.map((F)=>t(ut,{className:"group relative overflow-hidden border-border hover:border-primary/50 transition-all duration-200 cursor-pointer pb-1 pt-1",onClick:()=>_(F),children:o(xt,{className:"p-4 flex flex-col gap-3",children:[o("div",{className:"flex items-center justify-between",children:[o("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[t("div",{className:"w-10 h-10 rounded-full bg-muted flex items-center justify-center overflow-hidden",children:F.avatar?t("img",{src:F.avatar,className:"w-full h-full object-cover",alt:""}):t(Ct,{className:"w-6 h-6 text-muted-foreground"})}),o("div",{className:"min-w-0 flex-1",children:[t("span",{className:"font-bold text-foreground block truncate",children:F.name}),t("div",{className:"flex items-center gap-2 text-xs text-muted-foreground mt-0.5",children:o("span",{className:"flex items-center gap-1",children:[t(Nt,{className:"w-3 h-3"}),TI({count:F.skills?.length||0})]})})]})]}),o(he,{modal:!1,children:[t(ge,{asChild:!0,onClick:(Y)=>Y.stopPropagation(),children:t(E,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-foreground",children:t(Sr,{className:"w-4 h-4"})})}),t(Ae,{align:"end",className:"w-32",children:o(K,{onClick:(Y)=>{Y.stopPropagation(),b(F),m(!0)},className:"text-red-500 focus:text-red-500 gap-2 cursor-pointer",children:[t(we,{className:"w-4 h-4"})," ",at()]})})]})]}),o("div",{className:"flex items-center justify-between gap-2 pt-2 border-t border-border/50",children:[t("div",{children:F.type==="chat"?t("div",{onClick:(Y)=>Y.stopPropagation(),children:o(Le,{value:F.permission||"reviewer",onValueChange:(Y)=>{H.mutate({agentId:F.id,permission:Y})},disabled:!a,children:[t(Be,{className:"h-7 text-xs px-2 bg-background border-border w-[140px]",children:t(Ze,{children:F.permission==="reviewer"?Fa():F.permission==="editor"?La():Za()})}),o(Ue,{align:"start",children:[t(ne,{value:"reviewer",children:Fa()}),t(ne,{value:"editor",children:La()}),t(ne,{value:"owner",children:Za()})]})]})}):t("div",{})}),t("div",{onClick:(Y)=>Y.stopPropagation(),children:t(Me,{checked:F.enabled,onCheckedChange:(Y)=>{ie.mutate({teamId:e,agentId:F.id,name:F.name,type:F.type,enabled:Y,avatar:F.avatar,providerId:F.providerId,modelId:F.modelId,thinkingLevel:F.thinkingLevel,systemPrompt:F.systemPrompt,soul:F.soul,skills:F.skills?.map((ye)=>ye.skillId),deniedTools:F.deniedTools})}})})]})]})},F.id)),P.length===0&&o("div",{className:"col-span-full py-8 flex flex-col items-center justify-center border-2 border-dashed border-border rounded-xl bg-muted/30",children:[t("div",{className:"w-10 h-10 rounded-full bg-card flex items-center justify-center shadow-sm mb-3",children:t(j,{className:"w-5 h-5 text-muted-foreground"})}),t("p",{className:"text-sm text-muted-foreground",children:Kx({type:w(T.type)})}),t(E,{variant:"link",size:"sm",className:"text-primary font-medium h-auto p-0 mt-1",onClick:()=>{c(T.type),s(!0)},children:yy()})]})]})})]},T.type)})]})]})}S();S();function Ca({isOpen:e,onClose:r,onSubmit:a,initialValues:l,title:s,isLoading:d=!1,defaultApi:c,existingModelIds:g=[]}){let _=N(()=>IA.extend({modelId:f().min(1,eg()).refine((m)=>{if(l?.modelId===m)return!0;return!g.includes(m)},{message:xx()})}),[g,l]),p=()=>l||{modelId:"",name:"",config:{api:c,reasoning:!1,input:["text"],contextWindow:128000,maxTokens:4096,cost:{input:0,output:0,cacheRead:0,cacheWrite:0}}},b=$t({defaultValues:p(),validators:{onSubmit:_},onSubmit:async({value:m})=>{a(m)}});h(()=>{if(e)b.reset(p())},[e,l,c,b]);let x=(m)=>m.map((i)=>{if(typeof i==="string")return{message:i};if(i&&typeof i==="object"&&"message"in i)return{message:String(i.message)};return{message:String(i||"")}});return t(ue,{open:e,onOpenChange:r,children:o(ae,{className:"sm:max-w-xl h-[85vh] max-h-[700px] flex flex-col p-0 overflow-hidden",children:[t(fe,{className:"p-6 pb-2 shrink-0",children:t(le,{className:"text-xl",children:s})}),o("form",{onSubmit:(m)=>{m.preventDefault(),m.stopPropagation(),b.handleSubmit()},className:"flex-1 flex flex-col min-h-0 overflow-hidden",children:[t("div",{className:"flex-1 min-h-0",children:t(ce,{className:"h-full",children:o("div",{className:"p-6 pt-2 space-y-6 pr-6",children:[o("div",{className:"space-y-4",children:[t(b.Field,{name:"modelId",children:(m)=>{let i=!!m.state.meta.errors.length&&m.state.meta.isTouched;return o(Oe,{"data-invalid":i,children:[t(Qe,{htmlFor:m.name,children:eg()}),t(q,{id:m.name,name:m.name,value:m.state.value,onBlur:m.handleBlur,onChange:(v)=>m.handleChange(v.target.value),placeholder:Sx(),"aria-invalid":i}),i&&t(We,{errors:x(m.state.meta.errors)})]})}}),t(b.Field,{name:"name",children:(m)=>{let i=!!m.state.meta.errors.length&&m.state.meta.isTouched;return o(Oe,{"data-invalid":i,children:[t(Qe,{htmlFor:m.name,children:ab()}),t(q,{id:m.name,name:m.name,value:m.state.value||"",onBlur:m.handleBlur,onChange:(v)=>m.handleChange(v.target.value),placeholder:Cx(),"aria-invalid":i}),i&&t(We,{errors:x(m.state.meta.errors)})]})}})]}),o("div",{className:"space-y-4 pt-2 border-t border-border",children:[t("h4",{className:"text-sm font-semibold text-foreground",children:KS()}),t(b.Field,{name:"config.reasoning",children:(m)=>o(Oe,{orientation:"horizontal",className:"rounded-lg border border-border p-3 shadow-sm bg-muted/40 justify-between flex items-center",children:[t(Qe,{htmlFor:m.name,className:"cursor-pointer",children:Ep()}),t(Me,{id:m.name,checked:m.state.value,onCheckedChange:m.handleChange})]})}),o("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[t(b.Field,{name:"config.contextWindow",children:(m)=>{let i=!!m.state.meta.errors.length&&m.state.meta.isTouched;return o(Oe,{"data-invalid":i,children:[t(Qe,{htmlFor:m.name,className:"text-xs",children:ny()}),t(q,{id:m.name,name:m.name,type:"number",value:m.state.value,onBlur:m.handleBlur,onChange:(v)=>m.handleChange(parseInt(v.target.value)||0),"aria-invalid":i}),i&&t(We,{errors:x(m.state.meta.errors)})]})}}),t(b.Field,{name:"config.maxTokens",children:(m)=>{let i=!!m.state.meta.errors.length&&m.state.meta.isTouched;return o(Oe,{"data-invalid":i,children:[t(Qe,{htmlFor:m.name,className:"text-xs",children:Lw()}),t(q,{id:m.name,name:m.name,type:"number",value:m.state.value,onBlur:m.handleBlur,onChange:(v)=>m.handleChange(parseInt(v.target.value)||0),"aria-invalid":i}),i&&t(We,{errors:x(m.state.meta.errors)})]})}})]})]}),o("div",{className:"space-y-4 pt-2 border-t border-border",children:[o("h4",{className:"text-sm font-semibold text-foreground flex items-center gap-1.5",children:[t(ma,{className:"w-4 h-4 text-primary"}),dE()]}),o("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[t(b.Field,{name:"config.cost.input",children:(m)=>{let i=!!m.state.meta.errors.length&&m.state.meta.isTouched;return o(Oe,{"data-invalid":i,children:[t(Qe,{htmlFor:m.name,className:"text-xs",children:dw()}),t(q,{id:m.name,name:m.name,type:"number",step:"0.0001",value:m.state.value,onBlur:m.handleBlur,onChange:(v)=>m.handleChange(parseFloat(v.target.value)||0),"aria-invalid":i}),i&&t(We,{errors:x(m.state.meta.errors)})]})}}),t(b.Field,{name:"config.cost.output",children:(m)=>{let i=!!m.state.meta.errors.length&&m.state.meta.isTouched;return o(Oe,{"data-invalid":i,children:[t(Qe,{htmlFor:m.name,className:"text-xs",children:HS()}),t(q,{id:m.name,name:m.name,type:"number",step:"0.0001",value:m.state.value,onBlur:m.handleBlur,onChange:(v)=>m.handleChange(parseFloat(v.target.value)||0),"aria-invalid":i}),i&&t(We,{errors:x(m.state.meta.errors)})]})}}),t(b.Field,{name:"config.cost.cacheRead",children:(m)=>{let i=!!m.state.meta.errors.length&&m.state.meta.isTouched;return o(Oe,{"data-invalid":i,children:[t(Qe,{htmlFor:m.name,className:"text-xs",children:P_()}),t(q,{id:m.name,name:m.name,type:"number",step:"0.0001",value:m.state.value,onBlur:m.handleBlur,onChange:(v)=>m.handleChange(parseFloat(v.target.value)||0),"aria-invalid":i}),i&&t(We,{errors:x(m.state.meta.errors)})]})}}),t(b.Field,{name:"config.cost.cacheWrite",children:(m)=>{let i=!!m.state.meta.errors.length&&m.state.meta.isTouched;return o(Oe,{"data-invalid":i,children:[t(Qe,{htmlFor:m.name,className:"text-xs",children:N_()}),t(q,{id:m.name,name:m.name,type:"number",step:"0.0001",value:m.state.value,onBlur:m.handleBlur,onChange:(v)=>m.handleChange(parseFloat(v.target.value)||0),"aria-invalid":i}),i&&t(We,{errors:x(m.state.meta.errors)})]})}})]})]})]})})}),o(qe,{className:"p-6 pt-4 border-t border-border gap-2 shrink-0",children:[t(E,{type:"button",variant:"outline",onClick:r,disabled:d,children:De()}),t(b.Subscribe,{selector:(m)=>[m.canSubmit,m.isSubmitting],children:([m,i])=>t(E,{type:"submit",className:"min-w-[100px]",disabled:!m||i||d,children:i||d?t(O,{className:"w-4 h-4 animate-spin"}):qs()})})]})]})]})})}S();function Fs({isOpen:e,onClose:r,teamId:a,syncData:l,onSuccess:s}){let[d,c]=u(""),[g,_]=u(()=>new Set(l?.providers.map((P)=>P.name)||[])),[p,b]=u(()=>{let P=new Set;return l?.providers.forEach((j)=>{j.models.forEach((X)=>{P.add(`${j.name}:${X.modelId}`)})}),P});h(()=>{if(l){_(new Set(l.providers.map((j)=>j.name)));let P=new Set;l.providers.forEach((j)=>{j.models.forEach((X)=>{P.add(`${j.name}:${X.modelId}`)})}),b(P)}},[l]);let x=N(()=>{if(!l)return[];let P=d.trim().toLowerCase();if(!P)return l.providers;return l.providers.map((j)=>{let X=j.name.toLowerCase().includes(P),F=j.models.filter((Y)=>X||Y.modelId.toLowerCase().includes(P)||Y.name.toLowerCase().includes(P));if(F.length>0)return{...j,models:F};return null}).filter((j)=>j!==null)},[l,d]),m=p.size,i=N(()=>{if(!l)return 0;let P=0;for(let j of l.providers)if(j.models.some((F)=>p.has(`${j.name}:${F.modelId}`)))P++;return P},[l,p]),v=(P)=>{_((j)=>{let X=new Set(j);if(X.has(P))X.delete(P);else X.add(P);return X})},w=()=>{if(!l)return;_(new Set(l.providers.map((P)=>P.name)))},k=()=>{_(new Set)},z=(P,j)=>{let X=`${P}:${j}`;b((F)=>{let Y=new Set(F);if(Y.has(X))Y.delete(X);else Y.add(X);return Y})},J=(P)=>{let j=l?.providers.find((F)=>F.name===P);if(!j||j.models.length===0)return;let X=j.models.every((F)=>p.has(`${P}:${F.modelId}`));b((F)=>{let Y=new Set(F);return j.models.forEach((ye)=>{let me=`${P}:${ye.modelId}`;if(X)Y.delete(me);else Y.add(me)}),Y})},H=()=>{if(!l)return;let P=new Set;l.providers.forEach((j)=>{j.models.forEach((X)=>{P.add(`${j.name}:${X.modelId}`)})}),b(P)},ie=()=>{b(new Set)},oe=B({mutationFn:async(P)=>{let j=await A.api.teams[":teamId"].providers["sync-apply"].$post({param:{teamId:a},json:P});if(!j.ok){let X=await j.json().catch(()=>({message:"Failed to apply sync"}));throw Error(X.message||"Failed to apply sync")}return await j.json()},onSuccess:(P)=>{M.success(hT({modelCount:P.addedModels,providerCount:P.addedProviders})),s(),r()},onError:(P)=>{M.error(P.message)}}),T=async()=>{if(!l||m===0)return;let P=[];for(let j of l.providers){let X=j.models.filter((F)=>p.has(`${j.name}:${F.modelId}`));if(X.length>0)P.push({name:j.name,isNewProvider:j.isNewProvider,config:j.config,models:X})}if(P.length===0)return;await oe.mutateAsync({providers:P})};return t(ue,{open:e,onOpenChange:(P)=>!P&&r(),children:o(ae,{className:"sm:max-w-3xl md:max-w-4xl w-full h-[85vh] max-h-[85vh] flex flex-col p-0 overflow-hidden gap-0",children:[o(fe,{className:"p-6 pb-4 shrink-0",children:[o(le,{className:"flex items-center gap-2 text-xl font-semibold",children:[t(dn,{className:"w-5 h-5 text-primary"}),iT()]}),t(It,{className:"text-xs text-muted-foreground leading-relaxed mt-1.5",children:sT()})]}),t("div",{className:"px-6 pb-3 shrink-0",children:o("div",{className:"flex items-center justify-between gap-3",children:[o("div",{className:"relative flex-1",children:[t(Ut,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-muted-foreground"}),t(q,{value:d,onChange:(P)=>c(P.target.value),placeholder:fT(),className:"pl-8 h-8 text-xs bg-background"})]}),o("div",{className:"flex items-center gap-1.5",children:[t(E,{type:"button",variant:"outline",size:"sm",onClick:w,className:"h-8 text-xs px-2.5",children:lT()}),t(E,{type:"button",variant:"outline",size:"sm",onClick:k,className:"h-8 text-xs px-2.5",children:rT()}),t("div",{className:"w-px h-4 bg-border mx-1"}),t(E,{type:"button",variant:"outline",size:"sm",onClick:H,className:"h-8 text-xs px-2.5",children:pT()}),t(E,{type:"button",variant:"outline",size:"sm",onClick:ie,className:"h-8 text-xs px-2.5",children:oT()})]})]})}),t("div",{className:"flex-1 min-h-0 px-6 overflow-hidden",children:t(ce,{className:"h-full border border-border/60 rounded-md bg-muted/20",children:t("div",{className:"p-3 space-y-3",children:x.length===0?t("div",{className:"py-8 text-center text-sm text-muted-foreground",children:fg()}):x.map((P)=>{let j=g.has(P.name),X=P.isNewProvider,F=P.models.filter((me)=>p.has(`${P.name}:${me.modelId}`)).length,Y=F===P.models.length,ye=F>0&&!Y;return o("div",{className:"border border-border/50 rounded-lg bg-background overflow-hidden",children:[o("div",{className:"flex items-center justify-between px-3 py-2 bg-card hover:bg-muted/40 transition-colors",children:[o("div",{className:"flex items-center gap-2.5",children:[t("button",{type:"button",onClick:()=>v(P.name),className:"p-0.5 text-muted-foreground hover:text-foreground rounded transition-colors",children:j?t(ve,{className:"w-4 h-4"}):t(vt,{className:"w-4 h-4"})}),t(vr,{checked:Y?!0:ye?"indeterminate":!1,onCheckedChange:()=>J(P.name),id:`provider-check-${P.name}`}),o("label",{htmlFor:`provider-check-${P.name}`,className:"font-medium text-sm text-foreground flex items-center gap-2 cursor-pointer select-none",children:[t(io,{className:"w-4 h-4 text-muted-foreground"}),t("span",{children:P.name})]})]}),o("div",{className:"flex items-center gap-2",children:[X?t(be,{variant:"secondary",className:"text-[10px] px-1.5 py-0 bg-primary/10 text-primary border-primary/20",children:uT()}):t(be,{variant:"outline",className:"text-[10px] px-1.5 py-0 text-muted-foreground",children:aT()}),t("span",{className:"text-xs text-muted-foreground",children:cT({count:P.models.length})})]})]}),j&&t("div",{className:"border-t border-border/40 divide-y divide-border/30 bg-muted/10",children:P.models.map((me)=>{let Ee=p.has(`${P.name}:${me.modelId}`);return o("div",{className:"flex items-center justify-between pl-9 pr-3 py-2 hover:bg-muted/30 transition-colors",children:[o("div",{className:"flex items-center gap-2.5 min-w-0",children:[t(vr,{checked:Ee,onCheckedChange:()=>z(P.name,me.modelId),id:`model-check-${P.name}-${me.modelId}`}),o("label",{htmlFor:`model-check-${P.name}-${me.modelId}`,className:"text-xs font-medium text-foreground cursor-pointer select-none truncate",children:[me.name||me.modelId,t("span",{className:"ml-1.5 text-[11px] text-muted-foreground font-mono font-normal",children:me.modelId})]})]}),o("div",{className:"flex items-center gap-1.5 shrink-0 ml-2",children:[me.config.reasoning&&t(be,{variant:"outline",className:"text-[10px] px-1.5 py-0 font-normal border-amber-500/30 text-amber-600 dark:text-amber-400",children:dT()}),t("span",{className:"text-[11px] text-muted-foreground font-mono",children:nT({count:Math.round(me.config.contextWindow/1000)})})]})]},me.modelId)})})]},P.name)})})})}),o(qe,{className:"p-6 pt-3 shrink-0 border-t border-border flex items-center justify-between sm:justify-between w-full",children:[t("div",{className:"text-xs text-muted-foreground",children:mT({modelCount:m,providerCount:i})}),o("div",{className:"flex items-center gap-2",children:[t(E,{type:"button",variant:"outline",onClick:r,disabled:oe.isPending,children:De()}),t(E,{type:"button",onClick:T,disabled:m===0||oe.isPending,className:"gap-2",children:oe.isPending?o(L,{children:[t(O,{className:"w-4 h-4 animate-spin"}),eT()]}):XI({count:m})})]})]})]})})}var As={"openai-completions":"OpenAI Completions","mistral-conversations":"Mistral Conversations","openai-responses":"OpenAI Responses","azure-openai-responses":"Azure OpenAI Responses","openai-codex-responses":"OpenAI Codex Responses","anthropic-messages":"Anthropic Messages","bedrock-converse-stream":"AWS Bedrock","google-generative-ai":"Google Generative AI","google-vertex":"Google Vertex"};function Is({teamId:e}){let r=Q(),[a,l]=u(null),[s,d]=u(!1),[c,g]=u(""),[_,p]=u(!1),[b,x]=u(null),[m,i]=u(!1),[v,w]=u(null),k=B({mutationFn:async()=>{let j=await A.api.teams[":teamId"].providers["sync-check"].$post({param:{teamId:e}});if(!j.ok){let X=await j.json().catch(()=>({message:"Failed to check updates"}));throw Error(X.message||"Failed to check updates")}return await j.json()},onSuccess:(j)=>{if(j.totalNewModels===0&&j.totalNewProviders===0){M.info(gT());return}w(j),i(!0)},onError:(j)=>{M.error(j.message)}}),{data:z,isLoading:J}=Z({queryKey:["teams",e,"providers"],queryFn:async()=>{let j=await A.api.teams[":teamId"].providers.$get({param:{teamId:e}});if(!j.ok)throw Error("Failed to fetch providers");return await j.json()}}),H=N(()=>z?.find((j)=>j.id===a)||null,[z,a]),ie=N(()=>z?.map((j)=>j.name)||[],[z]),oe=N(()=>{if(!z)return[];if(!c.trim())return z;let j=c.toLowerCase();return z.filter((X)=>X.name.toLowerCase().includes(j))},[z,c]),T=B({mutationFn:async(j)=>{let X=await A.api.teams[":teamId"].providers.$post({param:{teamId:e},json:{name:j.name,config:j.config,models:j.models}});if(!X.ok)throw Error("Failed to create provider");return await X.json()},onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"providers"]}),d(!1),M.success(TE())},onError:(j)=>{M.error(zs({message:j.message}))}}),P=B({mutationFn:async(j)=>{let X=await A.api.providers[":id"].$delete({param:{id:j}});if(!X.ok)throw Error("Failed to delete provider");return await X.json()},onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"providers"]}),l(null),p(!1),x(null),M.success(ME())},onError:(j)=>{M.error(zs({message:j.message}))}});if(J)return t("div",{className:"flex h-64 items-center justify-center",children:t(O,{className:"h-8 w-8 animate-spin text-primary"})});return o("div",{className:"h-full flex flex-col space-y-0",children:[o("div",{className:"flex-none space-y-4 pb-4",children:[o("div",{className:"flex items-center justify-between",children:[o("h3",{className:"text-lg font-semibold text-foreground flex items-center gap-2",children:[t(io,{className:"w-5 h-5 text-primary"}),J_()]}),o("div",{className:"flex items-center gap-2",children:[t(E,{variant:"outline",onClick:()=>k.mutate(),disabled:k.isPending,className:"gap-2",children:k.isPending?o(L,{children:[t(O,{className:"w-4 h-4 animate-spin"}),tT()]}):o(L,{children:[t(ua,{className:"w-4 h-4"}),JI()]})}),o(E,{onClick:()=>d(!0),className:"bg-primary hover:bg-primary/90 text-primary-foreground gap-2",children:[t(pe,{className:"w-4 h-4"}),Mm()]})]})]}),o("div",{className:"relative px-0.5",children:[t(Ut,{className:"absolute left-3.5 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),t(q,{placeholder:Xg(),value:c,onChange:(j)=>g(j.target.value),className:"pl-10 bg-card border-border focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-0"})]})]}),t(ce,{className:"flex-1 min-h-0",children:o("div",{className:"pr-4 py-2 grid grid-cols-1 gap-4",children:[oe.map((j)=>t(ut,{className:"group cursor-pointer hover:border-primary/50 transition-all hover:shadow-md overflow-hidden",onClick:()=>l(j.id),children:o(xt,{className:"p-5 flex items-center justify-between gap-4",children:[o("div",{className:"flex items-center gap-4 min-w-0 flex-1",children:[t("div",{className:"flex-none p-3 bg-muted rounded-xl group-hover:bg-primary/10 transition-colors",children:t(ca,{className:"w-6 h-6 text-muted-foreground group-hover:text-primary"})}),o("div",{className:"min-w-0 flex-1",children:[t("div",{className:"flex items-center gap-2",children:t("span",{className:"font-bold text-foreground truncate",children:j.name})}),o("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1.5 text-xs text-muted-foreground mt-1",children:[o("span",{className:"flex items-center gap-1 flex-none",children:[t(qt,{className:"w-3 h-3"}),j.config.api]}),j.config.baseUrl&&o("span",{className:"flex items-center gap-1 min-w-0",children:[t("span",{className:"h-1 w-1 rounded-full bg-muted-foreground/30 flex-none"}),t(Wo,{className:"w-3 h-3 flex-none"}),t("span",{className:"truncate max-w-[200px] md:max-w-[300px]",children:j.config.baseUrl})]}),o("span",{className:"flex items-center gap-1 flex-none",children:[t("span",{className:"h-1 w-1 rounded-full bg-muted-foreground/30 flex-none"}),t(es,{className:"w-3 h-3"}),Ox({count:j.modelsCount})]})]})]})]}),o("div",{className:"flex items-center gap-1",children:[o(he,{modal:!1,children:[t(ge,{asChild:!0,onClick:(X)=>X.stopPropagation(),children:t(E,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-foreground",children:t(Sr,{className:"w-4 h-4"})})}),t(Ae,{align:"end",className:"w-32",children:o(K,{onClick:(X)=>{X.stopPropagation(),x(j),p(!0)},className:"text-destructive focus:text-destructive gap-2 cursor-pointer",children:[t(we,{className:"w-4 h-4"})," ",at()]})})]}),t(vt,{className:"flex-none w-5 h-5 text-muted-foreground/50 group-hover:text-primary transition-colors"})]})]})},j.id)),z?.length===0&&o("div",{className:"text-center py-12 bg-muted/30 rounded-2xl border-2 border-dashed border-border",children:[t(io,{className:"w-12 h-12 text-muted-foreground/50 mx-auto mb-4"}),t("h4",{className:"text-foreground font-medium",children:lS()}),t("p",{className:"text-sm text-muted-foreground mt-1",children:QA()})]}),z&&z.length>0&&oe.length===0&&o("div",{className:"text-center py-12",children:[t(Ut,{className:"w-12 h-12 text-muted-foreground/50 mx-auto mb-4"}),t("h4",{className:"text-foreground font-medium",children:fg()}),t("p",{className:"text-sm text-muted-foreground mt-1",children:JT({query:c})}),t(E,{variant:"ghost",size:"sm",onClick:()=>g(""),className:"mt-4 text-primary hover:text-primary/90 hover:bg-primary/10",children:z_()})]})]})}),t(qr,{isOpen:s,onClose:()=>d(!1),onSubmit:(j)=>T.mutate(j),isLoading:T.isPending,existingProviderNames:ie}),H&&t(jr,{isOpen:!!H,onClose:()=>l(null),provider:H,teamId:e,existingProviderNames:ie}),t(Je,{open:_,onOpenChange:p,children:o(Xe,{children:[o(et,{children:[t(rt,{children:dd()}),t(nt,{children:Wy({name:b?.name??""})})]}),o(tt,{children:[t(st,{onClick:()=>x(null),children:De()}),o(ot,{className:"bg-destructive hover:bg-destructive/90 text-destructive-foreground",onClick:()=>{if(b)P.mutate(b.id)},children:[P.isPending?t(O,{className:"w-4 h-4 animate-spin mr-2"}):t(we,{className:"w-4 h-4 mr-2"}),at()]})]})]})}),t(Fs,{isOpen:m,onClose:()=>i(!1),teamId:e,syncData:v,onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"providers"]})}})]})}function qr({isOpen:e,onClose:r,onSubmit:a,isLoading:l,existingProviderNames:s}){let[d,c]=u([]),[g,_]=u(!1),[p,b]=u(null),x=N(()=>R({name:f().min(1,Mg()).refine((w)=>!s.includes(w),{message:kg()}),config:ia}),[s]),m=$t({defaultValues:{name:"",config:{api:"openai-completions",baseUrl:"",apiKey:""}},validators:{onSubmit:x},onSubmit:async({value:w})=>{a({name:w.name,config:w.config,models:d})}});h(()=>{if(e)m.reset(),c([]),_(!1),b(null)},[e,m]);let i=(w)=>w.map((k)=>{if(typeof k==="string")return{message:k};if(k&&typeof k==="object"&&"message"in k)return{message:String(k.message)};return{message:String(k||"")}}),v=(w)=>{if(p!==null)c((k)=>k.map((z,J)=>J===p?w:z)),b(null);else c((k)=>[w,...k]),_(!1)};return t(ue,{open:e,onOpenChange:r,children:o(ae,{className:"sm:max-w-2xl h-[85vh] flex flex-col p-0 overflow-hidden",children:[o(fe,{className:"p-6 pb-2 shrink-0",children:[t(le,{className:"text-xl",children:JA()}),t(It,{children:oh()})]}),o("form",{onSubmit:(w)=>{w.preventDefault(),w.stopPropagation(),m.handleSubmit()},className:"flex-1 flex flex-col min-h-0 overflow-hidden",children:[t("div",{className:"flex-1 min-h-0",children:t(ce,{className:"h-full",children:o("div",{className:"p-6 pt-2 space-y-6 pr-6",children:[o("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 p-5 rounded-2xl border bg-muted/20",children:[t(m.Field,{name:"name",children:(w)=>{let k=!!w.state.meta.errors.length&&w.state.meta.isTouched;return o(Oe,{"data-invalid":k,children:[t(Qe,{htmlFor:w.name,children:Tg()}),t(q,{id:w.name,name:w.name,value:w.state.value,onBlur:w.handleBlur,onChange:(z)=>w.handleChange(z.target.value),placeholder:Rg(),"aria-invalid":k}),k&&t(We,{errors:i(w.state.meta.errors)})]})}}),t(m.Field,{name:"config.api",children:(w)=>{let k=!!w.state.meta.errors.length&&w.state.meta.isTouched;return o(Oe,{"data-invalid":k,children:[t(Qe,{htmlFor:w.name,children:Uh()}),o(Le,{onValueChange:w.handleChange,value:w.state.value,children:[t(Be,{id:w.name,"aria-invalid":k,children:t(Ze,{placeholder:eA()})}),t(Ue,{children:ou.map((z)=>t(ne,{value:z,children:As[z]},z))})]}),k&&t(We,{errors:i(w.state.meta.errors)})]})}}),t("div",{className:"md:col-span-2",children:t(m.Field,{name:"config.baseUrl",children:(w)=>{let k=!!w.state.meta.errors.length&&w.state.meta.isTouched;return o(Oe,{"data-invalid":k,children:[t(Qe,{htmlFor:w.name,children:th()}),t(q,{id:w.name,name:w.name,value:w.state.value||"",onBlur:w.handleBlur,onChange:(z)=>w.handleChange(z.target.value),placeholder:"https://api.openai.com/v1","aria-invalid":k}),t(aa,{children:_g()}),k&&t(We,{errors:i(w.state.meta.errors)})]})}})}),t("div",{className:"md:col-span-2",children:t(m.Field,{name:"config.apiKey",children:(w)=>{let k=!!w.state.meta.errors.length&&w.state.meta.isTouched;return o(Oe,{"data-invalid":k,children:[t(Qe,{htmlFor:w.name,children:ud()}),t(q,{id:w.name,name:w.name,type:"text",value:w.state.value||"",onBlur:w.handleBlur,onChange:(z)=>w.handleChange(z.target.value),placeholder:Wm(),"aria-invalid":k}),t(aa,{className:"text-xs mt-1",children:Km()}),k&&t(We,{errors:i(w.state.meta.errors)})]})}})})]}),o("div",{className:"space-y-3",children:[o("div",{className:"flex items-center justify-between",children:[o("div",{children:[t(W,{className:"text-base font-semibold",children:Sd()}),t("p",{className:"text-xs text-muted-foreground mt-0.5",children:Tx()})]}),o(E,{type:"button",variant:"outline",size:"sm",onClick:()=>_(!0),className:"gap-1.5",children:[t(pe,{className:"w-4 h-4"}),ad()]})]}),d.length===0?t("div",{className:"text-center py-8 rounded-xl border border-dashed text-muted-foreground text-sm",children:Cd()}):t("div",{className:"space-y-2",children:d.map((w,k)=>o("div",{className:"group cursor-pointer flex items-center justify-between p-3 rounded-xl border bg-card hover:border-primary/50 transition-all shadow-none hover:shadow-sm",onClick:()=>b(k),children:[o("div",{className:"min-w-0 flex-1",children:[o("div",{className:"flex items-center gap-2",children:[t("span",{className:"font-semibold text-foreground truncate",children:w.name||w.modelId}),t(be,{variant:"secondary",className:"font-mono text-[10px]",children:w.modelId}),w.config.reasoning&&o(be,{variant:"outline",className:"text-[10px] gap-1 bg-primary/10 text-primary border-primary/20",children:[t(qt,{className:"w-2.5 h-2.5"})," ",Ep()]})]}),o("div",{className:"text-xs text-muted-foreground mt-1 flex items-center gap-2",children:[o("span",{children:[w.config.contextWindow?.toLocaleString()," ",yA()]}),t("span",{children:"·"}),t("span",{children:lh({input:w.config.cost?.input??0,output:w.config.cost?.output??0})})]})]}),t("div",{className:"flex items-center gap-1 ml-2",children:t(E,{type:"button",variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:(z)=>{z.stopPropagation(),c((J)=>J.filter((H,ie)=>ie!==k))},children:t(we,{className:"w-3.5 h-3.5"})})})]},w.modelId+k))})]})]})})}),o(qe,{className:"p-6 pt-4 border-t border-border gap-2 shrink-0",children:[t(E,{type:"button",variant:"outline",onClick:r,disabled:l,children:De()}),t(m.Subscribe,{selector:(w)=>[w.canSubmit,w.isSubmitting],children:([w,k])=>t(E,{type:"submit",className:"min-w-[120px]",disabled:!w||k||l,children:k||l?t(O,{className:"w-4 h-4 animate-spin"}):Mm()})})]})]}),(g||p!==null)&&t(Ca,{isOpen:!0,onClose:()=>{_(!1),b(null)},onSubmit:v,title:p!==null?yh():ad(),initialValues:p!==null?d[p]:null,defaultApi:m.getFieldValue("config.api"),existingModelIds:d.filter((w,k)=>k!==p).map((w)=>w.modelId)},p!==null?`edit-${p}-${d[p]?.modelId}`:"add")]})})}function jr({isOpen:e,onClose:r,provider:a,teamId:l,existingProviderNames:s}){let d=Q(),[c,g]=u("general"),[_,p]=u(""),[b,x]=u(!1),[m,i]=u(null),[v,w]=u(null),{data:k=[],isLoading:z}=Z({queryKey:["teams",l,"providers",a.id,"models"],queryFn:async()=>{let F=await A.api.providers[":id"].models.$get({param:{id:a.id}});if(!F.ok)throw Error("Failed to fetch models");return await F.json()},enabled:e}),J=B({mutationFn:async(F)=>{let Y=await A.api.providers[":id"].$put({param:{id:a.id},json:{name:F.name,config:F.config}});if(!Y.ok)throw Error("Failed to update provider");return await Y.json()},onSuccess:()=>{d.invalidateQueries({queryKey:["teams",l,"providers"]}),M.success(Og())},onError:(F)=>{M.error(zs({message:F.message}))}}),H=B({mutationFn:async(F)=>{let Y=await A.api.providers[":id"].models.$post({param:{id:a.id},json:F});if(!Y.ok)throw Error("Failed to create model");return await Y.json()},onSuccess:()=>{d.invalidateQueries({queryKey:["teams",l,"providers",a.id,"models"]}),d.invalidateQueries({queryKey:["teams",l,"providers"]}),x(!1),M.success(vx())},onError:(F)=>{M.error(zs({message:F.message}))}}),ie=B({mutationFn:async({modelDbId:F,values:Y})=>{let ye=await A.api.providers[":id"].models[":modelDbId"].$put({param:{id:a.id,modelDbId:F},json:Y});if(!ye.ok)throw Error("Failed to update model");return await ye.json()},onSuccess:()=>{d.invalidateQueries({queryKey:["teams",l,"providers",a.id,"models"]}),i(null),M.success(Ix())},onError:(F)=>{M.error(zs({message:F.message}))}}),oe=B({mutationFn:async(F)=>{let Y=await A.api.providers[":id"].models[":modelDbId"].$delete({param:{id:a.id,modelDbId:F}});if(!Y.ok)throw Error("Failed to delete model");return await Y.json()},onSuccess:()=>{d.invalidateQueries({queryKey:["teams",l,"providers",a.id,"models"]}),d.invalidateQueries({queryKey:["teams",l,"providers"]}),w(null),M.success(wx())},onError:(F)=>{M.error(zs({message:F.message}))}}),T=N(()=>R({name:f().min(1,Mg()).refine((F)=>{if(a.name===F)return!0;return!s.includes(F)},{message:kg()}),config:ia}),[s,a.name]),P=$t({defaultValues:{name:a.name,config:a.config},validators:{onSubmit:T},onSubmit:async({value:F})=>{J.mutate({name:F.name,config:F.config})}});h(()=>{if(e)P.reset(),g("general"),p("")},[e,P]);let j=(F)=>F.map((Y)=>{if(typeof Y==="string")return{message:Y};if(Y&&typeof Y==="object"&&"message"in Y)return{message:String(Y.message)};return{message:String(Y||"")}}),X=N(()=>{if(!_.trim())return k;let F=_.toLowerCase();return k.filter((Y)=>Y.modelId.toLowerCase().includes(F)||Y.name?.toLowerCase().includes(F))},[k,_]);return t(ue,{open:e,onOpenChange:r,children:o(ae,{className:"sm:max-w-3xl h-[88vh] flex flex-col p-0 overflow-hidden",children:[o(fe,{className:"p-6 pb-2 shrink-0",children:[t(le,{className:"text-xl",children:_h({name:a.name})}),t(It,{children:oh()})]}),o(So,{value:c,onValueChange:(F)=>g(F),className:"flex-1 flex flex-col min-h-0",children:[t("div",{className:"px-6 pb-2 shrink-0",children:o(Eo,{className:"grid w-full grid-cols-2",children:[t(Kr,{value:"general",children:Bh()}),o(Kr,{value:"models",className:"gap-2",children:[Sd(),t(be,{variant:"secondary",className:"h-5 px-1.5 text-[11px]",children:k.length})]})]})}),t(kn,{value:"general",className:"flex-1 flex flex-col min-h-0 m-0",children:o("form",{onSubmit:(F)=>{F.preventDefault(),F.stopPropagation(),P.handleSubmit()},className:"flex-1 flex flex-col min-h-0",children:[t("div",{className:"flex-1 min-h-0",children:t(ce,{className:"h-full",children:t("div",{className:"p-6 space-y-6 pr-6",children:o("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-5 p-5 rounded-2xl border bg-muted/10",children:[t(P.Field,{name:"name",children:(F)=>{let Y=!!F.state.meta.errors.length&&F.state.meta.isTouched;return o(Oe,{"data-invalid":Y,children:[t(Qe,{htmlFor:F.name,children:Tg()}),t(q,{id:F.name,name:F.name,value:F.state.value,onBlur:F.handleBlur,onChange:(ye)=>F.handleChange(ye.target.value),placeholder:Rg(),"aria-invalid":Y}),Y&&t(We,{errors:j(F.state.meta.errors)})]})}}),t(P.Field,{name:"config.api",children:(F)=>{let Y=!!F.state.meta.errors.length&&F.state.meta.isTouched;return o(Oe,{"data-invalid":Y,children:[t(Qe,{htmlFor:F.name,children:Uh()}),o(Le,{onValueChange:F.handleChange,value:F.state.value,children:[t(Be,{id:F.name,"aria-invalid":Y,children:t(Ze,{placeholder:eA()})}),t(Ue,{children:ou.map((ye)=>t(ne,{value:ye,children:As[ye]},ye))})]}),Y&&t(We,{errors:j(F.state.meta.errors)})]})}}),t("div",{className:"md:col-span-2",children:t(P.Field,{name:"config.baseUrl",children:(F)=>{let Y=!!F.state.meta.errors.length&&F.state.meta.isTouched;return o(Oe,{"data-invalid":Y,children:[t(Qe,{htmlFor:F.name,children:th()}),t(q,{id:F.name,name:F.name,value:F.state.value||"",onBlur:F.handleBlur,onChange:(ye)=>F.handleChange(ye.target.value),placeholder:"https://api.openai.com/v1","aria-invalid":Y}),t(aa,{children:_g()}),Y&&t(We,{errors:j(F.state.meta.errors)})]})}})}),t("div",{className:"md:col-span-2",children:t(P.Field,{name:"config.apiKey",children:(F)=>{let Y=!!F.state.meta.errors.length&&F.state.meta.isTouched;return o(Oe,{"data-invalid":Y,children:[t(Qe,{htmlFor:F.name,children:ud()}),t(q,{id:F.name,name:F.name,type:"text",value:F.state.value||"",onBlur:F.handleBlur,onChange:(ye)=>F.handleChange(ye.target.value),placeholder:Wm(),"aria-invalid":Y}),t(aa,{className:"text-xs mt-1",children:Km()}),Y&&t(We,{errors:j(F.state.meta.errors)})]})}})})]})})})}),o(qe,{className:"p-6 pt-4 border-t border-border gap-2 shrink-0",children:[t(E,{type:"button",variant:"outline",onClick:r,children:De()}),t(P.Subscribe,{selector:(F)=>[F.canSubmit,F.isSubmitting],children:([F,Y])=>t(E,{type:"submit",className:"min-w-[120px]",disabled:!F||Y||J.isPending,children:Y||J.isPending?t(O,{className:"w-4 h-4 animate-spin"}):qs()})})]})]})}),o(kn,{value:"models",className:"flex-1 flex flex-col min-h-0 m-0",children:[o("div",{className:"p-6 pb-3 flex items-center justify-between gap-3 shrink-0",children:[o("div",{className:"relative flex-1 max-w-sm",children:[t(Ut,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),t(q,{placeholder:Rp(),value:_,onChange:(F)=>p(F.target.value),className:"pl-9 h-9"})]}),o(E,{size:"sm",onClick:()=>x(!0),className:"gap-1.5 shrink-0",children:[t(pe,{className:"w-4 h-4"}),ad()]})]}),t("div",{className:"flex-1 min-h-0 px-6",children:t(ce,{className:"h-full pr-4",children:z?t("div",{className:"flex h-48 items-center justify-center",children:t(O,{className:"h-6 w-6 animate-spin text-primary"})}):X.length===0?t("div",{className:"text-center py-12 border border-dashed rounded-xl text-muted-foreground text-sm",children:Cd()}):t("div",{className:"space-y-2 pb-4",children:X.map((F)=>o("div",{className:"group cursor-pointer flex items-center justify-between p-3.5 rounded-xl border bg-card hover:border-primary/50 transition-all shadow-none hover:shadow-sm",onClick:()=>i(F),children:[o("div",{className:"min-w-0 flex-1 pr-3",children:[o("div",{className:"flex items-center gap-2 flex-wrap",children:[t("span",{className:"font-semibold text-foreground text-sm",children:F.name||F.modelId}),t(be,{variant:"secondary",className:"font-mono text-[10px] px-1.5 py-0.5",children:F.modelId}),F.config?.reasoning&&o(be,{variant:"outline",className:"text-[10px] gap-1 bg-primary/10 text-primary border-primary/20 h-5",children:[t(qt,{className:"w-2.5 h-2.5"})," ",Ep()]})]}),o("div",{className:"text-xs text-muted-foreground mt-1.5 flex flex-wrap items-center gap-x-2 gap-y-1",children:[o("span",{children:[F.config?.contextWindow?.toLocaleString()," ",yA()]}),t("span",{children:"·"}),t("span",{children:Zw({count:F.config?.maxTokens?.toLocaleString()??"0"})}),t("span",{children:"·"}),t("span",{children:lh({input:F.config?.cost?.input??0,output:F.config?.cost?.output??0})})]})]}),t("div",{className:"flex items-center gap-1 shrink-0",children:t(E,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:(Y)=>{Y.stopPropagation(),w(F)},children:t(we,{className:"w-3.5 h-3.5"})})})]},F.id))})})})]})]}),b&&t(Ca,{isOpen:b,onClose:()=>x(!1),onSubmit:(F)=>H.mutate(F),title:ad(),isLoading:H.isPending,defaultApi:a.config.api,existingModelIds:k.map((F)=>F.modelId)}),m&&t(Ca,{isOpen:!!m,onClose:()=>i(null),onSubmit:(F)=>ie.mutate({modelDbId:m.id,values:F}),title:yh(),isLoading:ie.isPending,initialValues:{modelId:m.modelId,name:m.name,config:m.config},defaultApi:a.config.api,existingModelIds:k.filter((F)=>F.id!==m.id).map((F)=>F.modelId)}),t(Je,{open:!!v,onOpenChange:(F)=>!F&&w(null),children:o(Xe,{children:[o(et,{children:[t(rt,{children:dd()}),t(nt,{children:Vy({name:v?.name||v?.modelId||""})})]}),o(tt,{children:[t(st,{onClick:()=>w(null),children:De()}),o(ot,{className:"bg-destructive hover:bg-destructive/90 text-destructive-foreground",onClick:()=>{if(v)oe.mutate(v.id)},children:[oe.isPending?t(O,{className:"w-4 h-4 animate-spin mr-2"}):t(we,{className:"w-4 h-4 mr-2"}),at()]})]})]})})]})})}S();function Ts({teamId:e}){let r=Q(),[a,l]=u(""),{data:s,isLoading:d}=Z({queryKey:["teams",e,"sandbox"],queryFn:async()=>{let v=await A.api.teams[":teamId"].sandbox.$get({param:{teamId:e}});if(!v.ok)throw Error(Jo());return await v.json()}}),{mutate:c,isPending:g}=B({mutationFn:async(v)=>{let w=await A.api.teams[":teamId"].sandbox.$put({param:{teamId:e},json:v});if(!w.ok)throw Error(Rh());return await w.json()},onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"sandbox"]}),M.success(RC())},onError:(v)=>{M.error(v instanceof Error?v.message:Rh())}}),_=(v)=>{c({networkSandboxEnabled:v})},p=(v)=>{if(v.preventDefault(),!a.trim())return;if(s?.allowedDomains.includes(a.trim())){M.error(lb());return}let w=[...s?.allowedDomains||[],a.trim()],k=s?.pendingDomains||[];c({allowedDomains:w,pendingDomains:k}),l("")},b=(v)=>{let w=(s?.allowedDomains||[]).filter((z)=>z!==v),k=s?.pendingDomains||[];c({allowedDomains:w,pendingDomains:k})},x=(v)=>{let w=[...s?.allowedDomains||[],v],k=(s?.pendingDomains||[]).filter((z)=>z!==v);c({allowedDomains:w,pendingDomains:k})},m=(v)=>{let w=(s?.pendingDomains||[]).filter((k)=>k!==v);c({allowedDomains:s?.allowedDomains||[],pendingDomains:w})};if(d)return t("div",{className:"flex items-center justify-center p-8",children:t(O,{className:"h-8 w-8 animate-spin text-muted-foreground"})});let i=!!s?.networkSandboxEnabled;return t(ce,{className:"h-full",children:o("div",{className:"space-y-6 pr-4 pb-8",children:[o(ut,{children:[o(Tt,{children:[o("div",{className:"flex items-center gap-2",children:[t(ca,{className:"w-5 h-5 text-primary"}),t(Mt,{children:Bx()})]}),t(Ot,{children:Ux()})]}),o(xt,{children:[o("div",{className:"flex items-center justify-between p-4 mb-6 rounded-lg border border-border bg-muted/30",children:[o("div",{className:"space-y-0.5 pr-4",children:[t("label",{htmlFor:"network-sandbox-switch",className:"text-sm font-medium text-foreground cursor-pointer",children:Eb()}),t("p",{className:"text-xs text-muted-foreground",children:jx()})]}),t(Me,{id:"network-sandbox-switch",checked:i,onCheckedChange:_,disabled:g})]}),!i&&o("div",{className:"flex items-start gap-2.5 p-3.5 mb-6 rounded-lg bg-amber-500/10 border border-amber-500/20 text-amber-700 dark:text-amber-300 text-sm",children:[t(Wo,{className:"w-4 h-4 mt-0.5 shrink-0"}),t("span",{children:zx()})]}),o("form",{onSubmit:p,className:"flex gap-2 mb-6",children:[t(q,{placeholder:"e.g. api.openai.com",value:a,onChange:(v)=>l(v.target.value),disabled:g||!i}),o(E,{type:"submit",disabled:g||!i,children:[g?t(O,{className:"w-4 h-4 animate-spin"}):t(pe,{className:"w-4 h-4 mr-2"}),VA()]})]}),o("div",{className:"space-y-2",children:[t("h4",{className:"text-sm font-medium text-muted-foreground mb-3",children:Y0()}),o("div",{className:"flex flex-wrap gap-2",children:[s?.allowedDomains.map((v)=>o("div",{className:"flex items-center gap-1 px-3 py-1.5 bg-muted rounded-full text-sm border border-border transition-all hover:border-muted-foreground/50",children:[t("span",{className:"font-medium text-foreground",children:v}),t("button",{onClick:()=>b(v),className:"ml-1 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50 disabled:cursor-not-allowed",disabled:g||!i,children:t(Ne,{className:"w-3.5 h-3.5"})})]},v)),s?.allowedDomains.length===0&&t("div",{className:"text-sm text-muted-foreground italic",children:eS()})]})]})]})]}),o(ut,{className:"border-orange-500/20 bg-orange-500/5",children:[o(Tt,{children:[o("div",{className:"flex items-center gap-2",children:[t(Wl,{className:"w-5 h-5 text-orange-500"}),t(Mt,{children:eE()})]}),t(Ot,{children:tE()})]}),t(xt,{children:t("div",{className:"space-y-3",children:s?.pendingDomains&&s.pendingDomains.length>0?t("div",{className:"divide-y divide-border",children:s.pendingDomains.map((v)=>o("div",{className:"flex items-center justify-between py-2.5 first:pt-0 last:pb-0",children:[t("span",{className:"font-mono text-sm text-foreground bg-muted px-2 py-1 rounded break-all",children:v}),o("div",{className:"flex items-center gap-2",children:[o(E,{size:"sm",variant:"outline",className:"h-8 border-emerald-500/20 text-emerald-600 hover:bg-emerald-500/10 hover:text-emerald-600 dark:text-emerald-400 dark:hover:bg-emerald-500/20",onClick:()=>x(v),disabled:g||!i,children:[t(Pe,{className:"w-4 h-4 mr-1.5"}),s_()]}),o(E,{size:"sm",variant:"outline",className:"h-8 border-destructive/20 text-destructive hover:bg-destructive/10",onClick:()=>m(v),disabled:g||!i,children:[t(we,{className:"w-4 h-4 mr-1.5"}),at()]})]})]},v))}):t("div",{className:"text-sm text-muted-foreground italic py-2",children:aS()})})})]}),t(ut,{children:o(Tt,{children:[t(Mt,{children:wv()}),t(Ot,{children:xv()})]})})]})})}S();var Or=(e)=>o("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",...e,children:[t("path",{d:"M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"}),t("path",{d:"M9 18c-4.51 2-5-2-7-2"})]}),Es=({teamId:e})=>{let r=Q(),{canAdmin:a}=Dt(),[l,s]=u(!1),[d,c]=u(!1),[g,_]=u(!1),[p,b]=u(null),{data:x,isLoading:m}=Z({queryKey:["teams",e,"skills"],queryFn:async()=>{let k=await A.api.teams[":teamId"].skills.$get({param:{teamId:e}});if(!k.ok)throw Error(Jo());return await k.json()}}),i=B({mutationFn:async(k)=>{if(!(await A.api.skills[":id"].$delete({param:{id:k}})).ok)throw Error(Na())},onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"skills"]}),_(!1)}}),v=B({mutationFn:async({id:k,permission:z})=>{if(!(await A.api.skills[":id"].permission.$patch({param:{id:k},json:{permission:z}})).ok)throw Error(bl())},onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"skills"]})},onError:(k)=>{alert(k.message||bl())}}),w=x?.skills||[];return o(ut,{children:[o(Tt,{className:"flex flex-row items-center justify-between space-y-0 pb-7",children:[o("div",{className:"flex items-center gap-3",children:[t("div",{className:"p-2 bg-primary/10 text-primary rounded-lg",children:t(Nt,{className:"w-6 h-6"})}),o("div",{children:[t(Mt,{className:"text-xl font-bold",children:cA()}),t(Ot,{children:kI()})]})]}),o(E,{onClick:()=>s(!0),className:"gap-2",children:[t(pe,{className:"w-4 h-4"})," ",t0()]})]}),t(xt,{children:m?t("div",{className:"flex justify-center py-10",children:t(O,{className:"w-8 h-8 animate-spin text-primary"})}):w.length===0?o("div",{className:"text-center py-12 border-2 border-dashed border-border rounded-xl",children:[t("div",{className:"mx-auto w-12 h-12 bg-muted rounded-full flex items-center justify-center mb-4 text-muted-foreground",children:t(Nt,{className:"w-6 h-6"})}),t("h3",{className:"text-lg font-medium text-foreground",children:mS()}),t("p",{className:"text-muted-foreground mt-1 max-w-xs mx-auto",children:r0()})]}):t("div",{className:"space-y-4",children:w.map((k)=>t($r,{skill:k,canAdmin:a,onDelete:()=>{b(k),_(!0)},onConfigure:()=>{b(k),c(!0)},onPermissionChange:(z)=>v.mutate({id:k.id,permission:z})},k.id))})}),t(Qr,{open:l,onOpenChange:s,teamId:e}),p&&t(zr,{open:d,onOpenChange:(k)=>{if(c(k),!k)setTimeout(()=>{document.body.style.pointerEvents="auto"},100)},teamId:e,skill:p}),t(Je,{open:g,onOpenChange:_,children:o(Xe,{children:[o(et,{children:[t(rt,{children:dd()}),t(nt,{children:Xy({name:p?.name??""})})]}),o(tt,{children:[t(st,{children:De()}),o(ot,{className:"bg-destructive hover:bg-destructive/90 text-destructive-foreground",onClick:()=>{if(p)i.mutate(p.id)},children:[i.isPending?t(O,{className:"w-4 h-4 animate-spin mr-2"}):t(we,{className:"w-4 h-4 mr-2"}),at()]})]})]})})]})},$r=({skill:e,canAdmin:r,onDelete:a,onConfigure:l,onPermissionChange:s})=>o("div",{className:"p-4 bg-card rounded-xl border border-border flex flex-col justify-between hover:shadow-md transition-all group cursor-pointer",onClick:l,children:[o("div",{children:[o("div",{className:"flex items-start justify-between mb-2",children:[t("h4",{className:"font-bold text-foreground flex items-center gap-2",children:e.name}),o(he,{children:[t(ge,{asChild:!0,onClick:(d)=>d.stopPropagation(),children:t(E,{variant:"ghost",size:"icon",className:"h-8 w-8",children:t(Sr,{className:"w-4 h-4"})})}),t(Ae,{align:"end",className:"w-32",children:o(K,{onClick:(d)=>{d.stopPropagation(),a()},className:"text-destructive focus:text-destructive gap-2 cursor-pointer",children:[t(we,{className:"w-4 h-4"})," ",at()]})})]})]}),t("p",{className:"text-sm text-muted-foreground line-clamp-2",children:e.description||ug()})]}),o("div",{className:"mt-4 flex items-center justify-between gap-2 pt-2 border-t border-border/50 text-xs",children:[o("span",{className:"text-[10px] text-muted-foreground uppercase tracking-wider font-semibold",children:[wA()," ",new Date(e.updatedAt).toLocaleDateString()]}),t("div",{className:"flex items-center gap-2",onClick:(d)=>d.stopPropagation(),children:o(Le,{value:e.permission||"reviewer",onValueChange:(d)=>s(d),disabled:!r,children:[t(Be,{className:"h-7 text-xs px-2 bg-background border-border w-[140px]",children:t(Ze,{placeholder:Dp()})}),o(Ue,{align:"end",children:[t(ne,{value:"reviewer",children:Fa()}),t(ne,{value:"editor",children:La()}),t(ne,{value:"owner",children:Za()})]})]})})]})]}),Qr=({open:e,onOpenChange:r,teamId:a})=>{let l=Q(),[s,d]=u(""),[c,g]=u(!1),_=y(null),{data:p}=Z({queryKey:["teams",a,"projects"],queryFn:async()=>{let m=await A.api.teams[":teamId"].projects.$get({param:{teamId:a},query:{first:"1"}});if(!m.ok)throw Error("Failed to fetch projects");return await m.json()},enabled:e}),b=async(m)=>{g(!0);try{let i=await A.api.teams[":teamId"].skills.$post({param:{teamId:a},json:m});if(i.status===409){let v=await i.json();if(window.confirm(`${v.error}
|
|
1
|
+
import{V,D,h,$e,N,y,u,Ds,S,L,t,o,Q,Z,B,Rc,ze,A,I,xr,zn,Sr,O,Ct,Pe,ve,vt,er,eo,Wo,fi,vo,pe,Ut,we,Yo,Ne,C,fs,E,Ce,Ie,Te,he,ge,Ae,K,Vt,n,Pa,zA,wf,VA,QA,xf,KA,ad,JA,XA,Mm,km,t0,r0,i0,a0,l0,c0,d0,f0,p0,m0,g0,A0,_0,y0,b0,Nm,v0,Dm,w0,Om,x0,Fm,S0,Lm,E0,Zm,C0,Bm,I0,Um,T0,zm,M0,k0,R0,jm,P0,N0,D0,qm,Hm,$m,Gm,O0,F0,j0,q0,V0,Y0,cd,ud,Km,J0,X0,Wm,e_,t_,Ym,r_,Cf,Jm,Xm,n_,s_,dd,c_,u_,d_,h_,x_,S_,E_,C_,th,T_,M_,k_,R_,P_,N_,De,O_,L_,Z_,B_,z_,G_,V_,Q_,K_,oh,Y_,J_,ny,sy,lh,Zc,my,yy,by,vy,xy,Sy,Iy,My,Zy,By,at,Uy,zy,$y,Gy,Vy,Wy,Of,hh,Xy,yl,ob,sb,Lf,ab,lb,_h,fb,yh,pb,mb,Zf,Ab,bh,_b,vh,yb,wb,xb,Eb,Bf,Ib,Mb,wh,Pb,Nb,zs,Jo,Gb,Qb,Eh,Na,_d,Yb,Jb,Ch,rv,zf,Mh,kh,bl,ov,yd,Rh,Ph,av,lv,cv,Nh,fv,pv,wv,xv,Pv,Nv,Dv,Bh,Ov,Fv,Zv,Bv,Uh,Kv,Wv,Yv,Jv,Xv,ew,tw,rw,nw,ow,sw,iw,lw,jh,uw,dw,fw,Aw,_w,yw,bw,vw,ww,Tw,Rw,Lw,Zw,Bw,Uw,ep,zw,jw,$h,qw,Hw,$w,Gw,Vw,Gh,Vh,Qw,Kw,Ww,Yw,Qh,Jw,Kh,Xw,ex,Wh,Hc,xd,tx,rx,Yh,nx,ox,sx,ix,ax,lx,cx,ux,dx,px,mx,tp,rp,bx,vx,wx,eg,xx,Sx,Ex,Cx,Ix,Sd,Tx,kx,Rx,Px,Nx,Ox,wl,Fx,Zx,Bx,Ux,zx,jx,Kx,Wx,eS,ug,tS,fg,pg,Cd,aS,lS,cS,lp,cp,pS,mS,AS,bS,vS,hg,wS,SS,jS,gg,qS,HS,_g,$S,GS,VS,KS,eE,tE,Fa,La,Za,rE,nE,oE,iE,uE,dE,mE,Cg,IE,TE,ME,kE,Tg,Mg,kg,Rg,RE,Pg,Ng,Dg,Og,PE,NE,FE,ZE,Zg,_p,UE,jE,qE,$E,yp,bp,vp,wp,KE,Md,kd,Rd,Pd,Nd,YE,JE,Dd,XE,Od,eC,Fd,tC,xp,Tl,Sp,rC,nC,lC,cC,Ld,Ep,Ml,Gg,Vg,kC,RC,xo,PC,qs,Wg,Rp,Xg,eA,JC,tA,rA,XC,rI,nI,oA,sI,aI,sA,fI,iA,pI,mI,hI,gI,Gc,Dp,lA,TI,MI,cA,kI,RI,PI,NI,DI,OI,FI,LI,ZI,BI,UI,zI,jI,qI,HI,YI,JI,XI,eT,tT,rT,nT,oT,sT,iT,aT,lT,cT,uT,dT,fT,pT,mT,hT,gT,yT,xT,kT,PT,NT,DT,OT,FT,_A,ZT,HT,$T,GT,yA,VT,QT,KT,JT,wA,s1,f1,p1,m1,h1,xA,g1,x1,S1,E1,C1,I1,T1,M1,k1,R1,Je,Xe,et,tt,rt,nt,ot,st,ue,ae,fe,qe,le,It,q,ce,Dt,M,f,te,R,Ve,ro,ru,nu,CA,ou,ia,IA,Hs,TA,Ua,MA,su,So,Eo,Kr,kn,be,ht,gt,At,wi,W,Me,Le,Ze,Be,Ue,ne,vr,lr,Ar,ut,Tt,Mt,Ot,xt,nf}from"./chunk-vsefjzzj.js";import{Uo}from"./chunk-zp5b1mb6.js";import{Mo,_r}from"./chunk-3m6ch1x5.js";import{Ql,Kl}from"./chunk-6ns2vhbd.js";import{Qs,io,ma,Bo,vn,Wl,Qa,Oi,Yl}from"./chunk-asgxtqf0.js";import{Jl}from"./chunk-yd1k76na.js";import{Rn,Pn,Nn,wr,Et,yt}from"./chunk-ar6kq7hh.js";import{ha}from"./chunk-0ttr4a6b.js";import{Io}from"./chunk-3584j9fc.js";import{To}from"./chunk-s9svhjv6.js";import{Vn,ao}from"./chunk-m5cpsm28.js";import{fr}from"./chunk-dvkzhpxx.js";import{lo}from"./chunk-4mq874m3.js";import{dn}from"./chunk-t597y392.js";import{co}from"./chunk-80qz30dc.js";import{Nr}from"./chunk-4437dnfa.js";var Js=[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8",key:"7n84p3"}]],Ya=I("at-sign",Js);var tr=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M7 3v18",key:"bbkbws"}],["path",{d:"M3 7.5h4",key:"zfgn84"}],["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 16.5h4",key:"1230mu"}],["path",{d:"M17 3v18",key:"in4fa5"}],["path",{d:"M17 7.5h4",key:"myr1c1"}],["path",{d:"M17 16.5h4",key:"go4c1d"}]],Ja=I("film",tr);var ar=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]],ca=I("globe",ar);var sr=[["path",{d:"m2 21 9.6-9.6",key:"9l79m3"}],["path",{d:"m7.5 15.5 2.3 2.3a1 1 0 0 1 0 1.4l-2.1 2.1a1 1 0 0 1-1.4 0L4 19",key:"fw8biw"}],["circle",{cx:"15.5",cy:"7.5",r:"5.5",key:"4wxmhb"}]],Xt=I("key",sr);var rr=[["rect",{width:"7",height:"9",x:"3",y:"3",rx:"1",key:"10lvy0"}],["rect",{width:"7",height:"5",x:"14",y:"3",rx:"1",key:"16une8"}],["rect",{width:"7",height:"9",x:"14",y:"12",rx:"1",key:"1hutg5"}],["rect",{width:"7",height:"5",x:"3",y:"16",rx:"1",key:"ldoo1y"}]],Ma=I("layout-dashboard",rr);var or=[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]],es=I("maximize-2",or);var ir=[["path",{d:"M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719",key:"1sd12s"}]],ts=I("message-circle",ir);var nr=[["path",{d:"M12 2v20",key:"t6zp3m"}],["path",{d:"m15 19-3 3-3-3",key:"11eu04"}],["path",{d:"m19 9 3 3-3 3",key:"1mg7y2"}],["path",{d:"M2 12h20",key:"9i4pu4"}],["path",{d:"m5 9-3 3 3 3",key:"j64kie"}],["path",{d:"m9 5 3-3 3 3",key:"l8vdw6"}]],as=I("move",nr);var dr=[["path",{d:"M15.39 4.39a1 1 0 0 0 1.68-.474 2.5 2.5 0 1 1 3.014 3.015 1 1 0 0 0-.474 1.68l1.683 1.682a2.414 2.414 0 0 1 0 3.414L19.61 15.39a1 1 0 0 1-1.68-.474 2.5 2.5 0 1 0-3.014 3.015 1 1 0 0 1 .474 1.68l-1.683 1.682a2.414 2.414 0 0 1-3.414 0L8.61 19.61a1 1 0 0 0-1.68.474 2.5 2.5 0 1 1-3.014-3.015 1 1 0 0 0 .474-1.68l-1.683-1.682a2.414 2.414 0 0 1 0-3.414L4.39 8.61a1 1 0 0 1 1.68.474 2.5 2.5 0 1 0 3.014-3.015 1 1 0 0 1-.474-1.68l1.683-1.682a2.414 2.414 0 0 1 3.414 0z",key:"w46dr5"}]],Nt=I("puzzle",dr);var cr=[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]],ua=I("refresh-cw",cr);var mr=[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]],ss=I("send",mr);var ur=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],rs=I("shield-check",ur);var pr=[["path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5",key:"ftymec"}],["rect",{x:"2",y:"6",width:"14",height:"12",rx:"2",key:"158x01"}]],pa=I("video",pr);var gr=[["path",{d:"M15.914 4a1.5 1.5 0 00-2.474-1.561l-9 9A1.5 1.5 0 005.5 14h4.002a.5.5 0 01.471.666L8.086 20a1.5 1.5 0 002.475 1.56l9-9A1.5 1.5 0 0018.5 10h-3.997a.5.5 0 01-.472-.667z",key:"1v7up4"}]],qt=I("zap",gr);var hr=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"11",x2:"11",y1:"8",y2:"14",key:"1vmskp"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],os=I("zoom-in",hr);var br=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],is=I("zoom-out",br);S();S();var yr=fs("group/field flex w-full gap-3 data-[invalid=true]:text-destructive",{variants:{orientation:{vertical:["flex-col [&>*]:w-full [&>.sr-only]:w-auto"],horizontal:["flex-row items-center","[&>[data-slot=field-label]]:flex-auto","has-[>[data-slot=field-content]]:items-start has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px"],responsive:["flex-col @md/field-group:flex-row @md/field-group:items-center [&>*]:w-full @md/field-group:[&>*]:w-auto [&>.sr-only]:w-auto","@md/field-group:[&>[data-slot=field-label]]:flex-auto","@md/field-group:has-[>[data-slot=field-content]]:items-start @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px"]}},defaultVariants:{orientation:"vertical"}});function Oe({className:e,orientation:r="vertical",...a}){return t("div",{role:"group","data-slot":"field","data-orientation":r,className:C(yr({orientation:r}),e),...a})}function Qe({className:e,...r}){return t(W,{"data-slot":"field-label",className:C("group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50","has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col has-[>[data-slot=field]]:rounded-md has-[>[data-slot=field]]:border [&>*]:data-[slot=field]:p-4","has-data-[state=checked]:border-primary has-data-[state=checked]:bg-primary/5 dark:has-data-[state=checked]:bg-primary/10",e),...r})}function aa({className:e,...r}){return t("p",{"data-slot":"field-description",className:C("text-sm leading-normal font-normal text-muted-foreground group-has-[[data-orientation=horizontal]]/field:text-balance","last:mt-0 nth-last-2:-mt-1 [[data-variant=legend]+&]:-mt-1.5","[&>a]:underline [&>a]:underline-offset-4 [&>a:hover]:text-primary",e),...r})}function We({className:e,children:r,errors:a,...l}){let s=N(()=>{if(r)return r;if(!a?.length)return null;let d=[...new Map(a.map((c)=>[c?.message,c])).values()];if(d?.length==1)return d[0]?.message;return t("ul",{className:"ml-4 flex list-disc flex-col gap-1",children:d.map((c,g)=>c?.message&&t("li",{children:c.message},g))})},[r,a]);if(!s)return null;return t("div",{role:"alert","data-slot":"field-error",className:C("text-sm font-normal text-destructive",e),...l,children:s})}function ns({update:e,notify:r,unwatched:a}){return{link:l,unlink:s,propagate:d,checkDirty:c,shallowPropagate:g};function l(p,b,x){let m=b.depsTail;if(m!==void 0&&m.dep===p)return;let i=m!==void 0?m.nextDep:b.deps;if(i!==void 0&&i.dep===p){i.version=x,b.depsTail=i;return}let v=p.subsTail;if(v!==void 0&&v.version===x&&v.sub===b)return;let w=b.depsTail=p.subsTail={version:x,dep:p,sub:b,prevDep:m,nextDep:i,prevSub:v,nextSub:void 0};if(i!==void 0)i.prevDep=w;if(m!==void 0)m.nextDep=w;else b.deps=w;if(v!==void 0)v.nextSub=w;else p.subs=w}function s(p,b=p.sub){let{dep:x,prevDep:m,nextDep:i,nextSub:v,prevSub:w}=p;if(i!==void 0)i.prevDep=m;else b.depsTail=m;if(m!==void 0)m.nextDep=i;else b.deps=i;if(v!==void 0)v.prevSub=w;else x.subsTail=w;if(w!==void 0)w.nextSub=v;else if((x.subs=v)===void 0)a(x);return i}function d(p){let b=p.nextSub,x;e:do{let m=p.sub,i=m.flags;if(!(i&60))m.flags=i|32;else if(!(i&12))i=0;else if(!(i&4))m.flags=i&-9|32;else if(!(i&48)&&_(p,m))m.flags=i|40,i&=1;else i=0;if(i&2)r(m);if(i&1){let v=m.subs;if(v!==void 0){let w=(p=v).nextSub;if(w!==void 0)x={value:b,prev:x},b=w;continue}}if((p=b)!==void 0){b=p.nextSub;continue}while(x!==void 0)if(p=x.value,x=x.prev,p!==void 0){b=p.nextSub;continue e}break}while(!0)}function c(p,b){let x,m=0,i=!1;e:do{let v=p.dep,w=v.flags;if(b.flags&16)i=!0;else if((w&17)===17){if(e(v)){let k=v.subs;if(k.nextSub!==void 0)g(k);i=!0}}else if((w&33)===33){if(p.nextSub!==void 0||p.prevSub!==void 0)x={value:p,prev:x};p=v.deps,b=v,++m;continue}if(!i){let k=p.nextDep;if(k!==void 0){p=k;continue}}while(m--){let k=b.subs,z=k.nextSub!==void 0;if(z)p=x.value,x=x.prev;else p=k;if(i){if(e(b)){if(z)g(k);b=p.sub;continue}i=!1}else b.flags&=-33;b=p.sub;let J=p.nextDep;if(J!==void 0){p=J;continue e}}return i}while(!0)}function g(p){do{let b=p.sub,x=b.flags;if((x&48)===32){if(b.flags=x|16,(x&6)===2)r(b)}}while((p=p.nextSub)!==void 0)}function _(p,b){let x=b.depsTail;while(x!==void 0){if(x===p)return!0;x=x.prevDep}return!1}}function sa(e,r,a){let l=typeof e==="object",s=l?e:void 0;return{next:(l?e.next:e)?.bind(s),error:(l?e.error:r)?.bind(s),complete:(l?e.complete:a)?.bind(s)}}var Da=[],ga=0,{link:ls,unlink:Cr,propagate:kr,checkDirty:cs,shallowPropagate:ds}=ns({update(e){return e._update()},notify(e){Da[Aa++]=e,e.flags&=-3},unwatched(e){if(e.depsTail!==void 0)e.depsTail=void 0,e.flags=17,va(e)}}),fa=0,Aa=0,St,Ia=0;function Ge(e){try{++Ia,e()}finally{if(!--Ia)Ta()}}function va(e){let r=e.depsTail,a=r!==void 0?r.nextDep:e.deps;while(a!==void 0)a=Cr(a,e)}function Ta(){if(Ia>0)return;while(fa<Aa){let e=Da[fa];Da[fa++]=void 0,e.notify()}fa=0,Aa=0}function ba(e,r){let a=typeof e==="function",l=e,s={_snapshot:a?void 0:e,subs:void 0,subsTail:void 0,deps:void 0,depsTail:void 0,flags:a?0:1,get(){if(St!==void 0)ls(s,St,ga);return s._snapshot},subscribe(d){let c=sa(d),g={current:!1},_=Mr(()=>{if(s.get(),!g.current)g.current=!0;else c.next?.(s._snapshot)});return{unsubscribe:()=>{_.stop()}}},_update(d){let c=St,g=r?.compare??Object.is;if(a)St=s,++ga,s.depsTail=void 0;else if(d===void 0)return!1;if(a)s.flags=5;try{let _=s._snapshot,p=typeof d==="function"?d(_):d===void 0&&a?l(_):d;if(_===void 0||!g(_,p))return s._snapshot=p,!0;return!1}finally{if(St=c,a)s.flags&=-5;va(s)}}};if(a)s.flags=17,s.get=function(){let d=s.flags;if(d&16||d&32&&cs(s.deps,s)){if(s._update()){let c=s.subs;if(c!==void 0)ds(c)}}else if(d&32)s.flags=d&-33;if(St!==void 0)ls(s,St,ga);return s._snapshot};else s.set=function(d){if(s._update(d)){let c=s.subs;if(c!==void 0)kr(c),ds(c),Ta()}};return s}function Mr(e){let r=()=>{let l=St;St=a,++ga,a.depsTail=void 0,a.flags=6;try{return e()}finally{St=l,a.flags&=-5,va(a)}},a={deps:void 0,depsTail:void 0,subs:void 0,subsTail:void 0,flags:6,notify(){let l=this.flags;if(l&16||l&32&&cs(this.deps,this))r();else this.flags=2},stop(){this.flags=0,this.depsTail=void 0,va(this)}};return r(),a}var Ea=class{constructor(e,r){if(this.atom=ba(e),this.get=this.get.bind(this),this.setState=this.setState.bind(this),this.subscribe=this.subscribe.bind(this),r)this.actions=r(this)}setState(e){this.atom.set(e)}get state(){return this.atom.get()}get(){return this.state}subscribe(e){return this.atom.subscribe(sa(e))}},ms=class{constructor(e){this.atom=ba(e)}get state(){return this.atom.get()}get(){return this.state}subscribe(e){return this.atom.subscribe(sa(e))}};function kt(e,r){if(typeof e==="function")return new ms(e);if(r)return new Ea(e,r);return new Ea(e)}var us=class{constructor(e,r){if(this.fn=e,this.options=r,this.lastExecutionTime=0,this.isPending=!1,this.maybeExecute=(...a)=>{let l=Date.now()-this.lastExecutionTime;if(this.options.leading&&l>=this.options.wait)this.execute(...a);else if(this.lastArgs=a,!this.timeoutId&&this.options.trailing){let s=this.options.wait-l;this.isPending=!0,this.timeoutId=setTimeout(()=>{if(this.lastArgs!==void 0)this.execute(...this.lastArgs)},s)}},this.execute=(...a)=>{this.fn(...a),this.options.onExecute?.(a,this),this.lastExecutionTime=Date.now(),this.clearTimeout(),this.lastArgs=void 0,this.isPending=!1},this.flush=()=>{if(this.isPending&&this.lastArgs)this.execute(...this.lastArgs)},this.cancel=()=>{this.clearTimeout(),this.lastArgs=void 0,this.isPending=!1},this.clearTimeout=()=>{if(this.timeoutId)clearTimeout(this.timeoutId),this.timeoutId=void 0},this.options.leading===void 0&&this.options.trailing===void 0)this.options.leading=!0,this.options.trailing=!0}};function Va(e,r){return new us(e,r).maybeExecute}var Ra=class{#o=!0;#t;#e;#m;#a;#n;#s;#l;#u=0;#f=5;#i=!1;#d=!1;#r=null;#p=()=>{this.debugLog("Connected to event bus"),this.#n=!0,this.#i=!1,this.debugLog("Emitting queued events",this.#a),this.#a.forEach((e)=>this.emitEventToBus(e)),this.#a=[],this.stopConnectLoop(),this.#e().removeEventListener("tanstack-connect-success",this.#p)};#c=()=>{if(this.#u<this.#f){this.#u++,this.dispatchCustomEvent("tanstack-connect",{});return}this.#e().removeEventListener("tanstack-connect",this.#c),this.#d=!0,this.debugLog("Max retries reached, giving up on connection"),this.stopConnectLoop()};#g=()=>{if(this.#i)return;this.#i=!0,this.#e().addEventListener("tanstack-connect-success",this.#p),this.#c()};constructor({pluginId:e,debug:r=!1,enabled:a=!0,reconnectEveryMs:l=300}){this.#t=e,this.#o=a,this.#e=this.getGlobalTarget,this.#m=r,this.debugLog(" Initializing event subscription for plugin",this.#t),this.#a=[],this.#n=!1,this.#d=!1,this.#s=null,this.#l=l}startConnectLoop(){if(this.#s!==null||this.#n)return;this.debugLog(`Starting connect loop (every ${this.#l}ms)`),this.#s=setInterval(this.#c,this.#l)}stopConnectLoop(){if(this.#i=!1,this.#s===null)return;clearInterval(this.#s),this.#s=null,this.#a=[],this.debugLog("Stopped connect loop")}debugLog(...e){if(this.#m)console.log(`\uD83C\uDF34 [tanstack-devtools:${this.#t}-plugin]`,...e)}getGlobalTarget(){if(typeof globalThis<"u"&&globalThis.__TANSTACK_EVENT_TARGET__)return this.debugLog("Using global event target"),globalThis.__TANSTACK_EVENT_TARGET__;if(typeof window<"u"&&typeof window.addEventListener<"u")return this.debugLog("Using window as event target"),window;let e=typeof EventTarget<"u"?new EventTarget:void 0;if(typeof e>"u"||typeof e.addEventListener>"u")return this.debugLog("No event mechanism available, running in non-web environment"),{addEventListener:()=>{},removeEventListener:()=>{},dispatchEvent:()=>!1};return this.debugLog("Using new EventTarget as fallback"),e}getPluginId(){return this.#t}dispatchCustomEventShim(e,r){try{let a=new Event(e,{detail:r});this.#e().dispatchEvent(a)}catch(a){this.debugLog("Failed to dispatch shim event")}}dispatchCustomEvent(e,r){try{this.#e().dispatchEvent(new CustomEvent(e,{detail:r}))}catch(a){this.dispatchCustomEventShim(e,r)}}emitEventToBus(e){this.debugLog("Emitting event to client bus",e),this.dispatchCustomEvent("tanstack-dispatch-event",e)}createEventPayload(e,r){return{type:`${this.#t}:${e}`,payload:r,pluginId:this.#t}}emit(e,r){if(!this.#o){this.debugLog("Event bus client is disabled, not emitting event",e,r);return}if(this.#r)this.debugLog("Emitting event to internal event target",e,r),this.#r.dispatchEvent(new CustomEvent(`${this.#t}:${e}`,{detail:this.createEventPayload(e,r)}));if(this.#d){this.debugLog("Previously failed to connect, not emitting to bus");return}if(!this.#n){if(this.debugLog("Bus not available, will be pushed as soon as connected"),this.#a.push(this.createEventPayload(e,r)),typeof CustomEvent<"u"&&!this.#i)this.#g(),this.startConnectLoop();return}return this.emitEventToBus(this.createEventPayload(e,r))}on(e,r,a){let l=a?.withEventTarget??!1,s=`${this.#t}:${e}`;if(l){if(!this.#r)this.#r=new EventTarget;this.#r.addEventListener(s,(c)=>{r(c.detail)})}if(!this.#o)return this.debugLog("Event bus client is disabled, not registering event",s),()=>{};let d=(c)=>{this.debugLog("Received event from bus",c.detail),r(c.detail)};return this.#e().addEventListener(s,d),this.debugLog("Registered event to bus",s),()=>{if(l)this.#r?.removeEventListener(s,d);this.#e().removeEventListener(s,d)}}onAll(e){if(!this.#o)return this.debugLog("Event bus client is disabled, not registering event"),()=>{};let r=(a)=>{let l=a.detail;e(l)};return this.#e().addEventListener("tanstack-devtools-global",r),()=>this.#e().removeEventListener("tanstack-devtools-global",r)}onAllPluginEvents(e){if(!this.#o)return this.debugLog("Event bus client is disabled, not registering event"),()=>{};let r=(a)=>{let l=a.detail;if(this.#t&&l.pluginId!==this.#t)return;e(l)};return this.#e().addEventListener("tanstack-devtools-global",r),()=>this.#e().removeEventListener("tanstack-devtools-global",r)}};class ps extends Ra{constructor(){super({pluginId:"form-devtools",reconnectEveryMs:1000})}}var mt=new ps;function Ft(e,r){return typeof e==="function"?e(r):e}function Yt(e,r){return _a(r).reduce((l,s)=>{if(l===null)return null;if(typeof l<"u")return l[s];return},e)}function Gt(e,r,a){let l=_a(r);function s(d){if(!l.length)return Ft(a,d);let c=l.shift();if(typeof c==="string"||typeof c==="number"&&!Array.isArray(d)){if(typeof d==="object"){if(d===null)d={};return{...d,[c]:s(d[c])}}return{[c]:s()}}if(Array.isArray(d)&&typeof c==="number"){let g=d.slice(0,c);return[...g.length?g:Array(c),s(d[c]),...d.slice(c+1)]}return[...Array(c),s()]}return s(e)}function ja(e,r){let a=_a(r);function l(s){if(!s)return;if(a.length===1){let c=a[0];if(Array.isArray(s)&&typeof c==="number")return s.filter((p,b)=>b!==c);let{[c]:g,..._}=s;return _}let d=a.shift();if(typeof d==="string"||typeof d==="number"&&!Array.isArray(s)){if(typeof s==="object")return{...s,[d]:l(s[d])}}if(typeof d==="number"){if(Array.isArray(s)){if(d>=s.length)return s;let c=s.slice(0,d);return[...c.length?c:Array(d),l(s[d]),...s.slice(d+1)]}}throw Error("It seems we have created an infinite loop in deleteBy. ")}return l(e)}var gs=46,Ba=91,qa=93,hs=48,Fr=57;function _a(e){if(Array.isArray(e))return[...e];if(typeof e!=="string")throw Error("Path must be a string.");let r=e.length,a=[],l=r>0&&e.charCodeAt(0)===Ba?1:0,s=!0,d=-1;for(let c=l;c<=r;c++){let g=c<r?e.charCodeAt(c):-1;if(c===r||g===gs||g===Ba||g===qa){let _=c-l;if(_>0){let p=s&&(_===1||e.charCodeAt(l)!==hs),b=e.slice(l,c);if(p){let x=parseInt(b,10);if(_<=15||String(x)===b)a.push(x);else a.push(b)}else a.push(b)}else if(d!==qa&&!(d===-1&&g===qa)&&!(d===g&&(g===gs||g===Ba)))a.push("");l=c+1,s=!0}else if(g<hs||g>Fr)s=!1;d=g}if(!a.length)a.push("");return a}function Oa(e){return!(Array.isArray(e)&&e.length===0)}function Pt(e,r){let a=(l)=>l.validators.filter(Boolean).map((s)=>({cause:s.cause,validate:s.fn}));return r.validationLogic({form:r.form,group:r.group,validators:r.validators,event:{type:e,fieldName:r.fieldName,async:!1},runValidation:a})}function Rt(e,r){let{asyncDebounceMs:a}=r,{onBlurAsyncDebounceMs:l,onChangeAsyncDebounceMs:s,onDynamicAsyncDebounceMs:d}=r.validators||{},c=a??0,g=(_)=>_.validators.filter(Boolean).map((p)=>{let b=p?.cause||e,x=c;switch(b){case"change":x=s??c;break;case"blur":x=l??c;break;case"dynamic":x=d??c;break;case"submit":x=0;break}if(e==="submit")x=0;return{cause:b,validate:p.fn,debounceMs:x}});return r.validationLogic({form:r.form,group:r.group,validators:r.validators,event:{type:e,fieldName:r.fieldName,async:!0},runValidation:g})}var Jt=(e)=>!!e&&typeof e==="object"&&("fields"in e);function pt(e,r){if(Object.is(e,r))return!0;if(typeof e!=="object"||e===null||typeof r!=="object"||r===null)return!1;if(e instanceof Date&&r instanceof Date)return e.getTime()===r.getTime();if(e instanceof Map&&r instanceof Map){if(e.size!==r.size)return!1;for(let[s,d]of e)if(!r.has(s)||!Object.is(d,r.get(s)))return!1;return!0}if(e instanceof Set&&r instanceof Set){if(e.size!==r.size)return!1;for(let s of e)if(!r.has(s))return!1;return!0}let a=Object.keys(e),l=Object.keys(r);if(a.length!==l.length)return!1;if(a.length===0&&!Array.isArray(e)&&!Array.isArray(r)&&(Object.getPrototypeOf(e)!==Object.prototype||Object.getPrototypeOf(r)!==Object.prototype))return!1;for(let s of a)if(!l.includes(s)||!pt(e[s],r[s]))return!1;return!0}var ea=({newFormValidatorError:e,isPreviousErrorFromFormValidator:r,previousErrorValue:a})=>{if(e)return{newErrorValue:e,newSource:"form"};if(r)return{newErrorValue:void 0,newSource:void 0};if(a)return{newErrorValue:a,newSource:"field"};return{newErrorValue:void 0,newSource:void 0}},Wt=({formLevelError:e,fieldLevelError:r})=>{if(r)return{newErrorValue:r,newSource:"field"};if(e)return{newErrorValue:e,newSource:"form"};return{newErrorValue:void 0,newSource:void 0}};function it(e,r){if(e===void 0||e===null)return r;return{...e,...r}}var zt=256,xa=[],ya;while(zt--)xa[zt]=(zt+256).toString(16).substring(1);function ra(){let e=0,r,a="";if(!ya||zt+16>256){ya=Array(256),e=256;while(e--)ya[e]=256*Math.random()|0;e=0,zt=0}for(;e<16;e++){if(r=ya[zt+e],e===6)a+=xa[r&15|64];else if(e===8)a+=xa[r&63|128];else a+=xa[r];if(e&1&&e>1&&e<11)a+="-"}return zt++,a}var $a=Va((e)=>mt.emit("form-state",{id:e.formId,state:e.store.state}),{wait:300});function Ht(e){if(e===null||typeof e!=="object")return e;if(e instanceof Date)return new Date(e.getTime());if(Array.isArray(e)){let a=[];for(let l=0;l<e.length;l++)a[l]=Ht(e[l]);return a}if(e instanceof Map){let a=new Map;return e.forEach((l,s)=>{a.set(s,Ht(l))}),a}if(e instanceof Set){let a=new Set;return e.forEach((l)=>{a.add(Ht(l))}),a}let r={};for(let a in e)if(Object.prototype.hasOwnProperty.call(e,a))r[a]=Ht(e[a]);return r}function _t(e,r){return r===e||r.startsWith(`${e}.`)||r.startsWith(`${e}[`)}var ft=(e)=>{if(!e.validators)return e.runValidation({validators:[],form:e.form});let r=e.event.async,a=r?void 0:{fn:e.validators.onMount,cause:"mount"},l={fn:r?e.validators.onChangeAsync:e.validators.onChange,cause:"change"},s={fn:r?e.validators.onBlurAsync:e.validators.onBlur,cause:"blur"},d={fn:r?e.validators.onSubmitAsync:e.validators.onSubmit,cause:"submit"},c=r?void 0:{fn:()=>{return},cause:"server"};switch(e.event.type){case"mount":return e.runValidation({validators:[a],form:e.form});case"submit":return e.runValidation({validators:[l,s,d,c],form:e.form});case"server":return e.runValidation({validators:[],form:e.form});case"blur":return e.runValidation({validators:[s,c],form:e.form});case"change":return e.runValidation({validators:[l,c],form:e.form});default:throw Error(`Unknown validation event type: ${e.event.type}`)}};function Dr(e,r){let a=new Map;for(let l of e){let s=l.path??[],d=r,c="";for(let g=0;g<s.length;g++){let _=s[g];if(_===void 0)continue;let p=typeof _==="object"?_.key:_,b=Number(p);if(Array.isArray(d)&&!Number.isNaN(b))c+=`[${b}]`;else c+=(g>0?".":"")+String(p);if(typeof d==="object"&&d!==null)d=d[p];else d=void 0}a.set(c,(a.get(c)??[]).concat(l))}return Object.fromEntries(a)}var vs=(e,r)=>{let a=Dr(e,r);return{form:a,fields:a}},Lt={validate({value:e,validationSource:r},a){let l=a["~standard"].validate(e);if(l instanceof Promise)throw Error("async function passed to sync validator");if(!l.issues)return;if(r==="field")return l.issues;return vs(l.issues,e)},async validateAsync({value:e,validationSource:r},a){let l=await a["~standard"].validate(e);if(!l.issues)return;if(r==="field")return l.issues;return vs(l.issues,e)}},ta=(e)=>!!e&&("~standard"in e);var lt={isValidating:!1,isTouched:!1,isBlurred:!1,isDirty:!1,isPristine:!0,isValid:!0,isDefaultValue:!0,errors:[],errorMap:{},errorSourceMap:{},_arrayVersion:0,_pendingValidationsCount:0};function Bt(e){function r(x){let m=e.getFieldMeta(x)??lt;e.setFieldMeta(x,{...m,_arrayVersion:(m._arrayVersion||0)+1})}function a(x,m,i){r(x);let v=g(x,m,"move",i),w=Math.min(m,i),k=Math.max(m,i);for(let J=w;J<=k;J++)v.push(c(x,J));let z=Object.keys(e.fieldInfo).reduce((J,H)=>{if(H.startsWith(c(x,m)))J.set(H,e.getFieldMeta(H));return J},new Map);p(v,m<i?"up":"down"),Object.keys(e.fieldInfo).filter((J)=>J.startsWith(c(x,i))).forEach((J)=>{let H=J.replace(c(x,i),c(x,m)),ie=z.get(H);if(ie)e.setFieldMeta(J,ie)})}function l(x,m){r(x);let i=g(x,m,"remove");p(i,"up")}function s(x,m,i){r(x),g(x,m,"swap",i).forEach((w)=>{if(!w.toString().startsWith(c(x,m)))return;let k=w.toString().replace(c(x,m),c(x,i)),[z,J]=[e.getFieldMeta(w),e.getFieldMeta(k)];if(z)e.setFieldMeta(k,z);if(J)e.setFieldMeta(w,J)})}function d(x,m){r(x);let i=g(x,m,"insert");p(i,"down"),i.forEach((v)=>{if(v.toString().startsWith(c(x,m)))e.setFieldMeta(v,b())})}function c(x,m){return`${x}[${m}]`}function g(x,m,i,v){let w=[c(x,m)];switch(i){case"swap":w.push(c(x,v));break;case"move":{let[k,z]=[Math.min(m,v),Math.max(m,v)];for(let J=k;J<=z;J++)w.push(c(x,J));break}default:{let k=e.getFieldValue(x),z=Array.isArray(k)?k.length:0;for(let J=m+1;J<z;J++)w.push(c(x,J));break}}return Object.keys(e.fieldInfo).filter((k)=>w.some((z)=>k.startsWith(z)))}function _(x,m){return x.replace(/\[(\d+)\]/,(i,v)=>{let w=parseInt(v,10);return`[${m==="up"?w+1:Math.max(0,w-1)}]`})}function p(x,m){(m==="up"?x:[...x].reverse()).forEach((v)=>{let w=_(v.toString(),m),k=e.getFieldMeta(w);if(k)e.setFieldMeta(v,k);else e.setFieldMeta(v,b())})}let b=()=>lt;return{bumpArrayVersion:r,handleArrayMove:a,handleArrayRemove:l,handleArraySwap:s,handleArrayInsert:d}}function Ka(e){return{values:e.values??{},errorMap:e.errorMap??{},fieldMetaBase:e.fieldMetaBase??{},formGroupStateBase:e.formGroupStateBase??{},isSubmitted:e.isSubmitted??!1,isSubmitting:e.isSubmitting??!1,isValidating:e.isValidating??!1,submissionAttempts:e.submissionAttempts??0,isSubmitSuccessful:e.isSubmitSuccessful??!1,validationMetaMap:e.validationMetaMap??{onChange:void 0,onBlur:void 0,onSubmit:void 0,onMount:void 0,onServer:void 0,onDynamic:void 0}}}class na{constructor(e){this.options={},this.fieldInfo={},this.formGroupApis=new Set,this.mount=()=>{let s=this.store.subscribe(()=>{$a(this)}),d=mt.on("request-form-state",(b)=>{if(b.payload.id===this._formId)mt.emit("form-api",{id:this._formId,state:this.store.state,options:this.options})}),c=mt.on("request-form-reset",(b)=>{if(b.payload.id===this._formId)this.reset()}),g=mt.on("request-form-force-submit",(b)=>{if(b.payload.id===this._formId)this._devtoolsSubmissionOverride=!0,this.handleSubmit(),this._devtoolsSubmissionOverride=!1}),_=()=>{g(),c(),d(),s.unsubscribe(),mt.emit("form-unmounted",{id:this._formId})};this.options.listeners?.onMount?.({formApi:this});let{onMount:p}=this.options.validators||{};if(mt.emit("form-api",{id:this._formId,state:this.store.state,options:this.options}),!p)return _;return this.validateSync("mount"),_},this.update=(s)=>{if(!s)return;let d=this.options;this.options=s;let c=s.defaultValues&&!pt(s.defaultValues,d.defaultValues)&&!this.state.isTouched,g=!pt(s.defaultState,d.defaultState)&&!this.state.isTouched;if(!c&&!g)return;if(Ge(()=>{this.baseStore.setState(()=>Ka(Object.assign({},this.state,g?s.defaultState:{},c?{values:s.defaultValues}:{})))}),c){let _=Bt(this);for(let p of Object.keys(this.fieldInfo))if(Array.isArray(this.getFieldValue(p)))_.bumpArrayVersion(p)}mt.emit("form-api",{id:this._formId,state:this.store.state,options:this.options})},this.reset=(s,d)=>{let{fieldMeta:c}=this.state,g=this.resetFieldMeta(c);if(s&&!d?.keepDefaultValues)this.options={...this.options,defaultValues:s};this.baseStore.setState(()=>{let _=s??this.options.defaultValues??this.options.defaultState?.values;if(!s)Object.values(this.fieldInfo).forEach((p)=>{if(p.instance&&p.instance.options.defaultValue!==void 0)_=Gt(_,p.instance.name,p.instance.options.defaultValue)});return Ka({...this.options.defaultState,values:_,fieldMetaBase:g})})},this.validateAllFields=async(s)=>{let d=[];return Ge(()=>{Object.values(this.fieldInfo).forEach((g)=>{if(!g.instance)return;let _=g.instance;if(d.push(Promise.resolve().then(()=>_.validate(s,{skipFormValidation:!0,skipGroupValidation:!0}))),!g.instance.store.state.meta.isTouched)g.instance.setMeta((p)=>({...p,isTouched:!0}))})}),(await Promise.all(d)).flat()},this.validateArrayFieldsStartingFrom=async(s,d,c)=>{let g=this.getFieldValue(s),_=Array.isArray(g)?Math.max(g.length-1,0):null,p=[`${s}[${d}]`];for(let i=d+1;i<=(_??0);i++)p.push(`${s}[${i}]`);let b=Object.keys(this.fieldInfo).filter((i)=>p.some((v)=>i.startsWith(v))),x=[];return Ge(()=>{b.forEach((i)=>{x.push(Promise.resolve().then(()=>this.validateField(i,c)))})}),(await Promise.all(x)).flat()},this.validateField=(s,d)=>{let c=this.fieldInfo[s]?.instance;if(!c){let{hasErrored:g}=this.validateSync(d);if(g&&!this.options.asyncAlways)return this.getFieldMeta(s)?.errors??[];return this.validateAsync(d).then(()=>this.getFieldMeta(s)?.errors??[])}if(!c.store.state.meta.isTouched)c.setMeta((g)=>({...g,isTouched:!0}));return c.validate(d)},this.validateSync=(s,d)=>{let c=Pt(s,{...this.options,form:this,group:d?.group,validationLogic:this.options.validationLogic||ft}),g=!1,_={};return Ge(()=>{for(let x of c){if(!x.validate)continue;let m=this.runValidator({validate:x.validate,value:{value:this.state.values,formApi:this,validationSource:"form"},type:"validate"}),{formError:i,fieldErrors:v}=wa(m),w=oa(x.cause),k=new Set([...Object.keys(this.state.fieldMeta),...Object.keys(v||{})]);if(d?.filterFieldNames)k=new Set([...k].filter(d.filterFieldNames));for(let z of k){if(this.baseStore.state.fieldMetaBase[z]===void 0&&!v?.[z])continue;let J=this.getFieldMeta(z)??lt,{errorMap:H,errorSourceMap:ie}=J,oe=v?.[z],{newErrorValue:T,newSource:P}=ea({newFormValidatorError:oe,isPreviousErrorFromFormValidator:ie?.[w]==="form",previousErrorValue:H?.[w]});if(P==="form")_[z]={..._[z],[w]:oe};if(H?.[w]!==T)this.setFieldMeta(z,(j=lt)=>({...j,errorMap:{...j.errorMap,[w]:T},errorSourceMap:{...j.errorSourceMap,[w]:P}}))}if(!d?.dontUpdateFormErrorMap){if(this.state.errorMap?.[w]!==i)this.baseStore.setState((z)=>({...z,errorMap:{...z.errorMap,[w]:i}}))}if(i||v)g=!0}if(d?.dontUpdateFormErrorMap)return;let p=oa("submit");if(this.state.errorMap?.[p]&&s!=="submit"&&!g)this.baseStore.setState((x)=>({...x,errorMap:{...x.errorMap,[p]:void 0}}));let b=oa("server");if(this.state.errorMap?.[b]&&s!=="server"&&!g)this.baseStore.setState((x)=>({...x,errorMap:{...x.errorMap,[b]:void 0}}))}),{hasErrored:g,fieldsErrorMap:_}},this.validateAsync=async(s,d)=>{let c=Rt(s,{...this.options,form:this,group:d?.group,validationLogic:this.options.validationLogic||ft});if(!this.state.isFormValidating)this.baseStore.setState((x)=>({...x,isFormValidating:!0}));let g=[],_;for(let x of c){if(!x.validate)continue;let m=oa(x.cause);this.state.validationMetaMap[m]?.lastAbortController.abort();let v=new AbortController;this.state.validationMetaMap[m]={lastAbortController:v},g.push(new Promise(async(w)=>{let k;try{k=await new Promise((T,P)=>{setTimeout(async()=>{if(v.signal.aborted)return T(void 0);try{T(await this.runValidator({validate:x.validate,value:{value:this.state.values,formApi:this,validationSource:"form",signal:v.signal},type:"validateAsync"}))}catch(j){P(j)}},x.debounceMs)})}catch(T){k=T}let{formError:z,fieldErrors:J}=wa(k);if(J)_=_?{..._,...J}:J;let H=oa(x.cause),ie=new Set([...Object.keys(this.state.fieldMeta),...Object.keys(_||{})]),oe=Array.from(ie);if(d?.filterFieldNames)oe=oe.filter(d.filterFieldNames);for(let T of oe){if(this.baseStore.state.fieldMetaBase[T]===void 0&&!_?.[T])continue;let P=this.getFieldMeta(T)??lt,{errorMap:j,errorSourceMap:X}=P,F=_?.[T],{newErrorValue:Y,newSource:ye}=ea({newFormValidatorError:F,isPreviousErrorFromFormValidator:X?.[H]==="form",previousErrorValue:j?.[H]});if(j?.[H]!==Y)this.setFieldMeta(T,(me=lt)=>({...me,errorMap:{...me.errorMap,[H]:Y},errorSourceMap:{...me.errorSourceMap,[H]:ye}}))}if(!d?.dontUpdateFormErrorMap)this.baseStore.setState((T)=>({...T,errorMap:{...T.errorMap,[H]:z}}));w(_?{fieldErrors:_,errorMapKey:H}:void 0)}))}let p=[],b={};if(g.length){p=await Promise.all(g);for(let x of p)if(x?.fieldErrors){let{errorMapKey:m}=x;for(let[i,v]of Object.entries(x.fieldErrors)){let k={...b[i]||{},[m]:v};b[i]=k}}}return this.baseStore.setState((x)=>({...x,isFormValidating:!1})),b},this.validate=(s,d)=>{let{hasErrored:c,fieldsErrorMap:g}=this.validateSync(s,d);if(c&&!this.options.asyncAlways)return g;return this.validateAsync(s,d)},this._handleSubmit=async(s)=>{this.baseStore.setState((g)=>({...g,isSubmitted:!1,submissionAttempts:g.submissionAttempts+1,isSubmitSuccessful:!1})),Ge(()=>{Object.values(this.fieldInfo).forEach((g)=>{if(!g.instance)return;if(!g.instance.store.state.meta.isTouched)g.instance.setMeta((_)=>({..._,isTouched:!0}))})});let d=s??this.options.onSubmitMeta;if(!this.state.canSubmit&&!this._devtoolsSubmissionOverride){if(this.baseStore.state.submissionAttempts<=1){this.options.onSubmitInvalid?.({value:this.state.values,formApi:this,meta:d});return}}this.baseStore.setState((g)=>({...g,isSubmitting:!0}));let c=()=>{this.baseStore.setState((g)=>({...g,isSubmitting:!1}))};if(await this.validateAllFields("submit"),!this.state.isFieldsValid){c(),this.options.onSubmitInvalid?.({value:this.state.values,formApi:this,meta:d}),mt.emit("form-submission",{id:this._formId,submissionAttempt:this.state.submissionAttempts,successful:!1,stage:"validateAllFields",errors:Object.values(this.state.fieldMeta).map((g)=>g.errors).flat()});return}if(await this.validate("submit"),!this.state.isValid){c(),this.options.onSubmitInvalid?.({value:this.state.values,formApi:this,meta:d}),mt.emit("form-submission",{id:this._formId,submissionAttempt:this.state.submissionAttempts,successful:!1,stage:"validate",errors:this.state.errors});return}Ge(()=>{Object.values(this.fieldInfo).forEach((g)=>{g.instance?.triggerOnSubmitListener()})}),this.options.listeners?.onSubmit?.({formApi:this,meta:d});try{await this.options.onSubmit?.({value:this.state.values,formApi:this,meta:d}),Ge(()=>{this.baseStore.setState((g)=>({...g,isSubmitted:!0,isSubmitSuccessful:!0})),mt.emit("form-submission",{id:this._formId,submissionAttempt:this.state.submissionAttempts,successful:!0}),c()})}catch(g){throw this.baseStore.setState((_)=>({..._,isSubmitSuccessful:!1})),mt.emit("form-submission",{id:this._formId,submissionAttempt:this.state.submissionAttempts,successful:!1,stage:"inflight",onError:g}),c(),g}},this.getFieldValue=(s)=>Yt(this.state.values,s),this.getFieldMeta=(s)=>this.state.fieldMeta[s],this.getFormGroupMeta=(s)=>this.formGroupMetaDerived.state[s],this.getFieldInfo=(s)=>this.fieldInfo[s]||={instance:null,validationMetaMap:{onChange:void 0,onBlur:void 0,onSubmit:void 0,onMount:void 0,onServer:void 0,onDynamic:void 0}},this.setFieldMeta=(s,d)=>{this.baseStore.setState((c)=>({...c,fieldMetaBase:{...c.fieldMetaBase,[s]:Ft(d,c.fieldMetaBase[s])}}))},this.resetFieldMeta=(s)=>Object.keys(s).reduce((d,c)=>{let g=c;return d[g]=lt,d},{}),this.setFieldValue=(s,d,c)=>{let g=c?.dontUpdateMeta??!1,_=c?.dontRunListeners??!1,p=c?.dontValidate??!1;if(Ge(()=>{if(!g)this.setFieldMeta(s,(b)=>({...b,isTouched:!0,isDirty:!0,errorMap:{...b?.errorMap,onMount:void 0}}));this.baseStore.setState((b)=>({...b,values:Gt(b.values,s,d)}))}),!_)this.getFieldInfo(s).instance?.triggerOnChangeListener();if(!p)this.validateField(s,"change")},this.deleteField=(s)=>{let c=[...Object.keys(this.fieldInfo).filter((g)=>{let _=s.toString();return g.startsWith(`${_}.`)||g.startsWith(`${_}[`)}),s];this.baseStore.setState((g)=>{let _={...g};return c.forEach((p)=>{_.values=ja(_.values,p),delete this.fieldInfo[p],delete _.fieldMetaBase[p]}),_})},this.pushFieldValue=(s,d,c)=>{this.setFieldValue(s,(g)=>[...Array.isArray(g)?g:[],d],c),Bt(this).bumpArrayVersion(s)},this.insertFieldValue=async(s,d,c,g)=>{this.setFieldValue(s,(p)=>[...p.slice(0,d),c,...p.slice(d)],it(g,{dontValidate:!0}));let _=g?.dontValidate??!1;if(!_)await this.validateField(s,"change");if(Bt(this).handleArrayInsert(s,d),!_)await this.validateArrayFieldsStartingFrom(s,d,"change")},this.replaceFieldValue=async(s,d,c,g)=>{if(this.setFieldValue(s,(p)=>p.map((b,x)=>x===d?c:b),it(g,{dontValidate:!0})),Bt(this).bumpArrayVersion(s),!(g?.dontValidate??!1))await this.validateField(s,"change"),await this.validateArrayFieldsStartingFrom(s,d,"change")},this.removeFieldValue=async(s,d,c)=>{let g=this.getFieldValue(s),_=Array.isArray(g)?Math.max(g.length-1,0):null;if(this.setFieldValue(s,(b)=>b.filter((x,m)=>m!==d),it(c,{dontValidate:!0})),Bt(this).handleArrayRemove(s,d),_!==null){let b=`${s}[${_}]`;this.deleteField(b)}if(!(c?.dontValidate??!1))await this.validateField(s,"change"),await this.validateArrayFieldsStartingFrom(s,d,"change")},this.swapFieldValues=(s,d,c,g)=>{if(this.setFieldValue(s,(p)=>{let b=p[d],x=p[c];return Gt(Gt(p,`${d}`,x),`${c}`,b)},it(g,{dontValidate:!0})),Bt(this).handleArraySwap(s,d,c),!(g?.dontValidate??!1))this.validateField(s,"change"),this.validateField(`${s}[${d}]`,"change"),this.validateField(`${s}[${c}]`,"change")},this.moveFieldValues=(s,d,c,g)=>{if(this.setFieldValue(s,(p)=>{let b=[...p];return b.splice(c,0,b.splice(d,1)[0]),b},it(g,{dontValidate:!0})),Bt(this).handleArrayMove(s,d,c),!(g?.dontValidate??!1))this.validateField(s,"change"),this.validateField(`${s}[${d}]`,"change"),this.validateField(`${s}[${c}]`,"change")},this.clearFieldValues=(s,d)=>{let c=this.getFieldValue(s),g=Array.isArray(c)?Math.max(c.length-1,0):null;if(this.setFieldValue(s,[],it(d,{dontValidate:!0})),Bt(this).bumpArrayVersion(s),g!==null)for(let p=0;p<=g;p++){let b=`${s}[${p}]`;this.deleteField(b)}if(!(d?.dontValidate??!1))this.validateField(s,"change")},this.resetField=(s)=>{this.baseStore.setState((d)=>{let c=this.getFieldInfo(s).instance?.options.defaultValue,g=Yt(this.options.defaultValues,s),_=c??g;return{...d,fieldMetaBase:{...d.fieldMetaBase,[s]:lt},values:_!==void 0?Gt(d.values,s,_):d.values}})},this.setErrorMap=(s)=>{Ge(()=>{Object.entries(s).forEach(([d,c])=>{let g=d;if(Jt(c)){let{formError:_,fieldErrors:p}=wa(c);for(let b of Object.keys(this.fieldInfo)){if(!this.getFieldMeta(b))continue;this.setFieldMeta(b,(m)=>({...m,errorMap:{...m.errorMap,[g]:p?.[b]},errorSourceMap:{...m.errorSourceMap,[g]:"form"}}))}this.baseStore.setState((b)=>({...b,errorMap:{...b.errorMap,[g]:_}}))}else this.baseStore.setState((_)=>({..._,errorMap:{..._.errorMap,[g]:c}}))})})},this.getAllErrors=()=>({form:{errors:this.state.errors,errorMap:this.state.errorMap},fields:Object.entries(this.state.fieldMeta).reduce((s,[d,c])=>{if(Object.keys(c).length&&c.errors.length)s[d]={errors:c.errors,errorMap:c.errorMap};return s},{})}),this.parseValuesWithSchema=(s)=>Lt.validate({value:this.state.values,validationSource:"form"},s),this.parseValuesWithSchemaAsync=(s)=>Lt.validateAsync({value:this.state.values,validationSource:"form"},s),this.timeoutIds={validations:{},listeners:{},formListeners:{}},this._formId=e?.formId??ra(),this._devtoolsSubmissionOverride=!1;let r=Ka({...e?.defaultState,values:e?.defaultValues??e?.defaultState?.values});if(e?.transform){r=e.transform({state:r}).state;for(let s of Object.keys(r.errorMap)){let d=r.errorMap[s];if(d===void 0||!Jt(d))continue;for(let c of Object.keys(d.fields)){let g=d.fields[c];if(g===void 0)continue;let _=r.fieldMetaBase[c];r.fieldMetaBase[c]={isTouched:!1,isValidating:!1,isBlurred:!1,isDirty:!1,_arrayVersion:0,_pendingValidationsCount:0,..._??{},errorSourceMap:{..._?.errorSourceMap??{},onChange:"form"},errorMap:{..._?.errorMap??{},[s]:g}}}}}this.baseStore=kt(r);let a=void 0;this.fieldMetaDerived=kt((s)=>{let d=this.baseStore.get(),c=0,g={};for(let _ of Object.keys(d.fieldMetaBase)){let p=d.fieldMetaBase[_],b=a?.fieldMetaBase[_],x=s?.[_],m=Yt(d.values,_),i=x?.errors;if(!b||p.errorMap!==b.errorMap){i=Object.values(p.errorMap??{}).filter((J)=>J!==void 0);let z=this.getFieldInfo(_)?.instance;if(!z||!z.options.disableErrorFlat)i=i.flat(1)}let v=!Oa(i),w=!p.isDirty,k=pt(m,this.getFieldInfo(_)?.instance?.options.defaultValue??Yt(this.options.defaultValues,_));if(x&&x.isPristine===w&&x.isValid===v&&x.isDefaultValue===k&&x.errors===i&&p===b){g[_]=x,c++;continue}g[_]={...p,errors:i??[],isPristine:w,isValid:v,isDefaultValue:k}}if(!Object.keys(d.fieldMetaBase).length)return g;if(s&&c===Object.keys(d.fieldMetaBase).length)return s;return a=this.baseStore.get(),g}),this.formGroupMetaDerived=kt((s)=>{let d=this.baseStore.get(),c=this.fieldMetaDerived.get(),g={};for(let _ of this.formGroupApis){let p=_.name,b=d.formGroupStateBase[p]??{isSubmitted:!1,isSubmitting:!1,isValidating:!1,submissionAttempts:0,isSubmitSuccessful:!1},x=c[p],m=!1,i=!0,v=!1,w=!1,k=!0,z=!1;for(let Ee in c){if(Ee===p)continue;if(!_t(p,Ee))continue;let Fe=c[Ee];if(!Fe)continue;if(Fe.isValidating)m=!0;if(!Fe.isValid)i=!1;if(Fe.isTouched)v=!0;if(Fe.isBlurred)w=!0;if(!Fe.isDefaultValue)k=!1;if(Fe.isDirty)z=!0}let J=!z,H=!!m||b.isValidating,ie=x?.errorMap??{},oe=x?.errorSourceMap??{},T=Boolean(ie.onMount||Object.entries(c).some(([Ee,Fe])=>Fe&&Ee!==p&&_t(p,Ee)&&Fe.errorMap.onMount)),P=s?.[p],j=P?.errors??[];if(!P||P.__srcErrorMap!==ie)j=Object.values(ie).reduce((Ee,Fe)=>{if(Fe===void 0)return Ee;if(Fe&&typeof Fe==="object"&&"fields"in Fe){let se=Fe.group;if(se!==void 0)Ee.push(se);return Ee}return Ee.push(Fe),Ee},[]);let X=j.length===0,F=i&&X,Y=_.options.canSubmitWhenInvalid??!1,ye=b.submissionAttempts===0&&!v&&!T||!H&&!b.isSubmitting&&F||Y;if(P&&P.errorMap===ie&&P.errorSourceMap===oe&&P.errors===j&&P.isFieldsValidating===m&&P.isFieldsValid===i&&P.isGroupValid===X&&P.isValid===F&&P.canSubmit===ye&&P.isTouched===v&&P.isBlurred===w&&P.isPristine===J&&P.isDefaultValue===k&&P.isDirty===z&&P.isValidating===H&&P.isSubmitting===b.isSubmitting&&P.isSubmitted===b.isSubmitted&&P.submissionAttempts===b.submissionAttempts&&P.isSubmitSuccessful===b.isSubmitSuccessful){g[p]=P;continue}let me={...b,errorMap:ie,errorSourceMap:oe,_arrayVersion:x?._arrayVersion??0,isTouched:v,isBlurred:w,isDirty:z,isPristine:J,isDefaultValue:k,isValid:F,errors:j,isValidating:H,isFieldsValidating:m,isFieldsValid:i,isGroupValid:X,canSubmit:ye};Object.defineProperty(me,"__srcErrorMap",{value:ie,enumerable:!1,configurable:!0}),g[p]=me}return g});let l=void 0;this.store=kt((s)=>{let d=this.baseStore.get(),c=this.fieldMetaDerived.get(),g=Object.values(c).filter(Boolean),_=g.some((X)=>X.isValidating),p=g.every((X)=>X.isValid),b=g.some((X)=>X.isTouched),x=g.some((X)=>X.isBlurred),m=g.every((X)=>X.isDefaultValue),i=b&&d.errorMap?.onMount,v=g.some((X)=>X.isDirty),w=!v,k=Boolean(d.errorMap?.onMount||g.some((X)=>X?.errorMap?.onMount)),z=!!_,J=s?.errors??[];if(!l||d.errorMap!==l.errorMap)J=Object.values(d.errorMap).reduce((X,F)=>{if(F===void 0)return X;if(F&&Jt(F))return X.push(F.form),X;return X.push(F),X},[]);let H=J.length===0,ie=p&&H,oe=this.options.canSubmitWhenInvalid??!1,T=d.submissionAttempts===0&&!b&&!k||!z&&!d.isSubmitting&&ie||oe,P=d.errorMap;if(i)J=J.filter((X)=>X!==d.errorMap.onMount),P=Object.assign(P,{onMount:void 0});if(s&&l&&s.errorMap===P&&s.fieldMeta===this.fieldMetaDerived.state&&s.errors===J&&s.isFieldsValidating===_&&s.isFieldsValid===p&&s.isFormValid===H&&s.isValid===ie&&s.canSubmit===T&&s.isTouched===b&&s.isBlurred===x&&s.isPristine===w&&s.isDefaultValue===m&&s.isDirty===v&&pt(l,d))return s;let j={...d,errorMap:P,fieldMeta:this.fieldMetaDerived.state,errors:J,isFieldsValidating:_,isFieldsValid:p,isFormValid:H,isValid:ie,canSubmit:T,isTouched:b,isBlurred:x,isPristine:w,isDefaultValue:m,isDirty:v};return l=this.baseStore.get(),j}),this.handleSubmit=this.handleSubmit.bind(this),this.update(e||{})}get state(){return this.store.state}get formId(){return this._formId}runValidator(e){if(ta(e.validate))return Lt[e.type](e.value,e.validate);return e.validate(e.value)}handleSubmit(e){return this._handleSubmit(e)}}function wa(e){if(e){if(Jt(e)){let r=wa(e.form).formError,a=e.fields;return{formError:r,fieldErrors:a}}return{formError:e}}return{formError:void 0}}function oa(e){switch(e){case"submit":return"onSubmit";case"blur":return"onBlur";case"mount":return"onMount";case"server":return"onServer";case"dynamic":return"onDynamic";case"change":default:return"onChange"}}class jt{constructor(e){this.options={},this.mount=()=>{if(this.options.defaultValue!==void 0&&!this.getMeta().isTouched)this.form.setFieldValue(this.name,this.options.defaultValue,{dontUpdateMeta:!0});let r=this.getInfo();r.instance=this,this.update(this.options);let{onMount:a}=this.options.validators||{};if(a){let l=this.runValidator({validate:a,value:{value:this.state.value,fieldApi:this,validationSource:"field"},type:"validate"});if(l)this.setMeta((s)=>({...s,errorMap:{...s?.errorMap,onMount:l},errorSourceMap:{...s?.errorSourceMap,onMount:"field"}}))}return this.options.listeners?.onMount?.({value:this.state.value,fieldApi:this}),()=>{for(let[s,d]of Object.entries(this.timeoutIds.validations))if(d)clearTimeout(d),this.timeoutIds.validations[s]=null;for(let[s,d]of Object.entries(this.timeoutIds.listeners))if(d)clearTimeout(d),this.timeoutIds.listeners[s]=null;for(let[s,d]of Object.entries(this.timeoutIds.formListeners))if(d)clearTimeout(d),this.timeoutIds.formListeners[s]=null;let l=this.form.fieldInfo[this.name];if(!l)return;if(l.instance!==this)return;for(let[s,d]of Object.entries(l.validationMetaMap))d?.lastAbortController.abort(),l.validationMetaMap[s]=void 0;this.form.baseStore.setState((s)=>({...s,fieldMetaBase:{...s.fieldMetaBase,[this.name]:{...lt,isTouched:s.fieldMetaBase[this.name]?.isTouched??lt.isTouched,isBlurred:s.fieldMetaBase[this.name]?.isBlurred??lt.isBlurred,isDirty:s.fieldMetaBase[this.name]?.isDirty??lt.isDirty}}})),l.instance=null,this.options.listeners?.onUnmount?.({value:this.state.value,fieldApi:this}),this.form.options.listeners?.onFieldUnmount?.({formApi:this.form,fieldApi:this})}},this.update=(r)=>{if(this.options=r,this.name=r.name,!this.state.meta.isTouched&&this.options.defaultValue!==void 0){let a=this.form.getFieldValue(this.name);if(!pt(a,r.defaultValue))this.form.setFieldValue(this.name,r.defaultValue,{dontUpdateMeta:!0,dontValidate:!0,dontRunListeners:!0})}if(!this.form.getFieldMeta(this.name))this.form.setFieldMeta(this.name,this.state.meta)},this.getValue=()=>this.form.getFieldValue(this.name),this.setValue=(r,a)=>{if(this.form.setFieldValue(this.name,r,it(a,{dontRunListeners:!0,dontValidate:!0})),!a?.dontRunListeners)this.triggerOnChangeListener();if(!a?.dontValidate)this.validate("change")},this.getMeta=()=>this.store.state.meta,this.setMeta=(r)=>this.form.setFieldMeta(this.name,r),this.getInfo=()=>this.form.getFieldInfo(this.name),this.pushValue=(r,a)=>{if(this.form.pushFieldValue(this.name,r,it(a,{dontRunListeners:!0})),!a?.dontRunListeners)this.triggerOnChangeListener()},this.insertValue=(r,a,l)=>{if(this.form.insertFieldValue(this.name,r,a,it(l,{dontRunListeners:!0})),!l?.dontRunListeners)this.triggerOnChangeListener()},this.replaceValue=(r,a,l)=>{if(this.form.replaceFieldValue(this.name,r,a,it(l,{dontRunListeners:!0})),!l?.dontRunListeners)this.triggerOnChangeListener()},this.removeValue=(r,a)=>{if(this.form.removeFieldValue(this.name,r,it(a,{dontRunListeners:!0})),!a?.dontRunListeners)this.triggerOnChangeListener()},this.swapValues=(r,a,l)=>{if(this.form.swapFieldValues(this.name,r,a,it(l,{dontRunListeners:!0})),!l?.dontRunListeners)this.triggerOnChangeListener()},this.moveValue=(r,a,l)=>{if(this.form.moveFieldValues(this.name,r,a,it(l,{dontRunListeners:!0})),!l?.dontRunListeners)this.triggerOnChangeListener()},this.clearValues=(r)=>{if(this.form.clearFieldValues(this.name,it(r,{dontRunListeners:!0})),!r?.dontRunListeners)this.triggerOnChangeListener()},this.getLinkedFields=(r)=>{let a=Object.values(this.form.fieldInfo),l=[];for(let s of a){if(!s.instance)continue;if(!(s.instance instanceof jt))continue;let{onChangeListenTo:d,onBlurListenTo:c}=s.instance.options.validators||{};if(r==="change"&&d?.includes(this.name))l.push(s.instance);if(r==="blur"&&c?.includes(this.name))l.push(s.instance)}return l},this.validateSync=(r,a)=>{let l=Pt(r,{...this.options,form:this.form,fieldName:this.name,validationLogic:this.form.options.validationLogic||ft}),d=this.getLinkedFields(r).reduce((_,p)=>{let b=Pt(r,{...p.options,form:p.form,fieldName:p.name,validationLogic:p.form.options.validationLogic||ft});return b.forEach((x)=>{x.field=p}),_.concat(b)},[]),c=!1;Ge(()=>{let _=(p,b)=>{let x=la(b.cause),m=b.validate?bs(p.runValidator({validate:b.validate,value:{value:p.store.state.value,validationSource:"field",fieldApi:p},type:"validate"})):void 0,i=a[x],{newErrorValue:v,newSource:w}=Wt({formLevelError:i,fieldLevelError:m});if(p.state.meta.errorMap?.[x]!==v)p.setMeta((k)=>({...k,errorMap:{...k.errorMap,[x]:v},errorSourceMap:{...k.errorSourceMap,[x]:w}}));if(v)c=!0};for(let p of l)_(this,p);for(let p of d){if(!p.validate)continue;_(p.field,p)}});let g=la("submit");if(this.state.meta.errorMap?.[g]&&r!=="submit"&&!c)this.setMeta((_)=>({..._,errorMap:{..._.errorMap,[g]:void 0},errorSourceMap:{..._.errorSourceMap,[g]:void 0}}));return{hasErrored:c}},this.validateAsync=async(r,a)=>{let l=Rt(r,{...this.options,form:this.form,fieldName:this.name,validationLogic:this.form.options.validationLogic||ft}),s=await a,c=this.getLinkedFields(r).reduce((i,v)=>{let w=Rt(r,{...v.options,form:v.form,fieldName:v.name,validationLogic:v.form.options.validationLogic||ft});return w.forEach((k)=>{k.field=v}),i.concat(w)},[]),g=[],_=[],p=l.some((i)=>i.validate),b=Array.from(new Set(c.filter((i)=>i.validate).map((i)=>i.field)));Ge(()=>{if(p)this.startValidation();for(let i of b)i.startValidation()});let x=(i,v,w)=>{let k=la(v.cause),z=i.getInfo();z.validationMetaMap[k]?.lastAbortController.abort();let H=new AbortController;z.validationMetaMap[k]={lastAbortController:H},w.push(new Promise(async(ie)=>{let oe;try{oe=await new Promise((F,Y)=>{if(i.timeoutIds.validations[v.cause])clearTimeout(i.timeoutIds.validations[v.cause]),i.endValidation();i.timeoutIds.validations[v.cause]=setTimeout(async()=>{if(H.signal.aborted)return F(void 0);try{F(await this.runValidator({validate:v.validate,value:{value:i.store.state.value,fieldApi:i,signal:H.signal,validationSource:"field"},type:"validateAsync"}))}catch(ye){Y(ye)}},v.debounceMs)})}catch(F){oe=F}if(H.signal.aborted)return ie(void 0);let T=bs(oe),P=s[i.name]?.[k],{newErrorValue:j,newSource:X}=Wt({formLevelError:P,fieldLevelError:T});if(i.getInfo().instance!==i)return ie(void 0);i.setMeta((F)=>({...F,errorMap:{...F?.errorMap,[k]:j},errorSourceMap:{...F.errorSourceMap,[k]:X}})),ie(j)}))};for(let i of l){if(!i.validate)continue;x(this,i,g)}for(let i of c){if(!i.validate)continue;x(i.field,i,_)}let m=[];if(g.length||_.length)m=await Promise.all(g),await Promise.all(_);return Ge(()=>{if(p)this.endValidation();for(let i of b)i.endValidation()}),m.filter(Boolean)},this.validate=(r,a)=>{if(!this.state.meta.isTouched)return[];let l=a?.skipGroupValidation?[]:Array.from(this.form.formGroupApis).filter((x)=>this.name.startsWith(x.name)),d=((a?.skipFormValidation)?{fieldsErrorMap:{}}:this.form.validateSync(r)).fieldsErrorMap[this.name]??{};if(!a?.skipFormValidation)for(let x of l){if(x.state.meta.submissionAttempts===0)continue;let{fieldsErrorMap:m}=this.form.validateSync(r,{group:x,dontUpdateFormErrorMap:!0,filterFieldNames:(i)=>_t(x.name,i)});d={...d,...m[this.name]??{}}}let{hasErrored:c}=this.validateSync(r,d),g=new WeakMap;for(let x of l){let{hasErrored:m}=x.validateSync(r,{},{skipRelatedFieldValidation:!0});g.set(x,m)}if(c&&!this.options.asyncAlways){this.getInfo().validationMetaMap[la(r)]?.lastAbortController.abort();let x=[];for(let m of l)m.getInfo().validationMetaMap[la(r)]?.lastAbortController.abort(),x.push(m.state.meta.errors);return[...this.state.meta.errors,...x.flat()]}let _=a?.skipFormValidation?Promise.resolve({}):this.form.validateAsync(r),p=this.validateAsync(r,_),b=[];for(let x of l){if(g.get(x)&&!x.options.asyncAlways)continue;b.push(x.validateAsync(r,_,{skipRelatedFieldValidation:!0}))}if(b.length===0)return p;return Promise.all([p,...b]).then((x)=>x.flat())},this.handleChange=(r)=>{this.setValue(r)},this.handleBlur=()=>{if(!this.state.meta.isTouched)this.setMeta((a)=>({...a,isTouched:!0}));if(!this.state.meta.isBlurred)this.setMeta((a)=>({...a,isBlurred:!0}));this.validate("blur"),this.triggerOnBlurListener()},this.setErrorMap=(r)=>{this.setMeta((a)=>({...a,errorMap:{...a.errorMap,...r}}))},this.parseValueWithSchema=(r)=>Lt.validate({value:this.state.value,validationSource:"field"},r),this.parseValueWithSchemaAsync=(r)=>Lt.validateAsync({value:this.state.value,validationSource:"field"},r),this.triggerOnBlurListener=()=>{let r=this.form.options.listeners?.onBlurDebounceMs;if(r&&r>0){if(this.timeoutIds.formListeners.blur)clearTimeout(this.timeoutIds.formListeners.blur);this.timeoutIds.formListeners.blur=setTimeout(()=>{this.form.options.listeners?.onBlur?.({formApi:this.form,fieldApi:this})},r)}else this.form.options.listeners?.onBlur?.({formApi:this.form,fieldApi:this});let a=this.options.listeners?.onBlurDebounceMs;if(a&&a>0){if(this.timeoutIds.listeners.blur)clearTimeout(this.timeoutIds.listeners.blur);this.timeoutIds.listeners.blur=setTimeout(()=>{this.options.listeners?.onBlur?.({value:this.state.value,fieldApi:this})},a)}else this.options.listeners?.onBlur?.({value:this.state.value,fieldApi:this})},this.triggerOnChangeListener=()=>{let r=this.form.options.listeners?.onChangeDebounceMs;if(r&&r>0){if(this.timeoutIds.formListeners.change)clearTimeout(this.timeoutIds.formListeners.change);this.timeoutIds.formListeners.change=setTimeout(()=>{this.form.options.listeners?.onChange?.({formApi:this.form,fieldApi:this})},r)}else this.form.options.listeners?.onChange?.({formApi:this.form,fieldApi:this});let a=this.options.listeners?.onChangeDebounceMs;if(a&&a>0){if(this.timeoutIds.listeners.change)clearTimeout(this.timeoutIds.listeners.change);this.timeoutIds.listeners.change=setTimeout(()=>{this.options.listeners?.onChange?.({value:this.state.value,fieldApi:this})},a)}else this.options.listeners?.onChange?.({value:this.state.value,fieldApi:this});for(let l of this.form.formGroupApis)if(_t(l.name,this.name))l.triggerOnChangeListener()},this.triggerOnSubmitListener=()=>{this.options.listeners?.onSubmit?.({value:this.state.value,fieldApi:this})},this.form=e.form,this.name=e.name,this.options=e,this.timeoutIds={validations:{},listeners:{},formListeners:{}},this.store=kt((r)=>{this.form.store.get();let a=this.form.getFieldMeta(this.name)??{...lt,...e.defaultMeta},l=this.form.getFieldValue(this.name);if(!a.isTouched&&l===void 0&&this.options.defaultValue!==void 0&&!pt(l,this.options.defaultValue))l=this.options.defaultValue;if(r&&r.value===l&&r.meta===a)return r;return{value:l,meta:a}})}get state(){return this.store.state}runValidator(e){if(ta(e.validate))return Lt[e.type](e.value,e.validate);return e.validate(e.value)}startValidation(){this.setMeta((e)=>{let r=e._pendingValidationsCount+1;return{...e,_pendingValidationsCount:r,isValidating:r>0&&!e.isValidating?!0:e.isValidating}})}endValidation(){this.setMeta((e)=>{let r=Math.max(0,e._pendingValidationsCount-1);return{...e,_pendingValidationsCount:r,isValidating:r===0&&e.isValidating?!1:e.isValidating}})}}function bs(e){if(e)return e;return}function la(e){switch(e){case"submit":return"onSubmit";case"blur":return"onBlur";case"mount":return"onMount";case"server":return"onServer";case"dynamic":return"onDynamic";case"change":default:return"onChange"}}function za(e){return{isSubmitted:e.isSubmitted??!1,isSubmitting:e.isSubmitting??!1,isValidating:e.isValidating??!1,submissionAttempts:e.submissionAttempts??0,isSubmitSuccessful:e.isSubmitSuccessful??!1}}function xs(e){return{...lt,...e,errors:[],isPristine:!0,isValid:!0,isDefaultValue:!0,isFieldsValidating:!1,isFieldsValid:!0,isGroupValid:!0,canSubmit:!0,isSubmitting:!1,isSubmitted:!1,isValidating:!1,submissionAttempts:0,isSubmitSuccessful:!1}}class Zt{constructor(e){this.options={},this.setFormGroupState=(r)=>{this.form.baseStore.setState((a)=>{let l=a.formGroupStateBase[this.name]??za({});return{...a,formGroupStateBase:{...a.formGroupStateBase,[this.name]:r(l)}}})},this._lastDistributedFieldNames={},this.update=(r)=>{if(this.options=r,this.name=r.name,!this.state.meta.isTouched&&this.options.defaultValue!==void 0){let a=this.form.getFieldValue(this.name);if(!pt(a,r.defaultValue))this.form.setFieldValue(this.name,r.defaultValue,{dontUpdateMeta:!0,dontValidate:!0,dontRunListeners:!0})}if(!this.form.getFieldMeta(this.name))this.form.setFieldMeta(this.name,{...lt,...this.options.defaultMeta})},this.mount=()=>{this.update(this.options),this.form.formGroupApis.add(this),this.fieldInfo.instance=this,this.form.baseStore.setState((a)=>({...a,formGroupStateBase:{...a.formGroupStateBase,[this.name]:a.formGroupStateBase[this.name]??za({...this.options.defaultState})}}));let{onMount:r}=this.options.validators||{};if(r){let a=this.runValidator({validate:r,value:{value:this.state.value,groupApi:this,validationSource:"form"},type:"validate"}),l=a,s=void 0;if(Ga(a))l=a.group,s=a.fields;let d=Ha(l);if(d)this.setMeta((c)=>({...c,errorMap:{...c.errorMap,onMount:d},errorSourceMap:{...c.errorSourceMap,onMount:"field"}}));this.distributeFieldErrors("onMount",s)}return this.options.listeners?.onMount?.({value:this.state.value,groupApi:this}),()=>{for(let[a,l]of Object.entries(this.timeoutIds.validations))if(l)clearTimeout(l),this.timeoutIds.validations[a]=null;for(let[a,l]of Object.entries(this.timeoutIds.listeners))if(l)clearTimeout(l),this.timeoutIds.listeners[a]=null;for(let[a,l]of Object.entries(this.timeoutIds.formListeners))if(l)clearTimeout(l),this.timeoutIds.formListeners[a]=null;if(this.fieldInfo.instance!==this)return;for(let[a,l]of Object.entries(this.fieldInfo.validationMetaMap))l?.lastAbortController.abort(),this.fieldInfo.validationMetaMap[a]=void 0;this.form.formGroupApis.delete(this),this.form.baseStore.setState((a)=>({...a,formGroupStateBase:{...a.formGroupStateBase,[this.name]:za({})}})),this.fieldInfo.instance=null,this.options.listeners?.onUnmount?.({value:this.state.value,groupApi:this})}},this.setValue=(r,a)=>{if(this.form.setFieldValue(this.name,r,it(a,{dontRunListeners:!0,dontValidate:!0})),!a?.dontRunListeners)this.triggerOnChangeListener();if(!a?.dontValidate)this.validate("change")},this.getMeta=()=>this.store.state.meta,this.setMeta=(r)=>this.form.setFieldMeta(this.name,r),this.getInfo=()=>this.fieldInfo,this.getRelatedFields=()=>{let r=Object.values(this.form.fieldInfo),a=[];for(let l of r){if(!l.instance)continue;if(!(l.instance instanceof jt))continue;if(l.instance.name.startsWith(this.name))a.push(l.instance)}return a},this.getRelatedFieldMetasDerived=()=>{let r=Object.entries(this.form.fieldMetaDerived.state),a=[];for(let[l,s]of r){if(l===this.name)continue;if(_t(this.name,l))a.push({...s,name:l})}return a},this.buildChildFieldName=(r)=>{if(r==="")return this.name;if(r.startsWith("["))return`${this.name}${r}`;return`${this.name}.${r}`},this.distributeFieldErrors=(r,a)=>{let l=this._lastDistributedFieldNames[r]??new Set,s=new Set;if(a)for(let[g,_]of Object.entries(a)){if(_===void 0||_===null||_===!1)continue;s.add(this.buildChildFieldName(g))}let d=new Set([...l,...s]),c=!1;for(let g of d){let _=g.startsWith(this.name+"[")?g.slice(this.name.length):g.slice(this.name.length+1),p=a?.[_],b=this.form.getFieldMeta(g);if(!b&&!p)continue;let x=b?.errorMap[r],m=b?.errorSourceMap[r]==="form",{newErrorValue:i,newSource:v}=ea({newFormValidatorError:p,isPreviousErrorFromFormValidator:m,previousErrorValue:x});if(i)c=!0;if(x===i&&b?.errorSourceMap[r]===v)continue;this.form.setFieldMeta(g,(w=lt)=>({...w,errorMap:{...w.errorMap,[r]:i},errorSourceMap:{...w.errorSourceMap,[r]:v}}))}return this._lastDistributedFieldNames[r]=s,c},this.validateSync=(r,a,l={})=>{let s=Pt(r,{...this.options,form:this.form,group:this,validationLogic:this.options.validationLogic||this.form.options.validationLogic||ft}),c=(l.skipRelatedFieldValidation?[]:this.getRelatedFields()).reduce((p,b)=>{let x=Pt(r,{...b.options,form:b.form,validationLogic:b.form.options.validationLogic||ft});return x.forEach((m)=>{m.field=b}),p.concat(x)},[]),g=!1;Ge(()=>{let p=(b,x)=>{let m=Sa(x.cause),i=b===this,v=void 0;if(x.validate)v=b.runValidator({validate:x.validate,value:{value:b.store.state.value,validationSource:i?"form":"field",...b instanceof Zt?{groupApi:b}:{fieldApi:b}},type:"validate"});let w=v,k=void 0;if(i&&Ga(v))w=v.group,k=v.fields;let z=Ha(w),J=a[m],{newErrorValue:H,newSource:ie}=Wt({formLevelError:J,fieldLevelError:z});if(b.state.meta.errorMap?.[m]!==H)b.setMeta((oe)=>({...oe,errorMap:{...oe.errorMap,[m]:H},errorSourceMap:{...oe.errorSourceMap,[m]:ie}}));if(H)g=!0;if(i){if(this.distributeFieldErrors(m,k))g=!0}};for(let b of s)p(this,b);for(let b of c){if(!b.validate)continue;p(b.field,b)}});let _=Sa("submit");if(this.state.meta.errorMap?.[_]&&r!=="submit"&&!g)this.setMeta((p)=>({...p,errorMap:{...p.errorMap,[_]:void 0},errorSourceMap:{...p.errorSourceMap,[_]:void 0}}));return{hasErrored:g}},this.validateAsync=async(r,a,l={})=>{let s=Rt(r,{...this.options,form:this.form,group:this,validationLogic:this.options.validationLogic||this.form.options.validationLogic||ft}),d=await a,c=l.skipRelatedFieldValidation?[]:this.getRelatedFields(),g=c.reduce((i,v)=>{let w=Rt(r,{...v.options,form:v.form,validationLogic:v.form.options.validationLogic||ft});return w.forEach((k)=>{k.field=v}),i.concat(w)},[]),_=[],p=[],b=s.some((i)=>i.validate)||g.some((i)=>i.validate);if(b){if(!this.state.meta.isValidating)this.setMeta((i)=>({...i,isValidating:!0}));for(let i of c)i.setMeta((v)=>({...v,isValidating:!0}))}let x=(i,v,w)=>{let k=Sa(v.cause),z=i.getInfo();z.validationMetaMap[k]?.lastAbortController.abort();let H=new AbortController;z.validationMetaMap[k]={lastAbortController:H};let ie=i===this;w.push(new Promise(async(oe)=>{let T;try{T=await new Promise((me,Ee)=>{if(i.timeoutIds.validations[v.cause])clearTimeout(i.timeoutIds.validations[v.cause]);i.timeoutIds.validations[v.cause]=setTimeout(async()=>{if(H.signal.aborted)return me(void 0);try{me(await this.runValidator({validate:v.validate,value:{value:i.store.state.value,signal:H.signal,validationSource:ie?"form":"field",...i instanceof Zt?{groupApi:i}:{fieldApi:i}},type:"validateAsync"}))}catch(Fe){Ee(Fe)}},v.debounceMs)})}catch(me){T=me}if(H.signal.aborted)return oe(void 0);let P=T,j=void 0;if(ie&&Ga(T))P=T.group,j=T.fields;let X=Ha(P),F=d[i.name]?.[k],{newErrorValue:Y,newSource:ye}=Wt({formLevelError:F,fieldLevelError:X});if(i.getInfo().instance!==i)return oe(void 0);if(i.setMeta((me)=>({...me,errorMap:{...me?.errorMap,[k]:Y},errorSourceMap:{...me.errorSourceMap,[k]:ye}})),ie)this.distributeFieldErrors(k,j);oe(Y)}))};for(let i of s){if(!i.validate)continue;x(this,i,_)}for(let i of g){if(!i.validate)continue;x(i.field,i,p)}let m=[];if(_.length||p.length)m=await Promise.all(_),await Promise.all(p);if(b){this.setMeta((i)=>({...i,isValidating:!1}));for(let i of c)i.setMeta((v)=>({...v,isValidating:!1}))}return m.filter(Boolean)},this.validateAllFields=async(r)=>{let a=[];return Ge(()=>{Object.values(this.getRelatedFields()).forEach((s)=>{if(a.push(Promise.resolve().then(()=>s.validate(r,{skipFormValidation:!0,skipGroupValidation:!0}))),!s.store.state.meta.isTouched)s.setMeta((d)=>({...d,isTouched:!0}))})}),(await Promise.all(a)).flat()},this.validateArrayFieldsStartingFrom=(r,a,l)=>this.form.validateArrayFieldsStartingFrom(r,a,l),this.validateField=(r,a)=>this.form.validateField(r,a),this.getFieldValue=(r)=>this.form.getFieldValue(r),this.getFieldMeta=(r)=>this.form.getFieldMeta(r),this.setFieldMeta=(r,a)=>this.form.setFieldMeta(r,a),this.setFieldValue=(r,a)=>this.form.setFieldValue(r,a),this.deleteField=(r)=>this.form.deleteField(r),this.pushFieldValue=(r,a)=>this.form.pushFieldValue(r,a),this.insertFieldValue=(r,a,l)=>this.form.insertFieldValue(r,a,l),this.replaceFieldValue=(r,a,l)=>this.form.replaceFieldValue(r,a,l),this.swapFieldValues=(r,a,l)=>this.form.swapFieldValues(r,a,l),this.moveFieldValues=(r,a,l)=>this.form.moveFieldValues(r,a,l),this.clearFieldValues=(r)=>this.form.clearFieldValues(r),this.resetField=(r)=>this.form.resetField(r),this.removeFieldValue=(r,a)=>this.form.removeFieldValue(r,a),this.areRelatedFieldsValid=()=>Object.values(this.getRelatedFields()).every((r)=>r.state.meta.isValid),this.validate=(r,a)=>{let{fieldsErrorMap:l}=a?.skipFormValidation?{fieldsErrorMap:{}}:this.form.validateSync(r,{dontUpdateFormErrorMap:!0,filterFieldNames:(c)=>_t(this.name,c)}),{hasErrored:s}=this.validateSync(r,l[this.name]??{},{skipRelatedFieldValidation:a?.skipRelatedFieldValidation});if(s&&!this.options.asyncAlways)return this.getInfo().validationMetaMap[Sa(r)]?.lastAbortController.abort(),this.state.meta.errors;let d=a?.skipFormValidation?Promise.resolve({}):this.form.validateAsync(r,{dontUpdateFormErrorMap:!0,filterFieldNames:(c)=>_t(this.name,c)});return this.validateAsync(r,d,{skipRelatedFieldValidation:a?.skipRelatedFieldValidation})},this.triggerOnChangeListener=()=>{let r=this.form.options.listeners?.onChangeGroupDebounceMs;if(r&&r>0){if(this.timeoutIds.formListeners.change)clearTimeout(this.timeoutIds.formListeners.change);this.timeoutIds.formListeners.change=setTimeout(()=>{this.form.options.listeners?.onChangeGroup?.({formApi:this.form,groupApi:this})},r)}else this.form.options.listeners?.onChangeGroup?.({formApi:this.form,groupApi:this});let a=this.options.listeners?.onChangeDebounceMs;if(a&&a>0){if(this.timeoutIds.listeners.change)clearTimeout(this.timeoutIds.listeners.change);this.timeoutIds.listeners.change=setTimeout(()=>{this.options.listeners?.onChange?.({value:this.state.value,groupApi:this})},a)}else this.options.listeners?.onChange?.({value:this.state.value,groupApi:this})},this.triggerOnSubmitListener=()=>{this.options.listeners?.onSubmit?.({value:this.state.value,groupApi:this})},this._handleSubmit=async(r)=>{this.setFormGroupState((s)=>({...s,isSubmitted:!1,submissionAttempts:s.submissionAttempts+1,isSubmitSuccessful:!1})),Ge(()=>{Object.values(this.getRelatedFields()).forEach((s)=>{if(!s.state.meta.isTouched)s.setMeta((d)=>({...d,isTouched:!0}))})});let a=r??this.options.onSubmitMeta;this.setFormGroupState((s)=>({...s,isSubmitting:!0}));let l=()=>{this.setFormGroupState((s)=>({...s,isSubmitting:!1}))};if(await this.validateAllFields("submit"),!this.areRelatedFieldsValid()){l(),this.options.onGroupSubmitInvalid?.({value:this.state.value,groupApi:this,meta:a});return}if(await this.validate("submit",{skipRelatedFieldValidation:!0}),!this.areRelatedFieldsValid()||!this.state.meta.isValid){l(),this.options.onGroupSubmitInvalid?.({value:this.state.value,groupApi:this,meta:a});return}Ge(()=>{Object.values(this.getRelatedFields()).forEach((s)=>{s.options.listeners?.onGroupSubmit?.({value:s.state.value,fieldApi:s})})}),this.options.listeners?.onSubmit?.({groupApi:this,value:this.state.value});try{await this.options.onGroupSubmit?.({value:this.state.value,groupApi:this,meta:a}),Ge(()=>{this.setFormGroupState((s)=>({...s,isSubmitted:!0,isSubmitSuccessful:!0})),l()})}catch(s){throw this.setFormGroupState((d)=>({...d,isSubmitSuccessful:!1})),l(),s}},this.form=e.form,this.name=e.name,this.options=e,this.timeoutIds={validations:{},listeners:{},formListeners:{}},this.fieldInfo={instance:null,validationMetaMap:{onChange:void 0,onBlur:void 0,onSubmit:void 0,onMount:void 0,onServer:void 0,onDynamic:void 0}},this.store=kt((r)=>{this.form.formGroupMetaDerived.get(),this.form.baseStore.get();let a=this.form.getFormGroupMeta(this.name)??xs(e.defaultMeta),l=this.form.getFieldValue(this.name);if(!a.isTouched&&l===void 0&&this.options.defaultValue!==void 0&&!pt(l,this.options.defaultValue))l=this.options.defaultValue;if(r&&r.value===l&&r.meta===a)return r;return{value:l,meta:a}}),this.handleSubmit=this.handleSubmit.bind(this)}get state(){return this.store.state}runValidator(e){if(ta(e.validate)){let r=Lt[e.type](e.value,e.validate);if(e.type==="validate")return ys(r);return r.then(ys)}return e.validate(e.value)}handleSubmit(e){return this._handleSubmit(e)}}function Ha(e){if(e)return e;return}function Ga(e){return!!e&&typeof e==="object"&&"fields"in e}function ys(e){if(!e||typeof e!=="object")return e;if(!("form"in e)&&!("fields"in e))return e;let{form:r,fields:a,...l}=e;return{...l,group:r,fields:a}}function Sa(e){switch(e){case"submit":return"onSubmit";case"blur":return"onBlur";case"mount":return"onMount";case"server":return"onServer";case"dynamic":return"onDynamic";case"change":default:return"onChange"}}function Wa(e,r){if(!r)return;let a=Object.assign({},e,{state:Ht(e.state)});if(r(a),a.fieldInfo!==e.fieldInfo)e.fieldInfo=a.fieldInfo;if(a.options!==e.options)e.options=a.options;let s=Object.keys({values:null,validationMetaMap:null,fieldMetaBase:null,formGroupStateBase:null,isSubmitting:null,isSubmitted:null,isValidating:null,submissionAttempts:null,isSubmitSuccessful:null,_force_re_eval:null}).reduce((d,c)=>{if(e.state[c]!==a.state[c])d[c]=a.state[c];return d},{});return Ge(()=>{if(Object.keys(s).length)e.baseStore.setState((d)=>({...d,...s}));if(a.state.errorMap!==e.state.errorMap)e.setErrorMap(a.state.errorMap)}),a}S();function Ir(e,r){return e===r}function Re(e,r=(l)=>l,a){let l=a?.compare??Ir,s=D((c)=>{let{unsubscribe:g}=e.subscribe(c);return g},[e]),d=D(()=>e.get(),[e]);return Rc(s,d,d,r,l)}var da=(e,r=(l)=>l,a)=>Re(e,r,{compare:a});S();S();S();var wt=typeof window<"u"?$e:h;function Tr(e){let[r,a]=u(()=>({form:e.form,name:e.name})),[l,s]=u(()=>new jt({...e})),d=l;if(r.form!==e.form||r.name!==e.name)d=new jt({...e}),s(d),a({form:e.form,name:e.name});let c=Re(d.store,e.mode==="array"?(v)=>v.meta._arrayVersion||0:(v)=>v.value),g=Re(d.store,(v)=>v.meta.isTouched),_=Re(d.store,(v)=>v.meta.isBlurred),p=Re(d.store,(v)=>v.meta.isDirty),b=Re(d.store,(v)=>v.meta.errorMap),x=Re(d.store,(v)=>v.meta.errorSourceMap),m=Re(d.store,(v)=>v.meta.isValidating),i=N(()=>({...d,get state(){return{value:e.mode==="array"?d.state.value:c,get meta(){return{...d.state.meta,isTouched:g,isBlurred:_,isDirty:p,errorMap:b,errorSourceMap:x,isValidating:m}}}}}),[d,e.mode,c,g,_,p,b,x,m]);return wt(d.mount,[d]),wt(()=>{d.update(e)}),i}var _s=({children:e,...r})=>{let a=Tr(r),l=N(()=>Ft(e,a),[e,a]);return t(L,{children:l})};S();S();function ws(){return u(()=>ra())[0]}var Er=V,Ns=Ds.split(".")[0]==="17"?ws:Er.useId;S();function Vr(e){let[r,a]=u(()=>({form:e.form,name:e.name})),[l,s]=u(()=>new Zt({...e}));if(r.form!==e.form||r.name!==e.name)s(new Zt({...e})),a({form:e.form,name:e.name});let d=Re(l.store,(T)=>T.value),c=Re(l.store,(T)=>T.meta.isTouched),g=Re(l.store,(T)=>T.meta.isBlurred),_=Re(l.store,(T)=>T.meta.isDirty),p=Re(l.store,(T)=>T.meta.errorMap),b=Re(l.store,(T)=>T.meta.errorSourceMap),x=Re(l.store,(T)=>T.meta.isValidating),m=Re(l.store,(T)=>T.meta.isSubmitting),i=Re(l.store,(T)=>T.meta.isSubmitted),v=Re(l.store,(T)=>T.meta.submissionAttempts),w=Re(l.store,(T)=>T.meta.isSubmitSuccessful),k=Re(l.store,(T)=>T.meta.canSubmit),z=Re(l.store,(T)=>T.meta.isValid),J=Re(l.store,(T)=>T.meta.isFieldsValid),H=Re(l.store,(T)=>T.meta.isFieldsValidating),ie=Re(l.store,(T)=>T.meta.isGroupValid),oe=N(()=>({...l,handleSubmit:(...j)=>l._handleSubmit(...j),get state(){return{...l.state,value:d,get meta(){return{...l.state.meta,isTouched:c,isBlurred:g,isDirty:_,errorMap:p,errorSourceMap:b,isValidating:x,isSubmitting:m,isSubmitted:i,submissionAttempts:v,isSubmitSuccessful:w,canSubmit:k,isValid:z,isFieldsValid:J,isFieldsValidating:H,isGroupValid:ie}}}}}),[l,d,c,g,_,p,b,x,m,i,v,w,k,z,J,H,ie]);return wt(l.mount,[l]),wt(()=>{l.update(e)}),oe}var Ss=({children:e,...r})=>{let a=Vr(r),l=N(()=>Ft(e,a),[e,a]);return t(L,{children:l})};function Lr({form:e,selector:r=(l)=>l,children:a}){let l=Re(e.store,r);return t(L,{children:Ft(a,l)})}function $t(e){let r=Ns(),[a,l]=u(e?.formId),[s,d]=u(()=>new na({...e,formId:e?.formId??r}));if(a!==e?.formId){let _=e?.formId??r;d(new na({...e,formId:_})),l(_)}let c=N(()=>{let _={...s,handleSubmit:(...p)=>s._handleSubmit(...p),get formId(){return s._formId},get state(){return s.store.state}};return _.Field=function(b){return t(_s,{...b,form:s})},_.FormGroup=function(b){return t(Ss,{...b,form:s})},_.Subscribe=function(b){return t(Lr,{form:s,selector:b.selector,children:b.children})},_},[s]);wt(s.mount,[]),wt(()=>{s.update(e)});let g=y(!1);return wt(()=>{if(!g.current)return;if(!e?.transform)return;Wa(s,e.transform)},[s,e?.transform]),wt(()=>{g.current=!0}),c}S();var Pr=R({name:f().min(1,Fx()),type:Ve(["chat","autofill","embedding"]),permission:Ve(["owner","editor","reviewer"]),avatar:f().optional(),providerId:f().optional(),modelId:f().optional(),soul:f().optional(),thinkingLevel:nu.optional(),systemPrompt:f().optional(),skills:te(f()).optional(),mcpServerIds:te(f()).optional(),deniedTools:te(f()).optional()}),Rr=[{id:"bash",name:()=>y0(),description:()=>_0()},{id:"read_skill",name:()=>k0(),description:()=>M0()},{id:"read_asset",name:()=>zm(),description:()=>T0()},{id:"list_assets",name:()=>Bm(),description:()=>C0()},{id:"create_folder",name:()=>Dm(),description:()=>v0()},{id:"create_file",name:()=>Nm(),description:()=>b0()},{id:"create_version",name:()=>Om(),description:()=>w0()},{id:"generate_image",name:()=>Lm(),description:()=>S0()},{id:"generate_video",name:()=>Zm(),description:()=>E0()},{id:"rename_asset",name:()=>jm(),description:()=>R0()},{id:"move_assets",name:()=>Um(),description:()=>I0()},{id:"delete_asset",name:()=>Fm(),description:()=>x0()}];function ks({isOpen:e,onClose:r,teamId:a,type:l,initialValues:s,title:d}){let c=Q(),{canAdmin:g}=Dt(),{data:_}=Z({queryKey:["teams",a,"providers"],queryFn:async()=>{let G=await A.api.teams[":teamId"].providers.$get({param:{teamId:a}});if(!G.ok)throw Error("Failed to fetch providers");return await G.json()},enabled:e}),{data:p}=Z({queryKey:["teams",a,"skills"],queryFn:async()=>{let G=await A.api.teams[":teamId"].skills.$get({param:{teamId:a}});if(!G.ok)throw Error("Failed to fetch skills");return await G.json()},enabled:e}),b=p?.skills||[],{data:x}=Z({queryKey:["teams",a,"mcp","servers"],queryFn:async()=>{let G=await A.api.teams[":teamId"].mcp.servers.$get({param:{teamId:a}});if(!G.ok)throw Error("Failed to fetch MCP servers");return await G.json()},enabled:e}),m=x?.servers||[],i=N(()=>Pr.superRefine((G,ee)=>{if(G.type==="chat"||G.type==="autofill"){if(!G.providerId)ee.addIssue({code:ro.custom,message:kE(),path:["providerId"]});if(!G.modelId)ee.addIssue({code:ro.custom,message:Ex(),path:["modelId"]})}}),[]),v=$t({defaultValues:{name:s?.name||"",type:s?.type||l||"chat",permission:s?.permission||"reviewer",avatar:s?.avatarPreset||s?.avatar||ru[0].id,providerId:s?.providerId||"",modelId:s?.modelId||"",soul:s?.soul||"",thinkingLevel:s?.thinkingLevel||"off",systemPrompt:s?.systemPrompt||"",skills:s?.skills?.map((G)=>G.skillId)||[],mcpServerIds:s?.mcpServerIds||[],deniedTools:s?.deniedTools??[...CA]},validators:{onChange:i},onSubmit:async({value:G})=>{try{if(s?.id)await Fe.mutateAsync({id:s.id,values:G});else await Ee.mutateAsync(G)}catch{}}}),w=da(v.store,(G)=>G.values.providerId),{data:k,isLoading:z}=Z({queryKey:["teams",a,"providers",w,"models"],queryFn:async()=>{let G=await A.api.providers[":id"].models.$get({param:{id:w}});if(!G.ok)throw Error("Failed to fetch models");return await G.json()},enabled:!!w&&e}),[J,H]=u(""),[ie,oe]=u(!1),T=N(()=>{if(!_)return[];return[..._].sort((G,ee)=>G.name.toLowerCase().localeCompare(ee.name.toLowerCase()))},[_]),P=N(()=>{if(!J.trim())return T;let G=J.toLowerCase();return T.filter((ee)=>ee.name.toLowerCase().includes(G))},[T,J]),[j,X]=u(""),[F,Y]=u(!1),ye=N(()=>{if(!k)return[];return[...k].sort((G,ee)=>{let xe=(G.name||G.modelId).toLowerCase(),de=(ee.name||ee.modelId).toLowerCase();return xe.localeCompare(de)})},[k]),me=N(()=>{if(!j.trim())return ye;let G=j.toLowerCase();return ye.filter((ee)=>ee.modelId.toLowerCase().includes(G)||ee.name&&ee.name.toLowerCase().includes(G))},[ye,j]),Ee=B({mutationFn:async(G)=>{let ee=await A.api.teams[":teamId"].agents.$post({param:{teamId:a},json:G});if(!ee.ok)throw Error("Failed to create agent");return await ee.json()},onSuccess:()=>{r(),c.invalidateQueries({queryKey:["agents",a]}),M.success(l0())},onError:(G)=>{M.error(zs({message:G.message}))}}),Fe=B({mutationFn:async({id:G,values:ee})=>{let xe=await A.api.agents[":agentId"].$put({param:{agentId:G},json:ee});if(!xe.ok)throw Error("Failed to update agent");return await xe.json()},onSuccess:()=>{r(),c.invalidateQueries({queryKey:["agents",a]}),M.success(Gm())},onError:(G)=>{M.error(zs({message:G.message}))}});h(()=>{if(e)v.reset(),H(""),oe(!1),X(""),Y(!1)},[e,s,l]);let se=da(v.store,(G)=>G.values.type),ke=se==="chat"||se==="autofill",je=se==="chat",He=(G)=>G.map((ee)=>{if(typeof ee==="string")return{message:ee};if(ee&&typeof ee==="object"&&"message"in ee)return{message:String(ee.message)};return{message:String(ee||"")}});return t(ue,{open:e,onOpenChange:r,children:o(ae,{className:"sm:max-w-3xl h-[90vh] flex flex-col p-0 overflow-hidden",children:[o(fe,{className:"p-6 pb-2 flex-shrink-0",children:[t(le,{children:d}),t(It,{children:K_()})]}),o("form",{onSubmit:(G)=>{G.preventDefault(),G.stopPropagation(),v.handleSubmit()},className:"flex-1 flex flex-col min-h-0 overflow-hidden",children:[t(ce,{className:"flex-1 min-h-0",children:o("div",{className:"p-6 pt-2 space-y-6",children:[o("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[t(v.Field,{name:"name",children:(G)=>{let ee=!!G.state.meta.errors.length&&G.state.meta.isTouched;return o(Oe,{"data-invalid":ee,children:[t(Qe,{children:d0()}),t(q,{value:G.state.value,onBlur:G.handleBlur,onChange:(xe)=>G.handleChange(xe.target.value),placeholder:f0(),"aria-invalid":ee}),ee&&t(We,{errors:He(G.state.meta.errors)})]})}}),t(v.Field,{name:"type",children:(G)=>o(Oe,{children:[t(Qe,{children:D0()}),o(Le,{value:G.state.value,onValueChange:(ee)=>G.handleChange(ee),disabled:!0,children:[t(Be,{className:"bg-muted/50",children:t(Ze,{})}),o(Ue,{children:[t(ne,{value:"chat",children:Hm()}),t(ne,{value:"autofill",children:qm()}),t(ne,{value:"embedding",children:$m()})]})]})]})}),je&&t(v.Field,{name:"permission",children:(G)=>o(Oe,{children:[t(Qe,{children:Dp()}),o(Le,{value:G.state.value||"reviewer",onValueChange:(ee)=>G.handleChange(ee),disabled:!g,children:[t(Be,{children:t(Ze,{})}),o(Ue,{children:[t(ne,{value:"reviewer",children:Fa()}),t(ne,{value:"editor",children:La()}),t(ne,{value:"owner",children:Za()})]})]})]})}),t(v.Field,{name:"avatar",children:(G)=>o(Oe,{className:"md:col-span-2",children:[t(Qe,{children:a0()}),o("div",{className:"flex flex-wrap gap-4 mt-2",children:[ru.map((ee)=>{let xe=G.state.value===ee.id;return t("button",{type:"button",onClick:()=>G.handleChange(ee.id),className:C("relative w-14 h-14 rounded-full overflow-hidden border-2 transition-all hover:scale-105",xe?"border-primary ring-2 ring-primary ring-offset-2":"border-border hover:border-muted-foreground"),children:t("img",{src:ee.preview,className:"w-full h-full object-cover",alt:uE()})},ee.id)}),G.state.value&&!ru.some((ee)=>ee.id===G.state.value)&&t("button",{type:"button",className:"relative w-14 h-14 rounded-full overflow-hidden border-2 border-primary ring-2 ring-primary ring-offset-2 scale-105",children:t("img",{src:G.state.value,className:"w-full h-full object-cover",alt:Iy()})})]})]})})]}),ke&&o(L,{children:[o("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6 p-4 bg-muted/50 rounded-xl border border-border",children:[t(v.Field,{name:"providerId",children:(G)=>{let ee=!!G.state.meta.errors.length&&G.state.meta.isTouched,xe=_?.find((de)=>de.id===G.state.value);return o(Oe,{"data-invalid":ee,children:[t(Qe,{children:IE()}),o(ht,{open:ie,onOpenChange:(de)=>{if(oe(de),!de)H("")},modal:!0,children:[t(gt,{asChild:!0,children:o(E,{type:"button",variant:"outline",role:"combobox","aria-expanded":ie,"aria-invalid":ee,className:C("w-full justify-between font-normal h-10 px-3 bg-background border-border hover:bg-accent/50",ee&&"border-destructive ring-destructive"),children:[t("span",{className:"truncate",children:xe?t("span",{className:"font-medium text-foreground truncate",children:xe.name}):t("span",{className:"text-muted-foreground",children:nI()})}),t(ve,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),o(At,{className:"w-[--radix-popover-trigger-width] min-w-[320px] max-h-[360px] p-0 flex flex-col overflow-hidden",align:"start",side:"bottom",sideOffset:4,onWheel:(de)=>de.stopPropagation(),children:[o("div",{className:"relative p-2 pb-1.5 border-b border-border shrink-0",children:[t(Ut,{className:"absolute left-4.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-muted-foreground"}),t(q,{placeholder:Xg(),value:J,onChange:(de)=>H(de.target.value),className:"pl-8 h-8 text-xs bg-muted/40",autoFocus:!0})]}),t(ce,{className:"w-full p-1",style:{height:P.length===0?"96px":`${Math.min(P.length*38+8,256)}px`},onWheel:(de)=>de.stopPropagation(),children:P.length===0?t("div",{className:"flex items-center justify-center h-full py-6 text-xs text-muted-foreground",children:cS()}):t("div",{className:"space-y-0.5 pr-2",children:P.map((de)=>{let Ke=G.state.value===de.id;return o("div",{onClick:()=>{G.handleChange(de.id),v.setFieldValue("modelId",""),X(""),oe(!1),H("")},className:C("flex items-center justify-between px-2.5 py-2 rounded-md text-xs cursor-pointer transition-colors",Ke?"bg-accent text-accent-foreground font-medium":"hover:bg-muted/60 text-foreground"),children:[t("span",{className:"truncate flex-1 pr-2",children:de.name}),Ke&&t(Pe,{className:"w-4 h-4 text-primary shrink-0"})]},de.id)})})})]})]}),ee&&t(We,{errors:He(G.state.meta.errors)})]})}}),t(v.Field,{name:"modelId",children:(G)=>{let ee=!!G.state.meta.errors.length&&G.state.meta.isTouched,xe=k?.find((de)=>de.id===G.state.value);return o(Oe,{"data-invalid":ee,children:[o(Qe,{className:"flex items-center gap-2",children:[bx(),z&&t(O,{className:"w-3 h-3 animate-spin"})]}),o(ht,{open:F,onOpenChange:(de)=>{if(Y(de),!de)X("")},modal:!0,children:[t(gt,{asChild:!0,children:o(E,{type:"button",variant:"outline",role:"combobox","aria-expanded":F,"aria-invalid":ee,disabled:!w||z,className:C("w-full justify-between font-normal h-10 px-3 bg-background border-border hover:bg-accent/50",ee&&"border-destructive ring-destructive"),children:[t("span",{className:"truncate flex items-center gap-2",children:xe?o(L,{children:[t("span",{className:"truncate font-medium text-foreground",children:xe.name||xe.modelId}),xe.name&&xe.name!==xe.modelId&&t(be,{variant:"secondary",className:"font-mono text-[10px] px-1.5 py-0 shrink-0",children:xe.modelId})]}):t("span",{className:"text-muted-foreground",children:XC()})}),t(ve,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),o(At,{className:"w-[--radix-popover-trigger-width] min-w-[320px] max-h-[360px] p-0 flex flex-col overflow-hidden",align:"start",side:"bottom",sideOffset:4,onWheel:(de)=>de.stopPropagation(),children:[o("div",{className:"relative p-2 pb-1.5 border-b border-border shrink-0",children:[t(Ut,{className:"absolute left-4.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-muted-foreground"}),t(q,{placeholder:Rp(),value:j,onChange:(de)=>X(de.target.value),className:"pl-8 h-8 text-xs bg-muted/40",autoFocus:!0})]}),t(ce,{className:"w-full p-1",style:{height:me.length===0?"96px":`${Math.min(me.length*38+8,256)}px`},onWheel:(de)=>de.stopPropagation(),children:me.length===0?t("div",{className:"flex items-center justify-center h-full py-6 text-xs text-muted-foreground",children:Cd()}):t("div",{className:"space-y-0.5 pr-2",children:me.map((de)=>{let Ke=G.state.value===de.id;return o("div",{onClick:()=>{G.handleChange(de.id),Y(!1),X("")},className:C("flex items-center justify-between px-2.5 py-2 rounded-md text-xs cursor-pointer transition-colors",Ke?"bg-accent text-accent-foreground font-medium":"hover:bg-muted/60 text-foreground"),children:[t("div",{className:"min-w-0 flex-1 pr-2",children:o("div",{className:"flex items-center gap-2",children:[t("span",{className:"truncate",children:de.name||de.modelId}),de.name&&de.name!==de.modelId&&o("span",{className:"font-mono text-[10px] text-muted-foreground truncate",children:["(",de.modelId,")"]}),de.config?.reasoning&&t(be,{variant:"outline",className:"text-[9px] px-1 py-0 h-4 gap-0.5 bg-primary/10 text-primary border-primary/20 shrink-0",children:t(qt,{className:"w-2.5 h-2.5"})})]})}),Ke&&t(Pe,{className:"w-4 h-4 text-primary shrink-0"})]},de.id)})})})]})]}),ee&&t(We,{errors:He(G.state.meta.errors)})]})}}),t("div",{className:"md:col-span-2",children:t(v.Field,{name:"thinkingLevel",children:(G)=>{let ee={off:PT(),low:OT(),medium:FT(),high:NT()};return o(Oe,{children:[t(Qe,{children:DT()}),o(Le,{value:G.state.value,onValueChange:(xe)=>G.handleChange(xe),children:[t(Be,{children:t(Ze,{})}),t(Ue,{children:nu.options.map((xe)=>t(ne,{value:xe,children:ee[xe]||xe},xe))})]})]})}})})]}),t(v.Field,{name:"soul",children:(G)=>o(Oe,{children:[t(Qe,{children:g0()}),t(wi,{value:G.state.value,onBlur:G.handleBlur,onChange:(ee)=>G.handleChange(ee.target.value),placeholder:A0(),className:"min-h-[120px]"})]})}),o("div",{className:"space-y-4",children:[o(W,{className:"text-base font-bold flex items-center gap-2",children:[t(Nt,{className:"w-5 h-5 text-primary"}),lA()]}),t("div",{className:"space-y-2",children:t(v.Field,{name:"skills",children:(G)=>o(L,{children:[b.map((ee)=>{let xe=G.state.value?.includes(ee.id)||!1;return o("div",{className:"flex items-center justify-between p-3 bg-muted/30 border border-border rounded-lg",children:[o("div",{className:"flex items-center gap-3",children:[t(Nt,{className:"w-4 h-4 text-muted-foreground"}),o("div",{className:"flex flex-col",children:[t("span",{className:"text-sm font-medium",children:ee.name}),ee.description&&t("span",{className:"text-[10px] text-muted-foreground line-clamp-1",children:ee.description})]})]}),o("div",{className:"flex items-center gap-2",children:[t("span",{className:"text-xs text-muted-foreground",children:xe?Bf():Lf()}),t(Me,{checked:xe,onCheckedChange:(de)=>{if(de)G.handleChange([...G.state.value||[],ee.id]);else G.handleChange((G.state.value||[]).filter((Ke)=>Ke!==ee.id))}})]})]},ee.id)}),b.length===0&&t("div",{className:"text-center py-8 border-2 border-dashed border-border rounded-xl",children:t("p",{className:"text-sm text-muted-foreground",children:pS()})})]})})})]}),o("div",{className:"space-y-4 border-t border-border pt-6",children:[o(W,{className:"text-base font-bold flex items-center gap-2",children:[t(vn,{className:"w-5 h-5 text-primary"}),Hc()]}),t("div",{className:"space-y-2",children:t(v.Field,{name:"mcpServerIds",children:(G)=>o(L,{children:[m.map((ee)=>{let xe=G.state.value?.includes(ee.id)||!1,de=ee.status==="needs_auth"||!ee.hasCredential&&ee.authType==="oauth";return o("div",{className:"flex items-center justify-between p-3 bg-muted/30 border border-border rounded-lg",children:[o("div",{className:"flex items-center gap-3",children:[t(vn,{className:"w-4 h-4 text-muted-foreground"}),o("div",{className:"flex flex-col",children:[o("div",{className:"flex items-center gap-2",children:[t("span",{className:"text-sm font-medium",children:ee.name}),o(be,{variant:"outline",className:"text-[10px]",children:[ee.toolCount??0," tools"]}),de&&t(be,{variant:"secondary",className:"text-[10px] bg-amber-500/10 text-amber-600 border-amber-500/20",children:Yh()})]}),t("span",{className:"text-[10px] font-mono text-muted-foreground line-clamp-1",children:ee.url})]})]}),o("div",{className:"flex items-center gap-2",children:[t("span",{className:"text-xs text-muted-foreground",children:xe?Bf():Lf()}),t(Me,{checked:xe,onCheckedChange:(Ke)=>{if(Ke)G.handleChange([...G.state.value||[],ee.id]);else G.handleChange((G.state.value||[]).filter((bt)=>bt!==ee.id))}})]})]},ee.id)}),m.length===0&&t("div",{className:"text-center py-6 border-2 border-dashed border-border rounded-xl",children:t("p",{className:"text-xs text-muted-foreground",children:pg()})})]})})})]}),o("div",{className:"space-y-4 border-t border-border pt-6",children:[o(W,{className:"text-base font-bold flex items-center gap-2",children:[t(To,{className:"w-5 h-5 text-primary"}),P0()]}),t("p",{className:"text-xs text-muted-foreground",children:N0()}),t("div",{className:"space-y-2",children:t(v.Field,{name:"deniedTools",children:(G)=>{let ee=G.state.value||[];return t(L,{children:Rr.map((xe)=>{let de=!ee.includes(xe.id);return o("div",{className:"flex items-center justify-between p-3 bg-muted/30 border border-border rounded-lg",children:[o("div",{className:"flex items-center gap-3",children:[t(To,{className:"w-4 h-4 text-muted-foreground"}),o("div",{className:"flex flex-col",children:[t("span",{className:"text-sm font-medium",children:xe.name()}),t("span",{className:"text-[10px] text-muted-foreground line-clamp-1",children:xe.description()})]})]}),o("div",{className:"flex items-center gap-2",children:[t("span",{className:"text-xs text-muted-foreground",children:de?Bf():Lf()}),t(Me,{checked:de,disabled:!g,onCheckedChange:(Ke)=>{if(Ke)G.handleChange(ee.filter((bt)=>bt!==xe.id));else G.handleChange([...ee,xe.id])}})]})]},xe.id)})})}})})]})]})]})}),o(qe,{className:"p-6 pt-4 border-t border-border flex-shrink-0",children:[t(E,{variant:"outline",onClick:r,type:"button",children:De()}),t(v.Subscribe,{selector:(G)=>[G.canSubmit,G.isSubmitting],children:([G,ee])=>o(E,{type:"submit",className:"bg-primary hover:bg-primary/90 text-primary-foreground min-w-[120px]",disabled:!G||ee||Ee.isPending||Fe.isPending,children:[(ee||Ee.isPending||Fe.isPending)&&t(O,{className:"w-4 h-4 animate-spin mr-2"}),s?qs():my()]})})]})]})]})})}var Br=[{type:"chat",label:"Chat",icon:vo},{type:"autofill",label:"Autofill",icon:qt},{type:"embedding",label:"Embedding",icon:io}];function Ms({teamId:e}){let r=Q(),{canAdmin:a}=Dt(),[l,s]=u(!1),[d,c]=u("chat"),[g,_]=u(null),[p,b]=u(null),[x,m]=u(!1),[i,v]=u({chat:!0,autofill:!0,embedding:!0}),w=(T)=>{if(T==="chat")return Hm();if(T==="autofill")return qm();return $m()},{data:k=[],isLoading:z}=Z({queryKey:["agents",e],queryFn:async()=>{let T=await A.api.teams[":teamId"].agents.$get({param:{teamId:e}});if(!T.ok)throw Error("failed to fetch agents");return[...await T.json()].sort((j,X)=>X.id.localeCompare(j.id))}}),J=B({mutationFn:async(T)=>{if(!(await A.api.agents[":agentId"].$delete({param:{agentId:T}})).ok)throw Error("failed to delete agent")},onSuccess:()=>{m(!1),r.invalidateQueries({queryKey:["agents",e]}),M.success(c0())},onError:(T)=>{M.error(T.message)}}),H=B({mutationFn:async({agentId:T,permission:P})=>{let j=await A.api.agents[":agentId"].permission.$patch({param:{agentId:T},json:{permission:P}});if(!j.ok)throw Error(bl());return j.json()},onSuccess:()=>{r.invalidateQueries({queryKey:["agents",e]})},onError:(T)=>{M.error(T.message||bl())}}),ie=B({mutationFn:async(T)=>{let P=await A.api.agents[":agentId"].$put({param:{agentId:T.agentId},json:{name:T.name,type:T.type,enabled:T.enabled,avatar:T.avatar,providerId:T.providerId,modelId:T.modelId,thinkingLevel:T.thinkingLevel,systemPrompt:T.systemPrompt,soul:T.soul,skills:T.skills,deniedTools:T.deniedTools}});if(!P.ok)throw Error("failed to update agent");return P.json()},onSuccess:()=>{r.invalidateQueries({queryKey:["agents",e]}),M.success(Gm())},onError:(T)=>{M.error(T.message)}}),oe=(T)=>{v((P)=>({...P,[T]:!P[T]}))};return o(L,{children:[(l||g)&&t(ks,{isOpen:!0,title:g?_h({name:g.name}):xy({type:w(d)}),onClose:()=>{s(!1),_(null)},teamId:e,type:d,initialValues:g||void 0}),t(Je,{open:x,onOpenChange:m,children:o(Xe,{children:[o(et,{children:[t(rt,{children:dd()}),t(nt,{children:zy({name:p?.name??""})})]}),o(tt,{children:[t(st,{children:De()}),t(ot,{className:"bg-destructive hover:bg-destructive/90 text-white",onClick:(T)=>{if(J.isPending){T.preventDefault();return}if(p)J.mutate(p.id)},children:J.isPending?t(O,{className:"w-4 h-4 animate-spin"}):Uy()})]})]})}),z&&k.length===0?t("div",{className:"flex items-center justify-center p-12",children:t(O,{className:"w-8 h-8 animate-spin text-muted-foreground"})}):o("div",{className:"space-y-6 max-w-5xl mx-auto relative",children:[z&&t("div",{className:"absolute top-0 right-0 p-2",children:t(O,{className:"w-4 h-4 animate-spin text-muted-foreground"})}),Br.map((T)=>{let P=k.filter((F)=>F.type===T.type),j=T.icon,X=T.type==="autofill"||T.type==="embedding";return o("div",{className:"bg-card rounded-xl border border-border overflow-hidden",children:[o("div",{className:C("px-6 py-4 flex items-center justify-between",!X&&"cursor-pointer hover:bg-muted/50 transition-colors"),onClick:!X?()=>oe(T.type):void 0,children:[o("div",{className:"flex items-center gap-2",children:[t("h3",{className:"font-semibold text-foreground",children:T.type==="chat"?L_():T.type==="autofill"?h_():yb()}),!X&&t(be,{variant:"secondary",className:"h-5 px-1.5 min-w-[1.25rem] text-[10px]",children:P.length})]}),o("div",{className:"flex items-center gap-2",children:[!(X&&P.length>0)&&t(E,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-full bg-primary/10 text-primary hover:bg-primary/20",onClick:(F)=>{F.stopPropagation(),c(T.type),s(!0)},children:t(pe,{className:"w-4 h-4"})}),!X&&t(ve,{className:C("w-5 h-5 text-muted-foreground transition-transform duration-200",i[T.type]?"rotate-180":"")})]})]}),(X||i[T.type])&&t("div",{className:"px-6 pb-6 pt-2 space-y-3",children:o("div",{className:"grid grid-cols-1 gap-4",children:[P.map((F)=>t(ut,{className:"group relative overflow-hidden border-border hover:border-primary/50 transition-all duration-200 cursor-pointer pb-1 pt-1",onClick:()=>_(F),children:o(xt,{className:"p-4 flex flex-col gap-3",children:[o("div",{className:"flex items-center justify-between",children:[o("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[t("div",{className:"w-10 h-10 rounded-full bg-muted flex items-center justify-center overflow-hidden",children:F.avatar?t("img",{src:F.avatar,className:"w-full h-full object-cover",alt:""}):t(Ct,{className:"w-6 h-6 text-muted-foreground"})}),o("div",{className:"min-w-0 flex-1",children:[t("span",{className:"font-bold text-foreground block truncate",children:F.name}),t("div",{className:"flex items-center gap-2 text-xs text-muted-foreground mt-0.5",children:o("span",{className:"flex items-center gap-1",children:[t(Nt,{className:"w-3 h-3"}),TI({count:F.skills?.length||0})]})})]})]}),o(he,{modal:!1,children:[t(ge,{asChild:!0,onClick:(Y)=>Y.stopPropagation(),children:t(E,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-foreground",children:t(Sr,{className:"w-4 h-4"})})}),t(Ae,{align:"end",className:"w-32",children:o(K,{onClick:(Y)=>{Y.stopPropagation(),b(F),m(!0)},className:"text-red-500 focus:text-red-500 gap-2 cursor-pointer",children:[t(we,{className:"w-4 h-4"})," ",at()]})})]})]}),o("div",{className:"flex items-center justify-between gap-2 pt-2 border-t border-border/50",children:[t("div",{children:F.type==="chat"?t("div",{onClick:(Y)=>Y.stopPropagation(),children:o(Le,{value:F.permission||"reviewer",onValueChange:(Y)=>{H.mutate({agentId:F.id,permission:Y})},disabled:!a,children:[t(Be,{className:"h-7 text-xs px-2 bg-background border-border w-[140px]",children:t(Ze,{children:F.permission==="reviewer"?Fa():F.permission==="editor"?La():Za()})}),o(Ue,{align:"start",children:[t(ne,{value:"reviewer",children:Fa()}),t(ne,{value:"editor",children:La()}),t(ne,{value:"owner",children:Za()})]})]})}):t("div",{})}),t("div",{onClick:(Y)=>Y.stopPropagation(),children:t(Me,{checked:F.enabled,onCheckedChange:(Y)=>{ie.mutate({teamId:e,agentId:F.id,name:F.name,type:F.type,enabled:Y,avatar:F.avatar,providerId:F.providerId,modelId:F.modelId,thinkingLevel:F.thinkingLevel,systemPrompt:F.systemPrompt,soul:F.soul,skills:F.skills?.map((ye)=>ye.skillId),deniedTools:F.deniedTools})}})})]})]})},F.id)),P.length===0&&o("div",{className:"col-span-full py-8 flex flex-col items-center justify-center border-2 border-dashed border-border rounded-xl bg-muted/30",children:[t("div",{className:"w-10 h-10 rounded-full bg-card flex items-center justify-center shadow-sm mb-3",children:t(j,{className:"w-5 h-5 text-muted-foreground"})}),t("p",{className:"text-sm text-muted-foreground",children:Kx({type:w(T.type)})}),t(E,{variant:"link",size:"sm",className:"text-primary font-medium h-auto p-0 mt-1",onClick:()=>{c(T.type),s(!0)},children:yy()})]})]})})]},T.type)})]})]})}S();S();function Ca({isOpen:e,onClose:r,onSubmit:a,initialValues:l,title:s,isLoading:d=!1,defaultApi:c,existingModelIds:g=[]}){let _=N(()=>IA.extend({modelId:f().min(1,eg()).refine((m)=>{if(l?.modelId===m)return!0;return!g.includes(m)},{message:xx()})}),[g,l]),p=()=>l||{modelId:"",name:"",config:{api:c,reasoning:!1,input:["text"],contextWindow:128000,maxTokens:4096,cost:{input:0,output:0,cacheRead:0,cacheWrite:0}}},b=$t({defaultValues:p(),validators:{onSubmit:_},onSubmit:async({value:m})=>{a(m)}});h(()=>{if(e)b.reset(p())},[e,l,c,b]);let x=(m)=>m.map((i)=>{if(typeof i==="string")return{message:i};if(i&&typeof i==="object"&&"message"in i)return{message:String(i.message)};return{message:String(i||"")}});return t(ue,{open:e,onOpenChange:r,children:o(ae,{className:"sm:max-w-xl h-[85vh] max-h-[700px] flex flex-col p-0 overflow-hidden",children:[t(fe,{className:"p-6 pb-2 shrink-0",children:t(le,{className:"text-xl",children:s})}),o("form",{onSubmit:(m)=>{m.preventDefault(),m.stopPropagation(),b.handleSubmit()},className:"flex-1 flex flex-col min-h-0 overflow-hidden",children:[t("div",{className:"flex-1 min-h-0",children:t(ce,{className:"h-full",children:o("div",{className:"p-6 pt-2 space-y-6 pr-6",children:[o("div",{className:"space-y-4",children:[t(b.Field,{name:"modelId",children:(m)=>{let i=!!m.state.meta.errors.length&&m.state.meta.isTouched;return o(Oe,{"data-invalid":i,children:[t(Qe,{htmlFor:m.name,children:eg()}),t(q,{id:m.name,name:m.name,value:m.state.value,onBlur:m.handleBlur,onChange:(v)=>m.handleChange(v.target.value),placeholder:Sx(),"aria-invalid":i}),i&&t(We,{errors:x(m.state.meta.errors)})]})}}),t(b.Field,{name:"name",children:(m)=>{let i=!!m.state.meta.errors.length&&m.state.meta.isTouched;return o(Oe,{"data-invalid":i,children:[t(Qe,{htmlFor:m.name,children:ab()}),t(q,{id:m.name,name:m.name,value:m.state.value||"",onBlur:m.handleBlur,onChange:(v)=>m.handleChange(v.target.value),placeholder:Cx(),"aria-invalid":i}),i&&t(We,{errors:x(m.state.meta.errors)})]})}})]}),o("div",{className:"space-y-4 pt-2 border-t border-border",children:[t("h4",{className:"text-sm font-semibold text-foreground",children:KS()}),t(b.Field,{name:"config.reasoning",children:(m)=>o(Oe,{orientation:"horizontal",className:"rounded-lg border border-border p-3 shadow-sm bg-muted/40 justify-between flex items-center",children:[t(Qe,{htmlFor:m.name,className:"cursor-pointer",children:Ep()}),t(Me,{id:m.name,checked:m.state.value,onCheckedChange:m.handleChange})]})}),o("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[t(b.Field,{name:"config.contextWindow",children:(m)=>{let i=!!m.state.meta.errors.length&&m.state.meta.isTouched;return o(Oe,{"data-invalid":i,children:[t(Qe,{htmlFor:m.name,className:"text-xs",children:ny()}),t(q,{id:m.name,name:m.name,type:"number",value:m.state.value,onBlur:m.handleBlur,onChange:(v)=>m.handleChange(parseInt(v.target.value)||0),"aria-invalid":i}),i&&t(We,{errors:x(m.state.meta.errors)})]})}}),t(b.Field,{name:"config.maxTokens",children:(m)=>{let i=!!m.state.meta.errors.length&&m.state.meta.isTouched;return o(Oe,{"data-invalid":i,children:[t(Qe,{htmlFor:m.name,className:"text-xs",children:Lw()}),t(q,{id:m.name,name:m.name,type:"number",value:m.state.value,onBlur:m.handleBlur,onChange:(v)=>m.handleChange(parseInt(v.target.value)||0),"aria-invalid":i}),i&&t(We,{errors:x(m.state.meta.errors)})]})}})]})]}),o("div",{className:"space-y-4 pt-2 border-t border-border",children:[o("h4",{className:"text-sm font-semibold text-foreground flex items-center gap-1.5",children:[t(ma,{className:"w-4 h-4 text-primary"}),dE()]}),o("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[t(b.Field,{name:"config.cost.input",children:(m)=>{let i=!!m.state.meta.errors.length&&m.state.meta.isTouched;return o(Oe,{"data-invalid":i,children:[t(Qe,{htmlFor:m.name,className:"text-xs",children:dw()}),t(q,{id:m.name,name:m.name,type:"number",step:"0.0001",value:m.state.value,onBlur:m.handleBlur,onChange:(v)=>m.handleChange(parseFloat(v.target.value)||0),"aria-invalid":i}),i&&t(We,{errors:x(m.state.meta.errors)})]})}}),t(b.Field,{name:"config.cost.output",children:(m)=>{let i=!!m.state.meta.errors.length&&m.state.meta.isTouched;return o(Oe,{"data-invalid":i,children:[t(Qe,{htmlFor:m.name,className:"text-xs",children:HS()}),t(q,{id:m.name,name:m.name,type:"number",step:"0.0001",value:m.state.value,onBlur:m.handleBlur,onChange:(v)=>m.handleChange(parseFloat(v.target.value)||0),"aria-invalid":i}),i&&t(We,{errors:x(m.state.meta.errors)})]})}}),t(b.Field,{name:"config.cost.cacheRead",children:(m)=>{let i=!!m.state.meta.errors.length&&m.state.meta.isTouched;return o(Oe,{"data-invalid":i,children:[t(Qe,{htmlFor:m.name,className:"text-xs",children:P_()}),t(q,{id:m.name,name:m.name,type:"number",step:"0.0001",value:m.state.value,onBlur:m.handleBlur,onChange:(v)=>m.handleChange(parseFloat(v.target.value)||0),"aria-invalid":i}),i&&t(We,{errors:x(m.state.meta.errors)})]})}}),t(b.Field,{name:"config.cost.cacheWrite",children:(m)=>{let i=!!m.state.meta.errors.length&&m.state.meta.isTouched;return o(Oe,{"data-invalid":i,children:[t(Qe,{htmlFor:m.name,className:"text-xs",children:N_()}),t(q,{id:m.name,name:m.name,type:"number",step:"0.0001",value:m.state.value,onBlur:m.handleBlur,onChange:(v)=>m.handleChange(parseFloat(v.target.value)||0),"aria-invalid":i}),i&&t(We,{errors:x(m.state.meta.errors)})]})}})]})]})]})})}),o(qe,{className:"p-6 pt-4 border-t border-border gap-2 shrink-0",children:[t(E,{type:"button",variant:"outline",onClick:r,disabled:d,children:De()}),t(b.Subscribe,{selector:(m)=>[m.canSubmit,m.isSubmitting],children:([m,i])=>t(E,{type:"submit",className:"min-w-[100px]",disabled:!m||i||d,children:i||d?t(O,{className:"w-4 h-4 animate-spin"}):qs()})})]})]})]})})}S();function Fs({isOpen:e,onClose:r,teamId:a,syncData:l,onSuccess:s}){let[d,c]=u(""),[g,_]=u(()=>new Set(l?.providers.map((P)=>P.name)||[])),[p,b]=u(()=>{let P=new Set;return l?.providers.forEach((j)=>{j.models.forEach((X)=>{P.add(`${j.name}:${X.modelId}`)})}),P});h(()=>{if(l){_(new Set(l.providers.map((j)=>j.name)));let P=new Set;l.providers.forEach((j)=>{j.models.forEach((X)=>{P.add(`${j.name}:${X.modelId}`)})}),b(P)}},[l]);let x=N(()=>{if(!l)return[];let P=d.trim().toLowerCase();if(!P)return l.providers;return l.providers.map((j)=>{let X=j.name.toLowerCase().includes(P),F=j.models.filter((Y)=>X||Y.modelId.toLowerCase().includes(P)||Y.name.toLowerCase().includes(P));if(F.length>0)return{...j,models:F};return null}).filter((j)=>j!==null)},[l,d]),m=p.size,i=N(()=>{if(!l)return 0;let P=0;for(let j of l.providers)if(j.models.some((F)=>p.has(`${j.name}:${F.modelId}`)))P++;return P},[l,p]),v=(P)=>{_((j)=>{let X=new Set(j);if(X.has(P))X.delete(P);else X.add(P);return X})},w=()=>{if(!l)return;_(new Set(l.providers.map((P)=>P.name)))},k=()=>{_(new Set)},z=(P,j)=>{let X=`${P}:${j}`;b((F)=>{let Y=new Set(F);if(Y.has(X))Y.delete(X);else Y.add(X);return Y})},J=(P)=>{let j=l?.providers.find((F)=>F.name===P);if(!j||j.models.length===0)return;let X=j.models.every((F)=>p.has(`${P}:${F.modelId}`));b((F)=>{let Y=new Set(F);return j.models.forEach((ye)=>{let me=`${P}:${ye.modelId}`;if(X)Y.delete(me);else Y.add(me)}),Y})},H=()=>{if(!l)return;let P=new Set;l.providers.forEach((j)=>{j.models.forEach((X)=>{P.add(`${j.name}:${X.modelId}`)})}),b(P)},ie=()=>{b(new Set)},oe=B({mutationFn:async(P)=>{let j=await A.api.teams[":teamId"].providers["sync-apply"].$post({param:{teamId:a},json:P});if(!j.ok){let X=await j.json().catch(()=>({message:"Failed to apply sync"}));throw Error(X.message||"Failed to apply sync")}return await j.json()},onSuccess:(P)=>{M.success(hT({modelCount:P.addedModels,providerCount:P.addedProviders})),s(),r()},onError:(P)=>{M.error(P.message)}}),T=async()=>{if(!l||m===0)return;let P=[];for(let j of l.providers){let X=j.models.filter((F)=>p.has(`${j.name}:${F.modelId}`));if(X.length>0)P.push({name:j.name,isNewProvider:j.isNewProvider,config:j.config,models:X})}if(P.length===0)return;await oe.mutateAsync({providers:P})};return t(ue,{open:e,onOpenChange:(P)=>!P&&r(),children:o(ae,{className:"sm:max-w-3xl md:max-w-4xl w-full h-[85vh] max-h-[85vh] flex flex-col p-0 overflow-hidden gap-0",children:[o(fe,{className:"p-6 pb-4 shrink-0",children:[o(le,{className:"flex items-center gap-2 text-xl font-semibold",children:[t(dn,{className:"w-5 h-5 text-primary"}),iT()]}),t(It,{className:"text-xs text-muted-foreground leading-relaxed mt-1.5",children:sT()})]}),t("div",{className:"px-6 pb-3 shrink-0",children:o("div",{className:"flex items-center justify-between gap-3",children:[o("div",{className:"relative flex-1",children:[t(Ut,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-muted-foreground"}),t(q,{value:d,onChange:(P)=>c(P.target.value),placeholder:fT(),className:"pl-8 h-8 text-xs bg-background"})]}),o("div",{className:"flex items-center gap-1.5",children:[t(E,{type:"button",variant:"outline",size:"sm",onClick:w,className:"h-8 text-xs px-2.5",children:lT()}),t(E,{type:"button",variant:"outline",size:"sm",onClick:k,className:"h-8 text-xs px-2.5",children:rT()}),t("div",{className:"w-px h-4 bg-border mx-1"}),t(E,{type:"button",variant:"outline",size:"sm",onClick:H,className:"h-8 text-xs px-2.5",children:pT()}),t(E,{type:"button",variant:"outline",size:"sm",onClick:ie,className:"h-8 text-xs px-2.5",children:oT()})]})]})}),t("div",{className:"flex-1 min-h-0 px-6 overflow-hidden",children:t(ce,{className:"h-full border border-border/60 rounded-md bg-muted/20",children:t("div",{className:"p-3 space-y-3",children:x.length===0?t("div",{className:"py-8 text-center text-sm text-muted-foreground",children:fg()}):x.map((P)=>{let j=g.has(P.name),X=P.isNewProvider,F=P.models.filter((me)=>p.has(`${P.name}:${me.modelId}`)).length,Y=F===P.models.length,ye=F>0&&!Y;return o("div",{className:"border border-border/50 rounded-lg bg-background overflow-hidden",children:[o("div",{className:"flex items-center justify-between px-3 py-2 bg-card hover:bg-muted/40 transition-colors",children:[o("div",{className:"flex items-center gap-2.5",children:[t("button",{type:"button",onClick:()=>v(P.name),className:"p-0.5 text-muted-foreground hover:text-foreground rounded transition-colors",children:j?t(ve,{className:"w-4 h-4"}):t(vt,{className:"w-4 h-4"})}),t(vr,{checked:Y?!0:ye?"indeterminate":!1,onCheckedChange:()=>J(P.name),id:`provider-check-${P.name}`}),o("label",{htmlFor:`provider-check-${P.name}`,className:"font-medium text-sm text-foreground flex items-center gap-2 cursor-pointer select-none",children:[t(io,{className:"w-4 h-4 text-muted-foreground"}),t("span",{children:P.name})]})]}),o("div",{className:"flex items-center gap-2",children:[X?t(be,{variant:"secondary",className:"text-[10px] px-1.5 py-0 bg-primary/10 text-primary border-primary/20",children:uT()}):t(be,{variant:"outline",className:"text-[10px] px-1.5 py-0 text-muted-foreground",children:aT()}),t("span",{className:"text-xs text-muted-foreground",children:cT({count:P.models.length})})]})]}),j&&t("div",{className:"border-t border-border/40 divide-y divide-border/30 bg-muted/10",children:P.models.map((me)=>{let Ee=p.has(`${P.name}:${me.modelId}`);return o("div",{className:"flex items-center justify-between pl-9 pr-3 py-2 hover:bg-muted/30 transition-colors",children:[o("div",{className:"flex items-center gap-2.5 min-w-0",children:[t(vr,{checked:Ee,onCheckedChange:()=>z(P.name,me.modelId),id:`model-check-${P.name}-${me.modelId}`}),o("label",{htmlFor:`model-check-${P.name}-${me.modelId}`,className:"text-xs font-medium text-foreground cursor-pointer select-none truncate",children:[me.name||me.modelId,t("span",{className:"ml-1.5 text-[11px] text-muted-foreground font-mono font-normal",children:me.modelId})]})]}),o("div",{className:"flex items-center gap-1.5 shrink-0 ml-2",children:[me.config.reasoning&&t(be,{variant:"outline",className:"text-[10px] px-1.5 py-0 font-normal border-amber-500/30 text-amber-600 dark:text-amber-400",children:dT()}),t("span",{className:"text-[11px] text-muted-foreground font-mono",children:nT({count:Math.round(me.config.contextWindow/1000)})})]})]},me.modelId)})})]},P.name)})})})}),o(qe,{className:"p-6 pt-3 shrink-0 border-t border-border flex items-center justify-between sm:justify-between w-full",children:[t("div",{className:"text-xs text-muted-foreground",children:mT({modelCount:m,providerCount:i})}),o("div",{className:"flex items-center gap-2",children:[t(E,{type:"button",variant:"outline",onClick:r,disabled:oe.isPending,children:De()}),t(E,{type:"button",onClick:T,disabled:m===0||oe.isPending,className:"gap-2",children:oe.isPending?o(L,{children:[t(O,{className:"w-4 h-4 animate-spin"}),eT()]}):XI({count:m})})]})]})]})})}var As={"openai-completions":"OpenAI Completions","mistral-conversations":"Mistral Conversations","openai-responses":"OpenAI Responses","azure-openai-responses":"Azure OpenAI Responses","openai-codex-responses":"OpenAI Codex Responses","anthropic-messages":"Anthropic Messages","bedrock-converse-stream":"AWS Bedrock","google-generative-ai":"Google Generative AI","google-vertex":"Google Vertex"};function Is({teamId:e}){let r=Q(),[a,l]=u(null),[s,d]=u(!1),[c,g]=u(""),[_,p]=u(!1),[b,x]=u(null),[m,i]=u(!1),[v,w]=u(null),k=B({mutationFn:async()=>{let j=await A.api.teams[":teamId"].providers["sync-check"].$post({param:{teamId:e}});if(!j.ok){let X=await j.json().catch(()=>({message:"Failed to check updates"}));throw Error(X.message||"Failed to check updates")}return await j.json()},onSuccess:(j)=>{if(j.totalNewModels===0&&j.totalNewProviders===0){M.info(gT());return}w(j),i(!0)},onError:(j)=>{M.error(j.message)}}),{data:z,isLoading:J}=Z({queryKey:["teams",e,"providers"],queryFn:async()=>{let j=await A.api.teams[":teamId"].providers.$get({param:{teamId:e}});if(!j.ok)throw Error("Failed to fetch providers");return await j.json()}}),H=N(()=>z?.find((j)=>j.id===a)||null,[z,a]),ie=N(()=>z?.map((j)=>j.name)||[],[z]),oe=N(()=>{if(!z)return[];if(!c.trim())return z;let j=c.toLowerCase();return z.filter((X)=>X.name.toLowerCase().includes(j))},[z,c]),T=B({mutationFn:async(j)=>{let X=await A.api.teams[":teamId"].providers.$post({param:{teamId:e},json:{name:j.name,config:j.config,models:j.models}});if(!X.ok)throw Error("Failed to create provider");return await X.json()},onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"providers"]}),d(!1),M.success(TE())},onError:(j)=>{M.error(zs({message:j.message}))}}),P=B({mutationFn:async(j)=>{let X=await A.api.providers[":id"].$delete({param:{id:j}});if(!X.ok)throw Error("Failed to delete provider");return await X.json()},onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"providers"]}),l(null),p(!1),x(null),M.success(ME())},onError:(j)=>{M.error(zs({message:j.message}))}});if(J)return t("div",{className:"flex h-64 items-center justify-center",children:t(O,{className:"h-8 w-8 animate-spin text-primary"})});return o("div",{className:"h-full flex flex-col space-y-0",children:[o("div",{className:"flex-none space-y-4 pb-4",children:[o("div",{className:"flex items-center justify-between",children:[o("h3",{className:"text-lg font-semibold text-foreground flex items-center gap-2",children:[t(io,{className:"w-5 h-5 text-primary"}),J_()]}),o("div",{className:"flex items-center gap-2",children:[t(E,{variant:"outline",onClick:()=>k.mutate(),disabled:k.isPending,className:"gap-2",children:k.isPending?o(L,{children:[t(O,{className:"w-4 h-4 animate-spin"}),tT()]}):o(L,{children:[t(ua,{className:"w-4 h-4"}),JI()]})}),o(E,{onClick:()=>d(!0),className:"bg-primary hover:bg-primary/90 text-primary-foreground gap-2",children:[t(pe,{className:"w-4 h-4"}),Mm()]})]})]}),o("div",{className:"relative px-0.5",children:[t(Ut,{className:"absolute left-3.5 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),t(q,{placeholder:Xg(),value:c,onChange:(j)=>g(j.target.value),className:"pl-10 bg-card border-border focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-0"})]})]}),t(ce,{className:"flex-1 min-h-0",children:o("div",{className:"pr-4 py-2 grid grid-cols-1 gap-4",children:[oe.map((j)=>t(ut,{className:"group cursor-pointer hover:border-primary/50 transition-all hover:shadow-md overflow-hidden",onClick:()=>l(j.id),children:o(xt,{className:"p-5 flex items-center justify-between gap-4",children:[o("div",{className:"flex items-center gap-4 min-w-0 flex-1",children:[t("div",{className:"flex-none p-3 bg-muted rounded-xl group-hover:bg-primary/10 transition-colors",children:t(ca,{className:"w-6 h-6 text-muted-foreground group-hover:text-primary"})}),o("div",{className:"min-w-0 flex-1",children:[t("div",{className:"flex items-center gap-2",children:t("span",{className:"font-bold text-foreground truncate",children:j.name})}),o("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1.5 text-xs text-muted-foreground mt-1",children:[o("span",{className:"flex items-center gap-1 flex-none",children:[t(qt,{className:"w-3 h-3"}),j.config.api]}),j.config.baseUrl&&o("span",{className:"flex items-center gap-1 min-w-0",children:[t("span",{className:"h-1 w-1 rounded-full bg-muted-foreground/30 flex-none"}),t(Wo,{className:"w-3 h-3 flex-none"}),t("span",{className:"truncate max-w-[200px] md:max-w-[300px]",children:j.config.baseUrl})]}),o("span",{className:"flex items-center gap-1 flex-none",children:[t("span",{className:"h-1 w-1 rounded-full bg-muted-foreground/30 flex-none"}),t(es,{className:"w-3 h-3"}),Ox({count:j.modelsCount})]})]})]})]}),o("div",{className:"flex items-center gap-1",children:[o(he,{modal:!1,children:[t(ge,{asChild:!0,onClick:(X)=>X.stopPropagation(),children:t(E,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-foreground",children:t(Sr,{className:"w-4 h-4"})})}),t(Ae,{align:"end",className:"w-32",children:o(K,{onClick:(X)=>{X.stopPropagation(),x(j),p(!0)},className:"text-destructive focus:text-destructive gap-2 cursor-pointer",children:[t(we,{className:"w-4 h-4"})," ",at()]})})]}),t(vt,{className:"flex-none w-5 h-5 text-muted-foreground/50 group-hover:text-primary transition-colors"})]})]})},j.id)),z?.length===0&&o("div",{className:"text-center py-12 bg-muted/30 rounded-2xl border-2 border-dashed border-border",children:[t(io,{className:"w-12 h-12 text-muted-foreground/50 mx-auto mb-4"}),t("h4",{className:"text-foreground font-medium",children:lS()}),t("p",{className:"text-sm text-muted-foreground mt-1",children:QA()})]}),z&&z.length>0&&oe.length===0&&o("div",{className:"text-center py-12",children:[t(Ut,{className:"w-12 h-12 text-muted-foreground/50 mx-auto mb-4"}),t("h4",{className:"text-foreground font-medium",children:fg()}),t("p",{className:"text-sm text-muted-foreground mt-1",children:JT({query:c})}),t(E,{variant:"ghost",size:"sm",onClick:()=>g(""),className:"mt-4 text-primary hover:text-primary/90 hover:bg-primary/10",children:z_()})]})]})}),t(qr,{isOpen:s,onClose:()=>d(!1),onSubmit:(j)=>T.mutate(j),isLoading:T.isPending,existingProviderNames:ie}),H&&t(jr,{isOpen:!!H,onClose:()=>l(null),provider:H,teamId:e,existingProviderNames:ie}),t(Je,{open:_,onOpenChange:p,children:o(Xe,{children:[o(et,{children:[t(rt,{children:dd()}),t(nt,{children:Wy({name:b?.name??""})})]}),o(tt,{children:[t(st,{onClick:()=>x(null),children:De()}),o(ot,{className:"bg-destructive hover:bg-destructive/90 text-destructive-foreground",onClick:()=>{if(b)P.mutate(b.id)},children:[P.isPending?t(O,{className:"w-4 h-4 animate-spin mr-2"}):t(we,{className:"w-4 h-4 mr-2"}),at()]})]})]})}),t(Fs,{isOpen:m,onClose:()=>i(!1),teamId:e,syncData:v,onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"providers"]})}})]})}function qr({isOpen:e,onClose:r,onSubmit:a,isLoading:l,existingProviderNames:s}){let[d,c]=u([]),[g,_]=u(!1),[p,b]=u(null),x=N(()=>R({name:f().min(1,Mg()).refine((w)=>!s.includes(w),{message:kg()}),config:ia}),[s]),m=$t({defaultValues:{name:"",config:{api:"openai-completions",baseUrl:"",apiKey:""}},validators:{onSubmit:x},onSubmit:async({value:w})=>{a({name:w.name,config:w.config,models:d})}});h(()=>{if(e)m.reset(),c([]),_(!1),b(null)},[e,m]);let i=(w)=>w.map((k)=>{if(typeof k==="string")return{message:k};if(k&&typeof k==="object"&&"message"in k)return{message:String(k.message)};return{message:String(k||"")}}),v=(w)=>{if(p!==null)c((k)=>k.map((z,J)=>J===p?w:z)),b(null);else c((k)=>[w,...k]),_(!1)};return t(ue,{open:e,onOpenChange:r,children:o(ae,{className:"sm:max-w-2xl h-[85vh] flex flex-col p-0 overflow-hidden",children:[o(fe,{className:"p-6 pb-2 shrink-0",children:[t(le,{className:"text-xl",children:JA()}),t(It,{children:oh()})]}),o("form",{onSubmit:(w)=>{w.preventDefault(),w.stopPropagation(),m.handleSubmit()},className:"flex-1 flex flex-col min-h-0 overflow-hidden",children:[t("div",{className:"flex-1 min-h-0",children:t(ce,{className:"h-full",children:o("div",{className:"p-6 pt-2 space-y-6 pr-6",children:[o("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 p-5 rounded-2xl border bg-muted/20",children:[t(m.Field,{name:"name",children:(w)=>{let k=!!w.state.meta.errors.length&&w.state.meta.isTouched;return o(Oe,{"data-invalid":k,children:[t(Qe,{htmlFor:w.name,children:Tg()}),t(q,{id:w.name,name:w.name,value:w.state.value,onBlur:w.handleBlur,onChange:(z)=>w.handleChange(z.target.value),placeholder:Rg(),"aria-invalid":k}),k&&t(We,{errors:i(w.state.meta.errors)})]})}}),t(m.Field,{name:"config.api",children:(w)=>{let k=!!w.state.meta.errors.length&&w.state.meta.isTouched;return o(Oe,{"data-invalid":k,children:[t(Qe,{htmlFor:w.name,children:Uh()}),o(Le,{onValueChange:w.handleChange,value:w.state.value,children:[t(Be,{id:w.name,"aria-invalid":k,children:t(Ze,{placeholder:eA()})}),t(Ue,{children:ou.map((z)=>t(ne,{value:z,children:As[z]},z))})]}),k&&t(We,{errors:i(w.state.meta.errors)})]})}}),t("div",{className:"md:col-span-2",children:t(m.Field,{name:"config.baseUrl",children:(w)=>{let k=!!w.state.meta.errors.length&&w.state.meta.isTouched;return o(Oe,{"data-invalid":k,children:[t(Qe,{htmlFor:w.name,children:th()}),t(q,{id:w.name,name:w.name,value:w.state.value||"",onBlur:w.handleBlur,onChange:(z)=>w.handleChange(z.target.value),placeholder:"https://api.openai.com/v1","aria-invalid":k}),t(aa,{children:_g()}),k&&t(We,{errors:i(w.state.meta.errors)})]})}})}),t("div",{className:"md:col-span-2",children:t(m.Field,{name:"config.apiKey",children:(w)=>{let k=!!w.state.meta.errors.length&&w.state.meta.isTouched;return o(Oe,{"data-invalid":k,children:[t(Qe,{htmlFor:w.name,children:ud()}),t(q,{id:w.name,name:w.name,type:"text",value:w.state.value||"",onBlur:w.handleBlur,onChange:(z)=>w.handleChange(z.target.value),placeholder:Wm(),"aria-invalid":k}),t(aa,{className:"text-xs mt-1",children:Km()}),k&&t(We,{errors:i(w.state.meta.errors)})]})}})})]}),o("div",{className:"space-y-3",children:[o("div",{className:"flex items-center justify-between",children:[o("div",{children:[t(W,{className:"text-base font-semibold",children:Sd()}),t("p",{className:"text-xs text-muted-foreground mt-0.5",children:Tx()})]}),o(E,{type:"button",variant:"outline",size:"sm",onClick:()=>_(!0),className:"gap-1.5",children:[t(pe,{className:"w-4 h-4"}),ad()]})]}),d.length===0?t("div",{className:"text-center py-8 rounded-xl border border-dashed text-muted-foreground text-sm",children:Cd()}):t("div",{className:"space-y-2",children:d.map((w,k)=>o("div",{className:"group cursor-pointer flex items-center justify-between p-3 rounded-xl border bg-card hover:border-primary/50 transition-all shadow-none hover:shadow-sm",onClick:()=>b(k),children:[o("div",{className:"min-w-0 flex-1",children:[o("div",{className:"flex items-center gap-2",children:[t("span",{className:"font-semibold text-foreground truncate",children:w.name||w.modelId}),t(be,{variant:"secondary",className:"font-mono text-[10px]",children:w.modelId}),w.config.reasoning&&o(be,{variant:"outline",className:"text-[10px] gap-1 bg-primary/10 text-primary border-primary/20",children:[t(qt,{className:"w-2.5 h-2.5"})," ",Ep()]})]}),o("div",{className:"text-xs text-muted-foreground mt-1 flex items-center gap-2",children:[o("span",{children:[w.config.contextWindow?.toLocaleString()," ",yA()]}),t("span",{children:"·"}),t("span",{children:lh({input:w.config.cost?.input??0,output:w.config.cost?.output??0})})]})]}),t("div",{className:"flex items-center gap-1 ml-2",children:t(E,{type:"button",variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:(z)=>{z.stopPropagation(),c((J)=>J.filter((H,ie)=>ie!==k))},children:t(we,{className:"w-3.5 h-3.5"})})})]},w.modelId+k))})]})]})})}),o(qe,{className:"p-6 pt-4 border-t border-border gap-2 shrink-0",children:[t(E,{type:"button",variant:"outline",onClick:r,disabled:l,children:De()}),t(m.Subscribe,{selector:(w)=>[w.canSubmit,w.isSubmitting],children:([w,k])=>t(E,{type:"submit",className:"min-w-[120px]",disabled:!w||k||l,children:k||l?t(O,{className:"w-4 h-4 animate-spin"}):Mm()})})]})]}),(g||p!==null)&&t(Ca,{isOpen:!0,onClose:()=>{_(!1),b(null)},onSubmit:v,title:p!==null?yh():ad(),initialValues:p!==null?d[p]:null,defaultApi:m.getFieldValue("config.api"),existingModelIds:d.filter((w,k)=>k!==p).map((w)=>w.modelId)},p!==null?`edit-${p}-${d[p]?.modelId}`:"add")]})})}function jr({isOpen:e,onClose:r,provider:a,teamId:l,existingProviderNames:s}){let d=Q(),[c,g]=u("general"),[_,p]=u(""),[b,x]=u(!1),[m,i]=u(null),[v,w]=u(null),{data:k=[],isLoading:z}=Z({queryKey:["teams",l,"providers",a.id,"models"],queryFn:async()=>{let F=await A.api.providers[":id"].models.$get({param:{id:a.id}});if(!F.ok)throw Error("Failed to fetch models");return await F.json()},enabled:e}),J=B({mutationFn:async(F)=>{let Y=await A.api.providers[":id"].$put({param:{id:a.id},json:{name:F.name,config:F.config}});if(!Y.ok)throw Error("Failed to update provider");return await Y.json()},onSuccess:()=>{d.invalidateQueries({queryKey:["teams",l,"providers"]}),M.success(Og())},onError:(F)=>{M.error(zs({message:F.message}))}}),H=B({mutationFn:async(F)=>{let Y=await A.api.providers[":id"].models.$post({param:{id:a.id},json:F});if(!Y.ok)throw Error("Failed to create model");return await Y.json()},onSuccess:()=>{d.invalidateQueries({queryKey:["teams",l,"providers",a.id,"models"]}),d.invalidateQueries({queryKey:["teams",l,"providers"]}),x(!1),M.success(vx())},onError:(F)=>{M.error(zs({message:F.message}))}}),ie=B({mutationFn:async({modelDbId:F,values:Y})=>{let ye=await A.api.providers[":id"].models[":modelDbId"].$put({param:{id:a.id,modelDbId:F},json:Y});if(!ye.ok)throw Error("Failed to update model");return await ye.json()},onSuccess:()=>{d.invalidateQueries({queryKey:["teams",l,"providers",a.id,"models"]}),i(null),M.success(Ix())},onError:(F)=>{M.error(zs({message:F.message}))}}),oe=B({mutationFn:async(F)=>{let Y=await A.api.providers[":id"].models[":modelDbId"].$delete({param:{id:a.id,modelDbId:F}});if(!Y.ok)throw Error("Failed to delete model");return await Y.json()},onSuccess:()=>{d.invalidateQueries({queryKey:["teams",l,"providers",a.id,"models"]}),d.invalidateQueries({queryKey:["teams",l,"providers"]}),w(null),M.success(wx())},onError:(F)=>{M.error(zs({message:F.message}))}}),T=N(()=>R({name:f().min(1,Mg()).refine((F)=>{if(a.name===F)return!0;return!s.includes(F)},{message:kg()}),config:ia}),[s,a.name]),P=$t({defaultValues:{name:a.name,config:a.config},validators:{onSubmit:T},onSubmit:async({value:F})=>{J.mutate({name:F.name,config:F.config})}});h(()=>{if(e)P.reset(),g("general"),p("")},[e,P]);let j=(F)=>F.map((Y)=>{if(typeof Y==="string")return{message:Y};if(Y&&typeof Y==="object"&&"message"in Y)return{message:String(Y.message)};return{message:String(Y||"")}}),X=N(()=>{if(!_.trim())return k;let F=_.toLowerCase();return k.filter((Y)=>Y.modelId.toLowerCase().includes(F)||Y.name?.toLowerCase().includes(F))},[k,_]);return t(ue,{open:e,onOpenChange:r,children:o(ae,{className:"sm:max-w-3xl h-[88vh] flex flex-col p-0 overflow-hidden",children:[o(fe,{className:"p-6 pb-2 shrink-0",children:[t(le,{className:"text-xl",children:_h({name:a.name})}),t(It,{children:oh()})]}),o(So,{value:c,onValueChange:(F)=>g(F),className:"flex-1 flex flex-col min-h-0",children:[t("div",{className:"px-6 pb-2 shrink-0",children:o(Eo,{className:"grid w-full grid-cols-2",children:[t(Kr,{value:"general",children:Bh()}),o(Kr,{value:"models",className:"gap-2",children:[Sd(),t(be,{variant:"secondary",className:"h-5 px-1.5 text-[11px]",children:k.length})]})]})}),t(kn,{value:"general",className:"flex-1 flex flex-col min-h-0 m-0",children:o("form",{onSubmit:(F)=>{F.preventDefault(),F.stopPropagation(),P.handleSubmit()},className:"flex-1 flex flex-col min-h-0",children:[t("div",{className:"flex-1 min-h-0",children:t(ce,{className:"h-full",children:t("div",{className:"p-6 space-y-6 pr-6",children:o("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-5 p-5 rounded-2xl border bg-muted/10",children:[t(P.Field,{name:"name",children:(F)=>{let Y=!!F.state.meta.errors.length&&F.state.meta.isTouched;return o(Oe,{"data-invalid":Y,children:[t(Qe,{htmlFor:F.name,children:Tg()}),t(q,{id:F.name,name:F.name,value:F.state.value,onBlur:F.handleBlur,onChange:(ye)=>F.handleChange(ye.target.value),placeholder:Rg(),"aria-invalid":Y}),Y&&t(We,{errors:j(F.state.meta.errors)})]})}}),t(P.Field,{name:"config.api",children:(F)=>{let Y=!!F.state.meta.errors.length&&F.state.meta.isTouched;return o(Oe,{"data-invalid":Y,children:[t(Qe,{htmlFor:F.name,children:Uh()}),o(Le,{onValueChange:F.handleChange,value:F.state.value,children:[t(Be,{id:F.name,"aria-invalid":Y,children:t(Ze,{placeholder:eA()})}),t(Ue,{children:ou.map((ye)=>t(ne,{value:ye,children:As[ye]},ye))})]}),Y&&t(We,{errors:j(F.state.meta.errors)})]})}}),t("div",{className:"md:col-span-2",children:t(P.Field,{name:"config.baseUrl",children:(F)=>{let Y=!!F.state.meta.errors.length&&F.state.meta.isTouched;return o(Oe,{"data-invalid":Y,children:[t(Qe,{htmlFor:F.name,children:th()}),t(q,{id:F.name,name:F.name,value:F.state.value||"",onBlur:F.handleBlur,onChange:(ye)=>F.handleChange(ye.target.value),placeholder:"https://api.openai.com/v1","aria-invalid":Y}),t(aa,{children:_g()}),Y&&t(We,{errors:j(F.state.meta.errors)})]})}})}),t("div",{className:"md:col-span-2",children:t(P.Field,{name:"config.apiKey",children:(F)=>{let Y=!!F.state.meta.errors.length&&F.state.meta.isTouched;return o(Oe,{"data-invalid":Y,children:[t(Qe,{htmlFor:F.name,children:ud()}),t(q,{id:F.name,name:F.name,type:"text",value:F.state.value||"",onBlur:F.handleBlur,onChange:(ye)=>F.handleChange(ye.target.value),placeholder:Wm(),"aria-invalid":Y}),t(aa,{className:"text-xs mt-1",children:Km()}),Y&&t(We,{errors:j(F.state.meta.errors)})]})}})})]})})})}),o(qe,{className:"p-6 pt-4 border-t border-border gap-2 shrink-0",children:[t(E,{type:"button",variant:"outline",onClick:r,children:De()}),t(P.Subscribe,{selector:(F)=>[F.canSubmit,F.isSubmitting],children:([F,Y])=>t(E,{type:"submit",className:"min-w-[120px]",disabled:!F||Y||J.isPending,children:Y||J.isPending?t(O,{className:"w-4 h-4 animate-spin"}):qs()})})]})]})}),o(kn,{value:"models",className:"flex-1 flex flex-col min-h-0 m-0",children:[o("div",{className:"p-6 pb-3 flex items-center justify-between gap-3 shrink-0",children:[o("div",{className:"relative flex-1 max-w-sm",children:[t(Ut,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),t(q,{placeholder:Rp(),value:_,onChange:(F)=>p(F.target.value),className:"pl-9 h-9"})]}),o(E,{size:"sm",onClick:()=>x(!0),className:"gap-1.5 shrink-0",children:[t(pe,{className:"w-4 h-4"}),ad()]})]}),t("div",{className:"flex-1 min-h-0 px-6",children:t(ce,{className:"h-full pr-4",children:z?t("div",{className:"flex h-48 items-center justify-center",children:t(O,{className:"h-6 w-6 animate-spin text-primary"})}):X.length===0?t("div",{className:"text-center py-12 border border-dashed rounded-xl text-muted-foreground text-sm",children:Cd()}):t("div",{className:"space-y-2 pb-4",children:X.map((F)=>o("div",{className:"group cursor-pointer flex items-center justify-between p-3.5 rounded-xl border bg-card hover:border-primary/50 transition-all shadow-none hover:shadow-sm",onClick:()=>i(F),children:[o("div",{className:"min-w-0 flex-1 pr-3",children:[o("div",{className:"flex items-center gap-2 flex-wrap",children:[t("span",{className:"font-semibold text-foreground text-sm",children:F.name||F.modelId}),t(be,{variant:"secondary",className:"font-mono text-[10px] px-1.5 py-0.5",children:F.modelId}),F.config?.reasoning&&o(be,{variant:"outline",className:"text-[10px] gap-1 bg-primary/10 text-primary border-primary/20 h-5",children:[t(qt,{className:"w-2.5 h-2.5"})," ",Ep()]})]}),o("div",{className:"text-xs text-muted-foreground mt-1.5 flex flex-wrap items-center gap-x-2 gap-y-1",children:[o("span",{children:[F.config?.contextWindow?.toLocaleString()," ",yA()]}),t("span",{children:"·"}),t("span",{children:Zw({count:F.config?.maxTokens?.toLocaleString()??"0"})}),t("span",{children:"·"}),t("span",{children:lh({input:F.config?.cost?.input??0,output:F.config?.cost?.output??0})})]})]}),t("div",{className:"flex items-center gap-1 shrink-0",children:t(E,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:(Y)=>{Y.stopPropagation(),w(F)},children:t(we,{className:"w-3.5 h-3.5"})})})]},F.id))})})})]})]}),b&&t(Ca,{isOpen:b,onClose:()=>x(!1),onSubmit:(F)=>H.mutate(F),title:ad(),isLoading:H.isPending,defaultApi:a.config.api,existingModelIds:k.map((F)=>F.modelId)}),m&&t(Ca,{isOpen:!!m,onClose:()=>i(null),onSubmit:(F)=>ie.mutate({modelDbId:m.id,values:F}),title:yh(),isLoading:ie.isPending,initialValues:{modelId:m.modelId,name:m.name,config:m.config},defaultApi:a.config.api,existingModelIds:k.filter((F)=>F.id!==m.id).map((F)=>F.modelId)}),t(Je,{open:!!v,onOpenChange:(F)=>!F&&w(null),children:o(Xe,{children:[o(et,{children:[t(rt,{children:dd()}),t(nt,{children:Vy({name:v?.name||v?.modelId||""})})]}),o(tt,{children:[t(st,{onClick:()=>w(null),children:De()}),o(ot,{className:"bg-destructive hover:bg-destructive/90 text-destructive-foreground",onClick:()=>{if(v)oe.mutate(v.id)},children:[oe.isPending?t(O,{className:"w-4 h-4 animate-spin mr-2"}):t(we,{className:"w-4 h-4 mr-2"}),at()]})]})]})})]})})}S();function Ts({teamId:e}){let r=Q(),[a,l]=u(""),{data:s,isLoading:d}=Z({queryKey:["teams",e,"sandbox"],queryFn:async()=>{let v=await A.api.teams[":teamId"].sandbox.$get({param:{teamId:e}});if(!v.ok)throw Error(Jo());return await v.json()}}),{mutate:c,isPending:g}=B({mutationFn:async(v)=>{let w=await A.api.teams[":teamId"].sandbox.$put({param:{teamId:e},json:v});if(!w.ok)throw Error(Rh());return await w.json()},onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"sandbox"]}),M.success(RC())},onError:(v)=>{M.error(v instanceof Error?v.message:Rh())}}),_=(v)=>{c({networkSandboxEnabled:v})},p=(v)=>{if(v.preventDefault(),!a.trim())return;if(s?.allowedDomains.includes(a.trim())){M.error(lb());return}let w=[...s?.allowedDomains||[],a.trim()],k=s?.pendingDomains||[];c({allowedDomains:w,pendingDomains:k}),l("")},b=(v)=>{let w=(s?.allowedDomains||[]).filter((z)=>z!==v),k=s?.pendingDomains||[];c({allowedDomains:w,pendingDomains:k})},x=(v)=>{let w=[...s?.allowedDomains||[],v],k=(s?.pendingDomains||[]).filter((z)=>z!==v);c({allowedDomains:w,pendingDomains:k})},m=(v)=>{let w=(s?.pendingDomains||[]).filter((k)=>k!==v);c({allowedDomains:s?.allowedDomains||[],pendingDomains:w})};if(d)return t("div",{className:"flex items-center justify-center p-8",children:t(O,{className:"h-8 w-8 animate-spin text-muted-foreground"})});let i=!!s?.networkSandboxEnabled;return t(ce,{className:"h-full",children:o("div",{className:"space-y-6 pr-4 pb-8",children:[o(ut,{children:[o(Tt,{children:[o("div",{className:"flex items-center gap-2",children:[t(ca,{className:"w-5 h-5 text-primary"}),t(Mt,{children:Bx()})]}),t(Ot,{children:Ux()})]}),o(xt,{children:[o("div",{className:"flex items-center justify-between p-4 mb-6 rounded-lg border border-border bg-muted/30",children:[o("div",{className:"space-y-0.5 pr-4",children:[t("label",{htmlFor:"network-sandbox-switch",className:"text-sm font-medium text-foreground cursor-pointer",children:Eb()}),t("p",{className:"text-xs text-muted-foreground",children:jx()})]}),t(Me,{id:"network-sandbox-switch",checked:i,onCheckedChange:_,disabled:g})]}),!i&&o("div",{className:"flex items-start gap-2.5 p-3.5 mb-6 rounded-lg bg-amber-500/10 border border-amber-500/20 text-amber-700 dark:text-amber-300 text-sm",children:[t(Wo,{className:"w-4 h-4 mt-0.5 shrink-0"}),t("span",{children:zx()})]}),o("form",{onSubmit:p,className:"flex gap-2 mb-6",children:[t(q,{placeholder:"e.g. api.openai.com",value:a,onChange:(v)=>l(v.target.value),disabled:g||!i}),o(E,{type:"submit",disabled:g||!i,children:[g?t(O,{className:"w-4 h-4 animate-spin"}):t(pe,{className:"w-4 h-4 mr-2"}),VA()]})]}),o("div",{className:"space-y-2",children:[t("h4",{className:"text-sm font-medium text-muted-foreground mb-3",children:Y0()}),o("div",{className:"flex flex-wrap gap-2",children:[s?.allowedDomains.map((v)=>o("div",{className:"flex items-center gap-1 px-3 py-1.5 bg-muted rounded-full text-sm border border-border transition-all hover:border-muted-foreground/50",children:[t("span",{className:"font-medium text-foreground",children:v}),t("button",{onClick:()=>b(v),className:"ml-1 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50 disabled:cursor-not-allowed",disabled:g||!i,children:t(Ne,{className:"w-3.5 h-3.5"})})]},v)),s?.allowedDomains.length===0&&t("div",{className:"text-sm text-muted-foreground italic",children:eS()})]})]})]})]}),o(ut,{className:"border-orange-500/20 bg-orange-500/5",children:[o(Tt,{children:[o("div",{className:"flex items-center gap-2",children:[t(Wl,{className:"w-5 h-5 text-orange-500"}),t(Mt,{children:eE()})]}),t(Ot,{children:tE()})]}),t(xt,{children:t("div",{className:"space-y-3",children:s?.pendingDomains&&s.pendingDomains.length>0?t("div",{className:"divide-y divide-border",children:s.pendingDomains.map((v)=>o("div",{className:"flex items-center justify-between py-2.5 first:pt-0 last:pb-0",children:[t("span",{className:"font-mono text-sm text-foreground bg-muted px-2 py-1 rounded break-all",children:v}),o("div",{className:"flex items-center gap-2",children:[o(E,{size:"sm",variant:"outline",className:"h-8 border-emerald-500/20 text-emerald-600 hover:bg-emerald-500/10 hover:text-emerald-600 dark:text-emerald-400 dark:hover:bg-emerald-500/20",onClick:()=>x(v),disabled:g||!i,children:[t(Pe,{className:"w-4 h-4 mr-1.5"}),s_()]}),o(E,{size:"sm",variant:"outline",className:"h-8 border-destructive/20 text-destructive hover:bg-destructive/10",onClick:()=>m(v),disabled:g||!i,children:[t(we,{className:"w-4 h-4 mr-1.5"}),at()]})]})]},v))}):t("div",{className:"text-sm text-muted-foreground italic py-2",children:aS()})})})]}),t(ut,{children:o(Tt,{children:[t(Mt,{children:wv()}),t(Ot,{children:xv()})]})})]})})}S();var Or=(e)=>o("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",...e,children:[t("path",{d:"M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"}),t("path",{d:"M9 18c-4.51 2-5-2-7-2"})]}),Es=({teamId:e})=>{let r=Q(),{canAdmin:a}=Dt(),[l,s]=u(!1),[d,c]=u(!1),[g,_]=u(!1),[p,b]=u(null),{data:x,isLoading:m}=Z({queryKey:["teams",e,"skills"],queryFn:async()=>{let k=await A.api.teams[":teamId"].skills.$get({param:{teamId:e}});if(!k.ok)throw Error(Jo());return await k.json()}}),i=B({mutationFn:async(k)=>{if(!(await A.api.skills[":id"].$delete({param:{id:k}})).ok)throw Error(Na())},onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"skills"]}),_(!1)}}),v=B({mutationFn:async({id:k,permission:z})=>{if(!(await A.api.skills[":id"].permission.$patch({param:{id:k},json:{permission:z}})).ok)throw Error(bl())},onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"skills"]})},onError:(k)=>{alert(k.message||bl())}}),w=x?.skills||[];return o(ut,{children:[o(Tt,{className:"flex flex-row items-center justify-between space-y-0 pb-7",children:[o("div",{className:"flex items-center gap-3",children:[t("div",{className:"p-2 bg-primary/10 text-primary rounded-lg",children:t(Nt,{className:"w-6 h-6"})}),o("div",{children:[t(Mt,{className:"text-xl font-bold",children:cA()}),t(Ot,{children:kI()})]})]}),o(E,{onClick:()=>s(!0),className:"gap-2",children:[t(pe,{className:"w-4 h-4"})," ",t0()]})]}),t(xt,{children:m?t("div",{className:"flex justify-center py-10",children:t(O,{className:"w-8 h-8 animate-spin text-primary"})}):w.length===0?o("div",{className:"text-center py-12 border-2 border-dashed border-border rounded-xl",children:[t("div",{className:"mx-auto w-12 h-12 bg-muted rounded-full flex items-center justify-center mb-4 text-muted-foreground",children:t(Nt,{className:"w-6 h-6"})}),t("h3",{className:"text-lg font-medium text-foreground",children:mS()}),t("p",{className:"text-muted-foreground mt-1 max-w-xs mx-auto",children:r0()})]}):t("div",{className:"space-y-4",children:w.map((k)=>t($r,{skill:k,canAdmin:a,onDelete:()=>{b(k),_(!0)},onConfigure:()=>{b(k),c(!0)},onPermissionChange:(z)=>v.mutate({id:k.id,permission:z})},k.id))})}),t(Qr,{open:l,onOpenChange:s,teamId:e}),p&&t(zr,{open:d,onOpenChange:(k)=>{if(c(k),!k)setTimeout(()=>{document.body.style.pointerEvents="auto"},100)},teamId:e,skill:p}),t(Je,{open:g,onOpenChange:_,children:o(Xe,{children:[o(et,{children:[t(rt,{children:dd()}),t(nt,{children:Xy({name:p?.name??""})})]}),o(tt,{children:[t(st,{children:De()}),o(ot,{className:"bg-destructive hover:bg-destructive/90 text-destructive-foreground",onClick:()=>{if(p)i.mutate(p.id)},children:[i.isPending?t(O,{className:"w-4 h-4 animate-spin mr-2"}):t(we,{className:"w-4 h-4 mr-2"}),at()]})]})]})})]})},$r=({skill:e,canAdmin:r,onDelete:a,onConfigure:l,onPermissionChange:s})=>o("div",{className:"p-4 bg-card rounded-xl border border-border flex flex-col justify-between hover:shadow-md transition-all group cursor-pointer",onClick:l,children:[o("div",{children:[o("div",{className:"flex items-start justify-between mb-2",children:[t("h4",{className:"font-bold text-foreground flex items-center gap-2",children:e.name}),o(he,{children:[t(ge,{asChild:!0,onClick:(d)=>d.stopPropagation(),children:t(E,{variant:"ghost",size:"icon",className:"h-8 w-8",children:t(Sr,{className:"w-4 h-4"})})}),t(Ae,{align:"end",className:"w-32",children:o(K,{onClick:(d)=>{d.stopPropagation(),a()},className:"text-destructive focus:text-destructive gap-2 cursor-pointer",children:[t(we,{className:"w-4 h-4"})," ",at()]})})]})]}),t("p",{className:"text-sm text-muted-foreground line-clamp-2",children:e.description||ug()})]}),o("div",{className:"mt-4 flex items-center justify-between gap-2 pt-2 border-t border-border/50 text-xs",children:[o("span",{className:"text-[10px] text-muted-foreground uppercase tracking-wider font-semibold",children:[wA()," ",new Date(e.updatedAt).toLocaleDateString()]}),t("div",{className:"flex items-center gap-2",onClick:(d)=>d.stopPropagation(),children:o(Le,{value:e.permission||"reviewer",onValueChange:(d)=>s(d),disabled:!r,children:[t(Be,{className:"h-7 text-xs px-2 bg-background border-border w-[140px]",children:t(Ze,{placeholder:Dp()})}),o(Ue,{align:"end",children:[t(ne,{value:"reviewer",children:Fa()}),t(ne,{value:"editor",children:La()}),t(ne,{value:"owner",children:Za()})]})]})})]})]}),Qr=({open:e,onOpenChange:r,teamId:a})=>{let l=Q(),[s,d]=u(""),[c,g]=u(!1),_=y(null),{data:p}=Z({queryKey:["teams",a,"projects"],queryFn:async()=>{let m=await A.api.teams[":teamId"].projects.$get({param:{teamId:a},query:{first:"1"}});if(!m.ok)throw Error("Failed to fetch projects");return await m.json()},enabled:e}),b=async(m)=>{g(!0);try{let i=await A.api.teams[":teamId"].skills.$post({param:{teamId:a},json:m});if(i.status===409){let v=await i.json();if(window.confirm(`${v.error}
|
|
2
2
|
|
|
3
3
|
${$S()}`)){await b({...m,override:!0});return}}else if(!i.ok){let v=await i.json().catch(()=>({}));throw Error(v.error||Jb())}else l.invalidateQueries({queryKey:["teams",a,"skills"]}),r(!1),d("")}catch(i){if(i instanceof Error)alert(i.message);else alert(cd())}finally{g(!1)}},x=async(m)=>{if(!m||m.length===0)return;let i=p?.data?.[0]?.id;if(!i){alert(Zx());return}let v=m[0];if(!v.name.toLowerCase().endsWith(".zip")){alert(SS());return}g(!0);try{let w=v.name,k=v.type||"application/zip",z=await A.api.projects[":projectId"].attachments.$post({param:{projectId:i},json:{fileName:w,size:v.size,contentType:k}});if(!z.ok)throw Error("Failed to get upload URL");let{id:J,uploadUrl:H}=await z.json();if(!(await fetch(H,{method:"PUT",body:v,headers:{"Content-Type":k}})).ok)throw Error("Failed to upload file to storage");await b({assetId:J})}catch(w){if(w instanceof Error)alert(w.message);else alert(cd())}finally{g(!1)}};return t(ue,{open:e,onOpenChange:r,children:o(ae,{className:"sm:max-w-[450px]",children:[o(fe,{children:[t(le,{children:XA()}),t(It,{children:uw()})]}),o("div",{className:"space-y-6 pt-4",children:[o("div",{className:"space-y-3",children:[t(W,{children:GS()}),o("div",{onClick:()=>!c&&_.current?.click(),className:C("group relative h-32 border-2 border-dashed rounded-xl flex flex-col items-center justify-center transition-all cursor-pointer",c?"opacity-50 cursor-not-allowed bg-muted/50 border-border":"hover:bg-primary/5 hover:border-primary/50 border-border"),children:[t("input",{type:"file",ref:_,className:"hidden",accept:".zip",onChange:(m)=>x(m.target.files)}),t("div",{className:"p-3 bg-muted rounded-full group-hover:bg-primary/10 transition-colors",children:t(lo,{className:"w-6 h-6 text-muted-foreground group-hover:text-primary"})}),o("div",{className:"mt-3 text-center",children:[t("p",{className:"text-sm font-medium text-foreground",children:aI()}),t("p",{className:"text-[10px] text-muted-foreground mt-1 uppercase tracking-wider font-semibold",children:VS()})]})]}),c&&!s&&o("div",{className:"flex items-center gap-2 text-sm text-primary justify-center bg-primary/10 py-2 rounded-lg animate-pulse",children:[t(O,{className:"w-4 h-4 animate-spin"}),mE()]})]}),o("div",{className:"relative",children:[t("div",{className:"absolute inset-0 flex items-center",children:t("span",{className:"w-full border-t border-border"})}),t("div",{className:"relative flex justify-center text-xs uppercase",children:t("span",{className:"bg-background px-2 text-muted-foreground font-bold",children:gg()})})]}),t("div",{className:"space-y-4",children:o("div",{className:"space-y-2",children:[t(W,{htmlFor:"githubUrl",children:Zv()}),o("div",{className:"flex gap-2",children:[o("div",{className:"relative flex-1",children:[t(Or,{className:"absolute left-3 top-2.5 w-4 h-4 text-muted-foreground"}),t(q,{id:"githubUrl",placeholder:"https://github.com/owner/repo",value:s,onChange:(m)=>d(m.target.value),disabled:c,className:"pl-9"})]}),t(E,{onClick:()=>b({githubUrl:s}),disabled:!s||c,className:"px-6",children:c&&s?t(O,{className:"w-4 h-4 animate-spin"}):fw()})]}),t("p",{className:"text-[10px] text-muted-foreground italic",children:Bv()})]})})]})]})})},zr=({open:e,onOpenChange:r,teamId:a,skill:l})=>{let s=Q(),[d,c]=u({...l.config||{},environmentVariables:l.config?.environmentVariables||[]}),[g,_]=u(!1),p=(w,k)=>{let z=[...d.environmentVariables];z[w]={...z[w],default:k},c({...d,environmentVariables:z})},b=(w,k)=>{let z=[...d.environmentVariables];z[w]={...z[w],name:k},c({...d,environmentVariables:z})},x=()=>{c({...d,environmentVariables:[...d.environmentVariables,{name:"",default:""}]})},m=(w)=>{let k=[...d.environmentVariables];k.splice(w,1),c({...d,environmentVariables:k})},i=async()=>{let w=d.environmentVariables.filter((z)=>z.name.trim()!==""),k={...d,environmentVariables:w};_(!0);try{let z=await A.api.skills[":id"].config.$patch({param:{id:l.id},json:{config:k}});if(!z.ok){let J=await z.json().catch(()=>({}));throw Error(J.error||"Failed to update config")}s.invalidateQueries({queryKey:["teams",a,"skills"]}),r(!1)}catch(z){if(z instanceof Error)alert(z.message);else alert(cd())}finally{_(!1)}},v=d?.environmentVariables||[];return t(ue,{open:e,onOpenChange:r,children:o(ae,{className:"sm:max-w-[500px]",children:[o(fe,{children:[t("div",{className:"flex items-center justify-between",children:o(le,{className:"flex items-center gap-2",children:[t(Jl,{className:"w-5 h-5 text-primary"}),Y_({name:l.name})]})}),t(It,{children:Rw()})]}),t(ce,{className:"max-h-[60vh]",children:t("div",{className:"py-4 space-y-4 pr-4",children:v.length===0?t("div",{className:"text-center py-10 bg-muted/50 rounded-xl border border-dashed border-border",children:t("p",{className:"text-muted-foreground text-sm italic",children:tS()})}):v.map((w,k)=>o("div",{className:"p-4 bg-muted/50 rounded-xl border border-border space-y-3 relative group",children:[t("button",{onClick:()=>m(k),className:"absolute top-2 right-2 p-1 text-muted-foreground hover:text-destructive hover:bg-destructive/10 rounded-md transition-colors opacity-0 group-hover:opacity-100",children:t(Ne,{className:"w-4 h-4"})}),o("div",{className:"space-y-1.5",children:[t(W,{className:"text-[10px] uppercase tracking-wider font-bold text-muted-foreground",children:f1()}),t(q,{value:w.name,onChange:(z)=>b(k,z.target.value),placeholder:"e.g. API_KEY",className:"h-8 bg-background border-border text-sm font-mono"})]}),o("div",{className:"space-y-1.5",children:[t(W,{className:"text-[10px] uppercase tracking-wider font-bold text-muted-foreground",children:By()}),t(q,{value:w.default||"",onChange:(z)=>p(k,z.target.value),placeholder:jS(),className:"h-8 bg-background border-border text-sm"}),t("p",{className:"text-[10px] text-muted-foreground italic",children:Nb()})]})]},k))})}),o(qe,{className:"flex items-center justify-between sm:justify-between w-full pt-2 border-t border-border",children:[o(E,{variant:"ghost",size:"sm",onClick:x,className:"h-8 gap-1.5 text-primary hover:text-primary hover:bg-primary/10",children:[t(pe,{className:"w-3.5 h-3.5"})," ",i0()]}),o("div",{className:"flex gap-2",children:[t(E,{variant:"ghost",onClick:()=>r(!1),children:De()}),o(E,{onClick:i,disabled:g,className:"px-8",children:[g?t(O,{className:"w-4 h-4 animate-spin mr-2"}):null,qs()]})]})]})]})})};S();S();var Vs=({isOpen:e,onClose:r,teamId:a,server:l})=>{let s=Q(),d=!!l,[c,g]=u(""),[_,p]=u("streamable_http"),[b,x]=u("reviewer"),[m,i]=u("auto"),[v,w]=u(""),[k,z]=u(""),[J,H]=u(""),[ie,oe]=u(""),[T,P]=u("authorization_code"),[j,X]=u([]),[F,Y]=u([]),[ye,me]=u({}),[Ee,Fe]=u(!1);h(()=>{if(l)g(l.url),p(l.transport||"streamable_http"),x(l.permission||"reviewer"),i(l.authType||"auto"),X(Array.isArray(l.config?.directTools)?l.config.directTools:[]),Y(l.config?.excludeTools??[]),me({}),Fe(!1);else g(""),p("streamable_http"),x("reviewer"),i("auto"),w(""),z(""),H(""),oe(""),P("authorization_code"),X([]),Y([]),me({}),Fe(!1)},[l,e]);let se=()=>{if(m==="none")return{type:"none"};if(m==="bearer")return{type:"bearer",bearerToken:v||void 0};if(m==="oauth")return{type:"oauth",oauth:{grantType:T,clientId:k||void 0,clientSecret:J||void 0,scope:ie||void 0}};return},{data:ke,isLoading:je,refetch:He}=Z({queryKey:["mcp","servers",l?.id,"tools"],queryFn:async()=>{if(!l?.id)return{tools:[]};let U=await A.api.mcp.servers[":id"].tools.$get({param:{id:l.id}});if(!U.ok)throw Error("Failed to fetch tools");return await U.json()},enabled:e&&d&&!!l?.id}),G=B({mutationFn:async()=>{if(!l?.id)return;let U=await A.api.mcp.servers[":id"].refresh.$post({param:{id:l.id}});if(!U.ok){let _e=await U.json().catch(()=>({}));throw Error(_e.error||"Failed to refresh server")}return await U.json()},onSuccess:()=>{M.success(Jw()),He(),s.invalidateQueries({queryKey:["teams",a,"mcp","servers"]})},onError:(U)=>{M.error(U.message)}}),ee=B({mutationFn:async()=>{let U={directTools:j.length>0?j:void 0,excludeTools:F.length>0?F:void 0};if(d&&l){let _e={transport:_,permission:b,authConfig:se(),config:U},Se=await A.api.mcp.servers[":id"].$patch({param:{id:l.id},json:_e});if(!Se.ok){let ct=await Se.json().catch(()=>({}));throw Error(ct.error||bl())}return await Se.json()}else{let _e={url:c.trim()},Se=await A.api.teams[":teamId"].mcp.servers.$post({param:{teamId:a},json:_e});if(!Se.ok){let Qt=await Se.json().catch(()=>({}));throw Error(Qt.error||cd())}return await Se.json()}},onSuccess:()=>{M.success(d?Cg():Hc()),s.invalidateQueries({queryKey:["teams",a,"mcp","servers"]}),r()},onError:(U)=>{M.error(U.message)}}),xe=(U)=>{if(U.preventDefault(),!c.trim())return;ee.mutate()},de=ke?.tools??[],Ke=(U)=>{if(F.includes(U))return"off";if(j.includes(U))return"direct";return"on"},bt=(U,_e)=>{if(_e==="off")Y((Se)=>Se.includes(U)?Se:[...Se,U]),X((Se)=>Se.filter((ct)=>ct!==U));else if(_e==="on")Y((Se)=>Se.filter((ct)=>ct!==U)),X((Se)=>Se.filter((ct)=>ct!==U));else if(_e==="direct")Y((Se)=>Se.filter((ct)=>ct!==U)),X((Se)=>Se.includes(U)?Se:[...Se,U])},re=(U)=>{let _e=de.map((Se)=>Se.name);if(U==="off")Y(_e),X([]);else if(U==="on")Y([]),X([]);else if(U==="direct")Y([]),X(_e)},Ye=(U)=>{me((_e)=>({..._e,[U]:!_e[U]}))};return t(ue,{open:e,onOpenChange:(U)=>!U&&r(),children:d&&l?o(ae,{className:"sm:max-w-2xl h-[85vh] flex flex-col p-0 overflow-hidden",children:[G.isPending&&o("div",{className:"absolute inset-0 bg-background/60 backdrop-blur-[1px] flex flex-col items-center justify-center z-50 rounded-lg",children:[t(O,{className:"w-8 h-8 animate-spin text-primary mb-2"}),o("span",{className:"text-xs font-medium text-muted-foreground",children:[Qh(),"..."]})]}),o(fe,{className:"p-6 pb-4 border-b border-border flex-shrink-0",children:[o(le,{className:"flex items-center gap-2 text-xl font-bold",children:[t(vn,{className:"w-5 h-5 text-primary"}),fb()]}),t(It,{children:xd()})]}),o("form",{onSubmit:xe,className:"flex-1 flex flex-col min-h-0 overflow-hidden",children:[t(ce,{className:"flex-1 min-h-0",children:o("div",{className:"p-6 space-y-5",children:[o("div",{className:"grid grid-cols-1 gap-3 p-3 bg-muted/30 border border-border rounded-lg",children:[o("div",{className:"flex flex-col",children:[t("span",{className:"text-[10px] uppercase tracking-wider text-muted-foreground font-semibold",children:ex()}),t("span",{className:"text-sm font-medium",children:l.name})]}),o("div",{className:"flex flex-col",children:[t("span",{className:"text-[10px] uppercase tracking-wider text-muted-foreground font-semibold",children:Wh()}),t("span",{className:"text-sm font-mono text-foreground break-all",children:l.url})]}),l.description&&o("div",{className:"flex flex-col",children:[t("span",{className:"text-[10px] uppercase tracking-wider text-muted-foreground font-semibold",children:yl()}),t("span",{className:"text-sm text-foreground",children:l.description})]}),o("span",{className:"text-[10px] text-muted-foreground flex items-center gap-1.5",children:[t(Wo,{className:"w-3 h-3"}),Kh()]})]}),l.instructions&&o("div",{className:"p-3 bg-muted/20 border border-border rounded-lg space-y-1",children:[t("span",{className:"text-[10px] uppercase tracking-wider text-muted-foreground font-semibold block",children:Xw()}),t("p",{onClick:()=>Fe((U)=>!U),className:`text-xs text-muted-foreground whitespace-pre-wrap leading-relaxed cursor-pointer transition-all ${Ee?"":"line-clamp-2"}`,title:Ee?void 0:"Click to expand instructions",children:l.instructions})]}),o("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 pt-3 border-t border-border",children:[o("div",{className:"space-y-1.5",children:[t(W,{className:"text-xs",children:ux()}),o(Le,{value:_,onValueChange:(U)=>p(U),children:[t(Be,{className:"h-9 text-xs",children:t(Ze,{})}),o(Ue,{children:[t(ne,{value:"streamable_http",children:"Streamable HTTP"}),t(ne,{value:"sse",children:"Server-Sent Events (SSE)"})]})]})]}),o("div",{className:"space-y-1.5",children:[t(W,{className:"text-xs",children:Dp()}),o(Le,{value:b,onValueChange:(U)=>x(U),children:[t(Be,{className:"h-9 text-xs",children:t(Ze,{})}),o(Ue,{children:[t(ne,{value:"reviewer",children:Fa()}),t(ne,{value:"editor",children:La()}),t(ne,{value:"owner",children:Za()})]})]})]})]}),o("div",{className:"space-y-3 pt-3 border-t border-border",children:[o("div",{className:"space-y-1.5",children:[t(W,{className:"text-xs",children:qw()}),o(Le,{value:m,onValueChange:(U)=>i(U),children:[t(Be,{className:"h-9 text-xs",children:t(Ze,{})}),o(Ue,{children:[t(ne,{value:"auto",children:Bw()}),t(ne,{value:"none",children:zw()}),t(ne,{value:"bearer",children:Uw()}),t(ne,{value:"oauth",children:jw()})]})]})]}),m==="bearer"&&o("div",{className:"space-y-1.5",children:[t(W,{className:"text-xs",children:Hw()}),t(q,{className:"h-9 text-xs font-mono",type:"password",value:v,onChange:(U)=>w(U.target.value),placeholder:"Enter token string"})]}),m==="oauth"&&o("div",{className:"p-3 bg-muted/20 border border-border rounded-lg space-y-3",children:[o("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[o("div",{className:"space-y-1.5",children:[t(W,{className:"text-xs",children:Ww()}),o(Le,{value:T,onValueChange:(U)=>P(U),children:[t(Be,{className:"h-9 text-xs",children:t(Ze,{})}),o(Ue,{children:[t(ne,{value:"authorization_code",children:"Authorization Code"}),t(ne,{value:"client_credentials",children:"Client Credentials"})]})]})]}),o("div",{className:"space-y-1.5",children:[t(W,{className:"text-xs",children:Qw()}),t(q,{className:"h-9 text-xs",value:k,onChange:(U)=>z(U.target.value),placeholder:"Optional Client ID"})]})]}),o("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[o("div",{className:"space-y-1.5",children:[t(W,{className:"text-xs",children:Kw()}),t(q,{className:"h-9 text-xs",type:"password",value:J,onChange:(U)=>H(U.target.value),placeholder:"Optional Secret"})]}),o("div",{className:"space-y-1.5",children:[t(W,{className:"text-xs",children:Yw()}),t(q,{className:"h-9 text-xs",value:ie,onChange:(U)=>oe(U.target.value),placeholder:"Optional scope"})]})]})]})]}),o("div",{className:"space-y-3 pt-3 border-t border-border",children:[o("div",{className:"space-y-2.5",children:[o(W,{className:"text-xs font-semibold flex items-center gap-1.5",children:[t(Io,{className:"w-3.5 h-3.5"}),ax()," (",de.length,")"]}),t("p",{className:"text-[11px] text-muted-foreground leading-relaxed",children:cx()}),de.length>0&&o("div",{className:"flex items-center gap-1.5 pt-0.5",children:[t(E,{type:"button",variant:"outline",size:"sm",className:"h-7 text-[11px] px-2.5",onClick:()=>re("off"),disabled:G.isPending||je,children:Gw()}),t(E,{type:"button",variant:"outline",size:"sm",className:"h-7 text-[11px] px-2.5",onClick:()=>re("on"),disabled:G.isPending||je,children:Vw()}),t(E,{type:"button",variant:"outline",size:"sm",className:"h-7 text-[11px] px-2.5",onClick:()=>re("direct"),disabled:G.isPending||je,children:$w()})]})]}),t("div",{className:"space-y-2",children:je?t("div",{className:"flex justify-center py-8",children:t(O,{className:"w-6 h-6 animate-spin text-primary"})}):de.length===0?t("div",{className:"text-center py-6 text-muted-foreground text-xs",children:AS()}):de.map((U)=>{let _e=Ke(U.name),Se=!!ye[U.name],ct=U.inputSchema,Qt=ct?.properties&&Object.keys(ct.properties).length>0;return o("div",{className:`border border-border rounded-lg p-3 transition-colors ${_e!=="off"?"bg-card":"bg-muted/30 opacity-70"}`,children:[o("div",{className:"flex items-start justify-between gap-3",children:[o("div",{className:"flex items-start gap-2 flex-1 min-w-0 cursor-pointer",onClick:()=>Qt&&Ye(U.name),children:[Qt?Se?t(ve,{className:"w-4 h-4 text-muted-foreground mt-0.5 shrink-0"}):t(vt,{className:"w-4 h-4 text-muted-foreground mt-0.5 shrink-0"}):t("div",{className:"w-4 h-4 shrink-0"}),o("div",{className:"min-w-0 flex-1",children:[o("div",{className:"flex items-center gap-2 flex-wrap",children:[t("span",{className:"font-mono text-xs font-bold text-foreground break-all",children:U.name}),U.title&&t(be,{variant:"outline",className:"text-[10px]",children:U.title})]}),U.description&&t("p",{className:"text-xs text-muted-foreground mt-1 break-words line-clamp-3",children:U.description})]})]}),t("div",{className:"flex items-center gap-2 shrink-0",children:o(Mo,{type:"single",value:_e,onValueChange:(Kt)=>{if(Kt)bt(U.name,Kt)},size:"sm",variant:"outline",disabled:G.isPending||je,children:[t(_r,{value:"off",className:"text-[11px] px-2 h-7",children:sx()}),t(_r,{value:"on",className:"text-[11px] px-2 h-7",children:ix()}),t(_r,{value:"direct",className:"text-[11px] px-2 h-7",children:ox()})]})})]}),Se&&Qt&&o("div",{className:"mt-3 pt-3 border-t border-border/60 pl-6 space-y-2",children:[t("span",{className:"text-[11px] font-semibold text-muted-foreground uppercase tracking-wider",children:VT()}),t("div",{className:"grid grid-cols-1 gap-1.5",children:Object.entries(ct.properties).map(([Kt,ka])=>{let Ys=ct.required?.includes(Kt);return o("div",{className:"flex flex-col sm:flex-row sm:items-baseline justify-between gap-1 sm:gap-2 p-2 bg-muted/20 rounded text-xs min-w-0",children:[o("div",{className:"flex items-center gap-1.5 flex-wrap min-w-0",children:[t("span",{className:"font-mono font-semibold break-all",children:Kt}),Ys&&t("span",{className:"text-[10px] text-red-500 font-bold",children:"*"}),t(be,{variant:"secondary",className:"text-[9px] px-1 py-0",children:ka.type||"any"})]}),ka.description&&t("span",{className:"text-[11px] text-muted-foreground break-words sm:max-w-[320px]",children:ka.description})]},Kt)})})]})]},U.name)})})]})]})}),o(qe,{className:"p-6 pt-4 border-t border-border flex-shrink-0",children:[o(E,{type:"button",variant:"outline",onClick:()=>G.mutate(),disabled:G.isPending||je||ee.isPending,className:"gap-1.5 mr-auto",children:[t(ua,{className:`w-4 h-4 ${G.isPending?"animate-spin":""}`}),Qh()]}),t(E,{type:"button",variant:"outline",onClick:r,children:De()}),o(E,{type:"submit",disabled:ee.isPending||!c,children:[ee.isPending&&t(O,{className:"w-4 h-4 mr-2 animate-spin"}),qs()]})]})]})]}):o(ae,{className:"sm:max-w-md",children:[o(fe,{children:[o(le,{className:"flex items-center gap-2 text-xl font-bold",children:[t(vn,{className:"w-5 h-5 text-primary"}),xf()]}),t(It,{children:xd()})]}),o("form",{onSubmit:xe,className:"space-y-4",children:[o("div",{className:"space-y-2",children:[t(W,{className:"text-xs font-semibold",children:Wh()}),t(q,{value:c,onChange:(U)=>g(U.target.value),placeholder:"https://mcp.example.com/mcp",type:"url",required:!0}),o("p",{className:"text-[11px] text-muted-foreground flex items-center gap-1.5",children:[t(Wo,{className:"w-3.5 h-3.5"}),Kh()]})]}),o(qe,{children:[t(E,{type:"button",variant:"outline",onClick:r,children:De()}),o(E,{type:"submit",disabled:ee.isPending||!c,children:[ee.isPending&&t(O,{className:"w-4 h-4 mr-2 animate-spin"}),Zc()]})]})]})]})})};var Ls=({teamId:e})=>{let r=Q(),{canAdmin:a}=Dt(),[l,s]=u(!1),[d,c]=u(null),[g,_]=u(null),[p,b]=u(null),{data:x,isLoading:m}=Z({queryKey:["teams",e,"mcp","servers"],queryFn:async()=>{let H=await A.api.teams[":teamId"].mcp.servers.$get({param:{teamId:e}});if(!H.ok)throw Error(Jo());return await H.json()}}),i=B({mutationFn:async(H)=>{if(!(await A.api.mcp.servers[":id"].$delete({param:{id:H}})).ok)throw Error(Na())},onSuccess:()=>{M.success(at()),r.invalidateQueries({queryKey:["teams",e,"mcp","servers"]}),_(null)},onError:(H)=>{M.error(H.message)}}),v=B({mutationFn:async({id:H,permission:ie})=>{if(!(await A.api.mcp.servers[":id"].permission.$patch({param:{id:H},json:{permission:ie}})).ok)throw Error(bl())},onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"mcp","servers"]})},onError:(H)=>{M.error(H.message)}}),w=B({mutationFn:async(H)=>{if(!(await A.api.mcp.servers[":id"].auth.$delete({param:{id:H}})).ok)throw Error("Failed to disconnect auth")},onSuccess:()=>{M.success(Vh()),r.invalidateQueries({queryKey:["teams",e,"mcp","servers"]})},onError:(H)=>{M.error(H.message)}}),k=async(H)=>{b(H);try{let ie=await A.api.mcp.servers[":id"].auth.start.$post({param:{id:H}});if(!ie.ok){let T=await ie.json().catch(()=>({}));throw Error(T.error||ep())}let oe=await ie.json();if(oe.status==="authenticated"){M.success($h()),r.invalidateQueries({queryKey:["teams",e,"mcp","servers"]}),b(null);return}if(oe.authorizationUrl){let j=window.screenX+(window.outerWidth-600)/2,X=window.screenY+(window.outerHeight-700)/2,F=window.open(oe.authorizationUrl,"mcp_oauth_popup",`width=600,height=700,left=${j},top=${X},scrollbars=yes`),Y=(me)=>{if(me.data?.type==="mcp-oauth-callback")if(window.removeEventListener("message",Y),b(null),me.data.ok)M.success($h()),r.invalidateQueries({queryKey:["teams",e,"mcp","servers"]});else M.error(me.data.message||ep())};window.addEventListener("message",Y);let ye=setInterval(()=>{if(!F||F.closed)clearInterval(ye),window.removeEventListener("message",Y),b(null),r.invalidateQueries({queryKey:["teams",e,"mcp","servers"]})},1000)}}catch(ie){M.error(ie instanceof Error?ie.message:ep()),b(null)}},z=x?.servers||[],J=(H)=>{switch(H.status){case"connected":return o(be,{variant:"secondary",className:"gap-1 bg-emerald-500/10 text-emerald-600 border-emerald-500/20 text-[10px]",children:[t(xr,{className:"w-3 h-3"}),tx()]});case"needs_auth":return o(be,{variant:"secondary",className:"gap-1 bg-amber-500/10 text-amber-600 border-amber-500/20 text-[10px]",children:[t(Xt,{className:"w-3 h-3"}),Yh()]});case"failed":return o(be,{variant:"secondary",className:"gap-1 bg-red-500/10 text-red-600 border-red-500/20 text-[10px]",children:[t(fr,{className:"w-3 h-3"}),rx()]});default:return o(be,{variant:"outline",className:"gap-1 text-[10px]",children:[t(er,{className:"w-3 h-3 text-muted-foreground"}),nx()]})}};return o(ut,{children:[o(Tt,{className:"flex flex-row items-center justify-between space-y-0 pb-7",children:[o("div",{className:"flex items-center gap-3",children:[t("div",{className:"p-2 bg-primary/10 text-primary rounded-lg",children:t(vn,{className:"w-6 h-6"})}),o("div",{children:[t(Mt,{className:"text-xl font-bold",children:Hc()}),t(Ot,{children:xd()})]})]}),a&&o(E,{onClick:()=>s(!0),className:"gap-2",children:[t(pe,{className:"w-4 h-4"})," ",xf()]})]}),t(xt,{children:m?t("div",{className:"flex justify-center py-10",children:t(O,{className:"w-8 h-8 animate-spin text-primary"})}):z.length===0?o("div",{className:"text-center py-12 border-2 border-dashed border-border rounded-xl",children:[t("div",{className:"mx-auto w-12 h-12 bg-muted rounded-full flex items-center justify-center mb-4 text-muted-foreground",children:t(vn,{className:"w-6 h-6"})}),t("h3",{className:"text-base font-semibold",children:pg()}),t("p",{className:"text-xs text-muted-foreground mt-1 max-w-sm mx-auto",children:KA()}),a&&o(E,{onClick:()=>s(!0),className:"mt-4 gap-2",variant:"outline",children:[t(pe,{className:"w-4 h-4"})," ",xf()]})]}):t("div",{className:"space-y-4",children:z.map((H)=>{let ie=p===H.id,oe=H.status==="needs_auth"||!H.hasCredential&&H.authType!=="none";return o("div",{onClick:()=>a&&c(H),className:`p-4 bg-card rounded-xl border border-border flex flex-col justify-between hover:shadow-md transition-all group ${a?"cursor-pointer":""}`,children:[o("div",{className:"flex items-start justify-between gap-2 mb-2",children:[o("h4",{className:"font-bold text-foreground flex items-center gap-2 min-w-0",children:[t(vn,{className:"w-4 h-4 text-muted-foreground shrink-0"}),t("span",{className:"truncate",children:H.name}),t(be,{variant:"outline",className:"text-[10px] uppercase shrink-0",children:H.transport})]}),a&&o(he,{modal:!1,children:[t(ge,{asChild:!0,onClick:(T)=>T.stopPropagation(),children:t(E,{variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0",children:t(Sr,{className:"w-4 h-4"})})}),o(Ae,{align:"end",children:[H.status!=="connected"&&(H.authType!=="none"||H.hasCredential)?o(K,{onClick:(T)=>{T.stopPropagation(),k(H.id)},children:[t(Xt,{className:"w-4 h-4 mr-2"}),Gh()]}):null,H.hasCredential&&o(K,{onClick:(T)=>{T.stopPropagation(),w.mutate(H.id)},className:"text-amber-600",children:[t(rs,{className:"w-4 h-4 mr-2"}),Vh()]}),(H.status!=="connected"&&(H.authType!=="none"||H.hasCredential)||H.hasCredential)&&t(Vt,{}),o(K,{onClick:(T)=>{T.stopPropagation(),_(H)},className:"text-red-600",children:[t(we,{className:"w-4 h-4 mr-2"}),at()]})]})]})]}),o("div",{className:"space-y-1",children:[t("p",{className:"text-sm text-muted-foreground line-clamp-2",children:H.description||ug()}),t("p",{className:"font-mono text-[10px] text-muted-foreground/70 truncate",children:H.url}),H.lastError&&t("p",{className:"text-[10px] text-red-500/90 truncate font-mono",children:H.lastError})]}),o("div",{className:"mt-4 flex items-center justify-between gap-2 pt-2 border-t border-border/50 text-xs",children:[o("div",{className:"flex items-center gap-2 min-w-0",children:[J(H),o(be,{variant:"outline",className:"text-[10px] gap-1 shrink-0",children:[t(Io,{className:"w-3 h-3 text-muted-foreground"}),lx({count:H.toolCount})]}),o("span",{className:"text-[10px] text-muted-foreground uppercase tracking-wider font-semibold whitespace-nowrap",children:[wA()," ",new Date(H.updatedAt).toLocaleDateString()]})]}),o("div",{className:"flex items-center gap-2 shrink-0",onClick:(T)=>T.stopPropagation(),children:[a?o(Le,{value:H.permission,onValueChange:(T)=>v.mutate({id:H.id,permission:T}),children:[t(Be,{className:"h-7 text-xs px-2 bg-background border-border w-[130px]",children:t(Ze,{})}),o(Ue,{align:"end",children:[t(ne,{value:"reviewer",children:Fa()}),t(ne,{value:"editor",children:La()}),t(ne,{value:"owner",children:Za()})]})]}):t(be,{variant:"outline",className:"text-[10px]",children:H.permission==="reviewer"?Fa():H.permission==="editor"?La():Za()}),oe&&a&&o(E,{size:"sm",variant:"default",onClick:(T)=>{T.stopPropagation(),k(H.id)},disabled:ie,className:"gap-1.5 bg-amber-600 hover:bg-amber-700 text-white text-xs",children:[ie?t(O,{className:"w-3.5 h-3.5 animate-spin"}):t(Xt,{className:"w-3.5 h-3.5"}),Gh()]})]})]})]},H.id)})})}),t(Vs,{isOpen:l||!!d,onClose:()=>{s(!1),c(null)},teamId:e,server:d}),t(Je,{open:!!g,onOpenChange:(H)=>!H&&_(null),children:o(Xe,{children:[o(et,{children:[t(rt,{children:$y()}),t(nt,{children:Gy({name:g?.name||""})})]}),o(tt,{children:[t(st,{children:De()}),o(ot,{onClick:()=>g&&i.mutate(g.id),className:"bg-red-600 hover:bg-red-700 text-white",children:[i.isPending&&t(O,{className:"w-4 h-4 mr-2 animate-spin"}),at()]})]})]})})]})};function Ps({teamId:e}){let r=Q(),{data:a,isLoading:l}=Z({queryKey:["teams",e,"notification-settings"],queryFn:async()=>{let g=await A.api.teams[":teamId"].notifications.settings.$get({param:{teamId:e}});if(!g.ok)throw Error(Jo());return await g.json()}}),{mutate:s,isPending:d}=B({mutationFn:async(g)=>{let _=await A.api.teams[":teamId"].notifications.settings.$post({param:{teamId:e},json:g});if(!_.ok)throw Error(kh());return await _.json()},onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"notification-settings"]}),r.invalidateQueries({queryKey:["teams",e,"notifications"]}),M.success(vS())},onError:(g)=>{M.error(g instanceof Error?g.message:kh())}}),c=(g)=>{if(!a)return;let _={...a,[g]:!a[g]};s(_)};if(l)return t("div",{className:"flex items-center justify-center p-8",children:t(O,{className:"h-8 w-8 animate-spin text-muted-foreground"})});return t(ce,{className:"h-full",children:o("div",{className:"space-y-6 pr-4 pb-8",children:[o(ut,{className:"overflow-hidden gap-0 py-0",children:[o(Tt,{className:"border-b border-border bg-muted/30 py-5",children:[o("div",{className:"flex items-center gap-2",children:[t(vo,{className:"w-5 h-5 text-primary"}),t(Mt,{className:"text-lg",children:V_()})]}),t(Ot,{children:Q_()})]}),o(xt,{className:"divide-y divide-border p-0",children:[o("div",{className:"flex items-center justify-between p-6",children:[o("div",{className:"flex gap-4",children:[t("div",{className:"mt-1 flex items-center justify-center w-8 h-8 rounded-lg bg-muted text-foreground",children:t(vo,{className:"w-4 h-4"})}),o("div",{className:"space-y-0.5",children:[t("h4",{className:"text-sm font-semibold text-foreground",children:Dv()}),t("p",{className:"text-sm text-muted-foreground",children:I1()})]})]}),t(Me,{checked:a?.comments??!0,onCheckedChange:()=>c("comments"),disabled:d})]}),o("div",{className:"flex items-center justify-between p-6",children:[o("div",{className:"flex gap-4",children:[t("div",{className:"mt-1 flex items-center justify-center w-8 h-8 rounded-lg bg-muted text-foreground",children:t(ts,{className:"w-4 h-4"})}),o("div",{className:"space-y-0.5",children:[t("h4",{className:"text-sm font-semibold text-foreground",children:G_()}),t("p",{className:"text-sm text-muted-foreground",children:M1()})]})]}),t(Me,{checked:a?.replies??!0,onCheckedChange:()=>c("replies"),disabled:d})]}),o("div",{className:"flex items-center justify-between p-6",children:[o("div",{className:"flex gap-4",children:[t("div",{className:"mt-1 flex items-center justify-center w-8 h-8 rounded-lg bg-muted text-foreground",children:t(Ya,{className:"w-4 h-4"})}),o("div",{className:"space-y-0.5",children:[t("h4",{className:"text-sm font-semibold text-foreground",children:d_()}),t("p",{className:"text-sm text-muted-foreground",children:T1()})]})]}),t(Me,{checked:a?.mentions??!0,onCheckedChange:()=>c("mentions"),disabled:d})]})]})]}),o(ut,{className:"overflow-hidden gap-0 py-0",children:[o(Tt,{className:"border-b border-border bg-muted/30 py-5",children:[o("div",{className:"flex items-center gap-2",children:[t(zn,{className:"w-5 h-5 text-primary"}),t(Mt,{className:"text-lg",children:c_()})]}),t(Ot,{children:u_()})]}),o(xt,{className:"divide-y divide-border p-0",children:[o("div",{className:"flex items-center justify-between p-6",children:[o("div",{className:"flex gap-4",children:[t("div",{className:"mt-1 flex items-center justify-center w-8 h-8 rounded-lg bg-muted text-foreground",children:t(ha,{className:"w-4 h-4"})}),o("div",{className:"space-y-0.5",children:[t("h4",{className:"text-sm font-semibold text-foreground",children:R1()}),t("p",{className:"text-sm text-muted-foreground",children:k1()})]})]}),t(Me,{checked:a?.yourUploads??!1,onCheckedChange:()=>c("yourUploads"),disabled:d})]}),o("div",{className:"flex items-center justify-between p-6",children:[o("div",{className:"flex gap-4",children:[t("div",{className:"mt-1 flex items-center justify-center w-8 h-8 rounded-lg bg-muted text-foreground",children:t(zn,{className:"w-4 h-4"})}),o("div",{className:"space-y-0.5",children:[t("h4",{className:"text-sm font-semibold text-foreground",children:qS()}),t("p",{className:"text-sm text-muted-foreground",children:E1()})]})]}),t(Me,{checked:a?.otherUploads??!0,onCheckedChange:()=>c("otherUploads"),disabled:d})]}),o("div",{className:"flex items-center justify-between p-6",children:[o("div",{className:"flex gap-4",children:[t("div",{className:"mt-1 flex items-center justify-center w-8 h-8 rounded-lg bg-muted text-foreground",children:t(Qs,{className:"w-4 h-4"})}),o("div",{className:"space-y-0.5",children:[t("h4",{className:"text-sm font-semibold text-foreground",children:YI()}),t("p",{className:"text-sm text-muted-foreground",children:C1()})]})]}),t(Me,{checked:a?.statusUpdates??!0,onCheckedChange:()=>c("statusUpdates"),disabled:d})]})]})]}),o(ut,{className:"overflow-hidden gap-0 py-0",children:[o(Tt,{className:"border-b border-border bg-muted/30 py-5",children:[o("div",{className:"flex items-center gap-2",children:[t(Ma,{className:"w-5 h-5 text-primary"}),t(Mt,{className:"text-lg",children:yw()})]}),t(Ot,{children:_w()})]}),o(xt,{className:"divide-y divide-border p-0",children:[o("div",{className:"flex items-center justify-between p-6",children:[o("div",{className:"flex gap-4",children:[t("div",{className:"mt-1 flex items-center justify-center w-8 h-8 rounded-lg bg-muted text-foreground",children:t(Ma,{className:"w-4 h-4"})}),o("div",{className:"space-y-0.5",children:[t("h4",{className:"text-sm font-semibold text-foreground",children:bw()}),t("p",{className:"text-sm text-muted-foreground",children:S1()})]})]}),t(Me,{checked:a?.kanbanTasks??!0,onCheckedChange:()=>c("kanbanTasks"),disabled:d})]}),o("div",{className:"flex items-center justify-between p-6",children:[o("div",{className:"flex gap-4",children:[t("div",{className:"mt-1 flex items-center justify-center w-8 h-8 rounded-lg bg-muted text-foreground",children:t(vo,{className:"w-4 h-4"})}),o("div",{className:"space-y-0.5",children:[t("h4",{className:"text-sm font-semibold text-foreground",children:Aw()}),t("p",{className:"text-sm text-muted-foreground",children:x1()})]})]}),t(Me,{checked:a?.kanbanComments??!0,onCheckedChange:()=>c("kanbanComments"),disabled:d})]})]})]})]})})}S();function Rs({teamId:e}){let r=Q(),[a,l]=u(""),[s,d]=u(null),{data:c,isLoading:g}=Z({queryKey:["teams",e,"api-tokens"],queryFn:async()=>{let i=await A.api.teams[":teamId"]["api-tokens"].$get({param:{teamId:e}});if(!i.ok)throw Error("Failed to fetch API tokens");return await i.json()}}),{mutate:_,isPending:p}=B({mutationFn:async(i)=>{let v=await A.api.teams[":teamId"]["api-tokens"].$post({param:{teamId:e},json:{name:i}});if(!v.ok)throw Error("Failed to create API token");return await v.json()},onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"api-tokens"]}),l(""),M.success(e_())},onError:(i)=>{M.error(i instanceof Error?i.message:Yb())}}),{mutate:b}=B({mutationFn:async(i)=>{let v=await A.api.teams[":teamId"]["api-tokens"][":tokenId"].$delete({param:{teamId:e,tokenId:i}});if(!v.ok)throw Error("Failed to delete API token");return await v.json()},onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"api-tokens"]}),M.success(t_())},onError:(i)=>{M.error(i instanceof Error?i.message:rv())}}),x=(i)=>{if(i.preventDefault(),!a.trim())return;_(a.trim())},m=async(i,v)=>{await co(v),d(i),M.success(sy()),setTimeout(()=>d(null),2000)};if(g)return t("div",{className:"flex justify-center items-center p-8",children:t(O,{className:"w-8 h-8 animate-spin text-muted-foreground"})});return t("div",{className:"space-y-6",children:o(ut,{children:[o(Tt,{children:[t(Mt,{children:Ym()}),t(Ot,{children:r_()})]}),o(xt,{className:"space-y-6",children:[o("form",{onSubmit:x,className:"flex gap-4 items-end max-w-md",children:[o("div",{className:"flex-1 space-y-2",children:[t("label",{htmlFor:"tokenName",className:"text-sm font-medium text-muted-foreground",children:$T()}),t(q,{id:"tokenName",value:a,onChange:(i)=>l(i.target.value),placeholder:GT(),required:!0})]}),o(E,{type:"submit",disabled:p||!a.trim(),children:[p?t(O,{className:"w-4 h-4 animate-spin mr-2"}):t(pe,{className:"w-4 h-4 mr-2"}),Fv()]})]}),t("div",{className:"border rounded-lg overflow-hidden",children:o(Rn,{children:[t(Pn,{children:o(wr,{children:[t(Et,{children:wl()}),t(Et,{children:HT()}),t(Et,{children:Sy()}),t(Et,{className:"w-[100px] text-right",children:zA()})]})}),t(Nn,{children:!c||c.length===0?t(wr,{children:t(yt,{colSpan:4,className:"text-center py-6 text-muted-foreground text-sm",children:Wx()})}):c.map((i)=>o(wr,{children:[t(yt,{className:"font-medium",children:i.name}),t(yt,{className:"font-mono text-sm max-w-[200px] truncate",children:o("div",{className:"flex items-center gap-2",children:[o("span",{children:[i.token.substring(0,8),"..."]}),t(E,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>m(i.id,i.token),children:s===i.id?t(Pe,{className:"h-3.5 w-3.5 text-green-500"}):t(Nr,{className:"h-3.5 w-3.5"})})]})}),t(yt,{className:"text-muted-foreground",children:new Date(i.createdAt).toLocaleDateString()}),t(yt,{className:"text-right",children:t(E,{variant:"ghost",size:"icon",className:"h-8 w-8 text-red-500 hover:text-red-600 hover:bg-red-50",onClick:()=>b(i.id),children:t(we,{className:"h-4 w-4"})})})]},i.id))})]})})]})]})})}S();S();var Ur=[{value:"read_asset",label:()=>zm()},{value:"list_assets",label:()=>Bm()},{value:"create_folder",label:()=>Dm()},{value:"create_file",label:()=>Nm()},{value:"create_version",label:()=>Om()},{value:"generate_image",label:()=>Lm()},{value:"generate_video",label:()=>Zm()},{value:"rename_asset",label:()=>jm()},{value:"move_assets",label:()=>Um()},{value:"delete_asset",label:()=>Fm()}],Xa={agent_total_tokens:{label:()=>Nd(),icon:io,unit:"tokens",defaultLimit:1e5},agent_cost:{label:()=>kd(),icon:ma,unit:"$",defaultLimit:10},agent_mcp_call_count:{label:()=>Rd(),icon:vn,unit:"calls",defaultLimit:100},agent_bash_call_count:{label:()=>Md(),icon:To,unit:"calls",defaultLimit:50},agent_tool_call_count:{label:()=>Pd(),icon:Io,unit:"calls",defaultLimit:100}},Bs=({open:e,onOpenChange:r,teamId:a,rule:l,onSuccess:s})=>{let d=Q(),c=!!l,[g,_]=u("each_member"),[p,b]=u("team"),[x,m]=u([]),[i,v]=u("agent_total_tokens"),[w,k]=u(""),[z,J]=u("*"),[H,ie]=u("read_asset"),[oe,T]=u(1e5),[P,j]=u("1day"),[X,F]=u(!0),[Y,ye]=u(!1),[me,Ee]=u(""),{data:Fe=[]}=Z({queryKey:["teams",a,"members"],queryFn:async()=>{let re=await A.api.teams[":teamId"].members.$get({param:{teamId:a},query:{}});if(!re.ok)return[];return await re.json()},enabled:e}),{data:se}=Z({queryKey:["teams",a,"mcp","servers"],queryFn:async()=>{let re=await A.api.teams[":teamId"].mcp.servers.$get({param:{teamId:a}});if(!re.ok)return{servers:[]};return await re.json()},enabled:e&&i==="agent_mcp_call_count"}),ke=se?.servers||[];h(()=>{if(l){_(l.scopeMode),b(l.role||"team"),m(l.userIds||[]),v(l.resource);let re=l.resourceData||{};k(typeof re.id==="string"?re.id:""),J(typeof re.match==="string"?re.match:"*"),ie(typeof re.name==="string"?re.name:typeof re.toolName==="string"?re.toolName:"read_asset"),T(l.limit),j(su(l.period)),F(l.enabled)}else _("each_member"),b("team"),m([]),v("agent_total_tokens"),k(""),J("*"),ie("read_asset"),T(Xa.agent_total_tokens.defaultLimit),j("1day"),F(!0)},[l,e]);let je=(re)=>{if(v(re),!c)T(Xa[re]?.defaultLimit||100)},He=B({mutationFn:async()=>{let re={};if(i==="agent_mcp_call_count")re.id=w;else if(i==="agent_bash_call_count")re.match=z.trim()||"*";else if(i==="agent_tool_call_count")re.name=H||"read_asset";let Ye=await A.api.teams[":teamId"].quotas.$post({param:{teamId:a},json:{scopeMode:g,role:g!=="selected_members"&&p!=="team"?p:null,userIds:g==="selected_members"?x:null,resource:i,resourceData:Object.keys(re).length>0?re:null,limit:Number(oe),period:P,enabled:X}});if(!Ye.ok){let U=await Ye.json().catch(()=>({}));throw Error(U?.message||Eh())}return await Ye.json()},onSuccess:()=>{d.invalidateQueries({queryKey:["teams",a,"quotas"]}),M.success(ZE()),r(!1),s?.()},onError:(re)=>{console.error("CREATE MUTATION ERROR:",re),M.error(re instanceof Error?re.message:Eh())}}),G=B({mutationFn:async()=>{if(!l)return;let re={};if(i==="agent_mcp_call_count")re.id=w;else if(i==="agent_bash_call_count")re.match=z.trim()||"*";else if(i==="agent_tool_call_count")re.name=H||"read_asset";let Ye=await A.api.teams[":teamId"].quotas[":id"].$put({param:{teamId:a,id:l.id},json:{scopeMode:g,role:g!=="selected_members"&&p!=="team"?p:null,userIds:g==="selected_members"?x:null,resource:i,resourceData:Object.keys(re).length>0?re:null,limit:Number(oe),period:P,enabled:X}});if(!Ye.ok){let U=await Ye.json().catch(()=>({}));throw Error(U?.message||yd())}return await Ye.json()},onSuccess:()=>{d.invalidateQueries({queryKey:["teams",a,"quotas"]}),M.success(cC()),r(!1),s?.()},onError:(re)=>{M.error(re instanceof Error?re.message:yd())}}),ee=B({mutationFn:async()=>{if(!l)return;if(!(await A.api.teams[":teamId"].quotas[":id"].$delete({param:{teamId:a,id:l.id}})).ok)throw Error(_d())},onSuccess:()=>{d.invalidateQueries({queryKey:["teams",a,"quotas"]}),M.success(Zg()),ye(!1),r(!1),s?.()},onError:(re)=>{M.error(re instanceof Error?re.message:_d())}}),xe=(re)=>{if(re.preventDefault(),g==="selected_members"&&x.length===0){M.error(sI());return}if(i==="agent_mcp_call_count"&&!w.trim()){M.error(wh());return}if(oe<=0){M.error("Limit must be greater than 0");return}if(c)G.mutate();else He.mutate()},de=He.isPending||G.isPending||ee.isPending,Ke=Fe.filter((re)=>{if(!me.trim())return!0;let Ye=me.toLowerCase();return re.name.toLowerCase().includes(Ye)||re.email&&re.email.toLowerCase().includes(Ye)}),bt=(re)=>{m((Ye)=>Ye.includes(re)?Ye.filter((U)=>U!==re):[...Ye,re])};return o(L,{children:[t(ue,{open:e,onOpenChange:r,children:o(ae,{className:"sm:max-w-[540px] max-h-[90vh] flex flex-col p-0 overflow-hidden",children:[o(fe,{className:"p-6 pb-4 border-b border-border/60 shrink-0",children:[t(le,{className:"text-xl font-bold",children:c?pb():by()}),t(It,{className:"text-sm text-muted-foreground",children:c?mb():vy()})]}),o("form",{onSubmit:xe,noValidate:!0,className:"flex-1 overflow-y-auto min-h-0 p-6 space-y-5",children:[o("div",{className:"space-y-2",children:[t(W,{className:"text-sm font-semibold",children:JE()}),o("div",{className:"grid grid-cols-3 gap-2",children:[o(E,{type:"button",variant:g==="each_member"?"default":"outline",size:"sm",disabled:c||de,onClick:()=>_("each_member"),className:"flex flex-col h-auto py-2.5 px-2 gap-1 items-center justify-center text-xs",children:[t(Vn,{className:"w-4 h-4"}),t("span",{className:"font-semibold",children:Od()})]}),o(E,{type:"button",variant:g==="all_members"?"default":"outline",size:"sm",disabled:c||de,onClick:()=>_("all_members"),className:"flex flex-col h-auto py-2.5 px-2 gap-1 items-center justify-center text-xs",children:[t(ao,{className:"w-4 h-4"}),t("span",{className:"font-semibold",children:Dd()})]}),o(E,{type:"button",variant:g==="selected_members"?"default":"outline",size:"sm",disabled:c||de,onClick:()=>_("selected_members"),className:"flex flex-col h-auto py-2.5 px-2 gap-1 items-center justify-center text-xs",children:[t(Yo,{className:"w-4 h-4"}),t("span",{className:"font-semibold",children:Fd()})]})]}),o("p",{className:"text-xs text-muted-foreground pt-0.5",children:[g==="each_member"&&eC(),g==="all_members"&&XE(),g==="selected_members"&&tC()]})]}),g!=="selected_members"?o("div",{className:"space-y-2",children:[t(W,{htmlFor:"quota-role-scope",className:"text-sm font-semibold",children:YE()}),o(Le,{value:p,onValueChange:b,disabled:c||de,children:[t(Be,{id:"quota-role-scope",className:"w-full",children:t(Ze,{})}),o(Ue,{children:[t(ne,{value:"team",children:Tl()}),o(ne,{value:"owner",children:[xp(),": Owner"]}),o(ne,{value:"editor",children:[xp(),": Editor"]}),o(ne,{value:"reviewer",children:[xp(),": Reviewer"]})]})]})]}):o("div",{className:"space-y-2",children:[t(W,{className:"text-sm font-semibold",children:rA()}),o(ht,{children:[t(gt,{asChild:!0,children:o(E,{variant:"outline",role:"combobox",disabled:de,className:"w-full justify-between text-left font-normal h-10",children:[t("span",{className:"truncate",children:x.length===0?rA():rC({count:x.length})}),t(ve,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),t(At,{className:"w-[320px] p-2",align:"start",children:o("div",{className:"space-y-2",children:[o("div",{className:"relative",children:[t(Ut,{className:"w-3.5 h-3.5 absolute left-2.5 top-1/2 -translate-y-1/2 text-muted-foreground"}),t(q,{placeholder:Sp(),value:me,onChange:(re)=>Ee(re.target.value),className:"h-8 pl-8 text-xs"})]}),t(ce,{className:"h-48",children:t("div",{className:"space-y-1 pr-2",children:Ke.map((re)=>{let Ye=x.includes(re.id);return o("div",{onClick:()=>bt(re.id),className:"flex items-center gap-2 p-1.5 rounded-lg hover:bg-muted/60 cursor-pointer text-xs",children:[t(vr,{checked:Ye,onCheckedChange:()=>bt(re.id)}),o(Ce,{className:"w-5 h-5",children:[t(Ie,{src:re.image||void 0}),t(Te,{className:"text-[10px]",children:re.name?.[0]?.toUpperCase()||"U"})]}),o("div",{className:"truncate flex-1",children:[t("span",{className:"font-medium text-foreground block truncate",children:re.name}),re.email&&t("span",{className:"text-[10px] text-muted-foreground block truncate",children:re.email})]})]},re.id)})})})]})})]})]}),o("div",{className:"space-y-2",children:[t(W,{htmlFor:"quota-resource",className:"text-sm font-semibold",children:KE()}),o(Le,{value:i,onValueChange:(re)=>je(re),disabled:c||de,children:[t(Be,{id:"quota-resource",className:"w-full",children:t(Ze,{})}),o(Ue,{children:[t(ne,{value:"agent_total_tokens",children:o("div",{className:"flex items-center gap-2",children:[t(io,{className:"w-4 h-4 text-primary"}),t("span",{children:Nd()})]})}),t(ne,{value:"agent_cost",children:o("div",{className:"flex items-center gap-2",children:[t(ma,{className:"w-4 h-4 text-emerald-500"}),t("span",{children:kd()})]})}),t(ne,{value:"agent_mcp_call_count",children:o("div",{className:"flex items-center gap-2",children:[t(vn,{className:"w-4 h-4 text-blue-500"}),t("span",{children:Rd()})]})}),t(ne,{value:"agent_bash_call_count",children:o("div",{className:"flex items-center gap-2",children:[t(To,{className:"w-4 h-4 text-purple-500"}),t("span",{children:Md()})]})}),t(ne,{value:"agent_tool_call_count",children:o("div",{className:"flex items-center gap-2",children:[t(Io,{className:"w-4 h-4 text-cyan-500"}),t("span",{children:Pd()})]})})]})]})]}),i==="agent_mcp_call_count"&&o("div",{className:"space-y-2",children:[t(W,{htmlFor:"quota-mcp",className:"text-sm font-semibold",children:tA()}),ke.length>0?o(Le,{value:w,onValueChange:k,disabled:c||de,children:[t(Be,{id:"quota-mcp",className:"w-full",children:t(Ze,{placeholder:tA()})}),t(Ue,{children:ke.map((re)=>o(ne,{value:re.id,children:[re.name," (",re.id,")"]},re.id))})]}):t(q,{id:"quota-mcp",value:w,onChange:(re)=>k(re.target.value),placeholder:wh(),disabled:c||de})]}),i==="agent_bash_call_count"&&o("div",{className:"space-y-1.5",children:[t(W,{htmlFor:"quota-bash",className:"text-sm font-semibold",children:T_()}),t(q,{id:"quota-bash",value:z,onChange:(re)=>J(re.target.value),placeholder:M_(),disabled:de}),t("p",{className:"text-xs text-muted-foreground",children:FE()})]}),i==="agent_tool_call_count"&&o("div",{className:"space-y-2",children:[t(W,{htmlFor:"quota-tool",className:"text-sm font-semibold",children:oA()}),o(Le,{value:H,onValueChange:ie,disabled:c||de,children:[t(Be,{id:"quota-tool",className:"w-full",children:t(Ze,{placeholder:oA()})}),t(Ue,{children:Ur.map((re)=>t(ne,{value:re.value,children:re.label()},re.value))})]}),t("p",{className:"text-xs text-muted-foreground",children:lC()})]}),o("div",{className:"grid grid-cols-2 gap-4",children:[o("div",{className:"space-y-2",children:[o(W,{htmlFor:"quota-limit",className:"text-sm font-semibold",children:[jE()," (",Xa[i]?.unit||"",")"]}),t(q,{id:"quota-limit",type:"number",min:"0.01",step:i==="agent_cost"?"0.01":"1",value:oe,onChange:(re)=>T(Number(re.target.value)),placeholder:qE(),disabled:de,required:!0})]}),o("div",{className:"space-y-2",children:[t(W,{htmlFor:"quota-period",className:"text-sm font-semibold",children:$E()}),o(Le,{value:P,onValueChange:(re)=>j(re),disabled:de,children:[t(Be,{id:"quota-period",className:"w-full",children:t(Ze,{})}),o(Ue,{children:[t(ne,{value:"1hour",children:o("div",{className:"flex items-center gap-2",children:[t(er,{className:"w-3.5 h-3.5 text-muted-foreground"}),t("span",{children:bp()})]})}),t(ne,{value:"5hour",children:o("div",{className:"flex items-center gap-2",children:[t(er,{className:"w-3.5 h-3.5 text-muted-foreground"}),t("span",{children:vp()})]})}),t(ne,{value:"1day",children:o("div",{className:"flex items-center gap-2",children:[t(er,{className:"w-3.5 h-3.5 text-muted-foreground"}),t("span",{children:yp()})]})}),t(ne,{value:"7day",children:o("div",{className:"flex items-center gap-2",children:[t(er,{className:"w-3.5 h-3.5 text-muted-foreground"}),t("span",{children:wp()})]})})]})]})]})]}),o("div",{className:"flex items-center justify-between p-3 rounded-lg border bg-muted/20",children:[o("div",{className:"space-y-0.5",children:[t(W,{htmlFor:"quota-enabled",className:"text-sm font-medium cursor-pointer",children:X?UE():_p()}),t("p",{className:"text-xs text-muted-foreground",children:X?"Active and enforcing limits":"Inactive, requests will bypass this quota"})]}),t(Me,{id:"quota-enabled",checked:X,onCheckedChange:F,disabled:de})]}),o(qe,{className:"pt-4 flex items-center justify-between gap-2 sm:justify-between border-t border-border/60",children:[c?o(E,{type:"button",variant:"destructive",size:"sm",onClick:()=>ye(!0),disabled:de,className:"gap-1.5",children:[t(we,{className:"w-4 h-4"}),t("span",{children:Of()})]}):t("div",{}),o("div",{className:"flex items-center gap-2",children:[t(E,{type:"button",variant:"outline",onClick:()=>r(!1),disabled:de,children:De()}),o(E,{type:"submit",disabled:de,className:"gap-2",children:[de&&t(O,{className:"w-4 h-4 animate-spin"}),c?xo():Zc()]})]})]})]})]})}),t(Je,{open:Y,onOpenChange:ye,children:o(Xe,{children:[o(et,{children:[t(rt,{children:Of()}),t(nt,{children:hh()})]}),o(tt,{children:[t(st,{disabled:de,children:De()}),o(ot,{onClick:(re)=>{re.preventDefault(),ee.mutate()},disabled:de,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:[de&&t(O,{className:"w-4 h-4 animate-spin mr-2"}),at()]})]})]})})]})};var js=({teamId:e})=>{let r=Q(),[a,l]=u(!1),[s,d]=u(null),[c,g]=u(null),{data:_,isLoading:p}=Z({queryKey:["teams",e,"quotas"],queryFn:async()=>{let i=await A.api.teams[":teamId"].quotas.$get({param:{teamId:e}});if(!i.ok)throw Error(Jo());return await i.json()}}),b=B({mutationFn:async({id:i,enabled:v})=>{let w=await A.api.teams[":teamId"].quotas[":id"].$put({param:{teamId:e,id:i},json:{enabled:v}});if(!w.ok)throw Error(yd());return await w.json()},onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"quotas"]}),M.success(nC())},onError:(i)=>{M.error(i instanceof Error?i.message:yd())}}),x=B({mutationFn:async(i)=>{if(!(await A.api.teams[":teamId"].quotas[":id"].$delete({param:{teamId:e,id:i}})).ok)throw Error(_d())},onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"quotas"]}),M.success(Zg()),g(null)},onError:(i)=>{M.error(i instanceof Error?i.message:_d())}}),m=_?.rules||[];return o(ce,{className:"h-full",children:[t("div",{className:"space-y-6 pr-4 pb-10",children:o(ut,{children:[o(Tt,{className:"flex flex-row items-center justify-between space-y-0 pb-6",children:[o("div",{className:"flex items-center gap-3",children:[t("div",{className:"p-2 bg-primary/10 text-primary rounded-lg",children:t(Bo,{className:"w-6 h-6"})}),o("div",{children:[t(Mt,{className:"text-xl font-bold",children:Gg()}),t(Ot,{children:Vg()})]})]}),o(E,{onClick:()=>l(!0),className:"gap-2",children:[t(pe,{className:"w-4 h-4"})," ",km()]})]}),t(xt,{children:p?t("div",{className:"flex justify-center py-12",children:t(O,{className:"w-8 h-8 animate-spin text-primary"})}):m.length===0?o("div",{className:"text-center py-12 border-2 border-dashed border-border rounded-xl",children:[t("div",{className:"mx-auto w-12 h-12 bg-muted rounded-full flex items-center justify-center mb-4 text-muted-foreground",children:t(Bo,{className:"w-6 h-6"})}),t("h3",{className:"text-base font-semibold text-foreground mb-1",children:cp()}),t("p",{className:"text-sm text-muted-foreground max-w-md mx-auto mb-6",children:lp()}),o(E,{onClick:()=>l(!0),className:"gap-2",children:[t(pe,{className:"w-4 h-4"})," ",km()]})]}):t("div",{className:"flex flex-col gap-4",children:m.map((i)=>{let v=Qa[i.resource],w=i.resourceData||{};return t("div",{onClick:()=>d(i),className:`group relative flex flex-col justify-between p-5 rounded-xl border bg-card text-card-foreground shadow-2xs transition-all hover:border-primary/40 hover:shadow-xs cursor-pointer ${!i.enabled?"opacity-60 bg-muted/20":""}`,children:o("div",{className:"space-y-3",children:[o("div",{className:"flex items-start justify-between gap-2",children:[o("div",{children:[t("div",{className:"font-semibold text-base text-foreground group-hover:text-primary transition-colors flex items-center gap-2",children:t("span",{children:v?.label?v.label():i.resource})}),o("div",{className:"text-xs text-muted-foreground line-clamp-1",children:[i.resource==="agent_mcp_call_count"&&o("span",{children:["Server: ",String(w.id||"")]}),i.resource==="agent_bash_call_count"&&o("span",{children:["Match: ",String(w.match||"*")]}),i.resource==="agent_tool_call_count"&&o("span",{children:["Tool: ",String(w.name||w.toolName||"*")]})]})]}),o("div",{className:"flex items-center gap-2",onClick:(k)=>k.stopPropagation(),children:[t(Me,{checked:i.enabled,onCheckedChange:(k)=>b.mutate({id:i.id,enabled:k}),disabled:b.isPending}),o(he,{modal:!1,children:[t(ge,{asChild:!0,children:t(E,{variant:"ghost",size:"icon","aria-label":"Quota actions",className:"h-8 w-8 text-muted-foreground hover:text-foreground",children:t(Sr,{className:"w-4 h-4"})})}),t(Ae,{align:"end",children:o(K,{onClick:()=>g(i),className:"text-destructive focus:text-destructive",children:[t(we,{className:"w-4 h-4 mr-2"}),at()]})})]})]})]}),t("div",{className:"flex flex-wrap items-center gap-2 pt-2 border-t border-border/50",children:o("div",{className:"flex flex-wrap items-center gap-1.5",children:[i.scopeMode==="all_members"&&o(be,{variant:"secondary",className:"gap-1 text-xs",children:[t(ao,{className:"w-3 h-3"}),o("span",{children:[Dd(),i.role?` (${i.role})`:` (${Tl()})`]})]}),i.scopeMode==="each_member"&&o(be,{variant:"secondary",className:"gap-1 text-xs",children:[t(Vn,{className:"w-3 h-3"}),o("span",{children:[Od(),i.role?` (${i.role})`:` (${Tl()})`]})]}),i.scopeMode==="selected_members"&&o(be,{variant:"secondary",className:"gap-1 text-xs",children:[t(Yo,{className:"w-3 h-3"}),o("span",{children:[Fd()," (",i.userIds?.length||0,")"]})]}),o(be,{variant:"outline",className:"gap-1 text-xs",children:[t(er,{className:"w-3 h-3"}),o("span",{children:[Oi(i.resource,i.limit)," ",v?.unit," /"," ",Yl(i.period)]})]})]})})]})},i.id)})})})]})}),(a||!!s)&&t(Bs,{open:a||!!s,onOpenChange:(i)=>{if(!i)l(!1),d(null)},teamId:e,rule:s}),t(Je,{open:!!c,onOpenChange:(i)=>{if(!i)g(null)},children:o(Xe,{children:[o(et,{children:[t(rt,{children:Of()}),t(nt,{children:hh()})]}),o(tt,{children:[t(st,{disabled:x.isPending,children:De()}),o(ot,{onClick:(i)=>{if(i.preventDefault(),c)x.mutate(c.id)},disabled:x.isPending,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:[x.isPending&&t(O,{className:"w-4 h-4 animate-spin mr-2"}),at()]})]})]})})]})};function Os({teamId:e}){let r=Q(),{data:a,isLoading:l}=Z({queryKey:["teams",e,"settings"],queryFn:async()=>{let _=await A.api.teams[":teamId"].settings.$get({param:{teamId:e}});if(!_.ok)throw Error(Jo());return await _.json()},enabled:!!e}),{mutate:s,isPending:d}=B({mutationFn:async(_)=>{let p=await A.api.teams[":teamId"].settings.$patch({param:{teamId:e},json:{key:"appearance.hideAgent",value:_}});if(!p.ok)throw Error(Ph());return await p.json()},onSuccess:async(_,p)=>{if(r.invalidateQueries({queryKey:["teams",e,"settings"]}),await Ar.getState().fetchMetadata(e),p)lr.getState().setIsChatbotOpen(!1);M.success(n_())},onError:(_)=>{M.error(_ instanceof Error?_.message:Ph())}}),c=Boolean(a?.appearance?.hideAgent),g=(_)=>{s(_)};if(l)return t("div",{className:"flex items-center justify-center p-8",children:t(O,{className:"h-6 w-6 animate-spin text-muted-foreground"})});return t("div",{className:"h-full overflow-y-auto pr-1",children:o(ut,{children:[o(Tt,{children:[t(Mt,{children:Jm()}),t(Ot,{children:Xm()})]}),t(xt,{className:"space-y-6",children:o("div",{className:"flex items-center justify-between space-x-4 rounded-lg border border-border p-4",children:[o("div",{className:"space-y-1",children:[t("label",{htmlFor:"hide-agent-switch",className:"text-sm font-medium leading-none cursor-pointer",children:tw()}),t("p",{className:"text-xs text-muted-foreground",children:rw()})]}),t(Me,{id:"hide-agent-switch",checked:c,onCheckedChange:g,disabled:d})]})})]})})}S();S();function $s({isOpen:e,onClose:r,teamId:a,defaultFrom:l=""}){let[s,d]=u(l);h(()=>{if(e)d(l)},[l,e]);let{mutateAsync:c,isPending:g}=B({mutationFn:async(p)=>{let b=await A.api.teams[":teamId"].notifications.email.test.$post({param:{teamId:a},json:{from:p}});if(!b.ok){let x=await b.json().catch(()=>null);throw Error(x?.message||Mh())}return await b.json()}}),_=async()=>{if(!s.trim()){M.error(Pv());return}try{await c(s.trim()),M.success(kT()),r()}catch(p){M.error(p instanceof Error?p.message:Mh())}};return t(ue,{open:e,onOpenChange:(p)=>!p&&r(),children:o(ae,{className:"sm:max-w-md",children:[o(fe,{children:[o("div",{className:"flex items-center gap-2",children:[t(ss,{className:"w-5 h-5 text-primary"}),t(le,{children:sA()})]}),t(It,{children:fI()})]}),t("div",{className:"space-y-4 py-2",children:o("div",{className:"space-y-2",children:[t("label",{htmlFor:"test-dialog-from-input",className:"text-sm font-medium text-foreground",children:iA()}),t(q,{id:"test-dialog-from-input",value:s,onChange:(p)=>d(p.target.value),placeholder:"Shumai <noreply@example.com>",disabled:g,autoFocus:!0})]})}),o(qe,{className:"gap-2 sm:gap-0",children:[t(E,{variant:"outline",onClick:r,disabled:g,children:De()}),o(E,{onClick:_,disabled:g,children:[g&&t(O,{className:"w-4 h-4 animate-spin mr-2"}),sA()]})]})]})})}function Ks({teamId:e}){let r=Q(),[a,l]=u({enabled:!1,host:"",port:587,username:"",password:"",smtps:!1,ignoreCert:!1,from:"",replyTo:""}),[s,d]=u(!1),{data:c,isLoading:g,error:_}=Z({queryKey:["teams",e,"email-settings"],queryFn:async()=>{let i=await A.api.teams[":teamId"].notifications.email.$get({param:{teamId:e}});if(!i.ok)throw Error(Ch());return await i.json()},enabled:!!e});h(()=>{if(c)l({enabled:c.enabled??!1,host:c.host??"",port:c.port??587,username:c.username??"",password:"",smtps:c.smtps??!1,ignoreCert:c.ignoreCert??!1,from:c.from??"",replyTo:c.replyTo??""})},[c]);let{mutateAsync:p,isPending:b}=B({mutationFn:async(i)=>{let v=await A.api.teams[":teamId"].notifications.email.$put({param:{teamId:e},json:{enabled:i.enabled,host:i.host,port:i.port,username:i.username||"",password:i.password||"",smtps:i.smtps,ignoreCert:i.ignoreCert,from:i.from,replyTo:i.replyTo||""}});if(!v.ok){let w=await v.json().catch(()=>null);throw Error(w?.message||zf())}return await v.json()},onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"email-settings"]}),r.invalidateQueries({queryKey:["teams",e,"settings"]})}}),x=async()=>{try{await p(a),M.success(vh())}catch(i){M.error(i instanceof Error?i.message:zf())}},m=async()=>{if(!a.host.trim()){M.error(NI());return}try{await p(a),M.success(vh()),d(!0)}catch(i){M.error(i instanceof Error?i.message:zf())}};if(g)return t("div",{className:"flex items-center justify-center p-8",children:t(O,{className:"h-6 w-6 animate-spin text-muted-foreground"})});if(_)return t("div",{className:"p-8 text-center text-destructive",children:_ instanceof Error?_.message:Ch()});return o(L,{children:[t(ce,{className:"h-full",children:t("div",{className:"space-y-6 pr-4 pb-8",children:o(ut,{children:[o(xt,{className:"space-y-6 pt-6",children:[o("div",{className:"flex items-center justify-between space-x-4 rounded-lg border border-border p-4",children:[o("div",{className:"space-y-1",children:[t("label",{htmlFor:"enable-email-switch",className:"text-sm font-medium leading-none cursor-pointer",children:wb()}),t("p",{className:"text-xs text-muted-foreground",children:xb()})]}),t(Me,{id:"enable-email-switch",checked:a.enabled,onCheckedChange:(i)=>l({...a,enabled:i})})]}),o("div",{className:"space-y-4 pt-2",children:[t("h4",{className:"text-sm font-semibold text-foreground",children:jI()}),o("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[o("div",{className:"space-y-2 md:col-span-2",children:[t("label",{htmlFor:"smtp-host-input",className:"text-sm font-medium text-foreground",children:RI()}),t(q,{id:"smtp-host-input",value:a.host,onChange:(i)=>l({...a,host:i.target.value}),placeholder:PI(),disabled:!a.enabled})]}),o("div",{className:"space-y-2",children:[t("label",{htmlFor:"smtp-port-input",className:"text-sm font-medium text-foreground",children:BI()}),t(q,{id:"smtp-port-input",type:"number",value:a.port,onChange:(i)=>l({...a,port:parseInt(i.target.value,10)||587}),disabled:!a.enabled})]})]}),o("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[o("div",{className:"space-y-2",children:[t("label",{htmlFor:"smtp-username-input",className:"text-sm font-medium text-foreground",children:qI()}),t(q,{id:"smtp-username-input",value:a.username||"",onChange:(i)=>l({...a,username:i.target.value}),placeholder:HI(),disabled:!a.enabled,autoComplete:"off"})]}),o("div",{className:"space-y-2",children:[t("label",{htmlFor:"smtp-password-input",className:"text-sm font-medium text-foreground",children:FI()}),t(q,{id:"smtp-password-input",type:"password",value:a.password||"",onChange:(i)=>l({...a,password:i.target.value}),placeholder:c?.password?LI():ZI(),disabled:!a.enabled,autoComplete:"new-password"})]})]}),o("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 pt-2",children:[o("div",{className:"flex items-center justify-between space-x-4 rounded-lg border border-border p-4",children:[o("div",{className:"space-y-1",children:[t("label",{htmlFor:"smtps-switch",className:"text-sm font-medium leading-none cursor-pointer",children:UI()}),t("p",{className:"text-xs text-muted-foreground",children:zI()})]}),t(Me,{id:"smtps-switch",checked:a.smtps,onCheckedChange:(i)=>l({...a,smtps:i}),disabled:!a.enabled})]}),o("div",{className:"flex items-center justify-between space-x-4 rounded-lg border border-border p-4",children:[o("div",{className:"space-y-1",children:[t("label",{htmlFor:"ignore-cert-switch",className:"text-sm font-medium leading-none cursor-pointer",children:DI()}),t("p",{className:"text-xs text-muted-foreground",children:OI()})]}),t(Me,{id:"ignore-cert-switch",checked:a.ignoreCert,onCheckedChange:(i)=>l({...a,ignoreCert:i}),disabled:!a.enabled})]})]})]}),o("div",{className:"space-y-4 pt-4 border-t border-border",children:[t("h4",{className:"text-sm font-semibold text-foreground",children:gI()}),o("div",{className:"space-y-2",children:[t("label",{htmlFor:"sender-from-input",className:"text-sm font-medium text-foreground",children:iA()}),t(q,{id:"sender-from-input",value:a.from,onChange:(i)=>l({...a,from:i.target.value}),placeholder:"Shumai <noreply@example.com>",disabled:!a.enabled}),t("p",{className:"text-xs text-muted-foreground",children:pI()})]}),o("div",{className:"space-y-2",children:[t("label",{htmlFor:"sender-reply-to-input",className:"text-sm font-medium text-foreground",children:mI()}),t(q,{id:"sender-reply-to-input",value:a.replyTo||"",onChange:(i)=>l({...a,replyTo:i.target.value}),placeholder:"noreply@example.com",disabled:!a.enabled}),t("p",{className:"text-xs text-muted-foreground",children:hI()})]})]})]}),o(nf,{className:"flex flex-col sm:flex-row items-center justify-end gap-3 border-t border-border p-6 bg-muted/20",children:[o(E,{variant:"outline",onClick:x,disabled:b,children:[b&&t(O,{className:"w-4 h-4 animate-spin mr-2"}),xo()]}),o(E,{onClick:m,disabled:b||!a.enabled,children:[b&&t(O,{className:"w-4 h-4 animate-spin mr-2"}),PC()]})]})]})})}),t($s,{isOpen:s,onClose:()=>d(!1),teamId:e,defaultFrom:a.from})]})}S();var Us={openai:"OpenAI",google:"Google","google-vertex":"Google Vertex AI",xai:"xAI",fal:"Fal",replicate:"Replicate","black-forest-labs":"Black Forest Labs",klingai:"Kling AI",togetherai:"Together AI",fireworks:"Fireworks AI",deepinfra:"DeepInfra",luma:"Luma","amazon-bedrock":"Amazon Bedrock",alibaba:"Alibaba",bytedance:"ByteDance",minimax:"MiniMax",prodia:"Prodia",azure:"Azure OpenAI"};function Gs({teamId:e}){let r=Q(),[a,l]=u(null),{data:s,isLoading:d}=Z({queryKey:["teams",e,"media-generation"],queryFn:async()=>{let p=await A.api.teams[":teamId"]["media-generation"].$get({param:{teamId:e}});if(!p.ok)throw Error("Failed to fetch media generation settings");return await p.json()}}),c=s?.providers||[],g=s?.enabledModels||[],_=N(()=>{if(!a)return null;return c.find((p)=>p.provider===a.provider)||a},[a,c]);if(d)return t("div",{className:"flex h-64 items-center justify-center",children:t(O,{className:"h-8 w-8 animate-spin text-muted-foreground"})});return o("div",{className:"flex flex-col h-full min-w-0 w-full",children:[t(ce,{className:"h-full pr-1 [&>div>div]:block!",children:t("div",{className:"pb-12 min-w-0 w-full",children:o(ut,{className:"border-border min-w-0 w-full",children:[o(Tt,{children:[t(Mt,{className:"text-base font-semibold",children:px()}),t(Ot,{children:mx()})]}),t(xt,{className:"min-w-0",children:t("div",{className:"space-y-2.5 min-w-0",children:c.map((p)=>{let b=Us[p.provider]||p.provider,x=p.status==="configured_custom",m=p.status==="configured_env",i=g.filter((w)=>w.provider===p.provider&&w.type==="image").length,v=g.filter((w)=>w.provider===p.provider&&w.type==="video").length;return o("div",{onClick:()=>l(p),className:"group cursor-pointer flex items-center justify-between gap-4 p-3.5 rounded-xl border border-border bg-card/50 hover:bg-card/80 hover:border-primary/50 transition-all shadow-none hover:shadow-xs min-w-0",children:[o("div",{className:"flex flex-col gap-1.5 min-w-0 flex-1",children:[o("div",{className:"flex items-center gap-2.5 min-w-0",children:[t("span",{className:"font-semibold text-sm text-foreground truncate",children:b}),t("span",{className:"text-xs text-muted-foreground font-mono opacity-60 truncate",title:p.customApiKeyOrEnv||p.defaultEnvKey,children:p.customApiKeyOrEnv||p.defaultEnvKey})]}),o("div",{className:"flex flex-wrap items-center gap-2 min-w-0",children:[x&&o(be,{variant:"outline",className:"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border-emerald-500/20 text-[10px] shrink-0 font-normal gap-1",children:[t(xr,{className:"w-3 h-3"}),Pg()]}),m&&o(be,{variant:"outline",className:"bg-sky-500/10 text-sky-600 dark:text-sky-400 border-sky-500/20 text-[10px] shrink-0 font-normal gap-1",children:[t(xr,{className:"w-3 h-3"}),Ng()]}),!x&&!m&&t(be,{variant:"outline",className:"bg-muted text-muted-foreground border-border text-[10px] shrink-0 font-normal",children:Dg()}),p.supportedTypes.includes("image")&&o("span",{className:C("inline-flex items-center gap-1 text-[10px] px-2 py-0.5 rounded border shrink-0 font-normal transition-colors",i>0?"bg-primary/10 text-primary border-primary/20":"bg-muted/50 text-muted-foreground border-border/60"),children:[t(eo,{className:"w-3 h-3"}),lw({count:i})]}),p.supportedTypes.includes("video")&&o("span",{className:C("inline-flex items-center gap-1 text-[10px] px-2 py-0.5 rounded border shrink-0 font-normal transition-colors",v>0?"bg-purple-500/10 text-purple-600 dark:text-purple-400 border-purple-500/20":"bg-muted/50 text-muted-foreground border-border/60"),children:[t(pa,{className:"w-3 h-3"}),p1({count:v})]})]})]}),t(vt,{className:"w-4 h-4 text-muted-foreground group-hover:text-foreground transition-colors shrink-0"})]},p.provider)})})})]})})}),_&&t(Hr,{isOpen:!!_,onClose:()=>l(null),provider:_,teamId:e,enabledModels:g,onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"media-generation"]})}})]})}function Hr({isOpen:e,onClose:r,provider:a,teamId:l,enabledModels:s,onSuccess:d}){let[c,g]=u(()=>a.apiKeyConfigured?"models":"api-key"),[_,p]=u(a.customApiKeyOrEnv||""),[b,x]=u(()=>s.filter((se)=>se.provider===a.provider).map((se)=>({type:se.type,modelId:se.modelId,name:se.name}))),[m,i]=u(""),[v,w]=u("all"),[k,z]=u(""),[J,H]=u(a.supportedTypes[0]||"image");h(()=>{g(a.apiKeyConfigured?"models":"api-key"),p(a.customApiKeyOrEnv||""),x(s.filter((se)=>se.provider===a.provider).map((se)=>({type:se.type,modelId:se.modelId,name:se.name}))),i(""),w("all"),z(""),H(a.supportedTypes[0]||"image")},[a.provider,a.customApiKeyOrEnv,a.apiKeyConfigured,s]);let{data:ie=[],isLoading:oe}=Z({queryKey:["teams",l,"media-generation","curated",a.provider],queryFn:async()=>{let se=await A.api.teams[":teamId"]["media-generation"].models.curated.$get({param:{teamId:l},query:{provider:a.provider}});if(!se.ok)return[];return await se.json()},enabled:e}),{mutate:T,isPending:P}=B({mutationFn:async()=>{let se=await A.api.teams[":teamId"]["media-generation"].providers[":provider"].$put({param:{teamId:l,provider:a.provider},json:{apiKey:_.trim(),models:b.map((ke)=>({type:ke.type,modelId:ke.modelId,name:ke.name||ke.modelId}))}});if(!se.ok){let ke=await se.json().catch(()=>({}));throw Error(ke?.message||"Failed to update provider")}return await se.json()},onSuccess:()=>{M.success(Og()),d(),r()},onError:(se)=>{M.error(se instanceof Error?se.message:ov())}}),j=N(()=>new Set(ie.map((se)=>se.modelId)),[ie]),X=N(()=>b.filter((se)=>!j.has(se.modelId)),[b,j]),F=N(()=>{let se=[];for(let ke of ie){let je=b.some((He)=>He.modelId===ke.modelId&&He.type===ke.type);se.push({type:ke.type,modelId:ke.modelId,name:ke.name,isCustom:!1,isToggledOn:je})}for(let ke of X)se.push({type:ke.type,modelId:ke.modelId,name:ke.name||ke.modelId,isCustom:!0,isToggledOn:!0});return se},[ie,b,X]),Y=N(()=>F.filter((se)=>{if(v!=="all"&&se.type!==v)return!1;if(m.trim()){let ke=m.toLowerCase(),je=se.name.toLowerCase().includes(ke),He=se.modelId.toLowerCase().includes(ke);if(!je&&!He)return!1}return!0}),[F,v,m]),ye=(se,ke)=>{if(ke)x((je)=>[...je,{type:se.type,modelId:se.modelId,name:se.name,isCustom:se.isCustom}]);else x((je)=>je.filter((He)=>!(He.modelId===se.modelId&&He.type===se.type)))},me=(se,ke)=>{x((je)=>je.filter((He)=>!(He.modelId===se&&He.type===ke)))},Ee=()=>{let se=k.trim();if(!se)return;if(b.some((je)=>je.modelId===se&&je.type===J)){M.error(Qb());return}x((je)=>[...je,{type:J,modelId:se,name:se,isCustom:!0}]),z("")},Fe=Us[a.provider]||a.provider;return t(ue,{open:e,onOpenChange:(se)=>!se&&r(),children:o(ae,{className:"sm:max-w-2xl md:max-w-3xl h-[88vh] flex flex-col p-0 overflow-hidden",children:[o(fe,{className:"p-6 pb-2 shrink-0",children:[o(le,{className:"flex items-center gap-2 text-xl",children:[t("span",{children:Fe}),a.status==="configured_custom"&&t(be,{variant:"outline",className:"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border-emerald-500/20 text-[10px] font-normal",children:Pg()}),a.status==="configured_env"&&t(be,{variant:"outline",className:"bg-sky-500/10 text-sky-600 dark:text-sky-400 border-sky-500/20 text-[10px] font-normal",children:Ng()})]}),t(It,{children:Zy({envKey:a.defaultEnvKey})})]}),o(So,{value:c,onValueChange:(se)=>g(se),className:"flex-1 flex flex-col min-h-0",children:[t("div",{className:"px-6 pb-2 shrink-0",children:o(Eo,{className:"grid w-full grid-cols-2",children:[t(Kr,{value:"api-key",onClick:()=>g("api-key"),children:ud()}),o(Kr,{value:"models",onClick:()=>g("models"),children:[Sd()," (",b.length,")"]})]})}),t(kn,{value:"api-key",className:"flex-1 flex flex-col min-h-0 m-0",children:t("div",{className:"flex-1 min-h-0",children:t(ce,{className:"h-full",children:t("div",{className:"p-6 space-y-4 pr-6",children:o("div",{className:"space-y-2",children:[o("div",{className:"flex items-center justify-between",children:[t("label",{htmlFor:"provider-api-key",className:"text-xs font-medium text-foreground",children:ud()}),_&&o(E,{type:"button",variant:"ghost",size:"sm",className:"text-xs h-7 text-destructive hover:bg-destructive/10 hover:text-destructive gap-1 px-2",onClick:()=>p(""),children:[t(we,{className:"w-3.5 h-3.5"}),B_()]})]}),t(q,{id:"provider-api-key",type:"text",value:_,onChange:(se)=>p(se.target.value),placeholder:X0({envKey:a.defaultEnvKey}),className:"font-mono text-sm"}),t("p",{className:"text-xs text-muted-foreground mt-1",children:J0({envKey:a.defaultEnvKey})})]})})})})}),o(kn,{value:"models",className:"flex-1 flex flex-col min-h-0 m-0",children:[!a.apiKeyConfigured&&!_&&t("div",{className:"px-6 pb-2 shrink-0",children:o("div",{className:"flex items-start gap-2.5 p-3 rounded-lg bg-amber-500/10 border border-amber-500/20 text-amber-600 dark:text-amber-400 text-xs",children:[t(fr,{className:"w-4 h-4 shrink-0 mt-0.5"}),o("div",{children:[t("p",{className:"font-medium",children:Dg()}),t("p",{className:"text-[11px] opacity-90 mt-0.5",children:RE()})]})]})}),o("div",{className:"px-6 pb-3 flex items-center justify-between gap-3 shrink-0",children:[o("div",{className:"relative flex-1",children:[t(Ut,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),t(q,{type:"text",placeholder:Rp(),value:m,onChange:(se)=>i(se.target.value),className:"pl-9 h-9 text-xs"})]}),a.supportedTypes.length>1&&o("div",{className:"flex rounded-md border border-border overflow-hidden shrink-0 h-9",children:[t("button",{type:"button",onClick:()=>w("all"),className:C("px-3 text-xs transition-colors",v==="all"?"bg-primary text-primary-foreground font-medium":"bg-muted/40 hover:bg-muted text-muted-foreground"),children:V0()}),o("button",{type:"button",onClick:()=>w("image"),className:C("px-3 text-xs transition-colors flex items-center gap-1.5",v==="image"?"bg-primary text-primary-foreground font-medium":"bg-muted/40 hover:bg-muted text-muted-foreground"),children:[t(eo,{className:"w-3.5 h-3.5"}),tp()]}),o("button",{type:"button",onClick:()=>w("video"),className:C("px-3 text-xs transition-colors flex items-center gap-1.5",v==="video"?"bg-primary text-primary-foreground font-medium":"bg-muted/40 hover:bg-muted text-muted-foreground"),children:[t(pa,{className:"w-3.5 h-3.5"}),rp()]})]})]}),t("div",{className:"flex-1 min-h-0 px-6",children:t(ce,{className:"h-full pr-4",children:oe?o("div",{className:"flex h-48 items-center justify-center gap-2 text-muted-foreground",children:[t(O,{className:"h-5 w-5 animate-spin"}),t("span",{className:"text-xs",children:Tw()})]}):Y.length===0?t("div",{className:"text-center py-12 border border-dashed rounded-xl text-muted-foreground text-sm",children:Cd()}):t("div",{className:"space-y-2 pb-4",children:Y.map((se)=>o("div",{className:C("flex items-center justify-between p-3 rounded-xl border transition-all text-xs",se.isToggledOn?"border-primary/40 bg-primary/5":"border-border bg-card hover:border-primary/30"),children:[o("div",{className:"flex items-center gap-2.5 min-w-0 flex-1 mr-3",children:[o(be,{variant:"outline",className:C("text-[10px] px-1.5 py-0.5 gap-1 shrink-0 font-normal",se.type==="image"?"bg-primary/10 text-primary border-primary/20":"bg-purple-500/10 text-purple-600 dark:text-purple-400 border-purple-500/20"),children:[se.type==="image"?t(eo,{className:"w-3 h-3"}):t(pa,{className:"w-3 h-3"}),se.type==="image"?tp():rp()]}),o("div",{className:"min-w-0 flex-1",children:[o("div",{className:"font-semibold text-foreground text-sm truncate flex items-center gap-1.5",children:[t("span",{className:"truncate",children:se.name}),se.isCustom&&t(be,{variant:"secondary",className:"text-[10px] h-4 px-1 font-normal shrink-0",children:My().replace("...","")})]}),t("p",{className:"font-mono text-[11px] text-muted-foreground truncate mt-0.5",children:se.modelId})]})]}),o("div",{className:"flex items-center gap-2 shrink-0",children:[se.isCustom&&t(E,{type:"button",variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>me(se.modelId,se.type),title:at(),children:t(we,{className:"w-3.5 h-3.5"})}),t(Me,{checked:se.isToggledOn,onCheckedChange:(ke)=>ye(se,ke),"aria-label":`Toggle ${se.name}`})]})]},`${se.type}-${se.modelId}`))})})}),t("div",{className:"px-6 py-3 border-t border-border shrink-0 bg-muted/10",children:o("div",{className:"flex items-center gap-2",children:[a.supportedTypes.length>1&&o("div",{className:"flex rounded-md border border-border overflow-hidden shrink-0 h-8",children:[t("button",{type:"button",onClick:()=>H("image"),className:C("px-2.5 py-1 text-xs transition-colors",J==="image"?"bg-primary text-primary-foreground font-medium":"bg-muted/40 hover:bg-muted text-muted-foreground"),children:tp()}),t("button",{type:"button",onClick:()=>H("video"),className:C("px-2.5 py-1 text-xs transition-colors",J==="video"?"bg-primary text-primary-foreground font-medium":"bg-muted/40 hover:bg-muted text-muted-foreground"),children:rp()})]}),t(q,{type:"text",value:k,onChange:(se)=>z(se.target.value),placeholder:Mb(),className:"font-mono text-xs h-8 flex-1",onKeyDown:(se)=>{if(se.key==="Enter")se.preventDefault(),Ee()}}),o(E,{type:"button",size:"sm",variant:"outline",className:"h-8 text-xs shrink-0 gap-1",onClick:Ee,disabled:!k.trim(),children:[t(pe,{className:"w-3.5 h-3.5"}),wf()]})]})})]})]}),o(qe,{className:"px-6 py-4 border-t border-border shrink-0 flex items-center justify-between sm:justify-between w-full m-0 bg-card",children:[o("div",{className:"text-xs text-muted-foreground",children:[b.length," ",Sd().toLowerCase()]}),o("div",{className:"flex items-center gap-2",children:[t(E,{type:"button",variant:"outline",size:"sm",onClick:r,disabled:P,children:De()}),o(E,{type:"button",size:"sm",onClick:()=>T(),disabled:P,children:[P&&t(O,{className:"w-4 h-4 mr-1.5 animate-spin"}),xo()]})]})]})]})})}S();S();function Ws({isOpen:e,onClose:r,imageSrc:a,onConfirm:l}){let[s,d]=u(1),[c,g]=u({x:0,y:0}),[_,p]=u(!1),[b,x]=u(!1),m=y({x:0,y:0}),i=y(null),v=y(null),w=250;h(()=>{if(e)d(1),g({x:0,y:0}),x(!1)},[e,a]);let k=(T)=>{T.preventDefault(),p(!0),m.current={x:T.clientX-c.x,y:T.clientY-c.y}},z=(T)=>{if(!_)return;g({x:T.clientX-m.current.x,y:T.clientY-m.current.y})},J=()=>{p(!1)},H=(T)=>{if(T.touches.length!==1)return;p(!0);let P=T.touches[0];m.current={x:P.clientX-c.x,y:P.clientY-c.y}},ie=(T)=>{if(!_||T.touches.length!==1)return;let P=T.touches[0];g({x:P.clientX-m.current.x,y:P.clientY-m.current.y})},oe=async()=>{let T=i.current,P=v.current;if(!T||!P)return;x(!0);try{let j=T.getBoundingClientRect(),X=512,F=document.createElement("canvas");F.width=512,F.height=512;let Y=F.getContext("2d");if(Y){Y.clearRect(0,0,512,512);let ye=2.048,me=j.width/s,Ee=j.height/s,Fe=256+c.x*ye,se=256+c.y*ye;Y.translate(Fe,se),Y.scale(s*ye,s*ye),Y.drawImage(T,-me/2,-Ee/2,me,Ee);let ke=await new Promise((je)=>{F.toBlob((He)=>je(He),"image/jpeg",0.9)});if(ke)await l(ke)}}catch(j){console.error("Failed to crop image",j)}finally{x(!1)}};return t(ue,{open:e,onOpenChange:(T)=>!T&&r(),children:o(ae,{className:"sm:max-w-[420px] rounded-2xl border border-border bg-background/95 backdrop-blur-md shadow-2xl p-0 overflow-hidden gap-0",children:[t(fe,{className:"p-6 border-b border-border/40 bg-gradient-to-br from-primary/5 to-transparent",children:o(le,{className:"text-xl font-bold flex items-center gap-2",children:[t(as,{className:"w-5 h-5 text-primary"}),iE()]})}),o("div",{className:"p-6 flex flex-col items-center gap-6",children:[o("div",{ref:v,className:"relative overflow-hidden bg-muted select-none border border-border/40 rounded-xl cursor-move shadow-inner",style:{width:250,height:250},onMouseDown:k,onMouseMove:z,onMouseUp:J,onMouseLeave:J,onTouchStart:H,onTouchMove:ie,onTouchEnd:J,children:[a&&t("img",{ref:i,src:a,alt:E_(),crossOrigin:"anonymous",className:"absolute origin-center max-w-none pointer-events-none transition-transform duration-75 select-none",style:{top:"50%",left:"50%",transform:`translate(-50%, -50%) translate(${c.x}px, ${c.y}px) scale(${s})`,maxHeight:"100%"}}),t("div",{className:"absolute inset-0 pointer-events-none border-[3px] border-primary/90 rounded-full"}),t("div",{className:"absolute inset-0 pointer-events-none bg-black/40",style:{clipPath:"polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%)",maskImage:"radial-gradient(circle, transparent 122px, black 123px)",WebkitMaskImage:"radial-gradient(circle, transparent 122px, black 123px)"}})]}),o("div",{className:"w-full flex items-center gap-3 px-2",children:[t(is,{className:"w-4 h-4 text-muted-foreground"}),t("input",{type:"range",min:"1.0",max:"3.0",step:"0.01",value:s,onChange:(T)=>d(parseFloat(T.target.value)),className:"flex-1 h-1.5 bg-muted rounded-lg appearance-none cursor-pointer accent-primary focus:outline-none"}),t(os,{className:"w-4 h-4 text-muted-foreground"})]})]}),o(qe,{className:"p-6 border-t border-border/40 bg-muted/20 flex flex-row justify-end gap-3",children:[t(E,{variant:"outline",onClick:r,disabled:b,children:De()}),t(E,{onClick:oe,disabled:b||!a,className:"min-w-[80px]",children:b?o(L,{children:[t(O,{className:"w-4 h-4 animate-spin mr-2"}),Wg()]}):xo()})]})]})})}var Gr=["general","transcode","quotas","appearance","email","skills","mcp","providers","image-video","agents","sandbox","notifications","developer"],Wr=["480p","720p","1080p","1440p","2160p"],Zr=["480p","720p","1080p","1440p","2160p"];function Zs({teamId:e,settingKey:r,field:a,serverResolutions:l,defaultResolutions:s}){let d=Q(),c=y(null),[g,_]=u(null),p=y(Promise.resolve()),b=y(!1);return h(()=>{if(!b.current)c.current=null,_(null)},[l]),{currentResolutions:g??l??s,handleToggle:(i)=>{let v=c.current??g??l??s;if(v.includes(i)&&v.length===1)return;let w=v.includes(i)?v.filter((k)=>k!==i):[...v,i];if(w.length===0)return;c.current=w,_(w),d.setQueryData(["teams",e,"settings"],(k)=>{if(!k)return k;return{...k,transcode:{...k.transcode,[a]:w}}}),b.current=!0,p.current=p.current.then(async()=>{let k=c.current;if(!k)return;let z=await A.api.teams[":teamId"].settings.$patch({param:{teamId:e},json:{key:r,value:k}});if(!z.ok)throw Error("Failed to update settings");if(await z.json(),c.current===k)c.current=null,b.current=!1,_(null),await d.invalidateQueries({queryKey:["teams",e,"settings"]}),M.success(Gc())}).catch((k)=>{console.error(k),c.current=null,b.current=!1,_(null),d.invalidateQueries({queryKey:["teams",e,"settings"]}),M.error(Nh())})}}}function Xs(){if(typeof window>"u")return"general";let e=window.location.hash.replace(/^#/,"");return Gr.includes(e)?e:"general"}function Xr(){let{teamId:e}=Yr.useParams(),r=Q(),[a,l]=u(Xs),s=(U)=>{l(U);let _e=U==="general"?"":`#${U}`;if(window.location.hash!==_e)window.history.replaceState(null,"",window.location.pathname+window.location.search+_e)};h(()=>{let U=()=>{l(Xs())};return window.addEventListener("hashchange",U),()=>window.removeEventListener("hashchange",U)},[]);let[d,c]=u(""),[g,_]=u(!1),[p,b]=u(null),x=y(null),[m,i]=u(!1),{setMetadata:v,getMetadata:w}=Ar(),k=w("locale")||n(),z=async(U)=>{if(U==="en"||U==="zh")try{await v(e,"locale",U),Pa(U),M.success(ww())}catch(_e){console.error(_e),M.error(lv())}},{data:J,isLoading:H,error:ie}=Z({queryKey:["teams",e,"settings"],queryFn:async()=>{let U=await A.api.teams[":teamId"].settings.$get({param:{teamId:e}});if(!U.ok)throw Error("Failed to fetch settings");return await U.json()}}),{data:oe,isLoading:T}=Z({queryKey:["teams",e,"me"],queryFn:async()=>{let U=await A.api.teams[":teamId"].me.$get({param:{teamId:e}});if(!U.ok)throw Error("Failed to fetch me");return await U.json()},enabled:!!e});h(()=>{if(oe?.name)c(oe.name)},[oe]),h(()=>{let U=["transcode","quotas","appearance","email","providers","image-video","skills","mcp","agents","sandbox"];if(oe&&oe.role!=="owner"&&U.includes(a))s("general")},[oe,a]);let P=(U)=>{if(!U)return"U";let _e=U.split(" ");if(_e.length>1)return`${_e[0][0]}${_e[_e.length-1][0]}`.toUpperCase();return U.substring(0,2).toUpperCase()},j=(U)=>{let _e=U.target.files?.[0];if(_e){let Se=new FileReader;Se.onload=()=>{b(Se.result),_(!0)},Se.readAsDataURL(_e),U.target.value=""}},X=async(U)=>{i(!0);try{let _e=new File([U],"avatar.jpg",{type:"image/jpeg"}),Se=await A.api.teams[":teamId"].files.$post({param:{teamId:e},form:{file:_e}});if(!Se.ok)throw Error("Failed to upload avatar");let Qt=(await Se.json()).key;if(!(await A.api.teams[":teamId"].me.$patch({param:{teamId:e},json:{imageKey:Qt}})).ok)throw Error("Failed to save profile");M.success(C_()),r.invalidateQueries({queryKey:["teams",e,"me"]}),_(!1)}catch(_e){console.error(_e),M.error(av())}finally{i(!1)}},F=async()=>{i(!0);try{if(!(await A.api.teams[":teamId"].me.$patch({param:{teamId:e},json:{imageKey:null}})).ok)throw Error("Failed to remove avatar");M.success(S_()),r.invalidateQueries({queryKey:["teams",e,"me"]})}catch(U){console.error(U),M.error(Gb())}finally{i(!1)}},Y=async()=>{if(!d.trim())return;i(!0);try{if(!(await A.api.teams[":teamId"].me.$patch({param:{teamId:e},json:{name:d.trim()}})).ok)throw Error("Failed to update name");M.success(Cg()),r.invalidateQueries({queryKey:["teams",e,"me"]})}catch(U){console.error(U),M.error(cv())}finally{i(!1)}},{mutate:ye}=B({mutationFn:async(U)=>{let _e=await A.api.teams[":teamId"].settings.$patch({param:{teamId:U.teamId},json:U.data});if(!_e.ok)throw Error("Failed to update settings");return await _e.json()},onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"settings"]}),M.success(Gc())},onError:()=>{M.error(Nh())}}),me=(U)=>{ye({teamId:e,data:{key:"transcode.videoStrategy",value:U}})},{currentResolutions:Ee,handleToggle:Fe}=Zs({teamId:e,settingKey:"transcode.videoResolutions",field:"videoResolutions",serverResolutions:J?.transcode?.videoResolutions,defaultResolutions:TA}),{currentResolutions:se,handleToggle:ke}=Zs({teamId:e,settingKey:"transcode.hlsResolutions",field:"hlsResolutions",serverResolutions:J?.transcode?.hlsResolutions,defaultResolutions:MA}),je=(U)=>{ye({teamId:e,data:{key:"transcode.hardwareAcceleration",value:U}})},[He,G]=u(null),ee=J?.transcode?.threads??0;h(()=>{G(null)},[ee]);let xe=(U)=>{ye({teamId:e,data:{key:"transcode.threads",value:U}})},de=(U)=>{ye({teamId:e,data:{key:"transcode.hlsEnabled",value:U}})};if(H||T)return t("div",{className:"flex h-screen items-center justify-center",children:t(O,{className:"h-8 w-8 animate-spin text-muted-foreground"})});if(ie)return t("div",{className:"p-8 text-center text-red-500",children:Jo()});let Ke=J?.transcode?.videoStrategy||Hs.best_match;if(Ke==="single"||Ke==="disable")Ke=Hs.best_match;else if(Ke==="full"||Ke==="all"||Ke==="multi")Ke=Hs.multi;let bt=J?.transcode?.hardwareAcceleration||Ua.off,re=He??ee,Ye=J?.transcode?.hlsEnabled??!1;return t("div",{className:"h-full bg-background font-sans selection:bg-primary/20 transition-colors duration-300",children:o("div",{className:"flex flex-col md:flex-row h-full",children:[t("div",{className:"w-full h-full md:w-72 bg-sidebar border-b md:border-b-0 md:border-r border-sidebar-border z-10 md:left-16 overflow-y-auto transition-colors duration-300",children:o("nav",{className:"p-4 space-y-1 mt-4",children:[t("div",{className:"mb-2 px-4 text-xs font-semibold text-sidebar-foreground/60 uppercase tracking-wider",children:oE()}),o("button",{onClick:()=>s("general"),className:C("w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-lg transition-all",a==="general"?"bg-sidebar-accent text-sidebar-accent-foreground ring-1 ring-sidebar-border":"text-sidebar-foreground/75 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"),children:[t(Vn,{className:"w-5 h-5"}),Nv(),a==="general"&&t("div",{className:"ml-auto w-1.5 h-1.5 rounded-full bg-sidebar-primary"})]}),o("button",{onClick:()=>s("notifications"),className:C("w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-lg transition-all",a==="notifications"?"bg-sidebar-accent text-sidebar-accent-foreground ring-1 ring-sidebar-border":"text-sidebar-foreground/75 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"),children:[t(ha,{className:"w-5 h-5"}),hg(),a==="notifications"&&t("div",{className:"ml-auto w-1.5 h-1.5 rounded-full bg-sidebar-primary"})]}),o("button",{onClick:()=>s("developer"),className:C("w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-lg transition-all",a==="developer"?"bg-sidebar-accent text-sidebar-accent-foreground ring-1 ring-sidebar-border":"text-sidebar-foreground/75 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"),children:[t(Xt,{className:"w-5 h-5"}),Ym(),a==="developer"&&t("div",{className:"ml-auto w-1.5 h-1.5 rounded-full bg-sidebar-primary"})]}),oe?.role==="owner"&&o(L,{children:[t("div",{className:"mt-6 mb-2 px-4 text-xs font-semibold text-sidebar-foreground/60 uppercase tracking-wider pt-4 border-t border-sidebar-border",children:xT()}),o("button",{onClick:()=>s("transcode"),className:C("w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-lg transition-all",a==="transcode"?"bg-sidebar-accent text-sidebar-accent-foreground ring-1 ring-sidebar-border":"text-sidebar-foreground/75 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"),children:[t(Ja,{className:"w-5 h-5"}),xA(),a==="transcode"&&t("div",{className:"ml-auto w-1.5 h-1.5 rounded-full bg-sidebar-primary"})]}),o("button",{onClick:()=>s("quotas"),className:C("w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-lg transition-all",a==="quotas"?"bg-sidebar-accent text-sidebar-accent-foreground ring-1 ring-sidebar-border":"text-sidebar-foreground/75 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"),children:[t(Bo,{className:"w-5 h-5"}),Ld(),a==="quotas"&&t("div",{className:"ml-auto w-1.5 h-1.5 rounded-full bg-sidebar-primary"})]}),o("button",{onClick:()=>s("appearance"),className:C("w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-lg transition-all",a==="appearance"?"bg-sidebar-accent text-sidebar-accent-foreground ring-1 ring-sidebar-border":"text-sidebar-foreground/75 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"),children:[t(Ql,{className:"w-5 h-5"}),Cf(),a==="appearance"&&t("div",{className:"ml-auto w-1.5 h-1.5 rounded-full bg-sidebar-primary"})]}),o("button",{onClick:()=>s("email"),className:C("w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-lg transition-all",a==="email"?"bg-sidebar-accent text-sidebar-accent-foreground ring-1 ring-sidebar-border":"text-sidebar-foreground/75 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"),children:[t(fi,{className:"w-5 h-5"}),bh(),a==="email"&&t("div",{className:"ml-auto w-1.5 h-1.5 rounded-full bg-sidebar-primary"})]})]}),oe?.role==="owner"&&o(L,{children:[t("div",{className:"mt-6 mb-2 px-4 text-xs font-semibold text-sidebar-foreground/60 uppercase tracking-wider pt-4 border-t border-sidebar-border",children:yT()}),o("button",{onClick:()=>s("providers"),className:C("w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-lg transition-all",a==="providers"?"bg-sidebar-accent text-sidebar-accent-foreground ring-1 ring-sidebar-border":"text-sidebar-foreground/75 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"),children:[t(io,{className:"w-5 h-5"}),PE(),a==="providers"&&t("div",{className:"ml-auto w-1.5 h-1.5 rounded-full bg-sidebar-primary"})]}),o("button",{onClick:()=>s("image-video"),className:C("w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-lg transition-all",a==="image-video"?"bg-sidebar-accent text-sidebar-accent-foreground ring-1 ring-sidebar-border":"text-sidebar-foreground/75 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"),children:[t(dn,{className:"w-5 h-5"}),jh(),a==="image-video"&&t("div",{className:"ml-auto w-1.5 h-1.5 rounded-full bg-sidebar-primary"})]}),o("button",{onClick:()=>s("skills"),className:C("w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-lg transition-all",a==="skills"?"bg-sidebar-accent text-sidebar-accent-foreground ring-1 ring-sidebar-border":"text-sidebar-foreground/75 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"),children:[t(Nt,{className:"w-5 h-5"}),lA(),a==="skills"&&t("div",{className:"ml-auto w-1.5 h-1.5 rounded-full bg-sidebar-primary"})]}),o("button",{onClick:()=>s("mcp"),className:C("w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-lg transition-all",a==="mcp"?"bg-sidebar-accent text-sidebar-accent-foreground ring-1 ring-sidebar-border":"text-sidebar-foreground/75 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"),children:[t(vn,{className:"w-5 h-5"}),Hc(),a==="mcp"&&t("div",{className:"ml-auto w-1.5 h-1.5 rounded-full bg-sidebar-primary"})]}),o("button",{onClick:()=>s("agents"),className:C("w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-lg transition-all",a==="agents"?"bg-sidebar-accent text-sidebar-accent-foreground ring-1 ring-sidebar-border":"text-sidebar-foreground/75 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"),children:[t(Ct,{className:"w-5 h-5"}),O0(),a==="agents"&&t("div",{className:"ml-auto w-1.5 h-1.5 rounded-full bg-sidebar-primary"})]}),o("button",{onClick:()=>s("sandbox"),className:C("w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-lg transition-all",a==="sandbox"?"bg-sidebar-accent text-sidebar-accent-foreground ring-1 ring-sidebar-border":"text-sidebar-foreground/75 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"),children:[t(Kl,{className:"w-5 h-5"}),p0(),a==="sandbox"&&t("div",{className:"ml-auto w-1.5 h-1.5 rounded-full bg-sidebar-primary"})]})]})]})}),t("main",{className:"flex-1 bg-background/50 h-full flex flex-col transition-colors duration-300 overflow-y-hidden",children:o("div",{className:"flex-1 flex flex-col max-w-4xl w-full mx-auto p-6 md:p-10 overflow-hidden",children:[t("div",{className:"flex-none flex items-center justify-between mb-6",children:o("div",{children:[o("h2",{className:"text-2xl font-bold text-foreground",children:[a==="general"&&Bh(),a==="transcode"&&xA(),a==="quotas"&&Gg(),a==="appearance"&&Jm(),a==="email"&&bh(),a==="skills"&&cA(),a==="mcp"&&Hc(),a==="providers"&&q0(),a==="image-video"&&jh(),a==="agents"&&j0(),a==="sandbox"&&m0(),a==="notifications"&&bS(),a==="developer"&&sb()]}),o("p",{className:"text-sm text-muted-foreground mt-1",children:[a==="general"&&Ov(),a==="transcode"&&g1(),a==="quotas"&&Vg(),a==="appearance"&&Xm(),a==="email"&&_b(),a==="skills"&&MI(),a==="mcp"&&xd(),a==="providers"&&NE(),a==="image-video"&&dx(),a==="agents"&&F0(),a==="sandbox"&&kC(),a==="notifications"&&wS(),a==="developer"&&ob()]})]})}),o("div",{className:"flex-1 overflow-hidden animate-in fade-in slide-in-from-bottom-4 duration-500",children:[a==="general"&&o("div",{className:"h-full overflow-y-auto space-y-6 pr-1",children:[o(ut,{children:[o(Tt,{children:[t(Mt,{children:rE()}),t(Ot,{children:nE()})]}),t(xt,{className:"space-y-6",children:o("div",{className:"flex flex-col md:flex-row gap-8 items-start",children:[o("div",{className:"flex flex-col items-center gap-3",children:[t("span",{className:"text-sm font-medium text-muted-foreground",children:x_()}),o("div",{className:"group relative cursor-pointer overflow-hidden rounded-full w-24 h-24 border border-border/60 shadow-md transition-all hover:opacity-90",onClick:()=>x.current?.click(),children:[o(Ce,{className:"w-24 h-24",children:[oe?.image&&t(Ie,{src:oe.image,alt:oe.name,className:"object-cover w-24 h-24"}),t(Te,{className:"text-2xl bg-primary/40 text-foreground",children:P(oe?.name)})]}),t("div",{className:"absolute inset-0 bg-black/40 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:t("span",{className:"text-white text-xs font-semibold",children:O_()})})]}),o("div",{className:"flex gap-2",children:[t(E,{variant:"outline",size:"sm",onClick:()=>x.current?.click(),children:s1()}),oe?.image&&t(E,{variant:"ghost",size:"sm",className:"text-red-500 hover:text-red-600",onClick:F,children:Ml()})]}),t("input",{type:"file",ref:x,className:"hidden",accept:"image/*",onChange:j})]}),o("div",{className:"flex-1 space-y-4 w-full",children:[o("div",{className:"space-y-2",children:[t("label",{className:"text-sm font-medium text-muted-foreground",children:wl()}),t(q,{value:d,onChange:(U)=>c(U.target.value),placeholder:Pb(),className:"max-w-md"})]}),o("div",{className:"space-y-2",children:[t("label",{className:"text-sm font-medium text-muted-foreground",children:Zf()}),t(q,{value:oe?.email||"",disabled:!0,className:"max-w-md bg-muted/50 cursor-not-allowed"}),t("p",{className:"text-xs text-muted-foreground",children:Ab()})]}),o(E,{onClick:Y,disabled:m||!d.trim(),className:"mt-2",children:[m&&t(O,{className:"w-4 h-4 animate-spin mr-2"}),qs()]})]})]})})]}),o(ut,{className:"border border-slate-200 dark:border-slate-800 mt-6",children:[o(Tt,{children:[t(Mt,{children:vw()}),t(Ot,{children:rI()})]}),t(xt,{className:"space-y-4",children:t("div",{className:"max-w-xs",children:o(Le,{value:k,onValueChange:z,children:[t(Be,{children:t(Ze,{placeholder:JC()})}),o(Ue,{children:[t(ne,{value:"en",children:Ib()}),t(ne,{value:"zh",children:Z_()})]})]})})})]}),t(Ws,{isOpen:g,onClose:()=>_(!1),imageSrc:p,onConfirm:X})]}),a==="transcode"&&o("div",{className:"h-full overflow-y-auto space-y-6 pr-1 pb-8",children:[o(ut,{children:[o(Tt,{children:[t(Mt,{children:QT()}),t(Ot,{children:KT()})]}),o(xt,{className:"space-y-6",children:[o("div",{className:"space-y-4",children:[o("div",{className:"space-y-0.5",children:[t("h3",{className:"text-lg font-medium",children:kx()}),t("p",{className:"text-sm text-muted-foreground",children:Rx()})]}),o("div",{className:"space-y-3",children:[o("div",{className:C("cursor-pointer rounded-lg border p-4 transition-all hover:border-primary",Ke===Hs.best_match?"border-primary bg-primary/5":"border-border"),onClick:()=>me(Hs.best_match),children:[t("div",{className:"font-semibold",children:k_()}),t("div",{className:"text-sm text-muted-foreground",children:R_()})]}),o("div",{className:C("cursor-pointer rounded-lg border p-4 transition-all hover:border-primary",Ke===Hs.multi?"border-primary bg-primary/5":"border-border"),onClick:()=>me(Hs.multi),children:[t("div",{className:"font-semibold",children:Px()}),t("div",{className:"text-sm text-muted-foreground",children:Nx()})]}),Ke===Hs.multi&&o("div",{className:"space-y-3 pt-2 pl-1",children:[o("div",{className:"space-y-1",children:[t("h4",{className:"text-sm font-medium",children:m1()}),t("p",{className:"text-xs text-muted-foreground",children:h1()})]}),t("div",{className:"flex flex-wrap gap-4 pt-1",children:Wr.map((U)=>{let _e=Ee.includes(U),Se=_e&&Ee.length===1;return o("label",{className:C("flex items-center space-x-2 text-sm",Se?"cursor-not-allowed opacity-50":"cursor-pointer"),children:[t(vr,{checked:_e,disabled:Se,onCheckedChange:()=>Fe(U)}),t("span",{children:U})]},U)})})]})]})]}),o("div",{className:"space-y-4 pt-6 border-t border-border",children:[o("div",{className:"flex items-center justify-between",children:[o("div",{className:"space-y-0.5",children:[t("h3",{className:"text-lg font-medium",children:sw()}),t("p",{className:"text-sm text-muted-foreground",children:iw()})]}),t(Me,{checked:Ye,onCheckedChange:de})]}),Ye&&o("div",{className:"space-y-3 pt-2 pl-1",children:[o("div",{className:"space-y-1",children:[t("h4",{className:"text-sm font-medium",children:nw()}),t("p",{className:"text-xs text-muted-foreground",children:ow()})]}),t("div",{className:"flex flex-wrap gap-4 pt-1",children:Zr.map((U)=>{let _e=se.includes(U),Se=_e&&se.length===1;return o("label",{className:C("flex items-center space-x-2 text-sm",Se?"cursor-not-allowed opacity-50":"cursor-pointer"),children:[t(vr,{checked:_e,disabled:Se,onCheckedChange:()=>ke(U)}),t("span",{children:U})]},U)})})]})]})]})]}),o(ut,{children:[o(Tt,{children:[t(Mt,{children:Kv()}),t(Ot,{children:ew()})]}),o(xt,{className:"space-y-3",children:[o("div",{className:C("cursor-pointer rounded-lg border p-4 transition-all hover:border-primary",bt===Ua.off?"border-primary bg-primary/5":"border-border"),onClick:()=>je(Ua.off),children:[t("div",{className:"font-semibold",children:Jv()}),t("div",{className:"text-sm text-muted-foreground",children:Xv()})]}),o("div",{className:C("cursor-pointer rounded-lg border p-4 transition-all hover:border-primary",bt===Ua.auto?"border-primary bg-primary/5":"border-border"),onClick:()=>je(Ua.auto),children:[t("div",{className:"font-semibold",children:Wv()}),t("div",{className:"text-sm text-muted-foreground",children:Yv()})]})]})]}),o(ut,{children:[t(Tt,{children:o("div",{className:"flex items-center justify-between",children:[o("div",{children:[t(Mt,{children:fv()}),t(Ot,{className:"mt-1.5",children:pv()})]}),t("span",{className:"font-mono text-sm font-semibold px-2.5 py-1 rounded bg-muted text-foreground border border-border",children:re===0?_A():ZT({count:re})})]})}),t(xt,{children:o("div",{className:"pt-2 px-1",children:[t(Uo,{value:[re],min:0,max:32,step:1,onValueChange:([U])=>G(U),onValueCommit:([U])=>{G(U),xe(U)}}),o("div",{className:"flex justify-between text-xs text-muted-foreground mt-2",children:[o("span",{children:[_A()," (0)"]}),t("span",{children:"16"}),t("span",{children:"32"})]})]})})]})]}),a==="skills"&&t("div",{className:"h-full overflow-y-auto pr-1",children:t(Es,{teamId:e})}),a==="mcp"&&t("div",{className:"h-full overflow-y-auto pr-1",children:t(Ls,{teamId:e})}),a==="providers"&&t(Is,{teamId:e}),a==="image-video"&&t(Gs,{teamId:e}),a==="agents"&&t("div",{className:"h-full overflow-y-auto pr-1",children:t(Ms,{teamId:e})}),a==="sandbox"&&t("div",{className:"h-full overflow-y-auto pr-1",children:t(Ts,{teamId:e})}),a==="notifications"&&t(Ps,{teamId:e}),a==="developer"&&t(Rs,{teamId:e}),a==="quotas"&&t(js,{teamId:e}),a==="appearance"&&t(Os,{teamId:e}),a==="email"&&t(Ks,{teamId:e})]})]})})]})})}var Yr=ze("/teams/$teamId/settings")({component:Xr});export{Yr as Route};
|