@waiaas/daemon 2.3.0 → 2.4.0-rc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waiaas/daemon",
3
- "version": "2.3.0",
3
+ "version": "2.4.0-rc",
4
4
  "description": "WAIaaS daemon - self-hosted wallet service for AI agents",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -47,9 +47,9 @@
47
47
  "uuidv7": "^1.0.2",
48
48
  "viem": "^2.21.0",
49
49
  "zod": "^3.24.0",
50
- "@waiaas/adapter-evm": "2.3.0",
51
- "@waiaas/core": "2.3.0",
52
- "@waiaas/adapter-solana": "2.3.0"
50
+ "@waiaas/adapter-evm": "2.4.0-rc",
51
+ "@waiaas/adapter-solana": "2.4.0-rc",
52
+ "@waiaas/core": "2.4.0-rc"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/better-sqlite3": "^7.6.0",
@@ -1,3 +1,3 @@
1
- var ut,K,ya,ga,ye,Gt,ba,wa,Sa,$t,Lt,Ot,Be={},ka=[],Ya=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,vt=Array.isArray;function de(a,t){for(var n in t)a[n]=t[n];return a}function Kt(a){a&&a.parentNode&&a.parentNode.removeChild(a)}function Ja(a,t,n){var l,i,s,r={};for(s in t)s=="key"?l=t[s]:s=="ref"?i=t[s]:r[s]=t[s];if(arguments.length>2&&(r.children=arguments.length>3?ut.call(arguments,2):n),typeof a=="function"&&a.defaultProps!=null)for(s in a.defaultProps)r[s]===void 0&&(r[s]=a.defaultProps[s]);return it(a,r,l,i,null)}function it(a,t,n,l,i){var s={type:a,props:t,key:n,ref:l,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i??++ya,__i:-1,__u:0};return i==null&&K.vnode!=null&&K.vnode(s),s}function z(a){return a.children}function Ue(a,t){this.props=a,this.context=t}function Ie(a,t){if(t==null)return a.__?Ie(a.__,a.__i+1):null;for(var n;t<a.__k.length;t++)if((n=a.__k[t])!=null&&n.__e!=null)return n.__e;return typeof a.type=="function"?Ie(a):null}function Na(a){var t,n;if((a=a.__)!=null&&a.__c!=null){for(a.__e=a.__c.base=null,t=0;t<a.__k.length;t++)if((n=a.__k[t])!=null&&n.__e!=null){a.__e=a.__c.base=n.__e;break}return Na(a)}}function jt(a){(!a.__d&&(a.__d=!0)&&ye.push(a)&&!ot.__r++||Gt!=K.debounceRendering)&&((Gt=K.debounceRendering)||ba)(ot)}function ot(){for(var a,t,n,l,i,s,r,c=1;ye.length;)ye.length>c&&ye.sort(wa),a=ye.shift(),c=ye.length,a.__d&&(n=void 0,l=void 0,i=(l=(t=a).__v).__e,s=[],r=[],t.__P&&((n=de({},l)).__v=l.__v+1,K.vnode&&K.vnode(n),Ft(t.__P,n,l,t.__n,t.__P.namespaceURI,32&l.__u?[i]:null,s,i??Ie(l),!!(32&l.__u),r),n.__v=l.__v,n.__.__k[n.__i]=n,Ea(s,n,r),l.__e=l.__=null,n.__e!=i&&Na(n)));ot.__r=0}function Ta(a,t,n,l,i,s,r,c,m,o,u){var d,f,p,b,T,S,D,L=l&&l.__k||ka,M=t.length;for(m=Xa(n,t,L,m,M),d=0;d<M;d++)(p=n.__k[d])!=null&&(f=p.__i==-1?Be:L[p.__i]||Be,p.__i=d,S=Ft(a,p,f,i,s,r,c,m,o,u),b=p.__e,p.ref&&f.ref!=p.ref&&(f.ref&&Bt(f.ref,null,p),u.push(p.ref,p.__c||b,p)),T==null&&b!=null&&(T=b),(D=!!(4&p.__u))||f.__k===p.__k?m=Ca(p,m,a,D):typeof p.type=="function"&&S!==void 0?m=S:b&&(m=b.nextSibling),p.__u&=-7);return n.__e=T,m}function Xa(a,t,n,l,i){var s,r,c,m,o,u=n.length,d=u,f=0;for(a.__k=new Array(i),s=0;s<i;s++)(r=t[s])!=null&&typeof r!="boolean"&&typeof r!="function"?(typeof r=="string"||typeof r=="number"||typeof r=="bigint"||r.constructor==String?r=a.__k[s]=it(null,r,null,null,null):vt(r)?r=a.__k[s]=it(z,{children:r},null,null,null):r.constructor===void 0&&r.__b>0?r=a.__k[s]=it(r.type,r.props,r.key,r.ref?r.ref:null,r.__v):a.__k[s]=r,m=s+f,r.__=a,r.__b=a.__b+1,c=null,(o=r.__i=Za(r,n,m,d))!=-1&&(d--,(c=n[o])&&(c.__u|=2)),c==null||c.__v==null?(o==-1&&(i>u?f--:i<u&&f++),typeof r.type!="function"&&(r.__u|=4)):o!=m&&(o==m-1?f--:o==m+1?f++:(o>m?f--:f++,r.__u|=4))):a.__k[s]=null;if(d)for(s=0;s<u;s++)(c=n[s])!=null&&(2&c.__u)==0&&(c.__e==l&&(l=Ie(c)),Ia(c,c));return l}function Ca(a,t,n,l){var i,s;if(typeof a.type=="function"){for(i=a.__k,s=0;i&&s<i.length;s++)i[s]&&(i[s].__=a,t=Ca(i[s],t,n,l));return t}a.__e!=t&&(l&&(t&&a.type&&!t.parentNode&&(t=Ie(a)),n.insertBefore(a.__e,t||null)),t=a.__e);do t=t&&t.nextSibling;while(t!=null&&t.nodeType==8);return t}function Za(a,t,n,l){var i,s,r,c=a.key,m=a.type,o=t[n],u=o!=null&&(2&o.__u)==0;if(o===null&&c==null||u&&c==o.key&&m==o.type)return n;if(l>(u?1:0)){for(i=n-1,s=n+1;i>=0||s<t.length;)if((o=t[r=i>=0?i--:s++])!=null&&(2&o.__u)==0&&c==o.key&&m==o.type)return r}return-1}function Yt(a,t,n){t[0]=="-"?a.setProperty(t,n??""):a[t]=n==null?"":typeof n!="number"||Ya.test(t)?n:n+"px"}function Ze(a,t,n,l,i){var s,r;e:if(t=="style")if(typeof n=="string")a.style.cssText=n;else{if(typeof l=="string"&&(a.style.cssText=l=""),l)for(t in l)n&&t in n||Yt(a.style,t,"");if(n)for(t in n)l&&n[t]==l[t]||Yt(a.style,t,n[t])}else if(t[0]=="o"&&t[1]=="n")s=t!=(t=t.replace(Sa,"$1")),r=t.toLowerCase(),t=r in a||t=="onFocusOut"||t=="onFocusIn"?r.slice(2):t.slice(2),a.l||(a.l={}),a.l[t+s]=n,n?l?n.u=l.u:(n.u=$t,a.addEventListener(t,s?Ot:Lt,s)):a.removeEventListener(t,s?Ot:Lt,s);else{if(i=="http://www.w3.org/2000/svg")t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(t!="width"&&t!="height"&&t!="href"&&t!="list"&&t!="form"&&t!="tabIndex"&&t!="download"&&t!="rowSpan"&&t!="colSpan"&&t!="role"&&t!="popover"&&t in a)try{a[t]=n??"";break e}catch{}typeof n=="function"||(n==null||n===!1&&t[4]!="-"?a.removeAttribute(t):a.setAttribute(t,t=="popover"&&n==1?"":n))}}function Jt(a){return function(t){if(this.l){var n=this.l[t.type+a];if(t.t==null)t.t=$t++;else if(t.t<n.u)return;return n(K.event?K.event(t):t)}}}function Ft(a,t,n,l,i,s,r,c,m,o){var u,d,f,p,b,T,S,D,L,M,F,k,x,R,j,q,X,G=t.type;if(t.constructor!==void 0)return null;128&n.__u&&(m=!!(32&n.__u),s=[c=t.__e=n.__e]),(u=K.__b)&&u(t);e:if(typeof G=="function")try{if(D=t.props,L="prototype"in G&&G.prototype.render,M=(u=G.contextType)&&l[u.__c],F=u?M?M.props.value:u.__:l,n.__c?S=(d=t.__c=n.__c).__=d.__E:(L?t.__c=d=new G(D,F):(t.__c=d=new Ue(D,F),d.constructor=G,d.render=en),M&&M.sub(d),d.state||(d.state={}),d.__n=l,f=d.__d=!0,d.__h=[],d._sb=[]),L&&d.__s==null&&(d.__s=d.state),L&&G.getDerivedStateFromProps!=null&&(d.__s==d.state&&(d.__s=de({},d.__s)),de(d.__s,G.getDerivedStateFromProps(D,d.__s))),p=d.props,b=d.state,d.__v=t,f)L&&G.getDerivedStateFromProps==null&&d.componentWillMount!=null&&d.componentWillMount(),L&&d.componentDidMount!=null&&d.__h.push(d.componentDidMount);else{if(L&&G.getDerivedStateFromProps==null&&D!==p&&d.componentWillReceiveProps!=null&&d.componentWillReceiveProps(D,F),t.__v==n.__v||!d.__e&&d.shouldComponentUpdate!=null&&d.shouldComponentUpdate(D,d.__s,F)===!1){for(t.__v!=n.__v&&(d.props=D,d.state=d.__s,d.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(h){h&&(h.__=t)}),k=0;k<d._sb.length;k++)d.__h.push(d._sb[k]);d._sb=[],d.__h.length&&r.push(d);break e}d.componentWillUpdate!=null&&d.componentWillUpdate(D,d.__s,F),L&&d.componentDidUpdate!=null&&d.__h.push(function(){d.componentDidUpdate(p,b,T)})}if(d.context=F,d.props=D,d.__P=a,d.__e=!1,x=K.__r,R=0,L){for(d.state=d.__s,d.__d=!1,x&&x(t),u=d.render(d.props,d.state,d.context),j=0;j<d._sb.length;j++)d.__h.push(d._sb[j]);d._sb=[]}else do d.__d=!1,x&&x(t),u=d.render(d.props,d.state,d.context),d.state=d.__s;while(d.__d&&++R<25);d.state=d.__s,d.getChildContext!=null&&(l=de(de({},l),d.getChildContext())),L&&!f&&d.getSnapshotBeforeUpdate!=null&&(T=d.getSnapshotBeforeUpdate(p,b)),q=u,u!=null&&u.type===z&&u.key==null&&(q=Aa(u.props.children)),c=Ta(a,vt(q)?q:[q],t,n,l,i,s,r,c,m,o),d.base=t.__e,t.__u&=-161,d.__h.length&&r.push(d),S&&(d.__E=d.__=null)}catch(h){if(t.__v=null,m||s!=null)if(h.then){for(t.__u|=m?160:128;c&&c.nodeType==8&&c.nextSibling;)c=c.nextSibling;s[s.indexOf(c)]=null,t.__e=c}else{for(X=s.length;X--;)Kt(s[X]);xt(t)}else t.__e=n.__e,t.__k=n.__k,h.then||xt(t);K.__e(h,t,n)}else s==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):c=t.__e=Qa(n.__e,t,n,l,i,s,r,m,o);return(u=K.diffed)&&u(t),128&t.__u?void 0:c}function xt(a){a&&a.__c&&(a.__c.__e=!0),a&&a.__k&&a.__k.forEach(xt)}function Ea(a,t,n){for(var l=0;l<n.length;l++)Bt(n[l],n[++l],n[++l]);K.__c&&K.__c(t,a),a.some(function(i){try{a=i.__h,i.__h=[],a.some(function(s){s.call(i)})}catch(s){K.__e(s,i.__v)}})}function Aa(a){return typeof a!="object"||a==null||a.__b&&a.__b>0?a:vt(a)?a.map(Aa):de({},a)}function Qa(a,t,n,l,i,s,r,c,m){var o,u,d,f,p,b,T,S=n.props||Be,D=t.props,L=t.type;if(L=="svg"?i="http://www.w3.org/2000/svg":L=="math"?i="http://www.w3.org/1998/Math/MathML":i||(i="http://www.w3.org/1999/xhtml"),s!=null){for(o=0;o<s.length;o++)if((p=s[o])&&"setAttribute"in p==!!L&&(L?p.localName==L:p.nodeType==3)){a=p,s[o]=null;break}}if(a==null){if(L==null)return document.createTextNode(D);a=document.createElementNS(i,L,D.is&&D),c&&(K.__m&&K.__m(t,s),c=!1),s=null}if(L==null)S===D||c&&a.data==D||(a.data=D);else{if(s=s&&ut.call(a.childNodes),!c&&s!=null)for(S={},o=0;o<a.attributes.length;o++)S[(p=a.attributes[o]).name]=p.value;for(o in S)if(p=S[o],o!="children"){if(o=="dangerouslySetInnerHTML")d=p;else if(!(o in D)){if(o=="value"&&"defaultValue"in D||o=="checked"&&"defaultChecked"in D)continue;Ze(a,o,null,p,i)}}for(o in D)p=D[o],o=="children"?f=p:o=="dangerouslySetInnerHTML"?u=p:o=="value"?b=p:o=="checked"?T=p:c&&typeof p!="function"||S[o]===p||Ze(a,o,p,S[o],i);if(u)c||d&&(u.__html==d.__html||u.__html==a.innerHTML)||(a.innerHTML=u.__html),t.__k=[];else if(d&&(a.innerHTML=""),Ta(t.type=="template"?a.content:a,vt(f)?f:[f],t,n,l,L=="foreignObject"?"http://www.w3.org/1999/xhtml":i,s,r,s?s[0]:n.__k&&Ie(n,0),c,m),s!=null)for(o=s.length;o--;)Kt(s[o]);c||(o="value",L=="progress"&&b==null?a.removeAttribute("value"):b!=null&&(b!==a[o]||L=="progress"&&!b||L=="option"&&b!=S[o])&&Ze(a,o,b,S[o],i),o="checked",T!=null&&T!=a[o]&&Ze(a,o,T,S[o],i))}return a}function Bt(a,t,n){try{if(typeof a=="function"){var l=typeof a.__u=="function";l&&a.__u(),l&&t==null||(a.__u=a(t))}else a.current=t}catch(i){K.__e(i,n)}}function Ia(a,t,n){var l,i;if(K.unmount&&K.unmount(a),(l=a.ref)&&(l.current&&l.current!=a.__e||Bt(l,null,t)),(l=a.__c)!=null){if(l.componentWillUnmount)try{l.componentWillUnmount()}catch(s){K.__e(s,t)}l.base=l.__P=null}if(l=a.__k)for(i=0;i<l.length;i++)l[i]&&Ia(l[i],t,n||typeof a.type!="function");n||Kt(a.__e),a.__c=a.__=a.__e=void 0}function en(a,t,n){return this.constructor(a,n)}function tn(a,t,n){var l,i,s,r;t==document&&(t=document.documentElement),K.__&&K.__(a,t),i=(l=!1)?null:t.__k,s=[],r=[],Ft(t,a=t.__k=Ja(z,null,[a]),i||Be,Be,t.namespaceURI,i?null:t.firstChild?ut.call(t.childNodes):null,s,i?i.__e:t.firstChild,l,r),Ea(s,a,r)}ut=ka.slice,K={__e:function(a,t,n,l){for(var i,s,r;t=t.__;)if((i=t.__c)&&!i.__)try{if((s=i.constructor)&&s.getDerivedStateFromError!=null&&(i.setState(s.getDerivedStateFromError(a)),r=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(a,l||{}),r=i.__d),r)return i.__E=i}catch(c){a=c}throw a}},ya=0,ga=function(a){return a!=null&&a.constructor===void 0},Ue.prototype.setState=function(a,t){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=de({},this.state),typeof a=="function"&&(a=a(de({},n),this.props)),a&&de(n,a),a!=null&&this.__v&&(t&&this._sb.push(t),jt(this))},Ue.prototype.forceUpdate=function(a){this.__v&&(this.__e=!0,a&&this.__h.push(a),jt(this))},Ue.prototype.render=z,ye=[],ba=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,wa=function(a,t){return a.__v.__b-t.__v.__b},ot.__r=0,Sa=/(PointerCapture)$|Capture$/i,$t=0,Lt=Jt(!1),Ot=Jt(!0);var an=0;function e(a,t,n,l,i,s){t||(t={});var r,c,m=t;if("ref"in m)for(c in m={},t)c=="ref"?r=t[c]:m[c]=t[c];var o={type:a,props:m,key:n,ref:r,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--an,__i:-1,__u:0,__source:i,__self:s};if(typeof a=="function"&&(r=a.defaultProps))for(c in r)m[c]===void 0&&(m[c]=r[c]);return K.vnode&&K.vnode(o),o}var rt,ne,Nt,Xt,Rt=0,Da=[],Y=K,Zt=Y.__b,Qt=Y.__r,ea=Y.diffed,ta=Y.__c,aa=Y.unmount,na=Y.__;function La(a,t){Y.__h&&Y.__h(ne,a,Rt||t),Rt=0;var n=ne.__H||(ne.__H={__:[],__h:[]});return a>=n.__.length&&n.__.push({}),n.__[a]}function O(a,t){var n=La(rt++,3);!Y.__s&&Oa(n.__H,t)&&(n.__=a,n.u=t,ne.__H.__h.push(n))}function Ht(a){return Rt=5,ht(function(){return{current:a}},[])}function ht(a,t){var n=La(rt++,7);return Oa(n.__H,t)&&(n.__=a(),n.__H=t,n.__h=a),n.__}function nn(){for(var a;a=Da.shift();)if(a.__P&&a.__H)try{a.__H.__h.forEach(st),a.__H.__h.forEach(Pt),a.__H.__h=[]}catch(t){a.__H.__h=[],Y.__e(t,a.__v)}}Y.__b=function(a){ne=null,Zt&&Zt(a)},Y.__=function(a,t){a&&t.__k&&t.__k.__m&&(a.__m=t.__k.__m),na&&na(a,t)},Y.__r=function(a){Qt&&Qt(a),rt=0;var t=(ne=a.__c).__H;t&&(Nt===ne?(t.__h=[],ne.__h=[],t.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.forEach(st),t.__h.forEach(Pt),t.__h=[],rt=0)),Nt=ne},Y.diffed=function(a){ea&&ea(a);var t=a.__c;t&&t.__H&&(t.__H.__h.length&&(Da.push(t)!==1&&Xt===Y.requestAnimationFrame||((Xt=Y.requestAnimationFrame)||ln)(nn)),t.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),Nt=ne=null},Y.__c=function(a,t){t.some(function(n){try{n.__h.forEach(st),n.__h=n.__h.filter(function(l){return!l.__||Pt(l)})}catch(l){t.some(function(i){i.__h&&(i.__h=[])}),t=[],Y.__e(l,n.__v)}}),ta&&ta(a,t)},Y.unmount=function(a){aa&&aa(a);var t,n=a.__c;n&&n.__H&&(n.__H.__.forEach(function(l){try{st(l)}catch(i){t=i}}),n.__H=void 0,t&&Y.__e(t,n.__v))};var la=typeof requestAnimationFrame=="function";function ln(a){var t,n=function(){clearTimeout(l),la&&cancelAnimationFrame(t),setTimeout(a)},l=setTimeout(n,35);la&&(t=requestAnimationFrame(n))}function st(a){var t=ne,n=a.__c;typeof n=="function"&&(a.__c=void 0,n()),ne=t}function Pt(a){var t=ne;a.__c=a.__(),ne=t}function Oa(a,t){return!a||a.length!==t.length||t.some(function(n,l){return n!==a[l]})}var sn=Symbol.for("preact-signals");function mt(){if(me>1)me--;else{for(var a,t=!1;$e!==void 0;){var n=$e;for($e=void 0,Wt++;n!==void 0;){var l=n.o;if(n.o=void 0,n.f&=-3,!(8&n.f)&&Pa(n))try{n.c()}catch(i){t||(a=i,t=!0)}n=l}}if(Wt=0,me--,t)throw a}}function on(a){if(me>0)return a();me++;try{return a()}finally{mt()}}var $=void 0;function xa(a){var t=$;$=void 0;try{return a()}finally{$=t}}var $e=void 0,me=0,Wt=0,ct=0;function Ra(a){if($!==void 0){var t=a.n;if(t===void 0||t.t!==$)return t={i:0,S:a,p:$.s,n:void 0,t:$,e:void 0,x:void 0,r:t},$.s!==void 0&&($.s.n=t),$.s=t,a.n=t,32&$.f&&a.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=$.s,t.n=void 0,$.s.n=t,$.s=t),t}}function ee(a,t){this.v=a,this.i=0,this.n=void 0,this.t=void 0,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}ee.prototype.brand=sn;ee.prototype.h=function(){return!0};ee.prototype.S=function(a){var t=this,n=this.t;n!==a&&a.e===void 0&&(a.x=n,this.t=a,n!==void 0?n.e=a:xa(function(){var l;(l=t.W)==null||l.call(t)}))};ee.prototype.U=function(a){var t=this;if(this.t!==void 0){var n=a.e,l=a.x;n!==void 0&&(n.x=l,a.e=void 0),l!==void 0&&(l.e=n,a.x=void 0),a===this.t&&(this.t=l,l===void 0&&xa(function(){var i;(i=t.Z)==null||i.call(t)}))}};ee.prototype.subscribe=function(a){var t=this;return ze(function(){var n=t.value,l=$;$=void 0;try{a(n)}finally{$=l}},{name:"sub"})};ee.prototype.valueOf=function(){return this.value};ee.prototype.toString=function(){return this.value+""};ee.prototype.toJSON=function(){return this.value};ee.prototype.peek=function(){var a=$;$=void 0;try{return this.value}finally{$=a}};Object.defineProperty(ee.prototype,"value",{get:function(){var a=Ra(this);return a!==void 0&&(a.i=this.i),this.v},set:function(a){if(a!==this.v){if(Wt>100)throw new Error("Cycle detected");this.v=a,this.i++,ct++,me++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{mt()}}}});function te(a,t){return new ee(a,t)}function Pa(a){for(var t=a.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function Wa(a){for(var t=a.s;t!==void 0;t=t.n){var n=t.S.n;if(n!==void 0&&(t.r=n),t.S.n=t,t.i=-1,t.n===void 0){a.s=t;break}}}function Ma(a){for(var t=a.s,n=void 0;t!==void 0;){var l=t.p;t.i===-1?(t.S.U(t),l!==void 0&&(l.n=t.n),t.n!==void 0&&(t.n.p=l)):n=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=l}a.s=n}function be(a,t){ee.call(this,void 0),this.x=a,this.s=void 0,this.g=ct-1,this.f=4,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}be.prototype=new ee;be.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===ct))return!0;if(this.g=ct,this.f|=1,this.i>0&&!Pa(this))return this.f&=-2,!0;var a=$;try{Wa(this),$=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(n){this.v=n,this.f|=16,this.i++}return $=a,Ma(this),this.f&=-2,!0};be.prototype.S=function(a){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}ee.prototype.S.call(this,a)};be.prototype.U=function(a){if(this.t!==void 0&&(ee.prototype.U.call(this,a),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}};be.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var a=this.t;a!==void 0;a=a.x)a.t.N()}};Object.defineProperty(be.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var a=Ra(this);if(this.h(),a!==void 0&&(a.i=this.i),16&this.f)throw this.v;return this.v}});function He(a,t){return new be(a,t)}function Ua(a){var t=a.u;if(a.u=void 0,typeof t=="function"){me++;var n=$;$=void 0;try{t()}catch(l){throw a.f&=-2,a.f|=8,Vt(a),l}finally{$=n,mt()}}}function Vt(a){for(var t=a.s;t!==void 0;t=t.n)t.S.U(t);a.x=void 0,a.s=void 0,Ua(a)}function rn(a){if($!==this)throw new Error("Out-of-order effect");Ma(this),$=a,this.f&=-2,8&this.f&&Vt(this),mt()}function xe(a,t){this.x=a,this.u=void 0,this.s=void 0,this.o=void 0,this.f=32,this.name=t?.name}xe.prototype.c=function(){var a=this.S();try{if(8&this.f||this.x===void 0)return;var t=this.x();typeof t=="function"&&(this.u=t)}finally{a()}};xe.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Ua(this),Wa(this),me++;var a=$;return $=this,rn.bind(this,a)};xe.prototype.N=function(){2&this.f||(this.f|=2,this.o=$e,$e=this)};xe.prototype.d=function(){this.f|=8,1&this.f||Vt(this)};xe.prototype.dispose=function(){this.d()};function ze(a,t){var n=new xe(a,t);try{n.c()}catch(i){throw n.d(),i}var l=n.d.bind(n);return l[Symbol.dispose]=l,l}var $a,pt,Qe,cn=typeof window<"u"&&!!window.__PREACT_SIGNALS_DEVTOOLS__,Ka=[];ze(function(){$a=this.N})();function Re(a,t){K[a]=t.bind(null,K[a]||function(){})}function dt(a){if(Qe){var t=Qe;Qe=void 0,t()}Qe=a&&a.S()}function Fa(a){var t=this,n=a.data,l=v(n);l.value=n;var i=ht(function(){for(var c=t,m=t.__v;m=m.__;)if(m.__c){m.__c.__$f|=4;break}var o=He(function(){var p=l.value.value;return p===0?0:p===!0?"":p||""}),u=He(function(){return!Array.isArray(o.value)&&!ga(o.value)}),d=ze(function(){if(this.N=Ba,u.value){var p=o.value;c.__v&&c.__v.__e&&c.__v.__e.nodeType===3&&(c.__v.__e.data=p)}}),f=t.__$u.d;return t.__$u.d=function(){d(),f.call(this)},[u,o]},[]),s=i[0],r=i[1];return s.value?r.peek():r.value}Fa.displayName="ReactiveTextNode";Object.defineProperties(ee.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:Fa},props:{configurable:!0,get:function(){return{data:this}}},__b:{configurable:!0,value:1}});Re("__b",function(a,t){if(typeof t.type=="string"){var n,l=t.props;for(var i in l)if(i!=="children"){var s=l[i];s instanceof ee&&(n||(t.__np=n={}),n[i]=s,l[i]=s.peek())}}a(t)});Re("__r",function(a,t){if(a(t),t.type!==z){dt();var n,l=t.__c;l&&(l.__$f&=-2,(n=l.__$u)===void 0&&(l.__$u=n=(function(i,s){var r;return ze(function(){r=this},{name:s}),r.c=i,r})(function(){var i;cn&&((i=n.y)==null||i.call(n)),l.__$f|=1,l.setState({})},typeof t.type=="function"?t.type.displayName||t.type.name:""))),pt=l,dt(n)}});Re("__e",function(a,t,n,l){dt(),pt=void 0,a(t,n,l)});Re("diffed",function(a,t){dt(),pt=void 0;var n;if(typeof t.type=="string"&&(n=t.__e)){var l=t.__np,i=t.props;if(l){var s=n.U;if(s)for(var r in s){var c=s[r];c!==void 0&&!(r in l)&&(c.d(),s[r]=void 0)}else s={},n.U=s;for(var m in l){var o=s[m],u=l[m];o===void 0?(o=dn(n,m,u,i),s[m]=o):o.o(u,i)}}}a(t)});function dn(a,t,n,l){var i=t in a&&a.ownerSVGElement===void 0,s=te(n);return{o:function(r,c){s.value=r,l=c},d:ze(function(){this.N=Ba;var r=s.value.value;l[t]!==r&&(l[t]=r,i?a[t]=r:r!=null&&(r!==!1||t[4]==="-")?a.setAttribute(t,r):a.removeAttribute(t))})}}Re("unmount",function(a,t){if(typeof t.type=="string"){var n=t.__e;if(n){var l=n.U;if(l){n.U=void 0;for(var i in l){var s=l[i];s&&s.d()}}}}else{var r=t.__c;if(r){var c=r.__$u;c&&(r.__$u=void 0,c.d())}}a(t)});Re("__h",function(a,t,n,l){(l<3||l===9)&&(t.__$f|=2),a(t,n,l)});Ue.prototype.shouldComponentUpdate=function(a,t){if(this.__R)return!0;var n=this.__$u,l=n&&n.s!==void 0;for(var i in t)return!0;if(this.__f||typeof this.u=="boolean"&&this.u===!0){var s=2&this.__$f;if(!(l||s||4&this.__$f)||1&this.__$f)return!0}else if(!(l||4&this.__$f)||3&this.__$f)return!0;for(var r in a)if(r!=="__source"&&a[r]!==this.props[r])return!0;for(var c in this.props)if(!(c in a))return!0;return!1};function v(a,t){return ht(function(){return te(a,t)},[])}function un(a,t){var n=Ht(a);return n.current=a,pt.__$f|=4,ht(function(){return He(function(){return n.current()},t)},[])}var vn=function(a){queueMicrotask(function(){queueMicrotask(a)})};function hn(){on(function(){for(var a;a=Ka.shift();)$a.call(a)})}function Ba(){Ka.push(this)===1&&(K.requestAnimationFrame||vn)(hn)}const Ve=te(null),mn=He(()=>Ve.value!==null),Ha=te(900),pn=te(!1);let Ce=null;const Ee=()=>{zt()};function fn(){document.addEventListener("mousemove",Ee,{passive:!0}),document.addEventListener("keydown",Ee,{passive:!0}),document.addEventListener("click",Ee,{passive:!0}),zt()}function _n(){document.removeEventListener("mousemove",Ee),document.removeEventListener("keydown",Ee),document.removeEventListener("click",Ee),Ce!==null&&(clearTimeout(Ce),Ce=null)}function zt(){Ce!==null&&clearTimeout(Ce),Ce=setTimeout(()=>{qt()},Ha.value*1e3)}function yn(a,t){Ve.value=a,t!==void 0&&(Ha.value=t),fn(),location.hash="#/dashboard"}function qt(){Ve.value=null,_n(),location.hash="#/login"}const C={ADMIN_STATUS:"/v1/admin/status",ADMIN_KILL_SWITCH:"/v1/admin/kill-switch",ADMIN_KILL_SWITCH_ESCALATE:"/v1/admin/kill-switch/escalate",ADMIN_RECOVER:"/v1/admin/recover",ADMIN_SHUTDOWN:"/v1/admin/shutdown",ADMIN_ROTATE_SECRET:"/v1/admin/rotate-secret",WALLETS:"/v1/wallets",WALLET:a=>`/v1/wallets/${a}`,SESSIONS:"/v1/sessions",SESSION:a=>`/v1/sessions/${a}`,POLICIES:"/v1/policies",POLICY:a=>`/v1/policies/${a}`,ADMIN_NOTIFICATIONS_STATUS:"/v1/admin/notifications/status",ADMIN_NOTIFICATIONS_TEST:"/v1/admin/notifications/test",ADMIN_NOTIFICATIONS_LOG:"/v1/admin/notifications/log",MCP_TOKENS:"/v1/mcp/tokens",ADMIN_SETTINGS:"/v1/admin/settings",ADMIN_SETTINGS_TEST_RPC:"/v1/admin/settings/test-rpc",WALLET_NETWORKS:a=>`/v1/wallets/${a}/networks`,WALLET_DEFAULT_NETWORK:a=>`/v1/wallets/${a}/default-network`,ADMIN_WALLET_BALANCE:a=>`/v1/admin/wallets/${a}/balance`,ADMIN_WALLET_TRANSACTIONS:a=>`/v1/admin/wallets/${a}/transactions`,ADMIN_API_KEYS:"/v1/admin/api-keys",ADMIN_API_KEY:a=>`/v1/admin/api-keys/${a}`,ADMIN_FOREX_RATES:"/v1/admin/forex/rates",ADMIN_TELEGRAM_USERS:"/v1/admin/telegram-users",ADMIN_TELEGRAM_USER:a=>`/v1/admin/telegram-users/${a}`,WALLET_OWNER:a=>`/v1/wallets/${a}/owner`,WALLET_WITHDRAW:a=>`/v1/wallets/${a}/withdraw`,WALLET_WC_PAIR:a=>`/v1/wallets/${a}/wc/pair`,WALLET_WC_SESSION:a=>`/v1/wallets/${a}/wc/session`,WALLET_WC_PAIR_STATUS:a=>`/v1/wallets/${a}/wc/pair/status`,WALLET_OWNER_VERIFY:a=>`/v1/wallets/${a}/owner/verify`,ADMIN_BULK_SESSIONS:"/v1/admin/sessions/bulk",ADMIN_BULK_MCP_TOKENS:"/v1/admin/mcp/tokens/bulk"},Ke=te(""),Te=te(null),Fe=te(!1),ue={wrapper:{display:"flex",alignItems:"center",justifyContent:"center",minHeight:"100vh",background:"var(--color-bg-secondary)"},card:{background:"var(--color-bg)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-lg)",padding:"var(--space-8)",width:"100%",maxWidth:"360px",boxShadow:"var(--shadow-md)"},title:{fontSize:"var(--font-size-2xl)",fontWeight:"var(--font-weight-bold)",textAlign:"center",marginBottom:"var(--space-1)"},subtitle:{fontSize:"var(--font-size-sm)",color:"var(--color-text-secondary)",textAlign:"center",marginBottom:"var(--space-6)"},input:{width:"100%",padding:"var(--space-2) var(--space-3)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",fontSize:"var(--font-size-base)",outline:"none"},button:{width:"100%",padding:"var(--space-2) var(--space-4)",background:"var(--color-primary)",color:"white",border:"none",borderRadius:"var(--radius-md)",fontSize:"var(--font-size-base)",fontWeight:"var(--font-weight-medium)",marginTop:"var(--space-4)"},buttonDisabled:{opacity:.6,cursor:"not-allowed"},error:{color:"var(--color-danger)",fontSize:"var(--font-size-sm)",textAlign:"center",marginTop:"var(--space-3)"}},gn=async a=>{if(a.preventDefault(),!!Ke.value.trim()){Fe.value=!0,Te.value=null;try{const t=await fetch(C.ADMIN_STATUS,{headers:{"X-Master-Password":Ke.value},signal:AbortSignal.timeout(1e4)});if(t.status===401){Te.value="Invalid master password";return}if(!t.ok){Te.value="Cannot connect to daemon";return}const n=await t.json();yn(Ke.value,n.adminTimeout)}catch{Te.value="Cannot connect to daemon"}finally{Fe.value=!1}}};function bn(){return e("div",{style:ue.wrapper,children:e("form",{style:ue.card,onSubmit:gn,children:[e("h1",{style:ue.title,children:"WAIaaS Admin"}),e("p",{style:ue.subtitle,children:"Enter master password to continue"}),e("input",{type:"password",placeholder:"Master password",autoFocus:!0,value:Ke.value,onInput:a=>{Ke.value=a.target.value},style:ue.input}),e("button",{type:"submit",disabled:Fe.value,style:{...ue.button,...Fe.value?ue.buttonDisabled:{}},children:Fe.value?"Signing in...":"Sign in"}),Te.value&&e("p",{style:ue.error,children:Te.value})]})})}const wn=[{id:"wallets.rpc.solana_mainnet",label:"Solana Mainnet",description:"RPC endpoint URL for Solana mainnet",page:"/wallets",tab:"rpc",fieldName:"rpc.solana_mainnet",keywords:["blockchain","rpc","solana","url","endpoint"]},{id:"wallets.rpc.solana_devnet",label:"Solana Devnet",description:"RPC endpoint URL for Solana devnet",page:"/wallets",tab:"rpc",fieldName:"rpc.solana_devnet",keywords:["blockchain","rpc","solana","url","endpoint","test"]},{id:"wallets.rpc.solana_testnet",label:"Solana Testnet",description:"RPC endpoint URL for Solana testnet",page:"/wallets",tab:"rpc",fieldName:"rpc.solana_testnet",keywords:["blockchain","rpc","solana","url","endpoint","test"]},{id:"wallets.rpc.evm_ethereum_mainnet",label:"Ethereum Mainnet",description:"RPC endpoint URL for Ethereum mainnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_ethereum_mainnet",keywords:["blockchain","rpc","evm","ethereum","url","endpoint"]},{id:"wallets.rpc.evm_ethereum_sepolia",label:"Ethereum Sepolia",description:"RPC endpoint URL for Ethereum Sepolia testnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_ethereum_sepolia",keywords:["blockchain","rpc","evm","ethereum","url","endpoint","test"]},{id:"wallets.rpc.evm_polygon_mainnet",label:"Polygon Mainnet",description:"RPC endpoint URL for Polygon mainnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_polygon_mainnet",keywords:["blockchain","rpc","evm","polygon","matic","url","endpoint"]},{id:"wallets.rpc.evm_polygon_amoy",label:"Polygon Amoy",description:"RPC endpoint URL for Polygon Amoy testnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_polygon_amoy",keywords:["blockchain","rpc","evm","polygon","url","endpoint","test"]},{id:"wallets.rpc.evm_arbitrum_mainnet",label:"Arbitrum Mainnet",description:"RPC endpoint URL for Arbitrum mainnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_arbitrum_mainnet",keywords:["blockchain","rpc","evm","arbitrum","l2","url","endpoint"]},{id:"wallets.rpc.evm_arbitrum_sepolia",label:"Arbitrum Sepolia",description:"RPC endpoint URL for Arbitrum Sepolia testnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_arbitrum_sepolia",keywords:["blockchain","rpc","evm","arbitrum","l2","url","endpoint","test"]},{id:"wallets.rpc.evm_optimism_mainnet",label:"Optimism Mainnet",description:"RPC endpoint URL for Optimism mainnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_optimism_mainnet",keywords:["blockchain","rpc","evm","optimism","l2","url","endpoint"]},{id:"wallets.rpc.evm_optimism_sepolia",label:"Optimism Sepolia",description:"RPC endpoint URL for Optimism Sepolia testnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_optimism_sepolia",keywords:["blockchain","rpc","evm","optimism","l2","url","endpoint","test"]},{id:"wallets.rpc.evm_base_mainnet",label:"Base Mainnet",description:"RPC endpoint URL for Base mainnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_base_mainnet",keywords:["blockchain","rpc","evm","base","coinbase","l2","url","endpoint"]},{id:"wallets.rpc.evm_base_sepolia",label:"Base Sepolia",description:"RPC endpoint URL for Base Sepolia testnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_base_sepolia",keywords:["blockchain","rpc","evm","base","coinbase","l2","url","endpoint","test"]},{id:"wallets.rpc.evm_default_network",label:"Default EVM Network",description:"Default EVM network for new wallets",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_default_network",keywords:["blockchain","evm","default","network"]},{id:"wallets.monitoring.enabled",label:"Enabled",description:"Enable or disable balance monitoring",page:"/wallets",tab:"monitoring",fieldName:"monitoring.enabled",keywords:["balance","monitoring","toggle","enable"]},{id:"wallets.monitoring.check_interval_sec",label:"Check Interval (seconds)",description:"How often to check wallet balances",page:"/wallets",tab:"monitoring",fieldName:"monitoring.check_interval_sec",keywords:["balance","monitoring","interval","frequency"]},{id:"wallets.monitoring.low_balance_threshold_sol",label:"Low Balance Threshold (SOL)",description:"Alert when SOL balance drops below this amount",page:"/wallets",tab:"monitoring",fieldName:"monitoring.low_balance_threshold_sol",keywords:["balance","monitoring","threshold","solana","alert","low"]},{id:"wallets.monitoring.low_balance_threshold_eth",label:"Low Balance Threshold (ETH)",description:"Alert when ETH balance drops below this amount",page:"/wallets",tab:"monitoring",fieldName:"monitoring.low_balance_threshold_eth",keywords:["balance","monitoring","threshold","ethereum","alert","low"]},{id:"wallets.monitoring.cooldown_hours",label:"Alert Cooldown (hours)",description:"Suppress duplicate alerts for this many hours",page:"/wallets",tab:"monitoring",fieldName:"monitoring.cooldown_hours",keywords:["balance","monitoring","cooldown","alert","suppress"]},{id:"wallets.walletconnect.project_id",label:"Project ID",description:"WalletConnect Cloud project identifier",page:"/wallets",tab:"walletconnect",fieldName:"walletconnect.project_id",keywords:["walletconnect","project","cloud","dapp"]},{id:"wallets.walletconnect.relay_url",label:"Relay URL",description:"WalletConnect relay server URL",page:"/wallets",tab:"walletconnect",fieldName:"walletconnect.relay_url",keywords:["walletconnect","relay","websocket","server"]},{id:"sessions.settings.session_ttl",label:"Session TTL (seconds)",description:"How long a session token is valid before renewal",page:"/sessions",tab:"settings",fieldName:"security.session_ttl",keywords:["session","ttl","lifetime","expiry","timeout"]},{id:"sessions.settings.session_absolute_lifetime",label:"Absolute Lifetime (seconds)",description:"Maximum total session duration regardless of renewals",page:"/sessions",tab:"settings",fieldName:"security.session_absolute_lifetime",keywords:["session","lifetime","absolute","maximum"]},{id:"sessions.settings.session_max_renewals",label:"Max Renewals",description:"Maximum number of times a session can be renewed",page:"/sessions",tab:"settings",fieldName:"security.session_max_renewals",keywords:["session","renewal","limit","maximum"]},{id:"sessions.settings.max_sessions_per_wallet",label:"Max Sessions per Wallet",description:"Maximum concurrent sessions for a single wallet",page:"/sessions",tab:"settings",fieldName:"security.max_sessions_per_wallet",keywords:["session","limit","concurrent","wallet"]},{id:"sessions.settings.max_pending_tx",label:"Max Pending Transactions",description:"Maximum in-flight transactions per session",page:"/sessions",tab:"settings",fieldName:"security.max_pending_tx",keywords:["transaction","pending","limit","queue"]},{id:"sessions.settings.rate_limit_session_rpm",label:"Session Rate Limit (RPM)",description:"Max requests per minute per session",page:"/sessions",tab:"settings",fieldName:"security.rate_limit_session_rpm",keywords:["rate","limit","rpm","session","throttle"]},{id:"sessions.settings.rate_limit_tx_rpm",label:"Transaction Rate Limit (RPM)",description:"Max transaction requests per minute per session",page:"/sessions",tab:"settings",fieldName:"security.rate_limit_tx_rpm",keywords:["rate","limit","rpm","transaction","throttle"]},{id:"policies.defaults.policy_defaults_delay_seconds",label:"Policy Delay (seconds)",description:"Default delay before executing delayed-tier transactions",page:"/policies",tab:"defaults",fieldName:"security.policy_defaults_delay_seconds",keywords:["policy","delay","default","seconds","timer"]},{id:"policies.defaults.policy_defaults_approval_timeout",label:"Approval Timeout (seconds)",description:"How long to wait for owner approval before timeout",page:"/policies",tab:"defaults",fieldName:"security.policy_defaults_approval_timeout",keywords:["policy","approval","timeout","owner","default"]},{id:"policies.defaults.default_deny_tokens",label:"Default Deny: Token Transfers",description:"Deny token transfers unless a matching whitelist policy exists",page:"/policies",tab:"defaults",fieldName:"policy.default_deny_tokens",keywords:["policy","deny","token","transfer","default","security"]},{id:"policies.defaults.default_deny_contracts",label:"Default Deny: Contract Calls",description:"Deny contract calls unless a matching whitelist policy exists",page:"/policies",tab:"defaults",fieldName:"policy.default_deny_contracts",keywords:["policy","deny","contract","call","default","security"]},{id:"policies.defaults.default_deny_spenders",label:"Default Deny: Token Approvals",description:"Deny token approvals unless a matching whitelist policy exists",page:"/policies",tab:"defaults",fieldName:"policy.default_deny_spenders",keywords:["policy","deny","spender","approval","default","security"]},{id:"notifications.settings.enabled",label:"Enabled",description:"Enable or disable notifications globally",page:"/notifications",tab:"settings",fieldName:"notifications.enabled",keywords:["notifications","enable","toggle","global"]},{id:"notifications.settings.telegram_bot_token",label:"Telegram Bot Token",description:"Bot token for Telegram notifications",page:"/notifications",tab:"settings",fieldName:"notifications.telegram_bot_token",keywords:["telegram","bot","token","notification","credential"]},{id:"notifications.settings.telegram_chat_id",label:"Telegram Chat ID",description:"Chat ID for Telegram notification delivery",page:"/notifications",tab:"settings",fieldName:"notifications.telegram_chat_id",keywords:["telegram","chat","notification"]},{id:"notifications.settings.locale",label:"Locale",description:"Language for notification messages",page:"/notifications",tab:"settings",fieldName:"notifications.locale",keywords:["locale","language","notification","i18n"]},{id:"notifications.settings.discord_webhook_url",label:"Discord Webhook URL",description:"Webhook URL for Discord notifications",page:"/notifications",tab:"settings",fieldName:"notifications.discord_webhook_url",keywords:["discord","webhook","notification","credential"]},{id:"notifications.settings.ntfy_server",label:"Ntfy Server",description:"Server URL for ntfy notifications",page:"/notifications",tab:"settings",fieldName:"notifications.ntfy_server",keywords:["ntfy","server","push","notification"]},{id:"notifications.settings.ntfy_topic",label:"Ntfy Topic",description:"Topic name for ntfy notifications",page:"/notifications",tab:"settings",fieldName:"notifications.ntfy_topic",keywords:["ntfy","topic","push","notification"]},{id:"notifications.settings.slack_webhook_url",label:"Slack Webhook URL",description:"Webhook URL for Slack notifications",page:"/notifications",tab:"settings",fieldName:"notifications.slack_webhook_url",keywords:["slack","webhook","notification","credential"]},{id:"notifications.settings.rate_limit_rpm",label:"Rate Limit (RPM)",description:"Max notifications per minute",page:"/notifications",tab:"settings",fieldName:"notifications.rate_limit_rpm",keywords:["rate","limit","rpm","notification","throttle"]},{id:"notifications.settings.telegram_bot_enabled",label:"Bot Enabled",description:"Enable or disable the Telegram bot",page:"/notifications",tab:"settings",fieldName:"telegram.enabled",keywords:["telegram","bot","enable","toggle"]},{id:"notifications.settings.telegram_dedicated_bot_token",label:"Bot Token",description:"Dedicated bot token for Telegram bot (optional, uses notification token if empty)",page:"/notifications",tab:"settings",fieldName:"telegram.bot_token",keywords:["telegram","bot","token","credential"]},{id:"security.autostop.enabled",label:"Enabled",description:"Enable or disable AutoStop protection rules",page:"/security",tab:"autostop",fieldName:"autostop.enabled",keywords:["autostop","protection","enable","toggle","security"]},{id:"security.autostop.consecutive_failures_threshold",label:"Consecutive Failures Threshold",description:"Suspend wallet after this many consecutive failed transactions",page:"/security",tab:"autostop",fieldName:"autostop.consecutive_failures_threshold",keywords:["autostop","failure","threshold","suspend","security"]},{id:"security.autostop.unusual_activity_threshold",label:"Unusual Activity Threshold",description:"Max transactions within window before triggering unusual activity alert",page:"/security",tab:"autostop",fieldName:"autostop.unusual_activity_threshold",keywords:["autostop","unusual","activity","threshold","security"]},{id:"security.autostop.unusual_activity_window_sec",label:"Unusual Activity Window (seconds)",description:"Time window for unusual activity detection",page:"/security",tab:"autostop",fieldName:"autostop.unusual_activity_window_sec",keywords:["autostop","unusual","activity","window","time","security"]},{id:"security.autostop.idle_timeout_sec",label:"Idle Timeout (seconds)",description:"Revoke sessions with no activity for this duration",page:"/security",tab:"autostop",fieldName:"autostop.idle_timeout_sec",keywords:["autostop","idle","timeout","session","revoke","security"]},{id:"security.autostop.idle_check_interval_sec",label:"Idle Check Interval (seconds)",description:"How often to check for idle sessions",page:"/security",tab:"autostop",fieldName:"autostop.idle_check_interval_sec",keywords:["autostop","idle","check","interval","security"]},{id:"system..currency",label:"Display Currency",description:"Currency for USD amount conversion in dashboard and notifications",page:"/system",tab:"",fieldName:"display.currency",keywords:["currency","display","usd","conversion","fiat"]},{id:"system..rate_limit_global_ip_rpm",label:"Global IP Rate Limit (RPM)",description:"Maximum API requests per minute from a single IP address",page:"/system",tab:"",fieldName:"security.rate_limit_global_ip_rpm",keywords:["rate","limit","rpm","ip","global","throttle"]},{id:"system..log_level",label:"Log Level",description:"Daemon logging verbosity level",page:"/system",tab:"",fieldName:"daemon.log_level",keywords:["log","level","debug","info","warn","error","daemon"]},{id:"system..cross_validation_threshold",label:"Cross Validation Threshold (%)",description:"Maximum allowed deviation between price oracle sources",page:"/system",tab:"",fieldName:"oracle.cross_validation_threshold",keywords:["oracle","price","validation","threshold","deviation"]}],re=te(""),J=te(null),Sn={"/wallets":"Wallets","/sessions":"Sessions","/policies":"Policies","/notifications":"Notifications","/security":"Security","/system":"System"};function kn(a){if(!a.trim())return[];const t=a.toLowerCase();return wn.filter(n=>[n.label,n.description,n.keywords.join(" ")].join(" ").toLowerCase().includes(t)).slice(0,10)}function Nn(a){const t=Sn[a.page]??a.page;return a.tab?`${t} > ${a.tab}`:t}function Tn({open:a}){const t=v(""),n=v(0),l=Ht(null),i=a.value?kn(t.value):[];if(O(()=>{a.value&&(t.value="",n.value=0,requestAnimationFrame(()=>{l.current?.focus()}))},[a.value]),!a.value)return null;const s=()=>{a.value=!1,t.value="",n.value=0},r=o=>{o.target.classList.contains("search-overlay")&&s()},c=o=>{window.location.hash="#"+o.page,o.tab?J.value={tab:o.tab,fieldName:o.fieldName}:setTimeout(()=>{re.value=o.fieldName},100),s()};return e("div",{class:"search-overlay",onClick:r,children:e("div",{class:"search-popover",onKeyDown:o=>{if(o.key==="Escape"){s();return}if(o.key==="ArrowDown"){o.preventDefault(),n.value=Math.min(n.value+1,i.length-1);return}if(o.key==="ArrowUp"){o.preventDefault(),n.value=Math.max(n.value-1,0);return}if(o.key==="Enter"&&i.length>0){o.preventDefault(),c(i[n.value]);return}},children:[e("div",{class:"search-input-wrapper",children:e("input",{ref:l,class:"search-input",type:"text",placeholder:"Search settings...",value:t.value,onInput:o=>{t.value=o.target.value,n.value=0}})}),e("div",{class:"search-results",children:[t.value.trim()&&i.length===0&&e("div",{class:"search-empty",children:"No settings found"}),i.map((o,u)=>e("button",{class:`search-result-item${u===n.value?" selected":""}`,onClick:()=>c(o),onMouseEnter:()=>{n.value=u},children:[e("div",{class:"search-result-label",children:o.label}),e("div",{class:"search-result-desc",children:o.description}),e("div",{class:"search-result-path",children:Nn(o)})]},o.id))]}),e("div",{class:"search-hint",children:[e("span",{children:[e("kbd",{children:"Esc"})," close"]}),e("span",{children:[e("kbd",{children:"↑"}),e("kbd",{children:"↓"})," navigate"]}),e("span",{children:[e("kbd",{children:"Enter"})," select"]})]})]})})}const ge=te([]),Va=He(()=>ge.value.some(a=>a.isDirty()));function fe(a){ge.value=[...ge.value.filter(t=>t.id!==a.id),a]}function _e(a){ge.value=ge.value.filter(t=>t.id!==a)}async function Cn(){const a=ge.value.filter(t=>t.isDirty());try{for(const t of a)await t.save();return!0}catch{return!1}}function En(){const a=ge.value.filter(t=>t.isDirty());for(const t of a)t.discard()}function N({label:a,name:t,type:n="text",value:l,onChange:i,options:s,error:r,required:c,disabled:m,placeholder:o,min:u,max:d,description:f}){const p=re.value===t;if(O(()=>{if(p){const T=document.querySelector(`[name="${t}"]`);T&&T.closest(".form-field")?.scrollIntoView({behavior:"smooth",block:"center"});const S=setTimeout(()=>{re.value=""},2500);return()=>clearTimeout(S)}},[p,t]),n==="checkbox")return e("div",{class:`form-field${p?" form-field--highlight":""}`,children:[e("label",{children:[e("input",{type:"checkbox",name:t,checked:!!l,onChange:T=>i(T.target.checked),disabled:m}),a,c&&e("span",{children:" *"})]}),f&&e("span",{class:"form-description",children:f}),r&&e("span",{class:"form-error",children:r})]});const b=`field-${t}`;return e("div",{class:`form-field${p?" form-field--highlight":""}`,children:[e("label",{for:b,children:[a,c&&e("span",{children:" *"})]}),n==="select"?e("select",{id:b,name:t,value:l,onChange:T=>i(T.target.value),disabled:m,children:s?.map(T=>e("option",{value:T.value,children:T.label},T.value))}):n==="textarea"?e("textarea",{id:b,name:t,value:l,onInput:T=>i(T.target.value),disabled:m,placeholder:o}):e("input",{id:b,type:n,name:t,value:l,onInput:T=>{const S=T.target;i(n==="number"?Number(S.value):S.value)},disabled:m,placeholder:o,min:u,max:d,required:c}),f&&e("span",{class:"form-description",children:f}),r&&e("span",{class:"form-error",children:r})]})}function E({variant:a="primary",size:t="md",loading:n=!1,disabled:l=!1,onClick:i,children:s,type:r="button"}){const c=["btn",`btn-${a}`,t==="sm"?"btn-sm":""].filter(Boolean).join(" ");return e("button",{type:r,class:c,disabled:l||n,onClick:i,children:n?"...":s})}function P({variant:a,children:t}){return e("span",{class:`badge badge-${a}`,children:t})}const Me=te(null),Pe=te(!1);function za(a){Me.value=a}function An(){const a=Me.value;if(!a)return null;const t=async()=>{Pe.value=!0;const i=await Cn();Pe.value=!1,i&&(Me.value=null,a.execute())},n=()=>{En(),Me.value=null,a.execute()},l=()=>{Me.value=null};return e("div",{class:"modal-overlay",onClick:l,children:e("div",{class:"modal-card",onClick:i=>i.stopPropagation(),children:[e("div",{class:"modal-header",children:"Unsaved Changes"}),e("div",{class:"modal-body",children:e("p",{children:"You have unsaved changes. What would you like to do?"})}),e("div",{class:"modal-footer unsaved-dialog-footer",children:[e(E,{variant:"secondary",onClick:l,disabled:Pe.value,children:"Cancel"}),e(E,{variant:"ghost",onClick:n,disabled:Pe.value,children:"Discard & Navigate"}),e(E,{variant:"primary",onClick:t,loading:Pe.value,children:"Save & Navigate"})]})]})})}class _ extends Error{constructor(t,n,l){super(`[${t}] ${n}: ${l}`),this.status=t,this.code=n,this.serverMessage=l,this.name="ApiError"}}async function ft(a,t){const n={"Content-Type":"application/json",...t?.headers};Ve.value!==null&&(n["X-Master-Password"]=Ve.value);let l;try{l=await fetch(a,{...t,headers:n,signal:AbortSignal.timeout(1e4)})}catch(i){const s=i;throw s.name==="AbortError"||s.name==="TimeoutError"?new _(0,"TIMEOUT","Request timed out"):new _(0,"NETWORK_ERROR","Cannot connect to daemon")}if(l.status===401)throw qt(),new _(401,"INVALID_MASTER_PASSWORD","Authentication failed");if(!l.ok){let i={};try{i=await l.json()}catch{}throw new _(l.status,i.code??"UNKNOWN",i.message??"Unknown error")}return zt(),await l.json()}const B=a=>ft(a,{method:"GET"}),Q=(a,t)=>ft(a,{method:"POST",body:t?JSON.stringify(t):void 0}),le=(a,t)=>ft(a,{method:"PUT",body:t?JSON.stringify(t):void 0}),De=a=>ft(a,{method:"DELETE"});function In(a){const t=Math.floor(a/86400),n=Math.floor(a%86400/3600),l=Math.floor(a%3600/60);return t>0?`${t}d ${n}h ${l}m`:n>0?`${n}h ${l}m`:`${l}m`}function ie(a){const t=new Date(a*1e3),n=l=>l.toString().padStart(2,"0");return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}:${n(t.getMinutes())}`}function Mt(a){return a.length<=10?a:`${a.slice(0,4)}..${a.slice(-4)}`}const Dn=new Set(["KRW","JPY","VND","CLP","HUF","PKR"]),Ln=new Set(["KWD","BHD"]);function On(a){return Dn.has(a)?0:Ln.has(a)?3:2}function xn(a,t,n){const l=a*n,i=On(t),s=new Intl.NumberFormat("en-US",{style:"currency",currency:t,minimumFractionDigits:i,maximumFractionDigits:i}).format(l);return t==="USD"?s:`≈${s}`}let Ne=null;const Rn=300*1e3;async function Pn(){if(Ne&&Date.now()-Ne.fetchedAt<Rn)return{currency:Ne.currency,rate:Ne.rate};try{const t=(await B(C.ADMIN_SETTINGS)).display?.["display.currency"]??"USD";if(t==="USD")return Ne={currency:"USD",rate:1,fetchedAt:Date.now()},{currency:"USD",rate:1};const i=(await B(`${C.ADMIN_FOREX_RATES}?currencies=${t}`)).rates[t]?.rate??null;return Ne={currency:t,rate:i,fetchedAt:Date.now()},{currency:t,rate:i}}catch{return{currency:"USD",rate:1}}}function Wn(a,t,n){return a==null?"":n==null?`$${a.toFixed(2)}`:xn(a,t,n)}function we({columns:a,data:t,onRowClick:n,emptyMessage:l="No data",loading:i=!1}){return e("div",{class:"table-container",children:e("table",{children:[e("thead",{children:e("tr",{children:a.map(s=>e("th",{style:s.width?{width:s.width}:void 0,children:s.header},s.key))})}),e("tbody",{children:i?e("tr",{children:e("td",{colSpan:a.length,class:"table-loading",children:"Loading..."})}):!t||t.length===0?e("tr",{children:e("td",{colSpan:a.length,class:"table-empty",children:l})}):t.map((s,r)=>e("tr",{class:n?"clickable":"",onClick:n?()=>n(s):void 0,children:a.map(c=>e("td",{children:c.render?c.render(s):s[c.key]},c.key))},r))})]})})}const Mn={INVALID_TOKEN:"Your authentication token is invalid. Please log in again.",TOKEN_EXPIRED:"Your session token has expired. Please log in again.",SESSION_REVOKED:"Your session has been revoked by an administrator.",INVALID_SIGNATURE:"The cryptographic signature is invalid.",INVALID_NONCE:"The authentication nonce is invalid or has expired.",INVALID_MASTER_PASSWORD:"Invalid master password. Please try again.",MASTER_PASSWORD_LOCKED:"Master password is locked due to too many failed attempts. Please wait.",SYSTEM_LOCKED:"The system is currently locked.",SESSION_NOT_FOUND:"Session not found.",SESSION_EXPIRED:"The session has expired.",SESSION_LIMIT_EXCEEDED:"Maximum number of sessions reached.",CONSTRAINT_VIOLATED:"A session constraint was violated.",RENEWAL_LIMIT_REACHED:"Session renewal limit has been reached. Create a new session.",SESSION_ABSOLUTE_LIFETIME_EXCEEDED:"Session has exceeded its maximum lifetime.",RENEWAL_TOO_EARLY:"Session renewal attempted too early. Please wait.",SESSION_RENEWAL_MISMATCH:"Session renewal count mismatch. The session may have been renewed elsewhere.",PIPELINE_HALTED:"Transaction is queued for delay or approval.",INSUFFICIENT_BALANCE:"Insufficient balance for this transaction.",INVALID_ADDRESS:"The blockchain address is invalid.",TX_NOT_FOUND:"Transaction not found.",TX_EXPIRED:"The transaction has expired.",TX_ALREADY_PROCESSED:"This transaction has already been processed.",CHAIN_ERROR:"A blockchain network error occurred. Please try again.",SIMULATION_FAILED:"Transaction simulation failed. The transaction may revert.",TOKEN_NOT_FOUND:"Token not found.",TOKEN_NOT_ALLOWED:"This token is not in the allowed list.",INSUFFICIENT_TOKEN_BALANCE:"Insufficient token balance.",CONTRACT_CALL_DISABLED:"Contract calls are disabled. Configure a CONTRACT_WHITELIST policy first.",CONTRACT_NOT_WHITELISTED:"This contract address is not whitelisted.",METHOD_NOT_WHITELISTED:"This contract method is not whitelisted.",APPROVE_DISABLED:"Token approvals are disabled. Configure an APPROVED_SPENDERS policy first.",SPENDER_NOT_APPROVED:"This spender address is not in the approved list.",APPROVE_AMOUNT_EXCEEDED:"The approve amount exceeds the configured limit.",UNLIMITED_APPROVE_BLOCKED:"Unlimited token approvals are blocked by policy.",BATCH_NOT_SUPPORTED:"Batch transactions are not supported on this chain.",BATCH_SIZE_EXCEEDED:"Batch contains too many instructions (maximum 20).",BATCH_POLICY_VIOLATION:"A policy violation occurred in the batch transaction.",POLICY_NOT_FOUND:"Policy not found.",POLICY_DENIED:"Transaction denied by policy.",SPENDING_LIMIT_EXCEEDED:"Spending limit has been exceeded.",RATE_LIMIT_EXCEEDED:"Rate limit exceeded. Please wait before retrying.",WHITELIST_DENIED:"The destination address is not in the whitelist.",OWNER_ALREADY_CONNECTED:"An owner wallet is already connected to this wallet.",OWNER_NOT_CONNECTED:"No owner wallet is connected to this wallet.",OWNER_NOT_FOUND:"Owner not found.",APPROVAL_TIMEOUT:"The approval request has timed out.",APPROVAL_NOT_FOUND:"Approval request not found.",OWNER_NOT_SET:"Owner address must be set before connecting WalletConnect.",OWNER_ADDRESS_MISMATCH:"Connected wallet address does not match registered owner.",KILL_SWITCH_ACTIVE:"Kill switch is active. All operations are suspended.",KILL_SWITCH_NOT_ACTIVE:"Kill switch is not currently active.",KEYSTORE_LOCKED:"The keystore is locked. Please try again.",CHAIN_NOT_SUPPORTED:"This blockchain is not supported.",SHUTTING_DOWN:"The daemon is shutting down.",ADAPTER_NOT_AVAILABLE:"Chain adapter is not available. Please try again.",WALLET_NOT_FOUND:"Wallet not found.",WALLET_SUSPENDED:"This wallet is currently suspended.",WALLET_TERMINATED:"This wallet has been terminated.",WC_NOT_CONFIGURED:"WalletConnect is not configured. Set the Project ID in Settings first.",WC_SESSION_NOT_FOUND:"No active WalletConnect session.",WC_SESSION_EXISTS:"A WalletConnect session already exists. Disconnect first.",WC_SIGNING_FAILED:"WalletConnect signing request failed.",NO_OWNER:"No owner connected. Withdrawal requires an owner wallet.",WITHDRAW_LOCKED_ONLY:"Withdrawal is only available when the owner state is LOCKED.",SWEEP_TOTAL_FAILURE:"All sweep operations failed. Please try again.",INSUFFICIENT_FOR_FEE:"Insufficient balance to cover transaction fees.",ACTION_NOT_FOUND:"Action not found.",ACTION_VALIDATION_FAILED:"Action input validation failed.",ACTION_RESOLVE_FAILED:"Action failed due to an external API error. Please try again.",ACTION_RETURN_INVALID:"Action returned an invalid result.",ACTION_PLUGIN_LOAD_FAILED:"Failed to load the action plugin.",ACTION_NAME_CONFLICT:"An action with this name already exists.",ACTION_CHAIN_MISMATCH:"The request chain does not match the action provider.",ROTATION_TOO_RECENT:"Key rotation was attempted too recently. Please wait.",NETWORK_ERROR:"Cannot connect to the daemon. Check if it is running.",TIMEOUT:"Request timed out. The daemon may be busy."},Un=new Set(["ACTION_VALIDATION_FAILED","CONSTRAINT_VIOLATED","INVALID_ADDRESS","INVALID_SIGNATURE"]);function I(a,t){return t&&Un.has(a)?t:Mn[a]??`An error occurred (${a}).`}const he=te([]);let $n=0;function y(a,t){const n=$n++;he.value=[...he.value,{id:n,type:a,message:t}],setTimeout(()=>{he.value=he.value.filter(l=>l.id!==n)},5e3)}function Kn(a){he.value=he.value.filter(t=>t.id!==a)}function Fn(){return he.value.length===0?null:e("div",{class:"toast-container",children:he.value.map(a=>e("div",{class:`toast toast-${a.type}`,onClick:()=>Kn(a.id),children:a.message},a.id))})}function Bn(a,t){const n=[];return n.push("[WAIaaS Connection]"),n.push(`- URL: ${a}`),n.push(""),n.push("Wallets:"),t.forEach((l,i)=>{n.push(`${i+1}. ${l.name} (${l.id}) — ${l.defaultNetwork}`),n.push(` Session: ${l.sessionToken}`)}),n.push(""),n.push("세션이 만료되면(401 Unauthorized)"),n.push("POST /v1/wallets/{walletId}/sessions/{sessionId}/renew 으로 갱신하세요."),n.push(""),n.push("위 정보로 WAIaaS 지갑에 연결하여 잔액을 확인하고 관리해주세요."),n.join(`
1
+ var ut,K,ya,ga,ye,Gt,ba,wa,Sa,$t,Lt,Ot,Be={},ka=[],Ya=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,vt=Array.isArray;function de(a,t){for(var n in t)a[n]=t[n];return a}function Kt(a){a&&a.parentNode&&a.parentNode.removeChild(a)}function Ja(a,t,n){var l,i,s,o={};for(s in t)s=="key"?l=t[s]:s=="ref"?i=t[s]:o[s]=t[s];if(arguments.length>2&&(o.children=arguments.length>3?ut.call(arguments,2):n),typeof a=="function"&&a.defaultProps!=null)for(s in a.defaultProps)o[s]===void 0&&(o[s]=a.defaultProps[s]);return it(a,o,l,i,null)}function it(a,t,n,l,i){var s={type:a,props:t,key:n,ref:l,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i??++ya,__i:-1,__u:0};return i==null&&K.vnode!=null&&K.vnode(s),s}function z(a){return a.children}function Ue(a,t){this.props=a,this.context=t}function Ie(a,t){if(t==null)return a.__?Ie(a.__,a.__i+1):null;for(var n;t<a.__k.length;t++)if((n=a.__k[t])!=null&&n.__e!=null)return n.__e;return typeof a.type=="function"?Ie(a):null}function Na(a){var t,n;if((a=a.__)!=null&&a.__c!=null){for(a.__e=a.__c.base=null,t=0;t<a.__k.length;t++)if((n=a.__k[t])!=null&&n.__e!=null){a.__e=a.__c.base=n.__e;break}return Na(a)}}function jt(a){(!a.__d&&(a.__d=!0)&&ye.push(a)&&!rt.__r++||Gt!=K.debounceRendering)&&((Gt=K.debounceRendering)||ba)(rt)}function rt(){for(var a,t,n,l,i,s,o,c=1;ye.length;)ye.length>c&&ye.sort(wa),a=ye.shift(),c=ye.length,a.__d&&(n=void 0,l=void 0,i=(l=(t=a).__v).__e,s=[],o=[],t.__P&&((n=de({},l)).__v=l.__v+1,K.vnode&&K.vnode(n),Ft(t.__P,n,l,t.__n,t.__P.namespaceURI,32&l.__u?[i]:null,s,i??Ie(l),!!(32&l.__u),o),n.__v=l.__v,n.__.__k[n.__i]=n,Ea(s,n,o),l.__e=l.__=null,n.__e!=i&&Na(n)));rt.__r=0}function Ta(a,t,n,l,i,s,o,c,m,r,u){var d,f,p,b,T,k,D,L=l&&l.__k||ka,M=t.length;for(m=Xa(n,t,L,m,M),d=0;d<M;d++)(p=n.__k[d])!=null&&(f=p.__i==-1?Be:L[p.__i]||Be,p.__i=d,k=Ft(a,p,f,i,s,o,c,m,r,u),b=p.__e,p.ref&&f.ref!=p.ref&&(f.ref&&Bt(f.ref,null,p),u.push(p.ref,p.__c||b,p)),T==null&&b!=null&&(T=b),(D=!!(4&p.__u))||f.__k===p.__k?m=Ca(p,m,a,D):typeof p.type=="function"&&k!==void 0?m=k:b&&(m=b.nextSibling),p.__u&=-7);return n.__e=T,m}function Xa(a,t,n,l,i){var s,o,c,m,r,u=n.length,d=u,f=0;for(a.__k=new Array(i),s=0;s<i;s++)(o=t[s])!=null&&typeof o!="boolean"&&typeof o!="function"?(typeof o=="string"||typeof o=="number"||typeof o=="bigint"||o.constructor==String?o=a.__k[s]=it(null,o,null,null,null):vt(o)?o=a.__k[s]=it(z,{children:o},null,null,null):o.constructor===void 0&&o.__b>0?o=a.__k[s]=it(o.type,o.props,o.key,o.ref?o.ref:null,o.__v):a.__k[s]=o,m=s+f,o.__=a,o.__b=a.__b+1,c=null,(r=o.__i=Za(o,n,m,d))!=-1&&(d--,(c=n[r])&&(c.__u|=2)),c==null||c.__v==null?(r==-1&&(i>u?f--:i<u&&f++),typeof o.type!="function"&&(o.__u|=4)):r!=m&&(r==m-1?f--:r==m+1?f++:(r>m?f--:f++,o.__u|=4))):a.__k[s]=null;if(d)for(s=0;s<u;s++)(c=n[s])!=null&&(2&c.__u)==0&&(c.__e==l&&(l=Ie(c)),Ia(c,c));return l}function Ca(a,t,n,l){var i,s;if(typeof a.type=="function"){for(i=a.__k,s=0;i&&s<i.length;s++)i[s]&&(i[s].__=a,t=Ca(i[s],t,n,l));return t}a.__e!=t&&(l&&(t&&a.type&&!t.parentNode&&(t=Ie(a)),n.insertBefore(a.__e,t||null)),t=a.__e);do t=t&&t.nextSibling;while(t!=null&&t.nodeType==8);return t}function Za(a,t,n,l){var i,s,o,c=a.key,m=a.type,r=t[n],u=r!=null&&(2&r.__u)==0;if(r===null&&c==null||u&&c==r.key&&m==r.type)return n;if(l>(u?1:0)){for(i=n-1,s=n+1;i>=0||s<t.length;)if((r=t[o=i>=0?i--:s++])!=null&&(2&r.__u)==0&&c==r.key&&m==r.type)return o}return-1}function Yt(a,t,n){t[0]=="-"?a.setProperty(t,n??""):a[t]=n==null?"":typeof n!="number"||Ya.test(t)?n:n+"px"}function Ze(a,t,n,l,i){var s,o;e:if(t=="style")if(typeof n=="string")a.style.cssText=n;else{if(typeof l=="string"&&(a.style.cssText=l=""),l)for(t in l)n&&t in n||Yt(a.style,t,"");if(n)for(t in n)l&&n[t]==l[t]||Yt(a.style,t,n[t])}else if(t[0]=="o"&&t[1]=="n")s=t!=(t=t.replace(Sa,"$1")),o=t.toLowerCase(),t=o in a||t=="onFocusOut"||t=="onFocusIn"?o.slice(2):t.slice(2),a.l||(a.l={}),a.l[t+s]=n,n?l?n.u=l.u:(n.u=$t,a.addEventListener(t,s?Ot:Lt,s)):a.removeEventListener(t,s?Ot:Lt,s);else{if(i=="http://www.w3.org/2000/svg")t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(t!="width"&&t!="height"&&t!="href"&&t!="list"&&t!="form"&&t!="tabIndex"&&t!="download"&&t!="rowSpan"&&t!="colSpan"&&t!="role"&&t!="popover"&&t in a)try{a[t]=n??"";break e}catch{}typeof n=="function"||(n==null||n===!1&&t[4]!="-"?a.removeAttribute(t):a.setAttribute(t,t=="popover"&&n==1?"":n))}}function Jt(a){return function(t){if(this.l){var n=this.l[t.type+a];if(t.t==null)t.t=$t++;else if(t.t<n.u)return;return n(K.event?K.event(t):t)}}}function Ft(a,t,n,l,i,s,o,c,m,r){var u,d,f,p,b,T,k,D,L,M,F,w,x,R,j,q,X,G=t.type;if(t.constructor!==void 0)return null;128&n.__u&&(m=!!(32&n.__u),s=[c=t.__e=n.__e]),(u=K.__b)&&u(t);e:if(typeof G=="function")try{if(D=t.props,L="prototype"in G&&G.prototype.render,M=(u=G.contextType)&&l[u.__c],F=u?M?M.props.value:u.__:l,n.__c?k=(d=t.__c=n.__c).__=d.__E:(L?t.__c=d=new G(D,F):(t.__c=d=new Ue(D,F),d.constructor=G,d.render=en),M&&M.sub(d),d.state||(d.state={}),d.__n=l,f=d.__d=!0,d.__h=[],d._sb=[]),L&&d.__s==null&&(d.__s=d.state),L&&G.getDerivedStateFromProps!=null&&(d.__s==d.state&&(d.__s=de({},d.__s)),de(d.__s,G.getDerivedStateFromProps(D,d.__s))),p=d.props,b=d.state,d.__v=t,f)L&&G.getDerivedStateFromProps==null&&d.componentWillMount!=null&&d.componentWillMount(),L&&d.componentDidMount!=null&&d.__h.push(d.componentDidMount);else{if(L&&G.getDerivedStateFromProps==null&&D!==p&&d.componentWillReceiveProps!=null&&d.componentWillReceiveProps(D,F),t.__v==n.__v||!d.__e&&d.shouldComponentUpdate!=null&&d.shouldComponentUpdate(D,d.__s,F)===!1){for(t.__v!=n.__v&&(d.props=D,d.state=d.__s,d.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(h){h&&(h.__=t)}),w=0;w<d._sb.length;w++)d.__h.push(d._sb[w]);d._sb=[],d.__h.length&&o.push(d);break e}d.componentWillUpdate!=null&&d.componentWillUpdate(D,d.__s,F),L&&d.componentDidUpdate!=null&&d.__h.push(function(){d.componentDidUpdate(p,b,T)})}if(d.context=F,d.props=D,d.__P=a,d.__e=!1,x=K.__r,R=0,L){for(d.state=d.__s,d.__d=!1,x&&x(t),u=d.render(d.props,d.state,d.context),j=0;j<d._sb.length;j++)d.__h.push(d._sb[j]);d._sb=[]}else do d.__d=!1,x&&x(t),u=d.render(d.props,d.state,d.context),d.state=d.__s;while(d.__d&&++R<25);d.state=d.__s,d.getChildContext!=null&&(l=de(de({},l),d.getChildContext())),L&&!f&&d.getSnapshotBeforeUpdate!=null&&(T=d.getSnapshotBeforeUpdate(p,b)),q=u,u!=null&&u.type===z&&u.key==null&&(q=Aa(u.props.children)),c=Ta(a,vt(q)?q:[q],t,n,l,i,s,o,c,m,r),d.base=t.__e,t.__u&=-161,d.__h.length&&o.push(d),k&&(d.__E=d.__=null)}catch(h){if(t.__v=null,m||s!=null)if(h.then){for(t.__u|=m?160:128;c&&c.nodeType==8&&c.nextSibling;)c=c.nextSibling;s[s.indexOf(c)]=null,t.__e=c}else{for(X=s.length;X--;)Kt(s[X]);xt(t)}else t.__e=n.__e,t.__k=n.__k,h.then||xt(t);K.__e(h,t,n)}else s==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):c=t.__e=Qa(n.__e,t,n,l,i,s,o,m,r);return(u=K.diffed)&&u(t),128&t.__u?void 0:c}function xt(a){a&&a.__c&&(a.__c.__e=!0),a&&a.__k&&a.__k.forEach(xt)}function Ea(a,t,n){for(var l=0;l<n.length;l++)Bt(n[l],n[++l],n[++l]);K.__c&&K.__c(t,a),a.some(function(i){try{a=i.__h,i.__h=[],a.some(function(s){s.call(i)})}catch(s){K.__e(s,i.__v)}})}function Aa(a){return typeof a!="object"||a==null||a.__b&&a.__b>0?a:vt(a)?a.map(Aa):de({},a)}function Qa(a,t,n,l,i,s,o,c,m){var r,u,d,f,p,b,T,k=n.props||Be,D=t.props,L=t.type;if(L=="svg"?i="http://www.w3.org/2000/svg":L=="math"?i="http://www.w3.org/1998/Math/MathML":i||(i="http://www.w3.org/1999/xhtml"),s!=null){for(r=0;r<s.length;r++)if((p=s[r])&&"setAttribute"in p==!!L&&(L?p.localName==L:p.nodeType==3)){a=p,s[r]=null;break}}if(a==null){if(L==null)return document.createTextNode(D);a=document.createElementNS(i,L,D.is&&D),c&&(K.__m&&K.__m(t,s),c=!1),s=null}if(L==null)k===D||c&&a.data==D||(a.data=D);else{if(s=s&&ut.call(a.childNodes),!c&&s!=null)for(k={},r=0;r<a.attributes.length;r++)k[(p=a.attributes[r]).name]=p.value;for(r in k)if(p=k[r],r!="children"){if(r=="dangerouslySetInnerHTML")d=p;else if(!(r in D)){if(r=="value"&&"defaultValue"in D||r=="checked"&&"defaultChecked"in D)continue;Ze(a,r,null,p,i)}}for(r in D)p=D[r],r=="children"?f=p:r=="dangerouslySetInnerHTML"?u=p:r=="value"?b=p:r=="checked"?T=p:c&&typeof p!="function"||k[r]===p||Ze(a,r,p,k[r],i);if(u)c||d&&(u.__html==d.__html||u.__html==a.innerHTML)||(a.innerHTML=u.__html),t.__k=[];else if(d&&(a.innerHTML=""),Ta(t.type=="template"?a.content:a,vt(f)?f:[f],t,n,l,L=="foreignObject"?"http://www.w3.org/1999/xhtml":i,s,o,s?s[0]:n.__k&&Ie(n,0),c,m),s!=null)for(r=s.length;r--;)Kt(s[r]);c||(r="value",L=="progress"&&b==null?a.removeAttribute("value"):b!=null&&(b!==a[r]||L=="progress"&&!b||L=="option"&&b!=k[r])&&Ze(a,r,b,k[r],i),r="checked",T!=null&&T!=a[r]&&Ze(a,r,T,k[r],i))}return a}function Bt(a,t,n){try{if(typeof a=="function"){var l=typeof a.__u=="function";l&&a.__u(),l&&t==null||(a.__u=a(t))}else a.current=t}catch(i){K.__e(i,n)}}function Ia(a,t,n){var l,i;if(K.unmount&&K.unmount(a),(l=a.ref)&&(l.current&&l.current!=a.__e||Bt(l,null,t)),(l=a.__c)!=null){if(l.componentWillUnmount)try{l.componentWillUnmount()}catch(s){K.__e(s,t)}l.base=l.__P=null}if(l=a.__k)for(i=0;i<l.length;i++)l[i]&&Ia(l[i],t,n||typeof a.type!="function");n||Kt(a.__e),a.__c=a.__=a.__e=void 0}function en(a,t,n){return this.constructor(a,n)}function tn(a,t,n){var l,i,s,o;t==document&&(t=document.documentElement),K.__&&K.__(a,t),i=(l=!1)?null:t.__k,s=[],o=[],Ft(t,a=t.__k=Ja(z,null,[a]),i||Be,Be,t.namespaceURI,i?null:t.firstChild?ut.call(t.childNodes):null,s,i?i.__e:t.firstChild,l,o),Ea(s,a,o)}ut=ka.slice,K={__e:function(a,t,n,l){for(var i,s,o;t=t.__;)if((i=t.__c)&&!i.__)try{if((s=i.constructor)&&s.getDerivedStateFromError!=null&&(i.setState(s.getDerivedStateFromError(a)),o=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(a,l||{}),o=i.__d),o)return i.__E=i}catch(c){a=c}throw a}},ya=0,ga=function(a){return a!=null&&a.constructor===void 0},Ue.prototype.setState=function(a,t){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=de({},this.state),typeof a=="function"&&(a=a(de({},n),this.props)),a&&de(n,a),a!=null&&this.__v&&(t&&this._sb.push(t),jt(this))},Ue.prototype.forceUpdate=function(a){this.__v&&(this.__e=!0,a&&this.__h.push(a),jt(this))},Ue.prototype.render=z,ye=[],ba=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,wa=function(a,t){return a.__v.__b-t.__v.__b},rt.__r=0,Sa=/(PointerCapture)$|Capture$/i,$t=0,Lt=Jt(!1),Ot=Jt(!0);var an=0;function e(a,t,n,l,i,s){t||(t={});var o,c,m=t;if("ref"in m)for(c in m={},t)c=="ref"?o=t[c]:m[c]=t[c];var r={type:a,props:m,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--an,__i:-1,__u:0,__source:i,__self:s};if(typeof a=="function"&&(o=a.defaultProps))for(c in o)m[c]===void 0&&(m[c]=o[c]);return K.vnode&&K.vnode(r),r}var ot,ne,Nt,Xt,Rt=0,Da=[],Y=K,Zt=Y.__b,Qt=Y.__r,ea=Y.diffed,ta=Y.__c,aa=Y.unmount,na=Y.__;function La(a,t){Y.__h&&Y.__h(ne,a,Rt||t),Rt=0;var n=ne.__H||(ne.__H={__:[],__h:[]});return a>=n.__.length&&n.__.push({}),n.__[a]}function O(a,t){var n=La(ot++,3);!Y.__s&&Oa(n.__H,t)&&(n.__=a,n.u=t,ne.__H.__h.push(n))}function Ht(a){return Rt=5,ht(function(){return{current:a}},[])}function ht(a,t){var n=La(ot++,7);return Oa(n.__H,t)&&(n.__=a(),n.__H=t,n.__h=a),n.__}function nn(){for(var a;a=Da.shift();)if(a.__P&&a.__H)try{a.__H.__h.forEach(st),a.__H.__h.forEach(Pt),a.__H.__h=[]}catch(t){a.__H.__h=[],Y.__e(t,a.__v)}}Y.__b=function(a){ne=null,Zt&&Zt(a)},Y.__=function(a,t){a&&t.__k&&t.__k.__m&&(a.__m=t.__k.__m),na&&na(a,t)},Y.__r=function(a){Qt&&Qt(a),ot=0;var t=(ne=a.__c).__H;t&&(Nt===ne?(t.__h=[],ne.__h=[],t.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.forEach(st),t.__h.forEach(Pt),t.__h=[],ot=0)),Nt=ne},Y.diffed=function(a){ea&&ea(a);var t=a.__c;t&&t.__H&&(t.__H.__h.length&&(Da.push(t)!==1&&Xt===Y.requestAnimationFrame||((Xt=Y.requestAnimationFrame)||ln)(nn)),t.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),Nt=ne=null},Y.__c=function(a,t){t.some(function(n){try{n.__h.forEach(st),n.__h=n.__h.filter(function(l){return!l.__||Pt(l)})}catch(l){t.some(function(i){i.__h&&(i.__h=[])}),t=[],Y.__e(l,n.__v)}}),ta&&ta(a,t)},Y.unmount=function(a){aa&&aa(a);var t,n=a.__c;n&&n.__H&&(n.__H.__.forEach(function(l){try{st(l)}catch(i){t=i}}),n.__H=void 0,t&&Y.__e(t,n.__v))};var la=typeof requestAnimationFrame=="function";function ln(a){var t,n=function(){clearTimeout(l),la&&cancelAnimationFrame(t),setTimeout(a)},l=setTimeout(n,35);la&&(t=requestAnimationFrame(n))}function st(a){var t=ne,n=a.__c;typeof n=="function"&&(a.__c=void 0,n()),ne=t}function Pt(a){var t=ne;a.__c=a.__(),ne=t}function Oa(a,t){return!a||a.length!==t.length||t.some(function(n,l){return n!==a[l]})}var sn=Symbol.for("preact-signals");function mt(){if(me>1)me--;else{for(var a,t=!1;$e!==void 0;){var n=$e;for($e=void 0,Wt++;n!==void 0;){var l=n.o;if(n.o=void 0,n.f&=-3,!(8&n.f)&&Pa(n))try{n.c()}catch(i){t||(a=i,t=!0)}n=l}}if(Wt=0,me--,t)throw a}}function rn(a){if(me>0)return a();me++;try{return a()}finally{mt()}}var $=void 0;function xa(a){var t=$;$=void 0;try{return a()}finally{$=t}}var $e=void 0,me=0,Wt=0,ct=0;function Ra(a){if($!==void 0){var t=a.n;if(t===void 0||t.t!==$)return t={i:0,S:a,p:$.s,n:void 0,t:$,e:void 0,x:void 0,r:t},$.s!==void 0&&($.s.n=t),$.s=t,a.n=t,32&$.f&&a.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=$.s,t.n=void 0,$.s.n=t,$.s=t),t}}function ee(a,t){this.v=a,this.i=0,this.n=void 0,this.t=void 0,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}ee.prototype.brand=sn;ee.prototype.h=function(){return!0};ee.prototype.S=function(a){var t=this,n=this.t;n!==a&&a.e===void 0&&(a.x=n,this.t=a,n!==void 0?n.e=a:xa(function(){var l;(l=t.W)==null||l.call(t)}))};ee.prototype.U=function(a){var t=this;if(this.t!==void 0){var n=a.e,l=a.x;n!==void 0&&(n.x=l,a.e=void 0),l!==void 0&&(l.e=n,a.x=void 0),a===this.t&&(this.t=l,l===void 0&&xa(function(){var i;(i=t.Z)==null||i.call(t)}))}};ee.prototype.subscribe=function(a){var t=this;return ze(function(){var n=t.value,l=$;$=void 0;try{a(n)}finally{$=l}},{name:"sub"})};ee.prototype.valueOf=function(){return this.value};ee.prototype.toString=function(){return this.value+""};ee.prototype.toJSON=function(){return this.value};ee.prototype.peek=function(){var a=$;$=void 0;try{return this.value}finally{$=a}};Object.defineProperty(ee.prototype,"value",{get:function(){var a=Ra(this);return a!==void 0&&(a.i=this.i),this.v},set:function(a){if(a!==this.v){if(Wt>100)throw new Error("Cycle detected");this.v=a,this.i++,ct++,me++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{mt()}}}});function te(a,t){return new ee(a,t)}function Pa(a){for(var t=a.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function Wa(a){for(var t=a.s;t!==void 0;t=t.n){var n=t.S.n;if(n!==void 0&&(t.r=n),t.S.n=t,t.i=-1,t.n===void 0){a.s=t;break}}}function Ma(a){for(var t=a.s,n=void 0;t!==void 0;){var l=t.p;t.i===-1?(t.S.U(t),l!==void 0&&(l.n=t.n),t.n!==void 0&&(t.n.p=l)):n=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=l}a.s=n}function be(a,t){ee.call(this,void 0),this.x=a,this.s=void 0,this.g=ct-1,this.f=4,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}be.prototype=new ee;be.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===ct))return!0;if(this.g=ct,this.f|=1,this.i>0&&!Pa(this))return this.f&=-2,!0;var a=$;try{Wa(this),$=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(n){this.v=n,this.f|=16,this.i++}return $=a,Ma(this),this.f&=-2,!0};be.prototype.S=function(a){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}ee.prototype.S.call(this,a)};be.prototype.U=function(a){if(this.t!==void 0&&(ee.prototype.U.call(this,a),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}};be.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var a=this.t;a!==void 0;a=a.x)a.t.N()}};Object.defineProperty(be.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var a=Ra(this);if(this.h(),a!==void 0&&(a.i=this.i),16&this.f)throw this.v;return this.v}});function He(a,t){return new be(a,t)}function Ua(a){var t=a.u;if(a.u=void 0,typeof t=="function"){me++;var n=$;$=void 0;try{t()}catch(l){throw a.f&=-2,a.f|=8,Vt(a),l}finally{$=n,mt()}}}function Vt(a){for(var t=a.s;t!==void 0;t=t.n)t.S.U(t);a.x=void 0,a.s=void 0,Ua(a)}function on(a){if($!==this)throw new Error("Out-of-order effect");Ma(this),$=a,this.f&=-2,8&this.f&&Vt(this),mt()}function xe(a,t){this.x=a,this.u=void 0,this.s=void 0,this.o=void 0,this.f=32,this.name=t?.name}xe.prototype.c=function(){var a=this.S();try{if(8&this.f||this.x===void 0)return;var t=this.x();typeof t=="function"&&(this.u=t)}finally{a()}};xe.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Ua(this),Wa(this),me++;var a=$;return $=this,on.bind(this,a)};xe.prototype.N=function(){2&this.f||(this.f|=2,this.o=$e,$e=this)};xe.prototype.d=function(){this.f|=8,1&this.f||Vt(this)};xe.prototype.dispose=function(){this.d()};function ze(a,t){var n=new xe(a,t);try{n.c()}catch(i){throw n.d(),i}var l=n.d.bind(n);return l[Symbol.dispose]=l,l}var $a,pt,Qe,cn=typeof window<"u"&&!!window.__PREACT_SIGNALS_DEVTOOLS__,Ka=[];ze(function(){$a=this.N})();function Re(a,t){K[a]=t.bind(null,K[a]||function(){})}function dt(a){if(Qe){var t=Qe;Qe=void 0,t()}Qe=a&&a.S()}function Fa(a){var t=this,n=a.data,l=v(n);l.value=n;var i=ht(function(){for(var c=t,m=t.__v;m=m.__;)if(m.__c){m.__c.__$f|=4;break}var r=He(function(){var p=l.value.value;return p===0?0:p===!0?"":p||""}),u=He(function(){return!Array.isArray(r.value)&&!ga(r.value)}),d=ze(function(){if(this.N=Ba,u.value){var p=r.value;c.__v&&c.__v.__e&&c.__v.__e.nodeType===3&&(c.__v.__e.data=p)}}),f=t.__$u.d;return t.__$u.d=function(){d(),f.call(this)},[u,r]},[]),s=i[0],o=i[1];return s.value?o.peek():o.value}Fa.displayName="ReactiveTextNode";Object.defineProperties(ee.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:Fa},props:{configurable:!0,get:function(){return{data:this}}},__b:{configurable:!0,value:1}});Re("__b",function(a,t){if(typeof t.type=="string"){var n,l=t.props;for(var i in l)if(i!=="children"){var s=l[i];s instanceof ee&&(n||(t.__np=n={}),n[i]=s,l[i]=s.peek())}}a(t)});Re("__r",function(a,t){if(a(t),t.type!==z){dt();var n,l=t.__c;l&&(l.__$f&=-2,(n=l.__$u)===void 0&&(l.__$u=n=(function(i,s){var o;return ze(function(){o=this},{name:s}),o.c=i,o})(function(){var i;cn&&((i=n.y)==null||i.call(n)),l.__$f|=1,l.setState({})},typeof t.type=="function"?t.type.displayName||t.type.name:""))),pt=l,dt(n)}});Re("__e",function(a,t,n,l){dt(),pt=void 0,a(t,n,l)});Re("diffed",function(a,t){dt(),pt=void 0;var n;if(typeof t.type=="string"&&(n=t.__e)){var l=t.__np,i=t.props;if(l){var s=n.U;if(s)for(var o in s){var c=s[o];c!==void 0&&!(o in l)&&(c.d(),s[o]=void 0)}else s={},n.U=s;for(var m in l){var r=s[m],u=l[m];r===void 0?(r=dn(n,m,u,i),s[m]=r):r.o(u,i)}}}a(t)});function dn(a,t,n,l){var i=t in a&&a.ownerSVGElement===void 0,s=te(n);return{o:function(o,c){s.value=o,l=c},d:ze(function(){this.N=Ba;var o=s.value.value;l[t]!==o&&(l[t]=o,i?a[t]=o:o!=null&&(o!==!1||t[4]==="-")?a.setAttribute(t,o):a.removeAttribute(t))})}}Re("unmount",function(a,t){if(typeof t.type=="string"){var n=t.__e;if(n){var l=n.U;if(l){n.U=void 0;for(var i in l){var s=l[i];s&&s.d()}}}}else{var o=t.__c;if(o){var c=o.__$u;c&&(o.__$u=void 0,c.d())}}a(t)});Re("__h",function(a,t,n,l){(l<3||l===9)&&(t.__$f|=2),a(t,n,l)});Ue.prototype.shouldComponentUpdate=function(a,t){if(this.__R)return!0;var n=this.__$u,l=n&&n.s!==void 0;for(var i in t)return!0;if(this.__f||typeof this.u=="boolean"&&this.u===!0){var s=2&this.__$f;if(!(l||s||4&this.__$f)||1&this.__$f)return!0}else if(!(l||4&this.__$f)||3&this.__$f)return!0;for(var o in a)if(o!=="__source"&&a[o]!==this.props[o])return!0;for(var c in this.props)if(!(c in a))return!0;return!1};function v(a,t){return ht(function(){return te(a,t)},[])}function un(a,t){var n=Ht(a);return n.current=a,pt.__$f|=4,ht(function(){return He(function(){return n.current()},t)},[])}var vn=function(a){queueMicrotask(function(){queueMicrotask(a)})};function hn(){rn(function(){for(var a;a=Ka.shift();)$a.call(a)})}function Ba(){Ka.push(this)===1&&(K.requestAnimationFrame||vn)(hn)}const Ve=te(null),mn=He(()=>Ve.value!==null),Ha=te(900),pn=te(!1);let Ce=null;const Ee=()=>{zt()};function fn(){document.addEventListener("mousemove",Ee,{passive:!0}),document.addEventListener("keydown",Ee,{passive:!0}),document.addEventListener("click",Ee,{passive:!0}),zt()}function _n(){document.removeEventListener("mousemove",Ee),document.removeEventListener("keydown",Ee),document.removeEventListener("click",Ee),Ce!==null&&(clearTimeout(Ce),Ce=null)}function zt(){Ce!==null&&clearTimeout(Ce),Ce=setTimeout(()=>{qt()},Ha.value*1e3)}function yn(a,t){Ve.value=a,t!==void 0&&(Ha.value=t),fn(),location.hash="#/dashboard"}function qt(){Ve.value=null,_n(),location.hash="#/login"}const C={ADMIN_STATUS:"/v1/admin/status",ADMIN_KILL_SWITCH:"/v1/admin/kill-switch",ADMIN_KILL_SWITCH_ESCALATE:"/v1/admin/kill-switch/escalate",ADMIN_RECOVER:"/v1/admin/recover",ADMIN_SHUTDOWN:"/v1/admin/shutdown",ADMIN_ROTATE_SECRET:"/v1/admin/rotate-secret",WALLETS:"/v1/wallets",WALLET:a=>`/v1/wallets/${a}`,SESSIONS:"/v1/sessions",SESSION:a=>`/v1/sessions/${a}`,POLICIES:"/v1/policies",POLICY:a=>`/v1/policies/${a}`,ADMIN_NOTIFICATIONS_STATUS:"/v1/admin/notifications/status",ADMIN_NOTIFICATIONS_TEST:"/v1/admin/notifications/test",ADMIN_NOTIFICATIONS_LOG:"/v1/admin/notifications/log",MCP_TOKENS:"/v1/mcp/tokens",ADMIN_SETTINGS:"/v1/admin/settings",ADMIN_SETTINGS_TEST_RPC:"/v1/admin/settings/test-rpc",WALLET_NETWORKS:a=>`/v1/wallets/${a}/networks`,WALLET_DEFAULT_NETWORK:a=>`/v1/wallets/${a}/default-network`,ADMIN_WALLET_BALANCE:a=>`/v1/admin/wallets/${a}/balance`,ADMIN_WALLET_TRANSACTIONS:a=>`/v1/admin/wallets/${a}/transactions`,ADMIN_API_KEYS:"/v1/admin/api-keys",ADMIN_API_KEY:a=>`/v1/admin/api-keys/${a}`,ADMIN_FOREX_RATES:"/v1/admin/forex/rates",ADMIN_TELEGRAM_USERS:"/v1/admin/telegram-users",ADMIN_TELEGRAM_USER:a=>`/v1/admin/telegram-users/${a}`,WALLET_OWNER:a=>`/v1/wallets/${a}/owner`,WALLET_WITHDRAW:a=>`/v1/wallets/${a}/withdraw`,WALLET_WC_PAIR:a=>`/v1/wallets/${a}/wc/pair`,WALLET_WC_SESSION:a=>`/v1/wallets/${a}/wc/session`,WALLET_WC_PAIR_STATUS:a=>`/v1/wallets/${a}/wc/pair/status`,WALLET_OWNER_VERIFY:a=>`/v1/wallets/${a}/owner/verify`,ADMIN_BULK_SESSIONS:"/v1/admin/sessions/bulk",ADMIN_BULK_MCP_TOKENS:"/v1/admin/mcp/tokens/bulk"},Ke=te(""),Te=te(null),Fe=te(!1),ue={wrapper:{display:"flex",alignItems:"center",justifyContent:"center",minHeight:"100vh",background:"var(--color-bg-secondary)"},card:{background:"var(--color-bg)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-lg)",padding:"var(--space-8)",width:"100%",maxWidth:"360px",boxShadow:"var(--shadow-md)"},title:{fontSize:"var(--font-size-2xl)",fontWeight:"var(--font-weight-bold)",textAlign:"center",marginBottom:"var(--space-1)"},subtitle:{fontSize:"var(--font-size-sm)",color:"var(--color-text-secondary)",textAlign:"center",marginBottom:"var(--space-6)"},input:{width:"100%",padding:"var(--space-2) var(--space-3)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",fontSize:"var(--font-size-base)",outline:"none"},button:{width:"100%",padding:"var(--space-2) var(--space-4)",background:"var(--color-primary)",color:"white",border:"none",borderRadius:"var(--radius-md)",fontSize:"var(--font-size-base)",fontWeight:"var(--font-weight-medium)",marginTop:"var(--space-4)"},buttonDisabled:{opacity:.6,cursor:"not-allowed"},error:{color:"var(--color-danger)",fontSize:"var(--font-size-sm)",textAlign:"center",marginTop:"var(--space-3)"}},gn=async a=>{if(a.preventDefault(),!!Ke.value.trim()){Fe.value=!0,Te.value=null;try{const t=await fetch(C.ADMIN_STATUS,{headers:{"X-Master-Password":Ke.value},signal:AbortSignal.timeout(1e4)});if(t.status===401){Te.value="Invalid master password";return}if(!t.ok){Te.value="Cannot connect to daemon";return}const n=await t.json();yn(Ke.value,n.adminTimeout)}catch{Te.value="Cannot connect to daemon"}finally{Fe.value=!1}}};function bn(){return e("div",{style:ue.wrapper,children:e("form",{style:ue.card,onSubmit:gn,children:[e("h1",{style:ue.title,children:"WAIaaS Admin"}),e("p",{style:ue.subtitle,children:"Enter master password to continue"}),e("input",{type:"password",placeholder:"Master password",autoFocus:!0,value:Ke.value,onInput:a=>{Ke.value=a.target.value},style:ue.input}),e("button",{type:"submit",disabled:Fe.value,style:{...ue.button,...Fe.value?ue.buttonDisabled:{}},children:Fe.value?"Signing in...":"Sign in"}),Te.value&&e("p",{style:ue.error,children:Te.value})]})})}const wn=[{id:"wallets.rpc.solana_mainnet",label:"Solana Mainnet",description:"RPC endpoint URL for Solana mainnet",page:"/wallets",tab:"rpc",fieldName:"rpc.solana_mainnet",keywords:["blockchain","rpc","solana","url","endpoint"]},{id:"wallets.rpc.solana_devnet",label:"Solana Devnet",description:"RPC endpoint URL for Solana devnet",page:"/wallets",tab:"rpc",fieldName:"rpc.solana_devnet",keywords:["blockchain","rpc","solana","url","endpoint","test"]},{id:"wallets.rpc.solana_testnet",label:"Solana Testnet",description:"RPC endpoint URL for Solana testnet",page:"/wallets",tab:"rpc",fieldName:"rpc.solana_testnet",keywords:["blockchain","rpc","solana","url","endpoint","test"]},{id:"wallets.rpc.evm_ethereum_mainnet",label:"Ethereum Mainnet",description:"RPC endpoint URL for Ethereum mainnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_ethereum_mainnet",keywords:["blockchain","rpc","evm","ethereum","url","endpoint"]},{id:"wallets.rpc.evm_ethereum_sepolia",label:"Ethereum Sepolia",description:"RPC endpoint URL for Ethereum Sepolia testnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_ethereum_sepolia",keywords:["blockchain","rpc","evm","ethereum","url","endpoint","test"]},{id:"wallets.rpc.evm_polygon_mainnet",label:"Polygon Mainnet",description:"RPC endpoint URL for Polygon mainnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_polygon_mainnet",keywords:["blockchain","rpc","evm","polygon","matic","url","endpoint"]},{id:"wallets.rpc.evm_polygon_amoy",label:"Polygon Amoy",description:"RPC endpoint URL for Polygon Amoy testnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_polygon_amoy",keywords:["blockchain","rpc","evm","polygon","url","endpoint","test"]},{id:"wallets.rpc.evm_arbitrum_mainnet",label:"Arbitrum Mainnet",description:"RPC endpoint URL for Arbitrum mainnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_arbitrum_mainnet",keywords:["blockchain","rpc","evm","arbitrum","l2","url","endpoint"]},{id:"wallets.rpc.evm_arbitrum_sepolia",label:"Arbitrum Sepolia",description:"RPC endpoint URL for Arbitrum Sepolia testnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_arbitrum_sepolia",keywords:["blockchain","rpc","evm","arbitrum","l2","url","endpoint","test"]},{id:"wallets.rpc.evm_optimism_mainnet",label:"Optimism Mainnet",description:"RPC endpoint URL for Optimism mainnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_optimism_mainnet",keywords:["blockchain","rpc","evm","optimism","l2","url","endpoint"]},{id:"wallets.rpc.evm_optimism_sepolia",label:"Optimism Sepolia",description:"RPC endpoint URL for Optimism Sepolia testnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_optimism_sepolia",keywords:["blockchain","rpc","evm","optimism","l2","url","endpoint","test"]},{id:"wallets.rpc.evm_base_mainnet",label:"Base Mainnet",description:"RPC endpoint URL for Base mainnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_base_mainnet",keywords:["blockchain","rpc","evm","base","coinbase","l2","url","endpoint"]},{id:"wallets.rpc.evm_base_sepolia",label:"Base Sepolia",description:"RPC endpoint URL for Base Sepolia testnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_base_sepolia",keywords:["blockchain","rpc","evm","base","coinbase","l2","url","endpoint","test"]},{id:"wallets.rpc.evm_default_network",label:"Default EVM Network",description:"Default EVM network for new wallets",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_default_network",keywords:["blockchain","evm","default","network"]},{id:"wallets.monitoring.enabled",label:"Enabled",description:"Enable or disable balance monitoring",page:"/wallets",tab:"monitoring",fieldName:"monitoring.enabled",keywords:["balance","monitoring","toggle","enable"]},{id:"wallets.monitoring.check_interval_sec",label:"Check Interval (seconds)",description:"How often to check wallet balances",page:"/wallets",tab:"monitoring",fieldName:"monitoring.check_interval_sec",keywords:["balance","monitoring","interval","frequency"]},{id:"wallets.monitoring.low_balance_threshold_sol",label:"Low Balance Threshold (SOL)",description:"Alert when SOL balance drops below this amount",page:"/wallets",tab:"monitoring",fieldName:"monitoring.low_balance_threshold_sol",keywords:["balance","monitoring","threshold","solana","alert","low"]},{id:"wallets.monitoring.low_balance_threshold_eth",label:"Low Balance Threshold (ETH)",description:"Alert when ETH balance drops below this amount",page:"/wallets",tab:"monitoring",fieldName:"monitoring.low_balance_threshold_eth",keywords:["balance","monitoring","threshold","ethereum","alert","low"]},{id:"wallets.monitoring.cooldown_hours",label:"Alert Cooldown (hours)",description:"Suppress duplicate alerts for this many hours",page:"/wallets",tab:"monitoring",fieldName:"monitoring.cooldown_hours",keywords:["balance","monitoring","cooldown","alert","suppress"]},{id:"wallets.walletconnect.project_id",label:"Project ID",description:"WalletConnect Cloud project identifier",page:"/wallets",tab:"walletconnect",fieldName:"walletconnect.project_id",keywords:["walletconnect","project","cloud","dapp"]},{id:"wallets.walletconnect.relay_url",label:"Relay URL",description:"WalletConnect relay server URL",page:"/wallets",tab:"walletconnect",fieldName:"walletconnect.relay_url",keywords:["walletconnect","relay","websocket","server"]},{id:"sessions.settings.session_ttl",label:"Session TTL (seconds)",description:"How long a session token is valid before renewal",page:"/sessions",tab:"settings",fieldName:"security.session_ttl",keywords:["session","ttl","lifetime","expiry","timeout"]},{id:"sessions.settings.session_absolute_lifetime",label:"Absolute Lifetime (seconds)",description:"Maximum total session duration regardless of renewals",page:"/sessions",tab:"settings",fieldName:"security.session_absolute_lifetime",keywords:["session","lifetime","absolute","maximum"]},{id:"sessions.settings.session_max_renewals",label:"Max Renewals",description:"Maximum number of times a session can be renewed",page:"/sessions",tab:"settings",fieldName:"security.session_max_renewals",keywords:["session","renewal","limit","maximum"]},{id:"sessions.settings.max_sessions_per_wallet",label:"Max Sessions per Wallet",description:"Maximum concurrent sessions for a single wallet",page:"/sessions",tab:"settings",fieldName:"security.max_sessions_per_wallet",keywords:["session","limit","concurrent","wallet"]},{id:"sessions.settings.max_pending_tx",label:"Max Pending Transactions",description:"Maximum in-flight transactions per session",page:"/sessions",tab:"settings",fieldName:"security.max_pending_tx",keywords:["transaction","pending","limit","queue"]},{id:"sessions.settings.rate_limit_session_rpm",label:"Session Rate Limit (RPM)",description:"Max requests per minute per session",page:"/sessions",tab:"settings",fieldName:"security.rate_limit_session_rpm",keywords:["rate","limit","rpm","session","throttle"]},{id:"sessions.settings.rate_limit_tx_rpm",label:"Transaction Rate Limit (RPM)",description:"Max transaction requests per minute per session",page:"/sessions",tab:"settings",fieldName:"security.rate_limit_tx_rpm",keywords:["rate","limit","rpm","transaction","throttle"]},{id:"policies.defaults.policy_defaults_delay_seconds",label:"Policy Delay (seconds)",description:"Default delay before executing delayed-tier transactions",page:"/policies",tab:"defaults",fieldName:"security.policy_defaults_delay_seconds",keywords:["policy","delay","default","seconds","timer"]},{id:"policies.defaults.policy_defaults_approval_timeout",label:"Approval Timeout (seconds)",description:"How long to wait for owner approval before timeout",page:"/policies",tab:"defaults",fieldName:"security.policy_defaults_approval_timeout",keywords:["policy","approval","timeout","owner","default"]},{id:"policies.defaults.default_deny_tokens",label:"Default Deny: Token Transfers",description:"Deny token transfers unless a matching whitelist policy exists",page:"/policies",tab:"defaults",fieldName:"policy.default_deny_tokens",keywords:["policy","deny","token","transfer","default","security"]},{id:"policies.defaults.default_deny_contracts",label:"Default Deny: Contract Calls",description:"Deny contract calls unless a matching whitelist policy exists",page:"/policies",tab:"defaults",fieldName:"policy.default_deny_contracts",keywords:["policy","deny","contract","call","default","security"]},{id:"policies.defaults.default_deny_spenders",label:"Default Deny: Token Approvals",description:"Deny token approvals unless a matching whitelist policy exists",page:"/policies",tab:"defaults",fieldName:"policy.default_deny_spenders",keywords:["policy","deny","spender","approval","default","security"]},{id:"notifications.settings.enabled",label:"Enabled",description:"Enable or disable notifications globally",page:"/notifications",tab:"settings",fieldName:"notifications.enabled",keywords:["notifications","enable","toggle","global"]},{id:"notifications.settings.telegram_bot_token",label:"Telegram Bot Token",description:"Bot token for Telegram notifications",page:"/notifications",tab:"settings",fieldName:"notifications.telegram_bot_token",keywords:["telegram","bot","token","notification","credential"]},{id:"notifications.settings.telegram_chat_id",label:"Telegram Chat ID",description:"Chat ID for Telegram notification delivery",page:"/notifications",tab:"settings",fieldName:"notifications.telegram_chat_id",keywords:["telegram","chat","notification"]},{id:"notifications.settings.locale",label:"Locale",description:"Language for notification messages",page:"/notifications",tab:"settings",fieldName:"notifications.locale",keywords:["locale","language","notification","i18n"]},{id:"notifications.settings.discord_webhook_url",label:"Discord Webhook URL",description:"Webhook URL for Discord notifications",page:"/notifications",tab:"settings",fieldName:"notifications.discord_webhook_url",keywords:["discord","webhook","notification","credential"]},{id:"notifications.settings.ntfy_server",label:"Ntfy Server",description:"Server URL for ntfy notifications",page:"/notifications",tab:"settings",fieldName:"notifications.ntfy_server",keywords:["ntfy","server","push","notification"]},{id:"notifications.settings.ntfy_topic",label:"Ntfy Topic",description:"Topic name for ntfy notifications",page:"/notifications",tab:"settings",fieldName:"notifications.ntfy_topic",keywords:["ntfy","topic","push","notification"]},{id:"notifications.settings.slack_webhook_url",label:"Slack Webhook URL",description:"Webhook URL for Slack notifications",page:"/notifications",tab:"settings",fieldName:"notifications.slack_webhook_url",keywords:["slack","webhook","notification","credential"]},{id:"notifications.settings.rate_limit_rpm",label:"Rate Limit (RPM)",description:"Max notifications per minute",page:"/notifications",tab:"settings",fieldName:"notifications.rate_limit_rpm",keywords:["rate","limit","rpm","notification","throttle"]},{id:"notifications.settings.telegram_bot_enabled",label:"Bot Enabled",description:"Enable or disable the Telegram bot",page:"/notifications",tab:"settings",fieldName:"telegram.enabled",keywords:["telegram","bot","enable","toggle"]},{id:"notifications.settings.telegram_dedicated_bot_token",label:"Bot Token",description:"Dedicated bot token for Telegram bot (optional, uses notification token if empty)",page:"/notifications",tab:"settings",fieldName:"telegram.bot_token",keywords:["telegram","bot","token","credential"]},{id:"security.autostop.enabled",label:"Enabled",description:"Enable or disable AutoStop protection rules",page:"/security",tab:"autostop",fieldName:"autostop.enabled",keywords:["autostop","protection","enable","toggle","security"]},{id:"security.autostop.consecutive_failures_threshold",label:"Consecutive Failures Threshold",description:"Suspend wallet after this many consecutive failed transactions",page:"/security",tab:"autostop",fieldName:"autostop.consecutive_failures_threshold",keywords:["autostop","failure","threshold","suspend","security"]},{id:"security.autostop.unusual_activity_threshold",label:"Unusual Activity Threshold",description:"Max transactions within window before triggering unusual activity alert",page:"/security",tab:"autostop",fieldName:"autostop.unusual_activity_threshold",keywords:["autostop","unusual","activity","threshold","security"]},{id:"security.autostop.unusual_activity_window_sec",label:"Unusual Activity Window (seconds)",description:"Time window for unusual activity detection",page:"/security",tab:"autostop",fieldName:"autostop.unusual_activity_window_sec",keywords:["autostop","unusual","activity","window","time","security"]},{id:"security.autostop.idle_timeout_sec",label:"Idle Timeout (seconds)",description:"Revoke sessions with no activity for this duration",page:"/security",tab:"autostop",fieldName:"autostop.idle_timeout_sec",keywords:["autostop","idle","timeout","session","revoke","security"]},{id:"security.autostop.idle_check_interval_sec",label:"Idle Check Interval (seconds)",description:"How often to check for idle sessions",page:"/security",tab:"autostop",fieldName:"autostop.idle_check_interval_sec",keywords:["autostop","idle","check","interval","security"]},{id:"system..currency",label:"Display Currency",description:"Currency for USD amount conversion in dashboard and notifications",page:"/system",tab:"",fieldName:"display.currency",keywords:["currency","display","usd","conversion","fiat"]},{id:"system..rate_limit_global_ip_rpm",label:"Global IP Rate Limit (RPM)",description:"Maximum API requests per minute from a single IP address",page:"/system",tab:"",fieldName:"security.rate_limit_global_ip_rpm",keywords:["rate","limit","rpm","ip","global","throttle"]},{id:"system..log_level",label:"Log Level",description:"Daemon logging verbosity level",page:"/system",tab:"",fieldName:"daemon.log_level",keywords:["log","level","debug","info","warn","error","daemon"]},{id:"system..cross_validation_threshold",label:"Cross Validation Threshold (%)",description:"Maximum allowed deviation between price oracle sources",page:"/system",tab:"",fieldName:"oracle.cross_validation_threshold",keywords:["oracle","price","validation","threshold","deviation"]}],oe=te(""),J=te(null),Sn={"/wallets":"Wallets","/sessions":"Sessions","/policies":"Policies","/notifications":"Notifications","/security":"Security","/system":"System"};function kn(a){if(!a.trim())return[];const t=a.toLowerCase();return wn.filter(n=>[n.label,n.description,n.keywords.join(" ")].join(" ").toLowerCase().includes(t)).slice(0,10)}function Nn(a){const t=Sn[a.page]??a.page;return a.tab?`${t} > ${a.tab}`:t}function Tn({open:a}){const t=v(""),n=v(0),l=Ht(null),i=a.value?kn(t.value):[];if(O(()=>{a.value&&(t.value="",n.value=0,requestAnimationFrame(()=>{l.current?.focus()}))},[a.value]),!a.value)return null;const s=()=>{a.value=!1,t.value="",n.value=0},o=r=>{r.target.classList.contains("search-overlay")&&s()},c=r=>{window.location.hash="#"+r.page,r.tab?J.value={tab:r.tab,fieldName:r.fieldName}:setTimeout(()=>{oe.value=r.fieldName},100),s()};return e("div",{class:"search-overlay",onClick:o,children:e("div",{class:"search-popover",onKeyDown:r=>{if(r.key==="Escape"){s();return}if(r.key==="ArrowDown"){r.preventDefault(),n.value=Math.min(n.value+1,i.length-1);return}if(r.key==="ArrowUp"){r.preventDefault(),n.value=Math.max(n.value-1,0);return}if(r.key==="Enter"&&i.length>0){r.preventDefault(),c(i[n.value]);return}},children:[e("div",{class:"search-input-wrapper",children:e("input",{ref:l,class:"search-input",type:"text",placeholder:"Search settings...",value:t.value,onInput:r=>{t.value=r.target.value,n.value=0}})}),e("div",{class:"search-results",children:[t.value.trim()&&i.length===0&&e("div",{class:"search-empty",children:"No settings found"}),i.map((r,u)=>e("button",{class:`search-result-item${u===n.value?" selected":""}`,onClick:()=>c(r),onMouseEnter:()=>{n.value=u},children:[e("div",{class:"search-result-label",children:r.label}),e("div",{class:"search-result-desc",children:r.description}),e("div",{class:"search-result-path",children:Nn(r)})]},r.id))]}),e("div",{class:"search-hint",children:[e("span",{children:[e("kbd",{children:"Esc"})," close"]}),e("span",{children:[e("kbd",{children:"↑"}),e("kbd",{children:"↓"})," navigate"]}),e("span",{children:[e("kbd",{children:"Enter"})," select"]})]})]})})}const ge=te([]),Va=He(()=>ge.value.some(a=>a.isDirty()));function fe(a){ge.value=[...ge.value.filter(t=>t.id!==a.id),a]}function _e(a){ge.value=ge.value.filter(t=>t.id!==a)}async function Cn(){const a=ge.value.filter(t=>t.isDirty());try{for(const t of a)await t.save();return!0}catch{return!1}}function En(){const a=ge.value.filter(t=>t.isDirty());for(const t of a)t.discard()}function N({label:a,name:t,type:n="text",value:l,onChange:i,options:s,error:o,required:c,disabled:m,placeholder:r,min:u,max:d,description:f}){const p=oe.value===t;if(O(()=>{if(p){const T=document.querySelector(`[name="${t}"]`);T&&T.closest(".form-field")?.scrollIntoView({behavior:"smooth",block:"center"});const k=setTimeout(()=>{oe.value=""},2500);return()=>clearTimeout(k)}},[p,t]),n==="checkbox")return e("div",{class:`form-field${p?" form-field--highlight":""}`,children:[e("label",{children:[e("input",{type:"checkbox",name:t,checked:!!l,onChange:T=>i(T.target.checked),disabled:m}),a,c&&e("span",{children:" *"})]}),f&&e("span",{class:"form-description",children:f}),o&&e("span",{class:"form-error",children:o})]});const b=`field-${t}`;return e("div",{class:`form-field${p?" form-field--highlight":""}`,children:[e("label",{for:b,children:[a,c&&e("span",{children:" *"})]}),n==="select"?e("select",{id:b,name:t,value:l,onChange:T=>i(T.target.value),disabled:m,children:s?.map(T=>e("option",{value:T.value,children:T.label},T.value))}):n==="textarea"?e("textarea",{id:b,name:t,value:l,onInput:T=>i(T.target.value),disabled:m,placeholder:r}):e("input",{id:b,type:n,name:t,value:l,onInput:T=>{const k=T.target;i(n==="number"?Number(k.value):k.value)},disabled:m,placeholder:r,min:u,max:d,required:c}),f&&e("span",{class:"form-description",children:f}),o&&e("span",{class:"form-error",children:o})]})}function E({variant:a="primary",size:t="md",loading:n=!1,disabled:l=!1,onClick:i,children:s,type:o="button"}){const c=["btn",`btn-${a}`,t==="sm"?"btn-sm":""].filter(Boolean).join(" ");return e("button",{type:o,class:c,disabled:l||n,onClick:i,children:n?"...":s})}function P({variant:a,children:t}){return e("span",{class:`badge badge-${a}`,children:t})}const Me=te(null),Pe=te(!1);function za(a){Me.value=a}function An(){const a=Me.value;if(!a)return null;const t=async()=>{Pe.value=!0;const i=await Cn();Pe.value=!1,i&&(Me.value=null,a.execute())},n=()=>{En(),Me.value=null,a.execute()},l=()=>{Me.value=null};return e("div",{class:"modal-overlay",onClick:l,children:e("div",{class:"modal-card",onClick:i=>i.stopPropagation(),children:[e("div",{class:"modal-header",children:"Unsaved Changes"}),e("div",{class:"modal-body",children:e("p",{children:"You have unsaved changes. What would you like to do?"})}),e("div",{class:"modal-footer unsaved-dialog-footer",children:[e(E,{variant:"secondary",onClick:l,disabled:Pe.value,children:"Cancel"}),e(E,{variant:"ghost",onClick:n,disabled:Pe.value,children:"Discard & Navigate"}),e(E,{variant:"primary",onClick:t,loading:Pe.value,children:"Save & Navigate"})]})]})})}class _ extends Error{constructor(t,n,l){super(`[${t}] ${n}: ${l}`),this.status=t,this.code=n,this.serverMessage=l,this.name="ApiError"}}async function ft(a,t){const n={"Content-Type":"application/json",...t?.headers};Ve.value!==null&&(n["X-Master-Password"]=Ve.value);let l;try{l=await fetch(a,{...t,headers:n,signal:AbortSignal.timeout(1e4)})}catch(i){const s=i;throw s.name==="AbortError"||s.name==="TimeoutError"?new _(0,"TIMEOUT","Request timed out"):new _(0,"NETWORK_ERROR","Cannot connect to daemon")}if(l.status===401)throw qt(),new _(401,"INVALID_MASTER_PASSWORD","Authentication failed");if(!l.ok){let i={};try{i=await l.json()}catch{}throw new _(l.status,i.code??"UNKNOWN",i.message??"Unknown error")}return zt(),await l.json()}const B=a=>ft(a,{method:"GET"}),Q=(a,t)=>ft(a,{method:"POST",body:t?JSON.stringify(t):void 0}),le=(a,t)=>ft(a,{method:"PUT",body:t?JSON.stringify(t):void 0}),De=a=>ft(a,{method:"DELETE"});function In(a){const t=Math.floor(a/86400),n=Math.floor(a%86400/3600),l=Math.floor(a%3600/60);return t>0?`${t}d ${n}h ${l}m`:n>0?`${n}h ${l}m`:`${l}m`}function ie(a){const t=new Date(a*1e3),n=l=>l.toString().padStart(2,"0");return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}:${n(t.getMinutes())}`}function Mt(a){return a.length<=10?a:`${a.slice(0,4)}..${a.slice(-4)}`}const Dn=new Set(["KRW","JPY","VND","CLP","HUF","PKR"]),Ln=new Set(["KWD","BHD"]);function On(a){return Dn.has(a)?0:Ln.has(a)?3:2}function xn(a,t,n){const l=a*n,i=On(t),s=new Intl.NumberFormat("en-US",{style:"currency",currency:t,minimumFractionDigits:i,maximumFractionDigits:i}).format(l);return t==="USD"?s:`≈${s}`}let Ne=null;const Rn=300*1e3;async function Pn(){if(Ne&&Date.now()-Ne.fetchedAt<Rn)return{currency:Ne.currency,rate:Ne.rate};try{const t=(await B(C.ADMIN_SETTINGS)).display?.["display.currency"]??"USD";if(t==="USD")return Ne={currency:"USD",rate:1,fetchedAt:Date.now()},{currency:"USD",rate:1};const i=(await B(`${C.ADMIN_FOREX_RATES}?currencies=${t}`)).rates[t]?.rate??null;return Ne={currency:t,rate:i,fetchedAt:Date.now()},{currency:t,rate:i}}catch{return{currency:"USD",rate:1}}}function Wn(a,t,n){return a==null?"":n==null?`$${a.toFixed(2)}`:xn(a,t,n)}function we({columns:a,data:t,onRowClick:n,emptyMessage:l="No data",loading:i=!1}){return e("div",{class:"table-container",children:e("table",{children:[e("thead",{children:e("tr",{children:a.map(s=>e("th",{style:s.width?{width:s.width}:void 0,children:s.header},s.key))})}),e("tbody",{children:i?e("tr",{children:e("td",{colSpan:a.length,class:"table-loading",children:"Loading..."})}):!t||t.length===0?e("tr",{children:e("td",{colSpan:a.length,class:"table-empty",children:l})}):t.map((s,o)=>e("tr",{class:n?"clickable":"",onClick:n?()=>n(s):void 0,children:a.map(c=>e("td",{children:c.render?c.render(s):s[c.key]},c.key))},o))})]})})}const Mn={INVALID_TOKEN:"Your authentication token is invalid. Please log in again.",TOKEN_EXPIRED:"Your session token has expired. Please log in again.",SESSION_REVOKED:"Your session has been revoked by an administrator.",INVALID_SIGNATURE:"The cryptographic signature is invalid.",INVALID_NONCE:"The authentication nonce is invalid or has expired.",INVALID_MASTER_PASSWORD:"Invalid master password. Please try again.",MASTER_PASSWORD_LOCKED:"Master password is locked due to too many failed attempts. Please wait.",SYSTEM_LOCKED:"The system is currently locked.",SESSION_NOT_FOUND:"Session not found.",SESSION_EXPIRED:"The session has expired.",SESSION_LIMIT_EXCEEDED:"Maximum number of sessions reached.",CONSTRAINT_VIOLATED:"A session constraint was violated.",RENEWAL_LIMIT_REACHED:"Session renewal limit has been reached. Create a new session.",SESSION_ABSOLUTE_LIFETIME_EXCEEDED:"Session has exceeded its maximum lifetime.",RENEWAL_TOO_EARLY:"Session renewal attempted too early. Please wait.",SESSION_RENEWAL_MISMATCH:"Session renewal count mismatch. The session may have been renewed elsewhere.",PIPELINE_HALTED:"Transaction is queued for delay or approval.",INSUFFICIENT_BALANCE:"Insufficient balance for this transaction.",INVALID_ADDRESS:"The blockchain address is invalid.",TX_NOT_FOUND:"Transaction not found.",TX_EXPIRED:"The transaction has expired.",TX_ALREADY_PROCESSED:"This transaction has already been processed.",CHAIN_ERROR:"A blockchain network error occurred. Please try again.",SIMULATION_FAILED:"Transaction simulation failed. The transaction may revert.",TOKEN_NOT_FOUND:"Token not found.",TOKEN_NOT_ALLOWED:"This token is not in the allowed list.",INSUFFICIENT_TOKEN_BALANCE:"Insufficient token balance.",CONTRACT_CALL_DISABLED:"Contract calls are disabled. Configure a CONTRACT_WHITELIST policy first.",CONTRACT_NOT_WHITELISTED:"This contract address is not whitelisted.",METHOD_NOT_WHITELISTED:"This contract method is not whitelisted.",APPROVE_DISABLED:"Token approvals are disabled. Configure an APPROVED_SPENDERS policy first.",SPENDER_NOT_APPROVED:"This spender address is not in the approved list.",APPROVE_AMOUNT_EXCEEDED:"The approve amount exceeds the configured limit.",UNLIMITED_APPROVE_BLOCKED:"Unlimited token approvals are blocked by policy.",BATCH_NOT_SUPPORTED:"Batch transactions are not supported on this chain.",BATCH_SIZE_EXCEEDED:"Batch contains too many instructions (maximum 20).",BATCH_POLICY_VIOLATION:"A policy violation occurred in the batch transaction.",POLICY_NOT_FOUND:"Policy not found.",POLICY_DENIED:"Transaction denied by policy.",SPENDING_LIMIT_EXCEEDED:"Spending limit has been exceeded.",RATE_LIMIT_EXCEEDED:"Rate limit exceeded. Please wait before retrying.",WHITELIST_DENIED:"The destination address is not in the whitelist.",OWNER_ALREADY_CONNECTED:"An owner wallet is already connected to this wallet.",OWNER_NOT_CONNECTED:"No owner wallet is connected to this wallet.",OWNER_NOT_FOUND:"Owner not found.",APPROVAL_TIMEOUT:"The approval request has timed out.",APPROVAL_NOT_FOUND:"Approval request not found.",OWNER_NOT_SET:"Owner address must be set before connecting WalletConnect.",OWNER_ADDRESS_MISMATCH:"Connected wallet address does not match registered owner.",KILL_SWITCH_ACTIVE:"Kill switch is active. All operations are suspended.",KILL_SWITCH_NOT_ACTIVE:"Kill switch is not currently active.",KEYSTORE_LOCKED:"The keystore is locked. Please try again.",CHAIN_NOT_SUPPORTED:"This blockchain is not supported.",SHUTTING_DOWN:"The daemon is shutting down.",ADAPTER_NOT_AVAILABLE:"Chain adapter is not available. Please try again.",WALLET_NOT_FOUND:"Wallet not found.",WALLET_SUSPENDED:"This wallet is currently suspended.",WALLET_TERMINATED:"This wallet has been terminated.",WC_NOT_CONFIGURED:"WalletConnect is not configured. Set the Project ID in Settings first.",WC_SESSION_NOT_FOUND:"No active WalletConnect session.",WC_SESSION_EXISTS:"A WalletConnect session already exists. Disconnect first.",WC_SIGNING_FAILED:"WalletConnect signing request failed.",NO_OWNER:"No owner connected. Withdrawal requires an owner wallet.",WITHDRAW_LOCKED_ONLY:"Withdrawal is only available when the owner state is LOCKED.",SWEEP_TOTAL_FAILURE:"All sweep operations failed. Please try again.",INSUFFICIENT_FOR_FEE:"Insufficient balance to cover transaction fees.",ACTION_NOT_FOUND:"Action not found.",ACTION_VALIDATION_FAILED:"Action input validation failed.",ACTION_RESOLVE_FAILED:"Action failed due to an external API error. Please try again.",ACTION_RETURN_INVALID:"Action returned an invalid result.",ACTION_PLUGIN_LOAD_FAILED:"Failed to load the action plugin.",ACTION_NAME_CONFLICT:"An action with this name already exists.",ACTION_CHAIN_MISMATCH:"The request chain does not match the action provider.",ROTATION_TOO_RECENT:"Key rotation was attempted too recently. Please wait.",NETWORK_ERROR:"Cannot connect to the daemon. Check if it is running.",TIMEOUT:"Request timed out. The daemon may be busy."},Un=new Set(["ACTION_VALIDATION_FAILED","CONSTRAINT_VIOLATED","INVALID_ADDRESS","INVALID_SIGNATURE"]);function I(a,t){return t&&Un.has(a)?t:Mn[a]??`An error occurred (${a}).`}const he=te([]);let $n=0;function y(a,t){const n=$n++;he.value=[...he.value,{id:n,type:a,message:t}],setTimeout(()=>{he.value=he.value.filter(l=>l.id!==n)},5e3)}function Kn(a){he.value=he.value.filter(t=>t.id!==a)}function Fn(){return he.value.length===0?null:e("div",{class:"toast-container",children:he.value.map(a=>e("div",{class:`toast toast-${a.type}`,onClick:()=>Kn(a.id),children:a.message},a.id))})}function Bn(a,t){const n=[];return n.push("[WAIaaS Connection]"),n.push(`- URL: ${a}`),n.push(""),n.push("Wallets:"),t.forEach((l,i)=>{n.push(`${i+1}. ${l.name} (${l.id}) — ${l.defaultNetwork}`),n.push(` Session: ${l.sessionToken}`)}),n.push(""),n.push("세션이 만료되면(401 Unauthorized)"),n.push("POST /v1/wallets/{walletId}/sessions/{sessionId}/renew 으로 갱신하세요."),n.push(""),n.push("위 정보로 WAIaaS 지갑에 연결하여 잔액을 확인하고 관리해주세요."),n.join(`
2
2
  `)}function Hn(a,t){const n=[];return n.push("[WAIaaS Connection]"),n.push(`- URL: ${a}`),n.push(""),n.push("Wallets:"),n.push(`1. ${t.name} (${t.id}) — ${t.defaultNetwork}`),n.push(` Session: ${t.sessionToken}`),n.push(""),n.push("세션이 만료되면(401 Unauthorized)"),n.push("POST /v1/wallets/{walletId}/sessions/{sessionId}/renew 으로 갱신하세요."),n.push(""),n.push("위 정보로 WAIaaS 지갑에 연결하여 잔액을 확인하고 관리해주세요."),n.join(`
3
- `)}function ce({label:a,value:t,loading:n,badge:l,href:i}){const s=e(z,{children:[e("div",{class:"stat-label",children:[a,i&&e("span",{class:"stat-link-arrow",children:" →"})]}),n?e("div",{class:"stat-skeleton"}):l?e(P,{variant:l,children:t}):e("div",{class:"stat-value",children:t})]});return i?e("a",{href:i,class:"stat-card stat-card-link",style:{textDecoration:"none",color:"inherit",cursor:"pointer"},children:s}):e("div",{class:"stat-card",children:s})}function Vn(a,t){return[{key:"createdAt",header:"Time",render:n=>n.createdAt?ie(n.createdAt):"—"},{key:"walletName",header:"Wallet",render:n=>n.walletName??n.walletId.slice(0,8)},{key:"type",header:"Type"},{key:"amount",header:"Amount",render:n=>{if(!n.amount)return"—";const l=Wn(n.amountUsd,a,t);return l?`${n.amount} (${l})`:n.amount}},{key:"status",header:"Status",render:n=>{const l=n.status==="CONFIRMED"?"success":n.status==="FAILED"?"danger":"warning";return e(P,{variant:l,children:n.status})}}]}async function zn(a){try{await navigator.clipboard.writeText(a)}catch{const t=document.createElement("textarea");t.value=a,t.style.position="fixed",t.style.left="-9999px",document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)}}function ia(){const a=v(null),t=v(!0),n=v(null),l=v("USD"),i=v(1),s=v(!1),r=async()=>{t.value=!0,n.value=null;try{const o=await B(C.ADMIN_STATUS);a.value=o}catch(o){o instanceof _?n.value=I(o.code):n.value="An unexpected error occurred."}finally{t.value=!1}},c=async()=>{s.value=!0;try{const{items:o}=await B(C.WALLETS),u=o.filter(b=>b.status==="ACTIVE");if(u.length===0){y("warning","No active wallets found");return}const d=[];for(const b of u){const T=await Q(C.SESSIONS,{walletId:b.id,ttl:86400});d.push({id:b.id,name:b.name,chain:b.chain,defaultNetwork:b.network,sessionToken:T.token})}const f=window.location.origin||"http://localhost:3100",p=Bn(f,d);await zn(p),y("success","Agent prompt copied!")}catch(o){o instanceof _?y("error",I(o.code)):y("error","Failed to generate agent prompt")}finally{s.value=!1}};O(()=>{r(),Pn().then(({currency:u,rate:d})=>{l.value=u,i.value=d}).catch(()=>{});const o=setInterval(r,3e4);return()=>clearInterval(o)},[]);const m=t.value&&!a.value;return e("div",{class:"page",children:[n.value&&e("div",{class:"dashboard-error",children:[e("span",{children:n.value}),e(E,{variant:"secondary",size:"sm",onClick:r,children:"Retry"})]}),e("div",{class:"stat-grid",children:[e(ce,{label:"Version",value:a.value?.version??"—",loading:m}),e(ce,{label:"Uptime",value:a.value?In(a.value.uptime):"—",loading:m}),e(ce,{label:"Wallets",value:a.value?.walletCount?.toString()??"—",loading:m,href:"#/wallets"}),e(ce,{label:"Active Sessions",value:a.value?.activeSessionCount?.toString()??"—",loading:m,href:"#/sessions"})]}),e("div",{class:"stat-grid",style:{marginTop:"var(--space-4)"},children:[e(ce,{label:"Kill Switch",value:a.value?.killSwitchState==="ACTIVATED"?"ACTIVATED":"NORMAL",loading:m,badge:a.value?a.value.killSwitchState==="ACTIVATED"?"danger":"success":void 0}),e(ce,{label:"Status",value:a.value?.status??"—",loading:m})]}),e("div",{class:"stat-grid",style:{marginTop:"var(--space-4)"},children:[e(ce,{label:"Policies",value:a.value?.policyCount?.toString()??"—",loading:m,href:"#/policies"}),e(ce,{label:"Recent Txns (24h)",value:a.value?.recentTxCount?.toString()??"—",loading:m}),e(ce,{label:"Failed Txns (24h)",value:a.value?.failedTxCount?.toString()??"—",loading:m,badge:a.value?a.value.failedTxCount===0?"success":"danger":void 0})]}),e("div",{style:{marginTop:"var(--space-4)",display:"flex",justifyContent:"flex-end"},children:e(E,{variant:"secondary",size:"sm",onClick:c,loading:s.value,children:"Copy Agent Prompt"})}),e("div",{style:{marginTop:"var(--space-4)"},children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Recent Activity"}),e(we,{columns:Vn(l.value,i.value),data:a.value?.recentTransactions??[],loading:m,emptyMessage:"No recent transactions"})]})]})}function se({open:a,title:t,children:n,onConfirm:l,onCancel:i,confirmText:s="Confirm",cancelText:r="Cancel",confirmVariant:c="primary",confirmDisabled:m=!1,loading:o=!1}){return O(()=>{if(!a)return;const u=d=>{d.key==="Escape"&&i()};return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[a,i]),a?e("div",{class:"modal-overlay",onClick:i,children:e("div",{class:"modal-card",onClick:u=>u.stopPropagation(),children:[e("div",{class:"modal-header",children:t}),e("div",{class:"modal-body",children:n}),e("div",{class:"modal-footer",children:[e(E,{variant:"secondary",onClick:i,disabled:o,children:r}),l&&e(E,{variant:c,onClick:l,loading:o,disabled:m,children:s})]})]})}):null}function Le({value:a,label:t}){const n=v(!1);return e("button",{class:"btn btn-ghost btn-sm",onClick:async()=>{try{await navigator.clipboard.writeText(a)}catch{const i=document.createElement("textarea");i.value=a,i.style.position="fixed",i.style.left="-9999px",document.body.appendChild(i),i.select(),document.execCommand("copy"),document.body.removeChild(i)}n.value=!0,setTimeout(()=>{n.value=!1},2e3)},children:n.value?"Copied!":t??"Copy"})}function qn({title:a,description:t,actionLabel:n,onAction:l}){return e("div",{class:"empty-state",children:[e("h3",{children:a}),t&&e("p",{children:t}),n&&l&&e("button",{class:"btn btn-primary",onClick:l,children:n})]})}function qe({tabs:a,activeTab:t,onTabChange:n}){return e("div",{class:"tab-nav",children:a.map(l=>e("button",{class:`tab-btn ${t===l.key?"active":""}`,onClick:()=>{l.key!==t&&(Va.value?za({type:"tab",execute:()=>n(l.key)}):n(l.key))},children:l.label},l.key))})}function Ge({pageName:a,tabName:t,onPageClick:n}){return t?e("nav",{class:"breadcrumb","aria-label":"Breadcrumb",children:[e("button",{class:"breadcrumb-page",onClick:n,type:"button",children:a}),e("span",{class:"breadcrumb-separator","aria-hidden":"true",children:">"}),e("span",{class:"breadcrumb-current","aria-current":"page",children:t})]}):null}const Gn=new Set(["notifications.telegram_bot_token","notifications.discord_webhook_url","notifications.slack_webhook_url","telegram.bot_token"]);function jn(a){return Gn.has(a)}function W(a){return{enabled:"Enabled",telegram_bot_token:"Telegram Bot Token",telegram_chat_id:"Telegram Chat ID",discord_webhook_url:"Discord Webhook URL",ntfy_server:"Ntfy Server",ntfy_topic:"Ntfy Topic",locale:"Locale",rate_limit_rpm:"Rate Limit (RPM)",solana_mainnet:"Solana Mainnet",solana_devnet:"Solana Devnet",solana_testnet:"Solana Testnet",evm_ethereum_mainnet:"Ethereum Mainnet",evm_ethereum_sepolia:"Ethereum Sepolia",evm_polygon_mainnet:"Polygon Mainnet",evm_polygon_amoy:"Polygon Amoy",evm_arbitrum_mainnet:"Arbitrum Mainnet",evm_arbitrum_sepolia:"Arbitrum Sepolia",evm_optimism_mainnet:"Optimism Mainnet",evm_optimism_sepolia:"Optimism Sepolia",evm_base_mainnet:"Base Mainnet",evm_base_sepolia:"Base Sepolia",evm_default_network:"Default EVM Network",session_ttl:"Session TTL (seconds)",max_sessions_per_wallet:"Max Sessions per Wallet",max_pending_tx:"Max Pending Transactions",rate_limit_global_ip_rpm:"Global IP Rate Limit (RPM)",rate_limit_session_rpm:"Session Rate Limit (RPM)",rate_limit_tx_rpm:"Transaction Rate Limit (RPM)",policy_defaults_delay_seconds:"Policy Delay (seconds)",policy_defaults_approval_timeout:"Approval Timeout (seconds)",default_deny_tokens:"Default Deny: Token Transfers",default_deny_contracts:"Default Deny: Contract Calls",default_deny_spenders:"Default Deny: Token Approvals",project_id:"Project ID",log_level:"Log Level",currency:"Display Currency",consecutive_failures_threshold:"Consecutive Failures Threshold",unusual_activity_threshold:"Unusual Activity Threshold",unusual_activity_window_sec:"Unusual Activity Window (seconds)",idle_timeout_sec:"Idle Timeout (seconds)",idle_check_interval_sec:"Idle Check Interval (seconds)",check_interval_sec:"Check Interval (seconds)",low_balance_threshold_sol:"Low Balance Threshold (SOL)",low_balance_threshold_eth:"Low Balance Threshold (ETH)",cooldown_hours:"Alert Cooldown (hours)",relay_url:"Relay URL",session_absolute_lifetime:"Absolute Lifetime (seconds)",session_max_renewals:"Max Renewals",bot_token:"Bot Token"}[a]??a.replace(/_/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function U(a,t,n,l){const i=`${n}.${l}`;if(t[i]!==void 0)return t[i];const s=a[n];if(!s)return"";const r=s[l];return typeof r=="boolean"?jn(i)?"":String(r):r??""}function Ae(a,t,n,l){const i=`${n}.${l}`;if(t[i]!==void 0)return t[i]==="true";const s=a[n];if(!s)return!1;const r=s[l];return typeof r=="boolean"?r:r==="true"}function et(a,t,n,l){const i=`${n}.${l}`;if(t[i]!==void 0)return!1;const s=a[n];return s?s[l]===!0:!1}const Yn=[{key:"name",header:"Name"},{key:"chain",header:"Chain"},{key:"environment",header:"Environment",render:a=>e(P,{variant:a.environment==="mainnet"?"warning":"info",children:a.environment})},{key:"publicKey",header:"Public Key",render:a=>e("span",{style:{display:"flex",alignItems:"center",gap:"0.25rem"},children:[Mt(a.publicKey)," ",e(Le,{value:a.publicKey})]})},{key:"status",header:"Status",render:a=>e(P,{variant:a.status==="ACTIVE"?"success":"danger",children:a.status})},{key:"ownerState",header:"Owner",render:a=>e(P,{variant:qa(a.ownerState),children:a.ownerState})},{key:"createdAt",header:"Created",render:a=>ie(a.createdAt)}];function qa(a){switch(a){case"NONE":return"neutral";case"GRACE":return"warning";case"LOCKED":return"success";default:return"neutral"}}function Z({label:a,value:t,copy:n,children:l}){return e("div",{class:"detail-row",children:[e("div",{class:"detail-row-label",children:a}),e("div",{class:"detail-row-value",children:[l??t??"—",n&&t&&e(Le,{value:t})]})]})}function Jn({id:a}){const t=v(null),n=v(!0),l=v(!1),i=v(""),s=v(!1),r=v(!1),c=v(!1),m=v(!1),o=v(null),u=v([]),d=v(!0),f=v(!1),p=v(null),b=v(!0),T=v([]),S=v(!0),D=v(!1),L=v(null),M=v(!1),F=v(null),k=v(!0),x=v(!1),R=v(null),j=v(!1),q=v(""),X=v(!1),G=v(!1),h=async()=>{try{const w=await B(C.WALLET(a));t.value=w}catch(w){const V=w instanceof _?w:new _(0,"UNKNOWN","Unknown error");y("error",I(V.code))}finally{n.value=!1}},A=async()=>{s.value=!0;try{const w=await le(C.WALLET(a),{name:i.value});t.value=w,l.value=!1,y("success","Wallet name updated")}catch(w){const V=w instanceof _?w:new _(0,"UNKNOWN","Unknown error");y("error",I(V.code))}finally{s.value=!1}},ae=async()=>{c.value=!0;try{await De(C.WALLET(a)),y("success","Wallet terminated"),window.location.hash="#/wallets"}catch(w){const V=w instanceof _?w:new _(0,"UNKNOWN","Unknown error");y("error",I(V.code))}finally{c.value=!1}},_t=()=>{i.value=t.value.name,l.value=!0},Se=()=>{l.value=!1},je=async()=>{m.value=!0;try{const w=await Q(C.MCP_TOKENS,{walletId:a});o.value=w,y("success","MCP token provisioned successfully")}catch(w){const V=w instanceof _?w:new _(0,"UNKNOWN","Unknown error");y("error",I(V.code))}finally{m.value=!1}},Ye=async()=>{d.value=!0;try{const w=await B(C.WALLET_NETWORKS(a));u.value=w.availableNetworks??[]}catch(w){const V=w instanceof _?w:new _(0,"UNKNOWN","Unknown error");y("error",I(V.code)),u.value=[]}finally{d.value=!1}},yt=async()=>{b.value=!0;try{p.value=await B(C.ADMIN_WALLET_BALANCE(a))}catch{p.value=null}finally{b.value=!1}},gt=async()=>{S.value=!0;try{const w=await B(C.ADMIN_WALLET_TRANSACTIONS(a));T.value=w.items}catch{T.value=[]}finally{S.value=!1}},bt=async()=>{k.value=!0;try{F.value=await B(C.WALLET_WC_SESSION(a))}catch{F.value=null}finally{k.value=!1}},wt=()=>{R.value&&clearInterval(R.value),R.value=setInterval(async()=>{try{const w=await B(C.WALLET_WC_PAIR_STATUS(a));w.status==="connected"?(R.value&&clearInterval(R.value),R.value=null,D.value=!1,L.value=null,F.value=w.session??null,y("success","Wallet connected via WalletConnect")):(w.status==="expired"||w.status==="none")&&(R.value&&clearInterval(R.value),R.value=null,D.value=!1,L.value=null,y("error","Pairing expired. Try again."))}catch{}},3e3)},St=async()=>{M.value=!0;try{const w=await Q(C.WALLET_WC_PAIR(a));L.value=w,D.value=!0,wt()}catch(w){const V=w instanceof _?w:new _(0,"UNKNOWN","Unknown error");V.code==="WC_NOT_CONFIGURED"?(y("error","WalletConnect is not configured. Redirecting to settings..."),J.value={tab:"walletconnect",fieldName:"walletconnect.project_id"},window.location.hash="#/wallets"):y("error",I(V.code))}finally{M.value=!1}},kt=async()=>{x.value=!0;try{await De(C.WALLET_WC_SESSION(a)),F.value=null,y("success","WalletConnect session disconnected")}catch(w){const V=w instanceof _?w:new _(0,"UNKNOWN","Unknown error");y("error",I(V.code))}finally{x.value=!1}},Je=()=>{q.value=t.value?.ownerAddress??"",j.value=!0},g=()=>{j.value=!1},H=async()=>{if(!q.value.trim()){y("error","Owner address is required");return}X.value=!0;try{await le(C.WALLET_OWNER(a),{owner_address:q.value.trim()}),await h(),j.value=!1,y("success","Owner address updated")}catch(w){const V=w instanceof _?w:new _(0,"UNKNOWN","Unknown error");y("error",I(V.code,V.serverMessage))}finally{X.value=!1}},oe=async w=>{f.value=!0;try{await le(C.WALLET_DEFAULT_NETWORK(a),{network:w}),y("success",`Default network changed to ${w}`),await h(),await Ye()}catch(V){const Xe=V instanceof _?V:new _(0,"UNKNOWN","Unknown error");y("error",I(Xe.code))}finally{f.value=!1}},ja=async()=>{if(t.value){G.value=!0;try{const w=await Q(C.SESSIONS,{walletId:a,ttl:86400}),V=window.location.origin||"http://localhost:3100",Xe=Hn(V,{id:t.value.id,name:t.value.name,chain:t.value.chain,defaultNetwork:t.value.defaultNetwork??t.value.network,sessionToken:w.token});try{await navigator.clipboard.writeText(Xe)}catch{const ke=document.createElement("textarea");ke.value=Xe,ke.style.position="fixed",ke.style.left="-9999px",document.body.appendChild(ke),ke.select(),document.execCommand("copy"),document.body.removeChild(ke)}y("success","Agent prompt copied!")}catch(w){w instanceof _?y("error",I(w.code)):y("error","Failed to generate agent prompt")}finally{G.value=!1}}};return O(()=>{h(),Ye(),yt(),gt(),bt()},[a]),O(()=>()=>{R.value&&clearInterval(R.value)},[]),e("div",{class:"page",children:[e("a",{href:"#/wallets",class:"back-link",children:"← Back to Wallets"}),n.value?e("div",{class:"stat-skeleton",style:{height:"200px",marginTop:"var(--space-4)"}}):t.value?e("div",{class:"wallet-detail",children:[e("div",{class:"detail-header",children:[e("div",{class:"detail-name",children:l.value?e("div",{class:"inline-edit",children:[e("input",{value:i.value,onInput:w=>{i.value=w.target.value},class:"inline-edit-input"}),e(E,{size:"sm",onClick:A,loading:s.value,children:"Save"}),e(E,{size:"sm",variant:"secondary",onClick:Se,children:"Cancel"})]}):e("span",{children:[t.value.name,e("button",{class:"btn btn-ghost btn-sm",onClick:_t,title:"Edit name",children:"✎"})]})}),e("div",{style:{display:"flex",gap:"var(--space-2)"},children:[e(E,{variant:"secondary",size:"sm",onClick:ja,loading:G.value,children:"Copy Agent Prompt"}),e(E,{variant:"danger",onClick:()=>{r.value=!0},children:"Terminate Wallet"})]})]}),e("div",{class:"detail-grid",children:[e(Z,{label:"ID",value:t.value.id,copy:!0}),e(Z,{label:"Public Key",value:t.value.publicKey,copy:!0}),e(Z,{label:"Chain",value:t.value.chain}),e(Z,{label:"Environment",children:e(P,{variant:t.value.environment==="mainnet"?"warning":"info",children:t.value.environment})}),e(Z,{label:"Default Network",value:t.value.defaultNetwork??t.value.network}),e(Z,{label:"Status",children:e(P,{variant:t.value.status==="ACTIVE"?"success":"danger",children:t.value.status})}),e(Z,{label:"Created",value:ie(t.value.createdAt)}),e(Z,{label:"Updated",value:t.value.updatedAt?ie(t.value.updatedAt):"Never"})]}),e("div",{class:"balance-section",style:{marginTop:"var(--space-6)"},children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Balances"}),b.value?e("div",{class:"stat-skeleton",style:{height:"60px"}}):p.value?.balances?.length?e("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-3)"},children:p.value.balances.map(w=>e("div",{style:{padding:"var(--space-3)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",background:w.isDefault?"var(--color-bg-secondary)":"transparent"},children:[e("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)",marginBottom:"var(--space-2)"},children:[e("strong",{children:w.network}),w.isDefault&&e("span",{class:"badge badge-info",style:{fontSize:"0.7rem"},children:"Default"})]}),w.error?e("p",{style:{color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:w.error}):w.native?e("div",{children:[e(Z,{label:"Native",value:`${w.native.balance} ${w.native.symbol}`}),w.tokens.length>0?w.tokens.map(V=>e(Z,{label:V.symbol,value:V.balance},V.address)):null]}):e("p",{style:{color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:"Balance unavailable"})]},w.network))}):e("p",{style:{color:"var(--color-text-secondary)"},children:"No balance data available"})]}),e("div",{class:"networks-section",style:{marginTop:"var(--space-6)"},children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Available Networks"}),d.value?e("div",{class:"stat-skeleton",style:{height:"80px"}}):e("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-2)"},children:(u.value??[]).map(w=>e("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"var(--space-2) var(--space-3)",background:"var(--color-bg-secondary)",borderRadius:"var(--radius-md)"},children:[e("span",{children:[w.name??w.network,w.isDefault&&e(P,{variant:"success",style:{marginLeft:"var(--space-2)"},children:"Default"})]}),!w.isDefault&&t.value?.status==="ACTIVE"&&e(E,{size:"sm",variant:"secondary",onClick:()=>oe(w.network),loading:f.value,children:"Set Default"})]},w.network))})]}),e("div",{class:"transactions-section",style:{marginTop:"var(--space-6)"},children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Recent Transactions"}),e(we,{columns:[{key:"createdAt",header:"Time",render:w=>w.createdAt?ie(w.createdAt):"--"},{key:"type",header:"Type",render:w=>w.type},{key:"toAddress",header:"To",render:w=>w.toAddress?Mt(w.toAddress):"--"},{key:"amount",header:"Amount",render:w=>w.amount??"--"},{key:"status",header:"Status",render:w=>e(P,{variant:w.status==="CONFIRMED"?"success":w.status==="FAILED"?"danger":"warning",children:w.status})},{key:"network",header:"Network",render:w=>w.network??"--"}],data:T.value,loading:S.value,emptyMessage:"No transactions yet"})]}),e("div",{class:"owner-section",style:{marginTop:"var(--space-6)"},children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Owner Wallet"}),t.value.ownerState==="NONE"&&t.value.status!=="TERMINATED"&&e("div",{style:{background:"var(--color-bg-secondary)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",padding:"var(--space-3) var(--space-4)",marginBottom:"var(--space-4)"},children:[e("p",{style:{marginBottom:"var(--space-2)",fontWeight:500},children:"What is an Owner Wallet?"}),e("p",{style:{color:"var(--color-text-secondary)",fontSize:"0.85rem",marginBottom:"var(--space-3)"},children:"Register an Owner wallet to enable transaction approval (APPROVAL policy) for high-value transfers. Connect D'CENT, MetaMask, or other WalletConnect-compatible wallets to approve transactions directly."}),e(E,{size:"sm",onClick:Je,children:"Set Owner Address"})]}),e(Z,{label:"Address",children:j.value?e("div",{class:"inline-edit",children:[e("input",{value:q.value,onInput:w=>{q.value=w.target.value},class:"inline-edit-input",placeholder:"Enter owner wallet address"}),e(E,{size:"sm",onClick:H,loading:X.value,children:"Save"}),e(E,{size:"sm",variant:"secondary",onClick:g,children:"Cancel"})]}):e("span",{children:[t.value.ownerAddress?e(z,{children:[Mt(t.value.ownerAddress),e(Le,{value:t.value.ownerAddress})]}):"Not set",t.value.ownerState!=="LOCKED"&&t.value.status==="ACTIVE"&&e("button",{class:"btn btn-ghost btn-sm",onClick:Je,title:"Set owner address",children:"✎"})]})}),e(Z,{label:"State",children:e(P,{variant:qa(t.value.ownerState),children:t.value.ownerState})}),t.value.ownerState==="GRACE"&&e("div",{style:{background:"var(--color-bg-secondary)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",padding:"var(--space-3) var(--space-4)",marginTop:"var(--space-3)"},children:[e("p",{style:{marginBottom:"var(--space-2)",fontWeight:500,fontSize:"0.85rem"},children:"Verify Owner"}),e("p",{style:{color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:"Sign a verification message with the Owner wallet to transition from GRACE to LOCKED. Connect via WalletConnect first, then trigger an APPROVAL-tier transaction or use the CLI/SDK to call the verify endpoint."})]}),e("div",{style:{marginTop:"var(--space-4)",paddingTop:"var(--space-3)",borderTop:"1px solid var(--color-border)"},children:[e("h4",{style:{marginBottom:"var(--space-2)",fontSize:"0.9rem"},children:"WalletConnect"}),k.value?e("div",{class:"stat-skeleton",style:{height:"60px"}}):F.value?e("div",{children:[e(Z,{label:"Status",children:e(P,{variant:"success",children:"Connected"})}),e(Z,{label:"Peer",value:F.value.peerName??"Unknown"}),e(Z,{label:"Chain ID",value:F.value.chainId}),e(Z,{label:"Expires",value:ie(F.value.expiry)}),e("div",{style:{marginTop:"var(--space-3)"},children:e(E,{variant:"danger",onClick:kt,loading:x.value,children:"Disconnect"})})]}):e("div",{children:[e("p",{style:{marginBottom:"var(--space-3)",color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:"Connect an external wallet (D'CENT, MetaMask, Phantom) via WalletConnect for transaction approval."}),t.value?.ownerAddress?e(E,{onClick:St,loading:M.value,children:"Connect Wallet"}):e("p",{style:{color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:"Set an Owner address first to enable WalletConnect."})]})]})]}),e("div",{class:"mcp-setup-section",style:{marginTop:"var(--space-6)"},children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"MCP Setup"}),o.value?e("div",{children:[e("div",{class:"detail-grid",style:{marginBottom:"var(--space-4)"},children:[e(Z,{label:"Token Path",value:o.value.tokenPath}),e(Z,{label:"Expires At",value:ie(o.value.expiresAt)})]}),e("div",{style:{marginBottom:"var(--space-2)"},children:e("strong",{children:"Claude Desktop Config"})}),e("div",{style:{position:"relative"},children:[e("pre",{children:e("code",{style:{display:"block",whiteSpace:"pre-wrap",wordBreak:"break-all",background:"var(--color-bg-secondary)",padding:"var(--space-3)",borderRadius:"var(--radius-md)",fontSize:"0.85rem",maxHeight:"300px",overflow:"auto"},children:JSON.stringify({mcpServers:o.value.claudeDesktopConfig},null,2)})}),e("div",{style:{marginTop:"var(--space-2)"},children:e(Le,{value:JSON.stringify({mcpServers:o.value.claudeDesktopConfig},null,2),label:"Copy Config"})})]}),e("div",{style:{marginTop:"var(--space-3)"},children:e(E,{variant:"secondary",onClick:je,loading:m.value,children:"Re-provision"})})]}):e("div",{children:[e("p",{style:{marginBottom:"var(--space-3)",color:"var(--color-text-secondary)"},children:"Provision an MCP token for Claude Desktop integration."}),e(E,{onClick:je,loading:m.value,children:"Setup MCP"})]})]}),e(se,{open:r.value,title:"Terminate Wallet",onCancel:()=>{r.value=!1},onConfirm:ae,confirmText:"Terminate",confirmVariant:"danger",loading:c.value,children:e("p",{children:["Are you sure you want to terminate wallet ",e("strong",{children:t.value.name}),"? This action cannot be undone."]})}),e(se,{open:D.value,title:"Scan QR Code",onCancel:()=>{D.value=!1,R.value&&clearInterval(R.value),R.value=null},children:L.value&&e("div",{style:{textAlign:"center"},children:[e("img",{src:L.value.qrCode,alt:"WalletConnect QR Code",style:{width:"280px",height:"280px",margin:"0 auto"}}),e("p",{style:{marginTop:"var(--space-3)",color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:"Scan with D'CENT, MetaMask, Phantom, or any WalletConnect-compatible wallet"}),e("p",{style:{marginTop:"var(--space-2)",color:"var(--color-text-secondary)",fontSize:"0.75rem"},children:"Waiting for connection..."})]})})]}):e(qn,{title:"Wallet not found",description:"The wallet may have been deleted."})]})}const Xn=["solana_mainnet","solana_devnet","solana_testnet"],Zn=["evm_ethereum_mainnet","evm_ethereum_sepolia","evm_polygon_mainnet","evm_polygon_amoy","evm_arbitrum_mainnet","evm_arbitrum_sepolia","evm_optimism_mainnet","evm_optimism_sepolia","evm_base_mainnet","evm_base_sepolia"],Qn={solana_mainnet:"RPC endpoint URL for Solana mainnet",solana_devnet:"RPC endpoint URL for Solana devnet",solana_testnet:"RPC endpoint URL for Solana testnet",evm_ethereum_mainnet:"RPC endpoint URL for Ethereum mainnet",evm_ethereum_sepolia:"RPC endpoint URL for Ethereum Sepolia testnet",evm_polygon_mainnet:"RPC endpoint URL for Polygon mainnet",evm_polygon_amoy:"RPC endpoint URL for Polygon Amoy testnet",evm_arbitrum_mainnet:"RPC endpoint URL for Arbitrum mainnet",evm_arbitrum_sepolia:"RPC endpoint URL for Arbitrum Sepolia testnet",evm_optimism_mainnet:"RPC endpoint URL for Optimism mainnet",evm_optimism_sepolia:"RPC endpoint URL for Optimism Sepolia testnet",evm_base_mainnet:"RPC endpoint URL for Base mainnet",evm_base_sepolia:"RPC endpoint URL for Base Sepolia testnet"},sa={enabled:"Enable or disable balance monitoring",check_interval_sec:"How often to check wallet balances",low_balance_threshold_sol:"Alert when SOL balance drops below this amount",low_balance_threshold_eth:"Alert when ETH balance drops below this amount",cooldown_hours:"Suppress duplicate alerts for this many hours"},el=[{label:"Ethereum Mainnet",value:"ethereum-mainnet"},{label:"Ethereum Sepolia",value:"ethereum-sepolia"},{label:"Polygon Mainnet",value:"polygon-mainnet"},{label:"Polygon Amoy",value:"polygon-amoy"},{label:"Arbitrum Mainnet",value:"arbitrum-mainnet"},{label:"Arbitrum Sepolia",value:"arbitrum-sepolia"},{label:"Optimism Mainnet",value:"optimism-mainnet"},{label:"Optimism Sepolia",value:"optimism-sepolia"},{label:"Base Mainnet",value:"base-mainnet"},{label:"Base Sepolia",value:"base-sepolia"}];function tl(){const a=v({}),t=v({}),n=v(!1),l=v(!0),i=v({}),s=v({}),r=async()=>{try{const p=await B(C.ADMIN_SETTINGS);a.value=p}catch(p){const b=p instanceof _?p:new _(0,"UNKNOWN","Unknown error");y("error",I(b.code))}finally{l.value=!1}};O(()=>{r()},[]);const c=(p,b)=>{const T=String(b);t.value={...t.value,[p]:T}},m=async()=>{n.value=!0;try{const p=Object.entries(t.value).filter(([b])=>b.startsWith("rpc.")).map(([b,T])=>({key:b,value:T}));await le(C.ADMIN_SETTINGS,{settings:p}),t.value={},await r(),y("success","Settings saved and applied")}catch(p){const b=p instanceof _?p:new _(0,"UNKNOWN","Unknown error");y("error",I(b.code))}finally{n.value=!1}},o=()=>{t.value={}};O(()=>(fe({id:"wallets-rpc",isDirty:()=>Object.keys(t.value).filter(p=>p.startsWith("rpc.")).length>0,save:m,discard:o}),()=>_e("wallets-rpc")),[]);const u=async p=>{const b=p.split(".")[1]??"",T=U(a.value,t.value,"rpc",b);if(!T){y("warning","Enter a URL before testing");return}const S=b.startsWith("solana")?"solana":"evm";s.value={...s.value,[p]:!0};try{const D=await Q(C.ADMIN_SETTINGS_TEST_RPC,{url:T,chain:S});i.value={...i.value,[p]:D}}catch{i.value={...i.value,[p]:{success:!1,latencyMs:0,error:"Request failed"}}}finally{s.value={...s.value,[p]:!1}}};function d({shortKey:p}){const b=`rpc.${p}`,T=i.value[b],S=s.value[b];return e("div",{class:"settings-field-full",children:[e("div",{class:"rpc-field-row",children:[e(N,{label:W(p),name:b,type:"text",value:U(a.value,t.value,"rpc",p),onChange:D=>c(b,D),placeholder:"https://...",description:Qn[p]}),e(E,{variant:"ghost",size:"sm",onClick:()=>u(b),loading:!!S,children:"Test"})]}),T&&e("div",{class:`rpc-test-result ${T.success?"rpc-test-result--success":"rpc-test-result--failure"}`,children:[e(P,{variant:T.success?"success":"danger",children:T.success?"OK":"FAIL"}),e("span",{children:[T.latencyMs,"ms"]}),T.blockNumber!==void 0&&e("span",{children:[" (block #",T.blockNumber.toLocaleString(),")"]}),T.error&&e("span",{children:[" - ",T.error]})]})]})}const f=Object.keys(t.value).filter(p=>p.startsWith("rpc.")).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(z,{children:[f>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[f," unsaved change",f>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(E,{variant:"ghost",size:"sm",onClick:o,children:"Discard"}),e(E,{variant:"primary",size:"sm",onClick:m,loading:n.value,children:"Save"})]})]}),e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"RPC Endpoints"}),e("p",{class:"settings-description",children:"Configure blockchain RPC URLs for Solana and EVM networks"})]}),e("div",{class:"settings-category-body",children:[e("div",{class:"settings-subgroup",children:[e("div",{class:"settings-subgroup-title",children:"Solana"}),e("div",{class:"settings-fields-grid",children:Xn.map(p=>e(d,{shortKey:p},p))})]}),e("div",{class:"settings-subgroup",children:[e("div",{class:"settings-subgroup-title",children:"EVM"}),e("div",{class:"settings-fields-grid",children:[Zn.map(p=>e(d,{shortKey:p},p)),e("div",{class:"settings-field-full",children:e(N,{label:W("evm_default_network"),name:"rpc.evm_default_network",type:"select",value:U(a.value,t.value,"rpc","evm_default_network")||"ethereum-sepolia",onChange:p=>c("rpc.evm_default_network",p),options:el,description:"Default EVM network for new wallets"})})]})]})]})]})]})}function al(){const a=v({}),t=v({}),n=v(!1),l=v(!0),i=async()=>{try{const u=await B(C.ADMIN_SETTINGS);a.value=u}catch(u){const d=u instanceof _?u:new _(0,"UNKNOWN","Unknown error");y("error",I(d.code))}finally{l.value=!1}};O(()=>{i()},[]);const s=(u,d)=>{const f=String(d);t.value={...t.value,[u]:f}},r=async()=>{n.value=!0;try{const u=Object.entries(t.value).filter(([d])=>d.startsWith("monitoring.")).map(([d,f])=>({key:d,value:f}));await le(C.ADMIN_SETTINGS,{settings:u}),t.value={},await i(),y("success","Settings saved and applied")}catch(u){const d=u instanceof _?u:new _(0,"UNKNOWN","Unknown error");y("error",I(d.code))}finally{n.value=!1}},c=()=>{t.value={}};O(()=>(fe({id:"wallets-monitoring",isDirty:()=>Object.keys(t.value).filter(u=>u.startsWith("monitoring.")).length>0,save:r,discard:c}),()=>_e("wallets-monitoring")),[]);const m=[{key:"enabled",type:"checkbox"},{key:"check_interval_sec",type:"number",min:60,max:86400},{key:"low_balance_threshold_sol",type:"number",min:0},{key:"low_balance_threshold_eth",type:"number",min:0},{key:"cooldown_hours",type:"number",min:1,max:168}],o=Object.keys(t.value).filter(u=>u.startsWith("monitoring.")).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(z,{children:[o>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[o," unsaved change",o>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(E,{variant:"ghost",size:"sm",onClick:c,children:"Discard"}),e(E,{variant:"primary",size:"sm",onClick:r,loading:n.value,children:"Save"})]})]}),e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Balance Monitoring"}),e("p",{class:"settings-description",children:"Periodic balance checks for all active wallets. Sends LOW_BALANCE alerts when native token balance drops below thresholds. Changes apply immediately."})]}),e("div",{class:"settings-category-body",children:[e("div",{class:"settings-fields-grid",children:m.map(u=>u.type==="checkbox"?e("div",{class:"settings-field-full",children:e(N,{label:W(u.key),name:`monitoring.${u.key}`,type:"checkbox",value:Ae(a.value,t.value,"monitoring",u.key),onChange:d=>s(`monitoring.${u.key}`,d),description:sa[u.key]})},u.key):e(N,{label:W(u.key),name:`monitoring.${u.key}`,type:"number",value:Number(U(a.value,t.value,"monitoring",u.key))||0,onChange:d=>s(`monitoring.${u.key}`,d),min:u.min,max:u.max,description:sa[u.key]},u.key))}),e("div",{class:"settings-info-box",children:"Monitors all active wallet native token balances (SOL, ETH) at the configured interval. When balance drops below threshold, a LOW_BALANCE notification is sent. Duplicate alerts are suppressed for the cooldown period (per wallet)."})]})]})]})}function nl(){const a=v({}),t=v({}),n=v(!1),l=v(!0),i=async()=>{try{const o=await B(C.ADMIN_SETTINGS);a.value=o}catch(o){const u=o instanceof _?o:new _(0,"UNKNOWN","Unknown error");y("error",I(u.code))}finally{l.value=!1}};O(()=>{i()},[]);const s=(o,u)=>{const d=String(u);t.value={...t.value,[o]:d}},r=async()=>{n.value=!0;try{const o=Object.entries(t.value).filter(([u])=>u.startsWith("walletconnect.")).map(([u,d])=>({key:u,value:d}));await le(C.ADMIN_SETTINGS,{settings:o}),t.value={},await i(),y("success","Settings saved and applied")}catch(o){const u=o instanceof _?o:new _(0,"UNKNOWN","Unknown error");y("error",I(u.code))}finally{n.value=!1}},c=()=>{t.value={}};O(()=>(fe({id:"wallets-walletconnect",isDirty:()=>Object.keys(t.value).filter(o=>o.startsWith("walletconnect.")).length>0,save:r,discard:c}),()=>_e("wallets-walletconnect")),[]);const m=Object.keys(t.value).filter(o=>o.startsWith("walletconnect.")).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(z,{children:[m>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[m," unsaved change",m>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(E,{variant:"ghost",size:"sm",onClick:c,children:"Discard"}),e(E,{variant:"primary",size:"sm",onClick:r,loading:n.value,children:"Save"})]})]}),e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"WalletConnect"}),e("p",{class:"settings-description",children:"WalletConnect integration for dApp connections"})]}),e("div",{class:"settings-category-body",children:[e("div",{class:"settings-fields-grid",children:[e("div",{class:"settings-field-full",children:e(N,{label:W("project_id"),name:"walletconnect.project_id",type:"text",value:U(a.value,t.value,"walletconnect","project_id"),onChange:o=>s("walletconnect.project_id",o),description:"WalletConnect Cloud project identifier"})}),e("div",{class:"settings-field-full",children:e(N,{label:W("relay_url"),name:"walletconnect.relay_url",type:"text",value:U(a.value,t.value,"walletconnect","relay_url"),onChange:o=>s("walletconnect.relay_url",o),placeholder:"wss://relay.walletconnect.com",description:"WalletConnect relay server URL"})})]}),e("div",{class:"settings-info-box",children:["Get your project ID from"," ",e("a",{href:"https://cloud.walletconnect.com",target:"_blank",rel:"noopener noreferrer",children:"https://cloud.walletconnect.com"})," ","— Create a free account and project to obtain your project ID."]}),e("div",{class:"settings-info-box",children:"Relay URL defaults to wss://relay.walletconnect.com if not set."})]})]})]})}function ll(){const a=v([]),t=v(!0),n=v(!1),l=v(""),i=v("solana"),s=v("testnet"),r=v(null),c=v(!1),m=v(null),o=async()=>{try{const p=await B(C.WALLETS);a.value=p.items}catch(p){const b=p instanceof _?p:new _(0,"UNKNOWN","Unknown error");y("error",I(b.code))}finally{t.value=!1}},u=async()=>{if(!l.value.trim()){r.value="Name is required";return}r.value=null,c.value=!0;try{const p=await Q(C.WALLETS,{name:l.value.trim(),chain:i.value,environment:s.value});p.session?.token?(m.value=p.session.token,y("success","Wallet created with session")):y("success","Wallet created"),l.value="",i.value="solana",s.value="testnet",n.value=!1,t.value=!0,await o()}catch(p){const b=p instanceof _?p:new _(0,"UNKNOWN","Unknown error");r.value=I(b.code)}finally{c.value=!1}},d=p=>{window.location.hash="#/wallets/"+p.id},f=p=>{i.value=p};return O(()=>{o()},[]),e(z,{children:[e("div",{class:"page-actions",children:!n.value&&e(E,{onClick:()=>{n.value=!0},children:"Create Wallet"})}),n.value&&e("div",{class:"inline-form",children:[e(N,{label:"Name",name:"name",value:l.value,onChange:p=>{l.value=p},required:!0,placeholder:"e.g. trading-bot",error:r.value??void 0}),e(N,{label:"Chain",name:"chain",type:"select",value:i.value,onChange:f,options:[{label:"Solana",value:"solana"},{label:"Ethereum",value:"ethereum"}]}),e(N,{label:"Environment",name:"environment",type:"select",value:s.value,onChange:p=>{s.value=p},options:[{label:"Testnet",value:"testnet"},{label:"Mainnet",value:"mainnet"}]}),e("div",{class:"inline-form-actions",children:[e(E,{onClick:u,loading:c.value,children:"Create"}),e(E,{variant:"secondary",onClick:()=>{n.value=!1,r.value=null},children:"Cancel"})]})]}),m.value&&e("div",{class:"inline-form",style:{marginBottom:"1rem"},children:[e("div",{style:{fontWeight:"bold",marginBottom:"0.5rem"},children:"Session Token (copy now — shown only once)"}),e("div",{style:{display:"flex",gap:"0.5rem",alignItems:"center"},children:[e("input",{type:"text",readOnly:!0,value:m.value,style:{flex:1,fontFamily:"monospace",fontSize:"0.85rem",padding:"0.5rem"},onClick:p=>p.target.select()}),e(E,{variant:"secondary",onClick:()=>{navigator.clipboard.writeText(m.value),y("success","Token copied")},children:"Copy"}),e(E,{variant:"secondary",onClick:()=>{m.value=null},children:"Dismiss"})]})]}),e(we,{columns:Yn,data:a.value,loading:t.value,onRowClick:d,emptyMessage:"No wallets yet"})]})}const oa=[{key:"wallets",label:"Wallets"},{key:"rpc",label:"RPC Endpoints"},{key:"monitoring",label:"Balance Monitoring"},{key:"walletconnect",label:"WalletConnect"}];function il(){const a=v("wallets");return O(()=>{const t=J.value;t&&t.tab&&(a.value=t.tab,setTimeout(()=>{re.value=t.fieldName},100),J.value=null)},[J.value]),e("div",{class:"page",children:[e(Ge,{pageName:"Wallets",tabName:oa.find(t=>t.key===a.value)?.label??"",onPageClick:()=>{a.value="wallets"}}),e(qe,{tabs:oa,activeTab:a.value,onTabChange:t=>{a.value=t}}),a.value==="wallets"&&e(ll,{}),a.value==="rpc"&&e(tl,{}),a.value==="monitoring"&&e(al,{}),a.value==="walletconnect"&&e(nl,{})]})}function ra(){const a=ve.value,t=a.startsWith("/wallets/")?a.slice(9):null;return t?e(Jn,{id:t}):e(il,{})}function Oe({legend:a,children:t,description:n}){return e("fieldset",{class:"field-group",children:[e("legend",{class:"field-group-legend",children:a}),n&&e("p",{class:"field-group-description",children:n}),e("div",{class:"field-group-body",children:t})]})}function sl(a,t,n){t.value=a,n.value=!0}const ca=[{key:"sessions",label:"Sessions"},{key:"settings",label:"Settings"}],Tt=["security.session_ttl","security.session_absolute_lifetime","security.session_max_renewals","security.max_sessions_per_wallet","security.max_pending_tx","security.rate_limit_session_rpm","security.rate_limit_tx_rpm"];function ol(){const a=v({}),t=v({}),n=v(!1),l=v(!0),i=async()=>{try{const o=await B(C.ADMIN_SETTINGS);a.value=o}catch(o){const u=o instanceof _?o:new _(0,"UNKNOWN","Unknown error");y("error",I(u.code))}finally{l.value=!1}};O(()=>{i()},[]);const s=(o,u)=>{const d=String(u);t.value={...t.value,[o]:d}},r=async()=>{n.value=!0;try{const o=Object.entries(t.value).filter(([u])=>Tt.includes(u)).map(([u,d])=>({key:u,value:d}));await le(C.ADMIN_SETTINGS,{settings:o}),t.value={},await i(),y("success","Session settings saved and applied")}catch(o){const u=o instanceof _?o:new _(0,"UNKNOWN","Unknown error");y("error",I(u.code))}finally{n.value=!1}},c=()=>{t.value={}};O(()=>(fe({id:"sessions-settings",isDirty:()=>Object.keys(t.value).filter(o=>Tt.includes(o)).length>0,save:r,discard:c}),()=>_e("sessions-settings")),[]);const m=Object.keys(t.value).filter(o=>Tt.includes(o)).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(z,{children:[m>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[m," unsaved change",m>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(E,{variant:"ghost",size:"sm",onClick:c,children:"Discard"}),e(E,{variant:"primary",size:"sm",onClick:r,loading:n.value,children:"Save"})]})]}),e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Session Configuration"}),e("p",{class:"settings-description",children:"Configure session lifetime, renewal limits, and request rate limiting. Changes apply immediately without daemon restart."})]}),e("div",{class:"settings-category-body",children:[e(Oe,{legend:"Lifetime",description:"Session duration and renewal limits",children:e("div",{class:"settings-fields-grid",children:[e(N,{label:W("session_ttl"),name:"security.session_ttl",type:"number",value:Number(U(a.value,t.value,"security","session_ttl"))||0,onChange:o=>s("security.session_ttl",o),min:300,description:"How long a session token is valid before renewal"}),e(N,{label:W("session_absolute_lifetime"),name:"security.session_absolute_lifetime",type:"number",value:Number(U(a.value,t.value,"security","session_absolute_lifetime"))||0,onChange:o=>s("security.session_absolute_lifetime",o),min:0,description:"Maximum total session duration regardless of renewals"}),e(N,{label:W("session_max_renewals"),name:"security.session_max_renewals",type:"number",value:Number(U(a.value,t.value,"security","session_max_renewals"))||0,onChange:o=>s("security.session_max_renewals",o),min:0,description:"Maximum number of times a session can be renewed"}),e(N,{label:W("max_sessions_per_wallet"),name:"security.max_sessions_per_wallet",type:"number",value:Number(U(a.value,t.value,"security","max_sessions_per_wallet"))||0,onChange:o=>s("security.max_sessions_per_wallet",o),min:1,max:100,description:"Maximum concurrent sessions for a single wallet"})]})}),e(Oe,{legend:"Rate Limits",description:"Request throttling per session and transaction",children:e("div",{class:"settings-fields-grid",children:[e(N,{label:W("max_pending_tx"),name:"security.max_pending_tx",type:"number",value:Number(U(a.value,t.value,"security","max_pending_tx"))||0,onChange:o=>s("security.max_pending_tx",o),min:1,max:100,description:"Maximum in-flight transactions per session"}),e(N,{label:W("rate_limit_session_rpm"),name:"security.rate_limit_session_rpm",type:"number",value:Number(U(a.value,t.value,"security","rate_limit_session_rpm"))||0,onChange:o=>s("security.rate_limit_session_rpm",o),min:10,description:"Max requests per minute per session"}),e(N,{label:W("rate_limit_tx_rpm"),name:"security.rate_limit_tx_rpm",type:"number",value:Number(U(a.value,t.value,"security","rate_limit_tx_rpm"))||0,onChange:o=>s("security.rate_limit_tx_rpm",o),min:1,description:"Max transaction requests per minute per session"})]})})]})]})]})}function rl(){const a=v("sessions");O(()=>{const h=J.value;h&&h.tab&&(a.value=h.tab,setTimeout(()=>{re.value=h.fieldName},100),J.value=null)},[J.value]);const t=v([]),n=v(""),l=v(""),i=v([]),s=v(!1),r=v(!0),c=v(!1),m=v(!1),o=v(""),u=v(!1),d=v(""),f=v(!1),p=v(!1),b=v("api"),T=v(new Set),S=v(!1),D=v(!1),L=v([]),M=v(null),F=async()=>{try{const h=await B(C.WALLETS);t.value=h.items.filter(A=>A.status==="ACTIVE")}catch(h){const A=h instanceof _?h:new _(0,"UNKNOWN","Unknown error");y("error",I(A.code))}finally{r.value=!1}},k=async()=>{s.value=!0;try{const h=n.value?`${C.SESSIONS}?walletId=${n.value}`:C.SESSIONS,A=await B(h);i.value=A}catch(h){const A=h instanceof _?h:new _(0,"UNKNOWN","Unknown error");y("error",I(A.code))}finally{s.value=!1}},x=async()=>{c.value=!0;try{const h=await Q(C.SESSIONS,{walletId:n.value});o.value=h.token,m.value=!0,await k()}catch(h){const A=h instanceof _?h:new _(0,"UNKNOWN","Unknown error");y("error",I(A.code))}finally{c.value=!1}},R=h=>{const A=new Set(T.value);A.has(h)?A.delete(h):A.add(h),T.value=A},j=()=>{T.value.size===t.value.length?T.value=new Set:T.value=new Set(t.value.map(h=>h.id))},q=async()=>{if(T.value.size!==0){S.value=!0;try{const h=Array.from(T.value);if(b.value==="mcp"){const A=await Q(C.ADMIN_BULK_MCP_TOKENS,{walletIds:h});L.value=A.results,M.value=A.claudeDesktopConfig}else{const A=await Q(C.ADMIN_BULK_SESSIONS,{walletIds:h});L.value=A.results,M.value=null}p.value=!1,D.value=!0,await k()}catch(h){const A=h instanceof _?h:new _(0,"UNKNOWN","Unknown error");y("error",I(A.code))}finally{S.value=!1}}},X=async()=>{f.value=!0;try{await De(C.SESSION(d.value)),y("success","Session revoked"),u.value=!1,await k()}catch(h){const A=h instanceof _?h:new _(0,"UNKNOWN","Unknown error");y("error",I(A.code))}finally{f.value=!1}};O(()=>{F()},[]),O(()=>{i.value=[],k()},[n.value]);const G=[{key:"id",header:"ID",render:h=>h.id.slice(0,8)+"..."},{key:"walletName",header:"Wallet",render:h=>h.walletName??h.walletId.slice(0,8)+"..."},{key:"source",header:"Source",render:h=>e(P,{variant:h.source==="mcp"?"info":"default",children:h.source==="mcp"?"MCP":"API"})},{key:"status",header:"Status",render:h=>e(P,{variant:h.status==="ACTIVE"?"success":h.status==="EXPIRED"?"warning":"danger",children:h.status})},{key:"expiresAt",header:"Expires At",render:h=>ie(h.expiresAt)},{key:"renewals",header:"Renewals",render:h=>`${h.renewalCount}/${h.maxRenewals}`},{key:"createdAt",header:"Created",render:h=>ie(h.createdAt)},{key:"actions",header:"Actions",render:h=>h.status==="ACTIVE"?e(E,{size:"sm",variant:"danger",onClick:()=>sl(h.id,d,u),children:"Revoke"}):null}];return e("div",{class:"page",children:[e(Ge,{pageName:"Sessions",tabName:ca.find(h=>h.key===a.value)?.label??"",onPageClick:()=>{a.value="sessions"}}),e(qe,{tabs:ca,activeTab:a.value,onTabChange:h=>{a.value=h}}),a.value==="sessions"&&e(z,{children:[e("div",{class:"session-controls",children:[e("div",{class:"session-wallet-select",children:[e("label",{for:"wallet-select",children:"Wallet"}),e("select",{id:"wallet-select",value:n.value,onChange:h=>{n.value=h.target.value},disabled:r.value,children:[e("option",{value:"",children:"All Wallets"}),t.value.map(h=>e("option",{value:h.id,children:[h.name," (",h.chain,"/",h.network,")"]},h.id))]})]}),e("div",{class:"session-wallet-select",children:[e("label",{for:"source-select",children:"Source"}),e("select",{id:"source-select",value:l.value,onChange:h=>{l.value=h.target.value},children:[e("option",{value:"",children:"All"}),e("option",{value:"api",children:"API"}),e("option",{value:"mcp",children:"MCP"})]})]}),e(E,{onClick:x,disabled:!n.value,loading:c.value,children:"Create Session"}),e(E,{variant:"secondary",onClick:()=>{T.value=new Set,b.value="api",p.value=!0},disabled:t.value.length===0,children:"Bulk Create"})]}),e(we,{columns:G,data:l.value?i.value.filter(h=>h.source===l.value):i.value,loading:s.value,emptyMessage:"No sessions"}),e(se,{open:m.value,title:"Session Created",onCancel:()=>{m.value=!1},cancelText:"Close",children:[e("p",{class:"token-warning",children:"Copy this token now. It will not be shown again."}),e("div",{class:"token-display",children:[e("code",{class:"token-value",children:o.value}),e(Le,{value:o.value,label:"Copy Token"})]})]}),e(se,{open:u.value,title:"Revoke Session",onCancel:()=>{u.value=!1},onConfirm:X,confirmText:"Revoke",confirmVariant:"danger",loading:f.value,children:e("p",{children:"Are you sure you want to revoke this session? The associated token will be immediately invalidated."})}),e(se,{open:p.value,title:"Bulk Create Sessions",onCancel:()=>{p.value=!1},onConfirm:q,confirmText:`Create ${T.value.size} ${b.value==="mcp"?"MCP Tokens":"Sessions"}`,confirmDisabled:T.value.size===0,loading:S.value,children:[e("div",{style:{marginBottom:"var(--space-3)"},children:[e("label",{style:{fontWeight:600,display:"block",marginBottom:"var(--space-2)"},children:"Type"}),e("div",{style:{display:"flex",gap:"var(--space-3)"},children:[e("label",{style:{cursor:"pointer"},children:[e("input",{type:"radio",name:"bulkType",checked:b.value==="api",onChange:()=>{b.value="api"}})," API Session"]}),e("label",{style:{cursor:"pointer"},children:[e("input",{type:"radio",name:"bulkType",checked:b.value==="mcp",onChange:()=>{b.value="mcp"}})," MCP Token"]})]})]}),e("div",{children:[e("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"var(--space-2)"},children:[e("label",{style:{fontWeight:600},children:"Select Wallets"}),e("button",{type:"button",class:"btn btn-sm",onClick:j,children:T.value.size===t.value.length?"Deselect All":"Select All"})]}),e("div",{style:{maxHeight:"250px",overflow:"auto",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",padding:"var(--space-2)"},children:t.value.map(h=>e("label",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)",padding:"var(--space-1) 0",cursor:"pointer"},children:[e("input",{type:"checkbox",checked:T.value.has(h.id),onChange:()=>R(h.id)}),e("span",{children:h.name}),e("span",{style:{color:"var(--color-text-secondary)",fontSize:"0.8rem"},children:["(",h.chain,"/",h.network,")"]})]},h.id))})]})]}),e(se,{open:D.value,title:"Bulk Creation Results",onCancel:()=>{D.value=!1},cancelText:"Close",children:[e("div",{style:{marginBottom:"var(--space-3)"},children:e("p",{children:["Created: ",e("strong",{children:L.value.filter(h=>!h.error).length})," / Failed: ",e("strong",{children:L.value.filter(h=>h.error).length})]})}),e("div",{style:{maxHeight:"200px",overflow:"auto",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",padding:"var(--space-2)"},children:L.value.map(h=>e("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"var(--space-1) 0",borderBottom:"1px solid var(--color-border)"},children:[e("span",{children:h.walletName??h.walletId.slice(0,8)}),h.error?e(P,{variant:"danger",children:h.error}):e(P,{variant:"success",children:"Created"})]},h.walletId))}),M.value&&Object.keys(M.value).length>0&&e("div",{style:{marginTop:"var(--space-3)"},children:[e("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"var(--space-2)"},children:[e("label",{style:{fontWeight:600},children:"Claude Desktop Config"}),e(Le,{value:JSON.stringify({mcpServers:M.value},null,2),label:"Copy Config"})]}),e("pre",{style:{fontSize:"0.75rem",maxHeight:"150px",overflow:"auto",background:"var(--color-bg-secondary)",padding:"var(--space-2)",borderRadius:"var(--radius-md)"},children:JSON.stringify({mcpServers:M.value},null,2)})]})]})]}),a.value==="settings"&&e(ol,{})]})}function cl({rules:a,onChange:t,errors:n}){const l=s=>r=>{t({...a,[s]:r})},i=s=>r=>{const c=Number(r),m={...a};r===""||r===0||Number.isNaN(c)?delete m[s]:m[s]=c,t(m)};return e("div",{class:"policy-form-fields",children:[e("h4",{children:"Native Amount Tiers"}),e("div",{class:"policy-form-grid",children:[e(N,{label:"Instant Max (lamports/wei)",name:"instant_max",value:a.instant_max||"",onChange:l("instant_max"),error:n.instant_max,required:!0}),e(N,{label:"Notify Max (lamports/wei)",name:"notify_max",value:a.notify_max||"",onChange:l("notify_max"),error:n.notify_max,required:!0}),e(N,{label:"Delay Max (lamports/wei)",name:"delay_max",value:a.delay_max||"",onChange:l("delay_max"),error:n.delay_max,required:!0})]}),e("h4",{children:"USD Amount Tiers (Optional)"}),e("div",{class:"policy-form-grid",children:[e(N,{label:"Instant Max USD",name:"instant_max_usd",type:"number",value:a.instant_max_usd??"",onChange:i("instant_max_usd"),placeholder:"Optional"}),e(N,{label:"Notify Max USD",name:"notify_max_usd",type:"number",value:a.notify_max_usd??"",onChange:i("notify_max_usd"),placeholder:"Optional"}),e(N,{label:"Delay Max USD",name:"delay_max_usd",type:"number",value:a.delay_max_usd??"",onChange:i("delay_max_usd"),placeholder:"Optional"})]}),e("h4",{children:"Cumulative USD Limits (Optional)"}),e("div",{class:"policy-form-grid",children:[e(N,{label:"Daily Limit USD (24h rolling)",name:"daily_limit_usd",type:"number",value:a.daily_limit_usd??"",onChange:i("daily_limit_usd"),placeholder:"e.g. 500",error:n.daily_limit_usd}),e(N,{label:"Monthly Limit USD (30d rolling)",name:"monthly_limit_usd",type:"number",value:a.monthly_limit_usd??"",onChange:i("monthly_limit_usd"),placeholder:"e.g. 5000",error:n.monthly_limit_usd})]}),e(N,{label:"Delay Duration (seconds, min 60)",name:"delay_seconds",type:"number",value:a.delay_seconds??900,onChange:l("delay_seconds"),error:n.delay_seconds,required:!0,min:60})]})}function pe({items:a,onAdd:t,onRemove:n,renderRow:l,onChange:i,addLabel:s="+ Add",minItems:r=0,error:c}){return e("div",{class:"dynamic-row-list",children:[a.map((m,o)=>e("div",{class:"dynamic-row",children:[e("div",{class:"dynamic-row-fields",children:l(m,o,i)}),e("button",{class:"btn btn-ghost btn-sm dynamic-row-remove",onClick:()=>n(o),disabled:a.length<=r,title:"Remove",children:"x"})]},o)),e("button",{class:"btn btn-secondary btn-sm",onClick:t,children:s}),c&&e("span",{class:"form-error",children:c})]})}function dl({rules:a,onChange:t,errors:n}){const l=a.allowed_addresses||[];return e("div",{class:"policy-form-fields",children:e(pe,{items:l,onAdd:()=>t({...a,allowed_addresses:[...l,""]}),onRemove:i=>t({...a,allowed_addresses:l.filter((s,r)=>r!==i)}),onChange:(i,s)=>{const r=[...l];r[i]=s,t({...a,allowed_addresses:r})},renderRow:(i,s,r)=>e(N,{label:`Address ${s+1}`,name:`address-${s}`,value:i,onChange:c=>r(s,c),placeholder:"Wallet address",error:n[`allowed_addresses.${s}`],required:!0}),addLabel:"+ Add Address",error:n.allowed_addresses})})}function ul({rules:a,onChange:t,errors:n}){const l=i=>s=>{t({...a,[i]:s})};return e("div",{class:"policy-form-fields",children:[e(N,{label:"Max Requests",name:"max_requests",type:"number",value:a.max_requests??100,onChange:l("max_requests"),error:n.max_requests,required:!0,min:1}),e(N,{label:"Window (seconds)",name:"window_seconds",type:"number",value:a.window_seconds??3600,onChange:l("window_seconds"),error:n.window_seconds,required:!0,min:1})]})}function vl({rules:a,onChange:t,errors:n}){const l=i=>{const s={...a};i===""||i===void 0?delete s.maxAmount:s.maxAmount=i,t(s)};return e("div",{class:"policy-form-fields",children:[e(N,{label:"Max Amount (lamports/wei, optional)",name:"maxAmount",value:a.maxAmount??"",onChange:l,error:n.maxAmount,placeholder:"Leave empty for no limit"}),e(N,{label:"Block Unlimited Approvals",name:"blockUnlimited",type:"checkbox",value:a.blockUnlimited??!0,onChange:i=>t({...a,blockUnlimited:i})})]})}const hl=[{label:"Instant",value:"INSTANT"},{label:"Notify",value:"NOTIFY"},{label:"Delay",value:"DELAY"},{label:"Approval",value:"APPROVAL"}];function ml({rules:a,onChange:t,errors:n}){return e("div",{class:"policy-form-fields",children:e(N,{label:"Override Tier",name:"tier",type:"select",value:a.tier??"DELAY",onChange:l=>t({...a,tier:l}),options:hl,error:n.tier})})}const pl=[{label:"All Chains",value:""},{label:"Solana",value:"solana"},{label:"Ethereum",value:"ethereum"}];function fl({rules:a,onChange:t,errors:n}){const l=a.tokens||[];return e("div",{class:"policy-form-fields",children:e(pe,{items:l,onAdd:()=>t({...a,tokens:[...l,{address:"",symbol:"",chain:""}]}),onRemove:i=>t({...a,tokens:l.filter((s,r)=>r!==i)}),onChange:(i,s)=>{const r=[...l];r[i]=s,t({...a,tokens:r})},renderRow:(i,s,r)=>e("div",{class:"dynamic-row-fields",style:{display:"flex",gap:"0.5rem",flex:1},children:[e(N,{label:`Address ${s+1}`,name:`token-addr-${s}`,value:i.address,onChange:c=>r(s,{...i,address:c}),placeholder:"Token mint/contract address",error:n[`tokens.${s}.address`],required:!0}),e(N,{label:"Symbol",name:`token-symbol-${s}`,value:i.symbol,onChange:c=>r(s,{...i,symbol:c}),placeholder:"e.g. USDC"}),e(N,{label:"Chain",name:`token-chain-${s}`,type:"select",value:i.chain,onChange:c=>{const m={...i,chain:c};c||delete m.chain,r(s,m)},options:pl})]}),addLabel:"+ Add Token",error:n.tokens})})}const _l=[{label:"All Chains",value:""},{label:"Solana",value:"solana"},{label:"Ethereum",value:"ethereum"}];function yl({rules:a,onChange:t,errors:n}){const l=a.contracts||[];return e("div",{class:"policy-form-fields",children:e(pe,{items:l,onAdd:()=>t({...a,contracts:[...l,{address:"",name:"",chain:""}]}),onRemove:i=>t({...a,contracts:l.filter((s,r)=>r!==i)}),onChange:(i,s)=>{const r=[...l];r[i]=s,t({...a,contracts:r})},renderRow:(i,s,r)=>e("div",{class:"dynamic-row-fields",style:{display:"flex",gap:"0.5rem",flex:1},children:[e(N,{label:`Address ${s+1}`,name:`contract-addr-${s}`,value:i.address,onChange:c=>r(s,{...i,address:c}),placeholder:"Contract address",error:n[`contracts.${s}.address`],required:!0}),e(N,{label:"Name",name:`contract-name-${s}`,value:i.name,onChange:c=>r(s,{...i,name:c}),placeholder:"e.g. Uniswap Router"}),e(N,{label:"Chain",name:`contract-chain-${s}`,type:"select",value:i.chain,onChange:c=>{const m={...i,chain:c};c||delete m.chain,r(s,m)},options:_l})]}),addLabel:"+ Add Contract",error:n.contracts})})}function gl({rules:a,onChange:t,errors:n}){const l=a.methods||[],i=s=>{t({...a,methods:s})};return e("div",{class:"policy-form-fields",children:e(pe,{items:l,onAdd:()=>i([...l,{contractAddress:"",selectors:[""]}]),onRemove:s=>i(l.filter((r,c)=>c!==s)),onChange:(s,r)=>{const c=[...l];c[s]=r,i(c)},renderRow:(s,r,c)=>e("div",{style:{flex:1},children:[e(N,{label:`Contract Address ${r+1}`,name:`method-addr-${r}`,value:s.contractAddress,onChange:m=>c(r,{...s,contractAddress:m}),placeholder:"Contract address",error:n[`methods.${r}.contractAddress`],required:!0}),e("div",{style:{marginTop:"0.5rem",marginLeft:"1rem"},children:[e("label",{style:{fontSize:"0.85rem",fontWeight:500},children:"Selectors"}),e(pe,{items:s.selectors,onAdd:()=>c(r,{...s,selectors:[...s.selectors,""]}),onRemove:m=>c(r,{...s,selectors:s.selectors.filter((o,u)=>u!==m)}),onChange:(m,o)=>{const u=[...s.selectors];u[m]=o,c(r,{...s,selectors:u})},renderRow:(m,o,u)=>e(N,{label:`Selector ${o+1}`,name:`method-sel-${r}-${o}`,value:m,onChange:d=>u(o,d),placeholder:"e.g. 0xa9059cbb or transfer(address,uint256)",error:n[`methods.${r}.selectors.${o}`],required:!0}),addLabel:"+ Add Selector",error:n[`methods.${r}.selectors`]})]})]}),addLabel:"+ Add Method Entry",error:n.methods})})}function bl({rules:a,onChange:t,errors:n}){const l=a.spenders||[];return e("div",{class:"policy-form-fields",children:e(pe,{items:l,onAdd:()=>t({...a,spenders:[...l,{address:"",name:"",maxAmount:""}]}),onRemove:i=>t({...a,spenders:l.filter((s,r)=>r!==i)}),onChange:(i,s)=>{const r=[...l];r[i]=s,s.maxAmount||delete r[i].maxAmount,t({...a,spenders:r})},renderRow:(i,s,r)=>e("div",{class:"dynamic-row-fields",style:{display:"flex",gap:"0.5rem",flex:1},children:[e(N,{label:`Address ${s+1}`,name:`spender-addr-${s}`,value:i.address,onChange:c=>r(s,{...i,address:c}),placeholder:"Spender address",error:n[`spenders.${s}.address`],required:!0}),e(N,{label:"Name",name:`spender-name-${s}`,value:i.name,onChange:c=>r(s,{...i,name:c}),placeholder:"e.g. Uniswap"}),e(N,{label:"Max Amount",name:`spender-max-${s}`,value:i.maxAmount||"",onChange:c=>r(s,{...i,maxAmount:c}),placeholder:"Leave empty for unlimited",error:n[`spenders.${s}.maxAmount`]})]}),addLabel:"+ Add Spender",error:n.spenders})})}const wl=Array.from({length:24},(a,t)=>({label:`${String(t).padStart(2,"0")}:00`,value:String(t)})),Sl=Array.from({length:24},(a,t)=>({label:`${String(t+1).padStart(2,"0")}:00`,value:String(t+1)})),kl=[{label:"Sun",value:0},{label:"Mon",value:1},{label:"Tue",value:2},{label:"Wed",value:3},{label:"Thu",value:4},{label:"Fri",value:5},{label:"Sat",value:6}];function Nl({rules:a,onChange:t,errors:n}){const l=a.allowed_hours||{start:0,end:24},i=a.allowed_days||[],s=c=>m=>{const o={...l,[c]:Number(m)};t({...a,allowed_hours:o})},r=c=>{const m=i.includes(c)?i.filter(o=>o!==c):[...i,c].sort((o,u)=>o-u);t({...a,allowed_days:m})};return e("div",{class:"policy-form-fields",children:[e("h4",{children:"Allowed Hours"}),e("div",{class:"policy-form-grid",children:[e(N,{label:"Start Hour",name:"allowed_hours_start",type:"select",value:String(l.start),onChange:s("start"),options:wl,error:n.allowed_hours}),e(N,{label:"End Hour",name:"allowed_hours_end",type:"select",value:String(l.end),onChange:s("end"),options:Sl})]}),e("h4",{children:"Allowed Days"}),e("div",{style:{display:"flex",gap:"0.75rem",flexWrap:"wrap"},children:kl.map(c=>e("label",{style:{display:"flex",alignItems:"center",gap:"0.25rem",cursor:"pointer"},children:[e("input",{type:"checkbox",checked:i.includes(c.value),onChange:()=>r(c.value)}),c.label]},c.value))}),n.allowed_days&&e("span",{class:"form-error",children:n.allowed_days})]})}const Tl=[{label:"mainnet",value:"mainnet"},{label:"devnet",value:"devnet"},{label:"testnet",value:"testnet"},{label:"ethereum-mainnet",value:"ethereum-mainnet"},{label:"ethereum-sepolia",value:"ethereum-sepolia"},{label:"polygon-mainnet",value:"polygon-mainnet"},{label:"polygon-amoy",value:"polygon-amoy"},{label:"arbitrum-mainnet",value:"arbitrum-mainnet"},{label:"arbitrum-sepolia",value:"arbitrum-sepolia"},{label:"optimism-mainnet",value:"optimism-mainnet"},{label:"optimism-sepolia",value:"optimism-sepolia"},{label:"base-mainnet",value:"base-mainnet"},{label:"base-sepolia",value:"base-sepolia"}];function Cl({rules:a,onChange:t,errors:n}){const l=a.networks||[];return e("div",{class:"policy-form-fields",children:e(pe,{items:l,onAdd:()=>t({...a,networks:[...l,{network:"mainnet",name:""}]}),onRemove:i=>t({...a,networks:l.filter((s,r)=>r!==i)}),onChange:(i,s)=>{const r=[...l];r[i]=s,t({...a,networks:r})},renderRow:(i,s,r)=>e("div",{class:"dynamic-row-fields",style:{display:"flex",gap:"0.5rem",flex:1},children:[e(N,{label:`Network ${s+1}`,name:`network-sel-${s}`,type:"select",value:i.network,onChange:c=>r(s,{...i,network:c}),options:Tl,error:n[`networks.${s}.network`],required:!0}),e(N,{label:"Label",name:`network-name-${s}`,value:i.name,onChange:c=>r(s,{...i,name:c}),placeholder:"Optional label"})]}),addLabel:"+ Add Network",error:n.networks})})}function El({rules:a,onChange:t,errors:n}){const l=a.domains||[];return e("div",{class:"policy-form-fields",children:e(pe,{items:l,onAdd:()=>t({...a,domains:[...l,""]}),onRemove:i=>t({...a,domains:l.filter((s,r)=>r!==i)}),onChange:(i,s)=>{const r=[...l];r[i]=s,t({...a,domains:r})},renderRow:(i,s,r)=>e(N,{label:`Domain ${s+1}`,name:`domain-${s}`,value:i,onChange:c=>r(s,c),placeholder:"e.g. api.example.com or *.service.io",error:n[`domains.${s}`],required:!0}),addLabel:"+ Add Domain",error:n.domains})})}function da({type:a,rules:t,onChange:n,errors:l}){switch(a){case"SPENDING_LIMIT":return e(cl,{rules:t,onChange:n,errors:l});case"WHITELIST":return e(dl,{rules:t,onChange:n,errors:l});case"RATE_LIMIT":return e(ul,{rules:t,onChange:n,errors:l});case"APPROVE_AMOUNT_LIMIT":return e(vl,{rules:t,onChange:n,errors:l});case"APPROVE_TIER_OVERRIDE":return e(ml,{rules:t,onChange:n,errors:l});case"ALLOWED_TOKENS":return e(fl,{rules:t,onChange:n,errors:l});case"CONTRACT_WHITELIST":return e(yl,{rules:t,onChange:n,errors:l});case"METHOD_WHITELIST":return e(gl,{rules:t,onChange:n,errors:l});case"APPROVED_SPENDERS":return e(bl,{rules:t,onChange:n,errors:l});case"TIME_RESTRICTION":return e(Nl,{rules:t,onChange:n,errors:l});case"ALLOWED_NETWORKS":return e(Cl,{rules:t,onChange:n,errors:l});case"X402_ALLOWED_DOMAINS":return e(El,{rules:t,onChange:n,errors:l});default:return e("p",{class:"policy-form-placeholder",children:"This policy type uses JSON editor. Toggle to JSON mode."})}}function Ut(a){const t=typeof a=="string"?Number(a):a;return Number.isNaN(t)?String(a):t.toLocaleString("en-US")}function Al(a){return a===86400?"1d":a%86400===0?`${a/86400}d`:a===3600?"1h":a%3600===0?`${a/3600}h`:a===60?"1m":a%60===0?`${a/60}m`:`${a}s`}const Ct=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function Il(a){if(!a||a.length===0)return"";const t=[...a].sort((l,i)=>l-i);let n=!0;for(let l=1;l<t.length;l++)if(t[l]!==t[l-1]+1){n=!1;break}return n&&t.length>2?`${Ct[t[0]]}-${Ct[t[t.length-1]]}`:t.map(l=>Ct[l]??String(l)).join(", ")}function ua(a){return String(a).padStart(2,"0")}function Dl({rules:a}){const t=Number(a.instant_max??0),n=Number(a.notify_max??0),l=Number(a.delay_max??0),i=Math.max(t,n,l,1),s=[{label:"Instant",value:a.instant_max,width:t/i*100,cls:"instant"},{label:"Notify",value:a.notify_max,width:n/i*100,cls:"notify"},{label:"Delay",value:a.delay_max,width:l/i*100,cls:"delay"},{label:"Approval",value:"",width:100,cls:"approval"}];return e("div",{class:"tier-bars",children:s.map(r=>e("div",{class:"tier-bar",children:[e("span",{class:"tier-bar-label",children:r.label}),e("div",{class:"tier-bar-track",children:e("div",{class:`tier-bar-fill tier-bar-fill--${r.cls}`,style:{width:`${r.width}%`}})}),e("span",{class:"tier-bar-value",children:r.value?Ut(r.value):""})]},r.cls))})}function va(a){return a.toLocaleString("en-US",{minimumFractionDigits:0,maximumFractionDigits:2})}function Ll({rules:a}){const t=a.daily_limit_usd,n=a.monthly_limit_usd;return!t&&!n?null:e("div",{class:"cumulative-limits",children:[e("div",{class:"cumulative-limits-label",children:"Cumulative Limits"}),t&&e("div",{class:"cumulative-limit-row",children:[e("span",{class:"cumulative-limit-type",children:"Daily (24h)"}),e("span",{class:"cumulative-limit-value",children:["$",va(t)]})]}),n&&e("div",{class:"cumulative-limit-row",children:[e("span",{class:"cumulative-limit-type",children:"Monthly (30d)"}),e("span",{class:"cumulative-limit-value",children:["$",va(n)]})]})]})}const Ol={INSTANT:"success",NOTIFY:"info",DELAY:"warning",APPROVAL:"danger"};function xl({type:a,rules:t}){switch(a){case"SPENDING_LIMIT":return e("div",{class:"spending-limit-summary",children:[e(Dl,{rules:t}),e(Ll,{rules:t})]});case"ALLOWED_TOKENS":{const n=t.tokens||[];return n.length===0?e("span",{class:"rules-vis-text",children:"No tokens"}):e("div",{class:"rules-vis-badges",children:n.map((l,i)=>e(P,{variant:"info",children:l.symbol||(l.address?l.address.slice(0,8)+"...":"?")},i))})}case"RATE_LIMIT":{const n=t.max_requests,l=t.window_seconds;return e("span",{class:"rules-vis-text",children:[n," req / ",Al(l)]})}case"WHITELIST":{const n=t.allowed_addresses||[];return e(P,{variant:"neutral",children:[n.length," addresses"]})}case"TIME_RESTRICTION":{const n=t.allowed_days||[],l=t.allowed_hours,i=Il(n),s=l?`${ua(l.start)}:00-${ua(l.end)}:00`:"";return e("span",{class:"rules-vis-text",children:[i," ",s]})}case"CONTRACT_WHITELIST":{const n=t.contracts||[];if(n.length===0)return e("span",{class:"rules-vis-text",children:"No contracts"});const l=n.slice(0,3),i=n.length-3;return e("div",{class:"rules-vis-badges",children:[l.map((s,r)=>e(P,{variant:"neutral",children:s.name||(s.address?s.address.slice(0,8)+"...":"?")},r)),i>0&&e(P,{variant:"neutral",children:["+",i," more"]})]})}case"METHOD_WHITELIST":{const n=t.methods||[],l=n.length,i=n.reduce((s,r)=>s+(r.selectors?.length||0),0);return e(P,{variant:"neutral",children:[l," contracts, ",i," methods"]})}case"APPROVED_SPENDERS":{const n=t.spenders||[];return e(P,{variant:"neutral",children:[n.length," spenders"]})}case"APPROVE_AMOUNT_LIMIT":{const n=t.maxAmount,l=t.blockUnlimited;return n&&l?e("span",{class:"rules-vis-text",children:["Max: ",Ut(n)," + Block unlimited"]}):n?e("span",{class:"rules-vis-text",children:["Max: ",Ut(n)]}):l?e("span",{class:"rules-vis-text",children:"Block unlimited only"}):e("span",{class:"rules-vis-text",children:"No limits"})}case"APPROVE_TIER_OVERRIDE":{const n=t.tier||"DELAY",l=Ol[n]||"neutral";return e(P,{variant:l,children:n})}case"ALLOWED_NETWORKS":{const n=t.networks||[];if(n.length===0)return e("span",{class:"rules-vis-text",children:"No networks"});const l=n.slice(0,3),i=n.length-3;return e("div",{class:"rules-vis-badges",children:[l.map((s,r)=>e(P,{variant:"info",children:s.network},r)),i>0&&e(P,{variant:"info",children:["+",i," more"]})]})}case"X402_ALLOWED_DOMAINS":{const n=t.domains||[];if(n.length===0)return e("span",{class:"rules-vis-text",children:"No domains"});const l=n.slice(0,3),i=n.length-3;return e("div",{class:"rules-vis-badges",children:[l.map((s,r)=>e(P,{variant:"neutral",children:s},r)),i>0&&e(P,{variant:"neutral",children:["+",i," more"]})]})}default:{const n=JSON.stringify(t);return e("span",{class:"rules-summary",children:n.length>60?n.slice(0,60)+"...":n})}}}const Ga=[{label:"Spending Limit",value:"SPENDING_LIMIT"},{label:"Whitelist",value:"WHITELIST"},{label:"Time Restriction",value:"TIME_RESTRICTION"},{label:"Rate Limit",value:"RATE_LIMIT"},{label:"Allowed Tokens",value:"ALLOWED_TOKENS"},{label:"Contract Whitelist",value:"CONTRACT_WHITELIST"},{label:"Method Whitelist",value:"METHOD_WHITELIST"},{label:"Approved Spenders",value:"APPROVED_SPENDERS"},{label:"Approve Amount Limit",value:"APPROVE_AMOUNT_LIMIT"},{label:"Approve Tier Override",value:"APPROVE_TIER_OVERRIDE"},{label:"Allowed Networks",value:"ALLOWED_NETWORKS"},{label:"x402 Allowed Domains",value:"X402_ALLOWED_DOMAINS"}],We={SPENDING_LIMIT:{instant_max:"1000000",notify_max:"5000000",delay_max:"10000000",delay_seconds:300,approval_timeout:3600},WHITELIST:{allowed_addresses:[]},TIME_RESTRICTION:{allowed_hours:{start:0,end:24},allowed_days:[0,1,2,3,4,5,6]},RATE_LIMIT:{max_requests:100,window_seconds:3600},ALLOWED_TOKENS:{tokens:[]},CONTRACT_WHITELIST:{contracts:[]},METHOD_WHITELIST:{methods:[]},APPROVED_SPENDERS:{spenders:[]},APPROVE_AMOUNT_LIMIT:{maxAmount:"1000000",blockUnlimited:!0},APPROVE_TIER_OVERRIDE:{tier:"DELAY"},ALLOWED_NETWORKS:{networks:[]},X402_ALLOWED_DOMAINS:{domains:[]}};function tt(a,t){const n={};if(a==="SPENDING_LIMIT"){(!t.instant_max||!/^\d+$/.test(t.instant_max))&&(n.instant_max="Positive integer required"),(!t.notify_max||!/^\d+$/.test(t.notify_max))&&(n.notify_max="Positive integer required"),(!t.delay_max||!/^\d+$/.test(t.delay_max))&&(n.delay_max="Positive integer required");const l=Number(t.delay_seconds);(t.delay_seconds===void 0||t.delay_seconds===""||Number.isNaN(l)||l<60)&&(n.delay_seconds="Minimum 60 seconds");const i=t.daily_limit_usd;if(i!==void 0&&i!==""){const r=Number(i);(Number.isNaN(r)||r<=0)&&(n.daily_limit_usd="Must be a positive number")}const s=t.monthly_limit_usd;if(s!==void 0&&s!==""){const r=Number(s);(Number.isNaN(r)||r<=0)&&(n.monthly_limit_usd="Must be a positive number")}}else if(a==="WHITELIST"){const l=t.allowed_addresses||[];l.length===0&&(n.allowed_addresses="At least one address required"),l.forEach((i,s)=>{(!i||i.trim()==="")&&(n[`allowed_addresses.${s}`]="Address required")})}else if(a==="RATE_LIMIT"){const l=Number(t.max_requests);(!t.max_requests||Number.isNaN(l)||l<1||!Number.isInteger(l))&&(n.max_requests="Positive integer required");const i=Number(t.window_seconds);(!t.window_seconds||Number.isNaN(i)||i<1||!Number.isInteger(i))&&(n.window_seconds="Positive integer required")}else if(a==="APPROVE_AMOUNT_LIMIT")t.maxAmount&&!/^\d+$/.test(t.maxAmount)&&(n.maxAmount="Must be a positive integer string");else if(a==="ALLOWED_TOKENS"){const l=t.tokens||[];l.length===0&&(n.tokens="At least one token required"),l.forEach((i,s)=>{(!i.address||i.address.trim()==="")&&(n[`tokens.${s}.address`]="Address required")})}else if(a==="CONTRACT_WHITELIST"){const l=t.contracts||[];l.length===0&&(n.contracts="At least one contract required"),l.forEach((i,s)=>{(!i.address||i.address.trim()==="")&&(n[`contracts.${s}.address`]="Address required")})}else if(a==="METHOD_WHITELIST"){const l=t.methods||[];l.length===0&&(n.methods="At least one method entry required"),l.forEach((i,s)=>{(!i.contractAddress||i.contractAddress.trim()==="")&&(n[`methods.${s}.contractAddress`]="Contract address required"),!i.selectors||i.selectors.length===0?n[`methods.${s}.selectors`]="At least one selector required":i.selectors.forEach((r,c)=>{(!r||r.trim()==="")&&(n[`methods.${s}.selectors.${c}`]="Selector required")})})}else if(a==="APPROVED_SPENDERS"){const l=t.spenders||[];l.length===0&&(n.spenders="At least one spender required"),l.forEach((i,s)=>{(!i.address||i.address.trim()==="")&&(n[`spenders.${s}.address`]="Address required"),i.maxAmount&&!/^\d+$/.test(i.maxAmount)&&(n[`spenders.${s}.maxAmount`]="Must be a positive integer")})}else if(a==="TIME_RESTRICTION"){(t.allowed_days||[]).length===0&&(n.allowed_days="At least one day required");const i=t.allowed_hours;i&&i.start>=i.end&&(n.allowed_hours="Start must be before end")}else if(a==="ALLOWED_NETWORKS"){const l=t.networks||[];l.length===0&&(n.networks="At least one network required"),l.forEach((i,s)=>{(!i.network||i.network.trim()==="")&&(n[`networks.${s}.network`]="Network required")})}else if(a==="X402_ALLOWED_DOMAINS"){const l=t.domains||[];l.length===0&&(n.domains="At least one domain required"),l.forEach((i,s)=>{(!i||i.trim()==="")&&(n[`domains.${s}`]="Domain required")})}return n}function Rl(a,t){if(!a)return"Global";const n=t.find(l=>l.id===a);return n?n.name:a.slice(0,8)+"..."}function Et(a){const t=Ga.find(n=>n.value===a);return t?t.label:a}const ha=[{key:"policies",label:"Policies"},{key:"defaults",label:"Defaults"}],At=["security.policy_defaults_delay_seconds","security.policy_defaults_approval_timeout","policy.default_deny_tokens","policy.default_deny_contracts","policy.default_deny_spenders"];function Pl(){const a=v({}),t=v({}),n=v(!1),l=v(!0),i=async()=>{try{const o=await B(C.ADMIN_SETTINGS);a.value=o}catch(o){const u=o instanceof _?o:new _(0,"UNKNOWN","Unknown error");y("error",I(u.code))}finally{l.value=!1}};O(()=>{i()},[]);const s=(o,u)=>{const d=String(u);t.value={...t.value,[o]:d}},r=async()=>{n.value=!0;try{const o=Object.entries(t.value).filter(([u])=>At.includes(u)).map(([u,d])=>({key:u,value:d}));await le(C.ADMIN_SETTINGS,{settings:o}),t.value={},await i(),y("success","Policy defaults saved and applied")}catch(o){const u=o instanceof _?o:new _(0,"UNKNOWN","Unknown error");y("error",I(u.code))}finally{n.value=!1}},c=()=>{t.value={}};O(()=>(fe({id:"policies-defaults",isDirty:()=>Object.keys(t.value).filter(o=>At.includes(o)).length>0,save:r,discard:c}),()=>_e("policies-defaults")),[]);const m=Object.keys(t.value).filter(o=>At.includes(o)).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(z,{children:[m>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[m," unsaved change",m>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(E,{variant:"ghost",size:"sm",onClick:c,children:"Discard"}),e(E,{variant:"primary",size:"sm",onClick:r,loading:n.value,children:"Save"})]})]}),e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Policy Defaults"}),e("p",{class:"settings-description",children:"Configure default delay, approval timeout, and default-deny policies. Changes apply immediately without daemon restart."})]}),e("div",{class:"settings-category-body",children:[e("div",{class:"settings-fields-grid",children:[e(N,{label:W("policy_defaults_delay_seconds"),name:"security.policy_defaults_delay_seconds",type:"number",value:Number(U(a.value,t.value,"security","policy_defaults_delay_seconds"))||0,onChange:o=>s("security.policy_defaults_delay_seconds",o),min:0,description:"Default delay before executing delayed-tier transactions"}),e(N,{label:W("policy_defaults_approval_timeout"),name:"security.policy_defaults_approval_timeout",type:"number",value:Number(U(a.value,t.value,"security","policy_defaults_approval_timeout"))||0,onChange:o=>s("security.policy_defaults_approval_timeout",o),min:60,description:"How long to wait for owner approval before timeout"})]}),e("div",{class:"settings-subgroup",style:{marginTop:"1rem",borderTop:"1px solid var(--border)",paddingTop:"1rem"},children:[e("h4",{style:{margin:"0 0 0.5rem 0",fontSize:"0.875rem",fontWeight:600,color:"var(--text-secondary)"},children:"Default Deny Policies"}),e("div",{class:"settings-fields-grid",children:[e(N,{label:W("default_deny_tokens"),name:"policy.default_deny_tokens",type:"checkbox",value:Ae(a.value,t.value,"security","default_deny_tokens"),onChange:o=>s("policy.default_deny_tokens",o),description:"Deny token transfers unless a matching whitelist policy exists"}),e(N,{label:W("default_deny_contracts"),name:"policy.default_deny_contracts",type:"checkbox",value:Ae(a.value,t.value,"security","default_deny_contracts"),onChange:o=>s("policy.default_deny_contracts",o),description:"Deny contract calls unless a matching whitelist policy exists"}),e(N,{label:W("default_deny_spenders"),name:"policy.default_deny_spenders",type:"checkbox",value:Ae(a.value,t.value,"security","default_deny_spenders"),onChange:o=>s("policy.default_deny_spenders",o),description:"Deny token approvals unless a matching whitelist policy exists"})]})]}),e("div",{class:"settings-info-box",children:"When enabled, transactions are denied if no matching whitelist policy exists. Disable to allow all transactions of that type when no policy is configured."})]})]})]})}function Wl(){const a=v("policies");O(()=>{const g=J.value;g&&g.tab&&(a.value=g.tab,setTimeout(()=>{re.value=g.fieldName},100),J.value=null)},[J.value]);const t=v([]),n=v([]),l=v("__all__"),i=v(!1),s=v(!0),r=v(!1),c=v("SPENDING_LIMIT"),m=v(""),o=v(JSON.stringify(We.SPENDING_LIMIT,null,2)),u=v(We.SPENDING_LIMIT),d=v({}),f=v(!1),p=v(0),b=v(!0),T=v(""),S=v(null),D=v(!1),L=v(!1),M=v(null),F=v(""),k=v({}),x=v(!1),R=v({}),j=v(0),q=v(!0),X=v(null),G=v(!1),h=v(!1),A=v(null),ae=v(!1),_t=async()=>{try{const g=await B(C.WALLETS);t.value=g.items}catch(g){const H=g instanceof _?g:new _(0,"UNKNOWN","Unknown error");y("error",I(H.code))}finally{s.value=!1}},Se=async()=>{i.value=!0;try{let g=C.POLICIES;l.value!=="__all__"&&l.value!=="__global__"&&(g=`${C.POLICIES}?walletId=${l.value}`);const H=await B(g);l.value==="__global__"?n.value=H.filter(oe=>oe.walletId===null):n.value=H}catch(g){const H=g instanceof _?g:new _(0,"UNKNOWN","Unknown error");y("error",I(H.code))}finally{i.value=!1}},je=async()=>{S.value=null;let g;if(f.value)try{g=JSON.parse(o.value)}catch{S.value="Invalid JSON in rules field";return}else{const H=tt(c.value,u.value);if(Object.keys(H).length>0){d.value=H;return}d.value={},g=u.value}D.value=!0;try{await Q(C.POLICIES,{walletId:m.value||void 0,type:c.value,rules:g,priority:p.value,enabled:b.value,network:T.value||void 0}),y("success","Policy created"),r.value=!1,c.value="SPENDING_LIMIT",m.value="",T.value="",o.value=JSON.stringify(We.SPENDING_LIMIT,null,2),u.value=We.SPENDING_LIMIT,d.value={},f.value=!1,p.value=0,b.value=!0,S.value=null,await Se()}catch(H){const oe=H instanceof _?H:new _(0,"UNKNOWN","Unknown error");y("error",I(oe.code))}finally{D.value=!1}},Ye=g=>{M.value=g,F.value=JSON.stringify(g.rules,null,2),k.value={...g.rules},x.value=!1,R.value={},j.value=g.priority,q.value=g.enabled,X.value=null,L.value=!0},yt=async()=>{X.value=null;let g;if(x.value)try{g=JSON.parse(F.value)}catch{X.value="Invalid JSON in rules field";return}else{const H=tt(M.value.type,k.value);if(Object.keys(H).length>0){R.value=H;return}R.value={},g=k.value}G.value=!0;try{await le(C.POLICY(M.value.id),{rules:g,priority:j.value,enabled:q.value}),y("success","Policy updated"),L.value=!1,await Se()}catch(H){const oe=H instanceof _?H:new _(0,"UNKNOWN","Unknown error");y("error",I(oe.code))}finally{G.value=!1}},gt=()=>{if(!x.value)F.value=JSON.stringify(k.value,null,2);else try{k.value=JSON.parse(F.value),X.value=null}catch{X.value="Invalid JSON — cannot switch to form mode";return}x.value=!x.value},bt=g=>{A.value=g,h.value=!0},wt=async()=>{ae.value=!0;try{await De(C.POLICY(A.value.id)),y("success","Policy deleted"),h.value=!1,await Se()}catch(g){const H=g instanceof _?g:new _(0,"UNKNOWN","Unknown error");y("error",I(H.code))}finally{ae.value=!1}},St=g=>{const H=g;c.value=H;const oe=We[H];oe&&(o.value=JSON.stringify(oe,null,2),u.value={...oe}),d.value={},f.value=!1},kt=()=>{if(!f.value)o.value=JSON.stringify(u.value,null,2);else try{u.value=JSON.parse(o.value),S.value=null}catch{S.value="Invalid JSON — cannot switch to form mode";return}f.value=!f.value};O(()=>{_t()},[]),O(()=>{Se()},[l.value]);const Je=[{key:"type",header:"Type",render:g=>e(P,{variant:g.type==="SPENDING_LIMIT"?"success":"info",children:Et(g.type)})},{key:"walletId",header:"Wallet",render:g=>Rl(g.walletId,t.value)},{key:"network",header:"Network",render:g=>g.network??"All"},{key:"rules",header:"Rules",render:g=>e(xl,{type:g.type,rules:g.rules})},{key:"priority",header:"Priority"},{key:"enabled",header:"Enabled",render:g=>e(P,{variant:g.enabled?"success":"danger",children:g.enabled?"ON":"OFF"})},{key:"actions",header:"Actions",render:g=>e("span",{style:{display:"flex",gap:"0.25rem"},children:[e("button",{class:"btn btn-ghost btn-sm",onClick:H=>{H.stopPropagation(),Ye(g)},children:"Edit"}),e(E,{size:"sm",variant:"danger",onClick:()=>bt(g),children:"Delete"})]})}];return e("div",{class:"page",children:[e(Ge,{pageName:"Policies",tabName:ha.find(g=>g.key===a.value)?.label??"",onPageClick:()=>{a.value="policies"}}),e(qe,{tabs:ha,activeTab:a.value,onTabChange:g=>{a.value=g}}),a.value==="policies"&&e(z,{children:[e("div",{class:"policy-controls",children:[e("div",{class:"policy-filter-select",children:[e("label",{for:"policy-wallet-filter",children:"Filter by Wallet"}),e("select",{id:"policy-wallet-filter",value:l.value,onChange:g=>{l.value=g.target.value},disabled:s.value,children:[e("option",{value:"__all__",children:"All Policies"}),e("option",{value:"__global__",children:"Global Only"}),t.value.map(g=>e("option",{value:g.id,children:[g.name," (",g.chain,"/",g.network,")"]},g.id))]})]}),!r.value&&e(E,{onClick:()=>{r.value=!0},children:"Create Policy"})]}),r.value&&e("div",{class:"inline-form",children:[e(N,{label:"Type",name:"type",type:"select",value:c.value,onChange:St,options:Ga}),e(N,{label:"Wallet",name:"walletId",type:"select",value:m.value,onChange:g=>{m.value=g},options:[{label:"Global (no wallet)",value:""},...t.value.map(g=>({label:`${g.name} (${g.chain}/${g.network})`,value:g.id}))]}),e(N,{label:"Network Scope",name:"network",value:T.value,onChange:g=>{T.value=g},placeholder:"e.g. polygon-mainnet (leave empty for all networks)"}),e("div",{class:"policy-form-section",children:[e("div",{class:"policy-form-header",children:[e("label",{children:"Rules"}),e("button",{class:"btn btn-ghost btn-sm json-toggle",onClick:kt,children:f.value?"Switch to Form":"JSON Direct Edit"})]}),f.value?e(N,{label:"",name:"rules",type:"textarea",value:o.value,onChange:g=>{o.value=g},error:S.value??void 0}):e(da,{type:c.value,rules:u.value,onChange:g=>{u.value=g,Object.keys(d.value).length>0&&(d.value=tt(c.value,g))},errors:d.value})]}),e(N,{label:"Priority",name:"priority",type:"number",value:p.value,onChange:g=>{p.value=g},min:0,max:999}),e(N,{label:"Enabled",name:"enabled",type:"checkbox",value:b.value,onChange:g=>{b.value=g}}),e("div",{class:"inline-form-actions",children:[e(E,{onClick:je,loading:D.value,children:"Create"}),e(E,{variant:"secondary",onClick:()=>{r.value=!1,S.value=null},children:"Cancel"})]})]}),e(we,{columns:Je,data:n.value,loading:i.value,emptyMessage:"No policies found"}),e(se,{open:L.value,title:"Edit Policy",onCancel:()=>{L.value=!1},onConfirm:yt,confirmText:"Save",loading:G.value,children:M.value&&e("div",{children:[e("div",{class:"policy-type-readonly",children:["Type: ",Et(M.value.type)]}),e("div",{class:"policy-form-section",children:[e("div",{class:"policy-form-header",children:[e("label",{children:"Rules"}),e("button",{class:"btn btn-ghost btn-sm json-toggle",onClick:gt,children:x.value?"Switch to Form":"JSON Direct Edit"})]}),x.value?e("div",{class:"edit-rules-textarea",children:e(N,{label:"",name:"edit-rules",type:"textarea",value:F.value,onChange:g=>{F.value=g},error:X.value??void 0})}):e(da,{type:M.value.type,rules:k.value,onChange:g=>{k.value=g,Object.keys(R.value).length>0&&(R.value=tt(M.value.type,g))},errors:R.value})]}),e(N,{label:"Priority",name:"edit-priority",type:"number",value:j.value,onChange:g=>{j.value=g},min:0,max:999}),e(N,{label:"Enabled",name:"edit-enabled",type:"checkbox",value:q.value,onChange:g=>{q.value=g}})]})}),e(se,{open:h.value,title:"Delete Policy",onCancel:()=>{h.value=!1},onConfirm:wt,confirmText:"Delete",confirmVariant:"danger",loading:ae.value,children:A.value&&e("p",{children:["Are you sure you want to delete this"," ",e("strong",{children:Et(A.value.type)})," policy? This action cannot be undone."]})})]}),a.value==="defaults"&&e(Pl,{})]})}function Ml(){return e(Ul,{})}function Ul(){const a=v([]),t=v(!0),n=v(!1),l=v(null),i=v("ADMIN"),s=v(!1),r=v(!1),c=v(null),m=v(!1),o=async()=>{t.value=!0;try{const S=await B(C.ADMIN_TELEGRAM_USERS);a.value=S.users}catch(S){const D=S instanceof _?S:new _(0,"UNKNOWN","Unknown error");y("error",I(D.code))}finally{t.value=!1}};O(()=>{o()},[]);const u=S=>{l.value=S,i.value="ADMIN",n.value=!0},d=async()=>{if(l.value){s.value=!0;try{await le(C.ADMIN_TELEGRAM_USER(l.value.chat_id),{role:i.value}),y("success",`User approved as ${i.value}`),n.value=!1,l.value=null,await o()}catch(S){const D=S instanceof _?S:new _(0,"UNKNOWN","Unknown error");y("error",I(D.code))}finally{s.value=!1}}},f=S=>{c.value=S,r.value=!0},p=async()=>{if(c.value){m.value=!0;try{await De(C.ADMIN_TELEGRAM_USER(c.value.chat_id)),y("success","User deleted"),r.value=!1,c.value=null,await o()}catch(S){const D=S instanceof _?S:new _(0,"UNKNOWN","Unknown error");y("error",I(D.code))}finally{m.value=!1}}},b=S=>S==="PENDING"?"warning":S==="ADMIN"?"success":"info";return e("div",{class:"page",children:[e(we,{columns:[{key:"chat_id",header:"Chat ID",render:S=>String(S.chat_id)},{key:"username",header:"Username",render:S=>S.username??"-"},{key:"role",header:"Role",render:S=>e(P,{variant:b(S.role),children:S.role})},{key:"registered_at",header:"Registered",render:S=>ie(S.registered_at)},{key:"approved_at",header:"Approved",render:S=>S.approved_at?ie(S.approved_at):"-"},{key:"actions",header:"Actions",render:S=>e("div",{style:{display:"flex",gap:"var(--space-1)"},children:[S.role==="PENDING"&&e(E,{size:"sm",variant:"primary",onClick:()=>u(S),children:"Approve"}),e(E,{size:"sm",variant:"danger",onClick:()=>f(S),children:"Delete"})]})}],data:a.value,loading:t.value,emptyMessage:"No Telegram users registered. Users appear here after sending /start to the bot."}),e(se,{open:n.value,title:"Approve Telegram User",onCancel:()=>{n.value=!1,l.value=null},onConfirm:d,confirmText:"Approve",confirmVariant:"primary",loading:s.value,children:l.value&&e("div",{children:[e("p",{children:[e("strong",{children:"Chat ID:"})," ",l.value.chat_id,l.value.username&&e("span",{children:[" (",e("strong",{children:["@",l.value.username]}),")"]})]}),e("div",{class:"form-field",style:{marginTop:"var(--space-3)"},children:[e("label",{for:"approve-role",children:"Role"}),e("select",{id:"approve-role",value:i.value,onChange:S=>{i.value=S.target.value},children:[e("option",{value:"ADMIN",children:"ADMIN"}),e("option",{value:"READONLY",children:"READONLY"})]})]})]})}),e(se,{open:r.value,title:"Delete Telegram User",onCancel:()=>{r.value=!1,c.value=null},onConfirm:p,confirmText:"Delete",confirmVariant:"danger",loading:m.value,children:e("p",{children:"Are you sure you want to remove this user? They will need to /start again to re-register."})})]})}const It=20,ma=[{key:"channels",label:"Channels & Logs"},{key:"telegram",label:"Telegram Users"},{key:"settings",label:"Settings"}];function $l(){const a=v({}),t=v({}),n=v(!1),l=v(!0),i=v([]),s=v(!1),r=async()=>{try{const f=await B(C.ADMIN_SETTINGS);a.value=f}catch(f){const p=f instanceof _?f:new _(0,"UNKNOWN","Unknown error");y("error",I(p.code))}finally{l.value=!1}};O(()=>{r()},[]);const c=(f,p)=>{const b=String(p);t.value={...t.value,[f]:b}},m=async()=>{n.value=!0;try{const f=Object.entries(t.value).filter(([p])=>p.startsWith("notifications.")||p.startsWith("telegram.")).map(([p,b])=>({key:p,value:b}));await le(C.ADMIN_SETTINGS,{settings:f}),t.value={},await r(),y("success","Notification settings saved and applied")}catch(f){const p=f instanceof _?f:new _(0,"UNKNOWN","Unknown error");y("error",I(p.code))}finally{n.value=!1}},o=()=>{t.value={}};O(()=>(fe({id:"notifications-settings",isDirty:()=>Object.keys(t.value).filter(f=>f.startsWith("notifications.")||f.startsWith("telegram.")).length>0,save:m,discard:o}),()=>_e("notifications-settings")),[]);const u=async()=>{s.value=!0,i.value=[];try{const f=await Q(C.ADMIN_NOTIFICATIONS_TEST,{});if(i.value=f.results,f.results.length===0)y("info","No notification channels configured");else{const p=f.results.every(b=>b.success);y(p?"success":"warning",p?"All test notifications sent":"Some channels failed")}}catch(f){const p=f instanceof _?f:new _(0,"UNKNOWN","Unknown error");y("error",I(p.code))}finally{s.value=!1}},d=Object.keys(t.value).filter(f=>f.startsWith("notifications.")||f.startsWith("telegram.")).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(z,{children:[d>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[d," unsaved change",d>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(E,{variant:"ghost",size:"sm",onClick:o,children:"Discard"}),e(E,{variant:"primary",size:"sm",onClick:m,loading:n.value,children:"Save"})]})]}),e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Notification Configuration"}),e("p",{class:"settings-description",children:"Configure notification channels for transaction alerts. Changes apply immediately via hot-reload."})]}),e("div",{class:"settings-category-body",children:[e(Oe,{legend:"Telegram",description:"Telegram notification channel and bot configuration",children:[e("div",{class:"settings-fields-grid",children:[e("div",{class:"settings-field-full",children:e(N,{label:"Enabled",name:"notifications.enabled",type:"checkbox",value:Ae(a.value,t.value,"notifications","enabled"),onChange:f=>c("notifications.enabled",f),description:"Enable or disable notifications globally"})}),e(N,{label:W("telegram_bot_token"),name:"notifications.telegram_bot_token",type:"password",value:U(a.value,t.value,"notifications","telegram_bot_token"),onChange:f=>c("notifications.telegram_bot_token",f),placeholder:et(a.value,t.value,"notifications","telegram_bot_token")?"(configured)":"",description:"Bot token for Telegram notifications"}),e(N,{label:W("telegram_chat_id"),name:"notifications.telegram_chat_id",type:"text",value:U(a.value,t.value,"notifications","telegram_chat_id"),onChange:f=>c("notifications.telegram_chat_id",f),description:"Chat ID for Telegram notification delivery"}),e(N,{label:W("locale"),name:"notifications.locale",type:"select",value:U(a.value,t.value,"notifications","locale")||"en",onChange:f=>c("notifications.locale",f),options:[{label:"English",value:"en"},{label:"Korean",value:"ko"}],description:"Language for notification messages"})]}),e("div",{class:"settings-subgroup",style:{marginTop:"0.75rem",borderTop:"1px solid var(--border)",paddingTop:"0.75rem"},children:[e("div",{class:"settings-subgroup-title",children:"Telegram Bot"}),e("div",{class:"settings-fields-grid",children:[e(N,{label:"Bot Enabled",name:"telegram.enabled",type:"select",value:U(a.value,t.value,"telegram","enabled")||"false",onChange:f=>c("telegram.enabled",f),options:[{label:"Yes",value:"true"},{label:"No",value:"false"}],description:"Enable or disable the Telegram bot"}),e(N,{label:W("bot_token"),name:"telegram.bot_token",type:"password",value:U(a.value,t.value,"telegram","bot_token"),onChange:f=>c("telegram.bot_token",f),placeholder:et(a.value,t.value,"telegram","bot_token")?"(configured)":"Leave empty to use notification token",description:"Dedicated bot token for Telegram bot (optional, uses notification token if empty)"}),e(N,{label:"Locale",name:"telegram.locale",type:"select",value:U(a.value,t.value,"telegram","locale")||"en",onChange:f=>c("telegram.locale",f),options:[{label:"English",value:"en"},{label:"한국어",value:"ko"}],description:"Language for Telegram bot messages"})]})]})]}),e(Oe,{legend:"Other Channels",description:"Discord, ntfy, Slack, and rate limiting",children:e("div",{class:"settings-fields-grid",children:[e(N,{label:W("discord_webhook_url"),name:"notifications.discord_webhook_url",type:"password",value:U(a.value,t.value,"notifications","discord_webhook_url"),onChange:f=>c("notifications.discord_webhook_url",f),placeholder:et(a.value,t.value,"notifications","discord_webhook_url")?"(configured)":"",description:"Webhook URL for Discord notifications"}),e(N,{label:W("ntfy_server"),name:"notifications.ntfy_server",type:"text",value:U(a.value,t.value,"notifications","ntfy_server"),onChange:f=>c("notifications.ntfy_server",f),description:"Server URL for ntfy notifications"}),e(N,{label:W("ntfy_topic"),name:"notifications.ntfy_topic",type:"text",value:U(a.value,t.value,"notifications","ntfy_topic"),onChange:f=>c("notifications.ntfy_topic",f),description:"Topic name for ntfy notifications"}),e(N,{label:"Slack Webhook URL",name:"notifications.slack_webhook_url",type:"password",value:U(a.value,t.value,"notifications","slack_webhook_url"),onChange:f=>c("notifications.slack_webhook_url",f),placeholder:et(a.value,t.value,"notifications","slack_webhook_url")?"(configured)":"",description:"Webhook URL for Slack notifications"}),e(N,{label:W("rate_limit_rpm"),name:"notifications.rate_limit_rpm",type:"number",value:Number(U(a.value,t.value,"notifications","rate_limit_rpm"))||20,onChange:f=>c("notifications.rate_limit_rpm",f),min:1,max:1e3,description:"Max notifications per minute"})]})}),e("div",{class:"notif-test-section",children:[e(E,{variant:"secondary",size:"sm",onClick:u,loading:s.value,children:"Test Notification"}),i.value.length>0&&e("div",{class:"test-results",children:i.value.map(f=>e("div",{class:`test-result-item ${f.success?"test-result-success":"test-result-failure"}`,children:[e(P,{variant:f.success?"success":"danger",children:f.success?"OK":"FAIL"}),e("span",{children:f.channel}),f.error&&e("span",{style:"font-size: var(--font-size-xs); color: var(--color-danger);",children:[" - ",f.error]})]},f.channel))})]})]})]})]})}function pa(){const a=v("channels");O(()=>{const k=J.value;k&&k.tab&&(a.value=k.tab,setTimeout(()=>{re.value=k.fieldName},100),J.value=null)},[J.value]);const t=v(null),n=v(!0),l=v(!1),i=v(null),s=v(null),r=v(null),c=v(!0),m=v(1),o=v(null),u=async()=>{try{const k=await B(C.ADMIN_NOTIFICATIONS_STATUS);t.value=k}catch(k){const x=k instanceof _?k:new _(0,"UNKNOWN","Unknown error");y("error",I(x.code))}finally{n.value=!1}},d=async k=>{c.value=!0;try{const x=await B(`${C.ADMIN_NOTIFICATIONS_LOG}?page=${k}&pageSize=${It}`);r.value=x}catch(x){const R=x instanceof _?x:new _(0,"UNKNOWN","Unknown error");y("error",I(R.code))}finally{c.value=!1}},f=async()=>{l.value=!0,s.value=null;try{const x=(await Q(C.ADMIN_NOTIFICATIONS_TEST,{})).results;s.value=x,x.every(j=>j.success)?y("success","Test sent successfully"):y("warning","Some channels failed")}catch(k){const x=k instanceof _?k:new _(0,"UNKNOWN","Unknown error");y("error",I(x.code))}finally{l.value=!1}},p=async k=>{i.value=k,s.value=null;try{const R=(await Q(C.ADMIN_NOTIFICATIONS_TEST,{channel:k})).results;s.value=R,R.every(q=>q.success)?y("success",`Test sent to ${k}`):y("warning",`${k} test failed`)}catch(x){const R=x instanceof _?x:new _(0,"UNKNOWN","Unknown error");y("error",I(R.code))}finally{i.value=null}},b=()=>{m.value>1&&(m.value-=1,d(m.value))},T=()=>{const k=r.value?Math.ceil(r.value.total/It):1;m.value<k&&(m.value+=1,d(m.value))},S=k=>{o.value=o.value?.id===k.id?null:k};O(()=>{u(),d(1);const k=setInterval(()=>d(m.value),3e4);return()=>clearInterval(k)},[]);const D=n.value&&!t.value,L=t.value?.channels.some(k=>k.enabled)??!1,M=r.value?Math.max(1,Math.ceil(r.value.total/It)):1,F=[{key:"eventType",header:"Event Type"},{key:"walletId",header:"Wallet ID",render:k=>k.walletId?k.walletId.slice(0,8)+"...":"—"},{key:"channel",header:"Channel",render:k=>e("span",{style:{textTransform:"capitalize"},children:k.channel})},{key:"status",header:"Status",render:k=>e(P,{variant:k.status==="sent"?"success":"danger",children:k.status})},{key:"createdAt",header:"Time",render:k=>ie(k.createdAt)}];return e("div",{class:"page",children:[e(Ge,{pageName:"Notifications",tabName:ma.find(k=>k.key===a.value)?.label??"",onPageClick:()=>{a.value="channels"}}),e(qe,{tabs:ma,activeTab:a.value,onTabChange:k=>{a.value=k}}),a.value==="telegram"?e(Ml,{}):a.value==="settings"?e($l,{}):e(z,{children:[e("h2",{children:"Channel Status"}),t.value&&!t.value.enabled&&e("div",{class:"notif-disabled-banner",children:["Notifications are disabled. Set ",e("code",{children:"notifications.enabled = true"})," in config.toml"]}),D?e("div",{class:"channel-grid",children:[1,2,3].map(k=>e("div",{class:"channel-card",children:e("div",{class:"stat-skeleton"})},k))}):e("div",{class:"channel-grid",children:t.value?.channels.map(k=>e("div",{class:"channel-card",children:e("div",{class:"channel-card-header",children:[e("span",{class:"channel-card-name",children:k.name}),e("div",{class:"channel-card-actions",children:[e(P,{variant:k.enabled?"success":"neutral",children:k.enabled?"Connected":"Not Configured"}),k.enabled&&e(E,{variant:"secondary",size:"sm",onClick:()=>p(k.name),loading:i.value===k.name,children:"Test"})]})]})},k.name))}),e("div",{style:{marginTop:"var(--space-4)",marginBottom:"var(--space-6)"},children:[e(E,{onClick:f,loading:l.value,disabled:!L,children:"Test All Channels"}),s.value&&e("div",{class:"test-results",children:s.value.map(k=>e("div",{class:"test-result-item",children:[e("span",{class:k.success?"test-result-success":"test-result-failure",children:k.success?"✓":"✗"}),e("span",{style:{textTransform:"capitalize"},children:k.channel}),!k.success&&k.error&&e("span",{class:"test-result-failure",children:[" - ",k.error]})]},k.channel))})]}),e("h2",{children:"Delivery Log"}),e(we,{columns:F,data:r.value?.logs??[],loading:c.value,emptyMessage:"No notification logs",onRowClick:S}),o.value&&e("div",{class:"log-message-detail",children:[e("div",{class:"log-message-detail-header",children:[e("strong",{children:o.value.eventType})," via ",e("span",{style:{textTransform:"capitalize"},children:o.value.channel}),e(E,{variant:"ghost",size:"sm",onClick:()=>{o.value=null},children:"Close"})]}),e("div",{class:"log-message-detail-body",children:o.value.message?e("pre",{style:{whiteSpace:"pre-wrap",margin:0,fontSize:"var(--font-size-sm)"},children:o.value.message}):e("span",{class:"text-muted",children:"(No message recorded)"})})]}),e("div",{class:"pagination",children:[e("span",{class:"pagination-info",children:["Page ",m.value," of ",M,r.value?` (${r.value.total} total)`:""]}),e("div",{class:"pagination-buttons",children:[e(E,{variant:"secondary",size:"sm",onClick:b,disabled:m.value<=1,children:"Previous"}),e(E,{variant:"secondary",size:"sm",onClick:T,disabled:m.value>=M,children:"Next"})]})]}),e("div",{class:"config-guidance",children:e("p",{children:"Configure notification channels in the Settings tab above. Changes are applied immediately via hot-reload."})})]})]})}const fa=[{key:"killswitch",label:"Kill Switch"},{key:"autostop",label:"AutoStop Rules"},{key:"jwt",label:"Invalidate Sessions"}];function Kl(){const a=v(null),t=v(!0),n=v(!1),l=async()=>{try{const d=await B(C.ADMIN_KILL_SWITCH);a.value=d}catch(d){const f=d instanceof _?d:new _(0,"UNKNOWN","Unknown error");y("error",I(f.code))}finally{t.value=!1}};O(()=>{l()},[]);const i=async()=>{n.value=!0;try{await Q(C.ADMIN_KILL_SWITCH),y("success","Kill switch activated - all operations suspended"),await l()}catch(d){const f=d instanceof _?d:new _(0,"UNKNOWN","Unknown error");y("error",I(f.code))}finally{n.value=!1}},s=async()=>{n.value=!0;try{await Q(C.ADMIN_KILL_SWITCH_ESCALATE),y("success","Kill switch escalated to LOCKED"),await l()}catch(d){const f=d instanceof _?d:new _(0,"UNKNOWN","Unknown error");y("error",I(f.code))}finally{n.value=!1}},r=async()=>{n.value=!0;try{await Q(C.ADMIN_RECOVER),y("success","Kill switch recovered - operations resumed"),await l()}catch(d){const f=d instanceof _?d:new _(0,"UNKNOWN","Unknown error");y("error",I(f.code))}finally{n.value=!1}},c=a.value,m=c?.state==="ACTIVE",o=c?.state==="SUSPENDED",u=c?.state==="LOCKED";return e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Kill Switch"}),e("p",{class:"settings-description",children:"Emergency stop - suspends all wallet operations immediately. 3-state: ACTIVE (normal) → SUSPENDED (paused) → LOCKED (permanent)."})]}),e("div",{class:"settings-category-body",children:t.value?e("span",{children:"Loading..."}):c?e(z,{children:[e("div",{class:"ks-state-card",style:{marginBottom:"var(--space-4)"},children:[e(P,{variant:m?"success":u?"danger":"warning",children:c.state}),!m&&c.activatedAt&&e("span",{class:"ks-state-info",children:["Since ",ie(c.activatedAt),c.activatedBy?` by ${c.activatedBy}`:""]})]}),e("div",{style:{display:"flex",gap:"var(--space-2)",flexWrap:"wrap"},children:[m&&e(E,{variant:"danger",onClick:i,loading:n.value,children:"Activate Kill Switch"}),o&&e(z,{children:[e(E,{variant:"primary",onClick:r,loading:n.value,children:"Recover"}),e(E,{variant:"danger",onClick:s,loading:n.value,children:"Escalate to LOCKED"})]}),u&&e(E,{variant:"primary",onClick:r,loading:n.value,children:"Recover from LOCKED (5s wait)"})]}),o&&e("div",{class:"settings-info-box",style:{marginTop:"var(--space-3)"},children:"All wallet operations are suspended. Sessions revoked, transactions cancelled. You can Recover to resume operations, or Escalate to LOCKED for permanent lockdown."}),u&&e("div",{class:"settings-info-box",style:{marginTop:"var(--space-3)",borderColor:"var(--color-danger)"},children:"System is permanently locked. Recovery requires dual-auth (Owner signature + Master password) and has a mandatory 5-second wait period."})]}):null})]})}function Fl(){const a=v({}),t=v({}),n=v(!1),l=v(!0),i=async()=>{try{const o=await B(C.ADMIN_SETTINGS);a.value=o}catch(o){const u=o instanceof _?o:new _(0,"UNKNOWN","Unknown error");y("error",I(u.code))}finally{l.value=!1}};O(()=>{i()},[]);const s=(o,u)=>{const d=String(u);t.value={...t.value,[o]:d}},r=async()=>{n.value=!0;try{const o=Object.entries(t.value).filter(([u])=>u.startsWith("autostop.")).map(([u,d])=>({key:u,value:d}));await le(C.ADMIN_SETTINGS,{settings:o}),t.value={},await i(),y("success","AutoStop settings saved and applied")}catch(o){const u=o instanceof _?o:new _(0,"UNKNOWN","Unknown error");y("error",I(u.code))}finally{n.value=!1}},c=()=>{t.value={}};O(()=>(fe({id:"security-autostop",isDirty:()=>Object.keys(t.value).filter(o=>o.startsWith("autostop.")).length>0,save:r,discard:c}),()=>_e("security-autostop")),[]);const m=Object.keys(t.value).filter(o=>o.startsWith("autostop.")).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(z,{children:[m>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[m," unsaved change",m>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(E,{variant:"ghost",size:"sm",onClick:c,children:"Discard"}),e(E,{variant:"primary",size:"sm",onClick:r,loading:n.value,children:"Save"})]})]}),e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"AutoStop Rules"}),e("p",{class:"settings-description",children:"Automatic protection rules that suspend wallets or trigger Kill Switch on anomalies. Changes apply immediately without daemon restart."})]}),e("div",{class:"settings-category-body",children:[e("div",{class:"settings-field-full",style:{marginBottom:"var(--space-4)"},children:e(N,{label:W("enabled"),name:"autostop.enabled",type:"checkbox",value:Ae(a.value,t.value,"autostop","enabled"),onChange:o=>s("autostop.enabled",o),description:"Enable or disable AutoStop protection rules"})}),e(Oe,{legend:"Activity Detection",description:"Detects failures and unusual transaction patterns",children:e("div",{class:"settings-fields-grid",children:[e(N,{label:W("consecutive_failures_threshold"),name:"autostop.consecutive_failures_threshold",type:"number",value:Number(U(a.value,t.value,"autostop","consecutive_failures_threshold"))||0,onChange:o=>s("autostop.consecutive_failures_threshold",o),min:1,max:100,description:"Suspend wallet after this many consecutive failed transactions"}),e(N,{label:W("unusual_activity_threshold"),name:"autostop.unusual_activity_threshold",type:"number",value:Number(U(a.value,t.value,"autostop","unusual_activity_threshold"))||0,onChange:o=>s("autostop.unusual_activity_threshold",o),min:5,max:1e3,description:"Max transactions within window before triggering unusual activity alert"}),e(N,{label:W("unusual_activity_window_sec"),name:"autostop.unusual_activity_window_sec",type:"number",value:Number(U(a.value,t.value,"autostop","unusual_activity_window_sec"))||0,onChange:o=>s("autostop.unusual_activity_window_sec",o),min:60,max:86400,description:"Time window for unusual activity detection"})]})}),e(Oe,{legend:"Idle Detection",description:"Monitors inactivity and revokes idle sessions",children:e("div",{class:"settings-fields-grid",children:[e(N,{label:W("idle_timeout_sec"),name:"autostop.idle_timeout_sec",type:"number",value:Number(U(a.value,t.value,"autostop","idle_timeout_sec"))||0,onChange:o=>s("autostop.idle_timeout_sec",o),min:60,max:604800,description:"Revoke sessions with no activity for this duration"}),e(N,{label:W("idle_check_interval_sec"),name:"autostop.idle_check_interval_sec",type:"number",value:Number(U(a.value,t.value,"autostop","idle_check_interval_sec"))||0,onChange:o=>s("autostop.idle_check_interval_sec",o),min:10,max:3600,description:"How often to check for idle sessions"})]})}),e("div",{class:"settings-info-box",children:[e("strong",{children:"Consecutive Failures:"})," Suspends wallet after N consecutive failed transactions.",e("br",{}),e("strong",{children:"Unusual Activity:"})," Suspends wallet if transaction count exceeds threshold within the time window.",e("br",{}),e("strong",{children:"Idle Timeout:"})," Revokes sessions with no activity for the configured duration."]})]})]})]})}function Bl(){const a=v(!1),t=v(!1),n=async()=>{t.value=!0;try{await Q(C.ADMIN_ROTATE_SECRET),a.value=!1,y("success","All session tokens invalidated. Old tokens remain valid for 5 minutes.")}catch(l){const i=l instanceof _?l:new _(0,"UNKNOWN","Unknown error");y("error",I(i.code))}finally{t.value=!1}};return e(z,{children:[e("div",{class:"settings-section",children:[e("div",{class:"settings-section-header",children:[e("h3",{children:"Invalidate All Session Tokens"}),e("p",{class:"settings-description",children:"Revoke all active session tokens by rotating the signing key. Existing tokens remain valid for 5 minutes, then all wallets must create new sessions."})]}),e("div",{class:"settings-section-body",children:e(E,{variant:"secondary",onClick:()=>{a.value=!0},children:"Invalidate All Tokens"})})]}),e(se,{open:a.value,title:"Invalidate All Session Tokens",onCancel:()=>{a.value=!1},onConfirm:n,confirmText:"Invalidate",confirmVariant:"primary",loading:t.value,children:e("p",{children:"This will rotate the signing key and invalidate all active session tokens after 5 minutes. Every wallet will need to create a new session to continue API access. Use this when a token may have been compromised."})})]})}function Hl(){const a=v("killswitch");O(()=>{const n=J.value;n&&n.tab&&(a.value=n.tab,setTimeout(()=>{re.value=n.fieldName},100),J.value=null)},[J.value]);const t=fa.find(n=>n.key===a.value)?.label??"";return e("div",{class:"page",children:[e(Ge,{pageName:"Security",tabName:t,onPageClick:()=>{a.value="killswitch"}}),e(qe,{tabs:fa,activeTab:a.value,onTabChange:n=>{a.value=n}}),a.value==="killswitch"&&e(Kl,{}),a.value==="autostop"&&e(Fl,{}),a.value==="jwt"&&e(Bl,{})]})}const at=[{code:"USD",name:"US Dollar",symbol:"$"},{code:"KRW",name:"Korean Won",symbol:"₩"},{code:"JPY",name:"Japanese Yen",symbol:"¥"},{code:"EUR",name:"Euro",symbol:"€"},{code:"GBP",name:"British Pound",symbol:"£"},{code:"CNY",name:"Chinese Yuan",symbol:"¥"},{code:"CAD",name:"Canadian Dollar",symbol:"CA$"},{code:"AUD",name:"Australian Dollar",symbol:"A$"},{code:"CHF",name:"Swiss Franc",symbol:"CHF"},{code:"SGD",name:"Singapore Dollar",symbol:"S$"},{code:"HKD",name:"Hong Kong Dollar",symbol:"HK$"},{code:"INR",name:"Indian Rupee",symbol:"₹"},{code:"TWD",name:"Taiwan Dollar",symbol:"NT$"},{code:"THB",name:"Thai Baht",symbol:"฿"},{code:"MYR",name:"Malaysian Ringgit",symbol:"RM"},{code:"IDR",name:"Indonesian Rupiah",symbol:"Rp"},{code:"PHP",name:"Philippine Peso",symbol:"₱"},{code:"VND",name:"Vietnamese Dong",symbol:"₫"},{code:"BRL",name:"Brazilian Real",symbol:"R$"},{code:"MXN",name:"Mexican Peso",symbol:"MX$"},{code:"CLP",name:"Chilean Peso",symbol:"CL$"},{code:"TRY",name:"Turkish Lira",symbol:"₺"},{code:"PLN",name:"Polish Zloty",symbol:"zł"},{code:"CZK",name:"Czech Koruna",symbol:"Kč"},{code:"HUF",name:"Hungarian Forint",symbol:"Ft"},{code:"SEK",name:"Swedish Krona",symbol:"kr"},{code:"NOK",name:"Norwegian Krone",symbol:"kr"},{code:"DKK",name:"Danish Krone",symbol:"kr"},{code:"NZD",name:"New Zealand Dollar",symbol:"NZ$"},{code:"ZAR",name:"South African Rand",symbol:"R"},{code:"ILS",name:"Israeli Shekel",symbol:"₪"},{code:"SAR",name:"Saudi Riyal",symbol:"SR"},{code:"AED",name:"UAE Dirham",symbol:"AED"},{code:"KWD",name:"Kuwaiti Dinar",symbol:"KD"},{code:"BHD",name:"Bahraini Dinar",symbol:"BD"},{code:"NGN",name:"Nigerian Naira",symbol:"₦"},{code:"RUB",name:"Russian Ruble",symbol:"₽"},{code:"UAH",name:"Ukrainian Hryvnia",symbol:"₴"},{code:"PKR",name:"Pakistani Rupee",symbol:"Rs"},{code:"BDT",name:"Bangladeshi Taka",symbol:"৳"},{code:"LKR",name:"Sri Lankan Rupee",symbol:"Rs"},{code:"MMK",name:"Myanmar Kyat",symbol:"K"},{code:"GEL",name:"Georgian Lari",symbol:"₾"}];function Vl({value:a,onChange:t,name:n}){const l=v(""),i=v(!1),s=v(null),r=v(!1),c=Ht(null),m=un(()=>{const u=l.value.toLowerCase();return u?at.filter(d=>d.code.toLowerCase().includes(u)||d.name.toLowerCase().includes(u)||d.symbol.includes(u)):at});O(()=>{if(a==="USD"){s.value="1 USD = $1.00";return}r.value=!0,B(`${C.ADMIN_FOREX_RATES}?currencies=${a}`).then(u=>{const d=u.rates[a];s.value=d?.preview??null}).catch(()=>{s.value=null}).finally(()=>{r.value=!1})},[a]),O(()=>{const u=d=>{c.current&&!c.current.contains(d.target)&&(i.value=!1,l.value="")};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[]);const o=at.find(u=>u.code===a)??at[0];return e("div",{class:"currency-select",ref:c,children:[n&&e("input",{type:"hidden",name:n,value:a}),e("button",{type:"button",class:"currency-select-trigger",onClick:()=>{i.value=!i.value},children:[e("span",{class:"currency-select-value",children:[o.code," - ",o.name," (",o.symbol,")"]}),e("span",{class:"currency-select-chevron",children:i.value?"▲":"▼"})]}),s.value&&e("div",{class:"currency-rate-preview",children:r.value?"...":s.value}),i.value&&e("div",{class:"currency-select-dropdown",children:[e("input",{type:"text",class:"currency-select-search",placeholder:"Search currency...",value:l.value,onInput:u=>{l.value=u.target.value},autoFocus:!0}),e("div",{class:"currency-select-list",children:[m.value.map(u=>e("button",{type:"button",class:`currency-select-option ${u.code===a?"currency-select-option--active":""}`,onClick:()=>{t(u.code),i.value=!1,l.value=""},children:[e("span",{class:"currency-option-code",children:u.code}),e("span",{class:"currency-option-name",children:u.name}),e("span",{class:"currency-option-symbol",children:u.symbol})]},u.code)),m.value.length===0&&e("div",{class:"currency-select-empty",children:"No currencies found"})]})]})]})}const zl=["display.","daemon.","oracle."],ql=new Set(["security.rate_limit_global_ip_rpm"]);function Dt(a){return zl.some(t=>a.startsWith(t))||ql.has(a)}function Gl(){const a=v({}),t=v({}),n=v(!1),l=v(!0),i=v([]),s=v(!0),r=v(null),c=v(""),m=v(!1),o=v(!1),u=v(!1),d=v(""),f=v(!1),p=async()=>{try{const h=await B(C.ADMIN_SETTINGS);a.value=h}catch(h){const A=h instanceof _?h:new _(0,"UNKNOWN","Unknown error");y("error",I(A.code))}finally{l.value=!1}},b=async()=>{try{const h=await B(C.ADMIN_API_KEYS);i.value=h.keys}catch{}finally{s.value=!1}};O(()=>{p(),b()},[]),O(()=>{const h=J.value;h&&(setTimeout(()=>{re.value=h.fieldName},100),J.value=null)},[J.value]);const T=(h,A)=>U(a.value,t.value,h,A),S=(h,A)=>{const ae=String(A);t.value={...t.value,[h]:ae}},D=async()=>{n.value=!0;try{const h=Object.entries(t.value).filter(([A])=>Dt(A)).map(([A,ae])=>({key:A,value:ae}));await le(C.ADMIN_SETTINGS,{settings:h}),t.value={},await p(),y("success","Settings saved and applied")}catch(h){const A=h instanceof _?h:new _(0,"UNKNOWN","Unknown error");y("error",I(A.code))}finally{n.value=!1}},L=()=>{t.value={}};O(()=>(fe({id:"system-settings",isDirty:()=>Object.keys(t.value).filter(h=>Dt(h)).length>0,save:D,discard:L}),()=>_e("system-settings")),[]);const M=async h=>{m.value=!0;try{await le(C.ADMIN_API_KEY(h),{apiKey:c.value}),y("success",`API key saved for ${h}`),r.value=null,c.value="",await b()}catch(A){const ae=A instanceof _?A:new _(0,"UNKNOWN","Unknown error");y("error",I(ae.code))}finally{m.value=!1}},F=async h=>{try{await De(C.ADMIN_API_KEY(h)),y("success",`API key deleted for ${h}`),await b()}catch(A){const ae=A instanceof _?A:new _(0,"UNKNOWN","Unknown error");y("error",I(ae.code))}},k=async()=>{u.value=!0;try{await Q(C.ADMIN_SHUTDOWN),o.value=!1,d.value="",y("info","Shutdown initiated"),f.value=!0}catch(h){const A=h instanceof _?h:new _(0,"UNKNOWN","Unknown error");y("error",I(A.code))}finally{u.value=!1}},x=Object.keys(t.value).filter(h=>Dt(h)).length;function R(){return s.value?e("div",{class:"settings-loading",children:"Loading API keys..."}):i.value.length===0?null:e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"API Keys"}),e("p",{class:"settings-description",children:"Manage API keys for Action Providers"})]}),e("div",{class:"settings-category-body",children:i.value.map(h=>e("div",{class:"settings-field-row",children:[e("div",{class:"settings-field-label",children:[e("span",{children:h.providerName}),h.requiresApiKey&&!h.hasKey&&e(P,{variant:"warning",children:"Required"})]}),e("div",{class:"settings-field-value",children:r.value===h.providerName?e("div",{class:"api-key-edit-row",children:[e(N,{label:"API Key",type:"password",name:`apikey-${h.providerName}`,value:c.value,onChange:A=>{c.value=String(A)},placeholder:"Enter API key"}),e(E,{onClick:()=>M(h.providerName),loading:m.value,size:"sm",children:"Save"}),e(E,{variant:"ghost",onClick:()=>{r.value=null,c.value=""},size:"sm",children:"Cancel"})]}):e("div",{class:"api-key-display-row",children:[e("span",{class:"api-key-masked",children:h.hasKey?h.maskedKey:"Not set"}),e(E,{variant:"ghost",onClick:()=>{r.value=h.providerName,c.value=""},size:"sm",children:h.hasKey?"Change":"Set"}),h.hasKey&&e(E,{variant:"danger",onClick:()=>F(h.providerName),size:"sm",children:"Delete"})]})})]},h.providerName))})]})}function j(){return e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Oracle"}),e("p",{class:"settings-description",children:"Price oracle configuration for cross-validation"})]}),e("div",{class:"settings-category-body",children:[e("div",{class:"settings-fields-grid",children:e(N,{label:"Cross Validation Threshold (%)",name:"oracle.cross_validation_threshold",type:"number",value:Number(T("oracle","cross_validation_threshold"))||5,onChange:h=>S("oracle.cross_validation_threshold",h),min:0,max:100,description:"Maximum allowed deviation between price oracle sources"})}),e("div",{class:"settings-info-box",children:"Maximum allowed deviation between price sources before flagging a discrepancy. Default is 5%."})]})]})}function q(){const h=re.value==="display.currency";return O(()=>{if(h){const A=document.querySelector('[name="display.currency"]');A&&A.closest(".form-field")?.scrollIntoView({behavior:"smooth",block:"center"});const ae=setTimeout(()=>{re.value=""},2500);return()=>clearTimeout(ae)}},[h]),e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Display Currency"}),e("p",{class:"settings-description",children:"Configure display currency for USD amount conversion"})]}),e("div",{class:"settings-category-body",children:[e("div",{class:"settings-fields-grid",children:e("div",{class:`form-field${h?" form-field--highlight":""}`,children:[e("label",{children:W("currency")}),e(Vl,{name:"display.currency",value:T("display","currency")||"USD",onChange:A=>S("display.currency",A)})]})}),e("div",{class:"settings-info-box",children:"All USD amounts in the dashboard, notifications, and API responses will be converted to the selected currency. Policy evaluation always uses USD. The “≈” prefix indicates an approximate conversion."})]})]})}function X(){return e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Global IP Rate Limit"}),e("p",{class:"settings-description",children:"Maximum API requests per minute from a single IP address"})]}),e("div",{class:"settings-category-body",children:e("div",{class:"settings-fields-grid",children:e(N,{label:W("rate_limit_global_ip_rpm"),name:"security.rate_limit_global_ip_rpm",type:"number",value:Number(T("security","rate_limit_global_ip_rpm"))||0,onChange:h=>S("security.rate_limit_global_ip_rpm",h),min:10,description:"Maximum API requests per minute from a single IP address"})})})]})}function G(){return e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Log Level"}),e("p",{class:"settings-description",children:"General daemon configuration"})]}),e("div",{class:"settings-category-body",children:e("div",{class:"settings-fields-grid",children:e(N,{label:W("log_level"),name:"daemon.log_level",type:"select",value:T("daemon","log_level")||"info",onChange:h=>S("daemon.log_level",h),options:[{label:"debug",value:"debug"},{label:"info",value:"info"},{label:"warn",value:"warn"},{label:"error",value:"error"}],description:"Daemon logging verbosity level"})})})]})}return e("div",{class:"page",children:[f.value&&e("div",{class:"shutdown-overlay",children:[e("h2",{children:"Daemon is shutting down..."}),e("p",{children:"You can close this tab."})]}),x>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[x," unsaved change",x>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(E,{variant:"ghost",size:"sm",onClick:L,children:"Discard"}),e(E,{variant:"primary",size:"sm",onClick:D,loading:n.value,children:"Save"})]})]}),l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(z,{children:[e(R,{}),e(j,{}),e(q,{}),e(X,{}),e(G,{})]}),e("div",{class:"settings-section settings-section--danger",children:[e("div",{class:"settings-section-header",children:[e("h3",{children:"Danger Zone"}),e("p",{class:"settings-description",children:"Irreversible actions. Proceed with caution."})]}),e("div",{class:"settings-section-body",children:e(E,{variant:"danger",onClick:()=>{o.value=!0},children:"Shutdown Daemon"})})]}),e(se,{open:o.value,title:"Shutdown Daemon",onCancel:()=>{o.value=!1,d.value=""},onConfirm:k,confirmText:"Shutdown",confirmVariant:"danger",confirmDisabled:d.value!=="SHUTDOWN",loading:u.value,children:[e("p",{children:"This will gracefully stop the daemon process. All active connections will be terminated."}),e("div",{class:"shutdown-confirm-input",children:[e("label",{children:["Type ",e("strong",{children:"SHUTDOWN"})," to confirm"]}),e("input",{type:"text",value:d.value,onInput:h=>{d.value=h.target.value},placeholder:"SHUTDOWN"})]})]})]})}const ve=te(window.location.hash.slice(1)||"/dashboard"),nt=te(!1);window.addEventListener("hashchange",()=>{ve.value=window.location.hash.slice(1)||"/dashboard"});const jl={"/dashboard":"Dashboard","/wallets":"Wallets","/sessions":"Sessions","/policies":"Policies","/notifications":"Notifications","/security":"Security","/system":"System"},Yl={"/dashboard":"System overview and key metrics","/wallets":"Manage wallets, balances, and connections","/sessions":"View and manage active sessions","/policies":"Configure transaction policies and rules","/notifications":"Channel status, delivery logs, and settings","/security":"Emergency controls and automatic protection rules","/system":"API keys, display preferences, and daemon configuration"};function Jl(a){return a.startsWith("/wallets/")?"Wallet Detail":jl[a]??"Dashboard"}function _a(a){return Yl[a]}const Xl=[{path:"/dashboard",label:"Dashboard"},{path:"/wallets",label:"Wallets"},{path:"/sessions",label:"Sessions"},{path:"/policies",label:"Policies"},{path:"/notifications",label:"Notifications"},{path:"/security",label:"Security"},{path:"/system",label:"System"}];function Zl(){const a=ve.value;return a==="/sessions"?e(rl,{}):a==="/policies"?e(Wl,{}):a==="/notifications"?e(pa,{}):a==="/telegram-users"?(window.location.hash="#/notifications",e(pa,{})):a==="/settings"?(window.location.hash="#/dashboard",e(ia,{})):a==="/walletconnect"?(window.location.hash="#/wallets",e(ra,{})):a==="/security"?e(Hl,{}):a==="/system"?e(Gl,{}):a.startsWith("/wallets")?e(ra,{}):e(ia,{})}function Ql(){return O(()=>{const a=t=>{(t.metaKey||t.ctrlKey)&&t.key==="k"&&(t.preventDefault(),nt.value=!nt.value)};return document.addEventListener("keydown",a),()=>document.removeEventListener("keydown",a)},[]),e("div",{class:"layout",children:[e("aside",{class:"sidebar",children:[e("div",{class:"sidebar-brand",children:"WAIaaS"}),e("nav",{class:"sidebar-nav",children:Xl.map(a=>{const t=a.path==="/wallets"?ve.value.startsWith("/wallets"):ve.value===a.path;return e("a",{href:`#${a.path}`,class:`sidebar-link ${t?"active":""}`,onClick:n=>{Va.value&&(n.preventDefault(),za({type:"nav",execute:()=>{window.location.hash=`#${a.path}`}}))},children:a.label})})})]}),e("main",{class:"main",children:[e("header",{class:"header",children:[e("div",{class:"header-left",children:[e("h1",{class:"header-title",children:Jl(ve.value)}),_a(ve.value)&&e("p",{class:"header-subtitle",children:_a(ve.value)})]}),e("div",{class:"header-actions",children:[e("button",{class:"btn-search",onClick:()=>{nt.value=!0},title:"Search settings (Ctrl+K)",children:"🔍"}),e("button",{class:"btn-logout",onClick:()=>qt(),children:"Logout"})]})]}),e("div",{class:"content",children:e(Zl,{})})]}),e(Tn,{open:nt}),e(An,{})]})}const lt={overlay:{position:"fixed",inset:0,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0, 0, 0, 0.7)",color:"white",zIndex:9999},content:{textAlign:"center"},title:{fontSize:"var(--font-size-2xl)",fontWeight:"var(--font-weight-bold)",marginBottom:"var(--space-2)"},message:{fontSize:"var(--font-size-base)",color:"var(--color-text-muted)"}};function ei(){return e("div",{style:lt.overlay,children:e("div",{style:lt.content,children:[e("h1",{style:lt.title,children:"Daemon Shutting Down"}),e("p",{style:lt.message,children:"The daemon is shutting down. Please wait or restart."})]})})}function ti(){return pn.value?e(ei,{}):mn.value?e(z,{children:[e(Ql,{}),e(Fn,{})]}):e(bn,{})}tn(e(ti,{}),document.getElementById("app"));
3
+ `)}function ce({label:a,value:t,loading:n,badge:l,href:i}){const s=e(z,{children:[e("div",{class:"stat-label",children:[a,i&&e("span",{class:"stat-link-arrow",children:" →"})]}),n?e("div",{class:"stat-skeleton"}):l?e(P,{variant:l,children:t}):e("div",{class:"stat-value",children:t})]});return i?e("a",{href:i,class:"stat-card stat-card-link",style:{textDecoration:"none",color:"inherit",cursor:"pointer"},children:s}):e("div",{class:"stat-card",children:s})}function Vn(a,t){return[{key:"createdAt",header:"Time",render:n=>n.createdAt?ie(n.createdAt):"—"},{key:"walletName",header:"Wallet",render:n=>n.walletName??n.walletId.slice(0,8)},{key:"type",header:"Type"},{key:"amount",header:"Amount",render:n=>{if(!n.amount)return"—";const l=Wn(n.amountUsd,a,t);return l?`${n.amount} (${l})`:n.amount}},{key:"status",header:"Status",render:n=>{const l=n.status==="CONFIRMED"?"success":n.status==="FAILED"?"danger":"warning";return e(P,{variant:l,children:n.status})}}]}async function zn(a){try{await navigator.clipboard.writeText(a)}catch{const t=document.createElement("textarea");t.value=a,t.style.position="fixed",t.style.left="-9999px",document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)}}function ia(){const a=v(null),t=v(!0),n=v(null),l=v("USD"),i=v(1),s=v(!1),o=async()=>{t.value=!0,n.value=null;try{const r=await B(C.ADMIN_STATUS);a.value=r}catch(r){r instanceof _?n.value=I(r.code):n.value="An unexpected error occurred."}finally{t.value=!1}},c=async()=>{s.value=!0;try{const{items:r}=await B(C.WALLETS),u=r.filter(b=>b.status==="ACTIVE");if(u.length===0){y("warning","No active wallets found");return}const d=[];for(const b of u){const T=await Q(C.SESSIONS,{walletId:b.id,ttl:86400});d.push({id:b.id,name:b.name,chain:b.chain,defaultNetwork:b.network,sessionToken:T.token})}const f=window.location.origin||"http://localhost:3100",p=Bn(f,d);await zn(p),y("success","Agent prompt copied!")}catch(r){r instanceof _?y("error",I(r.code)):y("error","Failed to generate agent prompt")}finally{s.value=!1}};O(()=>{o(),Pn().then(({currency:u,rate:d})=>{l.value=u,i.value=d}).catch(()=>{});const r=setInterval(o,3e4);return()=>clearInterval(r)},[]);const m=t.value&&!a.value;return e("div",{class:"page",children:[n.value&&e("div",{class:"dashboard-error",children:[e("span",{children:n.value}),e(E,{variant:"secondary",size:"sm",onClick:o,children:"Retry"})]}),e("div",{class:"stat-grid",children:[e(ce,{label:"Version",value:a.value?.version??"—",loading:m}),e(ce,{label:"Uptime",value:a.value?In(a.value.uptime):"—",loading:m}),e(ce,{label:"Wallets",value:a.value?.walletCount?.toString()??"—",loading:m,href:"#/wallets"}),e(ce,{label:"Active Sessions",value:a.value?.activeSessionCount?.toString()??"—",loading:m,href:"#/sessions"})]}),e("div",{class:"stat-grid",style:{marginTop:"var(--space-4)"},children:[e(ce,{label:"Kill Switch",value:a.value?.killSwitchState==="ACTIVATED"?"ACTIVATED":"NORMAL",loading:m,badge:a.value?a.value.killSwitchState==="ACTIVATED"?"danger":"success":void 0}),e(ce,{label:"Status",value:a.value?.status??"—",loading:m})]}),e("div",{class:"stat-grid",style:{marginTop:"var(--space-4)"},children:[e(ce,{label:"Policies",value:a.value?.policyCount?.toString()??"—",loading:m,href:"#/policies"}),e(ce,{label:"Recent Txns (24h)",value:a.value?.recentTxCount?.toString()??"—",loading:m}),e(ce,{label:"Failed Txns (24h)",value:a.value?.failedTxCount?.toString()??"—",loading:m,badge:a.value?a.value.failedTxCount===0?"success":"danger":void 0})]}),e("div",{style:{marginTop:"var(--space-4)",display:"flex",justifyContent:"flex-end"},children:e(E,{variant:"secondary",size:"sm",onClick:c,loading:s.value,children:"Copy Agent Prompt"})}),e("div",{style:{marginTop:"var(--space-4)"},children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Recent Activity"}),e(we,{columns:Vn(l.value,i.value),data:a.value?.recentTransactions??[],loading:m,emptyMessage:"No recent transactions"})]})]})}function se({open:a,title:t,children:n,onConfirm:l,onCancel:i,confirmText:s="Confirm",cancelText:o="Cancel",confirmVariant:c="primary",confirmDisabled:m=!1,loading:r=!1}){return O(()=>{if(!a)return;const u=d=>{d.key==="Escape"&&i()};return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[a,i]),a?e("div",{class:"modal-overlay",onClick:i,children:e("div",{class:"modal-card",onClick:u=>u.stopPropagation(),children:[e("div",{class:"modal-header",children:t}),e("div",{class:"modal-body",children:n}),e("div",{class:"modal-footer",children:[e(E,{variant:"secondary",onClick:i,disabled:r,children:o}),l&&e(E,{variant:c,onClick:l,loading:r,disabled:m,children:s})]})]})}):null}function Le({value:a,label:t}){const n=v(!1);return e("button",{class:"btn btn-ghost btn-sm",onClick:async()=>{try{await navigator.clipboard.writeText(a)}catch{const i=document.createElement("textarea");i.value=a,i.style.position="fixed",i.style.left="-9999px",document.body.appendChild(i),i.select(),document.execCommand("copy"),document.body.removeChild(i)}n.value=!0,setTimeout(()=>{n.value=!1},2e3)},children:n.value?"Copied!":t??"Copy"})}function qn({title:a,description:t,actionLabel:n,onAction:l}){return e("div",{class:"empty-state",children:[e("h3",{children:a}),t&&e("p",{children:t}),n&&l&&e("button",{class:"btn btn-primary",onClick:l,children:n})]})}function qe({tabs:a,activeTab:t,onTabChange:n}){return e("div",{class:"tab-nav",children:a.map(l=>e("button",{class:`tab-btn ${t===l.key?"active":""}`,onClick:()=>{l.key!==t&&(Va.value?za({type:"tab",execute:()=>n(l.key)}):n(l.key))},children:l.label},l.key))})}function Ge({pageName:a,tabName:t,onPageClick:n}){return t?e("nav",{class:"breadcrumb","aria-label":"Breadcrumb",children:[e("button",{class:"breadcrumb-page",onClick:n,type:"button",children:a}),e("span",{class:"breadcrumb-separator","aria-hidden":"true",children:">"}),e("span",{class:"breadcrumb-current","aria-current":"page",children:t})]}):null}const Gn=new Set(["notifications.telegram_bot_token","notifications.discord_webhook_url","notifications.slack_webhook_url","telegram.bot_token"]);function jn(a){return Gn.has(a)}function W(a){return{enabled:"Enabled",telegram_bot_token:"Telegram Bot Token",telegram_chat_id:"Telegram Chat ID",discord_webhook_url:"Discord Webhook URL",ntfy_server:"Ntfy Server",ntfy_topic:"Ntfy Topic",locale:"Locale",rate_limit_rpm:"Rate Limit (RPM)",solana_mainnet:"Solana Mainnet",solana_devnet:"Solana Devnet",solana_testnet:"Solana Testnet",evm_ethereum_mainnet:"Ethereum Mainnet",evm_ethereum_sepolia:"Ethereum Sepolia",evm_polygon_mainnet:"Polygon Mainnet",evm_polygon_amoy:"Polygon Amoy",evm_arbitrum_mainnet:"Arbitrum Mainnet",evm_arbitrum_sepolia:"Arbitrum Sepolia",evm_optimism_mainnet:"Optimism Mainnet",evm_optimism_sepolia:"Optimism Sepolia",evm_base_mainnet:"Base Mainnet",evm_base_sepolia:"Base Sepolia",evm_default_network:"Default EVM Network",session_ttl:"Session TTL (seconds)",max_sessions_per_wallet:"Max Sessions per Wallet",max_pending_tx:"Max Pending Transactions",rate_limit_global_ip_rpm:"Global IP Rate Limit (RPM)",rate_limit_session_rpm:"Session Rate Limit (RPM)",rate_limit_tx_rpm:"Transaction Rate Limit (RPM)",policy_defaults_delay_seconds:"Policy Delay (seconds)",policy_defaults_approval_timeout:"Approval Timeout (seconds)",default_deny_tokens:"Default Deny: Token Transfers",default_deny_contracts:"Default Deny: Contract Calls",default_deny_spenders:"Default Deny: Token Approvals",project_id:"Project ID",log_level:"Log Level",currency:"Display Currency",consecutive_failures_threshold:"Consecutive Failures Threshold",unusual_activity_threshold:"Unusual Activity Threshold",unusual_activity_window_sec:"Unusual Activity Window (seconds)",idle_timeout_sec:"Idle Timeout (seconds)",idle_check_interval_sec:"Idle Check Interval (seconds)",check_interval_sec:"Check Interval (seconds)",low_balance_threshold_sol:"Low Balance Threshold (SOL)",low_balance_threshold_eth:"Low Balance Threshold (ETH)",cooldown_hours:"Alert Cooldown (hours)",relay_url:"Relay URL",session_absolute_lifetime:"Absolute Lifetime (seconds)",session_max_renewals:"Max Renewals",bot_token:"Bot Token"}[a]??a.replace(/_/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function U(a,t,n,l){const i=`${n}.${l}`;if(t[i]!==void 0)return t[i];const s=a[n];if(!s)return"";const o=s[l];return typeof o=="boolean"?jn(i)?"":String(o):o??""}function Ae(a,t,n,l){const i=`${n}.${l}`;if(t[i]!==void 0)return t[i]==="true";const s=a[n];if(!s)return!1;const o=s[l];return typeof o=="boolean"?o:o==="true"}function et(a,t,n,l){const i=`${n}.${l}`;if(t[i]!==void 0)return!1;const s=a[n];return s?s[l]===!0:!1}const Yn=[{key:"name",header:"Name"},{key:"chain",header:"Chain"},{key:"environment",header:"Environment",render:a=>e(P,{variant:a.environment==="mainnet"?"warning":"info",children:a.environment})},{key:"publicKey",header:"Public Key",render:a=>e("span",{style:{display:"flex",alignItems:"center",gap:"0.25rem"},children:[Mt(a.publicKey)," ",e(Le,{value:a.publicKey})]})},{key:"status",header:"Status",render:a=>e(P,{variant:a.status==="ACTIVE"?"success":"danger",children:a.status})},{key:"ownerState",header:"Owner",render:a=>e(P,{variant:qa(a.ownerState),children:a.ownerState})},{key:"createdAt",header:"Created",render:a=>ie(a.createdAt)}];function qa(a){switch(a){case"NONE":return"neutral";case"GRACE":return"warning";case"LOCKED":return"success";default:return"neutral"}}function Z({label:a,value:t,copy:n,children:l}){return e("div",{class:"detail-row",children:[e("div",{class:"detail-row-label",children:a}),e("div",{class:"detail-row-value",children:[l??t??"—",n&&t&&e(Le,{value:t})]})]})}function Jn({id:a}){const t=v(null),n=v(!0),l=v(!1),i=v(""),s=v(!1),o=v(!1),c=v(!1),m=v(!1),r=v(null),u=v([]),d=v(!0),f=v(!1),p=v(null),b=v(!0),T=v([]),k=v(!0),D=v(!1),L=v(null),M=v(!1),F=v(null),w=v(!0),x=v(!1),R=v(null),j=v(!1),q=v(""),X=v(!1),G=v(!1),h=async()=>{try{const S=await B(C.WALLET(a));t.value=S}catch(S){const V=S instanceof _?S:new _(0,"UNKNOWN","Unknown error");y("error",I(V.code))}finally{n.value=!1}},A=async()=>{s.value=!0;try{const S=await le(C.WALLET(a),{name:i.value});t.value=S,l.value=!1,y("success","Wallet name updated")}catch(S){const V=S instanceof _?S:new _(0,"UNKNOWN","Unknown error");y("error",I(V.code))}finally{s.value=!1}},ae=async()=>{c.value=!0;try{await De(C.WALLET(a)),y("success","Wallet terminated"),window.location.hash="#/wallets"}catch(S){const V=S instanceof _?S:new _(0,"UNKNOWN","Unknown error");y("error",I(V.code))}finally{c.value=!1}},_t=()=>{i.value=t.value.name,l.value=!0},Se=()=>{l.value=!1},je=async()=>{m.value=!0;try{const S=await Q(C.MCP_TOKENS,{walletId:a});r.value=S,y("success","MCP token provisioned successfully")}catch(S){const V=S instanceof _?S:new _(0,"UNKNOWN","Unknown error");y("error",I(V.code))}finally{m.value=!1}},Ye=async()=>{d.value=!0;try{const S=await B(C.WALLET_NETWORKS(a));u.value=S.availableNetworks??[]}catch(S){const V=S instanceof _?S:new _(0,"UNKNOWN","Unknown error");y("error",I(V.code)),u.value=[]}finally{d.value=!1}},yt=async()=>{b.value=!0;try{p.value=await B(C.ADMIN_WALLET_BALANCE(a))}catch{p.value=null}finally{b.value=!1}},gt=async()=>{k.value=!0;try{const S=await B(C.ADMIN_WALLET_TRANSACTIONS(a));T.value=S.items}catch{T.value=[]}finally{k.value=!1}},bt=async()=>{w.value=!0;try{F.value=await B(C.WALLET_WC_SESSION(a))}catch{F.value=null}finally{w.value=!1}},wt=()=>{R.value&&clearInterval(R.value),R.value=setInterval(async()=>{try{const S=await B(C.WALLET_WC_PAIR_STATUS(a));S.status==="connected"?(R.value&&clearInterval(R.value),R.value=null,D.value=!1,L.value=null,F.value=S.session??null,y("success","Wallet connected via WalletConnect")):(S.status==="expired"||S.status==="none")&&(R.value&&clearInterval(R.value),R.value=null,D.value=!1,L.value=null,y("error","Pairing expired. Try again."))}catch{}},3e3)},St=async()=>{M.value=!0;try{const S=await Q(C.WALLET_WC_PAIR(a));L.value=S,D.value=!0,wt()}catch(S){const V=S instanceof _?S:new _(0,"UNKNOWN","Unknown error");V.code==="WC_NOT_CONFIGURED"?(y("error","WalletConnect is not configured. Redirecting to settings..."),J.value={tab:"walletconnect",fieldName:"walletconnect.project_id"},window.location.hash="#/wallets"):y("error",I(V.code))}finally{M.value=!1}},kt=async()=>{x.value=!0;try{await De(C.WALLET_WC_SESSION(a)),F.value=null,y("success","WalletConnect session disconnected")}catch(S){const V=S instanceof _?S:new _(0,"UNKNOWN","Unknown error");y("error",I(V.code))}finally{x.value=!1}},Je=()=>{q.value=t.value?.ownerAddress??"",j.value=!0},g=()=>{j.value=!1},H=async()=>{if(!q.value.trim()){y("error","Owner address is required");return}X.value=!0;try{await le(C.WALLET_OWNER(a),{owner_address:q.value.trim()}),await h(),j.value=!1,y("success","Owner address updated")}catch(S){const V=S instanceof _?S:new _(0,"UNKNOWN","Unknown error");y("error",I(V.code,V.serverMessage))}finally{X.value=!1}},re=async S=>{f.value=!0;try{await le(C.WALLET_DEFAULT_NETWORK(a),{network:S}),y("success",`Default network changed to ${S}`),await h(),await Ye()}catch(V){const Xe=V instanceof _?V:new _(0,"UNKNOWN","Unknown error");y("error",I(Xe.code))}finally{f.value=!1}},ja=async()=>{if(t.value){G.value=!0;try{const S=await Q(C.SESSIONS,{walletId:a,ttl:86400}),V=window.location.origin||"http://localhost:3100",Xe=Hn(V,{id:t.value.id,name:t.value.name,chain:t.value.chain,defaultNetwork:t.value.defaultNetwork??t.value.network,sessionToken:S.token});try{await navigator.clipboard.writeText(Xe)}catch{const ke=document.createElement("textarea");ke.value=Xe,ke.style.position="fixed",ke.style.left="-9999px",document.body.appendChild(ke),ke.select(),document.execCommand("copy"),document.body.removeChild(ke)}y("success","Agent prompt copied!")}catch(S){S instanceof _?y("error",I(S.code)):y("error","Failed to generate agent prompt")}finally{G.value=!1}}};return O(()=>{h(),Ye(),yt(),gt(),bt()},[a]),O(()=>()=>{R.value&&clearInterval(R.value)},[]),e("div",{class:"page",children:[e("a",{href:"#/wallets",class:"back-link",children:"← Back to Wallets"}),n.value?e("div",{class:"stat-skeleton",style:{height:"200px",marginTop:"var(--space-4)"}}):t.value?e("div",{class:"wallet-detail",children:[e("div",{class:"detail-header",children:[e("div",{class:"detail-name",children:l.value?e("div",{class:"inline-edit",children:[e("input",{value:i.value,onInput:S=>{i.value=S.target.value},class:"inline-edit-input"}),e(E,{size:"sm",onClick:A,loading:s.value,children:"Save"}),e(E,{size:"sm",variant:"secondary",onClick:Se,children:"Cancel"})]}):e("span",{children:[t.value.name,e("button",{class:"btn btn-ghost btn-sm",onClick:_t,title:"Edit name",children:"✎"})]})}),e("div",{style:{display:"flex",gap:"var(--space-2)"},children:[e(E,{variant:"secondary",size:"sm",onClick:ja,loading:G.value,children:"Copy Agent Prompt"}),e(E,{variant:"danger",onClick:()=>{o.value=!0},children:"Terminate Wallet"})]})]}),e("div",{class:"detail-grid",children:[e(Z,{label:"ID",value:t.value.id,copy:!0}),e(Z,{label:"Public Key",value:t.value.publicKey,copy:!0}),e(Z,{label:"Chain",value:t.value.chain}),e(Z,{label:"Environment",children:e(P,{variant:t.value.environment==="mainnet"?"warning":"info",children:t.value.environment})}),e(Z,{label:"Default Network",value:t.value.defaultNetwork??t.value.network}),e(Z,{label:"Status",children:e(P,{variant:t.value.status==="ACTIVE"?"success":"danger",children:t.value.status})}),e(Z,{label:"Created",value:ie(t.value.createdAt)}),e(Z,{label:"Updated",value:t.value.updatedAt?ie(t.value.updatedAt):"Never"})]}),e("div",{class:"balance-section",style:{marginTop:"var(--space-6)"},children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Balances"}),b.value?e("div",{class:"stat-skeleton",style:{height:"60px"}}):p.value?.balances?.length?e("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-3)"},children:p.value.balances.map(S=>e("div",{style:{padding:"var(--space-3)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",background:S.isDefault?"var(--color-bg-secondary)":"transparent"},children:[e("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)",marginBottom:"var(--space-2)"},children:[e("strong",{children:S.network}),S.isDefault&&e("span",{class:"badge badge-info",style:{fontSize:"0.7rem"},children:"Default"})]}),S.error?e("p",{style:{color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:S.error}):S.native?e("div",{children:[e(Z,{label:"Native",value:`${S.native.balance} ${S.native.symbol}`}),S.tokens.length>0?S.tokens.map(V=>e(Z,{label:V.symbol,value:V.balance},V.address)):null]}):e("p",{style:{color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:"Balance unavailable"})]},S.network))}):e("p",{style:{color:"var(--color-text-secondary)"},children:"No balance data available"})]}),e("div",{class:"networks-section",style:{marginTop:"var(--space-6)"},children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Available Networks"}),d.value?e("div",{class:"stat-skeleton",style:{height:"80px"}}):e("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-2)"},children:(u.value??[]).map(S=>e("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"var(--space-2) var(--space-3)",background:"var(--color-bg-secondary)",borderRadius:"var(--radius-md)"},children:[e("span",{children:[S.name??S.network,S.isDefault&&e(P,{variant:"success",style:{marginLeft:"var(--space-2)"},children:"Default"})]}),!S.isDefault&&t.value?.status==="ACTIVE"&&e(E,{size:"sm",variant:"secondary",onClick:()=>re(S.network),loading:f.value,children:"Set Default"})]},S.network))})]}),e("div",{class:"transactions-section",style:{marginTop:"var(--space-6)"},children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Recent Transactions"}),e(we,{columns:[{key:"createdAt",header:"Time",render:S=>S.createdAt?ie(S.createdAt):"--"},{key:"type",header:"Type",render:S=>S.type},{key:"toAddress",header:"To",render:S=>S.toAddress?Mt(S.toAddress):"--"},{key:"amount",header:"Amount",render:S=>S.amount??"--"},{key:"status",header:"Status",render:S=>e(P,{variant:S.status==="CONFIRMED"?"success":S.status==="FAILED"?"danger":"warning",children:S.status})},{key:"network",header:"Network",render:S=>S.network??"--"}],data:T.value,loading:k.value,emptyMessage:"No transactions yet"})]}),e("div",{class:"owner-section",style:{marginTop:"var(--space-6)"},children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Owner Wallet"}),t.value.ownerState==="NONE"&&t.value.status!=="TERMINATED"&&e("div",{style:{background:"var(--color-bg-secondary)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",padding:"var(--space-3) var(--space-4)",marginBottom:"var(--space-4)"},children:[e("p",{style:{marginBottom:"var(--space-2)",fontWeight:500},children:"What is an Owner Wallet?"}),e("p",{style:{color:"var(--color-text-secondary)",fontSize:"0.85rem",marginBottom:"var(--space-3)"},children:"Register an Owner wallet to enable transaction approval (APPROVAL policy) for high-value transfers. Connect D'CENT, MetaMask, or other WalletConnect-compatible wallets to approve transactions directly."}),e(E,{size:"sm",onClick:Je,children:"Set Owner Address"})]}),e(Z,{label:"Address",children:j.value?e("div",{class:"inline-edit",children:[e("input",{value:q.value,onInput:S=>{q.value=S.target.value},class:"inline-edit-input",placeholder:"Enter owner wallet address"}),e(E,{size:"sm",onClick:H,loading:X.value,children:"Save"}),e(E,{size:"sm",variant:"secondary",onClick:g,children:"Cancel"})]}):e("span",{children:[t.value.ownerAddress?e(z,{children:[Mt(t.value.ownerAddress),e(Le,{value:t.value.ownerAddress})]}):"Not set",t.value.ownerState!=="LOCKED"&&t.value.status==="ACTIVE"&&e("button",{class:"btn btn-ghost btn-sm",onClick:Je,title:"Set owner address",children:"✎"})]})}),e(Z,{label:"State",children:e(P,{variant:qa(t.value.ownerState),children:t.value.ownerState})}),t.value.ownerState==="GRACE"&&e("div",{style:{background:"var(--color-bg-secondary)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",padding:"var(--space-3) var(--space-4)",marginTop:"var(--space-3)"},children:[e("p",{style:{marginBottom:"var(--space-2)",fontWeight:500,fontSize:"0.85rem"},children:"Verify Owner"}),e("p",{style:{color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:"Sign a verification message with the Owner wallet to transition from GRACE to LOCKED. Connect via WalletConnect first, then trigger an APPROVAL-tier transaction or use the CLI/SDK to call the verify endpoint."})]}),e("div",{style:{marginTop:"var(--space-4)",paddingTop:"var(--space-3)",borderTop:"1px solid var(--color-border)"},children:[e("h4",{style:{marginBottom:"var(--space-2)",fontSize:"0.9rem"},children:"WalletConnect"}),w.value?e("div",{class:"stat-skeleton",style:{height:"60px"}}):F.value?e("div",{children:[e(Z,{label:"Status",children:e(P,{variant:"success",children:"Connected"})}),e(Z,{label:"Peer",value:F.value.peerName??"Unknown"}),e(Z,{label:"Chain ID",value:F.value.chainId}),e(Z,{label:"Expires",value:ie(F.value.expiry)}),e("div",{style:{marginTop:"var(--space-3)"},children:e(E,{variant:"danger",onClick:kt,loading:x.value,children:"Disconnect"})})]}):e("div",{children:[e("p",{style:{marginBottom:"var(--space-3)",color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:"Connect an external wallet (D'CENT, MetaMask, Phantom) via WalletConnect for transaction approval."}),t.value?.ownerAddress?e(E,{onClick:St,loading:M.value,children:"Connect Wallet"}):e("p",{style:{color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:"Set an Owner address first to enable WalletConnect."})]})]})]}),e("div",{class:"mcp-setup-section",style:{marginTop:"var(--space-6)"},children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"MCP Setup"}),r.value?e("div",{children:[e("div",{class:"detail-grid",style:{marginBottom:"var(--space-4)"},children:[e(Z,{label:"Token Path",value:r.value.tokenPath}),e(Z,{label:"Expires At",value:ie(r.value.expiresAt)})]}),e("div",{style:{marginBottom:"var(--space-2)"},children:e("strong",{children:"Claude Desktop Config"})}),e("div",{style:{position:"relative"},children:[e("pre",{children:e("code",{style:{display:"block",whiteSpace:"pre-wrap",wordBreak:"break-all",background:"var(--color-bg-secondary)",padding:"var(--space-3)",borderRadius:"var(--radius-md)",fontSize:"0.85rem",maxHeight:"300px",overflow:"auto"},children:JSON.stringify({mcpServers:r.value.claudeDesktopConfig},null,2)})}),e("div",{style:{marginTop:"var(--space-2)"},children:e(Le,{value:JSON.stringify({mcpServers:r.value.claudeDesktopConfig},null,2),label:"Copy Config"})})]}),e("div",{style:{marginTop:"var(--space-3)"},children:e(E,{variant:"secondary",onClick:je,loading:m.value,children:"Re-provision"})})]}):e("div",{children:[e("p",{style:{marginBottom:"var(--space-3)",color:"var(--color-text-secondary)"},children:"Provision an MCP token for Claude Desktop integration."}),e(E,{onClick:je,loading:m.value,children:"Setup MCP"})]})]}),e(se,{open:o.value,title:"Terminate Wallet",onCancel:()=>{o.value=!1},onConfirm:ae,confirmText:"Terminate",confirmVariant:"danger",loading:c.value,children:e("p",{children:["Are you sure you want to terminate wallet ",e("strong",{children:t.value.name}),"? This action cannot be undone."]})}),e(se,{open:D.value,title:"Scan QR Code",onCancel:()=>{D.value=!1,R.value&&clearInterval(R.value),R.value=null},children:L.value&&e("div",{style:{textAlign:"center"},children:[e("img",{src:L.value.qrCode,alt:"WalletConnect QR Code",style:{width:"280px",height:"280px",margin:"0 auto"}}),e("p",{style:{marginTop:"var(--space-3)",color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:"Scan with D'CENT, MetaMask, Phantom, or any WalletConnect-compatible wallet"}),e("p",{style:{marginTop:"var(--space-2)",color:"var(--color-text-secondary)",fontSize:"0.75rem"},children:"Waiting for connection..."})]})})]}):e(qn,{title:"Wallet not found",description:"The wallet may have been deleted."})]})}const Xn=["solana_mainnet","solana_devnet","solana_testnet"],Zn=["evm_ethereum_mainnet","evm_ethereum_sepolia","evm_polygon_mainnet","evm_polygon_amoy","evm_arbitrum_mainnet","evm_arbitrum_sepolia","evm_optimism_mainnet","evm_optimism_sepolia","evm_base_mainnet","evm_base_sepolia"],Qn={solana_mainnet:"RPC endpoint URL for Solana mainnet",solana_devnet:"RPC endpoint URL for Solana devnet",solana_testnet:"RPC endpoint URL for Solana testnet",evm_ethereum_mainnet:"RPC endpoint URL for Ethereum mainnet",evm_ethereum_sepolia:"RPC endpoint URL for Ethereum Sepolia testnet",evm_polygon_mainnet:"RPC endpoint URL for Polygon mainnet",evm_polygon_amoy:"RPC endpoint URL for Polygon Amoy testnet",evm_arbitrum_mainnet:"RPC endpoint URL for Arbitrum mainnet",evm_arbitrum_sepolia:"RPC endpoint URL for Arbitrum Sepolia testnet",evm_optimism_mainnet:"RPC endpoint URL for Optimism mainnet",evm_optimism_sepolia:"RPC endpoint URL for Optimism Sepolia testnet",evm_base_mainnet:"RPC endpoint URL for Base mainnet",evm_base_sepolia:"RPC endpoint URL for Base Sepolia testnet"},sa={enabled:"Enable or disable balance monitoring",check_interval_sec:"How often to check wallet balances",low_balance_threshold_sol:"Alert when SOL balance drops below this amount",low_balance_threshold_eth:"Alert when ETH balance drops below this amount",cooldown_hours:"Suppress duplicate alerts for this many hours"},el=[{label:"Ethereum Mainnet",value:"ethereum-mainnet"},{label:"Ethereum Sepolia",value:"ethereum-sepolia"},{label:"Polygon Mainnet",value:"polygon-mainnet"},{label:"Polygon Amoy",value:"polygon-amoy"},{label:"Arbitrum Mainnet",value:"arbitrum-mainnet"},{label:"Arbitrum Sepolia",value:"arbitrum-sepolia"},{label:"Optimism Mainnet",value:"optimism-mainnet"},{label:"Optimism Sepolia",value:"optimism-sepolia"},{label:"Base Mainnet",value:"base-mainnet"},{label:"Base Sepolia",value:"base-sepolia"}];function tl(){const a=v({}),t=v({}),n=v(!1),l=v(!0),i=v({}),s=v({}),o=async()=>{try{const p=await B(C.ADMIN_SETTINGS);a.value=p}catch(p){const b=p instanceof _?p:new _(0,"UNKNOWN","Unknown error");y("error",I(b.code))}finally{l.value=!1}};O(()=>{o()},[]);const c=(p,b)=>{const T=String(b);t.value={...t.value,[p]:T}},m=async()=>{n.value=!0;try{const p=Object.entries(t.value).filter(([b])=>b.startsWith("rpc.")).map(([b,T])=>({key:b,value:T}));await le(C.ADMIN_SETTINGS,{settings:p}),t.value={},await o(),y("success","Settings saved and applied")}catch(p){const b=p instanceof _?p:new _(0,"UNKNOWN","Unknown error");y("error",I(b.code))}finally{n.value=!1}},r=()=>{t.value={}};O(()=>(fe({id:"wallets-rpc",isDirty:()=>Object.keys(t.value).filter(p=>p.startsWith("rpc.")).length>0,save:m,discard:r}),()=>_e("wallets-rpc")),[]);const u=async p=>{const b=p.split(".")[1]??"",T=U(a.value,t.value,"rpc",b);if(!T){y("warning","Enter a URL before testing");return}const k=b.startsWith("solana")?"solana":"evm";s.value={...s.value,[p]:!0};try{const D=await Q(C.ADMIN_SETTINGS_TEST_RPC,{url:T,chain:k});i.value={...i.value,[p]:D}}catch{i.value={...i.value,[p]:{success:!1,latencyMs:0,error:"Request failed"}}}finally{s.value={...s.value,[p]:!1}}};function d({shortKey:p}){const b=`rpc.${p}`,T=i.value[b],k=s.value[b];return e("div",{class:"settings-field-full",children:[e("div",{class:"rpc-field-row",children:[e(N,{label:W(p),name:b,type:"text",value:U(a.value,t.value,"rpc",p),onChange:D=>c(b,D),placeholder:"https://...",description:Qn[p]}),e(E,{variant:"ghost",size:"sm",onClick:()=>u(b),loading:!!k,children:"Test"})]}),T&&e("div",{class:`rpc-test-result ${T.success?"rpc-test-result--success":"rpc-test-result--failure"}`,children:[e(P,{variant:T.success?"success":"danger",children:T.success?"OK":"FAIL"}),e("span",{children:[T.latencyMs,"ms"]}),T.blockNumber!==void 0&&e("span",{children:[" (block #",T.blockNumber.toLocaleString(),")"]}),T.error&&e("span",{children:[" - ",T.error]})]})]})}const f=Object.keys(t.value).filter(p=>p.startsWith("rpc.")).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(z,{children:[f>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[f," unsaved change",f>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(E,{variant:"ghost",size:"sm",onClick:r,children:"Discard"}),e(E,{variant:"primary",size:"sm",onClick:m,loading:n.value,children:"Save"})]})]}),e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"RPC Endpoints"}),e("p",{class:"settings-description",children:"Configure blockchain RPC URLs for Solana and EVM networks"})]}),e("div",{class:"settings-category-body",children:[e("div",{class:"settings-subgroup",children:[e("div",{class:"settings-subgroup-title",children:"Solana"}),e("div",{class:"settings-fields-grid",children:Xn.map(p=>e(d,{shortKey:p},p))})]}),e("div",{class:"settings-subgroup",children:[e("div",{class:"settings-subgroup-title",children:"EVM"}),e("div",{class:"settings-fields-grid",children:[Zn.map(p=>e(d,{shortKey:p},p)),e("div",{class:"settings-field-full",children:e(N,{label:W("evm_default_network"),name:"rpc.evm_default_network",type:"select",value:U(a.value,t.value,"rpc","evm_default_network")||"ethereum-sepolia",onChange:p=>c("rpc.evm_default_network",p),options:el,description:"Default EVM network for new wallets"})})]})]})]})]})]})}function al(){const a=v({}),t=v({}),n=v(!1),l=v(!0),i=async()=>{try{const u=await B(C.ADMIN_SETTINGS);a.value=u}catch(u){const d=u instanceof _?u:new _(0,"UNKNOWN","Unknown error");y("error",I(d.code))}finally{l.value=!1}};O(()=>{i()},[]);const s=(u,d)=>{const f=String(d);t.value={...t.value,[u]:f}},o=async()=>{n.value=!0;try{const u=Object.entries(t.value).filter(([d])=>d.startsWith("monitoring.")).map(([d,f])=>({key:d,value:f}));await le(C.ADMIN_SETTINGS,{settings:u}),t.value={},await i(),y("success","Settings saved and applied")}catch(u){const d=u instanceof _?u:new _(0,"UNKNOWN","Unknown error");y("error",I(d.code))}finally{n.value=!1}},c=()=>{t.value={}};O(()=>(fe({id:"wallets-monitoring",isDirty:()=>Object.keys(t.value).filter(u=>u.startsWith("monitoring.")).length>0,save:o,discard:c}),()=>_e("wallets-monitoring")),[]);const m=[{key:"enabled",type:"checkbox"},{key:"check_interval_sec",type:"number",min:60,max:86400},{key:"low_balance_threshold_sol",type:"number",min:0},{key:"low_balance_threshold_eth",type:"number",min:0},{key:"cooldown_hours",type:"number",min:1,max:168}],r=Object.keys(t.value).filter(u=>u.startsWith("monitoring.")).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(z,{children:[r>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[r," unsaved change",r>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(E,{variant:"ghost",size:"sm",onClick:c,children:"Discard"}),e(E,{variant:"primary",size:"sm",onClick:o,loading:n.value,children:"Save"})]})]}),e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Balance Monitoring"}),e("p",{class:"settings-description",children:"Periodic balance checks for all active wallets. Sends LOW_BALANCE alerts when native token balance drops below thresholds. Changes apply immediately."})]}),e("div",{class:"settings-category-body",children:[e("div",{class:"settings-fields-grid",children:m.map(u=>u.type==="checkbox"?e("div",{class:"settings-field-full",children:e(N,{label:W(u.key),name:`monitoring.${u.key}`,type:"checkbox",value:Ae(a.value,t.value,"monitoring",u.key),onChange:d=>s(`monitoring.${u.key}`,d),description:sa[u.key]})},u.key):e(N,{label:W(u.key),name:`monitoring.${u.key}`,type:"number",value:Number(U(a.value,t.value,"monitoring",u.key))||0,onChange:d=>s(`monitoring.${u.key}`,d),min:u.min,max:u.max,description:sa[u.key]},u.key))}),e("div",{class:"settings-info-box",children:"Monitors all active wallet native token balances (SOL, ETH) at the configured interval. When balance drops below threshold, a LOW_BALANCE notification is sent. Duplicate alerts are suppressed for the cooldown period (per wallet)."})]})]})]})}function nl(){const a=v({}),t=v({}),n=v(!1),l=v(!0),i=async()=>{try{const r=await B(C.ADMIN_SETTINGS);a.value=r}catch(r){const u=r instanceof _?r:new _(0,"UNKNOWN","Unknown error");y("error",I(u.code))}finally{l.value=!1}};O(()=>{i()},[]);const s=(r,u)=>{const d=String(u);t.value={...t.value,[r]:d}},o=async()=>{n.value=!0;try{const r=Object.entries(t.value).filter(([u])=>u.startsWith("walletconnect.")).map(([u,d])=>({key:u,value:d}));await le(C.ADMIN_SETTINGS,{settings:r}),t.value={},await i(),y("success","Settings saved and applied")}catch(r){const u=r instanceof _?r:new _(0,"UNKNOWN","Unknown error");y("error",I(u.code))}finally{n.value=!1}},c=()=>{t.value={}};O(()=>(fe({id:"wallets-walletconnect",isDirty:()=>Object.keys(t.value).filter(r=>r.startsWith("walletconnect.")).length>0,save:o,discard:c}),()=>_e("wallets-walletconnect")),[]);const m=Object.keys(t.value).filter(r=>r.startsWith("walletconnect.")).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(z,{children:[m>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[m," unsaved change",m>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(E,{variant:"ghost",size:"sm",onClick:c,children:"Discard"}),e(E,{variant:"primary",size:"sm",onClick:o,loading:n.value,children:"Save"})]})]}),e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"WalletConnect"}),e("p",{class:"settings-description",children:"WalletConnect integration for dApp connections"})]}),e("div",{class:"settings-category-body",children:[e("div",{class:"settings-fields-grid",children:[e("div",{class:"settings-field-full",children:e(N,{label:W("project_id"),name:"walletconnect.project_id",type:"text",value:U(a.value,t.value,"walletconnect","project_id"),onChange:r=>s("walletconnect.project_id",r),description:"WalletConnect Cloud project identifier"})}),e("div",{class:"settings-field-full",children:e(N,{label:W("relay_url"),name:"walletconnect.relay_url",type:"text",value:U(a.value,t.value,"walletconnect","relay_url"),onChange:r=>s("walletconnect.relay_url",r),placeholder:"wss://relay.walletconnect.com",description:"WalletConnect relay server URL"})})]}),e("div",{class:"settings-info-box",children:["Get your project ID from"," ",e("a",{href:"https://cloud.walletconnect.com",target:"_blank",rel:"noopener noreferrer",children:"https://cloud.walletconnect.com"})," ","— Create a free account and project to obtain your project ID."]}),e("div",{class:"settings-info-box",children:"Relay URL defaults to wss://relay.walletconnect.com if not set."})]})]})]})}function ll(){const a=v([]),t=v(!0),n=v(!1),l=v(""),i=v("solana"),s=v("testnet"),o=v(null),c=v(!1),m=v(null),r=async()=>{try{const p=await B(C.WALLETS);a.value=p.items}catch(p){const b=p instanceof _?p:new _(0,"UNKNOWN","Unknown error");y("error",I(b.code))}finally{t.value=!1}},u=async()=>{if(!l.value.trim()){o.value="Name is required";return}o.value=null,c.value=!0;try{const p=await Q(C.WALLETS,{name:l.value.trim(),chain:i.value,environment:s.value});p.session?.token?(m.value=p.session.token,y("success","Wallet created with session")):y("success","Wallet created"),l.value="",i.value="solana",s.value="testnet",n.value=!1,t.value=!0,await r()}catch(p){const b=p instanceof _?p:new _(0,"UNKNOWN","Unknown error");o.value=I(b.code)}finally{c.value=!1}},d=p=>{window.location.hash="#/wallets/"+p.id},f=p=>{i.value=p};return O(()=>{r()},[]),e(z,{children:[e("div",{class:"page-actions",children:!n.value&&e(E,{onClick:()=>{n.value=!0},children:"Create Wallet"})}),n.value&&e("div",{class:"inline-form",children:[e(N,{label:"Name",name:"name",value:l.value,onChange:p=>{l.value=p},required:!0,placeholder:"e.g. trading-bot",error:o.value??void 0}),e(N,{label:"Chain",name:"chain",type:"select",value:i.value,onChange:f,options:[{label:"Solana",value:"solana"},{label:"Ethereum",value:"ethereum"}]}),e(N,{label:"Environment",name:"environment",type:"select",value:s.value,onChange:p=>{s.value=p},options:[{label:"Testnet",value:"testnet"},{label:"Mainnet",value:"mainnet"}]}),e("div",{class:"inline-form-actions",children:[e(E,{onClick:u,loading:c.value,children:"Create"}),e(E,{variant:"secondary",onClick:()=>{n.value=!1,o.value=null},children:"Cancel"})]})]}),m.value&&e("div",{class:"inline-form",style:{marginBottom:"1rem"},children:[e("div",{style:{fontWeight:"bold",marginBottom:"0.5rem"},children:"Session Token (copy now — shown only once)"}),e("div",{style:{display:"flex",gap:"0.5rem",alignItems:"center"},children:[e("input",{type:"text",readOnly:!0,value:m.value,style:{flex:1,fontFamily:"monospace",fontSize:"0.85rem",padding:"0.5rem"},onClick:p=>p.target.select()}),e(E,{variant:"secondary",onClick:()=>{navigator.clipboard.writeText(m.value),y("success","Token copied")},children:"Copy"}),e(E,{variant:"secondary",onClick:()=>{m.value=null},children:"Dismiss"})]})]}),e(we,{columns:Yn,data:a.value,loading:t.value,onRowClick:d,emptyMessage:"No wallets yet"})]})}const ra=[{key:"wallets",label:"Wallets"},{key:"rpc",label:"RPC Endpoints"},{key:"monitoring",label:"Balance Monitoring"},{key:"walletconnect",label:"WalletConnect"}];function il(){const a=v("wallets");return O(()=>{const t=J.value;t&&t.tab&&(a.value=t.tab,setTimeout(()=>{oe.value=t.fieldName},100),J.value=null)},[J.value]),e("div",{class:"page",children:[e(Ge,{pageName:"Wallets",tabName:ra.find(t=>t.key===a.value)?.label??"",onPageClick:()=>{a.value="wallets"}}),e(qe,{tabs:ra,activeTab:a.value,onTabChange:t=>{a.value=t}}),a.value==="wallets"&&e(ll,{}),a.value==="rpc"&&e(tl,{}),a.value==="monitoring"&&e(al,{}),a.value==="walletconnect"&&e(nl,{})]})}function oa(){const a=ve.value,t=a.startsWith("/wallets/")?a.slice(9):null;return t?e(Jn,{id:t}):e(il,{})}function Oe({legend:a,children:t,description:n}){return e("fieldset",{class:"field-group",children:[e("legend",{class:"field-group-legend",children:a}),n&&e("p",{class:"field-group-description",children:n}),e("div",{class:"field-group-body",children:t})]})}function sl(a,t,n){t.value=a,n.value=!0}const ca=[{key:"sessions",label:"Sessions"},{key:"settings",label:"Settings"}],Tt=["security.session_ttl","security.session_absolute_lifetime","security.session_max_renewals","security.max_sessions_per_wallet","security.max_pending_tx","security.rate_limit_session_rpm","security.rate_limit_tx_rpm"];function rl(){const a=v({}),t=v({}),n=v(!1),l=v(!0),i=async()=>{try{const r=await B(C.ADMIN_SETTINGS);a.value=r}catch(r){const u=r instanceof _?r:new _(0,"UNKNOWN","Unknown error");y("error",I(u.code))}finally{l.value=!1}};O(()=>{i()},[]);const s=(r,u)=>{const d=String(u);t.value={...t.value,[r]:d}},o=async()=>{n.value=!0;try{const r=Object.entries(t.value).filter(([u])=>Tt.includes(u)).map(([u,d])=>({key:u,value:d}));await le(C.ADMIN_SETTINGS,{settings:r}),t.value={},await i(),y("success","Session settings saved and applied")}catch(r){const u=r instanceof _?r:new _(0,"UNKNOWN","Unknown error");y("error",I(u.code))}finally{n.value=!1}},c=()=>{t.value={}};O(()=>(fe({id:"sessions-settings",isDirty:()=>Object.keys(t.value).filter(r=>Tt.includes(r)).length>0,save:o,discard:c}),()=>_e("sessions-settings")),[]);const m=Object.keys(t.value).filter(r=>Tt.includes(r)).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(z,{children:[m>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[m," unsaved change",m>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(E,{variant:"ghost",size:"sm",onClick:c,children:"Discard"}),e(E,{variant:"primary",size:"sm",onClick:o,loading:n.value,children:"Save"})]})]}),e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Session Configuration"}),e("p",{class:"settings-description",children:"Configure session lifetime, renewal limits, and request rate limiting. Changes apply immediately without daemon restart."})]}),e("div",{class:"settings-category-body",children:[e(Oe,{legend:"Lifetime",description:"Session duration and renewal limits",children:e("div",{class:"settings-fields-grid",children:[e(N,{label:W("session_ttl"),name:"security.session_ttl",type:"number",value:Number(U(a.value,t.value,"security","session_ttl"))||0,onChange:r=>s("security.session_ttl",r),min:300,description:"How long a session token is valid before renewal"}),e(N,{label:W("session_absolute_lifetime"),name:"security.session_absolute_lifetime",type:"number",value:Number(U(a.value,t.value,"security","session_absolute_lifetime"))||0,onChange:r=>s("security.session_absolute_lifetime",r),min:0,description:"Maximum total session duration regardless of renewals"}),e(N,{label:W("session_max_renewals"),name:"security.session_max_renewals",type:"number",value:Number(U(a.value,t.value,"security","session_max_renewals"))||0,onChange:r=>s("security.session_max_renewals",r),min:0,description:"Maximum number of times a session can be renewed"}),e(N,{label:W("max_sessions_per_wallet"),name:"security.max_sessions_per_wallet",type:"number",value:Number(U(a.value,t.value,"security","max_sessions_per_wallet"))||0,onChange:r=>s("security.max_sessions_per_wallet",r),min:1,max:100,description:"Maximum concurrent sessions for a single wallet"})]})}),e(Oe,{legend:"Rate Limits",description:"Request throttling per session and transaction",children:e("div",{class:"settings-fields-grid",children:[e(N,{label:W("max_pending_tx"),name:"security.max_pending_tx",type:"number",value:Number(U(a.value,t.value,"security","max_pending_tx"))||0,onChange:r=>s("security.max_pending_tx",r),min:1,max:100,description:"Maximum in-flight transactions per session"}),e(N,{label:W("rate_limit_session_rpm"),name:"security.rate_limit_session_rpm",type:"number",value:Number(U(a.value,t.value,"security","rate_limit_session_rpm"))||0,onChange:r=>s("security.rate_limit_session_rpm",r),min:10,description:"Max requests per minute per session"}),e(N,{label:W("rate_limit_tx_rpm"),name:"security.rate_limit_tx_rpm",type:"number",value:Number(U(a.value,t.value,"security","rate_limit_tx_rpm"))||0,onChange:r=>s("security.rate_limit_tx_rpm",r),min:1,description:"Max transaction requests per minute per session"})]})})]})]})]})}function ol(){const a=v("sessions");O(()=>{const h=J.value;h&&h.tab&&(a.value=h.tab,setTimeout(()=>{oe.value=h.fieldName},100),J.value=null)},[J.value]);const t=v([]),n=v(""),l=v(""),i=v([]),s=v(!1),o=v(!0),c=v(!1),m=v(!1),r=v(""),u=v(!1),d=v(""),f=v(!1),p=v(!1),b=v("api"),T=v(new Set),k=v(!1),D=v(!1),L=v([]),M=v(null),F=async()=>{try{const h=await B(C.WALLETS);t.value=h.items.filter(A=>A.status==="ACTIVE")}catch(h){const A=h instanceof _?h:new _(0,"UNKNOWN","Unknown error");y("error",I(A.code))}finally{o.value=!1}},w=async()=>{s.value=!0;try{const h=n.value?`${C.SESSIONS}?walletId=${n.value}`:C.SESSIONS,A=await B(h);i.value=A}catch(h){const A=h instanceof _?h:new _(0,"UNKNOWN","Unknown error");y("error",I(A.code))}finally{s.value=!1}},x=async()=>{c.value=!0;try{const h=await Q(C.SESSIONS,{walletId:n.value});r.value=h.token,m.value=!0,await w()}catch(h){const A=h instanceof _?h:new _(0,"UNKNOWN","Unknown error");y("error",I(A.code))}finally{c.value=!1}},R=h=>{const A=new Set(T.value);A.has(h)?A.delete(h):A.add(h),T.value=A},j=()=>{T.value.size===t.value.length?T.value=new Set:T.value=new Set(t.value.map(h=>h.id))},q=async()=>{if(T.value.size!==0){k.value=!0;try{const h=Array.from(T.value);if(b.value==="mcp"){const A=await Q(C.ADMIN_BULK_MCP_TOKENS,{walletIds:h});L.value=A.results,M.value=A.claudeDesktopConfig}else{const A=await Q(C.ADMIN_BULK_SESSIONS,{walletIds:h});L.value=A.results,M.value=null}p.value=!1,D.value=!0,await w()}catch(h){const A=h instanceof _?h:new _(0,"UNKNOWN","Unknown error");y("error",I(A.code))}finally{k.value=!1}}},X=async()=>{f.value=!0;try{await De(C.SESSION(d.value)),y("success","Session revoked"),u.value=!1,await w()}catch(h){const A=h instanceof _?h:new _(0,"UNKNOWN","Unknown error");y("error",I(A.code))}finally{f.value=!1}};O(()=>{F()},[]),O(()=>{i.value=[],w()},[n.value]);const G=[{key:"id",header:"ID",render:h=>h.id.slice(0,8)+"..."},{key:"walletName",header:"Wallet",render:h=>h.walletName??h.walletId.slice(0,8)+"..."},{key:"source",header:"Source",render:h=>e(P,{variant:h.source==="mcp"?"info":"default",children:h.source==="mcp"?"MCP":"API"})},{key:"status",header:"Status",render:h=>e(P,{variant:h.status==="ACTIVE"?"success":h.status==="EXPIRED"?"warning":"danger",children:h.status})},{key:"expiresAt",header:"Expires At",render:h=>ie(h.expiresAt)},{key:"renewals",header:"Renewals",render:h=>`${h.renewalCount}/${h.maxRenewals}`},{key:"createdAt",header:"Created",render:h=>ie(h.createdAt)},{key:"actions",header:"Actions",render:h=>h.status==="ACTIVE"?e(E,{size:"sm",variant:"danger",onClick:()=>sl(h.id,d,u),children:"Revoke"}):null}];return e("div",{class:"page",children:[e(Ge,{pageName:"Sessions",tabName:ca.find(h=>h.key===a.value)?.label??"",onPageClick:()=>{a.value="sessions"}}),e(qe,{tabs:ca,activeTab:a.value,onTabChange:h=>{a.value=h}}),a.value==="sessions"&&e(z,{children:[e("div",{class:"session-controls",children:[e("div",{class:"session-wallet-select",children:[e("label",{for:"wallet-select",children:"Wallet"}),e("select",{id:"wallet-select",value:n.value,onChange:h=>{n.value=h.target.value},disabled:o.value,children:[e("option",{value:"",children:"All Wallets"}),t.value.map(h=>e("option",{value:h.id,children:[h.name," (",h.chain,"/",h.network,")"]},h.id))]})]}),e("div",{class:"session-wallet-select",children:[e("label",{for:"source-select",children:"Source"}),e("select",{id:"source-select",value:l.value,onChange:h=>{l.value=h.target.value},children:[e("option",{value:"",children:"All"}),e("option",{value:"api",children:"API"}),e("option",{value:"mcp",children:"MCP"})]})]}),e(E,{onClick:x,disabled:!n.value,loading:c.value,children:"Create Session"}),e(E,{variant:"secondary",onClick:()=>{T.value=new Set,b.value="api",p.value=!0},disabled:t.value.length===0,children:"Bulk Create"})]}),e(we,{columns:G,data:l.value?i.value.filter(h=>h.source===l.value):i.value,loading:s.value,emptyMessage:"No sessions"}),e(se,{open:m.value,title:"Session Created",onCancel:()=>{m.value=!1},cancelText:"Close",children:[e("p",{class:"token-warning",children:"Copy this token now. It will not be shown again."}),e("div",{class:"token-display",children:[e("code",{class:"token-value",children:r.value}),e(Le,{value:r.value,label:"Copy Token"})]})]}),e(se,{open:u.value,title:"Revoke Session",onCancel:()=>{u.value=!1},onConfirm:X,confirmText:"Revoke",confirmVariant:"danger",loading:f.value,children:e("p",{children:"Are you sure you want to revoke this session? The associated token will be immediately invalidated."})}),e(se,{open:p.value,title:"Bulk Create Sessions",onCancel:()=>{p.value=!1},onConfirm:q,confirmText:`Create ${T.value.size} ${b.value==="mcp"?"MCP Tokens":"Sessions"}`,confirmDisabled:T.value.size===0,loading:k.value,children:[e("div",{style:{marginBottom:"var(--space-3)"},children:[e("label",{style:{fontWeight:600,display:"block",marginBottom:"var(--space-2)"},children:"Type"}),e("div",{style:{display:"flex",gap:"var(--space-3)"},children:[e("label",{style:{cursor:"pointer"},children:[e("input",{type:"radio",name:"bulkType",checked:b.value==="api",onChange:()=>{b.value="api"}})," API Session"]}),e("label",{style:{cursor:"pointer"},children:[e("input",{type:"radio",name:"bulkType",checked:b.value==="mcp",onChange:()=>{b.value="mcp"}})," MCP Token"]})]})]}),e("div",{children:[e("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"var(--space-2)"},children:[e("label",{style:{fontWeight:600},children:"Select Wallets"}),e("button",{type:"button",class:"btn btn-sm",onClick:j,children:T.value.size===t.value.length?"Deselect All":"Select All"})]}),e("div",{style:{maxHeight:"250px",overflow:"auto",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",padding:"var(--space-2)"},children:t.value.map(h=>e("label",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)",padding:"var(--space-1) 0",cursor:"pointer"},children:[e("input",{type:"checkbox",checked:T.value.has(h.id),onChange:()=>R(h.id)}),e("span",{children:h.name}),e("span",{style:{color:"var(--color-text-secondary)",fontSize:"0.8rem"},children:["(",h.chain,"/",h.network,")"]})]},h.id))})]})]}),e(se,{open:D.value,title:"Bulk Creation Results",onCancel:()=>{D.value=!1},cancelText:"Close",children:[e("div",{style:{marginBottom:"var(--space-3)"},children:e("p",{children:["Created: ",e("strong",{children:L.value.filter(h=>!h.error).length})," / Failed: ",e("strong",{children:L.value.filter(h=>h.error).length})]})}),e("div",{style:{maxHeight:"200px",overflow:"auto",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",padding:"var(--space-2)"},children:L.value.map(h=>e("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"var(--space-1) 0",borderBottom:"1px solid var(--color-border)"},children:[e("span",{children:h.walletName??h.walletId.slice(0,8)}),h.error?e(P,{variant:"danger",children:h.error}):e(P,{variant:"success",children:"Created"})]},h.walletId))}),M.value&&Object.keys(M.value).length>0&&e("div",{style:{marginTop:"var(--space-3)"},children:[e("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"var(--space-2)"},children:[e("label",{style:{fontWeight:600},children:"Claude Desktop Config"}),e(Le,{value:JSON.stringify({mcpServers:M.value},null,2),label:"Copy Config"})]}),e("pre",{style:{fontSize:"0.75rem",maxHeight:"150px",overflow:"auto",background:"var(--color-bg-secondary)",padding:"var(--space-2)",borderRadius:"var(--radius-md)"},children:JSON.stringify({mcpServers:M.value},null,2)})]})]})]}),a.value==="settings"&&e(rl,{})]})}function cl({rules:a,onChange:t,errors:n}){const l=s=>o=>{t({...a,[s]:o})},i=s=>o=>{const c=Number(o),m={...a};o===""||o===0||Number.isNaN(c)?delete m[s]:m[s]=c,t(m)};return e("div",{class:"policy-form-fields",children:[e("h4",{children:"Native Amount Tiers"}),e("div",{class:"policy-form-grid",children:[e(N,{label:"Instant Max (lamports/wei)",name:"instant_max",value:a.instant_max||"",onChange:l("instant_max"),error:n.instant_max,required:!0}),e(N,{label:"Notify Max (lamports/wei)",name:"notify_max",value:a.notify_max||"",onChange:l("notify_max"),error:n.notify_max,required:!0}),e(N,{label:"Delay Max (lamports/wei)",name:"delay_max",value:a.delay_max||"",onChange:l("delay_max"),error:n.delay_max,required:!0})]}),e("h4",{children:"USD Amount Tiers (Optional)"}),e("div",{class:"policy-form-grid",children:[e(N,{label:"Instant Max USD",name:"instant_max_usd",type:"number",value:a.instant_max_usd??"",onChange:i("instant_max_usd"),placeholder:"Optional"}),e(N,{label:"Notify Max USD",name:"notify_max_usd",type:"number",value:a.notify_max_usd??"",onChange:i("notify_max_usd"),placeholder:"Optional"}),e(N,{label:"Delay Max USD",name:"delay_max_usd",type:"number",value:a.delay_max_usd??"",onChange:i("delay_max_usd"),placeholder:"Optional"})]}),e("h4",{children:"Cumulative USD Limits (Optional)"}),e("div",{class:"policy-form-grid",children:[e(N,{label:"Daily Limit USD (24h rolling)",name:"daily_limit_usd",type:"number",value:a.daily_limit_usd??"",onChange:i("daily_limit_usd"),placeholder:"e.g. 500",error:n.daily_limit_usd}),e(N,{label:"Monthly Limit USD (30d rolling)",name:"monthly_limit_usd",type:"number",value:a.monthly_limit_usd??"",onChange:i("monthly_limit_usd"),placeholder:"e.g. 5000",error:n.monthly_limit_usd})]}),e(N,{label:"Delay Duration (seconds, min 60)",name:"delay_seconds",type:"number",value:a.delay_seconds??900,onChange:l("delay_seconds"),error:n.delay_seconds,required:!0,min:60})]})}function pe({items:a,onAdd:t,onRemove:n,renderRow:l,onChange:i,addLabel:s="+ Add",minItems:o=0,error:c}){return e("div",{class:"dynamic-row-list",children:[a.map((m,r)=>e("div",{class:"dynamic-row",children:[e("div",{class:"dynamic-row-fields",children:l(m,r,i)}),e("button",{class:"btn btn-ghost btn-sm dynamic-row-remove",onClick:()=>n(r),disabled:a.length<=o,title:"Remove",children:"x"})]},r)),e("button",{class:"btn btn-secondary btn-sm",onClick:t,children:s}),c&&e("span",{class:"form-error",children:c})]})}function dl({rules:a,onChange:t,errors:n}){const l=a.allowed_addresses||[];return e("div",{class:"policy-form-fields",children:e(pe,{items:l,onAdd:()=>t({...a,allowed_addresses:[...l,""]}),onRemove:i=>t({...a,allowed_addresses:l.filter((s,o)=>o!==i)}),onChange:(i,s)=>{const o=[...l];o[i]=s,t({...a,allowed_addresses:o})},renderRow:(i,s,o)=>e(N,{label:`Address ${s+1}`,name:`address-${s}`,value:i,onChange:c=>o(s,c),placeholder:"Wallet address",error:n[`allowed_addresses.${s}`],required:!0}),addLabel:"+ Add Address",error:n.allowed_addresses})})}function ul({rules:a,onChange:t,errors:n}){const l=i=>s=>{t({...a,[i]:s})};return e("div",{class:"policy-form-fields",children:[e(N,{label:"Max Requests",name:"max_requests",type:"number",value:a.max_requests??100,onChange:l("max_requests"),error:n.max_requests,required:!0,min:1}),e(N,{label:"Window (seconds)",name:"window_seconds",type:"number",value:a.window_seconds??3600,onChange:l("window_seconds"),error:n.window_seconds,required:!0,min:1})]})}function vl({rules:a,onChange:t,errors:n}){const l=i=>{const s={...a};i===""||i===void 0?delete s.maxAmount:s.maxAmount=i,t(s)};return e("div",{class:"policy-form-fields",children:[e(N,{label:"Max Amount (lamports/wei, optional)",name:"maxAmount",value:a.maxAmount??"",onChange:l,error:n.maxAmount,placeholder:"Leave empty for no limit"}),e(N,{label:"Block Unlimited Approvals",name:"blockUnlimited",type:"checkbox",value:a.blockUnlimited??!0,onChange:i=>t({...a,blockUnlimited:i})})]})}const hl=[{label:"Instant",value:"INSTANT"},{label:"Notify",value:"NOTIFY"},{label:"Delay",value:"DELAY"},{label:"Approval",value:"APPROVAL"}];function ml({rules:a,onChange:t,errors:n}){return e("div",{class:"policy-form-fields",children:e(N,{label:"Override Tier",name:"tier",type:"select",value:a.tier??"DELAY",onChange:l=>t({...a,tier:l}),options:hl,error:n.tier})})}const pl=[{label:"All Chains",value:""},{label:"Solana",value:"solana"},{label:"Ethereum",value:"ethereum"}];function fl({rules:a,onChange:t,errors:n}){const l=a.tokens||[];return e("div",{class:"policy-form-fields",children:e(pe,{items:l,onAdd:()=>t({...a,tokens:[...l,{address:"",symbol:"",chain:""}]}),onRemove:i=>t({...a,tokens:l.filter((s,o)=>o!==i)}),onChange:(i,s)=>{const o=[...l];o[i]=s,t({...a,tokens:o})},renderRow:(i,s,o)=>e("div",{class:"dynamic-row-fields",style:{display:"flex",gap:"0.5rem",flex:1},children:[e(N,{label:`Address ${s+1}`,name:`token-addr-${s}`,value:i.address,onChange:c=>o(s,{...i,address:c}),placeholder:"Token mint/contract address",error:n[`tokens.${s}.address`],required:!0}),e(N,{label:"Symbol",name:`token-symbol-${s}`,value:i.symbol,onChange:c=>o(s,{...i,symbol:c}),placeholder:"e.g. USDC"}),e(N,{label:"Chain",name:`token-chain-${s}`,type:"select",value:i.chain,onChange:c=>{const m={...i,chain:c};c||delete m.chain,o(s,m)},options:pl})]}),addLabel:"+ Add Token",error:n.tokens})})}const _l=[{label:"All Chains",value:""},{label:"Solana",value:"solana"},{label:"Ethereum",value:"ethereum"}];function yl({rules:a,onChange:t,errors:n}){const l=a.contracts||[];return e("div",{class:"policy-form-fields",children:e(pe,{items:l,onAdd:()=>t({...a,contracts:[...l,{address:"",name:"",chain:""}]}),onRemove:i=>t({...a,contracts:l.filter((s,o)=>o!==i)}),onChange:(i,s)=>{const o=[...l];o[i]=s,t({...a,contracts:o})},renderRow:(i,s,o)=>e("div",{class:"dynamic-row-fields",style:{display:"flex",gap:"0.5rem",flex:1},children:[e(N,{label:`Address ${s+1}`,name:`contract-addr-${s}`,value:i.address,onChange:c=>o(s,{...i,address:c}),placeholder:"Contract address",error:n[`contracts.${s}.address`],required:!0}),e(N,{label:"Name",name:`contract-name-${s}`,value:i.name,onChange:c=>o(s,{...i,name:c}),placeholder:"e.g. Uniswap Router"}),e(N,{label:"Chain",name:`contract-chain-${s}`,type:"select",value:i.chain,onChange:c=>{const m={...i,chain:c};c||delete m.chain,o(s,m)},options:_l})]}),addLabel:"+ Add Contract",error:n.contracts})})}function gl({rules:a,onChange:t,errors:n}){const l=a.methods||[],i=s=>{t({...a,methods:s})};return e("div",{class:"policy-form-fields",children:e(pe,{items:l,onAdd:()=>i([...l,{contractAddress:"",selectors:[""]}]),onRemove:s=>i(l.filter((o,c)=>c!==s)),onChange:(s,o)=>{const c=[...l];c[s]=o,i(c)},renderRow:(s,o,c)=>e("div",{style:{flex:1},children:[e(N,{label:`Contract Address ${o+1}`,name:`method-addr-${o}`,value:s.contractAddress,onChange:m=>c(o,{...s,contractAddress:m}),placeholder:"Contract address",error:n[`methods.${o}.contractAddress`],required:!0}),e("div",{style:{marginTop:"0.5rem",marginLeft:"1rem"},children:[e("label",{style:{fontSize:"0.85rem",fontWeight:500},children:"Selectors"}),e(pe,{items:s.selectors,onAdd:()=>c(o,{...s,selectors:[...s.selectors,""]}),onRemove:m=>c(o,{...s,selectors:s.selectors.filter((r,u)=>u!==m)}),onChange:(m,r)=>{const u=[...s.selectors];u[m]=r,c(o,{...s,selectors:u})},renderRow:(m,r,u)=>e(N,{label:`Selector ${r+1}`,name:`method-sel-${o}-${r}`,value:m,onChange:d=>u(r,d),placeholder:"e.g. 0xa9059cbb or transfer(address,uint256)",error:n[`methods.${o}.selectors.${r}`],required:!0}),addLabel:"+ Add Selector",error:n[`methods.${o}.selectors`]})]})]}),addLabel:"+ Add Method Entry",error:n.methods})})}function bl({rules:a,onChange:t,errors:n}){const l=a.spenders||[];return e("div",{class:"policy-form-fields",children:e(pe,{items:l,onAdd:()=>t({...a,spenders:[...l,{address:"",name:"",maxAmount:""}]}),onRemove:i=>t({...a,spenders:l.filter((s,o)=>o!==i)}),onChange:(i,s)=>{const o=[...l];o[i]=s,s.maxAmount||delete o[i].maxAmount,t({...a,spenders:o})},renderRow:(i,s,o)=>e("div",{class:"dynamic-row-fields",style:{display:"flex",gap:"0.5rem",flex:1},children:[e(N,{label:`Address ${s+1}`,name:`spender-addr-${s}`,value:i.address,onChange:c=>o(s,{...i,address:c}),placeholder:"Spender address",error:n[`spenders.${s}.address`],required:!0}),e(N,{label:"Name",name:`spender-name-${s}`,value:i.name,onChange:c=>o(s,{...i,name:c}),placeholder:"e.g. Uniswap"}),e(N,{label:"Max Amount",name:`spender-max-${s}`,value:i.maxAmount||"",onChange:c=>o(s,{...i,maxAmount:c}),placeholder:"Leave empty for unlimited",error:n[`spenders.${s}.maxAmount`]})]}),addLabel:"+ Add Spender",error:n.spenders})})}const wl=Array.from({length:24},(a,t)=>({label:`${String(t).padStart(2,"0")}:00`,value:String(t)})),Sl=Array.from({length:24},(a,t)=>({label:`${String(t+1).padStart(2,"0")}:00`,value:String(t+1)})),kl=[{label:"Sun",value:0},{label:"Mon",value:1},{label:"Tue",value:2},{label:"Wed",value:3},{label:"Thu",value:4},{label:"Fri",value:5},{label:"Sat",value:6}];function Nl({rules:a,onChange:t,errors:n}){const l=a.allowed_hours||{start:0,end:24},i=a.allowed_days||[],s=c=>m=>{const r={...l,[c]:Number(m)};t({...a,allowed_hours:r})},o=c=>{const m=i.includes(c)?i.filter(r=>r!==c):[...i,c].sort((r,u)=>r-u);t({...a,allowed_days:m})};return e("div",{class:"policy-form-fields",children:[e("h4",{children:"Allowed Hours"}),e("div",{class:"policy-form-grid",children:[e(N,{label:"Start Hour",name:"allowed_hours_start",type:"select",value:String(l.start),onChange:s("start"),options:wl,error:n.allowed_hours}),e(N,{label:"End Hour",name:"allowed_hours_end",type:"select",value:String(l.end),onChange:s("end"),options:Sl})]}),e("h4",{children:"Allowed Days"}),e("div",{style:{display:"flex",gap:"0.75rem",flexWrap:"wrap"},children:kl.map(c=>e("label",{style:{display:"flex",alignItems:"center",gap:"0.25rem",cursor:"pointer"},children:[e("input",{type:"checkbox",checked:i.includes(c.value),onChange:()=>o(c.value)}),c.label]},c.value))}),n.allowed_days&&e("span",{class:"form-error",children:n.allowed_days})]})}const Tl=[{label:"mainnet",value:"mainnet"},{label:"devnet",value:"devnet"},{label:"testnet",value:"testnet"},{label:"ethereum-mainnet",value:"ethereum-mainnet"},{label:"ethereum-sepolia",value:"ethereum-sepolia"},{label:"polygon-mainnet",value:"polygon-mainnet"},{label:"polygon-amoy",value:"polygon-amoy"},{label:"arbitrum-mainnet",value:"arbitrum-mainnet"},{label:"arbitrum-sepolia",value:"arbitrum-sepolia"},{label:"optimism-mainnet",value:"optimism-mainnet"},{label:"optimism-sepolia",value:"optimism-sepolia"},{label:"base-mainnet",value:"base-mainnet"},{label:"base-sepolia",value:"base-sepolia"}];function Cl({rules:a,onChange:t,errors:n}){const l=a.networks||[];return e("div",{class:"policy-form-fields",children:e(pe,{items:l,onAdd:()=>t({...a,networks:[...l,{network:"mainnet",name:""}]}),onRemove:i=>t({...a,networks:l.filter((s,o)=>o!==i)}),onChange:(i,s)=>{const o=[...l];o[i]=s,t({...a,networks:o})},renderRow:(i,s,o)=>e("div",{class:"dynamic-row-fields",style:{display:"flex",gap:"0.5rem",flex:1},children:[e(N,{label:`Network ${s+1}`,name:`network-sel-${s}`,type:"select",value:i.network,onChange:c=>o(s,{...i,network:c}),options:Tl,error:n[`networks.${s}.network`],required:!0}),e(N,{label:"Label",name:`network-name-${s}`,value:i.name,onChange:c=>o(s,{...i,name:c}),placeholder:"Optional label"})]}),addLabel:"+ Add Network",error:n.networks})})}function El({rules:a,onChange:t,errors:n}){const l=a.domains||[];return e("div",{class:"policy-form-fields",children:e(pe,{items:l,onAdd:()=>t({...a,domains:[...l,""]}),onRemove:i=>t({...a,domains:l.filter((s,o)=>o!==i)}),onChange:(i,s)=>{const o=[...l];o[i]=s,t({...a,domains:o})},renderRow:(i,s,o)=>e(N,{label:`Domain ${s+1}`,name:`domain-${s}`,value:i,onChange:c=>o(s,c),placeholder:"e.g. api.example.com or *.service.io",error:n[`domains.${s}`],required:!0}),addLabel:"+ Add Domain",error:n.domains})})}function da({type:a,rules:t,onChange:n,errors:l}){switch(a){case"SPENDING_LIMIT":return e(cl,{rules:t,onChange:n,errors:l});case"WHITELIST":return e(dl,{rules:t,onChange:n,errors:l});case"RATE_LIMIT":return e(ul,{rules:t,onChange:n,errors:l});case"APPROVE_AMOUNT_LIMIT":return e(vl,{rules:t,onChange:n,errors:l});case"APPROVE_TIER_OVERRIDE":return e(ml,{rules:t,onChange:n,errors:l});case"ALLOWED_TOKENS":return e(fl,{rules:t,onChange:n,errors:l});case"CONTRACT_WHITELIST":return e(yl,{rules:t,onChange:n,errors:l});case"METHOD_WHITELIST":return e(gl,{rules:t,onChange:n,errors:l});case"APPROVED_SPENDERS":return e(bl,{rules:t,onChange:n,errors:l});case"TIME_RESTRICTION":return e(Nl,{rules:t,onChange:n,errors:l});case"ALLOWED_NETWORKS":return e(Cl,{rules:t,onChange:n,errors:l});case"X402_ALLOWED_DOMAINS":return e(El,{rules:t,onChange:n,errors:l});default:return e("p",{class:"policy-form-placeholder",children:"This policy type uses JSON editor. Toggle to JSON mode."})}}function Ut(a){const t=typeof a=="string"?Number(a):a;return Number.isNaN(t)?String(a):t.toLocaleString("en-US")}function Al(a){return a===86400?"1d":a%86400===0?`${a/86400}d`:a===3600?"1h":a%3600===0?`${a/3600}h`:a===60?"1m":a%60===0?`${a/60}m`:`${a}s`}const Ct=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function Il(a){if(!a||a.length===0)return"";const t=[...a].sort((l,i)=>l-i);let n=!0;for(let l=1;l<t.length;l++)if(t[l]!==t[l-1]+1){n=!1;break}return n&&t.length>2?`${Ct[t[0]]}-${Ct[t[t.length-1]]}`:t.map(l=>Ct[l]??String(l)).join(", ")}function ua(a){return String(a).padStart(2,"0")}function Dl({rules:a}){const t=Number(a.instant_max??0),n=Number(a.notify_max??0),l=Number(a.delay_max??0),i=Math.max(t,n,l,1),s=[{label:"Instant",value:a.instant_max,width:t/i*100,cls:"instant"},{label:"Notify",value:a.notify_max,width:n/i*100,cls:"notify"},{label:"Delay",value:a.delay_max,width:l/i*100,cls:"delay"},{label:"Approval",value:"",width:100,cls:"approval"}];return e("div",{class:"tier-bars",children:s.map(o=>e("div",{class:"tier-bar",children:[e("span",{class:"tier-bar-label",children:o.label}),e("div",{class:"tier-bar-track",children:e("div",{class:`tier-bar-fill tier-bar-fill--${o.cls}`,style:{width:`${o.width}%`}})}),e("span",{class:"tier-bar-value",children:o.value?Ut(o.value):""})]},o.cls))})}function va(a){return a.toLocaleString("en-US",{minimumFractionDigits:0,maximumFractionDigits:2})}function Ll({rules:a}){const t=a.daily_limit_usd,n=a.monthly_limit_usd;return!t&&!n?null:e("div",{class:"cumulative-limits",children:[e("div",{class:"cumulative-limits-label",children:"Cumulative Limits"}),t&&e("div",{class:"cumulative-limit-row",children:[e("span",{class:"cumulative-limit-type",children:"Daily (24h)"}),e("span",{class:"cumulative-limit-value",children:["$",va(t)]})]}),n&&e("div",{class:"cumulative-limit-row",children:[e("span",{class:"cumulative-limit-type",children:"Monthly (30d)"}),e("span",{class:"cumulative-limit-value",children:["$",va(n)]})]})]})}const Ol={INSTANT:"success",NOTIFY:"info",DELAY:"warning",APPROVAL:"danger"};function xl({type:a,rules:t}){switch(a){case"SPENDING_LIMIT":return e("div",{class:"spending-limit-summary",children:[e(Dl,{rules:t}),e(Ll,{rules:t})]});case"ALLOWED_TOKENS":{const n=t.tokens||[];return n.length===0?e("span",{class:"rules-vis-text",children:"No tokens"}):e("div",{class:"rules-vis-badges",children:n.map((l,i)=>e(P,{variant:"info",children:l.symbol||(l.address?l.address.slice(0,8)+"...":"?")},i))})}case"RATE_LIMIT":{const n=t.max_requests,l=t.window_seconds;return e("span",{class:"rules-vis-text",children:[n," req / ",Al(l)]})}case"WHITELIST":{const n=t.allowed_addresses||[];return e(P,{variant:"neutral",children:[n.length," addresses"]})}case"TIME_RESTRICTION":{const n=t.allowed_days||[],l=t.allowed_hours,i=Il(n),s=l?`${ua(l.start)}:00-${ua(l.end)}:00`:"";return e("span",{class:"rules-vis-text",children:[i," ",s]})}case"CONTRACT_WHITELIST":{const n=t.contracts||[];if(n.length===0)return e("span",{class:"rules-vis-text",children:"No contracts"});const l=n.slice(0,3),i=n.length-3;return e("div",{class:"rules-vis-badges",children:[l.map((s,o)=>e(P,{variant:"neutral",children:s.name||(s.address?s.address.slice(0,8)+"...":"?")},o)),i>0&&e(P,{variant:"neutral",children:["+",i," more"]})]})}case"METHOD_WHITELIST":{const n=t.methods||[],l=n.length,i=n.reduce((s,o)=>s+(o.selectors?.length||0),0);return e(P,{variant:"neutral",children:[l," contracts, ",i," methods"]})}case"APPROVED_SPENDERS":{const n=t.spenders||[];return e(P,{variant:"neutral",children:[n.length," spenders"]})}case"APPROVE_AMOUNT_LIMIT":{const n=t.maxAmount,l=t.blockUnlimited;return n&&l?e("span",{class:"rules-vis-text",children:["Max: ",Ut(n)," + Block unlimited"]}):n?e("span",{class:"rules-vis-text",children:["Max: ",Ut(n)]}):l?e("span",{class:"rules-vis-text",children:"Block unlimited only"}):e("span",{class:"rules-vis-text",children:"No limits"})}case"APPROVE_TIER_OVERRIDE":{const n=t.tier||"DELAY",l=Ol[n]||"neutral";return e(P,{variant:l,children:n})}case"ALLOWED_NETWORKS":{const n=t.networks||[];if(n.length===0)return e("span",{class:"rules-vis-text",children:"No networks"});const l=n.slice(0,3),i=n.length-3;return e("div",{class:"rules-vis-badges",children:[l.map((s,o)=>e(P,{variant:"info",children:s.network},o)),i>0&&e(P,{variant:"info",children:["+",i," more"]})]})}case"X402_ALLOWED_DOMAINS":{const n=t.domains||[];if(n.length===0)return e("span",{class:"rules-vis-text",children:"No domains"});const l=n.slice(0,3),i=n.length-3;return e("div",{class:"rules-vis-badges",children:[l.map((s,o)=>e(P,{variant:"neutral",children:s},o)),i>0&&e(P,{variant:"neutral",children:["+",i," more"]})]})}default:{const n=JSON.stringify(t);return e("span",{class:"rules-summary",children:n.length>60?n.slice(0,60)+"...":n})}}}const Ga=[{label:"Spending Limit",value:"SPENDING_LIMIT"},{label:"Whitelist",value:"WHITELIST"},{label:"Time Restriction",value:"TIME_RESTRICTION"},{label:"Rate Limit",value:"RATE_LIMIT"},{label:"Allowed Tokens",value:"ALLOWED_TOKENS"},{label:"Contract Whitelist",value:"CONTRACT_WHITELIST"},{label:"Method Whitelist",value:"METHOD_WHITELIST"},{label:"Approved Spenders",value:"APPROVED_SPENDERS"},{label:"Approve Amount Limit",value:"APPROVE_AMOUNT_LIMIT"},{label:"Approve Tier Override",value:"APPROVE_TIER_OVERRIDE"},{label:"Allowed Networks",value:"ALLOWED_NETWORKS"},{label:"x402 Allowed Domains",value:"X402_ALLOWED_DOMAINS"}],We={SPENDING_LIMIT:{instant_max:"1000000",notify_max:"5000000",delay_max:"10000000",delay_seconds:300,approval_timeout:3600},WHITELIST:{allowed_addresses:[]},TIME_RESTRICTION:{allowed_hours:{start:0,end:24},allowed_days:[0,1,2,3,4,5,6]},RATE_LIMIT:{max_requests:100,window_seconds:3600},ALLOWED_TOKENS:{tokens:[]},CONTRACT_WHITELIST:{contracts:[]},METHOD_WHITELIST:{methods:[]},APPROVED_SPENDERS:{spenders:[]},APPROVE_AMOUNT_LIMIT:{maxAmount:"1000000",blockUnlimited:!0},APPROVE_TIER_OVERRIDE:{tier:"DELAY"},ALLOWED_NETWORKS:{networks:[]},X402_ALLOWED_DOMAINS:{domains:[]}};function tt(a,t){const n={};if(a==="SPENDING_LIMIT"){(!t.instant_max||!/^\d+$/.test(t.instant_max))&&(n.instant_max="Positive integer required"),(!t.notify_max||!/^\d+$/.test(t.notify_max))&&(n.notify_max="Positive integer required"),(!t.delay_max||!/^\d+$/.test(t.delay_max))&&(n.delay_max="Positive integer required");const l=Number(t.delay_seconds);(t.delay_seconds===void 0||t.delay_seconds===""||Number.isNaN(l)||l<60)&&(n.delay_seconds="Minimum 60 seconds");const i=t.daily_limit_usd;if(i!==void 0&&i!==""){const o=Number(i);(Number.isNaN(o)||o<=0)&&(n.daily_limit_usd="Must be a positive number")}const s=t.monthly_limit_usd;if(s!==void 0&&s!==""){const o=Number(s);(Number.isNaN(o)||o<=0)&&(n.monthly_limit_usd="Must be a positive number")}}else if(a==="WHITELIST"){const l=t.allowed_addresses||[];l.length===0&&(n.allowed_addresses="At least one address required"),l.forEach((i,s)=>{(!i||i.trim()==="")&&(n[`allowed_addresses.${s}`]="Address required")})}else if(a==="RATE_LIMIT"){const l=Number(t.max_requests);(!t.max_requests||Number.isNaN(l)||l<1||!Number.isInteger(l))&&(n.max_requests="Positive integer required");const i=Number(t.window_seconds);(!t.window_seconds||Number.isNaN(i)||i<1||!Number.isInteger(i))&&(n.window_seconds="Positive integer required")}else if(a==="APPROVE_AMOUNT_LIMIT")t.maxAmount&&!/^\d+$/.test(t.maxAmount)&&(n.maxAmount="Must be a positive integer string");else if(a==="ALLOWED_TOKENS"){const l=t.tokens||[];l.length===0&&(n.tokens="At least one token required"),l.forEach((i,s)=>{(!i.address||i.address.trim()==="")&&(n[`tokens.${s}.address`]="Address required")})}else if(a==="CONTRACT_WHITELIST"){const l=t.contracts||[];l.length===0&&(n.contracts="At least one contract required"),l.forEach((i,s)=>{(!i.address||i.address.trim()==="")&&(n[`contracts.${s}.address`]="Address required")})}else if(a==="METHOD_WHITELIST"){const l=t.methods||[];l.length===0&&(n.methods="At least one method entry required"),l.forEach((i,s)=>{(!i.contractAddress||i.contractAddress.trim()==="")&&(n[`methods.${s}.contractAddress`]="Contract address required"),!i.selectors||i.selectors.length===0?n[`methods.${s}.selectors`]="At least one selector required":i.selectors.forEach((o,c)=>{(!o||o.trim()==="")&&(n[`methods.${s}.selectors.${c}`]="Selector required")})})}else if(a==="APPROVED_SPENDERS"){const l=t.spenders||[];l.length===0&&(n.spenders="At least one spender required"),l.forEach((i,s)=>{(!i.address||i.address.trim()==="")&&(n[`spenders.${s}.address`]="Address required"),i.maxAmount&&!/^\d+$/.test(i.maxAmount)&&(n[`spenders.${s}.maxAmount`]="Must be a positive integer")})}else if(a==="TIME_RESTRICTION"){(t.allowed_days||[]).length===0&&(n.allowed_days="At least one day required");const i=t.allowed_hours;i&&i.start>=i.end&&(n.allowed_hours="Start must be before end")}else if(a==="ALLOWED_NETWORKS"){const l=t.networks||[];l.length===0&&(n.networks="At least one network required"),l.forEach((i,s)=>{(!i.network||i.network.trim()==="")&&(n[`networks.${s}.network`]="Network required")})}else if(a==="X402_ALLOWED_DOMAINS"){const l=t.domains||[];l.length===0&&(n.domains="At least one domain required"),l.forEach((i,s)=>{(!i||i.trim()==="")&&(n[`domains.${s}`]="Domain required")})}return n}function Rl(a,t){if(!a)return"Global";const n=t.find(l=>l.id===a);return n?n.name:a.slice(0,8)+"..."}function Et(a){const t=Ga.find(n=>n.value===a);return t?t.label:a}const ha=[{key:"policies",label:"Policies"},{key:"defaults",label:"Defaults"}],At=["security.policy_defaults_delay_seconds","security.policy_defaults_approval_timeout","policy.default_deny_tokens","policy.default_deny_contracts","policy.default_deny_spenders"];function Pl(){const a=v({}),t=v({}),n=v(!1),l=v(!0),i=async()=>{try{const r=await B(C.ADMIN_SETTINGS);a.value=r}catch(r){const u=r instanceof _?r:new _(0,"UNKNOWN","Unknown error");y("error",I(u.code))}finally{l.value=!1}};O(()=>{i()},[]);const s=(r,u)=>{const d=String(u);t.value={...t.value,[r]:d}},o=async()=>{n.value=!0;try{const r=Object.entries(t.value).filter(([u])=>At.includes(u)).map(([u,d])=>({key:u,value:d}));await le(C.ADMIN_SETTINGS,{settings:r}),t.value={},await i(),y("success","Policy defaults saved and applied")}catch(r){const u=r instanceof _?r:new _(0,"UNKNOWN","Unknown error");y("error",I(u.code))}finally{n.value=!1}},c=()=>{t.value={}};O(()=>(fe({id:"policies-defaults",isDirty:()=>Object.keys(t.value).filter(r=>At.includes(r)).length>0,save:o,discard:c}),()=>_e("policies-defaults")),[]);const m=Object.keys(t.value).filter(r=>At.includes(r)).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(z,{children:[m>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[m," unsaved change",m>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(E,{variant:"ghost",size:"sm",onClick:c,children:"Discard"}),e(E,{variant:"primary",size:"sm",onClick:o,loading:n.value,children:"Save"})]})]}),e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Policy Defaults"}),e("p",{class:"settings-description",children:"Configure default delay, approval timeout, and default-deny policies. Changes apply immediately without daemon restart."})]}),e("div",{class:"settings-category-body",children:[e("div",{class:"settings-fields-grid",children:[e(N,{label:W("policy_defaults_delay_seconds"),name:"security.policy_defaults_delay_seconds",type:"number",value:Number(U(a.value,t.value,"security","policy_defaults_delay_seconds"))||0,onChange:r=>s("security.policy_defaults_delay_seconds",r),min:0,description:"Default delay before executing delayed-tier transactions"}),e(N,{label:W("policy_defaults_approval_timeout"),name:"security.policy_defaults_approval_timeout",type:"number",value:Number(U(a.value,t.value,"security","policy_defaults_approval_timeout"))||0,onChange:r=>s("security.policy_defaults_approval_timeout",r),min:60,description:"How long to wait for owner approval before timeout"})]}),e("div",{class:"settings-subgroup",style:{marginTop:"1rem",borderTop:"1px solid var(--border)",paddingTop:"1rem"},children:[e("h4",{style:{margin:"0 0 0.5rem 0",fontSize:"0.875rem",fontWeight:600,color:"var(--text-secondary)"},children:"Default Deny Policies"}),e("div",{class:"settings-fields-grid",children:[e(N,{label:W("default_deny_tokens"),name:"policy.default_deny_tokens",type:"checkbox",value:Ae(a.value,t.value,"security","default_deny_tokens"),onChange:r=>s("policy.default_deny_tokens",r),description:"Deny token transfers unless a matching whitelist policy exists"}),e(N,{label:W("default_deny_contracts"),name:"policy.default_deny_contracts",type:"checkbox",value:Ae(a.value,t.value,"security","default_deny_contracts"),onChange:r=>s("policy.default_deny_contracts",r),description:"Deny contract calls unless a matching whitelist policy exists"}),e(N,{label:W("default_deny_spenders"),name:"policy.default_deny_spenders",type:"checkbox",value:Ae(a.value,t.value,"security","default_deny_spenders"),onChange:r=>s("policy.default_deny_spenders",r),description:"Deny token approvals unless a matching whitelist policy exists"})]})]}),e("div",{class:"settings-info-box",children:"When enabled, transactions are denied if no matching whitelist policy exists. Disable to allow all transactions of that type when no policy is configured."})]})]})]})}function Wl(){const a=v("policies");O(()=>{const g=J.value;g&&g.tab&&(a.value=g.tab,setTimeout(()=>{oe.value=g.fieldName},100),J.value=null)},[J.value]);const t=v([]),n=v([]),l=v("__all__"),i=v(!1),s=v(!0),o=v(!1),c=v("SPENDING_LIMIT"),m=v(""),r=v(JSON.stringify(We.SPENDING_LIMIT,null,2)),u=v(We.SPENDING_LIMIT),d=v({}),f=v(!1),p=v(0),b=v(!0),T=v(""),k=v(null),D=v(!1),L=v(!1),M=v(null),F=v(""),w=v({}),x=v(!1),R=v({}),j=v(0),q=v(!0),X=v(null),G=v(!1),h=v(!1),A=v(null),ae=v(!1),_t=async()=>{try{const g=await B(C.WALLETS);t.value=g.items}catch(g){const H=g instanceof _?g:new _(0,"UNKNOWN","Unknown error");y("error",I(H.code))}finally{s.value=!1}},Se=async()=>{i.value=!0;try{let g=C.POLICIES;l.value!=="__all__"&&l.value!=="__global__"&&(g=`${C.POLICIES}?walletId=${l.value}`);const H=await B(g);l.value==="__global__"?n.value=H.filter(re=>re.walletId===null):n.value=H}catch(g){const H=g instanceof _?g:new _(0,"UNKNOWN","Unknown error");y("error",I(H.code))}finally{i.value=!1}},je=async()=>{k.value=null;let g;if(f.value)try{g=JSON.parse(r.value)}catch{k.value="Invalid JSON in rules field";return}else{const H=tt(c.value,u.value);if(Object.keys(H).length>0){d.value=H;return}d.value={},g=u.value}D.value=!0;try{await Q(C.POLICIES,{walletId:m.value||void 0,type:c.value,rules:g,priority:p.value,enabled:b.value,network:T.value||void 0}),y("success","Policy created"),o.value=!1,c.value="SPENDING_LIMIT",m.value="",T.value="",r.value=JSON.stringify(We.SPENDING_LIMIT,null,2),u.value=We.SPENDING_LIMIT,d.value={},f.value=!1,p.value=0,b.value=!0,k.value=null,await Se()}catch(H){const re=H instanceof _?H:new _(0,"UNKNOWN","Unknown error");y("error",I(re.code))}finally{D.value=!1}},Ye=g=>{M.value=g,F.value=JSON.stringify(g.rules,null,2),w.value={...g.rules},x.value=!1,R.value={},j.value=g.priority,q.value=g.enabled,X.value=null,L.value=!0},yt=async()=>{X.value=null;let g;if(x.value)try{g=JSON.parse(F.value)}catch{X.value="Invalid JSON in rules field";return}else{const H=tt(M.value.type,w.value);if(Object.keys(H).length>0){R.value=H;return}R.value={},g=w.value}G.value=!0;try{await le(C.POLICY(M.value.id),{rules:g,priority:j.value,enabled:q.value}),y("success","Policy updated"),L.value=!1,await Se()}catch(H){const re=H instanceof _?H:new _(0,"UNKNOWN","Unknown error");y("error",I(re.code))}finally{G.value=!1}},gt=()=>{if(!x.value)F.value=JSON.stringify(w.value,null,2);else try{w.value=JSON.parse(F.value),X.value=null}catch{X.value="Invalid JSON — cannot switch to form mode";return}x.value=!x.value},bt=g=>{A.value=g,h.value=!0},wt=async()=>{ae.value=!0;try{await De(C.POLICY(A.value.id)),y("success","Policy deleted"),h.value=!1,await Se()}catch(g){const H=g instanceof _?g:new _(0,"UNKNOWN","Unknown error");y("error",I(H.code))}finally{ae.value=!1}},St=g=>{const H=g;c.value=H;const re=We[H];re&&(r.value=JSON.stringify(re,null,2),u.value={...re}),d.value={},f.value=!1},kt=()=>{if(!f.value)r.value=JSON.stringify(u.value,null,2);else try{u.value=JSON.parse(r.value),k.value=null}catch{k.value="Invalid JSON — cannot switch to form mode";return}f.value=!f.value};O(()=>{_t()},[]),O(()=>{Se()},[l.value]);const Je=[{key:"type",header:"Type",render:g=>e(P,{variant:g.type==="SPENDING_LIMIT"?"success":"info",children:Et(g.type)})},{key:"walletId",header:"Wallet",render:g=>Rl(g.walletId,t.value)},{key:"network",header:"Network",render:g=>g.network??"All"},{key:"rules",header:"Rules",render:g=>e(xl,{type:g.type,rules:g.rules})},{key:"priority",header:"Priority"},{key:"enabled",header:"Enabled",render:g=>e(P,{variant:g.enabled?"success":"danger",children:g.enabled?"ON":"OFF"})},{key:"actions",header:"Actions",render:g=>e("span",{style:{display:"flex",gap:"0.25rem"},children:[e("button",{class:"btn btn-ghost btn-sm",onClick:H=>{H.stopPropagation(),Ye(g)},children:"Edit"}),e(E,{size:"sm",variant:"danger",onClick:()=>bt(g),children:"Delete"})]})}];return e("div",{class:"page",children:[e(Ge,{pageName:"Policies",tabName:ha.find(g=>g.key===a.value)?.label??"",onPageClick:()=>{a.value="policies"}}),e(qe,{tabs:ha,activeTab:a.value,onTabChange:g=>{a.value=g}}),a.value==="policies"&&e(z,{children:[e("div",{class:"policy-controls",children:[e("div",{class:"policy-filter-select",children:[e("label",{for:"policy-wallet-filter",children:"Filter by Wallet"}),e("select",{id:"policy-wallet-filter",value:l.value,onChange:g=>{l.value=g.target.value},disabled:s.value,children:[e("option",{value:"__all__",children:"All Policies"}),e("option",{value:"__global__",children:"Global Only"}),t.value.map(g=>e("option",{value:g.id,children:[g.name," (",g.chain,"/",g.network,")"]},g.id))]})]}),!o.value&&e(E,{onClick:()=>{o.value=!0},children:"Create Policy"})]}),o.value&&e("div",{class:"inline-form",children:[e(N,{label:"Type",name:"type",type:"select",value:c.value,onChange:St,options:Ga}),e(N,{label:"Wallet",name:"walletId",type:"select",value:m.value,onChange:g=>{m.value=g},options:[{label:"Global (no wallet)",value:""},...t.value.map(g=>({label:`${g.name} (${g.chain}/${g.network})`,value:g.id}))]}),e(N,{label:"Network Scope",name:"network",value:T.value,onChange:g=>{T.value=g},placeholder:"e.g. polygon-mainnet (leave empty for all networks)"}),e("div",{class:"policy-form-section",children:[e("div",{class:"policy-form-header",children:[e("label",{children:"Rules"}),e("button",{class:"btn btn-ghost btn-sm json-toggle",onClick:kt,children:f.value?"Switch to Form":"JSON Direct Edit"})]}),f.value?e(N,{label:"",name:"rules",type:"textarea",value:r.value,onChange:g=>{r.value=g},error:k.value??void 0}):e(da,{type:c.value,rules:u.value,onChange:g=>{u.value=g,Object.keys(d.value).length>0&&(d.value=tt(c.value,g))},errors:d.value})]}),e(N,{label:"Priority",name:"priority",type:"number",value:p.value,onChange:g=>{p.value=g},min:0,max:999}),e(N,{label:"Enabled",name:"enabled",type:"checkbox",value:b.value,onChange:g=>{b.value=g}}),e("div",{class:"inline-form-actions",children:[e(E,{onClick:je,loading:D.value,children:"Create"}),e(E,{variant:"secondary",onClick:()=>{o.value=!1,k.value=null},children:"Cancel"})]})]}),e(we,{columns:Je,data:n.value,loading:i.value,emptyMessage:"No policies found"}),e(se,{open:L.value,title:"Edit Policy",onCancel:()=>{L.value=!1},onConfirm:yt,confirmText:"Save",loading:G.value,children:M.value&&e("div",{children:[e("div",{class:"policy-type-readonly",children:["Type: ",Et(M.value.type)]}),e("div",{class:"policy-form-section",children:[e("div",{class:"policy-form-header",children:[e("label",{children:"Rules"}),e("button",{class:"btn btn-ghost btn-sm json-toggle",onClick:gt,children:x.value?"Switch to Form":"JSON Direct Edit"})]}),x.value?e("div",{class:"edit-rules-textarea",children:e(N,{label:"",name:"edit-rules",type:"textarea",value:F.value,onChange:g=>{F.value=g},error:X.value??void 0})}):e(da,{type:M.value.type,rules:w.value,onChange:g=>{w.value=g,Object.keys(R.value).length>0&&(R.value=tt(M.value.type,g))},errors:R.value})]}),e(N,{label:"Priority",name:"edit-priority",type:"number",value:j.value,onChange:g=>{j.value=g},min:0,max:999}),e(N,{label:"Enabled",name:"edit-enabled",type:"checkbox",value:q.value,onChange:g=>{q.value=g}})]})}),e(se,{open:h.value,title:"Delete Policy",onCancel:()=>{h.value=!1},onConfirm:wt,confirmText:"Delete",confirmVariant:"danger",loading:ae.value,children:A.value&&e("p",{children:["Are you sure you want to delete this"," ",e("strong",{children:Et(A.value.type)})," policy? This action cannot be undone."]})})]}),a.value==="defaults"&&e(Pl,{})]})}function Ml(){return e(Ul,{})}function Ul(){const a=v([]),t=v(!0),n=v(!1),l=v(null),i=v("ADMIN"),s=v(!1),o=v(!1),c=v(null),m=v(!1),r=async()=>{t.value=!0;try{const k=await B(C.ADMIN_TELEGRAM_USERS);a.value=k.users}catch(k){const D=k instanceof _?k:new _(0,"UNKNOWN","Unknown error");y("error",I(D.code))}finally{t.value=!1}};O(()=>{r()},[]);const u=k=>{l.value=k,i.value="ADMIN",n.value=!0},d=async()=>{if(l.value){s.value=!0;try{await le(C.ADMIN_TELEGRAM_USER(l.value.chat_id),{role:i.value}),y("success",`User approved as ${i.value}`),n.value=!1,l.value=null,await r()}catch(k){const D=k instanceof _?k:new _(0,"UNKNOWN","Unknown error");y("error",I(D.code))}finally{s.value=!1}}},f=k=>{c.value=k,o.value=!0},p=async()=>{if(c.value){m.value=!0;try{await De(C.ADMIN_TELEGRAM_USER(c.value.chat_id)),y("success","User deleted"),o.value=!1,c.value=null,await r()}catch(k){const D=k instanceof _?k:new _(0,"UNKNOWN","Unknown error");y("error",I(D.code))}finally{m.value=!1}}},b=k=>k==="PENDING"?"warning":k==="ADMIN"?"success":"info";return e("div",{class:"page",children:[e(we,{columns:[{key:"chat_id",header:"Chat ID",render:k=>String(k.chat_id)},{key:"username",header:"Username",render:k=>k.username??"-"},{key:"role",header:"Role",render:k=>e(P,{variant:b(k.role),children:k.role})},{key:"registered_at",header:"Registered",render:k=>ie(k.registered_at)},{key:"approved_at",header:"Approved",render:k=>k.approved_at?ie(k.approved_at):"-"},{key:"actions",header:"Actions",render:k=>e("div",{style:{display:"flex",gap:"var(--space-1)"},children:[k.role==="PENDING"&&e(E,{size:"sm",variant:"primary",onClick:()=>u(k),children:"Approve"}),e(E,{size:"sm",variant:"danger",onClick:()=>f(k),children:"Delete"})]})}],data:a.value,loading:t.value,emptyMessage:"No Telegram users registered. Users appear here after sending /start to the bot."}),e(se,{open:n.value,title:"Approve Telegram User",onCancel:()=>{n.value=!1,l.value=null},onConfirm:d,confirmText:"Approve",confirmVariant:"primary",loading:s.value,children:l.value&&e("div",{children:[e("p",{children:[e("strong",{children:"Chat ID:"})," ",l.value.chat_id,l.value.username&&e("span",{children:[" (",e("strong",{children:["@",l.value.username]}),")"]})]}),e("div",{class:"form-field",style:{marginTop:"var(--space-3)"},children:[e("label",{for:"approve-role",children:"Role"}),e("select",{id:"approve-role",value:i.value,onChange:k=>{i.value=k.target.value},children:[e("option",{value:"ADMIN",children:"ADMIN"}),e("option",{value:"READONLY",children:"READONLY"})]})]})]})}),e(se,{open:o.value,title:"Delete Telegram User",onCancel:()=>{o.value=!1,c.value=null},onConfirm:p,confirmText:"Delete",confirmVariant:"danger",loading:m.value,children:e("p",{children:"Are you sure you want to remove this user? They will need to /start again to re-register."})})]})}const It=20,ma=[{key:"channels",label:"Channels & Logs"},{key:"telegram",label:"Telegram Users"},{key:"settings",label:"Settings"}];function $l(){const a=v({}),t=v({}),n=v(!1),l=v(!0),i=v([]),s=v(!1),o=async()=>{try{const f=await B(C.ADMIN_SETTINGS);a.value=f}catch(f){const p=f instanceof _?f:new _(0,"UNKNOWN","Unknown error");y("error",I(p.code))}finally{l.value=!1}};O(()=>{o()},[]);const c=(f,p)=>{const b=String(p);t.value={...t.value,[f]:b}},m=async()=>{n.value=!0;try{const f=Object.entries(t.value).filter(([p])=>p.startsWith("notifications.")||p.startsWith("telegram.")).map(([p,b])=>({key:p,value:b}));await le(C.ADMIN_SETTINGS,{settings:f}),t.value={},await o(),y("success","Notification settings saved and applied")}catch(f){const p=f instanceof _?f:new _(0,"UNKNOWN","Unknown error");y("error",I(p.code))}finally{n.value=!1}},r=()=>{t.value={}};O(()=>(fe({id:"notifications-settings",isDirty:()=>Object.keys(t.value).filter(f=>f.startsWith("notifications.")||f.startsWith("telegram.")).length>0,save:m,discard:r}),()=>_e("notifications-settings")),[]);const u=async()=>{s.value=!0,i.value=[];try{const f=await Q(C.ADMIN_NOTIFICATIONS_TEST,{});if(i.value=f.results,f.results.length===0)y("info","No notification channels configured");else{const p=f.results.every(b=>b.success);y(p?"success":"warning",p?"All test notifications sent":"Some channels failed")}}catch(f){const p=f instanceof _?f:new _(0,"UNKNOWN","Unknown error");y("error",I(p.code))}finally{s.value=!1}},d=Object.keys(t.value).filter(f=>f.startsWith("notifications.")||f.startsWith("telegram.")).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(z,{children:[d>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[d," unsaved change",d>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(E,{variant:"ghost",size:"sm",onClick:r,children:"Discard"}),e(E,{variant:"primary",size:"sm",onClick:m,loading:n.value,children:"Save"})]})]}),e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Notification Configuration"}),e("p",{class:"settings-description",children:"Configure notification channels for transaction alerts. Changes apply immediately via hot-reload."})]}),e("div",{class:"settings-category-body",children:[e("div",{class:"settings-fields-grid",style:{marginBottom:"var(--space-4)"},children:[e("div",{class:"settings-field-full",children:e(N,{label:"Enabled",name:"notifications.enabled",type:"checkbox",value:Ae(a.value,t.value,"notifications","enabled"),onChange:f=>c("notifications.enabled",f),description:"Enable or disable notifications globally"})}),e(N,{label:W("locale"),name:"notifications.locale",type:"select",value:U(a.value,t.value,"notifications","locale")||"en",onChange:f=>c("notifications.locale",f),options:[{label:"English",value:"en"},{label:"Korean",value:"ko"}],description:"Language for notification messages"})]}),e(Oe,{legend:"Telegram",description:"Telegram notification channel and bot configuration",children:[e("div",{class:"settings-fields-grid",children:[e(N,{label:W("telegram_bot_token"),name:"notifications.telegram_bot_token",type:"password",value:U(a.value,t.value,"notifications","telegram_bot_token"),onChange:f=>c("notifications.telegram_bot_token",f),placeholder:et(a.value,t.value,"notifications","telegram_bot_token")?"(configured)":"",description:"Bot token for Telegram notifications"}),e(N,{label:W("telegram_chat_id"),name:"notifications.telegram_chat_id",type:"text",value:U(a.value,t.value,"notifications","telegram_chat_id"),onChange:f=>c("notifications.telegram_chat_id",f),description:"Chat ID for Telegram notification delivery"})]}),e("div",{class:"settings-subgroup",style:{marginTop:"0.75rem",borderTop:"1px solid var(--border)",paddingTop:"0.75rem"},children:[e("div",{class:"settings-subgroup-title",children:"Telegram Bot"}),e("div",{class:"settings-fields-grid",children:[e(N,{label:"Bot Enabled",name:"telegram.enabled",type:"select",value:U(a.value,t.value,"telegram","enabled")||"false",onChange:f=>c("telegram.enabled",f),options:[{label:"Yes",value:"true"},{label:"No",value:"false"}],description:"Enable or disable the Telegram bot"}),e(N,{label:W("bot_token"),name:"telegram.bot_token",type:"password",value:U(a.value,t.value,"telegram","bot_token"),onChange:f=>c("telegram.bot_token",f),placeholder:et(a.value,t.value,"telegram","bot_token")?"(configured)":"Leave empty to use notification token",description:"Dedicated bot token for Telegram bot (optional, uses notification token if empty)"}),e(N,{label:"Locale",name:"telegram.locale",type:"select",value:U(a.value,t.value,"telegram","locale")||"en",onChange:f=>c("telegram.locale",f),options:[{label:"English",value:"en"},{label:"한국어",value:"ko"}],description:"Language for Telegram bot messages"})]})]})]}),e(Oe,{legend:"Other Channels",description:"Discord, ntfy, Slack, and rate limiting",children:e("div",{class:"settings-fields-grid",children:[e(N,{label:W("discord_webhook_url"),name:"notifications.discord_webhook_url",type:"password",value:U(a.value,t.value,"notifications","discord_webhook_url"),onChange:f=>c("notifications.discord_webhook_url",f),placeholder:et(a.value,t.value,"notifications","discord_webhook_url")?"(configured)":"",description:"Webhook URL for Discord notifications"}),e(N,{label:W("ntfy_server"),name:"notifications.ntfy_server",type:"text",value:U(a.value,t.value,"notifications","ntfy_server"),onChange:f=>c("notifications.ntfy_server",f),description:"Server URL for ntfy notifications"}),e(N,{label:W("ntfy_topic"),name:"notifications.ntfy_topic",type:"text",value:U(a.value,t.value,"notifications","ntfy_topic"),onChange:f=>c("notifications.ntfy_topic",f),description:"Topic name for ntfy notifications"}),e(N,{label:"Slack Webhook URL",name:"notifications.slack_webhook_url",type:"password",value:U(a.value,t.value,"notifications","slack_webhook_url"),onChange:f=>c("notifications.slack_webhook_url",f),placeholder:et(a.value,t.value,"notifications","slack_webhook_url")?"(configured)":"",description:"Webhook URL for Slack notifications"}),e(N,{label:W("rate_limit_rpm"),name:"notifications.rate_limit_rpm",type:"number",value:Number(U(a.value,t.value,"notifications","rate_limit_rpm"))||20,onChange:f=>c("notifications.rate_limit_rpm",f),min:1,max:1e3,description:"Max notifications per minute"})]})}),e("div",{class:"notif-test-section",children:[e(E,{variant:"secondary",size:"sm",onClick:u,loading:s.value,children:"Test Notification"}),i.value.length>0&&e("div",{class:"test-results",children:i.value.map(f=>e("div",{class:`test-result-item ${f.success?"test-result-success":"test-result-failure"}`,children:[e(P,{variant:f.success?"success":"danger",children:f.success?"OK":"FAIL"}),e("span",{children:f.channel}),f.error&&e("span",{style:"font-size: var(--font-size-xs); color: var(--color-danger);",children:[" - ",f.error]})]},f.channel))})]})]})]})]})}function pa(){const a=v("channels");O(()=>{const w=J.value;w&&w.tab&&(a.value=w.tab,setTimeout(()=>{oe.value=w.fieldName},100),J.value=null)},[J.value]);const t=v(null),n=v(!0),l=v(!1),i=v(null),s=v(null),o=v(null),c=v(!0),m=v(1),r=v(null),u=async()=>{try{const w=await B(C.ADMIN_NOTIFICATIONS_STATUS);t.value=w}catch(w){const x=w instanceof _?w:new _(0,"UNKNOWN","Unknown error");y("error",I(x.code))}finally{n.value=!1}},d=async w=>{c.value=!0;try{const x=await B(`${C.ADMIN_NOTIFICATIONS_LOG}?page=${w}&pageSize=${It}`);o.value=x}catch(x){const R=x instanceof _?x:new _(0,"UNKNOWN","Unknown error");y("error",I(R.code))}finally{c.value=!1}},f=async()=>{l.value=!0,s.value=null;try{const x=(await Q(C.ADMIN_NOTIFICATIONS_TEST,{})).results;s.value=x,x.every(j=>j.success)?y("success","Test sent successfully"):y("warning","Some channels failed")}catch(w){const x=w instanceof _?w:new _(0,"UNKNOWN","Unknown error");y("error",I(x.code))}finally{l.value=!1}},p=async w=>{i.value=w,s.value=null;try{const R=(await Q(C.ADMIN_NOTIFICATIONS_TEST,{channel:w})).results;s.value=R,R.every(q=>q.success)?y("success",`Test sent to ${w}`):y("warning",`${w} test failed`)}catch(x){const R=x instanceof _?x:new _(0,"UNKNOWN","Unknown error");y("error",I(R.code))}finally{i.value=null}},b=()=>{m.value>1&&(m.value-=1,d(m.value))},T=()=>{const w=o.value?Math.ceil(o.value.total/It):1;m.value<w&&(m.value+=1,d(m.value))},k=w=>{r.value=r.value?.id===w.id?null:w};O(()=>{u(),d(1);const w=setInterval(()=>d(m.value),3e4);return()=>clearInterval(w)},[]);const D=n.value&&!t.value,L=t.value?.channels.some(w=>w.enabled)??!1,M=o.value?Math.max(1,Math.ceil(o.value.total/It)):1,F=[{key:"eventType",header:"Event Type"},{key:"walletId",header:"Wallet ID",render:w=>w.walletId?w.walletId.slice(0,8)+"...":"—"},{key:"channel",header:"Channel",render:w=>e("span",{style:{textTransform:"capitalize"},children:w.channel})},{key:"status",header:"Status",render:w=>e(P,{variant:w.status==="sent"?"success":"danger",children:w.status})},{key:"createdAt",header:"Time",render:w=>ie(w.createdAt)}];return e("div",{class:"page",children:[e(Ge,{pageName:"Notifications",tabName:ma.find(w=>w.key===a.value)?.label??"",onPageClick:()=>{a.value="channels"}}),e(qe,{tabs:ma,activeTab:a.value,onTabChange:w=>{a.value=w}}),a.value==="telegram"?e(Ml,{}):a.value==="settings"?e($l,{}):e(z,{children:[e("h2",{children:"Channel Status"}),t.value&&!t.value.enabled&&e("div",{class:"notif-disabled-banner",children:["Notifications are disabled."," ",e("a",{href:"#",onClick:w=>{w.preventDefault(),a.value="settings"},children:"Enable them in the Settings tab"})]}),D?e("div",{class:"channel-grid",children:[1,2,3].map(w=>e("div",{class:"channel-card",children:e("div",{class:"stat-skeleton"})},w))}):e("div",{class:"channel-grid",children:t.value?.channels.map(w=>e("div",{class:"channel-card",children:e("div",{class:"channel-card-header",children:[e("span",{class:"channel-card-name",children:w.name}),e("div",{class:"channel-card-actions",children:[e(P,{variant:w.enabled?"success":"neutral",children:w.enabled?"Connected":"Not Configured"}),w.enabled&&e(E,{variant:"secondary",size:"sm",onClick:()=>p(w.name),loading:i.value===w.name,children:"Test"})]})]})},w.name))}),e("div",{style:{marginTop:"var(--space-4)",marginBottom:"var(--space-6)"},children:[e(E,{onClick:f,loading:l.value,disabled:!L,children:"Test All Channels"}),s.value&&e("div",{class:"test-results",children:s.value.map(w=>e("div",{class:"test-result-item",children:[e("span",{class:w.success?"test-result-success":"test-result-failure",children:w.success?"✓":"✗"}),e("span",{style:{textTransform:"capitalize"},children:w.channel}),!w.success&&w.error&&e("span",{class:"test-result-failure",children:[" - ",w.error]})]},w.channel))})]}),e("h2",{children:"Delivery Log"}),e(we,{columns:F,data:o.value?.logs??[],loading:c.value,emptyMessage:"No notification logs",onRowClick:k}),r.value&&e("div",{class:"log-message-detail",children:[e("div",{class:"log-message-detail-header",children:[e("strong",{children:r.value.eventType})," via ",e("span",{style:{textTransform:"capitalize"},children:r.value.channel}),e(E,{variant:"ghost",size:"sm",onClick:()=>{r.value=null},children:"Close"})]}),e("div",{class:"log-message-detail-body",children:r.value.message?e("pre",{style:{whiteSpace:"pre-wrap",margin:0,fontSize:"var(--font-size-sm)"},children:r.value.message}):e("span",{class:"text-muted",children:"(No message recorded)"})})]}),e("div",{class:"pagination",children:[e("span",{class:"pagination-info",children:["Page ",m.value," of ",M,o.value?` (${o.value.total} total)`:""]}),e("div",{class:"pagination-buttons",children:[e(E,{variant:"secondary",size:"sm",onClick:b,disabled:m.value<=1,children:"Previous"}),e(E,{variant:"secondary",size:"sm",onClick:T,disabled:m.value>=M,children:"Next"})]})]}),e("div",{class:"config-guidance",children:e("p",{children:"Configure notification channels in the Settings tab above. Changes are applied immediately via hot-reload."})})]})]})}const fa=[{key:"killswitch",label:"Kill Switch"},{key:"autostop",label:"AutoStop Rules"},{key:"jwt",label:"Invalidate Sessions"}];function Kl(){const a=v(null),t=v(!0),n=v(!1),l=async()=>{try{const d=await B(C.ADMIN_KILL_SWITCH);a.value=d}catch(d){const f=d instanceof _?d:new _(0,"UNKNOWN","Unknown error");y("error",I(f.code))}finally{t.value=!1}};O(()=>{l()},[]);const i=async()=>{n.value=!0;try{await Q(C.ADMIN_KILL_SWITCH),y("success","Kill switch activated - all operations suspended"),await l()}catch(d){const f=d instanceof _?d:new _(0,"UNKNOWN","Unknown error");y("error",I(f.code))}finally{n.value=!1}},s=async()=>{n.value=!0;try{await Q(C.ADMIN_KILL_SWITCH_ESCALATE),y("success","Kill switch escalated to LOCKED"),await l()}catch(d){const f=d instanceof _?d:new _(0,"UNKNOWN","Unknown error");y("error",I(f.code))}finally{n.value=!1}},o=async()=>{n.value=!0;try{await Q(C.ADMIN_RECOVER),y("success","Kill switch recovered - operations resumed"),await l()}catch(d){const f=d instanceof _?d:new _(0,"UNKNOWN","Unknown error");y("error",I(f.code))}finally{n.value=!1}},c=a.value,m=c?.state==="ACTIVE",r=c?.state==="SUSPENDED",u=c?.state==="LOCKED";return e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Kill Switch"}),e("p",{class:"settings-description",children:"Emergency stop - suspends all wallet operations immediately. 3-state: ACTIVE (normal) → SUSPENDED (paused) → LOCKED (permanent)."})]}),e("div",{class:"settings-category-body",children:t.value?e("span",{children:"Loading..."}):c?e(z,{children:[e("div",{class:"ks-state-card",style:{marginBottom:"var(--space-4)"},children:[e(P,{variant:m?"success":u?"danger":"warning",children:c.state}),!m&&c.activatedAt&&e("span",{class:"ks-state-info",children:["Since ",ie(c.activatedAt),c.activatedBy?` by ${c.activatedBy}`:""]})]}),e("div",{style:{display:"flex",gap:"var(--space-2)",flexWrap:"wrap"},children:[m&&e(E,{variant:"danger",onClick:i,loading:n.value,children:"Activate Kill Switch"}),r&&e(z,{children:[e(E,{variant:"primary",onClick:o,loading:n.value,children:"Recover"}),e(E,{variant:"danger",onClick:s,loading:n.value,children:"Escalate to LOCKED"})]}),u&&e(E,{variant:"primary",onClick:o,loading:n.value,children:"Recover from LOCKED (5s wait)"})]}),r&&e("div",{class:"settings-info-box",style:{marginTop:"var(--space-3)"},children:"All wallet operations are suspended. Sessions revoked, transactions cancelled. You can Recover to resume operations, or Escalate to LOCKED for permanent lockdown."}),u&&e("div",{class:"settings-info-box",style:{marginTop:"var(--space-3)",borderColor:"var(--color-danger)"},children:"System is permanently locked. Recovery requires dual-auth (Owner signature + Master password) and has a mandatory 5-second wait period."})]}):null})]})}function Fl(){const a=v({}),t=v({}),n=v(!1),l=v(!0),i=async()=>{try{const r=await B(C.ADMIN_SETTINGS);a.value=r}catch(r){const u=r instanceof _?r:new _(0,"UNKNOWN","Unknown error");y("error",I(u.code))}finally{l.value=!1}};O(()=>{i()},[]);const s=(r,u)=>{const d=String(u);t.value={...t.value,[r]:d}},o=async()=>{n.value=!0;try{const r=Object.entries(t.value).filter(([u])=>u.startsWith("autostop.")).map(([u,d])=>({key:u,value:d}));await le(C.ADMIN_SETTINGS,{settings:r}),t.value={},await i(),y("success","AutoStop settings saved and applied")}catch(r){const u=r instanceof _?r:new _(0,"UNKNOWN","Unknown error");y("error",I(u.code))}finally{n.value=!1}},c=()=>{t.value={}};O(()=>(fe({id:"security-autostop",isDirty:()=>Object.keys(t.value).filter(r=>r.startsWith("autostop.")).length>0,save:o,discard:c}),()=>_e("security-autostop")),[]);const m=Object.keys(t.value).filter(r=>r.startsWith("autostop.")).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(z,{children:[m>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[m," unsaved change",m>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(E,{variant:"ghost",size:"sm",onClick:c,children:"Discard"}),e(E,{variant:"primary",size:"sm",onClick:o,loading:n.value,children:"Save"})]})]}),e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"AutoStop Rules"}),e("p",{class:"settings-description",children:"Automatic protection rules that suspend wallets or trigger Kill Switch on anomalies. Changes apply immediately without daemon restart."})]}),e("div",{class:"settings-category-body",children:[e("div",{class:"settings-field-full",style:{marginBottom:"var(--space-4)"},children:e(N,{label:W("enabled"),name:"autostop.enabled",type:"checkbox",value:Ae(a.value,t.value,"autostop","enabled"),onChange:r=>s("autostop.enabled",r),description:"Enable or disable AutoStop protection rules"})}),e(Oe,{legend:"Activity Detection",description:"Detects failures and unusual transaction patterns",children:e("div",{class:"settings-fields-grid",children:[e(N,{label:W("consecutive_failures_threshold"),name:"autostop.consecutive_failures_threshold",type:"number",value:Number(U(a.value,t.value,"autostop","consecutive_failures_threshold"))||0,onChange:r=>s("autostop.consecutive_failures_threshold",r),min:1,max:100,description:"Suspend wallet after this many consecutive failed transactions"}),e(N,{label:W("unusual_activity_threshold"),name:"autostop.unusual_activity_threshold",type:"number",value:Number(U(a.value,t.value,"autostop","unusual_activity_threshold"))||0,onChange:r=>s("autostop.unusual_activity_threshold",r),min:5,max:1e3,description:"Max transactions within window before triggering unusual activity alert"}),e(N,{label:W("unusual_activity_window_sec"),name:"autostop.unusual_activity_window_sec",type:"number",value:Number(U(a.value,t.value,"autostop","unusual_activity_window_sec"))||0,onChange:r=>s("autostop.unusual_activity_window_sec",r),min:60,max:86400,description:"Time window for unusual activity detection"})]})}),e(Oe,{legend:"Idle Detection",description:"Monitors inactivity and revokes idle sessions",children:e("div",{class:"settings-fields-grid",children:[e(N,{label:W("idle_timeout_sec"),name:"autostop.idle_timeout_sec",type:"number",value:Number(U(a.value,t.value,"autostop","idle_timeout_sec"))||0,onChange:r=>s("autostop.idle_timeout_sec",r),min:60,max:604800,description:"Revoke sessions with no activity for this duration"}),e(N,{label:W("idle_check_interval_sec"),name:"autostop.idle_check_interval_sec",type:"number",value:Number(U(a.value,t.value,"autostop","idle_check_interval_sec"))||0,onChange:r=>s("autostop.idle_check_interval_sec",r),min:10,max:3600,description:"How often to check for idle sessions"})]})}),e("div",{class:"settings-info-box",children:[e("strong",{children:"Consecutive Failures:"})," Suspends wallet after N consecutive failed transactions.",e("br",{}),e("strong",{children:"Unusual Activity:"})," Suspends wallet if transaction count exceeds threshold within the time window.",e("br",{}),e("strong",{children:"Idle Timeout:"})," Revokes sessions with no activity for the configured duration."]})]})]})]})}function Bl(){const a=v(!1),t=v(!1),n=async()=>{t.value=!0;try{await Q(C.ADMIN_ROTATE_SECRET),a.value=!1,y("success","All session tokens invalidated. Old tokens remain valid for 5 minutes.")}catch(l){const i=l instanceof _?l:new _(0,"UNKNOWN","Unknown error");y("error",I(i.code))}finally{t.value=!1}};return e(z,{children:[e("div",{class:"settings-section",children:[e("div",{class:"settings-section-header",children:[e("h3",{children:"Invalidate All Session Tokens"}),e("p",{class:"settings-description",children:"Revoke all active session tokens by rotating the signing key. Existing tokens remain valid for 5 minutes, then all wallets must create new sessions."})]}),e("div",{class:"settings-section-body",children:e(E,{variant:"secondary",onClick:()=>{a.value=!0},children:"Invalidate All Tokens"})})]}),e(se,{open:a.value,title:"Invalidate All Session Tokens",onCancel:()=>{a.value=!1},onConfirm:n,confirmText:"Invalidate",confirmVariant:"primary",loading:t.value,children:e("p",{children:"This will rotate the signing key and invalidate all active session tokens after 5 minutes. Every wallet will need to create a new session to continue API access. Use this when a token may have been compromised."})})]})}function Hl(){const a=v("killswitch");O(()=>{const n=J.value;n&&n.tab&&(a.value=n.tab,setTimeout(()=>{oe.value=n.fieldName},100),J.value=null)},[J.value]);const t=fa.find(n=>n.key===a.value)?.label??"";return e("div",{class:"page",children:[e(Ge,{pageName:"Security",tabName:t,onPageClick:()=>{a.value="killswitch"}}),e(qe,{tabs:fa,activeTab:a.value,onTabChange:n=>{a.value=n}}),a.value==="killswitch"&&e(Kl,{}),a.value==="autostop"&&e(Fl,{}),a.value==="jwt"&&e(Bl,{})]})}const at=[{code:"USD",name:"US Dollar",symbol:"$"},{code:"KRW",name:"Korean Won",symbol:"₩"},{code:"JPY",name:"Japanese Yen",symbol:"¥"},{code:"EUR",name:"Euro",symbol:"€"},{code:"GBP",name:"British Pound",symbol:"£"},{code:"CNY",name:"Chinese Yuan",symbol:"¥"},{code:"CAD",name:"Canadian Dollar",symbol:"CA$"},{code:"AUD",name:"Australian Dollar",symbol:"A$"},{code:"CHF",name:"Swiss Franc",symbol:"CHF"},{code:"SGD",name:"Singapore Dollar",symbol:"S$"},{code:"HKD",name:"Hong Kong Dollar",symbol:"HK$"},{code:"INR",name:"Indian Rupee",symbol:"₹"},{code:"TWD",name:"Taiwan Dollar",symbol:"NT$"},{code:"THB",name:"Thai Baht",symbol:"฿"},{code:"MYR",name:"Malaysian Ringgit",symbol:"RM"},{code:"IDR",name:"Indonesian Rupiah",symbol:"Rp"},{code:"PHP",name:"Philippine Peso",symbol:"₱"},{code:"VND",name:"Vietnamese Dong",symbol:"₫"},{code:"BRL",name:"Brazilian Real",symbol:"R$"},{code:"MXN",name:"Mexican Peso",symbol:"MX$"},{code:"CLP",name:"Chilean Peso",symbol:"CL$"},{code:"TRY",name:"Turkish Lira",symbol:"₺"},{code:"PLN",name:"Polish Zloty",symbol:"zł"},{code:"CZK",name:"Czech Koruna",symbol:"Kč"},{code:"HUF",name:"Hungarian Forint",symbol:"Ft"},{code:"SEK",name:"Swedish Krona",symbol:"kr"},{code:"NOK",name:"Norwegian Krone",symbol:"kr"},{code:"DKK",name:"Danish Krone",symbol:"kr"},{code:"NZD",name:"New Zealand Dollar",symbol:"NZ$"},{code:"ZAR",name:"South African Rand",symbol:"R"},{code:"ILS",name:"Israeli Shekel",symbol:"₪"},{code:"SAR",name:"Saudi Riyal",symbol:"SR"},{code:"AED",name:"UAE Dirham",symbol:"AED"},{code:"KWD",name:"Kuwaiti Dinar",symbol:"KD"},{code:"BHD",name:"Bahraini Dinar",symbol:"BD"},{code:"NGN",name:"Nigerian Naira",symbol:"₦"},{code:"RUB",name:"Russian Ruble",symbol:"₽"},{code:"UAH",name:"Ukrainian Hryvnia",symbol:"₴"},{code:"PKR",name:"Pakistani Rupee",symbol:"Rs"},{code:"BDT",name:"Bangladeshi Taka",symbol:"৳"},{code:"LKR",name:"Sri Lankan Rupee",symbol:"Rs"},{code:"MMK",name:"Myanmar Kyat",symbol:"K"},{code:"GEL",name:"Georgian Lari",symbol:"₾"}];function Vl({value:a,onChange:t,name:n}){const l=v(""),i=v(!1),s=v(null),o=v(!1),c=Ht(null),m=un(()=>{const u=l.value.toLowerCase();return u?at.filter(d=>d.code.toLowerCase().includes(u)||d.name.toLowerCase().includes(u)||d.symbol.includes(u)):at});O(()=>{if(a==="USD"){s.value="1 USD = $1.00";return}o.value=!0,B(`${C.ADMIN_FOREX_RATES}?currencies=${a}`).then(u=>{const d=u.rates[a];s.value=d?.preview??null}).catch(()=>{s.value=null}).finally(()=>{o.value=!1})},[a]),O(()=>{const u=d=>{c.current&&!c.current.contains(d.target)&&(i.value=!1,l.value="")};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[]);const r=at.find(u=>u.code===a)??at[0];return e("div",{class:"currency-select",ref:c,children:[n&&e("input",{type:"hidden",name:n,value:a}),e("button",{type:"button",class:"currency-select-trigger",onClick:()=>{i.value=!i.value},children:[e("span",{class:"currency-select-value",children:[r.code," - ",r.name," (",r.symbol,")"]}),e("span",{class:"currency-select-chevron",children:i.value?"▲":"▼"})]}),s.value&&e("div",{class:"currency-rate-preview",children:o.value?"...":s.value}),i.value&&e("div",{class:"currency-select-dropdown",children:[e("input",{type:"text",class:"currency-select-search",placeholder:"Search currency...",value:l.value,onInput:u=>{l.value=u.target.value},autoFocus:!0}),e("div",{class:"currency-select-list",children:[m.value.map(u=>e("button",{type:"button",class:`currency-select-option ${u.code===a?"currency-select-option--active":""}`,onClick:()=>{t(u.code),i.value=!1,l.value=""},children:[e("span",{class:"currency-option-code",children:u.code}),e("span",{class:"currency-option-name",children:u.name}),e("span",{class:"currency-option-symbol",children:u.symbol})]},u.code)),m.value.length===0&&e("div",{class:"currency-select-empty",children:"No currencies found"})]})]})]})}const zl=["display.","daemon.","oracle."],ql=new Set(["security.rate_limit_global_ip_rpm"]);function Dt(a){return zl.some(t=>a.startsWith(t))||ql.has(a)}function Gl(){const a=v({}),t=v({}),n=v(!1),l=v(!0),i=v([]),s=v(!0),o=v(null),c=v(""),m=v(!1),r=v(!1),u=v(!1),d=v(""),f=v(!1),p=async()=>{try{const h=await B(C.ADMIN_SETTINGS);a.value=h}catch(h){const A=h instanceof _?h:new _(0,"UNKNOWN","Unknown error");y("error",I(A.code))}finally{l.value=!1}},b=async()=>{try{const h=await B(C.ADMIN_API_KEYS);i.value=h.keys}catch{}finally{s.value=!1}};O(()=>{p(),b()},[]),O(()=>{const h=J.value;h&&(setTimeout(()=>{oe.value=h.fieldName},100),J.value=null)},[J.value]);const T=(h,A)=>U(a.value,t.value,h,A),k=(h,A)=>{const ae=String(A);t.value={...t.value,[h]:ae}},D=async()=>{n.value=!0;try{const h=Object.entries(t.value).filter(([A])=>Dt(A)).map(([A,ae])=>({key:A,value:ae}));await le(C.ADMIN_SETTINGS,{settings:h}),t.value={},await p(),y("success","Settings saved and applied")}catch(h){const A=h instanceof _?h:new _(0,"UNKNOWN","Unknown error");y("error",I(A.code))}finally{n.value=!1}},L=()=>{t.value={}};O(()=>(fe({id:"system-settings",isDirty:()=>Object.keys(t.value).filter(h=>Dt(h)).length>0,save:D,discard:L}),()=>_e("system-settings")),[]);const M=async h=>{m.value=!0;try{await le(C.ADMIN_API_KEY(h),{apiKey:c.value}),y("success",`API key saved for ${h}`),o.value=null,c.value="",await b()}catch(A){const ae=A instanceof _?A:new _(0,"UNKNOWN","Unknown error");y("error",I(ae.code))}finally{m.value=!1}},F=async h=>{try{await De(C.ADMIN_API_KEY(h)),y("success",`API key deleted for ${h}`),await b()}catch(A){const ae=A instanceof _?A:new _(0,"UNKNOWN","Unknown error");y("error",I(ae.code))}},w=async()=>{u.value=!0;try{await Q(C.ADMIN_SHUTDOWN),r.value=!1,d.value="",y("info","Shutdown initiated"),f.value=!0}catch(h){const A=h instanceof _?h:new _(0,"UNKNOWN","Unknown error");y("error",I(A.code))}finally{u.value=!1}},x=Object.keys(t.value).filter(h=>Dt(h)).length;function R(){return s.value?e("div",{class:"settings-loading",children:"Loading API keys..."}):i.value.length===0?null:e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"API Keys"}),e("p",{class:"settings-description",children:"Manage API keys for Action Providers"})]}),e("div",{class:"settings-category-body",children:i.value.map(h=>e("div",{class:"settings-field-row",children:[e("div",{class:"settings-field-label",children:[e("span",{children:h.providerName}),h.requiresApiKey&&!h.hasKey&&e(P,{variant:"warning",children:"Required"})]}),e("div",{class:"settings-field-value",children:o.value===h.providerName?e("div",{class:"api-key-edit-row",children:[e(N,{label:"API Key",type:"password",name:`apikey-${h.providerName}`,value:c.value,onChange:A=>{c.value=String(A)},placeholder:"Enter API key"}),e(E,{onClick:()=>M(h.providerName),loading:m.value,size:"sm",children:"Save"}),e(E,{variant:"ghost",onClick:()=>{o.value=null,c.value=""},size:"sm",children:"Cancel"})]}):e("div",{class:"api-key-display-row",children:[e("span",{class:"api-key-masked",children:h.hasKey?h.maskedKey:"Not set"}),e(E,{variant:"ghost",onClick:()=>{o.value=h.providerName,c.value=""},size:"sm",children:h.hasKey?"Change":"Set"}),h.hasKey&&e(E,{variant:"danger",onClick:()=>F(h.providerName),size:"sm",children:"Delete"})]})})]},h.providerName))})]})}function j(){return e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Oracle"}),e("p",{class:"settings-description",children:"Price oracle configuration for cross-validation"})]}),e("div",{class:"settings-category-body",children:[e("div",{class:"settings-fields-grid",children:e(N,{label:"Cross Validation Threshold (%)",name:"oracle.cross_validation_threshold",type:"number",value:Number(T("oracle","cross_validation_threshold"))||5,onChange:h=>k("oracle.cross_validation_threshold",h),min:0,max:100,description:"Maximum allowed deviation between price oracle sources"})}),e("div",{class:"settings-info-box",children:"Maximum allowed deviation between price sources before flagging a discrepancy. Default is 5%."})]})]})}function q(){const h=oe.value==="display.currency";return O(()=>{if(h){const A=document.querySelector('[name="display.currency"]');A&&A.closest(".form-field")?.scrollIntoView({behavior:"smooth",block:"center"});const ae=setTimeout(()=>{oe.value=""},2500);return()=>clearTimeout(ae)}},[h]),e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Display Currency"}),e("p",{class:"settings-description",children:"Configure display currency for USD amount conversion"})]}),e("div",{class:"settings-category-body",children:[e("div",{class:"settings-fields-grid",children:e("div",{class:`form-field${h?" form-field--highlight":""}`,children:[e("label",{children:W("currency")}),e(Vl,{name:"display.currency",value:T("display","currency")||"USD",onChange:A=>k("display.currency",A)})]})}),e("div",{class:"settings-info-box",children:"All USD amounts in the dashboard, notifications, and API responses will be converted to the selected currency. Policy evaluation always uses USD. The “≈” prefix indicates an approximate conversion."})]})]})}function X(){return e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Global IP Rate Limit"}),e("p",{class:"settings-description",children:"Maximum API requests per minute from a single IP address"})]}),e("div",{class:"settings-category-body",children:e("div",{class:"settings-fields-grid",children:e(N,{label:W("rate_limit_global_ip_rpm"),name:"security.rate_limit_global_ip_rpm",type:"number",value:Number(T("security","rate_limit_global_ip_rpm"))||0,onChange:h=>k("security.rate_limit_global_ip_rpm",h),min:10,description:"Maximum API requests per minute from a single IP address"})})})]})}function G(){return e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Log Level"}),e("p",{class:"settings-description",children:"General daemon configuration"})]}),e("div",{class:"settings-category-body",children:e("div",{class:"settings-fields-grid",children:e(N,{label:W("log_level"),name:"daemon.log_level",type:"select",value:T("daemon","log_level")||"info",onChange:h=>k("daemon.log_level",h),options:[{label:"debug",value:"debug"},{label:"info",value:"info"},{label:"warn",value:"warn"},{label:"error",value:"error"}],description:"Daemon logging verbosity level"})})})]})}return e("div",{class:"page",children:[f.value&&e("div",{class:"shutdown-overlay",children:[e("h2",{children:"Daemon is shutting down..."}),e("p",{children:"You can close this tab."})]}),x>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[x," unsaved change",x>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(E,{variant:"ghost",size:"sm",onClick:L,children:"Discard"}),e(E,{variant:"primary",size:"sm",onClick:D,loading:n.value,children:"Save"})]})]}),l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(z,{children:[e(R,{}),e(j,{}),e(q,{}),e(X,{}),e(G,{})]}),e("div",{class:"settings-section settings-section--danger",children:[e("div",{class:"settings-section-header",children:[e("h3",{children:"Danger Zone"}),e("p",{class:"settings-description",children:"Irreversible actions. Proceed with caution."})]}),e("div",{class:"settings-section-body",children:e(E,{variant:"danger",onClick:()=>{r.value=!0},children:"Shutdown Daemon"})})]}),e(se,{open:r.value,title:"Shutdown Daemon",onCancel:()=>{r.value=!1,d.value=""},onConfirm:w,confirmText:"Shutdown",confirmVariant:"danger",confirmDisabled:d.value!=="SHUTDOWN",loading:u.value,children:[e("p",{children:"This will gracefully stop the daemon process. All active connections will be terminated."}),e("div",{class:"shutdown-confirm-input",children:[e("label",{children:["Type ",e("strong",{children:"SHUTDOWN"})," to confirm"]}),e("input",{type:"text",value:d.value,onInput:h=>{d.value=h.target.value},placeholder:"SHUTDOWN"})]})]})]})}const ve=te(window.location.hash.slice(1)||"/dashboard"),nt=te(!1);window.addEventListener("hashchange",()=>{ve.value=window.location.hash.slice(1)||"/dashboard"});const jl={"/dashboard":"Dashboard","/wallets":"Wallets","/sessions":"Sessions","/policies":"Policies","/notifications":"Notifications","/security":"Security","/system":"System"},Yl={"/dashboard":"System overview and key metrics","/wallets":"Manage wallets, balances, and connections","/sessions":"View and manage active sessions","/policies":"Configure transaction policies and rules","/notifications":"Channel status, delivery logs, and settings","/security":"Emergency controls and automatic protection rules","/system":"API keys, display preferences, and daemon configuration"};function Jl(a){return a.startsWith("/wallets/")?"Wallet Detail":jl[a]??"Dashboard"}function _a(a){return Yl[a]}const Xl=[{path:"/dashboard",label:"Dashboard"},{path:"/wallets",label:"Wallets"},{path:"/sessions",label:"Sessions"},{path:"/policies",label:"Policies"},{path:"/notifications",label:"Notifications"},{path:"/security",label:"Security"},{path:"/system",label:"System"}];function Zl(){const a=ve.value;return a==="/sessions"?e(ol,{}):a==="/policies"?e(Wl,{}):a==="/notifications"?e(pa,{}):a==="/telegram-users"?(window.location.hash="#/notifications",e(pa,{})):a==="/settings"?(window.location.hash="#/dashboard",e(ia,{})):a==="/walletconnect"?(window.location.hash="#/wallets",e(oa,{})):a==="/security"?e(Hl,{}):a==="/system"?e(Gl,{}):a.startsWith("/wallets")?e(oa,{}):e(ia,{})}function Ql(){return O(()=>{const a=t=>{(t.metaKey||t.ctrlKey)&&t.key==="k"&&(t.preventDefault(),nt.value=!nt.value)};return document.addEventListener("keydown",a),()=>document.removeEventListener("keydown",a)},[]),e("div",{class:"layout",children:[e("aside",{class:"sidebar",children:[e("div",{class:"sidebar-brand",children:"WAIaaS"}),e("nav",{class:"sidebar-nav",children:Xl.map(a=>{const t=a.path==="/wallets"?ve.value.startsWith("/wallets"):ve.value===a.path;return e("a",{href:`#${a.path}`,class:`sidebar-link ${t?"active":""}`,onClick:n=>{Va.value&&(n.preventDefault(),za({type:"nav",execute:()=>{window.location.hash=`#${a.path}`}}))},children:a.label})})})]}),e("main",{class:"main",children:[e("header",{class:"header",children:[e("div",{class:"header-left",children:[e("h1",{class:"header-title",children:Jl(ve.value)}),_a(ve.value)&&e("p",{class:"header-subtitle",children:_a(ve.value)})]}),e("div",{class:"header-actions",children:[e("button",{class:"btn-search",onClick:()=>{nt.value=!0},title:"Search settings (Ctrl+K)",children:"🔍"}),e("button",{class:"btn-logout",onClick:()=>qt(),children:"Logout"})]})]}),e("div",{class:"content",children:e(Zl,{})})]}),e(Tn,{open:nt}),e(An,{})]})}const lt={overlay:{position:"fixed",inset:0,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0, 0, 0, 0.7)",color:"white",zIndex:9999},content:{textAlign:"center"},title:{fontSize:"var(--font-size-2xl)",fontWeight:"var(--font-weight-bold)",marginBottom:"var(--space-2)"},message:{fontSize:"var(--font-size-base)",color:"var(--color-text-muted)"}};function ei(){return e("div",{style:lt.overlay,children:e("div",{style:lt.content,children:[e("h1",{style:lt.title,children:"Daemon Shutting Down"}),e("p",{style:lt.message,children:"The daemon is shutting down. Please wait or restart."})]})})}function ti(){return pn.value?e(ei,{}):mn.value?e(z,{children:[e(Ql,{}),e(Fn,{})]}):e(bn,{})}tn(e(ti,{}),document.getElementById("app"));
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>WAIaaS Admin</title>
7
- <script type="module" crossorigin src="/admin/assets/index-CftMYMk6.js"></script>
7
+ <script type="module" crossorigin src="/admin/assets/index-DSFhpAO9.js"></script>
8
8
  <link rel="stylesheet" crossorigin href="/admin/assets/index-BTZ185m_.css">
9
9
  </head>
10
10
  <body>