var w3=Object.defineProperty;var xy=t=>{throw TypeError(t)};var j3=(t,n,a)=>n in t?w3(t,n,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[n]=a;var by=(t,n,a)=>j3(t,typeof n!="symbol"?n+"":n,a),vy=(t,n,a)=>n.has(t)||xy("Cannot "+a);var pn=(t,n,a)=>(vy(t,n,"read from private field"),a?a.call(t):n.get(t)),yy=(t,n,a)=>n.has(t)?xy("Cannot add the same private member more than once"):n instanceof WeakSet?n.add(t):n.set(t,a),dp=(t,n,a,o)=>(vy(t,n,"write to private field"),o?o.call(t,a):n.set(t,a),a);function C3(t,n){for(var a=0;ao[c]})}}}return Object.freeze(Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}))}(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const c of document.querySelectorAll('link[rel="modulepreload"]'))o(c);new MutationObserver(c=>{for(const l of c)if(l.type==="childList")for(const d of l.addedNodes)d.tagName==="LINK"&&d.rel==="modulepreload"&&o(d)}).observe(document,{childList:!0,subtree:!0});function a(c){const l={};return c.integrity&&(l.integrity=c.integrity),c.referrerPolicy&&(l.referrerPolicy=c.referrerPolicy),c.crossOrigin==="use-credentials"?l.credentials="include":c.crossOrigin==="anonymous"?l.credentials="omit":l.credentials="same-origin",l}function o(c){if(c.ep)return;c.ep=!0;const l=a(c);fetch(c.href,l)}})();function s2(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var fp={exports:{}},Sl={};/** * @license React * react-jsx-runtime.production.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var wy;function S3(){if(wy)return Sl;wy=1;var t=Symbol.for("react.transitional.element"),n=Symbol.for("react.fragment");function a(o,c,l){var d=null;if(l!==void 0&&(d=""+l),c.key!==void 0&&(d=""+c.key),"key"in c){l={};for(var m in c)m!=="key"&&(l[m]=c[m])}else l=c;return c=l.ref,{$$typeof:t,type:o,key:d,ref:c!==void 0?c:null,props:l}}return Sl.Fragment=n,Sl.jsx=a,Sl.jsxs=a,Sl}var jy;function N3(){return jy||(jy=1,fp.exports=S3()),fp.exports}var s=N3(),mp={exports:{}},ze={};/** * @license React * react.production.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var Cy;function E3(){if(Cy)return ze;Cy=1;var t=Symbol.for("react.transitional.element"),n=Symbol.for("react.portal"),a=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),c=Symbol.for("react.profiler"),l=Symbol.for("react.consumer"),d=Symbol.for("react.context"),m=Symbol.for("react.forward_ref"),p=Symbol.for("react.suspense"),g=Symbol.for("react.memo"),b=Symbol.for("react.lazy"),v=Symbol.for("react.activity"),w=Symbol.iterator;function y(O){return O===null||typeof O!="object"?null:(O=w&&O[w]||O["@@iterator"],typeof O=="function"?O:null)}var C={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},S=Object.assign,N={};function E(O,D,B){this.props=O,this.context=D,this.refs=N,this.updater=B||C}E.prototype.isReactComponent={},E.prototype.setState=function(O,D){if(typeof O!="object"&&typeof O!="function"&&O!=null)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,O,D,"setState")},E.prototype.forceUpdate=function(O){this.updater.enqueueForceUpdate(this,O,"forceUpdate")};function T(){}T.prototype=E.prototype;function M(O,D,B){this.props=O,this.context=D,this.refs=N,this.updater=B||C}var k=M.prototype=new T;k.constructor=M,S(k,E.prototype),k.isPureReactComponent=!0;var _=Array.isArray;function R(){}var L={H:null,A:null,T:null,S:null},ne=Object.prototype.hasOwnProperty;function X(O,D,B){var V=B.ref;return{$$typeof:t,type:O,key:D,ref:V!==void 0?V:null,props:B}}function I(O,D){return X(O.type,D,O.props)}function H(O){return typeof O=="object"&&O!==null&&O.$$typeof===t}function q(O){var D={"=":"=0",":":"=2"};return"$"+O.replace(/[=:]/g,function(B){return D[B]})}var ce=/\/+/g;function de(O,D){return typeof O=="object"&&O!==null&&O.key!=null?q(""+O.key):D.toString(36)}function se(O){switch(O.status){case"fulfilled":return O.value;case"rejected":throw O.reason;default:switch(typeof O.status=="string"?O.then(R,R):(O.status="pending",O.then(function(D){O.status==="pending"&&(O.status="fulfilled",O.value=D)},function(D){O.status==="pending"&&(O.status="rejected",O.reason=D)})),O.status){case"fulfilled":return O.value;case"rejected":throw O.reason}}throw O}function P(O,D,B,V,Z){var be=typeof O;(be==="undefined"||be==="boolean")&&(O=null);var K=!1;if(O===null)K=!0;else switch(be){case"bigint":case"string":case"number":K=!0;break;case"object":switch(O.$$typeof){case t:case n:K=!0;break;case b:return K=O._init,P(K(O._payload),D,B,V,Z)}}if(K)return Z=Z(O),K=V===""?"."+de(O,0):V,_(Z)?(B="",K!=null&&(B=K.replace(ce,"$&/")+"/"),P(Z,D,B,"",function($){return $})):Z!=null&&(H(Z)&&(Z=I(Z,B+(Z.key==null||O&&O.key===Z.key?"":(""+Z.key).replace(ce,"$&/")+"/")+K)),D.push(Z)),1;K=0;var ge=V===""?".":V+":";if(_(O))for(var me=0;me>>1,G=P[ae];if(0>>1;aec(B,oe))Vc(Z,B)?(P[ae]=Z,P[V]=oe,ae=V):(P[ae]=B,P[D]=oe,ae=D);else if(Vc(Z,oe))P[ae]=Z,P[V]=oe,ae=V;else break e}}return W}function c(P,W){var oe=P.sortIndex-W.sortIndex;return oe!==0?oe:P.id-W.id}if(t.unstable_now=void 0,typeof performance=="object"&&typeof performance.now=="function"){var l=performance;t.unstable_now=function(){return l.now()}}else{var d=Date,m=d.now();t.unstable_now=function(){return d.now()-m}}var p=[],g=[],b=1,v=null,w=3,y=!1,C=!1,S=!1,N=!1,E=typeof setTimeout=="function"?setTimeout:null,T=typeof clearTimeout=="function"?clearTimeout:null,M=typeof setImmediate<"u"?setImmediate:null;function k(P){for(var W=a(g);W!==null;){if(W.callback===null)o(g);else if(W.startTime<=P)o(g),W.sortIndex=W.expirationTime,n(p,W);else break;W=a(g)}}function _(P){if(S=!1,k(P),!C)if(a(p)!==null)C=!0,R||(R=!0,q());else{var W=a(g);W!==null&&se(_,W.startTime-P)}}var R=!1,L=-1,ne=5,X=-1;function I(){return N?!0:!(t.unstable_now()-XP&&I());){var ae=v.callback;if(typeof ae=="function"){v.callback=null,w=v.priorityLevel;var G=ae(v.expirationTime<=P);if(P=t.unstable_now(),typeof G=="function"){v.callback=G,k(P),W=!0;break t}v===a(p)&&o(p),k(P)}else o(p);v=a(p)}if(v!==null)W=!0;else{var O=a(g);O!==null&&se(_,O.startTime-P),W=!1}}break e}finally{v=null,w=oe,y=!1}W=void 0}}finally{W?q():R=!1}}}var q;if(typeof M=="function")q=function(){M(H)};else if(typeof MessageChannel<"u"){var ce=new MessageChannel,de=ce.port2;ce.port1.onmessage=H,q=function(){de.postMessage(null)}}else q=function(){E(H,0)};function se(P,W){L=E(function(){P(t.unstable_now())},W)}t.unstable_IdlePriority=5,t.unstable_ImmediatePriority=1,t.unstable_LowPriority=4,t.unstable_NormalPriority=3,t.unstable_Profiling=null,t.unstable_UserBlockingPriority=2,t.unstable_cancelCallback=function(P){P.callback=null},t.unstable_forceFrameRate=function(P){0>P||125ae?(P.sortIndex=oe,n(g,P),a(p)===null&&P===a(g)&&(S?(T(L),L=-1):S=!0,se(_,oe-ae))):(P.sortIndex=G,n(p,P),C||y||(C=!0,R||(R=!0,q()))),P},t.unstable_shouldYield=I,t.unstable_wrapCallback=function(P){var W=w;return function(){var oe=w;w=W;try{return P.apply(this,arguments)}finally{w=oe}}}})(gp)),gp}var Ey;function T3(){return Ey||(Ey=1,hp.exports=k3()),hp.exports}var xp={exports:{}},hn={};/** * @license React * react-dom.production.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var ky;function M3(){if(ky)return hn;ky=1;var t=Xh();function n(p){var g="https://react.dev/errors/"+p;if(1"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(t)}catch(n){console.error(n)}}return t(),xp.exports=M3(),xp.exports}/** * @license React * react-dom-client.production.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var My;function R3(){if(My)return Nl;My=1;var t=T3(),n=Xh(),a=o2();function o(e){var r="https://react.dev/errors/"+e;if(1G||(e.current=ae[G],ae[G]=null,G--)}function B(e,r){G++,ae[G]=e.current,e.current=r}var V=O(null),Z=O(null),be=O(null),K=O(null);function ge(e,r){switch(B(be,r),B(Z,e),B(V,null),r.nodeType){case 9:case 11:e=(e=r.documentElement)&&(e=e.namespaceURI)?Bv(e):0;break;default:if(e=r.tagName,r=r.namespaceURI)r=Bv(r),e=$v(r,e);else switch(e){case"svg":e=1;break;case"math":e=2;break;default:e=0}}D(V),B(V,e)}function me(){D(V),D(Z),D(be)}function $(e){e.memoizedState!==null&&B(K,e);var r=V.current,i=$v(r,e.type);r!==i&&(B(Z,e),B(V,i))}function ie(e){Z.current===e&&(D(V),D(Z)),K.current===e&&(D(K),yl._currentValue=oe)}var ye,Se;function Be(e){if(ye===void 0)try{throw Error()}catch(i){var r=i.stack.trim().match(/\n( *(at )?)/);ye=r&&r[1]||"",Se=-1)":-1h||z[u]!==J[h]){var le=` `+z[u].replace(" at new "," at ");return e.displayName&&le.includes("")&&(le=le.replace("",e.displayName)),le}while(1<=u&&0<=h);break}}}finally{Ke=!1,Error.prepareStackTrace=i}return(i=e?e.displayName||e.name:"")?Be(i):""}function qt(e,r){switch(e.tag){case 26:case 27:case 5:return Be(e.type);case 16:return Be("Lazy");case 13:return e.child!==r&&r!==null?Be("Suspense Fallback"):Be("Suspense");case 19:return Be("SuspenseList");case 0:case 15:return We(e.type,!1);case 11:return We(e.type.render,!1);case 1:return We(e.type,!0);case 31:return Be("Activity");default:return""}}function vn(e){try{var r="",i=null;do r+=qt(e,i),i=e,e=e.return;while(e);return r}catch(u){return` Error generating stack: `+u.message+` `+u.stack}}var Xn=Object.prototype.hasOwnProperty,br=t.unstable_scheduleCallback,yn=t.unstable_cancelCallback,wn=t.unstable_shouldYield,Zn=t.unstable_requestPaint,Kt=t.unstable_now,po=t.unstable_getCurrentPriorityLevel,Pt=t.unstable_ImmediatePriority,Qn=t.unstable_UserBlockingPriority,Da=t.unstable_NormalPriority,Es=t.unstable_LowPriority,qr=t.unstable_IdlePriority,ho=t.log,Kr=t.unstable_setDisableYieldValue,Dn=null,yt=null;function On(e){if(typeof ho=="function"&&Kr(e),yt&&typeof yt.setStrictMode=="function")try{yt.setStrictMode(Dn,e)}catch{}}var Rt=Math.clz32?Math.clz32:go,Ai=Math.log,_i=Math.LN2;function go(e){return e>>>=0,e===0?32:31-(Ai(e)/_i|0)|0}var Wr=256,Oa=262144,Ar=4194304;function Wt(e){var r=e&42;if(r!==0)return r;switch(e&-e){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 e&261888;case 262144:case 524288:case 1048576:case 2097152:return e&3932160;case 4194304:case 8388608:case 16777216:case 33554432:return e&62914560;case 67108864:return 67108864;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 0;default:return e}}function La(e,r,i){var u=e.pendingLanes;if(u===0)return 0;var h=0,x=e.suspendedLanes,j=e.pingedLanes;e=e.warmLanes;var A=u&134217727;return A!==0?(u=A&~x,u!==0?h=Wt(u):(j&=A,j!==0?h=Wt(j):i||(i=A&~e,i!==0&&(h=Wt(i))))):(A=u&~x,A!==0?h=Wt(A):j!==0?h=Wt(j):i||(i=u&~e,i!==0&&(h=Wt(i)))),h===0?0:r!==0&&r!==h&&(r&x)===0&&(x=h&-h,i=r&-r,x>=i||x===32&&(i&4194048)!==0)?r:h}function De(e,r){return(e.pendingLanes&~(e.suspendedLanes&~e.pingedLanes)&r)===0}function rt(e,r){switch(e){case 1:case 2:case 4:case 8:case 64:return r+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 r+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 lt(){var e=Ar;return Ar<<=1,(Ar&62914560)===0&&(Ar=4194304),e}function rn(e){for(var r=[],i=0;31>i;i++)r.push(e);return r}function It(e,r){e.pendingLanes|=r,r!==268435456&&(e.suspendedLanes=0,e.pingedLanes=0,e.warmLanes=0)}function Jn(e,r,i,u,h,x){var j=e.pendingLanes;e.pendingLanes=i,e.suspendedLanes=0,e.pingedLanes=0,e.warmLanes=0,e.expiredLanes&=i,e.entangledLanes&=i,e.errorRecoveryDisabledLanes&=i,e.shellSuspendCounter=0;var A=e.entanglements,z=e.expirationTimes,J=e.hiddenUpdates;for(i=j&~i;0"u")return null;try{return e.activeElement||e.body}catch{return e.body}}var h5=/[\n"\\]/g;function rr(e){return e.replace(h5,function(r){return"\\"+r.charCodeAt(0).toString(16)+" "})}function af(e,r,i,u,h,x,j,A){e.name="",j!=null&&typeof j!="function"&&typeof j!="symbol"&&typeof j!="boolean"?e.type=j:e.removeAttribute("type"),r!=null?j==="number"?(r===0&&e.value===""||e.value!=r)&&(e.value=""+nr(r)):e.value!==""+nr(r)&&(e.value=""+nr(r)):j!=="submit"&&j!=="reset"||e.removeAttribute("value"),r!=null?sf(e,j,nr(r)):i!=null?sf(e,j,nr(i)):u!=null&&e.removeAttribute("value"),h==null&&x!=null&&(e.defaultChecked=!!x),h!=null&&(e.checked=h&&typeof h!="function"&&typeof h!="symbol"),A!=null&&typeof A!="function"&&typeof A!="symbol"&&typeof A!="boolean"?e.name=""+nr(A):e.removeAttribute("name")}function Ox(e,r,i,u,h,x,j,A){if(x!=null&&typeof x!="function"&&typeof x!="symbol"&&typeof x!="boolean"&&(e.type=x),r!=null||i!=null){if(!(x!=="submit"&&x!=="reset"||r!=null)){rf(e);return}i=i!=null?""+nr(i):"",r=r!=null?""+nr(r):i,A||r===e.value||(e.value=r),e.defaultValue=r}u=u??h,u=typeof u!="function"&&typeof u!="symbol"&&!!u,e.checked=A?e.checked:!!u,e.defaultChecked=!!u,j!=null&&typeof j!="function"&&typeof j!="symbol"&&typeof j!="boolean"&&(e.name=j),rf(e)}function sf(e,r,i){r==="number"&&xc(e.ownerDocument)===e||e.defaultValue===""+i||(e.defaultValue=""+i)}function bo(e,r,i,u){if(e=e.options,r){r={};for(var h=0;h"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),df=!1;if(Jr)try{var Ii={};Object.defineProperty(Ii,"passive",{get:function(){df=!0}}),window.addEventListener("test",Ii,Ii),window.removeEventListener("test",Ii,Ii)}catch{df=!1}var za=null,ff=null,vc=null;function $x(){if(vc)return vc;var e,r=ff,i=r.length,u,h="value"in za?za.value:za.textContent,x=h.length;for(e=0;e=$i),qx=" ",Kx=!1;function Wx(e,r){switch(e){case"keyup":return G5.indexOf(r.keyCode)!==-1;case"keydown":return r.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function Xx(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var jo=!1;function F5(e,r){switch(e){case"compositionend":return Xx(r);case"keypress":return r.which!==32?null:(Kx=!0,qx);case"textInput":return e=r.data,e===qx&&Kx?null:e;default:return null}}function Y5(e,r){if(jo)return e==="compositionend"||!xf&&Wx(e,r)?(e=$x(),vc=ff=za=null,jo=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(r.ctrlKey||r.altKey||r.metaKey)||r.ctrlKey&&r.altKey){if(r.char&&1=r)return{node:i,offset:r-e};e=u}e:{for(;i;){if(i.nextSibling){i=i.nextSibling;break e}i=i.parentNode}i=void 0}i=a1(i)}}function o1(e,r){return e&&r?e===r?!0:e&&e.nodeType===3?!1:r&&r.nodeType===3?o1(e,r.parentNode):"contains"in e?e.contains(r):e.compareDocumentPosition?!!(e.compareDocumentPosition(r)&16):!1:!1}function i1(e){e=e!=null&&e.ownerDocument!=null&&e.ownerDocument.defaultView!=null?e.ownerDocument.defaultView:window;for(var r=xc(e.document);r instanceof e.HTMLIFrameElement;){try{var i=typeof r.contentWindow.location.href=="string"}catch{i=!1}if(i)e=r.contentWindow;else break;r=xc(e.document)}return r}function yf(e){var r=e&&e.nodeName&&e.nodeName.toLowerCase();return r&&(r==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||r==="textarea"||e.contentEditable==="true")}var e4=Jr&&"documentMode"in document&&11>=document.documentMode,Co=null,wf=null,Fi=null,jf=!1;function l1(e,r,i){var u=i.window===i?i.document:i.nodeType===9?i:i.ownerDocument;jf||Co==null||Co!==xc(u)||(u=Co,"selectionStart"in u&&yf(u)?u={start:u.selectionStart,end:u.selectionEnd}:(u=(u.ownerDocument&&u.ownerDocument.defaultView||window).getSelection(),u={anchorNode:u.anchorNode,anchorOffset:u.anchorOffset,focusNode:u.focusNode,focusOffset:u.focusOffset}),Fi&&Vi(Fi,u)||(Fi=u,u=fu(wf,"onSelect"),0>=j,h-=j,Dr=1<<32-Rt(r)+h|i<$e?(Qe=ke,ke=null):Qe=ke.sibling;var st=ee(F,ke,Q[$e],fe);if(st===null){ke===null&&(ke=Qe);break}e&&ke&&st.alternate===null&&r(F,ke),U=x(st,U,$e),at===null?Re=st:at.sibling=st,at=st,ke=Qe}if($e===Q.length)return i(F,ke),tt&&ta(F,$e),Re;if(ke===null){for(;$e$e?(Qe=ke,ke=null):Qe=ke.sibling;var as=ee(F,ke,st.value,fe);if(as===null){ke===null&&(ke=Qe);break}e&&ke&&as.alternate===null&&r(F,ke),U=x(as,U,$e),at===null?Re=as:at.sibling=as,at=as,ke=Qe}if(st.done)return i(F,ke),tt&&ta(F,$e),Re;if(ke===null){for(;!st.done;$e++,st=Q.next())st=he(F,st.value,fe),st!==null&&(U=x(st,U,$e),at===null?Re=st:at.sibling=st,at=st);return tt&&ta(F,$e),Re}for(ke=u(ke);!st.done;$e++,st=Q.next())st=re(ke,F,$e,st.value,fe),st!==null&&(e&&st.alternate!==null&&ke.delete(st.key===null?$e:st.key),U=x(st,U,$e),at===null?Re=st:at.sibling=st,at=st);return e&&ke.forEach(function(y3){return r(F,y3)}),tt&&ta(F,$e),Re}function ht(F,U,Q,fe){if(typeof Q=="object"&&Q!==null&&Q.type===S&&Q.key===null&&(Q=Q.props.children),typeof Q=="object"&&Q!==null){switch(Q.$$typeof){case y:e:{for(var Re=Q.key;U!==null;){if(U.key===Re){if(Re=Q.type,Re===S){if(U.tag===7){i(F,U.sibling),fe=h(U,Q.props.children),fe.return=F,F=fe;break e}}else if(U.elementType===Re||typeof Re=="object"&&Re!==null&&Re.$$typeof===ne&&Ps(Re)===U.type){i(F,U.sibling),fe=h(U,Q.props),Zi(fe,Q),fe.return=F,F=fe;break e}i(F,U);break}else r(F,U);U=U.sibling}Q.type===S?(fe=_s(Q.props.children,F.mode,fe,Q.key),fe.return=F,F=fe):(fe=Mc(Q.type,Q.key,Q.props,null,F.mode,fe),Zi(fe,Q),fe.return=F,F=fe)}return j(F);case C:e:{for(Re=Q.key;U!==null;){if(U.key===Re)if(U.tag===4&&U.stateNode.containerInfo===Q.containerInfo&&U.stateNode.implementation===Q.implementation){i(F,U.sibling),fe=h(U,Q.children||[]),fe.return=F,F=fe;break e}else{i(F,U);break}else r(F,U);U=U.sibling}fe=Mf(Q,F.mode,fe),fe.return=F,F=fe}return j(F);case ne:return Q=Ps(Q),ht(F,U,Q,fe)}if(se(Q))return Ee(F,U,Q,fe);if(q(Q)){if(Re=q(Q),typeof Re!="function")throw Error(o(150));return Q=Re.call(Q),Oe(F,U,Q,fe)}if(typeof Q.then=="function")return ht(F,U,zc(Q),fe);if(Q.$$typeof===M)return ht(F,U,_c(F,Q),fe);Pc(F,Q)}return typeof Q=="string"&&Q!==""||typeof Q=="number"||typeof Q=="bigint"?(Q=""+Q,U!==null&&U.tag===6?(i(F,U.sibling),fe=h(U,Q),fe.return=F,F=fe):(i(F,U),fe=Tf(Q,F.mode,fe),fe.return=F,F=fe),j(F)):i(F,U)}return function(F,U,Q,fe){try{Xi=0;var Re=ht(F,U,Q,fe);return Oo=null,Re}catch(ke){if(ke===Do||ke===Oc)throw ke;var at=Pn(29,ke,null,F.mode);return at.lanes=fe,at.return=F,at}finally{}}}var Us=A1(!0),_1=A1(!1),$a=!1;function $f(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,lanes:0,hiddenCallbacks:null},callbacks:null}}function Hf(e,r){e=e.updateQueue,r.updateQueue===e&&(r.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,callbacks:null})}function Ha(e){return{lane:e,tag:0,payload:null,callback:null,next:null}}function Ga(e,r,i){var u=e.updateQueue;if(u===null)return null;if(u=u.shared,(it&2)!==0){var h=u.pending;return h===null?r.next=r:(r.next=h.next,h.next=r),u.pending=r,r=Tc(e),h1(e,null,i),r}return kc(e,u,r,i),Tc(e)}function Qi(e,r,i){if(r=r.updateQueue,r!==null&&(r=r.shared,(i&4194048)!==0)){var u=r.lanes;u&=e.pendingLanes,i|=u,r.lanes=i,bt(e,i)}}function Gf(e,r){var i=e.updateQueue,u=e.alternate;if(u!==null&&(u=u.updateQueue,i===u)){var h=null,x=null;if(i=i.firstBaseUpdate,i!==null){do{var j={lane:i.lane,tag:i.tag,payload:i.payload,callback:null,next:null};x===null?h=x=j:x=x.next=j,i=i.next}while(i!==null);x===null?h=x=r:x=x.next=r}else h=x=r;i={baseState:u.baseState,firstBaseUpdate:h,lastBaseUpdate:x,shared:u.shared,callbacks:u.callbacks},e.updateQueue=i;return}e=i.lastBaseUpdate,e===null?i.firstBaseUpdate=r:e.next=r,i.lastBaseUpdate=r}var Vf=!1;function Ji(){if(Vf){var e=_o;if(e!==null)throw e}}function el(e,r,i,u){Vf=!1;var h=e.updateQueue;$a=!1;var x=h.firstBaseUpdate,j=h.lastBaseUpdate,A=h.shared.pending;if(A!==null){h.shared.pending=null;var z=A,J=z.next;z.next=null,j===null?x=J:j.next=J,j=z;var le=e.alternate;le!==null&&(le=le.updateQueue,A=le.lastBaseUpdate,A!==j&&(A===null?le.firstBaseUpdate=J:A.next=J,le.lastBaseUpdate=z))}if(x!==null){var he=h.baseState;j=0,le=J=z=null,A=x;do{var ee=A.lane&-536870913,re=ee!==A.lane;if(re?(Ze&ee)===ee:(u&ee)===ee){ee!==0&&ee===Ao&&(Vf=!0),le!==null&&(le=le.next={lane:0,tag:A.tag,payload:A.payload,callback:null,next:null});e:{var Ee=e,Oe=A;ee=r;var ht=i;switch(Oe.tag){case 1:if(Ee=Oe.payload,typeof Ee=="function"){he=Ee.call(ht,he,ee);break e}he=Ee;break e;case 3:Ee.flags=Ee.flags&-65537|128;case 0:if(Ee=Oe.payload,ee=typeof Ee=="function"?Ee.call(ht,he,ee):Ee,ee==null)break e;he=v({},he,ee);break e;case 2:$a=!0}}ee=A.callback,ee!==null&&(e.flags|=64,re&&(e.flags|=8192),re=h.callbacks,re===null?h.callbacks=[ee]:re.push(ee))}else re={lane:ee,tag:A.tag,payload:A.payload,callback:A.callback,next:null},le===null?(J=le=re,z=he):le=le.next=re,j|=ee;if(A=A.next,A===null){if(A=h.shared.pending,A===null)break;re=A,A=re.next,re.next=null,h.lastBaseUpdate=re,h.shared.pending=null}}while(!0);le===null&&(z=he),h.baseState=z,h.firstBaseUpdate=J,h.lastBaseUpdate=le,x===null&&(h.shared.lanes=0),Ka|=j,e.lanes=j,e.memoizedState=he}}function D1(e,r){if(typeof e!="function")throw Error(o(191,e));e.call(r)}function O1(e,r){var i=e.callbacks;if(i!==null)for(e.callbacks=null,e=0;ex?x:8;var j=P.T,A={};P.T=A,cm(e,!1,r,i);try{var z=h(),J=P.S;if(J!==null&&J(A,z),z!==null&&typeof z=="object"&&typeof z.then=="function"){var le=c4(z,u);rl(e,r,le,Hn(e))}else rl(e,r,u,Hn(e))}catch(he){rl(e,r,{then:function(){},status:"rejected",reason:he},Hn())}finally{W.p=x,j!==null&&A.types!==null&&(j.types=A.types),P.T=j}}function h4(){}function im(e,r,i,u){if(e.tag!==5)throw Error(o(476));var h=fb(e).queue;db(e,h,r,oe,i===null?h4:function(){return mb(e),i(u)})}function fb(e){var r=e.memoizedState;if(r!==null)return r;r={memoizedState:oe,baseState:oe,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:sa,lastRenderedState:oe},next:null};var i={};return r.next={memoizedState:i,baseState:i,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:sa,lastRenderedState:i},next:null},e.memoizedState=r,e=e.alternate,e!==null&&(e.memoizedState=r),r}function mb(e){var r=fb(e);r.next===null&&(r=e.alternate.memoizedState),rl(e,r.next.queue,{},Hn())}function lm(){return on(yl)}function pb(){return zt().memoizedState}function hb(){return zt().memoizedState}function g4(e){for(var r=e.return;r!==null;){switch(r.tag){case 24:case 3:var i=Hn();e=Ha(i);var u=Ga(r,e,i);u!==null&&(Tn(u,r,i),Qi(u,r,i)),r={cache:Pf()},e.payload=r;return}r=r.return}}function x4(e,r,i){var u=Hn();i={lane:u,revertLane:0,gesture:null,action:i,hasEagerState:!1,eagerState:null,next:null},qc(e)?xb(r,i):(i=Ef(e,r,i,u),i!==null&&(Tn(i,e,u),bb(i,r,u)))}function gb(e,r,i){var u=Hn();rl(e,r,i,u)}function rl(e,r,i,u){var h={lane:u,revertLane:0,gesture:null,action:i,hasEagerState:!1,eagerState:null,next:null};if(qc(e))xb(r,h);else{var x=e.alternate;if(e.lanes===0&&(x===null||x.lanes===0)&&(x=r.lastRenderedReducer,x!==null))try{var j=r.lastRenderedState,A=x(j,i);if(h.hasEagerState=!0,h.eagerState=A,zn(A,j))return kc(e,r,h,0),xt===null&&Ec(),!1}catch{}finally{}if(i=Ef(e,r,h,u),i!==null)return Tn(i,e,u),bb(i,r,u),!0}return!1}function cm(e,r,i,u){if(u={lane:2,revertLane:$m(),gesture:null,action:u,hasEagerState:!1,eagerState:null,next:null},qc(e)){if(r)throw Error(o(479))}else r=Ef(e,i,u,2),r!==null&&Tn(r,e,2)}function qc(e){var r=e.alternate;return e===Ie||r!==null&&r===Ie}function xb(e,r){zo=Bc=!0;var i=e.pending;i===null?r.next=r:(r.next=i.next,i.next=r),e.pending=r}function bb(e,r,i){if((i&4194048)!==0){var u=r.lanes;u&=e.pendingLanes,i|=u,r.lanes=i,bt(e,i)}}var al={readContext:on,use:Gc,useCallback:At,useContext:At,useEffect:At,useImperativeHandle:At,useLayoutEffect:At,useInsertionEffect:At,useMemo:At,useReducer:At,useRef:At,useState:At,useDebugValue:At,useDeferredValue:At,useTransition:At,useSyncExternalStore:At,useId:At,useHostTransitionStatus:At,useFormState:At,useActionState:At,useOptimistic:At,useMemoCache:At,useCacheRefresh:At};al.useEffectEvent=At;var vb={readContext:on,use:Gc,useCallback:function(e,r){return gn().memoizedState=[e,r===void 0?null:r],e},useContext:on,useEffect:nb,useImperativeHandle:function(e,r,i){i=i!=null?i.concat([e]):null,Fc(4194308,4,ob.bind(null,r,e),i)},useLayoutEffect:function(e,r){return Fc(4194308,4,e,r)},useInsertionEffect:function(e,r){Fc(4,2,e,r)},useMemo:function(e,r){var i=gn();r=r===void 0?null:r;var u=e();if(Bs){On(!0);try{e()}finally{On(!1)}}return i.memoizedState=[u,r],u},useReducer:function(e,r,i){var u=gn();if(i!==void 0){var h=i(r);if(Bs){On(!0);try{i(r)}finally{On(!1)}}}else h=r;return u.memoizedState=u.baseState=h,e={pending:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:h},u.queue=e,e=e.dispatch=x4.bind(null,Ie,e),[u.memoizedState,e]},useRef:function(e){var r=gn();return e={current:e},r.memoizedState=e},useState:function(e){e=nm(e);var r=e.queue,i=gb.bind(null,Ie,r);return r.dispatch=i,[e.memoizedState,i]},useDebugValue:sm,useDeferredValue:function(e,r){var i=gn();return om(i,e,r)},useTransition:function(){var e=nm(!1);return e=db.bind(null,Ie,e.queue,!0,!1),gn().memoizedState=e,[!1,e]},useSyncExternalStore:function(e,r,i){var u=Ie,h=gn();if(tt){if(i===void 0)throw Error(o(407));i=i()}else{if(i=r(),xt===null)throw Error(o(349));(Ze&127)!==0||B1(u,r,i)}h.memoizedState=i;var x={value:i,getSnapshot:r};return h.queue=x,nb(H1.bind(null,u,x,e),[e]),u.flags|=2048,Io(9,{destroy:void 0},$1.bind(null,u,x,i,r),null),i},useId:function(){var e=gn(),r=xt.identifierPrefix;if(tt){var i=Or,u=Dr;i=(u&~(1<<32-Rt(u)-1)).toString(32)+i,r="_"+r+"R_"+i,i=$c++,0<\/script>",x=x.removeChild(x.firstChild);break;case"select":x=typeof u.is=="string"?j.createElement("select",{is:u.is}):j.createElement("select"),u.multiple?x.multiple=!0:u.size&&(x.size=u.size);break;default:x=typeof u.is=="string"?j.createElement(h,{is:u.is}):j.createElement(h)}}x[te]=r,x[je]=u;e:for(j=r.child;j!==null;){if(j.tag===5||j.tag===6)x.appendChild(j.stateNode);else if(j.tag!==4&&j.tag!==27&&j.child!==null){j.child.return=j,j=j.child;continue}if(j===r)break e;for(;j.sibling===null;){if(j.return===null||j.return===r)break e;j=j.return}j.sibling.return=j.return,j=j.sibling}r.stateNode=x;e:switch(cn(x,h,u),h){case"button":case"input":case"select":case"textarea":u=!!u.autoFocus;break e;case"img":u=!0;break e;default:u=!1}u&&ia(r)}}return jt(r),Cm(r,r.type,e===null?null:e.memoizedProps,r.pendingProps,i),null;case 6:if(e&&r.stateNode!=null)e.memoizedProps!==u&&ia(r);else{if(typeof u!="string"&&r.stateNode===null)throw Error(o(166));if(e=be.current,Mo(r)){if(e=r.stateNode,i=r.memoizedProps,u=null,h=sn,h!==null)switch(h.tag){case 27:case 5:u=h.memoizedProps}e[te]=r,e=!!(e.nodeValue===i||u!==null&&u.suppressHydrationWarning===!0||Iv(e.nodeValue,i)),e||Ua(r,!0)}else e=mu(e).createTextNode(u),e[te]=r,r.stateNode=e}return jt(r),null;case 31:if(i=r.memoizedState,e===null||e.memoizedState!==null){if(u=Mo(r),i!==null){if(e===null){if(!u)throw Error(o(318));if(e=r.memoizedState,e=e!==null?e.dehydrated:null,!e)throw Error(o(557));e[te]=r}else Ds(),(r.flags&128)===0&&(r.memoizedState=null),r.flags|=4;jt(r),e=!1}else i=Df(),e!==null&&e.memoizedState!==null&&(e.memoizedState.hydrationErrors=i),e=!0;if(!e)return r.flags&256?(Un(r),r):(Un(r),null);if((r.flags&128)!==0)throw Error(o(558))}return jt(r),null;case 13:if(u=r.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(h=Mo(r),u!==null&&u.dehydrated!==null){if(e===null){if(!h)throw Error(o(318));if(h=r.memoizedState,h=h!==null?h.dehydrated:null,!h)throw Error(o(317));h[te]=r}else Ds(),(r.flags&128)===0&&(r.memoizedState=null),r.flags|=4;jt(r),h=!1}else h=Df(),e!==null&&e.memoizedState!==null&&(e.memoizedState.hydrationErrors=h),h=!0;if(!h)return r.flags&256?(Un(r),r):(Un(r),null)}return Un(r),(r.flags&128)!==0?(r.lanes=i,r):(i=u!==null,e=e!==null&&e.memoizedState!==null,i&&(u=r.child,h=null,u.alternate!==null&&u.alternate.memoizedState!==null&&u.alternate.memoizedState.cachePool!==null&&(h=u.alternate.memoizedState.cachePool.pool),x=null,u.memoizedState!==null&&u.memoizedState.cachePool!==null&&(x=u.memoizedState.cachePool.pool),x!==h&&(u.flags|=2048)),i!==e&&i&&(r.child.flags|=8192),Qc(r,r.updateQueue),jt(r),null);case 4:return me(),e===null&&Fm(r.stateNode.containerInfo),jt(r),null;case 10:return ra(r.type),jt(r),null;case 19:if(D(Lt),u=r.memoizedState,u===null)return jt(r),null;if(h=(r.flags&128)!==0,x=u.rendering,x===null)if(h)ol(u,!1);else{if(_t!==0||e!==null&&(e.flags&128)!==0)for(e=r.child;e!==null;){if(x=Uc(e),x!==null){for(r.flags|=128,ol(u,!1),e=x.updateQueue,r.updateQueue=e,Qc(r,e),r.subtreeFlags=0,e=i,i=r.child;i!==null;)g1(i,e),i=i.sibling;return B(Lt,Lt.current&1|2),tt&&ta(r,u.treeForkCount),r.child}e=e.sibling}u.tail!==null&&Kt()>ru&&(r.flags|=128,h=!0,ol(u,!1),r.lanes=4194304)}else{if(!h)if(e=Uc(x),e!==null){if(r.flags|=128,h=!0,e=e.updateQueue,r.updateQueue=e,Qc(r,e),ol(u,!0),u.tail===null&&u.tailMode==="hidden"&&!x.alternate&&!tt)return jt(r),null}else 2*Kt()-u.renderingStartTime>ru&&i!==536870912&&(r.flags|=128,h=!0,ol(u,!1),r.lanes=4194304);u.isBackwards?(x.sibling=r.child,r.child=x):(e=u.last,e!==null?e.sibling=x:r.child=x,u.last=x)}return u.tail!==null?(e=u.tail,u.rendering=e,u.tail=e.sibling,u.renderingStartTime=Kt(),e.sibling=null,i=Lt.current,B(Lt,h?i&1|2:i&1),tt&&ta(r,u.treeForkCount),e):(jt(r),null);case 22:case 23:return Un(r),Yf(),u=r.memoizedState!==null,e!==null?e.memoizedState!==null!==u&&(r.flags|=8192):u&&(r.flags|=8192),u?(i&536870912)!==0&&(r.flags&128)===0&&(jt(r),r.subtreeFlags&6&&(r.flags|=8192)):jt(r),i=r.updateQueue,i!==null&&Qc(r,i.retryQueue),i=null,e!==null&&e.memoizedState!==null&&e.memoizedState.cachePool!==null&&(i=e.memoizedState.cachePool.pool),u=null,r.memoizedState!==null&&r.memoizedState.cachePool!==null&&(u=r.memoizedState.cachePool.pool),u!==i&&(r.flags|=2048),e!==null&&D(zs),null;case 24:return i=null,e!==null&&(i=e.memoizedState.cache),r.memoizedState.cache!==i&&(r.flags|=2048),ra(Ut),jt(r),null;case 25:return null;case 30:return null}throw Error(o(156,r.tag))}function j4(e,r){switch(Af(r),r.tag){case 1:return e=r.flags,e&65536?(r.flags=e&-65537|128,r):null;case 3:return ra(Ut),me(),e=r.flags,(e&65536)!==0&&(e&128)===0?(r.flags=e&-65537|128,r):null;case 26:case 27:case 5:return ie(r),null;case 31:if(r.memoizedState!==null){if(Un(r),r.alternate===null)throw Error(o(340));Ds()}return e=r.flags,e&65536?(r.flags=e&-65537|128,r):null;case 13:if(Un(r),e=r.memoizedState,e!==null&&e.dehydrated!==null){if(r.alternate===null)throw Error(o(340));Ds()}return e=r.flags,e&65536?(r.flags=e&-65537|128,r):null;case 19:return D(Lt),null;case 4:return me(),null;case 10:return ra(r.type),null;case 22:case 23:return Un(r),Yf(),e!==null&&D(zs),e=r.flags,e&65536?(r.flags=e&-65537|128,r):null;case 24:return ra(Ut),null;case 25:return null;default:return null}}function Gb(e,r){switch(Af(r),r.tag){case 3:ra(Ut),me();break;case 26:case 27:case 5:ie(r);break;case 4:me();break;case 31:r.memoizedState!==null&&Un(r);break;case 13:Un(r);break;case 19:D(Lt);break;case 10:ra(r.type);break;case 22:case 23:Un(r),Yf(),e!==null&&D(zs);break;case 24:ra(Ut)}}function il(e,r){try{var i=r.updateQueue,u=i!==null?i.lastEffect:null;if(u!==null){var h=u.next;i=h;do{if((i.tag&e)===e){u=void 0;var x=i.create,j=i.inst;u=x(),j.destroy=u}i=i.next}while(i!==h)}}catch(A){ut(r,r.return,A)}}function Ya(e,r,i){try{var u=r.updateQueue,h=u!==null?u.lastEffect:null;if(h!==null){var x=h.next;u=x;do{if((u.tag&e)===e){var j=u.inst,A=j.destroy;if(A!==void 0){j.destroy=void 0,h=r;var z=i,J=A;try{J()}catch(le){ut(h,z,le)}}}u=u.next}while(u!==x)}}catch(le){ut(r,r.return,le)}}function Vb(e){var r=e.updateQueue;if(r!==null){var i=e.stateNode;try{O1(r,i)}catch(u){ut(e,e.return,u)}}}function Fb(e,r,i){i.props=$s(e.type,e.memoizedProps),i.state=e.memoizedState;try{i.componentWillUnmount()}catch(u){ut(e,r,u)}}function ll(e,r){try{var i=e.ref;if(i!==null){switch(e.tag){case 26:case 27:case 5:var u=e.stateNode;break;case 30:u=e.stateNode;break;default:u=e.stateNode}typeof i=="function"?e.refCleanup=i(u):i.current=u}}catch(h){ut(e,r,h)}}function Lr(e,r){var i=e.ref,u=e.refCleanup;if(i!==null)if(typeof u=="function")try{u()}catch(h){ut(e,r,h)}finally{e.refCleanup=null,e=e.alternate,e!=null&&(e.refCleanup=null)}else if(typeof i=="function")try{i(null)}catch(h){ut(e,r,h)}else i.current=null}function Yb(e){var r=e.type,i=e.memoizedProps,u=e.stateNode;try{e:switch(r){case"button":case"input":case"select":case"textarea":i.autoFocus&&u.focus();break e;case"img":i.src?u.src=i.src:i.srcSet&&(u.srcset=i.srcSet)}}catch(h){ut(e,e.return,h)}}function Sm(e,r,i){try{var u=e.stateNode;V4(u,e.type,i,r),u[je]=r}catch(h){ut(e,e.return,h)}}function qb(e){return e.tag===5||e.tag===3||e.tag===26||e.tag===27&&Ja(e.type)||e.tag===4}function Nm(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||qb(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.tag===27&&Ja(e.type)||e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function Em(e,r,i){var u=e.tag;if(u===5||u===6)e=e.stateNode,r?(i.nodeType===9?i.body:i.nodeName==="HTML"?i.ownerDocument.body:i).insertBefore(e,r):(r=i.nodeType===9?i.body:i.nodeName==="HTML"?i.ownerDocument.body:i,r.appendChild(e),i=i._reactRootContainer,i!=null||r.onclick!==null||(r.onclick=Qr));else if(u!==4&&(u===27&&Ja(e.type)&&(i=e.stateNode,r=null),e=e.child,e!==null))for(Em(e,r,i),e=e.sibling;e!==null;)Em(e,r,i),e=e.sibling}function Jc(e,r,i){var u=e.tag;if(u===5||u===6)e=e.stateNode,r?i.insertBefore(e,r):i.appendChild(e);else if(u!==4&&(u===27&&Ja(e.type)&&(i=e.stateNode),e=e.child,e!==null))for(Jc(e,r,i),e=e.sibling;e!==null;)Jc(e,r,i),e=e.sibling}function Kb(e){var r=e.stateNode,i=e.memoizedProps;try{for(var u=e.type,h=r.attributes;h.length;)r.removeAttributeNode(h[0]);cn(r,u,i),r[te]=e,r[je]=i}catch(x){ut(e,e.return,x)}}var la=!1,Ht=!1,km=!1,Wb=typeof WeakSet=="function"?WeakSet:Set,Zt=null;function C4(e,r){if(e=e.containerInfo,Km=yu,e=i1(e),yf(e)){if("selectionStart"in e)var i={start:e.selectionStart,end:e.selectionEnd};else e:{i=(i=e.ownerDocument)&&i.defaultView||window;var u=i.getSelection&&i.getSelection();if(u&&u.rangeCount!==0){i=u.anchorNode;var h=u.anchorOffset,x=u.focusNode;u=u.focusOffset;try{i.nodeType,x.nodeType}catch{i=null;break e}var j=0,A=-1,z=-1,J=0,le=0,he=e,ee=null;t:for(;;){for(var re;he!==i||h!==0&&he.nodeType!==3||(A=j+h),he!==x||u!==0&&he.nodeType!==3||(z=j+u),he.nodeType===3&&(j+=he.nodeValue.length),(re=he.firstChild)!==null;)ee=he,he=re;for(;;){if(he===e)break t;if(ee===i&&++J===h&&(A=j),ee===x&&++le===u&&(z=j),(re=he.nextSibling)!==null)break;he=ee,ee=he.parentNode}he=re}i=A===-1||z===-1?null:{start:A,end:z}}else i=null}i=i||{start:0,end:0}}else i=null;for(Wm={focusedElem:e,selectionRange:i},yu=!1,Zt=r;Zt!==null;)if(r=Zt,e=r.child,(r.subtreeFlags&1028)!==0&&e!==null)e.return=r,Zt=e;else for(;Zt!==null;){switch(r=Zt,x=r.alternate,e=r.flags,r.tag){case 0:if((e&4)!==0&&(e=r.updateQueue,e=e!==null?e.events:null,e!==null))for(i=0;i title"))),cn(x,u,i),x[te]=e,Xt(x),u=x;break e;case"link":var j=ty("link","href",h).get(u+(i.href||""));if(j){for(var A=0;Aht&&(j=ht,ht=Oe,Oe=j);var F=s1(A,Oe),U=s1(A,ht);if(F&&U&&(re.rangeCount!==1||re.anchorNode!==F.node||re.anchorOffset!==F.offset||re.focusNode!==U.node||re.focusOffset!==U.offset)){var Q=he.createRange();Q.setStart(F.node,F.offset),re.removeAllRanges(),Oe>ht?(re.addRange(Q),re.extend(U.node,U.offset)):(Q.setEnd(U.node,U.offset),re.addRange(Q))}}}}for(he=[],re=A;re=re.parentNode;)re.nodeType===1&&he.push({element:re,left:re.scrollLeft,top:re.scrollTop});for(typeof A.focus=="function"&&A.focus(),A=0;Ai?32:i,P.T=null,i=Om,Om=null;var x=Xa,j=ma;if(Ft=0,Go=Xa=null,ma=0,(it&6)!==0)throw Error(o(331));var A=it;if(it|=4,ov(x.current),rv(x,x.current,j,i),it=A,pl(0,!1),yt&&typeof yt.onPostCommitFiberRoot=="function")try{yt.onPostCommitFiberRoot(Dn,x)}catch{}return!0}finally{W.p=h,P.T=u,Sv(e,r)}}function Ev(e,r,i){r=sr(i,r),r=mm(e.stateNode,r,2),e=Ga(e,r,2),e!==null&&(It(e,2),zr(e))}function ut(e,r,i){if(e.tag===3)Ev(e,e,i);else for(;r!==null;){if(r.tag===3){Ev(r,e,i);break}else if(r.tag===1){var u=r.stateNode;if(typeof r.type.getDerivedStateFromError=="function"||typeof u.componentDidCatch=="function"&&(Wa===null||!Wa.has(u))){e=sr(i,e),i=kb(2),u=Ga(r,i,2),u!==null&&(Tb(i,u,r,e),It(u,2),zr(u));break}}r=r.return}}function Im(e,r,i){var u=e.pingCache;if(u===null){u=e.pingCache=new E4;var h=new Set;u.set(r,h)}else h=u.get(r),h===void 0&&(h=new Set,u.set(r,h));h.has(i)||(Rm=!0,h.add(i),e=A4.bind(null,e,r,i),r.then(e,e))}function A4(e,r,i){var u=e.pingCache;u!==null&&u.delete(r),e.pingedLanes|=e.suspendedLanes&i,e.warmLanes&=~i,xt===e&&(Ze&i)===i&&(_t===4||_t===3&&(Ze&62914560)===Ze&&300>Kt()-nu?(it&2)===0&&Vo(e,0):Am|=i,Ho===Ze&&(Ho=0)),zr(e)}function kv(e,r){r===0&&(r=lt()),e=As(e,r),e!==null&&(It(e,r),zr(e))}function _4(e){var r=e.memoizedState,i=0;r!==null&&(i=r.retryLane),kv(e,i)}function D4(e,r){var i=0;switch(e.tag){case 31:case 13:var u=e.stateNode,h=e.memoizedState;h!==null&&(i=h.retryLane);break;case 19:u=e.stateNode;break;case 22:u=e.stateNode._retryCache;break;default:throw Error(o(314))}u!==null&&u.delete(r),kv(e,i)}function O4(e,r){return br(e,r)}var cu=null,Yo=null,Um=!1,uu=!1,Bm=!1,Qa=0;function zr(e){e!==Yo&&e.next===null&&(Yo===null?cu=Yo=e:Yo=Yo.next=e),uu=!0,Um||(Um=!0,z4())}function pl(e,r){if(!Bm&&uu){Bm=!0;do for(var i=!1,u=cu;u!==null;){if(e!==0){var h=u.pendingLanes;if(h===0)var x=0;else{var j=u.suspendedLanes,A=u.pingedLanes;x=(1<<31-Rt(42|e)+1)-1,x&=h&~(j&~A),x=x&201326741?x&201326741|1:x?x|2:0}x!==0&&(i=!0,Av(u,x))}else x=Ze,x=La(u,u===xt?x:0,u.cancelPendingCommit!==null||u.timeoutHandle!==-1),(x&3)===0||De(u,x)||(i=!0,Av(u,x));u=u.next}while(i);Bm=!1}}function L4(){Tv()}function Tv(){uu=Um=!1;var e=0;Qa!==0&&Y4()&&(e=Qa);for(var r=Kt(),i=null,u=cu;u!==null;){var h=u.next,x=Mv(u,r);x===0?(u.next=null,i===null?cu=h:i.next=h,h===null&&(Yo=i)):(i=u,(e!==0||(x&3)!==0)&&(uu=!0)),u=h}Ft!==0&&Ft!==5||pl(e),Qa!==0&&(Qa=0)}function Mv(e,r){for(var i=e.suspendedLanes,u=e.pingedLanes,h=e.expirationTimes,x=e.pendingLanes&-62914561;0A)break;var le=z.transferSize,he=z.initiatorType;le&&Uv(he)&&(z=z.responseEnd,j+=le*(z"u"?null:document;function Zv(e,r,i){var u=qo;if(u&&typeof r=="string"&&r){var h=rr(r);h='link[rel="'+e+'"][href="'+h+'"]',typeof i=="string"&&(h+='[crossorigin="'+i+'"]'),Xv.has(h)||(Xv.add(h),e={rel:e,crossOrigin:i,href:r},u.querySelector(h)===null&&(r=u.createElement("link"),cn(r,"link",e),Xt(r),u.head.appendChild(r)))}}function t3(e){pa.D(e),Zv("dns-prefetch",e,null)}function n3(e,r){pa.C(e,r),Zv("preconnect",e,r)}function r3(e,r,i){pa.L(e,r,i);var u=qo;if(u&&e&&r){var h='link[rel="preload"][as="'+rr(r)+'"]';r==="image"&&i&&i.imageSrcSet?(h+='[imagesrcset="'+rr(i.imageSrcSet)+'"]',typeof i.imageSizes=="string"&&(h+='[imagesizes="'+rr(i.imageSizes)+'"]')):h+='[href="'+rr(e)+'"]';var x=h;switch(r){case"style":x=Ko(e);break;case"script":x=Wo(e)}dr.has(x)||(e=v({rel:"preload",href:r==="image"&&i&&i.imageSrcSet?void 0:e,as:r},i),dr.set(x,e),u.querySelector(h)!==null||r==="style"&&u.querySelector(bl(x))||r==="script"&&u.querySelector(vl(x))||(r=u.createElement("link"),cn(r,"link",e),Xt(r),u.head.appendChild(r)))}}function a3(e,r){pa.m(e,r);var i=qo;if(i&&e){var u=r&&typeof r.as=="string"?r.as:"script",h='link[rel="modulepreload"][as="'+rr(u)+'"][href="'+rr(e)+'"]',x=h;switch(u){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":x=Wo(e)}if(!dr.has(x)&&(e=v({rel:"modulepreload",href:e},r),dr.set(x,e),i.querySelector(h)===null)){switch(u){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":if(i.querySelector(vl(x)))return}u=i.createElement("link"),cn(u,"link",e),Xt(u),i.head.appendChild(u)}}}function s3(e,r,i){pa.S(e,r,i);var u=qo;if(u&&e){var h=Xr(u).hoistableStyles,x=Ko(e);r=r||"default";var j=h.get(x);if(!j){var A={loading:0,preload:null};if(j=u.querySelector(bl(x)))A.loading=5;else{e=v({rel:"stylesheet",href:e,"data-precedence":r},i),(i=dr.get(x))&&np(e,i);var z=j=u.createElement("link");Xt(z),cn(z,"link",e),z._p=new Promise(function(J,le){z.onload=J,z.onerror=le}),z.addEventListener("load",function(){A.loading|=1}),z.addEventListener("error",function(){A.loading|=2}),A.loading|=4,hu(j,r,u)}j={type:"stylesheet",instance:j,count:1,state:A},h.set(x,j)}}}function o3(e,r){pa.X(e,r);var i=qo;if(i&&e){var u=Xr(i).hoistableScripts,h=Wo(e),x=u.get(h);x||(x=i.querySelector(vl(h)),x||(e=v({src:e,async:!0},r),(r=dr.get(h))&&rp(e,r),x=i.createElement("script"),Xt(x),cn(x,"link",e),i.head.appendChild(x)),x={type:"script",instance:x,count:1,state:null},u.set(h,x))}}function i3(e,r){pa.M(e,r);var i=qo;if(i&&e){var u=Xr(i).hoistableScripts,h=Wo(e),x=u.get(h);x||(x=i.querySelector(vl(h)),x||(e=v({src:e,async:!0,type:"module"},r),(r=dr.get(h))&&rp(e,r),x=i.createElement("script"),Xt(x),cn(x,"link",e),i.head.appendChild(x)),x={type:"script",instance:x,count:1,state:null},u.set(h,x))}}function Qv(e,r,i,u){var h=(h=be.current)?pu(h):null;if(!h)throw Error(o(446));switch(e){case"meta":case"title":return null;case"style":return typeof i.precedence=="string"&&typeof i.href=="string"?(r=Ko(i.href),i=Xr(h).hoistableStyles,u=i.get(r),u||(u={type:"style",instance:null,count:0,state:null},i.set(r,u)),u):{type:"void",instance:null,count:0,state:null};case"link":if(i.rel==="stylesheet"&&typeof i.href=="string"&&typeof i.precedence=="string"){e=Ko(i.href);var x=Xr(h).hoistableStyles,j=x.get(e);if(j||(h=h.ownerDocument||h,j={type:"stylesheet",instance:null,count:0,state:{loading:0,preload:null}},x.set(e,j),(x=h.querySelector(bl(e)))&&!x._p&&(j.instance=x,j.state.loading=5),dr.has(e)||(i={rel:"preload",as:"style",href:i.href,crossOrigin:i.crossOrigin,integrity:i.integrity,media:i.media,hrefLang:i.hrefLang,referrerPolicy:i.referrerPolicy},dr.set(e,i),x||l3(h,e,i,j.state))),r&&u===null)throw Error(o(528,""));return j}if(r&&u!==null)throw Error(o(529,""));return null;case"script":return r=i.async,i=i.src,typeof i=="string"&&r&&typeof r!="function"&&typeof r!="symbol"?(r=Wo(i),i=Xr(h).hoistableScripts,u=i.get(r),u||(u={type:"script",instance:null,count:0,state:null},i.set(r,u)),u):{type:"void",instance:null,count:0,state:null};default:throw Error(o(444,e))}}function Ko(e){return'href="'+rr(e)+'"'}function bl(e){return'link[rel="stylesheet"]['+e+"]"}function Jv(e){return v({},e,{"data-precedence":e.precedence,precedence:null})}function l3(e,r,i,u){e.querySelector('link[rel="preload"][as="style"]['+r+"]")?u.loading=1:(r=e.createElement("link"),u.preload=r,r.addEventListener("load",function(){return u.loading|=1}),r.addEventListener("error",function(){return u.loading|=2}),cn(r,"link",i),Xt(r),e.head.appendChild(r))}function Wo(e){return'[src="'+rr(e)+'"]'}function vl(e){return"script[async]"+e}function ey(e,r,i){if(r.count++,r.instance===null)switch(r.type){case"style":var u=e.querySelector('style[data-href~="'+rr(i.href)+'"]');if(u)return r.instance=u,Xt(u),u;var h=v({},i,{"data-href":i.href,"data-precedence":i.precedence,href:null,precedence:null});return u=(e.ownerDocument||e).createElement("style"),Xt(u),cn(u,"style",h),hu(u,i.precedence,e),r.instance=u;case"stylesheet":h=Ko(i.href);var x=e.querySelector(bl(h));if(x)return r.state.loading|=4,r.instance=x,Xt(x),x;u=Jv(i),(h=dr.get(h))&&np(u,h),x=(e.ownerDocument||e).createElement("link"),Xt(x);var j=x;return j._p=new Promise(function(A,z){j.onload=A,j.onerror=z}),cn(x,"link",u),r.state.loading|=4,hu(x,i.precedence,e),r.instance=x;case"script":return x=Wo(i.src),(h=e.querySelector(vl(x)))?(r.instance=h,Xt(h),h):(u=i,(h=dr.get(x))&&(u=v({},i),rp(u,h)),e=e.ownerDocument||e,h=e.createElement("script"),Xt(h),cn(h,"link",u),e.head.appendChild(h),r.instance=h);case"void":return null;default:throw Error(o(443,r.type))}else r.type==="stylesheet"&&(r.state.loading&4)===0&&(u=r.instance,r.state.loading|=4,hu(u,i.precedence,e));return r.instance}function hu(e,r,i){for(var u=i.querySelectorAll('link[rel="stylesheet"][data-precedence],style[data-precedence]'),h=u.length?u[u.length-1]:null,x=h,j=0;j title"):null)}function c3(e,r,i){if(i===1||r.itemProp!=null)return!1;switch(e){case"meta":case"title":return!0;case"style":if(typeof r.precedence!="string"||typeof r.href!="string"||r.href==="")break;return!0;case"link":if(typeof r.rel!="string"||typeof r.href!="string"||r.href===""||r.onLoad||r.onError)break;switch(r.rel){case"stylesheet":return e=r.disabled,typeof r.precedence=="string"&&e==null;default:return!0}case"script":if(r.async&&typeof r.async!="function"&&typeof r.async!="symbol"&&!r.onLoad&&!r.onError&&r.src&&typeof r.src=="string")return!0}return!1}function ry(e){return!(e.type==="stylesheet"&&(e.state.loading&3)===0)}function u3(e,r,i,u){if(i.type==="stylesheet"&&(typeof u.media!="string"||matchMedia(u.media).matches!==!1)&&(i.state.loading&4)===0){if(i.instance===null){var h=Ko(u.href),x=r.querySelector(bl(h));if(x){r=x._p,r!==null&&typeof r=="object"&&typeof r.then=="function"&&(e.count++,e=xu.bind(e),r.then(e,e)),i.state.loading|=4,i.instance=x,Xt(x);return}x=r.ownerDocument||r,u=Jv(u),(h=dr.get(h))&&np(u,h),x=x.createElement("link"),Xt(x);var j=x;j._p=new Promise(function(A,z){j.onload=A,j.onerror=z}),cn(x,"link",u),i.instance=x}e.stylesheets===null&&(e.stylesheets=new Map),e.stylesheets.set(i,r),(r=i.state.preload)&&(i.state.loading&3)===0&&(e.count++,i=xu.bind(e),r.addEventListener("load",i),r.addEventListener("error",i))}}var ap=0;function d3(e,r){return e.stylesheets&&e.count===0&&vu(e,e.stylesheets),0ap?50:800)+r);return e.unsuspend=i,function(){e.unsuspend=null,clearTimeout(u),clearTimeout(h)}}:null}function xu(){if(this.count--,this.count===0&&(this.imgCount===0||!this.waitingForImages)){if(this.stylesheets)vu(this,this.stylesheets);else if(this.unsuspend){var e=this.unsuspend;this.unsuspend=null,e()}}}var bu=null;function vu(e,r){e.stylesheets=null,e.unsuspend!==null&&(e.count++,bu=new Map,r.forEach(f3,e),bu=null,xu.call(e))}function f3(e,r){if(!(r.state.loading&4)){var i=bu.get(e);if(i)var u=i.get(null);else{i=new Map,bu.set(e,i);for(var h=e.querySelectorAll("link[data-precedence],style[data-precedence]"),x=0;x"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(t)}catch(n){console.error(n)}}return t(),pp.exports=R3(),pp.exports}var _3=A3();/** * react-router v7.18.2 * * Copyright (c) Remix Software Inc. * * This source code is licensed under the MIT license found in the * LICENSE.md file in the root directory of this source tree. * * @license MIT */var Zh=/^(?:[a-z][a-z0-9+.-]*:|[\\/]{2})/i,i2=/^[\\/]{2}/;function D3(t,n){return n+t.replace(/\\/g,"/")}var Ay="popstate";function _y(t){return typeof t=="object"&&t!=null&&"pathname"in t&&"search"in t&&"hash"in t&&"state"in t&&"key"in t}function O3(t={}){function n(o,c){var g;let l=(g=c.state)==null?void 0:g.masked,{pathname:d,search:m,hash:p}=l||o.location;return Qp("",{pathname:d,search:m,hash:p},c.state&&c.state.usr||null,c.state&&c.state.key||"default",l?{pathname:o.location.pathname,search:o.location.search,hash:o.location.hash}:void 0)}function a(o,c){return typeof c=="string"?c:Il(c)}return z3(n,a,null,t)}function kt(t,n){if(t===!1||t===null||typeof t>"u")throw new Error(n)}function pr(t,n){if(!t){typeof console<"u"&&console.warn(n);try{throw new Error(n)}catch{}}}function L3(){return Math.random().toString(36).substring(2,10)}function Dy(t,n){return{usr:t.state,key:t.key,idx:n,masked:t.mask?{pathname:t.pathname,search:t.search,hash:t.hash}:void 0}}function Qp(t,n,a=null,o,c){return{pathname:typeof t=="string"?t:t.pathname,search:"",hash:"",...typeof n=="string"?hi(n):n,state:a,key:n&&n.key||o||L3(),mask:c}}function Il({pathname:t="/",search:n="",hash:a=""}){return n&&n!=="?"&&(t+=n.charAt(0)==="?"?n:"?"+n),a&&a!=="#"&&(t+=a.charAt(0)==="#"?a:"#"+a),t}function hi(t){let n={};if(t){let a=t.indexOf("#");a>=0&&(n.hash=t.substring(a),t=t.substring(0,a));let o=t.indexOf("?");o>=0&&(n.search=t.substring(o),t=t.substring(0,o)),t&&(n.pathname=t)}return n}function z3(t,n,a,o={}){let{window:c=document.defaultView,v5Compat:l=!1}=o,d=c.history,m="POP",p=null,g=b();g==null&&(g=0,d.replaceState({...d.state,idx:g},""));function b(){return(d.state||{idx:null}).idx}function v(){m="POP";let N=b(),E=N==null?null:N-g;g=N,p&&p({action:m,location:S.location,delta:E})}function w(N,E){m="PUSH";let T=_y(N)?N:Qp(S.location,N,E);g=b()+1;let M=Dy(T,g),k=S.createHref(T.mask||T);try{d.pushState(M,"",k)}catch(_){if(_ instanceof DOMException&&_.name==="DataCloneError")throw _;c.location.assign(k)}l&&p&&p({action:m,location:S.location,delta:1})}function y(N,E){m="REPLACE";let T=_y(N)?N:Qp(S.location,N,E);g=b();let M=Dy(T,g),k=S.createHref(T.mask||T);d.replaceState(M,"",k),l&&p&&p({action:m,location:S.location,delta:0})}function C(N){return P3(c,N)}let S={get action(){return m},get location(){return t(c,d)},listen(N){if(p)throw new Error("A history only accepts one active listener");return c.addEventListener(Ay,v),p=N,()=>{c.removeEventListener(Ay,v),p=null}},createHref(N){return n(c,N)},createURL:C,encodeLocation(N){let E=C(N);return{pathname:E.pathname,search:E.search,hash:E.hash}},push:w,replace:y,go(N){return d.go(N)}};return S}function P3(t,n,a=!1){let o="http://localhost";t&&(o=t.location.origin!=="null"?t.location.origin:t.location.href),kt(o,"No window.location.(origin|href) available to create URL");let c=typeof n=="string"?n:Il(n);return c=c.replace(/ $/,"%20"),!a&&i2.test(c)&&(c=o+c),new URL(c,o)}function l2(t,n,a="/"){return I3(t,n,a,!1)}function I3(t,n,a,o,c){let l=typeof n=="string"?hi(n):n,d=Na(l.pathname||"/",a);if(d==null)return null;let m=U3(t),p=null,g=X3(d);for(let b=0;p==null&&b{let b={relativePath:g===void 0?d.path||"":g,caseSensitive:d.caseSensitive===!0,childrenIndex:m,route:d};if(b.relativePath.startsWith("/")){if(!b.relativePath.startsWith(o)&&p)return;kt(b.relativePath.startsWith(o),`Absolute route path "${b.relativePath}" nested under path "${o}" is not valid. An absolute child route path must start with the combined path of all its parent routes.`),b.relativePath=b.relativePath.slice(o.length)}let v=Sr([o,b.relativePath]),w=a.concat(b);d.children&&d.children.length>0&&(kt(d.index!==!0,`Index routes must not have child routes. Please remove all child routes from route path "${v}".`),c2(d.children,n,w,v,p)),!(d.path==null&&!d.index)&&n.push({path:v,score:q3(v,d.index),routesMeta:w.map((y,C)=>{let[S,N]=f2(y.relativePath,y.caseSensitive,C===w.length-1);return{...y,matcher:S,compiledParams:N}})})};return t.forEach((d,m)=>{var p;if(d.path===""||!((p=d.path)!=null&&p.includes("?")))l(d,m);else for(let g of u2(d.path))l(d,m,!0,g)}),n}function u2(t){let n=t.split("/");if(n.length===0)return[];let[a,...o]=n,c=a.endsWith("?"),l=a.replace(/\?$/,"");if(o.length===0)return c?[l,""]:[l];let d=u2(o.join("/")),m=[];return m.push(...d.map(p=>p===""?l:[l,p].join("/"))),c&&m.push(...d),m.map(p=>t.startsWith("/")&&p===""?"/":p)}function B3(t){t.sort((n,a)=>n.score!==a.score?a.score-n.score:K3(n.routesMeta.map(o=>o.childrenIndex),a.routesMeta.map(o=>o.childrenIndex)))}var $3=/^:[\w-]+$/,H3=3,G3=2,V3=1,F3=10,Y3=-2,Oy=t=>t==="*";function q3(t,n){let a=t.split("/"),o=a.length;return a.some(Oy)&&(o+=Y3),n&&(o+=G3),a.filter(c=>!Oy(c)).reduce((c,l)=>c+($3.test(l)?H3:l===""?V3:F3),o)}function K3(t,n){return t.length===n.length&&t.slice(0,-1).every((o,c)=>o===n[c])?t[t.length-1]-n[n.length-1]:0}function W3(t,n,a=!1){let{routesMeta:o}=t,c={},l="/",d=[];for(let m=0;m{if(b==="*"){let C=m[w]||"";d=l.slice(0,l.length-C.length).replace(/(.)\/+$/,"$1")}const y=m[w];return v&&!y?g[b]=void 0:g[b]=(y||"").replace(/%2F/g,"/"),g},{}),pathname:l,pathnameBase:d,pattern:t}}function f2(t,n=!1,a=!0){pr(t==="*"||!t.endsWith("*")||t.endsWith("/*"),`Route path "${t}" will be treated as if it were "${t.replace(/\*$/,"/*")}" because the \`*\` character must always follow a \`/\` in the pattern. To get rid of this warning, please change the route path to "${t.replace(/\*$/,"/*")}".`);let o=[],c="^"+t.replace(/\/*\*?$/,"").replace(/^\/*/,"/").replace(/[\\.*+^${}|()[\]]/g,"\\$&").replace(/\/:([\w-]+)(\?)?/g,(d,m,p,g,b)=>{if(o.push({paramName:m,isOptional:p!=null}),p){let v=b.charAt(g+d.length);return v&&v!=="/"?"/([^\\/]*)":"(?:/([^\\/]*))?"}return"/([^\\/]+)"}).replace(/\/([\w-]+)\?(\/|$)/g,"(/$1)?$2");return t.endsWith("*")?(o.push({paramName:"*"}),c+=t==="*"||t==="/*"?"(.*)$":"(?:\\/(.+)|\\/*)$"):a?c+="\\/*$":t!==""&&t!=="/"&&(c+="(?:(?=\\/|$))"),[new RegExp(c,n?void 0:"i"),o]}function X3(t){try{return t.split("/").map(n=>decodeURIComponent(n).replace(/\//g,"%2F")).join("/")}catch(n){return pr(!1,`The URL path "${t}" could not be decoded because it is a malformed URL segment. This is probably due to a bad percent encoding (${n}).`),t}}function Na(t,n){if(n==="/")return t;if(!t.toLowerCase().startsWith(n.toLowerCase()))return null;let a=n.endsWith("/")?n.length-1:n.length,o=t.charAt(a);return o&&o!=="/"?null:t.slice(a)||"/"}function Z3(t,n="/"){let{pathname:a,search:o="",hash:c=""}=typeof t=="string"?hi(t):t,l;return a?(a=m2(a),a.startsWith("/")?l=Ly(a.substring(1),"/"):l=Ly(a,n)):l=n,{pathname:l,search:eN(o),hash:tN(c)}}function Ly(t,n){let a=ad(n).split("/");return t.split("/").forEach(c=>{c===".."?a.length>1&&a.pop():c!=="."&&a.push(c)}),a.length>1?a.join("/"):"/"}function bp(t,n,a,o){return`Cannot include a '${t}' character in a manually specified \`to.${n}\` field [${JSON.stringify(o)}]. Please separate it out to the \`to.${a}\` field. Alternatively you may provide the full path as a string in and the router will parse it for you.`}function Q3(t){return t.filter((n,a)=>a===0||n.route.path&&n.route.path.length>0)}function Qh(t){let n=Q3(t);return n.map((a,o)=>o===n.length-1?a.pathname:a.pathnameBase)}function xd(t,n,a,o=!1){let c;typeof t=="string"?c=hi(t):(c={...t},kt(!c.pathname||!c.pathname.includes("?"),bp("?","pathname","search",c)),kt(!c.pathname||!c.pathname.includes("#"),bp("#","pathname","hash",c)),kt(!c.search||!c.search.includes("#"),bp("#","search","hash",c)));let l=t===""||c.pathname==="",d=l?"/":c.pathname,m;if(d==null)m=a;else{let v=n.length-1;if(!o&&d.startsWith("..")){let w=d.split("/");for(;w[0]==="..";)w.shift(),v-=1;c.pathname=w.join("/")}m=v>=0?n[v]:"/"}let p=Z3(c,m),g=d&&d!=="/"&&d.endsWith("/"),b=(l||d===".")&&a.endsWith("/");return!p.pathname.endsWith("/")&&(g||b)&&(p.pathname+="/"),p}var m2=t=>t.replace(/[\\/]{2,}/g,"/"),Sr=t=>m2(t.join("/")),ad=t=>t.replace(/\/+$/,""),J3=t=>ad(t).replace(/^\/*/,"/"),eN=t=>!t||t==="?"?"":t.startsWith("?")?t:"?"+t,tN=t=>!t||t==="#"?"":t.startsWith("#")?t:"#"+t,nN=class{constructor(t,n,a,o=!1){this.status=t,this.statusText=n||"",this.internal=o,a instanceof Error?(this.data=a.toString(),this.error=a):this.data=a}};function rN(t){return t!=null&&typeof t.status=="number"&&typeof t.statusText=="string"&&typeof t.internal=="boolean"&&"data"in t}function aN(t){let n=t.map(a=>a.route.path).filter(Boolean);return Sr(n)||"/"}var p2=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function h2(t,n){let a=t;if(typeof a!="string"||!Zh.test(a))return{absoluteURL:void 0,isExternal:!1,to:a};let o=a,c=!1;if(p2)try{let l=new URL(window.location.href),d=i2.test(a)?new URL(D3(a,l.protocol)):new URL(a),m=Na(d.pathname,n);d.origin===l.origin&&m!=null?a=m+d.search+d.hash:c=!0}catch{pr(!1,` contains an invalid URL which will probably break when clicked - please update to a valid URL path.`)}return{absoluteURL:o,isExternal:c,to:a}}Object.getOwnPropertyNames(Object.prototype).sort().join("\0");var g2=["POST","PUT","PATCH","DELETE"];new Set(g2);var sN=["GET",...g2];new Set(sN);var oN=["about:","blob:","chrome:","chrome-untrusted:","content:","data:","devtools:","file:","filesystem:","javascript:"];function iN(t){try{return oN.includes(new URL(t).protocol)}catch{return!1}}var gi=f.createContext(null);gi.displayName="DataRouter";var bd=f.createContext(null);bd.displayName="DataRouterState";var x2=f.createContext(!1);function lN(){return f.useContext(x2)}var b2=f.createContext({isTransitioning:!1});b2.displayName="ViewTransition";var cN=f.createContext(new Map);cN.displayName="Fetchers";var uN=f.createContext(null);uN.displayName="Await";var qn=f.createContext(null);qn.displayName="Navigation";var Jl=f.createContext(null);Jl.displayName="Location";var Tr=f.createContext({outlet:null,matches:[],isDataRoute:!1});Tr.displayName="Route";var Jh=f.createContext(null);Jh.displayName="RouteError";var v2="REACT_ROUTER_ERROR",dN="REDIRECT",fN="ROUTE_ERROR_RESPONSE";function mN(t){if(t.startsWith(`${v2}:${dN}:{`))try{let n=JSON.parse(t.slice(28));if(typeof n=="object"&&n&&typeof n.status=="number"&&typeof n.statusText=="string"&&typeof n.location=="string"&&typeof n.reloadDocument=="boolean"&&typeof n.replace=="boolean")return n}catch{}}function pN(t){if(t.startsWith(`${v2}:${fN}:{`))try{let n=JSON.parse(t.slice(40));if(typeof n=="object"&&n&&typeof n.status=="number"&&typeof n.statusText=="string")return new nN(n.status,n.statusText,n.data)}catch{}}function hN(t,{relative:n}={}){kt(xi(),"useHref() may be used only in the context of a component.");let{basename:a,navigator:o}=f.useContext(qn),{hash:c,pathname:l,search:d}=ec(t,{relative:n}),m=l;return a!=="/"&&(m=l==="/"?a:Sr([a,l])),o.createHref({pathname:m,search:d,hash:c})}function xi(){return f.useContext(Jl)!=null}function Kn(){return kt(xi(),"useLocation() may be used only in the context of a component."),f.useContext(Jl).location}var y2="You should call navigate() in a React.useEffect(), not when your component is first rendered.";function w2(t){f.useContext(qn).static||f.useLayoutEffect(t)}function ao(){let{isDataRoute:t}=f.useContext(Tr);return t?RN():gN()}function gN(){kt(xi(),"useNavigate() may be used only in the context of a component.");let t=f.useContext(gi),{basename:n,navigator:a}=f.useContext(qn),{matches:o}=f.useContext(Tr),{pathname:c}=Kn(),l=JSON.stringify(Qh(o)),d=f.useRef(!1);return w2(()=>{d.current=!0}),f.useCallback((p,g={})=>{if(pr(d.current,y2),!d.current)return;if(typeof p=="number"){a.go(p);return}let b=xd(p,JSON.parse(l),c,g.relative==="path");t==null&&n!=="/"&&(b.pathname=b.pathname==="/"?n:Sr([n,b.pathname])),(g.replace?a.replace:a.push)(b,g.state,g)},[n,a,l,c,t])}var xN=f.createContext(null);function bN(t){let n=f.useContext(Tr).outlet;return f.useMemo(()=>n&&f.createElement(xN.Provider,{value:t},n),[n,t])}function ec(t,{relative:n}={}){let{matches:a}=f.useContext(Tr),{pathname:o}=Kn(),c=JSON.stringify(Qh(a));return f.useMemo(()=>xd(t,JSON.parse(c),o,n==="path"),[t,c,o,n])}function vN(t,n){return j2(t,n)}function j2(t,n,a){var N;kt(xi(),"useRoutes() may be used only in the context of a component.");let{navigator:o}=f.useContext(qn),{matches:c}=f.useContext(Tr),l=c[c.length-1],d=l?l.params:{},m=l?l.pathname:"/",p=l?l.pathnameBase:"/",g=l&&l.route;{let E=g&&g.path||"";S2(m,!g||E.endsWith("*")||E.endsWith("*?"),`You rendered descendant (or called \`useRoutes()\`) at "${m}" (under ) but the parent route path has no trailing "*". This means if you navigate deeper, the parent won't match anymore and therefore the child routes will never render. Please change the parent to .`)}let b=Kn(),v;if(n){let E=typeof n=="string"?hi(n):n;kt(p==="/"||((N=E.pathname)==null?void 0:N.startsWith(p)),`When overriding the location using \`\` or \`useRoutes(routes, location)\`, the location pathname must begin with the portion of the URL pathname that was matched by all parent routes. The current pathname base is "${p}" but pathname "${E.pathname}" was given in the \`location\` prop.`),v=E}else v=b;let w=v.pathname||"/",y=w;if(p!=="/"){let E=p.replace(/^\//,"").split("/");y="/"+w.replace(/^\//,"").split("/").slice(E.length).join("/")}let C=a&&a.state.matches.length?a.state.matches.map(E=>Object.assign(E,{route:a.manifest[E.route.id]||E.route})):l2(t,{pathname:y});pr(g||C!=null,`No routes matched location "${v.pathname}${v.search}${v.hash}" `),pr(C==null||C[C.length-1].route.element!==void 0||C[C.length-1].route.Component!==void 0||C[C.length-1].route.lazy!==void 0,`Matched leaf route at location "${v.pathname}${v.search}${v.hash}" does not have an element or Component. This means it will render an with a null value by default resulting in an "empty" page.`);let S=SN(C&&C.map(E=>Object.assign({},E,{params:Object.assign({},d,E.params),pathname:Sr([p,o.encodeLocation?o.encodeLocation(E.pathname.replace(/%/g,"%25").replace(/\?/g,"%3F").replace(/#/g,"%23")).pathname:E.pathname]),pathnameBase:E.pathnameBase==="/"?p:Sr([p,o.encodeLocation?o.encodeLocation(E.pathnameBase.replace(/%/g,"%25").replace(/\?/g,"%3F").replace(/#/g,"%23")).pathname:E.pathnameBase])})),c,a);return n&&S?f.createElement(Jl.Provider,{value:{location:{pathname:"/",search:"",hash:"",state:null,key:"default",mask:void 0,...v},navigationType:"POP"}},S):S}function yN(){let t=MN(),n=rN(t)?`${t.status} ${t.statusText}`:t instanceof Error?t.message:JSON.stringify(t),a=t instanceof Error?t.stack:null,o="rgba(200,200,200, 0.5)",c={padding:"0.5rem",backgroundColor:o},l={padding:"2px 4px",backgroundColor:o},d=null;return console.error("Error handled by React Router default ErrorBoundary:",t),d=f.createElement(f.Fragment,null,f.createElement("p",null,"💿 Hey developer 👋"),f.createElement("p",null,"You can provide a way better UX than this when your app throws errors by providing your own ",f.createElement("code",{style:l},"ErrorBoundary")," or"," ",f.createElement("code",{style:l},"errorElement")," prop on your route.")),f.createElement(f.Fragment,null,f.createElement("h2",null,"Unexpected Application Error!"),f.createElement("h3",{style:{fontStyle:"italic"}},n),a?f.createElement("pre",{style:c},a):null,d)}var wN=f.createElement(yN,null),C2=class extends f.Component{constructor(t){super(t),this.state={location:t.location,revalidation:t.revalidation,error:t.error}}static getDerivedStateFromError(t){return{error:t}}static getDerivedStateFromProps(t,n){return n.location!==t.location||n.revalidation!=="idle"&&t.revalidation==="idle"?{error:t.error,location:t.location,revalidation:t.revalidation}:{error:t.error!==void 0?t.error:n.error,location:n.location,revalidation:t.revalidation||n.revalidation}}componentDidCatch(t,n){this.props.onError?this.props.onError(t,n):console.error("React Router caught the following error during render",t)}render(){let t=this.state.error;if(this.context&&typeof t=="object"&&t&&"digest"in t&&typeof t.digest=="string"){const a=pN(t.digest);a&&(t=a)}let n=t!==void 0?f.createElement(Tr.Provider,{value:this.props.routeContext},f.createElement(Jh.Provider,{value:t,children:this.props.component})):this.props.children;return this.context?f.createElement(jN,{error:t},n):n}};C2.contextType=x2;var vp=new WeakMap;function jN({children:t,error:n}){let{basename:a}=f.useContext(qn);if(typeof n=="object"&&n&&"digest"in n&&typeof n.digest=="string"){let o=mN(n.digest);if(o){let c=vp.get(n);if(c)throw c;let l=h2(o.location,a),d=l.absoluteURL||l.to;if(iN(d))throw new Error("Invalid redirect location");if(p2&&!vp.get(n))if(l.isExternal||o.reloadDocument)window.location.href=d;else{const m=Promise.resolve().then(()=>window.__reactRouterDataRouter.navigate(l.to,{replace:o.replace}));throw vp.set(n,m),m}return f.createElement("meta",{httpEquiv:"refresh",content:`0;url=${d}`})}}return t}function CN({routeContext:t,match:n,children:a}){let o=f.useContext(gi);return o&&o.static&&o.staticContext&&(n.route.errorElement||n.route.ErrorBoundary)&&(o.staticContext._deepestRenderedBoundaryId=n.route.id),f.createElement(Tr.Provider,{value:t},a)}function SN(t,n=[],a){let o=a==null?void 0:a.state;if(t==null){if(!o)return null;if(o.errors)t=o.matches;else if(n.length===0&&!o.initialized&&o.matches.length>0)t=o.matches;else return null}let c=t,l=o==null?void 0:o.errors;if(l!=null){let b=c.findIndex(v=>v.route.id&&(l==null?void 0:l[v.route.id])!==void 0);kt(b>=0,`Could not find a matching route for errors on route IDs: ${Object.keys(l).join(",")}`),c=c.slice(0,Math.min(c.length,b+1))}let d=!1,m=-1;if(a&&o){d=o.renderFallback;for(let b=0;b=0?c=c.slice(0,m+1):c=[c[0]];break}}}}let p=a==null?void 0:a.onError,g=o&&p?(b,v)=>{var w,y;p(b,{location:o.location,params:((y=(w=o.matches)==null?void 0:w[0])==null?void 0:y.params)??{},pattern:aN(o.matches),errorInfo:v})}:void 0;return c.reduceRight((b,v,w)=>{let y,C=!1,S=null,N=null;o&&(y=l&&v.route.id?l[v.route.id]:void 0,S=v.route.errorElement||wN,d&&(m<0&&w===0?(S2("route-fallback",!1,"No `HydrateFallback` element provided to render during initial hydration"),C=!0,N=null):m===w&&(C=!0,N=v.route.hydrateFallbackElement||null)));let E=n.concat(c.slice(0,w+1)),T=()=>{let M;return y?M=S:C?M=N:v.route.Component?M=f.createElement(v.route.Component,null):v.route.element?M=v.route.element:M=b,f.createElement(CN,{match:v,routeContext:{outlet:b,matches:E,isDataRoute:o!=null},children:M})};return o&&(v.route.ErrorBoundary||v.route.errorElement||w===0)?f.createElement(C2,{location:o.location,revalidation:o.revalidation,component:S,error:y,children:T(),routeContext:{outlet:null,matches:E,isDataRoute:!0},onError:g}):T()},null)}function eg(t){return`${t} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function NN(t){let n=f.useContext(gi);return kt(n,eg(t)),n}function EN(t){let n=f.useContext(bd);return kt(n,eg(t)),n}function kN(t){let n=f.useContext(Tr);return kt(n,eg(t)),n}function tg(t){let n=kN(t),a=n.matches[n.matches.length-1];return kt(a.route.id,`${t} can only be used on routes that contain a unique "id"`),a.route.id}function TN(){return tg("useRouteId")}function MN(){var o;let t=f.useContext(Jh),n=EN("useRouteError"),a=tg("useRouteError");return t!==void 0?t:(o=n.errors)==null?void 0:o[a]}function RN(){let{router:t}=NN("useNavigate"),n=tg("useNavigate"),a=f.useRef(!1);return w2(()=>{a.current=!0}),f.useCallback(async(c,l={})=>{pr(a.current,y2),a.current&&(typeof c=="number"?await t.navigate(c):await t.navigate(c,{fromRouteId:n,...l}))},[t,n])}var zy={};function S2(t,n,a){!n&&!zy[t]&&(zy[t]=!0,pr(!1,a))}f.memo(AN);function AN({routes:t,manifest:n,future:a,state:o,isStatic:c,onError:l}){return j2(t,void 0,{manifest:n,state:o,isStatic:c,onError:l})}function ya({to:t,replace:n,state:a,relative:o}){kt(xi()," may be used only in the context of a component.");let{static:c}=f.useContext(qn);pr(!c," must not be used on the initial render in a . This is a no-op, but you should modify your code so the is only ever rendered in response to some user interaction or state change.");let{matches:l}=f.useContext(Tr),{pathname:d}=Kn(),m=ao(),p=xd(t,Qh(l),d,o==="path"),g=JSON.stringify(p);return f.useEffect(()=>{m(JSON.parse(g),{replace:n,state:a,relative:o})},[m,g,o,n,a]),null}function _N(t){return bN(t.context)}function un(t){kt(!1,"A is only ever to be used as the child of element, never rendered directly. Please wrap your in a .")}function DN({basename:t="/",children:n=null,location:a,navigationType:o="POP",navigator:c,static:l=!1,useTransitions:d}){kt(!xi(),"You cannot render a inside another . You should never have more than one in your app.");let m=t.replace(/^\/*/,"/"),p=f.useMemo(()=>({basename:m,navigator:c,static:l,useTransitions:d,future:{}}),[m,c,l,d]);typeof a=="string"&&(a=hi(a));let{pathname:g="/",search:b="",hash:v="",state:w=null,key:y="default",mask:C}=a,S=f.useMemo(()=>{let N=Na(g,m);return N==null?null:{location:{pathname:N,search:b,hash:v,state:w,key:y,mask:C},navigationType:o}},[m,g,b,v,w,y,o,C]);return pr(S!=null,` is not able to match the URL "${g}${b}${v}" because it does not start with the basename, so the won't render anything.`),S==null?null:f.createElement(qn.Provider,{value:p},f.createElement(Jl.Provider,{children:n,value:S}))}function Py({children:t,location:n}){return vN(Jp(t),n)}function Jp(t,n=[]){let a=[];return f.Children.forEach(t,(o,c)=>{if(!f.isValidElement(o))return;let l=[...n,c];if(o.type===f.Fragment){a.push.apply(a,Jp(o.props.children,l));return}kt(o.type===un,`[${typeof o.type=="string"?o.type:o.type.name}] is not a component. All component children of must be a or `),kt(!o.props.index||!o.props.children,"An index route cannot have child routes.");let d={id:o.props.id||l.join("-"),caseSensitive:o.props.caseSensitive,element:o.props.element,Component:o.props.Component,index:o.props.index,path:o.props.path,middleware:o.props.middleware,loader:o.props.loader,action:o.props.action,hydrateFallbackElement:o.props.hydrateFallbackElement,HydrateFallback:o.props.HydrateFallback,errorElement:o.props.errorElement,ErrorBoundary:o.props.ErrorBoundary,hasErrorBoundary:o.props.hasErrorBoundary===!0||o.props.ErrorBoundary!=null||o.props.errorElement!=null,shouldRevalidate:o.props.shouldRevalidate,handle:o.props.handle,lazy:o.props.lazy};o.props.children&&(d.children=Jp(o.props.children,l)),a.push(d)}),a}var Fu="get",Yu="application/x-www-form-urlencoded";function vd(t){return typeof HTMLElement<"u"&&t instanceof HTMLElement}function ON(t){return vd(t)&&t.tagName.toLowerCase()==="button"}function LN(t){return vd(t)&&t.tagName.toLowerCase()==="form"}function zN(t){return vd(t)&&t.tagName.toLowerCase()==="input"}function PN(t){return!!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey)}function IN(t,n){return t.button===0&&(!n||n==="_self")&&!PN(t)}function eh(t=""){return new URLSearchParams(typeof t=="string"||Array.isArray(t)||t instanceof URLSearchParams?t:Object.keys(t).reduce((n,a)=>{let o=t[a];return n.concat(Array.isArray(o)?o.map(c=>[a,c]):[[a,o]])},[]))}function UN(t,n){let a=eh(t);return n&&n.forEach((o,c)=>{a.has(c)||n.getAll(c).forEach(l=>{a.append(c,l)})}),a}var ku=null;function BN(){if(ku===null)try{new FormData(document.createElement("form"),0),ku=!1}catch{ku=!0}return ku}var $N=new Set(["application/x-www-form-urlencoded","multipart/form-data","text/plain"]);function yp(t){return t!=null&&!$N.has(t)?(pr(!1,`"${t}" is not a valid \`encType\` for \`
\`/\`\` and will default to "${Yu}"`),null):t}function HN(t,n){let a,o,c,l,d;if(LN(t)){let m=t.getAttribute("action");o=m?Na(m,n):null,a=t.getAttribute("method")||Fu,c=yp(t.getAttribute("enctype"))||Yu,l=new FormData(t)}else if(ON(t)||zN(t)&&(t.type==="submit"||t.type==="image")){let m=t.form;if(m==null)throw new Error('Cannot submit a `,_=>`${k}-${_.id}`)}const N=w`
${n.i18n.searchDescription}
${n.i18n.skinToneDescription}
${y(n.skinTones,(T,M)=>w`
${T}
`,T=>T)}
${y(n.currentEmojisWithCategories,(T,M)=>w`
${C(T.emojis,n.searchMode,"emo")}
`,T=>T.category)}
`,E=(T,M)=>{for(const k of t.querySelectorAll(`[${T}]`))M(k,k.getAttribute(T))};if(p){t.appendChild(N);for(const T of["click","focusout","input","keydown","keyup"])E(`data-on-${T}`,(M,k)=>{M.addEventListener(T,o[k])});E("data-ref",(T,M)=>{l[M]=T}),d.addEventListener("abort",()=>{t.removeChild(N)})}E("data-action",(T,M)=>{let k=m.get(M);k||m.set(M,k=new WeakSet),k.has(T)||(k.add(T),c[M](T))})}const md=typeof queueMicrotask=="function"?queueMicrotask:t=>Promise.resolve().then(t);function oO(t){let n=!1,a;const o=new Map,c=new Set;let l;const d=()=>{if(n)return;const g=[...c];c.clear();try{for(const b of g)b()}finally{l=!1,c.size&&(l=!0,md(d))}},m=new Proxy({},{get(g,b){if(a){let v=o.get(b);v||(v=new Set,o.set(b,v)),v.add(a)}return g[b]},set(g,b,v){if(g[b]!==v){g[b]=v;const w=o.get(b);if(w){for(const y of w)c.add(y);l||(l=!0,md(d))}}return!0}}),p=g=>{const b=()=>{const v=a;a=b;try{return g()}finally{a=v}};return b()};return t.addEventListener("abort",()=>{n=!0}),{state:m,createEffect:p}}function qp(t,n,a){if(t.length!==n.length)return!1;for(let o=0;o{c.disconnect()})),c.observe(t)}}const Kp=[],{assign:$u}=Object;function lO(t,n){const a={},o=new AbortController,c=o.signal,{state:l,createEffect:d}=oO(c),m=new Map;$u(l,{skinToneEmoji:void 0,i18n:void 0,database:void 0,customEmoji:void 0,customCategorySorting:void 0,emojiVersion:void 0}),$u(l,n),$u(l,{initialLoad:!0,currentEmojis:[],currentEmojisWithCategories:[],rawSearchText:"",searchText:"",searchMode:!1,activeSearchItem:-1,message:void 0,skinTonePickerExpanded:!1,skinTonePickerExpandedAfterAnimation:!1,currentSkinTone:0,activeSkinTone:0,skinToneButtonText:void 0,pickerStyle:void 0,skinToneButtonLabel:"",skinTones:[],currentFavorites:[],defaultFavoriteEmojis:void 0,numColumns:kD,isRtl:!1,currentGroupIndex:0,groups:Hp,databaseLoaded:!1,activeSearchItemId:void 0}),d(()=>{l.currentGroup!==l.groups[l.currentGroupIndex]&&(l.currentGroup=l.groups[l.currentGroupIndex])});const p=$=>{t.getElementById($).focus()},g=$=>t.getElementById(`emo-${$.id}`),b=($,ie)=>{a.rootElement.dispatchEvent(new CustomEvent($,{detail:ie,bubbles:!0,composed:!0}))},v=($,ie)=>$.id===ie.id,w=($,ie)=>{const{category:ye,emojis:Se}=$,{category:Be,emojis:Ke}=ie;return ye!==Be?!1:qp(Se,Ke,v)},y=$=>{qp(l.currentEmojis,$,v)||(l.currentEmojis=$)},C=$=>{l.searchMode!==$&&(l.searchMode=$)},S=$=>{qp(l.currentEmojisWithCategories,$,w)||(l.currentEmojisWithCategories=$)},N=($,ie)=>ie&&$.skins&&$.skins[ie]||$.unicode,M={labelWithSkin:($,ie)=>VD([$.name||N($,ie),$.annotation,...$.shortcodes||Kp].filter(Boolean)).join(", "),titleForEmoji:$=>$.annotation||($.shortcodes||Kp).join(", "),unicodeWithSkin:N},k={onClickSkinToneButton:Z,onEmojiClick:D,onNavClick:oe,onNavKeydown:ae,onSearchKeydown:W,onSkinToneOptionsClick:V,onSkinToneOptionsFocusOut:ge,onSkinToneOptionsKeydown:be,onSkinToneOptionsKeyup:K,onSearchInput:me},_={calculateEmojiGridStyle:ne,updateOnIntersection:X};let R=!0;d(()=>{sO(t,l,M,k,_,a,c,m,R),R=!1}),l.emojiVersion||Vp().then($=>{$||(l.message=l.i18n.emojiUnsupportedMessage)}),d(()=>{async function $(){let ie=!1;const ye=setTimeout(()=>{ie=!0,l.message=l.i18n.loadingMessage},ND);try{await l.database.ready(),l.databaseLoaded=!0}catch(Se){console.error(Se),l.message=l.i18n.networkErrorMessage}finally{clearTimeout(ye),ie&&(ie=!1,l.message="")}}l.database&&$()}),d(()=>{l.pickerStyle=` --num-groups: ${l.groups.length}; --indicator-opacity: ${l.searchMode?0:1}; --num-skintones: ${z0};`}),d(()=>{l.customEmoji&&l.database&&L()}),d(()=>{l.customEmoji&&l.customEmoji.length?l.groups!==Fh&&(l.groups=Fh):l.groups!==Hp&&(l.currentGroupIndex&&l.currentGroupIndex--,l.groups=Hp)}),d(()=>{async function $(){l.databaseLoaded&&(l.currentSkinTone=await l.database.getPreferredSkinTone())}$()}),d(()=>{l.skinTones=Array(z0).fill().map(($,ie)=>ID(l.skinToneEmoji,ie))}),d(()=>{l.skinToneButtonText=l.skinTones[l.currentSkinTone]}),d(()=>{l.skinToneButtonLabel=l.i18n.skinToneLabel.replace("{skinTone}",l.i18n.skinTones[l.currentSkinTone])}),d(()=>{async function $(){const{database:ie}=l,ye=(await Promise.all(TD.map(Se=>ie.getEmojiByUnicodeOrName(Se)))).filter(Boolean);l.defaultFavoriteEmojis=ye}l.databaseLoaded&&$()});function L(){const{customEmoji:$,database:ie}=l,ye=$||Kp;ie.customEmoji!==ye&&(ie.customEmoji=ye)}d(()=>{async function $(){L();const{database:ie,defaultFavoriteEmojis:ye,numColumns:Se}=l,Be=await ie.getTopFavoriteEmoji(Se),Ke=await de(XS([...Be,...ye],We=>We.unicode||We.name).slice(0,Se));l.currentFavorites=Ke}l.databaseLoaded&&l.defaultFavoriteEmojis&&$()});function ne($){$D($,c,()=>{{const ie=getComputedStyle(a.rootElement),ye=parseInt(ie.getPropertyValue("--num-columns"),10),Se=ie.getPropertyValue("direction")==="rtl";l.numColumns=ye,l.isRtl=Se}})}function X($){iO($,c,ie=>{for(const{target:ye,isIntersecting:Se}of ie)ye.classList.toggle("onscreen",Se)})}d(()=>{async function $(){const{searchText:ie,currentGroup:ye,databaseLoaded:Se,customEmoji:Be}=l;if(!Se)l.currentEmojis=[],l.searchMode=!1;else if(ie.length>=CD){const Ke=await P(ie);l.searchText===ie&&(y(Ke),C(!0))}else{const{id:Ke}=ye;if(Ke!==-1||Be&&Be.length){const We=await se(Ke);l.currentGroup.id===Ke&&(y(We),C(!1))}}}$()});const I=()=>{ed(()=>FD(a.tabpanelElement))};d(()=>{const{currentEmojis:$,emojiVersion:ie}=l,ye=$.filter(Se=>Se.unicode).filter(Se=>P0(Se)&&!Yh.has(Se.unicode));if(!ie&&ye.length)y($),ed(()=>H(ye));else{const Se=ie?$:$.filter(q);y(Se),I()}});function H($){GD($,a.baselineEmoji,g)?I():l.currentEmojis=[...l.currentEmojis]}function q($){return!$.unicode||!P0($)||Yh.get($.unicode)}async function ce($){const ie=l.emojiVersion||await Vp();return $.filter(({version:ye})=>!ye||ye<=ie)}async function de($){return UD($,l.emojiVersion||await Vp())}async function se($){const ie=$===-1?l.customEmoji:await l.database.getEmojiByGroup($);return de(await ce(ie))}async function P($){return de(await ce(await l.database.getEmojiBySearchQuery($)))}d(()=>{}),d(()=>{function $(){const{searchMode:ye,currentEmojis:Se}=l;if(ye)return[{category:"",emojis:Se}];const Be=new Map;for(const Ke of Se){const We=Ke.category||"";let qt=Be.get(We);qt||(qt=[],Be.set(We,qt)),qt.push(Ke)}return[...Be.entries()].map(([Ke,We])=>({category:Ke,emojis:We})).sort((Ke,We)=>l.customCategorySorting(Ke.category,We.category))}const ie=$();S(ie)}),d(()=>{l.activeSearchItemId=l.activeSearchItem!==-1&&l.currentEmojis[l.activeSearchItem].id}),d(()=>{const{rawSearchText:$}=l;KS(()=>{l.searchText=($||"").trim(),l.activeSearchItem=-1})});function W($){if(!l.searchMode||!l.currentEmojis.length)return;const ie=ye=>{Ir($),l.activeSearchItem=Fp(ye,l.activeSearchItem,l.currentEmojis)};switch($.key){case"ArrowDown":return ie(!1);case"ArrowUp":return ie(!0);case"Enter":if(l.activeSearchItem===-1)l.activeSearchItem=0;else return Ir($),O(l.currentEmojis[l.activeSearchItem].id)}}function oe($){const{target:ie}=$,ye=ie.closest(".nav-button");if(!ye)return;const Se=parseInt(ye.dataset.groupId,10);a.searchElement.value="",l.rawSearchText="",l.searchText="",l.activeSearchItem=-1,l.currentGroupIndex=l.groups.findIndex(Be=>Be.id===Se)}function ae($){const{target:ie,key:ye}=$,Se=Be=>{Be&&(Ir($),Be.focus())};switch(ye){case"ArrowLeft":return Se(ie.previousElementSibling);case"ArrowRight":return Se(ie.nextElementSibling);case"Home":return Se(ie.parentElement.firstElementChild);case"End":return Se(ie.parentElement.lastElementChild)}}async function G($){const ie=await l.database.getEmojiByUnicodeOrName($),ye=[...l.currentEmojis,...l.currentFavorites].find(Be=>Be.id===$),Se=ye.unicode&&N(ye,l.currentSkinTone);return await l.database.incrementFavoriteEmojiCount($),{emoji:ie,skinTone:l.currentSkinTone,...Se&&{unicode:Se},...ye.name&&{name:ye.name}}}async function O($){const ie=G($);b("emoji-click-sync",ie),b("emoji-click",await ie)}function D($){const{target:ie}=$;if(!ie.classList.contains("emoji"))return;Ir($);const ye=ie.id.substring(4);O(ye)}function B($){l.currentSkinTone=$,l.skinTonePickerExpanded=!1,p("skintone-button"),b("skin-tone-change",{skinTone:$}),l.database.setPreferredSkinTone($)}function V($){const{target:{id:ie}}=$,ye=ie&&ie.match(/^skintone-(\d)/);if(!ye)return;Ir($);const Se=parseInt(ye[1],10);B(Se)}function Z($){l.skinTonePickerExpanded=!l.skinTonePickerExpanded,l.activeSkinTone=l.currentSkinTone,l.skinTonePickerExpanded&&(Ir($),ed(()=>p("skintone-list")))}d(()=>{l.skinTonePickerExpanded?a.skinToneDropdown.addEventListener("transitionend",()=>{l.skinTonePickerExpandedAfterAnimation=!0},{once:!0}):l.skinTonePickerExpandedAfterAnimation=!1});function be($){if(!l.skinTonePickerExpanded)return;const ie=async ye=>{Ir($),l.activeSkinTone=ye};switch($.key){case"ArrowUp":return ie(Fp(!0,l.activeSkinTone,l.skinTones));case"ArrowDown":return ie(Fp(!1,l.activeSkinTone,l.skinTones));case"Home":return ie(0);case"End":return ie(l.skinTones.length-1);case"Enter":return Ir($),B(l.activeSkinTone);case"Escape":return Ir($),l.skinTonePickerExpanded=!1,p("skintone-button")}}function K($){if(l.skinTonePickerExpanded)switch($.key){case" ":return Ir($),B(l.activeSkinTone)}}async function ge($){const{relatedTarget:ie}=$;(!ie||ie.id!=="skintone-list")&&(l.skinTonePickerExpanded=!1)}function me($){l.rawSearchText=$.target.value}return{$set($){$u(l,$)},$destroy(){o.abort()}}}const cO="https://cdn.jsdelivr.net/npm/emoji-picker-element-data@^1/en/emojibase/data.json",uO="en";var dO={categoriesLabel:"Categories",emojiUnsupportedMessage:"Your browser does not support color emoji.",favoritesLabel:"Favorites",loadingMessage:"Loading…",networkErrorMessage:"Could not load emoji.",regionLabel:"Emoji picker",searchDescription:"When search results are available, press up or down to select and enter to choose.",searchLabel:"Search",searchResultsLabel:"Search results",skinToneDescription:"When expanded, press up or down to select and enter to choose.",skinToneLabel:"Choose a skin tone (currently {skinTone})",skinTonesLabel:"Skin tones",skinTones:["Default","Light","Medium-Light","Medium","Medium-Dark","Dark"],categories:{custom:"Custom","smileys-emotion":"Smileys and emoticons","people-body":"People and body","animals-nature":"Animals and nature","food-drink":"Food and drink","travel-places":"Travel and places",activities:"Activities",objects:"Objects",symbols:"Symbols",flags:"Flags"}},fO=':host{--emoji-size:1.375rem;--emoji-padding:0.5rem;--category-emoji-size:var(--emoji-size);--category-emoji-padding:var(--emoji-padding);--indicator-height:3px;--input-border-radius:0.5rem;--input-border-size:1px;--input-font-size:1rem;--input-line-height:1.5;--input-padding:0.25rem;--num-columns:8;--outline-size:2px;--border-size:1px;--border-radius:0;--skintone-border-radius:1rem;--category-font-size:1rem;display:flex;width:min-content;height:400px}:host,:host(.light){color-scheme:light;--background:#fff;--border-color:#e0e0e0;--indicator-color:#385ac1;--input-border-color:#999;--input-font-color:#111;--input-placeholder-color:#999;--outline-color:#999;--category-font-color:#111;--button-active-background:#e6e6e6;--button-hover-background:#d9d9d9}:host(.dark){color-scheme:dark;--background:#222;--border-color:#444;--indicator-color:#5373ec;--input-border-color:#ccc;--input-font-color:#efefef;--input-placeholder-color:#ccc;--outline-color:#fff;--category-font-color:#efefef;--button-active-background:#555555;--button-hover-background:#484848}@media (prefers-color-scheme:dark){:host{color-scheme:dark;--background:#222;--border-color:#444;--indicator-color:#5373ec;--input-border-color:#ccc;--input-font-color:#efefef;--input-placeholder-color:#ccc;--outline-color:#fff;--category-font-color:#efefef;--button-active-background:#555555;--button-hover-background:#484848}}:host([hidden]){display:none}button{margin:0;padding:0;border:0;background:0 0;box-shadow:none;-webkit-tap-highlight-color:transparent}button::-moz-focus-inner{border:0}input{padding:0;margin:0;line-height:1.15;font-family:inherit}input[type=search]{-webkit-appearance:none}:focus{outline:var(--outline-color) solid var(--outline-size);outline-offset:calc(-1*var(--outline-size))}:host([data-js-focus-visible]) :focus:not([data-focus-visible-added]){outline:0}:focus:not(:focus-visible){outline:0}.hide-focus{outline:0}*{box-sizing:border-box}.picker{contain:content;display:flex;flex-direction:column;background:var(--background);border:var(--border-size) solid var(--border-color);border-radius:var(--border-radius);width:100%;height:100%;overflow:hidden;--total-emoji-size:calc(var(--emoji-size) + (2 * var(--emoji-padding)));--total-category-emoji-size:calc(var(--category-emoji-size) + (2 * var(--category-emoji-padding)))}.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);border:0}.hidden{opacity:0;pointer-events:none}.abs-pos{position:absolute;left:0;top:0}.gone{display:none!important}.skintone-button-wrapper,.skintone-list{background:var(--background);z-index:3}.skintone-button-wrapper.expanded{z-index:1}.skintone-list{position:absolute;inset-inline-end:0;top:0;z-index:2;overflow:visible;border-bottom:var(--border-size) solid var(--border-color);border-radius:0 0 var(--skintone-border-radius) var(--skintone-border-radius);will-change:transform;transition:transform .2s ease-in-out;transform-origin:center 0}@media (prefers-reduced-motion:reduce){.skintone-list{transition-duration:.001s}}@supports not (inset-inline-end:0){.skintone-list{right:0}}.skintone-list.no-animate{transition:none}.tabpanel{overflow-y:auto;scrollbar-gutter:stable;-webkit-overflow-scrolling:touch;will-change:transform;min-height:0;flex:1;contain:content}.emoji-menu{display:grid;grid-template-columns:repeat(var(--num-columns),var(--total-emoji-size));justify-content:space-around;align-items:flex-start;width:100%}.emoji-menu.visibility-auto{content-visibility:auto;contain-intrinsic-size:calc(var(--num-columns)*var(--total-emoji-size)) calc(var(--num-rows)*var(--total-emoji-size))}.category{padding:var(--emoji-padding);font-size:var(--category-font-size);color:var(--category-font-color)}.emoji,button.emoji{font-size:var(--emoji-size);display:flex;align-items:center;justify-content:center;border-radius:100%;height:var(--total-emoji-size);width:var(--total-emoji-size);line-height:1;overflow:hidden;font-family:var(--emoji-font-family);cursor:pointer}@media (hover:hover) and (pointer:fine){.emoji:hover,button.emoji:hover{background:var(--button-hover-background)}}.emoji.active,.emoji:active,button.emoji.active,button.emoji:active{background:var(--button-active-background)}.onscreen .custom-emoji::after{content:"";width:var(--emoji-size);height:var(--emoji-size);background-repeat:no-repeat;background-position:center center;background-size:contain;background-image:var(--custom-emoji-background)}.nav,.nav-button{align-items:center}.nav{display:grid;justify-content:space-between;contain:content}.nav-button{display:flex;justify-content:center}.nav-emoji{font-size:var(--category-emoji-size);width:var(--total-category-emoji-size);height:var(--total-category-emoji-size)}.indicator-wrapper{display:flex;border-bottom:1px solid var(--border-color)}.indicator{width:calc(100%/var(--num-groups));height:var(--indicator-height);opacity:var(--indicator-opacity);background-color:var(--indicator-color);will-change:transform,opacity;transition:opacity .1s linear,transform .25s ease-in-out}@media (prefers-reduced-motion:reduce){.indicator{will-change:opacity;transition:opacity .1s linear}}.pad-top,input.search{background:var(--background);width:100%}.pad-top{height:var(--emoji-padding);z-index:3}.search-row{display:flex;align-items:center;position:relative;padding-inline-start:var(--emoji-padding);padding-bottom:var(--emoji-padding)}.search-wrapper{flex:1;min-width:0}input.search{padding:var(--input-padding);border-radius:var(--input-border-radius);border:var(--input-border-size) solid var(--input-border-color);color:var(--input-font-color);font-size:var(--input-font-size);line-height:var(--input-line-height)}input.search::placeholder{color:var(--input-placeholder-color)}.favorites{overflow-y:auto;scrollbar-gutter:stable;display:flex;flex-direction:row;border-top:var(--border-size) solid var(--border-color);contain:content}.message{padding:var(--emoji-padding)}';const ZS=["customEmoji","customCategorySorting","database","dataSource","i18n","locale","skinToneEmoji","emojiVersion"],mO=`:host{--emoji-font-family:${WS}}`;class Cx extends HTMLElement{constructor(n){super(),this.attachShadow({mode:"open"});const a=document.createElement("style");a.textContent=fO+mO,this.shadowRoot.appendChild(a),this._ctx={locale:uO,dataSource:cO,skinToneEmoji:ED,customCategorySorting:MD,customEmoji:null,i18n:dO,emojiVersion:null,...n};for(const o of ZS)o!=="database"&&Object.prototype.hasOwnProperty.call(this,o)&&(this._ctx[o]=this[o],delete this[o]);this._dbFlush()}connectedCallback(){V0(this),this._cmp||(this._cmp=lO(this.shadowRoot,this._ctx))}disconnectedCallback(){V0(this),md(()=>{if(!this.isConnected&&this._cmp){this._cmp.$destroy(),this._cmp=void 0;const{database:n}=this._ctx;n.close().catch(a=>console.error(a))}})}static get observedAttributes(){return["locale","data-source","skin-tone-emoji","emoji-version"]}attributeChangedCallback(n,a,o){this._set(n.replace(/-([a-z])/g,(c,l)=>l.toUpperCase()),n==="emoji-version"?parseFloat(o):o)}_set(n,a){this._ctx[n]=a,this._cmp&&this._cmp.$set({[n]:a}),["locale","dataSource"].includes(n)&&this._dbFlush()}_dbCreate(){const{locale:n,dataSource:a,database:o}=this._ctx;(!o||o.locale!==n||o.dataSource!==a)&&this._set("database",new jD({locale:n,dataSource:a}))}_dbFlush(){md(()=>this._dbCreate())}}const QS={};for(const t of ZS)QS[t]={get(){return t==="database"&&this._dbCreate(),this._ctx[t]},set(n){if(t==="database")throw new Error("database is read-only");this._set(t,n)}};Object.defineProperties(Cx.prototype,QS);function V0(t){t instanceof Cx||Object.setPrototypeOf(t,customElements.get(t.tagName.toLowerCase()).prototype)}customElements.get("emoji-picker")||customElements.define("emoji-picker",Cx);function pO({onPick:t}){const n=f.useRef(null);return f.useEffect(()=>{const a=n.current;if(!a)return;const o=document.createElement("emoji-picker");o.className="unicode-emoji-picker-el",o.setAttribute("data-theme","dark");const c=l=>{var p;const d=l.detail,m=(d==null?void 0:d.unicode)??((p=d==null?void 0:d.emoji)==null?void 0:p.unicode);m&&t(m)};return o.addEventListener("emoji-click",c),a.appendChild(o),()=>{o.removeEventListener("emoji-click",c),o.remove()}},[t]),s.jsx("div",{ref:n,className:"unicode-emoji-panel-host overflow-hidden rounded-lg border border-border/50"})}const hO=/^<(a?):([^:>]+):(\d{17,20})>$/;function td(t,n,a=!1){return`${a?"`}function JS(t){const n=String(t??"").trim();if(!n)return{kind:"empty",value:""};const a=n.match(hO);return a?{kind:"custom",value:n,animated:a[1]==="a",name:a[2],id:a[3]}:{kind:"unicode",value:n}}function e5(t,n=!1){return`https://cdn.discordapp.com/emojis/${t}.${n?"gif":"png"}?size=64`}function gO(t,n=[]){const a=JS(t);if(a.kind==="custom"&&a.id&&!a.name){const o=n.find(c=>c.id===a.id);if(o)return{kind:"custom",value:td(o.name,o.id,o.animated),name:o.name,id:o.id,animated:o.animated}}if(a.kind==="custom"&&a.id){const o=n.find(c=>c.id===a.id);if(o&&a.value!==td(o.name,o.id,o.animated))return{kind:"custom",value:td(o.name,o.id,o.animated),name:o.name,id:o.id,animated:o.animated}}return a}function xO({value:t,guildEmojis:n,size:a="md"}){const o=gO(t,n),c=a==="lg"?"size-10":"size-7",l=a==="lg"?"text-3xl":"text-2xl";return o.kind==="empty"?s.jsx("span",{className:"text-sm text-muted-foreground",children:"No emoji selected"}):o.kind==="custom"&&o.id?s.jsxs("span",{className:"inline-flex items-center gap-3",children:[s.jsx("img",{src:e5(o.id,o.animated),alt:o.name??"custom emoji",className:pe(c,"shrink-0 rounded-md"),loading:"lazy"}),s.jsxs("span",{className:"flex flex-col items-start gap-0.5",children:[s.jsxs("span",{className:"text-sm font-medium",children:[":",o.name,":"]}),s.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:o.value})]})]}):s.jsx("span",{className:pe(l,"leading-none"),title:o.value,children:o.value})}function bO({id:t,label:n,description:a,value:o,onChange:c,readOnly:l}){const[d,m]=f.useState(!1),[p,g]=f.useState("server"),[b,v]=f.useState(null),[w,y]=f.useState(""),[C,S]=f.useState(!1),[N,E]=f.useState(""),T=f.useCallback(async(I=!1)=>{S(!0),y("");try{const H=await Ne.getGuildResources(I);H.data?(v(H.data),Array.isArray(H.data.emojis)||y("Server response is missing emojis. Restart the bot after updating.")):y("No guild data returned.")}catch(H){y(H instanceof Error?H.message:"Could not load server emojis")}finally{S(!1)}},[]);f.useEffect(()=>{d&&T(!0)},[d,T]);const M=f.useMemo(()=>Array.isArray(b==null?void 0:b.emojis)?b.emojis:[],[b]),k=f.useMemo(()=>{const I=N.trim().toLowerCase();return I?M.filter(H=>H.name.toLowerCase().includes(I)):M},[M,N]),_=String(o??""),R=JS(_);function L(I){c(I),m(!1)}function ne(I){c(td(I.name,I.id,I.animated)),m(!1)}function X(){c("")}return s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{htmlFor:t,children:n}),a?s.jsx("p",{className:"text-xs text-muted-foreground",children:a}):null,s.jsxs("div",{className:"flex flex-col gap-3 rounded-xl border border-border bg-card p-3 sm:flex-row sm:items-center sm:justify-between",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsx(xO,{value:o,guildEmojis:M,size:"lg"})}),s.jsxs("div",{className:"flex shrink-0 gap-2",children:[s.jsx(ue,{type:"button",variant:"secondary",size:"sm",disabled:l,onClick:()=>m(!0),children:"Choose emoji"}),_?s.jsx(ue,{type:"button",variant:"ghost",size:"sm",disabled:l,onClick:X,children:"Clear"}):null]})]}),s.jsx(Qs,{open:d,onOpenChange:m,children:s.jsxs(hs,{className:"max-h-[min(90vh,720px)] max-w-lg gap-0 overflow-hidden p-0 sm:max-w-xl",children:[s.jsxs(gs,{className:"space-y-1 border-b border-border px-5 py-4",children:[s.jsx(xs,{children:"Choose emoji"}),s.jsxs(bs,{children:["Server emojis save as"," ",s.jsx("code",{className:"rounded bg-muted px-1 text-xs",children:"<:name:id>"}),". Standard emojis save as Unicode characters."]})]}),s.jsxs(DS,{value:p,onValueChange:I=>g(I),className:"flex min-h-0 flex-1 flex-col",children:[s.jsxs(xx,{className:"mx-5 mt-3 grid h-9 w-auto grid-cols-2",children:[s.jsx(Ys,{value:"server",children:"Server"}),s.jsx(Ys,{value:"unicode",children:"All emojis"})]}),s.jsxs($h,{value:"server",className:"mt-0 flex-1 px-5 pb-4 pt-3",children:[s.jsxs("div",{className:"relative mb-3",children:[s.jsx(xe,{icon:vi,size:16,className:"pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground"}),s.jsx(_e,{placeholder:"Search by name…",value:N,onChange:I=>E(I.target.value),className:"h-9 border-border bg-secondary/30 pl-9"})]}),b?s.jsxs("p",{className:"mb-2 text-xs text-muted-foreground",children:[b.guildName," · ",M.length," custom emoji",M.length===1?"":"s"]}):null,s.jsx(fc,{className:"h-[min(50vh,320px)] rounded-lg border border-border/50 bg-secondary/20",children:C?s.jsx("div",{className:"grid grid-cols-6 gap-2 p-3 sm:grid-cols-8",children:Array.from({length:24}).map((I,H)=>s.jsx(Ue,{className:"aspect-square rounded-lg"},H))}):w?s.jsxs("div",{className:"space-y-3 p-4 text-center",children:[s.jsx("p",{className:"text-sm text-destructive",children:w}),s.jsx(ue,{type:"button",variant:"outline",size:"sm",onClick:()=>void T(!0),children:"Retry"})]}):k.length===0?s.jsx("p",{className:"p-6 text-center text-sm text-muted-foreground",children:M.length===0?"No custom emojis in this server, or the bot needs the Guild Emojis intent (restart after update).":"No emojis match your search."}):s.jsx("div",{className:"grid grid-cols-6 gap-1.5 p-2 sm:grid-cols-8",children:k.map(I=>{const H=R.kind==="custom"&&R.id===I.id;return s.jsx("button",{type:"button",title:`:${I.name}:`,className:pe("flex aspect-square items-center justify-center rounded-lg border border-transparent bg-background/50 transition-colors hover:border-primary/30 hover:bg-accent",H&&"border-primary/50 bg-primary/15 ring-2 ring-primary/30"),onClick:()=>ne(I),children:s.jsx("img",{src:I.url??e5(I.id,I.animated),alt:I.name,className:"size-8 object-contain",loading:"lazy"})},I.id)})})})]}),s.jsx($h,{value:"unicode",className:"mt-0 px-5 pb-4 pt-3",children:s.jsx(pO,{onPick:L})})]})]})}),s.jsx(_e,{value:_,disabled:l,onChange:I=>c(I.target.value),placeholder:"Unicode or <:name:id>",className:"border-border bg-secondary/30 font-mono text-xs"})]})}const F0="BOT_TOKEN",vO="MODEL_API_KEY";function pd({field:t,value:n,onChange:a,readOnly:o}){const c=t.path.replace(/\./g,"-");if(t.type==="googleFont")return s.jsx(S_,{field:t,value:n,onChange:a,readOnly:o});if(t.type==="boolean")return s.jsxs("div",{className:"flex items-center justify-between gap-4 rounded-lg border border-border bg-secondary/20 px-3 py-2.5",children:[s.jsxs("div",{children:[s.jsx(Ae,{htmlFor:c,className:"font-medium",children:t.label}),t.description?s.jsx("p",{className:"text-xs text-muted-foreground",children:t.description}):null]}),s.jsx(Mt,{id:c,checked:!!n,disabled:o,onCheckedChange:a})]});if(t.type==="stringList")return s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{children:t.label}),t.description?s.jsx("p",{className:"text-xs text-muted-foreground",children:t.description}):null,s.jsx(w_,{value:Array.isArray(n)?n:[],onChange:a})]});if(t.type==="select"&&t.options)return s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{htmlFor:c,children:t.label}),s.jsxs(Ca,{value:String(n??""),disabled:o,onValueChange:a,children:[s.jsx(Hr,{id:c,className:"border-border bg-secondary/30",children:s.jsx(Sa,{placeholder:"Select…"})}),s.jsx(Gr,{children:t.options.map(d=>s.jsx(Et,{value:d.value,children:d.label},d.value))})]})]});if(t.type==="color"){const d=$r(String(n??"#000000"));return s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{htmlFor:c,children:t.label}),t.description?s.jsx("p",{className:"text-xs text-muted-foreground",children:t.description}):null,s.jsxs("div",{className:"flex gap-2",children:[s.jsx(tf,{value:d,onChange:a}),s.jsx(_e,{id:c,value:d,disabled:o,onChange:m=>a(m.target.value),onBlur:m=>a($r(m.target.value,d)),className:"border-border bg-secondary/30 font-mono uppercase",placeholder:"#000000",maxLength:7})]})]})}if(t.type==="emoji")return s.jsx(bO,{id:c,label:t.label,description:t.description,value:n,onChange:a,readOnly:o});if(t.type==="discordChannel"||t.type==="discordRole"||t.type==="discordCategory"){const d=t.type==="discordRole"?"role":t.type==="discordCategory"?"category":"channel";return s.jsx(TS,{id:c,label:t.label,description:t.description,kind:d,value:n,onChange:a,readOnly:o})}if(t.type==="secret"){const d=n===F0||n===vO||!n?"":"••••••••••••";return s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{htmlFor:c,children:t.label}),t.description?s.jsx("p",{className:"text-xs text-muted-foreground",children:t.description}):null,s.jsx(_e,{id:c,type:"password",value:d,disabled:o,placeholder:t.placeholder??"Unchanged if empty",onChange:m=>{const p=m.target.value;a(p||(t.placeholder??F0))},className:"border-border bg-secondary/30"})]})}const l="border-border bg-secondary/30";return t.type==="textarea"?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{htmlFor:c,children:t.label}),s.jsx(Jd,{id:c,value:String(n??""),disabled:o,onChange:d=>a(d.target.value),className:`min-h-[88px] ${l}`})]}):s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{htmlFor:c,children:t.label}),t.description?s.jsx("p",{className:"text-xs text-muted-foreground",children:t.description}):null,s.jsx(_e,{id:c,type:t.type==="number"?"number":"text",value:n==null?"":String(n),disabled:o,onChange:d=>a(t.type==="number"?Number(d.target.value):d.target.value),placeholder:t.placeholder??(t.type==="discordId"?"Discord snowflake ID":void 0),className:l})]})}const Je=f.forwardRef(({className:t,...n},a)=>s.jsx("div",{ref:a,className:pe("rounded-xl border border-border bg-card text-card-foreground shadow-none",t),...n}));Je.displayName="Card";const dt=f.forwardRef(({className:t,...n},a)=>s.jsx("div",{ref:a,className:pe("flex flex-col space-y-1.5 p-6",t),...n}));dt.displayName="CardHeader";const ft=f.forwardRef(({className:t,...n},a)=>s.jsx("div",{ref:a,className:pe("font-semibold leading-none tracking-tight",t),...n}));ft.displayName="CardTitle";const Ot=f.forwardRef(({className:t,...n},a)=>s.jsx("div",{ref:a,className:pe("text-sm text-muted-foreground",t),...n}));Ot.displayName="CardDescription";const et=f.forwardRef(({className:t,...n},a)=>s.jsx("div",{ref:a,className:pe("p-6 pt-0",t),...n}));et.displayName="CardContent";const Sx=f.forwardRef(({className:t,...n},a)=>s.jsx("div",{ref:a,className:pe("flex items-center p-6 pt-0",t),...n}));Sx.displayName="CardFooter";function Y0(t){return t.replace(/_/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/\b\w/g,n=>n.toUpperCase())}function yO(t,n){if(typeof n=="boolean")return"boolean";if(typeof n=="number")return"number";if(Array.isArray(n))return"stringList";if(typeof n=="string"){const a=t.toLowerCase();return/prefix/.test(a)?"text":/emoji/.test(a)?"emoji":/guild.?id|guild_id/.test(a)?"discordId":/category/.test(a)?"discordCategory":/channel|forum/.test(a)?"discordChannel":/role|staff|admin|moderator/.test(a)?"discordRole":n.length>100?"textarea":"text"}return"text"}function Nx(t,n=""){const a=[];for(const[o,c]of Object.entries(t)){const l=n?`${n}.${o}`:o;if(Array.isArray(c)){if(c.length>0&&typeof c[0]=="object"&&c[0]!==null&&!Array.isArray(c[0]))continue;a.push({path:l,label:Y0(o),type:"stringList"});continue}if(c&&typeof c=="object"&&Object.keys(c).length>0){a.push(...Nx(c,l));continue}a.push({path:l,label:Y0(o),type:yO(o,c)})}return a}function wO(t){const n=Nx(t);return n.length===0?[{title:"Configuration",fields:[]}]:[{title:"Settings",description:"Values from this addon’s config file.",fields:n}]}function kr(t,n){const a=n.split(".");let o=t;for(const c of a){if(o==null||typeof o!="object")return;o=o[c]}return o}function Gn(t,n,a){const o=n.split("."),c=structuredClone(t);let l=c;for(let d=0;d{switch(t){case"success":return NO;case"info":return kO;case"warning":return EO;case"error":return TO;default:return null}},CO=Array(12).fill(0),SO=({visible:t,className:n})=>ve.createElement("div",{className:["sonner-loading-wrapper",n].filter(Boolean).join(" "),"data-visible":t},ve.createElement("div",{className:"sonner-spinner"},CO.map((a,o)=>ve.createElement("div",{className:"sonner-loading-bar",key:`spinner-bar-${o}`})))),NO=ve.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",height:"20",width:"20"},ve.createElement("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z",clipRule:"evenodd"})),EO=ve.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",height:"20",width:"20"},ve.createElement("path",{fillRule:"evenodd",d:"M9.401 3.003c1.155-2 4.043-2 5.197 0l7.355 12.748c1.154 2-.29 4.5-2.599 4.5H4.645c-2.309 0-3.752-2.5-2.598-4.5L9.4 3.003zM12 8.25a.75.75 0 01.75.75v3.75a.75.75 0 01-1.5 0V9a.75.75 0 01.75-.75zm0 8.25a.75.75 0 100-1.5.75.75 0 000 1.5z",clipRule:"evenodd"})),kO=ve.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",height:"20",width:"20"},ve.createElement("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z",clipRule:"evenodd"})),TO=ve.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",height:"20",width:"20"},ve.createElement("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z",clipRule:"evenodd"})),MO=ve.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},ve.createElement("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),ve.createElement("line",{x1:"6",y1:"6",x2:"18",y2:"18"})),RO=()=>{let[t,n]=ve.useState(document.hidden);return ve.useEffect(()=>{let a=()=>{n(document.hidden)};return document.addEventListener("visibilitychange",a),()=>window.removeEventListener("visibilitychange",a)},[]),t},qh=1,AO=class{constructor(){this.subscribe=t=>(this.subscribers.push(t),()=>{let n=this.subscribers.indexOf(t);this.subscribers.splice(n,1)}),this.publish=t=>{this.subscribers.forEach(n=>n(t))},this.addToast=t=>{this.publish(t),this.toasts=[...this.toasts,t]},this.create=t=>{var n;let{message:a,...o}=t,c=typeof(t==null?void 0:t.id)=="number"||((n=t.id)==null?void 0:n.length)>0?t.id:qh++,l=this.toasts.find(m=>m.id===c),d=t.dismissible===void 0?!0:t.dismissible;return this.dismissedToasts.has(c)&&this.dismissedToasts.delete(c),l?this.toasts=this.toasts.map(m=>m.id===c?(this.publish({...m,...t,id:c,title:a}),{...m,...t,id:c,dismissible:d,title:a}):m):this.addToast({title:a,...o,dismissible:d,id:c}),c},this.dismiss=t=>(this.dismissedToasts.add(t),t||this.toasts.forEach(n=>{this.subscribers.forEach(a=>a({id:n.id,dismiss:!0}))}),this.subscribers.forEach(n=>n({id:t,dismiss:!0})),t),this.message=(t,n)=>this.create({...n,message:t}),this.error=(t,n)=>this.create({...n,message:t,type:"error"}),this.success=(t,n)=>this.create({...n,type:"success",message:t}),this.info=(t,n)=>this.create({...n,type:"info",message:t}),this.warning=(t,n)=>this.create({...n,type:"warning",message:t}),this.loading=(t,n)=>this.create({...n,type:"loading",message:t}),this.promise=(t,n)=>{if(!n)return;let a;n.loading!==void 0&&(a=this.create({...n,promise:t,type:"loading",message:n.loading,description:typeof n.description!="function"?n.description:void 0}));let o=t instanceof Promise?t:t(),c=a!==void 0,l,d=o.then(async p=>{if(l=["resolve",p],ve.isValidElement(p))c=!1,this.create({id:a,type:"default",message:p});else if(DO(p)&&!p.ok){c=!1;let g=typeof n.error=="function"?await n.error(`HTTP error! status: ${p.status}`):n.error,b=typeof n.description=="function"?await n.description(`HTTP error! status: ${p.status}`):n.description;this.create({id:a,type:"error",message:g,description:b})}else if(n.success!==void 0){c=!1;let g=typeof n.success=="function"?await n.success(p):n.success,b=typeof n.description=="function"?await n.description(p):n.description;this.create({id:a,type:"success",message:g,description:b})}}).catch(async p=>{if(l=["reject",p],n.error!==void 0){c=!1;let g=typeof n.error=="function"?await n.error(p):n.error,b=typeof n.description=="function"?await n.description(p):n.description;this.create({id:a,type:"error",message:g,description:b})}}).finally(()=>{var p;c&&(this.dismiss(a),a=void 0),(p=n.finally)==null||p.call(n)}),m=()=>new Promise((p,g)=>d.then(()=>l[0]==="reject"?g(l[1]):p(l[1])).catch(g));return typeof a!="string"&&typeof a!="number"?{unwrap:m}:Object.assign(a,{unwrap:m})},this.custom=(t,n)=>{let a=(n==null?void 0:n.id)||qh++;return this.create({jsx:t(a),id:a,...n}),a},this.getActiveToasts=()=>this.toasts.filter(t=>!this.dismissedToasts.has(t.id)),this.subscribers=[],this.toasts=[],this.dismissedToasts=new Set}},Mn=new AO,_O=(t,n)=>{let a=(n==null?void 0:n.id)||qh++;return Mn.addToast({title:t,...n,id:a}),a},DO=t=>t&&typeof t=="object"&&"ok"in t&&typeof t.ok=="boolean"&&"status"in t&&typeof t.status=="number",OO=_O,LO=()=>Mn.toasts,zO=()=>Mn.getActiveToasts(),Dt=Object.assign(OO,{success:Mn.success,info:Mn.info,warning:Mn.warning,error:Mn.error,custom:Mn.custom,message:Mn.message,promise:Mn.promise,dismiss:Mn.dismiss,loading:Mn.loading},{getHistory:LO,getToasts:zO});function PO(t,{insertAt:n}={}){if(typeof document>"u")return;let a=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css",n==="top"&&a.firstChild?a.insertBefore(o,a.firstChild):a.appendChild(o),o.styleSheet?o.styleSheet.cssText=t:o.appendChild(document.createTextNode(t))}PO(`:where(html[dir="ltr"]),:where([data-sonner-toaster][dir="ltr"]){--toast-icon-margin-start: -3px;--toast-icon-margin-end: 4px;--toast-svg-margin-start: -1px;--toast-svg-margin-end: 0px;--toast-button-margin-start: auto;--toast-button-margin-end: 0;--toast-close-button-start: 0;--toast-close-button-end: unset;--toast-close-button-transform: translate(-35%, -35%)}:where(html[dir="rtl"]),:where([data-sonner-toaster][dir="rtl"]){--toast-icon-margin-start: 4px;--toast-icon-margin-end: -3px;--toast-svg-margin-start: 0px;--toast-svg-margin-end: -1px;--toast-button-margin-start: 0;--toast-button-margin-end: auto;--toast-close-button-start: unset;--toast-close-button-end: 0;--toast-close-button-transform: translate(35%, -35%)}:where([data-sonner-toaster]){position:fixed;width:var(--width);font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;--gray1: hsl(0, 0%, 99%);--gray2: hsl(0, 0%, 97.3%);--gray3: hsl(0, 0%, 95.1%);--gray4: hsl(0, 0%, 93%);--gray5: hsl(0, 0%, 90.9%);--gray6: hsl(0, 0%, 88.7%);--gray7: hsl(0, 0%, 85.8%);--gray8: hsl(0, 0%, 78%);--gray9: hsl(0, 0%, 56.1%);--gray10: hsl(0, 0%, 52.3%);--gray11: hsl(0, 0%, 43.5%);--gray12: hsl(0, 0%, 9%);--border-radius: 8px;box-sizing:border-box;padding:0;margin:0;list-style:none;outline:none;z-index:999999999;transition:transform .4s ease}:where([data-sonner-toaster][data-lifted="true"]){transform:translateY(-10px)}@media (hover: none) and (pointer: coarse){:where([data-sonner-toaster][data-lifted="true"]){transform:none}}:where([data-sonner-toaster][data-x-position="right"]){right:var(--offset-right)}:where([data-sonner-toaster][data-x-position="left"]){left:var(--offset-left)}:where([data-sonner-toaster][data-x-position="center"]){left:50%;transform:translate(-50%)}:where([data-sonner-toaster][data-y-position="top"]){top:var(--offset-top)}:where([data-sonner-toaster][data-y-position="bottom"]){bottom:var(--offset-bottom)}:where([data-sonner-toast]){--y: translateY(100%);--lift-amount: calc(var(--lift) * var(--gap));z-index:var(--z-index);position:absolute;opacity:0;transform:var(--y);filter:blur(0);touch-action:none;transition:transform .4s,opacity .4s,height .4s,box-shadow .2s;box-sizing:border-box;outline:none;overflow-wrap:anywhere}:where([data-sonner-toast][data-styled="true"]){padding:16px;background:var(--normal-bg);border:1px solid var(--normal-border);color:var(--normal-text);border-radius:var(--border-radius);box-shadow:0 4px 12px #0000001a;width:var(--width);font-size:13px;display:flex;align-items:center;gap:6px}:where([data-sonner-toast]:focus-visible){box-shadow:0 4px 12px #0000001a,0 0 0 2px #0003}:where([data-sonner-toast][data-y-position="top"]){top:0;--y: translateY(-100%);--lift: 1;--lift-amount: calc(1 * var(--gap))}:where([data-sonner-toast][data-y-position="bottom"]){bottom:0;--y: translateY(100%);--lift: -1;--lift-amount: calc(var(--lift) * var(--gap))}:where([data-sonner-toast]) :where([data-description]){font-weight:400;line-height:1.4;color:inherit}:where([data-sonner-toast]) :where([data-title]){font-weight:500;line-height:1.5;color:inherit}:where([data-sonner-toast]) :where([data-icon]){display:flex;height:16px;width:16px;position:relative;justify-content:flex-start;align-items:center;flex-shrink:0;margin-left:var(--toast-icon-margin-start);margin-right:var(--toast-icon-margin-end)}:where([data-sonner-toast][data-promise="true"]) :where([data-icon])>svg{opacity:0;transform:scale(.8);transform-origin:center;animation:sonner-fade-in .3s ease forwards}:where([data-sonner-toast]) :where([data-icon])>*{flex-shrink:0}:where([data-sonner-toast]) :where([data-icon]) svg{margin-left:var(--toast-svg-margin-start);margin-right:var(--toast-svg-margin-end)}:where([data-sonner-toast]) :where([data-content]){display:flex;flex-direction:column;gap:2px}[data-sonner-toast][data-styled=true] [data-button]{border-radius:4px;padding-left:8px;padding-right:8px;height:24px;font-size:12px;color:var(--normal-bg);background:var(--normal-text);margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end);border:none;cursor:pointer;outline:none;display:flex;align-items:center;flex-shrink:0;transition:opacity .4s,box-shadow .2s}:where([data-sonner-toast]) :where([data-button]):focus-visible{box-shadow:0 0 0 2px #0006}:where([data-sonner-toast]) :where([data-button]):first-of-type{margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end)}:where([data-sonner-toast]) :where([data-cancel]){color:var(--normal-text);background:rgba(0,0,0,.08)}:where([data-sonner-toast][data-theme="dark"]) :where([data-cancel]){background:rgba(255,255,255,.3)}:where([data-sonner-toast]) :where([data-close-button]){position:absolute;left:var(--toast-close-button-start);right:var(--toast-close-button-end);top:0;height:20px;width:20px;display:flex;justify-content:center;align-items:center;padding:0;color:var(--gray12);border:1px solid var(--gray4);transform:var(--toast-close-button-transform);border-radius:50%;cursor:pointer;z-index:1;transition:opacity .1s,background .2s,border-color .2s}[data-sonner-toast] [data-close-button]{background:var(--gray1)}:where([data-sonner-toast]) :where([data-close-button]):focus-visible{box-shadow:0 4px 12px #0000001a,0 0 0 2px #0003}:where([data-sonner-toast]) :where([data-disabled="true"]){cursor:not-allowed}:where([data-sonner-toast]):hover :where([data-close-button]):hover{background:var(--gray2);border-color:var(--gray5)}:where([data-sonner-toast][data-swiping="true"]):before{content:"";position:absolute;left:-50%;right:-50%;height:100%;z-index:-1}:where([data-sonner-toast][data-y-position="top"][data-swiping="true"]):before{bottom:50%;transform:scaleY(3) translateY(50%)}:where([data-sonner-toast][data-y-position="bottom"][data-swiping="true"]):before{top:50%;transform:scaleY(3) translateY(-50%)}:where([data-sonner-toast][data-swiping="false"][data-removed="true"]):before{content:"";position:absolute;inset:0;transform:scaleY(2)}:where([data-sonner-toast]):after{content:"";position:absolute;left:0;height:calc(var(--gap) + 1px);bottom:100%;width:100%}:where([data-sonner-toast][data-mounted="true"]){--y: translateY(0);opacity:1}:where([data-sonner-toast][data-expanded="false"][data-front="false"]){--scale: var(--toasts-before) * .05 + 1;--y: translateY(calc(var(--lift-amount) * var(--toasts-before))) scale(calc(-1 * var(--scale)));height:var(--front-toast-height)}:where([data-sonner-toast])>*{transition:opacity .4s}:where([data-sonner-toast][data-expanded="false"][data-front="false"][data-styled="true"])>*{opacity:0}:where([data-sonner-toast][data-visible="false"]){opacity:0;pointer-events:none}:where([data-sonner-toast][data-mounted="true"][data-expanded="true"]){--y: translateY(calc(var(--lift) * var(--offset)));height:var(--initial-height)}:where([data-sonner-toast][data-removed="true"][data-front="true"][data-swipe-out="false"]){--y: translateY(calc(var(--lift) * -100%));opacity:0}:where([data-sonner-toast][data-removed="true"][data-front="false"][data-swipe-out="false"][data-expanded="true"]){--y: translateY(calc(var(--lift) * var(--offset) + var(--lift) * -100%));opacity:0}:where([data-sonner-toast][data-removed="true"][data-front="false"][data-swipe-out="false"][data-expanded="false"]){--y: translateY(40%);opacity:0;transition:transform .5s,opacity .2s}:where([data-sonner-toast][data-removed="true"][data-front="false"]):before{height:calc(var(--initial-height) + 20%)}[data-sonner-toast][data-swiping=true]{transform:var(--y) translateY(var(--swipe-amount-y, 0px)) translate(var(--swipe-amount-x, 0px));transition:none}[data-sonner-toast][data-swiped=true]{user-select:none}[data-sonner-toast][data-swipe-out=true][data-y-position=bottom],[data-sonner-toast][data-swipe-out=true][data-y-position=top]{animation-duration:.2s;animation-timing-function:ease-out;animation-fill-mode:forwards}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=left]{animation-name:swipe-out-left}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=right]{animation-name:swipe-out-right}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=up]{animation-name:swipe-out-up}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=down]{animation-name:swipe-out-down}@keyframes swipe-out-left{0%{transform:var(--y) translate(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translate(calc(var(--swipe-amount-x) - 100%));opacity:0}}@keyframes swipe-out-right{0%{transform:var(--y) translate(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translate(calc(var(--swipe-amount-x) + 100%));opacity:0}}@keyframes swipe-out-up{0%{transform:var(--y) translateY(var(--swipe-amount-y));opacity:1}to{transform:var(--y) translateY(calc(var(--swipe-amount-y) - 100%));opacity:0}}@keyframes swipe-out-down{0%{transform:var(--y) translateY(var(--swipe-amount-y));opacity:1}to{transform:var(--y) translateY(calc(var(--swipe-amount-y) + 100%));opacity:0}}@media (max-width: 600px){[data-sonner-toaster]{position:fixed;right:var(--mobile-offset-right);left:var(--mobile-offset-left);width:100%}[data-sonner-toaster][dir=rtl]{left:calc(var(--mobile-offset-left) * -1)}[data-sonner-toaster] [data-sonner-toast]{left:0;right:0;width:calc(100% - var(--mobile-offset-left) * 2)}[data-sonner-toaster][data-x-position=left]{left:var(--mobile-offset-left)}[data-sonner-toaster][data-y-position=bottom]{bottom:var(--mobile-offset-bottom)}[data-sonner-toaster][data-y-position=top]{top:var(--mobile-offset-top)}[data-sonner-toaster][data-x-position=center]{left:var(--mobile-offset-left);right:var(--mobile-offset-right);transform:none}}[data-sonner-toaster][data-theme=light]{--normal-bg: #fff;--normal-border: var(--gray4);--normal-text: var(--gray12);--success-bg: hsl(143, 85%, 96%);--success-border: hsl(145, 92%, 91%);--success-text: hsl(140, 100%, 27%);--info-bg: hsl(208, 100%, 97%);--info-border: hsl(221, 91%, 91%);--info-text: hsl(210, 92%, 45%);--warning-bg: hsl(49, 100%, 97%);--warning-border: hsl(49, 91%, 91%);--warning-text: hsl(31, 92%, 45%);--error-bg: hsl(359, 100%, 97%);--error-border: hsl(359, 100%, 94%);--error-text: hsl(360, 100%, 45%)}[data-sonner-toaster][data-theme=light] [data-sonner-toast][data-invert=true]{--normal-bg: #000;--normal-border: hsl(0, 0%, 20%);--normal-text: var(--gray1)}[data-sonner-toaster][data-theme=dark] [data-sonner-toast][data-invert=true]{--normal-bg: #fff;--normal-border: var(--gray3);--normal-text: var(--gray12)}[data-sonner-toaster][data-theme=dark]{--normal-bg: #000;--normal-bg-hover: hsl(0, 0%, 12%);--normal-border: hsl(0, 0%, 20%);--normal-border-hover: hsl(0, 0%, 25%);--normal-text: var(--gray1);--success-bg: hsl(150, 100%, 6%);--success-border: hsl(147, 100%, 12%);--success-text: hsl(150, 86%, 65%);--info-bg: hsl(215, 100%, 6%);--info-border: hsl(223, 100%, 12%);--info-text: hsl(216, 87%, 65%);--warning-bg: hsl(64, 100%, 6%);--warning-border: hsl(60, 100%, 12%);--warning-text: hsl(46, 87%, 65%);--error-bg: hsl(358, 76%, 10%);--error-border: hsl(357, 89%, 16%);--error-text: hsl(358, 100%, 81%)}[data-sonner-toaster][data-theme=dark] [data-sonner-toast] [data-close-button]{background:var(--normal-bg);border-color:var(--normal-border);color:var(--normal-text)}[data-sonner-toaster][data-theme=dark] [data-sonner-toast] [data-close-button]:hover{background:var(--normal-bg-hover);border-color:var(--normal-border-hover)}[data-rich-colors=true][data-sonner-toast][data-type=success],[data-rich-colors=true][data-sonner-toast][data-type=success] [data-close-button]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}[data-rich-colors=true][data-sonner-toast][data-type=info],[data-rich-colors=true][data-sonner-toast][data-type=info] [data-close-button]{background:var(--info-bg);border-color:var(--info-border);color:var(--info-text)}[data-rich-colors=true][data-sonner-toast][data-type=warning],[data-rich-colors=true][data-sonner-toast][data-type=warning] [data-close-button]{background:var(--warning-bg);border-color:var(--warning-border);color:var(--warning-text)}[data-rich-colors=true][data-sonner-toast][data-type=error],[data-rich-colors=true][data-sonner-toast][data-type=error] [data-close-button]{background:var(--error-bg);border-color:var(--error-border);color:var(--error-text)}.sonner-loading-wrapper{--size: 16px;height:var(--size);width:var(--size);position:absolute;inset:0;z-index:10}.sonner-loading-wrapper[data-visible=false]{transform-origin:center;animation:sonner-fade-out .2s ease forwards}.sonner-spinner{position:relative;top:50%;left:50%;height:var(--size);width:var(--size)}.sonner-loading-bar{animation:sonner-spin 1.2s linear infinite;background:var(--gray11);border-radius:6px;height:8%;left:-10%;position:absolute;top:-3.9%;width:24%}.sonner-loading-bar:nth-child(1){animation-delay:-1.2s;transform:rotate(.0001deg) translate(146%)}.sonner-loading-bar:nth-child(2){animation-delay:-1.1s;transform:rotate(30deg) translate(146%)}.sonner-loading-bar:nth-child(3){animation-delay:-1s;transform:rotate(60deg) translate(146%)}.sonner-loading-bar:nth-child(4){animation-delay:-.9s;transform:rotate(90deg) translate(146%)}.sonner-loading-bar:nth-child(5){animation-delay:-.8s;transform:rotate(120deg) translate(146%)}.sonner-loading-bar:nth-child(6){animation-delay:-.7s;transform:rotate(150deg) translate(146%)}.sonner-loading-bar:nth-child(7){animation-delay:-.6s;transform:rotate(180deg) translate(146%)}.sonner-loading-bar:nth-child(8){animation-delay:-.5s;transform:rotate(210deg) translate(146%)}.sonner-loading-bar:nth-child(9){animation-delay:-.4s;transform:rotate(240deg) translate(146%)}.sonner-loading-bar:nth-child(10){animation-delay:-.3s;transform:rotate(270deg) translate(146%)}.sonner-loading-bar:nth-child(11){animation-delay:-.2s;transform:rotate(300deg) translate(146%)}.sonner-loading-bar:nth-child(12){animation-delay:-.1s;transform:rotate(330deg) translate(146%)}@keyframes sonner-fade-in{0%{opacity:0;transform:scale(.8)}to{opacity:1;transform:scale(1)}}@keyframes sonner-fade-out{0%{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.8)}}@keyframes sonner-spin{0%{opacity:1}to{opacity:.15}}@media (prefers-reduced-motion){[data-sonner-toast],[data-sonner-toast]>*,.sonner-loading-bar{transition:none!important;animation:none!important}}.sonner-loader{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);transform-origin:center;transition:opacity .2s,transform .2s}.sonner-loader[data-visible=false]{opacity:0;transform:scale(.8) translate(-50%,-50%)} `);function Hu(t){return t.label!==void 0}var IO=3,UO="32px",BO="16px",q0=4e3,$O=356,HO=14,GO=20,VO=200;function jr(...t){return t.filter(Boolean).join(" ")}function FO(t){let[n,a]=t.split("-"),o=[];return n&&o.push(n),a&&o.push(a),o}var YO=t=>{var n,a,o,c,l,d,m,p,g,b,v;let{invert:w,toast:y,unstyled:C,interacting:S,setHeights:N,visibleToasts:E,heights:T,index:M,toasts:k,expanded:_,removeToast:R,defaultRichColors:L,closeButton:ne,style:X,cancelButtonStyle:I,actionButtonStyle:H,className:q="",descriptionClassName:ce="",duration:de,position:se,gap:P,loadingIcon:W,expandByDefault:oe,classNames:ae,icons:G,closeButtonAriaLabel:O="Close toast",pauseWhenPageIsHidden:D}=t,[B,V]=ve.useState(null),[Z,be]=ve.useState(null),[K,ge]=ve.useState(!1),[me,$]=ve.useState(!1),[ie,ye]=ve.useState(!1),[Se,Be]=ve.useState(!1),[Ke,We]=ve.useState(!1),[qt,vn]=ve.useState(0),[Xn,br]=ve.useState(0),yn=ve.useRef(y.duration||de||q0),wn=ve.useRef(null),Zn=ve.useRef(null),Kt=M===0,po=M+1<=E,Pt=y.type,Qn=y.dismissible!==!1,Da=y.className||"",Es=y.descriptionClassName||"",qr=ve.useMemo(()=>T.findIndex(De=>De.toastId===y.id)||0,[T,y.id]),ho=ve.useMemo(()=>{var De;return(De=y.closeButton)!=null?De:ne},[y.closeButton,ne]),Kr=ve.useMemo(()=>y.duration||de||q0,[y.duration,de]),Dn=ve.useRef(0),yt=ve.useRef(0),On=ve.useRef(0),Rt=ve.useRef(null),[Ai,_i]=se.split("-"),go=ve.useMemo(()=>T.reduce((De,rt,lt)=>lt>=qr?De:De+rt.height,0),[T,qr]),Wr=RO(),Oa=y.invert||w,Ar=Pt==="loading";yt.current=ve.useMemo(()=>qr*P+go,[qr,go]),ve.useEffect(()=>{yn.current=Kr},[Kr]),ve.useEffect(()=>{ge(!0)},[]),ve.useEffect(()=>{let De=Zn.current;if(De){let rt=De.getBoundingClientRect().height;return br(rt),N(lt=>[{toastId:y.id,height:rt,position:y.position},...lt]),()=>N(lt=>lt.filter(rn=>rn.toastId!==y.id))}},[N,y.id]),ve.useLayoutEffect(()=>{if(!K)return;let De=Zn.current,rt=De.style.height;De.style.height="auto";let lt=De.getBoundingClientRect().height;De.style.height=rt,br(lt),N(rn=>rn.find(It=>It.toastId===y.id)?rn.map(It=>It.toastId===y.id?{...It,height:lt}:It):[{toastId:y.id,height:lt,position:y.position},...rn])},[K,y.title,y.description,N,y.id]);let Wt=ve.useCallback(()=>{$(!0),vn(yt.current),N(De=>De.filter(rt=>rt.toastId!==y.id)),setTimeout(()=>{R(y)},VO)},[y,R,N,yt]);ve.useEffect(()=>{if(y.promise&&Pt==="loading"||y.duration===1/0||y.type==="loading")return;let De;return _||S||D&&Wr?(()=>{if(On.current{var rt;(rt=y.onAutoClose)==null||rt.call(y,y),Wt()},yn.current)),()=>clearTimeout(De)},[_,S,y,Pt,D,Wr,Wt]),ve.useEffect(()=>{y.delete&&Wt()},[Wt,y.delete]);function La(){var De,rt,lt;return G!=null&&G.loading?ve.createElement("div",{className:jr(ae==null?void 0:ae.loader,(De=y==null?void 0:y.classNames)==null?void 0:De.loader,"sonner-loader"),"data-visible":Pt==="loading"},G.loading):W?ve.createElement("div",{className:jr(ae==null?void 0:ae.loader,(rt=y==null?void 0:y.classNames)==null?void 0:rt.loader,"sonner-loader"),"data-visible":Pt==="loading"},W):ve.createElement(SO,{className:jr(ae==null?void 0:ae.loader,(lt=y==null?void 0:y.classNames)==null?void 0:lt.loader),visible:Pt==="loading"})}return ve.createElement("li",{tabIndex:0,ref:Zn,className:jr(q,Da,ae==null?void 0:ae.toast,(n=y==null?void 0:y.classNames)==null?void 0:n.toast,ae==null?void 0:ae.default,ae==null?void 0:ae[Pt],(a=y==null?void 0:y.classNames)==null?void 0:a[Pt]),"data-sonner-toast":"","data-rich-colors":(o=y.richColors)!=null?o:L,"data-styled":!(y.jsx||y.unstyled||C),"data-mounted":K,"data-promise":!!y.promise,"data-swiped":Ke,"data-removed":me,"data-visible":po,"data-y-position":Ai,"data-x-position":_i,"data-index":M,"data-front":Kt,"data-swiping":ie,"data-dismissible":Qn,"data-type":Pt,"data-invert":Oa,"data-swipe-out":Se,"data-swipe-direction":Z,"data-expanded":!!(_||oe&&K),style:{"--index":M,"--toasts-before":M,"--z-index":k.length-M,"--offset":`${me?qt:yt.current}px`,"--initial-height":oe?"auto":`${Xn}px`,...X,...y.style},onDragEnd:()=>{ye(!1),V(null),Rt.current=null},onPointerDown:De=>{Ar||!Qn||(wn.current=new Date,vn(yt.current),De.target.setPointerCapture(De.pointerId),De.target.tagName!=="BUTTON"&&(ye(!0),Rt.current={x:De.clientX,y:De.clientY}))},onPointerUp:()=>{var De,rt,lt,rn;if(Se||!Qn)return;Rt.current=null;let It=Number(((De=Zn.current)==null?void 0:De.style.getPropertyValue("--swipe-amount-x").replace("px",""))||0),Jn=Number(((rt=Zn.current)==null?void 0:rt.style.getPropertyValue("--swipe-amount-y").replace("px",""))||0),er=new Date().getTime()-((lt=wn.current)==null?void 0:lt.getTime()),bt=B==="x"?It:Jn,Ln=Math.abs(bt)/er;if(Math.abs(bt)>=GO||Ln>.11){vn(yt.current),(rn=y.onDismiss)==null||rn.call(y,y),be(B==="x"?It>0?"right":"left":Jn>0?"down":"up"),Wt(),Be(!0),We(!1);return}ye(!1),V(null)},onPointerMove:De=>{var rt,lt,rn,It;if(!Rt.current||!Qn||((rt=window.getSelection())==null?void 0:rt.toString().length)>0)return;let Jn=De.clientY-Rt.current.y,er=De.clientX-Rt.current.x,bt=(lt=t.swipeDirections)!=null?lt:FO(se);!B&&(Math.abs(er)>1||Math.abs(Jn)>1)&&V(Math.abs(er)>Math.abs(Jn)?"x":"y");let Ln={x:0,y:0};B==="y"?(bt.includes("top")||bt.includes("bottom"))&&(bt.includes("top")&&Jn<0||bt.includes("bottom")&&Jn>0)&&(Ln.y=Jn):B==="x"&&(bt.includes("left")||bt.includes("right"))&&(bt.includes("left")&&er<0||bt.includes("right")&&er>0)&&(Ln.x=er),(Math.abs(Ln.x)>0||Math.abs(Ln.y)>0)&&We(!0),(rn=Zn.current)==null||rn.style.setProperty("--swipe-amount-x",`${Ln.x}px`),(It=Zn.current)==null||It.style.setProperty("--swipe-amount-y",`${Ln.y}px`)}},ho&&!y.jsx?ve.createElement("button",{"aria-label":O,"data-disabled":Ar,"data-close-button":!0,onClick:Ar||!Qn?()=>{}:()=>{var De;Wt(),(De=y.onDismiss)==null||De.call(y,y)},className:jr(ae==null?void 0:ae.closeButton,(c=y==null?void 0:y.classNames)==null?void 0:c.closeButton)},(l=G==null?void 0:G.close)!=null?l:MO):null,y.jsx||f.isValidElement(y.title)?y.jsx?y.jsx:typeof y.title=="function"?y.title():y.title:ve.createElement(ve.Fragment,null,Pt||y.icon||y.promise?ve.createElement("div",{"data-icon":"",className:jr(ae==null?void 0:ae.icon,(d=y==null?void 0:y.classNames)==null?void 0:d.icon)},y.promise||y.type==="loading"&&!y.icon?y.icon||La():null,y.type!=="loading"?y.icon||(G==null?void 0:G[Pt])||jO(Pt):null):null,ve.createElement("div",{"data-content":"",className:jr(ae==null?void 0:ae.content,(m=y==null?void 0:y.classNames)==null?void 0:m.content)},ve.createElement("div",{"data-title":"",className:jr(ae==null?void 0:ae.title,(p=y==null?void 0:y.classNames)==null?void 0:p.title)},typeof y.title=="function"?y.title():y.title),y.description?ve.createElement("div",{"data-description":"",className:jr(ce,Es,ae==null?void 0:ae.description,(g=y==null?void 0:y.classNames)==null?void 0:g.description)},typeof y.description=="function"?y.description():y.description):null),f.isValidElement(y.cancel)?y.cancel:y.cancel&&Hu(y.cancel)?ve.createElement("button",{"data-button":!0,"data-cancel":!0,style:y.cancelButtonStyle||I,onClick:De=>{var rt,lt;Hu(y.cancel)&&Qn&&((lt=(rt=y.cancel).onClick)==null||lt.call(rt,De),Wt())},className:jr(ae==null?void 0:ae.cancelButton,(b=y==null?void 0:y.classNames)==null?void 0:b.cancelButton)},y.cancel.label):null,f.isValidElement(y.action)?y.action:y.action&&Hu(y.action)?ve.createElement("button",{"data-button":!0,"data-action":!0,style:y.actionButtonStyle||H,onClick:De=>{var rt,lt;Hu(y.action)&&((lt=(rt=y.action).onClick)==null||lt.call(rt,De),!De.defaultPrevented&&Wt())},className:jr(ae==null?void 0:ae.actionButton,(v=y==null?void 0:y.classNames)==null?void 0:v.actionButton)},y.action.label):null))};function K0(){if(typeof window>"u"||typeof document>"u")return"ltr";let t=document.documentElement.getAttribute("dir");return t==="auto"||!t?window.getComputedStyle(document.documentElement).direction:t}function qO(t,n){let a={};return[t,n].forEach((o,c)=>{let l=c===1,d=l?"--mobile-offset":"--offset",m=l?BO:UO;function p(g){["top","right","bottom","left"].forEach(b=>{a[`${d}-${b}`]=typeof g=="number"?`${g}px`:g})}typeof o=="number"||typeof o=="string"?p(o):typeof o=="object"?["top","right","bottom","left"].forEach(g=>{o[g]===void 0?a[`${d}-${g}`]=m:a[`${d}-${g}`]=typeof o[g]=="number"?`${o[g]}px`:o[g]}):p(m)}),a}var KO=f.forwardRef(function(t,n){let{invert:a,position:o="bottom-right",hotkey:c=["altKey","KeyT"],expand:l,closeButton:d,className:m,offset:p,mobileOffset:g,theme:b="light",richColors:v,duration:w,style:y,visibleToasts:C=IO,toastOptions:S,dir:N=K0(),gap:E=HO,loadingIcon:T,icons:M,containerAriaLabel:k="Notifications",pauseWhenPageIsHidden:_}=t,[R,L]=ve.useState([]),ne=ve.useMemo(()=>Array.from(new Set([o].concat(R.filter(D=>D.position).map(D=>D.position)))),[R,o]),[X,I]=ve.useState([]),[H,q]=ve.useState(!1),[ce,de]=ve.useState(!1),[se,P]=ve.useState(b!=="system"?b:typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"),W=ve.useRef(null),oe=c.join("+").replace(/Key/g,"").replace(/Digit/g,""),ae=ve.useRef(null),G=ve.useRef(!1),O=ve.useCallback(D=>{L(B=>{var V;return(V=B.find(Z=>Z.id===D.id))!=null&&V.delete||Mn.dismiss(D.id),B.filter(({id:Z})=>Z!==D.id)})},[]);return ve.useEffect(()=>Mn.subscribe(D=>{if(D.dismiss){L(B=>B.map(V=>V.id===D.id?{...V,delete:!0}:V));return}setTimeout(()=>{m8.flushSync(()=>{L(B=>{let V=B.findIndex(Z=>Z.id===D.id);return V!==-1?[...B.slice(0,V),{...B[V],...D},...B.slice(V+1)]:[D,...B]})})})}),[]),ve.useEffect(()=>{if(b!=="system"){P(b);return}if(b==="system"&&(window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?P("dark"):P("light")),typeof window>"u")return;let D=window.matchMedia("(prefers-color-scheme: dark)");try{D.addEventListener("change",({matches:B})=>{P(B?"dark":"light")})}catch{D.addListener(({matches:V})=>{try{P(V?"dark":"light")}catch(Z){console.error(Z)}})}},[b]),ve.useEffect(()=>{R.length<=1&&q(!1)},[R]),ve.useEffect(()=>{let D=B=>{var V,Z;c.every(be=>B[be]||B.code===be)&&(q(!0),(V=W.current)==null||V.focus()),B.code==="Escape"&&(document.activeElement===W.current||(Z=W.current)!=null&&Z.contains(document.activeElement))&&q(!1)};return document.addEventListener("keydown",D),()=>document.removeEventListener("keydown",D)},[c]),ve.useEffect(()=>{if(W.current)return()=>{ae.current&&(ae.current.focus({preventScroll:!0}),ae.current=null,G.current=!1)}},[W.current]),ve.createElement("section",{ref:n,"aria-label":`${k} ${oe}`,tabIndex:-1,"aria-live":"polite","aria-relevant":"additions text","aria-atomic":"false",suppressHydrationWarning:!0},ne.map((D,B)=>{var V;let[Z,be]=D.split("-");return R.length?ve.createElement("ol",{key:D,dir:N==="auto"?K0():N,tabIndex:-1,ref:W,className:m,"data-sonner-toaster":!0,"data-theme":se,"data-y-position":Z,"data-lifted":H&&R.length>1&&!l,"data-x-position":be,style:{"--front-toast-height":`${((V=X[0])==null?void 0:V.height)||0}px`,"--width":`${$O}px`,"--gap":`${E}px`,...y,...qO(p,g)},onBlur:K=>{G.current&&!K.currentTarget.contains(K.relatedTarget)&&(G.current=!1,ae.current&&(ae.current.focus({preventScroll:!0}),ae.current=null))},onFocus:K=>{K.target instanceof HTMLElement&&K.target.dataset.dismissible==="false"||G.current||(G.current=!0,ae.current=K.relatedTarget)},onMouseEnter:()=>q(!0),onMouseMove:()=>q(!0),onMouseLeave:()=>{ce||q(!1)},onDragEnd:()=>q(!1),onPointerDown:K=>{K.target instanceof HTMLElement&&K.target.dataset.dismissible==="false"||de(!0)},onPointerUp:()=>de(!1)},R.filter(K=>!K.position&&B===0||K.position===D).map((K,ge)=>{var me,$;return ve.createElement(YO,{key:K.id,icons:M,index:ge,toast:K,defaultRichColors:v,duration:(me=S==null?void 0:S.duration)!=null?me:w,className:S==null?void 0:S.className,descriptionClassName:S==null?void 0:S.descriptionClassName,invert:a,visibleToasts:C,closeButton:($=S==null?void 0:S.closeButton)!=null?$:d,interacting:ce,position:D,style:S==null?void 0:S.style,unstyled:S==null?void 0:S.unstyled,classNames:S==null?void 0:S.classNames,cancelButtonStyle:S==null?void 0:S.cancelButtonStyle,actionButtonStyle:S==null?void 0:S.actionButtonStyle,removeToast:O,toasts:R.filter(ie=>ie.position==K.position),heights:X.filter(ie=>ie.position==K.position),setHeights:I,expandByDefault:l,gap:E,loadingIcon:T,expanded:H,pauseWhenPageIsHidden:_,swipeDirections:t.swipeDirections})})):null}))});async function nd(t){const n=Dt.loading("Saving changes…");try{const a=await t();if(Dt.success("Changes saved",{id:n}),a.botRestart){const o=Dt.loading("Restarting bot…");a.botRestart.success?Dt.success("Bot started",{id:o}):Dt.error(a.botRestart.error??"Could not start bot",{id:o})}return a}catch(a){throw Dt.error(a instanceof Error?a.message:"Save failed",{id:n}),a}}function WO({filename:t}){const{canEditConfig:n}=Yt(),a=!n("supportbot"),[o,c]=f.useState(null),[l,d]=f.useState(null),[m,p]=f.useState(!0),[g,b]=f.useState(!1),[v,w]=f.useState(""),[y,C]=f.useState(""),S=f.useCallback(async()=>{p(!0),w(""),C("");try{const _=(await Ne.getAddonConfigJson(t)).data??{};c(_),d(structuredClone(_))}catch(k){w(k instanceof Error?k.message:"Failed to load config")}finally{p(!1)}},[t]);f.useEffect(()=>{S()},[S]);const N=o?wO(o):null;function E(k,_){c(R=>R&&Gn(R,k,_))}async function T(){if(!(a||!o)){b(!0),w(""),C("");try{const k=await nd(()=>Ne.saveAddonConfig(t,o));C(k.message||"Saved."),await S()}catch(k){w(k instanceof Error?k.message:"Save failed")}finally{b(!1)}}}if(m)return s.jsxs("div",{className:"space-y-4",children:[s.jsx(Ue,{className:"h-24 w-full rounded-xl"}),s.jsx(Ue,{className:"h-48 w-full rounded-xl"})]});if(!o||!N)return s.jsx(Ye,{variant:"destructive",children:s.jsx(qe,{children:v||"Failed to load"})});const M=l&&JSON.stringify(o)!==JSON.stringify(l);return s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[M?s.jsx("span",{className:"text-xs text-amber-500",children:"Unsaved changes"}):null,s.jsx(ue,{variant:"outline",size:"sm",onClick:S,disabled:m||g,children:"Reload"}),a?s.jsx("span",{className:"text-xs text-muted-foreground",children:"View only"}):s.jsxs(ue,{size:"sm",onClick:T,disabled:g||!M,children:[s.jsx(xe,{icon:Sd,size:16,className:"mr-1.5"}),g?"Saving…":"Save"]})]}),v?s.jsxs(Ye,{variant:"destructive",children:[s.jsx(xe,{icon:ig,size:18}),s.jsx(qe,{children:v})]}):null,y?s.jsx(Ye,{className:"border-primary/30 bg-primary/10 text-primary",children:s.jsx(qe,{children:y})}):null,N.map(k=>s.jsxs(Je,{className:"border-border bg-card",children:[s.jsxs(dt,{className:"pb-3",children:[s.jsx(ft,{className:"text-base",children:k.title}),k.description?s.jsx(Ot,{children:k.description}):null]}),s.jsx(et,{className:"grid gap-4 sm:grid-cols-2",children:k.fields.map(_=>s.jsx("div",{className:_.type==="textarea"||_.type==="stringList"?"sm:col-span-2":"",children:s.jsx(pd,{field:_,value:kr(o,_.path),readOnly:a,onChange:R=>E(_.path,R)})},_.path))})]},k.title))]})}function XO(t){return t.startsWith("Ticket.DepartmentSystem.")?"Ticket Departments":t.startsWith("Ticket.PrioritySystem.")?"Ticket Priorities":t.startsWith("Ticket.")?"Tickets":(t.split(".")[0]??"Other").replace(/_/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/\b\w/g,a=>a.toUpperCase())}function ZO(t,n){const a=new Set(t.flatMap(d=>d.fields.map(m=>m.path))),o=Nx(n).filter(d=>!a.has(d.path));if(o.length===0)return t;const c=t.map(d=>({...d,fields:[...d.fields]})),l=new Map;for(const d of o){const m=XO(d.path),p=l.get(m)??[];p.push(d),l.set(m,p)}for(const[d,m]of l.entries()){const p=c.find(g=>g.title.toLowerCase()===d.toLowerCase());p?p.fields.push(...m):c.push({title:d,description:"These options exist in your config file but are not in the main editor sections.",fields:m.sort((g,b)=>g.path.localeCompare(b.path))})}return c}function W0(t,n){(n==null||n>t.length)&&(n=t.length);for(var a=0,o=Array(n);a=t.length?t.apply(this,c):function(){for(var d=arguments.length,m=new Array(d),p=0;p1&&arguments[1]!==void 0?arguments[1]:{};Gu.initial(t),Gu.handler(n);var a={current:t},o=Al(wL)(a,n),c=Al(yL)(a),l=Al(Gu.changes)(t),d=Al(vL)(a);function m(){var g=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(b){return b};return Gu.selector(g),g(a.current)}function p(g){cL(o,c,l,d)(g)}return[m,p]}function vL(t,n){return Ql(n)?n(t.current):n}function yL(t,n){return t.current=J0(J0({},t.current),n),n}function wL(t,n,a){return Ql(n)?n(t.current):Object.keys(a).forEach(function(o){var c;return(c=n[o])===null||c===void 0?void 0:c.call(n,t.current[o])}),a}var jL={create:bL},CL={paths:{vs:"https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs"}};function SL(t){return function n(){for(var a=this,o=arguments.length,c=new Array(o),l=0;l=t.length?t.apply(this,c):function(){for(var d=arguments.length,m=new Array(d),p=0;p{o.current=!1}:t,n)}var Yn=XL;function zl(){}function si(t,n,a,o){return ZL(t,o)||QL(t,n,a,o)}function ZL(t,n){return t.editor.getModel(l5(t,n))}function QL(t,n,a,o){return t.editor.createModel(n,a,o?l5(t,o):void 0)}function l5(t,n){return t.Uri.parse(n)}function JL({original:t,modified:n,language:a,originalLanguage:o,modifiedLanguage:c,originalModelPath:l,modifiedModelPath:d,keepCurrentOriginalModel:m=!1,keepCurrentModifiedModel:p=!1,theme:g="light",loading:b="Loading...",options:v={},height:w="100%",width:y="100%",className:C,wrapperProps:S={},beforeMount:N=zl,onMount:E=zl}){let[T,M]=f.useState(!1),[k,_]=f.useState(!0),R=f.useRef(null),L=f.useRef(null),ne=f.useRef(null),X=f.useRef(E),I=f.useRef(N),H=f.useRef(!1);i5(()=>{let se=s5.init();return se.then(P=>(L.current=P)&&_(!1)).catch(P=>(P==null?void 0:P.type)!=="cancelation"&&console.error("Monaco initialization: error:",P)),()=>R.current?de():se.cancel()}),Yn(()=>{if(R.current&&L.current){let se=R.current.getOriginalEditor(),P=si(L.current,t||"",o||a||"text",l||"");P!==se.getModel()&&se.setModel(P)}},[l],T),Yn(()=>{if(R.current&&L.current){let se=R.current.getModifiedEditor(),P=si(L.current,n||"",c||a||"text",d||"");P!==se.getModel()&&se.setModel(P)}},[d],T),Yn(()=>{let se=R.current.getModifiedEditor();se.getOption(L.current.editor.EditorOption.readOnly)?se.setValue(n||""):n!==se.getValue()&&(se.executeEdits("",[{range:se.getModel().getFullModelRange(),text:n||"",forceMoveMarkers:!0}]),se.pushUndoStop())},[n],T),Yn(()=>{var se,P;(P=(se=R.current)==null?void 0:se.getModel())==null||P.original.setValue(t||"")},[t],T),Yn(()=>{let{original:se,modified:P}=R.current.getModel();L.current.editor.setModelLanguage(se,o||a||"text"),L.current.editor.setModelLanguage(P,c||a||"text")},[a,o,c],T),Yn(()=>{var se;(se=L.current)==null||se.editor.setTheme(g)},[g],T),Yn(()=>{var se;(se=R.current)==null||se.updateOptions(v)},[v],T);let q=f.useCallback(()=>{var W;if(!L.current)return;I.current(L.current);let se=si(L.current,t||"",o||a||"text",l||""),P=si(L.current,n||"",c||a||"text",d||"");(W=R.current)==null||W.setModel({original:se,modified:P})},[a,n,c,t,o,l,d]),ce=f.useCallback(()=>{var se;!H.current&&ne.current&&(R.current=L.current.editor.createDiffEditor(ne.current,{automaticLayout:!0,...v}),q(),(se=L.current)==null||se.editor.setTheme(g),M(!0),H.current=!0)},[v,g,q]);f.useEffect(()=>{T&&X.current(R.current,L.current)},[T]),f.useEffect(()=>{!k&&!T&&ce()},[k,T,ce]);function de(){var P,W,oe,ae;let se=(P=R.current)==null?void 0:P.getModel();m||((W=se==null?void 0:se.original)==null||W.dispose()),p||((oe=se==null?void 0:se.modified)==null||oe.dispose()),(ae=R.current)==null||ae.dispose()}return ve.createElement(o5,{width:y,height:w,isEditorReady:T,loading:b,_ref:ne,className:C,wrapperProps:S})}var ez=JL;f.memo(ez);function tz(t){let n=f.useRef();return f.useEffect(()=>{n.current=t},[t]),n.current}var nz=tz,Vu=new Map;function rz({defaultValue:t,defaultLanguage:n,defaultPath:a,value:o,language:c,path:l,theme:d="light",line:m,loading:p="Loading...",options:g={},overrideServices:b={},saveViewState:v=!0,keepCurrentModel:w=!1,width:y="100%",height:C="100%",className:S,wrapperProps:N={},beforeMount:E=zl,onMount:T=zl,onChange:M,onValidate:k=zl}){let[_,R]=f.useState(!1),[L,ne]=f.useState(!0),X=f.useRef(null),I=f.useRef(null),H=f.useRef(null),q=f.useRef(T),ce=f.useRef(E),de=f.useRef(),se=f.useRef(o),P=nz(l),W=f.useRef(!1),oe=f.useRef(!1);i5(()=>{let O=s5.init();return O.then(D=>(X.current=D)&&ne(!1)).catch(D=>(D==null?void 0:D.type)!=="cancelation"&&console.error("Monaco initialization: error:",D)),()=>I.current?G():O.cancel()}),Yn(()=>{var D,B,V,Z;let O=si(X.current,t||o||"",n||c||"",l||a||"");O!==((D=I.current)==null?void 0:D.getModel())&&(v&&Vu.set(P,(B=I.current)==null?void 0:B.saveViewState()),(V=I.current)==null||V.setModel(O),v&&((Z=I.current)==null||Z.restoreViewState(Vu.get(l))))},[l],_),Yn(()=>{var O;(O=I.current)==null||O.updateOptions(g)},[g],_),Yn(()=>{!I.current||o===void 0||(I.current.getOption(X.current.editor.EditorOption.readOnly)?I.current.setValue(o):o!==I.current.getValue()&&(oe.current=!0,I.current.executeEdits("",[{range:I.current.getModel().getFullModelRange(),text:o,forceMoveMarkers:!0}]),I.current.pushUndoStop(),oe.current=!1))},[o],_),Yn(()=>{var D,B;let O=(D=I.current)==null?void 0:D.getModel();O&&c&&((B=X.current)==null||B.editor.setModelLanguage(O,c))},[c],_),Yn(()=>{var O;m!==void 0&&((O=I.current)==null||O.revealLine(m))},[m],_),Yn(()=>{var O;(O=X.current)==null||O.editor.setTheme(d)},[d],_);let ae=f.useCallback(()=>{var O;if(!(!H.current||!X.current)&&!W.current){ce.current(X.current);let D=l||a,B=si(X.current,o||t||"",n||c||"",D||"");I.current=(O=X.current)==null?void 0:O.editor.create(H.current,{model:B,automaticLayout:!0,...g},b),v&&I.current.restoreViewState(Vu.get(D)),X.current.editor.setTheme(d),m!==void 0&&I.current.revealLine(m),R(!0),W.current=!0}},[t,n,a,o,c,l,g,b,v,d,m]);f.useEffect(()=>{_&&q.current(I.current,X.current)},[_]),f.useEffect(()=>{!L&&!_&&ae()},[L,_,ae]),se.current=o,f.useEffect(()=>{var O,D;_&&M&&((O=de.current)==null||O.dispose(),de.current=(D=I.current)==null?void 0:D.onDidChangeModelContent(B=>{oe.current||M(I.current.getValue(),B)}))},[_,M]),f.useEffect(()=>{if(_){let O=X.current.editor.onDidChangeMarkers(D=>{var V;let B=(V=I.current.getModel())==null?void 0:V.uri;if(B&&D.find(Z=>Z.path===B.path)){let Z=X.current.editor.getModelMarkers({resource:B});k==null||k(Z)}});return()=>{O==null||O.dispose()}}return()=>{}},[_,k]);function G(){var O,D;(O=de.current)==null||O.dispose(),w?v&&Vu.set(l,I.current.saveViewState()):(D=I.current.getModel())==null||D.dispose(),I.current.dispose()}return ve.createElement(o5,{width:y,height:C,isEditorReady:_,loading:p,_ref:H,className:S,wrapperProps:N})}var az=rz,sz=f.memo(az),oz=sz;function iz(t){return t!==null&&typeof t=="object"&&"Command"in t}function lz(t){return Object.entries(t).filter(([,n])=>iz(n)).map(([n,a])=>({key:n,...a}))}function cz({data:t,onChange:n}){const a=lz(t);function o(c,l){const d=t[c];n({...t,[c]:{...d,...l}})}return a.length===0?s.jsx("p",{className:"text-sm text-muted-foreground",children:"No commands found in this config."}):s.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:a.map(c=>s.jsxs(Je,{className:"border-border bg-card",children:[s.jsxs(dt,{className:"flex flex-row items-center gap-2 space-y-0 pb-2",children:[s.jsx("div",{className:"flex size-9 items-center justify-center rounded-lg bg-primary/15 text-primary",children:s.jsx(xe,{icon:ds,size:18})}),s.jsx(ft,{className:"text-base",children:c.key})]}),s.jsxs(et,{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx(Ae,{htmlFor:`${c.key}-enabled`,children:"Enabled"}),s.jsx(Mt,{id:`${c.key}-enabled`,checked:c.Enabled!==!1,onCheckedChange:l=>o(c.key,{Enabled:l})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx(Ae,{children:"Slash command"}),s.jsx(_e,{value:c.Command??"",onChange:l=>o(c.key,{Command:l.target.value}),className:"border-border bg-secondary/30 font-mono"})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx(Ae,{children:"Description"}),s.jsx(_e,{value:c.Description??"",onChange:l=>o(c.key,{Description:l.target.value}),className:"border-border bg-secondary/30"})]})]})]},c.key))})}function uz(t,n){let a=structuredClone(n);if(t==="supportbot"){const o=kr(a,"General.Token");o&&o!=="BOT_TOKEN"&&(a=Gn(a,"General.Token","BOT_TOKEN"))}if(t==="supportbot-ai"){const o=kr(a,"General.Model_API_Key");o&&o!=="MODEL_API_KEY"&&(a=Gn(a,"General.Model_API_Key","MODEL_API_KEY"))}return a}function dz(t,n,a,o){const c={};for(const l of n)for(const d of l.fields){const m=kr(a,d.path),p=kr(o,d.path);d.type==="secret"&&(m==="BOT_TOKEN"||m==="MODEL_API_KEY"||m===""||m===void 0)||JSON.stringify(m)!==JSON.stringify(p)&&(c[`${t}:${d.path}`]=m)}return c}function fz(t,n){const a=new Map,o=[];for(const l of t){const d=l.path.split(".");if(d.length>=5&&d[1]==="DepartmentSystem"&&d[2]==="Departments"){const m=d[3],p=a.get(m)??[];p.push(l),a.set(m,p)}else if(d.length>=3){const m=d[1],p=a.get(m)??[];p.push(l),a.set(m,p)}else o.push(l)}if(a.size===0)return{standalone:t,groups:[]};const c=[...a.entries()].map(([l,d])=>{const m=["enabled","name","description","emoji","category","role","channelprefix","defaultpriority","questions"];d.sort((b,v)=>{var N,E;const w=((N=b.path.split(".").pop())==null?void 0:N.toLowerCase())||"",y=((E=v.path.split(".").pop())==null?void 0:E.toLowerCase())||"",C=m.indexOf(w),S=m.indexOf(y);return C!==-1&&S!==-1?C-S:C!==-1?-1:S!==-1?1:w.localeCompare(y)});const p=d.find(b=>b.path.toLowerCase().endsWith(".name")||b.path.toLowerCase().endsWith(".title"));let g="";if(p&&n){const b=kr(n,p.path);typeof b=="string"&&b.trim()&&(g=b.trim())}return g||(g=l.replace(/_/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/\b\w/g,b=>b.toUpperCase())),{key:l,name:g,fields:d}});return{standalone:o,groups:c}}function mz({configFile:t}){const{permissions:n,canEditConfig:a}=Yt(),o=Rn(n,"configs.raw_yaml"),c=!a(t),[l,d]=f.useState(null),[m,p]=f.useState(null),[g,b]=f.useState(!0),[v,w]=f.useState(!1),[y,C]=f.useState(""),[S,N]=f.useState(""),[E,T]=f.useState("visual");f.useEffect(()=>{!o&&E==="yaml"&&T("visual")},[o,E]);const[M,k]=f.useState(""),[_,R]=f.useState(""),[L]=wd(),[ne,X]=f.useState(()=>L.get("tab")||null),[I,H]=f.useState(!1),[q,ce]=f.useState(""),[de,se]=f.useState(""),P=()=>{const K=q.trim().toLowerCase().replace(/[^a-z0-9_-]/g,"");if(!K||!l)return;const ge=de.trim()||K,me=`Ticket.DepartmentSystem.Departments.${K}`,$={...l};Gn($,`${me}.Name`,ge),Gn($,`${me}.Description`,`Open a ${ge} ticket`),Gn($,`${me}.Emoji`,"🎫"),Gn($,`${me}.Category`,"CATEGORY_ID"),Gn($,`${me}.Role`,"ROLE_ID"),Gn($,`${me}.ChannelPrefix`,`${K}-`),Gn($,`${me}.DefaultPriority`,"normal"),Gn($,`${me}.Questions`,["What do you need assistance with?"]),d($),H(!1),ce(""),se("")},W=K=>{if(!l)return;const ge=`Ticket.DepartmentSystem.Departments.${K}`,me=JSON.parse(JSON.stringify(l));if(Object.keys(me).forEach($=>{($.startsWith(ge)||$===ge)&&delete me[$]}),me.Ticket&&typeof me.Ticket=="object"){const $=me.Ticket.DepartmentSystem;$&&typeof $=="object"&&$.Departments&&typeof $.Departments=="object"&&delete $.Departments[K]}d(me)},oe=FM(t),ae=f.useMemo(()=>!oe||oe==="commands"||!l?oe:ZO(oe,l),[oe,l]);f.useEffect(()=>{var K;if(ae&&ae!=="commands"){const ge=L.get("tab");if(ge&&ae.find(me=>me.title.toLowerCase()===ge.toLowerCase())){const me=ae.find($=>$.title.toLowerCase()===ge.toLowerCase());me&&me.title!==ne&&X(me.title)}else(!ne||!ae.find(me=>me.title===ne))&&X(((K=ae[0])==null?void 0:K.title)||null)}},[ae,ne,L]);const G=f.useCallback(async()=>{b(!0),C(""),N("");try{const ge=(await Ne.getConfigJson(t)).data??{},me=uz(t,ge);d(me),p(me);const ie=(await Ne.getConfigRaw(t)).data??"",ye=z8(ie,t);k(ye),R(ye)}catch(K){C(K instanceof Error?K.message:"Failed to load config")}finally{b(!1)}},[t]);f.useEffect(()=>{G()},[G]);function O(K,ge){d(me=>me&&Gn(me,K,ge))}async function D(){if(!(c||M===_)){w(!0),C(""),N("");try{const K=await nd(()=>Ne.saveConfigRaw(t,M));N(K.message||"Config saved."),await G()}catch(K){C(K instanceof Error?K.message:"Save failed")}finally{w(!1)}}}async function B(){if(!(c||!l||!m)){if(E==="yaml"){await D();return}w(!0),C(""),N("");try{if(oe==="commands"){const K={};for(const me of Object.keys(l))JSON.stringify(l[me])!==JSON.stringify(m[me])&&(K[`${t}:${me}`]=l[me]);if(Object.keys(K).length===0){N("No changes to save.");return}const ge=await nd(()=>Ne.updateConfigFields(K));N(ge.message||"")}else if(ae&&ae!=="commands"){const K=dz(t,ae,l,m);if(Object.keys(K).length===0){N("No changes to save.");return}const ge=await nd(()=>Ne.updateConfigFields(K));N(ge.message||"")}await G()}catch(K){C(K instanceof Error?K.message:"Save failed")}finally{w(!1)}}}if(oe===null)return s.jsx(Ye,{children:s.jsx(qe,{children:"No visual editor available for this file."})});if(g)return s.jsxs("div",{className:"space-y-4",children:[s.jsx(Ue,{className:"h-24 w-full rounded-xl"}),s.jsx(Ue,{className:"h-48 w-full rounded-xl"})]});if(!l)return s.jsx(Ye,{variant:"destructive",children:s.jsx(qe,{children:y||"Failed to load"})});const V=m&&JSON.stringify(l)!==JSON.stringify(m),be=E==="yaml"?M!==_:V;return s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[o?s.jsxs("div",{className:"flex rounded-lg border border-border p-0.5",children:[s.jsx(ue,{type:"button",variant:E==="visual"?"secondary":"ghost",size:"sm",className:"h-8",onClick:()=>T("visual"),children:"Visual"}),s.jsx(ue,{type:"button",variant:E==="yaml"?"secondary":"ghost",size:"sm",className:"h-8",onClick:()=>T("yaml"),children:"YAML"})]}):null,s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[be?s.jsx("span",{className:"text-xs text-amber-500",children:"Unsaved changes"}):null,s.jsx(ue,{variant:"outline",size:"sm",onClick:G,disabled:g||v,children:"Reload"}),c?s.jsx("span",{className:"text-xs text-muted-foreground",children:"View only"}):s.jsxs(ue,{size:"sm",onClick:B,disabled:v||!be,children:[s.jsx(xe,{icon:Sd,size:16,className:"mr-1.5"}),v?"Saving…":"Save"]})]})]}),y?s.jsxs(Ye,{variant:"destructive",children:[s.jsx(xe,{icon:ig,size:18}),s.jsx(qe,{children:y})]}):null,S?s.jsx(Ye,{className:"border-primary/30 bg-primary/10 text-primary",children:s.jsx(qe,{children:S})}):null,E==="yaml"?s.jsxs(Je,{className:"border-border bg-card",children:[s.jsxs(dt,{className:"pb-3",children:[s.jsx(ft,{className:"text-base",children:"Raw YAML"}),s.jsx(Ot,{children:"Edit the full file. Use this for nested lists (e.g. welcome buttons) or any option not in Visual mode."})]}),s.jsx(et,{className:"h-[min(520px,60vh)] overflow-hidden rounded-b-xl border-t border-border p-0",children:s.jsx(oz,{height:"100%",language:"yaml",theme:"vs-dark",value:M,onChange:K=>k(K||""),options:{readOnly:c,minimap:{enabled:!1},fontSize:13,wordWrap:"on",scrollBeyondLastLine:!1,padding:{top:16},tabSize:2}})})]}):oe==="commands"?s.jsx(cz,{data:l,onChange:K=>d(K)}):ae&&ae!=="commands"?s.jsxs("div",{className:"grid gap-6 lg:grid-cols-[200px_1fr]",children:[s.jsx("nav",{className:"flex flex-col gap-1",children:ae.map(K=>s.jsx("button",{onClick:()=>X(K.title),className:pe("text-left px-3 py-2 text-sm rounded-md transition-colors",ne===K.title?"bg-primary text-primary-foreground font-medium":"text-muted-foreground hover:bg-secondary hover:text-foreground"),children:K.title},K.title))}),s.jsx("div",{className:"min-w-0",children:ae.filter(K=>K.title===ne).map(K=>s.jsxs(Je,{className:"border-border bg-card",children:[s.jsxs(dt,{className:"pb-3 flex flex-row items-center justify-between",children:[s.jsxs("div",{children:[s.jsx(ft,{className:"text-base",children:K.title}),K.description?s.jsx(Ot,{children:K.description}):null]}),K.title==="Ticket Departments"&&!c&&s.jsxs(ue,{type:"button",size:"sm",variant:"outline",onClick:()=>H(!0),className:"gap-1.5 text-xs h-8 shrink-0",children:[s.jsx(xe,{icon:sg,size:14})," Add Department"]})]}),s.jsx(et,{className:"space-y-6",children:(()=>{const{standalone:ge,groups:me}=fz(K.fields,l);return s.jsxs(s.Fragment,{children:[ge.length>0&&s.jsx("div",{className:"grid gap-4 sm:grid-cols-2",children:ge.map($=>s.jsx("div",{className:$.type==="textarea"||$.type==="stringList"?"sm:col-span-2":"",children:s.jsx(pd,{field:$,value:kr(l,$.path),readOnly:c,onChange:ie=>O($.path,ie)})},$.path))}),me.map($=>s.jsxs("div",{className:"rounded-xl border border-border bg-card/60 p-4 space-y-4 shadow-sm transition-all hover:border-primary/40",children:[s.jsxs("div",{className:"flex items-center justify-between border-b border-border/60 pb-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"font-semibold text-base text-foreground",children:$.name}),s.jsx("span",{className:"text-xs font-mono px-2.5 py-0.5 rounded-full bg-primary/10 text-primary border border-primary/20 font-medium",children:K.title==="Ticket Departments"?`Ticket.${$.key}`:$.key})]}),K.title==="Ticket Departments"&&$.key!=="DepartmentSystem"&&!c&&s.jsx(ue,{type:"button",size:"sm",variant:"ghost",onClick:()=>W($.key),className:"h-7 w-7 p-0 text-muted-foreground hover:text-destructive",title:"Delete Department",children:s.jsx(xe,{icon:bi,size:14})})]}),s.jsx("div",{className:"grid gap-4 sm:grid-cols-2",children:$.fields.map(ie=>s.jsx("div",{className:ie.type==="textarea"||ie.type==="stringList"?"sm:col-span-2":"",children:s.jsx(pd,{field:ie,value:kr(l,ie.path),readOnly:c,onChange:ye=>O(ie.path,ye)})},ie.path))})]},$.key))]})})()})]},K.title))})]}):null,s.jsx(Qs,{open:I,onOpenChange:H,children:s.jsxs(hs,{className:"sm:max-w-[400px]",children:[s.jsxs(gs,{children:[s.jsx(xs,{className:"text-base",children:"Add Ticket Department"}),s.jsx(bs,{className:"text-xs",children:"Create a new support department for ticket creation."})]}),s.jsxs("div",{className:"space-y-3 py-2",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx(Ae,{className:"text-xs font-semibold",children:"Department Key (Internal ID)"}),s.jsx(_e,{placeholder:"billing",value:q,onChange:K=>ce(K.target.value.toLowerCase().replace(/[^a-z0-9_-]/g,"")),className:"text-xs font-mono border-border bg-secondary/30"}),s.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["e.g. ",s.jsx("code",{children:"billing"}),", ",s.jsx("code",{children:"technical"}),", ",s.jsx("code",{children:"sales"})]})]}),s.jsxs("div",{className:"space-y-1",children:[s.jsx(Ae,{className:"text-xs font-semibold",children:"Department Display Name"}),s.jsx(_e,{placeholder:"Billing & Sales Support",value:de,onChange:K=>se(K.target.value),className:"text-xs border-border bg-secondary/30"})]})]}),s.jsxs(Js,{className:"gap-2 sm:gap-0",children:[s.jsx(ue,{variant:"outline",size:"sm",onClick:()=>H(!1),className:"text-xs",children:"Cancel"}),s.jsx(ue,{size:"sm",onClick:P,disabled:!q.trim(),className:"text-xs bg-primary font-semibold",children:"Create Department"})]})]})})]})}const pz=Ne.listConfigs(),hz={supportbot:"Bot config","ticket-panel":"Ticket panel",commands:"Commands",messages:"Messages","supportbot-ai":"AI assistant"};function gz(){var M,k;const{permissions:t,canViewConfig:n}=Yt(),{files:a}=$2(),[o,c]=wd(),l=o.get("file"),d=n("supportbot"),m=f.useMemo(()=>pz.filter(_=>n(_)),[n]),p=f.useMemo(()=>d?a:[],[d,a]),g=f.useMemo(()=>[...m,...p.map(_=>_l(_))],[m,p]),b=g[0]??"",[v,w]=f.useState(()=>l&&g.includes(l)?l:b);if(f.useEffect(()=>{l&&g.includes(l)?w(l):g.includes(v)||(w(b),b&&c({file:b}))},[l,g,v,b,c]),g.length===0)return s.jsx(ya,{to:mg(t),replace:!0});const y=H8(v),C=(y==null?void 0:y.type)==="addon",S=C?y.file:null,N=C?H2(S):hz[v]??"Configuration",E=C?!!((M=t==null?void 0:t.configs.supportbot)!=null&&M.edit):t?!!((k=t.configs[v])!=null&&k.edit):!1,T=C?S:`${v}.yml`;return s.jsxs("div",{className:"space-y-6",children:[s.jsxs("div",{children:[s.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:N}),s.jsx("p",{className:"text-muted-foreground",children:E?`Edit ${T} — changes apply to the running bot without restarting the dashboard.`:`Viewing ${T} — you do not have permission to save changes.`})]}),s.jsx("div",{className:"mt-6",children:C&&S?s.jsx(WO,{filename:S},S):s.jsx(mz,{configFile:v},v)})]})}const xz={oauth_not_configured:"Discord OAuth is not configured. Complete setup at /setup first.",not_allowed:"Your Discord account is not allowed. Ask an owner to add you under Users, or add your ID to OwnerUserIds in Configs/api.yml.",invalid_state:"Login session expired. Please try again.",missing_code:"Discord did not return an authorization code. Please try again.",oauth_failed:"Could not complete Discord sign-in. Check your OAuth settings.",access_denied:"You cancelled Discord sign-in."};function bz(t){return t?xz[t]||"Sign-in failed. Please try again.":""}function vz(){const{branding:t}=Ed(),{isAuthenticated:n,loading:a,loginWithDiscord:o}=Yt(),[c]=wd(),l=f.useMemo(()=>bz(c.get("error")),[c]);return!a&&n?s.jsx(ya,{to:"/",replace:!0}):s.jsx("div",{className:"relative flex min-h-svh items-center justify-center bg-[#0c0c10] p-4 overflow-hidden",children:s.jsxs(Je,{className:"relative z-10 w-full max-w-md overflow-hidden rounded-3xl border border-white/10 bg-card/30 p-2 shadow-2xl backdrop-blur-2xl",children:[s.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-white/5 to-transparent pointer-events-none"}),s.jsxs(dt,{className:"space-y-6 pt-10 pb-4 text-center",children:[s.jsx("div",{className:"mx-auto flex size-28 items-center justify-center overflow-hidden rounded-3xl bg-white/5 p-4 shadow-inner ring-1 ring-white/10 transition-transform duration-500 hover:scale-105",children:s.jsx("img",{src:"/logo.png",alt:"SupportBot Logo",className:"h-full w-full object-contain drop-shadow-xl"})}),s.jsxs("div",{children:[s.jsx(ft,{className:"bg-gradient-to-br from-white to-white/50 bg-clip-text text-3xl font-extrabold tracking-tight text-transparent",children:t.title||"SupportBot"}),s.jsx(Ot,{className:"mt-2 text-base font-medium text-white/50",children:"Sign in to your dashboard"})]})]}),s.jsxs(et,{className:"space-y-6 pb-10",children:[s.jsxs("div",{className:"text-center space-y-1",children:[s.jsx("p",{className:"text-sm font-medium text-white/50",children:"Securely authenticate using your Discord account."}),s.jsxs("p",{className:"text-xs text-white/30",children:["Credentials are configured in ",s.jsx("code",{className:"rounded bg-white/5 px-1 py-0.5 text-white/40",children:"Configs/api.yml"})]})]}),l?s.jsx(Ye,{variant:"destructive",className:"border-red-500/50 bg-red-500/10 text-red-200 backdrop-blur-md",children:s.jsx(qe,{className:"font-medium",children:l})}):null,s.jsxs(ue,{type:"button",className:"group relative w-full overflow-hidden rounded-2xl bg-primary px-8 py-6 text-base font-bold text-primary-foreground shadow-[0_0_20px_rgba(var(--primary),0.3)] transition-all duration-300 hover:scale-[1.02] hover:shadow-[0_0_30px_rgba(var(--primary),0.5)] active:scale-95",disabled:a,onClick:o,children:[s.jsx("div",{className:"absolute inset-0 translate-x-[-100%] bg-gradient-to-r from-transparent via-white/20 to-transparent transition-transform duration-1000 group-hover:translate-x-[100%]"}),s.jsxs("span",{className:"relative flex items-center justify-center gap-2",children:[s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"22",height:"22",viewBox:"0 0 127.14 96.36",fill:"currentColor",children:s.jsx("path",{d:"M107.7,8.07A105.15,105.15,0,0,0,81.47,0a72.06,72.06,0,0,0-3.36,6.83A97.68,97.68,0,0,0,49,6.83,72.37,72.37,0,0,0,45.64,0,105.89,105.89,0,0,0,19.39,8.09C2.79,32.65-1.71,56.6.54,80.21h0A105.73,105.73,0,0,0,32.71,96.36,77.7,77.7,0,0,0,39.6,85.25a68.42,68.42,0,0,1-10.85-5.18c.91-.66,1.8-1.34,2.66-2a75.57,75.57,0,0,0,64.32,0c.87.71,1.76,1.39,2.66,2a68.68,68.68,0,0,1-10.87,5.19,77,77,0,0,0,6.89,11.1,105.25,105.25,0,0,0,32.19-16.14c2.64-27.38-4.51-51.11-19.32-72.15ZM42.68,68.22c-5.28,0-9.66-4.9-9.66-10.89s4.29-10.89,9.66-10.89c5.41,0,9.75,4.9,9.66,10.89C52.34,63.32,48.09,68.22,42.68,68.22Zm41.76,0c-5.28,0-9.66-4.9-9.66-10.89s4.29-10.89,9.66-10.89c5.41,0,9.75,4.9,9.66,10.89C84.44,63.32,80.19,68.22,84.44,68.22Z"})}),a?"Authenticating...":"Continue with Discord"]})]})]})]})})}const ui=[{id:"botToken",title:"Bot token",subtitle:"Connect your Discord bot",icon:cg},{id:"database",title:"Database",subtitle:"SQLite or MySQL engine",icon:x8},{id:"secretKey",title:"Session secret",subtitle:"Secure dashboard logins",icon:M8},{id:"oauth",title:"Discord OAuth",subtitle:"Sign in with Discord",icon:By},{id:"redirectUri",title:"Redirect URL",subtitle:"OAuth callback address",icon:Nd},{id:"owners",title:"Dashboard owners",subtitle:"Who can access this panel",icon:rh},{id:"emeraldApi",title:"Emerald API",subtitle:"One-click addons",icon:By}];function yz(t){return t==="oauth"?"oauth":t==="owners"?"owners":t}function wz({brandingTitle:t,faviconUrl:n,faviconVersion:a,hasFavicon:o,children:c}){return s.jsx("div",{className:"min-h-svh bg-background",children:s.jsxs("div",{className:"mx-auto flex min-h-svh max-w-6xl flex-col px-4 py-6 md:px-8 md:py-10",children:[s.jsxs("header",{className:"mb-8 flex items-center gap-4",children:[o&&n?s.jsx("img",{src:`${n}${a?`?v=${a}`:""}`,alt:"",className:"size-12 rounded-2xl border border-border object-contain"}):s.jsx("div",{className:"flex size-12 items-center justify-center rounded-2xl border border-border bg-primary text-primary-foreground",children:s.jsx(xe,{icon:cg,size:24})}),s.jsxs("div",{children:[s.jsx("p",{className:"text-xs font-medium uppercase tracking-wider text-muted-foreground",children:"First-time setup"}),s.jsx("h1",{className:"text-2xl font-semibold tracking-tight md:text-3xl",children:t})]})]}),c]})})}function jz({currentIndex:t,validation:n}){const a=(t+1)/ui.length*100;return s.jsxs("div",{className:"space-y-6",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[s.jsxs("span",{children:["Step ",t+1," of ",ui.length]}),s.jsxs("span",{children:[Math.round(a),"%"]})]}),s.jsx("div",{className:"h-2 overflow-hidden rounded-full bg-secondary",children:s.jsx("div",{className:"h-full rounded-full bg-primary transition-all duration-300 ease-out",style:{width:`${a}%`}})})]}),s.jsx("nav",{className:"hidden space-y-1 md:block","aria-label":"Setup steps",children:ui.map((o,c)=>{var g;const l=yz(o.id),d=(g=n[l])==null?void 0:g.ok,m=c===t,p=cs.jsxs("li",{className:"flex items-center gap-2",children:[s.jsx(xe,{icon:jd,size:14}),o.globalName||o.username,s.jsx("span",{className:"font-mono text-xs opacity-80",children:o.id})]},o.id))}):null,!t.bot&&!((a=t.users)!=null&&a.length)?s.jsx("p",{children:t.warning||"Verified successfully."}):null]})}):s.jsx(Ye,{variant:"destructive",children:s.jsx(qe,{children:t.error})}):null}function Sz({values:t,setValues:n,validation:a,validating:o,onValidate:c}){return s.jsxs("div",{className:"flex flex-1 flex-col gap-5",children:[s.jsxs("p",{className:"text-sm leading-relaxed text-muted-foreground",children:["Open the"," ",s.jsx("a",{href:"https://discord.com/developers/applications",target:"_blank",rel:"noreferrer",className:"font-medium text-primary hover:underline",children:"Discord Developer Portal"}),", select your application, go to ",s.jsx("strong",{children:"Bot"}),", and reset or copy the token."]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{htmlFor:"botToken",children:"Bot token"}),s.jsx(_e,{id:"botToken",type:"password",autoComplete:"off",value:t.botToken,onChange:l=>n({...t,botToken:l.target.value}),placeholder:"MTI…",className:"h-11 font-mono text-sm"})]}),s.jsx(mo,{result:a.botToken}),s.jsx("div",{className:"mt-auto",children:s.jsx(ue,{type:"button",variant:"secondary",disabled:o||!t.botToken,onClick:c,children:o?"Checking with Discord…":"Verify bot token"})})]})}function Nz({values:t,setValues:n,validation:a,validating:o,onValidate:c,onGenerate:l}){return s.jsxs("div",{className:"flex flex-1 flex-col gap-5",children:[s.jsx("p",{className:"text-sm leading-relaxed text-muted-foreground",children:"This random string signs your login cookies. Store it like a password — do not commit it to public repos."}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{htmlFor:"secretKey",children:"Session secret"}),s.jsx(_e,{id:"secretKey",type:"password",autoComplete:"off",value:t.secretKey,onChange:d=>n({...t,secretKey:d.target.value}),className:"h-11 font-mono text-sm"})]}),s.jsx(mo,{result:a.secretKey}),s.jsxs("div",{className:"mt-auto flex flex-wrap gap-2",children:[s.jsx(ue,{type:"button",variant:"outline",onClick:l,children:"Generate secure secret"}),s.jsx(ue,{type:"button",variant:"secondary",disabled:o||!t.secretKey,onClick:c,children:o?"Checking…":"Validate"})]})]})}function Ez({values:t,setValues:n,validation:a,validating:o,onValidate:c}){return s.jsxs("div",{className:"flex flex-1 flex-col gap-5",children:[s.jsxs("p",{className:"text-sm leading-relaxed text-muted-foreground",children:["Use the ",s.jsx("strong",{children:"same application"})," as your bot. Under OAuth2, copy the Client ID and Client Secret."]}),s.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[s.jsxs("div",{className:"space-y-2 sm:col-span-2",children:[s.jsx(Ae,{htmlFor:"clientId",children:"Client ID"}),s.jsx(_e,{id:"clientId",value:t.clientId,onChange:l=>n({...t,clientId:l.target.value}),className:"h-11 font-mono text-sm"})]}),s.jsxs("div",{className:"space-y-2 sm:col-span-2",children:[s.jsx(Ae,{htmlFor:"clientSecret",children:"Client Secret"}),s.jsx(_e,{id:"clientSecret",type:"password",autoComplete:"off",value:t.clientSecret,onChange:l=>n({...t,clientSecret:l.target.value}),className:"h-11 font-mono text-sm"})]})]}),s.jsx(mo,{result:a.oauth}),s.jsx("div",{className:"mt-auto",children:s.jsx(ue,{type:"button",variant:"secondary",disabled:o||!t.clientId||!t.clientSecret,onClick:c,children:o?"Checking with Discord…":"Verify OAuth credentials"})})]})}function kz({values:t,setValues:n,validation:a}){async function o(){if(t.redirectUri)try{await navigator.clipboard.writeText(t.redirectUri)}catch{}}return s.jsxs("div",{className:"flex flex-1 flex-col gap-5",children:[s.jsxs("p",{className:"text-sm leading-relaxed text-muted-foreground",children:["Add this exact URL under ",s.jsx("strong",{children:"OAuth2 → Redirects"})," in the Developer Portal. It must match character-for-character."]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{htmlFor:"redirectUri",children:"Redirect URI"}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx(_e,{id:"redirectUri",value:t.redirectUri,onChange:c=>n({...t,redirectUri:c.target.value}),className:"h-11 flex-1 font-mono text-xs"}),s.jsx(ue,{type:"button",variant:"outline",size:"icon",className:"size-11 shrink-0",onClick:()=>void o(),title:"Copy URL",children:s.jsx(xe,{icon:R2,size:18})})]})]}),a.redirectUri&&!a.redirectUri.ok?s.jsx(mo,{result:a.redirectUri}):s.jsx(Ye,{className:"border-border bg-secondary",children:s.jsx(qe,{className:"text-sm text-muted-foreground",children:"We pre-filled this from your current dashboard URL. If you access the panel from a different domain later, update this and add the new URL in Discord too."})})]})}function Tz({values:t,setValues:n,validation:a,validating:o,onValidate:c}){return s.jsxs("div",{className:"flex flex-1 flex-col gap-5",children:[s.jsxs("p",{className:"text-sm leading-relaxed text-muted-foreground",children:["Enable ",s.jsx("strong",{children:"Developer Mode"})," in Discord (Settings → Advanced), then right-click your profile and ",s.jsx("strong",{children:"Copy User ID"}),". Add one ID per line."]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{htmlFor:"owners",children:"Owner user IDs"}),s.jsx(Jd,{id:"owners",value:t.ownerUserIds,onChange:l=>n({...t,ownerUserIds:l.target.value}),placeholder:`829112572816130058 987654321098765432`,className:"min-h-[120px] font-mono text-sm"})]}),s.jsx(mo,{result:a.owners}),s.jsx("div",{className:"mt-auto",children:s.jsx(ue,{type:"button",variant:"secondary",disabled:o||!t.ownerUserIds.trim(),onClick:c,children:o?"Checking with Discord…":"Verify owner IDs"})})]})}function Mz({onContinue:t}){return s.jsx("div",{className:"mx-auto flex w-full max-w-lg flex-1 flex-col justify-center py-8",children:s.jsxs("div",{className:"rounded-2xl border border-border bg-card px-6 py-10 text-center md:px-10",children:[s.jsx("div",{className:"mx-auto mb-6 flex size-16 items-center justify-center rounded-2xl bg-primary/10 text-primary",children:s.jsx(xe,{icon:jd,size:40})}),s.jsx("h2",{className:"text-2xl font-semibold tracking-tight",children:"Setup complete"}),s.jsxs("p",{className:"mx-auto mt-3 max-w-sm text-sm leading-relaxed text-muted-foreground",children:["Your configuration has been saved. Restart the server for changes to take effect — stop the running process, then start it again (for example"," ",s.jsx("code",{className:"rounded-md bg-muted px-1.5 py-0.5 font-mono text-xs",children:"npm start"}),")."]}),s.jsx(Ye,{className:"mt-6 text-left",children:s.jsx(qe,{children:"After restarting, sign in with Discord to open the dashboard."})}),s.jsx(ue,{type:"button",size:"lg",className:"mt-8 min-w-[220px]",onClick:t,children:"Continue to sign in"})]})})}function Rz({currentIndex:t,validating:n,saving:a,onBack:o,onNext:c,onFinish:l}){const d=t===ui.length-1;return s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[s.jsxs(ue,{type:"button",variant:"ghost",disabled:t===0||a,onClick:o,children:[s.jsx(xe,{icon:T2,size:18,className:"mr-1"}),"Back"]}),s.jsx("div",{className:"flex flex-1 justify-end gap-2",children:d?s.jsx(ue,{type:"button",size:"lg",disabled:a||n,onClick:l,className:"min-w-[200px]",children:a?"Saving…":"Finish setup"}):s.jsxs(ue,{type:"button",size:"lg",disabled:n||a,onClick:c,children:["Continue",s.jsx(xe,{icon:lg,size:18,className:"ml-1"})]})})]})}function Az({values:t,setValues:n,validation:a,validating:o,onValidate:c}){return s.jsxs("div",{className:"flex flex-1 flex-col gap-5",children:[s.jsxs("p",{className:"text-sm leading-relaxed text-muted-foreground",children:["An Emerald Services API key is optional, but required to use the one-click addon installer in the dashboard. You can get yours from the"," ",s.jsx("a",{href:"https://emeraldsrv.dev",target:"_blank",rel:"noreferrer",className:"font-medium text-primary hover:underline",children:"Emerald Services Marketplace"}),"."]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{htmlFor:"emeraldApiKey",children:"Emerald API key (Optional)"}),s.jsx(_e,{id:"emeraldApiKey",type:"password",autoComplete:"off",value:t.emeraldApiKey,onChange:l=>n({...t,emeraldApiKey:l.target.value}),placeholder:"em_...",className:"h-11 font-mono text-sm"})]}),s.jsx(mo,{result:a.emeraldApi}),s.jsx("div",{className:"mt-auto",children:s.jsx(ue,{type:"button",variant:"secondary",disabled:o,onClick:c,children:o?"Checking…":t.emeraldApiKey?"Verify key":"Skip step"})})]})}function _z({values:t,setValues:n,validation:a,validating:o,onValidate:c}){const l=a.database,d=t.dbDriver==="mysql";return s.jsxs("div",{className:"flex flex-1 flex-col gap-6",children:[s.jsxs("p",{className:"text-sm leading-relaxed text-muted-foreground",children:["Choose your database storage engine. Select ",s.jsx("strong",{children:"SQLite"})," for instant zero-config local storage, or ",s.jsx("strong",{children:"MySQL / MariaDB"})," for external host databases."]}),s.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[s.jsxs("div",{onClick:()=>n(m=>({...m,dbDriver:"sqlite"})),className:pe("cursor-pointer rounded-xl border p-4 transition-all hover:border-primary",t.dbDriver==="sqlite"?"border-primary bg-primary/5 ring-2 ring-primary/20":"border-border bg-card"),children:[s.jsxs("div",{className:"flex items-center justify-between mb-2",children:[s.jsx("span",{className:"font-semibold text-foreground",children:"SQLite"}),s.jsx("span",{className:"rounded-full bg-emerald-500/10 px-2.5 py-0.5 text-xs font-medium text-emerald-500",children:"Zero Config"})]}),s.jsxs("p",{className:"text-xs text-muted-foreground",children:["Single-file SQL database stored locally at ",s.jsx("code",{className:"font-mono",children:"./Data/supportbot.db"}),". Zero extra setup required."]})]}),s.jsxs("div",{onClick:()=>n(m=>({...m,dbDriver:"mysql"})),className:pe("cursor-pointer rounded-xl border p-4 transition-all hover:border-primary",t.dbDriver==="mysql"?"border-primary bg-primary/5 ring-2 ring-primary/20":"border-border bg-card"),children:[s.jsxs("div",{className:"flex items-center justify-between mb-2",children:[s.jsx("span",{className:"font-semibold text-foreground",children:"MySQL / MariaDB"}),s.jsx("span",{className:"rounded-full bg-blue-500/10 px-2.5 py-0.5 text-xs font-medium text-blue-500",children:"External Database"})]}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"Connect to a remote or local MySQL database server."})]})]}),d&&s.jsxs("div",{className:"space-y-4 rounded-xl border border-border bg-card/50 p-4",children:[s.jsx("h4",{className:"text-sm font-semibold text-foreground",children:"MySQL Connection Settings"}),s.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[s.jsxs("div",{className:"space-y-2 sm:col-span-2",children:[s.jsx(Ae,{htmlFor:"dbHost",children:"Database Host"}),s.jsx(_e,{id:"dbHost",placeholder:"127.0.0.1 or localhost",value:t.dbHost,onChange:m=>n(p=>({...p,dbHost:m.target.value})),className:"h-11 text-sm"})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{htmlFor:"dbPort",children:"Port"}),s.jsx(_e,{id:"dbPort",placeholder:"3306",value:t.dbPort,onChange:m=>n(p=>({...p,dbPort:m.target.value})),className:"h-11 text-sm font-mono"})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{htmlFor:"dbDatabase",children:"Database Name"}),s.jsx(_e,{id:"dbDatabase",placeholder:"supportbot",value:t.dbDatabase,onChange:m=>n(p=>({...p,dbDatabase:m.target.value})),className:"h-11 text-sm"})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{htmlFor:"dbUser",children:"Database User"}),s.jsx(_e,{id:"dbUser",placeholder:"root",value:t.dbUser,onChange:m=>n(p=>({...p,dbUser:m.target.value})),className:"h-11 text-sm font-mono"})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{htmlFor:"dbPassword",children:"Password"}),s.jsx(_e,{id:"dbPassword",type:"password",placeholder:"••••••••••••",value:t.dbPassword,onChange:m=>n(p=>({...p,dbPassword:m.target.value})),className:"h-11 text-sm font-mono"})]})]})]}),s.jsx(mo,{result:l}),s.jsx("div",{className:"mt-auto",children:s.jsx(ue,{type:"button",variant:"secondary",disabled:o,onClick:c,children:o?"Testing Connection...":"Test Connection & Validate"})})]})}function Dz(){const t=crypto.randomUUID().replace(/-/g,""),n=crypto.randomUUID().replace(/-/g,"");return t+n}function Oz(t){return t.split(/[\s,]+/).map(n=>n.trim()).filter(Boolean)}function t2(t){return t==="oauth"?"oauth":t==="owners"?"owners":t==="database"?"database":t==="emeraldApi"?"emeraldApi":t}function Lz(){const t=ao(),{branding:n}=Ed(),{loading:a,error:o,refresh:c,status:l}=fS(),[d,m]=f.useState(0),[p,g]=f.useState({botToken:"",dbDriver:"sqlite",dbHost:"127.0.0.1",dbPort:"3306",dbUser:"",dbPassword:"",dbDatabase:"supportbot",secretKey:"",clientId:"",clientSecret:"",redirectUri:"",ownerUserIds:"",emeraldApiKey:""}),[b,v]=f.useState({}),[w,y]=f.useState(!1),[C,S]=f.useState(!1),[N,E]=f.useState(""),[T,M]=f.useState(!1),k=ui[d];f.useEffect(()=>{l!=null&&l.suggestedRedirectUri&&!p.redirectUri&&g(H=>({...H,redirectUri:l.suggestedRedirectUri}))},[l==null?void 0:l.suggestedRedirectUri,p.redirectUri]);const _=f.useMemo(()=>({botToken:p.botToken,dbDriver:p.dbDriver,dbHost:p.dbHost,dbPort:p.dbPort,dbUser:p.dbUser,dbPassword:p.dbPassword,dbDatabase:p.dbDatabase,secretKey:p.secretKey,clientId:p.clientId,clientSecret:p.clientSecret,redirectUri:p.redirectUri,ownerUserIds:Oz(p.ownerUserIds),emeraldApiKey:p.emeraldApiKey}),[p]);async function R(){y(!0),E("");try{const H=await Ne.validateSetup(_);return v(q=>{var ce;return{...q,...(ce=H.data)==null?void 0:ce.results}}),H.data}catch(H){return E(H instanceof Error?H.message:"Validation failed"),null}finally{y(!1)}}async function L(){var ce,de;const H=t2(k.id),q=await R();return!!((de=(ce=q==null?void 0:q.results)==null?void 0:ce[H])!=null&&de.ok)}async function ne(){const H=t2(k.id),q=b[H];!(q!=null&&q.ok)&&!await L()||m(ce=>Math.min(ce+1,ui.length-1))}async function X(){S(!0),E("");try{const H=await R();if(!(H!=null&&H.ok)){E("Fix the steps marked with errors before finishing.");return}await Ne.completeSetup(_),M(!0)}catch(H){E(H instanceof Error?H.message:"Could not save setup")}finally{S(!1)}}function I(){const H={values:p,setValues:g,validation:b,validating:w};switch(k.id){case"botToken":return s.jsx(Sz,{...H,onValidate:()=>void L()});case"database":return s.jsx(_z,{...H,onValidate:()=>void L()});case"secretKey":return s.jsx(Nz,{...H,onGenerate:()=>g(q=>({...q,secretKey:Dz()})),onValidate:()=>void L()});case"oauth":return s.jsx(Ez,{...H,onValidate:()=>void L()});case"redirectUri":return s.jsx(kz,{values:p,setValues:g,validation:b});case"owners":return s.jsx(Tz,{...H,onValidate:()=>void L()});case"emeraldApi":return s.jsx(Az,{...H,onValidate:()=>void L()})}}return a?s.jsx("div",{className:"min-h-svh bg-background px-4 py-10",children:s.jsxs("div",{className:"mx-auto max-w-6xl space-y-8",children:[s.jsx(Ue,{className:"h-14 w-64"}),s.jsxs("div",{className:"grid gap-8 lg:grid-cols-[280px_1fr]",children:[s.jsx(Ue,{className:"hidden h-80 lg:block"}),s.jsx(Ue,{className:"h-[520px] rounded-2xl"})]})]})}):s.jsxs(wz,{brandingTitle:n.title,faviconUrl:n.faviconUrl,faviconVersion:n.updatedAt??void 0,hasFavicon:n.hasFavicon,children:[o?s.jsx(Ye,{variant:"destructive",className:"mb-6",children:s.jsx(qe,{children:o})}):null,N?s.jsx(Ye,{variant:"destructive",className:"mb-6",children:s.jsx(qe,{children:N})}):null,T?s.jsx(Mz,{onContinue:async()=>{await c(),t("/login",{replace:!0})}}):s.jsxs("div",{className:"grid flex-1 gap-8 lg:grid-cols-[minmax(0,280px)_1fr]",children:[s.jsx(jz,{currentIndex:d,validation:b}),s.jsx(Cz,{step:k,footer:s.jsx(Rz,{currentIndex:d,validating:w,saving:C,onBack:()=>m(H=>Math.max(0,H-1)),onNext:()=>void ne(),onFinish:()=>void X()}),children:I()})]})]})}const zz={todo:"bg-rose-500/15 text-rose-400",progress:"bg-amber-500/15 text-amber-400",done:"bg-emerald-500/15 text-emerald-400"};function Pz({title:t,icon:n,href:a,badge:o="Configured",status:c="done"}){return s.jsxs(en,{to:a,className:pe("flex items-center gap-3 rounded-2xl border border-border bg-card p-4 transition-colors","hover:border-primary hover:bg-secondary"),children:[s.jsx("div",{className:"flex size-11 shrink-0 items-center justify-center rounded-full bg-secondary text-primary",children:s.jsx(xe,{icon:n,size:20})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("p",{className:"truncate font-semibold",children:t}),s.jsx("span",{className:pe("mt-1 inline-flex rounded-md px-2 py-0.5 text-[10px] font-semibold",zz[c]),children:o})]})]})}function Iz({percent:t,size:n=128,className:a,trackClassName:o="stroke-white/20",strokeClassName:c="stroke-white"}){const d=2*Math.PI*42,m=Math.min(100,Math.max(0,t)),p=d-m/100*d;return s.jsxs("div",{className:pe("relative inline-flex",a),children:[s.jsxs("svg",{width:n,height:n,viewBox:"0 0 100 100",className:"-rotate-90","aria-hidden":!0,children:[s.jsx("circle",{cx:"50",cy:"50",r:42,fill:"none",strokeWidth:"9",className:o}),s.jsx("circle",{cx:"50",cy:"50",r:42,fill:"none",strokeWidth:"9",strokeLinecap:"round",strokeDasharray:d,strokeDashoffset:p,className:c})]}),s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center text-center",children:[s.jsxs("span",{className:"text-2xl font-bold tabular-nums leading-none",children:[Math.round(m),"%"]}),s.jsx("span",{className:"mt-0.5 text-[10px] font-medium uppercase tracking-wide opacity-80",children:"Complete"})]})]})}const Uz={todo:{dot:"bg-rose-500",badge:"bg-rose-500/15 text-rose-400",label:"Needs setup"},progress:{dot:"bg-amber-400",badge:"bg-amber-500/15 text-amber-400",label:"In progress"},done:{dot:"bg-sky-400",badge:"bg-sky-500/15 text-sky-400",label:"Active"}};function Bz({title:t,subtitle:n,icon:a,href:o,status:c,meta:l="Open in dashboard"}){const d=Uz[c];return s.jsxs(en,{to:o,className:pe("group flex min-w-[280px] flex-1 flex-col gap-4 rounded-2xl border border-border bg-card p-4 transition-colors","hover:border-primary hover:bg-secondary","sm:min-w-[300px] lg:min-w-0"),children:[s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsx("span",{className:pe("mt-1.5 size-2 shrink-0 rounded-full",d.dot)}),s.jsx("span",{className:"text-xs text-muted-foreground",children:n})]}),s.jsxs("div",{children:[s.jsx("h3",{className:"font-semibold leading-snug tracking-tight",children:t}),s.jsx("span",{className:pe("mt-2 inline-flex rounded-md px-2 py-0.5 text-[11px] font-semibold",d.badge),children:d.label})]}),s.jsxs("div",{className:"mt-auto flex items-center justify-between border-t border-border pt-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("div",{className:"flex size-8 items-center justify-center rounded-lg bg-secondary text-primary",children:s.jsx(xe,{icon:a,size:16})}),s.jsx("span",{className:"text-xs text-muted-foreground",children:l})]}),s.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[s.jsx(xe,{icon:Nd,size:14,className:"opacity-60"}),s.jsx(xe,{icon:qs,size:14,className:"opacity-60 group-hover:text-primary"}),s.jsx(xe,{icon:lg,size:14,className:"text-primary opacity-0 transition-opacity group-hover:opacity-100"})]})]})]})}function $z({stats:t}){const n=[{id:"ping",label:"Gateway latency",detail:`${t.bot.ping}ms`,badge:t.bot.ping<200?"Good":"High",badgeClass:t.bot.ping<200?"bg-emerald-500/15 text-emerald-400":"bg-amber-500/15 text-amber-400"},{id:"uptime",label:"Bot uptime",detail:fg(t.bot.uptime),badge:"Live",badgeClass:"bg-primary/20 text-primary"},{id:"ram",label:"Memory usage",detail:`${t.hosting.ram_used} / ${t.hosting.ram_total}`,badge:`${t.hosting.ram_percent}%`,badgeClass:"bg-sky-500/15 text-sky-400"}];return s.jsxs("aside",{className:"hidden w-[min(100%,320px)] shrink-0 space-y-4 xl:block",children:[s.jsxs(Je,{className:"border-border bg-card",children:[s.jsxs(dt,{className:"flex flex-row items-center justify-between space-y-0 pb-3",children:[s.jsxs(ft,{className:"text-sm font-semibold",children:["Connected servers (",t.servers,")"]}),s.jsx(ue,{variant:"ghost",size:"icon",className:"size-7 text-muted-foreground",children:s.jsx("span",{className:"text-lg leading-none",children:"+"})})]}),s.jsxs(et,{className:"pt-0",children:[s.jsxs("div",{className:"flex -space-x-2",children:[Array.from({length:Math.min(6,t.servers)}).map((a,o)=>s.jsxs(vs,{className:"size-9 border-2 border-card ring-0",children:[s.jsx(eo,{src:t.bot.avatar,alt:""}),s.jsx(ys,{className:"bg-primary/25 text-[10px] text-primary",children:String(o+1)})]},o)),t.servers>6?s.jsxs("div",{className:"flex size-9 items-center justify-center rounded-full border-2 border-card bg-secondary text-xs font-medium text-muted-foreground",children:["+",t.servers-6]}):null]}),s.jsxs("p",{className:"mt-3 text-xs text-muted-foreground",children:[t.users.toLocaleString()," members across your guilds"]})]})]}),s.jsx(Je,{className:"overflow-hidden border-border bg-secondary",children:s.jsx(et,{className:"p-5",children:s.jsxs("div",{className:"space-y-3",children:[s.jsx("div",{className:"flex size-10 items-center justify-center rounded-xl bg-primary text-primary-foreground",children:s.jsx(xe,{icon:T8,size:22})}),s.jsxs("div",{children:[s.jsx("p",{className:"font-semibold",children:"Keep SupportBot up to date"}),s.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Check for releases and install updates from settings."})]}),s.jsx(ue,{asChild:!0,size:"sm",className:"w-full",children:s.jsxs(en,{to:"/settings",children:[s.jsx(xe,{icon:Cd,size:16,className:"mr-2"}),"Open settings"]})})]})})}),s.jsxs(Je,{className:"border-border bg-card",children:[s.jsxs(dt,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[s.jsx(ft,{className:"text-sm font-semibold",children:"System activity"}),s.jsx(ue,{variant:"ghost",size:"icon",className:"size-7 text-muted-foreground",children:s.jsx("span",{className:"text-base leading-none",children:"⋯"})})]}),s.jsxs(et,{className:"space-y-1 p-0 pb-2",children:[n.map(a=>s.jsxs("div",{className:"flex items-center gap-3 px-4 py-2.5 transition-colors hover:bg-secondary/40",children:[s.jsxs(vs,{className:"size-9",children:[s.jsx(eo,{src:t.bot.avatar,alt:t.bot.username}),s.jsx(ys,{className:"bg-secondary text-xs",children:"SB"})]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("p",{className:"truncate text-sm font-medium",children:a.label}),s.jsx("p",{className:"truncate text-xs text-muted-foreground",children:a.detail})]}),s.jsx("span",{className:`shrink-0 rounded-full px-2 py-0.5 text-[10px] font-semibold ${a.badgeClass}`,children:a.badge})]},a.id)),s.jsx(ue,{asChild:!0,variant:"ghost",className:"mx-2 mt-1 w-[calc(100%-1rem)] justify-between text-xs text-muted-foreground",children:s.jsxs(en,{to:"/system",children:["All system details",s.jsx(xe,{icon:lg,size:14})]})})]})]}),s.jsx(Je,{className:"border-border bg-card",children:s.jsxs(et,{className:"flex items-center gap-3 p-4",children:[s.jsx("div",{className:"flex size-9 items-center justify-center rounded-lg bg-secondary text-primary",children:s.jsx(xe,{icon:qs,size:18})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("p",{className:"text-sm font-medium",children:["v",t.bot.version]}),s.jsxs("p",{className:"text-xs text-muted-foreground",children:["CPU ",t.hosting.cpu_load]})]})]})})]})}const c5={todo:"Needs setup",progress:"In progress",done:"Active"};function Kh(t,n,a="Configure module"){const o=n==null?void 0:n[t];return o||{status:"todo",subtitle:a}}function Hz(){return s.jsxs("div",{className:"flex gap-6",children:[s.jsxs("div",{className:"min-w-0 flex-1 space-y-6",children:[s.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[s.jsx(Ue,{className:"h-44 rounded-2xl"}),s.jsx(Ue,{className:"h-44 rounded-2xl"})]}),s.jsx(Ue,{className:"h-8 w-48"}),s.jsx("div",{className:"flex gap-4 overflow-hidden",children:Array.from({length:3}).map((t,n)=>s.jsx(Ue,{className:"h-40 min-w-[280px] rounded-2xl"},n))}),s.jsx(Ue,{className:"h-8 w-56"}),s.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:Array.from({length:4}).map((t,n)=>s.jsx(Ue,{className:"h-20 rounded-2xl"},n))})]}),s.jsx(Ue,{className:"hidden h-[520px] w-80 shrink-0 rounded-2xl xl:block"})]})}function Gz(){const{stats:t,loading:n,error:a}=kd(),[o,c]=f.useState("all"),l=f.useMemo(()=>{if(!t)return 0;const b=t.tickets.total||0;return b===0?100:Math.round(t.tickets.closed/b*100)},[t]),d=f.useMemo(()=>o==="open"||o==="closed"?ai.filter(b=>b.category==="tickets"):o==="all"?ai:ai.filter(b=>b.category===o),[o]);if(n)return s.jsx(Hz,{});if(a||!t)return s.jsx(Ye,{variant:"destructive",children:s.jsx(qe,{children:a||"No stats available"})});const m=t.tickets.open,p=t.tickets.closed,g=t.tickets.total;return s.jsxs("div",{className:"flex flex-col gap-6 xl:flex-row xl:items-start",children:[s.jsxs("div",{className:"min-w-0 flex-1 space-y-6",children:[s.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[s.jsx(Je,{className:"overflow-hidden border-border bg-card",children:s.jsxs(et,{className:"flex flex-col gap-4 p-5 sm:flex-row sm:items-center sm:justify-between sm:p-6",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("p",{className:"text-lg font-semibold leading-snug",children:["You have"," ",s.jsx("span",{className:"text-primary",children:m})," open ticket",m===1?"":"s"]}),s.jsx("p",{className:"max-w-xs text-sm text-muted-foreground",children:"Review transcripts or tune your ticket panel so new requests are handled smoothly."}),s.jsx(ue,{asChild:!0,size:"sm",className:"rounded-lg px-5",children:s.jsx(en,{to:"/transcripts",children:"Review"})})]}),s.jsxs("div",{className:"relative mx-auto flex size-28 shrink-0 items-end justify-center sm:mx-0 sm:size-32","aria-hidden":!0,children:[s.jsx("div",{className:"absolute inset-0 rounded-2xl bg-secondary"}),s.jsx("span",{className:"relative text-6xl",children:"🎫"})]})]})}),s.jsx(Je,{className:"overflow-hidden border-border bg-primary text-primary-foreground",children:s.jsxs(et,{className:"flex flex-col gap-4 p-5 sm:flex-row sm:items-center sm:justify-between sm:p-6",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsx("p",{className:"text-sm font-medium text-white/80",children:"Ticket summary"}),s.jsxs("ul",{className:"space-y-1.5 text-sm",children:[s.jsxs("li",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"size-1.5 rounded-full bg-white/70"}),s.jsxs("span",{className:"text-white/90",children:[g," total"]})]}),s.jsxs("li",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"size-1.5 rounded-full bg-white/70"}),s.jsxs("span",{className:"text-white/90",children:[p," closed"]})]}),s.jsxs("li",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"size-1.5 rounded-full bg-white/70"}),s.jsxs("span",{className:"text-white/90",children:[m," open"]})]})]})]}),s.jsx(Iz,{percent:l,size:120})]})})]}),s.jsxs("section",{className:"space-y-4",children:[s.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[s.jsx("h2",{className:"text-xl font-bold tracking-tight",children:"Module overview"}),s.jsx(DS,{value:o,onValueChange:b=>c(b),children:s.jsxs(xx,{className:"h-auto flex-wrap rounded-xl bg-secondary/60 p-1",children:[s.jsx(Ys,{value:"all",className:"rounded-lg text-xs data-[state=active]:bg-background data-[state=active]:shadow-sm",children:"All"}),s.jsx(Ys,{value:"open",className:"rounded-lg text-xs data-[state=active]:bg-background",children:"Open"}),s.jsx(Ys,{value:"closed",className:"rounded-lg text-xs data-[state=active]:bg-background",children:"Closed"}),YM.filter(b=>b.id!=="all").map(b=>s.jsx(Ys,{value:b.id,className:"rounded-lg text-xs data-[state=active]:bg-background",children:b.label},b.id))]})})]}),s.jsx("div",{className:"-mx-1 flex gap-4 overflow-x-auto px-1 pb-2 lg:grid lg:grid-cols-3 lg:overflow-visible",children:(o==="open"?[{id:"open-queue",title:"Open ticket queue",subtitle:`${m} waiting`,icon:is,href:"/tickets",status:"done",meta:"View live tickets"}]:o==="closed"?[{id:"closed-archive",title:"Closed tickets",subtitle:`${p} resolved`,icon:jd,href:"/transcripts",status:"done",meta:"Browse archive"}]:d.map(b=>{const v=Kh(b.id,t.modules,b.description);return{id:b.id,title:b.title,subtitle:v.subtitle,icon:b.icon,href:b.href,status:v.status,meta:v.status==="done"?"View settings":"Configure"}})).map(b=>s.jsx(Bz,{title:b.title,subtitle:b.subtitle,icon:b.icon,href:b.href,status:b.status,meta:b.meta},b.id))})]}),s.jsxs("section",{className:"space-y-4",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("h2",{className:"text-xl font-bold tracking-tight",children:"Active modules"}),s.jsx(en,{to:"/configs",className:"text-sm font-medium text-primary hover:underline",children:"See all"})]}),s.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:ai.slice(0,4).map(b=>{const v=Kh(b.id,t.modules);return s.jsx(Pz,{title:b.title,icon:b.icon,href:b.href,badge:c5[v.status],status:v.status},b.id)})})]})]}),s.jsx($z,{stats:t})]})}function Vz(){const{permissions:t}=Yt();return Rn(t,"overview")?s.jsx(Gz,{}):s.jsx(ya,{to:mg(t),replace:!0})}function ga({permission:t,children:n}){const{loading:a,isAuthenticated:o,permissions:c}=Yt();return a?s.jsx("div",{className:"flex flex-1 items-center justify-center py-16 text-sm text-muted-foreground",children:"Loading…"}):o?Rn(c,t)?s.jsx(s.Fragment,{children:n}):s.jsx(ya,{to:mg(c),replace:!0}):s.jsx(ya,{to:"/login",replace:!0})}function Fz(){const{hasPermission:t}=Yt(),n=t("settings.update"),a=ao(),[o,c]=f.useState([]),[l,d]=f.useState(""),[m,p]=f.useState(!0),[g,b]=f.useState(""),[v,w]=f.useState(""),[y,C]=f.useState(null),S=f.useCallback(async()=>{p(!0),b("");try{const E=await Ne.getAddonsCatalog();E.data&&(c(E.data.addons),d(E.data.repository))}catch(E){b(E instanceof Error?E.message:"Failed to load addons")}finally{p(!1)}},[]);f.useEffect(()=>{S()},[S]);async function N(E){if(n){C(E.id),w(""),b("");try{const T=await Ne.installAddon(E.id);w(T.message||`${E.name} installed.`),await S();const M=E.configFiles[0];M&&a(`/configs?file=${_l(M)}`)}catch(T){b(T instanceof Error?T.message:"Install failed")}finally{C(null)}}}return s.jsxs("div",{className:"space-y-6",children:[s.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[s.jsxs("div",{children:[s.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:"Addons"}),s.jsxs("p",{className:"text-muted-foreground",children:["Requires an API key from"," ",s.jsx("a",{href:"https://emeraldsrv.dev",target:"_blank",rel:"noreferrer",className:"text-primary underline-offset-4 hover:underline",children:"emeraldsrv.dev"})," ","to browse and install addons. Configs will appear in the sidebar once installed."]})]}),s.jsxs(ue,{variant:"outline",size:"sm",onClick:S,disabled:m,children:[s.jsx(xe,{icon:_2,size:16,className:pe("mr-1.5",m&&"animate-spin")}),"Refresh"]})]}),g?s.jsx(Ye,{variant:"destructive",children:s.jsx(qe,{children:g})}):null,v?s.jsx(Ye,{className:"border-primary/30 bg-primary/10 text-primary",children:s.jsx(qe,{children:v})}):null,s.jsxs("section",{className:"space-y-4",children:[s.jsx("h2",{className:"text-sm font-semibold uppercase tracking-widest text-muted-foreground",children:"Marketplace"}),m?s.jsxs("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3",children:[s.jsx(Ue,{className:"h-40 rounded-xl"}),s.jsx(Ue,{className:"h-40 rounded-xl"}),s.jsx(Ue,{className:"h-40 rounded-xl"})]}):s.jsx("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3",children:o.map(E=>s.jsxs(Je,{className:"border-border bg-card",children:[s.jsxs(dt,{className:"pb-2",children:[s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs(ft,{className:"flex items-center gap-2 text-lg",children:[s.jsx(xe,{icon:dg,size:20,className:"text-primary"}),E.name]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx(Fn,{variant:"outline",className:"shrink-0 uppercase tracking-widest text-[10px]",children:E.price===0||!E.price?"Free":`$${E.price}`}),E.installed?s.jsxs(Fn,{variant:"secondary",className:"shrink-0 gap-1",children:[s.jsx(xe,{icon:D8,size:14}),"Installed"]}):null]})]}),s.jsx(Ot,{children:E.description})]}),s.jsxs(et,{className:"space-y-2 text-xs text-muted-foreground",children:[E.is_external?s.jsxs("p",{children:["Available on: ",s.jsx("span",{className:"font-medium text-foreground",children:E.external_store||"External Store"})]}):null,E.configFiles&&E.configFiles.length>0?s.jsxs("p",{children:["Config:"," ",E.configFiles.map((T,M)=>s.jsxs("span",{children:[M>0?", ":null,s.jsx(en,{to:`/configs?file=${_l(T)}`,className:"font-mono text-primary hover:underline",children:T})]},T))]}):null]}),s.jsxs(Sx,{className:"flex flex-wrap gap-2",children:[E.is_external?s.jsx(ue,{variant:"outline",size:"sm",asChild:!0,children:s.jsx("a",{href:E.repositoryUrl,target:"_blank",rel:"noreferrer",children:"View Store"})}):null,E.installed&&E.configFiles&&E.configFiles[0]?s.jsx(ue,{size:"sm",variant:"secondary",asChild:!0,children:s.jsx(en,{to:`/configs?file=${_l(E.configFiles[0])}`,children:"Edit config"})}):null,E.installed?s.jsx(ue,{size:"sm",disabled:!0,variant:"secondary",children:"Installed"}):E.is_external?null:s.jsxs(ue,{size:"sm",disabled:!n||y===E.id,onClick:()=>N(E),children:[s.jsx(xe,{icon:Cd,size:14,className:"mr-1"}),y===E.id?"Installing…":"Install"]})]})]},E.id))})]})]})}function Yz(){const{permissions:t}=Yt(),[n,a]=f.useState(!1),[o,c]=f.useState(!1),[l,d]=f.useState(""),[m,p]=f.useState(""),[g,b]=f.useState(""),[v,w]=f.useState("Administrator"),[y,C]=f.useState(""),[S,N]=f.useState(""),[E,T]=f.useState("General"),M=z2(t,"supportbot"),k=async()=>{if(!m.match(/^[a-z0-9_-]+$/i)){Dt.error("Command name can only contain letters, numbers, underscores and dashes.");return}a(!0),c(!1);try{const _=await Ne.buildAddon({name:m.toLowerCase(),description:g||"A custom command",permission:v,embed:{title:y,description:S||"Hello from your custom command!",color:E}});c(!0),d(_.message||"Restart required."),Dt.success(`Addon ${m}.js created successfully!`)}catch(_){Dt.error(_ instanceof Error?_.message:"Failed to build addon")}finally{a(!1)}};return M?s.jsxs("div",{className:"space-y-6",children:[s.jsxs("div",{children:[s.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:"Addon Builder"}),s.jsx("p",{className:"text-muted-foreground",children:"Visually scaffold a custom slash command addon for your bot."})]}),o?s.jsxs(Ye,{className:"border-green-500/20 bg-green-500/10 text-green-600 dark:text-green-400",children:[s.jsx(x0,{className:"h-4 w-4"}),s.jsxs(qe,{className:"ml-2",children:["Successfully built ",s.jsxs("strong",{children:[m,".js"]}),"! ",l]})]}):null,s.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[s.jsxs("div",{className:"space-y-6",children:[s.jsxs(Je,{children:[s.jsxs(dt,{children:[s.jsx(ft,{className:"text-lg",children:"Command Details"}),s.jsx(Ot,{children:"Configure how users trigger the command."})]}),s.jsxs(et,{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{children:"Command Name"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-muted-foreground",children:"/"}),s.jsx(_e,{placeholder:"ping",value:m,onChange:_=>p(_.target.value.replace(/[^a-z0-9_-]/gi,"").toLowerCase())})]})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{children:"Description"}),s.jsx(_e,{placeholder:"Replies with a custom embed",value:g,onChange:_=>b(_.target.value)})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{children:"Required Permission"}),s.jsxs(Ca,{value:v,onValueChange:w,children:[s.jsx(Hr,{children:s.jsx(Sa,{})}),s.jsxs(Gr,{children:[s.jsx(Et,{value:"none",children:"@everyone"}),s.jsx(Et,{value:"Administrator",children:"Administrator"}),s.jsx(Et,{value:"ManageMessages",children:"Manage Messages"}),s.jsx(Et,{value:"ManageGuild",children:"Manage Server"})]})]})]})]})]}),s.jsxs(Je,{children:[s.jsxs(dt,{children:[s.jsx(ft,{className:"text-lg",children:"Response Embed"}),s.jsx(Ot,{children:"What the bot will reply with."})]}),s.jsxs(et,{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{children:"Embed Title (Optional)"}),s.jsx(_e,{placeholder:"Hello!",value:y,onChange:_=>C(_.target.value)})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{children:"Embed Description"}),s.jsx(Jd,{placeholder:"Type your message here...",className:"resize-none",rows:4,value:S,onChange:_=>N(_.target.value)})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{children:"Embed Color"}),s.jsxs(Ca,{value:E,onValueChange:T,children:[s.jsx(Hr,{children:s.jsx(Sa,{})}),s.jsxs(Gr,{children:[s.jsx(Et,{value:"General",children:"Theme General"}),s.jsx(Et,{value:"Success",children:"Theme Success"}),s.jsx(Et,{value:"Warning",children:"Theme Warning"}),s.jsx(Et,{value:"Error",children:"Theme Error"})]})]})]})]})]})]}),s.jsx("div",{className:"space-y-6",children:s.jsxs(Je,{className:"sticky top-6 border-primary/20",children:[s.jsx(dt,{children:s.jsxs(ft,{className:"text-sm font-medium flex items-center gap-2",children:[s.jsx(xe,{icon:A8,size:16,className:"text-primary"}),"Live Preview"]})}),s.jsx(et,{children:s.jsx("div",{className:"rounded-md border bg-[#313338] p-4 font-sans text-sm text-[#dbdee1]",children:s.jsxs("div",{className:"flex gap-4",children:[s.jsx("div",{className:"size-10 shrink-0 rounded-full bg-indigo-500 flex items-center justify-center font-bold text-white",children:"B"}),s.jsxs("div",{className:"flex-1 space-y-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"font-medium text-white",children:"SupportBot"}),s.jsxs("span",{className:"text-[10px] text-white font-medium uppercase px-1.5 py-0.5 rounded bg-[#5865F2] flex items-center gap-1",children:[s.jsx(x0,{size:10})," BOT"]}),s.jsx("span",{className:"text-xs text-[#949ba4]",children:"Today at 12:00 PM"})]}),s.jsxs("div",{className:"mt-2 rounded bg-[#2b2d31] border-l-4 border-l-[#5865F2] px-4 py-3 max-w-[432px]",children:[y&&s.jsx("div",{className:"mb-1 font-semibold text-white",children:y}),s.jsx("div",{className:"whitespace-pre-wrap",children:S||"Hello from your custom command!"})]})]})]})})}),s.jsx(Sx,{children:s.jsxs(ue,{className:"w-full gap-2",size:"lg",disabled:!m||n,onClick:k,children:[s.jsx(xe,{icon:ds,size:18}),n?"Building...":"Generate Addon"]})})]})})]})]}):s.jsx("div",{className:"flex h-[50vh] items-center justify-center text-muted-foreground",children:"You don't have permission to build addons."})}const Ex="supportbot-dashboard-accent",Pl="#45b46c",qz=["--primary","--ring","--chart-1","--sidebar-primary","--sidebar-ring","--accent","--accent-foreground","--sidebar-accent","--sidebar-accent-foreground"];function Kz(t){const n=$r(t,Pl),a=parseInt(n.slice(1,3),16)/255,o=parseInt(n.slice(3,5),16)/255,c=parseInt(n.slice(5,7),16)/255,l=Math.max(a,o,c),d=Math.min(a,o,c),m=(l+d)/2;let p=0,g=0;if(l!==d){const b=l-d;switch(g=m>.5?b/(2-l-d):b/(l+d),l){case a:p=((o-c)/b+(o{const o=new FileReader;o.onload=()=>n(String(o.result)),o.onerror=()=>a(new Error("Could not read file")),o.readAsDataURL(t)})}function Jz({canEdit:t}){const[n,a]=f.useState(!1),[o,c]=f.useState(""),[l,d]=f.useState(!1);async function m(){if(t){a(!0),c("");try{const p=await Ne.resetDashboard();c(p.message||"Dashboard reset successfully."),setTimeout(()=>{window.location.href="/setup"},1500)}catch(p){c(p instanceof Error?p.message:"Reset failed"),a(!1)}}}return t?s.jsxs("div",{className:"space-y-4",children:[s.jsx("p",{className:"text-sm text-muted-foreground",children:"Reset the dashboard to factory settings. This clears the configuration and returns you to the initial setup screen."}),s.jsxs(Qs,{open:l,onOpenChange:d,children:[s.jsx(TM,{asChild:!0,children:s.jsx(ue,{type:"button",variant:"destructive",children:"Reset Dashboard"})}),s.jsxs(hs,{children:[s.jsxs(gs,{children:[s.jsx(xs,{children:"Are you absolutely sure?"}),s.jsx(bs,{children:"This action cannot be undone. This will reset the dashboard to setup mode. You will need to reconnect the Discord OAuth and reconfigure the dashboard owners."})]}),o&&s.jsx("p",{className:"text-sm font-medium text-destructive",children:o}),s.jsxs(Js,{children:[s.jsx(ue,{variant:"outline",onClick:()=>d(!1),disabled:n,children:"Cancel"}),s.jsx(ue,{variant:"destructive",onClick:()=>void m(),disabled:n,children:n?"Resetting...":"Yes, reset dashboard"})]})]})]})]}):null}function eP({canEdit:t}){const{branding:n,setBrandingLocal:a}=Ed(),o=f.useRef(null),[c,l]=f.useState(n.title),[d,m]=f.useState(n.pageTitle),[p,g]=f.useState(!1),[b,v]=f.useState(!1),[w,y]=f.useState("");f.useEffect(()=>{l(n.title),m(n.pageTitle)},[n.title,n.pageTitle]);const C=n.hasFavicon&&n.faviconUrl?`${n.faviconUrl}${n.updatedAt?`?v=${n.updatedAt}`:""}`:null;async function S(){if(t){g(!0),y("");try{const M=await Ne.updateBranding({title:c,pageTitle:d});M.data&&a(M.data),y(M.message||"Branding saved.")}catch(M){y(M instanceof Error?M.message:"Save failed")}finally{g(!1)}}}async function N(M){if(!(!t||!M)){v(!0),y("");try{const k=await Qz(M),_=await Ne.uploadBrandingFavicon(k);_.data&&a(_.data),y(_.message||"Favicon uploaded.")}catch(k){y(k instanceof Error?k.message:"Upload failed")}finally{v(!1),o.current&&(o.current.value="")}}}async function E(){if(t){v(!0),y("");try{const M=await Ne.removeBrandingFavicon();M.data&&a(M.data),y(M.message||"Favicon removed.")}catch(M){y(M instanceof Error?M.message:"Remove failed")}finally{v(!1)}}}const T=c.trim()!==n.title||d.trim()!==n.pageTitle;return s.jsxs("div",{className:"space-y-8",children:[s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm font-medium",children:"Branding Text"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"Sidebar title and browser tab title — saved on the server for everyone using this dashboard."})]}),s.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{htmlFor:"brand-title",children:"Sidebar title"}),s.jsx(_e,{id:"brand-title",value:c,disabled:!t,maxLength:64,onChange:M=>l(M.target.value),className:"border-border bg-secondary/30",placeholder:"SupportBot"})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{htmlFor:"brand-page-title",children:"Browser tab title"}),s.jsx(_e,{id:"brand-page-title",value:d,disabled:!t,maxLength:80,onChange:M=>m(M.target.value),className:"border-border bg-secondary/30",placeholder:"SupportBot Dashboard"})]})]}),t?s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ue,{type:"button",disabled:p||!T,onClick:()=>void S(),children:p?"Saving…":"Save titles"}),w&&T?s.jsx("span",{className:"text-xs text-muted-foreground",children:w}):null]}):null]}),s.jsxs("div",{className:"space-y-4 border-t border-border pt-6",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm font-medium",children:"Favicon"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"PNG, ICO, SVG, JPEG, or WebP — max 512 KB. Shown in the browser tab and beside the sidebar title."})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-4",children:[s.jsx("div",{className:"flex size-16 items-center justify-center overflow-hidden rounded-lg border border-border bg-secondary/30",children:C?s.jsx("img",{src:C,alt:"Favicon preview",className:"size-full object-contain p-2"}):s.jsx(xe,{icon:y8,size:24,className:"text-muted-foreground/50"})}),s.jsx("input",{ref:o,type:"file",accept:"image/png,image/jpeg,image/x-icon,image/vnd.microsoft.icon,image/svg+xml,image/webp,.ico",className:"hidden",disabled:!t||b,onChange:M=>{var k;return void N(((k=M.target.files)==null?void 0:k[0])??null)}}),s.jsxs("div",{className:"flex flex-col gap-2",children:[t?s.jsxs("div",{className:"flex gap-2",children:[s.jsx(ue,{type:"button",variant:"secondary",disabled:b,onClick:()=>{var M;return(M=o.current)==null?void 0:M.click()},children:b?"Uploading…":"Upload Favicon"}),n.hasFavicon?s.jsx(ue,{type:"button",variant:"destructive",disabled:b,onClick:()=>void E(),children:"Remove"}):null]}):s.jsx("span",{className:"text-xs text-muted-foreground",children:"View only"}),!T&&w?s.jsx("span",{className:"text-xs text-muted-foreground",children:w}):null]})]})]})]})}function tP(){var v,w,y,C,S,N,E,T,M,k,_;const{hasPermission:t}=Yt(),n=t("settings.update"),[a,o]=f.useState(!0),[c,l]=f.useState(!1),[d,m]=f.useState(""),[p,g]=f.useState(null);f.useEffect(()=>{Ne.getConfigJson("api").then(R=>{R.data&&g(R.data)}).catch(()=>m("Failed to load API config")).finally(()=>o(!1))},[]);async function b(){var R,L,ne,X,I,H,q,ce,de,se,P;if(!(!n||!p)){l(!0),m("");try{const W={"api:API.Port":(R=p.API)==null?void 0:R.Port,"api:API.EmeraldAPIKey":(L=p.API)==null?void 0:L.EmeraldAPIKey,"api:API.TrustProxy":(ne=p.API)==null?void 0:ne.TrustProxy,"api:API.OAuth.Enabled":(I=(X=p.API)==null?void 0:X.OAuth)==null?void 0:I.Enabled,"api:API.OAuth.ClientId":(q=(H=p.API)==null?void 0:H.OAuth)==null?void 0:q.ClientId,"api:API.OAuth.ClientSecret":(de=(ce=p.API)==null?void 0:ce.OAuth)==null?void 0:de.ClientSecret,"api:API.OAuth.RedirectUri":(P=(se=p.API)==null?void 0:se.OAuth)==null?void 0:P.RedirectUri};await Ne.updateConfigFields(W),m("API settings saved and backend restarted.")}catch(W){m(W instanceof Error?W.message:"Save failed")}finally{l(!1)}}}return a?s.jsx("div",{className:"animate-pulse h-32 bg-secondary/20 rounded-md"}):p?s.jsxs("div",{className:"space-y-8",children:[s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm font-medium",children:"Core API Settings"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"Configure the internal API that powers this dashboard."})]}),s.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{children:"API Port"}),s.jsx(_e,{type:"number",value:((v=p.API)==null?void 0:v.Port)||"",disabled:!n,onChange:R=>g({...p,API:{...p.API,Port:parseInt(R.target.value)||3e3}}),className:"border-border bg-secondary/30"})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{children:"Emerald API Key"}),s.jsx(_e,{type:"password",value:((w=p.API)==null?void 0:w.EmeraldAPIKey)||"",disabled:!n,onChange:R=>g({...p,API:{...p.API,EmeraldAPIKey:R.target.value}}),className:"border-border bg-secondary/30"})]})]}),s.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[s.jsx(Mt,{checked:((y=p.API)==null?void 0:y.TrustProxy)||!1,disabled:!n,onCheckedChange:R=>g({...p,API:{...p.API,TrustProxy:R}})}),s.jsx(Ae,{className:"text-sm",children:"Trust Proxy (Enable if using Cloudflare/Nginx)"})]})]}),s.jsxs("div",{className:"space-y-4 border-t border-border pt-6",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm font-medium",children:"OAuth Authentication"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"Discord application credentials for dashboard login."})]}),s.jsxs("div",{className:"flex items-center gap-2 pb-2",children:[s.jsx(Mt,{checked:((S=(C=p.API)==null?void 0:C.OAuth)==null?void 0:S.Enabled)||!1,disabled:!n,onCheckedChange:R=>{var L;return g({...p,API:{...p.API,OAuth:{...(L=p.API)==null?void 0:L.OAuth,Enabled:R}}})}}),s.jsx(Ae,{className:"text-sm",children:"Enable OAuth"})]}),s.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{children:"Client ID"}),s.jsx(_e,{value:((E=(N=p.API)==null?void 0:N.OAuth)==null?void 0:E.ClientId)||"",disabled:!n,onChange:R=>{var L;return g({...p,API:{...p.API,OAuth:{...(L=p.API)==null?void 0:L.OAuth,ClientId:R.target.value}}})},className:"border-border bg-secondary/30"})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{children:"Client Secret"}),s.jsx(_e,{type:"password",value:((M=(T=p.API)==null?void 0:T.OAuth)==null?void 0:M.ClientSecret)||"",disabled:!n,onChange:R=>{var L;return g({...p,API:{...p.API,OAuth:{...(L=p.API)==null?void 0:L.OAuth,ClientSecret:R.target.value}}})},className:"border-border bg-secondary/30"})]}),s.jsxs("div",{className:"space-y-2 sm:col-span-2",children:[s.jsx(Ae,{children:"Redirect URI"}),s.jsx(_e,{value:((_=(k=p.API)==null?void 0:k.OAuth)==null?void 0:_.RedirectUri)||"",disabled:!n,onChange:R=>{var L;return g({...p,API:{...p.API,OAuth:{...(L=p.API)==null?void 0:L.OAuth,RedirectUri:R.target.value}}})},className:"border-border bg-secondary/30"}),s.jsx("p",{className:"text-[10px] text-muted-foreground mt-1",children:"Must match the OAuth2 callback URL registered in the Discord Developer Portal exactly."})]})]})]}),n?s.jsxs("div",{className:"flex items-center gap-2 border-t border-border pt-6",children:[s.jsx(ue,{type:"button",disabled:c,onClick:()=>void b(),children:c?"Saving…":"Save API Config"}),d?s.jsx("span",{className:"text-xs text-muted-foreground",children:d}):null]}):null]}):null}function nP(){const{hasPermission:t}=Yt(),n=t("settings.update"),[a,o]=f.useState(null),[c,l]=f.useState(!0),[d,m]=f.useState(!1),[p,g]=f.useState(""),[b,v]=f.useState(""),[w,y]=f.useState(()=>d5()??Pl),[C,S]=f.useState(""),[N,E]=f.useState("appearance"),T=f.useCallback(async()=>{l(!0),g("");try{const k=await Ne.checkForUpdates();k.data&&o(k.data)}catch(k){g(k instanceof Error?k.message:"Could not check for updates")}finally{l(!1)}},[]);f.useEffect(()=>{T()},[T]);async function M(k){if(k.updateAvailable){m(!0),g(""),v("");try{const _=await Ne.runUpdate(k.id,k.latest,k.zipUrl);v(_.message||"Update installed. Restart your server (stop and run npm start again) to finish applying changes."),await T()}catch(_){g(_ instanceof Error?_.message:"Update failed")}finally{m(!1)}}}return s.jsxs("div",{className:"space-y-6",children:[s.jsxs("div",{children:[s.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:"Settings"}),s.jsx("p",{className:"text-muted-foreground",children:"Application updates and maintenance — config files are edited under each module in the sidebar."})]}),s.jsxs("div",{className:"flex flex-col md:flex-row gap-8 items-start",children:[s.jsx("aside",{className:"w-full md:w-56 shrink-0 sticky top-6",children:s.jsxs("nav",{className:"flex flex-row md:flex-col overflow-x-auto space-x-2 md:space-x-0 md:space-y-1 pb-2 md:pb-0",children:[s.jsx(ue,{variant:N==="appearance"?"secondary":"ghost",className:"justify-start w-full",onClick:()=>E("appearance"),children:"Appearance"}),s.jsx(ue,{variant:N==="api"?"secondary":"ghost",className:"justify-start w-full",onClick:()=>E("api"),children:"API Config"}),s.jsx(ue,{variant:N==="updates"?"secondary":"ghost",className:"justify-start w-full",onClick:()=>E("updates"),children:"Update Checker"}),n&&s.jsx(ue,{variant:"ghost",className:`justify-start w-full text-destructive hover:bg-destructive/10 hover:text-destructive ${N==="danger"?"bg-destructive/10 border-l-2 border-destructive rounded-l-none":""}`,onClick:()=>E("danger"),children:"Danger Zone"})]})}),s.jsxs("main",{className:"flex-1 w-full max-w-4xl space-y-6",children:[N==="appearance"&&s.jsx("div",{className:"space-y-6",children:s.jsxs(Je,{className:"border-border bg-card",children:[s.jsxs(dt,{children:[s.jsx(ft,{className:"text-lg",children:"Dashboard appearance"}),s.jsx(Ot,{children:"Customise branding for all users, and pick an accent colour for this browser only."})]}),s.jsxs(et,{className:"space-y-4",children:[s.jsx(eP,{canEdit:n}),s.jsxs("div",{className:"border-t border-border pt-4",children:[s.jsx("p",{className:"mb-1 text-sm font-medium",children:"Accent colour"}),s.jsx("p",{className:"mb-4 text-xs text-muted-foreground",children:"Buttons, links, and highlights — saved in this browser only."}),s.jsxs("div",{className:"flex flex-wrap items-center gap-4",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(tf,{value:w,onChange:k=>{y(k),n2(k),S("Accent updated.")}}),s.jsx(_e,{id:"accent-colour",value:w,onChange:k=>y(k.target.value),onBlur:()=>{const k=$r(w,Pl);y(k),n2(k),S("Accent updated.")},className:"w-32 border-border bg-secondary/30 font-mono uppercase",maxLength:7})]}),s.jsx(ue,{type:"button",variant:"outline",onClick:()=>{Xz(),y(Pl),S("Reset to default purple.")},children:"Reset to default"})]}),s.jsxs("div",{className:"flex flex-wrap gap-2 text-sm mt-5",children:[s.jsx("span",{className:"rounded-md bg-primary px-3 py-1.5 font-medium text-primary-foreground",children:"Primary button"}),s.jsx("span",{className:"rounded-md bg-primary/15 px-3 py-1.5 text-primary",children:"Highlight"}),s.jsx("span",{className:"rounded-md bg-accent px-3 py-1.5 text-accent-foreground",children:"Accent surface"})]}),C?s.jsx("p",{className:"text-xs text-muted-foreground",children:C}):null]})]})]})}),N==="danger"&&n&&s.jsxs(Je,{className:"border-destructive/50 bg-destructive/5",children:[s.jsxs(dt,{children:[s.jsx(ft,{className:"text-lg text-destructive",children:"Danger Zone"}),s.jsx(Ot,{className:"text-destructive/80",children:"Destructive actions that reset or permanently alter your dashboard."})]}),s.jsx(et,{children:s.jsx(Jz,{canEdit:n})})]}),N==="api"&&s.jsxs(Je,{className:"border-border bg-card",children:[s.jsxs(dt,{children:[s.jsx(ft,{className:"text-lg",children:"API Configuration"}),s.jsx(Ot,{children:"Configure the internal API settings, Emerald API key, and OAuth."})]}),s.jsx(et,{children:s.jsx(tP,{})})]}),N==="updates"&&s.jsxs(Je,{className:"border-border bg-card",children:[s.jsxs(dt,{children:[s.jsx(ft,{className:"text-lg",children:"Software updates"}),s.jsx(Ot,{children:"Manage updates for the bot and dashboard."})]}),s.jsxs(et,{className:"space-y-4",children:[c?s.jsx(Ue,{className:"h-24 w-full"}):a&&a.length>0?s.jsx("div",{className:"space-y-4",children:a.map(k=>s.jsxs("div",{className:"space-y-3 rounded-lg border border-border bg-secondary/20 p-4",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("p",{className:"font-medium text-sm",children:[s.jsx("a",{href:k.repository,target:"_blank",rel:"noreferrer",className:"text-primary underline-offset-4 hover:underline",children:k.name})," ","(",k.branch," branch)"]}),s.jsxs("div",{className:"flex gap-x-4 text-sm",children:[s.jsxs("p",{children:[s.jsx("span",{className:"text-muted-foreground",children:"Installed: "}),s.jsxs("span",{className:"font-mono font-medium",children:["v",k.current]})]}),s.jsxs("p",{children:[s.jsx("span",{className:"text-muted-foreground",children:"Latest: "}),s.jsxs("span",{className:"font-mono font-medium",children:["v",k.latest]})]})]})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[k.updateAvailable?s.jsx("p",{className:"text-sm text-amber-500",children:"A newer version is available. Update downloads files while keeping your Configs and Data."}):s.jsx("p",{className:"text-sm text-emerald-500",children:"You are on the latest release."}),k.updateAvailable&&n?s.jsxs(ue,{type:"button",size:"sm",onClick:()=>void M(k),disabled:d,children:[d?s.jsx(xe,{icon:_2,size:16,className:"mr-2 animate-spin"}):s.jsx(xe,{icon:Cd,size:16,className:"mr-2"}),d?"Installing…":"Update now"]}):null,k.updateAvailable&&!n?s.jsx("p",{className:"text-xs text-muted-foreground",children:"You cannot install updates with your role."}):null]})]},k.id))}):null,p?s.jsx(Ye,{variant:"destructive",children:s.jsx(qe,{children:p})}):null,b?s.jsx(Ye,{children:s.jsx(qe,{children:b})}):null,s.jsx("div",{className:"flex flex-wrap gap-2 pt-2",children:s.jsxs(ue,{type:"button",variant:"outline",onClick:T,disabled:c||d,children:[s.jsx(xe,{icon:fr,size:16,className:"mr-2"}),"Check again"]})})]})]})]})]})]})}function kx(t){const[n,a]=f.useState(!1),o=f.useRef(t);return o.current=t,f.useEffect(()=>{let c=null,l=null;const d=()=>{c=new EventSource("/api/stream"),c.onopen=()=>{a(!0)},c.addEventListener("connected",()=>{a(!0)}),c.addEventListener("metrics",m=>{var p,g;try{const b=JSON.parse(m.data);(g=(p=o.current).onMetrics)==null||g.call(p,b)}catch{}}),c.addEventListener("log",m=>{var p,g;try{const b=JSON.parse(m.data);(g=(p=o.current).onLog)==null||g.call(p,b)}catch{}}),c.addEventListener("ticket_message",m=>{var p,g;try{const b=JSON.parse(m.data);(g=(p=o.current).onTicketMessage)==null||g.call(p,b)}catch{}}),c.addEventListener("ticket_message_deleted",m=>{var p,g;try{const b=JSON.parse(m.data);(g=(p=o.current).onTicketMessageDeleted)==null||g.call(p,b)}catch{}}),c.addEventListener("ticket_message_updated",m=>{var p,g;try{const b=JSON.parse(m.data);(g=(p=o.current).onTicketMessageUpdated)==null||g.call(p,b)}catch{}}),c.addEventListener("ticket_created",m=>{var p,g;try{const b=JSON.parse(m.data);(g=(p=o.current).onTicketCreated)==null||g.call(p,b)}catch{}}),c.addEventListener("ticket_closed",m=>{var p,g;try{const b=JSON.parse(m.data);(g=(p=o.current).onTicketClosed)==null||g.call(p,b)}catch{}}),c.onerror=()=>{a(!1),c==null||c.close(),l=window.setTimeout(d,4e3)}};return d(),()=>{l&&window.clearTimeout(l),c&&c.close()}},[]),{connected:n}}function Tt({label:t,value:n,mono:a=!1}){return s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border py-3 last:border-0 sm:flex-row sm:items-center sm:justify-between",children:[s.jsx("dt",{className:"text-sm text-muted-foreground",children:t}),s.jsx("dd",{className:`text-sm font-medium text-foreground ${a?"font-mono text-xs sm:text-sm":""}`,children:n})]})}const rP={ok:"Healthy",missing_config:"Guild ID not set",not_in_guild:"Not in configured server",extra_guilds:"Extra servers joined",offline:"Bot offline"};function aP(t){return t==="ok"?"text-emerald-500":t==="offline"?"text-destructive":"text-amber-500"}function sP(){var N;const{stats:t,loading:n,error:a,refresh:o}=kd(),[c,l]=f.useState(null),[d,m]=f.useState(null),[p,g]=f.useState(!1),[b,v]=f.useState(null),{connected:w}=kx({onMetrics:E=>{v(E)}}),y=f.useCallback(async()=>{const[E,T]=await Promise.all([Ne.getGuildStatus().catch(()=>null),Ne.health().catch(()=>null)]);E!=null&&E.data&&l(E.data),T!=null&&T.success&&T.data&&m({dashboard:T.data.dashboard,botReady:T.data.botReady,oauthEnabled:T.data.oauthEnabled,setupComplete:T.data.setupComplete})},[]);f.useEffect(()=>{y()},[y]);async function C(){g(!0);try{await Promise.all([o(),y()])}finally{g(!1)}}if(n&&!t)return s.jsxs("div",{className:"space-y-6",children:[s.jsx(Ue,{className:"h-10 w-64"}),s.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[s.jsx(Ue,{className:"h-56 rounded-2xl"}),s.jsx(Ue,{className:"h-56 rounded-2xl"})]})]});if(a||!t)return s.jsx(Ye,{variant:"destructive",children:s.jsx(qe,{children:a||"Could not load system details."})});const S=t.bot.ping<200;return s.jsxs("div",{className:"space-y-6",children:[s.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx(ue,{asChild:!0,variant:"ghost",size:"sm",className:"-ml-2 h-8 px-2 text-muted-foreground",children:s.jsxs(en,{to:"/",children:[s.jsx(xe,{icon:T2,size:16,className:"mr-1.5"}),"Back to dashboard"]})}),s.jsxs("div",{children:[s.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:"System details"}),s.jsx("p",{className:"text-muted-foreground",children:"Live bot, host, and dashboard status — refreshed every 30 seconds."})]})]}),s.jsxs(ue,{type:"button",variant:"outline",disabled:p,onClick:()=>void C(),children:[s.jsx(xe,{icon:fr,size:16,className:"mr-2"}),p?"Refreshing…":"Refresh now"]})]}),s.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[s.jsxs(Je,{className:"border-border bg-card",children:[s.jsxs(dt,{children:[s.jsx(ft,{className:"text-lg",children:"Discord bot"}),s.jsx(Ot,{children:"Connection and identity"})]}),s.jsxs(et,{children:[s.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[s.jsxs(vs,{className:"size-12",children:[s.jsx(eo,{src:t.bot.avatar,alt:t.bot.username}),s.jsx(ys,{children:"SB"})]}),s.jsxs("div",{children:[s.jsx("p",{className:"font-semibold",children:t.bot.username}),s.jsx("p",{className:"font-mono text-xs text-muted-foreground",children:t.bot.id})]})]}),s.jsxs("dl",{children:[s.jsx(Tt,{label:"Version",value:`v${t.bot.version}`,mono:!0}),s.jsx(Tt,{label:"Gateway latency",value:s.jsxs("span",{className:S?"text-emerald-500":"text-amber-500",children:[t.bot.ping," ms"]})}),s.jsx(Tt,{label:"Process uptime",value:fg(t.bot.uptime)}),s.jsx(Tt,{label:"Connected servers",value:t.servers.toLocaleString()}),s.jsx(Tt,{label:"Members tracked",value:t.users.toLocaleString()}),t.bot.inviteUrl?s.jsx(Tt,{label:"Invite link",value:s.jsx("a",{href:t.bot.inviteUrl,target:"_blank",rel:"noreferrer",className:"text-primary underline-offset-4 hover:underline",children:"Open in Discord"})}):null]})]})]}),s.jsxs(Je,{className:"border-border bg-card",children:[s.jsxs(dt,{className:"flex flex-row items-center justify-between",children:[s.jsxs("div",{children:[s.jsx(ft,{className:"text-lg",children:"Host machine"}),s.jsx(Ot,{children:"Server resources running this instance"})]}),s.jsxs(Fn,{variant:w?"default":"outline",className:"text-xs",children:[s.jsx("span",{className:`mr-1.5 inline-block h-2 w-2 rounded-full ${w?"bg-emerald-500 animate-pulse":"bg-muted"}`}),w?"Live Stream":"Polling"]})]}),s.jsx(et,{children:s.jsxs("dl",{children:[s.jsx(Tt,{label:"Memory used",value:b?`${(b.ram_used_mb/1024).toFixed(2)} GB / ${(b.ram_total_mb/1024).toFixed(2)} GB`:`${t.hosting.ram_used} / ${t.hosting.ram_total}`}),s.jsx(Tt,{label:"Memory usage",value:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("span",{className:(b?b.ram_percent:t.hosting.ram_percent)>85?"text-amber-500 font-bold":"text-foreground font-medium",children:[b?b.ram_percent:t.hosting.ram_percent,"%"]}),s.jsx("div",{className:"w-24 h-2 bg-secondary rounded-full overflow-hidden",children:s.jsx("div",{className:"h-full bg-primary transition-all duration-500",style:{width:`${b?b.ram_percent:t.hosting.ram_percent}%`}})})]})}),s.jsx(Tt,{label:"CPU load (1 min avg)",value:b?String(b.cpu_load):t.hosting.cpu_load,mono:!0}),s.jsx(Tt,{label:"Host uptime",value:t.hosting.uptime})]})})]}),s.jsxs(Je,{className:"border-border bg-card",children:[s.jsxs(dt,{children:[s.jsx(ft,{className:"text-lg",children:"Tickets"}),s.jsx(Ot,{children:"Database snapshot"})]}),s.jsx(et,{children:s.jsxs("dl",{children:[s.jsx(Tt,{label:"Total tickets",value:t.tickets.total}),s.jsx(Tt,{label:"Open",value:s.jsx("span",{className:"text-primary",children:t.tickets.open})}),s.jsx(Tt,{label:"Closed",value:t.tickets.closed}),s.jsx(Tt,{label:"Transcripts",value:s.jsx(en,{to:"/transcripts",className:"text-primary underline-offset-4 hover:underline",children:"Browse archive"})})]})})]}),s.jsxs(Je,{className:"border-border bg-card",children:[s.jsxs(dt,{children:[s.jsx(ft,{className:"text-lg",children:"Guild health"}),s.jsx(Ot,{children:"Configured server and membership"})]}),s.jsx(et,{children:c?s.jsxs("dl",{children:[s.jsx(Tt,{label:"Status",value:s.jsx("span",{className:aP(c.status),children:rP[c.status]})}),s.jsx(Tt,{label:"Configured guild ID",value:c.configuredGuildId||"Not set",mono:!0}),c.configuredGuild?s.jsx(Tt,{label:"Configured server",value:`${c.configuredGuild.name} (${((N=c.configuredGuild.memberCount)==null?void 0:N.toLocaleString())??"?"} members)`}):null,c.message?s.jsx("div",{className:"mt-3 rounded-lg border border-border bg-secondary/30 px-3 py-2 text-sm text-muted-foreground",children:c.message}):null,c.extraGuilds.length>0?s.jsxs("div",{className:"mt-3 space-y-2",children:[s.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"Extra servers"}),s.jsx("ul",{className:"space-y-1 text-sm",children:c.extraGuilds.map(E=>s.jsxs("li",{className:"font-mono text-xs",children:[E.name," · ",E.id]},E.id))})]}):null]}):s.jsx(Ue,{className:"h-24 w-full"})})]})]}),s.jsxs(Je,{className:"border-border bg-card",children:[s.jsxs(dt,{children:[s.jsx(ft,{className:"text-lg",children:"Dashboard services"}),s.jsx(Ot,{children:"API and authentication"})]}),s.jsx(et,{children:d?s.jsxs("dl",{className:"max-w-xl",children:[s.jsx(Tt,{label:"Dashboard UI",value:d.dashboard?"Available":"Missing build"}),s.jsx(Tt,{label:"Bot connection",value:d.botReady?"Online":"Starting or offline"}),s.jsx(Tt,{label:"Discord OAuth",value:d.oauthEnabled?"Configured":"Not configured"}),s.jsx(Tt,{label:"Initial setup",value:d.setupComplete?"Complete":"Incomplete"}),s.jsx(Tt,{label:"Software updates",value:s.jsx(en,{to:"/settings",className:"text-primary underline-offset-4 hover:underline",children:"Open settings"})}),s.jsx(Tt,{label:"Logs",value:s.jsx(en,{to:"/logs",className:"text-primary underline-offset-4 hover:underline",children:"View log files"})})]}):s.jsx(Ue,{className:"h-32 w-full max-w-xl"})})]}),t.modules?s.jsxs(Je,{className:"border-border bg-card",children:[s.jsxs(dt,{children:[s.jsx(ft,{className:"text-lg",children:"Module setup status"}),s.jsx(Ot,{children:"Which features are configured and active"})]}),s.jsx(et,{children:s.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:ai.map(E=>{const T=Kh(E.id,t.modules);return s.jsxs(en,{to:E.href,className:"flex items-start justify-between gap-3 rounded-xl border border-border bg-secondary/20 px-4 py-3 transition-colors hover:bg-secondary/40",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"text-sm font-medium",children:E.title}),s.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:T.subtitle})]}),s.jsx("span",{className:"shrink-0 rounded-full bg-secondary px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:c5[T.status]})]},E.id)})})})]}):null]})}function oP(t){if(!t)return"—";const n=new Date(t);return Number.isNaN(n.getTime())?t:n.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",second:"2-digit"})}const iP=[{id:"all",label:"All"},{id:"Output",label:"Output"},{id:"Warn",label:"Warn"},{id:"Error",label:"Error"}],lP=["Output","Warn","Error"],cP={Output:"text-foreground/90",Warn:"text-amber-400",Error:"text-rose-400"},uP={Output:"bg-muted text-muted-foreground",Warn:"bg-amber-500/15 text-amber-400",Error:"bg-rose-500/15 text-rose-400"},gd=2e3,dP=2e3;function Wh(t,n){return`${t.type}-${t.timestamp??"na"}-${n}-${t.message.slice(0,32)}`}function fP(t,n,a){const o=a?[]:t,c=new Set(o.map((m,p)=>Wh(m,p))),l=[];for(let m=0;mgd?d.slice(d.length-gd):d}function mP(){const[t,n]=f.useState([]),[a,o]=f.useState(!0),[c,l]=f.useState(""),[d,m]=f.useState(!1),[p,g]=f.useState(!0),[b,v]=f.useState("all"),[w,y]=f.useState(""),[C,S]=f.useState(!0),[N,E]=f.useState(""),T=f.useRef(null),M=f.useRef(null),k=f.useRef(d);k.current=d;const _=f.useMemo(()=>b==="all"?lP:[b],[b]),R=f.useCallback(I=>{k.current||b!=="all"&&I.type!==b||(n(H=>{const q=[...H,I];return q.length>gd?q.slice(q.length-gd):q}),S(!0))},[b]);kx({onLog:R});const L=f.useCallback(async I=>{var ce,de;const H=await Ne.getLogs({types:_,cursor:I?void 0:T.current??void 0,tail:I?500:0}),q=((ce=H.data)==null?void 0:ce.entries)??[];return T.current=((de=H.data)==null?void 0:de.cursor)??{},n(se=>fP(se,q,I)),q.length},[_]),ne=f.useCallback(async()=>{var I;o(!0),l(""),T.current=null;try{const ce=(((I=(await Ne.getLogsMeta()).data)==null?void 0:I.files)??[]).filter(de=>de.file).map(de=>`${de.type}: ${de.file}`).join(" · ");E(ce||"No log files yet — output appears when the bot runs."),await L(!0),S(!0)}catch(H){l(H instanceof Error?H.message:"Failed to load logs"),S(!1)}finally{o(!1)}},[L]);f.useEffect(()=>{ne()},[ne]),f.useEffect(()=>{if(d||a)return;const I=window.setInterval(async()=>{if(!k.current)try{await L(!1),S(!0),l("")}catch(H){S(!1),l(H instanceof Error?H.message:"Live update failed")}},dP);return()=>window.clearInterval(I)},[d,a,L]),f.useEffect(()=>{if(!p||d)return;const I=M.current;I&&(I.scrollTop=I.scrollHeight)},[t,p,d]);const X=f.useMemo(()=>t.filter(I=>{var q;if(b!=="all"&&I.type!==b)return!1;if(!w.trim())return!0;const H=w.toLowerCase();return I.message.toLowerCase().includes(H)||(((q=I.timestamp)==null?void 0:q.toLowerCase().includes(H))??!1)}),[t,b,w]);return s.jsxs("div",{className:"flex h-[calc(100svh-8rem)] min-h-[480px] flex-col gap-4",children:[s.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between",children:[s.jsxs("div",{children:[s.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:"Logs"}),s.jsx("p",{className:"text-muted-foreground",children:"Live bot output — updates every 2 seconds"}),N?s.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:N}):null]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:pe("size-2 rounded-full",C&&!d?"animate-pulse bg-emerald-500":"bg-muted-foreground")}),s.jsx("span",{className:"text-xs text-muted-foreground",children:d?"Paused":C?"Live":"Disconnected"})]})]}),c?s.jsx(Ye,{variant:"destructive",children:s.jsx(qe,{children:c})}):null,s.jsxs(Je,{className:"flex min-h-0 flex-1 flex-col border-border bg-card",children:[s.jsxs(dt,{className:"shrink-0 space-y-4 border-b border-border pb-4",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[s.jsxs(ft,{className:"text-base font-medium",children:["Console",a?null:s.jsxs("span",{className:"ml-2 text-xs font-normal text-muted-foreground",children:[X.length," line",X.length===1?"":"s"]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-border px-2 py-1",children:[s.jsx(Mt,{id:"auto-scroll",checked:p,onCheckedChange:g}),s.jsx(Ae,{htmlFor:"auto-scroll",className:"text-xs font-normal",children:"Auto-scroll"})]}),s.jsxs(ue,{type:"button",variant:"outline",size:"sm",onClick:()=>m(I=>!I),children:[s.jsx(xe,{icon:d?k8:E8,size:16,className:"mr-1.5"}),d?"Resume":"Pause"]}),s.jsxs(ue,{type:"button",variant:"outline",size:"sm",onClick:()=>{n([]),ne()},disabled:a,children:[s.jsx(xe,{icon:fr,size:16,className:"mr-1.5"}),"Refresh"]})]})]}),s.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center",children:[s.jsx("div",{className:"flex flex-wrap gap-1 rounded-xl bg-secondary/50 p-1",children:iP.map(I=>s.jsx(ue,{type:"button",variant:b===I.id?"secondary":"ghost",size:"sm",className:"h-8 rounded-lg text-xs",onClick:()=>v(I.id),children:I.label},I.id))}),s.jsxs("div",{className:"relative flex-1 sm:max-w-xs",children:[s.jsx(xe,{icon:vi,size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground"}),s.jsx(_e,{placeholder:"Filter lines…",value:w,onChange:I=>y(I.target.value),className:"h-9 pl-9"})]})]})]}),s.jsx(et,{className:"min-h-0 flex-1 p-0",children:a?s.jsx("div",{className:"space-y-2 p-4",children:Array.from({length:8}).map((I,H)=>s.jsx(Ue,{className:"h-4 w-full"},H))}):s.jsx("div",{ref:M,className:"h-full max-h-[calc(100svh-18rem)] overflow-y-auto bg-[#0d0d12] p-4 font-mono text-[13px] leading-relaxed",children:X.length===0?s.jsx("p",{className:"text-muted-foreground",children:"No log lines yet. Start the bot and activity will appear here (also written to the Logs folder on disk)."}):s.jsx("ul",{className:"space-y-1",children:X.map((I,H)=>s.jsxs("li",{className:"flex gap-2 rounded px-1 py-0.5 hover:bg-white/[0.03]",children:[s.jsx("span",{className:"shrink-0 tabular-nums text-muted-foreground",children:oP(I.timestamp)}),s.jsx("span",{className:pe("shrink-0 rounded px-1.5 py-0 text-[10px] font-semibold uppercase",uP[I.type]),children:I.type}),s.jsx("span",{className:pe("min-w-0 flex-1 whitespace-pre-wrap break-words",cP[I.type]),children:I.message||" "})]},Wh(I,H)))})})})]})]})}const pP=[{title:"Colors",description:"Theme colors used across the transcript page.",fields:[{path:"Theme.Background",label:"Page background",type:"color"},{path:"Theme.Panel",label:"Panel background",type:"color"},{path:"Theme.PanelSecondary",label:"Secondary panel",type:"color"},{path:"Theme.Border",label:"Borders",type:"color"},{path:"Theme.Text",label:"Main text",type:"color"},{path:"Theme.Muted",label:"Muted text",type:"color"},{path:"Theme.Accent",label:"Accent",type:"color"},{path:"Theme.Link",label:"Links",type:"color"},{path:"Theme.AttachmentLink",label:"Attachment links",type:"color"},{path:"Theme.CodeBackground",label:"Code blocks",type:"color"}]},{title:"Typography",fields:[{path:"Typography.FontFamily",label:"Font family",type:"googleFont",description:"Google Fonts are loaded automatically in saved transcripts."}]},{title:"Header",fields:[{path:"Header.Title",label:"Title",type:"text"},{path:"Header.Subtitle",label:"Subtitle",type:"textarea",description:"Placeholders: {{ticketName}} {{ticketId}} {{messageCount}} {{reason}}. Use **text** for bold."},{path:"Header.Badge",label:"Badge label",type:"text"},{path:"Header.ShowMetaCards",label:"Show info cards",type:"boolean"}]},{title:"Info card labels",fields:[{path:"Meta.ChannelLabel",label:"Channel label",type:"text"},{path:"Meta.TicketIdLabel",label:"Ticket ID label",type:"text"},{path:"Meta.MessageCountLabel",label:"Message count label",type:"text"},{path:"Meta.CloseReasonLabel",label:"Close reason label",type:"text"},{path:"Meta.DefaultCloseReason",label:"Default close reason",type:"text"}]},{title:"Messages section",fields:[{path:"Messages.SectionTitle",label:"Section heading",type:"text"},{path:"Messages.EmptyState",label:"Empty state text",type:"text"}]},{title:"Advanced CSS",description:"Optional extra CSS appended to the transcript stylesheet.",fields:[{path:"Advanced.CustomCss",label:"Custom CSS",type:"textarea",description:"Example: .badge { font-size: 1rem; }"}]}],hP=450;function gP(t,n){return n&&t!=="viewer"}function xP(){const{user:t,hasPermission:n}=Yt(),a=!gP(t==null?void 0:t.role,n("transcripts")),[o,c]=f.useState(null),[l,d]=f.useState(null),[m,p]=f.useState(!0),[g,b]=f.useState(!1),[v,w]=f.useState(""),[y,C]=f.useState(""),[S,N]=f.useState(""),[E,T]=f.useState(!1),M=f.useRef(null),k=f.useCallback(async()=>{var X;p(!0),w(""),C("");try{const H=(await Ne.getTranscriptTemplate()).data??null;if(H){const q={...H,Typography:{...H.Typography,FontFamily:kS((X=H.Typography)==null?void 0:X.FontFamily)}};c(q),d(structuredClone(q))}}catch(I){w(I instanceof Error?I.message:"Failed to load template")}finally{p(!1)}},[]);f.useEffect(()=>{k()},[k]);const _=f.useCallback(async X=>{T(!0);try{const I=await Ne.previewTranscriptTemplate(X);N(I)}catch{N("

Preview failed to load.

")}finally{T(!1)}},[]);f.useEffect(()=>{if(o)return M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{_(o)},hP),()=>{M.current&&clearTimeout(M.current)}},[o,_]);function R(X,I){c(H=>H&&Gn(H,X,I))}async function L(){if(!(a||!o)){b(!0),w(""),C("");try{const X=await Ne.saveTranscriptTemplate(o);C(X.message||"Saved."),d(structuredClone(o))}catch(X){w(X instanceof Error?X.message:"Save failed")}finally{b(!1)}}}const ne=o&&l&&JSON.stringify(o)!==JSON.stringify(l);return m?s.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[s.jsx(Ue,{className:"h-96 rounded-xl"}),s.jsx(Ue,{className:"h-96 rounded-xl"})]}):o?s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[s.jsx("p",{className:"text-sm text-muted-foreground",children:"Customize how new ticket transcripts look. Existing saved transcripts are not changed."}),s.jsxs("div",{className:"flex items-center gap-2",children:[ne?s.jsx("span",{className:"text-xs text-amber-500",children:"Unsaved changes"}):null,a?s.jsx("span",{className:"text-xs text-muted-foreground",children:"View only"}):s.jsxs(ue,{size:"sm",onClick:L,disabled:g||!ne,children:[s.jsx(xe,{icon:Sd,size:16,className:"mr-1.5"}),g?"Saving…":"Save appearance"]})]})]}),v?s.jsx(Ye,{variant:"destructive",children:s.jsx(qe,{children:v})}):null,y?s.jsx(Ye,{className:"border-primary/30 bg-primary/10 text-primary",children:s.jsx(qe,{children:y})}):null,s.jsxs("div",{className:"grid min-h-0 gap-4 xl:grid-cols-[minmax(320px,420px)_1fr]",children:[s.jsx(bP,{data:o,readOnly:a,onPatch:R}),s.jsxs(Je,{className:"flex min-h-[520px] flex-col overflow-hidden border-border bg-card",children:[s.jsxs(dt,{className:"pb-2",children:[s.jsx(ft,{className:"text-base",children:"Live preview"}),s.jsxs(Ot,{children:["Sample ticket with your current settings",E?" · updating…":""]})]}),s.jsx(et,{className:"min-h-0 flex-1 p-4 pt-0",children:s.jsx("iframe",{title:"Transcript template preview",srcDoc:S,className:pe("h-[min(640px,calc(100svh-14rem))] w-full rounded-lg border border-border bg-background",E&&"opacity-60"),sandbox:"allow-same-origin"})})]})]})]}):s.jsx(Ye,{variant:"destructive",children:s.jsx(qe,{children:v||"Failed to load template"})})}function bP({data:t,readOnly:n,onPatch:a}){return s.jsx("div",{className:"max-h-[min(720px,calc(100svh-12rem))] space-y-4 overflow-y-auto pr-1",children:pP.map(o=>s.jsxs(Je,{className:"border-border bg-card",children:[s.jsxs(dt,{className:"pb-3",children:[s.jsx(ft,{className:"text-base",children:o.title}),o.description?s.jsx(Ot,{children:o.description}):null]}),s.jsx(et,{className:"grid gap-4 sm:grid-cols-2",children:o.fields.map(c=>s.jsx("div",{className:c.type==="textarea"?"sm:col-span-2":"",children:s.jsx(pd,{field:c,value:kr(t,c.path),readOnly:n,onChange:l=>a(c.path,l)})},c.path))})]},o.title))})}function vP(t,n){return n&&t!=="viewer"}function yP(){const{user:t,hasPermission:n}=Yt(),a=!vP(t==null?void 0:t.role,n("transcripts")),[o,c]=f.useState(null),[l,d]=f.useState(!0),[m,p]=f.useState(!1),[g,b]=f.useState(!1),[v,w]=f.useState(""),[y,C]=f.useState(""),S=f.useCallback(async()=>{var T,M,k;d(!0),w(""),C("");try{const R=(await Ne.getTranscriptSettings()).data;R&&c({autoDelete:{enabled:!!((T=R.autoDelete)!=null&&T.enabled),afterDays:((M=R.autoDelete)==null?void 0:M.afterDays)??30},publicAccess:{enabled:!!((k=R.publicAccess)!=null&&k.enabled)}})}catch(_){w(_ instanceof Error?_.message:"Failed to load settings")}finally{d(!1)}},[]);f.useEffect(()=>{S()},[S]);async function N(){if(!(!o||a)){p(!0),w(""),C("");try{const T=await Ne.updateTranscriptSettings(o);T.data&&c({autoDelete:{enabled:T.data.autoDelete.enabled,afterDays:T.data.autoDelete.afterDays},publicAccess:{enabled:T.data.publicAccess.enabled}}),C(T.message??"Settings saved.")}catch(T){w(T instanceof Error?T.message:"Failed to save settings")}finally{p(!1)}}}async function E(){var T,M;if(!a){b(!0),w(""),C("");try{const k=await Ne.purgeTranscripts();C(k.message??((T=k.data)!=null&&T.skipped?"Auto-delete is disabled.":`Removed ${((M=k.data)==null?void 0:M.deleted)??0} transcript(s).`))}catch(k){w(k instanceof Error?k.message:"Purge failed")}finally{b(!1)}}}return l?s.jsxs("div",{className:"space-y-4",children:[s.jsx(Ue,{className:"h-40 w-full rounded-xl"}),s.jsx(Ue,{className:"h-40 w-full rounded-xl"})]}):o?s.jsxs("div",{className:"mx-auto max-w-2xl space-y-4",children:[a?s.jsx(Ye,{children:s.jsx(qe,{children:"You have view-only access. An admin or editor can change these settings."})}):null,v?s.jsx(Ye,{variant:"destructive",children:s.jsx(qe,{children:v})}):null,y?s.jsx(Ye,{children:s.jsx(qe,{children:y})}):null,s.jsxs(Je,{className:"border-border bg-card",children:[s.jsxs(dt,{children:[s.jsx(ft,{className:"text-base",children:"Auto-delete"}),s.jsx(Ot,{children:"Remove transcript files automatically after they reach a certain age. The server checks hourly and whenever you open the library."})]}),s.jsxs(et,{className:"space-y-4",children:[s.jsxs("label",{className:"flex cursor-pointer items-start gap-3",children:[s.jsx("input",{type:"checkbox",className:"mt-1 size-4 rounded border-border accent-primary",checked:o.autoDelete.enabled,disabled:a,onChange:T=>c(M=>M&&{...M,autoDelete:{...M.autoDelete,enabled:T.target.checked}})}),s.jsxs("span",{className:"text-sm",children:[s.jsx("span",{className:"font-medium",children:"Enable auto-delete"}),s.jsx("span",{className:"mt-0.5 block text-muted-foreground",children:"Deletes HTML files in Data/Transcripts based on last modified time."})]})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("label",{className:"text-sm font-medium",htmlFor:"transcript-after-days",children:"Delete after (days)"}),s.jsx(_e,{id:"transcript-after-days",type:"number",min:1,max:3650,disabled:a||!o.autoDelete.enabled,value:o.autoDelete.afterDays,onChange:T=>c(M=>M&&{...M,autoDelete:{...M.autoDelete,afterDays:Math.min(3650,Math.max(1,parseInt(T.target.value,10)||1))}}),className:"max-w-[8rem]"})]}),s.jsxs(ue,{type:"button",variant:"outline",size:"sm",disabled:a||g,onClick:()=>void E(),children:[s.jsx(xe,{icon:fr,size:16,className:pe(g&&"animate-spin")}),"Run cleanup now"]})]})]}),s.jsxs(Je,{className:"border-border bg-card",children:[s.jsxs(dt,{children:[s.jsx(ft,{className:"text-base",children:"Public transcripts"}),s.jsxs(Ot,{children:["When enabled, anyone with the link can view a transcript at"," ",s.jsx("code",{className:"rounded bg-muted px-1 py-0.5 text-xs",children:typeof window<"u"?`${window.location.origin}/transcripts/:id`:"/transcripts/:id"})," ","without signing in. Channel IDs are numeric but not secret—only enable if you are comfortable sharing links."]})]}),s.jsx(et,{children:s.jsxs("label",{className:"flex cursor-pointer items-start gap-3",children:[s.jsx("input",{type:"checkbox",className:"mt-1 size-4 rounded border-border accent-primary",checked:o.publicAccess.enabled,disabled:a,onChange:T=>c(M=>M&&{...M,publicAccess:{enabled:T.target.checked}})}),s.jsxs("span",{className:"text-sm",children:[s.jsx("span",{className:"font-medium",children:"Allow public transcript URLs"}),s.jsx("span",{className:"mt-0.5 block text-muted-foreground",children:"Dashboard preview and download still require login."})]})]})})]}),a?null:s.jsxs(ue,{type:"button",disabled:m,onClick:()=>void N(),children:[s.jsx(xe,{icon:Sd,size:16}),m?"Saving…":"Save settings"]})]}):s.jsx(Ye,{variant:"destructive",children:s.jsx(qe,{children:"Could not load transcript settings."})})}function wP(t,n){return n&&t!=="viewer"}function r2(t){return t==null?"":t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function a2(t){const n=new Date(t);return Number.isNaN(n.getTime())?t:n.toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"})}function jP(){var B;const{user:t,hasPermission:n}=Yt(),a=wP(t==null?void 0:t.role,n("transcripts")),[o,c]=f.useState("browse"),[l,d]=f.useState([]),[m,p]=f.useState(null),[g,b]=f.useState(!0),[v,w]=f.useState(""),[y,C]=f.useState(""),[S,N]=f.useState(""),[E,T]=f.useState(0),[M,k]=f.useState(!1),[_,R]=f.useState(!1),[L,ne]=f.useState(!1),[X,I]=f.useState(!1),H=f.useCallback(async()=>{b(!0),C("");try{const Z=(await Ne.listTranscripts()).data??[];d(Z),p(be=>{var K;return be&&Z.some(ge=>ge.id===be)?be:((K=Z[0])==null?void 0:K.id)??null})}catch(V){C(V instanceof Error?V.message:"Failed to load transcripts")}finally{b(!1)}},[]);f.useEffect(()=>{H()},[H]),f.useEffect(()=>{o==="browse"&&Ne.getTranscriptSettings().then(V=>{var Z,be;ne(!!((be=(Z=V.data)==null?void 0:Z.publicAccess)!=null&&be.enabled))}).catch(()=>ne(!1))},[o]);const q=f.useMemo(()=>{if(!S.trim())return l;const V=S.toLowerCase();return l.filter(Z=>Z.id.includes(V)||Z.filename.toLowerCase().includes(V)||Z.ticketName&&Z.ticketName.toLowerCase().includes(V))},[l,S]),ce=f.useMemo(()=>l.find(V=>V.id===m)??null,[l,m]),de=m?`/api/system/transcripts/${encodeURIComponent(m)}/view`:null,se=m?`/api/system/transcripts/${encodeURIComponent(m)}/download`:null,P=m&&L?`${window.location.origin}/transcripts/${encodeURIComponent(m)}`:null;function W(V){w(""),p(V),T(Z=>Z+1)}function oe(){de&&window.open(de,"_blank","noopener,noreferrer")}function ae(){P&&window.open(P,"_blank","noopener,noreferrer")}async function G(){if(P)try{await navigator.clipboard.writeText(P),I(!0),window.setTimeout(()=>I(!1),2e3)}catch{w("Could not copy link to clipboard.")}}async function O(){var Z;if(!m||!a)return;const V=((Z=ce==null?void 0:ce.ticketName)==null?void 0:Z.trim())||`channel ${m}`;if(window.confirm(`Delete the transcript for ${V}? This cannot be undone.`)){R(!0),w("");try{await Ne.deleteTranscript(m),await H()}catch(be){w(be instanceof Error?be.message:"Failed to delete transcript")}finally{R(!1)}}}async function D(){if(!(!se||!ce)){k(!0),w("");try{const V=await fetch(se,{credentials:"include"});if(!V.ok){const ge=await V.json().catch(()=>({}));throw new Error(ge.error||`Download failed (${V.status})`)}const Z=await V.blob(),be=URL.createObjectURL(Z),K=document.createElement("a");K.href=be,K.download=ce.filename,K.click(),URL.revokeObjectURL(be)}catch(V){w(V instanceof Error?V.message:"Failed to download transcript")}finally{k(!1)}}}return s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-4",children:[s.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[s.jsxs("div",{children:[s.jsx("h1",{className:"text-2xl font-semibold tracking-tight",children:"Transcripts"}),s.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Browse saved transcripts or customize how new ones look when tickets close."})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs("div",{className:"flex rounded-lg border border-border p-0.5",children:[s.jsx(ue,{type:"button",variant:o==="browse"?"secondary":"ghost",size:"sm",className:"h-8",onClick:()=>c("browse"),children:"Library"}),s.jsx(ue,{type:"button",variant:o==="appearance"?"secondary":"ghost",size:"sm",className:"h-8",onClick:()=>c("appearance"),children:"Appearance"}),s.jsx(ue,{type:"button",variant:o==="settings"?"secondary":"ghost",size:"sm",className:"h-8",onClick:()=>c("settings"),children:"Settings"})]}),o==="browse"?s.jsxs(ue,{variant:"outline",size:"sm",onClick:()=>H(),disabled:g,children:[s.jsx(xe,{icon:fr,size:16,className:pe(g&&"animate-spin")}),"Refresh"]}):null]})]}),o==="appearance"?s.jsx(xP,{}):o==="settings"?s.jsx(yP,{}):s.jsxs(s.Fragment,{children:[y?s.jsx(Ye,{variant:"destructive",children:s.jsx(qe,{children:y})}):null,s.jsxs("div",{className:"grid min-h-0 flex-1 gap-4 lg:grid-cols-[minmax(240px,320px)_1fr]",children:[s.jsxs(Je,{className:"flex min-h-[420px] flex-col border-border bg-card",children:[s.jsxs(dt,{className:"space-y-3 pb-3",children:[s.jsxs(ft,{className:"text-base font-medium",children:["Saved transcripts",!g&&l.length>0?s.jsxs("span",{className:"ml-2 font-normal text-muted-foreground",children:["(",l.length,")"]}):null]}),s.jsxs("div",{className:"relative",children:[s.jsx(xe,{icon:vi,size:16,className:"pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground"}),s.jsx(_e,{placeholder:"Search by ticket name or channel ID…",value:S,onChange:V=>N(V.target.value),className:"pl-9"})]})]}),s.jsx(et,{className:"min-h-0 flex-1 p-0 pb-4",children:s.jsx(fc,{className:"h-[min(520px,calc(100svh-16rem))] px-4",children:g?s.jsx("div",{className:"space-y-2",children:Array.from({length:6}).map((V,Z)=>s.jsx(Ue,{className:"h-16 w-full rounded-lg"},Z))}):q.length===0?s.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-12 text-center text-sm text-muted-foreground",children:[s.jsx(xe,{icon:Ul,size:32,className:"opacity-40"}),s.jsx("p",{children:l.length===0?"No transcripts yet. They appear when tickets are closed.":"No transcripts match your search."})]}):s.jsx("ul",{className:"space-y-1.5",children:q.map(V=>{var K;const Z=V.id===m,be=((K=V.ticketName)==null?void 0:K.trim())||`Channel ${V.id}`;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>W(V.id),className:pe("w-full rounded-lg border px-3 py-2.5 text-left transition-colors",Z?"border-primary/50 bg-primary/10":"border-transparent bg-secondary/30 hover:bg-secondary/50"),children:[s.jsx("p",{className:"truncate text-sm font-medium",children:be}),s.jsxs("p",{className:"mt-0.5 text-xs text-muted-foreground",children:[a2(V.createdAt),V.size!=null?` · ${r2(V.size)}`:""]})]})},V.id)})})})})]}),s.jsxs(Je,{className:"flex min-h-[420px] flex-col overflow-hidden border-border bg-card",children:[s.jsxs(dt,{className:"flex flex-row flex-wrap items-center justify-between gap-2 space-y-0 pb-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx(ft,{className:"truncate text-base font-medium",children:ce?((B=ce.ticketName)==null?void 0:B.trim())||`Channel ${ce.id}`:"Preview"}),ce?s.jsxs("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:[a2(ce.createdAt),ce.size!=null?` · ${r2(ce.size)}`:""]}):null]}),s.jsxs("div",{className:"flex shrink-0 flex-wrap gap-2",children:[P?s.jsxs(s.Fragment,{children:[s.jsxs(ue,{variant:"outline",size:"sm",onClick:()=>void G(),children:[s.jsx(xe,{icon:R2,size:16}),X?"Copied":"Copy link"]}),s.jsxs(ue,{variant:"outline",size:"sm",onClick:ae,children:[s.jsx(xe,{icon:Nd,size:16}),"Public page"]})]}):null,s.jsxs(ue,{variant:"outline",size:"sm",disabled:!de,onClick:oe,children:[s.jsx(xe,{icon:p8,size:16}),"Open tab"]}),s.jsxs(ue,{variant:"outline",size:"sm",disabled:!se||M,onClick:()=>void D(),children:[s.jsx(xe,{icon:Cd,size:16}),M?"Saving…":"Download"]}),a?s.jsxs(ue,{variant:"outline",size:"sm",disabled:!m||_,className:"text-destructive hover:text-destructive",onClick:()=>void O(),children:[s.jsx(xe,{icon:bi,size:16}),_?"Deleting…":"Delete"]}):null]})]}),s.jsxs(et,{className:"flex min-h-0 flex-1 flex-col gap-2 p-4 pt-0",children:[v?s.jsx(Ye,{variant:"destructive",children:s.jsx(qe,{children:v})}):null,ce&&de?s.jsx("iframe",{title:`Transcript ${ce.id}`,src:de,className:"min-h-[min(560px,calc(100svh-18rem))] w-full flex-1 rounded-lg border border-border bg-background",sandbox:"allow-same-origin"},E):s.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-2 rounded-lg border border-dashed border-border py-16 text-center text-sm text-muted-foreground",children:[s.jsx(xe,{icon:Ul,size:40,className:"opacity-30"}),s.jsx("p",{children:"Select a transcript from the list to preview it here."})]})]})]})]})]})]})}function CP(){const[t,n]=f.useState([]),[a,o]=f.useState(""),[c,l]=f.useState(!0),[d,m]=f.useState(""),[p,g]=f.useState(!0),[b,v]=f.useState([]);f.useEffect(()=>{try{Ne.getConfigJson("supportbot").then(Y=>{if(Y&&Y.data&&typeof Y.data=="object"){const te=kr(Y.data,"Ticket.DepartmentSystem.Enabled");typeof te=="boolean"&&g(te);const je=kr(Y.data,"Ticket.DepartmentSystem.Departments");if(je&&typeof je=="object"){const we=Object.entries(je).map(([Le,Xe])=>({id:Le,name:Xe&&typeof Xe=="object"&&Xe.Name?Xe.Name:Le,emoji:Xe&&typeof Xe=="object"&&Xe.Emoji?Xe.Emoji:"🎫"}));we.length>0&&(v(we),yn(we[0].id))}}}).catch(()=>{})}catch{}},[]);const[w,y]=f.useState("all"),[C,S]=f.useState("all"),[N,E]=f.useState(""),T=f.useMemo(()=>{const Y=new Set;return Array.isArray(t)&&t.forEach(te=>{if(te&&te.department&&typeof te.department=="string"){const je=te.department.trim().toLowerCase();je&&Y.add(je)}}),Array.from(Y).sort()},[t]),M=f.useMemo(()=>Array.isArray(t)?t.filter(Y=>{var te,je,we,Le,Xe,vt;if(!Y||p&&w!=="all"&&((te=Y.department)==null?void 0:te.toLowerCase())!==w.toLowerCase()||C!=="all"&&((je=Y.priority)==null?void 0:je.toLowerCase())!==C.toLowerCase())return!1;if(N.trim()){const gt=N.toLowerCase().trim(),jn=(we=Y.subject)==null?void 0:we.toLowerCase().includes(gt),mn=(Le=Y.ticket_id)==null?void 0:Le.toLowerCase().includes(gt),an=(Xe=Y.user_id)==null?void 0:Xe.toLowerCase().includes(gt),tr=p&&((vt=Y.department)==null?void 0:vt.toLowerCase().includes(gt));if(!jn&&!mn&&!an&&!tr)return!1}return!0}):[],[t,p,w,C,N]),[k,_]=f.useState(null),[R,L]=f.useState(!1),[ne,X]=f.useState(!1),[I,H]=f.useState([]),[q,ce]=f.useState(!1),[de,se]=f.useState(""),[P,W]=f.useState([]),[oe,ae]=f.useState(!1),[G,O]=f.useState(null),[D,B]=f.useState(!1),[V,Z]=f.useState(""),[be,K]=f.useState(null),[ge,me]=f.useState(""),[$,ie]=f.useState(!1),[ye,Se]=f.useState(null),[Be,Ke]=f.useState(""),[We,qt]=f.useState(null),[vn,Xn]=f.useState(!1),[br,yn]=f.useState("general"),[wn,Zn]=f.useState(""),[Kt,po]=f.useState(""),[Pt,Qn]=f.useState(!1),Da=async()=>{if(!wn.trim()){Dt.error("Please enter a subject or reason for the ticket.");return}Qn(!0);try{const Y=await Ne.createTicket({department:p?br:"general",subject:wn.trim(),userId:Kt.trim()||void 0});Dt.success(Y.message||"Ticket opened successfully!"),Xn(!1),Zn(""),po(""),yt()}catch(Y){Dt.error(Y instanceof Error?Y.message:"Failed to open ticket.")}finally{Qn(!1)}},Es=Y=>{Se(Y),Ke("Closed via Web Dashboard"),ie(!0)},qr=async()=>{if(!ye)return;const Y=ye.ticket_id;qt(Y);try{await Ne.closeTicket(Y,Be||"Closed via Web Dashboard"),Dt.success("Ticket closed and transcript saved."),n(te=>te.filter(je=>je.ticket_id!==Y)),(k==null?void 0:k.ticket_id)===Y&&(L(!1),X(!1),_(null)),ie(!1),Se(null)}catch(te){Dt.error(te instanceof Error?te.message:"Failed to close ticket.")}finally{qt(null)}},ho=f.useRef(null),Kr=f.useRef(null),Dn=()=>{var Y;(Y=ho.current)==null||Y.scrollIntoView({behavior:"smooth"})},yt=f.useCallback(async()=>{l(!0),m("");try{const Y=await Ne.listOpenTickets();Y.data&&(o(Y.data.guildId),n(Y.data.tickets.sort((te,je)=>je.created_at-te.created_at)))}catch(Y){m(Y instanceof Error?Y.message:"Failed to load open tickets")}finally{l(!1)}},[]);f.useEffect(()=>{yt()},[yt]),f.useEffect(()=>{Ne.getGuildResources().then(Y=>{Y.data&&O(Y.data)}).catch(()=>{})},[]);const On=f.useCallback(Y=>{k&&Y.ticketId===k.ticket_id&&(H(te=>te.some(je=>je.id===Y.message.id)?te:[...te,Y.message]),setTimeout(Dn,100))},[k]),Rt=f.useCallback(Y=>{k&&Y.ticketId===k.ticket_id&&H(te=>te.filter(je=>je.id!==Y.messageId))},[k]),Ai=f.useCallback(Y=>{k&&Y.ticketId===k.ticket_id&&H(te=>te.map(je=>je.id===Y.messageId?{...je,content:Y.content}:je))},[k]),_i=f.useCallback(Y=>{n(te=>te.some(je=>je.ticket_id===Y.ticket_id)?te:[Y,...te]),Dt.info("New Ticket Created",{description:`#${Y.ticket_id} - ${Y.subject||"No Subject"}`})},[]),go=f.useCallback(Y=>{n(te=>te.filter(je=>je.ticket_id!==Y.ticket_id)),(k==null?void 0:k.ticket_id)===Y.ticket_id&&Dt.warning("Active ticket was closed in Discord.")},[k]);kx({onTicketMessage:On,onTicketMessageDeleted:Rt,onTicketMessageUpdated:Ai,onTicketCreated:_i,onTicketClosed:go});const Wr=async Y=>{var te;_(Y),L(!0),ce(!0),H([]),W([]),K(null);try{const je=await Ne.getTicketMessages(Y.ticket_id);(te=je.data)!=null&&te.messages&&(H(je.data.messages),setTimeout(Dn,150))}catch(je){Dt.error(je instanceof Error?je.message:"Failed to fetch messages")}finally{ce(!1)}},Oa=Y=>{const te=Array.from(Y.target.files||[]);te.length&&(te.forEach(je=>{const we=new FileReader;we.onload=Le=>{var vt;const Xe=(vt=Le.target)==null?void 0:vt.result;W(gt=>[...gt,{filename:je.name,data:Xe,previewUrl:je.type.startsWith("image/")?Xe:void 0,sizeMb:(je.size/1024/1024).toFixed(2)}])},we.readAsDataURL(je)}),Kr.current&&(Kr.current.value=""))},Ar=Y=>{W(te=>te.filter((je,we)=>we!==Y))},Wt=async Y=>{var we;if(Y.preventDefault(),!de.trim()&&!P.length||!k||oe)return;const te=de.trim(),je=[...P];ae(!0),se(""),W([]),B(!1);try{const Le=await Ne.me().catch(()=>null),Xe=((we=Le==null?void 0:Le.data)==null?void 0:we.username)||"Staff",vt=await Ne.sendTicketReply(k.ticket_id,te,Xe,je.map(gt=>({filename:gt.filename,data:gt.data})));vt.data&&(H(gt=>gt.some(jn=>jn.id===vt.data.id)?gt:[...gt,{id:vt.data.id,author:vt.data.author,content:vt.data.content,attachments:vt.data.attachments||[],createdAt:vt.data.createdAt}]),setTimeout(Dn,100))}catch(Le){Dt.error(Le instanceof Error?Le.message:"Failed to send reply to Discord."),se(te),W(je)}finally{ae(!1)}},La=async Y=>{if(k)try{await Ne.deleteTicketMessage(k.ticket_id,Y),H(te=>te.filter(je=>je.id!==Y)),Dt.success("Message deleted in Discord.")}catch(te){Dt.error(te instanceof Error?te.message:"Failed to delete message.")}},De=Y=>{K(Y.id),me(Y.content)},rt=()=>{K(null),me("")},lt=async Y=>{if(!(!k||!ge.trim()))try{await Ne.editTicketMessage(k.ticket_id,Y,ge.trim()),H(te=>te.map(je=>je.id===Y?{...je,content:ge.trim()}:je)),K(null),Dt.success("Message updated in Discord.")}catch(te){Dt.error(te instanceof Error?te.message:"Failed to edit message.")}},rn=Y=>{const te=Y.target.value;se(te);const je=Y.target.selectionStart||te.length,we=te.slice(0,je),Le=we.lastIndexOf("@");if(Le!==-1&&!we.slice(Le).includes(" ")){const Xe=we.slice(Le+1).toLowerCase();Z(Xe),B(!0)}else B(!1)},It=(Y,te,je)=>{const we=de.lastIndexOf("@"),Le=de.slice(0,we),Xe=je?`<@&${te}>`:`<@${te}>`;se(`${Le}${Xe} `),B(!1)},Jn=Y=>{const te=Math.floor((Date.now()-Y)/1e3);return fg(te)},er=Y=>new Date(Y).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),bt=Y=>{if(!Y)return null;const te=/(```[\s\S]*?```|`[^`]+`|\*\*\*[\s\S]+?\*\*\*|\*\*[\s\S]+?\*\*|__[\s\S]+?__|~~[\s\S]+?~~|\|\|[\s\S]+?\|\||<@!?&?\d+>|^###\s[^\n]+|^##\s[^\n]+|^-#\s[^\n]+|\[[^\]]+\]\(https?:\/\/[^\s)]+\)|https?:\/\/[^\s]+)/gm;return Y.split(te).map((we,Le)=>{var jn;if(!we)return null;if(we.startsWith("-# "))return s.jsx("span",{className:"text-xs text-muted-foreground font-medium block my-0.5 opacity-80",children:bt(we.slice(3))},Le);if(we.startsWith("## "))return s.jsx("span",{className:"text-base font-bold text-foreground block my-1 tracking-tight",children:bt(we.slice(3))},Le);if(we.startsWith("### "))return s.jsx("span",{className:"text-sm font-bold text-foreground block my-0.5",children:bt(we.slice(4))},Le);if(we.startsWith("```")&&we.endsWith("```")&&we.length>=6){const mn=we.slice(3,-3).replace(/^[a-z0-9_-]+\n/i,"");return s.jsx("pre",{className:"bg-black/60 p-2.5 rounded-lg text-xs font-mono my-1.5 border border-border overflow-x-auto text-emerald-400 font-mono",children:s.jsx("code",{children:mn})},Le)}if(we.startsWith("`")&&we.endsWith("`")&&we.length>2)return s.jsx("code",{className:"bg-black/50 px-1.5 py-0.5 rounded text-xs font-mono text-emerald-300 border border-border/40",children:we.slice(1,-1)},Le);if(we.startsWith("***")&&we.endsWith("***")&&we.length>6)return s.jsx("strong",{className:"font-bold italic",children:bt(we.slice(3,-3))},Le);if(we.startsWith("**")&&we.endsWith("**")&&we.length>4)return s.jsx("strong",{className:"font-bold",children:bt(we.slice(2,-2))},Le);if(we.startsWith("__")&&we.endsWith("__")&&we.length>4)return s.jsx("span",{className:"underline underline-offset-2",children:bt(we.slice(2,-2))},Le);if(we.startsWith("~~")&&we.endsWith("~~")&&we.length>4)return s.jsx("span",{className:"line-through opacity-80",children:bt(we.slice(2,-2))},Le);if(we.startsWith("||")&&we.endsWith("||")&&we.length>4)return s.jsx("span",{className:"bg-secondary text-transparent hover:text-foreground hover:bg-secondary/50 px-1.5 py-0.5 rounded transition-all cursor-pointer select-none border border-border/30",title:"Click to reveal spoiler",children:we.slice(2,-2)},Le);const Xe=we.match(/^<@!?(\d+)>$/);if(Xe){const mn=Xe[1],an=new Map;k&&an.set(k.user_id,"Ticket Author"),I.forEach(_r=>{var Xr;(Xr=_r.author)!=null&&Xr.id&&an.set(_r.author.id,_r.author.globalName||_r.author.username)});const tr=an.get(mn);return s.jsxs("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded font-semibold text-xs bg-primary/20 text-primary mx-0.5",title:`User ID: ${mn}`,children:["@",tr||"User"]},Le)}const vt=we.match(/^<@&(\d+)>$/);if(vt){const mn=vt[1],an=(jn=G==null?void 0:G.roles)==null?void 0:jn.find(tr=>tr.id===mn);return s.jsxs("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded font-semibold text-xs bg-amber-500/20 text-amber-400 mx-0.5",children:["@",an?an.name:`Role (${mn})`]},Le)}const gt=we.match(/^\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)$/);if(gt){const mn=gt[1],an=gt[2];return s.jsx("a",{href:an,target:"_blank",rel:"noreferrer",className:"text-primary underline hover:opacity-80 break-all",children:mn},Le)}return/^https?:\/\/[^\s]+$/i.test(we)?/\.(gif|jpe?g|png|webp)(\?[^\s]*)?$/i.test(we)||/cdn\.discordapp\.com\/(emojis|attachments)\//i.test(we)||/images\.discordapp\.net\//i.test(we)||/media\d*\.giphy\.com\//i.test(we)?s.jsx("span",{className:"block my-1",children:s.jsx("img",{src:we,alt:"GIF/Image",className:"max-h-64 rounded-lg border border-border object-contain hover:opacity-95 transition-opacity",loading:"lazy"})},Le):s.jsx("a",{href:we,target:"_blank",rel:"noreferrer",className:"text-primary underline hover:opacity-80 break-all",children:we},Le):we})},Ln=Y=>!Y||Y.length===0?null:s.jsx("div",{className:"space-y-2 mt-1",children:Y.map(te=>{var Xe,vt,gt;const je=((Xe=te.contentType)==null?void 0:Xe.startsWith("image/"))||/\.(png|jpe?g|gif|webp|svg)$/i.test(te.name),we=((vt=te.contentType)==null?void 0:vt.startsWith("video/"))||/\.(mp4|webm|mov|mkv)$/i.test(te.name),Le=((gt=te.contentType)==null?void 0:gt.startsWith("audio/"))||/\.(mp3|wav|ogg|m4a)$/i.test(te.name);return je?s.jsx("div",{className:"rounded-lg overflow-hidden border border-border bg-black/40",children:s.jsx("a",{href:te.url,target:"_blank",rel:"noreferrer",children:s.jsx("img",{src:te.url,alt:te.name,className:"max-h-80 max-w-full object-contain hover:opacity-95 transition-opacity",loading:"lazy"})})},te.id):we?s.jsx("div",{className:"rounded-lg overflow-hidden border border-border bg-black",children:s.jsx("video",{src:te.url,controls:!0,className:"max-h-80 max-w-full"})},te.id):Le?s.jsx("div",{className:"p-2 border border-border rounded-lg bg-secondary/20",children:s.jsx("audio",{src:te.url,controls:!0,className:"w-full h-8"})},te.id):s.jsxs("div",{className:"p-2.5 rounded-lg border border-border bg-secondary/20 flex items-center justify-between text-xs gap-3",children:[s.jsxs("div",{className:"flex items-center gap-2 truncate",children:[s.jsx(xe,{icon:Uy,size:16,className:"text-primary shrink-0"}),s.jsx("span",{className:"truncate font-medium",children:te.name})]}),s.jsx(ue,{variant:"ghost",size:"sm",asChild:!0,className:"h-7 px-2 text-xs",children:s.jsx("a",{href:te.url,target:"_blank",rel:"noreferrer",download:!0,children:"Download"})})]},te.id)})}),Di=Y=>!Y||Y.length===0?null:s.jsx("div",{className:"space-y-3 mt-1.5 w-full",children:Y.map((te,je)=>{var we,Le,Xe,vt;return s.jsxs("div",{className:"rounded-lg border border-border/60 bg-secondary/30 p-3.5 text-xs space-y-2 border-l-4 shadow-sm relative overflow-hidden max-w-xl",style:{borderLeftColor:te.color||"#5865F2"},children:[te.author&&s.jsxs("div",{className:"flex items-center gap-2 text-xs font-semibold text-foreground",children:[te.author.iconURL&&s.jsx("img",{src:te.author.iconURL,alt:"",className:"h-4 w-4 rounded-full"}),s.jsx("span",{children:te.author.name})]}),((we=te.thumbnail)==null?void 0:we.url)&&s.jsx("img",{src:te.thumbnail.url,alt:"",className:"h-12 w-12 rounded object-cover absolute top-3 right-3 border border-border"}),te.title&&s.jsx("h4",{className:"font-bold text-sm text-foreground tracking-tight pr-12",children:bt(te.title)}),te.description&&s.jsx("div",{className:"text-muted-foreground whitespace-pre-wrap leading-relaxed pr-12",children:bt(te.description)}),te.fields&&te.fields.length>0&&s.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2.5 pt-2 border-t border-border/30",children:te.fields.map((gt,jn)=>s.jsxs("div",{className:`space-y-0.5 ${gt.inline?"":"sm:col-span-2"}`,children:[s.jsx("p",{className:"font-semibold text-foreground text-[11px] uppercase tracking-wider",children:gt.name}),s.jsx("p",{className:"text-muted-foreground whitespace-pre-wrap",children:bt(gt.value)})]},jn))}),((Le=te.image)==null?void 0:Le.url)&&s.jsx("div",{className:"rounded-md overflow-hidden border border-border mt-2",children:s.jsx("img",{src:te.image.url,alt:"",className:"max-h-64 w-full object-cover"})}),(te.footer||te.timestamp)&&s.jsxs("div",{className:"flex items-center gap-2 pt-1 border-t border-border/20 text-[10px] text-muted-foreground",children:[((Xe=te.footer)==null?void 0:Xe.iconURL)&&s.jsx("img",{src:te.footer.iconURL,alt:"",className:"h-3.5 w-3.5 rounded-full"}),((vt=te.footer)==null?void 0:vt.text)&&s.jsx("span",{children:te.footer.text}),te.timestamp&&s.jsxs("span",{children:[new Date(te.timestamp).toLocaleDateString()," ",new Date(te.timestamp).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]})]})]},je)})}),Oi=Y=>{if(!Y||Y.length===0)return null;const te=Y.map(je=>({...je,components:(je.components||[]).filter(we=>we.customId||we.url||we.type===2||we.type===3||we.type==="BUTTON"||we.type==="STRING_SELECT")})).filter(je=>je.components&&je.components.length>0);return te.length===0?null:s.jsx("div",{className:"space-y-2 mt-2.5 w-full",children:te.map((je,we)=>{var Le;return s.jsx("div",{className:"flex items-center gap-2 flex-wrap",children:(Le=je.components)==null?void 0:Le.map((Xe,vt)=>s.jsxs("div",{className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-secondary/80 text-secondary-foreground text-xs font-semibold border border-border/80 shadow-sm hover:bg-secondary transition-colors cursor-pointer",children:[Xe.emoji&&s.jsx("span",{children:Xe.emoji}),s.jsx("span",{children:Xe.label||Xe.customId||"Button"})]},vt))},we)})})},Li=()=>s.jsx(fc,{className:"flex-1 p-4 sm:p-6",children:s.jsxs("div",{className:"max-w-4xl mx-auto w-full space-y-4",children:[q?s.jsxs("div",{className:"space-y-4 p-4",children:[s.jsx(Ue,{className:"h-10 w-3/4"}),s.jsx(Ue,{className:"h-10 w-1/2 ml-auto"}),s.jsx(Ue,{className:"h-10 w-2/3"})]}):I.length===0?s.jsx("div",{className:"p-12 text-center text-muted-foreground text-sm",children:"No recent messages in this ticket channel."}):I.map(Y=>{var te;return s.jsxs("div",{className:`group flex items-start gap-3 ${Y.author.isDashboard?"flex-row-reverse":""}`,children:[s.jsxs(vs,{className:"h-8 w-8 shrink-0",children:[s.jsx(eo,{src:Y.author.avatar,alt:Y.author.username}),s.jsx(ys,{children:s.jsx(xe,{icon:L8,size:16})})]}),s.jsxs("div",{className:`flex flex-col space-y-1 max-w-[80%] ${Y.author.isDashboard?"items-end":"items-start"}`,children:[s.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[s.jsx("span",{className:"font-semibold text-foreground",children:Y.author.globalName||Y.author.username}),Y.author.bot&&s.jsx(Fn,{variant:"secondary",className:"px-1 py-0 text-[10px]",children:"BOT"}),Y.author.isDashboard&&s.jsx(Fn,{variant:"default",className:"px-1 py-0 text-[10px]",children:"STAFF"}),s.jsx("span",{children:er(Y.createdAt)}),s.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-1",children:[s.jsx(ue,{variant:"ghost",size:"icon",className:"h-5 w-5 text-muted-foreground hover:text-foreground",onClick:()=>De(Y),title:"Edit Message",children:s.jsx(xe,{icon:D2,size:12})}),s.jsx(ue,{variant:"ghost",size:"icon",className:"h-5 w-5 text-muted-foreground hover:text-destructive",onClick:()=>La(Y.id),title:"Delete Message",children:s.jsx(xe,{icon:bi,size:12})})]})]}),be===Y.id?s.jsxs("div",{className:"flex items-center gap-2 w-full mt-1",children:[s.jsx(_e,{value:ge,onChange:je=>me(je.target.value),className:"h-8 text-sm",autoFocus:!0}),s.jsx(ue,{size:"sm",className:"h-8 px-2 bg-primary",onClick:()=>lt(Y.id),children:s.jsx(xe,{icon:_8,size:14})}),s.jsx(ue,{size:"sm",variant:"ghost",className:"h-8 px-2",onClick:rt,children:s.jsx(xe,{icon:ba,size:14})})]}):Y.content?s.jsx("div",{className:`rounded-lg px-3.5 py-2.5 text-sm whitespace-pre-wrap ${Y.author.isDashboard?"bg-primary text-primary-foreground":"bg-secondary/40 text-secondary-foreground border border-border/50"}`,style:Y.containerColor||Y.author.bot&&!((te=Y.embeds)!=null&&te.length)?{borderLeftWidth:"4px",borderLeftColor:Y.containerColor||"#5865F2"}:void 0,children:bt(Y.content)}):null,Ln(Y.attachments),Di(Y.embeds),Oi(Y.components)]})]},Y.id)}),s.jsx("div",{ref:ho})]})}),zi=()=>{var Y;return s.jsxs("div",{className:"p-4 border-t border-border bg-secondary/10 flex flex-col gap-2 relative",children:[P.length>0&&s.jsx("div",{className:"max-w-4xl mx-auto w-full flex items-center gap-2 flex-wrap mb-1",children:P.map((te,je)=>s.jsxs("div",{className:"flex items-center gap-2 p-1.5 px-3 rounded-lg border border-border bg-secondary text-xs",children:[te.previewUrl?s.jsx("img",{src:te.previewUrl,alt:"",className:"h-6 w-6 rounded object-cover"}):s.jsx(xe,{icon:Uy,size:14,className:"text-primary"}),s.jsx("span",{className:"font-medium max-w-[120px] truncate",children:te.filename}),s.jsxs("span",{className:"text-muted-foreground text-[10px]",children:[te.sizeMb,"MB"]}),s.jsx("button",{type:"button",onClick:()=>Ar(je),className:"text-muted-foreground hover:text-destructive ml-1",children:s.jsx(xe,{icon:ba,size:12})})]},je))}),D&&s.jsxs("div",{className:"max-w-4xl mx-auto w-full absolute bottom-full mb-2 z-50 bg-popover text-popover-foreground border border-border rounded-xl shadow-xl overflow-hidden max-h-48 overflow-y-auto",children:[s.jsx("div",{className:"p-2 text-[11px] font-semibold text-muted-foreground uppercase tracking-wider border-b",children:"Mentions (@)"}),k&&s.jsxs("button",{type:"button",onClick:()=>It("Ticket Author",k.user_id,!1),className:"w-full text-left p-2 hover:bg-secondary flex items-center justify-between text-xs",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(vs,{className:"h-5 w-5",children:s.jsx(ys,{children:"U"})}),s.jsx("span",{className:"font-medium",children:"Ticket Author"})]}),s.jsxs("span",{className:"text-[10px] font-mono text-muted-foreground",children:["@",k.user_id]})]}),(Y=G==null?void 0:G.roles)==null?void 0:Y.filter(te=>te.name.toLowerCase().includes(V)).slice(0,5).map(te=>s.jsxs("button",{type:"button",onClick:()=>It(te.name,te.id,!0),className:"w-full text-left p-2 hover:bg-secondary flex items-center justify-between text-xs",children:[s.jsxs("span",{className:"font-medium text-amber-400",children:["@",te.name]}),s.jsx("span",{className:"text-[10px] font-mono text-muted-foreground",children:"Role"})]},te.id))]}),s.jsxs("form",{onSubmit:Wt,className:"max-w-4xl mx-auto w-full flex items-center gap-2",children:[s.jsx("input",{type:"file",ref:Kr,multiple:!0,onChange:Oa,className:"hidden",accept:"image/*,video/*,audio/*,.pdf,.zip,.txt,.json"}),s.jsx(ue,{type:"button",variant:"outline",size:"sm",onClick:()=>{var te;return(te=Kr.current)==null?void 0:te.click()},title:"Attach files or media",className:"h-9 px-2.5",children:s.jsx(xe,{icon:v8,size:16})}),s.jsx(_e,{value:de,onChange:rn,placeholder:"Type a reply... Use @ to tag roles or users",disabled:oe||q,className:"flex-1"}),s.jsx(ue,{type:"submit",size:"sm",disabled:oe||!de.trim()&&!P.length||q,children:oe?s.jsx(xe,{icon:fr,size:16,className:"animate-spin"}):s.jsxs(s.Fragment,{children:[s.jsx(xe,{icon:R8,size:16,className:"mr-1.5"}),"Send"]})})]})]})};return s.jsxs("div",{className:"space-y-6",children:[s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[s.jsxs("div",{children:[s.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:"Open Tickets"}),s.jsx("p",{className:"text-muted-foreground",children:"Manage open support tickets & reply live to Discord channels from the web dashboard."})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(ue,{onClick:()=>Xn(!0),className:"gap-2 bg-primary font-semibold text-xs h-9",children:[s.jsx(xe,{icon:is,size:15})," Open Ticket"]}),s.jsxs(ue,{onClick:()=>void yt(),disabled:c,variant:"outline",size:"sm",children:[s.jsx(xe,{icon:fr,size:16,className:c?"animate-spin mr-2":"mr-2"}),"Refresh"]})]})]}),s.jsxs("div",{className:"flex flex-col md:flex-row items-center justify-between gap-3 bg-card/60 p-3.5 rounded-xl border border-border/80 shadow-sm",children:[s.jsxs("div",{className:"relative w-full md:w-80",children:[s.jsx(xe,{icon:vi,size:15,className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground"}),s.jsx(_e,{placeholder:"Search tickets by ID, user, subject...",value:N,onChange:Y=>E(Y.target.value),className:"pl-9 text-xs h-9 bg-secondary/30 border-border"})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2.5 w-full md:w-auto justify-end",children:[p&&s.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[s.jsx("span",{className:"text-xs font-semibold text-muted-foreground",children:"Department:"}),s.jsxs(Ca,{value:w,onValueChange:y,children:[s.jsx(Hr,{className:"text-xs h-9 w-[160px] bg-secondary/30 border-border capitalize",children:s.jsx(Sa,{placeholder:"All Departments"})}),s.jsxs(Gr,{children:[s.jsx(Et,{value:"all",children:"All Departments"}),T.map(Y=>s.jsx(Et,{value:Y,className:"capitalize",children:Y},Y))]})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[s.jsx("span",{className:"text-xs font-semibold text-muted-foreground",children:"Priority:"}),s.jsxs(Ca,{value:C,onValueChange:S,children:[s.jsx(Hr,{className:"text-xs h-9 w-[140px] bg-secondary/30 border-border capitalize",children:s.jsx(Sa,{placeholder:"All Priorities"})}),s.jsxs(Gr,{children:[s.jsx(Et,{value:"all",children:"All Priorities"}),s.jsx(Et,{value:"low",children:"Low"}),s.jsx(Et,{value:"medium",children:"Medium / Normal"}),s.jsx(Et,{value:"high",children:"High"}),s.jsx(Et,{value:"urgent",children:"Urgent"})]})]})]}),(w!=="all"||C!=="all"||N.trim())&&s.jsx(ue,{variant:"ghost",size:"sm",onClick:()=>{y("all"),S("all"),E("")},className:"h-9 text-xs text-muted-foreground hover:text-foreground px-2",children:"Reset"})]})]}),s.jsx(Je,{className:"border-border bg-card",children:s.jsx(et,{className:"p-0",children:c?s.jsxs("div",{className:"space-y-4 p-6",children:[s.jsx(Ue,{className:"h-12 w-full"}),s.jsx(Ue,{className:"h-12 w-full"}),s.jsx(Ue,{className:"h-12 w-full"})]}):d?s.jsx("div",{className:"p-6",children:s.jsx(Ye,{variant:"destructive",children:s.jsx(qe,{children:d})})}):M.length===0?s.jsxs("div",{className:"p-12 text-center text-muted-foreground space-y-2",children:[s.jsx("p",{children:"No open tickets found matching your filter criteria."}),(w!=="all"||C!=="all"||N.trim())&&s.jsx(ue,{variant:"outline",size:"sm",onClick:()=>{y("all"),S("all"),E("")},className:"text-xs mt-2",children:"Clear Filters"})]}):s.jsx("div",{className:"divide-y divide-border",children:M.map(Y=>s.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between p-4 hover:bg-secondary/10 transition-colors gap-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[s.jsx("p",{className:"font-medium text-primary",children:Y.subject||"Untitled Ticket"}),s.jsxs("span",{className:"text-xs font-mono text-muted-foreground",children:["#",Y.ticket_id]}),p&&Y.department&&s.jsx(Fn,{variant:"outline",className:"text-xs capitalize",children:Y.department}),s.jsxs(Fn,{variant:Y.priority==="high"?"destructive":Y.priority==="medium"?"secondary":"outline",className:"text-xs capitalize",children:[Y.priority," priority"]})]}),s.jsxs("p",{className:"text-sm text-muted-foreground",children:["User ID: ",s.jsx("span",{className:"font-mono",children:Y.user_id}),Y.description&&` • ${Y.description}`]})]}),s.jsxs("div",{className:"flex items-center gap-3 w-full sm:w-auto justify-end",children:[s.jsxs("div",{className:"text-sm text-muted-foreground flex items-center whitespace-nowrap mr-2",children:[s.jsx(xe,{icon:h8,size:14,className:"mr-1.5"}),Jn(Y.created_at)]}),s.jsxs(ue,{variant:"default",size:"sm",onClick:()=>Wr(Y),className:"bg-primary text-primary-foreground hover:bg-primary/90",children:[s.jsx(xe,{icon:g8,size:16,className:"mr-2"}),"Live Chat"]}),s.jsxs(ue,{variant:"destructive",size:"sm",onClick:()=>Es(Y),disabled:We===Y.ticket_id,children:[We===Y.ticket_id?s.jsx(xe,{icon:fr,size:14,className:"animate-spin mr-1.5"}):s.jsx(xe,{icon:ba,size:14,className:"mr-1.5"}),"Close"]}),a&&s.jsx(ue,{variant:"secondary",size:"sm",asChild:!0,children:s.jsx("a",{href:`https://discord.com/channels/${a}/${Y.ticket_id}`,target:"_blank",rel:"noreferrer",children:s.jsx(xe,{icon:Nd,size:16})})})]})]},Y.ticket_id))})})}),R&&ne&&s.jsx("div",{className:"fixed inset-0 z-50 bg-black/65 backdrop-blur-sm flex items-center justify-center p-4 sm:p-6 lg:p-8 animate-in fade-in-0",onClick:Y=>{Y.target===Y.currentTarget&&X(!1)},children:s.jsxs("div",{className:"bg-card text-card-foreground border border-border rounded-2xl shadow-2xl flex flex-col w-full max-w-5xl h-[88vh] overflow-hidden animate-in zoom-in-95",children:[s.jsxs("div",{className:"p-4 border-b border-border bg-secondary/20 flex flex-col space-y-1",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-2 flex-wrap min-w-0",children:[s.jsx("h2",{className:"text-lg font-bold tracking-tight truncate",children:(k==null?void 0:k.subject)||"Ticket Live Chat"}),s.jsxs(Fn,{variant:"outline",className:"font-mono text-xs shrink-0",children:["#",k==null?void 0:k.ticket_id]}),p&&(k==null?void 0:k.department)&&s.jsx(Fn,{variant:"secondary",className:"text-xs capitalize shrink-0",children:k.department})]}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[k&&s.jsxs(ue,{variant:"destructive",size:"sm",onClick:()=>Es(k),disabled:We===k.ticket_id,className:"h-8 px-2.5 text-xs",children:[We===k.ticket_id?s.jsx(xe,{icon:fr,size:14,className:"animate-spin mr-1.5"}):s.jsx(xe,{icon:ba,size:14,className:"mr-1.5"}),"Close Ticket"]}),s.jsxs(ue,{variant:"outline",size:"sm",onClick:()=>X(!1),className:"h-8 px-3 text-xs flex items-center gap-1.5",children:[s.jsx(xe,{icon:S8,size:14}),s.jsx("span",{children:"Collapse"})]}),s.jsx(ue,{variant:"ghost",size:"icon",onClick:()=>{L(!1),X(!1)},className:"h-8 w-8 text-muted-foreground hover:text-foreground",children:s.jsx(xe,{icon:ba,size:18})})]})]}),(k==null?void 0:k.description)&&s.jsx("p",{className:"text-xs text-muted-foreground truncate",children:k.description})]}),Li(),zi()]})}),R&&!ne&&s.jsx(Yj,{open:R,onOpenChange:L,children:s.jsxs(Hg,{side:"right",className:"w-full sm:max-w-xl p-0 flex flex-col h-full bg-card",children:[s.jsxs(Gg,{className:"p-4 border-b border-border space-y-1 bg-secondary/20",children:[s.jsxs("div",{className:"flex items-center justify-between pr-8",children:[s.jsxs("div",{className:"flex items-center gap-2 flex-wrap min-w-0",children:[s.jsx(Vg,{className:"text-base font-bold truncate",children:(k==null?void 0:k.subject)||"Ticket Live Chat"}),s.jsxs(Fn,{variant:"outline",className:"font-mono text-xs shrink-0",children:["#",k==null?void 0:k.ticket_id]})]}),s.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[k&&s.jsxs(ue,{variant:"destructive",size:"sm",onClick:()=>Es(k),disabled:We===k.ticket_id,className:"h-7 px-2 text-xs",children:[We===k.ticket_id?s.jsx(xe,{icon:fr,size:13,className:"animate-spin mr-1"}):s.jsx(xe,{icon:ba,size:13,className:"mr-1"}),"Close"]}),s.jsxs(ue,{variant:"outline",size:"sm",onClick:()=>X(!0),className:"h-7 px-2 text-xs flex items-center gap-1",title:"Open in Full View",children:[s.jsx(xe,{icon:C8,size:13}),s.jsx("span",{children:"Full View"})]})]})]}),(k==null?void 0:k.description)&&s.jsx(Fg,{className:"text-xs text-muted-foreground truncate",children:k.description})]}),Li(),zi()]})}),s.jsx(Qs,{open:$,onOpenChange:ie,children:s.jsxs(hs,{className:"sm:max-w-md bg-card border-border rounded-xl",children:[s.jsxs(gs,{children:[s.jsxs(xs,{className:"text-lg font-bold flex items-center gap-2",children:[s.jsx(xe,{icon:ba,className:"text-destructive",size:20}),"Close Ticket #",ye==null?void 0:ye.ticket_id]}),s.jsx(bs,{className:"text-xs text-muted-foreground pt-1",children:"Are you sure you want to close this ticket? A transcript will be created and the channel will be deleted in Discord."})]}),s.jsxs("div",{className:"space-y-2 py-2",children:[s.jsx("label",{className:"text-xs font-semibold text-foreground",children:"Reason for closing (Optional)"}),s.jsx(_e,{value:Be,onChange:Y=>Ke(Y.target.value),placeholder:"e.g. Issue resolved by support team",className:"text-sm"})]}),s.jsxs(Js,{className:"gap-2 sm:gap-0 mt-2",children:[s.jsx(ue,{variant:"outline",size:"sm",onClick:()=>ie(!1),disabled:!!We,children:"Cancel"}),s.jsxs(ue,{variant:"destructive",size:"sm",onClick:qr,disabled:!!We,children:[We?s.jsx(xe,{icon:fr,size:14,className:"animate-spin mr-1.5"}):s.jsx(xe,{icon:ba,size:14,className:"mr-1.5"}),"Confirm Close"]})]})]})}),s.jsx(Qs,{open:vn,onOpenChange:Xn,children:s.jsxs(hs,{className:"sm:max-w-[450px]",children:[s.jsxs(gs,{children:[s.jsxs(xs,{className:"text-base flex items-center gap-2",children:[s.jsx(xe,{icon:is,size:18,className:"text-primary"}),"Open Direct Ticket"]}),s.jsx(bs,{className:"text-xs",children:p?"Select a support department to create a new ticket channel in Discord immediately.":"Create a new ticket channel in Discord immediately."})]}),s.jsxs("div",{className:"space-y-4 py-2",children:[p&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx(Ae,{className:"text-xs font-semibold",children:"Department"}),s.jsxs(Ca,{value:br,onValueChange:yn,children:[s.jsx(Hr,{className:"text-xs border-border bg-secondary/30",children:s.jsx(Sa,{})}),s.jsx(Gr,{children:(b.length>0?b:[{id:"general",name:"General Support",emoji:"🎫"},{id:"purchase",name:"Purchase & Billing Support",emoji:"💳"},{id:"reports",name:"Player Report",emoji:"🚨"},{id:"appeals",name:"Ban Appeals",emoji:"⚖️"}]).map(Y=>s.jsxs(Et,{value:Y.id,children:[Y.emoji?`${Y.emoji} `:"",Y.name]},Y.id))})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx(Ae,{className:"text-xs font-semibold",children:"Ticket Subject / Reason"}),s.jsx(_e,{value:wn,onChange:Y=>Zn(Y.target.value),placeholder:"e.g. Assistance with server permissions",className:"text-xs border-border bg-secondary/30"})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx(Ae,{className:"text-xs font-semibold",children:"Discord User ID (Optional)"}),s.jsx(_e,{value:Kt,onChange:Y=>po(Y.target.value),placeholder:"e.g. 123456789012345678 (Leave blank for yourself)",className:"text-xs font-mono border-border bg-secondary/30"}),s.jsx("p",{className:"text-[11px] text-muted-foreground",children:"If specified, the ticket channel will be created for this user."})]})]}),s.jsxs(Js,{className:"gap-2 sm:gap-0",children:[s.jsx(ue,{variant:"outline",size:"sm",onClick:()=>Xn(!1),disabled:Pt,className:"text-xs",children:"Cancel"}),s.jsxs(ue,{size:"sm",onClick:Da,disabled:Pt||!wn.trim(),className:"gap-1.5 text-xs bg-primary font-semibold",children:[Pt?s.jsx(xe,{icon:fr,size:14,className:"animate-spin"}):s.jsx(xe,{icon:is,size:14}),Pt?"Opening Ticket...":"Open Ticket"]})]})]})})]})}const SP=["admin","moderator","editor","viewer","custom"];function NP(){return{mode:"add",id:"",username:"",globalName:"",role:"viewer",enabled:!0,permissions:ls("viewer"),yamlOwner:!1}}function EP({permissions:t,onChange:n,disabled:a}){const o=d=>n({...t,...d}),c=[{key:"overview",title:"Dashboard Overview",description:"Access to system metrics, bot health status, and main dashboard stats."},{key:"tickets",title:"Support Tickets",description:"View open support tickets, live web chat, send staff replies, and close tickets."},{key:"transcripts",title:"Ticket Transcripts",description:"Access saved ticket HTML transcripts and configure public transcript options."},{key:"logs",title:"Console Terminal Logs",description:"View real-time bot terminal output, system logs, and runtime error traces."}],l=[["supportbot","Bot config","Main bot token, prefix, channels, categories, and core settings."],["ticket-panel","Ticket panel","Ticket home embed, button labels, dropdown options, and panel styling."],["commands","Commands","Enable/disable slash commands, descriptions, and custom names."],["messages","Messages","Custom bot response messages, welcome embeds, and embed colors."],["supportbot-ai","AI assistant","Configure AI support rules, model API keys, and auto-response channels."]];return s.jsxs("div",{className:"space-y-6",children:[s.jsxs("div",{className:"space-y-2.5",children:[s.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:"General & Modules Access"}),s.jsx("div",{className:"grid gap-2.5",children:c.map(({key:d,title:m,description:p})=>s.jsxs("label",{className:"flex items-center justify-between gap-4 rounded-xl border border-border bg-secondary/20 p-3 transition-colors hover:bg-secondary/40",children:[s.jsxs("div",{className:"space-y-0.5 min-w-0",children:[s.jsx("p",{className:"text-sm font-semibold text-foreground",children:m}),s.jsx("p",{className:"text-xs text-muted-foreground leading-snug",children:p})]}),s.jsx(Mt,{checked:t[d]??(d==="tickets"?t.overview:!1),disabled:a,onCheckedChange:g=>o({[d]:g}),className:"shrink-0"})]},d))})]}),s.jsxs("div",{className:"space-y-2.5",children:[s.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:"Administration & Settings"}),s.jsxs("div",{className:"grid gap-2.5",children:[s.jsxs("label",{className:"flex items-center justify-between gap-4 rounded-xl border border-border bg-secondary/20 p-3 transition-colors hover:bg-secondary/40",children:[s.jsxs("div",{className:"space-y-0.5 min-w-0",children:[s.jsx("p",{className:"text-sm font-semibold text-foreground",children:"Settings (View)"}),s.jsx("p",{className:"text-xs text-muted-foreground leading-snug",children:"View system branding, OAuth configurations, and system health details."})]}),s.jsx(Mt,{checked:t.settings.view,disabled:a,onCheckedChange:d=>o({settings:{...t.settings,view:d}}),className:"shrink-0"})]}),s.jsxs("label",{className:"flex items-center justify-between gap-4 rounded-xl border border-border bg-secondary/20 p-3 transition-colors hover:bg-secondary/40",children:[s.jsxs("div",{className:"space-y-0.5 min-w-0",children:[s.jsx("p",{className:"text-sm font-semibold text-foreground",children:"Settings (Install Updates)"}),s.jsx("p",{className:"text-xs text-muted-foreground leading-snug",children:"Perform 1-click bot system updates and trigger bot server restarts."})]}),s.jsx(Mt,{checked:t.settings.update,disabled:a,onCheckedChange:d=>o({settings:{...t.settings,update:d}}),className:"shrink-0"})]}),s.jsxs("label",{className:"flex items-center justify-between gap-4 rounded-xl border border-border bg-secondary/20 p-3 transition-colors hover:bg-secondary/40",children:[s.jsxs("div",{className:"space-y-0.5 min-w-0",children:[s.jsx("p",{className:"text-sm font-semibold text-foreground",children:"Users & Groups (View)"}),s.jsx("p",{className:"text-xs text-muted-foreground leading-snug",children:"View dashboard staff accounts and permission group listings."})]}),s.jsx(Mt,{checked:t.users.view,disabled:a,onCheckedChange:d=>o({users:{...t.users,view:d}}),className:"shrink-0"})]}),s.jsxs("label",{className:"flex items-center justify-between gap-4 rounded-xl border border-border bg-secondary/20 p-3 transition-colors hover:bg-secondary/40",children:[s.jsxs("div",{className:"space-y-0.5 min-w-0",children:[s.jsx("p",{className:"text-sm font-semibold text-foreground",children:"Users & Groups (Manage)"}),s.jsx("p",{className:"text-xs text-muted-foreground leading-snug",children:"Create, edit, assign, and delete staff accounts and permission groups."})]}),s.jsx(Mt,{checked:t.users.manage,disabled:a,onCheckedChange:d=>o({users:{...t.users,manage:d}}),className:"shrink-0"})]})]})]}),s.jsxs("div",{className:"space-y-2.5",children:[s.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:"Configuration Files Access"}),s.jsxs("div",{className:"grid gap-2.5",children:[l.map(([d,m,p])=>{var b;const g=((b=t.configs)==null?void 0:b[d])??{view:!1,edit:!1};return s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-3 rounded-xl border border-border bg-secondary/20 p-3 transition-colors hover:bg-secondary/40",children:[s.jsxs("div",{className:"space-y-0.5 min-w-0",children:[s.jsx("p",{className:"text-sm font-semibold text-foreground",children:m}),s.jsx("p",{className:"text-xs text-muted-foreground leading-snug",children:p})]}),s.jsxs("div",{className:"flex items-center gap-4 shrink-0",children:[s.jsxs("label",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground cursor-pointer",children:[s.jsx("span",{children:"View"}),s.jsx(Mt,{checked:g.view,disabled:a,onCheckedChange:v=>o({configs:{...t.configs,[d]:{...g,view:v}}})})]}),s.jsxs("label",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground cursor-pointer",children:[s.jsx("span",{children:"Edit"}),s.jsx(Mt,{checked:g.edit,disabled:a,onCheckedChange:v=>o({configs:{...t.configs,[d]:{...g,edit:v,view:v?!0:g.view}}})})]})]})]},d)}),s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-3 rounded-xl border border-border bg-secondary/20 p-3 transition-colors hover:bg-secondary/40",children:[s.jsxs("div",{className:"space-y-0.5 min-w-0",children:[s.jsx("p",{className:"text-sm font-semibold text-foreground",children:"Raw YAML Code Editor"}),s.jsx("p",{className:"text-xs text-muted-foreground leading-snug",children:"Access the raw YAML code editor tab to view or edit full raw configuration files."})]}),s.jsx("div",{className:"flex items-center gap-4 shrink-0",children:s.jsxs("label",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground cursor-pointer",children:[s.jsx("span",{children:"Access"}),s.jsx(Mt,{checked:t.rawYaml??!1,disabled:a,onCheckedChange:d=>o({rawYaml:d})})]})})]})]})]})]})}function kP(t){return t.permissions.users.manage?"Full + user management":t.permissions.settings.update?"Configs + settings updates":Object.values(t.permissions.configs).some(n=>n.edit)?"Can edit configs":"View only"}function TP(){const{user:t,hasPermission:n}=Yt(),a=n("users.manage"),[o,c]=f.useState([]),[l,d]=f.useState([]),[m,p]=f.useState(!0),[g,b]=f.useState(""),[v,w]=f.useState(null),[y,C]=f.useState(!1),S=f.useCallback(async()=>{p(!0),b("");try{const[R,L]=await Promise.all([Ne.listDashboardUsers(),Ne.listGroups().catch(()=>({data:{groups:[]}}))]);R.data&&c(R.data.users),L.data&&d(L.data.groups)}catch(R){b(R instanceof Error?R.message:"Failed to load users")}finally{p(!1)}},[]);f.useEffect(()=>{S()},[S]);const N=f.useMemo(()=>[...o].sort((R,L)=>R.yamlOwner!==L.yamlOwner?R.yamlOwner?-1:1:(R.username||R.id).localeCompare(L.username||L.id)),[o]);function E(){w(NP())}function T(R){w({mode:"edit",id:R.id,username:R.username||"",globalName:R.globalName||"",role:R.yamlOwner?"owner":R.role,enabled:R.enabled,permissions:R.role==="custom"?R.permissions:ls(R.role),yamlOwner:R.yamlOwner})}function M(R){v&&w({...v,role:R,permissions:ls(R,v.permissions)})}async function k(){if(!(!v||!a)){C(!0),b("");try{v.mode==="add"?await Ne.addDashboardUser({id:v.id.trim(),role:v.role,username:v.username||void 0,globalName:v.globalName||void 0,enabled:v.enabled,permissions:v.role==="custom"?v.permissions:void 0}):await Ne.updateDashboardUser(v.id,{role:v.yamlOwner?void 0:v.role,enabled:v.enabled,username:v.username||void 0,globalName:v.globalName||void 0,permissions:v.role==="custom"?v.permissions:void 0}),w(null),await S()}catch(R){b(R instanceof Error?R.message:"Could not save user")}finally{C(!1)}}}async function _(R){if(a&&window.confirm("Remove this user from the dashboard?")){b("");try{await Ne.removeDashboardUser(R),await S()}catch(L){b(L instanceof Error?L.message:"Could not remove user")}}}return s.jsxs("div",{className:"space-y-6",children:[s.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[s.jsxs("div",{children:[s.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:"Users"}),s.jsxs("p",{className:"text-muted-foreground",children:["Control who can sign in and what they can view or edit. Owners in"," ",s.jsx("code",{className:"rounded bg-primary/10 px-1 text-xs text-primary",children:"api.yml"})," ","always have full access."]})]}),a?s.jsxs(ue,{onClick:E,children:[s.jsx(xe,{icon:sg,size:16,className:"mr-2"}),"Add user"]}):null]}),g?s.jsx(Ye,{variant:"destructive",children:s.jsx(qe,{children:g})}):null,s.jsx(Je,{className:"border-border bg-card overflow-hidden",children:s.jsx(et,{className:"p-0",children:m?s.jsxs("div",{className:"p-4 space-y-2",children:[s.jsx(Ue,{className:"h-8 w-full rounded-md"}),s.jsx(Ue,{className:"h-8 w-full rounded-md"})]}):N.length===0?s.jsx("div",{className:"p-6 text-center text-xs text-muted-foreground",children:"No users found."}):s.jsx("div",{className:"overflow-x-auto",children:s.jsxs("table",{className:"w-full text-left text-xs",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"border-b border-border/80 bg-secondary/30 text-[11px] font-semibold text-muted-foreground uppercase tracking-wider",children:[s.jsx("th",{className:"px-4 py-2.5",children:"User"}),s.jsx("th",{className:"px-4 py-2.5",children:"Group"}),s.jsx("th",{className:"px-4 py-2.5",children:"Access Summary"}),s.jsx("th",{className:"px-4 py-2.5",children:"Status"}),a&&s.jsx("th",{className:"px-4 py-2.5 text-right",children:"Actions"})]})}),s.jsx("tbody",{className:"divide-y divide-border/40",children:N.map(R=>{const L=l.find(I=>I.id===R.groupId||I.id===R.role),ne=(L==null?void 0:L.color)||"#10B981",X=(L==null?void 0:L.name)||$y[R.yamlOwner?"owner":R.role]||R.role;return s.jsxs("tr",{className:"transition-colors hover:bg-secondary/25",children:[s.jsx("td",{className:"px-4 py-2.5 font-medium whitespace-nowrap",children:s.jsxs("div",{className:"flex items-center gap-2.5",children:[s.jsxs(vs,{className:"size-7",children:[s.jsx(eo,{src:R.avatar,alt:R.username}),s.jsx(ys,{className:"text-[10px]",children:(R.username||R.id).slice(0,2).toUpperCase()})]}),s.jsxs("div",{className:"min-w-0 leading-tight",children:[s.jsxs("p",{className:"truncate font-semibold text-foreground text-xs",children:[P2(R),R.id===(t==null?void 0:t.id)?s.jsx("span",{className:"text-[11px] text-primary font-normal ml-1",children:"(you)"}):""]}),s.jsx("p",{className:"truncate text-[10px] text-muted-foreground font-mono",children:R.id})]})]})}),s.jsx("td",{className:"px-4 py-2.5 whitespace-nowrap",children:s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"size-2 rounded-full shrink-0 shadow-sm",style:{backgroundColor:ne}}),s.jsx("span",{className:"font-medium text-xs text-foreground",children:X}),R.yamlOwner&&s.jsx("span",{className:"text-[10px] font-semibold px-1.5 py-0.5 rounded bg-primary/10 text-primary border border-primary/20",children:"Config Owner"})]})}),s.jsx("td",{className:"px-4 py-2.5 text-xs text-muted-foreground max-w-xs truncate",children:kP(R)}),s.jsx("td",{className:"px-4 py-2.5 whitespace-nowrap",children:R.enabled?s.jsx(Fn,{className:"text-[10px] px-2 py-0.5 bg-emerald-500/15 text-emerald-400 hover:bg-emerald-500/15 border-emerald-500/20",children:"Active"}):s.jsx(Fn,{variant:"outline",className:"text-[10px] px-2 py-0.5",children:"Disabled"})}),a&&s.jsx("td",{className:"px-4 py-2.5 text-right whitespace-nowrap",children:s.jsxs("div",{className:"flex items-center justify-end gap-1",children:[s.jsxs(ue,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs gap-1 text-muted-foreground hover:text-foreground",onClick:()=>T(R),children:[s.jsx(xe,{icon:b8,size:13}),"Edit"]}),!R.yamlOwner&&s.jsxs(ue,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs gap-1 text-muted-foreground hover:text-destructive",onClick:()=>_(R.id),children:[s.jsx(xe,{icon:bi,size:13}),"Remove"]})]})})]},R.id)})})]})})})}),s.jsx(Qs,{open:!!v,onOpenChange:R=>!R&&w(null),children:s.jsxs(hs,{className:"max-h-[90vh] max-w-lg overflow-y-auto",children:[s.jsxs(gs,{children:[s.jsx(xs,{children:(v==null?void 0:v.mode)==="add"?"Add dashboard user":"Edit user"}),s.jsx(bs,{children:v!=null&&v.yamlOwner?"This user is an owner in api.yml. Role and removal are managed in the config file.":P8[(v==null?void 0:v.role)??"viewer"]})]}),v?s.jsxs("div",{className:"space-y-4",children:[v.mode==="add"?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{htmlFor:"discord-id",children:"Discord user ID"}),s.jsx(_e,{id:"discord-id",value:v.id,onChange:R=>w({...v,id:R.target.value}),placeholder:"829112572816130058"})]}):null,s.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{children:"Display name (optional)"}),s.jsx(_e,{value:v.globalName,onChange:R=>w({...v,globalName:R.target.value})})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{children:"Username (optional)"}),s.jsx(_e,{value:v.username,onChange:R=>w({...v,username:R.target.value})})]})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{children:"Permission Group"}),s.jsxs(Ca,{value:v.role,disabled:v.yamlOwner,onValueChange:R=>{const L=l.find(ne=>ne.id===R);L?w({...v,role:R,permissions:L.permissions}):M(R)},children:[s.jsx(Hr,{children:s.jsx(Sa,{})}),s.jsx(Gr,{children:v.yamlOwner?s.jsx(Et,{value:"owner",children:"Owner"}):l.length>0?l.map(R=>s.jsx(Et,{value:R.id,children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"size-2.5 rounded-full shrink-0",style:{backgroundColor:R.color||"#10B981"}}),s.jsx("span",{children:R.name})]})},R.id)):SP.map(R=>s.jsx(Et,{value:R,children:$y[R]},R))})]})]}),s.jsxs("label",{className:"flex items-center justify-between rounded-lg border border-border px-3 py-2",children:[s.jsx("span",{className:"text-sm",children:"Account enabled"}),s.jsx(Mt,{checked:v.enabled,disabled:v.yamlOwner,onCheckedChange:R=>w({...v,enabled:R})})]}),v.role==="custom"&&!v.yamlOwner?s.jsx(EP,{permissions:v.permissions,onChange:R=>w({...v,permissions:R})}):null]}):null,s.jsxs(Js,{children:[s.jsx(ue,{variant:"outline",onClick:()=>w(null),children:"Cancel"}),s.jsx(ue,{disabled:y||!a||(v==null?void 0:v.mode)==="add"&&!/^\d{17,20}$/.test(v.id.trim()),onClick:()=>void k(),children:y?"Saving…":"Save"})]})]})})]})}const MP=[{name:"Emerald",hex:"#10B981"},{name:"Blue",hex:"#3B82F6"},{name:"Purple",hex:"#8B5CF6"},{name:"Amber",hex:"#F59E0B"},{name:"Red",hex:"#EF4444"},{name:"Cyan",hex:"#06B6D4"},{name:"Gray",hex:"#6B7280"}];function RP({permissions:t,onChange:n,disabled:a}){const o=d=>n({...t,...d}),c=[{key:"overview",title:"Dashboard Overview",description:"Access to system metrics, bot health status, and main dashboard stats."},{key:"tickets",title:"Support Tickets",description:"View open support tickets, live web chat, send staff replies, and close tickets."},{key:"transcripts",title:"Ticket Transcripts",description:"Access saved ticket HTML transcripts and configure public transcript options."},{key:"logs",title:"Console Terminal Logs",description:"View real-time bot terminal output, system logs, and runtime error traces."}],l=[["supportbot","Bot config","Main bot token, prefix, channels, categories, and core settings."],["ticket-panel","Ticket panel","Ticket home embed, button labels, dropdown options, and panel styling."],["commands","Commands","Enable/disable slash commands, descriptions, and custom names."],["messages","Messages","Custom bot response messages, welcome embeds, and embed colors."],["supportbot-ai","AI assistant","Configure AI support rules, model API keys, and auto-response channels."]];return s.jsxs("div",{className:"space-y-6",children:[s.jsxs("div",{className:"space-y-2.5",children:[s.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:"General & Modules Access"}),s.jsx("div",{className:"grid gap-2.5",children:c.map(({key:d,title:m,description:p})=>s.jsxs("label",{className:"flex items-center justify-between gap-4 rounded-xl border border-border bg-secondary/20 p-3 transition-colors hover:bg-secondary/40",children:[s.jsxs("div",{className:"space-y-0.5 min-w-0",children:[s.jsx("p",{className:"text-sm font-semibold text-foreground",children:m}),s.jsx("p",{className:"text-xs text-muted-foreground leading-snug",children:p})]}),s.jsx(Mt,{checked:t[d]??(d==="tickets"?t.overview:!1),disabled:a,onCheckedChange:g=>o({[d]:g}),className:"shrink-0"})]},d))})]}),s.jsxs("div",{className:"space-y-2.5",children:[s.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:"Administration & Settings"}),s.jsxs("div",{className:"grid gap-2.5",children:[s.jsxs("label",{className:"flex items-center justify-between gap-4 rounded-xl border border-border bg-secondary/20 p-3 transition-colors hover:bg-secondary/40",children:[s.jsxs("div",{className:"space-y-0.5 min-w-0",children:[s.jsx("p",{className:"text-sm font-semibold text-foreground",children:"Settings (View)"}),s.jsx("p",{className:"text-xs text-muted-foreground leading-snug",children:"View system branding, OAuth configurations, and system health details."})]}),s.jsx(Mt,{checked:t.settings.view,disabled:a,onCheckedChange:d=>o({settings:{...t.settings,view:d}}),className:"shrink-0"})]}),s.jsxs("label",{className:"flex items-center justify-between gap-4 rounded-xl border border-border bg-secondary/20 p-3 transition-colors hover:bg-secondary/40",children:[s.jsxs("div",{className:"space-y-0.5 min-w-0",children:[s.jsx("p",{className:"text-sm font-semibold text-foreground",children:"Settings (Install Updates)"}),s.jsx("p",{className:"text-xs text-muted-foreground leading-snug",children:"Perform 1-click bot system updates and trigger bot server restarts."})]}),s.jsx(Mt,{checked:t.settings.update,disabled:a,onCheckedChange:d=>o({settings:{...t.settings,update:d}}),className:"shrink-0"})]}),s.jsxs("label",{className:"flex items-center justify-between gap-4 rounded-xl border border-border bg-secondary/20 p-3 transition-colors hover:bg-secondary/40",children:[s.jsxs("div",{className:"space-y-0.5 min-w-0",children:[s.jsx("p",{className:"text-sm font-semibold text-foreground",children:"Users & Groups (View)"}),s.jsx("p",{className:"text-xs text-muted-foreground leading-snug",children:"View dashboard staff accounts and permission group listings."})]}),s.jsx(Mt,{checked:t.users.view,disabled:a,onCheckedChange:d=>o({users:{...t.users,view:d}}),className:"shrink-0"})]}),s.jsxs("label",{className:"flex items-center justify-between gap-4 rounded-xl border border-border bg-secondary/20 p-3 transition-colors hover:bg-secondary/40",children:[s.jsxs("div",{className:"space-y-0.5 min-w-0",children:[s.jsx("p",{className:"text-sm font-semibold text-foreground",children:"Users & Groups (Manage)"}),s.jsx("p",{className:"text-xs text-muted-foreground leading-snug",children:"Create, edit, assign, and delete staff accounts and permission groups."})]}),s.jsx(Mt,{checked:t.users.manage,disabled:a,onCheckedChange:d=>o({users:{...t.users,manage:d}}),className:"shrink-0"})]})]})]}),s.jsxs("div",{className:"space-y-2.5",children:[s.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:"Configuration Files Access"}),s.jsxs("div",{className:"grid gap-2.5",children:[l.map(([d,m,p])=>{var b;const g=((b=t.configs)==null?void 0:b[d])??{view:!1,edit:!1};return s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-3 rounded-xl border border-border bg-secondary/20 p-3 transition-colors hover:bg-secondary/40",children:[s.jsxs("div",{className:"space-y-0.5 min-w-0",children:[s.jsx("p",{className:"text-sm font-semibold text-foreground",children:m}),s.jsx("p",{className:"text-xs text-muted-foreground leading-snug",children:p})]}),s.jsxs("div",{className:"flex items-center gap-4 shrink-0",children:[s.jsxs("label",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground cursor-pointer",children:[s.jsx("span",{children:"View"}),s.jsx(Mt,{checked:g.view,disabled:a,onCheckedChange:v=>o({configs:{...t.configs,[d]:{...g,view:v}}})})]}),s.jsxs("label",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground cursor-pointer",children:[s.jsx("span",{children:"Edit"}),s.jsx(Mt,{checked:g.edit,disabled:a,onCheckedChange:v=>o({configs:{...t.configs,[d]:{...g,edit:v,view:v?!0:g.view}}})})]})]})]},d)}),s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-3 rounded-xl border border-border bg-secondary/20 p-3 transition-colors hover:bg-secondary/40",children:[s.jsxs("div",{className:"space-y-0.5 min-w-0",children:[s.jsx("p",{className:"text-sm font-semibold text-foreground",children:"Raw YAML Code Editor"}),s.jsx("p",{className:"text-xs text-muted-foreground leading-snug",children:"Access the raw YAML code editor tab to view or edit full raw configuration files."})]}),s.jsx("div",{className:"flex items-center gap-4 shrink-0",children:s.jsxs("label",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground cursor-pointer",children:[s.jsx("span",{children:"Access"}),s.jsx(Mt,{checked:t.rawYaml??!1,disabled:a,onCheckedChange:d=>o({rawYaml:d})})]})})]})]})]})]})}function AP(){const{permissions:t,impersonateGroup:n,impersonatedGroup:a,stopImpersonation:o}=Yt(),c=Rn(t,"users.manage"),[l,d]=f.useState([]),[m,p]=f.useState(!0),[g,b]=f.useState(null),[v,w]=f.useState(null),[y,C]=f.useState(!1),[S,N]=f.useState("add"),[E,T]=f.useState(!1),[M,k]=f.useState(""),[_,R]=f.useState(""),[L,ne]=f.useState(""),[X,I]=f.useState("#10B981"),[H,q]=f.useState(""),[ce,de]=f.useState(ls("viewer")),se=async()=>{var G;p(!0),b(null);try{const O=await Ne.listGroups();d(((G=O.data)==null?void 0:G.groups)||[])}catch(O){b(O instanceof Error?O.message:"Failed to load groups")}finally{p(!1)}};f.useEffect(()=>{se()},[]);const P=()=>{N("add"),k(""),R(""),ne(""),I("#10B981"),q(""),de(ls("viewer")),C(!0)},W=G=>{N("edit"),k(G.id),R(G.name),ne(G.description||""),I(G.color||"#10B981"),q(G.discordRoleId||""),de(G.permissions||ls("viewer")),C(!0)},oe=async()=>{if(!_.trim()){b("Group name is required");return}T(!0),b(null);try{S==="add"?(await Ne.createGroup({name:_.trim(),description:L.trim(),color:X,discordRoleId:H.trim()||null,permissions:ce}),w(`Group "${_}" created successfully.`)):(await Ne.updateGroup(M,{name:_.trim(),description:L.trim(),color:X,discordRoleId:H.trim()||null,permissions:ce}),w(`Group "${_}" updated successfully.`)),C(!1),await se()}catch(G){b(G instanceof Error?G.message:"Failed to save group")}finally{T(!1)}},ae=async G=>{if(!G.isSystem&&confirm(`Are you sure you want to delete the group "${G.name}"?`))try{await Ne.deleteGroup(G.id),w(`Group "${G.name}" deleted.`),await se()}catch(O){b(O instanceof Error?O.message:"Failed to delete group")}};return s.jsxs("div",{className:"space-y-6",children:[s.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[s.jsxs("div",{children:[s.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:"Permission Groups"}),s.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Create custom permission groups, assign staff members, and optionally sync with Discord Role IDs."})]}),c&&s.jsxs(ue,{onClick:P,className:"shrink-0 gap-2 bg-primary",children:[s.jsx(xe,{icon:sg,size:18}),"Create Group"]})]}),g&&s.jsx(Ye,{variant:"destructive",children:s.jsx(qe,{children:g})}),v&&s.jsx(Ye,{className:"border-emerald-500/30 bg-emerald-500/10 text-emerald-500",children:s.jsxs(qe,{className:"flex items-center justify-between",children:[s.jsx("span",{children:v}),s.jsx(ue,{size:"sm",variant:"ghost",className:"h-6 px-2 text-xs",onClick:()=>w(null),children:"Dismiss"})]})}),s.jsx(Je,{className:"border-border bg-card overflow-hidden",children:s.jsx(et,{className:"p-0",children:m?s.jsxs("div",{className:"p-4 space-y-2",children:[s.jsx(Ue,{className:"h-8 w-full rounded-md"}),s.jsx(Ue,{className:"h-8 w-full rounded-md"})]}):l.length===0?s.jsx("div",{className:"p-6 text-center text-xs text-muted-foreground",children:'No permission groups found. Click "Create Group" to add one.'}):s.jsx("div",{className:"overflow-x-auto",children:s.jsxs("table",{className:"w-full text-left text-xs",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"border-b border-border/80 bg-secondary/30 text-[11px] font-semibold text-muted-foreground uppercase tracking-wider",children:[s.jsx("th",{className:"px-4 py-2.5",children:"Group"}),s.jsx("th",{className:"px-4 py-2.5",children:"Description"}),s.jsx("th",{className:"px-4 py-2.5",children:"Discord Role ID"}),s.jsx("th",{className:"px-4 py-2.5",children:"Enabled Permissions"}),s.jsx("th",{className:"px-4 py-2.5 text-right",children:"Actions"})]})}),s.jsx("tbody",{className:"divide-y divide-border/40",children:l.map(G=>{var O,D,B,V,Z,be,K;return s.jsxs("tr",{className:"transition-colors hover:bg-secondary/25",children:[s.jsx("td",{className:"px-4 py-2.5 font-medium whitespace-nowrap",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("div",{className:"size-2.5 rounded-full shrink-0 shadow-sm",style:{backgroundColor:G.color||"#10B981"}}),s.jsx("span",{className:"text-foreground font-semibold text-xs",children:G.name}),G.isSystem&&s.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] font-semibold px-1.5 py-0.5 rounded-full bg-secondary text-secondary-foreground border border-border/80",children:[s.jsx(xe,{icon:qu,size:10}),"System"]})]})}),s.jsx("td",{className:"px-4 py-2.5 text-xs text-muted-foreground max-w-xs truncate",children:G.description||"—"}),s.jsx("td",{className:"px-4 py-2.5 whitespace-nowrap",children:G.discordRoleId?s.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-muted-foreground font-mono bg-secondary/50 px-2 py-0.5 rounded border border-border/50",children:[s.jsx(xe,{icon:qu,size:12,className:"text-primary"}),G.discordRoleId]}):s.jsx("span",{className:"text-xs text-muted-foreground/60",children:"—"})}),s.jsx("td",{className:"px-4 py-2.5",children:s.jsxs("div",{className:"flex flex-wrap gap-1 max-w-md",children:[((O=G.permissions)==null?void 0:O.overview)&&s.jsx("span",{className:"text-[10px] font-medium px-1.5 py-0.5 rounded bg-primary/10 text-primary border border-primary/20",children:"Overview"}),(((D=G.permissions)==null?void 0:D.tickets)??((B=G.permissions)==null?void 0:B.overview))&&s.jsx("span",{className:"text-[10px] font-medium px-1.5 py-0.5 rounded bg-emerald-500/10 text-emerald-400 border border-emerald-500/20",children:"Tickets"}),((V=G.permissions)==null?void 0:V.transcripts)&&s.jsx("span",{className:"text-[10px] font-medium px-1.5 py-0.5 rounded bg-purple-500/10 text-purple-400 border border-purple-500/20",children:"Transcripts"}),((Z=G.permissions)==null?void 0:Z.logs)&&s.jsx("span",{className:"text-[10px] font-medium px-1.5 py-0.5 rounded bg-blue-500/10 text-blue-400 border border-blue-500/20",children:"Logs"}),((K=(be=G.permissions)==null?void 0:be.users)==null?void 0:K.manage)&&s.jsx("span",{className:"text-[10px] font-medium px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/20",children:"User Mgmt"})]})}),s.jsx("td",{className:"px-4 py-2.5 text-right whitespace-nowrap",children:s.jsxs("div",{className:"flex items-center justify-end gap-1",children:[s.jsxs(ue,{size:"sm",variant:"ghost",className:`h-7 px-2 text-xs gap-1 ${(a==null?void 0:a.id)===G.id?"text-amber-400 font-bold bg-amber-500/15 border border-amber-500/30":"text-amber-400 hover:text-amber-300 hover:bg-amber-500/10"}`,onClick:()=>(a==null?void 0:a.id)===G.id?o():n(G.id),children:[s.jsx(xe,{icon:qu,size:13}),(a==null?void 0:a.id)===G.id?"Active Preview":"View as Group"]}),c&&G.id!=="owner"&&s.jsxs(ue,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs gap-1 text-muted-foreground hover:text-foreground",onClick:()=>W(G),children:[s.jsx(xe,{icon:D2,size:13}),"Edit"]}),c&&!G.isSystem&&s.jsxs(ue,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs gap-1 text-muted-foreground hover:text-destructive",onClick:()=>ae(G),children:[s.jsx(xe,{icon:bi,size:13}),"Delete"]})]})})]},G.id)})})]})})})}),s.jsx(Qs,{open:y,onOpenChange:C,children:s.jsxs(hs,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[s.jsxs(gs,{children:[s.jsx(xs,{children:S==="add"?"Create Permission Group":`Edit Group: ${_}`}),s.jsx(bs,{children:"Configure group metadata, custom color badge, Discord role sync, and permission rules."})]}),s.jsxs("div",{className:"space-y-4 py-2",children:[s.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{htmlFor:"group-name",children:"Group Name"}),s.jsx(_e,{id:"group-name",placeholder:"e.g. Support Staff",value:_,onChange:G=>R(G.target.value)})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{htmlFor:"group-color",children:"Color Badge"}),s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(tf,{value:X,onChange:I}),s.jsx(_e,{value:X,onChange:G=>I(G.target.value),placeholder:"#10B981",className:"w-28 font-mono text-sm uppercase"}),s.jsx("div",{className:"flex flex-wrap gap-1 ml-auto",children:MP.map(G=>s.jsx("button",{type:"button",className:"size-6 rounded-full border border-white/20 transition-transform hover:scale-110",style:{backgroundColor:G.hex},onClick:()=>I(G.hex),title:G.name},G.hex))})]})]})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ae,{htmlFor:"group-desc",children:"Description"}),s.jsx(_e,{id:"group-desc",placeholder:"Brief description of what members in this group can access...",value:L,onChange:G=>ne(G.target.value)})]}),s.jsx(TS,{id:"discord-role-id",label:"Discord Role ID (Optional Auto-Sync)",description:"If provided, Discord users with this Role ID will automatically inherit this group upon login.",kind:"role",value:H,onChange:G=>q(String(G??""))}),s.jsxs("div",{className:"pt-2",children:[s.jsx("h4",{className:"text-sm font-semibold mb-3",children:"Group Permission Matrix"}),s.jsx(RP,{permissions:ce,onChange:de})]})]}),s.jsxs(Js,{className:"gap-2 sm:gap-0",children:[s.jsx(ue,{variant:"outline",onClick:()=>C(!1),disabled:E,children:"Cancel"}),s.jsx(ue,{onClick:oe,disabled:E,className:"bg-primary",children:E?"Saving...":S==="add"?"Create Group":"Save Changes"})]})]})})]})}function _P({children:t}){const{isAuthenticated:n,loading:a}=Yt();return a?s.jsx("div",{className:"flex min-h-svh items-center justify-center bg-background text-sm text-muted-foreground",children:"Loading…"}):n?s.jsx(s.Fragment,{children:t}):s.jsx(ya,{to:"/login",replace:!0})}function DP(){const{complete:t,loading:n}=fS(),a=Kn();return n?s.jsx("div",{className:"flex min-h-svh items-center justify-center bg-background text-sm text-muted-foreground",children:"Loading…"}):t?a.pathname==="/setup"?s.jsx(ya,{to:"/login",replace:!0}):s.jsxs(Py,{children:[s.jsx(un,{path:"/login",element:s.jsx(vz,{})}),s.jsxs(un,{element:s.jsx(_P,{children:s.jsx(TA,{})}),children:[s.jsx(un,{index:!0,element:s.jsx(Vz,{})}),s.jsx(un,{path:"system",element:s.jsx(ga,{permission:"overview",children:s.jsx(sP,{})})}),s.jsx(un,{path:"settings",element:s.jsx(ga,{permission:"settings.view",children:s.jsx(nP,{})})}),s.jsx(un,{path:"configs",element:s.jsx(gz,{})}),s.jsx(un,{path:"logs",element:s.jsx(ga,{permission:"logs",children:s.jsx(mP,{})})}),s.jsx(un,{path:"tickets",element:s.jsx(ga,{permission:"transcripts",children:s.jsx(CP,{})})}),s.jsx(un,{path:"transcripts",element:s.jsx(ga,{permission:"transcripts",children:s.jsx(jP,{})})}),s.jsx(un,{path:"users",element:s.jsx(ga,{permission:"users.view",children:s.jsx(TP,{})})}),s.jsx(un,{path:"groups",element:s.jsx(ga,{permission:"users.view",children:s.jsx(AP,{})})}),s.jsx(un,{path:"addons",element:s.jsx(ga,{permission:"settings.view",children:s.jsx(Fz,{})})}),s.jsx(un,{path:"addons/builder",element:s.jsx(ga,{permission:"settings.update",children:s.jsx(Yz,{})})})]}),s.jsx(un,{path:"*",element:s.jsx(ya,{to:"/",replace:!0})})]}):s.jsxs(Py,{children:[s.jsx(un,{path:"/setup",element:s.jsx(Lz,{})}),s.jsx(un,{path:"*",element:s.jsx(ya,{to:"/setup",replace:!0})})]})}function OP({...t}){return s.jsx(KO,{theme:"dark",position:"bottom-right",richColors:!0,closeButton:!0,style:{fontFamily:'"Poppins", system-ui, sans-serif'},toastOptions:{classNames:{toast:"group toast group-[.toaster]:bg-card group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",description:"group-[.toast]:text-muted-foreground"}},...t})}Zz();_3.createRoot(document.getElementById("root")).render(s.jsx(f.StrictMode,{children:s.jsx(a8,{children:s.jsx(aC,{children:s.jsx(B8,{children:s.jsx(MA,{children:s.jsxs(U8,{children:[s.jsx(DP,{}),s.jsx(OP,{})]})})})})})}));