@shumai-one/shumai 0.4.9 → 0.5.0
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-ckd5hnd0.js → chunk-03bfjh8k.js} +2 -2
- package/bin/{chunk-spm13ndr.js → chunk-0tf15vee.js} +2 -2
- package/bin/{chunk-ryvq9pbw.js → chunk-0vtk7wrf.js} +2 -2
- package/bin/{chunk-1v11geh0.js → chunk-0yv0nnmh.js} +2 -2
- package/bin/{chunk-tcyp8qtg.js → chunk-12npypek.js} +2 -2
- package/bin/chunk-13d525jm.js +2 -0
- package/bin/{chunk-snedd3at.js → chunk-1k16xsqq.js} +9 -9
- package/bin/{chunk-yyj21k15.js → chunk-1yt1gsyy.js} +1 -1
- package/bin/{chunk-0w3388vp.js → chunk-20anqpf1.js} +2 -2
- package/bin/{chunk-v2vdm22x.js → chunk-2g5qdx4s.js} +1 -1
- package/bin/{chunk-9fe75ns9.js → chunk-31vx01aw.js} +2 -2
- package/bin/{chunk-sg8hjkyg.js → chunk-32japja5.js} +1 -1
- package/bin/chunk-35mpp84e.js +2 -0
- package/bin/{chunk-6m44n3ms.js → chunk-36r20sj7.js} +1 -1
- package/bin/{chunk-rv15x8aw.js → chunk-3btc8a0p.js} +1 -1
- package/bin/{chunk-82cg5497.js → chunk-3cvbb6kh.js} +2 -2
- package/bin/chunk-3ewmtf1c.js +1 -0
- package/bin/chunk-3fjgf7eb.js +3 -0
- package/bin/chunk-3xw70yr4.js +2 -0
- package/bin/{chunk-nr80mrry.js → chunk-3z20b2hz.js} +2 -2
- package/bin/{chunk-6vqga3ma.js → chunk-3zvvct3r.js} +1 -1
- package/bin/{chunk-f3f6cary.js → chunk-51h2bgpf.js} +3 -3
- package/bin/{chunk-ytffpk7c.js → chunk-5bpvwv66.js} +2 -2
- package/bin/{chunk-eedhf8eb.js → chunk-5jbx9gqe.js} +1 -1
- package/bin/{chunk-sby10fz6.js → chunk-5patxztz.js} +4 -4
- package/bin/chunk-5seey9ee.js +2 -0
- package/bin/{chunk-c7hr2jga.js → chunk-5t05jpna.js} +3 -3
- package/bin/{chunk-c0wqfya9.js → chunk-5yd9cv7f.js} +5 -5
- package/bin/{chunk-8mhj6r2q.js → chunk-628k58ek.js} +2 -2
- package/bin/chunk-66hdwm6f.js +2 -0
- package/bin/{chunk-g6rw4jj5.js → chunk-6bgbx563.js} +2 -2
- package/bin/{chunk-tefct00a.js → chunk-6vvs18bw.js} +1 -1
- package/bin/chunk-756mr32b.js +2 -0
- package/bin/{chunk-gj0yxtqz.js → chunk-7vd5yajk.js} +7 -7
- package/bin/{chunk-qah2r4xa.js → chunk-7wb3dga5.js} +1 -1
- package/bin/{chunk-e2qn4d57.js → chunk-9h6nn1a3.js} +1 -1
- package/bin/chunk-9k86d2a3.js +4 -0
- package/bin/chunk-9wk11jtz.js +1 -0
- package/bin/chunk-a1crhhzy.js +1 -0
- package/bin/chunk-axfwh5et.js +2 -0
- package/bin/{chunk-rd5ek2sk.js → chunk-b9j5575n.js} +2 -2
- package/bin/chunk-cgsxyw07.js +2 -0
- package/bin/{chunk-kn82bccp.js → chunk-cw8z9w5c.js} +2 -2
- package/bin/{chunk-qa7pphr5.js → chunk-czny5thj.js} +2 -2
- package/bin/{chunk-sfwmwrq3.js → chunk-d7mgjqf8.js} +1 -1
- package/bin/{chunk-46hmh2ag.js → chunk-d9btz95y.js} +1 -1
- package/bin/chunk-dckdnqc0.js +2 -0
- package/bin/chunk-dx0wz749.js +211 -0
- package/bin/{chunk-2txahdj8.js → chunk-dz33q4v1.js} +2 -2
- package/bin/chunk-dz4fdrmk.js +1 -0
- package/bin/{chunk-nz16584e.js → chunk-e3r1m6rb.js} +1 -1
- package/bin/chunk-edjtb7pk.js +2 -0
- package/bin/{chunk-7hmt2gs5.js → chunk-eez1yncf.js} +1 -1
- package/bin/{chunk-zhtc1j3r.js → chunk-exgtwask.js} +1 -1
- package/bin/{chunk-fw5xzcnf.js → chunk-f22nrm6r.js} +4 -4
- package/bin/{chunk-q6k1ctph.js → chunk-fhq5m9ya.js} +2 -2
- package/bin/{chunk-ns8whqp6.js → chunk-fyssg02c.js} +30 -30
- package/bin/{chunk-09367z2r.js → chunk-g8h1e1kh.js} +2 -2
- package/bin/{chunk-kemfwmyq.js → chunk-ghjhyajn.js} +2 -2
- package/bin/{chunk-8r9q7xcv.js → chunk-gptzcgte.js} +1 -1
- package/bin/{chunk-2j31y48k.js → chunk-grsgkkrb.js} +5 -5
- package/bin/{chunk-1kr1jsrt.js → chunk-gy8z8sd7.js} +1 -1
- package/bin/{chunk-p4nbgn3v.js → chunk-h153xefb.js} +1 -1
- package/bin/chunk-h82r29wm.js +129 -0
- package/bin/{chunk-6yayg55q.js → chunk-h9x81yp6.js} +1 -1
- package/bin/{chunk-v2901ff5.js → chunk-hr2027z3.js} +8 -8
- package/bin/{chunk-xw7jea6g.js → chunk-hx76pje1.js} +1 -1
- package/bin/chunk-hz9stgvn.js +1 -0
- package/bin/chunk-hzr8100w.js +3 -0
- package/bin/{chunk-5w7yxz6p.js → chunk-j3xaq9s3.js} +2 -2
- package/bin/{chunk-5e4de0a1.js → chunk-j909v9p5.js} +1 -1
- package/bin/chunk-jb6d142z.js +1 -0
- package/bin/chunk-k9cgfzgk.js +3 -0
- package/bin/{chunk-0mv8jp7h.js → chunk-kgfa5y9w.js} +8 -8
- package/bin/{chunk-jxfz4h24.js → chunk-kzsdp31a.js} +2 -2
- package/bin/{chunk-ht4chp45.js → chunk-m1xc3t0p.js} +7 -7
- package/bin/{chunk-sedbz4km.js → chunk-m7dp8rqv.js} +1 -1
- package/bin/{chunk-46brm12f.js → chunk-m9sp00a9.js} +4 -4
- package/bin/{chunk-pw81eh3g.js → chunk-mcd7zas7.js} +2 -2
- package/bin/chunk-meyvvmgk.js +1 -0
- package/bin/{chunk-4cj3pz27.js → chunk-mqr096rn.js} +1 -1
- package/bin/{chunk-yfjyjjpz.js → chunk-mt532a33.js} +1 -1
- package/bin/{chunk-dzj91k6v.js → chunk-myd3wg9a.js} +2 -2
- package/bin/chunk-n1b3pt17.js +14 -0
- package/bin/chunk-n5v48hz5.js +2 -0
- package/bin/{chunk-zpk482rb.js → chunk-p5v22g5n.js} +2 -2
- package/bin/chunk-phzemmmy.js +2 -0
- package/bin/{chunk-jyg525f5.js → chunk-q5mkbnr9.js} +2 -2
- package/bin/chunk-qhzat67w.js +2 -0
- package/bin/{chunk-7zfyrt40.js → chunk-r1m4q8vw.js} +1 -1
- package/bin/{chunk-41fbx9mc.js → chunk-r5rpdhed.js} +2 -2
- package/bin/{chunk-d70acjwn.js → chunk-r6gkv98n.js} +5 -5
- package/bin/{chunk-p46em0kf.js → chunk-rkq6jvhb.js} +3 -3
- package/bin/{chunk-0g7ayjb5.js → chunk-rn9rktp4.js} +5 -5
- package/bin/{chunk-g7qejgap.js → chunk-rq2h2bwt.js} +2 -2
- package/bin/{chunk-yet4fnab.js → chunk-sg7n2g3z.js} +1 -1
- package/bin/chunk-smcn7ep7.js +2 -0
- package/bin/{chunk-cphwmdq5.js → chunk-tcat7q9p.js} +2 -2
- package/bin/{chunk-anky1dmg.js → chunk-tf8q7h6b.js} +1 -1
- package/bin/{chunk-bg2vgnzt.js → chunk-trndqdaa.js} +1 -1
- package/bin/chunk-tvr5rm1g.js +1 -0
- package/bin/chunk-ty88m3yg.js +2 -0
- package/bin/chunk-v2x9915x.js +1 -0
- package/bin/{chunk-tnv4ggx2.js → chunk-v42jcex0.js} +4 -4
- package/bin/{chunk-n6sny5c8.js → chunk-vbbn4hth.js} +1 -1
- package/bin/chunk-vnk2p7mq.css +1 -0
- package/bin/{chunk-r7e2fmmx.js → chunk-wkxm6yny.js} +2 -2
- package/bin/{chunk-6mnj9adr.js → chunk-wydd7sz7.js} +2 -2
- package/bin/chunk-x8hky9td.js +1 -0
- package/bin/{chunk-rbh4w2v2.js → chunk-xvdd04gy.js} +1 -1
- package/bin/{chunk-m0xbfmf0.js → chunk-y03z5rrg.js} +3 -3
- package/bin/{chunk-h29rwayb.js → chunk-y12ah7c6.js} +1 -1
- package/bin/{chunk-zy32pf0s.js → chunk-y7jz31ay.js} +1 -1
- package/bin/chunk-ydk3edsw.js +1 -0
- package/bin/{chunk-thzf89fp.js → chunk-yfe6hkzk.js} +3 -3
- package/bin/{chunk-aant41bd.js → chunk-z1r86fna.js} +2 -2
- package/bin/{chunk-szjkmkwc.js → chunk-z8mmqfm4.js} +1 -1
- package/bin/chunk-zbma2zeh.js +1 -0
- package/bin/{chunk-jpjc44j6.js → chunk-zcrtr8qd.js} +2 -2
- package/bin/{chunk-c3010erf.js → chunk-zfqz72sd.js} +1 -1
- package/bin/{chunk-6snwrej9.js → chunk-zhe16jvg.js} +1 -1
- package/bin/{chunk-8mjb093y.js → chunk-zwb9kamp.js} +2 -2
- package/bin/shumai-app.html +1 -1
- package/bin/shumai-app.js +360 -353
- package/package.json +9 -8
- package/prisma/migrations/20261001015042_migrate_video_strategy_multi_and_resolutions/migration.sql +16 -0
- package/prisma/migrations/20261002104921_add_asset_status_failed/migration.sql +2 -0
- package/prisma/schema.prisma +1 -0
- package/bin/chunk-01v2xh5b.js +0 -1
- package/bin/chunk-15n1v8mm.js +0 -1
- package/bin/chunk-17k9a427.js +0 -211
- package/bin/chunk-258tjpym.js +0 -1
- package/bin/chunk-2ar64j3z.js +0 -2
- package/bin/chunk-2kxhdnma.js +0 -3
- package/bin/chunk-315w58w6.js +0 -3
- package/bin/chunk-4sqbjvjt.js +0 -2
- package/bin/chunk-c8aw8dye.js +0 -2
- package/bin/chunk-e2724ggn.js +0 -2
- package/bin/chunk-e2j3vwcv.js +0 -2
- package/bin/chunk-ef3av8ay.js +0 -1
- package/bin/chunk-fjvbgahx.css +0 -1
- package/bin/chunk-fw0f45qw.js +0 -2
- package/bin/chunk-gvbajsje.js +0 -1
- package/bin/chunk-h37zfvmp.js +0 -3
- package/bin/chunk-jraqe5z0.js +0 -2
- package/bin/chunk-jy8by162.js +0 -1
- package/bin/chunk-jz9mcrj6.js +0 -1
- package/bin/chunk-k4n9rdq3.js +0 -1
- package/bin/chunk-kmx350y5.js +0 -14
- package/bin/chunk-kx0qbs28.js +0 -1
- package/bin/chunk-nhfbnqdr.js +0 -2
- package/bin/chunk-p7j6zgdg.js +0 -2
- package/bin/chunk-pbyp1xnb.js +0 -2
- package/bin/chunk-r4w1e3bd.js +0 -2
- package/bin/chunk-s9whhdb3.js +0 -2
- package/bin/chunk-ss1jchgx.js +0 -1
- package/bin/chunk-t0nktwrm.js +0 -1
- package/bin/chunk-t9eb2mdq.js +0 -4
- package/bin/chunk-tptgxbqa.js +0 -2
- package/bin/chunk-v8ngtwzx.js +0 -299
- package/bin/chunk-xex9v0rn.js +0 -2
- package/bin/chunk-xs2w45vp.js +0 -1
- package/bin/chunk-xza8wate.js +0 -2
package/bin/chunk-h37zfvmp.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{V,D,h,$e,P,b,u,Ns,S,L,t,o,Q,Z,B,Tc,ze,A,I,vr,zn,wr,F,Et,Re,ve,vt,Xt,eo,Wo,ci,vo,pe,Bt,we,Ne,C,ds,E,Ce,Ie,Te,he,ge,Ae,W,Vt,n,ka,PA,yf,BA,UA,bf,zA,od,HA,$A,Cm,Im,VA,QA,JA,XA,e_,t_,n_,o_,s_,i_,l_,c_,u_,d_,f_,km,p_,Rm,m_,Nm,h_,Pm,g_,Dm,A_,Om,__,Fm,y_,Lm,b_,Zm,v_,w_,x_,Bm,S_,E_,C_,Um,zm,jm,qm,I_,T_,D_,O_,F_,U_,z_,j_,G_,id,ad,Gm,V_,Q_,Vm,K_,W_,Qm,Y_,xf,Km,Wm,J_,e0,ld,o0,s0,i0,u0,_0,y0,b0,v0,Jm,x0,S0,E0,C0,I0,T0,Pe,k0,N0,P0,D0,F0,z0,j0,q0,H0,th,G0,V0,J0,ey,sh,Oc,cy,my,hy,gy,_y,yy,wy,Sy,Py,Dy,at,Oy,Fy,Uy,zy,jy,$y,Nf,fh,Qy,Al,Xy,eb,Df,rb,nb,hh,ab,gh,lb,cb,Of,fb,Ah,pb,_h,mb,Ab,_b,bb,Ff,wb,Sb,yh,Ib,Tb,Bs,Yo,zb,qb,wh,Ra,hd,Gb,Vb,xh,Yb,Zf,Ch,Ih,_l,Xb,gd,Th,Mh,tv,rv,nv,iv,av,gv,Av,Cv,Iv,Tv,Oh,Mv,kv,Nv,Pv,Fh,qv,Hv,$v,Gv,Vv,Qv,Kv,Yv,Zh,Xv,ew,tw,iw,aw,lw,cw,uw,dw,Aw,bw,Cw,Iw,Tw,Mw,Yf,kw,Rw,zh,Nw,Pw,Dw,Ow,Fw,jh,qh,Lw,Zw,Bw,Uw,Hh,zw,$h,jw,qw,Gh,zc,bd,Hw,$w,Vh,Gw,Vw,Qw,Kw,Ww,Yw,Jw,Xw,ex,Qh,tx,rx,Jf,Xf,lx,cx,ux,Kh,dx,fx,px,mx,hx,vd,gx,yx,bl,bx,wx,xx,Sx,Ex,Cx,Px,Dx,Zx,sg,Bx,ag,lg,xd,$x,Gx,Vx,sp,ip,Yx,Jx,tS,oS,sS,ug,iS,lS,CS,IS,TS,MS,fg,kS,RS,NS,DS,BS,US,Da,Oa,Fa,zS,jS,qS,$S,KS,WS,JS,yg,dE,fE,pE,mE,vg,wg,xg,Sg,hE,Eg,Cg,Ig,Tg,gE,AE,bE,wE,Rg,hp,SE,CE,IE,ME,gp,Ap,_p,yp,PE,Cd,Id,Td,Md,kd,OE,FE,Rd,LE,Nd,ZE,Pd,BE,bp,El,vp,UE,zE,GE,VE,Dd,wp,Cl,Bg,Ug,mC,hC,xo,gC,zs,qg,Tp,Gg,Vg,FC,Qg,Kg,LC,UC,zC,Yg,qC,$C,Jg,WC,Xg,YC,JC,XC,e1,Rp,rA,f1,p1,nA,m1,h1,g1,A1,_1,y1,b1,v1,w1,x1,S1,E1,C1,I1,T1,O1,F1,L1,Z1,B1,U1,z1,j1,q1,H1,$1,G1,V1,Q1,K1,W1,Y1,J1,X1,eI,iI,pI,hI,gI,AI,_I,yI,fA,vI,II,TI,MI,pA,kI,hA,RI,NI,DI,AA,zI,QI,KI,WI,nT,oT,sT,iT,aT,lT,cT,uT,dT,Je,Xe,et,tt,rt,nt,ot,st,ue,ae,fe,qe,le,Ct,H,ce,Dt,k,f,te,R,Ve,ro,Jc,Xc,bA,eu,na,vA,Ai,Za,tu,So,Eo,Qr,kn,be,mt,ht,gt,bi,K,De,Le,Ze,Be,Ue,ne,Dr,lr,gr,_t,kt,Rt,Ut,It,ef}from"./chunk-17k9a427.js";import{Uo}from"./chunk-4sqbjvjt.js";import{Mo,Ar}from"./chunk-rd5ek2sk.js";import{$l,Gl}from"./chunk-2txahdj8.js";import{$s,io,da,Bo,bn,Vl,fa,Ga,Ni,Ql}from"./chunk-jraqe5z0.js";import{Kl}from"./chunk-xza8wate.js";import{Rn,Nn,Pn,br,St,yt}from"./chunk-tcyp8qtg.js";import{pa}from"./chunk-kemfwmyq.js";import{Io}from"./chunk-7hmt2gs5.js";import{To}from"./chunk-qah2r4xa.js";import{Vn,ao}from"./chunk-rv15x8aw.js";import{vn}from"./chunk-g6rw4jj5.js";import{lo}from"./chunk-46hmh2ag.js";import{sn}from"./chunk-qa7pphr5.js";import{co}from"./chunk-80qz30dc.js";import{Rr}from"./chunk-41fbx9mc.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"}]],es=I("at-sign",Js);var er=[["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"}]],ts=I("film",er);var tr=[["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"}]],ua=I("globe",tr);var ar=[["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"}]],Zt=I("key",ar);var sr=[["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"}]],Ia=I("layout-dashboard",sr);var rr=[["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"}]],as=I("maximize-2",rr);var or=[["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"}]],ss=I("message-circle",or);var ir=[["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"}]],rs=I("move",ir);var nr=[["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"}]],wt=I("puzzle",nr);var dr=[["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"}]],ga=I("refresh-cw",dr);var cr=[["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"}]],os=I("send",cr);var mr=[["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"}]],is=I("shield-check",mr);var ur=[["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"}]],ha=I("video",ur);var pr=[["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"}]],jt=I("zap",pr);var fr=[["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"}]],ns=I("zoom-in",fr);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:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],ls=I("zoom-out",hr);S();S();var yr=ds("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(K,{"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 sa({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 He({className:e,children:r,errors:a,...l}){let s=P(()=>{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 cs({update:e,notify:r,unwatched:a}){return{link:l,unlink:s,propagate:d,checkDirty:c,shallowPropagate:g};function l(p,y,x){let m=y.depsTail;if(m!==void 0&&m.dep===p)return;let i=m!==void 0?m.nextDep:y.deps;if(i!==void 0&&i.dep===p){i.version=x,y.depsTail=i;return}let v=p.subsTail;if(v!==void 0&&v.version===x&&v.sub===y)return;let w=y.depsTail=p.subsTail={version:x,dep:p,sub:y,prevDep:m,nextDep:i,prevSub:v,nextSub:void 0};if(i!==void 0)i.prevDep=w;if(m!==void 0)m.nextDep=w;else y.deps=w;if(v!==void 0)v.nextSub=w;else p.subs=w}function s(p,y=p.sub){let{dep:x,prevDep:m,nextDep:i,nextSub:v,prevSub:w}=p;if(i!==void 0)i.prevDep=m;else y.depsTail=m;if(m!==void 0)m.nextDep=i;else y.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 y=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:y,prev:x},y=w;continue}}if((p=y)!==void 0){y=p.nextSub;continue}while(x!==void 0)if(p=x.value,x=x.prev,p!==void 0){y=p.nextSub;continue e}break}while(!0)}function c(p,y){let x,m=0,i=!1;e:do{let v=p.dep,w=v.flags;if(y.flags&16)i=!0;else if((w&17)===17){if(e(v)){let M=v.subs;if(M.nextSub!==void 0)g(M);i=!0}}else if((w&33)===33){if(p.nextSub!==void 0||p.prevSub!==void 0)x={value:p,prev:x};p=v.deps,y=v,++m;continue}if(!i){let M=p.nextDep;if(M!==void 0){p=M;continue}}while(m--){let M=y.subs,O=M.nextSub!==void 0;if(O)p=x.value,x=x.prev;else p=M;if(i){if(e(y)){if(O)g(M);y=p.sub;continue}i=!1}else y.flags&=-33;y=p.sub;let Y=p.nextDep;if(Y!==void 0){p=Y;continue e}}return i}while(!0)}function g(p){do{let y=p.sub,x=y.flags;if((x&48)===32){if(y.flags=x|16,(x&6)===2)r(y)}}while((p=p.nextSub)!==void 0)}function _(p,y){let x=y.depsTail;while(x!==void 0){if(x===p)return!0;x=x.prevDep}return!1}}function ra(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 Ea=[],ba=0,{link:ms,unlink:xr,propagate:_r,checkDirty:ps,shallowPropagate:us}=cs({update(e){return e._update()},notify(e){Ea[Ta++]=e,e.flags&=-3},unwatched(e){if(e.depsTail!==void 0)e.depsTail=void 0,e.flags=17,ya(e)}}),va=0,Ta=0,Nt,Va=0;function Ke(e){try{++Va,e()}finally{if(!--Va)La()}}function ya(e){let r=e.depsTail,a=r!==void 0?r.nextDep:e.deps;while(a!==void 0)a=xr(a,e)}function La(){if(Va>0)return;while(va<Ta){let e=Ea[va];Ea[va++]=void 0,e.notify()}va=0,Ta=0}function xa(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(Nt!==void 0)ms(s,Nt,ba);return s._snapshot},subscribe(d){let c=ra(d),g={current:!1},_=Nr(()=>{if(s.get(),!g.current)g.current=!0;else c.next?.(s._snapshot)});return{unsubscribe:()=>{_.stop()}}},_update(d){let c=Nt,g=r?.compare??Object.is;if(a)Nt=s,++ba,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(Nt=c,a)s.flags&=-5;ya(s)}}};if(a)s.flags=17,s.get=function(){let d=s.flags;if(d&16||d&32&&ps(s.deps,s)){if(s._update()){let c=s.subs;if(c!==void 0)us(c)}}else if(d&32)s.flags=d&-33;if(Nt!==void 0)ms(s,Nt,ba);return s._snapshot};else s.set=function(d){if(s._update(d)){let c=s.subs;if(c!==void 0)_r(c),us(c),La()}};return s}function Nr(e){let r=()=>{let l=Nt;Nt=a,++ba,a.depsTail=void 0,a.flags=6;try{return e()}finally{Nt=l,a.flags&=-5,ya(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&&ps(this.deps,this))r();else this.flags=2},stop(){this.flags=0,this.depsTail=void 0,ya(this)}};return r(),a}var Pa=class{constructor(e,r){if(this.atom=xa(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(ra(e))}},fs=class{constructor(e){this.atom=xa(e)}get state(){return this.atom.get()}get(){return this.state}subscribe(e){return this.atom.subscribe(ra(e))}};function Mt(e,r){if(typeof e==="function")return new fs(e);if(r)return new Pa(e,r);return new Pa(e)}var gs=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 Ba(e,r){return new gs(e,r).maybeExecute}var qa=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 hs extends qa{constructor(){super({pluginId:"form-devtools",reconnectEveryMs:1000})}}var ut=new hs;function Ft(e,r){return typeof e==="function"?e(r):e}function Yt(e,r){return Na(r).reduce((l,s)=>{if(l===null)return null;if(typeof l<"u")return l[s];return},e)}function Kt(e,r,a){let l=Na(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 Qa(e,r){let a=Na(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,y)=>y!==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 vs=46,ja=91,$a=93,bs=48,Sr=57;function Na(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)===ja?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===vs||g===ja||g===$a){let _=c-l;if(_>0){let p=s&&(_===1||e.charCodeAt(l)!==bs),y=e.slice(l,c);if(p){let x=parseInt(y,10);if(_<=15||String(x)===y)a.push(x);else a.push(y)}else a.push(y)}else if(d!==$a&&!(d===-1&&g===$a)&&!(d===g&&(g===vs||g===ja)))a.push("");l=c+1,s=!0}else if(g<bs||g>Sr)s=!1;d=g}if(!a.length)a.push("");return a}function za(e){return!(Array.isArray(e)&&e.length===0)}function Lt(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 Pt(e,r){let{asyncDebounceMs:a}=r,{onBlurAsyncDebounceMs:l,onChangeAsyncDebounceMs:s,onDynamicAsyncDebounceMs:d}=r.validators||{},c=a??0,g=(_)=>_.validators.filter(Boolean).map((p)=>{let y=p?.cause||e,x=c;switch(y){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:y,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}},Gt=({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 Ye(e,r){if(e===void 0||e===null)return r;return{...e,...r}}var Qt=256,wa=[],_a;while(Qt--)wa[Qt]=(Qt+256).toString(16).substring(1);function oa(){let e=0,r,a="";if(!_a||Qt+16>256){_a=Array(256),e=256;while(e--)_a[e]=256*Math.random()|0;e=0,Qt=0}for(;e<16;e++){if(r=_a[Qt+e],e===6)a+=wa[r&15|64];else if(e===8)a+=wa[r&63|128];else a+=wa[r];if(e&1&&e>1&&e<11)a+="-"}return Qt++,a}var Ka=Ba((e)=>ut.emit("form-state",{id:e.formId,state:e.store.state}),{wait:300});function zt(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]=zt(e[l]);return a}if(e instanceof Map){let a=new Map;return e.forEach((l,s)=>{a.set(s,zt(l))}),a}if(e instanceof Set){let a=new Set;return e.forEach((l)=>{a.add(zt(l))}),a}let r={};for(let a in e)if(Object.prototype.hasOwnProperty.call(e,a))r[a]=zt(e[a]);return r}function bt(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 Cr(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:_,y=Number(p);if(Array.isArray(d)&&!Number.isNaN(y))c+=`[${y}]`;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 ys=(e,r)=>{let a=Cr(e,r);return{form:a,fields:a}},At={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 ys(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 ys(l.issues,e)}},ta=(e)=>!!e&&("~standard"in e);var it={isValidating:!1,isTouched:!1,isBlurred:!1,isDirty:!1,isPristine:!0,isValid:!0,isDefaultValue:!0,errors:[],errorMap:{},errorSourceMap:{},_arrayVersion:0,_pendingValidationsCount:0};function qt(e){function r(x){let m=e.getFieldMeta(x)??it;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),M=Math.max(m,i);for(let Y=w;Y<=M;Y++)v.push(c(x,Y));let O=Object.keys(e.fieldInfo).reduce((Y,z)=>{if(z.startsWith(c(x,m)))Y.set(z,e.getFieldMeta(z));return Y},new Map);p(v,m<i?"up":"down"),Object.keys(e.fieldInfo).filter((Y)=>Y.startsWith(c(x,i))).forEach((Y)=>{let z=Y.replace(c(x,i),c(x,m)),de=O.get(z);if(de)e.setFieldMeta(Y,de)})}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 M=w.toString().replace(c(x,m),c(x,i)),[O,Y]=[e.getFieldMeta(w),e.getFieldMeta(M)];if(O)e.setFieldMeta(M,O);if(Y)e.setFieldMeta(w,Y)})}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,y())})}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[M,O]=[Math.min(m,v),Math.max(m,v)];for(let Y=M;Y<=O;Y++)w.push(c(x,Y));break}default:{let M=e.getFieldValue(x),O=Array.isArray(M)?M.length:0;for(let Y=m+1;Y<O;Y++)w.push(c(x,Y));break}}return Object.keys(e.fieldInfo).filter((M)=>w.some((O)=>M.startsWith(O)))}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),M=e.getFieldMeta(w);if(M)e.setFieldMeta(v,M);else e.setFieldMeta(v,y())})}let y=()=>it;return{bumpArrayVersion:r,handleArrayMove:a,handleArrayRemove:l,handleArraySwap:s,handleArrayInsert:d}}function Ua(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 la{constructor(e){this.options={},this.fieldInfo={},this.formGroupApis=new Set,this.mount=()=>{let s=this.store.subscribe(()=>{Ka(this)}),d=ut.on("request-form-state",(y)=>{if(y.payload.id===this._formId)ut.emit("form-api",{id:this._formId,state:this.store.state,options:this.options})}),c=ut.on("request-form-reset",(y)=>{if(y.payload.id===this._formId)this.reset()}),g=ut.on("request-form-force-submit",(y)=>{if(y.payload.id===this._formId)this._devtoolsSubmissionOverride=!0,this.handleSubmit(),this._devtoolsSubmissionOverride=!1}),_=()=>{g(),c(),d(),s.unsubscribe(),ut.emit("form-unmounted",{id:this._formId})};this.options.listeners?.onMount?.({formApi:this});let{onMount:p}=this.options.validators||{};if(ut.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(Ke(()=>{this.baseStore.setState(()=>Ua(Object.assign({},this.state,g?s.defaultState:{},c?{values:s.defaultValues}:{})))}),c){let _=qt(this);for(let p of Object.keys(this.fieldInfo))if(Array.isArray(this.getFieldValue(p)))_.bumpArrayVersion(p)}ut.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)_=Kt(_,p.instance.name,p.instance.options.defaultValue)});return Ua({...this.options.defaultState,values:_,fieldMetaBase:g})})},this.validateAllFields=async(s)=>{let d=[];return Ke(()=>{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 y=Object.keys(this.fieldInfo).filter((i)=>p.some((v)=>i.startsWith(v))),x=[];return Ke(()=>{y.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=Lt(s,{...this.options,form:this,group:d?.group,validationLogic:this.options.validationLogic||ft}),g=!1,_={};return Ke(()=>{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}=Sa(m),w=ia(x.cause),M=new Set([...Object.keys(this.state.fieldMeta),...Object.keys(v||{})]);if(d?.filterFieldNames)M=new Set([...M].filter(d.filterFieldNames));for(let O of M){if(this.baseStore.state.fieldMetaBase[O]===void 0&&!v?.[O])continue;let Y=this.getFieldMeta(O)??it,{errorMap:z,errorSourceMap:de}=Y,ie=v?.[O],{newErrorValue:T,newSource:q}=ea({newFormValidatorError:ie,isPreviousErrorFromFormValidator:de?.[w]==="form",previousErrorValue:z?.[w]});if(q==="form")_[O]={..._[O],[w]:ie};if(z?.[w]!==T)this.setFieldMeta(O,(j=it)=>({...j,errorMap:{...j.errorMap,[w]:T},errorSourceMap:{...j.errorSourceMap,[w]:q}}))}if(!d?.dontUpdateFormErrorMap){if(this.state.errorMap?.[w]!==i)this.baseStore.setState((O)=>({...O,errorMap:{...O.errorMap,[w]:i}}))}if(i||v)g=!0}if(d?.dontUpdateFormErrorMap)return;let p=ia("submit");if(this.state.errorMap?.[p]&&s!=="submit"&&!g)this.baseStore.setState((x)=>({...x,errorMap:{...x.errorMap,[p]:void 0}}));let y=ia("server");if(this.state.errorMap?.[y]&&s!=="server"&&!g)this.baseStore.setState((x)=>({...x,errorMap:{...x.errorMap,[y]:void 0}}))}),{hasErrored:g,fieldsErrorMap:_}},this.validateAsync=async(s,d)=>{let c=Pt(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=ia(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 M;try{M=await new Promise((T,q)=>{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){q(j)}},x.debounceMs)})}catch(T){M=T}let{formError:O,fieldErrors:Y}=Sa(M);if(Y)_=_?{..._,...Y}:Y;let z=ia(x.cause),de=new Set([...Object.keys(this.state.fieldMeta),...Object.keys(_||{})]),ie=Array.from(de);if(d?.filterFieldNames)ie=ie.filter(d.filterFieldNames);for(let T of ie){if(this.baseStore.state.fieldMetaBase[T]===void 0&&!_?.[T])continue;let q=this.getFieldMeta(T)??it,{errorMap:j,errorSourceMap:G}=q,N=_?.[T],{newErrorValue:X,newSource:xe}=ea({newFormValidatorError:N,isPreviousErrorFromFormValidator:G?.[z]==="form",previousErrorValue:j?.[z]});if(j?.[z]!==X)this.setFieldMeta(T,(ye=it)=>({...ye,errorMap:{...ye.errorMap,[z]:X},errorSourceMap:{...ye.errorSourceMap,[z]:xe}}))}if(!d?.dontUpdateFormErrorMap)this.baseStore.setState((T)=>({...T,errorMap:{...T.errorMap,[z]:O}}));w(_?{fieldErrors:_,errorMapKey:z}:void 0)}))}let p=[],y={};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 M={...y[i]||{},[m]:v};y[i]=M}}}return this.baseStore.setState((x)=>({...x,isFormValidating:!1})),y},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})),Ke(()=>{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}),ut.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}),ut.emit("form-submission",{id:this._formId,submissionAttempt:this.state.submissionAttempts,successful:!1,stage:"validate",errors:this.state.errors});return}Ke(()=>{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}),Ke(()=>{this.baseStore.setState((g)=>({...g,isSubmitted:!0,isSubmitSuccessful:!0})),ut.emit("form-submission",{id:this._formId,submissionAttempt:this.state.submissionAttempts,successful:!0}),c()})}catch(g){throw this.baseStore.setState((_)=>({..._,isSubmitSuccessful:!1})),ut.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]=it,d},{}),this.setFieldValue=(s,d,c)=>{let g=c?.dontUpdateMeta??!1,_=c?.dontRunListeners??!1,p=c?.dontValidate??!1;if(Ke(()=>{if(!g)this.setFieldMeta(s,(y)=>({...y,isTouched:!0,isDirty:!0,errorMap:{...y?.errorMap,onMount:void 0}}));this.baseStore.setState((y)=>({...y,values:Kt(y.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=Qa(_.values,p),delete this.fieldInfo[p],delete _.fieldMetaBase[p]}),_})},this.pushFieldValue=(s,d,c)=>{this.setFieldValue(s,(g)=>[...Array.isArray(g)?g:[],d],c),qt(this).bumpArrayVersion(s)},this.insertFieldValue=async(s,d,c,g)=>{this.setFieldValue(s,(p)=>[...p.slice(0,d),c,...p.slice(d)],Ye(g,{dontValidate:!0}));let _=g?.dontValidate??!1;if(!_)await this.validateField(s,"change");if(qt(this).handleArrayInsert(s,d),!_)await this.validateArrayFieldsStartingFrom(s,d,"change")},this.replaceFieldValue=async(s,d,c,g)=>{if(this.setFieldValue(s,(p)=>p.map((y,x)=>x===d?c:y),Ye(g,{dontValidate:!0})),qt(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,(y)=>y.filter((x,m)=>m!==d),Ye(c,{dontValidate:!0})),qt(this).handleArrayRemove(s,d),_!==null){let y=`${s}[${_}]`;this.deleteField(y)}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 y=p[d],x=p[c];return Kt(Kt(p,`${d}`,x),`${c}`,y)},Ye(g,{dontValidate:!0})),qt(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 y=[...p];return y.splice(c,0,y.splice(d,1)[0]),y},Ye(g,{dontValidate:!0})),qt(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,[],Ye(d,{dontValidate:!0})),qt(this).bumpArrayVersion(s),g!==null)for(let p=0;p<=g;p++){let y=`${s}[${p}]`;this.deleteField(y)}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]:it},values:_!==void 0?Kt(d.values,s,_):d.values}})},this.setErrorMap=(s)=>{Ke(()=>{Object.entries(s).forEach(([d,c])=>{let g=d;if(Jt(c)){let{formError:_,fieldErrors:p}=Sa(c);for(let y of Object.keys(this.fieldInfo)){if(!this.getFieldMeta(y))continue;this.setFieldMeta(y,(m)=>({...m,errorMap:{...m.errorMap,[g]:p?.[y]},errorSourceMap:{...m.errorSourceMap,[g]:"form"}}))}this.baseStore.setState((y)=>({...y,errorMap:{...y.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)=>At.validate({value:this.state.values,validationSource:"form"},s),this.parseValuesWithSchemaAsync=(s)=>At.validateAsync({value:this.state.values,validationSource:"form"},s),this.timeoutIds={validations:{},listeners:{},formListeners:{}},this._formId=e?.formId??oa(),this._devtoolsSubmissionOverride=!1;let r=Ua({...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=Mt(r);let a=void 0;this.fieldMetaDerived=Mt((s)=>{let d=this.baseStore.get(),c=0,g={};for(let _ of Object.keys(d.fieldMetaBase)){let p=d.fieldMetaBase[_],y=a?.fieldMetaBase[_],x=s?.[_],m=Yt(d.values,_),i=x?.errors;if(!y||p.errorMap!==y.errorMap){i=Object.values(p.errorMap??{}).filter((Y)=>Y!==void 0);let O=this.getFieldInfo(_)?.instance;if(!O||!O.options.disableErrorFlat)i=i.flat(1)}let v=!za(i),w=!p.isDirty,M=pt(m,this.getFieldInfo(_)?.instance?.options.defaultValue??Yt(this.options.defaultValues,_));if(x&&x.isPristine===w&&x.isValid===v&&x.isDefaultValue===M&&x.errors===i&&p===y){g[_]=x,c++;continue}g[_]={...p,errors:i??[],isPristine:w,isValid:v,isDefaultValue:M}}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=Mt((s)=>{let d=this.baseStore.get(),c=this.fieldMetaDerived.get(),g={};for(let _ of this.formGroupApis){let p=_.name,y=d.formGroupStateBase[p]??{isSubmitted:!1,isSubmitting:!1,isValidating:!1,submissionAttempts:0,isSubmitSuccessful:!1},x=c[p],m=!1,i=!0,v=!1,w=!1,M=!0,O=!1;for(let ke in c){if(ke===p)continue;if(!bt(p,ke))continue;let Se=c[ke];if(!Se)continue;if(Se.isValidating)m=!0;if(!Se.isValid)i=!1;if(Se.isTouched)v=!0;if(Se.isBlurred)w=!0;if(!Se.isDefaultValue)M=!1;if(Se.isDirty)O=!0}let Y=!O,z=!!m||y.isValidating,de=x?.errorMap??{},ie=x?.errorSourceMap??{},T=Boolean(de.onMount||Object.entries(c).some(([ke,Se])=>Se&&ke!==p&&bt(p,ke)&&Se.errorMap.onMount)),q=s?.[p],j=q?.errors??[];if(!q||q.__srcErrorMap!==de)j=Object.values(de).reduce((ke,Se)=>{if(Se===void 0)return ke;if(Se&&typeof Se==="object"&&"fields"in Se){let se=Se.group;if(se!==void 0)ke.push(se);return ke}return ke.push(Se),ke},[]);let G=j.length===0,N=i&&G,X=_.options.canSubmitWhenInvalid??!1,xe=y.submissionAttempts===0&&!v&&!T||!z&&!y.isSubmitting&&N||X;if(q&&q.errorMap===de&&q.errorSourceMap===ie&&q.errors===j&&q.isFieldsValidating===m&&q.isFieldsValid===i&&q.isGroupValid===G&&q.isValid===N&&q.canSubmit===xe&&q.isTouched===v&&q.isBlurred===w&&q.isPristine===Y&&q.isDefaultValue===M&&q.isDirty===O&&q.isValidating===z&&q.isSubmitting===y.isSubmitting&&q.isSubmitted===y.isSubmitted&&q.submissionAttempts===y.submissionAttempts&&q.isSubmitSuccessful===y.isSubmitSuccessful){g[p]=q;continue}let ye={...y,errorMap:de,errorSourceMap:ie,_arrayVersion:x?._arrayVersion??0,isTouched:v,isBlurred:w,isDirty:O,isPristine:Y,isDefaultValue:M,isValid:N,errors:j,isValidating:z,isFieldsValidating:m,isFieldsValid:i,isGroupValid:G,canSubmit:xe};Object.defineProperty(ye,"__srcErrorMap",{value:de,enumerable:!1,configurable:!0}),g[p]=ye}return g});let l=void 0;this.store=Mt((s)=>{let d=this.baseStore.get(),c=this.fieldMetaDerived.get(),g=Object.values(c).filter(Boolean),_=g.some((G)=>G.isValidating),p=g.every((G)=>G.isValid),y=g.some((G)=>G.isTouched),x=g.some((G)=>G.isBlurred),m=g.every((G)=>G.isDefaultValue),i=y&&d.errorMap?.onMount,v=g.some((G)=>G.isDirty),w=!v,M=Boolean(d.errorMap?.onMount||g.some((G)=>G?.errorMap?.onMount)),O=!!_,Y=s?.errors??[];if(!l||d.errorMap!==l.errorMap)Y=Object.values(d.errorMap).reduce((G,N)=>{if(N===void 0)return G;if(N&&Jt(N))return G.push(N.form),G;return G.push(N),G},[]);let z=Y.length===0,de=p&&z,ie=this.options.canSubmitWhenInvalid??!1,T=d.submissionAttempts===0&&!y&&!M||!O&&!d.isSubmitting&&de||ie,q=d.errorMap;if(i)Y=Y.filter((G)=>G!==d.errorMap.onMount),q=Object.assign(q,{onMount:void 0});if(s&&l&&s.errorMap===q&&s.fieldMeta===this.fieldMetaDerived.state&&s.errors===Y&&s.isFieldsValidating===_&&s.isFieldsValid===p&&s.isFormValid===z&&s.isValid===de&&s.canSubmit===T&&s.isTouched===y&&s.isBlurred===x&&s.isPristine===w&&s.isDefaultValue===m&&s.isDirty===v&&pt(l,d))return s;let j={...d,errorMap:q,fieldMeta:this.fieldMetaDerived.state,errors:Y,isFieldsValidating:_,isFieldsValid:p,isFormValid:z,isValid:de,canSubmit:T,isTouched:y,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 At[e.type](e.value,e.validate);return e.validate(e.value)}handleSubmit(e){return this._handleSubmit(e)}}function Sa(e){if(e){if(Jt(e)){let r=Sa(e.form).formError,a=e.fields;return{formError:r,fieldErrors:a}}return{formError:e}}return{formError:void 0}}function ia(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 Ot{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]:{...it,isTouched:s.fieldMetaBase[this.name]?.isTouched??it.isTouched,isBlurred:s.fieldMetaBase[this.name]?.isBlurred??it.isBlurred,isDirty:s.fieldMetaBase[this.name]?.isDirty??it.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,Ye(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,Ye(a,{dontRunListeners:!0})),!a?.dontRunListeners)this.triggerOnChangeListener()},this.insertValue=(r,a,l)=>{if(this.form.insertFieldValue(this.name,r,a,Ye(l,{dontRunListeners:!0})),!l?.dontRunListeners)this.triggerOnChangeListener()},this.replaceValue=(r,a,l)=>{if(this.form.replaceFieldValue(this.name,r,a,Ye(l,{dontRunListeners:!0})),!l?.dontRunListeners)this.triggerOnChangeListener()},this.removeValue=(r,a)=>{if(this.form.removeFieldValue(this.name,r,Ye(a,{dontRunListeners:!0})),!a?.dontRunListeners)this.triggerOnChangeListener()},this.swapValues=(r,a,l)=>{if(this.form.swapFieldValues(this.name,r,a,Ye(l,{dontRunListeners:!0})),!l?.dontRunListeners)this.triggerOnChangeListener()},this.moveValue=(r,a,l)=>{if(this.form.moveFieldValues(this.name,r,a,Ye(l,{dontRunListeners:!0})),!l?.dontRunListeners)this.triggerOnChangeListener()},this.clearValues=(r)=>{if(this.form.clearFieldValues(this.name,Ye(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 Ot))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=Lt(r,{...this.options,form:this.form,fieldName:this.name,validationLogic:this.form.options.validationLogic||ft}),d=this.getLinkedFields(r).reduce((_,p)=>{let y=Lt(r,{...p.options,form:p.form,fieldName:p.name,validationLogic:p.form.options.validationLogic||ft});return y.forEach((x)=>{x.field=p}),_.concat(y)},[]),c=!1;Ke(()=>{let _=(p,y)=>{let x=ca(y.cause),m=y.validate?xs(p.runValidator({validate:y.validate,value:{value:p.store.state.value,validationSource:"field",fieldApi:p},type:"validate"})):void 0,i=a[x],{newErrorValue:v,newSource:w}=Gt({formLevelError:i,fieldLevelError:m});if(p.state.meta.errorMap?.[x]!==v)p.setMeta((M)=>({...M,errorMap:{...M.errorMap,[x]:v},errorSourceMap:{...M.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=ca("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=Pt(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=Pt(r,{...v.options,form:v.form,fieldName:v.name,validationLogic:v.form.options.validationLogic||ft});return w.forEach((M)=>{M.field=v}),i.concat(w)},[]),g=[],_=[],p=l.some((i)=>i.validate),y=Array.from(new Set(c.filter((i)=>i.validate).map((i)=>i.field)));Ke(()=>{if(p)this.startValidation();for(let i of y)i.startValidation()});let x=(i,v,w)=>{let M=ca(v.cause),O=i.getInfo();O.validationMetaMap[M]?.lastAbortController.abort();let z=new AbortController;O.validationMetaMap[M]={lastAbortController:z},w.push(new Promise(async(de)=>{let ie;try{ie=await new Promise((N,X)=>{if(i.timeoutIds.validations[v.cause])clearTimeout(i.timeoutIds.validations[v.cause]),i.endValidation();i.timeoutIds.validations[v.cause]=setTimeout(async()=>{if(z.signal.aborted)return N(void 0);try{N(await this.runValidator({validate:v.validate,value:{value:i.store.state.value,fieldApi:i,signal:z.signal,validationSource:"field"},type:"validateAsync"}))}catch(xe){X(xe)}},v.debounceMs)})}catch(N){ie=N}if(z.signal.aborted)return de(void 0);let T=xs(ie),q=s[i.name]?.[M],{newErrorValue:j,newSource:G}=Gt({formLevelError:q,fieldLevelError:T});if(i.getInfo().instance!==i)return de(void 0);i.setMeta((N)=>({...N,errorMap:{...N?.errorMap,[M]:j},errorSourceMap:{...N.errorSourceMap,[M]:G}})),de(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 Ke(()=>{if(p)this.endValidation();for(let i of y)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)=>bt(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[ca(r)]?.lastAbortController.abort();let x=[];for(let m of l)m.getInfo().validationMetaMap[ca(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,_),y=[];for(let x of l){if(g.get(x)&&!x.options.asyncAlways)continue;y.push(x.validateAsync(r,_,{skipRelatedFieldValidation:!0}))}if(y.length===0)return p;return Promise.all([p,...y]).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)=>At.validate({value:this.state.value,validationSource:"field"},r),this.parseValueWithSchemaAsync=(r)=>At.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(bt(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=Mt((r)=>{this.form.store.get();let a=this.form.getFieldMeta(this.name)??{...it,...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 At[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 xs(e){if(e)return e;return}function ca(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 Ha(e){return{isSubmitted:e.isSubmitted??!1,isSubmitting:e.isSubmitting??!1,isValidating:e.isValidating??!1,submissionAttempts:e.submissionAttempts??0,isSubmitSuccessful:e.isSubmitSuccessful??!1}}function ws(e){return{...it,...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 Ht{constructor(e){this.options={},this.setFormGroupState=(r)=>{this.form.baseStore.setState((a)=>{let l=a.formGroupStateBase[this.name]??Ha({});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,{...it,...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]??Ha({...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(Xa(a))l=a.group,s=a.fields;let d=Wa(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]:Ha({})}})),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,Ye(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 Ot))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(bt(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?.[_],y=this.form.getFieldMeta(g);if(!y&&!p)continue;let x=y?.errorMap[r],m=y?.errorSourceMap[r]==="form",{newErrorValue:i,newSource:v}=ea({newFormValidatorError:p,isPreviousErrorFromFormValidator:m,previousErrorValue:x});if(i)c=!0;if(x===i&&y?.errorSourceMap[r]===v)continue;this.form.setFieldMeta(g,(w=it)=>({...w,errorMap:{...w.errorMap,[r]:i},errorSourceMap:{...w.errorSourceMap,[r]:v}}))}return this._lastDistributedFieldNames[r]=s,c},this.validateSync=(r,a,l={})=>{let s=Lt(r,{...this.options,form:this.form,group:this,validationLogic:this.options.validationLogic||this.form.options.validationLogic||ft}),c=(l.skipRelatedFieldValidation?[]:this.getRelatedFields()).reduce((p,y)=>{let x=Lt(r,{...y.options,form:y.form,validationLogic:y.form.options.validationLogic||ft});return x.forEach((m)=>{m.field=y}),p.concat(x)},[]),g=!1;Ke(()=>{let p=(y,x)=>{let m=Ca(x.cause),i=y===this,v=void 0;if(x.validate)v=y.runValidator({validate:x.validate,value:{value:y.store.state.value,validationSource:i?"form":"field",...y instanceof Ht?{groupApi:y}:{fieldApi:y}},type:"validate"});let w=v,M=void 0;if(i&&Xa(v))w=v.group,M=v.fields;let O=Wa(w),Y=a[m],{newErrorValue:z,newSource:de}=Gt({formLevelError:Y,fieldLevelError:O});if(y.state.meta.errorMap?.[m]!==z)y.setMeta((ie)=>({...ie,errorMap:{...ie.errorMap,[m]:z},errorSourceMap:{...ie.errorSourceMap,[m]:de}}));if(z)g=!0;if(i){if(this.distributeFieldErrors(m,M))g=!0}};for(let y of s)p(this,y);for(let y of c){if(!y.validate)continue;p(y.field,y)}});let _=Ca("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=Pt(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=Pt(r,{...v.options,form:v.form,validationLogic:v.form.options.validationLogic||ft});return w.forEach((M)=>{M.field=v}),i.concat(w)},[]),_=[],p=[],y=s.some((i)=>i.validate)||g.some((i)=>i.validate);if(y){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 M=Ca(v.cause),O=i.getInfo();O.validationMetaMap[M]?.lastAbortController.abort();let z=new AbortController;O.validationMetaMap[M]={lastAbortController:z};let de=i===this;w.push(new Promise(async(ie)=>{let T;try{T=await new Promise((ye,ke)=>{if(i.timeoutIds.validations[v.cause])clearTimeout(i.timeoutIds.validations[v.cause]);i.timeoutIds.validations[v.cause]=setTimeout(async()=>{if(z.signal.aborted)return ye(void 0);try{ye(await this.runValidator({validate:v.validate,value:{value:i.store.state.value,signal:z.signal,validationSource:de?"form":"field",...i instanceof Ht?{groupApi:i}:{fieldApi:i}},type:"validateAsync"}))}catch(Se){ke(Se)}},v.debounceMs)})}catch(ye){T=ye}if(z.signal.aborted)return ie(void 0);let q=T,j=void 0;if(de&&Xa(T))q=T.group,j=T.fields;let G=Wa(q),N=d[i.name]?.[M],{newErrorValue:X,newSource:xe}=Gt({formLevelError:N,fieldLevelError:G});if(i.getInfo().instance!==i)return ie(void 0);if(i.setMeta((ye)=>({...ye,errorMap:{...ye?.errorMap,[M]:X},errorSourceMap:{...ye.errorSourceMap,[M]:xe}})),de)this.distributeFieldErrors(M,j);ie(X)}))};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(y){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 Ke(()=>{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)=>bt(this.name,c)}),{hasErrored:s}=this.validateSync(r,l[this.name]??{},{skipRelatedFieldValidation:a?.skipRelatedFieldValidation});if(s&&!this.options.asyncAlways)return this.getInfo().validationMetaMap[Ca(r)]?.lastAbortController.abort(),this.state.meta.errors;let d=a?.skipFormValidation?Promise.resolve({}):this.form.validateAsync(r,{dontUpdateFormErrorMap:!0,filterFieldNames:(c)=>bt(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})),Ke(()=>{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}Ke(()=>{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}),Ke(()=>{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=Mt((r)=>{this.form.formGroupMetaDerived.get(),this.form.baseStore.get();let a=this.form.getFormGroupMeta(this.name)??ws(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=At[e.type](e.value,e.validate);if(e.type==="validate")return _s(r);return r.then(_s)}return e.validate(e.value)}handleSubmit(e){return this._handleSubmit(e)}}function Wa(e){if(e)return e;return}function Xa(e){return!!e&&typeof e==="object"&&"fields"in e}function _s(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 Ca(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 Ya(e,r){if(!r)return;let a=Object.assign({},e,{state:zt(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 Ke(()=>{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 kr(e,r){return e===r}function Me(e,r=(l)=>l,a){let l=a?.compare??kr,s=D((c)=>{let{unsubscribe:g}=e.subscribe(c);return g},[e]),d=D(()=>e.get(),[e]);return Tc(s,d,d,r,l)}var ma=(e,r=(l)=>l,a)=>Me(e,r,{compare:a});S();S();S();var xt=typeof window<"u"?$e:h;function Mr(e){let[r,a]=u(()=>({form:e.form,name:e.name})),[l,s]=u(()=>new Ot({...e})),d=l;if(r.form!==e.form||r.name!==e.name)d=new Ot({...e}),s(d),a({form:e.form,name:e.name});let c=Me(d.store,e.mode==="array"?(v)=>v.meta._arrayVersion||0:(v)=>v.value),g=Me(d.store,(v)=>v.meta.isTouched),_=Me(d.store,(v)=>v.meta.isBlurred),p=Me(d.store,(v)=>v.meta.isDirty),y=Me(d.store,(v)=>v.meta.errorMap),x=Me(d.store,(v)=>v.meta.errorSourceMap),m=Me(d.store,(v)=>v.meta.isValidating),i=P(()=>({...d,get state(){return{value:e.mode==="array"?d.state.value:c,get meta(){return{...d.state.meta,isTouched:g,isBlurred:_,isDirty:p,errorMap:y,errorSourceMap:x,isValidating:m}}}}}),[d,e.mode,c,g,_,p,y,x,m]);return xt(d.mount,[d]),xt(()=>{d.update(e)}),i}var Ss=({children:e,...r})=>{let a=Mr(r),l=P(()=>Ft(e,a),[e,a]);return t(L,{children:l})};S();S();function Cs(){return u(()=>oa())[0]}var Fr=V,ks=Ns.split(".")[0]==="17"?Cs:Fr.useId;S();function Ir(e){let[r,a]=u(()=>({form:e.form,name:e.name})),[l,s]=u(()=>new Ht({...e}));if(r.form!==e.form||r.name!==e.name)s(new Ht({...e})),a({form:e.form,name:e.name});let d=Me(l.store,(T)=>T.value),c=Me(l.store,(T)=>T.meta.isTouched),g=Me(l.store,(T)=>T.meta.isBlurred),_=Me(l.store,(T)=>T.meta.isDirty),p=Me(l.store,(T)=>T.meta.errorMap),y=Me(l.store,(T)=>T.meta.errorSourceMap),x=Me(l.store,(T)=>T.meta.isValidating),m=Me(l.store,(T)=>T.meta.isSubmitting),i=Me(l.store,(T)=>T.meta.isSubmitted),v=Me(l.store,(T)=>T.meta.submissionAttempts),w=Me(l.store,(T)=>T.meta.isSubmitSuccessful),M=Me(l.store,(T)=>T.meta.canSubmit),O=Me(l.store,(T)=>T.meta.isValid),Y=Me(l.store,(T)=>T.meta.isFieldsValid),z=Me(l.store,(T)=>T.meta.isFieldsValidating),de=Me(l.store,(T)=>T.meta.isGroupValid),ie=P(()=>({...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:y,isValidating:x,isSubmitting:m,isSubmitted:i,submissionAttempts:v,isSubmitSuccessful:w,canSubmit:M,isValid:O,isFieldsValid:Y,isFieldsValidating:z,isGroupValid:de}}}}}),[l,d,c,g,_,p,y,x,m,i,v,w,M,O,Y,z,de]);return xt(l.mount,[l]),xt(()=>{l.update(e)}),ie}var Ms=({children:e,...r})=>{let a=Ir(r),l=P(()=>Ft(e,a),[e,a]);return t(L,{children:l})};function Er({form:e,selector:r=(l)=>l,children:a}){let l=Me(e.store,r);return t(L,{children:Ft(a,l)})}function $t(e){let r=ks(),[a,l]=u(e?.formId),[s,d]=u(()=>new la({...e,formId:e?.formId??r}));if(a!==e?.formId){let _=e?.formId??r;d(new la({...e,formId:_})),l(_)}let c=P(()=>{let _={...s,handleSubmit:(...p)=>s._handleSubmit(...p),get formId(){return s._formId},get state(){return s.store.state}};return _.Field=function(y){return t(Ss,{...y,form:s})},_.FormGroup=function(y){return t(Ms,{...y,form:s})},_.Subscribe=function(y){return t(Er,{form:s,selector:y.selector,children:y.children})},_},[s]);xt(s.mount,[]),xt(()=>{s.update(e)});let g=b(!1);return xt(()=>{if(!g.current)return;if(!e?.transform)return;Ya(s,e.transform)},[s,e?.transform]),xt(()=>{g.current=!0}),c}S();var Tr=R({name:f().min(1,bx()),type:Ve(["chat","autofill","embedding"]),permission:Ve(["owner","editor","reviewer"]),avatar:f().optional(),providerId:f().optional(),modelId:f().optional(),soul:f().optional(),thinkingLevel:Xc.optional(),systemPrompt:f().optional(),skills:te(f()).optional(),mcpServerIds:te(f()).optional(),deniedTools:te(f()).optional()}),Vr=[{id:"bash",name:()=>d_(),description:()=>u_()},{id:"read_skill",name:()=>w_(),description:()=>v_()},{id:"read_asset",name:()=>Zm(),description:()=>b_()},{id:"list_assets",name:()=>Fm(),description:()=>__()},{id:"create_folder",name:()=>Rm(),description:()=>p_()},{id:"create_file",name:()=>km(),description:()=>f_()},{id:"create_version",name:()=>Nm(),description:()=>m_()},{id:"generate_image",name:()=>Dm(),description:()=>g_()},{id:"generate_video",name:()=>Om(),description:()=>A_()},{id:"rename_asset",name:()=>Bm(),description:()=>x_()},{id:"move_assets",name:()=>Lm(),description:()=>y_()},{id:"delete_asset",name:()=>Pm(),description:()=>h_()}];function Ds({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 U=await A.api.teams[":teamId"].providers.$get({param:{teamId:a}});if(!U.ok)throw Error("Failed to fetch providers");return await U.json()},enabled:e}),{data:p}=Z({queryKey:["teams",a,"skills"],queryFn:async()=>{let U=await A.api.teams[":teamId"].skills.$get({param:{teamId:a}});if(!U.ok)throw Error("Failed to fetch skills");return await U.json()},enabled:e}),y=p?.skills||[],{data:x}=Z({queryKey:["teams",a,"mcp","servers"],queryFn:async()=>{let U=await A.api.teams[":teamId"].mcp.servers.$get({param:{teamId:a}});if(!U.ok)throw Error("Failed to fetch MCP servers");return await U.json()},enabled:e}),m=x?.servers||[],i=P(()=>Tr.superRefine((U,J)=>{if(U.type==="chat"||U.type==="autofill"){if(!U.providerId)J.addIssue({code:ro.custom,message:mE(),path:["providerId"]});if(!U.modelId)J.addIssue({code:ro.custom,message:px(),path:["modelId"]})}}),[]),v=$t({defaultValues:{name:s?.name||"",type:s?.type||l||"chat",permission:s?.permission||"reviewer",avatar:s?.avatarPreset||s?.avatar||Jc[0].id,providerId:s?.providerId||"",modelId:s?.modelId||"",soul:s?.soul||"",thinkingLevel:s?.thinkingLevel||"off",systemPrompt:s?.systemPrompt||"",skills:s?.skills?.map((U)=>U.skillId)||[],mcpServerIds:s?.mcpServerIds||[],deniedTools:s?.deniedTools??[...bA]},validators:{onChange:i},onSubmit:async({value:U})=>{try{if(s?.id)await Se.mutateAsync({id:s.id,values:U});else await ke.mutateAsync(U)}catch{}}}),w=ma(v.store,(U)=>U.values.providerId),{data:M,isLoading:O}=Z({queryKey:["teams",a,"providers",w,"models"],queryFn:async()=>{let U=await A.api.providers[":id"].models.$get({param:{id:w}});if(!U.ok)throw Error("Failed to fetch models");return await U.json()},enabled:!!w&&e}),[Y,z]=u(""),[de,ie]=u(!1),T=P(()=>{if(!_)return[];return[..._].sort((U,J)=>U.name.toLowerCase().localeCompare(J.name.toLowerCase()))},[_]),q=P(()=>{if(!Y.trim())return T;let U=Y.toLowerCase();return T.filter((J)=>J.name.toLowerCase().includes(U))},[T,Y]),[j,G]=u(""),[N,X]=u(!1),xe=P(()=>{if(!M)return[];return[...M].sort((U,J)=>{let ee=(U.name||U.modelId).toLowerCase(),re=(J.name||J.modelId).toLowerCase();return ee.localeCompare(re)})},[M]),ye=P(()=>{if(!j.trim())return xe;let U=j.toLowerCase();return xe.filter((J)=>J.modelId.toLowerCase().includes(U)||J.name&&J.name.toLowerCase().includes(U))},[xe,j]),ke=B({mutationFn:async(U)=>{let J=await A.api.teams[":teamId"].agents.$post({param:{teamId:a},json:U});if(!J.ok)throw Error("Failed to create agent");return await J.json()},onSuccess:()=>{r(),c.invalidateQueries({queryKey:["agents",a]}),k.success(e_())},onError:(U)=>{k.error(Bs({message:U.message}))}}),Se=B({mutationFn:async({id:U,values:J})=>{let ee=await A.api.agents[":agentId"].$put({param:{agentId:U},json:J});if(!ee.ok)throw Error("Failed to update agent");return await ee.json()},onSuccess:()=>{r(),c.invalidateQueries({queryKey:["agents",a]}),k.success(qm())},onError:(U)=>{k.error(Bs({message:U.message}))}});h(()=>{if(e)v.reset(),z(""),ie(!1),G(""),X(!1)},[e,s,l]);let se=ma(v.store,(U)=>U.values.type),_e=se==="chat"||se==="autofill",Fe=se==="chat",Ee=(U)=>U.map((J)=>{if(typeof J==="string")return{message:J};if(J&&typeof J==="object"&&"message"in J)return{message:String(J.message)};return{message:String(J||"")}});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(Ct,{children:H0()})]}),o("form",{onSubmit:(U)=>{U.preventDefault(),U.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:(U)=>{let J=!!U.state.meta.errors.length&&U.state.meta.isTouched;return o(Oe,{"data-invalid":J,children:[t(Qe,{children:n_()}),t(H,{value:U.state.value,onBlur:U.handleBlur,onChange:(ee)=>U.handleChange(ee.target.value),placeholder:o_(),"aria-invalid":J}),J&&t(He,{errors:Ee(U.state.meta.errors)})]})}}),t(v.Field,{name:"type",children:(U)=>o(Oe,{children:[t(Qe,{children:C_()}),o(Le,{value:U.state.value,onValueChange:(J)=>U.handleChange(J),disabled:!0,children:[t(Be,{className:"bg-muted/50",children:t(Ze,{})}),o(Ue,{children:[t(ne,{value:"chat",children:zm()}),t(ne,{value:"autofill",children:Um()}),t(ne,{value:"embedding",children:jm()})]})]})]})}),Fe&&t(v.Field,{name:"permission",children:(U)=>o(Oe,{children:[t(Qe,{children:Rp()}),o(Le,{value:U.state.value||"reviewer",onValueChange:(J)=>U.handleChange(J),disabled:!g,children:[t(Be,{children:t(Ze,{})}),o(Ue,{children:[t(ne,{value:"reviewer",children:Da()}),t(ne,{value:"editor",children:Oa()}),t(ne,{value:"owner",children:Fa()})]})]})]})}),t(v.Field,{name:"avatar",children:(U)=>o(Oe,{className:"md:col-span-2",children:[t(Qe,{children:XA()}),o("div",{className:"flex flex-wrap gap-4 mt-2",children:[Jc.map((J)=>{let ee=U.state.value===J.id;return t("button",{type:"button",onClick:()=>U.handleChange(J.id),className:C("relative w-14 h-14 rounded-full overflow-hidden border-2 transition-all hover:scale-105",ee?"border-primary ring-2 ring-primary ring-offset-2":"border-border hover:border-muted-foreground"),children:t("img",{src:J.preview,className:"w-full h-full object-cover",alt:KS()})},J.id)}),U.state.value&&!Jc.some((J)=>J.id===U.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:U.state.value,className:"w-full h-full object-cover",alt:wy()})})]})]})})]}),_e&&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:(U)=>{let J=!!U.state.meta.errors.length&&U.state.meta.isTouched,ee=_?.find((re)=>re.id===U.state.value);return o(Oe,{"data-invalid":J,children:[t(Qe,{children:dE()}),o(mt,{open:de,onOpenChange:(re)=>{if(ie(re),!re)z("")},modal:!0,children:[t(ht,{asChild:!0,children:o(E,{type:"button",variant:"outline",role:"combobox","aria-expanded":de,"aria-invalid":J,className:C("w-full justify-between font-normal h-10 px-3 bg-background border-border hover:bg-accent/50",J&&"border-destructive ring-destructive"),children:[t("span",{className:"truncate",children:ee?t("span",{className:"font-medium text-foreground truncate",children:ee.name}):t("span",{className:"text-muted-foreground",children:zC()})}),t(ve,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),o(gt,{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:(re)=>re.stopPropagation(),children:[o("div",{className:"relative p-2 pb-1.5 border-b border-border shrink-0",children:[t(Bt,{className:"absolute left-4.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-muted-foreground"}),t(H,{placeholder:Gg(),value:Y,onChange:(re)=>z(re.target.value),className:"pl-8 h-8 text-xs bg-muted/40",autoFocus:!0})]}),t(ce,{className:"w-full p-1",style:{height:q.length===0?"96px":`${Math.min(q.length*38+8,256)}px`},onWheel:(re)=>re.stopPropagation(),children:q.length===0?t("div",{className:"flex items-center justify-center h-full py-6 text-xs text-muted-foreground",children:Vx()}):t("div",{className:"space-y-0.5 pr-2",children:q.map((re)=>{let Ge=U.state.value===re.id;return o("div",{onClick:()=>{U.handleChange(re.id),v.setFieldValue("modelId",""),G(""),ie(!1),z("")},className:C("flex items-center justify-between px-2.5 py-2 rounded-md text-xs cursor-pointer transition-colors",Ge?"bg-accent text-accent-foreground font-medium":"hover:bg-muted/60 text-foreground"),children:[t("span",{className:"truncate flex-1 pr-2",children:re.name}),Ge&&t(Re,{className:"w-4 h-4 text-primary shrink-0"})]},re.id)})})})]})]}),J&&t(He,{errors:Ee(U.state.meta.errors)})]})}}),t(v.Field,{name:"modelId",children:(U)=>{let J=!!U.state.meta.errors.length&&U.state.meta.isTouched,ee=M?.find((re)=>re.id===U.state.value);return o(Oe,{"data-invalid":J,children:[o(Qe,{className:"flex items-center gap-2",children:[lx(),O&&t(F,{className:"w-3 h-3 animate-spin"})]}),o(mt,{open:N,onOpenChange:(re)=>{if(X(re),!re)G("")},modal:!0,children:[t(ht,{asChild:!0,children:o(E,{type:"button",variant:"outline",role:"combobox","aria-expanded":N,"aria-invalid":J,disabled:!w||O,className:C("w-full justify-between font-normal h-10 px-3 bg-background border-border hover:bg-accent/50",J&&"border-destructive ring-destructive"),children:[t("span",{className:"truncate flex items-center gap-2",children:ee?o(L,{children:[t("span",{className:"truncate font-medium text-foreground",children:ee.name||ee.modelId}),ee.name&&ee.name!==ee.modelId&&t(be,{variant:"secondary",className:"font-mono text-[10px] px-1.5 py-0 shrink-0",children:ee.modelId})]}):t("span",{className:"text-muted-foreground",children:LC()})}),t(ve,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),o(gt,{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:(re)=>re.stopPropagation(),children:[o("div",{className:"relative p-2 pb-1.5 border-b border-border shrink-0",children:[t(Bt,{className:"absolute left-4.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-muted-foreground"}),t(H,{placeholder:Tp(),value:j,onChange:(re)=>G(re.target.value),className:"pl-8 h-8 text-xs bg-muted/40",autoFocus:!0})]}),t(ce,{className:"w-full p-1",style:{height:ye.length===0?"96px":`${Math.min(ye.length*38+8,256)}px`},onWheel:(re)=>re.stopPropagation(),children:ye.length===0?t("div",{className:"flex items-center justify-center h-full py-6 text-xs text-muted-foreground",children:xd()}):t("div",{className:"space-y-0.5 pr-2",children:ye.map((re)=>{let Ge=U.state.value===re.id;return o("div",{onClick:()=>{U.handleChange(re.id),X(!1),G("")},className:C("flex items-center justify-between px-2.5 py-2 rounded-md text-xs cursor-pointer transition-colors",Ge?"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:re.name||re.modelId}),re.name&&re.name!==re.modelId&&o("span",{className:"font-mono text-[10px] text-muted-foreground truncate",children:["(",re.modelId,")"]}),re.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(jt,{className:"w-2.5 h-2.5"})})]})}),Ge&&t(Re,{className:"w-4 h-4 text-primary shrink-0"})]},re.id)})})})]})]}),J&&t(He,{errors:Ee(U.state.meta.errors)})]})}}),t("div",{className:"md:col-span-2",children:t(v.Field,{name:"thinkingLevel",children:(U)=>{let J={off:hI(),low:_I(),medium:yI(),high:gI()};return o(Oe,{children:[t(Qe,{children:AI()}),o(Le,{value:U.state.value,onValueChange:(ee)=>U.handleChange(ee),children:[t(Be,{children:t(Ze,{})}),t(Ue,{children:Xc.options.map((ee)=>t(ne,{value:ee,children:J[ee]||ee},ee))})]})]})}})})]}),t(v.Field,{name:"soul",children:(U)=>o(Oe,{children:[t(Qe,{children:l_()}),t(bi,{value:U.state.value,onBlur:U.handleBlur,onChange:(J)=>U.handleChange(J.target.value),placeholder:c_(),className:"min-h-[120px]"})]})}),o("div",{className:"space-y-4",children:[o(K,{className:"text-base font-bold flex items-center gap-2",children:[t(wt,{className:"w-5 h-5 text-primary"}),rA()]}),t("div",{className:"space-y-2",children:t(v.Field,{name:"skills",children:(U)=>o(L,{children:[y.map((J)=>{let ee=U.state.value?.includes(J.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(wt,{className:"w-4 h-4 text-muted-foreground"}),o("div",{className:"flex flex-col",children:[t("span",{className:"text-sm font-medium",children:J.name}),J.description&&t("span",{className:"text-[10px] text-muted-foreground line-clamp-1",children:J.description})]})]}),o("div",{className:"flex items-center gap-2",children:[t("span",{className:"text-xs text-muted-foreground",children:ee?Ff():Df()}),t(De,{checked:ee,onCheckedChange:(re)=>{if(re)U.handleChange([...U.state.value||[],J.id]);else U.handleChange((U.state.value||[]).filter((Ge)=>Ge!==J.id))}})]})]},J.id)}),y.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:Yx()})})]})})})]}),o("div",{className:"space-y-4 border-t border-border pt-6",children:[o(K,{className:"text-base font-bold flex items-center gap-2",children:[t(bn,{className:"w-5 h-5 text-primary"}),zc()]}),t("div",{className:"space-y-2",children:t(v.Field,{name:"mcpServerIds",children:(U)=>o(L,{children:[m.map((J)=>{let ee=U.state.value?.includes(J.id)||!1,re=J.status==="needs_auth"||!J.hasCredential&&J.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(bn,{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:J.name}),o(be,{variant:"outline",className:"text-[10px]",children:[J.toolCount??0," tools"]}),re&&t(be,{variant:"secondary",className:"text-[10px] bg-amber-500/10 text-amber-600 border-amber-500/20",children:Vh()})]}),t("span",{className:"text-[10px] font-mono text-muted-foreground line-clamp-1",children:J.url})]})]}),o("div",{className:"flex items-center gap-2",children:[t("span",{className:"text-xs text-muted-foreground",children:ee?Ff():Df()}),t(De,{checked:ee,onCheckedChange:(Ge)=>{if(Ge)U.handleChange([...U.state.value||[],J.id]);else U.handleChange((U.state.value||[]).filter((Tt)=>Tt!==J.id))}})]})]},J.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:lg()})})]})})})]}),o("div",{className:"space-y-4 border-t border-border pt-6",children:[o(K,{className:"text-base font-bold flex items-center gap-2",children:[t(To,{className:"w-5 h-5 text-primary"}),S_()]}),t("p",{className:"text-xs text-muted-foreground",children:E_()}),t("div",{className:"space-y-2",children:t(v.Field,{name:"deniedTools",children:(U)=>{let J=U.state.value||[];return t(L,{children:Vr.map((ee)=>{let re=!J.includes(ee.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:ee.name()}),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:re?Ff():Df()}),t(De,{checked:re,disabled:!g,onCheckedChange:(Ge)=>{if(Ge)U.handleChange(J.filter((Tt)=>Tt!==ee.id));else U.handleChange([...J,ee.id])}})]})]},ee.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:Pe()}),t(v.Subscribe,{selector:(U)=>[U.canSubmit,U.isSubmitting],children:([U,J])=>o(E,{type:"submit",className:"bg-primary hover:bg-primary/90 text-primary-foreground min-w-[120px]",disabled:!U||J||ke.isPending||Se.isPending,children:[(J||ke.isPending||Se.isPending)&&t(F,{className:"w-4 h-4 animate-spin mr-2"}),s?zs():cy()]})})]})]})]})})}var Lr=[{type:"chat",label:"Chat",icon:vo},{type:"autofill",label:"Autofill",icon:jt},{type:"embedding",label:"Embedding",icon:io}];function As({teamId:e}){let r=Q(),{canAdmin:a}=Dt(),[l,s]=u(!1),[d,c]=u("chat"),[g,_]=u(null),[p,y]=u(null),[x,m]=u(!1),[i,v]=u({chat:!0,autofill:!0,embedding:!0}),w=(T)=>{if(T==="chat")return zm();if(T==="autofill")return Um();return jm()},{data:M=[],isLoading:O}=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,G)=>G.id.localeCompare(j.id))}}),Y=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]}),k.success(t_())},onError:(T)=>{k.error(T.message)}}),z=B({mutationFn:async({agentId:T,permission:q})=>{let j=await A.api.agents[":agentId"].permission.$patch({param:{agentId:T},json:{permission:q}});if(!j.ok)throw Error(_l());return j.json()},onSuccess:()=>{r.invalidateQueries({queryKey:["agents",e]})},onError:(T)=>{k.error(T.message||_l())}}),de=B({mutationFn:async(T)=>{let q=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(!q.ok)throw Error("failed to update agent");return q.json()},onSuccess:()=>{r.invalidateQueries({queryKey:["agents",e]}),k.success(qm())},onError:(T)=>{k.error(T.message)}}),ie=(T)=>{v((q)=>({...q,[T]:!q[T]}))};return o(L,{children:[(l||g)&&t(Ds,{isOpen:!0,title:g?hh({name:g.name}):_y({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:ld()}),t(nt,{children:Fy({name:p?.name??""})})]}),o(tt,{children:[t(st,{children:Pe()}),t(ot,{className:"bg-destructive hover:bg-destructive/90 text-white",onClick:(T)=>{if(Y.isPending){T.preventDefault();return}if(p)Y.mutate(p.id)},children:Y.isPending?t(F,{className:"w-4 h-4 animate-spin"}):Oy()})]})]})}),O&&M.length===0?t("div",{className:"flex items-center justify-center p-12",children:t(F,{className:"w-8 h-8 animate-spin text-muted-foreground"})}):o("div",{className:"space-y-6 max-w-5xl mx-auto relative",children:[O&&t("div",{className:"absolute top-0 right-0 p-2",children:t(F,{className:"w-4 h-4 animate-spin text-muted-foreground"})}),Lr.map((T)=>{let q=M.filter((N)=>N.type===T.type),j=T.icon,G=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",!G&&"cursor-pointer hover:bg-muted/50 transition-colors"),onClick:!G?()=>ie(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"?N0():T.type==="autofill"?u0():mb()}),!G&&t(be,{variant:"secondary",className:"h-5 px-1.5 min-w-[1.25rem] text-[10px]",children:q.length})]}),o("div",{className:"flex items-center gap-2",children:[!(G&&q.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:(N)=>{N.stopPropagation(),c(T.type),s(!0)},children:t(pe,{className:"w-4 h-4"})}),!G&&t(ve,{className:C("w-5 h-5 text-muted-foreground transition-transform duration-200",i[T.type]?"rotate-180":"")})]})]}),(G||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:[q.map((N)=>t(_t,{className:"group relative overflow-hidden border-border hover:border-primary/50 transition-all duration-200 cursor-pointer pb-1 pt-1",onClick:()=>_(N),children:o(It,{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:N.avatar?t("img",{src:N.avatar,className:"w-full h-full object-cover",alt:""}):t(Et,{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:N.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(wt,{className:"w-3 h-3"}),f1({count:N.skills?.length||0})]})})]})]}),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(wr,{className:"w-4 h-4"})})}),t(Ae,{align:"end",className:"w-32",children:o(W,{onClick:(X)=>{X.stopPropagation(),y(N),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:N.type==="chat"?t("div",{onClick:(X)=>X.stopPropagation(),children:o(Le,{value:N.permission||"reviewer",onValueChange:(X)=>{z.mutate({agentId:N.id,permission:X})},disabled:!a,children:[t(Be,{className:"h-7 text-xs px-2 bg-background border-border w-[140px]",children:t(Ze,{children:N.permission==="reviewer"?Da():N.permission==="editor"?Oa():Fa()})}),o(Ue,{align:"start",children:[t(ne,{value:"reviewer",children:Da()}),t(ne,{value:"editor",children:Oa()}),t(ne,{value:"owner",children:Fa()})]})]})}):t("div",{})}),t("div",{onClick:(X)=>X.stopPropagation(),children:t(De,{checked:N.enabled,onCheckedChange:(X)=>{de.mutate({teamId:e,agentId:N.id,name:N.name,type:N.type,enabled:X,avatar:N.avatar,providerId:N.providerId,modelId:N.modelId,thinkingLevel:N.thinkingLevel,systemPrompt:N.systemPrompt,soul:N.soul,skills:N.skills?.map((xe)=>xe.skillId),deniedTools:N.deniedTools})}})})]})]})},N.id)),q.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:Px({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:my()})]})]})})]},T.type)})]})]})}S();S();function Ma({isOpen:e,onClose:r,onSubmit:a,initialValues:l,title:s,isLoading:d=!1,defaultApi:c,existingModelIds:g=[]}){let _=P(()=>vA.extend({modelId:f().min(1,Kh()).refine((m)=>{if(l?.modelId===m)return!0;return!g.includes(m)},{message:dx()})}),[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}}},y=$t({defaultValues:p(),validators:{onSubmit:_},onSubmit:async({value:m})=>{a(m)}});h(()=>{if(e)y.reset(p())},[e,l,c,y]);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(),y.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(y.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:Kh()}),t(H,{id:m.name,name:m.name,value:m.state.value,onBlur:m.handleBlur,onChange:(v)=>m.handleChange(v.target.value),placeholder:fx(),"aria-invalid":i}),i&&t(He,{errors:x(m.state.meta.errors)})]})}}),t(y.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:rb()}),t(H,{id:m.name,name:m.name,value:m.state.value||"",onBlur:m.handleBlur,onChange:(v)=>m.handleChange(v.target.value),placeholder:mx(),"aria-invalid":i}),i&&t(He,{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:DS()}),t(y.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:wp()}),t(De,{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(y.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:J0()}),t(H,{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(He,{errors:x(m.state.meta.errors)})]})}}),t(y.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:Cw()}),t(H,{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(He,{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(da,{className:"w-4 h-4 text-primary"}),WS()]}),o("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[t(y.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:ew()}),t(H,{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(He,{errors:x(m.state.meta.errors)})]})}}),t(y.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:MS()}),t(H,{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(He,{errors:x(m.state.meta.errors)})]})}}),t(y.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:I0()}),t(H,{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(He,{errors:x(m.state.meta.errors)})]})}}),t(y.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:T0()}),t(H,{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(He,{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:Pe()}),t(y.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(F,{className:"w-4 h-4 animate-spin"}):zs()})})]})]})]})})}S();function Is({isOpen:e,onClose:r,teamId:a,syncData:l,onSuccess:s}){let[d,c]=u(""),[g,_]=u(()=>new Set(l?.providers.map((q)=>q.name)||[])),[p,y]=u(()=>{let q=new Set;return l?.providers.forEach((j)=>{j.models.forEach((G)=>{q.add(`${j.name}:${G.modelId}`)})}),q});h(()=>{if(l){_(new Set(l.providers.map((j)=>j.name)));let q=new Set;l.providers.forEach((j)=>{j.models.forEach((G)=>{q.add(`${j.name}:${G.modelId}`)})}),y(q)}},[l]);let x=P(()=>{if(!l)return[];let q=d.trim().toLowerCase();if(!q)return l.providers;return l.providers.map((j)=>{let G=j.name.toLowerCase().includes(q),N=j.models.filter((X)=>G||X.modelId.toLowerCase().includes(q)||X.name.toLowerCase().includes(q));if(N.length>0)return{...j,models:N};return null}).filter((j)=>j!==null)},[l,d]),m=p.size,i=P(()=>{if(!l)return 0;let q=0;for(let j of l.providers)if(j.models.some((N)=>p.has(`${j.name}:${N.modelId}`)))q++;return q},[l,p]),v=(q)=>{_((j)=>{let G=new Set(j);if(G.has(q))G.delete(q);else G.add(q);return G})},w=()=>{if(!l)return;_(new Set(l.providers.map((q)=>q.name)))},M=()=>{_(new Set)},O=(q,j)=>{let G=`${q}:${j}`;y((N)=>{let X=new Set(N);if(X.has(G))X.delete(G);else X.add(G);return X})},Y=(q)=>{let j=l?.providers.find((N)=>N.name===q);if(!j||j.models.length===0)return;let G=j.models.every((N)=>p.has(`${q}:${N.modelId}`));y((N)=>{let X=new Set(N);return j.models.forEach((xe)=>{let ye=`${q}:${xe.modelId}`;if(G)X.delete(ye);else X.add(ye)}),X})},z=()=>{if(!l)return;let q=new Set;l.providers.forEach((j)=>{j.models.forEach((G)=>{q.add(`${j.name}:${G.modelId}`)})}),y(q)},de=()=>{y(new Set)},ie=B({mutationFn:async(q)=>{let j=await A.api.teams[":teamId"].providers["sync-apply"].$post({param:{teamId:a},json:q});if(!j.ok){let G=await j.json().catch(()=>({message:"Failed to apply sync"}));throw Error(G.message||"Failed to apply sync")}return await j.json()},onSuccess:(q)=>{k.success(X1({modelCount:q.addedModels,providerCount:q.addedProviders})),s(),r()},onError:(q)=>{k.error(q.message)}}),T=async()=>{if(!l||m===0)return;let q=[];for(let j of l.providers){let G=j.models.filter((N)=>p.has(`${j.name}:${N.modelId}`));if(G.length>0)q.push({name:j.name,isNewProvider:j.isNewProvider,config:j.config,models:G})}if(q.length===0)return;await ie.mutateAsync({providers:q})};return t(ue,{open:e,onOpenChange:(q)=>!q&&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(sn,{className:"w-5 h-5 text-primary"}),H1()]}),t(Ct,{className:"text-xs text-muted-foreground leading-relaxed mt-1.5",children:q1()})]}),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(Bt,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-muted-foreground"}),t(H,{value:d,onChange:(q)=>c(q.target.value),placeholder:W1(),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:G1()}),t(E,{type:"button",variant:"outline",size:"sm",onClick:M,className:"h-8 text-xs px-2.5",children:U1()}),t("div",{className:"w-px h-4 bg-border mx-1"}),t(E,{type:"button",variant:"outline",size:"sm",onClick:z,className:"h-8 text-xs px-2.5",children:Y1()}),t(E,{type:"button",variant:"outline",size:"sm",onClick:de,className:"h-8 text-xs px-2.5",children:j1()})]})]})}),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:ag()}):x.map((q)=>{let j=g.has(q.name),G=q.isNewProvider,N=q.models.filter((ye)=>p.has(`${q.name}:${ye.modelId}`)).length,X=N===q.models.length,xe=N>0&&!X;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(q.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(Dr,{checked:X?!0:xe?"indeterminate":!1,onCheckedChange:()=>Y(q.name),id:`provider-check-${q.name}`}),o("label",{htmlFor:`provider-check-${q.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:q.name})]})]}),o("div",{className:"flex items-center gap-2",children:[G?t(be,{variant:"secondary",className:"text-[10px] px-1.5 py-0 bg-primary/10 text-primary border-primary/20",children:Q1()}):t(be,{variant:"outline",className:"text-[10px] px-1.5 py-0 text-muted-foreground",children:$1()}),t("span",{className:"text-xs text-muted-foreground",children:V1({count:q.models.length})})]})]}),j&&t("div",{className:"border-t border-border/40 divide-y divide-border/30 bg-muted/10",children:q.models.map((ye)=>{let ke=p.has(`${q.name}:${ye.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(Dr,{checked:ke,onCheckedChange:()=>O(q.name,ye.modelId),id:`model-check-${q.name}-${ye.modelId}`}),o("label",{htmlFor:`model-check-${q.name}-${ye.modelId}`,className:"text-xs font-medium text-foreground cursor-pointer select-none truncate",children:[ye.name||ye.modelId,t("span",{className:"ml-1.5 text-[11px] text-muted-foreground font-mono font-normal",children:ye.modelId})]})]}),o("div",{className:"flex items-center gap-1.5 shrink-0 ml-2",children:[ye.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:K1()}),t("span",{className:"text-[11px] text-muted-foreground font-mono",children:z1({count:Math.round(ye.config.contextWindow/1000)})})]})]},ye.modelId)})})]},q.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:J1({modelCount:m,providerCount:i})}),o("div",{className:"flex items-center gap-2",children:[t(E,{type:"button",variant:"outline",onClick:r,disabled:ie.isPending,children:Pe()}),t(E,{type:"button",onClick:T,disabled:m===0||ie.isPending,className:"gap-2",children:ie.isPending?o(L,{children:[t(F,{className:"w-4 h-4 animate-spin"}),Z1()]}):L1({count:m})})]})]})]})})}var Es={"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 Ts({teamId:e}){let r=Q(),[a,l]=u(null),[s,d]=u(!1),[c,g]=u(""),[_,p]=u(!1),[y,x]=u(null),[m,i]=u(!1),[v,w]=u(null),M=B({mutationFn:async()=>{let j=await A.api.teams[":teamId"].providers["sync-check"].$post({param:{teamId:e}});if(!j.ok){let G=await j.json().catch(()=>({message:"Failed to check updates"}));throw Error(G.message||"Failed to check updates")}return await j.json()},onSuccess:(j)=>{if(j.totalNewModels===0&&j.totalNewProviders===0){k.info(eI());return}w(j),i(!0)},onError:(j)=>{k.error(j.message)}}),{data:O,isLoading:Y}=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()}}),z=P(()=>O?.find((j)=>j.id===a)||null,[O,a]),de=P(()=>O?.map((j)=>j.name)||[],[O]),ie=P(()=>{if(!O)return[];if(!c.trim())return O;let j=c.toLowerCase();return O.filter((G)=>G.name.toLowerCase().includes(j))},[O,c]),T=B({mutationFn:async(j)=>{let G=await A.api.teams[":teamId"].providers.$post({param:{teamId:e},json:{name:j.name,config:j.config,models:j.models}});if(!G.ok)throw Error("Failed to create provider");return await G.json()},onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"providers"]}),d(!1),k.success(fE())},onError:(j)=>{k.error(Bs({message:j.message}))}}),q=B({mutationFn:async(j)=>{let G=await A.api.providers[":id"].$delete({param:{id:j}});if(!G.ok)throw Error("Failed to delete provider");return await G.json()},onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"providers"]}),l(null),p(!1),x(null),k.success(pE())},onError:(j)=>{k.error(Bs({message:j.message}))}});if(Y)return t("div",{className:"flex h-64 items-center justify-center",children:t(F,{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"}),V0()]}),o("div",{className:"flex items-center gap-2",children:[t(E,{variant:"outline",onClick:()=>M.mutate(),disabled:M.isPending,className:"gap-2",children:M.isPending?o(L,{children:[t(F,{className:"w-4 h-4 animate-spin"}),B1()]}):o(L,{children:[t(ga,{className:"w-4 h-4"}),F1()]})}),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"}),Cm()]})]})]}),o("div",{className:"relative px-0.5",children:[t(Bt,{className:"absolute left-3.5 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),t(H,{placeholder:Gg(),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:[ie.map((j)=>t(_t,{className:"group cursor-pointer hover:border-primary/50 transition-all hover:shadow-md overflow-hidden",onClick:()=>l(j.id),children:o(It,{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(ua,{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(jt,{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(as,{className:"w-3 h-3"}),yx({count:j.modelsCount})]})]})]})]}),o("div",{className:"flex items-center gap-1",children:[o(he,{modal:!1,children:[t(ge,{asChild:!0,onClick:(G)=>G.stopPropagation(),children:t(E,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-foreground",children:t(wr,{className:"w-4 h-4"})})}),t(Ae,{align:"end",className:"w-32",children:o(W,{onClick:(G)=>{G.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)),O?.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:Gx()}),t("p",{className:"text-sm text-muted-foreground mt-1",children:UA()})]}),O&&O.length>0&&ie.length===0&&o("div",{className:"text-center py-12",children:[t(Bt,{className:"w-12 h-12 text-muted-foreground/50 mx-auto mb-4"}),t("h4",{className:"text-foreground font-medium",children:ag()}),t("p",{className:"text-sm text-muted-foreground mt-1",children:DI({query:c})}),t(E,{variant:"ghost",size:"sm",onClick:()=>g(""),className:"mt-4 text-primary hover:text-primary/90 hover:bg-primary/10",children:F0()})]})]})}),t(Pr,{isOpen:s,onClose:()=>d(!1),onSubmit:(j)=>T.mutate(j),isLoading:T.isPending,existingProviderNames:de}),z&&t(Br,{isOpen:!!z,onClose:()=>l(null),provider:z,teamId:e,existingProviderNames:de}),t(Je,{open:_,onOpenChange:p,children:o(Xe,{children:[o(et,{children:[t(rt,{children:ld()}),t(nt,{children:$y({name:y?.name??""})})]}),o(tt,{children:[t(st,{onClick:()=>x(null),children:Pe()}),o(ot,{className:"bg-destructive hover:bg-destructive/90 text-destructive-foreground",onClick:()=>{if(y)q.mutate(y.id)},children:[q.isPending?t(F,{className:"w-4 h-4 animate-spin mr-2"}):t(we,{className:"w-4 h-4 mr-2"}),at()]})]})]})}),t(Is,{isOpen:m,onClose:()=>i(!1),teamId:e,syncData:v,onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"providers"]})}})]})}function Pr({isOpen:e,onClose:r,onSubmit:a,isLoading:l,existingProviderNames:s}){let[d,c]=u([]),[g,_]=u(!1),[p,y]=u(null),x=P(()=>R({name:f().min(1,wg()).refine((w)=>!s.includes(w),{message:xg()}),config:na}),[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),y(null)},[e,m]);let i=(w)=>w.map((M)=>{if(typeof M==="string")return{message:M};if(M&&typeof M==="object"&&"message"in M)return{message:String(M.message)};return{message:String(M||"")}}),v=(w)=>{if(p!==null)c((M)=>M.map((O,Y)=>Y===p?w:O)),y(null);else c((M)=>[w,...M]),_(!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:HA()}),t(Ct,{children:th()})]}),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 M=!!w.state.meta.errors.length&&w.state.meta.isTouched;return o(Oe,{"data-invalid":M,children:[t(Qe,{htmlFor:w.name,children:vg()}),t(H,{id:w.name,name:w.name,value:w.state.value,onBlur:w.handleBlur,onChange:(O)=>w.handleChange(O.target.value),placeholder:Sg(),"aria-invalid":M}),M&&t(He,{errors:i(w.state.meta.errors)})]})}}),t(m.Field,{name:"config.api",children:(w)=>{let M=!!w.state.meta.errors.length&&w.state.meta.isTouched;return o(Oe,{"data-invalid":M,children:[t(Qe,{htmlFor:w.name,children:Fh()}),o(Le,{onValueChange:w.handleChange,value:w.state.value,children:[t(Be,{id:w.name,"aria-invalid":M,children:t(Ze,{placeholder:Vg()})}),t(Ue,{children:eu.map((O)=>t(ne,{value:O,children:Es[O]},O))})]}),M&&t(He,{errors:i(w.state.meta.errors)})]})}}),t("div",{className:"md:col-span-2",children:t(m.Field,{name:"config.baseUrl",children:(w)=>{let M=!!w.state.meta.errors.length&&w.state.meta.isTouched;return o(Oe,{"data-invalid":M,children:[t(Qe,{htmlFor:w.name,children:Jm()}),t(H,{id:w.name,name:w.name,value:w.state.value||"",onBlur:w.handleBlur,onChange:(O)=>w.handleChange(O.target.value),placeholder:"https://api.openai.com/v1","aria-invalid":M}),t(sa,{children:fg()}),M&&t(He,{errors:i(w.state.meta.errors)})]})}})}),t("div",{className:"md:col-span-2",children:t(m.Field,{name:"config.apiKey",children:(w)=>{let M=!!w.state.meta.errors.length&&w.state.meta.isTouched;return o(Oe,{"data-invalid":M,children:[t(Qe,{htmlFor:w.name,children:ad()}),t(H,{id:w.name,name:w.name,type:"text",value:w.state.value||"",onBlur:w.handleBlur,onChange:(O)=>w.handleChange(O.target.value),placeholder:Vm(),"aria-invalid":M}),t(sa,{className:"text-xs mt-1",children:Gm()}),M&&t(He,{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(K,{className:"text-base font-semibold",children:vd()}),t("p",{className:"text-xs text-muted-foreground mt-0.5",children:gx()})]}),o(E,{type:"button",variant:"outline",size:"sm",onClick:()=>_(!0),className:"gap-1.5",children:[t(pe,{className:"w-4 h-4"}),od()]})]}),d.length===0?t("div",{className:"text-center py-8 rounded-xl border border-dashed text-muted-foreground text-sm",children:xd()}):t("div",{className:"space-y-2",children:d.map((w,M)=>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:()=>y(M),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(jt,{className:"w-2.5 h-2.5"})," ",wp()]})]}),o("div",{className:"text-xs text-muted-foreground mt-1 flex items-center gap-2",children:[o("span",{children:[w.config.contextWindow?.toLocaleString()," ",pA()]}),t("span",{children:"·"}),t("span",{children:sh({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:(O)=>{O.stopPropagation(),c((Y)=>Y.filter((z,de)=>de!==M))},children:t(we,{className:"w-3.5 h-3.5"})})})]},w.modelId+M))})]})]})})}),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:Pe()}),t(m.Subscribe,{selector:(w)=>[w.canSubmit,w.isSubmitting],children:([w,M])=>t(E,{type:"submit",className:"min-w-[120px]",disabled:!w||M||l,children:M||l?t(F,{className:"w-4 h-4 animate-spin"}):Cm()})})]})]}),(g||p!==null)&&t(Ma,{isOpen:!0,onClose:()=>{_(!1),y(null)},onSubmit:v,title:p!==null?gh():od(),initialValues:p!==null?d[p]:null,defaultApi:m.getFieldValue("config.api"),existingModelIds:d.filter((w,M)=>M!==p).map((w)=>w.modelId)},p!==null?`edit-${p}-${d[p]?.modelId}`:"add")]})})}function Br({isOpen:e,onClose:r,provider:a,teamId:l,existingProviderNames:s}){let d=Q(),[c,g]=u("general"),[_,p]=u(""),[y,x]=u(!1),[m,i]=u(null),[v,w]=u(null),{data:M=[],isLoading:O}=Z({queryKey:["teams",l,"providers",a.id,"models"],queryFn:async()=>{let N=await A.api.providers[":id"].models.$get({param:{id:a.id}});if(!N.ok)throw Error("Failed to fetch models");return await N.json()},enabled:e}),Y=B({mutationFn:async(N)=>{let X=await A.api.providers[":id"].$put({param:{id:a.id},json:{name:N.name,config:N.config}});if(!X.ok)throw Error("Failed to update provider");return await X.json()},onSuccess:()=>{d.invalidateQueries({queryKey:["teams",l,"providers"]}),k.success(Tg())},onError:(N)=>{k.error(Bs({message:N.message}))}}),z=B({mutationFn:async(N)=>{let X=await A.api.providers[":id"].models.$post({param:{id:a.id},json:N});if(!X.ok)throw Error("Failed to create model");return await X.json()},onSuccess:()=>{d.invalidateQueries({queryKey:["teams",l,"providers",a.id,"models"]}),d.invalidateQueries({queryKey:["teams",l,"providers"]}),x(!1),k.success(cx())},onError:(N)=>{k.error(Bs({message:N.message}))}}),de=B({mutationFn:async({modelDbId:N,values:X})=>{let xe=await A.api.providers[":id"].models[":modelDbId"].$put({param:{id:a.id,modelDbId:N},json:X});if(!xe.ok)throw Error("Failed to update model");return await xe.json()},onSuccess:()=>{d.invalidateQueries({queryKey:["teams",l,"providers",a.id,"models"]}),i(null),k.success(hx())},onError:(N)=>{k.error(Bs({message:N.message}))}}),ie=B({mutationFn:async(N)=>{let X=await A.api.providers[":id"].models[":modelDbId"].$delete({param:{id:a.id,modelDbId:N}});if(!X.ok)throw Error("Failed to delete model");return await X.json()},onSuccess:()=>{d.invalidateQueries({queryKey:["teams",l,"providers",a.id,"models"]}),d.invalidateQueries({queryKey:["teams",l,"providers"]}),w(null),k.success(ux())},onError:(N)=>{k.error(Bs({message:N.message}))}}),T=P(()=>R({name:f().min(1,wg()).refine((N)=>{if(a.name===N)return!0;return!s.includes(N)},{message:xg()}),config:na}),[s,a.name]),q=$t({defaultValues:{name:a.name,config:a.config},validators:{onSubmit:T},onSubmit:async({value:N})=>{Y.mutate({name:N.name,config:N.config})}});h(()=>{if(e)q.reset(),g("general"),p("")},[e,q]);let j=(N)=>N.map((X)=>{if(typeof X==="string")return{message:X};if(X&&typeof X==="object"&&"message"in X)return{message:String(X.message)};return{message:String(X||"")}}),G=P(()=>{if(!_.trim())return M;let N=_.toLowerCase();return M.filter((X)=>X.modelId.toLowerCase().includes(N)||X.name?.toLowerCase().includes(N))},[M,_]);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:hh({name:a.name})}),t(Ct,{children:th()})]}),o(So,{value:c,onValueChange:(N)=>g(N),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(Qr,{value:"general",children:Oh()}),o(Qr,{value:"models",className:"gap-2",children:[vd(),t(be,{variant:"secondary",className:"h-5 px-1.5 text-[11px]",children:M.length})]})]})}),t(kn,{value:"general",className:"flex-1 flex flex-col min-h-0 m-0",children:o("form",{onSubmit:(N)=>{N.preventDefault(),N.stopPropagation(),q.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(q.Field,{name:"name",children:(N)=>{let X=!!N.state.meta.errors.length&&N.state.meta.isTouched;return o(Oe,{"data-invalid":X,children:[t(Qe,{htmlFor:N.name,children:vg()}),t(H,{id:N.name,name:N.name,value:N.state.value,onBlur:N.handleBlur,onChange:(xe)=>N.handleChange(xe.target.value),placeholder:Sg(),"aria-invalid":X}),X&&t(He,{errors:j(N.state.meta.errors)})]})}}),t(q.Field,{name:"config.api",children:(N)=>{let X=!!N.state.meta.errors.length&&N.state.meta.isTouched;return o(Oe,{"data-invalid":X,children:[t(Qe,{htmlFor:N.name,children:Fh()}),o(Le,{onValueChange:N.handleChange,value:N.state.value,children:[t(Be,{id:N.name,"aria-invalid":X,children:t(Ze,{placeholder:Vg()})}),t(Ue,{children:eu.map((xe)=>t(ne,{value:xe,children:Es[xe]},xe))})]}),X&&t(He,{errors:j(N.state.meta.errors)})]})}}),t("div",{className:"md:col-span-2",children:t(q.Field,{name:"config.baseUrl",children:(N)=>{let X=!!N.state.meta.errors.length&&N.state.meta.isTouched;return o(Oe,{"data-invalid":X,children:[t(Qe,{htmlFor:N.name,children:Jm()}),t(H,{id:N.name,name:N.name,value:N.state.value||"",onBlur:N.handleBlur,onChange:(xe)=>N.handleChange(xe.target.value),placeholder:"https://api.openai.com/v1","aria-invalid":X}),t(sa,{children:fg()}),X&&t(He,{errors:j(N.state.meta.errors)})]})}})}),t("div",{className:"md:col-span-2",children:t(q.Field,{name:"config.apiKey",children:(N)=>{let X=!!N.state.meta.errors.length&&N.state.meta.isTouched;return o(Oe,{"data-invalid":X,children:[t(Qe,{htmlFor:N.name,children:ad()}),t(H,{id:N.name,name:N.name,type:"text",value:N.state.value||"",onBlur:N.handleBlur,onChange:(xe)=>N.handleChange(xe.target.value),placeholder:Vm(),"aria-invalid":X}),t(sa,{className:"text-xs mt-1",children:Gm()}),X&&t(He,{errors:j(N.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:Pe()}),t(q.Subscribe,{selector:(N)=>[N.canSubmit,N.isSubmitting],children:([N,X])=>t(E,{type:"submit",className:"min-w-[120px]",disabled:!N||X||Y.isPending,children:X||Y.isPending?t(F,{className:"w-4 h-4 animate-spin"}):zs()})})]})]})}),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(Bt,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),t(H,{placeholder:Tp(),value:_,onChange:(N)=>p(N.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"}),od()]})]}),t("div",{className:"flex-1 min-h-0 px-6",children:t(ce,{className:"h-full pr-4",children:O?t("div",{className:"flex h-48 items-center justify-center",children:t(F,{className:"h-6 w-6 animate-spin text-primary"})}):G.length===0?t("div",{className:"text-center py-12 border border-dashed rounded-xl text-muted-foreground text-sm",children:xd()}):t("div",{className:"space-y-2 pb-4",children:G.map((N)=>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(N),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:N.name||N.modelId}),t(be,{variant:"secondary",className:"font-mono text-[10px] px-1.5 py-0.5",children:N.modelId}),N.config?.reasoning&&o(be,{variant:"outline",className:"text-[10px] gap-1 bg-primary/10 text-primary border-primary/20 h-5",children:[t(jt,{className:"w-2.5 h-2.5"})," ",wp()]})]}),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:[N.config?.contextWindow?.toLocaleString()," ",pA()]}),t("span",{children:"·"}),t("span",{children:Iw({count:N.config?.maxTokens?.toLocaleString()??"0"})}),t("span",{children:"·"}),t("span",{children:sh({input:N.config?.cost?.input??0,output:N.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:(X)=>{X.stopPropagation(),w(N)},children:t(we,{className:"w-3.5 h-3.5"})})})]},N.id))})})})]})]}),y&&t(Ma,{isOpen:y,onClose:()=>x(!1),onSubmit:(N)=>z.mutate(N),title:od(),isLoading:z.isPending,defaultApi:a.config.api,existingModelIds:M.map((N)=>N.modelId)}),m&&t(Ma,{isOpen:!!m,onClose:()=>i(null),onSubmit:(N)=>de.mutate({modelDbId:m.id,values:N}),title:gh(),isLoading:de.isPending,initialValues:{modelId:m.modelId,name:m.name,config:m.config},defaultApi:a.config.api,existingModelIds:M.filter((N)=>N.id!==m.id).map((N)=>N.modelId)}),t(Je,{open:!!v,onOpenChange:(N)=>!N&&w(null),children:o(Xe,{children:[o(et,{children:[t(rt,{children:ld()}),t(nt,{children:jy({name:v?.name||v?.modelId||""})})]}),o(tt,{children:[t(st,{onClick:()=>w(null),children:Pe()}),o(ot,{className:"bg-destructive hover:bg-destructive/90 text-destructive-foreground",onClick:()=>{if(v)ie.mutate(v.id)},children:[ie.isPending?t(F,{className:"w-4 h-4 animate-spin mr-2"}):t(we,{className:"w-4 h-4 mr-2"}),at()]})]})]})})]})})}S();function Vs({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(Yo());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(Th());return await w.json()},onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"sandbox"]}),k.success(hC())},onError:(v)=>{k.error(v instanceof Error?v.message:Th())}}),_=(v)=>{c({networkSandboxEnabled:v})},p=(v)=>{if(v.preventDefault(),!a.trim())return;if(s?.allowedDomains.includes(a.trim())){k.error(nb());return}let w=[...s?.allowedDomains||[],a.trim()],M=s?.pendingDomains||[];c({allowedDomains:w,pendingDomains:M}),l("")},y=(v)=>{let w=(s?.allowedDomains||[]).filter((O)=>O!==v),M=s?.pendingDomains||[];c({allowedDomains:w,pendingDomains:M})},x=(v)=>{let w=[...s?.allowedDomains||[],v],M=(s?.pendingDomains||[]).filter((O)=>O!==v);c({allowedDomains:w,pendingDomains:M})},m=(v)=>{let w=(s?.pendingDomains||[]).filter((M)=>M!==v);c({allowedDomains:s?.allowedDomains||[],pendingDomains:w})};if(d)return t("div",{className:"flex items-center justify-center p-8",children:t(F,{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(_t,{children:[o(kt,{children:[o("div",{className:"flex items-center gap-2",children:[t(ua,{className:"w-5 h-5 text-primary"}),t(Rt,{children:xx()})]}),t(Ut,{children:Sx()})]}),o(It,{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:bb()}),t("p",{className:"text-xs text-muted-foreground",children:Cx()})]}),t(De,{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:Ex()})]}),o("form",{onSubmit:p,className:"flex gap-2 mb-6",children:[t(H,{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(F,{className:"w-4 h-4 animate-spin"}):t(pe,{className:"w-4 h-4 mr-2"}),BA()]})]}),o("div",{className:"space-y-2",children:[t("h4",{className:"text-sm font-medium text-muted-foreground mb-3",children:G_()}),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:()=>y(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:Zx()})]})]})]})]}),o(_t,{className:"border-orange-500/20 bg-orange-500/5",children:[o(kt,{children:[o("div",{className:"flex items-center gap-2",children:[t(Vl,{className:"w-5 h-5 text-orange-500"}),t(Rt,{children:BS()})]}),t(Ut,{children:US()})]}),t(It,{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(Re,{className:"w-4 h-4 mr-1.5"}),e0()]}),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:$x()})})})]}),t(_t,{children:o(kt,{children:[t(Rt,{children:gv()}),t(Ut,{children:Av()})]})})]})})}S();var qr=(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"})]}),Ls=({teamId:e})=>{let r=Q(),{canAdmin:a}=Dt(),[l,s]=u(!1),[d,c]=u(!1),[g,_]=u(!1),[p,y]=u(null),{data:x,isLoading:m}=Z({queryKey:["teams",e,"skills"],queryFn:async()=>{let M=await A.api.teams[":teamId"].skills.$get({param:{teamId:e}});if(!M.ok)throw Error(Yo());return await M.json()}}),i=B({mutationFn:async(M)=>{if(!(await A.api.skills[":id"].$delete({param:{id:M}})).ok)throw Error(Ra())},onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"skills"]}),_(!1)}}),v=B({mutationFn:async({id:M,permission:O})=>{if(!(await A.api.skills[":id"].permission.$patch({param:{id:M},json:{permission:O}})).ok)throw Error(_l())},onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"skills"]})},onError:(M)=>{alert(M.message||_l())}}),w=x?.skills||[];return o(_t,{children:[o(kt,{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(wt,{className:"w-6 h-6"})}),o("div",{children:[t(Rt,{className:"text-xl font-bold",children:nA()}),t(Ut,{children:m1()})]})]}),o(E,{onClick:()=>s(!0),className:"gap-2",children:[t(pe,{className:"w-4 h-4"})," ",VA()]})]}),t(It,{children:m?t("div",{className:"flex justify-center py-10",children:t(F,{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(wt,{className:"w-6 h-6"})}),t("h3",{className:"text-lg font-medium text-foreground",children:Jx()}),t("p",{className:"text-muted-foreground mt-1 max-w-xs mx-auto",children:QA()})]}):t("div",{className:"space-y-4",children:w.map((M)=>t(jr,{skill:M,canAdmin:a,onDelete:()=>{y(M),_(!0)},onConfigure:()=>{y(M),c(!0)},onPermissionChange:(O)=>v.mutate({id:M.id,permission:O})},M.id))})}),t(Or,{open:l,onOpenChange:s,teamId:e}),p&&t($r,{open:d,onOpenChange:(M)=>{if(c(M),!M)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:ld()}),t(nt,{children:Qy({name:p?.name??""})})]}),o(tt,{children:[t(st,{children:Pe()}),o(ot,{className:"bg-destructive hover:bg-destructive/90 text-destructive-foreground",onClick:()=>{if(p)i.mutate(p.id)},children:[i.isPending?t(F,{className:"w-4 h-4 animate-spin mr-2"}):t(we,{className:"w-4 h-4 mr-2"}),at()]})]})]})})]})},jr=({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(wr,{className:"w-4 h-4"})})}),t(Ae,{align:"end",className:"w-32",children:o(W,{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||sg()})]}),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:[AA()," ",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:Rp()})}),o(Ue,{align:"end",children:[t(ne,{value:"reviewer",children:Da()}),t(ne,{value:"editor",children:Oa()}),t(ne,{value:"owner",children:Fa()})]})]})})]})]}),Or=({open:e,onOpenChange:r,teamId:a})=>{let l=Q(),[s,d]=u(""),[c,g]=u(!1),_=b(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}),y=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
|
-
|
|
3
|
-
${kS()}`)){await y({...m,override:!0});return}}else if(!i.ok){let v=await i.json().catch(()=>({}));throw Error(v.error||Vb())}else l.invalidateQueries({queryKey:["teams",a,"skills"]}),r(!1),d("")}catch(i){if(i instanceof Error)alert(i.message);else alert(id())}finally{g(!1)}},x=async(m)=>{if(!m||m.length===0)return;let i=p?.data?.[0]?.id;if(!i){alert(wx());return}let v=m[0];if(!v.name.toLowerCase().endsWith(".zip")){alert(lS());return}g(!0);try{let w=v.name,M=v.type||"application/zip",O=await A.api.projects[":projectId"].attachments.$post({param:{projectId:i},json:{fileName:w,size:v.size,contentType:M}});if(!O.ok)throw Error("Failed to get upload URL");let{id:Y,uploadUrl:z}=await O.json();if(!(await fetch(z,{method:"PUT",body:v,headers:{"Content-Type":M}})).ok)throw Error("Failed to upload file to storage");await y({assetId:Y})}catch(w){if(w instanceof Error)alert(w.message);else alert(id())}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:$A()}),t(Ct,{children:Xv()})]}),o("div",{className:"space-y-6 pt-4",children:[o("div",{className:"space-y-3",children:[t(K,{children:RS()}),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:$C()}),t("p",{className:"text-[10px] text-muted-foreground mt-1 uppercase tracking-wider font-semibold",children:NS()})]})]}),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(F,{className:"w-4 h-4 animate-spin"}),JS()]})]}),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:IS()})})]}),t("div",{className:"space-y-4",children:o("div",{className:"space-y-2",children:[t(K,{htmlFor:"githubUrl",children:Nv()}),o("div",{className:"flex gap-2",children:[o("div",{className:"relative flex-1",children:[t(qr,{className:"absolute left-3 top-2.5 w-4 h-4 text-muted-foreground"}),t(H,{id:"githubUrl",placeholder:"https://github.com/owner/repo",value:s,onChange:(m)=>d(m.target.value),disabled:c,className:"pl-9"})]}),t(E,{onClick:()=>y({githubUrl:s}),disabled:!s||c,className:"px-6",children:c&&s?t(F,{className:"w-4 h-4 animate-spin"}):tw()})]}),t("p",{className:"text-[10px] text-muted-foreground italic",children:Pv()})]})})]})]})})},$r=({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,M)=>{let O=[...d.environmentVariables];O[w]={...O[w],default:M},c({...d,environmentVariables:O})},y=(w,M)=>{let O=[...d.environmentVariables];O[w]={...O[w],name:M},c({...d,environmentVariables:O})},x=()=>{c({...d,environmentVariables:[...d.environmentVariables,{name:"",default:""}]})},m=(w)=>{let M=[...d.environmentVariables];M.splice(w,1),c({...d,environmentVariables:M})},i=async()=>{let w=d.environmentVariables.filter((O)=>O.name.trim()!==""),M={...d,environmentVariables:w};_(!0);try{let O=await A.api.skills[":id"].config.$patch({param:{id:l.id},json:{config:M}});if(!O.ok){let Y=await O.json().catch(()=>({}));throw Error(Y.error||"Failed to update config")}s.invalidateQueries({queryKey:["teams",a,"skills"]}),r(!1)}catch(O){if(O instanceof Error)alert(O.message);else alert(id())}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(Kl,{className:"w-5 h-5 text-primary"}),G0({name:l.name})]})}),t(Ct,{children:bw()})]}),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:Bx()})}):v.map((w,M)=>o("div",{className:"p-4 bg-muted/50 rounded-xl border border-border space-y-3 relative group",children:[t("button",{onClick:()=>m(M),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(K,{className:"text-[10px] uppercase tracking-wider font-bold text-muted-foreground",children:QI()}),t(H,{value:w.name,onChange:(O)=>y(M,O.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(K,{className:"text-[10px] uppercase tracking-wider font-bold text-muted-foreground",children:Dy()}),t(H,{value:w.default||"",onChange:(O)=>p(M,O.target.value),placeholder:CS(),className:"h-8 bg-background border-border text-sm"}),t("p",{className:"text-[10px] text-muted-foreground italic",children:Tb()})]})]},M))})}),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"})," ",JA()]}),o("div",{className:"flex gap-2",children:[t(E,{variant:"ghost",onClick:()=>r(!1),children:Pe()}),o(E,{onClick:i,disabled:g,className:"px-8",children:[g?t(F,{className:"w-4 h-4 animate-spin mr-2"}):null,zs()]})]})]})]})})};S();S();var Ps=({isOpen:e,onClose:r,teamId:a,server:l})=>{let s=Q(),d=!!l,[c,g]=u(""),[_,p]=u("streamable_http"),[y,x]=u("reviewer"),[m,i]=u("auto"),[v,w]=u(""),[M,O]=u(""),[Y,z]=u(""),[de,ie]=u(""),[T,q]=u("authorization_code"),[j,G]=u([]),[N,X]=u([]),[xe,ye]=u({}),[ke,Se]=u(!1);h(()=>{if(l)g(l.url),p(l.transport||"streamable_http"),x(l.permission||"reviewer"),i(l.authType||"auto"),G(Array.isArray(l.config?.directTools)?l.config.directTools:[]),X(l.config?.excludeTools??[]),ye({}),Se(!1);else g(""),p("streamable_http"),x("reviewer"),i("auto"),w(""),O(""),z(""),ie(""),q("authorization_code"),G([]),X([]),ye({}),Se(!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:M||void 0,clientSecret:Y||void 0,scope:de||void 0}};return},{data:_e,isLoading:Fe,refetch:Ee}=Z({queryKey:["mcp","servers",l?.id,"tools"],queryFn:async()=>{if(!l?.id)return{tools:[]};let me=await A.api.mcp.servers[":id"].tools.$get({param:{id:l.id}});if(!me.ok)throw Error("Failed to fetch tools");return await me.json()},enabled:e&&d&&!!l?.id}),U=B({mutationFn:async()=>{if(!l?.id)return;let me=await A.api.mcp.servers[":id"].refresh.$post({param:{id:l.id}});if(!me.ok){let lt=await me.json().catch(()=>({}));throw Error(lt.error||"Failed to refresh server")}return await me.json()},onSuccess:()=>{k.success(zw()),Ee(),s.invalidateQueries({queryKey:["teams",a,"mcp","servers"]})},onError:(me)=>{k.error(me.message)}}),J=B({mutationFn:async()=>{let me={directTools:j.length>0?j:void 0,excludeTools:N.length>0?N:void 0};if(d&&l){let lt={transport:_,permission:y,authConfig:se(),config:me},je=await A.api.mcp.servers[":id"].$patch({param:{id:l.id},json:lt});if(!je.ok){let ct=await je.json().catch(()=>({}));throw Error(ct.error||_l())}return await je.json()}else{let lt={url:c.trim()},je=await A.api.teams[":teamId"].mcp.servers.$post({param:{teamId:a},json:lt});if(!je.ok){let aa=await je.json().catch(()=>({}));throw Error(aa.error||id())}return await je.json()}},onSuccess:()=>{k.success(d?yg():zc()),s.invalidateQueries({queryKey:["teams",a,"mcp","servers"]}),r()},onError:(me)=>{k.error(me.message)}}),ee=(me)=>{if(me.preventDefault(),!c.trim())return;J.mutate()},re=_e?.tools??[],Ge=(me)=>{if(N.includes(me))return"off";if(j.includes(me))return"direct";return"on"},Tt=(me,lt)=>{if(lt==="off")X((je)=>je.includes(me)?je:[...je,me]),G((je)=>je.filter((ct)=>ct!==me));else if(lt==="on")X((je)=>je.filter((ct)=>ct!==me)),G((je)=>je.filter((ct)=>ct!==me));else if(lt==="direct")X((je)=>je.filter((ct)=>ct!==me)),G((je)=>je.includes(me)?je:[...je,me])},oe=(me)=>{let lt=re.map((je)=>je.name);if(me==="off")X(lt),G([]);else if(me==="on")X([]),G([]);else if(me==="direct")X([]),G(lt)},We=(me)=>{ye((lt)=>({...lt,[me]:!lt[me]}))};return t(ue,{open:e,onOpenChange:(me)=>!me&&r(),children:d&&l?o(ae,{className:"sm:max-w-2xl h-[85vh] flex flex-col p-0 overflow-hidden",children:[U.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(F,{className:"w-8 h-8 animate-spin text-primary mb-2"}),o("span",{className:"text-xs font-medium text-muted-foreground",children:[Hh(),"..."]})]}),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(bn,{className:"w-5 h-5 text-primary"}),ab()]}),t(Ct,{children:bd()})]}),o("form",{onSubmit:ee,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:qw()}),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:Gh()}),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:Al()}),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"}),$h()]})]}),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:jw()}),t("p",{onClick:()=>Se((me)=>!me),className:`text-xs text-muted-foreground whitespace-pre-wrap leading-relaxed cursor-pointer transition-all ${ke?"":"line-clamp-2"}`,title:ke?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(K,{className:"text-xs",children:Xw()}),o(Le,{value:_,onValueChange:(me)=>p(me),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(K,{className:"text-xs",children:Rp()}),o(Le,{value:y,onValueChange:(me)=>x(me),children:[t(Be,{className:"h-9 text-xs",children:t(Ze,{})}),o(Ue,{children:[t(ne,{value:"reviewer",children:Da()}),t(ne,{value:"editor",children:Oa()}),t(ne,{value:"owner",children:Fa()})]})]})]})]}),o("div",{className:"space-y-3 pt-3 border-t border-border",children:[o("div",{className:"space-y-1.5",children:[t(K,{className:"text-xs",children:Nw()}),o(Le,{value:m,onValueChange:(me)=>i(me),children:[t(Be,{className:"h-9 text-xs",children:t(Ze,{})}),o(Ue,{children:[t(ne,{value:"auto",children:Tw()}),t(ne,{value:"none",children:kw()}),t(ne,{value:"bearer",children:Mw()}),t(ne,{value:"oauth",children:Rw()})]})]})]}),m==="bearer"&&o("div",{className:"space-y-1.5",children:[t(K,{className:"text-xs",children:Pw()}),t(H,{className:"h-9 text-xs font-mono",type:"password",value:v,onChange:(me)=>w(me.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(K,{className:"text-xs",children:Bw()}),o(Le,{value:T,onValueChange:(me)=>q(me),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(K,{className:"text-xs",children:Lw()}),t(H,{className:"h-9 text-xs",value:M,onChange:(me)=>O(me.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(K,{className:"text-xs",children:Zw()}),t(H,{className:"h-9 text-xs",type:"password",value:Y,onChange:(me)=>z(me.target.value),placeholder:"Optional Secret"})]}),o("div",{className:"space-y-1.5",children:[t(K,{className:"text-xs",children:Uw()}),t(H,{className:"h-9 text-xs",value:de,onChange:(me)=>ie(me.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(K,{className:"text-xs font-semibold flex items-center gap-1.5",children:[t(Io,{className:"w-3.5 h-3.5"}),Ww()," (",re.length,")"]}),t("p",{className:"text-[11px] text-muted-foreground leading-relaxed",children:Jw()}),re.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:()=>oe("off"),disabled:U.isPending||Fe,children:Ow()}),t(E,{type:"button",variant:"outline",size:"sm",className:"h-7 text-[11px] px-2.5",onClick:()=>oe("on"),disabled:U.isPending||Fe,children:Fw()}),t(E,{type:"button",variant:"outline",size:"sm",className:"h-7 text-[11px] px-2.5",onClick:()=>oe("direct"),disabled:U.isPending||Fe,children:Dw()})]})]}),t("div",{className:"space-y-2",children:Fe?t("div",{className:"flex justify-center py-8",children:t(F,{className:"w-6 h-6 animate-spin text-primary"})}):re.length===0?t("div",{className:"text-center py-6 text-muted-foreground text-xs",children:tS()}):re.map((me)=>{let lt=Ge(me.name),je=!!xe[me.name],ct=me.inputSchema,aa=ct?.properties&&Object.keys(ct.properties).length>0;return o("div",{className:`border border-border rounded-lg p-3 transition-colors ${lt!=="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:()=>aa&&We(me.name),children:[aa?je?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:me.name}),me.title&&t(be,{variant:"outline",className:"text-[10px]",children:me.title})]}),me.description&&t("p",{className:"text-xs text-muted-foreground mt-1 break-words line-clamp-3",children:me.description})]})]}),t("div",{className:"flex items-center gap-2 shrink-0",children:o(Mo,{type:"single",value:lt,onValueChange:(Wt)=>{if(Wt)Tt(me.name,Wt)},size:"sm",variant:"outline",disabled:U.isPending||Fe,children:[t(Ar,{value:"off",className:"text-[11px] px-2 h-7",children:Qw()}),t(Ar,{value:"on",className:"text-[11px] px-2 h-7",children:Kw()}),t(Ar,{value:"direct",className:"text-[11px] px-2 h-7",children:Vw()})]})})]}),je&&aa&&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:kI()}),t("div",{className:"grid grid-cols-1 gap-1.5",children:Object.entries(ct.properties).map(([Wt,Aa])=>{let Ys=ct.required?.includes(Wt);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:Wt}),Ys&&t("span",{className:"text-[10px] text-red-500 font-bold",children:"*"}),t(be,{variant:"secondary",className:"text-[9px] px-1 py-0",children:Aa.type||"any"})]}),Aa.description&&t("span",{className:"text-[11px] text-muted-foreground break-words sm:max-w-[320px]",children:Aa.description})]},Wt)})})]})]},me.name)})})]})]})}),o(qe,{className:"p-6 pt-4 border-t border-border flex-shrink-0",children:[o(E,{type:"button",variant:"outline",onClick:()=>U.mutate(),disabled:U.isPending||Fe||J.isPending,className:"gap-1.5 mr-auto",children:[t(ga,{className:`w-4 h-4 ${U.isPending?"animate-spin":""}`}),Hh()]}),t(E,{type:"button",variant:"outline",onClick:r,children:Pe()}),o(E,{type:"submit",disabled:J.isPending||!c,children:[J.isPending&&t(F,{className:"w-4 h-4 mr-2 animate-spin"}),zs()]})]})]})]}):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(bn,{className:"w-5 h-5 text-primary"}),bf()]}),t(Ct,{children:bd()})]}),o("form",{onSubmit:ee,className:"space-y-4",children:[o("div",{className:"space-y-2",children:[t(K,{className:"text-xs font-semibold",children:Gh()}),t(H,{value:c,onChange:(me)=>g(me.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"}),$h()]})]}),o(qe,{children:[t(E,{type:"button",variant:"outline",onClick:r,children:Pe()}),o(E,{type:"submit",disabled:J.isPending||!c,children:[J.isPending&&t(F,{className:"w-4 h-4 mr-2 animate-spin"}),Oc()]})]})]})]})})};var qs=({teamId:e})=>{let r=Q(),{canAdmin:a}=Dt(),[l,s]=u(!1),[d,c]=u(null),[g,_]=u(null),[p,y]=u(null),{data:x,isLoading:m}=Z({queryKey:["teams",e,"mcp","servers"],queryFn:async()=>{let z=await A.api.teams[":teamId"].mcp.servers.$get({param:{teamId:e}});if(!z.ok)throw Error(Yo());return await z.json()}}),i=B({mutationFn:async(z)=>{if(!(await A.api.mcp.servers[":id"].$delete({param:{id:z}})).ok)throw Error(Ra())},onSuccess:()=>{k.success(at()),r.invalidateQueries({queryKey:["teams",e,"mcp","servers"]}),_(null)},onError:(z)=>{k.error(z.message)}}),v=B({mutationFn:async({id:z,permission:de})=>{if(!(await A.api.mcp.servers[":id"].permission.$patch({param:{id:z},json:{permission:de}})).ok)throw Error(_l())},onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"mcp","servers"]})},onError:(z)=>{k.error(z.message)}}),w=B({mutationFn:async(z)=>{if(!(await A.api.mcp.servers[":id"].auth.$delete({param:{id:z}})).ok)throw Error("Failed to disconnect auth")},onSuccess:()=>{k.success(qh()),r.invalidateQueries({queryKey:["teams",e,"mcp","servers"]})},onError:(z)=>{k.error(z.message)}}),M=async(z)=>{y(z);try{let de=await A.api.mcp.servers[":id"].auth.start.$post({param:{id:z}});if(!de.ok){let T=await de.json().catch(()=>({}));throw Error(T.error||Yf())}let ie=await de.json();if(ie.status==="authenticated"){k.success(zh()),r.invalidateQueries({queryKey:["teams",e,"mcp","servers"]}),y(null);return}if(ie.authorizationUrl){let j=window.screenX+(window.outerWidth-600)/2,G=window.screenY+(window.outerHeight-700)/2,N=window.open(ie.authorizationUrl,"mcp_oauth_popup",`width=600,height=700,left=${j},top=${G},scrollbars=yes`),X=(ye)=>{if(ye.data?.type==="mcp-oauth-callback")if(window.removeEventListener("message",X),y(null),ye.data.ok)k.success(zh()),r.invalidateQueries({queryKey:["teams",e,"mcp","servers"]});else k.error(ye.data.message||Yf())};window.addEventListener("message",X);let xe=setInterval(()=>{if(!N||N.closed)clearInterval(xe),window.removeEventListener("message",X),y(null),r.invalidateQueries({queryKey:["teams",e,"mcp","servers"]})},1000)}}catch(de){k.error(de instanceof Error?de.message:Yf()),y(null)}},O=x?.servers||[],Y=(z)=>{switch(z.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(vr,{className:"w-3 h-3"}),Hw()]});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(Zt,{className:"w-3 h-3"}),Vh()]});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(vn,{className:"w-3 h-3"}),$w()]});default:return o(be,{variant:"outline",className:"gap-1 text-[10px]",children:[t(Xt,{className:"w-3 h-3 text-muted-foreground"}),Gw()]})}};return o(_t,{children:[o(kt,{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(bn,{className:"w-6 h-6"})}),o("div",{children:[t(Rt,{className:"text-xl font-bold",children:zc()}),t(Ut,{children:bd()})]})]}),a&&o(E,{onClick:()=>s(!0),className:"gap-2",children:[t(pe,{className:"w-4 h-4"})," ",bf()]})]}),t(It,{children:m?t("div",{className:"flex justify-center py-10",children:t(F,{className:"w-8 h-8 animate-spin text-primary"})}):O.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(bn,{className:"w-6 h-6"})}),t("h3",{className:"text-base font-semibold",children:lg()}),t("p",{className:"text-xs text-muted-foreground mt-1 max-w-sm mx-auto",children:zA()}),a&&o(E,{onClick:()=>s(!0),className:"mt-4 gap-2",variant:"outline",children:[t(pe,{className:"w-4 h-4"})," ",bf()]})]}):t("div",{className:"space-y-4",children:O.map((z)=>{let de=p===z.id,ie=z.status==="needs_auth"||!z.hasCredential&&z.authType!=="none";return o("div",{onClick:()=>a&&c(z),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(bn,{className:"w-4 h-4 text-muted-foreground shrink-0"}),t("span",{className:"truncate",children:z.name}),t(be,{variant:"outline",className:"text-[10px] uppercase shrink-0",children:z.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(wr,{className:"w-4 h-4"})})}),o(Ae,{align:"end",children:[z.status!=="connected"&&(z.authType!=="none"||z.hasCredential)?o(W,{onClick:(T)=>{T.stopPropagation(),M(z.id)},children:[t(Zt,{className:"w-4 h-4 mr-2"}),jh()]}):null,z.hasCredential&&o(W,{onClick:(T)=>{T.stopPropagation(),w.mutate(z.id)},className:"text-amber-600",children:[t(is,{className:"w-4 h-4 mr-2"}),qh()]}),(z.status!=="connected"&&(z.authType!=="none"||z.hasCredential)||z.hasCredential)&&t(Vt,{}),o(W,{onClick:(T)=>{T.stopPropagation(),_(z)},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:z.description||sg()}),t("p",{className:"font-mono text-[10px] text-muted-foreground/70 truncate",children:z.url}),z.lastError&&t("p",{className:"text-[10px] text-red-500/90 truncate font-mono",children:z.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:[Y(z),o(be,{variant:"outline",className:"text-[10px] gap-1 shrink-0",children:[t(Io,{className:"w-3 h-3 text-muted-foreground"}),Yw({count:z.toolCount})]}),o("span",{className:"text-[10px] text-muted-foreground uppercase tracking-wider font-semibold whitespace-nowrap",children:[AA()," ",new Date(z.updatedAt).toLocaleDateString()]})]}),o("div",{className:"flex items-center gap-2 shrink-0",onClick:(T)=>T.stopPropagation(),children:[a?o(Le,{value:z.permission,onValueChange:(T)=>v.mutate({id:z.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:Da()}),t(ne,{value:"editor",children:Oa()}),t(ne,{value:"owner",children:Fa()})]})]}):t(be,{variant:"outline",className:"text-[10px]",children:z.permission==="reviewer"?Da():z.permission==="editor"?Oa():Fa()}),ie&&a&&o(E,{size:"sm",variant:"default",onClick:(T)=>{T.stopPropagation(),M(z.id)},disabled:de,className:"gap-1.5 bg-amber-600 hover:bg-amber-700 text-white text-xs",children:[de?t(F,{className:"w-3.5 h-3.5 animate-spin"}):t(Zt,{className:"w-3.5 h-3.5"}),jh()]})]})]})]},z.id)})})}),t(Ps,{isOpen:l||!!d,onClose:()=>{s(!1),c(null)},teamId:e,server:d}),t(Je,{open:!!g,onOpenChange:(z)=>!z&&_(null),children:o(Xe,{children:[o(et,{children:[t(rt,{children:Uy()}),t(nt,{children:zy({name:g?.name||""})})]}),o(tt,{children:[t(st,{children:Pe()}),o(ot,{onClick:()=>g&&i.mutate(g.id),className:"bg-red-600 hover:bg-red-700 text-white",children:[i.isPending&&t(F,{className:"w-4 h-4 mr-2 animate-spin"}),at()]})]})]})})]})};function Rs({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(Yo());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(Ih());return await _.json()},onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"notification-settings"]}),r.invalidateQueries({queryKey:["teams",e,"notifications"]}),k.success(sS())},onError:(g)=>{k.error(g instanceof Error?g.message:Ih())}}),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(F,{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(_t,{className:"overflow-hidden gap-0 py-0",children:[o(kt,{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(Rt,{className:"text-lg",children:j0()})]}),t(Ut,{children:q0()})]}),o(It,{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:Tv()}),t("p",{className:"text-sm text-muted-foreground",children:aT()})]})]}),t(De,{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(ss,{className:"w-4 h-4"})}),o("div",{className:"space-y-0.5",children:[t("h4",{className:"text-sm font-semibold text-foreground",children:z0()}),t("p",{className:"text-sm text-muted-foreground",children:cT()})]})]}),t(De,{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(es,{className:"w-4 h-4"})}),o("div",{className:"space-y-0.5",children:[t("h4",{className:"text-sm font-semibold text-foreground",children:i0()}),t("p",{className:"text-sm text-muted-foreground",children:lT()})]})]}),t(De,{checked:a?.mentions??!0,onCheckedChange:()=>c("mentions"),disabled:d})]})]})]}),o(_t,{className:"overflow-hidden gap-0 py-0",children:[o(kt,{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(Rt,{className:"text-lg",children:o0()})]}),t(Ut,{children:s0()})]}),o(It,{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(pa,{className:"w-4 h-4"})}),o("div",{className:"space-y-0.5",children:[t("h4",{className:"text-sm font-semibold text-foreground",children:dT()}),t("p",{className:"text-sm text-muted-foreground",children:uT()})]})]}),t(De,{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:TS()}),t("p",{className:"text-sm text-muted-foreground",children:sT()})]})]}),t(De,{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($s,{className:"w-4 h-4"})}),o("div",{className:"space-y-0.5",children:[t("h4",{className:"text-sm font-semibold text-foreground",children:O1()}),t("p",{className:"text-sm text-muted-foreground",children:iT()})]})]}),t(De,{checked:a?.statusUpdates??!0,onCheckedChange:()=>c("statusUpdates"),disabled:d})]})]})]}),o(_t,{className:"overflow-hidden gap-0 py-0",children:[o(kt,{className:"border-b border-border bg-muted/30 py-5",children:[o("div",{className:"flex items-center gap-2",children:[t(Ia,{className:"w-5 h-5 text-primary"}),t(Rt,{className:"text-lg",children:lw()})]}),t(Ut,{children:aw()})]}),o(It,{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(Ia,{className:"w-4 h-4"})}),o("div",{className:"space-y-0.5",children:[t("h4",{className:"text-sm font-semibold text-foreground",children:cw()}),t("p",{className:"text-sm text-muted-foreground",children:oT()})]})]}),t(De,{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:iw()}),t("p",{className:"text-sm text-muted-foreground",children:nT()})]})]}),t(De,{checked:a?.kanbanComments??!0,onCheckedChange:()=>c("kanbanComments"),disabled:d})]})]})]})]})})}S();function js({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(""),k.success(K_())},onError:(i)=>{k.error(i instanceof Error?i.message:Gb())}}),{mutate:y}=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"]}),k.success(W_())},onError:(i)=>{k.error(i instanceof Error?i.message:Yb())}}),x=(i)=>{if(i.preventDefault(),!a.trim())return;_(a.trim())},m=async(i,v)=>{await co(v),d(i),k.success(ey()),setTimeout(()=>d(null),2000)};if(g)return t("div",{className:"flex justify-center items-center p-8",children:t(F,{className:"w-8 h-8 animate-spin text-muted-foreground"})});return t("div",{className:"space-y-6",children:o(_t,{children:[o(kt,{children:[t(Rt,{children:Qm()}),t(Ut,{children:Y_()})]}),o(It,{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:TI()}),t(H,{id:"tokenName",value:a,onChange:(i)=>l(i.target.value),placeholder:MI(),required:!0})]}),o(E,{type:"submit",disabled:p||!a.trim(),children:[p?t(F,{className:"w-4 h-4 animate-spin mr-2"}):t(pe,{className:"w-4 h-4 mr-2"}),kv()]})]}),t("div",{className:"border rounded-lg overflow-hidden",children:o(Rn,{children:[t(Nn,{children:o(br,{children:[t(St,{children:bl()}),t(St,{children:II()}),t(St,{children:yy()}),t(St,{className:"w-[100px] text-right",children:PA()})]})}),t(Pn,{children:!c||c.length===0?t(br,{children:t(yt,{colSpan:4,className:"text-center py-6 text-muted-foreground text-sm",children:Dx()})}):c.map((i)=>o(br,{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(Re,{className:"h-3.5 w-3.5 text-green-500"}):t(Rr,{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:()=>y(i.id),children:t(we,{className:"h-4 w-4"})})})]},i.id))})]})})]})]})})}S();S();var zr=[{value:"read_asset",label:()=>Zm()},{value:"list_assets",label:()=>Fm()},{value:"create_folder",label:()=>Rm()},{value:"create_file",label:()=>km()},{value:"create_version",label:()=>Nm()},{value:"generate_image",label:()=>Dm()},{value:"generate_video",label:()=>Om()},{value:"rename_asset",label:()=>Bm()},{value:"move_assets",label:()=>Lm()},{value:"delete_asset",label:()=>Pm()}],Ja={agent_total_tokens:{label:()=>kd(),icon:io,unit:"tokens",defaultLimit:1e5},agent_cost:{label:()=>Id(),icon:da,unit:"$",defaultLimit:10},agent_mcp_call_count:{label:()=>Td(),icon:bn,unit:"calls",defaultLimit:100},agent_bash_call_count:{label:()=>Cd(),icon:To,unit:"calls",defaultLimit:50},agent_tool_call_count:{label:()=>Md(),icon:Io,unit:"calls",defaultLimit:100}},Os=({open:e,onOpenChange:r,teamId:a,rule:l,onSuccess:s})=>{let d=Q(),c=!!l,[g,_]=u("each_member"),[p,y]=u("team"),[x,m]=u([]),[i,v]=u("agent_total_tokens"),[w,M]=u(""),[O,Y]=u("*"),[z,de]=u("read_asset"),[ie,T]=u(1e5),[q,j]=u("1day"),[G,N]=u(!0),[X,xe]=u(!1),[ye,ke]=u(""),{data:Se=[]}=Z({queryKey:["teams",a,"members"],queryFn:async()=>{let oe=await A.api.teams[":teamId"].members.$get({param:{teamId:a},query:{}});if(!oe.ok)return[];return await oe.json()},enabled:e}),{data:se}=Z({queryKey:["teams",a,"mcp","servers"],queryFn:async()=>{let oe=await A.api.teams[":teamId"].mcp.servers.$get({param:{teamId:a}});if(!oe.ok)return{servers:[]};return await oe.json()},enabled:e&&i==="agent_mcp_call_count"}),_e=se?.servers||[];h(()=>{if(l){_(l.scopeMode),y(l.role||"team"),m(l.userIds||[]),v(l.resource);let oe=l.resourceData||{};M(typeof oe.id==="string"?oe.id:""),Y(typeof oe.match==="string"?oe.match:"*"),de(typeof oe.name==="string"?oe.name:typeof oe.toolName==="string"?oe.toolName:"read_asset"),T(l.limit),j(tu(l.period)),N(l.enabled)}else _("each_member"),y("team"),m([]),v("agent_total_tokens"),M(""),Y("*"),de("read_asset"),T(Ja.agent_total_tokens.defaultLimit),j("1day"),N(!0)},[l,e]);let Fe=(oe)=>{if(v(oe),!c)T(Ja[oe]?.defaultLimit||100)},Ee=B({mutationFn:async()=>{let oe={};if(i==="agent_mcp_call_count")oe.id=w;else if(i==="agent_bash_call_count")oe.match=O.trim()||"*";else if(i==="agent_tool_call_count")oe.name=z||"read_asset";let We=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(oe).length>0?oe:null,limit:Number(ie),period:q,enabled:G}});if(!We.ok){let me=await We.json().catch(()=>({}));throw Error(me?.message||wh())}return await We.json()},onSuccess:()=>{d.invalidateQueries({queryKey:["teams",a,"quotas"]}),k.success(wE()),r(!1),s?.()},onError:(oe)=>{console.error("CREATE MUTATION ERROR:",oe),k.error(oe instanceof Error?oe.message:wh())}}),U=B({mutationFn:async()=>{if(!l)return;let oe={};if(i==="agent_mcp_call_count")oe.id=w;else if(i==="agent_bash_call_count")oe.match=O.trim()||"*";else if(i==="agent_tool_call_count")oe.name=z||"read_asset";let We=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(oe).length>0?oe:null,limit:Number(ie),period:q,enabled:G}});if(!We.ok){let me=await We.json().catch(()=>({}));throw Error(me?.message||gd())}return await We.json()},onSuccess:()=>{d.invalidateQueries({queryKey:["teams",a,"quotas"]}),k.success(VE()),r(!1),s?.()},onError:(oe)=>{k.error(oe instanceof Error?oe.message:gd())}}),J=B({mutationFn:async()=>{if(!l)return;if(!(await A.api.teams[":teamId"].quotas[":id"].$delete({param:{teamId:a,id:l.id}})).ok)throw Error(hd())},onSuccess:()=>{d.invalidateQueries({queryKey:["teams",a,"quotas"]}),k.success(Rg()),xe(!1),r(!1),s?.()},onError:(oe)=>{k.error(oe instanceof Error?oe.message:hd())}}),ee=(oe)=>{if(oe.preventDefault(),g==="selected_members"&&x.length===0){k.error(qC());return}if(i==="agent_mcp_call_count"&&!w.trim()){k.error(yh());return}if(ie<=0){k.error("Limit must be greater than 0");return}if(c)U.mutate();else Ee.mutate()},re=Ee.isPending||U.isPending||J.isPending,Ge=Se.filter((oe)=>{if(!ye.trim())return!0;let We=ye.toLowerCase();return oe.name.toLowerCase().includes(We)||oe.email&&oe.email.toLowerCase().includes(We)}),Tt=(oe)=>{m((We)=>We.includes(oe)?We.filter((me)=>me!==oe):[...We,oe])};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?lb():hy()}),t(Ct,{className:"text-sm text-muted-foreground",children:c?cb():gy()})]}),o("form",{onSubmit:ee,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(K,{className:"text-sm font-semibold",children:FE()}),o("div",{className:"grid grid-cols-3 gap-2",children:[o(E,{type:"button",variant:g==="each_member"?"default":"outline",size:"sm",disabled:c||re,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:Nd()})]}),o(E,{type:"button",variant:g==="all_members"?"default":"outline",size:"sm",disabled:c||re,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:Rd()})]}),o(E,{type:"button",variant:g==="selected_members"?"default":"outline",size:"sm",disabled:c||re,onClick:()=>_("selected_members"),className:"flex flex-col h-auto py-2.5 px-2 gap-1 items-center justify-center text-xs",children:[t(fa,{className:"w-4 h-4"}),t("span",{className:"font-semibold",children:Pd()})]})]}),o("p",{className:"text-xs text-muted-foreground pt-0.5",children:[g==="each_member"&&ZE(),g==="all_members"&&LE(),g==="selected_members"&&BE()]})]}),g!=="selected_members"?o("div",{className:"space-y-2",children:[t(K,{htmlFor:"quota-role-scope",className:"text-sm font-semibold",children:OE()}),o(Le,{value:p,onValueChange:y,disabled:c||re,children:[t(Be,{id:"quota-role-scope",className:"w-full",children:t(Ze,{})}),o(Ue,{children:[t(ne,{value:"team",children:El()}),o(ne,{value:"owner",children:[bp(),": Owner"]}),o(ne,{value:"editor",children:[bp(),": Editor"]}),o(ne,{value:"reviewer",children:[bp(),": Reviewer"]})]})]})]}):o("div",{className:"space-y-2",children:[t(K,{className:"text-sm font-semibold",children:Kg()}),o(mt,{children:[t(ht,{asChild:!0,children:o(E,{variant:"outline",role:"combobox",disabled:re,className:"w-full justify-between text-left font-normal h-10",children:[t("span",{className:"truncate",children:x.length===0?Kg():UE({count:x.length})}),t(ve,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),t(gt,{className:"w-[320px] p-2",align:"start",children:o("div",{className:"space-y-2",children:[o("div",{className:"relative",children:[t(Bt,{className:"w-3.5 h-3.5 absolute left-2.5 top-1/2 -translate-y-1/2 text-muted-foreground"}),t(H,{placeholder:vp(),value:ye,onChange:(oe)=>ke(oe.target.value),className:"h-8 pl-8 text-xs"})]}),t(ce,{className:"h-48",children:t("div",{className:"space-y-1 pr-2",children:Ge.map((oe)=>{let We=x.includes(oe.id);return o("div",{onClick:()=>Tt(oe.id),className:"flex items-center gap-2 p-1.5 rounded-lg hover:bg-muted/60 cursor-pointer text-xs",children:[t(Dr,{checked:We,onCheckedChange:()=>Tt(oe.id)}),o(Ce,{className:"w-5 h-5",children:[t(Ie,{src:oe.image||void 0}),t(Te,{className:"text-[10px]",children:oe.name?.[0]?.toUpperCase()||"U"})]}),o("div",{className:"truncate flex-1",children:[t("span",{className:"font-medium text-foreground block truncate",children:oe.name}),oe.email&&t("span",{className:"text-[10px] text-muted-foreground block truncate",children:oe.email})]})]},oe.id)})})})]})})]})]}),o("div",{className:"space-y-2",children:[t(K,{htmlFor:"quota-resource",className:"text-sm font-semibold",children:PE()}),o(Le,{value:i,onValueChange:(oe)=>Fe(oe),disabled:c||re,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:kd()})]})}),t(ne,{value:"agent_cost",children:o("div",{className:"flex items-center gap-2",children:[t(da,{className:"w-4 h-4 text-emerald-500"}),t("span",{children:Id()})]})}),t(ne,{value:"agent_mcp_call_count",children:o("div",{className:"flex items-center gap-2",children:[t(bn,{className:"w-4 h-4 text-blue-500"}),t("span",{children:Td()})]})}),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:Cd()})]})}),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:Md()})]})})]})]})]}),i==="agent_mcp_call_count"&&o("div",{className:"space-y-2",children:[t(K,{htmlFor:"quota-mcp",className:"text-sm font-semibold",children:Qg()}),_e.length>0?o(Le,{value:w,onValueChange:M,disabled:c||re,children:[t(Be,{id:"quota-mcp",className:"w-full",children:t(Ze,{placeholder:Qg()})}),t(Ue,{children:_e.map((oe)=>o(ne,{value:oe.id,children:[oe.name," (",oe.id,")"]},oe.id))})]}):t(H,{id:"quota-mcp",value:w,onChange:(oe)=>M(oe.target.value),placeholder:yh(),disabled:c||re})]}),i==="agent_bash_call_count"&&o("div",{className:"space-y-1.5",children:[t(K,{htmlFor:"quota-bash",className:"text-sm font-semibold",children:x0()}),t(H,{id:"quota-bash",value:O,onChange:(oe)=>Y(oe.target.value),placeholder:S0(),disabled:re}),t("p",{className:"text-xs text-muted-foreground",children:bE()})]}),i==="agent_tool_call_count"&&o("div",{className:"space-y-2",children:[t(K,{htmlFor:"quota-tool",className:"text-sm font-semibold",children:Yg()}),o(Le,{value:z,onValueChange:de,disabled:c||re,children:[t(Be,{id:"quota-tool",className:"w-full",children:t(Ze,{placeholder:Yg()})}),t(Ue,{children:zr.map((oe)=>t(ne,{value:oe.value,children:oe.label()},oe.value))})]}),t("p",{className:"text-xs text-muted-foreground",children:GE()})]}),o("div",{className:"grid grid-cols-2 gap-4",children:[o("div",{className:"space-y-2",children:[o(K,{htmlFor:"quota-limit",className:"text-sm font-semibold",children:[CE()," (",Ja[i]?.unit||"",")"]}),t(H,{id:"quota-limit",type:"number",min:"0.01",step:i==="agent_cost"?"0.01":"1",value:ie,onChange:(oe)=>T(Number(oe.target.value)),placeholder:IE(),disabled:re,required:!0})]}),o("div",{className:"space-y-2",children:[t(K,{htmlFor:"quota-period",className:"text-sm font-semibold",children:ME()}),o(Le,{value:q,onValueChange:(oe)=>j(oe),disabled:re,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(Xt,{className:"w-3.5 h-3.5 text-muted-foreground"}),t("span",{children:Ap()})]})}),t(ne,{value:"5hour",children:o("div",{className:"flex items-center gap-2",children:[t(Xt,{className:"w-3.5 h-3.5 text-muted-foreground"}),t("span",{children:_p()})]})}),t(ne,{value:"1day",children:o("div",{className:"flex items-center gap-2",children:[t(Xt,{className:"w-3.5 h-3.5 text-muted-foreground"}),t("span",{children:gp()})]})}),t(ne,{value:"7day",children:o("div",{className:"flex items-center gap-2",children:[t(Xt,{className:"w-3.5 h-3.5 text-muted-foreground"}),t("span",{children:yp()})]})})]})]})]})]}),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(K,{htmlFor:"quota-enabled",className:"text-sm font-medium cursor-pointer",children:G?SE():hp()}),t("p",{className:"text-xs text-muted-foreground",children:G?"Active and enforcing limits":"Inactive, requests will bypass this quota"})]}),t(De,{id:"quota-enabled",checked:G,onCheckedChange:N,disabled:re})]}),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:()=>xe(!0),disabled:re,className:"gap-1.5",children:[t(we,{className:"w-4 h-4"}),t("span",{children:Nf()})]}):t("div",{}),o("div",{className:"flex items-center gap-2",children:[t(E,{type:"button",variant:"outline",onClick:()=>r(!1),disabled:re,children:Pe()}),o(E,{type:"submit",disabled:re,className:"gap-2",children:[re&&t(F,{className:"w-4 h-4 animate-spin"}),c?xo():Oc()]})]})]})]})]})}),t(Je,{open:X,onOpenChange:xe,children:o(Xe,{children:[o(et,{children:[t(rt,{children:Nf()}),t(nt,{children:fh()})]}),o(tt,{children:[t(st,{disabled:re,children:Pe()}),o(ot,{onClick:(oe)=>{oe.preventDefault(),J.mutate()},disabled:re,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:[re&&t(F,{className:"w-4 h-4 animate-spin mr-2"}),at()]})]})]})})]})};var Qs=({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(Yo());return await i.json()}}),y=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(gd());return await w.json()},onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"quotas"]}),k.success(zE())},onError:(i)=>{k.error(i instanceof Error?i.message:gd())}}),x=B({mutationFn:async(i)=>{if(!(await A.api.teams[":teamId"].quotas[":id"].$delete({param:{teamId:e,id:i}})).ok)throw Error(hd())},onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"quotas"]}),k.success(Rg()),g(null)},onError:(i)=>{k.error(i instanceof Error?i.message:hd())}}),m=_?.rules||[];return o(ce,{className:"h-full",children:[t("div",{className:"space-y-6 pr-4 pb-10",children:o(_t,{children:[o(kt,{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(Rt,{className:"text-xl font-bold",children:Bg()}),t(Ut,{children:Ug()})]})]}),o(E,{onClick:()=>l(!0),className:"gap-2",children:[t(pe,{className:"w-4 h-4"})," ",Im()]})]}),t(It,{children:p?t("div",{className:"flex justify-center py-12",children:t(F,{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:ip()}),t("p",{className:"text-sm text-muted-foreground max-w-md mx-auto mb-6",children:sp()}),o(E,{onClick:()=>l(!0),className:"gap-2",children:[t(pe,{className:"w-4 h-4"})," ",Im()]})]}):t("div",{className:"flex flex-col gap-4",children:m.map((i)=>{let v=Ga[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:(M)=>M.stopPropagation(),children:[t(De,{checked:i.enabled,onCheckedChange:(M)=>y.mutate({id:i.id,enabled:M}),disabled:y.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(wr,{className:"w-4 h-4"})})}),t(Ae,{align:"end",children:o(W,{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:[Rd(),i.role?` (${i.role})`:` (${El()})`]})]}),i.scopeMode==="each_member"&&o(be,{variant:"secondary",className:"gap-1 text-xs",children:[t(Vn,{className:"w-3 h-3"}),o("span",{children:[Nd(),i.role?` (${i.role})`:` (${El()})`]})]}),i.scopeMode==="selected_members"&&o(be,{variant:"secondary",className:"gap-1 text-xs",children:[t(fa,{className:"w-3 h-3"}),o("span",{children:[Pd()," (",i.userIds?.length||0,")"]})]}),o(be,{variant:"outline",className:"gap-1 text-xs",children:[t(Xt,{className:"w-3 h-3"}),o("span",{children:[Ni(i.resource,i.limit)," ",v?.unit," /"," ",Ql(i.period)]})]})]})})]})},i.id)})})})]})}),(a||!!s)&&t(Os,{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:Nf()}),t(nt,{children:fh()})]}),o(tt,{children:[t(st,{disabled:x.isPending,children:Pe()}),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(F,{className:"w-4 h-4 animate-spin mr-2"}),at()]})]})]})})]})};function Ks({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(Yo());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(Mh());return await p.json()},onSuccess:async(_,p)=>{if(r.invalidateQueries({queryKey:["teams",e,"settings"]}),await gr.getState().fetchMetadata(e),p)lr.getState().setIsChatbotOpen(!1);k.success(J_())},onError:(_)=>{k.error(_ instanceof Error?_.message:Mh())}}),c=Boolean(a?.appearance?.hideAgent),g=(_)=>{s(_)};if(l)return t("div",{className:"flex items-center justify-center p-8",children:t(F,{className:"h-6 w-6 animate-spin text-muted-foreground"})});return t("div",{className:"h-full overflow-y-auto pr-1",children:o(_t,{children:[o(kt,{children:[t(Rt,{children:Km()}),t(Ut,{children:Wm()})]}),t(It,{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:Qv()}),t("p",{className:"text-xs text-muted-foreground",children:Kv()})]}),t(De,{id:"hide-agent-switch",checked:c,onCheckedChange:g,disabled:d})]})})]})})}S();S();function Us({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 y=await A.api.teams[":teamId"].notifications.email.test.$post({param:{teamId:a},json:{from:p}});if(!y.ok){let x=await y.json().catch(()=>null);throw Error(x?.message||Ch())}return await y.json()}}),_=async()=>{if(!s.trim()){k.error(Cv());return}try{await c(s.trim()),k.success(pI()),r()}catch(p){k.error(p instanceof Error?p.message:Ch())}};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(os,{className:"w-5 h-5 text-primary"}),t(le,{children:Jg()})]}),t(Ct,{children:WC()})]}),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:Xg()}),t(H,{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:Pe()}),o(E,{onClick:_,disabled:g,children:[g&&t(F,{className:"w-4 h-4 animate-spin mr-2"}),Jg()]})]})]})})}function Gs({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(xh());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:y}=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),k.success(_h())}catch(i){k.error(i instanceof Error?i.message:Zf())}},m=async()=>{if(!a.host.trim()){k.error(A1());return}try{await p(a),k.success(_h()),d(!0)}catch(i){k.error(i instanceof Error?i.message:Zf())}};if(g)return t("div",{className:"flex items-center justify-center p-8",children:t(F,{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:xh()});return o(L,{children:[t(ce,{className:"h-full",children:t("div",{className:"space-y-6 pr-4 pb-8",children:o(_t,{children:[o(It,{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:Ab()}),t("p",{className:"text-xs text-muted-foreground",children:_b()})]}),t(De,{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:C1()}),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:h1()}),t(H,{id:"smtp-host-input",value:a.host,onChange:(i)=>l({...a,host:i.target.value}),placeholder:g1(),disabled:!a.enabled})]}),o("div",{className:"space-y-2",children:[t("label",{htmlFor:"smtp-port-input",className:"text-sm font-medium text-foreground",children:x1()}),t(H,{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:I1()}),t(H,{id:"smtp-username-input",value:a.username||"",onChange:(i)=>l({...a,username:i.target.value}),placeholder:T1(),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:b1()}),t(H,{id:"smtp-password-input",type:"password",value:a.password||"",onChange:(i)=>l({...a,password:i.target.value}),placeholder:c?.password?v1():w1(),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:S1()}),t("p",{className:"text-xs text-muted-foreground",children:E1()})]}),t(De,{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:_1()}),t("p",{className:"text-xs text-muted-foreground",children:y1()})]}),t(De,{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:e1()}),o("div",{className:"space-y-2",children:[t("label",{htmlFor:"sender-from-input",className:"text-sm font-medium text-foreground",children:Xg()}),t(H,{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:YC()})]}),o("div",{className:"space-y-2",children:[t("label",{htmlFor:"sender-reply-to-input",className:"text-sm font-medium text-foreground",children:JC()}),t(H,{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:XC()})]})]})]}),o(ef,{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:y,children:[y&&t(F,{className:"w-4 h-4 animate-spin mr-2"}),xo()]}),o(E,{onClick:m,disabled:y||!a.enabled,children:[y&&t(F,{className:"w-4 h-4 animate-spin mr-2"}),gC()]})]})]})})}),t(Us,{isOpen:s,onClose:()=>d(!1),teamId:e,defaultFrom:a.from})]})}S();var Hs={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 Ws({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||[],_=P(()=>{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(F,{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(_t,{className:"border-border min-w-0 w-full",children:[o(kt,{children:[t(Rt,{className:"text-base font-semibold",children:tx()}),t(Ut,{children:rx()})]}),t(It,{className:"min-w-0",children:t("div",{className:"space-y-2.5 min-w-0",children:c.map((p)=>{let y=Hs[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:y}),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(vr,{className:"w-3 h-3"}),Eg()]}),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(vr,{className:"w-3 h-3"}),Cg()]}),!x&&!m&&t(be,{variant:"outline",className:"bg-muted text-muted-foreground border-border text-[10px] shrink-0 font-normal",children:Ig()}),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"}),Yv({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(ha,{className:"w-3 h-3"}),KI({count:v})]})]})]}),t(vt,{className:"w-4 h-4 text-muted-foreground group-hover:text-foreground transition-colors shrink-0"})]},p.provider)})})})]})})}),_&&t(Kr,{isOpen:!!_,onClose:()=>l(null),provider:_,teamId:e,enabledModels:g,onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"media-generation"]})}})]})}function Kr({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||""),[y,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"),[M,O]=u(""),[Y,z]=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"),O(""),z(a.supportedTypes[0]||"image")},[a.provider,a.customApiKeyOrEnv,a.apiKeyConfigured,s]);let{data:de=[],isLoading:ie}=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:q}=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:y.map((_e)=>({type:_e.type,modelId:_e.modelId,name:_e.name||_e.modelId}))}});if(!se.ok){let _e=await se.json().catch(()=>({}));throw Error(_e?.message||"Failed to update provider")}return await se.json()},onSuccess:()=>{k.success(Tg()),d(),r()},onError:(se)=>{k.error(se instanceof Error?se.message:Xb())}}),j=P(()=>new Set(de.map((se)=>se.modelId)),[de]),G=P(()=>y.filter((se)=>!j.has(se.modelId)),[y,j]),N=P(()=>{let se=[];for(let _e of de){let Fe=y.some((Ee)=>Ee.modelId===_e.modelId&&Ee.type===_e.type);se.push({type:_e.type,modelId:_e.modelId,name:_e.name,isCustom:!1,isToggledOn:Fe})}for(let _e of G)se.push({type:_e.type,modelId:_e.modelId,name:_e.name||_e.modelId,isCustom:!0,isToggledOn:!0});return se},[de,y,G]),X=P(()=>N.filter((se)=>{if(v!=="all"&&se.type!==v)return!1;if(m.trim()){let _e=m.toLowerCase(),Fe=se.name.toLowerCase().includes(_e),Ee=se.modelId.toLowerCase().includes(_e);if(!Fe&&!Ee)return!1}return!0}),[N,v,m]),xe=(se,_e)=>{if(_e)x((Fe)=>[...Fe,{type:se.type,modelId:se.modelId,name:se.name,isCustom:se.isCustom}]);else x((Fe)=>Fe.filter((Ee)=>!(Ee.modelId===se.modelId&&Ee.type===se.type)))},ye=(se,_e)=>{x((Fe)=>Fe.filter((Ee)=>!(Ee.modelId===se&&Ee.type===_e)))},ke=()=>{let se=M.trim();if(!se)return;if(y.some((Fe)=>Fe.modelId===se&&Fe.type===Y)){k.error(qb());return}x((Fe)=>[...Fe,{type:Y,modelId:se,name:se,isCustom:!0}]),O("")},Se=Hs[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:Se}),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:Eg()}),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:Cg()})]}),t(Ct,{children:Py({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(Qr,{value:"api-key",onClick:()=>g("api-key"),children:ad()}),o(Qr,{value:"models",onClick:()=>g("models"),children:[vd()," (",y.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:ad()}),_&&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"}),D0()]})]}),t(H,{id:"provider-api-key",type:"text",value:_,onChange:(se)=>p(se.target.value),placeholder:Q_({envKey:a.defaultEnvKey}),className:"font-mono text-sm"}),t("p",{className:"text-xs text-muted-foreground mt-1",children:V_({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(vn,{className:"w-4 h-4 shrink-0 mt-0.5"}),o("div",{children:[t("p",{className:"font-medium",children:Ig()}),t("p",{className:"text-[11px] opacity-90 mt-0.5",children:hE()})]})]})}),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(Bt,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),t(H,{type:"text",placeholder:Tp(),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:U_()}),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"}),Jf()]}),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(ha,{className:"w-3.5 h-3.5"}),Xf()]})]})]}),t("div",{className:"flex-1 min-h-0 px-6",children:t(ce,{className:"h-full pr-4",children:ie?o("div",{className:"flex h-48 items-center justify-center gap-2 text-muted-foreground",children:[t(F,{className:"h-5 w-5 animate-spin"}),t("span",{className:"text-xs",children:Aw()})]}):X.length===0?t("div",{className:"text-center py-12 border border-dashed rounded-xl text-muted-foreground text-sm",children:xd()}):t("div",{className:"space-y-2 pb-4",children:X.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(ha,{className:"w-3 h-3"}),se.type==="image"?Jf():Xf()]}),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:Sy().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:()=>ye(se.modelId,se.type),title:at(),children:t(we,{className:"w-3.5 h-3.5"})}),t(De,{checked:se.isToggledOn,onCheckedChange:(_e)=>xe(se,_e),"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:()=>z("image"),className:C("px-2.5 py-1 text-xs transition-colors",Y==="image"?"bg-primary text-primary-foreground font-medium":"bg-muted/40 hover:bg-muted text-muted-foreground"),children:Jf()}),t("button",{type:"button",onClick:()=>z("video"),className:C("px-2.5 py-1 text-xs transition-colors",Y==="video"?"bg-primary text-primary-foreground font-medium":"bg-muted/40 hover:bg-muted text-muted-foreground"),children:Xf()})]}),t(H,{type:"text",value:M,onChange:(se)=>O(se.target.value),placeholder:Sb(),className:"font-mono text-xs h-8 flex-1",onKeyDown:(se)=>{if(se.key==="Enter")se.preventDefault(),ke()}}),o(E,{type:"button",size:"sm",variant:"outline",className:"h-8 text-xs shrink-0 gap-1",onClick:ke,disabled:!M.trim(),children:[t(pe,{className:"w-3.5 h-3.5"}),yf()]})]})})]})]}),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:[y.length," ",vd().toLowerCase()]}),o("div",{className:"flex items-center gap-2",children:[t(E,{type:"button",variant:"outline",size:"sm",onClick:r,disabled:q,children:Pe()}),o(E,{type:"button",size:"sm",onClick:()=>T(),disabled:q,children:[q&&t(F,{className:"w-4 h-4 mr-1.5 animate-spin"}),xo()]})]})]})]})})}S();S();function Zs({isOpen:e,onClose:r,imageSrc:a,onConfirm:l}){let[s,d]=u(1),[c,g]=u({x:0,y:0}),[_,p]=u(!1),[y,x]=u(!1),m=b({x:0,y:0}),i=b(null),v=b(null),w=250;h(()=>{if(e)d(1),g({x:0,y:0}),x(!1)},[e,a]);let M=(T)=>{T.preventDefault(),p(!0),m.current={x:T.clientX-c.x,y:T.clientY-c.y}},O=(T)=>{if(!_)return;g({x:T.clientX-m.current.x,y:T.clientY-m.current.y})},Y=()=>{p(!1)},z=(T)=>{if(T.touches.length!==1)return;p(!0);let q=T.touches[0];m.current={x:q.clientX-c.x,y:q.clientY-c.y}},de=(T)=>{if(!_||T.touches.length!==1)return;let q=T.touches[0];g({x:q.clientX-m.current.x,y:q.clientY-m.current.y})},ie=async()=>{let T=i.current,q=v.current;if(!T||!q)return;x(!0);try{let j=T.getBoundingClientRect(),G=512,N=document.createElement("canvas");N.width=512,N.height=512;let X=N.getContext("2d");if(X){X.clearRect(0,0,512,512);let xe=2.048,ye=j.width/s,ke=j.height/s,Se=256+c.x*xe,se=256+c.y*xe;X.translate(Se,se),X.scale(s*xe,s*xe),X.drawImage(T,-ye/2,-ke/2,ye,ke);let _e=await new Promise((Fe)=>{N.toBlob((Ee)=>Fe(Ee),"image/jpeg",0.9)});if(_e)await l(_e)}}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(rs,{className:"w-5 h-5 text-primary"}),$S()]})}),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:M,onMouseMove:O,onMouseUp:Y,onMouseLeave:Y,onTouchStart:z,onTouchMove:de,onTouchEnd:Y,children:[a&&t("img",{ref:i,src:a,alt:b0(),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(ls,{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(ns,{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:y,children:Pe()}),t(E,{onClick:ie,disabled:y||!a,className:"min-w-[80px]",children:y?o(L,{children:[t(F,{className:"w-4 h-4 animate-spin mr-2"}),qg()]}):xo()})]})]})})}var Ur=["general","transcode","quotas","appearance","email","skills","mcp","providers","image-video","agents","sandbox","notifications","developer"];function Xs(){if(typeof window>"u")return"general";let e=window.location.hash.replace(/^#/,"");return Ur.includes(e)?e:"general"}function Gr(){let{teamId:e}=Hr.useParams(),r=Q(),[a,l]=u(Xs),s=(ee)=>{l(ee);let re=ee==="general"?"":`#${ee}`;if(window.location.hash!==re)window.history.replaceState(null,"",window.location.pathname+window.location.search+re)};h(()=>{let ee=()=>{l(Xs())};return window.addEventListener("hashchange",ee),()=>window.removeEventListener("hashchange",ee)},[]);let[d,c]=u(""),[g,_]=u(!1),[p,y]=u(null),x=b(null),[m,i]=u(!1),{setMetadata:v,getMetadata:w}=gr(),M=w("locale")||n(),O=async(ee)=>{if(ee==="en"||ee==="zh")try{await v(e,"locale",ee),ka(ee),k.success(dw())}catch(re){console.error(re),k.error(rv())}},{data:Y,isLoading:z,error:de}=Z({queryKey:["teams",e,"settings"],queryFn:async()=>{let ee=await A.api.teams[":teamId"].settings.$get({param:{teamId:e}});if(!ee.ok)throw Error("Failed to fetch settings");return await ee.json()}}),{data:ie,isLoading:T}=Z({queryKey:["teams",e,"me"],queryFn:async()=>{let ee=await A.api.teams[":teamId"].me.$get({param:{teamId:e}});if(!ee.ok)throw Error("Failed to fetch me");return await ee.json()},enabled:!!e});h(()=>{if(ie?.name)c(ie.name)},[ie]),h(()=>{let ee=["transcode","quotas","appearance","email","providers","image-video","skills","mcp","agents","sandbox"];if(ie&&ie.role!=="owner"&&ee.includes(a))s("general")},[ie,a]);let q=(ee)=>{if(!ee)return"U";let re=ee.split(" ");if(re.length>1)return`${re[0][0]}${re[re.length-1][0]}`.toUpperCase();return ee.substring(0,2).toUpperCase()},j=(ee)=>{let re=ee.target.files?.[0];if(re){let Ge=new FileReader;Ge.onload=()=>{y(Ge.result),_(!0)},Ge.readAsDataURL(re),ee.target.value=""}},G=async(ee)=>{i(!0);try{let re=new File([ee],"avatar.jpg",{type:"image/jpeg"}),Ge=await A.api.teams[":teamId"].files.$post({param:{teamId:e},form:{file:re}});if(!Ge.ok)throw Error("Failed to upload avatar");let oe=(await Ge.json()).key;if(!(await A.api.teams[":teamId"].me.$patch({param:{teamId:e},json:{imageKey:oe}})).ok)throw Error("Failed to save profile");k.success(v0()),r.invalidateQueries({queryKey:["teams",e,"me"]}),_(!1)}catch(re){console.error(re),k.error(tv())}finally{i(!1)}},N=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");k.success(y0()),r.invalidateQueries({queryKey:["teams",e,"me"]})}catch(ee){console.error(ee),k.error(zb())}finally{i(!1)}},X=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");k.success(yg()),r.invalidateQueries({queryKey:["teams",e,"me"]})}catch(ee){console.error(ee),k.error(nv())}finally{i(!1)}},{mutate:xe}=B({mutationFn:async(ee)=>{let re=await A.api.teams[":teamId"].settings.$patch({param:{teamId:ee.teamId},json:ee.data});if(!re.ok)throw Error("Failed to update settings");return await re.json()},onSuccess:()=>{r.invalidateQueries({queryKey:["teams",e,"settings"]})}}),ye=(ee)=>{xe({teamId:e,data:{key:"transcode.videoStrategy",value:ee}})},ke=(ee)=>{xe({teamId:e,data:{key:"transcode.hardwareAcceleration",value:ee}})},[Se,se]=u(null),_e=Y?.transcode?.threads??0;h(()=>{se(null)},[_e]);let Fe=(ee)=>{xe({teamId:e,data:{key:"transcode.threads",value:ee}})};if(z||T)return t("div",{className:"flex h-screen items-center justify-center",children:t(F,{className:"h-8 w-8 animate-spin text-muted-foreground"})});if(de)return t("div",{className:"p-8 text-center text-red-500",children:Yo()});let Ee=Y?.transcode?.videoStrategy||Ai.best_match;if(Ee==="single"||Ee==="disable")Ee=Ai.best_match;else if(Ee==="full")Ee=Ai.all;let U=Y?.transcode?.hardwareAcceleration||Za.off,J=Se??_e;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:qS()}),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"}),Iv(),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(pa,{className:"w-5 h-5"}),ug(),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(Zt,{className:"w-5 h-5"}),Qm(),a==="developer"&&t("div",{className:"ml-auto w-1.5 h-1.5 rounded-full bg-sidebar-primary"})]}),ie?.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:iI()}),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(ts,{className:"w-5 h-5"}),Qh(),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"}),Dd(),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($l,{className:"w-5 h-5"}),xf(),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(ci,{className:"w-5 h-5"}),Ah(),a==="email"&&t("div",{className:"ml-auto w-1.5 h-1.5 rounded-full bg-sidebar-primary"})]})]}),ie?.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:F_()}),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"}),gE(),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(sn,{className:"w-5 h-5"}),Zh(),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(wt,{className:"w-5 h-5"}),rA(),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(bn,{className:"w-5 h-5"}),zc(),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(Et,{className:"w-5 h-5"}),I_(),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(Gl,{className:"w-5 h-5"}),s_(),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"&&Oh(),a==="transcode"&&Qh(),a==="quotas"&&Bg(),a==="appearance"&&Km(),a==="email"&&Ah(),a==="skills"&&nA(),a==="mcp"&&zc(),a==="providers"&&O_(),a==="image-video"&&Zh(),a==="agents"&&D_(),a==="sandbox"&&i_(),a==="notifications"&&oS(),a==="developer"&&eb()]}),o("p",{className:"text-sm text-muted-foreground mt-1",children:[a==="general"&&Mv(),a==="transcode"&&hA(),a==="quotas"&&Ug(),a==="appearance"&&Wm(),a==="email"&&pb(),a==="skills"&&p1(),a==="mcp"&&bd(),a==="providers"&&AE(),a==="image-video"&&ex(),a==="agents"&&T_(),a==="sandbox"&&mC(),a==="notifications"&&iS(),a==="developer"&&Xy()]})]})}),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(_t,{children:[o(kt,{children:[t(Rt,{children:zS()}),t(Ut,{children:jS()})]}),t(It,{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:_0()}),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:[ie?.image&&t(Ie,{src:ie.image,alt:ie.name,className:"object-cover w-24 h-24"}),t(Te,{className:"text-2xl bg-primary/40 text-foreground",children:q(ie?.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:k0()})})]}),o("div",{className:"flex gap-2",children:[t(E,{variant:"outline",size:"sm",onClick:()=>x.current?.click(),children:zI()}),ie?.image&&t(E,{variant:"ghost",size:"sm",className:"text-red-500 hover:text-red-600",onClick:N,children:Cl()})]}),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:bl()}),t(H,{value:d,onChange:(ee)=>c(ee.target.value),placeholder:Ib(),className:"max-w-md"})]}),o("div",{className:"space-y-2",children:[t("label",{className:"text-sm font-medium text-muted-foreground",children:Of()}),t(H,{value:ie?.email||"",disabled:!0,className:"max-w-md bg-muted/50 cursor-not-allowed"}),t("p",{className:"text-xs text-muted-foreground",children:fb()})]}),o(E,{onClick:X,disabled:m||!d.trim(),className:"mt-2",children:[m&&t(F,{className:"w-4 h-4 animate-spin mr-2"}),zs()]})]})]})})]}),o(_t,{className:"border border-slate-200 dark:border-slate-800 mt-6",children:[o(kt,{children:[t(Rt,{children:uw()}),t(Ut,{children:UC()})]}),t(It,{className:"space-y-4",children:t("div",{className:"max-w-xs",children:o(Le,{value:M,onValueChange:O,children:[t(Be,{children:t(Ze,{placeholder:FC()})}),o(Ue,{children:[t(ne,{value:"en",children:wb()}),t(ne,{value:"zh",children:P0()})]})]})})})]}),t(Zs,{isOpen:g,onClose:()=>_(!1),imageSrc:p,onConfirm:G})]}),a==="transcode"&&t("div",{className:"h-full overflow-y-auto pr-1 pb-8",children:o(_t,{children:[o(kt,{children:[t(Rt,{children:RI()}),o(Ut,{children:[t("span",{className:"block mb-2",children:hA()}),t("span",{className:"block",children:NI()})]})]}),o(It,{className:"space-y-6",children:[o("div",{className:"space-y-3",children:[t("h3",{className:"text-lg font-medium",children:WI()}),o("div",{className:"space-y-3",children:[o("div",{className:C("cursor-pointer rounded-lg border p-4 transition-all hover:border-primary",Ee===Ai.best_match?"border-primary bg-primary/5":"border-border"),onClick:()=>ye(Ai.best_match),children:[t("div",{className:"font-semibold",children:E0()}),t("div",{className:"text-sm text-muted-foreground",children:C0()})]}),o("div",{className:C("cursor-pointer rounded-lg border p-4 transition-all hover:border-primary",Ee===Ai.all?"border-primary bg-primary/5":"border-border"),onClick:()=>ye(Ai.all),children:[t("div",{className:"font-semibold",children:z_()}),t("div",{className:"text-sm text-muted-foreground",children:j_()})]})]})]}),o("div",{className:"space-y-3 pt-6 border-t border-border",children:[t("h3",{className:"text-lg font-medium",children:qv()}),o("div",{className:"space-y-3",children:[o("div",{className:C("cursor-pointer rounded-lg border p-4 transition-all hover:border-primary",U===Za.off?"border-primary bg-primary/5":"border-border"),onClick:()=>ke(Za.off),children:[t("div",{className:"font-semibold",children:Gv()}),t("div",{className:"text-sm text-muted-foreground",children:Vv()})]}),o("div",{className:C("cursor-pointer rounded-lg border p-4 transition-all hover:border-primary",U===Za.auto?"border-primary bg-primary/5":"border-border"),onClick:()=>ke(Za.auto),children:[t("div",{className:"font-semibold",children:Hv()}),t("div",{className:"text-sm text-muted-foreground",children:$v()})]})]})]}),o("div",{className:"space-y-4 pt-6 border-t border-border",children:[o("div",{className:"flex items-center justify-between",children:[o("div",{children:[t("h3",{className:"text-lg font-medium",children:iv()}),t("p",{className:"text-sm text-muted-foreground",children:av()})]}),t("span",{className:"font-mono text-sm font-semibold px-2.5 py-1 rounded bg-muted text-foreground border border-border",children:J===0?fA():vI({count:J})})]}),o("div",{className:"pt-2 px-1",children:[t(Uo,{value:[J],min:0,max:32,step:1,onValueChange:([ee])=>se(ee),onValueCommit:([ee])=>{se(ee),Fe(ee)}}),o("div",{className:"flex justify-between text-xs text-muted-foreground mt-2",children:[o("span",{children:[fA()," (0)"]}),t("span",{children:"16"}),t("span",{children:"32"})]})]})]})]})]})}),a==="skills"&&t("div",{className:"h-full overflow-y-auto pr-1",children:t(Ls,{teamId:e})}),a==="mcp"&&t("div",{className:"h-full overflow-y-auto pr-1",children:t(qs,{teamId:e})}),a==="providers"&&t(Ts,{teamId:e}),a==="image-video"&&t(Ws,{teamId:e}),a==="agents"&&t("div",{className:"h-full overflow-y-auto pr-1",children:t(As,{teamId:e})}),a==="sandbox"&&t("div",{className:"h-full overflow-y-auto pr-1",children:t(Vs,{teamId:e})}),a==="notifications"&&t(Rs,{teamId:e}),a==="developer"&&t(js,{teamId:e}),a==="quotas"&&t(Qs,{teamId:e}),a==="appearance"&&t(Ks,{teamId:e}),a==="email"&&t(Gs,{teamId:e})]})]})})]})})}var Hr=ze("/teams/$teamId/settings")({component:Gr});export{Hr as Route};
|