var h3=Object.defineProperty;var g3=(e,n,a)=>n in e?h3(e,n,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[n]=a;var $b=(e,n,a)=>g3(e,typeof n!="symbol"?n+"":n,a);function x3(e,n){for(var a=0;ao[l]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const l of document.querySelectorAll('link[rel="modulepreload"]'))o(l);new MutationObserver(l=>{for(const c of l)if(c.type==="childList")for(const d of c.addedNodes)d.tagName==="LINK"&&d.rel==="modulepreload"&&o(d)}).observe(document,{childList:!0,subtree:!0});function a(l){const c={};return l.integrity&&(c.integrity=l.integrity),l.referrerPolicy&&(c.referrerPolicy=l.referrerPolicy),l.crossOrigin==="use-credentials"?c.credentials="include":l.crossOrigin==="anonymous"?c.credentials="omit":c.credentials="same-origin",c}function o(l){if(l.ep)return;l.ep=!0;const c=a(l);fetch(l.href,c)}})();function A0(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Jm={exports:{}},Fi={};/** * @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 Bb;function v3(){if(Bb)return Fi;Bb=1;var e=Symbol.for("react.transitional.element"),n=Symbol.for("react.fragment");function a(o,l,c){var d=null;if(c!==void 0&&(d=""+c),l.key!==void 0&&(d=""+l.key),"key"in l){c={};for(var m in l)m!=="key"&&(c[m]=l[m])}else c=l;return l=c.ref,{$$typeof:e,type:o,key:d,ref:l!==void 0?l:null,props:c}}return Fi.Fragment=n,Fi.jsx=a,Fi.jsxs=a,Fi}var Ub;function b3(){return Ub||(Ub=1,Jm.exports=v3()),Jm.exports}var s=b3(),ep={exports:{}},Pe={};/** * @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 Hb;function y3(){if(Hb)return Pe;Hb=1;var e=Symbol.for("react.transitional.element"),n=Symbol.for("react.portal"),a=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),l=Symbol.for("react.profiler"),c=Symbol.for("react.consumer"),d=Symbol.for("react.context"),m=Symbol.for("react.forward_ref"),p=Symbol.for("react.suspense"),h=Symbol.for("react.memo"),b=Symbol.for("react.lazy"),g=Symbol.for("react.activity"),y=Symbol.iterator;function w(_){return _===null||typeof _!="object"?null:(_=y&&_[y]||_["@@iterator"],typeof _=="function"?_:null)}var j={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},S=Object.assign,E={};function N(_,D,G){this.props=_,this.context=D,this.refs=E,this.updater=G||j}N.prototype.isReactComponent={},N.prototype.setState=function(_,D){if(typeof _!="object"&&typeof _!="function"&&_!=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,_,D,"setState")},N.prototype.forceUpdate=function(_){this.updater.enqueueForceUpdate(this,_,"forceUpdate")};function k(){}k.prototype=N.prototype;function T(_,D,G){this.props=_,this.context=D,this.refs=E,this.updater=G||j}var A=T.prototype=new k;A.constructor=T,S(A,N.prototype),A.isPureReactComponent=!0;var O=Array.isArray;function M(){}var z={H:null,A:null,T:null,S:null},B=Object.prototype.hasOwnProperty;function K(_,D,G){var V=G.ref;return{$$typeof:e,type:_,key:D,ref:V!==void 0?V:null,props:G}}function U(_,D){return K(_.type,D,_.props)}function q(_){return typeof _=="object"&&_!==null&&_.$$typeof===e}function ue(_){var D={"=":"=0",":":"=2"};return"$"+_.replace(/[=:]/g,function(G){return D[G]})}var pe=/\/+/g;function xe(_,D){return typeof _=="object"&&_!==null&&_.key!=null?ue(""+_.key):D.toString(36)}function se(_){switch(_.status){case"fulfilled":return _.value;case"rejected":throw _.reason;default:switch(typeof _.status=="string"?_.then(M,M):(_.status="pending",_.then(function(D){_.status==="pending"&&(_.status="fulfilled",_.value=D)},function(D){_.status==="pending"&&(_.status="rejected",_.reason=D)})),_.status){case"fulfilled":return _.value;case"rejected":throw _.reason}}throw _}function L(_,D,G,V,F){var oe=typeof _;(oe==="undefined"||oe==="boolean")&&(_=null);var ae=!1;if(_===null)ae=!0;else switch(oe){case"bigint":case"string":case"number":ae=!0;break;case"object":switch(_.$$typeof){case e:case n:ae=!0;break;case b:return ae=_._init,L(ae(_._payload),D,G,V,F)}}if(ae)return F=F(_),ae=V===""?"."+xe(_,0):V,O(F)?(G="",ae!=null&&(G=ae.replace(pe,"$&/")+"/"),L(F,D,G,"",function(Y){return Y})):F!=null&&(q(F)&&(F=U(F,G+(F.key==null||_&&_.key===F.key?"":(""+F.key).replace(pe,"$&/")+"/")+ae)),D.push(F)),1;ae=0;var be=V===""?".":V+":";if(O(_))for(var ve=0;ve<_.length;ve++)V=_[ve],oe=be+xe(V,ve),ae+=L(V,D,G,oe,F);else if(ve=w(_),typeof ve=="function")for(_=ve.call(_),ve=0;!(V=_.next()).done;)V=V.value,oe=be+xe(V,ve++),ae+=L(V,D,G,oe,F);else if(oe==="object"){if(typeof _.then=="function")return L(se(_),D,G,V,F);throw D=String(_),Error("Objects are not valid as a React child (found: "+(D==="[object Object]"?"object with keys {"+Object.keys(_).join(", ")+"}":D)+"). If you meant to render a collection of children, use an array instead.")}return ae}function I(_,D,G){if(_==null)return _;var V=[],F=0;return L(_,V,"","",function(oe){return D.call(G,oe,F++)}),V}function H(_){if(_._status===-1){var D=_._result;D=D(),D.then(function(G){(_._status===0||_._status===-1)&&(_._status=1,_._result=G)},function(G){(_._status===0||_._status===-1)&&(_._status=2,_._result=G)}),_._status===-1&&(_._status=0,_._result=D)}if(_._status===1)return _._result.default;throw _._result}var Z=typeof reportError=="function"?reportError:function(_){if(typeof window=="object"&&typeof window.ErrorEvent=="function"){var D=new window.ErrorEvent("error",{bubbles:!0,cancelable:!0,message:typeof _=="object"&&_!==null&&typeof _.message=="string"?String(_.message):String(_),error:_});if(!window.dispatchEvent(D))return}else if(typeof process=="object"&&typeof process.emit=="function"){process.emit("uncaughtException",_);return}console.error(_)},te={map:I,forEach:function(_,D,G){I(_,function(){D.apply(this,arguments)},G)},count:function(_){var D=0;return I(_,function(){D++}),D},toArray:function(_){return I(_,function(D){return D})||[]},only:function(_){if(!q(_))throw Error("React.Children.only expected to receive a single React element child.");return _}};return Pe.Activity=g,Pe.Children=te,Pe.Component=N,Pe.Fragment=a,Pe.Profiler=l,Pe.PureComponent=T,Pe.StrictMode=o,Pe.Suspense=p,Pe.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=z,Pe.__COMPILER_RUNTIME={__proto__:null,c:function(_){return z.H.useMemoCache(_)}},Pe.cache=function(_){return function(){return _.apply(null,arguments)}},Pe.cacheSignal=function(){return null},Pe.cloneElement=function(_,D,G){if(_==null)throw Error("The argument must be a React element, but you passed "+_+".");var V=S({},_.props),F=_.key;if(D!=null)for(oe in D.key!==void 0&&(F=""+D.key),D)!B.call(D,oe)||oe==="key"||oe==="__self"||oe==="__source"||oe==="ref"&&D.ref===void 0||(V[oe]=D[oe]);var oe=arguments.length-2;if(oe===1)V.children=G;else if(1>>1,te=L[Z];if(0>>1;Z<_;){var D=2*(Z+1)-1,G=L[D],V=D+1,F=L[V];if(0>l(G,H))Vl(F,G)?(L[Z]=F,L[V]=H,Z=V):(L[Z]=G,L[D]=H,Z=D);else if(Vl(F,H))L[Z]=F,L[V]=H,Z=V;else break e}}return I}function l(L,I){var H=L.sortIndex-I.sortIndex;return H!==0?H:L.id-I.id}if(e.unstable_now=void 0,typeof performance=="object"&&typeof performance.now=="function"){var c=performance;e.unstable_now=function(){return c.now()}}else{var d=Date,m=d.now();e.unstable_now=function(){return d.now()-m}}var p=[],h=[],b=1,g=null,y=3,w=!1,j=!1,S=!1,E=!1,N=typeof setTimeout=="function"?setTimeout:null,k=typeof clearTimeout=="function"?clearTimeout:null,T=typeof setImmediate<"u"?setImmediate:null;function A(L){for(var I=a(h);I!==null;){if(I.callback===null)o(h);else if(I.startTime<=L)o(h),I.sortIndex=I.expirationTime,n(p,I);else break;I=a(h)}}function O(L){if(S=!1,A(L),!j)if(a(p)!==null)j=!0,M||(M=!0,ue());else{var I=a(h);I!==null&&se(O,I.startTime-L)}}var M=!1,z=-1,B=5,K=-1;function U(){return E?!0:!(e.unstable_now()-KL&&U());){var Z=g.callback;if(typeof Z=="function"){g.callback=null,y=g.priorityLevel;var te=Z(g.expirationTime<=L);if(L=e.unstable_now(),typeof te=="function"){g.callback=te,A(L),I=!0;break t}g===a(p)&&o(p),A(L)}else o(p);g=a(p)}if(g!==null)I=!0;else{var _=a(h);_!==null&&se(O,_.startTime-L),I=!1}}break e}finally{g=null,y=H,w=!1}I=void 0}}finally{I?ue():M=!1}}}var ue;if(typeof T=="function")ue=function(){T(q)};else if(typeof MessageChannel<"u"){var pe=new MessageChannel,xe=pe.port2;pe.port1.onmessage=q,ue=function(){xe.postMessage(null)}}else ue=function(){N(q,0)};function se(L,I){z=N(function(){L(e.unstable_now())},I)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(L){L.callback=null},e.unstable_forceFrameRate=function(L){0>L||125Z?(L.sortIndex=H,n(h,L),a(p)===null&&L===a(h)&&(S?(k(z),z=-1):S=!0,se(O,H-Z))):(L.sortIndex=te,n(p,L),j||w||(j=!0,M||(M=!0,ue()))),L},e.unstable_shouldYield=U,e.unstable_wrapCallback=function(L){var I=y;return function(){var H=y;y=I;try{return L.apply(this,arguments)}finally{y=H}}}})(rp)),rp}var Fb;function C3(){return Fb||(Fb=1,np.exports=w3()),np.exports}var ap={exports:{}},ln={};/** * @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 Wb;function S3(){if(Wb)return ln;Wb=1;var e=Ku();function n(p){var h="https://react.dev/errors/"+p;if(1"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(e)}catch(n){console.error(n)}}return e(),ap.exports=S3(),ap.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 qb;function j3(){if(qb)return Wi;qb=1;var e=C3(),n=Ku(),a=M0();function o(t){var r="https://react.dev/errors/"+t;if(1te||(t.current=Z[te],Z[te]=null,te--)}function G(t,r){te++,Z[te]=t.current,t.current=r}var V=_(null),F=_(null),oe=_(null),ae=_(null);function be(t,r){switch(G(oe,r),G(F,t),G(V,null),r.nodeType){case 9:case 11:t=(t=r.documentElement)&&(t=t.namespaceURI)?lb(t):0;break;default:if(t=r.tagName,r=r.namespaceURI)r=lb(r),t=cb(r,t);else switch(t){case"svg":t=1;break;case"math":t=2;break;default:t=0}}D(V),G(V,t)}function ve(){D(V),D(F),D(oe)}function Y(t){t.memoizedState!==null&&G(ae,t);var r=V.current,i=cb(r,t.type);r!==i&&(G(F,t),G(V,i))}function le(t){F.current===t&&(D(V),D(F)),ae.current===t&&(D(ae),Ui._currentValue=H)}var ye,Te;function Le(t){if(ye===void 0)try{throw Error()}catch(i){var r=i.stack.trim().match(/\n( *(at )?)/);ye=r&&r[1]||"",Te=-1)":-1x||P[u]!==Q[x]){var ie=` `+P[u].replace(" at new "," at ");return t.displayName&&ie.includes("")&&(ie=ie.replace("",t.displayName)),ie}while(1<=u&&0<=x);break}}}finally{rt=!1,Error.prepareStackTrace=i}return(i=t?t.displayName||t.name:"")?Le(i):""}function Mt(t,r){switch(t.tag){case 26:case 27:case 5:return Le(t.type);case 16:return Le("Lazy");case 13:return t.child!==r&&r!==null?Le("Suspense Fallback"):Le("Suspense");case 19:return Le("SuspenseList");case 0:case 15:return ht(t.type,!1);case 11:return ht(t.type.render,!1);case 1:return ht(t.type,!0);case 31:return Le("Activity");default:return""}}function Tr(t){try{var r="",i=null;do r+=Mt(t,i),i=t,t=t.return;while(t);return r}catch(u){return` Error generating stack: `+u.message+` `+u.stack}}var _t=Object.prototype.hasOwnProperty,Ya=e.unstable_scheduleCallback,qa=e.unstable_cancelCallback,qt=e.unstable_shouldYield,dr=e.unstable_requestPaint,Kt=e.unstable_now,ti=e.unstable_getCurrentPriorityLevel,fr=e.unstable_ImmediatePriority,Lo=e.unstable_UserBlockingPriority,Rr=e.unstable_NormalPriority,Xt=e.unstable_LowPriority,Qn=e.unstable_IdlePriority,zo=e.log,mr=e.unstable_setDisableYieldValue,pr=null,Ht=null;function ee(t){if(typeof zo=="function"&&mr(t),Ht&&typeof Ht.setStrictMode=="function")try{Ht.setStrictMode(pr,t)}catch{}}var re=Math.clz32?Math.clz32:De,ke=Math.log,we=Math.LN2;function De(t){return t>>>=0,t===0?32:31-(ke(t)/we|0)|0}var at=256,ct=262144,mt=4194304;function Zt(t){var r=t&42;if(r!==0)return r;switch(t&-t){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:return 64;case 128:return 128;case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:return t&261888;case 262144:case 524288:case 1048576:case 2097152:return t&3932160;case 4194304:case 8388608:case 16777216:case 33554432:return t&62914560;case 67108864:return 67108864;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 0;default:return t}}function Me(t,r,i){var u=t.pendingLanes;if(u===0)return 0;var x=0,v=t.suspendedLanes,C=t.pingedLanes;t=t.warmLanes;var R=u&134217727;return R!==0?(u=R&~v,u!==0?x=Zt(u):(C&=R,C!==0?x=Zt(C):i||(i=R&~t,i!==0&&(x=Zt(i))))):(R=u&~v,R!==0?x=Zt(R):C!==0?x=Zt(C):i||(i=u&~t,i!==0&&(x=Zt(i)))),x===0?0:r!==0&&r!==x&&(r&v)===0&&(v=x&-x,i=r&-r,v>=i||v===32&&(i&4194048)!==0)?r:x}function Je(t,r){return(t.pendingLanes&~(t.suspendedLanes&~t.pingedLanes)&r)===0}function St(t,r){switch(t){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 kt(){var t=mt;return mt<<=1,(mt&62914560)===0&&(mt=4194304),t}function Jn(t){for(var r=[],i=0;31>i;i++)r.push(t);return r}function wt(t,r){t.pendingLanes|=r,r!==268435456&&(t.suspendedLanes=0,t.pingedLanes=0,t.warmLanes=0)}function dn(t,r,i,u,x,v){var C=t.pendingLanes;t.pendingLanes=i,t.suspendedLanes=0,t.pingedLanes=0,t.warmLanes=0,t.expiredLanes&=i,t.entangledLanes&=i,t.errorRecoveryDisabledLanes&=i,t.shellSuspendCounter=0;var R=t.entanglements,P=t.expirationTimes,Q=t.hiddenUpdates;for(i=C&~i;0"u")return null;try{return t.activeElement||t.body}catch{return t.body}}var cN=/[\n"\\]/g;function $n(t){return t.replace(cN,function(r){return"\\"+r.charCodeAt(0).toString(16)+" "})}function Wd(t,r,i,u,x,v,C,R){t.name="",C!=null&&typeof C!="function"&&typeof C!="symbol"&&typeof C!="boolean"?t.type=C:t.removeAttribute("type"),r!=null?C==="number"?(r===0&&t.value===""||t.value!=r)&&(t.value=""+In(r)):t.value!==""+In(r)&&(t.value=""+In(r)):C!=="submit"&&C!=="reset"||t.removeAttribute("value"),r!=null?Yd(t,C,In(r)):i!=null?Yd(t,C,In(i)):u!=null&&t.removeAttribute("value"),x==null&&v!=null&&(t.defaultChecked=!!v),x!=null&&(t.checked=x&&typeof x!="function"&&typeof x!="symbol"),R!=null&&typeof R!="function"&&typeof R!="symbol"&&typeof R!="boolean"?t.name=""+In(R):t.removeAttribute("name")}function nx(t,r,i,u,x,v,C,R){if(v!=null&&typeof v!="function"&&typeof v!="symbol"&&typeof v!="boolean"&&(t.type=v),r!=null||i!=null){if(!(v!=="submit"&&v!=="reset"||r!=null)){Fd(t);return}i=i!=null?""+In(i):"",r=r!=null?""+In(r):i,R||r===t.value||(t.value=r),t.defaultValue=r}u=u??x,u=typeof u!="function"&&typeof u!="symbol"&&!!u,t.checked=R?t.checked:!!u,t.defaultChecked=!!u,C!=null&&typeof C!="function"&&typeof C!="symbol"&&typeof C!="boolean"&&(t.name=C),Fd(t)}function Yd(t,r,i){r==="number"&&Gl(t.ownerDocument)===t||t.defaultValue===""+i||(t.defaultValue=""+i)}function Vo(t,r,i,u){if(t=t.options,r){r={};for(var x=0;x"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),Qd=!1;if(_r)try{var oi={};Object.defineProperty(oi,"passive",{get:function(){Qd=!0}}),window.addEventListener("test",oi,oi),window.removeEventListener("test",oi,oi)}catch{Qd=!1}var ia=null,Jd=null,Wl=null;function cx(){if(Wl)return Wl;var t,r=Jd,i=r.length,u,x="value"in ia?ia.value:ia.textContent,v=x.length;for(t=0;t=li),hx=" ",gx=!1;function xx(t,r){switch(t){case"keyup":return PN.indexOf(r.keyCode)!==-1;case"keydown":return r.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function vx(t){return t=t.detail,typeof t=="object"&&"data"in t?t.data:null}var Yo=!1;function $N(t,r){switch(t){case"compositionend":return vx(r);case"keypress":return r.which!==32?null:(gx=!0,hx);case"textInput":return t=r.data,t===hx&&gx?null:t;default:return null}}function BN(t,r){if(Yo)return t==="compositionend"||!af&&xx(t,r)?(t=cx(),Wl=Jd=ia=null,Yo=!1,t):null;switch(t){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-t};t=u}e:{for(;i;){if(i.nextSibling){i=i.nextSibling;break e}i=i.parentNode}i=void 0}i=Ex(i)}}function Tx(t,r){return t&&r?t===r?!0:t&&t.nodeType===3?!1:r&&r.nodeType===3?Tx(t,r.parentNode):"contains"in t?t.contains(r):t.compareDocumentPosition?!!(t.compareDocumentPosition(r)&16):!1:!1}function Rx(t){t=t!=null&&t.ownerDocument!=null&&t.ownerDocument.defaultView!=null?t.ownerDocument.defaultView:window;for(var r=Gl(t.document);r instanceof t.HTMLIFrameElement;){try{var i=typeof r.contentWindow.location.href=="string"}catch{i=!1}if(i)t=r.contentWindow;else break;r=Gl(t.document)}return r}function lf(t){var r=t&&t.nodeName&&t.nodeName.toLowerCase();return r&&(r==="input"&&(t.type==="text"||t.type==="search"||t.type==="tel"||t.type==="url"||t.type==="password")||r==="textarea"||t.contentEditable==="true")}var qN=_r&&"documentMode"in document&&11>=document.documentMode,qo=null,cf=null,fi=null,uf=!1;function Ax(t,r,i){var u=i.window===i?i.document:i.nodeType===9?i:i.ownerDocument;uf||qo==null||qo!==Gl(u)||(u=qo,"selectionStart"in u&&lf(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&&di(fi,u)||(fi=u,u=$c(cf,"onSelect"),0>=C,x-=C,hr=1<<32-re(r)+x|i<Ue?(Ke=Re,Re=null):Ke=Re.sibling;var tt=J(W,Re,X[Ue],ce);if(tt===null){Re===null&&(Re=Ke);break}t&&Re&&tt.alternate===null&&r(W,Re),$=v(tt,$,Ue),et===null?_e=tt:et.sibling=tt,et=tt,Re=Ke}if(Ue===X.length)return i(W,Re),Qe&&Dr(W,Ue),_e;if(Re===null){for(;UeUe?(Ke=Re,Re=null):Ke=Re.sibling;var Ra=J(W,Re,tt.value,ce);if(Ra===null){Re===null&&(Re=Ke);break}t&&Re&&Ra.alternate===null&&r(W,Re),$=v(Ra,$,Ue),et===null?_e=Ra:et.sibling=Ra,et=Ra,Re=Ke}if(tt.done)return i(W,Re),Qe&&Dr(W,Ue),_e;if(Re===null){for(;!tt.done;Ue++,tt=X.next())tt=de(W,tt.value,ce),tt!==null&&($=v(tt,$,Ue),et===null?_e=tt:et.sibling=tt,et=tt);return Qe&&Dr(W,Ue),_e}for(Re=u(Re);!tt.done;Ue++,tt=X.next())tt=ne(Re,W,Ue,tt.value,ce),tt!==null&&(t&&tt.alternate!==null&&Re.delete(tt.key===null?Ue:tt.key),$=v(tt,$,Ue),et===null?_e=tt:et.sibling=tt,et=tt);return t&&Re.forEach(function(p3){return r(W,p3)}),Qe&&Dr(W,Ue),_e}function ft(W,$,X,ce){if(typeof X=="object"&&X!==null&&X.type===S&&X.key===null&&(X=X.props.children),typeof X=="object"&&X!==null){switch(X.$$typeof){case w:e:{for(var _e=X.key;$!==null;){if($.key===_e){if(_e=X.type,_e===S){if($.tag===7){i(W,$.sibling),ce=x($,X.props.children),ce.return=W,W=ce;break e}}else if($.elementType===_e||typeof _e=="object"&&_e!==null&&_e.$$typeof===B&&so(_e)===$.type){i(W,$.sibling),ce=x($,X.props),vi(ce,X),ce.return=W,W=ce;break e}i(W,$);break}else r(W,$);$=$.sibling}X.type===S?(ce=to(X.props.children,W.mode,ce,X.key),ce.return=W,W=ce):(ce=nc(X.type,X.key,X.props,null,W.mode,ce),vi(ce,X),ce.return=W,W=ce)}return C(W);case j:e:{for(_e=X.key;$!==null;){if($.key===_e)if($.tag===4&&$.stateNode.containerInfo===X.containerInfo&&$.stateNode.implementation===X.implementation){i(W,$.sibling),ce=x($,X.children||[]),ce.return=W,W=ce;break e}else{i(W,$);break}else r(W,$);$=$.sibling}ce=xf(X,W.mode,ce),ce.return=W,W=ce}return C(W);case B:return X=so(X),ft(W,$,X,ce)}if(se(X))return Ne(W,$,X,ce);if(ue(X)){if(_e=ue(X),typeof _e!="function")throw Error(o(150));return X=_e.call(X),Oe(W,$,X,ce)}if(typeof X.then=="function")return ft(W,$,cc(X),ce);if(X.$$typeof===T)return ft(W,$,oc(W,X),ce);uc(W,X)}return typeof X=="string"&&X!==""||typeof X=="number"||typeof X=="bigint"?(X=""+X,$!==null&&$.tag===6?(i(W,$.sibling),ce=x($,X),ce.return=W,W=ce):(i(W,$),ce=gf(X,W.mode,ce),ce.return=W,W=ce),C(W)):i(W,$)}return function(W,$,X,ce){try{xi=0;var _e=ft(W,$,X,ce);return os=null,_e}catch(Re){if(Re===as||Re===ic)throw Re;var et=jn(29,Re,null,W.mode);return et.lanes=ce,et.return=W,et}finally{}}}var lo=Jx(!0),ev=Jx(!1),fa=!1;function Rf(t){t.updateQueue={baseState:t.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,lanes:0,hiddenCallbacks:null},callbacks:null}}function Af(t,r){t=t.updateQueue,r.updateQueue===t&&(r.updateQueue={baseState:t.baseState,firstBaseUpdate:t.firstBaseUpdate,lastBaseUpdate:t.lastBaseUpdate,shared:t.shared,callbacks:null})}function ma(t){return{lane:t,tag:0,payload:null,callback:null,next:null}}function pa(t,r,i){var u=t.updateQueue;if(u===null)return null;if(u=u.shared,(nt&2)!==0){var x=u.pending;return x===null?r.next=r:(r.next=x.next,x.next=r),u.pending=r,r=tc(t),Px(t,null,i),r}return ec(t,u,r,i),tc(t)}function bi(t,r,i){if(r=r.updateQueue,r!==null&&(r=r.shared,(i&4194048)!==0)){var u=r.lanes;u&=t.pendingLanes,i|=u,r.lanes=i,fn(t,i)}}function Mf(t,r){var i=t.updateQueue,u=t.alternate;if(u!==null&&(u=u.updateQueue,i===u)){var x=null,v=null;if(i=i.firstBaseUpdate,i!==null){do{var C={lane:i.lane,tag:i.tag,payload:i.payload,callback:null,next:null};v===null?x=v=C:v=v.next=C,i=i.next}while(i!==null);v===null?x=v=r:v=v.next=r}else x=v=r;i={baseState:u.baseState,firstBaseUpdate:x,lastBaseUpdate:v,shared:u.shared,callbacks:u.callbacks},t.updateQueue=i;return}t=i.lastBaseUpdate,t===null?i.firstBaseUpdate=r:t.next=r,i.lastBaseUpdate=r}var _f=!1;function yi(){if(_f){var t=rs;if(t!==null)throw t}}function wi(t,r,i,u){_f=!1;var x=t.updateQueue;fa=!1;var v=x.firstBaseUpdate,C=x.lastBaseUpdate,R=x.shared.pending;if(R!==null){x.shared.pending=null;var P=R,Q=P.next;P.next=null,C===null?v=Q:C.next=Q,C=P;var ie=t.alternate;ie!==null&&(ie=ie.updateQueue,R=ie.lastBaseUpdate,R!==C&&(R===null?ie.firstBaseUpdate=Q:R.next=Q,ie.lastBaseUpdate=P))}if(v!==null){var de=x.baseState;C=0,ie=Q=P=null,R=v;do{var J=R.lane&-536870913,ne=J!==R.lane;if(ne?(qe&J)===J:(u&J)===J){J!==0&&J===ns&&(_f=!0),ie!==null&&(ie=ie.next={lane:0,tag:R.tag,payload:R.payload,callback:null,next:null});e:{var Ne=t,Oe=R;J=r;var ft=i;switch(Oe.tag){case 1:if(Ne=Oe.payload,typeof Ne=="function"){de=Ne.call(ft,de,J);break e}de=Ne;break e;case 3:Ne.flags=Ne.flags&-65537|128;case 0:if(Ne=Oe.payload,J=typeof Ne=="function"?Ne.call(ft,de,J):Ne,J==null)break e;de=g({},de,J);break e;case 2:fa=!0}}J=R.callback,J!==null&&(t.flags|=64,ne&&(t.flags|=8192),ne=x.callbacks,ne===null?x.callbacks=[J]:ne.push(J))}else ne={lane:J,tag:R.tag,payload:R.payload,callback:R.callback,next:null},ie===null?(Q=ie=ne,P=de):ie=ie.next=ne,C|=J;if(R=R.next,R===null){if(R=x.shared.pending,R===null)break;ne=R,R=ne.next,ne.next=null,x.lastBaseUpdate=ne,x.shared.pending=null}}while(!0);ie===null&&(P=de),x.baseState=P,x.firstBaseUpdate=Q,x.lastBaseUpdate=ie,v===null&&(x.shared.lanes=0),ba|=C,t.lanes=C,t.memoizedState=de}}function tv(t,r){if(typeof t!="function")throw Error(o(191,t));t.call(r)}function nv(t,r){var i=t.callbacks;if(i!==null)for(t.callbacks=null,t=0;tv?v:8;var C=L.T,R={};L.T=R,Zf(t,!1,r,i);try{var P=x(),Q=L.S;if(Q!==null&&Q(R,P),P!==null&&typeof P=="object"&&typeof P.then=="function"){var ie=r4(P,u);ji(t,r,ie,Rn(t))}else ji(t,r,u,Rn(t))}catch(de){ji(t,r,{then:function(){},status:"rejected",reason:de},Rn())}finally{I.p=v,C!==null&&R.types!==null&&(C.types=R.types),L.T=C}}function c4(){}function Kf(t,r,i,u){if(t.tag!==5)throw Error(o(476));var x=Dv(t).queue;Ov(t,x,r,H,i===null?c4:function(){return Lv(t),i(u)})}function Dv(t){var r=t.memoizedState;if(r!==null)return r;r={memoizedState:H,baseState:H,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:Ir,lastRenderedState:H},next:null};var i={};return r.next={memoizedState:i,baseState:i,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:Ir,lastRenderedState:i},next:null},t.memoizedState=r,t=t.alternate,t!==null&&(t.memoizedState=r),r}function Lv(t){var r=Dv(t);r.next===null&&(r=t.alternate.memoizedState),ji(t,r.next.queue,{},Rn())}function Xf(){return en(Ui)}function zv(){return Rt().memoizedState}function Pv(){return Rt().memoizedState}function u4(t){for(var r=t.return;r!==null;){switch(r.tag){case 24:case 3:var i=Rn();t=ma(i);var u=pa(r,t,i);u!==null&&(yn(u,r,i),bi(u,r,i)),r={cache:Nf()},t.payload=r;return}r=r.return}}function d4(t,r,i){var u=Rn();i={lane:u,revertLane:0,gesture:null,action:i,hasEagerState:!1,eagerState:null,next:null},yc(t)?$v(r,i):(i=pf(t,r,i,u),i!==null&&(yn(i,t,u),Bv(i,r,u)))}function Iv(t,r,i){var u=Rn();ji(t,r,i,u)}function ji(t,r,i,u){var x={lane:u,revertLane:0,gesture:null,action:i,hasEagerState:!1,eagerState:null,next:null};if(yc(t))$v(r,x);else{var v=t.alternate;if(t.lanes===0&&(v===null||v.lanes===0)&&(v=r.lastRenderedReducer,v!==null))try{var C=r.lastRenderedState,R=v(C,i);if(x.hasEagerState=!0,x.eagerState=R,Sn(R,C))return ec(t,r,x,0),pt===null&&Jl(),!1}catch{}finally{}if(i=pf(t,r,x,u),i!==null)return yn(i,t,u),Bv(i,r,u),!0}return!1}function Zf(t,r,i,u){if(u={lane:2,revertLane:Rm(),gesture:null,action:u,hasEagerState:!1,eagerState:null,next:null},yc(t)){if(r)throw Error(o(479))}else r=pf(t,i,u,2),r!==null&&yn(r,t,2)}function yc(t){var r=t.alternate;return t===$e||r!==null&&r===$e}function $v(t,r){is=mc=!0;var i=t.pending;i===null?r.next=r:(r.next=i.next,i.next=r),t.pending=r}function Bv(t,r,i){if((i&4194048)!==0){var u=r.lanes;u&=t.pendingLanes,i|=u,r.lanes=i,fn(t,i)}}var Ni={readContext:en,use:gc,useCallback:jt,useContext:jt,useEffect:jt,useImperativeHandle:jt,useLayoutEffect:jt,useInsertionEffect:jt,useMemo:jt,useReducer:jt,useRef:jt,useState:jt,useDebugValue:jt,useDeferredValue:jt,useTransition:jt,useSyncExternalStore:jt,useId:jt,useHostTransitionStatus:jt,useFormState:jt,useActionState:jt,useOptimistic:jt,useMemoCache:jt,useCacheRefresh:jt};Ni.useEffectEvent=jt;var Uv={readContext:en,use:gc,useCallback:function(t,r){return cn().memoizedState=[t,r===void 0?null:r],t},useContext:en,useEffect:jv,useImperativeHandle:function(t,r,i){i=i!=null?i.concat([t]):null,vc(4194308,4,Tv.bind(null,r,t),i)},useLayoutEffect:function(t,r){return vc(4194308,4,t,r)},useInsertionEffect:function(t,r){vc(4,2,t,r)},useMemo:function(t,r){var i=cn();r=r===void 0?null:r;var u=t();if(co){ee(!0);try{t()}finally{ee(!1)}}return i.memoizedState=[u,r],u},useReducer:function(t,r,i){var u=cn();if(i!==void 0){var x=i(r);if(co){ee(!0);try{i(r)}finally{ee(!1)}}}else x=r;return u.memoizedState=u.baseState=x,t={pending:null,lanes:0,dispatch:null,lastRenderedReducer:t,lastRenderedState:x},u.queue=t,t=t.dispatch=d4.bind(null,$e,t),[u.memoizedState,t]},useRef:function(t){var r=cn();return t={current:t},r.memoizedState=t},useState:function(t){t=Gf(t);var r=t.queue,i=Iv.bind(null,$e,r);return r.dispatch=i,[t.memoizedState,i]},useDebugValue:Yf,useDeferredValue:function(t,r){var i=cn();return qf(i,t,r)},useTransition:function(){var t=Gf(!1);return t=Ov.bind(null,$e,t.queue,!0,!1),cn().memoizedState=t,[!1,t]},useSyncExternalStore:function(t,r,i){var u=$e,x=cn();if(Qe){if(i===void 0)throw Error(o(407));i=i()}else{if(i=r(),pt===null)throw Error(o(349));(qe&127)!==0||lv(u,r,i)}x.memoizedState=i;var v={value:i,getSnapshot:r};return x.queue=v,jv(uv.bind(null,u,v,t),[t]),u.flags|=2048,cs(9,{destroy:void 0},cv.bind(null,u,v,i,r),null),i},useId:function(){var t=cn(),r=pt.identifierPrefix;if(Qe){var i=gr,u=hr;i=(u&~(1<<32-re(u)-1)).toString(32)+i,r="_"+r+"R_"+i,i=pc++,0<\/script>",v=v.removeChild(v.firstChild);break;case"select":v=typeof u.is=="string"?C.createElement("select",{is:u.is}):C.createElement("select"),u.multiple?v.multiple=!0:u.size&&(v.size=u.size);break;default:v=typeof u.is=="string"?C.createElement(x,{is:u.is}):C.createElement(x)}}v[Qt]=r,v[pn]=u;e:for(C=r.child;C!==null;){if(C.tag===5||C.tag===6)v.appendChild(C.stateNode);else if(C.tag!==4&&C.tag!==27&&C.child!==null){C.child.return=C,C=C.child;continue}if(C===r)break e;for(;C.sibling===null;){if(C.return===null||C.return===r)break e;C=C.return}C.sibling.return=C.return,C=C.sibling}r.stateNode=v;e:switch(nn(v,x,u),x){case"button":case"input":case"select":case"textarea":u=!!u.autoFocus;break e;case"img":u=!0;break e;default:u=!1}u&&Br(r)}}return vt(r),dm(r,r.type,t===null?null:t.memoizedProps,r.pendingProps,i),null;case 6:if(t&&r.stateNode!=null)t.memoizedProps!==u&&Br(r);else{if(typeof u!="string"&&r.stateNode===null)throw Error(o(166));if(t=oe.current,es(r)){if(t=r.stateNode,i=r.memoizedProps,u=null,x=Jt,x!==null)switch(x.tag){case 27:case 5:u=x.memoizedProps}t[Qt]=r,t=!!(t.nodeValue===i||u!==null&&u.suppressHydrationWarning===!0||sb(t.nodeValue,i)),t||ua(r,!0)}else t=Bc(t).createTextNode(u),t[Qt]=r,r.stateNode=t}return vt(r),null;case 31:if(i=r.memoizedState,t===null||t.memoizedState!==null){if(u=es(r),i!==null){if(t===null){if(!u)throw Error(o(318));if(t=r.memoizedState,t=t!==null?t.dehydrated:null,!t)throw Error(o(557));t[Qt]=r}else no(),(r.flags&128)===0&&(r.memoizedState=null),r.flags|=4;vt(r),t=!1}else i=wf(),t!==null&&t.memoizedState!==null&&(t.memoizedState.hydrationErrors=i),t=!0;if(!t)return r.flags&256?(En(r),r):(En(r),null);if((r.flags&128)!==0)throw Error(o(558))}return vt(r),null;case 13:if(u=r.memoizedState,t===null||t.memoizedState!==null&&t.memoizedState.dehydrated!==null){if(x=es(r),u!==null&&u.dehydrated!==null){if(t===null){if(!x)throw Error(o(318));if(x=r.memoizedState,x=x!==null?x.dehydrated:null,!x)throw Error(o(317));x[Qt]=r}else no(),(r.flags&128)===0&&(r.memoizedState=null),r.flags|=4;vt(r),x=!1}else x=wf(),t!==null&&t.memoizedState!==null&&(t.memoizedState.hydrationErrors=x),x=!0;if(!x)return r.flags&256?(En(r),r):(En(r),null)}return En(r),(r.flags&128)!==0?(r.lanes=i,r):(i=u!==null,t=t!==null&&t.memoizedState!==null,i&&(u=r.child,x=null,u.alternate!==null&&u.alternate.memoizedState!==null&&u.alternate.memoizedState.cachePool!==null&&(x=u.alternate.memoizedState.cachePool.pool),v=null,u.memoizedState!==null&&u.memoizedState.cachePool!==null&&(v=u.memoizedState.cachePool.pool),v!==x&&(u.flags|=2048)),i!==t&&i&&(r.child.flags|=8192),Nc(r,r.updateQueue),vt(r),null);case 4:return ve(),t===null&&Om(r.stateNode.containerInfo),vt(r),null;case 10:return zr(r.type),vt(r),null;case 19:if(D(Tt),u=r.memoizedState,u===null)return vt(r),null;if(x=(r.flags&128)!==0,v=u.rendering,v===null)if(x)ki(u,!1);else{if(Nt!==0||t!==null&&(t.flags&128)!==0)for(t=r.child;t!==null;){if(v=fc(t),v!==null){for(r.flags|=128,ki(u,!1),t=v.updateQueue,r.updateQueue=t,Nc(r,t),r.subtreeFlags=0,t=i,i=r.child;i!==null;)Ix(i,t),i=i.sibling;return G(Tt,Tt.current&1|2),Qe&&Dr(r,u.treeForkCount),r.child}t=t.sibling}u.tail!==null&&Kt()>Ac&&(r.flags|=128,x=!0,ki(u,!1),r.lanes=4194304)}else{if(!x)if(t=fc(v),t!==null){if(r.flags|=128,x=!0,t=t.updateQueue,r.updateQueue=t,Nc(r,t),ki(u,!0),u.tail===null&&u.tailMode==="hidden"&&!v.alternate&&!Qe)return vt(r),null}else 2*Kt()-u.renderingStartTime>Ac&&i!==536870912&&(r.flags|=128,x=!0,ki(u,!1),r.lanes=4194304);u.isBackwards?(v.sibling=r.child,r.child=v):(t=u.last,t!==null?t.sibling=v:r.child=v,u.last=v)}return u.tail!==null?(t=u.tail,u.rendering=t,u.tail=t.sibling,u.renderingStartTime=Kt(),t.sibling=null,i=Tt.current,G(Tt,x?i&1|2:i&1),Qe&&Dr(r,u.treeForkCount),t):(vt(r),null);case 22:case 23:return En(r),Df(),u=r.memoizedState!==null,t!==null?t.memoizedState!==null!==u&&(r.flags|=8192):u&&(r.flags|=8192),u?(i&536870912)!==0&&(r.flags&128)===0&&(vt(r),r.subtreeFlags&6&&(r.flags|=8192)):vt(r),i=r.updateQueue,i!==null&&Nc(r,i.retryQueue),i=null,t!==null&&t.memoizedState!==null&&t.memoizedState.cachePool!==null&&(i=t.memoizedState.cachePool.pool),u=null,r.memoizedState!==null&&r.memoizedState.cachePool!==null&&(u=r.memoizedState.cachePool.pool),u!==i&&(r.flags|=2048),t!==null&&D(oo),null;case 24:return i=null,t!==null&&(i=t.memoizedState.cache),r.memoizedState.cache!==i&&(r.flags|=2048),zr(Ot),vt(r),null;case 25:return null;case 30:return null}throw Error(o(156,r.tag))}function g4(t,r){switch(bf(r),r.tag){case 1:return t=r.flags,t&65536?(r.flags=t&-65537|128,r):null;case 3:return zr(Ot),ve(),t=r.flags,(t&65536)!==0&&(t&128)===0?(r.flags=t&-65537|128,r):null;case 26:case 27:case 5:return le(r),null;case 31:if(r.memoizedState!==null){if(En(r),r.alternate===null)throw Error(o(340));no()}return t=r.flags,t&65536?(r.flags=t&-65537|128,r):null;case 13:if(En(r),t=r.memoizedState,t!==null&&t.dehydrated!==null){if(r.alternate===null)throw Error(o(340));no()}return t=r.flags,t&65536?(r.flags=t&-65537|128,r):null;case 19:return D(Tt),null;case 4:return ve(),null;case 10:return zr(r.type),null;case 22:case 23:return En(r),Df(),t!==null&&D(oo),t=r.flags,t&65536?(r.flags=t&-65537|128,r):null;case 24:return zr(Ot),null;case 25:return null;default:return null}}function d1(t,r){switch(bf(r),r.tag){case 3:zr(Ot),ve();break;case 26:case 27:case 5:le(r);break;case 4:ve();break;case 31:r.memoizedState!==null&&En(r);break;case 13:En(r);break;case 19:D(Tt);break;case 10:zr(r.type);break;case 22:case 23:En(r),Df(),t!==null&&D(oo);break;case 24:zr(Ot)}}function Ti(t,r){try{var i=r.updateQueue,u=i!==null?i.lastEffect:null;if(u!==null){var x=u.next;i=x;do{if((i.tag&t)===t){u=void 0;var v=i.create,C=i.inst;u=v(),C.destroy=u}i=i.next}while(i!==x)}}catch(R){st(r,r.return,R)}}function xa(t,r,i){try{var u=r.updateQueue,x=u!==null?u.lastEffect:null;if(x!==null){var v=x.next;u=v;do{if((u.tag&t)===t){var C=u.inst,R=C.destroy;if(R!==void 0){C.destroy=void 0,x=r;var P=i,Q=R;try{Q()}catch(ie){st(x,P,ie)}}}u=u.next}while(u!==v)}}catch(ie){st(r,r.return,ie)}}function f1(t){var r=t.updateQueue;if(r!==null){var i=t.stateNode;try{nv(r,i)}catch(u){st(t,t.return,u)}}}function m1(t,r,i){i.props=uo(t.type,t.memoizedProps),i.state=t.memoizedState;try{i.componentWillUnmount()}catch(u){st(t,r,u)}}function Ri(t,r){try{var i=t.ref;if(i!==null){switch(t.tag){case 26:case 27:case 5:var u=t.stateNode;break;case 30:u=t.stateNode;break;default:u=t.stateNode}typeof i=="function"?t.refCleanup=i(u):i.current=u}}catch(x){st(t,r,x)}}function xr(t,r){var i=t.ref,u=t.refCleanup;if(i!==null)if(typeof u=="function")try{u()}catch(x){st(t,r,x)}finally{t.refCleanup=null,t=t.alternate,t!=null&&(t.refCleanup=null)}else if(typeof i=="function")try{i(null)}catch(x){st(t,r,x)}else i.current=null}function p1(t){var r=t.type,i=t.memoizedProps,u=t.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(x){st(t,t.return,x)}}function fm(t,r,i){try{var u=t.stateNode;I4(u,t.type,i,r),u[pn]=r}catch(x){st(t,t.return,x)}}function h1(t){return t.tag===5||t.tag===3||t.tag===26||t.tag===27&&ja(t.type)||t.tag===4}function mm(t){e:for(;;){for(;t.sibling===null;){if(t.return===null||h1(t.return))return null;t=t.return}for(t.sibling.return=t.return,t=t.sibling;t.tag!==5&&t.tag!==6&&t.tag!==18;){if(t.tag===27&&ja(t.type)||t.flags&2||t.child===null||t.tag===4)continue e;t.child.return=t,t=t.child}if(!(t.flags&2))return t.stateNode}}function pm(t,r,i){var u=t.tag;if(u===5||u===6)t=t.stateNode,r?(i.nodeType===9?i.body:i.nodeName==="HTML"?i.ownerDocument.body:i).insertBefore(t,r):(r=i.nodeType===9?i.body:i.nodeName==="HTML"?i.ownerDocument.body:i,r.appendChild(t),i=i._reactRootContainer,i!=null||r.onclick!==null||(r.onclick=Mr));else if(u!==4&&(u===27&&ja(t.type)&&(i=t.stateNode,r=null),t=t.child,t!==null))for(pm(t,r,i),t=t.sibling;t!==null;)pm(t,r,i),t=t.sibling}function Ec(t,r,i){var u=t.tag;if(u===5||u===6)t=t.stateNode,r?i.insertBefore(t,r):i.appendChild(t);else if(u!==4&&(u===27&&ja(t.type)&&(i=t.stateNode),t=t.child,t!==null))for(Ec(t,r,i),t=t.sibling;t!==null;)Ec(t,r,i),t=t.sibling}function g1(t){var r=t.stateNode,i=t.memoizedProps;try{for(var u=t.type,x=r.attributes;x.length;)r.removeAttributeNode(x[0]);nn(r,u,i),r[Qt]=t,r[pn]=i}catch(v){st(t,t.return,v)}}var Ur=!1,zt=!1,hm=!1,x1=typeof WeakSet=="function"?WeakSet:Set,Gt=null;function x4(t,r){if(t=t.containerInfo,zm=Yc,t=Rx(t),lf(t)){if("selectionStart"in t)var i={start:t.selectionStart,end:t.selectionEnd};else e:{i=(i=t.ownerDocument)&&i.defaultView||window;var u=i.getSelection&&i.getSelection();if(u&&u.rangeCount!==0){i=u.anchorNode;var x=u.anchorOffset,v=u.focusNode;u=u.focusOffset;try{i.nodeType,v.nodeType}catch{i=null;break e}var C=0,R=-1,P=-1,Q=0,ie=0,de=t,J=null;t:for(;;){for(var ne;de!==i||x!==0&&de.nodeType!==3||(R=C+x),de!==v||u!==0&&de.nodeType!==3||(P=C+u),de.nodeType===3&&(C+=de.nodeValue.length),(ne=de.firstChild)!==null;)J=de,de=ne;for(;;){if(de===t)break t;if(J===i&&++Q===x&&(R=C),J===v&&++ie===u&&(P=C),(ne=de.nextSibling)!==null)break;de=J,J=de.parentNode}de=ne}i=R===-1||P===-1?null:{start:R,end:P}}else i=null}i=i||{start:0,end:0}}else i=null;for(Pm={focusedElem:t,selectionRange:i},Yc=!1,Gt=r;Gt!==null;)if(r=Gt,t=r.child,(r.subtreeFlags&1028)!==0&&t!==null)t.return=r,Gt=t;else for(;Gt!==null;){switch(r=Gt,v=r.alternate,t=r.flags,r.tag){case 0:if((t&4)!==0&&(t=r.updateQueue,t=t!==null?t.events:null,t!==null))for(i=0;i title"))),nn(v,u,i),v[Qt]=t,Vt(v),u=v;break e;case"link":var C=Sb("link","href",x).get(u+(i.href||""));if(C){for(var R=0;Rft&&(C=ft,ft=Oe,Oe=C);var W=kx(R,Oe),$=kx(R,ft);if(W&&$&&(ne.rangeCount!==1||ne.anchorNode!==W.node||ne.anchorOffset!==W.offset||ne.focusNode!==$.node||ne.focusOffset!==$.offset)){var X=de.createRange();X.setStart(W.node,W.offset),ne.removeAllRanges(),Oe>ft?(ne.addRange(X),ne.extend($.node,$.offset)):(X.setEnd($.node,$.offset),ne.addRange(X))}}}}for(de=[],ne=R;ne=ne.parentNode;)ne.nodeType===1&&de.push({element:ne,left:ne.scrollLeft,top:ne.scrollTop});for(typeof R.focus=="function"&&R.focus(),R=0;Ri?32:i,L.T=null,i=Cm,Cm=null;var v=wa,C=Wr;if(It=0,ps=wa=null,Wr=0,(nt&6)!==0)throw Error(o(331));var R=nt;if(nt|=4,T1(v.current),N1(v,v.current,C,i),nt=R,Li(0,!1),Ht&&typeof Ht.onPostCommitFiberRoot=="function")try{Ht.onPostCommitFiberRoot(pr,v)}catch{}return!0}finally{I.p=x,L.T=u,W1(t,r)}}function q1(t,r,i){r=Un(i,r),r=tm(t.stateNode,r,2),t=pa(t,r,2),t!==null&&(wt(t,2),vr(t))}function st(t,r,i){if(t.tag===3)q1(t,t,i);else for(;r!==null;){if(r.tag===3){q1(r,t,i);break}else if(r.tag===1){var u=r.stateNode;if(typeof r.type.getDerivedStateFromError=="function"||typeof u.componentDidCatch=="function"&&(ya===null||!ya.has(u))){t=Un(i,t),i=Kv(2),u=pa(r,i,2),u!==null&&(Xv(i,u,r,t),wt(u,2),vr(u));break}}r=r.return}}function Em(t,r,i){var u=t.pingCache;if(u===null){u=t.pingCache=new y4;var x=new Set;u.set(r,x)}else x=u.get(r),x===void 0&&(x=new Set,u.set(r,x));x.has(i)||(vm=!0,x.add(i),t=N4.bind(null,t,r,i),r.then(t,t))}function N4(t,r,i){var u=t.pingCache;u!==null&&u.delete(r),t.pingedLanes|=t.suspendedLanes&i,t.warmLanes&=~i,pt===t&&(qe&i)===i&&(Nt===4||Nt===3&&(qe&62914560)===qe&&300>Kt()-Rc?(nt&2)===0&&hs(t,0):bm|=i,ms===qe&&(ms=0)),vr(t)}function K1(t,r){r===0&&(r=kt()),t=eo(t,r),t!==null&&(wt(t,r),vr(t))}function E4(t){var r=t.memoizedState,i=0;r!==null&&(i=r.retryLane),K1(t,i)}function k4(t,r){var i=0;switch(t.tag){case 31:case 13:var u=t.stateNode,x=t.memoizedState;x!==null&&(i=x.retryLane);break;case 19:u=t.stateNode;break;case 22:u=t.stateNode._retryCache;break;default:throw Error(o(314))}u!==null&&u.delete(r),K1(t,i)}function T4(t,r){return Ya(t,r)}var zc=null,xs=null,km=!1,Pc=!1,Tm=!1,Sa=0;function vr(t){t!==xs&&t.next===null&&(xs===null?zc=xs=t:xs=xs.next=t),Pc=!0,km||(km=!0,A4())}function Li(t,r){if(!Tm&&Pc){Tm=!0;do for(var i=!1,u=zc;u!==null;){if(t!==0){var x=u.pendingLanes;if(x===0)var v=0;else{var C=u.suspendedLanes,R=u.pingedLanes;v=(1<<31-re(42|t)+1)-1,v&=x&~(C&~R),v=v&201326741?v&201326741|1:v?v|2:0}v!==0&&(i=!0,J1(u,v))}else v=qe,v=Me(u,u===pt?v:0,u.cancelPendingCommit!==null||u.timeoutHandle!==-1),(v&3)===0||Je(u,v)||(i=!0,J1(u,v));u=u.next}while(i);Tm=!1}}function R4(){X1()}function X1(){Pc=km=!1;var t=0;Sa!==0&&B4()&&(t=Sa);for(var r=Kt(),i=null,u=zc;u!==null;){var x=u.next,v=Z1(u,r);v===0?(u.next=null,i===null?zc=x:i.next=x,x===null&&(xs=i)):(i=u,(t!==0||(v&3)!==0)&&(Pc=!0)),u=x}It!==0&&It!==5||Li(t),Sa!==0&&(Sa=0)}function Z1(t,r){for(var i=t.suspendedLanes,u=t.pingedLanes,x=t.expirationTimes,v=t.pendingLanes&-62914561;0R)break;var ie=P.transferSize,de=P.initiatorType;ie&&ib(de)&&(P=P.responseEnd,C+=ie*(P"u"?null:document;function bb(t,r,i){var u=vs;if(u&&typeof r=="string"&&r){var x=$n(r);x='link[rel="'+t+'"][href="'+x+'"]',typeof i=="string"&&(x+='[crossorigin="'+i+'"]'),vb.has(x)||(vb.add(x),t={rel:t,crossOrigin:i,href:r},u.querySelector(x)===null&&(r=u.createElement("link"),nn(r,"link",t),Vt(r),u.head.appendChild(r)))}}function K4(t){Yr.D(t),bb("dns-prefetch",t,null)}function X4(t,r){Yr.C(t,r),bb("preconnect",t,r)}function Z4(t,r,i){Yr.L(t,r,i);var u=vs;if(u&&t&&r){var x='link[rel="preload"][as="'+$n(r)+'"]';r==="image"&&i&&i.imageSrcSet?(x+='[imagesrcset="'+$n(i.imageSrcSet)+'"]',typeof i.imageSizes=="string"&&(x+='[imagesizes="'+$n(i.imageSizes)+'"]')):x+='[href="'+$n(t)+'"]';var v=x;switch(r){case"style":v=bs(t);break;case"script":v=ys(t)}Yn.has(v)||(t=g({rel:"preload",href:r==="image"&&i&&i.imageSrcSet?void 0:t,as:r},i),Yn.set(v,t),u.querySelector(x)!==null||r==="style"&&u.querySelector($i(v))||r==="script"&&u.querySelector(Bi(v))||(r=u.createElement("link"),nn(r,"link",t),Vt(r),u.head.appendChild(r)))}}function Q4(t,r){Yr.m(t,r);var i=vs;if(i&&t){var u=r&&typeof r.as=="string"?r.as:"script",x='link[rel="modulepreload"][as="'+$n(u)+'"][href="'+$n(t)+'"]',v=x;switch(u){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":v=ys(t)}if(!Yn.has(v)&&(t=g({rel:"modulepreload",href:t},r),Yn.set(v,t),i.querySelector(x)===null)){switch(u){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":if(i.querySelector(Bi(v)))return}u=i.createElement("link"),nn(u,"link",t),Vt(u),i.head.appendChild(u)}}}function J4(t,r,i){Yr.S(t,r,i);var u=vs;if(u&&t){var x=Uo(u).hoistableStyles,v=bs(t);r=r||"default";var C=x.get(v);if(!C){var R={loading:0,preload:null};if(C=u.querySelector($i(v)))R.loading=5;else{t=g({rel:"stylesheet",href:t,"data-precedence":r},i),(i=Yn.get(v))&&Gm(t,i);var P=C=u.createElement("link");Vt(P),nn(P,"link",t),P._p=new Promise(function(Q,ie){P.onload=Q,P.onerror=ie}),P.addEventListener("load",function(){R.loading|=1}),P.addEventListener("error",function(){R.loading|=2}),R.loading|=4,Hc(C,r,u)}C={type:"stylesheet",instance:C,count:1,state:R},x.set(v,C)}}}function e3(t,r){Yr.X(t,r);var i=vs;if(i&&t){var u=Uo(i).hoistableScripts,x=ys(t),v=u.get(x);v||(v=i.querySelector(Bi(x)),v||(t=g({src:t,async:!0},r),(r=Yn.get(x))&&Fm(t,r),v=i.createElement("script"),Vt(v),nn(v,"link",t),i.head.appendChild(v)),v={type:"script",instance:v,count:1,state:null},u.set(x,v))}}function t3(t,r){Yr.M(t,r);var i=vs;if(i&&t){var u=Uo(i).hoistableScripts,x=ys(t),v=u.get(x);v||(v=i.querySelector(Bi(x)),v||(t=g({src:t,async:!0,type:"module"},r),(r=Yn.get(x))&&Fm(t,r),v=i.createElement("script"),Vt(v),nn(v,"link",t),i.head.appendChild(v)),v={type:"script",instance:v,count:1,state:null},u.set(x,v))}}function yb(t,r,i,u){var x=(x=oe.current)?Uc(x):null;if(!x)throw Error(o(446));switch(t){case"meta":case"title":return null;case"style":return typeof i.precedence=="string"&&typeof i.href=="string"?(r=bs(i.href),i=Uo(x).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"){t=bs(i.href);var v=Uo(x).hoistableStyles,C=v.get(t);if(C||(x=x.ownerDocument||x,C={type:"stylesheet",instance:null,count:0,state:{loading:0,preload:null}},v.set(t,C),(v=x.querySelector($i(t)))&&!v._p&&(C.instance=v,C.state.loading=5),Yn.has(t)||(i={rel:"preload",as:"style",href:i.href,crossOrigin:i.crossOrigin,integrity:i.integrity,media:i.media,hrefLang:i.hrefLang,referrerPolicy:i.referrerPolicy},Yn.set(t,i),v||n3(x,t,i,C.state))),r&&u===null)throw Error(o(528,""));return C}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=ys(i),i=Uo(x).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,t))}}function bs(t){return'href="'+$n(t)+'"'}function $i(t){return'link[rel="stylesheet"]['+t+"]"}function wb(t){return g({},t,{"data-precedence":t.precedence,precedence:null})}function n3(t,r,i,u){t.querySelector('link[rel="preload"][as="style"]['+r+"]")?u.loading=1:(r=t.createElement("link"),u.preload=r,r.addEventListener("load",function(){return u.loading|=1}),r.addEventListener("error",function(){return u.loading|=2}),nn(r,"link",i),Vt(r),t.head.appendChild(r))}function ys(t){return'[src="'+$n(t)+'"]'}function Bi(t){return"script[async]"+t}function Cb(t,r,i){if(r.count++,r.instance===null)switch(r.type){case"style":var u=t.querySelector('style[data-href~="'+$n(i.href)+'"]');if(u)return r.instance=u,Vt(u),u;var x=g({},i,{"data-href":i.href,"data-precedence":i.precedence,href:null,precedence:null});return u=(t.ownerDocument||t).createElement("style"),Vt(u),nn(u,"style",x),Hc(u,i.precedence,t),r.instance=u;case"stylesheet":x=bs(i.href);var v=t.querySelector($i(x));if(v)return r.state.loading|=4,r.instance=v,Vt(v),v;u=wb(i),(x=Yn.get(x))&&Gm(u,x),v=(t.ownerDocument||t).createElement("link"),Vt(v);var C=v;return C._p=new Promise(function(R,P){C.onload=R,C.onerror=P}),nn(v,"link",u),r.state.loading|=4,Hc(v,i.precedence,t),r.instance=v;case"script":return v=ys(i.src),(x=t.querySelector(Bi(v)))?(r.instance=x,Vt(x),x):(u=i,(x=Yn.get(v))&&(u=g({},i),Fm(u,x)),t=t.ownerDocument||t,x=t.createElement("script"),Vt(x),nn(x,"link",u),t.head.appendChild(x),r.instance=x);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,Hc(u,i.precedence,t));return r.instance}function Hc(t,r,i){for(var u=i.querySelectorAll('link[rel="stylesheet"][data-precedence],style[data-precedence]'),x=u.length?u[u.length-1]:null,v=x,C=0;C title"):null)}function r3(t,r,i){if(i===1||r.itemProp!=null)return!1;switch(t){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 t=r.disabled,typeof r.precedence=="string"&&t==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 Nb(t){return!(t.type==="stylesheet"&&(t.state.loading&3)===0)}function a3(t,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 x=bs(u.href),v=r.querySelector($i(x));if(v){r=v._p,r!==null&&typeof r=="object"&&typeof r.then=="function"&&(t.count++,t=Gc.bind(t),r.then(t,t)),i.state.loading|=4,i.instance=v,Vt(v);return}v=r.ownerDocument||r,u=wb(u),(x=Yn.get(x))&&Gm(u,x),v=v.createElement("link"),Vt(v);var C=v;C._p=new Promise(function(R,P){C.onload=R,C.onerror=P}),nn(v,"link",u),i.instance=v}t.stylesheets===null&&(t.stylesheets=new Map),t.stylesheets.set(i,r),(r=i.state.preload)&&(i.state.loading&3)===0&&(t.count++,i=Gc.bind(t),r.addEventListener("load",i),r.addEventListener("error",i))}}var Wm=0;function o3(t,r){return t.stylesheets&&t.count===0&&Wc(t,t.stylesheets),0Wm?50:800)+r);return t.unsuspend=i,function(){t.unsuspend=null,clearTimeout(u),clearTimeout(x)}}:null}function Gc(){if(this.count--,this.count===0&&(this.imgCount===0||!this.waitingForImages)){if(this.stylesheets)Wc(this,this.stylesheets);else if(this.unsuspend){var t=this.unsuspend;this.unsuspend=null,t()}}}var Fc=null;function Wc(t,r){t.stylesheets=null,t.unsuspend!==null&&(t.count++,Fc=new Map,r.forEach(s3,t),Fc=null,Gc.call(t))}function s3(t,r){if(!(r.state.loading&4)){var i=Fc.get(t);if(i)var u=i.get(null);else{i=new Map,Fc.set(t,i);for(var x=t.querySelectorAll("link[data-precedence],style[data-precedence]"),v=0;v"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(e)}catch(n){console.error(n)}}return e(),tp.exports=j3(),tp.exports}var E3=N3();/** * react-router v7.15.1 * * 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 Xb="popstate";function Zb(e){return typeof e=="object"&&e!=null&&"pathname"in e&&"search"in e&&"hash"in e&&"state"in e&&"key"in e}function k3(e={}){function n(o,l){var h;let c=(h=l.state)==null?void 0:h.masked,{pathname:d,search:m,hash:p}=c||o.location;return Up("",{pathname:d,search:m,hash:p},l.state&&l.state.usr||null,l.state&&l.state.key||"default",c?{pathname:o.location.pathname,search:o.location.search,hash:o.location.hash}:void 0)}function a(o,l){return typeof l=="string"?l:sl(l)}return R3(n,a,null,e)}function yt(e,n){if(e===!1||e===null||typeof e>"u")throw new Error(n)}function Xn(e,n){if(!e){typeof console<"u"&&console.warn(n);try{throw new Error(n)}catch{}}}function T3(){return Math.random().toString(36).substring(2,10)}function Qb(e,n){return{usr:e.state,key:e.key,idx:n,masked:e.mask?{pathname:e.pathname,search:e.search,hash:e.hash}:void 0}}function Up(e,n,a=null,o,l){return{pathname:typeof e=="string"?e:e.pathname,search:"",hash:"",...typeof n=="string"?$s(n):n,state:a,key:n&&n.key||o||T3(),mask:l}}function sl({pathname:e="/",search:n="",hash:a=""}){return n&&n!=="?"&&(e+=n.charAt(0)==="?"?n:"?"+n),a&&a!=="#"&&(e+=a.charAt(0)==="#"?a:"#"+a),e}function $s(e){let n={};if(e){let a=e.indexOf("#");a>=0&&(n.hash=e.substring(a),e=e.substring(0,a));let o=e.indexOf("?");o>=0&&(n.search=e.substring(o),e=e.substring(0,o)),e&&(n.pathname=e)}return n}function R3(e,n,a,o={}){let{window:l=document.defaultView,v5Compat:c=!1}=o,d=l.history,m="POP",p=null,h=b();h==null&&(h=0,d.replaceState({...d.state,idx:h},""));function b(){return(d.state||{idx:null}).idx}function g(){m="POP";let E=b(),N=E==null?null:E-h;h=E,p&&p({action:m,location:S.location,delta:N})}function y(E,N){m="PUSH";let k=Zb(E)?E:Up(S.location,E,N);h=b()+1;let T=Qb(k,h),A=S.createHref(k.mask||k);try{d.pushState(T,"",A)}catch(O){if(O instanceof DOMException&&O.name==="DataCloneError")throw O;l.location.assign(A)}c&&p&&p({action:m,location:S.location,delta:1})}function w(E,N){m="REPLACE";let k=Zb(E)?E:Up(S.location,E,N);h=b();let T=Qb(k,h),A=S.createHref(k.mask||k);d.replaceState(T,"",A),c&&p&&p({action:m,location:S.location,delta:0})}function j(E){return A3(E)}let S={get action(){return m},get location(){return e(l,d)},listen(E){if(p)throw new Error("A history only accepts one active listener");return l.addEventListener(Xb,g),p=E,()=>{l.removeEventListener(Xb,g),p=null}},createHref(E){return n(l,E)},createURL:j,encodeLocation(E){let N=j(E);return{pathname:N.pathname,search:N.search,hash:N.hash}},push:y,replace:w,go(E){return d.go(E)}};return S}function A3(e,n=!1){let a="http://localhost";typeof window<"u"&&(a=window.location.origin!=="null"?window.location.origin:window.location.href),yt(a,"No window.location.(origin|href) available to create URL");let o=typeof e=="string"?e:sl(e);return o=o.replace(/ $/,"%20"),!n&&o.startsWith("//")&&(o=a+o),new URL(o,a)}function _0(e,n,a="/"){return M3(e,n,a,!1)}function M3(e,n,a,o,l){let c=typeof n=="string"?$s(n):n,d=Jr(c.pathname||"/",a);if(d==null)return null;let m=_3(e),p=null,h=G3(d);for(let b=0;p==null&&b{let b={relativePath:h===void 0?d.path||"":h,caseSensitive:d.caseSensitive===!0,childrenIndex:m,route:d};if(b.relativePath.startsWith("/")){if(!b.relativePath.startsWith(o)&&p)return;yt(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 g=sr([o,b.relativePath]),y=a.concat(b);d.children&&d.children.length>0&&(yt(d.index!==!0,`Index routes must not have child routes. Please remove all child routes from route path "${g}".`),O0(d.children,n,y,g,p)),!(d.path==null&&!d.index)&&n.push({path:g,score:B3(g,d.index),routesMeta:y})};return e.forEach((d,m)=>{var p;if(d.path===""||!((p=d.path)!=null&&p.includes("?")))c(d,m);else for(let h of D0(d.path))c(d,m,!0,h)}),n}function D0(e){let n=e.split("/");if(n.length===0)return[];let[a,...o]=n,l=a.endsWith("?"),c=a.replace(/\?$/,"");if(o.length===0)return l?[c,""]:[c];let d=D0(o.join("/")),m=[];return m.push(...d.map(p=>p===""?c:[c,p].join("/"))),l&&m.push(...d),m.map(p=>e.startsWith("/")&&p===""?"/":p)}function O3(e){e.sort((n,a)=>n.score!==a.score?a.score-n.score:U3(n.routesMeta.map(o=>o.childrenIndex),a.routesMeta.map(o=>o.childrenIndex)))}var D3=/^:[\w-]+$/,L3=3,z3=2,P3=1,I3=10,$3=-2,Jb=e=>e==="*";function B3(e,n){let a=e.split("/"),o=a.length;return a.some(Jb)&&(o+=$3),n&&(o+=z3),a.filter(l=>!Jb(l)).reduce((l,c)=>l+(D3.test(c)?L3:c===""?P3:I3),o)}function U3(e,n){return e.length===n.length&&e.slice(0,-1).every((o,l)=>o===n[l])?e[e.length-1]-n[n.length-1]:0}function H3(e,n,a=!1){let{routesMeta:o}=e,l={},c="/",d=[];for(let m=0;m{if(b==="*"){let j=m[y]||"";d=c.slice(0,c.length-j.length).replace(/(.)\/+$/,"$1")}const w=m[y];return g&&!w?h[b]=void 0:h[b]=(w||"").replace(/%2F/g,"/"),h},{}),pathname:c,pathnameBase:d,pattern:e}}function V3(e,n=!1,a=!0){Xn(e==="*"||!e.endsWith("*")||e.endsWith("/*"),`Route path "${e}" will be treated as if it were "${e.replace(/\*$/,"/*")}" because the \`*\` character must always follow a \`/\` in the pattern. To get rid of this warning, please change the route path to "${e.replace(/\*$/,"/*")}".`);let o=[],l="^"+e.replace(/\/*\*?$/,"").replace(/^\/*/,"/").replace(/[\\.*+^${}|()[\]]/g,"\\$&").replace(/\/:([\w-]+)(\?)?/g,(d,m,p,h,b)=>{if(o.push({paramName:m,isOptional:p!=null}),p){let g=b.charAt(h+d.length);return g&&g!=="/"?"/([^\\/]*)":"(?:/([^\\/]*))?"}return"/([^\\/]+)"}).replace(/\/([\w-]+)\?(\/|$)/g,"(/$1)?$2");return e.endsWith("*")?(o.push({paramName:"*"}),l+=e==="*"||e==="/*"?"(.*)$":"(?:\\/(.+)|\\/*)$"):a?l+="\\/*$":e!==""&&e!=="/"&&(l+="(?:(?=\\/|$))"),[new RegExp(l,n?void 0:"i"),o]}function G3(e){try{return e.split("/").map(n=>decodeURIComponent(n).replace(/\//g,"%2F")).join("/")}catch(n){return Xn(!1,`The URL path "${e}" could not be decoded because it is a malformed URL segment. This is probably due to a bad percent encoding (${n}).`),e}}function Jr(e,n){if(n==="/")return e;if(!e.toLowerCase().startsWith(n.toLowerCase()))return null;let a=n.endsWith("/")?n.length-1:n.length,o=e.charAt(a);return o&&o!=="/"?null:e.slice(a)||"/"}var F3=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;function W3(e,n="/"){let{pathname:a,search:o="",hash:l=""}=typeof e=="string"?$s(e):e,c;return a?(a=L0(a),a.startsWith("/")?c=ey(a.substring(1),"/"):c=ey(a,n)):c=n,{pathname:c,search:K3(o),hash:X3(l)}}function ey(e,n){let a=Ru(n).split("/");return e.split("/").forEach(l=>{l===".."?a.length>1&&a.pop():l!=="."&&a.push(l)}),a.length>1?a.join("/"):"/"}function op(e,n,a,o){return`Cannot include a '${e}' 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 Y3(e){return e.filter((n,a)=>a===0||n.route.path&&n.route.path.length>0)}function Mh(e){let n=Y3(e);return n.map((a,o)=>o===n.length-1?a.pathname:a.pathnameBase)}function Xu(e,n,a,o=!1){let l;typeof e=="string"?l=$s(e):(l={...e},yt(!l.pathname||!l.pathname.includes("?"),op("?","pathname","search",l)),yt(!l.pathname||!l.pathname.includes("#"),op("#","pathname","hash",l)),yt(!l.search||!l.search.includes("#"),op("#","search","hash",l)));let c=e===""||l.pathname==="",d=c?"/":l.pathname,m;if(d==null)m=a;else{let g=n.length-1;if(!o&&d.startsWith("..")){let y=d.split("/");for(;y[0]==="..";)y.shift(),g-=1;l.pathname=y.join("/")}m=g>=0?n[g]:"/"}let p=W3(l,m),h=d&&d!=="/"&&d.endsWith("/"),b=(c||d===".")&&a.endsWith("/");return!p.pathname.endsWith("/")&&(h||b)&&(p.pathname+="/"),p}var L0=e=>e.replace(/\/\/+/g,"/"),sr=e=>L0(e.join("/")),Ru=e=>e.replace(/\/+$/,""),q3=e=>Ru(e).replace(/^\/*/,"/"),K3=e=>!e||e==="?"?"":e.startsWith("?")?e:"?"+e,X3=e=>!e||e==="#"?"":e.startsWith("#")?e:"#"+e,Z3=class{constructor(e,n,a,o=!1){this.status=e,this.statusText=n||"",this.internal=o,a instanceof Error?(this.data=a.toString(),this.error=a):this.data=a}};function Q3(e){return e!=null&&typeof e.status=="number"&&typeof e.statusText=="string"&&typeof e.internal=="boolean"&&"data"in e}function J3(e){let n=e.map(a=>a.route.path).filter(Boolean);return sr(n)||"/"}var z0=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function P0(e,n){let a=e;if(typeof a!="string"||!F3.test(a))return{absoluteURL:void 0,isExternal:!1,to:a};let o=a,l=!1;if(z0)try{let c=new URL(window.location.href),d=a.startsWith("//")?new URL(c.protocol+a):new URL(a),m=Jr(d.pathname,n);d.origin===c.origin&&m!=null?a=m+d.search+d.hash:l=!0}catch{Xn(!1,` contains an invalid URL which will probably break when clicked - please update to a valid URL path.`)}return{absoluteURL:o,isExternal:l,to:a}}Object.getOwnPropertyNames(Object.prototype).sort().join("\0");var I0=["POST","PUT","PATCH","DELETE"];new Set(I0);var eE=["GET",...I0];new Set(eE);var Bs=f.createContext(null);Bs.displayName="DataRouter";var Zu=f.createContext(null);Zu.displayName="DataRouterState";var $0=f.createContext(!1);function tE(){return f.useContext($0)}var B0=f.createContext({isTransitioning:!1});B0.displayName="ViewTransition";var nE=f.createContext(new Map);nE.displayName="Fetchers";var rE=f.createContext(null);rE.displayName="Await";var Dn=f.createContext(null);Dn.displayName="Navigation";var bl=f.createContext(null);bl.displayName="Location";var cr=f.createContext({outlet:null,matches:[],isDataRoute:!1});cr.displayName="Route";var _h=f.createContext(null);_h.displayName="RouteError";var U0="REACT_ROUTER_ERROR",aE="REDIRECT",oE="ROUTE_ERROR_RESPONSE";function sE(e){if(e.startsWith(`${U0}:${aE}:{`))try{let n=JSON.parse(e.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 iE(e){if(e.startsWith(`${U0}:${oE}:{`))try{let n=JSON.parse(e.slice(40));if(typeof n=="object"&&n&&typeof n.status=="number"&&typeof n.statusText=="string")return new Z3(n.status,n.statusText,n.data)}catch{}}function lE(e,{relative:n}={}){yt(Us(),"useHref() may be used only in the context of a component.");let{basename:a,navigator:o}=f.useContext(Dn),{hash:l,pathname:c,search:d}=yl(e,{relative:n}),m=c;return a!=="/"&&(m=c==="/"?a:sr([a,c])),o.createHref({pathname:m,search:d,hash:l})}function Us(){return f.useContext(bl)!=null}function Ln(){return yt(Us(),"useLocation() may be used only in the context of a component."),f.useContext(bl).location}var H0="You should call navigate() in a React.useEffect(), not when your component is first rendered.";function V0(e){f.useContext(Dn).static||f.useLayoutEffect(e)}function Ro(){let{isDataRoute:e}=f.useContext(cr);return e?SE():cE()}function cE(){yt(Us(),"useNavigate() may be used only in the context of a component.");let e=f.useContext(Bs),{basename:n,navigator:a}=f.useContext(Dn),{matches:o}=f.useContext(cr),{pathname:l}=Ln(),c=JSON.stringify(Mh(o)),d=f.useRef(!1);return V0(()=>{d.current=!0}),f.useCallback((p,h={})=>{if(Xn(d.current,H0),!d.current)return;if(typeof p=="number"){a.go(p);return}let b=Xu(p,JSON.parse(c),l,h.relative==="path");e==null&&n!=="/"&&(b.pathname=b.pathname==="/"?n:sr([n,b.pathname])),(h.replace?a.replace:a.push)(b,h.state,h)},[n,a,c,l,e])}var uE=f.createContext(null);function dE(e){let n=f.useContext(cr).outlet;return f.useMemo(()=>n&&f.createElement(uE.Provider,{value:e},n),[n,e])}function yl(e,{relative:n}={}){let{matches:a}=f.useContext(cr),{pathname:o}=Ln(),l=JSON.stringify(Mh(a));return f.useMemo(()=>Xu(e,JSON.parse(l),o,n==="path"),[e,l,o,n])}function fE(e,n){return G0(e,n)}function G0(e,n,a){var E;yt(Us(),"useRoutes() may be used only in the context of a component.");let{navigator:o}=f.useContext(Dn),{matches:l}=f.useContext(cr),c=l[l.length-1],d=c?c.params:{},m=c?c.pathname:"/",p=c?c.pathnameBase:"/",h=c&&c.route;{let N=h&&h.path||"";W0(m,!h||N.endsWith("*")||N.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=Ln(),g;if(n){let N=typeof n=="string"?$s(n):n;yt(p==="/"||((E=N.pathname)==null?void 0:E.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 "${N.pathname}" was given in the \`location\` prop.`),g=N}else g=b;let y=g.pathname||"/",w=y;if(p!=="/"){let N=p.replace(/^\//,"").split("/");w="/"+y.replace(/^\//,"").split("/").slice(N.length).join("/")}let j=a&&a.state.matches.length?a.state.matches.map(N=>Object.assign(N,{route:a.manifest[N.route.id]||N.route})):_0(e,{pathname:w});Xn(h||j!=null,`No routes matched location "${g.pathname}${g.search}${g.hash}" `),Xn(j==null||j[j.length-1].route.element!==void 0||j[j.length-1].route.Component!==void 0||j[j.length-1].route.lazy!==void 0,`Matched leaf route at location "${g.pathname}${g.search}${g.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=xE(j&&j.map(N=>Object.assign({},N,{params:Object.assign({},d,N.params),pathname:sr([p,o.encodeLocation?o.encodeLocation(N.pathname.replace(/%/g,"%25").replace(/\?/g,"%3F").replace(/#/g,"%23")).pathname:N.pathname]),pathnameBase:N.pathnameBase==="/"?p:sr([p,o.encodeLocation?o.encodeLocation(N.pathnameBase.replace(/%/g,"%25").replace(/\?/g,"%3F").replace(/#/g,"%23")).pathname:N.pathnameBase])})),l,a);return n&&S?f.createElement(bl.Provider,{value:{location:{pathname:"/",search:"",hash:"",state:null,key:"default",mask:void 0,...g},navigationType:"POP"}},S):S}function mE(){let e=CE(),n=Q3(e)?`${e.status} ${e.statusText}`:e instanceof Error?e.message:JSON.stringify(e),a=e instanceof Error?e.stack:null,o="rgba(200,200,200, 0.5)",l={padding:"0.5rem",backgroundColor:o},c={padding:"2px 4px",backgroundColor:o},d=null;return console.error("Error handled by React Router default ErrorBoundary:",e),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:c},"ErrorBoundary")," or"," ",f.createElement("code",{style:c},"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:l},a):null,d)}var pE=f.createElement(mE,null),F0=class extends f.Component{constructor(e){super(e),this.state={location:e.location,revalidation:e.revalidation,error:e.error}}static getDerivedStateFromError(e){return{error:e}}static getDerivedStateFromProps(e,n){return n.location!==e.location||n.revalidation!=="idle"&&e.revalidation==="idle"?{error:e.error,location:e.location,revalidation:e.revalidation}:{error:e.error!==void 0?e.error:n.error,location:n.location,revalidation:e.revalidation||n.revalidation}}componentDidCatch(e,n){this.props.onError?this.props.onError(e,n):console.error("React Router caught the following error during render",e)}render(){let e=this.state.error;if(this.context&&typeof e=="object"&&e&&"digest"in e&&typeof e.digest=="string"){const a=iE(e.digest);a&&(e=a)}let n=e!==void 0?f.createElement(cr.Provider,{value:this.props.routeContext},f.createElement(_h.Provider,{value:e,children:this.props.component})):this.props.children;return this.context?f.createElement(hE,{error:e},n):n}};F0.contextType=$0;var sp=new WeakMap;function hE({children:e,error:n}){let{basename:a}=f.useContext(Dn);if(typeof n=="object"&&n&&"digest"in n&&typeof n.digest=="string"){let o=sE(n.digest);if(o){let l=sp.get(n);if(l)throw l;let c=P0(o.location,a);if(z0&&!sp.get(n))if(c.isExternal||o.reloadDocument)window.location.href=c.absoluteURL||c.to;else{const d=Promise.resolve().then(()=>window.__reactRouterDataRouter.navigate(c.to,{replace:o.replace}));throw sp.set(n,d),d}return f.createElement("meta",{httpEquiv:"refresh",content:`0;url=${c.absoluteURL||c.to}`})}}return e}function gE({routeContext:e,match:n,children:a}){let o=f.useContext(Bs);return o&&o.static&&o.staticContext&&(n.route.errorElement||n.route.ErrorBoundary)&&(o.staticContext._deepestRenderedBoundaryId=n.route.id),f.createElement(cr.Provider,{value:e},a)}function xE(e,n=[],a){let o=a==null?void 0:a.state;if(e==null){if(!o)return null;if(o.errors)e=o.matches;else if(n.length===0&&!o.initialized&&o.matches.length>0)e=o.matches;else return null}let l=e,c=o==null?void 0:o.errors;if(c!=null){let b=l.findIndex(g=>g.route.id&&(c==null?void 0:c[g.route.id])!==void 0);yt(b>=0,`Could not find a matching route for errors on route IDs: ${Object.keys(c).join(",")}`),l=l.slice(0,Math.min(l.length,b+1))}let d=!1,m=-1;if(a&&o){d=o.renderFallback;for(let b=0;b=0?l=l.slice(0,m+1):l=[l[0]];break}}}}let p=a==null?void 0:a.onError,h=o&&p?(b,g)=>{var y,w;p(b,{location:o.location,params:((w=(y=o.matches)==null?void 0:y[0])==null?void 0:w.params)??{},pattern:J3(o.matches),errorInfo:g})}:void 0;return l.reduceRight((b,g,y)=>{let w,j=!1,S=null,E=null;o&&(w=c&&g.route.id?c[g.route.id]:void 0,S=g.route.errorElement||pE,d&&(m<0&&y===0?(W0("route-fallback",!1,"No `HydrateFallback` element provided to render during initial hydration"),j=!0,E=null):m===y&&(j=!0,E=g.route.hydrateFallbackElement||null)));let N=n.concat(l.slice(0,y+1)),k=()=>{let T;return w?T=S:j?T=E:g.route.Component?T=f.createElement(g.route.Component,null):g.route.element?T=g.route.element:T=b,f.createElement(gE,{match:g,routeContext:{outlet:b,matches:N,isDataRoute:o!=null},children:T})};return o&&(g.route.ErrorBoundary||g.route.errorElement||y===0)?f.createElement(F0,{location:o.location,revalidation:o.revalidation,component:S,error:w,children:k(),routeContext:{outlet:null,matches:N,isDataRoute:!0},onError:h}):k()},null)}function Oh(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function vE(e){let n=f.useContext(Bs);return yt(n,Oh(e)),n}function bE(e){let n=f.useContext(Zu);return yt(n,Oh(e)),n}function yE(e){let n=f.useContext(cr);return yt(n,Oh(e)),n}function Dh(e){let n=yE(e),a=n.matches[n.matches.length-1];return yt(a.route.id,`${e} can only be used on routes that contain a unique "id"`),a.route.id}function wE(){return Dh("useRouteId")}function CE(){var o;let e=f.useContext(_h),n=bE("useRouteError"),a=Dh("useRouteError");return e!==void 0?e:(o=n.errors)==null?void 0:o[a]}function SE(){let{router:e}=vE("useNavigate"),n=Dh("useNavigate"),a=f.useRef(!1);return V0(()=>{a.current=!0}),f.useCallback(async(l,c={})=>{Xn(a.current,H0),a.current&&(typeof l=="number"?await e.navigate(l):await e.navigate(l,{fromRouteId:n,...c}))},[e,n])}var ty={};function W0(e,n,a){!n&&!ty[e]&&(ty[e]=!0,Xn(!1,a))}f.memo(jE);function jE({routes:e,manifest:n,future:a,state:o,isStatic:l,onError:c}){return G0(e,void 0,{manifest:n,state:o,isStatic:l,onError:c})}function Qr({to:e,replace:n,state:a,relative:o}){yt(Us()," may be used only in the context of a component.");let{static:l}=f.useContext(Dn);Xn(!l," 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:c}=f.useContext(cr),{pathname:d}=Ln(),m=Ro(),p=Xu(e,Mh(c),d,o==="path"),h=JSON.stringify(p);return f.useEffect(()=>{m(JSON.parse(h),{replace:n,state:a,relative:o})},[m,h,o,n,a]),null}function NE(e){return dE(e.context)}function rn(e){yt(!1,"A is only ever to be used as the child of element, never rendered directly. Please wrap your in a .")}function EE({basename:e="/",children:n=null,location:a,navigationType:o="POP",navigator:l,static:c=!1,useTransitions:d}){yt(!Us(),"You cannot render a inside another . You should never have more than one in your app.");let m=e.replace(/^\/*/,"/"),p=f.useMemo(()=>({basename:m,navigator:l,static:c,useTransitions:d,future:{}}),[m,l,c,d]);typeof a=="string"&&(a=$s(a));let{pathname:h="/",search:b="",hash:g="",state:y=null,key:w="default",mask:j}=a,S=f.useMemo(()=>{let E=Jr(h,m);return E==null?null:{location:{pathname:E,search:b,hash:g,state:y,key:w,mask:j},navigationType:o}},[m,h,b,g,y,w,o,j]);return Xn(S!=null,` is not able to match the URL "${h}${b}${g}" because it does not start with the basename, so the won't render anything.`),S==null?null:f.createElement(Dn.Provider,{value:p},f.createElement(bl.Provider,{children:n,value:S}))}function ny({children:e,location:n}){return fE(Hp(e),n)}function Hp(e,n=[]){let a=[];return f.Children.forEach(e,(o,l)=>{if(!f.isValidElement(o))return;let c=[...n,l];if(o.type===f.Fragment){a.push.apply(a,Hp(o.props.children,c));return}yt(o.type===rn,`[${typeof o.type=="string"?o.type:o.type.name}] is not a component. All component children of must be a or `),yt(!o.props.index||!o.props.children,"An index route cannot have child routes.");let d={id:o.props.id||c.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=Hp(o.props.children,c)),a.push(d)}),a}var xu="get",vu="application/x-www-form-urlencoded";function Qu(e){return typeof HTMLElement<"u"&&e instanceof HTMLElement}function kE(e){return Qu(e)&&e.tagName.toLowerCase()==="button"}function TE(e){return Qu(e)&&e.tagName.toLowerCase()==="form"}function RE(e){return Qu(e)&&e.tagName.toLowerCase()==="input"}function AE(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function ME(e,n){return e.button===0&&(!n||n==="_self")&&!AE(e)}function Vp(e=""){return new URLSearchParams(typeof e=="string"||Array.isArray(e)||e instanceof URLSearchParams?e:Object.keys(e).reduce((n,a)=>{let o=e[a];return n.concat(Array.isArray(o)?o.map(l=>[a,l]):[[a,o]])},[]))}function _E(e,n){let a=Vp(e);return n&&n.forEach((o,l)=>{a.has(l)||n.getAll(l).forEach(c=>{a.append(l,c)})}),a}var eu=null;function OE(){if(eu===null)try{new FormData(document.createElement("form"),0),eu=!1}catch{eu=!0}return eu}var DE=new Set(["application/x-www-form-urlencoded","multipart/form-data","text/plain"]);function ip(e){return e!=null&&!DE.has(e)?(Xn(!1,`"${e}" is not a valid \`encType\` for \`
\`/\`\` and will default to "${vu}"`),null):e}function LE(e,n){let a,o,l,c,d;if(TE(e)){let m=e.getAttribute("action");o=m?Jr(m,n):null,a=e.getAttribute("method")||xu,l=ip(e.getAttribute("enctype"))||vu,c=new FormData(e)}else if(kE(e)||RE(e)&&(e.type==="submit"||e.type==="image")){let m=e.form;if(m==null)throw new Error('Cannot submit a `,O=>`${A}-${O.id}`)}const E=y`
${n.i18n.searchDescription}
${n.i18n.skinToneDescription}
${w(n.skinTones,(k,T)=>y`
${k}
`,k=>k)}
${w(n.currentEmojisWithCategories,(k,T)=>y`
${j(k.emojis,n.searchMode,"emo")}
`,k=>k.category)}
`,N=(k,T)=>{for(const A of e.querySelectorAll(`[${k}]`))T(A,A.getAttribute(k))};if(p){e.appendChild(E);for(const k of["click","focusout","input","keydown","keyup"])N(`data-on-${k}`,(T,A)=>{T.addEventListener(k,o[A])});N("data-ref",(k,T)=>{c[T]=k}),d.addEventListener("abort",()=>{e.removeChild(E)})}N("data-action",(k,T)=>{let A=m.get(T);A||m.set(T,A=new WeakSet),A.has(k)||(A.add(k),l[T](k))})}const Wu=typeof queueMicrotask=="function"?queueMicrotask:e=>Promise.resolve().then(e);function gP(e){let n=!1,a;const o=new Map,l=new Set;let c;const d=()=>{if(n)return;const h=[...l];l.clear();try{for(const b of h)b()}finally{c=!1,l.size&&(c=!0,Wu(d))}},m=new Proxy({},{get(h,b){if(a){let g=o.get(b);g||(g=new Set,o.set(b,g)),g.add(a)}return h[b]},set(h,b,g){if(h[b]!==g){h[b]=g;const y=o.get(b);if(y){for(const w of y)l.add(w);c||(c=!0,Wu(d))}}return!0}}),p=h=>{const b=()=>{const g=a;a=b;try{return h()}finally{a=g}};return b()};return e.addEventListener("abort",()=>{n=!0}),{state:m,createEffect:p}}function zp(e,n,a){if(e.length!==n.length)return!1;for(let o=0;o{l.disconnect()})),l.observe(e)}}const Pp=[],{assign:mu}=Object;function vP(e,n){const a={},o=new AbortController,l=o.signal,{state:c,createEffect:d}=gP(l),m=new Map;mu(c,{skinToneEmoji:void 0,i18n:void 0,database:void 0,customEmoji:void 0,customCategorySorting:void 0,emojiVersion:void 0}),mu(c,n),mu(c,{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:Pz,isRtl:!1,currentGroupIndex:0,groups:Mp,databaseLoaded:!1,activeSearchItemId:void 0}),d(()=>{c.currentGroup!==c.groups[c.currentGroupIndex]&&(c.currentGroup=c.groups[c.currentGroupIndex])});const p=Y=>{e.getElementById(Y).focus()},h=Y=>e.getElementById(`emo-${Y.id}`),b=(Y,le)=>{a.rootElement.dispatchEvent(new CustomEvent(Y,{detail:le,bubbles:!0,composed:!0}))},g=(Y,le)=>Y.id===le.id,y=(Y,le)=>{const{category:ye,emojis:Te}=Y,{category:Le,emojis:rt}=le;return ye!==Le?!1:zp(Te,rt,g)},w=Y=>{zp(c.currentEmojis,Y,g)||(c.currentEmojis=Y)},j=Y=>{c.searchMode!==Y&&(c.searchMode=Y)},S=Y=>{zp(c.currentEmojisWithCategories,Y,y)||(c.currentEmojisWithCategories=Y)},E=(Y,le)=>le&&Y.skins&&Y.skins[le]||Y.unicode,T={labelWithSkin:(Y,le)=>eP([Y.name||E(Y,le),Y.annotation,...Y.shortcodes||Pp].filter(Boolean)).join(", "),titleForEmoji:Y=>Y.annotation||(Y.shortcodes||Pp).join(", "),unicodeWithSkin:E},A={onClickSkinToneButton:F,onEmojiClick:D,onNavClick:H,onNavKeydown:Z,onSearchKeydown:I,onSkinToneOptionsClick:V,onSkinToneOptionsFocusOut:be,onSkinToneOptionsKeydown:oe,onSkinToneOptionsKeyup:ae,onSearchInput:ve},O={calculateEmojiGridStyle:B,updateOnIntersection:K};let M=!0;d(()=>{hP(e,c,T,A,O,a,l,m,M),M=!1}),c.emojiVersion||Op().then(Y=>{Y||(c.message=c.i18n.emojiUnsupportedMessage)}),d(()=>{async function Y(){let le=!1;const ye=setTimeout(()=>{le=!0,c.message=c.i18n.loadingMessage},Lz);try{await c.database.ready(),c.databaseLoaded=!0}catch(Te){console.error(Te),c.message=c.i18n.networkErrorMessage}finally{clearTimeout(ye),le&&(le=!1,c.message="")}}c.database&&Y()}),d(()=>{c.pickerStyle=` --num-groups: ${c.groups.length}; --indicator-opacity: ${c.searchMode?0:1}; --num-skintones: ${i0};`}),d(()=>{c.customEmoji&&c.database&&z()}),d(()=>{c.customEmoji&&c.customEmoji.length?c.groups!==Nh&&(c.groups=Nh):c.groups!==Mp&&(c.currentGroupIndex&&c.currentGroupIndex--,c.groups=Mp)}),d(()=>{async function Y(){c.databaseLoaded&&(c.currentSkinTone=await c.database.getPreferredSkinTone())}Y()}),d(()=>{c.skinTones=Array(i0).fill().map((Y,le)=>qz(c.skinToneEmoji,le))}),d(()=>{c.skinToneButtonText=c.skinTones[c.currentSkinTone]}),d(()=>{c.skinToneButtonLabel=c.i18n.skinToneLabel.replace("{skinTone}",c.i18n.skinTones[c.currentSkinTone])}),d(()=>{async function Y(){const{database:le}=c,ye=(await Promise.all(Iz.map(Te=>le.getEmojiByUnicodeOrName(Te)))).filter(Boolean);c.defaultFavoriteEmojis=ye}c.databaseLoaded&&Y()});function z(){const{customEmoji:Y,database:le}=c,ye=Y||Pp;le.customEmoji!==ye&&(le.customEmoji=ye)}d(()=>{async function Y(){z();const{database:le,defaultFavoriteEmojis:ye,numColumns:Te}=c,Le=await le.getTopFavoriteEmoji(Te),rt=await xe(H5([...Le,...ye],ht=>ht.unicode||ht.name).slice(0,Te));c.currentFavorites=rt}c.databaseLoaded&&c.defaultFavoriteEmojis&&Y()});function B(Y){Zz(Y,l,()=>{{const le=getComputedStyle(a.rootElement),ye=parseInt(le.getPropertyValue("--num-columns"),10),Te=le.getPropertyValue("direction")==="rtl";c.numColumns=ye,c.isRtl=Te}})}function K(Y){xP(Y,l,le=>{for(const{target:ye,isIntersecting:Te}of le)ye.classList.toggle("onscreen",Te)})}d(()=>{async function Y(){const{searchText:le,currentGroup:ye,databaseLoaded:Te,customEmoji:Le}=c;if(!Te)c.currentEmojis=[],c.searchMode=!1;else if(le.length>=Oz){const rt=await L(le);c.searchText===le&&(w(rt),j(!0))}else{const{id:rt}=ye;if(rt!==-1||Le&&Le.length){const ht=await se(rt);c.currentGroup.id===rt&&(w(ht),j(!1))}}}Y()});const U=()=>{Nu(()=>tP(a.tabpanelElement))};d(()=>{const{currentEmojis:Y,emojiVersion:le}=c,ye=Y.filter(Te=>Te.unicode).filter(Te=>l0(Te)&&!Eh.has(Te.unicode));if(!le&&ye.length)w(Y),Nu(()=>q(ye));else{const Te=le?Y:Y.filter(ue);w(Te),U()}});function q(Y){Jz(Y,a.baselineEmoji,h)?U():c.currentEmojis=[...c.currentEmojis]}function ue(Y){return!Y.unicode||!l0(Y)||Eh.get(Y.unicode)}async function pe(Y){const le=c.emojiVersion||await Op();return Y.filter(({version:ye})=>!ye||ye<=le)}async function xe(Y){return Kz(Y,c.emojiVersion||await Op())}async function se(Y){const le=Y===-1?c.customEmoji:await c.database.getEmojiByGroup(Y);return xe(await pe(le))}async function L(Y){return xe(await pe(await c.database.getEmojiBySearchQuery(Y)))}d(()=>{}),d(()=>{function Y(){const{searchMode:ye,currentEmojis:Te}=c;if(ye)return[{category:"",emojis:Te}];const Le=new Map;for(const rt of Te){const ht=rt.category||"";let Mt=Le.get(ht);Mt||(Mt=[],Le.set(ht,Mt)),Mt.push(rt)}return[...Le.entries()].map(([rt,ht])=>({category:rt,emojis:ht})).sort((rt,ht)=>c.customCategorySorting(rt.category,ht.category))}const le=Y();S(le)}),d(()=>{c.activeSearchItemId=c.activeSearchItem!==-1&&c.currentEmojis[c.activeSearchItem].id}),d(()=>{const{rawSearchText:Y}=c;B5(()=>{c.searchText=(Y||"").trim(),c.activeSearchItem=-1})});function I(Y){if(!c.searchMode||!c.currentEmojis.length)return;const le=ye=>{yr(Y),c.activeSearchItem=Dp(ye,c.activeSearchItem,c.currentEmojis)};switch(Y.key){case"ArrowDown":return le(!1);case"ArrowUp":return le(!0);case"Enter":if(c.activeSearchItem===-1)c.activeSearchItem=0;else return yr(Y),_(c.currentEmojis[c.activeSearchItem].id)}}function H(Y){const{target:le}=Y,ye=le.closest(".nav-button");if(!ye)return;const Te=parseInt(ye.dataset.groupId,10);a.searchElement.value="",c.rawSearchText="",c.searchText="",c.activeSearchItem=-1,c.currentGroupIndex=c.groups.findIndex(Le=>Le.id===Te)}function Z(Y){const{target:le,key:ye}=Y,Te=Le=>{Le&&(yr(Y),Le.focus())};switch(ye){case"ArrowLeft":return Te(le.previousElementSibling);case"ArrowRight":return Te(le.nextElementSibling);case"Home":return Te(le.parentElement.firstElementChild);case"End":return Te(le.parentElement.lastElementChild)}}async function te(Y){const le=await c.database.getEmojiByUnicodeOrName(Y),ye=[...c.currentEmojis,...c.currentFavorites].find(Le=>Le.id===Y),Te=ye.unicode&&E(ye,c.currentSkinTone);return await c.database.incrementFavoriteEmojiCount(Y),{emoji:le,skinTone:c.currentSkinTone,...Te&&{unicode:Te},...ye.name&&{name:ye.name}}}async function _(Y){const le=te(Y);b("emoji-click-sync",le),b("emoji-click",await le)}function D(Y){const{target:le}=Y;if(!le.classList.contains("emoji"))return;yr(Y);const ye=le.id.substring(4);_(ye)}function G(Y){c.currentSkinTone=Y,c.skinTonePickerExpanded=!1,p("skintone-button"),b("skin-tone-change",{skinTone:Y}),c.database.setPreferredSkinTone(Y)}function V(Y){const{target:{id:le}}=Y,ye=le&&le.match(/^skintone-(\d)/);if(!ye)return;yr(Y);const Te=parseInt(ye[1],10);G(Te)}function F(Y){c.skinTonePickerExpanded=!c.skinTonePickerExpanded,c.activeSkinTone=c.currentSkinTone,c.skinTonePickerExpanded&&(yr(Y),Nu(()=>p("skintone-list")))}d(()=>{c.skinTonePickerExpanded?a.skinToneDropdown.addEventListener("transitionend",()=>{c.skinTonePickerExpandedAfterAnimation=!0},{once:!0}):c.skinTonePickerExpandedAfterAnimation=!1});function oe(Y){if(!c.skinTonePickerExpanded)return;const le=async ye=>{yr(Y),c.activeSkinTone=ye};switch(Y.key){case"ArrowUp":return le(Dp(!0,c.activeSkinTone,c.skinTones));case"ArrowDown":return le(Dp(!1,c.activeSkinTone,c.skinTones));case"Home":return le(0);case"End":return le(c.skinTones.length-1);case"Enter":return yr(Y),G(c.activeSkinTone);case"Escape":return yr(Y),c.skinTonePickerExpanded=!1,p("skintone-button")}}function ae(Y){if(c.skinTonePickerExpanded)switch(Y.key){case" ":return yr(Y),G(c.activeSkinTone)}}async function be(Y){const{relatedTarget:le}=Y;(!le||le.id!=="skintone-list")&&(c.skinTonePickerExpanded=!1)}function ve(Y){c.rawSearchText=Y.target.value}return{$set(Y){mu(c,Y)},$destroy(){o.abort()}}}const bP="https://cdn.jsdelivr.net/npm/emoji-picker-element-data@^1/en/emojibase/data.json",yP="en";var wP={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"}},CP=':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 V5=["customEmoji","customCategorySorting","database","dataSource","i18n","locale","skinToneEmoji","emojiVersion"],SP=`:host{--emoji-font-family:${U5}}`;class Hg extends HTMLElement{constructor(n){super(),this.attachShadow({mode:"open"});const a=document.createElement("style");a.textContent=CP+SP,this.shadowRoot.appendChild(a),this._ctx={locale:yP,dataSource:bP,skinToneEmoji:zz,customCategorySorting:$z,customEmoji:null,i18n:wP,emojiVersion:null,...n};for(const o of V5)o!=="database"&&Object.prototype.hasOwnProperty.call(this,o)&&(this._ctx[o]=this[o],delete this[o]);this._dbFlush()}connectedCallback(){h0(this),this._cmp||(this._cmp=vP(this.shadowRoot,this._ctx))}disconnectedCallback(){h0(this),Wu(()=>{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,(l,c)=>c.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 _z({locale:n,dataSource:a}))}_dbFlush(){Wu(()=>this._dbCreate())}}const G5={};for(const e of V5)G5[e]={get(){return e==="database"&&this._dbCreate(),this._ctx[e]},set(n){if(e==="database")throw new Error("database is read-only");this._set(e,n)}};Object.defineProperties(Hg.prototype,G5);function h0(e){e instanceof Hg||Object.setPrototypeOf(e,customElements.get(e.tagName.toLowerCase()).prototype)}customElements.get("emoji-picker")||customElements.define("emoji-picker",Hg);function jP({onPick:e}){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 l=c=>{var p;const d=c.detail,m=(d==null?void 0:d.unicode)??((p=d==null?void 0:d.emoji)==null?void 0:p.unicode);m&&e(m)};return o.addEventListener("emoji-click",l),a.appendChild(o),()=>{o.removeEventListener("emoji-click",l),o.remove()}},[e]),s.jsx("div",{ref:n,className:"unicode-emoji-panel-host overflow-hidden rounded-lg border border-border/50"})}const NP=/^<(a?):([^:>]+):(\d{17,20})>$/;function Eu(e,n,a=!1){return`${a?"`}function F5(e){const n=String(e??"").trim();if(!n)return{kind:"empty",value:""};const a=n.match(NP);return a?{kind:"custom",value:n,animated:a[1]==="a",name:a[2],id:a[3]}:{kind:"unicode",value:n}}function W5(e,n=!1){return`https://cdn.discordapp.com/emojis/${e}.${n?"gif":"png"}?size=64`}function EP(e,n=[]){const a=F5(e);if(a.kind==="custom"&&a.id&&!a.name){const o=n.find(l=>l.id===a.id);if(o)return{kind:"custom",value:Eu(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(l=>l.id===a.id);if(o&&a.value!==Eu(o.name,o.id,o.animated))return{kind:"custom",value:Eu(o.name,o.id,o.animated),name:o.name,id:o.id,animated:o.animated}}return a}function kP({value:e,guildEmojis:n,size:a="md"}){const o=EP(e,n),l=a==="lg"?"size-10":"size-7",c=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:W5(o.id,o.animated),alt:o.name??"custom emoji",className:fe(l,"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:fe(c,"leading-none"),title:o.value,children:o.value})}function TP({id:e,label:n,description:a,value:o,onChange:l,readOnly:c}){const[d,m]=f.useState(!1),[p,h]=f.useState("server"),[b,g]=f.useState(null),[y,w]=f.useState(""),[j,S]=f.useState(!1),[E,N]=f.useState(""),k=f.useCallback(async(U=!1)=>{S(!0),w("");try{const q=await Ee.getGuildResources(U);q.data?(g(q.data),Array.isArray(q.data.emojis)||w("Server response is missing emojis. Restart the bot after updating.")):w("No guild data returned.")}catch(q){w(q instanceof Error?q.message:"Could not load server emojis")}finally{S(!1)}},[]);f.useEffect(()=>{d&&k(!0)},[d,k]);const T=f.useMemo(()=>Array.isArray(b==null?void 0:b.emojis)?b.emojis:[],[b]),A=f.useMemo(()=>{const U=E.trim().toLowerCase();return U?T.filter(q=>q.name.toLowerCase().includes(U)):T},[T,E]),O=String(o??""),M=F5(O);function z(U){l(U),m(!1)}function B(U){l(Eu(U.name,U.id,U.animated)),m(!1)}function K(){l("")}return s.jsxs("div",{className:"space-y-2",children:[s.jsx(ze,{htmlFor:e,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(kP,{value:o,guildEmojis:T,size:"lg"})}),s.jsxs("div",{className:"flex shrink-0 gap-2",children:[s.jsx(he,{type:"button",variant:"secondary",size:"sm",disabled:c,onClick:()=>m(!0),children:"Choose emoji"}),O?s.jsx(he,{type:"button",variant:"ghost",size:"sm",disabled:c,onClick:K,children:"Clear"}):null]})]}),s.jsx(zl,{open:d,onOpenChange:m,children:s.jsxs(qs,{className:"max-h-[min(90vh,720px)] max-w-lg gap-0 overflow-hidden p-0 sm:max-w-xl",children:[s.jsxs(Ks,{className:"space-y-1 border-b border-border px-5 py-4",children:[s.jsx(Xs,{children:"Choose emoji"}),s.jsxs(Zs,{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(N5,{value:p,onValueChange:U=>h(U),className:"flex min-h-0 flex-1 flex-col",children:[s.jsxs(zg,{className:"mx-5 mt-3 grid h-9 w-auto grid-cols-2",children:[s.jsx(xo,{value:"server",children:"Server"}),s.jsx(xo,{value:"unicode",children:"All emojis"})]}),s.jsxs(wh,{value:"server",className:"mt-0 flex-1 px-5 pb-4 pt-3",children:[s.jsxs("div",{className:"relative mb-3",children:[s.jsx(ge,{icon:ad,size:16,className:"pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground"}),s.jsx(Ie,{placeholder:"Search by name…",value:E,onChange:U=>N(U.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," · ",T.length," custom emoji",T.length===1?"":"s"]}):null,s.jsx($l,{className:"h-[min(50vh,320px)] rounded-lg border border-border/50 bg-secondary/20",children:j?s.jsx("div",{className:"grid grid-cols-6 gap-2 p-3 sm:grid-cols-8",children:Array.from({length:24}).map((U,q)=>s.jsx(Be,{className:"aspect-square rounded-lg"},q))}):y?s.jsxs("div",{className:"space-y-3 p-4 text-center",children:[s.jsx("p",{className:"text-sm text-destructive",children:y}),s.jsx(he,{type:"button",variant:"outline",size:"sm",onClick:()=>void k(!0),children:"Retry"})]}):A.length===0?s.jsx("p",{className:"p-6 text-center text-sm text-muted-foreground",children:T.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:A.map(U=>{const q=M.kind==="custom"&&M.id===U.id;return s.jsx("button",{type:"button",title:`:${U.name}:`,className:fe("flex aspect-square items-center justify-center rounded-lg border border-transparent bg-background/50 transition-colors hover:border-primary/30 hover:bg-accent",q&&"border-primary/50 bg-primary/15 ring-2 ring-primary/30"),onClick:()=>B(U),children:s.jsx("img",{src:U.url??W5(U.id,U.animated),alt:U.name,className:"size-8 object-contain",loading:"lazy"})},U.id)})})})]}),s.jsx(wh,{value:"unicode",className:"mt-0 px-5 pb-4 pt-3",children:s.jsx(jP,{onPick:z})})]})]})}),s.jsx(Ie,{value:O,disabled:c,onChange:U=>l(U.target.value),placeholder:"Unicode or <:name:id>",className:"border-border bg-secondary/30 font-mono text-xs"})]})}const g0="BOT_TOKEN",RP="MODEL_API_KEY";function Vg({field:e,value:n,onChange:a,readOnly:o}){const l=e.path.replace(/\./g,"-");if(e.type==="googleFont")return s.jsx(_L,{field:e,value:n,onChange:a,readOnly:o});if(e.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(ze,{htmlFor:l,className:"font-medium",children:e.label}),e.description?s.jsx("p",{className:"text-xs text-muted-foreground",children:e.description}):null]}),s.jsx(At,{id:l,checked:!!n,disabled:o,onCheckedChange:a})]});if(e.type==="stringList")return s.jsxs("div",{className:"space-y-2",children:[s.jsx(ze,{children:e.label}),e.description?s.jsx("p",{className:"text-xs text-muted-foreground",children:e.description}):null,s.jsx(RL,{value:Array.isArray(n)?n:[],onChange:a})]});if(e.type==="select"&&e.options)return s.jsxs("div",{className:"space-y-2",children:[s.jsx(ze,{htmlFor:l,children:e.label}),s.jsxs(No,{value:String(n??""),disabled:o,onValueChange:a,children:[s.jsx(Ba,{id:l,className:"border-border bg-secondary/30",children:s.jsx(Eo,{placeholder:"Select…"})}),s.jsx(Ua,{children:e.options.map(d=>s.jsx(an,{value:d.value,children:d.label},d.value))})]})]});if(e.type==="color"){const d=jr(String(n??"#000000"));return s.jsxs("div",{className:"space-y-2",children:[s.jsx(ze,{htmlFor:l,children:e.label}),e.description?s.jsx("p",{className:"text-xs text-muted-foreground",children:e.description}):null,s.jsxs("div",{className:"flex gap-2",children:[s.jsx(Id,{value:d,onChange:a}),s.jsx(Ie,{id:l,value:d,disabled:o,onChange:m=>a(m.target.value),onBlur:m=>a(jr(m.target.value,d)),className:"border-border bg-secondary/30 font-mono uppercase",placeholder:"#000000",maxLength:7})]})]})}if(e.type==="emoji")return s.jsx(TP,{id:l,label:e.label,description:e.description,value:n,onChange:a,readOnly:o});if(e.type==="discordChannel"||e.type==="discordRole"||e.type==="discordCategory"){const d=e.type==="discordRole"?"role":e.type==="discordCategory"?"category":"channel";return s.jsx(OL,{id:l,label:e.label,description:e.description,kind:d,value:n,onChange:a,readOnly:o})}if(e.type==="secret"){const d=n===g0||n===RP||!n?"":"••••••••••••";return s.jsxs("div",{className:"space-y-2",children:[s.jsx(ze,{htmlFor:l,children:e.label}),e.description?s.jsx("p",{className:"text-xs text-muted-foreground",children:e.description}):null,s.jsx(Ie,{id:l,type:"password",value:d,disabled:o,placeholder:e.placeholder??"Unchanged if empty",onChange:m=>{const p=m.target.value;a(p||(e.placeholder??g0))},className:"border-border bg-secondary/30"})]})}const c="border-border bg-secondary/30";return e.type==="textarea"?s.jsxs("div",{className:"space-y-2",children:[s.jsx(ze,{htmlFor:l,children:e.label}),s.jsx(Ld,{id:l,value:String(n??""),disabled:o,onChange:d=>a(d.target.value),className:`min-h-[88px] ${c}`})]}):s.jsxs("div",{className:"space-y-2",children:[s.jsx(ze,{htmlFor:l,children:e.label}),e.description?s.jsx("p",{className:"text-xs text-muted-foreground",children:e.description}):null,s.jsx(Ie,{id:l,type:e.type==="number"?"number":"text",value:n==null?"":String(n),disabled:o,onChange:d=>a(e.type==="number"?Number(d.target.value):d.target.value),placeholder:e.placeholder??(e.type==="discordId"?"Discord snowflake ID":void 0),className:c})]})}const Xe=f.forwardRef(({className:e,...n},a)=>s.jsx("div",{ref:a,className:fe("rounded-xl border border-border bg-card text-card-foreground shadow-none",e),...n}));Xe.displayName="Card";const it=f.forwardRef(({className:e,...n},a)=>s.jsx("div",{ref:a,className:fe("flex flex-col space-y-1.5 p-6",e),...n}));it.displayName="CardHeader";const lt=f.forwardRef(({className:e,...n},a)=>s.jsx("div",{ref:a,className:fe("font-semibold leading-none tracking-tight",e),...n}));lt.displayName="CardTitle";const Et=f.forwardRef(({className:e,...n},a)=>s.jsx("div",{ref:a,className:fe("text-sm text-muted-foreground",e),...n}));Et.displayName="CardDescription";const Ze=f.forwardRef(({className:e,...n},a)=>s.jsx("div",{ref:a,className:fe("p-6 pt-0",e),...n}));Ze.displayName="CardContent";const Gg=f.forwardRef(({className:e,...n},a)=>s.jsx("div",{ref:a,className:fe("flex items-center p-6 pt-0",e),...n}));Gg.displayName="CardFooter";function x0(e){return e.replace(/_/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/\b\w/g,n=>n.toUpperCase())}function AP(e,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=e.toLowerCase();return/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 Fg(e,n=""){const a=[];for(const[o,l]of Object.entries(e)){const c=n?`${n}.${o}`:o;if(Array.isArray(l)){if(l.length>0&&typeof l[0]=="object"&&l[0]!==null&&!Array.isArray(l[0]))continue;a.push({path:c,label:x0(o),type:"stringList"});continue}if(l&&typeof l=="object"&&Object.keys(l).length>0){a.push(...Fg(l,c));continue}a.push({path:c,label:x0(o),type:AP(o,l)})}return a}function MP(e){const n=Fg(e);return n.length===0?[{title:"Configuration",fields:[]}]:[{title:"Settings",description:"Values from this addon’s config file.",fields:n}]}function To(e,n){const a=n.split(".");let o=e;for(const l of a){if(o==null||typeof o!="object")return;o=o[l]}return o}function xl(e,n,a){const o=n.split("."),l=structuredClone(e);let c=l;for(let d=0;d"u")return;let n=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");a.type="text/css",n.appendChild(a),a.styleSheet?a.styleSheet.cssText=e:a.appendChild(document.createTextNode(e))}const OP=e=>{switch(e){case"success":return zP;case"info":return IP;case"warning":return PP;case"error":return $P;default:return null}},DP=Array(12).fill(0),LP=({visible:e,className:n})=>me.createElement("div",{className:["sonner-loading-wrapper",n].filter(Boolean).join(" "),"data-visible":e},me.createElement("div",{className:"sonner-spinner"},DP.map((a,o)=>me.createElement("div",{className:"sonner-loading-bar",key:`spinner-bar-${o}`})))),zP=me.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",height:"20",width:"20"},me.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"})),PP=me.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",height:"20",width:"20"},me.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"})),IP=me.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",height:"20",width:"20"},me.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"})),$P=me.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",height:"20",width:"20"},me.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"})),BP=me.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"},me.createElement("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),me.createElement("line",{x1:"6",y1:"6",x2:"18",y2:"18"})),UP=()=>{const[e,n]=me.useState(document.hidden);return me.useEffect(()=>{const a=()=>{n(document.hidden)};return document.addEventListener("visibilitychange",a),()=>window.removeEventListener("visibilitychange",a)},[]),e};let kh=1;class HP{constructor(){this.subscribe=n=>(this.subscribers.push(n),()=>{const a=this.subscribers.indexOf(n);this.subscribers.splice(a,1)}),this.publish=n=>{this.subscribers.forEach(a=>a(n))},this.addToast=n=>{this.publish(n),this.toasts=[...this.toasts,n]},this.create=n=>{var a;const{message:o,...l}=n,c=typeof(n==null?void 0:n.id)=="number"||((a=n.id)==null?void 0:a.length)>0?n.id:kh++,d=this.toasts.find(p=>p.id===c),m=n.dismissible===void 0?!0:n.dismissible;return this.dismissedToasts.has(c)&&this.dismissedToasts.delete(c),d?this.toasts=this.toasts.map(p=>p.id===c?(this.publish({...p,...n,id:c,title:o}),{...p,...n,id:c,dismissible:m,title:o}):p):this.addToast({title:o,...l,dismissible:m,id:c}),c},this.dismiss=n=>(n?(this.dismissedToasts.add(n),requestAnimationFrame(()=>this.subscribers.forEach(a=>a({id:n,dismiss:!0})))):this.toasts.forEach(a=>{this.subscribers.forEach(o=>o({id:a.id,dismiss:!0}))}),n),this.message=(n,a)=>this.create({...a,message:n}),this.error=(n,a)=>this.create({...a,message:n,type:"error"}),this.success=(n,a)=>this.create({...a,type:"success",message:n}),this.info=(n,a)=>this.create({...a,type:"info",message:n}),this.warning=(n,a)=>this.create({...a,type:"warning",message:n}),this.loading=(n,a)=>this.create({...a,type:"loading",message:n}),this.promise=(n,a)=>{if(!a)return;let o;a.loading!==void 0&&(o=this.create({...a,promise:n,type:"loading",message:a.loading,description:typeof a.description!="function"?a.description:void 0}));const l=Promise.resolve(n instanceof Function?n():n);let c=o!==void 0,d;const m=l.then(async h=>{if(d=["resolve",h],me.isValidElement(h))c=!1,this.create({id:o,type:"default",message:h});else if(GP(h)&&!h.ok){c=!1;const g=typeof a.error=="function"?await a.error(`HTTP error! status: ${h.status}`):a.error,y=typeof a.description=="function"?await a.description(`HTTP error! status: ${h.status}`):a.description,j=typeof g=="object"&&!me.isValidElement(g)?g:{message:g};this.create({id:o,type:"error",description:y,...j})}else if(h instanceof Error){c=!1;const g=typeof a.error=="function"?await a.error(h):a.error,y=typeof a.description=="function"?await a.description(h):a.description,j=typeof g=="object"&&!me.isValidElement(g)?g:{message:g};this.create({id:o,type:"error",description:y,...j})}else if(a.success!==void 0){c=!1;const g=typeof a.success=="function"?await a.success(h):a.success,y=typeof a.description=="function"?await a.description(h):a.description,j=typeof g=="object"&&!me.isValidElement(g)?g:{message:g};this.create({id:o,type:"success",description:y,...j})}}).catch(async h=>{if(d=["reject",h],a.error!==void 0){c=!1;const b=typeof a.error=="function"?await a.error(h):a.error,g=typeof a.description=="function"?await a.description(h):a.description,w=typeof b=="object"&&!me.isValidElement(b)?b:{message:b};this.create({id:o,type:"error",description:g,...w})}}).finally(()=>{c&&(this.dismiss(o),o=void 0),a.finally==null||a.finally.call(a)}),p=()=>new Promise((h,b)=>m.then(()=>d[0]==="reject"?b(d[1]):h(d[1])).catch(b));return typeof o!="string"&&typeof o!="number"?{unwrap:p}:Object.assign(o,{unwrap:p})},this.custom=(n,a)=>{const o=(a==null?void 0:a.id)||kh++;return this.create({jsx:n(o),id:o,...a}),o},this.getActiveToasts=()=>this.toasts.filter(n=>!this.dismissedToasts.has(n.id)),this.subscribers=[],this.toasts=[],this.dismissedToasts=new Set}}const wn=new HP,VP=(e,n)=>{const a=(n==null?void 0:n.id)||kh++;return wn.addToast({title:e,...n,id:a}),a},GP=e=>e&&typeof e=="object"&&"ok"in e&&typeof e.ok=="boolean"&&"status"in e&&typeof e.status=="number",FP=VP,WP=()=>wn.toasts,YP=()=>wn.getActiveToasts(),Bt=Object.assign(FP,{success:wn.success,info:wn.info,warning:wn.warning,error:wn.error,custom:wn.custom,message:wn.message,promise:wn.promise,dismiss:wn.dismiss,loading:wn.loading},{getHistory:WP,getToasts:YP});_P("[data-sonner-toaster][dir=ltr],html[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%)}[data-sonner-toaster][dir=rtl],html[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%)}[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:0;z-index:999999999;transition:transform .4s ease}@media (hover:none) and (pointer:coarse){[data-sonner-toaster][data-lifted=true]{transform:none}}[data-sonner-toaster][data-x-position=right]{right:var(--offset-right)}[data-sonner-toaster][data-x-position=left]{left:var(--offset-left)}[data-sonner-toaster][data-x-position=center]{left:50%;transform:translateX(-50%)}[data-sonner-toaster][data-y-position=top]{top:var(--offset-top)}[data-sonner-toaster][data-y-position=bottom]{bottom:var(--offset-bottom)}[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);touch-action:none;transition:transform .4s,opacity .4s,height .4s,box-shadow .2s;box-sizing:border-box;outline:0;overflow-wrap:anywhere}[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 rgba(0,0,0,.1);width:var(--width);font-size:13px;display:flex;align-items:center;gap:6px}[data-sonner-toast]:focus-visible{box-shadow:0 4px 12px rgba(0,0,0,.1),0 0 0 2px rgba(0,0,0,.2)}[data-sonner-toast][data-y-position=top]{top:0;--y:translateY(-100%);--lift:1;--lift-amount:calc(1 * var(--gap))}[data-sonner-toast][data-y-position=bottom]{bottom:0;--y:translateY(100%);--lift:-1;--lift-amount:calc(var(--lift) * var(--gap))}[data-sonner-toast][data-styled=true] [data-description]{font-weight:400;line-height:1.4;color:#3f3f3f}[data-rich-colors=true][data-sonner-toast][data-styled=true] [data-description]{color:inherit}[data-sonner-toaster][data-sonner-theme=dark] [data-description]{color:#e8e8e8}[data-sonner-toast][data-styled=true] [data-title]{font-weight:500;line-height:1.5;color:inherit}[data-sonner-toast][data-styled=true] [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)}[data-sonner-toast][data-promise=true] [data-icon]>svg{opacity:0;transform:scale(.8);transform-origin:center;animation:sonner-fade-in .3s ease forwards}[data-sonner-toast][data-styled=true] [data-icon]>*{flex-shrink:0}[data-sonner-toast][data-styled=true] [data-icon] svg{margin-left:var(--toast-svg-margin-start);margin-right:var(--toast-svg-margin-end)}[data-sonner-toast][data-styled=true] [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;font-weight:500;cursor:pointer;outline:0;display:flex;align-items:center;flex-shrink:0;transition:opacity .4s,box-shadow .2s}[data-sonner-toast][data-styled=true] [data-button]:focus-visible{box-shadow:0 0 0 2px rgba(0,0,0,.4)}[data-sonner-toast][data-styled=true] [data-button]:first-of-type{margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end)}[data-sonner-toast][data-styled=true] [data-cancel]{color:var(--normal-text);background:rgba(0,0,0,.08)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast][data-styled=true] [data-cancel]{background:rgba(255,255,255,.3)}[data-sonner-toast][data-styled=true] [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);background:var(--normal-bg);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-styled=true] [data-close-button]:focus-visible{box-shadow:0 4px 12px rgba(0,0,0,.1),0 0 0 2px rgba(0,0,0,.2)}[data-sonner-toast][data-styled=true] [data-disabled=true]{cursor:not-allowed}[data-sonner-toast][data-styled=true]:hover [data-close-button]:hover{background:var(--gray2);border-color:var(--gray5)}[data-sonner-toast][data-swiping=true]::before{content:'';position:absolute;left:-100%;right:-100%;height:100%;z-index:-1}[data-sonner-toast][data-y-position=top][data-swiping=true]::before{bottom:50%;transform:scaleY(3) translateY(50%)}[data-sonner-toast][data-y-position=bottom][data-swiping=true]::before{top:50%;transform:scaleY(3) translateY(-50%)}[data-sonner-toast][data-swiping=false][data-removed=true]::before{content:'';position:absolute;inset:0;transform:scaleY(2)}[data-sonner-toast][data-expanded=true]::after{content:'';position:absolute;left:0;height:calc(var(--gap) + 1px);bottom:100%;width:100%}[data-sonner-toast][data-mounted=true]{--y:translateY(0);opacity:1}[data-sonner-toast][data-expanded=false][data-front=false]{--scale:var(--toasts-before) * 0.05 + 1;--y:translateY(calc(var(--lift-amount) * var(--toasts-before))) scale(calc(-1 * var(--scale)));height:var(--front-toast-height)}[data-sonner-toast]>*{transition:opacity .4s}[data-sonner-toast][data-x-position=right]{right:0}[data-sonner-toast][data-x-position=left]{left:0}[data-sonner-toast][data-expanded=false][data-front=false][data-styled=true]>*{opacity:0}[data-sonner-toast][data-visible=false]{opacity:0;pointer-events:none}[data-sonner-toast][data-mounted=true][data-expanded=true]{--y:translateY(calc(var(--lift) * var(--offset)));height:var(--initial-height)}[data-sonner-toast][data-removed=true][data-front=true][data-swipe-out=false]{--y:translateY(calc(var(--lift) * -100%));opacity:0}[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}[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}[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,0)) translateX(var(--swipe-amount-x,0));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{from{transform:var(--y) translateX(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translateX(calc(var(--swipe-amount-x) - 100%));opacity:0}}@keyframes swipe-out-right{from{transform:var(--y) translateX(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translateX(calc(var(--swipe-amount-x) + 100%));opacity:0}}@keyframes swipe-out-up{from{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{from{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-sonner-theme=light]{--normal-bg:#fff;--normal-border:var(--gray4);--normal-text:var(--gray12);--success-bg:hsl(143, 85%, 96%);--success-border:hsl(145, 92%, 87%);--success-text:hsl(140, 100%, 27%);--info-bg:hsl(208, 100%, 97%);--info-border:hsl(221, 91%, 93%);--info-text:hsl(210, 92%, 45%);--warning-bg:hsl(49, 100%, 97%);--warning-border:hsl(49, 91%, 84%);--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-sonner-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-sonner-theme=dark] [data-sonner-toast][data-invert=true]{--normal-bg:#fff;--normal-border:var(--gray3);--normal-text:var(--gray12)}[data-sonner-toaster][data-sonner-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, 43%, 17%);--info-text:hsl(216, 87%, 65%);--warning-bg:hsl(64, 100%, 6%);--warning-border:hsl(60, 100%, 9%);--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-sonner-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-sonner-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]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}[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]{background:var(--info-bg);border-color:var(--info-border);color:var(--info-text)}[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]{background:var(--warning-bg);border-color:var(--warning-border);color:var(--warning-text)}[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]{background:var(--error-bg);border-color:var(--error-border);color:var(--error-text)}[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:first-child{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)}100%{opacity:1;transform:scale(1)}}@keyframes sonner-fade-out{0%{opacity:1;transform:scale(1)}100%{opacity:0;transform:scale(.8)}}@keyframes sonner-spin{0%{opacity:1}100%{opacity:.15}}@media (prefers-reduced-motion){.sonner-loading-bar,[data-sonner-toast],[data-sonner-toast]>*{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 pu(e){return e.label!==void 0}const qP=3,KP="24px",XP="16px",v0=4e3,ZP=356,QP=14,JP=45,eI=200;function wr(...e){return e.filter(Boolean).join(" ")}function tI(e){const[n,a]=e.split("-"),o=[];return n&&o.push(n),a&&o.push(a),o}const nI=e=>{var n,a,o,l,c,d,m,p,h;const{invert:b,toast:g,unstyled:y,interacting:w,setHeights:j,visibleToasts:S,heights:E,index:N,toasts:k,expanded:T,removeToast:A,defaultRichColors:O,closeButton:M,style:z,cancelButtonStyle:B,actionButtonStyle:K,className:U="",descriptionClassName:q="",duration:ue,position:pe,gap:xe,expandByDefault:se,classNames:L,icons:I,closeButtonAriaLabel:H="Close toast"}=e,[Z,te]=me.useState(null),[_,D]=me.useState(null),[G,V]=me.useState(!1),[F,oe]=me.useState(!1),[ae,be]=me.useState(!1),[ve,Y]=me.useState(!1),[le,ye]=me.useState(!1),[Te,Le]=me.useState(0),[rt,ht]=me.useState(0),Mt=me.useRef(g.duration||ue||v0),Tr=me.useRef(null),_t=me.useRef(null),Ya=N===0,qa=N+1<=S,qt=g.type,dr=g.dismissible!==!1,Kt=g.className||"",ti=g.descriptionClassName||"",fr=me.useMemo(()=>E.findIndex(Me=>Me.toastId===g.id)||0,[E,g.id]),Lo=me.useMemo(()=>{var Me;return(Me=g.closeButton)!=null?Me:M},[g.closeButton,M]),Rr=me.useMemo(()=>g.duration||ue||v0,[g.duration,ue]),Xt=me.useRef(0),Qn=me.useRef(0),zo=me.useRef(0),mr=me.useRef(null),[pr,Ht]=pe.split("-"),ee=me.useMemo(()=>E.reduce((Me,Je,St)=>St>=fr?Me:Me+Je.height,0),[E,fr]),re=UP(),ke=g.invert||b,we=qt==="loading";Qn.current=me.useMemo(()=>fr*xe+ee,[fr,ee]),me.useEffect(()=>{Mt.current=Rr},[Rr]),me.useEffect(()=>{V(!0)},[]),me.useEffect(()=>{const Me=_t.current;if(Me){const Je=Me.getBoundingClientRect().height;return ht(Je),j(St=>[{toastId:g.id,height:Je,position:g.position},...St]),()=>j(St=>St.filter(kt=>kt.toastId!==g.id))}},[j,g.id]),me.useLayoutEffect(()=>{if(!G)return;const Me=_t.current,Je=Me.style.height;Me.style.height="auto";const St=Me.getBoundingClientRect().height;Me.style.height=Je,ht(St),j(kt=>kt.find(wt=>wt.toastId===g.id)?kt.map(wt=>wt.toastId===g.id?{...wt,height:St}:wt):[{toastId:g.id,height:St,position:g.position},...kt])},[G,g.title,g.description,j,g.id,g.jsx,g.action,g.cancel]);const De=me.useCallback(()=>{oe(!0),Le(Qn.current),j(Me=>Me.filter(Je=>Je.toastId!==g.id)),setTimeout(()=>{A(g)},eI)},[g,A,j,Qn]);me.useEffect(()=>{if(g.promise&&qt==="loading"||g.duration===1/0||g.type==="loading")return;let Me;return T||w||re?(()=>{if(zo.current{Mt.current!==1/0&&(Xt.current=new Date().getTime(),Me=setTimeout(()=>{g.onAutoClose==null||g.onAutoClose.call(g,g),De()},Mt.current))})(),()=>clearTimeout(Me)},[T,w,g,qt,re,De]),me.useEffect(()=>{g.delete&&(De(),g.onDismiss==null||g.onDismiss.call(g,g))},[De,g.delete]);function at(){var Me;if(I!=null&&I.loading){var Je;return me.createElement("div",{className:wr(L==null?void 0:L.loader,g==null||(Je=g.classNames)==null?void 0:Je.loader,"sonner-loader"),"data-visible":qt==="loading"},I.loading)}return me.createElement(LP,{className:wr(L==null?void 0:L.loader,g==null||(Me=g.classNames)==null?void 0:Me.loader),visible:qt==="loading"})}const ct=g.icon||(I==null?void 0:I[qt])||OP(qt);var mt,Zt;return me.createElement("li",{tabIndex:0,ref:_t,className:wr(U,Kt,L==null?void 0:L.toast,g==null||(n=g.classNames)==null?void 0:n.toast,L==null?void 0:L.default,L==null?void 0:L[qt],g==null||(a=g.classNames)==null?void 0:a[qt]),"data-sonner-toast":"","data-rich-colors":(mt=g.richColors)!=null?mt:O,"data-styled":!(g.jsx||g.unstyled||y),"data-mounted":G,"data-promise":!!g.promise,"data-swiped":le,"data-removed":F,"data-visible":qa,"data-y-position":pr,"data-x-position":Ht,"data-index":N,"data-front":Ya,"data-swiping":ae,"data-dismissible":dr,"data-type":qt,"data-invert":ke,"data-swipe-out":ve,"data-swipe-direction":_,"data-expanded":!!(T||se&&G),"data-testid":g.testId,style:{"--index":N,"--toasts-before":N,"--z-index":k.length-N,"--offset":`${F?Te:Qn.current}px`,"--initial-height":se?"auto":`${rt}px`,...z,...g.style},onDragEnd:()=>{be(!1),te(null),mr.current=null},onPointerDown:Me=>{Me.button!==2&&(we||!dr||(Tr.current=new Date,Le(Qn.current),Me.target.setPointerCapture(Me.pointerId),Me.target.tagName!=="BUTTON"&&(be(!0),mr.current={x:Me.clientX,y:Me.clientY})))},onPointerUp:()=>{var Me,Je,St;if(ve||!dr)return;mr.current=null;const kt=Number(((Me=_t.current)==null?void 0:Me.style.getPropertyValue("--swipe-amount-x").replace("px",""))||0),Jn=Number(((Je=_t.current)==null?void 0:Je.style.getPropertyValue("--swipe-amount-y").replace("px",""))||0),wt=new Date().getTime()-((St=Tr.current)==null?void 0:St.getTime()),dn=Z==="x"?kt:Jn,Ka=Math.abs(dn)/wt;if(Math.abs(dn)>=JP||Ka>.11){Le(Qn.current),g.onDismiss==null||g.onDismiss.call(g,g),D(Z==="x"?kt>0?"right":"left":Jn>0?"down":"up"),De(),Y(!0);return}else{var fn,mn;(fn=_t.current)==null||fn.style.setProperty("--swipe-amount-x","0px"),(mn=_t.current)==null||mn.style.setProperty("--swipe-amount-y","0px")}ye(!1),be(!1),te(null)},onPointerMove:Me=>{var Je,St,kt;if(!mr.current||!dr||((Je=window.getSelection())==null?void 0:Je.toString().length)>0)return;const wt=Me.clientY-mr.current.y,dn=Me.clientX-mr.current.x;var Ka;const fn=(Ka=e.swipeDirections)!=null?Ka:tI(pe);!Z&&(Math.abs(dn)>1||Math.abs(wt)>1)&&te(Math.abs(dn)>Math.abs(wt)?"x":"y");let mn={x:0,y:0};const Po=er=>1/(1.5+Math.abs(er)/20);if(Z==="y"){if(fn.includes("top")||fn.includes("bottom"))if(fn.includes("top")&&wt<0||fn.includes("bottom")&&wt>0)mn.y=wt;else{const er=wt*Po(wt);mn.y=Math.abs(er)0)mn.x=dn;else{const er=dn*Po(dn);mn.x=Math.abs(er)0||Math.abs(mn.y)>0)&&ye(!0),(St=_t.current)==null||St.style.setProperty("--swipe-amount-x",`${mn.x}px`),(kt=_t.current)==null||kt.style.setProperty("--swipe-amount-y",`${mn.y}px`)}},Lo&&!g.jsx&&qt!=="loading"?me.createElement("button",{"aria-label":H,"data-disabled":we,"data-close-button":!0,onClick:we||!dr?()=>{}:()=>{De(),g.onDismiss==null||g.onDismiss.call(g,g)},className:wr(L==null?void 0:L.closeButton,g==null||(o=g.classNames)==null?void 0:o.closeButton)},(Zt=I==null?void 0:I.close)!=null?Zt:BP):null,(qt||g.icon||g.promise)&&g.icon!==null&&((I==null?void 0:I[qt])!==null||g.icon)?me.createElement("div",{"data-icon":"",className:wr(L==null?void 0:L.icon,g==null||(l=g.classNames)==null?void 0:l.icon)},g.promise||g.type==="loading"&&!g.icon?g.icon||at():null,g.type!=="loading"?ct:null):null,me.createElement("div",{"data-content":"",className:wr(L==null?void 0:L.content,g==null||(c=g.classNames)==null?void 0:c.content)},me.createElement("div",{"data-title":"",className:wr(L==null?void 0:L.title,g==null||(d=g.classNames)==null?void 0:d.title)},g.jsx?g.jsx:typeof g.title=="function"?g.title():g.title),g.description?me.createElement("div",{"data-description":"",className:wr(q,ti,L==null?void 0:L.description,g==null||(m=g.classNames)==null?void 0:m.description)},typeof g.description=="function"?g.description():g.description):null),me.isValidElement(g.cancel)?g.cancel:g.cancel&&pu(g.cancel)?me.createElement("button",{"data-button":!0,"data-cancel":!0,style:g.cancelButtonStyle||B,onClick:Me=>{pu(g.cancel)&&dr&&(g.cancel.onClick==null||g.cancel.onClick.call(g.cancel,Me),De())},className:wr(L==null?void 0:L.cancelButton,g==null||(p=g.classNames)==null?void 0:p.cancelButton)},g.cancel.label):null,me.isValidElement(g.action)?g.action:g.action&&pu(g.action)?me.createElement("button",{"data-button":!0,"data-action":!0,style:g.actionButtonStyle||K,onClick:Me=>{pu(g.action)&&(g.action.onClick==null||g.action.onClick.call(g.action,Me),!Me.defaultPrevented&&De())},className:wr(L==null?void 0:L.actionButton,g==null||(h=g.classNames)==null?void 0:h.actionButton)},g.action.label):null)};function b0(){if(typeof window>"u"||typeof document>"u")return"ltr";const e=document.documentElement.getAttribute("dir");return e==="auto"||!e?window.getComputedStyle(document.documentElement).direction:e}function rI(e,n){const a={};return[e,n].forEach((o,l)=>{const c=l===1,d=c?"--mobile-offset":"--offset",m=c?XP:KP;function p(h){["top","right","bottom","left"].forEach(b=>{a[`${d}-${b}`]=typeof h=="number"?`${h}px`:h})}typeof o=="number"||typeof o=="string"?p(o):typeof o=="object"?["top","right","bottom","left"].forEach(h=>{o[h]===void 0?a[`${d}-${h}`]=m:a[`${d}-${h}`]=typeof o[h]=="number"?`${o[h]}px`:o[h]}):p(m)}),a}const aI=me.forwardRef(function(n,a){const{id:o,invert:l,position:c="bottom-right",hotkey:d=["altKey","KeyT"],expand:m,closeButton:p,className:h,offset:b,mobileOffset:g,theme:y="light",richColors:w,duration:j,style:S,visibleToasts:E=qP,toastOptions:N,dir:k=b0(),gap:T=QP,icons:A,containerAriaLabel:O="Notifications"}=n,[M,z]=me.useState([]),B=me.useMemo(()=>o?M.filter(G=>G.toasterId===o):M.filter(G=>!G.toasterId),[M,o]),K=me.useMemo(()=>Array.from(new Set([c].concat(B.filter(G=>G.position).map(G=>G.position)))),[B,c]),[U,q]=me.useState([]),[ue,pe]=me.useState(!1),[xe,se]=me.useState(!1),[L,I]=me.useState(y!=="system"?y:typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"),H=me.useRef(null),Z=d.join("+").replace(/Key/g,"").replace(/Digit/g,""),te=me.useRef(null),_=me.useRef(!1),D=me.useCallback(G=>{z(V=>{var F;return(F=V.find(oe=>oe.id===G.id))!=null&&F.delete||wn.dismiss(G.id),V.filter(({id:oe})=>oe!==G.id)})},[]);return me.useEffect(()=>wn.subscribe(G=>{if(G.dismiss){requestAnimationFrame(()=>{z(V=>V.map(F=>F.id===G.id?{...F,delete:!0}:F))});return}setTimeout(()=>{X0.flushSync(()=>{z(V=>{const F=V.findIndex(oe=>oe.id===G.id);return F!==-1?[...V.slice(0,F),{...V[F],...G},...V.slice(F+1)]:[G,...V]})})})}),[M]),me.useEffect(()=>{if(y!=="system"){I(y);return}if(y==="system"&&(window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?I("dark"):I("light")),typeof window>"u")return;const G=window.matchMedia("(prefers-color-scheme: dark)");try{G.addEventListener("change",({matches:V})=>{I(V?"dark":"light")})}catch{G.addListener(({matches:F})=>{try{I(F?"dark":"light")}catch(oe){console.error(oe)}})}},[y]),me.useEffect(()=>{M.length<=1&&pe(!1)},[M]),me.useEffect(()=>{const G=V=>{var F;if(d.every(be=>V[be]||V.code===be)){var ae;pe(!0),(ae=H.current)==null||ae.focus()}V.code==="Escape"&&(document.activeElement===H.current||(F=H.current)!=null&&F.contains(document.activeElement))&&pe(!1)};return document.addEventListener("keydown",G),()=>document.removeEventListener("keydown",G)},[d]),me.useEffect(()=>{if(H.current)return()=>{te.current&&(te.current.focus({preventScroll:!0}),te.current=null,_.current=!1)}},[H.current]),me.createElement("section",{ref:a,"aria-label":`${O} ${Z}`,tabIndex:-1,"aria-live":"polite","aria-relevant":"additions text","aria-atomic":"false",suppressHydrationWarning:!0},K.map((G,V)=>{var F;const[oe,ae]=G.split("-");return B.length?me.createElement("ol",{key:G,dir:k==="auto"?b0():k,tabIndex:-1,ref:H,className:h,"data-sonner-toaster":!0,"data-sonner-theme":L,"data-y-position":oe,"data-x-position":ae,style:{"--front-toast-height":`${((F=U[0])==null?void 0:F.height)||0}px`,"--width":`${ZP}px`,"--gap":`${T}px`,...S,...rI(b,g)},onBlur:be=>{_.current&&!be.currentTarget.contains(be.relatedTarget)&&(_.current=!1,te.current&&(te.current.focus({preventScroll:!0}),te.current=null))},onFocus:be=>{be.target instanceof HTMLElement&&be.target.dataset.dismissible==="false"||_.current||(_.current=!0,te.current=be.relatedTarget)},onMouseEnter:()=>pe(!0),onMouseMove:()=>pe(!0),onMouseLeave:()=>{xe||pe(!1)},onDragEnd:()=>pe(!1),onPointerDown:be=>{be.target instanceof HTMLElement&&be.target.dataset.dismissible==="false"||se(!0)},onPointerUp:()=>se(!1)},B.filter(be=>!be.position&&V===0||be.position===G).map((be,ve)=>{var Y,le;return me.createElement(nI,{key:be.id,icons:A,index:ve,toast:be,defaultRichColors:w,duration:(Y=N==null?void 0:N.duration)!=null?Y:j,className:N==null?void 0:N.className,descriptionClassName:N==null?void 0:N.descriptionClassName,invert:l,visibleToasts:E,closeButton:(le=N==null?void 0:N.closeButton)!=null?le:p,interacting:xe,position:G,style:N==null?void 0:N.style,unstyled:N==null?void 0:N.unstyled,classNames:N==null?void 0:N.classNames,cancelButtonStyle:N==null?void 0:N.cancelButtonStyle,actionButtonStyle:N==null?void 0:N.actionButtonStyle,closeButtonAriaLabel:N==null?void 0:N.closeButtonAriaLabel,removeToast:D,toasts:B.filter(ye=>ye.position==be.position),heights:U.filter(ye=>ye.position==be.position),setHeights:q,expandByDefault:m,gap:T,expanded:ue,swipeDirections:n.swipeDirections})})):null}))});async function ku(e){const n=Bt.loading("Saving changes…");try{const a=await e();if(Bt.success("Changes saved",{id:n}),a.botRestart){const o=Bt.loading("Restarting bot…");a.botRestart.success?Bt.success("Bot started",{id:o}):Bt.error(a.botRestart.error??"Could not start bot",{id:o})}return a}catch(a){throw Bt.error(a instanceof Error?a.message:"Save failed",{id:n}),a}}function oI({filename:e}){const{canEditConfig:n}=Ut(),a=!n("supportbot"),[o,l]=f.useState(null),[c,d]=f.useState(null),[m,p]=f.useState(!0),[h,b]=f.useState(!1),[g,y]=f.useState(""),[w,j]=f.useState(""),S=f.useCallback(async()=>{p(!0),y(""),j("");try{const O=(await Ee.getAddonConfigJson(e)).data??{};l(O),d(structuredClone(O))}catch(A){y(A instanceof Error?A.message:"Failed to load config")}finally{p(!1)}},[e]);f.useEffect(()=>{S()},[S]);const E=o?MP(o):null;function N(A,O){l(M=>M&&xl(M,A,O))}async function k(){if(!(a||!o)){b(!0),y(""),j("");try{const A=await ku(()=>Ee.saveAddonConfig(e,o));j(A.message||"Saved."),await S()}catch(A){y(A instanceof Error?A.message:"Save failed")}finally{b(!1)}}}if(m)return s.jsxs("div",{className:"space-y-4",children:[s.jsx(Be,{className:"h-24 w-full rounded-xl"}),s.jsx(Be,{className:"h-48 w-full rounded-xl"})]});if(!o||!E)return s.jsx(We,{variant:"destructive",children:s.jsx(Ye,{children:g||"Failed to load"})});const T=c&&JSON.stringify(o)!==JSON.stringify(c);return s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[T?s.jsx("span",{className:"text-xs text-amber-500",children:"Unsaved changes"}):null,s.jsx(he,{variant:"outline",size:"sm",onClick:S,disabled:m||h,children:"Reload"}),a?s.jsx("span",{className:"text-xs text-muted-foreground",children:"View only"}):s.jsxs(he,{size:"sm",onClick:k,disabled:h||!T,children:[s.jsx(ge,{icon:nd,size:16,className:"mr-1.5"}),h?"Saving…":"Save"]})]}),g?s.jsxs(We,{variant:"destructive",children:[s.jsx(ge,{icon:Bh,size:18}),s.jsx(Ye,{children:g})]}):null,w?s.jsx(We,{className:"border-primary/30 bg-primary/10 text-primary",children:s.jsx(Ye,{children:w})}):null,E.map(A=>s.jsxs(Xe,{className:"border-border bg-card",children:[s.jsxs(it,{className:"pb-3",children:[s.jsx(lt,{className:"text-base",children:A.title}),A.description?s.jsx(Et,{children:A.description}):null]}),s.jsx(Ze,{className:"grid gap-4 sm:grid-cols-2",children:A.fields.map(O=>s.jsx("div",{className:O.type==="textarea"||O.type==="stringList"?"sm:col-span-2":"",children:s.jsx(Vg,{field:O,value:To(o,O.path),readOnly:a,onChange:M=>N(O.path,M)})},O.path))})]},A.title))]})}function sI(e){return e.replace(/_/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/\b\w/g,n=>n.toUpperCase())}function iI(e,n){const a=new Set(e.flatMap(d=>d.fields.map(m=>m.path))),o=Fg(n).filter(d=>!a.has(d.path));if(o.length===0)return e;const l=new Map;for(const d of o){const m=d.path.split(".")[0]??"Other",p=l.get(m)??[];p.push(d),l.set(m,p)}const c=[...l.entries()].sort(([d],[m])=>d.localeCompare(m)).map(([d,m])=>({title:sI(d),description:"These options exist in your config file but are not in the main editor sections.",fields:m.sort((p,h)=>p.path.localeCompare(h.path))}));return[...e,...c]}function y0(e,n){(n==null||n>e.length)&&(n=e.length);for(var a=0,o=Array(n);a=e.length?e.apply(this,l):function(){for(var d=arguments.length,m=new Array(d),p=0;p1&&arguments[1]!==void 0?arguments[1]:{};hu.initial(e),hu.handler(n);var a={current:e},o=Ji(MI)(a,n),l=Ji(AI)(a),c=Ji(hu.changes)(e),d=Ji(RI)(a);function m(){var h=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(b){return b};return hu.selector(h),h(a.current)}function p(h){bI(o,l,c,d)(h)}return[m,p]}function RI(e,n){return vl(n)?n(e.current):n}function AI(e,n){return e.current=j0(j0({},e.current),n),n}function MI(e,n,a){return vl(n)?n(e.current):Object.keys(a).forEach(function(o){var l;return(l=n[o])===null||l===void 0?void 0:l.call(n,e.current[o])}),a}var _I={create:TI},OI={paths:{vs:"https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs"}};function DI(e){return function n(){for(var a=this,o=arguments.length,l=new Array(o),c=0;c=e.length?e.apply(this,l):function(){for(var d=arguments.length,m=new Array(d),p=0;p{o.current=!1}:e,n)}var Mn=s$;function al(){}function Rs(e,n,a,o){return i$(e,o)||l$(e,n,a,o)}function i$(e,n){return e.editor.getModel(eN(e,n))}function l$(e,n,a,o){return e.editor.createModel(n,a,o?eN(e,o):void 0)}function eN(e,n){return e.Uri.parse(n)}function c$({original:e,modified:n,language:a,originalLanguage:o,modifiedLanguage:l,originalModelPath:c,modifiedModelPath:d,keepCurrentOriginalModel:m=!1,keepCurrentModifiedModel:p=!1,theme:h="light",loading:b="Loading...",options:g={},height:y="100%",width:w="100%",className:j,wrapperProps:S={},beforeMount:E=al,onMount:N=al}){let[k,T]=f.useState(!1),[A,O]=f.useState(!0),M=f.useRef(null),z=f.useRef(null),B=f.useRef(null),K=f.useRef(N),U=f.useRef(E),q=f.useRef(!1);J5(()=>{let se=Z5.init();return se.then(L=>(z.current=L)&&O(!1)).catch(L=>(L==null?void 0:L.type)!=="cancelation"&&console.error("Monaco initialization: error:",L)),()=>M.current?xe():se.cancel()}),Mn(()=>{if(M.current&&z.current){let se=M.current.getOriginalEditor(),L=Rs(z.current,e||"",o||a||"text",c||"");L!==se.getModel()&&se.setModel(L)}},[c],k),Mn(()=>{if(M.current&&z.current){let se=M.current.getModifiedEditor(),L=Rs(z.current,n||"",l||a||"text",d||"");L!==se.getModel()&&se.setModel(L)}},[d],k),Mn(()=>{let se=M.current.getModifiedEditor();se.getOption(z.current.editor.EditorOption.readOnly)?se.setValue(n||""):n!==se.getValue()&&(se.executeEdits("",[{range:se.getModel().getFullModelRange(),text:n||"",forceMoveMarkers:!0}]),se.pushUndoStop())},[n],k),Mn(()=>{var se,L;(L=(se=M.current)==null?void 0:se.getModel())==null||L.original.setValue(e||"")},[e],k),Mn(()=>{let{original:se,modified:L}=M.current.getModel();z.current.editor.setModelLanguage(se,o||a||"text"),z.current.editor.setModelLanguage(L,l||a||"text")},[a,o,l],k),Mn(()=>{var se;(se=z.current)==null||se.editor.setTheme(h)},[h],k),Mn(()=>{var se;(se=M.current)==null||se.updateOptions(g)},[g],k);let ue=f.useCallback(()=>{var I;if(!z.current)return;U.current(z.current);let se=Rs(z.current,e||"",o||a||"text",c||""),L=Rs(z.current,n||"",l||a||"text",d||"");(I=M.current)==null||I.setModel({original:se,modified:L})},[a,n,l,e,o,c,d]),pe=f.useCallback(()=>{var se;!q.current&&B.current&&(M.current=z.current.editor.createDiffEditor(B.current,{automaticLayout:!0,...g}),ue(),(se=z.current)==null||se.editor.setTheme(h),T(!0),q.current=!0)},[g,h,ue]);f.useEffect(()=>{k&&K.current(M.current,z.current)},[k]),f.useEffect(()=>{!A&&!k&&pe()},[A,k,pe]);function xe(){var L,I,H,Z;let se=(L=M.current)==null?void 0:L.getModel();m||((I=se==null?void 0:se.original)==null||I.dispose()),p||((H=se==null?void 0:se.modified)==null||H.dispose()),(Z=M.current)==null||Z.dispose()}return me.createElement(Q5,{width:w,height:y,isEditorReady:k,loading:b,_ref:B,className:j,wrapperProps:S})}var u$=c$;f.memo(u$);function d$(e){let n=f.useRef();return f.useEffect(()=>{n.current=e},[e]),n.current}var f$=d$,gu=new Map;function m$({defaultValue:e,defaultLanguage:n,defaultPath:a,value:o,language:l,path:c,theme:d="light",line:m,loading:p="Loading...",options:h={},overrideServices:b={},saveViewState:g=!0,keepCurrentModel:y=!1,width:w="100%",height:j="100%",className:S,wrapperProps:E={},beforeMount:N=al,onMount:k=al,onChange:T,onValidate:A=al}){let[O,M]=f.useState(!1),[z,B]=f.useState(!0),K=f.useRef(null),U=f.useRef(null),q=f.useRef(null),ue=f.useRef(k),pe=f.useRef(N),xe=f.useRef(),se=f.useRef(o),L=f$(c),I=f.useRef(!1),H=f.useRef(!1);J5(()=>{let _=Z5.init();return _.then(D=>(K.current=D)&&B(!1)).catch(D=>(D==null?void 0:D.type)!=="cancelation"&&console.error("Monaco initialization: error:",D)),()=>U.current?te():_.cancel()}),Mn(()=>{var D,G,V,F;let _=Rs(K.current,e||o||"",n||l||"",c||a||"");_!==((D=U.current)==null?void 0:D.getModel())&&(g&&gu.set(L,(G=U.current)==null?void 0:G.saveViewState()),(V=U.current)==null||V.setModel(_),g&&((F=U.current)==null||F.restoreViewState(gu.get(c))))},[c],O),Mn(()=>{var _;(_=U.current)==null||_.updateOptions(h)},[h],O),Mn(()=>{!U.current||o===void 0||(U.current.getOption(K.current.editor.EditorOption.readOnly)?U.current.setValue(o):o!==U.current.getValue()&&(H.current=!0,U.current.executeEdits("",[{range:U.current.getModel().getFullModelRange(),text:o,forceMoveMarkers:!0}]),U.current.pushUndoStop(),H.current=!1))},[o],O),Mn(()=>{var D,G;let _=(D=U.current)==null?void 0:D.getModel();_&&l&&((G=K.current)==null||G.editor.setModelLanguage(_,l))},[l],O),Mn(()=>{var _;m!==void 0&&((_=U.current)==null||_.revealLine(m))},[m],O),Mn(()=>{var _;(_=K.current)==null||_.editor.setTheme(d)},[d],O);let Z=f.useCallback(()=>{var _;if(!(!q.current||!K.current)&&!I.current){pe.current(K.current);let D=c||a,G=Rs(K.current,o||e||"",n||l||"",D||"");U.current=(_=K.current)==null?void 0:_.editor.create(q.current,{model:G,automaticLayout:!0,...h},b),g&&U.current.restoreViewState(gu.get(D)),K.current.editor.setTheme(d),m!==void 0&&U.current.revealLine(m),M(!0),I.current=!0}},[e,n,a,o,l,c,h,b,g,d,m]);f.useEffect(()=>{O&&ue.current(U.current,K.current)},[O]),f.useEffect(()=>{!z&&!O&&Z()},[z,O,Z]),se.current=o,f.useEffect(()=>{var _,D;O&&T&&((_=xe.current)==null||_.dispose(),xe.current=(D=U.current)==null?void 0:D.onDidChangeModelContent(G=>{H.current||T(U.current.getValue(),G)}))},[O,T]),f.useEffect(()=>{if(O){let _=K.current.editor.onDidChangeMarkers(D=>{var V;let G=(V=U.current.getModel())==null?void 0:V.uri;if(G&&D.find(F=>F.path===G.path)){let F=K.current.editor.getModelMarkers({resource:G});A==null||A(F)}});return()=>{_==null||_.dispose()}}return()=>{}},[O,A]);function te(){var _,D;(_=xe.current)==null||_.dispose(),y?g&&gu.set(c,U.current.saveViewState()):(D=U.current.getModel())==null||D.dispose(),U.current.dispose()}return me.createElement(Q5,{width:w,height:j,isEditorReady:O,loading:p,_ref:q,className:S,wrapperProps:E})}var p$=m$,h$=f.memo(p$),g$=h$;function x$(e){return e!==null&&typeof e=="object"&&"Command"in e}function v$(e){return Object.entries(e).filter(([,n])=>x$(n)).map(([n,a])=>({key:n,...a}))}function b$({data:e,onChange:n}){const a=v$(e);function o(l,c){const d=e[l];n({...e,[l]:{...d,...c}})}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(l=>s.jsxs(Xe,{className:"border-border bg-card",children:[s.jsxs(it,{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(ge,{icon:Da,size:18})}),s.jsx(lt,{className:"text-base",children:l.key})]}),s.jsxs(Ze,{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx(ze,{htmlFor:`${l.key}-enabled`,children:"Enabled"}),s.jsx(At,{id:`${l.key}-enabled`,checked:l.Enabled!==!1,onCheckedChange:c=>o(l.key,{Enabled:c})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx(ze,{children:"Slash command"}),s.jsx(Ie,{value:l.Command??"",onChange:c=>o(l.key,{Command:c.target.value}),className:"border-border bg-secondary/30 font-mono"})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx(ze,{children:"Description"}),s.jsx(Ie,{value:l.Description??"",onChange:c=>o(l.key,{Description:c.target.value}),className:"border-border bg-secondary/30"})]})]})]},l.key))})}function y$(e,n){let a=structuredClone(n);if(e==="supportbot"){const o=To(a,"General.Token");o&&o!=="BOT_TOKEN"&&(a=xl(a,"General.Token","BOT_TOKEN"))}if(e==="supportbot-ai"){const o=To(a,"General.Model_API_Key");o&&o!=="MODEL_API_KEY"&&(a=xl(a,"General.Model_API_Key","MODEL_API_KEY"))}return a}function w$(e,n,a,o){const l={};for(const c of n)for(const d of c.fields){const m=To(a,d.path),p=To(o,d.path);d.type==="secret"&&(m==="BOT_TOKEN"||m==="MODEL_API_KEY"||m===""||m===void 0)||JSON.stringify(m)!==JSON.stringify(p)&&(l[`${e}:${d.path}`]=m)}return l}function C$({configFile:e}){const{canEditConfig:n}=Ut(),a=!n(e),[o,l]=f.useState(null),[c,d]=f.useState(null),[m,p]=f.useState(!0),[h,b]=f.useState(!1),[g,y]=f.useState(""),[w,j]=f.useState(""),[S,E]=f.useState("visual"),[N,k]=f.useState(""),[T,A]=f.useState(""),[O]=Ju(),[M,z]=f.useState(()=>O.get("tab")||null),B=D_(e),K=f.useMemo(()=>!B||B==="commands"||!o?B:iI(B,o),[B,o]);f.useEffect(()=>{var I;if(K&&K!=="commands"){const H=O.get("tab");if(H&&K.find(Z=>Z.title.toLowerCase()===H.toLowerCase())){const Z=K.find(te=>te.title.toLowerCase()===H.toLowerCase());Z&&Z.title!==M&&z(Z.title)}else(!M||!K.find(Z=>Z.title===M))&&z(((I=K[0])==null?void 0:I.title)||null)}},[K,M,O]);const U=f.useCallback(async()=>{p(!0),y(""),j("");try{const H=(await Ee.getConfigJson(e)).data??{},Z=y$(e,H);l(Z),d(Z);const _=(await Ee.getConfigRaw(e)).data??"",D=E8(_,e);k(D),A(D)}catch(I){y(I instanceof Error?I.message:"Failed to load config")}finally{p(!1)}},[e]);f.useEffect(()=>{U()},[U]);function q(I,H){l(Z=>Z&&xl(Z,I,H))}async function ue(){if(!(a||N===T)){b(!0),y(""),j("");try{const I=await ku(()=>Ee.saveConfigRaw(e,N));j(I.message||"Config saved."),await U()}catch(I){y(I instanceof Error?I.message:"Save failed")}finally{b(!1)}}}async function pe(){if(!(a||!o||!c)){if(S==="yaml"){await ue();return}b(!0),y(""),j("");try{if(B==="commands"){const I={};for(const Z of Object.keys(o))JSON.stringify(o[Z])!==JSON.stringify(c[Z])&&(I[`${e}:${Z}`]=o[Z]);if(Object.keys(I).length===0){j("No changes to save.");return}const H=await ku(()=>Ee.updateConfigFields(I));j(H.message||"")}else if(K&&K!=="commands"){const I=w$(e,K,o,c);if(Object.keys(I).length===0){j("No changes to save.");return}const H=await ku(()=>Ee.updateConfigFields(I));j(H.message||"")}await U()}catch(I){y(I instanceof Error?I.message:"Save failed")}finally{b(!1)}}}if(B===null)return s.jsx(We,{children:s.jsx(Ye,{children:"No visual editor available for this file."})});if(m)return s.jsxs("div",{className:"space-y-4",children:[s.jsx(Be,{className:"h-24 w-full rounded-xl"}),s.jsx(Be,{className:"h-48 w-full rounded-xl"})]});if(!o)return s.jsx(We,{variant:"destructive",children:s.jsx(Ye,{children:g||"Failed to load"})});const xe=c&&JSON.stringify(o)!==JSON.stringify(c),L=S==="yaml"?N!==T:xe;return s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex rounded-lg border border-border p-0.5",children:[s.jsx(he,{type:"button",variant:S==="visual"?"secondary":"ghost",size:"sm",className:"h-8",onClick:()=>E("visual"),children:"Visual"}),s.jsx(he,{type:"button",variant:S==="yaml"?"secondary":"ghost",size:"sm",className:"h-8",onClick:()=>E("yaml"),children:"YAML"})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[L?s.jsx("span",{className:"text-xs text-amber-500",children:"Unsaved changes"}):null,s.jsx(he,{variant:"outline",size:"sm",onClick:U,disabled:m||h,children:"Reload"}),a?s.jsx("span",{className:"text-xs text-muted-foreground",children:"View only"}):s.jsxs(he,{size:"sm",onClick:pe,disabled:h||!L,children:[s.jsx(ge,{icon:nd,size:16,className:"mr-1.5"}),h?"Saving…":"Save"]})]})]}),g?s.jsxs(We,{variant:"destructive",children:[s.jsx(ge,{icon:Bh,size:18}),s.jsx(Ye,{children:g})]}):null,w?s.jsx(We,{className:"border-primary/30 bg-primary/10 text-primary",children:s.jsx(Ye,{children:w})}):null,S==="yaml"?s.jsxs(Xe,{className:"border-border bg-card",children:[s.jsxs(it,{className:"pb-3",children:[s.jsx(lt,{className:"text-base",children:"Raw YAML"}),s.jsx(Et,{children:"Edit the full file. Use this for nested lists (e.g. welcome buttons) or any option not in Visual mode."})]}),s.jsx(Ze,{className:"h-[min(520px,60vh)] overflow-hidden rounded-b-xl border-t border-border p-0",children:s.jsx(g$,{height:"100%",language:"yaml",theme:"vs-dark",value:N,onChange:I=>k(I||""),options:{readOnly:a,minimap:{enabled:!1},fontSize:13,wordWrap:"on",scrollBeyondLastLine:!1,padding:{top:16},tabSize:2}})})]}):B==="commands"?s.jsx(b$,{data:o,onChange:I=>l(I)}):K&&K!=="commands"?s.jsxs("div",{className:"grid gap-6 lg:grid-cols-[200px_1fr]",children:[s.jsx("nav",{className:"flex flex-col gap-1",children:K.map(I=>s.jsx("button",{onClick:()=>z(I.title),className:fe("text-left px-3 py-2 text-sm rounded-md transition-colors",M===I.title?"bg-primary text-primary-foreground font-medium":"text-muted-foreground hover:bg-secondary hover:text-foreground"),children:I.title},I.title))}),s.jsx("div",{className:"min-w-0",children:K.filter(I=>I.title===M).map(I=>s.jsxs(Xe,{className:"border-border bg-card",children:[s.jsxs(it,{className:"pb-3",children:[s.jsx(lt,{className:"text-base",children:I.title}),I.description?s.jsx(Et,{children:I.description}):null]}),s.jsx(Ze,{className:"grid gap-4 sm:grid-cols-2",children:I.fields.map(H=>s.jsx("div",{className:H.type==="textarea"||H.type==="stringList"?"sm:col-span-2":"",children:s.jsx(Vg,{field:H,value:To(o,H.path),readOnly:a,onChange:Z=>q(H.path,Z)})},H.path))})]},I.title))})]}):null]})}const S$=Ee.listConfigs(),j$={supportbot:"Bot config","ticket-panel":"Ticket panel",commands:"Commands",messages:"Messages","supportbot-ai":"AI assistant"};function N$(){var T,A;const{permissions:e,canViewConfig:n}=Ut(),{files:a}=f2(),[o,l]=Ju(),c=o.get("file"),d=n("supportbot"),m=f.useMemo(()=>S$.filter(O=>n(O)),[n]),p=f.useMemo(()=>d?a:[],[d,a]),h=f.useMemo(()=>[...m,...p.map(O=>el(O))],[m,p]),b=h[0]??"",[g,y]=f.useState(()=>c&&h.includes(c)?c:b);if(f.useEffect(()=>{c&&h.includes(c)?y(c):h.includes(g)||(y(b),b&&l({file:b}))},[c,h,g,b,l]),h.length===0)return s.jsx(Qr,{to:Wh(e),replace:!0});const w=O8(g),j=(w==null?void 0:w.type)==="addon",S=j?w.file:null,E=j?m2(S):j$[g]??"Configuration",N=j?!!((T=e==null?void 0:e.configs.supportbot)!=null&&T.edit):e?!!((A=e.configs[g])!=null&&A.edit):!1,k=j?S:`${g}.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:E}),s.jsx("p",{className:"text-muted-foreground",children:N?`Edit ${k} — changes apply to the running bot without restarting the dashboard.`:`Viewing ${k} — you do not have permission to save changes.`})]}),s.jsx("div",{className:"mt-6",children:j&&S?s.jsx(oI,{filename:S},S):s.jsx(C$,{configFile:g},g)})]})}const E$={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 k$(e){return e?E$[e]||"Sign-in failed. Please try again.":""}function T$(){const{branding:e}=od(),{isAuthenticated:n,loading:a,loginWithDiscord:o}=Ut(),[l]=Ju(),c=f.useMemo(()=>k$(l.get("error")),[l]);return!a&&n?s.jsx(Qr,{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(Xe,{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(it,{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(lt,{className:"bg-gradient-to-br from-white to-white/50 bg-clip-text text-3xl font-extrabold tracking-tight text-transparent",children:e.title||"SupportBot"}),s.jsx(Et,{className:"mt-2 text-base font-medium text-white/50",children:"Sign in to your dashboard"})]})]}),s.jsxs(Ze,{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"})]})]}),c?s.jsx(We,{variant:"destructive",className:"border-red-500/50 bg-red-500/10 text-red-200 backdrop-blur-md",children:s.jsx(Ye,{className:"font-medium",children:c})}):null,s.jsxs(he,{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 Os=[{id:"botToken",title:"Bot token",subtitle:"Connect your Discord bot",icon:Hh},{id:"secretKey",title:"Session secret",subtitle:"Secure dashboard logins",icon:y8},{id:"oauth",title:"Discord OAuth",subtitle:"Sign in with Discord",icon:oy},{id:"redirectUri",title:"Redirect URL",subtitle:"OAuth callback address",icon:rd},{id:"owners",title:"Dashboard owners",subtitle:"Who can access this panel",icon:Fp},{id:"emeraldApi",title:"Emerald API",subtitle:"One-click addons",icon:oy}];function R$(e){return e==="oauth"?"oauth":e==="owners"?"owners":e}function A$({brandingTitle:e,faviconUrl:n,faviconVersion:a,hasFavicon:o,children:l}){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(ge,{icon:Hh,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:e})]})]}),l]})})}function M$({currentIndex:e,validation:n}){const a=(e+1)/Os.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 ",e+1," of ",Os.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:Os.map((o,l)=>{var h;const c=R$(o.id),d=(h=n[c])==null?void 0:h.ok,m=l===e,p=ls.jsxs("li",{className:"flex items-center gap-2",children:[s.jsx(ge,{icon:ed,size:14}),o.globalName||o.username,s.jsx("span",{className:"font-mono text-xs opacity-80",children:o.id})]},o.id))}):null,!e.bot&&!((a=e.users)!=null&&a.length)?s.jsx("p",{children:e.warning||"Verified successfully."}):null]})}):s.jsx(We,{variant:"destructive",children:s.jsx(Ye,{children:e.error})}):null}function O$({values:e,setValues:n,validation:a,validating:o,onValidate:l}){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(ze,{htmlFor:"botToken",children:"Bot token"}),s.jsx(Ie,{id:"botToken",type:"password",autoComplete:"off",value:e.botToken,onChange:c=>n({...e,botToken:c.target.value}),placeholder:"MTI…",className:"h-11 font-mono text-sm"})]}),s.jsx(ei,{result:a.botToken}),s.jsx("div",{className:"mt-auto",children:s.jsx(he,{type:"button",variant:"secondary",disabled:o||!e.botToken,onClick:l,children:o?"Checking with Discord…":"Verify bot token"})})]})}function D$({values:e,setValues:n,validation:a,validating:o,onValidate:l,onGenerate:c}){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(ze,{htmlFor:"secretKey",children:"Session secret"}),s.jsx(Ie,{id:"secretKey",type:"password",autoComplete:"off",value:e.secretKey,onChange:d=>n({...e,secretKey:d.target.value}),className:"h-11 font-mono text-sm"})]}),s.jsx(ei,{result:a.secretKey}),s.jsxs("div",{className:"mt-auto flex flex-wrap gap-2",children:[s.jsx(he,{type:"button",variant:"outline",onClick:c,children:"Generate secure secret"}),s.jsx(he,{type:"button",variant:"secondary",disabled:o||!e.secretKey,onClick:l,children:o?"Checking…":"Validate"})]})]})}function L$({values:e,setValues:n,validation:a,validating:o,onValidate:l}){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(ze,{htmlFor:"clientId",children:"Client ID"}),s.jsx(Ie,{id:"clientId",value:e.clientId,onChange:c=>n({...e,clientId:c.target.value}),className:"h-11 font-mono text-sm"})]}),s.jsxs("div",{className:"space-y-2 sm:col-span-2",children:[s.jsx(ze,{htmlFor:"clientSecret",children:"Client Secret"}),s.jsx(Ie,{id:"clientSecret",type:"password",autoComplete:"off",value:e.clientSecret,onChange:c=>n({...e,clientSecret:c.target.value}),className:"h-11 font-mono text-sm"})]})]}),s.jsx(ei,{result:a.oauth}),s.jsx("div",{className:"mt-auto",children:s.jsx(he,{type:"button",variant:"secondary",disabled:o||!e.clientId||!e.clientSecret,onClick:l,children:o?"Checking with Discord…":"Verify OAuth credentials"})})]})}function z$({values:e,setValues:n,validation:a}){async function o(){if(e.redirectUri)try{await navigator.clipboard.writeText(e.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(ze,{htmlFor:"redirectUri",children:"Redirect URI"}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx(Ie,{id:"redirectUri",value:e.redirectUri,onChange:l=>n({...e,redirectUri:l.target.value}),className:"h-11 flex-1 font-mono text-xs"}),s.jsx(he,{type:"button",variant:"outline",size:"icon",className:"size-11 shrink-0",onClick:()=>void o(),title:"Copy URL",children:s.jsx(ge,{icon:t2,size:18})})]})]}),a.redirectUri&&!a.redirectUri.ok?s.jsx(ei,{result:a.redirectUri}):s.jsx(We,{className:"border-border bg-secondary",children:s.jsx(Ye,{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 P$({values:e,setValues:n,validation:a,validating:o,onValidate:l}){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(ze,{htmlFor:"owners",children:"Owner user IDs"}),s.jsx(Ld,{id:"owners",value:e.ownerUserIds,onChange:c=>n({...e,ownerUserIds:c.target.value}),placeholder:`829112572816130058 987654321098765432`,className:"min-h-[120px] font-mono text-sm"})]}),s.jsx(ei,{result:a.owners}),s.jsx("div",{className:"mt-auto",children:s.jsx(he,{type:"button",variant:"secondary",disabled:o||!e.ownerUserIds.trim(),onClick:l,children:o?"Checking with Discord…":"Verify owner IDs"})})]})}function I$({onContinue:e}){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(ge,{icon:ed,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(We,{className:"mt-6 text-left",children:s.jsx(Ye,{children:"After restarting, sign in with Discord to open the dashboard."})}),s.jsx(he,{type:"button",size:"lg",className:"mt-8 min-w-[220px]",onClick:e,children:"Continue to sign in"})]})})}function $$({currentIndex:e,validating:n,saving:a,onBack:o,onNext:l,onFinish:c}){const d=e===Os.length-1;return s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[s.jsxs(he,{type:"button",variant:"ghost",disabled:e===0||a,onClick:o,children:[s.jsx(ge,{icon:J0,size:18,className:"mr-1"}),"Back"]}),s.jsx("div",{className:"flex flex-1 justify-end gap-2",children:d?s.jsx(he,{type:"button",size:"lg",disabled:a||n,onClick:c,className:"min-w-[200px]",children:a?"Saving…":"Finish setup"}):s.jsxs(he,{type:"button",size:"lg",disabled:n||a,onClick:l,children:["Continue",s.jsx(ge,{icon:Uh,size:18,className:"ml-1"})]})})]})}function B$({values:e,setValues:n,validation:a,validating:o,onValidate:l}){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(ze,{htmlFor:"emeraldApiKey",children:"Emerald API key (Optional)"}),s.jsx(Ie,{id:"emeraldApiKey",type:"password",autoComplete:"off",value:e.emeraldApiKey,onChange:c=>n({...e,emeraldApiKey:c.target.value}),placeholder:"em_...",className:"h-11 font-mono text-sm"})]}),s.jsx(ei,{result:a.emeraldApi}),s.jsx("div",{className:"mt-auto",children:s.jsx(he,{type:"button",variant:"secondary",disabled:o,onClick:l,children:o?"Checking…":e.emeraldApiKey?"Verify key":"Skip step"})})]})}function U$(){const e=crypto.randomUUID().replace(/-/g,""),n=crypto.randomUUID().replace(/-/g,"");return e+n}function H$(e){return e.split(/[\s,]+/).map(n=>n.trim()).filter(Boolean)}function E0(e){return e==="oauth"?"oauth":e==="owners"?"owners":e==="emeraldApi"?"emeraldApi":e}function V$(){const e=Ro(),{branding:n}=od(),{loading:a,error:o,refresh:l,status:c}=Pj(),[d,m]=f.useState(0),[p,h]=f.useState({botToken:"",secretKey:"",clientId:"",clientSecret:"",redirectUri:"",ownerUserIds:"",emeraldApiKey:""}),[b,g]=f.useState({}),[y,w]=f.useState(!1),[j,S]=f.useState(!1),[E,N]=f.useState(""),[k,T]=f.useState(!1),A=Os[d];f.useEffect(()=>{c!=null&&c.suggestedRedirectUri&&!p.redirectUri&&h(q=>({...q,redirectUri:c.suggestedRedirectUri}))},[c==null?void 0:c.suggestedRedirectUri,p.redirectUri]);const O=f.useMemo(()=>({botToken:p.botToken,secretKey:p.secretKey,clientId:p.clientId,clientSecret:p.clientSecret,redirectUri:p.redirectUri,ownerUserIds:H$(p.ownerUserIds),emeraldApiKey:p.emeraldApiKey}),[p]);async function M(){w(!0),N("");try{const q=await Ee.validateSetup(O);return g(ue=>{var pe;return{...ue,...(pe=q.data)==null?void 0:pe.results}}),q.data}catch(q){return N(q instanceof Error?q.message:"Validation failed"),null}finally{w(!1)}}async function z(){var pe,xe;const q=E0(A.id),ue=await M();return!!((xe=(pe=ue==null?void 0:ue.results)==null?void 0:pe[q])!=null&&xe.ok)}async function B(){const q=E0(A.id),ue=b[q];!(ue!=null&&ue.ok)&&!await z()||m(pe=>Math.min(pe+1,Os.length-1))}async function K(){S(!0),N("");try{const q=await M();if(!(q!=null&&q.ok)){N("Fix the steps marked with errors before finishing.");return}await Ee.completeSetup(O),T(!0)}catch(q){N(q instanceof Error?q.message:"Could not save setup")}finally{S(!1)}}function U(){const q={values:p,setValues:h,validation:b,validating:y};switch(A.id){case"botToken":return s.jsx(O$,{...q,onValidate:()=>void z()});case"secretKey":return s.jsx(D$,{...q,onGenerate:()=>h(ue=>({...ue,secretKey:U$()})),onValidate:()=>void z()});case"oauth":return s.jsx(L$,{...q,onValidate:()=>void z()});case"redirectUri":return s.jsx(z$,{values:p,setValues:h,validation:b});case"owners":return s.jsx(P$,{...q,onValidate:()=>void z()});case"emeraldApi":return s.jsx(B$,{...q,onValidate:()=>void z()})}}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(Be,{className:"h-14 w-64"}),s.jsxs("div",{className:"grid gap-8 lg:grid-cols-[280px_1fr]",children:[s.jsx(Be,{className:"hidden h-80 lg:block"}),s.jsx(Be,{className:"h-[520px] rounded-2xl"})]})]})}):s.jsxs(A$,{brandingTitle:n.title,faviconUrl:n.faviconUrl,faviconVersion:n.updatedAt??void 0,hasFavicon:n.hasFavicon,children:[o?s.jsx(We,{variant:"destructive",className:"mb-6",children:s.jsx(Ye,{children:o})}):null,E?s.jsx(We,{variant:"destructive",className:"mb-6",children:s.jsx(Ye,{children:E})}):null,k?s.jsx(I$,{onContinue:async()=>{await l(),e("/login",{replace:!0})}}):s.jsxs("div",{className:"grid flex-1 gap-8 lg:grid-cols-[minmax(0,280px)_1fr]",children:[s.jsx(M$,{currentIndex:d,validation:b}),s.jsx(_$,{step:A,footer:s.jsx($$,{currentIndex:d,validating:y,saving:j,onBack:()=>m(q=>Math.max(0,q-1)),onNext:()=>void B(),onFinish:()=>void K()}),children:U()})]})]})}const G$={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 F$({title:e,icon:n,href:a,badge:o="Configured",status:l="done"}){return s.jsxs(Ft,{to:a,className:fe("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(ge,{icon:n,size:20})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("p",{className:"truncate font-semibold",children:e}),s.jsx("span",{className:fe("mt-1 inline-flex rounded-md px-2 py-0.5 text-[10px] font-semibold",G$[l]),children:o})]})]})}function W$({percent:e,size:n=128,className:a,trackClassName:o="stroke-white/20",strokeClassName:l="stroke-white"}){const d=2*Math.PI*42,m=Math.min(100,Math.max(0,e)),p=d-m/100*d;return s.jsxs("div",{className:fe("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:l})]}),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 Y$={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 q$({title:e,subtitle:n,icon:a,href:o,status:l,meta:c="Open in dashboard"}){const d=Y$[l];return s.jsxs(Ft,{to:o,className:fe("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:fe("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:e}),s.jsx("span",{className:fe("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(ge,{icon:a,size:16})}),s.jsx("span",{className:"text-xs text-muted-foreground",children:c})]}),s.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[s.jsx(ge,{icon:rd,size:14,className:"opacity-60"}),s.jsx(ge,{icon:vo,size:14,className:"opacity-60 group-hover:text-primary"}),s.jsx(ge,{icon:Uh,size:14,className:"text-primary opacity-0 transition-opacity group-hover:opacity-100"})]})]})]})}function K$({stats:e}){const n=[{id:"ping",label:"Gateway latency",detail:`${e.bot.ping}ms`,badge:e.bot.ping<200?"Good":"High",badgeClass:e.bot.ping<200?"bg-emerald-500/15 text-emerald-400":"bg-amber-500/15 text-amber-400"},{id:"uptime",label:"Bot uptime",detail:Fh(e.bot.uptime),badge:"Live",badgeClass:"bg-primary/20 text-primary"},{id:"ram",label:"Memory usage",detail:`${e.hosting.ram_used} / ${e.hosting.ram_total}`,badge:`${e.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(Xe,{className:"border-border bg-card",children:[s.jsxs(it,{className:"flex flex-row items-center justify-between space-y-0 pb-3",children:[s.jsxs(lt,{className:"text-sm font-semibold",children:["Connected servers (",e.servers,")"]}),s.jsx(he,{variant:"ghost",size:"icon",className:"size-7 text-muted-foreground",children:s.jsx("span",{className:"text-lg leading-none",children:"+"})})]}),s.jsxs(Ze,{className:"pt-0",children:[s.jsxs("div",{className:"flex -space-x-2",children:[Array.from({length:Math.min(6,e.servers)}).map((a,o)=>s.jsxs(Ia,{className:"size-9 border-2 border-card ring-0",children:[s.jsx(Co,{src:e.bot.avatar,alt:""}),s.jsx($a,{className:"bg-primary/25 text-[10px] text-primary",children:String(o+1)})]},o)),e.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:["+",e.servers-6]}):null]}),s.jsxs("p",{className:"mt-3 text-xs text-muted-foreground",children:[e.users.toLocaleString()," members across your guilds"]})]})]}),s.jsx(Xe,{className:"overflow-hidden border-border bg-secondary",children:s.jsx(Ze,{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(ge,{icon:b8,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(he,{asChild:!0,size:"sm",className:"w-full",children:s.jsxs(Ft,{to:"/settings",children:[s.jsx(ge,{icon:td,size:16,className:"mr-2"}),"Open settings"]})})]})})}),s.jsxs(Xe,{className:"border-border bg-card",children:[s.jsxs(it,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[s.jsx(lt,{className:"text-sm font-semibold",children:"System activity"}),s.jsx(he,{variant:"ghost",size:"icon",className:"size-7 text-muted-foreground",children:s.jsx("span",{className:"text-base leading-none",children:"⋯"})})]}),s.jsxs(Ze,{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(Ia,{className:"size-9",children:[s.jsx(Co,{src:e.bot.avatar,alt:e.bot.username}),s.jsx($a,{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(he,{asChild:!0,variant:"ghost",className:"mx-2 mt-1 w-[calc(100%-1rem)] justify-between text-xs text-muted-foreground",children:s.jsxs(Ft,{to:"/system",children:["All system details",s.jsx(ge,{icon:Uh,size:14})]})})]})]}),s.jsx(Xe,{className:"border-border bg-card",children:s.jsxs(Ze,{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(ge,{icon:vo,size:18})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("p",{className:"text-sm font-medium",children:["v",e.bot.version]}),s.jsxs("p",{className:"text-xs text-muted-foreground",children:["CPU ",e.hosting.cpu_load]})]})]})})]})}const tN={todo:"Needs setup",progress:"In progress",done:"Active"};function Th(e,n,a="Configure module"){const o=n==null?void 0:n[e];return o||{status:"todo",subtitle:a}}function X$(){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(Be,{className:"h-44 rounded-2xl"}),s.jsx(Be,{className:"h-44 rounded-2xl"})]}),s.jsx(Be,{className:"h-8 w-48"}),s.jsx("div",{className:"flex gap-4 overflow-hidden",children:Array.from({length:3}).map((e,n)=>s.jsx(Be,{className:"h-40 min-w-[280px] rounded-2xl"},n))}),s.jsx(Be,{className:"h-8 w-56"}),s.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:Array.from({length:4}).map((e,n)=>s.jsx(Be,{className:"h-20 rounded-2xl"},n))})]}),s.jsx(Be,{className:"hidden h-[520px] w-80 shrink-0 rounded-2xl xl:block"})]})}function Z$(){const{stats:e,loading:n,error:a}=sd(),[o,l]=f.useState("all"),c=f.useMemo(()=>{if(!e)return 0;const b=e.tickets.total||0;return b===0?100:Math.round(e.tickets.closed/b*100)},[e]),d=f.useMemo(()=>o==="open"||o==="closed"?Ts.filter(b=>b.category==="tickets"):o==="all"?Ts:Ts.filter(b=>b.category===o),[o]);if(n)return s.jsx(X$,{});if(a||!e)return s.jsx(We,{variant:"destructive",children:s.jsx(Ye,{children:a||"No stats available"})});const m=e.tickets.open,p=e.tickets.closed,h=e.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(Xe,{className:"overflow-hidden border-border bg-card",children:s.jsxs(Ze,{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(he,{asChild:!0,size:"sm",className:"rounded-lg px-5",children:s.jsx(Ft,{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(Xe,{className:"overflow-hidden border-border bg-primary text-primary-foreground",children:s.jsxs(Ze,{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:[h," 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(W$,{percent:c,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(N5,{value:o,onValueChange:b=>l(b),children:s.jsxs(zg,{className:"h-auto flex-wrap rounded-xl bg-secondary/60 p-1",children:[s.jsx(xo,{value:"all",className:"rounded-lg text-xs data-[state=active]:bg-background data-[state=active]:shadow-sm",children:"All"}),s.jsx(xo,{value:"open",className:"rounded-lg text-xs data-[state=active]:bg-background",children:"Open"}),s.jsx(xo,{value:"closed",className:"rounded-lg text-xs data-[state=active]:bg-background",children:"Closed"}),L_.filter(b=>b.id!=="all").map(b=>s.jsx(xo,{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:ll,href:"/tickets",status:"done",meta:"View live tickets"}]:o==="closed"?[{id:"closed-archive",title:"Closed tickets",subtitle:`${p} resolved`,icon:ed,href:"/transcripts",status:"done",meta:"Browse archive"}]:d.map(b=>{const g=Th(b.id,e.modules,b.description);return{id:b.id,title:b.title,subtitle:g.subtitle,icon:b.icon,href:b.href,status:g.status,meta:g.status==="done"?"View settings":"Configure"}})).map(b=>s.jsx(q$,{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(Ft,{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:Ts.slice(0,4).map(b=>{const g=Th(b.id,e.modules);return s.jsx(F$,{title:b.title,icon:b.icon,href:b.href,badge:tN[g.status],status:g.status},b.id)})})]})]}),s.jsx(K$,{stats:e})]})}function Q$(){const{permissions:e}=Ut();return qn(e,"overview")?s.jsx(Z$,{}):s.jsx(Qr,{to:Wh(e),replace:!0})}function Kr({permission:e,children:n}){const{loading:a,isAuthenticated:o,permissions:l}=Ut();return a?s.jsx("div",{className:"flex flex-1 items-center justify-center py-16 text-sm text-muted-foreground",children:"Loading…"}):o?qn(l,e)?s.jsx(s.Fragment,{children:n}):s.jsx(Qr,{to:Wh(l),replace:!0}):s.jsx(Qr,{to:"/login",replace:!0})}function J$(){const{hasPermission:e}=Ut(),n=e("settings.update"),a=Ro(),[o,l]=f.useState([]),[c,d]=f.useState(""),[m,p]=f.useState(!0),[h,b]=f.useState(""),[g,y]=f.useState(""),[w,j]=f.useState(null),S=f.useCallback(async()=>{p(!0),b("");try{const N=await Ee.getAddonsCatalog();N.data&&(l(N.data.addons),d(N.data.repository))}catch(N){b(N instanceof Error?N.message:"Failed to load addons")}finally{p(!1)}},[]);f.useEffect(()=>{S()},[S]);async function E(N){if(n){j(N.id),y(""),b("");try{const k=await Ee.installAddon(N.id);y(k.message||`${N.name} installed.`),await S();const T=N.configFiles[0];T&&a(`/configs?file=${el(T)}`)}catch(k){b(k instanceof Error?k.message:"Install failed")}finally{j(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(he,{variant:"outline",size:"sm",onClick:S,disabled:m,children:[s.jsx(ge,{icon:r2,size:16,className:fe("mr-1.5",m&&"animate-spin")}),"Refresh"]})]}),h?s.jsx(We,{variant:"destructive",children:s.jsx(Ye,{children:h})}):null,g?s.jsx(We,{className:"border-primary/30 bg-primary/10 text-primary",children:s.jsx(Ye,{children:g})}):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(Be,{className:"h-40 rounded-xl"}),s.jsx(Be,{className:"h-40 rounded-xl"}),s.jsx(Be,{className:"h-40 rounded-xl"})]}):s.jsx("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3",children:o.map(N=>s.jsxs(Xe,{className:"border-border bg-card",children:[s.jsxs(it,{className:"pb-2",children:[s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs(lt,{className:"flex items-center gap-2 text-lg",children:[s.jsx(ge,{icon:Gh,size:20,className:"text-primary"}),N.name]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx(An,{variant:"outline",className:"shrink-0 uppercase tracking-widest text-[10px]",children:N.price===0||!N.price?"Free":`$${N.price}`}),N.installed?s.jsxs(An,{variant:"secondary",className:"shrink-0 gap-1",children:[s.jsx(ge,{icon:j8,size:14}),"Installed"]}):null]})]}),s.jsx(Et,{children:N.description})]}),s.jsxs(Ze,{className:"space-y-2 text-xs text-muted-foreground",children:[N.is_external?s.jsxs("p",{children:["Available on: ",s.jsx("span",{className:"font-medium text-foreground",children:N.external_store||"External Store"})]}):null,N.configFiles&&N.configFiles.length>0?s.jsxs("p",{children:["Config:"," ",N.configFiles.map((k,T)=>s.jsxs("span",{children:[T>0?", ":null,s.jsx(Ft,{to:`/configs?file=${el(k)}`,className:"font-mono text-primary hover:underline",children:k})]},k))]}):null]}),s.jsxs(Gg,{className:"flex flex-wrap gap-2",children:[N.is_external?s.jsx(he,{variant:"outline",size:"sm",asChild:!0,children:s.jsx("a",{href:N.repositoryUrl,target:"_blank",rel:"noreferrer",children:"View Store"})}):null,N.installed&&N.configFiles&&N.configFiles[0]?s.jsx(he,{size:"sm",variant:"secondary",asChild:!0,children:s.jsx(Ft,{to:`/configs?file=${el(N.configFiles[0])}`,children:"Edit config"})}):null,N.installed?s.jsx(he,{size:"sm",disabled:!0,variant:"secondary",children:"Installed"}):N.is_external?null:s.jsxs(he,{size:"sm",disabled:!n||w===N.id,onClick:()=>E(N),children:[s.jsx(ge,{icon:td,size:14,className:"mr-1"}),w===N.id?"Installing…":"Install"]})]})]},N.id))})]})]})}function eB(){const{permissions:e}=Ut(),[n,a]=f.useState(!1),[o,l]=f.useState(!1),[c,d]=f.useState(""),[m,p]=f.useState(""),[h,b]=f.useState(""),[g,y]=f.useState("Administrator"),[w,j]=f.useState(""),[S,E]=f.useState(""),[N,k]=f.useState("General"),T=i2(e,"supportbot"),A=async()=>{if(!m.match(/^[a-z0-9_-]+$/i)){Bt.error("Command name can only contain letters, numbers, underscores and dashes.");return}a(!0),l(!1);try{const O=await Ee.buildAddon({name:m.toLowerCase(),description:h||"A custom command",permission:g,embed:{title:w,description:S||"Hello from your custom command!",color:N}});l(!0),d(O.message||"Restart required."),Bt.success(`Addon ${m}.js created successfully!`)}catch(O){Bt.error(O instanceof Error?O.message:"Failed to build addon")}finally{a(!1)}};return T?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(We,{className:"border-green-500/20 bg-green-500/10 text-green-600 dark:text-green-400",children:[s.jsx(Vy,{className:"h-4 w-4"}),s.jsxs(Ye,{className:"ml-2",children:["Successfully built ",s.jsxs("strong",{children:[m,".js"]}),"! ",c]})]}):null,s.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[s.jsxs("div",{className:"space-y-6",children:[s.jsxs(Xe,{children:[s.jsxs(it,{children:[s.jsx(lt,{className:"text-lg",children:"Command Details"}),s.jsx(Et,{children:"Configure how users trigger the command."})]}),s.jsxs(Ze,{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx(ze,{children:"Command Name"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-muted-foreground",children:"/"}),s.jsx(Ie,{placeholder:"ping",value:m,onChange:O=>p(O.target.value.replace(/[^a-z0-9_-]/gi,"").toLowerCase())})]})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(ze,{children:"Description"}),s.jsx(Ie,{placeholder:"Replies with a custom embed",value:h,onChange:O=>b(O.target.value)})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(ze,{children:"Required Permission"}),s.jsxs(No,{value:g,onValueChange:y,children:[s.jsx(Ba,{children:s.jsx(Eo,{})}),s.jsxs(Ua,{children:[s.jsx(an,{value:"none",children:"@everyone"}),s.jsx(an,{value:"Administrator",children:"Administrator"}),s.jsx(an,{value:"ManageMessages",children:"Manage Messages"}),s.jsx(an,{value:"ManageGuild",children:"Manage Server"})]})]})]})]})]}),s.jsxs(Xe,{children:[s.jsxs(it,{children:[s.jsx(lt,{className:"text-lg",children:"Response Embed"}),s.jsx(Et,{children:"What the bot will reply with."})]}),s.jsxs(Ze,{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx(ze,{children:"Embed Title (Optional)"}),s.jsx(Ie,{placeholder:"Hello!",value:w,onChange:O=>j(O.target.value)})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(ze,{children:"Embed Description"}),s.jsx(Ld,{placeholder:"Type your message here...",className:"resize-none",rows:4,value:S,onChange:O=>E(O.target.value)})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(ze,{children:"Embed Color"}),s.jsxs(No,{value:N,onValueChange:k,children:[s.jsx(Ba,{children:s.jsx(Eo,{})}),s.jsxs(Ua,{children:[s.jsx(an,{value:"General",children:"Theme General"}),s.jsx(an,{value:"Success",children:"Theme Success"}),s.jsx(an,{value:"Warning",children:"Theme Warning"}),s.jsx(an,{value:"Error",children:"Theme Error"})]})]})]})]})]})]}),s.jsx("div",{className:"space-y-6",children:s.jsxs(Xe,{className:"sticky top-6 border-primary/20",children:[s.jsx(it,{children:s.jsxs(lt,{className:"text-sm font-medium flex items-center gap-2",children:[s.jsx(ge,{icon:C8,size:16,className:"text-primary"}),"Live Preview"]})}),s.jsx(Ze,{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(Vy,{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:[w&&s.jsx("div",{className:"mb-1 font-semibold text-white",children:w}),s.jsx("div",{className:"whitespace-pre-wrap",children:S||"Hello from your custom command!"})]})]})]})})}),s.jsx(Gg,{children:s.jsxs(he,{className:"w-full gap-2",size:"lg",disabled:!m||n,onClick:A,children:[s.jsx(ge,{icon:Da,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 Wg="supportbot-dashboard-accent",ol="#45b46c",tB=["--primary","--ring","--chart-1","--sidebar-primary","--sidebar-ring","--accent","--accent-foreground","--sidebar-accent","--sidebar-accent-foreground"];function nB(e){const n=jr(e,ol),a=parseInt(n.slice(1,3),16)/255,o=parseInt(n.slice(3,5),16)/255,l=parseInt(n.slice(5,7),16)/255,c=Math.max(a,o,l),d=Math.min(a,o,l),m=(c+d)/2;let p=0,h=0;if(c!==d){const b=c-d;switch(h=m>.5?b/(2-c-d):b/(c+d),c){case a:p=((o-l)/b+(o{const o=new FileReader;o.onload=()=>n(String(o.result)),o.onerror=()=>a(new Error("Could not read file")),o.readAsDataURL(e)})}function iB({canEdit:e}){const[n,a]=f.useState(!1),[o,l]=f.useState(""),[c,d]=f.useState(!1);async function m(){if(e){a(!0),l("");try{const p=await Ee.resetDashboard();l(p.message||"Dashboard reset successfully."),setTimeout(()=>{window.location.href="/setup"},1500)}catch(p){l(p instanceof Error?p.message:"Reset failed"),a(!1)}}}return e?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(zl,{open:c,onOpenChange:d,children:[s.jsx(x_,{asChild:!0,children:s.jsx(he,{type:"button",variant:"destructive",children:"Reset Dashboard"})}),s.jsxs(qs,{children:[s.jsxs(Ks,{children:[s.jsx(Xs,{children:"Are you absolutely sure?"}),s.jsx(Zs,{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(Pl,{children:[s.jsx(he,{variant:"outline",onClick:()=>d(!1),disabled:n,children:"Cancel"}),s.jsx(he,{variant:"destructive",onClick:()=>void m(),disabled:n,children:n?"Resetting...":"Yes, reset dashboard"})]})]})]})]}):null}function lB({canEdit:e}){const{branding:n,setBrandingLocal:a}=od(),o=f.useRef(null),[l,c]=f.useState(n.title),[d,m]=f.useState(n.pageTitle),[p,h]=f.useState(!1),[b,g]=f.useState(!1),[y,w]=f.useState("");f.useEffect(()=>{c(n.title),m(n.pageTitle)},[n.title,n.pageTitle]);const j=n.hasFavicon&&n.faviconUrl?`${n.faviconUrl}${n.updatedAt?`?v=${n.updatedAt}`:""}`:null;async function S(){if(e){h(!0),w("");try{const T=await Ee.updateBranding({title:l,pageTitle:d});T.data&&a(T.data),w(T.message||"Branding saved.")}catch(T){w(T instanceof Error?T.message:"Save failed")}finally{h(!1)}}}async function E(T){if(!(!e||!T)){g(!0),w("");try{const A=await sB(T),O=await Ee.uploadBrandingFavicon(A);O.data&&a(O.data),w(O.message||"Favicon uploaded.")}catch(A){w(A instanceof Error?A.message:"Upload failed")}finally{g(!1),o.current&&(o.current.value="")}}}async function N(){if(e){g(!0),w("");try{const T=await Ee.removeBrandingFavicon();T.data&&a(T.data),w(T.message||"Favicon removed.")}catch(T){w(T instanceof Error?T.message:"Remove failed")}finally{g(!1)}}}const k=l.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(ze,{htmlFor:"brand-title",children:"Sidebar title"}),s.jsx(Ie,{id:"brand-title",value:l,disabled:!e,maxLength:64,onChange:T=>c(T.target.value),className:"border-border bg-secondary/30",placeholder:"SupportBot"})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(ze,{htmlFor:"brand-page-title",children:"Browser tab title"}),s.jsx(Ie,{id:"brand-page-title",value:d,disabled:!e,maxLength:80,onChange:T=>m(T.target.value),className:"border-border bg-secondary/30",placeholder:"SupportBot Dashboard"})]})]}),e?s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(he,{type:"button",disabled:p||!k,onClick:()=>void S(),children:p?"Saving…":"Save titles"}),y&&k?s.jsx("span",{className:"text-xs text-muted-foreground",children:y}):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:j?s.jsx("img",{src:j,alt:"Favicon preview",className:"size-full object-contain p-2"}):s.jsx(ge,{icon:d8,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:!e||b,onChange:T=>{var A;return void E(((A=T.target.files)==null?void 0:A[0])??null)}}),s.jsxs("div",{className:"flex flex-col gap-2",children:[e?s.jsxs("div",{className:"flex gap-2",children:[s.jsx(he,{type:"button",variant:"secondary",disabled:b,onClick:()=>{var T;return(T=o.current)==null?void 0:T.click()},children:b?"Uploading…":"Upload Favicon"}),n.hasFavicon?s.jsx(he,{type:"button",variant:"destructive",disabled:b,onClick:()=>void N(),children:"Remove"}):null]}):s.jsx("span",{className:"text-xs text-muted-foreground",children:"View only"}),!k&&y?s.jsx("span",{className:"text-xs text-muted-foreground",children:y}):null]})]})]})]})}function cB(){var g,y,w,j,S,E,N,k,T,A,O;const{hasPermission:e}=Ut(),n=e("settings.update"),[a,o]=f.useState(!0),[l,c]=f.useState(!1),[d,m]=f.useState(""),[p,h]=f.useState(null);f.useEffect(()=>{Ee.getConfigJson("api").then(M=>{M.data&&h(M.data)}).catch(()=>m("Failed to load API config")).finally(()=>o(!1))},[]);async function b(){var M,z,B,K,U,q,ue,pe,xe,se,L;if(!(!n||!p)){c(!0),m("");try{const I={"api:API.Port":(M=p.API)==null?void 0:M.Port,"api:API.EmeraldAPIKey":(z=p.API)==null?void 0:z.EmeraldAPIKey,"api:API.TrustProxy":(B=p.API)==null?void 0:B.TrustProxy,"api:API.OAuth.Enabled":(U=(K=p.API)==null?void 0:K.OAuth)==null?void 0:U.Enabled,"api:API.OAuth.ClientId":(ue=(q=p.API)==null?void 0:q.OAuth)==null?void 0:ue.ClientId,"api:API.OAuth.ClientSecret":(xe=(pe=p.API)==null?void 0:pe.OAuth)==null?void 0:xe.ClientSecret,"api:API.OAuth.RedirectUri":(L=(se=p.API)==null?void 0:se.OAuth)==null?void 0:L.RedirectUri};await Ee.updateConfigFields(I),m("API settings saved and backend restarted.")}catch(I){m(I instanceof Error?I.message:"Save failed")}finally{c(!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(ze,{children:"API Port"}),s.jsx(Ie,{type:"number",value:((g=p.API)==null?void 0:g.Port)||"",disabled:!n,onChange:M=>h({...p,API:{...p.API,Port:parseInt(M.target.value)||3e3}}),className:"border-border bg-secondary/30"})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(ze,{children:"Emerald API Key"}),s.jsx(Ie,{type:"password",value:((y=p.API)==null?void 0:y.EmeraldAPIKey)||"",disabled:!n,onChange:M=>h({...p,API:{...p.API,EmeraldAPIKey:M.target.value}}),className:"border-border bg-secondary/30"})]})]}),s.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[s.jsx(At,{checked:((w=p.API)==null?void 0:w.TrustProxy)||!1,disabled:!n,onCheckedChange:M=>h({...p,API:{...p.API,TrustProxy:M}})}),s.jsx(ze,{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(At,{checked:((S=(j=p.API)==null?void 0:j.OAuth)==null?void 0:S.Enabled)||!1,disabled:!n,onCheckedChange:M=>{var z;return h({...p,API:{...p.API,OAuth:{...(z=p.API)==null?void 0:z.OAuth,Enabled:M}}})}}),s.jsx(ze,{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(ze,{children:"Client ID"}),s.jsx(Ie,{value:((N=(E=p.API)==null?void 0:E.OAuth)==null?void 0:N.ClientId)||"",disabled:!n,onChange:M=>{var z;return h({...p,API:{...p.API,OAuth:{...(z=p.API)==null?void 0:z.OAuth,ClientId:M.target.value}}})},className:"border-border bg-secondary/30"})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(ze,{children:"Client Secret"}),s.jsx(Ie,{type:"password",value:((T=(k=p.API)==null?void 0:k.OAuth)==null?void 0:T.ClientSecret)||"",disabled:!n,onChange:M=>{var z;return h({...p,API:{...p.API,OAuth:{...(z=p.API)==null?void 0:z.OAuth,ClientSecret:M.target.value}}})},className:"border-border bg-secondary/30"})]}),s.jsxs("div",{className:"space-y-2 sm:col-span-2",children:[s.jsx(ze,{children:"Redirect URI"}),s.jsx(Ie,{value:((O=(A=p.API)==null?void 0:A.OAuth)==null?void 0:O.RedirectUri)||"",disabled:!n,onChange:M=>{var z;return h({...p,API:{...p.API,OAuth:{...(z=p.API)==null?void 0:z.OAuth,RedirectUri:M.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(he,{type:"button",disabled:l,onClick:()=>void b(),children:l?"Saving…":"Save API Config"}),d?s.jsx("span",{className:"text-xs text-muted-foreground",children:d}):null]}):null]}):null}function uB(){const{hasPermission:e}=Ut(),n=e("settings.update"),[a,o]=f.useState(null),[l,c]=f.useState(!0),[d,m]=f.useState(!1),[p,h]=f.useState(""),[b,g]=f.useState(""),[y,w]=f.useState(()=>rN()??ol),[j,S]=f.useState(""),[E,N]=f.useState("appearance"),k=f.useCallback(async()=>{c(!0),h("");try{const A=await Ee.checkForUpdates();A.data&&o(A.data)}catch(A){h(A instanceof Error?A.message:"Could not check for updates")}finally{c(!1)}},[]);f.useEffect(()=>{k()},[k]);async function T(A){if(A.updateAvailable){m(!0),h(""),g("");try{const O=await Ee.runUpdate(A.id,A.latest,A.zipUrl);g(O.message||"Update installed. Restart your server (stop and run npm start again) to finish applying changes."),await k()}catch(O){h(O instanceof Error?O.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(he,{variant:E==="appearance"?"secondary":"ghost",className:"justify-start w-full",onClick:()=>N("appearance"),children:"Appearance"}),s.jsx(he,{variant:E==="api"?"secondary":"ghost",className:"justify-start w-full",onClick:()=>N("api"),children:"API Config"}),s.jsx(he,{variant:E==="updates"?"secondary":"ghost",className:"justify-start w-full",onClick:()=>N("updates"),children:"Update Checker"}),n&&s.jsx(he,{variant:"ghost",className:`justify-start w-full text-destructive hover:bg-destructive/10 hover:text-destructive ${E==="danger"?"bg-destructive/10 border-l-2 border-destructive rounded-l-none":""}`,onClick:()=>N("danger"),children:"Danger Zone"})]})}),s.jsxs("main",{className:"flex-1 w-full max-w-4xl space-y-6",children:[E==="appearance"&&s.jsx("div",{className:"space-y-6",children:s.jsxs(Xe,{className:"border-border bg-card",children:[s.jsxs(it,{children:[s.jsx(lt,{className:"text-lg",children:"Dashboard appearance"}),s.jsx(Et,{children:"Customise branding for all users, and pick an accent colour for this browser only."})]}),s.jsxs(Ze,{className:"space-y-4",children:[s.jsx(lB,{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(Id,{value:y,onChange:A=>{w(A),k0(A),S("Accent updated.")}}),s.jsx(Ie,{id:"accent-colour",value:y,onChange:A=>w(A.target.value),onBlur:()=>{const A=jr(y,ol);w(A),k0(A),S("Accent updated.")},className:"w-32 border-border bg-secondary/30 font-mono uppercase",maxLength:7})]}),s.jsx(he,{type:"button",variant:"outline",onClick:()=>{aB(),w(ol),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"})]}),j?s.jsx("p",{className:"text-xs text-muted-foreground",children:j}):null]})]})]})}),E==="danger"&&n&&s.jsxs(Xe,{className:"border-destructive/50 bg-destructive/5",children:[s.jsxs(it,{children:[s.jsx(lt,{className:"text-lg text-destructive",children:"Danger Zone"}),s.jsx(Et,{className:"text-destructive/80",children:"Destructive actions that reset or permanently alter your dashboard."})]}),s.jsx(Ze,{children:s.jsx(iB,{canEdit:n})})]}),E==="api"&&s.jsxs(Xe,{className:"border-border bg-card",children:[s.jsxs(it,{children:[s.jsx(lt,{className:"text-lg",children:"API Configuration"}),s.jsx(Et,{children:"Configure the internal API settings, Emerald API key, and OAuth."})]}),s.jsx(Ze,{children:s.jsx(cB,{})})]}),E==="updates"&&s.jsxs(Xe,{className:"border-border bg-card",children:[s.jsxs(it,{children:[s.jsx(lt,{className:"text-lg",children:"Software updates"}),s.jsx(Et,{children:"Manage updates for the bot and dashboard."})]}),s.jsxs(Ze,{className:"space-y-4",children:[l?s.jsx(Be,{className:"h-24 w-full"}):a&&a.length>0?s.jsx("div",{className:"space-y-4",children:a.map(A=>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:A.repository,target:"_blank",rel:"noreferrer",className:"text-primary underline-offset-4 hover:underline",children:A.name})," ","(",A.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",A.current]})]}),s.jsxs("p",{children:[s.jsx("span",{className:"text-muted-foreground",children:"Latest: "}),s.jsxs("span",{className:"font-mono font-medium",children:["v",A.latest]})]})]})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[A.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."}),A.updateAvailable&&n?s.jsxs(he,{type:"button",size:"sm",onClick:()=>void T(A),disabled:d,children:[d?s.jsx(ge,{icon:r2,size:16,className:"mr-2 animate-spin"}):s.jsx(ge,{icon:td,size:16,className:"mr-2"}),d?"Installing…":"Update now"]}):null,A.updateAvailable&&!n?s.jsx("p",{className:"text-xs text-muted-foreground",children:"You cannot install updates with your role."}):null]})]},A.id))}):null,p?s.jsx(We,{variant:"destructive",children:s.jsx(Ye,{children:p})}):null,b?s.jsx(We,{children:s.jsx(Ye,{children:b})}):null,s.jsx("div",{className:"flex flex-wrap gap-2 pt-2",children:s.jsxs(he,{type:"button",variant:"outline",onClick:k,disabled:l||d,children:[s.jsx(ge,{icon:or,size:16,className:"mr-2"}),"Check again"]})})]})]})]})]})]})}function Yg(e){const[n,a]=f.useState(!1),o=f.useRef(e);return o.current=e,f.useEffect(()=>{let l=null,c=null;const d=()=>{l=new EventSource("/api/stream"),l.onopen=()=>{a(!0)},l.addEventListener("connected",()=>{a(!0)}),l.addEventListener("metrics",m=>{var p,h;try{const b=JSON.parse(m.data);(h=(p=o.current).onMetrics)==null||h.call(p,b)}catch{}}),l.addEventListener("log",m=>{var p,h;try{const b=JSON.parse(m.data);(h=(p=o.current).onLog)==null||h.call(p,b)}catch{}}),l.addEventListener("ticket_message",m=>{var p,h;try{const b=JSON.parse(m.data);(h=(p=o.current).onTicketMessage)==null||h.call(p,b)}catch{}}),l.addEventListener("ticket_message_deleted",m=>{var p,h;try{const b=JSON.parse(m.data);(h=(p=o.current).onTicketMessageDeleted)==null||h.call(p,b)}catch{}}),l.addEventListener("ticket_message_updated",m=>{var p,h;try{const b=JSON.parse(m.data);(h=(p=o.current).onTicketMessageUpdated)==null||h.call(p,b)}catch{}}),l.addEventListener("ticket_created",m=>{var p,h;try{const b=JSON.parse(m.data);(h=(p=o.current).onTicketCreated)==null||h.call(p,b)}catch{}}),l.addEventListener("ticket_closed",m=>{var p,h;try{const b=JSON.parse(m.data);(h=(p=o.current).onTicketClosed)==null||h.call(p,b)}catch{}}),l.onerror=()=>{a(!1),l==null||l.close(),c=window.setTimeout(d,4e3)}};return d(),()=>{c&&window.clearTimeout(c),l&&l.close()}},[]),{connected:n}}function Ct({label:e,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:e}),s.jsx("dd",{className:`text-sm font-medium text-foreground ${a?"font-mono text-xs sm:text-sm":""}`,children:n})]})}const dB={ok:"Healthy",missing_config:"Guild ID not set",not_in_guild:"Not in configured server",extra_guilds:"Extra servers joined",offline:"Bot offline"};function fB(e){return e==="ok"?"text-emerald-500":e==="offline"?"text-destructive":"text-amber-500"}function mB(){var E;const{stats:e,loading:n,error:a,refresh:o}=sd(),[l,c]=f.useState(null),[d,m]=f.useState(null),[p,h]=f.useState(!1),[b,g]=f.useState(null),{connected:y}=Yg({onMetrics:N=>{g(N)}}),w=f.useCallback(async()=>{const[N,k]=await Promise.all([Ee.getGuildStatus().catch(()=>null),Ee.health().catch(()=>null)]);N!=null&&N.data&&c(N.data),k!=null&&k.success&&k.data&&m({dashboard:k.data.dashboard,botReady:k.data.botReady,oauthEnabled:k.data.oauthEnabled,setupComplete:k.data.setupComplete})},[]);f.useEffect(()=>{w()},[w]);async function j(){h(!0);try{await Promise.all([o(),w()])}finally{h(!1)}}if(n&&!e)return s.jsxs("div",{className:"space-y-6",children:[s.jsx(Be,{className:"h-10 w-64"}),s.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[s.jsx(Be,{className:"h-56 rounded-2xl"}),s.jsx(Be,{className:"h-56 rounded-2xl"})]})]});if(a||!e)return s.jsx(We,{variant:"destructive",children:s.jsx(Ye,{children:a||"Could not load system details."})});const S=e.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(he,{asChild:!0,variant:"ghost",size:"sm",className:"-ml-2 h-8 px-2 text-muted-foreground",children:s.jsxs(Ft,{to:"/",children:[s.jsx(ge,{icon:J0,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(he,{type:"button",variant:"outline",disabled:p,onClick:()=>void j(),children:[s.jsx(ge,{icon:or,size:16,className:"mr-2"}),p?"Refreshing…":"Refresh now"]})]}),s.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[s.jsxs(Xe,{className:"border-border bg-card",children:[s.jsxs(it,{children:[s.jsx(lt,{className:"text-lg",children:"Discord bot"}),s.jsx(Et,{children:"Connection and identity"})]}),s.jsxs(Ze,{children:[s.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[s.jsxs(Ia,{className:"size-12",children:[s.jsx(Co,{src:e.bot.avatar,alt:e.bot.username}),s.jsx($a,{children:"SB"})]}),s.jsxs("div",{children:[s.jsx("p",{className:"font-semibold",children:e.bot.username}),s.jsx("p",{className:"font-mono text-xs text-muted-foreground",children:e.bot.id})]})]}),s.jsxs("dl",{children:[s.jsx(Ct,{label:"Version",value:`v${e.bot.version}`,mono:!0}),s.jsx(Ct,{label:"Gateway latency",value:s.jsxs("span",{className:S?"text-emerald-500":"text-amber-500",children:[e.bot.ping," ms"]})}),s.jsx(Ct,{label:"Process uptime",value:Fh(e.bot.uptime)}),s.jsx(Ct,{label:"Connected servers",value:e.servers.toLocaleString()}),s.jsx(Ct,{label:"Members tracked",value:e.users.toLocaleString()}),e.bot.inviteUrl?s.jsx(Ct,{label:"Invite link",value:s.jsx("a",{href:e.bot.inviteUrl,target:"_blank",rel:"noreferrer",className:"text-primary underline-offset-4 hover:underline",children:"Open in Discord"})}):null]})]})]}),s.jsxs(Xe,{className:"border-border bg-card",children:[s.jsxs(it,{className:"flex flex-row items-center justify-between",children:[s.jsxs("div",{children:[s.jsx(lt,{className:"text-lg",children:"Host machine"}),s.jsx(Et,{children:"Server resources running this instance"})]}),s.jsxs(An,{variant:y?"default":"outline",className:"text-xs",children:[s.jsx("span",{className:`mr-1.5 inline-block h-2 w-2 rounded-full ${y?"bg-emerald-500 animate-pulse":"bg-muted"}`}),y?"Live Stream":"Polling"]})]}),s.jsx(Ze,{children:s.jsxs("dl",{children:[s.jsx(Ct,{label:"Memory used",value:b?`${(b.ram_used_mb/1024).toFixed(2)} GB / ${(b.ram_total_mb/1024).toFixed(2)} GB`:`${e.hosting.ram_used} / ${e.hosting.ram_total}`}),s.jsx(Ct,{label:"Memory usage",value:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("span",{className:(b?b.ram_percent:e.hosting.ram_percent)>85?"text-amber-500 font-bold":"text-foreground font-medium",children:[b?b.ram_percent:e.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:e.hosting.ram_percent}%`}})})]})}),s.jsx(Ct,{label:"CPU load (1 min avg)",value:b?String(b.cpu_load):e.hosting.cpu_load,mono:!0}),s.jsx(Ct,{label:"Host uptime",value:e.hosting.uptime})]})})]}),s.jsxs(Xe,{className:"border-border bg-card",children:[s.jsxs(it,{children:[s.jsx(lt,{className:"text-lg",children:"Tickets"}),s.jsx(Et,{children:"Database snapshot"})]}),s.jsx(Ze,{children:s.jsxs("dl",{children:[s.jsx(Ct,{label:"Total tickets",value:e.tickets.total}),s.jsx(Ct,{label:"Open",value:s.jsx("span",{className:"text-primary",children:e.tickets.open})}),s.jsx(Ct,{label:"Closed",value:e.tickets.closed}),s.jsx(Ct,{label:"Transcripts",value:s.jsx(Ft,{to:"/transcripts",className:"text-primary underline-offset-4 hover:underline",children:"Browse archive"})})]})})]}),s.jsxs(Xe,{className:"border-border bg-card",children:[s.jsxs(it,{children:[s.jsx(lt,{className:"text-lg",children:"Guild health"}),s.jsx(Et,{children:"Configured server and membership"})]}),s.jsx(Ze,{children:l?s.jsxs("dl",{children:[s.jsx(Ct,{label:"Status",value:s.jsx("span",{className:fB(l.status),children:dB[l.status]})}),s.jsx(Ct,{label:"Configured guild ID",value:l.configuredGuildId||"Not set",mono:!0}),l.configuredGuild?s.jsx(Ct,{label:"Configured server",value:`${l.configuredGuild.name} (${((E=l.configuredGuild.memberCount)==null?void 0:E.toLocaleString())??"?"} members)`}):null,l.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:l.message}):null,l.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:l.extraGuilds.map(N=>s.jsxs("li",{className:"font-mono text-xs",children:[N.name," · ",N.id]},N.id))})]}):null]}):s.jsx(Be,{className:"h-24 w-full"})})]})]}),s.jsxs(Xe,{className:"border-border bg-card",children:[s.jsxs(it,{children:[s.jsx(lt,{className:"text-lg",children:"Dashboard services"}),s.jsx(Et,{children:"API and authentication"})]}),s.jsx(Ze,{children:d?s.jsxs("dl",{className:"max-w-xl",children:[s.jsx(Ct,{label:"Dashboard UI",value:d.dashboard?"Available":"Missing build"}),s.jsx(Ct,{label:"Bot connection",value:d.botReady?"Online":"Starting or offline"}),s.jsx(Ct,{label:"Discord OAuth",value:d.oauthEnabled?"Configured":"Not configured"}),s.jsx(Ct,{label:"Initial setup",value:d.setupComplete?"Complete":"Incomplete"}),s.jsx(Ct,{label:"Software updates",value:s.jsx(Ft,{to:"/settings",className:"text-primary underline-offset-4 hover:underline",children:"Open settings"})}),s.jsx(Ct,{label:"Logs",value:s.jsx(Ft,{to:"/logs",className:"text-primary underline-offset-4 hover:underline",children:"View log files"})})]}):s.jsx(Be,{className:"h-32 w-full max-w-xl"})})]}),e.modules?s.jsxs(Xe,{className:"border-border bg-card",children:[s.jsxs(it,{children:[s.jsx(lt,{className:"text-lg",children:"Module setup status"}),s.jsx(Et,{children:"Which features are configured and active"})]}),s.jsx(Ze,{children:s.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:Ts.map(N=>{const k=Th(N.id,e.modules);return s.jsxs(Ft,{to:N.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:N.title}),s.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:k.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:tN[k.status]})]},N.id)})})})]}):null]})}function pB(e){if(!e)return"—";const n=new Date(e);return Number.isNaN(n.getTime())?e:n.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",second:"2-digit"})}const hB=[{id:"all",label:"All"},{id:"Output",label:"Output"},{id:"Warn",label:"Warn"},{id:"Error",label:"Error"}],gB=["Output","Warn","Error"],xB={Output:"text-foreground/90",Warn:"text-amber-400",Error:"text-rose-400"},vB={Output:"bg-muted text-muted-foreground",Warn:"bg-amber-500/15 text-amber-400",Error:"bg-rose-500/15 text-rose-400"},qu=2e3,bB=2e3;function Rh(e,n){return`${e.type}-${e.timestamp??"na"}-${n}-${e.message.slice(0,32)}`}function yB(e,n,a){const o=a?[]:e,l=new Set(o.map((m,p)=>Rh(m,p))),c=[];for(let m=0;mqu?d.slice(d.length-qu):d}function wB(){const[e,n]=f.useState([]),[a,o]=f.useState(!0),[l,c]=f.useState(""),[d,m]=f.useState(!1),[p,h]=f.useState(!0),[b,g]=f.useState("all"),[y,w]=f.useState(""),[j,S]=f.useState(!0),[E,N]=f.useState(""),k=f.useRef(null),T=f.useRef(null),A=f.useRef(d);A.current=d;const O=f.useMemo(()=>b==="all"?gB:[b],[b]),M=f.useCallback(U=>{A.current||b!=="all"&&U.type!==b||(n(q=>{const ue=[...q,U];return ue.length>qu?ue.slice(ue.length-qu):ue}),S(!0))},[b]);Yg({onLog:M});const z=f.useCallback(async U=>{var pe,xe;const q=await Ee.getLogs({types:O,cursor:U?void 0:k.current??void 0,tail:U?500:0}),ue=((pe=q.data)==null?void 0:pe.entries)??[];return k.current=((xe=q.data)==null?void 0:xe.cursor)??{},n(se=>yB(se,ue,U)),ue.length},[O]),B=f.useCallback(async()=>{var U;o(!0),c(""),k.current=null;try{const pe=(((U=(await Ee.getLogsMeta()).data)==null?void 0:U.files)??[]).filter(xe=>xe.file).map(xe=>`${xe.type}: ${xe.file}`).join(" · ");N(pe||"No log files yet — output appears when the bot runs."),await z(!0),S(!0)}catch(q){c(q instanceof Error?q.message:"Failed to load logs"),S(!1)}finally{o(!1)}},[z]);f.useEffect(()=>{B()},[B]),f.useEffect(()=>{if(d||a)return;const U=window.setInterval(async()=>{if(!A.current)try{await z(!1),S(!0),c("")}catch(q){S(!1),c(q instanceof Error?q.message:"Live update failed")}},bB);return()=>window.clearInterval(U)},[d,a,z]),f.useEffect(()=>{if(!p||d)return;const U=T.current;U&&(U.scrollTop=U.scrollHeight)},[e,p,d]);const K=f.useMemo(()=>e.filter(U=>{var ue;if(b!=="all"&&U.type!==b)return!1;if(!y.trim())return!0;const q=y.toLowerCase();return U.message.toLowerCase().includes(q)||(((ue=U.timestamp)==null?void 0:ue.toLowerCase().includes(q))??!1)}),[e,b,y]);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"}),E?s.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:E}):null]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:fe("size-2 rounded-full",j&&!d?"animate-pulse bg-emerald-500":"bg-muted-foreground")}),s.jsx("span",{className:"text-xs text-muted-foreground",children:d?"Paused":j?"Live":"Disconnected"})]})]}),l?s.jsx(We,{variant:"destructive",children:s.jsx(Ye,{children:l})}):null,s.jsxs(Xe,{className:"flex min-h-0 flex-1 flex-col border-border bg-card",children:[s.jsxs(it,{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(lt,{className:"text-base font-medium",children:["Console",a?null:s.jsxs("span",{className:"ml-2 text-xs font-normal text-muted-foreground",children:[K.length," line",K.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(At,{id:"auto-scroll",checked:p,onCheckedChange:h}),s.jsx(ze,{htmlFor:"auto-scroll",className:"text-xs font-normal",children:"Auto-scroll"})]}),s.jsxs(he,{type:"button",variant:"outline",size:"sm",onClick:()=>m(U=>!U),children:[s.jsx(ge,{icon:d?v8:x8,size:16,className:"mr-1.5"}),d?"Resume":"Pause"]}),s.jsxs(he,{type:"button",variant:"outline",size:"sm",onClick:()=>{n([]),B()},disabled:a,children:[s.jsx(ge,{icon:or,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:hB.map(U=>s.jsx(he,{type:"button",variant:b===U.id?"secondary":"ghost",size:"sm",className:"h-8 rounded-lg text-xs",onClick:()=>g(U.id),children:U.label},U.id))}),s.jsxs("div",{className:"relative flex-1 sm:max-w-xs",children:[s.jsx(ge,{icon:ad,size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground"}),s.jsx(Ie,{placeholder:"Filter lines…",value:y,onChange:U=>w(U.target.value),className:"h-9 pl-9"})]})]})]}),s.jsx(Ze,{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((U,q)=>s.jsx(Be,{className:"h-4 w-full"},q))}):s.jsx("div",{ref:T,className:"h-full max-h-[calc(100svh-18rem)] overflow-y-auto bg-[#0d0d12] p-4 font-mono text-[13px] leading-relaxed",children:K.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:K.map((U,q)=>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:pB(U.timestamp)}),s.jsx("span",{className:fe("shrink-0 rounded px-1.5 py-0 text-[10px] font-semibold uppercase",vB[U.type]),children:U.type}),s.jsx("span",{className:fe("min-w-0 flex-1 whitespace-pre-wrap break-words",xB[U.type]),children:U.message||" "})]},Rh(U,q)))})})})]})]})}const CB=[{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; }"}]}],SB=450;function jB(e,n){return n&&e!=="viewer"}function NB(){const{user:e,hasPermission:n}=Ut(),a=!jB(e==null?void 0:e.role,n("transcripts")),[o,l]=f.useState(null),[c,d]=f.useState(null),[m,p]=f.useState(!0),[h,b]=f.useState(!1),[g,y]=f.useState(""),[w,j]=f.useState(""),[S,E]=f.useState(""),[N,k]=f.useState(!1),T=f.useRef(null),A=f.useCallback(async()=>{var K;p(!0),y(""),j("");try{const q=(await Ee.getTranscriptTemplate()).data??null;if(q){const ue={...q,Typography:{...q.Typography,FontFamily:d5((K=q.Typography)==null?void 0:K.FontFamily)}};l(ue),d(structuredClone(ue))}}catch(U){y(U instanceof Error?U.message:"Failed to load template")}finally{p(!1)}},[]);f.useEffect(()=>{A()},[A]);const O=f.useCallback(async K=>{k(!0);try{const U=await Ee.previewTranscriptTemplate(K);E(U)}catch{E("

Preview failed to load.

")}finally{k(!1)}},[]);f.useEffect(()=>{if(o)return T.current&&clearTimeout(T.current),T.current=setTimeout(()=>{O(o)},SB),()=>{T.current&&clearTimeout(T.current)}},[o,O]);function M(K,U){l(q=>q&&xl(q,K,U))}async function z(){if(!(a||!o)){b(!0),y(""),j("");try{const K=await Ee.saveTranscriptTemplate(o);j(K.message||"Saved."),d(structuredClone(o))}catch(K){y(K instanceof Error?K.message:"Save failed")}finally{b(!1)}}}const B=o&&c&&JSON.stringify(o)!==JSON.stringify(c);return m?s.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[s.jsx(Be,{className:"h-96 rounded-xl"}),s.jsx(Be,{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:[B?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(he,{size:"sm",onClick:z,disabled:h||!B,children:[s.jsx(ge,{icon:nd,size:16,className:"mr-1.5"}),h?"Saving…":"Save appearance"]})]})]}),g?s.jsx(We,{variant:"destructive",children:s.jsx(Ye,{children:g})}):null,w?s.jsx(We,{className:"border-primary/30 bg-primary/10 text-primary",children:s.jsx(Ye,{children:w})}):null,s.jsxs("div",{className:"grid min-h-0 gap-4 xl:grid-cols-[minmax(320px,420px)_1fr]",children:[s.jsx(EB,{data:o,readOnly:a,onPatch:M}),s.jsxs(Xe,{className:"flex min-h-[520px] flex-col overflow-hidden border-border bg-card",children:[s.jsxs(it,{className:"pb-2",children:[s.jsx(lt,{className:"text-base",children:"Live preview"}),s.jsxs(Et,{children:["Sample ticket with your current settings",N?" · updating…":""]})]}),s.jsx(Ze,{className:"min-h-0 flex-1 p-4 pt-0",children:s.jsx("iframe",{title:"Transcript template preview",srcDoc:S,className:fe("h-[min(640px,calc(100svh-14rem))] w-full rounded-lg border border-border bg-background",N&&"opacity-60"),sandbox:"allow-same-origin"})})]})]})]}):s.jsx(We,{variant:"destructive",children:s.jsx(Ye,{children:g||"Failed to load template"})})}function EB({data:e,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:CB.map(o=>s.jsxs(Xe,{className:"border-border bg-card",children:[s.jsxs(it,{className:"pb-3",children:[s.jsx(lt,{className:"text-base",children:o.title}),o.description?s.jsx(Et,{children:o.description}):null]}),s.jsx(Ze,{className:"grid gap-4 sm:grid-cols-2",children:o.fields.map(l=>s.jsx("div",{className:l.type==="textarea"?"sm:col-span-2":"",children:s.jsx(Vg,{field:l,value:To(e,l.path),readOnly:n,onChange:c=>a(l.path,c)})},l.path))})]},o.title))})}function kB(e,n){return n&&e!=="viewer"}function TB(){const{user:e,hasPermission:n}=Ut(),a=!kB(e==null?void 0:e.role,n("transcripts")),[o,l]=f.useState(null),[c,d]=f.useState(!0),[m,p]=f.useState(!1),[h,b]=f.useState(!1),[g,y]=f.useState(""),[w,j]=f.useState(""),S=f.useCallback(async()=>{var k,T,A;d(!0),y(""),j("");try{const M=(await Ee.getTranscriptSettings()).data;M&&l({autoDelete:{enabled:!!((k=M.autoDelete)!=null&&k.enabled),afterDays:((T=M.autoDelete)==null?void 0:T.afterDays)??30},publicAccess:{enabled:!!((A=M.publicAccess)!=null&&A.enabled)}})}catch(O){y(O instanceof Error?O.message:"Failed to load settings")}finally{d(!1)}},[]);f.useEffect(()=>{S()},[S]);async function E(){if(!(!o||a)){p(!0),y(""),j("");try{const k=await Ee.updateTranscriptSettings(o);k.data&&l({autoDelete:{enabled:k.data.autoDelete.enabled,afterDays:k.data.autoDelete.afterDays},publicAccess:{enabled:k.data.publicAccess.enabled}}),j(k.message??"Settings saved.")}catch(k){y(k instanceof Error?k.message:"Failed to save settings")}finally{p(!1)}}}async function N(){var k,T;if(!a){b(!0),y(""),j("");try{const A=await Ee.purgeTranscripts();j(A.message??((k=A.data)!=null&&k.skipped?"Auto-delete is disabled.":`Removed ${((T=A.data)==null?void 0:T.deleted)??0} transcript(s).`))}catch(A){y(A instanceof Error?A.message:"Purge failed")}finally{b(!1)}}}return c?s.jsxs("div",{className:"space-y-4",children:[s.jsx(Be,{className:"h-40 w-full rounded-xl"}),s.jsx(Be,{className:"h-40 w-full rounded-xl"})]}):o?s.jsxs("div",{className:"mx-auto max-w-2xl space-y-4",children:[a?s.jsx(We,{children:s.jsx(Ye,{children:"You have view-only access. An admin or editor can change these settings."})}):null,g?s.jsx(We,{variant:"destructive",children:s.jsx(Ye,{children:g})}):null,w?s.jsx(We,{children:s.jsx(Ye,{children:w})}):null,s.jsxs(Xe,{className:"border-border bg-card",children:[s.jsxs(it,{children:[s.jsx(lt,{className:"text-base",children:"Auto-delete"}),s.jsx(Et,{children:"Remove transcript files automatically after they reach a certain age. The server checks hourly and whenever you open the library."})]}),s.jsxs(Ze,{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:k=>l(T=>T&&{...T,autoDelete:{...T.autoDelete,enabled:k.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(Ie,{id:"transcript-after-days",type:"number",min:1,max:3650,disabled:a||!o.autoDelete.enabled,value:o.autoDelete.afterDays,onChange:k=>l(T=>T&&{...T,autoDelete:{...T.autoDelete,afterDays:Math.min(3650,Math.max(1,parseInt(k.target.value,10)||1))}}),className:"max-w-[8rem]"})]}),s.jsxs(he,{type:"button",variant:"outline",size:"sm",disabled:a||h,onClick:()=>void N(),children:[s.jsx(ge,{icon:or,size:16,className:fe(h&&"animate-spin")}),"Run cleanup now"]})]})]}),s.jsxs(Xe,{className:"border-border bg-card",children:[s.jsxs(it,{children:[s.jsx(lt,{className:"text-base",children:"Public transcripts"}),s.jsxs(Et,{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(Ze,{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:k=>l(T=>T&&{...T,publicAccess:{enabled:k.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(he,{type:"button",disabled:m,onClick:()=>void E(),children:[s.jsx(ge,{icon:nd,size:16}),m?"Saving…":"Save settings"]})]}):s.jsx(We,{variant:"destructive",children:s.jsx(Ye,{children:"Could not load transcript settings."})})}function RB(e,n){return n&&e!=="viewer"}function T0(e){return e==null?"":e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function R0(e){const n=new Date(e);return Number.isNaN(n.getTime())?e:n.toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"})}function AB(){var G;const{user:e,hasPermission:n}=Ut(),a=RB(e==null?void 0:e.role,n("transcripts")),[o,l]=f.useState("browse"),[c,d]=f.useState([]),[m,p]=f.useState(null),[h,b]=f.useState(!0),[g,y]=f.useState(""),[w,j]=f.useState(""),[S,E]=f.useState(""),[N,k]=f.useState(0),[T,A]=f.useState(!1),[O,M]=f.useState(!1),[z,B]=f.useState(!1),[K,U]=f.useState(!1),q=f.useCallback(async()=>{b(!0),j("");try{const F=(await Ee.listTranscripts()).data??[];d(F),p(oe=>{var ae;return oe&&F.some(be=>be.id===oe)?oe:((ae=F[0])==null?void 0:ae.id)??null})}catch(V){j(V instanceof Error?V.message:"Failed to load transcripts")}finally{b(!1)}},[]);f.useEffect(()=>{q()},[q]),f.useEffect(()=>{o==="browse"&&Ee.getTranscriptSettings().then(V=>{var F,oe;B(!!((oe=(F=V.data)==null?void 0:F.publicAccess)!=null&&oe.enabled))}).catch(()=>B(!1))},[o]);const ue=f.useMemo(()=>{if(!S.trim())return c;const V=S.toLowerCase();return c.filter(F=>F.id.includes(V)||F.filename.toLowerCase().includes(V)||F.ticketName&&F.ticketName.toLowerCase().includes(V))},[c,S]),pe=f.useMemo(()=>c.find(V=>V.id===m)??null,[c,m]),xe=m?`/api/system/transcripts/${encodeURIComponent(m)}/view`:null,se=m?`/api/system/transcripts/${encodeURIComponent(m)}/download`:null,L=m&&z?`${window.location.origin}/transcripts/${encodeURIComponent(m)}`:null;function I(V){y(""),p(V),k(F=>F+1)}function H(){xe&&window.open(xe,"_blank","noopener,noreferrer")}function Z(){L&&window.open(L,"_blank","noopener,noreferrer")}async function te(){if(L)try{await navigator.clipboard.writeText(L),U(!0),window.setTimeout(()=>U(!1),2e3)}catch{y("Could not copy link to clipboard.")}}async function _(){var F;if(!m||!a)return;const V=((F=pe==null?void 0:pe.ticketName)==null?void 0:F.trim())||`channel ${m}`;if(window.confirm(`Delete the transcript for ${V}? This cannot be undone.`)){M(!0),y("");try{await Ee.deleteTranscript(m),await q()}catch(oe){y(oe instanceof Error?oe.message:"Failed to delete transcript")}finally{M(!1)}}}async function D(){if(!(!se||!pe)){A(!0),y("");try{const V=await fetch(se,{credentials:"include"});if(!V.ok){const be=await V.json().catch(()=>({}));throw new Error(be.error||`Download failed (${V.status})`)}const F=await V.blob(),oe=URL.createObjectURL(F),ae=document.createElement("a");ae.href=oe,ae.download=pe.filename,ae.click(),URL.revokeObjectURL(oe)}catch(V){y(V instanceof Error?V.message:"Failed to download transcript")}finally{A(!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(he,{type:"button",variant:o==="browse"?"secondary":"ghost",size:"sm",className:"h-8",onClick:()=>l("browse"),children:"Library"}),s.jsx(he,{type:"button",variant:o==="appearance"?"secondary":"ghost",size:"sm",className:"h-8",onClick:()=>l("appearance"),children:"Appearance"}),s.jsx(he,{type:"button",variant:o==="settings"?"secondary":"ghost",size:"sm",className:"h-8",onClick:()=>l("settings"),children:"Settings"})]}),o==="browse"?s.jsxs(he,{variant:"outline",size:"sm",onClick:()=>q(),disabled:h,children:[s.jsx(ge,{icon:or,size:16,className:fe(h&&"animate-spin")}),"Refresh"]}):null]})]}),o==="appearance"?s.jsx(NB,{}):o==="settings"?s.jsx(TB,{}):s.jsxs(s.Fragment,{children:[w?s.jsx(We,{variant:"destructive",children:s.jsx(Ye,{children:w})}):null,s.jsxs("div",{className:"grid min-h-0 flex-1 gap-4 lg:grid-cols-[minmax(240px,320px)_1fr]",children:[s.jsxs(Xe,{className:"flex min-h-[420px] flex-col border-border bg-card",children:[s.jsxs(it,{className:"space-y-3 pb-3",children:[s.jsxs(lt,{className:"text-base font-medium",children:["Saved transcripts",!h&&c.length>0?s.jsxs("span",{className:"ml-2 font-normal text-muted-foreground",children:["(",c.length,")"]}):null]}),s.jsxs("div",{className:"relative",children:[s.jsx(ge,{icon:ad,size:16,className:"pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground"}),s.jsx(Ie,{placeholder:"Search by ticket name or channel ID…",value:S,onChange:V=>E(V.target.value),className:"pl-9"})]})]}),s.jsx(Ze,{className:"min-h-0 flex-1 p-0 pb-4",children:s.jsx($l,{className:"h-[min(520px,calc(100svh-16rem))] px-4",children:h?s.jsx("div",{className:"space-y-2",children:Array.from({length:6}).map((V,F)=>s.jsx(Be,{className:"h-16 w-full rounded-lg"},F))}):ue.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(ge,{icon:il,size:32,className:"opacity-40"}),s.jsx("p",{children:c.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:ue.map(V=>{var ae;const F=V.id===m,oe=((ae=V.ticketName)==null?void 0:ae.trim())||`Channel ${V.id}`;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>I(V.id),className:fe("w-full rounded-lg border px-3 py-2.5 text-left transition-colors",F?"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:oe}),s.jsxs("p",{className:"mt-0.5 text-xs text-muted-foreground",children:[R0(V.createdAt),V.size!=null?` · ${T0(V.size)}`:""]})]})},V.id)})})})})]}),s.jsxs(Xe,{className:"flex min-h-[420px] flex-col overflow-hidden border-border bg-card",children:[s.jsxs(it,{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(lt,{className:"truncate text-base font-medium",children:pe?((G=pe.ticketName)==null?void 0:G.trim())||`Channel ${pe.id}`:"Preview"}),pe?s.jsxs("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:[R0(pe.createdAt),pe.size!=null?` · ${T0(pe.size)}`:""]}):null]}),s.jsxs("div",{className:"flex shrink-0 flex-wrap gap-2",children:[L?s.jsxs(s.Fragment,{children:[s.jsxs(he,{variant:"outline",size:"sm",onClick:()=>void te(),children:[s.jsx(ge,{icon:t2,size:16}),K?"Copied":"Copy link"]}),s.jsxs(he,{variant:"outline",size:"sm",onClick:Z,children:[s.jsx(ge,{icon:rd,size:16}),"Public page"]})]}):null,s.jsxs(he,{variant:"outline",size:"sm",disabled:!xe,onClick:H,children:[s.jsx(ge,{icon:s8,size:16}),"Open tab"]}),s.jsxs(he,{variant:"outline",size:"sm",disabled:!se||T,onClick:()=>void D(),children:[s.jsx(ge,{icon:td,size:16}),T?"Saving…":"Download"]}),a?s.jsxs(he,{variant:"outline",size:"sm",disabled:!m||O,className:"text-destructive hover:text-destructive",onClick:()=>void _(),children:[s.jsx(ge,{icon:wl,size:16}),O?"Deleting…":"Delete"]}):null]})]}),s.jsxs(Ze,{className:"flex min-h-0 flex-1 flex-col gap-2 p-4 pt-0",children:[g?s.jsx(We,{variant:"destructive",children:s.jsx(Ye,{children:g})}):null,pe&&xe?s.jsx("iframe",{title:`Transcript ${pe.id}`,src:xe,className:"min-h-[min(560px,calc(100svh-18rem))] w-full flex-1 rounded-lg border border-border bg-background",sandbox:"allow-same-origin"},N):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(ge,{icon:il,size:40,className:"opacity-30"}),s.jsx("p",{children:"Select a transcript from the list to preview it here."})]})]})]})]})]})]})}function MB(){const[e,n]=f.useState([]),[a,o]=f.useState(""),[l,c]=f.useState(!0),[d,m]=f.useState(""),[p,h]=f.useState(null),[b,g]=f.useState(!1),[y,w]=f.useState(!1),[j,S]=f.useState([]),[E,N]=f.useState(!1),[k,T]=f.useState(""),[A,O]=f.useState([]),[M,z]=f.useState(!1),[B,K]=f.useState(null),[U,q]=f.useState(!1),[ue,pe]=f.useState(""),[xe,se]=f.useState(null),[L,I]=f.useState(""),[H,Z]=f.useState(!1),[te,_]=f.useState(null),[D,G]=f.useState(""),[V,F]=f.useState(null),oe=ee=>{_(ee),G("Closed via Web Dashboard"),Z(!0)},ae=async()=>{if(!te)return;const ee=te.ticket_id;F(ee);try{await Ee.closeTicket(ee,D||"Closed via Web Dashboard"),Bt.success("Ticket closed and transcript saved."),n(re=>re.filter(ke=>ke.ticket_id!==ee)),(p==null?void 0:p.ticket_id)===ee&&(g(!1),w(!1),h(null)),Z(!1),_(null)}catch(re){Bt.error(re instanceof Error?re.message:"Failed to close ticket.")}finally{F(null)}},be=f.useRef(null),ve=f.useRef(null),Y=()=>{var ee;(ee=be.current)==null||ee.scrollIntoView({behavior:"smooth"})},le=f.useCallback(async()=>{c(!0),m("");try{const ee=await Ee.listOpenTickets();ee.data&&(o(ee.data.guildId),n(ee.data.tickets.sort((re,ke)=>ke.created_at-re.created_at)))}catch(ee){m(ee instanceof Error?ee.message:"Failed to load open tickets")}finally{c(!1)}},[]);f.useEffect(()=>{le()},[le]),f.useEffect(()=>{Ee.getGuildResources().then(ee=>{ee.data&&K(ee.data)}).catch(()=>{})},[]);const ye=f.useCallback(ee=>{p&&ee.ticketId===p.ticket_id&&(S(re=>re.some(ke=>ke.id===ee.message.id)?re:[...re,ee.message]),setTimeout(Y,100))},[p]),Te=f.useCallback(ee=>{p&&ee.ticketId===p.ticket_id&&S(re=>re.filter(ke=>ke.id!==ee.messageId))},[p]),Le=f.useCallback(ee=>{p&&ee.ticketId===p.ticket_id&&S(re=>re.map(ke=>ke.id===ee.messageId?{...ke,content:ee.content}:ke))},[p]),rt=f.useCallback(ee=>{n(re=>re.some(ke=>ke.ticket_id===ee.ticket_id)?re:[ee,...re]),Bt.info("New Ticket Created",{description:`#${ee.ticket_id} - ${ee.subject||"No Subject"}`})},[]),ht=f.useCallback(ee=>{n(re=>re.filter(ke=>ke.ticket_id!==ee.ticket_id)),(p==null?void 0:p.ticket_id)===ee.ticket_id&&Bt.warning("Active ticket was closed in Discord.")},[p]);Yg({onTicketMessage:ye,onTicketMessageDeleted:Te,onTicketMessageUpdated:Le,onTicketCreated:rt,onTicketClosed:ht});const Mt=async ee=>{var re;h(ee),g(!0),N(!0),S([]),O([]),se(null);try{const ke=await Ee.getTicketMessages(ee.ticket_id);(re=ke.data)!=null&&re.messages&&(S(ke.data.messages),setTimeout(Y,150))}catch(ke){Bt.error(ke instanceof Error?ke.message:"Failed to fetch messages")}finally{N(!1)}},Tr=ee=>{const re=Array.from(ee.target.files||[]);re.length&&(re.forEach(ke=>{const we=new FileReader;we.onload=De=>{var ct;const at=(ct=De.target)==null?void 0:ct.result;O(mt=>[...mt,{filename:ke.name,data:at,previewUrl:ke.type.startsWith("image/")?at:void 0,sizeMb:(ke.size/1024/1024).toFixed(2)}])},we.readAsDataURL(ke)}),ve.current&&(ve.current.value=""))},_t=ee=>{O(re=>re.filter((ke,we)=>we!==ee))},Ya=async ee=>{var we;if(ee.preventDefault(),!k.trim()&&!A.length||!p||M)return;const re=k.trim(),ke=[...A];z(!0),T(""),O([]),q(!1);try{const De=await Ee.me().catch(()=>null),at=((we=De==null?void 0:De.data)==null?void 0:we.username)||"Staff",ct=await Ee.sendTicketReply(p.ticket_id,re,at,ke.map(mt=>({filename:mt.filename,data:mt.data})));ct.data&&(S(mt=>mt.some(Zt=>Zt.id===ct.data.id)?mt:[...mt,{id:ct.data.id,author:ct.data.author,content:ct.data.content,attachments:ct.data.attachments||[],createdAt:ct.data.createdAt}]),setTimeout(Y,100))}catch(De){Bt.error(De instanceof Error?De.message:"Failed to send reply to Discord."),T(re),O(ke)}finally{z(!1)}},qa=async ee=>{if(p)try{await Ee.deleteTicketMessage(p.ticket_id,ee),S(re=>re.filter(ke=>ke.id!==ee)),Bt.success("Message deleted in Discord.")}catch(re){Bt.error(re instanceof Error?re.message:"Failed to delete message.")}},qt=ee=>{se(ee.id),I(ee.content)},dr=()=>{se(null),I("")},Kt=async ee=>{if(!(!p||!L.trim()))try{await Ee.editTicketMessage(p.ticket_id,ee,L.trim()),S(re=>re.map(ke=>ke.id===ee?{...ke,content:L.trim()}:ke)),se(null),Bt.success("Message updated in Discord.")}catch(re){Bt.error(re instanceof Error?re.message:"Failed to edit message.")}},ti=ee=>{const re=ee.target.value;T(re);const ke=ee.target.selectionStart||re.length,we=re.slice(0,ke),De=we.lastIndexOf("@");if(De!==-1&&!we.slice(De).includes(" ")){const at=we.slice(De+1).toLowerCase();pe(at),q(!0)}else q(!1)},fr=(ee,re,ke)=>{const we=k.lastIndexOf("@"),De=k.slice(0,we),at=ke?`<@&${re}>`:`<@${re}>`;T(`${De}${at} `),q(!1)},Lo=ee=>{const re=Math.floor((Date.now()-ee)/1e3);return Fh(re)},Rr=ee=>new Date(ee).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),Xt=ee=>{if(!ee)return null;const re=/(```[\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 ee.split(re).map((we,De)=>{var Zt;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:Xt(we.slice(3))},De);if(we.startsWith("## "))return s.jsx("span",{className:"text-base font-bold text-foreground block my-1 tracking-tight",children:Xt(we.slice(3))},De);if(we.startsWith("### "))return s.jsx("span",{className:"text-sm font-bold text-foreground block my-0.5",children:Xt(we.slice(4))},De);if(we.startsWith("```")&&we.endsWith("```")&&we.length>=6){const Me=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:Me})},De)}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)},De);if(we.startsWith("***")&&we.endsWith("***")&&we.length>6)return s.jsx("strong",{className:"font-bold italic",children:Xt(we.slice(3,-3))},De);if(we.startsWith("**")&&we.endsWith("**")&&we.length>4)return s.jsx("strong",{className:"font-bold",children:Xt(we.slice(2,-2))},De);if(we.startsWith("__")&&we.endsWith("__")&&we.length>4)return s.jsx("span",{className:"underline underline-offset-2",children:Xt(we.slice(2,-2))},De);if(we.startsWith("~~")&&we.endsWith("~~")&&we.length>4)return s.jsx("span",{className:"line-through opacity-80",children:Xt(we.slice(2,-2))},De);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)},De);const at=we.match(/^<@!?(\d+)>$/);if(at){const Me=at[1],Je=new Map;p&&Je.set(p.user_id,"Ticket Author"),j.forEach(kt=>{var Jn;(Jn=kt.author)!=null&&Jn.id&&Je.set(kt.author.id,kt.author.globalName||kt.author.username)});const St=Je.get(Me);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: ${Me}`,children:["@",St||"User"]},De)}const ct=we.match(/^<@&(\d+)>$/);if(ct){const Me=ct[1],Je=(Zt=B==null?void 0:B.roles)==null?void 0:Zt.find(St=>St.id===Me);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:["@",Je?Je.name:`Role (${Me})`]},De)}const mt=we.match(/^\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)$/);if(mt){const Me=mt[1],Je=mt[2];return s.jsx("a",{href:Je,target:"_blank",rel:"noreferrer",className:"text-primary underline hover:opacity-80 break-all",children:Me},De)}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"})},De):s.jsx("a",{href:we,target:"_blank",rel:"noreferrer",className:"text-primary underline hover:opacity-80 break-all",children:we},De):we})},Qn=ee=>!ee||ee.length===0?null:s.jsx("div",{className:"space-y-2 mt-1",children:ee.map(re=>{var at,ct,mt;const ke=((at=re.contentType)==null?void 0:at.startsWith("image/"))||/\.(png|jpe?g|gif|webp|svg)$/i.test(re.name),we=((ct=re.contentType)==null?void 0:ct.startsWith("video/"))||/\.(mp4|webm|mov|mkv)$/i.test(re.name),De=((mt=re.contentType)==null?void 0:mt.startsWith("audio/"))||/\.(mp3|wav|ogg|m4a)$/i.test(re.name);return ke?s.jsx("div",{className:"rounded-lg overflow-hidden border border-border bg-black/40",children:s.jsx("a",{href:re.url,target:"_blank",rel:"noreferrer",children:s.jsx("img",{src:re.url,alt:re.name,className:"max-h-80 max-w-full object-contain hover:opacity-95 transition-opacity",loading:"lazy"})})},re.id):we?s.jsx("div",{className:"rounded-lg overflow-hidden border border-border bg-black",children:s.jsx("video",{src:re.url,controls:!0,className:"max-h-80 max-w-full"})},re.id):De?s.jsx("div",{className:"p-2 border border-border rounded-lg bg-secondary/20",children:s.jsx("audio",{src:re.url,controls:!0,className:"w-full h-8"})},re.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(ge,{icon:ay,size:16,className:"text-primary shrink-0"}),s.jsx("span",{className:"truncate font-medium",children:re.name})]}),s.jsx(he,{variant:"ghost",size:"sm",asChild:!0,className:"h-7 px-2 text-xs",children:s.jsx("a",{href:re.url,target:"_blank",rel:"noreferrer",download:!0,children:"Download"})})]},re.id)})}),zo=ee=>!ee||ee.length===0?null:s.jsx("div",{className:"space-y-3 mt-1.5 w-full",children:ee.map((re,ke)=>{var we,De,at,ct;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:re.color||"#5865F2"},children:[re.author&&s.jsxs("div",{className:"flex items-center gap-2 text-xs font-semibold text-foreground",children:[re.author.iconURL&&s.jsx("img",{src:re.author.iconURL,alt:"",className:"h-4 w-4 rounded-full"}),s.jsx("span",{children:re.author.name})]}),((we=re.thumbnail)==null?void 0:we.url)&&s.jsx("img",{src:re.thumbnail.url,alt:"",className:"h-12 w-12 rounded object-cover absolute top-3 right-3 border border-border"}),re.title&&s.jsx("h4",{className:"font-bold text-sm text-foreground tracking-tight pr-12",children:Xt(re.title)}),re.description&&s.jsx("div",{className:"text-muted-foreground whitespace-pre-wrap leading-relaxed pr-12",children:Xt(re.description)}),re.fields&&re.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:re.fields.map((mt,Zt)=>s.jsxs("div",{className:`space-y-0.5 ${mt.inline?"":"sm:col-span-2"}`,children:[s.jsx("p",{className:"font-semibold text-foreground text-[11px] uppercase tracking-wider",children:mt.name}),s.jsx("p",{className:"text-muted-foreground whitespace-pre-wrap",children:Xt(mt.value)})]},Zt))}),((De=re.image)==null?void 0:De.url)&&s.jsx("div",{className:"rounded-md overflow-hidden border border-border mt-2",children:s.jsx("img",{src:re.image.url,alt:"",className:"max-h-64 w-full object-cover"})}),(re.footer||re.timestamp)&&s.jsxs("div",{className:"flex items-center gap-2 pt-1 border-t border-border/20 text-[10px] text-muted-foreground",children:[((at=re.footer)==null?void 0:at.iconURL)&&s.jsx("img",{src:re.footer.iconURL,alt:"",className:"h-3.5 w-3.5 rounded-full"}),((ct=re.footer)==null?void 0:ct.text)&&s.jsx("span",{children:re.footer.text}),re.timestamp&&s.jsxs("span",{children:[new Date(re.timestamp).toLocaleDateString()," ",new Date(re.timestamp).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]})]})]},ke)})}),mr=ee=>{if(!ee||ee.length===0)return null;const re=ee.map(ke=>({...ke,components:(ke.components||[]).filter(we=>we.customId||we.url||we.type===2||we.type===3||we.type==="BUTTON"||we.type==="STRING_SELECT")})).filter(ke=>ke.components&&ke.components.length>0);return re.length===0?null:s.jsx("div",{className:"space-y-2 mt-2.5 w-full",children:re.map((ke,we)=>{var De;return s.jsx("div",{className:"flex items-center gap-2 flex-wrap",children:(De=ke.components)==null?void 0:De.map((at,ct)=>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:[at.emoji&&s.jsx("span",{children:at.emoji}),s.jsx("span",{children:at.label||at.customId||"Button"})]},ct))},we)})})},pr=()=>s.jsx($l,{className:"flex-1 p-4 sm:p-6",children:s.jsxs("div",{className:"max-w-4xl mx-auto w-full space-y-4",children:[E?s.jsxs("div",{className:"space-y-4 p-4",children:[s.jsx(Be,{className:"h-10 w-3/4"}),s.jsx(Be,{className:"h-10 w-1/2 ml-auto"}),s.jsx(Be,{className:"h-10 w-2/3"})]}):j.length===0?s.jsx("div",{className:"p-12 text-center text-muted-foreground text-sm",children:"No recent messages in this ticket channel."}):j.map(ee=>{var re;return s.jsxs("div",{className:`group flex items-start gap-3 ${ee.author.isDashboard?"flex-row-reverse":""}`,children:[s.jsxs(Ia,{className:"h-8 w-8 shrink-0",children:[s.jsx(Co,{src:ee.author.avatar,alt:ee.author.username}),s.jsx($a,{children:s.jsx(ge,{icon:N8,size:16})})]}),s.jsxs("div",{className:`flex flex-col space-y-1 max-w-[80%] ${ee.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:ee.author.globalName||ee.author.username}),ee.author.bot&&s.jsx(An,{variant:"secondary",className:"px-1 py-0 text-[10px]",children:"BOT"}),ee.author.isDashboard&&s.jsx(An,{variant:"default",className:"px-1 py-0 text-[10px]",children:"STAFF"}),s.jsx("span",{children:Rr(ee.createdAt)}),s.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-1",children:[s.jsx(he,{variant:"ghost",size:"icon",className:"h-5 w-5 text-muted-foreground hover:text-foreground",onClick:()=>qt(ee),title:"Edit Message",children:s.jsx(ge,{icon:a2,size:12})}),s.jsx(he,{variant:"ghost",size:"icon",className:"h-5 w-5 text-muted-foreground hover:text-destructive",onClick:()=>qa(ee.id),title:"Delete Message",children:s.jsx(ge,{icon:wl,size:12})})]})]}),xe===ee.id?s.jsxs("div",{className:"flex items-center gap-2 w-full mt-1",children:[s.jsx(Ie,{value:L,onChange:ke=>I(ke.target.value),className:"h-8 text-sm",autoFocus:!0}),s.jsx(he,{size:"sm",className:"h-8 px-2 bg-primary",onClick:()=>Kt(ee.id),children:s.jsx(ge,{icon:S8,size:14})}),s.jsx(he,{size:"sm",variant:"ghost",className:"h-8 px-2",onClick:dr,children:s.jsx(ge,{icon:Zr,size:14})})]}):ee.content?s.jsx("div",{className:`rounded-lg px-3.5 py-2.5 text-sm whitespace-pre-wrap ${ee.author.isDashboard?"bg-primary text-primary-foreground":"bg-secondary/40 text-secondary-foreground border border-border/50"}`,style:ee.containerColor||ee.author.bot&&!((re=ee.embeds)!=null&&re.length)?{borderLeftWidth:"4px",borderLeftColor:ee.containerColor||"#5865F2"}:void 0,children:Xt(ee.content)}):null,Qn(ee.attachments),zo(ee.embeds),mr(ee.components)]})]},ee.id)}),s.jsx("div",{ref:be})]})}),Ht=()=>{var ee;return s.jsxs("div",{className:"p-4 border-t border-border bg-secondary/10 flex flex-col gap-2 relative",children:[A.length>0&&s.jsx("div",{className:"max-w-4xl mx-auto w-full flex items-center gap-2 flex-wrap mb-1",children:A.map((re,ke)=>s.jsxs("div",{className:"flex items-center gap-2 p-1.5 px-3 rounded-lg border border-border bg-secondary text-xs",children:[re.previewUrl?s.jsx("img",{src:re.previewUrl,alt:"",className:"h-6 w-6 rounded object-cover"}):s.jsx(ge,{icon:ay,size:14,className:"text-primary"}),s.jsx("span",{className:"font-medium max-w-[120px] truncate",children:re.filename}),s.jsxs("span",{className:"text-muted-foreground text-[10px]",children:[re.sizeMb,"MB"]}),s.jsx("button",{type:"button",onClick:()=>_t(ke),className:"text-muted-foreground hover:text-destructive ml-1",children:s.jsx(ge,{icon:Zr,size:12})})]},ke))}),U&&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 (@)"}),p&&s.jsxs("button",{type:"button",onClick:()=>fr("Ticket Author",p.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(Ia,{className:"h-5 w-5",children:s.jsx($a,{children:"U"})}),s.jsx("span",{className:"font-medium",children:"Ticket Author"})]}),s.jsxs("span",{className:"text-[10px] font-mono text-muted-foreground",children:["@",p.user_id]})]}),(ee=B==null?void 0:B.roles)==null?void 0:ee.filter(re=>re.name.toLowerCase().includes(ue)).slice(0,5).map(re=>s.jsxs("button",{type:"button",onClick:()=>fr(re.name,re.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:["@",re.name]}),s.jsx("span",{className:"text-[10px] font-mono text-muted-foreground",children:"Role"})]},re.id))]}),s.jsxs("form",{onSubmit:Ya,className:"max-w-4xl mx-auto w-full flex items-center gap-2",children:[s.jsx("input",{type:"file",ref:ve,multiple:!0,onChange:Tr,className:"hidden",accept:"image/*,video/*,audio/*,.pdf,.zip,.txt,.json"}),s.jsx(he,{type:"button",variant:"outline",size:"sm",onClick:()=>{var re;return(re=ve.current)==null?void 0:re.click()},title:"Attach files or media",className:"h-9 px-2.5",children:s.jsx(ge,{icon:u8,size:16})}),s.jsx(Ie,{value:k,onChange:ti,placeholder:"Type a reply... Use @ to tag roles or users",disabled:M||E,className:"flex-1"}),s.jsx(he,{type:"submit",size:"sm",disabled:M||!k.trim()&&!A.length||E,children:M?s.jsx(ge,{icon:or,size:16,className:"animate-spin"}):s.jsxs(s.Fragment,{children:[s.jsx(ge,{icon:w8,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(he,{onClick:()=>void le(),disabled:l,variant:"outline",size:"sm",children:[s.jsx(ge,{icon:or,size:16,className:l?"animate-spin mr-2":"mr-2"}),"Refresh"]})]}),s.jsx(Xe,{className:"border-border bg-card",children:s.jsx(Ze,{className:"p-0",children:l?s.jsxs("div",{className:"space-y-4 p-6",children:[s.jsx(Be,{className:"h-12 w-full"}),s.jsx(Be,{className:"h-12 w-full"}),s.jsx(Be,{className:"h-12 w-full"})]}):d?s.jsx("div",{className:"p-6",children:s.jsx(We,{variant:"destructive",children:s.jsx(Ye,{children:d})})}):e.length===0?s.jsx("div",{className:"p-12 text-center text-muted-foreground",children:"No open tickets at the moment!"}):s.jsx("div",{className:"divide-y divide-border",children:e.map(ee=>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:ee.subject||"Untitled Ticket"}),s.jsxs("span",{className:"text-xs font-mono text-muted-foreground",children:["#",ee.ticket_id]}),s.jsx(An,{variant:"outline",className:"text-xs capitalize",children:ee.department}),s.jsxs(An,{variant:ee.priority==="high"?"destructive":ee.priority==="medium"?"secondary":"outline",className:"text-xs capitalize",children:[ee.priority," priority"]})]}),s.jsxs("p",{className:"text-sm text-muted-foreground",children:["User ID: ",s.jsx("span",{className:"font-mono",children:ee.user_id}),ee.description&&` • ${ee.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(ge,{icon:i8,size:14,className:"mr-1.5"}),Lo(ee.created_at)]}),s.jsxs(he,{variant:"default",size:"sm",onClick:()=>Mt(ee),className:"bg-primary text-primary-foreground hover:bg-primary/90",children:[s.jsx(ge,{icon:l8,size:16,className:"mr-2"}),"Live Chat"]}),s.jsxs(he,{variant:"destructive",size:"sm",onClick:()=>oe(ee),disabled:V===ee.ticket_id,children:[V===ee.ticket_id?s.jsx(ge,{icon:or,size:14,className:"animate-spin mr-1.5"}):s.jsx(ge,{icon:Zr,size:14,className:"mr-1.5"}),"Close"]}),a&&s.jsx(he,{variant:"secondary",size:"sm",asChild:!0,children:s.jsx("a",{href:`https://discord.com/channels/${a}/${ee.ticket_id}`,target:"_blank",rel:"noreferrer",children:s.jsx(ge,{icon:rd,size:16})})})]})]},ee.ticket_id))})})}),b&&y&&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:ee=>{ee.target===ee.currentTarget&&w(!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:(p==null?void 0:p.subject)||"Ticket Live Chat"}),s.jsxs(An,{variant:"outline",className:"font-mono text-xs shrink-0",children:["#",p==null?void 0:p.ticket_id]}),(p==null?void 0:p.department)&&s.jsx(An,{variant:"secondary",className:"text-xs capitalize shrink-0",children:p.department})]}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[p&&s.jsxs(he,{variant:"destructive",size:"sm",onClick:()=>oe(p),disabled:V===p.ticket_id,className:"h-8 px-2.5 text-xs",children:[V===p.ticket_id?s.jsx(ge,{icon:or,size:14,className:"animate-spin mr-1.5"}):s.jsx(ge,{icon:Zr,size:14,className:"mr-1.5"}),"Close Ticket"]}),s.jsxs(he,{variant:"outline",size:"sm",onClick:()=>w(!1),className:"h-8 px-3 text-xs flex items-center gap-1.5",children:[s.jsx(ge,{icon:h8,size:14}),s.jsx("span",{children:"Collapse"})]}),s.jsx(he,{variant:"ghost",size:"icon",onClick:()=>{g(!1),w(!1)},className:"h-8 w-8 text-muted-foreground hover:text-foreground",children:s.jsx(ge,{icon:Zr,size:18})})]})]}),(p==null?void 0:p.description)&&s.jsx("p",{className:"text-xs text-muted-foreground truncate",children:p.description})]}),pr(),Ht()]})}),b&&!y&&s.jsx(UC,{open:b,onOpenChange:g,children:s.jsxs(bg,{side:"right",className:"w-full sm:max-w-xl p-0 flex flex-col h-full bg-card",children:[s.jsxs(yg,{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(wg,{className:"text-base font-bold truncate",children:(p==null?void 0:p.subject)||"Ticket Live Chat"}),s.jsxs(An,{variant:"outline",className:"font-mono text-xs shrink-0",children:["#",p==null?void 0:p.ticket_id]})]}),s.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[p&&s.jsxs(he,{variant:"destructive",size:"sm",onClick:()=>oe(p),disabled:V===p.ticket_id,className:"h-7 px-2 text-xs",children:[V===p.ticket_id?s.jsx(ge,{icon:or,size:13,className:"animate-spin mr-1"}):s.jsx(ge,{icon:Zr,size:13,className:"mr-1"}),"Close"]}),s.jsxs(he,{variant:"outline",size:"sm",onClick:()=>w(!0),className:"h-7 px-2 text-xs flex items-center gap-1",title:"Open in Full View",children:[s.jsx(ge,{icon:p8,size:13}),s.jsx("span",{children:"Full View"})]})]})]}),(p==null?void 0:p.description)&&s.jsx(Cg,{className:"text-xs text-muted-foreground truncate",children:p.description})]}),pr(),Ht()]})}),s.jsx(zl,{open:H,onOpenChange:Z,children:s.jsxs(qs,{className:"sm:max-w-md bg-card border-border rounded-xl",children:[s.jsxs(Ks,{children:[s.jsxs(Xs,{className:"text-lg font-bold flex items-center gap-2",children:[s.jsx(ge,{icon:Zr,className:"text-destructive",size:20}),"Close Ticket #",te==null?void 0:te.ticket_id]}),s.jsx(Zs,{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(Ie,{value:D,onChange:ee=>G(ee.target.value),placeholder:"e.g. Issue resolved by support team",className:"text-sm"})]}),s.jsxs(Pl,{className:"gap-2 sm:gap-0 mt-2",children:[s.jsx(he,{variant:"outline",size:"sm",onClick:()=>Z(!1),disabled:!!V,children:"Cancel"}),s.jsxs(he,{variant:"destructive",size:"sm",onClick:ae,disabled:!!V,children:[V?s.jsx(ge,{icon:or,size:14,className:"animate-spin mr-1.5"}):s.jsx(ge,{icon:Zr,size:14,className:"mr-1.5"}),"Confirm Close"]})]})]})})]})}const _B=["admin","moderator","editor","viewer","custom"];function OB(){return{mode:"add",id:"",username:"",globalName:"",role:"viewer",enabled:!0,permissions:_a("viewer"),yamlOwner:!1}}function DB({permissions:e,onChange:n,disabled:a}){const o=d=>n({...e,...d}),l=[{key:"overview",title:"Dashboard Overview",description:"Access to system metrics, bot health status, and main dashboard stats."},{key:"tickets",title:"Tickets",description:"View open support tickets, live web chat, send staff replies, and close tickets."},{key:"transcripts",title:"Transcripts",description:"Access saved ticket HTML transcripts and configure public transcript options."},{key:"logs",title:"Console Logs",description:"View real-time bot terminal output, system logs, and runtime error traces."}],c=[["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 Capabilities"}),s.jsxs("div",{className:"grid gap-2.5",children:[l.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(At,{checked:e[d]??(d==="tickets"?e.overview:!1),disabled:a,onCheckedChange:h=>o({[d]:h}),className:"shrink-0"})]},d)),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(At,{checked:e.settings.view,disabled:a,onCheckedChange:d=>o({settings:{...e.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(At,{checked:e.settings.update,disabled:a,onCheckedChange:d=>o({settings:{...e.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(At,{checked:e.users.view,disabled:a,onCheckedChange:d=>o({users:{...e.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(At,{checked:e.users.manage,disabled:a,onCheckedChange:d=>o({users:{...e.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.jsx("div",{className:"grid gap-2.5",children:c.map(([d,m,p])=>{var b;const h=((b=e.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(At,{checked:h.view,disabled:a,onCheckedChange:g=>o({configs:{...e.configs,[d]:{...h,view:g}}})})]}),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(At,{checked:h.edit,disabled:a,onCheckedChange:g=>o({configs:{...e.configs,[d]:{...h,edit:g,view:g?!0:h.view}}})})]})]})]},d)})})]})]})}function LB(e){return e.permissions.users.manage?"Full + user management":e.permissions.settings.update?"Configs + settings updates":Object.values(e.permissions.configs).some(n=>n.edit)?"Can edit configs":"View only"}function zB(){const{user:e,hasPermission:n}=Ut(),a=n("users.manage"),[o,l]=f.useState([]),[c,d]=f.useState([]),[m,p]=f.useState(!0),[h,b]=f.useState(""),[g,y]=f.useState(null),[w,j]=f.useState(!1),S=f.useCallback(async()=>{p(!0),b("");try{const[M,z]=await Promise.all([Ee.listDashboardUsers(),Ee.listGroups().catch(()=>({data:{groups:[]}}))]);M.data&&l(M.data.users),z.data&&d(z.data.groups)}catch(M){b(M instanceof Error?M.message:"Failed to load users")}finally{p(!1)}},[]);f.useEffect(()=>{S()},[S]);const E=f.useMemo(()=>[...o].sort((M,z)=>M.yamlOwner!==z.yamlOwner?M.yamlOwner?-1:1:(M.username||M.id).localeCompare(z.username||z.id)),[o]);function N(){y(OB())}function k(M){y({mode:"edit",id:M.id,username:M.username||"",globalName:M.globalName||"",role:M.yamlOwner?"owner":M.role,enabled:M.enabled,permissions:M.role==="custom"?M.permissions:_a(M.role),yamlOwner:M.yamlOwner})}function T(M){g&&y({...g,role:M,permissions:_a(M,g.permissions)})}async function A(){if(!(!g||!a)){j(!0),b("");try{g.mode==="add"?await Ee.addDashboardUser({id:g.id.trim(),role:g.role,username:g.username||void 0,globalName:g.globalName||void 0,enabled:g.enabled,permissions:g.role==="custom"?g.permissions:void 0}):await Ee.updateDashboardUser(g.id,{role:g.yamlOwner?void 0:g.role,enabled:g.enabled,username:g.username||void 0,globalName:g.globalName||void 0,permissions:g.role==="custom"?g.permissions:void 0}),y(null),await S()}catch(M){b(M instanceof Error?M.message:"Could not save user")}finally{j(!1)}}}async function O(M){if(a&&window.confirm("Remove this user from the dashboard?")){b("");try{await Ee.removeDashboardUser(M),await S()}catch(z){b(z instanceof Error?z.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(he,{onClick:N,children:[s.jsx(ge,{icon:Z0,size:16,className:"mr-2"}),"Add user"]}):null]}),h?s.jsx(We,{variant:"destructive",children:s.jsx(Ye,{children:h})}):null,s.jsx(Xe,{className:"border-border bg-card overflow-hidden",children:s.jsx(Ze,{className:"p-0",children:m?s.jsxs("div",{className:"p-4 space-y-2",children:[s.jsx(Be,{className:"h-8 w-full rounded-md"}),s.jsx(Be,{className:"h-8 w-full rounded-md"})]}):E.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:E.map(M=>{const z=c.find(U=>U.id===M.groupId||U.id===M.role),B=(z==null?void 0:z.color)||"#10B981",K=(z==null?void 0:z.name)||sy[M.yamlOwner?"owner":M.role]||M.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(Ia,{className:"size-7",children:[s.jsx(Co,{src:M.avatar,alt:M.username}),s.jsx($a,{className:"text-[10px]",children:(M.username||M.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:[l2(M),M.id===(e==null?void 0:e.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:M.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:B}}),s.jsx("span",{className:"font-medium text-xs text-foreground",children:K}),M.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:LB(M)}),s.jsx("td",{className:"px-4 py-2.5 whitespace-nowrap",children:M.enabled?s.jsx(An,{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(An,{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(he,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs gap-1 text-muted-foreground hover:text-foreground",onClick:()=>k(M),children:[s.jsx(ge,{icon:c8,size:13}),"Edit"]}),!M.yamlOwner&&s.jsxs(he,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs gap-1 text-muted-foreground hover:text-destructive",onClick:()=>O(M.id),children:[s.jsx(ge,{icon:wl,size:13}),"Remove"]})]})})]},M.id)})})]})})})}),s.jsx(zl,{open:!!g,onOpenChange:M=>!M&&y(null),children:s.jsxs(qs,{className:"max-h-[90vh] max-w-lg overflow-y-auto",children:[s.jsxs(Ks,{children:[s.jsx(Xs,{children:(g==null?void 0:g.mode)==="add"?"Add dashboard user":"Edit user"}),s.jsx(Zs,{children:g!=null&&g.yamlOwner?"This user is an owner in api.yml. Role and removal are managed in the config file.":k8[(g==null?void 0:g.role)??"viewer"]})]}),g?s.jsxs("div",{className:"space-y-4",children:[g.mode==="add"?s.jsxs("div",{className:"space-y-2",children:[s.jsx(ze,{htmlFor:"discord-id",children:"Discord user ID"}),s.jsx(Ie,{id:"discord-id",value:g.id,onChange:M=>y({...g,id:M.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(ze,{children:"Display name (optional)"}),s.jsx(Ie,{value:g.globalName,onChange:M=>y({...g,globalName:M.target.value})})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(ze,{children:"Username (optional)"}),s.jsx(Ie,{value:g.username,onChange:M=>y({...g,username:M.target.value})})]})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(ze,{children:"Permission Group"}),s.jsxs(No,{value:g.role,disabled:g.yamlOwner,onValueChange:M=>{const z=c.find(B=>B.id===M);z?y({...g,role:M,permissions:z.permissions}):T(M)},children:[s.jsx(Ba,{children:s.jsx(Eo,{})}),s.jsx(Ua,{children:g.yamlOwner?s.jsx(an,{value:"owner",children:"Owner"}):c.length>0?c.map(M=>s.jsx(an,{value:M.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:M.color||"#10B981"}}),s.jsx("span",{children:M.name})]})},M.id)):_B.map(M=>s.jsx(an,{value:M,children:sy[M]},M))})]})]}),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(At,{checked:g.enabled,disabled:g.yamlOwner,onCheckedChange:M=>y({...g,enabled:M})})]}),g.role==="custom"&&!g.yamlOwner?s.jsx(DB,{permissions:g.permissions,onChange:M=>y({...g,permissions:M})}):null]}):null,s.jsxs(Pl,{children:[s.jsx(he,{variant:"outline",onClick:()=>y(null),children:"Cancel"}),s.jsx(he,{disabled:w||!a||(g==null?void 0:g.mode)==="add"&&!/^\d{17,20}$/.test(g.id.trim()),onClick:()=>void A(),children:w?"Saving…":"Save"})]})]})})]})}const PB=[{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 IB({permissions:e,onChange:n,disabled:a}){const o=d=>n({...e,...d}),l=[{key:"overview",title:"Dashboard Overview",description:"Access to system metrics, bot health status, and main dashboard stats."},{key:"tickets",title:"Tickets",description:"View open support tickets, live web chat, send staff replies, and close tickets."},{key:"transcripts",title:"Transcripts",description:"Access saved ticket HTML transcripts and configure public transcript options."},{key:"logs",title:"Console Logs",description:"View real-time bot terminal output, system logs, and runtime error traces."}],c=[["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 Capabilities"}),s.jsxs("div",{className:"grid gap-2.5",children:[l.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(At,{checked:e[d]??(d==="tickets"?e.overview:!1),disabled:a,onCheckedChange:h=>o({[d]:h}),className:"shrink-0"})]},d)),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(At,{checked:e.settings.view,disabled:a,onCheckedChange:d=>o({settings:{...e.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(At,{checked:e.settings.update,disabled:a,onCheckedChange:d=>o({settings:{...e.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(At,{checked:e.users.view,disabled:a,onCheckedChange:d=>o({users:{...e.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(At,{checked:e.users.manage,disabled:a,onCheckedChange:d=>o({users:{...e.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.jsx("div",{className:"grid gap-2.5",children:c.map(([d,m,p])=>{var b;const h=((b=e.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(At,{checked:h.view,disabled:a,onCheckedChange:g=>o({configs:{...e.configs,[d]:{...h,view:g}}})})]}),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(At,{checked:h.edit,disabled:a,onCheckedChange:g=>o({configs:{...e.configs,[d]:{...h,edit:g,view:g?!0:h.view}}})})]})]})]},d)})})]})]})}function $B(){const{impersonateGroup:e,impersonatedGroup:n,stopImpersonation:a}=Ut(),[o,l]=f.useState([]),[c,d]=f.useState(!0),[m,p]=f.useState(null),[h,b]=f.useState(null),[g,y]=f.useState(!1),[w,j]=f.useState("add"),[S,E]=f.useState(!1),[N,k]=f.useState(""),[T,A]=f.useState(""),[O,M]=f.useState(""),[z,B]=f.useState("#10B981"),[K,U]=f.useState(""),[q,ue]=f.useState(_a("viewer")),pe=async()=>{var H;d(!0),p(null);try{const Z=await Ee.listGroups();l(((H=Z.data)==null?void 0:H.groups)||[])}catch(Z){p(Z instanceof Error?Z.message:"Failed to load groups")}finally{d(!1)}};f.useEffect(()=>{pe()},[]);const xe=()=>{j("add"),k(""),A(""),M(""),B("#10B981"),U(""),ue(_a("viewer")),y(!0)},se=H=>{j("edit"),k(H.id),A(H.name),M(H.description||""),B(H.color||"#10B981"),U(H.discordRoleId||""),ue(H.permissions||_a("viewer")),y(!0)},L=async()=>{if(!T.trim()){p("Group name is required");return}E(!0),p(null);try{w==="add"?(await Ee.createGroup({name:T.trim(),description:O.trim(),color:z,discordRoleId:K.trim()||null,permissions:q}),b(`Group "${T}" created successfully.`)):(await Ee.updateGroup(N,{name:T.trim(),description:O.trim(),color:z,discordRoleId:K.trim()||null,permissions:q}),b(`Group "${T}" updated successfully.`)),y(!1),await pe()}catch(H){p(H instanceof Error?H.message:"Failed to save group")}finally{E(!1)}},I=async H=>{if(!H.isSystem&&confirm(`Are you sure you want to delete the group "${H.name}"?`))try{await Ee.deleteGroup(H.id),b(`Group "${H.name}" deleted.`),await pe()}catch(Z){p(Z instanceof Error?Z.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."})]}),s.jsxs(he,{onClick:xe,className:"shrink-0 gap-2 bg-primary",children:[s.jsx(ge,{icon:Z0,size:18}),"Create Group"]})]}),m&&s.jsx(We,{variant:"destructive",children:s.jsx(Ye,{children:m})}),h&&s.jsx(We,{className:"border-emerald-500/30 bg-emerald-500/10 text-emerald-500",children:s.jsxs(Ye,{className:"flex items-center justify-between",children:[s.jsx("span",{children:h}),s.jsx(he,{size:"sm",variant:"ghost",className:"h-6 px-2 text-xs",onClick:()=>b(null),children:"Dismiss"})]})}),s.jsx(Xe,{className:"border-border bg-card overflow-hidden",children:s.jsx(Ze,{className:"p-0",children:c?s.jsxs("div",{className:"p-4 space-y-2",children:[s.jsx(Be,{className:"h-8 w-full rounded-md"}),s.jsx(Be,{className:"h-8 w-full rounded-md"})]}):o.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:o.map(H=>{var Z,te,_,D,G,V,F;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:H.color||"#10B981"}}),s.jsx("span",{className:"text-foreground font-semibold text-xs",children:H.name}),H.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(ge,{icon:bu,size:10}),"System"]})]})}),s.jsx("td",{className:"px-4 py-2.5 text-xs text-muted-foreground max-w-xs truncate",children:H.description||"—"}),s.jsx("td",{className:"px-4 py-2.5 whitespace-nowrap",children:H.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(ge,{icon:bu,size:12,className:"text-primary"}),H.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:[((Z=H.permissions)==null?void 0:Z.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"}),(((te=H.permissions)==null?void 0:te.tickets)??((_=H.permissions)==null?void 0:_.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"}),((D=H.permissions)==null?void 0:D.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"}),((G=H.permissions)==null?void 0:G.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"}),((F=(V=H.permissions)==null?void 0:V.users)==null?void 0:F.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(he,{size:"sm",variant:"ghost",className:`h-7 px-2 text-xs gap-1 ${(n==null?void 0:n.id)===H.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:()=>(n==null?void 0:n.id)===H.id?a():e(H.id),children:[s.jsx(ge,{icon:bu,size:13}),(n==null?void 0:n.id)===H.id?"Active Preview":"View as Group"]}),!H.isSystem&&s.jsxs(s.Fragment,{children:[s.jsxs(he,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs gap-1 text-muted-foreground hover:text-foreground",onClick:()=>se(H),children:[s.jsx(ge,{icon:a2,size:13}),"Edit"]}),s.jsxs(he,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs gap-1 text-muted-foreground hover:text-destructive",onClick:()=>I(H),children:[s.jsx(ge,{icon:wl,size:13}),"Delete"]})]})]})})]},H.id)})})]})})})}),s.jsx(zl,{open:g,onOpenChange:y,children:s.jsxs(qs,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[s.jsxs(Ks,{children:[s.jsx(Xs,{children:w==="add"?"Create Permission Group":`Edit Group: ${T}`}),s.jsx(Zs,{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(ze,{htmlFor:"group-name",children:"Group Name"}),s.jsx(Ie,{id:"group-name",placeholder:"e.g. Support Staff",value:T,onChange:H=>A(H.target.value)})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(ze,{htmlFor:"group-color",children:"Color Badge"}),s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(Id,{value:z,onChange:B}),s.jsx(Ie,{value:z,onChange:H=>B(H.target.value),placeholder:"#10B981",className:"w-28 font-mono text-sm uppercase"}),s.jsx("div",{className:"flex flex-wrap gap-1 ml-auto",children:PB.map(H=>s.jsx("button",{type:"button",className:"size-6 rounded-full border border-white/20 transition-transform hover:scale-110",style:{backgroundColor:H.hex},onClick:()=>B(H.hex),title:H.name},H.hex))})]})]})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(ze,{htmlFor:"group-desc",children:"Description"}),s.jsx(Ie,{id:"group-desc",placeholder:"Brief description of what members in this group can access...",value:O,onChange:H=>M(H.target.value)})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(ze,{htmlFor:"discord-role-id",children:"Discord Role ID (Optional Auto-Sync)"}),s.jsx(Ie,{id:"discord-role-id",placeholder:"e.g. 123456789012345678",value:K,onChange:H=>U(H.target.value)}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"If provided, Discord users with this Role ID will automatically inherit this group upon login."})]}),s.jsxs("div",{className:"pt-2",children:[s.jsx("h4",{className:"text-sm font-semibold mb-3",children:"Group Permission Matrix"}),s.jsx(IB,{permissions:q,onChange:ue})]})]}),s.jsxs(Pl,{className:"gap-2 sm:gap-0",children:[s.jsx(he,{variant:"outline",onClick:()=>y(!1),disabled:S,children:"Cancel"}),s.jsx(he,{onClick:L,disabled:S,className:"bg-primary",children:S?"Saving...":w==="add"?"Create Group":"Save Changes"})]})]})})]})}function BB({children:e}){const{isAuthenticated:n,loading:a}=Ut();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:e}):s.jsx(Qr,{to:"/login",replace:!0})}function UB(){const{complete:e,loading:n}=Pj(),a=Ln();return n?s.jsx("div",{className:"flex min-h-svh items-center justify-center bg-background text-sm text-muted-foreground",children:"Loading…"}):e?a.pathname==="/setup"?s.jsx(Qr,{to:"/login",replace:!0}):s.jsxs(ny,{children:[s.jsx(rn,{path:"/login",element:s.jsx(T$,{})}),s.jsxs(rn,{element:s.jsx(BB,{children:s.jsx(ND,{})}),children:[s.jsx(rn,{index:!0,element:s.jsx(Q$,{})}),s.jsx(rn,{path:"system",element:s.jsx(Kr,{permission:"overview",children:s.jsx(mB,{})})}),s.jsx(rn,{path:"settings",element:s.jsx(Kr,{permission:"settings.view",children:s.jsx(uB,{})})}),s.jsx(rn,{path:"configs",element:s.jsx(N$,{})}),s.jsx(rn,{path:"logs",element:s.jsx(Kr,{permission:"logs",children:s.jsx(wB,{})})}),s.jsx(rn,{path:"tickets",element:s.jsx(Kr,{permission:"transcripts",children:s.jsx(MB,{})})}),s.jsx(rn,{path:"transcripts",element:s.jsx(Kr,{permission:"transcripts",children:s.jsx(AB,{})})}),s.jsx(rn,{path:"users",element:s.jsx(Kr,{permission:"users.view",children:s.jsx(zB,{})})}),s.jsx(rn,{path:"groups",element:s.jsx(Kr,{permission:"users.view",children:s.jsx($B,{})})}),s.jsx(rn,{path:"addons",element:s.jsx(Kr,{permission:"settings.view",children:s.jsx(J$,{})})}),s.jsx(rn,{path:"addons/builder",element:s.jsx(Kr,{permission:"settings.update",children:s.jsx(eB,{})})})]}),s.jsx(rn,{path:"*",element:s.jsx(Qr,{to:"/",replace:!0})})]}):s.jsxs(ny,{children:[s.jsx(rn,{path:"/setup",element:s.jsx(V$,{})}),s.jsx(rn,{path:"*",element:s.jsx(Qr,{to:"/setup",replace:!0})})]})}function HB({...e}){return s.jsx(aI,{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"}},...e})}oB();E3.createRoot(document.getElementById("root")).render(s.jsx(f.StrictMode,{children:s.jsx(ZE,{children:s.jsx(tS,{children:s.jsx(M8,{children:s.jsx(ED,{children:s.jsxs(A8,{children:[s.jsx(UB,{}),s.jsx(HB,{})]})})})})})}));