@suveren/gateway 0.29.0 → 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/content/integrations/gmail.json +13 -2
  2. package/content/integrations/mail.json +12 -2
  3. package/content/integrations/mollie.json +10 -0
  4. package/dist/control-plane/index.mjs +125 -37
  5. package/dist/mcp-server/http.mjs +772 -420
  6. package/dist/ui/assets/index-C2BnlNib.js +123 -0
  7. package/dist/ui/assets/{index-DUIlMVlP.css → index-DPgewsLG.css} +1 -1
  8. package/dist/ui/index.html +2 -2
  9. package/node_modules/qs/.github/THREAT_MODEL.md +4 -2
  10. package/node_modules/qs/CHANGELOG.md +38 -14
  11. package/node_modules/qs/README.md +31 -3
  12. package/node_modules/qs/dist/qs.js +20 -20
  13. package/node_modules/qs/lib/parse.js +94 -4
  14. package/node_modules/qs/lib/stringify.js +4 -4
  15. package/node_modules/qs/lib/utils.js +130 -6
  16. package/node_modules/qs/package.json +4 -4
  17. package/node_modules/qs/test/parse.js +174 -0
  18. package/node_modules/qs/test/stringify.js +263 -33
  19. package/node_modules/qs/test/utils.js +184 -0
  20. package/node_modules/sanitize-html/index.js +47 -10
  21. package/node_modules/sanitize-html/package.json +2 -3
  22. package/package.json +1 -1
  23. package/dist/ui/assets/index-C3vTF2Ye.js +0 -123
  24. package/node_modules/deepmerge/.editorconfig +0 -7
  25. package/node_modules/deepmerge/.eslintcache +0 -1
  26. package/node_modules/deepmerge/changelog.md +0 -167
  27. package/node_modules/deepmerge/dist/cjs.js +0 -133
  28. package/node_modules/deepmerge/dist/umd.js +0 -139
  29. package/node_modules/deepmerge/index.d.ts +0 -20
  30. package/node_modules/deepmerge/index.js +0 -106
  31. package/node_modules/deepmerge/license.txt +0 -21
  32. package/node_modules/deepmerge/package.json +0 -42
  33. package/node_modules/deepmerge/readme.md +0 -264
  34. package/node_modules/deepmerge/rollup.config.js +0 -22
@@ -0,0 +1,123 @@
1
+ var Ig=Object.defineProperty;var Pg=(t,s,a)=>s in t?Ig(t,s,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[s]=a;var Bs=(t,s,a)=>Pg(t,typeof s!="symbol"?s+"":s,a);(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const c of document.querySelectorAll('link[rel="modulepreload"]'))o(c);new MutationObserver(c=>{for(const u of c)if(u.type==="childList")for(const f of u.addedNodes)f.tagName==="LINK"&&f.rel==="modulepreload"&&o(f)}).observe(document,{childList:!0,subtree:!0});function a(c){const u={};return c.integrity&&(u.integrity=c.integrity),c.referrerPolicy&&(u.referrerPolicy=c.referrerPolicy),c.crossOrigin==="use-credentials"?u.credentials="include":c.crossOrigin==="anonymous"?u.credentials="omit":u.credentials="same-origin",u}function o(c){if(c.ep)return;c.ep=!0;const u=a(c);fetch(c.href,u)}})();var Sl={exports:{}},Ds={},bl={exports:{}},Ue={};/**
2
+ * @license React
3
+ * react.production.min.js
4
+ *
5
+ * Copyright (c) Facebook, Inc. and its affiliates.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */var sf;function _g(){if(sf)return Ue;sf=1;var t=Symbol.for("react.element"),s=Symbol.for("react.portal"),a=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),c=Symbol.for("react.profiler"),u=Symbol.for("react.provider"),f=Symbol.for("react.context"),g=Symbol.for("react.forward_ref"),p=Symbol.for("react.suspense"),v=Symbol.for("react.memo"),y=Symbol.for("react.lazy"),w=Symbol.iterator;function j(C){return C===null||typeof C!="object"?null:(C=w&&C[w]||C["@@iterator"],typeof C=="function"?C:null)}var N={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},b=Object.assign,S={};function k(C,L,fe){this.props=C,this.context=L,this.refs=S,this.updater=fe||N}k.prototype.isReactComponent={},k.prototype.setState=function(C,L){if(typeof C!="object"&&typeof C!="function"&&C!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,C,L,"setState")},k.prototype.forceUpdate=function(C){this.updater.enqueueForceUpdate(this,C,"forceUpdate")};function T(){}T.prototype=k.prototype;function R(C,L,fe){this.props=C,this.context=L,this.refs=S,this.updater=fe||N}var P=R.prototype=new T;P.constructor=R,b(P,k.prototype),P.isPureReactComponent=!0;var A=Array.isArray,B=Object.prototype.hasOwnProperty,H={current:null},G={key:!0,ref:!0,__self:!0,__source:!0};function me(C,L,fe){var Q,z={},X=null,ne=null;if(L!=null)for(Q in L.ref!==void 0&&(ne=L.ref),L.key!==void 0&&(X=""+L.key),L)B.call(L,Q)&&!G.hasOwnProperty(Q)&&(z[Q]=L[Q]);var ie=arguments.length-2;if(ie===1)z.children=fe;else if(1<ie){for(var K=Array(ie),ke=0;ke<ie;ke++)K[ke]=arguments[ke+2];z.children=K}if(C&&C.defaultProps)for(Q in ie=C.defaultProps,ie)z[Q]===void 0&&(z[Q]=ie[Q]);return{$$typeof:t,type:C,key:X,ref:ne,props:z,_owner:H.current}}function q(C,L){return{$$typeof:t,type:C.type,key:L,ref:C.ref,props:C.props,_owner:C._owner}}function ce(C){return typeof C=="object"&&C!==null&&C.$$typeof===t}function ee(C){var L={"=":"=0",":":"=2"};return"$"+C.replace(/[=:]/g,function(fe){return L[fe]})}var F=/\/+/g;function re(C,L){return typeof C=="object"&&C!==null&&C.key!=null?ee(""+C.key):L.toString(36)}function Y(C,L,fe,Q,z){var X=typeof C;(X==="undefined"||X==="boolean")&&(C=null);var ne=!1;if(C===null)ne=!0;else switch(X){case"string":case"number":ne=!0;break;case"object":switch(C.$$typeof){case t:case s:ne=!0}}if(ne)return ne=C,z=z(ne),C=Q===""?"."+re(ne,0):Q,A(z)?(fe="",C!=null&&(fe=C.replace(F,"$&/")+"/"),Y(z,L,fe,"",function(ke){return ke})):z!=null&&(ce(z)&&(z=q(z,fe+(!z.key||ne&&ne.key===z.key?"":(""+z.key).replace(F,"$&/")+"/")+C)),L.push(z)),1;if(ne=0,Q=Q===""?".":Q+":",A(C))for(var ie=0;ie<C.length;ie++){X=C[ie];var K=Q+re(X,ie);ne+=Y(X,L,fe,K,z)}else if(K=j(C),typeof K=="function")for(C=K.call(C),ie=0;!(X=C.next()).done;)X=X.value,K=Q+re(X,ie++),ne+=Y(X,L,fe,K,z);else if(X==="object")throw L=String(C),Error("Objects are not valid as a React child (found: "+(L==="[object Object]"?"object with keys {"+Object.keys(C).join(", ")+"}":L)+"). If you meant to render a collection of children, use an array instead.");return ne}function se(C,L,fe){if(C==null)return C;var Q=[],z=0;return Y(C,Q,"","",function(X){return L.call(fe,X,z++)}),Q}function ye(C){if(C._status===-1){var L=C._result;L=L(),L.then(function(fe){(C._status===0||C._status===-1)&&(C._status=1,C._result=fe)},function(fe){(C._status===0||C._status===-1)&&(C._status=2,C._result=fe)}),C._status===-1&&(C._status=0,C._result=L)}if(C._status===1)return C._result.default;throw C._result}var we={current:null},J={transition:null},V={ReactCurrentDispatcher:we,ReactCurrentBatchConfig:J,ReactCurrentOwner:H};function W(){throw Error("act(...) is not supported in production builds of React.")}return Ue.Children={map:se,forEach:function(C,L,fe){se(C,function(){L.apply(this,arguments)},fe)},count:function(C){var L=0;return se(C,function(){L++}),L},toArray:function(C){return se(C,function(L){return L})||[]},only:function(C){if(!ce(C))throw Error("React.Children.only expected to receive a single React element child.");return C}},Ue.Component=k,Ue.Fragment=a,Ue.Profiler=c,Ue.PureComponent=R,Ue.StrictMode=o,Ue.Suspense=p,Ue.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=V,Ue.act=W,Ue.cloneElement=function(C,L,fe){if(C==null)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+C+".");var Q=b({},C.props),z=C.key,X=C.ref,ne=C._owner;if(L!=null){if(L.ref!==void 0&&(X=L.ref,ne=H.current),L.key!==void 0&&(z=""+L.key),C.type&&C.type.defaultProps)var ie=C.type.defaultProps;for(K in L)B.call(L,K)&&!G.hasOwnProperty(K)&&(Q[K]=L[K]===void 0&&ie!==void 0?ie[K]:L[K])}var K=arguments.length-2;if(K===1)Q.children=fe;else if(1<K){ie=Array(K);for(var ke=0;ke<K;ke++)ie[ke]=arguments[ke+2];Q.children=ie}return{$$typeof:t,type:C.type,key:z,ref:X,props:Q,_owner:ne}},Ue.createContext=function(C){return C={$$typeof:f,_currentValue:C,_currentValue2:C,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},C.Provider={$$typeof:u,_context:C},C.Consumer=C},Ue.createElement=me,Ue.createFactory=function(C){var L=me.bind(null,C);return L.type=C,L},Ue.createRef=function(){return{current:null}},Ue.forwardRef=function(C){return{$$typeof:g,render:C}},Ue.isValidElement=ce,Ue.lazy=function(C){return{$$typeof:y,_payload:{_status:-1,_result:C},_init:ye}},Ue.memo=function(C,L){return{$$typeof:v,type:C,compare:L===void 0?null:L}},Ue.startTransition=function(C){var L=J.transition;J.transition={};try{C()}finally{J.transition=L}},Ue.unstable_act=W,Ue.useCallback=function(C,L){return we.current.useCallback(C,L)},Ue.useContext=function(C){return we.current.useContext(C)},Ue.useDebugValue=function(){},Ue.useDeferredValue=function(C){return we.current.useDeferredValue(C)},Ue.useEffect=function(C,L){return we.current.useEffect(C,L)},Ue.useId=function(){return we.current.useId()},Ue.useImperativeHandle=function(C,L,fe){return we.current.useImperativeHandle(C,L,fe)},Ue.useInsertionEffect=function(C,L){return we.current.useInsertionEffect(C,L)},Ue.useLayoutEffect=function(C,L){return we.current.useLayoutEffect(C,L)},Ue.useMemo=function(C,L){return we.current.useMemo(C,L)},Ue.useReducer=function(C,L,fe){return we.current.useReducer(C,L,fe)},Ue.useRef=function(C){return we.current.useRef(C)},Ue.useState=function(C){return we.current.useState(C)},Ue.useSyncExternalStore=function(C,L,fe){return we.current.useSyncExternalStore(C,L,fe)},Ue.useTransition=function(){return we.current.useTransition()},Ue.version="18.3.1",Ue}var af;function Xl(){return af||(af=1,bl.exports=_g()),bl.exports}/**
10
+ * @license React
11
+ * react-jsx-runtime.production.min.js
12
+ *
13
+ * Copyright (c) Facebook, Inc. and its affiliates.
14
+ *
15
+ * This source code is licensed under the MIT license found in the
16
+ * LICENSE file in the root directory of this source tree.
17
+ */var of;function $g(){if(of)return Ds;of=1;var t=Xl(),s=Symbol.for("react.element"),a=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,c=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,u={key:!0,ref:!0,__self:!0,__source:!0};function f(g,p,v){var y,w={},j=null,N=null;v!==void 0&&(j=""+v),p.key!==void 0&&(j=""+p.key),p.ref!==void 0&&(N=p.ref);for(y in p)o.call(p,y)&&!u.hasOwnProperty(y)&&(w[y]=p[y]);if(g&&g.defaultProps)for(y in p=g.defaultProps,p)w[y]===void 0&&(w[y]=p[y]);return{$$typeof:s,type:g,key:j,ref:N,props:w,_owner:c.current}}return Ds.Fragment=a,Ds.jsx=f,Ds.jsxs=f,Ds}var lf;function Lg(){return lf||(lf=1,Sl.exports=$g()),Sl.exports}var r=Lg(),h=Xl(),ci={},kl={exports:{}},Bt={},Nl={exports:{}},Cl={};/**
18
+ * @license React
19
+ * scheduler.production.min.js
20
+ *
21
+ * Copyright (c) Facebook, Inc. and its affiliates.
22
+ *
23
+ * This source code is licensed under the MIT license found in the
24
+ * LICENSE file in the root directory of this source tree.
25
+ */var cf;function zg(){return cf||(cf=1,(function(t){function s(J,V){var W=J.length;J.push(V);e:for(;0<W;){var C=W-1>>>1,L=J[C];if(0<c(L,V))J[C]=V,J[W]=L,W=C;else break e}}function a(J){return J.length===0?null:J[0]}function o(J){if(J.length===0)return null;var V=J[0],W=J.pop();if(W!==V){J[0]=W;e:for(var C=0,L=J.length,fe=L>>>1;C<fe;){var Q=2*(C+1)-1,z=J[Q],X=Q+1,ne=J[X];if(0>c(z,W))X<L&&0>c(ne,z)?(J[C]=ne,J[X]=W,C=X):(J[C]=z,J[Q]=W,C=Q);else if(X<L&&0>c(ne,W))J[C]=ne,J[X]=W,C=X;else break e}}return V}function c(J,V){var W=J.sortIndex-V.sortIndex;return W!==0?W:J.id-V.id}if(typeof performance=="object"&&typeof performance.now=="function"){var u=performance;t.unstable_now=function(){return u.now()}}else{var f=Date,g=f.now();t.unstable_now=function(){return f.now()-g}}var p=[],v=[],y=1,w=null,j=3,N=!1,b=!1,S=!1,k=typeof setTimeout=="function"?setTimeout:null,T=typeof clearTimeout=="function"?clearTimeout:null,R=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function P(J){for(var V=a(v);V!==null;){if(V.callback===null)o(v);else if(V.startTime<=J)o(v),V.sortIndex=V.expirationTime,s(p,V);else break;V=a(v)}}function A(J){if(S=!1,P(J),!b)if(a(p)!==null)b=!0,ye(B);else{var V=a(v);V!==null&&we(A,V.startTime-J)}}function B(J,V){b=!1,S&&(S=!1,T(me),me=-1),N=!0;var W=j;try{for(P(V),w=a(p);w!==null&&(!(w.expirationTime>V)||J&&!ee());){var C=w.callback;if(typeof C=="function"){w.callback=null,j=w.priorityLevel;var L=C(w.expirationTime<=V);V=t.unstable_now(),typeof L=="function"?w.callback=L:w===a(p)&&o(p),P(V)}else o(p);w=a(p)}if(w!==null)var fe=!0;else{var Q=a(v);Q!==null&&we(A,Q.startTime-V),fe=!1}return fe}finally{w=null,j=W,N=!1}}var H=!1,G=null,me=-1,q=5,ce=-1;function ee(){return!(t.unstable_now()-ce<q)}function F(){if(G!==null){var J=t.unstable_now();ce=J;var V=!0;try{V=G(!0,J)}finally{V?re():(H=!1,G=null)}}else H=!1}var re;if(typeof R=="function")re=function(){R(F)};else if(typeof MessageChannel<"u"){var Y=new MessageChannel,se=Y.port2;Y.port1.onmessage=F,re=function(){se.postMessage(null)}}else re=function(){k(F,0)};function ye(J){G=J,H||(H=!0,re())}function we(J,V){me=k(function(){J(t.unstable_now())},V)}t.unstable_IdlePriority=5,t.unstable_ImmediatePriority=1,t.unstable_LowPriority=4,t.unstable_NormalPriority=3,t.unstable_Profiling=null,t.unstable_UserBlockingPriority=2,t.unstable_cancelCallback=function(J){J.callback=null},t.unstable_continueExecution=function(){b||N||(b=!0,ye(B))},t.unstable_forceFrameRate=function(J){0>J||125<J?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):q=0<J?Math.floor(1e3/J):5},t.unstable_getCurrentPriorityLevel=function(){return j},t.unstable_getFirstCallbackNode=function(){return a(p)},t.unstable_next=function(J){switch(j){case 1:case 2:case 3:var V=3;break;default:V=j}var W=j;j=V;try{return J()}finally{j=W}},t.unstable_pauseExecution=function(){},t.unstable_requestPaint=function(){},t.unstable_runWithPriority=function(J,V){switch(J){case 1:case 2:case 3:case 4:case 5:break;default:J=3}var W=j;j=J;try{return V()}finally{j=W}},t.unstable_scheduleCallback=function(J,V,W){var C=t.unstable_now();switch(typeof W=="object"&&W!==null?(W=W.delay,W=typeof W=="number"&&0<W?C+W:C):W=C,J){case 1:var L=-1;break;case 2:L=250;break;case 5:L=1073741823;break;case 4:L=1e4;break;default:L=5e3}return L=W+L,J={id:y++,callback:V,priorityLevel:J,startTime:W,expirationTime:L,sortIndex:-1},W>C?(J.sortIndex=W,s(v,J),a(p)===null&&J===a(v)&&(S?(T(me),me=-1):S=!0,we(A,W-C))):(J.sortIndex=L,s(p,J),b||N||(b=!0,ye(B))),J},t.unstable_shouldYield=ee,t.unstable_wrapCallback=function(J){var V=j;return function(){var W=j;j=V;try{return J.apply(this,arguments)}finally{j=W}}}})(Cl)),Cl}var uf;function Fg(){return uf||(uf=1,Nl.exports=zg()),Nl.exports}/**
26
+ * @license React
27
+ * react-dom.production.min.js
28
+ *
29
+ * Copyright (c) Facebook, Inc. and its affiliates.
30
+ *
31
+ * This source code is licensed under the MIT license found in the
32
+ * LICENSE file in the root directory of this source tree.
33
+ */var df;function Og(){if(df)return Bt;df=1;var t=Xl(),s=Fg();function a(e){for(var n="https://reactjs.org/docs/error-decoder.html?invariant="+e,i=1;i<arguments.length;i++)n+="&args[]="+encodeURIComponent(arguments[i]);return"Minified React error #"+e+"; visit "+n+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}var o=new Set,c={};function u(e,n){f(e,n),f(e+"Capture",n)}function f(e,n){for(c[e]=n,e=0;e<n.length;e++)o.add(n[e])}var g=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),p=Object.prototype.hasOwnProperty,v=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,y={},w={};function j(e){return p.call(w,e)?!0:p.call(y,e)?!1:v.test(e)?w[e]=!0:(y[e]=!0,!1)}function N(e,n,i,l){if(i!==null&&i.type===0)return!1;switch(typeof n){case"function":case"symbol":return!0;case"boolean":return l?!1:i!==null?!i.acceptsBooleans:(e=e.toLowerCase().slice(0,5),e!=="data-"&&e!=="aria-");default:return!1}}function b(e,n,i,l){if(n===null||typeof n>"u"||N(e,n,i,l))return!0;if(l)return!1;if(i!==null)switch(i.type){case 3:return!n;case 4:return n===!1;case 5:return isNaN(n);case 6:return isNaN(n)||1>n}return!1}function S(e,n,i,l,d,m,x){this.acceptsBooleans=n===2||n===3||n===4,this.attributeName=l,this.attributeNamespace=d,this.mustUseProperty=i,this.propertyName=e,this.type=n,this.sanitizeURL=m,this.removeEmptyString=x}var k={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){k[e]=new S(e,0,!1,e,null,!1,!1)}),[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var n=e[0];k[n]=new S(n,1,!1,e[1],null,!1,!1)}),["contentEditable","draggable","spellCheck","value"].forEach(function(e){k[e]=new S(e,2,!1,e.toLowerCase(),null,!1,!1)}),["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){k[e]=new S(e,2,!1,e,null,!1,!1)}),"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(e){k[e]=new S(e,3,!1,e.toLowerCase(),null,!1,!1)}),["checked","multiple","muted","selected"].forEach(function(e){k[e]=new S(e,3,!0,e,null,!1,!1)}),["capture","download"].forEach(function(e){k[e]=new S(e,4,!1,e,null,!1,!1)}),["cols","rows","size","span"].forEach(function(e){k[e]=new S(e,6,!1,e,null,!1,!1)}),["rowSpan","start"].forEach(function(e){k[e]=new S(e,5,!1,e.toLowerCase(),null,!1,!1)});var T=/[\-:]([a-z])/g;function R(e){return e[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(e){var n=e.replace(T,R);k[n]=new S(n,1,!1,e,null,!1,!1)}),"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var n=e.replace(T,R);k[n]=new S(n,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)}),["xml:base","xml:lang","xml:space"].forEach(function(e){var n=e.replace(T,R);k[n]=new S(n,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)}),["tabIndex","crossOrigin"].forEach(function(e){k[e]=new S(e,1,!1,e.toLowerCase(),null,!1,!1)}),k.xlinkHref=new S("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1),["src","href","action","formAction"].forEach(function(e){k[e]=new S(e,1,!1,e.toLowerCase(),null,!0,!0)});function P(e,n,i,l){var d=k.hasOwnProperty(n)?k[n]:null;(d!==null?d.type!==0:l||!(2<n.length)||n[0]!=="o"&&n[0]!=="O"||n[1]!=="n"&&n[1]!=="N")&&(b(n,i,d,l)&&(i=null),l||d===null?j(n)&&(i===null?e.removeAttribute(n):e.setAttribute(n,""+i)):d.mustUseProperty?e[d.propertyName]=i===null?d.type===3?!1:"":i:(n=d.attributeName,l=d.attributeNamespace,i===null?e.removeAttribute(n):(d=d.type,i=d===3||d===4&&i===!0?"":""+i,l?e.setAttributeNS(l,n,i):e.setAttribute(n,i))))}var A=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,B=Symbol.for("react.element"),H=Symbol.for("react.portal"),G=Symbol.for("react.fragment"),me=Symbol.for("react.strict_mode"),q=Symbol.for("react.profiler"),ce=Symbol.for("react.provider"),ee=Symbol.for("react.context"),F=Symbol.for("react.forward_ref"),re=Symbol.for("react.suspense"),Y=Symbol.for("react.suspense_list"),se=Symbol.for("react.memo"),ye=Symbol.for("react.lazy"),we=Symbol.for("react.offscreen"),J=Symbol.iterator;function V(e){return e===null||typeof e!="object"?null:(e=J&&e[J]||e["@@iterator"],typeof e=="function"?e:null)}var W=Object.assign,C;function L(e){if(C===void 0)try{throw Error()}catch(i){var n=i.stack.trim().match(/\n( *(at )?)/);C=n&&n[1]||""}return`
34
+ `+C+e}var fe=!1;function Q(e,n){if(!e||fe)return"";fe=!0;var i=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{if(n)if(n=function(){throw Error()},Object.defineProperty(n.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(n,[])}catch(U){var l=U}Reflect.construct(e,[],n)}else{try{n.call()}catch(U){l=U}e.call(n.prototype)}else{try{throw Error()}catch(U){l=U}e()}}catch(U){if(U&&l&&typeof U.stack=="string"){for(var d=U.stack.split(`
35
+ `),m=l.stack.split(`
36
+ `),x=d.length-1,E=m.length-1;1<=x&&0<=E&&d[x]!==m[E];)E--;for(;1<=x&&0<=E;x--,E--)if(d[x]!==m[E]){if(x!==1||E!==1)do if(x--,E--,0>E||d[x]!==m[E]){var I=`
37
+ `+d[x].replace(" at new "," at ");return e.displayName&&I.includes("<anonymous>")&&(I=I.replace("<anonymous>",e.displayName)),I}while(1<=x&&0<=E);break}}}finally{fe=!1,Error.prepareStackTrace=i}return(e=e?e.displayName||e.name:"")?L(e):""}function z(e){switch(e.tag){case 5:return L(e.type);case 16:return L("Lazy");case 13:return L("Suspense");case 19:return L("SuspenseList");case 0:case 2:case 15:return e=Q(e.type,!1),e;case 11:return e=Q(e.type.render,!1),e;case 1:return e=Q(e.type,!0),e;default:return""}}function X(e){if(e==null)return null;if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case G:return"Fragment";case H:return"Portal";case q:return"Profiler";case me:return"StrictMode";case re:return"Suspense";case Y:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case ee:return(e.displayName||"Context")+".Consumer";case ce:return(e._context.displayName||"Context")+".Provider";case F:var n=e.render;return e=e.displayName,e||(e=n.displayName||n.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case se:return n=e.displayName||null,n!==null?n:X(e.type)||"Memo";case ye:n=e._payload,e=e._init;try{return X(e(n))}catch{}}return null}function ne(e){var n=e.type;switch(e.tag){case 24:return"Cache";case 9:return(n.displayName||"Context")+".Consumer";case 10:return(n._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return e=n.render,e=e.displayName||e.name||"",n.displayName||(e!==""?"ForwardRef("+e+")":"ForwardRef");case 7:return"Fragment";case 5:return n;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return X(n);case 8:return n===me?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof n=="function")return n.displayName||n.name||null;if(typeof n=="string")return n}return null}function ie(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function K(e){var n=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(n==="checkbox"||n==="radio")}function ke(e){var n=K(e)?"checked":"value",i=Object.getOwnPropertyDescriptor(e.constructor.prototype,n),l=""+e[n];if(!e.hasOwnProperty(n)&&typeof i<"u"&&typeof i.get=="function"&&typeof i.set=="function"){var d=i.get,m=i.set;return Object.defineProperty(e,n,{configurable:!0,get:function(){return d.call(this)},set:function(x){l=""+x,m.call(this,x)}}),Object.defineProperty(e,n,{enumerable:i.enumerable}),{getValue:function(){return l},setValue:function(x){l=""+x},stopTracking:function(){e._valueTracker=null,delete e[n]}}}}function Ne(e){e._valueTracker||(e._valueTracker=ke(e))}function $e(e){if(!e)return!1;var n=e._valueTracker;if(!n)return!0;var i=n.getValue(),l="";return e&&(l=K(e)?e.checked?"true":"false":e.value),e=l,e!==i?(n.setValue(e),!0):!1}function pe(e){if(e=e||(typeof document<"u"?document:void 0),typeof e>"u")return null;try{return e.activeElement||e.body}catch{return e.body}}function Le(e,n){var i=n.checked;return W({},n,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:i??e._wrapperState.initialChecked})}function Ge(e,n){var i=n.defaultValue==null?"":n.defaultValue,l=n.checked!=null?n.checked:n.defaultChecked;i=ie(n.value!=null?n.value:i),e._wrapperState={initialChecked:l,initialValue:i,controlled:n.type==="checkbox"||n.type==="radio"?n.checked!=null:n.value!=null}}function He(e,n){n=n.checked,n!=null&&P(e,"checked",n,!1)}function Oe(e,n){He(e,n);var i=ie(n.value),l=n.type;if(i!=null)l==="number"?(i===0&&e.value===""||e.value!=i)&&(e.value=""+i):e.value!==""+i&&(e.value=""+i);else if(l==="submit"||l==="reset"){e.removeAttribute("value");return}n.hasOwnProperty("value")?he(e,n.type,i):n.hasOwnProperty("defaultValue")&&he(e,n.type,ie(n.defaultValue)),n.checked==null&&n.defaultChecked!=null&&(e.defaultChecked=!!n.defaultChecked)}function lt(e,n,i){if(n.hasOwnProperty("value")||n.hasOwnProperty("defaultValue")){var l=n.type;if(!(l!=="submit"&&l!=="reset"||n.value!==void 0&&n.value!==null))return;n=""+e._wrapperState.initialValue,i||n===e.value||(e.value=n),e.defaultValue=n}i=e.name,i!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,i!==""&&(e.name=i)}function he(e,n,i){(n!=="number"||pe(e.ownerDocument)!==e)&&(i==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+i&&(e.defaultValue=""+i))}var Re=Array.isArray;function Pe(e,n,i,l){if(e=e.options,n){n={};for(var d=0;d<i.length;d++)n["$"+i[d]]=!0;for(i=0;i<e.length;i++)d=n.hasOwnProperty("$"+e[i].value),e[i].selected!==d&&(e[i].selected=d),d&&l&&(e[i].defaultSelected=!0)}else{for(i=""+ie(i),n=null,d=0;d<e.length;d++){if(e[d].value===i){e[d].selected=!0,l&&(e[d].defaultSelected=!0);return}n!==null||e[d].disabled||(n=e[d])}n!==null&&(n.selected=!0)}}function ut(e,n){if(n.dangerouslySetInnerHTML!=null)throw Error(a(91));return W({},n,{value:void 0,defaultValue:void 0,children:""+e._wrapperState.initialValue})}function Je(e,n){var i=n.value;if(i==null){if(i=n.children,n=n.defaultValue,i!=null){if(n!=null)throw Error(a(92));if(Re(i)){if(1<i.length)throw Error(a(93));i=i[0]}n=i}n==null&&(n=""),i=n}e._wrapperState={initialValue:ie(i)}}function ze(e,n){var i=ie(n.value),l=ie(n.defaultValue);i!=null&&(i=""+i,i!==e.value&&(e.value=i),n.defaultValue==null&&e.defaultValue!==i&&(e.defaultValue=i)),l!=null&&(e.defaultValue=""+l)}function _(e){var n=e.textContent;n===e._wrapperState.initialValue&&n!==""&&n!==null&&(e.value=n)}function oe(e){switch(e){case"svg":return"http://www.w3.org/2000/svg";case"math":return"http://www.w3.org/1998/Math/MathML";default:return"http://www.w3.org/1999/xhtml"}}function ge(e,n){return e==null||e==="http://www.w3.org/1999/xhtml"?oe(n):e==="http://www.w3.org/2000/svg"&&n==="foreignObject"?"http://www.w3.org/1999/xhtml":e}var Te,de=(function(e){return typeof MSApp<"u"&&MSApp.execUnsafeLocalFunction?function(n,i,l,d){MSApp.execUnsafeLocalFunction(function(){return e(n,i,l,d)})}:e})(function(e,n){if(e.namespaceURI!=="http://www.w3.org/2000/svg"||"innerHTML"in e)e.innerHTML=n;else{for(Te=Te||document.createElement("div"),Te.innerHTML="<svg>"+n.valueOf().toString()+"</svg>",n=Te.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;n.firstChild;)e.appendChild(n.firstChild)}});function Me(e,n){if(n){var i=e.firstChild;if(i&&i===e.lastChild&&i.nodeType===3){i.nodeValue=n;return}}e.textContent=n}var Ye={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},Qe=["Webkit","ms","Moz","O"];Object.keys(Ye).forEach(function(e){Qe.forEach(function(n){n=n+e.charAt(0).toUpperCase()+e.substring(1),Ye[n]=Ye[e]})});function pt(e,n,i){return n==null||typeof n=="boolean"||n===""?"":i||typeof n!="number"||n===0||Ye.hasOwnProperty(e)&&Ye[e]?(""+n).trim():n+"px"}function pn(e,n){e=e.style;for(var i in n)if(n.hasOwnProperty(i)){var l=i.indexOf("--")===0,d=pt(i,n[i],l);i==="float"&&(i="cssFloat"),l?e.setProperty(i,d):e[i]=d}}var jn=W({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function rt(e,n){if(n){if(jn[e]&&(n.children!=null||n.dangerouslySetInnerHTML!=null))throw Error(a(137,e));if(n.dangerouslySetInnerHTML!=null){if(n.children!=null)throw Error(a(60));if(typeof n.dangerouslySetInnerHTML!="object"||!("__html"in n.dangerouslySetInnerHTML))throw Error(a(61))}if(n.style!=null&&typeof n.style!="object")throw Error(a(62))}}function kt(e,n){if(e.indexOf("-")===-1)return typeof n.is=="string";switch(e){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var Et=null;function wt(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var le=null,Se=null,ve=null;function Be(e){if(e=Ns(e)){if(typeof le!="function")throw Error(a(280));var n=e.stateNode;n&&(n=ka(n),le(e.stateNode,e.type,n))}}function Fe(e){Se?ve?ve.push(e):ve=[e]:Se=e}function Xe(){if(Se){var e=Se,n=ve;if(ve=Se=null,Be(e),n)for(e=0;e<n.length;e++)Be(n[e])}}function Wt(e,n){return e(n)}function er(){}var as=!1;function na(e,n,i){if(as)return e(n,i);as=!0;try{return Wt(e,n,i)}finally{as=!1,(Se!==null||ve!==null)&&(er(),Xe())}}function Sn(e,n){var i=e.stateNode;if(i===null)return null;var l=ka(i);if(l===null)return null;i=l[n];e:switch(n){case"onClick":case"onClickCapture":case"onDoubleClick":case"onDoubleClickCapture":case"onMouseDown":case"onMouseDownCapture":case"onMouseMove":case"onMouseMoveCapture":case"onMouseUp":case"onMouseUpCapture":case"onMouseEnter":(l=!l.disabled)||(e=e.type,l=!(e==="button"||e==="input"||e==="select"||e==="textarea")),e=!l;break e;default:e=!1}if(e)return null;if(i&&typeof i!="function")throw Error(a(231,n,typeof i));return i}var tr=!1;if(g)try{var nr={};Object.defineProperty(nr,"passive",{get:function(){tr=!0}}),window.addEventListener("test",nr,nr),window.removeEventListener("test",nr,nr)}catch{tr=!1}function ra(e,n,i,l,d,m,x,E,I){var U=Array.prototype.slice.call(arguments,3);try{n.apply(i,U)}catch(te){this.onError(te)}}var $n=!1,rr=null,sr=!1,is=null,Cr={onError:function(e){$n=!0,rr=e}};function bn(e,n,i,l,d,m,x,E,I){$n=!1,rr=null,ra.apply(Cr,arguments)}function Bm(e,n,i,l,d,m,x,E,I){if(bn.apply(this,arguments),$n){if($n){var U=rr;$n=!1,rr=null}else throw Error(a(198));sr||(sr=!0,is=U)}}function ar(e){var n=e,i=e;if(e.alternate)for(;n.return;)n=n.return;else{e=n;do n=e,(n.flags&4098)!==0&&(i=n.return),e=n.return;while(e)}return n.tag===3?i:null}function Ec(e){if(e.tag===13){var n=e.memoizedState;if(n===null&&(e=e.alternate,e!==null&&(n=e.memoizedState)),n!==null)return n.dehydrated}return null}function Tc(e){if(ar(e)!==e)throw Error(a(188))}function Dm(e){var n=e.alternate;if(!n){if(n=ar(e),n===null)throw Error(a(188));return n!==e?null:e}for(var i=e,l=n;;){var d=i.return;if(d===null)break;var m=d.alternate;if(m===null){if(l=d.return,l!==null){i=l;continue}break}if(d.child===m.child){for(m=d.child;m;){if(m===i)return Tc(d),e;if(m===l)return Tc(d),n;m=m.sibling}throw Error(a(188))}if(i.return!==l.return)i=d,l=m;else{for(var x=!1,E=d.child;E;){if(E===i){x=!0,i=d,l=m;break}if(E===l){x=!0,l=d,i=m;break}E=E.sibling}if(!x){for(E=m.child;E;){if(E===i){x=!0,i=m,l=d;break}if(E===l){x=!0,l=m,i=d;break}E=E.sibling}if(!x)throw Error(a(189))}}if(i.alternate!==l)throw Error(a(190))}if(i.tag!==3)throw Error(a(188));return i.stateNode.current===i?e:n}function Rc(e){return e=Dm(e),e!==null?Ac(e):null}function Ac(e){if(e.tag===5||e.tag===6)return e;for(e=e.child;e!==null;){var n=Ac(e);if(n!==null)return n;e=e.sibling}return null}var Ic=s.unstable_scheduleCallback,Pc=s.unstable_cancelCallback,Um=s.unstable_shouldYield,Wm=s.unstable_requestPaint,dt=s.unstable_now,Hm=s.unstable_getCurrentPriorityLevel,Di=s.unstable_ImmediatePriority,_c=s.unstable_UserBlockingPriority,sa=s.unstable_NormalPriority,Vm=s.unstable_LowPriority,$c=s.unstable_IdlePriority,aa=null,gn=null;function Gm(e){if(gn&&typeof gn.onCommitFiberRoot=="function")try{gn.onCommitFiberRoot(aa,e,void 0,(e.current.flags&128)===128)}catch{}}var sn=Math.clz32?Math.clz32:Ym,Km=Math.log,qm=Math.LN2;function Ym(e){return e>>>=0,e===0?32:31-(Km(e)/qm|0)|0}var ia=64,oa=4194304;function os(e){switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return e&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return e&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return e}}function la(e,n){var i=e.pendingLanes;if(i===0)return 0;var l=0,d=e.suspendedLanes,m=e.pingedLanes,x=i&268435455;if(x!==0){var E=x&~d;E!==0?l=os(E):(m&=x,m!==0&&(l=os(m)))}else x=i&~d,x!==0?l=os(x):m!==0&&(l=os(m));if(l===0)return 0;if(n!==0&&n!==l&&(n&d)===0&&(d=l&-l,m=n&-n,d>=m||d===16&&(m&4194240)!==0))return n;if((l&4)!==0&&(l|=i&16),n=e.entangledLanes,n!==0)for(e=e.entanglements,n&=l;0<n;)i=31-sn(n),d=1<<i,l|=e[i],n&=~d;return l}function Jm(e,n){switch(e){case 1:case 2:case 4:return n+250;case 8:case 16:case 32:case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return n+5e3;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return-1;case 134217728:case 268435456:case 536870912:case 1073741824:return-1;default:return-1}}function Qm(e,n){for(var i=e.suspendedLanes,l=e.pingedLanes,d=e.expirationTimes,m=e.pendingLanes;0<m;){var x=31-sn(m),E=1<<x,I=d[x];I===-1?((E&i)===0||(E&l)!==0)&&(d[x]=Jm(E,n)):I<=n&&(e.expiredLanes|=E),m&=~E}}function Ui(e){return e=e.pendingLanes&-1073741825,e!==0?e:e&1073741824?1073741824:0}function Lc(){var e=ia;return ia<<=1,(ia&4194240)===0&&(ia=64),e}function Wi(e){for(var n=[],i=0;31>i;i++)n.push(e);return n}function ls(e,n,i){e.pendingLanes|=n,n!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,n=31-sn(n),e[n]=i}function Xm(e,n){var i=e.pendingLanes&~n;e.pendingLanes=n,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=n,e.mutableReadLanes&=n,e.entangledLanes&=n,n=e.entanglements;var l=e.eventTimes;for(e=e.expirationTimes;0<i;){var d=31-sn(i),m=1<<d;n[d]=0,l[d]=-1,e[d]=-1,i&=~m}}function Hi(e,n){var i=e.entangledLanes|=n;for(e=e.entanglements;i;){var l=31-sn(i),d=1<<l;d&n|e[l]&n&&(e[l]|=n),i&=~d}}var qe=0;function zc(e){return e&=-e,1<e?4<e?(e&268435455)!==0?16:536870912:4:1}var Fc,Vi,Oc,Mc,Bc,Gi=!1,ca=[],Ln=null,zn=null,Fn=null,cs=new Map,us=new Map,On=[],Zm="mousedown mouseup touchcancel touchend touchstart auxclick dblclick pointercancel pointerdown pointerup dragend dragstart drop compositionend compositionstart keydown keypress keyup input textInput copy cut paste click change contextmenu reset submit".split(" ");function Dc(e,n){switch(e){case"focusin":case"focusout":Ln=null;break;case"dragenter":case"dragleave":zn=null;break;case"mouseover":case"mouseout":Fn=null;break;case"pointerover":case"pointerout":cs.delete(n.pointerId);break;case"gotpointercapture":case"lostpointercapture":us.delete(n.pointerId)}}function ds(e,n,i,l,d,m){return e===null||e.nativeEvent!==m?(e={blockedOn:n,domEventName:i,eventSystemFlags:l,nativeEvent:m,targetContainers:[d]},n!==null&&(n=Ns(n),n!==null&&Vi(n)),e):(e.eventSystemFlags|=l,n=e.targetContainers,d!==null&&n.indexOf(d)===-1&&n.push(d),e)}function ep(e,n,i,l,d){switch(n){case"focusin":return Ln=ds(Ln,e,n,i,l,d),!0;case"dragenter":return zn=ds(zn,e,n,i,l,d),!0;case"mouseover":return Fn=ds(Fn,e,n,i,l,d),!0;case"pointerover":var m=d.pointerId;return cs.set(m,ds(cs.get(m)||null,e,n,i,l,d)),!0;case"gotpointercapture":return m=d.pointerId,us.set(m,ds(us.get(m)||null,e,n,i,l,d)),!0}return!1}function Uc(e){var n=ir(e.target);if(n!==null){var i=ar(n);if(i!==null){if(n=i.tag,n===13){if(n=Ec(i),n!==null){e.blockedOn=n,Bc(e.priority,function(){Oc(i)});return}}else if(n===3&&i.stateNode.current.memoizedState.isDehydrated){e.blockedOn=i.tag===3?i.stateNode.containerInfo:null;return}}}e.blockedOn=null}function ua(e){if(e.blockedOn!==null)return!1;for(var n=e.targetContainers;0<n.length;){var i=qi(e.domEventName,e.eventSystemFlags,n[0],e.nativeEvent);if(i===null){i=e.nativeEvent;var l=new i.constructor(i.type,i);Et=l,i.target.dispatchEvent(l),Et=null}else return n=Ns(i),n!==null&&Vi(n),e.blockedOn=i,!1;n.shift()}return!0}function Wc(e,n,i){ua(e)&&i.delete(n)}function tp(){Gi=!1,Ln!==null&&ua(Ln)&&(Ln=null),zn!==null&&ua(zn)&&(zn=null),Fn!==null&&ua(Fn)&&(Fn=null),cs.forEach(Wc),us.forEach(Wc)}function fs(e,n){e.blockedOn===n&&(e.blockedOn=null,Gi||(Gi=!0,s.unstable_scheduleCallback(s.unstable_NormalPriority,tp)))}function hs(e){function n(d){return fs(d,e)}if(0<ca.length){fs(ca[0],e);for(var i=1;i<ca.length;i++){var l=ca[i];l.blockedOn===e&&(l.blockedOn=null)}}for(Ln!==null&&fs(Ln,e),zn!==null&&fs(zn,e),Fn!==null&&fs(Fn,e),cs.forEach(n),us.forEach(n),i=0;i<On.length;i++)l=On[i],l.blockedOn===e&&(l.blockedOn=null);for(;0<On.length&&(i=On[0],i.blockedOn===null);)Uc(i),i.blockedOn===null&&On.shift()}var Er=A.ReactCurrentBatchConfig,da=!0;function np(e,n,i,l){var d=qe,m=Er.transition;Er.transition=null;try{qe=1,Ki(e,n,i,l)}finally{qe=d,Er.transition=m}}function rp(e,n,i,l){var d=qe,m=Er.transition;Er.transition=null;try{qe=4,Ki(e,n,i,l)}finally{qe=d,Er.transition=m}}function Ki(e,n,i,l){if(da){var d=qi(e,n,i,l);if(d===null)fo(e,n,l,fa,i),Dc(e,l);else if(ep(d,e,n,i,l))l.stopPropagation();else if(Dc(e,l),n&4&&-1<Zm.indexOf(e)){for(;d!==null;){var m=Ns(d);if(m!==null&&Fc(m),m=qi(e,n,i,l),m===null&&fo(e,n,l,fa,i),m===d)break;d=m}d!==null&&l.stopPropagation()}else fo(e,n,l,null,i)}}var fa=null;function qi(e,n,i,l){if(fa=null,e=wt(l),e=ir(e),e!==null)if(n=ar(e),n===null)e=null;else if(i=n.tag,i===13){if(e=Ec(n),e!==null)return e;e=null}else if(i===3){if(n.stateNode.current.memoizedState.isDehydrated)return n.tag===3?n.stateNode.containerInfo:null;e=null}else n!==e&&(e=null);return fa=e,null}function Hc(e){switch(e){case"cancel":case"click":case"close":case"contextmenu":case"copy":case"cut":case"auxclick":case"dblclick":case"dragend":case"dragstart":case"drop":case"focusin":case"focusout":case"input":case"invalid":case"keydown":case"keypress":case"keyup":case"mousedown":case"mouseup":case"paste":case"pause":case"play":case"pointercancel":case"pointerdown":case"pointerup":case"ratechange":case"reset":case"resize":case"seeked":case"submit":case"touchcancel":case"touchend":case"touchstart":case"volumechange":case"change":case"selectionchange":case"textInput":case"compositionstart":case"compositionend":case"compositionupdate":case"beforeblur":case"afterblur":case"beforeinput":case"blur":case"fullscreenchange":case"focus":case"hashchange":case"popstate":case"select":case"selectstart":return 1;case"drag":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"mousemove":case"mouseout":case"mouseover":case"pointermove":case"pointerout":case"pointerover":case"scroll":case"toggle":case"touchmove":case"wheel":case"mouseenter":case"mouseleave":case"pointerenter":case"pointerleave":return 4;case"message":switch(Hm()){case Di:return 1;case _c:return 4;case sa:case Vm:return 16;case $c:return 536870912;default:return 16}default:return 16}}var Mn=null,Yi=null,ha=null;function Vc(){if(ha)return ha;var e,n=Yi,i=n.length,l,d="value"in Mn?Mn.value:Mn.textContent,m=d.length;for(e=0;e<i&&n[e]===d[e];e++);var x=i-e;for(l=1;l<=x&&n[i-l]===d[m-l];l++);return ha=d.slice(e,1<l?1-l:void 0)}function ma(e){var n=e.keyCode;return"charCode"in e?(e=e.charCode,e===0&&n===13&&(e=13)):e=n,e===10&&(e=13),32<=e||e===13?e:0}function pa(){return!0}function Gc(){return!1}function Ht(e){function n(i,l,d,m,x){this._reactName=i,this._targetInst=d,this.type=l,this.nativeEvent=m,this.target=x,this.currentTarget=null;for(var E in e)e.hasOwnProperty(E)&&(i=e[E],this[E]=i?i(m):m[E]);return this.isDefaultPrevented=(m.defaultPrevented!=null?m.defaultPrevented:m.returnValue===!1)?pa:Gc,this.isPropagationStopped=Gc,this}return W(n.prototype,{preventDefault:function(){this.defaultPrevented=!0;var i=this.nativeEvent;i&&(i.preventDefault?i.preventDefault():typeof i.returnValue!="unknown"&&(i.returnValue=!1),this.isDefaultPrevented=pa)},stopPropagation:function(){var i=this.nativeEvent;i&&(i.stopPropagation?i.stopPropagation():typeof i.cancelBubble!="unknown"&&(i.cancelBubble=!0),this.isPropagationStopped=pa)},persist:function(){},isPersistent:pa}),n}var Tr={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},Ji=Ht(Tr),ms=W({},Tr,{view:0,detail:0}),sp=Ht(ms),Qi,Xi,ps,ga=W({},ms,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:eo,button:0,buttons:0,relatedTarget:function(e){return e.relatedTarget===void 0?e.fromElement===e.srcElement?e.toElement:e.fromElement:e.relatedTarget},movementX:function(e){return"movementX"in e?e.movementX:(e!==ps&&(ps&&e.type==="mousemove"?(Qi=e.screenX-ps.screenX,Xi=e.screenY-ps.screenY):Xi=Qi=0,ps=e),Qi)},movementY:function(e){return"movementY"in e?e.movementY:Xi}}),Kc=Ht(ga),ap=W({},ga,{dataTransfer:0}),ip=Ht(ap),op=W({},ms,{relatedTarget:0}),Zi=Ht(op),lp=W({},Tr,{animationName:0,elapsedTime:0,pseudoElement:0}),cp=Ht(lp),up=W({},Tr,{clipboardData:function(e){return"clipboardData"in e?e.clipboardData:window.clipboardData}}),dp=Ht(up),fp=W({},Tr,{data:0}),qc=Ht(fp),hp={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},mp={8:"Backspace",9:"Tab",12:"Clear",13:"Enter",16:"Shift",17:"Control",18:"Alt",19:"Pause",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",45:"Insert",46:"Delete",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NumLock",145:"ScrollLock",224:"Meta"},pp={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function gp(e){var n=this.nativeEvent;return n.getModifierState?n.getModifierState(e):(e=pp[e])?!!n[e]:!1}function eo(){return gp}var yp=W({},ms,{key:function(e){if(e.key){var n=hp[e.key]||e.key;if(n!=="Unidentified")return n}return e.type==="keypress"?(e=ma(e),e===13?"Enter":String.fromCharCode(e)):e.type==="keydown"||e.type==="keyup"?mp[e.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:eo,charCode:function(e){return e.type==="keypress"?ma(e):0},keyCode:function(e){return e.type==="keydown"||e.type==="keyup"?e.keyCode:0},which:function(e){return e.type==="keypress"?ma(e):e.type==="keydown"||e.type==="keyup"?e.keyCode:0}}),vp=Ht(yp),xp=W({},ga,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),Yc=Ht(xp),wp=W({},ms,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:eo}),jp=Ht(wp),Sp=W({},Tr,{propertyName:0,elapsedTime:0,pseudoElement:0}),bp=Ht(Sp),kp=W({},ga,{deltaX:function(e){return"deltaX"in e?e.deltaX:"wheelDeltaX"in e?-e.wheelDeltaX:0},deltaY:function(e){return"deltaY"in e?e.deltaY:"wheelDeltaY"in e?-e.wheelDeltaY:"wheelDelta"in e?-e.wheelDelta:0},deltaZ:0,deltaMode:0}),Np=Ht(kp),Cp=[9,13,27,32],to=g&&"CompositionEvent"in window,gs=null;g&&"documentMode"in document&&(gs=document.documentMode);var Ep=g&&"TextEvent"in window&&!gs,Jc=g&&(!to||gs&&8<gs&&11>=gs),Qc=" ",Xc=!1;function Zc(e,n){switch(e){case"keyup":return Cp.indexOf(n.keyCode)!==-1;case"keydown":return n.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function eu(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Rr=!1;function Tp(e,n){switch(e){case"compositionend":return eu(n);case"keypress":return n.which!==32?null:(Xc=!0,Qc);case"textInput":return e=n.data,e===Qc&&Xc?null:e;default:return null}}function Rp(e,n){if(Rr)return e==="compositionend"||!to&&Zc(e,n)?(e=Vc(),ha=Yi=Mn=null,Rr=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(n.ctrlKey||n.altKey||n.metaKey)||n.ctrlKey&&n.altKey){if(n.char&&1<n.char.length)return n.char;if(n.which)return String.fromCharCode(n.which)}return null;case"compositionend":return Jc&&n.locale!=="ko"?null:n.data;default:return null}}var Ap={color:!0,date:!0,datetime:!0,"datetime-local":!0,email:!0,month:!0,number:!0,password:!0,range:!0,search:!0,tel:!0,text:!0,time:!0,url:!0,week:!0};function tu(e){var n=e&&e.nodeName&&e.nodeName.toLowerCase();return n==="input"?!!Ap[e.type]:n==="textarea"}function nu(e,n,i,l){Fe(l),n=ja(n,"onChange"),0<n.length&&(i=new Ji("onChange","change",null,i,l),e.push({event:i,listeners:n}))}var ys=null,vs=null;function Ip(e){wu(e,0)}function ya(e){var n=$r(e);if($e(n))return e}function Pp(e,n){if(e==="change")return n}var ru=!1;if(g){var no;if(g){var ro="oninput"in document;if(!ro){var su=document.createElement("div");su.setAttribute("oninput","return;"),ro=typeof su.oninput=="function"}no=ro}else no=!1;ru=no&&(!document.documentMode||9<document.documentMode)}function au(){ys&&(ys.detachEvent("onpropertychange",iu),vs=ys=null)}function iu(e){if(e.propertyName==="value"&&ya(vs)){var n=[];nu(n,vs,e,wt(e)),na(Ip,n)}}function _p(e,n,i){e==="focusin"?(au(),ys=n,vs=i,ys.attachEvent("onpropertychange",iu)):e==="focusout"&&au()}function $p(e){if(e==="selectionchange"||e==="keyup"||e==="keydown")return ya(vs)}function Lp(e,n){if(e==="click")return ya(n)}function zp(e,n){if(e==="input"||e==="change")return ya(n)}function Fp(e,n){return e===n&&(e!==0||1/e===1/n)||e!==e&&n!==n}var an=typeof Object.is=="function"?Object.is:Fp;function xs(e,n){if(an(e,n))return!0;if(typeof e!="object"||e===null||typeof n!="object"||n===null)return!1;var i=Object.keys(e),l=Object.keys(n);if(i.length!==l.length)return!1;for(l=0;l<i.length;l++){var d=i[l];if(!p.call(n,d)||!an(e[d],n[d]))return!1}return!0}function ou(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function lu(e,n){var i=ou(e);e=0;for(var l;i;){if(i.nodeType===3){if(l=e+i.textContent.length,e<=n&&l>=n)return{node:i,offset:n-e};e=l}e:{for(;i;){if(i.nextSibling){i=i.nextSibling;break e}i=i.parentNode}i=void 0}i=ou(i)}}function cu(e,n){return e&&n?e===n?!0:e&&e.nodeType===3?!1:n&&n.nodeType===3?cu(e,n.parentNode):"contains"in e?e.contains(n):e.compareDocumentPosition?!!(e.compareDocumentPosition(n)&16):!1:!1}function uu(){for(var e=window,n=pe();n instanceof e.HTMLIFrameElement;){try{var i=typeof n.contentWindow.location.href=="string"}catch{i=!1}if(i)e=n.contentWindow;else break;n=pe(e.document)}return n}function so(e){var n=e&&e.nodeName&&e.nodeName.toLowerCase();return n&&(n==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||n==="textarea"||e.contentEditable==="true")}function Op(e){var n=uu(),i=e.focusedElem,l=e.selectionRange;if(n!==i&&i&&i.ownerDocument&&cu(i.ownerDocument.documentElement,i)){if(l!==null&&so(i)){if(n=l.start,e=l.end,e===void 0&&(e=n),"selectionStart"in i)i.selectionStart=n,i.selectionEnd=Math.min(e,i.value.length);else if(e=(n=i.ownerDocument||document)&&n.defaultView||window,e.getSelection){e=e.getSelection();var d=i.textContent.length,m=Math.min(l.start,d);l=l.end===void 0?m:Math.min(l.end,d),!e.extend&&m>l&&(d=l,l=m,m=d),d=lu(i,m);var x=lu(i,l);d&&x&&(e.rangeCount!==1||e.anchorNode!==d.node||e.anchorOffset!==d.offset||e.focusNode!==x.node||e.focusOffset!==x.offset)&&(n=n.createRange(),n.setStart(d.node,d.offset),e.removeAllRanges(),m>l?(e.addRange(n),e.extend(x.node,x.offset)):(n.setEnd(x.node,x.offset),e.addRange(n)))}}for(n=[],e=i;e=e.parentNode;)e.nodeType===1&&n.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof i.focus=="function"&&i.focus(),i=0;i<n.length;i++)e=n[i],e.element.scrollLeft=e.left,e.element.scrollTop=e.top}}var Mp=g&&"documentMode"in document&&11>=document.documentMode,Ar=null,ao=null,ws=null,io=!1;function du(e,n,i){var l=i.window===i?i.document:i.nodeType===9?i:i.ownerDocument;io||Ar==null||Ar!==pe(l)||(l=Ar,"selectionStart"in l&&so(l)?l={start:l.selectionStart,end:l.selectionEnd}:(l=(l.ownerDocument&&l.ownerDocument.defaultView||window).getSelection(),l={anchorNode:l.anchorNode,anchorOffset:l.anchorOffset,focusNode:l.focusNode,focusOffset:l.focusOffset}),ws&&xs(ws,l)||(ws=l,l=ja(ao,"onSelect"),0<l.length&&(n=new Ji("onSelect","select",null,n,i),e.push({event:n,listeners:l}),n.target=Ar)))}function va(e,n){var i={};return i[e.toLowerCase()]=n.toLowerCase(),i["Webkit"+e]="webkit"+n,i["Moz"+e]="moz"+n,i}var Ir={animationend:va("Animation","AnimationEnd"),animationiteration:va("Animation","AnimationIteration"),animationstart:va("Animation","AnimationStart"),transitionend:va("Transition","TransitionEnd")},oo={},fu={};g&&(fu=document.createElement("div").style,"AnimationEvent"in window||(delete Ir.animationend.animation,delete Ir.animationiteration.animation,delete Ir.animationstart.animation),"TransitionEvent"in window||delete Ir.transitionend.transition);function xa(e){if(oo[e])return oo[e];if(!Ir[e])return e;var n=Ir[e],i;for(i in n)if(n.hasOwnProperty(i)&&i in fu)return oo[e]=n[i];return e}var hu=xa("animationend"),mu=xa("animationiteration"),pu=xa("animationstart"),gu=xa("transitionend"),yu=new Map,vu="abort auxClick cancel canPlay canPlayThrough click close contextMenu copy cut drag dragEnd dragEnter dragExit dragLeave dragOver dragStart drop durationChange emptied encrypted ended error gotPointerCapture input invalid keyDown keyPress keyUp load loadedData loadedMetadata loadStart lostPointerCapture mouseDown mouseMove mouseOut mouseOver mouseUp paste pause play playing pointerCancel pointerDown pointerMove pointerOut pointerOver pointerUp progress rateChange reset resize seeked seeking stalled submit suspend timeUpdate touchCancel touchEnd touchStart volumeChange scroll toggle touchMove waiting wheel".split(" ");function Bn(e,n){yu.set(e,n),u(n,[e])}for(var lo=0;lo<vu.length;lo++){var co=vu[lo],Bp=co.toLowerCase(),Dp=co[0].toUpperCase()+co.slice(1);Bn(Bp,"on"+Dp)}Bn(hu,"onAnimationEnd"),Bn(mu,"onAnimationIteration"),Bn(pu,"onAnimationStart"),Bn("dblclick","onDoubleClick"),Bn("focusin","onFocus"),Bn("focusout","onBlur"),Bn(gu,"onTransitionEnd"),f("onMouseEnter",["mouseout","mouseover"]),f("onMouseLeave",["mouseout","mouseover"]),f("onPointerEnter",["pointerout","pointerover"]),f("onPointerLeave",["pointerout","pointerover"]),u("onChange","change click focusin focusout input keydown keyup selectionchange".split(" ")),u("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" ")),u("onBeforeInput",["compositionend","keypress","textInput","paste"]),u("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" ")),u("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" ")),u("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var js="abort canplay canplaythrough durationchange emptied encrypted ended error loadeddata loadedmetadata loadstart pause play playing progress ratechange resize seeked seeking stalled suspend timeupdate volumechange waiting".split(" "),Up=new Set("cancel close invalid load scroll toggle".split(" ").concat(js));function xu(e,n,i){var l=e.type||"unknown-event";e.currentTarget=i,Bm(l,n,void 0,e),e.currentTarget=null}function wu(e,n){n=(n&4)!==0;for(var i=0;i<e.length;i++){var l=e[i],d=l.event;l=l.listeners;e:{var m=void 0;if(n)for(var x=l.length-1;0<=x;x--){var E=l[x],I=E.instance,U=E.currentTarget;if(E=E.listener,I!==m&&d.isPropagationStopped())break e;xu(d,E,U),m=I}else for(x=0;x<l.length;x++){if(E=l[x],I=E.instance,U=E.currentTarget,E=E.listener,I!==m&&d.isPropagationStopped())break e;xu(d,E,U),m=I}}}if(sr)throw e=is,sr=!1,is=null,e}function tt(e,n){var i=n[vo];i===void 0&&(i=n[vo]=new Set);var l=e+"__bubble";i.has(l)||(ju(n,e,2,!1),i.add(l))}function uo(e,n,i){var l=0;n&&(l|=4),ju(i,e,l,n)}var wa="_reactListening"+Math.random().toString(36).slice(2);function Ss(e){if(!e[wa]){e[wa]=!0,o.forEach(function(i){i!=="selectionchange"&&(Up.has(i)||uo(i,!1,e),uo(i,!0,e))});var n=e.nodeType===9?e:e.ownerDocument;n===null||n[wa]||(n[wa]=!0,uo("selectionchange",!1,n))}}function ju(e,n,i,l){switch(Hc(n)){case 1:var d=np;break;case 4:d=rp;break;default:d=Ki}i=d.bind(null,n,i,e),d=void 0,!tr||n!=="touchstart"&&n!=="touchmove"&&n!=="wheel"||(d=!0),l?d!==void 0?e.addEventListener(n,i,{capture:!0,passive:d}):e.addEventListener(n,i,!0):d!==void 0?e.addEventListener(n,i,{passive:d}):e.addEventListener(n,i,!1)}function fo(e,n,i,l,d){var m=l;if((n&1)===0&&(n&2)===0&&l!==null)e:for(;;){if(l===null)return;var x=l.tag;if(x===3||x===4){var E=l.stateNode.containerInfo;if(E===d||E.nodeType===8&&E.parentNode===d)break;if(x===4)for(x=l.return;x!==null;){var I=x.tag;if((I===3||I===4)&&(I=x.stateNode.containerInfo,I===d||I.nodeType===8&&I.parentNode===d))return;x=x.return}for(;E!==null;){if(x=ir(E),x===null)return;if(I=x.tag,I===5||I===6){l=m=x;continue e}E=E.parentNode}}l=l.return}na(function(){var U=m,te=wt(i),ae=[];e:{var Z=yu.get(e);if(Z!==void 0){var xe=Ji,be=e;switch(e){case"keypress":if(ma(i)===0)break e;case"keydown":case"keyup":xe=vp;break;case"focusin":be="focus",xe=Zi;break;case"focusout":be="blur",xe=Zi;break;case"beforeblur":case"afterblur":xe=Zi;break;case"click":if(i.button===2)break e;case"auxclick":case"dblclick":case"mousedown":case"mousemove":case"mouseup":case"mouseout":case"mouseover":case"contextmenu":xe=Kc;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":xe=ip;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":xe=jp;break;case hu:case mu:case pu:xe=cp;break;case gu:xe=bp;break;case"scroll":xe=sp;break;case"wheel":xe=Np;break;case"copy":case"cut":case"paste":xe=dp;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":xe=Yc}var Ce=(n&4)!==0,ft=!Ce&&e==="scroll",M=Ce?Z!==null?Z+"Capture":null:Z;Ce=[];for(var $=U,D;$!==null;){D=$;var ue=D.stateNode;if(D.tag===5&&ue!==null&&(D=ue,M!==null&&(ue=Sn($,M),ue!=null&&Ce.push(bs($,ue,D)))),ft)break;$=$.return}0<Ce.length&&(Z=new xe(Z,be,null,i,te),ae.push({event:Z,listeners:Ce}))}}if((n&7)===0){e:{if(Z=e==="mouseover"||e==="pointerover",xe=e==="mouseout"||e==="pointerout",Z&&i!==Et&&(be=i.relatedTarget||i.fromElement)&&(ir(be)||be[kn]))break e;if((xe||Z)&&(Z=te.window===te?te:(Z=te.ownerDocument)?Z.defaultView||Z.parentWindow:window,xe?(be=i.relatedTarget||i.toElement,xe=U,be=be?ir(be):null,be!==null&&(ft=ar(be),be!==ft||be.tag!==5&&be.tag!==6)&&(be=null)):(xe=null,be=U),xe!==be)){if(Ce=Kc,ue="onMouseLeave",M="onMouseEnter",$="mouse",(e==="pointerout"||e==="pointerover")&&(Ce=Yc,ue="onPointerLeave",M="onPointerEnter",$="pointer"),ft=xe==null?Z:$r(xe),D=be==null?Z:$r(be),Z=new Ce(ue,$+"leave",xe,i,te),Z.target=ft,Z.relatedTarget=D,ue=null,ir(te)===U&&(Ce=new Ce(M,$+"enter",be,i,te),Ce.target=D,Ce.relatedTarget=ft,ue=Ce),ft=ue,xe&&be)t:{for(Ce=xe,M=be,$=0,D=Ce;D;D=Pr(D))$++;for(D=0,ue=M;ue;ue=Pr(ue))D++;for(;0<$-D;)Ce=Pr(Ce),$--;for(;0<D-$;)M=Pr(M),D--;for(;$--;){if(Ce===M||M!==null&&Ce===M.alternate)break t;Ce=Pr(Ce),M=Pr(M)}Ce=null}else Ce=null;xe!==null&&Su(ae,Z,xe,Ce,!1),be!==null&&ft!==null&&Su(ae,ft,be,Ce,!0)}}e:{if(Z=U?$r(U):window,xe=Z.nodeName&&Z.nodeName.toLowerCase(),xe==="select"||xe==="input"&&Z.type==="file")var Ee=Pp;else if(tu(Z))if(ru)Ee=zp;else{Ee=$p;var Ae=_p}else(xe=Z.nodeName)&&xe.toLowerCase()==="input"&&(Z.type==="checkbox"||Z.type==="radio")&&(Ee=Lp);if(Ee&&(Ee=Ee(e,U))){nu(ae,Ee,i,te);break e}Ae&&Ae(e,Z,U),e==="focusout"&&(Ae=Z._wrapperState)&&Ae.controlled&&Z.type==="number"&&he(Z,"number",Z.value)}switch(Ae=U?$r(U):window,e){case"focusin":(tu(Ae)||Ae.contentEditable==="true")&&(Ar=Ae,ao=U,ws=null);break;case"focusout":ws=ao=Ar=null;break;case"mousedown":io=!0;break;case"contextmenu":case"mouseup":case"dragend":io=!1,du(ae,i,te);break;case"selectionchange":if(Mp)break;case"keydown":case"keyup":du(ae,i,te)}var Ie;if(to)e:{switch(e){case"compositionstart":var _e="onCompositionStart";break e;case"compositionend":_e="onCompositionEnd";break e;case"compositionupdate":_e="onCompositionUpdate";break e}_e=void 0}else Rr?Zc(e,i)&&(_e="onCompositionEnd"):e==="keydown"&&i.keyCode===229&&(_e="onCompositionStart");_e&&(Jc&&i.locale!=="ko"&&(Rr||_e!=="onCompositionStart"?_e==="onCompositionEnd"&&Rr&&(Ie=Vc()):(Mn=te,Yi="value"in Mn?Mn.value:Mn.textContent,Rr=!0)),Ae=ja(U,_e),0<Ae.length&&(_e=new qc(_e,e,null,i,te),ae.push({event:_e,listeners:Ae}),Ie?_e.data=Ie:(Ie=eu(i),Ie!==null&&(_e.data=Ie)))),(Ie=Ep?Tp(e,i):Rp(e,i))&&(U=ja(U,"onBeforeInput"),0<U.length&&(te=new qc("onBeforeInput","beforeinput",null,i,te),ae.push({event:te,listeners:U}),te.data=Ie))}wu(ae,n)})}function bs(e,n,i){return{instance:e,listener:n,currentTarget:i}}function ja(e,n){for(var i=n+"Capture",l=[];e!==null;){var d=e,m=d.stateNode;d.tag===5&&m!==null&&(d=m,m=Sn(e,i),m!=null&&l.unshift(bs(e,m,d)),m=Sn(e,n),m!=null&&l.push(bs(e,m,d))),e=e.return}return l}function Pr(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5);return e||null}function Su(e,n,i,l,d){for(var m=n._reactName,x=[];i!==null&&i!==l;){var E=i,I=E.alternate,U=E.stateNode;if(I!==null&&I===l)break;E.tag===5&&U!==null&&(E=U,d?(I=Sn(i,m),I!=null&&x.unshift(bs(i,I,E))):d||(I=Sn(i,m),I!=null&&x.push(bs(i,I,E)))),i=i.return}x.length!==0&&e.push({event:n,listeners:x})}var Wp=/\r\n?/g,Hp=/\u0000|\uFFFD/g;function bu(e){return(typeof e=="string"?e:""+e).replace(Wp,`
38
+ `).replace(Hp,"")}function Sa(e,n,i){if(n=bu(n),bu(e)!==n&&i)throw Error(a(425))}function ba(){}var ho=null,mo=null;function po(e,n){return e==="textarea"||e==="noscript"||typeof n.children=="string"||typeof n.children=="number"||typeof n.dangerouslySetInnerHTML=="object"&&n.dangerouslySetInnerHTML!==null&&n.dangerouslySetInnerHTML.__html!=null}var go=typeof setTimeout=="function"?setTimeout:void 0,Vp=typeof clearTimeout=="function"?clearTimeout:void 0,ku=typeof Promise=="function"?Promise:void 0,Gp=typeof queueMicrotask=="function"?queueMicrotask:typeof ku<"u"?function(e){return ku.resolve(null).then(e).catch(Kp)}:go;function Kp(e){setTimeout(function(){throw e})}function yo(e,n){var i=n,l=0;do{var d=i.nextSibling;if(e.removeChild(i),d&&d.nodeType===8)if(i=d.data,i==="/$"){if(l===0){e.removeChild(d),hs(n);return}l--}else i!=="$"&&i!=="$?"&&i!=="$!"||l++;i=d}while(i);hs(n)}function Dn(e){for(;e!=null;e=e.nextSibling){var n=e.nodeType;if(n===1||n===3)break;if(n===8){if(n=e.data,n==="$"||n==="$!"||n==="$?")break;if(n==="/$")return null}}return e}function Nu(e){e=e.previousSibling;for(var n=0;e;){if(e.nodeType===8){var i=e.data;if(i==="$"||i==="$!"||i==="$?"){if(n===0)return e;n--}else i==="/$"&&n++}e=e.previousSibling}return null}var _r=Math.random().toString(36).slice(2),yn="__reactFiber$"+_r,ks="__reactProps$"+_r,kn="__reactContainer$"+_r,vo="__reactEvents$"+_r,qp="__reactListeners$"+_r,Yp="__reactHandles$"+_r;function ir(e){var n=e[yn];if(n)return n;for(var i=e.parentNode;i;){if(n=i[kn]||i[yn]){if(i=n.alternate,n.child!==null||i!==null&&i.child!==null)for(e=Nu(e);e!==null;){if(i=e[yn])return i;e=Nu(e)}return n}e=i,i=e.parentNode}return null}function Ns(e){return e=e[yn]||e[kn],!e||e.tag!==5&&e.tag!==6&&e.tag!==13&&e.tag!==3?null:e}function $r(e){if(e.tag===5||e.tag===6)return e.stateNode;throw Error(a(33))}function ka(e){return e[ks]||null}var xo=[],Lr=-1;function Un(e){return{current:e}}function nt(e){0>Lr||(e.current=xo[Lr],xo[Lr]=null,Lr--)}function Ze(e,n){Lr++,xo[Lr]=e.current,e.current=n}var Wn={},Tt=Un(Wn),Lt=Un(!1),or=Wn;function zr(e,n){var i=e.type.contextTypes;if(!i)return Wn;var l=e.stateNode;if(l&&l.__reactInternalMemoizedUnmaskedChildContext===n)return l.__reactInternalMemoizedMaskedChildContext;var d={},m;for(m in i)d[m]=n[m];return l&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=n,e.__reactInternalMemoizedMaskedChildContext=d),d}function zt(e){return e=e.childContextTypes,e!=null}function Na(){nt(Lt),nt(Tt)}function Cu(e,n,i){if(Tt.current!==Wn)throw Error(a(168));Ze(Tt,n),Ze(Lt,i)}function Eu(e,n,i){var l=e.stateNode;if(n=n.childContextTypes,typeof l.getChildContext!="function")return i;l=l.getChildContext();for(var d in l)if(!(d in n))throw Error(a(108,ne(e)||"Unknown",d));return W({},i,l)}function Ca(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||Wn,or=Tt.current,Ze(Tt,e),Ze(Lt,Lt.current),!0}function Tu(e,n,i){var l=e.stateNode;if(!l)throw Error(a(169));i?(e=Eu(e,n,or),l.__reactInternalMemoizedMergedChildContext=e,nt(Lt),nt(Tt),Ze(Tt,e)):nt(Lt),Ze(Lt,i)}var Nn=null,Ea=!1,wo=!1;function Ru(e){Nn===null?Nn=[e]:Nn.push(e)}function Jp(e){Ea=!0,Ru(e)}function Hn(){if(!wo&&Nn!==null){wo=!0;var e=0,n=qe;try{var i=Nn;for(qe=1;e<i.length;e++){var l=i[e];do l=l(!0);while(l!==null)}Nn=null,Ea=!1}catch(d){throw Nn!==null&&(Nn=Nn.slice(e+1)),Ic(Di,Hn),d}finally{qe=n,wo=!1}}return null}var Fr=[],Or=0,Ta=null,Ra=0,Jt=[],Qt=0,lr=null,Cn=1,En="";function cr(e,n){Fr[Or++]=Ra,Fr[Or++]=Ta,Ta=e,Ra=n}function Au(e,n,i){Jt[Qt++]=Cn,Jt[Qt++]=En,Jt[Qt++]=lr,lr=e;var l=Cn;e=En;var d=32-sn(l)-1;l&=~(1<<d),i+=1;var m=32-sn(n)+d;if(30<m){var x=d-d%5;m=(l&(1<<x)-1).toString(32),l>>=x,d-=x,Cn=1<<32-sn(n)+d|i<<d|l,En=m+e}else Cn=1<<m|i<<d|l,En=e}function jo(e){e.return!==null&&(cr(e,1),Au(e,1,0))}function So(e){for(;e===Ta;)Ta=Fr[--Or],Fr[Or]=null,Ra=Fr[--Or],Fr[Or]=null;for(;e===lr;)lr=Jt[--Qt],Jt[Qt]=null,En=Jt[--Qt],Jt[Qt]=null,Cn=Jt[--Qt],Jt[Qt]=null}var Vt=null,Gt=null,st=!1,on=null;function Iu(e,n){var i=tn(5,null,null,0);i.elementType="DELETED",i.stateNode=n,i.return=e,n=e.deletions,n===null?(e.deletions=[i],e.flags|=16):n.push(i)}function Pu(e,n){switch(e.tag){case 5:var i=e.type;return n=n.nodeType!==1||i.toLowerCase()!==n.nodeName.toLowerCase()?null:n,n!==null?(e.stateNode=n,Vt=e,Gt=Dn(n.firstChild),!0):!1;case 6:return n=e.pendingProps===""||n.nodeType!==3?null:n,n!==null?(e.stateNode=n,Vt=e,Gt=null,!0):!1;case 13:return n=n.nodeType!==8?null:n,n!==null?(i=lr!==null?{id:Cn,overflow:En}:null,e.memoizedState={dehydrated:n,treeContext:i,retryLane:1073741824},i=tn(18,null,null,0),i.stateNode=n,i.return=e,e.child=i,Vt=e,Gt=null,!0):!1;default:return!1}}function bo(e){return(e.mode&1)!==0&&(e.flags&128)===0}function ko(e){if(st){var n=Gt;if(n){var i=n;if(!Pu(e,n)){if(bo(e))throw Error(a(418));n=Dn(i.nextSibling);var l=Vt;n&&Pu(e,n)?Iu(l,i):(e.flags=e.flags&-4097|2,st=!1,Vt=e)}}else{if(bo(e))throw Error(a(418));e.flags=e.flags&-4097|2,st=!1,Vt=e}}}function _u(e){for(e=e.return;e!==null&&e.tag!==5&&e.tag!==3&&e.tag!==13;)e=e.return;Vt=e}function Aa(e){if(e!==Vt)return!1;if(!st)return _u(e),st=!0,!1;var n;if((n=e.tag!==3)&&!(n=e.tag!==5)&&(n=e.type,n=n!=="head"&&n!=="body"&&!po(e.type,e.memoizedProps)),n&&(n=Gt)){if(bo(e))throw $u(),Error(a(418));for(;n;)Iu(e,n),n=Dn(n.nextSibling)}if(_u(e),e.tag===13){if(e=e.memoizedState,e=e!==null?e.dehydrated:null,!e)throw Error(a(317));e:{for(e=e.nextSibling,n=0;e;){if(e.nodeType===8){var i=e.data;if(i==="/$"){if(n===0){Gt=Dn(e.nextSibling);break e}n--}else i!=="$"&&i!=="$!"&&i!=="$?"||n++}e=e.nextSibling}Gt=null}}else Gt=Vt?Dn(e.stateNode.nextSibling):null;return!0}function $u(){for(var e=Gt;e;)e=Dn(e.nextSibling)}function Mr(){Gt=Vt=null,st=!1}function No(e){on===null?on=[e]:on.push(e)}var Qp=A.ReactCurrentBatchConfig;function Cs(e,n,i){if(e=i.ref,e!==null&&typeof e!="function"&&typeof e!="object"){if(i._owner){if(i=i._owner,i){if(i.tag!==1)throw Error(a(309));var l=i.stateNode}if(!l)throw Error(a(147,e));var d=l,m=""+e;return n!==null&&n.ref!==null&&typeof n.ref=="function"&&n.ref._stringRef===m?n.ref:(n=function(x){var E=d.refs;x===null?delete E[m]:E[m]=x},n._stringRef=m,n)}if(typeof e!="string")throw Error(a(284));if(!i._owner)throw Error(a(290,e))}return e}function Ia(e,n){throw e=Object.prototype.toString.call(n),Error(a(31,e==="[object Object]"?"object with keys {"+Object.keys(n).join(", ")+"}":e))}function Lu(e){var n=e._init;return n(e._payload)}function zu(e){function n(M,$){if(e){var D=M.deletions;D===null?(M.deletions=[$],M.flags|=16):D.push($)}}function i(M,$){if(!e)return null;for(;$!==null;)n(M,$),$=$.sibling;return null}function l(M,$){for(M=new Map;$!==null;)$.key!==null?M.set($.key,$):M.set($.index,$),$=$.sibling;return M}function d(M,$){return M=Xn(M,$),M.index=0,M.sibling=null,M}function m(M,$,D){return M.index=D,e?(D=M.alternate,D!==null?(D=D.index,D<$?(M.flags|=2,$):D):(M.flags|=2,$)):(M.flags|=1048576,$)}function x(M){return e&&M.alternate===null&&(M.flags|=2),M}function E(M,$,D,ue){return $===null||$.tag!==6?($=gl(D,M.mode,ue),$.return=M,$):($=d($,D),$.return=M,$)}function I(M,$,D,ue){var Ee=D.type;return Ee===G?te(M,$,D.props.children,ue,D.key):$!==null&&($.elementType===Ee||typeof Ee=="object"&&Ee!==null&&Ee.$$typeof===ye&&Lu(Ee)===$.type)?(ue=d($,D.props),ue.ref=Cs(M,$,D),ue.return=M,ue):(ue=ti(D.type,D.key,D.props,null,M.mode,ue),ue.ref=Cs(M,$,D),ue.return=M,ue)}function U(M,$,D,ue){return $===null||$.tag!==4||$.stateNode.containerInfo!==D.containerInfo||$.stateNode.implementation!==D.implementation?($=yl(D,M.mode,ue),$.return=M,$):($=d($,D.children||[]),$.return=M,$)}function te(M,$,D,ue,Ee){return $===null||$.tag!==7?($=yr(D,M.mode,ue,Ee),$.return=M,$):($=d($,D),$.return=M,$)}function ae(M,$,D){if(typeof $=="string"&&$!==""||typeof $=="number")return $=gl(""+$,M.mode,D),$.return=M,$;if(typeof $=="object"&&$!==null){switch($.$$typeof){case B:return D=ti($.type,$.key,$.props,null,M.mode,D),D.ref=Cs(M,null,$),D.return=M,D;case H:return $=yl($,M.mode,D),$.return=M,$;case ye:var ue=$._init;return ae(M,ue($._payload),D)}if(Re($)||V($))return $=yr($,M.mode,D,null),$.return=M,$;Ia(M,$)}return null}function Z(M,$,D,ue){var Ee=$!==null?$.key:null;if(typeof D=="string"&&D!==""||typeof D=="number")return Ee!==null?null:E(M,$,""+D,ue);if(typeof D=="object"&&D!==null){switch(D.$$typeof){case B:return D.key===Ee?I(M,$,D,ue):null;case H:return D.key===Ee?U(M,$,D,ue):null;case ye:return Ee=D._init,Z(M,$,Ee(D._payload),ue)}if(Re(D)||V(D))return Ee!==null?null:te(M,$,D,ue,null);Ia(M,D)}return null}function xe(M,$,D,ue,Ee){if(typeof ue=="string"&&ue!==""||typeof ue=="number")return M=M.get(D)||null,E($,M,""+ue,Ee);if(typeof ue=="object"&&ue!==null){switch(ue.$$typeof){case B:return M=M.get(ue.key===null?D:ue.key)||null,I($,M,ue,Ee);case H:return M=M.get(ue.key===null?D:ue.key)||null,U($,M,ue,Ee);case ye:var Ae=ue._init;return xe(M,$,D,Ae(ue._payload),Ee)}if(Re(ue)||V(ue))return M=M.get(D)||null,te($,M,ue,Ee,null);Ia($,ue)}return null}function be(M,$,D,ue){for(var Ee=null,Ae=null,Ie=$,_e=$=0,bt=null;Ie!==null&&_e<D.length;_e++){Ie.index>_e?(bt=Ie,Ie=null):bt=Ie.sibling;var Ke=Z(M,Ie,D[_e],ue);if(Ke===null){Ie===null&&(Ie=bt);break}e&&Ie&&Ke.alternate===null&&n(M,Ie),$=m(Ke,$,_e),Ae===null?Ee=Ke:Ae.sibling=Ke,Ae=Ke,Ie=bt}if(_e===D.length)return i(M,Ie),st&&cr(M,_e),Ee;if(Ie===null){for(;_e<D.length;_e++)Ie=ae(M,D[_e],ue),Ie!==null&&($=m(Ie,$,_e),Ae===null?Ee=Ie:Ae.sibling=Ie,Ae=Ie);return st&&cr(M,_e),Ee}for(Ie=l(M,Ie);_e<D.length;_e++)bt=xe(Ie,M,_e,D[_e],ue),bt!==null&&(e&&bt.alternate!==null&&Ie.delete(bt.key===null?_e:bt.key),$=m(bt,$,_e),Ae===null?Ee=bt:Ae.sibling=bt,Ae=bt);return e&&Ie.forEach(function(Zn){return n(M,Zn)}),st&&cr(M,_e),Ee}function Ce(M,$,D,ue){var Ee=V(D);if(typeof Ee!="function")throw Error(a(150));if(D=Ee.call(D),D==null)throw Error(a(151));for(var Ae=Ee=null,Ie=$,_e=$=0,bt=null,Ke=D.next();Ie!==null&&!Ke.done;_e++,Ke=D.next()){Ie.index>_e?(bt=Ie,Ie=null):bt=Ie.sibling;var Zn=Z(M,Ie,Ke.value,ue);if(Zn===null){Ie===null&&(Ie=bt);break}e&&Ie&&Zn.alternate===null&&n(M,Ie),$=m(Zn,$,_e),Ae===null?Ee=Zn:Ae.sibling=Zn,Ae=Zn,Ie=bt}if(Ke.done)return i(M,Ie),st&&cr(M,_e),Ee;if(Ie===null){for(;!Ke.done;_e++,Ke=D.next())Ke=ae(M,Ke.value,ue),Ke!==null&&($=m(Ke,$,_e),Ae===null?Ee=Ke:Ae.sibling=Ke,Ae=Ke);return st&&cr(M,_e),Ee}for(Ie=l(M,Ie);!Ke.done;_e++,Ke=D.next())Ke=xe(Ie,M,_e,Ke.value,ue),Ke!==null&&(e&&Ke.alternate!==null&&Ie.delete(Ke.key===null?_e:Ke.key),$=m(Ke,$,_e),Ae===null?Ee=Ke:Ae.sibling=Ke,Ae=Ke);return e&&Ie.forEach(function(Ag){return n(M,Ag)}),st&&cr(M,_e),Ee}function ft(M,$,D,ue){if(typeof D=="object"&&D!==null&&D.type===G&&D.key===null&&(D=D.props.children),typeof D=="object"&&D!==null){switch(D.$$typeof){case B:e:{for(var Ee=D.key,Ae=$;Ae!==null;){if(Ae.key===Ee){if(Ee=D.type,Ee===G){if(Ae.tag===7){i(M,Ae.sibling),$=d(Ae,D.props.children),$.return=M,M=$;break e}}else if(Ae.elementType===Ee||typeof Ee=="object"&&Ee!==null&&Ee.$$typeof===ye&&Lu(Ee)===Ae.type){i(M,Ae.sibling),$=d(Ae,D.props),$.ref=Cs(M,Ae,D),$.return=M,M=$;break e}i(M,Ae);break}else n(M,Ae);Ae=Ae.sibling}D.type===G?($=yr(D.props.children,M.mode,ue,D.key),$.return=M,M=$):(ue=ti(D.type,D.key,D.props,null,M.mode,ue),ue.ref=Cs(M,$,D),ue.return=M,M=ue)}return x(M);case H:e:{for(Ae=D.key;$!==null;){if($.key===Ae)if($.tag===4&&$.stateNode.containerInfo===D.containerInfo&&$.stateNode.implementation===D.implementation){i(M,$.sibling),$=d($,D.children||[]),$.return=M,M=$;break e}else{i(M,$);break}else n(M,$);$=$.sibling}$=yl(D,M.mode,ue),$.return=M,M=$}return x(M);case ye:return Ae=D._init,ft(M,$,Ae(D._payload),ue)}if(Re(D))return be(M,$,D,ue);if(V(D))return Ce(M,$,D,ue);Ia(M,D)}return typeof D=="string"&&D!==""||typeof D=="number"?(D=""+D,$!==null&&$.tag===6?(i(M,$.sibling),$=d($,D),$.return=M,M=$):(i(M,$),$=gl(D,M.mode,ue),$.return=M,M=$),x(M)):i(M,$)}return ft}var Br=zu(!0),Fu=zu(!1),Pa=Un(null),_a=null,Dr=null,Co=null;function Eo(){Co=Dr=_a=null}function To(e){var n=Pa.current;nt(Pa),e._currentValue=n}function Ro(e,n,i){for(;e!==null;){var l=e.alternate;if((e.childLanes&n)!==n?(e.childLanes|=n,l!==null&&(l.childLanes|=n)):l!==null&&(l.childLanes&n)!==n&&(l.childLanes|=n),e===i)break;e=e.return}}function Ur(e,n){_a=e,Co=Dr=null,e=e.dependencies,e!==null&&e.firstContext!==null&&((e.lanes&n)!==0&&(Ft=!0),e.firstContext=null)}function Xt(e){var n=e._currentValue;if(Co!==e)if(e={context:e,memoizedValue:n,next:null},Dr===null){if(_a===null)throw Error(a(308));Dr=e,_a.dependencies={lanes:0,firstContext:e}}else Dr=Dr.next=e;return n}var ur=null;function Ao(e){ur===null?ur=[e]:ur.push(e)}function Ou(e,n,i,l){var d=n.interleaved;return d===null?(i.next=i,Ao(n)):(i.next=d.next,d.next=i),n.interleaved=i,Tn(e,l)}function Tn(e,n){e.lanes|=n;var i=e.alternate;for(i!==null&&(i.lanes|=n),i=e,e=e.return;e!==null;)e.childLanes|=n,i=e.alternate,i!==null&&(i.childLanes|=n),i=e,e=e.return;return i.tag===3?i.stateNode:null}var Vn=!1;function Io(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function Mu(e,n){e=e.updateQueue,n.updateQueue===e&&(n.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,effects:e.effects})}function Rn(e,n){return{eventTime:e,lane:n,tag:0,payload:null,callback:null,next:null}}function Gn(e,n,i){var l=e.updateQueue;if(l===null)return null;if(l=l.shared,(Ve&2)!==0){var d=l.pending;return d===null?n.next=n:(n.next=d.next,d.next=n),l.pending=n,Tn(e,i)}return d=l.interleaved,d===null?(n.next=n,Ao(l)):(n.next=d.next,d.next=n),l.interleaved=n,Tn(e,i)}function $a(e,n,i){if(n=n.updateQueue,n!==null&&(n=n.shared,(i&4194240)!==0)){var l=n.lanes;l&=e.pendingLanes,i|=l,n.lanes=i,Hi(e,i)}}function Bu(e,n){var i=e.updateQueue,l=e.alternate;if(l!==null&&(l=l.updateQueue,i===l)){var d=null,m=null;if(i=i.firstBaseUpdate,i!==null){do{var x={eventTime:i.eventTime,lane:i.lane,tag:i.tag,payload:i.payload,callback:i.callback,next:null};m===null?d=m=x:m=m.next=x,i=i.next}while(i!==null);m===null?d=m=n:m=m.next=n}else d=m=n;i={baseState:l.baseState,firstBaseUpdate:d,lastBaseUpdate:m,shared:l.shared,effects:l.effects},e.updateQueue=i;return}e=i.lastBaseUpdate,e===null?i.firstBaseUpdate=n:e.next=n,i.lastBaseUpdate=n}function La(e,n,i,l){var d=e.updateQueue;Vn=!1;var m=d.firstBaseUpdate,x=d.lastBaseUpdate,E=d.shared.pending;if(E!==null){d.shared.pending=null;var I=E,U=I.next;I.next=null,x===null?m=U:x.next=U,x=I;var te=e.alternate;te!==null&&(te=te.updateQueue,E=te.lastBaseUpdate,E!==x&&(E===null?te.firstBaseUpdate=U:E.next=U,te.lastBaseUpdate=I))}if(m!==null){var ae=d.baseState;x=0,te=U=I=null,E=m;do{var Z=E.lane,xe=E.eventTime;if((l&Z)===Z){te!==null&&(te=te.next={eventTime:xe,lane:0,tag:E.tag,payload:E.payload,callback:E.callback,next:null});e:{var be=e,Ce=E;switch(Z=n,xe=i,Ce.tag){case 1:if(be=Ce.payload,typeof be=="function"){ae=be.call(xe,ae,Z);break e}ae=be;break e;case 3:be.flags=be.flags&-65537|128;case 0:if(be=Ce.payload,Z=typeof be=="function"?be.call(xe,ae,Z):be,Z==null)break e;ae=W({},ae,Z);break e;case 2:Vn=!0}}E.callback!==null&&E.lane!==0&&(e.flags|=64,Z=d.effects,Z===null?d.effects=[E]:Z.push(E))}else xe={eventTime:xe,lane:Z,tag:E.tag,payload:E.payload,callback:E.callback,next:null},te===null?(U=te=xe,I=ae):te=te.next=xe,x|=Z;if(E=E.next,E===null){if(E=d.shared.pending,E===null)break;Z=E,E=Z.next,Z.next=null,d.lastBaseUpdate=Z,d.shared.pending=null}}while(!0);if(te===null&&(I=ae),d.baseState=I,d.firstBaseUpdate=U,d.lastBaseUpdate=te,n=d.shared.interleaved,n!==null){d=n;do x|=d.lane,d=d.next;while(d!==n)}else m===null&&(d.shared.lanes=0);hr|=x,e.lanes=x,e.memoizedState=ae}}function Du(e,n,i){if(e=n.effects,n.effects=null,e!==null)for(n=0;n<e.length;n++){var l=e[n],d=l.callback;if(d!==null){if(l.callback=null,l=i,typeof d!="function")throw Error(a(191,d));d.call(l)}}}var Es={},vn=Un(Es),Ts=Un(Es),Rs=Un(Es);function dr(e){if(e===Es)throw Error(a(174));return e}function Po(e,n){switch(Ze(Rs,n),Ze(Ts,e),Ze(vn,Es),e=n.nodeType,e){case 9:case 11:n=(n=n.documentElement)?n.namespaceURI:ge(null,"");break;default:e=e===8?n.parentNode:n,n=e.namespaceURI||null,e=e.tagName,n=ge(n,e)}nt(vn),Ze(vn,n)}function Wr(){nt(vn),nt(Ts),nt(Rs)}function Uu(e){dr(Rs.current);var n=dr(vn.current),i=ge(n,e.type);n!==i&&(Ze(Ts,e),Ze(vn,i))}function _o(e){Ts.current===e&&(nt(vn),nt(Ts))}var it=Un(0);function za(e){for(var n=e;n!==null;){if(n.tag===13){var i=n.memoizedState;if(i!==null&&(i=i.dehydrated,i===null||i.data==="$?"||i.data==="$!"))return n}else if(n.tag===19&&n.memoizedProps.revealOrder!==void 0){if((n.flags&128)!==0)return n}else if(n.child!==null){n.child.return=n,n=n.child;continue}if(n===e)break;for(;n.sibling===null;){if(n.return===null||n.return===e)return null;n=n.return}n.sibling.return=n.return,n=n.sibling}return null}var $o=[];function Lo(){for(var e=0;e<$o.length;e++)$o[e]._workInProgressVersionPrimary=null;$o.length=0}var Fa=A.ReactCurrentDispatcher,zo=A.ReactCurrentBatchConfig,fr=0,ot=null,yt=null,jt=null,Oa=!1,As=!1,Is=0,Xp=0;function Rt(){throw Error(a(321))}function Fo(e,n){if(n===null)return!1;for(var i=0;i<n.length&&i<e.length;i++)if(!an(e[i],n[i]))return!1;return!0}function Oo(e,n,i,l,d,m){if(fr=m,ot=n,n.memoizedState=null,n.updateQueue=null,n.lanes=0,Fa.current=e===null||e.memoizedState===null?ng:rg,e=i(l,d),As){m=0;do{if(As=!1,Is=0,25<=m)throw Error(a(301));m+=1,jt=yt=null,n.updateQueue=null,Fa.current=sg,e=i(l,d)}while(As)}if(Fa.current=Da,n=yt!==null&&yt.next!==null,fr=0,jt=yt=ot=null,Oa=!1,n)throw Error(a(300));return e}function Mo(){var e=Is!==0;return Is=0,e}function xn(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return jt===null?ot.memoizedState=jt=e:jt=jt.next=e,jt}function Zt(){if(yt===null){var e=ot.alternate;e=e!==null?e.memoizedState:null}else e=yt.next;var n=jt===null?ot.memoizedState:jt.next;if(n!==null)jt=n,yt=e;else{if(e===null)throw Error(a(310));yt=e,e={memoizedState:yt.memoizedState,baseState:yt.baseState,baseQueue:yt.baseQueue,queue:yt.queue,next:null},jt===null?ot.memoizedState=jt=e:jt=jt.next=e}return jt}function Ps(e,n){return typeof n=="function"?n(e):n}function Bo(e){var n=Zt(),i=n.queue;if(i===null)throw Error(a(311));i.lastRenderedReducer=e;var l=yt,d=l.baseQueue,m=i.pending;if(m!==null){if(d!==null){var x=d.next;d.next=m.next,m.next=x}l.baseQueue=d=m,i.pending=null}if(d!==null){m=d.next,l=l.baseState;var E=x=null,I=null,U=m;do{var te=U.lane;if((fr&te)===te)I!==null&&(I=I.next={lane:0,action:U.action,hasEagerState:U.hasEagerState,eagerState:U.eagerState,next:null}),l=U.hasEagerState?U.eagerState:e(l,U.action);else{var ae={lane:te,action:U.action,hasEagerState:U.hasEagerState,eagerState:U.eagerState,next:null};I===null?(E=I=ae,x=l):I=I.next=ae,ot.lanes|=te,hr|=te}U=U.next}while(U!==null&&U!==m);I===null?x=l:I.next=E,an(l,n.memoizedState)||(Ft=!0),n.memoizedState=l,n.baseState=x,n.baseQueue=I,i.lastRenderedState=l}if(e=i.interleaved,e!==null){d=e;do m=d.lane,ot.lanes|=m,hr|=m,d=d.next;while(d!==e)}else d===null&&(i.lanes=0);return[n.memoizedState,i.dispatch]}function Do(e){var n=Zt(),i=n.queue;if(i===null)throw Error(a(311));i.lastRenderedReducer=e;var l=i.dispatch,d=i.pending,m=n.memoizedState;if(d!==null){i.pending=null;var x=d=d.next;do m=e(m,x.action),x=x.next;while(x!==d);an(m,n.memoizedState)||(Ft=!0),n.memoizedState=m,n.baseQueue===null&&(n.baseState=m),i.lastRenderedState=m}return[m,l]}function Wu(){}function Hu(e,n){var i=ot,l=Zt(),d=n(),m=!an(l.memoizedState,d);if(m&&(l.memoizedState=d,Ft=!0),l=l.queue,Uo(Ku.bind(null,i,l,e),[e]),l.getSnapshot!==n||m||jt!==null&&jt.memoizedState.tag&1){if(i.flags|=2048,_s(9,Gu.bind(null,i,l,d,n),void 0,null),St===null)throw Error(a(349));(fr&30)!==0||Vu(i,n,d)}return d}function Vu(e,n,i){e.flags|=16384,e={getSnapshot:n,value:i},n=ot.updateQueue,n===null?(n={lastEffect:null,stores:null},ot.updateQueue=n,n.stores=[e]):(i=n.stores,i===null?n.stores=[e]:i.push(e))}function Gu(e,n,i,l){n.value=i,n.getSnapshot=l,qu(n)&&Yu(e)}function Ku(e,n,i){return i(function(){qu(n)&&Yu(e)})}function qu(e){var n=e.getSnapshot;e=e.value;try{var i=n();return!an(e,i)}catch{return!0}}function Yu(e){var n=Tn(e,1);n!==null&&dn(n,e,1,-1)}function Ju(e){var n=xn();return typeof e=="function"&&(e=e()),n.memoizedState=n.baseState=e,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:Ps,lastRenderedState:e},n.queue=e,e=e.dispatch=tg.bind(null,ot,e),[n.memoizedState,e]}function _s(e,n,i,l){return e={tag:e,create:n,destroy:i,deps:l,next:null},n=ot.updateQueue,n===null?(n={lastEffect:null,stores:null},ot.updateQueue=n,n.lastEffect=e.next=e):(i=n.lastEffect,i===null?n.lastEffect=e.next=e:(l=i.next,i.next=e,e.next=l,n.lastEffect=e)),e}function Qu(){return Zt().memoizedState}function Ma(e,n,i,l){var d=xn();ot.flags|=e,d.memoizedState=_s(1|n,i,void 0,l===void 0?null:l)}function Ba(e,n,i,l){var d=Zt();l=l===void 0?null:l;var m=void 0;if(yt!==null){var x=yt.memoizedState;if(m=x.destroy,l!==null&&Fo(l,x.deps)){d.memoizedState=_s(n,i,m,l);return}}ot.flags|=e,d.memoizedState=_s(1|n,i,m,l)}function Xu(e,n){return Ma(8390656,8,e,n)}function Uo(e,n){return Ba(2048,8,e,n)}function Zu(e,n){return Ba(4,2,e,n)}function ed(e,n){return Ba(4,4,e,n)}function td(e,n){if(typeof n=="function")return e=e(),n(e),function(){n(null)};if(n!=null)return e=e(),n.current=e,function(){n.current=null}}function nd(e,n,i){return i=i!=null?i.concat([e]):null,Ba(4,4,td.bind(null,n,e),i)}function Wo(){}function rd(e,n){var i=Zt();n=n===void 0?null:n;var l=i.memoizedState;return l!==null&&n!==null&&Fo(n,l[1])?l[0]:(i.memoizedState=[e,n],e)}function sd(e,n){var i=Zt();n=n===void 0?null:n;var l=i.memoizedState;return l!==null&&n!==null&&Fo(n,l[1])?l[0]:(e=e(),i.memoizedState=[e,n],e)}function ad(e,n,i){return(fr&21)===0?(e.baseState&&(e.baseState=!1,Ft=!0),e.memoizedState=i):(an(i,n)||(i=Lc(),ot.lanes|=i,hr|=i,e.baseState=!0),n)}function Zp(e,n){var i=qe;qe=i!==0&&4>i?i:4,e(!0);var l=zo.transition;zo.transition={};try{e(!1),n()}finally{qe=i,zo.transition=l}}function id(){return Zt().memoizedState}function eg(e,n,i){var l=Jn(e);if(i={lane:l,action:i,hasEagerState:!1,eagerState:null,next:null},od(e))ld(n,i);else if(i=Ou(e,n,i,l),i!==null){var d=_t();dn(i,e,l,d),cd(i,n,l)}}function tg(e,n,i){var l=Jn(e),d={lane:l,action:i,hasEagerState:!1,eagerState:null,next:null};if(od(e))ld(n,d);else{var m=e.alternate;if(e.lanes===0&&(m===null||m.lanes===0)&&(m=n.lastRenderedReducer,m!==null))try{var x=n.lastRenderedState,E=m(x,i);if(d.hasEagerState=!0,d.eagerState=E,an(E,x)){var I=n.interleaved;I===null?(d.next=d,Ao(n)):(d.next=I.next,I.next=d),n.interleaved=d;return}}catch{}finally{}i=Ou(e,n,d,l),i!==null&&(d=_t(),dn(i,e,l,d),cd(i,n,l))}}function od(e){var n=e.alternate;return e===ot||n!==null&&n===ot}function ld(e,n){As=Oa=!0;var i=e.pending;i===null?n.next=n:(n.next=i.next,i.next=n),e.pending=n}function cd(e,n,i){if((i&4194240)!==0){var l=n.lanes;l&=e.pendingLanes,i|=l,n.lanes=i,Hi(e,i)}}var Da={readContext:Xt,useCallback:Rt,useContext:Rt,useEffect:Rt,useImperativeHandle:Rt,useInsertionEffect:Rt,useLayoutEffect:Rt,useMemo:Rt,useReducer:Rt,useRef:Rt,useState:Rt,useDebugValue:Rt,useDeferredValue:Rt,useTransition:Rt,useMutableSource:Rt,useSyncExternalStore:Rt,useId:Rt,unstable_isNewReconciler:!1},ng={readContext:Xt,useCallback:function(e,n){return xn().memoizedState=[e,n===void 0?null:n],e},useContext:Xt,useEffect:Xu,useImperativeHandle:function(e,n,i){return i=i!=null?i.concat([e]):null,Ma(4194308,4,td.bind(null,n,e),i)},useLayoutEffect:function(e,n){return Ma(4194308,4,e,n)},useInsertionEffect:function(e,n){return Ma(4,2,e,n)},useMemo:function(e,n){var i=xn();return n=n===void 0?null:n,e=e(),i.memoizedState=[e,n],e},useReducer:function(e,n,i){var l=xn();return n=i!==void 0?i(n):n,l.memoizedState=l.baseState=n,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:n},l.queue=e,e=e.dispatch=eg.bind(null,ot,e),[l.memoizedState,e]},useRef:function(e){var n=xn();return e={current:e},n.memoizedState=e},useState:Ju,useDebugValue:Wo,useDeferredValue:function(e){return xn().memoizedState=e},useTransition:function(){var e=Ju(!1),n=e[0];return e=Zp.bind(null,e[1]),xn().memoizedState=e,[n,e]},useMutableSource:function(){},useSyncExternalStore:function(e,n,i){var l=ot,d=xn();if(st){if(i===void 0)throw Error(a(407));i=i()}else{if(i=n(),St===null)throw Error(a(349));(fr&30)!==0||Vu(l,n,i)}d.memoizedState=i;var m={value:i,getSnapshot:n};return d.queue=m,Xu(Ku.bind(null,l,m,e),[e]),l.flags|=2048,_s(9,Gu.bind(null,l,m,i,n),void 0,null),i},useId:function(){var e=xn(),n=St.identifierPrefix;if(st){var i=En,l=Cn;i=(l&~(1<<32-sn(l)-1)).toString(32)+i,n=":"+n+"R"+i,i=Is++,0<i&&(n+="H"+i.toString(32)),n+=":"}else i=Xp++,n=":"+n+"r"+i.toString(32)+":";return e.memoizedState=n},unstable_isNewReconciler:!1},rg={readContext:Xt,useCallback:rd,useContext:Xt,useEffect:Uo,useImperativeHandle:nd,useInsertionEffect:Zu,useLayoutEffect:ed,useMemo:sd,useReducer:Bo,useRef:Qu,useState:function(){return Bo(Ps)},useDebugValue:Wo,useDeferredValue:function(e){var n=Zt();return ad(n,yt.memoizedState,e)},useTransition:function(){var e=Bo(Ps)[0],n=Zt().memoizedState;return[e,n]},useMutableSource:Wu,useSyncExternalStore:Hu,useId:id,unstable_isNewReconciler:!1},sg={readContext:Xt,useCallback:rd,useContext:Xt,useEffect:Uo,useImperativeHandle:nd,useInsertionEffect:Zu,useLayoutEffect:ed,useMemo:sd,useReducer:Do,useRef:Qu,useState:function(){return Do(Ps)},useDebugValue:Wo,useDeferredValue:function(e){var n=Zt();return yt===null?n.memoizedState=e:ad(n,yt.memoizedState,e)},useTransition:function(){var e=Do(Ps)[0],n=Zt().memoizedState;return[e,n]},useMutableSource:Wu,useSyncExternalStore:Hu,useId:id,unstable_isNewReconciler:!1};function ln(e,n){if(e&&e.defaultProps){n=W({},n),e=e.defaultProps;for(var i in e)n[i]===void 0&&(n[i]=e[i]);return n}return n}function Ho(e,n,i,l){n=e.memoizedState,i=i(l,n),i=i==null?n:W({},n,i),e.memoizedState=i,e.lanes===0&&(e.updateQueue.baseState=i)}var Ua={isMounted:function(e){return(e=e._reactInternals)?ar(e)===e:!1},enqueueSetState:function(e,n,i){e=e._reactInternals;var l=_t(),d=Jn(e),m=Rn(l,d);m.payload=n,i!=null&&(m.callback=i),n=Gn(e,m,d),n!==null&&(dn(n,e,d,l),$a(n,e,d))},enqueueReplaceState:function(e,n,i){e=e._reactInternals;var l=_t(),d=Jn(e),m=Rn(l,d);m.tag=1,m.payload=n,i!=null&&(m.callback=i),n=Gn(e,m,d),n!==null&&(dn(n,e,d,l),$a(n,e,d))},enqueueForceUpdate:function(e,n){e=e._reactInternals;var i=_t(),l=Jn(e),d=Rn(i,l);d.tag=2,n!=null&&(d.callback=n),n=Gn(e,d,l),n!==null&&(dn(n,e,l,i),$a(n,e,l))}};function ud(e,n,i,l,d,m,x){return e=e.stateNode,typeof e.shouldComponentUpdate=="function"?e.shouldComponentUpdate(l,m,x):n.prototype&&n.prototype.isPureReactComponent?!xs(i,l)||!xs(d,m):!0}function dd(e,n,i){var l=!1,d=Wn,m=n.contextType;return typeof m=="object"&&m!==null?m=Xt(m):(d=zt(n)?or:Tt.current,l=n.contextTypes,m=(l=l!=null)?zr(e,d):Wn),n=new n(i,m),e.memoizedState=n.state!==null&&n.state!==void 0?n.state:null,n.updater=Ua,e.stateNode=n,n._reactInternals=e,l&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=d,e.__reactInternalMemoizedMaskedChildContext=m),n}function fd(e,n,i,l){e=n.state,typeof n.componentWillReceiveProps=="function"&&n.componentWillReceiveProps(i,l),typeof n.UNSAFE_componentWillReceiveProps=="function"&&n.UNSAFE_componentWillReceiveProps(i,l),n.state!==e&&Ua.enqueueReplaceState(n,n.state,null)}function Vo(e,n,i,l){var d=e.stateNode;d.props=i,d.state=e.memoizedState,d.refs={},Io(e);var m=n.contextType;typeof m=="object"&&m!==null?d.context=Xt(m):(m=zt(n)?or:Tt.current,d.context=zr(e,m)),d.state=e.memoizedState,m=n.getDerivedStateFromProps,typeof m=="function"&&(Ho(e,n,m,i),d.state=e.memoizedState),typeof n.getDerivedStateFromProps=="function"||typeof d.getSnapshotBeforeUpdate=="function"||typeof d.UNSAFE_componentWillMount!="function"&&typeof d.componentWillMount!="function"||(n=d.state,typeof d.componentWillMount=="function"&&d.componentWillMount(),typeof d.UNSAFE_componentWillMount=="function"&&d.UNSAFE_componentWillMount(),n!==d.state&&Ua.enqueueReplaceState(d,d.state,null),La(e,i,d,l),d.state=e.memoizedState),typeof d.componentDidMount=="function"&&(e.flags|=4194308)}function Hr(e,n){try{var i="",l=n;do i+=z(l),l=l.return;while(l);var d=i}catch(m){d=`
39
+ Error generating stack: `+m.message+`
40
+ `+m.stack}return{value:e,source:n,stack:d,digest:null}}function Go(e,n,i){return{value:e,source:null,stack:i??null,digest:n??null}}function Ko(e,n){try{console.error(n.value)}catch(i){setTimeout(function(){throw i})}}var ag=typeof WeakMap=="function"?WeakMap:Map;function hd(e,n,i){i=Rn(-1,i),i.tag=3,i.payload={element:null};var l=n.value;return i.callback=function(){Ya||(Ya=!0,ll=l),Ko(e,n)},i}function md(e,n,i){i=Rn(-1,i),i.tag=3;var l=e.type.getDerivedStateFromError;if(typeof l=="function"){var d=n.value;i.payload=function(){return l(d)},i.callback=function(){Ko(e,n)}}var m=e.stateNode;return m!==null&&typeof m.componentDidCatch=="function"&&(i.callback=function(){Ko(e,n),typeof l!="function"&&(qn===null?qn=new Set([this]):qn.add(this));var x=n.stack;this.componentDidCatch(n.value,{componentStack:x!==null?x:""})}),i}function pd(e,n,i){var l=e.pingCache;if(l===null){l=e.pingCache=new ag;var d=new Set;l.set(n,d)}else d=l.get(n),d===void 0&&(d=new Set,l.set(n,d));d.has(i)||(d.add(i),e=xg.bind(null,e,n,i),n.then(e,e))}function gd(e){do{var n;if((n=e.tag===13)&&(n=e.memoizedState,n=n!==null?n.dehydrated!==null:!0),n)return e;e=e.return}while(e!==null);return null}function yd(e,n,i,l,d){return(e.mode&1)===0?(e===n?e.flags|=65536:(e.flags|=128,i.flags|=131072,i.flags&=-52805,i.tag===1&&(i.alternate===null?i.tag=17:(n=Rn(-1,1),n.tag=2,Gn(i,n,1))),i.lanes|=1),e):(e.flags|=65536,e.lanes=d,e)}var ig=A.ReactCurrentOwner,Ft=!1;function Pt(e,n,i,l){n.child=e===null?Fu(n,null,i,l):Br(n,e.child,i,l)}function vd(e,n,i,l,d){i=i.render;var m=n.ref;return Ur(n,d),l=Oo(e,n,i,l,m,d),i=Mo(),e!==null&&!Ft?(n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~d,An(e,n,d)):(st&&i&&jo(n),n.flags|=1,Pt(e,n,l,d),n.child)}function xd(e,n,i,l,d){if(e===null){var m=i.type;return typeof m=="function"&&!pl(m)&&m.defaultProps===void 0&&i.compare===null&&i.defaultProps===void 0?(n.tag=15,n.type=m,wd(e,n,m,l,d)):(e=ti(i.type,null,l,n,n.mode,d),e.ref=n.ref,e.return=n,n.child=e)}if(m=e.child,(e.lanes&d)===0){var x=m.memoizedProps;if(i=i.compare,i=i!==null?i:xs,i(x,l)&&e.ref===n.ref)return An(e,n,d)}return n.flags|=1,e=Xn(m,l),e.ref=n.ref,e.return=n,n.child=e}function wd(e,n,i,l,d){if(e!==null){var m=e.memoizedProps;if(xs(m,l)&&e.ref===n.ref)if(Ft=!1,n.pendingProps=l=m,(e.lanes&d)!==0)(e.flags&131072)!==0&&(Ft=!0);else return n.lanes=e.lanes,An(e,n,d)}return qo(e,n,i,l,d)}function jd(e,n,i){var l=n.pendingProps,d=l.children,m=e!==null?e.memoizedState:null;if(l.mode==="hidden")if((n.mode&1)===0)n.memoizedState={baseLanes:0,cachePool:null,transitions:null},Ze(Gr,Kt),Kt|=i;else{if((i&1073741824)===0)return e=m!==null?m.baseLanes|i:i,n.lanes=n.childLanes=1073741824,n.memoizedState={baseLanes:e,cachePool:null,transitions:null},n.updateQueue=null,Ze(Gr,Kt),Kt|=e,null;n.memoizedState={baseLanes:0,cachePool:null,transitions:null},l=m!==null?m.baseLanes:i,Ze(Gr,Kt),Kt|=l}else m!==null?(l=m.baseLanes|i,n.memoizedState=null):l=i,Ze(Gr,Kt),Kt|=l;return Pt(e,n,d,i),n.child}function Sd(e,n){var i=n.ref;(e===null&&i!==null||e!==null&&e.ref!==i)&&(n.flags|=512,n.flags|=2097152)}function qo(e,n,i,l,d){var m=zt(i)?or:Tt.current;return m=zr(n,m),Ur(n,d),i=Oo(e,n,i,l,m,d),l=Mo(),e!==null&&!Ft?(n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~d,An(e,n,d)):(st&&l&&jo(n),n.flags|=1,Pt(e,n,i,d),n.child)}function bd(e,n,i,l,d){if(zt(i)){var m=!0;Ca(n)}else m=!1;if(Ur(n,d),n.stateNode===null)Ha(e,n),dd(n,i,l),Vo(n,i,l,d),l=!0;else if(e===null){var x=n.stateNode,E=n.memoizedProps;x.props=E;var I=x.context,U=i.contextType;typeof U=="object"&&U!==null?U=Xt(U):(U=zt(i)?or:Tt.current,U=zr(n,U));var te=i.getDerivedStateFromProps,ae=typeof te=="function"||typeof x.getSnapshotBeforeUpdate=="function";ae||typeof x.UNSAFE_componentWillReceiveProps!="function"&&typeof x.componentWillReceiveProps!="function"||(E!==l||I!==U)&&fd(n,x,l,U),Vn=!1;var Z=n.memoizedState;x.state=Z,La(n,l,x,d),I=n.memoizedState,E!==l||Z!==I||Lt.current||Vn?(typeof te=="function"&&(Ho(n,i,te,l),I=n.memoizedState),(E=Vn||ud(n,i,E,l,Z,I,U))?(ae||typeof x.UNSAFE_componentWillMount!="function"&&typeof x.componentWillMount!="function"||(typeof x.componentWillMount=="function"&&x.componentWillMount(),typeof x.UNSAFE_componentWillMount=="function"&&x.UNSAFE_componentWillMount()),typeof x.componentDidMount=="function"&&(n.flags|=4194308)):(typeof x.componentDidMount=="function"&&(n.flags|=4194308),n.memoizedProps=l,n.memoizedState=I),x.props=l,x.state=I,x.context=U,l=E):(typeof x.componentDidMount=="function"&&(n.flags|=4194308),l=!1)}else{x=n.stateNode,Mu(e,n),E=n.memoizedProps,U=n.type===n.elementType?E:ln(n.type,E),x.props=U,ae=n.pendingProps,Z=x.context,I=i.contextType,typeof I=="object"&&I!==null?I=Xt(I):(I=zt(i)?or:Tt.current,I=zr(n,I));var xe=i.getDerivedStateFromProps;(te=typeof xe=="function"||typeof x.getSnapshotBeforeUpdate=="function")||typeof x.UNSAFE_componentWillReceiveProps!="function"&&typeof x.componentWillReceiveProps!="function"||(E!==ae||Z!==I)&&fd(n,x,l,I),Vn=!1,Z=n.memoizedState,x.state=Z,La(n,l,x,d);var be=n.memoizedState;E!==ae||Z!==be||Lt.current||Vn?(typeof xe=="function"&&(Ho(n,i,xe,l),be=n.memoizedState),(U=Vn||ud(n,i,U,l,Z,be,I)||!1)?(te||typeof x.UNSAFE_componentWillUpdate!="function"&&typeof x.componentWillUpdate!="function"||(typeof x.componentWillUpdate=="function"&&x.componentWillUpdate(l,be,I),typeof x.UNSAFE_componentWillUpdate=="function"&&x.UNSAFE_componentWillUpdate(l,be,I)),typeof x.componentDidUpdate=="function"&&(n.flags|=4),typeof x.getSnapshotBeforeUpdate=="function"&&(n.flags|=1024)):(typeof x.componentDidUpdate!="function"||E===e.memoizedProps&&Z===e.memoizedState||(n.flags|=4),typeof x.getSnapshotBeforeUpdate!="function"||E===e.memoizedProps&&Z===e.memoizedState||(n.flags|=1024),n.memoizedProps=l,n.memoizedState=be),x.props=l,x.state=be,x.context=I,l=U):(typeof x.componentDidUpdate!="function"||E===e.memoizedProps&&Z===e.memoizedState||(n.flags|=4),typeof x.getSnapshotBeforeUpdate!="function"||E===e.memoizedProps&&Z===e.memoizedState||(n.flags|=1024),l=!1)}return Yo(e,n,i,l,m,d)}function Yo(e,n,i,l,d,m){Sd(e,n);var x=(n.flags&128)!==0;if(!l&&!x)return d&&Tu(n,i,!1),An(e,n,m);l=n.stateNode,ig.current=n;var E=x&&typeof i.getDerivedStateFromError!="function"?null:l.render();return n.flags|=1,e!==null&&x?(n.child=Br(n,e.child,null,m),n.child=Br(n,null,E,m)):Pt(e,n,E,m),n.memoizedState=l.state,d&&Tu(n,i,!0),n.child}function kd(e){var n=e.stateNode;n.pendingContext?Cu(e,n.pendingContext,n.pendingContext!==n.context):n.context&&Cu(e,n.context,!1),Po(e,n.containerInfo)}function Nd(e,n,i,l,d){return Mr(),No(d),n.flags|=256,Pt(e,n,i,l),n.child}var Jo={dehydrated:null,treeContext:null,retryLane:0};function Qo(e){return{baseLanes:e,cachePool:null,transitions:null}}function Cd(e,n,i){var l=n.pendingProps,d=it.current,m=!1,x=(n.flags&128)!==0,E;if((E=x)||(E=e!==null&&e.memoizedState===null?!1:(d&2)!==0),E?(m=!0,n.flags&=-129):(e===null||e.memoizedState!==null)&&(d|=1),Ze(it,d&1),e===null)return ko(n),e=n.memoizedState,e!==null&&(e=e.dehydrated,e!==null)?((n.mode&1)===0?n.lanes=1:e.data==="$!"?n.lanes=8:n.lanes=1073741824,null):(x=l.children,e=l.fallback,m?(l=n.mode,m=n.child,x={mode:"hidden",children:x},(l&1)===0&&m!==null?(m.childLanes=0,m.pendingProps=x):m=ni(x,l,0,null),e=yr(e,l,i,null),m.return=n,e.return=n,m.sibling=e,n.child=m,n.child.memoizedState=Qo(i),n.memoizedState=Jo,e):Xo(n,x));if(d=e.memoizedState,d!==null&&(E=d.dehydrated,E!==null))return og(e,n,x,l,E,d,i);if(m){m=l.fallback,x=n.mode,d=e.child,E=d.sibling;var I={mode:"hidden",children:l.children};return(x&1)===0&&n.child!==d?(l=n.child,l.childLanes=0,l.pendingProps=I,n.deletions=null):(l=Xn(d,I),l.subtreeFlags=d.subtreeFlags&14680064),E!==null?m=Xn(E,m):(m=yr(m,x,i,null),m.flags|=2),m.return=n,l.return=n,l.sibling=m,n.child=l,l=m,m=n.child,x=e.child.memoizedState,x=x===null?Qo(i):{baseLanes:x.baseLanes|i,cachePool:null,transitions:x.transitions},m.memoizedState=x,m.childLanes=e.childLanes&~i,n.memoizedState=Jo,l}return m=e.child,e=m.sibling,l=Xn(m,{mode:"visible",children:l.children}),(n.mode&1)===0&&(l.lanes=i),l.return=n,l.sibling=null,e!==null&&(i=n.deletions,i===null?(n.deletions=[e],n.flags|=16):i.push(e)),n.child=l,n.memoizedState=null,l}function Xo(e,n){return n=ni({mode:"visible",children:n},e.mode,0,null),n.return=e,e.child=n}function Wa(e,n,i,l){return l!==null&&No(l),Br(n,e.child,null,i),e=Xo(n,n.pendingProps.children),e.flags|=2,n.memoizedState=null,e}function og(e,n,i,l,d,m,x){if(i)return n.flags&256?(n.flags&=-257,l=Go(Error(a(422))),Wa(e,n,x,l)):n.memoizedState!==null?(n.child=e.child,n.flags|=128,null):(m=l.fallback,d=n.mode,l=ni({mode:"visible",children:l.children},d,0,null),m=yr(m,d,x,null),m.flags|=2,l.return=n,m.return=n,l.sibling=m,n.child=l,(n.mode&1)!==0&&Br(n,e.child,null,x),n.child.memoizedState=Qo(x),n.memoizedState=Jo,m);if((n.mode&1)===0)return Wa(e,n,x,null);if(d.data==="$!"){if(l=d.nextSibling&&d.nextSibling.dataset,l)var E=l.dgst;return l=E,m=Error(a(419)),l=Go(m,l,void 0),Wa(e,n,x,l)}if(E=(x&e.childLanes)!==0,Ft||E){if(l=St,l!==null){switch(x&-x){case 4:d=2;break;case 16:d=8;break;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:d=32;break;case 536870912:d=268435456;break;default:d=0}d=(d&(l.suspendedLanes|x))!==0?0:d,d!==0&&d!==m.retryLane&&(m.retryLane=d,Tn(e,d),dn(l,e,d,-1))}return ml(),l=Go(Error(a(421))),Wa(e,n,x,l)}return d.data==="$?"?(n.flags|=128,n.child=e.child,n=wg.bind(null,e),d._reactRetry=n,null):(e=m.treeContext,Gt=Dn(d.nextSibling),Vt=n,st=!0,on=null,e!==null&&(Jt[Qt++]=Cn,Jt[Qt++]=En,Jt[Qt++]=lr,Cn=e.id,En=e.overflow,lr=n),n=Xo(n,l.children),n.flags|=4096,n)}function Ed(e,n,i){e.lanes|=n;var l=e.alternate;l!==null&&(l.lanes|=n),Ro(e.return,n,i)}function Zo(e,n,i,l,d){var m=e.memoizedState;m===null?e.memoizedState={isBackwards:n,rendering:null,renderingStartTime:0,last:l,tail:i,tailMode:d}:(m.isBackwards=n,m.rendering=null,m.renderingStartTime=0,m.last=l,m.tail=i,m.tailMode=d)}function Td(e,n,i){var l=n.pendingProps,d=l.revealOrder,m=l.tail;if(Pt(e,n,l.children,i),l=it.current,(l&2)!==0)l=l&1|2,n.flags|=128;else{if(e!==null&&(e.flags&128)!==0)e:for(e=n.child;e!==null;){if(e.tag===13)e.memoizedState!==null&&Ed(e,i,n);else if(e.tag===19)Ed(e,i,n);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===n)break e;for(;e.sibling===null;){if(e.return===null||e.return===n)break e;e=e.return}e.sibling.return=e.return,e=e.sibling}l&=1}if(Ze(it,l),(n.mode&1)===0)n.memoizedState=null;else switch(d){case"forwards":for(i=n.child,d=null;i!==null;)e=i.alternate,e!==null&&za(e)===null&&(d=i),i=i.sibling;i=d,i===null?(d=n.child,n.child=null):(d=i.sibling,i.sibling=null),Zo(n,!1,d,i,m);break;case"backwards":for(i=null,d=n.child,n.child=null;d!==null;){if(e=d.alternate,e!==null&&za(e)===null){n.child=d;break}e=d.sibling,d.sibling=i,i=d,d=e}Zo(n,!0,i,null,m);break;case"together":Zo(n,!1,null,null,void 0);break;default:n.memoizedState=null}return n.child}function Ha(e,n){(n.mode&1)===0&&e!==null&&(e.alternate=null,n.alternate=null,n.flags|=2)}function An(e,n,i){if(e!==null&&(n.dependencies=e.dependencies),hr|=n.lanes,(i&n.childLanes)===0)return null;if(e!==null&&n.child!==e.child)throw Error(a(153));if(n.child!==null){for(e=n.child,i=Xn(e,e.pendingProps),n.child=i,i.return=n;e.sibling!==null;)e=e.sibling,i=i.sibling=Xn(e,e.pendingProps),i.return=n;i.sibling=null}return n.child}function lg(e,n,i){switch(n.tag){case 3:kd(n),Mr();break;case 5:Uu(n);break;case 1:zt(n.type)&&Ca(n);break;case 4:Po(n,n.stateNode.containerInfo);break;case 10:var l=n.type._context,d=n.memoizedProps.value;Ze(Pa,l._currentValue),l._currentValue=d;break;case 13:if(l=n.memoizedState,l!==null)return l.dehydrated!==null?(Ze(it,it.current&1),n.flags|=128,null):(i&n.child.childLanes)!==0?Cd(e,n,i):(Ze(it,it.current&1),e=An(e,n,i),e!==null?e.sibling:null);Ze(it,it.current&1);break;case 19:if(l=(i&n.childLanes)!==0,(e.flags&128)!==0){if(l)return Td(e,n,i);n.flags|=128}if(d=n.memoizedState,d!==null&&(d.rendering=null,d.tail=null,d.lastEffect=null),Ze(it,it.current),l)break;return null;case 22:case 23:return n.lanes=0,jd(e,n,i)}return An(e,n,i)}var Rd,el,Ad,Id;Rd=function(e,n){for(var i=n.child;i!==null;){if(i.tag===5||i.tag===6)e.appendChild(i.stateNode);else if(i.tag!==4&&i.child!==null){i.child.return=i,i=i.child;continue}if(i===n)break;for(;i.sibling===null;){if(i.return===null||i.return===n)return;i=i.return}i.sibling.return=i.return,i=i.sibling}},el=function(){},Ad=function(e,n,i,l){var d=e.memoizedProps;if(d!==l){e=n.stateNode,dr(vn.current);var m=null;switch(i){case"input":d=Le(e,d),l=Le(e,l),m=[];break;case"select":d=W({},d,{value:void 0}),l=W({},l,{value:void 0}),m=[];break;case"textarea":d=ut(e,d),l=ut(e,l),m=[];break;default:typeof d.onClick!="function"&&typeof l.onClick=="function"&&(e.onclick=ba)}rt(i,l);var x;i=null;for(U in d)if(!l.hasOwnProperty(U)&&d.hasOwnProperty(U)&&d[U]!=null)if(U==="style"){var E=d[U];for(x in E)E.hasOwnProperty(x)&&(i||(i={}),i[x]="")}else U!=="dangerouslySetInnerHTML"&&U!=="children"&&U!=="suppressContentEditableWarning"&&U!=="suppressHydrationWarning"&&U!=="autoFocus"&&(c.hasOwnProperty(U)?m||(m=[]):(m=m||[]).push(U,null));for(U in l){var I=l[U];if(E=d!=null?d[U]:void 0,l.hasOwnProperty(U)&&I!==E&&(I!=null||E!=null))if(U==="style")if(E){for(x in E)!E.hasOwnProperty(x)||I&&I.hasOwnProperty(x)||(i||(i={}),i[x]="");for(x in I)I.hasOwnProperty(x)&&E[x]!==I[x]&&(i||(i={}),i[x]=I[x])}else i||(m||(m=[]),m.push(U,i)),i=I;else U==="dangerouslySetInnerHTML"?(I=I?I.__html:void 0,E=E?E.__html:void 0,I!=null&&E!==I&&(m=m||[]).push(U,I)):U==="children"?typeof I!="string"&&typeof I!="number"||(m=m||[]).push(U,""+I):U!=="suppressContentEditableWarning"&&U!=="suppressHydrationWarning"&&(c.hasOwnProperty(U)?(I!=null&&U==="onScroll"&&tt("scroll",e),m||E===I||(m=[])):(m=m||[]).push(U,I))}i&&(m=m||[]).push("style",i);var U=m;(n.updateQueue=U)&&(n.flags|=4)}},Id=function(e,n,i,l){i!==l&&(n.flags|=4)};function $s(e,n){if(!st)switch(e.tailMode){case"hidden":n=e.tail;for(var i=null;n!==null;)n.alternate!==null&&(i=n),n=n.sibling;i===null?e.tail=null:i.sibling=null;break;case"collapsed":i=e.tail;for(var l=null;i!==null;)i.alternate!==null&&(l=i),i=i.sibling;l===null?n||e.tail===null?e.tail=null:e.tail.sibling=null:l.sibling=null}}function At(e){var n=e.alternate!==null&&e.alternate.child===e.child,i=0,l=0;if(n)for(var d=e.child;d!==null;)i|=d.lanes|d.childLanes,l|=d.subtreeFlags&14680064,l|=d.flags&14680064,d.return=e,d=d.sibling;else for(d=e.child;d!==null;)i|=d.lanes|d.childLanes,l|=d.subtreeFlags,l|=d.flags,d.return=e,d=d.sibling;return e.subtreeFlags|=l,e.childLanes=i,n}function cg(e,n,i){var l=n.pendingProps;switch(So(n),n.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return At(n),null;case 1:return zt(n.type)&&Na(),At(n),null;case 3:return l=n.stateNode,Wr(),nt(Lt),nt(Tt),Lo(),l.pendingContext&&(l.context=l.pendingContext,l.pendingContext=null),(e===null||e.child===null)&&(Aa(n)?n.flags|=4:e===null||e.memoizedState.isDehydrated&&(n.flags&256)===0||(n.flags|=1024,on!==null&&(dl(on),on=null))),el(e,n),At(n),null;case 5:_o(n);var d=dr(Rs.current);if(i=n.type,e!==null&&n.stateNode!=null)Ad(e,n,i,l,d),e.ref!==n.ref&&(n.flags|=512,n.flags|=2097152);else{if(!l){if(n.stateNode===null)throw Error(a(166));return At(n),null}if(e=dr(vn.current),Aa(n)){l=n.stateNode,i=n.type;var m=n.memoizedProps;switch(l[yn]=n,l[ks]=m,e=(n.mode&1)!==0,i){case"dialog":tt("cancel",l),tt("close",l);break;case"iframe":case"object":case"embed":tt("load",l);break;case"video":case"audio":for(d=0;d<js.length;d++)tt(js[d],l);break;case"source":tt("error",l);break;case"img":case"image":case"link":tt("error",l),tt("load",l);break;case"details":tt("toggle",l);break;case"input":Ge(l,m),tt("invalid",l);break;case"select":l._wrapperState={wasMultiple:!!m.multiple},tt("invalid",l);break;case"textarea":Je(l,m),tt("invalid",l)}rt(i,m),d=null;for(var x in m)if(m.hasOwnProperty(x)){var E=m[x];x==="children"?typeof E=="string"?l.textContent!==E&&(m.suppressHydrationWarning!==!0&&Sa(l.textContent,E,e),d=["children",E]):typeof E=="number"&&l.textContent!==""+E&&(m.suppressHydrationWarning!==!0&&Sa(l.textContent,E,e),d=["children",""+E]):c.hasOwnProperty(x)&&E!=null&&x==="onScroll"&&tt("scroll",l)}switch(i){case"input":Ne(l),lt(l,m,!0);break;case"textarea":Ne(l),_(l);break;case"select":case"option":break;default:typeof m.onClick=="function"&&(l.onclick=ba)}l=d,n.updateQueue=l,l!==null&&(n.flags|=4)}else{x=d.nodeType===9?d:d.ownerDocument,e==="http://www.w3.org/1999/xhtml"&&(e=oe(i)),e==="http://www.w3.org/1999/xhtml"?i==="script"?(e=x.createElement("div"),e.innerHTML="<script><\/script>",e=e.removeChild(e.firstChild)):typeof l.is=="string"?e=x.createElement(i,{is:l.is}):(e=x.createElement(i),i==="select"&&(x=e,l.multiple?x.multiple=!0:l.size&&(x.size=l.size))):e=x.createElementNS(e,i),e[yn]=n,e[ks]=l,Rd(e,n,!1,!1),n.stateNode=e;e:{switch(x=kt(i,l),i){case"dialog":tt("cancel",e),tt("close",e),d=l;break;case"iframe":case"object":case"embed":tt("load",e),d=l;break;case"video":case"audio":for(d=0;d<js.length;d++)tt(js[d],e);d=l;break;case"source":tt("error",e),d=l;break;case"img":case"image":case"link":tt("error",e),tt("load",e),d=l;break;case"details":tt("toggle",e),d=l;break;case"input":Ge(e,l),d=Le(e,l),tt("invalid",e);break;case"option":d=l;break;case"select":e._wrapperState={wasMultiple:!!l.multiple},d=W({},l,{value:void 0}),tt("invalid",e);break;case"textarea":Je(e,l),d=ut(e,l),tt("invalid",e);break;default:d=l}rt(i,d),E=d;for(m in E)if(E.hasOwnProperty(m)){var I=E[m];m==="style"?pn(e,I):m==="dangerouslySetInnerHTML"?(I=I?I.__html:void 0,I!=null&&de(e,I)):m==="children"?typeof I=="string"?(i!=="textarea"||I!=="")&&Me(e,I):typeof I=="number"&&Me(e,""+I):m!=="suppressContentEditableWarning"&&m!=="suppressHydrationWarning"&&m!=="autoFocus"&&(c.hasOwnProperty(m)?I!=null&&m==="onScroll"&&tt("scroll",e):I!=null&&P(e,m,I,x))}switch(i){case"input":Ne(e),lt(e,l,!1);break;case"textarea":Ne(e),_(e);break;case"option":l.value!=null&&e.setAttribute("value",""+ie(l.value));break;case"select":e.multiple=!!l.multiple,m=l.value,m!=null?Pe(e,!!l.multiple,m,!1):l.defaultValue!=null&&Pe(e,!!l.multiple,l.defaultValue,!0);break;default:typeof d.onClick=="function"&&(e.onclick=ba)}switch(i){case"button":case"input":case"select":case"textarea":l=!!l.autoFocus;break e;case"img":l=!0;break e;default:l=!1}}l&&(n.flags|=4)}n.ref!==null&&(n.flags|=512,n.flags|=2097152)}return At(n),null;case 6:if(e&&n.stateNode!=null)Id(e,n,e.memoizedProps,l);else{if(typeof l!="string"&&n.stateNode===null)throw Error(a(166));if(i=dr(Rs.current),dr(vn.current),Aa(n)){if(l=n.stateNode,i=n.memoizedProps,l[yn]=n,(m=l.nodeValue!==i)&&(e=Vt,e!==null))switch(e.tag){case 3:Sa(l.nodeValue,i,(e.mode&1)!==0);break;case 5:e.memoizedProps.suppressHydrationWarning!==!0&&Sa(l.nodeValue,i,(e.mode&1)!==0)}m&&(n.flags|=4)}else l=(i.nodeType===9?i:i.ownerDocument).createTextNode(l),l[yn]=n,n.stateNode=l}return At(n),null;case 13:if(nt(it),l=n.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(st&&Gt!==null&&(n.mode&1)!==0&&(n.flags&128)===0)$u(),Mr(),n.flags|=98560,m=!1;else if(m=Aa(n),l!==null&&l.dehydrated!==null){if(e===null){if(!m)throw Error(a(318));if(m=n.memoizedState,m=m!==null?m.dehydrated:null,!m)throw Error(a(317));m[yn]=n}else Mr(),(n.flags&128)===0&&(n.memoizedState=null),n.flags|=4;At(n),m=!1}else on!==null&&(dl(on),on=null),m=!0;if(!m)return n.flags&65536?n:null}return(n.flags&128)!==0?(n.lanes=i,n):(l=l!==null,l!==(e!==null&&e.memoizedState!==null)&&l&&(n.child.flags|=8192,(n.mode&1)!==0&&(e===null||(it.current&1)!==0?vt===0&&(vt=3):ml())),n.updateQueue!==null&&(n.flags|=4),At(n),null);case 4:return Wr(),el(e,n),e===null&&Ss(n.stateNode.containerInfo),At(n),null;case 10:return To(n.type._context),At(n),null;case 17:return zt(n.type)&&Na(),At(n),null;case 19:if(nt(it),m=n.memoizedState,m===null)return At(n),null;if(l=(n.flags&128)!==0,x=m.rendering,x===null)if(l)$s(m,!1);else{if(vt!==0||e!==null&&(e.flags&128)!==0)for(e=n.child;e!==null;){if(x=za(e),x!==null){for(n.flags|=128,$s(m,!1),l=x.updateQueue,l!==null&&(n.updateQueue=l,n.flags|=4),n.subtreeFlags=0,l=i,i=n.child;i!==null;)m=i,e=l,m.flags&=14680066,x=m.alternate,x===null?(m.childLanes=0,m.lanes=e,m.child=null,m.subtreeFlags=0,m.memoizedProps=null,m.memoizedState=null,m.updateQueue=null,m.dependencies=null,m.stateNode=null):(m.childLanes=x.childLanes,m.lanes=x.lanes,m.child=x.child,m.subtreeFlags=0,m.deletions=null,m.memoizedProps=x.memoizedProps,m.memoizedState=x.memoizedState,m.updateQueue=x.updateQueue,m.type=x.type,e=x.dependencies,m.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext}),i=i.sibling;return Ze(it,it.current&1|2),n.child}e=e.sibling}m.tail!==null&&dt()>Kr&&(n.flags|=128,l=!0,$s(m,!1),n.lanes=4194304)}else{if(!l)if(e=za(x),e!==null){if(n.flags|=128,l=!0,i=e.updateQueue,i!==null&&(n.updateQueue=i,n.flags|=4),$s(m,!0),m.tail===null&&m.tailMode==="hidden"&&!x.alternate&&!st)return At(n),null}else 2*dt()-m.renderingStartTime>Kr&&i!==1073741824&&(n.flags|=128,l=!0,$s(m,!1),n.lanes=4194304);m.isBackwards?(x.sibling=n.child,n.child=x):(i=m.last,i!==null?i.sibling=x:n.child=x,m.last=x)}return m.tail!==null?(n=m.tail,m.rendering=n,m.tail=n.sibling,m.renderingStartTime=dt(),n.sibling=null,i=it.current,Ze(it,l?i&1|2:i&1),n):(At(n),null);case 22:case 23:return hl(),l=n.memoizedState!==null,e!==null&&e.memoizedState!==null!==l&&(n.flags|=8192),l&&(n.mode&1)!==0?(Kt&1073741824)!==0&&(At(n),n.subtreeFlags&6&&(n.flags|=8192)):At(n),null;case 24:return null;case 25:return null}throw Error(a(156,n.tag))}function ug(e,n){switch(So(n),n.tag){case 1:return zt(n.type)&&Na(),e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 3:return Wr(),nt(Lt),nt(Tt),Lo(),e=n.flags,(e&65536)!==0&&(e&128)===0?(n.flags=e&-65537|128,n):null;case 5:return _o(n),null;case 13:if(nt(it),e=n.memoizedState,e!==null&&e.dehydrated!==null){if(n.alternate===null)throw Error(a(340));Mr()}return e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 19:return nt(it),null;case 4:return Wr(),null;case 10:return To(n.type._context),null;case 22:case 23:return hl(),null;case 24:return null;default:return null}}var Va=!1,It=!1,dg=typeof WeakSet=="function"?WeakSet:Set,je=null;function Vr(e,n){var i=e.ref;if(i!==null)if(typeof i=="function")try{i(null)}catch(l){ct(e,n,l)}else i.current=null}function tl(e,n,i){try{i()}catch(l){ct(e,n,l)}}var Pd=!1;function fg(e,n){if(ho=da,e=uu(),so(e)){if("selectionStart"in e)var i={start:e.selectionStart,end:e.selectionEnd};else e:{i=(i=e.ownerDocument)&&i.defaultView||window;var l=i.getSelection&&i.getSelection();if(l&&l.rangeCount!==0){i=l.anchorNode;var d=l.anchorOffset,m=l.focusNode;l=l.focusOffset;try{i.nodeType,m.nodeType}catch{i=null;break e}var x=0,E=-1,I=-1,U=0,te=0,ae=e,Z=null;t:for(;;){for(var xe;ae!==i||d!==0&&ae.nodeType!==3||(E=x+d),ae!==m||l!==0&&ae.nodeType!==3||(I=x+l),ae.nodeType===3&&(x+=ae.nodeValue.length),(xe=ae.firstChild)!==null;)Z=ae,ae=xe;for(;;){if(ae===e)break t;if(Z===i&&++U===d&&(E=x),Z===m&&++te===l&&(I=x),(xe=ae.nextSibling)!==null)break;ae=Z,Z=ae.parentNode}ae=xe}i=E===-1||I===-1?null:{start:E,end:I}}else i=null}i=i||{start:0,end:0}}else i=null;for(mo={focusedElem:e,selectionRange:i},da=!1,je=n;je!==null;)if(n=je,e=n.child,(n.subtreeFlags&1028)!==0&&e!==null)e.return=n,je=e;else for(;je!==null;){n=je;try{var be=n.alternate;if((n.flags&1024)!==0)switch(n.tag){case 0:case 11:case 15:break;case 1:if(be!==null){var Ce=be.memoizedProps,ft=be.memoizedState,M=n.stateNode,$=M.getSnapshotBeforeUpdate(n.elementType===n.type?Ce:ln(n.type,Ce),ft);M.__reactInternalSnapshotBeforeUpdate=$}break;case 3:var D=n.stateNode.containerInfo;D.nodeType===1?D.textContent="":D.nodeType===9&&D.documentElement&&D.removeChild(D.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(a(163))}}catch(ue){ct(n,n.return,ue)}if(e=n.sibling,e!==null){e.return=n.return,je=e;break}je=n.return}return be=Pd,Pd=!1,be}function Ls(e,n,i){var l=n.updateQueue;if(l=l!==null?l.lastEffect:null,l!==null){var d=l=l.next;do{if((d.tag&e)===e){var m=d.destroy;d.destroy=void 0,m!==void 0&&tl(n,i,m)}d=d.next}while(d!==l)}}function Ga(e,n){if(n=n.updateQueue,n=n!==null?n.lastEffect:null,n!==null){var i=n=n.next;do{if((i.tag&e)===e){var l=i.create;i.destroy=l()}i=i.next}while(i!==n)}}function nl(e){var n=e.ref;if(n!==null){var i=e.stateNode;switch(e.tag){case 5:e=i;break;default:e=i}typeof n=="function"?n(e):n.current=e}}function _d(e){var n=e.alternate;n!==null&&(e.alternate=null,_d(n)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(n=e.stateNode,n!==null&&(delete n[yn],delete n[ks],delete n[vo],delete n[qp],delete n[Yp])),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}function $d(e){return e.tag===5||e.tag===3||e.tag===4}function Ld(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||$d(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function rl(e,n,i){var l=e.tag;if(l===5||l===6)e=e.stateNode,n?i.nodeType===8?i.parentNode.insertBefore(e,n):i.insertBefore(e,n):(i.nodeType===8?(n=i.parentNode,n.insertBefore(e,i)):(n=i,n.appendChild(e)),i=i._reactRootContainer,i!=null||n.onclick!==null||(n.onclick=ba));else if(l!==4&&(e=e.child,e!==null))for(rl(e,n,i),e=e.sibling;e!==null;)rl(e,n,i),e=e.sibling}function sl(e,n,i){var l=e.tag;if(l===5||l===6)e=e.stateNode,n?i.insertBefore(e,n):i.appendChild(e);else if(l!==4&&(e=e.child,e!==null))for(sl(e,n,i),e=e.sibling;e!==null;)sl(e,n,i),e=e.sibling}var Nt=null,cn=!1;function Kn(e,n,i){for(i=i.child;i!==null;)zd(e,n,i),i=i.sibling}function zd(e,n,i){if(gn&&typeof gn.onCommitFiberUnmount=="function")try{gn.onCommitFiberUnmount(aa,i)}catch{}switch(i.tag){case 5:It||Vr(i,n);case 6:var l=Nt,d=cn;Nt=null,Kn(e,n,i),Nt=l,cn=d,Nt!==null&&(cn?(e=Nt,i=i.stateNode,e.nodeType===8?e.parentNode.removeChild(i):e.removeChild(i)):Nt.removeChild(i.stateNode));break;case 18:Nt!==null&&(cn?(e=Nt,i=i.stateNode,e.nodeType===8?yo(e.parentNode,i):e.nodeType===1&&yo(e,i),hs(e)):yo(Nt,i.stateNode));break;case 4:l=Nt,d=cn,Nt=i.stateNode.containerInfo,cn=!0,Kn(e,n,i),Nt=l,cn=d;break;case 0:case 11:case 14:case 15:if(!It&&(l=i.updateQueue,l!==null&&(l=l.lastEffect,l!==null))){d=l=l.next;do{var m=d,x=m.destroy;m=m.tag,x!==void 0&&((m&2)!==0||(m&4)!==0)&&tl(i,n,x),d=d.next}while(d!==l)}Kn(e,n,i);break;case 1:if(!It&&(Vr(i,n),l=i.stateNode,typeof l.componentWillUnmount=="function"))try{l.props=i.memoizedProps,l.state=i.memoizedState,l.componentWillUnmount()}catch(E){ct(i,n,E)}Kn(e,n,i);break;case 21:Kn(e,n,i);break;case 22:i.mode&1?(It=(l=It)||i.memoizedState!==null,Kn(e,n,i),It=l):Kn(e,n,i);break;default:Kn(e,n,i)}}function Fd(e){var n=e.updateQueue;if(n!==null){e.updateQueue=null;var i=e.stateNode;i===null&&(i=e.stateNode=new dg),n.forEach(function(l){var d=jg.bind(null,e,l);i.has(l)||(i.add(l),l.then(d,d))})}}function un(e,n){var i=n.deletions;if(i!==null)for(var l=0;l<i.length;l++){var d=i[l];try{var m=e,x=n,E=x;e:for(;E!==null;){switch(E.tag){case 5:Nt=E.stateNode,cn=!1;break e;case 3:Nt=E.stateNode.containerInfo,cn=!0;break e;case 4:Nt=E.stateNode.containerInfo,cn=!0;break e}E=E.return}if(Nt===null)throw Error(a(160));zd(m,x,d),Nt=null,cn=!1;var I=d.alternate;I!==null&&(I.return=null),d.return=null}catch(U){ct(d,n,U)}}if(n.subtreeFlags&12854)for(n=n.child;n!==null;)Od(n,e),n=n.sibling}function Od(e,n){var i=e.alternate,l=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(un(n,e),wn(e),l&4){try{Ls(3,e,e.return),Ga(3,e)}catch(Ce){ct(e,e.return,Ce)}try{Ls(5,e,e.return)}catch(Ce){ct(e,e.return,Ce)}}break;case 1:un(n,e),wn(e),l&512&&i!==null&&Vr(i,i.return);break;case 5:if(un(n,e),wn(e),l&512&&i!==null&&Vr(i,i.return),e.flags&32){var d=e.stateNode;try{Me(d,"")}catch(Ce){ct(e,e.return,Ce)}}if(l&4&&(d=e.stateNode,d!=null)){var m=e.memoizedProps,x=i!==null?i.memoizedProps:m,E=e.type,I=e.updateQueue;if(e.updateQueue=null,I!==null)try{E==="input"&&m.type==="radio"&&m.name!=null&&He(d,m),kt(E,x);var U=kt(E,m);for(x=0;x<I.length;x+=2){var te=I[x],ae=I[x+1];te==="style"?pn(d,ae):te==="dangerouslySetInnerHTML"?de(d,ae):te==="children"?Me(d,ae):P(d,te,ae,U)}switch(E){case"input":Oe(d,m);break;case"textarea":ze(d,m);break;case"select":var Z=d._wrapperState.wasMultiple;d._wrapperState.wasMultiple=!!m.multiple;var xe=m.value;xe!=null?Pe(d,!!m.multiple,xe,!1):Z!==!!m.multiple&&(m.defaultValue!=null?Pe(d,!!m.multiple,m.defaultValue,!0):Pe(d,!!m.multiple,m.multiple?[]:"",!1))}d[ks]=m}catch(Ce){ct(e,e.return,Ce)}}break;case 6:if(un(n,e),wn(e),l&4){if(e.stateNode===null)throw Error(a(162));d=e.stateNode,m=e.memoizedProps;try{d.nodeValue=m}catch(Ce){ct(e,e.return,Ce)}}break;case 3:if(un(n,e),wn(e),l&4&&i!==null&&i.memoizedState.isDehydrated)try{hs(n.containerInfo)}catch(Ce){ct(e,e.return,Ce)}break;case 4:un(n,e),wn(e);break;case 13:un(n,e),wn(e),d=e.child,d.flags&8192&&(m=d.memoizedState!==null,d.stateNode.isHidden=m,!m||d.alternate!==null&&d.alternate.memoizedState!==null||(ol=dt())),l&4&&Fd(e);break;case 22:if(te=i!==null&&i.memoizedState!==null,e.mode&1?(It=(U=It)||te,un(n,e),It=U):un(n,e),wn(e),l&8192){if(U=e.memoizedState!==null,(e.stateNode.isHidden=U)&&!te&&(e.mode&1)!==0)for(je=e,te=e.child;te!==null;){for(ae=je=te;je!==null;){switch(Z=je,xe=Z.child,Z.tag){case 0:case 11:case 14:case 15:Ls(4,Z,Z.return);break;case 1:Vr(Z,Z.return);var be=Z.stateNode;if(typeof be.componentWillUnmount=="function"){l=Z,i=Z.return;try{n=l,be.props=n.memoizedProps,be.state=n.memoizedState,be.componentWillUnmount()}catch(Ce){ct(l,i,Ce)}}break;case 5:Vr(Z,Z.return);break;case 22:if(Z.memoizedState!==null){Dd(ae);continue}}xe!==null?(xe.return=Z,je=xe):Dd(ae)}te=te.sibling}e:for(te=null,ae=e;;){if(ae.tag===5){if(te===null){te=ae;try{d=ae.stateNode,U?(m=d.style,typeof m.setProperty=="function"?m.setProperty("display","none","important"):m.display="none"):(E=ae.stateNode,I=ae.memoizedProps.style,x=I!=null&&I.hasOwnProperty("display")?I.display:null,E.style.display=pt("display",x))}catch(Ce){ct(e,e.return,Ce)}}}else if(ae.tag===6){if(te===null)try{ae.stateNode.nodeValue=U?"":ae.memoizedProps}catch(Ce){ct(e,e.return,Ce)}}else if((ae.tag!==22&&ae.tag!==23||ae.memoizedState===null||ae===e)&&ae.child!==null){ae.child.return=ae,ae=ae.child;continue}if(ae===e)break e;for(;ae.sibling===null;){if(ae.return===null||ae.return===e)break e;te===ae&&(te=null),ae=ae.return}te===ae&&(te=null),ae.sibling.return=ae.return,ae=ae.sibling}}break;case 19:un(n,e),wn(e),l&4&&Fd(e);break;case 21:break;default:un(n,e),wn(e)}}function wn(e){var n=e.flags;if(n&2){try{e:{for(var i=e.return;i!==null;){if($d(i)){var l=i;break e}i=i.return}throw Error(a(160))}switch(l.tag){case 5:var d=l.stateNode;l.flags&32&&(Me(d,""),l.flags&=-33);var m=Ld(e);sl(e,m,d);break;case 3:case 4:var x=l.stateNode.containerInfo,E=Ld(e);rl(e,E,x);break;default:throw Error(a(161))}}catch(I){ct(e,e.return,I)}e.flags&=-3}n&4096&&(e.flags&=-4097)}function hg(e,n,i){je=e,Md(e)}function Md(e,n,i){for(var l=(e.mode&1)!==0;je!==null;){var d=je,m=d.child;if(d.tag===22&&l){var x=d.memoizedState!==null||Va;if(!x){var E=d.alternate,I=E!==null&&E.memoizedState!==null||It;E=Va;var U=It;if(Va=x,(It=I)&&!U)for(je=d;je!==null;)x=je,I=x.child,x.tag===22&&x.memoizedState!==null?Ud(d):I!==null?(I.return=x,je=I):Ud(d);for(;m!==null;)je=m,Md(m),m=m.sibling;je=d,Va=E,It=U}Bd(e)}else(d.subtreeFlags&8772)!==0&&m!==null?(m.return=d,je=m):Bd(e)}}function Bd(e){for(;je!==null;){var n=je;if((n.flags&8772)!==0){var i=n.alternate;try{if((n.flags&8772)!==0)switch(n.tag){case 0:case 11:case 15:It||Ga(5,n);break;case 1:var l=n.stateNode;if(n.flags&4&&!It)if(i===null)l.componentDidMount();else{var d=n.elementType===n.type?i.memoizedProps:ln(n.type,i.memoizedProps);l.componentDidUpdate(d,i.memoizedState,l.__reactInternalSnapshotBeforeUpdate)}var m=n.updateQueue;m!==null&&Du(n,m,l);break;case 3:var x=n.updateQueue;if(x!==null){if(i=null,n.child!==null)switch(n.child.tag){case 5:i=n.child.stateNode;break;case 1:i=n.child.stateNode}Du(n,x,i)}break;case 5:var E=n.stateNode;if(i===null&&n.flags&4){i=E;var I=n.memoizedProps;switch(n.type){case"button":case"input":case"select":case"textarea":I.autoFocus&&i.focus();break;case"img":I.src&&(i.src=I.src)}}break;case 6:break;case 4:break;case 12:break;case 13:if(n.memoizedState===null){var U=n.alternate;if(U!==null){var te=U.memoizedState;if(te!==null){var ae=te.dehydrated;ae!==null&&hs(ae)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(a(163))}It||n.flags&512&&nl(n)}catch(Z){ct(n,n.return,Z)}}if(n===e){je=null;break}if(i=n.sibling,i!==null){i.return=n.return,je=i;break}je=n.return}}function Dd(e){for(;je!==null;){var n=je;if(n===e){je=null;break}var i=n.sibling;if(i!==null){i.return=n.return,je=i;break}je=n.return}}function Ud(e){for(;je!==null;){var n=je;try{switch(n.tag){case 0:case 11:case 15:var i=n.return;try{Ga(4,n)}catch(I){ct(n,i,I)}break;case 1:var l=n.stateNode;if(typeof l.componentDidMount=="function"){var d=n.return;try{l.componentDidMount()}catch(I){ct(n,d,I)}}var m=n.return;try{nl(n)}catch(I){ct(n,m,I)}break;case 5:var x=n.return;try{nl(n)}catch(I){ct(n,x,I)}}}catch(I){ct(n,n.return,I)}if(n===e){je=null;break}var E=n.sibling;if(E!==null){E.return=n.return,je=E;break}je=n.return}}var mg=Math.ceil,Ka=A.ReactCurrentDispatcher,al=A.ReactCurrentOwner,en=A.ReactCurrentBatchConfig,Ve=0,St=null,gt=null,Ct=0,Kt=0,Gr=Un(0),vt=0,zs=null,hr=0,qa=0,il=0,Fs=null,Ot=null,ol=0,Kr=1/0,In=null,Ya=!1,ll=null,qn=null,Ja=!1,Yn=null,Qa=0,Os=0,cl=null,Xa=-1,Za=0;function _t(){return(Ve&6)!==0?dt():Xa!==-1?Xa:Xa=dt()}function Jn(e){return(e.mode&1)===0?1:(Ve&2)!==0&&Ct!==0?Ct&-Ct:Qp.transition!==null?(Za===0&&(Za=Lc()),Za):(e=qe,e!==0||(e=window.event,e=e===void 0?16:Hc(e.type)),e)}function dn(e,n,i,l){if(50<Os)throw Os=0,cl=null,Error(a(185));ls(e,i,l),((Ve&2)===0||e!==St)&&(e===St&&((Ve&2)===0&&(qa|=i),vt===4&&Qn(e,Ct)),Mt(e,l),i===1&&Ve===0&&(n.mode&1)===0&&(Kr=dt()+500,Ea&&Hn()))}function Mt(e,n){var i=e.callbackNode;Qm(e,n);var l=la(e,e===St?Ct:0);if(l===0)i!==null&&Pc(i),e.callbackNode=null,e.callbackPriority=0;else if(n=l&-l,e.callbackPriority!==n){if(i!=null&&Pc(i),n===1)e.tag===0?Jp(Hd.bind(null,e)):Ru(Hd.bind(null,e)),Gp(function(){(Ve&6)===0&&Hn()}),i=null;else{switch(zc(l)){case 1:i=Di;break;case 4:i=_c;break;case 16:i=sa;break;case 536870912:i=$c;break;default:i=sa}i=Xd(i,Wd.bind(null,e))}e.callbackPriority=n,e.callbackNode=i}}function Wd(e,n){if(Xa=-1,Za=0,(Ve&6)!==0)throw Error(a(327));var i=e.callbackNode;if(qr()&&e.callbackNode!==i)return null;var l=la(e,e===St?Ct:0);if(l===0)return null;if((l&30)!==0||(l&e.expiredLanes)!==0||n)n=ei(e,l);else{n=l;var d=Ve;Ve|=2;var m=Gd();(St!==e||Ct!==n)&&(In=null,Kr=dt()+500,pr(e,n));do try{yg();break}catch(E){Vd(e,E)}while(!0);Eo(),Ka.current=m,Ve=d,gt!==null?n=0:(St=null,Ct=0,n=vt)}if(n!==0){if(n===2&&(d=Ui(e),d!==0&&(l=d,n=ul(e,d))),n===1)throw i=zs,pr(e,0),Qn(e,l),Mt(e,dt()),i;if(n===6)Qn(e,l);else{if(d=e.current.alternate,(l&30)===0&&!pg(d)&&(n=ei(e,l),n===2&&(m=Ui(e),m!==0&&(l=m,n=ul(e,m))),n===1))throw i=zs,pr(e,0),Qn(e,l),Mt(e,dt()),i;switch(e.finishedWork=d,e.finishedLanes=l,n){case 0:case 1:throw Error(a(345));case 2:gr(e,Ot,In);break;case 3:if(Qn(e,l),(l&130023424)===l&&(n=ol+500-dt(),10<n)){if(la(e,0)!==0)break;if(d=e.suspendedLanes,(d&l)!==l){_t(),e.pingedLanes|=e.suspendedLanes&d;break}e.timeoutHandle=go(gr.bind(null,e,Ot,In),n);break}gr(e,Ot,In);break;case 4:if(Qn(e,l),(l&4194240)===l)break;for(n=e.eventTimes,d=-1;0<l;){var x=31-sn(l);m=1<<x,x=n[x],x>d&&(d=x),l&=~m}if(l=d,l=dt()-l,l=(120>l?120:480>l?480:1080>l?1080:1920>l?1920:3e3>l?3e3:4320>l?4320:1960*mg(l/1960))-l,10<l){e.timeoutHandle=go(gr.bind(null,e,Ot,In),l);break}gr(e,Ot,In);break;case 5:gr(e,Ot,In);break;default:throw Error(a(329))}}}return Mt(e,dt()),e.callbackNode===i?Wd.bind(null,e):null}function ul(e,n){var i=Fs;return e.current.memoizedState.isDehydrated&&(pr(e,n).flags|=256),e=ei(e,n),e!==2&&(n=Ot,Ot=i,n!==null&&dl(n)),e}function dl(e){Ot===null?Ot=e:Ot.push.apply(Ot,e)}function pg(e){for(var n=e;;){if(n.flags&16384){var i=n.updateQueue;if(i!==null&&(i=i.stores,i!==null))for(var l=0;l<i.length;l++){var d=i[l],m=d.getSnapshot;d=d.value;try{if(!an(m(),d))return!1}catch{return!1}}}if(i=n.child,n.subtreeFlags&16384&&i!==null)i.return=n,n=i;else{if(n===e)break;for(;n.sibling===null;){if(n.return===null||n.return===e)return!0;n=n.return}n.sibling.return=n.return,n=n.sibling}}return!0}function Qn(e,n){for(n&=~il,n&=~qa,e.suspendedLanes|=n,e.pingedLanes&=~n,e=e.expirationTimes;0<n;){var i=31-sn(n),l=1<<i;e[i]=-1,n&=~l}}function Hd(e){if((Ve&6)!==0)throw Error(a(327));qr();var n=la(e,0);if((n&1)===0)return Mt(e,dt()),null;var i=ei(e,n);if(e.tag!==0&&i===2){var l=Ui(e);l!==0&&(n=l,i=ul(e,l))}if(i===1)throw i=zs,pr(e,0),Qn(e,n),Mt(e,dt()),i;if(i===6)throw Error(a(345));return e.finishedWork=e.current.alternate,e.finishedLanes=n,gr(e,Ot,In),Mt(e,dt()),null}function fl(e,n){var i=Ve;Ve|=1;try{return e(n)}finally{Ve=i,Ve===0&&(Kr=dt()+500,Ea&&Hn())}}function mr(e){Yn!==null&&Yn.tag===0&&(Ve&6)===0&&qr();var n=Ve;Ve|=1;var i=en.transition,l=qe;try{if(en.transition=null,qe=1,e)return e()}finally{qe=l,en.transition=i,Ve=n,(Ve&6)===0&&Hn()}}function hl(){Kt=Gr.current,nt(Gr)}function pr(e,n){e.finishedWork=null,e.finishedLanes=0;var i=e.timeoutHandle;if(i!==-1&&(e.timeoutHandle=-1,Vp(i)),gt!==null)for(i=gt.return;i!==null;){var l=i;switch(So(l),l.tag){case 1:l=l.type.childContextTypes,l!=null&&Na();break;case 3:Wr(),nt(Lt),nt(Tt),Lo();break;case 5:_o(l);break;case 4:Wr();break;case 13:nt(it);break;case 19:nt(it);break;case 10:To(l.type._context);break;case 22:case 23:hl()}i=i.return}if(St=e,gt=e=Xn(e.current,null),Ct=Kt=n,vt=0,zs=null,il=qa=hr=0,Ot=Fs=null,ur!==null){for(n=0;n<ur.length;n++)if(i=ur[n],l=i.interleaved,l!==null){i.interleaved=null;var d=l.next,m=i.pending;if(m!==null){var x=m.next;m.next=d,l.next=x}i.pending=l}ur=null}return e}function Vd(e,n){do{var i=gt;try{if(Eo(),Fa.current=Da,Oa){for(var l=ot.memoizedState;l!==null;){var d=l.queue;d!==null&&(d.pending=null),l=l.next}Oa=!1}if(fr=0,jt=yt=ot=null,As=!1,Is=0,al.current=null,i===null||i.return===null){vt=1,zs=n,gt=null;break}e:{var m=e,x=i.return,E=i,I=n;if(n=Ct,E.flags|=32768,I!==null&&typeof I=="object"&&typeof I.then=="function"){var U=I,te=E,ae=te.tag;if((te.mode&1)===0&&(ae===0||ae===11||ae===15)){var Z=te.alternate;Z?(te.updateQueue=Z.updateQueue,te.memoizedState=Z.memoizedState,te.lanes=Z.lanes):(te.updateQueue=null,te.memoizedState=null)}var xe=gd(x);if(xe!==null){xe.flags&=-257,yd(xe,x,E,m,n),xe.mode&1&&pd(m,U,n),n=xe,I=U;var be=n.updateQueue;if(be===null){var Ce=new Set;Ce.add(I),n.updateQueue=Ce}else be.add(I);break e}else{if((n&1)===0){pd(m,U,n),ml();break e}I=Error(a(426))}}else if(st&&E.mode&1){var ft=gd(x);if(ft!==null){(ft.flags&65536)===0&&(ft.flags|=256),yd(ft,x,E,m,n),No(Hr(I,E));break e}}m=I=Hr(I,E),vt!==4&&(vt=2),Fs===null?Fs=[m]:Fs.push(m),m=x;do{switch(m.tag){case 3:m.flags|=65536,n&=-n,m.lanes|=n;var M=hd(m,I,n);Bu(m,M);break e;case 1:E=I;var $=m.type,D=m.stateNode;if((m.flags&128)===0&&(typeof $.getDerivedStateFromError=="function"||D!==null&&typeof D.componentDidCatch=="function"&&(qn===null||!qn.has(D)))){m.flags|=65536,n&=-n,m.lanes|=n;var ue=md(m,E,n);Bu(m,ue);break e}}m=m.return}while(m!==null)}qd(i)}catch(Ee){n=Ee,gt===i&&i!==null&&(gt=i=i.return);continue}break}while(!0)}function Gd(){var e=Ka.current;return Ka.current=Da,e===null?Da:e}function ml(){(vt===0||vt===3||vt===2)&&(vt=4),St===null||(hr&268435455)===0&&(qa&268435455)===0||Qn(St,Ct)}function ei(e,n){var i=Ve;Ve|=2;var l=Gd();(St!==e||Ct!==n)&&(In=null,pr(e,n));do try{gg();break}catch(d){Vd(e,d)}while(!0);if(Eo(),Ve=i,Ka.current=l,gt!==null)throw Error(a(261));return St=null,Ct=0,vt}function gg(){for(;gt!==null;)Kd(gt)}function yg(){for(;gt!==null&&!Um();)Kd(gt)}function Kd(e){var n=Qd(e.alternate,e,Kt);e.memoizedProps=e.pendingProps,n===null?qd(e):gt=n,al.current=null}function qd(e){var n=e;do{var i=n.alternate;if(e=n.return,(n.flags&32768)===0){if(i=cg(i,n,Kt),i!==null){gt=i;return}}else{if(i=ug(i,n),i!==null){i.flags&=32767,gt=i;return}if(e!==null)e.flags|=32768,e.subtreeFlags=0,e.deletions=null;else{vt=6,gt=null;return}}if(n=n.sibling,n!==null){gt=n;return}gt=n=e}while(n!==null);vt===0&&(vt=5)}function gr(e,n,i){var l=qe,d=en.transition;try{en.transition=null,qe=1,vg(e,n,i,l)}finally{en.transition=d,qe=l}return null}function vg(e,n,i,l){do qr();while(Yn!==null);if((Ve&6)!==0)throw Error(a(327));i=e.finishedWork;var d=e.finishedLanes;if(i===null)return null;if(e.finishedWork=null,e.finishedLanes=0,i===e.current)throw Error(a(177));e.callbackNode=null,e.callbackPriority=0;var m=i.lanes|i.childLanes;if(Xm(e,m),e===St&&(gt=St=null,Ct=0),(i.subtreeFlags&2064)===0&&(i.flags&2064)===0||Ja||(Ja=!0,Xd(sa,function(){return qr(),null})),m=(i.flags&15990)!==0,(i.subtreeFlags&15990)!==0||m){m=en.transition,en.transition=null;var x=qe;qe=1;var E=Ve;Ve|=4,al.current=null,fg(e,i),Od(i,e),Op(mo),da=!!ho,mo=ho=null,e.current=i,hg(i),Wm(),Ve=E,qe=x,en.transition=m}else e.current=i;if(Ja&&(Ja=!1,Yn=e,Qa=d),m=e.pendingLanes,m===0&&(qn=null),Gm(i.stateNode),Mt(e,dt()),n!==null)for(l=e.onRecoverableError,i=0;i<n.length;i++)d=n[i],l(d.value,{componentStack:d.stack,digest:d.digest});if(Ya)throw Ya=!1,e=ll,ll=null,e;return(Qa&1)!==0&&e.tag!==0&&qr(),m=e.pendingLanes,(m&1)!==0?e===cl?Os++:(Os=0,cl=e):Os=0,Hn(),null}function qr(){if(Yn!==null){var e=zc(Qa),n=en.transition,i=qe;try{if(en.transition=null,qe=16>e?16:e,Yn===null)var l=!1;else{if(e=Yn,Yn=null,Qa=0,(Ve&6)!==0)throw Error(a(331));var d=Ve;for(Ve|=4,je=e.current;je!==null;){var m=je,x=m.child;if((je.flags&16)!==0){var E=m.deletions;if(E!==null){for(var I=0;I<E.length;I++){var U=E[I];for(je=U;je!==null;){var te=je;switch(te.tag){case 0:case 11:case 15:Ls(8,te,m)}var ae=te.child;if(ae!==null)ae.return=te,je=ae;else for(;je!==null;){te=je;var Z=te.sibling,xe=te.return;if(_d(te),te===U){je=null;break}if(Z!==null){Z.return=xe,je=Z;break}je=xe}}}var be=m.alternate;if(be!==null){var Ce=be.child;if(Ce!==null){be.child=null;do{var ft=Ce.sibling;Ce.sibling=null,Ce=ft}while(Ce!==null)}}je=m}}if((m.subtreeFlags&2064)!==0&&x!==null)x.return=m,je=x;else e:for(;je!==null;){if(m=je,(m.flags&2048)!==0)switch(m.tag){case 0:case 11:case 15:Ls(9,m,m.return)}var M=m.sibling;if(M!==null){M.return=m.return,je=M;break e}je=m.return}}var $=e.current;for(je=$;je!==null;){x=je;var D=x.child;if((x.subtreeFlags&2064)!==0&&D!==null)D.return=x,je=D;else e:for(x=$;je!==null;){if(E=je,(E.flags&2048)!==0)try{switch(E.tag){case 0:case 11:case 15:Ga(9,E)}}catch(Ee){ct(E,E.return,Ee)}if(E===x){je=null;break e}var ue=E.sibling;if(ue!==null){ue.return=E.return,je=ue;break e}je=E.return}}if(Ve=d,Hn(),gn&&typeof gn.onPostCommitFiberRoot=="function")try{gn.onPostCommitFiberRoot(aa,e)}catch{}l=!0}return l}finally{qe=i,en.transition=n}}return!1}function Yd(e,n,i){n=Hr(i,n),n=hd(e,n,1),e=Gn(e,n,1),n=_t(),e!==null&&(ls(e,1,n),Mt(e,n))}function ct(e,n,i){if(e.tag===3)Yd(e,e,i);else for(;n!==null;){if(n.tag===3){Yd(n,e,i);break}else if(n.tag===1){var l=n.stateNode;if(typeof n.type.getDerivedStateFromError=="function"||typeof l.componentDidCatch=="function"&&(qn===null||!qn.has(l))){e=Hr(i,e),e=md(n,e,1),n=Gn(n,e,1),e=_t(),n!==null&&(ls(n,1,e),Mt(n,e));break}}n=n.return}}function xg(e,n,i){var l=e.pingCache;l!==null&&l.delete(n),n=_t(),e.pingedLanes|=e.suspendedLanes&i,St===e&&(Ct&i)===i&&(vt===4||vt===3&&(Ct&130023424)===Ct&&500>dt()-ol?pr(e,0):il|=i),Mt(e,n)}function Jd(e,n){n===0&&((e.mode&1)===0?n=1:(n=oa,oa<<=1,(oa&130023424)===0&&(oa=4194304)));var i=_t();e=Tn(e,n),e!==null&&(ls(e,n,i),Mt(e,i))}function wg(e){var n=e.memoizedState,i=0;n!==null&&(i=n.retryLane),Jd(e,i)}function jg(e,n){var i=0;switch(e.tag){case 13:var l=e.stateNode,d=e.memoizedState;d!==null&&(i=d.retryLane);break;case 19:l=e.stateNode;break;default:throw Error(a(314))}l!==null&&l.delete(n),Jd(e,i)}var Qd;Qd=function(e,n,i){if(e!==null)if(e.memoizedProps!==n.pendingProps||Lt.current)Ft=!0;else{if((e.lanes&i)===0&&(n.flags&128)===0)return Ft=!1,lg(e,n,i);Ft=(e.flags&131072)!==0}else Ft=!1,st&&(n.flags&1048576)!==0&&Au(n,Ra,n.index);switch(n.lanes=0,n.tag){case 2:var l=n.type;Ha(e,n),e=n.pendingProps;var d=zr(n,Tt.current);Ur(n,i),d=Oo(null,n,l,e,d,i);var m=Mo();return n.flags|=1,typeof d=="object"&&d!==null&&typeof d.render=="function"&&d.$$typeof===void 0?(n.tag=1,n.memoizedState=null,n.updateQueue=null,zt(l)?(m=!0,Ca(n)):m=!1,n.memoizedState=d.state!==null&&d.state!==void 0?d.state:null,Io(n),d.updater=Ua,n.stateNode=d,d._reactInternals=n,Vo(n,l,e,i),n=Yo(null,n,l,!0,m,i)):(n.tag=0,st&&m&&jo(n),Pt(null,n,d,i),n=n.child),n;case 16:l=n.elementType;e:{switch(Ha(e,n),e=n.pendingProps,d=l._init,l=d(l._payload),n.type=l,d=n.tag=bg(l),e=ln(l,e),d){case 0:n=qo(null,n,l,e,i);break e;case 1:n=bd(null,n,l,e,i);break e;case 11:n=vd(null,n,l,e,i);break e;case 14:n=xd(null,n,l,ln(l.type,e),i);break e}throw Error(a(306,l,""))}return n;case 0:return l=n.type,d=n.pendingProps,d=n.elementType===l?d:ln(l,d),qo(e,n,l,d,i);case 1:return l=n.type,d=n.pendingProps,d=n.elementType===l?d:ln(l,d),bd(e,n,l,d,i);case 3:e:{if(kd(n),e===null)throw Error(a(387));l=n.pendingProps,m=n.memoizedState,d=m.element,Mu(e,n),La(n,l,null,i);var x=n.memoizedState;if(l=x.element,m.isDehydrated)if(m={element:l,isDehydrated:!1,cache:x.cache,pendingSuspenseBoundaries:x.pendingSuspenseBoundaries,transitions:x.transitions},n.updateQueue.baseState=m,n.memoizedState=m,n.flags&256){d=Hr(Error(a(423)),n),n=Nd(e,n,l,i,d);break e}else if(l!==d){d=Hr(Error(a(424)),n),n=Nd(e,n,l,i,d);break e}else for(Gt=Dn(n.stateNode.containerInfo.firstChild),Vt=n,st=!0,on=null,i=Fu(n,null,l,i),n.child=i;i;)i.flags=i.flags&-3|4096,i=i.sibling;else{if(Mr(),l===d){n=An(e,n,i);break e}Pt(e,n,l,i)}n=n.child}return n;case 5:return Uu(n),e===null&&ko(n),l=n.type,d=n.pendingProps,m=e!==null?e.memoizedProps:null,x=d.children,po(l,d)?x=null:m!==null&&po(l,m)&&(n.flags|=32),Sd(e,n),Pt(e,n,x,i),n.child;case 6:return e===null&&ko(n),null;case 13:return Cd(e,n,i);case 4:return Po(n,n.stateNode.containerInfo),l=n.pendingProps,e===null?n.child=Br(n,null,l,i):Pt(e,n,l,i),n.child;case 11:return l=n.type,d=n.pendingProps,d=n.elementType===l?d:ln(l,d),vd(e,n,l,d,i);case 7:return Pt(e,n,n.pendingProps,i),n.child;case 8:return Pt(e,n,n.pendingProps.children,i),n.child;case 12:return Pt(e,n,n.pendingProps.children,i),n.child;case 10:e:{if(l=n.type._context,d=n.pendingProps,m=n.memoizedProps,x=d.value,Ze(Pa,l._currentValue),l._currentValue=x,m!==null)if(an(m.value,x)){if(m.children===d.children&&!Lt.current){n=An(e,n,i);break e}}else for(m=n.child,m!==null&&(m.return=n);m!==null;){var E=m.dependencies;if(E!==null){x=m.child;for(var I=E.firstContext;I!==null;){if(I.context===l){if(m.tag===1){I=Rn(-1,i&-i),I.tag=2;var U=m.updateQueue;if(U!==null){U=U.shared;var te=U.pending;te===null?I.next=I:(I.next=te.next,te.next=I),U.pending=I}}m.lanes|=i,I=m.alternate,I!==null&&(I.lanes|=i),Ro(m.return,i,n),E.lanes|=i;break}I=I.next}}else if(m.tag===10)x=m.type===n.type?null:m.child;else if(m.tag===18){if(x=m.return,x===null)throw Error(a(341));x.lanes|=i,E=x.alternate,E!==null&&(E.lanes|=i),Ro(x,i,n),x=m.sibling}else x=m.child;if(x!==null)x.return=m;else for(x=m;x!==null;){if(x===n){x=null;break}if(m=x.sibling,m!==null){m.return=x.return,x=m;break}x=x.return}m=x}Pt(e,n,d.children,i),n=n.child}return n;case 9:return d=n.type,l=n.pendingProps.children,Ur(n,i),d=Xt(d),l=l(d),n.flags|=1,Pt(e,n,l,i),n.child;case 14:return l=n.type,d=ln(l,n.pendingProps),d=ln(l.type,d),xd(e,n,l,d,i);case 15:return wd(e,n,n.type,n.pendingProps,i);case 17:return l=n.type,d=n.pendingProps,d=n.elementType===l?d:ln(l,d),Ha(e,n),n.tag=1,zt(l)?(e=!0,Ca(n)):e=!1,Ur(n,i),dd(n,l,d),Vo(n,l,d,i),Yo(null,n,l,!0,e,i);case 19:return Td(e,n,i);case 22:return jd(e,n,i)}throw Error(a(156,n.tag))};function Xd(e,n){return Ic(e,n)}function Sg(e,n,i,l){this.tag=e,this.key=i,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=n,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=l,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function tn(e,n,i,l){return new Sg(e,n,i,l)}function pl(e){return e=e.prototype,!(!e||!e.isReactComponent)}function bg(e){if(typeof e=="function")return pl(e)?1:0;if(e!=null){if(e=e.$$typeof,e===F)return 11;if(e===se)return 14}return 2}function Xn(e,n){var i=e.alternate;return i===null?(i=tn(e.tag,n,e.key,e.mode),i.elementType=e.elementType,i.type=e.type,i.stateNode=e.stateNode,i.alternate=e,e.alternate=i):(i.pendingProps=n,i.type=e.type,i.flags=0,i.subtreeFlags=0,i.deletions=null),i.flags=e.flags&14680064,i.childLanes=e.childLanes,i.lanes=e.lanes,i.child=e.child,i.memoizedProps=e.memoizedProps,i.memoizedState=e.memoizedState,i.updateQueue=e.updateQueue,n=e.dependencies,i.dependencies=n===null?null:{lanes:n.lanes,firstContext:n.firstContext},i.sibling=e.sibling,i.index=e.index,i.ref=e.ref,i}function ti(e,n,i,l,d,m){var x=2;if(l=e,typeof e=="function")pl(e)&&(x=1);else if(typeof e=="string")x=5;else e:switch(e){case G:return yr(i.children,d,m,n);case me:x=8,d|=8;break;case q:return e=tn(12,i,n,d|2),e.elementType=q,e.lanes=m,e;case re:return e=tn(13,i,n,d),e.elementType=re,e.lanes=m,e;case Y:return e=tn(19,i,n,d),e.elementType=Y,e.lanes=m,e;case we:return ni(i,d,m,n);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case ce:x=10;break e;case ee:x=9;break e;case F:x=11;break e;case se:x=14;break e;case ye:x=16,l=null;break e}throw Error(a(130,e==null?e:typeof e,""))}return n=tn(x,i,n,d),n.elementType=e,n.type=l,n.lanes=m,n}function yr(e,n,i,l){return e=tn(7,e,l,n),e.lanes=i,e}function ni(e,n,i,l){return e=tn(22,e,l,n),e.elementType=we,e.lanes=i,e.stateNode={isHidden:!1},e}function gl(e,n,i){return e=tn(6,e,null,n),e.lanes=i,e}function yl(e,n,i){return n=tn(4,e.children!==null?e.children:[],e.key,n),n.lanes=i,n.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},n}function kg(e,n,i,l,d){this.tag=n,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Wi(0),this.expirationTimes=Wi(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Wi(0),this.identifierPrefix=l,this.onRecoverableError=d,this.mutableSourceEagerHydrationData=null}function vl(e,n,i,l,d,m,x,E,I){return e=new kg(e,n,i,E,I),n===1?(n=1,m===!0&&(n|=8)):n=0,m=tn(3,null,null,n),e.current=m,m.stateNode=e,m.memoizedState={element:l,isDehydrated:i,cache:null,transitions:null,pendingSuspenseBoundaries:null},Io(m),e}function Ng(e,n,i){var l=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:H,key:l==null?null:""+l,children:e,containerInfo:n,implementation:i}}function Zd(e){if(!e)return Wn;e=e._reactInternals;e:{if(ar(e)!==e||e.tag!==1)throw Error(a(170));var n=e;do{switch(n.tag){case 3:n=n.stateNode.context;break e;case 1:if(zt(n.type)){n=n.stateNode.__reactInternalMemoizedMergedChildContext;break e}}n=n.return}while(n!==null);throw Error(a(171))}if(e.tag===1){var i=e.type;if(zt(i))return Eu(e,i,n)}return n}function ef(e,n,i,l,d,m,x,E,I){return e=vl(i,l,!0,e,d,m,x,E,I),e.context=Zd(null),i=e.current,l=_t(),d=Jn(i),m=Rn(l,d),m.callback=n??null,Gn(i,m,d),e.current.lanes=d,ls(e,d,l),Mt(e,l),e}function ri(e,n,i,l){var d=n.current,m=_t(),x=Jn(d);return i=Zd(i),n.context===null?n.context=i:n.pendingContext=i,n=Rn(m,x),n.payload={element:e},l=l===void 0?null:l,l!==null&&(n.callback=l),e=Gn(d,n,x),e!==null&&(dn(e,d,x,m),$a(e,d,x)),x}function si(e){if(e=e.current,!e.child)return null;switch(e.child.tag){case 5:return e.child.stateNode;default:return e.child.stateNode}}function tf(e,n){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var i=e.retryLane;e.retryLane=i!==0&&i<n?i:n}}function xl(e,n){tf(e,n),(e=e.alternate)&&tf(e,n)}function Cg(){return null}var nf=typeof reportError=="function"?reportError:function(e){console.error(e)};function wl(e){this._internalRoot=e}ai.prototype.render=wl.prototype.render=function(e){var n=this._internalRoot;if(n===null)throw Error(a(409));ri(e,n,null,null)},ai.prototype.unmount=wl.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var n=e.containerInfo;mr(function(){ri(null,e,null,null)}),n[kn]=null}};function ai(e){this._internalRoot=e}ai.prototype.unstable_scheduleHydration=function(e){if(e){var n=Mc();e={blockedOn:null,target:e,priority:n};for(var i=0;i<On.length&&n!==0&&n<On[i].priority;i++);On.splice(i,0,e),i===0&&Uc(e)}};function jl(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function ii(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==" react-mount-point-unstable "))}function rf(){}function Eg(e,n,i,l,d){if(d){if(typeof l=="function"){var m=l;l=function(){var U=si(x);m.call(U)}}var x=ef(n,l,e,0,null,!1,!1,"",rf);return e._reactRootContainer=x,e[kn]=x.current,Ss(e.nodeType===8?e.parentNode:e),mr(),x}for(;d=e.lastChild;)e.removeChild(d);if(typeof l=="function"){var E=l;l=function(){var U=si(I);E.call(U)}}var I=vl(e,0,!1,null,null,!1,!1,"",rf);return e._reactRootContainer=I,e[kn]=I.current,Ss(e.nodeType===8?e.parentNode:e),mr(function(){ri(n,I,i,l)}),I}function oi(e,n,i,l,d){var m=i._reactRootContainer;if(m){var x=m;if(typeof d=="function"){var E=d;d=function(){var I=si(x);E.call(I)}}ri(n,x,e,d)}else x=Eg(i,n,e,d,l);return si(x)}Fc=function(e){switch(e.tag){case 3:var n=e.stateNode;if(n.current.memoizedState.isDehydrated){var i=os(n.pendingLanes);i!==0&&(Hi(n,i|1),Mt(n,dt()),(Ve&6)===0&&(Kr=dt()+500,Hn()))}break;case 13:mr(function(){var l=Tn(e,1);if(l!==null){var d=_t();dn(l,e,1,d)}}),xl(e,1)}},Vi=function(e){if(e.tag===13){var n=Tn(e,134217728);if(n!==null){var i=_t();dn(n,e,134217728,i)}xl(e,134217728)}},Oc=function(e){if(e.tag===13){var n=Jn(e),i=Tn(e,n);if(i!==null){var l=_t();dn(i,e,n,l)}xl(e,n)}},Mc=function(){return qe},Bc=function(e,n){var i=qe;try{return qe=e,n()}finally{qe=i}},le=function(e,n,i){switch(n){case"input":if(Oe(e,i),n=i.name,i.type==="radio"&&n!=null){for(i=e;i.parentNode;)i=i.parentNode;for(i=i.querySelectorAll("input[name="+JSON.stringify(""+n)+'][type="radio"]'),n=0;n<i.length;n++){var l=i[n];if(l!==e&&l.form===e.form){var d=ka(l);if(!d)throw Error(a(90));$e(l),Oe(l,d)}}}break;case"textarea":ze(e,i);break;case"select":n=i.value,n!=null&&Pe(e,!!i.multiple,n,!1)}},Wt=fl,er=mr;var Tg={usingClientEntryPoint:!1,Events:[Ns,$r,ka,Fe,Xe,fl]},Ms={findFiberByHostInstance:ir,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},Rg={bundleType:Ms.bundleType,version:Ms.version,rendererPackageName:Ms.rendererPackageName,rendererConfig:Ms.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:A.ReactCurrentDispatcher,findHostInstanceByFiber:function(e){return e=Rc(e),e===null?null:e.stateNode},findFiberByHostInstance:Ms.findFiberByHostInstance||Cg,findHostInstancesForRefresh:null,scheduleRefresh:null,scheduleRoot:null,setRefreshHandler:null,getCurrentFiber:null,reconcilerVersion:"18.3.1-next-f1338f8080-20240426"};if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"){var li=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!li.isDisabled&&li.supportsFiber)try{aa=li.inject(Rg),gn=li}catch{}}return Bt.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=Tg,Bt.createPortal=function(e,n){var i=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!jl(n))throw Error(a(200));return Ng(e,n,null,i)},Bt.createRoot=function(e,n){if(!jl(e))throw Error(a(299));var i=!1,l="",d=nf;return n!=null&&(n.unstable_strictMode===!0&&(i=!0),n.identifierPrefix!==void 0&&(l=n.identifierPrefix),n.onRecoverableError!==void 0&&(d=n.onRecoverableError)),n=vl(e,1,!1,null,null,i,!1,l,d),e[kn]=n.current,Ss(e.nodeType===8?e.parentNode:e),new wl(n)},Bt.findDOMNode=function(e){if(e==null)return null;if(e.nodeType===1)return e;var n=e._reactInternals;if(n===void 0)throw typeof e.render=="function"?Error(a(188)):(e=Object.keys(e).join(","),Error(a(268,e)));return e=Rc(n),e=e===null?null:e.stateNode,e},Bt.flushSync=function(e){return mr(e)},Bt.hydrate=function(e,n,i){if(!ii(n))throw Error(a(200));return oi(null,e,n,!0,i)},Bt.hydrateRoot=function(e,n,i){if(!jl(e))throw Error(a(405));var l=i!=null&&i.hydratedSources||null,d=!1,m="",x=nf;if(i!=null&&(i.unstable_strictMode===!0&&(d=!0),i.identifierPrefix!==void 0&&(m=i.identifierPrefix),i.onRecoverableError!==void 0&&(x=i.onRecoverableError)),n=ef(n,null,e,1,i??null,d,!1,m,x),e[kn]=n.current,Ss(e),l)for(e=0;e<l.length;e++)i=l[e],d=i._getVersion,d=d(i._source),n.mutableSourceEagerHydrationData==null?n.mutableSourceEagerHydrationData=[i,d]:n.mutableSourceEagerHydrationData.push(i,d);return new ai(n)},Bt.render=function(e,n,i){if(!ii(n))throw Error(a(200));return oi(null,e,n,!1,i)},Bt.unmountComponentAtNode=function(e){if(!ii(e))throw Error(a(40));return e._reactRootContainer?(mr(function(){oi(null,null,e,!1,function(){e._reactRootContainer=null,e[kn]=null})}),!0):!1},Bt.unstable_batchedUpdates=fl,Bt.unstable_renderSubtreeIntoContainer=function(e,n,i,l){if(!ii(i))throw Error(a(200));if(e==null||e._reactInternals===void 0)throw Error(a(38));return oi(e,n,i,!1,l)},Bt.version="18.3.1-next-f1338f8080-20240426",Bt}var ff;function uh(){if(ff)return kl.exports;ff=1;function t(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(t)}catch(s){console.error(s)}}return t(),kl.exports=Og(),kl.exports}var hf;function Mg(){if(hf)return ci;hf=1;var t=uh();return ci.createRoot=t.createRoot,ci.hydrateRoot=t.hydrateRoot,ci}var Bg=Mg();/**
41
+ * react-router v7.18.4
42
+ *
43
+ * Copyright (c) Remix Software Inc.
44
+ *
45
+ * This source code is licensed under the MIT license found in the
46
+ * LICENSE.md file in the root directory of this source tree.
47
+ *
48
+ * @license MIT
49
+ */var Zl=/^(?:[a-z][a-z0-9+.-]*:|[\\/]{2})/i,dh=/^[\\/]{2}/;function Dg(t,s){return s+t.replace(/\\/g,"/")}var mf="popstate";function pf(t){return typeof t=="object"&&t!=null&&"pathname"in t&&"search"in t&&"hash"in t&&"state"in t&&"key"in t}function Ug(t={}){function s(o,c){var v;let u=(v=c.state)==null?void 0:v.masked,{pathname:f,search:g,hash:p}=u||o.location;return Ml("",{pathname:f,search:g,hash:p},c.state&&c.state.usr||null,c.state&&c.state.key||"default",u?{pathname:o.location.pathname,search:o.location.search,hash:o.location.hash}:void 0)}function a(o,c){return typeof c=="string"?c:br(c)}return Hg(s,a,null,t)}function at(t,s){if(t===!1||t===null||typeof t>"u")throw new Error(s)}function rn(t,s){if(!t){typeof console<"u"&&console.warn(s);try{throw new Error(s)}catch{}}}function Wg(){return Math.random().toString(36).substring(2,10)}function gf(t,s){return{usr:t.state,key:t.key,idx:s,masked:t.mask?{pathname:t.pathname,search:t.search,hash:t.hash}:void 0}}function Ml(t,s,a=null,o,c){return{pathname:typeof t=="string"?t:t.pathname,search:"",hash:"",...typeof s=="string"?es(s):s,state:a,key:s&&s.key||o||Wg(),mask:c}}function br({pathname:t="/",search:s="",hash:a=""}){return s&&s!=="?"&&(t+=s.charAt(0)==="?"?s:"?"+s),a&&a!=="#"&&(t+=a.charAt(0)==="#"?a:"#"+a),t}function es(t){let s={};if(t){let a=t.indexOf("#");a>=0&&(s.hash=t.substring(a),t=t.substring(0,a));let o=t.indexOf("?");o>=0&&(s.search=t.substring(o),t=t.substring(0,o)),t&&(s.pathname=t)}return s}function Hg(t,s,a,o={}){let{window:c=document.defaultView,v5Compat:u=!1}=o,f=c.history,g="POP",p=null,v=y();v==null&&(v=0,f.replaceState({...f.state,idx:v},""));function y(){return(f.state||{idx:null}).idx}function w(){g="POP";let k=y(),T=k==null?null:k-v;v=k,p&&p({action:g,location:S.location,delta:T})}function j(k,T){g="PUSH";let R=pf(k)?k:Ml(S.location,k,T);v=y()+1;let P=gf(R,v),A=S.createHref(R.mask||R);try{f.pushState(P,"",A)}catch(B){if(B instanceof DOMException&&B.name==="DataCloneError")throw B;c.location.assign(A)}u&&p&&p({action:g,location:S.location,delta:1})}function N(k,T){g="REPLACE";let R=pf(k)?k:Ml(S.location,k,T);v=y();let P=gf(R,v),A=S.createHref(R.mask||R);f.replaceState(P,"",A),u&&p&&p({action:g,location:S.location,delta:0})}function b(k){return Vg(c,k)}let S={get action(){return g},get location(){return t(c,f)},listen(k){if(p)throw new Error("A history only accepts one active listener");return c.addEventListener(mf,w),p=k,()=>{c.removeEventListener(mf,w),p=null}},createHref(k){return s(c,k)},createURL:b,encodeLocation(k){let T=b(k);return{pathname:T.pathname,search:T.search,hash:T.hash}},push:j,replace:N,go(k){return f.go(k)}};return S}function Vg(t,s,a=!1){let o="http://localhost";t&&(o=t.location.origin!=="null"?t.location.origin:t.location.href),at(o,"No window.location.(origin|href) available to create URL");let c=typeof s=="string"?s:br(s);return c=c.replace(/ $/,"%20"),!a&&dh.test(c)&&(c=o+c),new URL(c,o)}function fh(t,s,a="/"){return Gg(t,s,a,!1)}function Gg(t,s,a,o,c){let u=typeof s=="string"?es(s):s,f=_n(u.pathname||"/",a);if(f==null)return null;let g=Kg(t),p=null,v=sy(f);for(let y=0;p==null&&y<g.length;++y)p=ry(g[y],v,o);return p}function Kg(t){let s=hh(t);return qg(s),s}function hh(t,s=[],a=[],o="",c=!1){let u=(f,g,p=c,v)=>{let y={relativePath:v===void 0?f.path||"":v,caseSensitive:f.caseSensitive===!0,childrenIndex:g,route:f};if(y.relativePath.startsWith("/")){if(!y.relativePath.startsWith(o)&&p)return;at(y.relativePath.startsWith(o),`Absolute route path "${y.relativePath}" nested under path "${o}" is not valid. An absolute child route path must start with the combined path of all its parent routes.`),y.relativePath=y.relativePath.slice(o.length)}let w=fn([o,y.relativePath]),j=a.concat(y);f.children&&f.children.length>0&&(at(f.index!==!0,`Index routes must not have child routes. Please remove all child routes from route path "${w}".`),hh(f.children,s,j,w,p)),!(f.path==null&&!f.index)&&s.push({path:w,score:ty(w,f.index),routesMeta:j.map((N,b)=>{let[S,k]=gh(N.relativePath,N.caseSensitive,b===j.length-1);return{...N,matcher:S,compiledParams:k}})})};return t.forEach((f,g)=>{var p;if(f.path===""||!((p=f.path)!=null&&p.includes("?")))u(f,g);else for(let v of mh(f.path))u(f,g,!0,v)}),s}function mh(t){let s=t.split("/");if(s.length===0)return[];let[a,...o]=s,c=a.endsWith("?"),u=a.replace(/\?$/,"");if(o.length===0)return c?[u,""]:[u];let f=mh(o.join("/")),g=[];return g.push(...f.map(p=>p===""?u:[u,p].join("/"))),c&&g.push(...f),g.map(p=>t.startsWith("/")&&p===""?"/":p)}function qg(t){t.sort((s,a)=>s.score!==a.score?a.score-s.score:ny(s.routesMeta.map(o=>o.childrenIndex),a.routesMeta.map(o=>o.childrenIndex)))}var Yg=/^:[\w-]+$/,Jg=3,Qg=2,Xg=1,Zg=10,ey=-2,yf=t=>t==="*";function ty(t,s){let a=t.split("/"),o=a.length;return a.some(yf)&&(o+=ey),s&&(o+=Qg),a.filter(c=>!yf(c)).reduce((c,u)=>c+(Yg.test(u)?Jg:u===""?Xg:Zg),o)}function ny(t,s){return t.length===s.length&&t.slice(0,-1).every((o,c)=>o===s[c])?t[t.length-1]-s[s.length-1]:0}function ry(t,s,a=!1){let{routesMeta:o}=t,c={},u="/",f=[];for(let g=0;g<o.length;++g){let p=o[g],v=g===o.length-1,y=u==="/"?s:s.slice(u.length)||"/",w={path:p.relativePath,caseSensitive:p.caseSensitive,end:v},j=p.matcher&&p.compiledParams?ph(w,y,p.matcher,p.compiledParams):ji(w,y),N=p.route;if(!j&&v&&a&&!o[o.length-1].route.index&&(j=ji({path:p.relativePath,caseSensitive:p.caseSensitive,end:!1},y)),!j)return null;Object.assign(c,j.params),f.push({params:c,pathname:fn([u,j.pathname]),pathnameBase:oy(fn([u,j.pathnameBase])),route:N}),j.pathnameBase!=="/"&&(u=fn([u,j.pathnameBase]))}return f}function ji(t,s){typeof t=="string"&&(t={path:t,caseSensitive:!1,end:!0});let[a,o]=gh(t.path,t.caseSensitive,t.end);return ph(t,s,a,o)}function ph(t,s,a,o){let c=s.match(a);if(!c)return null;let u=c[0],f=Xr(u,1),g=c.slice(1);return{params:o.reduce((v,{paramName:y,isOptional:w},j)=>{if(y==="*"){let b=g[j]||"";f=Xr(u.slice(0,u.length-b.length),1)}const N=g[j];return w&&!N?v[y]=void 0:v[y]=(N||"").replace(/%2F/g,"/"),v},{}),pathname:u,pathnameBase:f,pattern:t}}function gh(t,s=!1,a=!0){rn(t==="*"||!t.endsWith("*")||t.endsWith("/*"),`Route path "${t}" will be treated as if it were "${t.replace(/\*$/,"/*")}" because the \`*\` character must always follow a \`/\` in the pattern. To get rid of this warning, please change the route path to "${t.replace(/\*$/,"/*")}".`);let o=[],c="^"+t.replace(/\/*\*?$/,"").replace(/^\/*/,"/").replace(/[\\.*+^${}|()[\]]/g,"\\$&").replace(/\/:([\w-]+)(\?)?/g,(f,g,p,v,y)=>{if(o.push({paramName:g,isOptional:p!=null}),p){let w=y.charAt(v+f.length);return w&&w!=="/"?"/([^\\/]*)":"(?:/([^\\/]*))?"}return"/([^\\/]+)"}).replace(/\/([\w-]+)\?(\/|$)/g,"(/$1)?$2");return t.endsWith("*")?(o.push({paramName:"*"}),c+=t==="*"||t==="/*"?"(.*)$":"(?:\\/(.+)|\\/*)$"):a?c+="\\/*$":t!==""&&t!=="/"&&(c+="(?:(?=\\/|$))"),[new RegExp(c,s?void 0:"i"),o]}function sy(t){try{return t.split("/").map(s=>decodeURIComponent(s).replace(/\//g,"%2F")).join("/")}catch(s){return rn(!1,`The URL path "${t}" could not be decoded because it is a malformed URL segment. This is probably due to a bad percent encoding (${s}).`),t}}function _n(t,s){if(s==="/")return t;if(!t.toLowerCase().startsWith(s.toLowerCase()))return null;let a=s.endsWith("/")?s.length-1:s.length,o=t.charAt(a);return o&&o!=="/"?null:t.slice(a)||"/"}function ay(t,s="/"){let{pathname:a,search:o="",hash:c=""}=typeof t=="string"?es(t):t,u;return a?(a=yh(a),a.startsWith("/")||a.startsWith("\\")?u=vf(a.substring(1),"/"):u=vf(a,s)):u=s,{pathname:u,search:ly(o),hash:cy(c)}}function vf(t,s){let a=Xr(s).split("/");return t.split("/").forEach(c=>{c===".."?a.length>1&&a.pop():c!=="."&&a.push(c)}),a.length>1?a.join("/"):"/"}function El(t,s,a,o){return`Cannot include a '${t}' character in a manually specified \`to.${s}\` field [${JSON.stringify(o)}]. Please separate it out to the \`to.${a}\` field. Alternatively you may provide the full path as a string in <Link to="..."> and the router will parse it for you.`}function iy(t){return t.filter((s,a)=>a===0||s.route.path&&s.route.path.length>0)}function ec(t){let s=iy(t);return s.map((a,o)=>o===s.length-1?a.pathname:a.pathnameBase)}function Pi(t,s,a,o=!1){let c;typeof t=="string"?c=es(t):(c={...t},at(!c.pathname||!c.pathname.includes("?"),El("?","pathname","search",c)),at(!c.pathname||!c.pathname.includes("#"),El("#","pathname","hash",c)),at(!c.search||!c.search.includes("#"),El("#","search","hash",c)));let u=t===""||c.pathname==="",f=u?"/":c.pathname,g;if(f==null)g=a;else{let w=s.length-1;if(!o&&f.startsWith("..")){let j=f.split("/");for(;j[0]==="..";)j.shift(),w-=1;c.pathname=j.join("/")}g=w>=0?s[w]:"/"}let p=ay(c,g),v=f&&f!=="/"&&f.endsWith("/"),y=(u||f===".")&&a.endsWith("/");return!p.pathname.endsWith("/")&&(v||y)&&(p.pathname+="/"),p}var yh=t=>t.replace(/[\\/]{2,}/g,"/"),fn=t=>yh(t.join("/"));function Xr(t,s=0){let a=t.length;for(;a>s&&t.charCodeAt(a-1)===47;)a--;return a===t.length?t:t.slice(0,a)}var oy=t=>Xr(t).replace(/^\/*/,"/"),ly=t=>!t||t==="?"?"":t.startsWith("?")?t:"?"+t,cy=t=>!t||t==="#"?"":t.startsWith("#")?t:"#"+t,uy=class{constructor(t,s,a,o=!1){this.status=t,this.statusText=s||"",this.internal=o,a instanceof Error?(this.data=a.toString(),this.error=a):this.data=a}};function dy(t){return t!=null&&typeof t.status=="number"&&typeof t.statusText=="string"&&typeof t.internal=="boolean"&&"data"in t}function fy(t){let s=t.map(a=>a.route.path).filter(Boolean);return fn(s)||"/"}var vh=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function xh(t,s){let a=t;if(typeof a!="string"||!Zl.test(a))return{absoluteURL:void 0,isExternal:!1,to:a};let o=a,c=!1;if(vh)try{let u=new URL(window.location.href),f=dh.test(a)?new URL(Dg(a,u.protocol)):new URL(a),g=_n(f.pathname,s);f.origin===u.origin&&g!=null?a=g+f.search+f.hash:c=!0}catch{rn(!1,`<Link to="${a}"> contains an invalid URL which will probably break when clicked - please update to a valid URL path.`)}return{absoluteURL:o,isExternal:c,to:a}}Object.getOwnPropertyNames(Object.prototype).sort().join("\0");var xf=new URL("http://localhost");function tc(t){if(t.createURL)return t.createURL("/");try{return new URL(t.createHref("/"),xf)}catch{return xf}}function Tl(t,s){return t.origin===s.origin&&(t.origin!=="null"||t.protocol===s.protocol&&t.host===s.host)}function hy(t,s){if(t.startsWith("//"))return!0;let a=s.protocol.toLowerCase();return t.toLowerCase().startsWith(a)?s.host===""||t.slice(a.length).startsWith("//"):!1}function nc(t,s,a,o){let c=null;try{c=t==null?null:new URL(t,a)}catch{}let u=new URL(s,a),f=c!=null&&!Tl(c,a),g=!Tl(u,a);if(o==="reject"){if(f||g)throw new Error("External navigation is not allowed")}else if(g&&(c==null||!hy(t,c)||!Tl(c,u)))throw new Error("External navigation is not allowed")}var wh=["POST","PUT","PATCH","DELETE"];new Set(wh);var my=["GET",...wh];new Set(my);var py=["about:","blob:","chrome:","chrome-untrusted:","content:","data:","devtools:","file:","filesystem:","javascript:"];function gy(t){try{return py.includes(new URL(t).protocol)}catch{return!1}}var ts=h.createContext(null);ts.displayName="DataRouter";var _i=h.createContext(null);_i.displayName="DataRouterState";var jh=h.createContext(!1);function yy(){return h.useContext(jh)}var Sh=h.createContext({isTransitioning:!1});Sh.displayName="ViewTransition";var vy=h.createContext(new Map);vy.displayName="Fetchers";var xy=h.createContext(null);xy.displayName="Await";var Yt=h.createContext(null);Yt.displayName="Navigation";var ea=h.createContext(null);ea.displayName="Location";var hn=h.createContext({outlet:null,matches:[],isDataRoute:!1});hn.displayName="Route";var rc=h.createContext(null);rc.displayName="RouteError";var bh="REACT_ROUTER_ERROR",wy="REDIRECT",jy="ROUTE_ERROR_RESPONSE";function Sy(t){if(t.startsWith(`${bh}:${wy}:{`))try{let s=JSON.parse(t.slice(28));if(typeof s=="object"&&s&&typeof s.status=="number"&&typeof s.statusText=="string"&&typeof s.location=="string"&&typeof s.reloadDocument=="boolean"&&typeof s.replace=="boolean")return s}catch{}}function by(t){if(t.startsWith(`${bh}:${jy}:{`))try{let s=JSON.parse(t.slice(40));if(typeof s=="object"&&s&&typeof s.status=="number"&&typeof s.statusText=="string")return new uy(s.status,s.statusText,s.data)}catch{}}function ky(t,{relative:s}={}){at(ns(),"useHref() may be used only in the context of a <Router> component.");let{basename:a,navigator:o}=h.useContext(Yt),{hash:c,pathname:u,search:f}=ta(t,{relative:s}),g=u;return a!=="/"&&(g=u==="/"?a:fn([a,u])),o.createHref({pathname:g,search:f,hash:c})}function ns(){return h.useContext(ea)!=null}function Ut(){return at(ns(),"useLocation() may be used only in the context of a <Router> component."),h.useContext(ea).location}var kh="You should call navigate() in a React.useEffect(), not when your component is first rendered.";function Nh(t){h.useContext(Yt).static||h.useLayoutEffect(t)}function mn(){let{isDataRoute:t}=h.useContext(hn);return t?My():Ny()}function Ny(){at(ns(),"useNavigate() may be used only in the context of a <Router> component.");let t=h.useContext(ts),{basename:s,navigator:a}=h.useContext(Yt),{matches:o}=h.useContext(hn),{pathname:c}=Ut(),u=JSON.stringify(ec(o)),f=h.useRef(!1);return Nh(()=>{f.current=!0}),h.useCallback((p,v={})=>{if(rn(f.current,kh),!f.current)return;if(typeof p=="number"){a.go(p);return}let y=Pi(p,JSON.parse(u),c,v.relative==="path");t==null&&s!=="/"&&(y.pathname=y.pathname==="/"?s:fn([s,y.pathname])),nc(typeof p=="string"?p:br(p),a.createHref(y),tc(a),"reject"),(v.replace?a.replace:a.push)(y,v.state,v)},[s,a,u,c,t])}var Cy=h.createContext(null);function Ey(t){let s=h.useContext(hn).outlet;return h.useMemo(()=>s&&h.createElement(Cy.Provider,{value:t},s),[s,t])}function ta(t,{relative:s}={}){let{matches:a}=h.useContext(hn),{pathname:o}=Ut(),c=JSON.stringify(ec(a));return h.useMemo(()=>Pi(t,JSON.parse(c),o,s==="path"),[t,c,o,s])}function Ty(t,s){return Ch(t,s)}function Ch(t,s,a){var k;at(ns(),"useRoutes() may be used only in the context of a <Router> component.");let{navigator:o}=h.useContext(Yt),{matches:c}=h.useContext(hn),u=c[c.length-1],f=u?u.params:{},g=u?u.pathname:"/",p=u?u.pathnameBase:"/",v=u&&u.route;{let T=v&&v.path||"";Th(g,!v||T.endsWith("*")||T.endsWith("*?"),`You rendered descendant <Routes> (or called \`useRoutes()\`) at "${g}" (under <Route path="${T}">) but the parent route path has no trailing "*". This means if you navigate deeper, the parent won't match anymore and therefore the child routes will never render.
50
+
51
+ Please change the parent <Route path="${T}"> to <Route path="${T==="/"?"*":`${T}/*`}">.`)}let y=Ut(),w;if(s){let T=typeof s=="string"?es(s):s;at(p==="/"||((k=T.pathname)==null?void 0:k.startsWith(p)),`When overriding the location using \`<Routes location>\` or \`useRoutes(routes, location)\`, the location pathname must begin with the portion of the URL pathname that was matched by all parent routes. The current pathname base is "${p}" but pathname "${T.pathname}" was given in the \`location\` prop.`),w=T}else w=y;let j=w.pathname||"/",N=j;if(p!=="/"){let T=p.replace(/^\//,"").split("/");N="/"+j.replace(/^\//,"").split("/").slice(T.length).join("/")}let b=a&&a.state.matches.length?a.state.matches.map(T=>Object.assign(T,{route:a.manifest[T.route.id]||T.route})):fh(t,{pathname:N});rn(v||b!=null,`No routes matched location "${w.pathname}${w.search}${w.hash}" `),rn(b==null||b[b.length-1].route.element!==void 0||b[b.length-1].route.Component!==void 0||b[b.length-1].route.lazy!==void 0,`Matched leaf route at location "${w.pathname}${w.search}${w.hash}" does not have an element or Component. This means it will render an <Outlet /> with a null value by default resulting in an "empty" page.`);let S=_y(b&&b.map(T=>Object.assign({},T,{params:Object.assign({},f,T.params),pathname:fn([p,o.encodeLocation?o.encodeLocation(T.pathname.replace(/%/g,"%25").replace(/\?/g,"%3F").replace(/#/g,"%23")).pathname:T.pathname]),pathnameBase:T.pathnameBase==="/"?p:fn([p,o.encodeLocation?o.encodeLocation(T.pathnameBase.replace(/%/g,"%25").replace(/\?/g,"%3F").replace(/#/g,"%23")).pathname:T.pathnameBase])})),c,a);return s&&S?h.createElement(ea.Provider,{value:{location:{pathname:"/",search:"",hash:"",state:null,key:"default",mask:void 0,...w},navigationType:"POP"}},S):S}function Ry(){let t=Oy(),s=dy(t)?`${t.status} ${t.statusText}`:t instanceof Error?t.message:JSON.stringify(t),a=t instanceof Error?t.stack:null,o="rgba(200,200,200, 0.5)",c={padding:"0.5rem",backgroundColor:o},u={padding:"2px 4px",backgroundColor:o},f=null;return console.error("Error handled by React Router default ErrorBoundary:",t),f=h.createElement(h.Fragment,null,h.createElement("p",null,"💿 Hey developer 👋"),h.createElement("p",null,"You can provide a way better UX than this when your app throws errors by providing your own ",h.createElement("code",{style:u},"ErrorBoundary")," or"," ",h.createElement("code",{style:u},"errorElement")," prop on your route.")),h.createElement(h.Fragment,null,h.createElement("h2",null,"Unexpected Application Error!"),h.createElement("h3",{style:{fontStyle:"italic"}},s),a?h.createElement("pre",{style:c},a):null,f)}var Ay=h.createElement(Ry,null),Eh=class extends h.Component{constructor(t){super(t),this.state={location:t.location,revalidation:t.revalidation,error:t.error}}static getDerivedStateFromError(t){return{error:t}}static getDerivedStateFromProps(t,s){return s.location!==t.location||s.revalidation!=="idle"&&t.revalidation==="idle"?{error:t.error,location:t.location,revalidation:t.revalidation}:{error:t.error!==void 0?t.error:s.error,location:s.location,revalidation:t.revalidation||s.revalidation}}componentDidCatch(t,s){this.props.onError?this.props.onError(t,s):console.error("React Router caught the following error during render",t)}render(){let t=this.state.error;if(this.context&&typeof t=="object"&&t&&"digest"in t&&typeof t.digest=="string"){const a=by(t.digest);a&&(t=a)}let s=t!==void 0?h.createElement(hn.Provider,{value:this.props.routeContext},h.createElement(rc.Provider,{value:t,children:this.props.component})):this.props.children;return this.context?h.createElement(Iy,{error:t},s):s}};Eh.contextType=jh;var Rl=new WeakMap;function Iy({children:t,error:s}){let{basename:a,navigator:o}=h.useContext(Yt);if(typeof s=="object"&&s&&"digest"in s&&typeof s.digest=="string"){let c=Sy(s.digest);if(c){let u=Rl.get(s);if(u)throw u;let f=xh(c.location,a),g=f.absoluteURL||f.to;if(nc(c.location,g,tc(o),"allow-explicit"),gy(g))throw new Error("Invalid redirect location");if(vh&&!Rl.get(s))if(f.isExternal||c.reloadDocument)window.location.href=g;else{const p=Promise.resolve().then(()=>window.__reactRouterDataRouter.navigate(f.to,{replace:c.replace}));throw Rl.set(s,p),p}return h.createElement("meta",{httpEquiv:"refresh",content:`0;url=${g}`})}}return t}function Py({routeContext:t,match:s,children:a}){let o=h.useContext(ts);return o&&o.static&&o.staticContext&&(s.route.errorElement||s.route.ErrorBoundary)&&(o.staticContext._deepestRenderedBoundaryId=s.route.id),h.createElement(hn.Provider,{value:t},a)}function _y(t,s=[],a){let o=a==null?void 0:a.state;if(t==null){if(!o)return null;if(o.errors)t=o.matches;else if(s.length===0&&!o.initialized&&o.matches.length>0)t=o.matches;else return null}let c=t,u=o==null?void 0:o.errors;if(u!=null){let y=c.findIndex(w=>w.route.id&&(u==null?void 0:u[w.route.id])!==void 0);at(y>=0,`Could not find a matching route for errors on route IDs: ${Object.keys(u).join(",")}`),c=c.slice(0,Math.min(c.length,y+1))}let f=!1,g=-1;if(a&&o){f=o.renderFallback;for(let y=0;y<c.length;y++){let w=c[y];if((w.route.HydrateFallback||w.route.hydrateFallbackElement)&&(g=y),w.route.id){let{loaderData:j,errors:N}=o,b=w.route.loader&&!j.hasOwnProperty(w.route.id)&&(!N||N[w.route.id]===void 0);if(w.route.lazy||b){a.isStatic&&(f=!0),g>=0?c=c.slice(0,g+1):c=[c[0]];break}}}}let p=a==null?void 0:a.onError,v=o&&p?(y,w)=>{var j,N;p(y,{location:o.location,params:((N=(j=o.matches)==null?void 0:j[0])==null?void 0:N.params)??{},pattern:fy(o.matches),errorInfo:w})}:void 0;return c.reduceRight((y,w,j)=>{let N,b=!1,S=null,k=null;o&&(N=u&&w.route.id?u[w.route.id]:void 0,S=w.route.errorElement||Ay,f&&(g<0&&j===0?(Th("route-fallback",!1,"No `HydrateFallback` element provided to render during initial hydration"),b=!0,k=null):g===j&&(b=!0,k=w.route.hydrateFallbackElement||null)));let T=s.concat(c.slice(0,j+1)),R=()=>{let P;return N?P=S:b?P=k:w.route.Component?P=h.createElement(w.route.Component,null):w.route.element?P=w.route.element:P=y,h.createElement(Py,{match:w,routeContext:{outlet:y,matches:T,isDataRoute:o!=null},children:P})};return o&&(w.route.ErrorBoundary||w.route.errorElement||j===0)?h.createElement(Eh,{location:o.location,revalidation:o.revalidation,component:S,error:N,children:R(),routeContext:{outlet:null,matches:T,isDataRoute:!0},onError:v}):R()},null)}function sc(t){return`${t} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function $y(t){let s=h.useContext(ts);return at(s,sc(t)),s}function Ly(t){let s=h.useContext(_i);return at(s,sc(t)),s}function zy(t){let s=h.useContext(hn);return at(s,sc(t)),s}function ac(t){let s=zy(t),a=s.matches[s.matches.length-1];return at(a.route.id,`${t} can only be used on routes that contain a unique "id"`),a.route.id}function Fy(){return ac("useRouteId")}function Oy(){var o;let t=h.useContext(rc),s=Ly("useRouteError"),a=ac("useRouteError");return t!==void 0?t:(o=s.errors)==null?void 0:o[a]}function My(){let{router:t}=$y("useNavigate"),s=ac("useNavigate"),a=h.useRef(!1);return Nh(()=>{a.current=!0}),h.useCallback(async(c,u={})=>{rn(a.current,kh),a.current&&(typeof c=="number"?await t.navigate(c):await t.navigate(c,{fromRouteId:s,...u}))},[t,s])}var wf={};function Th(t,s,a){!s&&!wf[t]&&(wf[t]=!0,rn(!1,a))}h.memo(By);function By({routes:t,manifest:s,future:a,state:o,isStatic:c,onError:u}){return Ch(t,void 0,{manifest:s,state:o,isStatic:c,onError:u})}function Pn({to:t,replace:s,state:a,relative:o}){at(ns(),"<Navigate> may be used only in the context of a <Router> component.");let{static:c,navigator:u}=h.useContext(Yt);rn(!c,"<Navigate> must not be used on the initial render in a <StaticRouter>. This is a no-op, but you should modify your code so the <Navigate> is only ever rendered in response to some user interaction or state change.");let{matches:f}=h.useContext(hn),{pathname:g}=Ut(),p=mn(),v=Pi(t,ec(f),g,o==="path");nc(typeof t=="string"?t:br(t),u.createHref(v),tc(u),"reject");let y=JSON.stringify(v);return h.useEffect(()=>{p(JSON.parse(y),{replace:s,state:a,relative:o})},[p,y,o,s,a]),null}function Dy(t){return Ey(t.context)}function et(t){at(!1,"A <Route> is only ever to be used as the child of <Routes> element, never rendered directly. Please wrap your <Route> in a <Routes>.")}function Uy({basename:t="/",children:s=null,location:a,navigationType:o="POP",navigator:c,static:u=!1,useTransitions:f}){at(!ns(),"You cannot render a <Router> inside another <Router>. You should never have more than one in your app.");let g=t.replace(/^\/*/,"/"),p=h.useMemo(()=>({basename:g,navigator:c,static:u,useTransitions:f,future:{}}),[g,c,u,f]);typeof a=="string"&&(a=es(a));let{pathname:v="/",search:y="",hash:w="",state:j=null,key:N="default",mask:b}=a,S=h.useMemo(()=>{let k=_n(v,g);return k==null?null:{location:{pathname:k,search:y,hash:w,state:j,key:N,mask:b},navigationType:o}},[g,v,y,w,j,N,o,b]);return rn(S!=null,`<Router basename="${g}"> is not able to match the URL "${v}${y}${w}" because it does not start with the basename, so the <Router> won't render anything.`),S==null?null:h.createElement(Yt.Provider,{value:p},h.createElement(ea.Provider,{children:s,value:S}))}function Wy({children:t,location:s}){return Ty(Bl(t),s)}function Bl(t,s=[]){let a=[];return h.Children.forEach(t,(o,c)=>{if(!h.isValidElement(o))return;let u=[...s,c];if(o.type===h.Fragment){a.push.apply(a,Bl(o.props.children,u));return}at(o.type===et,`[${typeof o.type=="string"?o.type:o.type.name}] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>`),at(!o.props.index||!o.props.children,"An index route cannot have child routes.");let f={id:o.props.id||u.join("-"),caseSensitive:o.props.caseSensitive,element:o.props.element,Component:o.props.Component,index:o.props.index,path:o.props.path,middleware:o.props.middleware,loader:o.props.loader,action:o.props.action,hydrateFallbackElement:o.props.hydrateFallbackElement,HydrateFallback:o.props.HydrateFallback,errorElement:o.props.errorElement,ErrorBoundary:o.props.ErrorBoundary,hasErrorBoundary:o.props.hasErrorBoundary===!0||o.props.ErrorBoundary!=null||o.props.errorElement!=null,shouldRevalidate:o.props.shouldRevalidate,handle:o.props.handle,lazy:o.props.lazy};o.props.children&&(f.children=Bl(o.props.children,u)),a.push(f)}),a}var gi="get",yi="application/x-www-form-urlencoded";function $i(t){return typeof HTMLElement<"u"&&t instanceof HTMLElement}function Hy(t){return $i(t)&&t.tagName.toLowerCase()==="button"}function Vy(t){return $i(t)&&t.tagName.toLowerCase()==="form"}function Gy(t){return $i(t)&&t.tagName.toLowerCase()==="input"}function Ky(t){return!!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey)}function qy(t,s){return t.button===0&&(!s||s==="_self")&&!Ky(t)}function Dl(t=""){return new URLSearchParams(typeof t=="string"||Array.isArray(t)||t instanceof URLSearchParams?t:Object.keys(t).reduce((s,a)=>{let o=t[a];return s.concat(Array.isArray(o)?o.map(c=>[a,c]):[[a,o]])},[]))}function Yy(t,s){let a=Dl(t);return s&&s.forEach((o,c)=>{a.has(c)||s.getAll(c).forEach(u=>{a.append(c,u)})}),a}var ui=null;function Jy(){if(ui===null)try{new FormData(document.createElement("form"),0),ui=!1}catch{ui=!0}return ui}var Qy=new Set(["application/x-www-form-urlencoded","multipart/form-data","text/plain"]);function Al(t){return t!=null&&!Qy.has(t)?(rn(!1,`"${t}" is not a valid \`encType\` for \`<Form>\`/\`<fetcher.Form>\` and will default to "${yi}"`),null):t}function Xy(t,s){let a,o,c,u,f;if(Vy(t)){let g=t.getAttribute("action");o=g?_n(g,s):null,a=t.getAttribute("method")||gi,c=Al(t.getAttribute("enctype"))||yi,u=new FormData(t)}else if(Hy(t)||Gy(t)&&(t.type==="submit"||t.type==="image")){let g=t.form;if(g==null)throw new Error('Cannot submit a <button> or <input type="submit"> without a <form>');let p=t.getAttribute("formaction")||g.getAttribute("action");if(o=p?_n(p,s):null,a=t.getAttribute("formmethod")||g.getAttribute("method")||gi,c=Al(t.getAttribute("formenctype"))||Al(g.getAttribute("enctype"))||yi,u=new FormData(g,t),!Jy()){let{name:v,type:y,value:w}=t;if(y==="image"){let j=v?`${v}.`:"";u.append(`${j}x`,"0"),u.append(`${j}y`,"0")}else v&&u.append(v,w)}}else{if($i(t))throw new Error('Cannot submit element that is not <form>, <button>, or <input type="submit|image">');a=gi,o=null,c=yi,f=t}return u&&c==="text/plain"&&(f=u,u=void 0),{action:o,method:a.toLowerCase(),encType:c,formData:u,body:f}}Object.getOwnPropertyNames(Object.prototype).sort().join("\0");function ic(t,s){if(t===!1||t===null||typeof t>"u")throw new Error(s)}function Rh(t,s,a,o){let c=typeof t=="string"?new URL(t,typeof window>"u"?"server://singlefetch/":window.location.origin):t;return a?c.pathname.endsWith("/")?c.pathname=`${c.pathname}_.${o}`:c.pathname=`${c.pathname}.${o}`:c.pathname==="/"?c.pathname=`_root.${o}`:s&&_n(c.pathname,s)==="/"?c.pathname=`${Xr(s)}/_root.${o}`:c.pathname=`${Xr(c.pathname)}.${o}`,c}async function Zy(t,s){if(t.id in s)return s[t.id];try{let a=await import(t.module);return s[t.id]=a,a}catch(a){return console.error(`Error loading route module \`${t.module}\`, reloading page...`),console.error(a),window.__reactRouterContext&&window.__reactRouterContext.isSpaMode,window.location.reload(),new Promise(()=>{})}}function ev(t){return t==null?!1:t.href==null?t.rel==="preload"&&typeof t.imageSrcSet=="string"&&typeof t.imageSizes=="string":typeof t.rel=="string"&&typeof t.href=="string"}async function tv(t,s,a){let o=await Promise.all(t.map(async c=>{let u=s.routes[c.route.id];if(u){let f=await Zy(u,a);return f.links?f.links():[]}return[]}));return av(o.flat(1).filter(ev).filter(c=>c.rel==="stylesheet"||c.rel==="preload").map(c=>c.rel==="stylesheet"?{...c,rel:"prefetch",as:"style"}:{...c,rel:"prefetch"}))}function jf(t,s,a,o,c,u){let f=(p,v)=>a[v]?p.route.id!==a[v].route.id:!0,g=(p,v)=>{var y;return a[v].pathname!==p.pathname||((y=a[v].route.path)==null?void 0:y.endsWith("*"))&&a[v].params["*"]!==p.params["*"]};return u==="assets"?s.filter((p,v)=>f(p,v)||g(p,v)):u==="data"?s.filter((p,v)=>{var w;let y=o.routes[p.route.id];if(!y||!y.hasLoader)return!1;if(f(p,v)||g(p,v))return!0;if(p.route.shouldRevalidate){let j=p.route.shouldRevalidate({currentUrl:new URL(c.pathname+c.search+c.hash,window.origin),currentParams:((w=a[0])==null?void 0:w.params)||{},nextUrl:new URL(t,window.origin),nextParams:p.params,defaultShouldRevalidate:!0});if(typeof j=="boolean")return j}return!0}):[]}function nv(t,s,{includeHydrateFallback:a}={}){return rv(t.map(o=>{let c=s.routes[o.route.id];if(!c)return[];let u=[c.module];return c.clientActionModule&&(u=u.concat(c.clientActionModule)),c.clientLoaderModule&&(u=u.concat(c.clientLoaderModule)),a&&c.hydrateFallbackModule&&(u=u.concat(c.hydrateFallbackModule)),c.imports&&(u=u.concat(c.imports)),u}).flat(1))}function rv(t){return[...new Set(t)]}function sv(t){let s={},a=Object.keys(t).sort();for(let o of a)s[o]=t[o];return s}function av(t,s){let a=new Set;return new Set(s),t.reduce((o,c)=>{let u=JSON.stringify(sv(c));return a.has(u)||(a.add(u),o.push({key:u,link:c})),o},[])}function oc(){let t=h.useContext(ts);return ic(t,"You must render this element inside a <DataRouterContext.Provider> element"),t}function iv(){let t=h.useContext(_i);return ic(t,"You must render this element inside a <DataRouterStateContext.Provider> element"),t}var lc=h.createContext(void 0);lc.displayName="FrameworkContext";function Li(){let t=h.useContext(lc);return ic(t,"You must render this element inside a <HydratedRouter> element"),t}function ov(t,s){let a=h.useContext(lc),[o,c]=h.useState(!1),[u,f]=h.useState(!1),{onFocus:g,onBlur:p,onMouseEnter:v,onMouseLeave:y,onTouchStart:w}=s,j=h.useRef(null);h.useEffect(()=>{if(t==="render"&&f(!0),t==="viewport"){let S=T=>{T.forEach(R=>{f(R.isIntersecting)})},k=new IntersectionObserver(S,{threshold:.5});return j.current&&k.observe(j.current),()=>{k.disconnect()}}},[t]),h.useEffect(()=>{if(o){let S=setTimeout(()=>{f(!0)},100);return()=>{clearTimeout(S)}}},[o]);let N=()=>{c(!0)},b=()=>{c(!1),f(!1)};return a?t!=="intent"?[u,j,{}]:[u,j,{onFocus:Us(g,N),onBlur:Us(p,b),onMouseEnter:Us(v,N),onMouseLeave:Us(y,b),onTouchStart:Us(w,N)}]:[!1,j,{}]}function Us(t,s){return a=>{t&&t(a),a.defaultPrevented||s(a)}}function lv({page:t,...s}){let a=yy(),{nonce:o}=Li(),{router:c}=oc(),u=h.useMemo(()=>fh(c.routes,t,c.basename),[c.routes,t,c.basename]);return u?(s.nonce==null&&o&&(s={...s,nonce:o}),a?h.createElement(uv,{page:t,matches:u,...s}):h.createElement(dv,{page:t,matches:u,...s})):null}function cv(t){let{manifest:s,routeModules:a}=Li(),[o,c]=h.useState([]);return h.useEffect(()=>{let u=!1;return tv(t,s,a).then(f=>{u||c(f)}),()=>{u=!0}},[t,s,a]),o}function uv({page:t,matches:s,...a}){let o=Ut(),{future:c}=Li(),{basename:u}=oc(),f=h.useMemo(()=>{if(t===o.pathname+o.search+o.hash)return[];let g=Rh(t,u,c.v8_trailingSlashAwareDataRequests,"rsc"),p=!1,v=[];for(let y of s)typeof y.route.shouldRevalidate=="function"?p=!0:v.push(y.route.id);return p&&v.length>0&&g.searchParams.set("_routes",v.join(",")),[g.pathname+g.search]},[u,c.v8_trailingSlashAwareDataRequests,t,o,s]);return h.createElement(h.Fragment,null,f.map(g=>h.createElement("link",{key:g,rel:"prefetch",as:"fetch",href:g,...a})))}function dv({page:t,matches:s,...a}){let o=Ut(),{future:c,manifest:u,routeModules:f}=Li(),{basename:g}=oc(),{loaderData:p,matches:v}=iv(),y=h.useMemo(()=>jf(t,s,v,u,o,"data"),[t,s,v,u,o]),w=h.useMemo(()=>jf(t,s,v,u,o,"assets"),[t,s,v,u,o]),j=h.useMemo(()=>{if(t===o.pathname+o.search+o.hash)return[];let S=new Set,k=!1;if(s.forEach(R=>{var A;let P=u.routes[R.route.id];!P||!P.hasLoader||(!y.some(B=>B.route.id===R.route.id)&&R.route.id in p&&((A=f[R.route.id])!=null&&A.shouldRevalidate)||P.hasClientLoader?k=!0:S.add(R.route.id))}),S.size===0)return[];let T=Rh(t,g,c.v8_trailingSlashAwareDataRequests,"data");return k&&S.size>0&&T.searchParams.set("_routes",s.filter(R=>S.has(R.route.id)).map(R=>R.route.id).join(",")),[T.pathname+T.search]},[g,c.v8_trailingSlashAwareDataRequests,p,o,u,y,s,t,f]),N=h.useMemo(()=>nv(w,u),[w,u]),b=cv(w);return h.createElement(h.Fragment,null,j.map(S=>h.createElement("link",{key:S,rel:"prefetch",as:"fetch",href:S,...a})),N.map(S=>h.createElement("link",{key:S,rel:"modulepreload",href:S,...a})),b.map(({key:S,link:k})=>h.createElement("link",{key:S,nonce:a.nonce,...k,crossOrigin:k.crossOrigin??a.crossOrigin})))}function fv(...t){return s=>{t.forEach(a=>{typeof a=="function"?a(s):a!=null&&(a.current=s)})}}var hv=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";try{hv&&(window.__reactRouterVersion="7.18.4")}catch{}function mv({basename:t,children:s,useTransitions:a,window:o}){let c=h.useRef();c.current==null&&(c.current=Ug({window:o,v5Compat:!0}));let u=c.current,[f,g]=h.useState({action:u.action,location:u.location}),p=h.useCallback(v=>{a===!1?g(v):h.startTransition(()=>g(v))},[a]);return h.useLayoutEffect(()=>u.listen(p),[u,p]),h.createElement(Uy,{basename:t,children:s,location:f.location,navigationType:f.action,navigator:u,useTransitions:a})}var xt=h.forwardRef(function({onClick:s,discover:a="render",prefetch:o="none",relative:c,reloadDocument:u,replace:f,mask:g,state:p,target:v,to:y,preventScrollReset:w,viewTransition:j,defaultShouldRevalidate:N,...b},S){let{basename:k,navigator:T,useTransitions:R}=h.useContext(Yt),P=typeof y=="string"&&Zl.test(y),A=xh(y,k);y=A.to;let B=ky(y,{relative:c}),H=Ut(),G=null;if(g){let se=Pi(g,[],H.mask?H.mask.pathname:"/",!0);k!=="/"&&(se.pathname=se.pathname==="/"?k:fn([k,se.pathname])),G=T.createHref(se)}let[me,q,ce]=ov(o,b),ee=yv(y,{replace:f,mask:g,state:p,target:v,preventScrollReset:w,relative:c,viewTransition:j,defaultShouldRevalidate:N,useTransitions:R});function F(se){s&&s(se),se.defaultPrevented||ee(se)}let re=!(A.isExternal||u),Y=h.createElement("a",{...b,...ce,href:(re?G:void 0)||A.absoluteURL||B,onClick:re?F:s,ref:fv(S,q),target:v,"data-discover":!P&&a==="render"?"true":void 0});return me&&!P?h.createElement(h.Fragment,null,Y,h.createElement(lv,{page:B})):Y});xt.displayName="Link";var cc=h.forwardRef(function({"aria-current":s="page",caseSensitive:a=!1,className:o="",end:c=!1,style:u,to:f,viewTransition:g,children:p,...v},y){let w=ta(f,{relative:v.relative}),j=Ut(),N=h.useContext(_i),{navigator:b,basename:S}=h.useContext(Yt),k=N!=null&&Sv(w)&&g===!0,T=b.encodeLocation?b.encodeLocation(w).pathname:w.pathname,R=j.pathname,P=N&&N.navigation&&N.navigation.location?N.navigation.location.pathname:null;a||(R=R.toLowerCase(),P=P?P.toLowerCase():null,T=T.toLowerCase()),P&&S&&(P=_n(P,S)||P);const A=T!=="/"&&T.endsWith("/")?T.length-1:T.length;let B=R===T||!c&&R.startsWith(T)&&R.charAt(A)==="/",H=P!=null&&(P===T||!c&&P.startsWith(T)&&P.charAt(T.length)==="/"),G={isActive:B,isPending:H,isTransitioning:k},me=B?s:void 0,q;typeof o=="function"?q=o(G):q=[o,B?"active":null,H?"pending":null,k?"transitioning":null].filter(Boolean).join(" ");let ce=typeof u=="function"?u(G):u;return h.createElement(xt,{...v,"aria-current":me,className:q,ref:y,style:ce,to:f,viewTransition:g},typeof p=="function"?p(G):p)});cc.displayName="NavLink";var pv=h.forwardRef(({discover:t="render",fetcherKey:s,navigate:a,reloadDocument:o,replace:c,state:u,method:f=gi,action:g,onSubmit:p,relative:v,preventScrollReset:y,viewTransition:w,defaultShouldRevalidate:j,...N},b)=>{let{useTransitions:S}=h.useContext(Yt),k=wv(),T=jv(g,{relative:v}),R=f.toLowerCase()==="get"?"get":"post",P=typeof g=="string"&&Zl.test(g),A=B=>{if(p&&p(B),B.defaultPrevented)return;B.preventDefault();let H=B.nativeEvent.submitter,G=(H==null?void 0:H.getAttribute("formmethod"))||f,me=()=>k(H||B.currentTarget,{fetcherKey:s,method:G,navigate:a,replace:c,state:u,relative:v,preventScrollReset:y,viewTransition:w,defaultShouldRevalidate:j});S&&a!==!1?h.startTransition(()=>me()):me()};return h.createElement("form",{ref:b,method:R,action:T,onSubmit:o?p:A,...N,"data-discover":!P&&t==="render"?"true":void 0})});pv.displayName="Form";function gv(t){return`${t} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function Ah(t){let s=h.useContext(ts);return at(s,gv(t)),s}function yv(t,{target:s,replace:a,mask:o,state:c,preventScrollReset:u,relative:f,viewTransition:g,defaultShouldRevalidate:p,useTransitions:v}={}){let y=mn(),w=Ut(),j=ta(t,{relative:f});return h.useCallback(N=>{if(qy(N,s)){N.preventDefault();let b=a!==void 0?a:br(w)===br(j),S=()=>y(t,{replace:b,mask:o,state:c,preventScrollReset:u,relative:f,viewTransition:g,defaultShouldRevalidate:p});v?h.startTransition(()=>S()):S()}},[w,y,j,a,o,c,s,t,u,f,g,p,v])}function uc(t){rn(typeof URLSearchParams<"u","You cannot use the `useSearchParams` hook in a browser that does not support the URLSearchParams API. If you need to support Internet Explorer 11, we recommend you load a polyfill such as https://github.com/ungap/url-search-params.");let s=h.useRef(Dl(t)),a=h.useRef(!1),o=Ut(),c=h.useMemo(()=>Yy(o.search,a.current?null:s.current),[o.search]),u=mn(),f=h.useCallback((g,p)=>{const v=Dl(typeof g=="function"?g(new URLSearchParams(c)):g);a.current=!0,u("?"+v,p)},[u,c]);return[c,f]}var vv=0,xv=()=>`__${String(++vv)}__`;function wv(){let{router:t}=Ah("useSubmit"),{basename:s}=h.useContext(Yt),a=Fy(),o=t.fetch,c=t.navigate;return h.useCallback(async(u,f={})=>{let{action:g,method:p,encType:v,formData:y,body:w}=Xy(u,s);if(f.navigate===!1){let j=f.fetcherKey||xv();await o(j,a,f.action||g,{defaultShouldRevalidate:f.defaultShouldRevalidate,preventScrollReset:f.preventScrollReset,formData:y,body:w,formMethod:f.method||p,formEncType:f.encType||v,flushSync:f.flushSync})}else await c(f.action||g,{defaultShouldRevalidate:f.defaultShouldRevalidate,preventScrollReset:f.preventScrollReset,formData:y,body:w,formMethod:f.method||p,formEncType:f.encType||v,replace:f.replace,state:f.state,fromRouteId:a,flushSync:f.flushSync,viewTransition:f.viewTransition})},[o,c,s,a])}function jv(t,{relative:s}={}){let{basename:a}=h.useContext(Yt),o=h.useContext(hn);at(o,"useFormAction must be used inside a RouteContext");let[c]=o.matches.slice(-1),u={...ta(t||".",{relative:s})},f=Ut();if(t==null){u.search=f.search;let g=new URLSearchParams(u.search),p=g.getAll("index");if(p.some(y=>y==="")){g.delete("index"),p.filter(w=>w).forEach(w=>g.append("index",w));let y=g.toString();u.search=y?`?${y}`:""}}return(!t||t===".")&&c.route.index&&(u.search=u.search?u.search.replace(/^\?/,"?index&"):"?index"),a!=="/"&&(u.pathname=u.pathname==="/"?a:fn([a,u.pathname])),br(u)}function Sv(t,{relative:s}={}){let a=h.useContext(Sh);at(a!=null,"`useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. Did you accidentally import `RouterProvider` from `react-router`?");let{basename:o}=Ah("useViewTransitionState"),c=ta(t,{relative:s});if(!a.isTransitioning)return!1;let u=_n(a.currentLocation.pathname,o)||a.currentLocation.pathname,f=_n(a.nextLocation.pathname,o)||a.nextLocation.pathname;return ji(c.pathname,f)!=null||ji(c.pathname,u)!=null}var bv=uh();const wr="owner";function kv(t){const s=t||wr;return s===wr?[wr]:[s,wr]}function Nv(t){const s=new Map;for(const a of t)for(const o of a)s.has(o.id)||s.set(o.id,o);return[...s.values()].sort((a,o)=>o.createdAt-a.createdAt)}function Cv(t,s){const a=s||wr,o=(t==null?void 0:t.pendingDomains)??[];return o.includes(a)?a:o.includes(wr)?wr:a}class Ih extends Error{constructor(a){super("different_account");Bs(this,"summary");this.name="DifferentAccountError",this.summary=a}}function Ph(t){return t.grantors??t.approvers}function Ev(t){return t.approvals??1}function We(t,s){const a=t??{},o=Array.isArray(a.errors)?a.errors[0]:void 0;return o!=null&&o.message?o.code?`${o.message} (${o.code})`:o.message:o!=null&&o.code?o.code:a.error||a.detail||s}function Tv(t){const s=t==null?void 0:t.pubkeys;return!s||typeof s!="object"||Array.isArray(s)?[]:Object.entries(s).filter(a=>typeof a[1]=="string"&&a[1].length>0).map(([a,o])=>({userId:a,publicKey:o}))}class Rv{constructor(){Bs(this,"apiKey",null)}setApiKey(s){this.apiKey=s}clearApiKey(){this.apiKey=null}getApiKey(){return this.apiKey}async fetch(s,a){return globalThis.fetch(s,{...a,headers:{"Content-Type":"application/json",...this.apiKey?{"X-API-Key":this.apiKey}:{},...a==null?void 0:a.headers}})}async login(s,a={}){const o=await this.fetch("/auth/login",{method:"POST",headers:{"X-API-Key":s,"Content-Type":"application/json"},body:JSON.stringify({confirmWipe:a.confirmWipe===!0})});if(o.status===409){const u=await o.json().catch(()=>({}));if(u!=null&&u.wouldWipe)throw new Ih(u.summary??{credentialCount:0,serviceCount:0,credentialIds:[]})}if(!o.ok){const u=await o.json().catch(()=>({error:"Invalid API key"}));throw new Error(We(u,`Login failed: ${o.status}`))}return(await o.json()).user}async logout(){await this.fetch("/auth/logout",{method:"POST"})}async getGroups(){const s=await this.fetch("/api/groups");if(!s.ok)throw new Error(`Failed to fetch groups: ${s.status}`);const a=await s.json();return a.groups??a}async listProfiles(){const s=await this.fetch("/api/profiles");if(!s.ok)throw new Error(`Failed to fetch profiles: ${s.status}`);return(await s.json()).profiles}async getProfile(s){const a=await this.fetch(`/api/profiles/${encodeURIComponent(s)}`);if(!a.ok)throw new Error(`Failed to fetch profile: ${a.status}`);return a.json()}async attest(s){const a=await this.fetch("/api/as/mandate",{method:"POST",body:JSON.stringify(s)});if(!a.ok){const o=await a.json().catch(()=>({error:"Unknown error"}));throw new Error(We(o,`Signing failed: ${a.status}`))}return a.json()}async getPending(s){const a=await this.fetch(`/api/mandates/pending?domain=${encodeURIComponent(s)}`);if(!a.ok)throw new Error(`Failed to fetch pending: ${a.status}`);const o=await a.json();return o.pending??o}async getMyAttestations(s){const a=s?`?status=${encodeURIComponent(s)}`:"",o=await this.fetch(`/api/mandates/mine${a}`);if(!o.ok)throw new Error(`Failed to fetch attestations: ${o.status}`);return((await o.json()).mandates??[]).map(u=>{var f,g;return{authorization_id:u.authorization_id,profile_id:u.profileId,path:u.path,title:u.title??null,sp_status:u.status??null,frame:u.bounds??u.frame??{},required_domains:u.requiredDomains??[],attested_domains:u.attestedDomains??[],missing_domains:(u.requiredDomains??[]).filter(p=>!(u.attestedDomains??[]).includes(p)),deferred_commitment_domains:u.deferredCommitmentDomains??[],approvers_frozen:u.approversFrozen??[],above_cap:u.aboveCap??!1,created_at:u.createdAt?new Date(u.createdAt*1e3).toISOString():"",earliest_expiry:(f=u.attestations)!=null&&f.length?new Date(Math.min(...u.attestations.map(p=>p.expiresAt))*1e3).toISOString():null,remaining_seconds:(g=u.attestations)!=null&&g.length?Math.max(0,Math.min(...u.attestations.map(p=>p.expiresAt))-Math.floor(Date.now()/1e3)):null}})}async getDenials(s){const a=new URLSearchParams;s!=null&&s.since&&a.set("since",String(s.since)),s!=null&&s.limit&&a.set("limit",String(s.limit));const o=a.toString()?`?${a.toString()}`:"",c=await this.fetch(`/denials${o}`);if(!c.ok)throw new Error(`Failed to fetch denials: ${c.status}`);return c.json()}async getMyReceipts(s){const a=new URLSearchParams;s!=null&&s.date&&a.set("date",s.date),s!=null&&s.profile&&a.set("profile",s.profile),s!=null&&s.limit&&a.set("limit",String(s.limit));const o=a.toString(),c=await this.fetch(`/api/tickets/mine${o?"?"+o:""}`);if(!c.ok)throw new Error(`Failed to fetch receipts: ${c.status}`);return(await c.json()).tickets??[]}async fetchEvidenceBundle(){var c;const s=await this.fetch("/api/evidence-export"),a=await s.json();if(!s.ok)throw new Error(We(a,`Export failed (${s.status})`));const o=((c=/filename="([^"]+)"/.exec(s.headers.get("content-disposition")??""))==null?void 0:c[1])??"suveren-evidence.json";return{bundle:a,filename:o}}async getLocalAuthorizations(){const s=await this.fetch("/api/evidence/authorizations");if(!s.ok)throw new Error(`Local evidence unavailable (${s.status})`);const a=await s.json();return{authorizations:a.authorizations??{},signatures:a.signatures??{}}}async getArchivedReceipt(s){const a=await this.fetch(`/api/evidence/receipt/${encodeURIComponent(s)}`);if(a.status===404)return null;if(!a.ok)throw new Error(`Local evidence unavailable (${a.status})`);return await a.json()}async getReport(){const s=await this.fetch("/api/report");if(!s.ok){const a=await s.json().catch(()=>({error:`Report unavailable (${s.status})`}));throw new Error(We(a,`Report unavailable (${s.status})`))}return s.json()}async saveReport(s){const a=await this.fetch("/api/report",{method:"POST",body:JSON.stringify({html:s})});if(!a.ok){const o=await a.json().catch(()=>({error:`Save failed (${a.status})`}));throw new Error(We(o,`Save failed (${a.status})`))}return a.json()}async recheckReport(){const s=await this.fetch("/api/report/recheck",{method:"POST"});if(!s.ok){const a=await s.json().catch(()=>({error:`Recheck failed (${s.status})`}));throw new Error(We(a,`Recheck failed (${s.status})`))}return s.json()}async exportReportWithProof(){var c;const s=await this.fetch("/api/report/export");if(!s.ok){const u=await s.json().catch(()=>({error:`Export failed (${s.status})`}));throw new Error(We(u,`Export failed (${s.status})`))}const a=await s.text(),o=((c=/filename="([^"]+)"/.exec(s.headers.get("content-disposition")??""))==null?void 0:c[1])??"suveren-report.html";return{html:a,filename:o}}async revokeAttestation(s,a){const o=await this.fetch(`/api/authorizations/${encodeURIComponent(s)}/revoke`,{method:"POST",body:JSON.stringify({reason:a??"Revoked by user"})});if(!o.ok){const c=await o.json().catch(()=>({error:"Failed to revoke"}));throw new Error(We(c,`Revoke failed: ${o.status}`))}}async getAttestations(s){const a=await this.fetch(`/api/mandates?authorization_id=${encodeURIComponent(s)}`);if(!a.ok)throw new Error(`Failed to fetch attestations: ${a.status}`);const o=await a.json();return{...o,attestations:o.mandates??o.attestations??[]}}async getGroupById(s){const a=await this.fetch(`/api/groups/${encodeURIComponent(s)}`);if(!a.ok)throw new Error(`Failed to fetch group: ${a.status}`);return a.json()}async createGroup(s){const a=await this.fetch("/api/groups",{method:"POST",body:JSON.stringify({name:s})});if(!a.ok){const u=await a.json().catch(()=>({error:"Unknown error"}));throw new Error(We(u,`Create group failed: ${a.status}`))}const o=await a.json(),c=o.group||o;return{id:c.id,name:c.name,myDomains:c.myDomains||[],isAdmin:!0,ended:o.ended??{mandates:0,proposals:0}}}async getCreatePreview(){const s=await this.fetch("/api/groups/create/preview");if(!s.ok){const a=await s.json().catch(()=>({error:"Unknown error"}));throw new Error(We(a,`Failed to preview team creation: ${s.status}`))}return s.json()}async getJoinPreview(s){const a=await this.fetch(`/api/groups/join/preview?inviteCode=${encodeURIComponent(s)}`);if(!a.ok){const o=await a.json().catch(()=>({error:"Invalid or expired invite code"}));throw new Error(We(o,`Invalid invite code: ${a.status}`))}return a.json()}async requestToJoinGroup(s){const a=await this.fetch("/api/groups/join",{method:"POST",body:JSON.stringify({inviteCode:s})});if(a.status!==202){const c=await a.json().catch(()=>({error:"Unknown error"}));throw new Error(We(c,`Request to join failed: ${a.status}`))}return(await a.json()).request}async withdrawJoinRequest(){const s=await this.fetch("/api/groups/join",{method:"DELETE"});if(s.status===404)return!1;if(!s.ok){const o=await s.json().catch(()=>({error:"Unknown error"}));throw new Error(We(o,`Withdraw failed: ${s.status}`))}return(await s.json()).withdrawn===!0}async inviteToGroup(s){const a=await this.fetch(`/api/groups/${encodeURIComponent(s)}/invite`,{method:"POST"});if(!a.ok){const o=await a.json().catch(()=>({error:"Unknown error"}));throw new Error(We(o,`Invite failed: ${a.status}`))}return a.json()}async getMyTeam(){const s=await this.fetch("/api/groups/me");if(!s.ok)return{group:null,membership:null,pendingRequest:null};const a=await s.json();return{group:a.group??null,membership:a.membership??null,pendingRequest:a.pendingRequest??null}}async listUsers(){const s=await this.fetch("/api/users");return s.ok?(await s.json()).users??[]:[]}async setPubkey(s){const a=await this.fetch("/api/users/me/pubkey",{method:"PUT",body:JSON.stringify({pubkey:s})});if(!a.ok){const o=await a.json().catch(()=>({error:"Failed to set pubkey"}));throw new Error(We(o,`setPubkey failed: ${a.status}`))}}async getPubkey(s){const a=await this.fetch(`/api/users/${encodeURIComponent(s)}/pubkey`);return a.status===404||!a.ok?null:(await a.json()).pubkey??null}async leaveTeam(s){const a=await this.fetch(`/api/groups/${encodeURIComponent(s)}/leave`,{method:"POST"});if(!a.ok){const o=await a.json().catch(()=>({error:"Failed to leave team"}));throw new Error(We(o,`Leave failed: ${a.status}`))}}async getVaultStatus(){const s=await this.fetch("/vault/status");if(!s.ok)throw new Error(`Failed to fetch vault status: ${s.status}`);return s.json()}async getGatewaySettings(){const s=await this.fetch("/api/gateway-settings");if(!s.ok)throw new Error(`Failed to load settings: ${s.status}`);return s.json()}async setGatewaySettings(s){const a=await this.fetch("/api/gateway-settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!a.ok)throw new Error(`Failed to save settings: ${a.status}`);return a.json()}async getArchivedMandates(){const s=await this.fetch("/api/archived-mandates");if(!s.ok)throw new Error(`Failed to load archived mandates: ${s.status}`);return(await s.json()).archived}async setMandateArchived(s,a){const o=await this.fetch(`/api/archived-mandates/${encodeURIComponent(s)}`,{method:a?"PUT":"DELETE"});if(!o.ok)throw new Error(`Failed to ${a?"archive":"unarchive"} mandate: ${o.status}`);return(await o.json()).archived}async getLastSeenBlockedAt(){const s=await this.fetch("/api/blocked-seen");if(!s.ok)throw new Error(`Failed to load last-seen: ${s.status}`);return(await s.json()).lastSeenBlockedAt}async markBlockedSeen(s=Date.now()){const a=await this.fetch("/api/blocked-seen",{method:"POST",body:JSON.stringify({ts:s})});if(!a.ok)throw new Error(`Failed to mark blocked seen: ${a.status}`);return(await a.json()).lastSeenBlockedAt}async getCredential(s){const a=await this.fetch(`/vault/credentials/${encodeURIComponent(s)}`);if(!a.ok)throw new Error(`Failed to check credential: ${a.status}`);return a.json()}async setCredential(s,a){const o=await this.fetch(`/vault/credentials/${encodeURIComponent(s)}`,{method:"PUT",body:JSON.stringify(a)});if(!o.ok)throw new Error(`Failed to save credential: ${o.status}`)}async testCredential(s){const a=await this.fetch(`/vault/test/${encodeURIComponent(s)}`,{method:"POST"});if(!a.ok)throw new Error(`Test failed: ${a.status}`);return a.json()}async aiAssist(s){const a=await this.fetch("/ai/assist",{method:"POST",body:JSON.stringify(s)});if(!a.ok){const o=await a.json().catch(()=>({error:"AI request failed"}));return{success:!1,error:We(o,"AI request failed"),disclaimer:"AI surfaces reality. You supply intent."}}return a.json()}async aiIntentReview(s){const a=await this.fetch("/ai/intent-review",{method:"POST",body:JSON.stringify(s)});if(!a.ok){const o=await a.json().catch(()=>({error:"AI request failed"}));return{success:!1,error:We(o,"AI request failed")}}return a.json()}async aiTest(s){const a=await this.fetch("/ai/test",{method:"POST",body:JSON.stringify(s??{})});if(!a.ok)throw new Error(`AI test failed: ${a.status}`);return a.json()}async aiModels(s){const a=await this.fetch("/ai/models",{method:"POST",body:JSON.stringify(s??{})});if(!a.ok)throw new Error(`Model list failed: ${a.status}`);return a.json()}async getMcpHealth(){const s=await this.fetch("/mcp/health");if(!s.ok)throw new Error(`MCP server unreachable: ${s.status}`);return s.json()}async getAgentContact(){const s=await this.fetch("/mcp/agent-contact");if(!s.ok)throw new Error(`Failed to fetch agent contact: ${s.status}`);return s.json()}async getMcpIntegrations(){const s=await this.fetch("/mcp/integrations");if(!s.ok)throw new Error(`Failed to fetch integrations: ${s.status}`);return s.json()}async getOAuthHealth(s){try{const a=await this.fetch(`/auth/oauth/${encodeURIComponent(s)}/health`);return a.ok?await a.json():{status:"unverified"}}catch{return{status:"unverified"}}}async getIntegrationManifests(){const s=await this.fetch("/mcp/integrations/manifests");if(!s.ok)throw new Error(`Failed to fetch manifests: ${s.status}`);return s.json()}async discoverScopeField(s,a){const o=await this.fetch(`/integrations/${encodeURIComponent(s)}/discover/${encodeURIComponent(a)}`);if(!o.ok){const c=await o.json().catch(()=>({error:`Discovery failed: ${o.status}`}));throw new Error(We(c,`Discovery failed: ${o.status}`))}return o.json()}async activateIntegration(s){const a=await this.fetch(`/mcp/integrations/${encodeURIComponent(s)}/activate`,{method:"POST"});if(!a.ok){const o=await a.json().catch(()=>({error:"Failed"}));throw new Error(We(o,`Failed: ${a.status}`))}return a.json()}async removeMcpIntegration(s){const a=await this.fetch(`/mcp/integrations/${encodeURIComponent(s)}`,{method:"DELETE"});if(!a.ok)throw new Error(`Failed to remove integration: ${a.status}`)}async setReadPolicy(s,a){const o=await this.fetch(`/integrations/${encodeURIComponent(s)}/read-policy`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({readAgeDays:a})});if(!o.ok){const c=await o.json().catch(()=>({error:`HTTP ${o.status}`}));throw new Error(We(c,`HTTP ${o.status}`))}}async getTeamProfileConfig(s,a){const o=await this.fetch(`/api/groups/${encodeURIComponent(s)}/profile-config/${encodeURIComponent(a)}`);if(o.status===404||!o.ok)return null;const c=await o.json();return(c==null?void 0:c.config)??null}async setTeamProfileConfig(s,a,o){const c=await this.fetch(`/api/groups/${encodeURIComponent(s)}/profile-config/${encodeURIComponent(a)}`,{method:"PUT",body:JSON.stringify(o)});if(!c.ok){const u=await c.json().catch(()=>({error:"Failed to set profile config"}));throw new Error(We(u,`setTeamProfileConfig failed: ${c.status}`))}}async encryptIntent(s,a){const o=await this.fetch("/api/encrypt-intent",{method:"POST",body:JSON.stringify({intent:s,recipients:a})});if(!o.ok){const c=await o.json().catch(()=>({error:"Encryption failed"}));throw new Error(We(c,`encryptIntent failed: ${o.status}`))}return o.json()}async getToolDisplay(){const s=await this.fetch("/tool-display");if(!s.ok)return{};const a=await s.json();return(a==null?void 0:a.tools)??{}}async getApproversPubkeys(s,a){const o=await this.fetch(`/api/groups/${encodeURIComponent(s)}/profile-config/${encodeURIComponent(a)}/approvers/pubkeys`);return o.ok?Tv(await o.json()):[]}async deleteTeamProfileConfig(s,a){const o=await this.fetch(`/api/groups/${encodeURIComponent(s)}/profile-config/${encodeURIComponent(a)}`,{method:"DELETE"});if(!o.ok){const c=await o.json().catch(()=>({error:"Failed to delete profile config"}));throw new Error(We(c,`deleteTeamProfileConfig failed: ${o.status}`))}}async getIdentityDisclosure(){const s=await this.fetch("/api/users/me/identity-disclosure");if(!s.ok)throw new Error(`Failed to read identity setting: ${s.status}`);return s.json()}async setIdentityDisclosure(s){const a=await this.fetch("/api/users/me/identity-disclosure",{method:"PUT",body:JSON.stringify({always:s})});if(!a.ok)throw new Error(`Failed to save identity setting: ${a.status}`);return a.json()}async getProposals(s,a="pending"){const o=a==="all"?"&status=all":"",c=await this.fetch(`/api/proposals?domain=${encodeURIComponent(s)}${o}`);if(!c.ok)throw new Error(`Failed to fetch proposals: ${c.status}`);return(await c.json()).proposals??[]}async getMyProposals(s,a="pending"){const o=await Promise.all(kv(s).map(c=>this.getProposals(c,a)));return Nv(o)}async resolveProposal(s,a,o,c){const{noteEncrypted:u,contentHash:f,shownHash:g,note:p,...v}=c??{},y=await this.fetch(`/api/proposals/${encodeURIComponent(s)}/resolve`,{method:"POST",body:JSON.stringify({action:a,domain:o,...v,...u?{note_encrypted:u}:p?{note:p}:{},...f?{content_hash:f}:{},...g?{shown_hash:g}:{}})});if(!y.ok){const w=await y.json().catch(()=>({error:"Failed"}));throw new Error(We(w,`Failed: ${y.status}`))}return y.json()}async getProposal(s){const a=await this.fetch(`/api/proposals/${encodeURIComponent(s)}`);if(!a.ok){const c=await a.json().catch(()=>({error:"Failed"}));throw new Error(We(c,`getProposal failed: ${a.status}`))}const o=await a.json();return o.proposal??o}async getProposalsForApprover(){const s=await this.fetch("/api/proposals?approver=me");if(!s.ok)throw new Error(`Failed to fetch approver proposals: ${s.status}`);return(await s.json()).proposals??[]}async approveProposal(s,a,o){const c={};a&&(c.content_hash=a),o&&(c.shown_hash=o);const u=await this.fetch(`/api/proposals/${encodeURIComponent(s)}/approve`,{method:"POST",body:Object.keys(c).length>0?JSON.stringify(c):void 0});if(!u.ok){const f=await u.json().catch(()=>({error:"Failed"}));throw new Error(We(f,`approveProposal failed: ${u.status}`))}return u.json()}async rejectProposal(s,a,o,c){let u;if(typeof a=="string")u={reason:a};else{const{noteEncrypted:g,note:p,...v}=a??{};u={...v,...g?{note_encrypted:g}:p?{note:p}:{}}}o&&(u.content_hash=o),c&&(u.shown_hash=c);const f=await this.fetch(`/api/proposals/${encodeURIComponent(s)}/reject`,{method:"POST",body:JSON.stringify(u)});if(!f.ok){const g=await f.json().catch(()=>({error:"Failed"}));throw new Error(We(g,`rejectProposal failed: ${f.status}`))}return f.json()}async getProposalsCreatedByMe(){const s=await this.fetch("/api/proposals?creator=me");if(s.status===400)return null;if(!s.ok)throw new Error(`Failed to fetch my proposals: ${s.status}`);return(await s.json()).proposals??[]}async withdrawProposal(s,a,o,c){const{noteEncrypted:u,note:f}=a??{},g={...u?{note_encrypted:u}:f?{note:f}:{}};o&&(g.content_hash=o),c&&(g.shown_hash=c);const p=await this.fetch(`/api/proposals/${encodeURIComponent(s)}/withdraw`,{method:"POST",body:JSON.stringify(g)});if(!p.ok){const v=await p.json().catch(()=>({error:"Failed"}));throw new Error(We(v,`withdrawProposal failed: ${p.status}`))}return p.json()}async getProposalPreview(s){const a=await this.fetch(`/proposal-status/${encodeURIComponent(s)}/preview`);if(!a.ok)throw new Error(`Failed to fetch preview: ${a.status}`);return a.json()}async getProposalRequestContext(s){const a=await this.fetch(`/proposal-status/${encodeURIComponent(s)}/request-context`);if(!a.ok)throw new Error(`Failed to fetch request context: ${a.status}`);return a.json()}async saveShownSnapshot(s,a){const o=await this.fetch(`/proposal-status/${encodeURIComponent(s)}/shown-snapshot`,{method:"POST",body:JSON.stringify(a)});if(!o.ok)throw new Error(`Failed to store the shown snapshot: ${o.status}`);return o.json()}async getShownSnapshot(s){const a=await this.fetch(`/proposal-status/${encodeURIComponent(s)}/shown-snapshot`);if(!a.ok)throw new Error(`Failed to fetch the shown snapshot: ${a.status}`);return a.json()}async getProposalOutcome(s){const a=await this.fetch(`/proposal-status/${encodeURIComponent(s)}/outcome`);if(!a.ok)throw new Error(`Failed to fetch outcome: ${a.status}`);return a.json()}async getAttestationIntent(s){const a=await this.fetch(`/api/authorizations/${encodeURIComponent(s)}/intent`);return a.status===404||a.status===403||!a.ok?null:a.json()}async decryptIntent(s){const a=await this.fetch("/api/decrypt-intent",{method:"POST",body:JSON.stringify(s)});if(!a.ok){const c=await a.json().catch(()=>({error:"Decryption failed"}));throw new Error(We(c,`decryptIntent failed: ${a.status}`))}return(await a.json()).intent}async decryptProposalContent(s){const a=await this.fetch("/api/decrypt-proposal-content",{method:"POST",body:JSON.stringify(s)});if(!a.ok){const o=await a.json().catch(()=>({error:"Decryption failed"}));throw new Error(We(o,`decryptProposalContent failed: ${a.status}`))}return a.json()}async encryptProposalNote(s,a){const o=await this.fetch("/api/encrypt-proposal-note",{method:"POST",body:JSON.stringify({note:s,recipientUserIds:a})});if(!o.ok){const c=await o.json().catch(()=>({error:"Encryption failed"}));throw new Error(We(c,`encryptProposalNote failed: ${o.status}`))}return o.json()}async storeApprovedIntent(s,a){const o=await this.fetch("/api/approved-intents",{method:"POST",body:JSON.stringify({authorityId:s,intent:a})});if(!o.ok){const c=await o.json().catch(()=>({error:"Failed"}));throw new Error(We(c,`storeApprovedIntent failed: ${o.status}`))}}async listTeamAuthorizations(s){const a=await this.fetch(`/api/groups/${encodeURIComponent(s)}/mandates`);if(!a.ok)throw new Error(`Failed to fetch team authorizations: ${a.status}`);return((await a.json()).mandates??[]).map(c=>{var g,p;const u=c.owner??{userId:""};return{authorization_id:c.authorization_id??c.authorizationId,profile_id:c.profileId??c.profile_id,path:c.path??"",title:c.title??null,sp_status:c.status??c.sp_status??null,frame:c.bounds??c.frame??{},required_domains:c.requiredDomains??c.required_domains??[],attested_domains:c.attestedDomains??c.attested_domains??[],missing_domains:(c.requiredDomains??c.required_domains??[]).filter(v=>!(c.attestedDomains??c.attested_domains??[]).includes(v)),deferred_commitment_domains:c.deferredCommitmentDomains??c.deferred_commitment_domains??[],approvers_frozen:c.approversFrozen??c.approvers_frozen??[],above_cap:c.aboveCap??c.above_cap??!1,created_at:c.createdAt?new Date(c.createdAt*1e3).toISOString():c.created_at??"",earliest_expiry:(g=c.mandates)!=null&&g.length?new Date(Math.min(...c.mandates.map(v=>v.expiresAt))*1e3).toISOString():null,remaining_seconds:(p=c.mandates)!=null&&p.length?Math.max(0,Math.min(...c.mandates.map(v=>v.expiresAt))-Math.floor(Date.now()/1e3)):null,owner:u}})}async listTeamReceipts(s){const a=await this.fetch(`/api/groups/${encodeURIComponent(s)}/tickets`);if(!a.ok)throw new Error(`Failed to fetch team receipts: ${a.status}`);return(await a.json()).tickets??[]}async getMyReceiptsPage(s){const a=new URLSearchParams;s!=null&&s.before&&a.set("before",s.before),s!=null&&s.profile&&a.set("profile",s.profile),s!=null&&s.limit&&a.set("limit",String(s.limit));const o=a.toString(),c=await this.fetch(`/api/tickets/mine${o?"?"+o:""}`);if(!c.ok)throw new Error(`Failed to fetch receipts: ${c.status}`);const u=await c.json();return{receipts:u.tickets??[],nextBefore:u.nextBefore??null}}async listTeamReceiptsPage(s,a){const o=new URLSearchParams;a!=null&&a.before&&o.set("before",a.before),a!=null&&a.profile&&o.set("profile",a.profile),a!=null&&a.limit&&o.set("limit",String(a.limit));const c=o.toString(),u=await this.fetch(`/api/groups/${encodeURIComponent(s)}/tickets${c?"?"+c:""}`);if(!u.ok)throw new Error(`Failed to fetch team receipts: ${u.status}`);const f=await u.json();return{receipts:f.tickets??[],nextBefore:f.nextBefore??null}}async getThread(s){const a=s.sinceDays??7,o=s.status??"pending",c=await this.getMyProposals(s.domain,o);let u=[];if(o==="all"){const f=[],g=new Date;for(let v=0;v<a;v++){const y=new Date(g);y.setUTCDate(g.getUTCDate()-v),f.push(y.toISOString().slice(0,10))}u=(await Promise.all(f.map(v=>this.getMyReceipts({date:v,profile:s.profile})))).flat()}return{proposals:c,receipts:u}}async getAutostart(){const s=await this.fetch("/autostart");if(!s.ok)throw new Error(`HTTP ${s.status}`);return s.json()}async setAutostart(s){const a=await this.fetch("/autostart",{method:s?"POST":"DELETE"});if(!a.ok){const o=await a.json().catch(()=>({}));throw new Error(o.message||`HTTP ${a.status}`)}}async getAsPairing(){const s=await this.fetch("/as-pairing");if(!s.ok)throw new Error(`HTTP ${s.status}`);return s.json()}async getSkippedCommitments(){const s=await this.fetch("/skipped-commitments");if(!s.ok)throw new Error(`HTTP ${s.status}`);return s.json()}async getMyPendingProposals(){const s=await this.fetch("/my-pending-proposals");return s.ok?(await s.json().catch(()=>({proposals:[]}))).proposals??[]:[]}async getGateContent(s){const a=await this.fetch(`/gate-content?path=${encodeURIComponent(s)}`);if(!a.ok)throw new Error(`Failed to fetch gate content: ${a.status}`);return(await a.json()).entry??null}async resyncGates(){const s=await this.fetch("/resync-gates",{method:"POST"});if(!s.ok)throw new Error(`Failed to resync gates: ${s.status}`)}async getEnrichedAuthorizations(){const s=await this.fetch("/active-authorizations");if(!s.ok)throw new Error(`Failed to fetch authorizations: ${s.status}`);return(await s.json()).authorizations??[]}async pushGateContent(s){const a=await this.fetch("/gate-content",{method:"POST",body:JSON.stringify(s)});if(!a.ok){const o=await a.json().catch(()=>({error:"Failed to push gate content"}));throw new Error(We(o,`Push gate content failed: ${a.status}`))}}async getAgentContext(){const s=await this.fetch("/agent-brief/context");if(!s.ok)throw new Error(`Failed to fetch agent context: ${s.status}`);return(await s.json()).content}async saveAgentContext(s){const a=await this.fetch("/agent-brief/context",{method:"PUT",body:JSON.stringify({content:s})});if(!a.ok){const o=await a.json().catch(()=>({error:"Failed to save agent context"}));throw new Error(We(o,`Save failed: ${a.status}`))}}async aiChat(s){const a=await this.fetch("/ai/chat",{method:"POST",body:JSON.stringify(s)});if(!a.ok){const o=await a.json().catch(()=>({error:"AI chat failed"}));return{success:!1,error:We(o,`Chat failed: ${a.status}`)}}return a.json()}async getAIPrompts(){const s=await this.fetch("/ai-prompts");if(!s.ok)throw new Error(`Failed to load AI prompts: ${s.status}`);return s.json()}async setAIPrompt(s,a){const o=await this.fetch(`/ai-prompts/${s}`,{method:"PUT",body:JSON.stringify({value:a})});if(!o.ok){const c=await o.json().catch(()=>({error:"Save failed"}));throw new Error(We(c,`Save failed: ${o.status}`))}}}const O=new Rv,_h=h.createContext(null);function Av({children:t}){const[s,a]=h.useState(null),[o,c]=h.useState("personal"),[u,f]=h.useState(null),[g,p]=h.useState(""),[v,y]=h.useState(null),[w,j]=h.useState(null),[N,b]=h.useState(null),[S,k]=h.useState(!1),[T,R]=h.useState(""),P=h.useRef(!1),A=h.useRef(null),B=h.useCallback(async()=>{if(P.current)try{const ee=await O.getMyTeam();if(b(ee.pendingRequest),ee.group&&ee.membership){const{group:F,membership:re}=ee;y(F),j(re),c("team"),f(F);const Y=A.current??re.domains[0]??"owner";p(Y)}else y(null),j(null),c("personal")}catch{}},[]);h.useEffect(()=>{const ee=()=>{document.visibilityState==="visible"&&B()};return document.addEventListener("visibilitychange",ee),()=>document.removeEventListener("visibilitychange",ee)},[B]),h.useEffect(()=>{fetch("/health").then(ee=>ee.json()).then(ee=>{var F;((F=ee.session)==null?void 0:F.lockedReason)==="as-url-changed"&&R(`Authority Server changed to ${ee.spUrl??"a new server"} — sign in again.`)}).catch(()=>{})},[]);const H=h.useCallback(async(ee,F={})=>{k(!0),R("");try{O.setApiKey(ee),P.current=!0;const re=await O.login(ee,F);a(re),A.current=re.id;const Y=await O.getGroups(),se=Y.find(ye=>ye.isPersonal)??Y[0]??null;f(se),p("owner"),await B()}catch(re){throw O.clearApiKey(),P.current=!1,R(re instanceof Error?re.message:"Login failed"),re}finally{k(!1)}},[B]),G=h.useCallback(async()=>{await O.logout(),O.clearApiKey(),P.current=!1,A.current=null,a(null),f(null),p(""),y(null),j(null),b(null),c("personal"),R("")},[]),me=h.useCallback(ee=>{O.clearApiKey(),P.current=!1,A.current=null,a(null),f(null),p(""),y(null),j(null),b(null),c("personal"),R(ee??"Your sign-in ended after 30 days or was revoked. Sign in again.")},[]),q=h.useCallback(()=>R(""),[]),ce=h.useCallback((ee,F)=>{f(ee),p(F)},[]);return r.jsx(_h.Provider,{value:{user:s,mode:o,group:u,domain:g,groupId:(u==null?void 0:u.id)??null,activeTeam:v,activeMembership:w,pendingRequest:N,isLoading:S,error:T,login:H,logout:G,clearError:q,handleSessionLocked:me,activeGroup:u,activeDomain:g,groups:u?[u]:[],setActiveContext:ce,refreshGroups:B},children:t})}function mt(){const t=h.useContext(_h);if(!t)throw new Error("useAuth must be used within AuthProvider");return t}const Iv={"integration-changed":!0,"attestation-changed":!0,"proposal-added":!0,"proposal-resolved":!0,"team-membership-changed":!0,"action-approval-needed":!0,"action-resolved":!0,"proposal-approved":!0,"proposal-rejected":!0,"session-locked":!0,"execution-failed":!0,"denial-recorded":!0},Pv=Object.keys(Iv),$h=h.createContext(null);function _v({children:t}){const{user:s}=mt(),a=h.useRef(null),[o,c]=h.useState(!1),u=h.useRef(new Map),f=h.useCallback((g,p)=>{const v=u.current;return v.has(g)||v.set(g,new Set),v.get(g).add(p),()=>{var y;(y=v.get(g))==null||y.delete(p)}},[]);return h.useEffect(()=>{if(!s){a.current&&(a.current.close(),a.current=null,c(!1));return}if(a.current)return;const g=O.getApiKey();if(!g)return;const p=new EventSource(`/events?key=${encodeURIComponent(g)}`);a.current=p,p.onopen=()=>c(!0),p.onerror=()=>c(!1);for(const v of Pv)p.addEventListener(v,y=>{let w;try{w=JSON.parse(y.data)}catch{w=null}const j=u.current.get(v);if(j)for(const N of j)try{N(w)}catch(b){console.error(`[EventSource] handler for "${v}" threw:`,b)}});return()=>{p.close(),a.current=null,c(!1)}},[s]),r.jsx($h.Provider,{value:{connected:o,addListener:f},children:t})}function De(t,s){const a=h.useContext($h);if(!a)return;const{addListener:o}=a;h.useEffect(()=>o(t,s),[t,s,o])}const qs="suveren-theme",Sf="hap-theme";function di(t){return t!=="system"?t:window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}(function(){const s=localStorage.getItem(Sf);s!==null&&localStorage.getItem(qs)===null&&localStorage.setItem(qs,s),s!==null&&localStorage.removeItem(Sf)})();function Lh(){const[t,s]=h.useState(()=>{const u=localStorage.getItem(qs);return u==="light"||u==="dark"?u:"system"}),[a,o]=h.useState(()=>di(t));h.useEffect(()=>{const u=document.documentElement,f=di(t);u.setAttribute("data-theme",f),t==="system"?localStorage.removeItem(qs):localStorage.setItem(qs,t),o(di(t))},[t]),h.useEffect(()=>{if(t!=="system")return;const u=window.matchMedia("(prefers-color-scheme: dark)"),f=()=>o(di("system"));return u.addEventListener("change",f),()=>u.removeEventListener("change",f)},[t]);const c=h.useCallback(()=>{s(u=>u==="system"?"light":u==="light"?"dark":"system")},[]);return{theme:t,effectiveTheme:a,toggle:c}}const $v=300*1e3,Lv=2e3;function dc(){const[t,s]=h.useState(!1),[a,o]=h.useState("docker"),[c,u]=h.useState(""),[f,g]=h.useState(null),[p,v]=h.useState(!1),[y,w]=h.useState(!1),[j,N]=h.useState(!1),b=h.useRef(null);return h.useEffect(()=>{let S=!1;const k=(P=!1)=>{fetch(P?"/health?refresh=1":"/health").then(A=>A.json()).then(A=>{S||(A.installMethod&&o(A.installMethod),typeof A.latestVersion<"u"&&g(A.latestVersion),A.updateAvailable&&s(!0),A.version&&(u(A.version),b.current===null?b.current=A.version:A.version!==b.current&&A.version!=="dev"&&v(!0)))}).catch(()=>{})};k(!0);const T=setInterval(()=>k(!1),j?Lv:$v),R=()=>{document.visibilityState==="visible"&&k(!1)};return document.addEventListener("visibilitychange",R),window.addEventListener("focus",R),()=>{S=!0,clearInterval(T),document.removeEventListener("visibilitychange",R),window.removeEventListener("focus",R)}},[j]),{updateAvailable:t&&!y,installMethod:a,version:c,latestVersion:f,serverRestarted:p,startFastPolling:()=>N(!0),dismiss:()=>w(!0)}}function zv(t){return!t||typeof t!="object"?{managed:!1}:{managed:Array.isArray(t.policyLocked)&&t.policyLocked.includes("team")}}function Fv(){const[t,s]=h.useState({managed:!1});return h.useEffect(()=>{let a=!1;return fetch("/health").then(o=>o.json()).then(o=>{a||s(zv(o))}).catch(()=>{}),()=>{a=!0}},[]),t}function Ov({size:t=20}){return r.jsxs("svg",{width:t,height:t,viewBox:"0 0 128 128",fill:"none","aria-hidden":"true",focusable:"false",children:[r.jsx("path",{d:"M 104.6 58.29 A 41 41 0 1 1 48.64 25.99",stroke:"currentColor",strokeWidth:"15",strokeLinecap:"round"}),r.jsx("line",{x1:"73.24",y1:"21.99",x2:"95.76",y2:"34.99",stroke:"currentColor",strokeWidth:"15",strokeLinecap:"round"})]})}function Mv(t){return t?t==="dev"?"dev":/^[0-9a-f]{40}$/i.test(t)?t.slice(0,7):t:""}const bf={system:"◑",light:"☀",dark:"☾"};function fc({onMenuToggle:t}){const{user:s,logout:a,mode:o,activeTeam:c}=mt(),{theme:u,toggle:f}=Lh(),{version:g,updateAvailable:p,latestVersion:v}=dc(),{managed:y}=Fv(),w=Mv(g),j=o==="team"&&c?`Team ${c.name}`:"Personal";return r.jsx("nav",{className:"top-nav",children:r.jsxs("div",{className:"top-nav-inner",children:[r.jsxs("div",{className:"logo-group",children:[r.jsx(Ov,{size:20}),r.jsx("span",{className:"logo",children:"Suveren"}),r.jsx("span",{className:"version-badge",children:"Local Gateway"}),w&&r.jsxs("span",{className:"gw-version",title:p&&v?`Running v${w} — v${v} is available`:"Running gateway version","data-stale":p?"true":void 0,children:["v",w,p&&v?` → ${v}`:""]})]}),r.jsx("div",{className:"nav-spacer"}),r.jsx("div",{className:"nav-actions nav-actions-desktop",children:s?r.jsxs(r.Fragment,{children:[r.jsxs("span",{className:"workspace-pill","data-managed":y?"true":void 0,title:y?`${j} — set by your IT`:j,children:[j,y&&r.jsx("span",{className:"workspace-pill-it",children:" · set by your IT"})]}),r.jsx("span",{className:"user-chip",children:r.jsx("strong",{children:s.name})}),r.jsx("button",{className:"theme-toggle",onClick:f,title:`Theme: ${u}`,children:bf[u]}),r.jsx("button",{className:"nav-logout",onClick:a,children:"Logout"})]}):r.jsx("button",{className:"theme-toggle",onClick:f,title:`Theme: ${u}`,children:bf[u]})}),s&&t&&r.jsx("button",{className:"mobile-menu-btn",onClick:t,"aria-label":"Menu",children:"☰"})]})})}function hc(t,s){var a;if((a=s==null?void 0:s.revokedSet)!=null&&a.has(t.authorization_id))return"revoked";switch(t.sp_status){case"revoked":return"revoked";case"expired":return"expired";case"active":return"active";case"pending":return"pending"}return t.remaining_seconds===null||t.remaining_seconds<=0?"expired":t.missing_domains.length>0?"pending":"active"}function zh(t){return t==="expired"||t==="revoked"}function Fh(t,s){var a;return!!((a=s==null?void 0:s.archivedSet)!=null&&a.has(t.authorization_id))&&zh(hc(t,s))}function Si(t,s){return Fh(t,s)?"archived":hc(t,s)}function Oh(t,s){const a={active:[],pending:[],expired:[],revoked:[],archived:[]};for(const o of t)a[Si(o,s)].push(o);return a}function Bv(t,s){return s==="expired"?t.earliest_expiry?{iso:t.earliest_expiry,meaning:"expired"}:null:t.created_at?{iso:t.created_at,meaning:"created"}:null}function Dt(t,s,a){const o=h.useRef(t);o.current=t,h.useEffect(()=>{let c=null;const u=()=>typeof document>"u"?!0:document.visibilityState==="visible",f=()=>{u()&&o.current()},g=()=>{c===null&&(c=setInterval(f,s))},p=()=>{c!==null&&(clearInterval(c),c=null)},v=()=>{u()?(o.current(),g()):p()};return u()&&(o.current(),g()),document.addEventListener("visibilitychange",v),()=>{p(),document.removeEventListener("visibilitychange",v)}},[s,a])}function mc(){const[t,s]=h.useState(!1);return h.useEffect(()=>{let a=!1;const o=()=>{fetch("/health").then(f=>f.json()).then(f=>{a||s(f.simulation===!0)}).catch(()=>{})};o();const c=setInterval(o,3e4),u=()=>{document.visibilityState==="visible"&&o()};return document.addEventListener("visibilitychange",u),()=>{a=!0,clearInterval(c),document.removeEventListener("visibilitychange",u)}},[]),t}function Dv(t,s){const a=t.simulation;return a?(((s==null?void 0:s[a.field])??"").trim().toLowerCase()||a.default.trim().toLowerCase())==="simulation":!1}function Qs(t){return!!(t!=null&&t.simulation)}const Mh=h.createContext(null),Uv=3e4,Wv=5e3,Hv=3e5;function Vv(t,s,a){return s===0?"loading":t!=null&&t.running?"running":t!=null&&t.paused?"paused":t!=null&&t.error?"error":t&&a?"starting":"not-running"}function Gv({children:t}){const[s,a]=h.useState({manifests:[],integrations:[],activeSessions:0,mcpServerUp:null,manifestsError:!1,fetchCount:0,authHealth:{}}),o=h.useRef(null),c=h.useCallback(async()=>{let y=!1;const[w,j]=await Promise.all([O.getIntegrationManifests().catch(()=>(y=!0,{manifests:[]})),O.getMcpHealth().catch(()=>null)]);a(b=>({...b,manifests:w.manifests,integrations:(j==null?void 0:j.integrations)??b.integrations,activeSessions:(j==null?void 0:j.activeSessions)??b.activeSessions,mcpServerUp:!!j,manifestsError:y,fetchCount:b.fetchCount+1}));const N=w.manifests.filter(b=>b.oauth);if(N.length>0){const b=await Promise.all(N.map(async S=>[S.id,await O.getOAuthHealth(S.id)]));a(S=>({...S,authHealth:Object.fromEntries(b)}))}},[]),u=s.fetchCount>0&&s.manifests.some(y=>{const w=s.integrations.find(j=>j.id===y.id);return w&&!w.running&&!w.paused});De("integration-changed",c),Dt(c,u?Wv:Hv);const f=h.useMemo(()=>{const y=new Map(s.integrations.map(N=>[N.id,N])),w=Date.now();u&&o.current===null?o.current=w:u||(o.current=null);const j=o.current!==null&&w-o.current<Uv;return s.manifests.map(N=>{const b=y.get(N.id),S=Vv(b,s.fetchCount,j),k=s.authHealth[N.id];return{id:N.id,manifest:N,integration:b,state:S,authStatus:k==null?void 0:k.status,authAccount:k==null?void 0:k.account,authError:k==null?void 0:k.error}})},[s,u]),g=mc(),p=h.useMemo(()=>f.filter(y=>!(g&&!Qs(y.manifest))&&(y.state==="not-running"||y.state==="error"||y.authStatus==="failed")).length,[f,g]),v={loading:s.fetchCount===0,mcpServerUp:s.mcpServerUp,manifestsError:s.manifestsError,entries:f,attentionCount:p,activeSessions:s.activeSessions,refresh:c};return r.jsx(Mh.Provider,{value:v,children:t})}function pc(){const t=h.useContext(Mh);if(!t)throw new Error("useIntegrationStatus must be used inside IntegrationStatusProvider");return t}const Kv={gmail:"Gmail",calendar:"Google Calendar",crm:"CRM",linkedin:"LinkedIn",records:"Records",mollie:"Mollie"},gc=t=>Kv[t]??t,qv={resource:{chip:"Restricted",sev:"warn"},spam:{chip:"Spam / Trash",sev:"info"},age:{chip:"Too old",sev:"warn"},unset_age:{chip:"Needs setup",sev:"act",fixTo:"/integrations"},read_gate:{chip:"Not granted",sev:"act",fixTo:"/mandates"},ungoverned:{chip:"Unconfigured",sev:"act"},query_unsafe:{chip:"Unsafe search",sev:"info"}};function Yv(t){return(t&&qv[t])??{chip:"Blocked",sev:"info"}}function Jv(t){const s=gc(t.integrationId);switch(t.reason){case"resource":return t.integrationId==="calendar"?r.jsxs(r.Fragment,{children:["Tried to read your ",r.jsx("b",{children:t.target??"restricted"})," calendar"]}):r.jsxs(r.Fragment,{children:["Tried to read a restricted location in ",s]});case"spam":return r.jsxs(r.Fragment,{children:["Tried to open a message in ",r.jsx("b",{children:"spam or trash"})]});case"age":return r.jsxs(r.Fragment,{children:["Tried to read ",s," older than your read window"]});case"unset_age":return r.jsxs(r.Fragment,{children:["Your ",s," has ",r.jsx("b",{children:"no read window set"}),", so reads are blocked"]});case"read_gate":return r.jsxs(r.Fragment,{children:["Read access isn't granted on your ",s," mandate"]});case"ungoverned":return r.jsxs(r.Fragment,{children:["A ",s," tool isn't configured for safe reading"]});case"query_unsafe":return r.jsx(r.Fragment,{children:"A search couldn't be safely limited and was refused"});default:return r.jsx(r.Fragment,{children:t.detail})}}function Bh(t,s){const a=Math.max(0,(s-t)/1e3);if(a<60)return"Just now";if(a<3600)return`${Math.floor(a/60)} min ago`;if(a<86400)return`${Math.floor(a/3600)} hr ago`;const o=Math.floor(a/86400);return o===1?"Yesterday":`${o} days ago`}const kf=5,Qv=1440*60*1e3,vi=7;function Xv(t,s){const a=s-vi*Qv;return{recent:t.filter(o=>o.ts>=a),all:t}}function Zv(){const[t,s]=h.useState(null),[a,o]=h.useState(!1),[c,u]=h.useState(!1),f=h.useCallback(()=>{O.getDenials({limit:200}).then(({records:j})=>{s(j),u(!1)}).catch(()=>u(!0))},[]);if(h.useEffect(()=>{f()},[f]),Dt(f,12e4),c||t===null)return null;const{recent:g,all:p}=Xv(t,Date.now()),v=a?p:g.slice(0,kf),y=p.length-g.length,w=(j,N)=>{const b=Yv(j.reason);return r.jsxs("div",{className:"rb-row",children:[r.jsx("span",{className:`rb-dot ${b.sev==="act"?"act":b.sev==="info"?"info":""}`,"aria-hidden":"true"}),r.jsxs("div",{className:"rb-body",children:[r.jsx("div",{className:"rb-line",children:Jv(j)}),r.jsxs("div",{className:"rb-meta",children:[r.jsx("span",{className:`rb-chip ${b.sev==="act"?"act":b.sev==="warn"?"warn":""}`,children:b.chip}),r.jsx("span",{className:"rb-via",children:gc(j.integrationId)})]}),b.fixTo&&r.jsx(xt,{className:"rb-fix",to:b.fixTo,children:"Set a read window →"})]}),r.jsx("div",{className:"rb-when",children:Bh(j.ts,Date.now())})]},`${j.ts}-${N}`)};return r.jsxs("section",{className:"card recent-blocks","aria-label":"Recent blocks",style:{marginTop:"1.5rem"},children:[r.jsxs("div",{className:"card-header",children:[r.jsx("h2",{className:"card-title",children:"Recent blocks"}),(a?p.length:g.length)>0&&r.jsx("span",{className:"rb-count",children:a?p.length:g.length})]}),v.length===0?r.jsxs("div",{className:"rb-empty",children:[r.jsx("span",{className:"rb-mark","aria-hidden":"true",children:r.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("path",{d:"M20 6 9 17l-5-5"})})}),r.jsxs("h3",{children:["Nothing blocked in the last ",vi," days"]}),r.jsx("p",{children:"Your agent has stayed within every limit you set."}),y>0&&r.jsxs("button",{className:"rb-viewall",type:"button",onClick:()=>o(!0),children:["Show the last 30 days (",y,")"]})]}):r.jsxs(r.Fragment,{children:[r.jsxs("p",{className:"rb-sub",children:[a?"Last 30 days. ":`Last ${vi} days. `,"Limits you set that stopped your agent. Seeing them here means the gateway is doing its job."]}),r.jsx("div",{className:"rb-rows",children:v.map(w)}),!a&&p.length>v.length&&r.jsx("div",{className:"rb-foot",children:r.jsxs("button",{className:"rb-viewall",type:"button",onClick:()=>o(!0),children:["View all ",p.length," blocks from the last 30 days"]})}),a&&p.length>Math.min(g.length,kf)&&r.jsx("div",{className:"rb-foot",children:r.jsxs("button",{className:"rb-viewall",type:"button",onClick:()=>o(!1),children:["Show only the last ",vi," days"]})})]})]})}function zi(t){return t.kind??"read"}function ex(t,s){var u,f,g,p;if(!s)return"";if(!t)return s;const a=(f=(u=t.scopeSchema)==null?void 0:u.fields)==null?void 0:f[s];if(a!=null&&a.displayName)return a.displayName;const o=((g=t.boundsSchema)==null?void 0:g.fields)??{};if((p=o[s])!=null&&p.displayName)return o[s].displayName;const c=Object.values(o).find(v=>v.boundType&&"of"in v.boundType&&v.boundType.of===s);return c!=null&&c.displayName?c.displayName:s}const tx={bound:"Blocked — above your limit",scope:"Blocked — outside your mandate's scope",cumulative:"Blocked — limit reached",simulation:"Blocked — simulation mode",not_authorized:"Blocked — not authorized",read:"Read blocked"},nx={bound:"Nothing ran. To allow this, raise the limit on the mandate (needs your signature) — or ask the AI to stay within it.",scope:"Nothing ran. To allow this, widen the mandate's scope (needs your signature) — or ask the AI to stay within it.",cumulative:"Nothing ran. Possible again once the window resets — or raise the limit in the mandate.",simulation:"Nothing ran. Turn off simulation mode in Settings to use real systems.",not_authorized:"Nothing ran. Grant a mandate for this, or ask the decision owner.",read:"Nothing was read."};function Nf(t){return t===void 0?"":typeof t=="number"?t.toLocaleString():t}function rx(t,s){const a=zi(t),o=Nf(t.value),c=Nf(t.limit);switch(a){case"bound":return o&&c?`${s||"Value"} ${o} is above the limit ${c}.`:t.detail;case"scope":return o?`${s||"Value"} "${o}" is not within your mandate's allowed ${s||"scope"}.`:t.detail;case"cumulative":return o&&c?`${o} of ${c} used — the limit is reached.`:t.detail;case"simulation":return"Real systems are switched off while the gateway runs in simulation mode.";case"not_authorized":return"No mandate currently covers this action.";case"read":default:return t.detail}}function sx(t,s){if(t.mandateId){const a=s==null?void 0:s[t.mandateId];if(a)return a}return t.mandateTitle}function ax(t,s){const a=sx(t,s);if(a){const o=[{text:` · mandate "${a}"`}];return t.mandateId&&o.push({text:` (${t.mandateId.slice(0,14)}…)`,dim:!0}),o}return t.mandateId?[{text:` · mandate ${t.mandateId.slice(0,14)}…`}]:[]}function ix(t,s){const a=zi(t),o=gc(t.integrationId),c=t.who==="authority-server"?"refused by the Authority Server":a==="read"?"refused by this gateway":"refused by this gateway, before anything ran",u=t.code?` (${t.code})`:"";return[{text:`${o} · ${t.tool}`},...ax(t,s),{text:` · ${c}${u}`}]}function ox(t,s,a){const o=zi(t),c=ex(s,t.field);return{title:tx[o],sentence:rx(t,c),sourceLine:ix(t,a),whatYouCanDo:nx[o]}}function lx(t,s){const a=new Date(s);return a.setHours(0,0,0,0),t.filter(o=>o.ts>=a.getTime()).length}function cx(t,s){return t.filter(a=>a.ts>s).length}const ux=1440*60*1e3;function dx(t,s){const a=new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),o=new Date(s);o.setHours(0,0,0,0);const c=o.getTime();return t>=c?`Today · ${a}`:t>=c-ux?`Yesterday · ${a}`:`${new Date(t).toLocaleDateString(void 0,{month:"short",day:"numeric"})} · ${a}`}const fx=[{to:"/",icon:"□",label:"Dashboard"},{to:"/approvals",icon:"▷",label:"Pending Approvals",statusKey:"proposals"},{to:"/mandates",icon:"☰",label:"Mandates",statusKey:"authorizations"},{to:"/agent-brief",icon:"▤",label:"Agent Brief",statusKey:"brief"},{to:"/tickets",icon:"▣",label:"Tickets"},{to:"/blocked",icon:"⛔",label:"Blocked",statusKey:"blocked"},{to:"/reports",icon:"▥",label:"Reports"},{to:"/team",icon:"◉",label:"Team",teamOnly:!0},{to:"/integrations",icon:"⧗",label:"Integrations",statusKey:"integrations"},{to:"/settings",icon:"⚙",label:"Settings",statusKey:"assistant"}];function hx(){const{activeDomain:t}=mt(),[s,a]=h.useState({}),o=h.useCallback(async()=>{try{const[c,u,f,g,p,v,y,w]=await Promise.all([O.getCredential("ai-config").catch(()=>null),O.getMyAttestations().catch(()=>null),O.getMyProposals(t).catch(()=>null),O.getProposalsForApprover().catch(()=>null),O.getAgentContext().catch(()=>""),O.getArchivedMandates().catch(()=>[]),O.getDenials({limit:200}).catch(()=>null),O.getLastSeenBlockedAt().catch(()=>0)]),j={};if(c&&!c.configured&&(j.assistant=1),u){const k=Oh(u,{archivedSet:new Set(v)}).expired.length;k>0&&(j.authorizations=k)}const N=(f==null?void 0:f.length)??0,b=(g==null?void 0:g.length)??0,S=N+b;if(S>0&&(j.proposals=S),(!p||!p.trim())&&(j.brief=1),y){const k=cx(y.records,w);k>0&&(j.blocked=k)}a(j)}catch{}},[t]);return De("attestation-changed",o),De("proposal-added",o),De("proposal-resolved",o),De("proposal-approved",o),De("proposal-rejected",o),De("team-membership-changed",o),De("denial-recorded",o),h.useEffect(()=>(window.addEventListener("suveren:archived-changed",o),()=>window.removeEventListener("suveren:archived-changed",o)),[o]),h.useEffect(()=>(window.addEventListener("suveren:blocked-seen-changed",o),()=>window.removeEventListener("suveren:blocked-seen-changed",o)),[o]),Dt(o,3e5,t),s}const mx={marginLeft:"auto",minWidth:"1.25rem",height:"1.25rem",padding:"0 0.375rem",borderRadius:"0.625rem",background:"var(--warning)",color:"var(--bg-elevated)",fontSize:"0.7rem",fontWeight:600,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0},px={position:"fixed",bottom:"1.5rem",left:"50%",transform:"translateX(-50%)",background:"var(--bg-elevated, #1e1e2e)",color:"var(--text-primary, #e2e8f0)",border:"1px solid var(--border)",borderRadius:"0.5rem",padding:"0.625rem 1rem",fontSize:"0.85rem",boxShadow:"0 4px 16px rgba(0,0,0,0.3)",zIndex:9999,whiteSpace:"nowrap",pointerEvents:"none"};function gx(){const{mode:t,group:s,domain:a,activeTeam:o}=mt(),c=hx(),{attentionCount:u}=pc(),f={...c};u>0&&(f.integrations=u);const g=fx.filter(j=>!j.teamOnly||t==="team"),p=h.useRef(null),[v,y]=h.useState(null),w=Ut();return h.useEffect(()=>{if(p.current===null){p.current=t;return}p.current!==t&&(t==="team"&&o?y(`You are now acting in team context — ${o.name}`):t==="personal"&&y("You have left the team — back to personal context"),p.current=t)},[t,o]),h.useEffect(()=>{y(null)},[w.pathname]),r.jsxs("div",{className:"sidebar",children:[r.jsx("ul",{className:"sidebar-nav",children:g.map(j=>{const N=j.statusKey?f[j.statusKey]:0;return r.jsx("li",{children:r.jsxs(cc,{to:j.to,end:j.to==="/",className:({isActive:b})=>`sidebar-item${b?" active":""}`,children:[r.jsx("span",{className:"icon",children:j.icon}),j.label,N?r.jsx("span",{style:mx,children:N}):null]})},j.to)})}),r.jsxs("div",{className:"sidebar-context",children:[r.jsx("div",{className:"ctx-label",children:"Active context"}),r.jsx("div",{className:"ctx-value",children:t==="personal"?"personal":s?`${s.name} / ${a}`:a})]}),v&&r.jsx("div",{style:px,role:"status","aria-live":"polite",children:v})]})}const Il="suveren:updatedTo";function yx(t){return t==="managed"||t==="msi"?null:t==="npm"?"npm install -g @suveren/gateway@latest && suveren-gateway restart":t==="dev"?"git pull && pnpm install":"docker rm -f suveren-gateway 2>/dev/null; docker ps -q --filter publish=7400 --filter publish=7430 | xargs -r docker rm -f; docker pull ghcr.io/suverenai/suveren-gateway:latest && docker run -d --name suveren-gateway -p 7400:3000 -p 7430:3030 -v $HOME/.suveren:/app/data ghcr.io/suverenai/suveren-gateway"}const vx="Updates for this gateway come from your company's IT — no action needed here.";function xx(t){return t==="managed"?"update-banner is-managed":"update-banner"}const wx="Download the new installer and run it. Your settings and mandates stay.";function jx(t){const s="https://github.com/suverenai/suveren-gateway/releases";return t?`${s}/tag/v${t}`:`${s}/latest`}function Sx(){const t=document.querySelectorAll('[role="dialog"], .modal-overlay, .modal');for(const a of t)if(!a.closest(".update-overlay"))return!0;const s=document.activeElement;if(s&&(s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.isContentEditable)){const a=s.value;if(a&&a.trim())return!0}return!1}function Dh(){const{updateAvailable:t,installMethod:s,version:a,latestVersion:o,serverRestarted:c,startFastPolling:u,dismiss:f}=dc(),[g,p]=h.useState(!1),[v,y]=h.useState(!1),[w,j]=h.useState(()=>{try{const P=sessionStorage.getItem(Il);if(P)return sessionStorage.removeItem(Il),P}catch{}return null}),N=yx(s),b=h.useRef(null),S=P=>{try{sessionStorage.setItem(Il,P||o||"✓")}catch{}window.location.reload()};h.useEffect(()=>{if(!w)return;const P=setTimeout(()=>j(null),6e3);return()=>clearTimeout(P)},[w]),h.useEffect(()=>{if(!g||!c)return;const P=()=>Sx()?!1:(S(a),!0);if(P())return;const A=setInterval(P,1500);return()=>clearInterval(A)},[g,c,a]),h.useEffect(()=>(document.body.classList.toggle("is-updating",g),()=>document.body.classList.remove("is-updating")),[g]);const k=t&&!g&&!w||!!w&&!g;h.useEffect(()=>{if(!k){document.documentElement.style.removeProperty("--update-banner-h"),document.body.classList.remove("has-update-banner");return}document.body.classList.add("has-update-banner");const P=()=>{var H;const B=((H=b.current)==null?void 0:H.offsetHeight)??0;document.documentElement.style.setProperty("--update-banner-h",`${B}px`)};P();const A=new ResizeObserver(P);return b.current&&A.observe(b.current),()=>{A.disconnect(),document.documentElement.style.removeProperty("--update-banner-h"),document.body.classList.remove("has-update-banner")}},[k]);const T=()=>{p(!0),u()},R=async()=>{if(N)try{await navigator.clipboard.writeText(N),y(!0),setTimeout(()=>y(!1),1800)}catch{}};return r.jsxs(r.Fragment,{children:[w&&!g&&r.jsx("div",{ref:b,className:"update-banner is-live",role:"status","aria-live":"polite",children:r.jsxs("div",{className:"update-banner-row",children:[r.jsxs("span",{className:"update-banner-text",children:["✓"," You","’","re on the latest version",w&&w!=="✓"?` — ${w} is live`:" — now live","."]}),r.jsx("button",{className:"update-banner-x",onClick:()=>j(null),"aria-label":"Dismiss",children:"×"})]})}),t&&!g&&!w&&r.jsxs("div",{ref:b,className:xx(s),role:"status","aria-live":"polite",children:[r.jsxs("div",{className:"update-banner-row",children:[r.jsx("span",{className:"update-banner-text",children:s==="msi"&&o?`Update available — version ${o}.`:"Update available."}),r.jsxs("div",{style:{display:"flex",gap:"0.5rem",alignItems:"center"},children:[s==="msi"&&r.jsx("a",{className:"btn btn-sm btn-secondary",href:jx(o),target:"_blank",rel:"noopener noreferrer",children:"Download installer"}),s!=="managed"&&s!=="msi"&&r.jsx("button",{className:"btn btn-sm btn-secondary",onClick:T,children:"Update"}),r.jsx("button",{className:"update-banner-x",onClick:f,"aria-label":"Dismiss",children:"×"})]})]}),s==="managed"&&r.jsx("p",{className:"update-banner-hint",children:vx}),s==="msi"&&r.jsx("p",{className:"update-banner-hint",children:wx})]}),g&&r.jsx("div",{className:"update-overlay",children:r.jsxs("div",{className:"update-overlay-card",role:"dialog","aria-modal":"true","aria-label":"Finishing the update",children:[r.jsx("div",{className:"update-spinner"}),r.jsxs("h2",{children:["Finishing the update","…"]}),r.jsxs("p",{children:["Copy this command and run it in your terminal. The gateway will restart, and"," ",r.jsx("strong",{children:"this page updates automatically"})," when it comes back ","—"," no need to refresh."]}),r.jsxs("div",{className:"update-cmd-row",children:[r.jsx("code",{className:"update-cmd",children:N}),r.jsx("button",{className:"btn btn-sm btn-primary",onClick:R,children:v?"Copied":"Copy"})]}),r.jsxs("div",{className:"update-status",children:[r.jsx("span",{className:"update-pulse"})," Waiting for the gateway to restart","…"]}),r.jsxs("div",{className:"update-overlay-actions",children:[r.jsx("button",{className:"btn btn-primary",onClick:()=>S(a),children:"Reload now"}),r.jsx("button",{className:"btn btn-secondary",onClick:()=>p(!1),children:"Cancel"})]})]})})]})}function Uh(){const t=mc(),s=h.useRef(null);return h.useEffect(()=>{if(!t){document.documentElement.style.removeProperty("--sim-banner-h");return}const a=()=>{var u;const c=((u=s.current)==null?void 0:u.offsetHeight)??0;document.documentElement.style.setProperty("--sim-banner-h",`${c}px`)};a();const o=new ResizeObserver(a);return s.current&&o.observe(s.current),()=>{o.disconnect(),document.documentElement.style.removeProperty("--sim-banner-h")}},[t]),t?r.jsx("div",{ref:s,className:"simulation-banner",role:"status","aria-live":"polite",children:r.jsx("span",{className:"simulation-banner-text",children:"Simulation mode — real systems are blocked."})}):null}const bx={system:"◑",light:"☀",dark:"☾"},kx=[{to:"/",icon:"□",label:"Dashboard"},{to:"/approvals",icon:"▷",label:"Pending Approvals"},{to:"/mandates",icon:"☰",label:"Mandates"},{to:"/agent-brief",icon:"▤",label:"Agent Brief"},{to:"/tickets",icon:"▣",label:"Tickets"},{to:"/reports",icon:"▥",label:"Reports"},{to:"/team",icon:"◉",label:"Team"},{to:"/integrations",icon:"⧗",label:"Integrations"},{to:"/settings",icon:"⚙",label:"Settings"}];function Nx({open:t,onClose:s}){const{user:a,activeGroup:o,activeDomain:c,logout:u}=mt(),{theme:f,toggle:g}=Lh(),p=Ut();return h.useEffect(()=>{s()},[p.pathname]),t?r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"mobile-menu-backdrop",onClick:s}),r.jsxs("div",{className:"mobile-menu-panel",children:[a&&r.jsxs("div",{className:"mobile-menu-header",children:[r.jsx("strong",{children:a.name}),r.jsx("span",{style:{fontSize:"0.8rem",color:"var(--text-secondary)"},children:o?`${o.name} / ${c}`:c||"personal"})]}),r.jsx("nav",{className:"mobile-menu-nav",children:kx.map(v=>r.jsxs(cc,{to:v.to,end:v.to==="/",className:({isActive:y})=>`mobile-menu-item${y?" active":""}`,onClick:s,children:[r.jsx("span",{className:"icon",children:v.icon}),v.label]},v.to))}),r.jsxs("div",{className:"mobile-menu-footer",children:[r.jsxs("button",{className:"mobile-menu-action",onClick:()=>{g()},children:[r.jsx("span",{className:"icon",children:bx[f]}),"Theme: ",f]}),r.jsx("button",{className:"mobile-menu-action",onClick:()=>{u(),s()},children:"Logout"})]})]})]}):null}function Wh(t){return t.status==="pending"}function Cx(t,s){return t.filter(Wh).length+s.length}const vr=["proposal-added","proposal-resolved","proposal-approved","proposal-rejected","action-approval-needed","action-resolved","team-membership-changed"],Ex=500;function Hh(){const{user:t,domain:s}=mt(),[a,o]=h.useState(0),c=h.useRef(null),u=h.useCallback(async()=>{if(!t){o(0);return}try{const[g,p]=await Promise.all([O.getMyProposals(s).catch(()=>[]),O.getProposalsForApprover().catch(()=>[])]);o(Cx(g,p))}catch{o(0)}},[t,s]),f=h.useCallback(()=>{c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{u()},Ex)},[u]);return h.useEffect(()=>(u(),()=>{c.current&&clearTimeout(c.current)}),[u]),De(vr[0],f),De(vr[1],f),De(vr[2],f),De(vr[3],f),De(vr[4],f),De(vr[5],f),De(vr[6],f),a}const Cf="Suveren",Tx="/favicon.svg",Rx="M 104.94 61.85 A 41 41 0 1 1 45.39 27.47",fi={x1:74.54,y1:22.74,x2:94.46,y2:34.24},Ax=14,Ix="#f59e0b";function Px(t){const s=yc(t);return s>0?`(${s}) ${Cf}`:Cf}function yc(t){return Number.isFinite(t)&&t>0?Math.floor(t):0}function _x(){const t=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128" fill="none">
52
+ <path class="m" d="${Rx}"/>
53
+ <line class="m" x1="${fi.x1}" y1="${fi.y1}" x2="${fi.x2}" y2="${fi.y2}"/>
54
+ <circle cx="103" cy="103" r="25" fill="${Ix}"/>
55
+ <style>.m{stroke:#111111;stroke-width:${Ax};fill:none;stroke-linecap:round}@media (prefers-color-scheme:dark){.m{stroke:#ffffff;stroke-width:13.3}}</style>
56
+ </svg>`;return`data:image/svg+xml,${encodeURIComponent(t)}`}function $x(){return document.querySelector('link[rel="icon"]')}function Vh(t){const s=yc(t);document.title=Px(s),Gh(s);const a=$x();if(!a)return;const o=s>0?_x():Tx;a.getAttribute("href")!==o&&a.setAttribute("href",o)}function Lx(){Vh(0)}function Gh(t,s=globalThis.navigator){var c;if(!s||typeof s.setAppBadge!="function")return;const a=yc(t),o=a>0?s.setAppBadge(a):s.clearAppBadge?s.clearAppBadge():s.setAppBadge(0);(c=o==null?void 0:o.catch)==null||c.call(o,()=>{})}function zx(){const t=Hh();return h.useEffect(()=>{Vh(t)},[t]),h.useEffect(()=>Lx,[]),null}const Kh="suveren:dockBadgePrompt";function Fx(){var o;if(typeof window>"u"||!("Notification"in window)||!("setAppBadge"in navigator)||!(((o=window.matchMedia)==null?void 0:o.call(window,"(display-mode: standalone)").matches)||navigator.standalone===!0))return!1;const s=navigator.userAgent;if(!(/Safari\//.test(s)&&!/Chrome\/|Chromium\/|Edg\//.test(s))||Notification.permission!=="default")return!1;try{if(localStorage.getItem(Kh))return!1}catch{}return!0}function Ox(){const[t,s]=h.useState(!1),a=Hh();if(h.useEffect(()=>{s(Fx())},[]),!t)return null;const o=()=>{try{localStorage.setItem(Kh,"1")}catch{}s(!1)},c=async()=>{try{await Notification.requestPermission()==="granted"&&Gh(a)}catch{}o()};return r.jsxs("div",{className:"hint-box",style:{marginBottom:"1rem",alignItems:"center"},children:[r.jsxs("div",{className:"hint-body",children:[r.jsx("div",{className:"hint-head",children:"Show waiting approvals on the Dock icon"}),"Safari needs your permission once. The icon then shows how many approvals are waiting, and nothing else."]}),r.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:c,children:"Allow"}),r.jsx("button",{type:"button",className:"btn btn-ghost btn-sm",onClick:o,"aria-label":"Not now",children:"Not now"})]})}function Mx(){const[t,s]=h.useState(!1);return r.jsxs(Gv,{children:[r.jsx(zx,{}),r.jsx(fc,{onMenuToggle:()=>s(!t)}),r.jsx(Dh,{}),r.jsx(Uh,{}),r.jsx(gx,{}),r.jsx(Nx,{open:t,onClose:()=>s(!1)}),r.jsx("div",{className:"main-content",children:r.jsxs("div",{className:"page-inner",children:[r.jsx(Ox,{}),r.jsx(Dy,{})]})})]})}function qh({what:t}){return r.jsxs("div",{className:"human-only-note",role:"note",children:[r.jsx("strong",{children:"Only you."})," ",t==="sign-in"?"Never let an AI or a browser it controls sign in here or see this key.":"Approve only yourself. Never let an AI or a browser it controls open this page or approve for you."]})}function vc(){return typeof navigator<"u"&&navigator.webdriver===!0}const xc="This browser is controlled by automation. Sign-in and approvals are for a person only — open the gateway in your own browser.";function Bx(){const[t,s]=h.useState(""),{login:a,isLoading:o,error:c,clearError:u}=mt(),[f,g]=h.useState(null),p=vc(),v=async()=>{if(!(!t.trim()||p)){u();try{await a(t)}catch(j){if(j instanceof Ih){g(j.summary);return}}}},y=async()=>{g(null),u();try{await a(t,{confirmWipe:!0})}catch{}},w=()=>{g(null)};return r.jsxs(r.Fragment,{children:[r.jsx(fc,{}),r.jsx(Dh,{}),r.jsx(Uh,{}),r.jsxs("div",{className:"login-split",children:[r.jsx("div",{className:"login-split-left",children:r.jsxs("div",{style:{maxWidth:"28rem"},children:[r.jsx("h1",{style:{fontSize:"clamp(2.25rem, 4vw, 3.25rem)",letterSpacing:"-0.03em",lineHeight:1.1,marginBottom:"1.25rem"},children:"Your agents, your intent, your rules."}),r.jsx("p",{style:{fontSize:"1.125rem",color:"var(--text-secondary)",lineHeight:1.6,marginBottom:"3rem"},children:"The gateway runs on your machine, between your agents and the tools they use. Your signature. Your bounds. Your tickets."})]})}),r.jsx("div",{className:"login-split-right",children:r.jsxs("div",{style:{width:"100%",maxWidth:"24rem"},children:[r.jsxs("div",{style:{textAlign:"center",marginBottom:"2.5rem"},children:[r.jsx("div",{style:{fontSize:"1.75rem",fontWeight:700,marginBottom:"0.5rem"},children:"Sign In"}),r.jsx("div",{style:{fontSize:"0.95rem",color:"var(--text-secondary)",lineHeight:1.5},children:"Enter your API key to manage mandates."})]}),r.jsx(qh,{what:"sign-in"}),p&&r.jsx("div",{className:"error-message",children:xc}),c&&r.jsx("div",{className:"error-message",children:c}),r.jsxs("div",{className:"form-group",style:{marginBottom:"1.5rem"},children:[r.jsx("label",{className:"form-label",children:"API Key"}),r.jsx("input",{className:"form-input",type:"password",placeholder:"hap_sk_...",value:t,onChange:j=>s(j.target.value),onKeyDown:j=>j.key==="Enter"&&v(),disabled:o,style:{padding:"0.75rem"}}),r.jsx("div",{className:"form-hint",children:"From your Suveren account."})]}),r.jsx("button",{className:"btn btn-primary btn-full btn-lg",onClick:v,disabled:o||p,style:{marginBottom:"2rem"},children:o?"Signing in...":"Sign In"}),r.jsx("div",{className:"login-divider",children:"New here?"}),r.jsxs("div",{style:{textAlign:"center",marginBottom:"2.5rem"},children:[r.jsxs("p",{style:{fontSize:"0.9rem",color:"var(--text-secondary)",marginBottom:"1rem",lineHeight:1.5},children:["Create an account on Suveren,",r.jsx("br",{}),"then come back to sign in."]}),r.jsx("a",{href:"https://www.suveren.ai/get-started",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-full",style:{textDecoration:"none"},children:"Create Account"})]}),r.jsxs("div",{style:{paddingTop:"1.75rem",borderTop:"1px solid var(--border)"},children:[r.jsx("div",{style:{fontSize:"0.75rem",fontWeight:600,color:"var(--text-tertiary)",marginBottom:"0.875rem"},children:"Getting started"}),r.jsx("div",{style:{fontSize:"0.85rem",color:"var(--text-secondary)",lineHeight:1.8},children:[r.jsxs(r.Fragment,{children:["Create an account at ",r.jsx("a",{href:"https://www.suveren.ai/get-started",target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)"},children:"Suveren"})]}),"Join or create a team to get domain authority","Sign in here with your API key to start giving mandates"].map((j,N)=>r.jsxs("div",{style:{display:"flex",gap:"0.625rem",alignItems:"baseline",marginBottom:N<2?"0.5rem":0},children:[r.jsxs("span",{style:{color:"var(--accent)",fontWeight:700,fontSize:"0.95rem"},children:[N+1,"."]}),j]},N))})]})]})})]}),f&&r.jsx("div",{role:"dialog","aria-modal":"true","aria-labelledby":"wipe-warning-title",style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3,padding:"1rem"},onClick:w,children:r.jsxs("div",{className:"card",onClick:j=>j.stopPropagation(),style:{maxWidth:520,width:"100%",margin:0},children:[r.jsx("h3",{id:"wipe-warning-title",className:"card-title",style:{marginBottom:"0.5rem"},children:"Sign in with a different account?"}),r.jsxs("p",{style:{fontSize:"0.875rem",color:"var(--text-secondary)",marginBottom:"0.75rem"},children:["This gateway already holds data for another account. Signing in with this API key will ",r.jsx("strong",{children:"permanently wipe"})," the following local data:"]}),r.jsxs("ul",{style:{fontSize:"0.875rem",color:"var(--text-secondary)",marginBottom:"1rem",paddingLeft:"1.25rem",lineHeight:1.6},children:[r.jsxs("li",{children:[f.credentialCount," stored service credential",f.credentialCount===1?"":"s",f.credentialIds.length>0&&r.jsxs("span",{style:{color:"var(--text-tertiary)",fontSize:"0.825rem"},children:[" ","(",f.credentialIds.slice(0,5).join(", "),f.credentialIds.length>5?`, +${f.credentialIds.length-5} more`:"",")"]})]}),r.jsxs("li",{children:[f.serviceCount," configured integration",f.serviceCount===1?"":"s"]}),r.jsx("li",{children:"The local E2EE keypair (a new one will be generated for this account)"}),r.jsx("li",{children:"Any unsynchronised gate content stored locally"})]}),r.jsx("p",{style:{fontSize:"0.875rem",color:"var(--text-secondary)",marginBottom:"1rem"},children:"Mandates and tickets on the Authority Server are NOT affected — only this gateway's local state is wiped."}),r.jsx("p",{style:{fontSize:"0.825rem",color:"var(--text-tertiary)",marginBottom:"1rem"},children:"If this isn't what you wanted, cancel and sign back in with the original API key, or use a different gateway instance for this account."}),r.jsxs("div",{style:{display:"flex",gap:"0.5rem",justifyContent:"flex-end"},children:[r.jsx("button",{className:"btn btn-ghost",onClick:w,disabled:o,children:"Cancel"}),r.jsx("button",{className:"btn btn-secondary",style:{color:"var(--danger, #e53e3e)"},onClick:y,disabled:o,children:o?"Signing in...":"Wipe local data and sign in"})]})]})})]})}function Dx(t,s){return!s&&t!=null}function Ux(t,s){return t==="join-waiting"&&s==="team"}function Wx(t,s,a,o){return a!=null||t!=="join-waiting"||s==="team"?null:o}function Hx(t){return`${t} personal mandate${t===1?"":"s"}`}function Vx({mandates:t,pendingProposals:s}){return t.length===0&&s===0?r.jsx("p",{style:{fontSize:"0.825rem",color:"var(--text-secondary)"},children:"You have no personal mandates to end."}):r.jsxs("div",{style:{background:"var(--bg-elevated)",borderRadius:"0.5rem",padding:"0.75rem 1rem",margin:"0.75rem 0"},children:[r.jsx("div",{style:{fontSize:"0.7rem",fontWeight:600,letterSpacing:"0.04em",textTransform:"uppercase",color:"var(--text-tertiary)",marginBottom:"0.5rem"},children:"Your personal mandates end"}),r.jsx("ul",{style:{listStyle:"none",padding:0,margin:0,fontSize:"0.825rem"},children:t.map(a=>r.jsxs("li",{style:{display:"flex",justifyContent:"space-between",gap:"0.5rem",padding:"0.25rem 0",borderBottom:"1px solid var(--border)"},children:[r.jsx("span",{children:a.title||a.profileId}),r.jsx("span",{style:{color:"var(--text-tertiary)"},children:a.commitmentMode??""})]},a.id))}),r.jsxs("p",{style:{fontSize:"0.75rem",color:"var(--text-tertiary)",marginTop:"0.5rem",marginBottom:0},children:["They stay in your history; their tickets stay verifiable.",s>0&&` ${s} personal proposal${s===1?"":"s"} waiting for approval end${s===1?"s":""} too.`]})]})}function Gx(){const{mode:t,pendingRequest:s,refreshGroups:a}=mt(),o=mn(),[c,u]=h.useState("choose"),[f,g]=h.useState(""),[p,v]=h.useState(""),[y,w]=h.useState(null),[j,N]=h.useState(null),[b,S]=h.useState(""),[k,T]=h.useState(""),[R,P]=h.useState(!1),A=h.useRef(!1);h.useEffect(()=>{Dx(s,A.current)&&(A.current=!0,u("join-waiting"))},[s]),h.useEffect(()=>{Ux(c,t)&&o("/")},[c,t,o]);const B=h.useRef(null);h.useEffect(()=>{if(s){B.current=s.groupName;return}const F=Wx(c,t,s,B.current);F&&(S(F),u("join-declined"),B.current=null)},[s,c,t]),h.useEffect(()=>{if(c!=="join-waiting")return;const F=setInterval(()=>{a()},5e3);return()=>clearInterval(F)},[c,a]);const H=h.useCallback(()=>{u("choose"),T(""),w(null),N(null),g(""),v("")},[]),G=async()=>{if(f.trim()){P(!0),T("");try{const F=await O.getJoinPreview(f.trim());w(F),u("join-preview")}catch(F){T(F instanceof Error?F.message:"Invalid or expired invite code")}finally{P(!1)}}},me=async()=>{P(!0),T("");try{await O.requestToJoinGroup(f.trim()),await a(),u("join-waiting")}catch(F){T(F instanceof Error?F.message:"Failed to join group")}finally{P(!1)}},q=async()=>{P(!0),T("");try{await O.withdrawJoinRequest(),await a(),H()}catch(F){T(F instanceof Error?F.message:"Failed to withdraw request")}finally{P(!1)}},ce=async()=>{u("create"),T(""),P(!0);try{const F=await O.getCreatePreview();N(F)}catch(F){T(F instanceof Error?F.message:"Failed to load preview")}finally{P(!1)}},ee=async()=>{if(p.trim()){P(!0),T("");try{await O.createGroup(p.trim()),await a(),o("/")}catch(F){T(F instanceof Error?F.message:"Failed to create group")}finally{P(!1)}}};return r.jsxs(r.Fragment,{children:[r.jsx(fc,{}),r.jsx("div",{className:"main-content no-sidebar",style:{marginTop:"var(--nav-height)"},children:r.jsxs("div",{style:{maxWidth:"30rem",margin:"3rem auto",padding:"0 1rem"},children:[k&&r.jsx("div",{className:"error-message",children:k}),c==="choose"&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{style:{textAlign:"center",marginBottom:"2.5rem"},children:[r.jsx("h2",{style:{fontSize:"1.5rem",marginBottom:"0.5rem"},children:"Join or create a team"}),r.jsx("p",{style:{fontSize:"0.9rem",color:"var(--text-secondary)",lineHeight:1.6},children:"An account is Personal or in one team — never both. Joining or creating a team moves your account: your personal mandates end (kept in your history)."})]}),r.jsxs("div",{className:"card",style:{marginBottom:"1rem"},children:[r.jsx("h4",{style:{fontSize:"0.95rem",marginBottom:"0.25rem"},children:"Join an existing team"}),r.jsx("p",{style:{fontSize:"0.825rem",color:"var(--text-secondary)",marginBottom:"1rem"},children:"Ask your team admin for an invite code."}),r.jsxs("div",{className:"invite-input-row",children:[r.jsx("input",{className:"form-input",placeholder:"Paste invite code...",value:f,onChange:F=>g(F.target.value),onKeyDown:F=>F.key==="Enter"&&G(),style:{fontFamily:"'SF Mono', Monaco, monospace",fontSize:"0.85rem"},disabled:R}),r.jsx("button",{className:"btn btn-primary",onClick:G,disabled:R||!f.trim(),children:R?"Checking…":"Continue"})]})]}),r.jsxs("div",{className:"card",children:[r.jsx("h4",{style:{fontSize:"0.95rem",marginBottom:"0.25rem"},children:"Create a new team"}),r.jsx("p",{style:{fontSize:"0.825rem",color:"var(--text-secondary)",marginBottom:"1rem"},children:"Start a new team and invite members."}),r.jsx("button",{className:"btn btn-secondary",onClick:ce,disabled:R,children:"Create a team"})]})]}),c==="join-preview"&&y&&r.jsxs("div",{className:"card",children:[r.jsxs("h3",{style:{marginBottom:"0.25rem"},children:["Join team ",y.groupName,"?"]}),r.jsxs("p",{style:{fontSize:"0.875rem",color:"var(--text-secondary)",marginBottom:"0.75rem"},children:["Your account ",r.jsx("strong",{children:"moves to the team"}),". From then on you work under the team's rules — its approvers and limits."]}),r.jsx(Vx,{mandates:y.personalMandates,pendingProposals:y.pendingPersonalProposals}),r.jsxs("p",{style:{fontSize:"0.8rem",color:"var(--text-tertiary)",marginBottom:"1rem"},children:["The team admin (",y.admin.name,") confirms your request. Nothing changes until then."]}),r.jsxs("div",{style:{display:"flex",gap:"0.75rem"},children:[r.jsx("button",{className:"btn btn-primary",onClick:me,disabled:R,children:R?"Asking…":"Ask to join"}),r.jsx("button",{className:"btn btn-ghost",onClick:H,disabled:R,children:"Cancel"})]})]}),c==="join-waiting"&&r.jsxs("div",{className:"card",children:[r.jsxs("h3",{style:{marginBottom:"0.25rem"},children:["Request sent to team ",(s==null?void 0:s.groupName)??""]}),r.jsx("p",{style:{fontSize:"0.875rem",color:"var(--text-secondary)",marginBottom:"1rem"},children:"Waiting for the team admin to confirm. Until then your account stays Personal and your mandates keep working."}),r.jsx("button",{className:"btn btn-secondary",onClick:q,disabled:R,children:R?"Withdrawing…":"Withdraw request"})]}),c==="join-declined"&&r.jsxs("div",{className:"card",children:[r.jsxs("h3",{style:{marginBottom:"0.25rem"},children:["Request to ",b," ended"]}),r.jsx("p",{style:{fontSize:"0.875rem",color:"var(--text-secondary)",marginBottom:"1rem"},children:"The team admin declined your request, or it was withdrawn. Your account stays Personal."}),r.jsx("button",{className:"btn btn-primary",onClick:H,disabled:R,children:"Back"})]}),c==="create"&&r.jsxs("div",{className:"card",children:[r.jsx("h3",{style:{marginBottom:"0.75rem"},children:"Create a team"}),r.jsxs("div",{className:"form-group",style:{marginBottom:"0.75rem"},children:[r.jsx("label",{style:{fontSize:"0.825rem",display:"block",marginBottom:"0.375rem"},children:"Team name"}),r.jsx("input",{className:"form-input",placeholder:"e.g., Acme Corp",value:p,onChange:F=>v(F.target.value),onKeyDown:F=>F.key==="Enter"&&ee(),disabled:R,autoFocus:!0})]}),j&&r.jsxs("div",{className:"alert alert-info",style:{color:"white"},children:["Your account moves to the new team. Your ",Hx(j.personalMandates.length)," end (kept in your history)."]}),r.jsxs("div",{style:{display:"flex",gap:"0.75rem",marginTop:"1rem"},children:[r.jsx("button",{className:"btn btn-primary",onClick:ee,disabled:R||!p.trim(),children:R?"Creating…":"Create team and move my account"}),r.jsx("button",{className:"btn btn-ghost",onClick:H,disabled:R,children:"Cancel"})]})]})]})})]})}const Ef={"claude-code":{label:"Claude Code",snippet:t=>`claude mcp add --transport http suveren ${t}/mcp`},"claude-desktop":{label:"Claude Desktop",snippet:t=>`Add to ~/Library/Application Support/Claude/claude_desktop_config.json, then restart Claude Desktop:
57
+
58
+ ${JSON.stringify({mcpServers:{suveren:{command:"npx",args:["mcp-remote@latest",`${t}/mcp`,"--allow-http"]}}},null,2)}`},"chatgpt-codex":{label:"ChatGPT / Codex",snippet:t=>`Add to ~/.codex/config.toml:
59
+
60
+ [mcp_servers.suveren]
61
+ url = "${t}/mcp"
62
+
63
+ Or: codex mcp add suveren --url ${t}/mcp`},other:{label:"Other",snippet:t=>`Streamable HTTP: POST ${t}/mcp
64
+ SSE transport: GET ${t}/sse
65
+ Health check: GET ${t}/health`}},Tf=["claude-code","claude-desktop","chatgpt-codex","other"];function Ul({mcpEndpoint:t}){const[s,a]=h.useState(Tf[0]),[o,c]=h.useState(!1),u=h.useCallback(async g=>{try{await navigator.clipboard.writeText(g),c(!0),setTimeout(()=>c(!1),2e3)}catch{}},[]),f=Ef[s].snippet(t);return r.jsxs("div",{children:[r.jsx("div",{className:"gate-content-label",children:"MCP Endpoint"}),r.jsx("div",{className:"mcp-endpoint",children:t}),r.jsx("div",{className:"mcp-tabs",children:Tf.map(g=>r.jsx("button",{className:`mcp-tab${s===g?" active":""}`,onClick:()=>a(g),children:Ef[g].label},g))}),r.jsx("pre",{className:"mcp-snippet",children:f}),r.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>u(f),children:o?"Copied":"Copy"})]})}const Wl="suveren-setup-ai-skipped",Hl="suveren-setup-agent-done",Vl="suveren-setup-dismissed",Kx={"hap-setup-ai-skipped":Wl,"hap-setup-agent-done":Hl,"hap-setup-dismissed":Vl};function qx(){for(const[t,s]of Object.entries(Kx)){const a=localStorage.getItem(t);a!==null&&localStorage.getItem(s)===null&&localStorage.setItem(s,a),a!==null&&localStorage.removeItem(t)}}qx();function Yx({aiConfigured:t,hasRunningIntegration:s,hasActiveAuth:a,hasAgentConnected:o,mcpEndpoint:c}){const[u,f]=h.useState(()=>localStorage.getItem(Wl)==="true"),[g,p]=h.useState(()=>localStorage.getItem(Hl)==="true"),[v,y]=h.useState(()=>localStorage.getItem(Vl)==="true"),[w,j]=h.useState(null),N=[{label:"AI Assistant",detail:"A trusted AI helps you think through mandates — surfacing risks and asking the right questions.",to:"/settings",status:t?"done":u?"skipped":"pending",optional:!0},{label:"Connect a service",to:"/integrations",status:s?"done":"pending"},{label:"Give your agent a mandate",to:"/mandates?new=1",status:a?"done":"pending"},{label:"Connect your agent",status:o||g?"done":"pending"}],b=N.filter(A=>A.status==="done"||A.status==="skipped").length,S=b===N.length,k=h.useCallback(()=>{localStorage.setItem(Wl,"true"),f(!0)},[]),T=h.useCallback(()=>{localStorage.setItem(Hl,"true"),p(!0),j(null)},[]),R=h.useCallback(()=>{localStorage.setItem(Vl,"true"),y(!0)},[]);if(v||S)return null;const P=N.findIndex(A=>A.status==="pending");return r.jsxs("div",{style:{border:"2px solid var(--accent)",borderRadius:"0.75rem",padding:"1.5rem",marginBottom:"1.5rem",background:"var(--bg-elevated)"},children:[r.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:"1.25rem"},children:[r.jsx("h2",{style:{fontSize:"1.1rem",fontWeight:700,margin:0},children:"Get Started"}),r.jsx("button",{onClick:R,style:{background:"none",border:"none",color:"var(--text-tertiary)",cursor:"pointer",fontSize:"1.1rem",padding:"0 0.25rem",lineHeight:1},title:"Hide setup guide",children:"×"})]}),r.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem"},children:N.map((A,B)=>{const H=B===P,G=A.status==="done"||A.status==="skipped"?"●":"○",me=A.status==="done"?"var(--success)":A.status==="skipped"?"var(--text-tertiary)":H?"var(--accent)":"var(--text-tertiary)";return r.jsxs("div",{children:[r.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"0.75rem",padding:H?"0.75rem":"0.25rem 0",borderRadius:H?"0.5rem":void 0,background:H?"var(--accent-subtle)":void 0},children:[r.jsx("span",{style:{color:me,fontSize:"0.75rem",marginTop:"0.2rem",flexShrink:0},children:G}),r.jsxs("div",{style:{flex:1,minWidth:0},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem"},children:[A.to&&A.status==="pending"?r.jsx(xt,{to:A.to,style:{fontSize:"0.9rem",fontWeight:H?600:500,color:H?"var(--accent)":"var(--text-primary)",textDecoration:"none"},children:A.label}):A.status==="pending"&&B===3?r.jsx("button",{onClick:()=>j(w===3?null:3),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontSize:"0.9rem",fontWeight:H?600:500,color:H?"var(--accent)":"var(--text-primary)"},children:A.label}):r.jsx("span",{style:{fontSize:"0.9rem",fontWeight:500,color:A.status==="done"?"var(--text-secondary)":"var(--text-tertiary)"},children:A.label}),A.optional&&A.status==="pending"&&r.jsx("span",{style:{fontSize:"0.7rem",color:"var(--text-tertiary)",fontStyle:"italic"},children:"optional"}),A.status==="skipped"&&r.jsx("span",{style:{fontSize:"0.7rem",color:"var(--text-tertiary)"},children:"skipped"})]}),A.detail&&A.status==="pending"&&H&&r.jsx("div",{style:{fontSize:"0.8rem",color:"var(--text-secondary)",marginTop:"0.25rem",lineHeight:1.5},children:A.detail})]}),A.optional&&A.status==="pending"&&r.jsx("button",{onClick:k,style:{background:"none",border:"none",color:"var(--text-tertiary)",cursor:"pointer",fontSize:"0.75rem",padding:"0.125rem 0.5rem",flexShrink:0},children:"Skip"}),A.to&&A.status==="pending"&&r.jsx(xt,{to:A.to,style:{color:"var(--text-tertiary)",textDecoration:"none",fontSize:"0.8rem",flexShrink:0},children:"›"})]}),B===3&&w===3&&r.jsxs("div",{style:{marginTop:"0.75rem",marginLeft:"1.5rem",padding:"1rem",background:"var(--bg-main)",border:"1px solid var(--border)",borderRadius:"0.5rem"},children:[r.jsx(Ul,{mcpEndpoint:c}),r.jsx("button",{className:"btn btn-primary btn-sm",style:{marginTop:"0.75rem"},onClick:T,children:"Done"})]})]},B)})}),r.jsxs("div",{style:{marginTop:"1.25rem"},children:[r.jsx("div",{style:{height:"4px",background:"var(--border)",borderRadius:"2px",overflow:"hidden"},children:r.jsx("div",{style:{height:"100%",width:`${b/N.length*100}%`,background:"var(--accent)",borderRadius:"2px",transition:"width 0.3s ease"}})}),r.jsxs("div",{style:{fontSize:"0.7rem",color:"var(--text-tertiary)",marginTop:"0.375rem"},children:[b," of ",N.length," complete"]})]})]})}function Yh(t,s=null){const a=[t.hasContact,t.hasDelegationMandate,t.delegationProposalCount>0],o=a.every(Boolean),c=t.otherMandateCount===0&&!o,u=a.findIndex(v=>!v),f=s!==null&&a[s]===!1?s:u,g=t.managed?"managed":"self",p=v=>a[v]?{status:"done"}:v!==f?{status:"todo"}:v===1?{status:"open",variant:g,simulationOn:t.simulationOn}:v===0?{status:"open",variant:g}:{status:"open"};return{visible:c,step1:p(0),step2:p(1),step3:p(2)}}const Jx="/mandates?new=1&profile=delegation";function Rf({text:t}){const[s,a]=h.useState(!1),o=h.useCallback(async()=>{try{await navigator.clipboard.writeText(t),a(!0),setTimeout(()=>a(!1),2e3)}catch{}},[t]);return r.jsx("button",{className:"btn btn-secondary btn-sm",onClick:o,children:s?"Copied":"Copy"})}function Pl({todo:t,onOpen:s,children:a}){return t?r.jsx("button",{type:"button",className:"flow-step-title flow-todo-title flow-step-open-btn",onClick:s,children:a}):r.jsx("span",{className:"flow-step-title",children:a})}function Qx({contact:t,hasDelegationMandate:s,otherMandateCount:a,delegationProposalCount:o,managed:c,simulationOn:u,mcpEndpoint:f}){const g={hasContact:t!==null,hasDelegationMandate:s,otherMandateCount:a,delegationProposalCount:o,managed:c,simulationOn:u},[p,v]=h.useState(null),y=Yh(g,p);if(!y.visible)return null;const w=`Please connect to the Suveren gateway: MCP server at ${f}/mcp`;return r.jsxs("div",{className:"card setup-card",children:[r.jsx("h2",{className:"card-title",children:"Get started"}),r.jsx("p",{className:"setup-intro",children:"You decide what your AI can do — it acts only within that. Every action that changes something gets a signed ticket."}),r.jsxs("div",{className:"flow-step",children:[r.jsxs("div",{className:"flow-step-head",children:[r.jsx("span",{className:`flow-step-marker flow-${y.step1.status==="open"?"open":y.step1.status==="done"?"done":"todo"}`,children:y.step1.status==="done"?"✓":"1"}),y.step1.status==="done"&&t?r.jsxs("span",{className:"flow-step-title flow-done-title",children:[t.clientName," connected · last contact ",Bh(Date.parse(t.lastSeenAt),Date.now()).toLowerCase()]}):r.jsx(Pl,{todo:y.step1.status==="todo",onOpen:()=>v(0),children:"Connect your AI"})]}),y.step1.status==="open"&&r.jsx("div",{className:"flow-step-body",children:y.step1.variant==="managed"?r.jsxs(r.Fragment,{children:[r.jsx("p",{children:"Your IT sets up the connection. Open your AI — if Suveren isn't there, contact your IT."}),r.jsxs("details",{className:"int-details",children:[r.jsx("summary",{children:"For your IT"}),r.jsx("div",{style:{marginTop:"0.75rem"},children:r.jsx(Ul,{mcpEndpoint:f})})]})]}):r.jsxs(r.Fragment,{children:[r.jsx("p",{children:"Ask your AI to connect to Suveren. Copy this into it:"}),r.jsx("div",{className:"gate-content-block",style:{marginBottom:"0.75rem"},children:r.jsxs("div",{className:"quote-box",children:[r.jsx("span",{className:"quote-text",children:w}),r.jsx(Rf,{text:w})]})}),r.jsx("p",{className:"cta-helper",style:{marginTop:0,marginBottom:"0.75rem"},children:"If your AI can't add it itself, it will tell you how. In ChatGPT, use a local session."}),r.jsxs("details",{className:"int-details",children:[r.jsx("summary",{children:"Set it up by hand"}),r.jsx("div",{style:{marginTop:"0.75rem"},children:r.jsx(Ul,{mcpEndpoint:f})})]})]})})]}),r.jsxs("div",{className:"flow-step",children:[r.jsxs("div",{className:"flow-step-head",children:[r.jsx("span",{className:`flow-step-marker flow-${y.step2.status==="open"?"open":y.step2.status==="done"?"done":"todo"}`,children:y.step2.status==="done"?"✓":"2"}),y.step2.status==="done"?r.jsxs("span",{className:"flow-step-title flow-done-title",children:["Delegation mandate given · ",r.jsx(xt,{to:"/mandates",children:"review or revoke under Mandates"})]}):r.jsx(Pl,{todo:y.step2.status==="todo",onOpen:()=>v(1),children:"Give the Delegation mandate"})]}),y.step2.status==="open"&&r.jsxs("div",{className:"flow-step-body",children:[r.jsx("p",{children:"Delegation lets your AI propose the rest of its own setup — new mandates and its working instructions. It can only propose; nothing changes until you approve it."}),r.jsxs("ul",{className:"bound-list",children:[r.jsx("li",{children:"Read the setup guides"}),r.jsx("li",{children:"Propose new mandates — each waits for your approval"}),r.jsx("li",{children:"Propose an updated agent brief — also waits for your approval"})]}),y.step2.simulationOn?r.jsxs(r.Fragment,{children:[r.jsx(xt,{to:Jx,className:"btn btn-primary",children:"Give the Delegation mandate →"}),r.jsx("p",{className:"cta-helper",children:"You set the daily limit in the next step."}),y.step2.variant==="managed"&&r.jsx("p",{className:"managed-note",children:"In a company team you may need approver rights — ask your IT if the button is refused."})]}):r.jsx("p",{className:"managed-note",style:{marginTop:0},children:y.step2.variant==="managed"?"Delegation works in simulation mode only. Ask your IT to turn on simulation mode.":r.jsxs(r.Fragment,{children:["Delegation works in simulation mode only. Turn it on with ",r.jsx("code",{children:"suveren-gateway simulation on"})," and restart."]})})]})]}),r.jsxs("div",{className:"flow-step",children:[r.jsxs("div",{className:"flow-step-head",children:[r.jsx("span",{className:`flow-step-marker flow-${y.step3.status==="open"?"open":"todo"}`,children:"3"}),r.jsx(Pl,{todo:y.step3.status==="todo",onOpen:()=>v(2),children:"Ask your AI: “How do I start with Suveren?”"})]}),y.step3.status==="open"&&r.jsxs("div",{className:"flow-step-body",children:[r.jsx("div",{className:"gate-content-block",style:{marginBottom:"0.875rem"},children:r.jsxs("div",{className:"quote-box",children:[r.jsx("span",{className:"quote-text",children:"“How do I start with Suveren?”"}),r.jsx(Rf,{text:"How do I start with Suveren?"})]})}),r.jsxs("p",{children:["It will interview you, suggest test data, and propose mandates and a brief. Approve its proposals under ",r.jsx(xt,{to:"/approvals",children:"Approvals"}),"."]})]})]})]})}function Xx(){const[t,s]=h.useState(null);return h.useEffect(()=>{let a=!1;return fetch("/health").then(o=>o.json()).then(o=>{!a&&typeof o.mcpPort=="number"&&s(`http://localhost:${o.mcpPort}`)}).catch(()=>{}),()=>{a=!0}},[]),t}function Zx(t){if(!t||typeof t!="object")return{simulation:null,locked:!1};const s=Array.isArray(t.policyLocked)&&t.policyLocked.includes("simulation");return{simulation:typeof t.simulation=="boolean"?t.simulation:null,locked:s}}function Jh(){const[t,s]=h.useState({simulation:null,locked:!1});return h.useEffect(()=>{let a=!1;return fetch("/health").then(o=>o.json()).then(o=>{a||s(Zx(o))}).catch(()=>{}),()=>{a=!0}},[]),t}function e0(t){return!t||typeof t!="object"?!1:Array.isArray(t.policyLocked)&&t.policyLocked.length>0}function t0(){const[t,s]=h.useState(!1);return h.useEffect(()=>{let a=!1;const o=()=>{fetch("/health").then(f=>f.json()).then(f=>{a||s(e0(f))}).catch(()=>{})};o();const c=setInterval(o,3e4),u=()=>{document.visibilityState==="visible"&&o()};return document.addEventListener("visibilitychange",u),()=>{a=!0,clearInterval(c),document.removeEventListener("visibilitychange",u)}},[]),t}function jr({variant:t="base",style:s,className:a,...o}){const c=t==="title"?"skeleton skeleton-title":t==="line"?"skeleton skeleton-line":t==="line-sm"?"skeleton skeleton-line-sm":"skeleton";return r.jsx("span",{className:`${c}${a?` ${a}`:""}`,style:s,role:"status","aria-busy":"true","aria-label":o["aria-label"]??"Loading"})}function _l(){return r.jsxs("div",{className:"skeleton-card",role:"status","aria-busy":"true","aria-label":"Loading",children:[r.jsx(jr,{style:{width:"0.5rem",height:"0.5rem",borderRadius:"50%",flexShrink:0}}),r.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:"0.35rem"},children:[r.jsx(jr,{variant:"line",style:{width:"35%"}}),r.jsx(jr,{variant:"line-sm",style:{width:"65%"}})]})]})}function n0(){const[t,s]=h.useState([]);return Dt(async()=>{try{const{skipped:o}=await O.getSkippedCommitments();s(o)}catch{}},3e4),t.length===0?null:r.jsxs("div",{className:"card",style:{padding:"1.5rem",marginTop:"1.5rem",borderLeft:"3px solid var(--warn, #b58900)"},children:[r.jsxs("h2",{style:{fontSize:"1rem",fontWeight:700,margin:0},children:["Approved, but not run here (",t.length,")"]}),r.jsx("p",{style:{margin:"0.5rem 0 1rem",fontSize:"0.9rem",color:"var(--text-secondary)"},children:"These were approved, but this gateway has no local record of asking for them — usually because a different device/installation of yours submitted them, or its local record is gone. Re-run the same request on this gateway to execute it here."}),r.jsx("ul",{style:{margin:0,paddingLeft:"1.25rem",fontSize:"0.9rem"},children:t.map(o=>r.jsxs("li",{style:{marginBottom:"0.35rem"},children:[r.jsx("code",{children:o.tool})," ",r.jsxs("span",{style:{color:"var(--text-tertiary)"},children:["(",o.id,")"]})]},o.id))})]})}function r0(t,s){return s&&!Qs(t.manifest)}function s0(t,s=!1){var o;const a=[];for(const c of t)r0(c,s)||(c.state==="error"?a.push({label:"Integration error",detail:(o=c.integration)!=null&&o.error?`${c.manifest.name}: ${c.integration.error}`:`${c.manifest.name} is not running`,to:"/integrations",color:"var(--danger)"}):c.state==="not-running"&&(Qs(c.manifest)?a.push({label:`${c.manifest.name} is not running`,detail:"Activate it to use it in the test.",to:"/integrations",color:"var(--danger)"}):a.push({label:"Integration stopped",detail:`${c.manifest.name} is not running`,to:"/integrations",color:"var(--danger)"})));return a}function a0(t){const s=t.filter(a=>a.state==="paused");return s.length===0?null:{count:s.length,namesText:s.map(a=>a.manifest.name).join(", ")}}const i0=1800;function Yr(t){return t.replace(/@.*$/,"").split("/").pop()??t}function o0(){const{domain:t}=mt(),[s,a]=h.useState([]),[o,c]=h.useState([]),[u,f]=h.useState([]),[g,p]=h.useState(!0),[v,y]=h.useState(!1),[w,j]=h.useState([]),[N,b]=h.useState(!1),[S,k]=h.useState(!1),[T,R]=h.useState(null),[P,A]=h.useState(!1),{entries:B,activeSessions:H,loading:G}=pc(),me=Xx(),q=!G,{simulation:ce}=Jh(),ee=ce===!0,F=t0(),re=h.useCallback(()=>{O.getMyAttestations().then(K=>{a(K),y(!0)}).catch(()=>y(!0)),O.getArchivedMandates().then(j).catch(()=>j([])),O.getMyProposals(t).then(K=>{c(K),b(!0)}).catch(()=>b(!0)),O.getProposalsForApprover().then(K=>f(K)).catch(()=>f([])),O.getCredential("ai-config").then(K=>{p(K.configured),k(!0)}).catch(()=>k(!0)),O.getAgentContact().then(K=>{R(K.contact),A(!0)}).catch(()=>A(!0))},[t]);De("attestation-changed",re),De("proposal-added",re),De("proposal-resolved",re),De("proposal-approved",re),De("proposal-rejected",re),De("execution-failed",re),Dt(re,3e5,t);const Y=v&&N&&S&&q&&P&&ce!==null,se=Oh(s,{archivedSet:new Set(w)}),ye=se.active,we=se.expired,J=ye.some(K=>Yr(K.profile_id)==="delegation"),V=ye.filter(K=>Yr(K.profile_id)!=="delegation").length,W=o.filter(K=>Yr(K.profileId)==="delegation").length,C=Yh({hasContact:T!==null,hasDelegationMandate:J,otherMandateCount:V,delegationProposalCount:W,managed:F,simulationOn:ee}),L=ee&&C.visible,fe=ye.filter(K=>K.remaining_seconds!==null&&K.remaining_seconds<=i0),Q=o.filter(Wh),z=B.filter(K=>K.state==="running"),X=B.filter(K=>K.state==="starting"),ne=a0(B),ie=[];for(const K of u)ie.push({label:"Approval needed",detail:`${K.tool} — above-cap action under ${Yr(K.profileId)}`,to:"/approvals",color:"var(--warning)"});for(const K of Q)ie.push({label:"Approval pending",detail:`${K.tool} awaiting your approval`,to:"/approvals",color:"var(--warning)"});for(const K of fe){const ke=Math.ceil((K.remaining_seconds??0)/60);ie.push({label:"Expiring soon",detail:`${K.title??Yr(K.profile_id)} — ${ke} min remaining`,to:"/mandates",color:"var(--warning)"})}for(const K of we)ie.push({label:"Expired",detail:K.title??Yr(K.profile_id),to:"/mandates",color:"var(--danger)"});ie.push(...s0(B,ee));for(const K of X)ie.push({label:"Integration starting",detail:`${K.manifest.name} is coming up…`,to:"/integrations",color:"var(--warning)"});for(const K of B)K.authStatus==="failed"&&K.state!=="not-running"&&K.state!=="error"&&K.state!=="paused"&&ie.push({label:"Reconnect needed",detail:`${K.manifest.name}: authorization expired — reconnect to restore access`,to:"/integrations",color:"var(--danger)"});return g||ie.push({label:"AI Assistant",detail:"Not configured — needed for gate advisory",to:"/settings",color:"var(--text-tertiary)"}),r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"page-header",children:r.jsx("h1",{className:"page-title",children:"Dashboard"})}),Y&&me&&(L?r.jsx(Qx,{contact:T,hasDelegationMandate:J,otherMandateCount:V,delegationProposalCount:W,managed:F,simulationOn:ee,mcpEndpoint:me}):!ee&&r.jsx(Yx,{aiConfigured:g,hasRunningIntegration:z.length>0,hasActiveAuth:ye.length>0,hasAgentConnected:H>0,mcpEndpoint:me})),!L&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(8rem, 1fr))",gap:"0.75rem",marginBottom:"1.5rem"},children:[r.jsx(xt,{to:"/mandates",style:{textDecoration:"none"},children:r.jsxs("div",{className:"card",style:{padding:"1rem",textAlign:"center"},children:[v?r.jsx("div",{style:{fontSize:"1.5rem",fontWeight:700,color:ye.length>0?"var(--success)":"var(--text-tertiary)"},children:ye.length}):r.jsx(jr,{variant:"title"}),r.jsx("div",{style:{fontSize:"0.75rem",color:"var(--text-secondary)"},children:"Active"})]})}),r.jsx(xt,{to:"/approvals",style:{textDecoration:"none"},children:r.jsxs("div",{className:"card",style:{padding:"1rem",textAlign:"center"},children:[N?r.jsx("div",{style:{fontSize:"1.5rem",fontWeight:700,color:Q.length>0?"var(--warning)":"var(--text-tertiary)"},children:Q.length}):r.jsx(jr,{variant:"title"}),r.jsx("div",{style:{fontSize:"0.75rem",color:"var(--text-secondary)"},children:"Pending Approvals"})]})}),r.jsx(xt,{to:"/mandates",style:{textDecoration:"none"},children:r.jsxs("div",{className:"card",style:{padding:"1rem",textAlign:"center"},children:[v?r.jsx("div",{style:{fontSize:"1.5rem",fontWeight:700,color:we.length>0?"var(--danger)":"var(--text-tertiary)"},children:we.length}):r.jsx(jr,{variant:"title"}),r.jsx("div",{style:{fontSize:"0.75rem",color:"var(--text-secondary)"},children:"Expired"})]})}),r.jsx(xt,{to:"/integrations",style:{textDecoration:"none"},children:r.jsxs("div",{className:"card",style:{padding:"1rem",textAlign:"center"},children:[q?r.jsx("div",{style:{fontSize:"1.5rem",fontWeight:700,color:z.length>0?"var(--success)":"var(--text-tertiary)"},children:z.length}):r.jsx(jr,{variant:"title"}),r.jsx("div",{style:{fontSize:"0.75rem",color:"var(--text-secondary)"},children:"Integrations Running"})]})})]}),r.jsxs("section",{className:"card attention","aria-label":"Needs your attention",children:[r.jsxs("div",{className:"card-header",children:[r.jsx("h2",{className:"card-title",children:"Needs your attention"}),ie.length>0&&r.jsx("span",{className:"rb-count",children:ie.length})]}),ie.length>0?r.jsx("div",{className:"attention-rows",children:ie.map((K,ke)=>r.jsxs(xt,{to:K.to,className:"attention-row",children:[r.jsx("span",{className:"attention-dot",style:{background:K.color},"aria-hidden":"true"}),r.jsxs("div",{style:{flex:1,minWidth:0},children:[r.jsx("div",{style:{fontSize:"0.8rem",fontWeight:600,color:"var(--text-primary)"},children:K.label}),r.jsx("div",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:K.detail})]}),r.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-tertiary)"},children:"›"})]},ke))}):Y?r.jsxs("div",{className:"all-clear",children:[r.jsx("span",{className:"rb-mark","aria-hidden":"true",children:r.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("path",{d:"M20 6 9 17l-5-5"})})}),r.jsx("h3",{children:"All clear"}),r.jsx("p",{children:"Nothing needs your attention."})]}):r.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[r.jsx(_l,{}),r.jsx(_l,{}),r.jsx(_l,{})]})]})]}),ne&&r.jsxs("div",{className:"sim-paused-summary",role:"status",children:[r.jsx("span",{className:"sim-paused-summary-icon","aria-hidden":"true",children:"⏸"}),r.jsxs("span",{children:[r.jsxs("b",{children:[ne.count," real system",ne.count===1?"":"s"," ",ne.count===1?"is":"are"," paused"]})," ","while simulation mode is on — ",ne.namesText,"."]})]}),r.jsx(n0,{}),r.jsx(Zv,{})]})}const l0=["Scope & Limits","Intent","Sign"];function Qh({currentStep:t,onStepClick:s}){const a=mn();return r.jsxs("div",{className:"wizard-progress",children:[r.jsx("ol",{className:"wizard-steps",children:l0.map((o,c)=>{const u=c+2,f=u<t,g=u===t,p=u-1<t,v=f&&!!s;return r.jsxs("li",{className:`wizard-step${p?" reached":""}`,"aria-current":g?"step":void 0,children:[r.jsx("button",{type:"button",className:`step-circle${f?" completed":""}${g?" current":""}`,onClick:v?()=>s(u):void 0,disabled:!v,"aria-label":`${o}${f?" (done)":g?" (current)":""}`,children:f?"✓":c+1}),r.jsx("span",{className:`step-label-text${g?" current":f?" completed":""}`,children:o})]},u)})}),r.jsx("button",{type:"button",className:"btn btn-ghost btn-sm wizard-cancel",onClick:()=>a("/mandates?new=1"),children:"Cancel"})]})}const Af=40,c0={delegation:"Delegation"};function ht(t,s){const a=t.lastIndexOf("/"),o=a>=0?t.slice(a+1):t,c=o.indexOf("@"),u=c>=0?o.slice(0,c):o,f=c0[u.toLowerCase()];return f||(s?s.slice(0,Af):(u.charAt(0).toUpperCase()+u.slice(1)).slice(0,Af))}function u0({profileId:t,bounds:s,groupName:a,domain:o,onSwitch:c}){return r.jsxs("div",{className:"context-strip",children:[a&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"context-strip-label",children:"Team:"}),r.jsxs("span",{children:[r.jsx("strong",{children:a}),o?` / ${o}`:""]})]}),t&&r.jsxs("span",{children:[r.jsx("strong",{children:"Profile:"})," ",ht(t)]}),s&&r.jsxs("span",{children:[r.jsx("strong",{children:"Bounds:"})," ",s]}),c&&r.jsx("button",{className:"btn btn-ghost btn-sm",style:{marginLeft:"auto",padding:"0.2rem 0.5rem",fontSize:"0.7rem"},onClick:c,children:"Switch"})]})}function d0({integrationId:t,field:s,value:a,onChange:o,disabled:c,onLabels:u}){const[f,g]=h.useState(null),[p,v]=h.useState(null),[y,w]=h.useState(!0);h.useEffect(()=>{let b=!1;return O.discoverScopeField(t,s).then(S=>{var k;b||(g(S.options),w(!1),(k=S.options)!=null&&k.length&&(u==null||u(Object.fromEntries(S.options.map(T=>[T.value,T.label])))))}).catch(S=>{b||(v(S instanceof Error?S.message:String(S)),w(!1))}),()=>{b=!0}},[t,s]);const j=new Set(a.split(",").map(b=>b.trim()).filter(Boolean)),N=b=>{const S=new Set(j);S.has(b)?S.delete(b):S.add(b),o(Array.from(S).join(","))};return y?r.jsxs("p",{className:"hint-text",style:{color:"var(--text-tertiary)"},children:["Loading options from ",t,"…"]}):p||!f?r.jsxs(r.Fragment,{children:[r.jsxs("div",{style:{fontSize:"0.8rem",color:"var(--warning)",marginBottom:"0.5rem"},children:["Couldn't fetch options (",p??"no response","). Enter values manually, separated by commas."]}),r.jsx("input",{className:"form-input",type:"text",value:a,onChange:b=>o(b.target.value),disabled:c})]}):f.length===0?r.jsxs("p",{className:"hint-text",style:{color:"var(--text-tertiary)"},children:["No options available from ",t," for this field."]}):r.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"0.25rem"},children:f.map(b=>{const S=b.extras??{},k=typeof S.access=="string"?S.access:void 0,T=k==="reader",R=S.primary===!0;return r.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem",fontSize:"0.875rem",color:T?"var(--text-tertiary)":"var(--text-primary)",cursor:c||T?"not-allowed":"pointer"},title:T?"Read-only — you can authorize list/read but not writes":void 0,children:[r.jsx("input",{type:"checkbox",checked:j.has(String(b.value)),onChange:()=>N(String(b.value)),disabled:c||T}),r.jsx("span",{children:b.label||b.value}),R&&r.jsx("span",{style:{fontSize:"0.7rem",color:"var(--accent)",textTransform:"uppercase",letterSpacing:"0.04em"},children:"primary"}),k&&r.jsxs("span",{style:{fontSize:"0.7rem",color:"var(--text-tertiary)"},children:["· ",k]})]},b.value)})})}function wc(t){if(t.type!=="number")return 0;const s=t.boundType,a=t.unit;return(s==null?void 0:s.kind)==="per_transaction"&&a==="count"?1:0}function If(t,s){if(s!==void 0)return String(s);const a=t.default;return typeof a=="string"||typeof a=="number"&&Number.isFinite(a)?String(a):wc(t)===1?"1":""}function Gl(t){const s=t.maximum;return typeof s=="number"&&Number.isFinite(s)?s:void 0}function Pf(t,s){const a=wc(t),o=Gl(t),c=s===""?a:Math.max(a,Number(s));return o!==void 0?Math.min(o,c):c}function Fi(t){return!t||t==="count"?"":t==="minutes"?"min":t==="hours"?"hr":t==="days"?"days":t==="percent"?"%":t.startsWith("currency:")?t.slice(9):t}function f0(t,s){var o;const a=(o=t.capKinds)==null?void 0:o[s];return a||(t.approvers.length>0?"approval":"hard")}function jc(t,s,a){var o;return t.approvers.length===0||(s==null?void 0:s.enforcedBy)==="gatekeeper"||((o=s==null?void 0:s.boundType)==null?void 0:o.kind)==="enum"?"hard":f0(t,a)}function Xh(t,s,a){const o=t.indexOf(s),c=t.indexOf(a);return o===-1||c===-1?!1:c<o}function bi(t,s){var a;return((a=t.caps)==null?void 0:a[s])!==void 0}function h0(t,s,a){const o=Object.entries(s.caps??{}).filter(([u])=>jc(s,a[u],u)==="approval");if(o.length===0)return null;const c=u=>{var f;return((f=a[u])==null?void 0:f.displayName)??u};for(const[u,f]of o){const g=a[u],p=g==null?void 0:g.boundType,v=(p==null?void 0:p.kind)==="per_transaction"||(p==null?void 0:p.kind)==="cumulative_sum"?p.of:void 0,y=v?t[v]:void 0;if(typeof f=="number"&&typeof y=="number"&&y>f)return{field:u,fieldLabel:c(u),cap:f,value:y}}if(o.length===1){const[u,f]=o[0];return{field:u,fieldLabel:c(u),cap:f}}return null}function m0(t){return t.replace(/@.*$/,"").split("/").pop()??t}function Sc(t,s){return s.displayName?s.displayName:t.replace(/_/g," ").replace(/\b\w/g,a=>a.toUpperCase())}function p0(t){return t.type==="string"&&(t.format==="email"||t.format==="domain")}function g0(t){var a;const s=t;return!!(s.enum&&((a=s.constraint)!=null&&a.enforceable.includes("subset")))}function _f(t,s){const a=t.trim();return a?s==="email"?a.includes("@")&&a.indexOf(".",a.indexOf("@"))>-1:s==="domain"?a.includes(".")&&!a.includes("@"):!0:!1}function y0(t){return t?t==="minutes"?15:t==="percent"?5:t.startsWith("currency:")?10:1:1}function v0(t){return t?t==="minutes"?[{value:15,label:"15m"},{value:30,label:"30m"},{value:60,label:"1h"},{value:120,label:"2h"},{value:240,label:"4h"}]:t==="hours"?[{value:1,label:"1h"},{value:4,label:"4h"},{value:8,label:"8h"},{value:24,label:"1d"}]:t==="days"?[{value:1,label:"1d"},{value:7,label:"1w"},{value:30,label:"1mo"},{value:90,label:"3mo"}]:t==="percent"?[{value:10,label:"10%"},{value:25,label:"25%"},{value:50,label:"50%"},{value:100,label:"100%"}]:t.startsWith("currency:")?[{value:10,label:"10"},{value:50,label:"50"},{value:100,label:"100"},{value:500,label:"500"},{value:1e3,label:"1k"}]:[]:[]}function x0(t,s){if(!t||!s)return"";const a=Number(t);if(!Number.isFinite(a)||a<=0)return"";if(s==="minutes"&&a>=60){const o=Math.floor(a/60),c=a%60;return c===0?`${o} hour${o!==1?"s":""}`:`${o}h ${c}m`}if(s==="hours"&&a>=24&&a%24===0){const o=a/24;return`${o} day${o!==1?"s":""}`}if(s==="days"){if(a>=30&&a%30===0)return`${a/30} month${a/30!==1?"s":""}`;if(a>=7&&a%7===0)return`${a/7} week${a/7!==1?"s":""}`}return""}function w0({id:t,value:s,onChange:a,disabled:o,placeholder:c,unit:u,min:f=0,max:g}){const p=y0(u),v=v0(u).filter(S=>g===void 0||S.value<=g),y=Fi(u),w=x0(s,u),j=s===""?null:Number(s),N=()=>{const S=s===""?0:Number(s),k=S%p,T=k===0?S+p:S+(p-k);a(String(g!==void 0?Math.min(g,T):T))},b=()=>{const S=s===""?0:Number(s);if(S<=f)return;const k=S%p,T=k===0?S-p:S-k;a(String(Math.max(f,T)))};return r.jsxs("div",{className:"bounded-input",children:[r.jsxs("div",{className:"bounded-input-field",children:[r.jsx("button",{type:"button",className:"stepper-btn stepper-decrement",onClick:b,disabled:o||s===""||Number(s)<=f,"aria-label":"Decrease",children:"−"}),r.jsx("input",{id:t,className:"stepper-input",type:"number",min:f,max:g,step:p,value:s,placeholder:c??String(f),onChange:S=>{const k=S.target.value;a(g!==void 0&&k!==""&&Number(k)>g?String(g):k)},onFocus:S=>S.target.select(),disabled:o}),r.jsx("button",{type:"button",className:"stepper-btn stepper-increment",onClick:N,disabled:o||g!==void 0&&s!==""&&Number(s)>=g,"aria-label":"Increase",children:"+"}),y&&r.jsx("span",{className:"bounded-input-unit","aria-hidden":"true",children:y})]}),v.length>0&&!o&&r.jsx("div",{className:"bounded-input-presets",role:"group","aria-label":"Quick presets",children:v.map(S=>r.jsx("button",{type:"button",className:`preset-chip${j===S.value?" preset-chip-selected":""}`,onClick:()=>a(String(S.value)),children:S.label},S.value))}),w&&r.jsxs("div",{className:"bounded-input-echo",children:["≈ ",w]})]})}function $f({htmlFor:t,label:s,description:a}){const[o,c]=h.useState(!1);return r.jsxs("div",{className:"field-label-with-tip",children:[r.jsx("label",{className:"form-label",htmlFor:t,children:s}),a&&r.jsxs(r.Fragment,{children:[r.jsx("button",{type:"button",className:"field-tip-trigger","aria-label":`What does "${s}" mean?`,"aria-expanded":o,onClick:()=>c(u=>!u),onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),onBlur:()=>c(!1),children:"i"}),o&&r.jsx("div",{className:"field-tip-bubble",role:"tooltip",children:a})]})]})}function j0({id:t,value:s,onChange:a,disabled:o,format:c,placeholder:u}){const[f,g]=h.useState(""),[p,v]=h.useState(!1),y=h.useRef(null),w=s?s.split(",").map(T=>T.trim()).filter(Boolean):[],j=T=>{const R=T.trim();if(!R)return;if(!_f(R,c)){v(!0);return}v(!1);const P=w.includes(R)?w:[...w,R];a(P.join(",")),g("")},N=T=>{const R=w.filter((P,A)=>A!==T);a(R.join(","))},b=T=>{T.key==="Enter"||T.key===","||T.key==="Tab"?f.trim()&&(T.preventDefault(),j(f)):T.key==="Backspace"&&!f&&w.length>0&&N(w.length-1)},S=T=>{const R=T.clipboardData.getData("text");if(R.includes(",")){T.preventDefault();const A=R.split(",").map(H=>H.trim()).filter(Boolean).filter(H=>_f(H,c)),B=[...new Set([...w,...A])];a(B.join(",")),g(""),v(!1)}},k=c==="email"?"Type email and press Enter...":"Type domain and press Enter...";return r.jsxs("div",{className:`tag-input${p?" tag-input-invalid":""}`,onClick:()=>{var T;return(T=y.current)==null?void 0:T.focus()},children:[w.map((T,R)=>r.jsxs("span",{className:"tag-pill",children:[T,!o&&r.jsx("button",{type:"button",className:"tag-remove",onClick:P=>{P.stopPropagation(),N(R)},"aria-label":`Remove ${T}`,children:"×"})]},T)),!o&&r.jsx("input",{ref:y,id:t,className:"tag-input-field",type:"text",value:f,onChange:T=>{g(T.target.value),v(!1)},onKeyDown:b,onPaste:S,onBlur:()=>{f.trim()&&j(f)},placeholder:w.length===0?u??k:""})]})}function S0({id:t,options:s,value:a,onChange:o,disabled:c}){const u=a?a.split(",").map(g=>g.trim()).filter(Boolean):[],f=g=>{const p=u.includes(g)?u.filter(v=>v!==g):[...u,g];o(p.join(","))};return r.jsx("div",{className:"checkbox-group",id:t,children:s.map(g=>r.jsxs("label",{className:`checkbox-pill${u.includes(g)?" checkbox-pill-selected":""}`,children:[r.jsx("input",{type:"checkbox",checked:u.includes(g),onChange:()=>f(g),disabled:c}),r.jsx("span",{children:g})]},g))})}function Lf({fieldKey:t,fieldDef:s,value:a,onChange:o,prefix:c,readOnly:u,twoColumn:f,discoveryIntegrationId:g,onLabels:p,capMax:v,enumAllowedFrom:y}){const w=Sc(t,s),j=`${c}-field-${t}`,N=r.jsx(r.Fragment,{children:g0(s)?r.jsx(S0,{id:j,options:s.enum,value:a,onChange:b=>o(t,b),disabled:u}):(()=>{const b=s.boundType;return(b==null?void 0:b.kind)==="enum"&&Array.isArray(b.values)})()?r.jsxs("select",{id:j,className:"form-select",value:a,onChange:b=>o(t,b.target.value),disabled:u||y!==void 0&&s.boundType.values.length-y<=1,children:[r.jsx("option",{value:"",children:"Select..."}),s.boundType.values.map((b,S)=>r.jsx("option",{value:b,disabled:y!==void 0&&S<y,children:b},b))]}):s.enum?r.jsxs("select",{id:j,className:"form-select",value:a,onChange:b=>o(t,b.target.value),disabled:u,children:[r.jsx("option",{value:"",children:"Select..."}),s.enum.map(b=>r.jsx("option",{value:b,children:b},b))]}):s.type==="number"?r.jsx(w0,{id:j,value:a,onChange:b=>o(t,b),disabled:u,unit:s.unit,min:wc(s),max:v!==void 0?Math.min(v,Gl(s)??v):Gl(s)}):p0(s)?r.jsx(j0,{id:j,value:a,onChange:b=>o(t,b),disabled:u,format:s.format}):g?r.jsx(d0,{integrationId:g,field:t,value:a,onChange:b=>o(t,b),disabled:u,onLabels:b=>p==null?void 0:p(t,b)}):r.jsx("input",{id:j,className:"form-input",type:"text",value:a,onChange:b=>o(t,b.target.value),disabled:u})});return f?r.jsxs("div",{className:"bounds-field-row",children:[r.jsx("div",{className:"bounds-field-label",children:r.jsx($f,{htmlFor:j,label:w,description:s.description})}),r.jsx("div",{className:"bounds-field-input",children:N})]},`${c}-${t}`):r.jsxs("div",{className:"form-group",children:[r.jsx($f,{htmlFor:j,label:w,description:s.description}),N]},`${c}-${t}`)}function b0(t,s,a,o){if(!o||!bi(o,t))return null;const c=o.caps[t],u=jc(o,s,t);let f=!1;if(typeof c=="number"){const g=a===""?NaN:Number(a);f=!Number.isNaN(g)&&g>c}else if(typeof c=="string"&&a!==""){const g=s.boundType;f=(g==null?void 0:g.kind)==="enum"?Xh(g.values??[],c,a):!1}return{kind:u,cap:c,violating:f}}function zf(t,s,a,o){if(!o||!bi(o,t))return a;const c=jc(o,s,t),u=o.caps[t];if(c!=="hard")return a;if(typeof u=="number"){const f=a===""?NaN:Number(a);return String(Number.isNaN(f)?u:Math.min(f,u))}if(typeof u=="string"){const f=s.boundType,g=(f==null?void 0:f.kind)==="enum"?f.values??[]:[];return a!==""&&Xh(g,u,a)?u:a}return a}function k0(t,s){if(typeof s!="string")return;const a=t.boundType;if((a==null?void 0:a.kind)!=="enum")return;const o=(a.values??[]).indexOf(s);return o===-1?void 0:o}function N0(t,s){return Fi(s.unit)||Sc(t,s).toLowerCase()}function Zh(t,s){if(s&&s.length>0)return s.join(" or ");const a=(t==null?void 0:t.approvers)??[];return a.length>0?a.join(" or "):"your team's approvers"}function C0(t,s,a,o,c){var v;const u=s.enforcedBy==="gatekeeper",f=((v=s.boundType)==null?void 0:v.kind)==="enum";if(a.kind==="hard")return f?r.jsxs("span",{className:"cap-note hard","data-testid":`cap-note-${t}`,children:["Disabled by your team's policy — ",Sc(t,s).toLowerCase()," is capped at"," ",String(a.cap)," for this profile."]}):r.jsxs("span",{className:"cap-note hard","data-testid":`cap-note-${t}`,children:["Team limit ",String(a.cap),u?" — read limits are always hard, no approval path exists for this cap.":""]});const g=N0(t,s),p=Zh(o,c);return r.jsxs("span",{className:"cap-note soft","data-testid":`cap-note-${t}`,children:["Every ",g," above ",String(a.cap)," goes to ",p," for approval."]})}function E0({profile:t,onConfirm:s,onCancel:a,readOnly:o,initialBounds:c,initialContext:u,initialFrame:f,profileConfig:g,approverNames:p,adminName:v}){var Q;const y=t.boundsSchema,w=t.scopeSchema,j=z=>!!g&&bi(g,z),N=y?Object.entries(y.fields).filter(([z,X])=>!(z==="profile"||z==="path"||X.enforced===!1||X.enforcedBy==="gatekeeper"&&!j(z))):[],b=y?Object.entries(y.fields).filter(([z,X])=>X.enforcedBy==="gatekeeper"&&!j(z)).filter(([,z])=>z.enforced!==!1).map(([z,X])=>X.displayName??z):[],S=w&&w.keyOrder.length>0?Object.entries(w.fields):[],k=c??f??{},T=u??{},R={};for(const[z,X]of N)R[z]=zf(z,X,If(X,k[z]),g);const P={};for(const[z]of S)P[z]=T[z]!==void 0?String(T[z]):"";const[A,B]=h.useState(R),[H,G]=h.useState(P),[me,q]=h.useState({}),ce=h.useRef(new Set);h.useEffect(()=>{B(z=>{let X=!1;const ne={...z};for(const[ie,K]of N){if(ce.current.has(ie))continue;const ke=z[ie]!==void 0?z[ie]:If(K,k[ie]),Ne=zf(ie,K,ke,g);ne[ie]!==Ne&&(ne[ie]=Ne,X=!0)}return X?ne:z})},[g]);const[ee,F]=h.useState(null);h.useEffect(()=>{const z=m0(t.id);O.getIntegrationManifests().then(({manifests:X})=>{const ne=X.find(ie=>ie.profile===z&&ie.contextDiscovery&&Object.keys(ie.contextDiscovery).length>0);F(ne??null)}).catch(()=>F(null))},[t.id]);const re={};for(const[z,X]of N)re[z]=b0(z,X,A[z]??"",g);const Y=Object.entries(re).filter(([,z])=>(z==null?void 0:z.kind)==="hard"&&z.violating).map(([z])=>z),se=!!g&&(((Q=g.approvers)==null?void 0:Q.length)??0)>0&&N.every(([z])=>!bi(g,z)),ye=(z,X)=>{ce.current.add(z),B(ne=>({...ne,[z]:X}))},we=(z,X)=>{G(ne=>({...ne,[z]:X}))},J=()=>{const z={profile:t.id};for(const[ne,ie]of N)ie.type==="number"?z[ne]=Pf(ie,A[ne]):z[ne]=A[ne];const X={};for(const[ne,ie]of S)ie.type==="number"?X[ne]=H[ne]===""?0:Number(H[ne]):X[ne]=H[ne];return[z,X]},V=()=>{const[z,X]=J();s(z,X,me)},W=()=>{var ie;const z={...A};for(const K of Y){const ke=(ie=re[K])==null?void 0:ie.cap;ke!==void 0&&(z[K]=String(ke))}B(z);const X={profile:t.id};for(const[K,ke]of N)ke.type==="number"?X[K]=Pf(ke,z[K]??""):X[K]=z[K]??"";const ne={};for(const[K,ke]of S)ke.type==="number"?ne[K]=H[K]===""?0:Number(H[K]):ne[K]=H[K];s(X,ne,me)},C=()=>{if(!se)return null;const z=Zh(g,p);return r.jsxs("div",{style:{marginTop:"0.75rem",padding:"0.75rem 1rem",border:"1px solid var(--accent)",borderRadius:"0.375rem",background:"var(--bg-elevated)",fontSize:"0.82rem"},children:[r.jsxs("div",{style:{fontWeight:600,color:"var(--accent)",marginBottom:"0.25rem"},children:["Profile approvers: ",z]}),r.jsxs("div",{children:["No caps are set on this profile, so ",z," won't gate any action under this mandate. Your intent will still be encrypted and shared with them as an accountability record — they can read what you authorised, even though they aren't reviewing individual actions."]})]})},L=()=>{if(Y.length===0)return null;const z=v??"the team admin";return r.jsxs("div",{style:{marginTop:"0.75rem",padding:"0.75rem 1rem",border:"1px solid var(--danger)",borderRadius:"0.375rem",background:"var(--bg-elevated)",fontSize:"0.82rem"},children:[r.jsx("div",{style:{fontWeight:600,color:"var(--danger)",marginBottom:"0.25rem"},children:"Hard team ceiling."}),r.jsxs("div",{style:{marginBottom:"0.75rem"},children:["Lower the bound(s) above, or ask ",z," to add an approver path above the cap."]}),r.jsxs("div",{style:{display:"flex",gap:"0.5rem"},children:[r.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:W,children:"Save below cap"}),a&&r.jsx("button",{type:"button",className:"btn btn-ghost btn-sm",onClick:a,children:"Cancel"})]})]})},fe=Y.length>0;return r.jsxs("div",{children:[S.length>0&&r.jsxs("div",{className:"context-section",children:[r.jsxs("div",{className:"bounds-section-header",children:[r.jsx("span",{className:"bounds-section-icon",children:"🛡"}),r.jsxs("div",{children:[r.jsx("div",{className:"bounds-section-title",children:"Allowed scope"}),r.jsx("div",{className:"bounds-section-subtitle",children:"Encrypted on your device, never sent to the Authority Server"})]})]}),S.map(([z,X])=>{var ie;const ne=!!((ie=ee==null?void 0:ee.contextDiscovery)!=null&&ie[z]);return r.jsx(Lf,{fieldKey:z,fieldDef:X,value:H[z],onChange:we,prefix:"context",readOnly:o,discoveryIntegrationId:ne?ee.id:void 0,onLabels:(K,ke)=>q(Ne=>({...Ne,[K]:ke}))},`context-${z}`)})]}),N.length>0&&r.jsxs("div",{className:"bounds-section",children:[r.jsxs("div",{className:"bounds-section-header",children:[r.jsx("span",{className:"bounds-section-icon",children:"🔒"}),r.jsxs("div",{children:[r.jsx("div",{className:"bounds-section-title",children:"Limits"}),r.jsx("div",{className:"bounds-section-subtitle",children:"Enforced by the Authority Server"})]})]}),r.jsx("div",{className:"bounds-fields-grid",children:N.map(([z,X])=>{const ne=re[z];return r.jsxs("div",{style:{display:"contents"},children:[r.jsx(Lf,{fieldKey:z,fieldDef:X,value:A[z],onChange:ye,prefix:"bounds",readOnly:o,twoColumn:!0,capMax:(ne==null?void 0:ne.kind)==="hard"&&typeof ne.cap=="number"?ne.cap:void 0,enumAllowedFrom:(ne==null?void 0:ne.kind)==="hard"?k0(X,ne.cap):void 0}),ne&&r.jsx("div",{style:{gridColumn:"2 / 3",display:"flex",alignItems:"center",paddingBottom:"0.5rem"},children:C0(z,X,ne,g,p)})]},`bounds-${z}`)})}),C(),L(),b.length>0&&r.jsxs("div",{className:"bounds-local-note",style:{marginTop:"0.75rem",fontSize:"0.78rem",color:"var(--text-muted)"},children:[b.join(", ")," ",b.length===1?"is":"are"," set on the integration, not here — reads are checked on this device, so the limit applies immediately and can be changed any time under"," ",r.jsx(xt,{to:"/integrations",children:"Integrations"}),"."]})]}),r.jsx("button",{className:"btn btn-primary",onClick:V,disabled:fe,style:{marginTop:"0.5rem"},children:o?"Next: Gates":"Next: Problem Statement"})]})}function T0(t){var a;const s=t.match(/```(?:markdown|md)?\s*\n([\s\S]*?)```/);return((a=s==null?void 0:s[1])==null?void 0:a.trim())??null}function R0(t){return t.replace(/```(?:markdown|md)?\s*\n[\s\S]*?```/,"").trim()}const A0="Tell me what your agent should do — I'll help shape it. Or ask me to draft a full intent and we'll iterate.";function ki({target:t,currentText:s,onApply:a,greeting:o,placeholder:c,title:u}){const[f,g]=h.useState([{role:"assistant",content:o??A0}]),[p,v]=h.useState(""),[y,w]=h.useState(!1),[j,N]=h.useState(null),b=h.useRef(null),S=h.useRef(null);h.useEffect(()=>{const R=b.current;if(!R)return;const P=f[f.length-1],A=S.current;!y&&(P==null?void 0:P.role)==="assistant"&&f.length>1&&A?R.scrollTop=A.offsetTop:R.scrollTop=R.scrollHeight},[f,y]);const k=async()=>{const R=p.trim();if(!R||y)return;const P=[...f,{role:"user",content:R}];g(P),v(""),N(null),w(!0);try{const A=await O.aiChat({target:t,currentText:s,messages:P.filter((B,H)=>!(H===0&&B.role==="assistant"))});A.success&&A.reply?g(B=>[...B,{role:"assistant",content:A.reply}]):N(A.error??"AI returned no reply")}catch(A){N(A instanceof Error?A.message:"Chat failed")}finally{w(!1)}},T=R=>{R.key==="Enter"&&!R.shiftKey&&!R.nativeEvent.isComposing&&(R.preventDefault(),k())};return r.jsxs("div",{className:"intent-chat",children:[r.jsx("h3",{className:"card-title",children:u??"AI Assistant"}),r.jsxs("div",{ref:b,className:"chat-messages",children:[f.map((R,P)=>{const A=R.role==="assistant"?T0(R.content):null,B=A?R0(R.content):R.content;return r.jsx("div",{className:`chat-msg ${R.role}`,ref:P===f.length-1?S:void 0,children:r.jsxs("div",{className:"chat-msg-body",children:[B&&r.jsx("div",{className:"chat-msg-prose",children:B}),A!==null&&r.jsxs(r.Fragment,{children:[r.jsx("pre",{className:"chat-fenced-block",children:A}),r.jsx("button",{type:"button",className:"btn btn-primary btn-sm chat-apply-btn",onClick:()=>a(A),children:"Apply this draft"})]})]})},P)}),y&&r.jsx("div",{className:"chat-msg assistant",children:r.jsx("div",{className:"chat-msg-body chat-msg-thinking",children:"Thinking…"})})]}),j&&r.jsx("div",{className:"error-message",children:j}),r.jsxs("div",{className:"chat-composer",children:[r.jsxs("div",{className:"chat-composer-pill",children:[r.jsx("textarea",{className:"chat-input",value:p,onChange:R=>v(R.target.value),onKeyDown:T,placeholder:c??"Ask for help articulating the intent…",rows:1,disabled:y}),r.jsx("button",{type:"button",className:"chat-send-btn",onClick:k,disabled:y||!p.trim(),"aria-label":"Send",children:"↑"})]}),r.jsx("div",{className:"chat-composer-hint",children:"Enter to send · Shift+Enter for newline"})]})]})}function em({open:t,onClose:s,children:a,ariaLabel:o}){const c=h.useRef(null),u=h.useRef(null);return h.useEffect(()=>{var g;if(!t)return;u.current=document.activeElement,document.body.style.overflow="hidden";const f=p=>{p.key==="Escape"&&s()};return document.addEventListener("keydown",f),(g=c.current)==null||g.focus(),()=>{document.removeEventListener("keydown",f),document.body.style.overflow="",u.current instanceof HTMLElement&&u.current.focus()}},[t,s]),bv.createPortal(r.jsxs(r.Fragment,{children:[r.jsx("div",{className:`bottom-sheet-backdrop${t?" is-open":""}`,onClick:s,"aria-hidden":"true"}),r.jsxs("aside",{ref:c,className:`bottom-sheet${t?" is-open":""}`,role:"dialog","aria-modal":"true","aria-label":o,tabIndex:-1,children:[r.jsx("div",{className:"bottom-sheet-handle","aria-hidden":"true"}),r.jsx("button",{type:"button",className:"bottom-sheet-close",onClick:s,"aria-label":"Close",children:"×"}),a]})]}),document.body)}function I0(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function P0(t,s,a){if(s.length===0)return[{text:t,label:t,matched:null}];const o=[],c=new Set;for(const p of s)if(!(!p.scope||p.scope==="all (unscoped)"))for(const v of[p.scope,...p.scope.split(",").map(y=>y.trim())]){const y=v.toLowerCase();v&&!c.has(y)&&(c.add(y),o.push(v))}o.sort((p,v)=>v.length-p.length);const u=p=>{const v=p.toLowerCase();return s.filter(y=>{var w,j;return((w=y.scope)==null?void 0:w.toLowerCase())===v||((j=y.scope)==null?void 0:j.split(",").map(N=>N.trim().toLowerCase()).includes(v))})},f=["\\[\\d+\\]",...o.map(I0)],g=new RegExp(`(${f.join("|")})`,"gi");return t.split(g).filter(p=>p!=="").map(p=>{const v=/^\[(\d+)\]$/.exec(p);if(v){const y=s[Number(v[1])-1];if(y){const w=y.scope&&y.scope!=="all (unscoped)"?y.scope:"all recipients",j=a?`${a}: ${w}`:w;return{text:p,label:j,matched:[y]}}}else if(o.some(y=>y.toLowerCase()===p.toLowerCase())){const y=u(p);if(y.length>0)return{text:p,label:p,matched:y}}return{text:p,label:p,matched:null}})}const Ff=`Why — What's the situation? Why does this need to happen?
66
+
67
+ Goal — What should the agent try to achieve?
68
+
69
+ Watch out — What should the agent avoid or be careful about?`;function _0(t,s,a,o){return P0(t,s,o).map((c,u)=>{if(!c.matched)return r.jsx("span",{children:c.text},u);const f=c.matched;return r.jsx("button",{type:"button",onClick:()=>a(f),style:{background:"none",border:"none",padding:0,cursor:"pointer",color:"var(--accent)",textDecoration:"underline",font:"inherit"},children:c.label},u)})}function $0(){var $e;const t=mn(),[s]=uc(),a=Number(s.get("step"))||2,[o,c]=h.useState(null),[u,f]=h.useState(null),[g,p]=h.useState(a),[v,y]=h.useState(null),[w,j]=h.useState(null),[N,b]=h.useState({}),[S,k]=h.useState(Ff),[T,R]=h.useState(!1),[P,A]=h.useState(null),[B,H]=h.useState(!0),[G,me]=h.useState(null),[q,ce]=h.useState([]),[ee,F]=h.useState(void 0),[re,Y]=h.useState(!1),[se,ye]=h.useState(null),[we,J]=h.useState(null),[V,W]=h.useState(null),[C,L]=h.useState([]),[fe,Q]=h.useState(null);h.useEffect(()=>{var He;const pe=sessionStorage.getItem("agentAuth");if(!pe){t("/mandates?new=1");return}const Le=JSON.parse(pe);c(Le),Le.intentHint&&k(Le.intentHint),O.getCredential("ai-config").then(Oe=>A(Oe.configured)).catch(()=>A(!1));const Ge=sessionStorage.getItem("agentGate");if(Ge){const Oe=JSON.parse(Ge);Oe.bounds&&y(Oe.bounds),Oe.context&&j(Oe.context),(He=Oe.gateContent)!=null&&He.intent&&k(Oe.gateContent.intent)}O.getProfile(Le.profileId).then(Oe=>f(Oe)).catch(()=>t("/mandates?new=1")).finally(()=>H(!1)),Le.groupId&&Promise.all([O.getTeamProfileConfig(Le.groupId,Le.profileId).catch(()=>null),O.getGroupById(Le.groupId).catch(()=>null),O.listUsers().catch(()=>[])]).then(([Oe,lt,he])=>{if(me(Oe),Oe){const Re=new Map;for(const ze of he){const _=ze.name&&ze.email?`${ze.name} (${ze.email})`:ze.name||ze.email||ze.id;Re.set(ze.id,_)}const Pe=(lt==null?void 0:lt.members)??[];for(const ze of Pe){const _=ze.userId??ze.id;_&&(ze.name&&ze.email?Re.set(_,`${ze.name} (${ze.email})`):ze.name&&Re.set(_,ze.name))}const ut=(Oe.approvers??[]).map(ze=>Re.get(ze)??ze);ce(ut);const Je=Pe.find(ze=>ze.role==="admin");if(Je){const ze=Je.userId??Je.id;ze&&F(Re.get(ze)??Je.name)}}})},[t]);const z=v?Object.entries(v).filter(([pe])=>pe!=="profile"&&pe!=="path").map(([pe,Le])=>`${pe} = ${Le}`).join(", "):"",X=(pe,Le,Ge)=>{y(pe),j(Le),Ge&&b(Ge),p(3)},ne=S.trim()!==Ff.trim()&&S.trim()!=="",ie=pe=>{ne&&!confirm("Replace your current intent with the AI draft?")||k(pe)},K=()=>{const pe=u==null?void 0:u.ttl,Le={intent:S},Ge=JSON.parse(sessionStorage.getItem("agentGate")??"{}");sessionStorage.setItem("agentGate",JSON.stringify({...Ge,bounds:v,context:w,contextLabels:N,gateContent:Le,ttlConfig:pe})),t("/mandates/new/sign")},ke=async()=>{if(o){Y(!0),ye(null),J(null),W(null),L([]),Q(null);try{const pe=await O.aiIntentReview({profileId:o.profileId,newIntent:S,context:w??void 0});L(pe.grants??[]),pe.success?pe.review?ye(pe.review):J(pe.note??"No other mandates on this profile to compare against."):W(pe.error??"Check failed.")}catch(pe){W(pe instanceof Error?pe.message:"Check failed.")}finally{Y(!1)}}},Ne=pe=>{k(pe),(se||we||V)&&(ye(null),J(null),W(null),L([]),Q(null))};return B||!o||!u?r.jsx("p",{style:{color:"var(--text-tertiary)"},children:"Loading..."}):r.jsxs(r.Fragment,{children:[r.jsx(Qh,{currentStep:g,onStepClick:pe=>{pe>=2&&p(pe)}}),r.jsx(u0,{profileId:o.profileId,bounds:z||void 0,groupName:o.groupName,domain:o.domain}),g===2&&r.jsx("div",{className:"card",children:r.jsx(E0,{profile:u,onConfirm:X,onCancel:()=>t("/mandates?new=1"),initialBounds:v||void 0,initialContext:w||void 0,profileConfig:G,approverNames:q,adminName:ee})}),g===3&&r.jsxs("div",{className:`intent-layout${P?"":" no-chat"}`,children:[P&&r.jsx("div",{className:"card intent-pane chat tool",children:r.jsx(ki,{target:{kind:"intent",profileId:o.profileId,bounds:z||void 0},currentText:S,onApply:ie})}),r.jsxs("div",{className:"card intent-pane document",children:[r.jsx("h3",{className:"card-title",children:"What should your agent know?"}),r.jsxs("div",{className:"field-editable",style:{marginBottom:0},children:[r.jsxs("div",{className:"field-label",children:[r.jsx("span",{className:"pen",children:"✎"})," Intent — your words, signed with the grant"]}),r.jsx("textarea",{className:"intent-textarea",value:S,onChange:pe=>Ne(pe.target.value)}),r.jsxs("div",{className:"char-counter",children:[S.length," / 2000"]})]}),P===!1&&r.jsxs("p",{className:"intent-ai-hint",children:[r.jsx(xt,{to:"/settings",children:"Set up an AI assistant in Settings"})," to get help writing this."]}),P&&r.jsxs("div",{style:{marginTop:"0.5rem"},children:[r.jsx("button",{type:"button",className:"btn btn-ghost",style:{fontSize:"0.8rem",padding:"0.4rem 0.75rem"},onClick:ke,disabled:re||!ne,children:re?"Checking…":"Check against my other grants"}),V&&r.jsxs("div",{className:"hint-box",role:"note",style:{marginTop:"0.5rem",borderLeftColor:"var(--danger)"},children:[r.jsx("span",{className:"hint-icon","aria-hidden":"true",children:"!"}),r.jsx("div",{className:"hint-body",children:V})]}),we&&r.jsxs("div",{className:"hint-box",role:"note",style:{marginTop:"0.5rem"},children:[r.jsx("span",{className:"hint-icon","aria-hidden":"true",children:"i"}),r.jsx("div",{className:"hint-body",children:we})]}),se&&r.jsxs("div",{className:"hint-box",role:"note",style:{marginTop:"0.5rem"},children:[r.jsx("span",{className:"hint-icon","aria-hidden":"true",children:"i"}),r.jsxs("div",{className:"hint-body",children:[r.jsx("div",{className:"hint-head",children:"Intent review (advisory)"}),r.jsx("div",{style:{whiteSpace:"pre-wrap"},children:_0(se,C,Q,ht(o.profileId))}),r.jsx("div",{style:{fontSize:"0.7rem",color:"var(--text-tertiary)",marginTop:"0.4rem"},children:"Checked with your configured assistant. AI surfaces reality — you decide."})]})]})]}),r.jsxs("div",{className:"intent-footer",children:[r.jsx("button",{className:"btn btn-ghost",onClick:()=>p(2),children:"Back"}),r.jsx("button",{className:"btn btn-primary intent-continue-btn",onClick:K,disabled:!ne,children:"Continue to Review"})]}),((($e=G==null?void 0:G.approvers)==null?void 0:$e.length)??0)>0&&r.jsxs("div",{className:"hint-box",role:"note",children:[r.jsx("span",{className:"hint-icon","aria-hidden":"true",children:"i"}),r.jsxs("div",{className:"hint-body",children:[r.jsxs("div",{className:"hint-head",children:["Visible to ",q.length>0?q.join(", "):"the configured approvers"]}),"Your intent will be encrypted and shared with"," ",q.length>0?q.join(", "):"this profile's required approvers",". Only they can decrypt it — your Authority Server cannot. Each approver stores a copy as their accountability record."]})]})]}),P&&r.jsxs(r.Fragment,{children:[r.jsx("button",{type:"button",className:"floating-help",onClick:()=>R(!0),"aria-label":"Open intent assistant",children:"Get help with intent"}),r.jsx(em,{open:T,onClose:()=>R(!1),ariaLabel:"Intent assistant",children:r.jsx(ki,{target:{kind:"intent",profileId:o.profileId,bounds:z||void 0},currentText:S,onApply:pe=>{ie(pe),R(!1)}})})]}),fe&&r.jsx("div",{className:"modal-backdrop",onClick:pe=>pe.target===pe.currentTarget&&Q(null),children:r.jsxs("div",{className:"modal",children:[r.jsxs("div",{className:"modal-header",children:[r.jsx("h3",{className:"modal-title",children:fe.length>1?`Existing mandates (${fe.length})`:"Existing mandate"}),r.jsx("button",{className:"modal-close",onClick:()=>Q(null),children:"×"})]}),r.jsx("div",{className:"modal-body",children:fe.map((pe,Le)=>{var Ge;return r.jsxs("div",{style:{marginBottom:Le<fe.length-1?"1rem":0,paddingBottom:Le<fe.length-1?"1rem":0,borderBottom:Le<fe.length-1?"1px solid var(--border)":"none"},children:[r.jsx("div",{style:{fontSize:"0.7rem",fontWeight:600,color:"var(--text-tertiary)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:"0.25rem"},children:"Scope"}),r.jsx("div",{style:{marginBottom:"0.75rem"},children:pe.scope}),r.jsx("div",{style:{fontSize:"0.7rem",fontWeight:600,color:"var(--text-tertiary)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:"0.25rem"},children:"Intent"}),r.jsx("div",{style:{whiteSpace:"pre-wrap",marginBottom:"0.75rem"},children:((Ge=pe.intent)==null?void 0:Ge.trim())||"(no intent recorded)"}),Object.entries(pe.bounds).filter(([He])=>He!=="profile"&&He!=="path").length>0&&r.jsxs(r.Fragment,{children:[r.jsx("div",{style:{fontSize:"0.7rem",fontWeight:600,color:"var(--text-tertiary)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:"0.25rem"},children:"Limits"}),r.jsx("div",{style:{fontSize:"0.85rem",color:"var(--text-secondary)"},children:Object.entries(pe.bounds).filter(([He])=>He!=="profile"&&He!=="path").map(([He,Oe])=>`${He}: ${Oe}`).join(" · ")})]})]},Le)})})]})})]})]})}function L0(t){return t.normalize("NFC").replace(/\r\n?/g,`
70
+ `).split(`
71
+ `).map(c=>c.replace(/[ \t]+$/,"")).join(`
72
+ `).replace(/\n+$/,"")}async function bc(t){const a=new TextEncoder().encode(t),o=await crypto.subtle.digest("SHA-256",a);return Array.from(new Uint8Array(o)).map(u=>u.toString(16).padStart(2,"0")).join("")}class z0 extends Error{constructor(a,o,c){super(c);Bs(this,"code");Bs(this,"field");this.name="CanonicalValueError",this.code=a,this.field=o}}function F0(t){const s=new TextEncoder().encode(t);let a="";for(const o of s)o===61||o===37||o<32||o>126?a+="%"+o.toString(16).toUpperCase().padStart(2,"0"):a+=String.fromCharCode(o);return a}function tm(t,s,a){const o=[];for(const c of s){const u=t[c];if(u==null)continue;const f=String(u);if(f.includes(`
73
+ `)||f.includes("\r"))throw new z0(a,c,`Value for "${c}" contains a raw newline or carriage return. Refusing: a hash over stripped or normalized input would not represent what was authorized.`);o.push(`${c}=${F0(f)}`)}return o.join(`
74
+ `)}async function xi(t,s){const a=s.boundsSchema;if(!a)throw new Error("Profile has no boundsSchema");const o=tm(t,a.keyOrder,"BOUNDS_INVALID_VALUE");return`sha256:${await bc(o)}`}async function nm(t,s){const a=s.scopeSchema?tm(t,s.scopeSchema.keyOrder,"SCOPE_INVALID_VALUE"):"";return`sha256:${await bc(a)}`}function Kl(t){if(t===void 0)throw new Error("canonicalize: undefined is not serializable");if(typeof t=="number"&&!Number.isFinite(t))throw new Error(`canonicalize: ${t} is not a valid JSON number`);if(t===null||typeof t!="object")return JSON.stringify(t);if(Array.isArray(t))return"["+t.map(c=>c===void 0?"null":Kl(c)).join(",")+"]";const s=t,a=[];for(const o of Object.keys(s).sort()){const c=s[o];c!==void 0&&a.push(JSON.stringify(o)+":"+Kl(c))}return"{"+a.join(",")+"}"}async function rm(t){return`sha256:${await bc(Kl(t))}`}async function Ni(t){const s=new TextEncoder().encode(L0(t)),a=await crypto.subtle.digest("SHA-256",s);return`sha256:${Array.from(new Uint8Array(a)).map(u=>u.toString(16).padStart(2,"0")).join("")}`}function sm(t,s){if(!t.authorization_id)throw new Error("Signing result lacks authorization_id — the Authority Server predates per-ceremony identity. Update the Authority Server (lockstep deploy).");return{authorizationId:t.authorization_id,boundsHash:t.bounds_hash??s.boundsHash,contextHash:s.contextHash,context:s.context,...s.contextLabels&&Object.keys(s.contextLabels).length>0?{contextLabels:s.contextLabels}:{},gateContent:s.gateContent,...s.path?{path:s.path}:{}}}function O0(t){const s=t.commitment_modes;return s===void 0?["review","automatic"]:Array.isArray(s)?["review","automatic"].filter(a=>s.includes(a)):[]}function M0(t){return t==="per-action"?"review":"automatic"}function Of(t){return t?O0(t).map(s=>s==="review"?"per-action":"immediate"):["per-action","immediate"]}function B0(t,s){return s.includes(t)?t:s[0]??null}function Mf(t){return t==null?new Set:new Set(String(t).split(",").map(s=>s.trim().toLowerCase()).filter(Boolean))}function D0(t,s){for(const a of t)if(s.has(a))return!0;return!1}function U0(t,s,a){for(const o of t){const c=Mf(s[o]),u=Mf(a[o]);if(!(c.size===0||u.size===0)&&!D0(c,u))return!1}return!0}function W0(t){return t.length>24?`${t.slice(0,10)}…`:t}function am(t,s,a){const o=a==null?void 0:a[t];return String(s).split(",").map(u=>u.trim()).filter(Boolean).map(u=>{const f=o==null?void 0:o[u];return f?`${f} (${W0(u)})`:u}).join(", ")}function im(t){var c;if(t.isPersonal)return{can:!0};if(!t.configLoaded)return{can:!0};const s=t.teamName?`"${t.teamName}"`:"this team";return t.grantors!=="all"&&(((c=t.grantors)==null?void 0:c.length)??0)===0?{can:!1,code:"PROFILE_NOT_ENABLED_FOR_GROUP",reason:`Not enabled in ${s}.`,fix:`Ask an admin of ${s} to enable ${t.profileName} and name who may give its mandates.`}:t.grantors==="all"||!!t.userId&&t.grantors.includes(t.userId)?{can:!0}:{can:!1,code:"OWNER_NOT_APPROVER",reason:`Only ${t.profileName}'s grantors in ${s} can give this — you are not one of them.`,fix:"Ask one of them, or a team admin to add you."}}const Ci=500,H0=["Lower the discount","Other recipient","Shorter","Different wording"];function kc(t){const s=t.trim();return s.length===0?{valid:!1,error:"Describe what should change."}:s.length>Ci?{valid:!1,error:`At most ${Ci} characters (currently ${s.length}).`}:{valid:!0,trimmed:s}}function V0(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function om(t,s){return t.toLowerCase().includes(s.toLowerCase())}function G0(t,s){const a=t.trim();if(a.length===0)return s;if(!om(a,s))return`${a}. ${s}`;const o=new RegExp(`\\.?\\s*${V0(s)}\\.?`,"i");return a.replace(o,"").replace(/\s{2,}/g," ").replace(/^\.\s*/,"").trim()}function lm(){return{outcome:"rejected"}}function K0(t){const s=kc(t);if(!s.valid)throw new Error(s.error);return{outcome:"change_needed",note:s.trimmed}}function Bf(){return{outcome:"replaced"}}function q0(t,s){if((t.pendingApprovers??[]).includes(s))return{route:"approver"};const a=t.pendingDomains??[];return a.includes(s)?{route:"resolve",domain:s}:a.includes("owner")?{route:"resolve",domain:"owner"}:null}const Y0={rejected:"REJECTED",change_needed:"CHANGE NEEDED",replaced:"REPLACED"};function J0(t,s){const a=t.rejectedBy??t.approverRejectedBy;if(!a)return null;const o=a.outcome??"rejected",c=a.note??("reason"in a?a.reason:void 0);return{kind:Y0[o],who:a.userId===s?"You":a.userId,at:a.at,note:c}}function Q0(t){return t.refusal?{kind:"REFUSED",at:t.refusal.at,message:t.refusal.message}:null}function X0(){var ge,Te;const t=mn(),{user:s,mode:a,domain:o}=mt(),[c,u]=h.useState(null),[f,g]=h.useState(null),[p,v]=h.useState(null),[y,w]=h.useState("per-action"),[j,N]=h.useState(1800),[b,S]=h.useState(86400),[k,T]=h.useState(""),[R,P]=h.useState("hours"),[A,B]=h.useState(""),[H,G]=h.useState(!0),[me,q]=h.useState(!1);h.useEffect(()=>{O.getIdentityDisclosure().then(de=>q(de.always)).catch(()=>{})},[]);const[ce,ee]=h.useState(!1),[F,re]=h.useState(""),[Y,se]=h.useState(null),[ye,we]=h.useState([]),[J,V]=h.useState(!1),[W,C]=h.useState([]),[L,fe]=h.useState(0);h.useEffect(()=>{var jn;const de=sessionStorage.getItem("agentAuth"),Me=sessionStorage.getItem("agentGate");if(!de||!Me){t("/mandates?new=1");return}const Ye=JSON.parse(de),Qe=JSON.parse(Me),pt={bounds:Qe.bounds??{},context:Qe.context??{},contextLabels:Qe.contextLabels??void 0,gateContent:Qe.gateContent};u(Ye),g(pt),Qe.ttlConfig&&(N(Qe.ttlConfig.default??1800),S(Qe.ttlConfig.max??86400)),Qe.templateMode==="automatic"?w("immediate"):Qe.templateMode==="review"&&w("per-action");const pn=((jn=Qe.ttlConfig)==null?void 0:jn.max)??86400;if(typeof Qe.templateTtl=="number"&&Qe.templateTtl>0){const rt=Math.min(Qe.templateTtl,pn);N(rt),[3600,86400,604800,2592e3,31536e3].includes(rt)||(rt%86400===0?(T(String(rt/86400)),P("days")):(T(String(Math.max(1,Math.round(rt/3600)))),P("hours")))}O.getProfile(Ye.profileId).then(rt=>{var kt;if(v(rt),!A){const Et=rt.name??((kt=Ye.profileId.split("/").pop())==null?void 0:kt.replace(/@.*$/,""))??"",wt=[];if(pt.context&&rt.scopeSchema)for(const Se of rt.scopeSchema.keyOrder){const ve=pt.context[Se];if(ve!==void 0&&ve!==""){const Be=String(ve).split(",").map(Fe=>Fe.trim()).filter(Boolean);wt.push(Be.join(", "))}}const le=wt.length>0?`${Et}: ${wt.join(" · ")}`:Et;B(le)}}).catch(()=>{}),Ye.isPersonal?V(!0):Promise.all([O.getTeamProfileConfig(Ye.groupId,Ye.profileId).catch(()=>null),O.getGroupById(Ye.groupId).catch(()=>null),O.listUsers().catch(()=>[])]).then(([rt,kt,Et])=>{if(se(rt),rt){const wt=new Map;for(const ve of Et){const Be=ve.name&&ve.email?`${ve.name} (${ve.email})`:ve.name||ve.email||ve.id;wt.set(ve.id,Be)}const le=(kt==null?void 0:kt.members)??[];for(const ve of le){const Be=ve.userId??ve.id;Be&&(ve.name&&ve.email?wt.set(Be,`${ve.name} (${ve.email})`):ve.name&&wt.set(Be,ve.name))}const Se=(rt.approvers??[]).map(ve=>wt.get(ve)??ve);we(Se)}}).finally(()=>{V(!0)})},[t]),h.useEffect(()=>{if(!(c!=null&&c.profileId))return;const de=c.profileId,Me=sessionStorage.getItem("agentEditReplaces");O.getEnrichedAuthorizations().then(Ye=>{const Qe=Ye.filter(pt=>pt.profileId===de&&pt.authorizationId!==Me).map(pt=>({authorizationId:pt.authorizationId,bounds:pt.bounds,context:pt.context??{},intent:pt.intent}));C(Qe)}).catch(()=>C([]))},[c==null?void 0:c.profileId]),h.useEffect(()=>{if(!p)return;const de=B0(y,Of(p));de&&de!==y&&w(de)},[p,y]),h.useEffect(()=>{if(!f||!p||W.length===0){fe(0);return}let de=!1;return(async()=>{const Me=await xi(f.bounds,p),Ye=await Promise.all(W.map(Qe=>xi(Qe.bounds,p).catch(()=>null)));de||fe(Ye.filter(Qe=>Qe===Me).length)})().catch(()=>{de||fe(0)}),()=>{de=!0}},[f,p,W]);const Q=async()=>{if(!(!c||!f||!p||!s)){if(!c.groupId){re("No active group; cannot create mandate.");return}ee(!0),re("");try{const de=o||c.domain||"owner",Me=await xi(f.bounds,p),Ye=await nm(f.context,p),[Qe,pt]=await Promise.all([Ni(f.gateContent.intent),Ni(JSON.stringify({profile:c.profileId,domain:de,group:c.groupId}))]);let pn,jn,rt,kt;if(c.isTeam){const Fe=await O.getApproversPubkeys(c.groupId,c.profileId);if(Fe.length>0){const Xe=await O.encryptIntent(f.gateContent.intent,Fe);pn=Xe.intentCiphertext,jn=Xe.encryptedKeys,rt=Xe.approversFrozen,kt=Xe.intentDisclosureHash}}const Et=`authz_${crypto.randomUUID()}`,wt=sessionStorage.getItem("agentEditReplaces")||void 0,le=sessionStorage.getItem("agentReplacesProposal")||void 0,Se=await rm(p),ve=await O.attest({authorization_id:Et,replaces:wt,profile_id:c.profileId,profile_hash:Se,supported_versions:["0.7"],bounds:f.bounds,bounds_hash:Me,scope_hash:Ye,domain:de,did:s.did,mandate_owners:[{did:s.did}],gate_content_hashes:{intent:Qe},execution_context_hash:pt,group_id:c.groupId,ttl:j,commitment_mode:M0(y),title:A.trim(),intent_ciphertext:pn,encrypted_keys:jn,approvers_frozen:rt,intent_disclosure_hash:kt,disclose_identity:H});try{await O.pushGateContent(sm(ve,{boundsHash:Me,contextHash:Ye,context:f.context,contextLabels:f.contextLabels,gateContent:f.gateContent}))}catch(Fe){try{await O.revokeAttestation(Et,"Auto-revoked: gate content push failed")}catch{}throw new Error(`Mandate signed but gate content delivery failed. The mandate was revoked. Please try again. (${Fe instanceof Error?Fe.message:"Unknown error"})`)}if(wt)try{await O.revokeAttestation(wt,`Replaced by ${Et} (edit)`),O.resyncGates().catch(()=>{})}catch{}let Be="";if(le)try{const Fe=await O.getProposal(le);if(Fe.status==="pending"){const Xe=q0(Fe,(s==null?void 0:s.id)??"");Xe?Xe.route==="approver"?await O.rejectProposal(le,Bf()):await O.resolveProposal(le,"reject",Xe.domain,Bf()):Be="you are not one of the people who may decide it"}}catch(Fe){Be=Fe instanceof Error?Fe.message:"unknown error"}if(sessionStorage.removeItem("agentAuth"),sessionStorage.removeItem("agentGate"),sessionStorage.removeItem("agentEditReplaces"),sessionStorage.removeItem("agentReplacesProposal"),Be){re(`Your mandate is signed and active. The AI's proposal could not be withdrawn (${Be}) — reject it under Approvals.`);return}t(`/mandates?highlight=${encodeURIComponent(Et)}`)}catch(de){re(de instanceof Error?de.message:"Signing the mandate failed")}finally{ee(!1)}}};if(!c||!f)return r.jsx("p",{style:{color:"var(--text-tertiary)"},children:"Loading..."});const z=Object.entries(f.bounds).filter(([de])=>de!=="profile"&&de!=="path"),X=Object.entries(f.context),ie=((Y==null?void 0:Y.caps)!=null?Object.keys(Y.caps):[]).length!==0,K=ye.length>0?ye.join(", "):((Y==null?void 0:Y.approvers)??[]).join(", "),ke=ie?`Within-cap actions run per the mode you choose above. Over-cap actions will require approval from you and ${K}, regardless of your mode.`:"No caps set — they won't gate any action, but your intent is encrypted and shared with them as an accountability record.",Ne=ie?`Over-cap actions will be reviewed by you and ${K}. Within-cap actions run per the mode you chose above.`:`Approvers ${K} can read your intent but won't gate any action — no caps configured on this profile.`,$e=!!((ge=Y==null?void 0:Y.approvers)!=null&&ge.length),pe=im({isPersonal:c.isPersonal,configLoaded:J,grantors:Y?Ph(Y):void 0,userId:s==null?void 0:s.id,profileName:ht(c.profileId),teamName:c.groupName}),Le=!pe.can,Ge=Of(p),He=Ge.length===0,Oe=j>b,lt={flex:1,padding:"0.75rem",border:y==="immediate"?"2px solid var(--accent)":"1px solid var(--border)",borderRadius:"var(--radius)",background:y==="immediate"?"var(--accent-subtle)":"var(--bg-elevated)",cursor:"pointer",textAlign:"left",fontFamily:"inherit"},he={flex:1,padding:"0.75rem",border:y==="per-action"?"2px solid var(--accent)":"1px solid var(--border)",borderRadius:"var(--radius)",background:y==="per-action"?"var(--accent-subtle)":"var(--bg-elevated)",cursor:"pointer",textAlign:"left",fontFamily:"inherit"},Re=((Te=p==null?void 0:p.scopeSchema)==null?void 0:Te.keyOrder)??[],Pe=W.filter(de=>U0(Re,f.context,de.context)),ut=Pe.length>0,Je=ht(c.profileId),ze=de=>{const Me=Object.values(de).map(Ye=>String(Ye).trim()).filter(Boolean);return Me.length>0?Me.join(", "):"all (unscoped)"},_=Pe.map(de=>ze(de.context)).join("; "),oe=`This grant's scope overlaps an existing grant on ${Je} (scoped to: ${_}). The agent may act under either. Per-action limits take the more permissive value, and daily limits add together — two grants of 10/day allow 20/day. Approval is not weakened: if either grant requires review, review still applies. Confirm this is intended before authorizing.`;return r.jsxs(r.Fragment,{children:[r.jsx(Qh,{currentStep:4,onStepClick:de=>{de<=3&&t(`/mandates/new/intent?step=${de}`)}}),r.jsxs("div",{className:"card",children:[r.jsx("h3",{className:"card-title",style:{marginBottom:"0.25rem"},children:"Review & Commit"}),r.jsx("p",{style:{fontSize:"0.85rem",color:"var(--text-secondary)",marginBottom:"1.5rem"},children:"Review your mandate details before signing."}),c.upgradedFromProfileId&&p&&r.jsxs("div",{className:"hint-box",role:"note",style:{marginBottom:"1rem"},children:[r.jsx("span",{className:"hint-icon","aria-hidden":"true",children:"i"}),r.jsxs("div",{className:"hint-body",children:["Updated to ",ht(c.profileId)," ",p.version," — the current version of this profile."]})]}),F&&r.jsx("div",{className:"error-message",children:F}),r.jsxs("div",{className:"field-editable",children:[r.jsxs("div",{className:"field-label",children:[r.jsx("span",{className:"pen",children:"✎"})," Title"]}),r.jsx("input",{type:"text",className:"form-input",placeholder:`e.g. ${ht(c.profileId)}: daily operations`,value:A,onChange:de=>B(de.target.value),maxLength:80,style:{fontSize:"0.9rem"}}),r.jsx("div",{style:{fontSize:"0.7rem",color:"var(--text-tertiary)",marginTop:"0.25rem"},children:"A short name to identify this mandate on your dashboard."})]}),r.jsxs("div",{className:"field-editable",children:[r.jsxs("div",{className:"field-label",children:[r.jsx("span",{className:"pen",children:"✎"})," Commitment"]}),r.jsxs("div",{style:{display:"flex",gap:"0.75rem"},children:[Ge.includes("per-action")&&r.jsxs("button",{onClick:()=>w("per-action"),style:he,children:[r.jsx("div",{style:{fontWeight:600,fontSize:"0.85rem",marginBottom:"0.25rem",color:"var(--text-primary)"},children:"Review Each Action"}),r.jsx("div",{style:{fontSize:"0.75rem",color:"var(--text-secondary)"},children:"You review and approve each action before it executes."})]}),Ge.includes("immediate")&&r.jsxs("button",{onClick:()=>w("immediate"),style:lt,children:[r.jsx("div",{style:{fontWeight:600,fontSize:"0.85rem",marginBottom:"0.25rem",color:"var(--text-primary)"},children:"Automatic"}),r.jsx("div",{style:{fontSize:"0.75rem",color:"var(--text-secondary)"},children:"Agent acts freely within your limits."})]})]}),Ge.length===1&&r.jsx("div",{style:{fontSize:"0.75rem",color:"var(--text-tertiary)",marginTop:"0.25rem"},children:Ge[0]==="per-action"?"This profile only allows review: you approve each action before it runs.":"This profile only allows automatic mode."}),He&&r.jsx("div",{style:{fontSize:"0.75rem",color:"var(--danger)",marginTop:"0.25rem"},children:"This profile allows no commitment mode, so no mandate can be signed under it. Its publisher must fix the profile."})]}),r.jsxs("div",{className:"field-editable",children:[r.jsxs("div",{className:"field-label",children:[r.jsx("span",{className:"pen",children:"✎"})," Duration"]}),r.jsxs("div",{style:{display:"flex",gap:"0.5rem",flexWrap:"wrap",alignItems:"center"},children:[[{label:"1 hour",seconds:3600},{label:"24 hours",seconds:86400},{label:"7 days",seconds:604800},{label:"30 days",seconds:2592e3},{label:"1 year",seconds:31536e3}].filter(de=>de.seconds<=b).map(de=>r.jsx("button",{onClick:()=>{N(de.seconds),T("")},style:{padding:"0.5rem 0.85rem",border:j===de.seconds?"2px solid var(--accent)":"1px solid var(--border)",borderRadius:"0.375rem",background:j===de.seconds?"var(--accent-subtle)":"var(--bg-elevated)",cursor:"pointer",fontSize:"0.85rem",fontFamily:"inherit",color:"var(--text-primary)"},children:de.label},de.seconds)),r.jsxs("div",{style:{display:"flex",gap:"0.375rem",alignItems:"center"},children:[r.jsx("input",{type:"number",className:"form-input",style:{width:"5rem",padding:"0.45rem 0.6rem",fontSize:"0.85rem"},placeholder:"Custom",value:k,onChange:de=>{T(de.target.value);const Me=parseInt(de.target.value,10);if(Me>0){const Ye=R==="days"?Me*86400:Me*3600;N(Math.min(Ye,b))}}}),r.jsxs("select",{className:"form-input",style:{padding:"0.45rem 0.5rem",fontSize:"0.85rem"},value:R,onChange:de=>{P(de.target.value);const Me=parseInt(k,10);if(Me>0){const Ye=de.target.value==="days"?Me*86400:Me*3600;N(Math.min(Ye,b))}},children:[r.jsx("option",{value:"hours",children:"hours"}),r.jsx("option",{value:"days",children:"days"})]})]}),Oe&&r.jsxs("span",{style:{fontSize:"0.75rem",color:"var(--danger)"},children:["Maximum: ",b>=86400?`${Math.floor(b/86400)} days`:`${Math.floor(b/3600)} hours`]})]})]}),r.jsx("div",{className:"field-editable",children:r.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:"0.5rem",cursor:"pointer"},children:[r.jsx("input",{type:"checkbox",checked:me||H,disabled:me,onChange:de=>G(de.target.checked),style:{marginTop:"0.15rem"}}),r.jsxs("span",{style:{fontSize:"0.8rem"},children:["Show my verified name on actions under this mandate",r.jsxs("div",{style:{fontSize:"0.7rem",color:"var(--text-tertiary)",marginTop:"0.15rem"},children:['Adds "verified by Suveren" with your name to outgoing content. Takes effect only if your identity is verified; otherwise actions stay pseudonymous.',me&&" Always on — you chose this in Settings."]})]})]})}),r.jsx("div",{className:"info-section-label",children:"What you are signing — set in previous steps"}),r.jsxs("div",{className:"info-block",children:[r.jsxs("div",{className:"info-head",children:[r.jsx("span",{className:"info-title",children:"Intent"}),r.jsx("button",{className:"info-edit",onClick:()=>t("/mandates/new/intent?step=3"),children:"edit in step 3"})]}),r.jsx("div",{style:{whiteSpace:"pre-wrap"},children:f.gateContent.intent})]}),(!!z.length||!!X.length)&&r.jsxs("div",{className:"info-block",children:[r.jsxs("div",{className:"info-head",children:[r.jsx("span",{className:"info-title",children:"Scope & Limits"}),r.jsx("button",{className:"info-edit",onClick:()=>t("/mandates/new/intent?step=2"),children:"edit in step 2"})]}),r.jsxs("dl",{className:"info-kv",children:[X.map(([de,Me])=>r.jsxs("span",{style:{display:"contents"},children:[r.jsx("dt",{children:de}),r.jsx("dd",{children:am(de,Me,f.contextLabels)})]},de)),z.map(([de,Me])=>r.jsxs("span",{style:{display:"contents"},children:[r.jsx("dt",{children:de}),r.jsx("dd",{children:String(Me)})]},de))]})]}),r.jsxs("div",{className:"info-block",children:[r.jsx("div",{className:"info-head",children:r.jsx("span",{className:"info-title",children:"Authority"})}),r.jsxs("dl",{className:"info-kv",children:[r.jsx("dt",{children:"Profile"}),r.jsxs("dd",{children:[ht(c.profileId),r.jsx("div",{style:{fontSize:"0.75rem",color:"var(--text-tertiary)",marginTop:"0.125rem"},children:c.profileId})]}),!c.isPersonal&&c.groupName&&r.jsxs(r.Fragment,{children:[r.jsx("dt",{children:"Team"}),r.jsx("dd",{children:c.groupName})]}),!c.isPersonal&&r.jsxs(r.Fragment,{children:[r.jsx("dt",{children:"Approvers"}),r.jsx("dd",{children:J?pe.can?r.jsxs(r.Fragment,{children:[K,r.jsx("div",{style:{fontSize:"0.75rem",color:"var(--text-tertiary)",marginTop:"0.125rem"},children:ke})]}):r.jsxs(r.Fragment,{children:[r.jsx("span",{style:{color:"var(--danger)",fontWeight:600},children:pe.code==="PROFILE_NOT_ENABLED_FOR_GROUP"?`Not enabled for ${c.groupName??"this team"}`:"You cannot give this mandate"}),pe.code==="OWNER_NOT_APPROVER"&&r.jsx("div",{children:K}),r.jsxs("div",{style:{fontSize:"0.75rem",color:"var(--text-tertiary)",marginTop:"0.125rem"},children:[pe.reason," ",pe.fix]})]}):r.jsx("span",{style:{color:"var(--text-tertiary)"},children:"Loading…"})})]})]})]}),L>0?r.jsxs("div",{style:{display:"flex",gap:"0.625rem",padding:"0.75rem 0.875rem",marginBottom:"1.25rem",border:"1px solid var(--warning)",borderLeft:"3px solid var(--warning)",borderRadius:"0.5rem",background:"var(--bg-elevated)",fontSize:"0.82rem",color:"var(--text-primary)"},children:[r.jsx("span",{"aria-hidden":"true",style:{color:"var(--warning)",fontWeight:700},children:"⚠"}),r.jsxs("div",{children:[r.jsx("div",{style:{fontWeight:600,color:"var(--warning)",marginBottom:"0.2rem"},children:"Identical limits to an existing grant"}),r.jsxs("div",{children:[L===1?`An active grant on ${Je} already has exactly these limits.`:`${L} active grants on ${Je} already have exactly these limits.`," ","If you meant to give the existing grant more time, use ",r.jsx("strong",{children:"Extend"})," on the Mandates page instead — authorizing here creates a separate, independent grant with its own intent and usage counters."]})]})]}):null,ut?r.jsxs("div",{style:{display:"flex",gap:"0.625rem",padding:"0.75rem 0.875rem",marginBottom:"1.25rem",border:"1px solid var(--warning)",borderLeft:"3px solid var(--warning)",borderRadius:"0.5rem",background:"var(--bg-elevated)",fontSize:"0.82rem",color:"var(--text-primary)"},children:[r.jsx("span",{"aria-hidden":"true",style:{color:"var(--warning)",fontWeight:700},children:"⚠"}),r.jsxs("div",{children:[r.jsx("div",{style:{fontWeight:600,color:"var(--warning)",marginBottom:"0.2rem"},children:"Overlapping scope"}),r.jsx("div",{children:oe})]})]}):null,r.jsxs("div",{style:{display:"flex",gap:"0.5rem"},children:[r.jsx("button",{className:"btn btn-ghost",onClick:()=>t("/mandates/new/intent"),children:"Back"}),r.jsx("button",{className:"btn btn-primary btn-lg",style:{flex:1},onClick:Q,disabled:ce||!A.trim()||Le||He,children:ce?"Signing...":y==="immediate"?"Sign mandate":"Sign mandate (asks first)"})]}),r.jsx("div",{style:{marginTop:"1rem",fontSize:"0.75rem",color:"var(--text-tertiary)",textAlign:"center",display:$e?"block":"none"},children:Ne})]})]})}const Z0={card:"💳",mail:"✉️"};function cm(t){return Z0[t]??"🔧"}function ew(t){const s=t==null?void 0:t.overrides;return!s||typeof s!="object"?!1:Object.values(s).some(a=>{var o;return typeof((o=a==null?void 0:a.read)==null?void 0:o.ageField)=="string"})}const tw=[0,7,30,90,365,3650];function hi(t){return t===null?"From your mandate":t===0?"Read nothing":t===1?"1 day back":t===365?"1 year back":t%365===0?`${t/365} years back`:`${t} days back`}function nw(t){return(t==null?void 0:t.paused)==="simulation"?{chip:{c:"int-chip-paused",t:"Paused"},showStart:!1}:t&&!t.running&&t.error?{chip:{c:"int-chip-bad",t:"Crashed"},showStart:!0}:{chip:{c:"int-chip-idle",t:"Stopped"},showStart:!0}}function $l({manifest:t,integration:s,state:a,onStatusChange:o,onSuccess:c}){var ze;const[u,f]=h.useState({}),[g,p]=h.useState(!1),[v,y]=h.useState(!1),[w,j]=h.useState({}),[N,b]=h.useState({}),[S,k]=h.useState(void 0),[T,R]=h.useState(!1),[P,A]=h.useState(null),[B,H]=h.useState(!1),[G,me]=h.useState(!1),[q,ce]=h.useState(!1),[ee,F]=h.useState(!1),[re,Y]=h.useState({}),[se,ye]=h.useState(null),[we,J]=h.useState(!1),[V,W]=h.useState(null),[C,L]=h.useState(!1);h.useEffect(()=>{let _=!1;return O.getCredential(t.id).then(oe=>{var ge;if(!(_||!oe.configured)){if(p(!0),y(!0),oe.fields){const Te={};for(const de of t.credentials.fields)oe.fields[de.key]!=null&&(Te[de.key]=oe.fields[de.key]);j(Te)}if(b(oe.secrets??{}),k(oe.updatedAt),t.oauth){const Te=((ge=oe.fieldNames)==null?void 0:ge.includes(t.oauth.tokenStorage))??!1;R(Te),Te&&O.getOAuthHealth(t.id).then(de=>{_||A(de)})}}}).catch(()=>{}),()=>{_=!0}},[t.id,t.oauth]);const fe=ew(t.toolGating),Q=s?s.readAgeDays??null:void 0,z=we&&se?se.value:Q,X=async _=>{ye({value:_}),J(!0),W(null);try{await O.setReadPolicy(t.id,_),c(_===null?`${t.name} read window now follows your mandate`:`${t.name} read window set to ${hi(_).toLowerCase()}`),o()}catch(oe){W(oe instanceof Error?oe.message:"Could not save")}finally{J(!1),ye(null)}},ne=!!t.oauth||t.credentials.fields.some(_=>!_.optional),ie=t.oauth?T:g,K=!ne||ie,ke=a==="starting"?"starting":K?s!=null&&s.running?"running":!g&&t.credentials.fields.length>0?"unconfigured":"ready":t.oauth&&g&&!T?"needs-oauth":"unconfigured",Ne=async()=>{if(t.credentials.fields.some(oe=>{var ge;return(ge=u[oe.key])==null?void 0:ge.trim()})){H(!0);try{await O.setCredential(t.id,u),p(!0),f({}),t.oauth?c(`${t.name} credentials saved!`):(c(`${t.name} credentials saved — starting integration...`),await He())}catch{c(`Failed to save ${t.name} credentials`)}finally{H(!1)}}},$e=()=>{const _={};for(const oe of t.credentials.fields){const ge=u[oe.key];oe.type==="password"?ge!=null&&ge.trim()&&(_[oe.key]=ge):ge!=null&&ge!==(w[oe.key]??"")&&(_[oe.key]=ge)}return _},pe=Object.keys($e()).length>0,Le=async()=>{const _=$e();if(Object.keys(_).length!==0){H(!0);try{await O.setCredential(t.id,_),f({}),p(!0),t.oauth?c(`${t.name} credentials saved — now click Connect.`):(F(!1),c(`${t.name} credentials updated — restarting...`),await He())}catch{c(`Failed to update ${t.name} credentials`)}finally{H(!1)}}},Ge=()=>{window.open(`/auth/oauth/${t.id}/start`,"_blank","width=600,height=700");const _=setInterval(async()=>{var oe;try{const ge=await O.getCredential(t.id);ge.configured&&t.oauth&&((oe=ge.fieldNames)!=null&&oe.includes(t.oauth.tokenStorage))&&(R(!0),F(!1),A(null),clearInterval(_),c(`${t.name} connected — starting integration...`),O.getOAuthHealth(t.id).then(A).catch(()=>{}),await He())}catch{}},2e3);setTimeout(()=>clearInterval(_),12e4)},He=async()=>{ce(!0);try{const _=await O.activateIntegration(t.id);_.warning?c(_.warning):c(`${t.name} integration started with ${_.tools.length} tools`),o()}catch(_){c(`Failed to start ${t.name}: ${_ instanceof Error?_.message:"Unknown error"}`)}finally{ce(!1)}},Oe=async()=>{try{await O.removeMcpIntegration(t.id),c(`${t.name} integration removed`),o()}catch{c(`Failed to remove ${t.name}`)}},lt=cm(t.icon),he=nw(s),Re=ke==="running"?{c:"int-chip-ok",t:"Running"}:ke==="starting"?{c:"int-chip-idle",t:"Starting"}:he.chip,Pe=t.oauth&&T&&(P==null?void 0:P.status)==="failed",ut=ne?Pe?{c:"int-chip-bad",t:"Auth failed"}:ie?{c:"int-chip-ok",t:"Auth OK"}:{c:"int-chip-idle",t:"Not set up"}:{c:"int-chip-idle",t:"No auth"},Je=_=>_.replace(/https?:\/\/[^\s)]+\/auth\/oauth\/[a-z-]+\/callback/gi,`${window.location.origin}/auth/oauth/${t.id}/callback`);return r.jsxs("div",{className:"card",style:{marginBottom:"1rem"},children:[r.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"0.75rem"},children:[r.jsx("span",{style:{fontSize:"1.4rem",lineHeight:1.2},children:lt}),r.jsx("h3",{className:"card-title",style:{margin:0,flex:1,alignSelf:"center"},children:t.name}),r.jsxs("div",{style:{display:"flex",gap:"0.4rem",flexWrap:"wrap",justifyContent:"flex-end"},children:[ke!=="unconfigured"&&ke!=="needs-oauth"&&r.jsxs("span",{className:`int-chip ${Re.c}`,children:[r.jsx("span",{className:"int-dot"}),Re.t]}),r.jsxs("span",{className:`int-chip ${ut.c}`,children:[r.jsx("span",{className:"int-dot"}),ut.t]}),Dv(t,w)&&r.jsxs("span",{className:"int-chip int-chip-sim",title:"This connector answers from a simulated system with test data. Nothing reaches your real systems.",children:[r.jsx("span",{className:"int-dot"}),"Simulation"]})]})]}),t.oauth&&T&&r.jsx("div",{className:"int-account",style:{marginTop:"0.7rem"},children:P!=null&&P.account?r.jsxs(r.Fragment,{children:["Connected as ",r.jsx("b",{children:P.account})]}):r.jsx("span",{className:"int-none",children:"Account not recorded — reconnect to capture which account is used"})}),Pe&&!ee&&r.jsxs("div",{style:{marginTop:"0.7rem",border:"1px solid var(--danger)",borderRadius:"10px",padding:"0.8rem 0.95rem",background:"color-mix(in srgb, var(--danger) 5%, var(--bg-elevated))"},children:[r.jsxs("div",{style:{fontSize:"0.86rem",fontWeight:700},children:[t.name," stopped accepting the stored credentials"]}),r.jsxs("p",{style:{fontSize:"0.8rem",color:"var(--text-muted)",margin:"0.3rem 0 0",lineHeight:1.55},children:[(P==null?void 0:P.error)==="invalid_grant"?r.jsxs(r.Fragment,{children:["The refresh token was revoked (",r.jsx("code",{children:"invalid_grant"}),") — this usually follows a password change or a security checkup on the provider's side."]}):P!=null&&P.error?r.jsxs(r.Fragment,{children:["The provider reported ",r.jsx("code",{children:P.error}),"."]}):r.jsx(r.Fragment,{children:"The provider rejected the stored authentication."})," ","Your agent's ",t.name," actions are ",r.jsx("b",{children:"blocked"}),", not failing silently."]}),r.jsxs("div",{style:{display:"flex",gap:"0.5rem",marginTop:"0.6rem"},children:[r.jsxs("button",{className:"btn btn-primary btn-sm",onClick:Ge,children:["Reconnect ",t.name]}),r.jsx("button",{className:"btn btn-ghost btn-sm",onClick:()=>{f({...w}),F(!0)},children:"Edit credentials"})]})]}),r.jsxs("details",{className:"int-details",style:{marginTop:"0.85rem",marginBottom:"1.25rem"},children:[r.jsx("summary",{children:"Details"}),r.jsxs("div",{className:"int-meta",children:[r.jsx("span",{className:"int-k",children:"What"}),r.jsx("span",{children:t.description}),t.profile&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"int-k",children:"Profile"}),r.jsx("span",{children:t.profile})]}),t.oauth&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"int-k",children:"Scopes"}),r.jsx("span",{children:((ze=t.oauth.scopes)==null?void 0:ze.join(", "))||"—"})]}),s&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"int-k",children:"Tools"}),r.jsxs("span",{children:[s.toolCount," gated"]})]})]})]}),t.setupGuide&&t.setupGuide.length>0&&(ke!=="running"||Pe)&&r.jsxs("div",{style:{marginBottom:"0.75rem"},children:[r.jsxs("button",{onClick:()=>me(!G),style:{background:"none",border:"none",padding:0,fontSize:"0.8rem",color:"var(--accent)",cursor:"pointer",display:"flex",alignItems:"center",gap:"0.375rem"},children:[r.jsx("span",{style:{transition:"transform 0.2s",transform:G?"rotate(90deg)":"rotate(0deg)",display:"inline-block"},children:"▶"}),"How to set up ",t.name]}),G&&r.jsx("div",{style:{marginTop:"0.75rem",paddingLeft:"0.25rem"},children:t.setupGuide.map((_,oe)=>r.jsxs("div",{style:{display:"flex",gap:"0.75rem",marginBottom:"0.75rem"},children:[r.jsx("div",{style:{width:"1.5rem",height:"1.5rem",borderRadius:"50%",background:"var(--border)",color:"var(--text-secondary)",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"0.7rem",fontWeight:700,flexShrink:0,marginTop:"0.1rem"},children:oe+1}),r.jsxs("div",{children:[r.jsx("div",{style:{fontSize:"0.85rem",fontWeight:600,color:"var(--text-primary)",marginBottom:"0.125rem"},children:_.title}),r.jsxs("div",{style:{fontSize:"0.8rem",color:"var(--text-secondary)",lineHeight:1.5},children:[Je(_.description),_.link&&r.jsxs(r.Fragment,{children:[" ",r.jsxs("a",{href:_.link,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"0.8rem"},children:["Open ","↗"]})]})]})]})]},oe))})]}),ke==="starting"&&r.jsxs("div",{className:"service-status",style:{color:"var(--warning)"},children:[r.jsx("span",{className:"service-status-dot",style:{background:"var(--warning)"}}),"Starting…"]}),ee&&r.jsxs("div",{style:{marginTop:"0.7rem",paddingTop:"0.85rem",borderTop:"1px solid var(--border)"},children:[r.jsx("div",{style:{fontSize:"0.85rem",fontWeight:600,marginBottom:"0.5rem"},children:"Change credentials"}),v&&r.jsxs("p",{style:{fontSize:"0.8rem",color:"var(--text-muted)",marginBottom:"0.6rem"},children:["Leaving a secret blank keeps the stored one — editing other fields can never silently wipe it.",t.oauth?" Save, then Connect to re-link the account.":""]}),t.credentials.fields.map(_=>{var oe;return r.jsxs("div",{className:"form-group",style:{marginBottom:"0.6rem"},children:[r.jsx("label",{className:"form-label",children:_.label}),_.type==="password"?r.jsxs("div",{className:"cred-field",children:[r.jsx("input",{className:"form-input",type:re[_.key]?"text":"password",name:`${t.id}-${_.key}-credential`,autoComplete:"new-password",placeholder:(oe=N[_.key])!=null&&oe.preview?`Unchanged — ends in ${N[_.key].preview}`:v?"Unchanged — paste a new value to replace":_.placeholder,value:u[_.key]||"",onChange:ge=>f(Te=>({...Te,[_.key]:ge.target.value}))}),r.jsx("button",{className:"cred-toggle",onClick:()=>Y(ge=>({...ge,[_.key]:!ge[_.key]})),children:re[_.key]?"hide":"show"})]}):r.jsx("input",{className:"form-input",type:"text",name:`${t.id}-${_.key}-credential`,autoComplete:"off",placeholder:_.placeholder,value:u[_.key]||"",onChange:ge=>f(Te=>({...Te,[_.key]:ge.target.value}))})]},_.key)}),r.jsxs("div",{style:{display:"flex",gap:"0.5rem",flexWrap:"wrap",marginTop:"0.25rem"},children:[r.jsx("button",{className:"btn btn-primary btn-sm",onClick:Le,disabled:B||!pe,children:B?"Saving…":"Save"}),!pe&&!B&&r.jsx("span",{style:{fontSize:"0.78rem",color:"var(--text-muted)",alignSelf:"center"},children:"No changes yet"}),t.oauth&&r.jsxs("button",{className:"btn btn-secondary btn-sm",onClick:Ge,children:["Connect ",t.name]}),r.jsx("button",{className:"btn btn-ghost btn-sm",onClick:()=>{F(!1),f({})},children:"Cancel"})]})]}),!ee&&ke==="running"&&s&&r.jsxs(r.Fragment,{children:[(Object.keys(w).length>0||Object.keys(N).length>0)&&r.jsx("div",{style:{display:"grid",gap:"0.3rem",margin:"0.15rem 0 0.7rem",fontSize:"0.82rem"},children:t.credentials.fields.map(_=>{const oe=_.type==="password",ge=N[_.key];return!oe&&w[_.key]==null||oe&&ge==null?null:r.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:"1rem"},children:[r.jsx("span",{style:{color:"var(--text-muted)"},children:_.label}),r.jsxs("span",{style:{fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",fontSize:"0.78rem",textAlign:"right",wordBreak:"break-all"},children:[oe?ge.preview??"set":w[_.key],oe&&S&&r.jsxs("span",{style:{color:"var(--text-muted)",fontFamily:"inherit"},children:[" ","· added ",new Date(S).toLocaleDateString(void 0,{month:"short",day:"numeric"})]})]})]},_.key)})}),r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem"},children:[r.jsx(xt,{to:"/mandates?new=1",className:"btn btn-primary btn-sm",style:{textDecoration:"none"},children:"Give a mandate"}),(t.credentials.fields.length>0||t.oauth)&&r.jsx("button",{className:"btn btn-sm btn-secondary",onClick:()=>{f({...w}),F(!0)},title:"Re-enter client ID / secret (e.g. a new OAuth client).",children:"Edit credentials"}),r.jsx("span",{style:{flex:1}}),r.jsx("button",{className:"btn btn-sm btn-ghost",style:{color:"var(--danger)"},onClick:Oe,title:"Stops the subprocess and removes the integration from the registry. It will NOT auto-start on next gateway restart. Re-enable with Install.",children:"Disable"})]}),fe&&z!==void 0&&!C&&r.jsx("div",{style:{marginTop:"0.9rem",paddingTop:"0.85rem",borderTop:"1px solid var(--border)"},children:r.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"0.6rem"},children:[r.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"0.5rem",minWidth:0},children:[r.jsx("span",{style:{fontSize:"0.85rem",fontWeight:600},children:"Reads"}),r.jsx("span",{style:{fontSize:"0.82rem",color:"var(--text-muted)"},children:z===null?"window from your mandate":hi(z).toLowerCase()}),we&&r.jsx("span",{style:{fontSize:"0.78rem",color:"var(--text-muted)"},children:"saving…"}),V&&r.jsx("span",{style:{fontSize:"0.78rem",color:"var(--danger)"},children:V})]}),r.jsx("button",{className:"btn btn-sm btn-secondary",onClick:()=>L(!0),children:"Edit"})]})}),fe&&z!==void 0&&C&&r.jsxs("div",{style:{marginTop:"0.9rem",paddingTop:"0.85rem",borderTop:"1px solid var(--border)"},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"0.6rem",marginBottom:"0.35rem"},children:[r.jsx("span",{style:{fontSize:"0.85rem",fontWeight:600},children:"How far back may your agent read?"}),r.jsx("button",{className:"btn btn-sm btn-ghost",onClick:()=>L(!1),children:"Done"})]}),r.jsx("p",{style:{fontSize:"0.78rem",color:"var(--text-tertiary)",margin:"0 0 0.55rem"},children:"Applies immediately — no Save, no new mandate."}),r.jsxs("div",{style:{display:"flex",gap:"0.4rem",flexWrap:"wrap"},children:[tw.map(_=>{const oe=z===_;return r.jsx("button",{className:`btn btn-sm ${oe?"btn-primary":"btn-secondary"}`,"aria-pressed":oe,disabled:we,onClick:()=>X(_),children:hi(_)},_)}),r.jsx("button",{className:`btn btn-sm ${z===null?"btn-primary":"btn-ghost"}`,"aria-pressed":z===null,disabled:we,onClick:()=>X(null),title:"Clear the local setting and use the read window from your signed mandate instead.",children:hi(null)})]}),r.jsx("div",{style:{fontSize:"0.78rem",marginTop:"0.5rem"},children:V?r.jsx("span",{style:{color:"var(--danger)"},children:V}):we?r.jsx("span",{style:{color:"var(--text-muted)"},children:"Saving…"}):z===null?r.jsx("span",{style:{color:"var(--text-muted)"},children:"Using the window from your mandate. If none is set there, reads are blocked."}):z===0?r.jsx("span",{style:{color:"var(--text-muted)"},children:"Your agent cannot read any mail."}):r.jsxs("span",{style:{color:"var(--text-muted)"},children:["Anything older than ",z," days is blocked, whoever it is from."]})})]}),r.jsx("div",{style:{display:"none"},children:r.jsx(xt,{to:"/mandates?new=1",className:"btn btn-ghost btn-sm",style:{textDecoration:"none",display:"block",textAlign:"center"},children:"Give your agent a mandate"})})]}),ke==="unconfigured"&&(()=>{const _=t.credentials.fields.every(Te=>Te.optional),oe=t.credentials.fields.some(Te=>!Te.optional),ge=t.credentials.fields.some(Te=>{var de;return(de=u[Te.key])==null?void 0:de.trim()});return r.jsxs(r.Fragment,{children:[v&&r.jsxs("div",{className:"alert",style:{fontSize:"0.8rem",background:"var(--bg-main)",border:"1px solid var(--border)",borderRadius:"0.375rem",padding:"0.5rem 0.75rem",marginBottom:"0.75rem",color:"var(--text-secondary)"},children:[r.jsx("strong",{style:{color:"var(--text-primary)"},children:"Credentials on file."})," ","Existing values are encrypted in the vault and not shown. Enter new values below to replace them, or"," ",r.jsx("button",{onClick:()=>{p(!0),t.oauth&&R(!0)},style:{background:"none",border:"none",padding:0,color:"var(--accent)",cursor:"pointer",textDecoration:"underline"},children:"keep existing"}),"."]}),t.oauth&&!v&&r.jsx("p",{style:{fontSize:"0.8rem",color:"var(--text-tertiary)",marginBottom:"0.5rem"},children:"Step 1 of 2 — enter credentials, then connect your account."}),t.setupHint&&!v&&r.jsx("p",{style:{fontSize:"0.8rem",color:"var(--text-tertiary)",marginBottom:"0.75rem"},children:t.setupHint}),t.credentials.fields.map(Te=>r.jsxs("div",{className:"form-group",style:{marginBottom:"0.75rem"},children:[r.jsx("label",{className:"form-label",children:Te.label}),Te.type==="password"?r.jsxs("div",{className:"cred-field",children:[r.jsx("input",{className:"form-input",type:re[Te.key]?"text":"password",name:`${t.id}-${Te.key}-credential`,autoComplete:"new-password",placeholder:Te.placeholder,value:u[Te.key]||"",onChange:de=>f(Me=>({...Me,[Te.key]:de.target.value}))}),r.jsx("button",{className:"cred-toggle",onClick:()=>Y(de=>({...de,[Te.key]:!de[Te.key]})),children:re[Te.key]?"hide":"show"})]}):r.jsx("input",{className:"form-input",type:"text",name:`${t.id}-${Te.key}-credential`,autoComplete:"off",placeholder:Te.placeholder,value:u[Te.key]||"",onChange:de=>f(Me=>({...Me,[Te.key]:de.target.value}))})]},Te.key)),r.jsxs("div",{style:{display:"flex",gap:"0.5rem"},children:[ge&&r.jsx("button",{className:"btn btn-primary",onClick:Ne,disabled:B||oe&&!t.credentials.fields.filter(Te=>!Te.optional).every(Te=>{var de;return(de=u[Te.key])==null?void 0:de.trim()}),children:B?"Saving...":"Save & Encrypt"}),_&&!ge&&r.jsx("button",{className:"btn btn-primary",onClick:He,disabled:q,children:q?"Starting...":`Activate ${t.name}`})]})]})})(),ke==="needs-oauth"&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{style:{fontSize:"0.8rem",color:"var(--success)",marginBottom:"0.25rem"},children:["✓"," Step 1 done — credentials saved"]}),r.jsxs("div",{style:{fontSize:"0.8rem",color:"var(--text-secondary)",marginBottom:"0.75rem"},children:["Step 2: connect your ",t.name," account to authorize access."]}),r.jsxs("div",{style:{display:"flex",gap:"0.5rem",flexWrap:"wrap"},children:[r.jsxs("button",{className:"btn btn-primary",onClick:Ge,children:["Connect ",t.name," Account"]}),r.jsx("button",{className:"btn btn-ghost",onClick:()=>p(!1),children:"Change Credentials"})]})]}),ke==="ready"&&!s&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{style:{fontSize:"0.8rem",color:"var(--success)",marginBottom:"0.75rem"},children:["✓"," ",t.oauth?`${t.name} account connected`:"Credentials configured"]}),r.jsxs("div",{style:{display:"flex",gap:"0.5rem",flexWrap:"wrap"},children:[r.jsx("button",{className:"btn btn-primary",onClick:He,disabled:q,children:q?"Starting...":`Start ${t.name} Integration`}),!t.oauth&&r.jsx("button",{className:"btn btn-ghost",onClick:()=>p(!1),children:"Update Credentials"}),t.oauth&&r.jsx("button",{className:"btn btn-ghost",onClick:()=>{p(!1),R(!1)},children:"Change Credentials"})]})]}),ke==="ready"&&s&&!s.running&&(he.showStart?r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"service-status service-status-error",style:{marginBottom:"0.75rem"},children:[r.jsx("span",{className:"service-status-dot"}),"Not running"]}),s.error&&r.jsx("div",{style:{fontSize:"0.8rem",color:"var(--danger)",marginBottom:"0.75rem"},children:s.error}),r.jsxs("div",{style:{display:"flex",gap:"0.5rem"},children:[r.jsx("button",{className:"btn btn-primary",onClick:He,disabled:q,children:q?"Starting...":"Start"}),r.jsx("button",{className:"btn btn-ghost",style:{color:"var(--danger)"},onClick:Oe,children:"Disable"})]})]}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"service-status",style:{marginBottom:"0.5rem",color:"var(--text-muted)"},children:[r.jsx("span",{className:"service-status-dot",style:{background:"var(--text-muted)"}}),"Paused"]}),r.jsx("p",{style:{fontSize:"0.8rem",color:"var(--text-muted)",marginBottom:"0.75rem"},children:"Real systems are off while simulation mode is on."}),r.jsx("div",{style:{display:"flex",gap:"0.5rem"},children:r.jsx("button",{className:"btn btn-ghost",style:{color:"var(--danger)"},onClick:Oe,children:"Disable"})})]}))]})}function rw(t,s){if(!s)return{grouped:!1,testSystems:[],realErrors:[],pausedReal:[],ungrouped:t};const a=t.filter(f=>Qs(f.manifest)),o=t.filter(f=>!Qs(f.manifest)),c=o.filter(f=>f.state==="error"),u=o.filter(f=>f.state!=="error");return{grouped:!0,testSystems:a,realErrors:c,pausedReal:u,ungrouped:[]}}function sw({entry:t}){return r.jsxs("div",{className:"int-paused-row",children:[r.jsx("span",{"aria-hidden":"true",children:cm(t.manifest.icon)}),r.jsx("span",{className:"int-paused-name",children:t.manifest.name}),r.jsxs("span",{className:"int-chip int-chip-paused",children:[r.jsx("span",{className:"int-dot"}),"Paused"]})]})}function aw(){const{loading:t,mcpServerUp:s,manifestsError:a,entries:o,refresh:c}=pc(),u=mc(),[f,g]=h.useState(""),p=h.useCallback(y=>{g(y),setTimeout(()=>g(""),5e3)},[]),v=rw(o,u);return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"page-header",children:[r.jsx("h1",{className:"page-title",children:"Integrations"}),r.jsx("p",{className:"page-subtitle",children:"Connect external services and manage MCP integrations."})]}),f&&r.jsx("div",{className:"alert alert-success",children:f}),t?r.jsx("p",{style:{color:"var(--text-tertiary)"},children:"Loading integrations..."}):s===!1?r.jsxs("div",{className:"status-banner status-banner-error",children:[r.jsx("span",{className:"status-banner-icon",children:"!"}),r.jsx("span",{className:"status-banner-text",children:"MCP server is not reachable. Make sure it is running."})]}):v.grouped?r.jsxs(r.Fragment,{children:[v.testSystems.length>0&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"int-group-label",children:"Test systems"}),v.testSystems.map(y=>r.jsx($l,{manifest:y.manifest,integration:y.integration,state:y.state,onStatusChange:c,onSuccess:p},y.id))]}),(v.realErrors.length>0||v.pausedReal.length>0)&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"int-group-label",children:"Real systems"}),v.realErrors.map(y=>r.jsx($l,{manifest:y.manifest,integration:y.integration,state:y.state,onStatusChange:c,onSuccess:p},y.id)),v.pausedReal.length>0&&r.jsxs("details",{className:"int-paused-group",open:!0,children:[r.jsxs("summary",{children:["Paused while simulation mode is on (",v.pausedReal.length,")"]}),r.jsxs("p",{className:"int-paused-group-note",children:["Nothing is lost — mandates, credentials and data stay. They start again when simulation mode is switched off (",r.jsx("code",{children:"suveren-gateway simulation off"}),")."]}),v.pausedReal.map(y=>r.jsx(sw,{entry:y},y.id))]})]}),o.length===0&&r.jsx(Df,{manifestsError:a})]}):r.jsxs(r.Fragment,{children:[o.map(y=>r.jsx($l,{manifest:y.manifest,integration:y.integration,state:y.state,onStatusChange:c,onSuccess:p},y.id)),o.length===0&&r.jsx(Df,{manifestsError:a})]})]})}function Df({manifestsError:t}){return t?r.jsxs("div",{className:"status-banner status-banner-error",children:[r.jsx("span",{className:"status-banner-icon",children:"!"}),r.jsxs("span",{className:"status-banner-text",children:["Couldn't load integrations — the gateway can't reach its MCP server (or you're signed out). Check the control-plane's"," ",r.jsx("code",{children:"SUVEREN_MCP_INTERNAL_URL"})," (dev MCP is :3431), then refresh."]})]}):r.jsx("p",{style:{color:"var(--text-tertiary)",textAlign:"center",marginTop:"2rem"},children:"No integrations available yet."})}function iw(){var F,re,Y;const{activeTeam:t,activeMembership:s,refreshGroups:a,user:o}=mt(),c=mn(),[u,f]=h.useState(null),[g,p]=h.useState(!1),[v,y]=h.useState(""),[w,j]=h.useState(""),[N,b]=h.useState(!1),[S,k]=h.useState(""),[T,R]=h.useState("");h.useEffect(()=>{fetch("/health").then(se=>se.json()).then(se=>{typeof se.spUrl=="string"&&R(se.spUrl)}).catch(()=>{})},[]),h.useEffect(()=>{if(!t){f(null);return}O.getGroupById(t.id).then(se=>{const ye=se.group??se,we=se.members??[],J=se.isAdmin??!1,V=we.map(W=>{const C=W.userId||W.id||"",L=W.role||(J&&C===ye.createdBy?"admin":"member");return{id:C,name:W.name||C.slice(0,8)||"Member",email:W.email||"",domains:W.domains||[],role:L,isAdmin:L==="admin"||J&&C===ye.createdBy}});f({id:ye.id,name:ye.name,members:V})}).catch(()=>f(null))},[t==null?void 0:t.id]);const P=(u==null?void 0:u.members.filter(se=>se.isAdmin))??[],A=(t==null?void 0:t.isAdmin)===!0&&P.length<=1&&P.some(se=>se.id===(o==null?void 0:o.id)),B=(t==null?void 0:t.name)??"",H=S.trim()===B&&!g,G=()=>{k(""),b(!0)},me=()=>{b(!1),k("")},q=async()=>{if(!(!t||!H)){p(!0),y("");try{await O.leaveTeam(t.id),await a(),j("You have left the team."),f(null),me()}catch(se){y(se instanceof Error?se.message:"Failed to leave team")}finally{p(!1)}}},ce=t&&T?`${T}/dashboard/groups/${t.id}`:void 0,ee=T?`${T}/dashboard/groups`:void 0;return r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"page-header",children:r.jsxs("div",{children:[r.jsx("h1",{className:"page-title",children:"Team"}),r.jsx("p",{className:"page-subtitle",children:"Your current team context. Team management lives in your Authority Server dashboard."})]})}),v&&r.jsx("div",{className:"error-message",children:v}),w&&r.jsx("div",{className:"alert alert-success",children:w}),t?r.jsxs("div",{className:"card",style:{marginBottom:"1.5rem"},children:[r.jsxs("div",{className:"card-header",children:[r.jsxs("div",{children:[r.jsx("h3",{className:"card-title",children:t.name}),r.jsxs("p",{style:{fontSize:"0.8rem",color:"var(--text-tertiary)",marginTop:"0.125rem"},children:[((F=u==null?void 0:u.members)==null?void 0:F.length)??0," ",(((re=u==null?void 0:u.members)==null?void 0:re.length)??0)===1?"member":"members",t.isAdmin&&" · You are admin"]})]}),r.jsx("span",{className:"status-badge status-active",children:"Active"})]}),(Y=u==null?void 0:u.members)==null?void 0:Y.map(se=>r.jsxs("div",{className:"member-row",children:[r.jsx("div",{className:"member-avatar",children:se.name.split(" ").map(ye=>ye[0]).join("").slice(0,2).toUpperCase()}),r.jsxs("div",{className:"member-info",children:[r.jsx("div",{className:"member-name",children:se.name}),r.jsx("div",{className:"member-email",children:se.email})]}),r.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-tertiary)"},children:se.role})]},se.id)),r.jsxs("div",{style:{marginTop:"1.25rem",paddingTop:"1rem",borderTop:"1px solid var(--border)",display:"flex",alignItems:"center",gap:"0.75rem",flexWrap:"wrap"},children:[ce&&r.jsx("a",{className:"btn btn-secondary btn-sm",href:ce,target:"_blank",rel:"noopener noreferrer",children:"Manage this team in your Authority Server →"}),r.jsx("span",{title:A?"You are the only admin. Transfer admin to another member in your Authority Server dashboard before leaving.":void 0,style:{marginLeft:"auto"},children:r.jsx("button",{className:"btn btn-ghost btn-sm",style:{color:"var(--text-tertiary)"},onClick:G,disabled:g||A,children:"Leave team"})})]})]}):r.jsxs("div",{className:"card",style:{textAlign:"center",padding:"2rem 1.5rem"},children:[r.jsx("h3",{style:{margin:"0 0 0.5rem 0",fontSize:"1rem"},children:"You are working solo."}),r.jsx("p",{style:{fontSize:"0.875rem",color:"var(--text-secondary)",marginBottom:"1rem",maxWidth:480,marginLeft:"auto",marginRight:"auto"},children:"Every mandate you create here is in your personal context. An account is Personal or in one team — joining or creating a team moves it."}),r.jsxs("div",{style:{display:"flex",gap:"0.75rem",justifyContent:"center",flexWrap:"wrap"},children:[r.jsx("button",{className:"btn btn-primary btn-sm",onClick:()=>c("/onboarding"),children:"Join or create a team"}),ee&&r.jsx("a",{className:"btn btn-ghost btn-sm",href:ee,target:"_blank",rel:"noopener noreferrer",children:"Manage teams in your Authority Server →"})]})]}),N&&t&&r.jsx("div",{role:"dialog","aria-modal":"true","aria-labelledby":"leave-team-title",style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3,padding:"1rem"},onClick:me,children:r.jsxs("div",{className:"card",onClick:se=>se.stopPropagation(),style:{maxWidth:480,width:"100%",margin:0},children:[r.jsxs("h3",{id:"leave-team-title",className:"card-title",style:{marginBottom:"0.5rem"},children:["Leave ",B,"?"]}),r.jsx("p",{style:{fontSize:"0.875rem",color:"var(--text-secondary)",marginBottom:"0.75rem"},children:"Leaving will:"}),r.jsxs("ul",{style:{fontSize:"0.875rem",color:"var(--text-secondary)",marginBottom:"1rem",paddingLeft:"1.25rem",lineHeight:1.6},children:[r.jsx("li",{children:"Revoke all mandates you created in this team's context"}),r.jsx("li",{children:"Reject any pending action proposals you authored"}),r.jsx("li",{children:"Disable your membership — rejoining requires admin reactivation"})]}),r.jsxs("p",{style:{fontSize:"0.875rem",color:"var(--text-secondary)",marginBottom:"1rem"},children:["Your ",r.jsx("strong",{children:"personal"})," mandates are not affected."]}),r.jsxs("div",{className:"form-group",children:[r.jsxs("label",{htmlFor:"leave-confirm-input",style:{fontSize:"0.825rem",display:"block",marginBottom:"0.375rem"},children:["Type ",r.jsx("code",{children:B})," to confirm:"]}),r.jsx("input",{id:"leave-confirm-input",className:"form-input",type:"text",value:S,onChange:se=>k(se.target.value),placeholder:B,disabled:g,autoFocus:!0})]}),r.jsxs("div",{style:{display:"flex",gap:"0.5rem",justifyContent:"flex-end",marginTop:"1rem"},children:[r.jsx("button",{className:"btn btn-ghost",onClick:me,disabled:g,children:"Cancel"}),r.jsx("button",{className:"btn btn-secondary",style:{color:"var(--danger, #e53e3e)"},onClick:q,disabled:!H,children:g?"Leaving...":"Leave team"})]})]})})]})}const ow=new Set(["mail","users","receipt","credit-card","calendar","megaphone","archive","rocket","flask","shopping-cart","bar-chart","help-circle"]),lw={email:"mail",customers:"users",sales:"receipt",charge:"credit-card",calendar:"calendar",publish:"megaphone",records:"archive",deploy:"rocket",delegation:"flask",purchase:"shopping-cart",reporting:"bar-chart"};function cw(t){const s=t.lastIndexOf("/"),a=s>=0?t.slice(s+1):t,o=a.indexOf("@");return(o>=0?a.slice(0,o):a).toLowerCase()}function Nr(t,s){const a=cw(t),o=s!=null&&s.icon&&ow.has(s.icon)?s.icon:lw[a]??"help-circle",c=ht(t,s==null?void 0:s.name);return{icon:o,name:c,testSetup:a==="delegation"}}function Oi(t){return t.startsWith("setup__")}const uw={mail:r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"3",y:"5",width:"18",height:"14",rx:"2"}),r.jsx("path",{d:"m3 7 9 6 9-6"})]}),users:r.jsxs(r.Fragment,{children:[r.jsx("circle",{cx:"9",cy:"8",r:"3.2"}),r.jsx("path",{d:"M3.5 20c0-3.6 2.5-6.3 5.5-6.3s5.5 2.7 5.5 6.3"}),r.jsx("circle",{cx:"17.2",cy:"9.2",r:"2.3"}),r.jsx("path",{d:"M16.8 13.9c2.4.5 4.2 2.6 4.2 5.4"})]}),receipt:r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M6 3h12v18l-2.2-1.4L14 21l-2-1.4L10 21l-2-1.4L6 21V3Z"}),r.jsx("line",{x1:"9",y1:"7.5",x2:"15",y2:"7.5"}),r.jsx("line",{x1:"9",y1:"11.5",x2:"15",y2:"11.5"}),r.jsx("line",{x1:"9",y1:"15.5",x2:"13",y2:"15.5"})]}),"credit-card":r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"2",y:"5",width:"20",height:"14",rx:"2.2"}),r.jsx("line",{x1:"2",y1:"10",x2:"22",y2:"10"}),r.jsx("line",{x1:"5.5",y1:"15",x2:"9.5",y2:"15"})]}),calendar:r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"3",y:"4.5",width:"18",height:"16.5",rx:"2"}),r.jsx("line",{x1:"3",y1:"9.5",x2:"21",y2:"9.5"}),r.jsx("line",{x1:"8",y1:"2.5",x2:"8",y2:"6.5"}),r.jsx("line",{x1:"16",y1:"2.5",x2:"16",y2:"6.5"})]}),megaphone:r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M3 10.2v3.6c0 .7.6 1.2 1.2 1.2h2.6l6.4 4V5l-6.4 4H4.2C3.6 9 3 9.5 3 10.2Z"}),r.jsx("path",{d:"M14.5 8.3a4.3 4.3 0 0 1 0 7.4"}),r.jsx("path",{d:"M17.6 6a7.6 7.6 0 0 1 0 12"})]}),archive:r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"3",y:"3.5",width:"18",height:"5",rx:"1.2"}),r.jsx("path",{d:"M5 8.5V18a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8.5"}),r.jsx("line",{x1:"10",y1:"13",x2:"14",y2:"13"})]}),rocket:r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M12 2.2c2.4 2 3.8 5.3 3.8 8.6 0 1.9-.9 3.9-.9 3.9H9.1s-.9-2-.9-3.9c0-3.3 1.4-6.6 3.8-8.6Z"}),r.jsx("path",{d:"M9 14.7 6.3 19.4l3.8-1.7"}),r.jsx("path",{d:"M15 14.7l2.7 4.7-3.8-1.7"}),r.jsx("circle",{cx:"12",cy:"9.3",r:"1.3"})]}),flask:r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M9 3h6"}),r.jsx("path",{d:"M10 3v6.3l-5 9.1A2 2 0 0 0 6.7 21.5h10.6a2 2 0 0 0 1.7-3.1l-5-9.1V3"}),r.jsx("line",{x1:"8.3",y1:"14.5",x2:"15.7",y2:"14.5"})]}),"shopping-cart":r.jsxs(r.Fragment,{children:[r.jsx("circle",{cx:"9",cy:"20",r:"1.4"}),r.jsx("circle",{cx:"18",cy:"20",r:"1.4"}),r.jsx("path",{d:"M2.5 3h2.4l2.1 11.2a2 2 0 0 0 2 1.6h8.6a2 2 0 0 0 2-1.6l1.4-7.6H6"})]}),"bar-chart":r.jsxs(r.Fragment,{children:[r.jsx("line",{x1:"4",y1:"20.5",x2:"20",y2:"20.5"}),r.jsx("rect",{x:"6",y:"13",width:"3.2",height:"7.5"}),r.jsx("rect",{x:"11.4",y:"8.5",width:"3.2",height:"12"}),r.jsx("rect",{x:"16.8",y:"4",width:"3.2",height:"16.5"})]}),"help-circle":r.jsxs(r.Fragment,{children:[r.jsx("circle",{cx:"12",cy:"12",r:"9.2"}),r.jsx("path",{d:"M9.6 9.6a2.5 2.5 0 1 1 3.6 2.3c-.9.5-1.4 1.1-1.4 2.2"}),r.jsx("line",{x1:"12",y1:"17",x2:"12",y2:"17.05"})]})};function um({icon:t,className:s}){return r.jsx("svg",{className:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.75,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:uw[t]})}function rs({profileId:t,declared:s}){const{icon:a,name:o}=Nr(t,s);return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"id-rail",children:[r.jsx(um,{icon:a,className:"id-rail-icon"}),r.jsx("span",{className:"id-rail-name",children:o})]}),r.jsx("div",{className:"id-sep"})]})}const Xs=t=>t.replace(/@.*$/,"").split("/").pop()??t,Uf=t=>t.split("@")[1]??"";function dw(t,s){const a=new Map;for(const o of t){const c=Xs(o.id);if(!s.has(c))continue;const u=a.get(c);(!u||Uf(o.id).localeCompare(Uf(u.id),void 0,{numeric:!0})>0)&&a.set(c,o)}return a}function fw(t,s,a,o){var g;const c=new Set([...s.filter(p=>p.profile).map(p=>p.profile),...o.map(p=>Xs(p.profile))]),u=dw(t,c),f=[];for(const p of s){const v=p.profile?u.get(p.profile):void 0;v&&f.push({key:`connector:${p.id}`,name:p.name,description:p.description||v.description,profile:v,kind:"connector",ready:((g=a.find(y=>y.id===p.id))==null?void 0:g.running)===!0,setupId:p.id,...p.intentHint?{intentHint:p.intentHint}:{}})}for(const p of o){const v=u.get(Xs(p.profile));v&&f.push({key:`builtin:${p.id}`,name:p.name,description:p.description||v.description,profile:v,kind:"builtin",ready:p.available,unavailableReason:p.available?void 0:"Available only while simulation mode is on.",...p.intentHint?{intentHint:p.intentHint}:{}})}return f}function hw(t,s,a){if(s)return t.find(o=>Xs(o.profile.id)===Xs(s)&&o.ready&&a(o))}function mw({onDismiss:t,preselectProfileId:s}){const a=mn(),{group:o,groupId:c,domain:u,user:f}=mt(),[g,p]=h.useState([]),[v,y]=h.useState([]),[w,j]=h.useState([]),[N,b]=h.useState([]),[S,k]=h.useState(!0),[T,R]=h.useState({});h.useEffect(()=>{Promise.all([O.listProfiles().catch(()=>[]),O.getIntegrationManifests().then(q=>q.manifests??[]).catch(()=>[]),O.getMcpHealth().catch(()=>null)]).then(async([q,ce,ee])=>{if(p(q),y(ce),j((ee==null?void 0:ee.integrations)??[]),b((ee==null?void 0:ee.builtins)??[]),c){const F=await Promise.all(q.map(Y=>O.getTeamProfileConfig(c,Y.id).catch(()=>null))),re={};q.forEach((Y,se)=>{const ye=F[se];ye&&(re[Y.id]=ye)}),R(re)}}).finally(()=>k(!1))},[c]);const P=fw(g,v,w,N),A=q=>{const ce=T[q.id];return im({isPersonal:!!(o!=null&&o.isPersonal),configLoaded:!S,grantors:ce?Ph(ce):void 0,userId:f==null?void 0:f.id,profileName:ht(q.id),teamName:o==null?void 0:o.name})},B=q=>q in T,H=(q,ce)=>{if(!c){console.error("No active group when creating authorization");return}const ee=B(q);sessionStorage.setItem("agentAuth",JSON.stringify({profileId:q,groupId:c,groupName:(o==null?void 0:o.name)??null,domain:u,isTeam:ee,isPersonal:!!(o!=null&&o.isPersonal),...ce?{intentHint:ce}:{}})),sessionStorage.removeItem("agentGate"),t==null||t(),a("/mandates/new/intent")},G=(q,ce)=>{c&&H(q,ce)},me=h.useRef(!1);return h.useEffect(()=>{if(S||!s||me.current)return;const q=hw(P,s,ce=>A(ce.profile).can);q&&(me.current=!0,G(q.profile.id,q.intentHint))},[S,s]),r.jsxs(r.Fragment,{children:[r.jsx("style",{children:`
75
+ .profile-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.25rem; align-items: stretch; }
76
+ .profile-grid .card { display: flex; flex-direction: column; height: 100%; margin-top: 0 !important; }
77
+ @media (max-width: 900px) { .profile-grid { grid-template-columns: repeat(2, 1fr); } }
78
+ @media (max-width: 560px) { .profile-grid { grid-template-columns: 1fr; } }
79
+ `}),S?r.jsx("p",{style:{color:"var(--text-tertiary)",fontSize:"0.9rem"},children:"Loading..."}):P.length===0?r.jsxs("div",{className:"card",style:{padding:"2rem",textAlign:"center"},children:[r.jsx("p",{style:{color:"var(--text-secondary)",fontSize:"0.9rem",marginBottom:"1rem"},children:"No integrations set up yet. Connect a service first."}),r.jsx(xt,{to:"/integrations",className:"btn btn-primary btn-sm",onClick:()=>t==null?void 0:t(),children:"Go to Integrations"})]}):r.jsx("div",{className:"profile-grid",children:P.map(q=>{const ce=q.profile,ee=B(ce.id),F=A(ce),re=!q.ready||!F.can,{icon:Y}=Nr(ce.id,{name:ce.name,icon:ce.icon});return r.jsxs("div",{className:"card",style:re?{opacity:.7}:void 0,children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",marginBottom:"0.125rem"},children:[r.jsxs("h3",{className:"card-title profile-chip",style:{margin:0},children:[r.jsx(um,{icon:Y,className:"profile-chip-icon"}),q.name]}),ee?r.jsx("span",{style:{fontSize:"0.6rem",padding:"0.1rem 0.35rem",borderRadius:"0.2rem",background:"var(--accent-subtle)",color:"var(--accent)",fontWeight:600},children:"Team"}):o!=null&&o.isPersonal?r.jsx("span",{style:{fontSize:"0.6rem",padding:"0.1rem 0.35rem",borderRadius:"0.2rem",background:"var(--bg-main)",color:"var(--text-tertiary)",fontWeight:600,border:"1px solid var(--border)"},children:"Personal"}):null]}),r.jsx("p",{style:{fontSize:"0.8rem",color:"var(--text-tertiary)",marginBottom:"1rem",flex:1},children:q.description}),F.can?q.ready?r.jsx("button",{className:"btn btn-primary btn-sm",onClick:()=>G(ce.id,q.intentHint),children:"Give a mandate"}):q.kind==="builtin"?r.jsxs(r.Fragment,{children:[r.jsx("button",{className:"btn btn-secondary btn-sm",disabled:!0,children:"Give a mandate"}),r.jsx("div",{style:{fontSize:"0.75rem",color:"var(--text-tertiary)",marginTop:"0.5rem"},children:q.unavailableReason})]}):r.jsxs(xt,{to:`/integrations?setup=${q.setupId??""}`,className:"btn btn-secondary btn-sm",style:{textDecoration:"none",textAlign:"center"},onClick:()=>t==null?void 0:t(),children:["Set up ",q.name]}):r.jsxs(r.Fragment,{children:[r.jsx("button",{className:"btn btn-secondary btn-sm",disabled:!0,children:"Give a mandate"}),r.jsxs("div",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",marginTop:"0.5rem"},children:[F.reason," ",r.jsx("span",{style:{color:"var(--text-tertiary)"},children:F.fix})]})]})]},q.key)})})]})}const pw={active:"Active",pending:"Pending",expired:"Expired",revoked:"Revoked"};function gw({status:t,label:s}){return r.jsx("span",{className:`status-badge status-${t}`,children:s||pw[t]})}function yw({domain:t,attested:s}){const a=s===!0?"domain-attested":s===!1?"domain-missing":"";return r.jsx("span",{className:`domain-badge ${a}`,style:{fontSize:"0.75rem"},children:t})}const xr=86400,Ks=3600,mi=60,vw=30*xr;function xw(t){if(t<=0)return"Expired";if(t>90*xr){const s=Math.floor(t/vw);return`${s} ${s===1?"month":"months"} remaining`}if(t>7*xr){const s=Math.floor(t/xr);return`${s} ${s===1?"day":"days"} remaining`}if(t>=2*xr){const s=Math.floor(t/xr),a=Math.floor(t%xr/Ks);return`${s} ${s===1?"day":"days"} ${a}h remaining`}if(t>=2*Ks){const s=Math.floor(t/Ks),a=Math.floor(t%Ks/mi);return`${s}h ${String(a).padStart(2,"0")}m remaining`}if(t>=mi){const s=Math.floor(t/mi),a=Math.floor(t%mi);return`${s}m ${String(a).padStart(2,"0")}s remaining`}return`${Math.floor(t)}s remaining`}function ww({expiresAt:t}){const[s,a]=h.useState(()=>t-Date.now()/1e3),o=s<2*Ks;h.useEffect(()=>{const u=setInterval(()=>a(t-Date.now()/1e3),o?1e3:6e4);return()=>clearInterval(u)},[t,o]);const c=s<300;return r.jsx("span",{className:`ttl-badge ${c?"ttl-warn":"ttl-ok"}`,children:xw(s)})}function Zr({icon:t,title:s,text:a,children:o}){return r.jsxs("div",{className:"empty-state",children:[t&&r.jsx("div",{className:"empty-state-icon",children:t}),r.jsx("div",{className:"empty-state-title",children:s}),a&&r.jsx("div",{className:"empty-state-text",children:a}),o]})}function jw(t){const s=Math.floor(t/86400);if(s>=1)return`${s} day${s===1?"":"s"}`;const a=Math.floor(t/3600);if(a>=1)return`${a} hour${a===1?"":"s"}`;const o=Math.ceil(t/60);return`${o} minute${o===1?"":"s"}`}const Sw=[{label:"30m",seconds:1800},{label:"1h",seconds:3600},{label:"2h",seconds:7200},{label:"4h",seconds:14400},{label:"8h",seconds:28800},{label:"24h",seconds:86400},{label:"7d",seconds:604800},{label:"30d",seconds:2592e3},{label:"1y",seconds:31536e3}];function bw({item:t,onClose:s,onSuccess:a}){var P;const{user:o,activeDomain:c,groupId:u}=mt(),[f,g]=h.useState(null);h.useEffect(()=>{let A=!1;return O.getProfile(t.profile_id).then(B=>{var H;A||g(((H=B==null?void 0:B.ttl)==null?void 0:H.max)??null)}).catch(()=>{}),()=>{A=!0}},[t.profile_id]);const p=t.remaining_seconds??0,v=Sw.filter(A=>A.seconds>p&&(f===null||A.seconds<=f)),y=((P=v[0])==null?void 0:P.seconds)??2592e3,[w,j]=h.useState(y);h.useEffect(()=>{var A;if(f!==null&&w>f){const B=(A=v[v.length-1])==null?void 0:A.seconds;B&&j(B)}},[f]);const[N,b]=h.useState(!1),[S,k]=h.useState(""),T=Object.entries(t.frame).filter(([A])=>A!=="profile"&&A!=="path"),R=async()=>{var A;if(o){b(!0),k("");try{const B=t.authorization_id,H=await O.getGateContent(B);if(!H)throw new Error("Gate content not found locally. The MCP server may have restarted. Please re-authorize through the full wizard instead.");const G=await O.getProfile(t.profile_id),me=t.frame,q=H.context??{},ce=t.attested_domains[0]||c||"owner",ee=await xi(me,G),F=await nm(q,G),[re,Y]=await Promise.all([Ni(H.gateContent.intent),Ni(JSON.stringify({profile:t.profile_id,path:t.path,domain:ce}))]);if(!u)throw new Error("No active group; cannot extend mandate.");const se=(((A=t.deferred_commitment_domains)==null?void 0:A.length)??0)>0?"review":"automatic",ye=await rm(G),we=await O.attest({authorization_id:t.authorization_id,renew:!0,profile_id:t.profile_id,profile_hash:ye,supported_versions:["0.7"],bounds:me,bounds_hash:ee,scope_hash:F,domain:ce,did:o.did,mandate_owners:[{did:o.did}],gate_content_hashes:{intent:re},execution_context_hash:Y,group_id:u,commitment_mode:se,ttl:w});await O.pushGateContent(sm(we,{boundsHash:ee,contextHash:F,context:q,path:t.path,gateContent:H.gateContent})),a()}catch(B){k(B instanceof Error?B.message:"Extension failed")}finally{b(!1)}}};return r.jsx("div",{className:"modal-backdrop",onClick:A=>A.target===A.currentTarget&&s(),children:r.jsxs("div",{className:"modal",children:[r.jsxs("div",{className:"modal-header",children:[r.jsx("h3",{className:"modal-title",children:"Extend mandate"}),r.jsx("button",{className:"modal-close",onClick:s,children:"×"})]}),r.jsxs("div",{className:"modal-body",children:[r.jsxs("div",{style:{marginBottom:"1rem"},children:[r.jsxs("div",{style:{fontWeight:600,marginBottom:"0.25rem"},children:[ht(t.profile_id)," / ",t.path]}),T.length>0&&r.jsx("div",{style:{fontSize:"0.8rem",color:"var(--text-tertiary)"},children:T.map(([A,B])=>`${A}=${B}`).join(" · ")})]}),r.jsxs("div",{style:{marginBottom:"1rem"},children:[r.jsx("div",{style:{fontSize:"0.75rem",fontWeight:600,color:"var(--text-tertiary)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:"0.5rem"},children:"New duration"}),p>0&&r.jsxs("div",{style:{fontSize:"0.75rem",color:"var(--text-tertiary)",marginBottom:"0.5rem"},children:["Currently valid for ",jw(p),". Only longer durations are shown."]}),r.jsx("div",{style:{display:"flex",gap:"0.5rem",flexWrap:"wrap"},children:v.length===0?r.jsx("div",{style:{fontSize:"0.8rem",color:"var(--text-tertiary)"},children:"This mandate is already on the longest available duration. Nothing to extend."}):v.map(A=>r.jsx("button",{className:`btn ${w===A.seconds?"btn-primary":"btn-secondary"}`,onClick:()=>j(A.seconds),style:{minWidth:"3.5rem"},children:A.label},A.seconds))})]}),r.jsx("div",{style:{fontSize:"0.8rem",color:"var(--text-tertiary)",marginBottom:"0.5rem"},children:"Same bounds, scope, and gate content will be re-signed with a new TTL (measured from now)."}),S&&r.jsx("div",{className:"error-message",children:S})]}),r.jsxs("div",{className:"modal-footer",children:[r.jsx("button",{className:"btn btn-secondary",onClick:s,disabled:N,children:"Cancel"}),r.jsx("button",{className:"btn btn-primary",onClick:R,disabled:N,children:N?"Extending...":"Extend"})]})]})})}function Wf(t){return t.replace(/@.*$/,"").split("/").pop()??t}function Hf(t){return t.split("@")[1]??""}function kw(t,s){return Hf(t).localeCompare(Hf(s),void 0,{numeric:!0})>0}function dm(t,s){const a=Wf(t);let o;for(const c of s)Wf(c.id)===a&&(!o||kw(c.id,o.id))&&(o=c);return o}function fm(t,s){var o;if(!s)return{};const a={};for(const c of s.keyOrder){if(c==="profile"||c==="path")continue;if(t[c]!==void 0){a[c]=t[c];continue}const u=(o=s.fields[c])==null?void 0:o.default;(typeof u=="string"||typeof u=="number"&&Number.isFinite(u))&&(a[c]=u)}return a}function hm(t,s){return fm(t,s.boundsSchema)}function mm(t,s){return fm(t,s.scopeSchema)}function Nw(t,s,a){return[...t].sort((o,c)=>{if(a){if(o.authorization_id===a&&c.authorization_id!==a)return-1;if(c.authorization_id===a&&o.authorization_id!==a)return 1}const u=Si(o,s),f=Si(c,s),g={active:0,pending:1,expired:2,revoked:3,archived:4};return g[u]!==g[f]?g[u]-g[f]:new Date(c.created_at).getTime()-new Date(o.created_at).getTime()})}function Cw({item:t,newerProfile:s,revokedSet:a,expandedHash:o,gateCache:c,gateLoading:u,copiedHash:f,revokingHash:g,copyingHash:p,profileConfigCache:v,mode:y,ownerLabel:w,isAdmin:j,onExpand:N,onCopyHash:b,onCopy:S,onRevoke:k,onExtend:T,archivedSet:R,archivingHash:P,onArchive:A,highlightHash:B,needsReapprovalSet:H}){var ke;const G=hc(t,{revokedSet:a}),me=G==="active"&&((H==null?void 0:H.has(t.authorization_id))??!1),q=Fh(t,{revokedSet:a,archivedSet:R}),ce=!w&&!!A&&zh(G),ee=o===t.authorization_id,F=c[t.authorization_id],re=G==="active"||G==="pending"||G==="expired",Y=Object.entries(t.frame).filter(([Ne])=>Ne!=="profile"&&Ne!=="path"),se=v.get(t.profile_id)??null,ye=(((ke=se==null?void 0:se.approvers)==null?void 0:ke.length)??0)>0,we=new Map;if(se!=null&&se.caps&&y==="team")for(const[Ne,$e]of Y){const pe=se.caps[Ne];typeof pe=="number"&&Number($e)>pe&&we.set(Ne,{authorized:Number($e),cap:pe})}const J=we.size>0,V=t.approvers_frozen??[],W=(se==null?void 0:se.approvers)??[],C=y==="team"&&V.length>0&&W.length>0&&(V.length!==W.length||V.some(Ne=>!W.includes(Ne))||W.some(Ne=>!V.includes(Ne))),L=Array.from(we.entries()).map(([Ne,$e])=>`${Ne}: ${$e.authorized} (cap ${$e.cap})`).join(", "),fe=Array.from(we.entries()).map(([Ne,$e])=>`${Ne}: ${$e.authorized} → ${$e.cap}`).join(", "),Q=J?ye?we.size===1?`Above team cap: ${L} — actions require approval`:`Above team cap (${we.size}): ${L} — actions require approval`:we.size===1?`Reduced by hard cap: ${fe}`:`Reduced by hard cap (${we.size}): ${fe}`:"",z=J?ye?"Above-cap actions under this mandate require per-action approval from the profile's approvers. Bounds remain authorized at their original values.":"No approvers are configured for this profile, so the team cap is a hard ceiling. Bounds above the cap are effectively reduced to the cap. Ask the admin to raise the cap or add approvers, or copy this mandate to reissue within the cap.":void 0,X=Nr(t.profile_id),ne=X.name,ie=s?r.jsxs("div",{style:{fontSize:"0.75rem",color:"var(--text-tertiary)",marginBottom:"0.5rem",padding:"0.4rem 0.6rem",border:"1px solid var(--border)",borderRadius:6},children:[r.jsxs("strong",{style:{color:"var(--text-secondary)"},children:[ne,"@",s.version," available"]}),s.whatsNew?r.jsxs(r.Fragment,{children:[" — ",s.whatsNew]}):null,r.jsx("br",{}),r.jsxs("span",{children:["This mandate stays on ",t.profile_id.split("@")[1]??"its pinned version","; authorize again to move it."]})]}):null,K=B!=null&&t.authorization_id===B;return r.jsxs("div",{className:`card id-card${K?" card-highlight":""}`,style:{marginBottom:0},children:[r.jsx(rs,{profileId:t.profile_id}),r.jsxs("div",{className:"id-body",children:[ie,w&&r.jsxs("div",{style:{fontSize:"0.75rem",color:"var(--text-tertiary)",marginBottom:"0.375rem"},children:["Owner: ",r.jsx("span",{style:{color:"var(--text-secondary)",fontWeight:500},children:w})]}),r.jsxs("div",{className:"auth-card-header",children:[r.jsx("span",{style:{fontWeight:700,fontSize:"1rem",color:"var(--text-primary)",letterSpacing:"0.01em"},children:t.title||ne}),r.jsx(gw,{status:G}),me&&r.jsx("span",{title:"The Authority Server no longer verifies this mandate's protocol version. Re-approve it to keep using this authority.",style:{fontSize:"0.75rem",fontWeight:700,color:"var(--text-on-warning, #7a4a00)",background:"var(--warning-bg, #fff3cd)",borderRadius:"4px",padding:"2px 6px"},children:"Needs re-approval"}),X.testSetup&&r.jsx("span",{className:"sim-mark",children:"Test setup"}),G==="active"&&t.earliest_expiry&&r.jsx(ww,{expiresAt:new Date(t.earliest_expiry).getTime()/1e3}),G==="expired"&&(()=>{const Ne=Bv(t,G);return Ne?r.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-tertiary)"},title:`Expired ${new Date(Ne.iso).toLocaleString()}`,children:new Date(Ne.iso).toLocaleDateString(void 0,{month:"short",day:"numeric"})}):null})()]}),r.jsxs("div",{style:{display:"flex",gap:"0.5rem",flexWrap:"wrap",marginBottom:"0.5rem",alignItems:"center"},children:[t.required_domains.map(Ne=>r.jsx(yw,{domain:Ne,attested:t.attested_domains.includes(Ne)},Ne)),t.deferred_commitment_domains.length>0&&r.jsx("span",{style:{fontSize:"0.65rem",padding:"0.15rem 0.4rem",borderRadius:"0.25rem",background:"var(--accent-subtle)",color:"var(--accent)",fontWeight:600},children:"Review Mode"}),J&&r.jsx("span",{title:z,style:{fontSize:"0.65rem",padding:"0.15rem 0.4rem",borderRadius:"0.25rem",background:ye?"var(--accent-subtle)":"var(--danger-subtle)",color:ye?"var(--accent)":"var(--danger)",fontWeight:600,cursor:"help"},children:Q}),C&&r.jsx("button",{className:"btn btn-ghost btn-sm",style:{fontSize:"0.65rem",padding:"0.15rem 0.5rem",borderRadius:"0.25rem",background:"var(--warning-subtle, rgba(234,179,8,0.12))",color:"var(--warning, #ca8a04)",fontWeight:600,border:"1px solid var(--warning-border, rgba(234,179,8,0.3))",cursor:"pointer",lineHeight:1.4},onClick:()=>S(t),disabled:p===t.authorization_id,title:"The approver list for this profile has changed since this mandate was created. Copy to reissue with the current approvers.",children:p===t.authorization_id?"Copying...":"Approver list updated · Copy with new approvers"})]}),Y.length>0&&r.jsx("div",{style:{fontSize:"0.8rem",color:"var(--text-tertiary)"},children:Y.map(([Ne,$e],pe)=>{const Le=we.get(Ne);return r.jsxs("span",{children:[pe>0&&" · ",Le?ye?r.jsxs("span",{title:`Team cap on ${Ne} is ${Le.cap}. Actions exceeding the cap require per-action approval. Bound remains authorized at ${Le.authorized}.`,children:[r.jsxs("span",{style:{color:"var(--text-tertiary)"},children:[Ne,"=",String($e)]}),r.jsxs("span",{style:{color:"var(--accent)",marginLeft:"0.25rem",fontWeight:600},children:["↑ approval at ",Le.cap]})]}):r.jsxs("span",{title:`Team cap on ${Ne} is ${Le.cap} with no approvers configured (hard cap). Authorized for ${Le.authorized}; effective ${Le.cap}.`,children:[r.jsxs("span",{style:{textDecoration:"line-through",color:"var(--text-tertiary)"},children:[Ne,"=",String($e)]}),r.jsxs("span",{style:{color:"var(--danger)",marginLeft:"0.25rem",fontWeight:600},children:["→"," ",Le.cap]})]}):r.jsxs("span",{children:[Ne,"=",String($e)]})]},Ne)})}),r.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"0.5rem",marginTop:"0.5rem"},children:[ce&&r.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>A(t.authorization_id,!q),disabled:P===t.authorization_id,title:q?"Move back to the Expired or Revoked list":"Hide from the list and the nav badge. Nothing is deleted: the mandate and its tickets stay stored and verifiable.",children:P===t.authorization_id?q?"Unarchiving…":"Archiving…":q?"↩ Unarchive":"⊟ Archive"}),r.jsx("button",{className:"btn btn-ghost btn-sm",onClick:()=>N(t),children:ee?"▲ Hide Details":"▼ Details"})]}),ee&&r.jsxs("div",{style:{borderTop:"1px solid var(--border)",marginTop:"0.75rem",paddingTop:"0.75rem"},children:[Y.length>0&&r.jsxs(r.Fragment,{children:[r.jsx("div",{style:{fontSize:"0.75rem",fontWeight:600,color:"var(--text-tertiary)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:"0.25rem"},children:"Bounds"}),r.jsx("dl",{className:"review-grid",children:Y.map(([Ne,$e])=>r.jsxs("span",{style:{display:"contents"},children:[r.jsx("dt",{children:Ne}),r.jsx("dd",{children:String($e)})]},Ne))})]}),(F==null?void 0:F.context)&&Object.keys(F.context).length>0&&r.jsxs(r.Fragment,{children:[r.jsx("div",{style:{fontSize:"0.75rem",fontWeight:600,color:"var(--text-tertiary)",textTransform:"uppercase",letterSpacing:"0.04em",marginTop:"1rem",marginBottom:"0.25rem"},children:"Scope"}),r.jsx("dl",{className:"review-grid",children:Object.entries(F.context).map(([Ne,$e])=>r.jsxs("span",{style:{display:"contents"},children:[r.jsx("dt",{children:Ne}),r.jsx("dd",{title:String($e),children:am(Ne,$e,F.contextLabels)})]},Ne))})]}),r.jsx("div",{style:{fontSize:"0.75rem",fontWeight:600,color:"var(--text-tertiary)",textTransform:"uppercase",letterSpacing:"0.04em",marginTop:"1rem",marginBottom:"0.25rem"},children:"Intent"}),u===t.authorization_id?r.jsx("p",{style:{fontSize:"0.8rem",color:"var(--text-tertiary)"},children:"Loading gate content..."}):F?r.jsx("div",{className:"gate-content-block",children:r.jsx("div",{className:"gate-content-item",children:r.jsx("div",{className:"gate-content-text",children:F.gateContent.intent})})}):r.jsx("p",{style:{fontSize:"0.8rem",color:"var(--text-tertiary)"},children:"Gate content not available."}),r.jsxs("div",{style:{fontSize:"0.75rem",color:"var(--text-tertiary)",marginTop:"1rem"},children:["Created: ",new Date(t.created_at).toLocaleString(),t.earliest_expiry&&` · Expires: ${new Date(t.earliest_expiry).toLocaleString()}`]}),r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",marginTop:"0.25rem"},children:[r.jsx("span",{style:{fontSize:"0.7rem",color:"var(--text-tertiary)",fontFamily:"'SF Mono', Monaco, monospace",wordBreak:"break-all"},children:t.authorization_id}),r.jsx("button",{className:"btn btn-ghost btn-sm",style:{fontSize:"0.7rem",padding:"0.125rem 0.375rem"},onClick:()=>b(t.authorization_id),children:f===t.authorization_id?"copied":"copy"})]}),r.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"0.5rem",marginTop:"0.75rem"},children:[!w&&r.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>S(t),disabled:p===t.authorization_id,title:"Start a new mandate pre-filled with these bounds, scope, and intent",children:p===t.authorization_id?"Copying…":"⧉ Copy"}),!w&&(G==="active"||G==="pending")&&r.jsx("button",{className:me?"btn btn-primary btn-sm":"btn btn-secondary btn-sm",onClick:()=>S(t,{asEdit:!0}),disabled:p===t.authorization_id,title:me?"The Authority Server no longer verifies this mandate's protocol version. Re-approving opens the ceremony pre-filled with the same bounds, scope, and intent; signing it revokes this one.":"Adjust intent, bounds, or scope: opens the ceremony pre-filled; signing the new mandate revokes this one",children:me?"⚠ Re-approve":"✎ Edit"}),!w&&re&&r.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>T(t),children:"↻ Extend"}),w&&j&&G!=="revoked"?r.jsx("button",{className:"btn btn-danger btn-sm",onClick:()=>k(t.authorization_id,w,ne),disabled:g===t.authorization_id,children:g===t.authorization_id?"Revoking…":"Revoke"}):!w&&(G==="active"||G==="pending")?r.jsx("button",{className:"btn btn-danger btn-sm",onClick:()=>k(t.authorization_id),disabled:g===t.authorization_id,children:g===t.authorization_id?"Revoking…":"Revoke"}):null]})]})]})]},t.authorization_id)}function Ew(){const[t,s]=h.useState([]),[a,o]=h.useState(!0),[c,u]=h.useState([]),[f,g]=h.useState(!1),[p,v]=h.useState(new Map),[y,w]=h.useState("mine"),[j,N]=h.useState("active"),[b,S]=h.useState(null),[k,T]=h.useState(null),[R,P]=uc(),[A,B]=h.useState(()=>R.get("new")==="1"),[H]=h.useState(()=>R.get("profile")),[G,me]=h.useState(()=>R.get("highlight")),[q,ce]=h.useState(null),[ee,F]=h.useState({}),[re,Y]=h.useState(null),[se,ye]=h.useState(null),[we,J]=h.useState(null),[V,W]=h.useState(new Set),[C,L]=h.useState(null),[fe,Q]=h.useState(new Set),[z,X]=h.useState(null),[ne,ie]=h.useState(null),[K,ke]=h.useState(new Set),Ne=mn(),{group:$e,groupId:pe,domain:Le,mode:Ge,activeTeam:He}=mt(),Oe=(He==null?void 0:He.isAdmin)===!0,[lt,he]=h.useState(()=>new Map),Re=h.useCallback(()=>{o(!0),O.getMyAttestations().then(s).catch(()=>{}).finally(()=>o(!1))},[]),Pe=h.useCallback(()=>{O.getArchivedMandates().then(le=>Q(new Set(le))).catch(()=>{})},[]);h.useEffect(()=>{Pe()},[Pe]);const ut=h.useCallback(()=>{O.getEnrichedAuthorizations().then(le=>ke(new Set(le.filter(Se=>Se.needsReapproval).map(Se=>Se.authorizationId)))).catch(()=>{})},[]);h.useEffect(()=>{ut()},[ut]);const Je=async(le,Se)=>{X(le);try{const ve=await O.setMandateArchived(le,Se);Q(new Set(ve)),window.dispatchEvent(new Event("suveren:archived-changed"))}catch(ve){alert(ve instanceof Error?ve.message:"Failed to update archive")}finally{X(null)}},ze=h.useCallback(()=>{pe&&(g(!0),O.listTeamAuthorizations(pe).then(u).catch(()=>{}).finally(()=>g(!1)))},[pe]);De("attestation-changed",()=>{Re(),Oe&&pe&&ze(),ut()}),h.useEffect(()=>{if(!G)return;R.get("highlight")&&(R.delete("highlight"),P(R,{replace:!0}));const le=window.setTimeout(()=>me(null),3e3);return()=>window.clearTimeout(le)},[]),Dt(Re,3e5),h.useEffect(()=>{y==="team"&&Oe&&pe&&c.length===0&&!f&&ze()},[y,Oe,pe,c.length,f,ze]),h.useEffect(()=>{let le=!1;return O.listProfiles().then(Se=>{if(le)return;const ve=Xe=>Xe.replace(/@.*$/,"").split("/").pop()??Xe,Be=Xe=>Xe.split("@")[1]??"",Fe=new Map;for(const Xe of Se){const Wt=ve(Xe.id),er=Fe.get(Wt);(!er||Be(Xe.id).localeCompare(Be(er.id),void 0,{numeric:!0})>0)&&Fe.set(Wt,Xe)}v(Fe)}).catch(()=>{}),()=>{le=!0}},[]);const _=h.useCallback(le=>{const Se=Wt=>Wt.replace(/@.*$/,"").split("/").pop()??Wt,ve=Wt=>Wt.split("@")[1]??"",Be=p.get(Se(le));if(!Be)return;const Fe=ve(le),Xe=ve(Be.id);if(!(!Fe||!Xe))return Xe.localeCompare(Fe,void 0,{numeric:!0})>0?Be:void 0},[p]);h.useEffect(()=>{if(Ge!=="team"||!pe)return;const le=y==="mine"?t:c;if(le.length===0)return;const Se=[...new Set(le.map(ve=>ve.profile_id))].filter(ve=>!lt.has(ve));if(Se.length!==0){he(ve=>{const Be=new Map(ve);for(const Fe of Se)Be.set(Fe,null);return Be});for(const ve of Se)O.getTeamProfileConfig(pe,ve).then(Be=>{he(Fe=>new Map(Fe).set(ve,Be))}).catch(()=>{})}},[t,c,y,pe,Ge,lt]);const oe=async le=>{if(q===le.authorization_id){ce(null);return}ce(le.authorization_id);const Se=le.authorization_id;if(!(Se in ee)){Y(le.authorization_id);try{const ve=await O.getGateContent(Se);F(Be=>({...Be,[Se]:ve}))}catch{F(ve=>({...ve,[Se]:null}))}finally{Y(null)}}},ge=le=>{navigator.clipboard.writeText(le).then(()=>{J(le),setTimeout(()=>J(null),2e3)})},Te=async(le,Se)=>{var ve;if(!pe){alert("No active group; cannot copy mandate.");return}ie(le.authorization_id);try{const Be=le.authorization_id;let Fe=ee[Be]??null;Be in ee||(Fe=await O.getGateContent(Be),F(bn=>({...bn,[Be]:Fe})));const Xe=Object.fromEntries(Object.entries(le.frame).filter(([bn])=>bn!=="profile"&&bn!=="path")),Wt=(Fe==null?void 0:Fe.context)??{},er=((ve=Fe==null?void 0:Fe.gateContent)==null?void 0:ve.intent)??"",as=le.deferred_commitment_domains.length>0?"review":"automatic",na=le.attested_domains[0]||Le||"owner",Sn=Date.parse(le.created_at),tr=le.earliest_expiry?Date.parse(le.earliest_expiry):NaN,nr=Number.isFinite(Sn)&&Number.isFinite(tr)&&tr>Sn?Math.round((tr-Sn)/1e3):void 0;let ra=le.profile_id,$n=Xe,rr=Wt,sr;const is=await O.listProfiles(),Cr=dm(le.profile_id,is);if(Cr&&Cr.id!==le.profile_id){const bn=await O.getProfile(Cr.id);ra=Cr.id,$n=hm(Xe,bn),rr=mm(Wt,bn),sr=le.profile_id}sessionStorage.setItem("agentAuth",JSON.stringify({profileId:ra,groupId:pe,groupName:($e==null?void 0:$e.name)??null,domain:na,isPersonal:!!($e!=null&&$e.isPersonal),upgradedFromProfileId:sr})),sessionStorage.setItem("agentGate",JSON.stringify({bounds:$n,context:rr,gateContent:{intent:er},templateMode:as,templateTtl:nr})),Se!=null&&Se.asEdit?sessionStorage.setItem("agentEditReplaces",le.authorization_id):sessionStorage.removeItem("agentEditReplaces"),Ne("/mandates/new/intent")}catch(Be){alert(Be instanceof Error?Be.message:"Failed to copy mandate")}finally{ie(null)}},de=async(le,Se,ve)=>{const Be=Se&&ve?`Revoke ${Se}'s ${ve} mandate? This cannot be undone.`:"Revoke this mandate? The agent will no longer be able to execute actions under it.";if(confirm(Be)){L(le);try{await O.revokeAttestation(le),W(Fe=>new Set(Fe).add(le)),O.resyncGates().catch(()=>{}),Se&&pe&&ze()}catch(Fe){alert(Fe instanceof Error?Fe.message:"Failed to revoke mandate")}finally{L(null)}}},Me=y==="mine"?t:c,Ye=y==="mine"?a:f,Qe=y==="mine"?{revokedSet:V,archivedSet:fe}:{revokedSet:V},pt=le=>Si(le,Qe),pn={active:0,pending:0,expired:0,revoked:0,archived:0};for(const le of Me)pn[pt(le)]+=1;const jn=y==="mine"?["active","pending","expired","revoked","archived"]:["active","pending","expired","revoked"],rt=(()=>{const le=new Map;for(const Se of Me){if(pt(Se)!==j)continue;const ve=le.get(Se.profile_id)??{count:0,review:!1};ve.count+=1,Se.deferred_commitment_domains.length>0&&(ve.review=!0),le.set(Se.profile_id,ve)}return Array.from(le.entries()).map(([Se,ve])=>({profileId:Se,...ve})).sort((Se,ve)=>ht(Se.profileId).localeCompare(ht(ve.profileId)))})(),kt=Nw(Me.filter(le=>{if(pt(le)!==j||b!==null&&le.profile_id!==b)return!1;if(k!==null){const Se=le.deferred_commitment_domains.length>0;if(k==="review"&&!Se||k==="auto"&&Se)return!1}return!0}),Qe,G),Et={revokedSet:V,expandedHash:q,gateCache:ee,gateLoading:re,copiedHash:we,revokingHash:C,copyingHash:ne,profileConfigCache:lt,mode:Ge,activeDomain:Le,group:$e,groupId:pe,onExpand:oe,onCopyHash:ge,onCopy:Te,onRevoke:de,onExtend:ye,highlightHash:G},wt={...Et,archivedSet:fe,archivingHash:z,onArchive:Je,needsReapprovalSet:K};return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"page-header",style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:"1rem",flexWrap:"wrap"},children:[r.jsxs("div",{children:[r.jsx("h1",{className:"page-title",children:"Mandates"}),r.jsx("p",{className:"page-subtitle",children:"Active, pending, expired, and archived agent mandates."})]}),r.jsx("button",{className:"btn btn-primary",onClick:()=>B(!0),children:"+ New mandate"})]}),A&&r.jsx("div",{className:"modal-backdrop",onClick:()=>{B(!1),(R.get("new")||R.get("profile"))&&(R.delete("new"),R.delete("profile"),P(R,{replace:!0}))},children:r.jsxs("div",{className:"modal",onClick:le=>le.stopPropagation(),style:{maxWidth:"960px",width:"90vw"},children:[r.jsxs("div",{className:"modal-header",children:[r.jsx("h2",{className:"modal-title",children:"New mandate"}),r.jsx("button",{className:"modal-close",onClick:()=>{B(!1),(R.get("new")||R.get("profile"))&&(R.delete("new"),R.delete("profile"),P(R,{replace:!0}))},children:"×"})]}),r.jsxs("div",{className:"modal-body",children:[r.jsx("p",{style:{color:"var(--text-tertiary)",fontSize:"0.9rem",marginTop:0,marginBottom:"1rem"},children:"What should your agent be able to do? Pick a profile, set limits, then authorize."}),r.jsx(mw,{onDismiss:()=>B(!1),preselectProfileId:H})]})]})}),Oe&&r.jsxs("div",{className:"nav-tabs",style:{marginBottom:"0.5rem"},children:[r.jsx("button",{className:`nav-tab${y==="mine"?" active":""}`,onClick:()=>{w("mine"),N("active"),S(null),T(null),ce(null)},children:"Mine"}),r.jsx("button",{className:`nav-tab${y==="team"?" active":""}`,onClick:()=>{w("team"),N("active"),S(null),T(null),ce(null)},children:"Team"})]}),r.jsx("div",{className:"nav-tabs",children:jn.map(le=>r.jsxs("button",{className:`nav-tab${j===le?" active":""}`,onClick:()=>{N(le),S(null),T(null)},children:[le.charAt(0).toUpperCase()+le.slice(1)," (",pn[le],")"]},le))}),rt.length>0&&r.jsxs("div",{style:{display:"flex",gap:"0.5rem",flexWrap:"wrap",alignItems:"center",marginTop:"-0.25rem",marginBottom:"1rem"},children:[rt.map(le=>{const Se=b===le.profileId;return r.jsx("button",{className:`btn btn-sm ${Se?"btn-primary":"btn-secondary"}`,onClick:()=>S(Se?null:le.profileId),children:ht(le.profileId)},le.profileId)}),r.jsx("span",{"aria-hidden":"true",style:{color:"var(--border)",fontSize:"1.1rem",padding:"0 0.25rem",userSelect:"none"},children:"|"}),["auto","review"].map(le=>{const Se=k===le;return r.jsx("button",{className:`btn btn-sm ${Se?"btn-primary":"btn-secondary"}`,onClick:()=>T(Se?null:le),children:le==="auto"?"Auto":"Review"},le)})]}),Ye&&Me.length===0?r.jsx("p",{style:{color:"var(--text-tertiary)"},children:"Loading..."}):kt.length===0?r.jsx(Zr,{icon:"☰",title:"No mandates",text:j==="archived"?"Nothing archived. Archive an expired or revoked mandate to move it here.":`No ${j} mandates found.`}):r.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem"},children:kt.map(le=>{const Se=y==="team"?le:null,ve=Se!=null&&Se.owner?Se.owner.name??Se.owner.email??Se.owner.userId:void 0;return r.jsx(Cw,{item:le,newerProfile:_(le.profile_id),ownerLabel:ve,isAdmin:Oe,...y==="mine"?wt:Et},le.authorization_id)})}),se&&r.jsx(bw,{item:se,onClose:()=>ye(null),onSuccess:()=>{ye(null),Re()}})]})}const Tw=new Set(["ticket_id","apiKey","api_key","accessToken","access_token","password","secret","signature","_imagePreview"]);function qt(t){const s=t.replace(/([a-z])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").trim().toLowerCase();return s.charAt(0).toUpperCase()+s.slice(1)}function Mi(t){const s=t.indexOf("__");return s<0?{integrationId:"",toolName:t}:{integrationId:t.slice(0,s),toolName:t.slice(s+2)}}function Rw(t){const{integrationId:s,toolName:a}=Mi(t);return s?`${s} · ${a}`:a}function Nc(t,s){const a=s==null?void 0:s.find(o=>o.id===t);return a!=null&&a.name?a.name:t?t.toUpperCase():"the system"}function Aw(t){return Array.isArray(t)?"list":t&&typeof t=="object"?"object":typeof t=="string"&&(t.includes(`
80
+ `)||t.length>120)?"markdown":"text"}function Iw(t,s){var f,g;const a=(s==null?void 0:s.approvalView)??{},o=((f=s==null?void 0:s.inputSchema)==null?void 0:f.properties)??{},c=[...new Set([...Object.keys(a),...Object.keys(o),...Object.keys(t)])],u=[];for(const p of c){if(!(p in t)||Tw.has(p))continue;const v=t[p],y=a[p]??{},w=y.kind??Aw(v),j={key:p,label:y.label??qt(p),kind:w,value:v,hint:(g=o[p])==null?void 0:g.description};w==="money"&&y.currencyArg&&typeof t[y.currencyArg]=="string"&&(j.currency=t[y.currencyArg]),w==="profile"&&typeof v=="string"&&(j.profileRef=v),(w==="profile-limits"||w==="profile-scope")&&y.profileArg&&typeof t[y.profileArg]=="string"&&(j.profileRef=t[y.profileArg]),u.push(j)}return u}function pm(t,s){var o,c;const a=(c=(o=s==null?void 0:s.scopeSchema)==null?void 0:o.fields)==null?void 0:c[t];return a?{label:a.displayName??t,hint:a.description}:{label:t}}function Pw(t,s,a){if(!t||typeof t!="object"||Array.isArray(t))return[];const o=a==="limits"?s==null?void 0:s.boundsSchema:s==null?void 0:s.scopeSchema,c=(o==null?void 0:o.fields)??{},u=[...new Set([...(o==null?void 0:o.keyOrder)??[],...Object.keys(t)])],f=[];for(const g of u){if(g==="profile"||!(g in t))continue;const p=t[g],v=c[g],y=Fi(v==null?void 0:v.unit),w=Array.isArray(p)?p.join(", "):String(p);f.push({key:g,label:(v==null?void 0:v.displayName)??qt(g),value:y?`${w} ${y}`:w,hint:v==null?void 0:v.description,unknown:s?!v:void 0})}return f}function _w(t){const s=t.indexOf("__");return s<0?{integrationId:"",toolName:t}:{integrationId:t.slice(0,s),toolName:t.slice(s+2)}}function $w(t,s){var p,v,y;const{integrationId:a,toolName:o}=_w(t.action),c=s.find(w=>w.id===a),u=(v=(p=c==null?void 0:c.toolGating)==null?void 0:p.overrides)==null?void 0:v[o];if(u!=null&&u.actionLabel)return u.actionLabel;const f=ht(t.profileId),g=(y=t.executionContext)==null?void 0:y.action_type;return typeof g=="string"&&g?`${f} · ${g}`:`${f} · ${o}`}function Lw(t,s){var c;const a=(c=s==null?void 0:s.scopeSchema)==null?void 0:c.fields;if(!a)return"";const o=[];for(const[u,f]of Object.entries(t.executionContext??{})){if(!(u in a))continue;const g=String(f??"").trim();g&&o.push(g.split(",").map(p=>p.trim()).filter(Boolean).join(", "))}return o.join(" · ")}function zw(t,s){var c,u;if(!t)return"";const a=((c=s==null?void 0:s.scopeSchema)==null?void 0:c.fields)??{},o=[];for(const[f,g]of Object.entries(t)){if(f==="action_type")continue;const p=String(g??"").trim();if(!p)continue;const v=((u=a[f])==null?void 0:u.displayName)??f;o.push(`${v} ${p.split(",").map(y=>y.trim()).filter(Boolean).join(", ")}`)}return o.join(" · ")}function Vf(t){return t.appliesTo}function Fw(t,s,a){var g,p,v,y;const o=[{window:"daily",label:"today"},{window:"monthly",label:"this month"}],c=t.actionType??(typeof((g=t.executionContext)==null?void 0:g.action_type)=="string"?t.executionContext.action_type:void 0),u=(p=a==null?void 0:a.boundsSchema)==null?void 0:p.fields,f=[];for(const{window:w,label:j}of o){const N=(v=t.cumulativeState)==null?void 0:v[w];if(!N)continue;let b;if(u&&s){const T=Object.entries(u).filter(([A,B])=>{if(!(A in s))return!1;const H=B.boundType;if(!H||H.kind!=="cumulative_sum"&&H.kind!=="cumulative_count"||H.window!==w)return!1;const G=Vf(B);return!G||!c||G.includes(c)}),P=(c?T.find(([,A])=>{var B;return(B=Vf(A))==null?void 0:B.includes(c)}):void 0)??(T.length===1?T[0]:void 0);P&&(b={key:P[0],isAmount:((y=P[1].boundType)==null?void 0:y.kind)==="cumulative_sum"})}const S=b?b.isAmount?N.amount:N.count:void 0,k=b?Number(s==null?void 0:s[b.key]):NaN;b&&Number.isFinite(k)?f.push(`${S} of ${k} ${j}`):f.push(`${N.count} ${N.count===1?"call":"calls"} ${j}`)}return f.join(" · ")}function Ow(t,s,a){var u;const o=(u=a==null?void 0:a.boundsSchema)==null?void 0:u.fields;if(!t||!s||!o)return[];const c=[];for(const[f,g]of Object.entries(o)){const p=g.boundType;if(!p||p.kind!=="per_transaction")continue;const v=p.of;if(!(v in t)||!(f in s))continue;const y=Number(t[v]),w=Number(s[f]);if(!Number.isFinite(y)||!Number.isFinite(w))continue;const j=Fi(g.unit),N=g.displayName??qt(v),b=S=>j?`${S.toLocaleString()} ${j}`:S.toLocaleString();c.push({key:f,label:N,ok:y<=w,valueText:b(y),limitText:b(w)})}return c}function Mw(t){return typeof t.proposalId=="string"&&t.proposalId.length>0}function Bw(t){const s=ht(t),a=t.split("@")[1];return a?`${s}@${a}`:s}const Gf=new Map;function Dw(t){let s=Gf.get(t);return s||(s=(async()=>{try{let a=t;if(!t.includes("@")){const o=await O.listProfiles(),c=f=>f.replace(/@.*$/,"").split("/").pop(),u=o.filter(f=>c(f.id)===t).sort((f,g)=>(g.id.split("@")[1]??"").localeCompare(f.id.split("@")[1]??"",void 0,{numeric:!0}));if(!u[0])return null;a=u[0].id}return await O.getProfile(a)}catch{return null}})(),Gf.set(t,s)),s}function ss(t){const[s,a]=h.useState(null);return h.useEffect(()=>{let o=!0;return t&&Dw(t).then(c=>{o&&a(c)}),()=>{o=!1}},[t]),s}async function Kf(t){const s=new TextEncoder().encode(t),a=await crypto.subtle.digest("SHA-256",s);return Array.from(new Uint8Array(a)).map(o=>o.toString(16).padStart(2,"0")).join("")}function Uw(t){return t.normalize("NFC").replace(/\r\n?/g,`
81
+ `).split(`
82
+ `).map(c=>c.replace(/[ \t]+$/,"")).join(`
83
+ `).replace(/\n+$/,"")}function ql(t){if(t===void 0)throw new Error("canonicalize: undefined is not serializable");if(typeof t=="number"&&!Number.isFinite(t))throw new Error(`canonicalize: ${t} is not a valid JSON number`);if(t===null||typeof t!="object")return JSON.stringify(t);if(Array.isArray(t))return"["+t.map(c=>c===void 0?"null":ql(c)).join(",")+"]";const s=t,a=[];for(const o of Object.keys(s).sort()){const c=s[o];c!==void 0&&a.push(JSON.stringify(o)+":"+ql(c))}return"{"+a.join(",")+"}"}async function gm(t,s){if(t==="jcs"){if(typeof s=="string")throw new Error('content_binding kind="jcs" expects a record payload (object), got a string');return`sha256:${await Kf(ql(s))}`}if(typeof s!="string")throw new Error('content_binding kind="text" expects a string, got an object');return`sha256:${await Kf(Uw(s))}`}function nn(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function $t(t,s=!1){return t==null?"—":typeof t=="string"?t:typeof t=="boolean"?String(t):typeof t=="number"?s||Number.isInteger(t)?String(t):String(Math.round(t*100)/100):"—"}function Ww(t){return t==null?!1:typeof t=="string"||Array.isArray(t)?t.length>0:!0}function Sr(t,s,a){const o=s?Object.keys(s).filter(c=>c in t):Object.keys(t);return o.length===0?"—":o.map(c=>{var p,v;const u=t[c],f=((p=s==null?void 0:s[c])==null?void 0:p.title)??qt(c),g=nn(u)?Sr(u,(v=s==null?void 0:s[c])==null?void 0:v.properties,a):$t(u,a);return`${f}: ${g}`}).join(" · ")}function Hw(t,s){const a=s?Object.keys(s).filter(u=>t.some(f=>u in f)):[...new Set(t.flatMap(u=>Object.keys(u)))],o=a.map(u=>{var f;return{key:u,label:((f=s==null?void 0:s[u])==null?void 0:f.title)??qt(u)}}),c=t.map(u=>({cells:a.map(f=>{var y,w;const g=u[f],p=nn(g)?Sr(g,(y=s==null?void 0:s[f])==null?void 0:y.properties,!1):$t(g),v=nn(g)?Sr(g,(w=s==null?void 0:s[f])==null?void 0:w.properties,!0):$t(g,!0);return v===p?{value:p,sealed:!1}:{value:p,valueTitle:v,sealed:!1}})}));return{columns:o,rows:c}}function Vw(t){return t.split(`
84
+ `).map(s=>s.startsWith("+")&&!s.startsWith("+++")?{text:s,kind:"add"}:s.startsWith("-")&&!s.startsWith("---")?{text:s,kind:"remove"}:{text:s,kind:"context"})}function Gw(t,s){var c;if(Array.isArray(t)){if(t.length===0)return{value:"—"};if(t.every(y=>!nn(y)&&!Array.isArray(y))){if(t.every(j=>typeof j=="string"))return{lines:t};const y=t.map(j=>$t(j)).join(", "),w=t.map(j=>$t(j,!0)).join(", ");return w===y?{value:y}:{value:y,valueTitle:w}}const u=(c=s==null?void 0:s.items)==null?void 0:c.properties,f=t.map(y=>nn(y)?Sr(y,u,!1):$t(y)),g=t.map(y=>nn(y)?Sr(y,u,!0):$t(y,!0)),p=f.map((y,w)=>y===g[w]?void 0:g[w]),v=t.every(nn)?Hw(t,u):void 0;return{lines:f,...p.some(y=>y!==void 0)?{lineTitles:p}:{},...v?{table:v}:{}}}if(nn(t)){const u=s==null?void 0:s.properties,f=u?Object.keys(u).filter(v=>v in t):Object.keys(t);if(f.length>0&&f.every(v=>!nn(t[v])&&!Array.isArray(t[v])))return{sublist:f.map(y=>{var S;const w=t[y],j=((S=u==null?void 0:u[y])==null?void 0:S.title)??qt(y),N=$t(w),b=$t(w,!0);return b===N?{key:y,label:j,value:N}:{key:y,label:j,value:N,valueTitle:b}})};const g=Sr(t,u,!1),p=Sr(t,u,!0);return p===g?{value:g}:{value:g,valueTitle:p}}if(typeof t=="string"&&(s==null?void 0:s.contentMediaType)==="text/x-diff")return{diffLines:Vw(t)};const a=$t(t),o=$t(t,!0);return o===a?{value:a}:{value:a,valueTitle:o}}function Kw(t){let s;try{s=JSON.parse(t)}catch{return null}return nn(s)?s:null}function kr(t){const s=t!=null&&t.structured&&Object.keys(t.structured).length>0?t.structured:void 0;if(s)return{obj:s,schema:t==null?void 0:t.outputSchema};const a=t!=null&&t.text?Kw(t.text):null;return a?{obj:a}:null}function Ei(t){const s=kr(t);if(!s)return[];const{obj:a,schema:o}=s,c=(o==null?void 0:o.properties)??{},u=[...new Set([...Object.keys(c),...Object.keys(a)])],f=[];for(const g of u){if(!(g in a))continue;const p=c[g],v=(p==null?void 0:p.title)??qt(g),y={key:g,label:v,...Gw(a[g],p)};p!=null&&p.description&&(y.description=p.description),f.push(y)}return f}function Ti(t,s){const a=kr(t);if(a){const c=Ei(t),u=s==null?void 0:s.fields;let f;if(u&&u.length>0){const v=new Map(c.map(y=>[y.key,y]));f=u.map(y=>v.get(y)).filter(y=>y!==void 0)}else f=c.filter(v=>Ww(a.obj[v.key]));const g=new Set(f.map(v=>v.key)),p=c.filter(v=>!g.has(v.key));return{kind:"structured",fields:f,moreFields:p,totalFields:c.length}}const o=t==null?void 0:t.text;return o&&o.trim().length>0?{kind:"text",fields:[],moreFields:[],totalFields:0,text:o}:{kind:"empty",fields:[],moreFields:[],totalFields:0}}function qf(t){return t?t.lines?`lines:${JSON.stringify(t.lines)}`:t.sublist?`sublist:${JSON.stringify(t.sublist.map(s=>[s.key,s.value]))}`:t.diffLines?`diffLines:${JSON.stringify(t.diffLines)}`:`value:${t.value??""}`:""}function pi(t){return{kind:t.length>0?"structured":"empty",fields:t,moreFields:[],totalFields:t.length}}function qw(t,s,a){const o=kr(t),c=kr(s);if(!o&&!c){const j=(t==null?void 0:t.text)??"",N=(s==null?void 0:s.text)??"";return j===N?{approved:pi([]),current:pi([]),unchanged:!0}:{approved:{kind:"text",fields:[],moreFields:[],totalFields:0,text:j},current:{kind:"text",fields:[],moreFields:[],totalFields:0,text:N},unchanged:!1}}const u=new Map(Ei(t).map(j=>[j.key,j])),f=new Map(Ei(s).map(j=>[j.key,j])),p=[...new Set([...u.keys(),...f.keys()])].filter(j=>j===(a==null?void 0:a.excludeKey)?!1:qf(u.get(j))!==qf(f.get(j))),v=a!=null&&a.fields&&a.fields.length>0?[...a.fields.filter(j=>p.includes(j)),...p.filter(j=>!a.fields.includes(j))]:p,y=v.map(j=>u.get(j)).filter(j=>j!==void 0),w=v.map(j=>f.get(j)).filter(j=>j!==void 0);return{approved:pi(y),current:pi(w),unchanged:p.length===0}}function Yw(t){const s=t==null?void 0:t.structured;if(Array.isArray(s)&&s.every(nn))return s;if(t!=null&&t.text){let a;try{a=JSON.parse(t.text)}catch{return null}if(Array.isArray(a)&&a.every(nn))return a}return null}function Bi(t){const s=$t(t),a=$t(t,!0);return a===s?{value:s}:{value:s,valueTitle:a}}function ym(t){return!t||t.status!=="ok"?[]:Ei(t.body)}function vm(t){if(!t)return"Not read.";switch(t.status){case"not_found":return"Not found in the system.";case"none":return"Nothing to read.";default:return"Not available right now."}}function xm(t,s,a){var p;const o=ym(t);if(o.length===0)return{rawId:$t(s),context:[],unresolved:vm(t)};const c=t&&t.status==="ok"?(p=kr(t.body))==null?void 0:p.obj:void 0,u=o.find(v=>["name","title","label"].includes(v.key))??o.find(v=>typeof(c==null?void 0:c[v.key])=="string"&&!v.lines&&!v.sublist&&!v.diffLines),f=a==null?void 0:a.pathPrefix,g=o.filter(v=>v.key!==(u==null?void 0:u.key)&&v.key!=="id").map(v=>{var b,S;if(!f)return v;const y=`${f}.${v.key}`,w=Ys(a==null?void 0:a.displayHints,y,v.label);if(!Zs((b=a==null?void 0:a.displayHints)==null?void 0:b.money,y)&&!Zs((S=a==null?void 0:a.displayHints)==null?void 0:S.percent,y))return w===v.label?v:{...v,label:w};const{value:j,valueTitle:N}=Ri(c==null?void 0:c[v.key],a==null?void 0:a.displayHints,y,a==null?void 0:a.currency);return{...v,label:w,value:j,valueTitle:N}});return{name:u==null?void 0:u.value,rawId:$t(s),context:g}}const Jw=new Set(["id","name","title","label"]);function Zs(t,s){return!!(t!=null&&t.includes(s))}function Ys(t,s,a){var o;return((o=t==null?void 0:t.labels)==null?void 0:o[s])??a}function Qw(t,s){const a=typeof t=="number"?t:Number(t);return Number.isFinite(a)?{value:`${a.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}${s?` ${s}`:""}`}:Bi(t)}function Xw(t){return typeof t!="number"&&typeof t!="string"?Bi(t):{value:`${t} %`}}function Ri(t,s,a,o){return Zs(s==null?void 0:s.money,a)?Qw(t,o):Zs(s==null?void 0:s.percent,a)?Xw(t):Bi(t)}function wm(t,s){return Zs(t==null?void 0:t.hidden,s)}function Zw(t,s,a){var f;const o=t==null?void 0:t.currencyField;if(!o)return;const c=o.indexOf(".");if(c<0){const g=s[o];return typeof g=="string"?g:void 0}const u=(f=a(o.slice(0,c)))==null?void 0:f[o.slice(c+1)];return typeof u=="string"?u:void 0}function ej(t,s,a,o){const c=t.forEach??"",u=t.attach,f=t.elements??[],g=Math.min(s.length,f.length),p=s.slice(0,g),v=f.slice(0,g),y=[...new Set(p.flatMap(S=>Object.keys(S)))].filter(S=>S!==t.sourceArg).filter(S=>!wm(a,`${c}[].${S}`)),w=new Map;if(u)for(const S of v)for(const k of ym(S))w.has(k.key)||w.set(k.key,k.label);const j=u?[...w.keys()].filter(S=>!Jw.has(S)):[],N=[];u&&N.push({key:`__attach:${u}`,label:Ys(a,`${c}[].${u}`,qt(t.sourceArg??u))});for(const S of y)N.push({key:`bound:${S}`,label:Ys(a,`${c}[].${S}`,qt(S))});for(const S of j)N.push({key:`attached:${S}`,label:Ys(a,`${c}[].${u}.${S}`,w.get(S)??qt(S))});const b=p.map((S,k)=>{var A;const T=v[k],R=[];if(u){const B=xm(T,t.sourceArg?S[t.sourceArg]:void 0),H=B.name?`${B.name} (${B.rawId})`:B.unresolved?`${B.rawId} — ${B.unresolved}`:B.rawId;R.push({value:H,sealed:!1})}for(const B of y){const{value:H,valueTitle:G}=Ri(S[B],a,`${c}[].${B}`,o);R.push({value:H,valueTitle:G,sealed:!0})}const P=T&&T.status==="ok"?(A=kr(T.body))==null?void 0:A.obj:void 0;for(const B of j){const H=P==null?void 0:P[B],{value:G,valueTitle:me}=H!==void 0?Ri(H,a,`${c}[].${u}.${B}`,o):{value:"—",valueTitle:void 0};R.push({value:G,valueTitle:me,sealed:!1})}return{cells:R}});return{columns:N,rows:b,...t.overflow?{overflowNote:`${t.overflow.total-t.overflow.shown} more not shown`}:{}}}function tj(t){return`${qt(t)} — from the system`}function nj(t){const s=tj(t.tool),a=t.result;if(!a||a.status!=="ok")return{heading:s,note:vm(a)};const o=Yw(a.body);if(o){if(o.length===0)return{heading:s,note:"Nothing found."};const c=[...new Set(o.flatMap(g=>Object.keys(g)))],u=c.map(g=>({key:g,label:qt(g)})),f=o.map(g=>({cells:c.map(p=>({...Bi(g[p]),sealed:!1}))}));return{heading:s,table:{columns:u,rows:f}}}return{heading:s,body:Ti(a.body,{fields:t.fields})}}function rj(t,s,a){const o=new Map(s.filter(w=>w.attach&&!w.forEach).map(w=>[w.attach,w])),c=new Map(s.filter(w=>w.forEach).map(w=>[w.forEach,w])),u=s.filter(w=>!w.attach&&!w.forEach),g=Zw(a,t,w=>{var N,b;const j=(N=o.get(w))==null?void 0:N.result;return j&&j.status==="ok"?(b=kr(j.body))==null?void 0:b.obj:void 0}),p=(a==null?void 0:a.order)??[],v=[...new Set([...p,...Object.keys(t)])],y=[];for(const w of v){if(!(w in t)||wm(a,w))continue;const j=Ys(a,w,qt(w)),N=c.get(w);if(N){const T=Array.isArray(t[w])?t[w]:[];y.push({kind:"table",key:w,label:j,table:ej(N,T,a,g)});continue}const b=o.get(w);if(b){const T=xm(b.result,t[w],{pathPrefix:w,displayHints:a,currency:g});y.push({kind:"identity",key:w,label:j,identity:T});continue}const{value:S,valueTitle:k}=Ri(t[w],a,w,g);y.push({kind:"scalar",key:w,label:j,value:S,valueTitle:k})}return{rows:y,sections:u.map(nj)}}function sj(t){return t.offDevice?"off-device":t.boundContent===void 0?"none":t.hasHashToCheck?t.hashVerified===!0?"verified":"mismatch":"unchecked"}function aj(t,s){return t===void 0?{kind:"empty",fields:[],moreFields:[],totalFields:0}:typeof t=="string"?Ti({text:t}):Ti({structured:t},{fields:s})}function ij(t,s){return t?Object.entries(t).filter(([,a])=>a!=null&&a!=="").map(([a,o])=>({key:a,label:pm(a,s).label,value:String(o)})):[]}function Ai({table:t}){return t.columns.length===0?r.jsx("p",{className:"preview-note",children:"Nothing to show."}):r.jsxs(r.Fragment,{children:[r.jsxs("table",{className:"preview-table",children:[r.jsx("thead",{children:r.jsx("tr",{children:t.columns.map(s=>r.jsx("th",{children:s.label},s.key))})}),r.jsx("tbody",{children:t.rows.map((s,a)=>r.jsx("tr",{children:s.cells.map((o,c)=>r.jsx("td",{className:o.sealed?"src-tag-value src-tag-sealed-cell":"src-tag-value src-tag-system-cell",title:o.valueTitle,children:o.value},c))},a))})]}),t.overflowNote&&r.jsx("p",{className:"preview-note",children:t.overflowNote})]})}function Yf({row:t}){return r.jsxs("dt",{style:{color:"var(--text-tertiary)",whiteSpace:"nowrap",alignSelf:"start"},children:[t.label,t.description&&r.jsx("div",{style:{color:"var(--text-tertiary)",fontSize:"0.72rem",fontWeight:400,whiteSpace:"normal",marginTop:"0.1rem"},children:t.description})]})}function oj({row:t}){return t.sublist?r.jsx("dl",{style:{display:"grid",gridTemplateColumns:"max-content 1fr",gap:"0.15rem 0.6rem",margin:0},children:t.sublist.map(s=>r.jsxs(h.Fragment,{children:[r.jsx("dt",{style:{color:"var(--text-tertiary)",whiteSpace:"nowrap"},children:s.label}),r.jsx("dd",{style:{margin:0,wordBreak:"break-word"},title:s.valueTitle,children:s.value})]},s.key))}):t.diffLines?r.jsx("div",{style:{fontFamily:"ui-monospace, Menlo, monospace",fontSize:"0.8rem"},children:t.diffLines.map((s,a)=>r.jsx("div",{style:s.kind==="remove"?{color:"var(--danger)",textDecoration:"line-through"}:s.kind==="add"?{color:"var(--success)"}:void 0,children:s.text||" "},a))}):t.table?r.jsx(Ai,{table:t.table}):t.lines?r.jsx("div",{children:t.lines.map((s,a)=>{var o;return r.jsx("div",{title:(o=t.lineTitles)==null?void 0:o[a],children:s},a)})}):r.jsx("span",{title:t.valueTitle,children:t.value})}function Yl({rows:t}){return r.jsx("dl",{style:{display:"grid",gridTemplateColumns:"max-content 1fr",gap:"0.3rem 0.75rem",fontSize:"0.85rem",margin:"0.4rem 0"},children:t.map(s=>s.table?r.jsxs("div",{style:{gridColumn:"1 / -1"},children:[r.jsx(Yf,{row:s}),r.jsx(Ai,{table:s.table})]},s.key):r.jsxs(h.Fragment,{children:[r.jsx(Yf,{row:s}),r.jsx("dd",{style:{margin:0,wordBreak:"break-word"},children:r.jsx(oj,{row:s})})]},s.key))})}function wi({rendered:t}){return t.kind==="empty"?r.jsx("p",{style:{color:"var(--text-tertiary)",fontSize:"0.85rem",margin:"0.4rem 0"},children:"No fields returned."}):t.kind==="text"?r.jsx("div",{style:{whiteSpace:"pre-wrap",fontSize:"0.85rem",margin:"0.4rem 0"},children:t.text}):r.jsxs(r.Fragment,{children:[r.jsx(Yl,{rows:t.fields}),t.moreFields.length>0&&r.jsxs("details",{style:{fontSize:"0.8rem"},children:[r.jsxs("summary",{style:{cursor:"pointer",color:"var(--text-tertiary)"},children:["All fields (",t.totalFields,")"]}),r.jsx(Yl,{rows:t.moreFields})]})]})}function jm({receipt:t,profile:s}){var j;const[a,o]=h.useState(void 0),[c,u]=h.useState(null),f=!!(t.contentHash&&t.contentBinding);if(h.useEffect(()=>{let N=!0;return o(void 0),u(null),(async()=>{let b;try{b=await O.getArchivedReceipt(t.id)}catch{N&&o(null);return}let S=null;const k=b==null?void 0:b.entry.boundContent;if(k!==void 0&&f)try{S=await gm(t.contentBinding.kind,k)===t.contentHash}catch{S=!1}N&&(u(S),o(b))})(),()=>{N=!1}},[t.id,t.contentHash,t.contentBinding,f]),a===void 0)return r.jsx("div",{className:"ticket-done-box ticket-done-loading","data-testid":"ticket-what-was-done","data-bound":"loading","aria-busy":"true",children:"Loading…"});const g=a===null,p=a==null?void 0:a.entry.boundContent,v=sj({offDevice:g,boundContent:p,hasHashToCheck:f,hashVerified:c});if(v==="off-device")return r.jsx("div",{className:"ticket-done-box ticket-done-off-device","data-testid":"ticket-what-was-done","data-bound":"off-device",children:r.jsx("p",{className:"ticket-done-note",children:"Content not on this device — only the signed values are shown."})});if(v==="none"){const N=ij(t.executionContext,s);return r.jsxs("div",{className:"ticket-done-box","data-testid":"ticket-what-was-done","data-bound":"none",children:[r.jsx("h4",{children:"What was done"}),N.length>0?r.jsx("dl",{className:"ticket-done-fields",children:N.map(b=>r.jsxs("div",{className:"ticket-done-field-row",children:[r.jsx("dt",{children:b.label}),r.jsx("dd",{children:b.value})]},b.key))}):r.jsx("p",{className:"ticket-done-note",children:"No checked values recorded for this action."})]})}const y=aj(p,(j=t.contentBinding)==null?void 0:j.fields),w=v==="verified"?"ticket-done-verified":v==="mismatch"?"ticket-done-mismatch":"ticket-done-unchecked";return r.jsxs("div",{className:`ticket-done-box ${w}`,"data-testid":"ticket-what-was-done","data-bound":v,children:[r.jsxs("h4",{children:["What was done",v!=="unchecked"&&r.jsxs(r.Fragment,{children:[" ",r.jsx("span",{className:"src-tag src-tag-sealed",children:"sealed"})]})]}),r.jsx(wi,{rendered:y}),v==="verified"&&r.jsx("p",{className:"ticket-done-note ticket-done-note-ok",children:"✓ This exact content is bound by hash — any change after the fact would break the ticket."}),v==="mismatch"&&r.jsx("p",{className:"ticket-done-note ticket-done-note-bad",children:"⚠ This content does NOT match the ticket's signed hash — it may have been altered since archiving."}),v==="unchecked"&&r.jsx("p",{className:"ticket-done-note ticket-done-note-neutral",children:"This content is kept on this device, but the ticket carries no content hash — it cannot be checked against the ticket."})]})}const Jf=500;function Jl(t){return t.length>Jf?`${t.slice(0,Jf)}…`:t}function Qf(t){return t.length?t[0].toUpperCase()+t.slice(1):t}function lj(t){return new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function Sm(t,s,a){switch(t.status){case"none":return t.reason==="no_target"?{heading:"Nothing to read beforehand",note:`This action does not refer to an existing record — nothing to read beforehand. Showing exactly what will be sent to ${s}.`}:{heading:"No preview declared",note:`No preview declared for this tool — showing exactly what will be sent to ${s}.`};case"unavailable":return t.reason==="no_connector"?{heading:"Preview not available",note:"Preview not available on this gateway."}:{heading:"Preview not available",note:t.message?`Preview not available — ${Jl(t.message)}`:"Preview not available."};case"not_found":return{heading:"Not found in your system",note:t.message?`Not found in your system — ${Jl(t.message)}`:"Not found in your system."};case"ok":{if("reads"in t)return{heading:`What will be created in ${s}`,note:`Read by the gateway, not by the AI — read at ${lj(t.readAt)}.`,creation:rj(a??{},t.reads,t.display)};const o=Ti(t.body,{fields:t.fields}),c={heading:`From ${s}, before it runs`,note:`Read by the gateway with ${t.tool} when you opened this card — the AI is not involved.`,rendered:o},u=t.version;if(u&&(c.versionNote=`You approve ${u.field} ${u.approved}; if it changes, ${s} refuses it.`,u.stale)){const f=qw(t.body,u.currentBody,{fields:t.fields,excludeKey:u.field});c.stale={heading:`A newer ${u.field} exists (${u.current})`,approvedLabel:`${Qf(u.field)} ${u.approved}`,currentLabel:`${Qf(u.field)} ${u.current}`,...f.unchanged?{unchangedNote:"No visible change in the fields."}:{approvedRendered:f.approved,currentRendered:f.current}}}return c}}}function cj(t,s){if(t.state!=="failed")return null;const a=t.detail?Jl(t.detail):void 0;return t.outcome==="changed"?{heading:"Changed since your approval",note:`The record changed in ${s} since you approved it — nothing was done. Ask the AI to request it again.`}:{heading:`Refused by ${s}`,note:`${s} refused it${a?`: ${a}`:""} — nothing was done. Ask the AI to request it again.`}}function uj(t){return t!==null&&t!=="loading"&&t!=="ok"&&t!=="stale"}function dj({identity:t}){return t.unresolved?r.jsxs("span",{children:[r.jsx("span",{className:"id-raw",children:t.rawId})," ",r.jsxs("span",{style:{color:"var(--text-tertiary)"},children:["— ",t.unresolved]})]}):r.jsxs("span",{children:[t.name&&r.jsx("span",{className:"src-tag-value src-tag-system-cell",children:t.name})," ",r.jsx("span",{className:"id-raw",children:t.rawId}),t.context.length>0&&r.jsx("span",{className:"creation-context",children:t.context.map(s=>r.jsxs("span",{children:[" · ",s.label," ",s.value]},s.key))})]})}function fj({view:t}){return r.jsxs(r.Fragment,{children:[r.jsx("dl",{style:{display:"grid",gridTemplateColumns:"max-content 1fr",gap:"0.3rem 0.75rem",fontSize:"0.85rem",margin:"0.4rem 0"},children:t.rows.map(s=>s.kind==="table"?null:r.jsxs(h.Fragment,{children:[r.jsx("dt",{style:{color:"var(--text-tertiary)",whiteSpace:"nowrap",alignSelf:"start"},children:s.label}),r.jsx("dd",{style:{margin:0,wordBreak:"break-word"},children:s.kind==="identity"?r.jsx(dj,{identity:s.identity}):r.jsx("span",{className:"src-tag-value src-tag-sealed-cell",title:s.valueTitle,children:s.value})})]},s.key))}),t.rows.filter(s=>s.kind==="table").map(s=>r.jsxs("div",{style:{margin:"0.5rem 0"},children:[r.jsx("div",{style:{color:"var(--text-tertiary)",fontSize:"0.78rem",marginBottom:"0.2rem"},children:s.label}),r.jsx(Ai,{table:s.table})]},s.key)),t.sections.map((s,a)=>r.jsxs("div",{className:"creation-own-section",children:[r.jsxs("h5",{children:[s.heading," ",r.jsx("span",{className:"src-tag src-tag-system",children:"from the system"})]}),s.table&&r.jsx(Ai,{table:s.table}),s.body&&r.jsx(Yl,{rows:s.body.fields}),s.note&&r.jsx("p",{className:"preview-note",children:s.note})]},a))]})}function bm({resp:t,systemName:s,toolArgs:a,sealed:o}){const c=Sm(t,s,a??void 0),u=t.status==="ok"?c.stale?"stale":"ok":t.status;return u==="none"?r.jsx("p",{className:"preview-note","data-testid":"approval-preview","data-preview-status":"none",children:c.note}):r.jsxs("div",{className:`preview-box preview-box-${u}`,"data-testid":"approval-preview","data-preview-status":u,children:[r.jsxs("h4",{children:[c.heading,c.creation&&(o?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"src-tag src-tag-sealed",children:"sealed"})," ",r.jsx("span",{className:"lock-tag",children:"end-to-end encrypted"})]}):r.jsx("span",{className:"src-tag src-tag-sealed",children:"sealed"}))]}),c.creation&&r.jsx(fj,{view:c.creation}),c.rendered&&r.jsx(wi,{rendered:c.rendered}),r.jsx("p",{className:"preview-note",children:c.note}),c.versionNote&&!c.stale&&r.jsx("p",{className:"preview-note",children:c.versionNote}),c.stale&&r.jsxs("div",{className:"preview-stale",children:[r.jsx("h5",{children:c.stale.heading}),c.stale.unchangedNote?r.jsx("p",{className:"preview-note",children:c.stale.unchangedNote}):r.jsxs("dl",{style:{display:"grid",gridTemplateColumns:"max-content 1fr",gap:"0.3rem 0.75rem",fontSize:"0.85rem",margin:"0.5rem 0 0"},children:[r.jsx("dt",{children:c.stale.approvedLabel}),r.jsx("dd",{children:r.jsx(wi,{rendered:c.stale.approvedRendered})}),r.jsx("dt",{children:c.stale.currentLabel}),r.jsx("dd",{children:r.jsx(wi,{rendered:c.stale.currentRendered})})]})]})]})}function hj({proposalId:t,systemName:s,toolArgs:a,sealed:o,onTone:c,onData:u}){const[f,g]=h.useState(null),[p,v]=h.useState(!1);return h.useEffect(()=>{let y=!0;return g(null),v(!1),O.getProposalPreview(t).then(w=>{y&&g(w)}).catch(()=>{y&&v(!0)}),()=>{y=!1}},[t]),h.useEffect(()=>{if(p){c==null||c("unavailable"),u==null||u({status:"unavailable",reason:"connector_error"});return}if(!f){u==null||u(null);return}const y=Sm(f,s,a??void 0);c==null||c(f.status==="ok"?y.stale?"stale":"ok":f.status),u==null||u(f)},[f,p,s,c,u]),p?r.jsxs("div",{className:"preview-box preview-box-unavailable","data-testid":"approval-preview","data-preview-status":"unavailable",children:[r.jsx("h4",{children:"Preview not available"}),r.jsx("p",{className:"preview-note",children:"Preview not available on this gateway."})]}):f?r.jsx(bm,{resp:f,systemName:s,toolArgs:a,sealed:o}):r.jsxs("div",{className:"preview-box preview-box-loading","data-testid":"approval-preview","data-preview-status":"loading","aria-busy":"true",children:["Reading from ",s,"…"]})}const Ll=6;function Ii(t){if(!t)return;const s=Date.parse(t);return Number.isNaN(s)?t:new Date(s).toLocaleString([],{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function mj(t){if(!t)return{first:""};const s=t.split(`
85
+ `);return s.length<=Ll?{first:t}:{first:s.slice(0,Ll).join(`
86
+ `),more:s.slice(Ll).join(`
87
+ `)}}const pj="Linked by the AI",gj="linked automatically — this action already carried a reference to it";function yj(t){if(t.status==="none")return{state:"none",note:"No request linked.",chain:[]};if(t.status==="unreadable")return{state:"unreadable",note:`Request: link not readable (${t.reason}).`,chain:[]};if(t.status==="not_found")return{state:"not_found",note:"Request: this message no longer exists.",chain:[]};const{first:s,more:a}=mj(t.body),o=[t.connector,t.kind,t.author?`from ${t.author}`:void 0,Ii(t.at)].filter(c=>!!c);return{state:"ok",implicit:t.implicit,tag:pj,...t.implicit?{implicitNote:gj}:{},metaLine:o.join(" · "),title:t.title,bodyFirst:s,bodyMore:a,attribution:t.author?`— from ${t.author}, not checked`:void 0,chain:t.chain.map(c=>({...c,at:Ii(c.at)}))}}const Ws="Read by the gateway — same customer, not matched to this request";function vj(t){const s=t.matchedKeyType==="email_domain"?"matched by email domain":"matched by email";return`Latest entries for ${t.matchedKeyValue} (${s})`}function xj(t){var c;const s=!!t.aiWritten,a=s?"Activity":t.type??t.kind??"Entry";let o;if(s){const u=((c=t.aiWritten)==null?void 0:c.at)!==void 0?Ii(new Date(t.aiWritten.at).toISOString()):void 0;o=u?`— Written by the AI via Suveren, ${u} — not checked`:"— Written by the AI via Suveren — not checked"}else o=t.author?`— from ${t.author}, not checked`:"— not checked";return{headLabel:a,at:Ii(t.at),title:t.title,body:t.body,attribution:o,aiWritten:s}}function wj(t){if(t.status==="no_customer_link")return{state:"no_customer_link",label:Ws,note:"No customer link — nothing to match history against.",matchNotes:[],items:[]};if(t.status==="no_match")return{state:"no_match",label:Ws,note:"No match — no connector here matches on this customer's available identity key.",matchNotes:[],items:[]};if(t.status==="unreachable")return{state:"unreachable",label:Ws,note:`${t.connectorIds.join(", ")} not reachable — history could not be read.`,matchNotes:[],items:[]};const s=t.matches.flatMap(c=>c.items.map(u=>({it:u,m:c}))).sort((c,u)=>(Date.parse(u.it.at??"")||0)-(Date.parse(c.it.at??"")||0)).map(({it:c})=>xj(c)),a=t.matches.map(vj),o=t.unreachableConnectorIds.length>0?`${t.unreachableConnectorIds.join(", ")} not reachable — showing what could be read.`:void 0;return s.length===0?{state:"empty",label:Ws,note:"Nothing in the last few days.",matchNotes:a,items:[],unreachableNote:o}:{state:"ok",label:Ws,note:"",matchNotes:a,items:s,unreachableNote:o}}function km({resp:t}){const s=yj(t.request),a=wj(t.history);return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"preview-box preview-box-ai","data-testid":"au10-request","data-request-status":s.state,children:[r.jsxs("h4",{children:["Request",s.tag&&r.jsx("span",{className:"src-tag src-tag-ai",children:s.tag})]}),s.state!=="ok"?r.jsx("p",{className:"au10-req-state",children:s.note}):r.jsxs(r.Fragment,{children:[s.implicitNote&&r.jsx("p",{className:"au10-req-meta",style:{marginTop:"-0.1rem"},children:s.implicitNote}),s.metaLine&&r.jsx("p",{className:"au10-req-meta",children:s.metaLine}),s.title&&r.jsx("p",{className:"au10-req-meta",children:r.jsx("b",{children:s.title})}),s.bodyFirst&&r.jsx("p",{className:"au10-req-quote",children:s.bodyFirst}),s.bodyMore&&r.jsxs("details",{children:[r.jsx("summary",{children:"Show more"}),r.jsx("p",{className:"au10-req-quote",children:s.bodyMore})]}),s.attribution&&r.jsx("p",{className:"au10-req-attrib",children:s.attribution}),s.chain.length>0&&r.jsxs("details",{className:"au10-chain",children:[r.jsxs("summary",{children:["Earlier in this thread (",s.chain.length,")"]}),s.chain.map((o,c)=>r.jsxs("div",{className:"au10-chain-item",children:[(o.author||o.at)&&r.jsxs("p",{className:"au10-req-meta",children:[o.author?r.jsxs(r.Fragment,{children:["from ",r.jsx("b",{children:o.author})]}):null,o.author&&o.at?" · ":"",o.at]}),o.title&&r.jsx("p",{className:"au10-req-meta",children:r.jsx("b",{children:o.title})}),o.body&&r.jsx("p",{className:"au10-req-quote",children:o.body}),o.author&&r.jsxs("p",{className:"au10-req-attrib",children:["— from ",o.author,", not checked"]})]},c))]})]})]}),r.jsxs("div",{className:`preview-box ${a.state==="unreachable"?"preview-box-unreachable":"preview-box-sys"}`,"data-testid":"au10-history","data-history-status":a.state,children:[r.jsxs("h4",{children:["History",r.jsx("span",{className:"src-tag src-tag-system",children:a.label})]}),a.state!=="ok"?r.jsx("p",{className:"au10-hist-state",children:a.note}):r.jsxs(r.Fragment,{children:[a.matchNotes.map((o,c)=>r.jsx("p",{className:"preview-note",style:{marginTop:0},children:o},c)),r.jsx("ul",{className:"au10-hist-list",children:a.items.map((o,c)=>r.jsxs("li",{className:"au10-hist-item",children:[r.jsxs("div",{className:"au10-hist-head",children:[r.jsxs("span",{children:[o.aiWritten&&r.jsx("span",{className:"au10-dot au10-dot-ai"}),o.headLabel]}),r.jsx("span",{children:o.at})]}),o.title&&r.jsx("div",{className:"au10-hist-title",children:o.title}),o.body&&r.jsx("div",{className:"au10-hist-body",children:o.body}),r.jsx("p",{className:"au10-hist-attrib",children:o.attribution})]},c))}),a.unreachableNote&&r.jsx("p",{className:"preview-note",children:a.unreachableNote})]})]})]})}function jj({proposalId:t,onData:s}){const[a,o]=h.useState(null),[c,u]=h.useState(!1);return h.useEffect(()=>{let f=!0;return o(null),u(!1),O.getProposalRequestContext(t).then(g=>{f&&o(g)}).catch(()=>{f&&u(!0)}),()=>{f=!1}},[t]),h.useEffect(()=>{s==null||s(c?null:a)},[a,c,s]),c||!a?null:r.jsx(km,{resp:a})}function Sj(t,s,a){const o=Object.entries(t??{});if(o.length===0)return{entry:void 0,otherCount:0};const u=o.find(([,g])=>g.by===s)??(a?o.find(([g])=>g===`domain:${a}`):void 0),f=u?o.length-1:o.length;return{entry:u==null?void 0:u[1],otherCount:f}}function bj(t){return t.offDevice?"off-device":t.recordedHash?t.localHash===t.recordedHash?"verified":"mismatch":"unchecked"}function kj(t){if(!(t<=0))return`${t} other approver${t===1?"":"s"} recorded their own.`}function Nj(t){return new Date(t).toLocaleString([],{hour:"2-digit",minute:"2-digit"})}function Nm({proposalId:t,tool:s,manifests:a}){const{user:o,domain:c}=mt(),[u,f]=h.useState(null),[g,p]=h.useState(null),[v,y]=h.useState(!1);if(h.useEffect(()=>{let P=!0;return f(null),p(null),y(!1),Promise.all([O.getShownSnapshot(t),O.getProposal(t)]).then(([A,B])=>{P&&(f(A),p(B))}).catch(()=>{P&&y(!0)}),()=>{P=!1}},[t]),v||!u||!g)return null;const w=u.status==="off_device",{entry:j,otherCount:N}=Sj(g.shownHashes,(o==null?void 0:o.id)??"",c),b=bj({offDevice:w,recordedHash:j==null?void 0:j.hash,localHash:u.status==="ok"?u.shownHash:void 0}),S=kj(N);if(w)return r.jsxs("div",{className:"ticket-box ticket-shown-off-device","data-testid":"au10-shown","data-shown-status":"off-device",children:[r.jsx("h4",{children:"What you saw"}),r.jsx("p",{className:"ticket-done-note",children:"Only on the approving gateway — this device has no local copy."})]});const{snapshot:k}=u,{integrationId:T}=Mi(s),R=Nc(T,a);return r.jsxs("div",{className:`ticket-box ticket-shown-${b}`,"data-testid":"au10-shown","data-shown-status":b,children:[r.jsxs("h4",{children:["What you saw (read ",Nj(k.readAt),")",b==="verified"&&r.jsx("span",{className:"src-tag src-tag-sealed",children:"verified"}),b==="mismatch"&&r.jsx("span",{className:"src-tag src-tag-danger",children:"does not match what was approved"})]}),r.jsx(bm,{resp:k.preview,systemName:R,toolArgs:k.toolArgs,sealed:k.sealed}),r.jsx(km,{resp:k.requestContext}),b==="verified"&&r.jsx("p",{className:"ticket-done-note ticket-done-note-ok",children:"✓ Matches the fingerprint recorded with your approval."}),b==="mismatch"&&r.jsx("p",{className:"ticket-done-note ticket-done-note-bad",children:"⚠ This copy differs from the fingerprint recorded with your approval."}),b==="unchecked"&&r.jsx("p",{className:"ticket-done-note ticket-done-note-neutral",children:"This device's copy of what was shown, kept locally — the Authority Server does not record a fingerprint for you to check it against."}),S&&r.jsx("p",{className:"ticket-done-note ticket-done-note-neutral","data-testid":"au10-shown-others",children:S})]})}function Hs({label:t,children:s}){return r.jsxs(r.Fragment,{children:[r.jsx("dt",{className:"receipt-row-label",children:t}),r.jsx("dd",{className:"receipt-row-value",children:s})]})}function Cj({receipt:t,manifests:s,localAuth:a,localUnavailable:o,signature:c,grantTitle:u,ownerLabel:f,spUrl:g,formatDate:p,onOpenComplete:v}){var R;const y=ss(t.profileId),w=Lw(t,y),j=zw(a==null?void 0:a.context,y),N=Fw(t,(a==null?void 0:a.bounds)??t.limits,y),b=a==null?void 0:a.intent,S=Nr(t.profileId).testSetup||Oi(t.action),[k,T]=h.useState(!1);return r.jsxs("div",{className:"card id-card",style:{marginBottom:0},children:[r.jsx(rs,{profileId:t.profileId}),r.jsxs("div",{className:"id-body",children:[r.jsxs("div",{className:"receipt-head",children:[r.jsx("span",{className:"receipt-what",children:$w(t,s)}),r.jsx("span",{className:"receipt-tag",children:Mw(t)?"review":"automatic"}),t.contentHash&&r.jsx("span",{className:"receipt-tag receipt-tag-bound",title:(R=t.contentBinding)!=null&&R.fields?`The ticket binds: ${t.contentBinding.fields.join(", ")}`:"This exact content was authorized",children:"content bound"}),S&&r.jsx("span",{className:"sim-mark",children:"Test setup"}),r.jsx("span",{className:"auth-card-time",children:p(t.timestamp)})]}),w&&r.jsx("div",{className:"receipt-scope",children:w}),r.jsx(jm,{receipt:t,profile:y}),t.proposalId&&r.jsx(Nm,{proposalId:t.proposalId,tool:t.action,manifests:s}),r.jsxs("dl",{className:"receipt-rows",children:[r.jsxs(Hs,{label:"mandate",children:[r.jsx("strong",{children:u||Bw(t.profileId)})," ",r.jsx("span",{className:"src-tag src-tag-local",children:"local"})]}),f&&r.jsx(Hs,{label:"owner",children:f}),j&&r.jsxs(Hs,{label:"allowed",children:[j," ",r.jsx("span",{className:"src-tag src-tag-local",children:"local"})]}),N&&r.jsxs(Hs,{label:"used",children:[r.jsx("span",{className:"receipt-num",children:N})," ",r.jsx("span",{className:"src-tag src-tag-sealed",children:"sealed"})]}),r.jsx(Hs,{label:"intent",children:b?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:`intent-text${k?"":" intent-clamped"}`,children:b}),r.jsx("button",{type:"button",className:"btn btn-ghost btn-sm intent-toggle",onClick:()=>T(!k),children:k?"Show less":"Show full intent"})," ",r.jsx("span",{className:"src-tag src-tag-local",children:"local"})]}):r.jsx("span",{className:"receipt-absent",children:o?"local store unreachable — sign in to the gateway to read it":"not on this device — the Authority Server stores only its hash"})})]}),r.jsxs("div",{className:"receipt-foot",children:[c==="valid"&&r.jsx("span",{className:"receipt-verified",title:"Ed25519 signature checked on this device against the issuer key archived when the ticket was issued — no Authority Server involved.",children:"✓ Verified on this device"}),c==="valid-legacy"&&r.jsx("span",{className:"receipt-verified",title:"Ed25519 signature checked on this device against the issuer key archived when the ticket was issued. This ticket was issued before protocol 0.7 and is checked with that version's format.",children:"✓ Verified on this device · issued before protocol 0.7"}),c==="invalid"&&r.jsx("span",{className:"receipt-tamper",title:"The stored ticket does not match what was signed.",children:"⚠ Signature check FAILED"}),r.jsx("button",{type:"button",className:"receipt-evidence-link",onClick:v,children:"Complete ticket"}),g&&r.jsxs("span",{className:"receipt-public",children:["redacted, shareable:"," ",r.jsx("a",{className:"receipt-link",href:`${g}/r/${t.id}`,target:"_blank",rel:"noreferrer",children:"public link ↗"})]})]}),r.jsxs("details",{className:"receipt-more",children:[r.jsx("summary",{children:"Raw"}),r.jsxs("div",{className:"receipt-kv",children:[r.jsxs("div",{children:["ticket · ",t.id]}),r.jsxs("div",{children:["action · ",t.action]}),r.jsxs("div",{children:["profile · ",t.profileId]}),t.authorizationId&&r.jsxs("div",{children:["mandate · ",t.authorizationId]}),Object.keys(t.executionContext??{}).length>0&&r.jsxs("div",{children:["scope ·"," ",Object.entries(t.executionContext).map(([P,A])=>`${P}=${A}`).join(" · ")]}),(a==null?void 0:a.boundsHash)&&r.jsxs("div",{children:["bounds hash · ",a.boundsHash]}),(a==null?void 0:a.contextHash)&&r.jsxs("div",{children:["scope hash · ",a.contextHash]}),t.contentHash&&r.jsxs("div",{children:["content · ",t.contentHash]}),t.proposalId&&r.jsxs("div",{children:["proposal · ",t.proposalId]}),r.jsxs("div",{children:["signature · ",t.signature]})]})]})]})]})}function Ej({receipt:t,onClose:s}){const[a,o]=h.useState(null),[c,u]=h.useState(null),[f,g]=h.useState(null),[p,v]=h.useState(!0),[y,w]=h.useState(!1);h.useEffect(()=>{let k=!1;return v(!0),O.getArchivedReceipt(t.id).then(T=>{k||(o(T),u(T?"local":"authority-server"),g((T==null?void 0:T.signature)??null))}).catch(()=>{k||u("authority-server")}).finally(()=>{k||v(!1)}),()=>{k=!0}},[t.id]);const j=a?a.entry:{receipt:t},N=JSON.stringify(j,null,2);function b(){const k=URL.createObjectURL(new Blob([N],{type:"application/json"})),T=document.createElement("a");T.href=k,T.download=`suveren-ticket-${t.id.slice(0,8)}.json`,T.click(),URL.revokeObjectURL(k)}async function S(){try{await navigator.clipboard.writeText(N),w(!0),setTimeout(()=>w(!1),2e3)}catch{w(!1)}}return r.jsx("div",{className:"modal-backdrop",onClick:k=>k.target===k.currentTarget&&s(),children:r.jsxs("div",{className:"modal",style:{maxWidth:"44rem"},children:[r.jsxs("div",{className:"modal-header",children:[r.jsx("h3",{className:"modal-title",children:"Complete ticket"}),r.jsx("button",{className:"modal-close",onClick:s,"aria-label":"Close",children:"×"})]}),r.jsxs("div",{className:"modal-body",children:[f==="valid"&&r.jsx("p",{className:"receipt-verified",style:{margin:"0 0 0.5rem",fontSize:"0.8rem"},children:"✓ Ed25519 signature verified on this device, against the issuer key archived when this ticket was issued."}),f==="valid-legacy"&&r.jsx("p",{className:"receipt-verified",style:{margin:"0 0 0.5rem",fontSize:"0.8rem"},children:"✓ Ed25519 signature verified on this device, against the issuer key archived when this ticket was issued. Issued before protocol 0.7 — checked with that version's format."}),f==="invalid"&&r.jsx("p",{className:"receipt-tamper",style:{margin:"0 0 0.5rem",fontSize:"0.8rem"},children:"⚠ Signature check FAILED — the stored ticket does not match what was signed."}),r.jsx("p",{style:{fontSize:"0.8rem",color:"var(--text-muted)",margin:"0 0 0.75rem"},children:p?"Loading…":c==="local"?"Held on this device — the signed ticket, the mandate it ran under, and the issuer key. Anyone with this file and that key can verify it offline, without Suveren.":"No local copy of this ticket (it predates local archiving, or ran on another device). Shown from the Authority Server — complete and signed, but it needs the server to retrieve."}),r.jsx("pre",{style:{fontFamily:"'SF Mono', Monaco, monospace",fontSize:"0.68rem",lineHeight:1.65,margin:0,background:"var(--accent-subtle)",border:"1px solid var(--border)",borderRadius:"6px",padding:"0.75rem 0.85rem",overflowX:"auto",maxHeight:"22rem",overflowY:"auto"},children:N})]}),r.jsxs("div",{className:"modal-footer",children:[r.jsx("button",{className:"btn btn-primary btn-sm",onClick:b,children:"Download"}),r.jsx("button",{className:"btn btn-secondary btn-sm",onClick:S,children:y?"Copied":"Copy"})]})]})})}function Tj(t){return new Date(t*1e3).toLocaleString()}function Rj(t,s){if(s==="all")return!0;const a=s==="1d"?1:s==="7d"?7:30,o=Math.floor(Date.now()/1e3)-a*86400;return t.timestamp>=o}function Aj(t,s){if(!s)return!0;const a=s.toLowerCase();return t.profileId.toLowerCase().includes(a)||ht(t.profileId).toLowerCase().includes(a)||t.path.toLowerCase().includes(a)||t.action.toLowerCase().includes(a)||t.attestationHash.toLowerCase().includes(a)||t.id.toLowerCase().includes(a)||JSON.stringify(t.executionContext).toLowerCase().includes(a)}function Xf(t,s){const a=new Map(t.map(o=>[o.id,o]));for(const o of s)a.set(o.id,o);return[...a.values()].sort((o,c)=>c.timestamp-o.timestamp)}function Ij(){const{activeTeam:t,groupId:s}=mt(),a=(t==null?void 0:t.isAdmin)===!0,[o,c]=h.useState("mine"),[u,f]=h.useState([]),[g,p]=h.useState([]),[v,y]=h.useState(""),[w,j]=h.useState(!0),[N,b]=h.useState({}),[S,k]=h.useState(new Set),[T,R]=h.useState(""),[P,A]=h.useState(new Set),[B,H]=h.useState(new Set),[G,me]=h.useState("all"),[q,ce]=h.useState(!1),[ee,F]=h.useState(!1),[re,Y]=h.useState(null),[se,ye]=h.useState({}),[we,J]=h.useState(!1),[V,W]=h.useState({}),[C,L]=h.useState({}),[fe,Q]=h.useState(null),[z,X]=h.useState(null),[ne,ie]=h.useState(!1),[K,ke]=h.useState(!1),Ne=h.useRef(""),$e=h.useCallback(_=>o==="team"&&a&&s?O.listTeamReceiptsPage(s,{before:_,limit:200}):O.getMyReceiptsPage({before:_,limit:200}),[o,a,s]),pe=h.useCallback(()=>{const _=o==="team"?`team:${s}`:"mine",oe=Ne.current!==_;Ne.current=_,j(!0),ke(!1),$e().then(ge=>{f(Te=>oe?ge.receipts:Xf(Te,ge.receipts)),X(Te=>oe?ge.nextBefore:Te??ge.nextBefore)}).catch(()=>{oe&&f([]),ke(!0)}).finally(()=>j(!1))},[$e,o,s]),Le=h.useCallback(()=>{!z||ne||(ie(!0),ke(!1),$e(z).then(_=>{f(oe=>Xf(oe,_.receipts)),X(_.nextBefore)}).catch(()=>ke(!0)).finally(()=>ie(!1)))},[z,ne,$e]);Dt(pe,12e4),h.useEffect(()=>{O.getIntegrationManifests().then(({manifests:_})=>p(_)).catch(()=>{}),fetch("/health").then(_=>_.json()).then(_=>{typeof _.spUrl=="string"&&y(_.spUrl.replace(/\/$/,""))}).catch(()=>{})},[]),h.useEffect(()=>{O.getLocalAuthorizations().then(({authorizations:_,signatures:oe})=>{ye(_),W(oe),J(!1)}).catch(()=>{ye({}),W({}),J(!0)}),O.getMyAttestations().then(_=>{const oe={};for(const ge of _)ge.authorization_id&&ge.title&&(oe[ge.authorization_id]=ge.title);L(oe)}).catch(()=>{})},[]),h.useEffect(()=>{o!=="team"||Object.keys(N).length>0||O.listUsers().then(_=>{const oe={};for(const ge of _)oe[ge.id]={name:ge.name,email:ge.email};b(oe)}).catch(()=>{})},[o,N]);const Ge=h.useMemo(()=>{const _=new Set;for(const oe of u)_.add(ht(oe.profileId));return[..._].sort()},[u]),He=h.useMemo(()=>{const _=new Set;for(const oe of u)_.add(oe.action);return[..._].sort()},[u]),Oe=h.useMemo(()=>{if(o!=="team")return[];const _=new Set;for(const oe of u)oe.userId&&_.add(oe.userId);return[..._].map(oe=>{var ge;return{id:oe,label:(ge=N[oe])!=null&&ge.name?`${N[oe].name} (${N[oe].email})`:oe}}).sort((oe,ge)=>oe.label.localeCompare(ge.label))},[o,u,N]),lt=h.useMemo(()=>u.filter(_=>!(!Aj(_,T)||P.size>0&&!P.has(ht(_.profileId))||B.size>0&&!B.has(_.action)||S.size>0&&_.userId&&!S.has(_.userId)||!Rj(_,G))),[u,T,P,B,S,G]),he=P.size>0||B.size>0||S.size>0||G!=="all";function Re(_){A(oe=>{const ge=new Set(oe);return ge.has(_)?ge.delete(_):ge.add(_),ge})}function Pe(_){H(oe=>{const ge=new Set(oe);return ge.has(_)?ge.delete(_):ge.add(_),ge})}function ut(_){k(oe=>{const ge=new Set(oe);return ge.has(_)?ge.delete(_):ge.add(_),ge})}function Je(){A(new Set),H(new Set),k(new Set),me("all"),R("")}async function ze(){F(!0),Y(null);try{const{bundle:_,filename:oe}=await O.fetchEvidenceBundle(),ge=URL.createObjectURL(new Blob([JSON.stringify(_,null,2)],{type:"application/json"})),Te=document.createElement("a");Te.href=ge,Te.download=oe,Te.click(),URL.revokeObjectURL(ge);const de=_.sources??{};de.authorityServer?de.local||Y(`Downloaded Authority Server history only — ${de.localError??"local archive unavailable."}`):Y(`Downloaded local evidence only — ${de.asError??"Authority Server export unavailable."}`)}catch(_){Y(`Export failed: ${_ instanceof Error?_.message:String(_)}`)}finally{F(!1)}}return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"page-header",style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:"1rem",flexWrap:"wrap"},children:[r.jsxs("div",{children:[r.jsx("h1",{className:"page-title",children:"Tickets"}),r.jsx("p",{className:"page-subtitle",children:"Execution history for agent actions."})]}),r.jsx("button",{className:"btn btn-secondary",onClick:ze,disabled:ee,children:ee?"Preparing…":"Download evidence"})]}),re&&r.jsx("div",{style:{marginBottom:"1rem",color:"var(--text-tertiary)",fontSize:"0.875rem"},children:re}),a&&r.jsx("div",{style:{display:"flex",gap:"0.5rem",marginBottom:"1rem",borderBottom:"1px solid var(--border)"},children:["mine","team"].map(_=>r.jsx("button",{onClick:()=>c(_),className:"btn btn-ghost",style:{borderRadius:0,padding:"0.5rem 0.875rem",borderBottom:o===_?"2px solid var(--accent)":"2px solid transparent",color:o===_?"var(--text-primary)":"var(--text-tertiary)",fontWeight:o===_?600:500},children:_==="mine"?"Mine":"Team"},_))}),r.jsxs("div",{className:"search-filter-bar",children:[r.jsxs("div",{className:"search-input-wrap",children:[r.jsx("span",{className:"search-icon",children:"⌕"}),r.jsx("input",{type:"text",className:"form-input search-input",placeholder:"Search by profile, action, path, or hash\\u2026",value:T,onChange:_=>R(_.target.value)}),T&&r.jsx("button",{className:"search-clear",onClick:()=>R(""),children:"×"})]}),r.jsxs("button",{className:`btn btn-sm btn-secondary${q?" active":""}`,onClick:()=>ce(!q),children:["Filters",he?` (${P.size+B.size+(G!=="all"?1:0)})`:""]})]}),q&&r.jsxs("div",{className:"filter-panel",children:[Ge.length>1&&r.jsxs("div",{className:"filter-section",children:[r.jsx("div",{className:"filter-label",children:"Profile"}),r.jsx("div",{className:"filter-chips",children:Ge.map(_=>r.jsx("button",{className:`filter-chip${P.has(_)?" selected":""}`,onClick:()=>Re(_),children:_},_))})]}),He.length>1&&r.jsxs("div",{className:"filter-section",children:[r.jsx("div",{className:"filter-label",children:"Action"}),r.jsx("div",{className:"filter-chips",children:He.map(_=>r.jsx("button",{className:`filter-chip${B.has(_)?" selected":""}`,onClick:()=>Pe(_),children:_},_))})]}),o==="team"&&Oe.length>1&&r.jsxs("div",{className:"filter-section",children:[r.jsx("div",{className:"filter-label",children:"Owner"}),r.jsx("div",{className:"filter-chips",children:Oe.map(_=>r.jsx("button",{className:`filter-chip${S.has(_.id)?" selected":""}`,onClick:()=>ut(_.id),children:_.label},_.id))})]}),r.jsxs("div",{className:"filter-section",children:[r.jsx("div",{className:"filter-label",children:"Time range"}),r.jsx("div",{className:"filter-chips",children:[["1d","Today"],["7d","7 days"],["30d","30 days"],["all","All time"]].map(([_,oe])=>r.jsx("button",{className:`filter-chip${G===_?" selected":""}`,onClick:()=>me(_),children:oe},_))})]})]}),he&&r.jsxs("div",{className:"active-filters",children:[[...P].map(_=>r.jsxs("span",{className:"active-chip",onClick:()=>Re(_),children:[_," ",r.jsx("span",{className:"chip-remove",children:"×"})]},_)),[...B].map(_=>r.jsxs("span",{className:"active-chip",onClick:()=>Pe(_),children:[_," ",r.jsx("span",{className:"chip-remove",children:"×"})]},_)),[...S].map(_=>{const oe=N[_],ge=oe?oe.name:_;return r.jsxs("span",{className:"active-chip",onClick:()=>ut(_),children:[ge," ",r.jsx("span",{className:"chip-remove",children:"×"})]},_)}),G!=="all"&&r.jsxs("span",{className:"active-chip",onClick:()=>me("all"),children:[G==="1d"?"Today":G==="7d"?"7 days":"30 days"," ",r.jsx("span",{className:"chip-remove",children:"×"})]}),r.jsx("button",{className:"clear-filters",onClick:Je,children:"Clear all"})]}),K&&r.jsx("div",{className:"card",style:{borderColor:"var(--danger, #c0392b)",marginBottom:"0.75rem"},children:r.jsx("span",{style:{color:"var(--danger, #c0392b)",fontSize:"0.85rem"},children:"Couldn’t load tickets — your session may have expired. Try signing out and back in."})}),w&&u.length===0?r.jsx("p",{style:{color:"var(--text-tertiary)"},children:"Loading..."}):lt.length===0?r.jsx(Zr,{icon:"⌕",title:u.length===0?"No tickets in the last 30 days":"No matching tickets",text:u.length===0?"Tickets appear here after an agent uses an authorized tool. Older tickets can be loaded below.":"Try adjusting your search or filters."}):r.jsxs(r.Fragment,{children:[r.jsx("div",{style:{fontSize:"0.8rem",color:"var(--text-tertiary)",marginBottom:"0.75rem"},children:lt.length===u.length?`${u.length} ticket${u.length!==1?"s":""}`:`${lt.length} of ${u.length} tickets`}),r.jsx("div",{className:"timeline",children:lt.map(_=>{const oe=_.userId?N[_.userId]:void 0;return r.jsx("div",{className:"timeline-event",children:r.jsx(Cj,{receipt:_,manifests:g,localAuth:_.authorizationId?se[_.authorizationId]:void 0,localUnavailable:we,signature:V[_.id],grantTitle:_.authorizationId?C[_.authorizationId]:null,ownerLabel:o==="team"&&_.userId?oe?`${oe.name} (${oe.email})`:_.userId:null,spUrl:v,formatDate:Tj,onOpenComplete:()=>Q(_)})},_.id)})})]}),fe&&r.jsx(Ej,{receipt:fe,onClose:()=>Q(null)}),z&&r.jsx("div",{style:{textAlign:"center",marginTop:"1rem"},children:r.jsx("button",{className:"btn btn-secondary btn-sm",onClick:Le,disabled:ne,children:ne?"Loading…":"Load older"})})]})}function Pj(){const[t,s]=h.useState(null),[a,o]=h.useState({}),[c,u]=h.useState(!1),[f,g]=h.useState({}),p=h.useCallback(()=>{O.getMyAttestations().then(S=>{const k={};for(const T of S)T.title&&(k[T.authorization_id]=T.title);g(k)}).catch(()=>{})},[]);h.useEffect(()=>{p()},[p]),Dt(p,3e5);const[v,y]=h.useState(null),w=h.useRef(!1),j=h.useCallback(()=>{O.getDenials({limit:200}).then(({records:S})=>{s(S),u(!1)}).catch(()=>u(!0))},[]);h.useEffect(()=>{j()},[j]),Dt(j,6e4),h.useEffect(()=>{if(!t)return;const S=[...new Set(t.map(k=>k.profile).filter(k=>!!k))].filter(k=>!(k in a));S.length!==0&&Promise.all(S.map(k=>O.getProfile(k).catch(()=>null))).then(k=>{o(T=>{const R={...T};return S.forEach((P,A)=>{k[A]&&(R[P]=k[A])}),R})})},[t,a]),h.useEffect(()=>{!t||w.current||(w.current=!0,O.getLastSeenBlockedAt().then(S=>(y(S),O.markBlockedSeen(Date.now()))).then(()=>{window.dispatchEvent(new Event("suveren:blocked-seen-changed"))}).catch(()=>{}))},[t]);const N=h.useCallback(()=>{j(),p(),v!==null&&(typeof document<"u"&&document.visibilityState!=="visible"||O.markBlockedSeen(Date.now()).then(()=>{window.dispatchEvent(new Event("suveren:blocked-seen-changed"))}).catch(()=>{}))},[j,p,v]);if(De("denial-recorded",N),c)return r.jsx(Zr,{icon:"⛔",title:"Could not load blocked actions",text:"Try again shortly."});if(t===null)return null;const b=lx(t,Date.now());return r.jsxs("div",{className:"blocked-page",children:[r.jsxs("div",{className:"page-header blocked-header",children:[r.jsx("h1",{className:"page-title",children:"Blocked actions"}),r.jsxs("span",{className:"blocked-today",children:[b," today · nothing ran"]})]}),t.length===0?r.jsx(Zr,{icon:"✓",title:"Nothing blocked",text:"Every call your agent made stayed within its mandate."}):r.jsx("div",{className:"blocked-list",children:t.map((S,k)=>{const T=ox(S,S.profile?a[S.profile]:void 0,f),R=v!==null&&S.ts>v;return r.jsxs("div",{className:"card id-card blocked-item","data-seen":R?"false":"true",children:[r.jsx(rs,{profileId:S.profile??S.integrationId}),r.jsxs("div",{className:"id-body",children:[r.jsxs("div",{className:"blocked-row-head",children:[r.jsx("span",{className:`blocked-dot blocked-dot-${zi(S)}`,"aria-hidden":"true"}),r.jsx("span",{className:"blocked-title",children:T.title}),R&&r.jsx("span",{className:"new-pill",children:"New"}),r.jsx("span",{className:"blocked-when",children:dx(S.ts,Date.now())})]}),r.jsx("div",{className:"blocked-sentence",children:T.sentence}),r.jsx("div",{className:"blocked-source",children:T.sourceLine.map((P,A)=>P.dim?r.jsx("span",{className:"mandate-id",children:P.text},A):r.jsx("span",{children:P.text},A))}),r.jsxs("details",{children:[r.jsx("summary",{children:"What you can do"}),r.jsx("div",{className:"blocked-advice",children:T.whatYouCanDo})]})]})]},`${S.ts}-${k}`)})})]})}const _j={darwin:"a macOS login item",win32:"a Windows scheduled task",linux:"a systemd user service"};function $j(){const[t,s]=h.useState(null),[a,o]=h.useState(!1),[c,u]=h.useState(null),f=h.useCallback(async()=>{try{s(await O.getAutostart())}catch(v){u(v instanceof Error?v.message:"Could not read autostart state")}},[]);h.useEffect(()=>{f()},[f]);const g=h.useCallback(async()=>{if(!(!(t!=null&&t.supported)||a)){o(!0),u(null);try{await O.setAutostart(!t.installed)}catch(v){u(v instanceof Error?v.message:"Failed")}finally{try{s(await O.getAutostart()),u(null)}catch(v){u(v instanceof Error?v.message:"Could not re-read state")}o(!1)}}},[t,a,f]);if(!t)return r.jsxs("div",{className:"card",style:{padding:"1.5rem",marginTop:"2rem"},children:[r.jsx("h2",{style:{fontSize:"1rem",fontWeight:700,margin:0},children:"Keep Suveren running"}),r.jsx("p",{role:c?"alert":void 0,style:{margin:"0.5rem 0 0",fontSize:"0.9rem",color:"var(--text-secondary)"},children:c?`Could not read autostart state: ${c}`:"Checking…"})]});const p=_j[t.platform]??"a login service";return r.jsxs("div",{className:"card",style:{padding:"1.5rem",marginTop:"2rem"},children:[r.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:"1rem"},children:[r.jsxs("div",{children:[r.jsx("h2",{style:{fontSize:"1rem",fontWeight:700,margin:0},children:"Keep Suveren running"}),r.jsx("p",{style:{color:"var(--text-secondary)",margin:"0.5rem 0 0",fontSize:"0.9rem"},children:t.supported?r.jsxs(r.Fragment,{children:["Starts automatically when you log in, and restarts if it crashes. Uses ",p," — no admin rights needed."]}):t.reason})]}),t.supported&&r.jsx("button",{type:"button",onClick:()=>void g(),disabled:a,"aria-pressed":t.installed,className:t.installed?"btn btn-secondary":"btn btn-primary",style:{whiteSpace:"nowrap"},children:a?"Working…":t.installed?"Turn off":"Turn on"})]}),t.supported&&r.jsxs("p",{style:{margin:"1rem 0 0",fontSize:"0.85rem",color:"var(--text-tertiary)"},children:["Status: ",r.jsx("strong",{children:t.installed?"On — starts from your next login":"Off"})]}),t.supported&&r.jsxs("p",{style:{margin:"0.5rem 0 0",fontSize:"0.85rem",color:"var(--text-tertiary)"},children:["Turning this on doesn't interrupt the gateway you're using — it takes effect at your next login. After any restart Suveren comes back ",r.jsx("strong",{children:"locked"}),": you enter your API key once to unlock it, because nothing stored on this machine can unlock it for you."]}),c&&r.jsx("p",{role:"alert",style:{margin:"0.75rem 0 0",fontSize:"0.85rem",color:"var(--danger, #c00)"},children:c})]})}function Lj(){const[t,s]=h.useState(null),[a,o]=h.useState(!1),[c,u]=h.useState(null),f=h.useCallback(async()=>{try{const p=await O.getGatewaySettings();s(p.desktopNotifications),u(null)}catch(p){u(p instanceof Error?p.message:"Could not read notification setting")}},[]);h.useEffect(()=>{f()},[f]);const g=h.useCallback(async()=>{if(!(t===null||a)){o(!0),u(null);try{const p=await O.setGatewaySettings({desktopNotifications:!t});s(p.desktopNotifications)}catch(p){u(p instanceof Error?p.message:"Failed to save"),await f()}finally{o(!1)}}},[t,a,f]);return t===null?r.jsxs("div",{className:"card",style:{padding:"1.5rem",marginTop:"2rem"},children:[r.jsx("h2",{style:{fontSize:"1rem",fontWeight:700,margin:0},children:"Desktop notifications"}),r.jsx("p",{role:c?"alert":void 0,style:{margin:"0.5rem 0 0",fontSize:"0.9rem",color:"var(--text-secondary)"},children:c?`Could not read the setting: ${c}`:"Checking…"})]}):r.jsxs("div",{className:"card",style:{padding:"1.5rem",marginTop:"2rem"},children:[r.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:"1rem"},children:[r.jsxs("div",{children:[r.jsx("h2",{style:{fontSize:"1rem",fontWeight:700,margin:0},children:"Desktop notifications"}),r.jsx("p",{style:{color:"var(--text-secondary)",margin:"0.5rem 0 0",fontSize:"0.9rem"},children:"Tells you something is waiting for review — never what it is, and never with an approve button. Open Suveren to see and decide. At most one notification a minute; the browser tab always shows the count."})]}),r.jsx("button",{type:"button",onClick:()=>void g(),disabled:a,"aria-pressed":t,className:t?"btn btn-secondary":"btn btn-primary",style:{whiteSpace:"nowrap"},children:a?"Saving…":t?"Turn off":"Turn on"})]}),c&&r.jsx("p",{role:"alert",style:{margin:"0.75rem 0 0",fontSize:"0.85rem",color:"var(--danger)"},children:c})]})}const Zf={as_vouched:"verified by",eudi:"verified with an EU digital identity (EUDI)"};function zj(){const[t,s]=h.useState(null),[a,o]=h.useState(!1),[c,u]=h.useState(null),f=h.useCallback(async()=>{try{s(await O.getIdentityDisclosure()),u(null)}catch(y){u(y instanceof Error?y.message:"Could not read the setting")}},[]);h.useEffect(()=>{f()},[f]);const g=h.useCallback(async()=>{if(!(!t||a)){o(!0),u(null);try{s(await O.setIdentityDisclosure(!t.always))}catch(y){u(y instanceof Error?y.message:"Failed to save"),await f()}finally{o(!1)}}},[t,a,f]),p=r.jsx("h3",{className:"card-title",style:{margin:0},children:"Your name on mandates and tickets"});if(!t)return r.jsxs("div",{className:"card",style:{padding:"1.5rem",marginTop:"1rem"},children:[p,r.jsx("p",{role:c?"alert":void 0,style:{margin:"0.5rem 0 0",fontSize:"0.9rem",color:"var(--text-secondary)"},children:c?`Could not read the setting: ${c}`:"Checking…"})]});const v=t.verified&&t.name?`${t.name} — ${t.method==="as_vouched"?`${Zf.as_vouched} ${t.verifier}`:Zf[t.method??""]??t.method}`:null;return r.jsxs("div",{className:"card",style:{padding:"1.5rem",marginTop:"1rem"},children:[r.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:"1rem"},children:[r.jsxs("div",{children:[p,r.jsxs("p",{style:{color:"var(--text-secondary)",margin:"0.5rem 0 0",fontSize:"0.9rem"},children:[t.always?"On: your verified name is attached to every mandate you give — including ones the setup AI proposes and you approve — and to the tickets under them.":"Off: each mandate asks whether to show your name. Mandates the setup AI proposes carry no name."," ","Mandates already given stay as they are."]}),r.jsx("p",{style:{margin:"0.5rem 0 0",fontSize:"0.85rem",color:"var(--text-tertiary)"},children:v?`Your identity: ${v}.`:"Your identity is not verified yet — no name can be shown until it is."})]}),r.jsx("button",{type:"button",onClick:()=>void g(),disabled:a,"aria-pressed":t.always,className:t.always?"btn btn-secondary":"btn btn-primary",style:{whiteSpace:"nowrap"},children:a?"Saving…":t.always?"Turn off":"Always show my name"})]}),c&&r.jsx("p",{role:"alert",style:{margin:"0.75rem 0 0",fontSize:"0.85rem",color:"var(--danger)"},children:c})]})}const Fj={npm:"Checking npm for new releases",docker:"Checking the container registry for new images",dev:"Git checkout — comparing against origin/main, not npm releases",managed:"Checking npm for new releases — managed by your IT",msi:"Checking for new releases — update with the Windows installer"};function Oj(){const{version:t,latestVersion:s,updateAvailable:a,installMethod:o}=dc();return t?r.jsxs("div",{className:"card",style:{padding:"1.5rem",marginTop:"2rem"},children:[r.jsx("h2",{style:{fontSize:"1rem",fontWeight:700,margin:0},children:"Version"}),r.jsxs("p",{style:{margin:"0.5rem 0 0",fontSize:"0.9rem",color:"var(--text-secondary)"},children:["Running ",r.jsx("strong",{children:t}),a&&s?r.jsxs(r.Fragment,{children:[" — ",r.jsx("strong",{children:s})," is available"]}):null]}),r.jsxs("p",{style:{margin:"0.5rem 0 0",fontSize:"0.85rem",color:"var(--text-tertiary)"},children:[Fj[o]??"Update checking is unavailable",o==="dev"&&r.jsx(r.Fragment,{children:" — a development checkout is not told about published releases."})]})]}):null}function Ql({title:t}){return r.jsxs("span",{className:"it-locked-badge",title:t,children:[r.jsx("span",{className:"lock-icon","aria-hidden":"true",children:"🔒"})," Set by your IT"]})}function eh(t){return t===!0}function Mj(){const[t,s]=h.useState(null),[a,o]=h.useState(null);h.useEffect(()=>{let f=!1;return O.getAsPairing().then(g=>{f||s(g)}).catch(g=>{f||o(g instanceof Error?g.message:"Could not read Authority Server info")}),()=>{f=!0}},[]);const c=eh(t==null?void 0:t.asUrlLockedByPolicy),u=eh(t==null?void 0:t.pinTlsLockedByPolicy);return r.jsxs("div",{className:"card",style:{padding:"1.5rem",marginTop:"2rem"},children:[r.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:"1rem"},children:[r.jsx("h2",{style:{fontSize:"1rem",fontWeight:700,margin:0},children:"Authority Server"}),c&&r.jsx(Ql,{})]}),!t&&!a&&r.jsx("p",{style:{margin:"0.5rem 0 0",fontSize:"0.9rem",color:"var(--text-secondary)"},children:"Checking…"}),a&&r.jsx("p",{role:"alert",style:{margin:"0.5rem 0 0",fontSize:"0.9rem",color:"var(--danger, #c00)"},children:a}),t&&r.jsxs(r.Fragment,{children:[r.jsxs("p",{style:{margin:"0.5rem 0 0",fontSize:"0.9rem",color:"var(--text-secondary)"},children:[r.jsx("strong",{children:"URL:"})," ",r.jsx("code",{children:t.asUrl})]}),t.paired&&t.fingerprint?r.jsxs("p",{style:{margin:"0.5rem 0 0",fontSize:"0.9rem",color:"var(--text-secondary)"},children:[r.jsx("strong",{children:"Key fingerprint:"})," ",r.jsx("code",{children:t.fingerprint}),r.jsx("br",{}),r.jsx("span",{style:{fontSize:"0.8rem",color:"var(--text-tertiary)"},children:"Compare this with the fingerprint on the Authority Server's own admin page over a second channel (phone, video call) to confirm this gateway is talking to the right server."})]}):r.jsx("p",{style:{margin:"0.5rem 0 0",fontSize:"0.85rem",color:"var(--text-tertiary)"},children:"Not yet paired — sign in once to pin this server's key."}),(t.tlsPinFingerprint||t.pinTlsEnabled)&&r.jsxs("p",{style:{margin:"0.5rem 0 0",fontSize:"0.9rem",color:"var(--text-secondary)"},children:[r.jsx("strong",{children:"TLS certificate pin:"})," ",u&&r.jsx(Ql,{title:"TLS pinning is set by your IT policy"})," ",t.tlsPinFingerprint?r.jsx("code",{children:t.tlsPinFingerprint}):r.jsxs("span",{style:{color:"var(--text-tertiary)"},children:["not yet captured — this URL has no recorded pairing over TLS",t.pinTlsEnabled?"; sign in to establish one (re-pairing required)":""]}),r.jsx("br",{}),r.jsxs("span",{style:{fontSize:"0.8rem",color:"var(--text-tertiary)"},children:[t.pinTlsEnabled?r.jsxs(r.Fragment,{children:["TLS pinning is ON",u?r.jsx(r.Fragment,{children:", set by your organization's IT policy"}):r.jsxs(r.Fragment,{children:[" (",r.jsx("code",{children:"config set pin-tls on"}),")"]}),". Every connection to the Authority Server must present this certificate's public key, or the gateway refuses it and locks."]}):r.jsxs(r.Fragment,{children:["Captured at sign-in; not currently enforced",u?r.jsx(r.Fragment,{children:" — controlled by your organization's IT policy on this computer"}):r.jsxs(r.Fragment,{children:[" (",r.jsx("code",{children:"config set pin-tls on"})," to require it on every connection)"]}),"."]})," ","A certificate renewal with the SAME key keeps this pin; a NEW key needs re-pairing."]})]}),c?r.jsx("p",{style:{margin:"0.75rem 0 0",fontSize:"0.8rem",color:"var(--text-tertiary)"},children:"This Authority Server URL is set by your organization's IT policy and cannot be changed from this computer. Contact your IT administrator if it needs to change."}):r.jsxs("p",{style:{margin:"0.75rem 0 0",fontSize:"0.8rem",color:"var(--text-tertiary)"},children:["To point this gateway at a different Authority Server:"," ",r.jsx("code",{children:"suveren-gateway config set as-url <url>"}),", then restart. Changing it ends the current sign-in and clears cached mandates — you sign in again against the new server."]})]})]})}function Bj(){const{simulation:t,locked:s}=Jh();return s?r.jsxs("div",{className:"card",style:{padding:"1.5rem",marginTop:"2rem"},children:[r.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:"1rem"},children:[r.jsxs("div",{children:[r.jsx("h2",{style:{fontSize:"1rem",fontWeight:700,margin:0},children:"Simulation mode"}),r.jsxs("p",{style:{color:"var(--text-secondary)",margin:"0.5rem 0 0",fontSize:"0.9rem"},children:['Blocks every real connector without a manifest "simulation" marker.',t!==null&&r.jsxs(r.Fragment,{children:[" ","Currently ",r.jsx("strong",{children:t?"ON":"OFF"}),t?" — real systems are not reachable from this gateway.":"."]})]})]}),r.jsx(Ql,{})]}),r.jsxs("p",{style:{margin:"1rem 0 0",fontSize:"0.78rem",color:"var(--text-tertiary)"},children:["Simulation mode is set by your organization's IT policy",t!==null?` (currently ${t?"on":"off"})`:""," and cannot be changed from this computer — not even from the command line."]})]}):null}const Dj={ollama:{provider:"ollama",endpoint:"http://localhost:11434",models:["gemma4:e4b","gemma4:e2b","gemma4:26b","gemma4:31b","llama3.2","llama3.1","mistral","qwen2.5"]},openrouter:{provider:"openai-compatible",endpoint:"https://openrouter.ai/api/v1",models:["google/gemma-4-31b-it","qwen/qwen3.6-plus:free","stepfun/step-3.5-flash:free","google/gemini-2.5-flash","openai/gpt-4o-mini","anthropic/claude-haiku-4"]},openai:{provider:"openai-compatible",endpoint:"https://api.openai.com/v1",models:["gpt-4o-mini","gpt-4o","o3-mini"]},groq:{provider:"openai-compatible",endpoint:"https://api.groq.com/openai/v1",models:["llama-3.1-8b-instant","llama-3.3-70b-versatile","gemma2-9b-it"]},together:{provider:"openai-compatible",endpoint:"https://api.together.xyz/v1",models:["meta-llama/Llama-3-8b-chat-hf","meta-llama/Llama-3-70b-chat-hf"]}},Vs=["AI Assistant","Authority Server","This computer","Security","Version"],Gs={fontSize:"1rem",fontWeight:700,marginBottom:"1rem"};function Uj(){const[t,s]=h.useState(""),[a,o]=h.useState("openrouter"),[c,u]=h.useState("openai-compatible"),[f,g]=h.useState("https://openrouter.ai/api/v1"),[p,v]=h.useState("google/gemma-4-31b-it"),[y,w]=h.useState(""),[j,N]=h.useState(!1),[b,S]=h.useState(!1),[k,T]=h.useState(!1),[R,P]=h.useState(null),[A,B]=h.useState([]),[H,G]=h.useState(!1),[me,q]=h.useState(null),[ce,ee]=h.useState(""),F=h.useCallback(V=>{s(V),setTimeout(()=>s(""),3e3)},[]),re=h.useCallback(async(V,W,C)=>{G(!0),q(null);try{const L=await O.aiModels({provider:V,endpoint:W,...C?{apiKey:C}:{}});L.ok&&L.models.length>0?(B(L.models),q(`${L.models.length} models available`)):(B([]),q(L.message||"No models returned — using defaults"))}catch(L){B([]),q(L instanceof Error?L.message:"Failed to load models")}finally{G(!1)}},[]),Y=h.useCallback(async()=>{try{const V=await O.getCredential("ai-config");if(N(V.configured),V.configured&&V.fields){const W=V.fields.provider||"openai-compatible",C=V.fields.endpoint||"";V.fields.provider&&u(W),V.fields.endpoint&&g(C),V.fields.model&&v(V.fields.model),C.includes("openai.com")?o("openai"):C.includes("groq.com")?o("groq"):C.includes("together.xyz")?o("together"):C.includes("openrouter.ai")?o("openrouter"):o("ollama"),C&&re(W,C)}}catch{}},[re]);h.useEffect(()=>{Y()},[Y]);const se=V=>{o(V),B([]),q(null),ee("");const W=Dj[V];W&&(u(W.provider),g(W.endpoint),v(""),re(W.provider,W.endpoint,y||void 0))},ye=()=>re(c,f,y||void 0),we=async()=>{S(!0);try{await O.setCredential("ai-config",{provider:c,endpoint:f,model:p,...y?{apiKey:y}:{}}),N(!0),F("AI configuration saved!")}catch{F("Failed to save AI config")}finally{S(!1)}},J=async()=>{T(!0),P(null);try{const V=await O.aiTest({provider:c,endpoint:f,model:p,...y?{apiKey:y}:{}});P(V.ok?`OK: ${V.message}`:`Failed: ${V.message}`)}catch(V){P(`Error: ${V instanceof Error?V.message:"Unknown"}`)}finally{T(!1)}};return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"page-header",children:[r.jsx("h1",{className:"page-title",children:"Settings"}),r.jsx("p",{className:"page-subtitle",children:"Your AI assistant, the connection to your Authority Server, security and version."})]}),t&&r.jsx("div",{className:"alert alert-success",children:t}),r.jsxs("section",{style:{marginBottom:"2rem"},children:[r.jsx("h2",{style:Gs,children:Vs[0]}),r.jsx("p",{style:{fontSize:"0.85rem",color:"var(--text-secondary)",marginBottom:"1rem"},children:"Advisory AI to help you think through intent when giving mandates."}),r.jsxs("div",{className:"card",children:[r.jsx("h3",{className:"card-title",children:"Configuration"}),r.jsx("p",{style:{fontSize:"0.85rem",color:"var(--text-secondary)",marginBottom:"1rem"},children:"Connect a trusted AI model that has access to your intent — problem, objective, and tradeoffs — to help you think through mandates. Keys are encrypted in your vault."}),j&&r.jsxs("div",{className:"status-banner status-banner-success",style:{marginBottom:"1rem",fontSize:"0.8rem"},children:[r.jsx("span",{className:"status-banner-icon",children:"✓"}),r.jsx("span",{className:"status-banner-text",children:"AI configured"})]}),r.jsxs("div",{className:"form-group",style:{marginBottom:"0.75rem"},children:[r.jsx("label",{className:"form-label",children:"Provider Preset"}),r.jsxs("select",{className:"form-input",value:a,onChange:V=>se(V.target.value),children:[r.jsx("option",{value:"openrouter",children:"OpenRouter (recommended)"}),r.jsx("option",{value:"ollama",children:"Ollama (local)"}),r.jsx("option",{value:"openai",children:"OpenAI"}),r.jsx("option",{value:"groq",children:"Groq"}),r.jsx("option",{value:"together",children:"Together"})]})]}),r.jsxs("div",{className:"form-group",style:{marginBottom:"0.75rem"},children:[r.jsxs("label",{className:"form-label",children:["API Key ",c==="ollama"?"(not needed for Ollama)":"(required to load models)"]}),r.jsx("input",{className:"form-input",type:"password",name:"ai-provider-api-key-credential-top",autoComplete:"new-password",value:y,onChange:V=>w(V.target.value),onBlur:()=>{y.trim()&&re(c,f,y.trim())},placeholder:j?"••••••••••••••••":"sk-... (not needed for Ollama)"}),r.jsx("p",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",margin:"0.375rem 0 0"},children:"Each provider uses its own key — paste it and the model list loads automatically."})]}),r.jsxs("div",{className:"form-group",style:{marginBottom:"0.75rem"},children:[r.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[r.jsx("label",{className:"form-label",children:"Model"}),r.jsx("button",{type:"button",className:"btn btn-ghost",style:{fontSize:"0.75rem",padding:"0.125rem 0.5rem"},onClick:ye,disabled:H,title:"Re-fetch the model list from the provider",children:H?"Loading…":"↻ Refresh"})]}),A.length===0?r.jsx("div",{className:"form-input",style:{display:"flex",alignItems:"center",minHeight:"2.5rem",color:"var(--text-secondary)",fontSize:"0.85rem"},children:H?"Loading models…":c==="ollama"?"Start Ollama locally, then ↻ Refresh to load models.":"Enter a valid API key above to load available models."}):(()=>{const V=A,W=V.includes(p),C=V.length>12,L=ce.trim().toLowerCase();let fe=L?V.filter(Q=>Q.toLowerCase().includes(L)):V;return W&&!fe.includes(p)&&(fe=[p,...fe]),r.jsxs(r.Fragment,{children:[C&&r.jsx("input",{className:"form-input",value:ce,onChange:Q=>ee(Q.target.value),placeholder:"Filter models… (e.g. kimi)",style:{marginBottom:"0.375rem"}}),r.jsxs("select",{className:"form-input",value:W?p:"__unset__",onChange:Q=>v(Q.target.value==="__unset__"?"":Q.target.value),children:[r.jsx("option",{value:"__unset__",disabled:!0,children:"Select a model…"}),fe.map(Q=>r.jsx("option",{value:Q,children:Q},Q)),L&&fe.length===0&&r.jsxs("option",{value:"__unset__",disabled:!0,children:["No models match “",ce,"”"]})]})]})})(),me&&r.jsx("p",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",margin:"0.375rem 0 0"},children:me})]}),r.jsxs("div",{style:{display:"flex",gap:"0.5rem",alignItems:"center"},children:[r.jsx("button",{className:"btn btn-primary",onClick:we,disabled:b||!p.trim(),title:p.trim()?void 0:"Select a model first",children:b?"Saving...":"Save & Encrypt"}),j&&r.jsx("button",{className:"btn btn-ghost",onClick:J,disabled:k,children:k?"Testing...":"Test Connection"})]}),R&&r.jsx("div",{className:`alert ${R.startsWith("OK")?"alert-success":"alert-error"}`,style:{marginTop:"0.75rem"},children:R})]}),r.jsx(Wj,{})]}),r.jsxs("section",{style:{marginBottom:"2rem"},children:[r.jsx("h2",{style:Gs,children:Vs[1]}),r.jsx(Mj,{}),r.jsx(zj,{})]}),r.jsxs("section",{style:{marginBottom:"2rem"},children:[r.jsx("h2",{style:Gs,children:Vs[2]}),r.jsx($j,{}),r.jsx(Lj,{}),r.jsx(Bj,{})]}),r.jsxs("section",{style:{marginBottom:"2rem"},children:[r.jsx("h2",{style:Gs,children:Vs[3]}),r.jsx("div",{className:"card",style:{padding:"1.5rem"},children:r.jsxs("div",{style:{fontSize:"0.85rem",color:"var(--text-secondary)",lineHeight:1.7},children:[r.jsxs("div",{style:{marginBottom:"1rem"},children:[r.jsx("div",{style:{fontWeight:600,color:"var(--text-primary)",marginBottom:"0.375rem"},children:"What the gateway protects"}),r.jsxs("ul",{style:{margin:0,paddingLeft:"1.25rem"},children:[r.jsx("li",{children:"Every tool call verified against your mandate bounds"}),r.jsx("li",{children:"Credentials never exposed to agents through MCP"}),r.jsx("li",{children:"Every action produces a signed ticket"})]})]}),r.jsxs("div",{children:[r.jsx("div",{style:{fontWeight:600,color:"var(--text-primary)",marginBottom:"0.375rem"},children:"Your responsibility"}),r.jsxs("ul",{style:{margin:0,paddingLeft:"1.25rem"},children:[r.jsx("li",{children:"If your AI agent has full access to your computer, it could bypass the gateway"}),r.jsx("li",{children:"For best security, run agents in sandboxed environments"}),r.jsx("li",{children:"The gateway secures what agents do through tools — not what they do on your machine"})]})]})]})})]}),r.jsxs("section",{children:[r.jsx("h2",{style:Gs,children:Vs[4]}),r.jsx(Oj,{})]})]})}function Wj(){const[t,s]=h.useState(null),[a,o]=h.useState({intent:"",context:""}),[c,u]=h.useState(null),[f,g]=h.useState(null),[p,v]=h.useState(null),[y,w]=h.useState(!1),j=h.useCallback(async()=>{if(!y)try{const S=await O.getAIPrompts();s(S),o({intent:S.intent.current,context:S.context.current}),w(!0)}catch(S){g(S instanceof Error?S.message:"Failed to load prompts")}},[y]),N=async S=>{if(t){u(S),g(null);try{const k=a[S],T=k.trim()===t[S].default.trim()?"":k;await O.setAIPrompt(S,T);const R=await O.getAIPrompts();s(R),o({intent:R.intent.current,context:R.context.current}),v(S),setTimeout(()=>v(null),2e3)}catch(k){g(k instanceof Error?k.message:"Save failed")}finally{u(null)}}},b=async S=>{if(confirm(`Revert ${S} prompt to the built-in default?`)){u(S),g(null);try{await O.setAIPrompt(S,"");const k=await O.getAIPrompts();s(k),o({intent:k.intent.current,context:k.context.current})}catch(k){g(k instanceof Error?k.message:"Revert failed")}finally{u(null)}}};return r.jsxs("details",{className:"card",style:{padding:"1.5rem",marginTop:"1rem"},onToggle:S=>{S.currentTarget.open&&j()},children:[r.jsx("summary",{style:{fontSize:"1rem",fontWeight:700,cursor:"pointer",listStyle:"revert",userSelect:"none"},children:"Advanced — AI assistant prompts"}),r.jsx("p",{style:{fontSize:"0.85rem",color:"var(--text-secondary)",margin:"0.75rem 0 1rem 0",lineHeight:1.55},children:"These are the system prompts the AI assistant sees when helping you write Intent (per-mandate) or Context (your standing-orders brief). Edit with care — changes apply on the next chat turn."}),f&&r.jsx("div",{className:"alert alert-error",style:{marginBottom:"0.75rem"},children:f}),!y&&!f&&r.jsx("p",{style:{color:"var(--text-muted)",fontSize:"0.85rem"},children:"Loading prompts…"}),t&&r.jsxs(r.Fragment,{children:[r.jsx(th,{kind:"intent",label:"Intent — per-mandate",description:"Used on the Intent gate when creating a new mandate.",state:t.intent,draft:a.intent,onChange:S=>o(k=>({...k,intent:S})),onSave:()=>N("intent"),onRevert:()=>b("intent"),saving:c==="intent",justSaved:p==="intent"}),r.jsx(th,{kind:"context",label:"Context — standing-orders brief",description:"Used on the Brief page when refining your context.md.",state:t.context,draft:a.context,onChange:S=>o(k=>({...k,context:S})),onSave:()=>N("context"),onRevert:()=>b("context"),saving:c==="context",justSaved:p==="context"})]})]})}function th({kind:t,label:s,description:a,state:o,draft:c,onChange:u,onSave:f,onRevert:g,saving:p,justSaved:v}){const y=c!==o.current;return r.jsxs("section",{style:{marginBottom:"1.5rem"},children:[r.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"0.25rem",gap:"1rem",flexWrap:"wrap"},children:[r.jsxs("div",{children:[r.jsx("div",{style:{fontWeight:600,fontSize:"0.9rem"},children:s}),r.jsx("div",{style:{fontSize:"0.78rem",color:"var(--text-secondary)"},children:a})]}),o.overridden&&r.jsx("span",{style:{fontSize:"0.7rem",color:"var(--accent)",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Custom"})]}),r.jsx("textarea",{className:"form-textarea",value:c,onChange:w=>u(w.target.value),rows:12,spellCheck:!1,style:{width:"100%",fontFamily:"'SF Mono', Monaco, 'Cascadia Code', monospace",fontSize:"0.82rem",lineHeight:1.55,resize:"vertical",minHeight:"14rem",marginTop:"0.5rem"},"aria-label":`${s} system prompt`}),r.jsxs("div",{style:{display:"flex",gap:"0.5rem",alignItems:"center",marginTop:"0.5rem",flexWrap:"wrap"},children:[r.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:f,disabled:p||!y,children:p?"Saving…":"Save"}),o.overridden&&r.jsx("button",{type:"button",className:"btn btn-ghost btn-sm",onClick:g,disabled:p,title:"Discard the override and use the built-in default",children:"Revert to default"}),v&&r.jsx("span",{style:{fontSize:"0.78rem",color:"var(--success)"},children:"Saved"}),y&&!p&&!v&&r.jsx("span",{style:{fontSize:"0.78rem",color:"var(--text-muted)"},children:"Unsaved changes"})]}),r.jsxs("details",{style:{marginTop:"0.5rem"},children:[r.jsx("summary",{style:{fontSize:"0.78rem",color:"var(--text-muted)",cursor:"pointer"},children:"Show built-in default"}),r.jsx("pre",{style:{marginTop:"0.5rem",padding:"0.75rem 1rem",background:"var(--bg-main)",border:"1px solid var(--border)",borderRadius:"0.5rem",fontSize:"0.78rem",lineHeight:1.55,whiteSpace:"pre-wrap",maxHeight:"20rem",overflowY:"auto"},children:o.default})]}),r.jsx("span",{style:{display:"none"},children:t})]})}function Hj(t){return t.proposalId?"review":"automatic"}function nh(t,s,a={}){const o=a.status??"pending",c=a.includeAutonomous??!1,u=[];for(const f of t)o==="pending"&&f.status!=="pending"||a.profile&&f.profileId!==a.profile||u.push({kind:"proposal",id:f.id,sortTimestamp:f.createdAt,commitmentMode:"review",profileId:f.profileId,proposal:f});if(o==="all")for(const f of s){const g=Hj(f);!c&&g==="automatic"||a.profile&&f.profileId!==a.profile||u.push({kind:"receipt",id:f.id,sortTimestamp:f.timestamp,commitmentMode:g,profileId:f.profileId,receipt:f})}return u.sort((f,g)=>g.sortTimestamp-f.sortTimestamp),typeof a.limit=="number"&&a.limit>0?u.slice(0,a.limit):u}const Vj=["https://","http://"];function Cm(t,s){return t!=null&&t.length?t.flatMap(a=>{const o=a.template.replace(/\{(\w+)\}/g,(c,u)=>{const f=s[u];return typeof f=="string"||typeof f=="number"?String(f):"\0"});return o.includes("\0")||/\{|\}/.test(o)?[]:Vj.some(c=>o.toLowerCase().startsWith(c))?[{label:a.label,href:o,description:a.description}]:[]}):[]}function Em(t,s){const a=t-Math.floor(s/1e3);if(a<=0)return{label:"expired",urgent:!1,expired:!0};const o=Math.floor(a/86400),c=Math.floor(a%86400/3600),u=Math.floor(a%3600/60);let f;return o>0?f=`expires in ${o}d ${c}h`:c>0?f=`expires in ${c}h ${u}m`:f=`expires in ${Math.max(1,u)}m`,{label:f,urgent:a<2*3600,expired:!1}}const Gj=/^(image|img|photo|picture|thumbnail)(_?url)?$/i;function Kj(t,s){return typeof s!="string"?!1:/^data:image\//i.test(s)?!0:Gj.test(t)?/^https?:\/\//.test(s):/^https?:\/\/.+\.(jpe?g|png|gif|webp|svg|avif)(\?|$)/i.test(s)}function Jr(t){if(t==null)return"—";if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean")return String(t);try{return JSON.stringify(t,null,2)}catch{return String(t)}}function rh({row:t,which:s}){const a=ss(t.profileRef),o=Pw(t.value,a,s);return o.length===0?r.jsx("span",{style:{color:"var(--text-tertiary)"},children:"none"}):r.jsx("dl",{style:{display:"grid",gridTemplateColumns:"max-content 1fr",gap:"0.15rem 0.75rem",margin:0},children:o.map(c=>r.jsxs(h.Fragment,{children:[r.jsx("dt",{style:{color:"var(--text-secondary)"},title:c.hint,children:c.label}),r.jsxs("dd",{style:{margin:0,fontWeight:600},children:[c.value,c.unknown&&r.jsx("span",{style:{color:"var(--danger)",fontWeight:400,marginLeft:"0.5rem"},children:"not defined by this profile"})]})]},c.key))})}function qj({row:t}){const s=ss(t.profileRef),a=(s==null?void 0:s.id)??t.profileRef??"";return r.jsxs(r.Fragment,{children:[(s==null?void 0:s.name)??ht(a),r.jsx("div",{style:{fontSize:"0.75rem",color:"var(--text-tertiary)"},children:a})]})}function Yj({row:t,altText:s}){switch(t.kind){case"profile":return r.jsx(qj,{row:t});case"profile-limits":return r.jsx(rh,{row:t,which:"limits"});case"profile-scope":return r.jsx(rh,{row:t,which:"scope"});case"markdown":return r.jsx("div",{style:{whiteSpace:"pre-wrap",background:"var(--bg-main)",border:"1px solid var(--border)",borderRadius:"0.375rem",padding:"0.5rem 0.625rem"},children:Jr(t.value)});case"list":return Array.isArray(t.value)?r.jsx("ul",{style:{margin:0,paddingLeft:"1.1rem"},children:t.value.map((a,o)=>r.jsx("li",{children:Jr(a)},o))}):r.jsx(r.Fragment,{children:Jr(t.value)});case"money":return r.jsxs(r.Fragment,{children:[Jr(t.value),t.currency?` ${t.currency}`:""]});case"object":return r.jsx("pre",{style:{margin:0,whiteSpace:"pre-wrap",fontSize:"0.8rem"},children:Jr(t.value)});default:return Kj(t.key,t.value)?r.jsx("img",{src:t.value,alt:s??t.key,style:{display:"block",maxWidth:"100%",maxHeight:"240px",borderRadius:"0.375rem",border:"1px solid var(--border)"}}):r.jsx(r.Fragment,{children:Jr(t.value)})}}function Tm({args:t,display:s,heading:a="Details"}){const o=Iw(t,s);if(o.length===0)return null;const c=typeof t.altText=="string"?t.altText:void 0;return r.jsxs("div",{style:{marginBottom:"0.75rem"},children:[a&&r.jsx("div",{style:{fontSize:"0.7rem",fontWeight:600,color:"var(--text-tertiary)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:"0.35rem"},children:a}),r.jsx("dl",{style:{display:"grid",gridTemplateColumns:"max-content 1fr",gap:"0.35rem 0.75rem",fontSize:"0.85rem",margin:0},children:o.map(u=>r.jsxs(h.Fragment,{children:[r.jsx("dt",{style:{color:"var(--text-tertiary)",whiteSpace:"nowrap",alignSelf:"start"},title:u.hint,children:u.label}),r.jsx("dd",{style:{color:"var(--text-primary)",margin:0,wordBreak:"break-word",whiteSpace:"pre-wrap"},children:r.jsx(Yj,{row:u,altText:c})})]},u.key))})]})}function Jj({proposalId:t,systemName:s}){const[a,o]=h.useState(null);if(h.useEffect(()=>{let u=!0;return o(null),O.getProposalOutcome(t).then(f=>{u&&o(f)}).catch(()=>{}),()=>{u=!1}},[t]),!a)return null;const c=cj(a,s);return c?r.jsxs("div",{className:"outcome-box",children:[r.jsx("h4",{children:c.heading}),r.jsx("p",{className:"outcome-note",children:c.note})]}):null}let zl=null;function Qj(){return zl||(zl=O.getEnrichedAuthorizations().then(t=>new Map(t.map(s=>[s.authorizationId,s.bounds]))).catch(()=>new Map)),zl}function Xj(t){const[s,a]=h.useState(void 0);return h.useEffect(()=>{let o=!0;if(t)return Qj().then(c=>{o&&a(c.get(t))}),()=>{o=!1}},[t]),s}function Zj(t,s){const[a,o]=h.useState(null),[c,u]=h.useState(!1),[f,g]=h.useState(null);return h.useEffect(()=>{let p=!0;return o(null),g(null),u(!0),(async()=>{var v;try{try{const j=await O.getGateContent(t);if((v=j==null?void 0:j.gateContent)!=null&&v.intent){p&&o(j.gateContent.intent);return}}catch{}const y=await O.getAttestationIntent(t);if(!y){p&&g("Intent not available or you are not an authorized approver.");return}const w=await O.decryptIntent({intentCiphertext:y.intentCiphertext,encryptedKey:y.encryptedKey,approverId:s});p&&o(w)}catch(y){p&&g(y instanceof Error?y.message:"Failed to decrypt intent")}finally{p&&u(!1)}})(),()=>{p=!1}},[t,s]),{intent:a,loading:c,error:f}}async function Rm(t){if(t.toolArgs)return t.toolArgs;if(!t.content)return null;try{const{plaintext:s}=await O.decryptProposalContent(t.content),a=JSON.parse(s);return typeof a!="object"||a===null||Array.isArray(a)?null:a}catch{return null}}function eS(t){if(!t.content)return[];const s=new Set([...t.createdBy?[t.createdBy]:[],...t.pendingApprovers??[]]),a=new Set(Object.keys(t.content.keys));return Array.from(s).filter(o=>!a.has(o))}function Am(t){return!t.loading&&t.readable}function Im(t,s){const a=new Set;if(t.content)for(const o of Object.keys(t.content.keys))a.add(o);else{t.createdBy&&a.add(t.createdBy);for(const o of t.pendingApprovers??[])a.add(o)}return s&&a.add(s),Array.from(a)}async function Js(t){const s=await Rm(t);if(s)return gm("jcs",s)}function tS(t){var o;const[s,a]=h.useState((t==null?void 0:t.note)??null);return h.useEffect(()=>{let c=!0;if(t!=null&&t.note){a(t.note);return}if(!(t!=null&&t.noteEncrypted)){a(null);return}return a(null),O.decryptProposalContent(t.noteEncrypted).then(({plaintext:u})=>{c&&a(u)}).catch(()=>{c&&a(null)}),()=>{c=!1}},[t==null?void 0:t.note,(o=t==null?void 0:t.noteEncrypted)==null?void 0:o.ciphertext]),s}const nS={toolArgs:null,loading:!1,sealed:!1,undecryptable:!1};function Pm(t){var o;const[s,a]=h.useState(nS);return h.useEffect(()=>{let c=!0;if(t.toolArgs){a({toolArgs:t.toolArgs,loading:!1,sealed:!1,undecryptable:!1});return}if(!t.content){a({toolArgs:null,loading:!1,sealed:!1,undecryptable:!1});return}return a({toolArgs:null,loading:!0,sealed:!0,undecryptable:!1}),(async()=>{const u=await Rm(t);c&&a({toolArgs:u,loading:!1,sealed:!0,undecryptable:u===null})})(),()=>{c=!1}},[(o=t.content)==null?void 0:o.ciphertext,t.toolArgs]),s}function sh(t){if(!t||typeof t!="object"||Array.isArray(t))return{};const s={};for(const[a,o]of Object.entries(t))(typeof o=="string"||typeof o=="number")&&(s[a]=o);return s}function rS(t){const s=sh(t.limits),a=sh(t.scope),o=typeof t.intent=="string"?t.intent:"",c={bounds:s,context:a,gateContent:{intent:o}};return(t.mode==="automatic"||t.mode==="review")&&(c.templateMode=t.mode),typeof t.duration_hours=="number"&&t.duration_hours>0&&(c.templateTtl=Math.round(t.duration_hours*3600)),c}function _m(t){if(t==null)return"—";if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean")return String(t);if(Array.isArray(t))return t.map(s=>_m(s)).join(", ");try{return JSON.stringify(t,null,2)}catch{return String(t)}}const sS="setup__create_mandate";function $m({proposal:t,currentUserId:s,proposalLinks:a,toolDisplay:o,manifests:c,onContentState:u,onShownSnapshot:f,nameOf:g}){const[p,v]=h.useState(!1),[y,w]=h.useState(!1),[j,N]=h.useState(null),b=mn(),{group:S,groupId:k,domain:T}=mt(),R=Object.entries(t.executionContext),P=ss(t.profileId),A=Xj(t.authorizationId),B=Ow(t.executionContext,A,P),H=Rw(t.tool),{integrationId:G}=Mi(t.tool),me=Nc(G,c),{intent:q,loading:ce,error:ee}=Zj(t.authorizationId,s),F=Pm(t),re=F.toolArgs!==null;h.useEffect(()=>{u==null||u({loading:F.loading,readable:re})},[F.loading,re]);const Y=eS(t),se=F.toolArgs?Cm(a,F.toolArgs):[],ye=async()=>{if(!k){N("No active workspace; cannot open the mandate screen.");return}w(!0),N(null);try{if(!F.toolArgs){N("This content is not readable on this device yet.");return}const z=F.toolArgs,X=typeof z.profile=="string"?z.profile:"",ne=await O.listProfiles(),ie=dm(X,ne);if(!ie){N(`Unknown profile "${X}".`);return}const K=await O.getProfile(ie.id),ke=rS(z),Ne=hm(ke.bounds,K),$e=mm(ke.context,K);sessionStorage.setItem("agentAuth",JSON.stringify({profileId:ie.id,groupId:k,groupName:(S==null?void 0:S.name)??null,domain:T,isPersonal:!!(S!=null&&S.isPersonal)})),sessionStorage.setItem("agentGate",JSON.stringify({...ke,bounds:Ne,context:$e})),sessionStorage.setItem("agentReplacesProposal",t.id),b("/mandates/new/intent")}catch(z){N(z instanceof Error?z.message:"Could not open the mandate screen.")}finally{w(!1)}},[we,J]=h.useState(null),V=uj(we),[W,C]=h.useState(null),[L,fe]=h.useState(null);h.useEffect(()=>{if(!W||!L){f==null||f(null);return}const z=W.status==="ok"?W.readAt:Date.now();f==null||f({readAt:z,preview:W,requestContext:L,...F.toolArgs?{toolArgs:F.toolArgs}:{},sealed:F.sealed})},[W,L,F.toolArgs,F.sealed,f]);const Q=F.toolArgs?r.jsxs(r.Fragment,{children:[r.jsx(Tm,{args:F.toolArgs,display:o,heading:""}),R.length>0&&r.jsx("div",{style:{fontSize:"0.85rem",color:"var(--text-secondary)"},children:R.map(([z,X],ne)=>{const{label:ie,hint:K}=pm(z,P);return r.jsxs("span",{children:[ne>0&&" · ",r.jsxs("span",{title:K,children:[ie,"=",_m(X)]})]},z)})})]}):null;return r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"approval-headline",children:H}),F.sealed&&F.undecryptable&&r.jsxs("div",{className:"preview-box","data-testid":"proposal-undecryptable",style:{marginBottom:"0.5rem"},children:[r.jsx("strong",{children:"Encrypted for another device."}),r.jsx("p",{style:{margin:"0.35rem 0 0",fontSize:"0.85rem",color:"var(--text-secondary)"},children:"This device was added after the proposal was made, and no device of yours has shared it yet. It is shared automatically once a device that can read it comes online — or open it there."})]}),F.sealed&&F.loading&&r.jsx("div",{className:"preview-box","data-testid":"proposal-decrypting",style:{marginBottom:"0.5rem"},children:"Decrypting…"}),V&&re&&r.jsxs("div",{className:"preview-box preview-box-ok","data-testid":"bound-values-open",style:{marginBottom:"0.5rem"},children:[r.jsxs("h4",{children:["What will be sent",F.sealed?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"src-tag src-tag-sealed",children:"sealed"})," ",r.jsx("span",{className:"lock-tag",children:"end-to-end encrypted"})]}):r.jsx("span",{className:"src-tag src-tag-sealed",children:"sealed"})]}),Q,F.sealed&&r.jsx("p",{style:{margin:"0.5rem 0 0",fontSize:"0.75rem",color:"var(--text-tertiary)"},children:"Decrypted on this device. suveren.ai stores only an unreadable copy and its fingerprint."})]}),Y.length>0&&r.jsxs("p",{"data-testid":"proposal-cannot-read",style:{margin:"0 0 0.5rem",fontSize:"0.78rem",color:"var(--text-tertiary)"},children:["Cannot read this proposal yet: ",Y.map(z=>(g==null?void 0:g(z))??z).join(", ")," — shared automatically once they sign in on a device."]}),re&&r.jsx(hj,{proposalId:t.id,systemName:me,toolArgs:F.toolArgs,sealed:F.sealed,onTone:J,onData:C}),re&&r.jsx(jj,{proposalId:t.id,onData:fe}),re&&r.jsxs("p",{className:"creation-legend","data-testid":"au10-legend",children:[r.jsxs("span",{children:[r.jsx("i",{className:"creation-legend-dot creation-legend-dot-sealed"}),"sealed — approved and executed exactly so"]}),r.jsxs("span",{children:[r.jsx("i",{className:"creation-legend-dot creation-legend-dot-system"}),"from the system — read by the gateway, not by the AI"]}),r.jsxs("span",{children:[r.jsx("i",{className:"creation-legend-dot au10-dot-ai"}),"the AI's own claim or text — not checked"]})]}),B.length>0&&r.jsxs("div",{className:"limit-checks",children:[r.jsx("h4",{children:"Within your limits"}),r.jsx("ul",{className:"limit-check-list",children:B.map(z=>r.jsxs("li",{className:z.ok?"ok":"bad",children:[r.jsx("span",{className:"limit-check-icon",children:z.ok?"✓":"✗"}),r.jsxs("span",{children:[z.label," ",z.valueText," — your limit ",z.limitText]})]},z.key))})]}),r.jsxs("div",{className:"mandate-intent",children:[r.jsxs("dl",{children:[r.jsx("dt",{children:"Mandate"}),r.jsxs("dd",{children:[r.jsx("strong",{children:(P==null?void 0:P.name)??ht(t.profileId)}),r.jsx("span",{className:"src-tag src-tag-local",children:"local"})]})]}),r.jsxs("dl",{children:[r.jsx("dt",{children:"Intent"}),r.jsx("dd",{children:ee?r.jsx("p",{style:{color:"var(--danger)",fontSize:"0.8rem",margin:0},children:ee}):q!==null?r.jsxs(r.Fragment,{children:[r.jsx("p",{className:`intent-text${p?"":" intent-clamped"}`,children:q}),r.jsx("button",{className:"btn btn-ghost btn-sm intent-toggle",onClick:()=>v(!p),children:p?"Show less":"Show full intent"})]}):ce?r.jsx("p",{style:{color:"var(--text-tertiary)",fontSize:"0.8rem",margin:0},children:"Loading intent…"}):r.jsx("p",{style:{color:"var(--text-tertiary)",fontSize:"0.8rem",margin:0},children:"No intent available for this mandate."})})]})]}),re&&se.length>0&&r.jsx("div",{style:{marginBottom:"0.75rem",display:"flex",gap:"0.5rem",flexWrap:"wrap"},children:se.map(z=>r.jsxs("a",{href:z.href,target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm",style:{textDecoration:"none"},title:z.description??z.href,children:[z.label," ↗"]},z.label))}),!V&&re&&r.jsxs("details",{className:"proposal-args-fold",style:{marginBottom:"0.75rem"},children:[r.jsx("summary",{style:{fontSize:"0.8rem",color:"var(--text-tertiary)",cursor:"pointer"},children:"Details (exactly what is bound)"}),r.jsx("div",{style:{marginTop:"0.5rem"},children:Q})]}),re&&t.tool===sS&&r.jsxs("div",{style:{marginBottom:"0.75rem"},children:[r.jsxs("p",{style:{fontSize:"0.8rem",color:"var(--text-secondary)",margin:"0 0 0.4rem"},children:["The intent above is written by the AI, but it becomes ",r.jsx("strong",{children:"your words"})," once you approve. Edit it first — nothing is created until you sign on the mandate screen."]}),r.jsx("button",{type:"button",className:"btn btn-secondary btn-sm","data-testid":"edit-before-signing",onClick:ye,disabled:y,children:y?"Opening…":"Edit before signing"}),j&&r.jsx("p",{style:{color:"var(--danger)",fontSize:"0.8rem",margin:"0.4rem 0 0"},children:j})]})]})}function Lm({note:t,onNoteChange:s,onSend:a,onCancel:o,sending:c,error:u}){return r.jsxs("div",{style:{border:"1px solid var(--border)",borderRadius:"var(--radius)",background:"var(--bg-main)",padding:"0.75rem 0.875rem",marginTop:"0.5rem"},children:[r.jsxs("div",{style:{fontSize:"0.8rem",color:"var(--text-secondary)",marginBottom:"0.5rem"},children:[r.jsx("strong",{style:{color:"var(--text-primary)"},children:"What should change?"})," (the AI will read this)"]}),r.jsx("div",{style:{display:"flex",gap:"0.375rem",flexWrap:"wrap",marginBottom:"0.5rem"},children:H0.map(f=>r.jsx("button",{type:"button",className:`filter-chip${om(t,f)?" selected":""}`,onClick:()=>s(G0(t,f)),disabled:c,children:f},f))}),r.jsx("textarea",{"data-testid":"change-note",className:"form-input",value:t,maxLength:Ci,onChange:f=>s(f.target.value),rows:3,placeholder:"What should the AI do differently?",disabled:c,style:{width:"100%",resize:"vertical",fontFamily:"inherit"}}),r.jsxs("div",{style:{textAlign:"right",fontSize:"0.7rem",color:"var(--text-tertiary)"},children:[t.length," / ",Ci]}),u&&r.jsx("div",{className:"error-message",style:{marginTop:"0.4rem"},children:u}),r.jsxs("div",{style:{display:"flex",gap:"0.5rem",marginTop:"0.5rem"},children:[r.jsx("button",{"data-testid":"btn-send-back",className:"btn btn-primary",style:{background:"var(--warning)",borderColor:"var(--warning)"},onClick:a,disabled:c,children:c?"Sending…":"Send back for change"}),r.jsx("button",{className:"btn btn-ghost",onClick:o,disabled:c,children:"Cancel"})]}),r.jsx("p",{style:{fontSize:"0.72rem",color:"var(--text-tertiary)",marginTop:"0.5rem",marginBottom:0},children:"The AI is told: adjust and propose again — a new proposal you approve again. Nothing runs from this one."})]})}const aS={pending:"Pending",committed:"Approved",executed:"Executed",rejected:"Rejected",expired:"Expired",refused:"Refused"},iS={pending:"status-pending",committed:"status-active",executed:"status-active",rejected:"status-revoked",expired:"status-expired",refused:"status-revoked"},ah={REJECTED:"status-revoked","CHANGE NEEDED":"status-change-needed",REPLACED:"status-replaced",REFUSED:"status-revoked"};function Fl(t){const s=Date.now()-t*1e3,a=s/36e5;return a<48?a<1?`${Math.max(1,Math.round(s/6e4))}m ago`:`${Math.round(a)}h ago`:new Date(t*1e3).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function oS(t){return t.split("__").pop()??t}function lS(t){const s=t.toLowerCase();return s.includes("delete")||s.includes("refund")||s.includes("cancel")||s.includes("revoke")}function zm(t){if(t==null)return"—";if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean")return String(t);if(Array.isArray(t))return t.map(s=>zm(s)).join(", ");try{return JSON.stringify(t,null,2)}catch{return String(t)}}function ih({item:t,onApprove:s,onReject:a,onChangeNeeded:o,resolving:c,proposalLinks:u,toolDisplay:f,manifests:g,currentUserId:p}){const v=t.kind==="proposal",y=v?t.proposal.status:"executed",w=v?t.proposal.tool:t.receipt.action,j=oS(w),N=lS(w),{integrationId:b}=Mi(w),S=Nc(b,g),[k,T]=h.useState(!1),[R,P]=h.useState(""),[A,B]=h.useState(""),H=h.useRef(null),G=async()=>{const Q=H.current;if(!(!Q||!v))try{const{shownHash:z}=await O.saveShownSnapshot(t.proposal.id,Q);return z}catch{return}},me=async()=>{const Q=kc(R);if(!Q.valid){B(Q.error);return}B("");const z=await G();o==null||o(t.id,Q.trimmed,z)},q=v&&y==="rejected"?J0(t.proposal,p??""):null,ce=v&&y==="refused"?Q0(t.proposal):null,ee=tS(v?t.proposal.rejectedBy??t.proposal.approverRejectedBy??null:null),F=ss(t.profileId),re=Pm(v?t.proposal:{toolArgs:void 0,content:void 0}),Y=v?re.toolArgs:null,se=v?t.proposal.executionContext:t.receipt.executionContext,ye=v?null:t.receipt.cumulativeState,[we,J]=h.useState(!0),[V,W]=h.useState(!1),C=v&&re.toolArgs?Cm(u,re.toolArgs):[],L=Object.entries(se??{}),fe=Nr(t.profileId).testSetup||Oi(w);return r.jsxs("div",{className:"card id-card",children:[r.jsx(rs,{profileId:t.profileId}),r.jsxs("div",{className:"id-body",children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",marginBottom:"0.75rem",flexWrap:"wrap"},children:[r.jsx("code",{style:{fontSize:"0.85rem"},children:j}),fe&&r.jsx("span",{className:"sim-mark",children:"Test setup"}),t.commitmentMode==="automatic"&&r.jsx("span",{style:{fontSize:"0.7rem",color:"var(--text-tertiary)",textTransform:"uppercase",letterSpacing:"0.04em"},children:"autonomous"}),r.jsxs("span",{style:{marginLeft:"auto",display:"flex",alignItems:"center",gap:"0.5rem"},children:[v&&y==="pending"&&(()=>{const Q=Em(t.proposal.expiresAt,Date.now());return r.jsx("span",{style:{fontSize:"0.72rem",color:Q.urgent?"var(--warning)":"var(--text-tertiary)",fontWeight:Q.urgent?600:400,whiteSpace:"nowrap"},children:Q.label})})(),r.jsx("span",{"data-testid":q||ce?"outcome-kind":void 0,className:`status-badge ${q?ah[q.kind]:ce?ah.REFUSED:iS[y]}`,children:q?q.kind:ce?ce.kind:aS[y]}),r.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-tertiary)"},children:Fl(t.sortTimestamp)})]})]}),v&&t.proposal.status==="executed"&&r.jsx(Jj,{proposalId:t.proposal.id,systemName:S}),q&&r.jsxs("div",{style:{fontSize:"0.8rem",color:"var(--text-secondary)",marginBottom:"0.75rem"},children:[r.jsxs("div",{children:["By ",q.who,", ",Fl(q.at)]}),(ee??q.note)&&r.jsxs("div",{"data-testid":"outcome-note",style:{marginTop:"0.2rem"},children:[q.kind==="CHANGE NEEDED"?"Change: ":"Note: ",ee??q.note]})]}),ce&&r.jsxs("div",{style:{fontSize:"0.8rem",color:"var(--text-secondary)",marginBottom:"0.75rem"},children:[r.jsxs("div",{children:["By the Authority Server, ",Fl(ce.at)]}),r.jsxs("div",{"data-testid":"outcome-note",style:{marginTop:"0.2rem"},children:["Reason: ",ce.message]})]}),N&&r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.4rem",fontSize:"0.8rem",color:"var(--warning)",background:"var(--bg-main)",border:"1px solid var(--border)",borderRadius:"0.375rem",padding:"0.4rem 0.6rem",marginBottom:"0.75rem"},children:[r.jsx("span",{children:"⚠"}),r.jsx("span",{children:"Irreversible action"})]}),v&&typeof(Y==null?void 0:Y._imagePreview)=="string"&&r.jsxs("div",{style:{marginBottom:"0.75rem"},children:[r.jsx("div",{style:{fontSize:"0.7rem",fontWeight:600,color:"var(--text-tertiary)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:"0.35rem"},children:"Preview"}),r.jsx("img",{src:Y._imagePreview,alt:typeof(Y==null?void 0:Y.altText)=="string"?Y.altText:"local image preview",style:{display:"block",maxWidth:"100%",maxHeight:"240px",borderRadius:"0.375rem",border:"1px solid var(--border)"}})]}),v&&y==="pending"?r.jsx($m,{proposal:t.proposal,currentUserId:p??"",proposalLinks:u,toolDisplay:f,manifests:g,onContentState:({loading:Q,readable:z})=>{W(Q),J(z)},onShownSnapshot:Q=>{H.current=Q}}):r.jsxs(r.Fragment,{children:[C.length>0&&r.jsx("div",{style:{marginBottom:"0.75rem",display:"flex",gap:"0.5rem",flexWrap:"wrap"},children:C.map(Q=>r.jsxs("a",{href:Q.href,target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm",style:{textDecoration:"none"},title:Q.description??Q.href,children:[Q.label," ↗"]},Q.label))}),v?r.jsxs(r.Fragment,{children:[Y&&r.jsx(Tm,{args:Y,display:f}),L.length>0&&r.jsx("div",{style:{marginBottom:"0.75rem",fontSize:"0.8rem",color:"var(--text-secondary)"},children:L.map(([Q,z])=>`${Q}=${zm(z)}`).join(" · ")})]}):r.jsxs(r.Fragment,{children:[r.jsx(jm,{receipt:t.receipt,profile:F}),t.receipt.proposalId&&r.jsx(Nm,{proposalId:t.receipt.proposalId,tool:t.receipt.action,manifests:g})]})]}),ye&&r.jsxs("div",{style:{fontSize:"0.75rem",color:"var(--text-tertiary)",marginBottom:"0.5rem"},children:["After this action · today: ",ye.daily.count," action",ye.daily.count===1?"":"s",ye.daily.amount>0?`, ${ye.daily.amount}`:""," · ","this month: ",ye.monthly.count,ye.monthly.amount>0?`, ${ye.monthly.amount}`:""]}),v&&y==="pending"&&Am({loading:V,readable:we})&&(k?r.jsx(Lm,{note:R,onNoteChange:P,onSend:me,onCancel:()=>{T(!1),P(""),B("")},sending:!!c,error:A}):r.jsxs("div",{style:{display:"flex",gap:"0.5rem"},children:[r.jsx("button",{className:"btn btn-primary",onClick:async()=>s==null?void 0:s(t.id,await G()),disabled:c,children:c?"Approving…":"Approve"}),r.jsx("button",{"data-testid":"btn-change-needed",className:"btn",style:{background:"var(--bg-elevated)",color:"var(--warning)",border:"1px solid var(--warning)"},onClick:()=>T(!0),disabled:c,children:"Change needed"}),r.jsx("button",{"data-testid":"btn-reject",className:"btn btn-ghost",style:{color:"var(--danger)"},onClick:async()=>a==null?void 0:a(t.id,await G()),disabled:c,children:"Reject"})]})),r.jsxs("div",{style:{marginTop:"0.5rem",fontSize:"0.7rem",color:"var(--text-tertiary)"},children:[v?"Proposal":"Ticket",": ",t.id]})]})]})}function cS(t,s=[]){const a=new Map;for(const o of t){const c=o.name&&o.email?`${o.name} (${o.email})`:o.name||o.email||o.id;a.set(o.id,c)}for(const o of s){const c=o.userId??o.id;c&&(o.name&&o.email?a.set(c,`${o.name} (${o.email})`):o.name&&a.set(c,o.name))}return a}function uS(t,s){return t.map(a=>s.get(a)??a)}function Fm(t){var N;const{groupId:s}=mt(),a=ss(t.profileId),[o,c]=h.useState(null),[u,f]=h.useState(new Map),[g,p]=h.useState(!0);h.useEffect(()=>{let b=!0;if(!s){p(!1);return}return p(!0),Promise.all([O.getTeamProfileConfig(s,t.profileId).catch(()=>null),O.getGroupById(s).catch(()=>null),O.listUsers().catch(()=>[])]).then(([S,k,T])=>{b&&(c(S),f(cS(T,(k==null?void 0:k.members)??[])))}).finally(()=>{b&&p(!1)}),()=>{b=!1}},[s,t.profileId]);const v=Ev(o??{}),y=uS(t.pendingApprovers??[],u),w=b=>u.get(b)??b,j=o&&((N=a==null?void 0:a.boundsSchema)!=null&&N.fields)?h0(t.executionContext,o,a.boundsSchema.fields):null;return{loading:g,profileConfig:o,requiredApprovals:v,approverNames:y,nameOf:w,aboveCapReason:j}}function Om(t,s){return!!t.createdBy&&!!s&&t.createdBy===s}function Mm(t){return(t.pendingApprovers??[]).filter(s=>s!==t.createdBy)}function dS(t){const s=Date.now()-t*1e3,a=Math.floor(s/6e4);if(a<60)return`${Math.max(1,a)}m ago`;const o=Math.floor(s/36e5);return o<48?`${o}h ago`:`${Math.floor(o/24)}d ago`}function fS({proposal:t,currentUserId:s,onAction:a,onMessage:o,proposalLinks:c,toolDisplay:u,manifests:f}){const[g,p]=h.useState(!1),[v,y]=h.useState(!1),[w,j]=h.useState(!1),[N,b]=h.useState(""),[S,k]=h.useState(""),[T,R]=h.useState(!1),[P,A]=h.useState(!1),[B,H]=h.useState(!0),G=h.useRef(null),me=async()=>{const C=G.current;if(C)try{const{shownHash:L}=await O.saveShownSnapshot(t.id,C);return L}catch{return}},q=Nr(t.profileId).testSetup||Oi(t.tool),ce=Mm(t),ee=t.approvedBy??{},F=Object.keys(ee).length,re=s in ee,Y=Fm(t),se=Om(t,s),ye=C=>{const L=C instanceof Error?C.message:"Approval failed";return L.includes("APPROVER_IS_PROPOSER")?"You can't approve your own action. Ask another approver.":L.includes("APPROVAL_IMPOSSIBLE")?"This action cannot be approved — there is no one else eligible to approve it. Ask a team admin to add another approver.":L},we=async()=>{if(vc()){o(xc);return}p(!0),o("");try{const C=await Js(t),L=await me(),fe=await O.approveProposal(t.id,C,L);try{const ne=await O.getAttestationIntent(t.authorizationId);if(ne){const ie=await O.decryptIntent({intentCiphertext:ne.intentCiphertext,encryptedKey:ne.encryptedKey,approverId:s});await O.storeApprovedIntent(t.authorizationId,ie)}}catch{}const{requiredApprovals:Q,approvedCount:z}=fe,X=Q!==void 0&&z!==void 0?Q-z:void 0;o(X===void 0?"Approved.":X>0?`Approved. ${X} more approval${X===1?"":"s"} still needed.`:"Approved — the required number of approvals is met; the action is ready to execute."),a()}catch(C){o(ye(C))}finally{p(!1)}},J=async()=>{y(!0),o("");try{const C=await Js(t),L=await me();await O.rejectProposal(t.id,lm(),C,L),o("Action rejected."),a()}catch(C){o(C instanceof Error?C.message:"Rejection failed")}finally{y(!1)}},V=async()=>{const C=kc(N);if(!C.valid){k(C.error);return}k(""),R(!0),o("");try{const{noteEncrypted:L}=await O.encryptProposalNote(C.trimmed,Im(t,s)),fe=await Js(t),Q=await me();await O.rejectProposal(t.id,{outcome:"change_needed",noteEncrypted:L},fe,Q),o("Sent back for a change."),a()}catch(L){o(L instanceof Error?L.message:"Failed to send back")}finally{R(!1)}},W=g||v||T;return r.jsxs("div",{className:"card id-card",children:[r.jsx(rs,{profileId:t.profileId}),r.jsxs("div",{className:"id-body",children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",marginBottom:"0.5rem",flexWrap:"wrap"},children:[q&&r.jsx("span",{className:"sim-mark",children:"Test setup"}),r.jsxs("span",{style:{marginLeft:"auto",display:"flex",alignItems:"center",gap:"0.5rem"},children:[(()=>{const C=Em(t.expiresAt,Date.now());return r.jsx("span",{style:{fontSize:"0.72rem",color:C.urgent?"var(--warning)":"var(--text-tertiary)",fontWeight:C.urgent?600:400,whiteSpace:"nowrap"},children:C.label})})(),r.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-tertiary)"},children:dS(t.createdAt)})]})]}),r.jsxs("div",{className:"approver-progress",style:{fontSize:"0.8rem",color:"var(--text-tertiary)",marginBottom:"0.5rem"},children:["Needs ",Y.requiredApprovals," approval",Y.requiredApprovals===1?"":"s"," from:"," ",ce.map((C,L)=>r.jsxs("span",{className:`who${C in ee?" done":""}`,style:{marginLeft:L===0?"0.25rem":"0.5rem",color:C in ee?"var(--success)":void 0},children:[C in ee?"✓ ":"",Y.nameOf(C),C===s?" (you)":"",L<ce.length-1?",":""]},C)),Y.requiredApprovals>1&&r.jsxs("span",{style:{marginLeft:"0.5rem"},children:["(",F," of ",Y.requiredApprovals,")"]})]}),Y.aboveCapReason&&r.jsxs("div",{className:"over-limit-box","data-testid":"above-cap-reason",style:{display:"flex",gap:"0.5rem",alignItems:"flex-start",background:"var(--bg-main)",border:"1px solid var(--border)",borderRadius:"0.5rem",padding:"0.6rem 0.8rem",marginBottom:"0.6rem",fontSize:"0.82rem"},children:[r.jsx("span",{style:{color:"var(--warning)",fontWeight:700,whiteSpace:"nowrap"},children:"Above the team limit:"}),r.jsxs("span",{children:[Y.aboveCapReason.fieldLabel,Y.aboveCapReason.value!==void 0?` ${Y.aboveCapReason.value}`:""," (limit ",String(Y.aboveCapReason.cap),")."," ",t.createdBy?`Requested by ${Y.nameOf(t.createdBy)}.`:""]})]}),r.jsx($m,{proposal:t,currentUserId:s,proposalLinks:c,toolDisplay:u,manifests:f,nameOf:Y.nameOf,onContentState:({loading:C,readable:L})=>{A(C),H(L)},onShownSnapshot:C=>{G.current=C}}),!re&&Am({loading:P,readable:B})&&(w?r.jsx(Lm,{note:N,onNoteChange:b,onSend:V,onCancel:()=>{j(!1),b(""),k("")},sending:T,error:S}):r.jsxs("div",{style:{display:"flex",gap:"0.5rem",marginTop:"0.25rem",flexWrap:"wrap",alignItems:"center"},children:[se?r.jsx("p",{className:"blocked-note","data-testid":"cant-approve-own-action",style:{fontSize:"0.82rem",color:"var(--text-tertiary)",margin:0},children:r.jsx("strong",{style:{color:"var(--danger)"},children:"You can't approve your own action."})}):r.jsx("button",{className:"btn btn-primary",onClick:we,disabled:W,children:g?"Approving...":"Approve"}),r.jsx("button",{"data-testid":"btn-change-needed",className:"btn",style:{background:"var(--bg-elevated)",color:"var(--warning)",border:"1px solid var(--warning)"},onClick:()=>j(!0),disabled:W,children:"Change needed"}),r.jsx("button",{"data-testid":"btn-reject",className:"btn btn-ghost",style:{color:"var(--danger)"},onClick:J,disabled:W,children:v?"Rejecting...":"Reject"})]})),re&&r.jsxs("p",{style:{fontSize:"0.8rem",color:"var(--text-tertiary)",marginTop:"0.25rem"},children:["You approved this action.",Y.requiredApprovals>1&&F<Y.requiredApprovals?` Waiting on ${Y.requiredApprovals-F} more approval(s).`:""]}),r.jsxs("div",{style:{marginTop:"0.5rem",fontSize:"0.7rem",color:"var(--text-tertiary)"},children:["Proposal: ",t.id]})]})]})}function hS(){const{domain:t,user:s}=mt(),a=(s==null?void 0:s.id)??"",[o,c]=h.useState("awaiting-me"),[u,f]=h.useState([]),[g,p]=h.useState([]),[v,y]=h.useState({}),[w,j]=h.useState(!0),[N,b]=h.useState(""),S=h.useCallback(async()=>{try{const he=await O.getProposalsForApprover();f(he)}catch{}finally{j(!1)}},[]);De("proposal-added",S),De("proposal-approved",S),De("proposal-rejected",S),De("proposal-resolved",S),Dt(S,3e4);const[k,T]=h.useState([]),R=h.useCallback(async()=>{try{const he=await O.getMyProposals(t);T(he)}catch{}},[t]);De("proposal-added",R),De("proposal-approved",R),De("proposal-rejected",R),De("proposal-resolved",R),De("execution-failed",R),Dt(R,3e4,t);const P=h.useMemo(()=>k.filter(he=>{var Re;return he.status==="pending"&&(((Re=he.pendingApprovers)==null?void 0:Re.length)??0)===0}),[k]),A=h.useMemo(()=>nh(P,[],{status:"pending"}),[P]),[B,H]=h.useState([]),G=h.useCallback(async()=>{if(a)try{const Re=(await O.getMyProposals(t)).filter(Pe=>Pe.status==="pending"&&Pe.pendingApprovers&&Pe.pendingApprovers.includes(a)&&Pe.approvedBy&&a in Pe.approvedBy);H(Re)}catch{}},[a,t]);De("proposal-approved",G),De("proposal-rejected",G),Dt(G,3e4,`${a}:${t}`);const[me,q]=h.useState([]),ce=h.useCallback(async()=>{try{const he=await O.getProposalsCreatedByMe();if(he!==null){q(he);return}q(await O.getMyPendingProposals())}catch{}},[]);De("proposal-added",ce),De("proposal-approved",ce),De("proposal-rejected",ce),Dt(ce,3e4),h.useEffect(()=>{O.getIntegrationManifests().then(he=>p(he.manifests??[])).catch(()=>{}),O.getToolDisplay().then(y).catch(()=>{})},[]);const ee=he=>{var Re;return(Re=g.find(Pe=>Pe.id===he.split("__")[0]))==null?void 0:Re.proposalLinks};h.useEffect(()=>{S(),R(),G(),ce()},[]);const[F,re]=h.useState([]),[Y,se]=h.useState([]),[ye,we]=h.useState(!0),[J,V]=h.useState(null),[W,C]=h.useState(""),[L,fe]=h.useState("pending"),[Q,z]=h.useState(null),[X,ne]=h.useState(!1),ie=h.useCallback(async()=>{try{const{proposals:he,receipts:Re}=await O.getThread({domain:t,status:L,sinceDays:7});re(he),se(Re)}catch{}finally{we(!1)}},[t,L]);Dt(ie,3e4,`${t}:${L}`);const K=async(he,Re,Pe,ut)=>{if(Re==="commit"&&vc()){C(xc);return}V(he),C("");try{const Je=F.find(Te=>Te.id===he)??k.find(Te=>Te.id===he),ze=Cv(Je,t),_=Je?await Js(Je):void 0;let oe=Pe??{};if((Pe==null?void 0:Pe.outcome)==="change_needed"&&Pe.note){const Te=Je?Im(Je,a):[a],{noteEncrypted:de}=await O.encryptProposalNote(Pe.note,Te);oe={outcome:"change_needed",noteEncrypted:de}}const ge=await O.resolveProposal(he,Re,ze,{...oe,contentHash:_,shownHash:ut});C(Re==="commit"?`Action approved. Status: ${ge.status}`:(Pe==null?void 0:Pe.outcome)==="change_needed"?"Sent back for a change.":"Action rejected."),await Promise.all([ie(),R()])}catch(Je){C(Je instanceof Error?Je.message:"Failed")}finally{V(null)}},ke=(he,Re)=>K(he,"commit",void 0,Re),Ne=(he,Re)=>K(he,"reject",lm(),Re),$e=(he,Re,Pe)=>K(he,"reject",K0(Re),Pe),pe=h.useMemo(()=>{const he=new Set;for(const Re of F)he.add(Re.profileId);for(const Re of Y)he.add(Re.profileId);return Array.from(he).sort()},[F,Y]),Le=h.useMemo(()=>nh(F,Y,{status:L,profile:Q??void 0,includeAutonomous:X}),[F,Y,L,Q,X]),Ge=h.useCallback(()=>{S(),G()},[S,G]),He=h.useMemo(()=>{const he=new Set,Re=[];for(const Pe of[...B,...me])he.has(Pe.id)||(he.add(Pe.id),Re.push(Pe));return Re.sort((Pe,ut)=>ut.createdAt-Pe.createdAt)},[B,me]),Oe=u.length+A.length,lt=He.length;return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"page-header",children:[r.jsx("h1",{className:"page-title",children:"Pending Approvals"}),r.jsx("p",{className:"page-subtitle",children:"Actions awaiting approval, plus recent activity from the last 7 days."}),r.jsx(qh,{what:"approve"})]}),r.jsxs("div",{className:"nav-tabs",style:{marginBottom:"1rem"},children:[r.jsxs("button",{className:`nav-tab${o==="awaiting-me"?" active":""}`,onClick:()=>c("awaiting-me"),children:["Awaiting me ",Oe>0&&r.jsx("span",{style:{marginLeft:"0.4rem",background:"var(--warning)",color:"var(--bg-elevated)",borderRadius:"0.625rem",padding:"0 0.375rem",fontSize:"0.7rem",fontWeight:600},children:Oe})]}),r.jsxs("button",{className:`nav-tab${o==="awaiting-others"?" active":""}`,onClick:()=>c("awaiting-others"),children:["Awaiting others ",lt>0&&r.jsx("span",{style:{marginLeft:"0.4rem",background:"var(--border)",color:"var(--text-secondary)",borderRadius:"0.625rem",padding:"0 0.375rem",fontSize:"0.7rem",fontWeight:600},children:lt})]}),r.jsx("button",{className:`nav-tab${o==="all"?" active":""}`,onClick:()=>{c("all"),ie()},children:"All"})]}),o==="awaiting-me"&&r.jsx(r.Fragment,{children:w&&Oe===0?r.jsx("p",{style:{color:"var(--text-tertiary)"},children:"Loading..."}):Oe===0?r.jsxs("div",{className:"card",style:{textAlign:"center",padding:"2rem"},children:[r.jsx("p",{style:{color:"var(--text-tertiary)",marginBottom:"0.5rem"},children:"No actions awaiting your approval."}),r.jsx("p",{style:{fontSize:"0.8rem",color:"var(--text-tertiary)"},children:"Review-mode actions and above-cap actions you must approve will appear here."})]}):r.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"1rem"},children:[(N||W)&&r.jsx("div",{className:"alert alert-success",children:N||W}),A.map(he=>r.jsx(ih,{proposalLinks:he.kind==="proposal"?ee(he.proposal.tool):void 0,toolDisplay:he.kind==="proposal"?v[he.proposal.tool]:void 0,manifests:g,currentUserId:a,item:he,onApprove:ke,onReject:Ne,onChangeNeeded:$e,resolving:J===he.id},he.id)),u.map(he=>r.jsx(fS,{proposal:he,currentUserId:a,onAction:Ge,onMessage:b,proposalLinks:ee(he.tool),toolDisplay:v[he.tool],manifests:g},he.id))]})}),o==="awaiting-others"&&r.jsx(r.Fragment,{children:He.length===0?r.jsxs("div",{className:"card",style:{textAlign:"center",padding:"2rem"},children:[r.jsx("p",{style:{color:"var(--text-tertiary)",marginBottom:"0.5rem"},children:"No actions waiting on others."}),r.jsx("p",{style:{fontSize:"0.8rem",color:"var(--text-tertiary)"},children:"Actions you proposed or approved that are pending other approvers will appear here."})]}):r.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"1rem"},children:He.map(he=>r.jsx(pS,{proposal:he,currentUserId:a,onCancel:async()=>{try{await O.rejectProposal(he.id,{reason:"cancelled by creator"}),G(),R()}catch(Re){alert(Re instanceof Error?Re.message:"Cancel failed")}},onWithdraw:async()=>{const Re=await Js(he);await O.withdrawProposal(he.id,void 0,Re),ce(),G()}},he.id))})}),o==="all"&&r.jsxs(r.Fragment,{children:[W&&r.jsx("div",{className:"alert alert-success",style:{marginBottom:"1rem"},children:W}),r.jsxs("div",{className:"filter-chips",style:{marginBottom:"1rem"},children:[r.jsx("button",{className:`filter-chip ${L==="pending"?"selected":""}`,onClick:()=>fe("pending"),children:"Pending"}),r.jsx("button",{className:`filter-chip ${L==="all"?"selected":""}`,onClick:()=>fe("all"),children:"All"}),pe.length>0&&r.jsx("span",{style:{width:1,background:"var(--border)",alignSelf:"stretch",margin:"0 0.25rem"}}),pe.map(he=>r.jsx("button",{className:`filter-chip ${Q===he?"selected":""}`,onClick:()=>z(Q===he?null:he),children:ht(he)},he)),L==="all"&&r.jsxs(r.Fragment,{children:[r.jsx("span",{style:{width:1,background:"var(--border)",alignSelf:"stretch",margin:"0 0.25rem"}}),r.jsxs("button",{className:`filter-chip ${X?"selected":""}`,onClick:()=>ne(!X),title:"Include actions executed without human review (automatic commitment mode)",children:[X?"✓ ":"","Autonomous actions"]})]})]}),ye&&Le.length===0?r.jsx("p",{style:{color:"var(--text-tertiary)"},children:"Loading..."}):Le.length===0?r.jsxs("div",{className:"card",style:{textAlign:"center",padding:"2rem"},children:[r.jsx("p",{style:{color:"var(--text-tertiary)",marginBottom:"0.5rem"},children:L==="pending"?"No actions awaiting your approval.":"Nothing here yet."}),r.jsx("p",{style:{fontSize:"0.8rem",color:"var(--text-tertiary)"},children:L==="pending"?"Your agents are operating within their mandates. Switch to All to see recent activity.":"When an agent calls a gated tool, activity will appear here."})]}):r.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"1rem"},children:Le.map(he=>r.jsx(ih,{proposalLinks:he.kind==="proposal"?ee(he.proposal.tool):void 0,toolDisplay:he.kind==="proposal"?v[he.proposal.tool]:void 0,manifests:g,currentUserId:a,item:he,onApprove:ke,onReject:Ne,onChangeNeeded:$e,resolving:J===he.id},he.id))})]})]})}function mS(t){const s=Date.now()-t*1e3,a=Math.floor(s/6e4);if(a<60)return`${Math.max(1,a)}m ago`;const o=Math.floor(s/36e5);return o<48?`${o}h ago`:`${Math.floor(o/24)}d ago`}function pS({proposal:t,currentUserId:s,onCancel:a,onWithdraw:o}){const[c,u]=h.useState(!1),[f,g]=h.useState(!1),[p,v]=h.useState(""),y=Fm(t),w=Om(t,s),j=Mm(t),N=t.approvedBy??{},b=Object.keys(N).length,S=j.length>0,k=async()=>{u(!0);try{await a()}finally{u(!1)}},T=async()=>{g(!0),v("");try{await o()}catch(P){v(P instanceof Error?P.message:"Withdraw failed")}finally{g(!1)}},R=Nr(t.profileId).testSetup||Oi(t.tool);return r.jsxs("div",{className:"card id-card",children:[r.jsx(rs,{profileId:t.profileId}),r.jsxs("div",{className:"id-body",children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",marginBottom:"0.5rem",flexWrap:"wrap"},children:[r.jsx("code",{style:{fontSize:"0.85rem"},children:t.tool.split("__").pop()??t.tool}),R&&r.jsx("span",{className:"sim-mark",children:"Test setup"}),r.jsx("span",{style:{marginLeft:"auto",fontSize:"0.75rem",color:"var(--text-tertiary)"},children:mS(t.createdAt)})]}),S&&r.jsxs("div",{className:"approver-progress",style:{fontSize:"0.8rem",color:"var(--text-tertiary)",marginBottom:"0.5rem"},children:["Needs ",y.requiredApprovals," approval",y.requiredApprovals===1?"":"s"," from:"," ",j.map((P,A)=>r.jsxs("span",{className:`who${P in N?" done":""}`,style:{marginLeft:A===0?"0.25rem":"0.5rem",color:P in N?"var(--success)":void 0},children:[P in N?"✓ ":"",y.nameOf(P),P===s?" (you)":"",A<j.length-1?",":""]},P)),y.requiredApprovals>1&&r.jsxs("span",{style:{marginLeft:"0.5rem"},children:["(",b," of ",y.requiredApprovals,")"]})]}),y.aboveCapReason&&r.jsxs("div",{className:"over-limit-box","data-testid":"above-cap-reason",style:{display:"flex",gap:"0.5rem",alignItems:"flex-start",background:"var(--bg-main)",border:"1px solid var(--border)",borderRadius:"0.5rem",padding:"0.6rem 0.8rem",marginBottom:"0.6rem",fontSize:"0.82rem"},children:[r.jsx("span",{style:{color:"var(--warning)",fontWeight:700,whiteSpace:"nowrap"},children:"Above the team limit:"}),r.jsxs("span",{children:[y.aboveCapReason.fieldLabel,y.aboveCapReason.value!==void 0?` ${y.aboveCapReason.value}`:""," (limit ",String(y.aboveCapReason.cap),")."," ",t.createdBy?`Requested by ${y.nameOf(t.createdBy)}.`:""]})]}),S&&w&&r.jsx("p",{"data-testid":"cant-approve-own-action",style:{fontSize:"0.82rem",color:"var(--text-tertiary)",marginBottom:"0.5rem"},children:r.jsx("strong",{style:{color:"var(--danger)"},children:"You can't approve your own action."})}),S&&w?r.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"flex-end",gap:"0.35rem",marginTop:"0.5rem"},children:[r.jsx("button",{className:"btn btn-secondary btn-sm",style:{background:"var(--bg-elevated)",color:"var(--danger)",borderColor:"var(--danger)"},onClick:T,disabled:f,children:f?"Withdrawing...":"Withdraw"}),p&&r.jsx("p",{style:{fontSize:"0.78rem",color:"var(--danger)",margin:0},children:p})]}):r.jsx("div",{style:{display:"flex",justifyContent:"flex-end",gap:"0.5rem",marginTop:"0.5rem"},children:r.jsx("button",{className:"btn btn-ghost btn-sm",style:{color:"var(--danger)"},onClick:k,disabled:c,children:c?"Cancelling...":"Cancel"})})]})]})}const gS=`# Agent Brief
88
+
89
+ You act on my behalf through Suveren — the gateway that gates every
90
+ privileged tool call you make. Suveren implements the bounded-authority
91
+ model from the open Human Agency Protocol (HAP): each mandate
92
+ describes an area of authority, a set of numeric limits, and a scope.
93
+ Operate inside those bounds or the Gatekeeper will reject your action.
94
+
95
+ ## Before you act in a domain
96
+
97
+ 1. Call \`list-authorizations(domain: "<domain>")\` to load the full
98
+ intent, scope, and usage for that area. The session brief shows only
99
+ a one-line summary per mandate — the Intent paragraph lives behind
100
+ that call, and often contains soft rules you MUST honor (e.g. "never
101
+ publish on weekends", "only reply in English").
102
+ 2. If the action would exceed a bound or fall outside the scope, stop
103
+ and explain what would be blocked instead of trying.
104
+ 3. If you're not sure whether an action is covered, ask me first.
105
+
106
+ ## How to handle reviews
107
+
108
+ Mandates in review mode require my approval before the action
109
+ executes. When you propose an action:
110
+ - Include everything I need to judge it (title, recipients, amounts,
111
+ dates, attendees) in the tool arguments.
112
+ - Don't batch unrelated proposals — one proposal per decision.
113
+
114
+ ## Standing orders
115
+
116
+ (Add your own here. Examples:)
117
+
118
+ - Every morning, summarize today's calendar and flag conflicts.
119
+ - On Fridays, give me a weekly review: what's done, what slipped, what's
120
+ next.
121
+ - Never email anyone outside the company without asking first.
122
+ - When drafting posts, prefer plain language over marketing copy.
123
+ `;function yS(){const[t,s]=h.useState(""),[a,o]=h.useState(""),[c,u]=h.useState(!0),[f,g]=h.useState(!1),[p,v]=h.useState(null),[y,w]=h.useState(!1),j=t!==a,N=new Blob([t]).size,b=16*1024;h.useEffect(()=>{if(!j)return;const R=A=>{A.preventDefault(),A.returnValue=""},P=A=>{var G,me;if(A.defaultPrevented||A.button!==0||A.metaKey||A.ctrlKey||A.shiftKey||A.altKey)return;const B=(me=(G=A.target)==null?void 0:G.closest)==null?void 0:me.call(G,"a");if(!B||!B.href)return;let H;try{H=new URL(B.href)}catch{return}H.origin===window.location.origin&&H.pathname!==window.location.pathname&&(confirm("You have unsaved changes to your agent brief. Leave anyway?")||(A.preventDefault(),A.stopPropagation()))};return window.addEventListener("beforeunload",R),document.addEventListener("click",P,!0),()=>{window.removeEventListener("beforeunload",R),document.removeEventListener("click",P,!0)}},[j]),h.useEffect(()=>{let R=!1;return O.getAgentContext().then(P=>{R||(s(P),o(P))}).catch(P=>{R||v({kind:"error",text:P instanceof Error?P.message:"Failed to load context"})}).finally(()=>{R||u(!1)}),()=>{R=!0}},[]);const S=async()=>{g(!0),v(null);try{await O.saveAgentContext(t),o(t),v({kind:"ok",text:"Saved. New MCP sessions will pick this up on next connect."})}catch(R){v({kind:"error",text:R instanceof Error?R.message:"Save failed"})}finally{g(!1)}},k=()=>{s(a),v(null)},T=()=>{t.trim()&&!confirm("Replace current context with the starter template?")||s(gS)};return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"page-header",children:[r.jsx("h1",{className:"page-title",children:"Agent Brief"}),r.jsx("p",{className:"page-subtitle",children:"Standing orders for agents that connect via MCP. This text prepends every new session — keep it tight."}),!t.trim()&&!c&&r.jsx("button",{className:"btn btn-primary btn-sm",onClick:T,disabled:f,title:"Insert a starter brief covering Suveren basics and example standing orders",style:{marginTop:"0.5rem"},children:"Insert starter template"})]}),p&&r.jsx("div",{className:p.kind==="ok"?"alert alert-success":"error-message",style:{marginBottom:"1rem"},children:p.text}),r.jsxs("div",{className:"intent-layout",style:{marginBottom:"1rem"},children:[r.jsx("div",{className:"card intent-pane chat",children:r.jsx(ki,{target:{kind:"context"},currentText:t,onApply:R=>{t.trim()&&!confirm("Replace the current context with the applied draft?")||s(R)},greeting:"Tell me what your agent should know — I'll help shape your standing orders. Or ask me to draft a full brief and we'll iterate.",placeholder:"Ask for help with your brief…"})}),r.jsxs("div",{className:"card intent-pane document",children:[r.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"baseline",gap:"0.5rem",flexWrap:"wrap",marginBottom:"0.5rem"},children:[r.jsx("h3",{className:"card-title",style:{marginBottom:0},children:"context.md"}),r.jsxs("span",{style:{fontSize:"0.75rem",color:N>b?"var(--danger)":"var(--text-muted)"},children:[N.toLocaleString()," / ",b.toLocaleString()," bytes"]})]}),r.jsx("textarea",{className:"form-textarea",value:t,onChange:R=>s(R.target.value),placeholder:c?"Loading…":'Type your standing orders here, or click "Insert starter template" below.',disabled:c,rows:18,style:{fontFamily:"'SF Mono', Monaco, monospace",fontSize:"0.85rem",lineHeight:1.5,minHeight:"22rem"}}),r.jsxs("div",{className:"intent-footer",style:{marginTop:"0.75rem"},children:[r.jsx("button",{className:"btn btn-ghost",onClick:k,disabled:f||!j,children:"Revert"}),r.jsx("button",{className:"btn btn-primary",style:{flex:1},onClick:S,disabled:f||!j||N>b||c,children:f?"Saving…":"Save"})]})]}),r.jsx("button",{type:"button",className:"floating-help",onClick:()=>w(!0),"aria-label":"Open brief assistant",children:"Get help with brief"}),r.jsx(em,{open:y,onClose:()=>w(!1),ariaLabel:"Brief assistant",children:r.jsx(ki,{target:{kind:"context"},currentText:t,onApply:R=>{t.trim()&&!confirm("Replace the current context with the applied draft?")||(s(R),w(!1))},greeting:"Tell me what your agent should know — I'll help shape your standing orders.",placeholder:"Ask for help with your brief…"})})]})]})}function vS(t){const s=/<h1[^>]*>([\s\S]*?)<\/h1>/i.exec(t);return s&&s[1].replace(/<[^>]+>/g,"").trim()||"Report"}function xS(t){const s=t.find(c=>{var u;return c.kind==="sv-mandate"&&c.status!=="unverifiable"&&typeof((u=c.data)==null?void 0:u.profile)=="string"});if(!s)return null;const a=s.data;if(typeof a.profileLabel=="string"&&a.profileLabel)return a.profileLabel;const o=a.profile.split("@")[0].split("/").pop();return o?o.charAt(0).toUpperCase()+o.slice(1):null}function wS(t){return new Date(t*1e3).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function jS(t,s){const a=s.emailExportError?"cases unknown":`${s.coveredCases.length}/${s.loadedCases.length} cases`;return`${t.signaturesValid>0?`${t.signaturesValid} ✓ tickets`:`${t.signaturesValid} tickets`} · ${a} · ${s.ticketsReferenced.length}/${s.ticketsInPeriod.length} tickets covered`}function SS(t){return t.emailExportError?{kind:"error",text:"Cases: unknown — the email simulator could not be read.",detail:t.emailExportError}:{kind:"ok",text:`${t.coveredCases.length} of ${t.loadedCases.length}`}}function bS(t){return t.periodStart!==null?null:t.emailExportError?{text:"Test period start unknown — the email simulator could not be read. All saved tickets were counted.",detail:t.emailExportError}:{text:"Test period start unknown — all saved tickets were counted."}}function oh(t,s="none in this report"){return t>0?{kind:"ok",text:`${t} ✓`}:{kind:"neutral",text:s}}function kS(t){return/Labels?$/.test(t)||t==="limits"||t==="fields"}function NS(t,s){const a=s[t];return a==null||a===""||kS(t)?null:typeof a=="object"?JSON.stringify(a):String(a)}function CS(t){const s=[];return t.missingCases.length>0&&s.push(`cases ${t.missingCases.join(", ")}`),t.ticketsNotReferenced.length>0&&s.push(`${t.ticketsNotReferenced.length} ticket${t.ticketsNotReferenced.length===1?"":"s"}`),s.length>0?`Not in the report: ${s.join(" · ")}`:null}function ES(t,s){var a;if(s)return s;if(!t)return null;if(t.kind==="sv-ticket")return t.attrs.ref||null;if(t.kind==="sv-approval"||t.kind==="sv-mandate")return t.attrs.ticket||null;if(t.kind==="sv-case"){const o=(a=t.data)==null?void 0:a.goal;return(o==null?void 0:o.ticketId)??null}return null}const TS="allow-popups allow-popups-to-escape-sandbox",RS="AI analysis — not verified",AS="Green = verified by the gateway — raw signed fields only",IS="Grey dashed = the AI's own analysis, not verified",PS="= translation by the AI, not verified",_S="Übersetzung anzeigen / show translation";function lh(t){var a;const s=((a=t.formatNotice)==null?void 0:a.blocksNotShown)??0;return s<=0?null:`This report was written in an older format — ${s} ${s===1?"block was":"blocks were"} not shown. Ask the AI to write it again.`}function $S(t,s){return s&&t.renderedHtmlGloss?t.renderedHtmlGloss:t.renderedHtml}function LS(t,s,a){const o=new URLSearchParams(t);return o.set("element",s),a?o.set("ticket",a):o.delete("ticket"),o}const zS={"sv-ticket":"Action","sv-approval":"Approval","sv-mandate":"Mandate","sv-record":"Record","sv-case":"Case","sv-metric":"Figure"};function FS(t){return t.filter(s=>s.status==="unverifiable").map(s=>({elementId:s.id,text:`${zS[s.kind]??"Element"}: ${s.reason??"could not be checked"}`}))}function OS(t){if(!t||t.kind!=="sv-case"||!t.data)return[];const s=Array.isArray(t.data.steps)?t.data.steps:[],a=t.data.goal,o=[...s.map(c=>({n:c,isGoal:!1})),...a?[{n:a,isGoal:!0}]:[]].filter(c=>typeof c.n.ticketId=="string"&&c.n.ticketId);return o.sort((c,u)=>(c.n.time??0)-(u.n.time??0)),o.map(({n:c,isGoal:u})=>({ticketId:c.ticketId,label:String(c.action??c.ticketId),isGoal:u}))}function MS(t){return`<!doctype html><html><head><meta charset="utf-8"><meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; img-src data:;"><style>body{margin:12px;background:#fff}</style></head><body>${t}</body></html>`}const Cc={display:"grid",gridTemplateColumns:"auto 1fr",gap:"0.25rem 1rem",margin:0,fontSize:"0.85rem"},BS={Ticket:["ticketId","action","time","authorizationId","limitsUsed"],Mandate:["authorizationId","profile","rawLimits","ownersRaw"],Approval:["ticketId","who","createdAt","decidedAt","waitSeconds","status"]};function DS(t,s){return Array.isArray(s.fields)?s.fields.map(o=>({label:o.key,value:o.value})):{Ticket:["action","profile","time"],Mandate:["profile","mode","owners","intent"],Approval:["createdAt","decidedAt","whoLabel","status","waitSeconds"]}[t].filter(o=>s[o]!==void 0&&s[o]!==null).map(o=>({label:o,value:typeof s[o]=="object"?JSON.stringify(s[o]):String(s[o])}))}function US(t,s){const a=BS[t].filter(o=>s[o]!==void 0);return a.length===0?null:r.jsxs("details",{style:{marginTop:"0.5rem"},children:[r.jsx("summary",{style:{cursor:"pointer",fontSize:"0.8rem",color:"var(--text-muted)"},children:"Technical details"}),r.jsx("dl",{style:{...Cc,marginTop:"0.5rem"},children:a.map(o=>r.jsxs("div",{style:{display:"contents"},children:[r.jsx("dt",{style:{color:"var(--text-muted)"},children:o}),r.jsx("dd",{style:{margin:0,wordBreak:"break-word"},children:typeof s[o]=="object"?JSON.stringify(s[o]):String(s[o])})]},o))})]})}function Ol(t,s){return s?r.jsxs("div",{className:"card",style:{marginTop:"0.75rem"},children:[r.jsx("div",{className:"card-title",children:t}),s.status==="unverifiable"?r.jsxs("p",{className:"page-subtitle",children:["✗ not verifiable — ",s.reason??"no further detail."]}):r.jsxs(r.Fragment,{children:[r.jsx("dl",{style:Cc,children:DS(t,s.data??{}).map(({label:a,value:o})=>r.jsxs("div",{style:{display:"contents"},children:[r.jsx("dt",{style:{color:"var(--text-muted)"},children:a}),r.jsx("dd",{style:{margin:0,wordBreak:"break-word"},children:o})]},a))}),US(t,s.data??{})]})]}):null}function WS({report:t,elementId:s,ticketParam:a,onClose:o,onSelectTicket:c}){var w;const u=t.elements.find(j=>j.id===s),f=ES(u,a),g=f?t.ticketDetails[f]:void 0,p=OS(u),v=(w=t.proof.verifiedValues.find(j=>j.elementId===s))==null?void 0:w.summary,y=h.useRef(null);return h.useEffect(()=>{const j=y.current;if(!j||typeof j.getBoundingClientRect!="function")return;const N=j.getBoundingClientRect().top;(N<0||N>window.innerHeight-80)&&j.scrollIntoView({block:"start",behavior:"smooth"})},[s,a]),r.jsxs("div",{className:"card reports-detail",ref:y,children:[r.jsxs("div",{className:"card-header",children:[r.jsx("div",{className:"card-title",children:"Details"}),r.jsx("button",{type:"button",className:"btn btn-ghost btn-sm",onClick:o,children:"Close"})]}),v&&r.jsx("p",{className:"page-subtitle",style:{marginTop:0},children:v}),p.length>0&&r.jsx("div",{className:"reports-case-steps",role:"group","aria-label":"Case steps",children:p.map(j=>r.jsxs("button",{type:"button",className:`btn btn-sm ${j.ticketId===f?"btn-secondary":"btn-ghost"}`,"aria-pressed":j.ticketId===f,onClick:()=>c(j.ticketId),children:[j.isGoal?"Goal: ":"",j.label]},j.ticketId))}),!u&&r.jsx("p",{className:"page-subtitle",children:"This element is no longer in the report."}),u&&!f&&(u.status==="unverifiable"?r.jsxs("p",{className:"page-subtitle",children:["✗ not verifiable — ",u.reason??"no further detail."]}):r.jsx("dl",{style:Cc,children:Object.keys(u.data??{}).map(j=>{const N=NS(j,u.data??{});return N===null?null:r.jsxs("div",{style:{display:"contents"},children:[r.jsx("dt",{style:{color:"var(--text-muted)"},children:j}),r.jsx("dd",{style:{margin:0,wordBreak:"break-word"},children:N})]},j)})})),g&&r.jsxs(r.Fragment,{children:[Ol("Ticket",g.ticket),Ol("Mandate",g.mandate),Ol("Approval",g.approval)]}),f&&!g&&r.jsxs("p",{className:"page-subtitle",children:["No local detail for ticket ",f,"."]})]})}async function HS(t){const{html:s,filename:a}=await t.exportReport();t.download(s,a),await t.refresh()}function ch({detail:t}){return t?r.jsxs("details",{style:{marginTop:"0.25rem"},children:[r.jsx("summary",{style:{cursor:"pointer",fontSize:"0.8rem",color:"var(--text-muted)"},children:"Technical detail"}),r.jsx("p",{className:"page-subtitle",style:{marginTop:"0.25rem",wordBreak:"break-word"},children:t})]}):null}function VS({report:t,open:s,selectedId:a,onOpenElement:o,detail:c}){const{proof:u,coverage:f}=t,g=FS(t.elements),p=CS(f),v=SS(f),y=bS(f),w=oh(u.signaturesValid),j=oh(u.recordsChecked);return r.jsxs("div",{className:`reports-side${s?" reports-side-open":""}`,children:[c,r.jsxs("div",{className:"card",children:[r.jsx("div",{className:"card-title",children:"Proof"}),r.jsxs("div",{className:"reports-row",children:[r.jsx("span",{children:"Tickets referenced"}),r.jsx("b",{children:u.ticketsReferenced.length})]}),r.jsxs("div",{className:"reports-row",children:[r.jsx("span",{children:"Signatures valid"}),r.jsx("b",{style:w.kind==="ok"?{color:"var(--success)"}:void 0,children:w.text})]}),r.jsxs("div",{className:"reports-row",children:[r.jsx("span",{children:"Records checked"}),r.jsx("b",{style:j.kind==="ok"?{color:"var(--success)"}:void 0,children:j.text})]}),r.jsxs("div",{className:"reports-row",children:[r.jsx("span",{children:"Not verifiable"}),r.jsx("b",{children:u.unverifiableCount})]}),g.map(N=>r.jsxs("button",{type:"button",className:`reports-row reports-row-button reports-row-bad${a===N.elementId?" reports-row-selected":""}`,onClick:()=>o(N.elementId),children:[r.jsx("span",{children:N.text}),r.jsx("span",{"aria-hidden":"true",children:"›"})]},N.elementId))]}),r.jsxs("div",{className:"card",style:{marginTop:"0.75rem"},children:[r.jsx("div",{className:"card-title",children:"Coverage"}),v.kind==="error"?r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"reports-error",role:"alert",children:v.text}),r.jsx(ch,{detail:v.detail})]}):r.jsxs("div",{className:"reports-row",children:[r.jsx("span",{children:"Cases"}),r.jsx("b",{children:v.text})]}),r.jsxs("div",{className:"reports-row",children:[r.jsx("span",{children:"Tickets in test period"}),r.jsxs("b",{children:[f.ticketsReferenced.length," of ",f.ticketsInPeriod.length]})]}),y&&r.jsxs(r.Fragment,{children:[r.jsx("p",{className:y.detail?"reports-error":"reports-note",role:y.detail?"alert":void 0,children:y.text}),r.jsx(ch,{detail:y.detail})]}),p&&r.jsx("p",{className:"reports-missing",children:p})]}),u.verifiedValues.length>0&&r.jsxs("div",{className:"card reports-checked-values",style:{marginTop:"0.75rem"},children:[r.jsx("div",{className:"card-title",children:"Checked values"}),u.verifiedValues.map(N=>r.jsxs("button",{type:"button",className:`reports-row reports-row-button${a===N.elementId?" reports-row-selected":""}`,onClick:()=>o(N.elementId),title:"Show details",children:[r.jsx("span",{children:N.summary}),r.jsx("span",{"aria-hidden":"true",children:"›"})]},N.elementId))]})]})}function GS(){const[t,s]=h.useState(null),[a,o]=h.useState(!0),[c,u]=h.useState(null),[f,g]=h.useState(!1),[p,v]=h.useState(!1),[y,w]=h.useState(null),[j,N]=h.useState(!1),[b,S]=h.useState(!1),[k,T]=uc(),R=h.useCallback(()=>O.getReport().then(({report:F})=>s(F)).catch(F=>u(F instanceof Error?F.message:String(F))),[]),P=h.useCallback(()=>{o(!0),u(null),R().finally(()=>o(!1))},[R]);h.useEffect(()=>{P()},[P]);const A=h.useCallback(()=>{g(!0),O.recheckReport().then(({report:F})=>s(F)).catch(F=>u(F instanceof Error?F.message:String(F))).finally(()=>g(!1))},[]),B=h.useCallback(async()=>{v(!0),w(null);try{await HS({exportReport:()=>O.exportReportWithProof(),download:(F,re)=>{const Y=URL.createObjectURL(new Blob([F],{type:"text/html"})),se=document.createElement("a");se.href=Y,se.download=re,se.click(),URL.revokeObjectURL(Y)},refresh:R})}catch(F){w(F instanceof Error?F.message:String(F))}finally{v(!1)}},[R]),H=k.get("element"),G=k.get("ticket"),me=h.useCallback((F,re)=>{T(LS(k,F,re))},[k,T]),q=h.useCallback(()=>{const F=new URLSearchParams(k);F.delete("element"),F.delete("ticket"),T(F,{replace:!0})},[k,T]);if(a)return r.jsxs("div",{className:"page-inner",children:[r.jsx("div",{className:"page-header",children:r.jsx("h1",{className:"page-title",children:"Reports"})}),r.jsx("p",{className:"page-subtitle",children:"Loading…"})]});if(c)return r.jsxs("div",{className:"page-inner",children:[r.jsx("div",{className:"page-header",children:r.jsx("h1",{className:"page-title",children:"Reports"})}),r.jsx(Zr,{icon:"⚠",title:"Report unavailable",text:c})]});if(!t)return r.jsxs("div",{className:"page-inner",children:[r.jsx("div",{className:"page-header",children:r.jsx("h1",{className:"page-title",children:"Reports"})}),r.jsx(Zr,{icon:"▢",title:"No report yet",text:"No report yet — the AI writes it with the Reporting mandate."})]});const ce=vS(t.renderedHtml),ee=xS(t.elements);return r.jsx("div",{className:"page-inner reports-page",children:r.jsxs("div",{className:"reports-layout",children:[r.jsxs("div",{className:"reports-bar",children:[r.jsxs("div",{children:[r.jsx("h1",{className:"page-title",children:ce}),r.jsxs("p",{className:"page-subtitle",children:[ee?`written by the AI under mandate ${ee} · `:"","checked ",wS(t.checkedAt)]})]}),r.jsxs("div",{className:"reports-bar-actions",children:[r.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:A,disabled:f,children:f?"Checking…":"Check again"}),r.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:B,disabled:p,children:p?"Exporting…":"Export with proof"})]})]}),y&&r.jsxs("p",{className:"reports-error",role:"alert",style:{margin:"0.5rem 0 0 0"},children:["Export failed: ",y]}),r.jsxs("div",{className:"reports-summary-chip",children:[r.jsx("span",{children:jS(t.proof,t.coverage)}),r.jsx("button",{type:"button",className:"btn btn-ghost btn-sm",onClick:()=>N(F=>!F),children:j?"hide":"details"})]}),r.jsxs("div",{className:"reports-grid",children:[r.jsxs("div",{children:[r.jsxs("div",{className:"reports-legend",role:"note",children:[r.jsxs("span",{className:"reports-legend-chip",children:[r.jsx("span",{className:"reports-sw reports-sw-v"}),AS]}),r.jsxs("span",{className:"reports-legend-chip",children:[r.jsx("span",{className:"reports-sw reports-sw-a"}),IS," (“",RS,"”)"]}),t.renderedHtmlGloss&&r.jsxs("span",{className:"reports-legend-chip",children:[r.jsx("i",{className:"reports-gloss-swatch",children:"Abc"})," ",PS]})]}),lh(t)&&r.jsx("p",{className:"reports-error",role:"status",style:{margin:"0 0 0.5rem 0"},children:lh(t)}),t.renderedHtmlGloss&&r.jsxs("label",{className:"reports-gloss-switch",children:[r.jsx("input",{type:"checkbox",role:"switch",checked:b,onChange:F=>S(F.target.checked)}),r.jsx("span",{className:"reports-gloss-track","aria-hidden":"true",children:r.jsx("span",{className:"reports-gloss-thumb"})}),r.jsx("span",{children:_S})]}),r.jsx("p",{className:"form-hint",style:{marginBottom:"0.5rem"},children:"Written by the AI, rendered without scripts or network access. Scroll inside the report — the gateway does not auto-resize the frame. Click a checked value to see its details."}),r.jsx("iframe",{title:"Report",sandbox:TS,srcDoc:MS($S(t,b)),className:"reports-iframe"})]}),r.jsx(VS,{report:t,open:j||!!H,selectedId:H,onOpenElement:F=>me(F),detail:H?r.jsx(WS,{report:t,elementId:H,ticketParam:G,onClose:q,onSelectTicket:F=>me(H,F)}):void 0})]})]})})}function Qr({to:t}){const{search:s,hash:a}=Ut();return r.jsx(Pn,{to:`${t}${s}${a}`,replace:!0})}function KS({children:t}){const{user:s,mode:a,domain:o}=mt();return s?a==="team"&&!o?r.jsx(Pn,{to:"/onboarding",replace:!0}):r.jsx(r.Fragment,{children:t}):r.jsx(Pn,{to:"/login",replace:!0})}function qS(){const{user:t,handleSessionLocked:s,refreshGroups:a}=mt();return De("session-locked",o=>{const c=o==null?void 0:o.message;s(c)}),De("team-membership-changed",()=>{a()}),r.jsxs(Wy,{children:[r.jsx(et,{path:"/login",element:t?r.jsx(Pn,{to:"/",replace:!0}):r.jsx(Bx,{})}),r.jsx(et,{path:"/onboarding",element:t?r.jsx(Gx,{}):r.jsx(Pn,{to:"/login",replace:!0})}),r.jsxs(et,{element:r.jsx(KS,{children:r.jsx(Mx,{})}),children:[r.jsx(et,{path:"/",element:r.jsx(o0,{})}),r.jsx(et,{path:"/mandates",element:r.jsx(Ew,{})}),r.jsx(et,{path:"/mandates/new/intent",element:r.jsx($0,{})}),r.jsx(et,{path:"/mandates/new/sign",element:r.jsx(X0,{})}),r.jsx(et,{path:"/integrations",element:r.jsx(aw,{})}),r.jsx(et,{path:"/team",element:r.jsx(iw,{})}),r.jsx(et,{path:"/tickets",element:r.jsx(Ij,{})}),r.jsx(et,{path:"/blocked",element:r.jsx(Pj,{})}),r.jsx(et,{path:"/approvals",element:r.jsx(hS,{})}),r.jsx(et,{path:"/reports",element:r.jsx(GS,{})}),r.jsx(et,{path:"/agent/new",element:r.jsx(Pn,{to:"/mandates?new=1",replace:!0})}),r.jsx(et,{path:"/agent/gate",element:r.jsx(Qr,{to:"/mandates/new/intent"})}),r.jsx(et,{path:"/agent/review",element:r.jsx(Qr,{to:"/mandates/new/sign"})}),r.jsx(et,{path:"/authorizations",element:r.jsx(Qr,{to:"/mandates"})}),r.jsx(et,{path:"/groups",element:r.jsx(Qr,{to:"/team"})}),r.jsx(et,{path:"/audit",element:r.jsx(Qr,{to:"/tickets"})}),r.jsx(et,{path:"/proposals",element:r.jsx(Qr,{to:"/approvals"})}),r.jsx(et,{path:"/agent-brief",element:r.jsx(yS,{})}),r.jsx(et,{path:"/settings",element:r.jsx(Uj,{})}),r.jsx(et,{path:"/settings/services",element:r.jsx(Pn,{to:"/settings",replace:!0})}),r.jsx(et,{path:"/deploy",element:r.jsx(Pn,{to:"/integrations",replace:!0})})]}),r.jsx(et,{path:"*",element:r.jsx(Pn,{to:"/",replace:!0})})]})}function YS(){return r.jsx(mv,{children:r.jsx(Av,{children:r.jsx(_v,{children:r.jsx(qS,{})})})})}Bg.createRoot(document.getElementById("root")).render(r.jsx(h.StrictMode,{children:r.jsx(YS,{})}));