import{r as u,j as e,L as $c,e as fa,b as eb,f as tb,g as sb,h as ab,k as fs,l as lb,m as nb,O as pp,n as ib}from"./router-CWhjJi2n.js";import{a as rb,b as cb,g as ob}from"./react-vendor-Dtc2IqVY.js";import{I as db,c as ub,J as si,K as Lc,L as gu,M as mb,N as Ii,O as Pi,P as hb,n as ju}from"./utils-CCeOswSm.js";import{L as gp,T as jp,C as vp,R as xb,a as bp,V as fb,b as pb,S as yp,c as gb,d as Np,I as jb,e as wp,f as vb,g as _p,h as bb,i as yb,j as Nb,O as Sp,P as wb,k as Cp,l as kp,D as Tp,A as Ep,m as zp,n as _b,o as Sb,p as Ap,q as Cb,r as Mp,s as kb,t as Tb,u as Eb,v as zb,w as Ab,x as Dp,y as Op,F as Rp}from"./radix-extra-BM7iD6Dt.js";import{aj as Mb,ak as Db,al as Ob,am as Rb,an as Uc,ao as Bc,ap as Wi,aq as Lb,ar as vu,as as Hc,at as Ub,au as Bb,av as Hb}from"./charts-Dhri-zxi.js";import{S as qb,G as Lp,O as Up,o as Gb,C as Bp,p as Vb,T as Hp,D as qp,R as Fb,q as $b,H as Gp,I as Qb,J as Vp,K as Fp,L as Yb,M as $p,V as Xb,N as Qp,Q as Yp,U as Kb,X as Zb,Y as Xp,Z as Jb,_ as Ib,$ as Kp,a0 as Pb,a1 as Wb,a2 as Zp,a3 as ey,a4 as ty,a5 as sy,a6 as Jp,a7 as Ip,a8 as Pp,a9 as Wp,aa as eg,ab as tg,ac as ay}from"./radix-core-C3XKqQJw.js";import{R as ws,P as gr,C as ha,a as Oa,Z as ln,b as Kc,F as Da,c as ly,S as ai,A as ny,D as iy,d as Zc,e as Wn,M as cn,T as ry,X as on,f as cy,g as oy,I as Ra,h as ya,i as Na,j as Jc,E as or,k as Ws,l as sg,H as dy,m as at,n as rl,U as dr,o as ag,p as lg,L as Gf,K as ng,q as uy,r as my,s as Qc,t as Ss,u as hy,B as ar,v as Ic,w as Bu,x as xy,y as fy,z as zs,G as to,J as ti,N as Rl,O as ur,Q as jr,V as py,W as gy,Y as hs,_ as Hu,$ as nn,a0 as vr,a1 as dn,a2 as Ll,a3 as br,a4 as qu,a5 as jy,a6 as vy,a7 as by,a8 as rn,a9 as yy,aa as ig,ab as Eu,ac as mr,ad as Ny,ae as zu,af as Au,ag as rg,ah as Vf,ai as wy,aj as _y,ak as Sy,al as Ol,am as bu,an as Ff,ao as Cy,ap as yu,aq as ky,ar as Ty,as as Ey,at as zy,au as Ay,av as cg,aw as og,ax as dg,ay as My,az as $f,aA as Dy,aB as Oy,aC as Ry,aD as Ly}from"./icons-SnP_l694.js";import{S as Uy,p as By,j as Hy,a as qy,E as Qf,R as Gy,o as Vy}from"./codemirror-BHeANvwm.js";import{_ as Vs,c as Fy,g as ug,D as $y}from"./misc-DyBU7ISD.js";import{u as Qy,a as Yf,D as Yy,c as Xy,S as Ky,h as Zy,b as Jy,s as Iy,K as Py,P as Wy,d as eN,C as tN}from"./dnd-Dyi3CnuX.js";import{D as sN,U as aN}from"./uppy-BHC3OXBx.js";import{M as lN,r as nN,a as iN,b as rN}from"./markdown-A1ShuLvG.js";import{r as cN,H as Pc,P as Wc,u as oN,a as dN,R as uN,B as mN,b as hN,C as xN,M as fN,c as pN}from"./reactflow-B3n3_Vkw.js";(function(){const r=document.createElement("link").relList;if(r&&r.supports&&r.supports("modulepreload"))return;for(const h of document.querySelectorAll('link[rel="modulepreload"]'))d(h);new MutationObserver(h=>{for(const x of h)if(x.type==="childList")for(const f of x.addedNodes)f.tagName==="LINK"&&f.rel==="modulepreload"&&d(f)}).observe(document,{childList:!0,subtree:!0});function c(h){const x={};return h.integrity&&(x.integrity=h.integrity),h.referrerPolicy&&(x.referrerPolicy=h.referrerPolicy),h.crossOrigin==="use-credentials"?x.credentials="include":h.crossOrigin==="anonymous"?x.credentials="omit":x.credentials="same-origin",x}function d(h){if(h.ep)return;h.ep=!0;const x=c(h);fetch(h.href,x)}})();var Nu={exports:{}},er={},wu={exports:{}},_u={};var Xf;function gN(){return Xf||(Xf=1,(function(n){function r(A,X){var T=A.length;A.push(X);e:for(;0>>1,_=A[te];if(0>>1;teh(ae,T))xe<_&&0>h(ve,ae)?(A[te]=ve,A[xe]=T,te=xe):(A[te]=ae,A[oe]=T,te=oe);else if(xe<_&&0>h(ve,T))A[te]=ve,A[xe]=T,te=xe;else break e}}return X}function h(A,X){var T=A.sortIndex-X.sortIndex;return T!==0?T:A.id-X.id}if(n.unstable_now=void 0,typeof performance=="object"&&typeof performance.now=="function"){var x=performance;n.unstable_now=function(){return x.now()}}else{var f=Date,j=f.now();n.unstable_now=function(){return f.now()-j}}var p=[],N=[],v=1,C=null,S=3,w=!1,L=!1,F=!1,B=!1,O=typeof setTimeout=="function"?setTimeout:null,K=typeof clearTimeout=="function"?clearTimeout:null,H=typeof setImmediate<"u"?setImmediate:null;function z(A){for(var X=c(N);X!==null;){if(X.callback===null)d(N);else if(X.startTime<=A)d(N),X.sortIndex=X.expirationTime,r(p,X);else break;X=c(N)}}function V(A){if(F=!1,z(A),!L)if(c(p)!==null)L=!0,Y||(Y=!0,we());else{var X=c(N);X!==null&&be(V,X.startTime-A)}}var Y=!1,E=-1,R=5,ne=-1;function fe(){return B?!0:!(n.unstable_now()-neA&&fe());){var te=C.callback;if(typeof te=="function"){C.callback=null,S=C.priorityLevel;var _=te(C.expirationTime<=A);if(A=n.unstable_now(),typeof _=="function"){C.callback=_,z(A),X=!0;break t}C===c(p)&&d(p),z(A)}else d(p);C=c(p)}if(C!==null)X=!0;else{var me=c(N);me!==null&&be(V,me.startTime-A),X=!1}}break e}finally{C=null,S=T,w=!1}X=void 0}}finally{X?we():Y=!1}}}var we;if(typeof H=="function")we=function(){H(Ce)};else if(typeof MessageChannel<"u"){var pe=new MessageChannel,Ne=pe.port2;pe.port1.onmessage=Ce,we=function(){Ne.postMessage(null)}}else we=function(){O(Ce,0)};function be(A,X){E=O(function(){A(n.unstable_now())},X)}n.unstable_IdlePriority=5,n.unstable_ImmediatePriority=1,n.unstable_LowPriority=4,n.unstable_NormalPriority=3,n.unstable_Profiling=null,n.unstable_UserBlockingPriority=2,n.unstable_cancelCallback=function(A){A.callback=null},n.unstable_forceFrameRate=function(A){0>A||125te?(A.sortIndex=T,r(N,A),c(p)===null&&A===c(N)&&(F?(K(E),E=-1):F=!0,be(V,T-te))):(A.sortIndex=_,r(p,A),L||w||(L=!0,Y||(Y=!0,we()))),A},n.unstable_shouldYield=fe,n.unstable_wrapCallback=function(A){var X=S;return function(){var T=S;S=X;try{return A.apply(this,arguments)}finally{S=T}}}})(_u)),_u}var Kf;function jN(){return Kf||(Kf=1,wu.exports=gN()),wu.exports}var Zf;function vN(){if(Zf)return er;Zf=1;var n=jN(),r=rb(),c=cb();function d(t){var s="https://react.dev/errors/"+t;if(1_||(t.current=te[_],te[_]=null,_--)}function ae(t,s){_++,te[_]=t.current,t.current=s}var xe=me(null),ve=me(null),de=me(null),G=me(null);function W(t,s){switch(ae(de,s),ae(ve,t),ae(xe,null),s.nodeType){case 9:case 11:t=(t=s.documentElement)&&(t=t.namespaceURI)?df(t):0;break;default:if(t=s.tagName,s=s.namespaceURI)s=df(s),t=uf(s,t);else switch(t){case"svg":t=1;break;case"math":t=2;break;default:t=0}}oe(xe),ae(xe,t)}function U(){oe(xe),oe(ve),oe(de)}function ee(t){t.memoizedState!==null&&ae(G,t);var s=xe.current,a=uf(s,t.type);s!==a&&(ae(ve,t),ae(xe,a))}function Se(t){ve.current===t&&(oe(xe),oe(ve)),G.current===t&&(oe(G),Xi._currentValue=T)}var Me,tt;function Xe(t){if(Me===void 0)try{throw Error()}catch(a){var s=a.stack.trim().match(/\n( *(at )?)/);Me=s&&s[1]||"",tt=-1)":-1i||k[l]!==J[i]){var le=` `+k[l].replace(" at new "," at ");return t.displayName&&le.includes("")&&(le=le.replace("",t.displayName)),le}while(1<=l&&0<=i);break}}}finally{Ut=!1,Error.prepareStackTrace=a}return(a=t?t.displayName||t.name:"")?Xe(a):""}function re(t,s){switch(t.tag){case 26:case 27:case 5:return Xe(t.type);case 16:return Xe("Lazy");case 13:return t.child!==s&&s!==null?Xe("Suspense Fallback"):Xe("Suspense");case 19:return Xe("SuspenseList");case 0:case 15:return Bt(t.type,!1);case 11:return Bt(t.type.render,!1);case 1:return Bt(t.type,!0);case 31:return Xe("Activity");default:return""}}function ke(t){try{var s="",a=null;do s+=re(t,a),a=t,t=t.return;while(t);return s}catch(l){return` Error generating stack: `+l.message+` `+l.stack}}var Pe=Object.prototype.hasOwnProperty,Fe=n.unstable_scheduleCallback,ts=n.unstable_cancelCallback,As=n.unstable_shouldYield,js=n.unstable_requestPaint,Ke=n.unstable_now,D=n.unstable_getCurrentPriorityLevel,De=n.unstable_ImmediatePriority,ze=n.unstable_UserBlockingPriority,Ve=n.unstable_NormalPriority,At=n.unstable_LowPriority,We=n.unstable_IdlePriority,ss=n.log,gt=n.unstable_setDisableYieldValue,_e=null,je=null;function yt(t){if(typeof ss=="function"&>(t),je&&typeof je.setStrictMode=="function")try{je.setStrictMode(_e,t)}catch{}}var Ht=Math.clz32?Math.clz32:Kt,pa=Math.log,Ts=Math.LN2;function Kt(t){return t>>>=0,t===0?32:31-(pa(t)/Ts|0)|0}var Ms=256,Ds=262144,Ha=4194304;function Fs(t){var s=t&42;if(s!==0)return s;switch(t&-t){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:return 64;case 128:return 128;case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:return t&261888;case 262144:case 524288:case 1048576:case 2097152:return t&3932160;case 4194304:case 8388608:case 16777216:case 33554432:return t&62914560;case 67108864:return 67108864;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 0;default:return t}}function qa(t,s,a){var l=t.pendingLanes;if(l===0)return 0;var i=0,o=t.suspendedLanes,m=t.pingedLanes;t=t.warmLanes;var g=l&134217727;return g!==0?(l=g&~o,l!==0?i=Fs(l):(m&=g,m!==0?i=Fs(m):a||(a=g&~t,a!==0&&(i=Fs(a))))):(g=l&~o,g!==0?i=Fs(g):m!==0?i=Fs(m):a||(a=l&~t,a!==0&&(i=Fs(a)))),i===0?0:s!==0&&s!==i&&(s&o)===0&&(o=i&-i,a=s&-s,o>=a||o===32&&(a&4194048)!==0)?s:i}function Sa(t,s){return(t.pendingLanes&~(t.suspendedLanes&~t.pingedLanes)&s)===0}function P(t,s){switch(t){case 1:case 2:case 4:case 8:case 64:return s+250;case 16:case 32:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return s+5e3;case 4194304:case 8388608:case 16777216:case 33554432:return-1;case 67108864:case 134217728:case 268435456:case 536870912:case 1073741824:return-1;default:return-1}}function ye(){var t=Ha;return Ha<<=1,(Ha&62914560)===0&&(Ha=4194304),t}function Re(t){for(var s=[],a=0;31>a;a++)s.push(t);return s}function us(t,s){t.pendingLanes|=s,s!==268435456&&(t.suspendedLanes=0,t.pingedLanes=0,t.warmLanes=0)}function $s(t,s,a,l,i,o){var m=t.pendingLanes;t.pendingLanes=a,t.suspendedLanes=0,t.pingedLanes=0,t.warmLanes=0,t.expiredLanes&=a,t.entangledLanes&=a,t.errorRecoveryDisabledLanes&=a,t.shellSuspendCounter=0;var g=t.entanglements,k=t.expirationTimes,J=t.hiddenUpdates;for(a=m&~a;0"u")return null;try{return t.activeElement||t.body}catch{return t.body}}var Kg=/[\n"\\]/g;function aa(t){return t.replace(Kg,function(s){return"\\"+s.charCodeAt(0).toString(16)+" "})}function uo(t,s,a,l,i,o,m,g){t.name="",m!=null&&typeof m!="function"&&typeof m!="symbol"&&typeof m!="boolean"?t.type=m:t.removeAttribute("type"),s!=null?m==="number"?(s===0&&t.value===""||t.value!=s)&&(t.value=""+sa(s)):t.value!==""+sa(s)&&(t.value=""+sa(s)):m!=="submit"&&m!=="reset"||t.removeAttribute("value"),s!=null?mo(t,m,sa(s)):a!=null?mo(t,m,sa(a)):l!=null&&t.removeAttribute("value"),i==null&&o!=null&&(t.defaultChecked=!!o),i!=null&&(t.checked=i&&typeof i!="function"&&typeof i!="symbol"),g!=null&&typeof g!="function"&&typeof g!="symbol"&&typeof g!="boolean"?t.name=""+sa(g):t.removeAttribute("name")}function am(t,s,a,l,i,o,m,g){if(o!=null&&typeof o!="function"&&typeof o!="symbol"&&typeof o!="boolean"&&(t.type=o),s!=null||a!=null){if(!(o!=="submit"&&o!=="reset"||s!=null)){oo(t);return}a=a!=null?""+sa(a):"",s=s!=null?""+sa(s):a,g||s===t.value||(t.value=s),t.defaultValue=s}l=l??i,l=typeof l!="function"&&typeof l!="symbol"&&!!l,t.checked=g?t.checked:!!l,t.defaultChecked=!!l,m!=null&&typeof m!="function"&&typeof m!="symbol"&&typeof m!="boolean"&&(t.name=m),oo(t)}function mo(t,s,a){s==="number"&&Cr(t.ownerDocument)===t||t.defaultValue===""+a||(t.defaultValue=""+a)}function gn(t,s,a,l){if(t=t.options,s){s={};for(var i=0;i"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),go=!1;if(Fa)try{var ui={};Object.defineProperty(ui,"passive",{get:function(){go=!0}}),window.addEventListener("test",ui,ui),window.removeEventListener("test",ui,ui)}catch{go=!1}var ul=null,jo=null,Tr=null;function dm(){if(Tr)return Tr;var t,s=jo,a=s.length,l,i="value"in ul?ul.value:ul.textContent,o=i.length;for(t=0;t=xi),pm=" ",gm=!1;function jm(t,s){switch(t){case"keyup":return Nj.indexOf(s.keyCode)!==-1;case"keydown":return s.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function vm(t){return t=t.detail,typeof t=="object"&&"data"in t?t.data:null}var yn=!1;function _j(t,s){switch(t){case"compositionend":return vm(s);case"keypress":return s.which!==32?null:(gm=!0,pm);case"textInput":return t=s.data,t===pm&&gm?null:t;default:return null}}function Sj(t,s){if(yn)return t==="compositionend"||!wo&&jm(t,s)?(t=dm(),Tr=jo=ul=null,yn=!1,t):null;switch(t){case"paste":return null;case"keypress":if(!(s.ctrlKey||s.altKey||s.metaKey)||s.ctrlKey&&s.altKey){if(s.char&&1=s)return{node:a,offset:s-t};t=l}e:{for(;a;){if(a.nextSibling){a=a.nextSibling;break e}a=a.parentNode}a=void 0}a=km(a)}}function Em(t,s){return t&&s?t===s?!0:t&&t.nodeType===3?!1:s&&s.nodeType===3?Em(t,s.parentNode):"contains"in t?t.contains(s):t.compareDocumentPosition?!!(t.compareDocumentPosition(s)&16):!1:!1}function zm(t){t=t!=null&&t.ownerDocument!=null&&t.ownerDocument.defaultView!=null?t.ownerDocument.defaultView:window;for(var s=Cr(t.document);s instanceof t.HTMLIFrameElement;){try{var a=typeof s.contentWindow.location.href=="string"}catch{a=!1}if(a)t=s.contentWindow;else break;s=Cr(t.document)}return s}function Co(t){var s=t&&t.nodeName&&t.nodeName.toLowerCase();return s&&(s==="input"&&(t.type==="text"||t.type==="search"||t.type==="tel"||t.type==="url"||t.type==="password")||s==="textarea"||t.contentEditable==="true")}var Dj=Fa&&"documentMode"in document&&11>=document.documentMode,Nn=null,ko=null,ji=null,To=!1;function Am(t,s,a){var l=a.window===a?a.document:a.nodeType===9?a:a.ownerDocument;To||Nn==null||Nn!==Cr(l)||(l=Nn,"selectionStart"in l&&Co(l)?l={start:l.selectionStart,end:l.selectionEnd}:(l=(l.ownerDocument&&l.ownerDocument.defaultView||window).getSelection(),l={anchorNode:l.anchorNode,anchorOffset:l.anchorOffset,focusNode:l.focusNode,focusOffset:l.focusOffset}),ji&&gi(ji,l)||(ji=l,l=yc(ko,"onSelect"),0>=m,i-=m,ka=1<<32-Ht(s)+i|a<et?(ot=Ae,Ae=null):ot=Ae.sibling;var St=I(q,Ae,Z[et],ue);if(St===null){Ae===null&&(Ae=ot);break}t&&Ae&&St.alternate===null&&s(q,Ae),M=o(St,M,et),_t===null?Oe=St:_t.sibling=St,_t=St,Ae=ot}if(et===Z.length)return a(q,Ae),vt&&Qa(q,et),Oe;if(Ae===null){for(;etet?(ot=Ae,Ae=null):ot=Ae.sibling;var Dl=I(q,Ae,St.value,ue);if(Dl===null){Ae===null&&(Ae=ot);break}t&&Ae&&Dl.alternate===null&&s(q,Ae),M=o(Dl,M,et),_t===null?Oe=Dl:_t.sibling=Dl,_t=Dl,Ae=ot}if(St.done)return a(q,Ae),vt&&Qa(q,et),Oe;if(Ae===null){for(;!St.done;et++,St=Z.next())St=he(q,St.value,ue),St!==null&&(M=o(St,M,et),_t===null?Oe=St:_t.sibling=St,_t=St);return vt&&Qa(q,et),Oe}for(Ae=l(Ae);!St.done;et++,St=Z.next())St=se(Ae,q,et,St.value,ue),St!==null&&(t&&St.alternate!==null&&Ae.delete(St.key===null?et:St.key),M=o(St,M,et),_t===null?Oe=St:_t.sibling=St,_t=St);return t&&Ae.forEach(function(Wv){return s(q,Wv)}),vt&&Qa(q,et),Oe}function Ot(q,M,Z,ue){if(typeof Z=="object"&&Z!==null&&Z.type===F&&Z.key===null&&(Z=Z.props.children),typeof Z=="object"&&Z!==null){switch(Z.$$typeof){case w:e:{for(var Oe=Z.key;M!==null;){if(M.key===Oe){if(Oe=Z.type,Oe===F){if(M.tag===7){a(q,M.sibling),ue=i(M,Z.props.children),ue.return=q,q=ue;break e}}else if(M.elementType===Oe||typeof Oe=="object"&&Oe!==null&&Oe.$$typeof===R&&Jl(Oe)===M.type){a(q,M.sibling),ue=i(M,Z.props),_i(ue,Z),ue.return=q,q=ue;break e}a(q,M);break}else s(q,M);M=M.sibling}Z.type===F?(ue=Ql(Z.props.children,q.mode,ue,Z.key),ue.return=q,q=ue):(ue=Br(Z.type,Z.key,Z.props,null,q.mode,ue),_i(ue,Z),ue.return=q,q=ue)}return m(q);case L:e:{for(Oe=Z.key;M!==null;){if(M.key===Oe)if(M.tag===4&&M.stateNode.containerInfo===Z.containerInfo&&M.stateNode.implementation===Z.implementation){a(q,M.sibling),ue=i(M,Z.children||[]),ue.return=q,q=ue;break e}else{a(q,M);break}else s(q,M);M=M.sibling}ue=Ro(Z,q.mode,ue),ue.return=q,q=ue}return m(q);case R:return Z=Jl(Z),Ot(q,M,Z,ue)}if(be(Z))return Ee(q,M,Z,ue);if(we(Z)){if(Oe=we(Z),typeof Oe!="function")throw Error(d(150));return Z=Oe.call(Z),Ue(q,M,Z,ue)}if(typeof Z.then=="function")return Ot(q,M,Qr(Z),ue);if(Z.$$typeof===H)return Ot(q,M,Gr(q,Z),ue);Yr(q,Z)}return typeof Z=="string"&&Z!==""||typeof Z=="number"||typeof Z=="bigint"?(Z=""+Z,M!==null&&M.tag===6?(a(q,M.sibling),ue=i(M,Z),ue.return=q,q=ue):(a(q,M),ue=Oo(Z,q.mode,ue),ue.return=q,q=ue),m(q)):a(q,M)}return function(q,M,Z,ue){try{wi=0;var Oe=Ot(q,M,Z,ue);return Dn=null,Oe}catch(Ae){if(Ae===Mn||Ae===Fr)throw Ae;var _t=Ys(29,Ae,null,q.mode);return _t.lanes=ue,_t.return=q,_t}finally{}}}var Pl=eh(!0),th=eh(!1),pl=!1;function Xo(t){t.updateQueue={baseState:t.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,lanes:0,hiddenCallbacks:null},callbacks:null}}function Ko(t,s){t=t.updateQueue,s.updateQueue===t&&(s.updateQueue={baseState:t.baseState,firstBaseUpdate:t.firstBaseUpdate,lastBaseUpdate:t.lastBaseUpdate,shared:t.shared,callbacks:null})}function gl(t){return{lane:t,tag:0,payload:null,callback:null,next:null}}function jl(t,s,a){var l=t.updateQueue;if(l===null)return null;if(l=l.shared,(Ct&2)!==0){var i=l.pending;return i===null?s.next=s:(s.next=i.next,i.next=s),l.pending=s,s=Ur(t),Bm(t,null,a),s}return Lr(t,l,s,a),Ur(t)}function Si(t,s,a){if(s=s.updateQueue,s!==null&&(s=s.shared,(a&4194048)!==0)){var l=s.lanes;l&=t.pendingLanes,a|=l,s.lanes=a,dl(t,a)}}function Zo(t,s){var a=t.updateQueue,l=t.alternate;if(l!==null&&(l=l.updateQueue,a===l)){var i=null,o=null;if(a=a.firstBaseUpdate,a!==null){do{var m={lane:a.lane,tag:a.tag,payload:a.payload,callback:null,next:null};o===null?i=o=m:o=o.next=m,a=a.next}while(a!==null);o===null?i=o=s:o=o.next=s}else i=o=s;a={baseState:l.baseState,firstBaseUpdate:i,lastBaseUpdate:o,shared:l.shared,callbacks:l.callbacks},t.updateQueue=a;return}t=a.lastBaseUpdate,t===null?a.firstBaseUpdate=s:t.next=s,a.lastBaseUpdate=s}var Jo=!1;function Ci(){if(Jo){var t=An;if(t!==null)throw t}}function ki(t,s,a,l){Jo=!1;var i=t.updateQueue;pl=!1;var o=i.firstBaseUpdate,m=i.lastBaseUpdate,g=i.shared.pending;if(g!==null){i.shared.pending=null;var k=g,J=k.next;k.next=null,m===null?o=J:m.next=J,m=k;var le=t.alternate;le!==null&&(le=le.updateQueue,g=le.lastBaseUpdate,g!==m&&(g===null?le.firstBaseUpdate=J:g.next=J,le.lastBaseUpdate=k))}if(o!==null){var he=i.baseState;m=0,le=J=k=null,g=o;do{var I=g.lane&-536870913,se=I!==g.lane;if(se?(ct&I)===I:(l&I)===I){I!==0&&I===zn&&(Jo=!0),le!==null&&(le=le.next={lane:0,tag:g.tag,payload:g.payload,callback:null,next:null});e:{var Ee=t,Ue=g;I=s;var Ot=a;switch(Ue.tag){case 1:if(Ee=Ue.payload,typeof Ee=="function"){he=Ee.call(Ot,he,I);break e}he=Ee;break e;case 3:Ee.flags=Ee.flags&-65537|128;case 0:if(Ee=Ue.payload,I=typeof Ee=="function"?Ee.call(Ot,he,I):Ee,I==null)break e;he=C({},he,I);break e;case 2:pl=!0}}I=g.callback,I!==null&&(t.flags|=64,se&&(t.flags|=8192),se=i.callbacks,se===null?i.callbacks=[I]:se.push(I))}else se={lane:I,tag:g.tag,payload:g.payload,callback:g.callback,next:null},le===null?(J=le=se,k=he):le=le.next=se,m|=I;if(g=g.next,g===null){if(g=i.shared.pending,g===null)break;se=g,g=se.next,se.next=null,i.lastBaseUpdate=se,i.shared.pending=null}}while(!0);le===null&&(k=he),i.baseState=k,i.firstBaseUpdate=J,i.lastBaseUpdate=le,o===null&&(i.shared.lanes=0),wl|=m,t.lanes=m,t.memoizedState=he}}function sh(t,s){if(typeof t!="function")throw Error(d(191,t));t.call(s)}function ah(t,s){var a=t.callbacks;if(a!==null)for(t.callbacks=null,t=0;to?o:8;var m=A.T,g={};A.T=g,fd(t,!1,s,a);try{var k=i(),J=A.S;if(J!==null&&J(g,k),k!==null&&typeof k=="object"&&typeof k.then=="function"){var le=Vj(k,l);zi(t,s,le,Is(t))}else zi(t,s,l,Is(t))}catch(he){zi(t,s,{then:function(){},status:"rejected",reason:he},Is())}finally{X.p=o,m!==null&&g.types!==null&&(m.types=g.types),A.T=m}}function Kj(){}function hd(t,s,a,l){if(t.tag!==5)throw Error(d(476));var i=Rh(t).queue;Oh(t,i,s,T,a===null?Kj:function(){return Lh(t),a(l)})}function Rh(t){var s=t.memoizedState;if(s!==null)return s;s={memoizedState:T,baseState:T,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:Za,lastRenderedState:T},next:null};var a={};return s.next={memoizedState:a,baseState:a,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:Za,lastRenderedState:a},next:null},t.memoizedState=s,t=t.alternate,t!==null&&(t.memoizedState=s),s}function Lh(t){var s=Rh(t);s.next===null&&(s=t.alternate.memoizedState),zi(t,s.next.queue,{},Is())}function xd(){return bs(Xi)}function Uh(){return ls().memoizedState}function Bh(){return ls().memoizedState}function Zj(t){for(var s=t.return;s!==null;){switch(s.tag){case 24:case 3:var a=Is();t=gl(a);var l=jl(s,t,a);l!==null&&(qs(l,s,a),Si(l,s,a)),s={cache:Fo()},t.payload=s;return}s=s.return}}function Jj(t,s,a){var l=Is();a={lane:l,revertLane:0,gesture:null,action:a,hasEagerState:!1,eagerState:null,next:null},sc(t)?qh(s,a):(a=Mo(t,s,a,l),a!==null&&(qs(a,t,l),Gh(a,s,l)))}function Hh(t,s,a){var l=Is();zi(t,s,a,l)}function zi(t,s,a,l){var i={lane:l,revertLane:0,gesture:null,action:a,hasEagerState:!1,eagerState:null,next:null};if(sc(t))qh(s,i);else{var o=t.alternate;if(t.lanes===0&&(o===null||o.lanes===0)&&(o=s.lastRenderedReducer,o!==null))try{var m=s.lastRenderedState,g=o(m,a);if(i.hasEagerState=!0,i.eagerState=g,Qs(g,m))return Lr(t,s,i,0),Lt===null&&Rr(),!1}catch{}finally{}if(a=Mo(t,s,i,l),a!==null)return qs(a,t,l),Gh(a,s,l),!0}return!1}function fd(t,s,a,l){if(l={lane:2,revertLane:Xd(),gesture:null,action:l,hasEagerState:!1,eagerState:null,next:null},sc(t)){if(s)throw Error(d(479))}else s=Mo(t,a,l,2),s!==null&&qs(s,t,2)}function sc(t){var s=t.alternate;return t===Ie||s!==null&&s===Ie}function qh(t,s){Rn=Zr=!0;var a=t.pending;a===null?s.next=s:(s.next=a.next,a.next=s),t.pending=s}function Gh(t,s,a){if((a&4194048)!==0){var l=s.lanes;l&=t.pendingLanes,a|=l,s.lanes=a,dl(t,a)}}var Ai={readContext:bs,use:Pr,useCallback:It,useContext:It,useEffect:It,useImperativeHandle:It,useLayoutEffect:It,useInsertionEffect:It,useMemo:It,useReducer:It,useRef:It,useState:It,useDebugValue:It,useDeferredValue:It,useTransition:It,useSyncExternalStore:It,useId:It,useHostTransitionStatus:It,useFormState:It,useActionState:It,useOptimistic:It,useMemoCache:It,useCacheRefresh:It};Ai.useEffectEvent=It;var Vh={readContext:bs,use:Pr,useCallback:function(t,s){return Es().memoizedState=[t,s===void 0?null:s],t},useContext:bs,useEffect:Sh,useImperativeHandle:function(t,s,a){a=a!=null?a.concat([t]):null,ec(4194308,4,Eh.bind(null,s,t),a)},useLayoutEffect:function(t,s){return ec(4194308,4,t,s)},useInsertionEffect:function(t,s){ec(4,2,t,s)},useMemo:function(t,s){var a=Es();s=s===void 0?null:s;var l=t();if(Wl){yt(!0);try{t()}finally{yt(!1)}}return a.memoizedState=[l,s],l},useReducer:function(t,s,a){var l=Es();if(a!==void 0){var i=a(s);if(Wl){yt(!0);try{a(s)}finally{yt(!1)}}}else i=s;return l.memoizedState=l.baseState=i,t={pending:null,lanes:0,dispatch:null,lastRenderedReducer:t,lastRenderedState:i},l.queue=t,t=t.dispatch=Jj.bind(null,Ie,t),[l.memoizedState,t]},useRef:function(t){var s=Es();return t={current:t},s.memoizedState=t},useState:function(t){t=cd(t);var s=t.queue,a=Hh.bind(null,Ie,s);return s.dispatch=a,[t.memoizedState,a]},useDebugValue:ud,useDeferredValue:function(t,s){var a=Es();return md(a,t,s)},useTransition:function(){var t=cd(!1);return t=Oh.bind(null,Ie,t.queue,!0,!1),Es().memoizedState=t,[!1,t]},useSyncExternalStore:function(t,s,a){var l=Ie,i=Es();if(vt){if(a===void 0)throw Error(d(407));a=a()}else{if(a=s(),Lt===null)throw Error(d(349));(ct&127)!==0||oh(l,s,a)}i.memoizedState=a;var o={value:a,getSnapshot:s};return i.queue=o,Sh(uh.bind(null,l,o,t),[t]),l.flags|=2048,Un(9,{destroy:void 0},dh.bind(null,l,o,a,s),null),a},useId:function(){var t=Es(),s=Lt.identifierPrefix;if(vt){var a=Ta,l=ka;a=(l&~(1<<32-Ht(l)-1)).toString(32)+a,s="_"+s+"R_"+a,a=Jr++,0<\/script>",o=o.removeChild(o.firstChild);break;case"select":o=typeof l.is=="string"?m.createElement("select",{is:l.is}):m.createElement("select"),l.multiple?o.multiple=!0:l.size&&(o.size=l.size);break;default:o=typeof l.is=="string"?m.createElement(i,{is:l.is}):m.createElement(i)}}o[$e]=s,o[jt]=l;e:for(m=s.child;m!==null;){if(m.tag===5||m.tag===6)o.appendChild(m.stateNode);else if(m.tag!==4&&m.tag!==27&&m.child!==null){m.child.return=m,m=m.child;continue}if(m===s)break e;for(;m.sibling===null;){if(m.return===null||m.return===s)break e;m=m.return}m.sibling.return=m.return,m=m.sibling}s.stateNode=o;e:switch(Ns(o,i,l),i){case"button":case"input":case"select":case"textarea":l=!!l.autoFocus;break e;case"img":l=!0;break e;default:l=!1}l&&Ia(s)}}return Gt(s),Ed(s,s.type,t===null?null:t.memoizedProps,s.pendingProps,a),null;case 6:if(t&&s.stateNode!=null)t.memoizedProps!==l&&Ia(s);else{if(typeof l!="string"&&s.stateNode===null)throw Error(d(166));if(t=de.current,Tn(s)){if(t=s.stateNode,a=s.memoizedProps,l=null,i=vs,i!==null)switch(i.tag){case 27:case 5:l=i.memoizedProps}t[$e]=s,t=!!(t.nodeValue===a||l!==null&&l.suppressHydrationWarning===!0||cf(t.nodeValue,a)),t||xl(s,!0)}else t=Nc(t).createTextNode(l),t[$e]=s,s.stateNode=t}return Gt(s),null;case 31:if(a=s.memoizedState,t===null||t.memoizedState!==null){if(l=Tn(s),a!==null){if(t===null){if(!l)throw Error(d(318));if(t=s.memoizedState,t=t!==null?t.dehydrated:null,!t)throw Error(d(557));t[$e]=s}else Yl(),(s.flags&128)===0&&(s.memoizedState=null),s.flags|=4;Gt(s),t=!1}else a=Ho(),t!==null&&t.memoizedState!==null&&(t.memoizedState.hydrationErrors=a),t=!0;if(!t)return s.flags&256?(Ks(s),s):(Ks(s),null);if((s.flags&128)!==0)throw Error(d(558))}return Gt(s),null;case 13:if(l=s.memoizedState,t===null||t.memoizedState!==null&&t.memoizedState.dehydrated!==null){if(i=Tn(s),l!==null&&l.dehydrated!==null){if(t===null){if(!i)throw Error(d(318));if(i=s.memoizedState,i=i!==null?i.dehydrated:null,!i)throw Error(d(317));i[$e]=s}else Yl(),(s.flags&128)===0&&(s.memoizedState=null),s.flags|=4;Gt(s),i=!1}else i=Ho(),t!==null&&t.memoizedState!==null&&(t.memoizedState.hydrationErrors=i),i=!0;if(!i)return s.flags&256?(Ks(s),s):(Ks(s),null)}return Ks(s),(s.flags&128)!==0?(s.lanes=a,s):(a=l!==null,t=t!==null&&t.memoizedState!==null,a&&(l=s.child,i=null,l.alternate!==null&&l.alternate.memoizedState!==null&&l.alternate.memoizedState.cachePool!==null&&(i=l.alternate.memoizedState.cachePool.pool),o=null,l.memoizedState!==null&&l.memoizedState.cachePool!==null&&(o=l.memoizedState.cachePool.pool),o!==i&&(l.flags|=2048)),a!==t&&a&&(s.child.flags|=8192),rc(s,s.updateQueue),Gt(s),null);case 4:return U(),t===null&&Id(s.stateNode.containerInfo),Gt(s),null;case 10:return Xa(s.type),Gt(s),null;case 19:if(oe(as),l=s.memoizedState,l===null)return Gt(s),null;if(i=(s.flags&128)!==0,o=l.rendering,o===null)if(i)Di(l,!1);else{if(Pt!==0||t!==null&&(t.flags&128)!==0)for(t=s.child;t!==null;){if(o=Kr(t),o!==null){for(s.flags|=128,Di(l,!1),t=o.updateQueue,s.updateQueue=t,rc(s,t),s.subtreeFlags=0,t=a,a=s.child;a!==null;)Hm(a,t),a=a.sibling;return ae(as,as.current&1|2),vt&&Qa(s,l.treeForkCount),s.child}t=t.sibling}l.tail!==null&&Ke()>mc&&(s.flags|=128,i=!0,Di(l,!1),s.lanes=4194304)}else{if(!i)if(t=Kr(o),t!==null){if(s.flags|=128,i=!0,t=t.updateQueue,s.updateQueue=t,rc(s,t),Di(l,!0),l.tail===null&&l.tailMode==="hidden"&&!o.alternate&&!vt)return Gt(s),null}else 2*Ke()-l.renderingStartTime>mc&&a!==536870912&&(s.flags|=128,i=!0,Di(l,!1),s.lanes=4194304);l.isBackwards?(o.sibling=s.child,s.child=o):(t=l.last,t!==null?t.sibling=o:s.child=o,l.last=o)}return l.tail!==null?(t=l.tail,l.rendering=t,l.tail=t.sibling,l.renderingStartTime=Ke(),t.sibling=null,a=as.current,ae(as,i?a&1|2:a&1),vt&&Qa(s,l.treeForkCount),t):(Gt(s),null);case 22:case 23:return Ks(s),Po(),l=s.memoizedState!==null,t!==null?t.memoizedState!==null!==l&&(s.flags|=8192):l&&(s.flags|=8192),l?(a&536870912)!==0&&(s.flags&128)===0&&(Gt(s),s.subtreeFlags&6&&(s.flags|=8192)):Gt(s),a=s.updateQueue,a!==null&&rc(s,a.retryQueue),a=null,t!==null&&t.memoizedState!==null&&t.memoizedState.cachePool!==null&&(a=t.memoizedState.cachePool.pool),l=null,s.memoizedState!==null&&s.memoizedState.cachePool!==null&&(l=s.memoizedState.cachePool.pool),l!==a&&(s.flags|=2048),t!==null&&oe(Zl),null;case 24:return a=null,t!==null&&(a=t.memoizedState.cache),s.memoizedState.cache!==a&&(s.flags|=2048),Xa(is),Gt(s),null;case 25:return null;case 30:return null}throw Error(d(156,s.tag))}function tv(t,s){switch(Uo(s),s.tag){case 1:return t=s.flags,t&65536?(s.flags=t&-65537|128,s):null;case 3:return Xa(is),U(),t=s.flags,(t&65536)!==0&&(t&128)===0?(s.flags=t&-65537|128,s):null;case 26:case 27:case 5:return Se(s),null;case 31:if(s.memoizedState!==null){if(Ks(s),s.alternate===null)throw Error(d(340));Yl()}return t=s.flags,t&65536?(s.flags=t&-65537|128,s):null;case 13:if(Ks(s),t=s.memoizedState,t!==null&&t.dehydrated!==null){if(s.alternate===null)throw Error(d(340));Yl()}return t=s.flags,t&65536?(s.flags=t&-65537|128,s):null;case 19:return oe(as),null;case 4:return U(),null;case 10:return Xa(s.type),null;case 22:case 23:return Ks(s),Po(),t!==null&&oe(Zl),t=s.flags,t&65536?(s.flags=t&-65537|128,s):null;case 24:return Xa(is),null;case 25:return null;default:return null}}function mx(t,s){switch(Uo(s),s.tag){case 3:Xa(is),U();break;case 26:case 27:case 5:Se(s);break;case 4:U();break;case 31:s.memoizedState!==null&&Ks(s);break;case 13:Ks(s);break;case 19:oe(as);break;case 10:Xa(s.type);break;case 22:case 23:Ks(s),Po(),t!==null&&oe(Zl);break;case 24:Xa(is)}}function Oi(t,s){try{var a=s.updateQueue,l=a!==null?a.lastEffect:null;if(l!==null){var i=l.next;a=i;do{if((a.tag&t)===t){l=void 0;var o=a.create,m=a.inst;l=o(),m.destroy=l}a=a.next}while(a!==i)}}catch(g){Et(s,s.return,g)}}function yl(t,s,a){try{var l=s.updateQueue,i=l!==null?l.lastEffect:null;if(i!==null){var o=i.next;l=o;do{if((l.tag&t)===t){var m=l.inst,g=m.destroy;if(g!==void 0){m.destroy=void 0,i=s;var k=a,J=g;try{J()}catch(le){Et(i,k,le)}}}l=l.next}while(l!==o)}}catch(le){Et(s,s.return,le)}}function hx(t){var s=t.updateQueue;if(s!==null){var a=t.stateNode;try{ah(s,a)}catch(l){Et(t,t.return,l)}}}function xx(t,s,a){a.props=en(t.type,t.memoizedProps),a.state=t.memoizedState;try{a.componentWillUnmount()}catch(l){Et(t,s,l)}}function Ri(t,s){try{var a=t.ref;if(a!==null){switch(t.tag){case 26:case 27:case 5:var l=t.stateNode;break;case 30:l=t.stateNode;break;default:l=t.stateNode}typeof a=="function"?t.refCleanup=a(l):a.current=l}}catch(i){Et(t,s,i)}}function Ea(t,s){var a=t.ref,l=t.refCleanup;if(a!==null)if(typeof l=="function")try{l()}catch(i){Et(t,s,i)}finally{t.refCleanup=null,t=t.alternate,t!=null&&(t.refCleanup=null)}else if(typeof a=="function")try{a(null)}catch(i){Et(t,s,i)}else a.current=null}function fx(t){var s=t.type,a=t.memoizedProps,l=t.stateNode;try{e:switch(s){case"button":case"input":case"select":case"textarea":a.autoFocus&&l.focus();break e;case"img":a.src?l.src=a.src:a.srcSet&&(l.srcset=a.srcSet)}}catch(i){Et(t,t.return,i)}}function zd(t,s,a){try{var l=t.stateNode;wv(l,t.type,a,s),l[jt]=s}catch(i){Et(t,t.return,i)}}function px(t){return t.tag===5||t.tag===3||t.tag===26||t.tag===27&&Tl(t.type)||t.tag===4}function Ad(t){e:for(;;){for(;t.sibling===null;){if(t.return===null||px(t.return))return null;t=t.return}for(t.sibling.return=t.return,t=t.sibling;t.tag!==5&&t.tag!==6&&t.tag!==18;){if(t.tag===27&&Tl(t.type)||t.flags&2||t.child===null||t.tag===4)continue e;t.child.return=t,t=t.child}if(!(t.flags&2))return t.stateNode}}function Md(t,s,a){var l=t.tag;if(l===5||l===6)t=t.stateNode,s?(a.nodeType===9?a.body:a.nodeName==="HTML"?a.ownerDocument.body:a).insertBefore(t,s):(s=a.nodeType===9?a.body:a.nodeName==="HTML"?a.ownerDocument.body:a,s.appendChild(t),a=a._reactRootContainer,a!=null||s.onclick!==null||(s.onclick=Va));else if(l!==4&&(l===27&&Tl(t.type)&&(a=t.stateNode,s=null),t=t.child,t!==null))for(Md(t,s,a),t=t.sibling;t!==null;)Md(t,s,a),t=t.sibling}function cc(t,s,a){var l=t.tag;if(l===5||l===6)t=t.stateNode,s?a.insertBefore(t,s):a.appendChild(t);else if(l!==4&&(l===27&&Tl(t.type)&&(a=t.stateNode),t=t.child,t!==null))for(cc(t,s,a),t=t.sibling;t!==null;)cc(t,s,a),t=t.sibling}function gx(t){var s=t.stateNode,a=t.memoizedProps;try{for(var l=t.type,i=s.attributes;i.length;)s.removeAttributeNode(i[0]);Ns(s,l,a),s[$e]=t,s[jt]=a}catch(o){Et(t,t.return,o)}}var Pa=!1,os=!1,Dd=!1,jx=typeof WeakSet=="function"?WeakSet:Set,gs=null;function sv(t,s){if(t=t.containerInfo,eu=Ec,t=zm(t),Co(t)){if("selectionStart"in t)var a={start:t.selectionStart,end:t.selectionEnd};else e:{a=(a=t.ownerDocument)&&a.defaultView||window;var l=a.getSelection&&a.getSelection();if(l&&l.rangeCount!==0){a=l.anchorNode;var i=l.anchorOffset,o=l.focusNode;l=l.focusOffset;try{a.nodeType,o.nodeType}catch{a=null;break e}var m=0,g=-1,k=-1,J=0,le=0,he=t,I=null;t:for(;;){for(var se;he!==a||i!==0&&he.nodeType!==3||(g=m+i),he!==o||l!==0&&he.nodeType!==3||(k=m+l),he.nodeType===3&&(m+=he.nodeValue.length),(se=he.firstChild)!==null;)I=he,he=se;for(;;){if(he===t)break t;if(I===a&&++J===i&&(g=m),I===o&&++le===l&&(k=m),(se=he.nextSibling)!==null)break;he=I,I=he.parentNode}he=se}a=g===-1||k===-1?null:{start:g,end:k}}else a=null}a=a||{start:0,end:0}}else a=null;for(tu={focusedElem:t,selectionRange:a},Ec=!1,gs=s;gs!==null;)if(s=gs,t=s.child,(s.subtreeFlags&1028)!==0&&t!==null)t.return=s,gs=t;else for(;gs!==null;){switch(s=gs,o=s.alternate,t=s.flags,s.tag){case 0:if((t&4)!==0&&(t=s.updateQueue,t=t!==null?t.events:null,t!==null))for(a=0;a title"))),Ns(o,l,a),o[$e]=t,ps(o),l=o;break e;case"link":var m=Sf("link","href",i).get(l+(a.href||""));if(m){for(var g=0;gOt&&(m=Ot,Ot=Ue,Ue=m);var q=Tm(g,Ue),M=Tm(g,Ot);if(q&&M&&(se.rangeCount!==1||se.anchorNode!==q.node||se.anchorOffset!==q.offset||se.focusNode!==M.node||se.focusOffset!==M.offset)){var Z=he.createRange();Z.setStart(q.node,q.offset),se.removeAllRanges(),Ue>Ot?(se.addRange(Z),se.extend(M.node,M.offset)):(Z.setEnd(M.node,M.offset),se.addRange(Z))}}}}for(he=[],se=g;se=se.parentNode;)se.nodeType===1&&he.push({element:se,left:se.scrollLeft,top:se.scrollTop});for(typeof g.focus=="function"&&g.focus(),g=0;ga?32:a,A.T=null,a=qd,qd=null;var o=Sl,m=al;if(ms=0,Vn=Sl=null,al=0,(Ct&6)!==0)throw Error(d(331));var g=Ct;if(Ct|=4,Ex(o.current),Cx(o,o.current,m,a),Ct=g,Gi(0,!1),je&&typeof je.onPostCommitFiberRoot=="function")try{je.onPostCommitFiberRoot(_e,o)}catch{}return!0}finally{X.p=i,A.T=l,Xx(t,s)}}function Zx(t,s,a){s=na(a,s),s=vd(t.stateNode,s,2),t=jl(t,s,2),t!==null&&(us(t,2),za(t))}function Et(t,s,a){if(t.tag===3)Zx(t,t,a);else for(;s!==null;){if(s.tag===3){Zx(s,t,a);break}else if(s.tag===1){var l=s.stateNode;if(typeof s.type.getDerivedStateFromError=="function"||typeof l.componentDidCatch=="function"&&(_l===null||!_l.has(l))){t=na(a,t),a=Jh(2),l=jl(s,a,2),l!==null&&(Ih(a,l,s,t),us(l,2),za(l));break}}s=s.return}}function $d(t,s,a){var l=t.pingCache;if(l===null){l=t.pingCache=new nv;var i=new Set;l.set(s,i)}else i=l.get(s),i===void 0&&(i=new Set,l.set(s,i));i.has(a)||(Ld=!0,i.add(a),t=dv.bind(null,t,s,a),s.then(t,t))}function dv(t,s,a){var l=t.pingCache;l!==null&&l.delete(s),t.pingedLanes|=t.suspendedLanes&a,t.warmLanes&=~a,Lt===t&&(ct&a)===a&&(Pt===4||Pt===3&&(ct&62914560)===ct&&300>Ke()-uc?(Ct&2)===0&&Fn(t,0):Ud|=a,Gn===ct&&(Gn=0)),za(t)}function Jx(t,s){s===0&&(s=ye()),t=$l(t,s),t!==null&&(us(t,s),za(t))}function uv(t){var s=t.memoizedState,a=0;s!==null&&(a=s.retryLane),Jx(t,a)}function mv(t,s){var a=0;switch(t.tag){case 31:case 13:var l=t.stateNode,i=t.memoizedState;i!==null&&(a=i.retryLane);break;case 19:l=t.stateNode;break;case 22:l=t.stateNode._retryCache;break;default:throw Error(d(314))}l!==null&&l.delete(s),Jx(t,a)}function hv(t,s){return Fe(t,s)}var jc=null,Qn=null,Qd=!1,vc=!1,Yd=!1,kl=0;function za(t){t!==Qn&&t.next===null&&(Qn===null?jc=Qn=t:Qn=Qn.next=t),vc=!0,Qd||(Qd=!0,fv())}function Gi(t,s){if(!Yd&&vc){Yd=!0;do for(var a=!1,l=jc;l!==null;){if(t!==0){var i=l.pendingLanes;if(i===0)var o=0;else{var m=l.suspendedLanes,g=l.pingedLanes;o=(1<<31-Ht(42|t)+1)-1,o&=i&~(m&~g),o=o&201326741?o&201326741|1:o?o|2:0}o!==0&&(a=!0,ef(l,o))}else o=ct,o=qa(l,l===Lt?o:0,l.cancelPendingCommit!==null||l.timeoutHandle!==-1),(o&3)===0||Sa(l,o)||(a=!0,ef(l,o));l=l.next}while(a);Yd=!1}}function xv(){Ix()}function Ix(){vc=Qd=!1;var t=0;kl!==0&&Sv()&&(t=kl);for(var s=Ke(),a=null,l=jc;l!==null;){var i=l.next,o=Px(l,s);o===0?(l.next=null,a===null?jc=i:a.next=i,i===null&&(Qn=a)):(a=l,(t!==0||(o&3)!==0)&&(vc=!0)),l=i}ms!==0&&ms!==5||Gi(t),kl!==0&&(kl=0)}function Px(t,s){for(var a=t.suspendedLanes,l=t.pingedLanes,i=t.expirationTimes,o=t.pendingLanes&-62914561;0g)break;var le=k.transferSize,he=k.initiatorType;le&&of(he)&&(k=k.responseEnd,m+=le*(k"u"?null:document;function yf(t,s,a){var l=Yn;if(l&&typeof s=="string"&&s){var i=aa(s);i='link[rel="'+t+'"][href="'+i+'"]',typeof a=="string"&&(i+='[crossorigin="'+a+'"]'),bf.has(i)||(bf.add(i),t={rel:t,crossOrigin:a,href:s},l.querySelector(i)===null&&(s=l.createElement("link"),Ns(s,"link",t),ps(s),l.head.appendChild(s)))}}function Ov(t){ll.D(t),yf("dns-prefetch",t,null)}function Rv(t,s){ll.C(t,s),yf("preconnect",t,s)}function Lv(t,s,a){ll.L(t,s,a);var l=Yn;if(l&&t&&s){var i='link[rel="preload"][as="'+aa(s)+'"]';s==="image"&&a&&a.imageSrcSet?(i+='[imagesrcset="'+aa(a.imageSrcSet)+'"]',typeof a.imageSizes=="string"&&(i+='[imagesizes="'+aa(a.imageSizes)+'"]')):i+='[href="'+aa(t)+'"]';var o=i;switch(s){case"style":o=Xn(t);break;case"script":o=Kn(t)}ua.has(o)||(t=C({rel:"preload",href:s==="image"&&a&&a.imageSrcSet?void 0:t,as:s},a),ua.set(o,t),l.querySelector(i)!==null||s==="style"&&l.querySelector(Qi(o))||s==="script"&&l.querySelector(Yi(o))||(s=l.createElement("link"),Ns(s,"link",t),ps(s),l.head.appendChild(s)))}}function Uv(t,s){ll.m(t,s);var a=Yn;if(a&&t){var l=s&&typeof s.as=="string"?s.as:"script",i='link[rel="modulepreload"][as="'+aa(l)+'"][href="'+aa(t)+'"]',o=i;switch(l){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":o=Kn(t)}if(!ua.has(o)&&(t=C({rel:"modulepreload",href:t},s),ua.set(o,t),a.querySelector(i)===null)){switch(l){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":if(a.querySelector(Yi(o)))return}l=a.createElement("link"),Ns(l,"link",t),ps(l),a.head.appendChild(l)}}}function Bv(t,s,a){ll.S(t,s,a);var l=Yn;if(l&&t){var i=fn(l).hoistableStyles,o=Xn(t);s=s||"default";var m=i.get(o);if(!m){var g={loading:0,preload:null};if(m=l.querySelector(Qi(o)))g.loading=5;else{t=C({rel:"stylesheet",href:t,"data-precedence":s},a),(a=ua.get(o))&&cu(t,a);var k=m=l.createElement("link");ps(k),Ns(k,"link",t),k._p=new Promise(function(J,le){k.onload=J,k.onerror=le}),k.addEventListener("load",function(){g.loading|=1}),k.addEventListener("error",function(){g.loading|=2}),g.loading|=4,_c(m,s,l)}m={type:"stylesheet",instance:m,count:1,state:g},i.set(o,m)}}}function Hv(t,s){ll.X(t,s);var a=Yn;if(a&&t){var l=fn(a).hoistableScripts,i=Kn(t),o=l.get(i);o||(o=a.querySelector(Yi(i)),o||(t=C({src:t,async:!0},s),(s=ua.get(i))&&ou(t,s),o=a.createElement("script"),ps(o),Ns(o,"link",t),a.head.appendChild(o)),o={type:"script",instance:o,count:1,state:null},l.set(i,o))}}function qv(t,s){ll.M(t,s);var a=Yn;if(a&&t){var l=fn(a).hoistableScripts,i=Kn(t),o=l.get(i);o||(o=a.querySelector(Yi(i)),o||(t=C({src:t,async:!0,type:"module"},s),(s=ua.get(i))&&ou(t,s),o=a.createElement("script"),ps(o),Ns(o,"link",t),a.head.appendChild(o)),o={type:"script",instance:o,count:1,state:null},l.set(i,o))}}function Nf(t,s,a,l){var i=(i=de.current)?wc(i):null;if(!i)throw Error(d(446));switch(t){case"meta":case"title":return null;case"style":return typeof a.precedence=="string"&&typeof a.href=="string"?(s=Xn(a.href),a=fn(i).hoistableStyles,l=a.get(s),l||(l={type:"style",instance:null,count:0,state:null},a.set(s,l)),l):{type:"void",instance:null,count:0,state:null};case"link":if(a.rel==="stylesheet"&&typeof a.href=="string"&&typeof a.precedence=="string"){t=Xn(a.href);var o=fn(i).hoistableStyles,m=o.get(t);if(m||(i=i.ownerDocument||i,m={type:"stylesheet",instance:null,count:0,state:{loading:0,preload:null}},o.set(t,m),(o=i.querySelector(Qi(t)))&&!o._p&&(m.instance=o,m.state.loading=5),ua.has(t)||(a={rel:"preload",as:"style",href:a.href,crossOrigin:a.crossOrigin,integrity:a.integrity,media:a.media,hrefLang:a.hrefLang,referrerPolicy:a.referrerPolicy},ua.set(t,a),o||Gv(i,t,a,m.state))),s&&l===null)throw Error(d(528,""));return m}if(s&&l!==null)throw Error(d(529,""));return null;case"script":return s=a.async,a=a.src,typeof a=="string"&&s&&typeof s!="function"&&typeof s!="symbol"?(s=Kn(a),a=fn(i).hoistableScripts,l=a.get(s),l||(l={type:"script",instance:null,count:0,state:null},a.set(s,l)),l):{type:"void",instance:null,count:0,state:null};default:throw Error(d(444,t))}}function Xn(t){return'href="'+aa(t)+'"'}function Qi(t){return'link[rel="stylesheet"]['+t+"]"}function wf(t){return C({},t,{"data-precedence":t.precedence,precedence:null})}function Gv(t,s,a,l){t.querySelector('link[rel="preload"][as="style"]['+s+"]")?l.loading=1:(s=t.createElement("link"),l.preload=s,s.addEventListener("load",function(){return l.loading|=1}),s.addEventListener("error",function(){return l.loading|=2}),Ns(s,"link",a),ps(s),t.head.appendChild(s))}function Kn(t){return'[src="'+aa(t)+'"]'}function Yi(t){return"script[async]"+t}function _f(t,s,a){if(s.count++,s.instance===null)switch(s.type){case"style":var l=t.querySelector('style[data-href~="'+aa(a.href)+'"]');if(l)return s.instance=l,ps(l),l;var i=C({},a,{"data-href":a.href,"data-precedence":a.precedence,href:null,precedence:null});return l=(t.ownerDocument||t).createElement("style"),ps(l),Ns(l,"style",i),_c(l,a.precedence,t),s.instance=l;case"stylesheet":i=Xn(a.href);var o=t.querySelector(Qi(i));if(o)return s.state.loading|=4,s.instance=o,ps(o),o;l=wf(a),(i=ua.get(i))&&cu(l,i),o=(t.ownerDocument||t).createElement("link"),ps(o);var m=o;return m._p=new Promise(function(g,k){m.onload=g,m.onerror=k}),Ns(o,"link",l),s.state.loading|=4,_c(o,a.precedence,t),s.instance=o;case"script":return o=Kn(a.src),(i=t.querySelector(Yi(o)))?(s.instance=i,ps(i),i):(l=a,(i=ua.get(o))&&(l=C({},a),ou(l,i)),t=t.ownerDocument||t,i=t.createElement("script"),ps(i),Ns(i,"link",l),t.head.appendChild(i),s.instance=i);case"void":return null;default:throw Error(d(443,s.type))}else s.type==="stylesheet"&&(s.state.loading&4)===0&&(l=s.instance,s.state.loading|=4,_c(l,a.precedence,t));return s.instance}function _c(t,s,a){for(var l=a.querySelectorAll('link[rel="stylesheet"][data-precedence],style[data-precedence]'),i=l.length?l[l.length-1]:null,o=i,m=0;m title"):null)}function Vv(t,s,a){if(a===1||s.itemProp!=null)return!1;switch(t){case"meta":case"title":return!0;case"style":if(typeof s.precedence!="string"||typeof s.href!="string"||s.href==="")break;return!0;case"link":if(typeof s.rel!="string"||typeof s.href!="string"||s.href===""||s.onLoad||s.onError)break;switch(s.rel){case"stylesheet":return t=s.disabled,typeof s.precedence=="string"&&t==null;default:return!0}case"script":if(s.async&&typeof s.async!="function"&&typeof s.async!="symbol"&&!s.onLoad&&!s.onError&&s.src&&typeof s.src=="string")return!0}return!1}function kf(t){return!(t.type==="stylesheet"&&(t.state.loading&3)===0)}function Fv(t,s,a,l){if(a.type==="stylesheet"&&(typeof l.media!="string"||matchMedia(l.media).matches!==!1)&&(a.state.loading&4)===0){if(a.instance===null){var i=Xn(l.href),o=s.querySelector(Qi(i));if(o){s=o._p,s!==null&&typeof s=="object"&&typeof s.then=="function"&&(t.count++,t=Cc.bind(t),s.then(t,t)),a.state.loading|=4,a.instance=o,ps(o);return}o=s.ownerDocument||s,l=wf(l),(i=ua.get(i))&&cu(l,i),o=o.createElement("link"),ps(o);var m=o;m._p=new Promise(function(g,k){m.onload=g,m.onerror=k}),Ns(o,"link",l),a.instance=o}t.stylesheets===null&&(t.stylesheets=new Map),t.stylesheets.set(a,s),(s=a.state.preload)&&(a.state.loading&3)===0&&(t.count++,a=Cc.bind(t),s.addEventListener("load",a),s.addEventListener("error",a))}}var du=0;function $v(t,s){return t.stylesheets&&t.count===0&&Tc(t,t.stylesheets),0du?50:800)+s);return t.unsuspend=a,function(){t.unsuspend=null,clearTimeout(l),clearTimeout(i)}}:null}function Cc(){if(this.count--,this.count===0&&(this.imgCount===0||!this.waitingForImages)){if(this.stylesheets)Tc(this,this.stylesheets);else if(this.unsuspend){var t=this.unsuspend;this.unsuspend=null,t()}}}var kc=null;function Tc(t,s){t.stylesheets=null,t.unsuspend!==null&&(t.count++,kc=new Map,s.forEach(Qv,t),kc=null,Cc.call(t))}function Qv(t,s){if(!(s.state.loading&4)){var a=kc.get(t);if(a)var l=a.get(null);else{a=new Map,kc.set(t,a);for(var i=t.querySelectorAll("link[data-precedence],style[data-precedence]"),o=0;o"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(r){console.error(r)}}return n(),Nu.exports=vN(),Nu.exports}var yN=bN();function Q(...n){return db(ub(n))}const Ye=u.forwardRef(({className:n,...r},c)=>e.jsx("div",{ref:c,className:Q("rounded-xl border bg-card text-card-foreground shadow",n),...r}));Ye.displayName="Card";const Nt=u.forwardRef(({className:n,...r},c)=>e.jsx("div",{ref:c,className:Q("flex flex-col space-y-1.5 p-6",n),...r}));Nt.displayName="CardHeader";const wt=u.forwardRef(({className:n,...r},c)=>e.jsx("div",{ref:c,className:Q("font-semibold leading-none tracking-tight",n),...r}));wt.displayName="CardTitle";const ns=u.forwardRef(({className:n,...r},c)=>e.jsx("div",{ref:c,className:Q("text-sm text-muted-foreground",n),...r}));ns.displayName="CardDescription";const kt=u.forwardRef(({className:n,...r},c)=>e.jsx("div",{ref:c,className:Q("p-6 pt-0",n),...r}));kt.displayName="CardContent";const mg=u.forwardRef(({className:n,...r},c)=>e.jsx("div",{ref:c,className:Q("flex items-center p-6 pt-0",n),...r}));mg.displayName="CardFooter";const La=xb,wa=u.forwardRef(({className:n,...r},c)=>e.jsx(gp,{ref:c,className:Q("inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",n),...r}));wa.displayName=gp.displayName;const it=u.forwardRef(({className:n,...r},c)=>e.jsx(jp,{ref:c,className:Q("inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium ring-offset-background transition-all duration-300 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow",n),...r}));it.displayName=jp.displayName;const zt=u.forwardRef(({className:n,...r},c)=>e.jsx(vp,{ref:c,className:Q("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 data-[state=active]:animate-in data-[state=active]:fade-in data-[state=active]:duration-300",n),...r}));zt.displayName=vp.displayName;const st=u.forwardRef(({className:n,children:r,viewportRef:c,...d},h)=>e.jsxs(bp,{ref:h,className:Q("relative overflow-hidden",n),...d,children:[e.jsx(fb,{ref:c,className:"h-full w-full rounded-[inherit]",children:r}),e.jsx(Mu,{}),e.jsx(Mu,{orientation:"horizontal"}),e.jsx(pb,{})]}));st.displayName=bp.displayName;const Mu=u.forwardRef(({className:n,orientation:r="vertical",...c},d)=>e.jsx(yp,{ref:d,orientation:r,className:Q("flex touch-none select-none transition-colors",r==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",r==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",n),...c,children:e.jsx(gb,{className:"relative flex-1 rounded-full bg-border"})}));Mu.displayName=yp.displayName;function hg({className:n,...r}){return e.jsx("div",{className:Q("animate-pulse rounded-md bg-primary/10",n),...r})}const yr=u.forwardRef(({className:n,value:r,...c},d)=>e.jsx(Np,{ref:d,className:Q("relative h-2 w-full overflow-hidden rounded-full bg-primary/20",n),...c,children:e.jsx(jb,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(r||0)}%)`}})}));yr.displayName=Np.displayName;const NN={light:"",dark:".dark"},xg=u.createContext(null);function fg(){const n=u.useContext(xg);if(!n)throw new Error("useChart must be used within a ");return n}const Jn=u.forwardRef(({id:n,className:r,children:c,config:d,...h},x)=>{const f=u.useId(),j=`chart-${n||f.replace(/:/g,"")}`;return e.jsx(xg.Provider,{value:{config:d},children:e.jsxs("div",{"data-chart":j,ref:x,className:Q("flex aspect-video justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-none [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-sector]:outline-none [&_.recharts-surface]:outline-none",r),...h,children:[e.jsx(wN,{id:j,config:d}),e.jsx(Mb,{children:c})]})})});Jn.displayName="Chart";const wN=({id:n,config:r})=>{const c=Object.entries(r).filter(([,d])=>d.theme||d.color);return c.length?e.jsx("style",{dangerouslySetInnerHTML:{__html:Object.entries(NN).map(([d,h])=>` ${h} [data-chart=${n}] { ${c.map(([x,f])=>{const j=f.theme?.[d]||f.color;return j?` --color-${x}: ${j};`:null}).join(` `)} } `).join(` `)}}):null},tr=Db,In=u.forwardRef(({active:n,payload:r,className:c,indicator:d="dot",hideLabel:h=!1,hideIndicator:x=!1,label:f,labelFormatter:j,labelClassName:p,formatter:N,color:v,nameKey:C,labelKey:S},w)=>{const{config:L}=fg(),F=u.useMemo(()=>{if(h||!r?.length)return null;const[O]=r,K=`${S||O?.dataKey||O?.name||"value"}`,H=Du(L,O,K),z=!S&&typeof f=="string"?L[f]?.label||f:H?.label;return j?e.jsx("div",{className:Q("font-medium",p),children:j(z,r)}):z?e.jsx("div",{className:Q("font-medium",p),children:z}):null},[f,j,r,h,p,L,S]);if(!n||!r?.length)return null;const B=r.length===1&&d!=="dot";return e.jsxs("div",{ref:w,className:Q("grid min-w-[8rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl",c),children:[B?null:F,e.jsx("div",{className:"grid gap-1.5",children:r.filter(O=>O.type!=="none").map((O,K)=>{const H=`${C||O.name||O.dataKey||"value"}`,z=Du(L,O,H),V=v||O.payload.fill||O.color;return e.jsx("div",{className:Q("flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground",d==="dot"&&"items-center"),children:N&&O?.value!==void 0&&O.name?N(O.value,O.name,O,K,O.payload):e.jsxs(e.Fragment,{children:[z?.icon?e.jsx(z.icon,{}):!x&&e.jsx("div",{className:Q("shrink-0 rounded-[2px] border-[--color-border] bg-[--color-bg]",{"h-2.5 w-2.5":d==="dot","w-1":d==="line","w-0 border-[1.5px] border-dashed bg-transparent":d==="dashed","my-0.5":B&&d==="dashed"}),style:{"--color-bg":V,"--color-border":V}}),e.jsxs("div",{className:Q("flex flex-1 justify-between leading-none",B?"items-end":"items-center"),children:[e.jsxs("div",{className:"grid gap-1.5",children:[B?F:null,e.jsx("span",{className:"text-muted-foreground",children:z?.label||O.name})]}),O.value&&e.jsx("span",{className:"font-mono font-medium tabular-nums text-foreground",children:O.value.toLocaleString()})]})]})},O.dataKey)})})]})});In.displayName="ChartTooltip";const _N=Ob,pg=u.forwardRef(({className:n,hideIcon:r=!1,payload:c,verticalAlign:d="bottom",nameKey:h},x)=>{const{config:f}=fg();return c?.length?e.jsx("div",{ref:x,className:Q("flex items-center justify-center gap-4",d==="top"?"pb-3":"pt-3",n),children:c.filter(j=>j.type!=="none").map(j=>{const p=`${h||j.dataKey||"value"}`,N=Du(f,j,p);return e.jsxs("div",{className:Q("flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground"),children:[N?.icon&&!r?e.jsx(N.icon,{}):e.jsx("div",{className:"h-2 w-2 shrink-0 rounded-[2px]",style:{backgroundColor:j.color}}),N?.label]},j.value)})}):null});pg.displayName="ChartLegend";function Du(n,r,c){if(typeof r!="object"||r===null)return;const d="payload"in r&&typeof r.payload=="object"&&r.payload!==null?r.payload:void 0;let h=c;return c in r&&typeof r[c]=="string"?h=r[c]:d&&c in d&&typeof d[c]=="string"&&(h=d[c]),h in n?n[h]:n[c]}const hr=si("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground shadow hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",outline:"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2",sm:"h-8 rounded-md px-3 text-xs",lg:"h-10 rounded-md px-8",icon:"h-9 w-9"}},defaultVariants:{variant:"default",size:"default"}}),b=u.forwardRef(({className:n,variant:r,size:c,asChild:d=!1,...h},x)=>{const f=d?qb:"button";return e.jsx(f,{className:Q(hr({variant:r,size:c,className:n})),ref:x,...h})});b.displayName="Button";const SN=si("inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function Je({className:n,variant:r,...c}){return e.jsx("div",{className:Q(SN({variant:r}),n),...c})}const CN=5,kN=5e3;let Su=0;function TN(){return Su=(Su+1)%Number.MAX_SAFE_INTEGER,Su.toString()}const Cu=new Map,If=n=>{if(Cu.has(n))return;const r=setTimeout(()=>{Cu.delete(n),cr({type:"REMOVE_TOAST",toastId:n})},kN);Cu.set(n,r)},EN=(n,r)=>{switch(r.type){case"ADD_TOAST":return{...n,toasts:[r.toast,...n.toasts].slice(0,CN)};case"UPDATE_TOAST":return{...n,toasts:n.toasts.map(c=>c.id===r.toast.id?{...c,...r.toast}:c)};case"DISMISS_TOAST":{const{toastId:c}=r;return c?If(c):n.toasts.forEach(d=>{If(d.id)}),{...n,toasts:n.toasts.map(d=>d.id===c||c===void 0?{...d,open:!1}:d)}}case"REMOVE_TOAST":return r.toastId===void 0?{...n,toasts:[]}:{...n,toasts:n.toasts.filter(c=>c.id!==r.toastId)}}},Yc=[];let Xc={toasts:[]};function cr(n){Xc=EN(Xc,n),Yc.forEach(r=>{r(Xc)})}function zN({...n}){const r=TN(),c=h=>cr({type:"UPDATE_TOAST",toast:{...h,id:r}}),d=()=>cr({type:"DISMISS_TOAST",toastId:r});return cr({type:"ADD_TOAST",toast:{...n,id:r,open:!0,onOpenChange:h=>{h||d()}}}),{id:r,dismiss:d,update:c}}function Xt(){const[n,r]=u.useState(Xc);return u.useEffect(()=>(Yc.push(r),()=>{const c=Yc.indexOf(r);c>-1&&Yc.splice(c,1)}),[n]),{...n,toast:zN,dismiss:c=>cr({type:"DISMISS_TOAST",toastId:c})}}const AN=n=>{const r=[];for(let c=0;c{try{w(!0);const T=await Lc.get("https://v1.hitokoto.cn/?c=a&c=b&c=c&c=d&c=h&c=i&c=k");C({hitokoto:T.data.hitokoto,from:T.data.from||T.data.from_who||"未知"})}catch(T){console.error("获取一言失败:",T),C({hitokoto:"人生就像一盒巧克力,你永远不知道下一颗是什么味道。",from:"阿甘正传"})}finally{w(!1)}},[]),z=u.useCallback(async()=>{try{const T=localStorage.getItem("access-token"),te=await Lc.get("/api/webui/system/status",{headers:{Authorization:`Bearer ${T}`}});F(te.data)}catch(T){console.error("获取机器人状态失败:",T),F(null)}},[]),V=async()=>{if(!B)try{O(!0);const T=localStorage.getItem("access-token");await Lc.post("/api/webui/system/restart",{},{headers:{Authorization:`Bearer ${T}`}}),K({title:"重启中",description:"麦麦正在重启,请稍候..."}),setTimeout(()=>{z(),O(!1)},3e3)}catch(T){console.error("重启失败:",T),K({title:"重启失败",description:"无法重启麦麦,请检查控制台",variant:"destructive"}),O(!1)}},Y=u.useCallback(async()=>{try{const T=localStorage.getItem("access-token"),te=await Lc.get(`/api/webui/statistics/dashboard?hours=${f}`,{headers:{Authorization:`Bearer ${T}`}});r(te.data),d(!1),x(100)}catch(T){console.error("Failed to fetch dashboard data:",T),d(!1),x(100)}},[f]);if(u.useEffect(()=>{if(!c)return;x(0);const T=setTimeout(()=>x(15),200),te=setTimeout(()=>x(30),800),_=setTimeout(()=>x(45),2e3),me=setTimeout(()=>x(60),4e3),oe=setTimeout(()=>x(75),6500),ae=setTimeout(()=>x(85),9e3),xe=setTimeout(()=>x(92),11e3);return()=>{clearTimeout(T),clearTimeout(te),clearTimeout(_),clearTimeout(me),clearTimeout(oe),clearTimeout(ae),clearTimeout(xe)}},[c]),u.useEffect(()=>{Y(),H(),z()},[Y,H,z]),u.useEffect(()=>{if(!p)return;const T=setInterval(()=>{Y(),z()},3e4);return()=>clearInterval(T)},[p,Y,z]),c||!n)return e.jsx("div",{className:"flex items-center justify-center h-[calc(100vh-200px)]",children:e.jsxs("div",{className:"text-center space-y-6 w-full max-w-md px-4",children:[e.jsx(ws,{className:"h-12 w-12 animate-spin mx-auto text-primary"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-lg font-medium",children:"加载统计数据中..."}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"正在获取麦麦运行数据"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(yr,{value:h,className:"h-2"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[h,"%"]})]})]})});const{summary:E,model_stats:R=[],hourly_data:ne=[],daily_data:fe=[],recent_activity:Ce=[]}=n,we=E??{total_requests:0,total_cost:0,total_tokens:0,online_time:0,total_messages:0,total_replies:0,avg_response_time:0,cost_per_hour:0,tokens_per_hour:0},pe=T=>{const te=Math.floor(T/3600),_=Math.floor(T%3600/60);return`${te}小时${_}分钟`},Ne=T=>new Date(T).toLocaleString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),be=AN(R.length),A=R.map((T,te)=>({name:T.model_name,value:T.request_count,fill:be[te]})),X={requests:{label:"请求数",color:"hsl(var(--chart-1))"},cost:{label:"花费(¥)",color:"hsl(var(--chart-2))"},tokens:{label:"Tokens",color:"hsl(var(--chart-3))"}};return e.jsx(st,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"实时监控面板"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"麦麦运行状态和统计数据一览"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(La,{value:f.toString(),onValueChange:T=>j(Number(T)),children:e.jsxs(wa,{className:"grid grid-cols-3 w-full sm:w-auto",children:[e.jsx(it,{value:"24",children:"24小时"}),e.jsx(it,{value:"168",children:"7天"}),e.jsx(it,{value:"720",children:"30天"})]})}),e.jsxs(b,{variant:p?"default":"outline",size:"sm",onClick:()=>N(!p),className:"gap-2",children:[e.jsx(ws,{className:`h-4 w-4 ${p?"animate-spin":""}`}),e.jsx("span",{className:"hidden sm:inline",children:"自动刷新"})]}),e.jsx(b,{variant:"outline",size:"sm",onClick:Y,children:e.jsx(ws,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"flex items-center gap-3 px-4 py-2 rounded-lg border border-dashed border-muted-foreground/30 bg-muted/20",children:[S?e.jsx(hg,{className:"h-5 flex-1"}):v?e.jsxs("p",{className:"flex-1 text-sm text-muted-foreground italic truncate",children:['"',v.hitokoto,'" —— ',v.from]}):null,e.jsx(b,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:H,disabled:S,children:e.jsx(ws,{className:`h-3.5 w-3.5 ${S?"animate-spin":""}`})})]}),e.jsxs("div",{className:"grid gap-4 grid-cols-1 lg:grid-cols-3",children:[e.jsxs(Ye,{className:"lg:col-span-1",children:[e.jsx(Nt,{className:"pb-3",children:e.jsxs(wt,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(gr,{className:"h-4 w-4"}),"麦麦状态"]})}),e.jsx(kt,{children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"flex items-center gap-2",children:L?.running?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-3 w-3 rounded-full bg-green-500 animate-pulse"}),e.jsxs(Je,{variant:"outline",className:"text-green-600 border-green-300 bg-green-50",children:[e.jsx(ha,{className:"h-3 w-3 mr-1"}),"运行中"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-3 w-3 rounded-full bg-red-500"}),e.jsxs(Je,{variant:"outline",className:"text-red-600 border-red-300 bg-red-50",children:[e.jsx(Oa,{className:"h-3 w-3 mr-1"}),"已停止"]})]})}),L&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:[e.jsxs("span",{children:["v",L.version]}),e.jsx("span",{className:"mx-2",children:"|"}),e.jsxs("span",{children:["运行 ",pe(L.uptime)]})]})]})})]}),e.jsxs(Ye,{className:"lg:col-span-2",children:[e.jsx(Nt,{className:"pb-3",children:e.jsxs(wt,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(ln,{className:"h-4 w-4"}),"快速操作"]})}),e.jsx(kt,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(b,{variant:"outline",size:"sm",onClick:V,disabled:B,className:"gap-2",children:[e.jsx(Kc,{className:`h-4 w-4 ${B?"animate-spin":""}`}),B?"重启中...":"重启麦麦"]}),e.jsx(b,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs($c,{to:"/logs",children:[e.jsx(Da,{className:"h-4 w-4"}),"查看日志"]})}),e.jsx(b,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs($c,{to:"/plugins",children:[e.jsx(ly,{className:"h-4 w-4"}),"插件管理"]})}),e.jsx(b,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs($c,{to:"/settings",children:[e.jsx(ai,{className:"h-4 w-4"}),"系统设置"]})})]})})]})]}),e.jsxs("div",{className:"grid gap-4 grid-cols-1 xs:grid-cols-2 lg:grid-cols-4",children:[e.jsxs(Ye,{children:[e.jsxs(Nt,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(wt,{className:"text-sm font-medium",children:"总请求数"}),e.jsx(ny,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(kt,{children:[e.jsx("div",{className:"text-2xl font-bold",children:we.total_requests.toLocaleString()}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["最近",f<48?f+"小时":Math.floor(f/24)+"天"]})]})]}),e.jsxs(Ye,{children:[e.jsxs(Nt,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(wt,{className:"text-sm font-medium",children:"总花费"}),e.jsx(iy,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(kt,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:["¥",we.total_cost.toFixed(2)]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:we.cost_per_hour>0?`¥${we.cost_per_hour.toFixed(2)}/小时`:"暂无数据"})]})]}),e.jsxs(Ye,{children:[e.jsxs(Nt,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(wt,{className:"text-sm font-medium",children:"Token消耗"}),e.jsx(Zc,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(kt,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[(we.total_tokens/1e3).toFixed(1),"K"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:we.tokens_per_hour>0?`${(we.tokens_per_hour/1e3).toFixed(1)}K/小时`:"暂无数据"})]})]}),e.jsxs(Ye,{children:[e.jsxs(Nt,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(wt,{className:"text-sm font-medium",children:"平均响应"}),e.jsx(ln,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(kt,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[we.avg_response_time.toFixed(2),"s"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"API平均耗时"})]})]})]}),e.jsxs("div",{className:"grid gap-4 grid-cols-1 sm:grid-cols-3",children:[e.jsxs(Ye,{children:[e.jsxs(Nt,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(wt,{className:"text-sm font-medium",children:"在线时长"}),e.jsx(Wn,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(kt,{children:e.jsx("div",{className:"text-xl font-bold",children:pe(we.online_time)})})]}),e.jsxs(Ye,{children:[e.jsxs(Nt,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(wt,{className:"text-sm font-medium",children:"消息处理"}),e.jsx(cn,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(kt,{children:[e.jsx("div",{className:"text-xl font-bold",children:we.total_messages.toLocaleString()}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["回复 ",we.total_replies.toLocaleString()," 条"]})]})]}),e.jsxs(Ye,{children:[e.jsxs(Nt,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(wt,{className:"text-sm font-medium",children:"成本效率"}),e.jsx(ry,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(kt,{children:[e.jsx("div",{className:"text-xl font-bold",children:we.total_messages>0?`¥${(we.total_cost/we.total_messages*100).toFixed(2)}`:"¥0.00"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"每100条消息"})]})]})]}),e.jsxs(La,{defaultValue:"trends",className:"space-y-4",children:[e.jsxs(wa,{className:"grid w-full grid-cols-2 sm:grid-cols-4",children:[e.jsx(it,{value:"trends",children:"趋势"}),e.jsx(it,{value:"models",children:"模型"}),e.jsx(it,{value:"activity",children:"活动"}),e.jsx(it,{value:"daily",children:"日统计"})]}),e.jsxs(zt,{value:"trends",className:"space-y-4",children:[e.jsxs(Ye,{children:[e.jsxs(Nt,{children:[e.jsx(wt,{children:"请求趋势"}),e.jsxs(ns,{children:["最近",f,"小时的请求量变化"]})]}),e.jsx(kt,{children:e.jsx(Jn,{config:X,className:"h-[300px] sm:h-[400px] w-full aspect-auto",children:e.jsxs(Rb,{data:ne,children:[e.jsx(Uc,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(Bc,{dataKey:"timestamp",tickFormatter:T=>Ne(T),angle:-45,textAnchor:"end",height:60,stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Wi,{stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(tr,{content:e.jsx(In,{labelFormatter:T=>Ne(T)})}),e.jsx(Lb,{type:"monotone",dataKey:"requests",stroke:"var(--color-requests)",strokeWidth:2})]})})})]}),e.jsxs("div",{className:"grid gap-4 grid-cols-1 lg:grid-cols-2",children:[e.jsxs(Ye,{children:[e.jsxs(Nt,{children:[e.jsx(wt,{children:"花费趋势"}),e.jsx(ns,{children:"API调用成本变化"})]}),e.jsx(kt,{children:e.jsx(Jn,{config:X,className:"h-[250px] sm:h-[300px] w-full aspect-auto",children:e.jsxs(vu,{data:ne,children:[e.jsx(Uc,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(Bc,{dataKey:"timestamp",tickFormatter:T=>Ne(T),angle:-45,textAnchor:"end",height:60,stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Wi,{stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(tr,{content:e.jsx(In,{labelFormatter:T=>Ne(T)})}),e.jsx(Hc,{dataKey:"cost",fill:"var(--color-cost)"})]})})})]}),e.jsxs(Ye,{children:[e.jsxs(Nt,{children:[e.jsx(wt,{children:"Token消耗"}),e.jsx(ns,{children:"Token使用量变化"})]}),e.jsx(kt,{children:e.jsx(Jn,{config:X,className:"h-[250px] sm:h-[300px] w-full aspect-auto",children:e.jsxs(vu,{data:ne,children:[e.jsx(Uc,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(Bc,{dataKey:"timestamp",tickFormatter:T=>Ne(T),angle:-45,textAnchor:"end",height:60,stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Wi,{stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(tr,{content:e.jsx(In,{labelFormatter:T=>Ne(T)})}),e.jsx(Hc,{dataKey:"tokens",fill:"var(--color-tokens)"})]})})})]})]})]}),e.jsx(zt,{value:"models",className:"space-y-4",children:e.jsxs("div",{className:"grid gap-4 grid-cols-1 lg:grid-cols-2",children:[e.jsxs(Ye,{children:[e.jsxs(Nt,{children:[e.jsx(wt,{children:"模型请求分布"}),e.jsxs(ns,{children:["各模型使用占比 (共 ",R.length," 个模型)"]})]}),e.jsx(kt,{children:e.jsx(Jn,{config:Object.fromEntries(R.map((T,te)=>[T.model_name,{label:T.model_name,color:be[te]}])),className:"h-[300px] sm:h-[400px] w-full aspect-auto",children:e.jsxs(Ub,{children:[e.jsx(tr,{content:e.jsx(In,{})}),e.jsx(Bb,{data:A,cx:"50%",cy:"50%",labelLine:!1,label:({name:T,percent:te})=>te&&te<.05?"":`${T} ${te?(te*100).toFixed(0):0}%`,outerRadius:100,dataKey:"value",children:A.map((T,te)=>e.jsx(Hb,{fill:T.fill},`cell-${te}`))})]})})})]}),e.jsxs(Ye,{children:[e.jsxs(Nt,{children:[e.jsx(wt,{children:"模型详细统计"}),e.jsx(ns,{children:"请求数、花费和性能"})]}),e.jsx(kt,{children:e.jsx(st,{className:"h-[300px] sm:h-[400px]",children:e.jsx("div",{className:"space-y-3",children:R.map((T,te)=>e.jsxs("div",{className:"p-4 rounded-lg border bg-card hover:bg-accent/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h4",{className:"font-semibold text-sm truncate flex-1 min-w-0",children:T.model_name}),e.jsx("div",{className:"w-3 h-3 rounded-full ml-2 flex-shrink-0",style:{backgroundColor:`hsl(var(--chart-${te%5+1}))`}})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"请求数:"}),e.jsx("span",{className:"ml-1 font-medium",children:T.request_count.toLocaleString()})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"花费:"}),e.jsxs("span",{className:"ml-1 font-medium",children:["¥",T.total_cost.toFixed(2)]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Tokens:"}),e.jsxs("span",{className:"ml-1 font-medium",children:[(T.total_tokens/1e3).toFixed(1),"K"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"平均耗时:"}),e.jsxs("span",{className:"ml-1 font-medium",children:[T.avg_response_time.toFixed(2),"s"]})]})]})]},te))})})})]})]})}),e.jsx(zt,{value:"activity",children:e.jsxs(Ye,{children:[e.jsxs(Nt,{children:[e.jsx(wt,{children:"最近活动"}),e.jsx(ns,{children:"最新的API调用记录"})]}),e.jsx(kt,{children:e.jsx(st,{className:"h-[400px] sm:h-[500px]",children:e.jsx("div",{className:"space-y-2",children:Ce.map((T,te)=>e.jsxs("div",{className:"p-3 sm:p-4 rounded-lg border bg-card hover:bg-accent/50 transition-colors",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-2 mb-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium text-sm truncate",children:T.model}),e.jsx("div",{className:"text-xs text-muted-foreground",children:T.request_type})]}),e.jsx("div",{className:"text-xs text-muted-foreground flex-shrink-0",children:Ne(T.timestamp)})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2 text-xs",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Tokens:"}),e.jsx("span",{className:"ml-1",children:T.tokens})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"花费:"}),e.jsxs("span",{className:"ml-1",children:["¥",T.cost.toFixed(4)]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"耗时:"}),e.jsxs("span",{className:"ml-1",children:[T.time_cost.toFixed(2),"s"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"状态:"}),e.jsx("span",{className:`ml-1 ${T.status==="success"?"text-green-600":"text-red-600"}`,children:T.status})]})]})]},te))})})})]})}),e.jsx(zt,{value:"daily",children:e.jsxs(Ye,{children:[e.jsxs(Nt,{children:[e.jsx(wt,{children:"每日统计"}),e.jsx(ns,{children:"最近7天的数据汇总"})]}),e.jsx(kt,{children:e.jsx(Jn,{config:{requests:{label:"请求数",color:"hsl(var(--chart-1))"},cost:{label:"花费(¥)",color:"hsl(var(--chart-2))"}},className:"h-[400px] sm:h-[500px] w-full aspect-auto",children:e.jsxs(vu,{data:fe,children:[e.jsx(Uc,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(Bc,{dataKey:"timestamp",tickFormatter:T=>{const te=new Date(T);return`${te.getMonth()+1}/${te.getDate()}`},stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Wi,{yAxisId:"left",stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Wi,{yAxisId:"right",orientation:"right",stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(tr,{content:e.jsx(In,{labelFormatter:T=>new Date(T).toLocaleDateString("zh-CN")})}),e.jsx(_N,{content:e.jsx(pg,{})}),e.jsx(Hc,{yAxisId:"left",dataKey:"requests",fill:"var(--color-requests)"}),e.jsx(Hc,{yAxisId:"right",dataKey:"cost",fill:"var(--color-cost)"})]})})})]})})]})]})})}const DN={theme:"system",setTheme:()=>null},gg=u.createContext(DN),Gu=()=>{const n=u.useContext(gg);if(n===void 0)throw new Error("useTheme must be used within a ThemeProvider");return n},ON=(n,r,c)=>{const d=document.documentElement.classList.contains("no-animations");if(!document.startViewTransition||d){r(n);return}const h=c.clientX,x=c.clientY,f=Math.hypot(Math.max(h,innerWidth-h),Math.max(x,innerHeight-x));document.startViewTransition(()=>{r(n)}).ready.then(()=>{document.documentElement.animate({clipPath:[`circle(0px at ${h}px ${x}px)`,`circle(${f}px at ${h}px ${x}px)`]},{duration:500,easing:"ease-in-out",pseudoElement:"::view-transition-new(root)"})})},jg=u.createContext(void 0),vg=()=>{const n=u.useContext(jg);if(n===void 0)throw new Error("useAnimation must be used within an AnimationProvider");return n},Qe=u.forwardRef(({className:n,...r},c)=>e.jsx(wp,{className:Q("peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",n),...r,ref:c,children:e.jsx(vb,{className:Q("pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0")})}));Qe.displayName=wp.displayName;const RN=si("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),y=u.forwardRef(({className:n,...r},c)=>e.jsx(Lp,{ref:c,className:Q(RN(),n),...r}));y.displayName=Lp.displayName;const ce=u.forwardRef(({className:n,type:r,...c},d)=>e.jsx("input",{type:r,className:Q("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",n),ref:d,...c}));ce.displayName="Input";const LN=[{id:"minLength",label:"长度至少 10 位",description:"Token 长度必须大于等于 10 个字符",validate:n=>n.length>=10},{id:"hasUppercase",label:"包含大写字母",description:"至少包含一个大写字母 (A-Z)",validate:n=>/[A-Z]/.test(n)},{id:"hasLowercase",label:"包含小写字母",description:"至少包含一个小写字母 (a-z)",validate:n=>/[a-z]/.test(n)},{id:"hasSpecialChar",label:"包含特殊符号",description:"至少包含一个特殊符号 (!@#$%^&*()_+-=[]{}|;:,.<>?/)",validate:n=>/[!@#$%^&*()_+\-=[\]{}|;:,.<>?/]/.test(n)}];function UN(n){const r=LN.map(d=>({id:d.id,label:d.label,description:d.description,passed:d.validate(n)}));return{isValid:r.every(d=>d.passed),rules:r}}const Vu="0.11.6 Beta",Fu="MaiBot Dashboard",BN=`${Fu} v${Vu}`,HN=(n="v")=>`${n}${Vu}`,Gs={THEME:"maibot-ui-theme",ACCENT_COLOR:"accent-color",ENABLE_ANIMATIONS:"maibot-animations",ENABLE_WAVES_BACKGROUND:"maibot-waves-background",LOG_CACHE_SIZE:"maibot-log-cache-size",LOG_AUTO_SCROLL:"maibot-log-auto-scroll",LOG_FONT_SIZE:"maibot-log-font-size",LOG_LINE_SPACING:"maibot-log-line-spacing",DATA_SYNC_INTERVAL:"maibot-data-sync-interval",WS_RECONNECT_INTERVAL:"maibot-ws-reconnect-interval",WS_MAX_RECONNECT_ATTEMPTS:"maibot-ws-max-reconnect-attempts",COMPLETED_TOURS:"maibot-completed-tours"},Aa={theme:"system",accentColor:"blue",enableAnimations:!0,enableWavesBackground:!0,logCacheSize:1e3,logAutoScroll:!0,logFontSize:"xs",logLineSpacing:4,dataSyncInterval:30,wsReconnectInterval:3e3,wsMaxReconnectAttempts:10};function Wt(n){const r=bg(n),c=localStorage.getItem(r);if(c===null)return Aa[n];const d=Aa[n];if(typeof d=="boolean")return c==="true";if(typeof d=="number"){const h=parseFloat(c);return isNaN(h)?d:h}return c}function Pn(n,r){const c=bg(n);localStorage.setItem(c,String(r)),window.dispatchEvent(new CustomEvent("maibot-settings-change",{detail:{key:n,value:r}}))}function qN(){return{theme:Wt("theme"),accentColor:Wt("accentColor"),enableAnimations:Wt("enableAnimations"),enableWavesBackground:Wt("enableWavesBackground"),logCacheSize:Wt("logCacheSize"),logAutoScroll:Wt("logAutoScroll"),logFontSize:Wt("logFontSize"),logLineSpacing:Wt("logLineSpacing"),dataSyncInterval:Wt("dataSyncInterval"),wsReconnectInterval:Wt("wsReconnectInterval"),wsMaxReconnectAttempts:Wt("wsMaxReconnectAttempts")}}function GN(){const n=qN(),r=localStorage.getItem(Gs.COMPLETED_TOURS),c=r?JSON.parse(r):[];return{...n,completedTours:c}}function VN(n){const r=[],c=[];for(const[d,h]of Object.entries(n)){if(d==="completedTours"){Array.isArray(h)?(localStorage.setItem(Gs.COMPLETED_TOURS,JSON.stringify(h)),r.push("completedTours")):c.push("completedTours");continue}if(d in Aa){const x=d,f=Aa[x];if(typeof h==typeof f){if(x==="theme"&&!["light","dark","system"].includes(h)){c.push(d);continue}if(x==="logFontSize"&&!["xs","sm","base"].includes(h)){c.push(d);continue}Pn(x,h),r.push(d)}else c.push(d)}else c.push(d)}return{success:r.length>0,imported:r,skipped:c}}function FN(){for(const n of Object.keys(Aa))Pn(n,Aa[n]);localStorage.removeItem(Gs.COMPLETED_TOURS),window.dispatchEvent(new CustomEvent("maibot-settings-reset"))}function $N(){const n=[],r=[],c=[];for(let d=0;dd.size-c.size),{used:n,items:localStorage.length,details:r}}function QN(n){if(n===0)return"0 B";const r=1024,c=["B","KB","MB"],d=Math.floor(Math.log(n)/Math.log(r));return parseFloat((n/Math.pow(r,d)).toFixed(2))+" "+c[d]}function bg(n){return{theme:Gs.THEME,accentColor:Gs.ACCENT_COLOR,enableAnimations:Gs.ENABLE_ANIMATIONS,enableWavesBackground:Gs.ENABLE_WAVES_BACKGROUND,logCacheSize:Gs.LOG_CACHE_SIZE,logAutoScroll:Gs.LOG_AUTO_SCROLL,logFontSize:Gs.LOG_FONT_SIZE,logLineSpacing:Gs.LOG_LINE_SPACING,dataSyncInterval:Gs.DATA_SYNC_INTERVAL,wsReconnectInterval:Gs.WS_RECONNECT_INTERVAL,wsMaxReconnectAttempts:Gs.WS_MAX_RECONNECT_ATTEMPTS}[n]}const Ma=u.forwardRef(({className:n,...r},c)=>e.jsxs(_p,{ref:c,className:Q("relative flex w-full touch-none select-none items-center",n),...r,children:[e.jsx(bb,{className:"relative h-1.5 w-full grow overflow-hidden rounded-full bg-primary/20",children:e.jsx(yb,{className:"absolute h-full bg-primary"})}),e.jsx(Nb,{className:"block h-4 w-4 rounded-full border border-primary/50 bg-background shadow transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50"})]}));Ma.displayName=_p.displayName;class YN{ws=null;reconnectTimeout=null;reconnectAttempts=0;heartbeatInterval=null;logCallbacks=new Set;connectionCallbacks=new Set;isConnected=!1;logCache=[];getMaxCacheSize(){return Wt("logCacheSize")}getMaxReconnectAttempts(){return Wt("wsMaxReconnectAttempts")}getReconnectInterval(){return Wt("wsReconnectInterval")}getWebSocketUrl(){{const r=window.location.protocol==="https:"?"wss:":"ws:",c=window.location.host;return`${r}//${c}/ws/logs`}}connect(){if(this.ws?.readyState===WebSocket.OPEN||this.ws?.readyState===WebSocket.CONNECTING)return;const r=this.getWebSocketUrl();try{this.ws=new WebSocket(r),this.ws.onopen=()=>{this.isConnected=!0,this.reconnectAttempts=0,this.notifyConnection(!0),this.startHeartbeat()},this.ws.onmessage=c=>{try{if(c.data==="pong")return;const d=JSON.parse(c.data);this.notifyLog(d)}catch(d){console.error("解析日志消息失败:",d)}},this.ws.onerror=c=>{console.error("❌ WebSocket 错误:",c),this.isConnected=!1,this.notifyConnection(!1)},this.ws.onclose=()=>{this.isConnected=!1,this.notifyConnection(!1),this.stopHeartbeat(),this.attemptReconnect()}}catch(c){console.error("创建 WebSocket 连接失败:",c),this.attemptReconnect()}}attemptReconnect(){const r=this.getMaxReconnectAttempts();if(this.reconnectAttempts>=r)return;this.reconnectAttempts+=1;const c=this.getReconnectInterval(),d=Math.min(c*this.reconnectAttempts,3e4);this.reconnectTimeout=window.setTimeout(()=>{this.connect()},d)}startHeartbeat(){this.heartbeatInterval=window.setInterval(()=>{this.ws?.readyState===WebSocket.OPEN&&this.ws.send("ping")},3e4)}stopHeartbeat(){this.heartbeatInterval!==null&&(clearInterval(this.heartbeatInterval),this.heartbeatInterval=null)}disconnect(){this.reconnectTimeout!==null&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=null),this.stopHeartbeat(),this.ws&&(this.ws.close(),this.ws=null),this.isConnected=!1,this.reconnectAttempts=0}onLog(r){return this.logCallbacks.add(r),()=>this.logCallbacks.delete(r)}onConnectionChange(r){return this.connectionCallbacks.add(r),r(this.isConnected),()=>this.connectionCallbacks.delete(r)}notifyLog(r){if(!this.logCache.some(d=>d.id===r.id)){this.logCache.push(r);const d=this.getMaxCacheSize();this.logCache.length>d&&(this.logCache=this.logCache.slice(-d)),this.logCallbacks.forEach(h=>{try{h(r)}catch(x){console.error("日志回调执行失败:",x)}})}}notifyConnection(r){this.connectionCallbacks.forEach(c=>{try{c(r)}catch(d){console.error("连接状态回调执行失败:",d)}})}getAllLogs(){return[...this.logCache]}clearLogs(){this.logCache=[]}getConnectionStatus(){return this.isConnected}}const an=new YN;typeof window<"u"&&an.connect();const Jt=Fb,$u=$b,XN=Gb,yg=u.forwardRef(({className:n,...r},c)=>e.jsx(Up,{ref:c,className:Q("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",n),...r}));yg.displayName=Up.displayName;const $t=u.forwardRef(({className:n,children:r,preventOutsideClose:c=!1,...d},h)=>e.jsxs(XN,{children:[e.jsx(yg,{}),e.jsxs(Bp,{ref:h,className:Q("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",n),onPointerDownOutside:c?x=>x.preventDefault():void 0,onInteractOutside:c?x=>x.preventDefault():void 0,...d,children:[r,e.jsxs(Vb,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[e.jsx(on,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));$t.displayName=Bp.displayName;const Qt=({className:n,...r})=>e.jsx("div",{className:Q("flex flex-col space-y-1.5 text-center sm:text-left",n),...r});Qt.displayName="DialogHeader";const xs=({className:n,...r})=>e.jsx("div",{className:Q("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",n),...r});xs.displayName="DialogFooter";const Yt=u.forwardRef(({className:n,...r},c)=>e.jsx(Hp,{ref:c,className:Q("text-lg font-semibold leading-none tracking-tight",n),...r}));Yt.displayName=Hp.displayName;const ds=u.forwardRef(({className:n,...r},c)=>e.jsx(qp,{ref:c,className:Q("text-sm text-muted-foreground",n),...r}));ds.displayName=qp.displayName;const bt=_b,es=Sb,KN=wb,Ng=u.forwardRef(({className:n,...r},c)=>e.jsx(Sp,{className:Q("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",n),...r,ref:c}));Ng.displayName=Sp.displayName;const dt=u.forwardRef(({className:n,...r},c)=>e.jsxs(KN,{children:[e.jsx(Ng,{}),e.jsx(Cp,{ref:c,className:Q("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",n),...r})]}));dt.displayName=Cp.displayName;const ut=({className:n,...r})=>e.jsx("div",{className:Q("flex flex-col space-y-2 text-center sm:text-left",n),...r});ut.displayName="AlertDialogHeader";const mt=({className:n,...r})=>e.jsx("div",{className:Q("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",n),...r});mt.displayName="AlertDialogFooter";const ht=u.forwardRef(({className:n,...r},c)=>e.jsx(kp,{ref:c,className:Q("text-lg font-semibold",n),...r}));ht.displayName=kp.displayName;const xt=u.forwardRef(({className:n,...r},c)=>e.jsx(Tp,{ref:c,className:Q("text-sm text-muted-foreground",n),...r}));xt.displayName=Tp.displayName;const ft=u.forwardRef(({className:n,...r},c)=>e.jsx(Ep,{ref:c,className:Q(hr(),n),...r}));ft.displayName=Ep.displayName;const pt=u.forwardRef(({className:n,...r},c)=>e.jsx(zp,{ref:c,className:Q(hr({variant:"outline"}),"mt-2 sm:mt-0",n),...r}));pt.displayName=zp.displayName;function ZN(){return e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsx("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"系统设置"}),e.jsx("p",{className:"text-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:"管理您的应用偏好设置"})]})}),e.jsxs(La,{defaultValue:"appearance",className:"w-full",children:[e.jsxs(wa,{className:"grid w-full grid-cols-2 sm:grid-cols-4 gap-0.5 sm:gap-1 h-auto p-1",children:[e.jsxs(it,{value:"appearance",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(cy,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"外观"})]}),e.jsxs(it,{value:"security",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(oy,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"安全"})]}),e.jsxs(it,{value:"other",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(ai,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"其他"})]}),e.jsxs(it,{value:"about",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(Ra,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"关于"})]})]}),e.jsxs(st,{className:"h-[calc(100vh-240px)] sm:h-[calc(100vh-280px)] mt-4 sm:mt-6",children:[e.jsx(zt,{value:"appearance",className:"mt-0",children:e.jsx(JN,{})}),e.jsx(zt,{value:"security",className:"mt-0",children:e.jsx(IN,{})}),e.jsx(zt,{value:"other",className:"mt-0",children:e.jsx(PN,{})}),e.jsx(zt,{value:"about",className:"mt-0",children:e.jsx(WN,{})})]})]})]})}function Wf(n){const r=document.documentElement,d={blue:{hsl:"221.2 83.2% 53.3%",darkHsl:"217.2 91.2% 59.8%",gradient:null},purple:{hsl:"271 91% 65%",darkHsl:"270 95% 75%",gradient:null},green:{hsl:"142 71% 45%",darkHsl:"142 76% 36%",gradient:null},orange:{hsl:"25 95% 53%",darkHsl:"20 90% 48%",gradient:null},pink:{hsl:"330 81% 60%",darkHsl:"330 85% 70%",gradient:null},red:{hsl:"0 84% 60%",darkHsl:"0 90% 70%",gradient:null},"gradient-sunset":{hsl:"15 95% 60%",darkHsl:"15 95% 65%",gradient:"linear-gradient(135deg, hsl(25 95% 53%) 0%, hsl(330 81% 60%) 100%)"},"gradient-ocean":{hsl:"200 90% 55%",darkHsl:"200 90% 60%",gradient:"linear-gradient(135deg, hsl(221.2 83.2% 53.3%) 0%, hsl(189 94% 43%) 100%)"},"gradient-forest":{hsl:"150 70% 45%",darkHsl:"150 75% 40%",gradient:"linear-gradient(135deg, hsl(142 71% 45%) 0%, hsl(158 64% 52%) 100%)"},"gradient-aurora":{hsl:"310 85% 65%",darkHsl:"310 90% 70%",gradient:"linear-gradient(135deg, hsl(271 91% 65%) 0%, hsl(330 81% 60%) 100%)"},"gradient-fire":{hsl:"15 95% 55%",darkHsl:"15 95% 60%",gradient:"linear-gradient(135deg, hsl(0 84% 60%) 0%, hsl(25 95% 53%) 100%)"},"gradient-twilight":{hsl:"250 90% 60%",darkHsl:"250 95% 65%",gradient:"linear-gradient(135deg, hsl(239 84% 67%) 0%, hsl(271 91% 65%) 100%)"}}[n];if(d)r.style.setProperty("--primary",d.hsl),d.gradient?(r.style.setProperty("--primary-gradient",d.gradient),r.classList.add("has-gradient")):(r.style.removeProperty("--primary-gradient"),r.classList.remove("has-gradient"));else if(n.startsWith("#")){const h=x=>{x=x.replace("#","");const f=parseInt(x.substring(0,2),16)/255,j=parseInt(x.substring(2,4),16)/255,p=parseInt(x.substring(4,6),16)/255,N=Math.max(f,j,p),v=Math.min(f,j,p);let C=0,S=0;const w=(N+v)/2;if(N!==v){const L=N-v;switch(S=w>.5?L/(2-N-v):L/(N+v),N){case f:C=((j-p)/L+(jlocalStorage.getItem("accent-color")||"blue");u.useEffect(()=>{const N=localStorage.getItem("accent-color")||"blue";Wf(N)},[]);const p=N=>{j(N),localStorage.setItem("accent-color",N),Wf(N)};return e.jsxs("div",{className:"space-y-6 sm:space-y-8",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"主题模式"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3 sm:gap-4",children:[e.jsx(ku,{value:"light",current:n,onChange:r,label:"浅色",description:"始终使用浅色主题"}),e.jsx(ku,{value:"dark",current:n,onChange:r,label:"深色",description:"始终使用深色主题"}),e.jsx(ku,{value:"system",current:n,onChange:r,label:"跟随系统",description:"根据系统设置自动切换"})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"主题色"}),e.jsxs("div",{className:"space-y-3 sm:space-y-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs sm:text-sm font-medium mb-2 sm:mb-3",children:"单色"}),e.jsxs("div",{className:"grid grid-cols-3 sm:grid-cols-6 gap-2 sm:gap-3",children:[e.jsx(ma,{value:"blue",current:f,onChange:p,label:"蓝色",colorClass:"bg-blue-500"}),e.jsx(ma,{value:"purple",current:f,onChange:p,label:"紫色",colorClass:"bg-purple-500"}),e.jsx(ma,{value:"green",current:f,onChange:p,label:"绿色",colorClass:"bg-green-500"}),e.jsx(ma,{value:"orange",current:f,onChange:p,label:"橙色",colorClass:"bg-orange-500"}),e.jsx(ma,{value:"pink",current:f,onChange:p,label:"粉色",colorClass:"bg-pink-500"}),e.jsx(ma,{value:"red",current:f,onChange:p,label:"红色",colorClass:"bg-red-500"})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs sm:text-sm font-medium mb-2 sm:mb-3",children:"渐变色"}),e.jsxs("div",{className:"grid grid-cols-3 sm:grid-cols-6 gap-2 sm:gap-3",children:[e.jsx(ma,{value:"gradient-sunset",current:f,onChange:p,label:"日落",colorClass:"bg-gradient-to-r from-orange-500 to-pink-500"}),e.jsx(ma,{value:"gradient-ocean",current:f,onChange:p,label:"海洋",colorClass:"bg-gradient-to-r from-blue-500 to-cyan-500"}),e.jsx(ma,{value:"gradient-forest",current:f,onChange:p,label:"森林",colorClass:"bg-gradient-to-r from-green-500 to-emerald-500"}),e.jsx(ma,{value:"gradient-aurora",current:f,onChange:p,label:"极光",colorClass:"bg-gradient-to-r from-purple-500 to-pink-500"}),e.jsx(ma,{value:"gradient-fire",current:f,onChange:p,label:"烈焰",colorClass:"bg-gradient-to-r from-red-500 to-orange-500"}),e.jsx(ma,{value:"gradient-twilight",current:f,onChange:p,label:"暮光",colorClass:"bg-gradient-to-r from-indigo-500 to-purple-500"})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs sm:text-sm font-medium mb-2 sm:mb-3",children:"自定义颜色"}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 sm:gap-4",children:[e.jsx("div",{className:"flex-1",children:e.jsx("input",{type:"color",value:f.startsWith("#")?f:"#3b82f6",onChange:N=>p(N.target.value),className:"h-10 sm:h-12 w-full rounded-lg border-2 border-border cursor-pointer",title:"选择自定义颜色"})}),e.jsx("div",{className:"flex-1",children:e.jsx(ce,{type:"text",value:f,onChange:N=>p(N.target.value),placeholder:"#3b82f6",className:"font-mono text-sm"})})]}),e.jsx("p",{className:"text-[10px] sm:text-xs text-muted-foreground mt-2",children:"点击色块选择颜色,或手动输入 HEX 颜色代码"})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"动画效果"}),e.jsxs("div",{className:"space-y-2 sm:space-y-3",children:[e.jsx("div",{className:"rounded-lg border bg-card p-3 sm:p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5 flex-1",children:[e.jsx(y,{htmlFor:"animations",className:"text-base font-medium cursor-pointer",children:"启用动画效果"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"关闭后将禁用所有过渡动画和特效,提升性能"})]}),e.jsx(Qe,{id:"animations",checked:c,onCheckedChange:d})]})}),e.jsx("div",{className:"rounded-lg border bg-card p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5 flex-1",children:[e.jsx(y,{htmlFor:"waves-background",className:"text-base font-medium cursor-pointer",children:"登录页波浪背景"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"关闭后登录页将使用纯色背景,适合低性能设备"})]}),e.jsx(Qe,{id:"waves-background",checked:h,onCheckedChange:x})]})})]})]})]})}function IN(){const n=fa(),[r,c]=u.useState(""),[d,h]=u.useState(""),[x,f]=u.useState(!1),[j,p]=u.useState(!1),[N,v]=u.useState(!1),[C,S]=u.useState(!1),[w,L]=u.useState(!1),[F,B]=u.useState(!1),[O,K]=u.useState(""),[H,z]=u.useState(!1),{toast:V}=Xt(),Y=u.useMemo(()=>UN(d),[d]),E=async pe=>{if(!r){V({title:"无法复制",description:"Token 存储在安全 Cookie 中,请重新生成以获取新 Token",variant:"destructive"});return}try{await navigator.clipboard.writeText(pe),L(!0),V({title:"复制成功",description:"Token 已复制到剪贴板"}),setTimeout(()=>L(!1),2e3)}catch{V({title:"复制失败",description:"请手动复制 Token",variant:"destructive"})}},R=async()=>{if(!d.trim()){V({title:"输入错误",description:"请输入新的 Token",variant:"destructive"});return}if(!Y.isValid){const pe=Y.rules.filter(Ne=>!Ne.passed).map(Ne=>Ne.label).join(", ");V({title:"格式错误",description:`Token 不符合要求: ${pe}`,variant:"destructive"});return}v(!0);try{const pe=await fetch("/api/webui/auth/update",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({new_token:d.trim()})}),Ne=await pe.json();pe.ok&&Ne.success?(h(""),c(d.trim()),V({title:"更新成功",description:"Access Token 已更新,即将跳转到登录页"}),setTimeout(()=>{n({to:"/auth"})},1500)):V({title:"更新失败",description:Ne.message||"无法更新 Token",variant:"destructive"})}catch(pe){console.error("更新 Token 错误:",pe),V({title:"更新失败",description:"连接服务器失败",variant:"destructive"})}finally{v(!1)}},ne=async()=>{S(!0);try{const pe=await fetch("/api/webui/auth/regenerate",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include"}),Ne=await pe.json();pe.ok&&Ne.success?(c(Ne.token),K(Ne.token),B(!0),z(!1),V({title:"生成成功",description:"新的 Access Token 已生成,请及时保存"})):V({title:"生成失败",description:Ne.message||"无法生成新 Token",variant:"destructive"})}catch(pe){console.error("生成 Token 错误:",pe),V({title:"生成失败",description:"连接服务器失败",variant:"destructive"})}finally{S(!1)}},fe=async()=>{try{await navigator.clipboard.writeText(O),z(!0),V({title:"复制成功",description:"Token 已复制到剪贴板"})}catch{V({title:"复制失败",description:"请手动复制 Token",variant:"destructive"})}},Ce=()=>{B(!1),setTimeout(()=>{K(""),z(!1)},300),setTimeout(()=>{n({to:"/auth"})},500)},we=pe=>{pe||Ce()};return e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsx(Jt,{open:F,onOpenChange:we,children:e.jsxs($t,{className:"sm:max-w-md",children:[e.jsxs(Qt,{children:[e.jsxs(Yt,{className:"flex items-center gap-2",children:[e.jsx(ya,{className:"h-5 w-5 text-yellow-500"}),"新的 Access Token"]}),e.jsx(ds,{children:"这是您的新 Token,请立即保存。关闭此窗口后将跳转到登录页面。"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border-2 border-primary/20 bg-primary/5 p-4",children:[e.jsx(y,{className:"text-xs text-muted-foreground mb-2 block",children:"您的新 Token (64位安全令牌)"}),e.jsx("div",{className:"font-mono text-sm break-all select-all bg-background p-3 rounded border",children:O})]}),e.jsx("div",{className:"rounded-lg border border-yellow-200 dark:border-yellow-900 bg-yellow-50 dark:bg-yellow-950/30 p-3",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ya,{className:"h-4 w-4 text-yellow-600 dark:text-yellow-500 flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm text-yellow-800 dark:text-yellow-300 space-y-1",children:[e.jsx("p",{className:"font-semibold",children:"重要提示"}),e.jsxs("ul",{className:"list-disc list-inside space-y-0.5 text-xs",children:[e.jsx("li",{children:"此 Token 仅显示一次,关闭后无法再查看"}),e.jsx("li",{children:"请立即复制并保存到安全的位置"}),e.jsx("li",{children:"关闭窗口后将自动跳转到登录页面"}),e.jsx("li",{children:"请使用新 Token 重新登录系统"})]})]})]})})]}),e.jsxs(xs,{className:"gap-2 sm:gap-0",children:[e.jsx(b,{variant:"outline",onClick:fe,className:"gap-2",children:H?e.jsxs(e.Fragment,{children:[e.jsx(Na,{className:"h-4 w-4 text-green-500"}),"已复制"]}):e.jsxs(e.Fragment,{children:[e.jsx(Jc,{className:"h-4 w-4"}),"复制 Token"]})}),e.jsx(b,{onClick:Ce,children:"我已保存,关闭"})]})]})}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"当前 Access Token"}),e.jsx("div",{className:"space-y-3 sm:space-y-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"current-token",className:"text-sm",children:"您的访问令牌"}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(ce,{id:"current-token",type:x?"text":"password",value:r||"••••••••••••••••••••••••••••••••",readOnly:!0,className:"pr-10 font-mono text-sm",placeholder:"Token 存储在安全 Cookie 中"}),e.jsx("button",{onClick:()=>{r?f(!x):V({title:"无法查看",description:'Token 存储在安全 Cookie 中,如需新 Token 请点击"重新生成"'})},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1.5 hover:bg-accent rounded",title:x?"隐藏":"显示",children:x?e.jsx(or,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Ws,{className:"h-4 w-4 text-muted-foreground"})})]}),e.jsxs("div",{className:"flex gap-2 w-full sm:w-auto",children:[e.jsx(b,{variant:"outline",size:"icon",onClick:()=>E(r),title:"复制到剪贴板",className:"flex-shrink-0",disabled:!r,children:w?e.jsx(Na,{className:"h-4 w-4 text-green-500"}):e.jsx(Jc,{className:"h-4 w-4"})}),e.jsxs(bt,{children:[e.jsx(es,{asChild:!0,children:e.jsxs(b,{variant:"outline",disabled:C,className:"gap-2 flex-1 sm:flex-none",children:[e.jsx(ws,{className:Q("h-4 w-4",C&&"animate-spin")}),e.jsx("span",{className:"hidden sm:inline",children:"重新生成"}),e.jsx("span",{className:"sm:hidden",children:"生成"})]})}),e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认重新生成 Token"}),e.jsx(xt,{children:"这将生成一个新的 64 位安全令牌,并使当前 Token 立即失效。 您需要使用新 Token 重新登录系统。此操作不可撤销,确定要继续吗?"})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:ne,children:"确认生成"})]})]})]})]})]}),e.jsx("p",{className:"text-[10px] sm:text-xs text-muted-foreground",children:"请妥善保管您的 Access Token,不要泄露给他人"})]})})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"自定义 Access Token"}),e.jsxs("div",{className:"space-y-3 sm:space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"new-token",className:"text-sm",children:"新的访问令牌"}),e.jsxs("div",{className:"relative",children:[e.jsx(ce,{id:"new-token",type:j?"text":"password",value:d,onChange:pe=>h(pe.target.value),className:"pr-10 font-mono text-sm",placeholder:"输入自定义 Token"}),e.jsx("button",{onClick:()=>p(!j),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1.5 hover:bg-accent rounded",title:j?"隐藏":"显示",children:j?e.jsx(or,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Ws,{className:"h-4 w-4 text-muted-foreground"})})]}),d&&e.jsxs("div",{className:"mt-3 space-y-2 p-3 rounded-lg bg-muted/50",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"Token 安全要求:"}),e.jsx("div",{className:"space-y-1.5",children:Y.rules.map(pe=>e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[pe.passed?e.jsx(ha,{className:"h-4 w-4 text-green-500 flex-shrink-0"}):e.jsx(sg,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:Q(pe.passed?"text-green-600 dark:text-green-400":"text-muted-foreground"),children:pe.label})]},pe.id))}),Y.isValid&&e.jsx("div",{className:"mt-2 pt-2 border-t border-border",children:e.jsxs("div",{className:"flex items-center gap-2 text-sm text-green-600 dark:text-green-400",children:[e.jsx(Na,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:"Token 格式正确,可以使用"})]})})]})]}),e.jsx(b,{onClick:R,disabled:N||!Y.isValid||!d,className:"w-full sm:w-auto",children:N?"更新中...":"更新自定义 Token"})]})]}),e.jsxs("div",{className:"rounded-lg border border-yellow-200 dark:border-yellow-900 bg-yellow-50 dark:bg-yellow-950/30 p-3 sm:p-4",children:[e.jsx("h4",{className:"text-sm sm:text-base font-semibold text-yellow-900 dark:text-yellow-200 mb-2",children:"安全提示"}),e.jsxs("ul",{className:"text-xs sm:text-sm text-yellow-800 dark:text-yellow-300 space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"重新生成 Token 会创建系统随机生成的 64 位安全令牌"}),e.jsx("li",{children:"自定义 Token 必须满足所有安全要求才能使用"}),e.jsx("li",{children:"更新 Token 后,旧的 Token 将立即失效"}),e.jsx("li",{children:"请在安全的环境下查看和复制 Token"}),e.jsx("li",{children:"如果怀疑 Token 泄露,请立即重新生成或更新"}),e.jsx("li",{children:"建议使用系统生成的 Token 以获得最高安全性"})]})]})]})}function PN(){const n=fa(),{toast:r}=Xt(),[c,d]=u.useState(!1),[h,x]=u.useState(!1),[f,j]=u.useState(()=>Wt("logCacheSize")),[p,N]=u.useState(()=>Wt("wsReconnectInterval")),[v,C]=u.useState(()=>Wt("wsMaxReconnectAttempts")),[S,w]=u.useState(()=>Wt("dataSyncInterval")),[L,F]=u.useState(()=>Pf()),[B,O]=u.useState(!1),[K,H]=u.useState(!1),z=u.useRef(null);if(h)throw new Error("这是一个手动触发的测试错误,用于验证错误边界组件是否正常工作。");const V=()=>{F(Pf())},Y=A=>{const X=A[0];j(X),Pn("logCacheSize",X)},E=A=>{const X=A[0];N(X),Pn("wsReconnectInterval",X)},R=A=>{const X=A[0];C(X),Pn("wsMaxReconnectAttempts",X)},ne=A=>{const X=A[0];w(X),Pn("dataSyncInterval",X)},fe=()=>{an.clearLogs(),r({title:"日志已清除",description:"日志缓存已清空"})},Ce=()=>{const A=$N();V(),r({title:"缓存已清除",description:`已清除 ${A.clearedKeys.length} 项缓存数据`})},we=()=>{O(!0);try{const A=GN(),X=JSON.stringify(A,null,2),T=new Blob([X],{type:"application/json"}),te=URL.createObjectURL(T),_=document.createElement("a");_.href=te,_.download=`maibot-webui-settings-${new Date().toISOString().slice(0,10)}.json`,document.body.appendChild(_),_.click(),document.body.removeChild(_),URL.revokeObjectURL(te),r({title:"导出成功",description:"设置已导出为 JSON 文件"})}catch(A){console.error("导出设置失败:",A),r({title:"导出失败",description:"无法导出设置",variant:"destructive"})}finally{O(!1)}},pe=A=>{const X=A.target.files?.[0];if(!X)return;H(!0);const T=new FileReader;T.onload=te=>{try{const _=te.target?.result,me=JSON.parse(_),oe=VN(me);oe.success?(j(Wt("logCacheSize")),N(Wt("wsReconnectInterval")),C(Wt("wsMaxReconnectAttempts")),w(Wt("dataSyncInterval")),V(),r({title:"导入成功",description:`成功导入 ${oe.imported.length} 项设置${oe.skipped.length>0?`,跳过 ${oe.skipped.length} 项`:""}`}),(oe.imported.includes("theme")||oe.imported.includes("accentColor"))&&r({title:"提示",description:"部分设置需要刷新页面才能完全生效"})):r({title:"导入失败",description:"没有有效的设置项可导入",variant:"destructive"})}catch(_){console.error("导入设置失败:",_),r({title:"导入失败",description:"文件格式无效",variant:"destructive"})}finally{H(!1),z.current&&(z.current.value="")}},T.readAsText(X)},Ne=()=>{FN(),j(Aa.logCacheSize),N(Aa.wsReconnectInterval),C(Aa.wsMaxReconnectAttempts),w(Aa.dataSyncInterval),V(),r({title:"已重置",description:"所有设置已恢复为默认值,刷新页面以应用更改"})},be=async()=>{d(!0);try{const A=localStorage.getItem("access-token"),X=await fetch("/api/webui/setup/reset",{method:"POST",headers:{Authorization:`Bearer ${A}`}}),T=await X.json();X.ok&&T.success?(r({title:"重置成功",description:"即将进入初次配置向导"}),setTimeout(()=>{n({to:"/setup"})},1e3)):r({title:"重置失败",description:T.message||"无法重置配置状态",variant:"destructive"})}catch(A){console.error("重置配置状态错误:",A),r({title:"重置失败",description:"连接服务器失败",variant:"destructive"})}finally{d(!1)}};return e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsxs("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4 flex items-center gap-2",children:[e.jsx(Zc,{className:"h-5 w-5"}),"性能与存储"]}),e.jsxs("div",{className:"space-y-4 sm:space-y-5",children:[e.jsxs("div",{className:"rounded-lg bg-muted/50 p-3 sm:p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("span",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(dy,{className:"h-4 w-4"}),"本地存储使用"]}),e.jsx(b,{variant:"ghost",size:"sm",onClick:V,className:"h-7 px-2",children:e.jsx(ws,{className:"h-3 w-3"})})]}),e.jsx("div",{className:"text-2xl font-bold text-primary",children:QN(L.used)}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[L.items," 个存储项"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(y,{className:"text-sm font-medium",children:"日志缓存大小"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[f," 条"]})]}),e.jsx(Ma,{value:[f],onValueChange:Y,min:100,max:5e3,step:100,className:"w-full"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"控制日志查看器最多缓存的日志条数,较大的值会占用更多内存"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(y,{className:"text-sm font-medium",children:"首页数据刷新间隔"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[S," 秒"]})]}),e.jsx(Ma,{value:[S],onValueChange:ne,min:10,max:120,step:5,className:"w-full"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"控制首页统计数据的自动刷新间隔"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(y,{className:"text-sm font-medium",children:"WebSocket 重连间隔"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[p/1e3," 秒"]})]}),e.jsx(Ma,{value:[p],onValueChange:E,min:1e3,max:1e4,step:500,className:"w-full"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"日志 WebSocket 连接断开后的重连基础间隔"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(y,{className:"text-sm font-medium",children:"WebSocket 最大重连次数"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[v," 次"]})]}),e.jsx(Ma,{value:[v],onValueChange:R,min:3,max:30,step:1,className:"w-full"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"连接失败后的最大重连尝试次数"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 pt-2",children:[e.jsxs(b,{variant:"outline",size:"sm",onClick:fe,className:"gap-2",children:[e.jsx(at,{className:"h-4 w-4"}),"清除日志缓存"]}),e.jsxs(bt,{children:[e.jsx(es,{asChild:!0,children:e.jsxs(b,{variant:"outline",size:"sm",className:"gap-2",children:[e.jsx(at,{className:"h-4 w-4"}),"清除本地缓存"]})}),e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认清除本地缓存"}),e.jsx(xt,{children:"这将清除所有本地缓存的设置和数据(不包括登录凭证)。 您可能需要重新配置部分偏好设置。确定要继续吗?"})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:Ce,children:"确认清除"})]})]})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsxs("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4 flex items-center gap-2",children:[e.jsx(rl,{className:"h-5 w-5"}),"导入/导出设置"]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground",children:"导出当前的界面设置以便备份,或从之前导出的文件中恢复设置。"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(b,{variant:"outline",onClick:we,disabled:B,className:"gap-2",children:[e.jsx(rl,{className:"h-4 w-4"}),B?"导出中...":"导出设置"]}),e.jsx("input",{ref:z,type:"file",accept:".json",onChange:pe,className:"hidden"}),e.jsxs(b,{variant:"outline",onClick:()=>z.current?.click(),disabled:K,className:"gap-2",children:[e.jsx(dr,{className:"h-4 w-4"}),K?"导入中...":"导入设置"]})]}),e.jsx("div",{className:"pt-2 border-t",children:e.jsxs(bt,{children:[e.jsx(es,{asChild:!0,children:e.jsxs(b,{variant:"outline",size:"sm",className:"gap-2 text-destructive hover:text-destructive",children:[e.jsx(Kc,{className:"h-4 w-4"}),"重置所有设置为默认值"]})}),e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认重置所有设置"}),e.jsx(xt,{children:"这将把所有界面设置恢复为默认值,包括主题、颜色、动画等偏好设置。 此操作不会影响您的登录状态。确定要继续吗?"})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:Ne,children:"确认重置"})]})]})]})})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"配置向导"}),e.jsxs("div",{className:"space-y-3 sm:space-y-4",children:[e.jsx("div",{className:"space-y-2",children:e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground",children:"重新进行初次配置向导,可以帮助您重新设置系统的基础配置。"})}),e.jsxs(bt,{children:[e.jsx(es,{asChild:!0,children:e.jsxs(b,{variant:"outline",disabled:c,className:"gap-2",children:[e.jsx(Kc,{className:Q("h-4 w-4",c&&"animate-spin")}),"重新进行初次配置"]})}),e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认重新配置"}),e.jsx(xt,{children:"这将带您重新进入初次配置向导。您可以重新设置系统的基础配置项。确定要继续吗?"})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:be,children:"确认重置"})]})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border border-dashed border-yellow-500/50 bg-yellow-500/5 p-4 sm:p-6",children:[e.jsxs("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4 flex items-center gap-2",children:[e.jsx(ya,{className:"h-5 w-5 text-yellow-500"}),"开发者工具"]}),e.jsxs("div",{className:"space-y-3 sm:space-y-4",children:[e.jsx("div",{className:"space-y-2",children:e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground",children:"以下功能仅供开发调试使用,可能会导致页面崩溃或异常。"})}),e.jsxs(bt,{children:[e.jsx(es,{asChild:!0,children:e.jsxs(b,{variant:"destructive",className:"gap-2",children:[e.jsx(ya,{className:"h-4 w-4"}),"触发测试错误"]})}),e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认触发错误"}),e.jsx(xt,{children:"这将手动触发一个 React 错误,用于测试错误边界组件的显示效果。 页面将显示错误界面,您可以通过刷新页面或点击返回首页来恢复。"})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:()=>x(!0),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"确认触发"})]})]})]})]})]})]})}function WN(){return e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsx("div",{className:"rounded-lg border-2 border-primary/30 bg-gradient-to-r from-primary/5 to-primary/10 p-4 sm:p-6",children:e.jsxs("div",{className:"flex items-start gap-3 sm:gap-4",children:[e.jsx("div",{className:"flex-shrink-0 rounded-lg bg-primary/10 p-2 sm:p-3",children:e.jsx("svg",{className:"h-6 w-6 sm:h-8 sm:w-8 text-primary",fill:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{fillRule:"evenodd",d:"M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z",clipRule:"evenodd"})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-lg sm:text-xl font-bold text-foreground mb-2",children:"开源项目"}),e.jsx("p",{className:"text-sm sm:text-base text-muted-foreground mb-3",children:"本项目在 GitHub 开源,欢迎 Star ⭐ 支持!"}),e.jsxs("a",{href:"https://github.com/Mai-with-u/MaiBot-Dashboard",target:"_blank",rel:"noopener noreferrer",className:Q("inline-flex items-center gap-2 px-4 py-2 rounded-lg","bg-primary text-primary-foreground font-medium text-sm","hover:bg-primary/90 transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"),children:[e.jsx("svg",{className:"h-4 w-4",fill:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{fillRule:"evenodd",d:"M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z",clipRule:"evenodd"})}),"前往 GitHub",e.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})]})]})]})}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsxs("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:["关于 ",Fu]}),e.jsxs("div",{className:"space-y-2 text-xs sm:text-sm text-muted-foreground",children:[e.jsxs("p",{children:["版本: ",Vu]}),e.jsx("p",{children:"麦麦(MaiBot)的现代化 Web 管理界面"})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"作者"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium",children:"MaiBot 核心"}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground",children:"Mai-with-u"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium",children:"WebUI"}),e.jsxs("p",{className:"text-xs sm:text-sm text-muted-foreground",children:["Mai-with-u ",e.jsx("a",{href:"https://github.com/DrSmoothl",target:"_blank",rel:"noopener noreferrer",className:"text-primary underline",children:"@MotricSeven"})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"技术栈"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 text-xs sm:text-sm text-muted-foreground",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-foreground",children:"前端框架"}),e.jsxs("ul",{className:"space-y-0.5 list-disc list-inside",children:[e.jsx("li",{children:"React 19.2.0"}),e.jsx("li",{children:"TypeScript 5.7.2"}),e.jsx("li",{children:"Vite 6.0.7"}),e.jsx("li",{children:"TanStack Router 1.94.2"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-foreground",children:"UI 组件"}),e.jsxs("ul",{className:"space-y-0.5 list-disc list-inside",children:[e.jsx("li",{children:"shadcn/ui"}),e.jsx("li",{children:"Radix UI"}),e.jsx("li",{children:"Tailwind CSS 3.4.17"}),e.jsx("li",{children:"Lucide Icons"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-foreground",children:"后端"}),e.jsxs("ul",{className:"space-y-0.5 list-disc list-inside",children:[e.jsx("li",{children:"Python 3.12+"}),e.jsx("li",{children:"FastAPI"}),e.jsx("li",{children:"Uvicorn"}),e.jsx("li",{children:"WebSocket"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-foreground",children:"构建工具"}),e.jsxs("ul",{className:"space-y-0.5 list-disc list-inside",children:[e.jsx("li",{children:"Bun / npm"}),e.jsx("li",{children:"ESLint 9.17.0"}),e.jsx("li",{children:"PostCSS"})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"开源库感谢"}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground mb-3",children:"本项目使用了以下优秀的开源库,感谢他们的贡献:"}),e.jsx(st,{className:"h-[300px] sm:h-[400px]",children:e.jsxs("div",{className:"space-y-4 pr-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"UI 框架与组件"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(Zt,{name:"React",description:"用户界面构建库",license:"MIT"}),e.jsx(Zt,{name:"shadcn/ui",description:"优雅的 React 组件库",license:"MIT"}),e.jsx(Zt,{name:"Radix UI",description:"无样式的可访问组件库",license:"MIT"}),e.jsx(Zt,{name:"Tailwind CSS",description:"实用优先的 CSS 框架",license:"MIT"}),e.jsx(Zt,{name:"Lucide React",description:"精美的图标库",license:"ISC"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"路由与状态管理"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(Zt,{name:"TanStack Router",description:"类型安全的路由库",license:"MIT"}),e.jsx(Zt,{name:"Zustand",description:"轻量级状态管理",license:"MIT"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"表单处理"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(Zt,{name:"React Hook Form",description:"高性能表单库",license:"MIT"}),e.jsx(Zt,{name:"Zod",description:"TypeScript 优先的 schema 验证",license:"MIT"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"工具库"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(Zt,{name:"clsx",description:"条件 className 构建工具",license:"MIT"}),e.jsx(Zt,{name:"tailwind-merge",description:"Tailwind 类名合并工具",license:"MIT"}),e.jsx(Zt,{name:"class-variance-authority",description:"组件变体管理",license:"Apache-2.0"}),e.jsx(Zt,{name:"date-fns",description:"现代化日期处理库",license:"MIT"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"动画效果"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(Zt,{name:"Framer Motion",description:"React 动画库",license:"MIT"}),e.jsx(Zt,{name:"vaul",description:"抽屉组件动画",license:"MIT"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"后端框架"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(Zt,{name:"FastAPI",description:"现代化 Python Web 框架",license:"MIT"}),e.jsx(Zt,{name:"Uvicorn",description:"ASGI 服务器",license:"BSD-3-Clause"}),e.jsx(Zt,{name:"Pydantic",description:"数据验证库",license:"MIT"}),e.jsx(Zt,{name:"python-multipart",description:"文件上传支持",license:"Apache-2.0"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"开发工具"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(Zt,{name:"TypeScript",description:"JavaScript 的超集",license:"Apache-2.0"}),e.jsx(Zt,{name:"Vite",description:"下一代前端构建工具",license:"MIT"}),e.jsx(Zt,{name:"ESLint",description:"JavaScript 代码检查工具",license:"MIT"}),e.jsx(Zt,{name:"PostCSS",description:"CSS 转换工具",license:"MIT"})]})]})]})})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"开源许可"}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"rounded-lg bg-primary/5 border border-primary/20 p-3 sm:p-4",children:e.jsxs("div",{className:"flex items-start gap-2 sm:gap-3",children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:e.jsx("div",{className:"rounded-md bg-primary/10 px-2 py-1",children:e.jsx("span",{className:"text-xs sm:text-sm font-bold text-primary",children:"GPLv3"})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm sm:text-base font-semibold text-foreground mb-1",children:"MaiBot WebUI"}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground",children:"本项目采用 GNU General Public License v3.0 开源许可证。 您可以自由地使用、修改和分发本软件,但必须保持相同的开源许可。"})]})]})}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground",children:"本项目依赖的所有开源库均遵循各自的开源许可证(MIT、Apache-2.0、BSD 等)。 感谢所有开源贡献者的无私奉献。"})]})]})]})}function Zt({name:n,description:r,license:c}){return e.jsxs("div",{className:"flex items-start justify-between gap-2 rounded-lg border bg-muted/30 p-2.5 sm:p-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-foreground truncate",children:n}),e.jsx("p",{className:"text-muted-foreground text-xs mt-0.5",children:r})]}),e.jsx("span",{className:"inline-flex items-center rounded-full bg-primary/10 px-2 py-0.5 text-[10px] font-medium text-primary flex-shrink-0",children:c})]})}function ku({value:n,current:r,onChange:c,label:d,description:h}){const x=r===n;return e.jsxs("button",{onClick:()=>c(n),className:Q("relative rounded-lg border-2 p-3 sm:p-4 text-left transition-all","hover:border-primary/50 hover:bg-accent/50",x?"border-primary bg-accent":"border-border"),children:[x&&e.jsx("div",{className:"absolute top-2 right-2 sm:top-3 sm:right-3 h-2 w-2 rounded-full bg-primary"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-sm sm:text-base font-medium",children:d}),e.jsx("div",{className:"text-[10px] sm:text-xs text-muted-foreground",children:h})]}),e.jsxs("div",{className:"mt-2 sm:mt-3 flex gap-1",children:[n==="light"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-slate-200"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-slate-300"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-slate-400"})]}),n==="dark"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-slate-700"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-slate-800"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-slate-900"})]}),n==="system"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-gradient-to-r from-slate-200 to-slate-700"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-gradient-to-r from-slate-300 to-slate-800"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-gradient-to-r from-slate-400 to-slate-900"})]})]})]})}function ma({value:n,current:r,onChange:c,label:d,colorClass:h}){const x=r===n;return e.jsxs("button",{onClick:()=>c(n),className:Q("relative rounded-lg border-2 p-2 sm:p-3 text-left transition-all","hover:border-primary/50 hover:bg-accent/50",x?"border-primary bg-accent":"border-border"),children:[x&&e.jsx("div",{className:"absolute top-1.5 right-1.5 sm:top-2 sm:right-2 h-1.5 w-1.5 sm:h-2 sm:w-2 rounded-full bg-primary"}),e.jsxs("div",{className:"flex flex-col items-center gap-1.5 sm:gap-2",children:[e.jsx("div",{className:Q("h-8 w-8 sm:h-10 sm:w-10 rounded-full",h)}),e.jsx("div",{className:"text-[10px] sm:text-xs font-medium text-center",children:d})]})]})}class e0{grad3;p;perm;constructor(r=0){this.grad3=[[1,1,0],[-1,1,0],[1,-1,0],[-1,-1,0],[1,0,1],[-1,0,1],[1,0,-1],[-1,0,-1],[0,1,1],[0,-1,1],[0,1,-1],[0,-1,-1]],this.p=[];for(let c=0;c<256;c++)this.p[c]=Math.floor(Math.random()*256);this.perm=[];for(let c=0;c<512;c++)this.perm[c]=this.p[c&255]}dot(r,c,d){return r[0]*c+r[1]*d}mix(r,c,d){return(1-d)*r+d*c}fade(r){return r*r*r*(r*(r*6-15)+10)}perlin2(r,c){const d=Math.floor(r)&255,h=Math.floor(c)&255;r-=Math.floor(r),c-=Math.floor(c);const x=this.fade(r),f=this.fade(c),j=this.perm[d]+h,p=this.perm[j],N=this.perm[j+1],v=this.perm[d+1]+h,C=this.perm[v],S=this.perm[v+1];return this.mix(this.mix(this.dot(this.grad3[p%12],r,c),this.dot(this.grad3[C%12],r-1,c),x),this.mix(this.dot(this.grad3[N%12],r,c-1),this.dot(this.grad3[S%12],r-1,c-1),x),f)}}function ep(){const n=u.useRef(null),r=u.useRef(null),c=u.useRef(void 0),d=u.useRef({mouse:{x:-10,y:0,lx:0,ly:0,sx:0,sy:0,v:0,vs:0,a:0,set:!1},lines:[],paths:[],noise:new e0(Math.random()),bounding:null});return u.useEffect(()=>{const h=r.current,x=n.current;if(!h||!x)return;const f=d.current,j=()=>{const F=h.getBoundingClientRect();f.bounding=F,x.style.width=`${F.width}px`,x.style.height=`${F.height}px`},p=()=>{if(!f.bounding)return;const{width:F,height:B}=f.bounding;f.lines=[],f.paths.forEach(ne=>ne.remove()),f.paths=[];const O=10,K=32,H=F+200,z=B+30,V=Math.ceil(H/O),Y=Math.ceil(z/K),E=(F-O*V)/2,R=(B-K*Y)/2;for(let ne=0;ne<=V;ne++){const fe=[];for(let we=0;we<=Y;we++){const pe={x:E+O*ne,y:R+K*we,wave:{x:0,y:0},cursor:{x:0,y:0,vx:0,vy:0}};fe.push(pe)}const Ce=document.createElementNS("http://www.w3.org/2000/svg","path");x.appendChild(Ce),f.paths.push(Ce),f.lines.push(fe)}},N=F=>{const{lines:B,mouse:O,noise:K}=f;B.forEach(H=>{H.forEach(z=>{const V=K.perlin2((z.x+F*.0125)*.002,(z.y+F*.005)*.0015)*12;z.wave.x=Math.cos(V)*32,z.wave.y=Math.sin(V)*16;const Y=z.x-O.sx,E=z.y-O.sy,R=Math.hypot(Y,E),ne=Math.max(175,O.vs);if(R{const O={x:F.x+F.wave.x+(B?F.cursor.x:0),y:F.y+F.wave.y+(B?F.cursor.y:0)};return O.x=Math.round(O.x*10)/10,O.y=Math.round(O.y*10)/10,O},C=()=>{const{lines:F,paths:B}=f;F.forEach((O,K)=>{let H=v(O[0],!1),z=`M ${H.x} ${H.y}`;O.forEach((V,Y)=>{const E=Y===O.length-1;H=v(V,!E),z+=`L ${H.x} ${H.y}`}),B[K].setAttribute("d",z)})},S=F=>{const{mouse:B}=f;B.sx+=(B.x-B.sx)*.1,B.sy+=(B.y-B.sy)*.1;const O=B.x-B.lx,K=B.y-B.ly,H=Math.hypot(O,K);B.v=H,B.vs+=(H-B.vs)*.1,B.vs=Math.min(100,B.vs),B.lx=B.x,B.ly=B.y,B.a=Math.atan2(K,O),h&&(h.style.setProperty("--x",`${B.sx}px`),h.style.setProperty("--y",`${B.sy}px`)),N(F),C(),c.current=requestAnimationFrame(S)},w=F=>{if(!f.bounding)return;const{mouse:B}=f;B.x=F.pageX-f.bounding.left,B.y=F.pageY-f.bounding.top+window.scrollY,B.set||(B.sx=B.x,B.sy=B.y,B.lx=B.x,B.ly=B.y,B.set=!0)},L=()=>{j(),p()};return j(),p(),window.addEventListener("resize",L),window.addEventListener("mousemove",w),c.current=requestAnimationFrame(S),()=>{window.removeEventListener("resize",L),window.removeEventListener("mousemove",w),c.current&&cancelAnimationFrame(c.current)}},[]),e.jsxs("div",{ref:r,className:"waves-background",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",overflow:"hidden",pointerEvents:"none"},children:[e.jsx("div",{className:"waves-cursor",style:{position:"absolute",top:0,left:0,width:"0.5rem",height:"0.5rem",background:"hsl(var(--primary) / 0.3)",borderRadius:"50%",transform:"translate3d(calc(var(--x, -0.5rem) - 50%), calc(var(--y, 50%) - 50%), 0)",willChange:"transform",pointerEvents:"none"}}),e.jsx("svg",{ref:n,style:{display:"block",width:"100%",height:"100%"},children:e.jsx("style",{children:` path { fill: none; stroke: hsl(var(--primary) / 0.20); stroke-width: 1px; } `})})]})}async function Te(n,r){const c={...r,credentials:"include",headers:{"Content-Type":"application/json",...r?.headers}},d=await fetch(n,c);if(d.status===401)throw window.location.href="/auth",new Error("认证失败,请重新登录");return d}function Rt(){return{"Content-Type":"application/json"}}async function t0(){try{await fetch("/api/webui/auth/logout",{method:"POST",credentials:"include"})}catch(n){console.error("登出请求失败:",n)}window.location.href="/auth"}async function Qu(){try{return(await(await fetch("/api/webui/auth/check",{method:"GET",credentials:"include"})).json()).authenticated===!0}catch{return!1}}function s0(){const[n,r]=u.useState(""),[c,d]=u.useState(!1),[h,x]=u.useState(""),[f,j]=u.useState(!0),p=fa(),{enableWavesBackground:N,setEnableWavesBackground:v}=vg(),{theme:C,setTheme:S}=Gu();u.useEffect(()=>{(async()=>{try{await Qu()&&p({to:"/"})}catch{}finally{j(!1)}})()},[p]);const L=C==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":C,F=()=>{S(L==="dark"?"light":"dark")},B=async O=>{if(O.preventDefault(),x(""),!n.trim()){x("请输入 Access Token");return}d(!0);try{const K=await fetch("/api/webui/auth/verify",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({token:n.trim()})}),H=await K.json();K.ok&&H.valid?H.is_first_setup?p({to:"/setup"}):p({to:"/"}):x(H.message||"Token 验证失败,请检查后重试")}catch(K){console.error("Token 验证错误:",K),x("连接服务器失败,请检查网络连接")}finally{d(!1)}};return f?e.jsxs("div",{className:"relative flex min-h-screen items-center justify-center overflow-hidden bg-background p-4",children:[N&&e.jsx(ep,{}),e.jsx("div",{className:"text-muted-foreground",children:"正在检查登录状态..."})]}):e.jsxs("div",{className:"relative flex min-h-screen items-center justify-center overflow-hidden bg-background p-4",children:[N&&e.jsx(ep,{}),e.jsxs(Ye,{className:"relative z-10 w-full max-w-md shadow-2xl backdrop-blur-xl bg-card/80 border-border/50",children:[e.jsx("button",{onClick:F,className:"absolute right-4 top-4 rounded-lg p-2 hover:bg-accent transition-colors z-10 text-foreground",title:L==="dark"?"切换到浅色模式":"切换到深色模式",children:L==="dark"?e.jsx(ag,{className:"h-5 w-5",strokeWidth:2.5,fill:"none"}):e.jsx(lg,{className:"h-5 w-5",strokeWidth:2.5,fill:"none"})}),e.jsxs(Nt,{className:"space-y-4 text-center",children:[e.jsx("div",{className:"mx-auto flex h-16 w-16 items-center justify-center rounded-2xl bg-primary/10",children:e.jsx(Gf,{className:"h-8 w-8 text-primary",strokeWidth:2,fill:"none"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(wt,{className:"text-2xl font-bold",children:"欢迎使用 MaiBot"}),e.jsx(ns,{className:"text-base",children:"请输入您的 Access Token 以继续访问系统"})]})]}),e.jsx(kt,{children:e.jsxs("form",{onSubmit:B,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"token",className:"text-sm font-medium",children:"Access Token"}),e.jsxs("div",{className:"relative",children:[e.jsx(ng,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground",strokeWidth:2,fill:"none"}),e.jsx(ce,{id:"token",type:"password",placeholder:"请输入您的 Access Token",value:n,onChange:O=>r(O.target.value),className:Q("pl-10",h&&"border-red-500 focus-visible:ring-red-500"),disabled:c,autoFocus:!0,autoComplete:"off"})]})]}),h&&e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-red-50 p-3 text-sm text-red-600 dark:bg-red-950/50 dark:text-red-400",children:[e.jsx(Oa,{className:"h-4 w-4 flex-shrink-0",strokeWidth:2,fill:"none"}),e.jsx("span",{children:h})]}),e.jsx(b,{type:"submit",className:"w-full",disabled:c,children:c?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"验证中..."]}):"验证并进入"}),e.jsxs(Jt,{children:[e.jsx($u,{asChild:!0,children:e.jsxs("button",{className:"w-full text-center text-sm text-primary hover:text-primary/80 transition-colors underline-offset-4 hover:underline flex items-center justify-center gap-1",children:[e.jsx(uy,{className:"h-4 w-4",strokeWidth:2,fill:"none"}),"我没有 Token,我该去哪里获得 Token?"]})}),e.jsxs($t,{className:"sm:max-w-md",children:[e.jsxs(Qt,{children:[e.jsxs(Yt,{className:"flex items-center gap-2",children:[e.jsx(Gf,{className:"h-5 w-5 text-primary",strokeWidth:2,fill:"none"}),"如何获取 Access Token"]}),e.jsx(ds,{children:"Access Token 是访问 MaiBot WebUI 的唯一凭证,请按以下方式获取"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-lg border bg-muted/50 p-4 space-y-2",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(my,{className:"h-5 w-5 text-primary flex-shrink-0 mt-0.5",strokeWidth:2,fill:"none"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("h4",{className:"font-semibold text-sm",children:"方式一:查看启动日志"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"在 MaiBot 启动时,控制台会显示 WebUI Access Token。"}),e.jsxs("div",{className:"rounded bg-background p-2 font-mono text-xs",children:[e.jsx("p",{className:"text-muted-foreground",children:"🔑 WebUI Access Token: abc123..."}),e.jsx("p",{className:"text-muted-foreground",children:"💡 请使用此 Token 登录 WebUI"})]})]})]})}),e.jsx("div",{className:"rounded-lg border bg-muted/50 p-4 space-y-2",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Da,{className:"h-5 w-5 text-primary flex-shrink-0 mt-0.5",strokeWidth:2,fill:"none"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("h4",{className:"font-semibold text-sm",children:"方式二:查看配置文件"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Token 保存在项目根目录的配置文件中:"}),e.jsx("div",{className:"rounded bg-background p-2 font-mono text-xs break-all",children:e.jsx("code",{className:"text-primary",children:"data/webui.json"})}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["打开此文件,复制 ",e.jsx("code",{className:"px-1 py-0.5 bg-background rounded",children:"access_token"})," 字段的值"]})]})]})}),e.jsx("div",{className:"rounded-lg border border-yellow-200 dark:border-yellow-900 bg-yellow-50 dark:bg-yellow-950/30 p-3",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Oa,{className:"h-4 w-4 text-yellow-600 dark:text-yellow-500 flex-shrink-0 mt-0.5",strokeWidth:2,fill:"none"}),e.jsxs("div",{className:"text-sm text-yellow-800 dark:text-yellow-300 space-y-1",children:[e.jsx("p",{className:"font-semibold",children:"安全提示"}),e.jsxs("ul",{className:"list-disc list-inside space-y-0.5 text-xs",children:[e.jsx("li",{children:"请妥善保管您的 Token,不要泄露给他人"}),e.jsx("li",{children:"如需重置 Token,请在登录后前往系统设置"})]})]})]})})]})]})]}),e.jsxs(bt,{children:[e.jsx(es,{asChild:!0,children:e.jsxs("button",{className:"w-full text-center text-sm text-muted-foreground hover:text-foreground transition-colors underline-offset-4 hover:underline flex items-center justify-center gap-1",children:[e.jsx(ln,{className:"h-4 w-4",strokeWidth:2,fill:"none"}),"我觉得这个界面很卡怎么办?"]})}),e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsxs(ht,{className:"flex items-center gap-2",children:[e.jsx(ln,{className:"h-5 w-5 text-primary",strokeWidth:2,fill:"none"}),"关闭背景动画"]}),e.jsx(xt,{children:"背景动画可能会在低性能设备上造成卡顿。关闭动画可以显著提升界面流畅度。"})]}),e.jsx("div",{className:"rounded-lg border bg-muted/50 p-4 space-y-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"关闭动画后,背景将变为纯色,但不影响任何功能的使用。您可以随时在系统设置中重新开启动画。"})}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:()=>v(!1),children:"关闭动画"})]})]})]})]})})]}),e.jsx("div",{className:"absolute bottom-4 left-0 right-0 text-center text-xs text-muted-foreground",children:e.jsx("p",{children:BN})})]})}const Ft=u.forwardRef(({className:n,...r},c)=>e.jsx("textarea",{className:Q("flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",n),ref:c,...r}));Ft.displayName="Textarea";const xr=u.forwardRef(({className:n,orientation:r="horizontal",decorative:c=!0,...d},h)=>e.jsx(Ap,{ref:h,decorative:c,orientation:r,className:Q("shrink-0 bg-border",r==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",n),...d}));xr.displayName=Ap.displayName;function a0({config:n,onChange:r}){const c=h=>{h.trim()&&!n.alias_names.includes(h.trim())&&r({...n,alias_names:[...n.alias_names,h.trim()]})},d=h=>{r({...n,alias_names:n.alias_names.filter((x,f)=>f!==h)})};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(y,{htmlFor:"qq_account",children:"QQ账号 *"}),e.jsx(ce,{id:"qq_account",type:"number",placeholder:"请输入机器人的QQ账号",value:n.qq_account||"",onChange:h=>r({...n,qq_account:Number(h.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"机器人登录使用的QQ账号"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(y,{htmlFor:"nickname",children:"昵称 *"}),e.jsx(ce,{id:"nickname",placeholder:"请输入机器人的昵称",value:n.nickname,onChange:h=>r({...n,nickname:h.target.value})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"机器人的主要称呼名称"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(y,{children:"别名"}),e.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:n.alias_names.map((h,x)=>e.jsxs(Je,{variant:"secondary",className:"gap-1",children:[h,e.jsx("button",{type:"button",onClick:()=>d(x),className:"ml-1 hover:text-destructive",children:e.jsx(on,{className:"h-3 w-3"})})]},x))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ce,{id:"alias_input",placeholder:"输入别名后按回车添加",onKeyPress:h=>{h.key==="Enter"&&(c(h.target.value),h.target.value="")}}),e.jsx(b,{type:"button",variant:"outline",onClick:()=>{const h=document.getElementById("alias_input");h&&(c(h.value),h.value="")},children:"添加"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"机器人的其他称呼,可以添加多个"})]})]})}function l0({config:n,onChange:r}){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(y,{htmlFor:"personality",children:"人格特征 *"}),e.jsx(Ft,{id:"personality",placeholder:"描述机器人的人格特质和身份特征(建议120字以内)",value:n.personality,onChange:c=>r({...n,personality:c.target.value}),rows:3}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"例如:是一个女大学生,现在在读大二,会刷贴吧"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(y,{htmlFor:"reply_style",children:"表达风格 *"}),e.jsx(Ft,{id:"reply_style",placeholder:"描述机器人说话的表达风格、表达习惯",value:n.reply_style,onChange:c=>r({...n,reply_style:c.target.value}),rows:3}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"例如:回复平淡一些,简短一些,说中文,参考贴吧、知乎和微博的回复风格"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(y,{htmlFor:"interest",children:"兴趣 *"}),e.jsx(Ft,{id:"interest",placeholder:"描述机器人感兴趣的话题",value:n.interest,onChange:c=>r({...n,interest:c.target.value}),rows:2}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"会影响机器人对什么话题进行回复"})]}),e.jsx(xr,{}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(y,{htmlFor:"plan_style",children:"群聊说话规则 *"}),e.jsx(Ft,{id:"plan_style",placeholder:"机器人在群聊中的行为风格和规则",value:n.plan_style,onChange:c=>r({...n,plan_style:c.target.value}),rows:4}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"定义机器人在群聊中如何行动,例如回复频率、条件等"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(y,{htmlFor:"private_plan_style",children:"私聊说话规则 *"}),e.jsx(Ft,{id:"private_plan_style",placeholder:"机器人在私聊中的行为风格和规则",value:n.private_plan_style,onChange:c=>r({...n,private_plan_style:c.target.value}),rows:3}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"定义机器人在私聊中的行为方式"})]})]})}function n0({config:n,onChange:r}){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(y,{htmlFor:"emoji_chance",children:"表情包激活概率"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[(n.emoji_chance*100).toFixed(0),"%"]})]}),e.jsx(ce,{id:"emoji_chance",type:"range",min:"0",max:"1",step:"0.1",value:n.emoji_chance,onChange:c=>r({...n,emoji_chance:Number(c.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"机器人发送表情包的概率"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(y,{htmlFor:"max_reg_num",children:"最大表情包数量"}),e.jsx(ce,{id:"max_reg_num",type:"number",min:"1",max:"200",value:n.max_reg_num,onChange:c=>r({...n,max_reg_num:Number(c.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"机器人最多保存的表情包数量"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(y,{htmlFor:"do_replace",children:"达到最大数量时替换"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"开启后会删除旧表情包,关闭则不再收集新表情包"})]}),e.jsx(Qe,{id:"do_replace",checked:n.do_replace,onCheckedChange:c=>r({...n,do_replace:c})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(y,{htmlFor:"check_interval",children:"检查间隔(分钟)"}),e.jsx(ce,{id:"check_interval",type:"number",min:"1",max:"120",value:n.check_interval,onChange:c=>r({...n,check_interval:Number(c.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"检查表情包注册、破损、删除的时间间隔"})]}),e.jsx(xr,{}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(y,{htmlFor:"steal_emoji",children:"偷取表情包"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"允许机器人将一些表情包据为己有"})]}),e.jsx(Qe,{id:"steal_emoji",checked:n.steal_emoji,onCheckedChange:c=>r({...n,steal_emoji:c})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(y,{htmlFor:"content_filtration",children:"启用表情包过滤"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"只保存符合要求的表情包"})]}),e.jsx(Qe,{id:"content_filtration",checked:n.content_filtration,onCheckedChange:c=>r({...n,content_filtration:c})})]}),n.content_filtration&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(y,{htmlFor:"filtration_prompt",children:"过滤要求"}),e.jsx(ce,{id:"filtration_prompt",placeholder:"例如:符合公序良俗",value:n.filtration_prompt,onChange:c=>r({...n,filtration_prompt:c.target.value})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"描述表情包应该符合的要求"})]})]})}function i0({config:n,onChange:r}){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(y,{htmlFor:"enable_tool",children:"启用工具系统"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"允许机器人使用各种工具增强功能"})]}),e.jsx(Qe,{id:"enable_tool",checked:n.enable_tool,onCheckedChange:c=>r({...n,enable_tool:c})})]}),e.jsx(xr,{}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(y,{htmlFor:"enable_mood",children:"启用情绪系统"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"让机器人具有情绪变化能力"})]}),e.jsx(Qe,{id:"enable_mood",checked:n.enable_mood,onCheckedChange:c=>r({...n,enable_mood:c})})]}),n.enable_mood&&e.jsxs("div",{className:"ml-6 space-y-6 border-l-2 border-primary/20 pl-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(y,{htmlFor:"mood_update_threshold",children:"情绪更新阈值"}),e.jsx(ce,{id:"mood_update_threshold",type:"number",min:"0.1",max:"10",step:"0.1",value:n.mood_update_threshold||1,onChange:c=>r({...n,mood_update_threshold:Number(c.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"值越高,情绪更新越慢"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(y,{htmlFor:"emotion_style",children:"情感特征"}),e.jsx(Ft,{id:"emotion_style",placeholder:"描述情绪的变化情况,例如:情绪较为稳定,但遭遇特定事件时起伏较大",value:n.emotion_style||"",onChange:c=>r({...n,emotion_style:c.target.value}),rows:2}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"影响机器人的情绪变化方式"})]})]}),e.jsx(xr,{}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(y,{htmlFor:"all_global",children:"启用全局黑话模式"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"允许机器人学习和使用群组黑话"})]}),e.jsx(Qe,{id:"all_global",checked:n.all_global,onCheckedChange:c=>r({...n,all_global:c})})]})]})}function r0({config:n,onChange:r}){const[c,d]=u.useState(!1);return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"rounded-lg bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5",children:e.jsx("svg",{className:"h-5 w-5 text-blue-600 dark:text-blue-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}),e.jsxs("div",{className:"flex-1 text-sm",children:[e.jsx("p",{className:"font-medium text-blue-900 dark:text-blue-100 mb-1",children:"关于硅基流动 (SiliconFlow)"}),e.jsx("p",{className:"text-blue-700 dark:text-blue-300 mb-2",children:"硅基流动提供了完整的模型覆盖,包括 DeepSeek V3、Qwen、视觉模型、语音识别和嵌入模型。 只需一个 API Key 即可使用麦麦的所有功能!"}),e.jsxs("a",{href:"https://cloud.siliconflow.cn",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-blue-600 dark:text-blue-400 hover:underline font-medium",children:["前往硅基流动获取 API Key",e.jsx(Qc,{className:"h-3 w-3"})]})]})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(y,{htmlFor:"siliconflow_api_key",children:"SiliconFlow API Key *"}),e.jsxs("div",{className:"relative",children:[e.jsx(ce,{id:"siliconflow_api_key",type:c?"text":"password",placeholder:"sk-...",value:n.api_key,onChange:h=>r({api_key:h.target.value}),className:"font-mono pr-10"}),e.jsx(b,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3 hover:bg-transparent",onClick:()=>d(!c),children:c?e.jsx(or,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Ws,{className:"h-4 w-4 text-muted-foreground"})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"请输入您的硅基流动 API 密钥。获取后,麦麦将自动配置所有必需的模型。"})]}),e.jsxs("div",{className:"rounded-lg bg-muted/50 p-4 text-sm space-y-2",children:[e.jsx("p",{className:"font-medium",children:"将自动配置以下模型:"}),e.jsxs("ul",{className:"list-disc list-inside space-y-1 text-muted-foreground ml-2",children:[e.jsx("li",{children:"DeepSeek V3 - 主要对话和工具模型"}),e.jsx("li",{children:"Qwen3 30B - 高频小任务和工具调用"}),e.jsx("li",{children:"Qwen3 VL 30B - 图像识别"}),e.jsx("li",{children:"SenseVoice - 语音识别"}),e.jsx("li",{children:"BGE-M3 - 文本嵌入"}),e.jsx("li",{children:"知识库相关模型 (LPMM)"})]})]}),e.jsx("div",{className:"rounded-lg border border-amber-200 dark:border-amber-800 bg-amber-50 dark:bg-amber-950/30 p-4",children:e.jsxs("p",{className:"text-sm text-amber-900 dark:text-amber-100",children:[e.jsx("span",{className:"font-medium",children:"💡 提示:"}),'完成向导后,您可以在"系统设置 → 模型配置"中添加更多 API 提供商和模型。']})})]})}async function c0(){const n=await Te("/api/webui/config/bot",{method:"GET",headers:Rt()});if(!n.ok)throw new Error("读取Bot配置失败");const c=(await n.json()).config.bot||{};return{qq_account:c.qq_account||0,nickname:c.nickname||"",alias_names:c.alias_names||[]}}async function o0(){const n=await Te("/api/webui/config/bot",{method:"GET",headers:Rt()});if(!n.ok)throw new Error("读取人格配置失败");const c=(await n.json()).config.personality||{};return{personality:c.personality||"",reply_style:c.reply_style||"",interest:c.interest||"",plan_style:c.plan_style||"",private_plan_style:c.private_plan_style||""}}async function d0(){const n=await Te("/api/webui/config/bot",{method:"GET",headers:Rt()});if(!n.ok)throw new Error("读取表情包配置失败");const c=(await n.json()).config.emoji||{};return{emoji_chance:c.emoji_chance??.4,max_reg_num:c.max_reg_num??40,do_replace:c.do_replace??!0,check_interval:c.check_interval??10,steal_emoji:c.steal_emoji??!0,content_filtration:c.content_filtration??!1,filtration_prompt:c.filtration_prompt||""}}async function u0(){const n=await Te("/api/webui/config/bot",{method:"GET",headers:Rt()});if(!n.ok)throw new Error("读取其他配置失败");const c=(await n.json()).config,d=c.tool||{},h=c.mood||{},x=c.jargon||{};return{enable_tool:d.enable_tool??!0,enable_mood:h.enable_mood??!1,mood_update_threshold:h.mood_update_threshold,emotion_style:h.emotion_style,all_global:x.all_global??!0}}async function m0(){const n=await Te("/api/webui/config/model",{method:"GET",headers:Rt()});if(!n.ok)throw new Error("读取模型配置失败");return{api_key:((await n.json()).config.api_providers||[]).find(x=>x.name==="SiliconFlow")?.api_key||""}}async function h0(n){const r=await Te("/api/webui/config/bot/section/bot",{method:"POST",headers:Rt(),body:JSON.stringify(n)});if(!r.ok){const c=await r.json();throw new Error(c.detail||"保存Bot基础配置失败")}return await r.json()}async function x0(n){const r=await Te("/api/webui/config/bot/section/personality",{method:"POST",headers:Rt(),body:JSON.stringify(n)});if(!r.ok){const c=await r.json();throw new Error(c.detail||"保存人格配置失败")}return await r.json()}async function f0(n){const r=await Te("/api/webui/config/bot/section/emoji",{method:"POST",headers:Rt(),body:JSON.stringify(n)});if(!r.ok){const c=await r.json();throw new Error(c.detail||"保存表情包配置失败")}return await r.json()}async function p0(n){const r=[];r.push(Te("/api/webui/config/bot/section/tool",{method:"POST",headers:Rt(),body:JSON.stringify({enable_tool:n.enable_tool})})),r.push(Te("/api/webui/config/bot/section/jargon",{method:"POST",headers:Rt(),body:JSON.stringify({all_global:n.all_global})}));const c={enable_mood:n.enable_mood};n.enable_mood&&(c.mood_update_threshold=n.mood_update_threshold||1,c.emotion_style=n.emotion_style||""),r.push(Te("/api/webui/config/bot/section/mood",{method:"POST",headers:Rt(),body:JSON.stringify(c)}));const d=await Promise.all(r);for(const h of d)if(!h.ok){const x=await h.json();throw new Error(x.detail||"保存其他配置失败")}return{success:!0}}async function g0(n){const r=await Te("/api/webui/config/model",{method:"GET",headers:Rt()});if(!r.ok)throw new Error("读取模型配置失败");const d=(await r.json()).config,h=d.api_providers||[],x=h.findIndex(p=>p.name==="SiliconFlow");x>=0?h[x]={...h[x],api_key:n.api_key}:h.push({name:"SiliconFlow",base_url:"https://api.siliconflow.cn/v1",api_key:n.api_key,client_type:"openai",max_retry:3,timeout:120,retry_interval:5});const f={...d,api_providers:h},j=await Te("/api/webui/config/model",{method:"POST",headers:Rt(),body:JSON.stringify(f)});if(!j.ok){const p=await j.json();throw new Error(p.detail||"保存模型配置失败")}return await j.json()}async function tp(){const n=localStorage.getItem("access-token"),r=await Te("/api/webui/setup/complete",{method:"POST",headers:{Authorization:`Bearer ${n}`}});if(!r.ok){const c=await r.json();throw new Error(c.message||"标记配置完成失败")}return await r.json()}async function so(){const n=await Te("/api/webui/system/restart",{method:"POST",headers:Rt()});if(!n.ok){const r=await n.json();throw new Error(r.detail||"重启失败")}return await n.json()}async function j0(){const n=await Te("/api/webui/system/status",{method:"GET",headers:Rt()});if(!n.ok){const r=await n.json();throw new Error(r.detail||"获取状态失败")}return await n.json()}function v0(){const n=fa(),{toast:r}=Xt(),[c,d]=u.useState(0),[h,x]=u.useState(!1),[f,j]=u.useState(!1),[p,N]=u.useState(!0),[v,C]=u.useState({qq_account:0,nickname:"",alias_names:[]}),[S,w]=u.useState({personality:"是一个女大学生,现在在读大二,会刷贴吧。",reply_style:"请回复的平淡一些,简短一些,说中文,不要刻意突出自身学科背景。可以参考贴吧,知乎和微博的回复风格。",interest:"对技术相关话题,游戏和动漫相关话题感兴趣,也对日常话题感兴趣,不喜欢太过沉重严肃的话题",plan_style:`1.思考**所有**的可用的action中的**每个动作**是否符合当下条件,如果动作使用条件符合聊天内容就使用 2.如果相同的内容已经被执行,请不要重复执行 3.请控制你的发言频率,不要太过频繁的发言 4.如果有人对你感到厌烦,请减少回复 5.如果有人对你进行攻击,或者情绪激动,请你以合适的方法应对`,private_plan_style:`1.思考**所有**的可用的action中的**每个动作**是否符合当下条件,如果动作使用条件符合聊天内容就使用 2.如果相同的内容已经被执行,请不要重复执行 3.某句话如果已经被回复过,不要重复回复`}),[L,F]=u.useState({emoji_chance:.4,max_reg_num:40,do_replace:!0,check_interval:10,steal_emoji:!0,content_filtration:!1,filtration_prompt:"符合公序良俗"}),[B,O]=u.useState({enable_tool:!0,enable_mood:!1,mood_update_threshold:1,emotion_style:"情绪较为稳定,但遇遇特定事件的时候起伏较大",all_global:!0}),[K,H]=u.useState({api_key:""}),[z,V]=u.useState(!1),[Y,E]=u.useState(""),R=[{id:"bot-basic",title:"Bot基础",description:"配置机器人的基本信息",icon:ar},{id:"personality",title:"人格配置",description:"定义机器人的性格和说话风格",icon:Ic},{id:"emoji",title:"表情包",description:"配置表情包相关设置",icon:Bu},{id:"other",title:"其他设置",description:"工具、情绪系统等配置",icon:ai},{id:"siliconflow",title:"API配置",description:"配置硅基流动API密钥",icon:ng}],ne=(c+1)/R.length*100;u.useEffect(()=>{(async()=>{try{N(!0);const[X,T,te,_,me]=await Promise.all([c0(),o0(),d0(),u0(),m0()]);C(X),w(T),F(te),O(_),H(me)}catch(X){r({title:"加载配置失败",description:X instanceof Error?X.message:"无法加载现有配置,将使用默认值",variant:"destructive"})}finally{N(!1)}})()},[r]);const fe=async()=>{j(!0);try{switch(c){case 0:await h0(v);break;case 1:await x0(S);break;case 2:await f0(L);break;case 3:await p0(B);break;case 4:await g0(K);break}return r({title:"保存成功",description:`${R[c].title}配置已保存`}),!0}catch(A){return r({title:"保存失败",description:A instanceof Error?A.message:"未知错误",variant:"destructive"}),!1}finally{j(!1)}},Ce=async()=>{await fe()&&c{c>0&&d(c-1)},pe=async()=>{x(!0),V(!0);try{if(E("正在保存API配置..."),!await fe()){x(!1),V(!1);return}E("正在完成初始化..."),await tp(),E("正在重启麦麦..."),await so(),r({title:"配置完成",description:"麦麦正在重启以应用新配置..."}),E("等待麦麦重启完成...");const X=60;let T=0,te=!1;for(;TsetTimeout(_,1e3));try{(await j0()).running&&(te=!0,E("重启成功!正在跳转..."))}catch{T++}}if(!te)throw new Error("重启超时,请手动检查麦麦状态");setTimeout(()=>{n({to:"/"})},1e3)}catch(A){V(!1),r({title:"配置失败",description:A instanceof Error?A.message:"未知错误",variant:"destructive"})}finally{x(!1)}},Ne=async()=>{try{await tp(),n({to:"/"})}catch(A){r({title:"跳过失败",description:A instanceof Error?A.message:"未知错误",variant:"destructive"})}},be=()=>{switch(c){case 0:return e.jsx(a0,{config:v,onChange:C});case 1:return e.jsx(l0,{config:S,onChange:w});case 2:return e.jsx(n0,{config:L,onChange:F});case 3:return e.jsx(i0,{config:B,onChange:O});case 4:return e.jsx(r0,{config:K,onChange:H});default:return null}};return e.jsxs("div",{className:"relative flex min-h-screen flex-col items-center justify-center overflow-hidden bg-gradient-to-br from-primary/5 via-background to-secondary/5 p-4 md:p-6",children:[z&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm",children:e.jsxs("div",{className:"mx-auto flex max-w-md flex-col items-center space-y-6 rounded-lg border bg-card p-8 text-center shadow-lg",children:[e.jsx("div",{className:"flex h-20 w-20 items-center justify-center rounded-full bg-primary/10",children:e.jsx(Ss,{className:"h-10 w-10 animate-spin text-primary"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h2",{className:"text-2xl font-bold",children:"正在重启麦麦"}),e.jsx("p",{className:"text-muted-foreground",children:Y})]}),e.jsx("div",{className:"w-full",children:e.jsx("div",{className:"h-2 w-full overflow-hidden rounded-full bg-secondary",children:e.jsx("div",{className:"h-full w-full animate-pulse bg-primary",style:{animation:"pulse 1.5s cubic-bezier(0.4, 0, 0.6, 1) infinite"}})})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"请稍候,这可能需要一分钟..."})]})}),e.jsxs("div",{className:"absolute inset-0 overflow-hidden pointer-events-none",children:[e.jsx("div",{className:"absolute left-1/4 top-1/4 h-64 w-64 md:h-96 md:w-96 rounded-full bg-primary/5 blur-3xl"}),e.jsx("div",{className:"absolute right-1/4 bottom-1/4 h-64 w-64 md:h-96 md:w-96 rounded-full bg-secondary/5 blur-3xl"})]}),p?e.jsxs("div",{className:"relative z-10 text-center",children:[e.jsx("div",{className:"mx-auto mb-4 flex h-16 w-16 items-center justify-center",children:e.jsx("div",{className:"h-12 w-12 animate-spin rounded-full border-4 border-primary border-t-transparent"})}),e.jsx("p",{className:"text-lg font-medium",children:"加载配置中..."}),e.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:"正在读取现有配置"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative z-10 w-full max-w-4xl",children:[e.jsxs("div",{className:"mb-6 md:mb-8 text-center",children:[e.jsx("div",{className:"mx-auto mb-4 flex h-12 w-12 md:h-16 md:w-16 items-center justify-center rounded-2xl bg-primary/10",children:e.jsx(hy,{className:"h-6 w-6 md:h-8 md:w-8 text-primary",strokeWidth:2,fill:"none"})}),e.jsx("h1",{className:"mb-2 text-2xl md:text-3xl font-bold",children:"首次配置向导"}),e.jsxs("p",{className:"text-sm md:text-base text-muted-foreground",children:["让我们一起完成 ",Fu," 的初始配置"]})]}),e.jsxs("div",{className:"mb-6 md:mb-8",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between text-xs md:text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:["步骤 ",c+1," / ",R.length]}),e.jsxs("span",{className:"font-medium text-primary",children:[Math.round(ne),"%"]})]}),e.jsx(yr,{value:ne,className:"h-2"})]}),e.jsx("div",{className:"mb-6 md:mb-8 flex justify-between",children:R.map((A,X)=>{const T=A.icon;return e.jsxs("div",{className:Q("flex flex-1 flex-col items-center gap-1 md:gap-2",Xn({to:"/"}),className:"gap-2 w-full sm:w-auto",children:[e.jsx(to,{className:"h-4 w-4"}),"返回首页"]}),e.jsxs(b,{size:"lg",variant:"outline",onClick:()=>window.history.back(),className:"gap-2 w-full sm:w-auto",children:[e.jsx(ti,{className:"h-4 w-4"}),"返回上一页"]})]}),e.jsx("div",{className:"mt-12 pt-8 border-t border-border",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"如果您认为这是一个错误,请联系系统管理员"})})]})})}const qe=Jb,Ge=Ib,Be=u.forwardRef(({className:n,children:r,...c},d)=>e.jsxs(Gp,{ref:d,className:Q("flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background data-[placeholder]:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",n),...c,children:[r,e.jsx(Qb,{asChild:!0,children:e.jsx(Rl,{className:"h-4 w-4 opacity-50"})})]}));Be.displayName=Gp.displayName;const _g=u.forwardRef(({className:n,...r},c)=>e.jsx(Vp,{ref:c,className:Q("flex cursor-default items-center justify-center py-1",n),...r,children:e.jsx(ur,{className:"h-4 w-4"})}));_g.displayName=Vp.displayName;const Sg=u.forwardRef(({className:n,...r},c)=>e.jsx(Fp,{ref:c,className:Q("flex cursor-default items-center justify-center py-1",n),...r,children:e.jsx(Rl,{className:"h-4 w-4"})}));Sg.displayName=Fp.displayName;const He=u.forwardRef(({className:n,children:r,position:c="popper",...d},h)=>e.jsx(Yb,{children:e.jsxs($p,{ref:h,className:Q("relative z-[100] max-h-[--radix-select-content-available-height] min-w-[8rem] overflow-hidden rounded-md border border-border bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-select-content-transform-origin]",c==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",n),position:c,...d,children:[e.jsx(_g,{}),e.jsx(Xb,{className:Q("p-1",c==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:r}),e.jsx(Sg,{})]})}));He.displayName=$p.displayName;const b0=u.forwardRef(({className:n,...r},c)=>e.jsx(Qp,{ref:c,className:Q("px-2 py-1.5 text-sm font-semibold",n),...r}));b0.displayName=Qp.displayName;const ie=u.forwardRef(({className:n,children:r,...c},d)=>e.jsxs(Yp,{ref:d,className:Q("relative flex w-full cursor-default select-none items-center rounded-sm py-2 pl-2 pr-8 text-sm outline-none bg-white dark:bg-gray-900 hover:bg-gray-100 dark:hover:bg-gray-800 focus:bg-gray-100 dark:focus:bg-gray-800 data-[disabled]:pointer-events-none data-[disabled]:opacity-50",n),...c,children:[e.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(Kb,{children:e.jsx(Na,{className:"h-4 w-4"})})}),e.jsx(Zb,{children:r})]}));ie.displayName=Yp.displayName;const y0=u.forwardRef(({className:n,...r},c)=>e.jsx(Xp,{ref:c,className:Q("-mx-1 my-1 h-px bg-muted",n),...r}));y0.displayName=Xp.displayName;const Ua=kb,Ba=Tb,_a=u.forwardRef(({className:n,align:r="center",sideOffset:c=4,...d},h)=>e.jsx(Cb,{children:e.jsx(Mp,{ref:h,align:r,sideOffset:c,className:Q("z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-popover-content-transform-origin]",n),...d})}));_a.displayName=Mp.displayName;const Ul="/api/webui/config";async function sp(){const r=await(await Te(`${Ul}/bot`)).json();if(!r.success)throw new Error("获取配置数据失败");return r.config}async function ei(){const r=await(await Te(`${Ul}/model`)).json();if(!r.success)throw new Error("获取模型配置数据失败");return r.config}async function ap(n){const c=await(await Te(`${Ul}/bot`,{method:"POST",body:JSON.stringify(n)})).json();if(!c.success)throw new Error(c.message||"保存配置失败")}async function N0(){const r=await(await Te(`${Ul}/bot/raw`)).json();if(!r.success)throw new Error("获取配置源代码失败");return r.content}async function w0(n){const c=await(await Te(`${Ul}/bot/raw`,{method:"POST",body:JSON.stringify({raw_content:n})})).json();if(!c.success)throw new Error(c.message||"保存配置失败")}async function eo(n){const c=await(await Te(`${Ul}/model`,{method:"POST",body:JSON.stringify(n)})).json();if(!c.success)throw new Error(c.message||"保存配置失败")}async function _0(n,r){const d=await(await Te(`${Ul}/bot/section/${n}`,{method:"POST",body:JSON.stringify(r)})).json();if(!d.success)throw new Error(d.message||`保存配置节 ${n} 失败`)}async function Ou(n,r){const d=await(await Te(`${Ul}/model/section/${n}`,{method:"POST",body:JSON.stringify(r)})).json();if(!d.success)throw new Error(d.message||`保存配置节 ${n} 失败`)}async function S0(n,r="openai",c="/models"){const d=new URLSearchParams({provider_name:n,parser:r,endpoint:c}),h=await Te(`/api/webui/models/list?${d}`);if(!h.ok){const f=await h.json().catch(()=>({}));throw new Error(f.detail||`获取模型列表失败 (${h.status})`)}const x=await h.json();if(!x.success)throw new Error("获取模型列表失败");return x.models}async function C0(n){const r=new URLSearchParams({provider_name:n}),c=await Te(`/api/webui/models/test-connection-by-name?${r}`,{method:"POST"});if(!c.ok){const d=await c.json().catch(()=>({}));throw new Error(d.detail||`测试连接失败 (${c.status})`)}return await c.json()}const k0=si("relative w-full rounded-lg border px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7",{variants:{variant:{default:"bg-background text-foreground",destructive:"border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive"}},defaultVariants:{variant:"default"}}),cl=u.forwardRef(({className:n,variant:r,...c},d)=>e.jsx("div",{ref:d,role:"alert",className:Q(k0({variant:r}),n),...c}));cl.displayName="Alert";const T0=u.forwardRef(({className:n,...r},c)=>e.jsx("h5",{ref:c,className:Q("mb-1 font-medium leading-none tracking-tight",n),...r}));T0.displayName="AlertTitle";const ol=u.forwardRef(({className:n,...r},c)=>e.jsx("div",{ref:c,className:Q("text-sm [&_p]:leading-relaxed",n),...r}));ol.displayName="AlertDescription";function Yu({onRestartComplete:n,onRestartFailed:r}){const[c,d]=u.useState(0),[h,x]=u.useState("restarting"),[f,j]=u.useState(0),[p,N]=u.useState(0);u.useEffect(()=>{const S=setInterval(()=>{d(F=>F>=90?F:F+1)},200),w=setInterval(()=>{j(F=>F+1)},1e3),L=setTimeout(()=>{x("checking"),v()},3e3);return()=>{clearInterval(S),clearInterval(w),clearTimeout(L)}},[]);const v=()=>{const w=async()=>{try{if(N(F=>F+1),(await fetch("/api/webui/system/status",{method:"GET",headers:{"Content-Type":"application/json"},signal:AbortSignal.timeout(3e3)})).ok)d(100),x("success"),setTimeout(()=>{n?.()},1500);else throw new Error("Status check failed")}catch{p<60?setTimeout(w,2e3):(x("failed"),r?.())}};w()},C=S=>{const w=Math.floor(S/60),L=S%60;return`${w}:${L.toString().padStart(2,"0")}`};return e.jsx("div",{className:"fixed inset-0 bg-background/95 backdrop-blur-sm z-50 flex items-center justify-center",children:e.jsxs("div",{className:"max-w-md w-full mx-4 space-y-8",children:[e.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[h==="restarting"&&e.jsxs(e.Fragment,{children:[e.jsx(Ss,{className:"h-16 w-16 text-primary animate-spin"}),e.jsx("h2",{className:"text-2xl font-bold",children:"正在重启麦麦"}),e.jsx("p",{className:"text-muted-foreground text-center",children:"请稍候,麦麦正在重启中..."})]}),h==="checking"&&e.jsxs(e.Fragment,{children:[e.jsx(Ss,{className:"h-16 w-16 text-primary animate-spin"}),e.jsx("h2",{className:"text-2xl font-bold",children:"检查服务状态"}),e.jsxs("p",{className:"text-muted-foreground text-center",children:["等待服务恢复... (尝试 ",p,"/60)"]})]}),h==="success"&&e.jsxs(e.Fragment,{children:[e.jsx(ha,{className:"h-16 w-16 text-green-500"}),e.jsx("h2",{className:"text-2xl font-bold",children:"重启成功"}),e.jsx("p",{className:"text-muted-foreground text-center",children:"正在跳转到登录页面..."})]}),h==="failed"&&e.jsxs(e.Fragment,{children:[e.jsx(Oa,{className:"h-16 w-16 text-destructive"}),e.jsx("h2",{className:"text-2xl font-bold",children:"重启超时"}),e.jsx("p",{className:"text-muted-foreground text-center",children:"服务未能在预期时间内恢复,请手动检查或刷新页面"})]})]}),h!=="failed"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(yr,{value:c,className:"h-2"}),e.jsxs("div",{className:"flex justify-between text-sm text-muted-foreground",children:[e.jsxs("span",{children:[c,"%"]}),e.jsxs("span",{children:["已用时: ",C(f)]})]})]}),e.jsx("div",{className:"bg-muted/50 rounded-lg p-4 space-y-2",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:[h==="restarting"&&"🔄 配置已保存,正在重启主程序...",h==="checking"&&"⏳ 正在等待服务恢复,请勿关闭页面...",h==="success"&&"✅ 配置已生效,服务运行正常",h==="failed"&&"⚠️ 如果长时间无响应,请尝试手动重启"]})}),h==="failed"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>window.location.reload(),className:"flex-1 px-4 py-2 bg-primary text-primary-foreground rounded-md hover:bg-primary/90",children:"刷新页面"}),e.jsx("button",{onClick:()=>{x("checking"),N(0),v()},className:"flex-1 px-4 py-2 bg-secondary text-secondary-foreground rounded-md hover:bg-secondary/90",children:"重试检测"})]})]})})}const E0={name:"toml",startState:function(){return{inString:!1,stringType:"",lhs:!0,inArray:0}},token:function(n,r){let c;if(!r.inString&&(c=n.match(/^('''|"""|'|")/))&&(r.stringType=c[0],r.inString=!0),n.sol()&&!r.inString&&r.inArray===0&&(r.lhs=!0),r.inString){for(;r.inString;)if(n.match(r.stringType))r.inString=!1;else if(n.peek()==="\\")n.next(),n.next();else{if(n.eol())break;n.match(/^.[^\\\"\']*/)}return r.lhs?"property":"string"}else{if(r.inArray&&n.peek()==="]")return n.next(),r.inArray--,"bracket";if(r.lhs&&n.peek()==="["&&n.skipTo("]"))return n.next(),n.peek()==="]"&&n.next(),"atom";if(n.peek()==="#")return n.skipToEnd(),"comment";if(n.eatSpace())return null;if(r.lhs&&n.eatWhile(function(d){return d!="="&&d!=" "}))return"property";if(r.lhs&&n.peek()==="=")return n.next(),r.lhs=!1,null;if(!r.lhs&&n.match(/^\d\d\d\d[\d\-\:\.T]*Z/))return"atom";if(!r.lhs&&(n.match("true")||n.match("false")))return"atom";if(!r.lhs&&n.peek()==="[")return r.inArray++,n.next(),"bracket";if(!r.lhs&&n.match(/^\-?\d+(?:\.\d+)?/))return"number";n.eatSpace()||n.next()}return null},languageData:{commentTokens:{line:"#"}}},z0={python:[By()],json:[Hy(),qy()],toml:[Uy.define(E0)],text:[]};function A0({value:n,onChange:r,language:c="text",readOnly:d=!1,height:h="400px",minHeight:x,maxHeight:f,placeholder:j,theme:p="dark",className:N=""}){const[v,C]=u.useState(!1);if(u.useEffect(()=>{C(!0)},[]),!v)return e.jsx("div",{className:`rounded-md border bg-muted animate-pulse ${N}`,style:{height:h,minHeight:x,maxHeight:f}});const S=[...z0[c]||[],Qf.lineWrapping];return d&&S.push(Qf.editable.of(!1)),e.jsx("div",{className:`rounded-md overflow-hidden border ${N}`,children:e.jsx(Gy,{value:n,height:h,minHeight:x,maxHeight:f,theme:p==="dark"?Vy:void 0,extensions:S,onChange:r,placeholder:j,basicSetup:{lineNumbers:!0,highlightActiveLineGutter:!0,highlightSpecialChars:!0,history:!0,foldGutter:!0,drawSelection:!0,dropCursor:!0,allowMultipleSelections:!0,indentOnInput:!0,syntaxHighlighting:!0,bracketMatching:!0,closeBrackets:!0,autocompletion:!0,rectangularSelection:!0,crosshairCursor:!0,highlightActiveLine:!0,highlightSelectionMatches:!0,closeBracketsKeymap:!0,defaultKeymap:!0,searchKeymap:!0,historyKeymap:!0,foldKeymap:!0,completionKeymap:!0,lintKeymap:!0}})})}function M0(){const[n,r]=u.useState(!0),[c,d]=u.useState(!1),[h,x]=u.useState(!1),[f,j]=u.useState(!1),[p,N]=u.useState(!1),[v,C]=u.useState(!1),[S,w]=u.useState("visual"),[L,F]=u.useState(""),[B,O]=u.useState(!1),{toast:K}=Xt(),[H,z]=u.useState(null),[V,Y]=u.useState(null),[E,R]=u.useState(null),[ne,fe]=u.useState(null),[Ce,we]=u.useState(null),[pe,Ne]=u.useState(null),[be,A]=u.useState(null),[X,T]=u.useState(null),[te,_]=u.useState(null),[me,oe]=u.useState(null),[ae,xe]=u.useState(null),[ve,de]=u.useState(null),[G,W]=u.useState(null),[U,ee]=u.useState(null),[Se,Me]=u.useState(null),[tt,Xe]=u.useState(null),[Ut,Bt]=u.useState(null),[re,ke]=u.useState(null),Pe=u.useRef(null),Fe=u.useRef(!0),ts=u.useRef({}),As=u.useCallback(async()=>{try{const _e=await N0();F(_e),O(!1)}catch(_e){K({variant:"destructive",title:"加载失败",description:_e instanceof Error?_e.message:"加载源代码失败"})}},[K]),js=u.useCallback(async()=>{try{r(!0);const _e=await sp();ts.current=_e,z(_e.bot),Y(_e.personality);const je=_e.chat;je.talk_value_rules||(je.talk_value_rules=[]),R(je),fe(_e.expression),we(_e.emoji),Ne(_e.memory),A(_e.tool),T(_e.mood),_(_e.voice),oe(_e.lpmm_knowledge),xe(_e.keyword_reaction),de(_e.response_post_process),W(_e.chinese_typo),ee(_e.response_splitter),Me(_e.log),Xe(_e.debug),Bt(_e.maim_message),ke(_e.telemetry),j(!1),Fe.current=!1,await As()}catch(_e){console.error("加载配置失败:",_e),K({title:"加载失败",description:"无法加载配置文件",variant:"destructive"})}finally{r(!1)}},[K,As]);u.useEffect(()=>{js()},[js]);const Ke=u.useCallback(async(_e,je)=>{if(!Fe.current)try{x(!0),await _0(_e,je),j(!1)}catch(yt){console.error(`自动保存 ${_e} 失败:`,yt),j(!0)}finally{x(!1)}},[]),D=u.useCallback((_e,je)=>{Fe.current||(j(!0),Pe.current&&clearTimeout(Pe.current),Pe.current=setTimeout(()=>{Ke(_e,je)},2e3))},[Ke]);u.useEffect(()=>{H&&!Fe.current&&D("bot",H)},[H,D]),u.useEffect(()=>{V&&!Fe.current&&D("personality",V)},[V,D]),u.useEffect(()=>{E&&!Fe.current&&D("chat",E)},[E,D]),u.useEffect(()=>{ne&&!Fe.current&&D("expression",ne)},[ne,D]),u.useEffect(()=>{Ce&&!Fe.current&&D("emoji",Ce)},[Ce,D]),u.useEffect(()=>{pe&&!Fe.current&&D("memory",pe)},[pe,D]),u.useEffect(()=>{be&&!Fe.current&&D("tool",be)},[be,D]),u.useEffect(()=>{X&&!Fe.current&&D("mood",X)},[X,D]),u.useEffect(()=>{te&&!Fe.current&&D("voice",te)},[te,D]),u.useEffect(()=>{me&&!Fe.current&&D("lpmm_knowledge",me)},[me,D]),u.useEffect(()=>{ae&&!Fe.current&&D("keyword_reaction",ae)},[ae,D]),u.useEffect(()=>{ve&&!Fe.current&&D("response_post_process",ve)},[ve,D]),u.useEffect(()=>{G&&!Fe.current&&D("chinese_typo",G)},[G,D]),u.useEffect(()=>{U&&!Fe.current&&D("response_splitter",U)},[U,D]),u.useEffect(()=>{Se&&!Fe.current&&D("log",Se)},[Se,D]),u.useEffect(()=>{tt&&!Fe.current&&D("debug",tt)},[tt,D]),u.useEffect(()=>{Ut&&!Fe.current&&D("maim_message",Ut)},[Ut,D]),u.useEffect(()=>{re&&!Fe.current&&D("telemetry",re)},[re,D]);const De=async()=>{try{d(!0),await w0(L),j(!1),O(!1),K({title:"保存成功",description:"配置已保存"}),await js()}catch(_e){O(!0),K({variant:"destructive",title:"保存失败",description:_e instanceof Error?_e.message:"保存配置失败"})}finally{d(!1)}},ze=async _e=>{if(f){K({variant:"destructive",title:"切换失败",description:"请先保存当前更改"});return}if(w(_e),_e==="source")await As();else try{const je=await sp();ts.current=je,z(je.bot),Y(je.personality);const yt=je.chat;yt.talk_value_rules||(yt.talk_value_rules=[]),R(yt),fe(je.expression),we(je.emoji),Ne(je.memory),A(je.tool),T(je.mood),_(je.voice),oe(je.lpmm_knowledge),xe(je.keyword_reaction),de(je.response_post_process),W(je.chinese_typo),ee(je.response_splitter),Me(je.log),Xe(je.debug),Bt(je.maim_message),ke(je.telemetry),j(!1)}catch(je){console.error("加载配置失败:",je),K({title:"加载失败",description:"无法加载配置文件",variant:"destructive"})}},Ve=async()=>{try{d(!0),Pe.current&&clearTimeout(Pe.current);const _e={...ts.current,bot:H,personality:V,chat:E,expression:ne,emoji:Ce,memory:pe,tool:be,mood:X,voice:te,lpmm_knowledge:me,keyword_reaction:ae,response_post_process:ve,chinese_typo:G,response_splitter:U,log:Se,debug:tt,maim_message:Ut,telemetry:re};await ap(_e),j(!1),K({title:"保存成功",description:"麦麦主程序配置已保存"})}catch(_e){console.error("保存配置失败:",_e),K({title:"保存失败",description:_e.message,variant:"destructive"})}finally{d(!1)}},At=async()=>{try{N(!0),so().catch(()=>{}),C(!0)}catch(_e){console.error("重启失败:",_e),C(!1),K({title:"重启失败",description:"无法发送重启请求,请手动重启",variant:"destructive"}),N(!1)}},We=async()=>{try{d(!0),Pe.current&&clearTimeout(Pe.current);const _e={...ts.current,bot:H,personality:V,chat:E,expression:ne,emoji:Ce,memory:pe,tool:be,mood:X,voice:te,lpmm_knowledge:me,keyword_reaction:ae,response_post_process:ve,chinese_typo:G,response_splitter:U,log:Se,debug:tt,maim_message:Ut,telemetry:re};await ap(_e),j(!1),K({title:"保存成功",description:"配置已保存,即将重启麦麦..."}),await new Promise(je=>setTimeout(je,500)),await At()}catch(_e){console.error("保存失败:",_e),K({title:"保存失败",description:_e.message,variant:"destructive"})}finally{d(!1)}},ss=()=>{localStorage.removeItem("access-token"),window.location.href="/auth"},gt=()=>{C(!1),N(!1),K({title:"重启失败",description:"服务器未能在预期时间内恢复,请手动检查",variant:"destructive"})};return n?e.jsx(st,{className:"h-full",children:e.jsx("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("p",{className:"text-muted-foreground",children:"加载中..."})})})}):e.jsx(st,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:gap-4",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-xl sm:text-2xl md:text-3xl font-bold",children:"麦麦主程序配置"}),e.jsx("p",{className:"text-muted-foreground mt-1 text-xs sm:text-sm",children:"管理麦麦的核心功能和行为设置"})]}),e.jsxs("div",{className:"flex gap-2 flex-shrink-0",children:[e.jsxs(b,{onClick:S==="visual"?Ve:De,disabled:c||h||!f||p,size:"sm",variant:"outline",className:"w-20 sm:w-24",children:[e.jsx(jr,{className:"h-4 w-4 flex-shrink-0",strokeWidth:2,fill:"none"}),e.jsx("span",{className:"ml-1 truncate text-xs sm:text-sm",children:c?"保存中":h?"自动":f?"保存":"已保存"})]}),e.jsxs(bt,{children:[e.jsx(es,{asChild:!0,children:e.jsxs(b,{disabled:c||h||p,size:"sm",className:"w-20 sm:w-28",children:[e.jsx(gr,{className:"h-4 w-4 flex-shrink-0"}),e.jsx("span",{className:"ml-1 truncate text-xs sm:text-sm",children:p?"重启中":f?"保存重启":"重启"})]})}),e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认重启麦麦?"}),e.jsx(xt,{asChild:!0,children:e.jsx("div",{children:e.jsx("p",{children:f?"当前有未保存的配置更改。点击确认将先保存配置,然后重启麦麦使新配置生效。重启过程中麦麦将暂时离线。":"即将重启麦麦主程序。重启过程中麦麦将暂时离线,配置将在重启后生效。"})})})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:f?We:At,children:f?"保存并重启":"确认重启"})]})]})]})]})]}),e.jsx("div",{className:"flex",children:e.jsx(La,{value:S,onValueChange:_e=>ze(_e),className:"w-full",children:e.jsxs(wa,{className:"h-8 sm:h-9 w-full grid grid-cols-2",children:[e.jsxs(it,{value:"visual",className:"text-xs sm:text-sm",children:[e.jsx(py,{className:"h-3 w-3 sm:h-4 sm:w-4 mr-1"}),"可视化编辑"]}),e.jsxs(it,{value:"source",className:"text-xs sm:text-sm",children:[e.jsx(gy,{className:"h-3 w-3 sm:h-4 sm:w-4 mr-1"}),"源代码编辑"]})]})})})]}),e.jsxs(cl,{children:[e.jsx(Ra,{className:"h-4 w-4"}),e.jsxs(ol,{children:["配置更新后需要",e.jsx("strong",{children:"重启麦麦"}),'才能生效。你可以点击右上角的"保存并重启"按钮一键完成保存和重启。']})]}),S==="source"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(cl,{children:[e.jsx(Ra,{className:"h-4 w-4"}),e.jsxs(ol,{children:[e.jsx("strong",{children:"源代码模式(高级功能):"}),"直接编辑 TOML 配置文件。此功能仅适用于熟悉 TOML 语法的高级用户。保存时会在后端验证格式,只有格式完全正确才能保存。",B&&e.jsx("span",{className:"text-destructive font-semibold ml-2",children:"⚠️ 上次保存失败,请检查 TOML 格式"})]})]}),e.jsx(A0,{value:L,onChange:_e=>{F(_e),j(!0),B&&O(!1)},language:"toml",theme:"dark",height:"calc(100vh - 280px)",minHeight:"500px",placeholder:"TOML 配置内容"})]}),S==="visual"&&e.jsx(e.Fragment,{children:e.jsxs(La,{defaultValue:"bot",className:"w-full",children:[e.jsxs(wa,{className:"flex flex-wrap h-auto gap-1 p-1 sm:grid sm:grid-cols-5 lg:grid-cols-10",children:[e.jsx(it,{value:"bot",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"基本信息"}),e.jsx(it,{value:"personality",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"人格"}),e.jsx(it,{value:"chat",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"聊天"}),e.jsx(it,{value:"expression",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"表达"}),e.jsx(it,{value:"features",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"功能"}),e.jsx(it,{value:"processing",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"处理"}),e.jsx(it,{value:"mood",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"情绪"}),e.jsx(it,{value:"voice",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"语音"}),e.jsx(it,{value:"lpmm",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"知识库"}),e.jsx(it,{value:"other",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"其他"})]}),e.jsx(zt,{value:"bot",className:"space-y-4",children:H&&e.jsx(D0,{config:H,onChange:z})}),e.jsx(zt,{value:"personality",className:"space-y-4",children:V&&e.jsx(O0,{config:V,onChange:Y})}),e.jsx(zt,{value:"chat",className:"space-y-4",children:E&&e.jsx(R0,{config:E,onChange:R})}),e.jsx(zt,{value:"expression",className:"space-y-4",children:ne&&e.jsx(U0,{config:ne,onChange:fe})}),e.jsx(zt,{value:"features",className:"space-y-4",children:Ce&&pe&&be&&e.jsx(B0,{emojiConfig:Ce,memoryConfig:pe,toolConfig:be,onEmojiChange:we,onMemoryChange:Ne,onToolChange:A})}),e.jsx(zt,{value:"processing",className:"space-y-4",children:ae&&ve&&G&&U&&e.jsx(H0,{keywordReactionConfig:ae,responsePostProcessConfig:ve,chineseTypoConfig:G,responseSplitterConfig:U,onKeywordReactionChange:xe,onResponsePostProcessChange:de,onChineseTypoChange:W,onResponseSplitterChange:ee})}),e.jsx(zt,{value:"mood",className:"space-y-4",children:X&&e.jsx(q0,{config:X,onChange:T})}),e.jsx(zt,{value:"voice",className:"space-y-4",children:te&&e.jsx(G0,{config:te,onChange:_})}),e.jsx(zt,{value:"lpmm",className:"space-y-4",children:me&&e.jsx(V0,{config:me,onChange:oe})}),e.jsxs(zt,{value:"other",className:"space-y-4",children:[Se&&e.jsx(F0,{config:Se,onChange:Me}),tt&&e.jsx($0,{config:tt,onChange:Xe}),Ut&&e.jsx(Q0,{config:Ut,onChange:Bt}),re&&e.jsx(Y0,{config:re,onChange:ke})]})]})}),v&&e.jsx(Yu,{onRestartComplete:ss,onRestartFailed:gt})]})})}function D0({config:n,onChange:r}){const c=()=>{r({...n,platforms:[...n.platforms,""]})},d=p=>{r({...n,platforms:n.platforms.filter((N,v)=>v!==p)})},h=(p,N)=>{const v=[...n.platforms];v[p]=N,r({...n,platforms:v})},x=()=>{r({...n,alias_names:[...n.alias_names,""]})},f=p=>{r({...n,alias_names:n.alias_names.filter((N,v)=>v!==p)})},j=(p,N)=>{const v=[...n.alias_names];v[p]=N,r({...n,alias_names:v})};return e.jsx("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"基本信息"}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"platform",children:"平台"}),e.jsx(ce,{id:"platform",value:n.platform,onChange:p=>r({...n,platform:p.target.value}),placeholder:"qq"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"qq_account",children:"QQ账号"}),e.jsx(ce,{id:"qq_account",value:n.qq_account,onChange:p=>r({...n,qq_account:p.target.value}),placeholder:"123456789"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"nickname",children:"昵称"}),e.jsx(ce,{id:"nickname",value:n.nickname,onChange:p=>r({...n,nickname:p.target.value}),placeholder:"麦麦"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(y,{children:"其他平台账号"}),e.jsxs(b,{onClick:c,size:"sm",variant:"outline",children:[e.jsx(hs,{className:"h-4 w-4 mr-1"}),"添加"]})]}),e.jsxs("div",{className:"space-y-2",children:[n.platforms.map((p,N)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ce,{value:p,onChange:v=>h(N,v.target.value),placeholder:"wx:114514"}),e.jsxs(bt,{children:[e.jsx(es,{asChild:!0,children:e.jsx(b,{size:"icon",variant:"outline",children:e.jsx(at,{className:"h-4 w-4"})})}),e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认删除"}),e.jsxs(xt,{children:['确定要删除平台账号 "',p||"(空)",'" 吗?此操作无法撤销。']})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:()=>d(N),children:"删除"})]})]})]})]},N)),n.platforms.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"暂无其他平台账号"})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(y,{children:"别名"}),e.jsxs(b,{onClick:x,size:"sm",variant:"outline",children:[e.jsx(hs,{className:"h-4 w-4 mr-1"}),"添加"]})]}),e.jsxs("div",{className:"space-y-2",children:[n.alias_names.map((p,N)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ce,{value:p,onChange:v=>j(N,v.target.value),placeholder:"小麦"}),e.jsxs(bt,{children:[e.jsx(es,{asChild:!0,children:e.jsx(b,{size:"icon",variant:"outline",children:e.jsx(at,{className:"h-4 w-4"})})}),e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认删除"}),e.jsxs(xt,{children:['确定要删除别名 "',p||"(空)",'" 吗?此操作无法撤销。']})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:()=>f(N),children:"删除"})]})]})]})]},N)),n.alias_names.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"暂无别名"})]})]})]})]})})}function O0({config:n,onChange:r}){const c=()=>{r({...n,states:[...n.states,""]})},d=x=>{r({...n,states:n.states.filter((f,j)=>j!==x)})},h=(x,f)=>{const j=[...n.states];j[x]=f,r({...n,states:j})};return e.jsx("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"人格设置"}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"personality",children:"人格特质"}),e.jsx(Ft,{id:"personality",value:n.personality,onChange:x=>r({...n,personality:x.target.value}),placeholder:"描述人格特质和身份特征(建议120字以内)",rows:3}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"建议120字以内,描述人格特质和身份特征"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"reply_style",children:"表达风格"}),e.jsx(Ft,{id:"reply_style",value:n.reply_style,onChange:x=>r({...n,reply_style:x.target.value}),placeholder:"描述说话的表达风格和习惯",rows:3})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"interest",children:"兴趣"}),e.jsx(Ft,{id:"interest",value:n.interest,onChange:x=>r({...n,interest:x.target.value}),placeholder:"会影响麦麦对什么话题进行回复",rows:2})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"plan_style",children:"说话规则与行为风格"}),e.jsx(Ft,{id:"plan_style",value:n.plan_style,onChange:x=>r({...n,plan_style:x.target.value}),placeholder:"麦麦的说话规则和行为风格",rows:5})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"visual_style",children:"识图规则"}),e.jsx(Ft,{id:"visual_style",value:n.visual_style,onChange:x=>r({...n,visual_style:x.target.value}),placeholder:"识图时的处理规则",rows:3})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"private_plan_style",children:"私聊规则"}),e.jsx(Ft,{id:"private_plan_style",value:n.private_plan_style,onChange:x=>r({...n,private_plan_style:x.target.value}),placeholder:"私聊的说话规则和行为风格",rows:4})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(y,{children:"状态列表(人格多样性)"}),e.jsxs(b,{onClick:c,size:"sm",variant:"outline",children:[e.jsx(hs,{className:"h-4 w-4 mr-1"}),"添加状态"]})]}),e.jsx("div",{className:"space-y-2",children:n.states.map((x,f)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ft,{value:x,onChange:j=>h(f,j.target.value),placeholder:"描述一个人格状态",rows:2}),e.jsxs(bt,{children:[e.jsx(es,{asChild:!0,children:e.jsx(b,{size:"icon",variant:"outline",children:e.jsx(at,{className:"h-4 w-4"})})}),e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认删除"}),e.jsx(xt,{children:"确定要删除这个人格状态吗?此操作无法撤销。"})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:()=>d(f),children:"删除"})]})]})]})]},f))})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"state_probability",children:"状态替换概率"}),e.jsx(ce,{id:"state_probability",type:"number",step:"0.1",min:"0",max:"1",value:n.state_probability,onChange:x=>r({...n,state_probability:parseFloat(x.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"每次构建人格时替换 personality 的概率(0.0-1.0)"})]})]})]})})}function R0({config:n,onChange:r}){const c=()=>{r({...n,talk_value_rules:[...n.talk_value_rules,{target:"",time:"00:00-23:59",value:1}]})},d=j=>{r({...n,talk_value_rules:n.talk_value_rules.filter((p,N)=>N!==j)})},h=(j,p,N)=>{const v=[...n.talk_value_rules];v[j]={...v[j],[p]:N},r({...n,talk_value_rules:v})},x=({value:j,onChange:p})=>{const[N,v]=u.useState("00"),[C,S]=u.useState("00"),[w,L]=u.useState("23"),[F,B]=u.useState("59");u.useEffect(()=>{const K=j.split("-");if(K.length===2){const[H,z]=K,[V,Y]=H.split(":"),[E,R]=z.split(":");V&&v(V.padStart(2,"0")),Y&&S(Y.padStart(2,"0")),E&&L(E.padStart(2,"0")),R&&B(R.padStart(2,"0"))}},[j]);const O=(K,H,z,V)=>{const Y=`${K}:${H}-${z}:${V}`;p(Y)};return e.jsxs(Ua,{children:[e.jsx(Ba,{asChild:!0,children:e.jsxs(b,{variant:"outline",className:"w-full justify-start font-mono text-sm",children:[e.jsx(Wn,{className:"h-4 w-4 mr-2"}),j||"选择时间段"]})}),e.jsx(_a,{className:"w-72 sm:w-80",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium text-sm mb-3",children:"开始时间"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:gap-3",children:[e.jsxs("div",{children:[e.jsx(y,{className:"text-xs",children:"小时"}),e.jsxs(qe,{value:N,onValueChange:K=>{v(K),O(K,C,w,F)},children:[e.jsx(Be,{children:e.jsx(Ge,{})}),e.jsx(He,{children:Array.from({length:24},(K,H)=>H).map(K=>e.jsx(ie,{value:K.toString().padStart(2,"0"),children:K.toString().padStart(2,"0")},K))})]})]}),e.jsxs("div",{children:[e.jsx(y,{className:"text-xs",children:"分钟"}),e.jsxs(qe,{value:C,onValueChange:K=>{S(K),O(N,K,w,F)},children:[e.jsx(Be,{children:e.jsx(Ge,{})}),e.jsx(He,{children:Array.from({length:60},(K,H)=>H).map(K=>e.jsx(ie,{value:K.toString().padStart(2,"0"),children:K.toString().padStart(2,"0")},K))})]})]})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium text-sm mb-3",children:"结束时间"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:gap-3",children:[e.jsxs("div",{children:[e.jsx(y,{className:"text-xs",children:"小时"}),e.jsxs(qe,{value:w,onValueChange:K=>{L(K),O(N,C,K,F)},children:[e.jsx(Be,{children:e.jsx(Ge,{})}),e.jsx(He,{children:Array.from({length:24},(K,H)=>H).map(K=>e.jsx(ie,{value:K.toString().padStart(2,"0"),children:K.toString().padStart(2,"0")},K))})]})]}),e.jsxs("div",{children:[e.jsx(y,{className:"text-xs",children:"分钟"}),e.jsxs(qe,{value:F,onValueChange:K=>{B(K),O(N,C,w,K)},children:[e.jsx(Be,{children:e.jsx(Ge,{})}),e.jsx(He,{children:Array.from({length:60},(K,H)=>H).map(K=>e.jsx(ie,{value:K.toString().padStart(2,"0"),children:K.toString().padStart(2,"0")},K))})]})]})]})]})]})})]})},f=({rule:j})=>{const p=`{ target = "${j.target}", time = "${j.time}", value = ${j.value.toFixed(1)} }`;return e.jsxs(Ua,{children:[e.jsx(Ba,{asChild:!0,children:e.jsxs(b,{variant:"outline",size:"sm",children:[e.jsx(Ws,{className:"h-4 w-4 mr-1"}),"预览"]})}),e.jsx(_a,{className:"w-80 sm:w-96",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-sm",children:"配置预览"}),e.jsx("div",{className:"rounded-md bg-muted p-3 font-mono text-xs break-all",children:p}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"这是保存到 bot_config.toml 文件中的格式"})]})})]})};return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"聊天设置"}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"talk_value",children:"聊天频率(基础值)"}),e.jsx(ce,{id:"talk_value",type:"number",step:"0.1",min:"0",max:"1",value:n.talk_value,onChange:j=>r({...n,talk_value:parseFloat(j.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"越小越沉默,范围 0-1"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Qe,{id:"mentioned_bot_reply",checked:n.mentioned_bot_reply,onCheckedChange:j=>r({...n,mentioned_bot_reply:j})}),e.jsx(y,{htmlFor:"mentioned_bot_reply",className:"cursor-pointer",children:"启用提及必回复"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"max_context_size",children:"上下文长度"}),e.jsx(ce,{id:"max_context_size",type:"number",min:"1",value:n.max_context_size,onChange:j=>r({...n,max_context_size:parseInt(j.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"planner_smooth",children:"规划器平滑"}),e.jsx(ce,{id:"planner_smooth",type:"number",step:"1",min:"0",value:n.planner_smooth,onChange:j=>r({...n,planner_smooth:parseFloat(j.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"增大数值会减小 planner 负荷,推荐 1-5,0 为关闭"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Qe,{id:"enable_talk_value_rules",checked:n.enable_talk_value_rules,onCheckedChange:j=>r({...n,enable_talk_value_rules:j})}),e.jsx(y,{htmlFor:"enable_talk_value_rules",className:"cursor-pointer",children:"启用动态发言频率规则"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Qe,{id:"include_planner_reasoning",checked:n.include_planner_reasoning,onCheckedChange:j=>r({...n,include_planner_reasoning:j})}),e.jsx(y,{htmlFor:"include_planner_reasoning",className:"cursor-pointer",children:"将 planner 推理加入 replyer"})]})]})]}),n.enable_talk_value_rules&&e.jsxs("div",{className:"border-t pt-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-base font-semibold",children:"动态发言频率规则"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"按时段或聊天流ID调整发言频率,优先匹配具体聊天,再匹配全局规则"})]}),e.jsxs(b,{onClick:c,size:"sm",children:[e.jsx(hs,{className:"h-4 w-4 mr-1"}),"添加规则"]})]}),n.talk_value_rules&&n.talk_value_rules.length>0?e.jsx("div",{className:"space-y-4",children:n.talk_value_rules.map((j,p)=>e.jsxs("div",{className:"rounded-lg border p-4 bg-muted/50 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm font-medium text-muted-foreground",children:["规则 #",p+1]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{rule:j}),e.jsxs(bt,{children:[e.jsx(es,{asChild:!0,children:e.jsx(b,{variant:"ghost",size:"sm",children:e.jsx(at,{className:"h-4 w-4 text-destructive"})})}),e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认删除"}),e.jsxs(xt,{children:["确定要删除规则 #",p+1," 吗?此操作无法撤销。"]})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:()=>d(p),children:"删除"})]})]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{className:"text-xs font-medium",children:"配置类型"}),e.jsxs(qe,{value:j.target===""?"global":"specific",onValueChange:N=>{N==="global"?h(p,"target",""):h(p,"target","qq::group")},children:[e.jsx(Be,{children:e.jsx(Ge,{})}),e.jsxs(He,{children:[e.jsx(ie,{value:"global",children:"全局配置"}),e.jsx(ie,{value:"specific",children:"详细配置"})]})]})]}),j.target!==""&&(()=>{const N=j.target.split(":"),v=N[0]||"qq",C=N[1]||"",S=N[2]||"group";return e.jsxs("div",{className:"grid gap-4 p-3 sm:p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{className:"text-xs font-medium",children:"平台"}),e.jsxs(qe,{value:v,onValueChange:w=>{h(p,"target",`${w}:${C}:${S}`)},children:[e.jsx(Be,{children:e.jsx(Ge,{})}),e.jsxs(He,{children:[e.jsx(ie,{value:"qq",children:"QQ"}),e.jsx(ie,{value:"wx",children:"微信"})]})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{className:"text-xs font-medium",children:"群 ID"}),e.jsx(ce,{value:C,onChange:w=>{h(p,"target",`${v}:${w.target.value}:${S}`)},placeholder:"输入群 ID",className:"font-mono text-sm"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{className:"text-xs font-medium",children:"类型"}),e.jsxs(qe,{value:S,onValueChange:w=>{h(p,"target",`${v}:${C}:${w}`)},children:[e.jsx(Be,{children:e.jsx(Ge,{})}),e.jsxs(He,{children:[e.jsx(ie,{value:"group",children:"群组(group)"}),e.jsx(ie,{value:"private",children:"私聊(private)"})]})]})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["当前聊天流 ID:",j.target||"(未设置)"]})]})})(),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{className:"text-xs font-medium",children:"时间段 (Time)"}),e.jsx(x,{value:j.time,onChange:N=>h(p,"time",N)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"支持跨夜区间,例如 23:00-02:00"})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(y,{htmlFor:`rule-value-${p}`,className:"text-xs font-medium",children:"发言频率值 (Value)"}),e.jsx(ce,{id:`rule-value-${p}`,type:"number",step:"0.01",min:"0.01",max:"1",value:j.value,onChange:N=>{const v=parseFloat(N.target.value);isNaN(v)||h(p,"value",Math.max(.01,Math.min(1,v)))},className:"w-20 h-8 text-xs"})]}),e.jsx(Ma,{value:[j.value],onValueChange:N=>h(p,"value",N[0]),min:.01,max:1,step:.01,className:"w-full"}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:"0.01 (极少发言)"}),e.jsx("span",{children:"0.5"}),e.jsx("span",{children:"1.0 (正常)"})]})]})]})]},p))}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:e.jsx("p",{className:"text-sm",children:'暂无规则,点击"添加规则"按钮创建'})}),e.jsxs("div",{className:"mt-4 p-4 bg-blue-50 dark:bg-blue-950/20 border border-blue-200 dark:border-blue-800 rounded-lg",children:[e.jsx("h5",{className:"text-sm font-semibold text-blue-900 dark:text-blue-100 mb-2",children:"📝 规则说明"}),e.jsxs("ul",{className:"text-xs text-blue-800 dark:text-blue-200 space-y-1",children:[e.jsxs("li",{children:["• ",e.jsx("strong",{children:"Target 为空"}),":全局规则,对所有聊天生效"]}),e.jsxs("li",{children:["• ",e.jsx("strong",{children:"Target 指定"}),":仅对特定聊天流生效(格式:platform:id:type)"]}),e.jsxs("li",{children:["• ",e.jsx("strong",{children:"优先级"}),":先匹配具体聊天流规则,再匹配全局规则"]}),e.jsxs("li",{children:["• ",e.jsx("strong",{children:"时间支持跨夜"}),":例如 23:00-02:00 表示晚上11点到次日凌晨2点"]}),e.jsxs("li",{children:["• ",e.jsx("strong",{children:"数值范围"}),":建议 0-1,0 表示完全沉默,1 表示正常发言"]})]})]})]})]})}function L0({member:n,groupIndex:r,memberIndex:c,availableChatIds:d,onUpdate:h,onRemove:x}){const f=d.includes(n)||n==="*",[j,p]=u.useState(!f);return e.jsxs("div",{className:"flex gap-2",children:[e.jsx("div",{className:"flex-1 flex gap-2",children:j?e.jsxs(e.Fragment,{children:[e.jsx(ce,{value:n,onChange:N=>h(r,c,N.target.value),placeholder:'输入 "*" 或 "qq:123456:group"',className:"flex-1"}),d.length>0&&e.jsx(b,{size:"sm",variant:"outline",onClick:()=>p(!1),title:"切换到下拉选择",children:"下拉"})]}):e.jsxs(e.Fragment,{children:[e.jsxs(qe,{value:n,onValueChange:N=>h(r,c,N),children:[e.jsx(Be,{className:"flex-1",children:e.jsx(Ge,{placeholder:"选择聊天流"})}),e.jsxs(He,{children:[e.jsx(ie,{value:"*",children:"* (全局共享)"}),d.map((N,v)=>e.jsx(ie,{value:N,children:N},v))]})]}),e.jsx(b,{size:"sm",variant:"outline",onClick:()=>p(!0),title:"切换到手动输入",children:"输入"})]})}),e.jsxs(bt,{children:[e.jsx(es,{asChild:!0,children:e.jsx(b,{size:"icon",variant:"outline",children:e.jsx(at,{className:"h-4 w-4"})})}),e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认删除"}),e.jsxs(xt,{children:['确定要删除组成员 "',n||"(空)",'" 吗?此操作无法撤销。']})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:()=>x(r,c),children:"删除"})]})]})]})]})}function U0({config:n,onChange:r}){const c=()=>{r({...n,learning_list:[...n.learning_list,["","enable","enable","1.0"]]})},d=C=>{r({...n,learning_list:n.learning_list.filter((S,w)=>w!==C)})},h=(C,S,w)=>{const L=[...n.learning_list];L[C][S]=w,r({...n,learning_list:L})},x=({rule:C})=>{const S=`["${C[0]}", "${C[1]}", "${C[2]}", "${C[3]}"]`;return e.jsxs(Ua,{children:[e.jsx(Ba,{asChild:!0,children:e.jsxs(b,{variant:"outline",size:"sm",children:[e.jsx(Ws,{className:"h-4 w-4 mr-1"}),"预览"]})}),e.jsx(_a,{className:"w-80 sm:w-96",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-sm",children:"配置预览"}),e.jsx("div",{className:"rounded-md bg-muted p-3 font-mono text-xs break-all",children:S}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"这是保存到 bot_config.toml 文件中的格式"})]})})]})},f=()=>{r({...n,expression_groups:[...n.expression_groups,[]]})},j=C=>{r({...n,expression_groups:n.expression_groups.filter((S,w)=>w!==C)})},p=C=>{const S=[...n.expression_groups];S[C]=[...S[C],""],r({...n,expression_groups:S})},N=(C,S)=>{const w=[...n.expression_groups];w[C]=w[C].filter((L,F)=>F!==S),r({...n,expression_groups:w})},v=(C,S,w)=>{const L=[...n.expression_groups];L[C][S]=w,r({...n,expression_groups:L})};return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold",children:"表达学习配置"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"配置麦麦如何学习和使用表达方式"})]}),e.jsxs(b,{onClick:c,size:"sm",variant:"outline",children:[e.jsx(hs,{className:"h-4 w-4 mr-1"}),"添加规则"]})]}),e.jsxs("div",{className:"space-y-4",children:[n.learning_list.map((C,S)=>{const w=n.learning_list.some((H,z)=>z!==S&&H[0]===""),L=C[0]==="",F=C[0].split(":"),B=F[0]||"qq",O=F[1]||"",K=F[2]||"group";return e.jsxs("div",{className:"rounded-lg border p-4 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm font-medium",children:["规则 ",S+1," ",L&&"(全局配置)"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(x,{rule:C}),e.jsxs(bt,{children:[e.jsx(es,{asChild:!0,children:e.jsx(b,{size:"sm",variant:"ghost",children:e.jsx(at,{className:"h-4 w-4"})})}),e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认删除"}),e.jsxs(xt,{children:["确定要删除学习规则 ",S+1," 吗?此操作无法撤销。"]})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:()=>d(S),children:"删除"})]})]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{className:"text-xs font-medium",children:"配置类型"}),e.jsxs(qe,{value:L?"global":"specific",onValueChange:H=>{H==="global"?h(S,0,""):h(S,0,"qq::group")},disabled:w&&!L,children:[e.jsx(Be,{children:e.jsx(Ge,{})}),e.jsxs(He,{children:[e.jsx(ie,{value:"global",children:"全局配置"}),e.jsx(ie,{value:"specific",disabled:w&&!L,children:"详细配置"})]})]}),w&&!L&&e.jsx("p",{className:"text-xs text-amber-600",children:"已存在全局配置,无法创建新的全局配置"})]}),!L&&e.jsxs("div",{className:"grid gap-4 p-3 sm:p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{className:"text-xs font-medium",children:"平台"}),e.jsxs(qe,{value:B,onValueChange:H=>{h(S,0,`${H}:${O}:${K}`)},children:[e.jsx(Be,{children:e.jsx(Ge,{})}),e.jsxs(He,{children:[e.jsx(ie,{value:"qq",children:"QQ"}),e.jsx(ie,{value:"wx",children:"微信"})]})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{className:"text-xs font-medium",children:"群 ID"}),e.jsx(ce,{value:O,onChange:H=>{h(S,0,`${B}:${H.target.value}:${K}`)},placeholder:"输入群 ID",className:"font-mono text-sm"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{className:"text-xs font-medium",children:"类型"}),e.jsxs(qe,{value:K,onValueChange:H=>{h(S,0,`${B}:${O}:${H}`)},children:[e.jsx(Be,{children:e.jsx(Ge,{})}),e.jsxs(He,{children:[e.jsx(ie,{value:"group",children:"群组(group)"}),e.jsx(ie,{value:"private",children:"私聊(private)"})]})]})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["当前聊天流 ID:",C[0]||"(未设置)"]})]}),e.jsx("div",{className:"grid gap-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(y,{className:"text-xs font-medium",children:"使用学到的表达"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"允许麦麦使用从聊天中学到的表达方式"})]}),e.jsx(Qe,{checked:C[1]==="enable",onCheckedChange:H=>h(S,1,H?"enable":"disable")})]})}),e.jsx("div",{className:"grid gap-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(y,{className:"text-xs font-medium",children:"学习表达"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"允许麦麦从聊天中学习新的表达方式"})]}),e.jsx(Qe,{checked:C[2]==="enable",onCheckedChange:H=>h(S,2,H?"enable":"disable")})]})}),e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(y,{className:"text-xs font-medium",children:"学习强度"}),e.jsx(ce,{type:"number",step:"0.1",min:"0",max:"5",value:C[3],onChange:H=>{const z=parseFloat(H.target.value);isNaN(z)||h(S,3,Math.max(0,Math.min(5,z)).toFixed(1))},className:"w-20 h-8 text-xs"})]}),e.jsx(Ma,{value:[parseFloat(C[3])||1],onValueChange:H=>h(S,3,H[0].toFixed(1)),min:0,max:5,step:.1,className:"w-full"}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:"0 (不学习)"}),e.jsx("span",{children:"2.5"}),e.jsx("span",{children:"5.0 (快速学习)"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"影响学习频率,最短学习间隔 = 300/学习强度(秒)"})]})]})]},S)}),n.learning_list.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:'暂无学习规则,点击"添加规则"开始配置'})]})]})}),e.jsx("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold",children:"表达反思配置"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"配置麦麦主动向管理员询问表达方式是否合适的功能"})]}),e.jsx(Qe,{checked:n.reflect,onCheckedChange:C=>r({...n,reflect:C})})]}),n.reflect&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border p-4 space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx("span",{className:"text-sm font-medium",children:"反思操作员"})}),e.jsx("div",{className:"space-y-4",children:(()=>{const S=(n.reflect_operator_id||"").split(":"),w=S[0]||"qq",L=S[1]||"",F=S[2]||"private";return e.jsxs("div",{className:"grid gap-4 p-3 sm:p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{className:"text-xs font-medium",children:"平台"}),e.jsxs(qe,{value:w,onValueChange:B=>{r({...n,reflect_operator_id:`${B}:${L}:${F}`})},children:[e.jsx(Be,{children:e.jsx(Ge,{})}),e.jsxs(He,{children:[e.jsx(ie,{value:"qq",children:"QQ"}),e.jsx(ie,{value:"wx",children:"微信"})]})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{className:"text-xs font-medium",children:"用户/群 ID"}),e.jsx(ce,{value:L,onChange:B=>{r({...n,reflect_operator_id:`${w}:${B.target.value}:${F}`})},placeholder:"输入 ID",className:"font-mono text-sm"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{className:"text-xs font-medium",children:"类型"}),e.jsxs(qe,{value:F,onValueChange:B=>{r({...n,reflect_operator_id:`${w}:${L}:${B}`})},children:[e.jsx(Be,{children:e.jsx(Ge,{})}),e.jsxs(He,{children:[e.jsx(ie,{value:"private",children:"私聊(private)"}),e.jsx(ie,{value:"group",children:"群组(group)"})]})]})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["当前操作员 ID:",n.reflect_operator_id||"(未设置)"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"麦麦会向此操作员询问表达方式是否合适"})]})})()})]}),e.jsxs("div",{className:"rounded-lg border p-4 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-medium",children:"允许反思的聊天流"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"只有在此列表中的聊天流才会提出问题并跟踪。如果列表为空,则所有聊天流都可以进行表达反思"})]}),e.jsxs(b,{onClick:()=>{r({...n,allow_reflect:[...n.allow_reflect||[],"qq::group"]})},size:"sm",variant:"outline",children:[e.jsx(hs,{className:"h-4 w-4 mr-1"}),"添加聊天流"]})]}),e.jsxs("div",{className:"space-y-2",children:[(n.allow_reflect||[]).map((C,S)=>{const w=C.split(":"),L=w[0]||"qq",F=w[1]||"",B=w[2]||"group";return e.jsxs("div",{className:"flex items-center gap-2 p-3 rounded-lg bg-muted/50",children:[e.jsxs(qe,{value:L,onValueChange:O=>{const K=[...n.allow_reflect];K[S]=`${O}:${F}:${B}`,r({...n,allow_reflect:K})},children:[e.jsx(Be,{className:"w-24",children:e.jsx(Ge,{})}),e.jsxs(He,{children:[e.jsx(ie,{value:"qq",children:"QQ"}),e.jsx(ie,{value:"wx",children:"微信"})]})]}),e.jsx(ce,{value:F,onChange:O=>{const K=[...n.allow_reflect];K[S]=`${L}:${O.target.value}:${B}`,r({...n,allow_reflect:K})},placeholder:"ID",className:"flex-1 font-mono text-sm"}),e.jsxs(qe,{value:B,onValueChange:O=>{const K=[...n.allow_reflect];K[S]=`${L}:${F}:${O}`,r({...n,allow_reflect:K})},children:[e.jsx(Be,{className:"w-32",children:e.jsx(Ge,{})}),e.jsxs(He,{children:[e.jsx(ie,{value:"group",children:"群组"}),e.jsx(ie,{value:"private",children:"私聊"})]})]}),e.jsx(b,{onClick:()=>{r({...n,allow_reflect:n.allow_reflect.filter((O,K)=>K!==S)})},size:"sm",variant:"ghost",children:e.jsx(at,{className:"h-4 w-4"})})]},S)}),(!n.allow_reflect||n.allow_reflect.length===0)&&e.jsx("div",{className:"text-center py-4 text-muted-foreground text-sm",children:"列表为空,所有聊天流都可以进行表达反思"})]})]})]})]})}),e.jsx("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold",children:"表达共享组配置"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"配置不同聊天流之间如何共享学到的表达方式"})]}),e.jsxs(b,{onClick:f,size:"sm",variant:"outline",children:[e.jsx(hs,{className:"h-4 w-4 mr-1"}),"添加共享组"]})]}),e.jsxs("div",{className:"space-y-4",children:[n.expression_groups.map((C,S)=>{const w=n.learning_list.map(L=>L[0]).filter(L=>L!=="");return e.jsxs("div",{className:"rounded-lg border p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm font-medium",children:["共享组 ",S+1,C.length===1&&C[0]==="*"&&"(全局共享)"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{onClick:()=>p(S),size:"sm",variant:"outline",children:e.jsx(hs,{className:"h-4 w-4"})}),e.jsxs(bt,{children:[e.jsx(es,{asChild:!0,children:e.jsx(b,{size:"sm",variant:"ghost",children:e.jsx(at,{className:"h-4 w-4"})})}),e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认删除"}),e.jsxs(xt,{children:["确定要删除共享组 ",S+1," 吗?此操作无法撤销。"]})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:()=>j(S),children:"删除"})]})]})]})]})]}),e.jsx("div",{className:"space-y-2",children:C.map((L,F)=>e.jsx(L0,{member:L,groupIndex:S,memberIndex:F,availableChatIds:w,onUpdate:v,onRemove:N},`${S}-${F}`))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:'提示:可以从下拉框选择已配置的聊天流,或手动输入。输入 "*" 启用全局共享'})]},S)}),n.expression_groups.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:'暂无共享组,点击"添加共享组"开始配置'})]})]})})]})}function B0({emojiConfig:n,memoryConfig:r,toolConfig:c,onEmojiChange:d,onMemoryChange:h,onToolChange:x}){return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"工具设置"}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Qe,{id:"enable_tool",checked:c.enable_tool,onCheckedChange:f=>x({...c,enable_tool:f})}),e.jsx(y,{htmlFor:"enable_tool",className:"cursor-pointer",children:"启用工具系统"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"允许麦麦使用各种工具来增强功能"})]})}),e.jsx("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"记忆设置"}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"max_agent_iterations",children:"记忆思考深度"}),e.jsx(ce,{id:"max_agent_iterations",type:"number",min:"1",value:r.max_agent_iterations,onChange:f=>h({...r,max_agent_iterations:parseInt(f.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"最低为 1(不深入思考)"})]})]})}),e.jsx("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"表情包设置"}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"emoji_chance",children:"表情包激活概率"}),e.jsx(ce,{id:"emoji_chance",type:"number",step:"0.1",min:"0",max:"1",value:n.emoji_chance,onChange:f=>d({...n,emoji_chance:parseFloat(f.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"范围 0-1,越大越容易发送表情包"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"max_reg_num",children:"最大注册数量"}),e.jsx(ce,{id:"max_reg_num",type:"number",min:"1",value:n.max_reg_num,onChange:f=>d({...n,max_reg_num:parseInt(f.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"麦麦最多可以注册的表情包数量"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"check_interval",children:"检查间隔(分钟)"}),e.jsx(ce,{id:"check_interval",type:"number",min:"1",value:n.check_interval,onChange:f=>d({...n,check_interval:parseInt(f.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"检查表情包(注册、破损、删除)的时间间隔"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Qe,{id:"do_replace",checked:n.do_replace,onCheckedChange:f=>d({...n,do_replace:f})}),e.jsx(y,{htmlFor:"do_replace",className:"cursor-pointer",children:"达到最大数量时替换表情包"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Qe,{id:"steal_emoji",checked:n.steal_emoji,onCheckedChange:f=>d({...n,steal_emoji:f})}),e.jsx(y,{htmlFor:"steal_emoji",className:"cursor-pointer",children:"偷取表情包"})]}),e.jsx("p",{className:"text-xs text-muted-foreground -mt-2",children:"允许麦麦将看到的表情包据为己有"}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Qe,{id:"content_filtration",checked:n.content_filtration,onCheckedChange:f=>d({...n,content_filtration:f})}),e.jsx(y,{htmlFor:"content_filtration",className:"cursor-pointer",children:"启用表情包过滤"})]}),n.content_filtration&&e.jsxs("div",{className:"grid gap-2 pl-6 border-l-2 border-primary/20",children:[e.jsx(y,{htmlFor:"filtration_prompt",children:"过滤要求"}),e.jsx(ce,{id:"filtration_prompt",value:n.filtration_prompt,onChange:f=>d({...n,filtration_prompt:f.target.value}),placeholder:"符合公序良俗"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"只有符合此要求的表情包才会被保存"})]})]})]})})]})}function H0({keywordReactionConfig:n,responsePostProcessConfig:r,chineseTypoConfig:c,responseSplitterConfig:d,onKeywordReactionChange:h,onResponsePostProcessChange:x,onChineseTypoChange:f,onResponseSplitterChange:j}){const p=()=>{h({...n,regex_rules:[...n.regex_rules,{regex:[""],reaction:""}]})},N=z=>{h({...n,regex_rules:n.regex_rules.filter((V,Y)=>Y!==z)})},v=(z,V,Y)=>{const E=[...n.regex_rules];V==="regex"&&typeof Y=="string"?E[z]={...E[z],regex:[Y]}:V==="reaction"&&typeof Y=="string"&&(E[z]={...E[z],reaction:Y}),h({...n,regex_rules:E})},C=({regex:z,reaction:V,onRegexChange:Y,onReactionChange:E})=>{const[R,ne]=u.useState(!1),[fe,Ce]=u.useState(""),[we,pe]=u.useState(null),[Ne,be]=u.useState(""),[A,X]=u.useState({}),[T,te]=u.useState(""),_=u.useRef(null),[me,oe]=u.useState("build"),ae=G=>G.replace(/\(\?P<([^>]+)>/g,"(?<$1>"),xe=(G,W=0)=>{const U=_.current;if(!U)return;const ee=U.selectionStart||0,Se=U.selectionEnd||0,Me=z.substring(0,ee)+G+z.substring(Se);Y(Me),setTimeout(()=>{const tt=ee+G.length+W;U.setSelectionRange(tt,tt),U.focus()},0)};u.useEffect(()=>{if(!z||!fe){pe(null),X({}),te(V),be("");return}try{const G=ae(z),W=new RegExp(G,"g"),U=fe.match(W);pe(U),be("");const Se=new RegExp(G).exec(fe);if(Se&&Se.groups){X(Se.groups);let Me=V;Object.entries(Se.groups).forEach(([tt,Xe])=>{Me=Me.replace(new RegExp(`\\[${tt}\\]`,"g"),Xe||"")}),te(Me)}else X({}),te(V)}catch(G){be(G.message),pe(null),X({}),te(V)}},[z,fe,V]);const ve=()=>{if(!fe||!we||we.length===0)return e.jsx("span",{className:"text-muted-foreground",children:fe||"请输入测试文本"});try{const G=ae(z),W=new RegExp(G,"g");let U=0;const ee=[];let Se;for(;(Se=W.exec(fe))!==null;)Se.index>U&&ee.push(e.jsx("span",{children:fe.substring(U,Se.index)},`text-${U}`)),ee.push(e.jsx("span",{className:"bg-yellow-200 dark:bg-yellow-900 font-semibold",children:Se[0]},`match-${Se.index}`)),U=Se.index+Se[0].length;return U)",desc:"Python风格命名捕获组",moveCursor:-1},{label:"非捕获组",pattern:"(?:)",desc:"分组但不保存匹配结果",moveCursor:-1}]},{category:"字符类",items:[{label:"字符集",pattern:"[]",desc:"匹配括号内的任意字符",moveCursor:-1},{label:"排除字符",pattern:"[^]",desc:"匹配不在括号内的字符",moveCursor:-1},{label:"范围",pattern:"[a-z]",desc:"匹配a到z的字符"},{label:"中文字符",pattern:"[\\u4e00-\\u9fa5]",desc:"匹配中文汉字"}]},{category:"常用模板",items:[{label:"捕获词语",pattern:"(?P\\S+)",desc:"捕获一个词语"},{label:"捕获句子",pattern:"(?P.+)",desc:"捕获整个句子"},{label:"捕获数字",pattern:"(?P\\d+)",desc:"捕获一个或多个数字"},{label:"可选词语",pattern:"(?:词语1|词语2)",desc:"匹配多个可选项之一"}]}];return e.jsxs(Jt,{open:R,onOpenChange:ne,children:[e.jsx($u,{asChild:!0,children:e.jsxs(b,{variant:"outline",size:"sm",children:[e.jsx(Hu,{className:"h-4 w-4 mr-1"}),"正则编辑器"]})}),e.jsxs($t,{className:"max-w-[95vw] sm:max-w-[900px] max-h-[90vh]",children:[e.jsxs(Qt,{children:[e.jsx(Yt,{children:"正则表达式编辑器"}),e.jsx(ds,{className:"text-sm",children:"使用可视化工具构建正则表达式,并实时测试效果"})]}),e.jsx(st,{className:"max-h-[calc(90vh-120px)]",children:e.jsxs(La,{value:me,onValueChange:G=>oe(G),className:"w-full",children:[e.jsxs(wa,{className:"grid w-full grid-cols-2",children:[e.jsx(it,{value:"build",children:"🔧 构建器"}),e.jsx(it,{value:"test",children:"🧪 测试器"})]}),e.jsxs(zt,{value:"build",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{className:"text-sm font-medium",children:"正则表达式"}),e.jsx(ce,{ref:_,value:z,onChange:G=>Y(G.target.value),className:"font-mono text-sm",placeholder:"点击下方按钮构建正则表达式..."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{className:"text-sm font-medium",children:"Reaction 内容"}),e.jsx(Ft,{value:V,onChange:G=>E(G.target.value),placeholder:"使用 [捕获组名] 引用捕获的内容...",rows:3,className:"text-sm"})]}),e.jsxs("div",{className:"space-y-4 border-t pt-4",children:[de.map(G=>e.jsxs("div",{className:"space-y-2",children:[e.jsx("h5",{className:"text-xs font-semibold text-primary",children:G.category}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:G.items.map(W=>e.jsx(b,{variant:"outline",size:"sm",className:"justify-start h-auto py-2 px-3",onClick:()=>xe(W.pattern,W.moveCursor||0),children:e.jsxs("div",{className:"flex flex-col items-start w-full",children:[e.jsxs("div",{className:"flex items-center gap-2 w-full",children:[e.jsx("span",{className:"text-xs font-medium",children:W.label}),e.jsx("code",{className:"ml-auto text-xs bg-muted px-1.5 py-0.5 rounded font-mono",children:W.pattern})]}),e.jsx("span",{className:"text-xs text-muted-foreground mt-0.5",children:W.desc})]})},W.label))})]},G.category)),e.jsxs("div",{className:"space-y-2 border-t pt-4",children:[e.jsx("h5",{className:"text-xs font-semibold text-primary",children:"完整示例模板"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{variant:"outline",size:"sm",className:"w-full justify-start h-auto py-2 px-3",onClick:()=>Y("^(?P\\S{1,20})是这样的$"),children:e.jsxs("div",{className:"flex flex-col items-start w-full",children:[e.jsxs("code",{className:"text-xs font-mono bg-muted px-2 py-1 rounded w-full overflow-x-auto",children:["^(?P\\S","{1,20}",")是这样的$"]}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"匹配「某事物是这样的」并捕获事物名称"})]})}),e.jsx(b,{variant:"outline",size:"sm",className:"w-full justify-start h-auto py-2 px-3",onClick:()=>Y("(?:[^,。.\\s]+,\\s*)?我(?:也)?[没沒]要求你\\s*(?P.+?)[.。,,]?$"),children:e.jsxs("div",{className:"flex flex-col items-start w-full",children:[e.jsx("code",{className:"text-xs font-mono bg-muted px-2 py-1 rounded w-full overflow-x-auto",children:"(?:[^,。.\\s]+,\\s*)?我(?:也)?[没沒]要求你\\s*(?P.+?)[.。,,]?$"}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"匹配「我没要求你做某事」并捕获具体行为"})]})}),e.jsx(b,{variant:"outline",size:"sm",className:"w-full justify-start h-auto py-2 px-3",onClick:()=>Y("(?P.+?)(?:是|为什么|怎么)"),children:e.jsxs("div",{className:"flex flex-col items-start w-full",children:[e.jsx("code",{className:"text-xs font-mono bg-muted px-2 py-1 rounded w-full overflow-x-auto",children:"(?P.+?)(?:是|为什么|怎么)"}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"捕获问题主题词"})]})})]})]})]}),e.jsxs("div",{className:"rounded-md bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 p-3 space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-blue-900 dark:text-blue-100",children:"💡 使用提示"}),e.jsxs("ul",{className:"text-xs text-blue-700 dark:text-blue-300 space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"点击输入框设置光标位置,然后点击按钮插入模式"}),e.jsxs("li",{children:["命名捕获组格式:",e.jsx("code",{className:"bg-blue-100 dark:bg-blue-900 px-1 rounded",children:"(?P<名称>模式)"})]}),e.jsxs("li",{children:["在 reaction 中使用 ",e.jsx("code",{className:"bg-blue-100 dark:bg-blue-900 px-1 rounded",children:"[名称]"})," 引用捕获的内容"]}),e.jsx("li",{children:"切换到测试器标签页验证正则表达式效果"})]})]})]}),e.jsxs(zt,{value:"test",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{className:"text-sm font-medium",children:"当前正则表达式"}),e.jsx("div",{className:"rounded-md bg-muted p-3 font-mono text-xs break-all",children:z||"(未设置)"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"test-text",className:"text-sm font-medium",children:"测试文本"}),e.jsx(Ft,{id:"test-text",value:fe,onChange:G=>Ce(G.target.value),placeholder:`在此输入要测试的文本... 例如:打游戏是这样的`,className:"min-h-[100px] text-sm"})]}),Ne&&e.jsxs("div",{className:"rounded-md bg-destructive/10 border border-destructive/20 p-3",children:[e.jsx("p",{className:"text-sm text-destructive font-medium",children:"正则表达式错误"}),e.jsx("p",{className:"text-xs text-destructive/80 mt-1",children:Ne})]}),!Ne&&fe&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center gap-2",children:we&&we.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-green-500"}),e.jsxs("span",{className:"text-sm font-medium text-green-600 dark:text-green-400",children:["匹配成功 (",we.length," 处)"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-gray-400"}),e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"无匹配"})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{className:"text-sm font-medium",children:"匹配高亮"}),e.jsx(st,{className:"h-40 rounded-md bg-muted p-3",children:e.jsx("div",{className:"text-sm break-words",children:ve()})})]}),Object.keys(A).length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{className:"text-sm font-medium",children:"命名捕获组"}),e.jsx(st,{className:"h-32 rounded-md border p-3",children:e.jsx("div",{className:"space-y-2",children:Object.entries(A).map(([G,W])=>e.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[e.jsxs("span",{className:"font-mono font-semibold text-primary min-w-[80px]",children:["[",G,"]"]}),e.jsx("span",{className:"text-muted-foreground",children:"="}),e.jsx("span",{className:"font-mono bg-muted px-2 py-0.5 rounded",children:W})]},G))})})]}),Object.keys(A).length>0&&V&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{className:"text-sm font-medium",children:"Reaction 替换预览"}),e.jsx(st,{className:"h-48 rounded-md bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 p-3",children:e.jsx("div",{className:"text-sm break-words",children:T})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"reaction 中的 [name] 已被替换为对应的捕获组值"})]})]}),e.jsxs("div",{className:"rounded-md bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 p-3 space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-blue-900 dark:text-blue-100",children:"💡 测试说明"}),e.jsxs("ul",{className:"text-xs text-blue-700 dark:text-blue-300 space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"匹配的文本会以黄色背景高亮显示"}),e.jsx("li",{children:"命名捕获组的值会显示在下方列表中"}),e.jsx("li",{children:"Reaction 替换预览显示最终生成的反应内容"}),e.jsx("li",{children:"如需修改正则,切换回构建器标签页"})]})]})]})]})})]})]})},S=()=>{h({...n,keyword_rules:[...n.keyword_rules,{keywords:[],reaction:""}]})},w=z=>{h({...n,keyword_rules:n.keyword_rules.filter((V,Y)=>Y!==z)})},L=(z,V,Y)=>{const E=[...n.keyword_rules];typeof Y=="string"&&(E[z]={...E[z],reaction:Y}),h({...n,keyword_rules:E})},F=z=>{const V=[...n.keyword_rules];V[z]={...V[z],keywords:[...V[z].keywords||[],""]},h({...n,keyword_rules:V})},B=(z,V)=>{const Y=[...n.keyword_rules];Y[z]={...Y[z],keywords:(Y[z].keywords||[]).filter((E,R)=>R!==V)},h({...n,keyword_rules:Y})},O=(z,V,Y)=>{const E=[...n.keyword_rules],R=[...E[z].keywords||[]];R[V]=Y,E[z]={...E[z],keywords:R},h({...n,keyword_rules:E})},K=({rule:z})=>{const V=`{ regex = [${(z.regex||[]).map(Y=>`"${Y}"`).join(", ")}], reaction = "${z.reaction}" }`;return e.jsxs(Ua,{children:[e.jsx(Ba,{asChild:!0,children:e.jsxs(b,{variant:"outline",size:"sm",children:[e.jsx(Ws,{className:"h-4 w-4 mr-1"}),"预览"]})}),e.jsx(_a,{className:"w-[95vw] sm:w-[500px]",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-sm",children:"配置预览"}),e.jsx(st,{className:"h-60 rounded-md bg-muted p-3",children:e.jsx("pre",{className:"font-mono text-xs break-all",children:V})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"这是保存到 bot_config.toml 文件中的格式"})]})})]})},H=({rule:z})=>{const V=`[[keyword_reaction.keyword_rules]] keywords = [${(z.keywords||[]).map(Y=>`"${Y}"`).join(", ")}] reaction = "${z.reaction}"`;return e.jsxs(Ua,{children:[e.jsx(Ba,{asChild:!0,children:e.jsxs(b,{variant:"outline",size:"sm",children:[e.jsx(Ws,{className:"h-4 w-4 mr-1"}),"预览"]})}),e.jsx(_a,{className:"w-[95vw] sm:w-[500px]",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-sm",children:"配置预览"}),e.jsx(st,{className:"h-60 rounded-md bg-muted p-3",children:e.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap break-all",children:V})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"这是保存到 bot_config.toml 文件中的格式"})]})})]})};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"关键词反应配置"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"配置触发特定反应的关键词和正则表达式规则"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-base font-semibold",children:"正则表达式规则"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"使用正则表达式匹配消息内容"})]}),e.jsxs(b,{onClick:p,size:"sm",variant:"outline",children:[e.jsx(hs,{className:"h-4 w-4 mr-1"}),"添加正则规则"]})]}),e.jsxs("div",{className:"space-y-3",children:[n.regex_rules.map((z,V)=>e.jsxs("div",{className:"rounded-lg border p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm font-medium",children:["正则规则 ",V+1]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{regex:z.regex&&z.regex[0]||"",reaction:z.reaction,onRegexChange:Y=>v(V,"regex",Y),onReactionChange:Y=>v(V,"reaction",Y)}),e.jsx(K,{rule:z}),e.jsxs(bt,{children:[e.jsx(es,{asChild:!0,children:e.jsx(b,{size:"sm",variant:"ghost",children:e.jsx(at,{className:"h-4 w-4"})})}),e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认删除"}),e.jsxs(xt,{children:["确定要删除正则规则 ",V+1," 吗?此操作无法撤销。"]})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:()=>N(V),children:"删除"})]})]})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{className:"text-xs font-medium",children:"正则表达式(Python 语法)"}),e.jsx(ce,{value:z.regex&&z.regex[0]||"",onChange:Y=>v(V,"regex",Y.target.value),placeholder:"例如:^(?P\\\\S{1,20})是这样的$ (点击正则编辑器按钮可视化构建)",className:"font-mono text-sm"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:'支持命名捕获组 (?Ppattern),可在 reaction 中使用 [name] 引用。点击"正则编辑器"可视化构建和测试!'})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{className:"text-xs font-medium",children:"反应内容"}),e.jsx(Ft,{value:z.reaction,onChange:Y=>v(V,"reaction",Y.target.value),placeholder:`触发后麦麦的反应... 可以使用 [捕获组名] 来引用正则表达式中的内容`,rows:3,className:"text-sm"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"使用 [捕获组名] 引用正则表达式中的命名捕获组,例如 [n] 会被替换为捕获的内容"})]})]})]},V)),n.regex_rules.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:'暂无正则规则,点击"添加正则规则"开始配置'})]})]}),e.jsxs("div",{className:"space-y-4 border-t pt-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-base font-semibold",children:"关键词规则"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"使用关键词列表匹配消息内容"})]}),e.jsxs(b,{onClick:S,size:"sm",variant:"outline",children:[e.jsx(hs,{className:"h-4 w-4 mr-1"}),"添加关键词规则"]})]}),e.jsxs("div",{className:"space-y-3",children:[n.keyword_rules.map((z,V)=>e.jsxs("div",{className:"rounded-lg border p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm font-medium",children:["关键词规则 ",V+1]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(H,{rule:z}),e.jsxs(bt,{children:[e.jsx(es,{asChild:!0,children:e.jsx(b,{size:"sm",variant:"ghost",children:e.jsx(at,{className:"h-4 w-4"})})}),e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认删除"}),e.jsxs(xt,{children:["确定要删除关键词规则 ",V+1," 吗?此操作无法撤销。"]})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:()=>w(V),children:"删除"})]})]})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(y,{className:"text-xs font-medium",children:"关键词列表"}),e.jsxs(b,{onClick:()=>F(V),size:"sm",variant:"ghost",children:[e.jsx(hs,{className:"h-3 w-3 mr-1"}),"添加关键词"]})]}),e.jsxs("div",{className:"space-y-2",children:[(z.keywords||[]).map((Y,E)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ce,{value:Y,onChange:R=>O(V,E,R.target.value),placeholder:"关键词",className:"flex-1"}),e.jsx(b,{onClick:()=>B(V,E),size:"sm",variant:"ghost",children:e.jsx(at,{className:"h-4 w-4"})})]},E)),(!z.keywords||z.keywords.length===0)&&e.jsx("p",{className:"text-xs text-muted-foreground text-center py-2",children:'暂无关键词,点击"添加关键词"开始配置'})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{className:"text-xs font-medium",children:"反应内容"}),e.jsx(Ft,{value:z.reaction,onChange:Y=>L(V,"reaction",Y.target.value),placeholder:"触发后麦麦的反应...",rows:3,className:"text-sm"})]})]})]},V)),n.keyword_rules.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:'暂无关键词规则,点击"添加关键词规则"开始配置'})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"回复后处理配置"}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Qe,{id:"enable_response_post_process",checked:r.enable_response_post_process,onCheckedChange:z=>x({...r,enable_response_post_process:z})}),e.jsx(y,{htmlFor:"enable_response_post_process",className:"cursor-pointer",children:"启用回复后处理"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"包括错别字生成器和回复分割器"})]}),r.enable_response_post_process&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-t pt-6 space-y-4",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-4",children:[e.jsx(Qe,{id:"enable_chinese_typo",checked:c.enable,onCheckedChange:z=>f({...c,enable:z})}),e.jsx(y,{htmlFor:"enable_chinese_typo",className:"cursor-pointer font-semibold",children:"中文错别字生成器"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"为回复添加随机错别字,让麦麦的回复更自然"}),c.enable&&e.jsxs("div",{className:"grid gap-4 pl-6 border-l-2 border-primary/20",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"error_rate",className:"text-xs font-medium",children:"单字替换概率"}),e.jsx(ce,{id:"error_rate",type:"number",step:"0.001",min:"0",max:"1",value:c.error_rate,onChange:z=>f({...c,error_rate:parseFloat(z.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"min_freq",className:"text-xs font-medium",children:"最小字频阈值"}),e.jsx(ce,{id:"min_freq",type:"number",min:"0",value:c.min_freq,onChange:z=>f({...c,min_freq:parseInt(z.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"tone_error_rate",className:"text-xs font-medium",children:"声调错误概率"}),e.jsx(ce,{id:"tone_error_rate",type:"number",step:"0.01",min:"0",max:"1",value:c.tone_error_rate,onChange:z=>f({...c,tone_error_rate:parseFloat(z.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"word_replace_rate",className:"text-xs font-medium",children:"整词替换概率"}),e.jsx(ce,{id:"word_replace_rate",type:"number",step:"0.001",min:"0",max:"1",value:c.word_replace_rate,onChange:z=>f({...c,word_replace_rate:parseFloat(z.target.value)})})]})]})]})}),e.jsx("div",{className:"border-t pt-6 space-y-4",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-4",children:[e.jsx(Qe,{id:"enable_response_splitter",checked:d.enable,onCheckedChange:z=>j({...d,enable:z})}),e.jsx(y,{htmlFor:"enable_response_splitter",className:"cursor-pointer font-semibold",children:"回复分割器"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"控制回复的长度和句子数量"}),d.enable&&e.jsxs("div",{className:"grid gap-4 pl-6 border-l-2 border-primary/20",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"max_length",className:"text-xs font-medium",children:"最大长度"}),e.jsx(ce,{id:"max_length",type:"number",min:"1",value:d.max_length,onChange:z=>j({...d,max_length:parseInt(z.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"回复允许的最大字符数"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"max_sentence_num",className:"text-xs font-medium",children:"最大句子数"}),e.jsx(ce,{id:"max_sentence_num",type:"number",min:"1",value:d.max_sentence_num,onChange:z=>j({...d,max_sentence_num:parseInt(z.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"回复允许的最大句子数量"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Qe,{id:"enable_kaomoji_protection",checked:d.enable_kaomoji_protection,onCheckedChange:z=>j({...d,enable_kaomoji_protection:z})}),e.jsx(y,{htmlFor:"enable_kaomoji_protection",className:"cursor-pointer",children:"启用颜文字保护"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Qe,{id:"enable_overflow_return_all",checked:d.enable_overflow_return_all,onCheckedChange:z=>j({...d,enable_overflow_return_all:z})}),e.jsx(y,{htmlFor:"enable_overflow_return_all",className:"cursor-pointer",children:"超出时一次性返回全部"})]}),e.jsx("p",{className:"text-xs text-muted-foreground -mt-2",children:"当句子数量超出限制时,合并后一次性返回所有内容"})]})]})})]})]})]})}function q0({config:n,onChange:r}){return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"情绪设置"}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Qe,{checked:n.enable_mood,onCheckedChange:c=>r({...n,enable_mood:c})}),e.jsx(y,{className:"cursor-pointer",children:"启用情绪系统"})]}),n.enable_mood&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{children:"情绪更新阈值"}),e.jsx(ce,{type:"number",min:"1",value:n.mood_update_threshold,onChange:c=>r({...n,mood_update_threshold:parseInt(c.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"越高,更新越慢"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{children:"情感特征"}),e.jsx(Ft,{value:n.emotion_style,onChange:c=>r({...n,emotion_style:c.target.value}),placeholder:"影响情绪的变化情况",rows:2})]})]})]})]})}function G0({config:n,onChange:r}){return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"语音设置"}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Qe,{checked:n.enable_asr,onCheckedChange:c=>r({...n,enable_asr:c})}),e.jsx(y,{className:"cursor-pointer",children:"启用语音识别"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"启用后麦麦可以识别语音消息,需要配置语音识别模型"})]})}function V0({config:n,onChange:r}){return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"LPMM 知识库设置"}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Qe,{checked:n.enable,onCheckedChange:c=>r({...n,enable:c})}),e.jsx(y,{className:"cursor-pointer",children:"启用 LPMM 知识库"})]}),n.enable&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{children:"LPMM 模式"}),e.jsxs(qe,{value:n.lpmm_mode,onValueChange:c=>r({...n,lpmm_mode:c}),children:[e.jsx(Be,{children:e.jsx(Ge,{placeholder:"选择 LPMM 模式"})}),e.jsxs(He,{children:[e.jsx(ie,{value:"classic",children:"经典模式"}),e.jsx(ie,{value:"agent",children:"Agent 模式"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{children:"同义词搜索 TopK"}),e.jsx(ce,{type:"number",min:"1",value:n.rag_synonym_search_top_k,onChange:c=>r({...n,rag_synonym_search_top_k:parseInt(c.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{children:"同义词阈值"}),e.jsx(ce,{type:"number",step:"0.1",min:"0",max:"1",value:n.rag_synonym_threshold,onChange:c=>r({...n,rag_synonym_threshold:parseFloat(c.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{children:"实体提取线程数"}),e.jsx(ce,{type:"number",min:"1",value:n.info_extraction_workers,onChange:c=>r({...n,info_extraction_workers:parseInt(c.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{children:"嵌入向量维度"}),e.jsx(ce,{type:"number",min:"1",value:n.embedding_dimension,onChange:c=>r({...n,embedding_dimension:parseInt(c.target.value)})})]})]})]})]})]})}function F0({config:n,onChange:r}){const[c,d]=u.useState(""),[h,x]=u.useState("WARNING"),f=()=>{c&&!n.suppress_libraries.includes(c)&&(r({...n,suppress_libraries:[...n.suppress_libraries,c]}),d(""))},j=w=>{r({...n,suppress_libraries:n.suppress_libraries.filter(L=>L!==w)})},p=()=>{c&&!n.library_log_levels[c]&&(r({...n,library_log_levels:{...n.library_log_levels,[c]:h}}),d(""),x("WARNING"))},N=w=>{const L={...n.library_log_levels};delete L[w],r({...n,library_log_levels:L})},v=["DEBUG","INFO","WARNING","ERROR","CRITICAL"],C=["FULL","compact","lite"],S=["none","title","full"];return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"日志配置"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{children:"日期格式"}),e.jsx(ce,{value:n.date_style,onChange:w=>r({...n,date_style:w.target.value}),placeholder:"例如: m-d H:i:s"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"m=月, d=日, H=时, i=分, s=秒"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{children:"日志级别样式"}),e.jsxs(qe,{value:n.log_level_style,onValueChange:w=>r({...n,log_level_style:w}),children:[e.jsx(Be,{children:e.jsx(Ge,{})}),e.jsx(He,{children:C.map(w=>e.jsx(ie,{value:w,children:w},w))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{children:"日志文本颜色"}),e.jsxs(qe,{value:n.color_text,onValueChange:w=>r({...n,color_text:w}),children:[e.jsx(Be,{children:e.jsx(Ge,{})}),e.jsx(He,{children:S.map(w=>e.jsx(ie,{value:w,children:w},w))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{children:"全局日志级别"}),e.jsxs(qe,{value:n.log_level,onValueChange:w=>r({...n,log_level:w}),children:[e.jsx(Be,{children:e.jsx(Ge,{})}),e.jsx(He,{children:v.map(w=>e.jsx(ie,{value:w,children:w},w))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{children:"控制台日志级别"}),e.jsxs(qe,{value:n.console_log_level,onValueChange:w=>r({...n,console_log_level:w}),children:[e.jsx(Be,{children:e.jsx(Ge,{})}),e.jsx(He,{children:v.map(w=>e.jsx(ie,{value:w,children:w},w))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{children:"文件日志级别"}),e.jsxs(qe,{value:n.file_log_level,onValueChange:w=>r({...n,file_log_level:w}),children:[e.jsx(Be,{children:e.jsx(Ge,{})}),e.jsx(He,{children:v.map(w=>e.jsx(ie,{value:w,children:w},w))})]})]})]})]}),e.jsxs("div",{children:[e.jsx(y,{className:"mb-2 block",children:"完全屏蔽的库"}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx(ce,{value:c,onChange:w=>d(w.target.value),placeholder:"输入库名",className:"flex-1",onKeyDown:w=>{w.key==="Enter"&&(w.preventDefault(),f())}}),e.jsx(b,{onClick:f,size:"sm",className:"flex-shrink-0",children:e.jsx(hs,{className:"h-4 w-4",strokeWidth:2,fill:"none"})})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:n.suppress_libraries.map(w=>e.jsxs("div",{className:"flex items-center gap-1 bg-secondary px-3 py-1 rounded-md",children:[e.jsx("span",{className:"text-sm",children:w}),e.jsx(b,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0",onClick:()=>j(w),children:e.jsx(at,{className:"h-3 w-3",strokeWidth:2,fill:"none"})})]},w))})]}),e.jsxs("div",{children:[e.jsx(y,{className:"mb-2 block",children:"特定库的日志级别"}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx(ce,{value:c,onChange:w=>d(w.target.value),placeholder:"输入库名",className:"flex-1"}),e.jsxs(qe,{value:h,onValueChange:x,children:[e.jsx(Be,{className:"w-32",children:e.jsx(Ge,{})}),e.jsx(He,{children:v.map(w=>e.jsx(ie,{value:w,children:w},w))})]}),e.jsx(b,{onClick:p,size:"sm",children:e.jsx(hs,{className:"h-4 w-4",strokeWidth:2,fill:"none"})})]}),e.jsx("div",{className:"space-y-2",children:Object.entries(n.library_log_levels).map(([w,L])=>e.jsxs("div",{className:"flex items-center justify-between bg-secondary px-3 py-2 rounded-md",children:[e.jsx("span",{className:"text-sm font-medium",children:w}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:L}),e.jsx(b,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>N(w),children:e.jsx(at,{className:"h-3 w-3",strokeWidth:2,fill:"none"})})]})]},w))})]})]})}function $0({config:n,onChange:r}){return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"调试配置"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{children:"显示 Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否在日志中显示提示词"})]}),e.jsx(Qe,{checked:n.show_prompt,onCheckedChange:c=>r({...n,show_prompt:c})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{children:"显示回复器 Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示回复器的提示词"})]}),e.jsx(Qe,{checked:n.show_replyer_prompt,onCheckedChange:c=>r({...n,show_replyer_prompt:c})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{children:"显示回复器推理"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示回复器的推理过程"})]}),e.jsx(Qe,{checked:n.show_replyer_reasoning,onCheckedChange:c=>r({...n,show_replyer_reasoning:c})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{children:"显示 Jargon Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示术语相关的提示词"})]}),e.jsx(Qe,{checked:n.show_jargon_prompt,onCheckedChange:c=>r({...n,show_jargon_prompt:c})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{children:"显示记忆检索 Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示记忆检索相关的提示词"})]}),e.jsx(Qe,{checked:n.show_memory_prompt,onCheckedChange:c=>r({...n,show_memory_prompt:c})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{children:"显示 Planner Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示 Planner 的提示词和原始返回结果"})]}),e.jsx(Qe,{checked:n.show_planner_prompt,onCheckedChange:c=>r({...n,show_planner_prompt:c})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{children:"显示 LPMM 相关文段"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示 LPMM 知识库找到的相关文段日志"})]}),e.jsx(Qe,{checked:n.show_lpmm_paragraph,onCheckedChange:c=>r({...n,show_lpmm_paragraph:c})})]})]})]})}function Q0({config:n,onChange:r}){const[c,d]=u.useState(""),h=()=>{c&&!n.auth_token.includes(c)&&(r({...n,auth_token:[...n.auth_token,c]}),d(""))},x=f=>{r({...n,auth_token:n.auth_token.filter((j,p)=>p!==f)})};return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"MaimMessage 服务配置"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{children:"启用自定义服务器"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否使用自定义的 MaimMessage 服务器"})]}),e.jsx(Qe,{checked:n.use_custom,onCheckedChange:f=>r({...n,use_custom:f})})]}),n.use_custom&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{children:"主机地址"}),e.jsx(ce,{value:n.host,onChange:f=>r({...n,host:f.target.value}),placeholder:"127.0.0.1"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{children:"端口号"}),e.jsx(ce,{type:"number",value:n.port,onChange:f=>r({...n,port:parseInt(f.target.value)}),placeholder:"8090"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{children:"连接模式"}),e.jsxs(qe,{value:n.mode,onValueChange:f=>r({...n,mode:f}),children:[e.jsx(Be,{children:e.jsx(Ge,{})}),e.jsxs(He,{children:[e.jsx(ie,{value:"ws",children:"WebSocket (ws)"}),e.jsx(ie,{value:"tcp",children:"TCP"})]})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Qe,{checked:n.use_wss,onCheckedChange:f=>r({...n,use_wss:f}),disabled:n.mode!=="ws"}),e.jsx(y,{children:"使用 WSS 安全连接"})]})]}),n.use_wss&&n.mode==="ws"&&e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{children:"SSL 证书文件路径"}),e.jsx(ce,{value:n.cert_file,onChange:f=>r({...n,cert_file:f.target.value}),placeholder:"cert.pem"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{children:"SSL 密钥文件路径"}),e.jsx(ce,{value:n.key_file,onChange:f=>r({...n,key_file:f.target.value}),placeholder:"key.pem"})]})]})]})]})]}),e.jsxs("div",{children:[e.jsx(y,{className:"mb-2 block",children:"认证令牌"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"用于 API 验证,为空则不启用验证"}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx(ce,{value:c,onChange:f=>d(f.target.value),placeholder:"输入认证令牌",onKeyDown:f=>{f.key==="Enter"&&(f.preventDefault(),h())}}),e.jsx(b,{onClick:h,size:"sm",children:e.jsx(hs,{className:"h-4 w-4",strokeWidth:2,fill:"none"})})]}),e.jsx("div",{className:"space-y-2",children:n.auth_token.map((f,j)=>e.jsxs("div",{className:"flex items-center justify-between bg-secondary px-3 py-2 rounded-md",children:[e.jsx("span",{className:"text-sm font-mono",children:f}),e.jsx(b,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>x(j),children:e.jsx(at,{className:"h-3 w-3",strokeWidth:2,fill:"none"})})]},j))})]})]})}function Y0({config:n,onChange:r}){return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"统计信息"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{children:"启用统计信息发送"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"发送匿名统计信息,帮助我们了解全球有多少只麦麦在运行"})]}),e.jsx(Qe,{checked:n.enable,onCheckedChange:c=>r({...n,enable:c})})]})]})}const li=u.forwardRef(({className:n,...r},c)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:c,className:Q("w-full caption-bottom text-sm",n),...r})}));li.displayName="Table";const ni=u.forwardRef(({className:n,...r},c)=>e.jsx("thead",{ref:c,className:Q("[&_tr]:border-b",n),...r}));ni.displayName="TableHeader";const ii=u.forwardRef(({className:n,...r},c)=>e.jsx("tbody",{ref:c,className:Q("[&_tr:last-child]:border-0",n),...r}));ii.displayName="TableBody";const X0=u.forwardRef(({className:n,...r},c)=>e.jsx("tfoot",{ref:c,className:Q("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",n),...r}));X0.displayName="TableFooter";const _s=u.forwardRef(({className:n,...r},c)=>e.jsx("tr",{ref:c,className:Q("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",n),...r}));_s.displayName="TableRow";const rt=u.forwardRef(({className:n,...r},c)=>e.jsx("th",{ref:c,className:Q("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",n),...r}));rt.displayName="TableHead";const Ze=u.forwardRef(({className:n,...r},c)=>e.jsx("td",{ref:c,className:Q("px-4 py-3 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",n),...r}));Ze.displayName="TableCell";const K0=u.forwardRef(({className:n,...r},c)=>e.jsx("caption",{ref:c,className:Q("mt-4 text-sm text-muted-foreground",n),...r}));K0.displayName="TableCaption";const ao=u.forwardRef(({className:n,...r},c)=>e.jsx(Vs,{ref:c,className:Q("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",n),...r}));ao.displayName=Vs.displayName;const lo=u.forwardRef(({className:n,...r},c)=>e.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[e.jsx(zs,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),e.jsx(Vs.Input,{ref:c,className:Q("flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",n),...r})]}));lo.displayName=Vs.Input.displayName;const no=u.forwardRef(({className:n,...r},c)=>e.jsx(Vs.List,{ref:c,className:Q("max-h-[300px] overflow-y-auto overflow-x-hidden",n),...r}));no.displayName=Vs.List.displayName;const io=u.forwardRef((n,r)=>e.jsx(Vs.Empty,{ref:r,className:"py-6 text-center text-sm",...n}));io.displayName=Vs.Empty.displayName;const fr=u.forwardRef(({className:n,...r},c)=>e.jsx(Vs.Group,{ref:c,className:Q("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",n),...r}));fr.displayName=Vs.Group.displayName;const Z0=u.forwardRef(({className:n,...r},c)=>e.jsx(Vs.Separator,{ref:c,className:Q("-mx-1 h-px bg-border",n),...r}));Z0.displayName=Vs.Separator.displayName;const pr=u.forwardRef(({className:n,...r},c)=>e.jsx(Vs.Item,{ref:c,className:Q("relative flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",n),...r}));pr.displayName=Vs.Item.displayName;const Cs=u.forwardRef(({className:n,...r},c)=>e.jsx(Kp,{ref:c,className:Q("grid place-content-center peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",n),...r,children:e.jsx(Pb,{className:Q("grid place-content-center text-current"),children:e.jsx(Na,{className:"h-4 w-4"})})}));Cs.displayName=Kp.displayName;const Cg=u.createContext(null),kg="maibot-completed-tours";function J0(){try{const n=localStorage.getItem(kg);return n?new Set(JSON.parse(n)):new Set}catch{return new Set}}function lp(n){localStorage.setItem(kg,JSON.stringify([...n]))}function I0({children:n}){const[r,c]=u.useState({activeTourId:null,stepIndex:0,isRunning:!1}),d=u.useRef(new Map),[,h]=u.useState(0),[x,f]=u.useState(J0),j=u.useCallback((H,z)=>{d.current.set(H,z),h(V=>V+1)},[]),p=u.useCallback(H=>{d.current.delete(H),c(z=>z.activeTourId===H?{...z,activeTourId:null,isRunning:!1,stepIndex:0}:z)},[]),N=u.useCallback((H,z=0)=>{d.current.has(H)&&c({activeTourId:H,stepIndex:z,isRunning:!0})},[]),v=u.useCallback(()=>{c(H=>({...H,isRunning:!1}))},[]),C=u.useCallback(H=>{c(z=>({...z,stepIndex:H}))},[]),S=u.useCallback(()=>{c(H=>({...H,stepIndex:H.stepIndex+1}))},[]),w=u.useCallback(()=>{c(H=>({...H,stepIndex:Math.max(0,H.stepIndex-1)}))},[]),L=u.useCallback(()=>r.activeTourId?d.current.get(r.activeTourId)||[]:[],[r.activeTourId]),F=u.useCallback(H=>{f(z=>{const V=new Set(z);return V.add(H),lp(V),V})},[]),B=u.useCallback(H=>{const{action:z,index:V,status:Y,type:E}=H,R=["finished","skipped"];if(z==="close"){c(ne=>({...ne,isRunning:!1,stepIndex:0}));return}R.includes(Y)?c(ne=>(Y==="finished"&&ne.activeTourId&&setTimeout(()=>F(ne.activeTourId),0),{...ne,isRunning:!1,stepIndex:0})):E==="step:after"&&(z==="next"?c(ne=>({...ne,stepIndex:V+1})):z==="prev"&&c(ne=>({...ne,stepIndex:V-1})))},[F]),O=u.useCallback(H=>x.has(H),[x]),K=u.useCallback(H=>{f(z=>{const V=new Set(z);return V.delete(H),lp(V),V})},[]);return e.jsx(Cg.Provider,{value:{state:r,tours:d.current,registerTour:j,unregisterTour:p,startTour:N,stopTour:v,goToStep:C,nextStep:S,prevStep:w,getCurrentSteps:L,handleJoyrideCallback:B,isTourCompleted:O,markTourCompleted:F,resetTourCompleted:K},children:n})}function Xu(){const n=u.useContext(Cg);if(!n)throw new Error("useTour must be used within a TourProvider");return n}const P0={options:{zIndex:1e4,primaryColor:"hsl(var(--primary))",textColor:"hsl(var(--foreground))",backgroundColor:"hsl(var(--background))",arrowColor:"hsl(var(--background))",overlayColor:"rgba(0, 0, 0, 0.5)"},tooltip:{borderRadius:"var(--radius)",padding:"1rem"},tooltipContainer:{textAlign:"left"},tooltipTitle:{fontSize:"1rem",fontWeight:600,marginBottom:"0.5rem"},tooltipContent:{fontSize:"0.875rem",padding:"0.5rem 0"},buttonNext:{backgroundColor:"hsl(var(--primary))",color:"hsl(var(--primary-foreground))",borderRadius:"calc(var(--radius) - 2px)",fontSize:"0.875rem",padding:"0.5rem 1rem"},buttonBack:{color:"hsl(var(--muted-foreground))",fontSize:"0.875rem",marginRight:"0.5rem"},buttonSkip:{color:"hsl(var(--muted-foreground))",fontSize:"0.875rem"},buttonClose:{color:"hsl(var(--muted-foreground))"},spotlight:{borderRadius:"var(--radius)"}},W0={back:"上一步",close:"关闭",last:"完成",next:"下一步",nextLabelWithProgress:"下一步 ({step}/{steps})",open:"打开对话框",skip:"跳过"};function ew(){const{state:n,getCurrentSteps:r,handleJoyrideCallback:c}=Xu(),d=r(),[h,x]=u.useState(!1),f=u.useRef(n.stepIndex),j=u.useRef(null);u.useEffect(()=>{f.current!==n.stepIndex&&(x(!1),f.current=n.stepIndex)},[n.stepIndex]),u.useEffect(()=>{if(!n.isRunning||d.length===0){x(!1);return}const v=d[n.stepIndex];if(!v){x(!1);return}const C=v.target;if(C==="body"){x(!0);return}x(!1);const S=setTimeout(()=>{const w=()=>{const O=document.querySelector(C);if(O){const K=O.getBoundingClientRect();if(K.width>0&&K.height>0)return!0}return!1};if(w()){setTimeout(()=>x(!0),100);return}const L=setInterval(()=>{w()&&(clearInterval(L),setTimeout(()=>x(!0),100))},100),F=setTimeout(()=>{clearInterval(L),x(!0)},5e3),B=()=>{clearInterval(L),clearTimeout(F)};j.current=B},150);return()=>{clearTimeout(S),j.current&&(j.current(),j.current=null)}},[n.isRunning,n.stepIndex,d]);const p=u.useRef(null);if(u.useEffect(()=>{let v=document.getElementById("tour-portal-container");return v||(v=document.createElement("div"),v.id="tour-portal-container",v.style.cssText="position: fixed; top: 0; left: 0; z-index: 99999; pointer-events: none;",document.body.appendChild(v)),p.current=v,()=>{}},[]),!n.isRunning||d.length===0||!h)return null;const N=e.jsx(Fy,{steps:d,stepIndex:n.stepIndex,run:n.isRunning,continuous:!0,showSkipButton:!0,showProgress:!0,disableOverlayClose:!0,disableScrolling:!1,disableScrollParentFix:!1,callback:c,styles:P0,locale:W0,scrollOffset:80,scrollToFirstStep:!0,floaterProps:{styles:{floater:{zIndex:99999}},disableAnimation:!0}},`tour-step-${n.stepIndex}`);return p.current?eb.createPortal(N,p.current):N}const il="model-assignment-tour",Tg=[{target:"body",content:"本引导旨在帮助你配置模型提供商和对应的模型,并为麦麦的各个组件分配合适的模型。",placement:"center",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1},{target:'[data-tour="sidebar-model-provider"]',content:'第一步,你需要配置模型提供商。模型提供商决定了你要使用谁家的模型,无论是单一厂商(如 DeepSeek),还是模型平台(如 Siliconflow),都可以在这里进行配置。点击"下一步"进入配置页面。',placement:"right",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1},{target:'[data-tour="add-provider-button"]',content:'点击"添加提供商"按钮,开始配置你的模型提供商。',placement:"bottom",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!0,hideFooter:!0},{target:'[data-tour="provider-dialog"]',content:"在这里,你可以选择你想要配置的模型提供商,填写相关信息后保存即可。",placement:"left",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1},{target:'[data-tour="provider-name-input"]',content:"这里的名称是你为这个模型提供商起的一个名字,方便你在后续使用时识别它。",placement:"bottom",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1},{target:'[data-tour="provider-apikey-input"]',content:"这里需要填写你从模型提供商那里获取的 API 密钥,用于验证和调用模型服务。对于不同的提供商,获取 API 密钥的方式可能有所不同,请参考对应提供商的文档。",placement:"bottom",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1},{target:'[data-tour="provider-url-input"]',content:"这里需要填写模型提供商的 API 访问地址,确保填写正确以便系统能够连接到模型服务。对于不同的提供商,API 地址可能有所不同,请参考对应提供商的文档。",placement:"bottom",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1},{target:'[data-tour="provider-template-select"]',content:"当然,如果你不知道如何填写这些信息,很多模型提供商在这里都提供了预设的模板供你选择,选择对应的模板后,相关信息会自动填充。",placement:"bottom",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1},{target:'[data-tour="provider-save-button"]',content:"填写完所有信息后,点击保存按钮,模型提供商就配置完成了。",placement:"top",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1},{target:'[data-tour="provider-cancel-button"]',content:"因为这次咱们什么都没有填写,所以点击取消按钮退出吧。",placement:"top",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!0,hideFooter:!0},{target:'[data-tour="sidebar-model-management"]',content:'配置好模型提供商后,接下来我们需要为麦麦添加模型并分配功能。点击"下一步"进入模型管理页面。',placement:"right",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1},{target:'[data-tour="add-model-button"]',content:'在为麦麦的组件分配模型之前,首先需要添加你想要分配的模型,点击"添加模型"按钮开始添加。',placement:"bottom",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!0,hideFooter:!0},{target:'[data-tour="model-dialog"]',content:"在这里,你可以选择你之前配置好的模型提供商,然后选择对应的模型来添加。",placement:"left",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1},{target:'[data-tour="model-name-input"]',content:"这里的模型名称是你为这个模型起的一个名字,方便你在后续使用时识别它。",placement:"bottom",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1},{target:'[data-tour="model-provider-select"]',content:"在这里选择你之前配置好的模型提供商,这样系统才能知道你要添加哪个提供商的模型。",placement:"bottom",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1},{target:'[data-tour="model-identifier-input"]',content:"这里需要填写你想要添加的模型的标识符,不同的模型提供商可能有不同的标识符格式,请参考对应提供商的文档。",placement:"bottom",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1},{target:'[data-tour="model-save-button"]',content:"填写完所有信息后,点击保存按钮,模型就添加完成了。",placement:"top",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1},{target:'[data-tour="model-cancel-button"]',content:"当然,因为这次咱们什么都没有填写,所以直接点击取消按钮退出吧,等你准备好了再来添加模型。",placement:"top",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!0,hideFooter:!0},{target:'[data-tour="tasks-tab-trigger"]',content:'最后一步,添加好模型后,切换到"为模型分配功能"标签页,为麦麦的各个组件分配合适的模型。',placement:"bottom",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!0,hideFooter:!0},{target:'[data-tour="task-model-select"]',content:"在这里,你可以为每个组件选择一个或多个合适的模型,选择完成后配置会自动保存。恭喜你完成了模型配置的学习!",placement:"bottom",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1}],Eg={0:"/config/model",1:"/config/model",2:"/config/modelProvider",3:"/config/modelProvider",4:"/config/modelProvider",5:"/config/modelProvider",6:"/config/modelProvider",7:"/config/modelProvider",8:"/config/modelProvider",9:"/config/modelProvider",10:"/config/modelProvider",11:"/config/model",12:"/config/model",13:"/config/model",14:"/config/model",15:"/config/model",16:"/config/model",17:"/config/model",18:"/config/model",19:"/config/model"},lr=[{id:"siliconflow",name:"SiliconFlow",base_url:"https://api.siliconflow.cn/v1",client_type:"openai",display_name:"硅基流动 (SiliconFlow)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"deepseek",name:"DeepSeek",base_url:"https://api.deepseek.com",client_type:"openai",display_name:"DeepSeek",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"rinkoai",name:"RinkoAI",base_url:"https://rinkoai.com/v1",client_type:"openai",display_name:"RinkoAI",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"zhipu",name:"ZhipuAI",base_url:"https://open.bigmodel.cn/api/paas/v4",client_type:"openai",display_name:"智谱 AI (ZhipuAI / GLM)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"moonshot",name:"Moonshot",base_url:"https://api.moonshot.cn/v1",client_type:"openai",display_name:"月之暗面 (Moonshot / Kimi)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"doubao",name:"Doubao",base_url:"https://ark.cn-beijing.volces.com/api/v3",client_type:"openai",display_name:"字节豆包 (Doubao)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"alibaba",name:"Alibaba",base_url:"https://dashscope.aliyuncs.com/compatible-mode/v1",client_type:"openai",display_name:"阿里云百炼 (Alibaba Qwen)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"baichuan",name:"Baichuan",base_url:"https://api.baichuan-ai.com/v1",client_type:"openai",display_name:"百川智能 (Baichuan)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"minimax",name:"MiniMax",base_url:"https://api.minimax.chat/v1",client_type:"openai",display_name:"MiniMax (海螺 AI)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"stepfun",name:"StepFun",base_url:"https://api.stepfun.com/v1",client_type:"openai",display_name:"阶跃星辰 (StepFun)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"lingyi",name:"Lingyi",base_url:"https://api.lingyiwanwu.com/v1",client_type:"openai",display_name:"零一万物 (Lingyi / Yi)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"openai",name:"OpenAI",base_url:"https://api.openai.com/v1",client_type:"openai",display_name:"OpenAI",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"xai",name:"xAI",base_url:"https://api.x.ai/v1",client_type:"openai",display_name:"xAI (Grok)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"anthropic",name:"Anthropic",base_url:"https://api.anthropic.com/v1",client_type:"openai",display_name:"Anthropic (Claude)"},{id:"gemini",name:"Gemini",base_url:"https://generativelanguage.googleapis.com/v1beta",client_type:"gemini",display_name:"Google Gemini",modelFetcher:{endpoint:"/models",parser:"gemini"}},{id:"cohere",name:"Cohere",base_url:"https://api.cohere.ai/v1",client_type:"openai",display_name:"Cohere"},{id:"groq",name:"Groq",base_url:"https://api.groq.com/openai/v1",client_type:"openai",display_name:"Groq",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"together",name:"Together AI",base_url:"https://api.together.xyz/v1",client_type:"openai",display_name:"Together AI",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"fireworks",name:"Fireworks",base_url:"https://api.fireworks.ai/inference/v1",client_type:"openai",display_name:"Fireworks AI",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"mistral",name:"Mistral",base_url:"https://api.mistral.ai/v1",client_type:"openai",display_name:"Mistral AI",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"perplexity",name:"Perplexity",base_url:"https://api.perplexity.ai",client_type:"openai",display_name:"Perplexity AI"},{id:"custom",name:"",base_url:"",client_type:"openai",display_name:"自定义"}];function np(n){return n?n.replace(/\/+$/,"").toLowerCase():""}function tw(n){if(!n)return null;const r=np(n);return lr.find(c=>c.id!=="custom"&&np(c.base_url)===r)||null}function sw(){const[n,r]=u.useState([]),[c,d]=u.useState(!0),[h,x]=u.useState(!1),[f,j]=u.useState(!1),[p,N]=u.useState(!1),[v,C]=u.useState(!1),[S,w]=u.useState(!1),[L,F]=u.useState(!1),[B,O]=u.useState(null),[K,H]=u.useState(null),[z,V]=u.useState("custom"),[Y,E]=u.useState(!1),[R,ne]=u.useState(!1),[fe,Ce]=u.useState(null),[we,pe]=u.useState(!1),[Ne,be]=u.useState(""),[A,X]=u.useState(new Set),[T,te]=u.useState(!1),[_,me]=u.useState(1),[oe,ae]=u.useState(20),[xe,ve]=u.useState(""),[de,G]=u.useState({}),[W,U]=u.useState(new Set),[ee,Se]=u.useState(new Map),{toast:Me}=Xt(),tt=fa(),{state:Xe,goToStep:Ut,registerTour:Bt}=Xu(),re=u.useRef(null),ke=u.useRef(!0);u.useEffect(()=>{Bt(il,Tg)},[Bt]),u.useEffect(()=>{if(Xe.activeTourId===il&&Xe.isRunning){const P=Eg[Xe.stepIndex];P&&!window.location.pathname.endsWith(P.replace("/config/",""))&&tt({to:P})}},[Xe.stepIndex,Xe.activeTourId,Xe.isRunning,tt]);const Pe=u.useRef(Xe.stepIndex);u.useEffect(()=>{if(Xe.activeTourId===il&&Xe.isRunning){const P=Pe.current,ye=Xe.stepIndex;P>=3&&P<=9&&ye<3&&F(!1),P>=10&&ye>=3&&ye<=9&&(G({}),V("custom"),O({name:"",base_url:"",api_key:"",client_type:"openai",max_retry:2,timeout:30,retry_interval:10}),H(null),pe(!1),F(!0)),Pe.current=ye}},[Xe.stepIndex,Xe.activeTourId,Xe.isRunning]),u.useEffect(()=>{if(Xe.activeTourId!==il||!Xe.isRunning)return;const P=ye=>{const Re=ye.target,us=Xe.stepIndex;us===2&&Re.closest('[data-tour="add-provider-button"]')?setTimeout(()=>Ut(3),300):us===9&&Re.closest('[data-tour="provider-cancel-button"]')&&setTimeout(()=>Ut(10),300)};return document.addEventListener("click",P,!0),()=>document.removeEventListener("click",P,!0)},[Xe,Ut]),u.useEffect(()=>{Fe()},[]);const Fe=async()=>{try{d(!0);const P=await ei();r(P.api_providers||[]),N(!1),ke.current=!1}catch(P){console.error("加载配置失败:",P)}finally{d(!1)}},ts=async()=>{try{C(!0),so().catch(()=>{}),w(!0)}catch(P){console.error("重启失败:",P),w(!1),Me({title:"重启失败",description:"无法发送重启请求,请手动重启",variant:"destructive"}),C(!1)}},As=async()=>{try{x(!0),re.current&&clearTimeout(re.current);const P=await ei();P.api_providers=n,await eo(P),N(!1),Me({title:"保存成功",description:"正在重启麦麦..."}),await ts()}catch(P){console.error("保存配置失败:",P),Me({title:"保存失败",description:P.message,variant:"destructive"}),x(!1)}},js=()=>{localStorage.removeItem("access-token"),window.location.href="/auth"},Ke=()=>{w(!1),C(!1),Me({title:"重启超时",description:"服务未能在预期时间内恢复,请手动检查或刷新页面",variant:"destructive"})},D=u.useCallback(async P=>{if(!ke.current)try{j(!0),await Ou("api_providers",P),N(!1)}catch(ye){console.error("自动保存失败:",ye),N(!0)}finally{j(!1)}},[]);u.useEffect(()=>{if(!ke.current)return N(!0),re.current&&clearTimeout(re.current),re.current=setTimeout(()=>{D(n)},2e3),()=>{re.current&&clearTimeout(re.current)}},[n,D]);const De=async()=>{try{x(!0),re.current&&clearTimeout(re.current);const P=await ei();P.api_providers=n,await eo(P),N(!1),Me({title:"保存成功",description:"模型提供商配置已保存"})}catch(P){console.error("保存配置失败:",P),Me({title:"保存失败",description:P.message,variant:"destructive"})}finally{x(!1)}},ze=(P,ye)=>{if(G({}),P){const Re=lr.find(us=>us.base_url===P.base_url&&us.client_type===P.client_type);V(Re?.id||"custom"),O(P)}else V("custom"),O({name:"",base_url:"",api_key:"",client_type:"openai",max_retry:2,timeout:30,retry_interval:10});H(ye),pe(!1),F(!0)},Ve=P=>{V(P),E(!1);const ye=lr.find(Re=>Re.id===P);ye&&ye.id!=="custom"?O(Re=>({...Re,name:ye.name,base_url:ye.base_url,client_type:ye.client_type})):ye?.id==="custom"&&O(Re=>({...Re,name:"",base_url:"",client_type:"openai"}))},At=u.useMemo(()=>z!=="custom",[z]),We=async()=>{if(B?.api_key)try{await navigator.clipboard.writeText(B.api_key),Me({title:"复制成功",description:"API Key 已复制到剪贴板"})}catch{Me({title:"复制失败",description:"无法访问剪贴板",variant:"destructive"})}},ss=()=>{if(!B)return;const P={};if(B.name?.trim()||(P.name="请输入提供商名称"),B.base_url?.trim()||(P.base_url="请输入基础 URL"),B.api_key?.trim()||(P.api_key="请输入 API Key"),Object.keys(P).length>0){G(P);return}G({});const ye={...B,max_retry:B.max_retry??2,timeout:B.timeout??30,retry_interval:B.retry_interval??10};if(K!==null){const Re=[...n];Re[K]=ye,r(Re)}else r([...n,ye]);F(!1),O(null),H(null)},gt=P=>{if(!P&&B){const ye={...B,max_retry:B.max_retry??2,timeout:B.timeout??30,retry_interval:B.retry_interval??10};O(ye)}F(P)},_e=P=>{Ce(P),ne(!0)},je=()=>{if(fe!==null){const P=n.filter((ye,Re)=>Re!==fe);r(P),Me({title:"删除成功",description:"提供商已从列表中移除"})}ne(!1),Ce(null)},yt=P=>{const ye=new Set(A);ye.has(P)?ye.delete(P):ye.add(P),X(ye)},Ht=()=>{if(A.size===Kt.length)X(new Set);else{const P=Kt.map((ye,Re)=>n.findIndex(us=>us===Kt[Re]));X(new Set(P))}},pa=()=>{if(A.size===0){Me({title:"提示",description:"请先选择要删除的提供商",variant:"default"});return}te(!0)},Ts=()=>{const P=n.filter((ye,Re)=>!A.has(Re));r(P),X(new Set),te(!1),Me({title:"批量删除成功",description:`已删除 ${A.size} 个提供商`})},Kt=n.filter(P=>{if(!Ne)return!0;const ye=Ne.toLowerCase();return P.name.toLowerCase().includes(ye)||P.base_url.toLowerCase().includes(ye)||P.client_type.toLowerCase().includes(ye)}),Ms=Math.ceil(Kt.length/oe),Ds=Kt.slice((_-1)*oe,_*oe),Ha=()=>{const P=parseInt(xe);P>=1&&P<=Ms&&(me(P),ve(""))},Fs=async P=>{U(ye=>new Set(ye).add(P));try{const ye=await C0(P);Se(Re=>new Map(Re).set(P,ye)),ye.network_ok?ye.api_key_valid===!0?Me({title:"连接正常",description:`${P} 网络连接正常,API Key 有效 (${ye.latency_ms}ms)`}):ye.api_key_valid===!1?Me({title:"连接正常但 Key 无效",description:`${P} 网络连接正常,但 API Key 无效或已过期`,variant:"destructive"}):Me({title:"网络连接正常",description:`${P} 可以访问 (${ye.latency_ms}ms)`}):Me({title:"连接失败",description:ye.error||"无法连接到提供商",variant:"destructive"})}catch(ye){Me({title:"测试失败",description:ye.message,variant:"destructive"})}finally{U(ye=>{const Re=new Set(ye);return Re.delete(P),Re})}},qa=async()=>{for(const P of n)await Fs(P.name)},Sa=P=>{const ye=W.has(P),Re=ee.get(P);return ye?e.jsxs(Je,{variant:"secondary",className:"gap-1",children:[e.jsx(Ss,{className:"h-3 w-3 animate-spin"}),"测试中"]}):Re?Re.network_ok?Re.api_key_valid===!0?e.jsxs(Je,{className:"gap-1 bg-green-600 hover:bg-green-700",children:[e.jsx(ha,{className:"h-3 w-3"}),"正常"]}):Re.api_key_valid===!1?e.jsxs(Je,{variant:"destructive",className:"gap-1",children:[e.jsx(Oa,{className:"h-3 w-3"}),"Key无效"]}):e.jsxs(Je,{className:"gap-1 bg-blue-600 hover:bg-blue-700",children:[e.jsx(ha,{className:"h-3 w-3"}),"可访问"]}):e.jsxs(Je,{variant:"destructive",className:"gap-1",children:[e.jsx(sg,{className:"h-3 w-3"}),"离线"]}):null};return c?e.jsx("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("p",{className:"text-muted-foreground",children:"加载中..."})})}):e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"AI模型厂商配置"}),e.jsx("p",{className:"text-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:"管理 AI 模型厂商的 API 配置"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[A.size>0&&e.jsxs(b,{onClick:pa,size:"sm",variant:"destructive",className:"w-full sm:w-auto",children:[e.jsx(at,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),"批量删除 (",A.size,")"]}),e.jsxs(b,{onClick:qa,size:"sm",variant:"outline",className:"w-full sm:w-auto",disabled:n.length===0||W.size>0,children:[e.jsx(ln,{className:"mr-2 h-4 w-4"}),W.size>0?`测试中 (${W.size})`:"测试全部"]}),e.jsxs(b,{onClick:()=>ze(null,null),size:"sm",className:"w-full sm:w-auto","data-tour":"add-provider-button",children:[e.jsx(hs,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),"添加提供商"]}),e.jsxs(b,{onClick:De,disabled:h||f||!p||v,size:"sm",variant:"outline",className:"w-full sm:w-auto sm:min-w-[120px]",children:[e.jsx(jr,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),h?"保存中...":f?"自动保存中...":p?"保存配置":"已保存"]}),e.jsxs(bt,{children:[e.jsx(es,{asChild:!0,children:e.jsxs(b,{disabled:h||f||v,size:"sm",className:"w-full sm:w-auto sm:min-w-[120px]",children:[e.jsx(gr,{className:"mr-2 h-4 w-4"}),v?"重启中...":p?"保存并重启":"重启麦麦"]})}),e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认重启麦麦?"}),e.jsx(xt,{asChild:!0,children:e.jsx("div",{children:e.jsx("p",{children:p?"当前有未保存的配置更改。点击确认将先保存配置,然后重启麦麦使新配置生效。重启过程中麦麦将暂时离线。":"即将重启麦麦主程序。重启过程中麦麦将暂时离线,配置将在重启后生效。"})})})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:p?As:ts,children:p?"保存并重启":"确认重启"})]})]})]})]})]}),e.jsxs(cl,{children:[e.jsx(Ra,{className:"h-4 w-4"}),e.jsxs(ol,{children:["配置更新后需要",e.jsx("strong",{children:"重启麦麦"}),'才能生效。你可以点击右上角的"保存并重启"按钮一键完成保存和重启。']})]}),e.jsxs(st,{className:"h-[calc(100vh-260px)]",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center gap-2 mb-4",children:[e.jsxs("div",{className:"relative w-full sm:flex-1 sm:max-w-sm",children:[e.jsx(zs,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ce,{placeholder:"搜索提供商名称、URL 或类型...",value:Ne,onChange:P=>be(P.target.value),className:"pl-9"})]}),Ne&&e.jsxs("p",{className:"text-sm text-muted-foreground whitespace-nowrap",children:["找到 ",Kt.length," 个结果"]})]}),e.jsx("div",{className:"md:hidden space-y-3",children:Kt.length===0?e.jsx("div",{className:"text-center text-muted-foreground py-8 rounded-lg border bg-card",children:Ne?"未找到匹配的提供商":'暂无提供商配置,点击"添加提供商"开始配置'}):Ds.map((P,ye)=>{const Re=n.findIndex(us=>us===P);return e.jsxs("div",{className:"rounded-lg border bg-card p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("h3",{className:"font-semibold text-base truncate",children:P.name}),Sa(P.name)]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1 break-all",children:P.base_url})]}),e.jsxs("div",{className:"flex gap-1 flex-shrink-0",children:[e.jsx(b,{variant:"outline",size:"sm",onClick:()=>Fs(P.name),disabled:W.has(P.name),title:"测试连接",children:W.has(P.name)?e.jsx(Ss,{className:"h-4 w-4 animate-spin"}):e.jsx(ln,{className:"h-4 w-4"})}),e.jsx(b,{variant:"default",size:"sm",onClick:()=>ze(P,Re),children:e.jsx(nn,{className:"h-4 w-4",strokeWidth:2,fill:"none"})}),e.jsx(b,{size:"sm",onClick:()=>_e(Re),className:"bg-red-600 hover:bg-red-700 text-white",children:e.jsx(at,{className:"h-4 w-4",strokeWidth:2,fill:"none"})})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"客户端类型"}),e.jsx("p",{className:"font-medium",children:P.client_type})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"最大重试"}),e.jsx("p",{className:"font-medium",children:P.max_retry})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"超时(秒)"}),e.jsx("p",{className:"font-medium",children:P.timeout})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"重试间隔(秒)"}),e.jsx("p",{className:"font-medium",children:P.retry_interval})]})]})]},ye)})}),e.jsx("div",{className:"hidden md:block rounded-lg border bg-card overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(li,{children:[e.jsx(ni,{children:e.jsxs(_s,{children:[e.jsx(rt,{className:"w-12",children:e.jsx(Cs,{checked:A.size===Kt.length&&Kt.length>0,onCheckedChange:Ht})}),e.jsx(rt,{children:"状态"}),e.jsx(rt,{children:"名称"}),e.jsx(rt,{children:"基础URL"}),e.jsx(rt,{children:"客户端类型"}),e.jsx(rt,{className:"text-right",children:"最大重试"}),e.jsx(rt,{className:"text-right",children:"超时(秒)"}),e.jsx(rt,{className:"text-right",children:"重试间隔(秒)"}),e.jsx(rt,{className:"text-right",children:"操作"})]})}),e.jsx(ii,{children:Ds.length===0?e.jsx(_s,{children:e.jsx(Ze,{colSpan:9,className:"text-center text-muted-foreground py-8",children:Ne?"未找到匹配的提供商":'暂无提供商配置,点击"添加提供商"开始配置'})}):Ds.map((P,ye)=>{const Re=n.findIndex(us=>us===P);return e.jsxs(_s,{children:[e.jsx(Ze,{children:e.jsx(Cs,{checked:A.has(Re),onCheckedChange:()=>yt(Re)})}),e.jsx(Ze,{children:Sa(P.name)||e.jsx(Je,{variant:"outline",className:"text-muted-foreground",children:"未测试"})}),e.jsx(Ze,{className:"font-medium",children:P.name}),e.jsx(Ze,{className:"max-w-xs truncate",title:P.base_url,children:P.base_url}),e.jsx(Ze,{children:P.client_type}),e.jsx(Ze,{className:"text-right",children:P.max_retry}),e.jsx(Ze,{className:"text-right",children:P.timeout}),e.jsx(Ze,{className:"text-right",children:P.retry_interval}),e.jsx(Ze,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(b,{variant:"outline",size:"sm",onClick:()=>Fs(P.name),disabled:W.has(P.name),title:"测试连接",children:W.has(P.name)?e.jsx(Ss,{className:"h-4 w-4 animate-spin"}):e.jsx(ln,{className:"h-4 w-4"})}),e.jsxs(b,{variant:"default",size:"sm",onClick:()=>ze(P,Re),children:[e.jsx(nn,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"编辑"]}),e.jsxs(b,{size:"sm",onClick:()=>_e(Re),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(at,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"删除"]})]})})]},ye)})})]})})}),Kt.length>0&&e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4 mt-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{htmlFor:"page-size-provider",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(qe,{value:oe.toString(),onValueChange:P=>{ae(parseInt(P)),me(1),X(new Set)},children:[e.jsx(Be,{id:"page-size-provider",className:"w-20",children:e.jsx(Ge,{})}),e.jsxs(He,{children:[e.jsx(ie,{value:"10",children:"10"}),e.jsx(ie,{value:"20",children:"20"}),e.jsx(ie,{value:"50",children:"50"}),e.jsx(ie,{value:"100",children:"100"})]})]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["显示 ",(_-1)*oe+1," 到"," ",Math.min(_*oe,Kt.length)," 条,共 ",Kt.length," 条"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(b,{variant:"outline",size:"sm",onClick:()=>me(1),disabled:_===1,className:"hidden sm:flex",children:e.jsx(vr,{className:"h-4 w-4"})}),e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>me(P=>Math.max(1,P-1)),disabled:_===1,children:[e.jsx(dn,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"上一页"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ce,{type:"number",value:xe,onChange:P=>ve(P.target.value),onKeyDown:P=>P.key==="Enter"&&Ha(),placeholder:_.toString(),className:"w-16 h-8 text-center",min:1,max:Ms}),e.jsx(b,{variant:"outline",size:"sm",onClick:Ha,disabled:!xe,className:"h-8",children:"跳转"})]}),e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>me(P=>P+1),disabled:_>=Ms,children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Ll,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(b,{variant:"outline",size:"sm",onClick:()=>me(Ms),disabled:_>=Ms,className:"hidden sm:flex",children:e.jsx(br,{className:"h-4 w-4"})})]})]})]}),e.jsx(Jt,{open:L,onOpenChange:gt,children:e.jsxs($t,{className:"max-w-[95vw] sm:max-w-2xl max-h-[90vh] overflow-y-auto","data-tour":"provider-dialog",preventOutsideClose:Xe.isRunning,children:[e.jsxs(Qt,{children:[e.jsx(Yt,{children:K!==null?"编辑提供商":"添加提供商"}),e.jsx(ds,{children:"配置 API 提供商的连接信息和参数"})]}),e.jsxs("form",{onSubmit:P=>{P.preventDefault(),ss()},autoComplete:"off",children:[e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-2","data-tour":"provider-template-select",children:[e.jsx(y,{htmlFor:"template",children:"提供商模板"}),e.jsxs(Ua,{open:Y,onOpenChange:E,children:[e.jsx(Ba,{asChild:!0,children:e.jsxs(b,{variant:"outline",role:"combobox","aria-expanded":Y,className:"w-full justify-between",children:[z?lr.find(P=>P.id===z)?.display_name:"选择提供商模板...",e.jsx(qu,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(_a,{className:"p-0",align:"start",style:{width:"var(--radix-popover-trigger-width)"},children:e.jsxs(ao,{children:[e.jsx(lo,{placeholder:"搜索提供商模板..."}),e.jsx(st,{className:"h-[300px]",children:e.jsxs(no,{className:"max-h-none overflow-visible",children:[e.jsx(io,{children:"未找到匹配的模板"}),e.jsx(fr,{children:lr.map(P=>e.jsxs(pr,{value:P.display_name,onSelect:()=>Ve(P.id),children:[e.jsx(Na,{className:`mr-2 h-4 w-4 ${z===P.id?"opacity-100":"opacity-0"}`}),P.display_name]},P.id))})]})})]})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"选择预设模板可自动填充 URL 和客户端类型,支持搜索"})]}),e.jsxs("div",{className:"grid gap-2","data-tour":"provider-name-input",children:[e.jsx(y,{htmlFor:"name",className:de.name?"text-destructive":"",children:"名称 *"}),e.jsx(ce,{id:"name",value:B?.name||"",onChange:P=>{O(ye=>ye?{...ye,name:P.target.value}:null),de.name&&G(ye=>({...ye,name:void 0}))},placeholder:"例如: DeepSeek, SiliconFlow",className:de.name?"border-destructive focus-visible:ring-destructive":""}),de.name&&e.jsx("p",{className:"text-xs text-destructive",children:de.name})]}),e.jsxs("div",{className:"grid gap-2","data-tour":"provider-url-input",children:[e.jsx(y,{htmlFor:"base_url",className:de.base_url?"text-destructive":"",children:"基础 URL *"}),e.jsx(ce,{id:"base_url",value:B?.base_url||"",onChange:P=>{O(ye=>ye?{...ye,base_url:P.target.value}:null),de.base_url&&G(ye=>({...ye,base_url:void 0}))},placeholder:"https://api.example.com/v1",disabled:At,className:`${At?"bg-muted cursor-not-allowed":""} ${de.base_url?"border-destructive focus-visible:ring-destructive":""}`}),de.base_url&&e.jsx("p",{className:"text-xs text-destructive",children:de.base_url}),At&&!de.base_url&&e.jsx("p",{className:"text-xs text-muted-foreground",children:'使用模板时 URL 不可编辑,切换到"自定义"以手动配置'})]}),e.jsxs("div",{className:"grid gap-2","data-tour":"provider-apikey-input",children:[e.jsx(y,{htmlFor:"api_key",className:de.api_key?"text-destructive":"",children:"API Key *"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ce,{id:"api_key",type:we?"text":"password",value:B?.api_key||"",onChange:P=>{O(ye=>ye?{...ye,api_key:P.target.value}:null),de.api_key&&G(ye=>({...ye,api_key:void 0}))},placeholder:"sk-...",className:`flex-1 ${de.api_key?"border-destructive focus-visible:ring-destructive":""}`}),e.jsx(b,{type:"button",variant:"outline",size:"icon",onClick:()=>pe(!we),title:we?"隐藏密钥":"显示密钥",children:we?e.jsx(or,{className:"h-4 w-4"}):e.jsx(Ws,{className:"h-4 w-4"})}),e.jsx(b,{type:"button",variant:"outline",size:"icon",onClick:We,title:"复制密钥",children:e.jsx(Jc,{className:"h-4 w-4"})})]}),de.api_key&&e.jsx("p",{className:"text-xs text-destructive",children:de.api_key})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"client_type",children:"客户端类型"}),e.jsxs(qe,{value:B?.client_type||"openai",onValueChange:P=>O(ye=>ye?{...ye,client_type:P}:null),disabled:At,children:[e.jsx(Be,{id:"client_type",className:At?"bg-muted cursor-not-allowed":"",children:e.jsx(Ge,{placeholder:"选择客户端类型"})}),e.jsxs(He,{children:[e.jsx(ie,{value:"openai",children:"OpenAI"}),e.jsx(ie,{value:"gemini",children:"Gemini"})]})]}),At&&e.jsx("p",{className:"text-xs text-muted-foreground",children:'使用模板时客户端类型不可编辑,切换到"自定义"以手动配置'})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"max_retry",children:"最大重试"}),e.jsx(ce,{id:"max_retry",type:"number",min:"0",value:B?.max_retry??"",onChange:P=>{const ye=P.target.value===""?null:parseInt(P.target.value);O(Re=>Re?{...Re,max_retry:ye}:null)},placeholder:"默认: 2"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"timeout",children:"超时(秒)"}),e.jsx(ce,{id:"timeout",type:"number",min:"1",value:B?.timeout??"",onChange:P=>{const ye=P.target.value===""?null:parseInt(P.target.value);O(Re=>Re?{...Re,timeout:ye}:null)},placeholder:"默认: 30"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"retry_interval",children:"重试间隔(秒)"}),e.jsx(ce,{id:"retry_interval",type:"number",min:"1",value:B?.retry_interval??"",onChange:P=>{const ye=P.target.value===""?null:parseInt(P.target.value);O(Re=>Re?{...Re,retry_interval:ye}:null)},placeholder:"默认: 10"})]})]})]}),e.jsxs(xs,{children:[e.jsx(b,{type:"button",variant:"outline",onClick:()=>F(!1),"data-tour":"provider-cancel-button",children:"取消"}),e.jsx(b,{type:"submit","data-tour":"provider-save-button",children:"保存"})]})]})]})}),e.jsx(bt,{open:R,onOpenChange:ne,children:e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认删除"}),e.jsxs(xt,{children:['确定要删除提供商 "',fe!==null?n[fe]?.name:"",'" 吗? 此操作无法撤销。']})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:je,children:"删除"})]})]})}),e.jsx(bt,{open:T,onOpenChange:te,children:e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认批量删除"}),e.jsxs(xt,{children:["确定要删除选中的 ",A.size," 个提供商吗? 此操作无法撤销。"]})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:Ts,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"批量删除"})]})]})}),S&&e.jsx(Yu,{onRestartComplete:js,onRestartFailed:Ke})]})}function aw({value:n,label:r,onRemove:c}){const{attributes:d,listeners:h,setNodeRef:x,transform:f,transition:j,isDragging:p}=eN({id:n}),N={transform:tN.Transform.toString(f),transition:j,opacity:p?.5:1},v=S=>{S.preventDefault(),S.stopPropagation(),c(n)},C=S=>{S.stopPropagation()};return e.jsx("div",{ref:x,style:N,className:Q("inline-flex items-center gap-1",p&&"shadow-lg"),children:e.jsxs(Je,{variant:"secondary",className:"cursor-move hover:bg-secondary/80 flex items-center gap-1",children:[e.jsx("div",{...d,...h,className:"cursor-grab active:cursor-grabbing flex items-center",children:e.jsx(jy,{className:"h-3 w-3 text-muted-foreground"})}),e.jsx("span",{children:r}),e.jsx("button",{type:"button",className:"ml-1 rounded-sm hover:bg-destructive/20 focus:outline-none focus:ring-1 focus:ring-destructive",onClick:v,onPointerDown:C,onMouseDown:S=>S.stopPropagation(),children:e.jsx(on,{className:"h-3 w-3 cursor-pointer hover:text-destructive",strokeWidth:2,fill:"none"})})]})})}function lw({options:n,selected:r,onChange:c,placeholder:d="选择选项...",emptyText:h="未找到选项",className:x}){const[f,j]=u.useState(!1),p=Qy(Yf(Wy,{activationConstraint:{distance:8}}),Yf(Py,{coordinateGetter:Iy})),N=S=>{r.includes(S)?c(r.filter(w=>w!==S)):c([...r,S])},v=S=>{c(r.filter(w=>w!==S))},C=S=>{const{active:w,over:L}=S;if(L&&w.id!==L.id){const F=r.indexOf(w.id),B=r.indexOf(L.id);c(Jy(r,F,B))}};return e.jsxs(Ua,{open:f,onOpenChange:j,children:[e.jsx(Ba,{asChild:!0,children:e.jsxs(b,{variant:"outline",role:"combobox","aria-expanded":f,className:Q("w-full justify-between min-h-10 h-auto",x),children:[e.jsx(Yy,{sensors:p,collisionDetection:Xy,onDragEnd:C,children:e.jsx(Ky,{items:r,strategy:Zy,children:e.jsx("div",{className:"flex gap-1 flex-wrap flex-1",children:r.length===0?e.jsx("span",{className:"text-muted-foreground",children:d}):r.map(S=>{const w=n.find(L=>L.value===S);return e.jsx(aw,{value:S,label:w?.label||S,onRemove:v},S)})})})}),e.jsx(qu,{className:"ml-2 h-4 w-4 shrink-0 opacity-50",strokeWidth:2,fill:"none"})]})}),e.jsx(_a,{className:"w-full p-0",align:"start",children:e.jsxs(ao,{children:[e.jsx(lo,{placeholder:"搜索...",className:"h-9"}),e.jsxs(no,{children:[e.jsx(io,{children:h}),e.jsx(fr,{children:n.map(S=>{const w=r.includes(S.value);return e.jsxs(pr,{value:S.value,onSelect:()=>N(S.value),children:[e.jsx("div",{className:Q("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",w?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(Na,{className:"h-3 w-3",strokeWidth:2,fill:"none"})}),e.jsx("span",{children:S.label})]},S.value)})})]})]})})]})}const ip=new Map,nw=300*1e3;function iw(){const[n,r]=u.useState([]),[c,d]=u.useState([]),[h,x]=u.useState([]),[f,j]=u.useState([]),[p,N]=u.useState(null),[v,C]=u.useState(!0),[S,w]=u.useState(!1),[L,F]=u.useState(!1),[B,O]=u.useState(!1),[K,H]=u.useState(!1),[z,V]=u.useState(!1),[Y,E]=u.useState(!1),[R,ne]=u.useState(null),[fe,Ce]=u.useState(null),[we,pe]=u.useState(!1),[Ne,be]=u.useState(null),[A,X]=u.useState(""),[T,te]=u.useState(new Set),[_,me]=u.useState(!1),[oe,ae]=u.useState(1),[xe,ve]=u.useState(20),[de,G]=u.useState(""),[W,U]=u.useState([]),[ee,Se]=u.useState(!1),[Me,tt]=u.useState(null),[Xe,Ut]=u.useState(!1),[Bt,re]=u.useState(null),[ke,Pe]=u.useState({}),{toast:Fe}=Xt(),ts=fa(),{registerTour:As,startTour:js,state:Ke,goToStep:D}=Xu(),De=u.useRef(null),ze=u.useRef(null),Ve=u.useRef(!0);u.useEffect(()=>{As(il,Tg)},[As]),u.useEffect(()=>{if(Ke.activeTourId===il&&Ke.isRunning){const $=Eg[Ke.stepIndex];$&&!window.location.pathname.endsWith($.replace("/config/",""))&&ts({to:$})}},[Ke.stepIndex,Ke.activeTourId,Ke.isRunning,ts]);const At=u.useRef(Ke.stepIndex);u.useEffect(()=>{if(Ke.activeTourId===il&&Ke.isRunning){const $=At.current,ge=Ke.stepIndex;$>=12&&$<=17&&ge<12&&E(!1),At.current=ge}},[Ke.stepIndex,Ke.activeTourId,Ke.isRunning]),u.useEffect(()=>{if(Ke.activeTourId!==il||!Ke.isRunning)return;const $=ge=>{const Le=ge.target,$e=Ke.stepIndex;$e===2&&Le.closest('[data-tour="add-provider-button"]')?setTimeout(()=>D(3),300):$e===9&&Le.closest('[data-tour="provider-cancel-button"]')?setTimeout(()=>D(10),300):$e===11&&Le.closest('[data-tour="add-model-button"]')?setTimeout(()=>D(12),300):$e===17&&Le.closest('[data-tour="model-cancel-button"]')?setTimeout(()=>D(18),300):$e===18&&Le.closest('[data-tour="tasks-tab-trigger"]')&&setTimeout(()=>D(19),300)};return document.addEventListener("click",$,!0),()=>document.removeEventListener("click",$,!0)},[Ke,D]);const We=()=>{js(il)};u.useEffect(()=>{ss()},[]);const ss=async()=>{try{C(!0);const $=await ei(),ge=$.models||[];r(ge),j(ge.map($e=>$e.name));const Le=$.api_providers||[];d(Le.map($e=>$e.name)),x(Le),N($.model_task_config||null),O(!1),Ve.current=!1}catch($){console.error("加载配置失败:",$)}finally{C(!1)}},gt=u.useCallback($=>h.find(ge=>ge.name===$),[h]),_e=u.useCallback(async($,ge=!1)=>{const Le=gt($);if(!Le?.base_url){U([]),re(null),tt('提供商配置不完整,请先在"模型提供商配置"中配置');return}if(!Le.api_key){U([]),re(null),tt('该提供商未配置 API Key,请先在"模型提供商配置"中填写');return}const $e=tw(Le.base_url);if(re($e),!$e?.modelFetcher){U([]),tt(null);return}const jt=`${$}:${Le.base_url}`,ea=ip.get(jt);if(!ge&&ea&&Date.now()-ea.timestamp{Y&&R?.api_provider&&_e(R.api_provider)},[Y,R?.api_provider,_e]);const je=async()=>{try{H(!0),so().catch(()=>{}),V(!0)}catch($){console.error("重启失败:",$),V(!1),Fe({title:"重启失败",description:"无法发送重启请求,请手动重启",variant:"destructive"}),H(!1)}},yt=async()=>{try{w(!0),De.current&&clearTimeout(De.current),ze.current&&clearTimeout(ze.current);const $=await ei();$.models=n,$.model_task_config=p,await eo($),O(!1),Fe({title:"保存成功",description:"正在重启麦麦..."}),await je()}catch($){console.error("保存配置失败:",$),Fe({title:"保存失败",description:$.message,variant:"destructive"}),w(!1)}},Ht=()=>{localStorage.removeItem("access-token"),window.location.href="/auth"},pa=()=>{V(!1),H(!1),Fe({title:"重启超时",description:"服务未能在预期时间内恢复,请手动检查或刷新页面",variant:"destructive"})},Ts=u.useCallback(async $=>{if(!Ve.current)try{F(!0),await Ou("models",$),O(!1)}catch(ge){console.error("自动保存模型列表失败:",ge),O(!0)}finally{F(!1)}},[]),Kt=u.useCallback(async $=>{if(!Ve.current)try{F(!0),await Ou("model_task_config",$),O(!1)}catch(ge){console.error("自动保存任务配置失败:",ge),O(!0)}finally{F(!1)}},[]);u.useEffect(()=>{if(!Ve.current)return O(!0),De.current&&clearTimeout(De.current),De.current=setTimeout(()=>{Ts(n)},2e3),()=>{De.current&&clearTimeout(De.current)}},[n,Ts]),u.useEffect(()=>{if(!(Ve.current||!p))return O(!0),ze.current&&clearTimeout(ze.current),ze.current=setTimeout(()=>{Kt(p)},2e3),()=>{ze.current&&clearTimeout(ze.current)}},[p,Kt]);const Ms=async()=>{try{w(!0),De.current&&clearTimeout(De.current),ze.current&&clearTimeout(ze.current);const $=await ei();$.models=n,$.model_task_config=p,await eo($),O(!1),Fe({title:"保存成功",description:"模型配置已保存"}),await ss()}catch($){console.error("保存配置失败:",$),Fe({title:"保存失败",description:$.message,variant:"destructive"})}finally{w(!1)}},Ds=($,ge)=>{Pe({}),ne($||{model_identifier:"",name:"",api_provider:c[0]||"",price_in:0,price_out:0,force_stream_mode:!1,extra_params:{}}),Ce(ge),E(!0)},Ha=()=>{if(!R)return;const $={};if(R.name?.trim()||($.name="请输入模型名称"),R.api_provider?.trim()||($.api_provider="请选择 API 提供商"),R.model_identifier?.trim()||($.model_identifier="请输入模型标识符"),Object.keys($).length>0){Pe($);return}Pe({});const ge={...R,price_in:R.price_in??0,price_out:R.price_out??0};let Le,$e=null;if(fe!==null?($e=n[fe].name,Le=[...n],Le[fe]=ge):Le=[...n,ge],r(Le),j(Le.map(jt=>jt.name)),$e&&$e!==ge.name&&p){const jt=ea=>ea.map(ta=>ta===$e?ge.name:ta);N({...p,utils:{...p.utils,model_list:jt(p.utils?.model_list||[])},utils_small:{...p.utils_small,model_list:jt(p.utils_small?.model_list||[])},tool_use:{...p.tool_use,model_list:jt(p.tool_use?.model_list||[])},replyer:{...p.replyer,model_list:jt(p.replyer?.model_list||[])},planner:{...p.planner,model_list:jt(p.planner?.model_list||[])},vlm:{...p.vlm,model_list:jt(p.vlm?.model_list||[])},voice:{...p.voice,model_list:jt(p.voice?.model_list||[])},embedding:{...p.embedding,model_list:jt(p.embedding?.model_list||[])},lpmm_entity_extract:{...p.lpmm_entity_extract,model_list:jt(p.lpmm_entity_extract?.model_list||[])},lpmm_rdf_build:{...p.lpmm_rdf_build,model_list:jt(p.lpmm_rdf_build?.model_list||[])},lpmm_qa:{...p.lpmm_qa,model_list:jt(p.lpmm_qa?.model_list||[])}})}E(!1),ne(null),Ce(null)},Fs=$=>{if(!$&&R){const ge={...R,price_in:R.price_in??0,price_out:R.price_out??0};ne(ge)}E($)},qa=$=>{be($),pe(!0)},Sa=()=>{if(Ne!==null){const $=n.filter((ge,Le)=>Le!==Ne);r($),j($.map(ge=>ge.name)),Fe({title:"删除成功",description:"模型已从列表中移除"})}pe(!1),be(null)},P=$=>{const ge=new Set(T);ge.has($)?ge.delete($):ge.add($),te(ge)},ye=()=>{if(T.size===Os.length)te(new Set);else{const $=Os.map((ge,Le)=>n.findIndex($e=>$e===Os[Le]));te(new Set($))}},Re=()=>{if(T.size===0){Fe({title:"提示",description:"请先选择要删除的模型",variant:"default"});return}me(!0)},us=()=>{const $=n.filter((ge,Le)=>!T.has(Le));r($),j($.map(ge=>ge.name)),te(new Set),me(!1),Fe({title:"批量删除成功",description:`已删除 ${T.size} 个模型`})},$s=($,ge,Le)=>{p&&N({...p,[$]:{...p[$],[ge]:Le}})},Os=n.filter($=>{if(!A)return!0;const ge=A.toLowerCase();return $.name.toLowerCase().includes(ge)||$.model_identifier.toLowerCase().includes(ge)||$.api_provider.toLowerCase().includes(ge)}),dl=Math.ceil(Os.length/xe),Hl=Os.slice((oe-1)*xe,oe*xe),un=()=>{const $=parseInt(de);$>=1&&$<=dl&&(ae($),G(""))},mn=$=>p?[p.utils?.model_list||[],p.utils_small?.model_list||[],p.tool_use?.model_list||[],p.replyer?.model_list||[],p.planner?.model_list||[],p.vlm?.model_list||[],p.voice?.model_list||[],p.embedding?.model_list||[],p.lpmm_entity_extract?.model_list||[],p.lpmm_rdf_build?.model_list||[],p.lpmm_qa?.model_list||[]].some(Le=>Le.includes($)):!1;return v?e.jsx(st,{className:"h-full",children:e.jsx("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("p",{className:"text-muted-foreground",children:"加载中..."})})})}):e.jsx(st,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"模型管理与分配"}),e.jsx("p",{className:"text-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:"添加模型并为模型分配功能"})]}),e.jsxs("div",{className:"flex gap-2 w-full sm:w-auto",children:[e.jsxs(b,{onClick:Ms,disabled:S||L||!B||K,size:"sm",variant:"outline",className:"flex-1 sm:flex-none sm:min-w-[120px]",children:[e.jsx(jr,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),S?"保存中...":L?"自动保存中...":B?"保存配置":"已保存"]}),e.jsxs(bt,{children:[e.jsx(es,{asChild:!0,children:e.jsxs(b,{disabled:S||L||K,size:"sm",className:"flex-1 sm:flex-none sm:min-w-[120px]",children:[e.jsx(gr,{className:"mr-2 h-4 w-4"}),K?"重启中...":B?"保存并重启":"重启麦麦"]})}),e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认重启麦麦?"}),e.jsx(xt,{asChild:!0,children:e.jsx("div",{children:e.jsx("p",{children:B?"当前有未保存的配置更改。点击确认将先保存配置,然后重启麦麦使新配置生效。重启过程中麦麦将暂时离线。":"即将重启麦麦主程序。重启过程中麦麦将暂时离线,配置将在重启后生效。"})})})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:B?yt:je,children:B?"保存并重启":"确认重启"})]})]})]})]})]}),e.jsxs(cl,{children:[e.jsx(Ra,{className:"h-4 w-4"}),e.jsxs(ol,{children:["配置更新后需要",e.jsx("strong",{children:"重启麦麦"}),'才能生效。你可以点击右上角的"保存并重启"按钮一键完成保存和重启。']})]}),e.jsxs(cl,{className:"hidden lg:flex border-primary/30 bg-primary/5 cursor-pointer hover:bg-primary/10 transition-colors",onClick:We,children:[e.jsx(vy,{className:"h-4 w-4 text-primary"}),e.jsxs(ol,{className:"flex items-center justify-between",children:[e.jsxs("span",{children:[e.jsx("strong",{className:"text-primary",children:"新手引导:"}),"不知道如何配置模型?点击这里开始学习如何为麦麦的组件分配模型。"]}),e.jsx(b,{variant:"outline",size:"sm",className:"ml-4 shrink-0",children:"开始引导"})]})]}),e.jsxs(La,{defaultValue:"models",className:"w-full",children:[e.jsxs(wa,{className:"grid w-full max-w-full sm:max-w-md grid-cols-2",children:[e.jsx(it,{value:"models",children:"添加模型"}),e.jsx(it,{value:"tasks","data-tour":"tasks-tab-trigger",children:"为模型分配功能"})]}),e.jsxs(zt,{value:"models",className:"space-y-4 mt-0",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center gap-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"配置可用的模型列表"}),e.jsxs("div",{className:"flex gap-2 w-full sm:w-auto",children:[T.size>0&&e.jsxs(b,{onClick:Re,size:"sm",variant:"destructive",className:"w-full sm:w-auto",children:[e.jsx(at,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),"批量删除 (",T.size,")"]}),e.jsxs(b,{onClick:()=>Ds(null,null),size:"sm",variant:"outline",className:"w-full sm:w-auto","data-tour":"add-model-button",children:[e.jsx(hs,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),"添加模型"]})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center gap-2",children:[e.jsxs("div",{className:"relative w-full sm:flex-1 sm:max-w-sm",children:[e.jsx(zs,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ce,{placeholder:"搜索模型名称、标识符或提供商...",value:A,onChange:$=>X($.target.value),className:"pl-9"})]}),A&&e.jsxs("p",{className:"text-sm text-muted-foreground whitespace-nowrap",children:["找到 ",Os.length," 个结果"]})]}),e.jsx("div",{className:"md:hidden space-y-3",children:Hl.length===0?e.jsx("div",{className:"text-center text-muted-foreground py-8 rounded-lg border bg-card",children:A?"未找到匹配的模型":"暂无模型配置"}):Hl.map(($,ge)=>{const Le=n.findIndex(jt=>jt===$),$e=mn($.name);return e.jsxs("div",{className:"rounded-lg border bg-card p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("h3",{className:"font-semibold text-base",children:$.name}),e.jsx(Je,{variant:$e?"default":"secondary",className:$e?"bg-green-600 hover:bg-green-700":"",children:$e?"已使用":"未使用"})]}),e.jsx("p",{className:"text-xs text-muted-foreground break-all",title:$.model_identifier,children:$.model_identifier})]}),e.jsxs("div",{className:"flex gap-1 flex-shrink-0",children:[e.jsxs(b,{variant:"default",size:"sm",onClick:()=>Ds($,Le),children:[e.jsx(nn,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"编辑"]}),e.jsxs(b,{size:"sm",onClick:()=>qa(Le),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(at,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"删除"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"提供商"}),e.jsx("p",{className:"font-medium",children:$.api_provider})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"强制流式"}),e.jsx("p",{className:"font-medium",children:$.force_stream_mode?"是":"否"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"输入价格"}),e.jsxs("p",{className:"font-medium",children:["¥",$.price_in,"/M"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"输出价格"}),e.jsxs("p",{className:"font-medium",children:["¥",$.price_out,"/M"]})]})]})]},ge)})}),e.jsx("div",{className:"hidden md:block rounded-lg border bg-card overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(li,{children:[e.jsx(ni,{children:e.jsxs(_s,{children:[e.jsx(rt,{className:"w-12",children:e.jsx(Cs,{checked:T.size===Os.length&&Os.length>0,onCheckedChange:ye})}),e.jsx(rt,{className:"w-24",children:"使用状态"}),e.jsx(rt,{children:"模型名称"}),e.jsx(rt,{children:"模型标识符"}),e.jsx(rt,{children:"提供商"}),e.jsx(rt,{className:"text-right",children:"输入价格"}),e.jsx(rt,{className:"text-right",children:"输出价格"}),e.jsx(rt,{className:"text-center",children:"强制流式"}),e.jsx(rt,{className:"text-right",children:"操作"})]})}),e.jsx(ii,{children:Hl.length===0?e.jsx(_s,{children:e.jsx(Ze,{colSpan:9,className:"text-center text-muted-foreground py-8",children:A?"未找到匹配的模型":"暂无模型配置"})}):Hl.map(($,ge)=>{const Le=n.findIndex(jt=>jt===$),$e=mn($.name);return e.jsxs(_s,{children:[e.jsx(Ze,{children:e.jsx(Cs,{checked:T.has(Le),onCheckedChange:()=>P(Le)})}),e.jsx(Ze,{children:e.jsx(Je,{variant:$e?"default":"secondary",className:$e?"bg-green-600 hover:bg-green-700":"",children:$e?"已使用":"未使用"})}),e.jsx(Ze,{className:"font-medium",children:$.name}),e.jsx(Ze,{className:"max-w-xs truncate",title:$.model_identifier,children:$.model_identifier}),e.jsx(Ze,{children:$.api_provider}),e.jsxs(Ze,{className:"text-right",children:["¥",$.price_in,"/M"]}),e.jsxs(Ze,{className:"text-right",children:["¥",$.price_out,"/M"]}),e.jsx(Ze,{className:"text-center",children:$.force_stream_mode?"是":"否"}),e.jsx(Ze,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(b,{variant:"default",size:"sm",onClick:()=>Ds($,Le),children:[e.jsx(nn,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"编辑"]}),e.jsxs(b,{size:"sm",onClick:()=>qa(Le),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(at,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"删除"]})]})})]},ge)})})]})})}),Os.length>0&&e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4 mt-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{htmlFor:"page-size-model",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(qe,{value:xe.toString(),onValueChange:$=>{ve(parseInt($)),ae(1),te(new Set)},children:[e.jsx(Be,{id:"page-size-model",className:"w-20",children:e.jsx(Ge,{})}),e.jsxs(He,{children:[e.jsx(ie,{value:"10",children:"10"}),e.jsx(ie,{value:"20",children:"20"}),e.jsx(ie,{value:"50",children:"50"}),e.jsx(ie,{value:"100",children:"100"})]})]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["显示 ",(oe-1)*xe+1," 到"," ",Math.min(oe*xe,Os.length)," 条,共 ",Os.length," 条"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(b,{variant:"outline",size:"sm",onClick:()=>ae(1),disabled:oe===1,className:"hidden sm:flex",children:e.jsx(vr,{className:"h-4 w-4"})}),e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>ae($=>Math.max(1,$-1)),disabled:oe===1,children:[e.jsx(dn,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"上一页"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ce,{type:"number",value:de,onChange:$=>G($.target.value),onKeyDown:$=>$.key==="Enter"&&un(),placeholder:oe.toString(),className:"w-16 h-8 text-center",min:1,max:dl}),e.jsx(b,{variant:"outline",size:"sm",onClick:un,disabled:!de,className:"h-8",children:"跳转"})]}),e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>ae($=>$+1),disabled:oe>=dl,children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Ll,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(b,{variant:"outline",size:"sm",onClick:()=>ae(dl),disabled:oe>=dl,className:"hidden sm:flex",children:e.jsx(br,{className:"h-4 w-4"})})]})]})]}),e.jsxs(zt,{value:"tasks",className:"space-y-6 mt-0",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"为不同的任务配置使用的模型和参数"}),p&&e.jsxs("div",{className:"grid gap-4 sm:gap-6",children:[e.jsx(ba,{title:"组件模型 (utils)",description:"用于表情包、取名、关系、情绪变化等组件",taskConfig:p.utils,modelNames:f,onChange:($,ge)=>$s("utils",$,ge),dataTour:"task-model-select"}),e.jsx(ba,{title:"组件小模型 (utils_small)",description:"消耗量较大的组件,建议使用速度较快的小模型",taskConfig:p.utils_small,modelNames:f,onChange:($,ge)=>$s("utils_small",$,ge)}),e.jsx(ba,{title:"工具调用模型 (tool_use)",description:"需要使用支持工具调用的模型",taskConfig:p.tool_use,modelNames:f,onChange:($,ge)=>$s("tool_use",$,ge)}),e.jsx(ba,{title:"首要回复模型 (replyer)",description:"用于表达器和表达方式学习",taskConfig:p.replyer,modelNames:f,onChange:($,ge)=>$s("replyer",$,ge)}),e.jsx(ba,{title:"决策模型 (planner)",description:"负责决定麦麦该什么时候回复",taskConfig:p.planner,modelNames:f,onChange:($,ge)=>$s("planner",$,ge)}),e.jsx(ba,{title:"图像识别模型 (vlm)",description:"视觉语言模型",taskConfig:p.vlm,modelNames:f,onChange:($,ge)=>$s("vlm",$,ge),hideTemperature:!0}),e.jsx(ba,{title:"语音识别模型 (voice)",description:"语音转文字",taskConfig:p.voice,modelNames:f,onChange:($,ge)=>$s("voice",$,ge),hideTemperature:!0,hideMaxTokens:!0}),e.jsx(ba,{title:"嵌入模型 (embedding)",description:"用于向量化",taskConfig:p.embedding,modelNames:f,onChange:($,ge)=>$s("embedding",$,ge),hideTemperature:!0,hideMaxTokens:!0}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"LPMM 知识库模型"}),e.jsx(ba,{title:"实体提取模型 (lpmm_entity_extract)",description:"从文本中提取实体",taskConfig:p.lpmm_entity_extract,modelNames:f,onChange:($,ge)=>$s("lpmm_entity_extract",$,ge)}),e.jsx(ba,{title:"RDF 构建模型 (lpmm_rdf_build)",description:"构建知识图谱",taskConfig:p.lpmm_rdf_build,modelNames:f,onChange:($,ge)=>$s("lpmm_rdf_build",$,ge)}),e.jsx(ba,{title:"问答模型 (lpmm_qa)",description:"知识库问答",taskConfig:p.lpmm_qa,modelNames:f,onChange:($,ge)=>$s("lpmm_qa",$,ge)})]})]})]})]}),e.jsx(Jt,{open:Y,onOpenChange:Fs,children:e.jsxs($t,{className:"max-w-[95vw] sm:max-w-2xl max-h-[90vh] overflow-y-auto","data-tour":"model-dialog",preventOutsideClose:Ke.isRunning,children:[e.jsxs(Qt,{children:[e.jsx(Yt,{children:fe!==null?"编辑模型":"添加模型"}),e.jsx(ds,{children:"配置模型的基本信息和参数"})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-2","data-tour":"model-name-input",children:[e.jsx(y,{htmlFor:"model_name",className:ke.name?"text-destructive":"",children:"模型名称 *"}),e.jsx(ce,{id:"model_name",value:R?.name||"",onChange:$=>{ne(ge=>ge?{...ge,name:$.target.value}:null),ke.name&&Pe(ge=>({...ge,name:void 0}))},placeholder:"例如: qwen3-30b",className:ke.name?"border-destructive focus-visible:ring-destructive":""}),ke.name?e.jsx("p",{className:"text-xs text-destructive",children:ke.name}):e.jsx("p",{className:"text-xs text-muted-foreground",children:"用于在任务配置中引用此模型"})]}),e.jsxs("div",{className:"grid gap-2","data-tour":"model-provider-select",children:[e.jsx(y,{htmlFor:"api_provider",className:ke.api_provider?"text-destructive":"",children:"API 提供商 *"}),e.jsxs(qe,{value:R?.api_provider||"",onValueChange:$=>{ne(ge=>ge?{...ge,api_provider:$}:null),U([]),tt(null),ke.api_provider&&Pe(ge=>({...ge,api_provider:void 0}))},children:[e.jsx(Be,{id:"api_provider",className:ke.api_provider?"border-destructive focus-visible:ring-destructive":"",children:e.jsx(Ge,{placeholder:"选择提供商"})}),e.jsx(He,{children:c.map($=>e.jsx(ie,{value:$,children:$},$))})]}),ke.api_provider&&e.jsx("p",{className:"text-xs text-destructive",children:ke.api_provider})]}),e.jsxs("div",{className:"grid gap-2","data-tour":"model-identifier-input",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(y,{htmlFor:"model_identifier",className:ke.model_identifier?"text-destructive":"",children:"模型标识符 *"}),Bt?.modelFetcher&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Je,{variant:"secondary",className:"text-xs",children:Bt.display_name}),e.jsx(b,{variant:"ghost",size:"sm",className:"h-6 px-2",onClick:()=>R?.api_provider&&_e(R.api_provider,!0),disabled:ee,children:ee?e.jsx(Ss,{className:"h-3 w-3 animate-spin"}):e.jsx(ws,{className:"h-3 w-3"})})]})]}),Bt?.modelFetcher?e.jsxs(Ua,{open:Xe,onOpenChange:Ut,children:[e.jsx(Ba,{asChild:!0,children:e.jsxs(b,{variant:"outline",role:"combobox","aria-expanded":Xe,className:"w-full justify-between font-normal",disabled:ee||!!Me,children:[ee?e.jsxs("span",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(Ss,{className:"h-4 w-4 animate-spin"}),"正在获取模型列表..."]}):Me?e.jsx("span",{className:"text-muted-foreground text-sm",children:"点击下方输入框手动填写"}):R?.model_identifier?e.jsx("span",{className:"truncate",children:R.model_identifier}):e.jsx("span",{className:"text-muted-foreground",children:"搜索或选择模型..."}),e.jsx(qu,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(_a,{className:"p-0",align:"start",style:{width:"var(--radix-popover-trigger-width)"},children:e.jsxs(ao,{children:[e.jsx(lo,{placeholder:"搜索模型..."}),e.jsx(st,{className:"h-[300px]",children:e.jsxs(no,{className:"max-h-none overflow-visible",children:[e.jsx(io,{children:Me?e.jsxs("div",{className:"py-4 px-2 text-center space-y-2",children:[e.jsx("p",{className:"text-sm text-destructive",children:Me}),!Me.includes("API Key")&&e.jsx(b,{variant:"link",size:"sm",onClick:()=>R?.api_provider&&_e(R.api_provider,!0),children:"重试"})]}):"未找到匹配的模型"}),e.jsx(fr,{heading:"可用模型",children:W.map($=>e.jsxs(pr,{value:$.id,onSelect:()=>{ne(ge=>ge?{...ge,model_identifier:$.id}:null),Ut(!1)},children:[e.jsx(Na,{className:`mr-2 h-4 w-4 ${R?.model_identifier===$.id?"opacity-100":"opacity-0"}`}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:$.id}),$.name!==$.id&&e.jsx("span",{className:"text-xs text-muted-foreground",children:$.name})]})]},$.id))}),e.jsx(fr,{heading:"手动输入",children:e.jsxs(pr,{value:"__manual_input__",onSelect:()=>{Ut(!1)},children:[e.jsx(nn,{className:"mr-2 h-4 w-4"}),"手动输入模型标识符..."]})})]})})]})})]}):e.jsx(ce,{id:"model_identifier",value:R?.model_identifier||"",onChange:$=>{ne(ge=>ge?{...ge,model_identifier:$.target.value}:null),ke.model_identifier&&Pe(ge=>({...ge,model_identifier:void 0}))},placeholder:"Qwen/Qwen3-30B-A3B-Instruct-2507",className:ke.model_identifier?"border-destructive focus-visible:ring-destructive":""}),ke.model_identifier&&e.jsx("p",{className:"text-xs text-destructive",children:ke.model_identifier}),Me&&Bt?.modelFetcher&&!ke.model_identifier&&e.jsxs(cl,{variant:"destructive",className:"mt-2 py-2",children:[e.jsx(Ra,{className:"h-4 w-4"}),e.jsx(ol,{className:"text-xs",children:Me})]}),Bt?.modelFetcher&&e.jsx(ce,{value:R?.model_identifier||"",onChange:$=>{ne(ge=>ge?{...ge,model_identifier:$.target.value}:null),ke.model_identifier&&Pe(ge=>({...ge,model_identifier:void 0}))},placeholder:"或手动输入模型标识符",className:`mt-2 ${ke.model_identifier?"border-destructive focus-visible:ring-destructive":""}`}),!ke.model_identifier&&e.jsx("p",{className:"text-xs text-muted-foreground",children:Me?'请手动输入模型标识符,或前往"模型提供商配置"检查 API Key':Bt?.modelFetcher?`已识别为 ${Bt.display_name},支持自动获取模型列表`:"API 提供商提供的模型 ID"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"price_in",children:"输入价格 (¥/M token)"}),e.jsx(ce,{id:"price_in",type:"number",step:"0.1",min:"0",value:R?.price_in??"",onChange:$=>{const ge=$.target.value===""?null:parseFloat($.target.value);ne(Le=>Le?{...Le,price_in:ge}:null)},placeholder:"默认: 0"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"price_out",children:"输出价格 (¥/M token)"}),e.jsx(ce,{id:"price_out",type:"number",step:"0.1",min:"0",value:R?.price_out??"",onChange:$=>{const ge=$.target.value===""?null:parseFloat($.target.value);ne(Le=>Le?{...Le,price_out:ge}:null)},placeholder:"默认: 0"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Qe,{id:"force_stream_mode",checked:R?.force_stream_mode||!1,onCheckedChange:$=>ne(ge=>ge?{...ge,force_stream_mode:$}:null)}),e.jsx(y,{htmlFor:"force_stream_mode",className:"cursor-pointer",children:"强制流式输出模式"})]})]}),e.jsxs(xs,{children:[e.jsx(b,{variant:"outline",onClick:()=>E(!1),"data-tour":"model-cancel-button",children:"取消"}),e.jsx(b,{onClick:Ha,"data-tour":"model-save-button",children:"保存"})]})]})}),e.jsx(bt,{open:we,onOpenChange:pe,children:e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认删除"}),e.jsxs(xt,{children:['确定要删除模型 "',Ne!==null?n[Ne]?.name:"",'" 吗? 此操作无法撤销。']})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:Sa,children:"删除"})]})]})}),e.jsx(bt,{open:_,onOpenChange:me,children:e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认批量删除"}),e.jsxs(xt,{children:["确定要删除选中的 ",T.size," 个模型吗? 此操作无法撤销。"]})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:us,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"批量删除"})]})]})}),z&&e.jsx(Yu,{onRestartComplete:Ht,onRestartFailed:pa})]})})}function ba({title:n,description:r,taskConfig:c,modelNames:d,onChange:h,hideTemperature:x=!1,hideMaxTokens:f=!1,dataTour:j}){const p=N=>{h("model_list",N)};return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-base sm:text-lg",children:n}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground mt-1",children:r})]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-2","data-tour":j,children:[e.jsx(y,{children:"模型列表"}),e.jsx(lw,{options:d.map(N=>({label:N,value:N})),selected:c.model_list||[],onChange:p,placeholder:"选择模型...",emptyText:"暂无可用模型"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[!x&&e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(y,{children:"温度"}),e.jsx(ce,{type:"number",step:"0.1",min:"0",max:"1",value:c.temperature??.3,onChange:N=>{const v=parseFloat(N.target.value);!isNaN(v)&&v>=0&&v<=1&&h("temperature",v)},className:"w-20 h-8 text-sm"})]}),e.jsx(Ma,{value:[c.temperature??.3],onValueChange:N=>h("temperature",N[0]),min:0,max:1,step:.1,className:"w-full"})]}),!f&&e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{children:"最大 Token"}),e.jsx(ce,{type:"number",step:"1",min:"1",value:c.max_tokens??1024,onChange:N=>h("max_tokens",parseInt(N.target.value))})]})]})]})]})}const ro="/api/webui/config";async function rw(){const r=await(await Te(`${ro}/adapter-config/path`)).json();return!r.success||!r.path?null:{path:r.path,lastModified:r.lastModified}}async function rp(n){const c=await(await Te(`${ro}/adapter-config/path`,{method:"POST",headers:Rt(),body:JSON.stringify({path:n})})).json();if(!c.success)throw new Error(c.message||"保存路径失败")}async function cp(n){const c=await(await Te(`${ro}/adapter-config?path=${encodeURIComponent(n)}`)).json();if(!c.success)throw new Error("读取配置文件失败");return c.content}async function op(n,r){const d=await(await Te(`${ro}/adapter-config`,{method:"POST",headers:Rt(),body:JSON.stringify({path:n,content:r})})).json();if(!d.success)throw new Error(d.message||"保存配置失败")}const Ps={inner:{version:"0.1.2"},nickname:{nickname:""},napcat_server:{host:"localhost",port:8095,token:"",heartbeat_interval:30},maibot_server:{host:"localhost",port:8e3},chat:{group_list_type:"whitelist",group_list:[],private_list_type:"whitelist",private_list:[],ban_user_id:[],ban_qq_bot:!1,enable_poke:!0},voice:{use_tts:!1},debug:{level:"INFO"}},Tu={oneclick:{name:"一键包",description:"使用一键包部署的适配器配置",path:"../MaiBot-Napcat-Adapter/config.toml",icon:rn},docker:{name:"Docker",description:"Docker Compose 部署的适配器配置",path:"/MaiMBot/adapters-config/config.toml",icon:by}};function cw(){const[n,r]=u.useState("upload"),[c,d]=u.useState(null),[h,x]=u.useState(""),[f,j]=u.useState(""),[p,N]=u.useState("oneclick"),[v,C]=u.useState(""),[S,w]=u.useState(!1),[L,F]=u.useState(!1),[B,O]=u.useState(!1),[K,H]=u.useState(!1),[z,V]=u.useState(null),Y=u.useRef(null),{toast:E}=Xt(),R=u.useRef(null),ne=G=>{if(!G.trim())return{valid:!1,error:"路径不能为空"};if(!G.toLowerCase().endsWith(".toml"))return{valid:!1,error:"文件必须是 .toml 格式"};const W=/^([a-zA-Z]:\\|\\\\[^\\]+\\[^\\]+\\).+\.toml$/i,U=/^(\/|~\/).+\.toml$/i,ee=/^(\.{1,2}[\\/]|[^:\\/]).+\.toml$/i,Se=W.test(G),Me=U.test(G),tt=ee.test(G);return!Se&&!Me&&!tt?{valid:!1,error:"路径格式错误"}:/[<>"|?*\x00-\x1F]/.test(G)?{valid:!1,error:"路径包含非法字符"}:{valid:!0,error:""}},fe=G=>{if(j(G),G.trim()){const W=ne(G);C(W.error)}else C("")},Ce=u.useCallback(async G=>{const W=Tu[G];F(!0);try{const U=await cp(W.path),ee=oe(U);d(ee),N(G),j(W.path),await rp(W.path),E({title:"加载成功",description:`已从${W.name}预设加载配置`})}catch(U){console.error("加载预设配置失败:",U),E({title:"加载失败",description:U instanceof Error?U.message:"无法读取预设配置文件",variant:"destructive"})}finally{F(!1)}},[E]),we=u.useCallback(async G=>{const W=ne(G);if(!W.valid){C(W.error),E({title:"路径无效",description:W.error,variant:"destructive"});return}C(""),F(!0);try{const U=await cp(G),ee=oe(U);d(ee),j(G),await rp(G),E({title:"加载成功",description:"已从配置文件加载"})}catch(U){console.error("加载配置失败:",U),E({title:"加载失败",description:U instanceof Error?U.message:"无法读取配置文件",variant:"destructive"})}finally{F(!1)}},[E]);u.useEffect(()=>{(async()=>{try{const W=await rw();if(W&&W.path){j(W.path);const U=Object.entries(Tu).find(([,ee])=>ee.path===W.path);U?(r("preset"),N(U[0]),await Ce(U[0])):(r("path"),await we(W.path))}}catch(W){console.error("加载保存的路径失败:",W)}})()},[we,Ce]);const pe=u.useCallback(G=>{n!=="path"&&n!=="preset"||!f||(R.current&&clearTimeout(R.current),R.current=setTimeout(async()=>{w(!0);try{const W=ae(G);await op(f,W),E({title:"自动保存成功",description:"配置已保存到文件"})}catch(W){console.error("自动保存失败:",W),E({title:"自动保存失败",description:W instanceof Error?W.message:"保存配置失败",variant:"destructive"})}finally{w(!1)}},1e3))},[n,f,E]),Ne=async()=>{if(!c||!f)return;const G=ne(f);if(!G.valid){E({title:"保存失败",description:G.error,variant:"destructive"});return}w(!0);try{const W=ae(c);await op(f,W),E({title:"保存成功",description:"配置已保存到文件"})}catch(W){console.error("保存失败:",W),E({title:"保存失败",description:W instanceof Error?W.message:"保存配置失败",variant:"destructive"})}finally{w(!1)}},be=async()=>{f&&await we(f)},A=G=>{if(G!==n){if(c){V(G),O(!0);return}X(G)}},X=G=>{d(null),x(""),C(""),r(G),G==="preset"&&Ce("oneclick"),E({title:"已切换模式",description:{upload:"现在可以上传配置文件",path:"现在可以指定配置文件路径",preset:"现在可以使用预设配置"}[G]})},T=()=>{z&&(X(z),V(null)),O(!1)},te=()=>{if(c){H(!0);return}_()},_=()=>{j(""),d(null),C(""),E({title:"已清空",description:"路径和配置已清空"})},me=()=>{_(),H(!1)},oe=G=>{const W=JSON.parse(JSON.stringify(Ps)),U=G.split(` `);let ee="";for(const Se of U){const Me=Se.trim();if(!Me||Me.startsWith("#"))continue;const tt=Me.match(/^\[(\w+)\]/);if(tt){ee=tt[1];continue}const Xe=Me.match(/^(\w+)\s*=\s*(.+)$/);if(Xe&&ee){const[,Ut,Bt]=Xe;let re=Bt.trim();const ke=re.match(/^("[^"]*")/);if(ke)re=ke[1];else{const Fe=re.indexOf("#");Fe!==-1&&(re=re.substring(0,Fe).trim())}let Pe;if(re==="true")Pe=!0;else if(re==="false")Pe=!1;else if(re.startsWith("[")&&re.endsWith("]")){const Fe=re.slice(1,-1).trim();if(Fe){const ts=Fe.split(",").map(js=>{const Ke=js.trim();return isNaN(Number(Ke))?Ke.replace(/"/g,""):Number(Ke)}),As=typeof ts[0];Pe=ts.every(js=>typeof js===As)?ts:ts.filter(js=>typeof js=="number")}else Pe=[]}else re.startsWith('"')&&re.endsWith('"')?Pe=re.slice(1,-1):isNaN(Number(re))?Pe=re.replace(/"/g,""):Pe=Number(re);if(ee in W){const Fe=W[ee];Fe[Ut]=Pe}}}return W},ae=G=>{const W=[],U=(ee,Se)=>ee===""||ee===null||ee===void 0?Se:ee;return W.push("[inner]"),W.push(`version = "${U(G.inner.version,Ps.inner.version)}" # 版本号`),W.push("# 请勿修改版本号,除非你知道自己在做什么"),W.push(""),W.push("[nickname] # 现在没用"),W.push(`nickname = "${U(G.nickname.nickname,Ps.nickname.nickname)}"`),W.push(""),W.push("[napcat_server] # Napcat连接的ws服务设置"),W.push(`host = "${U(G.napcat_server.host,Ps.napcat_server.host)}" # Napcat设定的主机地址`),W.push(`port = ${U(G.napcat_server.port||0,Ps.napcat_server.port)} # Napcat设定的端口`),W.push(`token = "${U(G.napcat_server.token,Ps.napcat_server.token)}" # Napcat设定的访问令牌,若无则留空`),W.push(`heartbeat_interval = ${U(G.napcat_server.heartbeat_interval||0,Ps.napcat_server.heartbeat_interval)} # 与Napcat设置的心跳相同(按秒计)`),W.push(""),W.push("[maibot_server] # 连接麦麦的ws服务设置"),W.push(`host = "${U(G.maibot_server.host,Ps.maibot_server.host)}" # 麦麦在.env文件中设置的主机地址,即HOST字段`),W.push(`port = ${U(G.maibot_server.port||0,Ps.maibot_server.port)} # 麦麦在.env文件中设置的端口,即PORT字段`),W.push(""),W.push("[chat] # 黑白名单功能"),W.push(`group_list_type = "${U(G.chat.group_list_type,Ps.chat.group_list_type)}" # 群组名单类型,可选为:whitelist, blacklist`),W.push(`group_list = [${G.chat.group_list.join(", ")}] # 群组名单`),W.push("# 当group_list_type为whitelist时,只有群组名单中的群组可以聊天"),W.push("# 当group_list_type为blacklist时,群组名单中的任何群组无法聊天"),W.push(`private_list_type = "${U(G.chat.private_list_type,Ps.chat.private_list_type)}" # 私聊名单类型,可选为:whitelist, blacklist`),W.push(`private_list = [${G.chat.private_list.join(", ")}] # 私聊名单`),W.push("# 当private_list_type为whitelist时,只有私聊名单中的用户可以聊天"),W.push("# 当private_list_type为blacklist时,私聊名单中的任何用户无法聊天"),W.push(`ban_user_id = [${G.chat.ban_user_id.join(", ")}] # 全局禁止名单(全局禁止名单中的用户无法进行任何聊天)`),W.push(`ban_qq_bot = ${G.chat.ban_qq_bot} # 是否屏蔽QQ官方机器人`),W.push(`enable_poke = ${G.chat.enable_poke} # 是否启用戳一戳功能`),W.push(""),W.push("[voice] # 发送语音设置"),W.push(`use_tts = ${G.voice.use_tts} # 是否使用tts语音(请确保你配置了tts并有对应的adapter)`),W.push(""),W.push("[debug]"),W.push(`level = "${U(G.debug.level,Ps.debug.level)}" # 日志等级(DEBUG, INFO, WARNING, ERROR, CRITICAL)`),W.join(` `)},xe=G=>{const W=G.target.files?.[0];if(!W)return;const U=new FileReader;U.onload=ee=>{try{const Se=ee.target?.result,Me=oe(Se);d(Me),x(W.name),E({title:"上传成功",description:`已加载配置文件:${W.name}`})}catch(Se){console.error("解析配置文件失败:",Se),E({title:"解析失败",description:"配置文件格式错误,请检查文件内容",variant:"destructive"})}},U.readAsText(W)},ve=()=>{if(!c)return;const G=ae(c),W=new Blob([G],{type:"text/plain;charset=utf-8"}),U=URL.createObjectURL(W),ee=document.createElement("a");ee.href=U,ee.download=h||"config.toml",document.body.appendChild(ee),ee.click(),document.body.removeChild(ee),URL.revokeObjectURL(U),E({title:"下载成功",description:"配置文件已下载,请手动覆盖并重启适配器"})},de=()=>{d(JSON.parse(JSON.stringify(Ps))),x("config.toml"),E({title:"已加载默认配置",description:"可以开始编辑配置"})};return e.jsx(st,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsx("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"麦麦适配器配置"}),e.jsx("p",{className:"text-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:"管理麦麦的 QQ 适配器的配置文件"})]})}),e.jsxs("div",{className:"flex items-start gap-2 p-3 rounded-lg border border-amber-500/50 bg-amber-500/10 text-amber-700 dark:text-amber-400",children:[e.jsx(Oa,{className:"h-4 w-4 mt-0.5 flex-shrink-0"}),e.jsx("p",{className:"text-sm",children:"适配器配置保存之后使用 WebUI 的重启功能适配器并不会重启,需要手动重启适配器。"})]}),e.jsxs(Ye,{children:[e.jsxs(Nt,{children:[e.jsx(wt,{children:"工作模式"}),e.jsx(ns,{children:"选择配置文件的管理方式"})]}),e.jsxs(kt,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3 md:gap-4",children:[e.jsx("div",{className:`border-2 rounded-lg p-3 md:p-4 cursor-pointer transition-all ${n==="preset"?"border-primary bg-primary/5":"border-muted hover:border-primary/50 active:border-primary/70"}`,onClick:()=>A("preset"),children:e.jsxs("div",{className:"flex items-start gap-2 md:gap-3",children:[e.jsx(rn,{className:"h-4 w-4 md:h-5 md:w-5 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"font-semibold text-sm md:text-base",children:"预设模式"}),e.jsx("p",{className:"text-xs md:text-sm text-muted-foreground mt-1 line-clamp-2",children:"使用预设的部署配置"})]})]})}),e.jsx("div",{className:`border-2 rounded-lg p-3 md:p-4 cursor-pointer transition-all ${n==="upload"?"border-primary bg-primary/5":"border-muted hover:border-primary/50 active:border-primary/70"}`,onClick:()=>A("upload"),children:e.jsxs("div",{className:"flex items-start gap-2 md:gap-3",children:[e.jsx(dr,{className:"h-4 w-4 md:h-5 md:w-5 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"font-semibold text-sm md:text-base",children:"上传文件模式"}),e.jsx("p",{className:"text-xs md:text-sm text-muted-foreground mt-1 line-clamp-2",children:"上传配置文件,编辑后下载并手动覆盖"})]})]})}),e.jsx("div",{className:`border-2 rounded-lg p-3 md:p-4 cursor-pointer transition-all ${n==="path"?"border-primary bg-primary/5":"border-muted hover:border-primary/50 active:border-primary/70"}`,onClick:()=>A("path"),children:e.jsxs("div",{className:"flex items-start gap-2 md:gap-3",children:[e.jsx(yy,{className:"h-4 w-4 md:h-5 md:w-5 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"font-semibold text-sm md:text-base",children:"指定路径模式"}),e.jsx("p",{className:"text-xs md:text-sm text-muted-foreground mt-1 line-clamp-2",children:"指定配置文件路径,自动加载和保存"})]})]})})]}),n==="preset"&&e.jsxs("div",{className:"space-y-3 pt-2 border-t",children:[e.jsx(y,{className:"text-sm md:text-base",children:"选择部署方式"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:Object.entries(Tu).map(([G,W])=>{const U=W.icon,ee=p===G;return e.jsx("div",{className:`border-2 rounded-lg p-3 cursor-pointer transition-all ${ee?"border-primary bg-primary/5":"border-muted hover:border-primary/50"}`,onClick:()=>{N(G),Ce(G)},children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(U,{className:"h-5 w-5 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h4",{className:"font-semibold text-sm",children:W.name}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:W.description}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1 font-mono break-all",children:W.path})]})]})},G)})})]}),n==="path"&&e.jsxs("div",{className:"space-y-3 pt-2 border-t",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"config-path",className:"text-sm md:text-base",children:"配置文件路径"}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx(ce,{id:"config-path",value:f,onChange:G=>fe(G.target.value),placeholder:"例: C:\\Adapter\\config.toml",className:`text-sm ${v?"border-destructive":""}`}),v&&e.jsx("p",{className:"text-xs text-destructive",children:v})]}),e.jsx(b,{onClick:()=>we(f),disabled:L||!f||!!v,className:"w-full sm:w-auto",children:L?e.jsxs(e.Fragment,{children:[e.jsx(ws,{className:"h-4 w-4 animate-spin mr-2"}),e.jsx("span",{className:"sm:hidden",children:"加载中..."})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"sm:hidden",children:"加载配置"}),e.jsx("span",{className:"hidden sm:inline",children:"加载"})]})})]})]}),e.jsxs("details",{className:"rounded-lg bg-muted/50 p-3 group",children:[e.jsxs("summary",{className:"text-xs font-medium cursor-pointer select-none list-none flex items-center justify-between",children:[e.jsx("span",{children:"路径格式说明"}),e.jsx("svg",{className:"h-4 w-4 transition-transform group-open:rotate-180",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),e.jsxs("div",{className:"mt-2 space-y-2 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"font-mono bg-background px-1.5 py-0.5 rounded text-[10px] md:text-xs whitespace-nowrap",children:"Windows"})}),e.jsxs("div",{className:"pl-2 space-y-0.5 text-[10px] md:text-xs break-all",children:[e.jsx("div",{children:"C:\\Adapter\\config.toml"}),e.jsx("div",{className:"hidden sm:block",children:"D:\\MaiBot\\adapter\\config.toml"}),e.jsx("div",{className:"hidden sm:block",children:"\\\\server\\share\\config.toml"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"font-mono bg-background px-1.5 py-0.5 rounded text-[10px] md:text-xs whitespace-nowrap",children:"Linux"})}),e.jsxs("div",{className:"pl-2 space-y-0.5 text-[10px] md:text-xs break-all",children:[e.jsx("div",{children:"/opt/adapter/config.toml"}),e.jsx("div",{className:"hidden sm:block",children:"/home/user/adapter/config.toml"}),e.jsx("div",{className:"hidden sm:block",children:"~/adapter/config.toml"})]})]}),e.jsx("p",{className:"pt-1 border-t text-[10px] md:text-xs",children:"💡 配置会自动保存到指定文件,修改后 1 秒自动保存"})]})]})]})]})]}),e.jsxs(cl,{children:[e.jsx(Ra,{className:"h-4 w-4"}),e.jsx(ol,{children:n==="preset"?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"预设模式:"}),"选择预设的部署方式,配置会自动加载,修改后 1 秒自动保存",S&&" (正在保存...)"]}):n==="upload"?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"上传文件模式:"}),"上传配置文件 → 在线编辑 → 下载文件 → 手动覆盖并重启适配器"]}):e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"指定路径模式:"}),"指定配置文件路径后,配置会自动加载,修改后 1 秒自动保存",S&&" (正在保存...)"]})})]}),n==="upload"&&!c&&e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 w-full",children:[e.jsx("input",{ref:Y,type:"file",accept:".toml",className:"hidden",onChange:xe}),e.jsxs(b,{onClick:()=>Y.current?.click(),size:"sm",variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(dr,{className:"mr-2 h-4 w-4"}),"上传配置"]}),e.jsxs(b,{onClick:de,size:"sm",className:"w-full sm:w-auto",children:[e.jsx(Da,{className:"mr-2 h-4 w-4"}),"使用默认配置"]})]}),n==="upload"&&c&&e.jsx("div",{className:"flex gap-2",children:e.jsxs(b,{onClick:ve,size:"sm",className:"w-full sm:w-auto",children:[e.jsx(rl,{className:"mr-2 h-4 w-4"}),"下载配置"]})}),(n==="preset"||n==="path")&&c&&e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsxs(b,{onClick:Ne,size:"sm",disabled:S||!!v,className:"w-full sm:w-auto",children:[e.jsx(jr,{className:"mr-2 h-4 w-4"}),S?"保存中...":"立即保存"]}),e.jsxs(b,{onClick:be,size:"sm",variant:"outline",disabled:L,className:"w-full sm:w-auto",children:[e.jsx(ws,{className:`mr-2 h-4 w-4 ${L?"animate-spin":""}`}),"刷新"]}),n==="path"&&e.jsxs(b,{onClick:te,size:"sm",variant:"destructive",className:"w-full sm:w-auto",children:[e.jsx(at,{className:"mr-2 h-4 w-4"}),"清空路径"]})]}),c?e.jsxs(La,{defaultValue:"napcat",className:"w-full",children:[e.jsx("div",{className:"overflow-x-auto -mx-4 px-4 sm:mx-0 sm:px-0",children:e.jsxs(wa,{className:"inline-flex w-auto min-w-full sm:grid sm:w-full sm:grid-cols-5",children:[e.jsxs(it,{value:"napcat",className:"flex-shrink-0 text-xs sm:text-sm whitespace-nowrap",children:[e.jsx("span",{className:"hidden sm:inline",children:"Napcat 连接"}),e.jsx("span",{className:"sm:hidden",children:"Napcat"})]}),e.jsxs(it,{value:"maibot",className:"flex-shrink-0 text-xs sm:text-sm whitespace-nowrap",children:[e.jsx("span",{className:"hidden sm:inline",children:"麦麦连接"}),e.jsx("span",{className:"sm:hidden",children:"麦麦"})]}),e.jsxs(it,{value:"chat",className:"flex-shrink-0 text-xs sm:text-sm whitespace-nowrap",children:[e.jsx("span",{className:"hidden sm:inline",children:"聊天控制"}),e.jsx("span",{className:"sm:hidden",children:"聊天"})]}),e.jsxs(it,{value:"voice",className:"flex-shrink-0 text-xs sm:text-sm whitespace-nowrap",children:[e.jsx("span",{className:"hidden sm:inline",children:"语音设置"}),e.jsx("span",{className:"sm:hidden",children:"语音"})]}),e.jsx(it,{value:"debug",className:"flex-shrink-0 text-xs sm:text-sm whitespace-nowrap",children:"调试"})]})}),e.jsx(zt,{value:"napcat",className:"space-y-4",children:e.jsx(ow,{config:c,onChange:G=>{d(G),pe(G)}})}),e.jsx(zt,{value:"maibot",className:"space-y-4",children:e.jsx(dw,{config:c,onChange:G=>{d(G),pe(G)}})}),e.jsx(zt,{value:"chat",className:"space-y-4",children:e.jsx(uw,{config:c,onChange:G=>{d(G),pe(G)}})}),e.jsx(zt,{value:"voice",className:"space-y-4",children:e.jsx(mw,{config:c,onChange:G=>{d(G),pe(G)}})}),e.jsx(zt,{value:"debug",className:"space-y-4",children:e.jsx(hw,{config:c,onChange:G=>{d(G),pe(G)}})})]}):e.jsx("div",{className:"rounded-lg border bg-card p-6 md:p-12",children:e.jsxs("div",{className:"text-center space-y-3 md:space-y-4",children:[e.jsx(Da,{className:"h-12 w-12 md:h-16 md:w-16 mx-auto text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold",children:"尚未加载配置"}),e.jsx("p",{className:"text-xs md:text-sm text-muted-foreground mt-2 px-4",children:n==="preset"?"请选择预设的部署方式":n==="upload"?"请上传现有配置文件,或使用默认配置开始编辑":"请指定配置文件路径并点击加载按钮"})]})]})}),e.jsx(bt,{open:B,onOpenChange:O,children:e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认切换模式"}),e.jsxs(xt,{children:["切换模式将清空当前配置,确定要继续吗?",e.jsx("br",{}),e.jsx("span",{className:"text-destructive font-medium",children:"请确保已保存重要配置"})]})]}),e.jsxs(mt,{children:[e.jsx(pt,{onClick:()=>{O(!1),V(null)},children:"取消"}),e.jsx(ft,{onClick:T,children:"确认切换"})]})]})}),e.jsx(bt,{open:K,onOpenChange:H,children:e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认清空路径"}),e.jsxs(xt,{children:["清空路径将清除当前配置,确定要继续吗?",e.jsx("br",{}),e.jsx("span",{className:"text-muted-foreground text-sm",children:"此操作不会删除配置文件,只是清除界面中的配置"})]})]}),e.jsxs(mt,{children:[e.jsx(pt,{onClick:()=>H(!1),children:"取消"}),e.jsx(ft,{onClick:me,className:"bg-destructive hover:bg-destructive/90",children:"确认清空"})]})]})})]})})}function ow({config:n,onChange:r}){return e.jsx("div",{className:"rounded-lg border bg-card p-4 md:p-6 space-y-4 md:space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold mb-3 md:mb-4",children:"Napcat WebSocket 服务设置"}),e.jsxs("div",{className:"grid gap-3 md:gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"napcat-host",className:"text-sm md:text-base",children:"主机地址"}),e.jsx(ce,{id:"napcat-host",value:n.napcat_server.host,onChange:c=>r({...n,napcat_server:{...n.napcat_server,host:c.target.value}}),placeholder:"localhost",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Napcat 设定的主机地址"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"napcat-port",className:"text-sm md:text-base",children:"端口"}),e.jsx(ce,{id:"napcat-port",type:"number",value:n.napcat_server.port||"",onChange:c=>r({...n,napcat_server:{...n.napcat_server,port:c.target.value?parseInt(c.target.value):0}}),placeholder:"8095",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Napcat 设定的端口(留空使用默认值 8095)"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"napcat-token",className:"text-sm md:text-base",children:"访问令牌(Token)"}),e.jsx(ce,{id:"napcat-token",type:"password",value:n.napcat_server.token,onChange:c=>r({...n,napcat_server:{...n.napcat_server,token:c.target.value}}),placeholder:"留空表示无需令牌",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Napcat 设定的访问令牌,若无则留空"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"napcat-heartbeat",className:"text-sm md:text-base",children:"心跳间隔(秒)"}),e.jsx(ce,{id:"napcat-heartbeat",type:"number",value:n.napcat_server.heartbeat_interval||"",onChange:c=>r({...n,napcat_server:{...n.napcat_server,heartbeat_interval:c.target.value?parseInt(c.target.value):0}}),placeholder:"30",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"与 Napcat 设置的心跳间隔保持一致(留空使用默认值 30)"})]})]})]})})}function dw({config:n,onChange:r}){return e.jsx("div",{className:"rounded-lg border bg-card p-4 md:p-6 space-y-4 md:space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold mb-3 md:mb-4",children:"麦麦 WebSocket 服务设置"}),e.jsxs("div",{className:"grid gap-3 md:gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"maibot-host",className:"text-sm md:text-base",children:"主机地址"}),e.jsx(ce,{id:"maibot-host",value:n.maibot_server.host,onChange:c=>r({...n,maibot_server:{...n.maibot_server,host:c.target.value}}),placeholder:"localhost",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"麦麦在 .env 文件中设置的 HOST 字段"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{htmlFor:"maibot-port",className:"text-sm md:text-base",children:"端口"}),e.jsx(ce,{id:"maibot-port",type:"number",value:n.maibot_server.port||"",onChange:c=>r({...n,maibot_server:{...n.maibot_server,port:c.target.value?parseInt(c.target.value):0}}),placeholder:"8000",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"麦麦在 .env 文件中设置的 PORT 字段(留空使用默认值 8000)"})]})]})]})})}function uw({config:n,onChange:r}){const c=x=>{const f={...n};x==="group"?f.chat.group_list=[...f.chat.group_list,0]:x==="private"?f.chat.private_list=[...f.chat.private_list,0]:f.chat.ban_user_id=[...f.chat.ban_user_id,0],r(f)},d=(x,f)=>{const j={...n};x==="group"?j.chat.group_list=j.chat.group_list.filter((p,N)=>N!==f):x==="private"?j.chat.private_list=j.chat.private_list.filter((p,N)=>N!==f):j.chat.ban_user_id=j.chat.ban_user_id.filter((p,N)=>N!==f),r(j)},h=(x,f,j)=>{const p={...n};x==="group"?p.chat.group_list[f]=j:x==="private"?p.chat.private_list[f]=j:p.chat.ban_user_id[f]=j,r(p)};return e.jsx("div",{className:"rounded-lg border bg-card p-4 md:p-6 space-y-4 md:space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold mb-3 md:mb-4",children:"聊天黑白名单功能"}),e.jsxs("div",{className:"grid gap-4 md:gap-6",children:[e.jsxs("div",{className:"space-y-3 md:space-y-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{className:"text-sm md:text-base",children:"群组名单类型"}),e.jsxs(qe,{value:n.chat.group_list_type,onValueChange:x=>r({...n,chat:{...n.chat,group_list_type:x}}),children:[e.jsx(Be,{children:e.jsx(Ge,{})}),e.jsxs(He,{children:[e.jsx(ie,{value:"whitelist",children:"白名单(仅名单内可聊天)"}),e.jsx(ie,{value:"blacklist",children:"黑名单(名单内禁止聊天)"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2 sm:gap-0",children:[e.jsx(y,{className:"text-sm md:text-base",children:"群组列表"}),e.jsxs(b,{onClick:()=>c("group"),size:"sm",variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(Da,{className:"mr-1 h-4 w-4"}),"添加群号"]})]}),n.chat.group_list.map((x,f)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ce,{type:"number",value:x,onChange:j=>h("group",f,parseInt(j.target.value)||0),placeholder:"输入群号",className:"text-sm md:text-base"}),e.jsxs(bt,{children:[e.jsx(es,{asChild:!0,children:e.jsx(b,{size:"icon",variant:"outline",children:e.jsx(at,{className:"h-4 w-4"})})}),e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认删除"}),e.jsxs(xt,{children:["确定要删除群号 ",x," 吗?此操作无法撤销。"]})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:()=>d("group",f),children:"删除"})]})]})]})]},f)),n.chat.group_list.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"暂无群组"})]})]}),e.jsxs("div",{className:"space-y-3 md:space-y-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{className:"text-sm md:text-base",children:"私聊名单类型"}),e.jsxs(qe,{value:n.chat.private_list_type,onValueChange:x=>r({...n,chat:{...n.chat,private_list_type:x}}),children:[e.jsx(Be,{children:e.jsx(Ge,{})}),e.jsxs(He,{children:[e.jsx(ie,{value:"whitelist",children:"白名单(仅名单内可聊天)"}),e.jsx(ie,{value:"blacklist",children:"黑名单(名单内禁止聊天)"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2 sm:gap-0",children:[e.jsx(y,{className:"text-sm md:text-base",children:"私聊列表"}),e.jsxs(b,{onClick:()=>c("private"),size:"sm",variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(Da,{className:"mr-1 h-4 w-4"}),"添加用户"]})]}),n.chat.private_list.map((x,f)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ce,{type:"number",value:x,onChange:j=>h("private",f,parseInt(j.target.value)||0),placeholder:"输入QQ号",className:"text-sm md:text-base"}),e.jsxs(bt,{children:[e.jsx(es,{asChild:!0,children:e.jsx(b,{size:"icon",variant:"outline",children:e.jsx(at,{className:"h-4 w-4"})})}),e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认删除"}),e.jsxs(xt,{children:["确定要删除用户 ",x," 吗?此操作无法撤销。"]})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:()=>d("private",f),children:"删除"})]})]})]})]},f)),n.chat.private_list.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"暂无用户"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2 sm:gap-0",children:[e.jsxs("div",{children:[e.jsx(y,{className:"text-sm md:text-base",children:"全局禁止名单"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"名单中的用户无法进行任何聊天"})]}),e.jsxs(b,{onClick:()=>c("ban"),size:"sm",variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(Da,{className:"mr-1 h-4 w-4"}),"添加用户"]})]}),n.chat.ban_user_id.map((x,f)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ce,{type:"number",value:x,onChange:j=>h("ban",f,parseInt(j.target.value)||0),placeholder:"输入QQ号",className:"text-sm md:text-base"}),e.jsxs(bt,{children:[e.jsx(es,{asChild:!0,children:e.jsx(b,{size:"icon",variant:"outline",children:e.jsx(at,{className:"h-4 w-4"})})}),e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认删除"}),e.jsxs(xt,{children:["确定要从全局禁止名单中删除用户 ",x," 吗?此操作无法撤销。"]})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:()=>d("ban",f),children:"删除"})]})]})]})]},f)),n.chat.ban_user_id.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"暂无禁止用户"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(y,{className:"text-sm md:text-base",children:"屏蔽QQ官方机器人"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"是否屏蔽来自QQ官方机器人的消息"})]}),e.jsx(Qe,{checked:n.chat.ban_qq_bot,onCheckedChange:x=>r({...n,chat:{...n.chat,ban_qq_bot:x}})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(y,{className:"text-sm md:text-base",children:"启用戳一戳功能"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"是否响应戳一戳消息"})]}),e.jsx(Qe,{checked:n.chat.enable_poke,onCheckedChange:x=>r({...n,chat:{...n.chat,enable_poke:x}})})]})]})]})})}function mw({config:n,onChange:r}){return e.jsx("div",{className:"rounded-lg border bg-card p-4 md:p-6 space-y-4 md:space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold mb-3 md:mb-4",children:"发送语音设置"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(y,{className:"text-sm md:text-base",children:"使用 TTS 语音"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"请确保已配置 TTS 并有对应的适配器"})]}),e.jsx(Qe,{checked:n.voice.use_tts,onCheckedChange:c=>r({...n,voice:{use_tts:c}})})]})]})})}function hw({config:n,onChange:r}){return e.jsx("div",{className:"rounded-lg border bg-card p-4 md:p-6 space-y-4 md:space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold mb-3 md:mb-4",children:"调试设置"}),e.jsx("div",{className:"grid gap-3 md:gap-4",children:e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{className:"text-sm md:text-base",children:"日志等级"}),e.jsxs(qe,{value:n.debug.level,onValueChange:c=>r({...n,debug:{level:c}}),children:[e.jsx(Be,{children:e.jsx(Ge,{})}),e.jsxs(He,{children:[e.jsx(ie,{value:"DEBUG",children:"DEBUG(调试)"}),e.jsx(ie,{value:"INFO",children:"INFO(信息)"}),e.jsx(ie,{value:"WARNING",children:"WARNING(警告)"}),e.jsx(ie,{value:"ERROR",children:"ERROR(错误)"}),e.jsx(ie,{value:"CRITICAL",children:"CRITICAL(严重)"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"设置适配器的日志输出等级"})]})})]})})}const xw=["defaultChecked","defaultValue","suppressContentEditableWarning","suppressHydrationWarning","dangerouslySetInnerHTML","accessKey","className","contentEditable","contextMenu","dir","draggable","hidden","id","lang","placeholder","slot","spellCheck","style","tabIndex","title","translate","radioGroup","role","about","datatype","inlist","prefix","property","resource","typeof","vocab","autoCapitalize","autoCorrect","autoSave","color","itemProp","itemScope","itemType","itemID","itemRef","results","security","unselectable","inputMode","is","onCopy","onCopyCapture","onCut","onCutCapture","onPaste","onPasteCapture","onCompositionEnd","onCompositionEndCapture","onCompositionStart","onCompositionStartCapture","onCompositionUpdate","onCompositionUpdateCapture","onFocus","onFocusCapture","onBlur","onBlurCapture","onChange","onChangeCapture","onBeforeInput","onBeforeInputCapture","onInput","onInputCapture","onReset","onResetCapture","onSubmit","onSubmitCapture","onInvalid","onInvalidCapture","onLoad","onLoadCapture","onError","onErrorCapture","onKeyDown","onKeyDownCapture","onKeyPress","onKeyPressCapture","onKeyUp","onKeyUpCapture","onAbort","onAbortCapture","onCanPlay","onCanPlayCapture","onCanPlayThrough","onCanPlayThroughCapture","onDurationChange","onDurationChangeCapture","onEmptied","onEmptiedCapture","onEncrypted","onEncryptedCapture","onEnded","onEndedCapture","onLoadedData","onLoadedDataCapture","onLoadedMetadata","onLoadedMetadataCapture","onLoadStart","onLoadStartCapture","onPause","onPauseCapture","onPlay","onPlayCapture","onPlaying","onPlayingCapture","onProgress","onProgressCapture","onRateChange","onRateChangeCapture","onSeeked","onSeekedCapture","onSeeking","onSeekingCapture","onStalled","onStalledCapture","onSuspend","onSuspendCapture","onTimeUpdate","onTimeUpdateCapture","onVolumeChange","onVolumeChangeCapture","onWaiting","onWaitingCapture","onAuxClick","onAuxClickCapture","onClick","onClickCapture","onContextMenu","onContextMenuCapture","onDoubleClick","onDoubleClickCapture","onDrag","onDragCapture","onDragEnd","onDragEndCapture","onDragEnter","onDragEnterCapture","onDragExit","onDragExitCapture","onDragLeave","onDragLeaveCapture","onDragOver","onDragOverCapture","onDragStart","onDragStartCapture","onDrop","onDropCapture","onMouseDown","onMouseDownCapture","onMouseEnter","onMouseLeave","onMouseMove","onMouseMoveCapture","onMouseOut","onMouseOutCapture","onMouseOver","onMouseOverCapture","onMouseUp","onMouseUpCapture","onSelect","onSelectCapture","onTouchCancel","onTouchCancelCapture","onTouchEnd","onTouchEndCapture","onTouchMove","onTouchMoveCapture","onTouchStart","onTouchStartCapture","onPointerDown","onPointerDownCapture","onPointerMove","onPointerMoveCapture","onPointerUp","onPointerUpCapture","onPointerCancel","onPointerCancelCapture","onPointerEnter","onPointerEnterCapture","onPointerLeave","onPointerLeaveCapture","onPointerOver","onPointerOverCapture","onPointerOut","onPointerOutCapture","onGotPointerCapture","onGotPointerCaptureCapture","onLostPointerCapture","onLostPointerCaptureCapture","onScroll","onScrollCapture","onWheel","onWheelCapture","onAnimationStart","onAnimationStartCapture","onAnimationEnd","onAnimationEndCapture","onAnimationIteration","onAnimationIterationCapture","onTransitionEnd","onTransitionEndCapture"],fw=/^(aria-|data-)/,zg=n=>Object.fromEntries(Object.entries(n).filter(([r])=>fw.test(r)||xw.includes(r)));function pw(n,r){const c=zg(n);return Object.keys(n).some(d=>!Object.hasOwn(c,d)&&n[d]!==r[d])}class gw extends u.Component{container;plugin;componentDidMount(){this.installPlugin()}componentDidUpdate(r){if(r.uppy!==this.props.uppy)this.uninstallPlugin(r),this.installPlugin();else if(pw(this.props,r)){const{uppy:c,...d}={...this.props,target:this.container};this.plugin.setOptions(d)}}componentWillUnmount(){this.uninstallPlugin()}installPlugin(){const{uppy:r,...c}={id:"Dashboard",...this.props,inline:!0,target:this.container};r.use(sN,c),this.plugin=r.getPlugin(c.id)}uninstallPlugin(r=this.props){const{uppy:c}=r;c.removePlugin(this.plugin)}render(){return u.createElement("div",{className:"uppy-Container",ref:r=>{this.container=r},...zg(this.props)})}}function jw({src:n,alt:r="表情包",className:c,maxRetries:d=5,retryInterval:h=1500}){const[x,f]=u.useState("loading"),[j,p]=u.useState(0),[N,v]=u.useState(null),C=u.useCallback(async()=>{try{const S=await fetch(n,{credentials:"include"});if(S.status===202){f("generating"),j{p(F=>F+1)},h):f("error");return}if(!S.ok){f("error");return}const w=await S.blob(),L=URL.createObjectURL(w);v(L),f("loaded")}catch(S){console.error("加载缩略图失败:",S),f("error")}},[n,j,d,h]);return u.useEffect(()=>{f("loading"),p(0),v(null)},[n]),u.useEffect(()=>{C()},[C]),u.useEffect(()=>()=>{N&&URL.revokeObjectURL(N)},[N]),x==="loading"||x==="generating"?e.jsx(hg,{className:Q("w-full h-full",c)}):x==="error"||!N?e.jsx("div",{className:Q("w-full h-full flex items-center justify-center bg-muted",c),children:e.jsx(ig,{className:"h-8 w-8 text-muted-foreground"})}):e.jsx("img",{src:N,alt:r,className:Q("w-full h-full object-contain",c)})}function vw({content:n,className:r=""}){return e.jsx("div",{className:`prose prose-sm dark:prose-invert max-w-none ${r}`,children:e.jsx(lN,{remarkPlugins:[iN,rN],rehypePlugins:[nN],components:{code({inline:c,className:d,children:h,...x}){return c?e.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-sm font-mono",...x,children:h}):e.jsx("code",{className:`${d} block bg-muted p-4 rounded-lg overflow-x-auto`,...x,children:h})},table({children:c,...d}){return e.jsx("div",{className:"overflow-x-auto",children:e.jsx("table",{className:"border-collapse border border-border",...d,children:c})})},th({children:c,...d}){return e.jsx("th",{className:"border border-border bg-muted px-4 py-2 text-left font-semibold",...d,children:c})},td({children:c,...d}){return e.jsx("td",{className:"border border-border px-4 py-2",...d,children:c})},a({children:c,...d}){return e.jsx("a",{className:"text-primary hover:underline",target:"_blank",rel:"noopener noreferrer",...d,children:c})},blockquote({children:c,...d}){return e.jsx("blockquote",{className:"border-l-4 border-primary pl-4 italic text-muted-foreground",...d,children:c})},h1({children:c,...d}){return e.jsx("h1",{className:"text-3xl font-bold mt-6 mb-4",...d,children:c})},h2({children:c,...d}){return e.jsx("h2",{className:"text-2xl font-bold mt-5 mb-3",...d,children:c})},h3({children:c,...d}){return e.jsx("h3",{className:"text-xl font-bold mt-4 mb-2",...d,children:c})},h4({children:c,...d}){return e.jsx("h4",{className:"text-lg font-semibold mt-3 mb-2",...d,children:c})},ul({children:c,...d}){return e.jsx("ul",{className:"list-disc list-inside space-y-1 my-2",...d,children:c})},ol({children:c,...d}){return e.jsx("ol",{className:"list-decimal list-inside space-y-1 my-2",...d,children:c})},p({children:c,...d}){return e.jsx("p",{className:"my-2 leading-relaxed",...d,children:c})},hr({...c}){return e.jsx("hr",{className:"my-4 border-border",...c})}},children:n})})}function bw({children:n,className:r}){return e.jsx(vw,{content:n,className:r})}const xa="/api/webui/emoji";async function yw(n){const r=new URLSearchParams;n.page&&r.append("page",n.page.toString()),n.page_size&&r.append("page_size",n.page_size.toString()),n.search&&r.append("search",n.search),n.is_registered!==void 0&&r.append("is_registered",n.is_registered.toString()),n.is_banned!==void 0&&r.append("is_banned",n.is_banned.toString()),n.format&&r.append("format",n.format),n.sort_by&&r.append("sort_by",n.sort_by),n.sort_order&&r.append("sort_order",n.sort_order);const c=await Te(`${xa}/list?${r}`,{});if(!c.ok)throw new Error(`获取表情包列表失败: ${c.statusText}`);return c.json()}async function Nw(n){const r=await Te(`${xa}/${n}`,{});if(!r.ok)throw new Error(`获取表情包详情失败: ${r.statusText}`);return r.json()}async function ww(n,r){const c=await Te(`${xa}/${n}`,{method:"PATCH",body:JSON.stringify(r)});if(!c.ok)throw new Error(`更新表情包失败: ${c.statusText}`);return c.json()}async function _w(n){const r=await Te(`${xa}/${n}`,{method:"DELETE"});if(!r.ok)throw new Error(`删除表情包失败: ${r.statusText}`);return r.json()}async function Sw(){const n=await Te(`${xa}/stats/summary`,{});if(!n.ok)throw new Error(`获取统计数据失败: ${n.statusText}`);return n.json()}async function Cw(n){const r=await Te(`${xa}/${n}/register`,{method:"POST"});if(!r.ok)throw new Error(`注册表情包失败: ${r.statusText}`);return r.json()}async function kw(n){const r=await Te(`${xa}/${n}/ban`,{method:"POST"});if(!r.ok)throw new Error(`封禁表情包失败: ${r.statusText}`);return r.json()}function Tw(n,r=!1){return r?`${xa}/${n}/thumbnail?original=true`:`${xa}/${n}/thumbnail`}function Ew(n){return`${xa}/${n}/thumbnail?original=true`}async function zw(n){const r=await Te(`${xa}/batch/delete`,{method:"POST",body:JSON.stringify({emoji_ids:n})});if(!r.ok){const c=await r.json();throw new Error(c.detail||"批量删除失败")}return r.json()}function Aw(){return`${xa}/upload`}function Mw(){const[n,r]=u.useState([]),[c,d]=u.useState(null),[h,x]=u.useState(!1),[f,j]=u.useState(1),[p,N]=u.useState(0),[v,C]=u.useState(20),[S,w]=u.useState("all"),[L,F]=u.useState("all"),[B,O]=u.useState("all"),[K,H]=u.useState("usage_count"),[z,V]=u.useState("desc"),[Y,E]=u.useState(null),[R,ne]=u.useState(!1),[fe,Ce]=u.useState(!1),[we,pe]=u.useState(!1),[Ne,be]=u.useState(new Set),[A,X]=u.useState(!1),[T,te]=u.useState(""),[_,me]=u.useState("medium"),[oe,ae]=u.useState(!1),{toast:xe}=Xt(),ve=u.useCallback(async()=>{try{x(!0);const re=await yw({page:f,page_size:v,is_registered:S==="all"?void 0:S==="registered",is_banned:L==="all"?void 0:L==="banned",format:B==="all"?void 0:B,sort_by:K,sort_order:z});r(re.data),N(re.total)}catch(re){const ke=re instanceof Error?re.message:"加载表情包列表失败";xe({title:"错误",description:ke,variant:"destructive"})}finally{x(!1)}},[f,v,S,L,B,K,z,xe]),de=async()=>{try{const re=await Sw();d(re.data)}catch(re){console.error("加载统计数据失败:",re)}};u.useEffect(()=>{ve()},[ve]),u.useEffect(()=>{de()},[]);const G=async re=>{try{const ke=await Nw(re.id);E(ke.data),ne(!0)}catch(ke){const Pe=ke instanceof Error?ke.message:"加载详情失败";xe({title:"错误",description:Pe,variant:"destructive"})}},W=re=>{E(re),Ce(!0)},U=re=>{E(re),pe(!0)},ee=async()=>{if(Y)try{await _w(Y.id),xe({title:"成功",description:"表情包已删除"}),pe(!1),E(null),ve(),de()}catch(re){const ke=re instanceof Error?re.message:"删除失败";xe({title:"错误",description:ke,variant:"destructive"})}},Se=async re=>{try{await Cw(re.id),xe({title:"成功",description:"表情包已注册"}),ve(),de()}catch(ke){const Pe=ke instanceof Error?ke.message:"注册失败";xe({title:"错误",description:Pe,variant:"destructive"})}},Me=async re=>{try{await kw(re.id),xe({title:"成功",description:"表情包已封禁"}),ve(),de()}catch(ke){const Pe=ke instanceof Error?ke.message:"封禁失败";xe({title:"错误",description:Pe,variant:"destructive"})}},tt=re=>{const ke=new Set(Ne);ke.has(re)?ke.delete(re):ke.add(re),be(ke)},Xe=async()=>{try{const re=await zw(Array.from(Ne));xe({title:"批量删除完成",description:re.message}),be(new Set),X(!1),ve(),de()}catch(re){xe({title:"批量删除失败",description:re instanceof Error?re.message:"批量删除失败",variant:"destructive"})}},Ut=()=>{const re=parseInt(T),ke=Math.ceil(p/v);re>=1&&re<=ke?(j(re),te("")):xe({title:"无效的页码",description:`请输入1-${ke}之间的页码`,variant:"destructive"})},Bt=c?.formats?Object.keys(c.formats):[];return e.jsxs("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:[e.jsxs("div",{className:"mb-4 sm:mb-6 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"表情包管理"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"管理麦麦的表情包资源"})]}),e.jsxs(b,{onClick:()=>ae(!0),className:"gap-2",children:[e.jsx(dr,{className:"h-4 w-4"}),"上传表情包"]})]}),e.jsx(st,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 pr-4",children:[c&&e.jsxs("div",{className:"grid gap-4 grid-cols-2 lg:grid-cols-4",children:[e.jsx(Ye,{children:e.jsxs(Nt,{className:"pb-2",children:[e.jsx(ns,{children:"总数"}),e.jsx(wt,{className:"text-2xl",children:c.total})]})}),e.jsx(Ye,{children:e.jsxs(Nt,{className:"pb-2",children:[e.jsx(ns,{children:"已注册"}),e.jsx(wt,{className:"text-2xl text-green-600",children:c.registered})]})}),e.jsx(Ye,{children:e.jsxs(Nt,{className:"pb-2",children:[e.jsx(ns,{children:"已封禁"}),e.jsx(wt,{className:"text-2xl text-red-600",children:c.banned})]})}),e.jsx(Ye,{children:e.jsxs(Nt,{className:"pb-2",children:[e.jsx(ns,{children:"未注册"}),e.jsx(wt,{className:"text-2xl text-gray-600",children:c.unregistered})]})})]}),e.jsxs(Ye,{children:[e.jsx(Nt,{children:e.jsxs(wt,{className:"flex items-center gap-2",children:[e.jsx(Eu,{className:"h-5 w-5"}),"筛选和排序"]})}),e.jsxs(kt,{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"排序方式"}),e.jsxs(qe,{value:`${K}-${z}`,onValueChange:re=>{const[ke,Pe]=re.split("-");H(ke),V(Pe),j(1)},children:[e.jsx(Be,{children:e.jsx(Ge,{})}),e.jsxs(He,{children:[e.jsx(ie,{value:"usage_count-desc",children:"使用次数 (多→少)"}),e.jsx(ie,{value:"usage_count-asc",children:"使用次数 (少→多)"}),e.jsx(ie,{value:"register_time-desc",children:"注册时间 (新→旧)"}),e.jsx(ie,{value:"register_time-asc",children:"注册时间 (旧→新)"}),e.jsx(ie,{value:"record_time-desc",children:"记录时间 (新→旧)"}),e.jsx(ie,{value:"record_time-asc",children:"记录时间 (旧→新)"}),e.jsx(ie,{value:"last_used_time-desc",children:"最后使用 (新→旧)"}),e.jsx(ie,{value:"last_used_time-asc",children:"最后使用 (旧→新)"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"注册状态"}),e.jsxs(qe,{value:S,onValueChange:re=>{w(re),j(1)},children:[e.jsx(Be,{children:e.jsx(Ge,{})}),e.jsxs(He,{children:[e.jsx(ie,{value:"all",children:"全部"}),e.jsx(ie,{value:"registered",children:"已注册"}),e.jsx(ie,{value:"unregistered",children:"未注册"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"封禁状态"}),e.jsxs(qe,{value:L,onValueChange:re=>{F(re),j(1)},children:[e.jsx(Be,{children:e.jsx(Ge,{})}),e.jsxs(He,{children:[e.jsx(ie,{value:"all",children:"全部"}),e.jsx(ie,{value:"banned",children:"已封禁"}),e.jsx(ie,{value:"unbanned",children:"未封禁"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"格式"}),e.jsxs(qe,{value:B,onValueChange:re=>{O(re),j(1)},children:[e.jsx(Be,{children:e.jsx(Ge,{})}),e.jsxs(He,{children:[e.jsx(ie,{value:"all",children:"全部"}),Bt.map(re=>e.jsxs(ie,{value:re,children:[re.toUpperCase()," (",c?.formats[re],")"]},re))]})]})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between gap-3 pt-4 border-t",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[Ne.size>0&&e.jsxs("span",{className:"text-sm text-muted-foreground",children:["已选择 ",Ne.size," 个表情包"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{className:"text-sm whitespace-nowrap",children:"卡片大小"}),e.jsxs(qe,{value:_,onValueChange:re=>me(re),children:[e.jsx(Be,{className:"w-24",children:e.jsx(Ge,{})}),e.jsxs(He,{children:[e.jsx(ie,{value:"small",children:"小"}),e.jsx(ie,{value:"medium",children:"中"}),e.jsx(ie,{value:"large",children:"大"})]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{htmlFor:"emoji-page-size",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(qe,{value:v.toString(),onValueChange:re=>{C(parseInt(re)),j(1),be(new Set)},children:[e.jsx(Be,{id:"emoji-page-size",className:"w-20",children:e.jsx(Ge,{})}),e.jsxs(He,{children:[e.jsx(ie,{value:"20",children:"20"}),e.jsx(ie,{value:"40",children:"40"}),e.jsx(ie,{value:"60",children:"60"}),e.jsx(ie,{value:"100",children:"100"})]})]}),Ne.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(b,{variant:"outline",size:"sm",onClick:()=>be(new Set),children:"取消选择"}),e.jsxs(b,{variant:"destructive",size:"sm",onClick:()=>X(!0),children:[e.jsx(at,{className:"h-4 w-4 mr-1"}),"批量删除"]})]})]})]}),e.jsx("div",{className:"flex justify-end pt-4 border-t",children:e.jsxs(b,{variant:"outline",size:"sm",onClick:ve,disabled:h,children:[e.jsx(ws,{className:`h-4 w-4 mr-2 ${h?"animate-spin":""}`}),"刷新"]})})]})]}),e.jsxs(Ye,{children:[e.jsxs(Nt,{children:[e.jsx(wt,{children:"表情包列表"}),e.jsxs(ns,{children:["共 ",p," 个表情包,当前第 ",f," 页"]})]}),e.jsxs(kt,{children:[n.length===0?e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:"暂无数据"}):e.jsx("div",{className:`grid gap-3 ${_==="small"?"grid-cols-3 sm:grid-cols-4 md:grid-cols-6 lg:grid-cols-8 xl:grid-cols-10":_==="medium"?"grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6 xl:grid-cols-8":"grid-cols-2 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5"}`,children:n.map(re=>e.jsxs("div",{className:`group relative rounded-lg border bg-card overflow-hidden hover:ring-2 hover:ring-primary transition-all cursor-pointer ${Ne.has(re.id)?"ring-2 ring-primary bg-primary/5":""}`,onClick:()=>tt(re.id),children:[e.jsx("div",{className:`absolute top-1 left-1 z-10 transition-opacity ${Ne.has(re.id)?"opacity-100":"opacity-0 group-hover:opacity-100"}`,children:e.jsx("div",{className:`w-5 h-5 rounded-full border-2 flex items-center justify-center ${Ne.has(re.id)?"bg-primary border-primary text-primary-foreground":"bg-background/80 border-muted-foreground/50"}`,children:Ne.has(re.id)&&e.jsx(ha,{className:"h-3 w-3"})})}),e.jsxs("div",{className:"absolute top-1 right-1 z-10 flex flex-col gap-0.5",children:[re.is_registered&&e.jsx(Je,{variant:"default",className:"bg-green-600 text-[10px] px-1 py-0",children:"已注册"}),re.is_banned&&e.jsx(Je,{variant:"destructive",className:"text-[10px] px-1 py-0",children:"已封禁"})]}),e.jsx("div",{className:`aspect-square bg-muted flex items-center justify-center overflow-hidden ${_==="small"?"p-1":_==="medium"?"p-2":"p-3"}`,children:e.jsx(jw,{src:Tw(re.id),alt:"表情包"})}),e.jsxs("div",{className:`border-t bg-card ${_==="small"?"p-1":"p-2"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-1 text-xs text-muted-foreground mb-1",children:[e.jsx(Je,{variant:"outline",className:"text-[10px] px-1 py-0",children:re.format.toUpperCase()}),e.jsxs("span",{className:"font-mono",children:[re.usage_count,"次"]})]}),e.jsxs("div",{className:`flex gap-1 justify-center opacity-0 group-hover:opacity-100 transition-opacity ${_==="small"?"flex-wrap":""}`,children:[e.jsx(b,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:ke=>{ke.stopPropagation(),W(re)},title:"编辑",children:e.jsx(mr,{className:"h-3 w-3"})}),e.jsx(b,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:ke=>{ke.stopPropagation(),G(re)},title:"详情",children:e.jsx(Ra,{className:"h-3 w-3"})}),!re.is_registered&&e.jsx(b,{variant:"ghost",size:"icon",className:"h-6 w-6 text-green-600 hover:text-green-700",onClick:ke=>{ke.stopPropagation(),Se(re)},title:"注册",children:e.jsx(ha,{className:"h-3 w-3"})}),!re.is_banned&&e.jsx(b,{variant:"ghost",size:"icon",className:"h-6 w-6 text-orange-600 hover:text-orange-700",onClick:ke=>{ke.stopPropagation(),Me(re)},title:"封禁",children:e.jsx(Ny,{className:"h-3 w-3"})}),e.jsx(b,{variant:"ghost",size:"icon",className:"h-6 w-6 text-red-600 hover:text-red-700",onClick:ke=>{ke.stopPropagation(),U(re)},title:"删除",children:e.jsx(at,{className:"h-3 w-3"})})]})]})]},re.id))}),p>0&&e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4 mt-4",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["显示 ",(f-1)*v+1," 到"," ",Math.min(f*v,p)," 条,共 ",p," 条"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(b,{variant:"outline",size:"sm",onClick:()=>j(1),disabled:f===1,className:"hidden sm:flex",children:e.jsx(vr,{className:"h-4 w-4"})}),e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>j(re=>Math.max(1,re-1)),disabled:f===1,children:[e.jsx(dn,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"上一页"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ce,{type:"number",value:T,onChange:re=>te(re.target.value),onKeyDown:re=>re.key==="Enter"&&Ut(),placeholder:f.toString(),className:"w-16 h-8 text-center",min:1,max:Math.ceil(p/v)}),e.jsx(b,{variant:"outline",size:"sm",onClick:Ut,disabled:!T,className:"h-8",children:"跳转"})]}),e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>j(re=>re+1),disabled:f>=Math.ceil(p/v),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Ll,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(b,{variant:"outline",size:"sm",onClick:()=>j(Math.ceil(p/v)),disabled:f>=Math.ceil(p/v),className:"hidden sm:flex",children:e.jsx(br,{className:"h-4 w-4"})})]})]})]})]}),e.jsx(Dw,{emoji:Y,open:R,onOpenChange:ne}),e.jsx(Ow,{emoji:Y,open:fe,onOpenChange:Ce,onSuccess:()=>{ve(),de()}}),e.jsx(Rw,{open:oe,onOpenChange:ae,onSuccess:()=>{ve(),de()}})]})}),e.jsx(bt,{open:A,onOpenChange:X,children:e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认批量删除"}),e.jsxs(xt,{children:["你确定要删除选中的 ",Ne.size," 个表情包吗?此操作不可撤销。"]})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:Xe,children:"确认删除"})]})]})}),e.jsx(Jt,{open:we,onOpenChange:pe,children:e.jsxs($t,{children:[e.jsxs(Qt,{children:[e.jsx(Yt,{children:"确认删除"}),e.jsx(ds,{children:"确定要删除这个表情包吗?此操作无法撤销。"})]}),e.jsxs(xs,{children:[e.jsx(b,{variant:"outline",onClick:()=>pe(!1),children:"取消"}),e.jsx(b,{variant:"destructive",onClick:ee,children:"删除"})]})]})})]})}function Dw({emoji:n,open:r,onOpenChange:c}){if(!n)return null;const d=h=>h?new Date(h*1e3).toLocaleString("zh-CN"):"-";return e.jsx(Jt,{open:r,onOpenChange:c,children:e.jsxs($t,{className:"max-w-2xl max-h-[90vh]",children:[e.jsx(Qt,{children:e.jsx(Yt,{children:"表情包详情"})}),e.jsx(st,{className:"max-h-[calc(90vh-8rem)] pr-4",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"w-32 h-32 bg-muted rounded-lg flex items-center justify-center overflow-hidden",children:e.jsx("img",{src:Ew(n.id),alt:n.description||"表情包",className:"w-full h-full object-cover",onError:h=>{const x=h.target;x.style.display="none";const f=x.parentElement;f&&(f.innerHTML='')}})})}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(y,{className:"text-muted-foreground",children:"ID"}),e.jsx("div",{className:"mt-1 font-mono",children:n.id})]}),e.jsxs("div",{children:[e.jsx(y,{className:"text-muted-foreground",children:"格式"}),e.jsx("div",{className:"mt-1",children:e.jsx(Je,{variant:"outline",children:n.format.toUpperCase()})})]})]}),e.jsxs("div",{children:[e.jsx(y,{className:"text-muted-foreground",children:"文件路径"}),e.jsx("div",{className:"mt-1 font-mono text-sm break-all bg-muted p-2 rounded",children:n.full_path})]}),e.jsxs("div",{children:[e.jsx(y,{className:"text-muted-foreground",children:"哈希值"}),e.jsx("div",{className:"mt-1 font-mono text-sm break-all bg-muted p-2 rounded",children:n.emoji_hash})]}),e.jsxs("div",{children:[e.jsx(y,{className:"text-muted-foreground",children:"描述"}),n.description?e.jsx("div",{className:"mt-1 rounded-lg border bg-muted/50 p-3",children:e.jsx(bw,{className:"prose-sm",children:n.description})}):e.jsx("div",{className:"mt-1 text-sm text-muted-foreground",children:"-"})]}),e.jsxs("div",{children:[e.jsx(y,{className:"text-muted-foreground",children:"情绪"}),e.jsx("div",{className:"mt-1",children:n.emotion?e.jsx("span",{className:"text-sm",children:n.emotion}):e.jsx("span",{className:"text-sm text-muted-foreground",children:"-"})})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(y,{className:"text-muted-foreground",children:"状态"}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[n.is_registered&&e.jsx(Je,{variant:"default",className:"bg-green-600",children:"已注册"}),n.is_banned&&e.jsx(Je,{variant:"destructive",children:"已封禁"}),!n.is_registered&&!n.is_banned&&e.jsx(Je,{variant:"outline",children:"未注册"})]})]}),e.jsxs("div",{children:[e.jsx(y,{className:"text-muted-foreground",children:"使用次数"}),e.jsx("div",{className:"mt-1 font-mono text-lg",children:n.usage_count})]})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(y,{className:"text-muted-foreground",children:"记录时间"}),e.jsx("div",{className:"mt-1 text-sm",children:d(n.record_time)})]}),e.jsxs("div",{children:[e.jsx(y,{className:"text-muted-foreground",children:"注册时间"}),e.jsx("div",{className:"mt-1 text-sm",children:d(n.register_time)})]})]}),e.jsxs("div",{children:[e.jsx(y,{className:"text-muted-foreground",children:"最后使用"}),e.jsx("div",{className:"mt-1 text-sm",children:d(n.last_used_time)})]})]})})]})})}function Ow({emoji:n,open:r,onOpenChange:c,onSuccess:d}){const[h,x]=u.useState(""),[f,j]=u.useState(!1),[p,N]=u.useState(!1),[v,C]=u.useState(!1),{toast:S}=Xt();u.useEffect(()=>{n&&(x(n.emotion||""),j(n.is_registered),N(n.is_banned))},[n]);const w=async()=>{if(n)try{C(!0);const L=h.split(/[,,]/).map(F=>F.trim()).filter(Boolean).join(",");await ww(n.id,{emotion:L||void 0,is_registered:f,is_banned:p}),S({title:"成功",description:"表情包信息已更新"}),c(!1),d()}catch(L){const F=L instanceof Error?L.message:"保存失败";S({title:"错误",description:F,variant:"destructive"})}finally{C(!1)}};return n?e.jsx(Jt,{open:r,onOpenChange:c,children:e.jsxs($t,{className:"max-w-2xl",children:[e.jsxs(Qt,{children:[e.jsx(Yt,{children:"编辑表情包"}),e.jsx(ds,{children:"修改表情包的情绪和状态信息"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(y,{children:"情绪"}),e.jsx(Ft,{value:h,onChange:L=>x(L.target.value),placeholder:"输入情绪描述...",rows:2,className:"mt-1"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"输入情绪相关的文本描述"})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Cs,{id:"is_registered",checked:f,onCheckedChange:L=>{L===!0?(j(!0),N(!1)):j(!1)}}),e.jsx(y,{htmlFor:"is_registered",className:"cursor-pointer",children:"已注册"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Cs,{id:"is_banned",checked:p,onCheckedChange:L=>{L===!0?(N(!0),j(!1)):N(!1)}}),e.jsx(y,{htmlFor:"is_banned",className:"cursor-pointer",children:"已封禁"})]})]})]}),e.jsxs(xs,{children:[e.jsx(b,{variant:"outline",onClick:()=>c(!1),children:"取消"}),e.jsx(b,{onClick:w,disabled:v,children:v?"保存中...":"保存"})]})]})}):null}function Rw({open:n,onOpenChange:r,onSuccess:c}){const[d,h]=u.useState("select"),[x,f]=u.useState([]),[j,p]=u.useState(null),[N,v]=u.useState(!1),{toast:C}=Xt(),S=u.useMemo(()=>new aN({id:"emoji-uploader",autoProceed:!1,restrictions:{maxFileSize:10485760,allowedFileTypes:["image/jpeg","image/png","image/gif","image/webp"],maxNumberOfFiles:20},locale:{pluralize:()=>0,strings:{addMoreFiles:"添加更多文件",addingMoreFiles:"正在添加更多文件",allowedFileTypes:"允许的文件类型:%{types}",cancel:"取消",closeModal:"关闭",complete:"完成",connectedToInternet:"已连接到互联网",copyLink:"复制链接",copyLinkToClipboardFallback:"复制下方链接",copyLinkToClipboardSuccess:"链接已复制到剪贴板",dashboardTitle:"选择文件",dashboardWindowTitle:"文件选择窗口(按 ESC 关闭)",done:"完成",dropHereOr:"拖放文件到这里或 %{browse}",dropHint:"将文件拖放到此处",dropPasteFiles:"将文件拖放到这里或 %{browseFiles}",dropPasteFolders:"将文件拖放到这里或 %{browseFolders}",dropPasteBoth:"将文件拖放到这里,%{browseFiles} 或 %{browseFolders}",dropPasteImportFiles:"将文件拖放到这里,%{browseFiles} 或从以下位置导入:",dropPasteImportFolders:"将文件拖放到这里,%{browseFolders} 或从以下位置导入:",dropPasteImportBoth:"将文件拖放到这里,%{browseFiles},%{browseFolders} 或从以下位置导入:",editFile:"编辑文件",editing:"正在编辑 %{file}",emptyFolderAdded:"未从空文件夹添加文件",exceedsSize:"%{file} 超过了最大允许大小 %{size}",failedToUpload:"上传 %{file} 失败",fileSource:"文件来源:%{name}",filesUploadedOfTotal:{0:"已上传 %{complete} / %{smart_count} 个文件",1:"已上传 %{complete} / %{smart_count} 个文件"},filter:"筛选",finishEditingFile:"完成编辑文件",folderAdded:{0:"已从 %{folder} 添加 %{smart_count} 个文件",1:"已从 %{folder} 添加 %{smart_count} 个文件"},generatingThumbnails:"正在生成缩略图...",import:"导入",importFiles:"从以下位置导入文件:",importFrom:"从 %{name} 导入",loading:"加载中...",logOut:"登出",myDevice:"我的设备",noFilesFound:"这里没有文件或文件夹",noInternetConnection:"无网络连接",openFolderNamed:"打开文件夹 %{name}",pause:"暂停",pauseUpload:"暂停上传",paused:"已暂停",poweredBy:"技术支持:%{uppy}",processingXFiles:{0:"正在处理 %{smart_count} 个文件",1:"正在处理 %{smart_count} 个文件"},recording:"录制中",removeFile:"移除文件",resetFilter:"重置筛选",resume:"继续",resumeUpload:"继续上传",retry:"重试",retryUpload:"重试上传",save:"保存",saveChanges:"保存更改",selectFileNamed:"选择文件 %{name}",selectX:{0:"选择 %{smart_count}",1:"选择 %{smart_count}"},smile:"笑一个!",startRecording:"开始录制视频",stopRecording:"停止录制视频",takePicture:"拍照",timedOut:"上传已停滞 %{seconds} 秒,正在中止。",upload:"下一步",uploadComplete:"上传完成",uploadFailed:"上传失败",uploadPaused:"上传已暂停",uploadXFiles:{0:"下一步(%{smart_count} 个文件)",1:"下一步(%{smart_count} 个文件)"},uploadXNewFiles:{0:"下一步(+%{smart_count} 个文件)",1:"下一步(+%{smart_count} 个文件)"},uploading:"正在上传",uploadingXFiles:{0:"正在上传 %{smart_count} 个文件",1:"正在上传 %{smart_count} 个文件"},xFilesSelected:{0:"已选择 %{smart_count} 个文件",1:"已选择 %{smart_count} 个文件"},xMoreFilesAdded:{0:"又添加了 %{smart_count} 个文件",1:"又添加了 %{smart_count} 个文件"},xTimeLeft:"剩余 %{time}",youCanOnlyUploadFileTypes:"您只能上传:%{types}",youCanOnlyUploadX:{0:"您只能上传 %{smart_count} 个文件",1:"您只能上传 %{smart_count} 个文件"},youHaveToAtLeastSelectX:{0:"您至少需要选择 %{smart_count} 个文件",1:"您至少需要选择 %{smart_count} 个文件"},browseFiles:"浏览文件",browseFolders:"浏览文件夹",cancelUpload:"取消上传",addMore:"添加更多",back:"返回",editFileWithFilename:"编辑文件 %{file}"}}}),[]);u.useEffect(()=>{const Y=()=>{const E=S.getFiles();if(E.length===0)return;const R=E.map(ne=>({id:ne.id,name:ne.name,previewUrl:ne.preview||URL.createObjectURL(ne.data),emotion:"",description:"",isRegistered:!0,file:ne.data}));f(R),E.length===1?(p(R[0].id),h("edit-single")):h("edit-multiple")};return S.on("upload",Y),()=>{S.off("upload",Y)}},[S]),u.useEffect(()=>{n||(S.cancelAll(),h("select"),f([]),p(null),v(!1))},[n,S]);const w=u.useCallback((Y,E)=>{f(R=>R.map(ne=>ne.id===Y?{...ne,...E}:ne))},[]),L=u.useCallback(Y=>Y.emotion.trim().length>0,[]),F=u.useMemo(()=>x.length>0&&x.every(L),[x,L]),B=u.useMemo(()=>x.find(Y=>Y.id===j)||null,[x,j]),O=u.useCallback(()=>{(d==="edit-single"||d==="edit-multiple")&&(h("select"),f([]),p(null))},[d]),K=u.useCallback(async()=>{if(!F){C({title:"请填写必填项",description:"每个表情包的情感标签都是必填的",variant:"destructive"});return}v(!0);const Y=localStorage.getItem("access-token")||"";let E=0,R=0;try{for(const ne of x){const fe=new FormData;fe.append("file",ne.file),fe.append("emotion",ne.emotion),fe.append("description",ne.description),fe.append("is_registered",ne.isRegistered.toString());try{(await fetch(Aw(),{method:"POST",headers:{Authorization:`Bearer ${Y}`},body:fe})).ok?E++:R++}catch{R++}}R===0?(C({title:"上传成功",description:`成功上传 ${E} 个表情包`}),r(!1),c()):(C({title:"部分上传失败",description:`成功 ${E} 个,失败 ${R} 个`,variant:"destructive"}),c())}finally{v(!1)}},[F,x,C,r,c]),H=()=>e.jsx("div",{className:"space-y-4",children:e.jsx("div",{className:"border rounded-lg overflow-hidden w-full",children:e.jsx(gw,{uppy:S,proudlyDisplayPoweredByUppy:!1,hideProgressDetails:!0,height:350,width:"100%",theme:"auto",note:"支持 JPG、PNG、GIF、WebP 格式,最多 20 个文件"})})}),z=()=>{const Y=x[0];return Y?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(b,{variant:"ghost",size:"sm",onClick:O,children:[e.jsx(ti,{className:"h-4 w-4 mr-1"}),"返回"]}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"编辑表情包信息"})]}),e.jsxs("div",{className:"flex gap-6",children:[e.jsxs("div",{className:"flex-shrink-0",children:[e.jsx("div",{className:"w-32 h-32 rounded-lg border overflow-hidden bg-muted flex items-center justify-center",children:e.jsx("img",{src:Y.previewUrl,alt:Y.name,className:"max-w-full max-h-full object-contain"})}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2 text-center truncate max-w-32",children:Y.name})]}),e.jsxs("div",{className:"flex-1 space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(y,{htmlFor:"single-emotion",children:["情感标签 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(ce,{id:"single-emotion",value:Y.emotion,onChange:E=>w(Y.id,{emotion:E.target.value}),placeholder:"多个标签用逗号分隔,如:开心,高兴",className:Y.emotion.trim()?"":"border-destructive"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"用于情感匹配,多个标签用逗号分隔"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"single-description",children:"描述"}),e.jsx(ce,{id:"single-description",value:Y.description,onChange:E=>w(Y.id,{description:E.target.value}),placeholder:"输入表情包描述..."})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Cs,{id:"single-is-registered",checked:Y.isRegistered,onCheckedChange:E=>w(Y.id,{isRegistered:E===!0})}),e.jsx(y,{htmlFor:"single-is-registered",className:"cursor-pointer",children:"上传后立即注册(可被麦麦使用)"})]})]})]}),e.jsx(xs,{children:e.jsx(b,{onClick:K,disabled:!F||N,children:N?"上传中...":"上传"})})]}):null},V=()=>{const Y=x.filter(L).length,E=x.length;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(b,{variant:"ghost",size:"sm",onClick:O,children:[e.jsx(ti,{className:"h-4 w-4 mr-1"}),"返回"]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["编辑表情包信息(",Y,"/",E," 已完成)"]})]}),e.jsx(Je,{variant:F?"default":"secondary",children:F?e.jsxs(e.Fragment,{children:[e.jsx(Na,{className:"h-3 w-3 mr-1"}),"全部完成"]}):e.jsxs(e.Fragment,{children:[e.jsx(on,{className:"h-3 w-3 mr-1"}),"未完成"]})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(st,{className:"h-[350px] pr-2",children:e.jsx("div",{className:"space-y-2",children:x.map(R=>{const ne=L(R),fe=j===R.id;return e.jsxs("div",{onClick:()=>p(R.id),className:` flex items-center gap-3 p-3 rounded-lg border-2 cursor-pointer transition-all ${fe?"ring-2 ring-primary":""} ${ne?"border-green-500 bg-green-50 dark:bg-green-950/20":"border-border hover:border-muted-foreground/50"} `,children:[e.jsx("div",{className:"w-12 h-12 rounded border overflow-hidden bg-muted flex-shrink-0 flex items-center justify-center",children:e.jsx("img",{src:R.previewUrl,alt:R.name,className:"max-w-full max-h-full object-contain"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:R.name}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:R.emotion||"未填写情感标签"})]}),ne?e.jsx(ha,{className:"h-5 w-5 text-green-500 flex-shrink-0"}):e.jsx("div",{className:"h-5 w-5 rounded-full border-2 border-muted-foreground/30 flex-shrink-0"})]},R.id)})})}),e.jsx("div",{className:"border rounded-lg p-4",children:B?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-16 h-16 rounded border overflow-hidden bg-muted flex items-center justify-center",children:e.jsx("img",{src:B.previewUrl,alt:B.name,className:"max-w-full max-h-full object-contain"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium truncate",children:B.name}),L(B)&&e.jsxs(Je,{variant:"outline",className:"text-green-600 border-green-600",children:[e.jsx(Na,{className:"h-3 w-3 mr-1"}),"已完成"]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(y,{htmlFor:"multi-emotion",children:["情感标签 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(ce,{id:"multi-emotion",value:B.emotion,onChange:R=>w(B.id,{emotion:R.target.value}),placeholder:"多个标签用逗号分隔,如:开心,高兴",className:B.emotion.trim()?"":"border-destructive"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"multi-description",children:"描述"}),e.jsx(ce,{id:"multi-description",value:B.description,onChange:R=>w(B.id,{description:R.target.value}),placeholder:"输入表情包描述..."})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Cs,{id:"multi-is-registered",checked:B.isRegistered,onCheckedChange:R=>w(B.id,{isRegistered:R===!0})}),e.jsx(y,{htmlFor:"multi-is-registered",className:"cursor-pointer text-sm",children:"上传后立即注册"})]})]}):e.jsx("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:e.jsxs("div",{className:"text-center",children:[e.jsx(ig,{className:"h-12 w-12 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"点击左侧卡片编辑"})]})})})]}),e.jsx(xs,{children:e.jsx(b,{onClick:K,disabled:!F||N,children:N?"上传中...":`上传全部 (${E})`})})]})};return e.jsx(Jt,{open:n,onOpenChange:r,children:e.jsxs($t,{className:"max-w-3xl max-h-[90vh] overflow-hidden",children:[e.jsxs(Qt,{children:[e.jsxs(Yt,{className:"flex items-center gap-2",children:[e.jsx(dr,{className:"h-5 w-5"}),d==="select"&&"上传表情包 - 选择文件",d==="edit-single"&&"上传表情包 - 填写信息",d==="edit-multiple"&&"上传表情包 - 批量编辑"]}),e.jsxs(ds,{children:[d==="select"&&"支持 JPG、PNG、GIF、WebP 格式,单个文件最大 10MB,可同时上传多个文件",d==="edit-single"&&"请填写表情包的情感标签(必填)和描述",d==="edit-multiple"&&"点击左侧卡片编辑每个表情包的信息,情感标签为必填项"]})]}),e.jsxs("div",{className:"overflow-y-auto pr-1",children:[d==="select"&&H(),d==="edit-single"&&z(),d==="edit-multiple"&&V()]})]})})}const Bl="/api/webui/expression";async function Lw(){const n=await Te(`${Bl}/chats`,{});if(!n.ok){const r=await n.json();throw new Error(r.detail||"获取聊天列表失败")}return n.json()}async function Uw(n){const r=new URLSearchParams;n.page&&r.append("page",n.page.toString()),n.page_size&&r.append("page_size",n.page_size.toString()),n.search&&r.append("search",n.search),n.chat_id&&r.append("chat_id",n.chat_id);const c=await Te(`${Bl}/list?${r}`,{});if(!c.ok){const d=await c.json();throw new Error(d.detail||"获取表达方式列表失败")}return c.json()}async function Bw(n){const r=await Te(`${Bl}/${n}`,{});if(!r.ok){const c=await r.json();throw new Error(c.detail||"获取表达方式详情失败")}return r.json()}async function Hw(n){const r=await Te(`${Bl}/`,{method:"POST",body:JSON.stringify(n)});if(!r.ok){const c=await r.json();throw new Error(c.detail||"创建表达方式失败")}return r.json()}async function qw(n,r){const c=await Te(`${Bl}/${n}`,{method:"PATCH",body:JSON.stringify(r)});if(!c.ok){const d=await c.json();throw new Error(d.detail||"更新表达方式失败")}return c.json()}async function Gw(n){const r=await Te(`${Bl}/${n}`,{method:"DELETE"});if(!r.ok){const c=await r.json();throw new Error(c.detail||"删除表达方式失败")}return r.json()}async function Vw(n){const r=await Te(`${Bl}/batch/delete`,{method:"POST",body:JSON.stringify({ids:n})});if(!r.ok){const c=await r.json();throw new Error(c.detail||"批量删除表达方式失败")}return r.json()}async function Fw(){const n=await Te(`${Bl}/stats/summary`,{});if(!n.ok){const r=await n.json();throw new Error(r.detail||"获取统计数据失败")}return n.json()}function $w(){const[n,r]=u.useState([]),[c,d]=u.useState(!0),[h,x]=u.useState(0),[f,j]=u.useState(1),[p,N]=u.useState(20),[v,C]=u.useState(""),[S,w]=u.useState(null),[L,F]=u.useState(!1),[B,O]=u.useState(!1),[K,H]=u.useState(!1),[z,V]=u.useState(null),[Y,E]=u.useState(new Set),[R,ne]=u.useState(!1),[fe,Ce]=u.useState(""),[we,pe]=u.useState({total:0,recent_7days:0,chat_count:0,top_chats:{}}),[Ne,be]=u.useState([]),[A,X]=u.useState(new Map),{toast:T}=Xt(),te=async()=>{try{d(!0);const ee=await Uw({page:f,page_size:p,search:v||void 0});r(ee.data),x(ee.total)}catch(ee){T({title:"加载失败",description:ee instanceof Error?ee.message:"无法加载表达方式",variant:"destructive"})}finally{d(!1)}},_=async()=>{try{const ee=await Fw();ee?.data&&pe(ee.data)}catch(ee){console.error("加载统计数据失败:",ee)}},me=async()=>{try{const ee=await Lw();if(ee?.data){be(ee.data);const Se=new Map;ee.data.forEach(Me=>{Se.set(Me.chat_id,Me.chat_name)}),X(Se)}}catch(ee){console.error("加载聊天列表失败:",ee)}},oe=ee=>A.get(ee)||ee;u.useEffect(()=>{te(),_(),me()},[f,p,v]);const ae=async ee=>{try{const Se=await Bw(ee.id);w(Se.data),F(!0)}catch(Se){T({title:"加载详情失败",description:Se instanceof Error?Se.message:"无法加载表达方式详情",variant:"destructive"})}},xe=ee=>{w(ee),O(!0)},ve=async ee=>{try{await Gw(ee.id),T({title:"删除成功",description:`已删除表达方式: ${ee.situation}`}),V(null),te(),_()}catch(Se){T({title:"删除失败",description:Se instanceof Error?Se.message:"无法删除表达方式",variant:"destructive"})}},de=ee=>{const Se=new Set(Y);Se.has(ee)?Se.delete(ee):Se.add(ee),E(Se)},G=()=>{Y.size===n.length&&n.length>0?E(new Set):E(new Set(n.map(ee=>ee.id)))},W=async()=>{try{await Vw(Array.from(Y)),T({title:"批量删除成功",description:`已删除 ${Y.size} 个表达方式`}),E(new Set),ne(!1),te(),_()}catch(ee){T({title:"批量删除失败",description:ee instanceof Error?ee.message:"无法批量删除表达方式",variant:"destructive"})}},U=()=>{const ee=parseInt(fe),Se=Math.ceil(h/p);ee>=1&&ee<=Se?(j(ee),Ce("")):T({title:"无效的页码",description:`请输入1-${Se}之间的页码`,variant:"destructive"})};return e.jsxs("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:[e.jsx("div",{className:"mb-4 sm:mb-6",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl sm:text-3xl font-bold flex items-center gap-2",children:[e.jsx(cn,{className:"h-8 w-8",strokeWidth:2}),"表达方式管理"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"管理麦麦的表达方式和话术模板"})]}),e.jsxs(b,{onClick:()=>H(!0),className:"gap-2",children:[e.jsx(hs,{className:"h-4 w-4"}),"新增表达方式"]})]})}),e.jsx(st,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 pr-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"总数量"}),e.jsx("div",{className:"text-2xl font-bold mt-1",children:we.total})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"近7天新增"}),e.jsx("div",{className:"text-2xl font-bold mt-1 text-green-600",children:we.recent_7days})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"关联聊天数"}),e.jsx("div",{className:"text-2xl font-bold mt-1 text-blue-600",children:we.chat_count})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx(y,{htmlFor:"search",children:"搜索"}),e.jsx("div",{className:"flex flex-col sm:flex-row gap-2 mt-1.5",children:e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(zs,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(ce,{id:"search",placeholder:"搜索情境、风格或上下文...",value:v,onChange:ee=>C(ee.target.value),className:"pl-9"})]})}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between gap-3 mt-4 pt-4 border-t",children:[e.jsx("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:Y.size>0&&e.jsxs("span",{children:["已选择 ",Y.size," 个表达方式"]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{htmlFor:"page-size",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(qe,{value:p.toString(),onValueChange:ee=>{N(parseInt(ee)),j(1),E(new Set)},children:[e.jsx(Be,{id:"page-size",className:"w-20",children:e.jsx(Ge,{})}),e.jsxs(He,{children:[e.jsx(ie,{value:"10",children:"10"}),e.jsx(ie,{value:"20",children:"20"}),e.jsx(ie,{value:"50",children:"50"}),e.jsx(ie,{value:"100",children:"100"})]})]}),Y.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(b,{variant:"outline",size:"sm",onClick:()=>E(new Set),children:"取消选择"}),e.jsxs(b,{variant:"destructive",size:"sm",onClick:()=>ne(!0),children:[e.jsx(at,{className:"h-4 w-4 mr-1"}),"批量删除"]})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card",children:[e.jsx("div",{className:"hidden md:block",children:e.jsxs(li,{children:[e.jsx(ni,{children:e.jsxs(_s,{children:[e.jsx(rt,{className:"w-12",children:e.jsx(Cs,{checked:Y.size===n.length&&n.length>0,onCheckedChange:G})}),e.jsx(rt,{children:"情境"}),e.jsx(rt,{children:"风格"}),e.jsx(rt,{children:"聊天"}),e.jsx(rt,{className:"text-right",children:"操作"})]})}),e.jsx(ii,{children:c?e.jsx(_s,{children:e.jsx(Ze,{colSpan:5,className:"text-center py-8 text-muted-foreground",children:"加载中..."})}):n.length===0?e.jsx(_s,{children:e.jsx(Ze,{colSpan:5,className:"text-center py-8 text-muted-foreground",children:"暂无数据"})}):n.map(ee=>e.jsxs(_s,{children:[e.jsx(Ze,{children:e.jsx(Cs,{checked:Y.has(ee.id),onCheckedChange:()=>de(ee.id)})}),e.jsx(Ze,{className:"font-medium max-w-xs truncate",children:ee.situation}),e.jsx(Ze,{className:"max-w-xs truncate",children:ee.style}),e.jsx(Ze,{className:"max-w-[200px] truncate",title:oe(ee.chat_id),style:{wordBreak:"keep-all"},children:e.jsx("span",{className:"whitespace-nowrap overflow-hidden text-ellipsis block",children:oe(ee.chat_id)})}),e.jsx(Ze,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(b,{variant:"default",size:"sm",onClick:()=>xe(ee),children:[e.jsx(mr,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsx(b,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>ae(ee),title:"查看详情",children:e.jsx(Ws,{className:"h-4 w-4"})}),e.jsxs(b,{size:"sm",onClick:()=>V(ee),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(at,{className:"h-4 w-4 mr-1"}),"删除"]})]})})]},ee.id))})]})}),e.jsx("div",{className:"md:hidden space-y-3 p-4",children:c?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):n.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无数据"}):n.map(ee=>e.jsxs("div",{className:"rounded-lg border bg-card p-4 space-y-3 overflow-hidden",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Cs,{checked:Y.has(ee.id),onCheckedChange:()=>de(ee.id),className:"mt-1"}),e.jsxs("div",{className:"min-w-0 flex-1 overflow-hidden space-y-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"情境"}),e.jsx("h3",{className:"font-semibold text-sm line-clamp-2 w-full break-all",title:ee.situation,children:ee.situation})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"风格"}),e.jsx("p",{className:"text-sm line-clamp-2 w-full break-all",title:ee.style,children:ee.style})]})]})]}),e.jsxs("div",{className:"text-sm",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"聊天"}),e.jsx("p",{className:"text-sm truncate",title:oe(ee.chat_id),style:{wordBreak:"keep-all"},children:oe(ee.chat_id)})]}),e.jsxs("div",{className:"flex flex-wrap gap-1 pt-2 border-t overflow-hidden",children:[e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>xe(ee),className:"text-xs px-2 py-1 h-auto flex-shrink-0",children:[e.jsx(mr,{className:"h-3 w-3 mr-1"}),"编辑"]}),e.jsx(b,{variant:"outline",size:"sm",onClick:()=>ae(ee),className:"text-xs px-2 py-1 h-auto flex-shrink-0",children:e.jsx(Ws,{className:"h-3 w-3"})}),e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>V(ee),className:"text-xs px-2 py-1 h-auto flex-shrink-0 text-destructive hover:text-destructive",children:[e.jsx(at,{className:"h-3 w-3 mr-1"}),"删除"]})]})]},ee.id))}),h>0&&e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4 px-4 py-3 border-t",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["共 ",h," 条记录,第 ",f," / ",Math.ceil(h/p)," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(b,{variant:"outline",size:"sm",onClick:()=>j(1),disabled:f===1,className:"hidden sm:flex",children:e.jsx(vr,{className:"h-4 w-4"})}),e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>j(f-1),disabled:f===1,children:[e.jsx(dn,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"上一页"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ce,{type:"number",value:fe,onChange:ee=>Ce(ee.target.value),onKeyDown:ee=>ee.key==="Enter"&&U(),placeholder:f.toString(),className:"w-16 h-8 text-center",min:1,max:Math.ceil(h/p)}),e.jsx(b,{variant:"outline",size:"sm",onClick:U,disabled:!fe,className:"h-8",children:"跳转"})]}),e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>j(f+1),disabled:f>=Math.ceil(h/p),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Ll,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(b,{variant:"outline",size:"sm",onClick:()=>j(Math.ceil(h/p)),disabled:f>=Math.ceil(h/p),className:"hidden sm:flex",children:e.jsx(br,{className:"h-4 w-4"})})]})]})]})]})}),e.jsx(Qw,{expression:S,open:L,onOpenChange:F,chatNameMap:A}),e.jsx(Yw,{open:K,onOpenChange:H,chatList:Ne,onSuccess:()=>{te(),_(),H(!1)}}),e.jsx(Xw,{expression:S,open:B,onOpenChange:O,chatList:Ne,onSuccess:()=>{te(),_(),O(!1)}}),e.jsx(bt,{open:!!z,onOpenChange:()=>V(null),children:e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认删除"}),e.jsxs(xt,{children:['确定要删除表达方式 "',z?.situation,'" 吗? 此操作不可撤销。']})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:()=>z&&ve(z),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"删除"})]})]})}),e.jsx(Kw,{open:R,onOpenChange:ne,onConfirm:W,count:Y.size})]})}function Qw({expression:n,open:r,onOpenChange:c,chatNameMap:d}){if(!n)return null;const h=f=>f?new Date(f*1e3).toLocaleString("zh-CN"):"-",x=f=>d.get(f)||f;return e.jsx(Jt,{open:r,onOpenChange:c,children:e.jsxs($t,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Qt,{children:[e.jsx(Yt,{children:"表达方式详情"}),e.jsx(ds,{children:"查看表达方式的完整信息"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(sr,{label:"情境",value:n.situation}),e.jsx(sr,{label:"风格",value:n.style}),e.jsx(sr,{label:"聊天",value:x(n.chat_id)}),e.jsx(sr,{icon:zu,label:"记录ID",value:n.id.toString(),mono:!0})]}),e.jsx("div",{className:"grid grid-cols-2 gap-4",children:e.jsx(sr,{icon:Wn,label:"创建时间",value:h(n.create_date)})})]}),e.jsx(xs,{children:e.jsx(b,{onClick:()=>c(!1),children:"关闭"})})]})})}function sr({icon:n,label:r,value:c,mono:d=!1}){return e.jsxs("div",{className:"space-y-1",children:[e.jsxs(y,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[n&&e.jsx(n,{className:"h-3 w-3"}),r]}),e.jsx("div",{className:Q("text-sm",d&&"font-mono",!c&&"text-muted-foreground"),children:c||"-"})]})}function Yw({open:n,onOpenChange:r,chatList:c,onSuccess:d}){const[h,x]=u.useState({situation:"",style:"",chat_id:""}),[f,j]=u.useState(!1),{toast:p}=Xt(),N=async()=>{if(!h.situation||!h.style||!h.chat_id){p({title:"验证失败",description:"请填写必填字段:情境、风格和聊天",variant:"destructive"});return}try{j(!0),await Hw(h),p({title:"创建成功",description:"表达方式已创建"}),x({situation:"",style:"",chat_id:""}),d()}catch(v){p({title:"创建失败",description:v instanceof Error?v.message:"无法创建表达方式",variant:"destructive"})}finally{j(!1)}};return e.jsx(Jt,{open:n,onOpenChange:r,children:e.jsxs($t,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Qt,{children:[e.jsx(Yt,{children:"新增表达方式"}),e.jsx(ds,{children:"创建新的表达方式记录"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(y,{htmlFor:"situation",children:["情境 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(ce,{id:"situation",value:h.situation,onChange:v=>x({...h,situation:v.target.value}),placeholder:"描述使用场景"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(y,{htmlFor:"style",children:["风格 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(ce,{id:"style",value:h.style,onChange:v=>x({...h,style:v.target.value}),placeholder:"描述表达风格"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(y,{htmlFor:"chat_id",children:["聊天 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(qe,{value:h.chat_id,onValueChange:v=>x({...h,chat_id:v}),children:[e.jsx(Be,{children:e.jsx(Ge,{placeholder:"选择关联的聊天"})}),e.jsx(He,{children:c.map(v=>e.jsx(ie,{value:v.chat_id,children:e.jsxs("span",{className:"truncate",style:{wordBreak:"keep-all"},children:[v.chat_name,v.is_group&&e.jsx("span",{className:"text-muted-foreground ml-1",children:"(群聊)"})]})},v.chat_id))})]})]})]}),e.jsxs(xs,{children:[e.jsx(b,{variant:"outline",onClick:()=>r(!1),children:"取消"}),e.jsx(b,{onClick:N,disabled:f,children:f?"创建中...":"创建"})]})]})})}function Xw({expression:n,open:r,onOpenChange:c,chatList:d,onSuccess:h}){const[x,f]=u.useState({}),[j,p]=u.useState(!1),{toast:N}=Xt();u.useEffect(()=>{n&&f({situation:n.situation,style:n.style,chat_id:n.chat_id})},[n]);const v=async()=>{if(n)try{p(!0),await qw(n.id,x),N({title:"保存成功",description:"表达方式已更新"}),h()}catch(C){N({title:"保存失败",description:C instanceof Error?C.message:"无法更新表达方式",variant:"destructive"})}finally{p(!1)}};return n?e.jsx(Jt,{open:r,onOpenChange:c,children:e.jsxs($t,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Qt,{children:[e.jsx(Yt,{children:"编辑表达方式"}),e.jsx(ds,{children:"修改表达方式的信息"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"edit_situation",children:"情境"}),e.jsx(ce,{id:"edit_situation",value:x.situation||"",onChange:C=>f({...x,situation:C.target.value}),placeholder:"描述使用场景"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"edit_style",children:"风格"}),e.jsx(ce,{id:"edit_style",value:x.style||"",onChange:C=>f({...x,style:C.target.value}),placeholder:"描述表达风格"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"edit_chat_id",children:"聊天"}),e.jsxs(qe,{value:x.chat_id||"",onValueChange:C=>f({...x,chat_id:C}),children:[e.jsx(Be,{children:e.jsx(Ge,{placeholder:"选择关联的聊天"})}),e.jsx(He,{children:d.map(C=>e.jsx(ie,{value:C.chat_id,children:e.jsxs("span",{className:"truncate",style:{wordBreak:"keep-all"},children:[C.chat_name,C.is_group&&e.jsx("span",{className:"text-muted-foreground ml-1",children:"(群聊)"})]})},C.chat_id))})]})]})]}),e.jsxs(xs,{children:[e.jsx(b,{variant:"outline",onClick:()=>c(!1),children:"取消"}),e.jsx(b,{onClick:v,disabled:j,children:j?"保存中...":"保存"})]})]})}):null}function Kw({open:n,onOpenChange:r,onConfirm:c,count:d}){return e.jsx(bt,{open:n,onOpenChange:r,children:e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认批量删除"}),e.jsxs(xt,{children:["您即将删除 ",d," 个表达方式,此操作无法撤销。确定要继续吗?"]})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:c,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"确认删除"})]})]})})}const ri="/api/webui/person";async function Zw(n){const r=new URLSearchParams;n.page&&r.append("page",n.page.toString()),n.page_size&&r.append("page_size",n.page_size.toString()),n.search&&r.append("search",n.search),n.is_known!==void 0&&r.append("is_known",n.is_known.toString()),n.platform&&r.append("platform",n.platform);const c=await Te(`${ri}/list?${r}`,{headers:Rt()});if(!c.ok){const d=await c.json();throw new Error(d.detail||"获取人物列表失败")}return c.json()}async function Jw(n){const r=await Te(`${ri}/${n}`,{headers:Rt()});if(!r.ok){const c=await r.json();throw new Error(c.detail||"获取人物详情失败")}return r.json()}async function Iw(n,r){const c=await Te(`${ri}/${n}`,{method:"PATCH",headers:Rt(),body:JSON.stringify(r)});if(!c.ok){const d=await c.json();throw new Error(d.detail||"更新人物信息失败")}return c.json()}async function Pw(n){const r=await Te(`${ri}/${n}`,{method:"DELETE",headers:Rt()});if(!r.ok){const c=await r.json();throw new Error(c.detail||"删除人物信息失败")}return r.json()}async function Ww(){const n=await Te(`${ri}/stats/summary`,{headers:Rt()});if(!n.ok){const r=await n.json();throw new Error(r.detail||"获取统计数据失败")}return n.json()}async function e1(n){const r=await Te(`${ri}/batch/delete`,{method:"POST",headers:Rt(),body:JSON.stringify({person_ids:n})});if(!r.ok){const c=await r.json();throw new Error(c.detail||"批量删除失败")}return r.json()}function t1(){const[n,r]=u.useState([]),[c,d]=u.useState(!0),[h,x]=u.useState(0),[f,j]=u.useState(1),[p,N]=u.useState(20),[v,C]=u.useState(""),[S,w]=u.useState(void 0),[L,F]=u.useState(void 0),[B,O]=u.useState(null),[K,H]=u.useState(!1),[z,V]=u.useState(!1),[Y,E]=u.useState(null),[R,ne]=u.useState({total:0,known:0,unknown:0,platforms:{}}),[fe,Ce]=u.useState(new Set),[we,pe]=u.useState(!1),[Ne,be]=u.useState(""),{toast:A}=Xt(),X=async()=>{try{d(!0);const U=await Zw({page:f,page_size:p,search:v||void 0,is_known:S,platform:L});r(U.data),x(U.total)}catch(U){A({title:"加载失败",description:U instanceof Error?U.message:"无法加载人物信息",variant:"destructive"})}finally{d(!1)}},T=async()=>{try{const U=await Ww();U?.data&&ne(U.data)}catch(U){console.error("加载统计数据失败:",U)}};u.useEffect(()=>{X(),T()},[f,p,v,S,L]);const te=async U=>{try{const ee=await Jw(U.person_id);O(ee.data),H(!0)}catch(ee){A({title:"加载详情失败",description:ee instanceof Error?ee.message:"无法加载人物详情",variant:"destructive"})}},_=U=>{O(U),V(!0)},me=async U=>{try{await Pw(U.person_id),A({title:"删除成功",description:`已删除人物信息: ${U.person_name||U.nickname||U.user_id}`}),E(null),X(),T()}catch(ee){A({title:"删除失败",description:ee instanceof Error?ee.message:"无法删除人物信息",variant:"destructive"})}},oe=u.useMemo(()=>Object.keys(R.platforms),[R.platforms]),ae=U=>{const ee=new Set(fe);ee.has(U)?ee.delete(U):ee.add(U),Ce(ee)},xe=()=>{fe.size===n.length&&n.length>0?Ce(new Set):Ce(new Set(n.map(U=>U.person_id)))},ve=()=>{if(fe.size===0){A({title:"未选择任何人物",description:"请先选择要删除的人物",variant:"destructive"});return}pe(!0)},de=async()=>{try{const U=await e1(Array.from(fe));A({title:"批量删除完成",description:U.message}),Ce(new Set),pe(!1),X(),T()}catch(U){A({title:"批量删除失败",description:U instanceof Error?U.message:"批量删除失败",variant:"destructive"})}},G=()=>{const U=parseInt(Ne),ee=Math.ceil(h/p);U>=1&&U<=ee?(j(U),be("")):A({title:"无效的页码",description:`请输入1-${ee}之间的页码`,variant:"destructive"})},W=U=>U?new Date(U*1e3).toLocaleString("zh-CN"):"-";return e.jsxs("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:[e.jsx("div",{className:"mb-4 sm:mb-6",children:e.jsx("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl sm:text-3xl font-bold flex items-center gap-2",children:[e.jsx(Au,{className:"h-8 w-8",strokeWidth:2}),"人物信息管理"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"管理麦麦认识的所有人物信息"})]})})}),e.jsx(st,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 pr-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"总人数"}),e.jsx("div",{className:"text-2xl font-bold mt-1",children:R.total})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"已认识"}),e.jsx("div",{className:"text-2xl font-bold mt-1 text-green-600",children:R.known})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"未认识"}),e.jsx("div",{className:"text-2xl font-bold mt-1 text-muted-foreground",children:R.unknown})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx(y,{htmlFor:"search",children:"搜索"}),e.jsxs("div",{className:"relative mt-1.5",children:[e.jsx(zs,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(ce,{id:"search",placeholder:"搜索名称、昵称或用户ID...",value:v,onChange:U=>C(U.target.value),className:"pl-9"})]})]}),e.jsxs("div",{children:[e.jsx(y,{htmlFor:"filter-known",children:"认识状态"}),e.jsxs(qe,{value:S===void 0?"all":S.toString(),onValueChange:U=>{w(U==="all"?void 0:U==="true"),j(1)},children:[e.jsx(Be,{id:"filter-known",className:"mt-1.5",children:e.jsx(Ge,{})}),e.jsxs(He,{children:[e.jsx(ie,{value:"all",children:"全部"}),e.jsx(ie,{value:"true",children:"已认识"}),e.jsx(ie,{value:"false",children:"未认识"})]})]})]}),e.jsxs("div",{children:[e.jsx(y,{htmlFor:"filter-platform",children:"平台"}),e.jsxs(qe,{value:L||"all",onValueChange:U=>{F(U==="all"?void 0:U),j(1)},children:[e.jsx(Be,{id:"filter-platform",className:"mt-1.5",children:e.jsx(Ge,{})}),e.jsxs(He,{children:[e.jsx(ie,{value:"all",children:"全部平台"}),oe.map(U=>e.jsxs(ie,{value:U,children:[U," (",R.platforms[U],")"]},U))]})]})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between gap-3 mt-4 pt-4 border-t",children:[e.jsx("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:fe.size>0&&e.jsxs("span",{children:["已选择 ",fe.size," 个人物"]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{htmlFor:"page-size",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(qe,{value:p.toString(),onValueChange:U=>{N(parseInt(U)),j(1),Ce(new Set)},children:[e.jsx(Be,{id:"page-size",className:"w-20",children:e.jsx(Ge,{})}),e.jsxs(He,{children:[e.jsx(ie,{value:"10",children:"10"}),e.jsx(ie,{value:"20",children:"20"}),e.jsx(ie,{value:"50",children:"50"}),e.jsx(ie,{value:"100",children:"100"})]})]}),fe.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(b,{variant:"outline",size:"sm",onClick:()=>Ce(new Set),children:"取消选择"}),e.jsxs(b,{variant:"destructive",size:"sm",onClick:ve,children:[e.jsx(at,{className:"h-4 w-4 mr-1"}),"批量删除"]})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card",children:[e.jsx("div",{className:"hidden md:block",children:e.jsxs(li,{children:[e.jsx(ni,{children:e.jsxs(_s,{children:[e.jsx(rt,{className:"w-12",children:e.jsx(Cs,{checked:n.length>0&&fe.size===n.length,onCheckedChange:xe,"aria-label":"全选"})}),e.jsx(rt,{children:"状态"}),e.jsx(rt,{children:"名称"}),e.jsx(rt,{children:"昵称"}),e.jsx(rt,{children:"平台"}),e.jsx(rt,{children:"用户ID"}),e.jsx(rt,{children:"最后更新"}),e.jsx(rt,{className:"text-right",children:"操作"})]})}),e.jsx(ii,{children:c?e.jsx(_s,{children:e.jsx(Ze,{colSpan:8,className:"text-center py-8 text-muted-foreground",children:"加载中..."})}):n.length===0?e.jsx(_s,{children:e.jsx(Ze,{colSpan:8,className:"text-center py-8 text-muted-foreground",children:"暂无数据"})}):n.map(U=>e.jsxs(_s,{children:[e.jsx(Ze,{children:e.jsx(Cs,{checked:fe.has(U.person_id),onCheckedChange:()=>ae(U.person_id),"aria-label":`选择 ${U.person_name||U.nickname||U.user_id}`})}),e.jsx(Ze,{children:e.jsx("div",{className:Q("inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium",U.is_known?"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400":"bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-400"),children:U.is_known?"已认识":"未认识"})}),e.jsx(Ze,{className:"font-medium",children:U.person_name||e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsx(Ze,{children:U.nickname||"-"}),e.jsx(Ze,{children:U.platform}),e.jsx(Ze,{className:"font-mono text-sm",children:U.user_id}),e.jsx(Ze,{className:"text-sm text-muted-foreground",children:W(U.last_know)}),e.jsx(Ze,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(b,{variant:"default",size:"sm",onClick:()=>te(U),children:[e.jsx(Ws,{className:"h-4 w-4 mr-1"}),"详情"]}),e.jsxs(b,{variant:"default",size:"sm",onClick:()=>_(U),children:[e.jsx(mr,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsxs(b,{size:"sm",onClick:()=>E(U),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(at,{className:"h-4 w-4 mr-1"}),"删除"]})]})})]},U.id))})]})}),e.jsx("div",{className:"md:hidden space-y-3 p-4",children:c?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):n.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无数据"}):n.map(U=>e.jsxs("div",{className:"rounded-lg border bg-card p-4 space-y-3 overflow-hidden",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Cs,{checked:fe.has(U.person_id),onCheckedChange:()=>ae(U.person_id),className:"mt-1"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:Q("inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium mb-2",U.is_known?"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400":"bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-400"),children:U.is_known?"已认识":"未认识"}),e.jsx("h3",{className:"font-semibold text-sm line-clamp-1 w-full break-all",children:U.person_name||e.jsx("span",{className:"text-muted-foreground",children:"未命名"})}),U.nickname&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1 line-clamp-1 w-full break-all",children:["昵称: ",U.nickname]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"平台"}),e.jsx("p",{className:"font-medium text-xs",children:U.platform})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"用户ID"}),e.jsx("p",{className:"font-mono text-xs truncate",title:U.user_id,children:U.user_id})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"最后更新"}),e.jsx("p",{className:"text-xs",children:W(U.last_know)})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-1 pt-2 border-t overflow-hidden",children:[e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>te(U),className:"text-xs px-2 py-1 h-auto flex-shrink-0",children:[e.jsx(Ws,{className:"h-3 w-3 mr-1"}),"查看"]}),e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>_(U),className:"text-xs px-2 py-1 h-auto flex-shrink-0",children:[e.jsx(mr,{className:"h-3 w-3 mr-1"}),"编辑"]}),e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>E(U),className:"text-xs px-2 py-1 h-auto flex-shrink-0 text-destructive hover:text-destructive",children:[e.jsx(at,{className:"h-3 w-3 mr-1"}),"删除"]})]})]},U.id))}),h>0&&e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4 px-4 py-3 border-t",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["共 ",h," 条记录,第 ",f," / ",Math.ceil(h/p)," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(b,{variant:"outline",size:"sm",onClick:()=>j(1),disabled:f===1,className:"hidden sm:flex",children:e.jsx(vr,{className:"h-4 w-4"})}),e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>j(f-1),disabled:f===1,children:[e.jsx(dn,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"上一页"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ce,{type:"number",value:Ne,onChange:U=>be(U.target.value),onKeyDown:U=>U.key==="Enter"&&G(),placeholder:f.toString(),className:"w-16 h-8 text-center",min:1,max:Math.ceil(h/p)}),e.jsx(b,{variant:"outline",size:"sm",onClick:G,disabled:!Ne,className:"h-8",children:"跳转"})]}),e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>j(f+1),disabled:f>=Math.ceil(h/p),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Ll,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(b,{variant:"outline",size:"sm",onClick:()=>j(Math.ceil(h/p)),disabled:f>=Math.ceil(h/p),className:"hidden sm:flex",children:e.jsx(br,{className:"h-4 w-4"})})]})]})]})]})}),e.jsx(s1,{person:B,open:K,onOpenChange:H}),e.jsx(a1,{person:B,open:z,onOpenChange:V,onSuccess:()=>{X(),T(),V(!1)}}),e.jsx(bt,{open:!!Y,onOpenChange:()=>E(null),children:e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认删除"}),e.jsxs(xt,{children:['确定要删除人物信息 "',Y?.person_name||Y?.nickname||Y?.user_id,'" 吗? 此操作不可撤销。']})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:()=>Y&&me(Y),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"删除"})]})]})}),e.jsx(bt,{open:we,onOpenChange:pe,children:e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"确认批量删除"}),e.jsxs(xt,{children:["确定要删除选中的 ",fe.size," 个人物信息吗? 此操作不可撤销。"]})]}),e.jsxs(mt,{children:[e.jsx(pt,{children:"取消"}),e.jsx(ft,{onClick:de,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"批量删除"})]})]})})]})}function s1({person:n,open:r,onOpenChange:c}){if(!n)return null;const d=h=>h?new Date(h*1e3).toLocaleString("zh-CN"):"-";return e.jsx(Jt,{open:r,onOpenChange:c,children:e.jsxs($t,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Qt,{children:[e.jsx(Yt,{children:"人物详情"}),e.jsxs(ds,{children:["查看 ",n.person_name||n.nickname||n.user_id," 的完整信息"]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(nl,{icon:Ic,label:"人物名称",value:n.person_name}),e.jsx(nl,{icon:cn,label:"昵称",value:n.nickname}),e.jsx(nl,{icon:zu,label:"用户ID",value:n.user_id,mono:!0}),e.jsx(nl,{icon:zu,label:"人物ID",value:n.person_id,mono:!0}),e.jsx(nl,{label:"平台",value:n.platform}),e.jsx(nl,{label:"状态",value:n.is_known?"已认识":"未认识"})]}),n.name_reason&&e.jsxs("div",{className:"rounded-lg border bg-muted/50 p-3",children:[e.jsx(y,{className:"text-xs text-muted-foreground",children:"名称设定原因"}),e.jsx("p",{className:"mt-1 text-sm",children:n.name_reason})]}),n.memory_points&&e.jsxs("div",{className:"rounded-lg border bg-muted/50 p-3",children:[e.jsx(y,{className:"text-xs text-muted-foreground",children:"个人印象"}),e.jsx("p",{className:"mt-1 text-sm whitespace-pre-wrap",children:n.memory_points})]}),n.group_nick_name&&n.group_nick_name.length>0&&e.jsxs("div",{className:"rounded-lg border bg-muted/50 p-3",children:[e.jsx(y,{className:"text-xs text-muted-foreground",children:"群昵称"}),e.jsx("div",{className:"mt-2 space-y-1",children:n.group_nick_name.map((h,x)=>e.jsxs("div",{className:"text-sm flex items-center gap-2",children:[e.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:h.group_id}),e.jsx("span",{children:"→"}),e.jsx("span",{children:h.group_nick_name})]},x))})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsx(nl,{icon:Wn,label:"认识时间",value:d(n.know_times)}),e.jsx(nl,{icon:Wn,label:"首次记录",value:d(n.know_since)}),e.jsx(nl,{icon:Wn,label:"最后更新",value:d(n.last_know)})]})]}),e.jsx(xs,{children:e.jsx(b,{onClick:()=>c(!1),children:"关闭"})})]})})}function nl({icon:n,label:r,value:c,mono:d=!1}){return e.jsxs("div",{className:"space-y-1",children:[e.jsxs(y,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[n&&e.jsx(n,{className:"h-3 w-3"}),r]}),e.jsx("div",{className:Q("text-sm",d&&"font-mono",!c&&"text-muted-foreground"),children:c||"-"})]})}function a1({person:n,open:r,onOpenChange:c,onSuccess:d}){const[h,x]=u.useState({}),[f,j]=u.useState(!1),{toast:p}=Xt();u.useEffect(()=>{n&&x({person_name:n.person_name||"",name_reason:n.name_reason||"",nickname:n.nickname||"",memory_points:n.memory_points||"",is_known:n.is_known})},[n]);const N=async()=>{if(n)try{j(!0),await Iw(n.person_id,h),p({title:"保存成功",description:"人物信息已更新"}),d()}catch(v){p({title:"保存失败",description:v instanceof Error?v.message:"无法更新人物信息",variant:"destructive"})}finally{j(!1)}};return n?e.jsx(Jt,{open:r,onOpenChange:c,children:e.jsxs($t,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Qt,{children:[e.jsx(Yt,{children:"编辑人物信息"}),e.jsxs(ds,{children:["修改 ",n.person_name||n.nickname||n.user_id," 的信息"]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"person_name",children:"人物名称"}),e.jsx(ce,{id:"person_name",value:h.person_name||"",onChange:v=>x({...h,person_name:v.target.value}),placeholder:"为这个人设置一个名称"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"nickname",children:"昵称"}),e.jsx(ce,{id:"nickname",value:h.nickname||"",onChange:v=>x({...h,nickname:v.target.value}),placeholder:"昵称"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"name_reason",children:"名称设定原因"}),e.jsx(Ft,{id:"name_reason",value:h.name_reason||"",onChange:v=>x({...h,name_reason:v.target.value}),placeholder:"为什么这样称呼这个人?",rows:2})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"memory_points",children:"个人印象"}),e.jsx(Ft,{id:"memory_points",value:h.memory_points||"",onChange:v=>x({...h,memory_points:v.target.value}),placeholder:"对这个人的印象和记忆点...",rows:4})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-3",children:[e.jsxs("div",{children:[e.jsx(y,{htmlFor:"is_known",className:"text-base font-medium",children:"已认识"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"标记是否已经认识这个人"})]}),e.jsx(Qe,{id:"is_known",checked:h.is_known,onCheckedChange:v=>x({...h,is_known:v})})]})]}),e.jsxs(xs,{children:[e.jsx(b,{variant:"outline",onClick:()=>c(!1),children:"取消"}),e.jsx(b,{onClick:N,disabled:f,children:f?"保存中...":"保存"})]})]})}):null}var l1=cN();const dp=ob(l1),Ku="/api/webui";async function n1(n=100,r="all"){const c=`${Ku}/knowledge/graph?limit=${n}&node_type=${r}`,d=await fetch(c);if(!d.ok)throw new Error(`获取知识图谱失败: ${d.status}`);return d.json()}async function i1(){const n=await fetch(`${Ku}/knowledge/stats`);if(!n.ok)throw new Error("获取知识图谱统计信息失败");return n.json()}async function r1(n){const r=await fetch(`${Ku}/knowledge/search?query=${encodeURIComponent(n)}`);if(!r.ok)throw new Error("搜索知识节点失败");return r.json()}const Ag=u.memo(({data:n})=>e.jsxs("div",{className:"px-4 py-2 shadow-md rounded-lg bg-gradient-to-br from-blue-500 to-blue-600 border-2 border-blue-700 min-w-[120px]",children:[e.jsx(Pc,{type:"target",position:Wc.Top}),e.jsx("div",{className:"font-semibold text-white text-sm truncate max-w-[200px]",title:n.content,children:n.label}),e.jsx(Pc,{type:"source",position:Wc.Bottom})]}));Ag.displayName="EntityNode";const Mg=u.memo(({data:n})=>e.jsxs("div",{className:"px-3 py-2 shadow-md rounded-md bg-gradient-to-br from-green-500 to-green-600 border-2 border-green-700 min-w-[100px]",children:[e.jsx(Pc,{type:"target",position:Wc.Top}),e.jsx("div",{className:"font-medium text-white text-xs truncate max-w-[150px]",title:n.content,children:n.label}),e.jsx(Pc,{type:"source",position:Wc.Bottom})]}));Mg.displayName="ParagraphNode";const c1={entity:Ag,paragraph:Mg};function o1(n,r){const c=new dp.graphlib.Graph;c.setDefaultEdgeLabel(()=>({})),c.setGraph({rankdir:"TB",ranksep:100,nodesep:80});const d=[],h=[];return n.forEach(x=>{c.setNode(x.id,{width:150,height:50})}),r.forEach(x=>{c.setEdge(x.source,x.target)}),dp.layout(c),n.forEach(x=>{const f=c.node(x.id);d.push({id:x.id,type:x.type,position:{x:f.x-75,y:f.y-25},data:{label:x.content.slice(0,20)+(x.content.length>20?"...":""),content:x.content}})}),r.forEach((x,f)=>{const j={id:`edge-${f}`,source:x.source,target:x.target,animated:n.length<=200&&x.weight>5,style:{strokeWidth:Math.min(x.weight/2,5),opacity:.6}};x.weight>10&&n.length<100&&(j.label=`${x.weight.toFixed(0)}`),h.push(j)}),{nodes:d,edges:h}}function d1(){const n=fa(),[r,c]=u.useState(!1),[d,h]=u.useState(null),[x,f]=u.useState(""),[j,p]=u.useState("all"),[N,v]=u.useState(50),[C,S]=u.useState("50"),[w,L]=u.useState(!1),[F,B]=u.useState(!0),[O,K]=u.useState(!1),[H,z]=u.useState(!1),[V,Y,E]=oN([]),[R,ne,fe]=dN([]),[Ce,we]=u.useState(0),[pe,Ne]=u.useState(null),[be,A]=u.useState(null),{toast:X}=Xt(),T=u.useCallback(de=>de.type==="entity"?"#6366f1":de.type==="paragraph"?"#10b981":"#6b7280",[]),te=u.useCallback(async(de=!1)=>{try{if(!de&&N>200){z(!0);return}c(!0);const[G,W]=await Promise.all([n1(N,j),i1()]);if(h(W),G.nodes.length===0){X({title:"提示",description:"知识库为空,请先导入知识数据"}),Y([]),ne([]);return}const{nodes:U,edges:ee}=o1(G.nodes,G.edges);Y(U),ne(ee),we(U.length),W&&W.total_nodes>N&&X({title:"提示",description:`知识图谱包含 ${W.total_nodes} 个节点,当前显示 ${U.length} 个`}),X({title:"加载成功",description:`已加载 ${U.length} 个节点,${ee.length} 条边`})}catch(G){console.error("加载知识图谱失败:",G),X({title:"加载失败",description:G instanceof Error?G.message:"未知错误",variant:"destructive"})}finally{c(!1)}},[N,j,X]),_=u.useCallback(async()=>{if(!x.trim()){X({title:"提示",description:"请输入搜索关键词"});return}try{const de=await r1(x);if(de.length===0){X({title:"未找到",description:"没有找到匹配的节点"});return}const G=new Set(de.map(W=>W.id));Y(W=>W.map(U=>({...U,style:{...U.style,opacity:G.has(U.id)?1:.3,filter:G.has(U.id)?"brightness(1.2)":"brightness(0.8)"}}))),X({title:"搜索完成",description:`找到 ${de.length} 个匹配节点`})}catch(de){console.error("搜索失败:",de),X({title:"搜索失败",description:de instanceof Error?de.message:"未知错误",variant:"destructive"})}},[x,X]),me=u.useCallback(()=>{Y(de=>de.map(G=>({...G,style:{...G.style,opacity:1,filter:"brightness(1)"}})))},[]),oe=u.useCallback(()=>{B(!1),K(!0),te()},[te]),ae=u.useCallback(()=>{z(!1),setTimeout(()=>{te(!0)},0)},[te]),xe=u.useCallback((de,G)=>{V.find(U=>U.id===G.id)&&Ne({id:G.id,type:G.type,content:G.data.content})},[V]);u.useEffect(()=>{F||O&&te()},[N,j,F,O]);const ve=u.useCallback((de,G)=>{const W=V.find(Se=>Se.id===G.source),U=V.find(Se=>Se.id===G.target),ee=R.find(Se=>Se.id===G.id);W&&U&&ee&&A({source:{id:W.id,type:W.type,content:W.data.content},target:{id:U.id,type:U.type,content:U.data.content},edge:{source:G.source,target:G.target,weight:parseFloat(G.label||"0")}})},[V,R]);return e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"flex-shrink-0 p-4 border-b bg-background",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"麦麦知识库图谱"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"可视化知识实体与关系网络"})]}),d&&e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsxs(Je,{variant:"outline",className:"gap-1",children:[e.jsx(Zc,{className:"h-3 w-3"}),"节点: ",d.total_nodes]}),e.jsxs(Je,{variant:"outline",className:"gap-1",children:[e.jsx(rg,{className:"h-3 w-3"}),"边: ",d.total_edges]}),e.jsxs(Je,{variant:"outline",className:"gap-1",children:[e.jsx(Ra,{className:"h-3 w-3"}),"实体: ",d.entity_nodes]}),e.jsxs(Je,{variant:"outline",className:"gap-1",children:[e.jsx(Da,{className:"h-3 w-3"}),"段落: ",d.paragraph_nodes]})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 mt-4",children:[e.jsxs("div",{className:"flex-1 flex gap-2",children:[e.jsx(ce,{placeholder:"搜索节点内容...",value:x,onChange:de=>f(de.target.value),onKeyDown:de=>de.key==="Enter"&&_(),className:"flex-1"}),e.jsx(b,{onClick:_,size:"sm",children:e.jsx(zs,{className:"h-4 w-4"})}),e.jsx(b,{onClick:me,variant:"outline",size:"sm",children:"重置"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(qe,{value:j,onValueChange:de=>p(de),children:[e.jsx(Be,{className:"w-[120px]",children:e.jsx(Ge,{})}),e.jsxs(He,{children:[e.jsx(ie,{value:"all",children:"全部节点"}),e.jsx(ie,{value:"entity",children:"仅实体"}),e.jsx(ie,{value:"paragraph",children:"仅段落"})]})]}),e.jsxs(qe,{value:N===1e4?"all":w?"custom":N.toString(),onValueChange:de=>{de==="custom"?(L(!0),S(N.toString())):de==="all"?(L(!1),v(1e4)):(L(!1),v(Number(de)))},children:[e.jsx(Be,{className:"w-[120px]",children:e.jsx(Ge,{})}),e.jsxs(He,{children:[e.jsx(ie,{value:"50",children:"50 节点"}),e.jsx(ie,{value:"100",children:"100 节点"}),e.jsx(ie,{value:"200",children:"200 节点"}),e.jsx(ie,{value:"500",children:"500 节点"}),e.jsx(ie,{value:"1000",children:"1000 节点"}),e.jsx(ie,{value:"all",children:"全部 (最多10000)"}),e.jsx(ie,{value:"custom",children:"自定义..."})]})]}),w&&e.jsx(ce,{type:"number",min:"50",value:C,onChange:de=>S(de.target.value),onBlur:()=>{const de=parseInt(C);!isNaN(de)&&de>=50?v(de):(S("50"),v(50))},onKeyDown:de=>{if(de.key==="Enter"){const G=parseInt(C);!isNaN(G)&&G>=50?v(G):(S("50"),v(50))}},placeholder:"最少50个",className:"w-[120px]"}),e.jsx(b,{onClick:()=>te(),variant:"outline",size:"sm",disabled:r,children:e.jsx(ws,{className:Q("h-4 w-4",r&&"animate-spin")})})]})]})]}),e.jsx("div",{className:"flex-1 relative",children:r?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(ws,{className:"h-8 w-8 animate-spin mx-auto mb-2 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground",children:"加载知识图谱中..."})]})}):V.length===0?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(Zc,{className:"h-12 w-12 mx-auto mb-4 text-muted-foreground"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"知识库为空"}),e.jsx("p",{className:"text-muted-foreground",children:"请先导入知识数据"})]})}):e.jsxs(uN,{nodes:V,edges:R,onNodesChange:E,onEdgesChange:fe,onNodeClick:xe,onEdgeClick:ve,nodeTypes:c1,fitView:!0,minZoom:.05,maxZoom:1.5,defaultViewport:{x:0,y:0,zoom:.5},elevateNodesOnSelect:Ce<=500,nodesDraggable:Ce<=1e3,attributionPosition:"bottom-left",children:[e.jsx(mN,{variant:hN.Dots,gap:12,size:1}),e.jsx(xN,{}),Ce<=500&&e.jsx(fN,{nodeColor:T,nodeBorderRadius:8,pannable:!0,zoomable:!0}),e.jsxs(pN,{position:"top-right",className:"bg-background/95 backdrop-blur-sm rounded-lg border p-3 shadow-lg",children:[e.jsx("div",{className:"text-sm font-semibold mb-2",children:"图例"}),e.jsxs("div",{className:"space-y-2 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-4 h-4 rounded bg-gradient-to-br from-blue-500 to-blue-600 border-2 border-blue-700"}),e.jsx("span",{children:"实体节点"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-4 h-4 rounded bg-gradient-to-br from-green-500 to-green-600 border-2 border-green-700"}),e.jsx("span",{children:"段落节点"})]}),Ce>200&&e.jsxs("div",{className:"mt-2 pt-2 border-t text-yellow-600 dark:text-yellow-500",children:[e.jsx("div",{className:"font-semibold",children:"性能模式"}),e.jsx("div",{children:"已禁用动画"}),Ce>500&&e.jsx("div",{children:"已禁用缩略图"})]})]})]})]})}),e.jsx(Jt,{open:!!pe,onOpenChange:de=>!de&&Ne(null),children:e.jsxs($t,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsx(Qt,{children:e.jsx(Yt,{children:"节点详情"})}),pe&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"grid grid-cols-2 gap-4",children:e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"类型"}),e.jsx("div",{className:"mt-1",children:e.jsx(Je,{variant:pe.type==="entity"?"default":"secondary",children:pe.type==="entity"?"🏷️ 实体":"📄 段落"})})]})}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"ID"}),e.jsx("code",{className:"mt-1 block p-2 bg-muted rounded text-xs break-all",children:pe.id})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"内容"}),e.jsx(st,{className:"mt-1 h-40 p-3 bg-muted rounded",children:e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:pe.content})})]})]})]})}),e.jsx(Jt,{open:!!be,onOpenChange:de=>!de&&A(null),children:e.jsxs($t,{className:"max-w-2xl max-h-[80vh] overflow-hidden flex flex-col",children:[e.jsx(Qt,{children:e.jsx(Yt,{children:"边详情"})}),be&&e.jsx(st,{className:"flex-1 pr-4",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0 p-3 bg-blue-50 dark:bg-blue-950 rounded border-2 border-blue-200 dark:border-blue-800",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"源节点"}),e.jsx("div",{className:"font-medium text-sm mb-2 truncate",children:be.source.content}),e.jsxs("code",{className:"text-xs text-muted-foreground truncate block",children:[be.source.id.slice(0,40),"..."]})]}),e.jsx("div",{className:"text-2xl text-muted-foreground flex-shrink-0",children:"→"}),e.jsxs("div",{className:"flex-1 min-w-0 p-3 bg-green-50 dark:bg-green-950 rounded border-2 border-green-200 dark:border-green-800",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"目标节点"}),e.jsx("div",{className:"font-medium text-sm mb-2 truncate",children:be.target.content}),e.jsxs("code",{className:"text-xs text-muted-foreground truncate block",children:[be.target.id.slice(0,40),"..."]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"权重"}),e.jsx("div",{className:"mt-1",children:e.jsx(Je,{variant:"outline",className:"text-base font-mono",children:be.edge.weight.toFixed(4)})})]})]})})]})}),e.jsx(bt,{open:F,onOpenChange:B,children:e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"加载知识图谱"}),e.jsxs(xt,{children:["知识图谱的动态展示会消耗较多系统资源。",e.jsx("br",{}),"确定要加载知识图谱吗?"]})]}),e.jsxs(mt,{children:[e.jsx(pt,{onClick:()=>n({to:"/"}),children:"取消 (返回首页)"}),e.jsx(ft,{onClick:oe,children:"确认加载"})]})]})}),e.jsx(bt,{open:H,onOpenChange:z,children:e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"⚠️ 节点数量较多"}),e.jsx(xt,{asChild:!0,children:e.jsxs("div",{children:[e.jsxs("p",{children:["您正在尝试加载 ",e.jsx("strong",{className:"text-orange-600",children:N>=1e4?"全部 (最多10000个)":N})," 个节点。"]}),e.jsx("p",{className:"mt-4",children:"节点数量过多可能导致:"}),e.jsxs("ul",{className:"list-disc list-inside mt-2 space-y-1",children:[e.jsx("li",{children:"页面加载时间较长"}),e.jsx("li",{children:"浏览器卡顿或崩溃"}),e.jsx("li",{children:"系统资源占用过高"})]}),e.jsx("p",{className:"mt-4",children:"建议先选择较少的节点数量 (50-200 个)。"})]})})]}),e.jsxs(mt,{children:[e.jsx(pt,{onClick:()=>{z(!1),N>200&&(v(50),L(!1))},children:"取消"}),e.jsx(ft,{onClick:ae,className:"bg-orange-600 hover:bg-orange-700",children:"我了解风险,继续加载"})]})]})})]})}function up({className:n,classNames:r,showOutsideDays:c=!0,captionLayout:d="label",buttonVariant:h="ghost",formatters:x,components:f,...j}){const p=ug();return e.jsx($y,{showOutsideDays:c,className:Q("bg-background group/calendar p-3 [--cell-size:2rem] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent",String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,n),captionLayout:d,formatters:{formatMonthDropdown:N=>N.toLocaleString("default",{month:"short"}),...x},classNames:{root:Q("w-fit",p.root),months:Q("relative flex flex-col gap-4 md:flex-row",p.months),month:Q("flex w-full flex-col gap-4",p.month),nav:Q("absolute inset-x-0 top-0 flex w-full items-center justify-between gap-1",p.nav),button_previous:Q(hr({variant:h}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",p.button_previous),button_next:Q(hr({variant:h}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",p.button_next),month_caption:Q("flex h-[--cell-size] w-full items-center justify-center px-[--cell-size]",p.month_caption),dropdowns:Q("flex h-[--cell-size] w-full items-center justify-center gap-1.5 text-sm font-medium",p.dropdowns),dropdown_root:Q("has-focus:border-ring border-input shadow-xs has-focus:ring-ring/50 has-focus:ring-[3px] relative rounded-md border",p.dropdown_root),dropdown:Q("bg-popover absolute inset-0 opacity-0",p.dropdown),caption_label:Q("select-none font-medium",d==="label"?"text-sm":"[&>svg]:text-muted-foreground flex h-8 items-center gap-1 rounded-md pl-2 pr-1 text-sm [&>svg]:size-3.5",p.caption_label),table:"w-full border-collapse",weekdays:Q("flex",p.weekdays),weekday:Q("text-muted-foreground flex-1 select-none rounded-md text-[0.8rem] font-normal",p.weekday),week:Q("mt-2 flex w-full",p.week),week_number_header:Q("w-[--cell-size] select-none",p.week_number_header),week_number:Q("text-muted-foreground select-none text-[0.8rem]",p.week_number),day:Q("group/day relative aspect-square h-full w-full select-none p-0 text-center [&:first-child[data-selected=true]_button]:rounded-l-md [&:last-child[data-selected=true]_button]:rounded-r-md",p.day),range_start:Q("bg-accent rounded-l-md",p.range_start),range_middle:Q("rounded-none",p.range_middle),range_end:Q("bg-accent rounded-r-md",p.range_end),today:Q("bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none",p.today),outside:Q("text-muted-foreground aria-selected:text-muted-foreground",p.outside),disabled:Q("text-muted-foreground opacity-50",p.disabled),hidden:Q("invisible",p.hidden),...r},components:{Root:({className:N,rootRef:v,...C})=>e.jsx("div",{"data-slot":"calendar",ref:v,className:Q(N),...C}),Chevron:({className:N,orientation:v,...C})=>v==="left"?e.jsx(dn,{className:Q("size-4",N),...C}):v==="right"?e.jsx(Ll,{className:Q("size-4",N),...C}):e.jsx(Rl,{className:Q("size-4",N),...C}),DayButton:u1,WeekNumber:({children:N,...v})=>e.jsx("td",{...v,children:e.jsx("div",{className:"flex size-[--cell-size] items-center justify-center text-center",children:N})}),...f},...j})}function u1({className:n,day:r,modifiers:c,...d}){const h=ug(),x=u.useRef(null);return u.useEffect(()=>{c.focused&&x.current?.focus()},[c.focused]),e.jsx(b,{ref:x,variant:"ghost",size:"icon","data-day":r.date.toLocaleDateString(),"data-selected-single":c.selected&&!c.range_start&&!c.range_end&&!c.range_middle,"data-range-start":c.range_start,"data-range-end":c.range_end,"data-range-middle":c.range_middle,className:Q("data-[selected-single=true]:bg-primary data-[selected-single=true]:text-primary-foreground data-[range-middle=true]:bg-accent data-[range-middle=true]:text-accent-foreground data-[range-start=true]:bg-primary data-[range-start=true]:text-primary-foreground data-[range-end=true]:bg-primary data-[range-end=true]:text-primary-foreground group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-ring/50 flex aspect-square h-auto w-full min-w-[--cell-size] flex-col gap-1 font-normal leading-none data-[range-end=true]:rounded-md data-[range-middle=true]:rounded-none data-[range-start=true]:rounded-md group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:ring-[3px] [&>span]:text-xs [&>span]:opacity-70",h.day,n),...d})}const m1={lessThanXSeconds:{one:"不到 1 秒",other:"不到 {{count}} 秒"},xSeconds:{one:"1 秒",other:"{{count}} 秒"},halfAMinute:"半分钟",lessThanXMinutes:{one:"不到 1 分钟",other:"不到 {{count}} 分钟"},xMinutes:{one:"1 分钟",other:"{{count}} 分钟"},xHours:{one:"1 小时",other:"{{count}} 小时"},aboutXHours:{one:"大约 1 小时",other:"大约 {{count}} 小时"},xDays:{one:"1 天",other:"{{count}} 天"},aboutXWeeks:{one:"大约 1 个星期",other:"大约 {{count}} 个星期"},xWeeks:{one:"1 个星期",other:"{{count}} 个星期"},aboutXMonths:{one:"大约 1 个月",other:"大约 {{count}} 个月"},xMonths:{one:"1 个月",other:"{{count}} 个月"},aboutXYears:{one:"大约 1 年",other:"大约 {{count}} 年"},xYears:{one:"1 年",other:"{{count}} 年"},overXYears:{one:"超过 1 年",other:"超过 {{count}} 年"},almostXYears:{one:"将近 1 年",other:"将近 {{count}} 年"}},h1=(n,r,c)=>{let d;const h=m1[n];return typeof h=="string"?d=h:r===1?d=h.one:d=h.other.replace("{{count}}",String(r)),c?.addSuffix?c.comparison&&c.comparison>0?d+"内":d+"前":d},x1={full:"y'年'M'月'd'日' EEEE",long:"y'年'M'月'd'日'",medium:"yyyy-MM-dd",short:"yy-MM-dd"},f1={full:"zzzz a h:mm:ss",long:"z a h:mm:ss",medium:"a h:mm:ss",short:"a h:mm"},p1={full:"{{date}} {{time}}",long:"{{date}} {{time}}",medium:"{{date}} {{time}}",short:"{{date}} {{time}}"},g1={date:gu({formats:x1,defaultWidth:"full"}),time:gu({formats:f1,defaultWidth:"full"}),dateTime:gu({formats:p1,defaultWidth:"full"})};function mp(n,r,c){const d="eeee p";return mb(n,r,c)?d:n.getTime()>r.getTime()?"'下个'"+d:"'上个'"+d}const j1={lastWeek:mp,yesterday:"'昨天' p",today:"'今天' p",tomorrow:"'明天' p",nextWeek:mp,other:"PP p"},v1=(n,r,c,d)=>{const h=j1[n];return typeof h=="function"?h(r,c,d):h},b1={narrow:["前","公元"],abbreviated:["前","公元"],wide:["公元前","公元"]},y1={narrow:["1","2","3","4"],abbreviated:["第一季","第二季","第三季","第四季"],wide:["第一季度","第二季度","第三季度","第四季度"]},N1={narrow:["一","二","三","四","五","六","七","八","九","十","十一","十二"],abbreviated:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],wide:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"]},w1={narrow:["日","一","二","三","四","五","六"],short:["日","一","二","三","四","五","六"],abbreviated:["周日","周一","周二","周三","周四","周五","周六"],wide:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]},_1={narrow:{am:"上",pm:"下",midnight:"凌晨",noon:"午",morning:"早",afternoon:"下午",evening:"晚",night:"夜"},abbreviated:{am:"上午",pm:"下午",midnight:"凌晨",noon:"中午",morning:"早晨",afternoon:"中午",evening:"晚上",night:"夜间"},wide:{am:"上午",pm:"下午",midnight:"凌晨",noon:"中午",morning:"早晨",afternoon:"中午",evening:"晚上",night:"夜间"}},S1={narrow:{am:"上",pm:"下",midnight:"凌晨",noon:"午",morning:"早",afternoon:"下午",evening:"晚",night:"夜"},abbreviated:{am:"上午",pm:"下午",midnight:"凌晨",noon:"中午",morning:"早晨",afternoon:"中午",evening:"晚上",night:"夜间"},wide:{am:"上午",pm:"下午",midnight:"凌晨",noon:"中午",morning:"早晨",afternoon:"中午",evening:"晚上",night:"夜间"}},C1=(n,r)=>{const c=Number(n);switch(r?.unit){case"date":return c.toString()+"日";case"hour":return c.toString()+"时";case"minute":return c.toString()+"分";case"second":return c.toString()+"秒";default:return"第 "+c.toString()}},k1={ordinalNumber:C1,era:Ii({values:b1,defaultWidth:"wide"}),quarter:Ii({values:y1,defaultWidth:"wide",argumentCallback:n=>n-1}),month:Ii({values:N1,defaultWidth:"wide"}),day:Ii({values:w1,defaultWidth:"wide"}),dayPeriod:Ii({values:_1,defaultWidth:"wide",formattingValues:S1,defaultFormattingWidth:"wide"})},T1=/^(第\s*)?\d+(日|时|分|秒)?/i,E1=/\d+/i,z1={narrow:/^(前)/i,abbreviated:/^(前)/i,wide:/^(公元前|公元)/i},A1={any:[/^(前)/i,/^(公元)/i]},M1={narrow:/^[1234]/i,abbreviated:/^第[一二三四]刻/i,wide:/^第[一二三四]刻钟/i},D1={any:[/(1|一)/i,/(2|二)/i,/(3|三)/i,/(4|四)/i]},O1={narrow:/^(一|二|三|四|五|六|七|八|九|十[二一])/i,abbreviated:/^(一|二|三|四|五|六|七|八|九|十[二一]|\d|1[12])月/i,wide:/^(一|二|三|四|五|六|七|八|九|十[二一])月/i},R1={narrow:[/^一/i,/^二/i,/^三/i,/^四/i,/^五/i,/^六/i,/^七/i,/^八/i,/^九/i,/^十(?!(一|二))/i,/^十一/i,/^十二/i],any:[/^一|1/i,/^二|2/i,/^三|3/i,/^四|4/i,/^五|5/i,/^六|6/i,/^七|7/i,/^八|8/i,/^九|9/i,/^十(?!(一|二))|10/i,/^十一|11/i,/^十二|12/i]},L1={narrow:/^[一二三四五六日]/i,short:/^[一二三四五六日]/i,abbreviated:/^周[一二三四五六日]/i,wide:/^星期[一二三四五六日]/i},U1={any:[/日/i,/一/i,/二/i,/三/i,/四/i,/五/i,/六/i]},B1={any:/^(上午?|下午?|午夜|[中正]午|早上?|下午|晚上?|凌晨|)/i},H1={any:{am:/^上午?/i,pm:/^下午?/i,midnight:/^午夜/i,noon:/^[中正]午/i,morning:/^早上/i,afternoon:/^下午/i,evening:/^晚上?/i,night:/^凌晨/i}},q1={ordinalNumber:hb({matchPattern:T1,parsePattern:E1,valueCallback:n=>parseInt(n,10)}),era:Pi({matchPatterns:z1,defaultMatchWidth:"wide",parsePatterns:A1,defaultParseWidth:"any"}),quarter:Pi({matchPatterns:M1,defaultMatchWidth:"wide",parsePatterns:D1,defaultParseWidth:"any",valueCallback:n=>n+1}),month:Pi({matchPatterns:O1,defaultMatchWidth:"wide",parsePatterns:R1,defaultParseWidth:"any"}),day:Pi({matchPatterns:L1,defaultMatchWidth:"wide",parsePatterns:U1,defaultParseWidth:"any"}),dayPeriod:Pi({matchPatterns:B1,defaultMatchWidth:"any",parsePatterns:H1,defaultParseWidth:"any"})},qc={code:"zh-CN",formatDistance:h1,formatLong:g1,formatRelative:v1,localize:k1,match:q1,options:{weekStartsOn:1,firstWeekContainsDate:4}},Gc={xs:{label:"小",rowHeight:28,class:"text-[10px] sm:text-xs"},sm:{label:"中",rowHeight:36,class:"text-xs sm:text-sm"},base:{label:"大",rowHeight:44,class:"text-sm sm:text-base"}};function G1(){const[n,r]=u.useState([]),[c,d]=u.useState(""),[h,x]=u.useState("all"),[f,j]=u.useState("all"),[p,N]=u.useState(void 0),[v,C]=u.useState(void 0),[S,w]=u.useState(!0),[L,F]=u.useState(!1),[B,O]=u.useState("xs"),[K,H]=u.useState(4),z=u.useRef(null);u.useEffect(()=>{const T=an.getAllLogs();r(T);const te=an.onLog(()=>{r(an.getAllLogs())}),_=an.onConnectionChange(me=>{F(me)});return()=>{te(),_()}},[]);const V=u.useMemo(()=>{const T=new Set(n.map(te=>te.module).filter(te=>te&&te.trim()!==""));return Array.from(T).sort()},[n]),Y=T=>{switch(T){case"DEBUG":return"text-muted-foreground";case"INFO":return"text-blue-500 dark:text-blue-400";case"WARNING":return"text-yellow-600 dark:text-yellow-500";case"ERROR":return"text-red-600 dark:text-red-500";case"CRITICAL":return"text-red-700 dark:text-red-400 font-bold";default:return"text-foreground"}},E=T=>{switch(T){case"DEBUG":return"bg-gray-800/30 dark:bg-gray-800/50";case"INFO":return"bg-blue-900/20 dark:bg-blue-500/20";case"WARNING":return"bg-yellow-900/20 dark:bg-yellow-500/20";case"ERROR":return"bg-red-900/20 dark:bg-red-500/20";case"CRITICAL":return"bg-red-900/30 dark:bg-red-600/30";default:return"bg-gray-800/20 dark:bg-gray-800/30"}},R=()=>{window.location.reload()},ne=()=>{an.clearLogs(),r([])},fe=()=>{const T=pe.map(oe=>`${oe.timestamp} [${oe.level.padEnd(8)}] [${oe.module}] ${oe.message}`).join(` `),te=new Blob([T],{type:"text/plain;charset=utf-8"}),_=URL.createObjectURL(te),me=document.createElement("a");me.href=_,me.download=`logs-${ju(new Date,"yyyy-MM-dd-HHmmss")}.txt`,me.click(),URL.revokeObjectURL(_)},Ce=()=>{w(!S)},we=()=>{N(void 0),C(void 0)},pe=u.useMemo(()=>n.filter(T=>{const te=c===""||T.message.toLowerCase().includes(c.toLowerCase())||T.module.toLowerCase().includes(c.toLowerCase()),_=h==="all"||T.level===h,me=f==="all"||T.module===f;let oe=!0;if(p||v){const ae=new Date(T.timestamp);if(p){const xe=new Date(p);xe.setHours(0,0,0,0),oe=oe&&ae>=xe}if(v){const xe=new Date(v);xe.setHours(23,59,59,999),oe=oe&&ae<=xe}}return te&&_&&me&&oe}),[n,c,h,f,p,v]),Ne=Gc[B].rowHeight+K,be=tb({count:pe.length,getScrollElement:()=>z.current,estimateSize:()=>Ne,overscan:15}),A=u.useRef(!1),X=u.useRef(pe.length);return u.useEffect(()=>{const T=z.current;if(!T)return;const te=()=>{if(A.current)return;const{scrollTop:_,scrollHeight:me,clientHeight:oe}=T,ae=me-_-oe;ae>100&&S?w(!1):ae<50&&!S&&w(!0)};return T.addEventListener("scroll",te,{passive:!0}),()=>T.removeEventListener("scroll",te)},[S]),u.useEffect(()=>{const T=pe.length>X.current;X.current=pe.length,S&&pe.length>0&&T&&(A.current=!0,be.scrollToIndex(pe.length-1,{align:"end",behavior:"auto"}),requestAnimationFrame(()=>{requestAnimationFrame(()=>{A.current=!1})}))},[pe.length,S,be]),e.jsxs("div",{className:"h-full flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex-shrink-0 space-y-4 p-3 sm:p-4 lg:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl sm:text-2xl lg:text-3xl font-bold",children:"日志查看器"}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground mt-1",children:"实时查看和分析麦麦运行日志"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:Q("h-2.5 w-2.5 sm:h-3 sm:w-3 rounded-full",L?"bg-green-500 animate-pulse":"bg-red-500")}),e.jsx("span",{className:"text-xs sm:text-sm text-muted-foreground",children:L?"已连接":"未连接"})]})]}),e.jsx(Ye,{className:"p-3 sm:p-4",children:e.jsxs("div",{className:"flex flex-col gap-3 sm:gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:gap-4",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(zs,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ce,{placeholder:"搜索日志...",value:c,onChange:T=>d(T.target.value),className:"pl-9 h-9 text-sm"})]}),e.jsxs(qe,{value:h,onValueChange:x,children:[e.jsxs(Be,{className:"w-full sm:w-[140px] lg:w-[180px] h-9 text-sm",children:[e.jsx(Eu,{className:"h-4 w-4 mr-2"}),e.jsx(Ge,{placeholder:"级别"})]}),e.jsxs(He,{children:[e.jsx(ie,{value:"all",children:"全部级别"}),e.jsx(ie,{value:"DEBUG",children:"DEBUG"}),e.jsx(ie,{value:"INFO",children:"INFO"}),e.jsx(ie,{value:"WARNING",children:"WARNING"}),e.jsx(ie,{value:"ERROR",children:"ERROR"}),e.jsx(ie,{value:"CRITICAL",children:"CRITICAL"})]})]}),e.jsxs(qe,{value:f,onValueChange:j,children:[e.jsxs(Be,{className:"w-full sm:w-[160px] lg:w-[200px] h-9 text-sm",children:[e.jsx(Eu,{className:"h-4 w-4 mr-2"}),e.jsx(Ge,{placeholder:"模块"})]}),e.jsxs(He,{children:[e.jsx(ie,{value:"all",children:"全部模块"}),V.map(T=>e.jsx(ie,{value:T,children:T},T))]})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:gap-4",children:[e.jsxs(Ua,{children:[e.jsx(Ba,{asChild:!0,children:e.jsxs(b,{variant:"outline",size:"sm",className:Q("w-full sm:w-[200px] lg:w-[240px] justify-start text-left font-normal h-9",!p&&"text-muted-foreground"),children:[e.jsx(Vf,{className:"mr-2 h-4 w-4"}),e.jsx("span",{className:"text-xs sm:text-sm",children:p?ju(p,"PPP",{locale:qc}):"开始日期"})]})}),e.jsx(_a,{className:"w-auto p-0",align:"start",children:e.jsx(up,{mode:"single",selected:p,onSelect:N,initialFocus:!0,locale:qc})})]}),e.jsxs(Ua,{children:[e.jsx(Ba,{asChild:!0,children:e.jsxs(b,{variant:"outline",size:"sm",className:Q("w-full sm:w-[200px] lg:w-[240px] justify-start text-left font-normal h-9",!v&&"text-muted-foreground"),children:[e.jsx(Vf,{className:"mr-2 h-4 w-4"}),e.jsx("span",{className:"text-xs sm:text-sm",children:v?ju(v,"PPP",{locale:qc}):"结束日期"})]})}),e.jsx(_a,{className:"w-auto p-0",align:"start",children:e.jsx(up,{mode:"single",selected:v,onSelect:C,initialFocus:!0,locale:qc})})]}),(p||v)&&e.jsxs(b,{variant:"outline",size:"sm",onClick:we,className:"w-full sm:w-auto h-9",children:[e.jsx(on,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline text-sm",children:"清除时间筛选"}),e.jsx("span",{className:"sm:hidden text-sm",children:"清除"})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:flex-wrap sm:items-center",children:[e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsxs(b,{variant:S?"default":"outline",size:"sm",onClick:Ce,className:"flex-1 sm:flex-none h-9",children:[S?e.jsx(wy,{className:"h-4 w-4"}):e.jsx(_y,{className:"h-4 w-4"}),e.jsx("span",{className:"ml-2 text-sm",children:S?"自动滚动":"已暂停"})]}),e.jsxs(b,{variant:"outline",size:"sm",onClick:R,className:"flex-1 sm:flex-none h-9",children:[e.jsx(ws,{className:"h-4 w-4"}),e.jsx("span",{className:"ml-2 text-sm",children:"刷新"})]}),e.jsxs(b,{variant:"outline",size:"sm",onClick:ne,className:"flex-1 sm:flex-none h-9",children:[e.jsx(at,{className:"h-4 w-4"}),e.jsx("span",{className:"ml-2 text-sm",children:"清空"})]}),e.jsxs(b,{variant:"outline",size:"sm",onClick:fe,className:"flex-1 sm:flex-none h-9",children:[e.jsx(rl,{className:"h-4 w-4"}),e.jsx("span",{className:"ml-2 text-sm",children:"导出"})]})]}),e.jsx("div",{className:"flex-1 hidden sm:block"}),e.jsxs("div",{className:"text-xs sm:text-sm text-muted-foreground flex items-center justify-center sm:justify-end",children:[e.jsxs("span",{className:"font-mono",children:[pe.length," / ",n.length]}),e.jsx("span",{className:"ml-1",children:"条日志"})]})]}),e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:gap-6 pt-2 border-t border-border/50",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(Sy,{className:"h-4 w-4"}),e.jsx("span",{children:"字号"})]}),e.jsx("div",{className:"flex gap-1",children:Object.keys(Gc).map(T=>e.jsx(b,{variant:B===T?"default":"outline",size:"sm",onClick:()=>O(T),className:"h-7 px-3 text-xs",children:Gc[T].label},T))})]}),e.jsxs("div",{className:"flex items-center gap-3 flex-1 max-w-xs",children:[e.jsx("span",{className:"text-sm text-muted-foreground whitespace-nowrap",children:"行距"}),e.jsx(Ma,{value:[K],onValueChange:([T])=>H(T),min:0,max:12,step:2,className:"flex-1"}),e.jsxs("span",{className:"text-xs text-muted-foreground w-8",children:[K,"px"]})]})]})]})})]}),e.jsx("div",{className:"flex-1 min-h-0 px-3 sm:px-4 lg:px-6 pb-3 sm:pb-4 lg:pb-6",children:e.jsx(Ye,{className:"bg-black dark:bg-gray-950 border-gray-800 dark:border-gray-900 h-full",children:e.jsx(st,{viewportRef:z,className:"h-full",children:e.jsx("div",{className:Q("p-2 sm:p-3 font-mono relative",Gc[B].class),style:{height:`${be.getTotalSize()}px`},children:pe.length===0?e.jsx("div",{className:"text-gray-500 dark:text-gray-600 text-center py-8 text-sm",children:"暂无日志数据"}):be.getVirtualItems().map(T=>{const te=pe[T.index];return e.jsxs("div",{"data-index":T.index,ref:be.measureElement,className:Q("absolute top-0 left-0 w-full px-2 sm:px-3 rounded hover:bg-white/5 transition-colors group",E(te.level)),style:{transform:`translateY(${T.start}px)`,paddingTop:`${K/2}px`,paddingBottom:`${K/2}px`},children:[e.jsxs("div",{className:"flex flex-col gap-0.5 sm:hidden",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-gray-500 dark:text-gray-600",children:te.timestamp}),e.jsxs("span",{className:Q("font-semibold",Y(te.level)),children:["[",te.level,"]"]})]}),e.jsx("div",{className:"text-cyan-400 dark:text-cyan-500 truncate",children:te.module}),e.jsx("div",{className:"text-gray-300 dark:text-gray-400 whitespace-pre-wrap break-words",children:te.message})]}),e.jsxs("div",{className:"hidden sm:flex gap-2 items-start",children:[e.jsx("span",{className:"text-gray-500 dark:text-gray-600 flex-shrink-0 w-[130px] lg:w-[160px]",children:te.timestamp}),e.jsxs("span",{className:Q("flex-shrink-0 w-[65px] lg:w-[75px] font-semibold",Y(te.level)),children:["[",te.level,"]"]}),e.jsx("span",{className:"text-cyan-400 dark:text-cyan-500 flex-shrink-0 w-[100px] lg:w-[130px] truncate",children:te.module}),e.jsx("span",{className:"text-gray-300 dark:text-gray-400 flex-1 whitespace-pre-wrap break-words",children:te.message})]})]},T.key)})})})})})]})}const V1="Mai-with-u",F1="plugin-repo",$1="main",Q1="plugin_details.json";async function Y1(){try{const n=await Te("/api/webui/plugins/fetch-raw",{method:"POST",body:JSON.stringify({owner:V1,repo:F1,branch:$1,file_path:Q1})});if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);const r=await n.json();if(!r.success||!r.data)throw new Error(r.error||"获取插件列表失败");return JSON.parse(r.data).filter(h=>!h?.id||!h?.manifest?(console.warn("跳过无效插件数据:",h),!1):!h.manifest.name||!h.manifest.version?(console.warn("跳过缺少必需字段的插件:",h.id),!1):!0).map(h=>({id:h.id,manifest:{manifest_version:h.manifest.manifest_version||1,name:h.manifest.name,version:h.manifest.version,description:h.manifest.description||"",author:h.manifest.author||{name:"Unknown"},license:h.manifest.license||"Unknown",host_application:h.manifest.host_application||{min_version:"0.0.0"},homepage_url:h.manifest.homepage_url,repository_url:h.manifest.repository_url,keywords:h.manifest.keywords||[],categories:h.manifest.categories||[],default_locale:h.manifest.default_locale||"zh-CN",locales_path:h.manifest.locales_path},downloads:0,rating:0,review_count:0,installed:!1,published_at:new Date().toISOString(),updated_at:new Date().toISOString()}))}catch(n){throw console.error("Failed to fetch plugin list:",n),n}}async function X1(){try{const n=await Te("/api/webui/plugins/git-status");if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);return await n.json()}catch(n){return console.error("Failed to check Git status:",n),{installed:!1,error:"无法检测 Git 安装状态"}}}async function K1(){try{const n=await Te("/api/webui/plugins/version");if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);return await n.json()}catch(n){return console.error("Failed to get Maimai version:",n),{version:"0.0.0",version_major:0,version_minor:0,version_patch:0}}}function Z1(n,r,c){const d=n.split(".").map(j=>parseInt(j)||0),h=d[0]||0,x=d[1]||0,f=d[2]||0;if(c.version_majorparseInt(C)||0),p=j[0]||0,N=j[1]||0,v=j[2]||0;if(c.version_major>p||c.version_major===p&&c.version_minor>N||c.version_major===p&&c.version_minor===N&&c.version_patch>v)return!1}return!0}function J1(n,r){const c=window.location.protocol==="https:"?"wss:":"ws:",d=window.location.host,h=new WebSocket(`${c}//${d}/api/webui/ws/plugin-progress`);return h.onopen=()=>{console.log("Plugin progress WebSocket connected");const x=setInterval(()=>{h.readyState===WebSocket.OPEN?h.send("ping"):clearInterval(x)},3e4)},h.onmessage=x=>{try{if(x.data==="pong")return;const f=JSON.parse(x.data);n(f)}catch(f){console.error("Failed to parse progress data:",f)}},h.onerror=x=>{console.error("Plugin progress WebSocket error:",x),r?.(x)},h.onclose=()=>{console.log("Plugin progress WebSocket disconnected")},h}async function nr(){try{const n=await Te("/api/webui/plugins/installed",{headers:Rt()});if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);const r=await n.json();if(!r.success)throw new Error(r.message||"获取已安装插件列表失败");return r.plugins||[]}catch(n){return console.error("Failed to get installed plugins:",n),[]}}function Vc(n,r){return r.some(c=>c.id===n)}function Fc(n,r){const c=r.find(d=>d.id===n);if(c)return c.manifest?.version||c.version}async function I1(n,r,c="main"){const d=await Te("/api/webui/plugins/install",{method:"POST",body:JSON.stringify({plugin_id:n,repository_url:r,branch:c})});if(!d.ok){const h=await d.json();throw new Error(h.detail||"安装失败")}return await d.json()}async function P1(n){const r=await Te("/api/webui/plugins/uninstall",{method:"POST",body:JSON.stringify({plugin_id:n})});if(!r.ok){const c=await r.json();throw new Error(c.detail||"卸载失败")}return await r.json()}async function W1(n,r,c="main"){const d=await Te("/api/webui/plugins/update",{method:"POST",body:JSON.stringify({plugin_id:n,repository_url:r,branch:c})});if(!d.ok){const h=await d.json();throw new Error(h.detail||"更新失败")}return await d.json()}async function e2(n){const r=await Te(`/api/webui/plugins/config/${n}/schema`,{headers:Rt()});if(!r.ok){const d=await r.json();throw new Error(d.detail||"获取配置 Schema 失败")}const c=await r.json();if(!c.success)throw new Error(c.message||"获取配置 Schema 失败");return c.schema}async function t2(n){const r=await Te(`/api/webui/plugins/config/${n}`,{headers:Rt()});if(!r.ok){const d=await r.json();throw new Error(d.detail||"获取配置失败")}const c=await r.json();if(!c.success)throw new Error(c.message||"获取配置失败");return c.config}async function s2(n,r){const c=await Te(`/api/webui/plugins/config/${n}`,{method:"PUT",body:JSON.stringify({config:r})});if(!c.ok){const d=await c.json();throw new Error(d.detail||"保存配置失败")}return await c.json()}async function a2(n){const r=await Te(`/api/webui/plugins/config/${n}/reset`,{method:"POST",headers:Rt()});if(!r.ok){const c=await r.json();throw new Error(c.detail||"重置配置失败")}return await r.json()}async function l2(n){const r=await Te(`/api/webui/plugins/config/${n}/toggle`,{method:"POST",headers:Rt()});if(!r.ok){const c=await r.json();throw new Error(c.detail||"切换状态失败")}return await r.json()}const Nr="https://maibot-plugin-stats.maibot-webui.workers.dev";async function Dg(n){try{const r=await fetch(`${Nr}/stats/${n}`);return r.ok?await r.json():(console.error("Failed to fetch plugin stats:",r.statusText),null)}catch(r){return console.error("Error fetching plugin stats:",r),null}}async function n2(n,r){try{const c=r||Zu(),d=await fetch(`${Nr}/stats/like`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:n,user_id:c})}),h=await d.json();return d.status===429?{success:!1,error:"操作过于频繁,请稍后再试"}:d.ok?{success:!0,...h}:{success:!1,error:h.error||"点赞失败"}}catch(c){return console.error("Error liking plugin:",c),{success:!1,error:"网络错误"}}}async function i2(n,r){try{const c=r||Zu(),d=await fetch(`${Nr}/stats/dislike`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:n,user_id:c})}),h=await d.json();return d.status===429?{success:!1,error:"操作过于频繁,请稍后再试"}:d.ok?{success:!0,...h}:{success:!1,error:h.error||"点踩失败"}}catch(c){return console.error("Error disliking plugin:",c),{success:!1,error:"网络错误"}}}async function r2(n,r,c,d){if(r<1||r>5)return{success:!1,error:"评分必须在 1-5 之间"};try{const h=d||Zu(),x=await fetch(`${Nr}/stats/rate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:n,rating:r,comment:c,user_id:h})}),f=await x.json();return x.status===429?{success:!1,error:"每天最多评分 3 次"}:x.ok?{success:!0,...f}:{success:!1,error:f.error||"评分失败"}}catch(h){return console.error("Error rating plugin:",h),{success:!1,error:"网络错误"}}}async function c2(n){try{const r=await fetch(`${Nr}/stats/download`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:n})}),c=await r.json();return r.status===429?(console.warn("Download recording rate limited"),{success:!0}):r.ok?{success:!0,...c}:(console.error("Failed to record download:",c.error),{success:!1,error:c.error})}catch(r){return console.error("Error recording download:",r),{success:!1,error:"网络错误"}}}function o2(){const n=navigator,r=[navigator.userAgent,navigator.language,navigator.languages?.join(",")||"",navigator.platform,navigator.hardwareConcurrency||0,screen.width,screen.height,screen.colorDepth,screen.pixelDepth,new Date().getTimezoneOffset(),Intl.DateTimeFormat().resolvedOptions().timeZone,navigator.maxTouchPoints||0,n.deviceMemory||0].join("|");let c=0;for(let d=0;d{x(!0);const O=await Dg(n);O&&d(O),x(!1)};u.useEffect(()=>{w()},[n]);const L=async()=>{const O=await n2(n);O.success?(S({title:"已点赞",description:"感谢你的支持!"}),w()):S({title:"点赞失败",description:O.error||"未知错误",variant:"destructive"})},F=async()=>{const O=await i2(n);O.success?(S({title:"已反馈",description:"感谢你的反馈!"}),w()):S({title:"操作失败",description:O.error||"未知错误",variant:"destructive"})},B=async()=>{if(f===0){S({title:"请选择评分",description:"至少选择 1 颗星",variant:"destructive"});return}const O=await r2(n,f,p||void 0);O.success?(S({title:"评分成功",description:"感谢你的评价!"}),C(!1),j(0),N(""),w()):S({title:"评分失败",description:O.error||"未知错误",variant:"destructive"})};return h?e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(rl,{className:"h-4 w-4"}),e.jsx("span",{children:"-"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Ol,{className:"h-4 w-4"}),e.jsx("span",{children:"-"})]})]}):c?r?e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",title:`下载量: ${c.downloads.toLocaleString()}`,children:[e.jsx(rl,{className:"h-4 w-4"}),e.jsx("span",{children:c.downloads.toLocaleString()})]}),e.jsxs("div",{className:"flex items-center gap-1",title:`评分: ${c.rating.toFixed(1)} (${c.rating_count} 条评价)`,children:[e.jsx(Ol,{className:"h-4 w-4 fill-yellow-400 text-yellow-400"}),e.jsx("span",{children:c.rating.toFixed(1)})]}),e.jsxs("div",{className:"flex items-center gap-1",title:`点赞数: ${c.likes}`,children:[e.jsx(bu,{className:"h-4 w-4"}),e.jsx("span",{children:c.likes})]})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(rl,{className:"h-5 w-5 text-muted-foreground mb-1"}),e.jsx("span",{className:"text-2xl font-bold",children:c.downloads.toLocaleString()}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"下载量"})]}),e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(Ol,{className:"h-5 w-5 text-yellow-400 mb-1 fill-yellow-400"}),e.jsx("span",{className:"text-2xl font-bold",children:c.rating.toFixed(1)}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[c.rating_count," 条评价"]})]}),e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(bu,{className:"h-5 w-5 text-green-500 mb-1"}),e.jsx("span",{className:"text-2xl font-bold",children:c.likes}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"点赞"})]}),e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(Ff,{className:"h-5 w-5 text-red-500 mb-1"}),e.jsx("span",{className:"text-2xl font-bold",children:c.dislikes}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"点踩"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(b,{variant:"outline",size:"sm",onClick:L,children:[e.jsx(bu,{className:"h-4 w-4 mr-1"}),"点赞"]}),e.jsxs(b,{variant:"outline",size:"sm",onClick:F,children:[e.jsx(Ff,{className:"h-4 w-4 mr-1"}),"点踩"]}),e.jsxs(Jt,{open:v,onOpenChange:C,children:[e.jsx($u,{asChild:!0,children:e.jsxs(b,{variant:"default",size:"sm",children:[e.jsx(Ol,{className:"h-4 w-4 mr-1"}),"评分"]})}),e.jsxs($t,{children:[e.jsxs(Qt,{children:[e.jsx(Yt,{children:"为插件评分"}),e.jsx(ds,{children:"分享你的使用体验,帮助其他用户"})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx("div",{className:"flex gap-2",children:[1,2,3,4,5].map(O=>e.jsx("button",{onClick:()=>j(O),className:"focus:outline-none",children:e.jsx(Ol,{className:`h-8 w-8 transition-colors ${O<=f?"fill-yellow-400 text-yellow-400":"text-muted-foreground hover:text-yellow-300"}`})},O))}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[f===0&&"点击星星进行评分",f===1&&"很差",f===2&&"一般",f===3&&"还行",f===4&&"不错",f===5&&"非常好"]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium mb-2 block",children:"评论(可选)"}),e.jsx(Ft,{value:p,onChange:O=>N(O.target.value),placeholder:"分享你的使用体验...",rows:4,maxLength:500}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1 text-right",children:[p.length," / 500"]})]})]}),e.jsxs(xs,{children:[e.jsx(b,{variant:"outline",onClick:()=>C(!1),children:"取消"}),e.jsx(b,{onClick:B,disabled:f===0,children:"提交评分"})]})]})]})]}),c.recent_ratings&&c.recent_ratings.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-sm font-semibold",children:"最近评价"}),e.jsx("div",{className:"space-y-3",children:c.recent_ratings.map((O,K)=>e.jsxs("div",{className:"p-3 rounded-lg border bg-muted/50",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("div",{className:"flex gap-1",children:[1,2,3,4,5].map(H=>e.jsx(Ol,{className:`h-3 w-3 ${H<=O.rating?"fill-yellow-400 text-yellow-400":"text-muted-foreground"}`},H))}),e.jsx("span",{className:"text-xs text-muted-foreground",children:new Date(O.created_at).toLocaleDateString()})]}),O.comment&&e.jsx("p",{className:"text-sm text-muted-foreground",children:O.comment})]},K))})]})]}):null}const hp={"Group Management":"群组管理","Entertainment & Interaction":"娱乐互动","Utility Tools":"实用工具","Content Generation":"内容生成",Multimedia:"多媒体","External Integration":"外部集成","Data Analysis & Insights":"数据分析与洞察",Other:"其他"};function u2(){const n=fa(),[r,c]=u.useState(null),[d,h]=u.useState(""),[x,f]=u.useState("all"),[j,p]=u.useState("all"),[N,v]=u.useState(!0),[C,S]=u.useState([]),[w,L]=u.useState(!0),[F,B]=u.useState(null),[O,K]=u.useState(null),[H,z]=u.useState(null),[V,Y]=u.useState(null),[,E]=u.useState([]),[R,ne]=u.useState({}),{toast:fe}=Xt(),Ce=async _=>{const me=_.map(async xe=>{try{const ve=await Dg(xe.id);return{id:xe.id,stats:ve}}catch(ve){return console.warn(`Failed to load stats for ${xe.id}:`,ve),{id:xe.id,stats:null}}}),oe=await Promise.all(me),ae={};oe.forEach(({id:xe,stats:ve})=>{ve&&(ae[xe]=ve)}),ne(ae)};u.useEffect(()=>{let _=null,me=!1;return(async()=>{if(_=J1(ae=>{me||(z(ae),ae.stage==="success"?setTimeout(()=>{me||z(null)},2e3):ae.stage==="error"&&(L(!1),B(ae.error||"加载失败")))},ae=>{console.error("WebSocket error:",ae),me||fe({title:"WebSocket 连接失败",description:"无法实时显示加载进度",variant:"destructive"})}),await new Promise(ae=>{if(!_){ae();return}const xe=()=>{_&&_.readyState===WebSocket.OPEN?(console.log("WebSocket connected, starting to load plugins"),ae()):_&&_.readyState===WebSocket.CLOSED?(console.warn("WebSocket closed before loading plugins"),ae()):setTimeout(xe,100)};xe()}),!me){const ae=await X1();K(ae),ae.installed||fe({title:"Git 未安装",description:ae.error||"请先安装 Git 才能使用插件安装功能",variant:"destructive"})}if(!me){const ae=await K1();Y(ae)}if(!me)try{L(!0),B(null);const ae=await Y1();if(!me){const xe=await nr();E(xe);const ve=ae.map(de=>{const G=Vc(de.id,xe),W=Fc(de.id,xe);return{...de,installed:G,installed_version:W}});for(const de of xe)!ve.some(W=>W.id===de.id)&&de.manifest&&ve.push({id:de.id,manifest:{manifest_version:de.manifest.manifest_version||1,name:de.manifest.name,version:de.manifest.version,description:de.manifest.description||"",author:de.manifest.author,license:de.manifest.license||"Unknown",host_application:de.manifest.host_application,homepage_url:de.manifest.homepage_url,repository_url:de.manifest.repository_url,keywords:de.manifest.keywords||[],categories:de.manifest.categories||[],default_locale:de.manifest.default_locale||"zh-CN",locales_path:de.manifest.locales_path},downloads:0,rating:0,review_count:0,installed:!0,installed_version:de.manifest.version,published_at:new Date().toISOString(),updated_at:new Date().toISOString()});S(ve),Ce(ve)}}catch(ae){if(!me){const xe=ae instanceof Error?ae.message:"加载插件列表失败";B(xe),fe({title:"加载失败",description:xe,variant:"destructive"})}}finally{me||L(!1)}})(),()=>{me=!0,_&&_.close()}},[fe]);const we=_=>{if(!_.installed&&V&&!pe(_))return e.jsxs(Je,{variant:"destructive",className:"gap-1",children:[e.jsx(Oa,{className:"h-3 w-3"}),"不兼容"]});if(_.installed){const me=_.installed_version?.trim(),oe=_.manifest.version?.trim();if(me!==oe){const ae=me?.split(".").map(Number)||[0,0,0],xe=oe?.split(".").map(Number)||[0,0,0];for(let ve=0;ve<3;ve++){if((xe[ve]||0)>(ae[ve]||0))return e.jsxs(Je,{variant:"outline",className:"gap-1 text-orange-600 border-orange-600",children:[e.jsx(Oa,{className:"h-3 w-3"}),"可更新"]});if((xe[ve]||0)<(ae[ve]||0))break}}return e.jsxs(Je,{variant:"default",className:"gap-1",children:[e.jsx(ha,{className:"h-3 w-3"}),"已安装"]})}return null},pe=_=>!V||!_.manifest?.host_application?!0:Z1(_.manifest.host_application.min_version,_.manifest.host_application.max_version,V),Ne=_=>{if(!_.installed||!_.installed_version||!_.manifest?.version)return!1;const me=_.installed_version.trim(),oe=_.manifest.version.trim();if(me===oe)return!1;const ae=me.split(".").map(Number),xe=oe.split(".").map(Number);for(let ve=0;ve<3;ve++){if((xe[ve]||0)>(ae[ve]||0))return!0;if((xe[ve]||0)<(ae[ve]||0))return!1}return!1},be=C.filter(_=>{if(!_.manifest)return console.warn("[过滤] 跳过无 manifest 的插件:",_.id),!1;const me=d===""||_.manifest.name?.toLowerCase().includes(d.toLowerCase())||_.manifest.description?.toLowerCase().includes(d.toLowerCase())||_.manifest.keywords&&_.manifest.keywords.some(ve=>ve.toLowerCase().includes(d.toLowerCase())),oe=x==="all"||_.manifest.categories&&_.manifest.categories.includes(x);let ae=!0;j==="installed"?ae=_.installed===!0:j==="updates"&&(ae=_.installed===!0&&Ne(_));const xe=!N||!V||pe(_);return me&&oe&&ae&&xe}),A=()=>{c(null)},X=async _=>{if(!O?.installed){fe({title:"无法安装",description:"Git 未安装",variant:"destructive"});return}if(V&&!pe(_)){fe({title:"无法安装",description:"插件与当前麦麦版本不兼容",variant:"destructive"});return}try{await I1(_.id,_.manifest.repository_url||"","main"),c2(_.id).catch(oe=>{console.warn("Failed to record download:",oe)}),fe({title:"安装成功",description:`${_.manifest.name} 已成功安装`});const me=await nr();E(me),S(oe=>oe.map(ae=>{if(ae.id===_.id){const xe=Vc(ae.id,me),ve=Fc(ae.id,me);return{...ae,installed:xe,installed_version:ve}}return ae}))}catch(me){fe({title:"安装失败",description:me instanceof Error?me.message:"未知错误",variant:"destructive"})}},T=async _=>{try{await P1(_.id),fe({title:"卸载成功",description:`${_.manifest.name} 已成功卸载`});const me=await nr();E(me),S(oe=>oe.map(ae=>{if(ae.id===_.id){const xe=Vc(ae.id,me),ve=Fc(ae.id,me);return{...ae,installed:xe,installed_version:ve}}return ae}))}catch(me){fe({title:"卸载失败",description:me instanceof Error?me.message:"未知错误",variant:"destructive"})}},te=async _=>{if(!O?.installed){fe({title:"无法更新",description:"Git 未安装",variant:"destructive"});return}try{const me=await W1(_.id,_.manifest.repository_url||"","main");fe({title:"更新成功",description:`${_.manifest.name} 已从 ${me.old_version} 更新到 ${me.new_version}`});const oe=await nr();E(oe),S(ae=>ae.map(xe=>{if(xe.id===_.id){const ve=Vc(xe.id,oe),de=Fc(xe.id,oe);return{...xe,installed:ve,installed_version:de}}return xe}))}catch(me){fe({title:"更新失败",description:me instanceof Error?me.message:"未知错误",variant:"destructive"})}};return e.jsx(st,{className:"h-full",children:e.jsxs("div",{className:"space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"插件市场"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"浏览和管理麦麦的插件"})]}),e.jsxs(b,{onClick:()=>n({to:"/plugin-mirrors"}),children:[e.jsx(Cy,{className:"h-4 w-4 mr-2"}),"配置镜像源"]})]}),O&&!O.installed&&e.jsxs(Ye,{className:"border-orange-600 bg-orange-50 dark:bg-orange-950/20",children:[e.jsx(Nt,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ya,{className:"h-5 w-5 text-orange-600"}),e.jsxs("div",{children:[e.jsx(wt,{className:"text-lg text-orange-900 dark:text-orange-100",children:"Git 未安装"}),e.jsx(ns,{className:"text-orange-800 dark:text-orange-200",children:O.error||"请先安装 Git 才能使用插件安装功能"})]})]})}),e.jsx(kt,{children:e.jsxs("p",{className:"text-sm text-orange-800 dark:text-orange-200",children:["您可以从 ",e.jsx("a",{href:"https://git-scm.com/downloads",target:"_blank",rel:"noopener noreferrer",className:"underline font-medium",children:"git-scm.com"})," 下载并安装 Git。 安装完成后,请重启麦麦应用。"]})})]}),e.jsx(Ye,{className:"p-4",children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row gap-4",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(zs,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ce,{placeholder:"搜索插件...",value:d,onChange:_=>h(_.target.value),className:"pl-9"})]}),e.jsxs(qe,{value:x,onValueChange:f,children:[e.jsx(Be,{className:"w-full sm:w-[200px]",children:e.jsx(Ge,{placeholder:"选择分类"})}),e.jsxs(He,{children:[e.jsx(ie,{value:"all",children:"全部分类"}),e.jsx(ie,{value:"Group Management",children:"群组管理"}),e.jsx(ie,{value:"Entertainment & Interaction",children:"娱乐互动"}),e.jsx(ie,{value:"Utility Tools",children:"实用工具"}),e.jsx(ie,{value:"Content Generation",children:"内容生成"}),e.jsx(ie,{value:"Multimedia",children:"多媒体"}),e.jsx(ie,{value:"External Integration",children:"外部集成"}),e.jsx(ie,{value:"Data Analysis & Insights",children:"数据分析与洞察"}),e.jsx(ie,{value:"Other",children:"其他"})]})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Cs,{id:"compatible-only",checked:N,onCheckedChange:_=>v(_===!0)}),e.jsx("label",{htmlFor:"compatible-only",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 cursor-pointer",children:"只显示兼容当前版本的插件"})]})]})}),e.jsx(La,{value:j,onValueChange:p,className:"w-full",children:e.jsxs(wa,{className:"grid w-full grid-cols-3",children:[e.jsxs(it,{value:"all",children:["全部插件 (",C.filter(_=>{if(!_.manifest)return!1;const me=d===""||_.manifest.name?.toLowerCase().includes(d.toLowerCase())||_.manifest.description?.toLowerCase().includes(d.toLowerCase())||_.manifest.keywords&&_.manifest.keywords.some(xe=>xe.toLowerCase().includes(d.toLowerCase())),oe=x==="all"||_.manifest.categories&&_.manifest.categories.includes(x),ae=!N||!V||pe(_);return me&&oe&&ae}).length,")"]}),e.jsxs(it,{value:"installed",children:["已安装 (",C.filter(_=>{if(!_.manifest)return!1;const me=d===""||_.manifest.name?.toLowerCase().includes(d.toLowerCase())||_.manifest.description?.toLowerCase().includes(d.toLowerCase())||_.manifest.keywords&&_.manifest.keywords.some(xe=>xe.toLowerCase().includes(d.toLowerCase())),oe=x==="all"||_.manifest.categories&&_.manifest.categories.includes(x),ae=!N||!V||pe(_);return _.installed&&me&&oe&&ae}).length,")"]}),e.jsxs(it,{value:"updates",children:["可更新 (",C.filter(_=>{if(!_.manifest)return!1;const me=d===""||_.manifest.name?.toLowerCase().includes(d.toLowerCase())||_.manifest.description?.toLowerCase().includes(d.toLowerCase())||_.manifest.keywords&&_.manifest.keywords.some(xe=>xe.toLowerCase().includes(d.toLowerCase())),oe=x==="all"||_.manifest.categories&&_.manifest.categories.includes(x),ae=!N||!V||pe(_);return _.installed&&Ne(_)&&me&&oe&&ae}).length,")"]})]})}),H&&H.stage==="loading"&&e.jsx(Ye,{className:"p-4",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ss,{className:"h-4 w-4 animate-spin"}),e.jsxs("span",{className:"text-sm font-medium",children:[H.operation==="fetch"&&"加载插件列表",H.operation==="install"&&`安装插件${H.plugin_id?`: ${H.plugin_id}`:""}`,H.operation==="uninstall"&&`卸载插件${H.plugin_id?`: ${H.plugin_id}`:""}`,H.operation==="update"&&`更新插件${H.plugin_id?`: ${H.plugin_id}`:""}`]})]}),e.jsxs("span",{className:"text-sm font-medium",children:[H.progress,"%"]})]}),e.jsx(yr,{value:H.progress,className:"h-2"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:H.message}),H.operation==="fetch"&&H.total_plugins>0&&e.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:["已加载 ",H.loaded_plugins," / ",H.total_plugins," 个插件"]})]})}),H&&H.stage==="error"&&H.error&&e.jsx(Ye,{className:"border-destructive bg-destructive/10",children:e.jsx(Nt,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ya,{className:"h-5 w-5 text-destructive"}),e.jsxs("div",{children:[e.jsx(wt,{className:"text-lg text-destructive",children:"加载失败"}),e.jsx(ns,{className:"text-destructive/80",children:H.error})]})]})})}),w?e.jsxs("div",{className:"flex items-center justify-center py-12",children:[e.jsx(Ss,{className:"h-8 w-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"加载插件列表中..."})]}):F?e.jsx(Ye,{className:"p-6",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(ya,{className:"h-12 w-12 text-destructive mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"加载失败"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:F}),e.jsx(b,{onClick:()=>window.location.reload(),children:"重新加载"})]})}):be.length===0?e.jsx(Ye,{className:"p-6",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(zs,{className:"h-12 w-12 text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"未找到插件"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:d||x!=="all"?"尝试调整搜索条件或筛选器":"暂无可用插件"})]})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:be.map(_=>e.jsxs(Ye,{className:"flex flex-col hover:shadow-lg transition-shadow h-full",children:[e.jsxs(Nt,{children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx(wt,{className:"text-xl",children:_.manifest?.name||_.id}),e.jsxs("div",{className:"flex flex-col gap-1",children:[_.manifest?.categories&&_.manifest.categories[0]&&e.jsx(Je,{variant:"secondary",className:"text-xs whitespace-nowrap",children:hp[_.manifest.categories[0]]||_.manifest.categories[0]}),we(_)]})]}),e.jsx(ns,{className:"line-clamp-2",children:_.manifest?.description||"无描述"})]}),e.jsx(kt,{className:"flex-1",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(rl,{className:"h-4 w-4"}),e.jsx("span",{children:(R[_.id]?.downloads??_.downloads??0).toLocaleString()})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Ol,{className:"h-4 w-4 fill-yellow-400 text-yellow-400"}),e.jsx("span",{children:(R[_.id]?.rating??_.rating??0).toFixed(1)})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[_.manifest?.keywords&&_.manifest.keywords.slice(0,3).map(me=>e.jsx(Je,{variant:"outline",className:"text-xs",children:me},me)),_.manifest?.keywords&&_.manifest.keywords.length>3&&e.jsxs(Je,{variant:"outline",className:"text-xs",children:["+",_.manifest.keywords.length-3]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground pt-2 border-t space-y-1",children:[e.jsxs("div",{children:["v",_.manifest?.version||"unknown"," · ",_.manifest?.author?.name||"Unknown"]}),_.manifest?.host_application&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{children:"支持:"}),e.jsxs("span",{className:"font-medium",children:[_.manifest.host_application.min_version,_.manifest.host_application.max_version?` - ${_.manifest.host_application.max_version}`:" - 最新版本"]})]})]})]})}),e.jsx(mg,{className:"pt-4",children:e.jsxs("div",{className:"flex items-center justify-end gap-2 w-full",children:[e.jsx(b,{variant:"outline",size:"sm",onClick:()=>c(_),children:"查看详情"}),_.installed?Ne(_)?e.jsxs(b,{size:"sm",disabled:!O?.installed,title:O?.installed?void 0:"Git 未安装",onClick:()=>te(_),children:[e.jsx(ws,{className:"h-4 w-4 mr-1"}),"更新"]}):e.jsxs(b,{variant:"destructive",size:"sm",disabled:!O?.installed,title:O?.installed?void 0:"Git 未安装",onClick:()=>T(_),children:[e.jsx(at,{className:"h-4 w-4 mr-1"}),"卸载"]}):e.jsxs(b,{size:"sm",disabled:!O?.installed||H?.operation==="install"||V!==null&&!pe(_),title:O?.installed?V!==null&&!pe(_)?`不兼容当前版本 (需要 ${_.manifest?.host_application?.min_version||"未知"}${_.manifest?.host_application?.max_version?` - ${_.manifest.host_application.max_version}`:"+"},当前 ${V?.version})`:void 0:"Git 未安装",onClick:()=>X(_),children:[e.jsx(rl,{className:"h-4 w-4 mr-1"}),H?.operation==="install"&&H?.plugin_id===_.id?"安装中...":"安装"]})]})})]},_.id))}),e.jsx(Jt,{open:r!==null,onOpenChange:A,children:r&&r.manifest&&e.jsx($t,{className:"max-w-2xl max-h-[80vh] p-0 flex flex-col",children:e.jsx(st,{className:"flex-1 overflow-auto",children:e.jsxs("div",{className:"p-6",children:[e.jsx(Qt,{children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-2 flex-1",children:[e.jsx(Yt,{className:"text-2xl",children:r.manifest.name}),e.jsxs(ds,{children:["作者: ",r.manifest.author?.name||"Unknown",r.manifest.author?.url&&e.jsx("a",{href:r.manifest.author.url,target:"_blank",rel:"noopener noreferrer",className:"ml-2 text-primary hover:underline",children:e.jsx(Qc,{className:"h-3 w-3 inline"})})]})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[r.manifest.categories&&r.manifest.categories[0]&&e.jsx(Je,{variant:"secondary",children:hp[r.manifest.categories[0]]||r.manifest.categories[0]}),we(r)]})]})}),e.jsxs("div",{className:"space-y-6",children:[e.jsx(d2,{pluginId:r.id}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"版本"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["v",r.manifest?.version||"unknown"]}),r.installed&&r.installed_version&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["已安装: v",r.installed_version]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"下载量"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:(R[r.id]?.downloads??r.downloads??0).toLocaleString()})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"评分"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Ol,{className:"h-4 w-4 fill-yellow-400 text-yellow-400"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[(R[r.id]?.rating??r.rating??0).toFixed(1)," (",R[r.id]?.rating_count??r.review_count??0,")"]})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"许可证"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:r.manifest.license||"Unknown"})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("p",{className:"text-sm font-medium",children:"支持版本"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[r.manifest.host_application?.min_version||"未知",r.manifest.host_application?.max_version?` - ${r.manifest.host_application.max_version}`:" - 最新版本"]})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:"关键词"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:r.manifest.keywords&&r.manifest.keywords.map(_=>e.jsx(Je,{variant:"outline",children:_},_))})]}),r.detailed_description&&e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:"详细说明"}),e.jsx("p",{className:"text-sm text-muted-foreground whitespace-pre-line",children:r.detailed_description})]}),!r.detailed_description&&e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:"说明"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:r.manifest.description||"无描述"})]}),e.jsxs("div",{className:"space-y-2",children:[r.manifest.homepage_url&&e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"font-medium",children:"主页: "}),e.jsx("a",{href:r.manifest.homepage_url,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:r.manifest.homepage_url})]}),r.manifest.repository_url&&e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"font-medium",children:"仓库: "}),e.jsx("a",{href:r.manifest.repository_url,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:r.manifest.repository_url})]})]})]}),e.jsxs(xs,{children:[r.manifest.homepage_url&&e.jsxs(b,{onClick:()=>window.open(r.manifest.homepage_url,"_blank"),children:[e.jsx(Qc,{className:"h-4 w-4 mr-2"}),"访问主页"]}),r.manifest.repository_url&&e.jsxs(b,{variant:"outline",onClick:()=>window.open(r.manifest.repository_url,"_blank"),children:[e.jsx(Qc,{className:"h-4 w-4 mr-2"}),"查看仓库"]})]})]})})})})]})})}const Ru=Eb,Lu=zb,Uu=Ab;function m2({field:n,value:r,onChange:c}){const[d,h]=u.useState(!1);switch(n.ui_type){case"switch":return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(y,{children:n.label}),n.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:n.hint})]}),e.jsx(Qe,{checked:!!r,onCheckedChange:c,disabled:n.disabled})]});case"number":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:n.label}),e.jsx(ce,{type:"number",value:r??n.default,onChange:x=>c(parseFloat(x.target.value)||0),min:n.min,max:n.max,step:n.step??1,placeholder:n.placeholder,disabled:n.disabled}),n.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:n.hint})]});case"slider":return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(y,{children:n.label}),e.jsx("span",{className:"text-sm text-muted-foreground",children:r??n.default})]}),e.jsx(Ma,{value:[r??n.default],onValueChange:x=>c(x[0]),min:n.min??0,max:n.max??100,step:n.step??1,disabled:n.disabled}),n.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:n.hint})]});case"select":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:n.label}),e.jsxs(qe,{value:String(r??n.default),onValueChange:c,disabled:n.disabled,children:[e.jsx(Be,{children:e.jsx(Ge,{placeholder:n.placeholder??"请选择"})}),e.jsx(He,{children:n.choices?.map(x=>e.jsx(ie,{value:String(x),children:String(x)},String(x)))})]}),n.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:n.hint})]});case"textarea":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:n.label}),e.jsx(Ft,{value:r??n.default,onChange:x=>c(x.target.value),placeholder:n.placeholder,rows:n.rows??3,disabled:n.disabled}),n.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:n.hint})]});case"password":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:n.label}),e.jsxs("div",{className:"relative",children:[e.jsx(ce,{type:d?"text":"password",value:r??"",onChange:x=>c(x.target.value),placeholder:n.placeholder,disabled:n.disabled,className:"pr-10"}),e.jsx(b,{type:"button",variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-full px-3",onClick:()=>h(!d),children:d?e.jsx(or,{className:"h-4 w-4"}):e.jsx(Ws,{className:"h-4 w-4"})})]}),n.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:n.hint})]});case"text":default:return e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:n.label}),e.jsx(ce,{type:"text",value:r??n.default??"",onChange:x=>c(x.target.value),placeholder:n.placeholder,maxLength:n.max_length,disabled:n.disabled}),n.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:n.hint})]})}}function xp({section:n,config:r,onChange:c}){const[d,h]=u.useState(!n.collapsed),x=Object.entries(n.fields).filter(([,f])=>!f.hidden).sort(([,f],[,j])=>f.order-j.order);return e.jsx(Ru,{open:d,onOpenChange:h,children:e.jsxs(Ye,{children:[e.jsx(Lu,{asChild:!0,children:e.jsxs(Nt,{className:"cursor-pointer hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[d?e.jsx(Rl,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Ll,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(wt,{className:"text-lg",children:n.title})]}),e.jsxs(Je,{variant:"secondary",className:"text-xs",children:[x.length," 项"]})]}),n.description&&e.jsx(ns,{className:"ml-6",children:n.description})]})}),e.jsx(Uu,{children:e.jsx(kt,{className:"space-y-4 pt-0",children:x.map(([f,j])=>e.jsx(m2,{field:j,value:r[n.name]?.[f],onChange:p=>c(n.name,f,p),sectionName:n.name},f))})})]})})}function h2({plugin:n,onBack:r}){const{toast:c}=Xt(),[d,h]=u.useState(null),[x,f]=u.useState({}),[j,p]=u.useState({}),[N,v]=u.useState(!0),[C,S]=u.useState(!1),[w,L]=u.useState(!1),[F,B]=u.useState(!1),O=u.useCallback(async()=>{v(!0);try{const[R,ne]=await Promise.all([e2(n.id),t2(n.id)]);h(R),f(ne),p(JSON.parse(JSON.stringify(ne)))}catch(R){c({title:"加载配置失败",description:R instanceof Error?R.message:"未知错误",variant:"destructive"})}finally{v(!1)}},[n.id,c]);u.useEffect(()=>{O()},[O]),u.useEffect(()=>{L(JSON.stringify(x)!==JSON.stringify(j))},[x,j]);const K=(R,ne,fe)=>{f(Ce=>({...Ce,[R]:{...Ce[R]||{},[ne]:fe}}))},H=async()=>{S(!0);try{await s2(n.id,x),p(JSON.parse(JSON.stringify(x))),c({title:"配置已保存",description:"更改将在插件重新加载后生效"})}catch(R){c({title:"保存失败",description:R instanceof Error?R.message:"未知错误",variant:"destructive"})}finally{S(!1)}},z=async()=>{try{await a2(n.id),c({title:"配置已重置",description:"下次加载插件时将使用默认配置"}),B(!1),O()}catch(R){c({title:"重置失败",description:R instanceof Error?R.message:"未知错误",variant:"destructive"})}},V=async()=>{try{const R=await l2(n.id);c({title:R.message,description:R.note}),O()}catch(R){c({title:"切换状态失败",description:R instanceof Error?R.message:"未知错误",variant:"destructive"})}};if(N)return e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(Ss,{className:"h-8 w-8 animate-spin text-muted-foreground"})});if(!d)return e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 space-y-4",children:[e.jsx(Oa,{className:"h-12 w-12 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground",children:"无法加载配置"}),e.jsxs(b,{onClick:r,variant:"outline",children:[e.jsx(ti,{className:"h-4 w-4 mr-2"}),"返回"]})]});const Y=Object.values(d.sections).sort((R,ne)=>R.order-ne.order),E=x.plugin?.enabled!==!1;return e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start sm:justify-between gap-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(b,{variant:"ghost",size:"icon",onClick:r,children:e.jsx(ti,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:d.plugin_info.name||n.manifest.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx(Je,{variant:E?"default":"secondary",children:E?"已启用":"已禁用"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["v",d.plugin_info.version||n.manifest.version]})]})]})]}),e.jsxs("div",{className:"flex gap-2 ml-10 sm:ml-0",children:[e.jsxs(b,{variant:"outline",size:"sm",onClick:V,children:[e.jsx(gr,{className:"h-4 w-4 mr-2"}),E?"禁用":"启用"]}),e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>B(!0),children:[e.jsx(Kc,{className:"h-4 w-4 mr-2"}),"重置"]}),e.jsxs(b,{size:"sm",onClick:H,disabled:!w||C,children:[C?e.jsx(Ss,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(jr,{className:"h-4 w-4 mr-2"}),"保存"]})]})]}),w&&e.jsx(Ye,{className:"border-orange-200 bg-orange-50 dark:bg-orange-950/20 dark:border-orange-900",children:e.jsx(kt,{className:"py-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ra,{className:"h-4 w-4 text-orange-600"}),e.jsx("p",{className:"text-sm text-orange-800 dark:text-orange-200",children:"有未保存的更改"})]})})}),d.layout.type==="tabs"&&d.layout.tabs.length>0?e.jsxs(La,{defaultValue:d.layout.tabs[0]?.id,children:[e.jsx(wa,{children:d.layout.tabs.map(R=>e.jsxs(it,{value:R.id,children:[R.title,R.badge&&e.jsx(Je,{variant:"secondary",className:"ml-2 text-xs",children:R.badge})]},R.id))}),d.layout.tabs.map(R=>e.jsx(zt,{value:R.id,className:"space-y-4 mt-4",children:R.sections.map(ne=>{const fe=d.sections[ne];return fe?e.jsx(xp,{section:fe,config:x,onChange:K},ne):null})},R.id))]}):e.jsx("div",{className:"space-y-4",children:Y.map(R=>e.jsx(xp,{section:R,config:x,onChange:K},R.name))}),e.jsx(Jt,{open:F,onOpenChange:B,children:e.jsxs($t,{children:[e.jsxs(Qt,{children:[e.jsx(Yt,{children:"确认重置配置"}),e.jsx(ds,{children:"这将删除当前配置文件,下次加载插件时将使用默认配置。此操作不可撤销。"})]}),e.jsxs(xs,{children:[e.jsx(b,{variant:"outline",onClick:()=>B(!1),children:"取消"}),e.jsx(b,{variant:"destructive",onClick:z,children:"确认重置"})]})]})})]})}function x2(){const{toast:n}=Xt(),[r,c]=u.useState([]),[d,h]=u.useState(!0),[x,f]=u.useState(""),[j,p]=u.useState(null),N=async()=>{h(!0);try{const w=await nr();c(w)}catch(w){n({title:"加载插件列表失败",description:w instanceof Error?w.message:"未知错误",variant:"destructive"})}finally{h(!1)}};u.useEffect(()=>{N()},[]);const v=r.filter(w=>{const L=x.toLowerCase();return w.id.toLowerCase().includes(L)||w.manifest.name.toLowerCase().includes(L)||w.manifest.description?.toLowerCase().includes(L)}),C=r.length,S=0;return j?e.jsx(st,{className:"h-full",children:e.jsx("div",{className:"p-4 sm:p-6",children:e.jsx(h2,{plugin:j,onBack:()=>p(null)})})}):e.jsx(st,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"插件配置"}),e.jsx("p",{className:"text-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:"管理和配置已安装的插件"})]}),e.jsxs(b,{variant:"outline",size:"sm",onClick:N,children:[e.jsx(ws,{className:`h-4 w-4 mr-2 ${d?"animate-spin":""}`}),"刷新"]})]}),e.jsxs("div",{className:"grid gap-4 grid-cols-1 xs:grid-cols-2 lg:grid-cols-3",children:[e.jsxs(Ye,{children:[e.jsxs(Nt,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(wt,{className:"text-sm font-medium",children:"已安装插件"}),e.jsx(rn,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(kt,{children:[e.jsx("div",{className:"text-2xl font-bold",children:r.length}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:d?"正在加载...":"个插件"})]})]}),e.jsxs(Ye,{children:[e.jsxs(Nt,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(wt,{className:"text-sm font-medium",children:"已启用"}),e.jsx(ha,{className:"h-4 w-4 text-green-600"})]}),e.jsxs(kt,{children:[e.jsx("div",{className:"text-2xl font-bold",children:C}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"运行中的插件"})]})]}),e.jsxs(Ye,{children:[e.jsxs(Nt,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(wt,{className:"text-sm font-medium",children:"已禁用"}),e.jsx(Oa,{className:"h-4 w-4 text-orange-600"})]}),e.jsxs(kt,{children:[e.jsx("div",{className:"text-2xl font-bold",children:S}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"未激活的插件"})]})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(zs,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ce,{placeholder:"搜索插件...",value:x,onChange:w=>f(w.target.value),className:"pl-9"})]}),e.jsxs(Ye,{children:[e.jsxs(Nt,{children:[e.jsx(wt,{children:"已安装的插件"}),e.jsx(ns,{children:"点击插件查看和编辑配置"})]}),e.jsx(kt,{children:d?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(Ss,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):v.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 space-y-4",children:[e.jsx(rn,{className:"h-16 w-16 text-muted-foreground/50"}),e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx("p",{className:"text-lg font-medium text-muted-foreground",children:x?"没有找到匹配的插件":"暂无已安装的插件"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:x?"尝试其他搜索关键词":"前往插件市场安装插件"})]})]}):e.jsx("div",{className:"space-y-2",children:v.map(w=>e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg border hover:bg-muted/50 cursor-pointer transition-colors",onClick:()=>p(w),children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("div",{className:"h-10 w-10 rounded-lg bg-primary/10 flex items-center justify-center flex-shrink-0",children:e.jsx(rn,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"font-medium truncate",children:w.manifest.name}),e.jsxs(Je,{variant:"secondary",className:"text-xs flex-shrink-0",children:["v",w.manifest.version]})]}),e.jsx("p",{className:"text-sm text-muted-foreground truncate",children:w.manifest.description||"暂无描述"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(b,{variant:"ghost",size:"sm",children:e.jsx(ai,{className:"h-4 w-4"})}),e.jsx(Ll,{className:"h-4 w-4 text-muted-foreground"})]})]},w.id))})})]})]})})}function f2(){const n=fa(),{toast:r}=Xt(),[c,d]=u.useState([]),[h,x]=u.useState(!0),[f,j]=u.useState(null),[p,N]=u.useState(null),[v,C]=u.useState(!1),[S,w]=u.useState(!1),[L,F]=u.useState({id:"",name:"",raw_prefix:"",clone_prefix:"",enabled:!0,priority:1}),B=u.useCallback(async()=>{try{x(!0),j(null);const E=localStorage.getItem("access-token"),R=await fetch("/api/webui/plugins/mirrors",{headers:{Authorization:`Bearer ${E}`}});if(!R.ok)throw new Error("获取镜像源列表失败");const ne=await R.json();d(ne.mirrors||[])}catch(E){const R=E instanceof Error?E.message:"加载镜像源失败";j(R),r({title:"加载失败",description:R,variant:"destructive"})}finally{x(!1)}},[r]);u.useEffect(()=>{B()},[B]);const O=async()=>{try{const E=localStorage.getItem("access-token"),R=await fetch("/api/webui/plugins/mirrors",{method:"POST",headers:{Authorization:`Bearer ${E}`,"Content-Type":"application/json"},body:JSON.stringify(L)});if(!R.ok){const ne=await R.json();throw new Error(ne.detail||"添加镜像源失败")}r({title:"添加成功",description:"镜像源已添加"}),C(!1),F({id:"",name:"",raw_prefix:"",clone_prefix:"",enabled:!0,priority:1}),B()}catch(E){r({title:"添加失败",description:E instanceof Error?E.message:"未知错误",variant:"destructive"})}},K=async()=>{if(p)try{const E=localStorage.getItem("access-token");if(!(await fetch(`/api/webui/plugins/mirrors/${p.id}`,{method:"PUT",headers:{Authorization:`Bearer ${E}`,"Content-Type":"application/json"},body:JSON.stringify({name:L.name,raw_prefix:L.raw_prefix,clone_prefix:L.clone_prefix,enabled:L.enabled,priority:L.priority})})).ok)throw new Error("更新镜像源失败");r({title:"更新成功",description:"镜像源已更新"}),w(!1),N(null),B()}catch(E){r({title:"更新失败",description:E instanceof Error?E.message:"未知错误",variant:"destructive"})}},H=async E=>{if(confirm("确定要删除这个镜像源吗?"))try{const R=localStorage.getItem("access-token");if(!(await fetch(`/api/webui/plugins/mirrors/${E}`,{method:"DELETE",headers:{Authorization:`Bearer ${R}`}})).ok)throw new Error("删除镜像源失败");r({title:"删除成功",description:"镜像源已删除"}),B()}catch(R){r({title:"删除失败",description:R instanceof Error?R.message:"未知错误",variant:"destructive"})}},z=async E=>{try{const R=localStorage.getItem("access-token");if(!(await fetch(`/api/webui/plugins/mirrors/${E.id}`,{method:"PUT",headers:{Authorization:`Bearer ${R}`,"Content-Type":"application/json"},body:JSON.stringify({enabled:!E.enabled})})).ok)throw new Error("更新状态失败");B()}catch(R){r({title:"更新失败",description:R instanceof Error?R.message:"未知错误",variant:"destructive"})}},V=E=>{N(E),F({id:E.id,name:E.name,raw_prefix:E.raw_prefix,clone_prefix:E.clone_prefix,enabled:E.enabled,priority:E.priority}),w(!0)},Y=async(E,R)=>{const ne=R==="up"?E.priority-1:E.priority+1;if(!(ne<1))try{const fe=localStorage.getItem("access-token");if(!(await fetch(`/api/webui/plugins/mirrors/${E.id}`,{method:"PUT",headers:{Authorization:`Bearer ${fe}`,"Content-Type":"application/json"},body:JSON.stringify({priority:ne})})).ok)throw new Error("更新优先级失败");B()}catch(fe){r({title:"更新失败",description:fe instanceof Error?fe.message:"未知错误",variant:"destructive"})}};return e.jsx(st,{className:"h-full",children:e.jsxs("div",{className:"space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(b,{variant:"ghost",size:"icon",onClick:()=>n({to:"/plugins"}),children:e.jsx(ti,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"镜像源配置"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"管理 Git 克隆和文件下载的镜像源"})]})]}),e.jsxs(b,{onClick:()=>C(!0),children:[e.jsx(hs,{className:"h-4 w-4 mr-2"}),"添加镜像源"]})]}),h?e.jsx(Ye,{className:"p-6",children:e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(Ss,{className:"h-8 w-8 animate-spin text-primary"})})}):f?e.jsx(Ye,{className:"p-6",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(ya,{className:"h-12 w-12 text-destructive mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"加载失败"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:f}),e.jsx(b,{onClick:B,children:"重新加载"})]})}):e.jsxs(Ye,{children:[e.jsx("div",{className:"hidden md:block",children:e.jsxs(li,{children:[e.jsx(ni,{children:e.jsxs(_s,{children:[e.jsx(rt,{children:"状态"}),e.jsx(rt,{children:"名称"}),e.jsx(rt,{children:"ID"}),e.jsx(rt,{children:"优先级"}),e.jsx(rt,{className:"text-right",children:"操作"})]})}),e.jsx(ii,{children:c.map(E=>e.jsxs(_s,{children:[e.jsx(Ze,{children:e.jsx(Qe,{checked:E.enabled,onCheckedChange:()=>z(E)})}),e.jsx(Ze,{children:e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:E.name}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:["Raw: ",E.raw_prefix]})]})}),e.jsx(Ze,{children:e.jsx(Je,{variant:"outline",children:E.id})}),e.jsx(Ze,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-mono",children:E.priority}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(b,{variant:"ghost",size:"icon",className:"h-5 w-5",onClick:()=>Y(E,"up"),disabled:E.priority===1,children:e.jsx(ur,{className:"h-3 w-3"})}),e.jsx(b,{variant:"ghost",size:"icon",className:"h-5 w-5",onClick:()=>Y(E,"down"),children:e.jsx(Rl,{className:"h-3 w-3"})})]})]})}),e.jsx(Ze,{className:"text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(b,{variant:"ghost",size:"icon",onClick:()=>V(E),children:e.jsx(nn,{className:"h-4 w-4"})}),e.jsx(b,{variant:"ghost",size:"icon",onClick:()=>H(E.id),children:e.jsx(at,{className:"h-4 w-4 text-destructive"})})]})})]},E.id))})]})}),e.jsx("div",{className:"md:hidden p-4 space-y-4",children:c.map(E=>e.jsx(Ye,{className:"p-4",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"font-semibold",children:E.name}),E.enabled&&e.jsx(Je,{variant:"default",className:"text-xs",children:"启用"})]}),e.jsx(Je,{variant:"outline",className:"mt-1 text-xs",children:E.id})]}),e.jsx(Qe,{checked:E.enabled,onCheckedChange:()=>z(E)})]}),e.jsxs("div",{className:"text-sm space-y-1",children:[e.jsxs("div",{className:"text-muted-foreground",children:[e.jsx("span",{className:"font-medium",children:"Raw: "}),e.jsx("span",{className:"break-all",children:E.raw_prefix})]}),e.jsxs("div",{className:"text-muted-foreground",children:[e.jsx("span",{className:"font-medium",children:"优先级: "}),e.jsx("span",{className:"font-mono",children:E.priority})]})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-2 border-t",children:[e.jsxs(b,{variant:"outline",size:"sm",className:"flex-1",onClick:()=>V(E),children:[e.jsx(nn,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsx(b,{variant:"outline",size:"sm",onClick:()=>Y(E,"up"),disabled:E.priority===1,children:e.jsx(ur,{className:"h-4 w-4"})}),e.jsx(b,{variant:"outline",size:"sm",onClick:()=>Y(E,"down"),children:e.jsx(Rl,{className:"h-4 w-4"})}),e.jsx(b,{variant:"destructive",size:"sm",onClick:()=>H(E.id),children:e.jsx(at,{className:"h-4 w-4"})})]})]})},E.id))})]}),e.jsx(Jt,{open:v,onOpenChange:C,children:e.jsxs($t,{className:"max-w-lg",children:[e.jsxs(Qt,{children:[e.jsx(Yt,{children:"添加镜像源"}),e.jsx(ds,{children:"添加新的 Git 镜像源配置"})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"add-id",children:"镜像源 ID *"}),e.jsx(ce,{id:"add-id",placeholder:"例如: my-mirror",value:L.id,onChange:E=>F({...L,id:E.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"add-name",children:"名称 *"}),e.jsx(ce,{id:"add-name",placeholder:"例如: 我的镜像源",value:L.name,onChange:E=>F({...L,name:E.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"add-raw",children:"Raw 文件前缀 *"}),e.jsx(ce,{id:"add-raw",placeholder:"https://example.com/raw",value:L.raw_prefix,onChange:E=>F({...L,raw_prefix:E.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"add-clone",children:"克隆前缀 *"}),e.jsx(ce,{id:"add-clone",placeholder:"https://example.com/clone",value:L.clone_prefix,onChange:E=>F({...L,clone_prefix:E.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"add-priority",children:"优先级"}),e.jsx(ce,{id:"add-priority",type:"number",min:"1",value:L.priority,onChange:E=>F({...L,priority:parseInt(E.target.value)||1})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"数字越小优先级越高"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Qe,{id:"add-enabled",checked:L.enabled,onCheckedChange:E=>F({...L,enabled:E})}),e.jsx(y,{htmlFor:"add-enabled",children:"启用此镜像源"})]})]}),e.jsxs(xs,{children:[e.jsx(b,{variant:"outline",onClick:()=>C(!1),children:"取消"}),e.jsx(b,{onClick:O,children:"添加"})]})]})}),e.jsx(Jt,{open:S,onOpenChange:w,children:e.jsxs($t,{className:"max-w-lg",children:[e.jsxs(Qt,{children:[e.jsx(Yt,{children:"编辑镜像源"}),e.jsx(ds,{children:"修改镜像源配置"})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"镜像源 ID"}),e.jsx(ce,{value:L.id,disabled:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"edit-name",children:"名称 *"}),e.jsx(ce,{id:"edit-name",value:L.name,onChange:E=>F({...L,name:E.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"edit-raw",children:"Raw 文件前缀 *"}),e.jsx(ce,{id:"edit-raw",value:L.raw_prefix,onChange:E=>F({...L,raw_prefix:E.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"edit-clone",children:"克隆前缀 *"}),e.jsx(ce,{id:"edit-clone",value:L.clone_prefix,onChange:E=>F({...L,clone_prefix:E.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"edit-priority",children:"优先级"}),e.jsx(ce,{id:"edit-priority",type:"number",min:"1",value:L.priority,onChange:E=>F({...L,priority:parseInt(E.target.value)||1})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"数字越小优先级越高"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Qe,{id:"edit-enabled",checked:L.enabled,onCheckedChange:E=>F({...L,enabled:E})}),e.jsx(y,{htmlFor:"edit-enabled",children:"启用此镜像源"})]})]}),e.jsxs(xs,{children:[e.jsx(b,{variant:"outline",onClick:()=>w(!1),children:"取消"}),e.jsx(b,{onClick:K,children:"保存"})]})]})})]})})}const ir=u.forwardRef(({className:n,...r},c)=>e.jsx(Dp,{ref:c,className:Q("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",n),...r}));ir.displayName=Dp.displayName;const p2=u.forwardRef(({className:n,...r},c)=>e.jsx(Op,{ref:c,className:Q("aspect-square h-full w-full",n),...r}));p2.displayName=Op.displayName;const rr=u.forwardRef(({className:n,...r},c)=>e.jsx(Rp,{ref:c,className:Q("flex h-full w-full items-center justify-center rounded-full bg-muted",n),...r}));rr.displayName=Rp.displayName;function g2(){return"webui_"+Math.random().toString(36).substr(2,9)+"_"+Date.now().toString(36)}function j2(){const n="maibot_webui_user_id";let r=localStorage.getItem(n);return r||(r=g2(),localStorage.setItem(n,r)),r}function v2(){return localStorage.getItem("maibot_webui_user_name")||"WebUI用户"}function b2(n){localStorage.setItem("maibot_webui_user_name",n)}const Og="maibot_webui_virtual_tabs";function y2(){try{const n=localStorage.getItem(Og);if(n)return JSON.parse(n)}catch(n){console.error("[Chat] 加载虚拟标签页失败:",n)}return[]}function fp(n){try{localStorage.setItem(Og,JSON.stringify(n))}catch(r){console.error("[Chat] 保存虚拟标签页失败:",r)}}function N2(){const n={id:"webui-default",type:"webui",label:"WebUI",messages:[],isConnected:!1,isTyping:!1,sessionInfo:{}},r=()=>{const De=y2().map(ze=>{const Ve=ze.virtualConfig;return!Ve.groupId&&Ve.platform&&Ve.userId&&(Ve.groupId=`webui_virtual_group_${Ve.platform}_${Ve.userId}`),{id:ze.id,type:"virtual",label:ze.label,virtualConfig:Ve,messages:[],isConnected:!1,isTyping:!1,sessionInfo:{}}});return[n,...De]},[c,d]=u.useState(r),[h,x]=u.useState("webui-default"),f=c.find(D=>D.id===h)||c[0],[j,p]=u.useState(""),[N,v]=u.useState(!1),[C,S]=u.useState(!0),[w,L]=u.useState(v2()),[F,B]=u.useState(!1),[O,K]=u.useState(""),[H,z]=u.useState(!1),[V,Y]=u.useState([]),[E,R]=u.useState([]),[ne,fe]=u.useState(!1),[Ce,we]=u.useState(!1),[pe,Ne]=u.useState(""),[be,A]=u.useState({platform:"",personId:"",userId:"",userName:"",groupName:"",groupId:""}),X=u.useRef(j2()),T=u.useRef(new Map),te=u.useRef(null),_=u.useRef(new Map),me=u.useRef(0),oe=u.useRef(new Map),{toast:ae}=Xt(),xe=D=>(me.current+=1,`${D}-${Date.now()}-${me.current}-${Math.random().toString(36).substr(2,9)}`),ve=u.useCallback((D,De)=>{d(ze=>ze.map(Ve=>Ve.id===D?{...Ve,...De}:Ve))},[]),de=u.useCallback((D,De)=>{d(ze=>ze.map(Ve=>Ve.id===D?{...Ve,messages:[...Ve.messages,De]}:Ve))},[]),G=u.useCallback(()=>{te.current?.scrollIntoView({behavior:"smooth"})},[]);u.useEffect(()=>{G()},[f?.messages,G]);const W=u.useCallback(async()=>{fe(!0);try{const D=await Te("/api/chat/platforms");if(console.log("[Chat] 平台列表响应:",D.status,D.headers.get("content-type")),D.ok){const De=D.headers.get("content-type");if(De&&De.includes("application/json")){const ze=await D.json();console.log("[Chat] 平台列表数据:",ze),Y(ze.platforms||[])}else{const ze=await D.text();console.error("[Chat] 获取平台列表失败: 非 JSON 响应:",ze.substring(0,200)),ae({title:"连接失败",description:"无法连接到后端服务,请确保 MaiBot 已启动",variant:"destructive"})}}else console.error("[Chat] 获取平台列表失败: HTTP",D.status),ae({title:"获取平台失败",description:`服务器返回错误: ${D.status}`,variant:"destructive"})}catch(D){console.error("[Chat] 获取平台列表失败:",D),ae({title:"网络错误",description:"无法连接到后端服务",variant:"destructive"})}finally{fe(!1)}},[ae]),U=u.useCallback(async(D,De)=>{we(!0);try{const ze=new URLSearchParams;D&&ze.append("platform",D),De&&ze.append("search",De),ze.append("limit","50");const Ve=await Te(`/api/chat/persons?${ze.toString()}`);if(Ve.ok){const At=Ve.headers.get("content-type");if(At&&At.includes("application/json")){const We=await Ve.json();R(We.persons||[])}else console.error("[Chat] 获取用户列表失败: 后端返回非 JSON 响应")}}catch(ze){console.error("[Chat] 获取用户列表失败:",ze)}finally{we(!1)}},[]);u.useEffect(()=>{be.platform&&U(be.platform,pe)},[be.platform,pe,U]);const ee=u.useCallback(async(D,De)=>{S(!0);try{const ze=new URLSearchParams;ze.append("user_id",X.current),ze.append("limit","50"),De&&ze.append("group_id",De);const Ve=`/api/chat/history?${ze.toString()}`;console.log("[Chat] 正在加载历史消息:",Ve);const At=await Te(Ve);if(At.ok){const We=await At.text();try{const ss=JSON.parse(We);if(ss.messages&&ss.messages.length>0){const gt=ss.messages.map(je=>({id:je.id,type:je.type,content:je.content,timestamp:je.timestamp,sender:{name:je.sender_name||(je.is_bot?"麦麦":"WebUI用户"),user_id:je.user_id,is_bot:je.is_bot}}));ve(D,{messages:gt});const _e=oe.current.get(D)||new Set;gt.forEach(je=>{if(je.type==="bot"){const yt=`bot-${je.content}-${Math.floor(je.timestamp*1e3)}`;_e.add(yt)}}),oe.current.set(D,_e)}}catch(ss){console.error("[Chat] JSON 解析失败:",ss)}}}catch(ze){console.error("[Chat] 加载历史消息失败:",ze)}finally{S(!1)}},[ve]),Se=u.useCallback((D,De,ze)=>{const Ve=T.current.get(D);if(Ve?.readyState===WebSocket.OPEN||Ve?.readyState===WebSocket.CONNECTING){console.log(`[Tab ${D}] WebSocket 已存在,跳过连接`);return}v(!0);const At=window.location.protocol==="https:"?"wss:":"ws:",We=new URLSearchParams;De==="virtual"&&ze?(We.append("user_id",ze.userId),We.append("user_name",ze.userName),We.append("platform",ze.platform),We.append("person_id",ze.personId),We.append("group_name",ze.groupName||"WebUI虚拟群聊"),ze.groupId&&We.append("group_id",ze.groupId)):(We.append("user_id",X.current),We.append("user_name",w));const ss=`${At}//${window.location.host}/api/chat/ws?${We.toString()}`;console.log(`[Tab ${D}] 正在连接 WebSocket:`,ss);try{const gt=new WebSocket(ss);T.current.set(D,gt),gt.onopen=()=>{ve(D,{isConnected:!0}),v(!1),console.log(`[Tab ${D}] WebSocket 已连接`)},gt.onmessage=_e=>{try{const je=JSON.parse(_e.data);switch(je.type){case"session_info":ve(D,{sessionInfo:{session_id:je.session_id,user_id:je.user_id,user_name:je.user_name,bot_name:je.bot_name}});break;case"system":de(D,{id:xe("sys"),type:"system",content:je.content||"",timestamp:je.timestamp||Date.now()/1e3});break;case"user_message":de(D,{id:je.message_id||xe("user"),type:"user",content:je.content||"",timestamp:je.timestamp||Date.now()/1e3,sender:je.sender});break;case"bot_message":{ve(D,{isTyping:!1});const yt=oe.current.get(D)||new Set,Ht=`bot-${je.content}-${Math.floor((je.timestamp||0)*1e3)}`;if(yt.has(Ht))break;if(yt.add(Ht),oe.current.set(D,yt),yt.size>100){const pa=yt.values().next().value;pa&&yt.delete(pa)}de(D,{id:xe("bot"),type:"bot",content:je.content||"",timestamp:je.timestamp||Date.now()/1e3,sender:je.sender});break}case"typing":ve(D,{isTyping:je.is_typing||!1});break;case"error":de(D,{id:xe("error"),type:"error",content:je.content||"发生错误",timestamp:je.timestamp||Date.now()/1e3}),ae({title:"错误",description:je.content,variant:"destructive"});break;case"pong":break;case"history":{const yt=je.messages||[];if(yt.length>0){const Ht=oe.current.get(D)||new Set,pa=yt.map(Ts=>{const Kt=Ts.is_bot||!1,Ms=Ts.id||xe(Kt?"bot":"user"),Ds=`${Kt?"bot":"user"}-${Ts.content}-${Math.floor(Ts.timestamp*1e3)}`;return Ht.add(Ds),{id:Ms,type:Kt?"bot":"user",content:Ts.content,timestamp:Ts.timestamp,sender:{name:Ts.sender_name||(Kt?"麦麦":"用户"),user_id:Ts.sender_id,is_bot:Kt}}});oe.current.set(D,Ht),ve(D,{messages:pa}),console.log(`[Tab ${D}] 已加载 ${pa.length} 条历史消息`)}break}default:console.log("未知消息类型:",je.type)}}catch(je){console.error("解析消息失败:",je)}},gt.onclose=()=>{ve(D,{isConnected:!1}),v(!1),T.current.delete(D),console.log(`[Tab ${D}] WebSocket 已断开`);const _e=_.current.get(D);_e&&clearTimeout(_e);const je=window.setTimeout(()=>{if(!Me.current){const yt=c.find(Ht=>Ht.id===D);yt&&Se(D,yt.type,yt.virtualConfig)}},5e3);_.current.set(D,je)},gt.onerror=_e=>{console.error(`[Tab ${D}] WebSocket 错误:`,_e),v(!1)}}catch(gt){console.error(`[Tab ${D}] 创建 WebSocket 失败:`,gt),v(!1)}},[w,ve,de,ae,c]),Me=u.useRef(!1);u.useEffect(()=>{Me.current=!1;const D=T.current,De=_.current,ze=oe.current;ee("webui-default");const Ve=setTimeout(()=>{Me.current||(Se("webui-default","webui"),c.forEach(We=>{We.type==="virtual"&&We.virtualConfig&&(ze.set(We.id,new Set),setTimeout(()=>{Me.current||Se(We.id,"virtual",We.virtualConfig)},200))}))},100),At=setInterval(()=>{D.forEach(We=>{We.readyState===WebSocket.OPEN&&We.send(JSON.stringify({type:"ping"}))})},3e4);return()=>{Me.current=!0,clearTimeout(Ve),clearInterval(At),De.forEach(We=>{clearTimeout(We)}),De.clear(),D.forEach(We=>{We.close()}),D.clear()}},[]);const tt=u.useCallback(()=>{const D=T.current.get(h);if(!j.trim()||!D||D.readyState!==WebSocket.OPEN)return;const De=f?.type==="virtual"&&f.virtualConfig?.userName||w;D.send(JSON.stringify({type:"message",content:j.trim(),user_name:De})),p("")},[j,w,h,f]),Xe=D=>{D.key==="Enter"&&!D.shiftKey&&(D.preventDefault(),tt())},Ut=()=>{K(w),B(!0)},Bt=()=>{const D=O.trim()||"WebUI用户";L(D),b2(D),B(!1);const De=T.current.get(h);De?.readyState===WebSocket.OPEN&&De.send(JSON.stringify({type:"update_nickname",user_name:D}))},re=()=>{K(""),B(!1)},ke=D=>new Date(D*1e3).toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}),Pe=()=>{const D=T.current.get(h);D&&(D.close(),T.current.delete(h)),Se(h,f?.type||"webui",f?.virtualConfig)},Fe=()=>{A({platform:"",personId:"",userId:"",userName:"",groupName:"",groupId:""}),Ne(""),W(),z(!0)},ts=()=>{if(!be.platform||!be.personId){ae({title:"配置不完整",description:"请选择平台和用户",variant:"destructive"});return}const D=`webui_virtual_group_${be.platform}_${be.userId}`,De=`virtual-${be.platform}-${be.userId}-${Date.now()}`,ze=be.userName||be.userId,Ve={id:De,type:"virtual",label:ze,virtualConfig:{...be,groupId:D},messages:[],isConnected:!1,isTyping:!1,sessionInfo:{}};d(At=>{const We=[...At,Ve],ss=We.filter(gt=>gt.type==="virtual"&>.virtualConfig).map(gt=>({id:gt.id,label:gt.label,virtualConfig:gt.virtualConfig,createdAt:Date.now()}));return fp(ss),We}),x(De),z(!1),oe.current.set(De,new Set),setTimeout(()=>{Se(De,"virtual",be)},100),ae({title:"虚拟身份标签页",description:`已创建 ${ze} 的对话`})},As=(D,De)=>{if(De?.stopPropagation(),D==="webui-default")return;const ze=T.current.get(D);ze&&(ze.close(),T.current.delete(D));const Ve=_.current.get(D);Ve&&(clearTimeout(Ve),_.current.delete(D)),oe.current.delete(D),d(At=>{const We=At.filter(gt=>gt.id!==D),ss=We.filter(gt=>gt.type==="virtual"&>.virtualConfig).map(gt=>({id:gt.id,label:gt.label,virtualConfig:gt.virtualConfig,createdAt:Date.now()}));return fp(ss),We}),h===D&&x("webui-default")},js=D=>{x(D)},Ke=D=>{A(De=>({...De,personId:D.person_id,userId:D.user_id,userName:D.nickname||D.person_name}))};return e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsx(Jt,{open:H,onOpenChange:z,children:e.jsxs($t,{className:"sm:max-w-[500px] max-h-[85vh] overflow-hidden flex flex-col",children:[e.jsxs(Qt,{children:[e.jsxs(Yt,{className:"flex items-center gap-2",children:[e.jsx(yu,{className:"h-5 w-5"}),"新建虚拟身份对话"]}),e.jsx(ds,{children:"选择一个麦麦已认识的用户,以该用户的身份与麦麦对话。麦麦将使用她对该用户的记忆和认知来回应。"})]}),e.jsxs("div",{className:"space-y-4 flex-1 overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(y,{className:"flex items-center gap-2",children:[e.jsx(ky,{className:"h-4 w-4"}),"选择平台"]}),e.jsxs(qe,{value:be.platform,onValueChange:D=>{A(De=>({...De,platform:D,personId:"",userId:"",userName:""})),R([])},children:[e.jsx(Be,{disabled:ne,children:e.jsx(Ge,{placeholder:ne?"加载中...":"选择平台"})}),e.jsx(He,{children:V.map(D=>e.jsxs(ie,{value:D.platform,children:[D.platform," (",D.count," 人)"]},D.platform))})]})]}),be.platform&&e.jsxs("div",{className:"space-y-2 flex-1 overflow-hidden flex flex-col",children:[e.jsxs(y,{className:"flex items-center gap-2",children:[e.jsx(Au,{className:"h-4 w-4"}),"选择用户"]}),e.jsxs("div",{className:"relative",children:[e.jsx(zs,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ce,{placeholder:"搜索用户名...",value:pe,onChange:D=>Ne(D.target.value),className:"pl-9"})]}),e.jsx(st,{className:"h-[250px] border rounded-md",children:e.jsx("div",{className:"p-2",children:Ce?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(Ss,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):E.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-muted-foreground",children:[e.jsx(Au,{className:"h-8 w-8 mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"没有找到用户"})]}):e.jsx("div",{className:"space-y-1",children:E.map(D=>e.jsxs("button",{onClick:()=>Ke(D),className:Q("w-full flex items-center gap-3 p-2 rounded-md text-left transition-colors",be.personId===D.person_id?"bg-primary text-primary-foreground":"hover:bg-muted"),children:[e.jsx(ir,{className:"h-8 w-8 shrink-0",children:e.jsx(rr,{className:Q("text-xs",be.personId===D.person_id?"bg-primary-foreground/20":"bg-muted"),children:(D.nickname||D.person_name||"?").charAt(0)})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"font-medium truncate",children:D.nickname||D.person_name}),e.jsxs("div",{className:Q("text-xs truncate",be.personId===D.person_id?"text-primary-foreground/70":"text-muted-foreground"),children:["ID: ",D.user_id,D.is_known&&" · 已认识"]})]})]},D.person_id))})})})]}),be.personId&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"虚拟群名(可选)"}),e.jsx(ce,{placeholder:"WebUI虚拟群聊",value:be.groupName,onChange:D=>A(De=>({...De,groupName:D.target.value}))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"麦麦会认为这是一个名为此名称的群聊"})]})]}),e.jsxs(xs,{className:"gap-2 sm:gap-0",children:[e.jsx(b,{variant:"outline",onClick:()=>z(!1),children:"取消"}),e.jsx(b,{onClick:ts,disabled:!be.platform||!be.personId,children:"创建对话"})]})]})}),e.jsx("div",{className:"shrink-0 border-b bg-muted/30",children:e.jsx("div",{className:"max-w-4xl mx-auto px-2 sm:px-4",children:e.jsxs("div",{className:"flex items-center gap-1 overflow-x-auto py-1.5 scrollbar-thin",children:[c.map(D=>e.jsxs("button",{onClick:()=>js(D.id),className:Q("flex items-center gap-1.5 px-3 py-1.5 rounded-md text-sm whitespace-nowrap transition-colors","hover:bg-muted",h===D.id?"bg-background shadow-sm border":"text-muted-foreground"),children:[D.type==="webui"?e.jsx(cn,{className:"h-3.5 w-3.5"}):e.jsx(yu,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"max-w-[100px] truncate",children:D.label}),e.jsx("span",{className:Q("w-1.5 h-1.5 rounded-full",D.isConnected?"bg-green-500":"bg-muted-foreground/50")}),D.id!=="webui-default"&&e.jsx("button",{onClick:De=>As(D.id,De),className:"ml-0.5 p-0.5 rounded hover:bg-muted-foreground/20",children:e.jsx(on,{className:"h-3 w-3"})})]},D.id)),e.jsx("button",{onClick:Fe,className:"flex items-center gap-1 px-2 py-1.5 rounded-md text-sm text-muted-foreground hover:bg-muted hover:text-foreground transition-colors",title:"新建虚拟身份对话",children:e.jsx(hs,{className:"h-3.5 w-3.5"})})]})})}),e.jsx("div",{className:"shrink-0 border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60",children:e.jsxs("div",{className:"p-3 sm:p-4 max-w-4xl mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 min-w-0",children:[e.jsx(ir,{className:"h-8 w-8 sm:h-10 sm:w-10 shrink-0",children:e.jsx(rr,{className:"bg-primary/10 text-primary",children:e.jsx(ar,{className:"h-4 w-4 sm:h-5 sm:w-5"})})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-base sm:text-lg font-semibold truncate",children:f?.sessionInfo.bot_name||"麦麦"}),e.jsx("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:f?.isConnected?e.jsxs(e.Fragment,{children:[e.jsx(Ty,{className:"h-3 w-3 text-green-500"}),e.jsx("span",{className:"text-green-600 dark:text-green-400",children:"已连接"})]}):N?e.jsxs(e.Fragment,{children:[e.jsx(Ss,{className:"h-3 w-3 animate-spin"}),e.jsx("span",{children:"连接中..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ey,{className:"h-3 w-3 text-red-500"}),e.jsx("span",{className:"text-red-600 dark:text-red-400",children:"未连接"})]})})]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[C&&e.jsx(Ss,{className:"h-4 w-4 animate-spin text-muted-foreground"}),e.jsx(b,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:Pe,disabled:N,title:"重新连接",children:e.jsx(ws,{className:Q("h-4 w-4",N&&"animate-spin")})})]})]}),e.jsx("div",{className:"hidden sm:flex items-center gap-2 mt-2 text-sm text-muted-foreground",children:f?.type==="virtual"&&f.virtualConfig?e.jsxs(e.Fragment,{children:[e.jsx(yu,{className:"h-3 w-3 text-primary"}),e.jsx("span",{children:"虚拟身份:"}),e.jsx("span",{className:"font-medium text-primary",children:f.virtualConfig.userName}),e.jsxs("span",{className:"text-xs",children:["(",f.virtualConfig.platform,")"]}),f.virtualConfig.groupName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1",children:"·"}),e.jsxs("span",{className:"text-xs",children:["群:",f.virtualConfig.groupName]})]})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ic,{className:"h-3 w-3"}),e.jsx("span",{children:"当前身份:"}),F?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ce,{value:O,onChange:D=>K(D.target.value),onKeyDown:D=>{D.key==="Enter"&&Bt(),D.key==="Escape"&&re()},className:"h-7 w-32",placeholder:"输入昵称",autoFocus:!0}),e.jsx(b,{size:"sm",variant:"ghost",className:"h-7 px-2",onClick:Bt,children:"保存"}),e.jsx(b,{size:"sm",variant:"ghost",className:"h-7 px-2",onClick:re,children:"取消"})]}):e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"font-medium text-foreground",children:w}),e.jsx(b,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:Ut,title:"修改昵称",children:e.jsx(zy,{className:"h-3 w-3"})})]})]})})]})}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx(st,{className:"h-full",children:e.jsxs("div",{className:"p-3 sm:p-4 max-w-4xl mx-auto space-y-3 sm:space-y-4",children:[f?.messages.length===0&&!C&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(ar,{className:"h-12 w-12 mb-4 opacity-50"}),e.jsxs("p",{className:"text-sm",children:["开始与 ",f?.sessionInfo.bot_name||"麦麦"," 对话吧!"]})]}),f?.messages.map(D=>e.jsxs("div",{className:Q("flex gap-2 sm:gap-3",D.type==="user"&&"flex-row-reverse",D.type==="system"&&"justify-center",D.type==="error"&&"justify-center"),children:[D.type==="system"&&e.jsx("div",{className:"text-xs text-muted-foreground bg-muted/50 px-3 py-1 rounded-full max-w-[90%]",children:D.content}),D.type==="error"&&e.jsx("div",{className:"text-xs text-red-600 dark:text-red-400 bg-red-100 dark:bg-red-900/30 px-3 py-1 rounded-full max-w-[90%]",children:D.content}),(D.type==="user"||D.type==="bot")&&e.jsxs(e.Fragment,{children:[e.jsx(ir,{className:"h-7 w-7 sm:h-8 sm:w-8 shrink-0",children:e.jsx(rr,{className:Q("text-xs",D.type==="bot"?"bg-primary/10 text-primary":"bg-secondary text-secondary-foreground"),children:D.type==="bot"?e.jsx(ar,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"}):e.jsx(Ic,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"})})}),e.jsxs("div",{className:Q("flex flex-col gap-1 max-w-[75%] sm:max-w-[70%]",D.type==="user"&&"items-end"),children:[e.jsxs("div",{className:"flex items-center gap-2 text-[10px] sm:text-xs text-muted-foreground",children:[e.jsx("span",{className:"hidden sm:inline",children:D.sender?.name||(D.type==="bot"?f?.sessionInfo.bot_name:w)}),e.jsx("span",{children:ke(D.timestamp)})]}),e.jsx("div",{className:Q("rounded-2xl px-3 py-2 text-sm whitespace-pre-wrap break-words",D.type==="bot"?"bg-muted rounded-tl-sm":"bg-primary text-primary-foreground rounded-tr-sm"),children:D.content})]})]})]},D.id)),f?.isTyping&&e.jsxs("div",{className:"flex gap-2 sm:gap-3",children:[e.jsx(ir,{className:"h-7 w-7 sm:h-8 sm:w-8 shrink-0",children:e.jsx(rr,{className:"bg-primary/10 text-primary",children:e.jsx(ar,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"})})}),e.jsx("div",{className:"bg-muted rounded-2xl rounded-tl-sm px-4 py-3",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx("span",{className:"w-2 h-2 bg-muted-foreground/50 rounded-full animate-bounce",style:{animationDelay:"0ms"}}),e.jsx("span",{className:"w-2 h-2 bg-muted-foreground/50 rounded-full animate-bounce",style:{animationDelay:"150ms"}}),e.jsx("span",{className:"w-2 h-2 bg-muted-foreground/50 rounded-full animate-bounce",style:{animationDelay:"300ms"}})]})})]}),e.jsx("div",{ref:te})]})})}),e.jsx("div",{className:"shrink-0 border-t bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60",children:e.jsx("div",{className:"p-3 sm:p-4 max-w-4xl mx-auto",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ce,{value:j,onChange:D=>p(D.target.value),onKeyDown:Xe,placeholder:f?.isConnected?"输入消息...":"等待连接...",disabled:!f?.isConnected,className:"flex-1 h-10 sm:h-10"}),e.jsx(b,{onClick:tt,disabled:!f?.isConnected||!j.trim(),size:"icon",className:"h-10 w-10 shrink-0",children:e.jsx(Ay,{className:"h-4 w-4"})})]})})})]})}function w2(){const n=fa(),[r,c]=u.useState(!0);return u.useEffect(()=>{let d=!1;return(async()=>{try{const x=await Qu();!d&&!x&&n({to:"/auth"})}catch{d||n({to:"/auth"})}finally{d||c(!1)}})(),()=>{d=!0}},[n]),{checking:r}}async function _2(){return await Qu()}const S2=si("pointer-events-none inline-flex select-none items-center gap-1 rounded border bg-muted px-1.5 font-mono font-medium opacity-100",{variants:{size:{sm:"h-5 text-[10px]",default:"h-6 text-xs",lg:"h-7 text-sm"}},defaultVariants:{size:"default"}}),Rg=u.forwardRef(({className:n,size:r,abbrTitle:c,children:d,...h},x)=>e.jsx("kbd",{className:Q(S2({size:r,className:n})),ref:x,...h,children:c?e.jsx("abbr",{title:c,children:d}):d}));Rg.displayName="Kbd";const C2=[{icon:to,title:"首页",description:"查看仪表板概览",path:"/",category:"概览"},{icon:Da,title:"麦麦主程序配置",description:"配置麦麦的核心设置",path:"/config/bot",category:"配置"},{icon:cg,title:"麦麦模型提供商配置",description:"配置模型提供商",path:"/config/modelProvider",category:"配置"},{icon:og,title:"麦麦模型配置",description:"配置模型参数",path:"/config/model",category:"配置"},{icon:Bu,title:"表情包管理",description:"管理麦麦的表情包",path:"/resource/emoji",category:"资源"},{icon:cn,title:"表达方式管理",description:"管理麦麦的表达方式",path:"/resource/expression",category:"资源"},{icon:dg,title:"人物信息管理",description:"管理人物信息",path:"/resource/person",category:"资源"},{icon:My,title:"统计信息",description:"查看使用统计",path:"/statistics",category:"监控"},{icon:rn,title:"插件市场",description:"浏览和安装插件",path:"/plugins",category:"扩展"},{icon:Hu,title:"日志查看器",description:"查看系统日志",path:"/logs",category:"监控"},{icon:ai,title:"系统设置",description:"配置系统参数",path:"/settings",category:"系统"}];function k2({open:n,onOpenChange:r}){const[c,d]=u.useState(""),[h,x]=u.useState(0),f=fa(),j=C2.filter(v=>v.title.toLowerCase().includes(c.toLowerCase())||v.description.toLowerCase().includes(c.toLowerCase())||v.category.toLowerCase().includes(c.toLowerCase()));u.useEffect(()=>{n&&(d(""),x(0))},[n]);const p=u.useCallback(v=>{f({to:v}),r(!1)},[f,r]),N=u.useCallback(v=>{v.key==="ArrowDown"?(v.preventDefault(),x(C=>(C+1)%j.length)):v.key==="ArrowUp"?(v.preventDefault(),x(C=>(C-1+j.length)%j.length)):v.key==="Enter"&&j[h]&&(v.preventDefault(),p(j[h].path))},[j,h,p]);return e.jsx(Jt,{open:n,onOpenChange:r,children:e.jsxs($t,{className:"max-w-2xl p-0 gap-0",children:[e.jsxs(Qt,{className:"px-4 pt-4 pb-0",children:[e.jsx(Yt,{className:"sr-only",children:"搜索"}),e.jsxs("div",{className:"relative",children:[e.jsx(zs,{className:"absolute left-3 top-1/2 h-5 w-5 -translate-y-1/2 text-muted-foreground"}),e.jsx(ce,{value:c,onChange:v=>{d(v.target.value),x(0)},onKeyDown:N,placeholder:"搜索页面...",className:"h-12 pl-11 text-base border-0 focus-visible:ring-0 shadow-none",autoFocus:!0})]})]}),e.jsx("div",{className:"border-t",children:e.jsx(st,{className:"h-[400px]",children:j.length>0?e.jsx("div",{className:"p-2",children:j.map((v,C)=>{const S=v.icon;return e.jsxs("button",{onClick:()=>p(v.path),onMouseEnter:()=>x(C),className:Q("w-full flex items-center gap-3 px-3 py-2.5 rounded-md text-left transition-colors",C===h?"bg-accent text-accent-foreground":"hover:bg-accent/50"),children:[e.jsx(S,{className:"h-5 w-5 flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium text-sm",children:v.title}),e.jsx("div",{className:"text-xs text-muted-foreground truncate",children:v.description})]}),e.jsx("div",{className:"text-xs text-muted-foreground px-2 py-1 bg-muted rounded",children:v.category})]},v.path)})}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[e.jsx(zs,{className:"h-12 w-12 text-muted-foreground/50 mb-4"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:c?"未找到匹配的页面":"输入关键词开始搜索"})]})})}),e.jsx("div",{className:"border-t px-4 py-3 flex items-center justify-between text-xs text-muted-foreground",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"↑"}),e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"↓"}),"导航"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"Enter"}),"选择"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"Esc"}),"关闭"]})]})})]})})}const T2=ey,E2=ty,z2=sy,Lg=u.forwardRef(({className:n,sideOffset:r=4,...c},d)=>e.jsx(Wb,{children:e.jsx(Zp,{ref:d,sideOffset:r,className:Q("z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-tooltip-content-transform-origin]",n),...c})}));Lg.displayName=Zp.displayName;function A2({children:n}){const{checking:r}=w2(),[c,d]=u.useState(!0),[h,x]=u.useState(!1),[f,j]=u.useState(!1),{theme:p,setTheme:N}=Gu(),v=sb();if(u.useEffect(()=>{const F=B=>{(B.metaKey||B.ctrlKey)&&B.key==="k"&&(B.preventDefault(),j(!0))};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[]),r)return e.jsx("div",{className:"flex h-screen items-center justify-center bg-background",children:e.jsx("div",{className:"text-muted-foreground",children:"正在验证登录状态..."})});const C=[{title:"概览",items:[{icon:to,label:"首页",path:"/"}]},{title:"麦麦配置编辑",items:[{icon:Da,label:"麦麦主程序配置",path:"/config/bot"},{icon:cg,label:"AI模型厂商配置",path:"/config/modelProvider",tourId:"sidebar-model-provider"},{icon:og,label:"模型管理与分配",path:"/config/model",tourId:"sidebar-model-management"},{icon:$f,label:"麦麦适配器配置",path:"/config/adapter"}]},{title:"麦麦资源管理",items:[{icon:Bu,label:"表情包管理",path:"/resource/emoji"},{icon:cn,label:"表达方式管理",path:"/resource/expression"},{icon:dg,label:"人物信息管理",path:"/resource/person"},{icon:rg,label:"知识库图谱可视化",path:"/resource/knowledge-graph"}]},{title:"扩展与监控",items:[{icon:rn,label:"插件市场",path:"/plugins"},{icon:$f,label:"插件配置",path:"/plugin-config"},{icon:Hu,label:"日志查看器",path:"/logs"},{icon:cn,label:"本地聊天室",path:"/chat"}]},{title:"系统",items:[{icon:ai,label:"系统设置",path:"/settings"}]}],w=p==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":p,L=async()=>{await t0()};return e.jsx(T2,{delayDuration:300,children:e.jsxs("div",{className:"flex h-screen overflow-hidden",children:[e.jsxs("aside",{className:Q("fixed inset-y-0 left-0 z-50 flex flex-col border-r bg-card transition-all duration-300 lg:relative lg:z-0","w-64 lg:w-auto",c?"lg:w-64":"lg:w-16",h?"translate-x-0":"-translate-x-full lg:translate-x-0"),children:[e.jsx("div",{className:"flex h-16 items-center border-b px-4",children:e.jsxs("div",{className:Q("relative flex items-center justify-center flex-1 transition-all overflow-hidden","lg:flex-1",!c&&"lg:flex-none lg:w-8"),children:[e.jsxs("div",{className:Q("flex items-baseline gap-2",!c&&"lg:hidden"),children:[e.jsx("span",{className:"font-bold text-xl text-primary-gradient whitespace-nowrap",children:"MaiBot WebUI"}),e.jsx("span",{className:"text-xs text-primary/60 whitespace-nowrap",children:HN()})]}),!c&&e.jsx("span",{className:"hidden lg:block font-bold text-primary-gradient text-2xl",children:"M"})]})}),e.jsx(st,{className:Q("flex-1 overflow-x-hidden",!c&&"lg:w-16"),children:e.jsx("nav",{className:Q("p-4",!c&&"lg:p-2 lg:w-16"),children:e.jsx("ul",{className:Q("space-y-6",!c&&"lg:space-y-3 lg:w-full"),children:C.map((F,B)=>e.jsxs("li",{children:[e.jsx("div",{className:Q("px-3 h-[1.25rem]","mb-2",!c&&"lg:mb-1 lg:invisible"),children:e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground/60 whitespace-nowrap",children:F.title})}),!c&&B>0&&e.jsx("div",{className:"hidden lg:block mb-2 border-t border-border"}),e.jsx("ul",{className:"space-y-1",children:F.items.map(O=>{const K=v({to:O.path}),H=O.icon,z=e.jsxs(e.Fragment,{children:[K&&e.jsx("div",{className:"absolute left-0 top-1/2 h-8 w-1 -translate-y-1/2 rounded-r-full bg-primary transition-opacity duration-300"}),e.jsxs("div",{className:Q("flex items-center transition-all duration-300",c?"gap-3":"gap-3 lg:gap-0"),children:[e.jsx(H,{className:Q("h-5 w-5 flex-shrink-0",K&&"text-primary"),strokeWidth:2,fill:"none"}),e.jsx("span",{className:Q("text-sm font-medium whitespace-nowrap transition-all duration-300",K&&"font-semibold",c?"opacity-100 max-w-[200px]":"opacity-100 max-w-[200px] lg:opacity-0 lg:max-w-0 lg:overflow-hidden"),children:O.label})]})]});return e.jsx("li",{className:"relative",children:e.jsxs(E2,{children:[e.jsx(z2,{asChild:!0,children:e.jsx($c,{to:O.path,"data-tour":O.tourId,className:Q("relative flex items-center rounded-lg py-2 transition-all duration-300","hover:bg-accent hover:text-accent-foreground",K?"bg-accent text-foreground":"text-muted-foreground hover:text-foreground",c?"px-3":"px-3 lg:px-0 lg:justify-center lg:w-12 lg:mx-auto"),onClick:()=>x(!1),children:z})}),!c&&e.jsx(Lg,{side:"right",className:"hidden lg:block",children:e.jsx("p",{children:O.label})})]})},O.path)})})]},F.title))})})})]}),h&&e.jsx("div",{className:"fixed inset-0 z-40 bg-black/50 lg:hidden",onClick:()=>x(!1)}),e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsxs("header",{className:"flex h-16 items-center justify-between border-b bg-card/80 backdrop-blur-md px-4 sticky top-0 z-10",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("button",{onClick:()=>x(!h),className:"rounded-lg p-2 hover:bg-accent lg:hidden",children:e.jsx(Dy,{className:"h-5 w-5"})}),e.jsx("button",{onClick:()=>d(!c),className:"hidden rounded-lg p-2 hover:bg-accent lg:block",title:c?"收起侧边栏":"展开侧边栏",children:e.jsx(dn,{className:Q("h-5 w-5 transition-transform",!c&&"rotate-180")})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>j(!0),className:"relative hidden md:flex items-center w-64 h-9 pl-9 pr-16 bg-background/50 border rounded-md hover:bg-accent/50 transition-colors text-left",children:[e.jsx(zs,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"搜索..."}),e.jsxs(Rg,{size:"sm",className:"absolute right-2 top-1/2 -translate-y-1/2",children:[e.jsx("span",{className:"text-xs",children:"⌘"}),"K"]})]}),e.jsx(k2,{open:f,onOpenChange:j}),e.jsxs(b,{variant:"ghost",size:"sm",onClick:()=>window.open("https://docs.mai-mai.org","_blank"),className:"gap-2",title:"查看麦麦文档",children:[e.jsx(Oy,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"麦麦文档"})]}),e.jsx("button",{onClick:F=>{ON(w==="dark"?"light":"dark",N,F)},className:"rounded-lg p-2 hover:bg-accent",title:w==="dark"?"切换到浅色模式":"切换到深色模式",children:w==="dark"?e.jsx(ag,{className:"h-5 w-5"}):e.jsx(lg,{className:"h-5 w-5"})}),e.jsx("div",{className:"h-6 w-px bg-border"}),e.jsxs(b,{variant:"ghost",size:"sm",onClick:L,className:"gap-2",title:"登出系统",children:[e.jsx(Ry,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"登出"})]})]})]}),e.jsx("main",{className:"flex-1 overflow-hidden bg-background",children:n})]})]})})}function M2(n){const r=n.split(` `).slice(1),c=[];for(const d of r){const h=d.trim();if(!h.startsWith("at "))continue;const x=h.match(/at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?$/);x?c.push({functionName:x[1]||"",fileName:x[2],lineNumber:x[3],columnNumber:x[4],raw:h}):c.push({functionName:"",fileName:"",lineNumber:"",columnNumber:"",raw:h})}return c}function D2({error:n,errorInfo:r}){const[c,d]=u.useState(!0),[h,x]=u.useState(!1),[f,j]=u.useState(!1),p=n.stack?M2(n.stack):[],N=async()=>{const v=` Error: ${n.name} Message: ${n.message} Stack Trace: ${n.stack||"No stack trace available"} Component Stack: ${r?.componentStack||"No component stack available"} URL: ${window.location.href} User Agent: ${navigator.userAgent} Time: ${new Date().toISOString()} `.trim();try{await navigator.clipboard.writeText(v),j(!0),setTimeout(()=>j(!1),2e3)}catch(C){console.error("Failed to copy:",C)}};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(cl,{variant:"destructive",className:"border-red-500/50 bg-red-500/10",children:[e.jsx(ya,{className:"h-4 w-4"}),e.jsxs(ol,{className:"font-mono text-sm",children:[e.jsxs("span",{className:"font-semibold",children:[n.name,":"]})," ",n.message]})]}),p.length>0&&e.jsxs(Ru,{open:c,onOpenChange:d,children:[e.jsx(Lu,{asChild:!0,children:e.jsxs(b,{variant:"ghost",className:"w-full justify-between p-3 h-auto",children:[e.jsxs("span",{className:"font-semibold text-sm flex items-center gap-2",children:[e.jsx(Ly,{className:"h-4 w-4"}),"Stack Trace (",p.length," frames)"]}),c?e.jsx(ur,{className:"h-4 w-4"}):e.jsx(Rl,{className:"h-4 w-4"})]})}),e.jsx(Uu,{children:e.jsx(st,{className:"h-[280px] rounded-md border bg-muted/30",children:e.jsx("div",{className:"p-3 space-y-1",children:p.map((v,C)=>e.jsx("div",{className:"font-mono text-xs p-2 rounded hover:bg-muted/50 transition-colors",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("span",{className:"text-muted-foreground w-6 text-right flex-shrink-0",children:[C+1,"."]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-primary font-medium",children:v.functionName}),v.fileName&&e.jsxs("div",{className:"text-muted-foreground mt-0.5 break-all",children:[v.fileName,v.lineNumber&&e.jsxs("span",{className:"text-yellow-600 dark:text-yellow-400",children:[":",v.lineNumber,":",v.columnNumber]})]})]})]})},C))})})})]}),r?.componentStack&&e.jsxs(Ru,{open:h,onOpenChange:x,children:[e.jsx(Lu,{asChild:!0,children:e.jsxs(b,{variant:"ghost",className:"w-full justify-between p-3 h-auto",children:[e.jsxs("span",{className:"font-semibold text-sm flex items-center gap-2",children:[e.jsx(ya,{className:"h-4 w-4"}),"Component Stack"]}),h?e.jsx(ur,{className:"h-4 w-4"}):e.jsx(Rl,{className:"h-4 w-4"})]})}),e.jsx(Uu,{children:e.jsx(st,{className:"h-[200px] rounded-md border bg-muted/30",children:e.jsx("pre",{className:"p-3 font-mono text-xs whitespace-pre-wrap text-muted-foreground",children:r.componentStack})})})]}),e.jsx(b,{variant:"outline",size:"sm",onClick:N,className:"w-full",children:f?e.jsxs(e.Fragment,{children:[e.jsx(Na,{className:"mr-2 h-4 w-4 text-green-500"}),"已复制到剪贴板"]}):e.jsxs(e.Fragment,{children:[e.jsx(Jc,{className:"mr-2 h-4 w-4"}),"复制错误信息"]})})]})}function Ug({error:n,errorInfo:r}){const c=()=>{window.location.href="/"},d=()=>{window.location.reload()};return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background p-4",children:e.jsxs(Ye,{className:"w-full max-w-2xl shadow-lg",children:[e.jsxs(Nt,{className:"text-center pb-2",children:[e.jsx("div",{className:"mx-auto flex h-16 w-16 items-center justify-center rounded-full bg-red-100 dark:bg-red-900/30 mb-4",children:e.jsx(ya,{className:"h-8 w-8 text-red-600 dark:text-red-400"})}),e.jsx(wt,{className:"text-2xl font-bold",children:"页面出现了问题"}),e.jsx(ns,{className:"text-base mt-2",children:"应用程序遇到了意外错误。您可以尝试刷新页面或返回首页。"})]}),e.jsxs(kt,{className:"space-y-4",children:[e.jsx(D2,{error:n,errorInfo:r}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 pt-2",children:[e.jsxs(b,{onClick:d,className:"flex-1",children:[e.jsx(ws,{className:"mr-2 h-4 w-4"}),"刷新页面"]}),e.jsxs(b,{onClick:c,variant:"outline",className:"flex-1",children:[e.jsx(to,{className:"mr-2 h-4 w-4"}),"返回首页"]})]}),e.jsx("p",{className:"text-xs text-center text-muted-foreground pt-2",children:"如果问题持续存在,请将错误信息复制并反馈给开发者"})]})]})})}class O2 extends u.Component{constructor(r){super(r),this.state={hasError:!1,error:null,errorInfo:null}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,c){console.error("ErrorBoundary caught an error:",r,c),this.setState({errorInfo:c})}handleReset=()=>{this.setState({hasError:!1,error:null,errorInfo:null})};render(){return this.state.hasError&&this.state.error?this.props.fallback?this.props.fallback:e.jsx(Ug,{error:this.state.error,errorInfo:this.state.errorInfo}):this.props.children}}function Bg({error:n}){return e.jsx(Ug,{error:n,errorInfo:null})}const wr=ab({component:()=>e.jsxs(e.Fragment,{children:[e.jsx(pp,{}),!1]}),beforeLoad:()=>{if(window.location.pathname==="/"&&!_2())throw nb({to:"/auth"})}}),R2=fs({getParentRoute:()=>wr,path:"/auth",component:s0}),L2=fs({getParentRoute:()=>wr,path:"/setup",component:v0}),ks=fs({getParentRoute:()=>wr,id:"protected",component:()=>e.jsx(A2,{children:e.jsx(pp,{})}),errorComponent:({error:n})=>e.jsx(Bg,{error:n})}),U2=fs({getParentRoute:()=>ks,path:"/",component:MN}),B2=fs({getParentRoute:()=>ks,path:"/config/bot",component:M0}),H2=fs({getParentRoute:()=>ks,path:"/config/modelProvider",component:sw}),q2=fs({getParentRoute:()=>ks,path:"/config/model",component:iw}),G2=fs({getParentRoute:()=>ks,path:"/config/adapter",component:cw}),V2=fs({getParentRoute:()=>ks,path:"/resource/emoji",component:Mw}),F2=fs({getParentRoute:()=>ks,path:"/resource/expression",component:$w}),$2=fs({getParentRoute:()=>ks,path:"/resource/person",component:t1}),Q2=fs({getParentRoute:()=>ks,path:"/resource/knowledge-graph",component:d1}),Y2=fs({getParentRoute:()=>ks,path:"/logs",component:G1}),X2=fs({getParentRoute:()=>ks,path:"/chat",component:N2}),K2=fs({getParentRoute:()=>ks,path:"/plugins",component:u2}),Z2=fs({getParentRoute:()=>ks,path:"/plugin-config",component:x2}),J2=fs({getParentRoute:()=>ks,path:"/plugin-mirrors",component:f2}),I2=fs({getParentRoute:()=>ks,path:"/settings",component:ZN}),P2=fs({getParentRoute:()=>wr,path:"*",component:wg}),W2=wr.addChildren([R2,L2,ks.addChildren([U2,B2,H2,q2,G2,V2,F2,$2,Q2,K2,Z2,J2,Y2,X2,I2]),P2]),e_=lb({routeTree:W2,defaultNotFoundComponent:wg,defaultErrorComponent:({error:n})=>e.jsx(Bg,{error:n})});function t_({children:n,defaultTheme:r="system",storageKey:c="ui-theme",...d}){const[h,x]=u.useState(()=>localStorage.getItem(c)||r);u.useEffect(()=>{const j=window.document.documentElement;if(j.classList.remove("light","dark"),h==="system"){const p=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";j.classList.add(p);return}j.classList.add(h)},[h]),u.useEffect(()=>{const j=localStorage.getItem("accent-color");if(j){const p=document.documentElement,v={blue:{hsl:"221.2 83.2% 53.3%",darkHsl:"217.2 91.2% 59.8%",gradient:null},purple:{hsl:"271 91% 65%",darkHsl:"270 95% 75%",gradient:null},green:{hsl:"142 71% 45%",darkHsl:"142 76% 36%",gradient:null},orange:{hsl:"25 95% 53%",darkHsl:"20 90% 48%",gradient:null},pink:{hsl:"330 81% 60%",darkHsl:"330 85% 70%",gradient:null},red:{hsl:"0 84% 60%",darkHsl:"0 90% 70%",gradient:null},"gradient-sunset":{hsl:"15 95% 60%",darkHsl:"15 95% 65%",gradient:"linear-gradient(135deg, hsl(25 95% 53%) 0%, hsl(330 81% 60%) 100%)"},"gradient-ocean":{hsl:"200 90% 55%",darkHsl:"200 90% 60%",gradient:"linear-gradient(135deg, hsl(221.2 83.2% 53.3%) 0%, hsl(189 94% 43%) 100%)"},"gradient-forest":{hsl:"150 70% 45%",darkHsl:"150 75% 40%",gradient:"linear-gradient(135deg, hsl(142 71% 45%) 0%, hsl(158 64% 52%) 100%)"},"gradient-aurora":{hsl:"310 85% 65%",darkHsl:"310 90% 70%",gradient:"linear-gradient(135deg, hsl(271 91% 65%) 0%, hsl(330 81% 60%) 100%)"},"gradient-fire":{hsl:"15 95% 55%",darkHsl:"15 95% 60%",gradient:"linear-gradient(135deg, hsl(0 84% 60%) 0%, hsl(25 95% 53%) 100%)"},"gradient-twilight":{hsl:"250 90% 60%",darkHsl:"250 95% 65%",gradient:"linear-gradient(135deg, hsl(239 84% 67%) 0%, hsl(271 91% 65%) 100%)"}}[j];v&&(p.style.setProperty("--primary",v.hsl),v.gradient?(p.style.setProperty("--primary-gradient",v.gradient),p.classList.add("has-gradient")):(p.style.removeProperty("--primary-gradient"),p.classList.remove("has-gradient")))}},[]);const f={theme:h,setTheme:j=>{localStorage.setItem(c,j),x(j)}};return e.jsx(gg.Provider,{...d,value:f,children:n})}function s_({children:n,defaultEnabled:r=!0,defaultWavesEnabled:c=!0,storageKey:d="enable-animations",wavesStorageKey:h="enable-waves-background"}){const[x,f]=u.useState(()=>{const v=localStorage.getItem(d);return v!==null?v==="true":r}),[j,p]=u.useState(()=>{const v=localStorage.getItem(h);return v!==null?v==="true":c});u.useEffect(()=>{const v=document.documentElement;x?v.classList.remove("no-animations"):v.classList.add("no-animations"),localStorage.setItem(d,String(x))},[x,d]),u.useEffect(()=>{localStorage.setItem(h,String(j))},[j,h]);const N={enableAnimations:x,setEnableAnimations:f,enableWavesBackground:j,setEnableWavesBackground:p};return e.jsx(jg.Provider,{value:N,children:n})}const a_=ay,Hg=u.forwardRef(({className:n,...r},c)=>e.jsx(Jp,{ref:c,className:Q("fixed bottom-0 right-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:max-w-[420px] gap-2",n),...r}));Hg.displayName=Jp.displayName;const l_=si("group pointer-events-auto relative flex w-full items-center justify-between space-x-2 overflow-hidden rounded-md border p-4 pr-6 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-slide-in-from-right data-[state=open]:animate-fade-in data-[state=closed]:animate-slide-out-to-right data-[state=closed]:animate-fade-out data-[swipe=end]:animate-slide-out-to-right",{variants:{variant:{default:"border bg-primary/5 text-foreground backdrop-blur-sm",destructive:"destructive group border-destructive bg-destructive/10 text-destructive-foreground backdrop-blur-sm"}},defaultVariants:{variant:"default"}}),qg=u.forwardRef(({className:n,variant:r,...c},d)=>e.jsx(Ip,{ref:d,className:Q(l_({variant:r}),n),...c}));qg.displayName=Ip.displayName;const n_=u.forwardRef(({className:n,...r},c)=>e.jsx(Pp,{ref:c,className:Q("inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium transition-colors hover:bg-secondary focus:outline-none focus:ring-1 focus:ring-ring disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",n),...r}));n_.displayName=Pp.displayName;const Gg=u.forwardRef(({className:n,...r},c)=>e.jsx(Wp,{ref:c,className:Q("absolute right-1 top-1 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-1 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600",n),"toast-close":"",...r,children:e.jsx(on,{className:"h-4 w-4"})}));Gg.displayName=Wp.displayName;const Vg=u.forwardRef(({className:n,...r},c)=>e.jsx(eg,{ref:c,className:Q("text-sm font-semibold [&+div]:text-xs",n),...r}));Vg.displayName=eg.displayName;const Fg=u.forwardRef(({className:n,...r},c)=>e.jsx(tg,{ref:c,className:Q("text-sm opacity-90",n),...r}));Fg.displayName=tg.displayName;function i_(){const{toasts:n}=Xt();return e.jsxs(a_,{children:[n.map(function({id:r,title:c,description:d,action:h,...x}){return e.jsxs(qg,{...x,children:[e.jsxs("div",{className:"grid gap-1",children:[c&&e.jsx(Vg,{children:c}),d&&e.jsx(Fg,{children:d})]}),h,e.jsx(Gg,{})]},r)}),e.jsx(Hg,{})]})}yN.createRoot(document.getElementById("root")).render(e.jsx(u.StrictMode,{children:e.jsx(O2,{children:e.jsx(t_,{defaultTheme:"system",children:e.jsx(s_,{children:e.jsxs(I0,{children:[e.jsx(ib,{router:e_}),e.jsx(ew,{}),e.jsx(i_,{})]})})})})}));