vendor: 20,451 bytes, lines 1-3
1var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,a)=>(a=n==null?{}:e(i(n)),s(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var l=o((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.portal`),r=Symbol.for(`react.fragment`),i=Symbol.for(`react.strict_mode`),a=Symbol.for(`react.profiler`),o=Symbol.for(`react.consumer`),s=Symbol.for(`react.context`),c=Symbol.for(`react.forward_ref`),l=Symbol.for(`react.suspense`),u=Symbol.for(`react.memo`),d=Symbol.for(`react.lazy`),f=Symbol.for(`react.activity`),p=Symbol.iterator;function m(e){return typeof e!=`object`||!e?null:(e=p&&e[p]||e[`@@iterator`],typeof e==`function`?e:null)}var h={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},g=Object.assign,_={};function v(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}v.prototype.isReactComponent={},v.prototype.setState=function(e,t){if(typeof e!=`object`&&typeof e!=`function`&&e!=null)throw Error(`takes an object of state variables to update or a function which returns an object of state variables.`);this.updater.enqueueSetState(this,e,t,`setState`)},v.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,`forceUpdate`)};function y(){}y.prototype=v.prototype;function b(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}var x=b.prototype=new y;x.constructor=b,g(x,v.prototype),x.isPureReactComponent=!0;var S=Array.isArray;function C(){}var w={H:null,A:null,T:null,S:null},T=Object.prototype.hasOwnProperty;function E(e,n,r){var i=r.ref;return{$$typeof:t,type:e,key:n,ref:i===void 0?null:i,props:r}}function D(e,t){return E(e.type,t,e.props)}function O(e){return typeof e==`object`&&!!e&&e.$$typeof===t}function k(e){var t={"=":`=0`,":":`=2`};return`$`+e.replace(/[=:]/g,function(e){return t[e]})}var A=/\/+/g;function j(e,t){return typeof e==`object`&&e&&e.key!=null?k(``+e.key):t.toString(36)}function M(e){switch(e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason;default:switch(typeof e.status==`string`?e.then(C,C):(e.status=`pending`,e.then(function(t){e.status===`pending`&&(e.status=`fulfilled`,e.value=t)},function(t){e.status===`pending`&&(e.status=`rejected`,e.reason=t)})),e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason}}throw e}function ee(e,r,i,a,o){var s=typeof e;(s===`undefined`||s===`boolean`)&&(e=null);var c=!1;if(e===null)c=!0;else switch(s){case`bigint`:case`string`:case`number`:c=!0;break;case`object`:switch(e.$$typeof){case t:case n:c=!0;break;case d:return c=e._init,ee(c(e._payload),r,i,a,o)}}if(c)return o=o(e),c=a===``?`.`+j(e,0):a,S(o)?(i=``,c!=null&&(i=c.replace(A,`$&/`)+`/`),ee(o,r,i,``,function(e){return e})):o!=null&&(O(o)&&(o=D(o,i+(o.key==null||e&&e.key===o.key?``:(``+o.key).replace(A,`$&/`)+`/`)+c)),r.push(o)),1;c=0;var l=a===``?`.`:a+`:`;if(S(e))for(var u=0;u<e.length;u++)a=e[u],s=l+j(a,u),c+=ee(a,r,i,s,o);else if(u=m(e),typeof u==`function`)for(e=u.call(e),u=0;!(a=e.next()).done;)a=a.value,s=l+j(a,u++),c+=ee(a,r,i,s,o);else if(s===`object`){if(typeof e.then==`function`)return ee(M(e),r,i,a,o);throw r=String(e),Error(`Objects are not valid as a React child (found: `+(r===`[object Object]`?`object with keys {`+Object.keys(e).join(`, `)+`}`:r)+`). If you meant to render a collection of children, use an array instead.`)}return c}function N(e,t,n){if(e==null)return e;var r=[],i=0;return ee(e,r,``,``,function(e){return t.call(n,e,i++)}),r}function P(e){if(e._status===-1){var t=e._result;t=t(),t.then(function(t){(e._status===0||e._status===-1)&&(e._status=1,e._result=t)},function(t){(e._status===0||e._status===-1)&&(e._status=2,e._result=t)}),e._status===-1&&(e._status=0,e._result=t)}if(e._status===1)return e._result.default;throw e._result}var F=typeof reportError==`function`?reportError:function(e){if(typeof window==`object`&&typeof window.ErrorEvent==`function`){var t=new window.ErrorEvent(`error`,{bubbles:!0,cancelable:!0,message:typeof e==`object`&&e&&typeof e.message==`string`?String(e.message):String(e),error:e});if(!window.dispatchEvent(t))return}else if(typeof process==`object`&&typeof process.emit==`function`){process.emit(`uncaughtException`,e);return}console.error(e)},I={map:N,forEach:function(e,t,n){N(e,function(){t.apply(this,arguments)},n)},count:function(e){var t=0;return N(e,function(){t++}),t},toArray:function(e){return N(e,function(e){return e})||[]},only:function(e){if(!O(e))throw Error(`React.Children.only expected to receive a single React element child.`);return e}};e.Activity=f,e.Children=I,e.Component=v,e.Fragment=r,e.Profiler=a,e.PureComponent=b,e.StrictMode=i,e.Suspense=l,e.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=w,e.__COMPILER_RUNTIME={__proto__:null,c:function(e){return w.H.useMemoCache(e)}},e.cache=function(e){return function(){return e.apply(null,arguments)}},e.cacheSignal=function(){return null},e.cloneElement=function(e,t,n){if(e==null)throw Error(`The argument must be a React element, but you passed `+e+`.`);var r=g({},e.props),i=e.key;if(t!=null)for(a in t.key!==void 0&&(i=``+t.key),t)!T.call(t,a)||a===`key`||a===`__self`||a===`__source`||a===`ref`&&t.ref===void 0||(r[a]=t[a]);var a=arguments.length-2;if(a===1)r.children=n;else if(1<a){for(var o=Array(a),s=0;s<a;s++)o[s]=arguments[s+2];r.children=o}return E(e.type,i,r)},e.createContext=function(e){return e={$$typeof:s,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null},e.Provider=e,e.Consumer={$$typeof:o,_context:e},e},e.createElement=function(e,t,n){var r,i={},a=null;if(t!=null)for(r in t.key!==void 0&&(a=``+t.key),t)T.call(t,r)&&r!==`key`&&r!==`__self`&&r!==`__source`&&(i[r]=t[r]);var o=arguments.length-2;if(o===1)i.children=n;else if(1<o){for(var s=Array(o),c=0;c<o;c++)s[c]=arguments[c+2];i.children=s}if(e&&e.defaultProps)for(r in o=e.defaultProps,o)i[r]===void 0&&(i[r]=o[r]);return E(e,a,i)},e.createRef=function(){return{current:null}},e.forwardRef=function(e){return{$$typeof:c,render:e}},e.isValidElement=O,e.lazy=function(e){return{$$typeof:d,_payload:{_status:-1,_result:e},_init:P}},e.memo=function(e,t){return{$$typeof:u,type:e,compare:t===void 0?null:t}},e.startTransition=function(e){var t=w.T,n={};w.T=n;try{var r=e(),i=w.S;i!==null&&i(n,r),typeof r==`object`&&r&&typeof r.then==`function`&&r.then(C,F)}catch(e){F(e)}finally{t!==null&&n.types!==null&&(t.types=n.types),w.T=t}},e.unstable_useCacheRefresh=function(){return w.H.useCacheRefresh()},e.use=function(e){return w.H.use(e)},e.useActionState=function(e,t,n){return w.H.useActionState(e,t,n)},e.useCallback=function(e,t){return w.H.useCallback(e,t)},e.useContext=function(e){return w.H.useContext(e)},e.useDebugValue=function(){},e.useDeferredValue=function(e,t){return w.H.useDeferredValue(e,t)},e.useEffect=function(e,t){return w.H.useEffect(e,t)},e.useEffectEvent=function(e){return w.H.useEffectEvent(e)},e.useId=function(){return w.H.useId()},e.useImperativeHandle=function(e,t,n){return w.H.useImperativeHandle(e,t,n)},e.useInsertionEffect=function(e,t){return w.H.useInsertionEffect(e,t)},e.useLayoutEffect=function(e,t){return w.H.useLayoutEffect(e,t)},e.useMemo=function(e,t){return w.H.useMemo(e,t)},e.useOptimistic=function(e,t){return w.H.useOptimistic(e,t)},e.useReducer=function(e,t,n){return w.H.useReducer(e,t,n)},e.useRef=function(e){return w.H.useRef(e)},e.useState=function(e){return w.H.useState(e)},e.useSyncExternalStore=function(e,t,n){return w.H.useSyncExternalStore(e,t,n)},e.useTransition=function(){return w.H.useTransition()},e.version=`19.2.4`})),u=o(((e,t)=>{t.exports=l()})),d=o((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0<n;){var r=n-1>>>1,a=e[r];if(0<i(a,t))e[r]=t,e[n]=a,n=r;else break a}}function n(e){return e.length===0?null:e[0]}function r(e){if(e.length===0)return null;var t=e[0],n=e.pop();if(n!==t){e[0]=n;a:for(var r=0,a=e.length,o=a>>>1;r<o;){var s=2*(r+1)-1,c=e[s],l=s+1,u=e[l];if(0>i(c,n))l<a&&0>i(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(l<a&&0>i(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m)if(n(c)!==null)m=!0,S||(S=!0,O());else{var t=n(l);t!==null&&j(x,t.startTime-e)}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-T<w)}function D(){if(g=!1,S){var t=e.unstable_now();T=t;var i=!0;try{a:{m=!1,h&&(h=!1,v(C),C=-1),p=!0;var a=f;try{b:{for(b(t),d=n(c);d!==null&&!(d.expirationTime>t&&E());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&j(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}i=void 0}}finally{i?O():S=!1}}}var O;if(typeof y==`function`)O=function(){y(D)};else if(typeof MessageChannel<`u`){var k=new MessageChannel,A=k.port2;k.port1.onmessage=D,O=function(){A.postMessage(null)}}else O=function(){_(D,0)};function j(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125<e?console.error(`forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported`):w=0<e?Math.floor(1e3/e):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var n=f;f=t;try{return e()}finally{f=n}},e.unstable_requestPaint=function(){g=!0},e.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var n=f;f=e;try{return t()}finally{f=n}},e.unstable_scheduleCallback=function(r,i,a){var o=e.unstable_now();switch(typeof a==`object`&&a?(a=a.delay,a=typeof a==`number`&&0<a?o+a:o):a=o,r){case 1:var s=-1;break;case 2:s=250;break;case 5:s=1073741823;break;case 4:s=1e4;break;default:s=5e3}return s=a+s,r={id:u++,callback:i,priorityLevel:r,startTime:a,expirationTime:s,sortIndex:-1},a>o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,j(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,O()))),r},e.unstable_shouldYield=E,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),f=o(((e,t)=>{t.exports=d()})),p=o((e=>{var t=u();function n(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function r(){}var i={d:{f:r,r:function(){throw Error(n(522))},D:r,C:r,L:r,m:r,X:r,S:r,M:r},p:0,findDOMNode:null},a=Symbol.for(`react.portal`);function o(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:a,key:r==null?null:``+r,children:e,containerInfo:t,implementation:n}}var s=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function c(e,t){if(e===`font`)return``;if(typeof t==`string`)return t===`use-credentials`?t:``}e.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=i,e.createPortal=function(e,t){var r=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)throw Error(n(299));return o(e,t,null,r)},e.flushSync=function(e){var t=s.T,n=i.p;try{if(s.T=null,i.p=2,e)return e()}finally{s.T=t,i.p=n,i.d.f()}},e.preconnect=function(e,t){typeof e==`string`&&(t?(t=t.crossOrigin,t=typeof t==`string`?t===`use-credentials`?t:``:void 0):t=null,i.d.C(e,t))},e.prefetchDNS=function(e){typeof e==`string`&&i.d.D(e)},e.preinit=function(e,t){if(typeof e==`string`&&t&&typeof t.as==`string`){var n=t.as,r=c(n,t.crossOrigin),a=typeof t.integrity==`string`?t.integrity:void 0,o=typeof t.fetchPriority==`string`?t.fetchPriority:void 0;n===`style`?i.d.S(e,typeof t.precedence==`string`?t.precedence:void 0,{crossOrigin:r,integrity:a,fetchPriority:o}):n===`script`&&i.d.X(e,{crossOrigin:r,integrity:a,fetchPriority:o,nonce:typeof t.nonce==`string`?t.nonce:void 0})}},e.preinitModule=function(e,t){if(typeof e==`string`)if(typeof t==`object`&&t){if(t.as==null||t.as===`script`){var n=c(t.as,t.crossOrigin);i.d.M(e,{crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0})}}else t??i.d.M(e)},e.preload=function(e,t){if(typeof e==`string`&&typeof t==`object`&&t&&typeof t.as==`string`){var n=t.as,r=c(n,t.crossOrigin);i.d.L(e,n,{crossOrigin:r,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,type:typeof t.type==`string`?t.type:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0,referrerPolicy:typeof t.referrerPolicy==`string`?t.referrerPolicy:void 0,imageSrcSet:typeof t.imageSrcSet==`string`?t.imageSrcSet:void 0,imageSizes:typeof t.imageSizes==`string`?t.imageSizes:void 0,media:typeof t.media==`string`?t.media:void 0})}},e.preloadModule=function(e,t){if(typeof e==`string`)if(t){var n=c(t.as,t.crossOrigin);i.d.m(e,{as:typeof t.as==`string`&&t.as!==`script`?t.as:void 0,crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0})}else i.d.m(e)},e.requestFormReset=function(e){i.d.r(e)},e.unstable_batchedUpdates=function(e,t){return e(t)},e.useFormState=function(e,t,n){return s.H.useFormState(e,t,n)},e.useFormStatus=function(){return s.H.useHostTransitionStatus()},e.version=`19.2.4`})),m=o(((e,t)=>{function n(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>`u`||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!=`function`))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=p()})),h=o((e=>{var t=f(),n=u(),r=m();function i(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function a(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function o(e){var t=e,n=e;if(e.alternate)for(;t.return;)t=t.return;else{e=t;do t=e,t.flags&4098&&(n=t.return),e=t.return;while(e)}return t.tag===3?n:null}function s(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function c(e){if(e.tag===31){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function l(e){if(o(e)!==e)throw Error(i(188))}function d(e){var t=e.alternate;if(!t){if(t=o(e),t===null)throw Error(i(188));return t===e?e:null}for(var n=e,r=t;;){var a=n.return;if(a===null)break;var s=a.alternate;if(s===null){if(r=a.return,r!==null){n=r;continue}break}if(a.child===s.child){for(s=a.child;s;){if(s===n)return l(a),e;if(s===r)return l(a),t;s=s.sibling}throw Error(i(188))}if(n.return!==r.return)n=a,r=s;else{for(var c=!1,u=a.child;u;){if(u===n){c=!0,n=a,r=s;break}if(u===r){c=!0,r=a,n=s;break}u=u.sibling}if(!c){for(u=s.child;u;){if(u===n){c=!0,n=s,r=a;break}if(u===r){c=!0,r=s,n=a;break}u=u.sibling}if(!c)throw Error(i(189))}}if(n.alternate!==r)throw Error(i(190))}if(n.tag!==3)throw Error(i(188));return n.stateNode.current===n?e:t}function p(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=p(e),t!==null)return t;e=e.sibling}return null}var h=Object.assign,g=Symbol.for(`react.element`),_=Symbol.for(`react.transitional.element`),v=Symbol.for(`react.portal`),y=Symbol.for(`react.fragment`),b=Symbol.for(`react.strict_mode`),x=Symbol.for(`react.profiler`),S=Symbol.for(`react.consumer`),C=Symbol.for(`react.context`),w=Symbol.for(`react.forward_ref`),T=Symbol.for(`react.suspense`),E=Symbol.for(`react.suspense_list`),D=Symbol.for(`react.memo`),O=Symbol.for(`react.lazy`),k=Symbol.for(`react.activity`),A=Symbol.for(`react.memo_cache_sentinel`),j=Symbol.iterator;function M(e){return typeof e!=`object`||!e?null:(e=j&&e[j]||e[`@@iterator`],typeof e==`function`?e:null)}var ee=Symbol.for(`react.client.reference`);function N(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===ee?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case y:return`Fragment`;case x:return`Profiler`;case b:return`StrictMode`;case T:return`Suspense`;case E:return`SuspenseList`;case k:return`Activity`}if(typeof e==`object`)switch(e.$$typeof){case v:return`Portal`;case C:return e.displayName||`Context`;case S:return(e._context.displayName||`Context`)+`.Consumer`;case w:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case D:return t=e.displayName||null,t===null?N(e.type)||`Memo`:t;case O:t=e._payload,e=e._init;try{return N(e(t))}catch{}}return null}var P=Array.isArray,F=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,I=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,te={pending:!1,data:null,method:null,action:null},ne=[],re=-1;function ie(e){return{current:e}}function ae(e){0>re||(e.current=ne[re],ne[re]=null,re--)}function oe(e,t){re++,ne[re]=e.current,e.current=t}var se=ie(null),ce=ie(null),le=ie(null),ue=ie(null);function de(e,t){switch(oe(le,t),oe(ce,e),oe(se,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?ef(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=ef(t),e=tf(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}ae(se),oe(se,e)}function fe(){ae(se),ae(ce),ae(le)}function pe(e){e.memoizedState!==null&&oe(ue,e);var t=se.current,n=tf(t,e.type);t!==n&&(oe(ce,e),oe(se,n))}function me(e){ce.current===e&&(ae(se),ae(ce)),ue.current===e&&(ae(ue),dp._currentValue=te)}var he,ge;function _e(e){if(he===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);he=t&&t[1]||``,ge=-1<e.stack.indexOf(` 2 at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return` 3`+he+e+ge}var ve=!1;function ye(e,t){if(!e||ve)return``;ve=!0;var n=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var r={DetermineComponentFrameRoot:function(){try{if(t){var n=function(){throw Error()};if(Object.defineProperty(n.prototype,`props`,{set:function(){throw Error()}}),typeof Reflect==`object`&&Reflect.construct){try{Reflect.construct(n,[])}catch(e){var r=e}Reflect.construct(e,[],n)}
vendor: 98,286 bytes, lines 3-8
3else{try{n.call()}catch(e){r=e}e.call(n.prototype)}}else{try{throw Error()}catch(e){r=e}(n=e())&&typeof n.catch==`function`&&n.catch(function(){})}}catch(e){if(e&&r&&typeof e.stack==`string`)return[e.stack,r.stack]}return[null,null]}};r.DetermineComponentFrameRoot.displayName=`DetermineComponentFrameRoot`;var i=Object.getOwnPropertyDescriptor(r.DetermineComponentFrameRoot,`name`);i&&i.configurable&&Object.defineProperty(r.DetermineComponentFrameRoot,`name`,{value:`DetermineComponentFrameRoot`});var a=r.DetermineComponentFrameRoot(),o=a[0],s=a[1];if(o&&s){var c=o.split(` 4`),l=s.split(` 5`);for(i=r=0;r<c.length&&!c[r].includes(`DetermineComponentFrameRoot`);)r++;for(;i<l.length&&!l[i].includes(`DetermineComponentFrameRoot`);)i++;if(r===c.length||i===l.length)for(r=c.length-1,i=l.length-1;1<=r&&0<=i&&c[r]!==l[i];)i--;for(;1<=r&&0<=i;r--,i--)if(c[r]!==l[i]){if(r!==1||i!==1)do if(r--,i--,0>i||c[r]!==l[i]){var u=` 6`+c[r].replace(` at new `,` at `);return e.displayName&&u.includes(`<anonymous>`)&&(u=u.replace(`<anonymous>`,e.displayName)),u}while(1<=r&&0<=i);break}}}finally{ve=!1,Error.prepareStackTrace=n}return(n=e?e.displayName||e.name:``)?_e(n):``}function be(e,t){switch(e.tag){case 26:case 27:case 5:return _e(e.type);case 16:return _e(`Lazy`);case 13:return e.child!==t&&t!==null?_e(`Suspense Fallback`):_e(`Suspense`);case 19:return _e(`SuspenseList`);case 0:case 15:return ye(e.type,!1);case 11:return ye(e.type.render,!1);case 1:return ye(e.type,!0);case 31:return _e(`Activity`);default:return``}}function xe(e){try{var t=``,n=null;do t+=be(e,n),n=e,e=e.return;while(e);return t}catch(e){return` 7Error generating stack: `+e.message+` 8`+e.stack}}var Se=Object.prototype.hasOwnProperty,Ce=t.unstable_scheduleCallback,we=t.unstable_cancelCallback,Te=t.unstable_shouldYield,Ee=t.unstable_requestPaint,De=t.unstable_now,Oe=t.unstable_getCurrentPriorityLevel,ke=t.unstable_ImmediatePriority,Ae=t.unstable_UserBlockingPriority,je=t.unstable_NormalPriority,Me=t.unstable_LowPriority,Ne=t.unstable_IdlePriority,Pe=t.log,Fe=t.unstable_setDisableYieldValue,Ie=null,Le=null;function Re(e){if(typeof Pe==`function`&&Fe(e),Le&&typeof Le.setStrictMode==`function`)try{Le.setStrictMode(Ie,e)}catch{}}var ze=Math.clz32?Math.clz32:He,Be=Math.log,Ve=Math.LN2;function He(e){return e>>>=0,e===0?32:31-(Be(e)/Ve|0)|0}var Ue=256,We=262144,Ge=4194304;function Ke(e){var t=e&42;if(t!==0)return t;switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:return 64;case 128:return 128;case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:return e&261888;case 262144:case 524288:case 1048576:case 2097152:return e&3932160;case 4194304:case 8388608:case 16777216:case 33554432:return e&62914560;case 67108864:return 67108864;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 0;default:return e}}function qe(e,t,n){var r=e.pendingLanes;if(r===0)return 0;var i=0,a=e.suspendedLanes,o=e.pingedLanes;e=e.warmLanes;var s=r&134217727;return s===0?(s=r&~a,s===0?o===0?n||(n=r&~e,n!==0&&(i=Ke(n))):i=Ke(o):i=Ke(s)):(r=s&~a,r===0?(o&=s,o===0?n||(n=s&~e,n!==0&&(i=Ke(n))):i=Ke(o)):i=Ke(r)),i===0?0:t!==0&&t!==i&&(t&a)===0&&(a=i&-i,n=t&-t,a>=n||a===32&&n&4194048)?t:i}function Je(e,t){return(e.pendingLanes&~(e.suspendedLanes&~e.pingedLanes)&t)===0}function Ye(e,t){switch(e){case 1:case 2:case 4:case 8:case 64:return t+250;case 16:case 32:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return t+5e3;case 4194304:case 8388608:case 16777216:case 33554432:return-1;case 67108864:case 134217728:case 268435456:case 536870912:case 1073741824:return-1;default:return-1}}function Xe(){var e=Ge;return Ge<<=1,!(Ge&62914560)&&(Ge=4194304),e}function Ze(e){for(var t=[],n=0;31>n;n++)t.push(e);return t}function Qe(e,t){e.pendingLanes|=t,t!==268435456&&(e.suspendedLanes=0,e.pingedLanes=0,e.warmLanes=0)}function $e(e,t,n,r,i,a){var o=e.pendingLanes;e.pendingLanes=n,e.suspendedLanes=0,e.pingedLanes=0,e.warmLanes=0,e.expiredLanes&=n,e.entangledLanes&=n,e.errorRecoveryDisabledLanes&=n,e.shellSuspendCounter=0;var s=e.entanglements,c=e.expirationTimes,l=e.hiddenUpdates;for(n=o&~n;0<n;){var u=31-ze(n),d=1<<u;s[u]=0,c[u]=-1;var f=l[u];if(f!==null)for(l[u]=null,u=0;u<f.length;u++){var p=f[u];p!==null&&(p.lane&=-536870913)}n&=~d}r!==0&&et(e,r,0),a!==0&&i===0&&e.tag!==0&&(e.suspendedLanes|=a&~(o&~t))}function et(e,t,n){e.pendingLanes|=t,e.suspendedLanes&=~t;var r=31-ze(t);e.entangledLanes|=t,e.entanglements[r]=e.entanglements[r]|1073741824|n&261930}function tt(e,t){var n=e.entangledLanes|=t;for(e=e.entanglements;n;){var r=31-ze(n),i=1<<r;i&t|e[r]&t&&(e[r]|=t),n&=~i}}function nt(e,t){var n=t&-t;return n=n&42?1:rt(n),(n&(e.suspendedLanes|t))===0?n:0}function rt(e){switch(e){case 2:e=1;break;case 8:e=4;break;case 32:e=16;break;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:e=128;break;case 268435456:e=134217728;break;default:e=0}return e}function it(e){return e&=-e,2<e?8<e?e&134217727?32:268435456:8:2}function at(){var e=I.p;return e===0?(e=window.event,e===void 0?32:Dp(e.type)):e}function ot(e,t){var n=I.p;try{return I.p=e,t()}finally{I.p=n}}var st=Math.random().toString(36).slice(2),ct=`__reactFiber$`+st,lt=`__reactProps$`+st,ut=`__reactContainer$`+st,dt=`__reactEvents$`+st,ft=`__reactListeners$`+st,pt=`__reactHandles$`+st,mt=`__reactResources$`+st,ht=`__reactMarker$`+st;function gt(e){delete e[ct],delete e[lt],delete e[dt],delete e[ft],delete e[pt]}function _t(e){var t=e[ct];if(t)return t;for(var n=e.parentNode;n;){if(t=n[ut]||n[ct]){if(n=t.alternate,t.child!==null||n!==null&&n.child!==null)for(e=wf(e);e!==null;){if(n=e[ct])return n;e=wf(e)}return t}e=n,n=e.parentNode}return null}function vt(e){if(e=e[ct]||e[ut]){var t=e.tag;if(t===5||t===6||t===13||t===31||t===26||t===27||t===3)return e}return null}function yt(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e.stateNode;throw Error(i(33))}function bt(e){var t=e[mt];return t||=e[mt]={hoistableStyles:new Map,hoistableScripts:new Map},t}function xt(e){e[ht]=!0}var St=new Set,Ct={};function wt(e,t){Tt(e,t),Tt(e+`Capture`,t)}function Tt(e,t){for(Ct[e]=t,e=0;e<t.length;e++)St.add(t[e])}var Et=RegExp(`^[: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]*$`),Dt={},Ot={};function kt(e){return Se.call(Ot,e)?!0:Se.call(Dt,e)?!1:Et.test(e)?Ot[e]=!0:(Dt[e]=!0,!1)}function At(e,t,n){if(kt(t))if(n===null)e.removeAttribute(t);else{switch(typeof n){case`undefined`:case`function`:case`symbol`:e.removeAttribute(t);return;case`boolean`:var r=t.toLowerCase().slice(0,5);if(r!==`data-`&&r!==`aria-`){e.removeAttribute(t);return}}e.setAttribute(t,``+n)}}function jt(e,t,n){if(n===null)e.removeAttribute(t);else{switch(typeof n){case`undefined`:case`function`:case`symbol`:case`boolean`:e.removeAttribute(t);return}e.setAttribute(t,``+n)}}function Mt(e,t,n,r){if(r===null)e.removeAttribute(n);else{switch(typeof r){case`undefined`:case`function`:case`symbol`:case`boolean`:e.removeAttribute(n);return}e.setAttributeNS(t,n,``+r)}}function Nt(e){switch(typeof e){case`bigint`:case`boolean`:case`number`:case`string`:case`undefined`:return e;case`object`:return e;default:return``}}function Pt(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()===`input`&&(t===`checkbox`||t===`radio`)}function Ft(e,t,n){var r=Object.getOwnPropertyDescriptor(e.constructor.prototype,t);if(!e.hasOwnProperty(t)&&r!==void 0&&typeof r.get==`function`&&typeof r.set==`function`){var i=r.get,a=r.set;return Object.defineProperty(e,t,{configurable:!0,get:function(){return i.call(this)},set:function(e){n=``+e,a.call(this,e)}}),Object.defineProperty(e,t,{enumerable:r.enumerable}),{getValue:function(){return n},setValue:function(e){n=``+e},stopTracking:function(){e._valueTracker=null,delete e[t]}}}}function It(e){if(!e._valueTracker){var t=Pt(e)?`checked`:`value`;e._valueTracker=Ft(e,t,``+e[t])}}function Lt(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r=``;return e&&(r=Pt(e)?e.checked?`true`:`false`:e.value),e=r,e===n?!1:(t.setValue(e),!0)}function Rt(e){if(e||=typeof document<`u`?document:void 0,e===void 0)return null;try{return e.activeElement||e.body}catch{return e.body}}var zt=/[\n"\\]/g;function Bt(e){return e.replace(zt,function(e){return`\\`+e.charCodeAt(0).toString(16)+` `})}function Vt(e,t,n,r,i,a,o,s){e.name=``,o!=null&&typeof o!=`function`&&typeof o!=`symbol`&&typeof o!=`boolean`?e.type=o:e.removeAttribute(`type`),t==null?o!==`submit`&&o!==`reset`||e.removeAttribute(`value`):o===`number`?(t===0&&e.value===``||e.value!=t)&&(e.value=``+Nt(t)):e.value!==``+Nt(t)&&(e.value=``+Nt(t)),t==null?n==null?r!=null&&e.removeAttribute(`value`):Ut(e,o,Nt(n)):Ut(e,o,Nt(t)),i==null&&a!=null&&(e.defaultChecked=!!a),i!=null&&(e.checked=i&&typeof i!=`function`&&typeof i!=`symbol`),s!=null&&typeof s!=`function`&&typeof s!=`symbol`&&typeof s!=`boolean`?e.name=``+Nt(s):e.removeAttribute(`name`)}function Ht(e,t,n,r,i,a,o,s){if(a!=null&&typeof a!=`function`&&typeof a!=`symbol`&&typeof a!=`boolean`&&(e.type=a),t!=null||n!=null){if(!(a!==`submit`&&a!==`reset`||t!=null)){It(e);return}n=n==null?``:``+Nt(n),t=t==null?n:``+Nt(t),s||t===e.value||(e.value=t),e.defaultValue=t}r??=i,r=typeof r!=`function`&&typeof r!=`symbol`&&!!r,e.checked=s?e.checked:!!r,e.defaultChecked=!!r,o!=null&&typeof o!=`function`&&typeof o!=`symbol`&&typeof o!=`boolean`&&(e.name=o),It(e)}function Ut(e,t,n){t===`number`&&Rt(e.ownerDocument)===e||e.defaultValue===``+n||(e.defaultValue=``+n)}function Wt(e,t,n,r){if(e=e.options,t){t={};for(var i=0;i<n.length;i++)t[`$`+n[i]]=!0;for(n=0;n<e.length;n++)i=t.hasOwnProperty(`$`+e[n].value),e[n].selected!==i&&(e[n].selected=i),i&&r&&(e[n].defaultSelected=!0)}else{for(n=``+Nt(n),t=null,i=0;i<e.length;i++){if(e[i].value===n){e[i].selected=!0,r&&(e[i].defaultSelected=!0);return}t!==null||e[i].disabled||(t=e[i])}t!==null&&(t.selected=!0)}}function Gt(e,t,n){if(t!=null&&(t=``+Nt(t),t!==e.value&&(e.value=t),n==null)){e.defaultValue!==t&&(e.defaultValue=t);return}e.defaultValue=n==null?``:``+Nt(n)}function Kt(e,t,n,r){if(t==null){if(r!=null){if(n!=null)throw Error(i(92));if(P(r)){if(1<r.length)throw Error(i(93));r=r[0]}n=r}n??=``,t=n}n=Nt(t),e.defaultValue=n,r=e.textContent,r===n&&r!==``&&r!==null&&(e.value=r),It(e)}function qt(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var Jt=new Set(`animationIterationCount aspectRatio borderImageOutset borderImageSlice borderImageWidth boxFlex boxFlexGroup boxOrdinalGroup columnCount columns flex flexGrow flexPositive flexShrink flexNegative flexOrder gridArea gridRow gridRowEnd gridRowSpan gridRowStart gridColumn gridColumnEnd gridColumnSpan gridColumnStart fontWeight lineClamp lineHeight opacity order orphans scale tabSize widows zIndex zoom fillOpacity floodOpacity stopOpacity strokeDasharray strokeDashoffset strokeMiterlimit strokeOpacity strokeWidth MozAnimationIterationCount MozBoxFlex MozBoxFlexGroup MozLineClamp msAnimationIterationCount msFlex msZoom msFlexGrow msFlexNegative msFlexOrder msFlexPositive msFlexShrink msGridColumn msGridColumnSpan msGridRow msGridRowSpan WebkitAnimationIterationCount WebkitBoxFlex WebKitBoxFlexGroup WebkitBoxOrdinalGroup WebkitColumnCount WebkitColumns WebkitFlex WebkitFlexGrow WebkitFlexPositive WebkitFlexShrink WebkitLineClamp`.split(` `));function Yt(e,t,n){var r=t.indexOf(`--`)===0;n==null||typeof n==`boolean`||n===``?r?e.setProperty(t,``):t===`float`?e.cssFloat=``:e[t]=``:r?e.setProperty(t,n):typeof n!=`number`||n===0||Jt.has(t)?t===`float`?e.cssFloat=n:e[t]=(``+n).trim():e[t]=n+`px`}function Xt(e,t,n){if(t!=null&&typeof t!=`object`)throw Error(i(62));if(e=e.style,n!=null){for(var r in n)!n.hasOwnProperty(r)||t!=null&&t.hasOwnProperty(r)||(r.indexOf(`--`)===0?e.setProperty(r,``):r===`float`?e.cssFloat=``:e[r]=``);for(var a in t)r=t[a],t.hasOwnProperty(a)&&n[a]!==r&&Yt(e,a,r)}else for(var o in t)t.hasOwnProperty(o)&&Yt(e,o,t[o])}function Zt(e){if(e.indexOf(`-`)===-1)return!1;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 Qt=new Map([[`acceptCharset`,`accept-charset`],[`htmlFor`,`for`],[`httpEquiv`,`http-equiv`],[`crossOrigin`,`crossorigin`],[`accentHeight`,`accent-height`],[`alignmentBaseline`,`alignment-baseline`],[`arabicForm`,`arabic-form`],[`baselineShift`,`baseline-shift`],[`capHeight`,`cap-height`],[`clipPath`,`clip-path`],[`clipRule`,`clip-rule`],[`colorInterpolation`,`color-interpolation`],[`colorInterpolationFilters`,`color-interpolation-filters`],[`colorProfile`,`color-profile`],[`colorRendering`,`color-rendering`],[`dominantBaseline`,`dominant-baseline`],[`enableBackground`,`enable-background`],[`fillOpacity`,`fill-opacity`],[`fillRule`,`fill-rule`],[`floodColor`,`flood-color`],[`floodOpacity`,`flood-opacity`],[`fontFamily`,`font-family`],[`fontSize`,`font-size`],[`fontSizeAdjust`,`font-size-adjust`],[`fontStretch`,`font-stretch`],[`fontStyle`,`font-style`],[`fontVariant`,`font-variant`],[`fontWeight`,`font-weight`],[`glyphName`,`glyph-name`],[`glyphOrientationHorizontal`,`glyph-orientation-horizontal`],[`glyphOrientationVertical`,`glyph-orientation-vertical`],[`horizAdvX`,`horiz-adv-x`],[`horizOriginX`,`horiz-origin-x`],[`imageRendering`,`image-rendering`],[`letterSpacing`,`letter-spacing`],[`lightingColor`,`lighting-color`],[`markerEnd`,`marker-end`],[`markerMid`,`marker-mid`],[`markerStart`,`marker-start`],[`overlinePosition`,`overline-position`],[`overlineThickness`,`overline-thickness`],[`paintOrder`,`paint-order`],[`panose-1`,`panose-1`],[`pointerEvents`,`pointer-events`],[`renderingIntent`,`rendering-intent`],[`shapeRendering`,`shape-rendering`],[`stopColor`,`stop-color`],[`stopOpacity`,`stop-opacity`],[`strikethroughPosition`,`strikethrough-position`],[`strikethroughThickness`,`strikethrough-thickness`],[`strokeDasharray`,`stroke-dasharray`],[`strokeDashoffset`,`stroke-dashoffset`],[`strokeLinecap`,`stroke-linecap`],[`strokeLinejoin`,`stroke-linejoin`],[`strokeMiterlimit`,`stroke-miterlimit`],[`strokeOpacity`,`stroke-opacity`],[`strokeWidth`,`stroke-width`],[`textAnchor`,`text-anchor`],[`textDecoration`,`text-decoration`],[`textRendering`,`text-rendering`],[`transformOrigin`,`transform-origin`],[`underlinePosition`,`underline-position`],[`underlineThickness`,`underline-thickness`],[`unicodeBidi`,`unicode-bidi`],[`unicodeRange`,`unicode-range`],[`unitsPerEm`,`units-per-em`],[`vAlphabetic`,`v-alphabetic`],[`vHanging`,`v-hanging`],[`vIdeographic`,`v-ideographic`],[`vMathematical`,`v-mathematical`],[`vectorEffect`,`vector-effect`],[`vertAdvY`,`vert-adv-y`],[`vertOriginX`,`vert-origin-x`],[`vertOriginY`,`vert-origin-y`],[`wordSpacing`,`word-spacing`],[`writingMode`,`writing-mode`],[`xmlnsXlink`,`xmlns:xlink`],[`xHeight`,`x-height`]]),$t=/^[\u0000-\u001F ]*j[\r\n\t]*a[\r\n\t]*v[\r\n\t]*a[\r\n\t]*s[\r\n\t]*c[\r\n\t]*r[\r\n\t]*i[\r\n\t]*p[\r\n\t]*t[\r\n\t]*:/i;function en(e){return $t.test(``+e)?`javascript:throw new Error('React has blocked a javascript: URL as a security precaution.')`:e}function tn(){}var nn=null;function rn(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var an=null,on=null;function sn(e){var t=vt(e);if(t&&(e=t.stateNode)){var n=e[lt]||null;a:switch(e=t.stateNode,t.type){case`input`:if(Vt(e,n.value,n.defaultValue,n.defaultValue,n.checked,n.defaultChecked,n.type,n.name),t=n.name,n.type===`radio`&&t!=null){for(n=e;n.parentNode;)n=n.parentNode;for(n=n.querySelectorAll(`input[name="`+Bt(``+t)+`"][type="radio"]`),t=0;t<n.length;t++){var r=n[t];if(r!==e&&r.form===e.form){var a=r[lt]||null;if(!a)throw Error(i(90));Vt(r,a.value,a.defaultValue,a.defaultValue,a.checked,a.defaultChecked,a.type,a.name)}}for(t=0;t<n.length;t++)r=n[t],r.form===e.form&&Lt(r)}break a;case`textarea`:Gt(e,n.value,n.defaultValue);break a;case`select`:t=n.value,t!=null&&Wt(e,!!n.multiple,t,!1)}}}var cn=!1;function ln(e,t,n){if(cn)return e(t,n);cn=!0;try{return e(t)}finally{if(cn=!1,(an!==null||on!==null)&&(Au(),an&&(t=an,e=on,on=an=null,sn(t),e)))for(t=0;t<e.length;t++)sn(e[t])}}function un(e,t){var n=e.stateNode;if(n===null)return null;var r=n[lt]||null;if(r===null)return null;n=r[t];a:switch(t){case`onClick`:case`onClickCapture`:case`onDoubleClick`:case`onDoubleClickCapture`:case`onMouseDown`:case`onMouseDownCapture`:case`onMouseMove`:case`onMouseMoveCapture`:case`onMouseUp`:case`onMouseUpCapture`:case`onMouseEnter`:(r=!r.disabled)||(e=e.type,r=!(e===`button`||e===`input`||e===`select`||e===`textarea`)),e=!r;break a;default:e=!1}if(e)return null;if(n&&typeof n!=`function`)throw Error(i(231,t,typeof n));return n}var dn=!(typeof window>`u`||window.document===void 0||window.document.createElement===void 0),fn=!1;if(dn)try{var pn={};Object.defineProperty(pn,`passive`,{get:function(){fn=!0}}),window.addEventListener(`test`,pn,pn),window.removeEventListener(`test`,pn,pn)}catch{fn=!1}var mn=null,hn=null,gn=null;function _n(){if(gn)return gn;var e,t=hn,n=t.length,r,i=`value`in mn?mn.value:mn.textContent,a=i.length;for(e=0;e<n&&t[e]===i[e];e++);var o=n-e;for(r=1;r<=o&&t[n-r]===i[a-r];r++);return gn=i.slice(e,1<r?1-r:void 0)}function vn(e){var t=e.keyCode;return`charCode`in e?(e=e.charCode,e===0&&t===13&&(e=13)):e=t,e===10&&(e=13),32<=e||e===13?e:0}function yn(){return!0}function bn(){return!1}function xn(e){function t(t,n,r,i,a){for(var o in this._reactName=t,this._targetInst=r,this.type=n,this.nativeEvent=i,this.target=a,this.currentTarget=null,e)e.hasOwnProperty(o)&&(t=e[o],this[o]=t?t(i):i[o]);return this.isDefaultPrevented=(i.defaultPrevented==null?!1===i.returnValue:i.defaultPrevented)?yn:bn,this.isPropagationStopped=bn,this}return h(t.prototype,{preventDefault:function(){this.defaultPrevented=!0;var e=this.nativeEvent;e&&(e.preventDefault?e.preventDefault():typeof e.returnValue!=`unknown`&&(e.returnValue=!1),this.isDefaultPrevented=yn)},stopPropagation:function(){var e=this.nativeEvent;e&&(e.stopPropagation?e.stopPropagation():typeof e.cancelBubble!=`unknown`&&(e.cancelBubble=!0),this.isPropagationStopped=yn)},persist:function(){},isPersistent:yn}),t}var Sn={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},Cn=xn(Sn),wn=h({},Sn,{view:0,detail:0}),Tn=xn(wn),En,Dn,On,kn=h({},wn,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:Bn,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!==On&&(On&&e.type===`mousemove`?(En=e.screenX-On.screenX,Dn=e.screenY-On.screenY):Dn=En=0,On=e),En)},movementY:function(e){return`movementY`in e?e.movementY:Dn}}),An=xn(kn),jn=xn(h({},kn,{dataTransfer:0})),Mn=xn(h({},wn,{relatedTarget:0})),Nn=xn(h({},Sn,{animationName:0,elapsedTime:0,pseudoElement:0})),Pn=xn(h({},Sn,{clipboardData:function(e){return`clipboardData`in e?e.clipboardData:window.clipboardData}})),Fn=xn(h({},Sn,{data:0})),In={Esc:`Escape`,Spacebar:` `,Left:`ArrowLeft`,Up:`ArrowUp`,Right:`ArrowRight`,Down:`ArrowDown`,Del:`Delete`,Win:`OS`,Menu:`ContextMenu`,Apps:`ContextMenu`,Scroll:`ScrollLock`,MozPrintableKey:`Unidentified`},Ln={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`},Rn={Alt:`altKey`,Control:`ctrlKey`,Meta:`metaKey`,Shift:`shiftKey`};function zn(e){var t=this.nativeEvent;return t.getModifierState?t.getModifierState(e):(e=Rn[e])?!!t[e]:!1}function Bn(){return zn}var Vn=xn(h({},wn,{key:function(e){if(e.key){var t=In[e.key]||e.key;if(t!==`Unidentified`)return t}return e.type===`keypress`?(e=vn(e),e===13?`Enter`:String.fromCharCode(e)):e.type===`keydown`||e.type===`keyup`?Ln[e.keyCode]||`Unidentified`:``},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:Bn,charCode:function(e){return e.type===`keypress`?vn(e):0},keyCode:function(e){return e.type===`keydown`||e.type===`keyup`?e.keyCode:0},which:function(e){return e.type===`keypress`?vn(e):e.type===`keydown`||e.type===`keyup`?e.keyCode:0}})),Hn=xn(h({},kn,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0})),Un=xn(h({},wn,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:Bn})),Wn=xn(h({},Sn,{propertyName:0,elapsedTime:0,pseudoElement:0})),Gn=xn(h({},kn,{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})),Kn=xn(h({},Sn,{newState:0,oldState:0})),qn=[9,13,27,32],Jn=dn&&`CompositionEvent`in window,Yn=null;dn&&`documentMode`in document&&(Yn=document.documentMode);var Xn=dn&&`TextEvent`in window&&!Yn,Zn=dn&&(!Jn||Yn&&8<Yn&&11>=Yn),Qn=` `,$n=!1;function er(e,t){switch(e){case`keyup`:return qn.indexOf(t.keyCode)!==-1;case`keydown`:return t.keyCode!==229;case`keypress`:case`mousedown`:case`focusout`:return!0;default:return!1}}function tr(e){return e=e.detail,typeof e==`object`&&`data`in e?e.data:null}var nr=!1;function rr(e,t){switch(e){case`compositionend`:return tr(t);case`keypress`:return t.which===32?($n=!0,Qn):null;case`textInput`:return e=t.data,e===Qn&&$n?null:e;default:return null}}function ir(e,t){if(nr)return e===`compositionend`||!Jn&&er(e,t)?(e=_n(),gn=hn=mn=null,nr=!1,e):null;switch(e){case`paste`:return null;case`keypress`:if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1<t.char.length)return t.char;if(t.which)return String.fromCharCode(t.which)}return null;case`compositionend`:return Zn&&t.locale!==`ko`?null:t.data;default:return null}}var ar={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 or(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t===`input`?!!ar[e.type]:t===`textarea`}function sr(e,t,n,r){an?on?on.push(r):on=[r]:an=r,t=Rd(t,`onChange`),0<t.length&&(n=new Cn(`onChange`,`change`,null,n,r),e.push({event:n,listeners:t}))}var cr=null,lr=null;function ur(e){Ad(e,0)}function dr(e){if(Lt(yt(e)))return e}function fr(e,t){if(e===`change`)return t}var pr=!1;if(dn){var mr;if(dn){var hr=`oninput`in document;if(!hr){var gr=document.createElement(`div`);gr.setAttribute(`oninput`,`return;`),hr=typeof gr.oninput==`function`}mr=hr}else mr=!1;pr=mr&&(!document.documentMode||9<document.documentMode)}function _r(){cr&&(cr.detachEvent(`onpropertychange`,vr),lr=cr=null)}function vr(e){if(e.propertyName===`value`&&dr(lr)){var t=[];sr(t,lr,e,rn(e)),ln(ur,t)}}function yr(e,t,n){e===`focusin`?(_r(),cr=t,lr=n,cr.attachEvent(`onpropertychange`,vr)):e===`focusout`&&_r()}function br(e){if(e===`selectionchange`||e===`keyup`||e===`keydown`)return dr(lr)}function xr(e,t){if(e===`click`)return dr(t)}function Sr(e,t){if(e===`input`||e===`change`)return dr(t)}function Cr(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var wr=typeof Object.is==`function`?Object.is:Cr;function Tr(e,t){if(wr(e,t))return!0;if(typeof e!=`object`||!e||typeof t!=`object`||!t)return!1;var n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(r=0;r<n.length;r++){var i=n[r];if(!Se.call(t,i)||!wr(e[i],t[i]))return!1}return!0}function Er(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function Dr(e,t){var n=Er(e);e=0;for(var r;n;){if(n.nodeType===3){if(r=e+n.textContent.length,e<=t&&r>=t)return{node:n,offset:t-e};e=r}a:{for(;n;){if(n.nextSibling){n=n.nextSibling;break a}n=n.parentNode}n=void 0}n=Er(n)}}function Or(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?Or(e,t.parentNode):`contains`in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function kr(e){e=e!=null&&e.ownerDocument!=null&&e.ownerDocument.defaultView!=null?e.ownerDocument.defaultView:window;for(var t=Rt(e.document);t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href==`string`}catch{n=!1}if(n)e=t.contentWindow;else break;t=Rt(e.document)}return t}function Ar(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t&&(t===`input`&&(e.type===`text`||e.type===`search`||e.type===`tel`||e.type===`url`||e.type===`password`)||t===`textarea`||e.contentEditable===`true`)}var jr=dn&&`documentMode`in document&&11>=document.documentMode,Mr=null,Nr=null,Pr=null,Fr=!1;function Ir(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;Fr||Mr==null||Mr!==Rt(r)||(r=Mr,`selectionStart`in r&&Ar(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),Pr&&Tr(Pr,r)||(Pr=r,r=Rd(Nr,`onSelect`),0<r.length&&(t=new Cn(`onSelect`,`select`,null,t,n),e.push({event:t,listeners:r}),t.target=Mr)))}function Lr(e,t){var n={};return n[e.toLowerCase()]=t.toLowerCase(),n[`Webkit`+e]=`webkit`+t,n[`Moz`+e]=`moz`+t,n}var Rr={animationend:Lr(`Animation`,`AnimationEnd`),animationiteration:Lr(`Animation`,`AnimationIteration`),animationstart:Lr(`Animation`,`AnimationStart`),transitionrun:Lr(`Transition`,`TransitionRun`),transitionstart:Lr(`Transition`,`TransitionStart`),transitioncancel:Lr(`Transition`,`TransitionCancel`),transitionend:Lr(`Transition`,`TransitionEnd`)},zr={},Br={};dn&&(Br=document.createElement(`div`).style,`AnimationEvent`in window||(delete Rr.animationend.animation,delete Rr.animationiteration.animation,delete Rr.animationstart.animation),`TransitionEvent`in window||delete Rr.transitionend.transition);function Vr(e){if(zr[e])return zr[e];if(!Rr[e])return e;var t=Rr[e],n;for(n in t)if(t.hasOwnProperty(n)&&n in Br)return zr[e]=t[n];return e}var Hr=Vr(`animationend`),Ur=Vr(`animationiteration`),Wr=Vr(`animationstart`),Gr=Vr(`transitionrun`),Kr=Vr(`transitionstart`),qr=Vr(`transitioncancel`),Jr=Vr(`transitionend`),Yr=new Map,Xr=`abort auxClick beforeToggle 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(` `);Xr.push(`scrollEnd`);function Zr(e,t){Yr.set(e,t),wt(t,[e])}var Qr=typeof reportError==`function`?reportError:function(e){if(typeof window==`object`&&typeof window.ErrorEvent==`function`){var t=new window.ErrorEvent(`error`,{bubbles:!0,cancelable:!0,message:typeof e==`object`&&e&&typeof e.message==`string`?String(e.message):String(e),error:e});if(!window.dispatchEvent(t))return}else if(typeof process==`object`&&typeof process.emit==`function`){process.emit(`uncaughtException`,e);return}console.error(e)},$r=[],ei=0,ti=0;function L(){for(var e=ei,t=ti=ei=0;t<e;){var n=$r[t];$r[t++]=null;var r=$r[t];$r[t++]=null;var i=$r[t];$r[t++]=null;var a=$r[t];if($r[t++]=null,r!==null&&i!==null){var o=r.pending;o===null?i.next=i:(i.next=o.next,o.next=i),r.pending=i}a!==0&&ai(n,i,a)}}function ni(e,t,n,r){$r[ei++]=e,$r[ei++]=t,$r[ei++]=n,$r[ei++]=r,ti|=r,e.lanes|=r,e=e.alternate,e!==null&&(e.lanes|=r)}function ri(e,t,n,r){return ni(e,t,n,r),oi(e)}function ii(e,t){return ni(e,null,null,t),oi(e)}function ai(e,t,n){e.lanes|=n;var r=e.alternate;r!==null&&(r.lanes|=n);for(var i=!1,a=e.return;a!==null;)a.childLanes|=n,r=a.alternate,r!==null&&(r.childLanes|=n),a.tag===22&&(e=a.stateNode,e===null||e._visibility&1||(i=!0)),e=a,a=a.return;return e.tag===3?(a=e.stateNode,i&&t!==null&&(i=31-ze(n),e=a.hiddenUpdates,r=e[i],r===null?e[i]=[t]:r.push(t),t.lane=n|536870912),a):null}function oi(e){if(50<xu)throw xu=0,Su=null,Error(i(185));for(var t=e.return;t!==null;)e=t,t=e.return;return e.tag===3?e.stateNode:null}var si={};function ci(e,t,n,r){this.tag=e,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.refCleanup=this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function li(e,t,n,r){return new ci(e,t,n,r)}function ui(e){return e=e.prototype,!(!e||!e.isReactComponent)}function di(e,t){var n=e.alternate;return n===null?(n=li(e.tag,t,e.key,e.mode),n.elementType=e.elementType,n.type=e.type,n.stateNode=e.stateNode,n.alternate=e,e.alternate=n):(n.pendingProps=t,n.type=e.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=e.flags&65011712,n.childLanes=e.childLanes,n.lanes=e.lanes,n.child=e.child,n.memoizedProps=e.memoizedProps,n.memoizedState=e.memoizedState,n.updateQueue=e.updateQueue,t=e.dependencies,n.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},n.sibling=e.sibling,n.index=e.index,n.ref=e.ref,n.refCleanup=e.refCleanup,n}function fi(e,t){e.flags&=65011714;var n=e.alternate;return n===null?(e.childLanes=0,e.lanes=t,e.child=null,e.subtreeFlags=0,e.memoizedProps=null,e.memoizedState=null,e.updateQueue=null,e.dependencies=null,e.stateNode=null):(e.childLanes=n.childLanes,e.lanes=n.lanes,e.child=n.child,e.subtreeFlags=0,e.deletions=null,e.memoizedProps=n.memoizedProps,e.memoizedState=n.memoizedState,e.updateQueue=n.updateQueue,e.type=n.type,t=n.dependencies,e.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext}),e}function pi(e,t,n,r,a,o){var s=0;if(r=e,typeof e==`function`)ui(e)&&(s=1);else if(typeof e==`string`)s=np(e,n,se.current)?26:e===`html`||e===`head`||e===`body`?27:5;else a:switch(e){case k:return e=li(31,n,t,a),e.elementType=k,e.lanes=o,e;case y:return mi(n.children,a,o,t);case b:s=8,a|=24;break;case x:return e=li(12,n,t,a|2),e.elementType=x,e.lanes=o,e;case T:return e=li(13,n,t,a),e.elementType=T,e.lanes=o,e;case E:return e=li(19,n,t,a),e.elementType=E,e.lanes=o,e;default:if(typeof e==`object`&&e)switch(e.$$typeof){case C:s=10;break a;case S:s=9;break a;case w:s=11;break a;case D:s=14;break a;case O:s=16,r=null;break a}s=29,n=Error(i(130,e===null?`null`:typeof e,``)),r=null}return t=li(s,n,t,a),t.elementType=e,t.type=r,t.lanes=o,t}function mi(e,t,n,r){return e=li(7,e,r,t),e.lanes=n,e}function hi(e,t,n){return e=li(6,e,null,t),e.lanes=n,e}function gi(e){var t=li(18,null,null,0);return t.stateNode=e,t}function _i(e,t,n){return t=li(4,e.children===null?[]:e.children,e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}var vi=new WeakMap;function R(e,t){if(typeof e==`object`&&e){var n=vi.get(e);return n===void 0?(t={value:e,source:t,stack:xe(t)},vi.set(e,t),t):n}return{value:e,source:t,stack:xe(t)}}var yi=[],bi=0,xi=null,Si=0,Ci=[],wi=0,Ti=null,Ei=1,Di=``;function Oi(e,t){yi[bi++]=Si,yi[bi++]=xi,xi=e,Si=t}function ki(e,t,n){Ci[wi++]=Ei,Ci[wi++]=Di,Ci[wi++]=Ti,Ti=e;var r=Ei;e=Di;var i=32-ze(r)-1;r&=~(1<<i),n+=1;var a=32-ze(t)+i;if(30<a){var o=i-i%5;a=(r&(1<<o)-1).toString(32),r>>=o,i-=o,Ei=1<<32-ze(t)+i|n<<i|r,Di=a+e}else Ei=1<<a|n<<i|r,Di=e}function Ai(e){e.return!==null&&(Oi(e,1),ki(e,1,0))}function ji(e){for(;e===xi;)xi=yi[--bi],yi[bi]=null,Si=yi[--bi],yi[bi]=null;for(;e===Ti;)Ti=Ci[--wi],Ci[wi]=null,Di=Ci[--wi],Ci[wi]=null,Ei=Ci[--wi],Ci[wi]=null}function Mi(e,t){Ci[wi++]=Ei,Ci[wi++]=Di,Ci[wi++]=Ti,Ei=t.id,Di=t.overflow,Ti=e}var Ni=null,Pi=null,z=!1,Fi=null,Ii=!1,Li=Error(i(519));function Ri(e){throw Wi(R(Error(i(418,1<arguments.length&&arguments[1]!==void 0&&arguments[1]?`text`:`HTML`,``)),e)),Li}function zi(e){var t=e.stateNode,n=e.type,r=e.memoizedProps;switch(t[ct]=e,t[lt]=r,n){case`dialog`:jd(`cancel`,t),jd(`close`,t);break;case`iframe`:case`object`:case`embed`:jd(`load`,t);break;case`video`:case`audio`:for(n=0;n<Od.length;n++)jd(Od[n],t);break;case`source`:jd(`error`,t);break;case`img`:case`image`:case`link`:jd(`error`,t),jd(`load`,t);break;case`details`:jd(`toggle`,t);break;case`input`:jd(`invalid`,t),Ht(t,r.value,r.defaultValue,r.checked,r.defaultChecked,r.type,r.name,!0);break;case`select`:jd(`invalid`,t);break;case`textarea`:jd(`invalid`,t),Kt(t,r.value,r.defaultValue,r.children)}n=r.children,typeof n!=`string`&&typeof n!=`number`&&typeof n!=`bigint`||t.textContent===``+n||!0===r.suppressHydrationWarning||Wd(t.textContent,n)?(r.popover!=null&&(jd(`beforetoggle`,t),jd(`toggle`,t)),r.onScroll!=null&&jd(`scroll`,t),r.onScrollEnd!=null&&jd(`scrollend`,t),r.onClick!=null&&(t.onclick=tn),t=!0):t=!1,t||Ri(e,!0)}function Bi(e){for(Ni=e.return;Ni;)switch(Ni.tag){case 5:case 31:case 13:Ii=!1;return;case 27:case 3:Ii=!0;return;default:Ni=Ni.return}}function Vi(e){if(e!==Ni)return!1;if(!z)return Bi(e),z=!0,!1;var t=e.tag,n;if((n=t!==3&&t!==27)&&((n=t===5)&&(n=e.type,n=!(n!==`form`&&n!==`button`)||nf(e.type,e.memoizedProps)),n=!n),n&&Pi&&Ri(e),Bi(e),t===13){if(e=e.memoizedState,e=e===null?null:e.dehydrated,!e)throw Error(i(317));Pi=Cf(e)}else if(t===31){if(e=e.memoizedState,e=e===null?null:e.dehydrated,!e)throw Error(i(317));Pi=Cf(e)}else t===27?(t=Pi,df(e.type)?(e=Sf,Sf=null,Pi=e):Pi=t):Pi=Ni?xf(e.stateNode.nextSibling):null;return!0}function Hi(){Pi=Ni=null,z=!1}function Ui(){var e=Fi;return e!==null&&(su===null?su=e:su.push.apply(su,e),Fi=null),e}function Wi(e){Fi===null?Fi=[e]:Fi.push(e)}var Gi=ie(null),Ki=null,qi=null;function Ji(e,t,n){oe(Gi,t._currentValue),t._currentValue=n}function Yi(e){e._currentValue=Gi.current,ae(Gi)}function Xi(e,t,n){for(;e!==null;){var r=e.alternate;if((e.childLanes&t)===t?r!==null&&(r.childLanes&t)!==t&&(r.childLanes|=t):(e.childLanes|=t,r!==null&&(r.childLanes|=t)),e===n)break;e=e.return}}function Zi(e,t,n,r){var a=e.child;for(a!==null&&(a.return=e);a!==null;){var o=a.dependencies;if(o!==null){var s=a.child;o=o.firstContext;a:for(;o!==null;){var c=o;o=a;for(var l=0;l<t.length;l++)if(c.context===t[l]){o.lanes|=n,c=o.alternate,c!==null&&(c.lanes|=n),Xi(o.return,n,e),r||(s=null);break a}o=c.next}}else if(a.tag===18){if(s=a.return,s===null)throw Error(i(341));s.lanes|=n,o=s.alternate,o!==null&&(o.lanes|=n),Xi(s,n,e),s=null}else s=a.child;if(s!==null)s.return=a;else for(s=a;s!==null;){if(s===e){s=null;break}if(a=s.sibling,a!==null){a.return=s.return,s=a;break}s=s.return}a=s}}function Qi(e,t,n,r){e=null;for(var a=t,o=!1;a!==null;){if(!o){if(a.flags&524288)o=!0;else if(a.flags&262144)break}if(a.tag===10){var s=a.alternate;if(s===null)throw Error(i(387));if(s=s.memoizedProps,s!==null){var c=a.type;wr(a.pendingProps.value,s.value)||(e===null?e=[c]:e.push(c))}}else if(a===ue.current){if(s=a.alternate,s===null)throw Error(i(387));s.memoizedState.memoizedState!==a.memoizedState.memoizedState&&(e===null?e=[dp]:e.push(dp))}a=a.return}e!==null&&Zi(t,e,n,r),t.flags|=262144}function $i(e){for(e=e.firstContext;e!==null;){if(!wr(e.context._currentValue,e.memoizedValue))return!0;e=e.next}return!1}function ea(e){Ki=e,qi=null,e=e.dependencies,e!==null&&(e.firstContext=null)}function ta(e){return ra(Ki,e)}function na(e,t){return Ki===null&&ea(e),ra(e,t)}function ra(e,t){var n=t._currentValue;if(t={context:t,memoizedValue:n,next:null},qi===null){if(e===null)throw Error(i(308));qi=t,e.dependencies={lanes:0,firstContext:t},e.flags|=524288}else qi=qi.next=t;return n}var ia=typeof AbortController<`u`?AbortController:function(){var e=[],t=this.signal={aborted:!1,addEventListener:function(t,n){e.push(n)}};this.abort=function(){t.aborted=!0,e.forEach(function(e){return e()})}},aa=t.unstable_scheduleCallback,oa=t.unstable_NormalPriority,sa={$$typeof:C,Consumer:null,Provider:null,_currentValue:null,_currentValue2:null,_threadCount:0};function ca(){return{controller:new ia,data:new Map,refCount:0}}function la(e){e.refCount--,e.refCount===0&&aa(oa,function(){e.controller.abort()})}var ua=null,da=0,fa=0,pa=null;function ma(e,t){if(ua===null){var n=ua=[];da=0,fa=Sd(),pa={status:`pending`,value:void 0,then:function(e){n.push(e)}}}return da++,t.then(ha,ha),t}function ha(){if(--da===0&&ua!==null){pa!==null&&(pa.status=`fulfilled`);var e=ua;ua=null,fa=0,pa=null;for(var t=0;t<e.length;t++)(0,e[t])()}}function ga(e,t){var n=[],r={status:`pending`,value:null,reason:null,then:function(e){n.push(e)}};return e.then(function(){r.status=`fulfilled`,r.value=t;for(var e=0;e<n.length;e++)(0,n[e])(t)},function(e){for(r.status=`rejected`,r.reason=e,e=0;e<n.length;e++)(0,n[e])(void 0)}),r}var B=F.S;F.S=function(e,t){uu=De(),typeof t==`object`&&t&&typeof t.then==`function`&&ma(e,t),B!==null&&B(e,t)};var _a=ie(null);function va(){var e=_a.current;return e===null?Gl.pooledCache:e}function ya(e,t){t===null?oe(_a,_a.current):oe(_a,t.pool)}function ba(){var e=va();return e===null?null:{parent:sa._currentValue,pool:e}}var xa=Error(i(460)),Sa=Error(i(474)),Ca=Error(i(542)),wa={then:function(){}};function Ta(e){return e=e.status,e===`fulfilled`||e===`rejected`}function Ea(e,t,n){switch(n=e[n],n===void 0?e.push(t):n!==t&&(t.then(tn,tn),t=n),t.status){case`fulfilled`:return t.value;case`rejected`:throw e=t.reason,Aa(e),e;default:if(typeof t.status==`string`)t.then(tn,tn);else{if(e=Gl,e!==null&&100<e.shellSuspendCounter)throw Error(i(482));e=t,e.status=`pending`,e.then(function(e){if(t.status===`pending`){var n=t;n.status=`fulfilled`,n.value=e}},function(e){if(t.status===`pending`){var n=t;n.status=`rejected`,n.reason=e}})}switch(t.status){case`fulfilled`:return t.value;case`rejected`:throw e=t.reason,Aa(e),e}throw Oa=t,xa}}function Da(e){try{var t=e._init;return t(e._payload)}catch(e){throw typeof e==`object`&&e&&typeof e.then==`function`?(Oa=e,xa):e}}var Oa=null;function ka(){if(Oa===null)throw Error(i(459));var e=Oa;return Oa=null,e}function Aa(e){if(e===xa||e===Ca)throw Error(i(483))}var ja=null,Ma=0;function Na(e){var t=Ma;return Ma+=1,ja===null&&(ja=[]),Ea(ja,e,t)}function Pa(e,t){t=t.props.ref,e.ref=t===void 0?null:t}function Fa(e,t){throw t.$$typeof===g?Error(i(525)):(e=Object.prototype.toString.call(t),Error(i(31,e===`[object Object]`?`object with keys {`+Object.keys(t).join(`, `)+`}`:e)))}function Ia(e){function t(t,n){if(e){var r=t.deletions;r===null?(t.deletions=[n],t.flags|=16):r.push(n)}}function n(n,r){if(!e)return null;for(;r!==null;)t(n,r),r=r.sibling;return null}function r(e){for(var t=new Map;e!==null;)e.key===null?t.set(e.index,e):t.set(e.key,e),e=e.sibling;return t}function a(e,t){return e=di(e,t),e.index=0,e.sibling=null,e}function o(t,n,r){return t.index=r,e?(r=t.alternate,r===null?(t.flags|=67108866,n):(r=r.index,r<n?(t.flags|=67108866,n):r)):(t.flags|=1048576,n)}function s(t){return e&&t.alternate===null&&(t.flags|=67108866),t}function c(e,t,n,r){return t===null||t.tag!==6?(t=hi(n,e.mode,r),t.return=e,t):(t=a(t,n),t.return=e,t)}function l(e,t,n,r){var i=n.type;return i===y?d(e,t,n.props.children,r,n.key):t!==null&&(t.elementType===i||typeof i==`object`&&i&&i.$$typeof===O&&Da(i)===t.type)?(t=a(t,n.props),Pa(t,n),t.return=e,t):(t=pi(n.type,n.key,n.props,null,e.mode,r),Pa(t,n),t.return=e,t)}function u(e,t,n,r){return t===null||t.tag!==4||t.stateNode.containerInfo!==n.containerInfo||t.stateNode.implementation!==n.implementation?(t=_i(n,e.mode,r),t.return=e,t):(t=a(t,n.children||[]),t.return=e,t)}function d(e,t,n,r,i){return t===null||t.tag!==7?(t=mi(n,e.mode,r,i),t.return=e,t):(t=a(t,n),t.return=e,t)}function f(e,t,n){if(typeof t==`string`&&t!==``||typeof t==`number`||typeof t==`bigint`)return t=hi(``+t,e.mode,n),t.return=e,t;if(typeof t==`object`&&t){switch(t.$$typeof){case _:return n=pi(t.type,t.key,t.props,null,e.mode,n),Pa(n,t),n.return=e,n;case v:return t=_i(t,e.mode,n),t.return=e,t;case O:return t=Da(t),f(e,t,n)}if(P(t)||M(t))return t=mi(t,e.mode,n,null),t.return=e,t;if(typeof t.then==`function`)return f(e,Na(t),n);if(t.$$typeof===C)return f(e,na(e,t),n);Fa(e,t)}return null}function p(e,t,n,r){var i=t===null?null:t.key;if(typeof n==`string`&&n!==``||typeof n==`number`||typeof n==`bigint`)return i===null?c(e,t,``+n,r):null;if(typeof n==`object`&&n){switch(n.$$typeof){case _:return n.key===i?l(e,t,n,r):null;case v:return n.key===i?u(e,t,n,r):null;case O:return n=Da(n),p(e,t,n,r)}if(P(n)||M(n))return i===null?d(e,t,n,r,null):null;if(typeof n.then==`function`)return p(e,t,Na(n),r);if(n.$$typeof===C)return p(e,t,na(e,n),r);Fa(e,n)}return null}function m(e,t,n,r,i){if(typeof r==`string`&&r!==``||typeof r==`number`||typeof r==`bigint`)return e=e.get(n)||null,c(t,e,``+r,i);if(typeof r==`object`&&r){switch(r.$$typeof){case _:return e=e.get(r.key===null?n:r.key)||null,l(t,e,r,i);case v:return e=e.get(r.key===null?n:r.key)||null,u(t,e,r,i);case O:return r=Da(r),m(e,t,n,r,i)}if(P(r)||M(r))return e=e.get(n)||null,d(t,e,r,i,null);if(typeof r.then==`function`)return m(e,t,n,Na(r),i);if(r.$$typeof===C)return m(e,t,n,na(t,r),i);Fa(t,r)}return null}function h(i,a,s,c){for(var l=null,u=null,d=a,h=a=0,g=null;d!==null&&h<s.length;h++){d.index>h?(g=d,d=null):g=d.sibling;var _=p(i,d,s[h],c);if(_===null){d===null&&(d=g);break}e&&d&&_.alternate===null&&t(i,d),a=o(_,a,h),u===null?l=_:u.sibling=_,u=_,d=g}if(h===s.length)return n(i,d),z&&Oi(i,h),l;if(d===null){for(;h<s.length;h++)d=f(i,s[h],c),d!==null&&(a=o(d,a,h),u===null?l=d:u.sibling=d,u=d);return z&&Oi(i,h),l}for(d=r(d);h<s.length;h++)g=m(d,i,h,s[h],c),g!==null&&(e&&g.alternate!==null&&d.delete(g.key===null?h:g.key),a=o(g,a,h),u===null?l=g:u.sibling=g,u=g);return e&&d.forEach(function(e){return t(i,e)}),z&&Oi(i,h),l}function g(a,s,c,l){if(c==null)throw Error(i(151));for(var u=null,d=null,h=s,g=s=0,_=null,v=c.next();h!==null&&!v.done;g++,v=c.next()){h.index>g?(_=h,h=null):_=h.sibling;var y=p(a,h,v.value,l);if(y===null){h===null&&(h=_);break}e&&h&&y.alternate===null&&t(a,h),s=o(y,s,g),d===null?u=y:d.sibling=y,d=y,h=_}if(v.done)return n(a,h),z&&Oi(a,g),u;if(h===null){for(;!v.done;g++,v=c.next())v=f(a,v.value,l),v!==null&&(s=o(v,s,g),d===null?u=v:d.sibling=v,d=v);return z&&Oi(a,g),u}for(h=r(h);!v.done;g++,v=c.next())v=m(h,a,g,v.value,l),v!==null&&(e&&v.alternate!==null&&h.delete(v.key===null?g:v.key),s=o(v,s,g),d===null?u=v:d.sibling=v,d=v);return e&&h.forEach(function(e){return t(a,e)}),z&&Oi(a,g),u}function b(e,r,o,c){if(typeof o==`object`&&o&&o.type===y&&o.key===null&&(o=o.props.children),typeof o==`object`&&o){switch(o.$$typeof){case _:a:{for(var l=o.key;r!==null;){if(r.key===l){if(l=o.type,l===y){if(r.tag===7){n(e,r.sibling),c=a(r,o.props.children),c.return=e,e=c;break a}}else if(r.elementType===l||typeof l==`object`&&l&&l.$$typeof===O&&Da(l)===r.type){n(e,r.sibling),c=a(r,o.props),Pa(c,o),c.return=e,e=c;break a}n(e,r);break}else t(e,r);r=r.sibling}o.type===y?(c=mi(o.props.children,e.mode,c,o.key),c.return=e,e=c):(c=pi(o.type,o.key,o.props,null,e.mode,c),Pa(c,o),c.return=e,e=c)}return s(e);case v:a:{for(l=o.key;r!==null;){if(r.key===l)if(r.tag===4&&r.stateNode.containerInfo===o.containerInfo&&r.stateNode.implementation===o.implementation){n(e,r.sibling),c=a(r,o.children||[]),c.return=e,e=c;break a}else{n(e,r);break}else t(e,r);r=r.sibling}c=_i(o,e.mode,c),c.return=e,e=c}return s(e);case O:return o=Da(o),b(e,r,o,c)}if(P(o))return h(e,r,o,c);if(M(o)){if(l=M(o),typeof l!=`function`)throw Error(i(150));return o=l.call(o),g(e,r,o,c)}if(typeof o.then==`function`)return b(e,r,Na(o),c);if(o.$$typeof===C)return b(e,r,na(e,o),c);Fa(e,o)}return typeof o==`string`&&o!==``||typeof o==`number`||typeof o==`bigint`?(o=``+o,r!==null&&r.tag===6?(n(e,r.sibling),c=a(r,o),c.return=e,e=c):(n(e,r),c=hi(o,e.mode,c),c.return=e,e=c),s(e)):n(e,r)}return function(e,t,n,r){try{Ma=0;var i=b(e,t,n,r);return ja=null,i}catch(t){if(t===xa||t===Ca)throw t;var a=li(29,t,null,e.mode);return a.lanes=r,a.return=e,a}}}var La=Ia(!0),Ra=Ia(!1),za=!1;function Ba(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,lanes:0,hiddenCallbacks:null},callbacks:null}}function Va(e,t){e=e.updateQueue,t.updateQueue===e&&(t.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,callbacks:null})}function Ha(e){return{lane:e,tag:0,payload:null,callback:null,next:null}}function Ua(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,Wl&2){var i=r.pending;return i===null?t.next=t:(t.next=i.next,i.next=t),r.pending=t,t=oi(e),ai(e,null,n),t}return ni(e,r,t,n),oi(e)}function Wa(e,t,n){if(t=t.updateQueue,t!==null&&(t=t.shared,n&4194048)){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,tt(e,n)}}function Ga(e,t){var n=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,n===r)){var i=null,a=null;if(n=n.firstBaseUpdate,n!==null){do{var o={lane:n.lane,tag:n.tag,payload:n.payload,callback:null,next:null};a===null?i=a=o:a=a.next=o,n=n.next}while(n!==null);a===null?i=a=t:a=a.next=t}else i=a=t;n={baseState:r.baseState,firstBaseUpdate:i,lastBaseUpdate:a,shared:r.shared,callbacks:r.callbacks},e.updateQueue=n;return}e=n.lastBaseUpdate,e===null?n.firstBaseUpdate=t:e.next=t,n.lastBaseUpdate=t}var Ka=!1;function qa(){if(Ka){var e=pa;if(e!==null)throw e}}function Ja(e,t,n,r){Ka=!1;var i=e.updateQueue;za=!1;var a=i.firstBaseUpdate,o=i.lastBaseUpdate,s=i.shared.pending;if(s!==null){i.shared.pending=null;var c=s,l=c.next;c.next=null,o===null?a=l:o.next=l,o=c;var u=e.alternate;u!==null&&(u=u.updateQueue,s=u.lastBaseUpdate,s!==o&&(s===null?u.firstBaseUpdate=l:s.next=l,u.lastBaseUpdate=c))}if(a!==null){var d=i.baseState;o=0,u=l=c=null,s=a;do{var f=s.lane&-536870913,p=f!==s.lane;if(p?(ql&f)===f:(r&f)===f){f!==0&&f===fa&&(Ka=!0),u!==null&&(u=u.next={lane:0,tag:s.tag,payload:s.payload,callback:null,next:null});a:{var m=e,g=s;f=t;var _=n;switch(g.tag){case 1:if(m=g.payload,typeof m==`function`){d=m.call(_,d,f);break a}d=m;break a;case 3:m.flags=m.flags&-65537|128;case 0:if(m=g.payload,f=typeof m==`function`?m.call(_,d,f):m,f==null)break a;d=h({},d,f);break a;case 2:za=!0}}f=s.callback,f!==null&&(e.flags|=64,p&&(e.flags|=8192),p=i.callbacks,p===null?i.callbacks=[f]:p.push(f))}else p={lane:f,tag:s.tag,payload:s.payload,callback:s.callback,next:null},u===null?(l=u=p,c=d):u=u.next=p,o|=f;if(s=s.next,s===null){if(s=i.shared.pending,s===null)break;p=s,s=p.next,p.next=null,i.lastBaseUpdate=p,i.shared.pending=null}}while(1);u===null&&(c=d),i.baseState=c,i.firstBaseUpdate=l,i.lastBaseUpdate=u,a===null&&(i.shared.lanes=0),tu|=o,e.lanes=o,e.memoizedState=d}}function Ya(e,t){if(typeof e!=`function`)throw Error(i(191,e));e.call(t)}function Xa(e,t){var n=e.callbacks;if(n!==null)for(e.callbacks=null,e=0;e<n.length;e++)Ya(n[e],t)}var Za=ie(null),Qa=ie(0);function $a(e,t){e=$l,oe(Qa,e),oe(Za,t),$l=e|t.baseLanes}function eo(){oe(Qa,$l),oe(Za,Za.current)}function to(){$l=Qa.current,ae(Za),ae(Qa)}var no=ie(null),ro=null;function io(e){var t=e.alternate;oe(lo,lo.current&1),oe(no,e),ro===null&&(t===null||Za.current!==null||t.memoizedState!==null)&&(ro=e)}function ao(e){oe(lo,lo.current),oe(no,e),ro===null&&(ro=e)}function oo(e){e.tag===22?(oe(lo,lo.current),oe(no,e),ro===null&&(ro=e)):so(e)}function so(){oe(lo,lo.current),oe(no,no.current)}function co(e){ae(no),ro===e&&(ro=null),ae(lo)}var lo=ie(0);function uo(e){for(var t=e;t!==null;){if(t.tag===13){var n=t.memoizedState;if(n!==null&&(n=n.dehydrated,n===null||vf(n)||yf(n)))return t}else if(t.tag===19&&(t.memoizedProps.revealOrder===`forwards`||t.memoizedProps.revealOrder===`backwards`||t.memoizedProps.revealOrder===`unstable_legacy-backwards`||t.memoizedProps.revealOrder===`together`)){if(t.flags&128)return t}else if(t.child!==null){t.child.return=t,t=t.child;continue}if(t===e)break;for(;t.sibling===null;){if(t.return===null||t.return===e)return null;t=t.return}t.sibling.return=t.return,t=t.sibling}return null}var fo=0,po=null,mo=null,ho=null,go=!1,_o=!1,vo=!1,yo=0,bo=0,xo=null,So=0;function Co(){throw Error(i(321))}function wo(e,t){if(t===null)return!1;for(var n=0;n<t.length&&n<e.length;n++)if(!wr(e[n],t[n]))return!1;return!0}function To(e,t,n,r,i,a){return fo=a,po=t,t.memoizedState=null,t.updateQueue=null,t.lanes=0,F.H=e===null||e.memoizedState===null?Hs:Us,vo=!1,a=n(r,i),vo=!1,_o&&(a=Do(t,n,r,i)),Eo(e),a}function Eo(e){F.H=Vs;var t=mo!==null&&mo.next!==null;if(fo=0,ho=mo=po=null,go=!1,bo=0,xo=null,t)throw Error(i(300));e===null||oc||(e=e.dependencies,e!==null&&$i(e)&&(oc=!0))}function Do(e,t,n,r){po=e;var a=0;do{if(_o&&(xo=null),bo=0,_o=!1,25<=a)throw Error(i(301));if(a+=1,ho=mo=null,e.updateQueue!=null){var o=e.updateQueue;o.lastEffect=null,o.events=null,o.stores=null,o.memoCache!=null&&(o.memoCache.index=0)}F.H=Ws,o=t(n,r)}while(_o);return o}function Oo(){var e=F.H,t=e.useState()[0];return t=typeof t.then==`function`?Fo(t):t,e=e.useState()[0],(mo===null?null:mo.memoizedState)!==e&&(po.flags|=1024),t}function ko(){var e=yo!==0;return yo=0,e}function Ao(e,t,n){t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~n}function jo(e){if(go){for(e=e.memoizedState;e!==null;){var t=e.queue;t!==null&&(t.pending=null),e=e.next}go=!1}fo=0,ho=mo=po=null,_o=!1,bo=yo=0,xo=null}function Mo(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return ho===null?po.memoizedState=ho=e:ho=ho.next=e,ho}function No(){if(mo===null){var e=po.alternate;e=e===null?null:e.memoizedState}else e=mo.next;var t=ho===null?po.memoizedState:ho.next;if(t!==null)ho=t,mo=e;else{if(e===null)throw po.alternate===null?Error(i(467)):Error(i(310));mo=e,e={memoizedState:mo.memoizedState,baseState:mo.baseState,baseQueue:mo.baseQueue,queue:mo.queue,next:null},ho===null?po.memoizedState=ho=e:ho=ho.next=e}return ho}function Po(){return{lastEffect:null,events:null,stores:null,memoCache:null}}function Fo(e){var t=bo;return bo+=1,xo===null&&(xo=[]),e=Ea(xo,e,t),t=po,(ho===null?t.memoizedState:ho.next)===null&&(t=t.alternate,F.H=t===null||t.memoizedState===null?Hs:Us),e}function Io(e){if(typeof e==`object`&&e){if(typeof e.then==`function`)return Fo(e);if(e.$$typeof===C)return ta(e)}throw Error(i(438,String(e)))}function Lo(e){var t=null,n=po.updateQueue;if(n!==null&&(t=n.memoCache),t==null){var r=po.alternate;r!==null&&(r=r.updateQueue,r!==null&&(r=r.memoCache,r!=null&&(t={data:r.data.map(function(e){return e.slice()}),index:0})))}if(t??={data:[],index:0},n===null&&(n=Po(),po.updateQueue=n),n.memoCache=t,n=t.data[t.index],n===void 0)for(n=t.data[t.index]=Array(e),r=0;r<e;r++)n[r]=A;return t.index++,n}function Ro(e,t){return typeof t==`function`?t(e):t}function zo(e){return Bo(No(),mo,e)}function Bo(e,t,n){var r=e.queue;if(r===null)throw Error(i(311));r.lastRenderedReducer=n;var a=e.baseQueue,o=r.pending;if(o!==null){if(a!==null){var s=a.next;a.next=o.next,o.next=s}t.baseQueue=a=o,r.pending=null}if(o=e.baseState,a===null)e.memoizedState=o;else{t=a.next;var c=s=null,l=null,u=t,d=!1;do{var f=u.lane&-536870913;if(f===u.lane?(fo&f)===f:(ql&f)===f){var p=u.revertLane;if(p===0)l!==null&&(l=l.next={lane:0,revertLane:0,gesture:null,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null}),f===fa&&(d=!0);else if((fo&p)===p){u=u.next,p===fa&&(d=!0);continue}else f={lane:0,revertLane:u.revertLane,gesture:null,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null},l===null?(c=l=f,s=o):l=l.next=f,po.lanes|=p,tu|=p;f=u.action,vo&&n(o,f),o=u.hasEagerState?u.eagerState:n(o,f)}else p={lane:f,revertLane:u.revertLane,gesture:u.gesture,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null},l===null?(c=l=p,s=o):l=l.next=p,po.lanes|=f,tu|=f;u=u.next}while(u!==null&&u!==t);if(l===null?s=o:l.next=c,!wr(o,e.memoizedState)&&(oc=!0,d&&(n=pa,n!==null)))throw n;e.memoizedState=o,e.baseState=s,e.baseQueue=l,r.lastRenderedState=o}return a===null&&(r.lanes=0),[e.memoizedState,r.dispatch]}function Vo(e){var t=No(),n=t.queue;if(n===null)throw Error(i(311));n.lastRenderedReducer=e;var r=n.dispatch,a=n.pending,o=t.memoizedState;if(a!==null){n.pending=null;var s=a=a.next;do o=e(o,s.action),s=s.next;while(s!==a);wr(o,t.memoizedState)||(oc=!0),t.memoizedState=o,t.baseQueue===null&&(t.baseState=o),n.lastRenderedState=o}return[o,r]}function Ho(e,t,n){var r=po,a=No(),o=z;if(o){if(n===void 0)throw Error(i(407));n=n()}else n=t();var s=!wr((mo||a).memoizedState,n);if(s&&(a.memoizedState=n,oc=!0),a=a.queue,ps(Go.bind(null,r,a,e),[e]),a.getSnapshot!==t||s||ho!==null&&ho.memoizedState.tag&1){if(r.flags|=2048,cs(9,{destroy:void 0},Wo.bind(null,r,a,n,t),null),Gl===null)throw Error(i(349));o||fo&127||Uo(r,t,n)}return n}function Uo(e,t,n){e.flags|=16384,e={getSnapshot:t,value:n},t=po.updateQueue,t===null?(t=Po(),po.updateQueue=t,t.stores=[e]):(n=t.stores,n===null?t.stores=[e]:n.push(e))}function Wo(e,t,n,r){t.value=n,t.getSnapshot=r,Ko(t)&&qo(e)}function Go(e,t,n){return n(function(){Ko(t)&&qo(e)})}function Ko(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!wr(e,n)}catch{return!0}}function qo(e){var t=ii(e,2);t!==null&&Tu(t,e,2)}function Jo(e){var t=Mo();if(typeof e==`function`){var n=e;if(e=n(),vo){Re(!0);try{n()}finally{Re(!1)}}}return t.memoizedState=t.baseState=e,t.queue={pending:null,lanes:0,dispatch:null,lastRenderedReducer:Ro,lastRenderedState:e},t}function Yo(e,t,n,r){return e.baseState=n,Bo(e,mo,typeof r==`function`?r:Ro)}function Xo(e,t,n,r,a){if(Rs(e))throw Error(i(485));if(e=t.action,e!==null){var o={payload:a,action:e,next:null,isTransition:!0,status:`pending`,value:null,reason:null,listeners:[],then:function(e){o.listeners.push(e)}};F.T===null?o.isTransition=!1:n(!0),r(o),n=t.pending,n===null?(o.next=t.pending=o,Zo(t,o)):(o.next=n.next,t.pending=n.next=o)}}function Zo(e,t){var n=t.action,r=t.payload,i=e.state;if(t.isTransition){var a=F.T,o={};F.T=o;try{var s=n(i,r),c=F.S;c!==null&&c(o,s),Qo(e,t,s)}catch(n){es(e,t,n)}finally{a!==null&&o.types!==null&&(a.types=o.types),F.T=a}}else try{a=n(i,r),Qo(e,t,a)}catch(n){es(e,t,n)}}function Qo(e,t,n){typeof n==`object`&&n&&typeof n.then==`function`?n.then(function(n){$o(e,t,n)},function(n){return es(e,t,n)}):$o(e,t,n)}function $o(e,t,n){t.status=`fulfilled`,t.value=n,ts(t),e.state=n,t=e.pending,t!==null&&(n=t.next,n===t?e.pending=null:(n=n.next,t.next=n,Zo(e,n)))}function es(e,t,n){var r=e.pending;if(e.pending=null,r!==null){r=r.next;do t.status=`rejected`,t.reason=n,ts(t),t=t.next;while(t!==r)}e.action=null}function ts(e){e=e.listeners;for(var t=0;t<e.length;t++)(0,e[t])()}function ns(e,t){return t}function rs(e,t){if(z){var n=Gl.formState;if(n!==null){a:{var r=po;if(z){if(Pi){b:{for(var i=Pi,a=Ii;i.nodeType!==8;){if(!a){i=null;break b}if(i=xf(i.nextSibling),i===null){i=null;break b}}a=i.data,i=a===`F!`||a===`F`?i:null}if(i){Pi=xf(i.nextSibling),r=i.data===`F!`;break a}}Ri(r)}r=!1}r&&(t=n[0])}}return n=Mo(),n.memoizedState=n.baseState=t,r={pending:null,lanes:0,dispatch:null,lastRenderedReducer:ns,lastRenderedState:t},n.queue=r,n=Fs.bind(null,po,r),r.dispatch=n,r=Jo(!1),a=Ls.bind(null,po,!1,r.queue),r=Mo(),i={state:t,dispatch:null,action:e,pending:null},r.queue=i,n=Xo.bind(null,po,i,a,n),i.dispatch=n,r.memoizedState=e,[t,n,!1]}function is(e){return as(No(),mo,e)}function as(e,t,n){if(t=Bo(e,t,ns)[0],e=zo(Ro)[0],typeof t==`object`&&t&&typeof t.then==`function`)try{var r=Fo(t)}catch(e){throw e===xa?Ca:e}else r=t;t=No();var i=t.queue,a=i.dispatch;return n!==t.memoizedState&&(po.flags|=2048,cs(9,{destroy:void 0},os.bind(null,i,n),null)),[r,a,e]}function os(e,t){e.action=t}function ss(e){var t=No(),n=mo;if(n!==null)return as(t,n,e);No(),t=t.memoizedState,n=No();var r=n.queue.dispatch;return n.memoizedState=e,[t,r,!1]}function cs(e,t,n,r){return e={tag:e,create:n,deps:r,inst:t,next:null},t=po.updateQueue,t===null&&(t=Po(),po.updateQueue=t),n=t.lastEffect,n===null?t.lastEffect=e.next=e:(r=n.next,n.next=e,e.next=r,t.lastEffect=e),e}function ls(){return No().memoizedState}function us(e,t,n,r){var i=Mo();po.flags|=e,i.memoizedState=cs(1|t,{destroy:void 0},n,r===void 0?null:r)}function ds(e,t,n,r){var i=No();r=r===void 0?null:r;var a=i.memoizedState.inst;mo!==null&&r!==null&&wo(r,mo.memoizedState.deps)?i.memoizedState=cs(t,a,n,r):(po.flags|=e,i.memoizedState=cs(1|t,a,n,r))}function fs(e,t){us(8390656,8,e,t)}function ps(e,t){ds(2048,8,e,t)}function ms(e){po.flags|=4;var t=po.updateQueue;if(t===null)t=Po(),po.updateQueue=t,t.events=[e];else{var n=t.events;n===null?t.events=[e]:n.push(e)}}function hs(e){var t=No().memoizedState;return ms({ref:t,nextImpl:e}),function(){if(Wl&2)throw Error(i(440));return t.impl.apply(void 0,arguments)}}function gs(e,t){return ds(4,2,e,t)}function _s(e,t){return ds(4,4,e,t)}function vs(e,t){if(typeof t==`function`){e=e();var n=t(e);return function(){typeof n==`function`?n():t(null)}}if(t!=null)return e=e(),t.current=e,function(){t.current=null}}function ys(e,t,n){n=n==null?null:n.concat([e]),ds(4,4,vs.bind(null,t,e),n)}function bs(){}function xs(e,t){var n=No();t=t===void 0?null:t;var r=n.memoizedState;return t!==null&&wo(t,r[1])?r[0]:(n.memoizedState=[e,t],e)}function Ss(e,t){var n=No();t=t===void 0?null:t;var r=n.memoizedState;if(t!==null&&wo(t,r[1]))return r[0];if(r=e(),vo){Re(!0);try{e()}finally{Re(!1)}}return n.memoizedState=[r,t],r}function Cs(e,t,n){return n===void 0||fo&1073741824&&!(ql&261930)?e.memoizedState=t:(e.memoizedState=n,e=wu(),po.lanes|=e,tu|=e,n)}function ws(e,t,n,r){return wr(n,t)?n:Za.current===null?!(fo&42)||fo&1073741824&&!(ql&261930)?(oc=!0,e.memoizedState=n):(e=wu(),po.lanes|=e,tu|=e,t):(e=Cs(e,n,r),wr(e,t)||(oc=!0),e)}function Ts(e,t,n,r,i){var a=I.p;I.p=a!==0&&8>a?a:8;var o=F.T,s={};F.T=s,Ls(e,!1,t,n);try{var c=i(),l=F.S;l!==null&&l(s,c),typeof c==`object`&&c&&typeof c.then==`function`?Is(e,t,ga(c,r),Cu(e)):Is(e,t,r,Cu(e))}catch(n){Is(e,t,{then:function(){},status:`rejected`,reason:n},Cu())}finally{I.p=a,o!==null&&s.types!==null&&(o.types=s.types),F.T=o}}function Es(){}function Ds(e,t,n,r){if(e.tag!==5)throw Error(i(476));var a=Os(e).queue;Ts(e,a,t,te,n===null?Es:function(){return ks(e),n(r)})}function Os(e){var t=e.memoizedState;if(t!==null)return t;t={memoizedState:te,baseState:te,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:Ro,lastRenderedState:te},next:null};var n={};return t.next={memoizedState:n,baseState:n,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:Ro,lastRenderedState:n},next:null},e.memoizedState=t,e=e.alternate,e!==null&&(e.memoizedState=t),t}function ks(e){var t=Os(e);t.next===null&&(t=e.alternate.memoizedState),Is(e,t.next.queue,{},Cu())}function As(){return ta(dp)}function js(){return No().memoizedState}function Ms(){return No().memoizedState}function Ns(e){for(var t=e.return;t!==null;){switch(t.tag){case 24:case 3:var n=Cu();e=Ha(n);var r=Ua(t,e,n);r!==null&&(Tu(r,t,n),Wa(r,t,n)),t={cache:ca()},e.payload=t;return}t=t.return}}function Ps(e,t,n){var r=Cu();n={lane:r,revertLane:0,gesture:null,action:n,hasEagerState:!1,eagerState:null,next:null},Rs(e)?zs(t,n):(n=ri(e,t,n,r),n!==null&&(Tu(n,e,r),Bs(n,t,r)))}function Fs(e,t,n){Is(e,t,n,Cu())}function Is(e,t,n,r){var i={lane:r,revertLane:0,gesture:null,action:n,hasEagerState:!1,eagerState:null,next:null};if(Rs(e))zs(t,i);else{var a=e.alternate;if(e.lanes===0&&(a===null||a.lanes===0)&&(a=t.lastRenderedReducer,a!==null))try{var o=t.lastRenderedState,s=a(o,n);if(i.hasEagerState=!0,i.eagerState=s,wr(s,o))return ni(e,t,i,0),Gl===null&&L(),!1}catch{}if(n=ri(e,t,i,r),n!==null)return Tu(n,e,r),Bs(n,t,r),!0}return!1}function Ls(e,t,n,r){if(r={lane:2,revertLane:Sd(),gesture:null,action:r,hasEagerState:!1,eagerState:null,next:null},Rs(e)){if(t)throw Error(i(479))}else t=ri(e,n,r,2),t!==null&&Tu(t,e,2)}function Rs(e){var t=e.alternate;return e===po||t!==null&&t===po}function zs(e,t){_o=go=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function Bs(e,t,n){if(n&4194048){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,tt(e,n)}}var Vs={readContext:ta,use:Io,useCallback:Co,useContext:Co,useEffect:Co,useImperativeHandle:Co,useLayoutEffect:Co,useInsertionEffect:Co,useMemo:Co,useReducer:Co,useRef:Co,useState:Co,useDebugValue:Co,useDeferredValue:Co,useTransition:Co,useSyncExternalStore:Co,useId:Co,useHostTransitionStatus:Co,useFormState:Co,useActionState:Co,useOptimistic:Co,useMemoCache:Co,useCacheRefresh:Co};Vs.useEffectEvent=Co;var Hs={readContext:ta,use:Io,useCallback:function(e,t){return Mo().memoizedState=[e,t===void 0?null:t],e},useContext:ta,useEffect:fs,useImperativeHandle:function(e,t,n){n=n==null?null:n.concat([e]),us(4194308,4,vs.bind(null,t,e),n)},useLayoutEffect:function(e,t){return us(4194308,4,e,t)},useInsertionEffect:function(e,t){us(4,2,e,t)},useMemo:function(e,t){var n=Mo();t=t===void 0?null:t;var r=e();if(vo){Re(!0);try{e()}finally{Re(!1)}}return n.memoizedState=[r,t],r},useReducer:function(e,t,n){var r=Mo();if(n!==void 0){var i=n(t);if(vo){Re(!0);try{n(t)}finally{Re(!1)}}}else i=t;return r.memoizedState=r.baseState=i,e={pending:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:i},r.queue=e,e=e.dispatch=Ps.bind(null,po,e),[r.memoizedState,e]},useRef:function(e){var t=Mo();return e={current:e},t.memoizedState=e},useState:function(e){e=Jo(e);var t=e.queue,n=Fs.bind(null,po,t);return t.dispatch=n,[e.memoizedState,n]},useDebugValue:bs,useDeferredValue:function(e,t){return Cs(Mo(),e,t)},useTransition:function(){var e=Jo(!1);return e=Ts.bind(null,po,e.queue,!0,!1),Mo().memoizedState=e,[!1,e]},useSyncExternalStore:function(e,t,n){var r=po,a=Mo();if(z){if(n===void 0)throw Error(i(407));n=n()}else{if(n=t(),Gl===null)throw Error(i(349));ql&127||Uo(r,t,n)}a.memoizedState=n;var o={value:n,getSnapshot:t};return a.queue=o,fs(Go.bind(null,r,o,e),[e]),r.flags|=2048,cs(9,{destroy:void 0},Wo.bind(null,r,o,n,t),null),n},useId:function(){var e=Mo(),t=Gl.identifierPrefix;if(z){var n=Di,r=Ei;n=(r&~(1<<32-ze(r)-1)).toString(32)+n,t=`_`+t+`R_`+n,n=yo++,0<n&&(t+=`H`+n.toString(32)),t+=`_`}else n=So++,t=`_`+t+`r_`+n.toString(32)+`_`;return e.memoizedState=t},useHostTransitionStatus:As,useFormState:rs,useActionState:rs,useOptimistic:function(e){var t=Mo();t.memoizedState=t.baseState=e;var n={pending:null,lanes:0,dispatch:null,lastRenderedReducer:null,lastRenderedState:null};return t.queue=n,t=Ls.bind(null,po,!0,n),n.dispatch=t,[e,t]},useMemoCache:Lo,useCacheRefresh:function(){return Mo().memoizedState=Ns.bind(null,po)},useEffectEvent:function(e){var t=Mo(),n={impl:e};return t.memoizedState=n,function(){if(Wl&2)throw Error(i(440));return n.impl.apply(void 0,arguments)}}},Us={readContext:ta,use:Io,useCallback:xs,useContext:ta,useEffect:ps,useImperativeHandle:ys,useInsertionEffect:gs,useLayoutEffect:_s,useMemo:Ss,useReducer:zo,useRef:ls,useState:function(){return zo(Ro)},useDebugValue:bs,useDeferredValue:function(e,t){return ws(No(),mo.memoizedState,e,t)},useTransition:function(){var e=zo(Ro)[0],t=No().memoizedState;return[typeof e==`boolean`?e:Fo(e),t]},useSyncExternalStore:Ho,useId:js,useHostTransitionStatus:As,useFormState:is,useActionState:is,useOptimistic:function(e,t){return Yo(No(),mo,e,t)},useMemoCache:Lo,useCacheRefresh:Ms};Us.useEffectEvent=hs;var Ws={readContext:ta,use:Io,useCallback:xs,useContext:ta,useEffect:ps,useImperativeHandle:ys,useInsertionEffect:gs,useLayoutEffect:_s,useMemo:Ss,useReducer:Vo,useRef:ls,useState:function(){return Vo(Ro)},useDebugValue:bs,useDeferredValue:function(e,t){var n=No();return mo===null?Cs(n,e,t):ws(n,mo.memoizedState,e,t)},useTransition:function(){var e=Vo(Ro)[0],t=No().memoizedState;return[typeof e==`boolean`?e:Fo(e),t]},useSyncExternalStore:Ho,useId:js,useHostTransitionStatus:As,useFormState:ss,useActionState:ss,useOptimistic:function(e,t){var n=No();return mo===null?(n.baseState=e,[e,n.queue.dispatch]):Yo(n,mo,e,t)},useMemoCache:Lo,useCacheRefresh:Ms};Ws.useEffectEvent=hs;function Gs(e,t,n,r){t=e.memoizedState,n=n(r,t),n=n==null?t:h({},t,n),e.memoizedState=n,e.lanes===0&&(e.updateQueue.baseState=n)}var Ks={enqueueSetState:function(e,t,n){e=e._reactInternals;var r=Cu(),i=Ha(r);i.payload=t,n!=null&&(i.callback=n),t=Ua(e,i,r),t!==null&&(Tu(t,e,r),Wa(t,e,r))},enqueueReplaceState:function(e,t,n){e=e._reactInternals;var r=Cu(),i=Ha(r);i.tag=1,i.payload=t,n!=null&&(i.callback=n),t=Ua(e,i,r),t!==null&&(Tu(t,e,r),Wa(t,e,r))},enqueueForceUpdate:function(e,t){e=e._reactInternals;var n=Cu(),r=Ha(n);r.tag=2,t!=null&&(r.callback=t),t=Ua(e,r,n),t!==null&&(Tu(t,e,n),Wa(t,e,n))}};function qs(e,t,n,r,i,a,o){return e=e.stateNode,typeof e.shouldComponentUpdate==`function`?e.shouldComponentUpdate(r,a,o):t.prototype&&t.prototype.isPureReactComponent?!Tr(n,r)||!Tr(i,a):!0}function Js(e,t,n,r){e=t.state,typeof t.componentWillReceiveProps==`function`&&t.componentWillReceiveProps(n,r),typeof t.UNSAFE_componentWillReceiveProps==`function`&&t.UNSAFE_componentWillReceiveProps(n,r),t.state!==e&&Ks.enqueueReplaceState(t,t.state,null)}function Ys(e,t){var n=t;if(`ref`in t)for(var r in n={},t)r!==`ref`&&(n[r]=t[r]);if(e=e.defaultProps)for(var i in n===t&&(n=h({},n)),e)n[i]===void 0&&(n[i]=e[i]);return n}function Xs(e){Qr(e)}function Zs(e){console.error(e)}function Qs(e){Qr(e)}function $s(e,t){try{var n=e.onUncaughtError;n(t.value,{componentStack:t.stack})}catch(e){setTimeout(function(){throw e})}}function ec(e,t,n){try{var r=e.onCaughtError;r(n.value,{componentStack:n.stack,errorBoundary:t.tag===1?t.stateNode:null})}catch(e){setTimeout(function(){throw e})}}function tc(e,t,n){return n=Ha(n),n.tag=3,n.payload={element:null},n.callback=function(){$s(e,t)},n}function nc(e){return e=Ha(e),e.tag=3,e}function rc(e,t,n,r){var i=n.type.getDerivedStateFromError;if(typeof i==`function`){var a=r.value;e.payload=function(){return i(a)},e.callback=function(){ec(t,n,r)}}var o=n.stateNode;o!==null&&typeof o.componentDidCatch==`function`&&(e.callback=function(){ec(t,n,r),typeof i!=`function`&&(pu===null?pu=new Set([this]):pu.add(this));var e=r.stack;this.componentDidCatch(r.value,{componentStack:e===null?``:e})})}function ic(e,t,n,r,a){if(n.flags|=32768,typeof r==`object`&&r&&typeof r.then==`function`){if(t=n.alternate,t!==null&&Qi(t,n,a,!0),n=no.current,n!==null){switch(n.tag){case 31:case 13:return ro===null?Lu():n.alternate===null&&eu===0&&(eu=3),n.flags&=-257,n.flags|=65536,n.lanes=a,r===wa?n.flags|=16384:(t=n.updateQueue,t===null?n.updateQueue=new Set([r]):t.add(r),nd(e,r,a)),!1;case 22:return n.flags|=65536,r===wa?n.flags|=16384:(t=n.updateQueue,t===null?(t={transitions:null,markerInstances:null,retryQueue:new Set([r])},n.updateQueue=t):(n=t.retryQueue,n===null?t.retryQueue=new Set([r]):n.add(r)),nd(e,r,a)),!1}throw Error(i(435,n.tag))}return nd(e,r,a),Lu(),!1}if(z)return t=no.current,t===null?(r!==Li&&(t=Error(i(423),{cause:r}),Wi(R(t,n))),e=e.current.alternate,e.flags|=65536,a&=-a,e.lanes|=a,r=R(r,n),a=tc(e.stateNode,r,a),Ga(e,a),eu!==4&&(eu=2)):(!(t.flags&65536)&&(t.flags|=256),t.flags|=65536,t.lanes=a,r!==Li&&(e=Error(i(422),{cause:r}),Wi(R(e,n)))),!1;var o=Error(i(520),{cause:r});if(o=R(o,n),ou===null?ou=[o]:ou.push(o),eu!==4&&(eu=2),t===null)return!0;r=R(r,n),n=t;do{switch(n.tag){case 3:return n.flags|=65536,e=a&-a,n.lanes|=e,e=tc(n.stateNode,r,e),Ga(n,e),!1;case 1:if(t=n.type,o=n.stateNode,!(n.flags&128)&&(typeof t.getDerivedStateFromError==`function`||o!==null&&typeof o.componentDidCatch==`function`&&(pu===null||!pu.has(o))))return n.flags|=65536,a&=-a,n.lanes|=a,a=nc(a),rc(a,e,n,r),Ga(n,a),!1}n=n.return}while(n!==null);return!1}var ac=Error(i(461)),oc=!1;function sc(e,t,n,r){t.child=e===null?Ra(t,null,n,r):La(t,e.child,n,r)}function cc(e,t,n,r,i){n=n.render;var a=t.ref;if(`ref`in r){var o={};for(var s in r)s!==`ref`&&(o[s]=r[s])}else o=r;return ea(t),r=To(e,t,n,o,a,i),s=ko(),e!==null&&!oc?(Ao(e,t,i),Mc(e,t,i)):(z&&s&&Ai(t),t.flags|=1,sc(e,t,r,i),t.child)}function lc(e,t,n,r,i){if(e===null){var a=n.type;return typeof a==`function`&&!ui(a)&&a.defaultProps===void 0&&n.compare===null?(t.tag=15,t.type=a,uc(e,t,a,r,i)):(e=pi(n.type,null,r,t,t.mode,i),e.ref=t.ref,e.return=t,t.child=e)}if(a=e.child,!Nc(e,i)){var o=a.memoizedProps;if(n=n.compare,n=n===null?Tr:n,n(o,r)&&e.ref===t.ref)return Mc(e,t,i)}return t.flags|=1,e=di(a,r),e.ref=t.ref,e.return=t,t.child=e}function uc(e,t,n,r,i){if(e!==null){var a=e.memoizedProps;if(Tr(a,r)&&e.ref===t.ref)if(oc=!1,t.pendingProps=r=a,Nc(e,i))e.flags&131072&&(oc=!0);else return t.lanes=e.lanes,Mc(e,t,i)}return vc(e,t,n,r,i)}function dc(e,t,n,r){var i=r.children,a=e===null?null:e.memoizedState;if(e===null&&t.stateNode===null&&(t.stateNode={_visibility:1,_pendingMarkers:null,_retryCache:null,_transitions:null}),r.mode===`hidden`){if(t.flags&128){if(a=a===null?n:a.baseLanes|n,e!==null){for(r=t.child=e.child,i=0;r!==null;)i=i|r.lanes|r.childLanes,r=r.sibling;r=i&~a}else r=0,t.child=null;return pc(e,t,a,n,r)}if(n&536870912)t.memoizedState={baseLanes:0,cachePool:null},e!==null&&ya(t,a===null?null:a.cachePool),a===null?eo():$a(t,a),oo(t);else return r=t.lanes=536870912,pc(e,t,a===null?n:a.baseLanes|n,n,r)}else a===null?(e!==null&&ya(t,null),eo(),so(t)):(ya(t,a.cachePool),$a(t,a),so(t),t.memoizedState=null);return sc(e,t,i,n),t.child}function fc(e,t){return e!==null&&e.tag===22||t.stateNode!==null||(t.stateNode={_visibility:1,_pendingMarkers:null,_retryCache:null,_transitions:null}),t.sibling}function pc(e,t,n,r,i){var a=va();return a=a===null?null:{parent:sa._currentValue,pool:a},t.memoizedState={baseLanes:n,cachePool:a},e!==null&&ya(t,null),eo(),oo(t),e!==null&&Qi(e,t,r,!0),t.childLanes=i,null}function mc(e,t){return t=Dc({mode:t.mode,children:t.children},e.mode),t.ref=e.ref,e.child=t,t.return=e,t}function hc(e,t,n){return La(t,e.child,null,n),e=mc(t,t.pendingProps),e.flags|=2,co(t),t.memoizedState=null,e}function gc(e,t,n){var r=t.pendingProps,a=(t.flags&128)!=0;if(t.flags&=-129,e===null){if(z){if(r.mode===`hidden`)return e=mc(t,r),t.lanes=536870912,fc(null,e);if(ao(t),(e=Pi)?(e=_f(e,Ii),e=e!==null&&e.data===`&`?e:null,e!==null&&(t.memoizedState={dehydrated:e,treeContext:Ti===null?null:{id:Ei,overflow:Di},retryLane:536870912,hydrationErrors:null},n=gi(e),n.return=t,t.child=n,Ni=t,Pi=null)):e=null,e===null)throw Ri(t);return t.lanes=536870912,null}return mc(t,r)}var o=e.memoizedState;if(o!==null){var s=o.dehydrated;if(ao(t),a)if(t.flags&256)t.flags&=-257,t=hc(e,t,n);else if(t.memoizedState!==null)t.child=e.child,t.flags|=128,t=null;else throw Error(i(558));else if(oc||Qi(e,t,n,!1),a=(n&e.childLanes)!==0,oc||a){if(r=Gl,r!==null&&(s=nt(r,n),s!==0&&s!==o.retryLane))throw o.retryLane=s,ii(e,s),Tu(r,e,s),ac;Lu(),t=hc(e,t,n)}else e=o.treeContext,Pi=xf(s.nextSibling),Ni=t,z=!0,Fi=null,Ii=!1,e!==null&&Mi(t,e),t=mc(t,r),t.flags|=4096;return t}return e=di(e.child,{mode:r.mode,children:r.children}),e.ref=t.ref,t.child=e,e.return=t,e}function _c(e,t){var n=t.ref;if(n===null)e!==null&&e.ref!==null&&(t.flags|=4194816);else{if(typeof n!=`function`&&typeof n!=`object`)throw Error(i(284));(e===null||e.ref!==n)&&(t.flags|=4194816)}}function vc(e,t,n,r,i){return ea(t),n=To(e,t,n,r,void 0,i),r=ko(),e!==null&&!oc?(Ao(e,t,i),Mc(e,t,i)):(z&&r&&Ai(t),t.flags|=1,sc(e,t,n,i),t.child)}function yc(e,t,n,r,i,a){return ea(t),t.updateQueue=null,n=Do(t,r,n,i),Eo(e),r=ko(),e!==null&&!oc?(Ao(e,t,a),Mc(e,t,a)):(z&&r&&Ai(t),t.flags|=1,sc(e,t,n,a),t.child)}function bc(e,t,n,r,i){if(ea(t),t.stateNode===null){var a=si,o=n.contextType;typeof o==`object`&&o&&(a=ta(o)),a=new n(r,a),t.memoizedState=a.state!==null&&a.state!==void 0?a.state:null,a.updater=Ks,t.stateNode=a,a._reactInternals=t,a=t.stateNode,a.props=r,a.state=t.memoizedState,a.refs={},Ba(t),o=n.contextType,a.context=typeof o==`object`&&o?ta(o):si,a.state=t.memoizedState,o=n.getDerivedStateFromProps,typeof o==`function`&&(Gs(t,n,o,r),a.state=t.memoizedState),typeof n.getDerivedStateFromProps==`function`||typeof a.getSnapshotBeforeUpdate==`function`||typeof a.UNSAFE_componentWillMount!=`function`&&typeof a.componentWillMount!=`function`||(o=a.state,typeof a.componentWillMount==`function`&&a.componentWillMount(),typeof a.UNSAFE_componentWillMount==`function`&&a.UNSAFE_componentWillMount(),o!==a.state&&Ks.enqueueReplaceState(a,a.state,null),Ja(t,r,a,i),qa(),a.state=t.memoizedState),typeof a.componentDidMount==`function`&&(t.flags|=4194308),r=!0}else if(e===null){a=t.stateNode;var s=t.memoizedProps,c=Ys(n,s);a.props=c;var l=a.context,u=n.contextType;o=si,typeof u==`object`&&u&&(o=ta(u));var d=n.getDerivedStateFromProps;u=typeof d==`function`||typeof a.getSnapshotBeforeUpdate==`function`,s=t.pendingProps!==s,u||typeof a.UNSAFE_componentWillReceiveProps!=`function`&&typeof a.componentWillReceiveProps!=`function`||(s||l!==o)&&Js(t,a,r,o),za=!1;var f=t.memoizedState;a.state=f,Ja(t,r,a,i),qa(),l=t.memoizedState,s||f!==l||za?(typeof d==`function`&&(Gs(t,n,d,r),l=t.memoizedState),(c=za||qs(t,n,c,r,f,l,o))?(u||typeof a.UNSAFE_componentWillMount!=`function`&&typeof a.componentWillMount!=`function`||(typeof a.componentWillMount==`function`&&a.componentWillMount(),typeof a.UNSAFE_componentWillMount==`function`&&a.UNSAFE_componentWillMount()),typeof a.componentDidMount==`function`&&(t.flags|=4194308)):(typeof a.componentDidMount==`function`&&(t.flags|=4194308),t.memoizedProps=r,t.memoizedState=l),a.props=r,a.state=l,a.context=o,r=c):(typeof a.componentDidMount==`function`&&(t.flags|=4194308),r=!1)}else{a=t.stateNode,Va(e,t),o=t.memoizedProps,u=Ys(n,o),a.props=u,d=t.pendingProps,f=a.context,l=n.contextType,c=si,typeof l==`object`&&l&&(c=ta(l)),s=n.getDerivedStateFromProps,(l=typeof s==`function`||typeof a.getSnapshotBeforeUpdate==`function`)||typeof a.UNSAFE_componentWillReceiveProps!=`function`&&typeof a.componentWillReceiveProps!=`function`||(o!==d||f!==c)&&Js(t,a,r,c),za=!1,f=t.memoizedState,a.state=f,Ja(t,r,a,i),qa();var p=t.memoizedState;o!==d||f!==p||za||e!==null&&e.dependencies!==null&&$i(e.dependencies)?(typeof s==`function`&&(Gs(t,n,s,r),p=t.memoizedState),(u=za||qs(t,n,u,r,f,p,c)||e!==null&&e.dependencies!==null&&$i(e.dependencies))?(l||typeof a.UNSAFE_componentWillUpdate!=`function`&&typeof a.componentWillUpdate!=`function`||(typeof a.componentWillUpdate==`function`&&a.componentWillUpdate(r,p,c),typeof a.UNSAFE_componentWillUpdate==`function`&&a.UNSAFE_componentWillUpdate(r,p,c)),typeof a.componentDidUpdate==`function`&&(t.flags|=4),typeof a.getSnapshotBeforeUpdate==`function`&&(t.flags|=1024)):(typeof a.componentDidUpdate!=`function`||o===e.memoizedProps&&f===e.memoizedState||(t.flags|=4),typeof a.getSnapshotBeforeUpdate!=`function`||o===e.memoizedProps&&f===e.memoizedState||(t.flags|=1024),t.memoizedProps=r,t.memoizedState=p),a.props=r,a.state=p,a.context=c,r=u):(typeof a.componentDidUpdate!=`function`||o===e.memoizedProps&&f===e.memoizedState||(t.flags|=4),typeof a.getSnapshotBeforeUpdate!=`function`||o===e.memoizedProps&&f===e.memoizedState||(t.flags|=1024),r=!1)}return a=r,_c(e,t),r=(t.flags&128)!=0,a||r?(a=t.stateNode,n=r&&typeof n.getDerivedStateFromError!=`function`?null:a.render(),t.flags|=1,e!==null&&r?(t.child=La(t,e.child,null,i),t.child=La(t,null,n,i)):sc(e,t,n,i),t.memoizedState=a.state,e=t.child):e=Mc(e,t,i),e}function xc(e,t,n,r){return Hi(),t.flags|=256,sc(e,t,n,r),t.child}var Sc={dehydrated:null,treeContext:null,retryLane:0,hydrationErrors:null};function Cc(e){return{baseLanes:e,cachePool:ba()}}function wc(e,t,n){return e=e===null?0:e.childLanes&~n,t&&(e|=iu),e}function Tc(e,t,n){var r=t.pendingProps,a=!1,o=(t.flags&128)!=0,s;if((s=o)||(s=e!==null&&e.memoizedState===null?!1:(lo.current&2)!=0),s&&(a=!0,t.flags&=-129),s=(t.flags&32)!=0,t.flags&=-33,e===null){if(z){if(a?io(t):so(t),(e=Pi)?(e=_f(e,Ii),e=e!==null&&e.data!==`&`?e:null,e!==null&&(t.memoizedState={dehydrated:e,treeContext:Ti===null?null:{id:Ei,overflow:Di},retryLane:536870912,hydrationErrors:null},n=gi(e),n.return=t,t.child=n,Ni=t,Pi=null)):e=null,e===null)throw Ri(t);return yf(e)?t.lanes=32:t.lanes=536870912,null}var c=r.children;return r=r.fallback,a?(so(t),a=t.mode,c=Dc({mode:`hidden`,children:c},a),r=mi(r,a,n,null),c.return=t,r.return=t,c.sibling=r,t.child=c,r=t.child,r.memoizedState=Cc(n),r.childLanes=wc(e,s,n),t.memoizedState=Sc,fc(null,r)):(io(t),Ec(t,c))}var l=e.memoizedState;if(l!==null&&(c=l.dehydrated,c!==null)){if(o)t.flags&256?(io(t),t.flags&=-257,t=Oc(e,t,n)):t.memoizedState===null?(so(t),c=r.fallback,a=t.mode,r=Dc({mode:`visible`,children:r.children},a),c=mi(c,a,n,null),c.flags|=2,r.return=t,c.return=t,r.sibling=c,t.child=r,La(t,e.child,null,n),r=t.child,r.memoizedState=Cc(n),r.childLanes=wc(e,s,n),t.memoizedState=Sc,t=fc(null,r)):(so(t),t.child=e.child,t.flags|=128,t=null);else if(io(t),yf(c)){if(s=c.nextSibling&&c.nextSibling.dataset,s)var u=s.dgst;s=u,r=Error(i(419)),r.stack=``,r.digest=s,Wi({value:r,source:null,stack:null}),t=Oc(e,t,n)}else if(oc||Qi(e,t,n,!1),s=(n&e.childLanes)!==0,oc||s){if(s=Gl,s!==null&&(r=nt(s,n),r!==0&&r!==l.retryLane))throw l.retryLane=r,ii(e,r),Tu(s,e,r),ac;vf(c)||Lu(),t=Oc(e,t,n)}else vf(c)?(t.flags|=192,t.child=e.child,t=null):(e=l.treeContext,Pi=xf(c.nextSibling),Ni=t,z=!0,Fi=null,Ii=!1,e!==null&&Mi(t,e),t=Ec(t,r.children),t.flags|=4096);return t}return a?(so(t),c=r.fallback,a=t.mode,l=e.child,u=l.sibling,r=di(l,{mode:`hidden`,children:r.children}),r.subtreeFlags=l.subtreeFlags&65011712,u===null?(c=mi(c,a,n,null),c.flags|=2):c=di(u,c),c.return=t,r.return=t,r.sibling=c,t.child=r,fc(null,r),r=t.child,c=e.child.memoizedState,c===null?c=Cc(n):(a=c.cachePool,a===null?a=ba():(l=sa._currentValue,a=a.parent===l?a:{parent:l,pool:l}),c={baseLanes:c.baseLanes|n,cachePool:a}),r.memoizedState=c,r.childLanes=wc(e,s,n),t.memoizedState=Sc,fc(e.child,r)):(io(t),n=e.child,e=n.sibling,n=di(n,{mode:`visible`,children:r.children}),n.return=t,n.sibling=null,e!==null&&(s=t.deletions,s===null?(t.deletions=[e],t.flags|=16):s.push(e)),t.child=n,t.memoizedState=null,n)}function Ec(e,t){return t=Dc({mode:`visible`,children:t},e.mode),t.return=e,e.child=t}function Dc(e,t){return e=li(22,e,null,t),e.lanes=0,e}function Oc(e,t,n){return La(t,e.child,null,n),e=Ec(t,t.pendingProps.children),e.flags|=2,t.memoizedState=null,e}function kc(e,t,n){e.lanes|=t;var r=e.alternate;r!==null&&(r.lanes|=t),Xi(e.return,t,n)}function Ac(e,t,n,r,i,a){var o=e.memoizedState;o===null?e.memoizedState={isBackwards:t,rendering:null,renderingStartTime:0,last:r,tail:n,tailMode:i,treeForkCount:a}:(o.isBackwards=t,o.rendering=null,o.renderingStartTime=0,o.last=r,o.tail=n,o.tailMode=i,o.treeForkCount=a)}function jc(e,t,n){var r=t.pendingProps,i=r.revealOrder,a=r.tail;r=r.children;var o=lo.current,s=(o&2)!=0;if(s?(o=o&1|2,t.flags|=128):o&=1,oe(lo,o),sc(e,t,r,n),r=z?Si:0,!s&&e!==null&&e.flags&128)a:for(e=t.child;e!==null;){if(e.tag===13)e.memoizedState!==null&&kc(e,n,t);else if(e.tag===19)kc(e,n,t);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===t)break a;for(;e.sibling===null;){if(e.return===null||e.return===t)break a;e=e.return}e.sibling.return=e.return,e=e.sibling}switch(i){case`forwards`:for(n=t.child,i=null;n!==null;)e=n.alternate,e!==null&&uo(e)===null&&(i=n),n=n.sibling;n=i,n===null?(i=t.child,t.child=null):(i=n.sibling,n.sibling=null),Ac(t,!1,i,n,a,r);break;case`backwards`:case`unstable_legacy-backwards`:for(n=null,i=t.child,t.child=null;i!==null;){if(e=i.alternate,e!==null&&uo(e)===null){t.child=i;break}e=i.sibling,i.sibling=n,n=i,i=e}Ac(t,!0,n,null,a,r);break;case`together`:Ac(t,!1,null,null,void 0,r);break;default:t.memoizedState=null}return t.child}function Mc(e,t,n){if(e!==null&&(t.dependencies=e.dependencies),tu|=t.lanes,(n&t.childLanes)===0)if(e!==null){if(Qi(e,t,n,!1),(n&t.childLanes)===0)return null}else return null;if(e!==null&&t.child!==e.child)throw Error(i(153));if(t.child!==null){for(e=t.child,n=di(e,e.pendingProps),t.child=n,n.return=t;e.sibling!==null;)e=e.sibling,n=n.sibling=di(e,e.pendingProps),n.return=t;n.sibling=null}return t.child}function Nc(e,t){return(e.lanes&t)===0?(e=e.dependencies,!!(e!==null&&$i(e))):!0}function Pc(e,t,n){switch(t.tag){case 3:de(t,t.stateNode.containerInfo),Ji(t,sa,e.memoizedState.cache),Hi();break;case 27:case 5:pe(t);break;case 4:de(t,t.stateNode.containerInfo);break;case 10:Ji(t,t.type,t.memoizedProps.value);break;case 31:if(t.memoizedState!==null)return t.flags|=128,ao(t),null;break;case 13:var r=t.memoizedState;if(r!==null)return r.dehydrated===null?(n&t.child.childLanes)===0?(io(t),e=Mc(e,t,n),e===null?null:e.sibling):Tc(e,t,n):(io(t),t.flags|=128,null);io(t);break;case 19:var i=(e.flags&128)!=0;if(r=(n&t.childLanes)!==0,r||=(Qi(e,t,n,!1),(n&t.childLanes)!==0),i){if(r)return jc(e,t,n);t.flags|=128}if(i=t.memoizedState,i!==null&&(i.rendering=null,i.tail=null,i.lastEffect=null),oe(lo,lo.current),r)break;return null;case 22:return t.lanes=0,dc(e,t,n,t.pendingProps);case 24:Ji(t,sa,e.memoizedState.cache)}return Mc(e,t,n)}function Fc(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps)oc=!0;else{if(!Nc(e,n)&&!(t.flags&128))return oc=!1,Pc(e,t,n);oc=!!(e.flags&131072)}else oc=!1,z&&t.flags&1048576&&ki(t,Si,t.index);switch(t.lanes=0,t.tag){case 16:a:{var r=t.pendingProps;if(e=Da(t.elementType),t.type=e,typeof e==`function`)ui(e)?(r=Ys(e,r),t.tag=1,t=bc(null,t,e,r,n)):(t.tag=0,t=vc(null,t,e,r,n));else{if(e!=null){var a=e.$$typeof;if(a===w){t.tag=11,t=cc(null,t,e,r,n);break a}else if(a===D){t.tag=14,t=lc(null,t,e,r,n);break a}}throw t=N(e)||e,Error(i(306,t,``))}}return t;case 0:return vc(e,t,t.type,t.pendingProps,n);case 1:return r=t.type,a=Ys(r,t.pendingProps),bc(e,t,r,a,n);case 3:a:{if(de(t,t.stateNode.containerInfo),e===null)throw Error(i(387));r=t.pendingProps;var o=t.memoizedState;a=o.element,Va(e,t),Ja(t,r,null,n);var s=t.memoizedState;if(r=s.cache,Ji(t,sa,r),r!==o.cache&&Zi(t,[sa],n,!0),qa(),r=s.element,o.isDehydrated)if(o={element:r,isDehydrated:!1,cache:s.cache},t.updateQueue.baseState=o,t.memoizedState=o,t.flags&256){t=xc(e,t,r,n);break a}else if(r!==a){a=R(Error(i(424)),t),Wi(a),t=xc(e,t,r,n);break a}else{switch(e=t.stateNode.containerInfo,e.nodeType){case 9:e=e.body;break;default:e=e.nodeName===`HTML`?e.ownerDocument.body:e}for(Pi=xf(e.firstChild),Ni=t,z=!0,Fi=null,Ii=!0,n=Ra(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling}else{if(Hi(),r===a){t=Mc(e,t,n);break a}sc(e,t,r,n)}t=t.child}return t;case 26:return _c(e,t),e===null?(n=Hf(t.type,null,t.pendingProps,null))?t.memoizedState=n:z||(n=t.type,e=t.pendingProps,r=$d(le.current).createElement(n),r[ct]=t,r[lt]=e,qd(r,n,e),xt(r),t.stateNode=r):t.memoizedState=Hf(t.type,e.memoizedProps,t.pendingProps,e.memoizedState),null;case 27:return pe(t),e===null&&z&&(r=t.stateNode=Tf(t.type,t.pendingProps,le.current),Ni=t,Ii=!0,a=Pi,df(t.type)?(Sf=a,Pi=xf(r.firstChild)):Pi=a),sc(e,t,t.pendingProps.children,n),_c(e,t),e===null&&(t.flags|=4194304),t.child;case 5:return e===null&&z&&((a=r=Pi)&&(r=hf(r,t.type,t.pendingProps,Ii),r===null?a=!1:(t.stateNode=r,Ni=t,Pi=xf(r.firstChild),Ii=!1,a=!0)),a||Ri(t)),pe(t),a=t.type,o=t.pendingProps,s=e===null?null:e.memoizedProps,r=o.children,nf(a,o)?r=null:s!==null&&nf(a,s)&&(t.flags|=32),t.memoizedState!==null&&(a=To(e,t,Oo,null,null,n),dp._currentValue=a),_c(e,t),sc(e,t,r,n),t.child;case 6:return e===null&&z&&((e=n=Pi)&&(n=gf(n,t.pendingProps,Ii),n===null?e=!1:(t.stateNode=n,Ni=t,Pi=null,e=!0)),e||Ri(t)),null;case 13:return Tc(e,t,n);case 4:return de(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=La(t,null,r,n):sc(e,t,r,n),t.child;case 11:return cc(e,t,t.type,t.pendingProps,n);case 7:return sc(e,t,t.pendingProps,n),t.child;case 8:return sc(e,t,t.pendingProps.children,n),t.child;case 12:return sc(e,t,t.pendingProps.children,n),t.child;case 10:return r=t.pendingProps,Ji(t,t.type,r.value),sc(e,t,r.children,n),t.child;case 9:return a=t.type._context,r=t.pendingProps.children,ea(t),a=ta(a),r=r(a),t.flags|=1,sc(e,t,r,n),t.child;case 14:return lc(e,t,t.type,t.pendingProps,n);case 15:return uc(e,t,t.type,t.pendingProps,n);case 19:return jc(e,t,n);case 31:return gc(e,t,n);case 22:return dc(e,t,n,t.pendingProps);case 24:return ea(t),r=ta(sa),e===null?(a=va(),a===null&&(a=Gl,o=ca(),a.pooledCache=o,o.refCount++,o!==null&&(a.pooledCacheLanes|=n),a=o),t.memoizedState={parent:r,cache:a},Ba(t),Ji(t,sa,a)):((e.lanes&n)!==0&&(Va(e,t),Ja(t,null,null,n),qa()),a=e.memoizedState,o=t.memoizedState,a.parent===r?(r=o.cache,Ji(t,sa,r),r!==a.cache&&Zi(t,[sa],n,!0)):(a={parent:r,cache:r},t.memoizedState=a,t.lanes===0&&(t.memoizedState=t.updateQueue.baseState=a),Ji(t,sa,r))),sc(e,t,t.pendingProps.children,n),t.child;case 29:throw t.pendingProps}throw Error(i(156,t.tag))}function Ic(e){e.flags|=4}function Lc(e,t,n,r,i){if((t=(e.mode&32)!=0)&&(t=!1),t){if(e.flags|=16777216,(i&335544128)===i)if(e.stateNode.complete)e.flags|=8192;else if(Pu())e.flags|=8192;else throw Oa=wa,Sa}else e.flags&=-16777217}function Rc(e,t){if(t.type!==`stylesheet`||t.state.loading&4)e.flags&=-16777217;else if(e.flags|=16777216,!rp(t))if(Pu())e.flags|=8192;else throw Oa=wa,Sa}function zc(e,t){t!==null&&(e.flags|=4),e.flags&16384&&(t=e.tag===22?536870912:Xe(),e.lanes|=t,au|=t)}function Bc(e,t){if(!z)switch(e.tailMode){case`hidden`:t=e.tail;for(var n=null;t!==null;)t.alternate!==null&&(n=t),t=t.sibling;n===null?e.tail=null:n.sibling=null;break;case`collapsed`:n=e.tail;for(var r=null;n!==null;)n.alternate!==null&&(r=n),n=n.sibling;r===null?t||e.tail===null?e.tail=null:e.tail.sibling=null:r.sibling=null}}function Vc(e){var t=e.alternate!==null&&e.alternate.child===e.child,n=0,r=0;if(t)for(var i=e.child;i!==null;)n|=i.lanes|i.childLanes,r|=i.subtreeFlags&65011712,r|=i.flags&65011712,i.return=e,i=i.sibling;else for(i=e.child;i!==null;)n|=i.lanes|i.childLanes,r|=i.subtreeFlags,r|=i.flags,i.return=e,i=i.sibling;return e.subtreeFlags|=r,e.childLanes=n,t}function Hc(e,t,n){var r=t.pendingProps;switch(ji(t),t.tag){case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return Vc(t),null;case 1:return Vc(t),null;case 3:return n=t.stateNode,r=null,e!==null&&(r=e.memoizedState.cache),t.memoizedState.cache!==r&&(t.flags|=2048),Yi(sa),fe(),n.pendingContext&&(n.context=n.pendingContext,n.pendingContext=null),(e===null||e.child===null)&&(Vi(t)?Ic(t):e===null||e.memoizedState.isDehydrated&&!(t.flags&256)||(t.flags|=1024,Ui())),Vc(t),null;case 26:var a=t.type,o=t.memoizedState;return e===null?(Ic(t),o===null?(Vc(t),Lc(t,a,null,r,n)):(Vc(t),Rc(t,o))):o?o===e.memoizedState?(Vc(t),t.flags&=-16777217):(Ic(t),Vc(t),Rc(t,o)):(e=e.memoizedProps,e!==r&&Ic(t),Vc(t),Lc(t,a,e,r,n)),null;case 27:if(me(t),n=le.current,a=t.type,e!==null&&t.stateNode!=null)e.memoizedProps!==r&&Ic(t);else{if(!r){if(t.stateNode===null)throw Error(i(166));return Vc(t),null}e=se.current,Vi(t)?zi(t,e):(e=Tf(a,r,n),t.stateNode=e,Ic(t))}return Vc(t),null;case 5:if(me(t),a=t.type,e!==null&&t.stateNode!=null)e.memoizedProps!==r&&Ic(t);else{if(!r){if(t.stateNode===null)throw Error(i(166));return Vc(t),null}if(o=se.current,Vi(t))zi(t,o);else{var s=$d(le.current);switch(o){case 1:o=s.createElementNS(`http://www.w3.org/2000/svg`,a);break;case 2:o=s.createElementNS(`http://www.w3.org/1998/Math/MathML`,a);break;default:switch(a){case`svg`:o=s.createElementNS(`http://www.w3.org/2000/svg`,a);break;case`math`:o=s.createElementNS(`http://www.w3.org/1998/Math/MathML`,a);break;case`script`:o=s.createElement(`div`),o.innerHTML=`<script><\/script>`,o=o.removeChild(o.firstChild);break;case`select`:o=typeof r.is==`string`?s.createElement(`select`,{is:r.is}):s.createElement(`select`),r.multiple?o.multiple=!0:r.size&&(o.size=r.size);break;default:o=typeof r.is==`string`?s.createElement(a,{is:r.is}):s.createElement(a)}}o[ct]=t,o[lt]=r;a:for(s=t.child;s!==null;){if(s.tag===5||s.tag===6)o.appendChild(s.stateNode);else if(s.tag!==4&&s.tag!==27&&s.child!==null){s.child.return=s,s=s.child;continue}if(s===t)break a;for(;s.sibling===null;){if(s.return===null||s.return===t)break a;s=s.return}s.sibling.return=s.return,s=s.sibling}t.stateNode=o;a:switch(qd(o,a,r),a){case`button`:case`input`:case`select`:case`textarea`:r=!!r.autoFocus;break a;case`img`:r=!0;break a;default:r=!1}r&&Ic(t)}}return Vc(t),Lc(t,t.type,e===null?null:e.memoizedProps,t.pendingProps,n),null;case 6:if(e&&t.stateNode!=null)e.memoizedProps!==r&&Ic(t);else{if(typeof r!=`string`&&t.stateNode===null)throw Error(i(166));if(e=le.current,Vi(t)){if(e=t.stateNode,n=t.memoizedProps,r=null,a=Ni,a!==null)switch(a.tag){case 27:case 5:r=a.memoizedProps}e[ct]=t,e=!!(e.nodeValue===n||r!==null&&!0===r.suppressHydrationWarning||Wd(e.nodeValue,n)),e||Ri(t,!0)}else e=$d(e).createTextNode(r),e[ct]=t,t.stateNode=e}return Vc(t),null;case 31:if(n=t.memoizedState,e===null||e.memoizedState!==null){if(r=Vi(t),n!==null){if(e===null){if(!r)throw Error(i(318));if(e=t.memoizedState,e=e===null?null:e.dehydrated,!e)throw Error(i(557));e[ct]=t}else Hi(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;Vc(t),e=!1}else n=Ui(),e!==null&&e.memoizedState!==null&&(e.memoizedState.hydrationErrors=n),e=!0;if(!e)return t.flags&256?(co(t),t):(co(t),null);if(t.flags&128)throw Error(i(558))}return Vc(t),null;case 13:if(r=t.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(a=Vi(t),r!==null&&r.dehydrated!==null){if(e===null){if(!a)throw Error(i(318));if(a=t.memoizedState,a=a===null?null:a.dehydrated,!a)throw Error(i(317));a[ct]=t}else Hi(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;Vc(t),a=!1}else a=Ui(),e!==null&&e.memoizedState!==null&&(e.memoizedState.hydrationErrors=a),a=!0;if(!a)return t.flags&256?(co(t),t):(co(t),null)}return co(t),t.flags&128?(t.lanes=n,t):(n=r!==null,e=e!==null&&e.memoizedState!==null,n&&(r=t.child,a=null,r.alternate!==null&&r.alternate.memoizedState!==null&&r.alternate.memoizedState.cachePool!==null&&(a=r.alternate.memoizedState.cachePool.pool),o=null,r.memoizedState!==null&&r.memoizedState.cachePool!==null&&(o=r.memoizedState.cachePool.pool),o!==a&&(r.flags|=2048)),n!==e&&n&&(t.child.flags|=8192),zc(t,t.updateQueue),Vc(t),null);case 4:return fe(),e===null&&Pd(t.stateNode.containerInfo),Vc(t),null;case 10:return Yi(t.type),Vc(t),null;case 19:if(ae(lo),r=t.memoizedState,r===null)return Vc(t),null;if(a=(t.flags&128)!=0,o=r.rendering,o===null)if(a)Bc(r,!1);else{if(eu!==0||e!==null&&e.flags&128)for(e=t.child;e!==null;){if(o=uo(e),o!==null){for(t.flags|=128,Bc(r,!1),e=o.updateQueue,t.updateQueue=e,zc(t,e),t.subtreeFlags=0,e=n,n=t.child;n!==null;)fi(n,e),n=n.sibling;return oe(lo,lo.current&1|2),z&&Oi(t,r.treeForkCount),t.child}e=e.sibling}r.tail!==null&&De()>du&&(t.flags|=128,a=!0,Bc(r,!1),t.lanes=4194304)}else{if(!a)if(e=uo(o),e!==null){if(t.flags|=128,a=!0,e=e.updateQueue,t.updateQueue=e,zc(t,e),Bc(r,!0),r.tail===null&&r.tailMode===`hidden`&&!o.alternate&&!z)return Vc(t),null}else 2*De()-r.renderingStartTime>du&&n!==536870912&&(t.flags|=128,a=!0,Bc(r,!1),t.lanes=4194304);r.isBackwards?(o.sibling=t.child,t.child=o):(e=r.last,e===null?t.child=o:e.sibling=o,r.last=o)}return r.tail===null?(Vc(t),null):(e=r.tail,r.rendering=e,r.tail=e.sibling,r.renderingStartTime=De(),e.sibling=null,n=lo.current,oe(lo,a?n&1|2:n&1),z&&Oi(t,r.treeForkCount),e);case 22:case 23:return co(t),to(),r=t.memoizedState!==null,e===null?r&&(t.flags|=8192):e.memoizedState!==null!==r&&(t.flags|=8192),r?n&536870912&&!(t.flags&128)&&(Vc(t),t.subtreeFlags&6&&(t.flags|=8192)):Vc(t),n=t.updateQueue,n!==null&&zc(t,n.retryQueue),n=null,e!==null&&e.memoizedState!==null&&e.memoizedState.cachePool!==null&&(n=e.memoizedState.cachePool.pool),r=null,t.memoizedState!==null&&t.memoizedState.cachePool!==null&&(r=t.memoizedState.cachePool.pool),r!==n&&(t.flags|=2048),e!==null&&ae(_a),null;case 24:return n=null,e!==null&&(n=e.memoizedState.cache),t.memoizedState.cache!==n&&(t.flags|=2048),Yi(sa),Vc(t),null;case 25:return null;case 30:return null}throw Error(i(156,t.tag))}function Uc(e,t){switch(ji(t),t.tag){case 1:return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return Yi(sa),fe(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 26:case 27:case 5:return me(t),null;case 31:if(t.memoizedState!==null){if(co(t),t.alternate===null)throw Error(i(340));Hi()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 13:if(co(t),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(i(340));Hi()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return ae(lo),null;case 4:return fe(),null;case 10:return Yi(t.type),null;case 22:case 23:return co(t),to(),e!==null&&ae(_a),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 24:return Yi(sa),null;case 25:return null;default:return null}}function Wc(e,t){switch(ji(t),t.tag){case 3:Yi(sa),fe();break;case 26:case 27:case 5:me(t);break;case 4:fe();break;case 31:t.memoizedState!==null&&co(t);break;case 13:co(t);break;case 19:ae(lo);break;case 10:Yi(t.type);break;case 22:case 23:co(t),to(),e!==null&&ae(_a);break;case 24:Yi(sa)}}function Gc(e,t){try{var n=t.updateQueue,r=n===null?null:n.lastEffect;if(r!==null){var i=r.next;n=i;do{if((n.tag&e)===e){r=void 0;var a=n.create,o=n.inst;r=a(),o.destroy=r}n=n.next}while(n!==i)}}catch(e){td(t,t.return,e)}}function Kc(e,t,n){try{var r=t.updateQueue,i=r===null?null:r.lastEffect;if(i!==null){var a=i.next;r=a;do{if((r.tag&e)===e){var o=r.inst,s=o.destroy;if(s!==void 0){o.destroy=void 0,i=t;var c=n,l=s;try{l()}catch(e){td(i,c,e)}}}r=r.next}while(r!==a)}}catch(e){td(t,t.return,e)}}function qc(e){var t=e.updateQueue;if(t!==null){var n=e.stateNode;try{Xa(t,n)}catch(t){td(e,e.return,t)}}}function Jc(e,t,n){n.props=Ys(e.type,e.memoizedProps),n.state=e.memoizedState;try{n.componentWillUnmount()}catch(n){td(e,t,n)}}function Yc(e,t){try{var n=e.ref;if(n!==null){switch(e.tag){case 26:case 27:case 5:var r=e.stateNode;break;case 30:r=e.stateNode;break;default:r=e.stateNode}typeof n==`function`?e.refCleanup=n(r):n.current=r}}catch(n){td(e,t,n)}}function Xc(e,t){var n=e.ref,r=e.refCleanup;if(n!==null)if(typeof r==`function`)try{r()}catch(n){td(e,t,n)}finally{e.refCleanup=null,e=e.alternate,e!=null&&(e.refCleanup=null)}else if(typeof n==`function`)try{n(null)}catch(n){td(e,t,n)}else n.current=null}function Zc(e){var t=e.type,n=e.memoizedProps,r=e.stateNode;try{a:switch(t){case`button`:case`input`:case`select`:case`textarea`:n.autoFocus&&r.focus();break a;case`img`:n.src?r.src=n.src:n.srcSet&&(r.srcset=n.srcSet)}}catch(t){td(e,e.return,t)}}function Qc(e,t,n){try{var r=e.stateNode;Jd(r,e.type,n,t),r[lt]=t}catch(t){td(e,e.return,t)}}function $c(e){return e.tag===5||e.tag===3||e.tag===26||e.tag===27&&df(e.type)||e.tag===4}function el(e){a:for(;;){for(;e.sibling===null;){if(e.return===null||$c(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.tag===27&&df(e.type)||e.flags&2||e.child===null||e.tag===4)continue a;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function tl(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?(n.nodeType===9?n.body:n.nodeName===`HTML`?n.ownerDocument.body:n).insertBefore(e,t):(t=n.nodeType===9?n.body:n.nodeName===`HTML`?n.ownerDocument.body:n,t.appendChild(e),n=n._reactRootContainer,n!=null||t.onclick!==null||(t.onclick=tn));else if(r!==4&&(r===27&&df(e.type)&&(n=e.stateNode,t=null),e=e.child,e!==null))for(tl(e,t,n),e=e.sibling;e!==null;)tl(e,t,n),e=e.sibling}function nl(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.insertBefore(e,t):n.appendChild(e);else if(r!==4&&(r===27&&df(e.type)&&(n=e.stateNode),e=e.child,e!==null))for(nl(e,t,n),e=e.sibling;e!==null;)nl(e,t,n),e=e.sibling}function rl(e){var t=e.stateNode,n=e.memoizedProps;try{for(var r=e.type,i=t.attributes;i.length;)t.removeAttributeNode(i[0]);qd(t,r,n),t[ct]=e,t[lt]=n}catch(t){td(e,e.return,t)}}var il=!1,al=!1,ol=!1,sl=typeof WeakSet==`function`?WeakSet:Set,cl=null;function ll(e,t){if(e=e.containerInfo,Zd=bp,e=kr(e),Ar(e)){if(`selectionStart`in e)var n={start:e.selectionStart,end:e.selectionEnd};else a:{n=(n=e.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var a=r.anchorOffset,o=r.focusNode;r=r.focusOffset;try{n.nodeType,o.nodeType}catch{n=null;break a}var s=0,c=-1,l=-1,u=0,d=0,f=e,p=null;b:for(;;){for(var m;f!==n||a!==0&&f.nodeType!==3||(c=s+a),f!==o||r!==0&&f.nodeType!==3||(l=s+r),f.nodeType===3&&(s+=f.nodeValue.length),(m=f.firstChild)!==null;)p=f,f=m;for(;;){if(f===e)break b;if(p===n&&++u===a&&(c=s),p===o&&++d===r&&(l=s),(m=f.nextSibling)!==null)break;f=p,p=f.parentNode}f=m}n=c===-1||l===-1?null:{start:c,end:l}}else n=null}n||={start:0,end:0}}else n=null;for(Qd={focusedElem:e,selectionRange:n},bp=!1,cl=t;cl!==null;)if(t=cl,e=t.child,t.subtreeFlags&1028&&e!==null)e.return=t,cl=e;else for(;cl!==null;){switch(t=cl,o=t.alternate,e=t.flags,t.tag){case 0:if(e&4&&(e=t.updateQueue,e=e===null?null:e.events,e!==null))for(n=0;n<e.length;n++)a=e[n],a.ref.impl=a.nextImpl;break;case 11:case 15:break;case 1:if(e&1024&&o!==null){e=void 0,n=t,a=o.memoizedProps,o=o.memoizedState,r=n.stateNode;try{var h=Ys(n.type,a);e=r.getSnapshotBeforeUpdate(h,o),r.__reactInternalSnapshotBeforeUpdate=e}catch(e){td(n,n.return,e)}}break;case 3:if(e&1024){if(e=t.stateNode.containerInfo,n=e.nodeType,n===9)mf(e);else if(n===1)switch(e.nodeName){case`HEAD`:case`HTML`:case`BODY`:mf(e);break;default:e.textContent=``}}break;case 5:case 26:case 27:case 6:case 4:case 17:break;default:if(e&1024)throw Error(i(163))}if(e=t.sibling,e!==null){e.return=t.return,cl=e;break}cl=t.return}}function ul(e,t,n){var r=n.flags;switch(n.tag){case 0:case 11:case 15:Tl(e,n),r&4&&Gc(5,n);break;case 1:if(Tl(e,n),r&4)if(e=n.stateNode,t===null)try{e.componentDidMount()}catch(e){td(n,n.return,e)}else{var i=Ys(n.type,t.memoizedProps);t=t.memoizedState;
vendor: 5,412 bytes, line 8
8try{e.componentDidUpdate(i,t,e.__reactInternalSnapshotBeforeUpdate)}catch(e){td(n,n.return,e)}}r&64&&qc(n),r&512&&Yc(n,n.return);break;case 3:if(Tl(e,n),r&64&&(e=n.updateQueue,e!==null)){if(t=null,n.child!==null)switch(n.child.tag){case 27:case 5:t=n.child.stateNode;break;case 1:t=n.child.stateNode}try{Xa(e,t)}catch(e){td(n,n.return,e)}}break;case 27:t===null&&r&4&&rl(n);case 26:case 5:Tl(e,n),t===null&&r&4&&Zc(n),r&512&&Yc(n,n.return);break;case 12:Tl(e,n);break;case 31:Tl(e,n),r&4&&gl(e,n);break;case 13:Tl(e,n),r&4&&_l(e,n),r&64&&(e=n.memoizedState,e!==null&&(e=e.dehydrated,e!==null&&(n=ad.bind(null,n),bf(e,n))));break;case 22:if(r=n.memoizedState!==null||il,!r){t=t!==null&&t.memoizedState!==null||al,i=il;var a=al;il=r,(al=t)&&!a?Dl(e,n,(n.subtreeFlags&8772)!=0):Tl(e,n),il=i,al=a}break;case 30:break;default:Tl(e,n)}}function dl(e){var t=e.alternate;t!==null&&(e.alternate=null,dl(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&>(t)),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}var fl=null,pl=!1;function ml(e,t,n){for(n=n.child;n!==null;)hl(e,t,n),n=n.sibling}function hl(e,t,n){if(Le&&typeof Le.onCommitFiberUnmount==`function`)try{Le.onCommitFiberUnmount(Ie,n)}catch{}switch(n.tag){case 26:al||Xc(n,t),ml(e,t,n),n.memoizedState?n.memoizedState.count--:n.stateNode&&(n=n.stateNode,n.parentNode.removeChild(n));break;case 27:al||Xc(n,t);var r=fl,i=pl;df(n.type)&&(fl=n.stateNode,pl=!1),ml(e,t,n),Ef(n.stateNode),fl=r,pl=i;break;case 5:al||Xc(n,t);case 6:if(r=fl,i=pl,fl=null,ml(e,t,n),fl=r,pl=i,fl!==null)if(pl)try{(fl.nodeType===9?fl.body:fl.nodeName===`HTML`?fl.ownerDocument.body:fl).removeChild(n.stateNode)}catch(e){td(n,t,e)}else try{fl.removeChild(n.stateNode)}catch(e){td(n,t,e)}break;case 18:fl!==null&&(pl?(e=fl,ff(e.nodeType===9?e.body:e.nodeName===`HTML`?e.ownerDocument.body:e,n.stateNode),Kp(e)):ff(fl,n.stateNode));break;case 4:r=fl,i=pl,fl=n.stateNode.containerInfo,pl=!0,ml(e,t,n),fl=r,pl=i;break;case 0:case 11:case 14:case 15:Kc(2,n,t),al||Kc(4,n,t),ml(e,t,n);break;case 1:al||(Xc(n,t),r=n.stateNode,typeof r.componentWillUnmount==`function`&&Jc(n,t,r)),ml(e,t,n);break;case 21:ml(e,t,n);break;case 22:al=(r=al)||n.memoizedState!==null,ml(e,t,n),al=r;break;default:ml(e,t,n)}}function gl(e,t){if(t.memoizedState===null&&(e=t.alternate,e!==null&&(e=e.memoizedState,e!==null))){e=e.dehydrated;try{Kp(e)}catch(e){td(t,t.return,e)}}}function _l(e,t){if(t.memoizedState===null&&(e=t.alternate,e!==null&&(e=e.memoizedState,e!==null&&(e=e.dehydrated,e!==null))))try{Kp(e)}catch(e){td(t,t.return,e)}}function vl(e){switch(e.tag){case 31:case 13:case 19:var t=e.stateNode;return t===null&&(t=e.stateNode=new sl),t;case 22:return e=e.stateNode,t=e._retryCache,t===null&&(t=e._retryCache=new sl),t;default:throw Error(i(435,e.tag))}}function yl(e,t){var n=vl(e);t.forEach(function(t){if(!n.has(t)){n.add(t);var r=od.bind(null,e,t);t.then(r,r)}})}function bl(e,t){var n=t.deletions;if(n!==null)for(var r=0;r<n.length;r++){var a=n[r],o=e,s=t,c=s;a:for(;c!==null;){switch(c.tag){case 27:if(df(c.type)){fl=c.stateNode,pl=!1;break a}break;case 5:fl=c.stateNode,pl=!1;break a;case 3:case 4:fl=c.stateNode.containerInfo,pl=!0;break a}c=c.return}if(fl===null)throw Error(i(160));hl(o,s,a),fl=null,pl=!1,o=a.alternate,o!==null&&(o.return=null),a.return=null}if(t.subtreeFlags&13886)for(t=t.child;t!==null;)Sl(t,e),t=t.sibling}var xl=null;function Sl(e,t){var n=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:bl(t,e),Cl(e),r&4&&(Kc(3,e,e.return),Gc(3,e),Kc(5,e,e.return));break;case 1:bl(t,e),Cl(e),r&512&&(al||n===null||Xc(n,n.return)),r&64&&il&&(e=e.updateQueue,e!==null&&(r=e.callbacks,r!==null&&(n=e.shared.hiddenCallbacks,e.shared.hiddenCallbacks=n===null?r:n.concat(r))));break;case 26:var a=xl;if(bl(t,e),Cl(e),r&512&&(al||n===null||Xc(n,n.return)),r&4){var o=n===null?null:n.memoizedState;if(r=e.memoizedState,n===null)if(r===null)if(e.stateNode===null){a:{r=e.type,n=e.memoizedProps,a=a.ownerDocument||a;b:switch(r){case`title`:o=a.getElementsByTagName(`title`)[0],(!o||o[ht]||o[ct]||o.namespaceURI===`http://www.w3.org/2000/svg`||o.hasAttribute(`itemprop`))&&(o=a.createElement(r),a.head.insertBefore(o,a.querySelector(`head > title`))),qd(o,r,n),o[ct]=e,xt(o),r=o;break a;case`link`:var s=ep(`link`,`href`,a).get(r+(n.href||``));if(s){for(var c=0;c<s.length;c++)if(o=s[c],o.getAttribute(`href`)===(n.href==null||n.href===``?null:n.href)&&o.getAttribute(`rel`)===(n.rel==null?null:n.rel)&&o.getAttribute(`title`)===(n.title==null?null:n.title)&&o.getAttribute(`crossorigin`)===(n.crossOrigin==null?null:n.crossOrigin)){s.splice(c,1);break b}}o=a.createElement(r),qd(o,r,n),a.head.appendChild(o);break;case`meta`:if(s=ep(`meta`,`content`,a).get(r+(n.content||``))){for(c=0;c<s.length;c++)if(o=s[c],o.getAttribute(`content`)===(n.content==null?null:``+n.content)&&o.getAttribute(`name`)===(n.name==null?null:n.name)&&o.getAttribute(`property`)===(n.property==null?null:n.property)&&o.getAttribute(`http-equiv`)===(n.httpEquiv==null?null:n.httpEquiv)&&o.getAttribute(`charset`)===(n.charSet==null?null:n.charSet)){s.splice(c,1);break b}}o=a.createElement(r),qd(o,r,n),a.head.appendChild(o);break;default:throw Error(i(468,r))}o[ct]=e,xt(o),r=o}e.stateNode=r}else tp(a,e.type,e.stateNode);else e.stateNode=Yf(a,r,e.memoizedProps);
vendor: 40,675 bytes, lines 8-9
8else o===r?r===null&&e.stateNode!==null&&Qc(e,e.memoizedProps,n.memoizedProps):(o===null?n.stateNode!==null&&(n=n.stateNode,n.parentNode.removeChild(n)):o.count--,r===null?tp(a,e.type,e.stateNode):Yf(a,r,e.memoizedProps))}break;case 27:bl(t,e),Cl(e),r&512&&(al||n===null||Xc(n,n.return)),n!==null&&r&4&&Qc(e,e.memoizedProps,n.memoizedProps);break;case 5:if(bl(t,e),Cl(e),r&512&&(al||n===null||Xc(n,n.return)),e.flags&32){a=e.stateNode;try{qt(a,``)}catch(t){td(e,e.return,t)}}r&4&&e.stateNode!=null&&(a=e.memoizedProps,Qc(e,a,n===null?a:n.memoizedProps)),r&1024&&(ol=!0);break;case 6:if(bl(t,e),Cl(e),r&4){if(e.stateNode===null)throw Error(i(162));r=e.memoizedProps,n=e.stateNode;try{n.nodeValue=r}catch(t){td(e,e.return,t)}}break;case 3:if($f=null,a=xl,xl=kf(t.containerInfo),bl(t,e),xl=a,Cl(e),r&4&&n!==null&&n.memoizedState.isDehydrated)try{Kp(t.containerInfo)}catch(t){td(e,e.return,t)}ol&&(ol=!1,wl(e));break;case 4:r=xl,xl=kf(e.stateNode.containerInfo),bl(t,e),Cl(e),xl=r;break;case 12:bl(t,e),Cl(e);break;case 31:bl(t,e),Cl(e),r&4&&(r=e.updateQueue,r!==null&&(e.updateQueue=null,yl(e,r)));break;case 13:bl(t,e),Cl(e),e.child.flags&8192&&e.memoizedState!==null!=(n!==null&&n.memoizedState!==null)&&(lu=De()),r&4&&(r=e.updateQueue,r!==null&&(e.updateQueue=null,yl(e,r)));break;case 22:a=e.memoizedState!==null;var l=n!==null&&n.memoizedState!==null,u=il,d=al;if(il=u||a,al=d||l,bl(t,e),al=d,il=u,Cl(e),r&8192)a:for(t=e.stateNode,t._visibility=a?t._visibility&-2:t._visibility|1,a&&(n===null||l||il||al||El(e)),n=null,t=e;;){if(t.tag===5||t.tag===26){if(n===null){l=n=t;try{if(o=l.stateNode,a)s=o.style,typeof s.setProperty==`function`?s.setProperty(`display`,`none`,`important`):s.display=`none`;else{c=l.stateNode;var f=l.memoizedProps.style,p=f!=null&&f.hasOwnProperty(`display`)?f.display:null;c.style.display=p==null||typeof p==`boolean`?``:(``+p).trim()}}catch(e){td(l,l.return,e)}}}else if(t.tag===6){if(n===null){l=t;try{l.stateNode.nodeValue=a?``:l.memoizedProps}catch(e){td(l,l.return,e)}}}else if(t.tag===18){if(n===null){l=t;try{var m=l.stateNode;a?pf(m,!0):pf(l.stateNode,!1)}catch(e){td(l,l.return,e)}}}else if((t.tag!==22&&t.tag!==23||t.memoizedState===null||t===e)&&t.child!==null){t.child.return=t,t=t.child;continue}if(t===e)break a;for(;t.sibling===null;){if(t.return===null||t.return===e)break a;n===t&&(n=null),t=t.return}n===t&&(n=null),t.sibling.return=t.return,t=t.sibling}r&4&&(r=e.updateQueue,r!==null&&(n=r.retryQueue,n!==null&&(r.retryQueue=null,yl(e,n))));break;case 19:bl(t,e),Cl(e),r&4&&(r=e.updateQueue,r!==null&&(e.updateQueue=null,yl(e,r)));break;case 30:break;case 21:break;default:bl(t,e),Cl(e)}}function Cl(e){var t=e.flags;if(t&2){try{for(var n,r=e.return;r!==null;){if($c(r)){n=r;break}r=r.return}if(n==null)throw Error(i(160));switch(n.tag){case 27:var a=n.stateNode;nl(e,el(e),a);break;case 5:var o=n.stateNode;n.flags&32&&(qt(o,``),n.flags&=-33),nl(e,el(e),o);break;case 3:case 4:var s=n.stateNode.containerInfo;tl(e,el(e),s);break;default:throw Error(i(161))}}catch(t){td(e,e.return,t)}e.flags&=-3}t&4096&&(e.flags&=-4097)}function wl(e){if(e.subtreeFlags&1024)for(e=e.child;e!==null;){var t=e;wl(t),t.tag===5&&t.flags&1024&&t.stateNode.reset(),e=e.sibling}}function Tl(e,t){if(t.subtreeFlags&8772)for(t=t.child;t!==null;)ul(e,t.alternate,t),t=t.sibling}function El(e){for(e=e.child;e!==null;){var t=e;switch(t.tag){case 0:case 11:case 14:case 15:Kc(4,t,t.return),El(t);break;case 1:Xc(t,t.return);var n=t.stateNode;typeof n.componentWillUnmount==`function`&&Jc(t,t.return,n),El(t);break;case 27:Ef(t.stateNode);case 26:case 5:Xc(t,t.return),El(t);break;case 22:t.memoizedState===null&&El(t);break;case 30:El(t);break;default:El(t)}e=e.sibling}}function Dl(e,t,n){for(n&&=(t.subtreeFlags&8772)!=0,t=t.child;t!==null;){var r=t.alternate,i=e,a=t,o=a.flags;switch(a.tag){case 0:case 11:case 15:Dl(i,a,n),Gc(4,a);break;case 1:if(Dl(i,a,n),r=a,i=r.stateNode,typeof i.componentDidMount==`function`)try{i.componentDidMount()}catch(e){td(r,r.return,e)}if(r=a,i=r.updateQueue,i!==null){var s=r.stateNode;try{var c=i.shared.hiddenCallbacks;if(c!==null)for(i.shared.hiddenCallbacks=null,i=0;i<c.length;i++)Ya(c[i],s)}catch(e){td(r,r.return,e)}}n&&o&64&&qc(a),Yc(a,a.return);break;case 27:rl(a);case 26:case 5:Dl(i,a,n),n&&r===null&&o&4&&Zc(a),Yc(a,a.return);break;case 12:Dl(i,a,n);break;case 31:Dl(i,a,n),n&&o&4&&gl(i,a);break;case 13:Dl(i,a,n),n&&o&4&&_l(i,a);break;case 22:a.memoizedState===null&&Dl(i,a,n),Yc(a,a.return);break;case 30:break;default:Dl(i,a,n)}t=t.sibling}}function Ol(e,t){var n=null;e!==null&&e.memoizedState!==null&&e.memoizedState.cachePool!==null&&(n=e.memoizedState.cachePool.pool),e=null,t.memoizedState!==null&&t.memoizedState.cachePool!==null&&(e=t.memoizedState.cachePool.pool),e!==n&&(e!=null&&e.refCount++,n!=null&&la(n))}function kl(e,t){e=null,t.alternate!==null&&(e=t.alternate.memoizedState.cache),t=t.memoizedState.cache,t!==e&&(t.refCount++,e!=null&&la(e))}function Al(e,t,n,r){if(t.subtreeFlags&10256)for(t=t.child;t!==null;)jl(e,t,n,r),t=t.sibling}function jl(e,t,n,r){var i=t.flags;switch(t.tag){case 0:case 11:case 15:Al(e,t,n,r),i&2048&&Gc(9,t);break;case 1:Al(e,t,n,r);break;case 3:Al(e,t,n,r),i&2048&&(e=null,t.alternate!==null&&(e=t.alternate.memoizedState.cache),t=t.memoizedState.cache,t!==e&&(t.refCount++,e!=null&&la(e)));break;case 12:if(i&2048){Al(e,t,n,r),e=t.stateNode;try{var a=t.memoizedProps,o=a.id,s=a.onPostCommit;typeof s==`function`&&s(o,t.alternate===null?`mount`:`update`,e.passiveEffectDuration,-0)}catch(e){td(t,t.return,e)}}else Al(e,t,n,r);break;case 31:Al(e,t,n,r);break;case 13:Al(e,t,n,r);break;case 23:break;case 22:a=t.stateNode,o=t.alternate,t.memoizedState===null?a._visibility&2?Al(e,t,n,r):(a._visibility|=2,Ml(e,t,n,r,(t.subtreeFlags&10256)!=0||!1)):a._visibility&2?Al(e,t,n,r):Nl(e,t),i&2048&&Ol(o,t);break;case 24:Al(e,t,n,r),i&2048&&kl(t.alternate,t);break;default:Al(e,t,n,r)}}function Ml(e,t,n,r,i){for(i&&=(t.subtreeFlags&10256)!=0||!1,t=t.child;t!==null;){var a=e,o=t,s=n,c=r,l=o.flags;switch(o.tag){case 0:case 11:case 15:Ml(a,o,s,c,i),Gc(8,o);break;case 23:break;case 22:var u=o.stateNode;o.memoizedState===null?(u._visibility|=2,Ml(a,o,s,c,i)):u._visibility&2?Ml(a,o,s,c,i):Nl(a,o),i&&l&2048&&Ol(o.alternate,o);break;case 24:Ml(a,o,s,c,i),i&&l&2048&&kl(o.alternate,o);break;default:Ml(a,o,s,c,i)}t=t.sibling}}function Nl(e,t){if(t.subtreeFlags&10256)for(t=t.child;t!==null;){var n=e,r=t,i=r.flags;switch(r.tag){case 22:Nl(n,r),i&2048&&Ol(r.alternate,r);break;case 24:Nl(n,r),i&2048&&kl(r.alternate,r);break;default:Nl(n,r)}t=t.sibling}}var Pl=8192;function Fl(e,t,n){if(e.subtreeFlags&Pl)for(e=e.child;e!==null;)Il(e,t,n),e=e.sibling}function Il(e,t,n){switch(e.tag){case 26:Fl(e,t,n),e.flags&Pl&&e.memoizedState!==null&&ip(n,xl,e.memoizedState,e.memoizedProps);break;case 5:Fl(e,t,n);break;case 3:case 4:var r=xl;xl=kf(e.stateNode.containerInfo),Fl(e,t,n),xl=r;break;case 22:e.memoizedState===null&&(r=e.alternate,r!==null&&r.memoizedState!==null?(r=Pl,Pl=16777216,Fl(e,t,n),Pl=r):Fl(e,t,n));break;default:Fl(e,t,n)}}function Ll(e){var t=e.alternate;if(t!==null&&(e=t.child,e!==null)){t.child=null;do t=e.sibling,e.sibling=null,e=t;while(e!==null)}}function Rl(e){var t=e.deletions;if(e.flags&16){if(t!==null)for(var n=0;n<t.length;n++){var r=t[n];cl=r,Vl(r,e)}Ll(e)}if(e.subtreeFlags&10256)for(e=e.child;e!==null;)zl(e),e=e.sibling}function zl(e){switch(e.tag){case 0:case 11:case 15:Rl(e),e.flags&2048&&Kc(9,e,e.return);break;case 3:Rl(e);break;case 12:Rl(e);break;case 22:var t=e.stateNode;e.memoizedState!==null&&t._visibility&2&&(e.return===null||e.return.tag!==13)?(t._visibility&=-3,Bl(e)):Rl(e);break;default:Rl(e)}}function Bl(e){var t=e.deletions;if(e.flags&16){if(t!==null)for(var n=0;n<t.length;n++){var r=t[n];cl=r,Vl(r,e)}Ll(e)}for(e=e.child;e!==null;){switch(t=e,t.tag){case 0:case 11:case 15:Kc(8,t,t.return),Bl(t);break;case 22:n=t.stateNode,n._visibility&2&&(n._visibility&=-3,Bl(t));break;default:Bl(t)}e=e.sibling}}function Vl(e,t){for(;cl!==null;){var n=cl;switch(n.tag){case 0:case 11:case 15:Kc(8,n,t);break;case 23:case 22:if(n.memoizedState!==null&&n.memoizedState.cachePool!==null){var r=n.memoizedState.cachePool.pool;r!=null&&r.refCount++}break;case 24:la(n.memoizedState.cache)}if(r=n.child,r!==null)r.return=n,cl=r;else a:for(n=e;cl!==null;){r=cl;var i=r.sibling,a=r.return;if(dl(r),r===n){cl=null;break a}if(i!==null){i.return=a,cl=i;break a}cl=a}}}var Hl={getCacheForType:function(e){var t=ta(sa),n=t.data.get(e);return n===void 0&&(n=e(),t.data.set(e,n)),n},cacheSignal:function(){return ta(sa).controller.signal}},Ul=typeof WeakMap==`function`?WeakMap:Map,Wl=0,Gl=null,Kl=null,ql=0,Jl=0,Yl=null,Xl=!1,Zl=!1,Ql=!1,$l=0,eu=0,tu=0,nu=0,ru=0,iu=0,au=0,ou=null,su=null,cu=!1,lu=0,uu=0,du=1/0,fu=null,pu=null,mu=0,hu=null,gu=null,_u=0,vu=0,yu=null,bu=null,xu=0,Su=null;function Cu(){return Wl&2&&ql!==0?ql&-ql:F.T===null?at():Sd()}function wu(){if(iu===0)if(!(ql&536870912)||z){var e=We;We<<=1,!(We&3932160)&&(We=262144),iu=e}else iu=536870912;return e=no.current,e!==null&&(e.flags|=32),iu}function Tu(e,t,n){(e===Gl&&(Jl===2||Jl===9)||e.cancelPendingCommit!==null)&&(Mu(e,0),ku(e,ql,iu,!1)),Qe(e,n),(!(Wl&2)||e!==Gl)&&(e===Gl&&(!(Wl&2)&&(nu|=n),eu===4&&ku(e,ql,iu,!1)),md(e))}function Eu(e,t,n){if(Wl&6)throw Error(i(327));var r=!n&&(t&127)==0&&(t&e.expiredLanes)===0||Je(e,t),a=r?Bu(e,t):Ru(e,t,!0),o=r;do{if(a===0){Zl&&!r&&ku(e,t,0,!1);break}else{if(n=e.current.alternate,o&&!Ou(n)){a=Ru(e,t,!1),o=!1;continue}if(a===2){if(o=t,e.errorRecoveryDisabledLanes&o)var s=0;else s=e.pendingLanes&-536870913,s=s===0?s&536870912?536870912:0:s;if(s!==0){t=s;a:{var c=e;a=ou;var l=c.current.memoizedState.isDehydrated;if(l&&(Mu(c,s).flags|=256),s=Ru(c,s,!1),s!==2){if(Ql&&!l){c.errorRecoveryDisabledLanes|=o,nu|=o,a=4;break a}o=su,su=a,o!==null&&(su===null?su=o:su.push.apply(su,o))}a=s}if(o=!1,a!==2)continue}}if(a===1){Mu(e,0),ku(e,t,0,!0);break}a:{switch(r=e,o=a,o){case 0:case 1:throw Error(i(345));case 4:if((t&4194048)!==t)break;case 6:ku(r,t,iu,!Xl);break a;case 2:su=null;break;case 3:case 5:break;default:throw Error(i(329))}if((t&62914560)===t&&(a=lu+300-De(),10<a)){if(ku(r,t,iu,!Xl),qe(r,0,!0)!==0)break a;_u=t,r.timeoutHandle=of(Du.bind(null,r,n,su,fu,cu,t,iu,nu,au,Xl,o,`Throttled`,-0,0),a);break a}Du(r,n,su,fu,cu,t,iu,nu,au,Xl,o,null,-0,0)}}break}while(1);md(e)}function Du(e,t,n,r,i,a,o,s,c,l,u,d,f,p){if(e.timeoutHandle=-1,d=t.subtreeFlags,d&8192||(d&16785408)==16785408){d={stylesheets:null,count:0,imgCount:0,imgBytes:0,suspenseyImages:[],waitingForImages:!0,waitingForViewTransition:!1,unsuspend:tn},Il(t,a,d);var m=(a&62914560)===a?lu-De():(a&4194048)===a?uu-De():0;if(m=op(d,m),m!==null){_u=a,e.cancelPendingCommit=m(qu.bind(null,e,t,a,n,r,i,o,s,c,u,d,null,f,p)),ku(e,a,o,!l);return}}qu(e,t,a,n,r,i,o,s,c)}function Ou(e){for(var t=e;;){var n=t.tag;if((n===0||n===11||n===15)&&t.flags&16384&&(n=t.updateQueue,n!==null&&(n=n.stores,n!==null)))for(var r=0;r<n.length;r++){var i=n[r],a=i.getSnapshot;i=i.value;try{if(!wr(a(),i))return!1}catch{return!1}}if(n=t.child,t.subtreeFlags&16384&&n!==null)n.return=t,t=n;else{if(t===e)break;for(;t.sibling===null;){if(t.return===null||t.return===e)return!0;t=t.return}t.sibling.return=t.return,t=t.sibling}}return!0}function ku(e,t,n,r){t&=~ru,t&=~nu,e.suspendedLanes|=t,e.pingedLanes&=~t,r&&(e.warmLanes|=t),r=e.expirationTimes;for(var i=t;0<i;){var a=31-ze(i),o=1<<a;r[a]=-1,i&=~o}n!==0&&et(e,n,t)}function Au(){return Wl&6?!0:(hd(0,!1),!1)}function ju(){if(Kl!==null){if(Jl===0)var e=Kl.return;else e=Kl,qi=Ki=null,jo(e),ja=null,Ma=0,e=Kl;for(;e!==null;)Wc(e.alternate,e),e=e.return;Kl=null}}function Mu(e,t){var n=e.timeoutHandle;n!==-1&&(e.timeoutHandle=-1,sf(n)),n=e.cancelPendingCommit,n!==null&&(e.cancelPendingCommit=null,n()),_u=0,ju(),Gl=e,Kl=n=di(e.current,null),ql=t,Jl=0,Yl=null,Xl=!1,Zl=Je(e,t),Ql=!1,au=iu=ru=nu=tu=eu=0,su=ou=null,cu=!1,t&8&&(t|=t&32);var r=e.entangledLanes;if(r!==0)for(e=e.entanglements,r&=t;0<r;){var i=31-ze(r),a=1<<i;t|=e[i],r&=~a}return $l=t,L(),n}function Nu(e,t){po=null,F.H=Vs,t===xa||t===Ca?(t=ka(),Jl=3):t===Sa?(t=ka(),Jl=4):Jl=t===ac?8:typeof t==`object`&&t&&typeof t.then==`function`?6:1,Yl=t,Kl===null&&(eu=1,$s(e,R(t,e.current)))}function Pu(){var e=no.current;return e===null?!0:(ql&4194048)===ql?ro===null:(ql&62914560)===ql||ql&536870912?e===ro:!1}function Fu(){var e=F.H;return F.H=Vs,e===null?Vs:e}function Iu(){var e=F.A;return F.A=Hl,e}function Lu(){eu=4,Xl||(ql&4194048)!==ql&&no.current!==null||(Zl=!0),!(tu&134217727)&&!(nu&134217727)||Gl===null||ku(Gl,ql,iu,!1)}function Ru(e,t,n){var r=Wl;Wl|=2;var i=Fu(),a=Iu();(Gl!==e||ql!==t)&&(fu=null,Mu(e,t)),t=!1;var o=eu;a:do try{if(Jl!==0&&Kl!==null){var s=Kl,c=Yl;switch(Jl){case 8:ju(),o=6;break a;case 3:case 2:case 9:case 6:no.current===null&&(t=!0);var l=Jl;if(Jl=0,Yl=null,Wu(e,s,c,l),n&&Zl){o=0;break a}break;default:l=Jl,Jl=0,Yl=null,Wu(e,s,c,l)}}zu(),o=eu;break}catch(t){Nu(e,t)}while(1);return t&&e.shellSuspendCounter++,qi=Ki=null,Wl=r,F.H=i,F.A=a,Kl===null&&(Gl=null,ql=0,L()),o}function zu(){for(;Kl!==null;)Hu(Kl)}function Bu(e,t){var n=Wl;Wl|=2;var r=Fu(),a=Iu();Gl!==e||ql!==t?(fu=null,du=De()+500,Mu(e,t)):Zl=Je(e,t);a:do try{if(Jl!==0&&Kl!==null){t=Kl;var o=Yl;b:switch(Jl){case 1:Jl=0,Yl=null,Wu(e,t,o,1);break;case 2:case 9:if(Ta(o)){Jl=0,Yl=null,Uu(t);break}t=function(){Jl!==2&&Jl!==9||Gl!==e||(Jl=7),md(e)},o.then(t,t);break a;case 3:Jl=7;break a;case 4:Jl=5;break a;case 7:Ta(o)?(Jl=0,Yl=null,Uu(t)):(Jl=0,Yl=null,Wu(e,t,o,7));break;case 5:var s=null;switch(Kl.tag){case 26:s=Kl.memoizedState;case 5:case 27:var c=Kl;if(s?rp(s):c.stateNode.complete){Jl=0,Yl=null;var l=c.sibling;if(l!==null)Kl=l;else{var u=c.return;u===null?Kl=null:(Kl=u,Gu(u))}break b}}Jl=0,Yl=null,Wu(e,t,o,5);break;case 6:Jl=0,Yl=null,Wu(e,t,o,6);break;case 8:ju(),eu=6;break a;default:throw Error(i(462))}}Vu();break}catch(t){Nu(e,t)}while(1);return qi=Ki=null,F.H=r,F.A=a,Wl=n,Kl===null?(Gl=null,ql=0,L(),eu):0}function Vu(){for(;Kl!==null&&!Te();)Hu(Kl)}function Hu(e){var t=Fc(e.alternate,e,$l);e.memoizedProps=e.pendingProps,t===null?Gu(e):Kl=t}function Uu(e){var t=e,n=t.alternate;switch(t.tag){case 15:case 0:t=yc(n,t,t.pendingProps,t.type,void 0,ql);break;case 11:t=yc(n,t,t.pendingProps,t.type.render,t.ref,ql);break;case 5:jo(t);default:Wc(n,t),t=Kl=fi(t,$l),t=Fc(n,t,$l)}e.memoizedProps=e.pendingProps,t===null?Gu(e):Kl=t}function Wu(e,t,n,r){qi=Ki=null,jo(t),ja=null,Ma=0;var i=t.return;try{if(ic(e,i,t,n,ql)){eu=1,$s(e,R(n,e.current)),Kl=null;return}}catch(t){if(i!==null)throw Kl=i,t;eu=1,$s(e,R(n,e.current)),Kl=null;return}t.flags&32768?(z||r===1?e=!0:Zl||ql&536870912?e=!1:(Xl=e=!0,(r===2||r===9||r===3||r===6)&&(r=no.current,r!==null&&r.tag===13&&(r.flags|=16384))),Ku(t,e)):Gu(t)}function Gu(e){var t=e;do{if(t.flags&32768){Ku(t,Xl);return}e=t.return;var n=Hc(t.alternate,t,$l);if(n!==null){Kl=n;return}if(t=t.sibling,t!==null){Kl=t;return}Kl=t=e}while(t!==null);eu===0&&(eu=5)}function Ku(e,t){do{var n=Uc(e.alternate,e);if(n!==null){n.flags&=32767,Kl=n;return}if(n=e.return,n!==null&&(n.flags|=32768,n.subtreeFlags=0,n.deletions=null),!t&&(e=e.sibling,e!==null)){Kl=e;return}Kl=e=n}while(e!==null);eu=6,Kl=null}function qu(e,t,n,r,a,o,s,c,l){e.cancelPendingCommit=null;do Qu();while(mu!==0);if(Wl&6)throw Error(i(327));if(t!==null){if(t===e.current)throw Error(i(177));if(o=t.lanes|t.childLanes,o|=ti,$e(e,n,o,s,c,l),e===Gl&&(Kl=Gl=null,ql=0),gu=t,hu=e,_u=n,vu=o,yu=a,bu=r,t.subtreeFlags&10256||t.flags&10256?(e.callbackNode=null,e.callbackPriority=0,sd(je,function(){return $u(),null})):(e.callbackNode=null,e.callbackPriority=0),r=(t.flags&13878)!=0,t.subtreeFlags&13878||r){r=F.T,F.T=null,a=I.p,I.p=2,s=Wl,Wl|=4;try{ll(e,t,n)}finally{Wl=s,I.p=a,F.T=r}}mu=1,Ju(),Yu(),Xu()}}function Ju(){if(mu===1){mu=0;var e=hu,t=gu,n=(t.flags&13878)!=0;if(t.subtreeFlags&13878||n){n=F.T,F.T=null;var r=I.p;I.p=2;var i=Wl;Wl|=4;try{Sl(t,e);var a=Qd,o=kr(e.containerInfo),s=a.focusedElem,c=a.selectionRange;if(o!==s&&s&&s.ownerDocument&&Or(s.ownerDocument.documentElement,s)){if(c!==null&&Ar(s)){var l=c.start,u=c.end;if(u===void 0&&(u=l),`selectionStart`in s)s.selectionStart=l,s.selectionEnd=Math.min(u,s.value.length);else{var d=s.ownerDocument||document,f=d&&d.defaultView||window;if(f.getSelection){var p=f.getSelection(),m=s.textContent.length,h=Math.min(c.start,m),g=c.end===void 0?h:Math.min(c.end,m);!p.extend&&h>g&&(o=g,g=h,h=o);var _=Dr(s,h),v=Dr(s,g);if(_&&v&&(p.rangeCount!==1||p.anchorNode!==_.node||p.anchorOffset!==_.offset||p.focusNode!==v.node||p.focusOffset!==v.offset)){var y=d.createRange();y.setStart(_.node,_.offset),p.removeAllRanges(),h>g?(p.addRange(y),p.extend(v.node,v.offset)):(y.setEnd(v.node,v.offset),p.addRange(y))}}}}for(d=[],p=s;p=p.parentNode;)p.nodeType===1&&d.push({element:p,left:p.scrollLeft,top:p.scrollTop});for(typeof s.focus==`function`&&s.focus(),s=0;s<d.length;s++){var b=d[s];b.element.scrollLeft=b.left,b.element.scrollTop=b.top}}bp=!!Zd,Qd=Zd=null}finally{Wl=i,I.p=r,F.T=n}}e.current=t,mu=2}}function Yu(){if(mu===2){mu=0;var e=hu,t=gu,n=(t.flags&8772)!=0;if(t.subtreeFlags&8772||n){n=F.T,F.T=null;var r=I.p;I.p=2;var i=Wl;Wl|=4;try{ul(e,t.alternate,t)}finally{Wl=i,I.p=r,F.T=n}}mu=3}}function Xu(){if(mu===4||mu===3){mu=0,Ee();var e=hu,t=gu,n=_u,r=bu;t.subtreeFlags&10256||t.flags&10256?mu=5:(mu=0,gu=hu=null,Zu(e,e.pendingLanes));var i=e.pendingLanes;if(i===0&&(pu=null),it(n),t=t.stateNode,Le&&typeof Le.onCommitFiberRoot==`function`)try{Le.onCommitFiberRoot(Ie,t,void 0,(t.current.flags&128)==128)}catch{}if(r!==null){t=F.T,i=I.p,I.p=2,F.T=null;try{for(var a=e.onRecoverableError,o=0;o<r.length;o++){var s=r[o];a(s.value,{componentStack:s.stack})}}finally{F.T=t,I.p=i}}_u&3&&Qu(),md(e),i=e.pendingLanes,n&261930&&i&42?e===Su?xu++:(xu=0,Su=e):xu=0,hd(0,!1)}}function Zu(e,t){(e.pooledCacheLanes&=t)===0&&(t=e.pooledCache,t!=null&&(e.pooledCache=null,la(t)))}function Qu(){return Ju(),Yu(),Xu(),$u()}function $u(){if(mu!==5)return!1;var e=hu,t=vu;vu=0;var n=it(_u),r=F.T,a=I.p;try{I.p=32>n?32:n,F.T=null,n=yu,yu=null;var o=hu,s=_u;if(mu=0,gu=hu=null,_u=0,Wl&6)throw Error(i(331));var c=Wl;if(Wl|=4,zl(o.current),jl(o,o.current,s,n),Wl=c,hd(0,!1),Le&&typeof Le.onPostCommitFiberRoot==`function`)try{Le.onPostCommitFiberRoot(Ie,o)}catch{}return!0}finally{I.p=a,F.T=r,Zu(e,t)}}function ed(e,t,n){t=R(n,t),t=tc(e.stateNode,t,2),e=Ua(e,t,2),e!==null&&(Qe(e,2),md(e))}function td(e,t,n){if(e.tag===3)ed(e,e,n);else for(;t!==null;){if(t.tag===3){ed(t,e,n);break}else if(t.tag===1){var r=t.stateNode;if(typeof t.type.getDerivedStateFromError==`function`||typeof r.componentDidCatch==`function`&&(pu===null||!pu.has(r))){e=R(n,e),n=nc(2),r=Ua(t,n,2),r!==null&&(rc(n,r,t,e),Qe(r,2),md(r));break}}t=t.return}}function nd(e,t,n){var r=e.pingCache;if(r===null){r=e.pingCache=new Ul;var i=new Set;r.set(t,i)}else i=r.get(t),i===void 0&&(i=new Set,r.set(t,i));i.has(n)||(Ql=!0,i.add(n),e=rd.bind(null,e,t,n),t.then(e,e))}function rd(e,t,n){var r=e.pingCache;r!==null&&r.delete(t),e.pingedLanes|=e.suspendedLanes&n,e.warmLanes&=~n,Gl===e&&(ql&n)===n&&(eu===4||eu===3&&(ql&62914560)===ql&&300>De()-lu?!(Wl&2)&&Mu(e,0):ru|=n,au===ql&&(au=0)),md(e)}function id(e,t){t===0&&(t=Xe()),e=ii(e,t),e!==null&&(Qe(e,t),md(e))}function ad(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),id(e,n)}function od(e,t){var n=0;switch(e.tag){case 31:case 13:var r=e.stateNode,a=e.memoizedState;a!==null&&(n=a.retryLane);break;case 19:r=e.stateNode;break;case 22:r=e.stateNode._retryCache;break;default:throw Error(i(314))}r!==null&&r.delete(t),id(e,n)}function sd(e,t){return Ce(e,t)}var cd=null,ld=null,ud=!1,dd=!1,fd=!1,pd=0;function md(e){e!==ld&&e.next===null&&(ld===null?cd=ld=e:ld=ld.next=e),dd=!0,ud||(ud=!0,xd())}function hd(e,t){if(!fd&&dd){fd=!0;do for(var n=!1,r=cd;r!==null;){if(!t)if(e!==0){var i=r.pendingLanes;if(i===0)var a=0;else{var o=r.suspendedLanes,s=r.pingedLanes;a=(1<<31-ze(42|e)+1)-1,a&=i&~(o&~s),a=a&201326741?a&201326741|1:a?a|2:0}a!==0&&(n=!0,bd(r,a))}else a=ql,a=qe(r,r===Gl?a:0,r.cancelPendingCommit!==null||r.timeoutHandle!==-1),!(a&3)||Je(r,a)||(n=!0,bd(r,a));r=r.next}while(n);fd=!1}}function gd(){_d()}function _d(){dd=ud=!1;var e=0;pd!==0&&af()&&(e=pd);for(var t=De(),n=null,r=cd;r!==null;){var i=r.next,a=vd(r,t);a===0?(r.next=null,n===null?cd=i:n.next=i,i===null&&(ld=n)):(n=r,(e!==0||a&3)&&(dd=!0)),r=i}mu!==0&&mu!==5||hd(e,!1),pd!==0&&(pd=0)}function vd(e,t){for(var n=e.suspendedLanes,r=e.pingedLanes,i=e.expirationTimes,a=e.pendingLanes&-62914561;0<a;){var o=31-ze(a),s=1<<o,c=i[o];c===-1?((s&n)===0||(s&r)!==0)&&(i[o]=Ye(s,t)):c<=t&&(e.expiredLanes|=s),a&=~s}if(t=Gl,n=ql,n=qe(e,e===t?n:0,e.cancelPendingCommit!==null||e.timeoutHandle!==-1),r=e.callbackNode,n===0||e===t&&(Jl===2||Jl===9)||e.cancelPendingCommit!==null)return r!==null&&r!==null&&we(r),e.callbackNode=null,e.callbackPriority=0;if(!(n&3)||Je(e,n)){if(t=n&-n,t===e.callbackPriority)return t;switch(r!==null&&we(r),it(n)){case 2:case 8:n=Ae;break;case 32:n=je;break;case 268435456:n=Ne;break;default:n=je}return r=yd.bind(null,e),n=Ce(n,r),e.callbackPriority=t,e.callbackNode=n,t}return r!==null&&r!==null&&we(r),e.callbackPriority=2,e.callbackNode=null,2}function yd(e,t){if(mu!==0&&mu!==5)return e.callbackNode=null,e.callbackPriority=0,null;var n=e.callbackNode;if(Qu()&&e.callbackNode!==n)return null;var r=ql;return r=qe(e,e===Gl?r:0,e.cancelPendingCommit!==null||e.timeoutHandle!==-1),r===0?null:(Eu(e,r,t),vd(e,De()),e.callbackNode!=null&&e.callbackNode===n?yd.bind(null,e):null)}function bd(e,t){if(Qu())return null;Eu(e,t,!0)}function xd(){lf(function(){Wl&6?Ce(ke,gd):_d()})}function Sd(){if(pd===0){var e=fa;e===0&&(e=Ue,Ue<<=1,!(Ue&261888)&&(Ue=256)),pd=e}return pd}function Cd(e){return e==null||typeof e==`symbol`||typeof e==`boolean`?null:typeof e==`function`?e:en(``+e)}function wd(e,t){var n=t.ownerDocument.createElement(`input`);return n.name=t.name,n.value=t.value,e.id&&n.setAttribute(`form`,e.id),t.parentNode.insertBefore(n,t),e=new FormData(e),n.parentNode.removeChild(n),e}function Td(e,t,n,r,i){if(t===`submit`&&n&&n.stateNode===i){var a=Cd((i[lt]||null).action),o=r.submitter;o&&(t=(t=o[lt]||null)?Cd(t.formAction):o.getAttribute(`formAction`),t!==null&&(a=t,o=null));var s=new Cn(`action`,`action`,null,r,i);e.push({event:s,listeners:[{instance:null,listener:function(){if(r.defaultPrevented){if(pd!==0){var e=o?wd(i,o):new FormData(i);Ds(n,{pending:!0,data:e,method:i.method,action:a},null,e)}}else typeof a==`function`&&(s.preventDefault(),e=o?wd(i,o):new FormData(i),Ds(n,{pending:!0,data:e,method:i.method,action:a},a,e))},currentTarget:i}]})}}for(var Ed=0;Ed<Xr.length;Ed++){var Dd=Xr[Ed];Zr(Dd.toLowerCase(),`on`+(Dd[0].toUpperCase()+Dd.slice(1)))}Zr(Hr,`onAnimationEnd`),Zr(Ur,`onAnimationIteration`),Zr(Wr,`onAnimationStart`),Zr(`dblclick`,`onDoubleClick`),Zr(`focusin`,`onFocus`),Zr(`focusout`,`onBlur`),Zr(Gr,`onTransitionRun`),Zr(Kr,`onTransitionStart`),Zr(qr,`onTransitionCancel`),Zr(Jr,`onTransitionEnd`),Tt(`onMouseEnter`,[`mouseout`,`mouseover`]),Tt(`onMouseLeave`,[`mouseout`,`mouseover`]),Tt(`onPointerEnter`,[`pointerout`,`pointerover`]),Tt(`onPointerLeave`,[`pointerout`,`pointerover`]),wt(`onChange`,`change click focusin focusout input keydown keyup selectionchange`.split(` `)),wt(`onSelect`,`focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange`.split(` `)),wt(`onBeforeInput`,[`compositionend`,`keypress`,`textInput`,`paste`]),wt(`onCompositionEnd`,`compositionend focusout keydown keypress keyup mousedown`.split(` `)),wt(`onCompositionStart`,`compositionstart focusout keydown keypress keyup mousedown`.split(` `)),wt(`onCompositionUpdate`,`compositionupdate focusout keydown keypress keyup mousedown`.split(` `));var Od=`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(` `),kd=new Set(`beforetoggle cancel close invalid load scroll scrollend toggle`.split(` `).concat(Od));function Ad(e,t){t=(t&4)!=0;for(var n=0;n<e.length;n++){var r=e[n],i=r.event;r=r.listeners;a:{var a=void 0;if(t)for(var o=r.length-1;0<=o;o--){var s=r[o],c=s.instance,l=s.currentTarget;if(s=s.listener,c!==a&&i.isPropagationStopped())break a;a=s,i.currentTarget=l;try{a(i)}catch(e){Qr(e)}i.currentTarget=null,a=c}else for(o=0;o<r.length;o++){if(s=r[o],c=s.instance,l=s.currentTarget,s=s.listener,c!==a&&i.isPropagationStopped())break a;a=s,i.currentTarget=l;try{a(i)}catch(e){Qr(e)}i.currentTarget=null,a=c}}}}function jd(e,t){var n=t[dt];n===void 0&&(n=t[dt]=new Set);var r=e+`__bubble`;n.has(r)||(Fd(t,e,2,!1),n.add(r))}function Md(e,t,n){var r=0;t&&(r|=4),Fd(n,e,r,t)}var Nd=`_reactListening`+Math.random().toString(36).slice(2);function Pd(e){if(!e[Nd]){e[Nd]=!0,St.forEach(function(t){t!==`selectionchange`&&(kd.has(t)||Md(t,!1,e),Md(t,!0,e))});var t=e.nodeType===9?e:e.ownerDocument;t===null||t[Nd]||(t[Nd]=!0,Md(`selectionchange`,!1,t))}}function Fd(e,t,n,r){switch(Dp(t)){case 2:var i=xp;break;case 8:i=Sp;break;default:i=Cp}n=i.bind(null,t,n,e),i=void 0,!fn||t!==`touchstart`&&t!==`touchmove`&&t!==`wheel`||(i=!0),r?i===void 0?e.addEventListener(t,n,!0):e.addEventListener(t,n,{capture:!0,passive:i}):i===void 0?e.addEventListener(t,n,!1):e.addEventListener(t,n,{passive:i})}function Id(e,t,n,r,i){var a=r;if(!(t&1)&&!(t&2)&&r!==null)a:for(;;){if(r===null)return;var s=r.tag;if(s===3||s===4){var c=r.stateNode.containerInfo;if(c===i)break;if(s===4)for(s=r.return;s!==null;){var l=s.tag;if((l===3||l===4)&&s.stateNode.containerInfo===i)return;s=s.return}for(;c!==null;){if(s=_t(c),s===null)return;if(l=s.tag,l===5||l===6||l===26||l===27){r=a=s;continue a}c=c.parentNode}}r=r.return}ln(function(){var r=a,i=rn(n),s=[];a:{var c=Yr.get(e);if(c!==void 0){var l=Cn,u=e;switch(e){case`keypress`:if(vn(n)===0)break a;case`keydown`:case`keyup`:l=Vn;break;case`focusin`:u=`focus`,l=Mn;break;case`focusout`:u=`blur`,l=Mn;break;case`beforeblur`:case`afterblur`:l=Mn;break;case`click`:if(n.button===2)break a;case`auxclick`:case`dblclick`:case`mousedown`:case`mousemove`:case`mouseup`:case`mouseout`:case`mouseover`:case`contextmenu`:l=An;break;case`drag`:case`dragend`:case`dragenter`:case`dragexit`:case`dragleave`:case`dragover`:case`dragstart`:case`drop`:l=jn;break;case`touchcancel`:case`touchend`:case`touchmove`:case`touchstart`:l=Un;break;case Hr:case Ur:case Wr:l=Nn;break;case Jr:l=Wn;break;case`scroll`:case`scrollend`:l=Tn;break;case`wheel`:l=Gn;break;case`copy`:case`cut`:case`paste`:l=Pn;break;case`gotpointercapture`:case`lostpointercapture`:case`pointercancel`:case`pointerdown`:case`pointermove`:case`pointerout`:case`pointerover`:case`pointerup`:l=Hn;break;case`toggle`:case`beforetoggle`:l=Kn}var d=(t&4)!=0,f=!d&&(e===`scroll`||e===`scrollend`),p=d?c===null?null:c+`Capture`:c;d=[];for(var m=r,h;m!==null;){var g=m;if(h=g.stateNode,g=g.tag,g!==5&&g!==26&&g!==27||h===null||p===null||(g=un(m,p),g!=null&&d.push(Ld(m,g,h))),f)break;m=m.return}0<d.length&&(c=new l(c,u,null,n,i),s.push({event:c,listeners:d}))}}if(!(t&7)){a:{if(c=e===`mouseover`||e===`pointerover`,l=e===`mouseout`||e===`pointerout`,c&&n!==nn&&(u=n.relatedTarget||n.fromElement)&&(_t(u)||u[ut]))break a;if((l||c)&&(c=i.window===i?i:(c=i.ownerDocument)?c.defaultView||c.parentWindow:window,l?(u=n.relatedTarget||n.toElement,l=r,u=u?_t(u):null,u!==null&&(f=o(u),d=u.tag,u!==f||d!==5&&d!==27&&d!==6)&&(u=null)):(l=null,u=r),l!==u)){if(d=An,g=`onMouseLeave`,p=`onMouseEnter`,m=`mouse`,(e===`pointerout`||e===`pointerover`)&&(d=Hn,g=`onPointerLeave`,p=`onPointerEnter`,m=`pointer`),f=l==null?c:yt(l),h=u==null?c:yt(u),c=new d(g,m+`leave`,l,n,i),c.target=f,c.relatedTarget=h,g=null,_t(i)===r&&(d=new d(p,m+`enter`,u,n,i),d.target=h,d.relatedTarget=f,g=d),f=g,l&&u)b:{for(d=zd,p=l,m=u,h=0,g=p;g;g=d(g))h++;g=0;for(var _=m;_;_=d(_))g++;for(;0<h-g;)p=d(p),h--;for(;0<g-h;)m=d(m),g--;for(;h--;){if(p===m||m!==null&&p===m.alternate){d=p;break b}p=d(p),m=d(m)}d=null}else d=null;l!==null&&Bd(s,c,l,d,!1),u!==null&&f!==null&&Bd(s,f,u,d,!0)}}a:{if(c=r?yt(r):window,l=c.nodeName&&c.nodeName.toLowerCase(),l===`select`||l===`input`&&c.type===`file`)var v=fr;else if(or(c))if(pr)v=Sr;else{v=br;var y=yr}else l=c.nodeName,!l||l.toLowerCase()!==`input`||c.type!==`checkbox`&&c.type!==`radio`?r&&Zt(r.elementType)&&(v=fr):v=xr;if(v&&=v(e,r)){sr(s,v,n,i);break a}y&&y(e,c,r),e===`focusout`&&r&&c.type===`number`&&r.memoizedProps.value!=null&&Ut(c,`number`,c.value)}switch(y=r?yt(r):window,e){case`focusin`:(or(y)||y.contentEditable===`true`)&&(Mr=y,Nr=r,Pr=null);break;case`focusout`:Pr=Nr=Mr=null;break;case`mousedown`:Fr=!0;break;case`contextmenu`:case`mouseup`:case`dragend`:Fr=!1,Ir(s,n,i);break;case`selectionchange`:if(jr)break;case`keydown`:case`keyup`:Ir(s,n,i)}var b;if(Jn)b:{switch(e){case`compositionstart`:var x=`onCompositionStart`;break b;case`compositionend`:x=`onCompositionEnd`;break b;case`compositionupdate`:x=`onCompositionUpdate`;break b}x=void 0}else nr?er(e,n)&&(x=`onCompositionEnd`):e===`keydown`&&n.keyCode===229&&(x=`onCompositionStart`);x&&(Zn&&n.locale!==`ko`&&(nr||x!==`onCompositionStart`?x===`onCompositionEnd`&&nr&&(b=_n()):(mn=i,hn=`value`in mn?mn.value:mn.textContent,nr=!0)),y=Rd(r,x),0<y.length&&(x=new Fn(x,e,null,n,i),s.push({event:x,listeners:y}),b?x.data=b:(b=tr(n),b!==null&&(x.data=b)))),(b=Xn?rr(e,n):ir(e,n))&&(x=Rd(r,`onBeforeInput`),0<x.length&&(y=new Fn(`onBeforeInput`,`beforeinput`,null,n,i),s.push({event:y,listeners:x}),y.data=b)),Td(s,e,r,n,i)}Ad(s,t)})}function Ld(e,t,n){return{instance:e,listener:t,currentTarget:n}}function Rd(e,t){for(var n=t+`Capture`,r=[];e!==null;){var i=e,a=i.stateNode;if(i=i.tag,i!==5&&i!==26&&i!==27||a===null||(i=un(e,n),i!=null&&r.unshift(Ld(e,i,a)),i=un(e,t),i!=null&&r.push(Ld(e,i,a))),e.tag===3)return r;e=e.return}return[]}function zd(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5&&e.tag!==27);return e||null}function Bd(e,t,n,r,i){for(var a=t._reactName,o=[];n!==null&&n!==r;){var s=n,c=s.alternate,l=s.stateNode;if(s=s.tag,c!==null&&c===r)break;s!==5&&s!==26&&s!==27||l===null||(c=l,i?(l=un(n,a),l!=null&&o.unshift(Ld(n,l,c))):i||(l=un(n,a),l!=null&&o.push(Ld(n,l,c)))),n=n.return}o.length!==0&&e.push({event:t,listeners:o})}var Vd=/\r\n?/g,Hd=/\u0000|\uFFFD/g;function Ud(e){return(typeof e==`string`?e:``+e).replace(Vd,` 9`).replace(Hd,``)}function Wd(e,t){return t=Ud(t),Ud(e)===t}function Gd(e,t,n,r,a,o){switch(n){case`children`:typeof r==`string`?t===`body`||t===`textarea`&&r===``||qt(e,r):(typeof r==`number`||typeof r==`bigint`)&&t!==`body`&&qt(e,``+r);break;case`className`:jt(e,`class`,r);break;case`tabIndex`:jt(e,`tabindex`,r);break;case`dir`:case`role`:case`viewBox`:case`width`:case`height`:jt(e,n,r);break;case`style`:Xt(e,r,o);break;case`data`:if(t!==`object`){jt(e,`data`,r);break}case`src`:case`href`:if(r===``&&(t!==`a`||n!==`href`)){e.removeAttribute(n);break}if(r==null||typeof r==`function`||typeof r==`symbol`||typeof r==`boolean`){e.removeAttribute(n);break}r=en(``+r),e.setAttribute(n,r);break;case`action`:case`formAction`:if(typeof r==`function`){e.setAttribute(n,`javascript:throw new Error('A React form was unexpectedly submitted. If you called form.submit() manually, consider using form.requestSubmit() instead. If you\\'re trying to use event.stopPropagation() in a submit event handler, consider also calling event.preventDefault().')`);break}else typeof o==`function`&&(n===`formAction`?(t!==`input`&&Gd(e,t,`name`,a.name,a,null),Gd(e,t,`formEncType`,a.formEncType,a,null),Gd(e,t,`formMethod`,a.formMethod,a,null),Gd(e,t,`formTarget`,a.formTarget,a,null)):(Gd(e,t,`encType`,a.encType,a,null),Gd(e,t,`method`,a.method,a,null),Gd(e,t,`target`,a.target,a,null)));if(r==null||typeof r==`symbol`||typeof r==`boolean`){e.removeAttribute(n);break}r=en(``+r),e.setAttribute(n,r);break;case`onClick`:r!=null&&(e.onclick=tn);break;case`onScroll`:r!=null&&jd(`scroll`,e);break;case`onScrollEnd`:r!=null&&jd(`scrollend`,e);break;case`dangerouslySetInnerHTML`:if(r!=null){if(typeof r!=`object`||!(`__html`in r))throw Error(i(61));if(n=r.__html,n!=null){if(a.children!=null)throw Error(i(60));e.innerHTML=n}}break;case`multiple`:e.multiple=r&&typeof r!=`function`&&typeof r!=`symbol`;break;case`muted`:e.muted=r&&typeof r!=`function`&&typeof r!=`symbol`;break;case`suppressContentEditableWarning`:case`suppressHydrationWarning`:case`defaultValue`:case`defaultChecked`:case`innerHTML`:case`ref`:break;case`autoFocus`:break;case`xlinkHref`:if(r==null||typeof r==`function`||typeof r==`boolean`||typeof r==`symbol`){e.removeAttribute(`xlink:href`);break}n=en(``+r),e.setAttributeNS(`http://www.w3.org/1999/xlink`,`xlink:href`,n);break;case`contentEditable`:case`spellCheck`:case`draggable`:case`value`:case`autoReverse`:case`externalResourcesRequired`:case`focusable`:case`preserveAlpha`:r!=null&&typeof r!=`function`&&typeof r!=`symbol`?e.setAttribute(n,``+r):e.removeAttribute(n);break;case`inert`:case`allowFullScreen`:case`async`:case`autoPlay`:case`controls`:case`default`:case`defer`:case`disabled`:case`disablePictureInPicture`:case`disableRemotePlayback`:case`formNoValidate`:case`hidden`:case`loop`:case`noModule`:case`noValidate`:case`open`:case`playsInline`:case`readOnly`:case`required`:case`reversed`:case`scoped`:case`seamless`:case`itemScope`:r&&typeof r!=`function`&&typeof r!=`symbol`?e.setAttribute(n,``):e.removeAttribute(n);break;case`capture`:case`download`:!0===r?e.setAttribute(n,``):!1!==r&&r!=null&&typeof r!=`function`&&typeof r!=`symbol`?e.setAttribute(n,r):e.removeAttribute(n);break;case`cols`:case`rows`:case`size`:case`span`:r!=null&&typeof r!=`function`&&typeof r!=`symbol`&&!isNaN(r)&&1<=r?e.setAttribute(n,r):e.removeAttribute(n);break;case`rowSpan`:case`start`:r==null||typeof r==`function`||typeof r==`symbol`||isNaN(r)?e.removeAttribute(n):e.setAttribute(n,r);break;case`popover`:jd(`beforetoggle`,e),jd(`toggle`,e),At(e,`popover`,r);break;case`xlinkActuate`:Mt(e,`http://www.w3.org/1999/xlink`,`xlink:actuate`,r);break;case`xlinkArcrole`:Mt(e,`http://www.w3.org/1999/xlink`,`xlink:arcrole`,r);break;case`xlinkRole`:Mt(e,`http://www.w3.org/1999/xlink`,`xlink:role`,r);break;case`xlinkShow`:Mt(e,`http://www.w3.org/1999/xlink`,`xlink:show`,r);break;case`xlinkTitle`:Mt(e,`http://www.w3.org/1999/xlink`,`xlink:title`,r);break;case`xlinkType`:Mt(e,`http://www.w3.org/1999/xlink`,`xlink:type`,r);break;case`xmlBase`:Mt(e,`http://www.w3.org/XML/1998/namespace`,`xml:base`,r);break;case`xmlLang`:Mt(e,`http://www.w3.org/XML/1998/namespace`,`xml:lang`,r);break;case`xmlSpace`:Mt(e,`http://www.w3.org/XML/1998/namespace`,`xml:space`,r);break;case`is`:At(e,`is`,r);break;case`innerText`:case`textContent`:break;default:(!(2<n.length)||n[0]!==`o`&&n[0]!==`O`||n[1]!==`n`&&n[1]!==`N`)&&(n=Qt.get(n)||n,At(e,n,r))}}function Kd(e,t,n,r,a,o){switch(n){case`style`:Xt(e,r,o);break;case`dangerouslySetInnerHTML`:if(r!=null){if(typeof r!=`object`||!(`__html`in r))throw Error(i(61));if(n=r.__html,n!=null){if(a.children!=null)throw Error(i(60));e.innerHTML=n}}break;case`children`:typeof r==`string`?qt(e,r):(typeof r==`number`||typeof r==`bigint`)&&qt(e,``+r);break;case`onScroll`:r!=null&&jd(`scroll`,e);break;case`onScrollEnd`:r!=null&&jd(`scrollend`,e);break;case`onClick`:r!=null&&(e.onclick=tn);break;case`suppressContentEditableWarning`:case`suppressHydrationWarning`:case`innerHTML`:case`ref`:break;case`innerText`:case`textContent`:break;default:if(!Ct.hasOwnProperty(n))a:{if(n[0]===`o`&&n[1]===`n`&&(a=n.endsWith(`Capture`),t=n.slice(2,a?n.length-7:void 0),o=e[lt]||null,o=o==null?null:o[n],typeof o==`function`&&e.removeEventListener(t,o,a),typeof r==`function`)){typeof o!=`function`&&o!==null&&(n in e?e[n]=null:e.hasAttribute(n)&&e.removeAttribute(n)),e.addEventListener(t,r,a);break a}n in e?e[n]=r:!0===r?e.setAttribute(n,``):At(e,n,r)}}}function qd(e,t,n){switch(t){case`div`:case`span`:case`svg`:case`path`:case`a`:case`g`:case`p`:case`li`:break;case`img`:jd(`error`,e),jd(`load`,e);var r=!1,a=!1,o;for(o in n)if(n.hasOwnProperty(o)){var s=n[o];if(s!=null)switch(o){case`src`:r=!0;break;case`srcSet`:a=!0;break;case`children`:case`dangerouslySetInnerHTML`:throw Error(i(137,t));default:Gd(e,t,o,s,n,null)}}a&&Gd(e,t,`srcSet`,n.srcSet,n,null),r&&Gd(e,t,`src`,n.src,n,null);return;case`input`:jd(`invalid`,e);var c=o=s=a=null,l=null,u=null;for(r in n)if(n.hasOwnProperty(r)){var d=n[r];if(d!=null)switch(r){case`name`:a=d;break;case`type`:s=d;break;case`checked`:l=d;break;case`defaultChecked`:u=d;break;case`value`:o=d;break;case`defaultValue`:c=d;break;case`children`:case`dangerouslySetInnerHTML`:if(d!=null)throw Error(i(137,t));break;default:Gd(e,t,r,d,n,null)}}Ht(e,o,c,l,u,s,a,!1);return;case`select`:for(a in jd(`invalid`,e),r=s=o=null,n)if(n.hasOwnProperty(a)&&(c=n[a],c!=null))switch(a){case`value`:o=c;break;case`defaultValue`:s=c;break;case`multiple`:r=c;default:Gd(e,t,a,c,n,null)}t=o,n=s,e.multiple=!!r,t==null?n!=null&&Wt(e,!!r,n,!0):Wt(e,!!r,t,!1);return;case`textarea`:for(s in jd(`invalid`,e),o=a=r=null,n)if(n.hasOwnProperty(s)&&(c=n[s],c!=null))switch(s){case`value`:r=c;break;case`defaultValue`:a=c;break;case`children`:o=c;break;case`dangerouslySetInnerHTML`:if(c!=null)throw Error(i(91));break;default:Gd(e,t,s,c,n,null)}Kt(e,r,a,o);return;case`option`:for(l in n)if(n.hasOwnProperty(l)&&(r=n[l],r!=null))switch(l){case`selected`:e.selected=r&&typeof r!=`function`&&typeof r!=`symbol`;break;default:Gd(e,t,l,r,n,null)}return;case`dialog`:jd(`beforetoggle`,e),jd(`toggle`,e),jd(`cancel`,e),jd(`close`,e);break;case`iframe`:case`object`:jd(`load`,e);break;case`video`:case`audio`:for(r=0;r<Od.length;r++)jd(Od[r],e);break;case`image`:jd(`error`,e),jd(`load`,e);break;case`details`:jd(`toggle`,e);break;case`embed`:case`source`:case`link`:jd(`error`,e),jd(`load`,e);case`area`:case`base`:case`br`:case`col`:case`hr`:case`keygen`:case`meta`:case`param`:case`track`:case`wbr`:case`menuitem`:for(u in n)if(n.hasOwnProperty(u)&&(r=n[u],r!=null))switch(u){case`children`:case`dangerouslySetInnerHTML`:throw Error(i(137,t));default:Gd(e,t,u,r,n,null)}return;default:if(Zt(t)){for(d in n)n.hasOwnProperty(d)&&(r=n[d],r!==void 0&&Kd(e,t,d,r,n,void 0));return}}for(c in n)n.hasOwnProperty(c)&&(r=n[c],r!=null&&Gd(e,t,c,r,n,null))}function Jd(e,t,n,r){switch(t){case`div`:case`span`:case`svg`:case`path`:case`a`:case`g`:case`p`:case`li`:break;case`input`:var a=null,o=null,s=null,c=null,l=null,u=null,d=null;for(m in n){var f=n[m];if(n.hasOwnProperty(m)&&f!=null)switch(m){case`checked`:break;case`value`:break;case`defaultValue`:l=f;default:r.hasOwnProperty(m)||Gd(e,t,m,null,r,f)}}for(var p in r){var m=r[p];if(f=n[p],r.hasOwnProperty(p)&&(m!=null||f!=null))switch(p){case`type`:o=m;break;case`name`:a=m;break;case`checked`:u=m;break;case`defaultChecked`:d=m;break;case`value`:s=m;break;case`defaultValue`:c=m;break;case`children`:case`dangerouslySetInnerHTML`:if(m!=null)throw Error(i(137,t));break;default:m!==f&&Gd(e,t,p,m,r,f)}}Vt(e,s,c,l,u,d,o,a);return;case`select`:for(o in m=s=c=p=null,n)if(l=n[o],n.hasOwnProperty(o)&&l!=null)switch(o){case`value`:break;case`multiple`:m=l;default:r.hasOwnProperty(o)||Gd(e,t,o,null,r,l)}for(a in r)if(o=r[a],l=n[a],r.hasOwnProperty(a)&&(o!=null||l!=null))switch(a){case`value`:p=o;break;case`defaultValue`:c=o;break;case`multiple`:s=o;default:o!==l&&Gd(e,t,a,o,r,l)}t=c,n=s,r=m,p==null?!!r!=!!n&&(t==null?Wt(e,!!n,n?[]:``,!1):Wt(e,!!n,t,!0)):Wt(e,!!n,p,!1);return;case`textarea`:for(c in m=p=null,n)if(a=n[c],n.hasOwnProperty(c)&&a!=null&&!r.hasOwnProperty(c))switch(c){case`value`:break;case`children`:break;default:Gd(e,t,c,null,r,a)}for(s in r)if(a=r[s],o=n[s],r.hasOwnProperty(s)&&(a!=null||o!=null))switch(s){case`value`:p=a;break;case`defaultValue`:m=a;break;case`children`:break;case`dangerouslySetInnerHTML`:if(a!=null)throw Error(i(91));break;default:a!==o&&Gd(e,t,s,a,r,o)}Gt(e,p,m);return;case`option`:for(var h in n)if(p=n[h],n.hasOwnProperty(h)&&p!=null&&!r.hasOwnProperty(h))switch(h){case`selected`:e.selected=!1;break;default:Gd(e,t,h,null,r,p)}for(l in r)if(p=r[l],m=n[l],r.hasOwnProperty(l)&&p!==m&&(p!=null||m!=null))switch(l){case`selected`:e.selected=p&&typeof p!=`function`&&typeof p!=`symbol`;break;default:Gd(e,t,l,p,r,m)}return;case`img`:case`link`:case`area`:case`base`:case`br`:case`col`:case`embed`:case`hr`:case`keygen`:case`meta`:case`param`:case`source`:case`track`:case`wbr`:case`menuitem`:for(var g in n)p=n[g],n.hasOwnProperty(g)&&p!=null&&!r.hasOwnProperty(g)&&Gd(e,t,g,null,r,p);for(u in r)if(p=r[u],m=n[u],r.hasOwnProperty(u)&&p!==m&&(p!=null||m!=null))switch(u){case`children`:case`dangerouslySetInnerHTML`:if(p!=null)throw Error(i(137,t));break;default:Gd(e,t,u,p,r,m)}return;default:if(Zt(t)){for(var _ in n)p=n[_],n.hasOwnProperty(_)&&p!==void 0&&!r.hasOwnProperty(_)&&Kd(e,t,_,void 0,r,p);
vendor: 4,463 bytes, line 9
9for(d in r)p=r[d],m=n[d],!r.hasOwnProperty(d)||p===m||p===void 0&&m===void 0||Kd(e,t,d,p,r,m);return}}for(var v in n)p=n[v],n.hasOwnProperty(v)&&p!=null&&!r.hasOwnProperty(v)&&Gd(e,t,v,null,r,p);for(f in r)p=r[f],m=n[f],!r.hasOwnProperty(f)||p===m||p==null&&m==null||Gd(e,t,f,p,r,m)}function Yd(e){switch(e){case`css`:case`script`:case`font`:case`img`:case`image`:case`input`:case`link`:return!0;default:return!1}}function Xd(){if(typeof performance.getEntriesByType==`function`){for(var e=0,t=0,n=performance.getEntriesByType(`resource`),r=0;r<n.length;r++){var i=n[r],a=i.transferSize,o=i.initiatorType,s=i.duration;if(a&&s&&Yd(o)){for(o=0,s=i.responseEnd,r+=1;r<n.length;r++){var c=n[r],l=c.startTime;if(l>s)break;var u=c.transferSize,d=c.initiatorType;u&&Yd(d)&&(c=c.responseEnd,o+=u*(c<s?1:(s-l)/(c-l)))}if(--r,t+=8*(a+o)/(i.duration/1e3),e++,10<e)break}}if(0<e)return t/e/1e6}return navigator.connection&&(e=navigator.connection.downlink,typeof e==`number`)?e:5}var Zd=null,Qd=null;function $d(e){return e.nodeType===9?e:e.ownerDocument}function ef(e){switch(e){case`http://www.w3.org/2000/svg`:return 1;case`http://www.w3.org/1998/Math/MathML`:return 2;default:return 0}}function tf(e,t){if(e===0)switch(t){case`svg`:return 1;case`math`:return 2;default:return 0}return e===1&&t===`foreignObject`?0:e}function nf(e,t){return e===`textarea`||e===`noscript`||typeof t.children==`string`||typeof t.children==`number`||typeof t.children==`bigint`||typeof t.dangerouslySetInnerHTML==`object`&&t.dangerouslySetInnerHTML!==null&&t.dangerouslySetInnerHTML.__html!=null}var rf=null;function af(){var e=window.event;return e&&e.type===`popstate`?e===rf?!1:(rf=e,!0):(rf=null,!1)}var of=typeof setTimeout==`function`?setTimeout:void 0,sf=typeof clearTimeout==`function`?clearTimeout:void 0,cf=typeof Promise==`function`?Promise:void 0,lf=typeof queueMicrotask==`function`?queueMicrotask:cf===void 0?of:function(e){return cf.resolve(null).then(e).catch(uf)};function uf(e){setTimeout(function(){throw e})}function df(e){return e===`head`}function ff(e,t){var n=t,r=0;do{var i=n.nextSibling;if(e.removeChild(n),i&&i.nodeType===8)if(n=i.data,n===`/$`||n===`/&`){if(r===0){e.removeChild(i),Kp(t);return}r--}else if(n===`$`||n===`$?`||n===`$~`||n===`$!`||n===`&`)r++;else if(n===`html`)Ef(e.ownerDocument.documentElement);else if(n===`head`){n=e.ownerDocument.head,Ef(n);for(var a=n.firstChild;a;){var o=a.nextSibling,s=a.nodeName;a[ht]||s===`SCRIPT`||s===`STYLE`||s===`LINK`&&a.rel.toLowerCase()===`stylesheet`||n.removeChild(a),a=o}}else n===`body`&&Ef(e.ownerDocument.body);n=i}while(n);Kp(t)}function pf(e,t){var n=e;e=0;do{var r=n.nextSibling;if(n.nodeType===1?t?(n._stashedDisplay=n.style.display,n.style.display=`none`):(n.style.display=n._stashedDisplay||``,n.getAttribute(`style`)===``&&n.removeAttribute(`style`)):n.nodeType===3&&(t?(n._stashedText=n.nodeValue,n.nodeValue=``):n.nodeValue=n._stashedText||``),r&&r.nodeType===8)if(n=r.data,n===`/$`){if(e===0)break;e--}else n!==`$`&&n!==`$?`&&n!==`$~`&&n!==`$!`||e++;n=r}while(n)}function mf(e){var t=e.firstChild;for(t&&t.nodeType===10&&(t=t.nextSibling);t;){var n=t;switch(t=t.nextSibling,n.nodeName){case`HTML`:case`HEAD`:case`BODY`:mf(n),gt(n);continue;case`SCRIPT`:case`STYLE`:continue;case`LINK`:if(n.rel.toLowerCase()===`stylesheet`)continue}e.removeChild(n)}}function hf(e,t,n,r){for(;e.nodeType===1;){var i=n;if(e.nodeName.toLowerCase()!==t.toLowerCase()){if(!r&&(e.nodeName!==`INPUT`||e.type!==`hidden`))break}else if(!r)if(t===`input`&&e.type===`hidden`){var a=i.name==null?null:``+i.name;if(i.type===`hidden`&&e.getAttribute(`name`)===a)return e}else return e;else if(!e[ht])switch(t){case`meta`:if(!e.hasAttribute(`itemprop`))break;return e;case`link`:if(a=e.getAttribute(`rel`),a===`stylesheet`&&e.hasAttribute(`data-precedence`)||a!==i.rel||e.getAttribute(`href`)!==(i.href==null||i.href===``?null:i.href)||e.getAttribute(`crossorigin`)!==(i.crossOrigin==null?null:i.crossOrigin)||e.getAttribute(`title`)!==(i.title==null?null:i.title))break;return e;case`style`:if(e.hasAttribute(`data-precedence`))break;return e;case`script`:if(a=e.getAttribute(`src`),(a!==(i.src==null?null:i.src)||e.getAttribute(`type`)!==(i.type==null?null:i.type)||e.getAttribute(`crossorigin`)!==(i.crossOrigin==null?null:i.crossOrigin))&&a&&e.hasAttribute(`async`)&&!e.hasAttribute(`itemprop`))break;return e;default:return e}if(e=xf(e.nextSibling),e===null)break}return null}function gf(e,t,n){if(t===``)return null;for(;
vendor: 18,557 bytes, line 9
9e.nodeType!==3;)if((e.nodeType!==1||e.nodeName!==`INPUT`||e.type!==`hidden`)&&!n||(e=xf(e.nextSibling),e===null))return null;return e}function _f(e,t){for(;e.nodeType!==8;)if((e.nodeType!==1||e.nodeName!==`INPUT`||e.type!==`hidden`)&&!t||(e=xf(e.nextSibling),e===null))return null;return e}function vf(e){return e.data===`$?`||e.data===`$~`}function yf(e){return e.data===`$!`||e.data===`$?`&&e.ownerDocument.readyState!==`loading`}function bf(e,t){var n=e.ownerDocument;if(e.data===`$~`)e._reactRetry=t;else if(e.data!==`$?`||n.readyState!==`loading`)t();else{var r=function(){t(),n.removeEventListener(`DOMContentLoaded`,r)};n.addEventListener(`DOMContentLoaded`,r),e._reactRetry=r}}function xf(e){for(;e!=null;e=e.nextSibling){var t=e.nodeType;if(t===1||t===3)break;if(t===8){if(t=e.data,t===`$`||t===`$!`||t===`$?`||t===`$~`||t===`&`||t===`F!`||t===`F`)break;if(t===`/$`||t===`/&`)return null}}return e}var Sf=null;function Cf(e){e=e.nextSibling;for(var t=0;e;){if(e.nodeType===8){var n=e.data;if(n===`/$`||n===`/&`){if(t===0)return xf(e.nextSibling);t--}else n!==`$`&&n!==`$!`&&n!==`$?`&&n!==`$~`&&n!==`&`||t++}e=e.nextSibling}return null}function wf(e){e=e.previousSibling;for(var t=0;e;){if(e.nodeType===8){var n=e.data;if(n===`$`||n===`$!`||n===`$?`||n===`$~`||n===`&`){if(t===0)return e;t--}else n!==`/$`&&n!==`/&`||t++}e=e.previousSibling}return null}function Tf(e,t,n){switch(t=$d(n),e){case`html`:if(e=t.documentElement,!e)throw Error(i(452));return e;case`head`:if(e=t.head,!e)throw Error(i(453));return e;case`body`:if(e=t.body,!e)throw Error(i(454));return e;default:throw Error(i(451))}}function Ef(e){for(var t=e.attributes;t.length;)e.removeAttributeNode(t[0]);gt(e)}var Df=new Map,Of=new Set;function kf(e){return typeof e.getRootNode==`function`?e.getRootNode():e.nodeType===9?e:e.ownerDocument}var Af=I.d;I.d={f:jf,r:Mf,D:Ff,C:If,L:Lf,m:Rf,X:Bf,S:zf,M:Vf};function jf(){var e=Af.f(),t=Au();return e||t}function Mf(e){var t=vt(e);t!==null&&t.tag===5&&t.type===`form`?ks(t):Af.r(e)}var Nf=typeof document>`u`?null:document;function Pf(e,t,n){var r=Nf;if(r&&typeof t==`string`&&t){var i=Bt(t);i=`link[rel="`+e+`"][href="`+i+`"]`,typeof n==`string`&&(i+=`[crossorigin="`+n+`"]`),Of.has(i)||(Of.add(i),e={rel:e,crossOrigin:n,href:t},r.querySelector(i)===null&&(t=r.createElement(`link`),qd(t,`link`,e),xt(t),r.head.appendChild(t)))}}function Ff(e){Af.D(e),Pf(`dns-prefetch`,e,null)}function If(e,t){Af.C(e,t),Pf(`preconnect`,e,t)}function Lf(e,t,n){Af.L(e,t,n);var r=Nf;if(r&&e&&t){var i=`link[rel="preload"][as="`+Bt(t)+`"]`;t===`image`&&n&&n.imageSrcSet?(i+=`[imagesrcset="`+Bt(n.imageSrcSet)+`"]`,typeof n.imageSizes==`string`&&(i+=`[imagesizes="`+Bt(n.imageSizes)+`"]`)):i+=`[href="`+Bt(e)+`"]`;var a=i;switch(t){case`style`:a=Uf(e);break;case`script`:a=qf(e)}Df.has(a)||(e=h({rel:`preload`,href:t===`image`&&n&&n.imageSrcSet?void 0:e,as:t},n),Df.set(a,e),r.querySelector(i)!==null||t===`style`&&r.querySelector(Wf(a))||t===`script`&&r.querySelector(Jf(a))||(t=r.createElement(`link`),qd(t,`link`,e),xt(t),r.head.appendChild(t)))}}function Rf(e,t){Af.m(e,t);var n=Nf;if(n&&e){var r=t&&typeof t.as==`string`?t.as:`script`,i=`link[rel="modulepreload"][as="`+Bt(r)+`"][href="`+Bt(e)+`"]`,a=i;switch(r){case`audioworklet`:case`paintworklet`:case`serviceworker`:case`sharedworker`:case`worker`:case`script`:a=qf(e)}if(!Df.has(a)&&(e=h({rel:`modulepreload`,href:e},t),Df.set(a,e),n.querySelector(i)===null)){switch(r){case`audioworklet`:case`paintworklet`:case`serviceworker`:case`sharedworker`:case`worker`:case`script`:if(n.querySelector(Jf(a)))return}r=n.createElement(`link`),qd(r,`link`,e),xt(r),n.head.appendChild(r)}}}function zf(e,t,n){Af.S(e,t,n);var r=Nf;if(r&&e){var i=bt(r).hoistableStyles,a=Uf(e);t||=`default`;var o=i.get(a);if(!o){var s={loading:0,preload:null};if(o=r.querySelector(Wf(a)))s.loading=5;else{e=h({rel:`stylesheet`,href:e,"data-precedence":t},n),(n=Df.get(a))&&Zf(e,n);var c=o=r.createElement(`link`);xt(c),qd(c,`link`,e),c._p=new Promise(function(e,t){c.onload=e,c.onerror=t}),c.addEventListener(`load`,function(){s.loading|=1}),c.addEventListener(`error`,function(){s.loading|=2}),s.loading|=4,Xf(o,t,r)}o={type:`stylesheet`,instance:o,count:1,state:s},i.set(a,o)}}}function Bf(e,t){Af.X(e,t);var n=Nf;if(n&&e){var r=bt(n).hoistableScripts,i=qf(e),a=r.get(i);a||(a=n.querySelector(Jf(i)),a||(e=h({src:e,async:!0},t),(t=Df.get(i))&&Qf(e,t),a=n.createElement(`script`),xt(a),qd(a,`link`,e),n.head.appendChild(a)),a={type:`script`,instance:a,count:1,state:null},r.set(i,a))}}function Vf(e,t){Af.M(e,t);var n=Nf;if(n&&e){var r=bt(n).hoistableScripts,i=qf(e),a=r.get(i);a||(a=n.querySelector(Jf(i)),a||(e=h({src:e,async:!0,type:`module`},t),(t=Df.get(i))&&Qf(e,t),a=n.createElement(`script`),xt(a),qd(a,`link`,e),n.head.appendChild(a)),a={type:`script`,instance:a,count:1,state:null},r.set(i,a))}}function Hf(e,t,n,r){var a=(a=le.current)?kf(a):null;if(!a)throw Error(i(446));switch(e){case`meta`:case`title`:return null;case`style`:return typeof n.precedence==`string`&&typeof n.href==`string`?(t=Uf(n.href),n=bt(a).hoistableStyles,r=n.get(t),r||(r={type:`style`,instance:null,count:0,state:null},n.set(t,r)),r):{type:`void`,instance:null,count:0,state:null};case`link`:if(n.rel===`stylesheet`&&typeof n.href==`string`&&typeof n.precedence==`string`){e=Uf(n.href);var o=bt(a).hoistableStyles,s=o.get(e);if(s||(a=a.ownerDocument||a,s={type:`stylesheet`,instance:null,count:0,state:{loading:0,preload:null}},o.set(e,s),(o=a.querySelector(Wf(e)))&&!o._p&&(s.instance=o,s.state.loading=5),Df.has(e)||(n={rel:`preload`,as:`style`,href:n.href,crossOrigin:n.crossOrigin,integrity:n.integrity,media:n.media,hrefLang:n.hrefLang,referrerPolicy:n.referrerPolicy},Df.set(e,n),o||Kf(a,e,n,s.state))),t&&r===null)throw Error(i(528,``));return s}if(t&&r!==null)throw Error(i(529,``));return null;case`script`:return t=n.async,n=n.src,typeof n==`string`&&t&&typeof t!=`function`&&typeof t!=`symbol`?(t=qf(n),n=bt(a).hoistableScripts,r=n.get(t),r||(r={type:`script`,instance:null,count:0,state:null},n.set(t,r)),r):{type:`void`,instance:null,count:0,state:null};default:throw Error(i(444,e))}}function Uf(e){return`href="`+Bt(e)+`"`}function Wf(e){return`link[rel="stylesheet"][`+e+`]`}function Gf(e){return h({},e,{"data-precedence":e.precedence,precedence:null})}function Kf(e,t,n,r){e.querySelector(`link[rel="preload"][as="style"][`+t+`]`)?r.loading=1:(t=e.createElement(`link`),r.preload=t,t.addEventListener(`load`,function(){return r.loading|=1}),t.addEventListener(`error`,function(){return r.loading|=2}),qd(t,`link`,n),xt(t),e.head.appendChild(t))}function qf(e){return`[src="`+Bt(e)+`"]`}function Jf(e){return`script[async]`+e}function Yf(e,t,n){if(t.count++,t.instance===null)switch(t.type){case`style`:var r=e.querySelector(`style[data-href~="`+Bt(n.href)+`"]`);if(r)return t.instance=r,xt(r),r;var a=h({},n,{"data-href":n.href,"data-precedence":n.precedence,href:null,precedence:null});return r=(e.ownerDocument||e).createElement(`style`),xt(r),qd(r,`style`,a),Xf(r,n.precedence,e),t.instance=r;case`stylesheet`:a=Uf(n.href);var o=e.querySelector(Wf(a));if(o)return t.state.loading|=4,t.instance=o,xt(o),o;r=Gf(n),(a=Df.get(a))&&Zf(r,a),o=(e.ownerDocument||e).createElement(`link`),xt(o);var s=o;return s._p=new Promise(function(e,t){s.onload=e,s.onerror=t}),qd(o,`link`,r),t.state.loading|=4,Xf(o,n.precedence,e),t.instance=o;case`script`:return o=qf(n.src),(a=e.querySelector(Jf(o)))?(t.instance=a,xt(a),a):(r=n,(a=Df.get(o))&&(r=h({},n),Qf(r,a)),e=e.ownerDocument||e,a=e.createElement(`script`),xt(a),qd(a,`link`,r),e.head.appendChild(a),t.instance=a);case`void`:return null;default:throw Error(i(443,t.type))}else t.type===`stylesheet`&&!(t.state.loading&4)&&(r=t.instance,t.state.loading|=4,Xf(r,n.precedence,e));return t.instance}function Xf(e,t,n){for(var r=n.querySelectorAll(`link[rel="stylesheet"][data-precedence],style[data-precedence]`),i=r.length?r[r.length-1]:null,a=i,o=0;o<r.length;o++){var s=r[o];if(s.dataset.precedence===t)a=s;else if(a!==i)break}a?a.parentNode.insertBefore(e,a.nextSibling):(t=n.nodeType===9?n.head:n,t.insertBefore(e,t.firstChild))}function Zf(e,t){e.crossOrigin??=t.crossOrigin,e.referrerPolicy??=t.referrerPolicy,e.title??=t.title}function Qf(e,t){e.crossOrigin??=t.crossOrigin,e.referrerPolicy??=t.referrerPolicy,e.integrity??=t.integrity}var $f=null;function ep(e,t,n){if($f===null){var r=new Map,i=$f=new Map;i.set(n,r)}else i=$f,r=i.get(n),r||(r=new Map,i.set(n,r));if(r.has(e))return r;for(r.set(e,null),n=n.getElementsByTagName(e),i=0;i<n.length;i++){var a=n[i];if(!(a[ht]||a[ct]||e===`link`&&a.getAttribute(`rel`)===`stylesheet`)&&a.namespaceURI!==`http://www.w3.org/2000/svg`){var o=a.getAttribute(t)||``;o=e+o;var s=r.get(o);s?s.push(a):r.set(o,[a])}}return r}function tp(e,t,n){e=e.ownerDocument||e,e.head.insertBefore(n,t===`title`?e.querySelector(`head > title`):null)}function np(e,t,n){if(n===1||t.itemProp!=null)return!1;switch(e){case`meta`:case`title`:return!0;case`style`:if(typeof t.precedence!=`string`||typeof t.href!=`string`||t.href===``)break;return!0;case`link`:if(typeof t.rel!=`string`||typeof t.href!=`string`||t.href===``||t.onLoad||t.onError)break;switch(t.rel){case`stylesheet`:return e=t.disabled,typeof t.precedence==`string`&&e==null;default:return!0}case`script`:if(t.async&&typeof t.async!=`function`&&typeof t.async!=`symbol`&&!t.onLoad&&!t.onError&&t.src&&typeof t.src==`string`)return!0}return!1}function rp(e){return!(e.type===`stylesheet`&&!(e.state.loading&3))}function ip(e,t,n,r){if(n.type===`stylesheet`&&(typeof r.media!=`string`||!1!==matchMedia(r.media).matches)&&!(n.state.loading&4)){if(n.instance===null){var i=Uf(r.href),a=t.querySelector(Wf(i));if(a){t=a._p,typeof t==`object`&&t&&typeof t.then==`function`&&(e.count++,e=sp.bind(e),t.then(e,e)),n.state.loading|=4,n.instance=a,xt(a);return}a=t.ownerDocument||t,r=Gf(r),(i=Df.get(i))&&Zf(r,i),a=a.createElement(`link`),xt(a);var o=a;o._p=new Promise(function(e,t){o.onload=e,o.onerror=t}),qd(a,`link`,r),n.instance=a}e.stylesheets===null&&(e.stylesheets=new Map),e.stylesheets.set(n,t),(t=n.state.preload)&&!(n.state.loading&3)&&(e.count++,n=sp.bind(e),t.addEventListener(`load`,n),t.addEventListener(`error`,n))}}var ap=0;function op(e,t){return e.stylesheets&&e.count===0&&lp(e,e.stylesheets),0<e.count||0<e.imgCount?function(n){var r=setTimeout(function(){if(e.stylesheets&&lp(e,e.stylesheets),e.unsuspend){var t=e.unsuspend;e.unsuspend=null,t()}},6e4+t);0<e.imgBytes&&ap===0&&(ap=62500*Xd());var i=setTimeout(function(){if(e.waitingForImages=!1,e.count===0&&(e.stylesheets&&lp(e,e.stylesheets),e.unsuspend)){var t=e.unsuspend;e.unsuspend=null,t()}},(e.imgBytes>ap?50:800)+t);return e.unsuspend=n,function(){e.unsuspend=null,clearTimeout(r),clearTimeout(i)}}:null}function sp(){if(this.count--,this.count===0&&(this.imgCount===0||!this.waitingForImages)){if(this.stylesheets)lp(this,this.stylesheets);else if(this.unsuspend){var e=this.unsuspend;this.unsuspend=null,e()}}}var cp=null;function lp(e,t){e.stylesheets=null,e.unsuspend!==null&&(e.count++,cp=new Map,t.forEach(up,e),cp=null,sp.call(e))}function up(e,t){if(!(t.state.loading&4)){var n=cp.get(e);if(n)var r=n.get(null);else{n=new Map,cp.set(e,n);for(var i=e.querySelectorAll(`link[data-precedence],style[data-precedence]`),a=0;a<i.length;a++){var o=i[a];(o.nodeName===`LINK`||o.getAttribute(`media`)!==`not all`)&&(n.set(o.dataset.precedence,o),r=o)}r&&n.set(null,r)}i=t.instance,o=i.getAttribute(`data-precedence`),a=n.get(o)||r,a===r&&n.set(null,i),n.set(o,i),this.count++,r=sp.bind(this),i.addEventListener(`load`,r),i.addEventListener(`error`,r),a?a.parentNode.insertBefore(i,a.nextSibling):(e=e.nodeType===9?e.head:e,e.insertBefore(i,e.firstChild)),t.state.loading|=4}}var dp={$$typeof:C,Provider:null,Consumer:null,_currentValue:te,_currentValue2:te,_threadCount:0};function fp(e,t,n,r,i,a,o,s,c){this.tag=1,this.containerInfo=e,this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.next=this.pendingContext=this.context=this.cancelPendingCommit=null,this.callbackPriority=0,this.expirationTimes=Ze(-1),this.entangledLanes=this.shellSuspendCounter=this.errorRecoveryDisabledLanes=this.expiredLanes=this.warmLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Ze(0),this.hiddenUpdates=Ze(null),this.identifierPrefix=r,this.onUncaughtError=i,this.onCaughtError=a,this.onRecoverableError=o,this.pooledCache=null,this.pooledCacheLanes=0,this.formState=c,this.incompleteTransitions=new Map}function pp(e,t,n,r,i,a,o,s,c,l,u,d){return e=new fp(e,t,n,o,c,l,u,d,s),t=1,!0===a&&(t|=24),a=li(3,null,null,t),e.current=a,a.stateNode=e,t=ca(),t.refCount++,e.pooledCache=t,t.refCount++,a.memoizedState={element:r,isDehydrated:n,cache:t},Ba(a),e}function mp(e){return e?(e=si,e):si}function hp(e,t,n,r,i,a){i=mp(i),r.context===null?r.context=i:r.pendingContext=i,r=Ha(t),r.payload={element:n},a=a===void 0?null:a,a!==null&&(r.callback=a),n=Ua(e,r,t),n!==null&&(Tu(n,e,t),Wa(n,e,t))}function gp(e,t){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var n=e.retryLane;e.retryLane=n!==0&&n<t?n:t}}function _p(e,t){gp(e,t),(e=e.alternate)&&gp(e,t)}function vp(e){if(e.tag===13||e.tag===31){var t=ii(e,67108864);t!==null&&Tu(t,e,67108864),_p(e,67108864)}}function yp(e){if(e.tag===13||e.tag===31){var t=Cu();t=rt(t);var n=ii(e,t);n!==null&&Tu(n,e,t),_p(e,t)}}var bp=!0;function xp(e,t,n,r){var i=F.T;F.T=null;var a=I.p;try{I.p=2,Cp(e,t,n,r)}finally{I.p=a,F.T=i}}function Sp(e,t,n,r){var i=F.T;F.T=null;var a=I.p;try{I.p=8,Cp(e,t,n,r)}finally{I.p=a,F.T=i}}function Cp(e,t,n,r){if(bp){var i=wp(r);if(i===null)Id(e,t,r,Tp,n),Ip(e,r);else if(Rp(i,e,t,n,r))r.stopPropagation();else if(Ip(e,r),t&4&&-1<Fp.indexOf(e)){for(;i!==null;){var a=vt(i);if(a!==null)switch(a.tag){case 3:if(a=a.stateNode,a.current.memoizedState.isDehydrated){var o=Ke(a.pendingLanes);if(o!==0){var s=a;for(s.pendingLanes|=2,s.entangledLanes|=2;o;){var c=1<<31-ze(o);s.entanglements[1]|=c,o&=~c}md(a),!(Wl&6)&&(du=De()+500,hd(0,!1))}}break;case 31:case 13:s=ii(a,2),s!==null&&Tu(s,a,2),Au(),_p(a,2)}if(a=wp(r),a===null&&Id(e,t,r,Tp,n),a===i)break;i=a}i!==null&&r.stopPropagation()}else Id(e,t,r,null,n)}}function wp(e){return e=rn(e),Ep(e)}var Tp=null;function Ep(e){if(Tp=null,e=_t(e),e!==null){var t=o(e);if(t===null)e=null;else{var n=t.tag;if(n===13){if(e=s(t),e!==null)return e;e=null}else if(n===31){if(e=c(t),e!==null)return e;e=null}else if(n===3){if(t.stateNode.current.memoizedState.isDehydrated)return t.tag===3?t.stateNode.containerInfo:null;e=null}else t!==e&&(e=null)}}return Tp=e,null}function Dp(e){switch(e){case`beforetoggle`: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`toggle`: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 2;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`touchmove`:case`wheel`:case`mouseenter`:case`mouseleave`:case`pointerenter`:case`pointerleave`:return 8;case`message`:switch(Oe()){case ke:return 2;case Ae:return 8;case je:case Me:return 32;case Ne:return 268435456;default:return 32}default:return 32}}var Op=!1,kp=null,Ap=null,jp=null,Mp=new Map,Np=new Map,Pp=[],Fp=`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`.split(` `);function Ip(e,t){switch(e){case`focusin`:case`focusout`:kp=null;break;case`dragenter`:case`dragleave`:Ap=null;break;case`mouseover`:case`mouseout`:jp=null;break;case`pointerover`:case`pointerout`:Mp.delete(t.pointerId);break;case`gotpointercapture`:case`lostpointercapture`:Np.delete(t.pointerId)}}function Lp(e,t,n,r,i,a){return e===null||e.nativeEvent!==a?(e={blockedOn:t,domEventName:n,eventSystemFlags:r,nativeEvent:a,targetContainers:[i]},t!==null&&(t=vt(t),t!==null&&vp(t)),e):(e.eventSystemFlags|=r,t=e.targetContainers,i!==null&&t.indexOf(i)===-1&&t.push(i),e)}function Rp(e,t,n,r,i){switch(t){case`focusin`:return kp=Lp(kp,e,t,n,r,i),!0;case`dragenter`:return Ap=Lp(Ap,e,t,n,r,i),!0;case`mouseover`:return jp=Lp(jp,e,t,n,r,i),!0;case`pointerover`:var a=i.pointerId;return Mp.set(a,Lp(Mp.get(a)||null,e,t,n,r,i)),!0;case`gotpointercapture`:return a=i.pointerId,Np.set(a,Lp(Np.get(a)||null,e,t,n,r,i)),!0}return!1}function zp(e){var t=_t(e.target);if(t!==null){var n=o(t);if(n!==null){if(t=n.tag,t===13){if(t=s(n),t!==null){e.blockedOn=t,ot(e.priority,function(){yp(n)});return}}else if(t===31){if(t=c(n),t!==null){e.blockedOn=t,ot(e.priority,function(){yp(n)});return}}else if(t===3&&n.stateNode.current.memoizedState.isDehydrated){e.blockedOn=n.tag===3?n.stateNode.containerInfo:null;return}}}e.blockedOn=null}function Bp(e){if(e.blockedOn!==null)return!1;for(var t=e.targetContainers;0<t.length;){var n=wp(e.nativeEvent);if(n===null){n=e.nativeEvent;var r=new n.constructor(n.type,n);nn=r,n.target.dispatchEvent(r),nn=null}else return t=vt(n),t!==null&&vp(t),e.blockedOn=n,!1;t.shift()}return!0}function Vp(e,t,n){Bp(e)&&n.delete(t)}function Hp(){Op=!1,kp!==null&&Bp(kp)&&(kp=null),Ap!==null&&Bp(Ap)&&(Ap=null),jp!==null&&Bp(jp)&&(jp=null),Mp.forEach(Vp),Np.forEach(Vp)}function Up(e,n){e.blockedOn===n&&(e.blockedOn=null,Op||(Op=!0,t.unstable_scheduleCallback(t.unstable_NormalPriority,Hp)))}var Wp=null;function Gp(e){Wp!==e&&(Wp=e,t.unstable_scheduleCallback(t.unstable_NormalPriority,function(){Wp===e&&(Wp=null);for(var t=0;t<e.length;t+=3){var n=e[t],r=e[t+1],i=e[t+2];if(typeof r!=`function`){if(Ep(r||n)===null)continue;break}var a=vt(n);a!==null&&(e.splice(t,3),t-=3,Ds(a,{pending:!0,data:i,method:n.method,action:r},r,i))}}))}function Kp(e){function t(t){return Up(t,e)}kp!==null&&Up(kp,e),Ap!==null&&Up(Ap,e),jp!==null&&Up(jp,e),Mp.forEach(t),Np.forEac
9h(t);for(var n=0;n<Pp.length;n++){var r=Pp[n];r.blockedOn===e&&(r.blockedOn=null)}for(;0<Pp.length&&(n=Pp[0],n.blockedOn===null);)zp(n),n.blockedOn===null&&Pp.shift();if(n=(e.ownerDocument||e).$$reactFormReplay,n!=null)for(r=0;r<n.length;r+=3){var i=n[r],a=n[r+1],o=i[lt]||null;if(typeof a==`function`)o||Gp(n);else if(o){var s=null;if(a&&a.hasAttribute(`formAction`)){if(i=a,o=a[lt]||null)s=o.formAction;else if(Ep(i)!==null)continue}else s=o.action;typeof s==`function`?n[r+1]=s:(n.splice(r,3),r-=3),Gp(n)}}}function qp(){function e(e){e.canIntercept&&e.info===`react-transition`&&e.intercept({handler:function(){return new Promise(function(e){return i=e})},focusReset:`manual`,scroll:`manual`})}function t(){i!==null&&(i(),i=null),r||setTimeout(n,20)}function n(){if(!r&&!navigation.transition){var e=navigation.currentEntry;e&&e.url!=null&&navigation.navigate(e.url,{state:e.getState(),info:`react-transition`,history:`replace`})}}if(typeof navigation==`object`){var r=!1,i=null;return navigation.addEventListener(`navigate`,e),navigation.addEventListener(`navigatesuccess`,t),navigation.addEventListener(`navigateerror`,t),setTimeout(n,100),function(){r=!0,navigation.removeEventListener(`navigate`,e),navigation.removeEventListener(`navigatesuccess`,t),navigation.removeEventListener(`navigateerror`,t),i!==null&&(i(),i=null)}}}function Jp(e){this._internalRoot=e}Yp.prototype.render=Jp.prototype.render=function(e){var t=this._internalRoot;if(t===null)throw Error(i(409));var n=t.current;hp(n,Cu(),e,t,null,null)},Yp.prototype.unmount=Jp.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var t=e.containerInfo;hp(e.current,2,null,e,null,null),Au(),t[ut]=null}};function Yp(e){this._internalRoot=e}Yp.prototype.unstable_scheduleHydration=function(e){if(e){var t=at();e={blockedOn:null,target:e,priority:t};for(var n=0;n<Pp.length&&t!==0&&t<Pp[n].priority;n++);Pp.splice(n,0,e),n===0&&zp(e)}};var Xp=n.version;if(Xp!==`19.2.4`)throw Error(i(527,Xp,`19.2.4`));I.findDOMNode=function(e){var t=e._reactInternals;if(t===void 0)throw typeof e.render==`function`?Error(i(188)):(e=Object.keys(e).join(`,`),Error(i(268,e)));return e=d(t),e=e===null?null:p(e),e=e===null?null:e.stateNode,e};var Zp={bundleType:0,version:`19.2.4`,rendererPackageName:`react-dom`,currentDispatcherRef:F,reconcilerVersion:`19.2.4`};if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<`u`){var Qp=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!Qp.isDisabled&&Qp.supportsFiber)try{Ie=Qp.inject(Zp),Le=Qp}catch{}}e.createRoot=function(e,t){if(!a(e))throw Error(i(299));var n=!1,r=``,o=Xs,s=Zs,c=Qs;return t!=null&&(!0===t.unstable_strictMode&&(n=!0),t.identifierPrefix!==void 0&&(r=t.identifierPrefix),t.onUncaughtError!==void 0&&(o=t.onUncaughtError),t.onCaughtError!==void 0&&(s=t.onCaughtError),t.onRecoverableError!==void 0&&(c=t.onRecoverableError)),t=pp(e,1,!1,null,null,n,r,null,o,s,c,qp),e[ut]=t.current,Pd(e),new Jp(t)}})),g=o(((e,t)=>{function n(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>`u`||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!=`function`))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=h()}))(),_=c(u(),1),v=c(m(),1),y=`modulepreload`,b=function(e){return`/`+e},x={},S=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}r=o(t.map(t=>{if(t=b(t,n),t in x)return;x[t]=!0;let r=t.endsWith(`.css`),i=r?`[rel="stylesheet"]`:``;if(n)for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}else if(document.querySelector(`link[href="${t}"]${i}`))return;let o=document.createElement(`link`);if(o.rel=r?`stylesheet`:y,r||(o.as=`script`),o.crossOrigin=``,o.href=t,a&&o.setAttribute(`nonce`,a),document.head.appendChild(o),r)return new Promise((e,n)=>{o.addEventListener(`load`,e),o.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},C=`popstate`;function w(e){return typeof e==`object`&&!!e&&`pathname`in e&&`search`in e&&`hash`in e&&`state`in e&&`key`in e}function T(e={}){function t(e,t){let n=t.state?.masked,{pathname:r,search:i,hash:a}=n||e.location;return A(``,{pathname:r,search:i,hash:a},t.state&&t.state.usr||null,t.state&&t.state.key||`default`,n?{pathname:e.location.pathname,search:e.location.search,hash:e.location.hash}:void 0)}function n(e,t){return typeof t==`string`?t:j(t)}return ee(t,n,null,e)}function E(e,t){if(e===!1||e==null)throw Error(t)}function D(e,t){if(!e){typeof console<`u`&&console.warn(t);try{throw Error(t)}catch{}}}function O(){return Math.random().toString(36).substring(2,10)}function k(e,t){return{usr:e.state,key:e.key,idx:t,masked:e.unstable_mask?{pathname:e.pathname,search:e.search,hash:e.hash}:void 0}}function A(e,t,n=null,r,i){return{pathname:typeof e==`string`?e:e.pathname,search:``,hash:``,...typeof t==`string`?M(t):t,state:n,key:t&&t.key||r||O(),unstable_mask:i}}function j({pathname:e=`/`,search:t=``,hash:n=``}){return t&&t!==`?`&&(e+=t.charAt(0)===`?`?t:`?`+t),n&&n!==`#`&&(e+=n.charAt(0)===`#`?n:`#`+n),e}function M(e){let t={};if(e){let n=e.indexOf(`#`);n>=0&&(t.hash=e.substring(n),e=e.substring(0,n));let r=e.indexOf(`?`);r>=0&&(t.search=e.substring(r),e=e.substring(0,r)),e&&(t.pathname=e)}return t}function ee(e,t,n,r={}){let{window:i=document.defaultView,v5Compat:a=!1}=r,o=i.history,s=`POP`,c=null,l=u();l??(l=0,o.replaceState({...o.state,idx:l},``));function u(){return(o.state||{idx:null}).idx}function d(){s=`POP`;let e=u(),t=e==null?null:e-l;l=e,c&&c({action:s,location:h.location,delta:t})}function f(e,t){s=`PUSH`;let r=w(e)?e:A(h.location,e,t);n&&n(r,e),l=u()+1;let d=k(r,l),f=h.createHref(r.unstable_mask||r);try{o.pushState(d,``,f)}catch(e){if(e instanceof DOMException&&e.name===`DataCloneError`)throw e;i.location.assign(f)}a&&c&&c({action:s,location:h.location,delta:1})}function p(e,t){s=`REPLACE`;let r=w(e)?e:A(h.location,e,t);n&&n(r,e),l=u();let i=k(r,l),d=h.createHref(r.unstable_mask||r);o.replaceState(i,``,d),a&&c&&c({action:s,location:h.location,delta:0})}function m(e){return N(e)}let h={get action(){return s},get location(){return e(i,o)},listen(e){if(c)throw Error(`A history only accepts one active listener`);return i.addEventListener(C,d),c=e,()=>{i.removeEventListener(C,d),c=null}},createHref(e){return t(i,e)},createURL:m,encodeLocation(e){let t=m(e);return{pathname:t.pathname,search:t.search,hash:t.hash}},push:f,replace:p,go(e){return o.go(e)}};return h}function N(e,t=!1){let n=`http://localhost`;typeof window<`u`&&(n=window.location.origin===`null`?window.location.href:window.location.origin),E(n,`No window.location.(origin|href) available to create URL`);let r=typeof e==`string`?e:j(e);return r=r.replace(/ $/,`%20`),!t&&r.startsWith(`//`)&&(r=n+r),new URL(r,n)}function P(e,t,n=`/`){return F(e,t,n,!1)}function F(e,t,n,r){let i=_e((typeof t==`string`?M(t):t).pathname||`/`,n);if(i==null)return null;let a=te(e);re(a);let o=null;for(let e=0;o==null&&e<a.length;++e){let t=ge(i);o=pe(a[e],t,r)}return o}function I(e,t){let{route:n,pathname:r,params:i}=e;return{id:n.id,pathname:r,params:i,data:t[n.id],loaderData:t[n.id],handle:n.handle}}function te(e,t=[],n=[],r=``,i=!1){let a=(e,a,o=i,s)=>{let c={relativePath:s===void 0?e.path||``:s,caseSensitive:e.caseSensitive===!0,childrenIndex:a,route:e};if(c.relativePath.startsWith(`/`)){if(!c.relativePath.startsWith(r)&&o)return;E(c.relativePath.startsWith(r),`Absolute route path "${c.relativePath}" nested under path "${r}
9" is not valid. An absolute child route path must start with the combined path of all its parent routes.`),c.relativePath=c.relativePath.slice(r.length)}let l=Te([r,c.relativePath]),u=n.concat(c);e.children&&e.children.length>0&&(E(e.index!==!0,`Index routes must not have child routes. Please remove all child routes from route path "${l}".`),te(e.children,t,u,l,o)),!(e.path==null&&!e.index)&&t.push({path:l,score:de(l,e.index),routesMeta:u})};return e.forEach((e,t)=>{if(e.path===``||!e.path?.includes(`?`))a(e,t);else for(let n of ne(e.path))a(e,t,!0,n)}),t}function ne(e){let t=e.split(`/`);if(t.length===0)return[];let[n,...r]=t,i=n.endsWith(`?`),a=n.replace(/\?$/,``);if(r.length===0)return i?[a,``]:[a];let o=ne(r.join(`/`)),s=[];return s.push(...o.map(e=>e===``?a:[a,e].join(`/`))),i&&s.push(...o),s.map(t=>e.startsWith(`/`)&&t===``?`/`:t)}function re(e){e.sort((e,t)=>e.score===t.score?fe(e.routesMeta.map(e=>e.childrenIndex),t.routesMeta.map(e=>e.childrenIndex)):t.score-e.score)}var ie=/^:[\w-]+$/,ae=3,oe=2,se=1,ce=10,le=-2,ue=e=>e===`*`;function de(e,t){let n=e.split(`/`),r=n.length;return n.some(ue)&&(r+=le),t&&(r+=oe),n.filter(e=>!ue(e)).reduce((e,t)=>e+(ie.test(t)?ae:t===``?se:ce),r)}function fe(e,t){return e.length===t.length&&e.slice(0,-1).every((e,n)=>e===t[n])?e[e.length-1]-t[t.length-1]:0}function pe(e,t,n=!1){let{routesMeta:r}=e,i={},a=`/`,o=[];for(let e=0;e<r.length;++e){let s=r[e],c=e===r.length-1,l=a===`/`?t:t.slice(a.length)||`/`,u=me({path:s.relativePath,caseSensitive:s.caseSensitive,end:c},l),d=s.route;if(!u&&c&&n&&!r[r.length-1].route.index&&(u=me({path:s.relativePath,caseSensitive:s.caseSensitive,end:!1},l)),!u)return null;
9Object.assign(i,u.params),o.push({params:i,pathname:Te([a,u.pathname]),pathnameBase:Ee(Te([a,u.pathnameBase])),route:d}),u.pathnameBase!==`/`&&(a=Te([a,u.pathnameBase]))}return o}function me(e,t){typeof e==`string`&&(e={path:e,caseSensitive:!1,end:!0});let[n,r]=he(e.path,e.caseSensitive,e.end),i=t.match(n);if(!i)return null;let a=i[0],o=a.replace(/(.)\/+$/,`$1`),s=i.slice(1);return{params:r.reduce((e,{paramName:t,isOptional:n},r)=>{if(t===`*`){let e=s[r]||``;o=a.slice(0,a.length-e.length).replace(/(.)\/+$/,`$1`)}let i=s[r];return n&&!i?e[t]=void 0:e[t]=(i||``).replace(/%2F/g,`/`),e},{}),pathname:a,pathnameBase:o,pattern:e}}function he(e,t=!1,n=!0){D(e===`*`||!e.endsWith(`*`)||e.endsWith(`/*`),`Route path "${e}" will be treated as if it were "${e.replace(/\*$/,`/*`)}" because the \`*\` character must always follow a \`/\` in the pattern. To get rid of this warning, please change the route path to "${e.replace(/\*$/,`/*`)}".`);let r=[],i=`^`+e.replace(/\/*\*?$/,``).replace(/^\/*/,`/`).replace(/[\\.*+^${}|()[\]]/g,`\\$&`).replace(/\/:([\w-]+)(\?)?/g,(e,t,n,i,a)=>{if(r.push({paramName:t,isOptional:n!=null}),n){let t=a.charAt(i+e.length);return t&&t!==`/`?`/([^\\/]*)`:`(?:/([^\\/]*))?`}return`/([^\\/]+)`}).replace(/\/([\w-]+)\?(\/|$)/g,`(/$1)?$2`);return e.endsWith(`*`)?(r.push({paramName:`*`}),i+=e===`*`||e===`/*`?`(.*)$`:`(?:\\/(.+)|\\/*)$`):n?i+=`\\/*$`:e!==``&&e!==`/`&&(i+=`(?:(?=\\/|$))`),[new RegExp(i,t?void 0:`i`),r]}function ge(e){try{return e.split(`/`).map(e=>decodeURIComponent(e).replace(/\//g,`%2F`)).join(`/`)}catch(t){return D(!1,`The URL path "${e}" could not be decoded because it is a malformed URL segment. This is probably due to a bad percent encoding (${t}).`),e}}function _e(e,t){if(t===`/`)return e;if(!e.toLowerCase().startsWith(t.toLowerCase()))return null;let n=t.endsWith(`/`)?t.length-1:t.length,r=e.charAt(n);return r&&r!==`/`?null:e.slice(n)||`/`}var ve=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;function ye(e,t=`/`){let{pathname:n,search:r=``,hash:i=``}=typeof e==`string`?M(e):e,a;return n?(n=n.replace(/\/\/+/g,`/`),a=n.startsWith(`/`)?be(n.substring(1),`/`):be(n,t)):a=t,{pathname:a,search:De(r),hash:Oe(i)}}function be(e,t){let n=t.replace(/\/+$/,``).split(`/`);return e.split(`/`).forEach(e=>{e===`..`?n.length>1&&n.pop():e!==`.`&&n.push(e)}),n.length>1?n.join(`/`):`/`}function xe(e,t,n,r){return`Cannot include a '${e}' character in a manually specified \`to.${t}\` field [${JSON.stringify(r)}]. Please separate it out to the \`to.${n}\` field. Alternatively you may provide the full path as a string in <Link to="..."> and the router will parse it for you.`}function Se(e){return e.filter((e,t)=>t===0||e.route.path&&e.route.path.length>0)}function Ce(e){let t=Se(e);return t.map((e,n)=>n===t.length-1?e.pathname:e.pathnameBase)}function we(e,t,n,r=!1){let i;typeof e==`string`?i=M(e):(i={...e},E(!i.pathname||!i.pathname.includes(`?`),xe(`?`,`pathname`,`search`,i)),E(!i.pathname||!i.pathname.includes(`#`),xe(`#`,`pathname`,`hash`,i)),E(!i.search||!i.search.includes(`#`),xe(`#`,`search`,`hash`,i)));let a=e===``||i.pathname===``,o=a?`/`:i.pathname,s;if(o==null)s=n;else{let e=t.length-1;if(!r&&o.startsWith(`..`)){let t=o.split(`/`);for(;t[0]===`..`;)t.shift(),--e;i.pathname=t.join(`/`)}s=e>=0?t[e]:`/`}let c=ye(i,s),l=o&&o!==`/`&&o.endsWith(`/`),u=(a||o===`.`)&&n.endsWith(`/`);return!c.pathname.endsWith(`/`)&&(l||u)&&(c.pathname+=`/`),c}var Te=e=>e.join(`/`).replace(/\/\/+/g,`/`),Ee=e=>e.replace(/\/+$/,``).replace(/^\/*/,`/`),De=e=>!e||e===`?`?``:e.startsWith(`?`)?e:`?`+e,Oe=e=>!e||e===`#`?``:e.startsWith(`#`)?e:`#`+e,ke=class{constructor(e,t,n,r=!1){this.status=e,this.statusText=t||``,this.internal=r,n instanceof Error?(this.data=n.toString(),this.error=n):this.data=n}};function Ae(e){return e!=null&&typeof e.status==`number`&&typeof e.statusText==`string`&&typeof e.internal==`boolean`&&`data`in e}function je(e){return e.map(e=>e.route.path).filter(Boolean).join(`/`).replace(/\/\/*/g,`/`)||`/`}var Me=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;function Ne(e,t){let n=e;if(typeof n!=`string`||!ve.test(n))return{absoluteURL:void 0,isExternal:!1,to:n};let r=n,i=!1;if(Me)try{let e=new URL(window.location.href),r=n.startsWith(`//`)?new URL(e.protocol+n):new URL(n),a=_e(r.pathname,t);r.origin===e.origin&&a!=null?n=a+r.search+r.hash:i=!0}catch{D(!1,`<Link to="${n}">
9 contains an invalid URL which will probably break when clicked - please update to a valid URL path.`)}return{absoluteURL:r,isExternal:i,to:n}}Object.getOwnPropertyNames(Object.prototype).sort().join(`\0`);var Pe=_.createContext(null);Pe.displayName=`DataRouter`;var Fe=_.createContext(null);Fe.displayName=`DataRouterState`;var Ie=_.createContext(!1),Le=_.createContext({isTransitioning:!1});Le.displayName=`ViewTransition`;var Re=_.createContext(new Map);Re.displayName=`Fetchers`;var ze=_.createContext(null);ze.displayName=`Await`;var Be=_.createContext(null);Be.displayName=`Navigation`;var Ve=_.createContext(null);Ve.displayName=`Location`;var He=_.createContext({outlet:null,matches:[],isDataRoute:!1});He.displayName=`Route`;var Ue=_.createContext(null);Ue.displayName=`RouteError`;var We=`REACT_ROUTER_ERROR`,Ge=`REDIRECT`,Ke=`ROUTE_ERROR_RESPONSE`;function qe(e){if(e.startsWith(`${We}:${Ge}:{`))try{let t=JSON.parse(e.slice(28));if(typeof t==`object`&&t&&typeof t.status==`number`&&typeof t.statusText==`string`&&typeof t.location==`string`&&typeof t.reloadDocument==`boolean`&&typeof t.replace==`boolean`)return t}catch{}}function Je(e){if(e.startsWith(`${We}:${Ke}:{`))try{let t=JSON.parse(e.slice(40));if(typeof t==`object`&&t&&typeof t.status==`number`&&typeof t.statusText==`string`)return new ke(t.status,t.statusText,t.data)}catch{}}function Ye(e,{relative:t}={}){E(Xe(),`useHref() may be used only in the context of a <Router> component.`);let{basename:n,navigator:r}=_.useContext(Be),{hash:i,pathname:a,search:o}=it(e,{relative:t}),s=a;return n!==`/`&&(s=a===`/`?n:Te([n,a])),r.createHref({pathname:s,search:o,hash:i})}function Xe(){return _.useContext(Ve)!=null}function Ze(){return E(Xe(),`useLocation() may be used only in the context of a <Router> component.`),_.useContext(Ve).location}var Qe=`You should call navigate() in a React.useEffect(), not when your component is first rendered.`;function $e(e){_.useContext(Be).static||_.useLayoutEffect(e)}function et(){let{isDataRoute:e}=_.useContext(He);return e?Ct():tt()}function tt(){E(Xe(),`useNavigate() may be used only in the context of a <Router> component.`);let e=_.useContext(Pe),{basename:t,navigator:n}=_.useContext(Be),{matches:r}=_.useContext(He),{pathname:i}=Ze(),a=JSON.stringify(Ce(r)),o=_.useRef(!1);return $e(()=>{o.current=!0}),_.useCallback((r,s={})=>{if(D(o.current,Qe),!o.current)return;if(typeof r==`number`){n.go(r);return}let c=we(r,JSON.parse(a),i,s.relative===`path`);e==null&&t!==`/`&&(c.pathname=c.pathname===`/`?t:Te([t,c.pathname])),(s.replace?n.replace:n.push)(c,s.state,s)},[t,n,a,i,e])}var nt=_.createContext(null);function rt(e){let t=_.useContext(He).outlet;return _.useMemo(()=>t&&_.createElement(nt.Provider,{value:e},t),[t,e])}function it(e,{relative:t}={}){let{matches:n}=_.useContext(He),{pathname:r}=Ze(),i=JSON.stringify(Ce(n));return _.useMemo(()=>we(e,JSON.parse(i),r,t===`path`),[e,i,r,t])}function at(e,t){return ot(e,t)}function ot(e,t,n){E(Xe(),`useRoutes() may be used only in the context of a <Router> component.`);let{navigator:r}=_.useContext(Be),{matches:i}=_.useContext(He),a=i[i.length-1],o=a?a.params:{},s=a?a.pathname:`/`,c=a?a.pathnameBase:`/`,l=a&&a.route;{let e=l&&l.path||``;Tt(s,!l||e.endsWith(`*`)||e.endsWith(`*?`),`You rendered descendant <Routes> (or called \`useRoutes()\`) at "${s}" (under <Route path="${e}">) 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. 10 11Please change the parent <Route path="${e}"> to <Route path="${e===`/`?`*`:`${e}/*`}">.`)}let u=Ze(),d;if(t){let e=typeof t==`string`?M(t):t;E(c===`/`||e.pathname?.startsWith(c),`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 "${c}" but pathname "${e.pathname}" was given in the \`location\` prop.`),d=e}else d=u;let f=d.pathname||`/`,p=f;if(c!==`/`){let e=c.replace(/^\//,``).split(`/`);p=`/`+f.replace(/^\//,``).split(`/`).slice(e.length).join(`/`)}let m=P(e,{pathname:p});D(l||m!=null,`No routes matched location "${d.pathname}${d.search}${d.hash}" `),D(m==null||m[m.length-1].route.element!==void 0||m[m.length-1].route.Component!==void 0||m[m.length-1].route.lazy!==void 0,`Matched leaf route at location "${d.pathname}${d.search}${d.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 h=pt(m&&m.map(e=>Object.assign({},e,{params:Object.assign({},o,e.params),pathname:Te([c,r.encodeLocation?r.encodeLocation(e.pathname.replace(/\?/g,`%3F`).replace(/#/g,`%23`)).pathname:e.pathname]),pathnameBase:e.pathnameBase===`/`?c:Te([c,r.encodeLocation?r.encodeLocation(e.pathnameBase.replace(/\?/g,`%3F`).replace(/#/g,`%23`)).pathname:e.pathnameBase])})),i,n);return t&&h?_.createElement(Ve.Provider,{value:{location:{pathname:`/`,search:``,hash:``,state:null,key:`default`,unstable_mask:void 0,...d},navigationType:`POP`}},h):h}function st(){let e=St(),t=Ae(e)?`${e.status} ${e.statusText}`:e instanceof Error?e.message:JSON.stringify(e),n=e instanceof Error?e.stack:null,r=`rgba(200,200,200, 0.5)`,i={padding:`0.5rem`,backgroundColor:r},a={padding:`2px 4px`,backgroundColor:r},o=null;return console.error(`Error handled by React Router default ErrorBoundary:`,e),o=_.createElement(_.Fragment,null,_.createElement(`p`,null,`ð¿ Hey developer ð`),_.createElement(`p`,null,`You can provide a way better UX than this when your app throws errors by providing your own `,_.createElement(`code`,{style:a},`ErrorBoundary`),` or`,` `,_.createElement(`code`,{style:a},`errorElement`),` prop on your route.`)),_.createElement(_.Fragment,null,_.createElement(`h2`,null,`Unexpected Application
11Error!`),_.createElement(`h3`,{style:{fontStyle:`italic`}},t),n?_.createElement(`pre`,{style:i},n):null,o)}var ct=_.createElement(st,null),lt=class extends _.Component{constructor(e){super(e),this.state={location:e.location,revalidation:e.revalidation,error:e.error}}static getDerivedStateFromError(e){return{error:e}}static getDerivedStateFromProps(e,t){return t.location!==e.location||t.revalidation!==`idle`&&e.revalidation===`idle`?{error:e.error,location:e.location,revalidation:e.revalidation}:{error:e.error===void 0?t.error:e.error,location:t.location,revalidation:e.revalidation||t.revalidation}}componentDidCatch(e,t){this.props.onError?this.props.onError(e,t):console.error(`React Router caught the following error during render`,e)}render(){let e=this.state.error;if(this.context&&typeof e==`object`&&e&&`digest`in e&&typeof e.digest==`string`){let t=Je(e.digest);t&&(e=t)}let t=e===void 0?this.props.children:_.createElement(He.Provider,{value:this.props.routeContext},_.createElement(Ue.Provider,{value:e,children:this.props.component}));return this.context?_.createElement(dt,{error:e},t):t}};lt.contextType=Ie;var ut=new WeakMap;function dt({children:e,error:t}){let{basename:n}=_.useContext(Be);if(typeof t==`object`&&t&&`digest`in t&&typeof t.digest==`string`){let e=qe(t.digest);if(e){let r=ut.get(t);if(r)throw r;let i=Ne(e.location,n);if(Me&&!ut.get(t))if(i.isExternal||e.reloadDocument)window.location.href=i.absoluteURL||i.to;else{let n=Promise.resolve().then(()=>window.__reactRouterDataRouter.navigate(i.to,{replace:e.replace}));throw ut.set(t,n),n}return _.createElement(`meta`,{httpEquiv:`refresh`,content:`0;url=${i.absoluteURL||i.to}`})}}return e}function ft({routeContext:e,match:t,children:n}){let r=_.useContext(Pe);return r&&r.static&&r.staticContext&&(t.route.errorElement||t.route.ErrorBoundary)&&(r.staticContext._deepestRenderedBoundaryId=t.route.id),_.createElement(He.Provider,{value:e},n)}function pt(e,t=[],n){let r=n?.state;if(e==null){if(!r)return null;if(r.errors)e=r.matches;else if(t.length===0&&!r.initialized&&r.matches.length>0)e=r.matches;else return null}let i=e,a=r?.errors;if(a!=null){let e=i.findIndex(e=>e.route.id&&a?.[e.route.id]!==void 0);E(e>=0,`Could not find a matching route for errors on route IDs: ${Object.keys(a).join(`,`)}`),i=i.slice(0,Math.min(i.length,e+1))}let o=!1,s=-1;if(n&&r){o=r.renderFallback;for(let e=0;e<i.length;e++){let t=i[e];if((t.route.HydrateFallback||t.route.hydrateFallbackElement)&&(s=e),t.route.id){let{loaderData:e,errors:a}=r,c=t.route.loader&&!e.hasOwnProperty(t.route.id)&&(!a||a[t.route.id]===void 0);if(t.route.lazy||c){n.isStatic&&(o=!0),i=s>=0?i.slice(0,s+1):[i[0]];break}}}}let c=n?.onError,l=r&&c?(e,t)=>{c(e,{location:r.location,params:r.matches?.[0]?.params??{},unstable_pattern:je(r.matches),errorInfo:t})}:void 0;return i.reduceRight((e,n,c)=>{let u,d=!1,f=null,p=null;r&&(u=a&&n.route.id?a[n.route.id]:void 0,f=n.route.errorElement||ct,o&&(s<0&&c===0?(Tt(`route-fallback`,!1,"No `HydrateFallback` element provided to render during initial hydration"),d=!0,p=null):s===c&&(d=!0,p=n.route.hydrateFallbackElement||null)));let m=t.concat(i.slice(0,c+1)),h=()=>{let t;return t=u?f:d?p:n.route.Component?_.createElement(n.route.Component,null):n.route.element?n.route.element:e,_.createElement(ft,{match:n,routeContext:{outlet:e,matches:m,isDataRoute:r!=null},children:t})};return r&&(n.route.ErrorBoundary||n.route.errorElement||c===0)?_.createElement(lt,{location:r.location,revalidation:r.revalidation,component:f,error:u,children:h(),routeContext:{outlet:null,matches:m,isDataRoute:!0},onError:l}):h()},null)}function mt(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function ht(e){let t=_.useContext(Pe);return E(t,mt(e)),t}function gt(e){let t=_.useContext(Fe);return E(t,mt(e)),t}function _t(e){let t=_.useContext(He);return E(t,mt(e)),t}function vt(e){let t=_t(e),n=t.matches[t.matches.length-1];return E(n.route.id,`${e} can only be used on routes that contain a unique "id"`),n.route.id}function yt(){return vt(`useRouteId`)}function bt(){return gt(`useNavigation`).navigation}
11function xt(){let{matches:e,loaderData:t}=gt(`useMatches`);return _.useMemo(()=>e.map(e=>I(e,t)),[e,t])}function St(){let e=_.useContext(Ue),t=gt(`useRouteError`),n=vt(`useRouteError`);return e===void 0?t.errors?.[n]:e}function Ct(){let{router:e}=ht(`useNavigate`),t=vt(`useNavigate`),n=_.useRef(!1);return $e(()=>{n.current=!0}),_.useCallback(async(r,i={})=>{D(n.current,Qe),n.current&&(typeof r==`number`?await e.navigate(r):await e.navigate(r,{fromRouteId:t,...i}))},[e,t])}var wt={};function Tt(e,t,n){!t&&!wt[e]&&(wt[e]=!0,D(!1,n))}_.useOptimistic,_.memo(Et);function Et({routes:e,future:t,state:n,isStatic:r,onError:i}){return ot(e,void 0,{state:n,isStatic:r,onError:i,future:t})}function Dt({to:e,replace:t,state:n,relative:r}){E(Xe(),`<Navigate> may be used only in the context of a <Router> component.`);let{static:i}=_.useContext(Be);D(!i,`<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:a}=_.useContext(He),{pathname:o}=Ze(),s=et(),c=we(e,Ce(a),o,r===`path`),l=JSON.stringify(c);return _.useEffect(()=>{s(JSON.parse(l),{replace:t,state:n,relative:r})},[s,l,r,t,n]),null}function Ot(e){return rt(e.context)}function kt(e){E(!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 At({basename:e=`/`,children:t=null,location:n,navigationType:r=`POP`,navigator:i,static:a=!1,unstable_useTransitions:o}){E(!Xe(),`You cannot render a <Router> inside another <Router>. You should never have more than one in your app.`);let s=e.replace(/^\/*/,`/`),c=_.useMemo(()=>({basename:s,navigator:i,static:a,unstable_useTransitions:o,future:{}}),[s,i,a,o]);typeof n==`string`&&(n=M(n));let{pathname:l=`/`,search:u=``,hash:d=``,state:f=null,key:p=`default`,unstable_mask:m}=n,h=_.useMemo(()=>{let e=_e(l,s);return e==null?null:{location:{pathname:e,search:u,hash:d,state:f,key:p,unstable_mask:m},navigationType:r}},[s,l,u,d,f,p,r,m]);return D(h!=null,`<Router basename="${s}"> is not able to match the URL "${l}${u}${d}" because it does not start with the basename, so the <Router> won't render anything.`),h==null?null:_.createElement(Be.Provider,{value:c},_.createElement(Ve.Provider,{children:t,value:h}))}function jt({children:e,location:t}){return at(Mt(e),t)}function Mt(e,t=[]){let n=[];return _.Children.forEach(e,(e,r)=>{if(!_.isValidElement(e))return;let i=[...t,r];if(e.type===_.Fragment){n.push.apply(n,Mt(e.props.children,i));return}E(e.type===kt,`[${typeof e.type==`string`?e.type:e.type.name}] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>`),E(!e.props.index||!e.props.children,`An index route cannot have child routes.`);let a={id:e.props.id||i.join(`-`),caseSensitive:e.props.caseSensitive,element:e.props.element,Component:e.props.Component,index:e.props.index,path:e.props.path,middleware:e.props.middleware,loader:e.props.loader,action:e.props.action,hydrateFallbackElement:e.props.hydrateFallbackElement,HydrateFallback:e.props.HydrateFallback,errorElement:e.props.errorElement,ErrorBoundary:e.props.ErrorBoundary,hasErrorBoundary:e.props.hasErrorBoundary===!0||e.props.ErrorBoundary!=null||e.props.errorElement!=null,shouldRevalidate:e.props.shouldRevalidate,handle:e.props.handle,lazy:e.props.lazy};e.props.children&&(a.children=Mt(e.props.children,i)),n.push(a)}),n}var Nt=`get`,Pt=`application/x-www-form-urlencoded`;function Ft(e){return typeof HTMLElement<`u`&&e instanceof HTMLElement}function It(e){return Ft(e)&&e.tagName.toLowerCase()===`button`}function Lt(e){return Ft(e)&&e.tagName.toLowerCase()===`form`}function Rt(e){return Ft(e)&&e.tagName.toLowerCase()===`input`}function zt(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function Bt(e,t){return e.button===0&&(!t||t===`_self`)&&!zt(e)}function Vt(e=``){return new URLSearchParams(typeof e==`string`||Array.isArray(e)||e instanceof URLSearchParams?e:Object.keys(e).reduce((t,n)=>{let r=e[n];return t.concat(Array.isArray(r)?r.map(e=>[n,e]):[[n,r]])},[]))}function Ht(e,t){let n=Vt(e);return t&&t.forEach((e,r)=>
11{n.has(r)||t.getAll(r).forEach(e=>{n.append(r,e)})}),n}var Ut=null;function Wt(){if(Ut===null)try{new FormData(document.createElement(`form`),0),Ut=!1}catch{Ut=!0}return Ut}var Gt=new Set([`application/x-www-form-urlencoded`,`multipart/form-data`,`text/plain`]);function Kt(e){return e!=null&&!Gt.has(e)?(D(!1,`"${e}" is not a valid \`encType\` for \`<Form>\`/\`<fetcher.Form>\` and will default to "${Pt}"`),null):e}function qt(e,t){let n,r,i,a,o;if(Lt(e)){let o=e.getAttribute(`action`);r=o?_e(o,t):null,n=e.getAttribute(`method`)||Nt,i=Kt(e.getAttribute(`enctype`))||Pt,a=new FormData(e)}else if(It(e)||Rt(e)&&(e.type===`submit`||e.type===`image`)){let o=e.form;if(o==null)throw Error(`Cannot submit a <button> or <input type="submit"> without a <form>`);let s=e.getAttribute(`formaction`)||o.getAttribute(`action`);if(r=s?_e(s,t):null,n=e.getAttribute(`formmethod`)||o.getAttribute(`method`)||Nt,i=Kt(e.getAttribute(`formenctype`))||Kt(o.getAttribute(`enctype`))||Pt,a=new FormData(o,e),!Wt()){let{name:t,type:n,value:r}=e;if(n===`image`){let e=t?`${t}.`:``;a.append(`${e}x`,`0`),a.append(`${e}y`,`0`)}else t&&a.append(t,r)}}else if(Ft(e))throw Error(`Cannot submit element that is not <form>, <button>, or <input type="submit|image">`);else n=Nt,r=null,i=Pt,o=e;return a&&i===`text/plain`&&(o=a,a=void 0),{action:r,method:n.toLowerCase(),encType:i,formData:a,body:o}}Object.getOwnPropertyNames(Object.prototype).sort().join(`\0`);var Jt={"&":`\\u0026`,">":`\\u003e`,"<":`\\u003c`,"\u2028":`\\u2028`,"\u2029":`\\u2029`},Yt=/[&><\u2028\u2029]/g;function Xt(e){return e.replace(Yt,e=>Jt[e])}function Zt(e,t){if(e===!1||e==null)throw Error(t)}function Qt(e,t,n,r){let i=typeof e==`string`?new URL(e,typeof window>`u`?`server://singlefetch/`:window.location.origin):e;return n?i.pathname.endsWith(`/`)?i.pathname=`${i.pathname}_.${r}`:i.pathname=`${i.pathname}.${r}`:i.pathname===`/`?i.pathname=`_root.${r}`:t&&_e(i.pathname,t)===`/`?i.pathname=`${t.replace(/\/$/,``)}/_root.${r}`:i.pathname=`${i.pathname.replace(/\/$/,``)}.${r}`,i}async function $t(e,t){if(e.id in t)return t[e.id];try{let n=await S(()=>import(e.module),[]);return t[e.id]=n,n}catch(t){return console.error(`Error loading route module \`${e.module}\`, reloading page...`),console.error(t),window.__reactRouterContext&&window.__reactRouterContext.isSpaMode,window.location.reload(),new Promise(()=>{})}}function en(e){return e!=null&&typeof e.page==`string`}function tn(e){return e==null?!1:e.href==null?e.rel===`preload`&&typeof e.imageSrcSet==`string`&&typeof e.imageSizes==`string`:typeof e.rel==`string`&&typeof e.href==`string`}async function nn(e,t,n){return cn((await Promise.all(e.map(async e=>{let r=t.routes[e.route.id];if(r){let e=await $t(r,n);return e.links?e.links():[]}return[]}))).flat(1).filter(tn).filter(e=>e.rel===`stylesheet`||e.rel===`preload`).map(e=>e.rel===`stylesheet`?{...e,rel:`prefetch`,as:`style`}:{...e,rel:`prefetch`}))}function rn(e,t,n,r,i,a){let o=(e,t)=>n[t]?e.route.id!==n[t].route.id:!0,s=(e,t)=>n[t].pathname!==e.pathname||n[t].route.path?.endsWith(`*`)&&n[t].params[`*`]!==e.params[`*`];return a===`assets`?t.filter((e,t)=>o(e,t)||s(e,t)):a===`data`?t.filter((t,a)=>{let c=r.routes[t.route.id];if(!c||!c.hasLoader)return!1;if(o(t,a)||s(t,a))return!0;if(t.route.shouldRevalidate){let r=t.route.shouldRevalidate({currentUrl:new URL(i.pathname+i.search+i.hash,window.origin),currentParams:n[0]?.params||{},nextUrl:new URL(e,window.origin),nextParams:t.params,defaultShouldRevalidate:!0});if(typeof r==`boolean`)return r}return!0}):[]}function an(e,t,{includeHydrateFallback:n}={}){return on(e.map(e=>{let r=t.routes[e.route.id];if(!r)return[];let i=[r.module];return r.clientActionModule&&(i=i.concat(r.clientActionModule)),r.clientLoaderModule&&(i=i.concat(r.clientLoaderModule)),n&&r.hydrateFallbackModule&&(i=i.concat(r.hydrateFallbackModule)),r.imports&&(i=i.concat(r.imports)),i}).flat(1))}function on(e){return[...new Set(e)]}function sn(e){let t={},n=Object.keys(e).sort();for(let r of n)t[r]=e[r];return t}function cn(e,t){let n=new Set,r=new Set(t);return e.reduce((e,i)=>{if(t&&!en(i)&&i.as===`script`&&i.href&&r.has(i.href))return e;let a=JSON.stringify(sn(i));return n.has(a)||(n.add(a),e.push({key:a,link:i})),e},[])}function ln(){let e=_.useContext(Pe);return Zt(e,`You must render this element inside a <DataRouterContext.Provider> element`),e}function un(){let e=_.useContext(Fe);return Zt(e,`You must render this element inside a <DataRouterStateContext.Provider> element`),e}var dn=_.createContext(void 0);dn.displayName=`FrameworkContext`;function fn(){let e=_.useContext(dn);return Zt(e,`You must render this element inside a <HydratedRouter> element`),e}function pn(e,t){let n=_.useContext(dn),[r,i]=_.useState(!1),[a,o]=_.useState(!1),{onFocus:s,onBlur:c,onMouseEnter:l,onMouseLeave:u,onTouchStart:d}=t,f=_.useRef(null);_.useEffect(()=>{if(e===`render`&&o(!0),e===`viewport`){let e=new IntersectionObserver(e=>
11{e.forEach(e=>{o(e.isIntersecting)})},{threshold:.5});return f.current&&e.observe(f.current),()=>{e.disconnect()}}},[e]),_.useEffect(()=>{if(r){let e=setTimeout(()=>{o(!0)},100);return()=>{clearTimeout(e)}}},[r]);let p=()=>{i(!0)},m=()=>{i(!1),o(!1)};return n?e===`intent`?[a,f,{onFocus:mn(s,p),onBlur:mn(c,m),onMouseEnter:mn(l,p),onMouseLeave:mn(u,m),onTouchStart:mn(d,p)}]:[a,f,{}]:[!1,f,{}]}function mn(e,t){return n=>{e&&e(n),n.defaultPrevented||t(n)}}function hn({page:e,...t}){let{router:n}=ln(),r=_.useMemo(()=>P(n.routes,e,n.basename),[n.routes,e,n.basename]);return r?_.createElement(_n,{page:e,matches:r,...t}):null}function gn(e){let{manifest:t,routeModules:n}=fn(),[r,i]=_.useState([]);return _.useEffect(()=>{let r=!1;return nn(e,t,n).then(e=>{r||i(e)}),()=>{r=!0}},[e,t,n]),r}function _n({page:e,matches:t,...n}){let r=Ze(),{future:i,manifest:a,routeModules:o}=fn(),{basename:s}=ln(),{loaderData:c,matches:l}=un(),u=_.useMemo(()=>rn(e,t,l,a,r,`data`),[e,t,l,a,r]),d=_.useMemo(()=>rn(e,t,l,a,r,`assets`),[e,t,l,a,r]),f=_.useMemo(()=>{if(e===r.pathname+r.search+r.hash)return[];let n=new Set,l=!1;if(t.forEach(e=>{let t=a.routes[e.route.id];!t||!t.hasLoader||(!u.some(t=>t.route.id===e.route.id)&&e.route.id in c&&o[e.route.id]?.shouldRevalidate||t.hasClientLoader?l=!0:n.add(e.route.id))}),n.size===0)return[];let d=Qt(e,s,i.unstable_trailingSlashAwareDataRequests,`data`);return l&&n.size>0&&d.searchParams.set(`_routes`,t.filter(e=>n.has(e.route.id)).map(e=>e.route.id).join(`,`)),[d.pathname+d.search]},[s,i.unstable_trailingSlashAwareDataRequests,c,r,a,u,t,e,o]),p=_.useMemo(()=>an(d,a),[d,a]),m=gn(d);return _.createElement(_.Fragment,null,f.map(e=>_.createElement(`link`,{key:e,rel:`prefetch`,as:`fetch`,href:e,...n})),p.map(e=>_.createElement(`link`,{key:e,rel:`modulepreload`,href:e,...n})),m.map(({key:e,link:t})=>_.createElement(`link`,{key:e,nonce:n.nonce,...t,crossOrigin:t.crossOrigin??n.crossOrigin})))}function vn(...e){return t=>{e.forEach(e=>{typeof e==`function`?e(t):e!=null&&(e.current=t)})}}var yn=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;try{yn&&(window.__reactRouterVersion=`7.13.1`)}catch{}function bn({basename:e,children:t,unstable_useTransitions:n,window:r}){let i=_.useRef();i.current??=T({window:r,v5Compat:!0});let a=i.current,[o,s]=_.useState({action:a.action,location:a.location}),c=_.useCallback(e=>{n===!1?s(e):_.startTransition(()=>s(e))},[n]);return _.useLayoutEffect(()=>a.listen(c),[a,c]),_.createElement(At,{basename:e,children:t,location:o.location,navigationType:o.action,navigator:a,unstable_useTransitions:n})}function xn({basename:e,children:t,history:n,unstable_useTransitions:r}){let[i,a]=_.useState({action:n.action,location:n.location}),o=_.useCallback(e=>{r===!1?a(e):_.startTransition(()=>a(e))},[r]);return _.useLayoutEffect(()=>n.listen(o),[n,o]),_.createElement(At,{basename:e,children:t,location:i.location,navigationType:i.action,navigator:n,unstable_useTransitions:r})}xn.displayName=`unstable_HistoryRouter`;var Sn=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,Cn=_.forwardRef(function({onClick:e,discover:t=`render`,prefetch:n=`none`,relative:r,reloadDocument:i,replace:a,unstable_mask:o,state:s,target:c,to:l,preventScrollReset:u,viewTransition:d,unstable_defaultShouldRevalidate:f,...p},m){let{basename:h,navigator:g,unstable_useTransitions:v}=_.useContext(Be),y=typeof l==`string`&&Sn.test(l),b=Ne(l,h);l=b.to;let x=Ye(l,{relative:r}),S=Ze(),C=null;if(o){let e=we(o,[],S.unstable_mask?S.unstable_mask.pathname:`/`,!0);h!==`/`&&(e.pathname=e.pathname===`/`?h:Te([h,e.pathname])),C=g.createHref(e)}let[w,T,E]=pn(n,p),D=An(l,{replace:a,unstable_mask:o,state:s,target:c,preventScrollReset:u,relative:r,viewTransition:d,unstable_defaultShouldRevalidate:f,unstable_useTransitions:v});function O(t){e&&e(t),t.defaultPrevented||D(t)}let k=!(b.isExternal||i),A=_.createElement(`a`,{...p,...E,href:(k?C:void 0)||b.absoluteURL||x,onClick:k?O:e,ref:vn(m,T),target:c,"data-discover":!y&&t===`render`?`true`:void 0});return w&&!y?_.createElement(_.Fragment,null,A,_.createElement(hn,{page:x})):A});Cn.displayName=`Link`;var wn=_.forwardRef(function({"aria-current":e=`page`,caseSensitive:t=!1,className:n=``,end:r=!1,style:i,to:a,viewTransition:o,children:s,...c},l){let u=it(a,{relative:c.relative}),d=Ze(),f=_.useContext(Fe),{navigator:p,basename:m}=_.useContext(Be),h=f!=null&&Vn(u)&&o===!0,g=p.encodeLocation?p.encodeLocation(u).pathname:u.pathname,v=d.pathname,y=f&&f.navigation&&f.navigation.location?f.navigation.location.pathname:null;t||(v=v.toLowerCase(),y=y?y.toLowerCase():null,g=g.toLowerCase()),y&&m&&(y=_e(y,m)||y);let b=g!==`/`&&g.endsWith(`/`)?g.length-1:g.length,x=v===g||!r&&v.startsWith(g)&&v.charAt(b)===`/`,S=y!=null&&(y===g||!r&&y.startsWith(g)&&y.charAt(g.length)===`/`),C={isActive:x,isPending:S,isTransitioning:h},w=x?e:void 0,T;T=typeof n==`function`?n(C):[n,x?`active`:null,S?`pending`:null,h?`transitioning`:null].filter(
11Boolean).join(` `);let E=typeof i==`function`?i(C):i;return _.createElement(Cn,{...c,"aria-current":w,className:T,ref:l,style:E,to:a,viewTransition:o},typeof s==`function`?s(C):s)});wn.displayName=`NavLink`;var Tn=_.forwardRef(({discover:e=`render`,fetcherKey:t,navigate:n,reloadDocument:r,replace:i,state:a,method:o=Nt,action:s,onSubmit:c,relative:l,preventScrollReset:u,viewTransition:d,unstable_defaultShouldRevalidate:f,...p},m)=>{let{unstable_useTransitions:h}=_.useContext(Be),g=Pn(),v=Fn(s,{relative:l}),y=o.toLowerCase()===`get`?`get`:`post`,b=typeof s==`string`&&Sn.test(s);return _.createElement(`form`,{ref:m,method:y,action:v,onSubmit:r?c:e=>{if(c&&c(e),e.defaultPrevented)return;e.preventDefault();let r=e.nativeEvent.submitter,s=r?.getAttribute(`formmethod`)||o,p=()=>g(r||e.currentTarget,{fetcherKey:t,method:s,navigate:n,replace:i,state:a,relative:l,preventScrollReset:u,viewTransition:d,unstable_defaultShouldRevalidate:f});h&&n!==!1?_.startTransition(()=>p()):p()},...p,"data-discover":!b&&e===`render`?`true`:void 0})});Tn.displayName=`Form`;function En({getKey:e,storageKey:t,...n}){let r=_.useContext(dn),{basename:i}=_.useContext(Be),a=Ze(),o=xt();zn({getKey:e,storageKey:t});let s=_.useMemo(()=>{if(!r||!e)return null;let t=Rn(a,o,i,e);return t===a.key?null:t},[]);if(!r||r.isSpaMode)return null;let c=((e,t)=>{if(!window.history.state||!window.history.state.key){let e=Math.random().toString(32).slice(2);window.history.replaceState({key:e},``)}try{let n=JSON.parse(sessionStorage.getItem(e)||`{}`)[t||window.history.state.key];
11typeof n==`number`&&window.scrollTo(0,n)}catch(t){console.error(t),sessionStorage.removeItem(e)}}).toString();return _.createElement(`script`,{...n,suppressHydrationWarning:!0,dangerouslySetInnerHTML:{__html:`(${c})(${Xt(JSON.stringify(t||In))}, ${Xt(JSON.stringify(s))})`}})}En.displayName=`ScrollRestoration`;function Dn(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function On(e){let t=_.useContext(Pe);return E(t,Dn(e)),t}function kn(e){let t=_.useContext(Fe);return E(t,Dn(e)),t}function An(e,{target:t,replace:n,unstable_mask:r,state:i,preventScrollReset:a,relative:o,viewTransition:s,unstable_defaultShouldRevalidate:c,unstable_useTransitions:l}={}){let u=et(),d=Ze(),f=it(e,{relative:o});return _.useCallback(p=>{if(Bt(p,t)){p.preventDefault();let t=n===void 0?j(d)===j(f):n,m=()=>u(e,{replace:t,unstable_mask:r,state:i,preventScrollReset:a,relative:o,viewTransition:s,unstable_defaultShouldRevalidate:c});l?_.startTransition(()=>m()):m()}},[d,u,f,n,r,i,t,e,a,o,s,c,l])}function jn(e){D(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 t=_.useRef(Vt(e)),n=_.useRef(!1),r=Ze(),i=_.useMemo(()=>Ht(r.search,n.current?null:t.current),[r.search]),a=et();return[i,_.useCallback((e,t)=>{let r=Vt(typeof e==`function`?e(new URLSearchParams(i)):e);n.current=!0,a(`?`+r,t)},[a,i])]}var Mn=0,Nn=()=>`__${String(++Mn)}__`;function Pn(){let{router:e}=On(`useSubmit`),{basename:t}=_.useContext(Be),n=yt(),r=e.fetch,i=e.navigate;return _.useCallback(async(e,a={})=>{let{action:o,method:s,encType:c,formData:l,body:u}=qt(e,t);a.navigate===!1?await r(a.fetcherKey||Nn(),n,a.action||o,{unstable_defaultShouldRevalidate:a.unstable_defaultShouldRevalidate,preventScrollReset:a.preventScrollReset,formData:l,body:u,formMethod:a.method||s,formEncType:a.encType||c,flushSync:a.flushSync}):await i(a.action||o,{unstable_defaultShouldRevalidate:a.unstable_defaultShouldRevalidate,preventScrollReset:a.preventScrollReset,formData:l,body:u,formMethod:a.method||s,formEncType:a.encType||c,replace:a.replace,state:a.state,fromRouteId:n,flushSync:a.flushSync,viewTransition:a.viewTransition})},[r,i,t,n])}function Fn(e,{relative:t}={}){let{basename:n}=_.useContext(Be),r=_.useContext(He);E(r,`useFormAction must be used inside a RouteContext`);let[i]=r.matches.slice(-1),a={...it(e||`.`,{relative:t})},o=Ze();if(e==null){a.search=o.search;let e=new URLSearchParams(a.search),t=e.getAll(`index`);if(t.some(e=>e===``)){e.delete(`index`),t.filter(e=>e).forEach(t=>e.append(`index`,t));let n=e.toString();a.search=n?`?${n}`:``}}return(!e||e===`.`)&&i.route.index&&(a.search=a.search?a.search.replace(/^\?/,`?index&`):`?index`),n!==`/`&&(a.pathname=a.pathname===`/`?n:Te([n,a.pathname])),j(a)}var In=`react-router-scroll-positions`,Ln={};function Rn(e,t,n,r){let i=null;return r&&(i=r(n===`/`?e:{...e,pathname:_e(e.pathname,n)||e.pathname},t)),i??=e.key,i}function zn({getKey:e,storageKey:t}={}){let{router:n}=On(`useScrollRestoration`),{restoreScrollPosition:r,preventScrollReset:i}=kn(`useScrollRestoration`),{basename:a}=_.useContext(Be),o=Ze(),s=xt(),c=bt();_.useEffect(()=>(window.history.scrollRestoration=`manual`,()=>{window.history.scrollRestoration=`auto`}),[]),Bn(_.useCallback(()=>{if(c.state===`idle`){let t=Rn(o,s,a,e);Ln[t]=window.scrollY}try{sessionStorage.setItem(t||In,JSON.stringify(Ln))}catch(e){D(!1,`Failed to save scroll positions in sessionStorage, <ScrollRestoration /> will not work properly (${e}).`)}window.history.scrollRestoration=`auto`},[c.state,e,a,o,s,t])),typeof document<`u`&&(_.useLayoutEffect(()=>{try{let e=sessionStorage.getItem(t||In);e&&(Ln=JSON.parse(e))}catch{}},[t]),_.useLayoutEffect(()=>{let t=n?.enableScrollRestoration(Ln,()=>window.scrollY,e?(t,n)=>Rn(t,n,a,e):void 0);return()=>t&&t()},[n,a,e]),_.useLayoutEffect(()=>{if(r!==!1){if(typeof r==`number`){window.scrollTo(0,r);return}try{if(o.hash){let e=document.getElementById(decodeURIComponent(o.hash.slice(1)));if(e){e.scrollIntoView();return}}}catch{D(!1,`"${o.hash.slice(1)}" is not a decodable element ID. The view will not scroll to it.`)}i!==!0&&window.scrollTo(0,0)}},[o,r,i]))}function Bn(e,t){let{capture:n}=t||{};_.useEffect(()=>{let t=n==null?void 0:{capture:n};return window.addEventListener(`pagehide`,e,t),()=>{window.removeEventListener(`pagehide`,e,t)}},[e,n])}function Vn(e,{relative:t}={}){let n=_.useContext(Le);E(n!=null,"`useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. Did you accidentally import `RouterProvider` from `react-router`?");let{basename:r}=On(`useViewTransitionState`),i=it(e,{relative:t});if(!n.isTransitioning)return!1;let a=_e(n.currentLocation.pathname,r)||n.currentLocation.pathname,o=_e(n.nextLocation.pathname,r)||n.nextLocation.pathname;return me(i.pathname,o)!=null||me(i.pathname,a)!=null}var Hn=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}},Un=new class extends Hn{#e;#t;#n;constructor(){super(),this.#n=e=>{if(typeof window<`u`&&window.addEventListener){let t=()=>e();return window.addEventListener(`visibilitychange`,t,!1),()=>{window.removeEventListener(`visibilitychange`,t)}}}}onSubscribe(){this.#t||this.setEventListener(this.#n)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#n=e,this.#t?.(),this.#t=e(e=>{typeof e==`boolean`?this.setFocused(e):this.onFocus()})}setFocused(e){this.#e!==e&&(this.#e=e,this.onFocus())}onFocus(){let e=this.isFocused();
11this.listeners.forEach(t=>{t(e)})}isFocused(){return typeof this.#e==`boolean`?this.#e:globalThis.document?.visibilityState!==`hidden`}},Wn={setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e),setInterval:(e,t)=>setInterval(e,t),clearInterval:e=>clearInterval(e)},Gn=new class{#e=Wn;setTimeoutProvider(e){this.#e=e}setTimeout(e,t){return this.#e.setTimeout(e,t)}clearTimeout(e){this.#e.clearTimeout(e)}setInterval(e,t){return this.#e.setInterval(e,t)}clearInterval(e){this.#e.clearInterval(e)}};function Kn(e){setTimeout(e,0)}var qn=typeof window>`u`||`Deno`in globalThis;function Jn(){}function Yn(e,t){return typeof e==`function`?e(t):e}function Xn(e){return typeof e==`number`&&e>=0&&e!==1/0}function Zn(e,t){return Math.max(e+(t||0)-Date.now(),0)}function Qn(e,t){return typeof e==`function`?e(t):e}function $n(e,t){return typeof e==`function`?e(t):e}function er(e,t){let{type:n=`all`,exact:r,fetchStatus:i,predicate:a,queryKey:o,stale:s}=e;if(o){if(r){if(t.queryHash!==nr(o,t.options))return!1}else if(!ir(t.queryKey,o))return!1}if(n!==`all`){let e=t.isActive();if(n===`active`&&!e||n===`inactive`&&e)return!1}return!(typeof s==`boolean`&&t.isStale()!==s||i&&i!==t.state.fetchStatus||a&&!a(t))}function tr(e,t){let{exact:n,status:r,predicate:i,mutationKey:a}=e;if(a){if(!t.options.mutationKey)return!1;if(n){if(rr(t.options.mutationKey)!==rr(a))return!1}else if(!ir(t.options.mutationKey,a))return!1}return!(r&&t.state.status!==r||i&&!i(t))}function nr(e,t){return(t?.queryKeyHashFn||rr)(e)}function rr(e){return JSON.stringify(e,(e,t)=>lr(t)?Object.keys(t).sort().reduce((e,n)=>(e[n]=t[n],e),{}):t)}function ir(e,t){return e===t?!0:typeof e==typeof t&&e&&t&&typeof e==`object`&&typeof t==`object`?Object.keys(t).every(n=>ir(e[n],t[n])):!1}var ar=Object.prototype.hasOwnProperty;function or(e,t,n=0){if(e===t)return e;if(n>500)return t;let r=cr(e)&&cr(t);if(!r&&!(lr(e)&&lr(t)))return t;let i=(r?e:Object.keys(e)).length,a=r?t:Object.keys(t),o=a.length,s=r?Array(o):{},c=0;for(let l=0;l<o;l++){let o=r?l:a[l],u=e[o],d=t[o];if(u===d){s[o]=u,(r?l<i:ar.call(e,o))&&c++;continue}if(u===null||d===null||typeof u!=`object`||typeof d!=`object`){s[o]=d;continue}let f=or(u,d,n+1);s[o]=f,f===u&&c++}return i===o&&c===i?e:s}function sr(e,t){if(!t||Object.keys(e).length!==Object.keys(t).length)return!1;for(let n in e)if(e[n]!==t[n])return!1;return!0}function cr(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function lr(e){if(!ur(e))return!1;let t=e.constructor;if(t===void 0)return!0;let n=t.prototype;return!(!ur(n)||!n.hasOwnProperty(`isPrototypeOf`)||Object.getPrototypeOf(e)!==Object.prototype)}function ur(e){return Object.prototype.toString.call(e)===`[object Object]`}function dr(e){return new Promise(t=>{Gn.setTimeout(t,e)})}function fr(e,t,n){return typeof n.structuralSharing==`function`?n.structuralSharing(e,t):n.structuralSharing===!1?t:or(e,t)}function pr(e){return e}function mr(e,t,n=0){let r=[...e,t];return n&&r.length>n?r.slice(1):r}function hr(e,t,n=0){let r=[t,...e];return n&&r.length>n?r.slice(0,-1):r}var gr=Symbol();function _r(e,t){return!e.queryFn&&t?.initialPromise?()=>t.initialPromise:!e.queryFn||e.queryFn===gr?()=>Promise.reject(Error(`Missing queryFn: '${e.queryHash}'`)):e.queryFn}function vr(e,t){return typeof e==`function`?e(...t):!!e}function yr(e,t,n){let r=!1,i;return Object.defineProperty(e,`signal`,{enumerable:!0,get:()=>(i??=t(),r?i:(r=!0,i.aborted?n():i.addEventListener(`abort`,n,{once:!0}),i))}),e}var br=(()=>{let e=()=>qn;return{isServer(){return e()},setIsServer(t){e=t}}})();function xr(){let e,t,n=new Promise((n,r)=>{e=n,t=r});n.status=`pending`,n.catch(()=>{});function r(e){Object.assign(n,e),delete n.resolve,delete n.reject}return n.resolve=t=>{r({status:`fulfilled`,value:t}),e(t)},n.reject=e=>{r({status:`rejected`,reason:e}),t(e)},n}var Sr=Kn;function Cr(){let e=[],t=0,n=e=>{e()},r=e=>{e()},i=Sr,a=r=>{t?e.push(r):i(()=>{n(r)})},o=()=>{let t=e;e=[],t.length&&i(()=>{r(()=>{t.forEach(e=>{n(e)})})})};return{batch:e=>{let n;t++;try{n=e()}finally{t--,t||o()}return n},batchCalls:e=>(...t)=>{a(()=>{e(...t)})},schedule:a,setNotifyFunction:e=>{n=e},setBatchNotifyFunction:e=>{r=e},setScheduler:e=>{i=e}}}var wr=Cr(),Tr=new class extends Hn{#e=!0;#t;#n;constructor(){super(),this.#n=e=>{if(typeof window<`u`&&window.addEventListener){let t=()=>e(!0),n=()=>e(!1);return window.addEventListener(`online`,t,!1),window.addEventListener(`offline`,n,!1),()=>{window.removeEventListener(`online`,t),window.removeEventListener(`offline`,n)}}}}onSubscribe(){this.#t||this.setEventListener(this.#n)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#n=e,this.#t?.(),this.#t=e(this.setOnline.bind(this))}
11setOnline(e){this.#e!==e&&(this.#e=e,this.listeners.forEach(t=>{t(e)}))}isOnline(){return this.#e}};function Er(e){return Math.min(1e3*2**e,3e4)}function Dr(e){return(e??`online`)===`online`?Tr.isOnline():!0}var Or=class extends Error{constructor(e){super(`CancelledError`),this.revert=e?.revert,this.silent=e?.silent}};function kr(e){let t=!1,n=0,r,i=xr(),a=()=>i.status!==`pending`,o=t=>{if(!a()){let n=new Or(t);f(n),e.onCancel?.(n)}},s=()=>{t=!0},c=()=>{t=!1},l=()=>Un.isFocused()&&(e.networkMode===`always`||Tr.isOnline())&&e.canRun(),u=()=>Dr(e.networkMode)&&e.canRun(),d=e=>{a()||(r?.(),i.resolve(e))},f=e=>{a()||(r?.(),i.reject(e))},p=()=>new Promise(t=>{r=e=>{(a()||l())&&t(e)},e.onPause?.()}).then(()=>{r=void 0,a()||e.onContinue?.()}),m=()=>{if(a())return;let r,i=n===0?e.initialPromise:void 0;try{r=i??e.fn()}catch(e){r=Promise.reject(e)}Promise.resolve(r).then(d).catch(r=>{if(a())return;let i=e.retry??(br.isServer()?0:3),o=e.retryDelay??Er,s=typeof o==`function`?o(n,r):o,c=i===!0||typeof i==`number`&&n<i||typeof i==`function`&&i(n,r);if(t||!c){f(r);return}n++,e.onFail?.(n,r),dr(s).then(()=>l()?void 0:p()).then(()=>{t?f(r):m()})})};return{promise:i,status:()=>i.status,cancel:o,continue:()=>(r?.(),i),cancelRetry:s,continueRetry:c,canStart:u,start:()=>(u()?m():p().then(m),i)}}var Ar=class{#e;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),Xn(this.gcTime)&&(this.#e=Gn.setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(e){this.gcTime=Math.max(this.gcTime||0,e??(br.isServer()?1/0:300*1e3))}clearGcTimeout(){this.#e&&=(Gn.clearTimeout(this.#e),void 0)}},jr=class extends Ar{#e;#t;#n;#r;#i;#a;#o;constructor(e){super(),this.#o=!1,this.#a=e.defaultOptions,this.setOptions(e.options),this.observers=[],this.#r=e.client,this.#n=this.#r.getQueryCache(),this.queryKey=e.queryKey,this.queryHash=e.queryHash,this.#e=Pr(this.options),this.state=e.state??this.#e,this.scheduleGc()}get meta(){return this.options.meta}get promise(){return this.#i?.promise}setOptions(e){if(this.options={...this.#a,...e},this.updateGcTime(this.options.gcTime),this.state&&this.state.data===void 0){let e=Pr(this.options);e.data!==void 0&&(this.setState(Nr(e.data,e.dataUpdatedAt)),this.#e=e)}}optionalRemove(){!this.observers.length&&this.state.fetchStatus===`idle`&&this.#n.remove(this)}setData(e,t){let n=fr(this.state.data,e,this.options);return this.#c({data:n,type:`success`,dataUpdatedAt:t?.updatedAt,manual:t?.manual}),n}setState(e,t){this.#c({type:`setState`,state:e,setStateOptions:t})}cancel(e){let t=this.#i?.promise;return this.#i?.cancel(e),t?t.then(Jn).catch(Jn):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}get resetState(){return this.#e}reset(){this.destroy(),this.setState(this.resetState)}isActive(){return this.observers.some(e=>$n(e.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===gr||!this.isFetched()}isFetched(){return this.state.dataUpdateCount+this.state.errorUpdateCount>0}isStatic(){return this.getObserversCount()>0?this.observers.some(e=>Qn(e.options.staleTime,this)===`static`):!1}isStale(){return this.getObserversCount()>0?this.observers.some(e=>e.getCurrentResult().isStale):this.state.data===void 0||this.state.isInvalidated}isStaleByTime(e=0){return this.state.data===void 0?!0:e===`static`?!1:this.state.isInvalidated?!0:!Zn(this.state.dataUpdatedAt,e)}onFocus(){this.observers.find(e=>e.shouldFetchOnWindowFocus())?.refetch({cancelRefetch:!1}),this.#i?.continue()}onOnline(){this.observers.find(e=>e.shouldFetchOnReconnect())?.refetch({cancelRefetch:!1}),this.#i?.continue()}addObserver(e){this.observers.includes(e)||(this.observers.push(e),this.clearGcTimeout(),this.#n.notify({type:`observerAdded`,query:this,observer:e}))}removeObserver(e){this.observers.includes(e)&&(this.observers=this.observers.filter(t=>t!==e),this.observers.length||(this.#i&&(this.#o||this.#s()?this.#i.cancel({revert:!0}):this.#i.cancelRetry()),this.scheduleGc()),this.#n.notify({type:`observerRemoved`,query:this,observer:e}))}getObserversCount(){return this.observers.length}#s(){return this.state.fetchStatus===`paused`&&this.state.status===`pen
11ding`}invalidate(){this.state.isInvalidated||this.#c({type:`invalidate`})}async fetch(e,t){if(this.state.fetchStatus!==`idle`&&this.#i?.status()!==`rejected`){if(this.state.data!==void 0&&t?.cancelRefetch)this.cancel({silent:!0});else if(this.#i)return this.#i.continueRetry(),this.#i.promise}if(e&&this.setOptions(e),!this.options.queryFn){let e=this.observers.find(e=>e.options.queryFn);e&&this.setOptions(e.options)}let n=new AbortController,r=e=>{Object.defineProperty(e,`signal`,{enumerable:!0,get:()=>(this.#o=!0,n.signal)})},i=()=>{let e=_r(this.options,t),n=(()=>{let e={client:this.#r,queryKey:this.queryKey,meta:this.meta};return r(e),e})();return this.#o=!1,this.options.persister?this.options.persister(e,n,this):e(n)},a=(()=>{let e={fetchOptions:t,options:this.options,queryKey:this.queryKey,client:this.#r,state:this.state,fetchFn:i};return r(e),e})();this.options.behavior?.onFetch(a,this),this.#t=this.state,(this.state.fetchStatus===`idle`||this.state.fetchMeta!==a.fetchOptions?.meta)&&this.#c({type:`fetch`,meta:a.fetchOptions?.meta}),this.#i=kr({initialPromise:t?.initialPromise,fn:a.fetchFn,onCancel:e=>{e instanceof Or&&e.revert&&this.setState({...this.#t,fetchStatus:`idle`}),n.abort()},onFail:(e,t)=>{this.#c({type:`failed`,failureCount:e,error:t})},onPause:()=>{this.#c({type:`pause`})},onContinue:()=>{this.#c({type:`continue`})},retry:a.options.retry,retryDelay:a.options.retryDelay,networkMode:a.options.networkMode,canRun:()=>!0});try{let e=await this.#i.start();if(e===void 0)throw Error(`${this.queryHash} data is undefined`);return this.setData(e),this.#n.config.onSuccess?.(e,this),this.#n.config.onSettled?.(e,this.state.error,this),e}catch(e){if(e instanceof Or){if(e.silent)return this.#i.promise;if(e.revert){if(this.state.data===void 0)throw e;return this.state.data}}throw this.#c({type:`error`,error:e}),this.#n.config.onError?.(e,this),this.#n.config.onSettled?.(this.state.data,e,this),e}finally{this.scheduleGc()}}#c(e){this.state=(t=>{switch(e.type){case`failed`:return{...t,fetchFailureCount:e.failureCount,fetchFailureReason:e.error};case`pause`:return{...t,fetchStatus:`paused`};case`continue`:return{...t,fetchStatus:`fetching`};case`fetch`:return{...t,...Mr(t.data,this.options),fetchMeta:e.meta??null};case`success`:let n={...t,...Nr(e.data,e.dataUpdatedAt),dataUpdateCount:t.dataUpdateCount+1,...!e.manual&&{fetchStatus:`idle`,fetchFailureCount:0,fetchFailureReason:null}};return this.#t=e.manual?n:void 0,n;case`error`:let r=e.error;return{...t,error:r,errorUpdateCount:t.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:t.fetchFailureCount+1,fetchFailureReason:r,fetchStatus:`idle`,status:`error`,isInvalidated:!0};case`invalidate`:return{...t,isInvalidated:!0};case`setState`:return{...t,...e.state}}})(this.state),wr.batch(()=>{this.observers.forEach(e=>{e.onQueryUpdate()}),this.#n.notify({query:this,type:`updated`,action:e})})}};function Mr(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:Dr(t.networkMode)?`fetching`:`paused`,...e===void 0&&{error:null,status:`pending`}}}function Nr(e,t){return{data:e,dataUpdatedAt:t??Date.now(),error:null,isInvalidated:!1,status:`success`}}function Pr(e){let t=typeof e.initialData==`function`?e.initialData():e.initialData,n=t!==void 0,r=n?typeof e.initialDataUpdatedAt==`function`?e.initialDataUpdatedAt():e.initialDataUpdatedAt:0;return{data:t,dataUpdateCount:0,dataUpdatedAt:n?r??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:n?`success`:`pending`,fetchStatus:`idle`}}var Fr=class extends Hn{constructor(e,t){super(),this.options=t,this.#e=e,this.#s=null,this.#o=xr(),this.bindMethods(),this.setOptions(t)}#e;#t=void 0;#n=void 0;#r=void 0;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p;#m=new Set;bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(this.#t.addObserver(this),Lr(this.#t,this.options)?this.#h():this.updateResult(),this.#y())}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return Rr(this.#t,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return Rr(this.#t,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,this.#b(),this.#x(),this.#t.removeObserver(this)}setOptions(e){let t=this.options,n=this.#t;if(this.options=this.#e.defaultQueryOptions(e),this.options.enabled!==void 0&&typeof this.options.enabled!=`boolean`&&typeof this.options.enabled!=`function`&&typeof $n(this.options.enabled,this.#t)!=`boolean`)throw Error(`Expected enabled to be a boolean or a callback that returns a boolean`);this.#S(),this.#t.setOptions(this.options),t._defaulted&&!sr(this.options,t)&&this.#e.getQueryCache().notify({type:`observerOptionsUpdated`,query:this.#t,observer:this});let r=this.hasListeners();r&&zr(this.#t,n,this.options,t)&&this.#h(),this.updateResult(),r&&(this.#t!==n||$n(this.options.enabled,this.#t)!==$n(t.enabled,this.#t)||Qn(this.options.staleTime,this.#t)!==Qn(t.staleTime,this.#t))&&this.#g();let i=this.#_();r&&(this.#t!==n||$n(this.options.enabled,this.#t)!==$n(t.enabled,this.#t)||i!==this.#p)&&this.#v(i)}getOptimisticResult(e){let t=this.#e.getQueryCache().build(this.#e,e),n=this.createResult(t,e);return Vr(this,n)&&(this.#r=n,this.#a=this.options,this.#i=this.#t.state),n}getCurrentResult(){return this.#r}trackResult(e,t){return new Proxy(e,{get:(e,n)=>(this.trackProp(n),t?.(n),n===`promise`&&(this.trackProp(`data`),!this.options.experimental_prefetchInRender&&this.#o.status===`pen
11ding`&&this.#o.reject(Error(`experimental_prefetchInRender feature flag is not enabled`))),Reflect.get(e,n))})}trackProp(e){this.#m.add(e)}getCurrentQuery(){return this.#t}refetch({...e}={}){return this.fetch({...e})}fetchOptimistic(e){let t=this.#e.defaultQueryOptions(e),n=this.#e.getQueryCache().build(this.#e,t);return n.fetch().then(()=>this.createResult(n,t))}fetch(e){return this.#h({...e,cancelRefetch:e.cancelRefetch??!0}).then(()=>(this.updateResult(),this.#r))}#h(e){this.#S();let t=this.#t.fetch(this.options,e);return e?.throwOnError||(t=t.catch(Jn)),t}#g(){this.#b();let e=Qn(this.options.staleTime,this.#t);if(br.isServer()||this.#r.isStale||!Xn(e))return;let t=Zn(this.#r.dataUpdatedAt,e)+1;this.#d=Gn.setTimeout(()=>{this.#r.isStale||this.updateResult()},t)}#_(){return(typeof this.options.refetchInterval==`function`?this.options.refetchInterval(this.#t):this.options.refetchInterval)??!1}#v(e){this.#x(),this.#p=e,!(br.isServer()||$n(this.options.enabled,this.#t)===!1||!Xn(this.#p)||this.#p===0)&&(this.#f=Gn.setInterval(()=>{(this.options.refetchIntervalInBackground||Un.isFocused())&&this.#h()},this.#p))}#y(){this.#g(),this.#v(this.#_())}#b(){this.#d&&=(Gn.clearTimeout(this.#d),void 0)}#x(){this.#f&&=(Gn.clearInterval(this.#f),void 0)}createResult(e,t){let n=this.#t,r=this.options,i=this.#r,a=this.#i,o=this.#a,s=e===n?this.#n:e.state,{state:c}=e,l={...c},u=!1,d;if(t._optimisticResults){let i=this.hasListeners(),a=!i&&Lr(e,t),o=i&&zr(e,n,t,r);(a||o)&&(l={...l,...Mr(c.data,e.options)}),t._optimisticResults===`isRestoring`&&(l.fetchStatus=`idle`)}let{error:f,errorUpdatedAt:p,status:m}=l;d=l.data;let h=!1;if(t.placeholderData!==void 0&&d===void 0&&m===`pending`){let e;i?.isPlaceholderData&&t.placeholderData===o?.placeholderData?(e=i.data,h=!0):e=typeof t.placeholderData==`function`?t.placeholderData(this.#u?.state.data,this.#u):t.placeholderData,e!==void 0&&(m=`success`,d=fr(i?.data,e,t),u=!0)}if(t.select&&d!==void 0&&!h)if(i&&d===a?.data&&t.select===this.#c)d=this.#l;else try{this.#c=t.select,d=t.select(d),d=fr(i?.data,d,t),this.#l=d,this.#s=null}catch(e){this.#s=e}this.#s&&(f=this.#s,d=this.#l,p=Date.now(),m=`error`);let g=l.fetchStatus===`fetching`,_=m===`pending`,v=m===`error`,y=_&&g,b=d!==void 0,x={status:m,fetchStatus:l.fetchStatus,isPending:_,isSuccess:m===`success`,isError:v,isInitialLoading:y,isLoading:y,data:d,dataUpdatedAt:l.dataUpdatedAt,error:f,errorUpdatedAt:p,failureCount:l.fetchFailureCount,failureReason:l.fetchFailureReason,errorUpdateCount:l.errorUpdateCount,isFetched:e.isFetched(),isFetchedAfterMount:l.dataUpdateCount>s.dataUpdateCount||l.errorUpdateCount>s.errorUpdateCount,isFetching:g,isRefetching:g&&!_,isLoadingError:v&&!b,isPaused:l.fetchStatus===`paused`,isPlaceholderData:u,isRefetchError:v&&b,isStale:Br(e,t),refetch:this.refetch,promise:this.#o,isEnabled:$n(t.enabled,e)!==!1};if(this.options.experimental_prefetchInRender){let t=x.data!==void 0,r=x.status===`error`&&!t,i=e=>{r?e.reject(x.error):t&&e.resolve(x.data)},a=()=>{i(this.#o=x.promise=xr())},o=this.#o;switch(o.status){case`pending`:e.queryHash===n.queryHash&&i(o);break;case`fulfilled`:(r||x.data!==o.value)&&a();break;case`rejected`:(!r||x.error!==o.reason)&&a();break}}return x}updateResult(){let e=this.#r,t=this.createResult(this.#t,this.options);this.#i=this.#t.state,this.#a=this.options,this.#i.data!==void 0&&(this.#u=this.#t),!sr(t,e)&&(this.#r=t,this.#C({listeners:(()=>{if(!e)return!0;let{notifyOnChangeProps:t}=this.options,n=typeof t==`function`?t():t;if(n===`all`||!n&&!this.#m.size)return!0;let r=new Set(n??this.#m);return this.options.throwOnError&&r.add(`error`),Object.keys(this.#r).some(t=>{let n=t;return this.#r[n]!==e[n]&&r.has(n)})})()}))}#S(){let e=this.#e.getQueryCache().build(this.#e,this.options);if(e===this.#t)return;let t=this.#t;this.#t=e,this.#n=e.state,this.hasListeners()&&(t?.removeObserver(this),e.addObserver(this))}onQueryUpdate(){this.updateResult(),this.hasListeners()&&this.#y()}#C(e){wr.batch(()=>{e.listeners&&this.listeners.forEach(e=>{e(this.#r)}),this.#e.getQueryCache().notify({query:this.#t,type:`observerResultsUpdated`})})}};function Ir(e,t){return $n(t.enabled,e)!==!1&&e.state.data===void 0&&!(e.state.status===`error`&&t.retryOn
11Mount===!1)}function Lr(e,t){return Ir(e,t)||e.state.data!==void 0&&Rr(e,t,t.refetchOnMount)}function Rr(e,t,n){if($n(t.enabled,e)!==!1&&Qn(t.staleTime,e)!==`static`){let r=typeof n==`function`?n(e):n;return r===`always`||r!==!1&&Br(e,t)}return!1}function zr(e,t,n,r){return(e!==t||$n(r.enabled,e)===!1)&&(!n.suspense||e.state.status!==`error`)&&Br(e,n)}function Br(e,t){return $n(t.enabled,e)!==!1&&e.isStaleByTime(Qn(t.staleTime,e))}function Vr(e,t){return!sr(e.getCurrentResult(),t)}function Hr(e){return{onFetch:(t,n)=>{let r=t.options,i=t.fetchOptions?.meta?.fetchMore?.direction,a=t.state.data?.pages||[],o=t.state.data?.pageParams||[],s={pages:[],pageParams:[]},c=0,l=async()=>{let n=!1,l=e=>{yr(e,()=>t.signal,()=>n=!0)},u=_r(t.options,t.fetchOptions),d=async(e,r,i)=>{if(n)return Promise.reject();if(r==null&&e.pages.length)return Promise.resolve(e);let a=await u((()=>{let e={client:t.client,queryKey:t.queryKey,pageParam:r,direction:i?`backward`:`forward`,meta:t.options.meta};return l(e),e})()),{maxPages:o}=t.options,s=i?hr:mr;return{pages:s(e.pages,a,o),pageParams:s(e.pageParams,r,o)}};if(i&&a.length){let e=i===`backward`,t=e?Wr:Ur,n={pages:a,pageParams:o};s=await d(n,t(r,n),e)}else{let t=e??a.length;do{let e=c===0?o[0]??r.initialPageParam:Ur(r,s);if(c>0&&e==null)break;s=await d(s,e),c++}while(c<t)}return s};t.options.persister?t.fetchFn=()=>t.options.persister?.(l,{client:t.client,queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},n):t.fetchFn=l}}}function Ur(e,{pages:t,pageParams:n}){let r=t.length-1;return t.length>0?e.getNextPageParam(t[r],t,n[r],n):void 0}function Wr(e,{pages:t,pageParams:n}){return t.length>0?e.getPreviousPageParam?.(t[0],t,n[0],n):void 0}function Gr(e,t){return t?Ur(e,t)!=null:!1}function Kr(e,t){return!t||!e.getPreviousPageParam?!1:Wr(e,t)!=null}var qr=class extends Fr{constructor(e,t){super(e,t)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(e){super.setOptions({...e,behavior:Hr()})}getOptimisticResult(e){return e.behavior=Hr(),super.getOptimisticResult(e)}fetchNextPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`forward`}}})}fetchPreviousPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`backward`}}})}createResult(e,t){let{state:n}=e,r=super.createResult(e,t),{isFetching:i,isRefetching:a,isError:o,isRefetchError:s}=r,c=n.fetchMeta?.fetchMore?.direction,l=o&&c===`forward`,u=i&&c===`forward`,d=o&&c===`backward`,f=i&&c===`backward`;return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:Gr(t,n.data),hasPreviousPage:Kr(t,n.data),isFetchNextPageError:l,isFetchingNextPage:u,isFetchPreviousPageError:d,isFetchingPreviousPage:f,isRefetchError:s&&!l&&!d,isRefetching:a&&!u&&!f}}},Jr=class extends Ar{#e;#t;#n;#r;constructor(e){super(),this.#e=e.client,this.mutationId=e.mutationId,this.#n=e.mutationCache,this.#t=[],this.state=e.state||Yr(),this.setOptions(e.options),this.scheduleGc()}setOptions(e){this.options=e,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(e){this.#t.includes(e)||(this.#t.push(e),this.clearGcTimeout(),this.#n.notify({type:`observerAdded`,mutation:this,observer:e}))}removeObserver(e){this.#t=this.#t.filter(t=>t!==e),this.scheduleGc(),this.#n.notify({type:`observerRemoved`,mutation:this,observer:e})}optionalRemove(){this.#t.length||(this.state.status===`pending`?this.scheduleGc():this.#n.remove(this))}continue(){return this.#r?.continue()??this.execute(this.state.variables)}async execute(e){let t=()=>{this.#i({type:`continue`})},n={client:this.#e,meta:this.options.meta,mutationKey:this.options.mutationKey};this.#r=kr({fn:()=>this.options.mutationFn?this.options.mutationFn(e,n):Promise.reject(Error(`No mutationFn found`)),onFail:(e,t)=>{this.#i({type:`failed`,failureCount:e,error:t})},onPause:()=>{this.#i({type:`pause`})},onContinue:t,retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>this.#n.canRun(this)});
vendor: 2,868 bytes, line 11
11let r=this.state.status===`pending`,i=!this.#r.canStart();try{if(r)t();else{this.#i({type:`pending`,variables:e,isPaused:i}),this.#n.config.onMutate&&await this.#n.config.onMutate(e,this,n);let t=await this.options.onMutate?.(e,n);t!==this.state.context&&this.#i({type:`pending`,context:t,variables:e,isPaused:i})}let a=await this.#r.start();return await this.#n.config.onSuccess?.(a,e,this.state.context,this,n),await this.options.onSuccess?.(a,e,this.state.context,n),await this.#n.config.onSettled?.(a,null,this.state.variables,this.state.context,this,n),await this.options.onSettled?.(a,null,e,this.state.context,n),this.#i({type:`success`,data:a}),a}catch(t){try{await this.#n.config.onError?.(t,e,this.state.context,this,n)}catch(e){Promise.reject(e)}try{await this.options.onError?.(t,e,this.state.context,n)}catch(e){Promise.reject(e)}try{await this.#n.config.onSettled?.(void 0,t,this.state.variables,this.state.context,this,n)}catch(e){Promise.reject(e)}try{await this.options.onSettled?.(void 0,t,e,this.state.context,n)}catch(e){Promise.reject(e)}throw this.#i({type:`error`,error:t}),t}finally{this.#n.runNext(this)}}#i(e){this.state=(t=>{switch(e.type){case`failed`:return{...t,failureCount:e.failureCount,failureReason:e.error};case`pause`:return{...t,isPaused:!0};case`continue`:return{...t,isPaused:!1};case`pending`:return{...t,context:e.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:e.isPaused,status:`pending`,variables:e.variables,submittedAt:Date.now()};case`success`:return{...t,data:e.data,failureCount:0,failureReason:null,error:null,status:`success`,isPaused:!1};case`error`:return{...t,data:void 0,error:e.error,failureCount:t.failureCount+1,failureReason:e.error,isPaused:!1,status:`error`}}})(this.state),wr.batch(()=>{this.#t.forEach(t=>{t.onMutationUpdate(e)}),this.#n.notify({mutation:this,type:`updated`,action:e})})}};function Yr(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:`idle`,variables:void 0,submittedAt:0}}var Xr=class extends Hn{constructor(e={}){super(),this.config=e,this.#e=new Set,this.#t=new Map,this.#n=0}#e;#t;#n;build(e,t,n){let r=new Jr({client:e,mutationCache:this,mutationId:++this.#n,options:e.defaultMutationOptions(t),state:n});return this.add(r),r}add(e){this.#e.add(e);let t=Zr(e);if(typeof t==`string`){let n=this.#t.get(t);n?n.push(e):this.#t.set(t,[e])}this.notify({type:`added`,mutation:e})}remove(e){if(this.#e.delete(e)){let t=Zr(e);if(typeof t==`string`){let n=this.#t.get(t);if(n)if(n.length>1){let t=n.indexOf(e);t!==-1&&n.splice(t,1)}else n[0]===e&&this.#t.delete(t)}}this.notify({type:`removed`,mutation:e})}canRun(e){let t=Zr(e);if(typeof t==`string`){let n=this.#t.get(t)?.find(e=>e.state.status===`pending`);return!n||n===e}else return!0}runNext(e){let t=Zr(e);return typeof t==`string`?(this.#t.get(t)?.find(t=>
11t!==e&&t.state.isPaused))?.continue()??Promise.resolve():Promise.resolve()}clear(){wr.batch(()=>{this.#e.forEach(e=>{this.notify({type:`removed`,mutation:e})}),this.#e.clear(),this.#t.clear()})}getAll(){return Array.from(this.#e)}find(e){let t={exact:!0,...e};return this.getAll().find(e=>tr(t,e))}findAll(e={}){return this.getAll().filter(t=>tr(e,t))}notify(e){wr.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){let e=this.getAll().filter(e=>e.state.isPaused);return wr.batch(()=>Promise.all(e.map(e=>e.continue().catch(Jn))))}};function Zr(e){return e.options.scope?.id}var Qr=class extends Hn{#e;#t=void 0;#n;#r;constructor(e,t){super(),this.#e=e,this.setOptions(t),this.bindMethods(),this.#i()}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(e){let t=this.options;this.options=this.#e.defaultMutationOptions(e),sr(this.options,t)||this.#e.getMutationCache().notify({type:`observerOptionsUpdated`,mutation:this.#n,observer:this}),t?.mutationKey&&this.options.mutationKey&&rr(t.mutationKey)!==rr(this.options.mutationKey)?this.reset():this.#n?.state.status===`pending`&&this.#n.setOptions(this.options)}onUnsubscribe(){this.hasListeners()||this.#n?.removeObserver(this)}onMutationUpdate(e){this.#i(),this.#a(e)}getCurrentResult(){return this.#t}reset(){this.#n?.removeObserver(this),this.#n=void 0,this.#i(),this.#a()}mutate(e,t){return this.#r=t,this.#n?.removeObserver(this),this.#n=this.#e.getMutationCache().build(this.#e,this.options),this.#n.addObserver(this),this.#n.execute(e)}#i(){let e=this.#n?.state??Yr();this.#t={...e,isPending:e.status===`pending`,isSuccess:e.status===`success`,isError:e.status===`error`,isIdle:e.status===`idle`,mutate:this.mutate,reset:this.reset}}#a(e){wr.batch(()=>{if(this.#r&&this.hasListeners()){let t=this.#t.variables,n=this.#t.context,r={client:this.#e,meta:this.options.meta,mutationKey:this.options.mutationKey};if(e?.type===`success`){try{this.#r.onSuccess?.(e.data,t,n,r)}catch(e){Promise.reject(e)}try{this.#r.onSettled?.(e.data,null,t,n,r)}catch(e){Promise.reject(e)}}else if(e?.type===`error`){try{this.#r.onError?.(e.error,t,n,r)}catch(e){Promise.reject(e)}try{this.#r.onSettled?.(void 0,e.error,t,n,r)}catch(e){Promise.reject(e)}}}this.listeners.forEach(e=>{e(this.#t)})})}},$r=class extends Hn{constructor(e={}){super(),this.config=e,this.#e=new Map}#e;build(e,t,n){let r=t.queryKey,i=t.queryHash??nr(r,t),a=this.get(i);return a||(a=new jr({client:e,queryKey:r,queryHash:i,options:e.defaultQueryOptions(t),state:n,defaultOptions:e.getQueryDefaults(r)}),this.add(a)),a}add(e){this.#e.has(e.queryHash)||(this.#e.set(e.queryHash,e),this.notify({type:`added`,query:e}))}remove(e){let t=this.#e.get(e.queryHash);t&&(e.destroy(),t===e&&this.#e.delete(e.queryHash),this.notify({type:`removed`,query:e}))}clear(){wr.batch(()=>{this.getAll().forEach(e=>{this.remove(e)})})}get(e){return this.#e.get(e)}getAll(){return[...this.#e.values()]}find(e){let t={exact:!0,...e};return this.getAll().find(e=>er(t,e))}findAll(e={}){let t=this.getAll();return Object.keys(e).length>0?t.filter(t=>er(e,t)):t}notify(e){wr.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){wr.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){wr.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}},ei=class{#e;#t;#n;#r;#i;#a;#o;#s;constructor(e={}){this.#e=e.queryCache||new $r,this.#t=e.mutationCache||new Xr,this.#n=e.defaultOptions||{},this.#r=new Map,this.#i=new Map,this.#a=0}mount(){this.#a++,this.#a===1&&(this.#o=Un.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#s=Tr.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onOnline())}))}unmount(){this.#a--,this.#a===0&&(this.#o?.(),this.#o=void 0,this.#s?.(),this.#s=void 0)}isFetching(e){return this.#e.findAll({...e,fetchStatus:`fetching`}).length}isMutating(e){return this.#t.findAll({...e,status:`pending`}).length}getQueryData(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state.data}ensureQueryData(e){let t=this.defaultQueryOptions(e),n=this.#e.build(this,t),r=n.state.data;return r===void 0?this.fetchQuery(e):(e.revalidateIfStale&&n.isStaleByTime(Qn(t.staleTime,n))&&this.prefetchQuery(t),Promise.resolve(r))}getQueriesData(e){return this.#e.findAll(e).map(({queryKey:e,state:t})=>[e,t.data])}setQueryData(e,t,n){let r=this.defaultQueryOptions({queryKey:e}),i=this.#e.get(r.queryHash)?.state.data,a=Yn(t,i);if(a!==void 0)return this.#e.build(this,r).setData(a,{...n,manual:!0})}
11setQueriesData(e,t,n){return wr.batch(()=>this.#e.findAll(e).map(({queryKey:e})=>[e,this.setQueryData(e,t,n)]))}getQueryState(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state}removeQueries(e){let t=this.#e;wr.batch(()=>{t.findAll(e).forEach(e=>{t.remove(e)})})}resetQueries(e,t){let n=this.#e;return wr.batch(()=>(n.findAll(e).forEach(e=>{e.reset()}),this.refetchQueries({type:`active`,...e},t)))}cancelQueries(e,t={}){let n={revert:!0,...t},r=wr.batch(()=>this.#e.findAll(e).map(e=>e.cancel(n)));return Promise.all(r).then(Jn).catch(Jn)}invalidateQueries(e,t={}){return wr.batch(()=>(this.#e.findAll(e).forEach(e=>{e.invalidate()}),e?.refetchType===`none`?Promise.resolve():this.refetchQueries({...e,type:e?.refetchType??e?.type??`active`},t)))}refetchQueries(e,t={}){let n={...t,cancelRefetch:t.cancelRefetch??!0},r=wr.batch(()=>this.#e.findAll(e).filter(e=>!e.isDisabled()&&!e.isStatic()).map(e=>{let t=e.fetch(void 0,n);return n.throwOnError||(t=t.catch(Jn)),e.state.fetchStatus===`paused`?Promise.resolve():t}));return Promise.all(r).then(Jn)}fetchQuery(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let n=this.#e.build(this,t);return n.isStaleByTime(Qn(t.staleTime,n))?n.fetch(t):Promise.resolve(n.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(Jn).catch(Jn)}fetchInfiniteQuery(e){return e.behavior=Hr(e.pages),this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(Jn).catch(Jn)}ensureInfiniteQueryData(e){return e.behavior=Hr(e.pages),this.ensureQueryData(e)}resumePausedMutations(){return Tr.isOnline()?this.#t.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#e}getMutationCache(){return this.#t}getDefaultOptions(){return this.#n}setDefaultOptions(e){this.#n=e}setQueryDefaults(e,t){this.#r.set(rr(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){let t=[...this.#r.values()],n={};return t.forEach(t=>{ir(e,t.queryKey)&&Object.assign(n,t.defaultOptions)}),n}setMutationDefaults(e,t){this.#i.set(rr(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){let t=[...this.#i.values()],n={};return t.forEach(t=>{ir(e,t.mutationKey)&&Object.assign(n,t.defaultOptions)}),n}defaultQueryOptions(e){if(e._defaulted)return e;let t={...this.#n.queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||=nr(t.queryKey,t),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!==`always`),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode=`offlineFirst`),t.queryFn===gr&&(t.enabled=!1),t}defaultMutationOptions(e){return e?._defaulted?e:{...this.#n.mutations,...e?.mutationKey&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){this.#e.clear(),this.#t.clear()}},ti=o((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),L=o(((e,t)=>{t.exports=ti()}))(),ni=_.createContext(void 0),ri=e=>{let t=_.useContext(ni);if(e)return e;if(!t)throw Error(`No QueryClient set, use QueryClientProvider to set one`);return t},ii=({client:e,children:t})=>(_.useEffect(()=>(e.mount(),()=>{e.unmount()}),[e]),(0,L.jsx)(ni.Provider,{value:e,children:t})),ai=_.createContext(!1),oi=()=>_.useContext(ai);ai.Provider;function si(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var ci=_.createContext(si()),li=()=>_.useContext(ci),ui=(e,t,n)=>{let r=n?.state.error&&typeof e.throwOnError==`function`?vr(e.throwOnError,[n.state.error,n]):e.throwOnError;(e.suspense||e.experimental_prefetchInRender||r)&&(t.isReset()||(e.retryOnMount=!1))},di=e=>{_.useEffect(()=>{e.clearReset()},[e])},fi=({result:e,errorResetBoundary:t,throwOnError:n,query:r,suspense:i})=>e.isError&&!t.isReset()&&!e.isFetching&&r&&(i&&e.data===void 0||vr(n,[e.error,r])),pi=e=>{if(e.suspense){let t=1e3,n=e=>e===`static`?e:Math.max(e??t,t),r=e.staleTime;e.staleTime=typeof r==`function`?(...e)=>n(r(...e)):n(r),typeof e.gcTime==`number`&&(e.gcTime=Math.max(e.gcTime,t))}},mi=(e,t)=>e.isLoading&&e.isFetching&&!t,hi=(e,t)=>e?.suspense&&t.isPending,gi=(e,t,n)=>t.fetchOptimistic(e).catch(()=>{n.clearReset()});
11function _i(e,t,n){let r=oi(),i=li(),a=ri(n),o=a.defaultQueryOptions(e);a.getDefaultOptions().queries?._experimental_beforeQuery?.(o);let s=a.getQueryCache().get(o.queryHash);o._optimisticResults=r?`isRestoring`:`optimistic`,pi(o),ui(o,i,s),di(i);let c=!a.getQueryCache().get(o.queryHash),[l]=_.useState(()=>new t(a,o)),u=l.getOptimisticResult(o),d=!r&&e.subscribed!==!1;if(_.useSyncExternalStore(_.useCallback(e=>{let t=d?l.subscribe(wr.batchCalls(e)):Jn;return l.updateResult(),t},[l,d]),()=>l.getCurrentResult(),()=>l.getCurrentResult()),_.useEffect(()=>{l.setOptions(o)},[o,l]),hi(o,u))throw gi(o,l,i);if(fi({result:u,errorResetBoundary:i,throwOnError:o.throwOnError,query:s,suspense:o.suspense}))throw u.error;return a.getDefaultOptions().queries?._experimental_afterQuery?.(o,u),o.experimental_prefetchInRender&&!br.isServer()&&mi(u,r)&&(c?gi(o,l,i):s?.promise)?.catch(Jn).finally(()=>{l.updateResult()}),o.notifyOnChangeProps?u:l.trackResult(u)}function vi(e,t){return _i(e,Fr,t)}function R(e,t){let n=ri(t),[r]=_.useState(()=>new Qr(n,e));_.useEffect(()=>{r.setOptions(e)},[r,e]);let i=_.useSyncExternalStore(_.useCallback(e=>r.subscribe(wr.batchCalls(e)),[r]),()=>r.getCurrentResult(),()=>r.getCurrentResult()),a=_.useCallback((e,t)=>{r.mutate(e,t).catch(Jn)},[r]);if(i.error&&vr(r.options.throwOnError,[i.error]))throw i.error;return{...i,mutate:a,mutateAsync:i.mutate}}function yi(e,t){return _i(e,qr,t)}function bi(e){if(!e||typeof document>`u`)return;let t=document.head||document.getElementsByTagName(`head`)[0],n=document.createElement(`style`);n.type=`text/css`,t.appendChild(n),n.styleSheet?n.styleSheet.cssText=e:n.appendChild(document.createTextNode(e))}var xi=e=>{switch(e){case`success`:return wi;case`info`:return Ei;case`warning`:return Ti;case`error`:return Di;default:return null}},Si=Array(12).fill(0),Ci=({visible:e,className:t})=>_.createElement(`div`,{className:[`sonner-loading-wrapper`,t].filter(Boolean).join(` `),"data-visible":e},_.createElement(`div`,{className:`sonner-spinner`},Si.map((e,t)=>_.createElement(`div`,{className:`sonner-loading-bar`,key:`spinner-bar-${t}`})))),wi=_.createElement(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 20 20`,fill:`currentColor`,height:`20`,width:`20`},_.createElement(`path`,{fillRule:`evenodd`,d:`M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z`,clipRule:`evenodd`})),Ti=_.createElement(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`currentColor`,height:`20`,width:`20`},_.createElement(`path`,{fillRule:`evenodd`,d:`M9.401 3.003c1.155-2 4.043-2 5.197 0l7.355 12.748c1.154 2-.29 4.5-2.599 4.5H4.645c-2.309 0-3.752-2.5-2.598-4.5L9.4 3.003zM12 8.25a.75.75 0 01.75.75v3.75a.75.75 0 01-1.5 0V9a.75.75 0 01.75-.75zm0 8.25a.75.75 0 100-1.5.75.75 0 000 1.5z`,clipRule:`evenodd`})),Ei=_.createElement(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 20 20`,fill:`currentColor`,height:`20`,width:`20`},_.createElement(`path`,{fillRule:`evenodd`,d:`M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z`,clipRule:`evenodd`})),Di=_.createElement(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 20 20`,fill:`currentColor`,height:`20`,width:`20`},_.createElement(`path`,{fillRule:`evenodd`,d:`M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z`,clipRule:`evenodd`})),Oi=_.createElement(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`},_.createElement(`line`,{x1:`18`,y1:`6`,x2:`6`,y2:`18`}),_.createElement(`line`,{x1:`6`,y1:`6`,x2:`18`,y2:`18`})),ki=()=>{let[e,t]=_.useState(document.hidden);return _.useEffect(()=>{let e=()=>{t(document.hidden)};return document.addEventListener(`visibilitychange`,e),()=>window.removeEventListener(`visibilitychange`,e)},[]),e},Ai=1,ji=new class{constructor(){this.subscribe=e=>(this.subscribers.push(e),()=>{let t=this.subscribers.indexOf(e);this.subscribers.splice(t,1)}),this.publish=e=>
11{this.subscribers.forEach(t=>t(e))},this.addToast=e=>{this.publish(e),this.toasts=[...this.toasts,e]},this.create=e=>{let{message:t,...n}=e,r=typeof e?.id==`number`||e.id?.length>0?e.id:Ai++,i=this.toasts.find(e=>e.id===r),a=e.dismissible===void 0?!0:e.dismissible;return this.dismissedToasts.has(r)&&this.dismissedToasts.delete(r),i?this.toasts=this.toasts.map(n=>n.id===r?(this.publish({...n,...e,id:r,title:t}),{...n,...e,id:r,dismissible:a,title:t}):n):this.addToast({title:t,...n,dismissible:a,id:r}),r},this.dismiss=e=>(e?(this.dismissedToasts.add(e),requestAnimationFrame(()=>this.subscribers.forEach(t=>t({id:e,dismiss:!0})))):this.toasts.forEach(e=>{this.subscribers.forEach(t=>t({id:e.id,dismiss:!0}))}),e),this.message=(e,t)=>this.create({...t,message:e}),this.error=(e,t)=>this.create({...t,message:e,type:`error`}),this.success=(e,t)=>this.create({...t,type:`success`,message:e}),this.info=(e,t)=>this.create({...t,type:`info`,message:e}),this.warning=(e,t)=>this.create({...t,type:`warning`,message:e}),this.loading=(e,t)=>
11this.create({...t,type:`loading`,message:e}),this.promise=(e,t)=>{if(!t)return;let n;t.loading!==void 0&&(n=this.create({...t,promise:e,type:`loading`,message:t.loading,description:typeof t.description==`function`?void 0:t.description}));let r=Promise.resolve(e instanceof Function?e():e),i=n!==void 0,a,o=r.then(async e=>{if(a=[`resolve`,e],_.isValidElement(e))i=!1,this.create({id:n,type:`default`,message:e});else if(Ni(e)&&!e.ok){i=!1;let r=typeof t.error==`function`?await t.error(`HTTP error! status: ${e.status}`):t.error,a=typeof t.description==`function`?await t.description(`HTTP error! status: ${e.status}`):t.description,o=typeof r==`object`&&!_.isValidElement(r)?r:{message:r};this.create({id:n,type:`error`,description:a,...o})}else if(e instanceof Error){i=!1;let r=typeof t.error==`function`?await t.error(e):t.error,a=typeof t.description==`function`?await t.description(e):t.description,o=typeof r==`object`&&!_.isValidElement(r)?r:{message:r};this.create({id:n,type:`error`,description:a,...o})}else if(t.success!==void 0){i=!1;let r=typeof t.success==`function`?await t.success(e):t.success,a=typeof t.description==`function`?await t.description(e):t.description,o=typeof r==`object`&&!_.isValidElement(r)?r:{message:r};this.create({id:n,type:`success`,description:a,...o})}}).catch(async e=>{if(a=[`reject`,e],t.error!==void 0){i=!1;let r=typeof t.error==`function`?await t.error(e):t.error,a=typeof t.description==`function`?await t.description(e):t.description,o=typeof r==`object`&&!_.isValidElement(r)?r:{message:r};this.create({id:n,type:`error`,description:a,...o})}}).finally(()=>{i&&(this.dismiss(n),n=void 0),t.finally==null||t.finally.call(t)}),s=()=>new Promise((e,t)=>o.then(()=>a[0]===`reject`?t(a[1]):e(a[1])).catch(t));return typeof n!=`string`&&typeof n!=`number`?{unwrap:s}:Object.assign(n,{unwrap:s})},this.custom=(e,t)=>{let n=t?.id||Ai++;return this.create({jsx:e(n),id:n,...t}),n},this.getActiveToasts=()=>this.toasts.filter(e=>!this.dismissedToasts.has(e.id)),this.subscribers=[],this.toasts=[],this.dismissedToasts=new Set}},Mi=(e,t)=>{let n=t?.id||Ai++;return ji.addToast({title:e,...t,id:n}),n},Ni=e=>e&&typeof e==`object`&&`ok`in e&&typeof e.ok==`boolean`&&`status`in e&&typeof e.status==`number`,Pi=Mi,z=Object.assign(Pi,{success:ji.success,info:ji.info,warning:ji.warning,error:ji.error,custom:ji.custom,message:ji.message,promise:ji.promise,dismiss:ji.dismiss,loading:ji.loading},{getHistory:()=>ji.toasts,getToasts:()=>ji.getActiveToasts()});bi(`
vendor: 14,859 bytes, line 11
11[data-sonner-toaster][dir=ltr],html[dir=ltr]{--toast-icon-margin-start:-3px;--toast-icon-margin-end:4px;--toast-svg-margin-start:-1px;--toast-svg-margin-end:0px;--toast-button-margin-start:auto;--toast-button-margin-end:0;--toast-close-button-start:0;--toast-close-button-end:unset;--toast-close-button-transform:translate(-35%, -35%)}[data-sonner-toaster][dir=rtl],html[dir=rtl]{--toast-icon-margin-start:4px;--toast-icon-margin-end:-3px;--toast-svg-margin-start:0px;--toast-svg-margin-end:-1px;--toast-button-margin-start:0;--toast-button-margin-end:auto;--toast-close-button-start:unset;--toast-close-button-end:0;--toast-close-button-transform:translate(35%, -35%)}[data-sonner-toaster]{position:fixed;width:var(--width);font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;--gray1:hsl(0, 0%, 99%);--gray2:hsl(0, 0%, 97.3%);--gray3:hsl(0, 0%, 95.1%);--gray4:hsl(0, 0%, 93%);--gray5:hsl(0, 0%, 90.9%);--gray6:hsl(0, 0%, 88.7%);--gray7:hsl(0, 0%, 85.8%);--gray8:hsl(0, 0%, 78%);--gray9:hsl(0, 0%, 56.1%);--gray10:hsl(0, 0%, 52.3%);--gray11:hsl(0, 0%, 43.5%);--gray12:hsl(0, 0%, 9%);--border-radius:8px;box-sizing:border-box;padding:0;margin:0;list-style:none;outline:0;z-index:999999999;transition:transform .4s ease}@media (hover:none) and (pointer:coarse){[data-sonner-toaster][data-lifted=true]{transform:none}}[data-sonner-toaster][data-x-position=right]{right:var(--offset-right)}[data-sonner-toaster][data-x-position=left]{left:var(--offset-left)}[data-sonner-toaster][data-x-position=center]{left:50%;transform:translateX(-50%)}[data-sonner-toaster][data-y-position=top]{top:var(--offset-top)}[data-sonner-toaster][data-y-position=bottom]{bottom:var(--offset-bottom)}[data-sonner-toast]{--y:translateY(100%);--lift-amount:calc(var(--lift) * var(--gap));z-index:var(--z-index);position:absolute;opacity:0;transform:var(--y);touch-action:none;transition:transform .4s,opacity .4s,height .4s,box-shadow .2s;box-sizing:border-box;outline:0;overflow-wrap:anywhere}[data-sonner-toast][data-styled=true]{padding:16px;background:var(--normal-bg);border:1px solid var(--normal-border);color:var(--normal-text);border-radius:var(--border-radius);box-shadow:0 4px 12px rgba(0,0,0,.1);width:var(--width);font-size:13px;display:flex;align-items:center;gap:6px}[data-sonner-toast]:focus-visible{box-shadow:0 4px 12px rgba(0,0,0,.1),0 0 0 2px rgba(0,0,0,.2)}[data-sonner-toast][data-y-position=top]{top:0;--y:translateY(-100%);--lift:1;--lift-amount:calc(1 * var(--gap))}[data-sonner-toast][data-y-position=bottom]{bottom:0;--y:translateY(100%);--lift:-1;--lift-amount:calc(var(--lift) * var(--gap))}[data-sonner-toast][data-styled=true] [data-description]{font-weight:400;line-height:1.4;color:#3f3f3f}[data-rich-colors=true][data-sonner-toast][data-styled=true] [data-description]{color:inherit}[data-sonner-toaster][data-sonner-theme=dark] [data-description]{color:#e8e8e8}[data-sonner-toast][data-styled=true] [data-title]{font-weight:500;line-height:1.5;color:inherit}[data-sonner-toast][data-styled=true] [data-icon]{display:flex;height:16px;width:16px;position:relative;justify-content:flex-start;align-items:center;flex-shrink:0;margin-left:var(--toast-icon-margin-start);margin-right:var(--toast-icon-margin-end)}[data-sonner-toast][data-promise=true] [data-icon]>svg{opacity:0;transform:scale(.8);transform-origin:center;animation:sonner-fade-in .3s ease forwards}[data-sonner-toast][data-styled=true] [data-icon]>*{flex-shrink:0}[data-sonner-toast][data-styled=true] [data-icon] svg{margin-left:var(--toast-svg-margin-start);margin-right:var(--toast-svg-margin-end)}[data-sonner-toast][data-styled=true] [data-content]{display:flex;flex-direction:column;gap:2px}[data-sonner-toast][data-styled=true] [data-button]{border-radius:4px;padding-left:8px;padding-right:8px;height:24px;font-size:12px;color:var(--normal-bg);background:var(--normal-text);margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end);border:none;font-weight:500;cursor:pointer;outline:0;display:flex;align-items:center;flex-shrink:0;transition:opacity .4s,box-shadow .2s}[data-sonner-toast][data-styled=true] [data-button]:focus-visible{box-shadow:0 0 0 2px rgba(0,0,0,.4)}[data-sonner-toast][data-styled=true] [data-button]:first-of-type{margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end)}[data-sonner-toast][data-styled=true] [data-cancel]{color:var(--normal-text);background:rgba(0,0,0,.08)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast][data-styled=true] [data-cancel]{background:rgba(255,255,255,.3)}[data-sonner-toast][data-styled=true] [data-close-button]{position:absolute;left:var(--toast-close-button-start);right:var(--toast-close-button-end);top:0;height:20px;width:20px;display:flex;justify-content:center;align-items:center;padding:0;color:var(--gray12);background:var(--normal-bg);border:1px solid var(--gray4);transform:var(--toast-close-button-transform);border-radius:50%;cursor:pointer;z-index:1;transition:opacity .1s,background .2s,border-color .2s}[data-sonner-toast][data-styled=true] [data-close-button]:focus-visible{box-shadow:0 4px 12px rgba(0,0,0,.1),0 0 0 2px rgba(0,0,0,.2)}[data-sonner-toast][data-styled=true] [data-disabled=true]{cursor:not-allowed}[data-sonner-toast][data-styled=true]:hover [data-close-button]:hover{background:var(--gray2);border-color:var(--gray5)}[data-sonner-toast][data-swiping=true]::before{content:'';position:absolute;left:-100%;right:-100%;height:100%;z-index:-1}[data-sonner-toast][data-y-position=top][data-swiping=true]::before{bottom:50%;transform:scaleY(3) translateY(50%)}[data-sonner-toast][data-y-position=bottom][data-swiping=true]::before{top:50%;transform:scaleY(3) translateY(-50%)}[data-sonner-toast][data-swiping=false][data-removed=true]::before{content:'';position:absolute;inset:0;transform:scaleY(2)}[data-sonner-toast][data-expanded=true]::after{content:'';position:absolute;left:0;height:calc(var(--gap) + 1px);bottom:100%;width:100%}[data-sonner-toast][data-mounted=true]{--y:translateY(0);opacity:1}[data-sonner-toast][data-expanded=false][data-front=false]{--scale:var(--toasts-before) * 0.05 + 1;--y:translateY(calc(var(--lift-amount) * var(--toasts-before))) scale(calc(-1 * var(--scale)));height:var(--front-toast-height)}[data-sonner-toast]>*{transition:opacity .4s}[data-sonner-toast][data-x-position=right]{right:0}[data-sonner-toast][data-x-position=left]{left:0}[data-sonner-toast][data-expanded=false][data-front=false][data-styled=true]>*{opacity:0}[data-sonner-toast][data-visible=false]{opacity:0;pointer-events:none}[data-sonner-toast][data-mounted=true][data-expanded=true]{--y:translateY(calc(var(--lift) * var(--offset)));height:var(--initial-height)}[data-sonner-toast][data-removed=true][data-front=true][data-swipe-out=false]{--y:translateY(calc(var(--lift) * -100%));opacity:0}[data-sonner-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=true]{--y:translateY(calc(var(--lift) * var(--offset) + var(--lift) * -100%));opacity:0}[data-sonner-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=false]{--y:translateY(40%);opacity:0;transition:transform .5s,opacity .2s}[data-sonner-toast][data-removed=true][data-front=false]::before{height:calc(var(--initial-height) + 20%)}[data-sonner-toast][data-swiping=true]{transform:var(--y) translateY(var(--swipe-amount-y,0)) translateX(var(--swipe-amount-x,0));transition:none}[data-sonner-toast][data-swiped=true]{user-select:none}[data-sonner-toast][data-swipe-out=true][data-y-position=bottom],[data-sonner-toast][data-swipe-out=true][data-y-position=top]{animation-duration:.2s;animation-timing-function:ease-out;animation-fill-mode:forwards}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=left]{animation-name:swipe-out-left}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=right]{animation-name:swipe-out-right}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=up]{animation-name:swipe-out-up}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=down]{animation-name:swipe-out-down}@keyframes swipe-out-left{from{transform:var(--y) translateX(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translateX(calc(var(--swipe-amount-x) - 100%));opacity:0}}@keyframes swipe-out-right{from{transform:var(--y) translateX(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translateX(calc(var(--swipe-amount-x) + 100%));opacity:0}}@keyframes swipe-out-up{from{transform:var(--y) translateY(var(--swipe-amount-y));opacity:1}to{transform:var(--y) translateY(calc(var(--swipe-amount-y) - 100%));opacity:0}}@keyframes swipe-out-down{from{transform:var(--y) translateY(var(--swipe-amount-y));opacity:1}to{transform:var(--y) translateY(calc(var(--swipe-amount-y) + 100%));opacity:0}}@media (max-width:600px){[data-sonner-toaster]{position:fixed;right:var(--mobile-offset-right);left:var(--mobile-offset-left);width:100%}[data-sonner-toaster][dir=rtl]{left:calc(var(--mobile-offset-left) * -1)}[data-sonner-toaster] [data-sonner-toast]{left:0;right:0;width:calc(100% - var(--mobile-offset-left) * 2)}[data-sonner-toaster][data-x-position=left]{left:var(--mobile-offset-left)}[data-sonner-toaster][data-y-position=bottom]{bottom:var(--mobile-offset-bottom)}[data-sonner-toaster][data-y-position=top]{top:var(--mobile-offset-top)}[data-sonner-toaster][data-x-position=center]{left:var(--mobile-offset-left);right:var(--mobile-offset-right);transform:none}}[data-sonner-toaster][data-sonner-theme=light]{--normal-bg:#fff;--normal-border:var(--gray4);--normal-text:var(--gray12);--success-bg:hsl(143, 85%, 96%);--success-border:hsl(145, 92%, 87%);--success-text:hsl(140, 100%, 27%);--info-bg:hsl(208, 100%, 97%);--info-border:hsl(221, 91%, 93%);--info-text:hsl(210, 92%, 45%);--warning-bg:hsl(49, 100%, 97%);--warning-border:hsl(49, 91%, 84%);--warning-text:hsl(31, 92%, 45%);--error-bg:hsl(359, 100%, 97%);--error-border:hsl(359, 100%, 94%);--error-text:hsl(360, 100%, 45%)}[data-sonner-toaster][data-sonner-theme=light] [data-sonner-toast][data-invert=true]{--normal-bg:#000;--normal-border:hsl(0, 0%, 20%);--normal-text:var(--gray1)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast][data-invert=true]{--normal-bg:#fff;--normal-border:var(--gray3);--normal-text:var(--gray12)}[data-sonner-toaster][data-sonner-theme=dark]{--normal-bg:#000;--normal-bg-hover:hsl(0, 0%, 12%);--normal-border:hsl(0, 0%, 20%);--normal-border-hover:hsl(0, 0%, 25%);--normal-text:var(--gray1);--success-bg:hsl(150, 100%, 6%);--success-border:hsl(147, 100%, 12%);--success-text:hsl(150, 86%, 65%);--info-bg:hsl(215, 100%, 6%);--info-border:hsl(223, 43%, 17%);--info-text:hsl(216, 87%, 65%);--warning-bg:hsl(64, 100%, 6%);--warning-border:hsl(60, 100%, 9%);--warning-text:hsl(46, 87%, 65%);--error-bg:hsl(358, 76%, 10%);--error-border:hsl(357, 89%, 16%);--error-text:hsl(358, 100%, 81%)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast] [data-close-button]{background:var(--normal-bg);border-color:var(--normal-border);color:var(--normal-text)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast] [data-close-button]:hover{background:var(--normal-bg-hover);border-color:var(--normal-border-hover)}[data-rich-colors=true][data-sonner-toast][data-type=success]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}[data-rich-colors=true][data-sonner-toast][data-type=success] [data-close-button]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}[data-rich-colors=true][data-sonner-toast][data-type=info]{background:var(--info-bg);border-color:var(--info-border);color:var(--info-text)}[data-rich-colors=true][data-sonner-toast][data-type=info] [data-close-button]{background:var(--info-bg);border-color:var(--info-border);color:var(--info-text)}[data-rich-colors=true][data-sonner-toast][data-type=warning]{background:var(--warning-bg);border-color:var(--warning-border);color:var(--warning-text)}[data-rich-colors=true][data-sonner-toast][data-type=warning] [data-close-button]{background:var(--warning-bg);border-color:var(--warning-border);color:var(--warning-text)}[data-rich-colors=true][data-sonner-toast][data-type=error]{background:var(--error-bg);border-color:var(--error-border);color:var(--error-text)}[data-rich-colors=true][data-sonner-toast][data-type=error] [data-close-button]{background:var(--error-bg);border-color:var(--error-border);color:var(--error-text)}.sonner-loading-wrapper{--size:16px;height:var(--size);width:var(--size);position:absolute;inset:0;z-index:10}.sonner-loading-wrapper[data-visible=false]{transform-origin:center;animation:sonner-fade-out .2s ease forwards}.sonner-spinner{position:relative;top:50%;left:50%;height:var(--size);width:var(--size)}.sonner-loading-bar{animation:sonner-spin 1.2s linear infinite;background:var(--gray11);border-radius:6px;height:8%;left:-10%;position:absolute;top:-3.9%;width:24%}.sonner-loading-bar:first-child{animation-delay:-1.2s;transform:rotate(.0001deg) translate(146%)}.sonner-loading-bar:nth-child(2){animation-delay:-1.1s;transform:rotate(30deg) translate(146%)}.sonner-loading-bar:nth-child(3){animation-delay:-1s;transform:rotate(60deg) translate(146%)}.sonner-loading-bar:nth-child(4){animation-delay:-.9s;transform:rotate(90deg) translate(146%)}.sonner-loading-bar:nth-child(5){animation-delay:-.8s;transform:rotate(120deg) translate(146%)}.sonner-loading-bar:nth-child(6){animation-delay:-.7s;transform:rotate(150deg) translate(146%)}.sonner-loading-bar:nth-child(7){animation-delay:-.6s;transform:rotate(180deg) translate(146%)}.sonner-loading-bar:nth-child(8){animation-delay:-.5s;transform:rotate(210deg) translate(146%)}.sonner-loading-bar:nth-child(9){animation-delay:-.4s;transform:rotate(240deg) translate(146%)}.sonner-loading-bar:nth-child(10){animation-delay:-.3s;transform:rotate(270deg) translate(146%)}.sonner-loading-bar:nth-child(11){animation-delay:-.2s;transform:rotate(300deg) translate(146%)}.sonner-loading-bar:nth-child(12){animation-delay:-.1s;transform:rotate(330deg) translate(146%)}@keyframes sonner-fade-in{0%{opacity:0;transform:scale(.8)}100%{opacity:1;transform:scale(1)}}@keyframes sonner-fade-out{0%{opacity:1;transform:scale(1)}100%{opacity:0;transform:scale(.8)}}@keyframes sonner-spin{0%{opacity:1}100%{opacity:.15}}@media (prefers-reduced-motion){.sonner-loading-bar,[data-sonner-toast],[data-sonner-toast]>*{transition:none!important;animation:none!important}}.sonner-loader{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);transform-origin:center;transition:opacity .2s,transform .2s}.sonner-loader[data-visible=false]{opacity:0;transform:scale(.8) translate(-50%,-50%)}
11`);function Fi(e){return e.label!==void 0}var Ii=3,Li=`24px`,Ri=`16px`,zi=4e3,Bi=356,Vi=14,Hi=45,Ui=200;function Wi(...e){return e.filter(Boolean).join(` `)}function Gi(e){let[t,n]=e.split(`-`),r=[];return t&&r.push(t),n&&r.push(n),r}var Ki=e=>{let{invert:t,toast:n,unstyled:r,interacting:i,setHeights:a,visibleToasts:o,heights:s,index:c,toasts:l,expanded:u,removeToast:d,defaultRichColors:f,closeButton:p,style:m,cancelButtonStyle:h,actionButtonStyle:g,className:v=``,descriptionClassName:y=``,duration:b,position:x,gap:S,expandByDefault:C,classNames:w,icons:T,closeButtonAriaLabel:E=`Close toast`}=e,[D,O]=_.useState(null),[k,A]=_.useState(null),[j,M]=_.useState(!1),[ee,N]=_.useState(!1),[P,F]=_.useState(!1),[I,te]=_.useState(!1),[ne,re]=_.useState(!1),[ie,ae]=_.useState(0),[oe,se]=_.useState(0),ce=_.useRef(n.duration||b||zi),le=_.useRef(null),ue=_.useRef(null),de=c===0,fe=c+1<=o,pe=n.type,me=n.dismissible!==!1,he=n.className||``,ge=n.descriptionClassName||``,_e=_.useMemo(()=>s.findIndex(e=>e.toastId===n.id)||0,[s,n.id]),ve=_.useMemo(()=>n.closeButton??p,[n.closeButton,p]),ye=_.useMemo(()=>n.duration||b||zi,[n.duration,b]),be=_.useRef(0),xe=_.useRef(0),Se=_.useRef(0),Ce=_.useRef(null),[we,Te]=x.split(`-`),Ee=_.useMemo(()=>
11s.reduce((e,t,n)=>n>=_e?e:e+t.height,0),[s,_e]),De=ki(),Oe=n.invert||t,ke=pe===`loading`;xe.current=_.useMemo(()=>_e*S+Ee,[_e,Ee]),_.useEffect(()=>{ce.current=ye},[ye]),_.useEffect(()=>{M(!0)},[]),_.useEffect(()=>{let e=ue.current;if(e){let t=e.getBoundingClientRect().height;return se(t),a(e=>[{toastId:n.id,height:t,position:n.position},...e]),()=>a(e=>e.filter(e=>e.toastId!==n.id))}},[a,n.id]),_.useLayoutEffect(()=>{if(!j)return;let e=ue.current,t=e.style.height;e.style.height=`auto`;let r=e.getBoundingClientRect().height;e.style.height=t,se(r),a(e=>e.find(e=>e.toastId===n.id)?e.map(e=>e.toastId===n.id?{...e,height:r}:e):[{toastId:n.id,height:r,position:n.position},...e])},[j,n.title,n.description,a,n.id,n.jsx,n.action,n.cancel]);let Ae=_.useCallback(()=>{N(!0),ae(xe.current),a(e=>e.filter(e=>e.toastId!==n.id)),setTimeout(()=>{d(n)},Ui)},[n,d,a,xe]);_.useEffect(()=>{if(n.promise&&pe===`loading`||n.duration===1/0||n.type===`loading`)return;let e;return u||i||De?(()=>{if(Se.current<be.current){let e=new Date().getTime()-be.current;ce.current-=e}Se.current=new Date().getTime()})():ce.current!==1/0&&(be.current=new Date().getTime(),e=setTimeout(()=>{n.onAutoClose==null||n.onAutoClose.call(n,n),Ae()},ce.current)),()=>clearTimeout(e)},[u,i,n,pe,De,Ae]),_.useEffect(()=>{n.delete&&(Ae(),n.onDismiss==null||n.onDismiss.call(n,n))},[Ae,n.delete]);function je(){return T?.loading?_.createElement(`div`,{className:Wi(w?.loader,n?.classNames?.loader,`sonner-loader`),"data-visible":pe===`loading`},T.loading):_.createElement(Ci,{className:Wi(w?.loader,n?.classNames?.loader),visible:pe===`loading`})}let Me=n.icon||T?.[pe]||xi(pe);return _.createElement(`li`,{tabIndex:0,ref:ue,className:Wi(v,he,w?.toast,n?.classNames?.toast,w?.default,w?.[pe],n?.classNames?.[pe]),"data-sonner-toast":``,"data-rich-colors":n.richColors??f,"data-styled":!(n.jsx||n.unstyled||r),"data-mounted":j,"data-promise":!!n.promise,"data-swiped":ne,"data-removed":ee,"data-visible":fe,"data-y-position":we,"data-x-position":Te,"data-index":c,"data-front":de,"data-swiping":P,"data-dismissible":me,"data-type":pe,"data-invert":Oe,"data-swipe-out":I,"data-swipe-direction":k,"data-expanded":!!(u||C&&j),"data-testid":n.testId,style:{"--index":c,"--toasts-before":c,"--z-index":l.length-c,"--offset":`${ee?ie:xe.current}px`,"--initial-height":C?`auto`:`${oe}px`,...m,...n.style},onDragEnd:()=>{F(!1),O(null),Ce.current=null},onPointerDown:e=>{e.button!==2&&(ke||!me||(le.current=new Date,ae(xe.current),e.target.setPointerCapture(e.pointerId),e.target.tagName!==`BUTTON`&&(F(!0),Ce.current={x:e.clientX,y:e.clientY})))},onPointerUp:()=>{if(I||!me)return;Ce.current=null;let e=Number(ue.current?.style.getPropertyValue(`--swipe-amount-x`).replace(`px`,``)||0),t=Number(ue.current?.style.getPropertyValue(`--swipe-amount-y`).replace(`px`,``)||0),r=new Date().getTime()-le.current?.getTime(),i=D===`x`?e:t,a=Math.abs(i)/r;if(Math.abs(i)>=Hi||a>.11){ae(xe.current),n.onDismiss==null||n.onDismiss.call(n,n),A(D===`x`?e>0?`right`:`left`:t>0?`down`:`up`),Ae(),te(!0);return}else{var o,s;(o=ue.current)==null||o.style.setProperty(`--swipe-amount-x`,`0px`),(s=ue.current)==null||s.style.setProperty(`--swipe-amount-y`,`0px`)}re(!1),F(!1),O(null)},onPointerMove:t=>{var n,r;if(!Ce.current||!me||window.getSelection()?.toString().length>0)return;let i=t.clientY-Ce.current.y,a=t.clientX-Ce.current.x,o=e.swipeDirections??Gi(x);!D&&(Math.abs(a)>1||Math.abs(i)>1)&&O(Math.abs(a)>Math.abs(i)?`x`:`y`);let s={x:0,y:0},c=e=>1/(1.5+Math.abs(e)/20);if(D===`y`){if(o.includes(`top`)||o.includes(`bottom`))if(o.includes(`top`)&&i<0||o.includes(`bottom`)&&i>0)s.y=i;else{let e=i*c(i);s.y=Math.abs(e)<Math.abs(i)?e:i}}else if(D===`x`&&(o.includes(`left`)||o.includes(`right`)))if(o.includes(`left`)&&a<0||o.includes(`right`)&&a>0)s.x=a;else{let e=a*c(a);s.x=Math.abs(e)<Math.abs(a)?e:a}(Math.abs(s.x)>0||Math.abs(s.y)>0)&&re(!0),(n=ue.current)==null||n.style.setProperty(`--swipe-amount-x`,`${s.x}px`),(r=ue.current)==null||r.style.setProperty(`--swipe-amount-y`,`${s.y}px`)}},ve&&!n.jsx&&pe!==`loading`?_.createElement(`button`,{"aria-label":E,"data-disabled":ke,"data-close-button":!0,onClick:ke||!me?()=>{}:()=>{Ae(),n.onDismiss==null||n.onDismiss.call(n,n)},className:Wi(w?.closeButton,n?.classNames?.closeButton)},T?.close??Oi):null,(pe||n.icon||n.promise)&&n.icon!==null&&(T?.[pe]!==null||n.icon)?_.createElement(`div`,{"data-icon":``,className:Wi(w?.icon,n?.classNames?.icon)},n.promise||n.type===`loading`&&!n.icon?n.icon||je():null,n.type===`loading`?null:Me):null,_.createElement(`div`,{"data-content":``,className:Wi(w?.content,n?.classNames?.content)},_.createElement(`div`,{"data-title":``,className:Wi(w?.title,n?.classNames?.title)},n.jsx?n.jsx:typeof n.title==`function`?n.title():n.title),n.description?_.createElement(`div`,{"data-description":``,className:Wi(y,ge,w?.description,n?.classNames?.description)},typeof n.description==`function`?n.description():n.description):null),_.isValidElement(n.cancel)?n.c
11ancel:n.cancel&&Fi(n.cancel)?_.createElement(`button`,{"data-button":!0,"data-cancel":!0,style:n.cancelButtonStyle||h,onClick:e=>{Fi(n.cancel)&&me&&(n.cancel.onClick==null||n.cancel.onClick.call(n.cancel,e),Ae())},className:Wi(w?.cancelButton,n?.classNames?.cancelButton)},n.cancel.label):null,_.isValidElement(n.action)?n.action:n.action&&Fi(n.action)?_.createElement(`button`,{"data-button":!0,"data-action":!0,style:n.actionButtonStyle||g,onClick:e=>{Fi(n.action)&&(n.action.onClick==null||n.action.onClick.call(n.action,e),!e.defaultPrevented&&Ae())},className:Wi(w?.actionButton,n?.classNames?.actionButton)},n.action.label):null)};function qi(){if(typeof window>`u`||typeof document>`u`)return`ltr`;let e=document.documentElement.getAttribute(`dir`);return e===`auto`||!e?window.getComputedStyle(document.documentElement).direction:e}function Ji(e,t){let n={};return[e,t].forEach((e,t)=>{let r=t===1,i=r?`--mobile-offset`:`--offset`,a=r?Ri:Li;function o(e){[`top`,`right`,`bottom`,`left`].forEach(t=>{n[`${i}-${t}`]=typeof e==`number`?`${e}px`:e})}typeof e==`number`||typeof e==`string`?o(e):typeof e==`object`?[`top`,`right`,`bottom`,`left`].forEach(t=>{e[t]===void 0?n[`${i}-${t}`]=a:n[`${i}-${t}`]=typeof e[t]==`number`?`${e[t]}px`:e[t]}):o(a)}),n}var Yi=_.forwardRef(function(e,t){let{id:n,invert:r,position:i=`bottom-right`,hotkey:a=[`altKey`,`KeyT`],expand:o,closeButton:s,className:c,offset:l,mobileOffset:u,theme:d=`light`,richColors:f,duration:p,style:m,visibleToasts:h=Ii,toastOptions:g,dir:y=qi(),gap:b=Vi,icons:x,containerAriaLabel:S=`Notifications`}=e,[C,w]=_.useState([]),T=_.useMemo(()=>n?C.filter(e=>e.toasterId===n):C.filter(e=>!e.toasterId),[C,n]),E=_.useMemo(()=>Array.from(new Set([i].concat(T.filter(e=>e.position).map(e=>e.position)))),[T,i]),[D,O]=_.useState([]),[k,A]=_.useState(!1),[j,M]=_.useState(!1),[ee,N]=_.useState(d===`system`?typeof window<`u`&&window.matchMedia&&window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`:d),P=_.useRef(null),F=a.join(`+`).replace(/Key/g,``).replace(/Digit/g,``),I=_.useRef(null),te=_.useRef(!1),ne=_.useCallback(e=>{w(t=>(t.find(t=>t.id===e.id)?.delete||ji.dismiss(e.id),t.filter(({id:t})=>t!==e.id)))},[]);return _.useEffect(()=>ji.subscribe(e=>{if(e.dismiss){requestAnimationFrame(()=>{w(t=>t.map(t=>t.id===e.id?{...t,delete:!0}:t))});return}setTimeout(()=>{v.flushSync(()=>{w(t=>{let n=t.findIndex(t=>t.id===e.id);return n===-1?[e,...t]:[...t.slice(0,n),{...t[n],...e},...t.slice(n+1)]})})})}),[C]),_.useEffect(()=>{if(d!==`system`){N(d);return}if(d===`system`&&(window.matchMedia&&window.matchMedia(`(prefers-color-scheme: dark)`).matches?N(`dark`):N(`light`)),typeof window>`u`)return;let e=window.matchMedia(`(prefers-color-scheme: dark)`);try{e.addEventListener(`change`,({matches:e})=>{N(e?`dark`:`light`)})}catch{e.addListener(({matches:e})=>{try{N(e?`dark`:`light`)}catch(e){console.error(e)}})}},[d]),_.useEffect(()=>{C.length<=1&&A(!1)},[C]),_.useEffect(()=>{let e=e=>{if(a.every(t=>e[t]||e.code===t)){var t;A(!0),(t=P.current)==null||t.focus()}e.code===`Escape`&&(document.activeElement===P.current||P.current?.contains(document.activeElement))&&A(!1)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[a]),_.useEffect(()=>{if(P.current)return()=>{I.current&&(I.current.focus({preventScroll:!0}),I.current=null,te.current=!1)}},[P.current]),_.createElement(`section`,{ref:t,"aria-label":`${S} ${F}`,tabIndex:-1,"aria-live":`polite`,"aria-relevant":`additions text`,"aria-atomic":`false`,suppressHydrationWarning:!0},E.map((t,n)=>{let[i,a]=t.split(`-`);return T.length?_.createElement(`ol`,{key:t,dir:y===`auto`?qi():y,tabIndex:-1,ref:P,className:c,"data-sonner-toaster":!0,"data-sonner-theme":ee,"data-y-position":i,"data-x-position":a,style:{"--front-toast-height":`${D[0]?.height||0}px`,"--width":`${Bi}px`,"--gap":`${b}px`,...m,...Ji(l,u)},onBlur:e=>{te.current&&!e.currentTarget.contains(e.relatedTarget)&&(te.current=!1,I.current&&=(I.current.focus({preventScroll:!0}),null))},onFocus:e=>{e.target instanceof HTMLElement&&e.target.dataset.dismissible===`fal
11se`||te.current||(te.current=!0,I.current=e.relatedTarget)},onMouseEnter:()=>A(!0),onMouseMove:()=>A(!0),onMouseLeave:()=>{j||A(!1)},onDragEnd:()=>A(!1),onPointerDown:e=>{e.target instanceof HTMLElement&&e.target.dataset.dismissible===`false`||M(!0)},onPointerUp:()=>M(!1)},T.filter(e=>!e.position&&n===0||e.position===t).map((n,i)=>_.createElement(Ki,{key:n.id,icons:x,index:i,toast:n,defaultRichColors:f,duration:g?.duration??p,className:g?.className,descriptionClassName:g?.descriptionClassName,invert:r,visibleToasts:h,closeButton:g?.closeButton??s,interacting:j,position:t,style:g?.style,unstyled:g?.unstyled,classNames:g?.classNames,cancelButtonStyle:g?.cancelButtonStyle,actionButtonStyle:g?.actionButtonStyle,closeButtonAriaLabel:g?.closeButtonAriaLabel,removeToast:ne,toasts:T.filter(e=>e.position==n.position),heights:D.filter(e=>e.position==n.position),setHeights:O,expandByDefault:o,gap:b,expanded:k,swipeDirections:e.swipeDirections}))):null}))});function Xi(e,t){if(typeof e==`function`)return e(t);e!=null&&(e.current=t)}function Zi(...e){return t=>{let n=!1,r=e.map(e=>{let r=Xi(e,t);return!n&&typeof r==`function`&&(n=!0),r});if(n)return()=>{for(let t=0;t<r.length;t++){let n=r[t];typeof n==`function`?n():Xi(e[t],null)}}}}function Qi(...e){return _.useCallback(Zi(...e),e)}function $i(e){let t=ta(e),n=_.forwardRef((e,n)=>{let{children:r,...i}=e,a=_.Children.toArray(r),o=a.find(ia);if(o){let e=o.props.children,r=a.map(t=>t===o?_.Children.count(e)>1?_.Children.only(null):_.isValidElement(e)?e.props.children:null:t);return(0,L.jsx)(t,{...i,ref:n,children:_.isValidElement(e)?_.cloneElement(e,void 0,r):null})}return(0,L.jsx)(t,{...i,ref:n,children:r})});return n.displayName=`${e}.Slot`,n}var ea=$i(`Slot`);function ta(e){let t=_.forwardRef((e,t)=>{let{children:n,...r}=e;if(_.isValidElement(n)){let e=oa(n),i=aa(r,n.props);return n.type!==_.Fragment&&(i.ref=t?Zi(t,e):e),_.cloneElement(n,i)}return _.Children.count(n)>1?_.Children.only(null):null});return t.displayName=`${e}.SlotClone`,t}var na=Symbol(`radix.slottable`);function ra(e){let t=({children:e})=>(0,L.jsx)(L.Fragment,{children:e});return t.displayName=`${e}.Slottable`,t.__radixId=na,t}function ia(e){return _.isValidElement(e)&&typeof e.type==`function`&&`__radixId`in e.type&&e.type.__radixId===na}function aa(e,t){let n={...t};for(let r in t){let i=e[r],a=t[r];/^on[A-Z]/.test(r)?i&&a?n[r]=(...e)=>{let t=a(...e);return i(...e),t}:i&&(n[r]=i):r===`style`?n[r]={...i,...a}:r===`className`&&(n[r]=[i,a].filter(Boolean).join(` `))}return{...e,...n}}function oa(e){let t=Object.getOwnPropertyDescriptor(e.props,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var sa=[`a`,`button`,`div`,`form`,`h2`,`h3`,`img`,`input`,`label`,`li`,`nav`,`ol`,`p`,`select`,`span`,`svg`,`ul`].reduce((e,t)=>{let n=$i(`Primitive.${t}`),r=_.forwardRef((e,r)=>{let{asChild:i,...a}=e,o=i?n:t;return typeof window<`u`&&(window[Symbol.for(`radix-ui`)]=!0),(0,L.jsx)(o,{...a,ref:r})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function ca(e,t){e&&v.flushSync(()=>e.dispatchEvent(t))}var la=Object.freeze({position:`absolute`,border:0,width:1,height:1,padding:0,margin:-1,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,wordWrap:`normal`}),ua=`VisuallyHidden`,da=_.forwardRef((e,t)=>(0,L.jsx)(sa.span,{...e,ref:t,style:{...la,...e.style}}));da.displayName=ua;var fa=da;function pa(e,t){let n=_.createContext(t),r=e=>{let{children:t,...r}=e,i=_.useMemo(()=>r,Object.values(r));return(0,L.jsx)(n.Provider,{value:i,children:t})};r.displayName=e+`Provider`;function i(r){let i=_.useContext(n);if(i)return i;if(t!==void 0)return t;throw Error(`\`${r}\` must be used within \`${e}\``)}return[r,i]}function ma(e,t=[]){let n=[];function r(t,r){let i=_.createContext(r),a=n.length;n=[...n,r];let o=t=>{let{scope:n,children:r,...o}=t,s=n?.[e]?.[a]||i,c=_.useMemo(()=>o,Object.values(o));return(0,L.jsx)(s.Provider,{value:c,children:r})};o.displayName=t+`Provider`;function s(n,o){let s=o?.[e]?.[a]||i,c=_.useContext(s);if(c)return c;if(r!==void 0)return r;throw Error(`\`${n}\` must be used within \`${t}\``)}return[o,s]}let i=()=>{let t=n.map(e=>_.createContext(e));return function(n){let r=n?.[e]||t;return _.useMemo(()=>({[`__scope${e}`]:{...n,[e]:r}}),[n,r])}};return i.scopeName=e,[r,ha(i,...t)]}function ha(...e){let t=e[0];if(e.length===1)return t;let n=()=>{let n=e.map(e=>({useScope:e(),scopeName:e.scopeName}));return function(e){let r=n.reduce((t,{useScope:n,scopeName:r})=>{let i=n(e)[`__scope${r}`];return{...t,...i}},{});return _.useMemo(()=>({[`__scope${t.scopeName}`]:r}),[r])}};return n.scopeName=t.scopeName,n}function ga(e){let t=e+`CollectionProvider`,[n,r]=ma(t),[i,a]=n(t,{collectionRef:{current:null},itemMap:new Map}),o=e=>{let{scope:t,children:n}=e,r=_.useRef(null),a=_.useRef(new Map).current;return(0,L.jsx)(i,{scope:t,itemMap:a,collectionRef:r,children:n})};o.displayName=t;let s=e+`CollectionSlot`,c=$i(s),l=_.forwardRef((e,t)=>
11{let{scope:n,children:r}=e;return(0,L.jsx)(c,{ref:Qi(t,a(s,n).collectionRef),children:r})});l.displayName=s;let u=e+`CollectionItemSlot`,d=`data-radix-collection-item`,f=$i(u),p=_.forwardRef((e,t)=>{let{scope:n,children:r,...i}=e,o=_.useRef(null),s=Qi(t,o),c=a(u,n);return _.useEffect(()=>(c.itemMap.set(o,{ref:o,...i}),()=>void c.itemMap.delete(o))),(0,L.jsx)(f,{[d]:``,ref:s,children:r})});p.displayName=u;function m(t){let n=a(e+`CollectionConsumer`,t);return _.useCallback(()=>{let e=n.collectionRef.current;if(!e)return[];let t=Array.from(e.querySelectorAll(`[${d}]`));return Array.from(n.itemMap.values()).sort((e,n)=>t.indexOf(e.ref.current)-t.indexOf(n.ref.current))},[n.collectionRef,n.itemMap])}return[{Provider:o,Slot:l,ItemSlot:p},m,r]}typeof window<`u`&&window.document&&window.document.createElement;function B(e,t,{checkForDefaultPrevented:n=!0}={}){return function(r){if(e?.(r),n===!1||!r.defaultPrevented)return t?.(r)}}var _a=globalThis?.document?_.useLayoutEffect:()=>{},va=_.useInsertionEffect||_a;function ya({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){let[i,a,o]=ba({defaultProp:t,onChange:n}),s=e!==void 0,c=s?e:i;{let t=_.useRef(e!==void 0);_.useEffect(()=>{let e=t.current;
11if(e!==s){let t=e?`controlled`:`uncontrolled`,n=s?`controlled`:`uncontrolled`;console.warn(`${r} is changing from ${t} to ${n}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`)}t.current=s},[s,r])}return[c,_.useCallback(t=>{if(s){let n=xa(t)?t(e):t;n!==e&&o.current?.(n)}else a(t)},[s,e,a,o])]}function ba({defaultProp:e,onChange:t}){let[n,r]=_.useState(e),i=_.useRef(n),a=_.useRef(t);return va(()=>{a.current=t},[t]),_.useEffect(()=>{i.current!==n&&(a.current?.(n),i.current=n)},[n,i]),[n,r,a]}function xa(e){return typeof e==`function`}function Sa(e,t){return _.useReducer((e,n)=>t[e][n]??e,e)}var Ca=e=>{let{present:t,children:n}=e,r=wa(t),i=typeof n==`function`?n({present:r.isPresent}):_.Children.only(n),a=Qi(r.ref,Ea(i));return typeof n==`function`||r.isPresent?_.cloneElement(i,{ref:a}):null};Ca.displayName=`Presence`;function wa(e){let[t,n]=_.useState(),r=_.useRef(null),i=_.useRef(e),a=_.useRef(`none`),[o,s]=Sa(e?`mounted`:`unmounted`,{mounted:{UNMOUNT:`unmounted`,ANIMATION_OUT:`unmountSuspended`},unmountSuspended:{MOUNT:`mounted`,ANIMATION_END:`unmounted`},unmounted:{MOUNT:`mounted`}});return _.useEffect(()=>{let e=Ta(r.current);a.current=o===`mounted`?e:`none`},[o]),_a(()=>{let t=r.current,n=i.current;if(n!==e){let r=a.current,o=Ta(t);e?s(`MOUNT`):o===`none`||t?.display===`none`?s(`UNMOUNT`):s(n&&r!==o?`ANIMATION_OUT`:`UNMOUNT`),i.current=e}},[e,s]),_a(()=>{if(t){let e,n=t.ownerDocument.defaultView??window,o=a=>{let o=Ta(r.current).includes(CSS.escape(a.animationName));if(a.target===t&&o&&(s(`ANIMATION_END`),!i.current)){let r=t.style.animationFillMode;t.style.animationFillMode=`forwards`,e=n.setTimeout(()=>{t.style.animationFillMode===`forwards`&&(t.style.animationFillMode=r)})}},c=e=>{e.target===t&&(a.current=Ta(r.current))};return t.addEventListener(`animationstart`,c),t.addEventListener(`animationcancel`,o),t.addEventListener(`animationend`,o),()=>{n.clearTimeout(e),t.removeEventListener(`animationstart`,c),t.removeEventListener(`animationcancel`,o),t.removeEventListener(`animationend`,o)}}else s(`ANIMATION_END`)},[t,s]),{isPresent:[`mounted`,`unmountSuspended`].includes(o),ref:_.useCallback(e=>{r.current=e?getComputedStyle(e):null,n(e)},[])}}function Ta(e){return e?.animationName||`none`}function Ea(e){let t=Object.getOwnPropertyDescriptor(e.props,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var Da=_.useId||(()=>void 0),Oa=0;function ka(e){let[t,n]=_.useState(Da());return _a(()=>{e||n(e=>e??String(Oa++))},[e]),e||(t?`radix-${t}`:``)}var Aa=`Collapsible`,[ja,Ma]=ma(Aa),[Na,Pa]=ja(Aa),Fa=_.forwardRef((e,t)=>{let{__scopeCollapsible:n,open:r,defaultOpen:i,disabled:a,onOpenChange:o,...s}=e,[c,l]=ya({prop:r,defaultProp:i??!1,onChange:o,caller:Aa});return(0,L.jsx)(Na,{scope:n,disabled:a,contentId:ka(),open:c,onOpenToggle:_.useCallback(()=>l(e=>!e),[l]),children:(0,L.jsx)(sa.div,{"data-state":Va(c),"data-disabled":a?``:void 0,...s,ref:t})})});Fa.displayName=Aa;var Ia=`CollapsibleTrigger`,La=_.forwardRef((e,t)=>{let{__scopeCollapsible:n,...r}=e,i=Pa(Ia,n);return(0,L.jsx)(sa.button,{type:`button`,"aria-controls":i.contentId,"aria-expanded":i.open||!1,"data-state":Va(i.open),"data-disabled":i.disabled?``:void 0,disabled:i.disabled,...r,ref:t,onClick:B(e.onClick,i.onOpenToggle)})});La.displayName=Ia;var Ra=`CollapsibleContent`,za=_.forwardRef((e,t)=>{let{forceMount:n,...r}=e,i=Pa(Ra,e.__scopeCollapsible);return(0,L.jsx)(Ca,{present:n||i.open,children:({present:e})=>(0,L.jsx)(Ba,{...r,ref:t,present:e})})});za.displayName=Ra;var Ba=_.forwardRef((e,t)=>{let{__scopeCollapsible:n,present:r,children:i,...a}=e,o=Pa(Ra,n),[s,c]=_.useState(r),l=_.useRef(null),u=Qi(t,l),d=_.useRef(0),f=d.current,p=_.useRef(0),m=p.current,h=o.open||s,g=_.useRef(h),v=_.useRef(void 0);return _.useEffect(()=>{let e=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(e)},[]),_a(()=>{let e=l.current;if(e){v.current=v.current||{transitionDuration:e.style.transitionDuration,animationName:e.style.animationName},e.style.transitionDuration=`0s`,e.style.animationName=`none`;let t=e.getBoundingClientRect();d.current=t.height,p.current=t.width,g.current||(e.style.transitionDuration=v.current.transitionDuration,e.style.animationName=v.current.animationName),c(r)}},[o.open,r]),(0,L.jsx)(sa.div,{"data-state":Va(o.open),"data-disabled":o.disabled?``:void 0,id:o.contentId,hidden:!h,...a,ref:u,style:{"--radix-collapsible-content-height":f?`${f}px`:void 0,"--radix-collapsible-content-width":m?`${m}px`:void 0,...e.style},children:h&&i})});function Va(e){return e?`open`:`closed`}var Ha=Fa,Ua=_.createContext(void 0);function Wa(e){let t=_.useContext(Ua);return e||t||`ltr`}function Ga(e){let t=_.useRef(e);return _.useEffect(()=>{t.current=e}),_.useMemo(()=>(...e)=>t.current?.(...e),[])}function Ka(e,t=globalThis?.document){let n=Ga(e);_.useEffect(()=>{let e=e=>{e.key===`Escape`&&n(e)};
vendor: 16,847 bytes, lines 11-51
11return t.addEventListener(`keydown`,e,{capture:!0}),()=>t.removeEventListener(`keydown`,e,{capture:!0})},[n,t])}var qa=`DismissableLayer`,Ja=`dismissableLayer.update`,Ya=`dismissableLayer.pointerDownOutside`,Xa=`dismissableLayer.focusOutside`,Za,Qa=_.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),$a=_.forwardRef((e,t)=>{let{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:i,onFocusOutside:a,onInteractOutside:o,onDismiss:s,...c}=e,l=_.useContext(Qa),[u,d]=_.useState(null),f=u?.ownerDocument??globalThis?.document,[,p]=_.useState({}),m=Qi(t,e=>d(e)),h=Array.from(l.layers),[g]=[...l.layersWithOutsidePointerEventsDisabled].slice(-1),v=h.indexOf(g),y=u?h.indexOf(u):-1,b=l.layersWithOutsidePointerEventsDisabled.size>0,x=y>=v,S=no(e=>{let t=e.target,n=[...l.branches].some(e=>e.contains(t));!x||n||(i?.(e),o?.(e),e.defaultPrevented||s?.())},f),C=ro(e=>{let t=e.target;[...l.branches].some(e=>e.contains(t))||(a?.(e),o?.(e),e.defaultPrevented||s?.())},f);return Ka(e=>{y===l.layers.size-1&&(r?.(e),!e.defaultPrevented&&s&&(e.preventDefault(),s()))},f),_.useEffect(()=>{if(u)return n&&(l.layersWithOutsidePointerEventsDisabled.size===0&&(Za=f.body.style.pointerEvents,f.body.style.pointerEvents=`none`),l.layersWithOutsidePointerEventsDisabled.add(u)),l.layers.add(u),io(),()=>{n&&l.layersWithOutsidePointerEventsDisabled.size===1&&(f.body.style.pointerEvents=Za)}},[u,f,n,l]),_.useEffect(()=>()=>{u&&(l.layers.delete(u),l.layersWithOutsidePointerEventsDisabled.delete(u),io())},[u,l]),_.useEffect(()=>{let e=()=>p({});return document.addEventListener(Ja,e),()=>document.removeEventListener(Ja,e)},[]),(0,L.jsx)(sa.div,{...c,ref:m,style:{pointerEvents:b?x?`auto`:`none`:void 0,...e.style},onFocusCapture:B(e.onFocusCapture,C.onFocusCapture),onBlurCapture:B(e.onBlurCapture,C.onBlurCapture),onPointerDownCapture:B(e.onPointerDownCapture,S.onPointerDownCapture)})});$a.displayName=qa;var eo=`DismissableLayerBranch`,to=_.forwardRef((e,t)=>{let n=_.useContext(Qa),r=_.useRef(null),i=Qi(t,r);return _.useEffect(()=>{let e=r.current;if(e)return n.branches.add(e),()=>{n.branches.delete(e)}},[n.branches]),(0,L.jsx)(sa.div,{...e,ref:i})});to.displayName=eo;function no(e,t=globalThis?.document){let n=Ga(e),r=_.useRef(!1),i=_.useRef(()=>{});return _.useEffect(()=>{let e=e=>{if(e.target&&!r.current){let r=function(){ao(Ya,n,a,{discrete:!0})},a={originalEvent:e};e.pointerType===`touch`?(t.removeEventListener(`click`,i.current),i.current=r,t.addEventListener(`click`,i.current,{once:!0})):r()}else t.removeEventListener(`click`,i.current);r.current=!1},a=window.setTimeout(()=>{t.addEventListener(`pointerdown`,e)},0);return()=>{window.clearTimeout(a),t.removeEventListener(`pointerdown`,e),t.removeEventListener(`click`,i.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function ro(e,t=globalThis?.document){let n=Ga(e),r=_.useRef(!1);return _.useEffect(()=>{let e=e=>{e.target&&!r.current&&ao(Xa,n,{originalEvent:e},{discrete:!1})};return t.addEventListener(`focusin`,e),()=>t.removeEventListener(`focusin`,e)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function io(){let e=new CustomEvent(Ja);document.dispatchEvent(e)}function ao(e,t,n,{discrete:r}){let i=n.originalEvent.target,a=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&i.addEventListener(e,t,{once:!0}),r?ca(i,a):i.dispatchEvent(a)}var oo=`focusScope.autoFocusOnMount`,so=`focusScope.autoFocusOnUnmount`,co={bubbles:!1,cancelable:!0},lo=`FocusScope`,uo=_.forwardRef((e,t)=>{let{loop:n=!1,trapped:r=!1,onMountAutoFocus:i,onUnmountAutoFocus:a,...o}=e,[s,c]=_.useState(null),l=Ga(i),u=Ga(a),d=_.useRef(null),f=Qi(t,e=>c(e)),p=_.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;_.useEffect(()=>{if(r){let e=function(e){if(p.paused||!s)return;let t=e.target;s.contains(t)?d.current=t:vo(d.current,{select:!0})},t=function(e){if(p.paused||!s)return;let t=e.relatedTarget;t!==null&&(s.contains(t)||vo(d.current,{select:!0}))},n=function(e){if(document.activeElement===document.body)for(let t of e)t.removedNodes.length>0&&vo(s)};document.addEventListener(`focusin`,e),document.addEventListener(`focusout`,t);let r=new MutationObserver(n);return s&&r.observe(s,{childList:!0,subtree:!0}),()=>{document.removeEventListener(`focusin`,e),document.removeEventListener(`focusout`,t),r.disconnect()}}},[r,s,p.paused]),_.useEffect(()=>{if(s){yo.add(p);let e=document.activeElement;if(!s.contains(e)){let t=new CustomEvent(oo,co);s.addEventListener(oo,l),s.dispatchEvent(t),t.defaultPrevented||(fo(So(mo(s)),{select:!0}),document.activeElement===e&&vo(s))}return()=>{s.removeEventListener(oo,l),setTimeout(()=>{let t=new CustomEvent(so,co);s.addEventListener(so,u),s.dispatchEvent(t),t.defaultPrevented||vo(e??document.body,{select:!0}),s.removeEventListener(so,u),yo.remove(p)},0)}}},[s,l,u,p]);let m=_.useCallback(e=>{if(!n&&!r||p.paused)return;let t=e.key===`Tab`&&!e.altKey&&!e.ctrlKey&&!e.metaKey,i=document.activeElement;if(t&&i){let t=e.currentTarget,[r,a]=po(t);r&&a?!e.shiftKey&&i===a?(e.preventDefault(),n&&vo(r,{select:!0})):e.shiftKey&&i===r&&(e.preventDefault(),n&&vo(a,{select:!0})):i===t&&e.preventDefault()}},[n,r,p.paused]);return(0,L.jsx)(sa.div,{tabIndex:-1,...o,ref:f,onKeyDown:m})});uo.displayName=lo;function fo(e,{select:t=!1}={}){let n=document.activeElement;for(let r of e)if(vo(r,{select:t}),document.activeElement!==n)return}function po(e){let t=mo(e);return[ho(t,e),ho(t.reverse(),e)]}function mo(e){let t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>{let t=e.tagName===`INPUT`&&e.type===`hidden`;return e.disabled||e.hidden||t?NodeFilter.FILTER_SKIP:e.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function ho(e,t){for(let n of e)if(!go(n,{upTo:t}))return n}function go(e,{upTo:t}){if(getComputedStyle(e).visibility===`hidden`)return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display===`none`)return!0;e=e.parentElement}return!1}function _o(e){return e instanceof HTMLInputElement&&`select`in e}function vo(e,{select:t=!1}={}){if(e&&e.focus){let n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&_o(e)&&t&&e.select()}}var yo=bo();function bo(){let e=[];return{add(t){let n=e[0];t!==n&&n?.pause(),e=xo(e,t),e.unshift(t)},remove(t){e=xo(e,t),e[0]?.resume()}}}function xo(e,t){let n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function So(e){return e.filter(e=>e.tagName!==`A`)}var Co=`Portal`,wo=_.forwardRef((e,t)=>{let{container:n,...r}=e,[i,a]=_.useState(!1);_a(()=>a(!0),[]);let o=n||i&&globalThis?.document?.body;return o?v.createPortal((0,L.jsx)(sa.div,{...r,ref:t}),o):null});wo.displayName=Co;var To=0;function Eo(){_.useEffect(()=>{let e=document.querySelectorAll(`[data-radix-focus-guard]`);return document.body.insertAdjacentElement(`afterbegin`,e[0]??Do()),document.body.insertAdjacentElement(`beforeend`,e[1]??Do()),To++,()=>{To===1&&document.querySelectorAll(`[data-radix-focus-guard]`).forEach(e=>e.remove()),To--}},[])}function Do(){let e=document.createElement(`span`);return e.setAttribute(`data-radix-focus-guard`,``),e.tabIndex=0,e.style.outline=`none`,e.style.opacity=`0`,e.style.position=`fixed`,e.style.pointerEvents=`none`,e}var Oo=function(){return Oo=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n],t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},Oo.apply(this,arguments)};function ko(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols==`function`)for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n}function Ao(e,t,n){if(n||arguments.length===2)for(var r=0,i=t.length,a;r<i;r++)(a||!(r in t))&&(a||=Array.prototype.slice.call(t,0,r),a[r]=t[r]);return e.concat(a||Array.prototype.slice.call(t))}var jo=`right-scroll-bar-position`,Mo=`width-before-scroll-bar`,No=`with-scroll-bars-hidden`,Po=`--removed-body-scroll-bar-size`;function Fo(e,t){return typeof e==`function`?e(t):e&&(e.current=t),e}function Io(e,t){var n=(0,_.useState)(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(e){var t=n.value;t!==e&&(n.value=e,n.callback(e,t))}}}})[0];return n.callback=t,n.facade}var Lo=typeof window<`u`?_.useLayoutEffect:_.useEffect,Ro=new WeakMap;function zo(e,t){var n=Io(t||null,function(t){return e.forEach(function(e){return Fo(e,t)})});return Lo(function(){var t=Ro.get(n);if(t){var r=new Set(t),i=new Set(e),a=n.current;r.forEach(function(e){i.has(e)||Fo(e,null)}),i.forEach(function(e){r.has(e)||Fo(e,a)})}Ro.set(n,e)},[e]),n}function Bo(e){return e}function Vo(e,t){t===void 0&&(t=Bo);var n=[],r=!1;return{read:function(){if(r)throw Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(e){var i=t(e,r);return n.push(i),function(){n=n.filter(function(e){return e!==i})}},assignSyncMedium:function(e){for(r=!0;n.length;){var t=n;n=[],t.forEach(e)}n={push:function(t){return e(t)},filter:function(){return n}}},assignMedium:function(e){r=!0;var t=[];if(n.length){var i=n;n=[],i.forEach(e),t=n}var a=function(){var n=t;t=[],n.forEach(e)},o=function(){return Promise.resolve().then(a)};o(),n={push:function(e){t.push(e),o()},filter:function(e){return t=t.filter(e),n}}}}}function Ho(e){e===void 0&&(e={});var t=Vo(null);return t.options=Oo({async:!0,ssr:!1},e),t}var Uo=function(e){var t=e.sideCar,n=ko(e,[`sideCar`]);if(!t)throw Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw Error(`Sidecar medium not found`);return _.createElement(r,Oo({},n))};Uo.isSideCarExport=!0;function Wo(e,t){return e.useMedium(t),Uo}var Go=Ho(),Ko=function(){},qo=_.forwardRef(function(e,t){var n=_.useRef(null),r=_.useState({onScrollCapture:Ko,onWheelCapture:Ko,onTouchMoveCapture:Ko}),i=r[0],a=r[1],o=e.forwardProps,s=e.children,c=e.className,l=e.removeScrollBar,u=e.enabled,d=e.shards,f=e.sideCar,p=e.noRelative,m=e.noIsolation,h=e.inert,g=e.allowPinchZoom,v=e.as,y=v===void 0?`div`:v,b=e.gapMode,x=ko(e,[`forwardProps`,`children`,`className`,`removeScrollBar`,`enabled`,`shards`,`sideCar`,`noRelative`,`noIsolation`,`inert`,`allowPinchZoom`,`as`,`gapMode`]),S=f,C=zo([n,t]),w=Oo(Oo({},x),i);return _.createElement(_.Fragment,null,u&&_.createElement(S,{sideCar:Go,removeScrollBar:l,shards:d,noRelative:p,noIsolation:m,inert:h,setCallbacks:a,allowPinchZoom:!!g,lockRef:n,gapMode:b}),o?_.cloneElement(_.Children.only(s),Oo(Oo({},w),{ref:C})):_.createElement(y,Oo({},w,{className:c,ref:C}),s))});qo.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},qo.classNames={fullWidth:Mo,zeroRight:jo};var Jo,Yo=function(){if(Jo)return Jo;if(typeof __webpack_nonce__<`u`)return __webpack_nonce__};function Xo(){if(!document)return null;var e=document.createElement(`style`);e.type=`text/css`;var t=Yo();return t&&e.setAttribute(`nonce`,t),e}function Zo(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Qo(e){(document.head||document.getElementsByTagName(`head`)[0]).appendChild(e)}var $o=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Xo())&&(Zo(t,n),Qo(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},es=function(){var e=$o();return function(t,n){_.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},ts=function(){var e=es();return function(t){var n=t.styles,r=t.dynamic;return e(n,r),null}},ns={left:0,top:0,right:0,gap:0},rs=function(e){return parseInt(e||``,10)||0},is=function(e){var t=window.getComputedStyle(document.body),n=t[e===`padding`?`paddingLeft`:`marginLeft`],r=t[e===`padding`?`paddingTop`:`marginTop`],i=t[e===`padding`?`paddingRight`:`marginRight`];return[rs(n),rs(r),rs(i)]},as=function(e){if(e===void 0&&(e=`margin`),typeof window>`u`)return ns;var t=is(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},os=ts(),ss=`data-scroll-locked`,cs=function(e,t,n,r){var i=e.left,a=e.top,o=e.right,s=e.gap;return n===void 0&&(n=`margin`),` 12 .${No} { 13 overflow: hidden ${r}; 14 padding-right: ${s}px ${r}; 15 } 16 body[${ss}] { 17 overflow: hidden ${r}; 18 overscroll-behavior: contain; 19 ${[t&&`position: relative ${r};`,n===`margin`&&` 20 padding-left: ${i}px; 21 padding-top: ${a}px; 22 padding-right: ${o}px; 23 margin-left:0; 24 margin-top:0; 25 margin-right: ${s}px ${r}; 26 `,n===`padding`&&`padding-right: ${s}px ${r};`].filter(Boolean).join(``)} 27 } 28 29 .${jo} { 30 right: ${s}px ${r}; 31 } 32 33 .${Mo} { 34 margin-right: ${s}px ${r}; 35 } 36 37 .${jo} .${jo} { 38 right: 0 ${r}; 39 } 40 41 .${Mo} .${Mo} { 42 margin-right: 0 ${r}; 43 } 44 45 body[${ss}] { 46 ${Po}: ${s}px; 47 } 48`},ls=function(){var e=parseInt(document.body.getAttribute(`data-scroll-locked`)||`0`,10);return isFinite(e)?e:0},us=function(){_.useEffect(function(){return document.body.setAttribute(ss,(ls()+1).toString()),function(){var e=ls()-1;e<=0?document.body.removeAttribute(ss):document.body.setAttribute(ss,e.toString())}},[])},ds=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,i=r===void 0?`margin`:r;us();var a=_.useMemo(function(){return as(i)},[i]);return _.createElement(os,{styles:cs(a,!t,i,n?``:`!important`)})},fs=!1;if(typeof window<`u`)try{var ps=Object.defineProperty({},`passive`,{get:function(){return fs=!0,!0}});window.addEventListener(`test`,ps,ps),window.removeEventListener(`test`,ps,ps)}catch{fs=!1}var ms=fs?{passive:!1}:!1,hs=function(e){return e.tagName===`TEXTAREA`},gs=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!==`hidden`&&!(n.overflowY===n.overflowX&&!hs(e)&&n[t]===`visible`)},_s=function(e){return gs(e,`overflowY`)},vs=function(e){return gs(e,`overflowX`)},ys=function(e,t){var n=t.ownerDocument,r=t;do{if(typeof ShadowRoot<`u`&&r instanceof ShadowRoot&&(r=r.host),Ss(e,r)){var i=Cs(e,r);if(i[1]>i[2])return!0}r=r.parentNode}while(r&&r!==n.body);return!1},bs=function(e){return[e.scrollTop,e.scrollHeight,e.clientHeight]},xs=function(e){return[e.scrollLeft,e.scrollWidth,e.clientWidth]},Ss=function(e,t){return e===`v`?_s(t):vs(t)},Cs=function(e,t){return e===`v`?bs(t):xs(t)},ws=function(e,t){return e===`h`&&t===`rtl`?-1:1},Ts=function(e,t,n,r,i){var a=ws(e,window.getComputedStyle(t).direction),o=a*r,s=n.target,c=t.contains(s),l=!1,u=o>0,d=0,f=0;do{if(!s)break;var p=Cs(e,s),m=p[0],h=p[1]-p[2]-a*m;(m||h)&&Ss(e,s)&&(d+=h,f+=m);var g=s.parentNode;s=g&&g.nodeType===Node.DOCUMENT_FRAGMENT_NODE?g.host:g}while(!c&&s!==document.body||c&&(t.contains(s)||t===s));return(u&&(i&&Math.abs(d)<1||!i&&o>d)||!u&&(i&&Math.abs(f)<1||!i&&-o>f))&&(l=!0),l},Es=function(e){return`changedTouches`in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Ds=function(e){return[e.deltaX,e.deltaY]},Os=function(e){return e&&`current`in e?e.current:e},ks=function(e,t){return e[0]===t[0]&&e[1]===t[1]},As=function(e){return` 49 .block-interactivity-${e} {pointer-events: none;} 50 .allow-interactivity-${e} {pointer-events: all;} 51`},js=0,Ms=[];function Ns(e){var t=_.useRef([]),n=_.useRef([0,0]),r=_.useRef(),i=_.useState(js++)[0],a=_.useState(ts)[0],o=_.useRef(e);_.useEffect(function(){o.current=e},[e]),_.useEffect(function(){if(e.inert){document.body.classList.add(`block-interactivity-${i}`);var t=Ao([e.lockRef.current],(e.shards||[]).map(Os),!0).filter(Boolean);return t.forEach(function(e){return e.classList.add(`allow-interactivity-${i}`)}),function(){document.body.classList.remove(`block-interactivity-${i}`),t.forEach(function(e){return e.classList.remove(`allow-interactivity-${i}`)})}}},[e.inert,e.lockRef.current,e.shards]);var s=_.useCallback(function(e,t){if(`touches`in e&&e.touches.length===2||e.type===`wheel`&&e.ctrlKey)return!o.current.allowPinchZoom;var i=Es(e),a=n.current,s=`deltaX`in e?e.deltaX:a[0]-i[0],c=`deltaY`in e?e.deltaY:a[1]-i[1],l,u=e.target,d=Math.abs(s)>Math.abs(c)?`h`:`v`;if(`touches`in e&&d===`h`&&u.type===`range`)return!1;var f=window.getSelection(),p=f&&f.anchorNode;if(p&&(p===u||p.contains(u)))return!1;var m=ys(d,u);if(!m)return!0;if(m?l=d:(l=d===`v`?`h`:`v`,m=ys(d,u)),!m)return!1;if(!r.current&&`changedTouches`in e&&(s||c)&&(r.current=l),!l)return!0;var h=r.current||l;return Ts(h,t,e,h===`h`?s:c,!0)},[]),c=_.useCallback(function(e){var n=e;if(!(!Ms.length||Ms[Ms.length-1]!==a)){var r=`deltaY`in n?Ds(n):Es(n),i=t.current.filter(function(e){return e.name===n.type&&(e.target===n.target||n.target===e.shadowParent)&&ks(e.delta,r)})[0];if(i&&i.should){n.cancelable&&n.preventDefault();return}
vendor: 8,448 bytes, lines 51-55
51if(!i){var c=(o.current.shards||[]).map(Os).filter(Boolean).filter(function(e){return e.contains(n.target)});(c.length>0?s(n,c[0]):!o.current.noIsolation)&&n.cancelable&&n.preventDefault()}}},[]),l=_.useCallback(function(e,n,r,i){var a={name:e,delta:n,target:r,should:i,shadowParent:Ps(r)};t.current.push(a),setTimeout(function(){t.current=t.current.filter(function(e){return e!==a})},1)},[]),u=_.useCallback(function(e){n.current=Es(e),r.current=void 0},[]),d=_.useCallback(function(t){l(t.type,Ds(t),t.target,s(t,e.lockRef.current))},[]),f=_.useCallback(function(t){l(t.type,Es(t),t.target,s(t,e.lockRef.current))},[]);_.useEffect(function(){return Ms.push(a),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:f}),document.addEventListener(`wheel`,c,ms),document.addEventListener(`touchmove`,c,ms),document.addEventListener(`touchstart`,u,ms),function(){Ms=Ms.filter(function(e){return e!==a}),document.removeEventListener(`wheel`,c,ms),document.removeEventListener(`touchmove`,c,ms),document.removeEventListener(`touchstart`,u,ms)}},[]);var p=e.removeScrollBar,m=e.inert;return _.createElement(_.Fragment,null,m?_.createElement(a,{styles:As(i)}):null,p?_.createElement(ds,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Ps(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}var Fs=Wo(Go,Ns),Is=_.forwardRef(function(e,t){return _.createElement(qo,Oo({},e,{ref:t,sideCar:Fs}))});Is.classNames=qo.classNames;var Ls=function(e){return typeof document>`u`?null:(Array.isArray(e)?e[0]:e).ownerDocument.body},Rs=new WeakMap,zs=new WeakMap,Bs={},Vs=0,Hs=function(e){return e&&(e.host||Hs(e.parentNode))},Us=function(e,t){return t.map(function(t){if(e.contains(t))return t;var n=Hs(t);return n&&e.contains(n)?n:(console.error(`aria-hidden`,t,`in not contained inside`,e,`. Doing nothing`),null)}).filter(function(e){return!!e})},Ws=function(e,t,n,r){var i=Us(t,Array.isArray(e)?e:[e]);Bs[n]||(Bs[n]=new WeakMap);var a=Bs[n],o=[],s=new Set,c=new Set(i),l=function(e){!e||s.has(e)||(s.add(e),l(e.parentNode))};i.forEach(l);var u=function(e){!e||c.has(e)||Array.prototype.forEach.call(e.children,function(e){if(s.has(e))u(e);else try{var t=e.getAttribute(r),i=t!==null&&t!==`false`,c=(Rs.get(e)||0)+1,l=(a.get(e)||0)+1;Rs.set(e,c),a.set(e,l),o.push(e),c===1&&i&&zs.set(e,!0),l===1&&e.setAttribute(n,`true`),i||e.setAttribute(r,`true`)}catch(t){console.error(`aria-hidden: cannot operate on `,e,t)}})};return u(t),s.clear(),Vs++,function(){o.forEach(function(e){var t=Rs.get(e)-1,i=a.get(e)-1;Rs.set(e,t),a.set(e,i),t||(zs.has(e)||e.removeAttribute(r),zs.delete(e)),i||e.removeAttribute(n)}),Vs--,Vs||(Rs=new WeakMap,Rs=new WeakMap,zs=new WeakMap,Bs={})}},Gs=function(e,t,n){n===void 0&&(n=`data-aria-hidden`);var r=Array.from(Array.isArray(e)?e:[e]),i=t||Ls(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll(`[aria-live], script`))),Ws(r,i,n,`aria-hidden`)):function(){return null}},Ks=`Dialog`,[qs,Js]=ma(Ks),[Ys,Xs]=qs(Ks),Zs=e=>{let{__scopeDialog:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:o=!0}=e,s=_.useRef(null),c=_.useRef(null),[l,u]=ya({prop:r,defaultProp:i??!1,onChange:a,caller:Ks});return(0,L.jsx)(Ys,{scope:t,triggerRef:s,contentRef:c,contentId:ka(),titleId:ka(),descriptionId:ka(),open:l,onOpenChange:u,onOpenToggle:_.useCallback(()=>u(e=>!e),[u]),modal:o,children:n})};Zs.displayName=Ks;var Qs=`DialogTrigger`,$s=_.forwardRef((e,t)=>{let{__scopeDialog:n,...r}=e,i=Xs(Qs,n),a=Qi(t,i.triggerRef);return(0,L.jsx)(sa.button,{type:`button`,"aria-haspopup":`dialog`,"aria-expanded":i.open,"aria-controls":i.contentId,"data-state":yc(i.open),...r,ref:a,onClick:B(e.onClick,i.onOpenToggle)})});$s.displayName=Qs;var ec=`DialogPortal`,[tc,nc]=qs(ec,{forceMount:void 0}),rc=e=>{let{__scopeDialog:t,forceMount:n,children:r,container:i}=e,a=Xs(ec,t);return(0,L.jsx)(tc,{scope:t,forceMount:n,children:_.Children.map(r,e=>(0,L.jsx)(Ca,{present:n||a.open,children:(0,L.jsx)(wo,{asChild:!0,container:i,children:e})}))})};rc.displayName=ec;var ic=`DialogOverlay`,ac=_.forwardRef((e,t)=>{let n=nc(ic,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=Xs(ic,e.__scopeDialog);return a.modal?(0,L.jsx)(Ca,{present:r||a.open,children:(0,L.jsx)(sc,{...i,ref:t})}):null});ac.displayName=ic;var oc=$i(`DialogOverlay.RemoveScroll`),sc=_.forwardRef((e,t)=>{let{__scopeDialog:n,...r}=e,i=Xs(ic,n);return(0,L.jsx)(Is,{as:oc,allowPinchZoom:!0,shards:[i.contentRef],children:(0,L.jsx)(sa.div,{"data-state":yc(i.open),...r,ref:t,style:{pointerEvents:`auto`,...r.style}})})}),cc=`DialogContent`,lc=_.forwardRef((e,t)=>{let n=nc(cc,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=Xs(cc,e.__scopeDialog);return(0,L.jsx)(Ca,{present:r||a.open,children:a.modal?(0,L.jsx)(uc,{...i,ref:t}):(0,L.jsx)(dc,{...i,ref:t})})});lc.displayName=cc;var uc=_.forwardRef((e,t)=>{let n=Xs(cc,e.__scopeDialog),r=_.useRef(null),i=Qi(t,n.contentRef,r);return _.useEffect(()=>{let e=r.current;if(e)return Gs(e)},[]),(0,L.jsx)(fc,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:B(e.onCloseAutoFocus,e=>{e.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:B(e.onPointerDownOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0;(t.button===2||n)&&e.preventDefault()}),onFocusOutside:B(e.onFocusOutside,e=>e.preventDefault())})}),dc=_.forwardRef((e,t)=>{let n=Xs(cc,e.__scopeDialog),r=_.useRef(!1),i=_.useRef(!1);return(0,L.jsx)(fc,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),t.defaultPrevented||(r.current||n.triggerRef.current?.focus(),t.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),t.defaultPrevented||(r.current=!0,t.detail.originalEvent.type===`pointerdown`&&(i.current=!0));let a=t.target;n.triggerRef.current?.contains(a)&&t.preventDefault(),t.detail.originalEvent.type===`focusin`&&i.current&&t.preventDefault()}})}),fc=_.forwardRef((e,t)=>{let{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,...o}=e,s=Xs(cc,n),c=_.useRef(null),l=Qi(t,c);return Eo(),(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(uo,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:(0,L.jsx)($a,{role:`dialog`,id:s.contentId,"aria-describedby":s.descriptionId,"aria-labelledby":s.titleId,"data-state":yc(s.open),...o,ref:l,onDismiss:()=>s.onOpenChange(!1)})}),(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(Cc,{titleId:s.titleId}),(0,L.jsx)(Tc,{contentRef:c,descriptionId:s.descriptionId})]})]})}),pc=`DialogTitle`,mc=_.forwardRef((e,t)=>{let{__scopeDialog:n,...r}=e,i=Xs(pc,n);return(0,L.jsx)(sa.h2,{id:i.titleId,...r,ref:t})});mc.displayName=pc;var hc=`DialogDescription`,gc=_.forwardRef((e,t)=>{let{__scopeDialog:n,...r}=e,i=Xs(hc,n);return(0,L.jsx)(sa.p,{id:i.descriptionId,...r,ref:t})});gc.displayName=hc;var _c=`DialogClose`,vc=_.forwardRef((e,t)=>{let{__scopeDialog:n,...r}=e,i=Xs(_c,n);return(0,L.jsx)(sa.button,{type:`button`,...r,ref:t,onClick:B(e.onClick,()=>i.onOpenChange(!1))})});vc.displayName=_c;function yc(e){return e?`open`:`closed`}var bc=`DialogTitleWarning`,[xc,Sc]=pa(bc,{contentName:cc,titleName:pc,docsSlug:`dialog`}),Cc=({titleId:e})=>{let t=Sc(bc),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users. 52 53If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component. 54 55For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return _.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},wc=`DialogDescriptionWarning`,Tc=({contentRef:e,descriptionId:t})=>{let n=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Sc(wc).contentName}}.`;return _.useEffect(()=>{let r=e.current?.getAttribute(`aria-describedby`);t&&r&&(document.getElementById(t)||console.warn(n))},[n,e,t]),null},Ec=Zs,Dc=$s,Oc=rc,kc=ac,Ac=lc,jc=mc,Mc=gc,Nc=vc,Pc=`AlertDialog`,[Fc,Ic]=ma(Pc,[Js]),Lc=Js(),Rc=e=>{let{__scopeAlertDialog:t,...n}=e,r=Lc(t);return(0,L.jsx)(Ec,{...r,...n,modal:!0})};Rc.displayName=Pc;var zc=`AlertDialogTrigger`,Bc=_.forwardRef((e,t)=>{let{__scopeAlertDialog:n,...r}=e,i=Lc(n);return(0,L.jsx)(Dc,{...i,...r,ref:t})});Bc.displayName=zc;var Vc=`AlertDialogPortal`,Hc=e=>{let{__scopeAlertDialog:t,...n}=e,r=Lc(t);return(0,L.jsx)(Oc,{...r,...n})};Hc.displayName=Vc;var Uc=`AlertDialogOverlay`,Wc=_.forwardRef((e,t)=>
55{let{__scopeAlertDialog:n,...r}=e,i=Lc(n);return(0,L.jsx)(kc,{...i,...r,ref:t})});Wc.displayName=Uc;var Gc=`AlertDialogContent`,[Kc,qc]=Fc(Gc),Jc=ra(`AlertDialogContent`),Yc=_.forwardRef((e,t)=>{let{__scopeAlertDialog:n,children:r,...i}=e,a=Lc(n),o=_.useRef(null),s=Qi(t,o),c=_.useRef(null);return(0,L.jsx)(xc,{contentName:Gc,titleName:Xc,docsSlug:`alert-dialog`,children:(0,L.jsx)(Kc,{scope:n,cancelRef:c,children:(0,L.jsxs)(Ac,{role:`alertdialog`,...a,...i,ref:s,onOpenAutoFocus:B(i.onOpenAutoFocus,e=>{e.preventDefault(),c.current?.focus({preventScroll:!0})}),onPointerDownOutside:e=>e.preventDefault(),onInteractOutside:e=>e.preventDefault(),children:[(0,L.jsx)(Jc,{children:r}),(0,L.jsx)(il,{contentRef:o})]})})})});Yc.displayName=Gc;var Xc=`AlertDialogTitle`,Zc=_.forwardRef((e,t)=>{let{__scopeAlertDialog:n,...r}=e,i=Lc(n);return(0,L.jsx)(jc,{...i,...r,ref:t})});Zc.displayName=Xc;var Qc=`AlertDialogDescription`,$c=_.forwardRef((e,t)=>{let{__scopeAlertDialog:n,...r}=e,i=Lc(n);return(0,L.jsx)(Mc,{...i,...r,ref:t})});$c.displayName=Qc;var el=`AlertDialogAction`,tl=_.forwardRef((e,t)=>{let{__scopeAlertDialog:n,...r}=e,i=Lc(n);return(0,L.jsx)(Nc,{...i,...r,ref:t})});tl.displayName=el;var nl=`AlertDialogCancel`,rl=_.forwardRef((e,t)=>{let{__scopeAlertDialog:n,...r}=e,{cancelRef:i}=qc(nl,n),a=Lc(n),o=Qi(t,i);return(0,L.jsx)(Nc,{...a,...r,ref:o})});rl.displayName=nl;var il=({contentRef:e})=>{let t=`\`${Gc}\` requires a description for the component to be accessible for screen reader users. 56 57You can add a description to the \`${Gc}\` by passing a \`${Qc}\` component as a child, which also benefits sighted users by adding visible context to the dialog. 58 59Alternatively, you can use your own component as a description by assigning it an \`id\` and passing the same value to the \`aria-describedby\` prop in \`${Gc}\`. If the description is confusing or duplicative for sighted users, you can use the \`@radix-ui/react-visually-hidden\` primitive as a wrapper around your description component. 60 61For more information, see https://radix-ui.com/primitives/docs/components/alert-dialog`;return _.useEffect(()=>{document.getElementById(e.current?.getAttribute(`aria-describedby`))||console.warn(t)},[t,e]),null},al=Rc,ol=Bc,sl=Hc,cl=Wc,ll=Yc,ul=tl,dl=rl,fl=Zc,pl=$c;function ml(e){let t=_.useRef({value:e,previous:e});return _.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}function hl(e){let[t,n]=_.useState(void 0);return _a(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});let t=new ResizeObserver(t=>{if(!Array.isArray(t)||!t.length)return;let r=t[0],i,a;if(`borderBoxSize`in r){let e=r.borderBoxSize,t=Array.isArray(e)?e[0]:e;i=t.inlineSize,a=t.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return t.observe(e,{box:`border-box`}),()=>t.unobserve(e)}else n(void 0)},[e]),t}var gl=`Checkbox`,[_l,vl]=ma(gl),[yl,bl]=_l(gl);function xl(e){let{__scopeCheckbox:t,checked:n,children:r,defaultChecked:i,disabled:a,form:o,name:s,onCheckedChange:c,required:l,value:u=`on`,internal_do_not_use_render:d}=e,[f,p]=ya({prop:n,defaultProp:i??!1,onChange:c,caller:gl}),[m,h]=_.useState(null),[g,v]=_.useState(null),y=_.useRef(!1),b=m?!!o||!!m.closest(`form`):!0,x={checked:f,disabled:a,setChecked:p,control:m,setControl:h,name:s,form:o,value:u,hasConsumerStoppedPropagationRef:y,required:l,defaultChecked:Al(i)?!1:i,isFormControl:b,bubbleInput:g,setBubbleInput:v};return(0,L.jsx)(yl,{scope:t,...x,children:kl(d)?d(x):r})}var Sl=`CheckboxTrigger`,Cl=_.forwardRef(({__scopeCheckbox:e,onKeyDown:t,onClick:n,...r},i)=>{let{control:a,value:o,disabled:s,checked:c,required:l,setControl:u,setChecked:d,hasConsumerStoppedPropagationRef:f,isFormControl:p,bubbleInput:m}=bl(Sl,e),h=Qi(i,u),g=_.useRef(c);return _.useEffect(()=>{let e=a?.form;if(e){let t=()=>d(g.current);return e.addEventListener(`reset`,t),()=>e.removeEventListener(`reset`,t)}},[a,d]),(0,L.jsx)(sa.button,{type:`button`,role:`checkbox`,"aria-checked":Al(c)?`mixed`:c,"aria-required":l,"data-state":jl(c),"data-disabled":s?``:void 0,disabled:s,value:o,...r,ref:h,onKeyDown:B(t,e=>{e.key===`Enter`&&e.preventDefault()}),onClick:B(n,e=>{d(e=>Al(e)?!0:!e),m&&p&&(f.current=e.isPropagationStopped(),f.current||e.stopPropagation())})})});Cl.displayName=Sl;var wl=_.forwardRef((e,t)=>
vendor: 4,730 bytes, line 61
61{let{__scopeCheckbox:n,name:r,checked:i,defaultChecked:a,required:o,disabled:s,value:c,onCheckedChange:l,form:u,...d}=e;return(0,L.jsx)(xl,{__scopeCheckbox:n,checked:i,defaultChecked:a,disabled:s,required:o,onCheckedChange:l,name:r,form:u,value:c,internal_do_not_use_render:({isFormControl:e})=>(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(Cl,{...d,ref:t,__scopeCheckbox:n}),e&&(0,L.jsx)(Ol,{__scopeCheckbox:n})]})})});wl.displayName=gl;var Tl=`CheckboxIndicator`,El=_.forwardRef((e,t)=>{let{__scopeCheckbox:n,forceMount:r,...i}=e,a=bl(Tl,n);return(0,L.jsx)(Ca,{present:r||Al(a.checked)||a.checked===!0,children:(0,L.jsx)(sa.span,{"data-state":jl(a.checked),"data-disabled":a.disabled?``:void 0,...i,ref:t,style:{pointerEvents:`none`,...e.style}})})});El.displayName=Tl;var Dl=`CheckboxBubbleInput`,Ol=_.forwardRef(({__scopeCheckbox:e,...t},n)=>{let{control:r,hasConsumerStoppedPropagationRef:i,checked:a,defaultChecked:o,required:s,disabled:c,name:l,value:u,form:d,bubbleInput:f,setBubbleInput:p}=bl(Dl,e),m=Qi(n,p),h=ml(a),g=hl(r);_.useEffect(()=>{let e=f;if(!e)return;let t=window.HTMLInputElement.prototype,n=Object.getOwnPropertyDescriptor(t,`checked`).set,r=!i.current;if(h!==a&&n){let t=new Event(`click`,{bubbles:r});e.indeterminate=Al(a),n.call(e,Al(a)?!1:a),e.dispatchEvent(t)}},[f,h,a,i]);let v=_.useRef(Al(a)?!1:a);return(0,L.jsx)(sa.input,{type:`checkbox`,"aria-hidden":!0,defaultChecked:o??v.current,required:s,disabled:c,name:l,value:u,form:d,...t,tabIndex:-1,ref:m,style:{...t.style,...g,position:`absolute`,pointerEvents:`none`,opacity:0,margin:0,transform:`translateX(-100%)`}})});Ol.displayName=Dl;function kl(e){return typeof e==`function`}function Al(e){return e===`indeterminate`}function jl(e){return Al(e)?`indeterminate`:e?`checked`:`unchecked`}var Ml=[`top`,`right`,`bottom`,`left`],Nl=Math.min,Pl=Math.max,Fl=Math.round,Il=Math.floor,Ll=e=>({x:e,y:e}),Rl={left:`right`,right:`left`,bottom:`top`,top:`bottom`};function zl(e,t,n){return Pl(e,Nl(t,n))}function Bl(e,t){return typeof e==`function`?e(t):e}function Vl(e){return e.split(`-`)[0]}function Hl(e){return e.split(`-`)[1]}function Ul(e){return e===`x`?`y`:`x`}function Wl(e){return e===`y`?`height`:`width`}function Gl(e){let t=e[0];return t===`t`||t===`b`?`y`:`x`}function Kl(e){return Ul(Gl(e))}function ql(e,t,n){n===void 0&&(n=!1);let r=Hl(e),i=Kl(e),a=Wl(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=nu(o)),[o,nu(o)]}function Jl(e){let t=nu(e);return[Yl(e),t,Yl(t)]}function Yl(e){return e.includes(`start`)?e.replace(`start`,`end`):e.replace(`end`,`start`)}var Xl=[`left`,`right`],Zl=[`right`,`left`],Ql=[`top`,`bottom`],$l=[`bottom`,`top`];function eu(e,t,n){switch(e){case`top`:case`bottom`:return n?t?Zl:Xl:t?Xl:Zl;case`left`:case`right`:return t?Ql:$l;default:return[]}}function tu(e,t,n,r){let i=Hl(e),a=eu(Vl(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(Yl)))),a}function nu(e){let t=Vl(e);return Rl[t]+e.slice(t.length)}function ru(e){return{top:0,right:0,bottom:0,left:0,...e}}function iu(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:ru(e)}function au(e){let{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function ou(e,t,n){let{reference:r,floating:i}=e,a=Gl(t),o=Kl(t),s=Wl(o),c=Vl(t),l=a===`y`,u=r.x+r.width/2-i.width/2,d=r.y+r.height/2-i.height/2,f=r[s]/2-i[s]/2,p;switch(c){case`top`:p={x:u,y:r.y-i.height};break;case`bottom`:p={x:u,y:r.y+r.height};break;case`right`:p={x:r.x+r.width,y:d};break;case`left`:p={x:r.x-i.width,y:d};break;default:p={x:r.x,y:r.y}}switch(Hl(t)){case`start`:p[o]-=f*(n&&l?-1:1);break;case`end`:p[o]+=f*(n&&l?-1:1);break}return p}async function su(e,t){t===void 0&&(t={});let{x:n,y:r,platform:i,rects:a,elements:o,strategy:s}=e,{boundary:c=`clippingAncestors`,rootBoundary:l=`viewport`,elementContext:u=`floating`,altBoundary:d=!1,padding:f=0}=Bl(t,e),p=iu(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=au(await i.getClippingRect({element:await(i.isElement==null?void 0:i.isElement(m))??!0?m:m.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:c,rootBoundary:l,strategy:s})),g=u===`floating`?{x:n,y:r,width:a.floating.width,height:a.floating.height}:a.reference,_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),v=await(i.isElement==null?void 0:i.isElement(_))&&await(i.getScale==null?void 0:i.getScale(_))||{x:1,y:1},y=au(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:g,offsetParent:_,strategy:s}):g);return{top:(h.top-y.top+p.top)/v.y,bottom:(y.bottom-h.bottom+p.bottom)/v.y,left
vendor: 8,588 bytes, line 61
61:(h.left-y.left+p.left)/v.x,right:(y.right-h.right+p.right)/v.x}}var cu=50,lu=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:su},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=ou(l,r,c),f=r,p=0,m={};for(let n=0;n<a.length;n++){let h=a[n];if(!h)continue;let{name:g,fn:_}=h,{x:v,y,data:b,reset:x}=await _({x:u,y:d,initialPlacement:r,placement:f,strategy:i,middlewareData:m,rects:l,platform:s,elements:{reference:e,floating:t}});u=v??u,d=y??d,m[g]={...m[g],...b},x&&p<cu&&(p++,typeof x==`object`&&(x.placement&&(f=x.placement),x.rects&&(l=x.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):x.rects),{x:u,y:d}=ou(l,f,c)),n=-1)}return{x:u,y:d,placement:f,strategy:i,middlewareData:m}},uu=e=>({name:`arrow`,options:e,async fn(t){let{x:n,y:r,placement:i,rects:a,platform:o,elements:s,middlewareData:c}=t,{element:l,padding:u=0}=Bl(e,t)||{};if(l==null)return{};let d=iu(u),f={x:n,y:r},p=Kl(i),m=Wl(p),h=await o.getDimensions(l),g=p===`y`,_=g?`top`:`left`,v=g?`bottom`:`right`,y=g?`clientHeight`:`clientWidth`,b=a.reference[m]+a.reference[p]-f[p]-a.floating[m],x=f[p]-a.reference[p],S=await(o.getOffsetParent==null?void 0:o.getOffsetParent(l)),C=S?S[y]:0;(!C||!await(o.isElement==null?void 0:o.isElement(S)))&&(C=s.floating[y]||a.floating[m]);let w=b/2-x/2,T=C/2-h[m]/2-1,E=Nl(d[_],T),D=Nl(d[v],T),O=E,k=C-h[m]-D,A=C/2-h[m]/2+w,j=zl(O,A,k),M=!c.arrow&&Hl(i)!=null&&A!==j&&a.reference[m]/2-(A<O?E:D)-h[m]/2<0,ee=M?A<O?A-O:A-k:0;return{[p]:f[p]+ee,data:{[p]:j,centerOffset:A-j-ee,...M&&{alignmentOffset:ee}},reset:M}}}),du=function(e){return e===void 0&&(e={}),{name:`flip`,options:e,async fn(t){var n;let{placement:r,middlewareData:i,rects:a,initialPlacement:o,platform:s,elements:c}=t,{mainAxis:l=!0,crossAxis:u=!0,fallbackPlacements:d,fallbackStrategy:f=`bestFit`,fallbackAxisSideDirection:p=`none`,flipAlignment:m=!0,...h}=Bl(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=Vl(r),_=Gl(o),v=Vl(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[nu(o)]:Jl(o)),x=p!==`none`;!d&&x&&b.push(...tu(o,m,p,y));let S=[o,...b],C=await s.detectOverflow(t,h),w=[],T=i.flip?.overflows||[];if(l&&w.push(C[g]),u){let e=ql(r,a,y);w.push(C[e[0]],C[e[1]])}if(T=[...T,{placement:r,overflows:w}],!w.every(e=>e<=0)){let e=(i.flip?.index||0)+1,t=S[e];if(t&&(!(u===`alignment`&&_!==Gl(t))||T.every(e=>Gl(e.placement)===_?e.overflows[0]>0:!0)))return{data:{index:e,overflows:T},reset:{placement:t}};let n=T.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0]?.placement;if(!n)switch(f){case`bestFit`:{let e=T.filter(e=>{if(x){let t=Gl(e.placement);return t===_||t===`y`}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0]?.[0];e&&(n=e);break}case`initialPlacement`:n=o;break}if(r!==n)return{reset:{placement:n}}}return{}}}};function fu(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function pu(e){return Ml.some(t=>e[t]>=0)}var mu=function(e){return e===void 0&&(e={}),{name:`hide`,options:e,async fn(t){let{rects:n,platform:r}=t,{strategy:i=`referenceHidden`,...a}=Bl(e,t);switch(i){case`referenceHidden`:{let e=fu(await r.detectOverflow(t,{...a,elementContext:`reference`}),n.reference);return{data:{referenceHiddenOffsets:e,referenceHidden:pu(e)}}}case`escaped`:{let e=fu(await r.detectOverflow(t,{...a,altBoundary:!0}),n.floating);return{data:{escapedOffsets:e,escaped:pu(e)}}}default:return{}}}}},hu=new Set([`left`,`top`]);async function gu(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=Vl(n),s=Hl(n),c=Gl(n)===`y`,l=hu.has(o)?-1:1,u=a&&c?-1:1,d=Bl(t,e),{mainAxis:f,crossAxis:p,alignmentAxis:m}=typeof d==`number`?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return s&&typeof m==`number`&&(p=s===`end`?m*-1:m),c?{x:p*u,y:f*l}:{x:f*l,y:p*u}}var _u=function(e){return e===void 0&&(e=0),{name:`offset`,options:e,async fn(t){var n;let{x:r,y:i,placement:a,middlewareData:o}=t,s=await gu(t,e);return a===o.offset?.placement&&(n=o.arrow)!=null&&n.alignmentOffset?{}:{x:r+s.x,y:i+s.y,data:{...s,placement:a}}}}},vu=function(e){return e===void 0&&(e={}),{name:`shift`,options:e,async fn(t){let{x:n,y:r,placement:i,platform:a}=t,{mainAxis:o=!0,crossAxis:s=!1,limiter:c={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...l}=Bl(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=Gl(Vl(i)),p=Ul(f),m=u[p],h=u[f];if(o){let e=p===`y`?`top`:`left`,t=p===`y`?`bottom`:`right`,n=m+d[e],r=m-d[t];m=zl(n,m,r)}if(s){let e=f===`y`?`top`:`left`,t=f===`y`?`bottom`:`right`,n=h+d[e],r=h-d[t];h=zl(n,h,r)}let g=c.fn({...t,[p]:m,[f]:h});return{...g,data:{x:g.x-n,y:g.y-r,enabled:{[p]:o,[f]:s}}}}}},yu=function(e){return e===void 0&&(e={}),{options:e,fn(t){let{x:n,y:r,placement:i,rects:a,middlewareData:o}=t,{offset:s=0,mainAxis:c=!0,crossAxis:l=!0}=Bl(e,t),u={x:n,y:r},d=Gl(i),f=Ul(d),p=u[f],m=u[d],h=Bl(s,t),g=typeof h==`number`?{mainAxis:h,crossAxis:0}:{mainAxis:0,crossAxis:0,...h};if(c){let e=f===`y`?`height`:`width`,t=a.reference[f]-a.floating[e]+g.mainAxis,n=a.reference[f]+a.reference[e]-g.mainAxis;p<t?p=t:p>n&&(p=n)}if(l){let e=f===`y`?`width`:`height`,t=hu.has(Vl(i)),n=a.reference[d]-a.floating[e]+(t&&o.offset?.[d]||0)+(t?0:g.crossAxis),r=a.reference[d]+a.reference[e]+(t?0:o.offset?.[d]||0)-(t?g.crossAxis:0);m<n?m=n:m>r&&(m=r)}return{[f]:p,[d]:m}}}},bu=function(e){return e===void 0&&(e={}),{name:`size`,options:e,async fn(t){var n,r;let{placement:i,rects:a,platform:o,elements:s}=t,{apply:c=()=>{},...l}=Bl(e,t),u=await o.detectOverflow(t,l),d=Vl(i),f=Hl(i),p=Gl(i)===`y`,{width:m,height:h}=a.floating,g,_;d===`top`||d===`bottom`?(g=d,_=f===(await(o.isRTL==null?void 0:o.isRTL(s.floating))?`start`:`end`)?`left`:`right`):(_=d,g=f===`end`?`top`:`bottom`);let v=h-u.top-u.bottom,y=m-u.left-u.right,b=Nl(h-u[g],v),x=Nl(m-u[_],y),S=!t.middlewareData.shift,C=b,w=x;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(w=y),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(C=v),S&&!f){let e=Pl(u.left,0),t=Pl(u.right,0),n=Pl(u.top,0),r=Pl(u.bottom,0);p?w=m-2*(e!==0||t!==0?e+t:Pl(u.left,u.right)):C=h-2*(n!==0||r!==0?n+r:Pl(u.top,u.bottom))}await c({...t,availableWidth:w,availableHeight:C});let T=await o.getDimensions(s.floating);return m!==T.width||h!==T.height?{reset:{rects:!0}}:{}}}};function xu(){return typeof window<`u`}function Su(e){return Tu(e)?(e.nodeName||``).toLowerCase():`#document`}function Cu(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function wu(e){return((Tu(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function Tu(e){return xu()?e instanceof Node||e instanceof Cu(e).Node:!1}function Eu(e){return xu()?e instanceof Element||e instanceof Cu(e).Element:!1}function Du(e){return xu()?e instanceof HTMLElement||e instanceof Cu(e).HTMLElement:!1}function Ou(e){return!xu()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof Cu(e).ShadowRoot}function ku(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=Bu(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!==`inline`&&i!==`contents`}function Au(e){return/^(table|td|th)$/.test(Su(e))}function ju(e){try{if(e.matches(`:popover-open`))return!0}catch{}try{return e.matches(`:modal`)}catch{return!1}}var Mu=/transform|translate|scale|rotate|perspective|filter/,Nu=/paint|layout|strict|content/,Pu=e=>!!e&&e!==`none`,Fu;function Iu(e){let t=Eu(e)?Bu(e):e;return Pu(t.transform)||Pu(t.translate)||Pu(t.scale)||Pu(t.rotate)||Pu(t.perspective)||!Ru()&&(Pu(t.backdropFilter)||Pu(t.filter))||Mu.test(t.willChange||``)||Nu.test(t.contain||``)}function Lu(e){let t=Hu(e);for(;Du(t)&&!zu(t);){if(Iu(t))return t;if(ju(t))return null;t=Hu(t)}return null}function Ru(){return Fu??=typeof CSS<`u`&&CSS.supports&&CSS.supports(`-webkit-backdrop-filter`,`none`),Fu}function zu(e){return/^(html|body|#document)$/.test(Su(e))}function Bu(e){return Cu(e).getComputedStyle(e)}function Vu(e){return Eu(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Hu(e){if(Su(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||Ou(e)&&e.host||wu(e);return Ou(t)?t.host:t}function Uu(e){let t=Hu(e);return zu(t)?e.ownerDocument?e.ownerDocument.body:e.body:Du(t)&&ku(t)?t:Uu(t)}function Wu(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=Uu(e),i=r===e.ownerDocument?.body,a=Cu(r);if(i){let e=Gu(a);
vendor: 6,486 bytes, line 61
61return t.concat(a,a.visualViewport||[],ku(r)?r:[],e&&n?Wu(e):[])}else return t.concat(r,Wu(r,[],n))}function Gu(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Ku(e){let t=Bu(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=Du(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=Fl(n)!==a||Fl(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function qu(e){return Eu(e)?e:e.contextElement}function Ju(e){let t=qu(e);if(!Du(t))return Ll(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=Ku(t),o=(a?Fl(n.width):n.width)/r,s=(a?Fl(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!s||!Number.isFinite(s))&&(s=1),{x:o,y:s}}var Yu=Ll(0);function Xu(e){let t=Cu(e);return!Ru()||!t.visualViewport?Yu:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Zu(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Cu(e)?!1:t}function Qu(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=qu(e),o=Ll(1);t&&(r?Eu(r)&&(o=Ju(r)):o=Ju(e));let s=Zu(a,n,r)?Xu(a):Ll(0),c=(i.left+s.x)/o.x,l=(i.top+s.y)/o.y,u=i.width/o.x,d=i.height/o.y;if(a){let e=Cu(a),t=r&&Eu(r)?Cu(r):r,n=e,i=Gu(n);for(;i&&r&&t!==n;){let e=Ju(i),t=i.getBoundingClientRect(),r=Bu(i),a=t.left+(i.clientLeft+parseFloat(r.paddingLeft))*e.x,o=t.top+(i.clientTop+parseFloat(r.paddingTop))*e.y;c*=e.x,l*=e.y,u*=e.x,d*=e.y,c+=a,l+=o,n=Cu(i),i=Gu(n)}}return au({width:u,height:d,x:c,y:l})}function $u(e,t){let n=Vu(e).scrollLeft;return t?t.left+n:Qu(wu(e)).left+n}function ed(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-$u(e,n),y:n.top+t.scrollTop}}function td(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=wu(r),s=t?ju(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=Ll(1),u=Ll(0),d=Du(r);if((d||!d&&!a)&&((Su(r)!==`body`||ku(o))&&(c=Vu(r)),d)){let e=Qu(r);l=Ju(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?ed(o,c):Ll(0);return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-c.scrollLeft*l.x+u.x+f.x,y:n.y*l.y-c.scrollTop*l.y+u.y+f.y}}function nd(e){return Array.from(e.getClientRects())}function rd(e){let t=wu(e),n=Vu(e),r=e.ownerDocument.body,i=Pl(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),a=Pl(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight),o=-n.scrollLeft+$u(e),s=-n.scrollTop;return Bu(r).direction===`rtl`&&(o+=Pl(t.clientWidth,r.clientWidth)-i),{width:i,height:a,x:o,y:s}}var id=25;function ad(e,t){let n=Cu(e),r=wu(e),i=n.visualViewport,a=r.clientWidth,o=r.clientHeight,s=0,c=0;if(i){a=i.width,o=i.height;let e=Ru();(!e||e&&t===`fixed`)&&(s=i.offsetLeft,c=i.offsetTop)}let l=$u(r);if(l<=0){let e=r.ownerDocument,t=e.body,n=getComputedStyle(t),i=e.compatMode===`CSS1Compat`&&parseFloat(n.marginLeft)+parseFloat(n.marginRight)||0,o=Math.abs(r.clientWidth-t.clientWidth-i);o<=id&&(a-=o)}else l<=id&&(a+=l);return{width:a,height:o,x:s,y:c}}function od(e,t){let n=Qu(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=Du(e)?Ju(e):Ll(1);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function sd(e,t,n){let r;if(t===`viewport`)r=ad(e,n);else if(t===`document`)r=rd(wu(e));else if(Eu(t))r=od(t,n);else{let n=Xu(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return au(r)}function cd(e,t){let n=Hu(e);return n===t||!Eu(n)||zu(n)?!1:Bu(n).position===`fixed`||cd(n,t)}function ld(e,t){let n=t.get(e);if(n)return n;let r=Wu(e,[],!1).filter(e=>Eu(e)&&Su(e)!==`body`),i=null,a=Bu(e).position===`fixed`,o=a?Hu(e):e;for(;Eu(o)&&!zu(o);){let t=Bu(o),n=Iu(o);!n&&t.position===`fixed`&&(i=null),(a?!n&&!i:!n&&t.position===`static`&&i&&(i.position===`absolute`||i.position===`fixed`)||ku(o)&&!n&&cd(e,o))?r=r.filter(e=>e!==o):i=t,o=Hu(o)}return t.set(e,r),r}function ud(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?ju(t)?[]:ld(t,this._c):[].concat(n),r],o=sd(t,a[0],i),s=o.top,c=o.right,l=o.bottom,u=o.left;for(let e=1;e<a.length;e++){let n=sd(t,a[e],i);s=Pl(n.top,s),c=Nl(n.right,c),l=Nl(n.bottom,l),u=Pl(n.left,u)}return{width:c-u,height:l-s,x:u,y:s}}function dd(e){let{width:t,height:n}=Ku(e);return{width:t,height:n}}function fd(e,t,n){let r=Du(t),i=wu(t),a=n===`fixed`,o=Qu(e,!0,a,t),s={scrollLeft:0,scrollTop:0},c=Ll(0);function l(){c.x=$u(i)}if(r||!r&&!a)if((Su(t)!==`body`||ku(i))&&(s=Vu(t)),r){let e=Qu(t,!0,a,t);c.x=e.x+t.clientLeft,c.y=e.y+t.clientTop}else i&&l();a&&!r&&i&&l();let u=i&&!r&&!a?ed(i,s):Ll(0);return{x:o.left+s.scrollLeft-c.x-u.x,y:o.top+s.scrollTop-c.y-u.y,width:o.width,height:o.height}}function pd(e){return Bu(e).position===`static`}function md(e,t){if(!Du(e)||Bu(e).position===`fixed`)return null;if(t)return t(e);let n=e.offsetParent;return wu(e)===n&&(n=n.ownerDocument.body),n}function hd(e,t){let n=Cu(e);if(ju(e))return n;if(!Du(e)){let t=Hu(e);for(;t&&!zu(t);){if(Eu(t)&&!pd(t))return t;t=Hu(t)}return n}let r=md(e,t);for(;r&&Au(r)&&pd(r);)r=md(r,t);return r&&zu(r)&&pd(r)&&!Iu(r)?n:r||Lu(e)||n}var gd=async function(e){let t=this.getOffsetParent||hd,n=this.getDimensions,r=await n(e.floating);return{reference:fd(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function _d(e){return Bu(e).direction===`rtl`}var vd={convertOffsetParentRelativeRectToViewportRelativeRect:td,getDocumentElement:wu,getClippingRect:ud,getOffsetParent:hd,getElementRects:gd,getClientRects:nd,getDimensions:dd,getScale:Ju,isElement:Eu,isRTL:_d};function yd(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function bd(e,t){let n=null,r,i=wu(e);function a(){var e;clearTimeout(r),(e=n)==null||e.disconnect(),n=null}function o(s,c){s===void 0&&(s=!1),c===void 0&&(c=1),a();let l=e.getBoundingClientRect(),{left:u,top:d,width:f,height:p}=l;if(s||t(),!f||!p)return;let m=Il(d),h=Il(i.clientWidth-(u+f)),g=Il(i.clientHeight-(d+p)),_=Il(u),v={rootMargin:-m+`px `+-h+`px `+-g+`px `+-_+`px`,threshold:Pl(0,Nl(1,c))||1},y=!0;function b(t){let n=t[0].intersectionRatio;if(n!==c){if(!y)return o();n?o(!1,n):r=setTimeout(()=>{o(!1,1e-7)},1e3)}n===1&&!yd(l,e.getBoundingClientRect())&&o(),y=!1}try{n=new IntersectionObserver(b,{...v,root:i.ownerDocument})}catch{n=new IntersectionObserver(b,v)}n.observe(e)}return o(!0),a}function xd(e,t,n,r){r===void 0&&(r={});let{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:o=typeof ResizeObserver==`function`,layoutShift:s=typeof IntersectionObserver==`function`,animationFrame:c=!1}=r,l=qu(e),u=i||a?[...l?Wu(l):[],...t?Wu(t):[]]:[];
vendor: 4,428 bytes, line 61
61u.forEach(e=>{i&&e.addEventListener(`scroll`,n,{passive:!0}),a&&e.addEventListener(`resize`,n)});let d=l&&s?bd(l,n):null,f=-1,p=null;o&&(p=new ResizeObserver(e=>{let[r]=e;r&&r.target===l&&p&&t&&(p.unobserve(t),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var e;(e=p)==null||e.observe(t)})),n()}),l&&!c&&p.observe(l),t&&p.observe(t));let m,h=c?Qu(e):null;c&&g();function g(){let t=Qu(e);h&&!yd(h,t)&&n(),h=t,m=requestAnimationFrame(g)}return n(),()=>{var e;u.forEach(e=>{i&&e.removeEventListener(`scroll`,n),a&&e.removeEventListener(`resize`,n)}),d?.(),(e=p)==null||e.disconnect(),p=null,c&&cancelAnimationFrame(m)}}var Sd=_u,Cd=vu,wd=du,Td=bu,Ed=mu,Dd=uu,Od=yu,kd=(e,t,n)=>{let r=new Map,i={platform:vd,...n},a={...i.platform,_c:r};return lu(e,t,{...i,platform:a})},Ad=typeof document<`u`?_.useLayoutEffect:function(){};function jd(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e==`function`&&e.toString()===t.toString())return!0;let n,r,i;if(e&&t&&typeof e==`object`){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!jd(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){let n=i[r];if(!(n===`_owner`&&e.$$typeof)&&!jd(e[n],t[n]))return!1}return!0}return e!==e&&t!==t}function Md(e){return typeof window>`u`?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Nd(e,t){let n=Md(e);return Math.round(t*n)/n}function Pd(e){let t=_.useRef(e);return Ad(()=>{t.current=e}),t}function Fd(e){e===void 0&&(e={});let{placement:t=`bottom`,strategy:n=`absolute`,middleware:r=[],platform:i,elements:{reference:a,floating:o}={},transform:s=!0,whileElementsMounted:c,open:l}=e,[u,d]=_.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[f,p]=_.useState(r);jd(f,r)||p(r);let[m,h]=_.useState(null),[g,y]=_.useState(null),b=_.useCallback(e=>{e!==w.current&&(w.current=e,h(e))},[]),x=_.useCallback(e=>{e!==T.current&&(T.current=e,y(e))},[]),S=a||m,C=o||g,w=_.useRef(null),T=_.useRef(null),E=_.useRef(u),D=c!=null,O=Pd(c),k=Pd(i),A=Pd(l),j=_.useCallback(()=>{if(!w.current||!T.current)return;let e={placement:t,strategy:n,middleware:f};k.current&&(e.platform=k.current),kd(w.current,T.current,e).then(e=>{let t={...e,isPositioned:A.current!==!1};M.current&&!jd(E.current,t)&&(E.current=t,v.flushSync(()=>{d(t)}))})},[f,t,n,k,A]);Ad(()=>{l===!1&&E.current.isPositioned&&(E.current.isPositioned=!1,d(e=>({...e,isPositioned:!1})))},[l]);let M=_.useRef(!1);Ad(()=>(M.current=!0,()=>{M.current=!1}),[]),Ad(()=>{if(S&&(w.current=S),C&&(T.current=C),S&&C){if(O.current)return O.current(S,C,j);j()}},[S,C,j,O,D]);let ee=_.useMemo(()=>({reference:w,floating:T,setReference:b,setFloating:x}),[b,x]),N=_.useMemo(()=>({reference:S,floating:C}),[S,C]),P=_.useMemo(()=>{let e={position:n,left:0,top:0};if(!N.floating)return e;let t=Nd(N.floating,u.x),r=Nd(N.floating,u.y);return s?{...e,transform:`translate(`+t+`px, `+r+`px)`,...Md(N.floating)>=1.5&&{willChange:`transform`}}:{position:n,left:t,top:r}},[n,s,N.floating,u.x,u.y]);return _.useMemo(()=>({...u,update:j,refs:ee,elements:N,floatingStyles:P}),[u,j,ee,N,P])}var Id=e=>{function t(e){return{}.hasOwnProperty.call(e,`current`)}return{name:`arrow`,options:e,fn(n){let{element:r,padding:i}=typeof e==`function`?e(n):e;return r&&t(r)?r.current==null?{}:Dd({element:r.current,padding:i}).fn(n):r?Dd({element:r,padding:i}).fn(n):{}}}},Ld=(e,t)=>{let n=Sd(e);return{name:n.name,fn:n.fn,options:[e,t]}},Rd=(e,t)=>{let n=Cd(e);return{name:n.name,fn:n.fn,options:[e,t]}},zd=(e,t)=>({fn:Od(e).fn,options:[e,t]}),Bd=(e,t)=>{let n=wd(e);return{name:n.name,fn:n.fn,options:[e,t]}},Vd=(e,t)=>{let n=Td(e);return{name:n.name,fn:n.fn,options:[e,t]}},Hd=(e,t)=>{let n=Ed(e);return{name:n.name,fn:n.fn,options:[e,t]}},Ud=(e,t)=>{let n=Id(e);return{name:n.name,fn:n.fn,options:[e,t]}},Wd=`Arrow`,Gd=_.forwardRef((e,t)=>{let{children:n,width:r=10,height:i=5,...a}=e;return(0,L.jsx)(sa.svg,{...a,ref:t,width:r,height:i,viewBox:`0 0 30 10`,preserveAspectRatio:`none`,children:e.asChild?n:(0,L.jsx)(`polygon`,{points:`0,0 30,0 15,10`})})});Gd.displayName=Wd;var Kd=Gd,qd=`Popper`,[Jd,Yd]=ma(qd),[Xd,Zd]=Jd(qd),Qd=e=>{let{__scopePopper:t,children:n}=e,[r,i]=_.useState(null);return(0,L.jsx)(Xd,{scope:t,anchor:r,onAnchorChange:i,children:n})};Qd.displayName=qd;var $d=`PopperAnchor`,ef=_.forwardRef((e,t)=>
vendor: 5,166 bytes, line 61
61{let{__scopePopper:n,virtualRef:r,...i}=e,a=Zd($d,n),o=_.useRef(null),s=Qi(t,o),c=_.useRef(null);return _.useEffect(()=>{let e=c.current;c.current=r?.current||o.current,e!==c.current&&a.onAnchorChange(c.current)}),r?null:(0,L.jsx)(sa.div,{...i,ref:s})});ef.displayName=$d;var tf=`PopperContent`,[nf,rf]=Jd(tf),af=_.forwardRef((e,t)=>{let{__scopePopper:n,side:r=`bottom`,sideOffset:i=0,align:a=`center`,alignOffset:o=0,arrowPadding:s=0,avoidCollisions:c=!0,collisionBoundary:l=[],collisionPadding:u=0,sticky:d=`partial`,hideWhenDetached:f=!1,updatePositionStrategy:p=`optimized`,onPlaced:m,...h}=e,g=Zd(tf,n),[v,y]=_.useState(null),b=Qi(t,e=>y(e)),[x,S]=_.useState(null),C=hl(x),w=C?.width??0,T=C?.height??0,E=r+(a===`center`?``:`-`+a),D=typeof u==`number`?u:{top:0,right:0,bottom:0,left:0,...u},O=Array.isArray(l)?l:[l],k=O.length>0,A={padding:D,boundary:O.filter(lf),altBoundary:k},{refs:j,floatingStyles:M,placement:ee,isPositioned:N,middlewareData:P}=Fd({strategy:`fixed`,placement:E,whileElementsMounted:(...e)=>xd(...e,{animationFrame:p===`always`}),elements:{reference:g.anchor},middleware:[Ld({mainAxis:i+T,alignmentAxis:o}),c&&Rd({mainAxis:!0,crossAxis:!1,limiter:d===`partial`?zd():void 0,...A}),c&&Bd({...A}),Vd({...A,apply:({elements:e,rects:t,availableWidth:n,availableHeight:r})=>{let{width:i,height:a}=t.reference,o=e.floating.style;o.setProperty(`--radix-popper-available-width`,`${n}px`),o.setProperty(`--radix-popper-available-height`,`${r}px`),o.setProperty(`--radix-popper-anchor-width`,`${i}px`),o.setProperty(`--radix-popper-anchor-height`,`${a}px`)}}),x&&Ud({element:x,padding:s}),uf({arrowWidth:w,arrowHeight:T}),f&&Hd({strategy:`referenceHidden`,...A})]}),[F,I]=df(ee),te=Ga(m);_a(()=>{N&&te?.()},[N,te]);let ne=P.arrow?.x,re=P.arrow?.y,ie=P.arrow?.centerOffset!==0,[ae,oe]=_.useState();return _a(()=>{v&&oe(window.getComputedStyle(v).zIndex)},[v]),(0,L.jsx)(`div`,{ref:j.setFloating,"data-radix-popper-content-wrapper":``,style:{...M,transform:N?M.transform:`translate(0, -200%)`,minWidth:`max-content`,zIndex:ae,"--radix-popper-transform-origin":[P.transformOrigin?.x,P.transformOrigin?.y].join(` `),...P.hide?.referenceHidden&&{visibility:`hidden`,pointerEvents:`none`}},dir:e.dir,children:(0,L.jsx)(nf,{scope:n,placedSide:F,onArrowChange:S,arrowX:ne,arrowY:re,shouldHideArrow:ie,children:(0,L.jsx)(sa.div,{"data-side":F,"data-align":I,...h,ref:b,style:{...h.style,animation:N?void 0:`none`}})})})});af.displayName=tf;var of=`PopperArrow`,sf={top:`bottom`,right:`left`,bottom:`top`,left:`right`},cf=_.forwardRef(function(e,t){let{__scopePopper:n,...r}=e,i=rf(of,n),a=sf[i.placedSide];return(0,L.jsx)(`span`,{ref:i.onArrowChange,style:{position:`absolute`,left:i.arrowX,top:i.arrowY,[a]:0,transformOrigin:{top:``,right:`0 0`,bottom:`center 0`,left:`100% 0`}[i.placedSide],transform:{top:`translateY(100%)`,right:`translateY(50%) rotate(90deg) translateX(-50%)`,bottom:`rotate(180deg)`,left:`translateY(50%) rotate(-90deg) translateX(50%)`}[i.placedSide],visibility:i.shouldHideArrow?`hidden`:void 0},children:(0,L.jsx)(Kd,{...r,ref:t,style:{...r.style,display:`block`}})})});cf.displayName=of;function lf(e){return e!==null}var uf=e=>({name:`transformOrigin`,options:e,fn(t){let{placement:n,rects:r,middlewareData:i}=t,a=i.arrow?.centerOffset!==0,o=a?0:e.arrowWidth,s=a?0:e.arrowHeight,[c,l]=df(n),u={start:`0%`,center:`50%`,end:`100%`}[l],d=(i.arrow?.x??0)+o/2,f=(i.arrow?.y??0)+s/2,p=``,m=``;return c===`bottom`?(p=a?u:`${d}px`,m=`${-s}px`):c===`top`?(p=a?u:`${d}px`,m=`${r.floating.height+s}px`):c===`right`?(p=`${-s}px`,m=a?u:`${f}px`):c===`left`&&(p=`${r.floating.width+s}px`,m=a?u:`${f}px`),{data:{x:p,y:m}}}});function df(e){let[t,n=`center`]=e.split(`-`);return[t,n]}var ff=Qd,pf=ef,mf=af,hf=cf,gf=`rovingFocusGroup.onEntryFocus`,_f={bubbles:!1,cancelable:!0},vf=`RovingFocusGroup`,[yf,bf,xf]=ga(vf),[Sf,Cf]=ma(vf,[xf]),[wf,Tf]=Sf(vf),Ef=_.forwardRef((e,t)=>(0,L.jsx)(yf.Provider,{scope:e.__scopeRovingFocusGroup,children:(0,L.jsx)(yf.Slot,{scope:e.__scopeRovingFocusGroup,children:(0,L.jsx)(Df,{...e,ref:t})})}));Ef.displayName=vf;var Df=_.forwardRef((e,t)=>{let{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:a,currentTabStopId:o,defaultCurrentTabStopId:s,onCurrentTabStopIdChange:c,onEntryFocus:l,preventScrollOnEntryFocus:u=!1,...d}=e,f=_.useRef(null),p=Qi(t,f),m=Wa(a),[h,g]=ya({prop:o,defaultProp:s??null,onChange:c,caller:vf}),[v,y]=_.useState(!1),b=Ga(l),x=bf(n),S=_.useRef(!1),[C,w]=_.useState(0);return _.useEffect(()=>{let e=f.current;if(e)return e.addEventListener(gf,b),()=>e.removeEventListener(gf,b)},[b]),(0,L.jsx)(wf,{scope:n,orientation:r,dir:m,loop:i,currentTabStopId:h,onItemFocus:_.useCallback(e=>g(e),[g]),onItemShiftTab:_.useCallback(()=>y(!0),[]),onFocusableItemAdd:_.useCallback(()=>w(e=>e+1),[]),onFocusableItemRemove:_.useCallback(()=>w(e=>e-1),[]),children:(0,L.jsx)(sa.div,{tabIndex:v||C===0?-1:0,"data-orientation":r,...d,ref:p,style:{outline:`none`,...e.style},onMouseDown:B(e.onMouseDown,()=>{S.current=!0}),onFocus:B(e.onFocus,e=>{let t=!S.current;if(e.target===e.currentTarget&&t&&!v){let t=new CustomEvent(gf,_f);if(e.currentTarget.dispatchEvent(t),!t.defaultPrevented){let e=x().filter(e=>
61e.focusable);Nf([e.find(e=>e.active),e.find(e=>e.id===h),...e].filter(Boolean).map(e=>e.ref.current),u)}}S.current=!1}),onBlur:B(e.onBlur,()=>y(!1))})})}),Of=`RovingFocusGroupItem`,kf=_.forwardRef((e,t)=>{let{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:a,children:o,...s}=e,c=ka(),l=a||c,u=Tf(Of,n),d=u.currentTabStopId===l,f=bf(n),{onFocusableItemAdd:p,onFocusableItemRemove:m,currentTabStopId:h}=u;return _.useEffect(()=>{if(r)return p(),()=>m()},[r,p,m]),(0,L.jsx)(yf.ItemSlot,{scope:n,id:l,focusable:r,active:i,children:(0,L.jsx)(sa.span,{tabIndex:d?0:-1,"data-orientation":u.orientation,...s,ref:t,onMouseDown:B(e.onMouseDown,e=>{r?u.onItemFocus(l):e.preventDefault()}),onFocus:B(e.onFocus,()=>u.onItemFocus(l)),onKeyDown:B(e.onKeyDown,e=>{if(e.key===`Tab`&&e.shiftKey){u.onItemShiftTab();return}if(e.target!==e.currentTarget)return;let t=Mf(e,u.orientation,u.dir);if(t!==void 0){if(e.metaKey||e.ctrlKey||e.altKey||e.shiftKey)return;e.preventDefault();let n=f().filter(e=>e.focusable).map(e=>e.ref.current);if(t===`last`)n.reverse();else if(t===`prev`||t===`next`){t===`prev`&&n.reverse();let r=n.indexOf(e.currentTarget);n=u.loop?Pf(n,r+1):n.slice(r+1)}setTimeout(()=>Nf(n))}}),children:typeof o==`function`?o({isCurrentTabStop:d,hasTabStop:h!=null}):o})})});kf.displayName=Of;var Af={ArrowLeft:`prev`,ArrowUp:`prev`,ArrowRight:`next`,ArrowDown:`next`,PageUp:`first`,Home:`first`,PageDown:`last`,End:`last`};function jf(e,t){return t===`rtl`?e===`ArrowLeft`?`ArrowRight`:e===`ArrowRight`?`ArrowLeft`:e:e}function Mf(e,t,n){let r=jf(e.key,n);if(!(t===`vertical`&&[`ArrowLeft`,`ArrowRight`].includes(r))&&!(t===`horizontal`&&[`ArrowUp`,`ArrowDown`].includes(r)))return Af[r]}function Nf(e,t=!1){let n=document.activeElement;for(let r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function Pf(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Ff=Ef,If=kf,Lf=[`Enter`,` `],Rf=[`ArrowDown`,`PageUp`,`Home`],zf=[`ArrowUp`,`PageDown`,`End`],Bf=[...Rf,...zf],Vf={ltr:[...Lf,`ArrowRight`],rtl:[...Lf,`ArrowLeft`]},Hf={ltr:[`ArrowLeft`],rtl:[`ArrowRight`]},Uf=`Menu`,[Wf,Gf,Kf]=ga(Uf),[qf,Jf]=ma(Uf,[Kf,Yd,Cf]),Yf=Yd(),Xf=Cf(),[Zf,Qf]=qf(Uf),[$f,ep]=qf(Uf),tp=e=>{let{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:a,modal:o=!0}=e,s=Yf(t),[c,l]=_.useState(null),u=_.useRef(!1),d=Ga(a),f=Wa(i);return _.useEffect(()=>{let e=()=>{u.current=!0,document.addEventListener(`pointerdown`,t,{capture:!0,once:!0}),document.addEventListener(`pointermove`,t,{capture:!0,once:!0})},t=()=>u.current=!1;return document.addEventListener(`keydown`,e,{capture:!0}),()=>{document.removeEventListener(`keydown`,e,{capture:!0}),document.removeEventListener(`pointerdown`,t,{capture:!0}),document.removeEventListener(`pointermove`,t,{capture:!0})}},[]),(0,L.jsx)(ff,{...s,children:(0,L.jsx)(Zf,{scope:t,open:n,onOpenChange:d,content:c,onContentChange:l,children:(0,L.jsx)($f,{scope:t,onClose:_.useCallback(()=>d(!1),[d]),isUsingKeyboardRef:u,dir:f,modal:o,children:r})})})};tp.displayName=Uf;var np=`MenuAnchor`,rp=_.forwardRef((e,t)=>{let{__scopeMenu:n,...r}=e,i=Yf(n);return(0,L.jsx)(pf,{...i,...r,ref:t})});rp.displayName=np;var ip=`MenuPortal`,[ap,op]=qf(ip,{forceMount:void 0}),sp=e=>{let{__scopeMenu:t,forceMount:n,children:r,container:i}=e,a=Qf(ip,t);return(0,L.jsx)(ap,{scope:t,forceMount:n,children:(0,L.jsx)(Ca,{present:n||a.open,children:(0,L.jsx)(wo,{asChild:!0,container:i,children:r})})})};sp.displayName=ip;var cp=`MenuContent`,[lp,up]=qf(cp),dp=_.forwardRef((e,t)=>{let n=op(cp,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,a=Qf(cp,e.__scopeMenu),o=ep(cp,e.__scopeMenu);return(0,L.jsx)(Wf.Provider,{scope:e.__scopeMenu,children:(0,L.jsx)(Ca,{present:r||a.open,children:(0,L.jsx)(Wf.Slot,{scope:e.__scopeMenu,children:o.modal?(0,L.jsx)(fp,{...i,ref:t}):(0,L.jsx)(pp,{...i,ref:t})})})})}),fp=_.forwardRef((e,t)=>{let n=Qf(cp,e.__scopeMenu),r=_.useRef(null),i=Qi(t,r);return _.useEffect(()=>{let e=r.current;if(e)return Gs(e)},[]),(0,L.jsx)(hp,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:B(e.onFocusOutside,e=>e.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),pp=_.forwardRef((e,t)=>
vendor: 8,471 bytes, line 61
61{let n=Qf(cp,e.__scopeMenu);return(0,L.jsx)(hp,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),mp=$i(`MenuContent.ScrollLock`),hp=_.forwardRef((e,t)=>{let{__scopeMenu:n,loop:r=!1,trapFocus:i,onOpenAutoFocus:a,onCloseAutoFocus:o,disableOutsidePointerEvents:s,onEntryFocus:c,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:f,onDismiss:p,disableOutsideScroll:m,...h}=e,g=Qf(cp,n),v=ep(cp,n),y=Yf(n),b=Xf(n),x=Gf(n),[S,C]=_.useState(null),w=_.useRef(null),T=Qi(t,w,g.onContentChange),E=_.useRef(0),D=_.useRef(``),O=_.useRef(0),k=_.useRef(null),A=_.useRef(`right`),j=_.useRef(0),M=m?Is:_.Fragment,ee=m?{as:mp,allowPinchZoom:!0}:void 0,N=e=>{let t=D.current+e,n=x().filter(e=>!e.disabled),r=document.activeElement,i=n.find(e=>e.ref.current===r)?.textValue,a=$p(n.map(e=>e.textValue),t,i),o=n.find(e=>e.textValue===a)?.ref.current;(function e(t){D.current=t,window.clearTimeout(E.current),t!==``&&(E.current=window.setTimeout(()=>e(``),1e3))})(t),o&&setTimeout(()=>o.focus())};_.useEffect(()=>()=>window.clearTimeout(E.current),[]),Eo();let P=_.useCallback(e=>A.current===k.current?.side&&tm(e,k.current?.area),[]);return(0,L.jsx)(lp,{scope:n,searchRef:D,onItemEnter:_.useCallback(e=>{P(e)&&e.preventDefault()},[P]),onItemLeave:_.useCallback(e=>{P(e)||(w.current?.focus(),C(null))},[P]),onTriggerLeave:_.useCallback(e=>{P(e)&&e.preventDefault()},[P]),pointerGraceTimerRef:O,onPointerGraceIntentChange:_.useCallback(e=>{k.current=e},[]),children:(0,L.jsx)(M,{...ee,children:(0,L.jsx)(uo,{asChild:!0,trapped:i,onMountAutoFocus:B(a,e=>{e.preventDefault(),w.current?.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:(0,L.jsx)($a,{asChild:!0,disableOutsidePointerEvents:s,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:f,onDismiss:p,children:(0,L.jsx)(Ff,{asChild:!0,...b,dir:v.dir,orientation:`vertical`,loop:r,currentTabStopId:S,onCurrentTabStopIdChange:C,onEntryFocus:B(c,e=>{v.isUsingKeyboardRef.current||e.preventDefault()}),preventScrollOnEntryFocus:!0,children:(0,L.jsx)(mf,{role:`menu`,"aria-orientation":`vertical`,"data-state":Jp(g.open),"data-radix-menu-content":``,dir:v.dir,...y,...h,ref:T,style:{outline:`none`,...h.style},onKeyDown:B(h.onKeyDown,e=>{let t=e.target.closest(`[data-radix-menu-content]`)===e.currentTarget,n=e.ctrlKey||e.altKey||e.metaKey,r=e.key.length===1;t&&(e.key===`Tab`&&e.preventDefault(),!n&&r&&N(e.key));let i=w.current;if(e.target!==i||!Bf.includes(e.key))return;e.preventDefault();let a=x().filter(e=>!e.disabled).map(e=>e.ref.current);zf.includes(e.key)&&a.reverse(),Zp(a)}),onBlur:B(e.onBlur,e=>{e.currentTarget.contains(e.target)||(window.clearTimeout(E.current),D.current=``)}),onPointerMove:B(e.onPointerMove,nm(e=>{let t=e.target,n=j.current!==e.clientX;e.currentTarget.contains(t)&&n&&(A.current=e.clientX>j.current?`right`:`left`,j.current=e.clientX)}))})})})})})})});dp.displayName=cp;var gp=`MenuGroup`,_p=_.forwardRef((e,t)=>{let{__scopeMenu:n,...r}=e;return(0,L.jsx)(sa.div,{role:`group`,...r,ref:t})});_p.displayName=gp;var vp=`MenuLabel`,yp=_.forwardRef((e,t)=>{let{__scopeMenu:n,...r}=e;return(0,L.jsx)(sa.div,{...r,ref:t})});yp.displayName=vp;var bp=`MenuItem`,xp=`menu.itemSelect`,Sp=_.forwardRef((e,t)=>{let{disabled:n=!1,onSelect:r,...i}=e,a=_.useRef(null),o=ep(bp,e.__scopeMenu),s=up(bp,e.__scopeMenu),c=Qi(t,a),l=_.useRef(!1),u=()=>{let e=a.current;if(!n&&e){let t=new CustomEvent(xp,{bubbles:!0,cancelable:!0});e.addEventListener(xp,e=>r?.(e),{once:!0}),ca(e,t),t.defaultPrevented?l.current=!1:o.onClose()}};return(0,L.jsx)(Cp,{...i,ref:c,disabled:n,onClick:B(e.onClick,u),onPointerDown:t=>{e.onPointerDown?.(t),l.current=!0},onPointerUp:B(e.onPointerUp,e=>{l.current||e.currentTarget?.click()}),onKeyDown:B(e.onKeyDown,e=>{let t=s.searchRef.current!==``;n||t&&e.key===` `||Lf.includes(e.key)&&(e.currentTarget.click(),e.preventDefault())})})});Sp.displayName=bp;var Cp=_.forwardRef((e,t)=>{let{__scopeMenu:n,disabled:r=!1,textValue:i,...a}=e,o=up(bp,n),s=Xf(n),c=_.useRef(null),l=Qi(t,c),[u,d]=_.useState(!1),[f,p]=_.useState(``);return _.useEffect(()=>{let e=c.current;e&&p((e.textContent??``).trim())},[a.children]),(0,L.jsx)(Wf.ItemSlot,{scope:n,disabled:r,textValue:i??f,children:(0,L.jsx)(If,{asChild:!0,...s,focusable:!r,children:(0,L.jsx)(sa.div,{role:`menuitem`,"data-highlighted":u?``:void 0,"aria-disabled":r||void 0,"data-disabled":r?``:void 0,...a,ref:l,onPointerMove:B(e.onPointerMove,nm(e=>{r?o.onItemLeave(e):(o.onItemEnter(e),e.defaultPrevented||e.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:B(e.onPointerLeave,nm(e=>o.onItemLeave(e))),onFocus:B(e.onFocus,()=>d(!0)),onBlur:B(e.onBlur,()=>d(!1))})})})}),wp=`MenuCheckboxItem`,Tp=_.forwardRef((e,t)=>{let{checked:n=!1,onCheckedChange:r,...i}=e;return(0,L.jsx)(Np,{scope:e.__scopeMenu,checked:n,children:(0,L.jsx)(Sp,{role:`menuitemcheckbox`,"aria-checked":Yp(n)?`mixed`:n,...i,ref:t,"data-state":Xp(n),onSelect:B(i.onSelect,()=>r?.(Yp(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Tp.displayName=wp;var Ep=`MenuRadioGroup`,[Dp,Op]=qf(Ep,{value:void 0,onValueChange:()=>{}}),kp=_.forwardRef((e,t)=>{let{value:n,onValueChange:r,...i}=e,a=Ga(r);return(0,L.jsx)(Dp,{scope:e.__scopeMenu,value:n,onValueChange:a,children:(0,L.jsx)(_p,{...i,ref:t})})});kp.displayName=Ep;var Ap=`MenuRadioItem`,jp=_.forwardRef((e,t)=>{let{value:n,...r}=e,i=Op(Ap,e.__scopeMenu),a=n===i.value;return(0,L.jsx)(Np,{scope:e.__scopeMenu,checked:a,children:(0,L.jsx)(Sp,{role:`menuitemradio`,"aria-checked":a,...r,ref:t,"data-state":Xp(a),onSelect:B(r.onSelect,()=>i.onValueChange?.(n),{checkForDefaultPrevented:!1})})})});jp.displayName=Ap;var Mp=`MenuItemIndicator`,[Np,Pp]=qf(Mp,{checked:!1}),Fp=_.forwardRef((e,t)=>{let{__scopeMenu:n,forceMount:r,...i}=e,a=Pp(Mp,n);return(0,L.jsx)(Ca,{present:r||Yp(a.checked)||a.checked===!0,children:(0,L.jsx)(sa.span,{...i,ref:t,"data-state":Xp(a.checked)})})});Fp.displayName=Mp;var Ip=`MenuSeparator`,Lp=_.forwardRef((e,t)=>{let{__scopeMenu:n,...r}=e;return(0,L.jsx)(sa.div,{role:`separator`,"aria-orientation":`horizontal`,...r,ref:t})});Lp.displayName=Ip;var Rp=`MenuArrow`,zp=_.forwardRef((e,t)=>{let{__scopeMenu:n,...r}=e,i=Yf(n);return(0,L.jsx)(hf,{...i,...r,ref:t})});zp.displayName=Rp;var Bp=`MenuSub`,[Vp,Hp]=qf(Bp),Up=e=>{let{__scopeMenu:t,children:n,open:r=!1,onOpenChange:i}=e,a=Qf(Bp,t),o=Yf(t),[s,c]=_.useState(null),[l,u]=_.useState(null),d=Ga(i);return _.useEffect(()=>(a.open===!1&&d(!1),()=>d(!1)),[a.open,d]),(0,L.jsx)(ff,{...o,children:(0,L.jsx)(Zf,{scope:t,open:r,onOpenChange:d,content:l,onContentChange:u,children:(0,L.jsx)(Vp,{scope:t,contentId:ka(),triggerId:ka(),trigger:s,onTriggerChange:c,children:n})})})};Up.displayName=Bp;var Wp=`MenuSubTrigger`,Gp=_.forwardRef((e,t)=>{let n=Qf(Wp,e.__scopeMenu),r=ep(Wp,e.__scopeMenu),i=Hp(Wp,e.__scopeMenu),a=up(Wp,e.__scopeMenu),o=_.useRef(null),{pointerGraceTimerRef:s,onPointerGraceIntentChange:c}=a,l={__scopeMenu:e.__scopeMenu},u=_.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return _.useEffect(()=>u,[u]),_.useEffect(()=>{let e=s.current;return()=>{window.clearTimeout(e),c(null)}},[s,c]),(0,L.jsx)(rp,{asChild:!0,...l,children:(0,L.jsx)(Cp,{id:i.triggerId,"aria-haspopup":`menu`,"aria-expanded":n.open,"aria-controls":i.contentId,"data-state":Jp(n.open),...e,ref:Zi(t,i.onTriggerChange),onClick:t=>{e.onClick?.(t),!(e.disabled||t.defaultPrevented)&&(t.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:B(e.onPointerMove,nm(t=>{a.onItemEnter(t),!t.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(a.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),u()},100))})),onPointerLeave:B(e.onPointerLeave,nm(e=>{u();let t=n.content?.getBoundingClientRect();if(t){let r=n.content?.dataset.side,i=r===`right`,o=i?-5:5,c=t[i?`left`:`right`],l=t[i?`right`:`left`];a.onPointerGraceIntentChange({area:[{x:e.clientX+o,y:e.clientY},{x:c,y:t.top},{x:l,y:t.top},{x:l,y:t.bottom},{x:c,y:t.bottom}],side:r}),window.clearTimeout(s.current),s.current=window.setTimeout(()=>a.onPointerGraceIntentChange(null),300)}else{if(a.onTriggerLeave(e),e.defaultPrevented)return;a.onPointerGraceIntentChange(null)}})),onKeyDown:B(e.onKeyDown,t=>{let i=a.searchRef.current!==``;e.disabled||i&&t.key===` `||Vf[r.dir].includes(t.key)&&(n.onOpenChange(!0),n.content?.focus(),t.preventDefault())})})})});Gp.displayName=Wp;var Kp=`MenuSubContent`,qp=_.forwardRef((e,t)=>
61{let n=op(cp,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,a=Qf(cp,e.__scopeMenu),o=ep(cp,e.__scopeMenu),s=Hp(Kp,e.__scopeMenu),c=_.useRef(null),l=Qi(t,c);return(0,L.jsx)(Wf.Provider,{scope:e.__scopeMenu,children:(0,L.jsx)(Ca,{present:r||a.open,children:(0,L.jsx)(Wf.Slot,{scope:e.__scopeMenu,children:(0,L.jsx)(hp,{id:s.contentId,"aria-labelledby":s.triggerId,...i,ref:l,align:`start`,side:o.dir===`rtl`?`left`:`right`,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:e=>{o.isUsingKeyboardRef.current&&c.current?.focus(),e.preventDefault()},onCloseAutoFocus:e=>e.preventDefault(),onFocusOutside:B(e.onFocusOutside,e=>{e.target!==s.trigger&&a.onOpenChange(!1)}),onEscapeKeyDown:B(e.onEscapeKeyDown,e=>{o.onClose(),e.preventDefault()}),onKeyDown:B(e.onKeyDown,e=>{let t=e.currentTarget.contains(e.target),n=Hf[o.dir].includes(e.key);t&&n&&(a.onOpenChange(!1),s.trigger?.focus(),e.preventDefault())})})})})})});qp.displayName=Kp;function Jp(e){return e?`open`:`closed`}function Yp(e){return e===`indeterminate`}function Xp(e){return Yp(e)?`indeterminate`:e?`checked`:`unchecked`}function Zp(e){let t=document.activeElement;for(let n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function Qp(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function $p(e,t,n){let r=t.length>1&&Array.from(t).every(e=>e===t[0])?t[0]:t,i=n?e.indexOf(n):-1,a=Qp(e,Math.max(i,0));r.length===1&&(a=a.filter(e=>e!==n));let o=a.find(e=>e.toLowerCase().startsWith(r.toLowerCase()));return o===n?void 0:o}function em(e,t){let{x:n,y:r}=e,i=!1;for(let e=0,a=t.length-1;e<t.length;a=e++){let o=t[e],s=t[a],c=o.x,l=o.y,u=s.x,d=s.y;l>r!=d>r&&n<(u-c)*(r-l)/(d-l)+c&&(i=!i)}return i}function tm(e,t){return t?em({x:e.clientX,y:e.clientY},t):!1}function nm(e){return t=>t.pointerType===`mouse`?e(t):void 0}var rm=tp,im=rp,am=sp,om=dp,sm=_p,cm=yp,lm=Sp,um=Tp,dm=kp,fm=jp,pm=Fp,mm=Lp,hm=zp,gm=Up,_m=Gp,vm=qp,ym=`ContextMenu`,[bm,xm]=ma(ym,[Jf]),Sm=Jf(),[Cm,wm]=bm(ym),Tm=e=>{let{__scopeContextMenu:t,children:n,onOpenChange:r,dir:i,modal:a=!0}=e,[o,s]=_.useState(!1),c=Sm(t),l=Ga(r),u=_.useCallback(e=>{s(e),l(e)},[l]);return(0,L.jsx)(Cm,{scope:t,open:o,onOpenChange:u,modal:a,children:(0,L.jsx)(rm,{...c,dir:i,open:o,onOpenChange:u,modal:a,children:n})})};Tm.displayName=ym;var Em=`ContextMenuTrigger`,Dm=_.forwardRef((e,t)=>{let{__scopeContextMenu:n,disabled:r=!1,...i}=e,a=wm(Em,n),o=Sm(n),s=_.useRef({x:0,y:0}),c=_.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...s.current})}),l=_.useRef(0),u=_.useCallback(()=>window.clearTimeout(l.current),[]),d=e=>{s.current={x:e.clientX,y:e.clientY},a.onOpenChange(!0)};return _.useEffect(()=>u,[u]),_.useEffect(()=>void(r&&u()),[r,u]),(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(im,{...o,virtualRef:c}),(0,L.jsx)(sa.span,{"data-state":a.open?`open`:`closed`,"data-disabled":r?``:void 0,...i,ref:t,style:{WebkitTouchCallout:`none`,...e.style},onContextMenu:r?e.onContextMenu:B(e.onContextMenu,e=>{u(),d(e),e.preventDefault()}),onPointerDown:r?e.onPointerDown:B(e.onPointerDown,nh(e=>{u(),l.current=window.setTimeout(()=>d(e),700)})),onPointerMove:r?e.onPointerMove:B(e.onPointerMove,nh(u)),onPointerCancel:r?e.onPointerCancel:B(e.onPointerCancel,nh(u)),onPointerUp:r?e.onPointerUp:B(e.onPointerUp,nh(u))})]})});Dm.displayName=Em;var Om=`ContextMenuPortal`,km=e=>{let{__scopeContextMenu:t,...n}=e,r=Sm(t);return(0,L.jsx)(am,{...r,...n})};km.displayName=Om;var Am=`ContextMenuContent`,jm=_.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=wm(Am,n),a=Sm(n),o=_.useRef(!1);return(0,L.jsx)(om,{...a,...r,ref:t,side:`right`,sideOffset:2,align:`start`,onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),!t.defaultPrevented&&o.current&&t.preventDefault(),o.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),!t.defaultPrevented&&!i.modal&&(o.current=!0)},style:{...e.style,"--radix-context-menu-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-context-menu-content-available-width":`var(--radix-popper-available-width)`,"--radix-context-menu-content-available-height":`var(--radix-popper-available-height)`,"--radix-context-menu-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-context-menu-trigger-height":`var(--radix-popper-anchor-height)`}})});jm.displayName=Am;var Mm=`ContextMenuGroup`,Nm=_.forwardRef((e,t)=>
vendor: 4,726 bytes, line 61
61{let{__scopeContextMenu:n,...r}=e,i=Sm(n);return(0,L.jsx)(sm,{...i,...r,ref:t})});Nm.displayName=Mm;var Pm=`ContextMenuLabel`,Fm=_.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=Sm(n);return(0,L.jsx)(cm,{...i,...r,ref:t})});Fm.displayName=Pm;var Im=`ContextMenuItem`,Lm=_.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=Sm(n);return(0,L.jsx)(lm,{...i,...r,ref:t})});Lm.displayName=Im;var Rm=`ContextMenuCheckboxItem`,zm=_.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=Sm(n);return(0,L.jsx)(um,{...i,...r,ref:t})});zm.displayName=Rm;var Bm=`ContextMenuRadioGroup`,Vm=_.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=Sm(n);return(0,L.jsx)(dm,{...i,...r,ref:t})});Vm.displayName=Bm;var Hm=`ContextMenuRadioItem`,Um=_.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=Sm(n);return(0,L.jsx)(fm,{...i,...r,ref:t})});Um.displayName=Hm;var Wm=`ContextMenuItemIndicator`,Gm=_.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=Sm(n);return(0,L.jsx)(pm,{...i,...r,ref:t})});Gm.displayName=Wm;var Km=`ContextMenuSeparator`,qm=_.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=Sm(n);return(0,L.jsx)(mm,{...i,...r,ref:t})});qm.displayName=Km;var Jm=`ContextMenuArrow`,Ym=_.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=Sm(n);return(0,L.jsx)(hm,{...i,...r,ref:t})});Ym.displayName=Jm;var Xm=`ContextMenuSub`,Zm=e=>{let{__scopeContextMenu:t,children:n,onOpenChange:r,open:i,defaultOpen:a}=e,o=Sm(t),[s,c]=ya({prop:i,defaultProp:a??!1,onChange:r,caller:Xm});return(0,L.jsx)(gm,{...o,open:s,onOpenChange:c,children:n})};Zm.displayName=Xm;var Qm=`ContextMenuSubTrigger`,$m=_.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=Sm(n);return(0,L.jsx)(_m,{...i,...r,ref:t})});$m.displayName=Qm;var eh=`ContextMenuSubContent`,th=_.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=Sm(n);return(0,L.jsx)(vm,{...i,...r,ref:t,style:{...e.style,"--radix-context-menu-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-context-menu-content-available-width":`var(--radix-popper-available-width)`,"--radix-context-menu-content-available-height":`var(--radix-popper-available-height)`,"--radix-context-menu-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-context-menu-trigger-height":`var(--radix-popper-anchor-height)`}})});th.displayName=eh;function nh(e){return t=>t.pointerType===`mouse`?void 0:e(t)}var rh=Tm,ih=Dm,ah=km,oh=jm,sh=Lm,ch=qm,lh=`DropdownMenu`,[uh,dh]=ma(lh,[Jf]),fh=Jf(),[ph,mh]=uh(lh),hh=e=>{let{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:a,onOpenChange:o,modal:s=!0}=e,c=fh(t),l=_.useRef(null),[u,d]=ya({prop:i,defaultProp:a??!1,onChange:o,caller:lh});return(0,L.jsx)(ph,{scope:t,triggerId:ka(),triggerRef:l,contentId:ka(),open:u,onOpenChange:d,onOpenToggle:_.useCallback(()=>d(e=>!e),[d]),modal:s,children:(0,L.jsx)(rm,{...c,open:u,onOpenChange:d,dir:r,modal:s,children:n})})};hh.displayName=lh;var gh=`DropdownMenuTrigger`,_h=_.forwardRef((e,t)=>{let{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,a=mh(gh,n),o=fh(n);return(0,L.jsx)(im,{asChild:!0,...o,children:(0,L.jsx)(sa.button,{type:`button`,id:a.triggerId,"aria-haspopup":`menu`,"aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":a.open?`open`:`closed`,"data-disabled":r?``:void 0,disabled:r,...i,ref:Zi(t,a.triggerRef),onPointerDown:B(e.onPointerDown,e=>{!r&&e.button===0&&e.ctrlKey===!1&&(a.onOpenToggle(),a.open||e.preventDefault())}),onKeyDown:B(e.onKeyDown,e=>{r||([`Enter`,` `].includes(e.key)&&a.onOpenToggle(),e.key===`ArrowDown`&&a.onOpenChange(!0),[`Enter`,` `,`ArrowDown`].includes(e.key)&&e.preventDefault())})})})});_h.displayName=gh;var vh=`DropdownMenuPortal`,yh=e=>{let{__scopeDropdownMenu:t,...n}=e,r=fh(t);return(0,L.jsx)(am,{...r,...n})};yh.displayName=vh;var bh=`DropdownMenuContent`,xh=_.forwardRef((e,t)=>{let{__scopeDropdownMenu:n,...r}=e,i=mh(bh,n),a=fh(n),o=_.useRef(!1);return(0,L.jsx)(om,{id:i.contentId,"aria-labelledby":i.triggerId,...a,...r,ref:t,onCloseAutoFocus:B(e.onCloseAutoFocus,e=>{o.current||i.triggerRef.current?.focus(),o.current=!1,e.preventDefault()}),onInteractOutside:B(e.onInteractOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0,r=t.button===2||n;(!i.modal||r)&&(o.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-dropdown-menu-content-available-width":`var(--radix-popper-available-width)`,"--radix-dropdown-menu-content-available-height":`var(--radix-popper-available-height)`,"--radix-dropdown-menu-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-dropdown-menu-trigger-height":`var(--radix-popper-anchor-height)`}})});xh.displayName=bh;var Sh=`DropdownMenuGroup`,Ch=_.forwardRef((e,t)=>
vendor: 4,645 bytes, line 61
61{let{__scopeDropdownMenu:n,...r}=e,i=fh(n);return(0,L.jsx)(sm,{...i,...r,ref:t})});Ch.displayName=Sh;var wh=`DropdownMenuLabel`,Th=_.forwardRef((e,t)=>{let{__scopeDropdownMenu:n,...r}=e,i=fh(n);return(0,L.jsx)(cm,{...i,...r,ref:t})});Th.displayName=wh;var Eh=`DropdownMenuItem`,Dh=_.forwardRef((e,t)=>{let{__scopeDropdownMenu:n,...r}=e,i=fh(n);return(0,L.jsx)(lm,{...i,...r,ref:t})});Dh.displayName=Eh;var Oh=`DropdownMenuCheckboxItem`,kh=_.forwardRef((e,t)=>{let{__scopeDropdownMenu:n,...r}=e,i=fh(n);return(0,L.jsx)(um,{...i,...r,ref:t})});kh.displayName=Oh;var Ah=`DropdownMenuRadioGroup`,jh=_.forwardRef((e,t)=>{let{__scopeDropdownMenu:n,...r}=e,i=fh(n);return(0,L.jsx)(dm,{...i,...r,ref:t})});jh.displayName=Ah;var Mh=`DropdownMenuRadioItem`,Nh=_.forwardRef((e,t)=>{let{__scopeDropdownMenu:n,...r}=e,i=fh(n);return(0,L.jsx)(fm,{...i,...r,ref:t})});Nh.displayName=Mh;var Ph=`DropdownMenuItemIndicator`,Fh=_.forwardRef((e,t)=>{let{__scopeDropdownMenu:n,...r}=e,i=fh(n);return(0,L.jsx)(pm,{...i,...r,ref:t})});Fh.displayName=Ph;var Ih=`DropdownMenuSeparator`,Lh=_.forwardRef((e,t)=>{let{__scopeDropdownMenu:n,...r}=e,i=fh(n);return(0,L.jsx)(mm,{...i,...r,ref:t})});Lh.displayName=Ih;var Rh=`DropdownMenuArrow`,zh=_.forwardRef((e,t)=>{let{__scopeDropdownMenu:n,...r}=e,i=fh(n);return(0,L.jsx)(hm,{...i,...r,ref:t})});zh.displayName=Rh;var Bh=`DropdownMenuSubTrigger`,Vh=_.forwardRef((e,t)=>{let{__scopeDropdownMenu:n,...r}=e,i=fh(n);return(0,L.jsx)(_m,{...i,...r,ref:t})});Vh.displayName=Bh;var Hh=`DropdownMenuSubContent`,Uh=_.forwardRef((e,t)=>{let{__scopeDropdownMenu:n,...r}=e,i=fh(n);return(0,L.jsx)(vm,{...i,...r,ref:t,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-dropdown-menu-content-available-width":`var(--radix-popper-available-width)`,"--radix-dropdown-menu-content-available-height":`var(--radix-popper-available-height)`,"--radix-dropdown-menu-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-dropdown-menu-trigger-height":`var(--radix-popper-anchor-height)`}})});Uh.displayName=Hh;var Wh=hh,Gh=_h,Kh=yh,qh=xh,Jh=Th,Yh=Dh,Xh=Lh;function Zh(e,[t,n]){return Math.min(n,Math.max(t,e))}var Qh=`Popover`,[$h,eg]=ma(Qh,[Yd]),tg=Yd(),[ng,rg]=$h(Qh),ig=e=>{let{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:o=!1}=e,s=tg(t),c=_.useRef(null),[l,u]=_.useState(!1),[d,f]=ya({prop:r,defaultProp:i??!1,onChange:a,caller:Qh});return(0,L.jsx)(ff,{...s,children:(0,L.jsx)(ng,{scope:t,contentId:ka(),triggerRef:c,open:d,onOpenChange:f,onOpenToggle:_.useCallback(()=>f(e=>!e),[f]),hasCustomAnchor:l,onCustomAnchorAdd:_.useCallback(()=>u(!0),[]),onCustomAnchorRemove:_.useCallback(()=>u(!1),[]),modal:o,children:n})})};ig.displayName=Qh;var ag=`PopoverAnchor`,og=_.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=rg(ag,n),a=tg(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:s}=i;return _.useEffect(()=>(o(),()=>s()),[o,s]),(0,L.jsx)(pf,{...a,...r,ref:t})});og.displayName=ag;var sg=`PopoverTrigger`,cg=_.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=rg(sg,n),a=tg(n),o=Qi(t,i.triggerRef),s=(0,L.jsx)(sa.button,{type:`button`,"aria-haspopup":`dialog`,"aria-expanded":i.open,"aria-controls":i.contentId,"data-state":Cg(i.open),...r,ref:o,onClick:B(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?s:(0,L.jsx)(pf,{asChild:!0,...a,children:s})});cg.displayName=sg;var lg=`PopoverPortal`,[ug,dg]=$h(lg,{forceMount:void 0}),fg=e=>{let{__scopePopover:t,forceMount:n,children:r,container:i}=e,a=rg(lg,t);return(0,L.jsx)(ug,{scope:t,forceMount:n,children:(0,L.jsx)(Ca,{present:n||a.open,children:(0,L.jsx)(wo,{asChild:!0,container:i,children:r})})})};fg.displayName=lg;var pg=`PopoverContent`,mg=_.forwardRef((e,t)=>{let n=dg(pg,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,a=rg(pg,e.__scopePopover);return(0,L.jsx)(Ca,{present:r||a.open,children:a.modal?(0,L.jsx)(gg,{...i,ref:t}):(0,L.jsx)(_g,{...i,ref:t})})});mg.displayName=pg;var hg=$i(`PopoverContent.RemoveScroll`),gg=_.forwardRef((e,t)=>{let n=rg(pg,e.__scopePopover),r=_.useRef(null),i=Qi(t,r),a=_.useRef(!1);return _.useEffect(()=>{let e=r.current;if(e)return Gs(e)},[]),(0,L.jsx)(Is,{as:hg,allowPinchZoom:!0,children:(0,L.jsx)(vg,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:B(e.onCloseAutoFocus,e=>{e.preventDefault(),a.current||n.triggerRef.current?.focus()}),onPointerDownOutside:B(e.onPointerDownOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0;a.current=t.button===2||n},{checkForDefaultPrevented:!1}),onFocusOutside:B(e.onFocusOutside,e=>e.preventDefault(),{checkForDefaultPrevented:!1})})})}),_g=_.forwardRef((e,t)=>
61{let n=rg(pg,e.__scopePopover),r=_.useRef(!1),i=_.useRef(!1);return(0,L.jsx)(vg,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),t.defaultPrevented||(r.current||n.triggerRef.current?.focus(),t.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),t.defaultPrevented||(r.current=!0,t.detail.originalEvent.type===`pointerdown`&&(i.current=!0));let a=t.target;n.triggerRef.current?.contains(a)&&t.preventDefault(),t.detail.originalEvent.type===`focusin`&&i.current&&t.preventDefault()}})}),vg=_.forwardRef((e,t)=>{let{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,disableOutsidePointerEvents:o,onEscapeKeyDown:s,onPointerDownOutside:c,onFocusOutside:l,onInteractOutside:u,...d}=e,f=rg(pg,n),p=tg(n);return Eo(),(0,L.jsx)(uo,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:(0,L.jsx)($a,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:u,onEscapeKeyDown:s,onPointerDownOutside:c,onFocusOutside:l,onDismiss:()=>f.onOpenChange(!1),children:(0,L.jsx)(mf,{"data-state":Cg(f.open),role:`dialog`,id:f.contentId,...p,...d,ref:t,style:{...d.style,"--radix-popover-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-popover-content-available-width":`var(--radix-popper-available-width)`,"--radix-popover-content-available-height":`var(--radix-popper-available-height)`,"--radix-popover-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-popover-trigger-height":`var(--radix-popper-anchor-height)`}})})})}),yg=`PopoverClose`,bg=_.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=rg(yg,n);return(0,L.jsx)(sa.button,{type:`button`,...r,ref:t,onClick:B(e.onClick,()=>i.onOpenChange(!1))})});bg.displayName=yg;var xg=`PopoverArrow`,Sg=_.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=tg(n);return(0,L.jsx)(hf,{...i,...r,ref:t})});Sg.displayName=xg;function Cg(e){return e?`open`:`closed`}var wg=ig,Tg=cg,Eg=fg,Dg=mg,Og=[` `,`Enter`,`ArrowUp`,`ArrowDown`],kg=[` `,`Enter`],Ag=`Select`,[jg,Mg,Ng]=ga(Ag),[Pg,Fg]=ma(Ag,[Ng,Yd]),Ig=Yd(),[Lg,Rg]=Pg(Ag),[zg,Bg]=Pg(Ag),Vg=e=>{let{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:a,value:o,defaultValue:s,onValueChange:c,dir:l,name:u,autoComplete:d,disabled:f,required:p,form:m}=e,h=Ig(t),[g,v]=_.useState(null),[y,b]=_.useState(null),[x,S]=_.useState(!1),C=Wa(l),[w,T]=ya({prop:r,defaultProp:i??!1,onChange:a,caller:Ag}),[E,D]=ya({prop:o,defaultProp:s,onChange:c,caller:Ag}),O=_.useRef(null),k=g?m||!!g.closest(`form`):!0,[A,j]=_.useState(new Set),M=Array.from(A).map(e=>e.props.value).join(`;`);return(0,L.jsx)(ff,{...h,children:(0,L.jsxs)(Lg,{required:p,scope:t,trigger:g,onTriggerChange:v,valueNode:y,onValueNodeChange:b,valueNodeHasChildren:x,onValueNodeHasChildrenChange:S,contentId:ka(),value:E,onValueChange:D,open:w,onOpenChange:T,dir:C,triggerPointerDownPosRef:O,disabled:f,children:[(0,L.jsx)(jg.Provider,{scope:t,children:(0,L.jsx)(zg,{scope:e.__scopeSelect,onNativeOptionAdd:_.useCallback(e=>{j(t=>new Set(t).add(e))},[]),onNativeOptionRemove:_.useCallback(e=>{j(t=>{let n=new Set(t);return n.delete(e),n})},[]),children:n})}),k?(0,L.jsxs)(I_,{"aria-hidden":!0,required:p,tabIndex:-1,name:u,autoComplete:d,value:E,onChange:e=>D(e.target.value),disabled:f,form:m,children:[E===void 0?(0,L.jsx)(`option`,{value:``}):null,Array.from(A)]},M):null]})})};Vg.displayName=Ag;var Hg=`SelectTrigger`,Ug=_.forwardRef((e,t)=>{let{__scopeSelect:n,disabled:r=!1,...i}=e,a=Ig(n),o=Rg(Hg,n),s=o.disabled||r,c=Qi(t,o.onTriggerChange),l=Mg(n),u=_.useRef(`touch`),[d,f,p]=R_(e=>{let t=l().filter(e=>!e.disabled),n=z_(t,e,t.find(e=>e.value===o.value));n!==void 0&&o.onValueChange(n.value)}),m=e=>{s||(o.onOpenChange(!0),p()),e&&(o.triggerPointerDownPosRef.current={x:Math.round(e.pageX),y:Math.round(e.pageY)})};return(0,L.jsx)(pf,{asChild:!0,...a,children:(0,L.jsx)(sa.button,{type:`button`,role:`combobox`,"aria-controls":o.contentId,"aria-expanded":o.open,"aria-required":o.required,"aria-autocomplete":`none`,dir:o.dir,"data-state":o.open?`open`:`closed`,disabled:s,"data-disabled":s?``:void 0,"data-placeholder":L_(o.value)?``:void 0,...i,ref:c,onClick:B(i.onClick,e=>
vendor: 7,132 bytes, line 61
61{e.currentTarget.focus(),u.current!==`mouse`&&m(e)}),onPointerDown:B(i.onPointerDown,e=>{u.current=e.pointerType;let t=e.target;t.hasPointerCapture(e.pointerId)&&t.releasePointerCapture(e.pointerId),e.button===0&&e.ctrlKey===!1&&e.pointerType===`mouse`&&(m(e),e.preventDefault())}),onKeyDown:B(i.onKeyDown,e=>{let t=d.current!==``;!(e.ctrlKey||e.altKey||e.metaKey)&&e.key.length===1&&f(e.key),!(t&&e.key===` `)&&Og.includes(e.key)&&(m(),e.preventDefault())})})})});Ug.displayName=Hg;var Wg=`SelectValue`,Gg=_.forwardRef((e,t)=>{let{__scopeSelect:n,className:r,style:i,children:a,placeholder:o=``,...s}=e,c=Rg(Wg,n),{onValueNodeHasChildrenChange:l}=c,u=a!==void 0,d=Qi(t,c.onValueNodeChange);return _a(()=>{l(u)},[l,u]),(0,L.jsx)(sa.span,{...s,ref:d,style:{pointerEvents:`none`},children:L_(c.value)?(0,L.jsx)(L.Fragment,{children:o}):a})});Gg.displayName=Wg;var Kg=`SelectIcon`,qg=_.forwardRef((e,t)=>{let{__scopeSelect:n,children:r,...i}=e;return(0,L.jsx)(sa.span,{"aria-hidden":!0,...i,ref:t,children:r||`â¼`})});qg.displayName=Kg;var Jg=`SelectPortal`,Yg=e=>(0,L.jsx)(wo,{asChild:!0,...e});Yg.displayName=Jg;var Xg=`SelectContent`,Zg=_.forwardRef((e,t)=>{let n=Rg(Xg,e.__scopeSelect),[r,i]=_.useState();if(_a(()=>{i(new DocumentFragment)},[]),!n.open){let t=r;return t?v.createPortal((0,L.jsx)($g,{scope:e.__scopeSelect,children:(0,L.jsx)(jg.Slot,{scope:e.__scopeSelect,children:(0,L.jsx)(`div`,{children:e.children})})}),t):null}return(0,L.jsx)(r_,{...e,ref:t})});Zg.displayName=Xg;var Qg=10,[$g,e_]=Pg(Xg),t_=`SelectContentImpl`,n_=$i(`SelectContent.RemoveScroll`),r_=_.forwardRef((e,t)=>{let{__scopeSelect:n,position:r=`item-aligned`,onCloseAutoFocus:i,onEscapeKeyDown:a,onPointerDownOutside:o,side:s,sideOffset:c,align:l,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:p,sticky:m,hideWhenDetached:h,avoidCollisions:g,...v}=e,y=Rg(Xg,n),[b,x]=_.useState(null),[S,C]=_.useState(null),w=Qi(t,e=>x(e)),[T,E]=_.useState(null),[D,O]=_.useState(null),k=Mg(n),[A,j]=_.useState(!1),M=_.useRef(!1);_.useEffect(()=>{if(b)return Gs(b)},[b]),Eo();let ee=_.useCallback(e=>{let[t,...n]=k().map(e=>e.ref.current),[r]=n.slice(-1),i=document.activeElement;for(let n of e)if(n===i||(n?.scrollIntoView({block:`nearest`}),n===t&&S&&(S.scrollTop=0),n===r&&S&&(S.scrollTop=S.scrollHeight),n?.focus(),document.activeElement!==i))return},[k,S]),N=_.useCallback(()=>ee([T,b]),[ee,T,b]);_.useEffect(()=>{A&&N()},[A,N]);let{onOpenChange:P,triggerPointerDownPosRef:F}=y;_.useEffect(()=>{if(b){let e={x:0,y:0},t=t=>{e={x:Math.abs(Math.round(t.pageX)-(F.current?.x??0)),y:Math.abs(Math.round(t.pageY)-(F.current?.y??0))}},n=n=>{e.x<=10&&e.y<=10?n.preventDefault():b.contains(n.target)||P(!1),document.removeEventListener(`pointermove`,t),F.current=null};return F.current!==null&&(document.addEventListener(`pointermove`,t),document.addEventListener(`pointerup`,n,{capture:!0,once:!0})),()=>{document.removeEventListener(`pointermove`,t),document.removeEventListener(`pointerup`,n,{capture:!0})}}},[b,P,F]),_.useEffect(()=>{let e=()=>P(!1);return window.addEventListener(`blur`,e),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`blur`,e),window.removeEventListener(`resize`,e)}},[P]);let[I,te]=R_(e=>{let t=k().filter(e=>!e.disabled),n=z_(t,e,t.find(e=>e.ref.current===document.activeElement));n&&setTimeout(()=>n.ref.current.focus())}),ne=_.useCallback((e,t,n)=>{let r=!M.current&&!n;(y.value!==void 0&&y.value===t||r)&&(E(e),r&&(M.current=!0))},[y.value]),re=_.useCallback(()=>b?.focus(),[b]),ie=_.useCallback((e,t,n)=>{let r=!M.current&&!n;(y.value!==void 0&&y.value===t||r)&&O(e)},[y.value]),ae=r===`popper`?s_:a_,oe=ae===s_?{side:s,sideOffset:c,align:l,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:p,sticky:m,hideWhenDetached:h,avoidCollisions:g}:{};return(0,L.jsx)($g,{scope:n,content:b,viewport:S,onViewportChange:C,itemRefCallback:ne,selectedItem:T,onItemLeave:re,itemTextRefCallback:ie,focusSelectedItem:N,selectedItemText:D,position:r,isPositioned:A,searchRef:I,children:(0,L.jsx)(Is,{as:n_,allowPinchZoom:!0,children:(0,L.jsx)(uo,{asChild:!0,trapped:y.open,onMountAutoFocus:e=>{e.preventDefault()},onUnmountAutoFocus:B(i,e=>{y.trigger?.focus({preventScroll:!0}),e.preventDefault()}),children:(0,L.jsx)($a,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:e=>e.preventDefault(),onDismiss:()=>y.onOpenChange(!1),children:(0,L.jsx)(ae,{role:`listbox`,id:y.contentId,"data-state":y.open?`open`:`closed`,dir:y.dir,onContextMenu:e=>e.preventDefault(),...v,...oe,onPlaced:()=>j(!0),ref:w,style:{display:`flex`,flexDirection:`column`,outline:`none`,...v.style},onKeyDown:B(v.onKeyDown,e=>{let t=e.ctrlKey||e.altKey||e.metaKey;if(e.key===`Tab`&&e.preventDefault(),!t&&e.key.length===1&&te(e.key),[`ArrowUp`,`ArrowDown`,`Home`,`End`].includes(e.key)){let t=k().filter(e=>!e.disabled).map(e=>e.ref.current);if([`ArrowUp`,`End`].includes(e.key)&&(t=t.slice().reverse()),[`ArrowUp`,`ArrowDown`].includes(e.key)){let n=e.target,r=t.indexOf(n);t=t.slice(r+1)}setTimeout(()=>ee(t)),e.preventDefault()}})})})})})})});r_.displayName=t_;var i_=`SelectItemAlignedPosition`,a_=_.forwardRef((e,t)=>{let{__scopeSelect:n,onPlaced:r,...i}=e,a=Rg(Xg,n),o=e_(Xg,n),[s,c]=_.useState(null),[l,u]=_.useState(null),d=Qi(t,e=>u(e)),f=Mg(n),p=_.useRef(!1),m=_.useRef(!0),{viewport:h,selectedItem:g,selectedItemText:v,focusSelectedItem:y}=o,b=_.useCallback(()=>{if(a.trigger&&a.valueNode&&s&&l&&h&&g&&v){let e=a.trigger.getBoundingClientRect(),t=l.getBoundingClientRect(),n=a.valueNode.getBoundingClientRect(),i=v.getBoundingClientRect();if(a.dir!==`rtl`){let r=i.left-t.left,a=n.left-r,o=e.left-a,c=e.width+o,l=Math.max(c,t.width),u=window.innerWidth-Qg,d=Zh(a,[Qg,Math.max(Qg,u-l)]);s.style.minWidth=c+`px`,s.style.left=d+`px`}else{let r=t.right-i.right,a=window.innerWidth-n.right-r,o=window.innerWidth-e.right-a,c=e.width+o,l=Math.max(c,t.width),u=window.innerWidth-Qg,d=Zh(a,[Qg,Math.max(Qg,u-l)]);s.style.minWidth=c+`px`,s.style.right=d+`px`}let o=f(),c=window.innerHeight-Qg*2,u=h.scrollHeight,d=window.getComputedStyle(l),m=parseInt(d.borderTopWidth,10),_=parseInt(d.paddingTop,10),y=parseInt(d.borderBottomWidth,10),b=parseInt(d.paddingBottom,10),x=m+_+u+b+y,S=Math.min(g.offsetHeight*5,x),C=window.getComputedStyle(h),w=parseInt(C.paddingTop,10),T=parseInt(C.paddingBottom,10),E=e.top+e.height/2-Qg,D=c-E,O=g.offsetHeight/2,k=g.offsetTop+O,A=m+_+k,j=x-A;if(A<=E){let e=o.length>0&&g===o[o.length-1].ref.current;s.style.bottom=`0px`;let t=l.clientHeight-h.offsetTop-h.offsetHeight,n=A+Math.max(D,O+(e?T:0)+t+y);s.style.height=n+`px`}else{let e=o.length>0&&g===o[0].ref.current;s.style.top=`0px`;let t=Math.max(E,m+h.offsetTop+(e?w:0)+O)+j;s.style.height=t+`px`,h.scrollTop=A-E+h.offsetTop}s.style.margin=`${Qg}px 0`,s.style.minHeight=S+`px`,s.style.maxHeight=c+`px`,r?.(),requestAnimationFrame(()=>p.current=!0)}},[f,a.trigger,a.valueNode,s,l,h,g,v,a.dir,r]);_a(()=>b(),[b]);let[x,S]=_.useState();return _a(()=>{l&&S(window.getComputedStyle(l).zIndex)},[l]),(0,L.jsx)(c_,{scope:n,contentWrapper:s,shouldExpandOnScrollRef:p,onScrollButtonChange:_.useCallback(e=>
vendor: 4,689 bytes, line 61
61{e&&m.current===!0&&(b(),y?.(),m.current=!1)},[b,y]),children:(0,L.jsx)(`div`,{ref:c,style:{display:`flex`,flexDirection:`column`,position:`fixed`,zIndex:x},children:(0,L.jsx)(sa.div,{...i,ref:d,style:{boxSizing:`border-box`,maxHeight:`100%`,...i.style}})})})});a_.displayName=i_;var o_=`SelectPopperPosition`,s_=_.forwardRef((e,t)=>{let{__scopeSelect:n,align:r=`start`,collisionPadding:i=Qg,...a}=e,o=Ig(n);return(0,L.jsx)(mf,{...o,...a,ref:t,align:r,collisionPadding:i,style:{boxSizing:`border-box`,...a.style,"--radix-select-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-select-content-available-width":`var(--radix-popper-available-width)`,"--radix-select-content-available-height":`var(--radix-popper-available-height)`,"--radix-select-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-select-trigger-height":`var(--radix-popper-anchor-height)`}})});s_.displayName=o_;var[c_,l_]=Pg(Xg,{}),u_=`SelectViewport`,d_=_.forwardRef((e,t)=>{let{__scopeSelect:n,nonce:r,...i}=e,a=e_(u_,n),o=l_(u_,n),s=Qi(t,a.onViewportChange),c=_.useRef(0);return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`style`,{dangerouslySetInnerHTML:{__html:`[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}`},nonce:r}),(0,L.jsx)(jg.Slot,{scope:n,children:(0,L.jsx)(sa.div,{"data-radix-select-viewport":``,role:`presentation`,...i,ref:s,style:{position:`relative`,flex:1,overflow:`hidden auto`,...i.style},onScroll:B(i.onScroll,e=>{let t=e.currentTarget,{contentWrapper:n,shouldExpandOnScrollRef:r}=o;if(r?.current&&n){let e=Math.abs(c.current-t.scrollTop);if(e>0){let r=window.innerHeight-Qg*2,i=parseFloat(n.style.minHeight),a=parseFloat(n.style.height),o=Math.max(i,a);if(o<r){let i=o+e,a=Math.min(r,i),s=i-a;n.style.height=a+`px`,n.style.bottom===`0px`&&(t.scrollTop=s>0?s:0,n.style.justifyContent=`flex-end`)}}}c.current=t.scrollTop})})})]})});d_.displayName=u_;var f_=`SelectGroup`,[p_,m_]=Pg(f_),h_=_.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=ka();return(0,L.jsx)(p_,{scope:n,id:i,children:(0,L.jsx)(sa.div,{role:`group`,"aria-labelledby":i,...r,ref:t})})});h_.displayName=f_;var g_=`SelectLabel`,__=_.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=m_(g_,n);return(0,L.jsx)(sa.div,{id:i.id,...r,ref:t})});__.displayName=g_;var v_=`SelectItem`,[y_,b_]=Pg(v_),x_=_.forwardRef((e,t)=>{let{__scopeSelect:n,value:r,disabled:i=!1,textValue:a,...o}=e,s=Rg(v_,n),c=e_(v_,n),l=s.value===r,[u,d]=_.useState(a??``),[f,p]=_.useState(!1),m=Qi(t,e=>c.itemRefCallback?.(e,r,i)),h=ka(),g=_.useRef(`touch`),v=()=>{i||(s.onValueChange(r),s.onOpenChange(!1))};if(r===``)throw Error(`A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.`);return(0,L.jsx)(y_,{scope:n,value:r,disabled:i,textId:h,isSelected:l,onItemTextChange:_.useCallback(e=>{d(t=>t||(e?.textContent??``).trim())},[]),children:(0,L.jsx)(jg.ItemSlot,{scope:n,value:r,disabled:i,textValue:u,children:(0,L.jsx)(sa.div,{role:`option`,"aria-labelledby":h,"data-highlighted":f?``:void 0,"aria-selected":l&&f,"data-state":l?`checked`:`unchecked`,"aria-disabled":i||void 0,"data-disabled":i?``:void 0,tabIndex:i?void 0:-1,...o,ref:m,onFocus:B(o.onFocus,()=>p(!0)),onBlur:B(o.onBlur,()=>p(!1)),onClick:B(o.onClick,()=>{g.current!==`mouse`&&v()}),onPointerUp:B(o.onPointerUp,()=>{g.current===`mouse`&&v()}),onPointerDown:B(o.onPointerDown,e=>{g.current=e.pointerType}),onPointerMove:B(o.onPointerMove,e=>{g.current=e.pointerType,i?c.onItemLeave?.():g.current===`mouse`&&e.currentTarget.focus({preventScroll:!0})}),onPointerLeave:B(o.onPointerLeave,e=>{e.currentTarget===document.activeElement&&c.onItemLeave?.()}),onKeyDown:B(o.onKeyDown,e=>{c.searchRef?.current!==``&&e.key===` `||(kg.includes(e.key)&&v(),e.key===` `&&e.preventDefault())})})})})});x_.displayName=v_;var S_=`SelectItemText`,C_=_.forwardRef((e,t)=>{let{__scopeSelect:n,className:r,style:i,...a}=e,o=Rg(S_,n),s=e_(S_,n),c=b_(S_,n),l=Bg(S_,n),[u,d]=_.useState(null),f=Qi(t,e=>d(e),c.onItemTextChange,e=>s.itemTextRefCallback?.(e,c.value,c.disabled)),p=u?.textContent,m=_.useMemo(()=>(0,L.jsx)(`option`,{value:c.value,disabled:c.disabled,children:p},c.value),[c.disabled,c.value,p]),{onNativeOptionAdd:h,onNativeOptionRemove:g}=l;return _a(()=>(h(m),()=>g(m)),[h,g,m]),(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(sa.span,{id:c.textId,...a,ref:f}),c.isSelected&&o.valueNode&&!o.valueNodeHasChildren?v.createPortal(a.children,o.valueNode):null]})});C_.displayName=S_;var w_=`SelectItemIndicator`,T_=_.forwardRef((e,t)=>
61{let{__scopeSelect:n,...r}=e;return b_(w_,n).isSelected?(0,L.jsx)(sa.span,{"aria-hidden":!0,...r,ref:t}):null});T_.displayName=w_;var E_=`SelectScrollUpButton`,D_=_.forwardRef((e,t)=>{let n=e_(E_,e.__scopeSelect),r=l_(E_,e.__scopeSelect),[i,a]=_.useState(!1),o=Qi(t,r.onScrollButtonChange);return _a(()=>{if(n.viewport&&n.isPositioned){let e=function(){a(t.scrollTop>0)},t=n.viewport;return e(),t.addEventListener(`scroll`,e),()=>t.removeEventListener(`scroll`,e)}},[n.viewport,n.isPositioned]),i?(0,L.jsx)(A_,{...e,ref:o,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=n;e&&t&&(e.scrollTop-=t.offsetHeight)}}):null});D_.displayName=E_;var O_=`SelectScrollDownButton`,k_=_.forwardRef((e,t)=>{let n=e_(O_,e.__scopeSelect),r=l_(O_,e.__scopeSelect),[i,a]=_.useState(!1),o=Qi(t,r.onScrollButtonChange);return _a(()=>{if(n.viewport&&n.isPositioned){let e=function(){let e=t.scrollHeight-t.clientHeight;a(Math.ceil(t.scrollTop)<e)},t=n.viewport;return e(),t.addEventListener(`scroll`,e),()=>t.removeEventListener(`scroll`,e)}},[n.viewport,n.isPositioned]),i?(0,L.jsx)(A_,{...e,ref:o,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=n;e&&t&&(e.scrollTop+=t.offsetHeight)}}):null});k_.displayName=O_;var A_=_.forwardRef((e,t)=>{let{__scopeSelect:n,onAutoScroll:r,...i}=e,a=e_(`SelectScrollButton`,n),o=_.useRef(null),s=Mg(n),c=_.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return _.useEffect(()=>()=>c(),[c]),_a(()=>{s().find(e=>e.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:`nearest`})},[s]),(0,L.jsx)(sa.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:B(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:B(i.onPointerMove,()=>{a.onItemLeave?.(),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:B(i.onPointerLeave,()=>{c()})})}),j_=`SelectSeparator`,M_=_.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e;return(0,L.jsx)(sa.div,{"aria-hidden":!0,...r,ref:t})});M_.displayName=j_;var N_=`SelectArrow`,P_=_.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=Ig(n),a=Rg(N_,n),o=e_(N_,n);return a.open&&o.position===`popper`?(0,L.jsx)(hf,{...i,...r,ref:t}):null});P_.displayName=N_;var F_=`SelectBubbleInput`,I_=_.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{let i=_.useRef(null),a=Qi(r,i),o=ml(t);return _.useEffect(()=>{let e=i.current;if(!e)return;let n=window.HTMLSelectElement.prototype,r=Object.getOwnPropertyDescriptor(n,`value`).set;if(o!==t&&r){let n=new Event(`change`,{bubbles:!0});r.call(e,t),e.dispatchEvent(n)}},[o,t]),(0,L.jsx)(sa.select,{...n,style:{...la,...n.style},ref:a,defaultValue:t})});I_.displayName=F_;function L_(e){return e===``||e===void 0}function R_(e){let t=Ga(e),n=_.useRef(``),r=_.useRef(0),i=_.useCallback(e=>{let i=n.current+e;t(i),(function e(t){n.current=t,window.clearTimeout(r.current),t!==``&&(r.current=window.setTimeout(()=>e(``),1e3))})(i)},[t]),a=_.useCallback(()=>{n.current=``,window.clearTimeout(r.current)},[]);return _.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,a]}function z_(e,t,n){let r=t.length>1&&Array.from(t).every(e=>e===t[0])?t[0]:t,i=n?e.indexOf(n):-1,a=B_(e,Math.max(i,0));r.length===1&&(a=a.filter(e=>e!==n));let o=a.find(e=>e.textValue.toLowerCase().startsWith(r.toLowerCase()));return o===n?void 0:o}function B_(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var V_=Vg,H_=Ug,U_=Gg,W_=qg,G_=Yg,K_=Zg,q_=d_,J_=h_,Y_=__,X_=x_,Z_=C_,Q_=T_,$_=D_,ev=k_,tv=M_,nv=`Separator`,rv=`horizontal`,iv=[`horizontal`,`vertical`],av=_.forwardRef((e,t)=>{let{decorative:n,orientation:r=rv,...i}=e,a=ov(r)?r:rv,o=a===`vertical`?a:void 0,s=n?{role:`none`}:{"aria-orientation":o,role:`separator`};return(0,L.jsx)(sa.div,{"data-orientation":a,...s,...i,ref:t})});av.displayName=nv;function ov(e){return iv.includes(e)}var sv=av,cv=`Switch`,[lv,uv]=ma(cv),[dv,fv]=lv(cv),pv=_.forwardRef((e,t)=>{let{__scopeSwitch:n,name:r,checked:i,defaultChecked:a,required:o,disabled:s,value:c=`on`,onCheckedChange:l,form:u,...d}=e,[f,p]=_.useState(null),m=Qi(t,e=>p(e)),h=_.useRef(!1),g=f?u||!!f.closest(`form`):!0,[v,y]=ya({prop:i,defaultProp:a??!1,onChange:l,caller:cv});return(0,L.jsxs)(dv,{scope:n,checked:v,disabled:s,children:[(0,L.jsx)(sa.button,{type:`button`,role:`switch`,"aria-checked":v,"aria-required":o,"data-state":vv(v),"data-disabled":s?``:void 0,disabled:s,value:c,...d,ref:m,onClick:B(e.onClick,e=>{y(e=>!e),g&&(h.current=e.isPropagationStopped(),h.current||e.stopPropagation())})}),g&&(0,L.jsx)(_v,{control:f,bubbles:!h.current,name:r,value:c,checked:v,required:o,disabled:s,form:u,style:{transform:`translateX(-100%)`}})]})});pv.displayName=cv;var mv=`SwitchThumb`,hv=_.forwardRef((e,t)=>
vendor: 4,989 bytes, line 61
61{let{__scopeSwitch:n,...r}=e,i=fv(mv,n);return(0,L.jsx)(sa.span,{"data-state":vv(i.checked),"data-disabled":i.disabled?``:void 0,...r,ref:t})});hv.displayName=mv;var gv=`SwitchBubbleInput`,_v=_.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...i},a)=>{let o=_.useRef(null),s=Qi(o,a),c=ml(n),l=hl(t);return _.useEffect(()=>{let e=o.current;if(!e)return;let t=window.HTMLInputElement.prototype,i=Object.getOwnPropertyDescriptor(t,`checked`).set;if(c!==n&&i){let t=new Event(`click`,{bubbles:r});i.call(e,n),e.dispatchEvent(t)}},[c,n,r]),(0,L.jsx)(`input`,{type:`checkbox`,"aria-hidden":!0,defaultChecked:n,...i,tabIndex:-1,ref:s,style:{...i.style,...l,position:`absolute`,pointerEvents:`none`,opacity:0,margin:0}})});_v.displayName=gv;function vv(e){return e?`checked`:`unchecked`}var yv=pv,bv=hv,xv=`Tabs`,[Sv,Cv]=ma(xv,[Cf]),wv=Cf(),[Tv,Ev]=Sv(xv),Dv=_.forwardRef((e,t)=>{let{__scopeTabs:n,value:r,onValueChange:i,defaultValue:a,orientation:o=`horizontal`,dir:s,activationMode:c=`automatic`,...l}=e,u=Wa(s),[d,f]=ya({prop:r,onChange:i,defaultProp:a??``,caller:xv});return(0,L.jsx)(Tv,{scope:n,baseId:ka(),value:d,onValueChange:f,orientation:o,dir:u,activationMode:c,children:(0,L.jsx)(sa.div,{dir:u,"data-orientation":o,...l,ref:t})})});Dv.displayName=xv;var Ov=`TabsList`,kv=_.forwardRef((e,t)=>{let{__scopeTabs:n,loop:r=!0,...i}=e,a=Ev(Ov,n),o=wv(n);return(0,L.jsx)(Ff,{asChild:!0,...o,orientation:a.orientation,dir:a.dir,loop:r,children:(0,L.jsx)(sa.div,{role:`tablist`,"aria-orientation":a.orientation,...i,ref:t})})});kv.displayName=Ov;var Av=`TabsTrigger`,jv=_.forwardRef((e,t)=>{let{__scopeTabs:n,value:r,disabled:i=!1,...a}=e,o=Ev(Av,n),s=wv(n),c=Pv(o.baseId,r),l=Fv(o.baseId,r),u=r===o.value;return(0,L.jsx)(If,{asChild:!0,...s,focusable:!i,active:u,children:(0,L.jsx)(sa.button,{type:`button`,role:`tab`,"aria-selected":u,"aria-controls":l,"data-state":u?`active`:`inactive`,"data-disabled":i?``:void 0,disabled:i,id:c,...a,ref:t,onMouseDown:B(e.onMouseDown,e=>{!i&&e.button===0&&e.ctrlKey===!1?o.onValueChange(r):e.preventDefault()}),onKeyDown:B(e.onKeyDown,e=>{[` `,`Enter`].includes(e.key)&&o.onValueChange(r)}),onFocus:B(e.onFocus,()=>{let e=o.activationMode!==`manual`;!u&&!i&&e&&o.onValueChange(r)})})})});jv.displayName=Av;var Mv=`TabsContent`,Nv=_.forwardRef((e,t)=>{let{__scopeTabs:n,value:r,forceMount:i,children:a,...o}=e,s=Ev(Mv,n),c=Pv(s.baseId,r),l=Fv(s.baseId,r),u=r===s.value,d=_.useRef(u);return _.useEffect(()=>{let e=requestAnimationFrame(()=>d.current=!1);return()=>cancelAnimationFrame(e)},[]),(0,L.jsx)(Ca,{present:i||u,children:({present:n})=>(0,L.jsx)(sa.div,{"data-state":u?`active`:`inactive`,"data-orientation":s.orientation,role:`tabpanel`,"aria-labelledby":c,hidden:!n,id:l,tabIndex:0,...o,ref:t,style:{...e.style,animationDuration:d.current?`0s`:void 0},children:n&&a})})});Nv.displayName=Mv;function Pv(e,t){return`${e}-trigger-${t}`}function Fv(e,t){return`${e}-content-${t}`}var Iv=Dv,Lv=kv,Rv=jv,zv=Nv,[Bv,Vv]=ma(`Tooltip`,[Yd]),Hv=Yd(),Uv=`TooltipProvider`,Wv=700,Gv=`tooltip.open`,[Kv,qv]=Bv(Uv),Jv=e=>{let{__scopeTooltip:t,delayDuration:n=Wv,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:a}=e,o=_.useRef(!0),s=_.useRef(!1),c=_.useRef(0);return _.useEffect(()=>{let e=c.current;return()=>window.clearTimeout(e)},[]),(0,L.jsx)(Kv,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:_.useCallback(()=>{window.clearTimeout(c.current),o.current=!1},[]),onClose:_.useCallback(()=>{window.clearTimeout(c.current),c.current=window.setTimeout(()=>o.current=!0,r)},[r]),isPointerInTransitRef:s,onPointerInTransitChange:_.useCallback(e=>{s.current=e},[]),disableHoverableContent:i,children:a})};Jv.displayName=Uv;var Yv=`Tooltip`,[Xv,Zv]=Bv(Yv),Qv=e=>{let{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:a,disableHoverableContent:o,delayDuration:s}=e,c=qv(Yv,e.__scopeTooltip),l=Hv(t),[u,d]=_.useState(null),f=ka(),p=_.useRef(0),m=o??c.disableHoverableContent,h=s??c.delayDuration,g=_.useRef(!1),[v,y]=ya({prop:r,defaultProp:i??!1,onChange:e=>{e?(c.onOpen(),document.dispatchEvent(new CustomEvent(Gv))):c.onClose(),a?.(e)},caller:Yv}),b=_.useMemo(()=>v?g.current?`delayed-open`:`instant-open`:`closed`,[v]),x=_.useCallback(()=>{window.clearTimeout(p.current),p.current=0,g.current=!1,y(!0)},[y]),S=_.useCallback(()=>{window.clearTimeout(p.current),p.current=0,y(!1)},[y]),C=_.useCallback(()=>{window.clearTimeout(p.current),p.current=window.setTimeout(()=>{g.current=!0,y(!0),p.current=0},h)},[h,y]);return _.useEffect(()=>()=>{p.current&&=(window.clearTimeout(p.current),0)},[]),(0,L.jsx)(ff,{...l,children:(0,L.jsx)(Xv,{scope:t,contentId:f,open:v,stateAttribute:b,trigger:u,onTriggerChange:d,onTriggerEnter:_.useCallback(()=>{c.isOpenDelayedRef.current?C():x()},[c.isOpenDelayedRef,C,x]),onTriggerLeave:_.useCallback(()=>{m?S():(window.clearTimeout(p.current),p.current=0)},[S,m]),onOpen:x,onClose:S,disableHoverableContent:m,children:n})})};Qv.displayName=Yv;var $v=`TooltipTrigger`,ey=_.forwardRef((e,t)=>
vendor: 4,765 bytes, line 61
61{let{__scopeTooltip:n,...r}=e,i=Zv($v,n),a=qv($v,n),o=Hv(n),s=Qi(t,_.useRef(null),i.onTriggerChange),c=_.useRef(!1),l=_.useRef(!1),u=_.useCallback(()=>c.current=!1,[]);return _.useEffect(()=>()=>document.removeEventListener(`pointerup`,u),[u]),(0,L.jsx)(pf,{asChild:!0,...o,children:(0,L.jsx)(sa.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:s,onPointerMove:B(e.onPointerMove,e=>{e.pointerType!==`touch`&&!l.current&&!a.isPointerInTransitRef.current&&(i.onTriggerEnter(),l.current=!0)}),onPointerLeave:B(e.onPointerLeave,()=>{i.onTriggerLeave(),l.current=!1}),onPointerDown:B(e.onPointerDown,()=>{i.open&&i.onClose(),c.current=!0,document.addEventListener(`pointerup`,u,{once:!0})}),onFocus:B(e.onFocus,()=>{c.current||i.onOpen()}),onBlur:B(e.onBlur,i.onClose),onClick:B(e.onClick,i.onClose)})})});ey.displayName=$v;var ty=`TooltipPortal`,[ny,ry]=Bv(ty,{forceMount:void 0}),iy=e=>{let{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,a=Zv(ty,t);return(0,L.jsx)(ny,{scope:t,forceMount:n,children:(0,L.jsx)(Ca,{present:n||a.open,children:(0,L.jsx)(wo,{asChild:!0,container:i,children:r})})})};iy.displayName=ty;var ay=`TooltipContent`,oy=_.forwardRef((e,t)=>{let n=ry(ay,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i=`top`,...a}=e,o=Zv(ay,e.__scopeTooltip);return(0,L.jsx)(Ca,{present:r||o.open,children:o.disableHoverableContent?(0,L.jsx)(dy,{side:i,...a,ref:t}):(0,L.jsx)(sy,{side:i,...a,ref:t})})}),sy=_.forwardRef((e,t)=>{let n=Zv(ay,e.__scopeTooltip),r=qv(ay,e.__scopeTooltip),i=_.useRef(null),a=Qi(t,i),[o,s]=_.useState(null),{trigger:c,onClose:l}=n,u=i.current,{onPointerInTransitChange:d}=r,f=_.useCallback(()=>{s(null),d(!1)},[d]),p=_.useCallback((e,t)=>{let n=e.currentTarget,r={x:e.clientX,y:e.clientY},i=hy(r,my(r,n.getBoundingClientRect())),a=gy(t.getBoundingClientRect());s(vy([...i,...a])),d(!0)},[d]);return _.useEffect(()=>()=>f(),[f]),_.useEffect(()=>{if(c&&u){let e=e=>p(e,u),t=e=>p(e,c);return c.addEventListener(`pointerleave`,e),u.addEventListener(`pointerleave`,t),()=>{c.removeEventListener(`pointerleave`,e),u.removeEventListener(`pointerleave`,t)}}},[c,u,p,f]),_.useEffect(()=>{if(o){let e=e=>{let t=e.target,n={x:e.clientX,y:e.clientY},r=c?.contains(t)||u?.contains(t),i=!_y(n,o);r?f():i&&(f(),l())};return document.addEventListener(`pointermove`,e),()=>document.removeEventListener(`pointermove`,e)}},[c,u,o,l,f]),(0,L.jsx)(dy,{...e,ref:a})}),[cy,ly]=Bv(Yv,{isInside:!1}),uy=ra(`TooltipContent`),dy=_.forwardRef((e,t)=>{let{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:a,onPointerDownOutside:o,...s}=e,c=Zv(ay,n),l=Hv(n),{onClose:u}=c;return _.useEffect(()=>(document.addEventListener(Gv,u),()=>document.removeEventListener(Gv,u)),[u]),_.useEffect(()=>{if(c.trigger){let e=e=>{e.target?.contains(c.trigger)&&u()};return window.addEventListener(`scroll`,e,{capture:!0}),()=>window.removeEventListener(`scroll`,e,{capture:!0})}},[c.trigger,u]),(0,L.jsx)($a,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:e=>e.preventDefault(),onDismiss:u,children:(0,L.jsxs)(mf,{"data-state":c.stateAttribute,...l,...s,ref:t,style:{...s.style,"--radix-tooltip-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-tooltip-content-available-width":`var(--radix-popper-available-width)`,"--radix-tooltip-content-available-height":`var(--radix-popper-available-height)`,"--radix-tooltip-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-tooltip-trigger-height":`var(--radix-popper-anchor-height)`},children:[(0,L.jsx)(uy,{children:r}),(0,L.jsx)(cy,{scope:n,isInside:!0,children:(0,L.jsx)(fa,{id:c.contentId,role:`tooltip`,children:i||r})})]})})});oy.displayName=ay;var fy=`TooltipArrow`,py=_.forwardRef((e,t)=>{let{__scopeTooltip:n,...r}=e,i=Hv(n);return ly(fy,n).isInside?null:(0,L.jsx)(hf,{...i,...r,ref:t})});py.displayName=fy;function my(e,t){let n=Math.abs(t.top-e.y),r=Math.abs(t.bottom-e.y),i=Math.abs(t.right-e.x),a=Math.abs(t.left-e.x);switch(Math.min(n,r,i,a)){case a:return`left`;case i:return`right`;case n:return`top`;case r:return`bottom`;default:throw Error(`unreachable`)}}function hy(e,t,n=5){let r=[];switch(t){case`top`:r.push({x:e.x-n,y:e.y+n},{x:e.x+n,y:e.y+n});break;case`bottom`:r.push({x:e.x-n,y:e.y-n},{x:e.x+n,y:e.y-n});break;case`left`:r.push({x:e.x+n,y:e.y-n},{x:e.x+n,y:e.y+n});break;case`right`:r.push({x:e.x-n,y:e.y-n},{x:e.x-n,y:e.y+n});break}return r}function gy(e){let{top:t,right:n,bottom:r,left:i}=e;return[{x:i,y:t},{x:n,y:t},{x:n,y:r},{x:i,y:r}]}function _y(e,t){let{x:n,y:r}=e,i=!1;for(let e=0,a=t.length-1;e<t.length;a=e++){let o=t[e],s=t[a],c=o.x,l=o.y,u=s.x,d=s.y;l>r!=d>r&&n<(u-c)*(r-l)/(d-l)+c&&(i=!i)}return i}function vy(e){let t=e.slice();return t.sort((e,t)=>
vendor: 4,455 bytes, line 61
61e.x<t.x?-1:e.x>t.x?1:e.y<t.y?-1:e.y>t.y?1:0),yy(t)}function yy(e){if(e.length<=1)return e.slice();let t=[];for(let n=0;n<e.length;n++){let r=e[n];for(;t.length>=2;){let e=t[t.length-1],n=t[t.length-2];if((e.x-n.x)*(r.y-n.y)>=(e.y-n.y)*(r.x-n.x))t.pop();else break}t.push(r)}t.pop();let n=[];for(let t=e.length-1;t>=0;t--){let r=e[t];for(;n.length>=2;){let e=n[n.length-1],t=n[n.length-2];if((e.x-t.x)*(r.y-t.y)>=(e.y-t.y)*(r.x-t.x))n.pop();else break}n.push(r)}return n.pop(),t.length===1&&n.length===1&&t[0].x===n[0].x&&t[0].y===n[0].y?t:t.concat(n)}var by=Jv,xy=Qv,Sy=ey,Cy=iy,wy=oy,Ty=py;function Ey(e){var t,n,r=``;if(typeof e==`string`||typeof e==`number`)r+=e;else if(typeof e==`object`)if(Array.isArray(e)){var i=e.length;for(t=0;t<i;t++)e[t]&&(n=Ey(e[t]))&&(r&&(r+=` `),r+=n)}else for(n in e)e[n]&&(r&&(r+=` `),r+=n);return r}function Dy(){for(var e,t,n=0,r=``,i=arguments.length;n<i;n++)(e=arguments[n])&&(t=Ey(e))&&(r&&(r+=` `),r+=t);return r}var Oy=(e,t)=>{let n=Array(e.length+t.length);for(let t=0;t<e.length;t++)n[t]=e[t];for(let r=0;r<t.length;r++)n[e.length+r]=t[r];return n},ky=(e,t)=>({classGroupId:e,validator:t}),Ay=(e=new Map,t=null,n)=>({nextPart:e,validators:t,classGroupId:n}),jy=`-`,My=[],Ny=`arbitrary..`,Py=e=>{let t=Ly(e),{conflictingClassGroups:n,conflictingClassGroupModifiers:r}=e;return{getClassGroupId:e=>{if(e.startsWith(`[`)&&e.endsWith(`]`))return Iy(e);let n=e.split(jy);return Fy(n,n[0]===``&&n.length>1?1:0,t)},getConflictingClassGroupIds:(e,t)=>{if(t){let t=r[e],i=n[e];return t?i?Oy(i,t):t:i||My}return n[e]||My}}},Fy=(e,t,n)=>{if(e.length-t===0)return n.classGroupId;let r=e[t],i=n.nextPart.get(r);if(i){let n=Fy(e,t+1,i);if(n)return n}let a=n.validators;if(a===null)return;let o=t===0?e.join(jy):e.slice(t).join(jy),s=a.length;for(let e=0;e<s;e++){let t=a[e];if(t.validator(o))return t.classGroupId}},Iy=e=>e.slice(1,-1).indexOf(`:`)===-1?void 0:(()=>{let t=e.slice(1,-1),n=t.indexOf(`:`),r=t.slice(0,n);return r?Ny+r:void 0})(),Ly=e=>{let{theme:t,classGroups:n}=e;return Ry(n,t)},Ry=(e,t)=>{let n=Ay();for(let r in e){let i=e[r];zy(i,n,r,t)}return n},zy=(e,t,n,r)=>{let i=e.length;for(let a=0;a<i;a++){let i=e[a];By(i,t,n,r)}},By=(e,t,n,r)=>{if(typeof e==`string`){Vy(e,t,n);return}if(typeof e==`function`){Hy(e,t,n,r);return}Uy(e,t,n,r)},Vy=(e,t,n)=>{let r=e===``?t:Wy(t,e);r.classGroupId=n},Hy=(e,t,n,r)=>{if(Gy(e)){zy(e(r),t,n,r);return}t.validators===null&&(t.validators=[]),t.validators.push(ky(n,e))},Uy=(e,t,n,r)=>{let i=Object.entries(e),a=i.length;for(let e=0;e<a;e++){let[a,o]=i[e];zy(o,Wy(t,a),n,r)}},Wy=(e,t)=>{let n=e,r=t.split(jy),i=r.length;for(let e=0;e<i;e++){let t=r[e],i=n.nextPart.get(t);i||(i=Ay(),n.nextPart.set(t,i)),n=i}return n},Gy=e=>`isThemeGetter`in e&&e.isThemeGetter===!0,Ky=e=>{if(e<1)return{get:()=>void 0,set:()=>{}};let t=0,n=Object.create(null),r=Object.create(null),i=(i,a)=>{n[i]=a,t++,t>e&&(t=0,r=n,n=Object.create(null))};return{get(e){let t=n[e];if(t!==void 0)return t;if((t=r[e])!==void 0)return i(e,t),t},set(e,t){e in n?n[e]=t:i(e,t)}}},qy=`!`,Jy=`:`,Yy=[],Xy=(e,t,n,r,i)=>({modifiers:e,hasImportantModifier:t,baseClassName:n,maybePostfixModifierPosition:r,isExternal:i}),Zy=e=>{let{prefix:t,experimentalParseClassName:n}=e,r=e=>{let t=[],n=0,r=0,i=0,a,o=e.length;for(let s=0;s<o;s++){let o=e[s];if(n===0&&r===0){if(o===Jy){t.push(e.slice(i,s)),i=s+1;continue}if(o===`/`){a=s;continue}}o===`[`?n++:o===`]`?n--:o===`(`?r++:o===`)`&&r--}let s=t.length===0?e:e.slice(i),c=s,l=!1;s.endsWith(qy)?(c=s.slice(0,-1),l=!0):s.startsWith(qy)&&(c=s.slice(1),l=!0);let u=a&&a>i?a-i:void 0;return Xy(t,l,c,u)};if(t){let e=t+Jy,n=r;r=t=>t.startsWith(e)?n(t.slice(e.length)):Xy(Yy,!1,t,void 0,!0)}if(n){let e=r;r=t=>n({className:t,parseClassName:e})}return r},Qy=e=>{let t=new Map;return e.orderSensitiveModifiers.forEach((e,n)=>{t.set(e,1e6+n)}),e=>{let n=[],r=[];for(let i=0;i<e.length;i++){let a=e[i],o=a[0]===`[`,s=t.has(a);o||s?(r.length>0&&(r.sort(),n.push(...r),r=[]),n.push(a)):r.push(a)}return r.length>0&&(r.sort(),n.push(...r)),n}},$y=e=>({cache:Ky(e.cacheSize),parseClassName:Zy(e),sortModifiers:Qy(e),...Py(e)}),eb=/\s+/,tb=(e,t)=>{let{parseClassName:n,getClassGroupId:r,getConflictingClassGroupIds:i,sortModifiers:a}=t,o=[],s=e.trim().split(eb),c=``;for(let e=s.length-1;e>=0;--e){let t=s[e],{isExternal:l,modifiers:u,hasImportantModifier:d,baseClassName:f,maybePostfixModifierPosition:p}=n(t);if(l){c=t+(c.length>0?` `+c:c);continue}let m=!!p,h=r(m?f.substring(0,p):f);
vendor: 4,698 bytes, line 61
61if(!h){if(!m){c=t+(c.length>0?` `+c:c);continue}if(h=r(f),!h){c=t+(c.length>0?` `+c:c);continue}m=!1}let g=u.length===0?``:u.length===1?u[0]:a(u).join(`:`),_=d?g+qy:g,v=_+h;if(o.indexOf(v)>-1)continue;o.push(v);let y=i(h,m);for(let e=0;e<y.length;++e){let t=y[e];o.push(_+t)}c=t+(c.length>0?` `+c:c)}return c},nb=(...e)=>{let t=0,n,r,i=``;for(;t<e.length;)(n=e[t++])&&(r=rb(n))&&(i&&(i+=` `),i+=r);return i},rb=e=>{if(typeof e==`string`)return e;let t,n=``;for(let r=0;r<e.length;r++)e[r]&&(t=rb(e[r]))&&(n&&(n+=` `),n+=t);return n},ib=(e,...t)=>{let n,r,i,a,o=o=>(n=$y(t.reduce((e,t)=>t(e),e())),r=n.cache.get,i=n.cache.set,a=s,s(o)),s=e=>{let t=r(e);if(t)return t;let a=tb(e,n);return i(e,a),a};return a=o,(...e)=>a(nb(...e))},ab=[],ob=e=>{let t=t=>t[e]||ab;return t.isThemeGetter=!0,t},sb=/^\[(?:(\w[\w-]*):)?(.+)\]$/i,cb=/^\((?:(\w[\w-]*):)?(.+)\)$/i,lb=/^\d+(?:\.\d+)?\/\d+(?:\.\d+)?$/,ub=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,db=/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/,fb=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix)\(.+\)$/,pb=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,mb=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,hb=e=>lb.test(e),gb=e=>!!e&&!Number.isNaN(Number(e)),_b=e=>!!e&&Number.isInteger(Number(e)),vb=e=>e.endsWith(`%`)&&gb(e.slice(0,-1)),yb=e=>ub.test(e),bb=()=>!0,xb=e=>db.test(e)&&!fb.test(e),Sb=()=>!1,Cb=e=>pb.test(e),wb=e=>mb.test(e),Tb=e=>!Db(e)&&!Fb(e),Eb=e=>Ub(e,qb,Sb),Db=e=>sb.test(e),Ob=e=>Ub(e,Jb,xb),kb=e=>Ub(e,Yb,gb),Ab=e=>Ub(e,Zb,bb),jb=e=>Ub(e,Xb,Sb),Mb=e=>Ub(e,Gb,Sb),Nb=e=>Ub(e,Kb,wb),Pb=e=>Ub(e,Qb,Cb),Fb=e=>cb.test(e),Ib=e=>Wb(e,Jb),Lb=e=>Wb(e,Xb),Rb=e=>Wb(e,Gb),zb=e=>Wb(e,qb),Bb=e=>Wb(e,Kb),Vb=e=>Wb(e,Qb,!0),Hb=e=>Wb(e,Zb,!0),Ub=(e,t,n)=>{let r=sb.exec(e);return r?r[1]?t(r[1]):n(r[2]):!1},Wb=(e,t,n=!1)=>{let r=cb.exec(e);return r?r[1]?t(r[1]):n:!1},Gb=e=>e===`position`||e===`percentage`,Kb=e=>e===`image`||e===`url`,qb=e=>e===`length`||e===`size`||e===`bg-size`,Jb=e=>e===`length`,Yb=e=>e===`number`,Xb=e=>e===`family-name`,Zb=e=>e===`number`||e===`weight`,Qb=e=>e===`shadow`,$b=ib(()=>{let e=ob(`color`),t=ob(`font`),n=ob(`text`),r=ob(`font-weight`),i=ob(`tracking`),a=ob(`leading`),o=ob(`breakpoint`),s=ob(`container`),c=ob(`spacing`),l=ob(`radius`),u=ob(`shadow`),d=ob(`inset-shadow`),f=ob(`text-shadow`),p=ob(`drop-shadow`),m=ob(`blur`),h=ob(`perspective`),g=ob(`aspect`),_=ob(`ease`),v=ob(`animate`),y=()=>[`auto`,`avoid`,`all`,`avoid-page`,`page`,`left`,`right`,`column`],b=()=>[`center`,`top`,`bottom`,`left`,`right`,`top-left`,`left-top`,`top-right`,`right-top`,`bottom-right`,`right-bottom`,`bottom-left`,`left-bottom`],x=()=>[...b(),Fb,Db],S=()=>[`auto`,`hidden`,`clip`,`visible`,`scroll`],C=()=>[`auto`,`contain`,`none`],w=()=>[Fb,Db,c],T=()=>[hb,`full`,`auto`,...w()],E=()=>[_b,`none`,`subgrid`,Fb,Db],D=()=>[`auto`,{span:[`full`,_b,Fb,Db]},_b,Fb,Db],O=()=>[_b,`auto`,Fb,Db],k=()=>[`auto`,`min`,`max`,`fr`,Fb,Db],A=()=>[`start`,`end`,`center`,`between`,`around`,`evenly`,`stretch`,`baseline`,`center-safe`,`end-safe`],j=()=>[`start`,`end`,`center`,`stretch`,`center-safe`,`end-safe`],M=()=>[`auto`,...w()],ee=()=>[hb,`auto`,`full`,`dvw`,`dvh`,`lvw`,`lvh`,`svw`,`svh`,`min`,`max`,`fit`,...w()],N=()=>[hb,`screen`,`full`,`dvw`,`lvw`,`svw`,`min`,`max`,`fit`,...w()],P=()=>[hb,`screen`,`full`,`lh`,`dvh`,`lvh`,`svh`,`min`,`max`,`fit`,...w()],F=()=>[e,Fb,Db],I=()=>[...b(),Rb,Mb,{position:[Fb,Db]}],te=()=>[`no-repeat`,{repeat:[``,`x`,`y`,`space`,`round`]}],ne=()=>[`auto`,`cover`,`contain`,zb,Eb,{size:[Fb,Db]}],re=()=>[vb,Ib,Ob],ie=()=>[``,`none`,`full`,l,Fb,Db],ae=()=>[``,gb,Ib,Ob],oe=()=>[`solid`,`dashed`,`dotted`,`double`],se=()=>[`normal`,`multiply`,`screen`,`overlay`,`darken`,`lighten`,`color-dodge`,`color-burn`,`hard-light`,`soft-light`,`difference`,`exclusion`,`hue`,`saturation`,`color`,`luminosity`],ce=()=>[gb,vb,Rb,Mb],le=()=>[``,`none`,m,Fb,Db],ue=()=>[`none`,gb,Fb,Db],de=()=>[`none`,gb,Fb,Db],fe=()=>[gb,Fb,Db],pe=()=>[hb,`full`,...w()];return{cacheSize:500,theme:{animate:[`spin`,`ping`,`pulse`,`bounce`],aspect:[`video`],blur:[yb],breakpoint:[yb],color:[bb],container:[yb],"drop-shadow":[yb],ease:[`in`,`out`,`in-out`],font:[Tb],"font-weight":[`thin`,`extralight`,`light`,`normal`,`medium`,`semibold`,`bold`,`extrabold`,`black`],"inset-shadow":[yb],leading:[`none`,`tight`,`snug`,`normal`,`relaxed`,`loose`],perspective:[`dramatic`,`near`,`normal`,`midrange`,`distant`,`none`],radius:[yb],shadow:[yb],spacing:[`px`,gb],text:[yb],"text-shadow":[yb],tracking:[`tighter`,`tight`,`normal`,`wide`,`wider`,`widest`]},classGroups:{aspect:[{aspect:[`auto`,`square`,hb,Db,Fb,g]}
vendor: 6,101 bytes, line 61
61],container:[`container`],columns:[{columns:[gb,Db,Fb,s]}],"break-after":[{"break-after":y()}],"break-before":[{"break-before":y()}],"break-inside":[{"break-inside":[`auto`,`avoid`,`avoid-page`,`avoid-column`]}],"box-decoration":[{"box-decoration":[`slice`,`clone`]}],box:[{box:[`border`,`content`]}],display:[`block`,`inline-block`,`inline`,`flex`,`inline-flex`,`table`,`inline-table`,`table-caption`,`table-cell`,`table-column`,`table-column-group`,`table-footer-group`,`table-header-group`,`table-row-group`,`table-row`,`flow-root`,`grid`,`inline-grid`,`contents`,`list-item`,`hidden`],sr:[`sr-only`,`not-sr-only`],float:[{float:[`right`,`left`,`none`,`start`,`end`]}],clear:[{clear:[`left`,`right`,`both`,`none`,`start`,`end`]}],isolation:[`isolate`,`isolation-auto`],"object-fit":[{object:[`contain`,`cover`,`fill`,`none`,`scale-down`]}],"object-position":[{object:x()}],overflow:[{overflow:S()}],"overflow-x":[{"overflow-x":S()}],"overflow-y":[{"overflow-y":S()}],overscroll:[{overscroll:C()}],"overscroll-x":[{"overscroll-x":C()}],"overscroll-y":[{"overscroll-y":C()}],position:[`static`,`fixed`,`absolute`,`relative`,`sticky`],inset:[{inset:T()}],"inset-x":[{"inset-x":T()}],"inset-y":[{"inset-y":T()}],start:[{"inset-s":T(),start:T()}],end:[{"inset-e":T(),end:T()}],"inset-bs":[{"inset-bs":T()}],"inset-be":[{"inset-be":T()}],top:[{top:T()}],right:[{right:T()}],bottom:[{bottom:T()}],left:[{left:T()}],visibility:[`visible`,`invisible`,`collapse`],z:[{z:[_b,`auto`,Fb,Db]}],basis:[{basis:[hb,`full`,`auto`,s,...w()]}],"flex-direction":[{flex:[`row`,`row-reverse`,`col`,`col-reverse`]}],"flex-wrap":[{flex:[`nowrap`,`wrap`,`wrap-reverse`]}],flex:[{flex:[gb,hb,`auto`,`initial`,`none`,Db]}],grow:[{grow:[``,gb,Fb,Db]}],shrink:[{shrink:[``,gb,Fb,Db]}],order:[{order:[_b,`first`,`last`,`none`,Fb,Db]}],"grid-cols":[{"grid-cols":E()}],"col-start-end":[{col:D()}],"col-start":[{"col-start":O()}],"col-end":[{"col-end":O()}],"grid-rows":[{"grid-rows":E()}],"row-start-end":[{row:D()}],"row-start":[{"row-start":O()}],"row-end":[{"row-end":O()}],"grid-flow":[{"grid-flow":[`row`,`col`,`dense`,`row-dense`,`col-dense`]}],"auto-cols":[{"auto-cols":k()}],"auto-rows":[{"auto-rows":k()}],gap:[{gap:w()}],"gap-x":[{"gap-x":w()}],"gap-y":[{"gap-y":w()}],"justify-content":[{justify:[...A(),`normal`]}],"justify-items":[{"justify-items":[...j(),`normal`]}],"justify-self":[{"justify-self":[`auto`,...j()]}],"align-content":[{content:[`normal`,...A()]}],"align-items":[{items:[...j(),{baseline:[``,`last`]}]}],"align-self":[{self:[`auto`,...j(),{baseline:[``,`last`]}]}],"place-content":[{"place-content":A()}],"place-items":[{"place-items":[...j(),`baseline`]}],"place-self":[{"place-self":[`auto`,...j()]}],p:[{p:w()}],px:[{px:w()}],py:[{py:w()}],ps:[{ps:w()}],pe:[{pe:w()}],pbs:[{pbs:w()}],pbe:[{pbe:w()}],pt:[{pt:w()}],pr:[{pr:w()}],pb:[{pb:w()}],pl:[{pl:w()}],m:[{m:M()}],mx:[{mx:M()}],my:[{my:M()}],ms:[{ms:M()}],me:[{me:M()}],mbs:[{mbs:M()}],mbe:[{mbe:M()}],mt:[{mt:M()}],mr:[{mr:M()}],mb:[{mb:M()}],ml:[{ml:M()}],"space-x":[{"space-x":w()}],"space-x-reverse":[`space-x-reverse`],"space-y":[{"space-y":w()}],"space-y-reverse":[`space-y-reverse`],size:[{size:ee()}],"inline-size":[{inline:[`auto`,...N()]}],"min-inline-size":[{"min-inline":[`auto`,...N()]}],"max-inline-size":[{"max-inline":[`none`,...N()]}],"block-size":[{block:[`auto`,...P()]}],"min-block-size":[{"min-block":[`auto`,...P()]}],"max-block-size":[{"max-block":[`none`,...P()]}],w:[{w:[s,`screen`,...ee()]}],"min-w":[{"min-w":[s,`screen`,`none`,...ee()]}],"max-w":[{"max-w":[s,`screen`,`none`,`prose`,{screen:[o]},...ee()]}],h:[{h:[`screen`,`lh`,...ee()]}],"min-h":[{"min-h":[`screen`,`lh`,`none`,...ee()]}],"max-h":[{"max-h":[`screen`,`lh`,...ee()]}],"font-size":[{text:[`base`,n,Ib,Ob]}],"font-smoothing":[`antialiased`,`subpixel-antialiased`],"font-style":[`italic`,`not-italic`],"font-weight":[{font:[r,Hb,Ab]}],"font-stretch":[{"font-stretch":[`ultra-condensed`,`extra-condensed`,`condensed`,`semi-condensed`,`normal`,`semi-expanded`,`expanded`,`extra-expanded`,`ultra-expanded`,vb,Db]}],"font-family":[{font:[Lb,jb,t]}],"font-features":[{"font-features":[Db]}],"fvn-normal":[`normal-nums`],"fvn-ordinal":[`ordinal`],"fvn-slashed-zero":[`slashed-zero`],"fvn-figure":[`lining-nums`,`oldstyle-nums`],"fvn-spacing":[`proportional-nums`,`tabular-nums`],"fvn-fraction":[`diagonal-fractions`,`stacked-fractions`],tracking:[{tracking:[i,Fb,Db]}],"line-clamp":[{"line-clamp":[gb,`none`,Fb,kb]}],leading:[{leading:[a,...w()]}],"list-image":[{"list-image":[`none`,Fb,Db]}],"list-style-position":[{list:[`inside`,`outside`]}],"list-style-type":[{list:[`disc`,`decimal`,`none`,Fb,Db]}],"text-alignment":[{text:[`left`,`center`,`right`,`justify`,`start`,`end`]}],"placeholder-color":[{placeholder:F()}],"text-color":[{text:F()}],"text-decoration":[`underline`,`overline`,`line-through`,`no-underline`],"text-decoration-style":[{decoration:[...oe(),`wavy`]}],"text-decoration-thickness":[{decoration:[gb,`from-font`,`auto`,Fb,Ob]}],"text-decoration-color":[{decoration:F()}],"underline-offset":[{"underline-offset":[gb,`auto`,Fb,Db]}],"text-transform":[`uppercase`,`lowercase`,`capitalize`,`normal-case`],"text-overflow":[`truncate`,`text-ellipsis`,`text-clip`],"text-wrap":[{text:[`wrap`,`nowrap`,`balance`,`pretty`]}],indent:[{indent:w()}],"vertical-align":[{align:[`baseline`,`top`,`middle`,`bottom`,`text-top`,`text-bottom`,`sub`,`super`,Fb,Db]}],whitespace:[{whitespace:[`normal`,`nowrap`,`pre`,`pre-line`,`pre-wrap`,`break-spaces`]}],break:[{break:[`normal`,`words`,`all`,`keep`]}],wrap:[{wrap:[`break-word`,`anywhere`,`normal`]}],hyphens:[{hyphens:[`none`,`manual`,`auto`]}],content:[{content:[`none`,Fb,Db]}],"bg-attachment":[{bg:[`fixed`,`local`,`scroll`]}],"bg-clip":[{"bg-clip":[`border`,`padding`,`content`,`text`]}],"bg-origin":[{"bg-origin":[`border`,`padding`,`content`]}],"bg-position":[{bg:I()}],"bg-repeat":[{bg:te()}],"bg-size":[{bg:ne()}],"bg-image":[{bg:[`none`,{linear:[{to:[`t`,`tr`,`r`,`br`,`b`,`bl`,`l`,`tl`]},_b,Fb,Db],radial:[``,Fb,Db],conic:[_b,Fb,Db]},Bb,Nb]}],"bg-color":[{bg:F()}],"gradient-from-pos":[{from:re()}
vendor: 7,881 bytes, line 61
61],"gradient-via-pos":[{via:re()}],"gradient-to-pos":[{to:re()}],"gradient-from":[{from:F()}],"gradient-via":[{via:F()}],"gradient-to":[{to:F()}],rounded:[{rounded:ie()}],"rounded-s":[{"rounded-s":ie()}],"rounded-e":[{"rounded-e":ie()}],"rounded-t":[{"rounded-t":ie()}],"rounded-r":[{"rounded-r":ie()}],"rounded-b":[{"rounded-b":ie()}],"rounded-l":[{"rounded-l":ie()}],"rounded-ss":[{"rounded-ss":ie()}],"rounded-se":[{"rounded-se":ie()}],"rounded-ee":[{"rounded-ee":ie()}],"rounded-es":[{"rounded-es":ie()}],"rounded-tl":[{"rounded-tl":ie()}],"rounded-tr":[{"rounded-tr":ie()}],"rounded-br":[{"rounded-br":ie()}],"rounded-bl":[{"rounded-bl":ie()}],"border-w":[{border:ae()}],"border-w-x":[{"border-x":ae()}],"border-w-y":[{"border-y":ae()}],"border-w-s":[{"border-s":ae()}],"border-w-e":[{"border-e":ae()}],"border-w-bs":[{"border-bs":ae()}],"border-w-be":[{"border-be":ae()}],"border-w-t":[{"border-t":ae()}],"border-w-r":[{"border-r":ae()}],"border-w-b":[{"border-b":ae()}],"border-w-l":[{"border-l":ae()}],"divide-x":[{"divide-x":ae()}],"divide-x-reverse":[`divide-x-reverse`],"divide-y":[{"divide-y":ae()}],"divide-y-reverse":[`divide-y-reverse`],"border-style":[{border:[...oe(),`hidden`,`none`]}],"divide-style":[{divide:[...oe(),`hidden`,`none`]}],"border-color":[{border:F()}],"border-color-x":[{"border-x":F()}],"border-color-y":[{"border-y":F()}],"border-color-s":[{"border-s":F()}],"border-color-e":[{"border-e":F()}],"border-color-bs":[{"border-bs":F()}],"border-color-be":[{"border-be":F()}],"border-color-t":[{"border-t":F()}],"border-color-r":[{"border-r":F()}],"border-color-b":[{"border-b":F()}],"border-color-l":[{"border-l":F()}],"divide-color":[{divide:F()}],"outline-style":[{outline:[...oe(),`none`,`hidden`]}],"outline-offset":[{"outline-offset":[gb,Fb,Db]}],"outline-w":[{outline:[``,gb,Ib,Ob]}],"outline-color":[{outline:F()}],shadow:[{shadow:[``,`none`,u,Vb,Pb]}],"shadow-color":[{shadow:F()}],"inset-shadow":[{"inset-shadow":[`none`,d,Vb,Pb]}],"inset-shadow-color":[{"inset-shadow":F()}],"ring-w":[{ring:ae()}],"ring-w-inset":[`ring-inset`],"ring-color":[{ring:F()}],"ring-offset-w":[{"ring-offset":[gb,Ob]}],"ring-offset-color":[{"ring-offset":F()}],"inset-ring-w":[{"inset-ring":ae()}],"inset-ring-color":[{"inset-ring":F()}],"text-shadow":[{"text-shadow":[`none`,f,Vb,Pb]}],"text-shadow-color":[{"text-shadow":F()}],opacity:[{opacity:[gb,Fb,Db]}],"mix-blend":[{"mix-blend":[...se(),`plus-darker`,`plus-lighter`]}],"bg-blend":[{"bg-blend":se()}],"mask-clip":[{"mask-clip":[`border`,`padding`,`content`,`fill`,`stroke`,`view`]},`mask-no-clip`],"mask-composite":[{mask:[`add`,`subtract`,`intersect`,`exclude`]}],"mask-image-linear-pos":[{"mask-linear":[gb]}],"mask-image-linear-from-pos":[{"mask-linear-from":ce()}],"mask-image-linear-to-pos":[{"mask-linear-to":ce()}],"mask-image-linear-from-color":[{"mask-linear-from":F()}],"mask-image-linear-to-color":[{"mask-linear-to":F()}],"mask-image-t-from-pos":[{"mask-t-from":ce()}],"mask-image-t-to-pos":[{"mask-t-to":ce()}],"mask-image-t-from-color":[{"mask-t-from":F()}],"mask-image-t-to-color":[{"mask-t-to":F()}],"mask-image-r-from-pos":[{"mask-r-from":ce()}],"mask-image-r-to-pos":[{"mask-r-to":ce()}],"mask-image-r-from-color":[{"mask-r-from":F()}],"mask-image-r-to-color":[{"mask-r-to":F()}],"mask-image-b-from-pos":[{"mask-b-from":ce()}],"mask-image-b-to-pos":[{"mask-b-to":ce()}],"mask-image-b-from-color":[{"mask-b-from":F()}],"mask-image-b-to-color":[{"mask-b-to":F()}],"mask-image-l-from-pos":[{"mask-l-from":ce()}],"mask-image-l-to-pos":[{"mask-l-to":ce()}],"mask-image-l-from-color":[{"mask-l-from":F()}],"mask-image-l-to-color":[{"mask-l-to":F()}],"mask-image-x-from-pos":[{"mask-x-from":ce()}],"mask-image-x-to-pos":[{"mask-x-to":ce()}],"mask-image-x-from-color":[{"mask-x-from":F()}],"mask-image-x-to-color":[{"mask-x-to":F()}],"mask-image-y-from-pos":[{"mask-y-from":ce()}],"mask-image-y-to-pos":[{"mask-y-to":ce()}],"mask-image-y-from-color":[{"mask-y-from":F()}],"mask-image-y-to-color":[{"mask-y-to":F()}],"mask-image-radial":[{"mask-radial":[Fb,Db]}],"mask-image-radial-from-pos":[{"mask-radial-from":ce()}],"mask-image-radial-to-pos":[{"mask-radial-to":ce()}],"mask-image-radial-from-color":[{"mask-radial-from":F()}],"mask-image-radial-to-color":[{"mask-radial-to":F()}],"mask-image-radial-shape":[{"mask-radial":[`circle`,`ellipse`]}],"mask-image-radial-size":[{"mask-radial":[{closest:[`side`,`corner`],farthest:[`side`,`corner`]}]}],"mask-image-radial-pos":[{"mask-radial-at":b()}],"mask-image-conic-pos":[{"mask-conic":[gb]}],"mask-image-conic-from-pos":[{"mask-conic-from":ce()}],"mask-image-conic-to-pos":[{"mask-conic-to":ce()}],"mask-image-conic-from-color":[{"mask-conic-from":F()}],"mask-image-conic-to-color":[{"mask-conic-to":F()}],"mask-mode":[{mask:[`alpha`,`luminance`,`match`]}],"mask-origin":[{"mask-origin":[`border`,`padding`,`content`,`fill`,`stroke`,`view`]}],"mask-position":[{mask:I()}],"mask-repeat":[{mask:te()}],"mask-size":[{mask:ne()}],"mask-type":[{"mask-type":[`alpha`,`luminance`]}],"mask-image":[{mask:[`none`,Fb,Db]}],filter:[{filter:[``,`none`,Fb,Db]}],blur:[{blur:le()}],brightness:[{brightness:[gb,Fb,Db]}],contrast:[{contrast:[gb,Fb,Db]}],"drop-shadow":[{"drop-shadow":[``,`none`,p,Vb,Pb]}],"drop-shadow-color":[{"drop-shadow":F()}],grayscale:[{grayscale:[``,gb,Fb,Db]}],"hue-rotate":[{"hue-rotate":[gb,Fb,Db]}],invert:[{invert:[``,gb,Fb,Db]}],saturate:[{saturate:[gb,Fb,Db]}],sepia:[{sepia:[``,gb,Fb,Db]}],"backdrop-filter":[{"backdrop-filter":[``,`none`,Fb,Db]}],"backdrop-blur":[{"backdrop-blur":le()}],"backdrop-brightness":[{"backdrop-brightness":[gb,Fb,Db]}],"backdrop-contrast":[{"backdrop-contrast":[gb,Fb,Db]}],"backdrop-grayscale":[{"backdrop-grayscale":[``,gb,Fb,Db]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[gb,Fb,Db]}],"backdrop-invert":[{"backdrop-invert":[``,gb,Fb,Db]}],"backdrop-opacity":[{"backdrop-opacity":[gb,Fb,Db]}],"backdrop-saturate":[{"backdrop-saturate":[gb,Fb,Db]}],"backdrop-sepia":[{"backdrop-sepia":[``,gb,Fb,Db]}],"border-collapse":[{border:[`collapse`,`separate`]}],"border-spacing":[{"border-spacing":w()}],"border-spacing-x":[{"border-spacing-x":w()}],"border-spacing-y":[{"border-spacing-y":w()}],"table-layout":[{table:[`auto`,`fixed`]}],caption:[{caption:[`top`,`bottom`]}],transition:[{transition:[``,`all`,`colors`,`opacity`,`shadow`,`transform`,`none`,Fb,Db]}],"transition-behavior":[{transition:[`normal`,`discrete`]}],duration:[{duration:[gb,`initial`,Fb,Db]}],ease:[{ease:[`linear`,`initial`,_,Fb,Db]}],delay:[{delay:[gb,Fb,Db]}],animate:[{animate:[`none`,v,Fb,Db]}],backface:[{backface:[`hidden`,`visible`]}],perspective:[{perspective:[h,Fb,Db]}],"perspective-origin":[{"perspective-origin":x()}],rotate:[{rotate:ue()}],"rotate-x":[{"rotate-x":ue()}],"rotate-y":[{"rotate-y":ue()}],"rotate-z":[{"rotate-z":ue()}],scale:[{scale:de()}],"scale-x":[{"scale-x":de()}],"scale-y":[{"scale-y":de()}],"scale-z":[{"scale-z":de()}],"scale-3d":[`scale-3d`],skew:[{skew:fe()}],"skew-x":[{"skew-x":fe()}],"skew-y":[{"skew-y":fe()}],transform:[{transform:[Fb,Db,``,`none`,`gpu`,`cpu`]}],"transform-origin":[{origin:x()}],"transform-style":[{transform:[`3d`,`flat`]}],translate:[{translate:pe()}],"translate-x":[{"translate-x":pe()}],"translate-y":[{"translate-y":pe()}],"translate-z":[{"translate-z":pe()}],"translate-none":[`translate-none`],accent:[{accent:F()}],appearance:[{appearance:[`none`,`auto`]}],"caret-color":[{caret:F()}],"color-scheme":[{scheme:[`normal`,`dark`,`light`,`light-dark`,`only-dark`,`only-light`]}],cursor:[{cursor:[`auto`,`default`,`pointer`,`wait`,`text`,`move`,`help`,`not-allowed`,`none`,`context-menu`,`progress`,`cell`,`crosshair`,`vertical-text`,`alias`,`copy`,`no-drop`,`grab`,`grabbing`,`all-scroll`,`col-resize`,`row-resize`,`n-resize`,`e-resize`,`s-resize`,`w-resize`,`ne-resize`,`nw-resize`,`se-resize`,`sw-resize`,`ew-resize`,`ns-resize`,`nesw-resize`,`nwse-resize`,`zoom
61-in`,`zoom-out`,Fb,Db]}],"field-sizing":[{"field-sizing":[`fixed`,`content`]}],"pointer-events":[{"pointer-events":[`auto`,`none`]}],resize:[{resize:[`none`,``,`y`,`x`]}],"scroll-behavior":[{scroll:[`auto`,`smooth`]}],"scroll-m":[{"scroll-m":w()}],"scroll-mx":[{"scroll-mx":w()}],"scroll-my":[{"scroll-my":w()}],"scroll-ms":[{"scroll-ms":w()}],"scroll-me":[{"scroll-me":w()}],"scroll-mbs":[{"scroll-mbs":w()}],"scroll-mbe":[{"scroll-mbe":w()}],"scroll-mt":[{"scroll-mt":w()}],"scroll-mr":[{"scroll-mr":w()}],"scroll-mb":[{"scroll-mb":w()}],"scroll-ml":[{"scroll-ml":w()}],"scroll-p":[{"scroll-p":w()}],"scroll-px":[{"scroll-px":w()}],"scroll-py":[{"scroll-py":w()}],"scroll-ps":[{"scroll-ps":w()}],"scroll-pe":[{"scroll-pe":w()}],"scroll-pbs":[{"scroll-pbs":w()}],"scroll-pbe":[{"scroll-pbe":w()}],"scroll-pt":[{"scroll-pt":w()}],"scroll-pr":[{"scroll-pr":w()}],"scroll-pb":[{"scroll-pb":w()}],"scroll-pl":[{"scroll-pl":w()}],"snap-align":[{snap:[`start`,`end`,`center`,`align-none`]}],"snap-stop":[{snap:[`normal`,`always`]}],"snap-type":[{snap:[`none`,`x`,`y`,`both`]}],"snap-strictness":[{snap:[`mandatory`,`proximity`]}
61],touch:[{touch:[`auto`,`none`,`manipulation`]}],"touch-x":[{"touch-pan":[`x`,`left`,`right`]}],"touch-y":[{"touch-pan":[`y`,`up`,`down`]}],"touch-pz":[`touch-pinch-zoom`],select:[{select:[`none`,`text`,`all`,`auto`]}],"will-change":[{"will-change":[`auto`,`scroll`,`contents`,`transform`,Fb,Db]}],fill:[{fill:[`none`,...F()]}],"stroke-w":[{stroke:[gb,Ib,Ob,kb]}],stroke:[{stroke:[`none`,...F()]}],"forced-color-adjust":[{"forced-color-adjust":[`auto`,`none`]}]},conflictingClassGroups:{overflow:[`overflow-x`,`overflow-y`],overscroll:[`overscroll-x`,`overscroll-y`],inset:[`inset-x`,`inset-y`,`inset-bs`,`inset-be`,`start`,`end`,`top`,`right`,`bottom`,`left`],"inset-x":[`right`,`left`],"inset-y":[`top`,`bottom`],flex:[`basis`,`grow`,`shrink`],gap:[`gap-x`,`gap-y`],p:[`px`,`py`,`ps`,`pe`,`pbs`,`pbe`,`pt`,`pr`,`pb`,`pl`],px:[`pr`,`pl`],py:[`pt`,`pb`],m:[`mx`,`my`,`ms`,`me`,`mbs`,`mbe`,`mt`,`mr`,`mb`,`ml`],mx:[`mr`,`ml`],my:[`mt`,`mb`],size:[`w`,`h`],"font-size":[`leading`],"fvn-normal":[`fvn-ordinal`,`fvn-slashed-zero`,`fvn-figure`,`fvn-spacing`,`fvn-fraction`],"fvn-ordinal":[`fvn-normal`],"fvn-slashed-zero":[`fvn-normal`],"fvn-figure":[`fvn-normal`],"fvn-spacing":[`fvn-normal`],"fvn-fraction":[`fvn-normal`],"line-clamp":[`display`,`overflow`],rounded:[`rounded-s`,`rounded-e`,`rounded-t`,`rounded-r`,`rounded-b`,`rounded-l`,`rounded-ss`,`rounded-se`,`rounded-ee`,`rounded-es`,`rounded-tl`,`rounded-tr`,`rounded-br`,`rounded-bl`],"rounded-s":[`rounded-ss`,`rounded-es`],"rounded-e":[`rounded-se`,`rounded-ee`],"rounded-t":[`rounded-tl`,`rounded-tr`],"rounded-r":[`rounded-tr`,`rounded-br`],"rounded-b":[`rounded-br`,`rounded-bl`],"rounded-l":[`rounded-tl`,`rounded-bl`],"border-spacing":[`border-spacing-x`,`border-spacing-y`],"border-w":[`border-w-x`,`border-w-y`,`border-w-s`,`border-w-e`,`border-w-bs`,`border-w-be`,`border-w-t`,`border-w-r`,`border-w-b`,`border-w-l`],"border-w-x":[`border-w-r`,`border-w-l`],"border-w-y":[`border-w-t`,`border-w-b`],"border-color":[`border-color-x`,`border-color-y`,`border-color-s`,`border-color-e`,`border-color-bs`,`border-color-be`,`border-color-t`,`border-color-r`,`border-color-b`,`border-color-l`],"border-color-x":[`border-color-r`,`border-color-l`],"border-color-y":[`border-color-t`,`border-color-b`],translate:[`translate-x`,`translate-y`,`translate-none`],"translate-none":[`translate`,`translate-x`,`translate-y`,`translate-z`],"scroll-m":[`scroll-mx`,`scroll-my`,`scroll-ms`,`scroll-me`,`scroll-mbs`,`scroll-mbe`,`scroll-mt`,`scroll-mr`,`scroll-mb`,`scroll-ml`],"scroll-mx":[`scroll-mr`,`scroll-ml`],"scroll-my":[`scroll-mt`,`scroll-mb`],"scroll-p":[`scroll-px`,`scroll-py`,`scroll-ps`,`scroll-pe`,`scroll-pbs`,`scroll-pbe`,`scroll-pt`,`scroll-pr`,`scroll-pb`,`scroll-pl`],"scroll-px":[`scroll-pr`,`scroll-pl`],"scroll-py":[`scroll-pt`,`scroll-pb`],touch:[`touch-x`,`touch-y`,`touch-pz`],"touch-x":[`touch`],"touch-y":[`touch`],"touch-pz":[`touch`]},conflictingClassGroupModifiers:{"font-size":[`leading`]},orderSensitiveModifiers:[`*`,`**`,`after`,`backdrop`,`before`,`details-content`,`file`,`first-letter`,`first-line`,`marker`,`placeholder`,`selection`]}});function V(...e){return $b(Dy(e))}function ex({delayDuration:e=0,...t}){return(0,L.jsx)(by,{"data-slot":`tooltip-provider`,delayDuration:e,...t})}function tx({...e}){return(0,L.jsx)(xy,{"data-slot":`tooltip`,...e})}function nx({...e}){return(0,L.jsx)(Sy,{"data-slot":`tooltip-trigger`,...e})}function rx({className:e,sideOffset:t=0,children:n,...r}){return(0,L.jsx)(Cy,{children:(0,L.jsxs)(wy,{"data-slot":`tooltip-content`,sideOffset:t,className:V(`z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95`,e),...r,children:[n,(0,L.jsx)(Ty,{className:`z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground`})]})})}var ix=Object.create(null),ax=e=>({}),ox=new Proxy(ix,{get(e,t){return ax()[t]??ix[t]},has(e,t){return t in ax()||t in ix},set(e,t,n){let r=ax(!0);return r[t]=n,!0},deleteProperty(e,t){if(!t)return!1;let n=ax(!0);return delete n[t],!0},ownKeys(){let e=ax(!0);return Object.keys(e)}});function sx(e,t){return typeof process<`u`?{}[e]??t:typeof Deno<`u`?Deno.env.get(e)??t:typeof Bun<`u`?Bun.env[e]??t:t}Object.freeze({get BETTER_AUTH_SECRET(){return sx(`BETTER_AUTH_SECRET`)},get AUTH_SECRET(){return sx(`AUTH_SECRET`)},get BETTER_AUTH_TELEMETRY(){return sx(`BETTER_AUTH_TELEMETRY`)},get BETTER_AUTH_TELEMETRY_ID(){return sx(`BETTER_AUTH_TELEMETRY_ID`)},get NODE_ENV(){return sx(`NODE_ENV`,`development`)},get PACKAGE_VERSION(){return sx(`PACKAGE_VERSION`,`0.0.0`)},get BETTER_AUTH_TELEMETRY_ENDPOINT(){return sx(`BETTER_AUTH_TELEMETRY_ENDPOINT`,``)}});var cx=1,lx=4,ux=8,dx=24,fx={eterm:lx,cons25:lx,console:lx,cygwin:lx,dtterm:lx,gnome:lx,hurd:lx,jfbterm:lx,konsole:lx,kterm:lx,mlterm:lx,mosh:dx,putty:lx,st:lx,"rxvt-unicode-24bit":dx,terminator:dx,"xterm-kitty":dx},px=new Map(Object.entries({APPVEYOR:ux,BUILDKITE:ux,CIRCLECI:dx,DRONE:ux,GITEA_ACTIONS:dx,GITHUB_ACTIONS:dx,GITLAB_CI:ux,TRAVIS:ux})),mx=[/ansi/,/color/,/linux/,/direct/,/^con[0-9]*x[0-9]/,/^rxvt/,/^screen/,/^xterm/,/^vt100/,/^vt220/];function hx(){if(sx(`FORCE_COLOR`)!==void 0)switch(sx(`FORCE_COLOR`)){case``:case`1`:case`true`:return lx;case`2`:return ux;case`3`:return dx;default:return cx}if(sx(`NODE_DISABLE_COLORS`)!==void 0&&sx(`NODE_DISABLE_COLORS`)!==``||sx(`NO_COLOR`)!==void 0&&sx(`NO_COLOR`)!==``||sx(`TERM`)===`dumb`)return cx;if(sx(`TMUX`))return dx;if(`TF_BUILD`in ox&&`AGENT_NAME`in ox)return lx;if(`CI`in ox){for(let{0:e,1:t}of px)if(e in ox)return t;return sx(`CI_NAME`)===`codeship`?ux:cx}if(`TEAMCITY_VERSION`in ox)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.exec(sx(`TEAMCITY_VERSION`))===null?cx:lx;switch(sx(`TERM_PROGRAM`)){case`iTerm.app`:return!sx(`TERM_PROGRAM_VERSION`)||/^[0-2]\./.exec(sx(`TERM_PROGRAM_VERSION`))!==null?ux:dx;case`HyperTerm`:case`MacTerm`:return dx;case`Apple_Terminal`:return ux}if(sx(`COLORTERM`)===`truecolor`||sx(`COLORTERM`)===`24bit`)return dx;if(sx(`TERM`)){if(/truecolor/.exec(sx(`TERM`))!==null)return dx;if(/^xterm-256/.exec(sx(`TERM`))!==null)return ux;let e=sx(`TERM`).toLowerCase();if(fx[e])return fx[e];if(mx.some(t=>t.exec(e)!==null))return lx}return sx(`COLORTERM`)?lx:cx}var gx={reset:`\x1B[0m`,bright:`\x1B[1m`,dim:`\x1B[2m`,undim:`\x1B[22m`,underscore:`\x1B[4m`,blink:`\x1B[5m`,reverse:`\x1B[7m`,hidden:`\x1B[8m`,fg:{black:`\x1B[30m`,red:`\x1B[31m`,green:`\x1B[32m`,yellow:`\x1B[33m`,blue:`\x1B[34m`,magenta:`\x1B[35m`,cyan:`\x1B[36m`,white:`\x1B[37m`},bg:{black:`\x1B[40m`,red:`\x1B[41m`,green:`\x1B[42m`,yellow:`\x1B[43m`,blue:`\x1B[44m`,magenta:`\x1B[45m`,cyan:`\x1B[46m`,white:`\x1B[47m`}},_x=[`debug`,`info`,`success`,`warn`,`error`];function vx(e,t){return _x.indexOf(t)>=_x.indexOf(e)}var yx={info:gx.fg.blue,success:gx.fg.green,warn:gx.fg.yellow,error:gx.fg.red,debug:gx.fg.magenta},bx=(e,t,n)=>{let r=new Date().toISOString();return n?`${gx.dim}${r}${gx.reset} ${yx[e]}${e.toUpperCase()}${gx.reset} ${gx.bright}[Better Auth]:${gx.reset} ${t}`:`${r} ${e.toUpperCase()} [Better Auth]: ${t}`};(e=>{let t=e?.disabled!==!0,n=e?.level??`warn`,r=e?.disableColors===void 0?hx()!==1:!e.disableColors,i=(i,a,o=[])=>{if(!t||!vx(n,i))return;let s=bx(i,a,r);if(!e||typeof e.log!=`function`){i===`error`?console.error(s,...o):i===`warn`?console.warn(s,...o):console.log(s,...o);return}e.log(i===`success`?`info`:i,a,...o)};return{...Object.fromEntries(_x.map(e=>[e,(...[t,...n])=>i(e,t,n)])),get level(){return n}}})();function xx(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,{code:e,message:t,toString:()=>e}]))}xx({USER_NOT_FOUND:`User not found`,FAILED_TO_CREATE_USER:`Failed to create user`,FAILED_TO_CREATE_SESSION:`Failed to create session`,FAILED_TO_UPDATE_USER:`Failed to update user`,FAILED_TO_GET_SESSION:`Failed to get session`,INVALID_PASSWORD:`Invalid password`,INVALID_EMAIL:`Invalid email`,INVALID_EMAIL_OR_PASSWORD:`Invalid email or password`,INVALID_USER:`Invalid user`,SOCIAL_ACCOUNT_ALREADY_LINKED:`Social account already linked`,PROVIDER_NOT_FOUND:`Provider not found`,INVA
61LID_TOKEN:`Invalid token`,TOKEN_EXPIRED:`Token expired`,ID_TOKEN_NOT_SUPPORTED:`id_token not supported`,FAILED_TO_GET_USER_INFO:`Failed to get user info`,USER_EMAIL_NOT_FOUND:`User email not found`,EMAIL_NOT_VERIFIED:`Email not verified`,PASSWORD_TOO_SHORT:`Password too short`,PASSWORD_TOO_LONG:`Password too long`,USER_ALREADY_EXISTS:`User already exists.`,USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL:`User already exists. Use another email.`,EMAIL_CAN_NOT_BE_UPDATED:`Email can not be updated`,CREDENTIAL_ACCOUNT_NOT_FOUND:`Credential account not found`,SESSION_EXPIRED:`Session expired. Re-authenticate to perform this action.`,FAILED_TO_UNLINK_LAST_ACCOUNT:`You can't unlink your last account`,ACCOUNT_NOT_FOUND:`Account not found`,USER_ALREADY_HAS_PASSWORD:`User already has a password. Provide that to delete the account.`,CROSS_SITE_NAVIGATION_LOGIN_BLOCKED:`Cross-site navigation login blocked. This request appears to be a CSRF attack.`,VERIFICATION_EMAIL_NOT_ENABLED:`Verification email isn't enabled`,EMAIL_ALREADY_VERIFIED:`Email is already verified`,EMAIL_MISMATCH:`Email mismatch`,SESSION_NOT_FRESH:`Session is not fresh`,LINKED_ACCOUNT_ALREADY_EXISTS:`Linked account already exists`,INVALID_ORIGIN:`Invalid origin`,INVALID_CALLBACK_URL:`Invalid callbackURL`,INVALID_REDIRECT_URL:`Invalid redirectURL`,INVALID_ERROR_CALLBACK_URL:`Invalid errorCallbackURL`,INVALID_NEW_USER_CALLBACK_URL:`Invalid newUserCallbackURL`,MISSING_OR_NULL_ORIGIN:`Missing or null Origin`,CALLBACK_URL_REQUIRED:`callbackURL is required`,FAILED_TO_CREATE_VERIFICATION:`Unable to create verification`,FIELD_NOT_ALLOWED:`Field not allowed to be set`,ASYNC_VALIDATION_NOT_SUPPORTED:`Async validation is not supported`,VALIDATION_ERROR:`Validation Error`,MISSING_FIELD:`Field is required`,METHOD_NOT_ALLOWED_DEFER_SESSION_REQUIRED:`POST method requires deferSessionRefresh to be enabled in session config`,BODY_MUST_BE_AN_OBJECT:`Body must be an object`,PASSWORD_ALREADY_SET:`User already has a password set`});function Sx(){let e=Object.getOwnPropertyDescriptor(Error,`stackTraceLimit`);return e===void 0?Object.isExtensible(Error):Object.prototype.hasOwnProperty.call(e,`writable`)?e.writable:e.set!==void 0}function Cx(e){let t=e.split(` 62 at `);return t.length<=1?e:(t.splice(1,1),t.join(` 63 at `))}function wx(e,t){class n extends e{#e;constructor(...e){if(Sx()){let t=Error.stackTraceLimit;Error.stackTraceLimit=0,super(...e),Error.stackTraceLimit=t}else super(...e);let t=Error().stack;t&&(this.#e=Cx(t.replace(/^Error/,this.name)))}get errorStack(){return this.#e}}return Object.defineProperty(n.prototype,`constructor`,{get(){return t},enumerable:!1,configurable:!0}),n}var Tx={OK:200,CREATED:201,ACCEPTED:202,NO_CONTENT:204,MULTIPLE_CHOICES:300,MOVED_PERMANENTLY:301,FOUND:302,SEE_OTHER:303,NOT_MODIFIED:304,TEMPORARY_REDIRECT:307,BAD_REQUEST:400,UNAUTHORIZED:401,PAYMENT_REQUIRED:402,FORBIDDEN:403,NOT_FOUND:404,METHOD_NOT_ALLOWED:405,NOT_ACCEPTABLE:406,PROXY_AUTHENTICATION_REQUIRED:407,REQUEST_TIMEOUT:408,CONFLICT:409,GONE:410,LENGTH_REQUIRED:411,PRECONDITION_FAILED:412,PAYLOAD_TOO_LARGE:413,URI_TOO_LONG:414,UNSUPPORTED_MEDIA_TYPE:415,RANGE_NOT_SATISFIABLE:416,EXPECTATION_FAILED:417,"I'M_A_TEAPOT":418,MISDIRECTED_REQUEST:421,UNPROCESSABLE_ENTITY:422,LOCKED:423,FAILED_DEPENDENCY:424,TOO_EARLY:425,UPGRADE_REQUIRED:426,PRECONDITION_REQUIRED:428,TOO_MANY_REQUESTS:429,REQUEST_HEADER_FIELDS_TOO_LARGE:431,UNAVAILABLE_FOR_LEGAL_REASONS:451,INTERNAL_SERVER_ERROR:500,NOT_IMPLEMENTED:501,BAD_GATEWAY:502,SERVICE_UNAVAILABLE:503,GATEWAY_TIMEOUT:504,HTTP_VERSION_NOT_SUPPORTED:505,VARIANT_ALSO_NEGOTIATES:506,INSUFFICIENT_STORAGE:507,LOOP_DETECTED:508,NOT_EXTENDED:510,NETWORK_AUTHENTICATION_REQUIRED:511};wx(class extends Error{constructor(e=`INTERNAL_SERVER_ERROR`,t=void 0,n={},r=typeof e==`number`?e:Tx[e]){super(t?.message,t?.cause?{cause:t.cause}:void 0),this.status=e,this.body=t,this.headers=n,this.statusCode=r,this.name=`APIError`,this.status=e,this.headers=n,this.statusCode=r,this.body=t}},Error);var Ex=class extends Error{constructor(e,t){super(e,t),this.name=`BetterAuthError`,this.message=e,this.stack=``}};function Dx(e){try{return(new URL(e).pathname.replace(/\/+$/,``)||`/`)!==`/`}catch{throw new Ex(`Invalid base URL: ${e}. Please provide a valid base URL.`)}}function Ox(e){try{let t=new URL(e);if(t.protocol!==`http:`&&t.protocol!==`https:`)throw new Ex(`Invalid base URL: ${e}. URL must include 'http://' or 'https://'`)}catch(t){throw t instanceof Ex?t:new Ex(`Invalid base URL: ${e}. Please provide a valid base URL.`,{cause:t})}}function kx(e,t=`/api/auth`){if(Ox(e),Dx(e))return e;let n=e.replace(/\/+$/,``);return!t||t===`/`?n:(t=t.startsWith(`/`)?t:`/${t}`,`${n}${t}`)}function Ax(e,t){return!e||e.trim()===``?!1:t===`proto`?e===`http`||e===`https`:t===`host`?[/\.\./,/\0/,/[\s]/,/^[.]/,/[<>'"]/,/javascript:/i,/file:/i,/data:/i].some(t=>t.test(e))?!1:/^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*(:[0-9]{1,5})?$/.test(e)||/^(\d{1,3}\.){3}\d{1,3}(:[0-9]{1,5})?$/.test(e)||/^\[[0-9a-fA-F:]+\](:[0-9]{1,5})?$/.test(e)||/^localhost(:[0-9]{1,5})?$/i.test(e):!1}function jx(e,t,n,r,i){if(e)return kx(e,t);if(r!==!1){let e=ox.BETTER_AUTH_URL||ox.NEXT_PUBLIC_BETTER_AUTH_URL||ox.PUBLIC_BETTER_AUTH_URL||ox.NUXT_PUBLIC_BETTER_AUTH_URL||ox.NUXT_PUBLIC_AUTH_URL||(ox.BASE_URL===`/`?void 0:ox.BASE_URL);if(e)return kx(e,t)}let a=n?.headers.get(`x-forwarded-host`),o=n?.headers.get(`x-forwarded-proto`);if(a&&o&&i&&Ax(o,`proto`)&&Ax(a,`host`))try{return kx(`${o}://${a}`,t)}catch{}if(n){let e=Mx(n.url);if(!e)throw new Ex(`Could not get origin from request. Please provide a valid base URL.`);return kx(e,t)}if(typeof window<`u`&&window.location)return kx(window.location.origin,t)}function Mx(e){try{let t=new URL(e);return t.origin===`null`?null:t.origin}catch{return null}}var Nx={proto:/"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/,constructor:/"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/,protoShort:/"__proto__"\s*:/,constructorShort:/"constructor"\s*:/},Px=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/,Fx={true:!0,false:!1,null:null,undefined:void 0,nan:NaN,infinity:1/0,"-infinity":-1/0},Ix=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,7}))?(?:Z|([+-])(\d{2}):(\d{2}))$/;function Lx(e){return e instanceof Date&&!isNaN(e.getTime())}function Rx(e){let t=Ix.exec(e);if(!t)return null;let[,n,r,i,a,o,s,c,l,u,d]=t,f=new Date(Date.UTC(parseInt(n,10),parseInt(r,10)-1,parseInt(i,10),parseInt(a,10),parseInt(o,10),parseInt(s,10),c?parseInt(c.padEnd(3,`0`),10):0));if(l){let e=(parseInt(u,10)*60+parseInt(d,10))*(l===`+`?-1:1);f.setUTCMinutes(f.getUTCMinutes()+e)}return Lx(f)?f:null}function zx(e,t={}){let{strict:n=!1,warnings:r=!1,reviver:i,parseDates:a=!0}=t;if(typeof e!=`string`)return e;let o=e.trim();if(o.length>0&&o[0]===`"`&&o.endsWith(`"`)&&!o.slice(1,-1).includes(`"`))return o.slice(1,-1);let s=o.toLowerCase();if(s.length<=9&&s in Fx)return Fx[s];if(!Px.test(o)){if(n)throw SyntaxError(`[better-json] Invalid JSON`);return e}if(Object.entries(Nx).some(([e,t])=>{let n=t.test(o);return n&&r&&console.warn(`[better-json] Detected potential prototype pollution attempt using ${e} pattern`),n})&&n)throw Error(`[better-json] Potential prototype pollution attempt detected`);try{return JSON.parse(o,(e,t)=>{if(e===`__proto__`||e===`constructor`&&t&&typeof t==`object`&&`prototype`in t){r&&console.warn(`[better-json] Dropping "${e}" key to prevent prototype pollution`);return}if(a&&typeof t==`string`){let e=Rx(t);if(e)return e}return i?i(e,t):t})}catch(t){if(n)throw t;return e}}function Bx(e,t={strict:!0}){return zx(e,t)}var Vx={id:`redirect`,name:`Redirect`,hooks:{onSuccess(e){if(e.data?.url&&e.data?.redirect&&typeof window<`u`&&window.location&&window.location)try{window.location.href=e.data.url}catch{}}}},Hx=[],Ux=0,Wx=4,Gx=0,Kx=e=>{let t=[],n={get(){return n.lc||n.listen(()=>{})(),n.value},init:e,lc:0,listen(e){return n.lc=t.push(e),()=>{for(let t=Ux+Wx;t<Hx.length;)Hx[t]===e?Hx.splice(t,Wx):t+=Wx;let r=t.indexOf(e);~r&&(t.splice(r,1),--n.lc||n.off())}},notify(e,r){Gx++;let i=!Hx.length;for(let i of t)Hx.push(i,n.value,e,r);
63if(i){for(Ux=0;Ux<Hx.length;Ux+=Wx)Hx[Ux](Hx[Ux+1],Hx[Ux+2],Hx[Ux+3]);Hx.length=0}},off(){},set(e){let t=n.value;t!==e&&(n.value=e,n.notify(t))},subscribe(e){let t=n.listen(e);return e(n.value),t},value:e};return n},qx=5,Jx=6,Yx=10,Xx=(e,t,n,r)=>(e.events=e.events||{},e.events[n+Yx]||(e.events[n+Yx]=r(t=>{e.events[n].reduceRight((e,t)=>(t(e),e),{shared:{},...t})})),e.events[n]=e.events[n]||[],e.events[n].push(t),()=>{let r=e.events[n],i=r.indexOf(t);r.splice(i,1),r.length||(delete e.events[n],e.events[n+Yx](),delete e.events[n+Yx])}),Zx=1e3,Qx=(e,t)=>Xx(e,n=>{let r=t(n);r&&e.events[Jx].push(r)},qx,t=>{let n=e.listen;e.listen=(...r)=>(!e.lc&&!e.active&&(e.active=!0,t()),n(...r));let r=e.off;return e.events[Jx]=[],e.off=()=>{r(),setTimeout(()=>{if(e.active&&!e.lc){e.active=!1;for(let t of e.events[Jx])t();e.events[Jx]=[]}},Zx)},()=>{e.listen=n,e.off=r}});function $x(e,t,n){let r=new Set(t).add(void 0);return e.listen((e,t,i)=>{r.has(i)&&n(e,t,i)})}var eS=()=>typeof window>`u`,tS=(e,t,n,r)=>{let i=Kx({data:null,error:null,isPending:!0,isRefetching:!1,refetch:e=>a(e)}),a=async e=>new Promise(a=>{let o=typeof r==`function`?r({data:i.get().data,error:i.get().error,isPending:i.get().isPending}):r;n(t,{...o,query:{...o?.query,...e?.query},async onSuccess(e){i.set({data:e.data,error:null,isPending:!1,isRefetching:!1,refetch:i.value.refetch}),await o?.onSuccess?.(e)},async onError(e){let{request:t}=e,n=typeof t.retry==`number`?t.retry:t.retry?.attempts,r=t.retryAttempt||0;if(n&&r<n)return;let a=e.error.status===401;i.set({error:e.error,data:a?null:i.get().data,isPending:!1,isRefetching:!1,refetch:i.value.refetch}),await o?.onError?.(e)},async onRequest(e){let t=i.get();i.set({isPending:t.data===null,data:t.data,error:null,isRefetching:!0,refetch:i.value.refetch}),await o?.onRequest?.(e)}}).catch(e=>{i.set({error:e,data:i.get().data,isPending:!1,isRefetching:!1,refetch:i.value.refetch})}).finally(()=>{a(void 0)})});e=Array.isArray(e)?e:[e];let o=!1;for(let t of e)t.subscribe(async()=>{eS()||(o?await a():Qx(i,()=>{let e=setTimeout(async()=>{o||=(await a(),!0)},0);return()=>{i.off(),t.off(),clearTimeout(e)}}))});return i},nS=Symbol.for(`better-auth:broadcast-channel`),rS=()=>Math.floor(Date.now()/1e3),iS=class{listeners=new Set;name;constructor(e=`better-auth.message`){this.name=e}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}post(e){if(!(typeof window>`u`))try{localStorage.setItem(this.name,JSON.stringify({...e,timestamp:rS()}))}catch{}}setup(){if(typeof window>`u`||window.addEventListener===void 0)return()=>{};let e=e=>{if(e.key!==this.name)return;let t=JSON.parse(e.newValue??`{}`);t?.event!==`session`||!t?.data||this.listeners.forEach(e=>e(t))};return window.addEventListener(`storage`,e),()=>{window.removeEventListener(`storage`,e)}}};function aS(e=`better-auth.message`){return globalThis[nS]||(globalThis[nS]=new iS(e)),globalThis[nS]}var oS=Symbol.for(`better-auth:focus-manager`),sS=class{listeners=new Set;subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}setFocused(e){this.listeners.forEach(t=>t(e))}setup(){if(typeof window>`u`||typeof document>`u`||window.addEventListener===void 0)return()=>{};let e=()=>{document.visibilityState===`visible`&&this.setFocused(!0)};return document.addEventListener(`visibilitychange`,e,!1),()=>{document.removeEventListener(`visibilitychange`,e,!1)}}};function cS(){return globalThis[oS]||(globalThis[oS]=new sS),globalThis[oS]}var lS=Symbol.for(`better-auth:online-manager`),uS=class{listeners=new Set;isOnline=typeof navigator<`u`?navigator.onLine:!0;subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}setOnline(e){this.isOnline=e,this.listeners.forEach(t=>t(e))}setup(){if(typeof window>`u`||window.addEventListener===void 0)return()=>{};let e=()=>this.setOnline(!0),t=()=>this.setOnline(!1);return window.addEventListener(`online`,e,!1),window.addEventListener(`offline`,t,!1),()=>{window.removeEventListener(`online`,e,!1),window.removeEventListener(`offline`,t,!1)}}};function dS(){return globalThis[lS]||(globalThis[lS]=new uS),globalThis[lS]}var fS=()=>Math.floor(Date.now()/1e3),pS=5;function mS(e){let{sessionAtom:t,sessionSignal:n,$fetch:r,options:i={}}=e,a=i.sessionOptions?.refetchInterval??0,o=i.sessionOptions?.refetchOnWindowFocus??!0,s=i.sessionOptions?.refetchWhenOffline??!1,c={lastSync:0,lastSessionRequest:0,cachedSession:void 0},l=()=>s||dS().isOnline,u=e=>{if(!l())return;if(e?.event===`storage`){c.lastSync=fS(),n.set(!n.get());return}let i=t.get(),a=()=>{c.lastSessionRequest=fS(),r(`/get-session`).then(async e=>{let a=e.data,o=e.error||null;if(a?.needsRefresh)try{let e=await r(`/get-session`,{method:`POST`});a=e.data,o=e.error||null}catch{}let s=a?.session&&a?.user?a:null;t.set({...i,data:s,error:o}),c.lastSync=fS(),n.set(!n.get())}).catch(()=>{})};if(e?.event===`poll`){a();return}if(e?.event===`visibilitychange`){if(fS()-c.lastSessionRequest<pS)return;c.lastSessionRequest=fS()}if(e?.event===`visibilitychange`){a();return}(i?.data===null||i?.data===void 0)&&(c.lastSync=fS(),n.set(!n.get()))},d=e=>{aS().post({event:`session`,data:{trigger:e},clientId:Math.random().toString(36).substring(7)})},f=()=>{a&&a>0&&(c.pollInterval=setInterval(()=>{t.get()?.data&&u({event:`poll`})},a*1e3))},p=()=>{c.unsubscribeBroadcast=aS().subscribe(()=>{u({event:`storage`})})},m=()=>{o&&(c.unsubscribeFocus=cS().subscribe(()=>{u({event:`visibilitychange`})}))},h=()=>{c.unsubscribeOnline=dS().subscribe(e=>{e&&u({event:`visibilitychange`})})};return{init:()=>{f(),p(),m(),h(),aS().setup(),cS().setup(),dS().setup()},cleanup:()=>{c.pollInterval&&=(clearInterval(c.pollInterval),void 0),c.unsubscribeBroadcast&&=(c.unsubscribeBroadcast(),void 0),c.unsubscribeFocus&&=(c.unsubscribeFocus(),void 0),c.unsubscribeOnline&&=(c.unsubscribeOnline(),void 0),c.lastSync=0,c.lastSessionRequest=0,c.cachedSession=void 0},triggerRefetch:u,broadcastSessionUpdate:d}}function hS(e,t){let n=Kx(!1),r=tS(n,`/get-session`,e,{method:`GET`}),i=()=>{};return Qx(r,()=>{let a=mS({sessionAtom:r,sessionSignal:n,$fetch:e,options:t});return a.init(),i=a.broadcastSessionUpdate,()=>{a.cleanup()}}),{session:r,$sessionSignal:n,broadcastSessionUpdate:e=>i(e)}}function gS(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t!==null&&t!==Object.prototype&&Object.getPrototypeOf(t)!==null||Symbol.iterator in e?!1:Symbol.toStringTag in e?Object.prototype.toString.call(e)===`[object Module]`:!0}function _S(e,t,n=`.`,r){if(!gS(t))return _S(e,{},n,r);let i=Object.assign({},t);for(let t in e){if(t===`__proto__`||t===`constructor`)continue;let a=e[t];a!=null&&(r&&r(i,t,a,n)||(Array.isArray(a)&&Array.isArray(i[t])?i[t]=[...a,...i[t]]:gS(a)&&gS(i[t])?i[t]=_S(a,i[t],(n?`${n}.`:``)+t.toString(),r):i[t]=a))}return i}function vS(e){return(...t)=>t.reduce((t,n)=>_S(t,n,``,e),{})}var yS=vS(),bS=Object.defineProperty,xS=Object.defineProperties,SS=Object.getOwnPropertyDescriptors,CS=Object.getOwnPropertySymbols,wS=Object.prototype.hasOwnProperty,TS=Object.prototype.propertyIsEnumerable,ES=(e,t,n)=>t in e?bS(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,DS=(e,t)=>{for(var n in t||={})wS.call(t,n)&&ES(e,n,t[n]);if(CS)for(var n of CS(t))TS.call(t,n)&&ES(e,n,t[n]);return e},OS=(e,t)=>
63xS(e,SS(t)),kS=class extends Error{constructor(e,t,n){super(t||e.toString(),{cause:n}),this.status=e,this.statusText=t,this.error=n,Error.captureStackTrace(this,this.constructor)}},AS=async(e,t)=>{let n=t||{},r={onRequest:[t?.onRequest],onResponse:[t?.onResponse],onSuccess:[t?.onSuccess],onError:[t?.onError],onRetry:[t?.onRetry]};if(!t||!t?.plugins)return{url:e,options:n,hooks:r};for(let i of t?.plugins||[]){if(i.init){let r=await i.init?.call(i,e.toString(),t);n=r.options||n,e=r.url}r.onRequest.push(i.hooks?.onRequest),r.onResponse.push(i.hooks?.onResponse),r.onSuccess.push(i.hooks?.onSuccess),r.onError.push(i.hooks?.onError),r.onRetry.push(i.hooks?.onRetry)}return{url:e,options:n,hooks:r}},jS=class{constructor(e){this.options=e}shouldAttemptRetry(e,t){return this.options.shouldRetry?Promise.resolve(e<this.options.attempts&&this.options.shouldRetry(t)):Promise.resolve(e<this.options.attempts)}getDelay(){return this.options.delay}},MS=class{constructor(e){this.options=e}shouldAttemptRetry(e,t){return this.options.shouldRetry?Promise.resolve(e<this.options.attempts&&this.options.shouldRetry(t)):Promise.resolve(e<this.options.attempts)}getDelay(e){return Math.min(this.options.maxDelay,this.options.baseDelay*2**e)}};function NS(e){if(typeof e==`number`)return new jS({type:`linear`,attempts:e,delay:1e3});switch(e.type){case`linear`:return new jS(e);case`exponential`:return new MS(e);default:throw Error(`Invalid retry strategy`)}}var PS=async e=>{let t={},n=async e=>typeof e==`function`?await e():e;if(e?.auth){if(e.auth.type===`Bearer`){let r=await n(e.auth.token);if(!r)return t;t.authorization=`Bearer ${r}`}else if(e.auth.type===`Basic`){let[r,i]=await Promise.all([n(e.auth.username),n(e.auth.password)]);if(!r||!i)return t;t.authorization=`Basic ${btoa(`${r}:${i}`)}`}else if(e.auth.type===`Custom`){let[r,i]=await Promise.all([n(e.auth.prefix),n(e.auth.value)]);if(!i)return t;t.authorization=`${r??``} ${i}`}}return t},FS=/^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;function IS(e){let t=e.headers.get(`content-type`),n=new Set([`image/svg`,`application/xml`,`application/xhtml`,`application/html`]);if(!t)return`json`;let r=t.split(`;`).shift()||``;return FS.test(r)?`json`:n.has(r)||r.startsWith(`text/`)?`text`:`blob`}function LS(e){try{return JSON.parse(e),!0}catch{return!1}}function RS(e){if(e===void 0)return!1;let t=typeof e;return t===`string`||t===`number`||t===`boolean`||t===null?!0:t===`object`?Array.isArray(e)?!0:e.buffer?!1:e.constructor&&e.constructor.name===`Object`||typeof e.toJSON==`function`:!1}function zS(e){try{return JSON.parse(e)}catch{return e}}function BS(e){return typeof e==`function`}function VS(e){if(e?.customFetchImpl)return e.customFetchImpl;if(typeof globalThis<`u`&&BS(globalThis.fetch))return globalThis.fetch;if(typeof window<`u`&&BS(window.fetch))return window.fetch;throw Error(`No fetch implementation found`)}async function HS(e){let t=new Headers(e?.headers),n=await PS(e);for(let[e,r]of Object.entries(n||{}))t.set(e,r);if(!t.has(`content-type`)){let n=US(e?.body);n&&t.set(`content-type`,n)}return t}function US(e){return RS(e)?`application/json`:null}function WS(e){if(!e?.body)return null;let t=new Headers(e?.headers);if(RS(e.body)&&!t.has(`content-type`)){for(let[t,n]of Object.entries(e?.body))n instanceof Date&&(e.body[t]=n.toISOString());return JSON.stringify(e.body)}return t.has(`content-type`)&&t.get(`content-type`)===`application/x-www-form-urlencoded`&&RS(e.body)?new URLSearchParams(e.body).toString():e.body}function GS(e,t){if(t?.method)return t.method.toUpperCase();if(e.startsWith(`@`)){let n=e.split(`@`)[1]?.split(`/`)[0];return YS.includes(n)?n.toUpperCase():t?.body?`POST`:`GET`}return t?.body?`POST`:`GET`}function KS(e,t){let n;return!e?.signal&&e?.timeout&&(n=setTimeout(()=>t?.abort(),e?.timeout)),{abortTimeout:n,clearTimeout:()=>{n&&clearTimeout(n)}}}var qS=class e extends Error{constructor(t,n){super(n||JSON.stringify(t,null,2)),this.issues=t,Object.setPrototypeOf(this,e.prototype)}};async function JS(e,t){let n=await e[`~standard`].validate(t);if(n.issues)throw new qS(n.issues);return n.value}var YS=[`get`,`post`,`put`,`patch`,`delete`],XS=e=>({id:`apply-schema`,name:`Apply Schema`,version:`1.0.0`,async init(t,n){let r=e.plugins?.find(e=>
63e.schema?.config?t.startsWith(e.schema.config.baseURL||``)||t.startsWith(e.schema.config.prefix||``):!1)?.schema||e.schema;if(r){let e=t;r.config?.prefix&&e.startsWith(r.config.prefix)&&(e=e.replace(r.config.prefix,``),r.config.baseURL&&(t=t.replace(r.config.prefix,r.config.baseURL))),r.config?.baseURL&&e.startsWith(r.config.baseURL)&&(e=e.replace(r.config.baseURL,``));let i=r.schema[e];if(i){let e=OS(DS({},n),{method:i.method,output:i.output});return n?.disableValidation||(e=OS(DS({},e),{body:i.input?await JS(i.input,n?.body):n?.body,params:i.params?await JS(i.params,n?.params):n?.params,query:i.query?await JS(i.query,n?.query):n?.query})),{url:t,options:e}}}return{url:t,options:n}}}),ZS=e=>{async function t(t,n){let r=OS(DS(DS({},e),n),{plugins:[...e?.plugins||[],XS(e||{}),...n?.plugins||[]]});if(e?.catchAllError)try{return await $S(t,r)}catch(e){return{data:null,error:{status:500,statusText:`Fetch Error`,message:`Fetch related error. Captured by catchAllError option. See error property for more details.`,error:e}}}return await $S(t,r)}return t};function QS(e,t){let{baseURL:n,params:r,query:i}=t||{query:{},params:{},baseURL:``},a=e.startsWith(`http`)?e.split(`/`).slice(0,3).join(`/`):n||``;if(e.startsWith(`@`)){let t=e.toString().split(`@`)[1].split(`/`)[0];YS.includes(t)&&(e=e.replace(`@${t}/`,`/`))}a.endsWith(`/`)||(a+=`/`);let[o,s]=e.replace(a,``).split(`?`),c=new URLSearchParams(s);for(let[e,t]of Object.entries(i||{})){if(t==null)continue;let n;if(typeof t==`string`)n=t;else if(Array.isArray(t)){for(let n of t)c.append(e,n);continue}else n=JSON.stringify(t);c.set(e,n)}if(r)if(Array.isArray(r)){let e=o.split(`/`).filter(e=>e.startsWith(`:`));for(let[t,n]of e.entries()){let e=r[t];o=o.replace(n,e)}}else for(let[e,t]of Object.entries(r))o=o.replace(`:${e}`,String(t));o=o.split(`/`).map(encodeURIComponent).join(`/`),o.startsWith(`/`)&&(o=o.slice(1));let l=c.toString();return l=l.length>0?`?${l}`.replace(/\+/g,`%20`):``,a.startsWith(`http`)?new URL(`${o}${l}`,a):`${a}${o}${l}`}var $S=async(e,t)=>{let{hooks:n,url:r,options:i}=await AS(e,t),a=VS(i),o=new AbortController,s=i.signal??o.signal,c=QS(r,i),l=WS(i),u=await HS(i),d=GS(r,i),f=OS(DS({},i),{url:c,headers:u,body:l,method:d,signal:s});for(let e of n.onRequest)if(e){let t=await e(f);typeof t==`object`&&t&&(f=t)}(`pipeTo`in f&&typeof f.pipeTo==`function`||typeof t?.body?.pipe==`function`)&&(`duplex`in f||(f.duplex=`half`));let{clearTimeout:p}=KS(i,o),m=await a(f.url,f);p();let h={response:m,request:f};for(let e of n.onResponse)if(e){let n=await e(OS(DS({},h),{response:t?.hookOptions?.cloneResponse?m.clone():m}));n instanceof Response?m=n:typeof n==`object`&&n&&(m=n.response)}if(m.ok){if(f.method===`HEAD`)return{data:``,error:null};let e=IS(m),r={data:null,response:m,request:f};if(e===`json`||e===`text`){let e=await m.text();r.data=await(f.jsonParser??zS)(e)}else r.data=await m[e]();f?.output&&f.output&&!f.disableValidation&&(r.data=await JS(f.output,r.data));for(let e of n.onSuccess)e&&await e(OS(DS({},r),{response:t?.hookOptions?.cloneResponse?m.clone():m}));return t?.throw?r.data:{data:r.data,error:null}}let g=t?.jsonParser??zS,_=await m.text(),v=LS(_),y=v?await g(_):null,b={response:m,responseText:_,request:f,error:OS(DS({},y),{status:m.status,statusText:m.statusText})};for(let e of n.onError)e&&await e(OS(DS({},b),{response:t?.hookOptions?.cloneResponse?m.clone():m}));if(t?.retry){let r=NS(t.retry),i=t.retryAttempt??0;if(await r.shouldAttemptRetry(i,m)){for(let e of n.onRetry)e&&await e(h);let a=r.getDelay(i);return await new Promise(e=>setTimeout(e,a)),await $S(e,OS(DS({},t),{retryAttempt:i+1}))}}if(t?.throw)throw new kS(m.status,m.statusText,v?y:_);return{data:null,error:OS(DS({},y),{status:m.status,statusText:m.statusText})}},eC=e=>{if(typeof process>`u`)return;let t=e??`/api/auth`;if({}.NEXT_PUBLIC_AUTH_URL)return{}.NEXT_PUBLIC_AUTH_URL;if(typeof window>`u`){if({}.NEXTAUTH_URL)try{return{}.NEXTAUTH_URL}catch{}if({}.VERCEL_URL)try{let e={}.VERCEL_URL.startsWith(`http`)?``:`https://`;return`${new URL(`${e}${{}.VERCEL_URL}`).origin}${t}`}catch{}}},tC=(e,t)=>{let n=`credentials`in Request.prototype,r=jx(e?.baseURL,e?.basePath,void 0,t)??eC(e?.basePath)??`/api/auth`,i=e?.plugins?.flatMap(e=>e.fetchPlugins).filter(e=>e!==void 0)||[],a={id:`lifecycle-hooks`,name:`lifecycle-hooks`,hooks:{onSuccess:e?.fetchOptions?.onSuccess,onError:e?.fetchOptions?.onError,onRequest:e?.fetchOptions?.onRequest,onResponse:e?.fetchOptions?.onResponse}},{onSuccess:o,onError:s,onRequest:c,onResponse:l,...u}=e?.fetchOptions||{},d=ZS({baseURL:r,...n?{credentials:`include`}:{},method:`GET`,jsonParser(e){return e?Bx(e,{strict:!1}):null},customFetchImpl:fetch,...u,plugins:[a,...u.plugins||[],...e?.disableDefaultFetchPlugins?[]:[Vx],...i]}),{$sessionSignal:f,session:p,broadcastSessionUpdate:m}=hS(d,e),h=e?.plugins||[],g={},_={$sessionSignal:f,session:p}
63,v={"/sign-out":`POST`,"/revoke-sessions":`POST`,"/revoke-other-sessions":`POST`,"/delete-user":`POST`},y=[{signal:`$sessionSignal`,matcher(e){return e===`/sign-out`||e===`/update-user`||e===`/update-session`||e===`/sign-up/email`||e===`/sign-in/email`||e===`/delete-user`||e===`/verify-email`||e===`/revoke-sessions`||e===`/revoke-session`||e===`/change-email`},callback(e){e===`/sign-out`?m(`signout`):(e===`/update-user`||e===`/update-session`)&&m(`updateUser`)}}];for(let e of h)e.getAtoms&&Object.assign(_,e.getAtoms?.(d)),e.pathMethods&&Object.assign(v,e.pathMethods),e.atomListeners&&y.push(...e.atomListeners);let b={notify:e=>{_[e].set(!_[e].get())},listen:(e,t)=>{_[e].subscribe(t)},atoms:_};for(let t of h)t.getActions&&(g=yS(t.getActions?.(d,b,e)??{},g));return{get baseURL(){return r},pluginsActions:g,pluginsAtoms:_,pluginPathMethods:v,atomListeners:y,$fetch:d,$store:b}};function nC(e){return typeof e==`object`&&!!e&&`get`in e&&typeof e.get==`function`&&`lc`in e&&typeof e.lc==`number`}function rC(e,t,n){let r=t[e],{fetchOptions:i,query:a,...o}=n||{};return r||(i?.method?i.method:o&&Object.keys(o).length>0?`POST`:`GET`)}function iC(e,t,n,r,i){function a(o=[]){return new Proxy(function(){},{get(t,n){if(typeof n!=`string`||n===`then`||n===`catch`||n===`finally`)return;let r=[...o,n],i=e;for(let e of r)if(i&&typeof i==`object`&&e in i)i=i[e];else{i=void 0;break}return typeof i==`function`||nC(i)?i:a(r)},apply:async(e,a,s)=>{let c=`/`+o.map(e=>e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)).join(`/`),l=s[0]||{},u=s[1]||{},{query:d,fetchOptions:f,...p}=l,m={...u,...f},h=rC(c,n,l);return await t(c,{...m,body:h===`GET`?void 0:{...p,...m?.body||{}},query:d||m?.query,method:h,async onSuccess(e){if(await m?.onSuccess?.(e),!i||m.disableSignal)return;let t=i.filter(e=>e.matcher(c));if(!t.length)return;let n=new Set;for(let e of t){let t=r[e.signal];if(!t)return;if(n.has(e.signal))continue;n.add(e.signal);let i=t.get();setTimeout(()=>{t.set(!i)},10),e.callback?.(c)}}})}})}return a()}function aC(e,t={}){let n=(0,_.useRef)(e.get()),{keys:r,deps:i=[e,r]}=t,a=(0,_.useCallback)(t=>{let i=e=>{n.current!==e&&(n.current=e,t())};return i(e.value),r?.length?$x(e,r,i):e.listen(i)},i),o=()=>n.current;return(0,_.useSyncExternalStore)(a,o,o)}function oC(e){return e.charAt(0).toUpperCase()+e.slice(1)}function sC(e){return`use${oC(e)}`}function cC(e){let{pluginPathMethods:t,pluginsActions:n,pluginsAtoms:r,$fetch:i,$store:a,atomListeners:o}=tC(e),s={};for(let[e,t]of Object.entries(r))s[sC(e)]=()=>aC(t);return iC({...n,...s,$fetch:i,$store:a},i,t,r,o)}var lC=class extends Error{status;body;constructor(e,t,n){super(e),this.name=`ApiError`,this.status=t,this.body=n}};async function H(e,t){let n=await fetch(`${e}`,{...t,credentials:`include`,headers:{"Content-Type":`application/json`,...t?.headers}});if(n.status===401)throw window.location.href=`/login`,Error(`Session expired`);if(!n.ok){let e=await n.json().catch(()=>({})),t=e.error??`Request failed: ${n.status}`;throw new lC(typeof t==`string`?t:`Request failed: ${n.status}`,n.status,e)}return n.json()}var uC=cC({baseURL:``});function dC({children:e}){let{data:t,isPending:n}=uC.useSession();return n?(0,L.jsx)(`div`,{className:`flex min-h-screen items-center justify-center`,children:(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading...`})}):t?(0,L.jsx)(L.Fragment,{children:e}):(0,L.jsx)(Dt,{to:`/login`,replace:!0})}var fC=(...e)=>e.filter((e,t,n)=>!!e&&e.trim()!==``&&n.indexOf(e)===t).join(` `).trim(),pC=e=>e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase(),mC=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,t,n)=>n?n.toUpperCase():t.toLowerCase()),hC=e=>{let t=mC(e);return t.charAt(0).toUpperCase()+t.slice(1)},gC={xmlns:`http://www.w3.org/2000/svg`,width:24,height:24,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`},_C=e=>{for(let t in e)if(t.startsWith(`aria-`)||t===`role`||t===`title`)return!0;return!1},vC=(0,_.forwardRef)(({color:e=`currentColor`,size:t=24,strokeWidth:n=2,absoluteStrokeWidth:r,className:i=``,children:a,iconNode:o,...s},c)=>(0,_.createElement)(`svg`,{ref:c,...gC,width:t,height:t,stroke:e,strokeWidth:r?Number(n)*24/Number(t):n,className:fC(`lucide`,i),...!a&&!_C(s)&&{"aria-hidden":`true`},...s},[...o.map(([e,t])=>(0,_.createElement)(e,t)),...Array.isArray(a)?a:[a]])),U=(e,t)=>{let n=(0,_.forwardRef)(({className:n,...r},i)=>(0,_.createElement)(vC,{ref:i,iconNode:t,className:fC(`lucide-${pC(hC(e))}`,`lucide-${e}`,n),...r}));return n.displayName=hC(e),n},yC=U(`activity`,[[`path`,{d:`M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l
63-2.35 8.36A2 2 0 0 1 4.49 12H2`,key:`169zse`}]]),bC=U(`archive-restore`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h2`,key:`tvwodi`}],[`path`,{d:`M20 8v11a2 2 0 0 1-2 2h-2`,key:`1gkqxj`}],[`path`,{d:`m9 15 3-3 3 3`,key:`1pd0qc`}],[`path`,{d:`M12 12v9`,key:`192myk`}]]),xC=U(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),SC=U(`arrow-down`,[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]),CC=U(`arrow-left`,[[`path`,{d:`m12 19-7-7 7-7`,key:`1l729n`}],[`path`,{d:`M19 12H5`,key:`x3x0zl`}]]),wC=U(`arrow-right-left`,[[`path`,{d:`m16 3 4 4-4 4`,key:`1x1c3m`}],[`path`,{d:`M20 7H4`,key:`zbl0bi`}],[`path`,{d:`m8 21-4-4 4-4`,key:`h9nckh`}],[`path`,{d:`M4 17h16`,key:`g4d7ey`}]]),TC=U(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),EC=U(`arrow-up-down`,[[`path`,{d:`m21 16-4 4-4-4`,key:`f6ql7i`}],[`path`,{d:`M17 20V4`,key:`1ejh1v`}],[`path`,{d:`m3 8 4-4 4 4`,key:`11wl7u`}],[`path`,{d:`M7 4v16`,key:`1glfcx`}]]),DC=U(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),OC=U(`bell`,[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326`,key:`11g9vi`}]]),kC=U(`book-open`,[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z`,key:`ruj8y`}]]),AC=U(`bookmark`,[[`path`,{d:`M17 3a2 2 0 0 1 2 2v15a1 1 0 0 1-1.496.868l-4.512-2.578a2 2 0 0 0-1.984 0l-4.512 2.578A1 1 0 0 1 5 20V5a2 2 0 0 1 2-2z`,key:`oz39mx`}]]),jC=U(`bot-off`,[[`path`,{d:`M13.67 8H18a2 2 0 0 1 2 2v4.33`,key:`7az073`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M22 22 2 2`,key:`1r8tn9`}],[`path`,{d:`M8 8H6a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h12a2 2 0 0 0 1.414-.586`,key:`s09a7a`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}],[`path`,{d:`M9.67 4H12v2.33`,key:`110xot`}]]),MC=U(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),NC=U(`brain`,[[`path`,{d:`M12 18V5`,key:`adv99a`}],[`path`,{d:`M15 13a4.17 4.17 0 0 1-3-4 4.17 4.17 0 0 1-3 4`,key:`1e3is1`}],[`path`,{d:`M17.598 6.5A3 3 0 1 0 12 5a3 3 0 1 0-5.598 1.5`,key:`1gqd8o`}],[`path`,{d:`M17.997 5.125a4 4 0 0 1 2.526 5.77`,key:`iwvgf7`}],[`path`,{d:`M18 18a4 4 0 0 0 2-7.464`,key:`efp6ie`}],[`path`,{d:`M19.967 17.483A4 4 0 1 1 12 18a4 4 0 1 1-7.967-.517`,key:`1gq6am`}],[`path`,{d:`M6 18a4 4 0 0 1-2-7.464`,key:`k1g0md`}],[`path`,{d:`M6.003 5.125a4 4 0 0 0-2.526 5.77`,key:`q97ue3`}]]),PC=U(`cable`,[[`path`,{d:`M17 19a1 1 0 0 1-1-1v-2a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v2a1 1 0 0 1-1 1z`,key:`trhst0`}],[`path`,{d:`M17 21v-2`,key:`ds4u3f`}],[`path`,{d:`M19 14V6.5a1 1 0 0 0-7 0v11a1 1 0 0 1-7 0V10`,key:`1mo9zo`}],[`path`,{d:`M21 21v-2`,key:`eo0ou`}],[`path`,{d:`M3 5V3`,key:`1k5hjh`}],[`path`,{d:`M4 10a2 2 0 0 1-2-2V6a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2a2 2 0 0 1-2 2z`,key:`1dd30t`}],[`path`,{d:`M7 5V3`,key:`1t1388`}]]),FC=U(`calendar-clock`,[[`path`,{d:`M16 14v2.2l1.6 1`,key:`fo4ql5`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5`,key:`1osxxc`}],[`path`,{d:`M3 10h5`,key:`r794hk`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]),IC=U(`calendar`,[[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`rect`,{width:`18`,height:`18`,x:`3`,y:`4`,rx:`2`,key:`1hopcy`}],[`path`,{d:`M3 10h18`,key:`8toen8`}]]),LC=U(`chart-column`,[[`path`,{d:`M3 3v16a2 2 0 0 0 2 2h16`,key:`c24i48`}],[`path`,{d:`M18 17V9`,key:`2bz60n`}],[`path`,{d:`M13 17V5`,key:`1frdt8`}
63],[`path`,{d:`M8 17v-3`,key:`17ska0`}]]),RC=U(`check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),zC=U(`chevron-down`,[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]),BC=U(`chevron-left`,[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]),VC=U(`chevron-right`,[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]),HC=U(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),UC=U(`chevrons-down-up`,[[`path`,{d:`m7 20 5-5 5 5`,key:`13a0gw`}],[`path`,{d:`m7 4 5 5 5-5`,key:`1kwcof`}]]),WC=U(`circle-alert`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`12`,x2:`12`,y1:`8`,y2:`12`,key:`1pkeuh`}],[`line`,{x1:`12`,x2:`12.01`,y1:`16`,y2:`16`,key:`4dfq90`}]]),GC=U(`circle-check-big`,[[`path`,{d:`M21.801 10A10 10 0 1 1 17 3.335`,key:`yps3ct`}],[`path`,{d:`m9 11 3 3L22 4`,key:`1pflzl`}]]),KC=U(`circle-check`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]),qC=U(`circle-pause`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`10`,x2:`10`,y1:`15`,y2:`9`,key:`c1nkhi`}],[`line`,{x1:`14`,x2:`14`,y1:`15`,y2:`9`,key:`h65svq`}]]),JC=U(`circle-play`,[[`path`,{d:`M9 9.003a1 1 0 0 1 1.517-.859l4.997 2.997a1 1 0 0 1 0 1.718l-4.997 2.997A1 1 0 0 1 9 14.996z`,key:`kmsa83`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),YC=U(`circle-question-mark`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),XC=U(`circle-x`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]]),ZC=U(`circle`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),QC=U(`clock`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6l4 2`,key:`mmk7yg`}]]),$C=U(`compass`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m16.24 7.76-1.804 5.411a2 2 0 0 1-1.265 1.265L7.76 16.24l1.804-5.411a2 2 0 0 1 1.265-1.265z`,key:`9ktpf1`}]]),ew=U(`copy`,[[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]),tw=U(`corner-down-right`,[[`path`,{d:`m15 10 5 5-5 5`,key:`qqa56n`}],[`path`,{d:`M4 4v7a4 4 0 0 0 4 4h12`,key:`z08zvw`}]]),nw=U(`corner-up-left`,[[`path`,{d:`M20 20v-7a4 4 0 0 0-4-4H4`,key:`1nkjon`}],[`path`,{d:`M9 14 4 9l5-5`,key:`102s5s`}]]),rw=U(`crown`,[[`path`,{d:`M11.562 3.266a.5.5 0 0 1 .876 0L15.39 8.87a1 1 0 0 0 1.516.294L21.183 5.5a.5.5 0 0 1 .798.519l-2.834 10.246a1 1 0 0 1-.956.734H5.81a1 1 0 0 1-.957-.734L2.02 6.02a.5.5 0 0 1 .798-.519l4.276 3.664a1 1 0 0 0 1.516-.294z`,key:`1vdc57`}],[`path`,{d:`M5 21h14`,key:`11awu3`}]]),iw=U(`download`,[[`path`,{d:`M12 15V3`,key:`m9g1x1`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`path`,{d:`m7 10 5 5 5-5`,key:`brsn70`}]]),aw=U(`ellipsis`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`19`,cy:`12`,r:`1`,key:`1wjl8i`}],[`circle`,{cx:`5`,cy:`12`,r:`1`,key:`1pcz8c`}]]),ow=U(`external-link`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]),sw=U(`eye`,[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`,key:`1nclc0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),cw=U(`fast-forward`,[[`path`,{d:`M12 6a2 2 0 0 1 3.414-1.414l6 6a2 2 0 0 1 0 2.828l-6 6A2 2 0 0 1 12 18z`,key:`b19h5q`}],[`path`,{d:`M2 6a2 2 0 0 1 3.414-1.414l6 6a2 2 0 0 1 0 2.828l-6 6A2 2 0 0 1 2 18z`,key:`h7h5ge`}]]),lw=U(`file-text`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),uw=U(`flag`,[[`path`,{d:`M4 22V4a1 1 0 0 1 .4-.8A6 6 0 0 1 8 2c3 0 5 2 7.333 2q2 0 3.067-.8A1 1 0 0 1 20 4v10a1 1 0 0 1-.4.8A6 6 0 0 1 16 16c-3 0-5-2-8-2a6 6 0 0 0-4 1.528`,key:`1jaruq`}]]),dw=U(`flame`,[[`path`,{d:`M12 3q1 4 4 6.5t3 5.5a1 1 0 0 1-14 0 5 5 0 0 1 1-3 1 1 0 0 0 5 0c0-2-1.5-3-1.5-5q0-2 2.5-4`,key:`1slcih`}]]),fw=U(`flask-conical`,[[`path`,{d:`M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2`,key:`18mbvz`}],[`path`,{d:`M6.453 15h11.094`,key:`3shlmq`}],[`path`,{d:`M8.5 2h7`,key:`csnxdl`}]]),pw=U(`forward`,[[`path`,{d:`m15 17 5-5-5-5`,key:`nf172w`}],[`path`,{d:`M4 18v-2a4 4 0 0 1 4-4h12`,key:`jmiej9`}]]),mw=U(`funnel`,[[`path`,{d:`M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z`,key:`sc7q7i`}]]),hw=U(`git-branch`,[[`path`,{d:`M15 6a9 9 0 0 0-9 9V3`,key:`1cii5b`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}]]),gw=U(`git-merge`,[[`circle`,{cx:`18`,cy:`18`,r:`3`,key:`1xkwt0`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}
63],[`path`,{d:`M6 21V9a9 9 0 0 0 9 9`,key:`7kw0sc`}]]),_w=U(`globe`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20`,key:`13o1zl`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}]]),vw=U(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),yw=U(`image`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]),bw=U(`inbox`,[[`polyline`,{points:`22 12 16 12 14 15 10 15 8 12 2 12`,key:`o97t9d`}],[`path`,{d:`M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z`,key:`oot6mr`}]]),xw=U(`info`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]),Sw=U(`layout-dashboard`,[[`rect`,{width:`7`,height:`9`,x:`3`,y:`3`,rx:`1`,key:`10lvy0`}],[`rect`,{width:`7`,height:`5`,x:`14`,y:`3`,rx:`1`,key:`16une8`}],[`rect`,{width:`7`,height:`9`,x:`14`,y:`12`,rx:`1`,key:`1hutg5`}],[`rect`,{width:`7`,height:`5`,x:`3`,y:`16`,rx:`1`,key:`ldoo1y`}]]),Cw=U(`link-2`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]),ww=U(`link`,[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]),Tw=U(`list-checks`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`path`,{d:`m3 7 2 2 4-4`,key:`1obspn`}]]),Ew=U(`loader-circle`,[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]]),Dw=U(`log-out`,[[`path`,{d:`m16 17 5-5-5-5`,key:`1bji2h`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`,key:`1uf3rs`}]]),Ow=U(`mail`,[[`path`,{d:`m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7`,key:`132q7q`}],[`rect`,{x:`2`,y:`4`,width:`20`,height:`16`,rx:`2`,key:`izxlao`}]]),kw=U(`map-pin`,[[`path`,{d:`M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0`,key:`1r0f0z`}],[`circle`,{cx:`12`,cy:`10`,r:`3`,key:`ilqhr7`}]]),Aw=U(`maximize-2`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`m21 3-7 7`,key:`1l2asr`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M9 21H3v-6`,key:`wtvkvv`}]]),jw=U(`message-circle`,[[`path`,{d:`M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719`,key:`1sd12s`}]]),Mw=U(`message-square-plus`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M12 8v6`,key:`1ib9pf`}],[`path`,{d:`M9 11h6`,key:`1fldmi`}]]),Nw=U(`message-square`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}]]),Pw=U(`mouse-pointer-click`,[[`path`,{d:`M14 4.1 12 6`,key:`ita8i4`}],[`path`,{d:`m5.1 8-2.9-.8`,key:`1go3kf`}],[`path`,{d:`m6 12-1.9 2`,key:`mnht97`}],[`path`,{d:`M7.2 2.2 8 5.1`,key:`1cfko1`}],[`path`,{d:`M9.037 9.69a.498.498 0 0 1 .653-.653l11 4.5a.5.5 0 0 1-.074.949l-4.349 1.041a1 1 0 0 0-.74.739l-1.04 4.35a.5.5 0 0 1-.95.074z`,key:`s0h3yz`}]]),Fw=U(`paintbrush`,[[`path`,{d:`m14.622 17.897-10.68-2.913`,key:`vj2p1u`}],[`path`,{d:`M18.376 2.622a1 1 0 1 1 3.002 3.002L17.36 9.643a.5.5 0 0 0 0 .707l.944.944a2.41 2.41 0 0 1 0 3.408l-.944.944a.5.5 0 0 1-.707 0L8.354 7.348a.5.5 0 0 1 0-.707l.944-.944a2.41 2.41 0 0 1 3.408 0l.944.944a.5.5 0 0 0 .707 0z`,key:`18tc5c`}],[`path`,{d:`M9 8c-1.804 2.71-3.97 3.46-6.583 3.948a.507.507 0 0 0-.302.819l7.32 8.883a1 1 0 0 0 1.185.204C12.735 20.405 16 16.792 16 15`,key:`ytzfxy`}]]),Iw=U(`palette`,[[`path`,{d:`M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z`,key:`e79jfc`}],[`circle`,{cx:`13.5`,cy:`6.5`,r:`.5`,fill:`currentColor`,key:`1okk4w`}],[`circle`,{cx:`17.5`,cy:`10.5`,r:`.5`,fill:`currentColor`,key:`f64h9f`}],[`circle`,{cx:`6.5`,cy:`12.5`,r:`.5`,fill:`currentColor`,key:`qy21gx`}],[`circle`,{cx:`8.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`fotxhn`}]]),Lw=U(`panel-left`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}]]),Rw=U(`panel-right`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]),zw=U(`paperclip`,[[`path`,{d:`m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551`,key:`1miecu`}]]),Bw=U(`pencil`,[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}]]),Vw=U(`phone`,[[`path`,{d:`M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2
630 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384`,key:`9njp5v`}]]),Hw=U(`pin-off`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89`,key:`znwnzq`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11`,key:`c9qhm2`}]]),Uw=U(`pin`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]),Ww=U(`play`,[[`path`,{d:`M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z`,key:`10ikf1`}]]),Gw=U(`plus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]),Kw=U(`printer`,[[`path`,{d:`M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2`,key:`143wyd`}],[`path`,{d:`M6 9V3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v6`,key:`1itne7`}],[`rect`,{x:`6`,y:`14`,width:`12`,height:`8`,rx:`1`,key:`1ue0tg`}]]),qw=U(`radio-tower`,[[`path`,{d:`M4.9 16.1C1 12.2 1 5.8 4.9 1.9`,key:`s0qx1y`}],[`path`,{d:`M7.8 4.7a6.14 6.14 0 0 0-.8 7.5`,key:`1idnkw`}],[`circle`,{cx:`12`,cy:`9`,r:`2`,key:`1092wv`}],[`path`,{d:`M16.2 4.8c2 2 2.26 5.11.8 7.47`,key:`ojru2q`}],[`path`,{d:`M19.1 1.9a9.96 9.96 0 0 1 0 14.1`,key:`rhi7fg`}],[`path`,{d:`M9.5 18h5`,key:`mfy3pd`}],[`path`,{d:`m8 22 4-11 4 11`,key:`25yftu`}]]),Jw=U(`radio`,[[`path`,{d:`M16.247 7.761a6 6 0 0 1 0 8.478`,key:`1fwjs5`}],[`path`,{d:`M19.075 4.933a10 10 0 0 1 0 14.134`,key:`ehdyv1`}],[`path`,{d:`M4.925 19.067a10 10 0 0 1 0-14.134`,key:`1q22gi`}],[`path`,{d:`M7.753 16.239a6 6 0 0 1 0-8.478`,key:`r2q7qm`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}]]),Yw=U(`refresh-cw`,[[`path`,{d:`M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8`,key:`v9h5vc`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}],[`path`,{d:`M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16`,key:`3uifl3`}],[`path`,{d:`M8 16H3v5`,key:`1cv678`}]]),Xw=U(`rotate-ccw`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}]]),Zw=U(`rotate-cw`,[[`path`,{d:`M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8`,key:`1p45f6`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}]]),Qw=U(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]),$w=U(`search`,[[`path`,{d:`m21 21-4.34-4.34`,key:`14j7rj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}]]),eT=U(`send`,[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]),tT=U(`settings-2`,[[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`path`,{d:`M19 7h-9`,key:`6i9tg`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]),nT=U(`shield-check`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]),rT=U(`shield`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}]]),iT=U(`sliders-horizontal`,[[`path`,{d:`M10 5H3`,key:`1qgfaw`}],[`path`,{d:`M12 19H3`,key:`yhmn1j`}],[`path`,{d:`M14 3v4`,key:`1sua03`}],[`path`,{d:`M16 17v4`,key:`1q0r14`}],[`path`,{d:`M21 12h-9`,key:`1o4lsq`}],[`path`,{d:`M21 19h-5`,key:`1rlt1p`}],[`path`,{d:`M21 5h-7`,key:`1oszz2`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M8 12H3`,key:`a7s4jb`}]]),aT=U(`smartphone`,[[`rect`,{width:`14`,height:`20`,x:`5`,y:`2`,rx:`2`,ry:`2`,key:`1yt0o3`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}]]),oT=U(`smile-plus`,[[`path`,{d:`M22 11v1a10 10 0 1 1-9-10`,key:`ew0xw9`}],[`path`,{d:`M8 14s1.5 2 4 2 4-2 4-2`,key:`1y1vjs`}],[`line`,{x1:`9`,x2:`9.01`,y1:`9`,y2:`9`,key:`yxxnd0`}],[`line`,{x1:`15`,x2:`15.01`,y1:`9`,y2:`9`,key:`1p4y9e`}],[`path`,{d:`M16 5h6`,key:`1vod17`}
63],[`path`,{d:`M19 2v6`,key:`4bpg5p`}]]),sT=U(`smile`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M8 14s1.5 2 4 2 4-2 4-2`,key:`1y1vjs`}],[`line`,{x1:`9`,x2:`9.01`,y1:`9`,y2:`9`,key:`yxxnd0`}],[`line`,{x1:`15`,x2:`15.01`,y1:`9`,y2:`9`,key:`1p4y9e`}]]),cT=U(`snowflake`,[[`path`,{d:`m10 20-1.25-2.5L6 18`,key:`18frcb`}],[`path`,{d:`M10 4 8.75 6.5 6 6`,key:`7mghy3`}],[`path`,{d:`m14 20 1.25-2.5L18 18`,key:`1chtki`}],[`path`,{d:`m14 4 1.25 2.5L18 6`,key:`1b4wsy`}],[`path`,{d:`m17 21-3-6h-4`,key:`15hhxa`}],[`path`,{d:`m17 3-3 6 1.5 3`,key:`11697g`}],[`path`,{d:`M2 12h6.5L10 9`,key:`kv9z4n`}],[`path`,{d:`m20 10-1.5 2 1.5 2`,key:`1swlpi`}],[`path`,{d:`M22 12h-6.5L14 15`,key:`1mxi28`}],[`path`,{d:`m4 10 1.5 2L4 14`,key:`k9enpj`}],[`path`,{d:`m7 21 3-6-1.5-3`,key:`j8hb9u`}],[`path`,{d:`m7 3 3 6h4`,key:`1otusx`}]]),lT=U(`sparkles`,[[`path`,{d:`M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z`,key:`1s2grr`}],[`path`,{d:`M20 2v4`,key:`1rf3ol`}],[`path`,{d:`M22 4h-4`,key:`gwowj6`}],[`circle`,{cx:`4`,cy:`20`,r:`2`,key:`6kqj1y`}]]),uT=U(`square-check-big`,[[`path`,{d:`M21 10.656V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h12.344`,key:`2acyp4`}],[`path`,{d:`m9 11 3 3L22 4`,key:`1pflzl`}]]),dT=U(`square-pen`,[[`path`,{d:`M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7`,key:`1m0v6g`}],[`path`,{d:`M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z`,key:`ohrbg2`}]]),fT=U(`square-split-horizontal`,[[`path`,{d:`M8 19H5c-1 0-2-1-2-2V7c0-1 1-2 2-2h3`,key:`lubmu8`}],[`path`,{d:`M16 5h3c1 0 2 1 2 2v10c0 1-1 2-2 2h-3`,key:`1ag34g`}],[`line`,{x1:`12`,x2:`12`,y1:`4`,y2:`20`,key:`1tx1rr`}]]),pT=U(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),mT=U(`star`,[[`path`,{d:`M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z`,key:`r04s7s`}]]),hT=U(`sun`,[[`circle`,{cx:`12`,cy:`12`,r:`4`,key:`4exip2`}],[`path`,{d:`M12 2v2`,key:`tus03m`}],[`path`,{d:`M12 20v2`,key:`1lh1kg`}],[`path`,{d:`m4.93 4.93 1.41 1.41`,key:`149t6j`}],[`path`,{d:`m17.66 17.66 1.41 1.41`,key:`ptbguv`}],[`path`,{d:`M2 12h2`,key:`1t8f8n`}],[`path`,{d:`M20 12h2`,key:`1q8mjw`}],[`path`,{d:`m6.34 17.66-1.41 1.41`,key:`1m8zz5`}],[`path`,{d:`m19.07 4.93-1.41 1.41`,key:`1shlcs`}]]),gT=U(`terminal`,[[`path`,{d:`M12 19h8`,key:`baeox8`}],[`path`,{d:`m4 17 6-6-6-6`,key:`1yngyt`}]]),_T=U(`timer`,[[`line`,{x1:`10`,x2:`14`,y1:`2`,y2:`2`,key:`14vaq8`}],[`line`,{x1:`12`,x2:`15`,y1:`14`,y2:`11`,key:`17fdiu`}],[`circle`,{cx:`12`,cy:`14`,r:`8`,key:`1e1u0o`}]]),vT=U(`trash-2`,[[`path`,{d:`M10 11v6`,key:`nco0om`}],[`path`,{d:`M14 11v6`,key:`outv1u`}],[`path`,{d:`M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6`,key:`miytrc`}],[`path`,{d:`M3 6h18`,key:`d0wm0j`}],[`path`,{d:`M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2`,key:`e791ji`}]]),yT=U(`trending-down`,[[`path`,{d:`M16 17h6v-6`,key:`t6n2it`}],[`path`,{d:`m22 17-8.5-8.5-5 5L2 7`,key:`x473p`}]]),bT=U(`trending-up`,[[`path`,{d:`M16 7h6v6`,key:`box55l`}],[`path`,{d:`m22 7-8.5 8.5-5-5L2 17`,key:`1t1m79`}]]),xT=U(`triangle-alert`,[[`path`,{d:`m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3`,key:`wmoenq`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),ST=U(`trophy`,[[`path`,{d:`M10 14.66v1.626a2 2 0 0 1-.976 1.696A5 5 0 0 0 7 21.978`,key:`1n3hpd`}],[`path`,{d:`M14 14.66v1.626a2 2 0 0 0 .976 1.696A5 5 0 0 1 17 21.978`,key:`rfe1zi`}],[`path`,{d:`M18 9h1.5a1 1 0 0 0 0-5H18`,key:`7xy6bh`}],[`path`,{d:`M4 22h16`,key:`57wxv0`}],[`path`,{d:`M6 9a6 6 0 0 0 12 0V3a1 1 0 0 0-1-1H7a1 1 0 0 0-1 1z`,key:`1mhfuq`}],[`path`,{d:`M6 9H4.5a1 1 0 0 1 0-5H6`,key:`tex48p`}]]),CT=U(`upload`,[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]),wT=U(`user-check`,[[`path`,{d:`m16 11 2 2 4-4`,key:`9rsbq5`}],[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),TT=U(`user-cog`,[[`path`,{d:`M10 15H6a4 4 0 0 0-4 4v2`,key:`1nfge6`}],[`path`,{d:`m14.305 16.53.923-.382`,key:`1itpsq`}],[`path`,{d:`m15.228 13.852-.923-.383`,key:`eplpkm`}],[`path`,{d:`m16.852 12.228-.383-.923`,key:`13v3q0`}],[`path`,{d:`m16.852 17.772-.383.924`,key:`1i8mnm`}],[`path`,{d:`m19.148 12.228.383-.923`,key:`1q8j1v`}],[`path`,{d:`m19.53 18.696-.382-.924`,key:`vk1qj3`}],[`path`,{d:`m20.772 13.852.924-.383`,key:`n880s0`}],[`path`,{d:`m20.772 16.148.924.383`,key:`1g6xey`}],[`circle`,{cx:`18`,cy:`15`,r:`3`,key:`gjjjvw`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),ET=U(`user-minus`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`22`,x2:`16`,y1:`11`,y2:`11`,key:`1shjgl`}]]),DT=U(`user-plus`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`19`,x2:`19`,y1:`8`,y2:`14`,key:`1bvyxn`}],[`line`,{x1:`22`,x2:`16`,y1:`11`,y2:`11`,key:`1shjgl`}]]),OT=U(`user-round-search`,[[`circle`,{cx:`10`,cy:`8`,r:`5`,key:`o932ke`}],[`path`,{d:`M2 21a8 8 0 0 1 10.434-7.62`,key:`1yezr2`}],[`circle`,{cx:`18`,cy:`18`,r:`3`,key:`1xkwt0`}],[`path`,{d:`m22 22-1.9-1.9`,key:`1e5ubv`}]]),kT=U(`user-x`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`17`,x2:`22`,y1:`8`,y2:`13`,key:`3nzzx3`}],[`line`,{x1:`22`,x2:`17`,y1:`8`,y2:`13`,key:`1swrse`}]]),AT=U(`user`,[[`path`,{d:`M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2`,key:`975kel`}],[`circle`,{cx:`12`,cy:`7`,r:`4`,key:`17ys0d`}]]),jT=U(`users-round`,[[`path`,{d:`M18 21a8 8 0 0 0-16 0`,key:`3ypg7q`}],[`circle`,{cx:`10`,cy:`8`,r:`5`,key:`o932ke`}],[`path`,{d:`M22 20c0-3.37-2-6.5-4-8a5 5 0 0 0-.45-8.3`,key:`10s06x`}]]),MT=U(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}
63]]),NT=U(`wifi-off`,[[`path`,{d:`M12 20h.01`,key:`zekei9`}],[`path`,{d:`M8.5 16.429a5 5 0 0 1 7 0`,key:`1bycff`}],[`path`,{d:`M5 12.859a10 10 0 0 1 5.17-2.69`,key:`1dl1wf`}],[`path`,{d:`M19 12.859a10 10 0 0 0-2.007-1.523`,key:`4k23kn`}],[`path`,{d:`M2 8.82a15 15 0 0 1 4.177-2.643`,key:`1grhjp`}],[`path`,{d:`M22 8.82a15 15 0 0 0-11.288-3.764`,key:`z3jwby`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),PT=U(`workflow`,[[`rect`,{width:`8`,height:`8`,x:`3`,y:`3`,rx:`2`,key:`by2w9f`}],[`path`,{d:`M7 11v4a2 2 0 0 0 2 2h4`,key:`xkn7yn`}],[`rect`,{width:`8`,height:`8`,x:`13`,y:`13`,rx:`2`,key:`1cgmvn`}]]),FT=U(`x`,[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]),IT=U(`zap`,[[`path`,{d:`M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z`,key:`1xq2db`}]]),LT=e=>typeof e==`boolean`?`${e}`:e===0?`0`:e,RT=Dy,zT=(e,t)=>n=>{if(t?.variants==null)return RT(e,n?.class,n?.className);let{variants:r,defaultVariants:i}=t,a=Object.keys(r).map(e=>{let t=n?.[e],a=i?.[e];if(t===null)return null;let o=LT(t)||LT(a);return r[e][o]}),o=n&&Object.entries(n).reduce((e,t)=>{let[n,r]=t;return r===void 0||(e[n]=r),e},{});return RT(e,a,t?.compoundVariants?.reduce((e,t)=>{let{class:n,className:r,...a}=t;return Object.entries(a).every(e=>{let[t,n]=e;return Array.isArray(n)?n.includes({...i,...o}[t]):{...i,...o}[t]===n})?[...e,n,r]:e},[]),n?.class,n?.className)},BT=1024;function VT(e){let t=`(max-width: ${e-1}px)`;return{subscribe(e){let n=window.matchMedia(t);return n.addEventListener(`change`,e),()=>n.removeEventListener(`change`,e)},getSnapshot(){return window.innerWidth<e}}}function HT(){return!1}var UT=VT(768),WT=VT(BT);function GT(){return(0,_.useSyncExternalStore)(UT.subscribe,UT.getSnapshot,HT)}function KT(){return(0,_.useSyncExternalStore)(WT.subscribe,WT.getSnapshot,HT)}var qT=zT(`inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,{variants:{variant:{default:`bg-primary text-primary-foreground hover:bg-primary/90`,destructive:`bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40`,outline:`border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50`,secondary:`bg-secondary text-secondary-foreground hover:bg-secondary/80`,ghost:`hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50`,link:`text-primary underline-offset-4 hover:underline`},size:{default:`h-9 px-4 py-2 has-[>svg]:px-3`,xs:`h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3`,sm:`h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5`,lg:`h-10 rounded-md px-6 has-[>svg]:px-4`,icon:`size-9`,"icon-xs":`size-6 rounded-md [&_svg:not([class*='size-'])]:size-3`,"icon-sm":`size-8`,"icon-lg":`size-10`}},defaultVariants:{variant:`default`,size:`default`}});function W({className:e,variant:t=`default`,size:n=`default`,asChild:r=!1,...i}){return(0,L.jsx)(r?ea:`button`,{"data-slot":`button`,"data-variant":t,"data-size":n,className:V(qT({variant:t,size:n,className:e})),...i})}function G({className:e,type:t,...n}){return(0,L.jsx)(`input`,{type:t,"data-slot":`input`,className:V(`h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none selection:bg-primary selection:text-primary-foreground file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm dark:bg-input/30`,`focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50`,`aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40`,e),...n})}function JT({className:e,orientation:t=`horizontal`,decorative:n=!0,...r}){return(0,L.jsx)(sv,{"data-slot":`separator`,decorative:n,orientation:t,className:V(`shrink-0 bg-border data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px`,e),...r})}function YT({...e}){return(0,L.jsx)(Ec,{"data-slot":`sheet`,...e})}function XT({...e}){return(0,L.jsx)(Dc,{"data-slot":`sheet-trigger`,...e})}function ZT({...e}){return(0,L.jsx)(Oc,{"data-slot":`sheet-portal`,...e})}function QT({className:e,...t}){return(0,L.jsx)(kc,{"data-slot":`sheet-overlay`,className:V(`fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0`,e),...t})}function $T({className:e,children:t,side:n=`right`,showCloseButton:r=!0,...i}){return(0,L.jsxs)(ZT,{children:[(0,L.jsx)(QT,{}),(0,L.jsxs)(Ac,{"data-slot":`sheet-content`,className:V(`fixed z-50 flex flex-col gap-4 bg-background shadow-lg transition ease-in-out data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:animate-in data-[state=open]:duration-500`,n===`right`&&`inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm`,n===`left`&&`inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm`,n===`top`&&`inset-x-0 top-0 h-auto border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top`,n===`bottom`&&`inset-x-0 bottom-0 h-auto border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom`,e),...i,children:[t,r&&(0,L.jsxs)(Nc,{className:`absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none data-[state=open]:bg-secondary`,children:[(0,L.jsx)(FT,{className:`size-4`}),(0,L.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function eE({className:e,...t}){return(0,L.jsx)(`div`,{"data-slot":`sheet-header`,className:V(`flex flex-col gap-1.5 p-4`,e),...t})}function tE({className:e,...t}){return(0,L.jsx)(jc,{"data-slot":`sheet-title`,className:V(`font-semibold text-foreground`,e),...t})}function nE({className:e,...t}){return(0,L.jsx)(Mc,{"data-slot":`sheet-description`,className:V(`text-sm text-muted-foreground`,e),...t})}function rE({className:e,...t}){return(0,L.jsx)(`div`,{"data-slot":`skeleton`,className:V(`animate-pulse rounded-md bg-accent`,e),...t})}var iE=`sidebar_state`,aE=3600*24*7,oE=`16rem`,sE=`18rem`,cE=`3rem`,lE=`b`,uE=_.createContext(null);function dE(){let e=_.useContext(uE);if(!e)throw Error(`useSidebar must be used within a SidebarProvider.`);return e}function fE({defaultOpen:e=!0,open:t,onOpenChange:n,className:r,style:i,children:a,...o}){let s=GT(),[c,l]=_.useState(!1),[u,d]=_.useState(e),f=t??u,p=_.useCallback(e=>{let t=typeof e==`function`?e(f):e;n?n(t):d(t),document.cookie=`${iE}=${t}; path=/; max-age=${aE}`},[n,f]),m=_.useCallback(()=>s?l(e=>!e):p(e=>!e),[s,p,l]);_.useEffect(()=>{let e=e=>
63{e.key===lE&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),m())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[m]);let h=f?`expanded`:`collapsed`,g=_.useMemo(()=>({state:h,open:f,setOpen:p,isMobile:s,openMobile:c,setOpenMobile:l,toggleSidebar:m}),[h,f,p,s,c,l,m]);return(0,L.jsx)(uE.Provider,{value:g,children:(0,L.jsx)(ex,{delayDuration:0,children:(0,L.jsx)(`div`,{"data-slot":`sidebar-wrapper`,style:{"--sidebar-width":oE,"--sidebar-width-icon":cE,...i},className:V(`group/sidebar-wrapper flex min-h-svh w-full has-data-[variant=inset]:bg-sidebar`,r),...o,children:a})})})}function pE({side:e=`left`,variant:t=`sidebar`,collapsible:n=`offcanvas`,className:r,children:i,...a}){let{isMobile:o,state:s,openMobile:c,setOpenMobile:l}=dE();return n===`none`?(0,L.jsx)(`div`,{"data-slot":`sidebar`,className:V(`flex h-full w-(--sidebar-width) flex-col bg-sidebar text-sidebar-foreground`,r),...a,children:i}):o?(0,L.jsx)(YT,{open:c,onOpenChange:l,...a,children:(0,L.jsxs)($T,{"data-sidebar":`sidebar`,"data-slot":`sidebar`,"data-mobile":`true`,className:`w-(--sidebar-width) bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden`,style:{"--sidebar-width":sE},side:e,children:[(0,L.jsxs)(eE,{className:`sr-only`,children:[(0,L.jsx)(tE,{children:`Sidebar`}),(0,L.jsx)(nE,{children:`Displays the mobile sidebar.`})]}),(0,L.jsx)(`div`,{className:`flex h-full w-full flex-col`,children:i})]})}):(0,L.jsxs)(`div`,{className:`group peer hidden text-sidebar-foreground md:block`,"data-state":s,"data-collapsible":s===`collapsed`?n:``,"data-variant":t,"data-side":e,"data-slot":`sidebar`,children:[(0,L.jsx)(`div`,{"data-slot":`sidebar-gap`,className:V(`relative w-(--sidebar-width) bg-transparent transition-[width] duration-200 ease-linear`,`group-data-[collapsible=offcanvas]:w-0`,`group-data-[side=right]:rotate-180`,t===`floating`||t===`inset`?`group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]`:`group-data-[collapsible=icon]:w-(--sidebar-width-icon)`)}),(0,L.jsx)(`div`,{"data-slot":`sidebar-container`,className:V(`fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear md:flex`,e===`left`?`left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]`:`right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]`,t===`floating`||t===`inset`?`p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]`:`group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l`,r),...a,children:(0,L.jsx)(`div`,{"data-sidebar":`sidebar`,"data-slot":`sidebar-inner`,className:`flex h-full w-full flex-col bg-sidebar group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:border-sidebar-border group-data-[variant=floating]:shadow-sm`,children:i})})]})}function mE({className:e,onClick:t,...n}){let{toggleSidebar:r}=dE();return(0,L.jsxs)(W,{"data-sidebar":`trigger`,"data-slot":`sidebar-trigger`,variant:`ghost`,size:`icon`,className:V(`size-7`,e),onClick:e=>{t?.(e),r()},...n,children:[(0,L.jsx)(Lw,{}),(0,L.jsx)(`span`,{className:`sr-only`,children:`Toggle Sidebar`})]})}function hE({className:e,...t}){let{toggleSidebar:n}=dE();return(0,L.jsx)(`button`,{"data-sidebar":`rail`,"data-slot":`sidebar-rail`,"aria-label":`Toggle Sidebar`,tabIndex:-1,onClick:n,title:`Toggle Sidebar`,className:V(`absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] hover:after:bg-sidebar-border sm:flex`,`in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize`,`[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize`,`group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full hover:group-data-[collapsible=offcanvas]:bg-sidebar`,`[[data-side=left][data-collapsible=offcanvas]_&]:-right-2`,`[[data-side=right][data-collapsible=offcanvas]_&]:-left-2`,e),...t})}function gE({className:e,...t}){return(0,L.jsx)(`main`,{"data-slot":`sidebar-inset`,className:V(`relative flex w-full flex-1 flex-col bg-background`,`md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow-sm md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2`,e),...t})}function _E({className:e,...t}){return(0,L.jsx)(`div`,{"data-slot":`sidebar-header`,"data-sidebar":`header`,className:V(`flex flex-col gap-2 p-2`,e),...t})}function vE({className:e,...t}){return(0,L.jsx)(`div`,{"data-slot":`sidebar-footer`,"data-sidebar":`footer`,className:V(`flex flex-col gap-2 p-2`,e),...t})}function yE({className:e,...t}){return(0,L.jsx)(`div`,{"data-slot":`sidebar-content`,"data-sidebar":`content`,className:V(`flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden`,e),...t})}function bE({className:e,...t}){return(0,L.jsx)(`div`,{"data-slot":`sidebar-group`,"data-sidebar":`group`,className:V(`relative flex w-full min-w-0 flex-col p-2`,e),...t})}function xE({className:e,asChild:t=!1,...n}){return(0,L.jsx)(t?ea:`div`,{"data-slot":`sidebar-group-label`,"data-sidebar":`group-label`,className:V(`flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium text-sidebar-foreground
63/70 ring-sidebar-ring outline-hidden transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0`,`group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0`,e),...n})}function SE({className:e,...t}){return(0,L.jsx)(`div`,{"data-slot":`sidebar-group-content`,"data-sidebar":`group-content`,className:V(`w-full text-sm`,e),...t})}function CE({className:e,...t}){return(0,L.jsx)(`ul`,{"data-slot":`sidebar-menu`,"data-sidebar":`menu`,className:V(`flex w-full min-w-0 flex-col gap-1`,e),...t})}function wE({className:e,...t}){return(0,L.jsx)(`li`,{"data-slot":`sidebar-menu-item`,"data-sidebar":`menu-item`,className:V(`group/menu-item relative`,e),...t})}var TE=zT(`peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm ring-sidebar-ring outline-hidden transition-[width,height,padding] group-has-data-[sidebar=menu-action]/menu-item:pr-8 group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0`,{variants:{variant:{default:`hover:bg-sidebar-accent hover:text-sidebar-accent-foreground`,outline:`bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]`},size:{default:`h-8 text-sm`,sm:`h-7 text-xs`,lg:`h-12 text-sm group-data-[collapsible=icon]:p-0!`}},defaultVariants:{variant:`default`,size:`default`}});function EE({asChild:e=!1,isActive:t=!1,variant:n=`default`,size:r=`default`,tooltip:i,className:a,...o}){let s=e?ea:`button`,{isMobile:c,state:l}=dE(),u=(0,L.jsx)(s,{"data-slot":`sidebar-menu-button`,"data-sidebar":`menu-button`,"data-size":r,"data-active":t,className:V(TE({variant:n,size:r}),a),...o});return i?(typeof i==`string`&&(i={children:i}),(0,L.jsxs)(tx,{children:[(0,L.jsx)(nx,{asChild:!0,children:u}),(0,L.jsx)(rx,{side:`right`,align:`center`,hidden:l!==`collapsed`||c,...i})]})):u}var DE=[{label:`Overview`,items:[{title:`Dashboard`,url:`/`,icon:Sw},{title:`Inbox`,url:`/messages`,icon:Nw}]},{label:`Management`,items:[{title:`Leads`,url:`/leads`,icon:MT},{title:`Agents`,url:`/agents`,icon:wT},{title:`Assignments`,url:`/assignments`,icon:hw},{title:`Backlog`,url:`/backlog`,icon:QC}]},{label:`AI`,items:[{title:`AI & Settings`,url:`/ai-training`,icon:NC},{title:`Knowledge Base`,url:`/knowledge-base`,icon:kC}]},{label:`Agent PA`,items:[{title:`Groups`,url:`/agent-pa`,icon:jT},{title:`Weekly Digests`,url:`/agent-pa/weekly-digests`,icon:lw},{title:`Alerts`,url:`/agent-pa/alerts`,icon:OC}]},{label:`System`,items:[{title:`Usage Report`,url:`/analytics`,icon:LC},{title:`Activity Log`,url:`/activity`,icon:yC},{title:`Connect`,url:`/connect`,icon:PC},{title:`Website Widget`,url:`/website-widget`,icon:_w}]}];function OE(e){let t=Ze(),n=et(),{data:r}=uC.useSession();return(0,L.jsxs)(pE,{collapsible:`icon`,...e,children:[(0,L.jsx)(_E,{className:`p-4`,children:(0,L.jsx)(`span`,{className:`text-lg font-semibold tracking-tight group-data-[collapsible=icon]:hidden`,children:`StackedHomes`})}),(0,L.jsx)(yE,{children:DE.map(e=>(0,L.jsxs)(bE,{children:[(0,L.jsx)(xE,{children:e.label}),(0,L.jsx)(SE,{children:(0,L.jsx)(CE,{children:e.items.map(e=>(0,L.jsx)(wE,{children:(0,L.jsx)(EE,{asChild:!0,isActive:e.url===`/`?t.pathname===`/`:t.pathname===e.url,tooltip:e.title,children:(0,L.jsxs)(Cn,{to:e.url,children:[(0,L.jsx)(e.icon,{}),(0,L.jsx)(`span`,{children:e.title})]})})},e.title))})})]},e.label))}),(0,L.jsx)(vE,{className:`p-2`,children:(0,L.jsx)(CE,{children:(0,L.jsx)(wE,{children:(0,L.jsxs)(EE,{tooltip:`Sign out`,onClick:async()=>{await uC.signOut(),n(`/login`)},children:[(0,L.jsx)(Dw,{}),(0,L.jsxs)(`span`,{className:`flex flex-col items-start`,children:[(0,L.jsx)(`span`,{className:`text-xs truncate max-w-[140px]`,children:r?.user?.email}),(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Sign out`})]})]})})})}),(0,L.jsx)(hE,{})]})}function kE(e){if(!e||!(e instanceof Element))return!1;let t=e.tagName;return!!(t===`INPUT`||t===`TEXTAREA`||t===`SELECT`||e instanceof HTMLElement&&e.isContentEditable)}function AE(e,t){let n=e.toLowerCase().split(`+`).map(e=>e.trim()),r=n[n.length-1],i=new Set(n.slice(0,-1)),a=i.has(`mod`),o=i.has(`cmd`)||i.has(`meta`),s=i.has(`ctrl`)||i.has(`control`),c=i.has(`shift`),l=i.has(`alt`)||i.has(`option`);if(a){if(!(t.metaKey||t.ctrlKey))return!1}else if(o&&!t.metaKey||s&&!t.ctrlKey||!o&&!s&&(t.metaKey||t.ctrlKey))return!1;return c&&!t.shiftKey||l&&!t.altKey?!1:t.key.toLowerCase()===r}function jE(e,t){for(let n of e)if((Array.isArray(n.keys)?n.keys:[n.keys]).some(e=>AE(e,t)))return n;return null}function ME(e,t=!0){return(0,_.useEffect)(()=>
63{if(!t)return;let n=t=>{let n=jE(e,t);if(!n)return;let r=t.key===`Escape`;kE(t.target)&&!n.allowInInputs&&!r||n.handler(t)};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]),e}function NE(e,t){let n=new URLSearchParams(t);return{path:e,leadId:n.get(`lead`),conversationId:n.get(`conversation`)}}var PE={"/":`the Dashboard`,"/leads":`the Leads page`,"/messages":`the inbox`,"/agents":`the Agents page`,"/assignments":`the assignment log`,"/backlog":`the backlog`,"/ai-training":`the AI & Settings page`,"/knowledge-base":`the Knowledge Base`,"/analytics":`the usage report`,"/activity":`the activity log`,"/connect":`the WhatsApp connection page`,"/website-widget":`the Website Widget page`,"/agent-pa":`the Agent PA groups page`,"/agent-pa/weekly-digests":`the weekly digests page`,"/agent-pa/alerts":`the Agent PA alerts page`,"/simulation":`the simulation page`,"/sandbox":`the sandbox`};function FE(e){return PE[e]??`the dashboard`}function IE(e,t=Date.now()){if(!e)return null;let n=new Date(e).getTime();if(Number.isNaN(n))return null;let r=Math.max(0,Math.round((t-n)/1e3));if(r<60)return`just now`;let i=Math.round(r/60);if(i<60)return`${i} minute${i===1?``:`s`} ago`;let a=Math.round(i/60);if(a<24)return`${a} hour${a===1?``:`s`} ago`;let o=Math.round(a/24);return`${o} day${o===1?``:`s`} ago`}function LE(e,t,n=Date.now()){if(e.leadId&&t){let e=[];e.push(t.status),e.push(t.assignedAgentName?`assigned to ${t.assignedAgentName}`:`unassigned`);let r=IE(t.lastContactedAt,n);return r&&e.push(`last contacted ${r}`),t.deletedAt&&e.push(`SOFT-DELETED`),`Viewing ${t.name??`this lead`} - ${e.join(`, `)}`}return e.leadId&&!t?`Viewing a lead that could not be loaded`:`On ${FE(e.path)}`}function RE(e){let t=[];if(e){let n=e.name??`this lead`;e.deletedAt?t.push({label:`Why was this lead deleted?`,prompt:`Lead ${n} (${e.id}) shows as deleted. When was it deleted and why is it not on my dashboard?`}):e.assignedAgentId||t.push({label:`Why isn't this lead assigned?`,prompt:`Why hasn't lead ${n} (${e.id}) been assigned to an agent yet?`}),t.push({label:`Did the AI handle this lead correctly?`,prompt:`Walk me through what the AI did for lead ${n} (${e.id}). Did it read the form answers correctly and reply appropriately?`})}return t.push({label:`Is WhatsApp live right now?`,prompt:`Is WhatsApp connected right now, and are AI replies being sent to leads or held as drafts?`},{label:`Which leads are stuck?`,prompt:`Which leads are stuck in qualification right now, and does that number look normal?`}),t}function zE(){return{text:``,evidence:[],triage:null,proposals:[],doneMessageId:null,error:null}}function BE(e,t){switch(t.type){case`text`:return{...e,text:e.text+t.text};case`tool_call`:return{...e,evidence:[...e.evidence,{id:t.id,name:t.name,args:t.args,rowCount:null,truncated:!1,table:null,error:null}]};case`tool_result`:return{...e,evidence:e.evidence.map(e=>e.id===t.id?{...e,rowCount:t.rowCount,truncated:t.truncated,error:t.error??null}:e)};case`table`:return{...e,evidence:e.evidence.map(e=>e.id===t.id?{...e,table:{columns:t.columns,rows:t.rows}}:e)};case`proposals`:{let n=new Map(e.proposals.map(e=>[e.id,e]));for(let e of t.proposals)n.set(e.id,e);return{...e,proposals:[...n.values()]}}case`triage`:return{...e,triage:{verdict:t.verdict,playbookId:t.playbookId,routeToEthan:t.routeToEthan,handoffDraft:t.handoffDraft}};case`done`:return{...e,doneMessageId:t.messageId};case`error`:return{...e,error:t.message};default:return e}}function VE(e){let t=e.trim();if(!t)return null;try{return JSON.parse(t)}catch{return null}}function HE(e){return e.filter(e=>e.role===`user`||e.role===`assistant`).filter(e=>e.content.trim().length>0).map(e=>({id:e.id,role:e.role===`assistant`?`assistant`:`user`,content:e.content,evidence:[],proposals:[],triage:e.triageStatus===`ok`?{verdict:e.triageVerdict??``,playbookId:e.triagePlaybookId,routeToEthan:e.triageRouteToEthan??!1,handoffDraft:e.triageHandoffDraft}:null}))}async function UE(){return(await H(`/api/copilot/sessions`)).data?.sessions??[]}async function WE(e){return HE((await H(`/api/copilot/sessions/${encodeURIComponent(e)}/messages`)).data??[])}
63async function GE(){let e=await H(`/api/copilot/proposals?status=pending`),t=(e.data?.proposals??[]).map(e=>({id:e.id,leadId:e.leadId,leadName:e.leadName,sessionId:e.sessionId,status:`pending`,windowStart:e.windowStart,windowEnd:e.windowEnd,summary:e.summary,suggestedStatus:e.suggestedStatus,baselineTier:e.baselineTier,tier:e.tier,flagReason:e.flagReason,leadUpdatedAt:e.leadUpdatedAt,updatedAt:e.updatedAt}));return{proposals:t,total:e.data?.total??t.length,truncated:e.data?.truncated===!0}}function KE(e,t){let n=new Set(t.map(e=>e.id));return[...t,...e.filter(e=>!n.has(e.id))]}var qE=`copilot.lastSessionId`;function JE(){try{let e=window.localStorage.getItem(qE);return e&&e.trim()?e:null}catch{return null}}function YE(e){try{window.localStorage.setItem(qE,e)}catch{}}function XE(){try{window.localStorage.removeItem(qE)}catch{}}function ZE(e){return e.ok?{kind:`approved`,appliedStatus:e.appliedStatus}:null}function QE(e){return e.ok?{kind:`rejected`}:null}function $E(e,t,n){let r=e[t];return r&&(r.kind!==`resolved`||n.kind===`resolved`)?e:{...e,[t]:n}}function eD(e,t,n){let r=new Set(n),i=null;for(let n of t)r.has(n)||e[n]||(i??={...e},i[n]={kind:`resolved`});return i??e}var tD=(0,_.createContext)({resolutions:{},resolve:()=>{},onSettled:()=>{}});function nD(){return(0,_.useContext)(tD)}function rD(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(!1),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(zE()),[u,d]=(0,_.useState)(null),f=(0,_.useRef)(null),[p,m]=(0,_.useState)([]),[h,g]=(0,_.useState)(!1),[v,y]=(0,_.useState)(null),[b,x]=(0,_.useState)(0),[S,C]=(0,_.useState)(!1),w=(0,_.useRef)([]),[T,E]=(0,_.useState)({}),D=(0,_.useRef)([]);(0,_.useEffect)(()=>{D.current=e.flatMap(e=>e.proposals.map(e=>e.id))},[e]);let O=(0,_.useCallback)(e=>{f.current=e,d(e),e?YE(e):XE()},[]),k=(0,_.useRef)(0),A=(0,_.useCallback)(async()=>{let e=++k.current,t=()=>e===k.current;g(!0);try{let e=await GE();if(!t())return;let n=w.current,r=KE(n,e.proposals);if(w.current=r,m(r),y(null),x(e.total),C(e.truncated),!e.truncated){let t=[...D.current,...n.map(e=>e.id)],r=e.proposals.map(e=>e.id);E(e=>eD(e,t,r))}}catch(e){if(!t())return;y(e instanceof Error?e.message:`Could not load pending proposals`)}finally{t()&&g(!1)}},[]),j=(0,_.useRef)(A);j.current=A;let M=(0,_.useCallback)((e,t)=>{E(n=>$E(n,e,t))},[]),ee=(0,_.useCallback)(()=>{j.current()},[]),N=(0,_.useMemo)(()=>({resolutions:T,resolve:M,onSettled:ee}),[T,M,ee]),P=(0,_.useCallback)(async()=>{if(f.current)return f.current;let e=await fetch(`/api/copilot/sessions`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`},body:`{}`});if(e.status===401)throw window.location.href=`/login`,Error(`Session expired`);if(!e.ok)throw Error(`Could not start copilot session (${e.status})`);let t=await e.json();return O(t.data.id),t.data.id},[O]),F=(0,_.useRef)(null),I=(0,_.useRef)(0),te=(0,_.useCallback)(e=>{let t=++I.current;a(!0);let n=e(()=>I.current===t).finally(()=>{I.current===t&&a(!1),F.current===n&&(F.current=null)});return F.current=n,n},[]),ne=(0,_.useCallback)(async()=>{for(;F.current;)await F.current.catch(()=>{})},[]),re=(0,_.useRef)(`pending`),ie=(0,_.useCallback)(async()=>{if(re.current===`done`)return;let e=JE(),n=re.current===`retry`;if(!e||f.current&&!(n&&f.current===e)){re.current=`done`;return}re.current=`done`,await te(async n=>{try{let r=await WE(e);if(!n())return;O(e),t(r),s(!1)}catch(t){if(!n())return;if(t instanceof lC&&t.status>=400&&t.status<500){XE(),s(!1);return}re.current=`retry`,O(e),s(!0)}})},[O,te]),ae=(0,_.useCallback)(async e=>{re.current=`done`,await te(async n=>{try{let r=await WE(e);if(!n())return;O(e),t(r),l(zE()),s(!1)}catch(e){if(!n())return;z.error(e instanceof Error?e.message:`Could not open that chat`)}})},[O,te]);return{messages:e,streaming:n,resuming:i,resumeFailed:o,live:c,sessionId:u,send:(0,_.useCallback)(async(e,i)=>{let a=e.trim();if(!a||n)return;await ne(),t(e=>[...e,{id:`u-${Date.now()}`,role:`user`,content:a,evidence:[],triage:null,proposals:[]}]),l(zE()),r(!0);let o=zE(),s=null,c=e=>{let t=VE(e);t&&(t.type===`error`&&z.error(t.message),o=BE(o,t),f.current===s&&l(o))};try{let e=await P();s=e;let n=await fetch(`/api/copilot/sessions/${e}/chat`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify({message:a,context:i?{path:i.path,leadId:i.leadId??void 0,conversationId:i.conversationId??void 0}:void 0})});if(n.status===401){window.location.href=`/login`;return}if(!n.ok||!n.body)throw Error(`Request failed: ${n.status}`);let r=n.body.getReader(),l=new TextDecoder,u=``;for(;;){let{done:e,value:t}=await r.read();if(e)break;u+=l.decode(t,{stream:!0});let n=u.split(` 64`);u=n.pop()??``;for(let e of n)c(e)}if(u.trim()&&c(u),f.current!==e)return;t(e=>[...e,{id:o.doneMessageId??`a-${Date.now()}`,role:`assistant`,content:o.text.trim(),evidence:o.evidence,triage:o.triage,proposals:o.proposals}])}catch(e){z.error(e instanceof Error?e.message:`Copilot failed`)}finally{l(zE()),r(!1)}},[P,ne,n]),reset:(0,_.useCallback)(()=>{re.current=`done`,O(null),t([]),l(zE()),s(!1)},[O]),resume:ie,openSession:ae,pending:(0,_.useMemo)(()=>({proposals:p,loading:h,error:v,total:b,truncated:S,refresh:A}),[p,h,v,b,S,A]),resolutionStore:N}}function iD({ctx:e,lead:t}){return(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b px-4 py-2 text-xs text-muted-foreground`,children:[(0,L.jsx)(kw,{className:`h-3.5 w-3.5 shrink-0`}),(0,L.jsx)(`span`,{className:`truncate`,children:LE(e,t)})]})}function aD({lead:e,disabled:t,onPick:n}){let r=RE(e);return r.length===0?null:(0,L.jsx)(`div`,{className:`flex flex-wrap gap-1.5 px-4 pb-3`,children:r.map(e=>(0,L.jsx)(`button`,{type:`button`,disabled:t,onClick:()=>n(e.prompt),className:`rounded-full border bg-background px-3 py-1 text-xs text-foreground transition-colors hover:bg-muted disabled:opacity-50`,children:e.label},e.label))})}function oD(e){if(e.name===`read_playbook`){let t=e.args?.id;return t?`Read playbook: ${t}`:`Read a playbook`}if(e.name===`list_playbooks`)return`Listed the playbooks`;if(e.name===`run_sql`)return e.error||e.rowCount===null?`Ran a query`:`Ran a query (${e.rowCount} rows)`;let t=e.rowCount===null||e.error?``:` (${e.rowCount})`;return`${e.name.replace(/_/g,` `)}${t}`}function sD(e){return e.filter(e=>e.error!==null).length}function cD(e){let t=`Checked ${e.length} source${e.length===1?``:`s`}`,n=sD(e);return n===0?t:`${t} · ${n} failed`}function lD(e){return e.some(e=>e.table!==null&&e.table.rows.length>0)}function uD({columns:e,rows:t}){return(0,L.jsx)(`div`,{className:`mt-1 max-h-52 overflow-auto rounded border`,children:(0,L.jsxs)(`table`,{className:`w-full border-collapse text-[11px]`,children:[(0,L.jsx)(`thead`,{className:`sticky top-0 bg-muted`,children:(0,L.jsx)(`tr`,{children:e.map((e,t)=>(0,L.jsx)(`th`,{className:`border-b px-2 py-1 text-left font-medium`,children:e},t))})}),(0,L.jsx)(`tbody`,{children:t.map((e,t)=>(0,L.jsx)(`tr`,{className:`odd:bg-muted/30`,children:e.map((e,t)=>(0,L.jsx)(`td`,{className:`border-b px-2 py-1 align-top`,children:e==null?(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`null`}):String(e)},t))},t))})]})})}function dD({evidence:e}){let[t,n]=(0,_.useState)(null),r=t??lD(e);return e.length===0?null:(0,L.jsxs)(`div`,{className:`mt-2 text-xs`,children:[(0,L.jsxs)(`button`,{type:`button`,onClick:()=>n(!r),"aria-expanded":r,className:`flex items-center gap-1 text-muted-foreground transition-colors hover:text-foreground`,children:[(0,L.jsx)(VC,{className:`h-3 w-3 transition-transform ${r?`rotate-90`:``}`}),(0,L.jsx)($w,{className:`h-3 w-3`}),cD(e)]}),r&&(0,L.jsx)(`ol`,{className:`mt-1 space-y-2 border-l pl-3`,children:e.map(e=>(0,L.jsxs)(`li`,{className:`space-y-1`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-foreground`,children:[(0,L.jsx)(`span`,{children:oD(e)}),e.error&&(0,L.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-1 rounded border border-destructive/40 bg-destructive/10 px-1 py-px text-[10px] font-medium text-destructive`,children:[(0,L.jsx)(xT,{className:`h-2.5 w-2.5`}),`failed`]})]}),e.name===`run_sql`&&e.args?.sql&&(0,L.jsx)(`pre`,{className:`overflow-x-auto rounded bg-muted px-2 py-1 text-[11px] whitespace-pre-wrap`,children:e.args.sql}),e.error&&(0,L.jsx)(`div`,{className:`rounded border border-destructive/30 bg-destructive/5 px-2 py-1 text-[11px] whitespace-pre-wrap text-destructive`,children:e.error}),e.table&&(0,L.jsx)(uD,{columns:e.table.columns,rows:e.table.rows}),e.truncated&&(0,L.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:`Results were truncated to keep the answer readable.`})]},e.id))})]})}function fD({draft:e}){let[t,n]=(0,_.useState)(!1);return(0,L.jsxs)(`div`,{className:`mt-2 rounded-lg border border-amber-300 bg-amber-50 p-3 text-sm dark:border-amber-800 dark:bg-amber-950/40`,children:[(0,L.jsxs)(`div`,{className:`mb-1 flex items-center gap-1.5 font-medium text-amber-900 dark:text-amber-200`,children:[(0,L.jsx)(Nw,{className:`h-4 w-4`}),`Ask Ethan`]}),(0,L.jsx)(`p`,{className:`mb-2 whitespace-pre-wrap rounded border bg-background px-2 py-1.5 text-foreground`,children:e}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsxs)(W,{size:`sm`,variant:`outline`,onClick:async()=>{try{await navigator.clipboard.writeText(e),n(!0),setTimeout(()=>n(!1),2e3)}catch{n(!1)}},children:[t?(0,L.jsx)(RC,{className:`h-3.5 w-3.5`}):(0,L.jsx)(ew,{className:`h-3.5 w-3.5`}),t?`Copied`:`Copy message`]}),(0,L.jsx)(`a`,{href:`https://wa.me/?text=${encodeURIComponent(e)}`,target:`_blank`,rel:`noreferrer`,className:`text-xs text-amber-800 underline hover:no-underline dark:text-amber-300`,children:`Open in WhatsApp`})]}),(0,L.jsx)(`p`,{className:`mt-2 text-[11px] text-amber-800/80 dark:text-amber-300/70`,children:`Drafted by AI from the lead's own messages - read it before you send.`})]})}var pD=[`lead_changed`,`card_redrafted`,`both`];async function mD(e,t={}
64){try{return{ok:!0,...(await H(`/api/copilot/proposals/${encodeURIComponent(e)}/approve`,{method:`POST`,body:JSON.stringify({acknowledgeStale:t.acknowledgeStale,proposalUpdatedAt:t.proposalUpdatedAt})})).data}}catch(e){if(e instanceof lC){let t=e.body;if(e.status===409&&t?.data?.reason===`stale`){let e=t.data.staleReason;return{ok:!1,kind:`stale`,staleReason:pD.includes(e??``)?e:`lead_changed`}}return{ok:!1,kind:`error`,message:e.message}}throw e}}async function hD(e){try{return{ok:!0,already:(await H(`/api/copilot/proposals/${encodeURIComponent(e)}/reject`,{method:`POST`,body:`{}`})).data.already}}catch(e){if(e instanceof lC)return{ok:!1,message:e.message};throw e}}function gD(e,t){switch(t.type){case`submit`:return{phase:`working`,action:t.action};case`approveResult`:{let e=t.result;return e.ok?{phase:`approved`,appliedStatus:e.appliedStatus}:e.kind===`stale`?{phase:`stale`,reason:e.staleReason}:{phase:`error`,message:e.message}}case`rejectResult`:{let e=t.result;return e.ok?{phase:`rejected`}:{phase:`error`,message:e.message}}case`reset`:return{phase:`idle`};default:return e}}var _D={red:{border:`border-red-300 dark:border-red-800`,dot:`bg-red-500`,label:`Urgent`},yellow:{border:`border-amber-300 dark:border-amber-800`,dot:`bg-amber-500`,label:`Follow up`},green:{border:`border-border`,dot:`bg-green-500`,label:`FYI`}},vD={lead_changed:{title:`The lead changed since this was drafted`,body:`Someone edited this lead after the copilot wrote the summary. Approve anyway?`},card_redrafted:{title:`This summary was rewritten since you opened it`,body:`The copilot has re-drafted this card. Approving saves the newer summary, not the text shown here. Approve anyway?`},both:{title:`This summary was rewritten, and the lead changed`,body:`The copilot has re-drafted this card and the lead was edited since. Approving saves the newer summary, not the text shown here. Approve anyway?`}};function yD(e){return e.replace(/_/g,` `)}function bD(e){let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function xD({proposal:e}){let[t,n]=(0,_.useReducer)(gD,{phase:`idle`}),{resolutions:r,resolve:i,onSettled:a}=nD(),o=(0,_.useRef)(!1),s=(0,_.useRef)(null),c=(0,_.useRef)(null),l=(0,_.useRef)(null),u=(0,_.useRef)(null),d=(0,_.useRef)(!1),f=_D[e.tier]??_D.green,p=`${bD(e.windowStart)} - ${bD(e.windowEnd)}`,m=r[e.id]??(t.phase===`approved`?{kind:`approved`,appliedStatus:t.appliedStatus}:t.phase===`rejected`?{kind:`rejected`}:null),h=m!==null;(0,_.useEffect)(()=>{if(!h){t.phase===`stale`?c.current?.focus():t.phase===`error`&&s.current?.focus();return}d.current&&(d.current=!1,u.current?.focus())},[t.phase,h]);let g=()=>{d.current=l.current?.contains(document.activeElement)??!1},v=async t=>{if(!(o.current||m)){g(),o.current=!0,n({type:`submit`,action:`approve`});try{let r=await mD(e.id,{acknowledgeStale:t,proposalUpdatedAt:e.updatedAt});n({type:`approveResult`,result:r});let o=ZE(r);o&&i(e.id,o),a()}catch(e){z.error(e instanceof Error?e.message:`Could not approve`),n({type:`reset`})}finally{o.current=!1}}},y=async()=>{if(!(o.current||m)){g(),o.current=!0,n({type:`submit`,action:`reject`});try{let t=await hD(e.id);n({type:`rejectResult`,result:t});let r=QE(t);r&&i(e.id,r),a()}catch(e){z.error(e instanceof Error?e.message:`Could not reject`),n({type:`reset`})}finally{o.current=!1}}},b=t.phase===`working`&&!m,x=!m&&(t.phase===`idle`||t.phase===`error`||b);return(0,L.jsxs)(`div`,{ref:l,className:`mt-2 rounded-lg border ${f.border} bg-background p-3 text-sm`,children:[(0,L.jsxs)(`div`,{className:`mb-1 flex items-center justify-between gap-2`,children:[(0,L.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 font-medium text-foreground`,children:[(0,L.jsx)(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${f.dot}`,"aria-hidden":!0}),(0,L.jsx)(`span`,{className:`truncate`,children:e.leadName||`Unnamed lead`})]}),(0,L.jsx)(`span`,{className:`shrink-0 text-[11px] text-muted-foreground`,children:f.label})]}),e.flagReason&&(0,L.jsx)(`p`,{className:`mb-1.5 text-xs text-muted-foreground`,children:e.flagReason}),(0,L.jsx)(`p`,{className:`whitespace-pre-wrap rounded border bg-muted/40 px-2 py-1.5 text-foreground`,children:e.summary}),(0,L.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-muted-foreground`,children:[(0,L.jsx)(`span`,{children:p}),e.suggestedStatus&&(0,L.jsxs)(`span`,{children:[`Suggested status:`,` `,(0,L.jsx)(`span`,{className:`font-medium text-foreground`,children:yD(e.suggestedStatus)})]})]}),!m&&t.phase===`error`&&(0,L.jsx)(`p`,{role:`alert`,className:`mt-2 text-xs text-destructive`,children:t.message}),x&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:`mt-2 flex items-center gap-2`,children:[(0,L.jsxs)(W,{ref:s,size:`sm`,onClick:()=>void v(!1),disabled:b,children:[(0,L.jsx)(RC,{className:`h-3.5 w-3.5`}),`Approve`]}),(0,L.jsxs)(W,{size:`sm`,variant:`outline`,onClick:()=>void y(),disabled:b,children:[(0,L.jsx)(FT,{className:`h-3.5 w-3.5`}),`Reject`]})]}),(0,L.jsxs)(`p`,{className:`mt-1.5 text-[11px] text-muted-foreground`,children:[`Approving adds this summary as a dated note on the lead`,e.suggestedStatus?` and updates its status.`:`.`]})]}),!m&&t.phase===`stale`&&(0,L.jsxs)(`div`,{role:`alert`,className:`mt-2 rounded border border-amber-300 bg-amber-50 p-2 text-xs dar
64k:border-amber-800 dark:bg-amber-950/40`,children:[(0,L.jsxs)(`div`,{className:`mb-1.5 flex items-center gap-1.5 font-medium text-amber-900 dark:text-amber-200`,children:[(0,L.jsx)(xT,{className:`h-3.5 w-3.5`}),vD[t.reason].title]}),(0,L.jsx)(`p`,{className:`mb-2 text-amber-800 dark:text-amber-300/90`,children:vD[t.reason].body}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsxs)(W,{ref:c,size:`sm`,onClick:()=>void v(!0),children:[(0,L.jsx)(RC,{className:`h-3.5 w-3.5`}),`Approve anyway`]}),(0,L.jsx)(W,{size:`sm`,variant:`ghost`,onClick:()=>n({type:`reset`}),children:`Cancel`})]})]}),(0,L.jsxs)(`div`,{ref:u,tabIndex:-1,role:`status`,"aria-live":`polite`,className:`rounded-md outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50`,children:[b&&(0,L.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,L.jsx)(Ew,{className:`h-3.5 w-3.5 animate-spin`}),t.action===`approve`?`Approving...`:`Rejecting...`]}),m?.kind===`approved`&&(0,L.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5 text-xs font-medium text-green-700 dark:text-green-400`,children:[(0,L.jsx)(RC,{className:`h-3.5 w-3.5`}),`Approved`,m.appliedStatus?` - moved to ${yD(m.appliedStatus)}`:` - note added`]}),m?.kind===`rejected`&&(0,L.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,L.jsx)(FT,{className:`h-3.5 w-3.5`}),`Rejected`]}),m?.kind===`resolved`&&(0,L.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,L.jsx)(RC,{className:`h-3.5 w-3.5`}),`Already handled`]})]})]})}function SD({proposals:e}){return e.length===0?null:(0,L.jsx)(`div`,{className:`space-y-1`,children:e.map(e=>(0,L.jsx)(xD,{proposal:e},e.id))})}function CD({content:e,evidence:t,triage:n,proposals:r=[],streaming:i}){return(0,L.jsxs)(`div`,{className:`max-w-[90%] space-y-1 rounded-2xl bg-muted px-4 py-2 text-sm`,children:[(0,L.jsx)(`div`,{className:`whitespace-pre-wrap`,children:e||(i?(0,L.jsx)(Ew,{className:`h-4 w-4 animate-spin opacity-60`}):`â¦`)}),(0,L.jsx)(dD,{evidence:t}),n?.routeToEthan&&n.handoffDraft&&(0,L.jsx)(fD,{draft:n.handoffDraft}),(0,L.jsx)(SD,{proposals:r})]})}function wD({messages:e,live:t,streaming:n,resuming:r=!1,resumeFailed:i=!1}){let a=(0,_.useRef)(null);(0,_.useEffect)(()=>{a.current?.scrollIntoView({behavior:`smooth`})},[e,t,n]);let o=e.length===0&&!n&&!r&&!i;return(0,L.jsxs)(`div`,{className:`flex-1 space-y-4 overflow-y-auto p-4`,children:[r&&e.length===0&&(0,L.jsxs)(`div`,{className:`mt-12 flex items-center justify-center gap-2 text-xs text-muted-foreground`,children:[(0,L.jsx)(Ew,{className:`h-3.5 w-3.5 animate-spin`}),`Picking up where you left off...`]}),i&&!r&&(0,L.jsx)(`div`,{role:`status`,className:`mx-auto max-w-sm rounded border border-amber-300 bg-amber-50 px-3 py-2 text-center text-xs text-amber-900 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-200`,children:`Couldn't load your earlier messages just now. Nothing is lost - this chat carries on where it left off, and reopening the copilot tries again.`}),o&&(0,L.jsxs)(`div`,{className:`mx-auto mt-12 max-w-xs text-center text-muted-foreground`,children:[(0,L.jsx)($C,{className:`mx-auto mb-3 h-8 w-8 opacity-60`}),(0,L.jsx)(`p`,{className:`text-sm`,children:`Ask why a lead looks off, whether the AI handled something right, or if WhatsApp is sending. I read live data and show my working, and I can draft a lead note or status change - nothing is saved until you approve it, and I never message leads.`})]}),e.map(e=>e.role===`user`?(0,L.jsx)(`div`,{className:`flex justify-end`,children:(0,L.jsx)(`div`,{className:`max-w-[85%] whitespace-pre-wrap rounded-2xl bg-primary px-4 py-2 text-sm text-primary-foreground`,children:e.content})},e.id):(0,L.jsx)(`div`,{className:`flex justify-start`,children:(0,L.jsx)(CD,{content:e.content,evidence:e.evidence,triage:e.triage,proposals:e.proposals})},e.id)),n&&(0,L.jsx)(`div`,{className:`flex justify-start`,children:(0,L.jsx)(CD,{content:t.text,evidence:t.evidence,triage:t.triage,streaming:!0})}),(0,L.jsx)(`div`,{ref:a})]})}var TD=_.forwardRef(({className:e,...t},n)=>
64(0,L.jsx)(`textarea`,{className:V(`flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm`,e),ref:n,...t}));TD.displayName=`Textarea`;function ED({disabled:e,onSend:t}){let[n,r]=(0,_.useState)(``),i=()=>{let i=n.trim();!i||e||(t(i),r(``))};return(0,L.jsxs)(`div`,{className:`border-t p-3`,children:[(0,L.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,L.jsx)(TD,{value:n,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),i())},placeholder:`e.g. Why hasn't this lead been assigned?`,rows:2,className:`max-h-40 min-h-[44px] resize-none`}),(0,L.jsx)(W,{onClick:i,disabled:e||!n.trim(),size:`icon`,"aria-label":`Send message`,children:e?(0,L.jsx)(Ew,{className:`h-4 w-4 animate-spin`}):(0,L.jsx)(eT,{className:`h-4 w-4`})})]}),(0,L.jsxs)(`p`,{className:`mt-1 text-[11px] text-muted-foreground`,children:[`Enter to send · Shift+Enter for a new line`,(0,L.jsx)(`br`,{}),`I read live data and draft lead notes for you to approve. I never message leads or change anything on my own.`]})]})}function DD({activeSessionId:e,disabled:t,onSelect:n}){let[r,i]=(0,_.useState)({phase:`loading`});return(0,_.useEffect)(()=>{let e=!1;return UE().then(t=>{e||i({phase:`ready`,sessions:t})},()=>{e||i({phase:`error`})}),()=>{e=!0}},[]),(0,L.jsxs)(`div`,{className:`max-h-64 shrink-0 overflow-y-auto border-b bg-muted/30 py-1`,children:[r.phase===`loading`&&(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5 px-4 py-2 text-xs text-muted-foreground`,children:[(0,L.jsx)(Ew,{className:`h-3 w-3 animate-spin`}),`Loading past chats...`]}),r.phase===`error`&&(0,L.jsx)(`div`,{className:`px-4 py-2 text-xs text-muted-foreground`,children:`Could not load past chats.`}),r.phase===`ready`&&r.sessions.length===0&&(0,L.jsx)(`div`,{className:`px-4 py-2 text-xs text-muted-foreground`,children:`No past chats yet.`}),r.phase===`ready`&&r.sessions.map(r=>{let i=r.id===e;return(0,L.jsxs)(`button`,{type:`button`,disabled:t,onClick:()=>n(r.id),className:`flex w-full items-center gap-2 px-4 py-1.5 text-left text-xs transition-colors hover:bg-muted disabled:pointer-events-none disabled:opacity-50`,children:[i?(0,L.jsx)(RC,{className:`h-3 w-3 shrink-0 text-foreground`}):(0,L.jsx)(`span`,{className:`h-3 w-3 shrink-0`,"aria-hidden":!0}),(0,L.jsx)(`span`,{className:`truncate ${i?`font-medium text-foreground`:``}`,children:r.title}),(0,L.jsx)(`span`,{className:`ml-auto shrink-0 text-[11px] text-muted-foreground`,children:IE(r.updatedAt)??``})]},r.id)})]})}function OD({proposals:e,loading:t,error:n,total:r=0,truncated:i=!1,onRetry:a}){let{resolutions:o}=nD(),[s,c]=(0,_.useState)(!1);if(e.length===0&&!t&&!n)return null;let l=e.filter(e=>!o[e.id]).length,u=i?`${l} of ${r} pending lead-note proposals`:l>0?`${l} pending lead-note proposal${l===1?``:`s`}`:`All proposals handled`;return(0,L.jsxs)(`div`,{className:`shrink-0 border-b bg-amber-50/60 dark:bg-amber-950/20`,children:[e.length>0?(0,L.jsxs)(`button`,{type:`button`,onClick:()=>c(e=>!e),"aria-expanded":s,className:`flex w-full items-center gap-1.5 px-4 py-2 text-left text-xs font-medium text-amber-900 transition-colors hover:bg-amber-100/60 dark:text-amber-200 dark:hover:bg-amber-900/30`,children:[(0,L.jsx)(VC,{className:`h-3.5 w-3.5 shrink-0 transition-transform ${s?`rotate-90`:``}`}),(0,L.jsx)(bw,{className:`h-3.5 w-3.5 shrink-0`}),(0,L.jsx)(`span`,{className:`truncate`,children:u}),t&&(0,L.jsx)(Ew,{className:`ml-auto h-3 w-3 shrink-0 animate-spin opacity-70`})]}):(0,L.jsxs)(`div`,{className:`flex w-full items-center gap-1.5 px-4 py-2 text-xs font-medium text-amber-900 dark:text-amber-200`,children:[(0,L.jsx)(bw,{className:`h-3.5 w-3.5 shrink-0`}),(0,L.jsx)(`span`,{className:`truncate`,children:n?`Couldn't load pending proposals`:`Checking for pending proposals...`}),t&&!n&&(0,L.jsx)(Ew,{className:`ml-auto h-3 w-3 shrink-0 animate-spin opacity-70`})]}),n&&(0,L.jsxs)(`div`,{role:`status`,className:`flex items-center gap-2 px-4 pb-2 text-xs text-amber-900 dark:text-amber-200`,children:[(0,L.jsx)(xT,{className:`h-3.5 w-3.5 shrink-0`}),(0,L.jsx)(`span`,{className:`min-w-0 flex-1`,children:e.length>0?`Couldn't refresh - this list may be out of date.`:`Something went wrong on our side. There may still be proposals waiting.`}),a&&(0,L.jsx)(W,{size:`sm`,variant:`outline`,className:`h-6 shrink-0 px-2 text-xs`,onClick:a,disabled:t,children:`Retry`})]}),s&&e.length>0&&(0,L.jsx)(`div`,{className:`max-h-[min(18rem,35vh)] overflow-y-auto px-4 pb-3`,children:(0,L.jsx)(SD,{proposals:e})})]})}function kD(){let[e,t]=(0,_.useState)(!1),[n,r]=(0,_.useState)(!1),[i,a]=(0,_.useState)(!1),o=Ze(),{messages:s,streaming:c,resuming:l,resumeFailed:u,live:d,sessionId:f,
64send:p,reset:m,resume:h,openSession:g,pending:v,resolutionStore:y}=rD(),b=(0,_.useMemo)(()=>NE(o.pathname,o.search),[o.pathname,o.search]);(0,_.useEffect)(()=>{H(`/api/copilot/enabled`).then(e=>t(e.data.enabled)).catch(()=>t(!1))},[]);let[x,S]=(0,_.useState)(null);(0,_.useEffect)(()=>{let e=!1;return(async()=>{if(!b.leadId)return null;try{return(await H(`/api/leads/${b.leadId}`)).data}catch{return null}})().then(t=>{e||S(t)}),()=>{e=!0}},[b.leadId]),ME((0,_.useMemo)(()=>[{keys:`mod+j`,allowInInputs:!0,description:`Open the copilot`,handler:t=>{t.preventDefault(),e&&r(e=>!e)}},{keys:`Escape`,handler:()=>r(!1)}],[e]),e);let C=(0,_.useCallback)(e=>void p(e,b),[p,b]),{refresh:w}=v;(0,_.useEffect)(()=>{!e||!n||(h(),w())},[e,n,h,w]);let T=(0,_.useCallback)(()=>void w(),[w]),E=(0,_.useCallback)(e=>{a(!1),g(e)},[g]),D=(0,_.useCallback)(()=>{a(!1),m()},[m]);return e?(0,L.jsxs)(L.Fragment,{children:[!n&&(0,L.jsxs)(W,{onClick:()=>r(!0),size:`sm`,variant:`outline`,className:`fixed bottom-4 right-4 z-[60] gap-1.5 shadow-md`,"aria-label":`Open copilot`,children:[(0,L.jsx)(lT,{className:`h-4 w-4`}),`Copilot`]}),(0,L.jsxs)(`aside`,{className:`fixed inset-y-0 right-0 z-[60] flex w-full max-w-md flex-col border-l bg-background shadow-xl transition-transform duration-200 ${n?`translate-x-0`:`pointer-events-none translate-x-full`}`,"aria-hidden":!n,children:[(0,L.jsxs)(`header`,{className:`flex h-14 shrink-0 items-center justify-between border-b px-4`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 font-medium`,children:[(0,L.jsx)(lT,{className:`h-4 w-4`}),`Copilot`]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(W,{variant:`ghost`,size:`icon`,onClick:()=>a(e=>!e),disabled:c,"aria-label":`Past chats`,"aria-expanded":i,children:(0,L.jsx)(vw,{className:`h-4 w-4`})}),(s.length>0||f!==null)&&(0,L.jsx)(W,{variant:`ghost`,size:`sm`,onClick:D,disabled:c,children:`New`}),(0,L.jsx)(W,{variant:`ghost`,size:`icon`,onClick:()=>r(!1),"aria-label":`Close copilot`,children:(0,L.jsx)(FT,{className:`h-4 w-4`})})]})]}),i&&(0,L.jsx)(DD,{activeSessionId:f,disabled:c||l,onSelect:E}),(0,L.jsx)(iD,{ctx:b,lead:x}),(0,L.jsxs)(tD.Provider,{value:y,children:[(0,L.jsx)(OD,{proposals:v.proposals,loading:v.loading,error:v.error,total:v.total,truncated:v.truncated,onRetry:T}),(0,L.jsx)(wD,{messages:s,live:d,streaming:c,resuming:l,resumeFailed:u})]}),s.length===0&&!c&&!l&&(0,L.jsx)(aD,{lead:x,disabled:c,onPick:C}),(0,L.jsx)(ED,{disabled:c||l,onSend:C})]})]}):null}function AD(){return(0,L.jsxs)(fE,{children:[(0,L.jsx)(OE,{className:`print:hidden`}),(0,L.jsxs)(gE,{children:[(0,L.jsx)(`header`,{className:`flex h-14 shrink-0 items-center gap-2 border-b px-4 print:hidden`,children:(0,L.jsx)(mE,{className:`-ml-1`})}),(0,L.jsx)(`main`,{className:`flex-1 p-6 print:p-0`,children:(0,L.jsx)(Ot,{})})]}),(0,L.jsx)(kD,{})]})}var jD=new ei({defaultOptions:{queries:{staleTime:10*1e3,retry:1}}});function K({className:e,...t}){return(0,L.jsx)(`div`,{"data-slot":`card`,className:V(`flex flex-col gap-6 rounded-xl border bg-card py-6 text-card-foreground shadow-sm`,e),...t})}function MD({className:e,...t}){return(0,L.jsx)(`div`,{"data-slot":`card-header`,className:V(`@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6`,e),...t})}function ND({className:e,...t}){return(0,L.jsx)(`div`,{"data-slot":`card-title`,className:V(`leading-none font-semibold`,e),...t})}function PD({className:e,...t}){return(0,L.jsx)(`div`,{"data-slot":`card-description`,className:V(`text-sm text-muted-foreground`,e),...t})}function q({className:e,...t}){return(0,L.jsx)(`div`,{"data-slot":`card-content`,className:V(`px-6`,e),...t})}function FD(){let[e,t]=(0,_.useState)(``),[n,r]=(0,_.useState)(!1);async function i(){t(``),r(!0);try{await uC.signIn.social({provider:`google`,callbackURL:window.location.origin+`/`})}catch{t(`Something went wrong`),r(!1)}}return(0,L.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-background p-4`,children:(0,L.jsxs)(K,{className:`w-full max-w-sm`,children:[(0,L.jsxs)(MD,{className:`text-center`,children:[(0,L.jsx)(ND,{className:`text-xl`,children:`StackedHomes`}),(0,L.jsx)(PD,{children:`Sign in to the dashboard`})]}),(0,L.jsxs)(q,{className:`space-y-4`,children:[e&&(0,L.jsx)(`p`,{className:`text-sm text-destructive text-center`,children:e}),(0,L.jsxs)(W,{variant:`outline`,className:`w-full`,onClick:i,disabled:n,children:[(0,L.jsxs)(`svg`,{className:`mr-2 h-4 w-4`,viewBox:`0 0 24 24`,children:[(0,L.jsx)(`path`,{d:`M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 0 1-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1z`,fill:`#4285F4`}),(0,L.jsx)(`path`,{d:`M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z`,fill:`#34A853`}),(0,L.jsx)(`path`,{d:`M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z`,fill:`#FBBC05`}),(0,L.jsx)(`path`,{d:`M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z`,fill:`#EA4335`})]}),n?`Signing in...`:`Sign in with Google`]}),!1]})]})})}function ID(e,t){return typeof e==`function`?e(t):e}function LD(e,t){return n=>{t.setState(t=>({...t,[e]:ID(n,t[e])}))}}function RD(e){return e instanceof Function}function zD(e){return Array.isArray(e)&&e.every(e=>typeof e==`number`)}function BD(e,t){let n=[],r=e=>
vendor: 42,274 bytes, lines 64-67
64{e.forEach(e=>{n.push(e);let i=t(e);i!=null&&i.length&&r(i)})};return r(e),n}function VD(e,t,n){let r=[],i;return a=>{let o;n.key&&n.debug&&(o=Date.now());let s=e(a);if(!(s.length!==r.length||s.some((e,t)=>r[t]!==e)))return i;r=s;let c;if(n.key&&n.debug&&(c=Date.now()),i=t(...s),n==null||n.onChange==null||n.onChange(i),n.key&&n.debug&&n!=null&&n.debug()){let e=Math.round((Date.now()-o)*100)/100,t=Math.round((Date.now()-c)*100)/100,r=t/16,i=(e,t)=>{for(e=String(e);e.length<t;)e=` `+e;return e};console.info(`%câ± ${i(t,5)} /${i(e,5)} ms`,` 65 font-size: .6rem; 66 font-weight: bold; 67 color: hsl(${Math.max(0,Math.min(120-120*r,120))}deg 100% 31%);`,n?.key)}return i}}function HD(e,t,n,r){return{debug:()=>e?.debugAll??e[t],key:!1,onChange:r}}function UD(e,t,n,r){let i={id:`${t.id}_${n.id}`,row:t,column:n,getValue:()=>t.getValue(r),renderValue:()=>i.getValue()??e.options.renderFallbackValue,getContext:VD(()=>[e,n,t,i],(e,t,n,r)=>({table:e,column:t,row:n,cell:r,getValue:r.getValue,renderValue:r.renderValue}),HD(e.options,`debugCells`,`cell.getContext`))};return e._features.forEach(r=>{r.createCell==null||r.createCell(i,n,t,e)},{}),i}function WD(e,t,n,r){let i={...e._getDefaultColumnDef(),...t},a=i.accessorKey,o=i.id??(a?typeof String.prototype.replaceAll==`function`?a.replaceAll(`.`,`_`):a.replace(/\./g,`_`):void 0)??(typeof i.header==`string`?i.header:void 0),s;if(i.accessorFn?s=i.accessorFn:a&&(s=a.includes(`.`)?e=>{let t=e;for(let e of a.split(`.`))t=t?.[e];return t}:e=>e[i.accessorKey]),!o)throw Error();let c={id:`${String(o)}`,accessorFn:s,parent:r,depth:n,columnDef:i,columns:[],getFlatColumns:VD(()=>[!0],()=>[c,...c.columns?.flatMap(e=>e.getFlatColumns())],HD(e.options,`debugColumns`,`column.getFlatColumns`)),getLeafColumns:VD(()=>[e._getOrderColumnsFn()],e=>{var t;return(t=c.columns)!=null&&t.length?e(c.columns.flatMap(e=>e.getLeafColumns())):[c]},HD(e.options,`debugColumns`,`column.getLeafColumns`))};for(let t of e._features)t.createColumn==null||t.createColumn(c,e);return c}var GD=`debugHeaders`;function KD(e,t,n){let r={id:n.id??t.id,column:t,index:n.index,isPlaceholder:!!n.isPlaceholder,placeholderId:n.placeholderId,depth:n.depth,subHeaders:[],colSpan:0,rowSpan:0,headerGroup:null,getLeafHeaders:()=>{let e=[],t=n=>{n.subHeaders&&n.subHeaders.length&&n.subHeaders.map(t),e.push(n)};return t(r),e},getContext:()=>({table:e,header:r,column:t})};return e._features.forEach(t=>{t.createHeader==null||t.createHeader(r,e)}),r}var qD={createTable:e=>{e.getHeaderGroups=VD(()=>[e.getAllColumns(),e.getVisibleLeafColumns(),e.getState().columnPinning.left,e.getState().columnPinning.right],(t,n,r,i)=>{let a=r?.map(e=>n.find(t=>t.id===e)).filter(Boolean)??[],o=i?.map(e=>n.find(t=>t.id===e)).filter(Boolean)??[],s=n.filter(e=>!(r!=null&&r.includes(e.id))&&!(i!=null&&i.includes(e.id)));return JD(t,[...a,...s,...o],e)},HD(e.options,GD,`getHeaderGroups`)),e.getCenterHeaderGroups=VD(()=>[e.getAllColumns(),e.getVisibleLeafColumns(),e.getState().columnPinning.left,e.getState().columnPinning.right],(t,n,r,i)=>(n=n.filter(e=>!(r!=null&&r.includes(e.id))&&!(i!=null&&i.includes(e.id))),JD(t,n,e,`center`)),HD(e.options,GD,`getCenterHeaderGroups`)),e.getLeftHeaderGroups=VD(()=>[e.getAllColumns(),e.getVisibleLeafColumns(),e.getState().columnPinning.left],(t,n,r)=>JD(t,r?.map(e=>n.find(t=>t.id===e)).filter(Boolean)??[],e,`left`),HD(e.options,GD,`getLeftHeaderGroups`)),e.getRightHeaderGroups=VD(()=>[e.getAllColumns(),e.getVisibleLeafColumns(),e.getState().columnPinning.right],(t,n,r)=>JD(t,r?.map(e=>n.find(t=>t.id===e)).filter(Boolean)??[],e,`right`),HD(e.options,GD,`getRightHeaderGroups`)),e.getFooterGroups=VD(()=>[e.getHeaderGroups()],e=>[...e].reverse(),HD(e.options,GD,`getFooterGroups`)),e.getLeftFooterGroups=VD(()=>[e.getLeftHeaderGroups()],e=>[...e].reverse(),HD(e.options,GD,`getLeftFooterGroups`)),e.getCenterFooterGroups=VD(()=>[e.getCenterHeaderGroups()],e=>[...e].reverse(),HD(e.options,GD,`getCenterFooterGroups`)),e.getRightFooterGroups=VD(()=>[e.getRightHeaderGroups()],e=>[...e].reverse(),HD(e.options,GD,`getRightFooterGroups`)),e.getFlatHeaders=VD(()=>[e.getHeaderGroups()],e=>e.map(e=>e.headers).flat(),HD(e.options,GD,`getFlatHeaders`)),e.getLeftFlatHeaders=VD(()=>[e.getLeftHeaderGroups()],e=>e.map(e=>e.headers).flat(),HD(e.options,GD,`getLeftFlatHeaders`)),e.getCenterFlatHeaders=VD(()=>[e.getCenterHeaderGroups()],e=>e.map(e=>e.headers).flat(),HD(e.options,GD,`getCenterFlatHeaders`)),e.getRightFlatHeaders=VD(()=>[e.getRightHeaderGroups()],e=>e.map(e=>e.headers).flat(),HD(e.options,GD,`getRightFlatHeaders`)),e.getCenterLeafHeaders=VD(()=>[e.getCenterFlatHeaders()],e=>e.filter(e=>{var t;return!((t=e.subHeaders)!=null&&t.length)}),HD(e.options,GD,`getCenterLeafHeaders`)),e.getLeftLeafHeaders=VD(()=>[e.getLeftFlatHeaders()],e=>e.filter(e=>{var t;return!((t=e.subHeaders)!=null&&t.length)}),HD(e.options,GD,`getLeftLeafHeaders`)),e.getRightLeafHeaders=VD(()=>[e.getRightFlatHeaders()],e=>e.filter(e=>{var t;return!((t=e.subHeaders)!=null&&t.length)}),HD(e.options,GD,`getRightLeafHeaders`)),e.getLeafHeaders=VD(()=>[e.getLeftHeaderGroups(),e.getCenterHeaderGroups(),e.getRightHeaderGroups()],(e,t,n)=>[...e[0]?.headers??[],...t[0]?.headers??[],...n[0]?.headers??[]].map(e=>e.getLeafHeaders()).flat(),HD(e.options,GD,`getLeafHeaders`))}};function JD(e,t,n,r){let i=0,a=function(e,t){t===void 0&&(t=1),i=Math.max(i,t),e.filter(e=>e.getIsVisible()).forEach(e=>{var n;(n=e.columns)!=null&&n.length&&a(e.columns,t+1)},0)};a(e);let o=[],s=(e,t)=>{let i={depth:t,id:[r,`${t}`].filter(Boolean).join(`_`),headers:[]},a=[];e.forEach(e=>{let o=[...a].reverse()[0],s=e.column.depth===i.depth,c,l=!1;if(s&&e.column.parent?c=e.column.parent:(c=e.column,l=!0),o&&o?.column===c)o.subHeaders.push(e);else{let i=KD(n,c,{id:[r,t,c.id,e?.id].filter(Boolean).join(`_`),isPlaceholder:l,placeholderId:l?`${a.filter(e=>e.column===c).length}`:void 0,depth:t,index:a.length});i.subHeaders.push(e),a.push(i)}i.headers.push(e),e.headerGroup=i}),o.push(i),t>0&&s(a,t-1)};s(t.map((e,t)=>KD(n,e,{depth:i,index:t})),i-1),o.reverse();let c=e=>e.filter(e=>e.column.getIsVisible()).map(e=>{let t=0,n=0,r=[0];e.subHeaders&&e.subHeaders.length?(r=[],c(e.subHeaders).forEach(e=>{let{colSpan:n,rowSpan:i}=e;t+=n,r.push(i)})):t=1;let i=Math.min(...r);return n+=i,e.colSpan=t,e.rowSpan=n,{colSpan:t,rowSpan:n}});return c(o[0]?.headers??[]),o}var YD=(e,t,n,r,i,a,o)=>{let s={id:t,index:r,original:n,depth:i,parentId:o,_valuesCache:{},_uniqueValuesCache:{},getValue:t=>{if(s._valuesCache.hasOwnProperty(t))return s._valuesCache[t];let n=e.getColumn(t);if(n!=null&&n.accessorFn)return s._valuesCache[t]=n.accessorFn(s.original,r),s._valuesCache[t]},getUniqueValues:t=>{if(s._uniqueValuesCache.hasOwnProperty(t))return s._uniqueValuesCache[t];let n=e.getColumn(t);if(n!=null&&n.accessorFn)return n.columnDef.getUniqueValues?(s._uniqueValuesCache[t]=n.columnDef.getUniqueValues(s.original,r),s._uniqueValuesCache[t]):(s._uniqueValuesCache[t]=[s.getValue(t)],s._uniqueValuesCache[t])},renderValue:t=>s.getValue(t)??e.options.renderFallbackValue,subRows:a??[],getLeafRows:()=>BD(s.subRows,e=>e.subRows),getParentRow:()=>s.parentId?e.getRow(s.parentId,!0):void 0,getParentRows:()=>{let e=[],t=s;for(;;){let n=t.getParentRow();if(!n)break;e.push(n),t=n}return e.reverse()},getAllCells:VD(()=>[e.getAllLeafColumns()],t=>t.map(t=>UD(e,s,t,t.id)),HD(e.options,`debugRows`,`getAllCells`)),_getAllCellsByColumnId:VD(()=>[s.getAllCells()],e=>e.reduce((e,t)=>(e[t.column.id]=t,e),{}),HD(e.options,`debugRows`,`getAllCellsByColumnId`))};for(let t=0;t<e._features.length;t++){let n=e._features[t];n==null||n.createRow==null||n.createRow(s,e)}return s},XD={createColumn:(e,t)=>{e._getFacetedRowModel=t.options.getFacetedRowModel&&t.options.getFacetedRowModel(t,e.id),e.getFacetedRowModel=()=>e._getFacetedRowModel?e._getFacetedRowModel():t.getPreFilteredRowModel(),e._getFacetedUniqueValues=t.options.getFacetedUniqueValues&&t.options.getFacetedUniqueValues(t,e.id),e.getFacetedUniqueValues=()=>e._getFacetedUniqueValues?e._getFacetedUniqueValues():new Map,e._getFacetedMinMaxValues=t.options.getFacetedMinMaxValues&&t.options.getFacetedMinMaxValues(t,e.id),e.getFacetedMinMaxValues=()=>{if(e._getFacetedMinMaxValues)return e._getFacetedMinMaxValues()}}},ZD=(e,t,n)=>{var r,i;let a=n==null||(r=n.toString())==null?void 0:r.toLowerCase();return!!(!((i=e.getValue(t))==null||(i=i.toString())==null||(i=i.toLowerCase())==null)&&i.includes(a))};ZD.autoRemove=e=>sO(e);var QD=(e,t,n)=>{var r;return!!(!((r=e.getValue(t))==null||(r=r.toString())==null)&&r.includes(n))};QD.autoRemove=e=>sO(e);var $D=(e,t,n)=>{var r;return((r=e.getValue(t))==null||(r=r.toString())==null?void 0:r.toLowerCase())===n?.toLowerCase()};$D.autoRemove=e=>sO(e);var eO=(e,t,n)=>e.getValue(t)?.includes(n);eO.autoRemove=e=>sO(e);var tO=(e,t,n)=>!n.some(n=>{var r;return!((r=e.getValue(t))!=null&&r.includes(n))});tO.autoRemove=e=>sO(e)||!(e!=null&&e.length);var nO=(e,t,n)=>n.some(n=>e.getValue(t)?.includes(n));nO.autoRemove=e=>sO(e)||!(e!=null&&e.length);var rO=(e,t,n)=>e.getValue(t)===n;rO.autoRemove=e=>sO(e);var iO=(e,t,n)=>e.getValue(t)==n;iO.autoRemove=e=>sO(e);var aO=(e,t,n)=>{let[r,i]=n,a=e.getValue(t);return a>=r&&a<=i};aO.resolveFilterValue=e=>{let[t,n]=e,r=typeof t==`number`?t:parseFloat(t),i=typeof n==`number`?n:parseFloat(n),a=t===null||Number.isNaN(r)?-1/0:r,o=n===null||Number.isNaN(i)?1/0:i;if(a>o){let e=a;a=o,o=e}return[a,o]},aO.autoRemove=e=>sO(e)||sO(e[0])&&sO(e[1]);var oO={includesString:ZD,includesStringSensitive:QD,equalsString:$D,arrIncludes:eO,arrIncludesAll:tO,arrIncludesSome:nO,equals:rO,weakEquals:iO,inNumberRange:aO};function sO(e){return e==null||e===``}var cO={getDefaultColumnDef:()=>({filterFn:`auto`}),getInitialState:e=>({columnFilters:[],...e}),getDefaultOptions:e=>({onColumnFiltersChange:LD(`columnFilters`,e),filterFromLeafRows:!1,maxLeafRowFilterDepth:100}),createColumn:(e,t)=>{e.getAutoFilterFn=()=>{let n=t.getCoreRowModel().flatRows[0]?.getValue(e.id);return typeof n==`string`?oO.includesString:typeof n==`number`?oO.inNumberRange:typeof n==`boolean`||typeof n==`object`&&n?oO.equals:Array.isArray(n)?oO.arrIncludes:oO.weakEquals},e.getFilterFn=()=>RD(e.columnDef.filterFn)?e.columnDef.filterFn:e.columnDef.filterFn===`auto`?e.getAutoFilterFn():t.options.filterFns?.[e.columnDef.filterFn]??oO[e.columnDef.filterFn],e.getCanFilter=()=>(e.columnDef.enableColumnFilter??!0)&&(t.options.enableColumnFilters??!0)&&(t.options.enableFilters??!0)&&!!e.accessorFn,e.getIsFiltered=()=>e.getFilterIndex()>-1,e.getFilterValue=()=>{var n;return(n=t.getState().columnFilters)==null||(n=n.find(t=>t.id===e.id))==null?void 0:n.value},e.getFilterIndex=()=>t.getState().columnFilters?.findIndex(t=>t.id===e.id)??-1,e.setFilterValue=n=>{t.setColumnFilters(t=>{let r=e.getFilterFn(),i=t?.find(t=>t.id===e.id),a=ID(n,i?i.value:void 0);if(lO(r,a,e))return t?.filter(t=>t.id!==e.id)??[];let o={id:e.id,value:a};return i?t?.map(t=>t.id===e.id?o:t)??[]:t!=null&&t.length?[...t,o]:[o]})}},createRow:(e,t)=>{e.columnFilters={},e.columnFiltersMeta={}},createTable:e=>{e.setColumnFilters=t=>{let n=e.getAllLeafColumns();e.options.onColumnFiltersChange==null||e.options.onColumnFiltersChange(e=>ID(t,e)?.filter(e=>{let t=n.find(t=>t.id===e.id);return!(t&&lO(t.getFilterFn(),e.value,t))}))},e.resetColumnFilters=t=>{e.setColumnFilters(t?[]:e.initialState?.columnFilters??[])},e.getPreFilteredRowModel=()=>e.getCoreRowModel(),e.getFilteredRowModel=()=>(!e._getFilteredRowModel&&e.options.getFilteredRowModel&&(e._getFilteredRowModel=e.options.getFilteredRowModel(e)),e.options.manualFiltering||!e._getFilteredRowModel?e.getPreFilteredRowModel():e._getFilteredRowModel())}};function lO(e,t,n){return(e&&e.autoRemove?e.autoRemove(t,n):!1)||t===void 0||typeof t==`string`&&!t}var uO={sum:(e,t,n)=>n.reduce((t,n)=>{let r=n.getValue(e);return t+(typeof r==`number`?r:0)},0),min:(e,t,n)=>{let r;return n.forEach(t=>{let n=t.getValue(e);n!=null&&(r>n||r===void 0&&n>=n)&&(r=n)}),r},max:(e,t,n)=>{let r;return n.forEach(t=>{let n=t.getValue(e);n!=null&&(r<n||r===void 0&&n>=n)&&(r=n)}),r},extent:(e,t,n)=>{let r,i;return n.forEach(t=>{let n=t.getValue(e);n!=null&&(r===void 0?n>=n&&(r=i=n):(r>n&&(r=n),i<n&&(i=n)))}),[r,i]},mean:(e,t)=>{let n=0,r=0;if(t.forEach(t=>{let i=t.getValue(e);i!=null&&(i=+i)>=i&&(++n,r+=i)}),n)return r/n},median:(e,t)=>{if(!t.length)return;let n=t.map(t=>t.getValue(e));if(!zD(n))return;if(n.length===1)return n[0];let r=Math.floor(n.length/2),i=n.sort((e,t)=>e-t);return n.length%2==0?(i[r-1]+i[r])/2:i[r]},unique:(e,t)=>Array.from(new Set(t.map(t=>t.getValue(e))).values()),uniqueCount:(e,t)=>new Set(t.map(t=>t.getValue(e))).size,count:(e,t)=>t.length},dO={getDefaultColumnDef:()=>({aggregatedCell:e=>{var t;return((t=e.getValue())==null||t.toString==null?void 0:t.toString())??null},aggregationFn:`auto`}),getInitialState:e=>({grouping:[],...e}),getDefaultOptions:e=>({onGroupingChange:LD(`grouping`,e),groupedColumnMode:`reorder`}),createColumn:(e,t)=>{e.toggleGrouping=()=>{t.setGrouping(t=>t!=null&&t.includes(e.id)?t.filter(t=>t!==e.id):[...t??[],e.id])},e.getCanGroup=()=>(e.columnDef.enableGrouping??!0)&&(t.options.enableGrouping??!0)&&(!!e.accessorFn||!!e.columnDef.getGroupingValue),e.getIsGrouped=()=>t.getState().grouping?.includes(e.id),e.getGroupedIndex=()=>t.getState().grouping?.indexOf(e.id),e.getToggleGroupingHandler=()=>{let t=e.getCanGroup();return()=>{t&&e.toggleGrouping()}},e.getAutoAggregationFn=()=>{let n=t.getCoreRowModel().flatRows[0]?.getValue(e.id);if(typeof n==`number`)return uO.sum;if(Object.prototype.toString.call(n)===`[object Date]`)return uO.extent},e.getAggregationFn=()=>{if(!e)throw Error();return RD(e.columnDef.aggregationFn)?e.columnDef.aggregationFn:e.columnDef.aggregationFn===`auto`?e.getAutoAggregationFn():t.options.aggregationFns?.[e.columnDef.aggregationFn]??uO[e.columnDef.aggregationFn]}},createTable:e=>{e.setGrouping=t=>e.options.onGroupingChange==null?void 0:e.options.onGroupingChange(t),e.resetGrouping=t=>{e.setGrouping(t?[]:e.initialState?.grouping??[])},e.getPreGroupedRowModel=()=>e.getFilteredRowModel(),e.getGroupedRowModel=()=>(!e._getGroupedRowModel&&e.options.getGroupedRowModel&&(e._getGroupedRowModel=e.options.getGroupedRowModel(e)),e.options.manualGrouping||!e._getGroupedRowModel?e.getPreGroupedRowModel():e._getGroupedRowModel())},createRow:(e,t)=>{e.getIsGrouped=()=>!!e.groupingColumnId,e.getGroupingValue=n=>{if(e._groupingValuesCache.hasOwnProperty(n))return e._groupingValuesCache[n];let r=t.getColumn(n);return r!=null&&r.columnDef.getGroupingValue?(e._groupingValuesCache[n]=r.columnDef.getGroupingValue(e.original),e._groupingValuesCache[n]):e.getValue(n)},e._groupingValuesCache={}},createCell:(e,t,n,r)=>{e.getIsGrouped=()=>t.getIsGrouped()&&t.id===n.groupingColumnId,e.getIsPlaceholder=()=>!e.getIsGrouped()&&t.getIsGrouped(),e.getIsAggregated=()=>{var t;return!e.getIsGrouped()&&!e.getIsPlaceholder()&&!!((t=n.subRows)!=null&&t.length)}}};function fO(e,t,n){if(!(t!=null&&t.length)||!n)return e;let r=e.filter(e=>!t.includes(e.id));return n===`remove`?r:[...t.map(t=>e.find(e=>e.id===t)).filter(Boolean),...r]}var pO={getInitialState:e=>({columnOrder:[],...e}),getDefaultOptions:e=>({onColumnOrderChange:LD(`columnOrder`,e)}),createColumn:(e,t)=>{e.getIndex=VD(e=>[wO(t,e)],t=>t.findIndex(t=>t.id===e.id),HD(t.options,`debugColumns`,`getIndex`)),e.getIsFirstColumn=n=>wO(t,n)[0]?.id===e.id,e.getIsLastColumn=n=>{let r=wO(t,n);return r[r.length-1]?.id===e.id}},createTable:e=>{e.setColumnOrder=t=>e.options.onColumnOrderChange==null?void 0:e.options.onColumnOrderChange(t),e.resetColumnOrder=t=>{e.setColumnOrder(t?[]:e.initialState.columnOrder??[])},e._getOrderColumnsFn=VD(()=>[e.getState().columnOrder,e.getState().grouping,e.options.groupedColumnMode],(e,t,n)=>r=>{let i=[];if(!(e!=null&&e.length))i=r;else{let t=[...e],n=[...r];for(;n.length&&t.length;){let e=t.shift(),r=n.findIndex(t=>t.id===e);r>-1&&i.push(n.splice(r,1)[0])}i=[...i,...n]}return fO(i,t,n)},HD(e.options,`debugTable`,`_getOrderColumnsFn`))}},mO=()=>({left:[],right:[]}),hO={getInitialState:e=>({columnPinning:mO(),...e}),getDefaultOptions:e=>({onColumnPinningChange:LD(`columnPinning`,e)}),createColumn:(e,t)=>{e.pin=n=>{let r=e.getLeafColumns().map(e=>e.id).filter(Boolean);t.setColumnPinning(e=>n===`right`?{left:(e?.left??[]).filter(e=>!(r!=null&&r.includes(e))),right:[...(e?.right??[]).filter(e=>!(r!=null&&r.includes(e))),...r]}:n===`left`?{left:[...(e?.left??[]).filter(e=>!(r!=null&&r.includes(e))),...r],right:(e?.right??[]).filter(e=>!(r!=null&&r.includes(e)))}:{left:(e?.left??[]).filter(e=>!(r!=null&&r.includes(e))),right:(e?.right??[]).filter(e=>!(r!=null&&r.includes(e)))})},e.getCanPin=()=>e.getLeafColumns().some(e=>(e.columnDef.enablePinning??!0)&&(t.options.enableColumnPinning??t.options.enablePinning??!0)),e.getIsPinned=()=>{let n=e.getLeafColumns().map(e=>e.id),{left:r,right:i}=t.getState().columnPinning,a=n.some(e=>r?.includes(e)),o=n.some(e=>i?.includes(e));return a?`left`:o?`right`:!1},e.getPinnedIndex=()=>{var n;let r=e.getIsPinned();return r?((n=t.getState().columnPinning)==null||(n=n[r])==null?void 0:n.indexOf(e.id))??-1:0}},createRow:(e,t)=>{e.getCenterVisibleCells=VD(()=>[e._getAllVisibleCells(),t.getState().columnPinning.left,t.getState().columnPinning.right],(e,t,n)=>{let r=[...t??[],...n??[]];return e.filter(e=>!r.includes(e.column.id))},HD(t.options,`debugRows`,`getCenterVisibleCells`)),e.getLeftVisibleCells=VD(()=>[e._getAllVisibleCells(),t.getState().columnPinning.left],(e,t)=>(t??[]).map(t=>e.find(e=>e.column.id===t)).filter(Boolean).map(e=>({...e,position:`left`})),HD(t.options,`debugRows`,`getLeftVisibleCells`)),e.getRightVisibleCells=VD(()=>[e._getAllVisibleCells(),t.getState().columnPinning.right],(e,t)=>(t??[]).map(t=>e.find(e=>e.column.id===t)).filter(Boolean).map(e=>({...e,position:`right`})),HD(t.options,`debugRows`,`getRightVisibleCells`))},createTable:e=>{e.setColumnPinning=t=>e.options.onColumnPinningChange==null?void 0:e.options.onColumnPinningChange(t),e.resetColumnPinning=t=>e.setColumnPinning(t?mO():e.initialState?.columnPinning??mO()),e.getIsSomeColumnsPinned=t=>{let n=e.getState().columnPinning;return t?!!n[t]?.length:!!(n.left?.length||n.right?.length)},e.getLeftLeafColumns=VD(()=>[e.getAllLeafColumns(),e.getState().columnPinning.left],(e,t)=>(t??[]).map(t=>e.find(e=>e.id===t)).filter(Boolean),HD(e.options,`debugColumns`,`getLeftLeafColumns`)),e.getRightLeafColumns=VD(()=>[e.getAllLeafColumns(),e.getState().columnPinning.right],(e,t)=>(t??[]).map(t=>e.find(e=>e.id===t)).filter(Boolean),HD(e.options,`debugColumns`,`getRightLeafColumns`)),e.getCenterLeafColumns=VD(()=>[e.getAllLeafColumns(),e.getState().columnPinning.left,e.getState().columnPinning.right],(e,t,n)=>{let r=[...t??[],...n??[]];return e.filter(e=>!r.includes(e.id))},HD(e.options,`debugColumns`,`getCenterLeafColumns`))}};function gO(e){return e||(typeof document<`u`?document:null)}var _O={size:150,minSize:20,maxSize:2**53-1},vO=()=>({startOffset:null,startSize:null,deltaOffset:null,deltaPercentage:null,isResizingColumn:!1,columnSizingStart:[]}),yO={getDefaultColumnDef:()=>_O,getInitialState:e=>({columnSizing:{},columnSizingInfo:vO(),...e}),getDefaultOptions:e=>({columnResizeMode:`onEnd`,columnResizeDirection:`ltr`,onColumnSizingChange:LD(`columnSizing`,e),onColumnSizingInfoChange:LD(`columnSizingInfo`,e)}),createColumn:(e,t)=>{e.getSize=()=>{let n=t.getState().columnSizing[e.id];return Math.min(Math.max(e.columnDef.minSize??_O.minSize,n??e.columnDef.size??_O.size),e.columnDef.maxSize??_O.maxSize)},e.getStart=VD(e=>[e,wO(t,e),t.getState().columnSizing],(t,n)=>n.slice(0,e.getIndex(t)).reduce((e,t)=>e+t.getSize(),0),HD(t.options,`debugColumns`,`getStart`)),e.getAfter=VD(e=>[e,wO(t,e),t.getState().columnSizing],(t,n)=>n.slice(e.getIndex(t)+1).reduce((e,t)=>e+t.getSize(),0),HD(t.options,`debugColumns`,`getAfter`)),e.resetSize=()=>{t.setColumnSizing(t=>{let{[e.id]:n,...r}=t;return r})},e.getCanResize=()=>(e.columnDef.enableResizing??!0)&&(t.options.enableColumnResizing??!0),e.getIsResizing=()=>t.getState().columnSizingInfo.isResizingColumn===e.id},createHeader:(e,t)=>{e.getSize=()=>{let t=0,n=e=>{e.subHeaders.length?e.subHeaders.forEach(n):t+=e.column.getSize()??0};return n(e),t},e.getStart=()=>{if(e.index>0){let t=e.headerGroup.headers[e.index-1];return t.getStart()+t.getSize()}return 0},e.getResizeHandler=n=>{let r=t.getColumn(e.column.id),i=r?.getCanResize();return a=>{if(!r||!i||(a.persist==null||a.persist(),SO(a)&&a.touches&&a.touches.length>1))return;let o=e.getSize(),s=e?e.getLeafHeaders().map(e=>[e.column.id,e.column.getSize()]):[[r.id,r.getSize()]],c=SO(a)?Math.round(a.touches[0].clientX):a.clientX,l={},u=(e,n)=>{typeof n==`number`&&(t.setColumnSizingInfo(e=>{let r=t.options.columnResizeDirection===`rtl`?-1:1,i=(n-(e?.startOffset??0))*r,a=Math.max(i/(e?.startSize??0),-.999999);return e.columnSizingStart.forEach(e=>{let[t,n]=e;l[t]=Math.round(Math.max(n+n*a,0)*100)/100}),{...e,deltaOffset:i,deltaPercentage:a}}),(t.options.columnResizeMode===`onChange`||e===`end`)&&t.setColumnSizing(e=>({...e,...l})))},d=e=>u(`move`,e),f=e=>{u(`end`,e),t.setColumnSizingInfo(e=>({...e,isResizingColumn:!1,startOffset:null,startSize:null,deltaOffset:null,deltaPercentage:null,columnSizingStart:[]}))},p=gO(n),m={moveHandler:e=>d(e.clientX),upHandler:e=>{p?.removeEventListener(`mousemove`,m.moveHandler),p?.removeEventListener(`mouseup`,m.upHandler),f(e.clientX)}},h={moveHandler:e=>(e.cancelable&&(e.preventDefault(),e.stopPropagation()),d(e.touches[0].clientX),!1),upHandler:e=>{p?.removeEventListener(`touchmove`,h.moveHandler),p?.removeEventListener(`touchend`,h.upHandler),e.cancelable&&(e.preventDefault(),e.stopPropagation()),f(e.touches[0]?.clientX)}},g=xO()?{passive:!1}:!1;SO(a)?(p?.addEventListener(`touchmove`,h.moveHandler,g),p?.addEventListener(`touchend`,h.upHandler,g)):(p?.addEventListener(`mousemove`,m.moveHandler,g),p?.addEventListener(`mouseup`,m.upHandler,g)),t.setColumnSizingInfo(e=>({...e,startOffset:c,startSize:o,deltaOffset:0,deltaPercentage:0,columnSizingStart:s,isResizingColumn:r.id}))}}},createTable:e=>{e.setColumnSizing=t=>e.options.onColumnSizingChange==null?void 0:e.options.onColumnSizingChange(t),e.setColumnSizingInfo=t=>e.options.onColumnSizingInfoChange==null?void 0:e.options.onColumnSizingInfoChange(t),e.resetColumnSizing=t=>{e.setColumnSizing(t?{}:e.initialState.columnSizing??{})},e.resetHeaderSizeInfo=t=>{e.setColumnSizingInfo(t?vO():e.initialState.columnSizingInfo??vO())},e.getTotalSize=()=>e.getHeaderGroups()[0]?.headers.reduce((e,t)=>e+t.getSize(),0)??0,e.getLeftTotalSize=()=>e.getLeftHeaderGroups()[0]?.headers.reduce((e,t)=>e+t.getSize(),0)??0,e.getCenterTotalSize=()=>e.getCenterHeaderGroups()[0]?.headers.reduce((e,t)=>e+t.getSize(),0)??0,e.getRightTotalSize=()=>e.getRightHeaderGroups()[0]?.headers.reduce((e,t)=>e+t.getSize(),0)??0}},bO=null;function xO(){if(typeof bO==`boolean`)return bO;let e=!1;try{let t={get passive(){return e=!0,!1}},n=()=>{};window.addEventListener(`test`,n,t),window.removeEventListener(`test`,n)}catch{e=!1}return bO=e,bO}function SO(e){return e.type===`touchstart`}var CO={getInitialState:e=>({columnVisibility:{},...e}),getDefaultOptions:e=>({onColumnVisibilityChange:LD(`columnVisibility`,e)}),createColumn:(e,t)=>{e.toggleVisibility=n=>{e.getCanHide()&&t.setColumnVisibility(t=>({...t,[e.id]:n??!e.getIsVisible()}))},e.getIsVisible=()=>{let n=e.columns;return(n.length?n.some(e=>e.getIsVisible()):t.getState().columnVisibility?.[e.id])??!0},e.getCanHide=()=>(e.columnDef.enableHiding??!0)&&(t.options.enableHiding??!0),e.getToggleVisibilityHandler=()=>t=>{e.toggleVisibility==null||e.toggleVisibility(t.target.checked)}},createRow:(e,t)=>{e._getAllVisibleCells=VD(()=>[e.getAllCells(),t.getState().columnVisibility],e=>e.filter(e=>e.column.getIsVisible()),HD(t.options,`debugRows`,`_getAllVisibleCells`)),e.getVisibleCells=VD(()=>[e.getLeftVisibleCells(),e.getCenterVisibleCells(),e.getRightVisibleCells()],(e,t,n)=>[...e,...t,...n],HD(t.options,`debugRows`,`getVisibleCells`))},createTable:e=>{let t=(t,n)=>VD(()=>[n(),n().filter(e=>e.getIsVisible()).map(e=>e.id).join(`_`)],e=>e.filter(e=>e.getIsVisible==null?void 0:e.getIsVisible()),HD(e.options,`debugColumns`,t));e.getVisibleFlatColumns=t(`getVisibleFlatColumns`,()=>e.getAllFlatColumns()),e.getVisibleLeafColumns=t(`getVisibleLeafColumns`,()=>e.getAllLeafColumns()),e.getLeftVisibleLeafColumns=t(`getLeftVisibleLeafColumns`,()=>e.getLeftLeafColumns()),e.getRightVisibleLeafColumns=t(`getRightVisibleLeafColumns`,()=>e.getRightLeafColumns()),e.getCenterVisibleLeafColumns=t(`getCenterVisibleLeafColumns`,()=>e.getCenterLeafColumns()),e.setColumnVisibility=t=>e.options.onColumnVisibilityChange==null?void 0:e.options.onColumnVisibilityChange(t),e.resetColumnVisibility=t=>{e.setColumnVisibility(t?{}:e.initialState.columnVisibility??{})},e.toggleAllColumnsVisible=t=>{t??=!e.getIsAllColumnsVisible(),e.setColumnVisibility(e.getAllLeafColumns().reduce((e,n)=>({...e,[n.id]:t||!(n.getCanHide!=null&&n.getCanHide())}),{}))},e.getIsAllColumnsVisible=()=>!e.getAllLeafColumns().some(e=>!(e.getIsVisible!=null&&e.getIsVisible())),e.getIsSomeColumnsVisible=()=>e.getAllLeafColumns().some(e=>e.getIsVisible==null?void 0:e.getIsVisible()),e.getToggleAllColumnsVisibilityHandler=()=>t=>{e.toggleAllColumnsVisible(t.target?.checked)}}};function wO(e,t){return t?t===`center`?e.getCenterVisibleLeafColumns():t===`left`?e.getLeftVisibleLeafColumns():e.getRightVisibleLeafColumns():e.getVisibleLeafColumns()}var TO={createTable:e=>{e._getGlobalFacetedRowModel=e.options.getFacetedRowModel&&e.options.getFacetedRowModel(e,`__global__`),e.getGlobalFacetedRowModel=()=>e.options.manualFiltering||!e._getGlobalFacetedRowModel?e.getPreFilteredRowModel():e._getGlobalFacetedRowModel(),e._getGlobalFacetedUniqueValues=e.options.getFacetedUniqueValues&&e.options.getFacetedUniqueValues(e,`__global__`),e.getGlobalFacetedUniqueValues=()=>e._getGlobalFacetedUniqueValues?e._getGlobalFacetedUniqueValues():new Map,e._getGlobalFacetedMinMaxValues=e.options.getFacetedMinMaxValues&&e.options.getFacetedMinMaxValues(e,`__global__`),e.getGlobalFacetedMinMaxValues=()=>{if(e._getGlobalFacetedMinMaxValues)return e._getGlobalFacetedMinMaxValues()}}},EO={getInitialState:e=>({globalFilter:void 0,...e}),getDefaultOptions:e=>({onGlobalFilterChange:LD(`globalFilter`,e),globalFilterFn:`auto`,getColumnCanGlobalFilter:t=>{var n;let r=(n=e.getCoreRowModel().flatRows[0])==null||(n=n._getAllCellsByColumnId()[t.id])==null?void 0:n.getValue();return typeof r==`string`||typeof r==`number`}}),createColumn:(e,t)=>{e.getCanGlobalFilter=()=>(e.columnDef.enableGlobalFilter??!0)&&(t.options.enableGlobalFilter??!0)&&(t.options.enableFilters??!0)&&((t.options.getColumnCanGlobalFilter==null?void 0:t.options.getColumnCanGlobalFilter(e))??!0)&&!!e.accessorFn},createTable:e=>{e.getGlobalAutoFilterFn=()=>oO.includesString,e.getGlobalFilterFn=()=>{let{globalFilterFn:t}=e.options;return RD(t)?t:t===`auto`?e.getGlobalAutoFilterFn():e.options.filterFns?.[t]??oO[t]},e.setGlobalFilter=t=>{e.options.onGlobalFilterChange==null||e.options.onGlobalFilterChange(t)},e.resetGlobalFilter=t=>{e.setGlobalFilter(t?void 0:e.initialState.globalFilter)}}},DO={getInitialState:e=>({expanded:{},...e}),getDefaultOptions:e=>({onExpandedChange:LD(`expanded`,e),paginateExpandedRows:!0}),createTable:e=>{let t=!1,n=!1;e._autoResetExpanded=()=>{if(!t){e._queue(()=>{t=!0});return}if(e.options.autoResetAll??e.options.autoResetExpanded??!e.options.manualExpanding){if(n)return;n=!0,e._queue(()=>{e.resetExpanded(),n=!1})}},e.setExpanded=t=>e.options.onExpandedChange==null?void 0:e.options.onExpandedChange(t),e.toggleAllRowsExpanded=t=>{t??!e.getIsAllRowsExpanded()?e.setExpanded(!0):e.setExpanded({})},e.resetExpanded=t=>{e.setExpanded(t?{}:e.initialState?.expanded??{})},e.getCanSomeRowsExpand=()=>e.getPrePaginationRowModel().flatRows.some(e=>e.getCanExpand()),e.getToggleAllRowsExpandedHandler=()=>t=>{t.persist==null||t.persist(),e.toggleAllRowsExpanded()},e.getIsSomeRowsExpanded=()=>{let t=e.getState().expanded;return t===!0||Object.values(t).some(Boolean)},e.getIsAllRowsExpanded=()=>{let t=e.getState().expanded;return typeof t==`boolean`?t===!0:!(!Object.keys(t).length||e.getRowModel().flatRows.some(e=>!e.getIsExpanded()))},e.getExpandedDepth=()=>{let t=0;return(e.getState().expanded===!0?Object.keys(e.getRowModel().rowsById):Object.keys(e.getState().expanded)).forEach(e=>{let n=e.split(`.`);t=Math.max(t,n.length)}),t},e.getPreExpandedRowModel=()=>e.getSortedRowModel(),e.getExpandedRowModel=()=>(!e._getExpandedRowModel&&e.options.getExpandedRowModel&&(e._getExpandedRowModel=e.options.getExpandedRowModel(e)),e.options.manualExpanding||!e._getExpandedRowModel?e.getPreExpandedRowModel():e._getExpandedRowModel())},createRow:(e,t)=>{e.toggleExpanded=n=>{t.setExpanded(r=>{let i=r===!0?!0:!!(r!=null&&r[e.id]),a={};if(r===!0?Object.keys(t.getRowModel().rowsById).forEach(e=>{a[e]=!0}):a=r,n??=!i,!i&&n)return{...a,[e.id]:!0};if(i&&!n){let{[e.id]:t,...n}=a;return n}return r})},e.getIsExpanded=()=>{let n=t.getState().expanded;return!!((t.options.getIsRowExpanded==null?void 0:t.options.getIsRowExpanded(e))??(n===!0||n?.[e.id]))},e.getCanExpand=()=>{var n;return(t.options.getRowCanExpand==null?void 0:t.options.getRowCanExpand(e))??((t.options.enableExpanding??!0)&&!!((n=e.subRows)!=null&&n.length))},e.getIsAllParentsExpanded=()=>{let n=!0,r=e;for(;n&&r.parentId;)r=t.getRow(r.parentId,!0),n=r.getIsExpanded();return n},e.getToggleExpandedHandler=()=>{let t=e.getCanExpand();return()=>{t&&e.toggleExpanded()}}}},OO=0,kO=10,AO=()=>({pageIndex:OO,pageSize:kO}),jO={getInitialState:e=>({...e,pagination:{...AO(),...e?.pagination}}),getDefaultOptions:e=>({onPaginationChange:LD(`pagination`,e)}),createTable:e=>{let t=!1,n=!1;e._autoResetPageIndex=()=>{if(!t){e._queue(()=>{t=!0});return}if(e.options.autoResetAll??e.options.autoResetPageIndex??!e.options.manualPagination){if(n)return;n=!0,e._queue(()=>{e.resetPageIndex(),n=!1})}},e.setPagination=t=>e.options.onPaginationChange==null?void 0:e.options.onPaginationChange(e=>ID(t,e)),e.resetPagination=t=>{e.setPagination(t?AO():e.initialState.pagination??AO())},e.setPageIndex=t=>{e.setPagination(n=>{let r=ID(t,n.pageIndex),i=e.options.pageCount===void 0||e.options.pageCount===-1?2**53-1:e.options.pageCount-1;return r=Math.max(0,Math.min(r,i)),{...n,pageIndex:r}})},e.resetPageIndex=t=>{var n;e.setPageIndex(t?OO:((n=e.initialState)==null||(n=n.pagination)==null?void 0:n.pageIndex)??OO)},e.resetPageSize=t=>{var n;e.setPageSize(t?kO:((n=e.initialState)==null||(n=n.pagination)==null?void 0:n.pageSize)??kO)},e.setPageSize=t=>{e.setPagination(e=>{let n=Math.max(1,ID(t,e.pageSize)),r=e.pageSize*e.pageIndex,i=Math.floor(r/n);return{...e,pageIndex:i,pageSize:n}})},e.setPageCount=t=>e.setPagination(n=>{let r=ID(t,e.options.pageCount??-1);return typeof r==`number`&&(r=Math.max(-1,r)),{...n,pageCount:r}}),e.getPageOptions=VD(()=>[e.getPageCount()],e=>{let t=[];return e&&e>0&&(t=[...Array(e)].fill(null).map((e,t)=>t)),t},HD(e.options,`debugTable`,`getPageOptions`)),e.getCanPreviousPage=()=>e.getState().pagination.pageIndex>0,e.getCanNextPage=()=>{let{pageIndex:t}=e.getState().pagination,n=e.getPageCount();return n===-1?!0:n===0?!1:t<n-1},e.previousPage=()=>e.setPageIndex(e=>e-1),e.nextPage=()=>e.setPageIndex(e=>e+1),e.firstPage=()=>e.setPageIndex(0),e.lastPage=()=>e.setPageIndex(e.getPageCount()-1),e.getPrePaginationRowModel=()=>e.getExpandedRowModel(),e.getPaginationRowModel=()=>(!e._getPaginationRowModel&&e.options.getPaginationRowModel&&(e._getPaginationRowModel=e.options.getPaginationRowModel(e)),e.options.manualPagination||!e._getPaginationRowModel?e.getPrePaginationRowModel():e._getPaginationRowModel()),e.getPageCount=()=>e.options.pageCount??Math.ceil(e.getRowCount()/e.getState().pagination.pageSize),e.getRowCount=()=>e.options.rowCount??e.getPrePaginationRowModel().rows.length}},MO=()=>({top:[],bottom:[]}),NO={getInitialState:e=>({rowPinning:MO(),...e}),getDefaultOptions:e=>({onRowPinningChange:LD(`rowPinning`,e)}),createRow:(e,t)=>{e.pin=(n,r,i)=>{let a=r?e.getLeafRows().map(e=>{let{id:t}=e;return t}):[],o=i?e.getParentRows().map(e=>{let{id:t}=e;return t}):[],s=new Set([...o,e.id,...a]);t.setRowPinning(e=>n===`bottom`?{top:(e?.top??[]).filter(e=>!(s!=null&&s.has(e))),bottom:[...(e?.bottom??[]).filter(e=>!(s!=null&&s.has(e))),...Array.from(s)]}:n===`top`?{top:[...(e?.top??[]).filter(e=>!(s!=null&&s.has(e))),...Array.from(s)],bottom:(e?.bottom??[]).filter(e=>!(s!=null&&s.has(e)))}:{top:(e?.top??[]).filter(e=>!(s!=null&&s.has(e))),bottom:(e?.bottom??[]).filter(e=>!(s!=null&&s.has(e)))})},e.getCanPin=()=>{let{enableRowPinning:n,enablePinning:r}=t.options;return typeof n==`function`?n(e):n??r??!0},e.getIsPinned=()=>{let n=[e.id],{top:r,bottom:i}=t.getState().rowPinning,a=n.some(e=>r?.includes(e)),o=n.some(e=>i?.includes(e));return a?`top`:o?`bottom`:!1},e.getPinnedIndex=()=>{let n=e.getIsPinned();return n?((n===`top`?t.getTopRows():t.getBottomRows())?.map(e=>{let{id:t}=e;return t}))?.indexOf(e.id)??-1:-1}},createTable:e=>{e.setRowPinning=t=>e.options.onRowPinningChange==null?void 0:e.options.onRowPinningChange(t),e.resetRowPinning=t=>e.setRowPinning(t?MO():e.initialState?.rowPinning??MO()),e.getIsSomeRowsPinned=t=>{let n=e.getState().rowPinning;return t?!!n[t]?.length:!!(n.top?.length||n.bottom?.length)},e._getPinnedRows=(t,n,r)=>(e.options.keepPinnedRows??!0?(n??[]).map(t=>{let n=e.getRow(t,!0);return n.getIsAllParentsExpanded()?n:null}):(n??[]).map(e=>t.find(t=>t.id===e))).filter(Boolean).map(e=>({...e,position:r})),e.getTopRows=VD(()=>[e.getRowModel().rows,e.getState().rowPinning.top],(t,n)=>e._getPinnedRows(t,n,`top`),HD(e.options,`debugRows`,`getTopRows`)),e.getBottomRows=VD(()=>[e.getRowModel().rows,e.getState().rowPinning.bottom],(t,n)=>e._getPinnedRows(t,n,`bottom`),HD(e.options,`debugRows`,`getBottomRows`)),e.getCenterRows=VD(()=>[e.getRowModel().rows,e.getState().rowPinning.top,e.getState().rowPinning.bottom],(e,t,n)=>{let r=new Set([...t??[],...n??[]]);return e.filter(e=>!r.has(e.id))},HD(e.options,`debugRows`,`getCenterRows`))}},PO={getInitialState:e=>({rowSelection:{},...e}),getDefaultOptions:e=>({onRowSelectionChange:LD(`rowSelection`,e),enableRowSelection:!0,enableMultiRowSelection:!0,enableSubRowSelection:!0}),createTable:e=>{e.setRowSelection=t=>e.options.onRowSelectionChange==null?void 0:e.options.onRowSelectionChange(t),e.resetRowSelection=t=>e.setRowSelection(t?{}:e.initialState.rowSelection??{}),e.toggleAllRowsSelected=t=>{e.setRowSelection(n=>{t=t===void 0?!e.getIsAllRowsSelected():t;let r={...n},i=e.getPreGroupedRowModel().flatRows;return t?i.forEach(e=>{e.getCanSelect()&&(r[e.id]=!0)}):i.forEach(e=>{delete r[e.id]}),r})},e.toggleAllPageRowsSelected=t=>e.setRowSelection(n=>{let r=t===void 0?!e.getIsAllPageRowsSelected():t,i={...n};return e.getRowModel().rows.forEach(t=>{FO(i,t.id,r,!0,e)}),i}),e.getPreSelectedRowModel=()=>e.getCoreRowModel(),e.getSelectedRowModel=VD(()=>[e.getState().rowSelection,e.getCoreRowModel()],(t,n)=>Object.keys(t).length?IO(e,n):{rows:[],flatRows:[],rowsById:{}},HD(e.options,`debugTable`,`getSelectedRowModel`)),e.getFilteredSelectedRowModel=VD(()=>[e.getState().rowSelection,e.getFilteredRowModel()],(t,n)=>Object.keys(t).length?IO(e,n):{rows:[],flatRows:[],rowsById:{}},HD(e.options,`debugTable`,`getFilteredSelectedRowModel`)),e.getGroupedSelectedRowModel=VD(()=>[e.getState().rowSelection,e.getSortedRowModel()],(t,n)=>Object.keys(t).length?IO(e,n):{rows:[],flatRows:[],rowsById:{}},HD(e.options,`debugTable`,`getGroupedSelectedRowModel`)),e.getIsAllRowsSelected=()=>{let t=e.getFilteredRowModel().flatRows,{rowSelection:n}=e.getState(),r=!!(t.length&&Object.keys(n).length);return r&&t.some(e=>e.getCanSelect()&&!n[e.id])&&(r=!1),r},e.getIsAllPageRowsSelected=()=>{let t=e.getPaginationRowModel().flatRows.filter(e=>e.getCanSelect()),{rowSelection:n}=e.getState(),r=!!t.length;return r&&t.some(e=>!n[e.id])&&(r=!1),r},e.getIsSomeRowsSelected=()=>{let t=Object.keys(e.getState().rowSelection??{}).length;return t>0&&t<e.getFilteredRowModel().flatRows.length},e.getIsSomePageRowsSelected=()=>{let t=e.getPaginationRowModel().flatRows;return e.getIsAllPageRowsSelected()?!1:t.filter(e=>e.getCanSelect()).some(e=>e.getIsSelected()||e.getIsSomeSelected())},e.getToggleAllRowsSelectedHandler=()=>t=>{e.toggleAllRowsSelected(t.target.checked)},e.getToggleAllPageRowsSelectedHandler=()=>t=>{e.toggleAllPageRowsSelected(t.target.checked)}},createRow:(e,t)=>{e.toggleSelected=(n,r)=>{let i=e.getIsSelected();t.setRowSelection(a=>{if(n=n===void 0?!i:n,e.getCanSelect()&&i===n)return a;let o={...a};return FO(o,e.id,n,r?.selectChildren??!0,t),o})},e.getIsSelected=()=>{let{rowSelection:n}=t.getState();return LO(e,n)},e.getIsSomeSelected=()=>{let{rowSelection:n}=t.getState();return RO(e,n)===`some`},e.getIsAllSubRowsSelected=()=>{let{rowSelection:n}=t.getState();return RO(e,n)===`all`},e.getCanSelect=()=>typeof t.options.enableRowSelection==`function`?t.options.enableRowSelection(e):t.options.enableRowSelection??!0,e.getCanSelectSubRows=()=>typeof t.options.enableSubRowSelection==`function`?t.options.enableSubRowSelection(e):t.options.enableSubRowSelection??!0,e.getCanMultiSelect=()=>typeof t.options.enableMultiRowSelection==`function`?t.options.enableMultiRowSelection(e):t.options.enableMultiRowSelection??!0,e.getToggleSelectedHandler=()=>{let t=e.getCanSelect();return n=>{t&&e.toggleSelected(n.target?.checked)}}}},FO=(e,t,n,r,i)=>{var a;let o=i.getRow(t,!0);n?(o.getCanMultiSelect()||Object.keys(e).forEach(t=>delete e[t]),o.getCanSelect()&&(e[t]=!0)):delete e[t],r&&(a=o.subRows)!=null&&a.length&&o.getCanSelectSubRows()&&o.subRows.forEach(t=>FO(e,t.id,n,r,i))};function IO(e,t){let n=e.getState().rowSelection,r=[],i={},a=function(e,t){return e.map(e=>{var t;let o=LO(e,n);if(o&&(r.push(e),i[e.id]=e),(t=e.subRows)!=null&&t.length&&(e={...e,subRows:a(e.subRows)}),o)return e}).filter(Boolean)};return{rows:a(t.rows),flatRows:r,rowsById:i}}function LO(e,t){return t[e.id]??!1}function RO(e,t,n){var r;if(!((r=e.subRows)!=null&&r.length))return!1;let i=!0,a=!1;return e.subRows.forEach(e=>{if(!(a&&!i)&&(e.getCanSelect()&&(LO(e,t)?a=!0:i=!1),e.subRows&&e.subRows.length)){let n=RO(e,t);n===`all`?a=!0:(n===`some`&&(a=!0),i=!1)}}),i?`all`:a?`some`:!1}var zO=/([0-9]+)/gm,BO=(e,t,n)=>JO(qO(e.getValue(n)).toLowerCase(),qO(t.getValue(n)).toLowerCase()),VO=(e,t,n)=>JO(qO(e.getValue(n)),qO(t.getValue(n))),HO=(e,t,n)=>KO(qO(e.getValue(n)).toLowerCase(),qO(t.getValue(n)).toLowerCase()),UO=(e,t,n)=>KO(qO(e.getValue(n)),qO(t.getValue(n))),WO=(e,t,n)=>{let r=e.getValue(n),i=t.getValue(n);return r>i?1:r<i?-1:0},GO=(e,t,n)=>KO(e.getValue(n),t.getValue(n));function KO(e,t){return e===t?0:e>t?1:-1}function qO(e){return typeof e==`number`?isNaN(e)||e===1/0||e===-1/0?``:String(e):typeof e==`string`?e:``}function JO(e,t){let n=e.split(zO).filter(Boolean),r=t.split(zO).filter(Boolean);for(;n.length&&r.length;){let e=n.shift(),t=r.shift(),i=parseInt(e,10),a=parseInt(t,10),o=[i,a].sort();if(isNaN(o[0])){if(e>t)return 1;if(t>e)return-1;continue}if(isNaN(o[1]))return isNaN(i)?-1:1;if(i>a)return 1;if(a>i)return-1}return n.length-r.length}var YO={alphanumeric:BO,alphanumericCaseSensitive:VO,text:HO,textCaseSensitive:UO,datetime:WO,basic:GO},XO=[qD,CO,pO,hO,XD,cO,TO,EO,{getInitialState:e=>({sorting:[],...e}),getDefaultColumnDef:()=>({sortingFn:`auto`,sortUndefined:1}),getDefaultOptions:e=>({onSortingChange:LD(`sorting`,e),isMultiSortEvent:e=>e.shiftKey}),createColumn:(e,t)=>{e.getAutoSortingFn=()=>{let n=t.getFilteredRowModel().flatRows.slice(10),r=!1;for(let t of n){let n=t?.getValue(e.id);if(Object.prototype.toString.call(n)===`[object Date]`)return YO.datetime;if(typeof n==`string`&&(r=!0,n.split(zO).length>1))return YO.alphanumeric}return r?YO.text:YO.basic},e.getAutoSortDir=()=>typeof t.getFilteredRowModel().flatRows[0]?.getValue(e.id)==`string`?`asc`:`desc`,e.getSortingFn=()=>{if(!e)throw Error();return RD(e.columnDef.sortingFn)?e.columnDef.sortingFn:e.columnDef.sortingFn===`auto`?e.getAutoSortingFn():t.options.sortingFns?.[e.columnDef.sortingFn]??YO[e.columnDef.sortingFn]},e.toggleSorting=(n,r)=>{let i=e.getNextSortingOrder(),a=n!=null;t.setSorting(o=>{let s=o?.find(t=>t.id===e.id),c=o?.findIndex(t=>t.id===e.id),l=[],u,d=a?n:i===`desc`;return u=o!=null&&o.length&&e.getCanMultiSort()&&r?s?`toggle`:`add`:o!=null&&o.length&&c!==o.length-1?`replace`:s?`toggle`:`replace`,u===`toggle`&&(a||i||(u=`remove`)),u===`add`?(l=[...o,{id:e.id,desc:d}],l.splice(0,l.length-(t.options.maxMultiSortColCount??2**53-1))):l=u===`toggle`?o.map(t=>t.id===e.id?{...t,desc:d}:t):u===`remove`?o.filter(t=>t.id!==e.id):[{id:e.id,desc:d}],l})},e.getFirstSortDir=()=>e.columnDef.sortDescFirst??t.options.sortDescFirst??e.getAutoSortDir()===`desc`?`desc`:`asc`,e.getNextSortingOrder=n=>{let r=e.getFirstSortDir(),i=e.getIsSorted();return i?i!==r&&(t.options.enableSortingRemoval??!0)&&(!n||(t.options.enableMultiRemove??!0))?!1:i===`desc`?`asc`:`desc`:r},e.getCanSort=()=>(e.columnDef.enableSorting??!0)&&(t.options.enableSorting??!0)&&!!e.accessorFn,e.getCanMultiSort=()=>e.columnDef.enableMultiSort??t.options.enableMultiSort??!!e.accessorFn,e.getIsSorted=()=>{let n=t.getState().sorting?.find(t=>t.id===e.id);return n?n.desc?`desc`:`asc`:!1},e.getSortIndex=()=>t.getState().sorting?.findIndex(t=>t.id===e.id)??-1,e.clearSorting=()=>{t.setSorting(t=>t!=null&&t.length?t.filter(t=>t.id!==e.id):[])},e.getToggleSortingHandler=()=>{let n=e.getCanSort();return r=>{n&&(r.persist==null||r.persist(),e.toggleSorting==null||e.toggleSorting(void 0,e.getCanMultiSort()?t.options.isMultiSortEvent==null?void 0:t.options.isMultiSortEvent(r):!1))}}},createTable:e=>{e.setSorting=t=>e.options.onSortingChange==null?void 0:e.options.onSortingChange(t),e.resetSorting=t=>{e.setSorting(t?[]:e.initialState?.sorting??[])},e.getPreSortedRowModel=()=>e.getGroupedRowModel(),e.getSortedRowModel=()=>(!e._getSortedRowModel&&e.options.getSortedRowModel&&(e._getSortedRowModel=e.options.getSortedRowModel(e)),e.options.manualSorting||!e._getSortedRowModel?e.getPreSortedRowModel():e._getSortedRowModel())}},dO,DO,jO,NO,PO,yO];function ZO(e){let t=[...XO,...e._features??[]],n={_features:t},r=n._features.reduce((e,t)=>
67Object.assign(e,t.getDefaultOptions==null?void 0:t.getDefaultOptions(n)),{}),i=e=>n.options.mergeOptions?n.options.mergeOptions(r,e):{...r,...e},a={...e.initialState??{}};n._features.forEach(e=>{a=(e.getInitialState==null?void 0:e.getInitialState(a))??a});let o=[],s=!1,c={_features:t,options:{...r,...e},initialState:a,_queue:e=>{o.push(e),s||(s=!0,Promise.resolve().then(()=>{for(;o.length;)o.shift()();s=!1}).catch(e=>setTimeout(()=>{throw e})))},reset:()=>{n.setState(n.initialState)},setOptions:e=>{n.options=i(ID(e,n.options))},getState:()=>n.options.state,setState:e=>{n.options.onStateChange==null||n.options.onStateChange(e)},_getRowId:(e,t,r)=>(n.options.getRowId==null?void 0:n.options.getRowId(e,t,r))??`${r?[r.id,t].join(`.`):t}`,getCoreRowModel:()=>(n._getCoreRowModel||=n.options.getCoreRowModel(n),n._getCoreRowModel()),getRowModel:()=>n.getPaginationRowModel(),getRow:(e,t)=>{let r=(t?n.getPrePaginationRowModel():n.getRowModel()).rowsById[e];if(!r&&(r=n.getCoreRowModel().rowsById[e],!r))throw Error();return r},_getDefaultColumnDef:VD(()=>[n.options.defaultColumn],e=>(e??={},{header:e=>{let t=e.header.column.columnDef;return t.accessorKey?t.accessorKey:t.accessorFn?t.id:null},cell:e=>{var t;return((t=e.renderValue())==null||t.toString==null?void 0:t.toString())??null},...n._features.reduce((e,t)=>Object.assign(e,t.getDefaultColumnDef==null?void 0:t.getDefaultColumnDef()),{}),...e}),HD(e,`debugColumns`,`_getDefaultColumnDef`)),_getColumnDefs:()=>n.options.columns,getAllColumns:VD(()=>[n._getColumnDefs()],e=>{let t=function(e,r,i){return i===void 0&&(i=0),e.map(e=>{let a=WD(n,e,i,r),o=e;return a.columns=o.columns?t(o.columns,a,i+1):[],a})};return t(e)},HD(e,`debugColumns`,`getAllColumns`)),getAllFlatColumns:VD(()=>[n.getAllColumns()],e=>e.flatMap(e=>e.getFlatColumns()),HD(e,`debugColumns`,`getAllFlatColumns`)),_getAllFlatColumnsById:VD(()=>[n.getAllFlatColumns()],e=>e.reduce((e,t)=>(e[t.id]=t,e),{}),HD(e,`debugColumns`,`getAllFlatColumnsById`)),getAllLeafColumns:VD(()=>[n.getAllColumns(),n._getOrderColumnsFn()],(e,t)=>t(e.flatMap(e=>e.getLeafColumns())),HD(e,`debugColumns`,`getAllLeafColumns`)),getColumn:e=>n._getAllFlatColumnsById()[e]};Object.assign(n,c);for(let e=0;e<n._features.length;e++){let t=n._features[e];t==null||t.createTable==null||t.createTable(n)}return n}function QO(){return e=>VD(()=>[e.options.data],t=>{let n={rows:[],flatRows:[],rowsById:{}},r=function(t,i,a){i===void 0&&(i=0);let o=[];for(let c=0;c<t.length;c++){let l=YD(e,e._getRowId(t[c],c,a),t[c],c,i,void 0,a?.id);if(n.flatRows.push(l),n.rowsById[l.id]=l,o.push(l),e.options.getSubRows){var s;l.originalSubRows=e.options.getSubRows(t[c],c),(s=l.originalSubRows)!=null&&s.length&&(l.subRows=r(l.originalSubRows,i+1,l))}}return o};return n.rows=r(t),n},HD(e.options,`debugTable`,`getRowModel`,()=>e._autoResetPageIndex()))}function $O(e,t){return e?ek(e)?_.createElement(e,t):e:null}function ek(e){return tk(e)||typeof e==`function`||nk(e)}function tk(e){return typeof e==`function`&&(()=>{let t=Object.getPrototypeOf(e);return t.prototype&&t.prototype.isReactComponent})()}function nk(e){return typeof e==`object`&&typeof e.$$typeof==`symbol`&&[`react.memo`,`react.forward_ref`].includes(e.$$typeof.description)}function rk(e){let t={state:{},onStateChange:()=>{},renderFallbackValue:null,...e},[n]=_.useState(()=>({current:ZO(t)})),[r,i]=_.useState(()=>n.current.initialState);return n.current.setOptions(t=>({...t,...e,state:{...r,...e.state},onStateChange:t=>{i(t),e.onStateChange==null||e.onStateChange(t)}})),n.current}function ik(e,t,n){let r=n.initialDeps??[],i,a=!0;function o(){let o;n.key&&n.debug?.call(n)&&(o=Date.now());let s=e();if(!(s.length!==r.length||s.some((e,t)=>r[t]!==e)))return i;r=s;let c;if(n.key&&n.debug?.call(n)&&(c=Date.now()),i=t(...s),n.key&&n.debug?.call(n)){let e=Math.round((Date.now()-o)*100)/100,t=Math.round((Date.now()-c)*100)/100,r=t/16,i=(e,t)=>{for(e=String(e);e.length<t;)e=` `+e;return e};console.info(`%câ± ${i(t,5)} /${i(e,5)} ms`,` 68 font-size: .6rem; 69 font-weight: bold; 70 color: hsl(${Math.max(0,Math.min(120-120*r,120))}deg 100% 31%);`,n?.key)}return n?.onChange&&!(a&&n.skipInitialOnChange)&&n.onChange(i),a=!1,i}return o.updateDeps=e=>{r=e},o}function ak(e,t){if(e===void 0)throw Error(`Unexpected undefined${t?`: ${t}`:``}`);return e}var ok=(e,t)=>Math.abs(e-t)<1.01,sk=(e,t,n)=>{let r;return function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)}},ck=e=>{let{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},lk=e=>e,uk=e=>{let t=Math.max(e.startIndex-e.overscan,0),n=Math.min(e.endIndex+e.overscan,e.count-1),r=[];for(let e=t;e<=n;e++)r.push(e);return r},dk=(e,t)=>{let n=e.scrollElement;if(!n)return;let r=e.targetWindow;if(!r)return;let i=e=>{let{width:n,height:r}=e;t({width:Math.round(n),height:Math.round(r)})};if(i(ck(n)),!r.ResizeObserver)return()=>{};let a=new r.ResizeObserver(t=>{let r=()=>{let e=t[0];if(e?.borderBoxSize){let t=e.borderBoxSize[0];if(t){i({width:t.inlineSize,height:t.blockSize});return}}i(ck(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(r):r()});return a.observe(n,{box:`border-box`}),()=>{a.unobserve(n)}},fk={passive:!0},pk=typeof window>`u`?!0:`onscrollend`in window,mk=(e,t)=>{let n=e.scrollElement;if(!n)return;let r=e.targetWindow;if(!r)return;let i=0,a=e.options.useScrollendEvent&&pk?()=>void 0:sk(r,()=>{t(i,!1)},e.options.isScrollingResetDelay),o=r=>()=>{let{horizontal:o,isRtl:s}=e.options;i=o?n.scrollLeft*(s&&-1||1):n.scrollTop,a(),t(i,r)},s=o(!0),c=o(!1);n.addEventListener(`scroll`,s,fk);let l=e.options.useScrollendEvent&&pk;return l&&n.addEventListener(`scrollend`,c,fk),()=>{n.removeEventListener(`scroll`,s),l&&n.removeEventListener(`scrollend`,c)}},hk=(e,t,n)=>{if(t?.borderBoxSize){let e=t.borderBoxSize[0];if(e)return Math.round(e[n.options.horizontal?`inlineSize`:`blockSize`])}return e[n.options.horizontal?`offsetWidth`:`offsetHeight`]}
vendor: 13,262 bytes, line 70
70,gk=(e,{adjustments:t=0,behavior:n},r)=>{var i,a;let o=e+t;(a=(i=r.scrollElement)?.scrollTo)==null||a.call(i,{[r.options.horizontal?`left`:`top`]:o,behavior:n})},_k=class{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this.itemSizeCache=new Map,this.laneAssignments=new Map,this.pendingMeasuredCacheIndexes=[],this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this.elementsCache=new Map,this.now=()=>{var e;return((e=this.targetWindow?.performance)?.now)?.call(e)??Date.now()},this.observer=(()=>{let e=null,t=()=>e||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:e=new this.targetWindow.ResizeObserver(e=>{e.forEach(e=>{let t=()=>{let t=e.target,n=this.indexFromElement(t);if(!t.isConnected){this.observer.unobserve(t);return}this.shouldMeasureDuringScroll(n)&&this.resizeItem(n,this.options.measureElement(t,e,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(t):t()})}));return{disconnect:()=>{var n;(n=t())==null||n.disconnect(),e=null},observe:e=>t()?.observe(e,{box:`border-box`}),unobserve:e=>t()?.unobserve(e)}})(),this.range=null,this.setOptions=e=>{Object.entries(e).forEach(([t,n])=>{n===void 0&&delete e[t]}),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:lk,rangeExtractor:uk,onChange:()=>{},measureElement:hk,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:`data-index`,initialMeasurementsCache:[],lanes:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:`estimate`,...e}},this.notify=e=>{var t,n;(n=(t=this.options).onChange)==null||n.call(t,this,e)},this.maybeNotify=ik(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),e=>{this.notify(e)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(e=>e()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{let e=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==e){if(this.cleanup(),!e){this.maybeNotify();return}this.scrollElement=e,this.scrollElement&&`ownerDocument`in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=this.scrollElement?.window??null,this.elementsCache.forEach(e=>{this.observer.observe(e)}),this.unsubs.push(this.options.observeElementRect(this,e=>{this.scrollRect=e,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(e,t)=>{this.scrollAdjustments=0,this.scrollDirection=t?this.getScrollOffset()<e?`forward`:`backward`:null,this.scrollOffset=e,this.isScrolling=t,this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?`width`:`height`]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset==`function`?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getFurthestMeasurement=(e,t)=>{let n=new Map,r=new Map;for(let i=t-1;i>=0;i--){let t=e[i];if(n.has(t.lane))continue;let a=r.get(t.lane);if(a==null||t.end>a.end?r.set(t.lane,t):t.end<a.end&&n.set(t.lane,!0),n.size===this.options.lanes)break}return r.size===this.options.lanes?Array.from(r.values()).sort((e,t)=>e.end===t.end?e.index-t.index:e.end-t.end)[0]:void 0},this.getMeasurementOptions=ik(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode],(e,t,n,r,i,a,o)=>(this.prevLanes!==void 0&&this.prevLanes!==a&&(this.lanesChangedFlag=!0),this.prevLanes=a,this.pendingMeasuredCacheIndexes=[],{count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a,laneAssignmentMode:o}),{key:!1}),this.getMeasurements=ik(()=>[this.getMeasurementOptions(),this.itemSizeCache],({count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a,laneAssignmentMode:o},s)=>{if(!i)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>e)for(let t of this.laneAssignments.keys())t>=e&&this.laneAssignments.delete(t);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMeasuredCacheIndexes=[]),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(e=>{this.itemSizeCache.set(e.key,e.size)}));let c=this.lanesSettling?0:this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[],this.lanesSettling&&this.measurementsCache.length===e&&(this.lanesSettling=!1);let l=this.measurementsCache.slice(0,c),u=Array(a).fill(void 0);for(let e=0;e<c;e++){let t=l[e];t&&(u[t.lane]=e)}for(let i=c;i<e;i++){let e=r(i),a=this.laneAssignments.get(i),c,d,f=o===`estimate`||s.has(e);if(a!==void 0&&this.options.lanes>1){c=a;let e=u[c],r=e===void 0?void 0:l[e];d=r?r.end+this.options.gap:t+n}else{let e=this.options.lanes===1?l[i-1]:this.getFurthestMeasurement(l,i);d=e?e.end+this.options.gap:t+n,c=e?e.lane:i%this.options.lanes,this.options.lanes>1&&f&&this.laneAssignments.set(i,c)}let p=s.get(e),m=typeof p==`number`?p:this.options.estimateSize(i),h=d+m;l[i]={index:i,start:d,size:m,end:h,key:e,lane:c},u[c]=i}return this.measurementsCache=l,l},{key:!1,debug:()=>this.options.debug}),this.calculateRange=ik(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(e,t,n,r)=>this.range=e.length>0&&t>0?yk({measurements:e,outerSize:t,scrollOffset:n,lanes:r}):null,{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=ik(()=>{let e=null,t=null,n=this.calculateRange();return n&&(e=n.startIndex,t=n.endIndex),this.maybeNotify.updateDeps([this.isScrolling,e,t]),[this.options.rangeExtractor,this.options.overscan,this.options.count,e,t]},(e,t,n,r,i)=>r===null||i===null?[]:e({startIndex:r,endIndex:i,overscan:t,count:n}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=e=>{let t=this.options.indexAttribute,n=e.getAttribute(t);return n?parseInt(n,10):(console.warn(`Missing attribute name '${t}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=e=>{if(!this.scrollState||this.scrollState.behavior!==`smooth`)return!0;let t=this.scrollState.index??this.getVirtualItemForOffset(this.scrollState.lastTargetOffset)?.index;if(t!==void 0&&this.range){let n=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),r=Math.max(0,t-n),i=Math.min(this.options.count-1,t+n);return e>=r&&e<=i}return!0},this.measureElement=e=>{if(!e){this.elementsCache.forEach((e,t)=>{e.isConnected||(this.observer.unobserve(e),this.elementsCache.delete(t))});return}let t=this.indexFromElement(e),n=this.options.getItemKey(t),r=this.elementsCache.get(n);r!==e&&(r&&this.observer.unobserve(r),this.observer.observe(e),this.elementsCache.set(n,e)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(t)&&this.resizeItem(t,this.options.measureElement(e,void 0,this))},this.resizeItem=(e,t)=>{let n=this.measurementsCache[e];if(!n)return;let r=t-(this.itemSizeCache.get(n.key)??n.size);r!==0&&(this.scrollState?.behavior!==`smooth`&&(this.shouldAdjustScrollPositionOnItemSizeChange===void 0?n.start<this.getScrollOffset()+this.scrollAdjustments:this.shouldAdjustScrollPositionOnItemSizeChange(n,r,this))&&this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=r,behavior:void 0}),this.pendingMeasuredCacheIndexes.push(n.index),this.itemSizeCache=new Map(this.itemSizeCache.set(n.key,t)),this.notify(!1))},this.getVirtualItems=ik(()=>[this.getVirtualIndexes(),this.getMeasurements()],(e,t)=>{let n=[];for(let r=0,i=e.length;r<i;r++){let i=t[e[r]];n.push(i)}return n},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=e=>{let t=this.getMeasurements();if(t.length!==0)return ak(t[vk(0,t.length-1,e=>ak(t[e]).start,e)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if(`scrollHeight`in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{let e=this.scrollElement.document.documentElement;return this.options.horizontal?e.scrollWidth-this.scrollElement.innerWidth:e.scrollHeight-this.scrollElement.innerHeight}},this.getOffsetForAlignment=(e,t,n=0)=>{if(!this.scrollElement)return 0;let r=this.getSize(),i=this.getScrollOffset();t===`auto`&&(t=e>=i+r?`end`:`start`),t===`center`?e+=(n-r)/2:t===`end`&&(e-=r);let a=this.getMaxScrollOffset();return Math.max(Math.min(a,e),0)},this.getOffsetForIndex=(e,t=`auto`)=>{e=Math.max(0,Math.min(e,this.options.count-1));let n=this.getSize(),r=this.getScrollOffset(),i=this.measurementsCache[e];if(!i)return;if(t===`auto`)if(i.end>=r+n-this.options.scrollPaddingEnd)t=`end`;else if(i.start<=r+this.options.scrollPaddingStart)t=`start`;else return[r,t];if(t===`end`&&e===this.options.count-1)return[this.getMaxScrollOffset(),t];let a=t===`end`?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(a,t,i.size),t]},this.scrollToOffset=(e,{align:t=`start`,behavior:n=`auto`}={})=>{let r=this.getOffsetForAlignment(e,t);this.scrollState={index:null,align:t,behavior:n,startedAt:this.now(),lastTargetOffset:r,stableFrames:0},this._scrollToOffset(r,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollToIndex=(e,{align:t=`auto`,behavior:n=`auto`}={})=>{e=Math.max(0,Math.min(e,this.options.count-1));let r=this.getOffsetForIndex(e,t);if(!r)return;let[i,a]=r,o=this.now();this.scrollState={index:e,align:a,behavior:n,startedAt:o,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollBy=(e,{behavior:t=`auto`}={})=>{let n=this.getScrollOffset()+e;this.scrollState={index:null,align:`start`,behavior:t,startedAt:this.now(),lastTargetOffset:n,stableFrames:0},this._scrollToOffset(n,{adjustments:void 0,behavior:t}),this.scheduleScrollReconcile()},this.getTotalSize=()=>{let e=this.getMeasurements(),t;if(e.length===0)t=this.options.paddingStart;else if(this.options.lanes===1)t=e[e.length-1]?.end??0;else{let n=Array(this.options.lanes).fill(null),r=e.length-1;for(;r>=0&&n.some(e=>e===null);){let t=e[r];n[t.lane]===null&&(n[t.lane]=t.end),r--}t=Math.max(...n.filter(e=>e!==null))}return Math.max(t-this.options.scrollMargin+this.options.paddingEnd,0)},this._scrollToOffset=(e,{adjustments:t,behavior:n})=>{this.options.scrollToFn(e,{behavior:n,adjustments:t},this)},this.measure=()=>{this.itemSizeCache=new Map,this.laneAssignments=new Map,this.notify(!1)},this.setOptions(e)}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId??=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()})}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}let e=this.scrollState.index==null?void 0:this.getOffsetForIndex(this.scrollState.index,this.scrollState.align),t=e?e[0]:this.scrollState.lastTargetOffset,n=t!==this.scrollState.lastTargetOffset;if(!n&&ok(t,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=1){this.scrollState=null;return}}else this.scrollState.stableFrames=0,n&&(this.scrollState.lastTargetOffset=t,this.scrollState.behavior=`auto`,this._scrollToOffset(t,{adjustments:void 0,behavior:`auto`}));this.scheduleScrollReconcile()}},vk=(e,t,n,r)=>{for(;e<=t;){let i=(e+t)/2|0,a=n(i);if(a<r)e=i+1;else if(a>r)t=i-1;else return i}return e>0?e-1:0};function yk({measurements:e,outerSize:t,scrollOffset:n,lanes:r}){let i=e.length-1,a=t=>e[t].start;if(e.length<=r)return{startIndex:0,endIndex:i};let o=vk(0,i,a,n),s=o;if(r===1)for(;s<i&&e[s].end<n+t;)s++;else if(r>1){let a=Array(r).fill(0);for(;s<i&&a.some(e=>e<n+t);){let t=e[s];a[t.lane]=t.end,s++}let c=Array(r).fill(n+t);for(;o>=0&&c.some(e=>e>=n);){let t=e[o];c[t.lane]=t.start,o--}o=Math.max(0,o-o%r),s=Math.min(i,s+(r-1-s%r))}return{startIndex:o,endIndex:s}}var bk=typeof document<`u`?_.useLayoutEffect:_.useEffect;function xk({useFlushSync:e=!0,...t}){let n=_.useReducer(()=>({}),{}
70)[1],r={...t,onChange:(r,i)=>{var a;e&&i?(0,v.flushSync)(n):n(),(a=t.onChange)==null||a.call(t,r,i)}},[i]=_.useState(()=>new _k(r));return i.setOptions(r),bk(()=>i._didMount(),[]),bk(()=>i._willUpdate()),i}function Sk(e){return xk({observeElementRect:dk,observeElementOffset:mk,scrollToFn:gk,...e})}var Ck=_.forwardRef(({className:e,...t},n)=>(0,L.jsx)(yv,{className:V(`peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input`,e),...t,ref:n,children:(0,L.jsx)(bv,{className:V(`pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0`)})}));Ck.displayName=yv.displayName;var wk=V_,Tk=J_,Ek=U_,Dk=_.forwardRef(({className:e,children:t,...n},r)=>(0,L.jsxs)(H_,{ref:r,className:V(`flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1`,e),...n,children:[t,(0,L.jsx)(W_,{asChild:!0,children:(0,L.jsx)(zC,{className:`h-4 w-4 opacity-50`})})]}));Dk.displayName=H_.displayName;var Ok=_.forwardRef(({className:e,children:t,position:n=`popper`,...r},i)=>(0,L.jsx)(G_,{children:(0,L.jsxs)(K_,{ref:i,className:V(`relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,n===`popper`&&`data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1`,e),position:n,...r,children:[(0,L.jsx)(Mk,{}),(0,L.jsx)(q_,{className:V(`p-1`,n===`popper`&&`h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]`),children:t}),(0,L.jsx)(Nk,{})]})}));Ok.displayName=K_.displayName;var kk=_.forwardRef(({className:e,...t},n)=>(0,L.jsx)(Y_,{ref:n,className:V(`px-2 py-1.5 text-sm font-semibold`,e),...t}));kk.displayName=Y_.displayName;var Ak=_.forwardRef(({className:e,children:t,...n},r)=>(0,L.jsxs)(X_,{ref:r,className:V(`relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`,e),...n,children:[(0,L.jsx)(`span`,{className:`absolute right-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,L.jsx)(Q_,{children:(0,L.jsx)(RC,{className:`h-4 w-4`})})}),(0,L.jsx)(Z_,{children:t})]}));Ak.displayName=X_.displayName;var jk=_.forwardRef(({className:e,...t},n)=>(0,L.jsx)(tv,{ref:n,className:V(`-mx-1 my-1 h-px bg-muted`,e),...t}));jk.displayName=tv.displayName;var Mk=_.forwardRef(({className:e,...t},n)=>(0,L.jsx)($_,{ref:n,className:V(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,L.jsx)(HC,{className:`h-4 w-4`})}));Mk.displayName=$_.displayName;var Nk=_.forwardRef(({className:e,...t},n)=>(0,L.jsx)(ev,{ref:n,className:V(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,L.jsx)(zC,{className:`h-4 w-4`})}));Nk.displayName=ev.displayName;function Pk({className:e,...t}){return(0,L.jsx)(`div`,{"data-slot":`table-container`,className:`relative w-full overflow-x-auto`,children:(0,L.jsx)(`table`,{"data-slot":`table`,className:V(`w-full caption-bottom text-sm`,e),...t})})}function Fk({className:e,...t}){return(0,L.jsx)(`thead`,{"data-slot":`table-header`,className:V(`[&_tr]:border-b`,e),...t})}function Ik({className:e,...t}){return(0,L.jsx)(`tbody`,{"data-slot":`table-body`,className:V(`[&_tr:last-child]:border-0`,e),...t})}function Lk({className:e,...t}){return(0,L.jsx)(`tr`,{"data-slot":`table-row`,className:V(`border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted`,e),...t})}function J({className:e,...t}){return(0,L.jsx)(`th`,{"data-slot":`table-head`,className:V(`h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]`,e),...t})}function Y({className:e,...t}){return(0,L.jsx)(`td`,{"data-slot":`table-cell`,className:V(`p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]`,e),...t})}function Rk({...e}){return(0,L.jsx)(rh,{"data-slot":`context-menu`,...e})}function zk({...e}){return(0,L.jsx)(ih,{"data-slot":`context-menu-trigger`,...e})}function Bk({className:e,...t}){return(0,L.jsx)(ah,{children:(0,L.jsx)(oh,{"data-slot":`context-menu-content`,className:V(`z-50 max-h-(--radix-context-menu-content-available-height) min-w-[8rem] origin-(--radix-context-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95`,e),...t})})}function Vk({className:e,inset:t,variant:n=`default`,...r}){return(0,L.jsx)(sh,{"data-slot":`context-menu-item`,"data-inset":t,"data-variant":n,className:V(`relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!`,e),...r})}function Hk({className:e,...t}){return(0,L.jsx)(ch,{"data-slot":`context-menu-separator`,className:V(`-mx-1 my-1 h-px bg-border`,e),...t})}function Uk(e){return`"${(e==null?``:String(e)).replace(/"/g,`""`)}"`}
70function Wk(e,t,n){let r=[e.map(Uk).join(`,`),...t.map(e=>e.map(Uk).join(`,`))].join(` 71`),i=new Blob([r],{type:`text/csv;charset=utf-8;`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=n,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(a)}var Gk=[`widget`,`page_form`,`instabot`,`consult_page`,`sheet`,`chat`,`manual`,`csv`,`simulation`,`sandbox`],Kk={widget:`Widget`,page_form:`Page form`,instabot:`InstaBot`,consult_page:`Consult page`,sheet:`Sheet`,chat:`Chat`,manual:`Manual`,csv:`CSV`,simulation:`Simulation`,sandbox:`Sandbox`},qk={widget:`Submitted through our website widget`,page_form:`Submitted through a hosted page-form link`,instabot:`Captured by the InstaBot bot on the website and synced from the Google Sheet`,consult_page:`Submitted on the consultation page and synced from the Google Sheet`,sheet:`Synced from the Google Sheet with no recognisable signup page`,chat:`Created from a WhatsApp conversation in the inbox`,manual:`Created by hand with the New Lead form`,csv:`Imported from a CSV file`,simulation:`Created as a test lead by the simulation tool, not a real inquiry`,sandbox:`Created as a test lead in the WhatsApp sandbox, not a real inquiry`},Jk={widget:`bg-blue-100 text-blue-800 border-blue-200 dark:bg-blue-950/40 dark:text-blue-300 dark:border-blue-900`,page_form:`bg-teal-100 text-teal-800 border-teal-200 dark:bg-teal-950/40 dark:text-teal-300 dark:border-teal-900`,instabot:`bg-violet-100 text-violet-800 border-violet-200 dark:bg-violet-950/40 dark:text-violet-300 dark:border-violet-900`,consult_page:`bg-indigo-100 text-indigo-800 border-indigo-200 dark:bg-indigo-950/40 dark:text-indigo-300 dark:border-indigo-900`,sheet:`bg-green-100 text-green-800 border-green-200 dark:bg-green-950/40 dark:text-green-300 dark:border-green-900`,chat:`bg-amber-100 text-amber-800 border-amber-200 dark:bg-amber-950/40 dark:text-amber-300 dark:border-amber-900`,manual:`bg-slate-100 text-slate-700 border-slate-200 dark:bg-slate-800 dark:text-slate-300 dark:border-slate-700`,csv:`bg-orange-100 text-orange-800 border-orange-200 dark:bg-orange-950/40 dark:text-orange-300 dark:border-orange-900`,simulation:`bg-transparent text-muted-foreground border-dashed border-muted-foreground/40`,sandbox:`bg-transparent text-muted-foreground border-dashed border-muted-foreground/40`},Yk=new Set([`widget`,`instabot`,`consult_page`,`sheet`]),Xk=new Set([`none`,`null`,`n/a`,`na`,`-`,`â`]);function Zk(e){let t=e?.trim().toLowerCase();return!t||Xk.has(t)}function Qk(e){return Zk(e)?void 0:e?.trim()}function $k(e){try{let t=new URL(e),n=t.pathname===`/`?``:t.pathname;return`${t.host}${n}`}catch{return e}}function eA(e){let t=e.leadProfileData??{};if(Yk.has(e.origin)){let e=Qk(t.signupPage)??Qk(t.cameFrom);return e?$k(e):null}if(e.origin===`page_form`){let e=Qk(t.pageLinkLabel)??Qk(t.landingUrl);return e?$k(e):null}return null}var tA=`leads-density-v1`,nA=[`compact`,`default`,`comfortable`],rA={compact:32,default:44,comfortable:56};function iA(){try{let e=window.localStorage.getItem(tA);if(e&&nA.includes(e))return e}catch{}return`default`}function aA(e){try{window.localStorage.setItem(tA,e)}catch{}}function oA(){let[e,t]=(0,_.useState)(()=>iA()),n=(0,_.useCallback)(e=>{t(e),aA(e)},[]);return(0,_.useEffect)(()=>{let e=e=>{e.key===tA&&e.newValue&&nA.includes(e.newValue)&&t(e.newValue)};return window.addEventListener(`storage`,e),()=>window.removeEventListener(`storage`,e)},[]),[e,n]}function sA({interval:e,source:t}){let n=t?`Syncs from ${t} every ${e}`:`Refreshes every ${e}`;return(0,L.jsx)(ex,{delayDuration:200,children:(0,L.jsxs)(tx,{children:[(0,L.jsx)(nx,{asChild:!0,children:(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs text-muted-foreground`,children:[(0,L.jsx)(Yw,{className:`h-3 w-3`}),(0,L.jsx)(`span`,{children:e})]})}),(0,L.jsx)(rx,{children:(0,L.jsx)(`p`,{children:n})})]})})}var cA=zT(`inline-flex w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-full border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-[color,box-shadow] focu
71s-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3`,{variants:{variant:{default:`bg-primary text-primary-foreground [a&]:hover:bg-primary/90`,secondary:`bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90`,destructive:`bg-destructive text-white focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40 [a&]:hover:bg-destructive/90`,outline:`border-border text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground`,ghost:`[a&]:hover:bg-accent [a&]:hover:text-accent-foreground`,link:`text-primary underline-offset-4 [a&]:hover:underline`}},defaultVariants:{variant:`default`}});function X({className:e,variant:t=`default`,asChild:n=!1,...r}){return(0,L.jsx)(n?ea:`span`,{"data-slot":`badge`,"data-variant":t,className:V(cA({variant:t}),e),...r})}function lA({...e}){return(0,L.jsx)(al,{"data-slot":`alert-dialog`,...e})}function uA({...e}){return(0,L.jsx)(ol,{"data-slot":`alert-dialog-trigger`,...e})}function dA({...e}){return(0,L.jsx)(sl,{"data-slot":`alert-dialog-portal`,...e})}function fA({className:e,...t}){return(0,L.jsx)(cl,{"data-slot":`alert-dialog-overlay`,className:V(`fixed inset-0 z-50 bg-black/50 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,e),...t})}function pA({className:e,...t}){return(0,L.jsxs)(dA,{children:[(0,L.jsx)(fA,{}),(0,L.jsx)(ll,{"data-slot":`alert-dialog-content`,className:V(`fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg`,e),...t})]})}function mA({className:e,...t}){return(0,L.jsx)(`div`,{"data-slot":`alert-dialog-header`,className:V(`flex flex-col space-y-2 text-center sm:text-left`,e),...t})}function hA({className:e,...t}){return(0,L.jsx)(`div`,{"data-slot":`alert-dialog-footer`,className:V(`flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2`,e),...t})}function gA({className:e,...t}){return(0,L.jsx)(fl,{"data-slot":`alert-dialog-title`,className:V(`text-lg font-semibold`,e),...t})}function _A({className:e,...t}){return(0,L.jsx)(pl,{"data-slot":`alert-dialog-description`,className:V(`text-sm text-muted-foreground`,e),...t})}function vA({className:e,...t}){return(0,L.jsx)(ul,{className:V(qT(),e),...t})}function yA({className:e,...t}){return(0,L.jsx)(dl,{className:V(qT({variant:`outline`}),`mt-2 sm:mt-0`,e),...t})}var bA=[`new`,`contacted`,`qualified`,`awaiting_consent`,`consent_declined`,`interested`,`not_interested`,`lost`,`skipped`,`backlogged`],xA=[`backlogged`],SA=[`new`,`contacted`,`qualified`,`awaiting_consent`,`consent_declined`,`interested`,`not_interested`,`lost`,`skipped`],CA=[`new`,`contacted`,`qualified`,`interested`,`not_interested`,`lost`,`skipped`];function wA(e){return xA.includes(e)}var TA=[`hot`,`warm`,`cold`,`new`],EA=[`hot`,`warm`,`cold`];function DA(e){return!EA.includes(e)}var Z=_.forwardRef(({className:e,...t},n)=>(0,L.jsx)(`label`,{ref:n,className:V(`text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70`,e),...t}));Z.displayName=`Label`;function OA({...e}){return(0,L.jsx)(wg,{"data-slot":`popover`,...e})}function kA({...e}){return(0,L.jsx)(Tg,{"data-slot":`popover-trigger`,...e})}function AA({className:e,align:t=`start`,sideOffset:n=4,...r}){return(0,L.jsx)(Eg,{children:(0,L.jsx)(Dg,{"data-slot":`popover-content`,align:t,sideOffset:n,className:V(`z-50 w-72 rounded-md border bg-popover p-3 text-popover-foreground shadow-md outline-none data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:sli
71de-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95`,e),...r})})}var jA=new Set([`not_interested`,`consent_declined`,`lost`,`skipped`,`backlogged`]),MA={follow_up_intervals:[1,3,7],max_followups:3,qualification_timeout_hours:48,qualification_lost_hours:96,grace_period_days_before_lost:3};function NA(){let{data:e}=vi({queryKey:[`ai-config`,`scheduling`],queryFn:async()=>(await H(`/api/ai-config/scheduling`)).data,staleTime:60*1e3});return e??MA}var PA=jA;function FA(e){let t=e.toLocaleDateString(void 0,{weekday:`short`,day:`numeric`,month:`short`}),n=e.getHours(),r=e.getMinutes(),i=n>=12?`pm`:`am`,a=n%12||12;return`${t}, ${r===0?`${a}${i}`:`${a}:${String(r).padStart(2,`0`)}${i}`}`}function IA(e){let t=e.getTime()-Date.now(),n=Math.abs(t),r=Math.round(n/(24*3600*1e3)),i=Math.round(n/(3600*1e3));return t<0?i<24?`${i}h ago`:`${r}d ago`:i<1?`in <1h`:i<24?`in ${i}h`:`in ${r}d`}function LA(e,t){if(!e.nextFollowUpAt)return[];let n=[],r=new Date(e.nextFollowUpAt),i=e.followUpCount,a=Math.min(t.max_followups,t.follow_up_intervals.length);if(i>=a)return n.push({label:`Mark as lost (no reply)`,date:r,isCurrent:!0,isTerminal:!0}),n;n.push({label:`Follow-up #${i+1} of ${a}`,date:r,isCurrent:!0});for(let e=i+1;e<a;e++){let i=t.follow_up_intervals[e],o=new Date(r.getTime()+i*24*3600*1e3);n.push({label:`Follow-up #${e+1} of ${a}`,date:o}),r=o}let o=new Date(r.getTime()+t.grace_period_days_before_lost*24*3600*1e3);return n.push({label:`Mark as lost (no reply)`,date:o,isTerminal:!0}),n}function RA(e,t){if(!e.lastContactedAt)return null;let n=new Date(e.lastContactedAt);return{nudgeAt:new Date(n.getTime()+t.qualification_timeout_hours*3600*1e3),lostAt:new Date(n.getTime()+t.qualification_lost_hours*3600*1e3),nudgeFired:e.qualificationNudgeCount>=1,nudgeHours:t.qualification_timeout_hours,lostHours:t.qualification_lost_hours}}function zA({source:e,hasSchedule:t}){return e?e===`default`?(0,L.jsxs)(X,{variant:`secondary`,className:`text-xs gap-1`,children:[(0,L.jsx)(IC,{className:`h-3 w-3`}),` Default`]}):e===`ai`?(0,L.jsxs)(X,{variant:`outline`,className:`text-xs gap-1 border-blue-300 text-blue-700 bg-blue-50`,children:[(0,L.jsx)(MC,{className:`h-3 w-3`}),` AI`]}):e===`manual`?(0,L.jsxs)(X,{variant:`outline`,className:`text-xs gap-1 border-purple-300 text-purple-700 bg-purple-50`,children:[(0,L.jsx)(AT,{className:`h-3 w-3`}),` Manual`]}):(0,L.jsxs)(X,{variant:`outline`,className:`text-xs gap-1 border-orange-300 text-orange-700 bg-orange-50`,children:[(0,L.jsx)(qC,{className:`h-3 w-3`}),` Paused`]}):t?(0,L.jsxs)(X,{variant:`secondary`,className:`text-xs gap-1`,children:[(0,L.jsx)(IC,{className:`h-3 w-3`}),` Default`]}):null}function BA(){let e=new Date;return e.setDate(e.getDate()+1),e.setHours(10,0,0,0),e}function VA(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function HA(e){return`${String(e.getHours()).padStart(2,`0`)}:${String(e.getMinutes()).padStart(2,`0`)}`}function UA({initialDate:e,initialReason:t,onSave:n,onCancel:r,isSaving:i}){let a=e??BA(),[o,s]=(0,_.useState)(VA(a)),[c,l]=(0,_.useState)(HA(a)),[u,d]=(0,_.useState)(t??``),f=(e,t)=>{let n=new Date;n.setTime(n.getTime()+e*3600*1e3),t!==void 0&&n.setHours(t,0,0,0),s(VA(n)),l(HA(n))},p=()=>{if(!o||!c){z.error(`Pick a date and time`);return}let e=new Date(`${o}T${c}`);if(isNaN(e.getTime())){z.error(`Invalid date or time`);return}if(e.getTime()<=Date.now()){z.error(`Scheduled time must be in the future`);return}n(e,u.trim())},m=VA(new Date);return(0,L.jsxs)(`div`,{className:`space-y-3`,children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[(0,L.jsx)(W,{type:`button`,variant:`outline`,size:`sm`,className:`text-xs h-7`,onClick:()=>f(24,10),children:`Tomorrow 10am`}),(0,L.jsx)(W,{type:`button`,variant:`outline`,size:`sm`,className:`text-xs h-7`,onClick:()=>f(72),children:`+3 days`}),(0,L.jsx)(W,{type:`button`,variant:`outline`,size:`sm`,className:`text-xs h-7`,onClick:()=>f(168),children:`+1 week`}),(0,L.jsx)(W,{type:`button`,variant:`outline`,size:`sm`,className:`text-xs h-7`,onClick:()=>f(336),children:`+2 weeks`})]}),(0,L.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsx)(Z,{className:`text-xs`,children:`Date`}),(0,L.jsx)(G,{type:`date`,value:o,min:m,onChange:e=>s(e.target.value),className:`h-8 text-sm`})]}),(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsx)(Z,{className:`text-xs`,children:`Time`}),(0,L.jsx)(G,{type:`time`,value:c,onChange:e=>l(e.target.value),className:`h-8 text-sm`})]})]}),(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsx)(Z,{className:`text-xs`,children:`Reason (optional)`}),(0,L.jsx)(TD,{value:u,onChange:e=>d(e.target.value),placeholder:`e.g. Lead asked to chat next week`,className:`min-h-[60
71px] resize-none text-sm`})]}),(0,L.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,L.jsx)(W,{type:`button`,variant:`ghost`,size:`sm`,onClick:r,disabled:i,children:`Cancel`}),(0,L.jsx)(W,{type:`button`,size:`sm`,onClick:p,disabled:i,children:i?`Savingâ¦`:`Save`})]})]})}function WA({lead:e,variant:t,onUpdate:n}){let[r,i]=(0,_.useState)(!1),a=ri(),o=PA.has(e.status),s=e.status===`new`,c=e.qualificationMode===`qualifying`,l=e.scheduleSource===`paused`,u=!o&&!s&&!c,d=R({mutationFn:t=>H(`/api/leads/${e.id}/follow-up-schedule`,{method:`POST`,body:JSON.stringify({scheduledAt:t.scheduledAt.toISOString(),reason:t.reason||void 0})}),onSuccess:()=>{z.success(`Follow-up scheduled`),i(!1),n?.(),a.invalidateQueries({queryKey:[`lead-detail`,e.id]}),a.invalidateQueries({queryKey:[`leads`]}),a.invalidateQueries({queryKey:[`conversation-details`]})},onError:e=>z.error(e.message)}),f=R({mutationFn:()=>H(`/api/leads/${e.id}/follow-up-schedule`,{method:`DELETE`}),onSuccess:()=>{z.success(`Follow-up cleared â AI scheduling paused`),n?.(),a.invalidateQueries({queryKey:[`lead-detail`,e.id]}),a.invalidateQueries({queryKey:[`leads`]}),a.invalidateQueries({queryKey:[`conversation-details`]})},onError:e=>z.error(e.message)}),p=R({mutationFn:()=>H(`/api/leads/${e.id}/follow-up-schedule/resume`,{method:`POST`}),onSuccess:()=>{z.success(`AI scheduling resumed`),n?.(),a.invalidateQueries({queryKey:[`lead-detail`,e.id]}),a.invalidateQueries({queryKey:[`leads`]}),a.invalidateQueries({queryKey:[`conversation-details`]})},onError:e=>z.error(e.message)});return t===`compact`?(0,L.jsx)(KA,{lead:e,editable:u,isPaused:l,isQualifying:c,pickerOpen:r,setPickerOpen:i,onSave:(e,t)=>d.mutate({scheduledAt:e,reason:t}),onClear:()=>f.mutate(),onResume:()=>p.mutate(),isSaving:d.isPending,isClearing:f.isPending,isResuming:p.isPending}):(0,L.jsx)(GA,{lead:e,editable:u,isNew:s,isTerminal:o,isPaused:l,isQualifying:c,pickerOpen:r,setPickerOpen:i,onSave:(e,t)=>d.mutate({scheduledAt:e,reason:t}),onClear:()=>f.mutate(),onResume:()=>p.mutate(),isSaving:d.isPending,isClearing:f.isPending,isResuming:p.isPending})}function GA(e){let{lead:t,editable:n,isNew:r,isTerminal:i,isPaused:a,isQualifying:o,pickerOpen:s,setPickerOpen:c,onSave:l,onClear:u,onResume:d,isSaving:f,isClearing:p,isResuming:m}=e,h=NA(),g=o?[]:LA(t,h),_=o?RA(t,h):null,v=t.nextFollowUpAt?new Date(t.nextFollowUpAt):null;return(0,L.jsxs)(`div`,{className:`space-y-3 border rounded-lg p-3 bg-card`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsxs)(`h3`,{className:`text-sm font-medium flex items-center gap-1.5`,children:[(0,L.jsx)(IC,{className:`h-3.5 w-3.5`}),`Follow-up schedule`]}),(0,L.jsx)(zA,{source:t.scheduleSource,hasSchedule:!!t.nextFollowUpAt})]}),r&&(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Lead has not been contacted yet â scheduling will start after initial outreach.`}),i&&(0,L.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Lead is `,t.status.replace(/_/g,` `),` â no follow-ups scheduled.`]}),!r&&!i&&a&&(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Follow-ups paused. The AI will not schedule or send any messages until resumed.`}),!r&&!i&&!a&&v&&!o&&(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsxs)(`div`,{className:`text-sm`,children:[(0,L.jsx)(`span`,{className:`font-medium`,children:`Next:`}),` `,FA(v),` `,(0,L.jsxs)(`span`,{className:`text-muted-foreground`,children:[`(`,IA(v),`)`]})]}),t.scheduleReason&&(0,L.jsx)(`div`,{className:`text-xs text-muted-foreground line-clamp-2`,children:t.scheduleReason})]}),!r&&!i&&!a&&!v&&!o&&(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No follow-up scheduled. AI will reschedule on the next interaction, or override manually below.`}),!o&&!a&&g.length>0&&(0,L.jsxs)(`div`,{className:`space-y-1.5 pt-1`,children:[(0,L.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground`,children:`If no reply`}),(0,L.jsx)(`ul`,{className:`space-y-1 text-xs`,children:g.map((e,t)=>(0,L.jsxs)(`li`,{className:`flex items-center justify-between ${e.isCurrent?`text-foreground font-medium`:`text-muted-foreground`}`,children:[(0,L.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,L.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full ${e.isCurrent?`bg-foreground`:e.isTerminal?`bg-red-400`:`bg-muted-foreground
71/40`}`}),e.label]}),(0,L.jsx)(`span`,{children:FA(e.date)})]},t))})]}),o&&_&&!a&&(0,L.jsxs)(`div`,{className:`space-y-1.5 pt-1`,children:[(0,L.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground`,children:`Qualification timing`}),(0,L.jsxs)(`ul`,{className:`space-y-1 text-xs`,children:[(0,L.jsxs)(`li`,{className:`flex items-center justify-between`,children:[(0,L.jsxs)(`span`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,L.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full bg-muted-foreground/40`}),`Last activity`]}),(0,L.jsx)(`span`,{children:t.lastContactedAt?FA(new Date(t.lastContactedAt)):`â`})]}),(0,L.jsxs)(`li`,{className:`flex items-center justify-between ${_.nudgeFired?`text-muted-foreground line-through`:`text-foreground font-medium`}`,children:[(0,L.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,L.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full bg-foreground`}),`Nudge (`,_.nudgeHours,`h silence)`]}),(0,L.jsx)(`span`,{children:FA(_.nudgeAt)})]}),(0,L.jsxs)(`li`,{className:`flex items-center justify-between text-muted-foreground`,children:[(0,L.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,L.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full bg-red-400`}),`Mark as lost (`,_.lostHours,`h)`]}),(0,L.jsx)(`span`,{children:FA(_.lostAt)}
71)]})]})]}),!i&&!o&&(0,L.jsx)(`div`,{className:`flex flex-wrap gap-2 pt-1`,children:r?(0,L.jsxs)(tx,{children:[(0,L.jsx)(nx,{asChild:!0,children:(0,L.jsx)(`span`,{className:`inline-block`,children:(0,L.jsxs)(W,{size:`sm`,variant:`outline`,disabled:!0,children:[(0,L.jsx)(Bw,{className:`h-3.5 w-3.5 mr-1`}),`Override`]})})}),(0,L.jsx)(rx,{children:`Lead must be contacted first`})]}):a?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(W,{size:`sm`,onClick:()=>c(!s),disabled:f,children:[(0,L.jsx)(Bw,{className:`h-3.5 w-3.5 mr-1`}),`Schedule a follow-up`]}),(0,L.jsxs)(W,{size:`sm`,variant:`outline`,onClick:d,disabled:m,children:[(0,L.jsx)(JC,{className:`h-3.5 w-3.5 mr-1`}),`Resume AI`]})]}):t.scheduleSource===`manual`?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(W,{size:`sm`,variant:`outline`,onClick:()=>c(!s),disabled:f,children:[(0,L.jsx)(Bw,{className:`h-3.5 w-3.5 mr-1`}),s?`Cancel`:`Update`]}),(0,L.jsxs)(W,{size:`sm`,variant:`outline`,onClick:u,disabled:p,children:[(0,L.jsx)(FT,{className:`h-3.5 w-3.5 mr-1`}),`Clear`]}),(0,L.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:d,disabled:m,children:[(0,L.jsx)(JC,{className:`h-3.5 w-3.5 mr-1`}),`Resume AI`]})]}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(W,{size:`sm`,variant:`outline`,onClick:()=>c(!s),disabled:f,children:[(0,L.jsx)(Bw,{className:`h-3.5 w-3.5 mr-1`}),s?`Cancel`:`Override`]}),(0,L.jsxs)(W,{size:`sm`,variant:`outline`,onClick:u,disabled:p,children:[(0,L.jsx)(FT,{className:`h-3.5 w-3.5 mr-1`}),`Clear`]})]})}),n&&s&&(0,L.jsx)(`div`,{className:`border-t pt-3`,children:(0,L.jsx)(UA,{initialDate:t.scheduleSource===`manual`&&t.nextFollowUpAt?new Date(t.nextFollowUpAt):void 0,initialReason:t.scheduleSource===`manual`?t.scheduleReason??``:``,onSave:l,onCancel:()=>c(!1),isSaving:f})})]})}function KA(e){let{lead:t,editable:n,isPaused:r,isQualifying:i,pickerOpen:a,setPickerOpen:o,onSave:s,onClear:c,onResume:l,isSaving:u,isClearing:d,isResuming:f}=e,p=NA(),m=t.nextFollowUpAt?new Date(t.nextFollowUpAt):null,h=i?RA(t,p):null,g;return g=r?`Paused`:m&&!i?FA(m):h&&!h.nudgeFired?`Nudge ${IA(h.nudgeAt)}`:h?`Lost ${IA(h.lostAt)}`:`Not scheduled`,(0,L.jsxs)(OA,{open:a,onOpenChange:o,children:[(0,L.jsx)(kA,{asChild:!0,children:(0,L.jsxs)(`button`,{type:`button`,disabled:!n,className:`w-full flex items-center justify-between gap-2 rounded-md border bg-card px-3 py-2 text-sm hover:bg-accent disabled:opacity-60 disabled:cursor-not-allowed`,children:[(0,L.jsxs)(`span`,{className:`flex items-center gap-2 min-w-0`,children:[(0,L.jsx)(IC,{className:`h-3.5 w-3.5 shrink-0`}),(0,L.jsx)(`span`,{className:`truncate`,children:g})]}),(0,L.jsxs)(`span`,{className:`flex items-center gap-1.5 shrink-0`,children:[(0,L.jsx)(zA,{source:t.scheduleSource,hasSchedule:!!t.nextFollowUpAt}),(0,L.jsx)(zC,{className:`h-3.5 w-3.5 text-muted-foreground`})]})]})}),(0,L.jsx)(AA,{className:`w-[360px] p-3`,align:`end`,children:(0,L.jsxs)(`div`,{className:`space-y-3`,children:[(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsx)(`div`,{className:`text-sm font-medium`,children:`Follow-up schedule`}),m&&(0,L.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[`Next: `,FA(m)]}),t.scheduleReason&&(0,L.jsx)(`div`,{className:`text-xs text-muted-foreground line-clamp-2`,children:t.scheduleReason})]}),n&&!r&&(0,L.jsx)(UA,{initialDate:t.scheduleSource===`manual`&&t.nextFollowUpAt?new Date(t.nextFollowUpAt):void 0,initialReason:t.scheduleSource===`manual`?t.scheduleReason??``:``,onSave:s,onCancel:()=>o(!1),isSaving:u}),n&&r&&(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Follow-ups are paused. Schedule a date or hand control back to AI.`}),(0,L.jsx)(UA,{onSave:s,onCancel:()=>o(!1),isSaving:u})]}),n&&(0,L.jsxs)(`div`,{className:`flex flex-wrap gap-2 pt-2 border-t`,children:[!r&&(0,L.jsxs)(W,{size:`sm`,variant:`outline`,className:`text-xs h-7`,onClick:c,disabled:d,children:[(0,L.jsx)(FT,{className:`h-3 w-3 mr-1`}),`Clear`]}),(r||t.scheduleSource===`manual`)&&(0,L.jsxs)(W,{size:`sm`,variant:`ghost`,className:`text-xs h-7`,onClick:l,disabled:f,children:[(0,L.jsx)(JC,{className:`h-3 w-3 mr-1`}),`Resume AI`]})]}),!n&&(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t.status===`new`?`Lead must be contacted first.`:`Lead is ${t.status.replace(/_/g,` `)} â no follow-ups.`})]})})]})}function qA({origin:e,leadProfileData:t,className:n}){let r=Kk[e];if(!r)return null;let i=eA({origin:e,leadProfileData:t});return(0,L.jsxs)(tx,{children:[(0,L.jsx)(nx,{asChild:!0,children:(0,L.jsx)(X,{variant:`outline`,className:V(Jk[e],n),children:r})}),(0,L.jsxs)(rx,{children:[(0,L.jsx)(`p`,{children:qk[e]}),i&&(0,L.jsx)(`p`,{className:`mt-0.5 text-background/70`,children:i})]})]})}var JA=/^\d+$/,YA=[`signupPage`,`cameFrom`,`referrer`,`utmSource`,`utmMedium`,`utmCampaign`,`pageLinkLabel`,`landingUrl`],XA={signupPage:`Signup page`,cameFrom:`Came from`,referrer:`Referrer`,utmSource:`UTM source`,utmMedium:`UTM medium`,utmCampaign:`UTM campaign`,pageLinkLabel:`Page link`,landingUrl:`Landing page`};function ZA(e){let t=e??{},n=[],r=(e,t,r)=>{Zk(r)||n.push({key:e,label:t,value:r.trim()})};for(let e of YA)r(e,XA[e],t[e]);return t.widget&&JA.test(t.widget.trim())&&r(`widget`,`InstaBot widget id`,t.widget),n}var QA=/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z?/g;function $A(e){let t=e.toLocaleDateString(),n=e.getHours(),r=e.getMinutes(),i=n>=12?`pm`:`am`,a=n%12||12;return`${t}, ${r===0?`${a}${i}`:`${a}
71:${String(r).padStart(2,`0`)}${i}`}`}function ej(e){let t=e.match(QA);return t?t.map(e=>{let t=new Date(e);return isNaN(t.getTime())?e:$A(t)}).filter((e,t,n)=>n.indexOf(e)===t).join(` / `):e}function tj({rows:e}){return e.length===0?null:(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(`h3`,{className:`text-sm font-medium`,children:`Attribution`}),(0,L.jsx)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-2 text-sm`,children:e.map(e=>(0,L.jsxs)(`div`,{className:`min-w-0`,children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:e.label}),(0,L.jsx)(`p`,{className:`break-all`,title:e.value,children:e.value})]},e.key))})]})}function nj(e){return(0,L.jsx)(Ak,{value:e,disabled:!0,children:e.replace(/_/g,` `)})}var rj=1e3;function ij({leadId:e,open:t,onClose:n}){let r=ri(),i=et(),a=GT(),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(0),f=(0,_.useRef)(``),p=(0,_.useRef)(0),m=(0,_.useRef)(0),h=(0,_.useRef)(!1),g=(0,_.useRef)([]),v=(0,_.useRef)({session:0,base:``}),y=(0,_.useRef)(void 0),[b,x]=(0,_.useState)(`profile`),{data:S,isLoading:C,refetch:w}=vi({queryKey:[`lead-detail`,e],queryFn:()=>H(`/api/leads/${e}`),enabled:!!e&&t,staleTime:3e4}),{data:T}=vi({queryKey:[`lead-history`,e],queryFn:()=>H(`/api/leads/${e}/history`),enabled:!!e&&t&&b===`history`}),{data:E}=vi({queryKey:[`lead-assignments`,e],queryFn:()=>H(`/api/leads/${e}/assignments`),enabled:!!e&&t&&b===`assignments`}),{data:D}=vi({queryKey:[`agents-list`],queryFn:()=>H(`/api/agents`),enabled:t}),O=S?.data,k=O?.notes??``,[A,j]=(0,_.useState)(null),[M,ee]=(0,_.useState)(``);if(!t)A!==null&&j(null);else if(O){let e=O.id!==A,t=k!==M;e||t&&o===c?(j(O.id),ee(k),d(e=>e+1),s(k),l(k)):t&&ee(k)}(0,_.useEffect)(()=>{p.current=u,f.current=c},[u,c]);let N=R({mutationFn:t=>H(`/api/leads/${e}`,{method:`PUT`,body:JSON.stringify(t)}),onSuccess:()=>{r.invalidateQueries({queryKey:[`lead-detail`,e]}),r.invalidateQueries({queryKey:[`leads`]}),r.invalidateQueries({queryKey:[`lead-history`,e]})},onError:e=>z.error(e.message)}),P=R({mutationFn:e=>H(`/api/leads/${e.leadId}`,{method:`PUT`,body:JSON.stringify({notes:e.notes,notesBase:e.base})}),onSuccess:(e,t)=>{if(r.invalidateQueries({queryKey:[`lead-detail`,t.leadId]}),r.invalidateQueries({queryKey:[`leads`]}),r.invalidateQueries({queryKey:[`lead-history`,t.leadId]}),F(t))return;let n=t.notes??``;(e.data?.notes??``).startsWith(n)||console.warn(`Notes save: stored body is not an extension of the body sent`),v.current={session:t.session,base:n},t.session===p.current&&l(n)},onError:async(e,t)=>{if(!F(t)){if(e instanceof lC&&e.status===409){if(g.current=g.current.filter(e=>e.session!==t.session),t.session!==p.current){z.error(`An earlier notes edit could not be saved - those notes changed elsewhere.`);return}z.error(`Notes were updated elsewhere - refreshing with the latest.`);let e=(await w()).data?.data?.notes??``;f.current=e,p.current+=1,d(e=>e+1),s(e),l(e);return}z.error(e.message)}},onSettled:()=>{h.current=!1}});function F(e){return e.seq!==m.current||e.session!==v.current.session||e.base!==v.current.base}function I(){let e=g.current[0];if(e){if(h.current){y.current=setTimeout(I,rj);return}v.current.session!==e.session&&(v.current={session:e.session,base:e.seedBase}),g.current.shift(),h.current=!0,m.current+=1,P.mutate({leadId:e.leadId,session:e.session,seq:m.current,base:v.current.base,notes:e.value||null}),g.current.length>0&&(y.current=setTimeout(I,rj))}}let te=R({mutationFn:()=>H(`/api/leads/${e}`,{method:`DELETE`}),onSuccess:()=>{z.success(`Lead moved to trash`),r.invalidateQueries({queryKey:[`leads`]}),n()},onError:e=>z.error(e.message)}),ne=R({mutationFn:()=>H(`/api/leads/${e}/permanent`,{method:`DELETE`}),onSuccess:()=>{z.success(`Lead permanently deleted`),r.invalidateQueries({queryKey:[`leads`]}),n()},onError:e=>z.error(e.message)}),re=R({mutationFn:()=>H(`/api/leads/${e}/restore`,{method:`POST`}),onSuccess:()=>{z.success(`Lead restored`),r.invalidateQueries({queryKey:[`leads`]}),r.invalidateQueries({queryKey:[`lead-detail`,e]})},onError:e=>z.error(e.message)}),ie=(0,_.useRef)(I);(0,_.useEffect)(()=>{ie.current=I}),(0,_.useEffect)(()=>{t||ie.current()},[t]);let ae=t=>{if(s(t),!e)return;let n=p.current,r=g.current.at(-1);r&&r.session===n?r.value=t:g.current.push({leadId:e,session:n,value:t,seedBase:f.current}),y.current&&clearTimeout(y.current),y.current=setTimeout(I,rj)};(0,_.useEffect)(()=>()=>{y.current&&clearTimeout(y.current)},[]);let oe=ZA(O?.leadProfileData),se=new Set(YA);oe.some(e=>e.key===`widget`)&&se.add(`widget`);let ce=O?.leadProfileData?Object.entries(O.leadProfileData).filter(([e,t])=>t&&t.trim()&&!se.has(e)):[],le=(D?.data??[]).filter(e=>e.isActive&&e.canTakeLeads);return(0,L.jsx)(YT,{open:t,onOpenChange:e=>!e&&n(),children:(0,L.jsx)($T,{side:a?`bottom`:`right`,className:a?`h-[90vh] max-h-[90vh] overflow-y-auto p-0`:`w-[720px] sm:w-[800px] overflow-y-auto p-0`,children:C||!O?(0,L.jsx)(`div`,{className:`p-6 text-center text-muted-foreground`,children:`Loading...`}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(eE,{className:`sticky top-0 bg-background z-10 p-6 pb-4 border-b`,children:[(0,L.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,L.jsxs)(`div`,{className:`space-y-1 min-w-0`,children:[(0,L.jsx)(tE,{className:`text-lg truncate`,children:O.name}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,L.jsx)(`span`,{className:`font-mono`,children:O.phone}),O.email&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`span`,{children:`-`}),(0,L.jsx)(`span`,{className:`truncate`,children:O.email})]})]})]}),(0,L.jsxs)(W,{variant:`ghost`,size:`sm`,onClick:()=>i(`/messages?lead=${O.id}`),children:[(0,L.jsx)(Nw,{className:`h-4 w-4 mr-1`}),`Chat`]})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-3 mt-3`,children:[(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Warmth`}),(0,L.jsxs)(wk,{value:O.warmth,onValueChange:e=>N.mutate({warmth:e}),children:[(0,L.jsx)(Dk,{className:`h-8 w-28`,children:(0,L.jsx)(Ek,{})}),(0,L.jsxs)(Ok,{children:[DA(O.warmth)&&nj(O.warmth),EA.map(e=>(0,L.jsxs)(Ak,{value:e,children:[(0,L.jsx)(`span`,{className:`inline-block w-2 h-2 rounded-full mr-1.5 ${e===`hot`?`bg-red-500`:e===`warm`?`bg-orange-500`:`bg-blue-500`}`}),e]},e))]})]})]}),(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Status`}),(0,L.jsxs)(wk,{value:O.status,onValueChange:e=>N.mutate({status:e}),children:[(0,L.jsx)(Dk,{className:`h-8 w-40`,children:(0,L.jsx)(Ek,{})}),(0,L.jsxs)(Ok,{children:[wA(O.status)&&nj(O.status),SA.map(e=>(0,L.jsx)(Ak,{value:e,children:e.replace(/_/g,` `)},e))]})]})]}),(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Agent`}),(0,L.jsxs)(wk,{value:O.assignedAgentId??`none`,onValueChange:e=>N.mutate({assignedAgentId:e===`none`?null:e}),children:[(0,L.jsx)(Dk,{className:`h-8 w-44`,children:(0,L.jsx)(Ek,{placeholder:`Unassigned`})}),(0,L.jsxs)(Ok,{children:[(0,L.jsx)(Ak,{value:`none`,children:`Unassigned`}),le.map(e=>(0,L.jsx)(Ak,{value:e.id,children:e.name},e.id))]})]})]})]})]}),(0,L.jsx)(`div`,{className:`flex border-b`,children:[{key:`profile`,label:`Profile`,icon:AT},{key:`messages`,label:`Messages`,icon:Nw},{key:`assignments`,label:`Assignments`,icon:VC},{key:`history`,label:`History`,icon:vw}].map(({key:e,label:t,icon:n})=>(0,L.jsxs)(`button`,{className:`flex items-center gap-1.5 px-4 py-2.5 text-sm border-b-2 transition-colors ${b===e?`border-foreground text-foreground font-medium`:`border-transparent text-muted-foreground hover:text-foreground`}`,onClick:()=>x(e),children:[(0,L.jsx)(n,{className:`h-3.5 w-3.5`}),t,e===`messages`&&O.messages&&O.messages.length>0&&(0,L.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`(`,O.messages.length,`)`]})]},e))}),(0,L.jsxs)(`div`,{className:`p-6 space-y-6`,children:[b===`profile`&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsxs)(`label`,{className:`text-sm font-medium flex items-center gap-1.5`,children:[(0,L.jsx)(lw,{className:`h-3.5 w-3.5`}),`Notes`]}),(0,L.jsx)(TD,{value:o,onChange:e=>ae(e.target.value),placeholder:`Add notes about this lead...`,className:`min-h-[80px] resize-y`}),(P.isPending||N.isPending)&&(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Saving...`})]}),(0,L.jsx)(WA,{lead:{id:O.id,status:O.status,qualificationMode:O.qualificationMode??null,nextFollowUpAt:O.nextFollowUpAt??null,scheduleSource:O.scheduleSource??null,scheduleReason:O.scheduleReason??null,followUpCount:O.followUpCount??0,qualificationNudgeCount:O.qualificationNudgeCount??0,lastContactedAt:O.lastContactedAt??null},variant:`full`,onUpdate:()=>{r.invalidateQueries({queryKey:[`lead-detail`,e]}),r.invalidateQueries({queryKey:[`leads`]})}}),(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(`h3`,{className:`text-sm font-medium`,children:`Details`}),(0,L.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-2 text-sm`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`Source`}),(0,L.jsx)(`p`,{children:O.source||`â`})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`Origin`}),(0,L.jsx)(`p`,{children:(0,L.jsx)(qA,{origin:O.origin,leadProfileData:O.leadProfileData})})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`Sheet Date`}
71),(0,L.jsx)(`p`,{children:O.sheetDate?ej(O.sheetDate):`â`})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`Last Contacted`}),(0,L.jsx)(`p`,{children:O.lastContactedAt?new Date(O.lastContactedAt).toLocaleDateString():`â`})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`Follow-ups sent`}),(0,L.jsxs)(`p`,{children:[O.followUpCount??0,` / 3`]})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`Created`}),(0,L.jsx)(`p`,{children:new Date(O.createdAt).toLocaleDateString()})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`Updated`}),(0,L.jsx)(`p`,{children:new Date(O.updatedAt).toLocaleDateString()})]})]})]}),(0,L.jsx)(tj,{rows:oe}),ce.length>0&&(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(`h3`,{className:`text-sm font-medium`,children:`Lead Profile`}),(0,L.jsx)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-2 text-sm`,children:ce.map(([e,t])=>(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`span`,{className:`text-muted-foreground capitalize`,children:e.replace(/_/g,` `)}),(0,L.jsx)(`p`,{children:ej(t)})]},e))})]}),O.qualificationData&&Object.keys(O.qualificationData).length>0&&(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(`h3`,{className:`text-sm font-medium`,children:`Qualification Data`}),(0,L.jsx)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-2 text-sm`,children:Object.entries(O.qualificationData).map(([e,t])=>(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`span`,{className:`text-muted-foreground capitalize`,children:e.replace(/_/g,` `)}),(0,L.jsx)(`p`,{children:String(t??`â`)})]},e))})]}),(0,L.jsx)(JT,{}),O.deletedAt?(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`This lead is in trash (deleted `,new Date(O.deletedAt).toLocaleDateString(),`). It will be permanently deleted 30 days after deletion.`]}),(0,L.jsxs)(W,{variant:`outline`,size:`sm`,className:`w-full`,onClick:()=>re.mutate(),children:[(0,L.jsx)(bC,{className:`h-4 w-4 mr-1.5`}),`Restore Lead`]}),(0,L.jsxs)(lA,{children:[(0,L.jsx)(uA,{asChild:!0,children:(0,L.jsxs)(W,{variant:`destructive`,size:`sm`,className:`w-full`,children:[(0,L.jsx)(vT,{className:`h-4 w-4 mr-1.5`}),`Permanently Delete`]})}),(0,L.jsxs)(pA,{children:[(0,L.jsxs)(mA,{children:[(0,L.jsx)(gA,{children:`Permanently delete lead?`}),(0,L.jsxs)(_A,{children:[`This will permanently delete "`,O.name,`" and all their conversations, messages, and assignments. This action cannot be undone.`]})]}),(0,L.jsxs)(hA,{children:[(0,L.jsx)(yA,{children:`Cancel`}),(0,L.jsx)(vA,{onClick:()=>ne.mutate(),className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]})]})]})]}):(0,L.jsxs)(lA,{children:[(0,L.jsx)(uA,{asChild:!0,children:(0,L.jsxs)(W,{variant:`destructive`,size:`sm`,className:`w-full`,children:[(0,L.jsx)(vT,{className:`h-4 w-4 mr-1.5`}),`Delete Lead`]})}),(0,L.jsxs)(pA,{children:[(0,L.jsxs)(mA,{children:[(0,L.jsx)(gA,{children:`Move to trash?`}),(0,L.jsxs)(_A,{children:[`"`,O.name,`" will be moved to trash and restorable for 30 days. After that, the lead and all their conversations, messages, and assignments are permanently deleted.`]})]}),(0,L.jsxs)(hA,{children:[(0,L.jsx)(yA,{children:`Cancel`}),(0,L.jsx)(vA,{onClick:()=>te.mutate(),className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]})]})]})]}),b===`messages`&&(0,L.jsx)(`div`,{className:`space-y-3`,children:!O.messages||O.messages.length===0?(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-8`,children:`No messages yet`}):O.messages.map(e=>(0,L.jsx)(`div`,{className:`flex ${e.direction===`outbound`?`justify-end`:`justify-start`}`,children:(0,L.jsxs)(`div`,{className:`max-w-[85%] rounded-lg px-3 py-2 text-sm ${e.direction===`outbound`?`bg-primary text-primary-foreground`:`bg-muted`}`,children:[e.contactName&&e.direction===`inbound`&&(0,L.jsx)(`p`,{className:`text-xs font-medium mb-0.5 opacity-70`,children:e.contactName}),(0,L.jsx)(`p`,{className:`whitespace-pre-wrap`,children:e.body}),(0,L.jsxs)(`p`,{className:`text-xs mt-1 ${e.direction===`outbound`?`text-primary-foreground
71/60`:`text-muted-foreground`}`,children:[new Date(e.timestamp).toLocaleString(),e.conversationType&&e.conversationType!==`direct`&&(0,L.jsxs)(`span`,{className:`ml-1`,children:[`(`,e.conversationType,`)`]})]})]})},e.id))}),b===`assignments`&&(0,L.jsx)(`div`,{className:`space-y-3`,children:!E?.data||E.data.length===0?(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-8`,children:`No assignments yet`}):E.data.map(e=>(0,L.jsxs)(`div`,{className:`border rounded-lg p-3 space-y-1.5`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`span`,{className:`text-sm font-medium`,children:e.agentName??`Unknown`}),(0,L.jsx)(X,{variant:`outline`,className:`text-xs`,children:e.status})]}),(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:new Date(e.createdAt).toLocaleDateString()})]}),(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground line-clamp-2`,children:e.reason}),e.failureReason&&(0,L.jsx)(`p`,{className:`text-sm text-destructive`,children:e.failureReason}),e.overrideReason&&(0,L.jsxs)(`p`,{className:`text-sm text-orange-600`,children:[`Override: `,e.overrideReason]})]},e.id))}),b===`history`&&(0,L.jsx)(`div`,{className:`space-y-3`,children:!T?.data||T.data.length===0?(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-8`,children:`No changes recorded`}):T.data.map(e=>(0,L.jsxs)(`div`,{className:`border rounded-lg p-3 space-y-1.5`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(X,{variant:`outline`,className:`text-xs`,children:e.changeType.replace(/_/g,` `)}),(0,L.jsx)(`span`,{className:`text-sm`,children:e.changedByName??`System`})]}),(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:new Date(e.createdAt).toLocaleString()})]}),(0,L.jsx)(`div`,{className:`space-y-1`,children:Object.entries(e.changes).map(([e,{old:t,new:n}])=>(0,L.jsxs)(`div`,{className:`text-sm`,children:[(0,L.jsxs)(`span`,{className:`text-muted-foreground capitalize`,children:[e.replace(/_/g,` `),`:`]}),` `,(0,L.jsx)(`span`,{className:`text-red-600 line-through`,children:String(t??`empty`)}),` `,(0,L.jsx)(`span`,{className:`text-green-600`,children:String(n??`empty`)})]},e))})]},e.id))})]})]})})})}function aj({...e}){return(0,L.jsx)(Ec,{"data-slot":`dialog`,...e})}function oj({...e}){return(0,L.jsx)(Dc,{"data-slot":`dialog-trigger`,...e})}function sj({...e}){return(0,L.jsx)(Oc,{"data-slot":`dialog-portal`,...e})}function cj({className:e,...t}){return(0,L.jsx)(kc,{"data-slot":`dialog-overlay`,className:V(`fixed inset-0 z-50 bg-black/50 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,e),...t})}function lj({className:e,children:t,...n}){return(0,L.jsxs)(sj,{children:[(0,L.jsx)(cj,{}),(0,L.jsxs)(Ac,{"data-slot":`dialog-content`,className:V(`fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg`,e),...n,children:[t,(0,L.jsxs)(Nc,{className:`absolute right-4 top-4 roun
71ded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground`,children:[(0,L.jsx)(FT,{className:`h-4 w-4`}),(0,L.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function uj({className:e,...t}){return(0,L.jsx)(`div`,{"data-slot":`dialog-header`,className:V(`flex flex-col space-y-1.5 text-center sm:text-left`,e),...t})}function dj({className:e,...t}){return(0,L.jsx)(`div`,{"data-slot":`dialog-footer`,className:V(`flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2`,e),...t})}function fj({className:e,...t}){return(0,L.jsx)(jc,{"data-slot":`dialog-title`,className:V(`text-lg font-semibold leading-none tracking-tight`,e),...t})}function pj({className:e,...t}){return(0,L.jsx)(Mc,{"data-slot":`dialog-description`,className:V(`text-sm text-muted-foreground`,e),...t})}var mj=EA,hj=CA;function gj(){let e=ri(),t=et(),[n,r]=(0,_.useState)(!1),[i,a]=(0,_.useState)({name:``,phone:``,email:``,source:``,warmth:``,status:`new`,notes:``}),o=R({mutationFn:()=>{let e={name:i.name.trim(),phone:i.phone.trim()};return i.email.trim()&&(e.email=i.email.trim()),i.source.trim()&&(e.source=i.source.trim()),i.warmth&&(e.warmth=i.warmth),i.status&&(e.status=i.status),i.notes.trim()&&(e.notes=i.notes.trim()),H(`/api/leads`,{method:`POST`,body:JSON.stringify(e)})},onSuccess:()=>{z.success(`Lead created`),e.invalidateQueries({queryKey:[`leads`]}),r(!1),a({name:``,phone:``,email:``,source:``,warmth:``,status:`new`,notes:``})},onError:e=>{e.message.includes(`in trash`)?z.error(e.message,{action:{label:`View Trash`,onClick:()=>{r(!1),t(`/leads?trash=true`)}}}):z.error(e.message)}}),s=i.name.trim().length>0&&i.phone.trim().length>0;return(0,L.jsxs)(aj,{open:n,onOpenChange:r,children:[(0,L.jsx)(oj,{asChild:!0,children:(0,L.jsxs)(W,{size:`sm`,children:[(0,L.jsx)(Gw,{className:`h-4 w-4 mr-1.5`}),`New Lead`]})}),(0,L.jsxs)(lj,{className:`sm:max-w-md`,children:[(0,L.jsx)(uj,{children:(0,L.jsx)(fj,{children:`Create Lead`})}),(0,L.jsxs)(`div`,{className:`space-y-4`,children:[(0,L.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`lead-name`,children:`Name *`}),(0,L.jsx)(G,{id:`lead-name`,value:i.name,onChange:e=>a(t=>({...t,name:e.target.value})),placeholder:`Lead name`})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`lead-phone`,children:`Phone *`}),(0,L.jsx)(G,{id:`lead-phone`,value:i.phone,onChange:e=>a(t=>({...t,phone:e.target.value})),placeholder:`+65...`})]})]}),(0,L.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`lead-email`,children:`Email`}),(0,L.jsx)(G,{id:`lead-email`,type:`email`,value:i.email,onChange:e=>a(t=>({...t,email:e.target.value})),placeholder:`[email protected]`})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`lead-source`,children:`Source`}),(0,L.jsx)(G,{id:`lead-source`,value:i.source,onChange:e=>a(t=>({...t,source:e.target.value})),placeholder:`e.g. Website, Referral`})]})]}),(0,L.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{children:`Warmth`}),(0,L.jsxs)(wk,{value:i.warmth,onValueChange:e=>a(t=>({...t,warmth:e})),children:[(0,L.jsx)(Dk,{children:(0,L.jsx)(Ek,{placeholder:`Select warmth`})}),(0,L.jsx)(Ok,{children:mj.map(e=>(0,L.jsx)(Ak,{value:e,children:e},e))})]})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{children:`Status`}),(0,L.jsxs)(wk,{value:i.status,onValueChange:e=>a(t=>({...t,status:e})),children:[(0,L.jsx)(Dk,{children:(0,L.jsx)(Ek,{})}),(0,L.jsx)(Ok,{children:hj.map(e=>(0,L.jsx)(Ak,{value:e,children:e.replace(/_/g,` `)},e))})]})]})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`lead-notes`,children:`Notes`}),(0,L.jsx)(TD,{id:`lead-notes`,value:i.notes,onChange:e=>a(t=>({...t,notes:e.target.value})),placeholder:`Any notes about this lead...`,className:`min-h-[60
71px]`})]})]}),(0,L.jsx)(dj,{children:(0,L.jsx)(W,{onClick:()=>o.mutate(),disabled:!s||o.isPending,children:o.isPending?`Creating...`:`Create Lead`})})]})]})}var _j=[`skip`,`name`,`phone`,`email`,`source`,`warmth`,`status`,`notes`];function vj(){let e=ri(),[t,n]=(0,_.useState)(!1),[r,i]=(0,_.useState)(`upload`),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(null),[d,f]=(0,_.useState)({}),p=(0,_.useRef)(null),m=()=>{i(`upload`),o(``),c(``),u(null),f({}),p.current&&(p.current.value=``)},h=R({mutationFn:async e=>{let t=await e.text(),n=new FormData;n.append(`file`,new Blob([t],{type:`text/csv`}),e.name);let r=await fetch(`/api/leads/import/preview`,{method:`POST`,credentials:`include`,body:n});if(!r.ok){let e=await r.json().catch(()=>({}));throw Error(e.error??`Upload failed: ${r.status}`)}return{text:t,preview:(await r.json()).data}},onSuccess:({text:e,preview:t})=>{o(e),u(t),f(t.mapping),i(`map`)},onError:e=>z.error(e.message)}),g=R({mutationFn:async e=>(await H(`/api/leads/import/preview`,{method:`POST`,body:JSON.stringify({csvData:a,mapping:e})})).data,onSuccess:e=>{u(e)},onError:e=>z.error(e.message)}),v=R({mutationFn:async()=>(await H(`/api/leads/import/commit`,{method:`POST`,body:JSON.stringify({csvData:a,mapping:d})})).data,onSuccess:t=>{z.success(`Imported ${t.newCount} new, ${t.updateCount} updated (${t.errorCount} errors)`),e.invalidateQueries({queryKey:[`leads`]}),n(!1),m()},onError:e=>z.error(e.message)}),y=e=>{let t=e.target.files?.[0];if(t){if(!t.name.toLowerCase().endsWith(`.csv`)){z.error(`Only .csv files are supported`);return}c(t.name),h.mutate(t)}},b=(e,t)=>{let n={...d,[e]:t};f(n),g.mutate(n)},x=!!l&&l.proposed.newCount+l.proposed.updateCount>0&&!v.isPending;return(0,L.jsxs)(aj,{open:t,onOpenChange:e=>{n(e),e||m()},children:[(0,L.jsx)(oj,{asChild:!0,children:(0,L.jsxs)(W,{variant:`outline`,size:`sm`,children:[(0,L.jsx)(CT,{className:`h-4 w-4 mr-1.5`}),`Import CSV`]})}),(0,L.jsxs)(lj,{className:`sm:max-w-2xl max-h-[85vh] overflow-y-auto`,children:[(0,L.jsx)(uj,{children:(0,L.jsx)(fj,{children:`Import leads from CSV`})}),r===`upload`&&(0,L.jsxs)(`div`,{className:`space-y-4`,children:[(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Upload a .csv file with a header row. Columns will auto-map to lead fields by name. Existing leads are matched by phone number and updated in place.`}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(Z,{htmlFor:`csv-file`,className:`sr-only`,children:`CSV file`}),(0,L.jsx)(`input`,{id:`csv-file`,ref:p,type:`file`,accept:`.csv,text/csv`,onChange:y,disabled:h.isPending,className:`block w-full text-sm text-foreground file:mr-4 file:rounded-md file:border file:border-input file:bg-background file:px-3 file:py-1.5 file:text-sm file:font-medium file:text-foreground hover:file:bg-accent`}),h.isPending&&(0,L.jsxs)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:[`Parsing `,s,`...`]})]})]}),r===`map`&&l&&(0,L.jsxs)(`div`,{className:`space-y-5`,children:[(0,L.jsxs)(`div`,{className:`text-sm`,children:[(0,L.jsx)(`span`,{className:`font-medium`,children:s}),(0,L.jsxs)(`span`,{className:`text-muted-foreground`,children:[` `,`â `,l.totalRows,` data row`,l.totalRows===1?``:`s`]})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`h3`,{className:`text-sm font-medium mb-2`,children:`Column mapping`}),(0,L.jsxs)(`div`,{className:`rounded-md border`,children:[(0,L.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-4 px-3 py-2 border-b bg-muted/40 text-xs font-medium text-muted-foreground`,children:[(0,L.jsx)(`span`,{children:`CSV column`}),(0,L.jsx)(`span`,{children:`Maps to`})]}),(0,L.jsx)(`div`,{className:`divide-y`,children:l.columns.map(e=>(0,L.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-4 px-3 py-2 items-center`,children:[(0,L.jsx)(`span`,{className:`text-sm truncate`,title:e,children:e}),(0,L.jsxs)(wk,{value:d[e]??`skip`,onValueChange:t=>b(e,t),children:[(0,L.jsx)(Dk,{className:`h-8`,children:(0,L.jsx)(Ek,{})}),(0,L.jsx)(Ok,{children:_j.map(e=>(0,L.jsx)(Ak,{value:e,children:e===`skip`?`â Skip â`:e},e))})]})]},e))})]})]}),(0,L.jsxs)(`div`,{className:`rounded-md border p-3 space-y-1 text-sm`,children:[(0,L.jsx)(`div`,{className:`font-medium`,children:`Dry-run preview`}),(0,L.jsxs)(`div`,{className:`text-muted-foreground`,children:[`Will create`,` `,(0,L.jsx)(`span`,{className:`text-foreground font-medium`,children:l.proposed.newCount}),` `,`new leads, update`,` `,(0,L.jsx)(`span`,{className:`text-foreground font-medium`,children:l.proposed.updateCount}),` `,`existing, with`,` `,(0,L.jsx)(`span`,{className:`font-medium ${l.proposed.errorCount>0?`text-red-600`:`text-foreground`}`,children:l.proposed.errorCount}),` `,`errors.`]})]}),l.errors.length>0&&(0,L.jsxs)(`div`,{className:`rounded-md border border-red-200 bg-red-50 p-3`,children:[(0,L.jsxs)(`div`,{className:`text-sm font-medium text-red-900 mb-1.5`,children:[`Errors (`,l.errors.length,`)`]}),(0,L.jsxs)(`ul`,{className:`max-h-40 overflow-y-auto space-y-0.5 text-xs text-red-800 font-mono`,children:[l.errors.slice(0,100).map((e,t)=>(0,L.jsxs)(`li`,{children:[e.row===0?`General`:`Row ${e.row}`,`: `,e.reason]},t)),l.errors.length>100&&(0,L.jsxs)(`li`,{className:`italic`,children:[`... and `,l.errors.length-100,` more`]})]})]}),l.sampleRows.length>0&&(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`h3`,{className:`text-sm font-medium mb-2`,children:`Sample rows`}),(0,L.jsx)(`div`,{className:`rounded-md border overflow-x-auto`,children:(0,L.jsxs)(`table`,{className:`text-xs w-full`,children:[(0,L.jsx)(`thead`,{className:`bg-muted/40`,children:(0,L.jsx)(`tr`,{children:l.columns.map(e=>(0,L.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium`,children:e},e))})}),(0,L.jsx)(`tbody`,{children:l.sampleRows.map((e,t)=>(0,L.jsx)(`tr`,{className:`border-t`,children:l.columns.map((t,n)=>(0,L.jsx)(`td`,{className:`px-2 py-1.5 whitespace-nowrap truncate max-w-[200px]`,children:e[n]??``},n))},t))})]})})]})]}),r===`commit`&&(0,L.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`Importing...`}),(0,L.jsx)(dj,{children:r===`map`&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(W,{variant:`outline`,onClick:m,disabled:v.isPending,children:`Start over`}),(0,L.jsx)(W,{onClick:()=>v.mutate(),disabled:!x,children:v.isPending?`Importing...`:`Import`})]})})]})]})}var yj=EA,bj=SA,xj=[{key:`phone`,label:`Phone`,type:`text`},{key:`source`,label:`Source`,type:`text`},{key:`email`,label:`Email`,type:`email`},{key:`notes`,label:`Notes`,type:`notes`}];function Sj({selectedIds:e,hiddenCount:t=0,onClear:n,trashView:r=!1,dynamicColumns:i,leadsOnPage:a}){let o=ri(),{data:s}=vi({queryKey:[`agents-list`],queryFn:()=>H(`/api/agents`)}),c=(0,_.useMemo)(()=>Array.from(e),[e]),l=(s?.data??[]).filter(e=>e.isActive&&e.canTakeLeads),u=R({mutationFn:e=>H(`/api/leads/bulk`,{method:`POST`,body:JSON.stringify(e)}),onSuccess:e=>{let{affected:t,failed:r}=e.data;r&&r>0?z.warning(`${t} leads updated, ${r}
71 failed â retry the failed ones`):t===0?z.success(`No changes - the selected leads were already up to date`):z.success(`${t} leads updated`),o.invalidateQueries({queryKey:[`leads`]}),n()},onError:e=>z.error(e.message)}),[d,f]=(0,_.useState)(!1),[p,m]=(0,_.useState)(`configure`),[h,g]=(0,_.useState)(``),[v,y]=(0,_.useState)(``),[b,x]=(0,_.useState)(`append`),S=(0,_.useMemo)(()=>{let e=xj.map(e=>({kind:`core`,key:e.key,label:e.label,type:e.type})),t=(i??[]).slice().sort((e,t)=>e.displayOrder-t.displayOrder).map(e=>({kind:`dynamic`,key:`${e.sourceTab}::${e.id}::${e.sheetHeaderName}`,label:`${e.sheetHeaderName} (${e.sourceTab===`lead_database`?`Lead DB`:`Monitoring`})`,sourceTab:e.sourceTab,jsonbKey:e.sheetHeaderName}));return[...e,...t]},[i]),C=S.find(e=>e.key===h),w=()=>{m(`configure`),g(``),y(``),x(`append`)},T=()=>{w(),f(!0)},E=e=>{f(e),e||w()},D=e=>{if(!C)return``;if(C.kind===`core`){let t=e[C.key];return typeof t==`string`&&t.length>0?t:`â`}let t=(C.sourceTab===`lead_database`?e.leadProfileData:e.extraColumns)?.[C.jsonbKey];return t&&t.length>0?t:`â`},O=(0,_.useMemo)(()=>a?a.filter(t=>e.has(t.id)).slice(0,3):[],[a,e]),k=!!C&&(C.kind===`core`&&C.type===`notes`?v.length>0:!0),A=()=>C?C.kind===`core`&&C.type===`notes`&&b===`append`?`(append) ${v}`:v===``?`(cleared)`:v:``,j=()=>{C&&(C.kind===`core`?u.mutate({action:`update_field`,leadIds:c,field:C.key,value:v,...C.type===`notes`?{notesMode:b}:{}},{onSuccess:()=>f(!1)}):u.mutate({action:`update_dynamic`,leadIds:c,key:C.jsonbKey,value:v,sourceTab:C.sourceTab},{onSuccess:()=>f(!1)}))};if(e.size===0)return null;if(r)return(0,L.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border bg-muted/50 px-4 py-2`,children:[(0,L.jsxs)(`span`,{className:`text-sm font-medium`,children:[e.size,` selected`,t>0&&(0,L.jsxs)(`span`,{className:`ml-1 text-xs font-normal text-muted-foreground`,children:[`(`,t,` hidden by current filter)`]})]}),(0,L.jsxs)(W,{variant:`outline`,size:`sm`,className:`h-8`,onClick:()=>u.mutate({action:`restore`,leadIds:c}),children:[(0,L.jsx)(bC,{className:`h-3.5 w-3.5 mr-1`}),`Restore`]}),(0,L.jsxs)(lA,{children:[(0,L.jsx)(uA,{asChild:!0,children:(0,L.jsxs)(W,{variant:`destructive`,size:`sm`,className:`h-8`,children:[(0,L.jsx)(vT,{className:`h-3.5 w-3.5 mr-1`}),`Permanently Delete`]})}),(0,L.jsxs)(pA,{children:[(0,L.jsxs)(mA,{children:[(0,L.jsxs)(gA,{children:[`Permanently delete `,e.size,` leads?`]}),(0,L.jsx)(_A,{children:`This will permanently delete the selected leads and all their conversations, messages, and assignments. This cannot be undone.`})]}),(0,L.jsxs)(hA,{children:[(0,L.jsx)(yA,{children:`Cancel`}),(0,L.jsx)(vA,{onClick:()=>u.mutate({action:`permanent_delete`,leadIds:c}),className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]})]})]}),(0,L.jsx)(W,{variant:`ghost`,size:`sm`,className:`h-8 ml-auto`,onClick:n,children:(0,L.jsx)(FT,{className:`h-3.5 w-3.5`})})]});let M=u.isPending&&e.size>50;return(0,L.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border bg-muted/50 px-4 py-2`,children:[(0,L.jsxs)(`span`,{className:`text-sm font-medium`,children:[e.size,` selected`,t>0&&(0,L.jsxs)(`span`,{className:`ml-1 font-normal text-muted-foreground`,children:[`(`,t,` hidden by current filter)`]})]}),(0,L.jsxs)(wk,{onValueChange:e=>u.mutate({action:`update_status`,leadIds:c,value:e}),children:[(0,L.jsx)(Dk,{className:`h-8 w-36`,children:(0,L.jsx)(Ek,{placeholder:`Set status`})}),(0,L.jsx)(Ok,{children:bj.map(e=>(0,L.jsx)(Ak,{value:e,children:e.replace(/_/g,` `)},e))})]}),(0,L.jsxs)(wk,{onValueChange:e=>u.mutate({action:`update_warmth`,leadIds:c,value:e}),children:[(0,L.jsx)(Dk,{className:`h-8 w-32`,children:(0,L.jsx)(Ek,{placeholder:`Set warmth`})}),(0,L.jsx)(Ok,{children:yj.map(e=>(0,L.jsx)(Ak,{value:e,children:e},e))})]}),(0,L.jsxs)(wk,{onValueChange:e=>u.mutate({action:`assign`,leadIds:c,value:e}),children:[(0,L.jsx)(Dk,{className:`h-8 w-40`,children:(0,L.jsx)(Ek,{placeholder:`Assign agent`})}),(0,L.jsx)(Ok,{children:l.map(e=>(0,L.jsx)(Ak,{value:e.id,children:e.name},e.id))})]}),(0,L.jsxs)(W,{variant:`outline`,size:`sm`,className:`h-8`,onClick:T,disabled:S.length===0,children:[(0,L.jsx)(Bw,{className:`h-3.5 w-3.5 mr-1`}),`Edit field...`]}),(0,L.jsxs)(lA,{children:[(0,L.jsx)(uA,{asChild:!0,children:(0,L.jsxs)(W,{variant:`destructive`,size:`sm`,className:`h-8`,children:[(0,L.jsx)(vT,{className:`h-3.5 w-3.5 mr-1`}),`Delete`]})}),(0,L.jsxs)(pA,{children:[(0,L.jsxs)(mA,{children:[(0,L.jsxs)(gA,{children:[`Move `,e.size,` leads to trash?`]}),(0,L.jsx)(_A,{children:`These leads will be moved to trash. You can restore them within 30 days â after that, they are permanently deleted along with their conversations, messages, and assignments.`})]}),(0,L.jsxs)(hA,{children:[(0,L.jsx)(yA,{children:`Cancel`}),(0,L.jsx)(vA,{onClick:()=>u.mutate({action:`delete`,leadIds:c}),className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]})]})]}),(0,L.jsx)(W,{variant:`ghost`,size:`sm`,className:`h-8 ml-auto`,onClick:n,children:(0,L.jsx)(FT,{className:`h-3.5 w-3.5`})}),(0,L.jsx)(aj,{open:d,onOpenChange:E,children:(0,L.jsxs)(lj,{className:`sm:max-w-md`,children:[(0,L.jsxs)(uj,{children:[(0,L.jsx)(fj,{children:p===`configure`?`Bulk edit field`:`Confirm bulk edit`}),(0,L.jsx)(pj,{children:p===`configure`?`Editing ${e.size} selected lead${e.size===1?``:`s`}.`:`Review the change before applying.`})]}),p===`configure`&&(0,L.jsxs)(`div`,{className:`space-y-4`,children:[(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{children:`Field`}),(0,L.jsxs)(wk,{value:h,onValueChange:g,children:[(0,L.jsx)(Dk,{children:(0,L.jsx)(Ek,{placeholder:`Select a field...`})}),(0,L.jsx)(Ok,{children:S.map(e=>(0,L.jsx)(Ak,{value:e.key,children:e.label},e.key))})]})]}),C&&C.kind===`core`&&C.type===`notes`&&(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{children:`Mode`}),(0,L.jsxs)(`div`,{className:`flex gap-4 text-sm`,children:[(0,L.jsxs)(`label`,{className:`flex items-center gap-1.5 cursor-pointer`,children:[(0,L.jsx)(`input`,{type:`radio`,name:`notes-mode`,value:`append`,checked:b===`append`,onChange:()=>x(`append`)}),`Append`]}),(0,L.jsxs)(`label`,{className:`flex items-center gap-1.5 cursor-pointer`,children:[(0,L.jsx)(`input`,{type:`radio`,name:`notes-mode`,value:`replace`,checked:b===`replace`,onChange:()=>x(`replace`)}),`Replace`]})]})]}),C&&(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`bulk-edit-value`,children:`New value`}),C.kind===`core`&&C.type===`notes`?(0,L.jsx)(TD,{id:`bulk-edit-value`,value:v,onCh
71ange:e=>y(e.target.value),placeholder:b===`append`?`Text to append...`:`Replacement notes...`,className:`min-h-[80px]`}):(0,L.jsx)(G,{id:`bulk-edit-value`,type:C.kind===`core`&&C.type===`email`?`email`:`text`,value:v,onChange:e=>y(e.target.value),placeholder:`New ${C.label} value...`}),C.kind===`core`&&C.type!==`notes`&&(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Leave empty to clear the field.`})]})]}),p===`preview`&&C&&(0,L.jsxs)(`div`,{className:`space-y-4 text-sm`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`span`,{className:`font-medium`,children:e.size}),` lead`,e.size===1?``:`s`,` will be updated.`]}),(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsx)(`div`,{className:`text-xs uppercase tracking-wide text-muted-foreground`,children:`Field`}),(0,L.jsx)(`div`,{className:`font-medium`,children:C.label})]}),O.length>0&&(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsxs)(`div`,{className:`text-xs uppercase tracking-wide text-muted-foreground`,children:[`Sample before values (first `,O.length,`)`]}),(0,L.jsx)(`ul`,{className:`list-disc pl-5 space-y-0.5`,children:O.map(e=>(0,L.jsx)(`li`,{className:`break-words`,children:(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:D(e)})},e.id))})]}),(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsx)(`div`,{className:`text-xs uppercase tracking-wide text-muted-foreground`,children:`New value`}),(0,L.jsx)(`div`,{className:`font-medium break-words whitespace-pre-wrap`,children:A()})]}),M&&(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,L.jsx)(Ew,{className:`h-3.5 w-3.5 animate-spin`}),`Updating `,e.size,` leads...`]})]}),(0,L.jsx)(dj,{children:p===`configure`?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(W,{variant:`outline`,onClick:()=>f(!1),children:`Cancel`}),(0,L.jsx)(W,{onClick:()=>m(`preview`),disabled:!k,children:`Preview`})]}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(W,{variant:`outline`,onClick:()=>m(`configure`),disabled:u.isPending,children:`Back`}),(0,L.jsx)(W,{onClick:j,disabled:u.isPending,children:u.isPending?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(Ew,{className:`h-3.5 w-3.5 mr-1.5 animate-spin`}),`Applying...`]}):`Confirm`})]})})]})})]})}var Cj={name:{type:`text`},phone:{type:`text`},email:{type:`text`},source:{type:`text`},origin:{type:`select`,labels:Kk},notes:{type:`text`},warmth:{type:`select`},status:{type:`select`},assignedAgentName:{type:`select`},sheetDate:{type:`date`},createdAt:{type:`date`},lastContactedAt:{type:`date`}};function wj(e,t){return Cj[e].labels?.[t]??t.replace(/_/g,` `)}var Tj=[`contains`,`equals`,`starts_with`,`is_empty`],Ej=[`in`],Dj=[`between`],Oj=[`recency`,`createdAt`,`sheetDate`,`name`,`warmth`,`status`,`source`,`origin`,`lastContactedAt`],kj=`filter.`;function Aj(e){return Object.prototype.hasOwnProperty.call(Cj,e)}function jj(e,t){if(!Aj(e))return null;let n=Cj[e],r=t.indexOf(`:`);if(r===-1)return null;let i=t.slice(0,r),a=t.slice(r+1);if(n.type===`text`)return!Tj.includes(i)||i!==`is_empty`&&a.trim()===``?null:{columnId:e,type:`text`,operator:i,value:i===`is_empty`?``:a};if(n.type===`select`){if(!Ej.includes(i))return null;let t=a.split(`,`).map(e=>e.trim()).filter(Boolean);return t.length===0?null:{columnId:e,type:`select`,operator:i,values:t}}if(n.type===`date`){if(!Dj.includes(i))return null;let[t=``,n=``]=a.split(`,`),r=t.trim(),o=n.trim();if(!r&&!o)return null;let s=/^\d{4}-\d{2}-\d{2}$/,c=s.test(r)?r:``,l=s.test(o)?o:``;return!c&&!l?null:{columnId:e,type:`date`,operator:i,from:c,to:l}}return null}function Mj(e){let t=[];for(let[n,r]of e.entries()){if(!n.startsWith(kj))continue;let e=jj(n.slice(7),r);e&&t.push(e)}return t}function Nj(e){return e.type===`text`?e.operator===`is_empty`?`is_empty:`:`${e.operator}:${e.value}`:e.type===`select`?`in:${e.values.join(`,`)}`:`between:${e.from},${e.to}`}function Pj(e){return`${kj}${e}`}function Fj(e){let t=e.get(`sort`);if(!t){let t=e.get(`sortBy`),n=e.get(`sortOrder`)===`asc`?`asc`:`desc`;return t&&Oj.includes(t)?[{columnId:t,order:n}]:[]}let n=[];for(let e of t.split(`,`)){let[t,r]=e.split(`:`);
71if(!t||!Oj.includes(t))continue;let i=r===`asc`?`asc`:`desc`;n.some(e=>e.columnId===t)||n.push({columnId:t,order:i})}return n}function Ij(e){return e.map(e=>`${e.columnId}:${e.order}`).join(`,`)}function Lj(e,t){let n=new URLSearchParams({limit:String(t.limit),offset:String(t.offset),sort:e.sortString});e.search&&n.set(`search`,e.search);for(let[t,r]of e.filterEntries)n.set(t,r);return e.createdToday&&n.set(`createdToday`,`true`),e.contactedToday&&n.set(`contactedToday`,`true`),e.qualifiedToday&&n.set(`qualifiedToday`,`true`),e.trashView&&n.set(`trash`,`true`),e.country!==`all`&&n.set(`country`,e.country),n}var Rj={name:`Name`,phone:`Phone`,email:`Email`,source:`Source`,origin:`Origin`,notes:`Notes`,warmth:`Warmth`,status:`Status`,assignedAgentName:`Agent`,sheetDate:`Date`,createdAt:`Created`,lastContactedAt:`Last contacted`},zj={recency:`Latest enquiry`},Bj={contains:`contains`,equals:`is`,starts_with:`starts with`,is_empty:`is empty`,in:`in`,between:`between`};function Vj(e){let t=Rj[e.columnId]??e.columnId;return e.type===`text`?e.operator===`is_empty`?`${t} ${Bj.is_empty}`:`${t} ${Bj[e.operator]??e.operator} "${e.value}"`:e.type===`select`?`${t}: ${e.values.map(t=>wj(e.columnId,t)).join(`, `)}`:`${t}: ${[e.from||`â¦`,e.to||`â¦`].join(` â `)}`}function Hj({filters:e,sorts:t,hasExplicitSort:n,hasSearch:r,hasDateDrilldown:i,onRemoveFilter:a,onRemoveSort:o,onClearAll:s}){let c=Object.entries(e).filter(e=>!!e[1]);return c.length>0||n||r||i?(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[c.map(([e,t])=>(0,L.jsxs)(X,{variant:`secondary`,className:`gap-1 pl-2 pr-1 py-0.5 text-xs font-normal`,children:[(0,L.jsx)(`span`,{className:`truncate max-w-[200px]`,children:Vj(t)}),(0,L.jsx)(`button`,{type:`button`,"aria-label":`Remove ${Rj[e]} filter`,className:`inline-flex h-4 w-4 items-center justify-center rounded hover:bg-muted`,onClick:()=>a(e),children:(0,L.jsx)(FT,{className:`h-3 w-3`})})]},e)),n&&t.map((e,n)=>(0,L.jsxs)(X,{variant:`outline`,className:`gap-1 pl-2 pr-1 py-0.5 text-xs font-normal`,children:[(0,L.jsxs)(`span`,{children:[t.length>1?`${n+1}. `:``,`Sort`,` `,zj[e.columnId]??Rj[e.columnId]??e.columnId,` `,e.order]}),(0,L.jsx)(`button`,{type:`button`,"aria-label":`Remove sort on ${e.columnId}`,className:`inline-flex h-4 w-4 items-center justify-center rounded hover:bg-muted`,onClick:()=>o(e.columnId),children:(0,L.jsx)(FT,{className:`h-3 w-3`})})]},`sort-${e.columnId}`)),(0,L.jsx)(W,{variant:`ghost`,size:`sm`,className:`h-6 px-2 text-xs`,onClick:s,children:`Clear all`})]}):(0,L.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Click a column header to sort; click the filter icon to filter. Shift+Click a header to add secondary sort.`})}function Uj({...e}){return(0,L.jsx)(Wh,{"data-slot":`dropdown-menu`,...e})}function Wj({...e}){return(0,L.jsx)(Gh,{"data-slot":`dropdown-menu-trigger`,...e})}function Gj({className:e,sideOffset:t=4,...n}){return(0,L.jsx)(Kh,{children:(0,L.jsx)(qh,{"data-slot":`dropdown-menu-content`,sideOffset:t,className:V(`z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95`,e),...n})})}function Kj({className:e,inset:t,variant:n=`default`,...r}){return(0,L.jsx)(Yh,{"data-slot":`dropdown-menu-item`,"data-inset":t,"data-variant":n,className:V(`relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!`,e),...r})}function qj({className:e,inset:t,...n}){return(0,L.jsx)(Jh,{"data-slot":`dropdown-menu-label`,"data-inset":t,className:V(`px-2 py-1.5 text-sm font-medium data-[inset]:pl-8`,e),...n})}function Jj({className:e,...t}){return(0,L.jsx)(Xh,{"data-slot":`dropdown-menu-separator`,className:V(`-mx-1 my-1 h-px bg-border`,e),...t})}function Yj({captureConfig:e,applyConfig:t}){let n=ri(),[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(!1),[s,c]=(0,_.useState)(!1),{data:l,isLoading:u}=vi({queryKey:[`lead-views`],queryFn:()=>H(`/api/lead-views`)}),d=l?.data??[],f=()=>n.invalidateQueries({queryKey:[`lead-views`]}),p=R({mutationFn:e=>H(`/api/lead-views`,{method:`POST`,body:JSON.stringify(e)}),onSuccess:()=>{z.success(`View saved`),f()},onError:e=>z.error(e.message)}),m=e=>{t(e.config),i(!1),z.success(`Applied "${e.name}"`)};return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(Uj,{open:r,onOpenChange:i,children:[(0,L.jsx)(Wj,{asChild:!0,children:(0,L.jsxs)(W,{variant:`outline`,size:`sm`,children:[(0,L.jsx)(AC,{className:`h-4 w-4 mr-1.5`}),`Views`,d.length>0&&(0,L.jsxs)(`span`,{className:`ml-1.5 text-xs text-muted-foreground`,children:[`(`,d.length,`)`]}),(0,L.jsx)(zC,{className:`h-3.5 w-3.5 ml-1 opacity-60`})]})}),(0,L.jsxs)(Gj,{align:`start`,className:`w-64`,children:[(0,L.jsx)(qj,{children:`Saved views`}),(0,L.jsx)(Jj,{}),u?(0,L.jsx)(`div`,{className:`px-2 py-1.5 text-xs text-muted-foreground`,children:`Loadingâ¦`}):d.length===0?(0,L.jsx)(`div`,{className:`px-2 py-1.5 text-xs text-muted-foreground`,children:`No saved views yet`}):(0,L.jsx)(`div`,{className:`max-h-64 overflow-y-auto`,children:d.map(e=>(0,L.jsxs)(Kj,{onSelect:t=>{t.preventDefault(),m(e)},className:`flex items-start gap-2`,children:[(0,L.jsx)(RC,{className:`h-3.5 w-3.5 mt-0.5 opacity-0`}),(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsx)(`div`,{className:`truncate font-medium`,children:e.name}),e.description&&(0,L.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:e.description})]})]},e.id))}),(0,L.jsx)(Jj,{}),(0,L.jsxs)(Kj,{onSelect:e=>{e.preventDefault(),i(!1),o(!0)},children:[(0,L.jsx)(Gw,{className:`h-4 w-4 mr-2`}),`Save current asâ¦`]}),(0,L.jsxs)(Kj,{disabled:d.length===0,onSelect:e=>{e.preventDefault(),i(!1),c(!0)},children:[(0,L.jsx)(tT,{className:`h-4 w-4 mr-2`}),`Manage viewsâ¦`]})]})]}),(0,L.jsx)(Xj,{open:a,onOpenChange:o,onSubmit:(t,n)=>p.mutate({name:t,description:n||void 0,config:e()},{onSuccess:()=>o(!1)}),isPending:p.isPending}),(0,L.jsx)(Zj,{open:s,onOpenChange:c,views:d,captureConfig:e,onInvalidate:f})]})}function Xj({open:e,onOpenChange:t,onSubmit:n,isPending:r}){let[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(``),c=e=>{e||(a(``),s(``)),t(e)},l=i.trim().length>0&&!r;return(0,L.jsx)(aj,{open:e,onOpenChange:c,children:(0,L.jsxs)(lj,{className:`sm:max-w-md`,children:[(0,L.jsxs)(uj,{children:[(0,L.jsx)(fj,{children:`Save view`}),(0,L.jsx)(pj,{children:`Capture the current filters, sort, column layout, density, and page size.`})]}),(0,L.jsxs)(`div`,{className:`space-y-4`,children:[(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`view-name`,children:`N
71ame *`}),(0,L.jsx)(G,{id:`view-name`,autoFocus:!0,value:i,maxLength:100,onChange:e=>a(e.target.value),placeholder:`My hot leads`,onKeyDown:e=>{e.key===`Enter`&&l&&n(i.trim(),o.trim())}})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`view-description`,children:`Description`}),(0,L.jsx)(TD,{id:`view-description`,value:o,maxLength:500,onChange:e=>s(e.target.value),placeholder:`Optional â what this view shows`,className:`min-h-[60px]`})]})]}),(0,L.jsxs)(dj,{children:[(0,L.jsx)(W,{variant:`outline`,onClick:()=>c(!1),children:`Cancel`}),(0,L.jsx)(W,{disabled:!l,onClick:()=>n(i.trim(),o.trim()),children:r?`Savingâ¦`:`Save view`})]})]})})}function Zj({open:e,onOpenChange:t,views:n,captureConfig:r,onInvalidate:i}){let[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(``),d=R({mutationFn:e=>H(`/api/lead-views/${e.id}`,{method:`PUT`,body:JSON.stringify(e.body)}),onSuccess:()=>{z.success(`View updated`),i(),o(null)},onError:e=>z.error(e.message)}),f=R({mutationFn:e=>H(`/api/lead-views/${e}`,{method:`DELETE`}),onSuccess:()=>{z.success(`View deleted`),i()},onError:e=>z.error(e.message)}),p=e=>{o(e.id),c(e.name),u(e.description??``)},m=()=>{if(!a)return;let e=s.trim();if(!e){z.error(`Name is required`);return}d.mutate({id:a,body:{name:e,description:l.trim()?l.trim():null}})},h=e=>{d.mutate({id:e,body:{config:r()}})};return(0,L.jsx)(aj,{open:e,onOpenChange:t,children:(0,L.jsxs)(lj,{className:`sm:max-w-lg`,children:[(0,L.jsxs)(uj,{children:[(0,L.jsx)(fj,{children:`Manage views`}),(0,L.jsx)(pj,{children:`Rename, replace with current state, or delete your saved views.`})]}),(0,L.jsx)(`div`,{className:`max-h-[60vh] overflow-y-auto space-y-2`,children:n.length===0?(0,L.jsx)(`div`,{className:`text-sm text-muted-foreground py-6 text-center`,children:`No saved views yet.`}):n.map(e=>(0,L.jsx)(`div`,{className:`rounded-md border p-3 space-y-2`,children:a===e.id?(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsx)(Z,{htmlFor:`edit-name-${e.id}`,className:`text-xs`,children:`Name`}),(0,L.jsx)(G,{id:`edit-name-${e.id}`,value:s,maxLength:100,onChange:e=>c(e.target.value)})]}),(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsx)(Z,{htmlFor:`edit-description-${e.id}`,className:`text-xs`,children:`Description`}),(0,L.jsx)(TD,{id:`edit-description-${e.id}`,value:l,maxLength:500,onChange:e=>u(e.target.value),className:`min-h-[50px]`})]}),(0,L.jsxs)(`div`,{className:`flex justify-end gap-2 pt-1`,children:[(0,L.jsx)(W,{variant:`outline`,size:`sm`,onClick:()=>o(null),children:`Cancel`}),(0,L.jsx)(W,{size:`sm`,disabled:d.isPending,onClick:m,children:d.isPending?`Savingâ¦`:`Save`})]})]}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`div`,{className:`flex items-start justify-between gap-3`,children:(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsx)(`div`,{className:`truncate text-sm font-medium`,children:e.name}),e.description&&(0,L.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:e.description})]})}),(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(0,L.jsxs)(W,{variant:`outline`,size:`sm`,onClick:()=>p(e),children:[(0,L.jsx)(Bw,{className:`h-3.5 w-3.5 mr-1.5`}),`Rename`]}),(0,L.jsx)(W,{variant:`outline`,size:`sm`,disabled:d.isPending,onClick:()=>h(e.id),title:`Replace this view's config with the current toolbar state`,children:`Update with current`}),(0,L.jsxs)(W,{variant:`outline`,size:`sm`,className:`text-destructive hover:text-destructive`,disabled:f.isPending,onClick:()=>{window.confirm(`Delete view "${e.name}"? This cannot be undone.`)&&f.mutate(e.id)},children:[(0,L.jsx)(vT,{className:`h-3.5 w-3.5 mr-1.5`}),`Delete`]})]})]})},e.id))}),(0,L.jsx)(dj,{children:(0,L.jsx)(W,{variant:`outline`,onClick:()=>t(!1),children:`Close`})})]})})}function Qj(e){let t={};for(let[n,r]of e.searchParams.entries())r===``||r==null||(t[n]=r);return{urlParams:t,columnOrder:e.columnOrder.slice(),columnVisibility:{...e.columnVisibility},columnPinning:{left:(e.columnPinning.left??[]).slice(),right:(e.columnPinning.right??[]).slice()},columnSizing:{...e.columnSizing},density:e.density,pageSize:e.pageSize}}var $j={hot:`bg-red-600 text-white border-red-600`,warm:`bg-orange-500 text-white border-orange-500`,cold:`bg-blue-500 text-white border-blue-500`};function eM({leads:e,onSelect:t,onMessage:n}){return e.length===0?(0,L.jsx)(`div`,{className:`rounded-md border p-8 text-center text-muted-foreground`,children:`No leads to display.`}):(0,L.jsx)(`ul`,{className:`space-y-2`,children:e.map(e=>(0,L.jsxs)(`li`,{onClick:()=>t(e.id),className:`rounded-lg border p-3 space-y-1 active:bg-muted cursor-pointer`,children:[(0,L.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsx)(`p`,{className:`font-semibold truncate`,children:e.name}),(0,L.jsx)(`p`,{className:`font-mono text-xs text-muted-foreground truncate`,children:e.phone})]}),(0,L.jsx)(W,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,"aria-label":`Message lead`,onClick:t=>{t.stopPropagation(),n(e.id)},children:(0,L.jsx)(Nw,{className:`h-4 w-4`})})]}),(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,L.jsx)(X,{className:`capitalize ${$j[e.warmth]??``}`,variant:$j[e.warmth]?void 0:`outline`,children:e.warmth}),(0,L.jsx)(X,{variant:`outline`,className:`capitalize`,children:e.status.replace(/_/g,` `)}),e.qualificationMode===`qualifying`&&(0,L.jsx)(X,{variant:`secondary`,className:`text-xs`,children:`qualifying`}),(0,L.jsx)(qA,{origin:e.origin,leadProfileData:e.leadProfileData})]}),(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-xs text-muted-foreground`,children:[(0,L.jsx)(`span`,{className:`truncate`,children:e.assignedAgentName?(0,L.jsxs)(L.Fragment,{children:[`Agent: `,(0,L.jsx)(`span`,{className:`text-foreground`,children:e.assignedAgentName})]}):(0,L.jsx)(`span`,{className:`italic`,children:`Unassigned`})}),e.source&&(0,L.jsx)(`span`,{className:`truncate`,children:e.source})]})]},e.id))})}var tM=_.forwardRef(({className:e,...t},n)=>(0,L.jsx)(wl,{ref:n,className:V(`peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow-sm focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground`,e),...t,children:(0,L.jsx)(El,{className:V(`flex items-center justify-center text-current`),children:(0,L.jsx)(RC,{className:`h-4 w-4`})})}));tM.displayName=wl.displayName;var nM={contains:`Contains`,equals:`Equals`,starts_with:`Starts with`,is_empty:`Is empty`};function rM(e){return`${e.getFullYear()}
71-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function iM(){let e=new Date;return{from:rM(e),to:rM(e)}}function aM(){let e=new Date,t=(e.getDay()+6)%7,n=new Date(e);return n.setDate(e.getDate()-t),{from:rM(n),to:rM(e)}}function oM(e){let[t,n]=(0,_.useState)(!1),r=e.value!==void 0;return(0,L.jsxs)(OA,{open:t,onOpenChange:n,children:[(0,L.jsx)(kA,{asChild:!0,children:(0,L.jsx)(`button`,{type:`button`,className:V(`inline-flex h-6 w-6 items-center justify-center rounded hover:bg-muted/80`,r&&`bg-primary/10 text-primary`),"aria-label":`Filter ${e.columnLabel}`,onClick:e=>e.stopPropagation(),onDragStart:e=>e.preventDefault(),draggable:!1,"data-testid":`filter-${e.columnId}`,children:(0,L.jsx)(mw,{className:`h-3.5 w-3.5`})})}),(0,L.jsx)(AA,{className:`w-72`,onClick:e=>e.stopPropagation(),children:t&&(0,L.jsx)(sM,{...e,hasActive:r,onClose:()=>n(!1)})})]})}function sM({columnId:e,columnLabel:t,type:n,selectOptions:r,value:i,onChange:a,hasActive:o,onClose:s}){let[c,l]=(0,_.useState)(i?.type===`text`?i.operator:`contains`),[u,d]=(0,_.useState)(i?.type===`text`?i.value:``),[f,p]=(0,_.useState)(i?.type===`select`?i.values:[]),[m,h]=(0,_.useState)(i?.type===`date`?i.from:``),[g,v]=(0,_.useState)(i?.type===`date`?i.to:``),y=()=>{n===`text`?c===`is_empty`?a({columnId:e,type:`text`,operator:`is_empty`,value:``}):u.trim()?a({columnId:e,type:`text`,operator:c,value:u}):a(void 0):n===`select`?f.length>0?a({columnId:e,type:`select`,operator:`in`,values:f}):a(void 0):n===`date`&&a(m||g?{columnId:e,type:`date`,operator:`between`,from:m,to:g}:void 0),s()};return(0,L.jsxs)(`div`,{className:`space-y-3`,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),y())},children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsxs)(`span`,{className:`text-sm font-medium`,children:[`Filter `,t]}),o&&(0,L.jsxs)(`button`,{type:`button`,onClick:()=>{a(void 0),s()},className:`text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,children:[(0,L.jsx)(FT,{className:`h-3 w-3`}),` Clear`]})]}),n===`text`&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(wk,{value:c,onValueChange:e=>l(e),children:[(0,L.jsx)(Dk,{className:`w-full`,children:(0,L.jsx)(Ek,{})}),(0,L.jsx)(Ok,{children:Tj.map(e=>(0,L.jsx)(Ak,{value:e,children:nM[e]},e))})]}),c!==`is_empty`&&(0,L.jsx)(G,{autoFocus:!0,value:u,onChange:e=>d(e.target.value),placeholder:`Value...`})]}),n===`select`&&(0,L.jsx)(`div`,{className:`max-h-60 space-y-1 overflow-y-auto`,children:(r??[]).length===0?(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No options`}):(r??[]).map(t=>{let n=f.includes(t),r=wj(e,t),i=r===t.replace(/_/g,` `);return(0,L.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 rounded px-1.5 py-1 text-sm hover:bg-muted/60`,children:[(0,L.jsx)(tM,{checked:n,onCheckedChange:e=>{p(n=>e?[...n,t]:n.filter(e=>e!==t))}}),(0,L.jsx)(`span`,{className:i?`capitalize`:void 0,children:r})]},t)})}),n===`date`&&(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsxs)(`div`,{className:`flex gap-1`,children:[(0,L.jsx)(W,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 text-xs flex-1`,onClick:()=>{let e=iM();h(e.from),v(e.to)},children:`Today`}),(0,L.jsx)(W,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 text-xs flex-1`,onClick:()=>{let e=aM();h(e.from),v(e.to)},children:`This week`}),(0,L.jsx)(W,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 text-xs flex-1`,onClick:()=>{h(``),v(``)},children:`Clear`})]}),(0,L.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsx)(`label`,{className:`text-xs text-muted-foreground`,children:`From`}),(0,L.jsx)(G,{type:`date`,value:m,onChange:e=>h(e.target.value)})]}),(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsx)(`label`,{className:`text-xs text-muted-foreground`,children:`To`}),(0,L.jsx)(G,{type:`date`,value:g,onChange:e=>v(e.target.value)})]})]})]}),(0,L.jsxs)(`div`,{className:`flex justify-end gap-2 pt-1`,children:[(0,L.jsx)(W,{type:`button`,variant:`outline`,size:`sm`,onClick:s,children:`Cancel`}),(0,L.jsx)(W,{type:`button`,size:`sm`,onClick:y,children:`Apply`})]})]})}function cM(e,t){return t??e}function lM({label:e,columnId:t,sortable:n,tooltip:r,filter:i,sorts:a,onHeaderClick:o}){let s=cM(e,r),c=a.findIndex(e=>e.columnId===t),l=c!==-1,u=l?a[c].order:null,d=l&&a.length>1?c+1:null;return(0,L.jsxs)(`div`,{className:`flex min-w-0 items-center gap-0.5`,children:[n?(0,L.jsxs)(tx,{children:[(0,L.jsx)(nx,{asChild:!0,children:(0,L.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(t,e.shiftKey)},onDragStart:e=>
71e.preventDefault(),draggable:!1,className:`inline-flex min-w-0 flex-1 items-center gap-1 hover:text-foreground`,children:[(0,L.jsx)(`span`,{className:`truncate`,children:e}),u===`asc`?(0,L.jsx)(DC,{className:`h-3 w-3 shrink-0`}):u===`desc`?(0,L.jsx)(SC,{className:`h-3 w-3 shrink-0`}):(0,L.jsx)(EC,{className:`h-3 w-3 shrink-0 opacity-40`}),d!==null&&(0,L.jsx)(`span`,{className:`inline-flex h-4 min-w-4 shrink-0 items-center justify-center rounded-full bg-primary/10 px-1 text-[10px] font-semibold text-primary`,children:d})]})}),(0,L.jsx)(rx,{children:s})]}):(0,L.jsxs)(tx,{children:[(0,L.jsx)(nx,{asChild:!0,children:(0,L.jsx)(`span`,{className:`truncate`,children:e})}),(0,L.jsx)(rx,{children:s})]}),i&&(0,L.jsx)(oM,{columnId:i.columnId,columnLabel:e,type:i.type,selectOptions:i.selectOptions,value:i.value,onChange:i.onChange})]})}function uM(e){let t=new Date(e);return isNaN(t.getTime())?e:t.toLocaleString(`en-SG`,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`})}function dM({leadId:e,fieldKey:t,currentUserId:n,autoFocus:r}){let i=ri(),[a,o]=(0,_.useState)(``),{data:s,isLoading:c}=vi({queryKey:[`lead-comments`,e,t],queryFn:()=>H(`/api/lead-comments?leadId=${encodeURIComponent(e)}&fieldKey=${encodeURIComponent(t)}`)}),l=s?.data??[],u=l.filter(e=>!e.resolved),d=()=>{i.invalidateQueries({queryKey:[`lead-comments`,e,t]}),i.invalidateQueries({queryKey:[`lead-comments-summary`,e]})},f=R({mutationFn:n=>H(`/api/lead-comments`,{method:`POST`,body:JSON.stringify({leadId:e,fieldKey:t,body:n})}),onSuccess:()=>{o(``),d()},onError:e=>z.error(e.message)}),p=R({mutationFn:({id:e,resolved:t})=>H(`/api/lead-comments/${e}`,{method:`PATCH`,body:JSON.stringify({resolved:t})}),onSuccess:d,onError:e=>z.error(e.message)}),m=R({mutationFn:e=>H(`/api/lead-comments/${e}`,{method:`DELETE`}),onSuccess:d,onError:e=>z.error(e.message)}),h=()=>{for(let e of u)p.mutate({id:e.id,resolved:!0})},g=()=>{let e=a.trim();e&&f.mutate(e)};return(0,L.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:`Comments`}),u.length>0&&(0,L.jsxs)(W,{variant:`ghost`,size:`sm`,className:`h-6 px-2 text-xs`,onClick:h,disabled:p.isPending,title:`Mark all as resolved`,children:[(0,L.jsx)(KC,{className:`h-3.5 w-3.5 mr-1`}),`Resolve`]})]}),(0,L.jsx)(`div`,{className:`max-h-56 overflow-y-auto flex flex-col gap-3 pr-1`,children:c?(0,L.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Loading...`}):l.length===0?(0,L.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No comments yet.`}):l.map(e=>(0,L.jsxs)(`div`,{className:`rounded-md border p-2 text-sm ${e.resolved?`bg-muted/50 opacity-60`:`bg-background`}`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-1`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs`,children:[(0,L.jsx)(`span`,{className:`font-medium`,children:e.userName??e.userEmail??`Unknown`}),(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:uM(e.createdAt)}),e.resolved&&(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:`(resolved)`})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!e.resolved&&(0,L.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground`,onClick:()=>p.mutate({id:e.id,resolved:!0}),title:`Resolve this comment`,children:(0,L.jsx)(KC,{className:`h-3.5 w-3.5`})}),n&&e.userId===n&&(0,L.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-destructive`,onClick:()=>m.mutate(e.id),title:`Delete this comment`,children:(0,L.jsx)(vT,{className:`h-3.5 w-3.5`})})]})]}),(0,L.jsx)(`div`,{className:`whitespace-pre-wrap break-words`,children:e.body})]},e.id))}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,L.jsx)(TD,{value:a,onChange:e=>o(e.target.value),placeholder:`Add a comment...`,className:`min-h-16 text-sm`,autoFocus:r,onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),g())}}),(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Cmd/Ctrl+Enter to post`}),(0,L.jsx)(W,{size:`sm`,onClick:g,disabled:!a.trim()||f.isPending,children:f.isPending?`Posting...`:`Post`})]})]})]})}function fM({leadId:e,fieldKey:t,commentCount:n,currentUserId:r,children:i}){let[a,o]=(0,_.useState)(!1),[s,c]=(0,_.useState)(!1);return(0,L.jsxs)(OA,{open:a,onOpenChange:e=>{o(e),e||c(!1)},children:[(0,L.jsxs)(Rk,{children:[(0,L.jsx)(zk,{asChild:!0,children:(0,L.jsxs)(`span`,{className:`relative flex min-w-0 items-center gap-1`,onClick:e=>{e.target.closest(`[data-comment-indicator]`)&&(e.stopPropagation(),o(!0))},children:[i,n>0?(0,L.jsx)(kA,{asChild:!0,children:(0,L.jsx)(`button`,{type:`button`,"data-comment-indicator":!0,"aria-label":`${n} comment${n===1?``:`s`}`,className:`inline-flex h-4 min-w-4 items-center justify-center rounded-full bg-orange-500 px-1 text-[10px] font-medium text-white shrink-0 hover:bg-orange-600 shadow-sm`,onClick:e=>{e.stopPropagation(),o(!0)},title:`${n} unresolved comment${n===1?``:`s`}`,children:n>9?`9+`:n})}):(0,L.jsx)(kA,{asChild:!0,children:(0,L.jsx)(`span`,{className:`sr-only`,"aria-hidden":`true`})})]})}),(0,L.jsx)(Bk,{children:(0,L.jsxs)(Vk,{onSelect:e=>{e.preventDefault(),c(!0),o(!0)},children:[(0,L.jsx)(jw,{className:`h-4 w-4`}),`Add comment`]})})]}),(0,L.jsx)(AA,{className:`w-80`,align:`start`,onClick:e=>e.stopPropagation(),children:(0,L.jsx)(dM,{leadId:e,fieldKey:t,currentUserId:r,autoF
71ocus:s||n===0})})]})}function pM({value:e,options:t,onValueChange:n,variant:r}){return(0,L.jsxs)(wk,{value:e,onValueChange:n,children:[(0,L.jsx)(Dk,{className:`h-6 w-auto border-none bg-transparent p-0 shadow-none focus:ring-0 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:opacity-0 hover:[&>svg]:opacity-100`,children:(0,L.jsx)(X,{variant:r??`outline`,className:`cursor-pointer`,children:e.replace(/_/g,` `)})}),(0,L.jsx)(Ok,{children:t.map(e=>(0,L.jsx)(Ak,{value:e,children:e.replace(/_/g,` `)},e))})]})}function mM({value:e,onSave:t,renderDisplay:n,renderEditor:r,className:i,label:a,isEqual:o}){let[s,c]=(0,_.useState)(!1),[l,u]=(0,_.useState)(e),[d,f]=(0,_.useState)(e);!s&&d!==e&&(f(e),u(e));let p=(0,_.useCallback)(()=>{u(e),c(!0)},[e]),m=(0,_.useCallback)(()=>{c(!1)},[]),h=(0,_.useCallback)(()=>{u(e),m()},[e,m]),g=(0,_.useMemo)(()=>o||((e,t)=>e===t?!0:e==null||t==null?e===t:typeof e==`object`||typeof t==`object`?JSON.stringify(e)===JSON.stringify(t):!1),[o]),v=(0,_.useCallback)(()=>{g(l,e)||t(l),m()},[l,e,g,m,t]);return s?(0,L.jsx)(`div`,{className:`w-full`,onClick:e=>e.stopPropagation(),onDoubleClick:e=>e.stopPropagation(),onKeyDown:e=>{e.key===`Escape`&&(e.preventDefault(),h())},children:r({value:l,onChange:u,onCommit:v,onCancel:h})}):(0,L.jsx)(`div`,{role:`button`,tabIndex:0,"aria-label":a,className:V(`w-full cursor-pointer rounded-sm px-1 -mx-1 outline-none`,`focus-visible:ring-2 focus-visible:ring-ring`,`hover:bg-muted/50`,i),onDoubleClick:e=>{e.stopPropagation(),p()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),p())},children:n(e)})}function hM({value:e,onSave:t,placeholder:n,className:r,inputClassName:i,displayClassName:a,mono:o,emptyPlaceholder:s}){return(0,L.jsx)(mM,{value:e??``,onSave:t,className:r,renderDisplay:e=>(0,L.jsx)(`span`,{className:V(`block truncate`,o&&`font-mono text-sm`,!e&&`text-muted-foreground`,a),children:e||(s??`â`)}),renderEditor:({value:e,onChange:t,onCommit:r,onCancel:a})=>(0,L.jsx)(G,{autoFocus:!0,value:e,placeholder:n,className:V(`h-7 text-sm`,o&&`font-mono`,i),onChange:e=>t(e.target.value),onBlur:r,onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),r()):e.key===`Escape`&&(e.preventDefault(),a())}})})}function gM({value:e,displayName:t,options:n,onSave:r,className:i}){return(0,L.jsx)(mM,{value:e??null,onSave:r,className:i,renderDisplay:()=>(0,L.jsx)(`span`,{className:V(`block truncate text-sm`,!t&&`text-muted-foreground`),children:t??`â`}),renderEditor:({value:e,onChange:t,onCommit:r,onCancel:i})=>(0,L.jsx)(_M,{value:e,options:n,onChange:t,onCommit:r,onCancel:i})})}function _M({value:e,options:t,onChange:n,onCommit:r,onCancel:i}){let[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(0),l=(0,_.useRef)(null),u=(0,_.useRef)(null),d=(0,_.useRef)(!1),f=(0,_.useMemo)(()=>{let e=a.trim().toLowerCase(),n=[{id:null,name:`Unassigned`},...t];return e?n.filter(t=>t.name.toLowerCase().includes(e)):n},[t,a]);(0,_.useEffect)(()=>{l.current?.focus()},[]),(0,_.useEffect)(()=>{d.current&&(d.current=!1,r())},[e,r]);let p=e=>{d.current=!0,n(e)};return(0,L.jsxs)(`div`,{className:`relative w-48`,children:[(0,L.jsx)(G,{ref:l,value:a,placeholder:`Search agent...`,className:`h-7 text-sm`,onChange:e=>{o(e.target.value),c(0)},onBlur:e=>{let t=e.relatedTarget;t&&u.current?.contains(t)||i()},onKeyDown:e=>{if(e.key===`ArrowDown`)e.preventDefault(),c(e=>Math.min(e+1,Math.max(0,f.length-1)));else if(e.key===`ArrowUp`)e.preventDefault(),c(e=>Math.max(e-1,0));else if(e.key===`Enter`){e.preventDefault();let t=f[s];t&&p(t.id)}else e.key===`Escape`&&(e.preventDefault(),i())}}),(0,L.jsxs)(`div`,{ref:u,className:`absolute left-0 top-full z-50 mt-1 max-h-56 w-64 overflow-auto rounded-md border bg-popover p-1 shadow-md`,children:[f.length===0&&(0,L.jsx)(`div`,{className:`px-2 py-1.5 text-sm text-muted-foreground`,children:`No agents found`}),f.map((t,n)=>(0,L.jsxs)(`button`,{type:`button`,className:V(`flex w-full items-center justify-between rounded-sm px-2 py-1.5 text-left text-sm`,s===n?`bg-accent text-accent-foreground`:`hover:bg-muted`),onMouseEnter:()=>c(n),onMouseDown:e=>{e.preventDefault(),p(t.id)},children:[(0,L.jsx)(`span`,{className:V(t.id===null&&`text-muted-foreground`),children:t.name}),e===t.id&&(0,L.jsx)(RC,{className:`h-3.5 w-3.5`})]},t.id??`__none__`))]})]})}function vM(e){let t=e.split(` 72`);for(let e=t.length-1;e>=0;e--)if(t[e].trim()!==``)return t[e];return``}function yM({value:e,onSave:t,placeholder:n}){let[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(e??``),[s,c]=(0,_.useState)(e??``),[l,u]=(0,_.useState)(e??``),d=e??``;!r&&s!==d&&(c(d),o(d),u(d));let f=()=>{let e=a.trim()===``?null:a;if(e!==(l||null)){let n=e??``;t(e,l).then(e=>{e&&u(n)},()=>{})}i(!1)},p=()=>{o(l),i(!1)};return(0,L.jsxs)(OA,{open:r,onOpenChange:i,children:[(0,L.jsx)(kA,{asChild:!0,children:(0,L.jsx)(`div`,{role:`button`,tabIndex:0,"aria-label":`Edit notes`,className:V(`w-full min-w-0 max-w-[220px] cursor-pointer rounded-sm px-1 -mx-1 outline-none`,`focus-visible:ring-2 focus-visible:ring-ring`,`hover:bg-muted/50`),onDoubleClick:e=>{e.stopPropagation(),i(!0)},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),i(!0))},children:(0,L.jsx)(`span`,{className:V(`block truncate text-sm`,!e&&`text-muted-foreground`),children:e&&vM(e)||`â`})})}),(0,L.jsx)(AA,{className:`w-80`,onOpenAutoFocus:e=>{e.preventDefault()},children:(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(TD,{autoFocus:!0,value:a,placeholder:n??`Add notesâ¦`,className:`min-h-[120px] resize-y`,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Escape`&&(e.preventDefault(),p()),(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),f())}}),(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`ââµ save · Esc cancel`}),(0,L.jsxs)(`div`,{className:`flex gap-2`,children:[(0,L.jsx)(W,{variant:`ghost`,size:`sm`,onClick:p,children:`Cancel`}),(0,L.jsx)(W,{size:`sm`,onClick:f,children:`Save`})]})]})]})})]})}var bM={hot:`destructive`,warm:`default`,cold:`secondary`},xM=/^(\d{4}-\d{2}-\d{2}T[\d:.]+Z?)/,SM=/^(\d{1,2})[/\-.](\d{1,2})[/\-.](\d{4})$/,CM=/^(\d{4})[/\-.](\d{1,2})[/\-.](\d{1,2})$/;function wM(e){if(!e)return`â`;let t=e.trim();if(!t)return`â`;let n=null,r=t.match(xM);if(r){let e=new Date(r[1]);isNaN(e.getTime())||(n=e)}if(!n){let e=t.match(SM);if(e){let[,t,r,i]=e;n=new Date(Number(i),Number(r)-1,Number(t))}}if(!n){let e=t.match(CM);if(e){let[,t,r,i]=e;n=new Date(Number(t),Number(r)-1,Number(i))}}if(!n){let e=new Date(t);isNaN(e.getTime())||(n=e)}return!n||isNaN(n.getTime())?t:n.toLocaleDateString(`en-SG`,{day:`numeric`,month:`short`,year:`numeric`})}function TM(e,t){return e?.trim()?wM(e):wM(t)}function EM(e,t){return t.sourceTab===`lead_database`?e.leadProfileData?.[t.dbField??t.sheetHeaderName]:e.extraColumns?.[t.sheetHeaderName]}function DM({visibleDynamicColumns:e,onInlineUpdate:t,onNavigateToChat:n,onOpenDrawer:r,trashView:i=!1,onRestoreLead:a,restorePending:o=!1,columnFilters:s,onColumnFilterChange:c,sorts:l,onHeaderSort:u,agentNameOptions:d,agentOptions:f=[],getCommentCount:p,currentUserId:m}){let h=[{id:`select`,header:({table:e})=>(0,L.jsx)(tM,{checked:e.getIsAllPageRowsSelected()?!0:e.getIsSomePageRowsSelected()?`indeterminate`:!1,onCheckedChange:t=>e.toggleAllPageRowsSelected(!!t)}),cell:({row:e})=>(0,L.jsx)(tM,{checked:e.getIsSelected(),onCheckedChange:t=>e.toggleSelected(!!t)}),enableSorting:!1,enableResizing:!1,enableHiding:!1,size:40,minSize:40,maxSize:40,meta:{headClassName:`w-10`,stopRowClick:!0}},{id:`name`,accessorKey:`name`,header:()=>(0,L.jsx)(lM,{label:`Name`,columnId:`name`,sortable:!0,sorts:l,onHeaderClick:u,filter:{columnId:`name`,type:`text`,value:s.name,onChange:e=>c(`name`,e)}}),size:240,minSize:140,enableHiding:!1,cell:({row:e})=>{let i=e.original,a=p?.(i.id,`name`)??0,o=(0,L.jsx)(hM,{value:i.name,onSave:e=>
72t({id:i.id,updates:{name:e}}),displayClassName:`font-medium`});return(0,L.jsxs)(`div`,{className:`flex w-full items-center gap-1`,children:[(0,L.jsx)(`div`,{className:`min-w-0 flex-1`,children:p?(0,L.jsx)(fM,{leadId:i.id,fieldKey:`name`,commentCount:a,currentUserId:m,children:o}):o}),(0,L.jsx)(W,{variant:`ghost`,size:`icon`,className:`h-6 w-6 shrink-0`,title:`View chat`,onClick:e=>{e.stopPropagation(),n(i.id)},children:(0,L.jsx)(Nw,{className:`h-3.5 w-3.5`})}),(0,L.jsx)(W,{variant:`ghost`,size:`icon`,className:`h-6 w-6 shrink-0`,title:`Open details`,onClick:e=>{e.stopPropagation(),r(i.id)},children:(0,L.jsx)(Rw,{className:`h-3.5 w-3.5`})})]})},meta:{cellClassName:`font-medium`,stopRowClick:!0}},{id:`sheetDate`,accessorKey:`sheetDate`,header:()=>(0,L.jsx)(lM,{label:`Date`,columnId:`sheetDate`,sortable:!0,sorts:l,onHeaderClick:u,filter:{columnId:`sheetDate`,type:`date`,value:s.sheetDate,onChange:e=>c(`sheetDate`,e)}}),size:130,minSize:90,cell:({row:e})=>TM(e.original.sheetDate,e.original.createdAt),meta:{cellClassName:`text-sm text-muted-foreground whitespace-nowrap`}},{id:`phone`,accessorKey:`phone`,header:()=>(0,L.jsx)(lM,{label:`Phone`,columnId:`phone`,sortable:!1,sorts:l,onHeaderClick:u,filter:{columnId:`phone`,type:`text`,value:s.phone,onChange:e=>c(`phone`,e)}}),size:140,minSize:100,cell:({row:e})=>(0,L.jsx)(hM,{value:e.original.phone,mono:!0,onSave:n=>t({id:e.original.id,updates:{phone:n}})}),meta:{cellClassName:`font-mono text-sm`,stopRowClick:!0}},{id:`source`,accessorKey:`source`,header:()=>(0,L.jsx)(lM,{label:`Source`,columnId:`source`,sortable:!0,tooltip:`The article author attributed from the signup page.`,sorts:l,onHeaderClick:u,filter:{columnId:`source`,type:`text`,value:s.source,onChange:e=>c(`source`,e)}}),size:140,minSize:100,cell:({row:e})=>(0,L.jsx)(hM,{value:e.original.source??``,onSave:n=>t({id:e.original.id,updates:{source:n}})}),meta:{stopRowClick:!0}},{id:`origin`,accessorKey:`origin`,header:()=>(0,L.jsx)(lM,{label:`Origin`,columnId:`origin`,sortable:!0,sorts:l,onHeaderClick:u,filter:{columnId:`origin`,type:`select`,selectOptions:Gk,value:s.origin,onChange:e=>c(`origin`,e)}}),size:120,minSize:100,cell:({row:e})=>(0,L.jsx)(qA,{origin:e.original.origin,leadProfileData:e.original.leadProfileData})},{id:`warmth`,accessorKey:`warmth`,header:()=>(0,L.jsx)(lM,{label:`Warmth`,columnId:`warmth`,sortable:!0,sorts:l,onHeaderClick:u,filter:{columnId:`warmth`,type:`select`,selectOptions:TA,value:s.warmth,onChange:e=>c(`warmth`,e)}}),size:110,minSize:90,cell:({row:e})=>{let n=e.original;return(0,L.jsx)(pM,{value:n.warmth,options:EA,variant:bM[n.warmth],onValueChange:e=>t({id:n.id,updates:{warmth:e}})})},meta:{stopRowClick:!0}},{id:`status`,accessorKey:`status`,header:()=>(0,L.jsx)(lM,{label:`Status`,columnId:`status`,sortable:!0,sorts:l,onHeaderClick:u,filter:{columnId:`status`,type:`select`,selectOptions:bA,value:s.status,onChange:e=>c(`status`,e)}}),size:160,minSize:120,cell:({row:e})=>{let n=e.original;return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(pM,{value:n.status,options:SA,onValueChange:e=>t({id:n.id,updates:{status:e}})}),n.qualificationMode===`qualifying`&&(0,L.jsx)(X,{variant:`secondary`,className:`text-xs`,children:`qualifying`})]}),n.skipReason&&(0,L.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`(`,n.skipReason,`)`]})]})},meta:{stopRowClick:!0}},{id:`assignedAgentName`,accessorKey:`assignedAgentName`,header:()=>(0,L.jsx)(lM,{label:`Agent`,columnId:`assignedAgentName`,sortable:!1,sorts:l,onHeaderClick:u,filter:d.length>0?{columnId:`assignedAgentName`,type:`select`,selectOptions:d,value:s.assignedAgentName,onChange:e=>c(`assignedAgentName`,e)}:void 0}),size:150,minSize:100,cell:({row:e})=>(0,L.jsx)(gM,{value:e.original.assignedAgentId??null,displayName:e.original.assignedAgentName??null,options:f,onSave:n=>t({id:e.original.id,updates:{assignedAgentId:n}})}),meta:{cellClassName:`text-sm`,stopRowClick:!0}},{id:`notes`,accessorKey:`notes`,header:()=>(0,L.jsx)(lM,{label:`Notes`,columnId:`notes`,sortable:!1,sorts:l,onHeaderClick:u,filter:{columnId:`notes`,type:`text`,value:s.notes,onChange:e=>c(`notes`,e)}}),size:200,minSize:140,cell:({row:e})=>(0,L.jsx)(yM,{value:e.original.notes,onSave:(n,r)=>t({id:e.original.id,updates:{notes:n,notesBase:r}}),placeholder:`Add notes...`}
72),enableSorting:!1,meta:{cellClassName:`text-sm`,stopRowClick:!0}}];for(let n of e){let e=n.sourceTab===`lead_database`?`leadProfileData`:`extraColumns`,r=n.sourceTab===`lead_database`?n.dbField??n.sheetHeaderName:n.sheetHeaderName;h.push({id:`dyn-${n.id}`,header:()=>(0,L.jsxs)(tx,{children:[(0,L.jsx)(nx,{asChild:!0,children:(0,L.jsx)(`div`,{className:`truncate`,children:n.sheetHeaderName})}),(0,L.jsx)(rx,{children:n.sheetHeaderName})]}),accessorFn:e=>EM(e,n)??``,size:150,minSize:100,cell:({row:i})=>(0,L.jsx)(hM,{value:EM(i.original,n)??``,onSave:n=>t({id:i.original.id,updates:{[e]:{[r]:n===``?null:n}}})}),enableSorting:!1,meta:{cellClassName:`text-sm`,stopRowClick:!0}})}return h.push({id:`createdAt`,accessorKey:`createdAt`,header:()=>(0,L.jsx)(lM,{label:i?`Deleted`:`Created`,columnId:`createdAt`,sortable:!0,sorts:l,onHeaderClick:u,filter:i?void 0:{columnId:`createdAt`,type:`date`,value:s.createdAt,onChange:e=>c(`createdAt`,e)}}),size:120,minSize:90,cell:({row:e})=>{let t=e.original,n=i&&t.deletedAt?t.deletedAt:t.createdAt;return new Date(n).toLocaleDateString()},meta:{cellClassName:`text-sm text-muted-foreground`}}),i&&a&&h.push({id:`restore`,header:`Action`,enableSorting:!1,enableResizing:!1,enableHiding:!1,size:110,minSize:110,cell:({row:e})=>(0,L.jsxs)(W,{variant:`outline`,size:`sm`,className:`h-7`,disabled:o,onClick:()=>a(e.original.id),children:[(0,L.jsx)(bC,{className:`h-3.5 w-3.5 mr-1`}),`Restore`]}),meta:{headClassName:`w-24`,stopRowClick:!0}}),h}var OM=[`select`,`name`,`sheetDate`,`phone`,`source`,`origin`,`warmth`,`status`,`assignedAgentName`,`notes`,`createdAt`],kM={select:`Select`,name:`Name`,sheetDate:`Date`,phone:`Phone`,source:`Source`,origin:`Origin`,warmth:`Warmth`,status:`Status`,assignedAgentName:`Agent`,notes:`Notes`,createdAt:`Created`},AM=1440*60*1e3;function jM(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}var MM=[{id:`stale`,label:`Stale leads`,description:`Highlight leads not contacted in the last 7 days`,evaluate:(e,t=new Date)=>{if(!e.lastContactedAt)return null;let n=new Date(e.lastContactedAt);return isNaN(n.getTime())||t.getTime()-n.getTime()<=7*AM?null:`bg-yellow-50 dark:bg-yellow-950/20`}},{id:`overdue`,label:`Overdue follow-ups`,description:`Highlight leads with a follow-up scheduled in the past`,evaluate:(e,t=new Date)=>{if(!e.nextFollowUpAt)return null;let n=new Date(e.nextFollowUpAt);return isNaN(n.getTime())||n.getTime()>=t.getTime()?null:`bg-red-50 dark:bg-red-950/20`}},{id:`warmth_heatmap`,label:`Warmth heat map`,description:`Tint rows red/orange/blue for hot/warm/cold leads`,evaluate:e=>{switch(e.warmth){case`hot`:return`bg-red-50/50 dark:bg-red-950/10`;case`warm`:return`bg-orange-50/50 dark:bg-orange-950/10`;case`cold`:return`bg-blue-50/50 dark:bg-blue-950/10`;default:return null}}},{id:`created_today`,label:`Created today`,description:`Show a green indicator bar on leads created today`,evaluate:(e,t=new Date)=>{if(!e.createdAt)return null;let n=new Date(e.createdAt);return isNaN(n.getTime())||!jM(n,t)?null:`relative before:content-[''] before:absolute before:inset-y-0 before:left-0 before:w-1 before:bg-green-500`}}],NM={stale:!1,overdue:!1,warmth_heatmap:!1,created_today:!1},PM=`leads-formatting-rules-v1`;function FM(){if(typeof window>`u`)return{...NM};try{let e=window.localStorage.getItem(PM);if(!e)return{...NM};let t=JSON.parse(e),n={...NM};for(let e of MM)typeof t[e.id]==`boolean`&&(n[e.id]=t[e.id]);return n}catch{return{...NM}}}function IM(e){if(!(typeof window>`u`))try{window.localStorage.setItem(PM,JSON.stringify(e))}catch{}}function LM(e,t,n=new Date){let r=[];for(let i of MM){if(!t[i.id])continue;let a=i.evaluate(e,n);a&&r.push(a)}return r.join(` `)}function RM({open:e,onOpenChange:t,bindings:n}){let r=HM(n);return(0,L.jsx)(aj,{open:e,onOpenChange:t,children:(0,L.jsxs)(lj,{className:`max-w-lg`,children:[(0,L.jsxs)(uj,{children:[(0,L.jsx)(fj,{children:`Keyboard shortcuts`}),(0,L.jsxs)(pj,{children:[`Press `,(0,L.jsx)(zM,{children:`?`}),` anytime to show this list.`]})]}),(0,L.jsx)(`div`,{className:`grid grid-cols-1 gap-6 sm:grid-cols-2`,children:r.map(([e,t])=>(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2`,children:e}),(0,L.jsx)(`ul`,{className:`space-y-1.5`,children:t.map((t,n)=>(0,L.jsxs)(`li`,{className:`flex items-center justify-between gap-3 text-sm`,children:[(0,L.jsx)(`span`,{className:`text-foreground`,children:t.description??``}),(0,L.jsx)(`span`,{className:`flex items-center gap-1 shrink-0`,children:BM(t.keys).map((e,t)=>(0,L.jsx)(zM,{children:e},t))})]},`${e}-${n}`))})]},e))})]})})}function zM({children:e}){return(0,L.jsx)(`kbd`,{className:`inline-flex items-center justify-center min-w-[1.5rem] h-6 px-1.5 rounded border bg-muted text-[11px] font-mono font-medium text-foreground`,children:e})}function BM(e){return(Array.isArray(e)?e[0]:e).split(`+`).map(VM)}
72function VM(e){let t=e.toLowerCase();return t===`mod`?navigator.platform.match(/Mac|iPod|iPhone|iPad/)?`Cmd`:`Ctrl`:t===`cmd`||t===`meta`?`Cmd`:t===`ctrl`||t===`control`?`Ctrl`:t===`shift`?`Shift`:t===`alt`||t===`option`?`Alt`:t===`enter`?`Enter`:t===`escape`?`Esc`:t===`arrowup`?`â`:t===`arrowdown`?`â`:t===`arrowleft`?`â`:t===`arrowright`?`â`:e.length===1?e.toUpperCase():e}function HM(e){let t=new Map;for(let n of e){if(!n.description)continue;let e=n.group??`Other`,r=t.get(e);r?r.push(n):t.set(e,[n])}return Array.from(t.entries())}function UM(e,t=`body`){let n=e.column.getIsPinned();if(!n)return{style:{},className:``};let r=n===`left`,i=r&&e.column.getIsLastColumn(`left`),a=!r&&e.column.getIsFirstColumn(`right`);return{style:{position:`sticky`,[r?`left`:`right`]:r?`${e.column.getStart(`left`)}px`:`${e.column.getAfter(`right`)}px`,zIndex:t===`header`?20:2},className:`${t===`header`?`bg-background`:`bg-background group-hover:bg-[color-mix(in_oklab,var(--muted)_50%,var(--background))] group-data-[state=selected]:bg-muted`} ${i?`shadow-[inset_-1px_0_0_0_var(--border)]`:a?`shadow-[inset_1px_0_0_0_var(--border)]`:``}`}}function WM(e){let t=new Map,n=e.getHeaderGroups()[0];if(!n)return t;for(let e of n.headers){let n=UM(e,`header`),r=UM(e,`body`),i=e.getSize();t.set(e.column.id,{headStyle:{...n.style,width:i},headClassName:n.className,bodyStyle:{...r.style,width:i},bodyClassName:r.className})}return t}var GM=`leads-row-selection-v1`,KM=`leads-row-selection-trash-v1`,qM=[`10`,`50`,`100`,`200`,`500`,`all`],JM=`10`,YM=1e4;function XM(e){return e&&qM.includes(e)?e:JM}function ZM(e){return e===`all`?`All`:e}var QM=[{value:`compact`,label:`Compact`},{value:`default`,label:`Default`},{value:`comfortable`,label:`Comfortable`}],$M=`leads-column-widths-v1`,eN=`leads-column-order-v1`,tN=`leads-column-pinning-v1`,nN=`leads-column-visibility-v1`,rN={left:[`select`,`name`],right:[]};function iN(e,t){if(typeof window>`u`)return t;try{let n=window.localStorage.getItem(e);return n?JSON.parse(n):t}catch{return t}}function aN(e,t){if(!(typeof window>`u`))try{window.localStorage.setItem(e,JSON.stringify(t))}catch{}}function oN({row:e,cellStyles:t,fmtClass:n,rowHeight:r,isSelected:i,focusedColId:a,onRowClick:o,vrIndex:s}){let c=e.original.id;return(0,L.jsx)(Lk,{"data-index":s,"data-state":i?`selected`:void 0,className:`group cursor-pointer hover:bg-muted/50 ${n}`,style:{height:r},onClick:()=>o(c),children:e.getVisibleCells().map(e=>{let n=t.get(e.column.id),r=a===e.column.id;return(0,L.jsx)(Y,{"data-focused":r?`true`:void 0,className:`${e.column.columnDef.meta?.cellClassName??``} ${n?.bodyClassName??``}`,style:n?.bodyStyle,onClick:e.column.columnDef.meta?.stopRowClick?e=>e.stopPropagation():void 0,children:$O(e.column.columnDef.cell,e.getContext())},e.id)})})}var sN=(0,_.memo)(oN,(e,t)=>e.row.original===t.row.original&&e.cellStyles===t.cellStyles&&e.fmtClass===t.fmtClass&&e.rowHeight===t.rowHeight&&e.isSelected===t.isSelected&&e.focusedColId===t.focusedColId&&e.onRowClick===t.onRowClick&&e.vrIndex===t.vrIndex),cN=1e4;function lN(){let e=et(),[t,n]=jn(),r=ri(),i=Number(t.get(`page`)??`0`),a=t.get(`search`)??``,o=t.get(`trash`)===`true`,s=(0,_.useMemo)(()=>{let e={};for(let n of Mj(t))e[n.columnId]=n;let n=t.get(`warmth`);n&&!e.warmth&&(e.warmth={columnId:`warmth`,type:`select`,operator:`in`,values:[n]});let r=t.get(`status`);return r&&!e.status&&(e.status={columnId:`status`,type:`select`,operator:`in`,values:[r]}),e},[t]),c=(0,_.useMemo)(()=>{let e=Fj(t);return e.length>0?e:[{columnId:`recency`,order:`desc`}]},[t]),l=t.has(`sort`)||t.has(`sortBy`),u=XM(t.get(`pageSize`)),d=u===`all`,f=d?YM:Number(u),[p,m]=oA(),h=rA[p],[g,v]=(0,_.useState)(null),[y,b]=(0,_.useState)(!1),x=t.get(`lead`);(0,_.useEffect)(()=>{x&&(v(x),b(!0))},[x]);let S=o?KM:GM,[C,w]=(0,_.useState)(()=>{if(typeof window>`u`)return{};try{let e=window.sessionStorage.getItem(S);if(!e)return{};let t=JSON.parse(e),n={};for(let e of t)n[e]=!0;return n}catch{return{}}});(0,_.useEffect)(()=>{if(!(typeof window>`u`))try{let e=window.sessionStorage.getItem(S);if(!e){w({});return}let t=JSON.parse(e),n={};for(let e of t)n[e]=!0;w(n)}catch{w({})}},[o]),(0,_.useEffect)(()=>
72{if(!(typeof window>`u`))try{let e=Object.keys(C).filter(e=>C[e]);e.length===0?window.sessionStorage.removeItem(S):window.sessionStorage.setItem(S,JSON.stringify(e))}catch{}},[C,S]);let T=(0,_.useCallback)(()=>{if(w({}),typeof window<`u`)try{window.sessionStorage.removeItem(S)}catch{}},[S]),[E,D]=(0,_.useState)(()=>iN($M,{})),[O,k]=(0,_.useState)(()=>iN(eN,[])),[A,j]=(0,_.useState)(()=>iN(tN,rN)),[M,ee]=(0,_.useState)(()=>iN(nN,{})),N=(0,_.useRef)(null);(0,_.useEffect)(()=>aN($M,E),[E]),(0,_.useEffect)(()=>aN(tN,A),[A]),(0,_.useEffect)(()=>aN(nN,M),[M]),(0,_.useEffect)(()=>aN(eN,O),[O]);let[P,F]=(0,_.useState)(()=>FM());(0,_.useEffect)(()=>IM(P),[P]);let I=(0,_.useCallback)(e=>{F(t=>({...t,[e]:!t[e]}))},[]),[te,ne]=(0,_.useState)(null),[re,ie]=(0,_.useState)(!1),ae=(0,_.useRef)(null),oe=(0,_.useRef)(te);oe.current=te;let se=(0,_.useCallback)(()=>Qj({searchParams:t,columnOrder:O,columnVisibility:M,columnPinning:A,columnSizing:E,density:p,pageSize:XM(t.get(`pageSize`))}),[t,O,M,A,E,p]),ce=(0,_.useCallback)(e=>{let t={...e.urlParams};e.pageSize&&e.pageSize!==JM?t.pageSize=e.pageSize:delete t.pageSize,n(t,{replace:!0}),k(e.columnOrder.slice()),ee({...e.columnVisibility}),j({left:(e.columnPinning?.left??[]).slice(),right:(e.columnPinning?.right??[]).slice()}),D({...e.columnSizing}),m(e.density)},[n,m]),le=e=>{n(t=>{let n=new URLSearchParams(t);for(let[t,r]of Object.entries(e))r===``||r===null?n.delete(t):n.set(t,r);return n},{replace:!0})},ue=e=>{let t=typeof e==`function`?e(i):e;le({page:t===0?``:String(t)})},de=t.get(`createdToday`)===`true`,fe=t.get(`contactedToday`)===`true`,pe=t.get(`qualifiedToday`)===`true`,[me,he]=(0,_.useState)(!1),ge=(0,_.useDeferredValue)(a),{data:_e}=vi({queryKey:[`columns`],queryFn:()=>H(`/api/columns`)}),{data:ve}=vi({queryKey:[`agents`],queryFn:()=>H(`/api/agents`),staleTime:6e4}),ye=(0,_.useMemo)(()=>(ve?.data??[]).map(e=>e.name).filter(e=>!!e&&e.trim().length>0),[ve]),be=(0,_.useMemo)(()=>(ve?.data??[]).map(e=>({id:e.id,name:e.name??`â`})),[ve]),xe=f,Se=d?0:i*f,Ce=Ij(c),we=(0,_.useMemo)(()=>{let e=[];for(let t of Object.keys(s).sort()){let n=s[t];n&&e.push([Pj(n.columnId),Nj(n)])}return e},[s]),Te=t.get(`country`)??`all`,Ee={sortString:Ce,search:ge,filterEntries:we,createdToday:de,contactedToday:fe,qualifiedToday:pe,trashView:o,country:Te},De=Lj(Ee,{limit:xe,offset:Se}),{data:Oe,isLoading:ke}=vi({queryKey:[`leads`,i,u,ge,Ce,we,de,fe,pe,o,Te],queryFn:()=>H(`/api/leads?${De.toString()}`)}),Ae=R({mutationFn:({id:e,updates:t})=>H(`/api/leads/${e}`,{method:`PUT`,body:JSON.stringify(t)}),onSuccess:()=>{z.success(`Saved`),r.invalidateQueries({queryKey:[`leads`]}),r.invalidateQueries({queryKey:[`lead-detail`]})},onError:(e,t)=>{if(e instanceof lC&&e.status===409&&`notesBase`in t.updates){z.error(`Notes were updated elsewhere - refreshing with the latest.`),r.invalidateQueries({queryKey:[`leads`]}),r.invalidateQueries({queryKey:[`lead-detail`]});return}z.error(e.message||`Failed to save`)}}),je=R({mutationFn:e=>H(`/api/leads/${e}/restore`,{method:`POST`}),onSuccess:()=>{z.success(`Lead restored`),r.invalidateQueries({queryKey:[`leads`]}),r.invalidateQueries({queryKey:[`lead-detail`]})},onError:e=>z.error(e.message)}),Me=R({mutationFn:({id:e,isVisible:t})=>H(`/api/columns/${e}`,{method:`PUT`,body:JSON.stringify({isVisible:t})}),onSuccess:()=>r.invalidateQueries({queryKey:[`columns`]})}),Ne=R({mutationFn:({id:e,displayOrder:t})=>H(`/api/columns/${e}`,{method:`PUT`,body:JSON.stringify({displayOrder:t})}),onError:e=>z.error(e.message)}),Pe=R({mutationFn:({sourceTab:e,isVisible:t})=>H(`/api/columns/bulk-visibility`,{method:`PUT`,body:JSON.stringify({sourceTab:e,isVisible:t})}),onSuccess:()=>r.invalidateQueries({queryKey:[`columns`]})}),Fe=R({mutationFn:()=>H(`/api/leads/sync/new`,{method:`POST`}),onSuccess:e=>{z.success(e.message),r.invalidateQueries({queryKey:[`leads`]})},onError:e=>z.error(e.message)}),Ie=R({mutationFn:()=>H(`/api/leads/sync`,{method:`POST`}),onSuccess:e=>{z.success(e.message),r.invalidateQueries({queryKey:[`leads`]}),r.invalidateQueries({queryKey:[`columns`]})},onError:e=>z.error(e.message)}),Le=async()=>{he(!0);try{let e=Lj(Ee,{limit:cN,offset:0}),[t,n]=await Promise.all([H(`/api/leads?${e.toString()}`),H(`/api/columns`)]),r=(n.data??[]).filter(e=>e.sourceTab===`agent_monitoring`?e.isExtra&&e.isVisible:e.sourceTab===`lead_database`?e.isVisible:!1),i=[`Name`,`Date`,`Phone`,`Source`,`Origin`,`Warmth`,`Status`,`Agent`,`Notes`,...r.map(e=>e.sheetHeaderName),`Created`],a=(t.data??[]).map(e=>[e.name,e.sheetDate??``,e.phone,e.source??``,Kk[e.origin],e.warmth,e.status,e.assignedAgentName??``,e.
72notes??``,...r.map(t=>EM(e,t)??``),new Date(e.createdAt).toISOString()]);Wk(i,a,`leads-${new Date().toISOString().split(`T`)[0]}.csv`),t.total>a.length&&z.warning(`Exported the first ${a.length.toLocaleString()} of ${t.total.toLocaleString()} matching leads. Narrow the filters to export the rest.`)}catch(e){console.error(`Failed to export CSV:`,e),z.error(e instanceof Error?`Export failed: ${e.message}`:`Export failed`)}finally{he(!1)}},Re=(0,_.useMemo)(()=>_e?.data??[],[_e]),ze=(0,_.useMemo)(()=>Re.filter(e=>e.sourceTab===`agent_monitoring`?e.isExtra&&e.isVisible:e.sourceTab===`lead_database`?e.isVisible:!1).slice().sort((e,t)=>e.displayOrder-t.displayOrder),[Re]),Be=(0,_.useMemo)(()=>Re.filter(e=>e.sourceTab===`agent_monitoring`&&e.isExtra),[Re]),Ve=(0,_.useMemo)(()=>Re.filter(e=>e.sourceTab===`lead_database`),[Re]),He=(0,_.useMemo)(()=>Oe?.data??[],[Oe]),Ue=Oe?.total??0,We=Math.max(1,Math.ceil(Ue/f)),{data:Ge}=uC.useSession(),Ke=Ge?.user?.id,qe=(0,_.useMemo)(()=>He.map(e=>e.id).slice().sort().join(`,`),[He]),Je=vi({queryKey:[`lead-comments-summary`,qe],enabled:qe.length>0,staleTime:3e4,queryFn:async()=>(await H(`/api/lead-comments/summary/batch?leadIds=${encodeURIComponent(qe)}`)).data??{}}),Ye=(0,_.useCallback)((e,t)=>Je.data?.[e]?.[t]??0,[Je.data]),Xe=(0,_.useCallback)(e=>Ae.mutateAsync(e).then(()=>!0,()=>!1),[Ae]),Ze=(0,_.useCallback)(t=>e(`/messages?lead=${t}`),[e]),Qe=(0,_.useCallback)(e=>je.mutate(e),[je]),$e=(0,_.useCallback)(e=>{v(e),b(!0)},[]),tt=(0,_.useCallback)((e,t)=>{n(n=>{let r=new URLSearchParams(n),i=Pj(e);return t?r.set(i,Nj(t)):r.delete(i),r.delete(`warmth`),r.delete(`status`),r.delete(`sortBy`),r.delete(`sortOrder`),r.delete(`page`),r},{replace:!0})},[n]),nt=(0,_.useCallback)((e,t)=>{n(n=>{let r=new URLSearchParams(n),i=Fj(r),a,o=i.findIndex(t=>t.columnId===e);return t?o===-1?a=[...i,{columnId:e,order:`desc`}]:(a=i.slice(),a[o]={columnId:e,order:i[o].order===`asc`?`desc`:`asc`}):a=o===0&&i.length===1?[{columnId:e,order:i[0].order===`asc`?`desc`:`asc`}]:[{columnId:e,order:`desc`}],r.set(`sort`,Ij(a)),r.delete(`sortBy`),r.delete(`sortOrder`),r.delete(`page`),r},{replace:!0})},[n]),rt=(0,_.useMemo)(()=>DM({visibleDynamicColumns:ze,onInlineUpdate:Xe,onNavigateToChat:Ze,onOpenDrawer:$e,trashView:o,onRestoreLead:Qe,restorePending:je.isPending,columnFilters:s,onColumnFilterChange:tt,sorts:c,onHeaderSort:nt,agentNameOptions:ye,agentOptions:be,getCommentCount:Ye,currentUserId:Ke}),[ze,Xe,Ze,$e,o,Qe,je.isPending,s,tt,c,nt,ye,be,Ye,Ke]),it=(0,_.useMemo)(()=>{let e=[`select`,`name`,`sheetDate`,`phone`,`source`,`origin`,`warmth`,`status`,`assignedAgentName`,`notes`,...ze.map(e=>`dyn-${e.id}`),`createdAt`];return o&&e.push(`restore`),e},[ze,o]);(0,_.useEffect)(()=>{let e=new Set(it),t=new Set(O),n=it.filter(e=>!t.has(e)),r=O.filter(t=>e.has(t));n.length===0&&r.length===O.length||k(r.length+n.length>0?[...r,...n]:it)},[it,O]);let at=(0,_.useCallback)((e,t)=>{if(e===t)return;let n=O.length>0?O:it,r=n.indexOf(e),i=n.indexOf(t);if(r<0||i<0)return;let a=n.slice(),[o]=a.splice(r,1);a.splice(i,0,o),k(a),a.filter(e=>e.startsWith(`dyn-`)).forEach((e,t)=>{let n=e.slice(4),r=ze.find(e=>e.id===n);r&&r.displayOrder!==t&&Ne.mutate({id:n,displayOrder:t})})},[O,it,ze,Ne]),ot=(0,_.useMemo)(()=>({pageIndex:d?0:i,pageSize:f}),[d,i,f]),st=rk({data:He,columns:rt,state:{pagination:ot,rowSelection:C,columnSizing:E,columnOrder:O,columnPinning:A,columnVisibility:M},getRowId:e=>e.id,manualSorting:!0,manualFiltering:!0,manualPagination:!0,pageCount:We,enableColumnResizing:!0,columnResizeMode:`onEnd`,onPaginationChange:e=>{ue((typeof e==`function`?e(ot):e).pageIndex)},onRowSelectionChange:w,onColumnSizingChange:D,onColumnOrderChange:k,onColumnPinningChange:j,onColumnVisibilityChange:ee,getCoreRowModel:QO()}),ct=(0,_.useMemo)(()=>new Set(Object.keys(C).filter(e=>C[e])),[C]),lt=(0,_.useMemo)(()=>He.reduce((e,t)=>ct.has(t.id)?e+1:e,0),[He,ct]),ut=Math.max(0,ct.size-lt),dt=(0,_.useMemo)(()=>WM(st),[st,E,A,O,M]),ft=(0,_.useMemo)(()=>{let e=new Map;for(let t of He)e.set(t.id,LM(t,P));return e},[He,P]),pt=(0,_.useRef)(null),mt=st.getRowModel().rows,ht=Sk({count:mt.length,getScrollElement:()=>pt.current,estimateSize:()=>h,overscan:10}),gt=ht.getVirtualItems(),_t=ht.getTotalSize(),vt=gt.length>0?gt[0].start:0,yt=gt.length>0?_t-gt[gt.length-1].end:0,bt=(0,_.useMemo)(()=>st.getVisibleLeafColumns().map(e=>e.id).filter(e=>e!==`select`),[st,O,M]);(0,_.useEffect)(()=>
72{if(!te)return;let e=mt.some(e=>e.id===te.rowId),t=bt.includes(te.colId);(!e||!t)&&ne(null)},[te,mt,bt]);let xt=(0,_.useRef)(mt);xt.current=mt;let St=(0,_.useRef)(bt);St.current=bt;let Ct=(0,_.useCallback)((e,t)=>{let n=xt.current,r=St.current;n.length===0||r.length===0||ne(i=>{if(!i)return{rowId:n[0].id,colId:r[0]};let a=n.findIndex(e=>e.id===i.rowId),o=r.indexOf(i.colId);if(a<0||o<0)return{rowId:n[0].id,colId:r[0]};let s=Math.max(0,Math.min(n.length-1,a+t)),c=Math.max(0,Math.min(r.length-1,o+e));return{rowId:n[s].id,colId:r[c]}})},[]),wt=(0,_.useRef)(st);wt.current=st;let Tt=(0,_.useRef)(re);Tt.current=re;let Et=(0,_.useMemo)(()=>[{keys:`mod+k`,allowInInputs:!0,group:`Search`,description:`Focus search`,handler:e=>{e.preventDefault(),ae.current?.focus(),ae.current?.select()}},{keys:`/`,group:`Search`,description:`Focus search`,handler:e=>{e.preventDefault(),ae.current?.focus(),ae.current?.select()}},{keys:`mod+a`,group:`Selection`,description:`Select all on page`,handler:e=>{e.preventDefault(),wt.current.toggleAllPageRowsSelected(!0)}},{keys:`?`,group:`Help`,description:`Show keyboard shortcuts`,handler:e=>{e.preventDefault(),ie(e=>!e)}},{keys:`ArrowUp`,group:`Navigation`,description:`Move focus up`,handler:e=>{e.preventDefault(),Ct(0,-1)}},{keys:`ArrowDown`,group:`Navigation`,description:`Move focus down`,handler:e=>{e.preventDefault(),Ct(0,1)}},{keys:`ArrowLeft`,group:`Navigation`,description:`Move focus left`,handler:e=>{e.preventDefault(),Ct(-1,0)}},{keys:`ArrowRight`,group:`Navigation`,description:`Move focus right`,handler:e=>{e.preventDefault(),Ct(1,0)}},{keys:`Enter`,group:`Editing`,description:`Edit focused cell`,handler:e=>{oe.current&&(e.preventDefault(),(document.querySelector(`td[data-focused="true"]`)?.querySelector(`[role="button"]`))?.dispatchEvent(new MouseEvent(`dblclick`,{bubbles:!0,cancelable:!0})))}},{keys:`Escape`,allowInInputs:!0,group:`Editing`,description:`Close modal / blur`,handler:()=>{if(Tt.current){ie(!1);return}let e=document.activeElement;e instanceof HTMLElement&&e.blur()}}],[Ct]);ME(Et,!re);let Dt=(0,L.jsxs)(`div`,{className:`flex items-center justify-start gap-6`,children:[(0,L.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[Ue,` total leads`]}),!d&&(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(W,{variant:`outline`,size:`sm`,disabled:i===0,onClick:()=>ue(e=>e-1),children:`Previous`}),(0,L.jsxs)(`span`,{className:`text-sm text-muted-foreground`,children:[`Page `,i+1,` of `,We]}),(0,L.jsx)(W,{variant:`outline`,size:`sm`,disabled:i+1>=We,onClick:()=>ue(e=>e+1),children:`Next`})]})]});return(0,L.jsxs)(`div`,{className:`space-y-6`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,L.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:o?`Trash`:`Leads`}),!o&&(0,L.jsx)(sA,{interval:`5 min`,source:`Google Sheets`})]}),(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:o?`Deleted leads are kept for 30 days and then permanently removed.`:`All leads synced from Google Sheets with warmth scores`})]}),(0,L.jsxs)(`div`,{className:`hidden md:flex items-center gap-3`,children:[(0,L.jsx)(G,{ref:ae,placeholder:`Search name, phone, email, source...`,value:a,onChange:e=>{le({search:e.target.value,page:``})},className:`w-64`}),(0,L.jsxs)(wk,{value:u,onValueChange:e=>{let t=XM(e);le({pageSize:t===JM?``:t,page:``})},children:[(0,L.jsx)(Dk,{className:`w-28`,"aria-label":`Rows per page`,children:(0,L.jsx)(Ek,{placeholder:`Rows`})}),(0,L.jsx)(Ok,{children:qM.map(e=>(0,L.jsx)(Ak,{value:e,children:ZM(e)},e))})]}),(0,L.jsxs)(wk,{value:p,onValueChange:e=>m(e),children:[(0,L.jsx)(Dk,{className:`w-36`,"aria-label":`Row density`,children:(0,L.jsx)(Ek,{placeholder:`Density`})}),(0,L.jsx)(Ok,{children:QM.map(e=>(0,L.jsx)(Ak,{value:e.value,children:e.label},e.value))})]}),(0,L.jsxs)(wk,{value:Te,onValueChange:e=>le({country:e===`all`?``:e,page:``}),children:[(0,L.jsx)(Dk,{className:`w-32`,"aria-label":`Country filter`,children:(0,L.jsx)(Ek,{placeholder:`Country`})}),(0,L.jsxs)(Ok,{children:[(0,L.jsx)(Ak,{value:`all`,children:`All countries`}),(0,L.jsx)(Ak,{value:`sg`,children:`SG only`}),(0,L.jsx)(Ak,{value:`non-sg`,children:`Non-SG only`})]})]})]}),(0,L.jsx)(`div`,{className:`flex md:hidden items-center gap-2`,children:(0,L.jsx)(G,{placeholder:`Search...`,value:a,onChange:e=>le({search:e.target.value,page:``}),className:`flex-1`})}),(0,L.jsxs)(`div`,{className:`hidden md:flex items-center gap-2`,children:[!
72o&&(0,L.jsx)(gj,{}),!o&&(0,L.jsx)(Yj,{captureConfig:se,applyConfig:ce}),(0,L.jsxs)(YT,{children:[(0,L.jsx)(XT,{asChild:!0,children:(0,L.jsxs)(W,{variant:`outline`,size:`sm`,children:[(0,L.jsx)(iT,{className:`h-4 w-4 mr-1.5`}),`Columns`,ze.length>0&&(0,L.jsxs)(`span`,{className:`ml-1.5 text-xs text-muted-foreground`,children:[`(`,ze.length,`)`]})]})}),(0,L.jsxs)($T,{side:`right`,className:`overflow-y-auto`,children:[(0,L.jsx)(eE,{children:(0,L.jsx)(tE,{children:`Visible Columns`})}),(0,L.jsxs)(`div`,{className:`space-y-6 px-4 pb-4`,children:[(0,L.jsxs)(`div`,{className:`space-y-3`,children:[(0,L.jsx)(`h3`,{className:`text-sm font-medium`,children:`Core Columns`}),(0,L.jsx)(`div`,{className:`space-y-2`,children:OM.filter(e=>e!==`select`).map(e=>{let t=e!==`name`,n=M[e]!==!1;return(0,L.jsxs)(`label`,{className:`flex items-center justify-between gap-2 text-sm`,children:[(0,L.jsx)(`span`,{className:`truncate`,children:kM[e]??e}),(0,L.jsx)(Ck,{checked:n,disabled:!t,onCheckedChange:t=>ee(n=>({...n,[e]:t}))})]},e)})})]}),Be.length>0&&(0,L.jsxs)(`div`,{className:`space-y-3`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsx)(`h3`,{className:`text-sm font-medium`,children:`Agent Monitoring`}),(0,L.jsxs)(`div`,{className:`flex gap-2`,children:[(0,L.jsx)(W,{variant:`ghost`,size:`sm`,className:`h-6 px-2 text-xs`,onClick:()=>Pe.mutate({sourceTab:`agent_monitoring`,isVisible:!0}),children:`Show all`}),(0,L.jsx)(W,{variant:`ghost`,size:`sm`,className:`h-6 px-2 text-xs`,onClick:()=>Pe.mutate({sourceTab:`agent_monitoring`,isVisible:!1}),children:`Hide all`})]})]}),(0,L.jsx)(`div`,{className:`space-y-2`,children:Be.map(e=>(0,L.jsxs)(`label`,{className:`flex items-center justify-between gap-2 text-sm`,children:[(0,L.jsx)(`span`,{className:`truncate`,children:e.sheetHeaderName}),(0,L.jsx)(Ck,{checked:e.isVisible,onCheckedChange:t=>Me.mutate({id:e.id,isVisible:t})})]},e.id))})]}),Ve.length>0&&(0,L.jsxs)(`div`,{className:`space-y-3`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsx)(`h3`,{className:`text-sm font-medium`,children:`Lead Database`}),(0,L.jsxs)(`div`,{className:`flex gap-2`,children:[(0,L.jsx)(W,{variant:`ghost`,size:`sm`,className:`h-6 px-2 text-xs`,onClick:()=>Pe.mutate({sourceTab:`lead_database`,isVisible:!0}),children:`Show all`}),(0,L.jsx)(W,{variant:`ghost`,size:`sm`,className:`h-6 px-2 text-xs`,onClick:()=>Pe.mutate({sourceTab:`lead_database`,isVisible:!1}),children:`Hide all`})]})]}),(0,L.jsx)(`div`,{className:`space-y-2`,children:Ve.map(e=>(0,L.jsxs)(`label`,{className:`flex items-center justify-between gap-2 text-sm`,children:[(0,L.jsx)(`span`,{className:`truncate`,children:e.sheetHeaderName}),(0,L.jsx)(Ck,{checked:e.isVisible,onCheckedChange:t=>Me.mutate({id:e.id,isVisible:t})})]},e.id))})]})]})]})]}),(0,L.jsxs)(YT,{children:[(0,L.jsx)(XT,{asChild:!0,children:(0,L.jsxs)(W,{variant:`outline`,size:`sm`,children:[(0,L.jsx)(Fw,{className:`h-4 w-4 mr-1.5`}),`Formatting`,(()=>{let e=Object.values(P).filter(Boolean).length;return e>0?(0,L.jsxs)(`span`,{className:`ml-1.5 text-xs text-muted-foreground`,children:[`(`,e,`)`]}):null})()]})}),(0,L.jsxs)($T,{side:`right`,className:`overflow-y-auto`,children:[(0,L.jsx)(eE,{children:(0,L.jsx)(tE,{children:`Conditional Formatting`})}),(0,L.jsxs)(`div`,{className:`space-y-4 px-4 pb-4`,children:[(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Toggle built-in rules to tint rows based on lead attributes. Rules stack â multiple enabled rules layer visually.`}),(0,L.jsx)(`div`,{className:`space-y-3`,children:MM.map(e=>(0,L.jsxs)(`label`,{className:`flex items-start justify-between gap-3 text-sm`,children:[(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsx)(`div`,{className:`font-medium`,children:e.label}),(0,L.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:e.description})]}),(0,L.jsx)(Ck,{checked:P[e.id],onCheckedChange:()=>I(e.id)})]},e.id))})]})]})]}),(0,L.jsxs)(W,{variant:`outline`,size:`sm`,onClick:Le,disabled:me,children:[(0,L.jsx)(iw,{className:`h-4 w-4 mr-1.5`}),me?`Exporting...`:`Export CSV`]}),(0,L.jsx)(vj,{}),(0,L.jsxs)(W,{variant:`outline`,size:`sm`,onClick:()=>{let e=t.toString(),n=e?`/leads/print?${e}`:`/leads/print`;window.open(n,`_blank`,`noopener,noreferrer`)},children:[(0,L.jsx)(Kw,{className:`h-4 w-4 mr-1.5`}),`Print view`]}),(0,L.jsxs)(W,{variant:`outline`,size:`sm`,disabled:Fe.isPending,onClick:()=>Fe.mutate(),children:[(0,L.jsx)(iw,{className:`h-4 w-4 mr-1.5`}),Fe.isPending?`Syncing...`:`Get New Rows`]}),!o&&(0,L.jsxs)(W,{variant:`outline`,size:`sm`,disabled:Ie.isPending,onClick:()=>Ie.mutate(),children:[(0,L.jsx)(Yw,{className:`h-4 w-4 mr-1.5 ${Ie.isPending?`animate-spin`:``}`}),Ie.isPending?`Syncing...`:`Full Sync`]})]}),(0,L.jsx)(`div`,{className:`hidden md:flex`,children:(0,L.jsx)(W,{variant:o?`default`:`outline`,size:`sm`,onClick:()=>{le({trash:o?``:`true`,page:``}),T()},children:o?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(bC,{className:`h-4 w-4 mr-1.5`}),`Back to Leads`]}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(vT,{className:`h-4 w-4 mr-1.5`}),`View Trash`]})})}),(0,L.jsx)(`div`,{className:`hidden md:block`,children:(0,L.jsx)(Hj,{filters:s,sorts:c,hasExplicitSort:l,hasSearch:!!a,hasDateDrilldown:de||fe||pe,onRemoveFilter:e=>tt(e,void 0),onRemoveSort:e=>{let t=c.filter(t=>t.columnId!==e);n(e=>{let n=new URLSearchParams(e);return t.length===0?n.delete(`sort`):n.set(`sort`,Ij(t)),n.delete(`sortBy`),n.delete(`sortOrder`),n.delete(`page`),n},{replace:!0})},onClearAll:()=>n({},{replace:!0})})}),(0,L.jsx)(Sj,{selectedIds:ct,hiddenCount:ut,onClear:T,trashView:o,dynamicColumns:Re.filter(e=>e.sourceTab===`agent_monitoring`?e.isExtra:!0),leadsOnPage:He}),ke?(0,L.jsx)(`div`,{className:`rounded-md border p-8 text-center text-muted-foreground`,children:`Loading...`}):He.length===0&&i===0?(0,L.jsx)(`div`,{className:`rounded-md border p-8 text-center text-muted-foreground`,children:o?`Trash is empty.`:`No leads yet. Connect Google Sheets to sync leads.`}):(0,L.jsxs)(L.Fragment,{children:[Dt,(0,L.jsx)(`div`,{className:`md:hidden`,children:(0,L.jsx)(eM,{leads:He,onSelect:e=>{v(e),b(!0)},onMessage:t=>e(`/messages?lead=${t}`)})}),(0,L.jsx)(`div`,{ref:pt,className:d?`hidden md:block rounded-md border overflow-auto max-h-[70vh] relative`:`hidden md:block rounded-md border overflow-auto max-h-[calc(100vh-22rem)] relative`,children:(0,L.jsxs)(`table`,{className:`caption-bottom text-sm`,style:{width:st.getTotalSize(),tableLayout:`fixed`},children:[(0,L.jsx)(Fk,{className:`sticky top-0 z-10 bg-background shadow-[0_1px_0_0_var(--border)]`,children:st.getHeaderGroups().map(e=>(0,L.jsx)(Lk,{children:e.headers.map(e=>{let t=e.isPlaceholder,n=e.column.getIsPinned(),r=dt.get(e.column.id),i=e.column.id!==`select`;return(0,L.jsxs)(Rk,{children:[(0,L.jsx)(zk,{asChild:!0,disabled:!i,children:(0,L.jsxs)(J,{colSpan:e.colSpan,draggable:i,onDragStart:()=>
72{i&&(N.current=e.column.id)},onDragOver:t=>{N.current&&N.current!==e.column.id&&(t.preventDefault(),t.dataTransfer.dropEffect=`move`)},onDrop:t=>{t.preventDefault();let n=N.current;N.current=null,!(!n||n===e.column.id)&&at(n,e.column.id)},onDragEnd:()=>{N.current=null},className:`${e.column.columnDef.meta?.headClassName??``} ${r?.headClassName??``} ${i?`cursor-grab active:cursor-grabbing`:``} relative group select-none`,style:r?.headStyle,children:[t?null:$O(e.column.columnDef.header,e.getContext()),e.column.getCanResize()&&(0,L.jsx)(`div`,{onMouseDown:e.getResizeHandler(),onTouchStart:e.getResizeHandler(),onClick:e=>e.stopPropagation(),onDragStart:e=>e.preventDefault(),draggable:!1,className:`absolute top-0 right-0 h-full w-1 cursor-col-resize select-none touch-none opacity-0 group-hover:opacity-100 hover:bg-primary/40 ${e.column.getIsResizing()?`bg-primary opacity-100`:``}`})]})}),i&&(0,L.jsxs)(Bk,{children:[(0,L.jsxs)(Vk,{disabled:n===`left`,onSelect:()=>e.column.pin(`left`),children:[(0,L.jsx)(Uw,{className:`h-4 w-4 mr-2`}),`Pin to left`]}),(0,L.jsxs)(Vk,{disabled:n===`right`,onSelect:()=>e.column.pin(`right`),children:[(0,L.jsx)(Uw,{className:`h-4 w-4 mr-2 rotate-180`}),`Pin to right`]}),(0,L.jsx)(Hk,{}),(0,L.jsxs)(Vk,{disabled:!n,onSelect:()=>e.column.pin(!1),children:[(0,L.jsx)(Hw,{className:`h-4 w-4 mr-2`}),`Unpin`]}),e.column.getCanHide()&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(Hk,{}),(0,L.jsx)(Vk,{onSelect:()=>e.column.toggleVisibility(!1),children:`Hide column`})]})]})]},e.id)})},e.id))}),(0,L.jsx)(Ik,{children:d?(0,L.jsxs)(L.Fragment,{children:[vt>0&&(0,L.jsx)(`tr`,{"aria-hidden":`true`,style:{height:vt},children:(0,L.jsx)(`td`,{colSpan:rt.length})}),gt.map(e=>{let t=mt[e.index];if(!t)return null;let n=ft.get(t.original.id)??``,r=te?.rowId===t.id?te.colId:null;return(0,L.jsx)(sN,{row:t,cellStyles:dt,fmtClass:n,rowHeight:h,isSelected:t.getIsSelected(),focusedColId:r,onRowClick:$e,vrIndex:e.index},t.id)}),yt>0&&(0,L.jsx)(`tr`,{"aria-hidden":`true`,style:{height:yt},children:(0,L.jsx)(`td`,{colSpan:rt.length})})]}):mt.map(e=>{let t=ft.get(e.original.id)??``,n=te?.rowId===e.id?te.colId:null;return(0,L.jsx)(sN,{row:e,cellStyles:dt,fmtClass:t,rowHeight:h,isSelected:e.getIsSelected(),focusedColId:n,onRowClick:$e},e.id)})})]})}),!d&&Dt]}),(0,L.jsx)(ij,{leadId:g,open:y,onClose:()=>{b(!1),v(null),t.has(`lead`)&&n(e=>{let t=new URLSearchParams(e);return t.delete(`lead`),t})}}),(0,L.jsx)(RM,{open:re,onOpenChange:ie,bindings:Et})]})}var uN=200;function dN(e,t){return t.sourceTab===`lead_database`?e.leadProfileData?.[t.dbField??t.sheetHeaderName]:e.extraColumns?.[t.sheetHeaderName]}function fN(e){if(!e)return`â`;let t=e.trim();if(!t)return`â`;let n=null,r=t.match(/^(\d{4}-\d{2}-\d{2}T[\d:.]+Z?)/);if(r){let e=new Date(r[1]);isNaN(e.getTime())||(n=e)}if(!n){let e=t.match(/^(\d{1,2})[/\-.](\d{1,2})[/\-.](\d{4})$/);if(e){let[,t,r,i]=e;n=new Date(Number(i),Number(r)-1,Number(t))}}if(!n){let e=t.match(/^(\d{4})[/\-.](\d{1,2})[/\-.](\d{1,2})$/);if(e){let[,t,r,i]=e;n=new Date(Number(t),Number(r)-1,Number(i))}}if(!n){let e=new Date(t);isNaN(e.getTime())||(n=e)}return!n||isNaN(n.getTime())?t:n.toLocaleDateString(`en-SG`,{day:`numeric`,month:`short`,year:`numeric`})}async function pN(e,t=5e3){let n=[],r=0,i=0;for(;n.length<t;){let t=new URLSearchParams(e);t.set(`limit`,String(uN)),t.set(`offset`,String(i));let a=await H(`/api/leads?${t.toString()}`);r=a.total;let o=a.data??[];if(n.push(...o),o.length<uN||(i+=uN,i>=r))break}return{data:n,total:r}}function mN(e){let t=[],n=e.get(`search`),r=e.get(`warmth`),i=e.get(`status`),a=e.get(`source`),o=e.get(`sortBy`),s=e.get(`sortOrder`);return e.get(`trash`)===`true`&&t.push(`Trash view`),n&&t.push(`Search: ${n}`),r&&t.push(`Warmth: ${r}`),i&&t.push(`Status: ${i.replace(/_/g,` `)}`),a&&t.push(`Source: ${a}`),e.get(`createdToday`)===`true`&&t.push(`Created today`),e.get(`contactedToday`)===`true`&&t.push(`Contacted today`),e.get(`qualifiedToday`)===`true`&&t.push(`Qualified today`),o&&t.push(`Sort: ${o}${s===`asc`?` â`:` â`}`),t.join(` · `)}function hN(){let[e]=jn(),t=new URLSearchParams;for(let[n,r]of e.entries())n===`page`||n===`limit`||n===`offset`||t.set(n,r);let{data:n}=vi({queryKey:[`columns`],queryFn:()=>H(`/api/columns`)}),{data:r,isLoading:i,error:a}=vi({queryKey:[`leads-print`,t.toString()],queryFn:()=>pN(t),staleTime:1/0});(0,_.useEffect)(()=>{let e=document.title,t=new Date().toLocaleDateString(`en-SG`,{day:`numeric`,month:`short`,year:`numeric`});return document.title=`Leads â ${t}`,()=>{document.title=e}},[]);let o=(n?.data??[]).filter(e=>e.sourceTab===`agent_monitoring`?e.isExtra&&e.isVisible:e.sourceTab===`lead_database`?e.isVisible:!1),s=r?.data??[],c=r?.total??0,l=s.length<c,u=new Date().toLocaleDateString(`en-SG`,{day:`numeric`,month:`short`,year:`numeric`}),d=mN(t);return(0,L.jsxs)(`div`,{className:`leads-print-root`,children:[(0,L.jsx)(`style`,{children:` 73 @page { size: A4 landscape; margin: 12mm; } 74 75 .leads-print-root { 76 color: black; 77 background: white; 78 font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif; 79 } 80 81 @media screen { 82 .leads-print-root { 83 min-height: 100vh; 84 padding: 24px; 85 } 86 .leads-print-container { 87 max-width: 1600px; 88 margin: 0 auto; 89 } 90 .leads-print-toolbar { 91 display: flex; 92 align-items: center; 93 justify-content: space-between; 94 gap: 12px; 95 margin-bottom: 16px; 96 } 97 } 98 99 @media print { 100 /* Hide anything marked as screen-only. */ 101 .no-print { display: none !important; } 102 103 body { margin: 0; color: black; background: white; } 104 .leads-print-root { padding: 0; } 105 } 106 107 .leads-print-header h1 { 108 font-size: 18pt; 109 font-weight: 600; 110 margin: 0 0 4px 0; 111 } 112 .leads-print-header .meta { 113 font-size: 10pt; 114 color: #333; 115 } 116 117 table.leads-print-table { 118 width: 100%; 119 border-collapse: collapse; 120 margin-top: 12px; 121 font-size: 9pt; 122 color: black; 123 } 124 table.leads-print-table thead { 125 display: table-header-group; /* repeat on each printed page */ 126 } 127 table.leads-print-table tr { 128 page-break-inside: avoid; 129 break-inside: avoid; 130 } 131 table.leads-print-table th, 132 table.leads-print-table td { 133 border: 1px solid #999; 134 padding: 4px 6px; 135 text-align: left; 136 vertical-align: top; 137 } 138 table.leads-print-table th { 139 background: #f0f0f0; 140 font-weight: 600; 141 } 142 table.leads-print-table td.muted { 143 color: #666; 144 } 145 table.leads-print-table td.mono { 146 font-family: ui-monospace, SFMono-Regular, Menlo, monospace; 147 } 148 `}),(0,L.jsxs)(`div`,{className:`leads-print-container`,children:[(0,L.jsxs)(`div`,{className:`leads-print-toolbar no-print`,children:[(0,L.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`This is a print-friendly view. Use your browser's print dialog (or "Save as PDF") to produce a hard copy.`}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(W,{variant:`outline`,size:`sm`,onClick:()=>window.close(),children:`Close`}),(0,L.jsx)(W,{size:`sm`,onClick:()=>window.print(),children:`Print now`})]})]}),(0,L.jsxs)(`div`,{className:`leads-print-header`,children:[(0,L.jsx)(`h1`,{children:`Leads`}),(0,L.jsxs)(`div`,{className:`meta`,children:[u,` · `,s.length,` of `,c,` leads`,l?` (showing first rows)`:``,d?` · ${d}`:``]})]}),i?(0,L.jsx)(`p`,{className:`no-print`,style:{marginTop:24},children:`Loading leadsâ¦`}):a?(0,L.jsxs)(`p`,{className:`no-print`,style:{marginTop:24,color:`#b00`},children:[`Failed to load leads: `,a.message]}):s.length===0?(0,L.jsx)(`p`,{style:{marginTop:24},children:`No leads match the current filters.`}):(0,L.jsxs)(`table`,{className:`leads-print-table`,children:[(0,L.jsx)(`thead`,{children:(0,L.jsxs)(`tr`,{children:[(0,L.jsx)(`th`,{children:`N
148ame`}),(0,L.jsx)(`th`,{children:`Date`}),(0,L.jsx)(`th`,{children:`Phone`}),(0,L.jsx)(`th`,{children:`Source`}),(0,L.jsx)(`th`,{children:`Warmth`}),(0,L.jsx)(`th`,{children:`Status`}),(0,L.jsx)(`th`,{children:`Agent`}),o.map(e=>(0,L.jsx)(`th`,{children:e.sheetHeaderName},e.id)),(0,L.jsx)(`th`,{children:`Created`})]})}),(0,L.jsx)(`tbody`,{children:s.map(e=>(0,L.jsxs)(`tr`,{children:[(0,L.jsx)(`td`,{children:e.name}),(0,L.jsx)(`td`,{children:fN(e.sheetDate?.trim()?e.sheetDate:e.createdAt)}),(0,L.jsx)(`td`,{className:`mono`,children:e.phone}),(0,L.jsx)(`td`,{children:e.source}),(0,L.jsx)(`td`,{children:e.warmth}),(0,L.jsx)(`td`,{children:e.status.replace(/_/g,` `)}),(0,L.jsx)(`td`,{children:e.assignedAgentName??(0,L.jsx)(`span`,{className:`muted`,children:`â`})}),o.map(t=>(0,L.jsx)(`td`,{children:dN(e,t)??(0,L.jsx)(`span`,{className:`muted`,children:`â`})},t.id)),(0,L.jsx)(`td`,{className:`muted`,children:new Date(e.createdAt).toLocaleDateString()})]},e.id))})]})]})]})}var gN=1e4,_N=new Map,vN=new Set,yN=new Map;function bN(){for(let e of vN)e()}function xN(e){return vN.add(e),()=>{vN.delete(e)}}function SN(e){let t=_N.get(e);if(t)return t;let n=yN.get(e);return n||(n=Object.freeze({}),yN.set(e,n)),n}function CN(e,t,n){let r=_N.get(e)??{},i=Date.now(),a={...n,updatedAt:i};return _N.set(e,{...r,[t]:a}),bN(),i}function wN(e,t,n){let r=_N.get(e);if(!r)return;let i=r[t];if(!i||i.updatedAt!==n||i.state!==`composing`&&i.state!==`recording`)return;let a={state:`paused`,lastSeen:i.lastSeen,updatedAt:Date.now()};_N.set(e,{...r,[t]:a}),bN()}var TN=3e4,EN=3;function DN(){let e=ri(),[t,n]=(0,_.useState)({connected:!1,fallbackMode:!1});return(0,_.useEffect)(()=>{let t=null,r=!1,i=0,a=null,o=()=>{e.invalidateQueries({queryKey:[`conversations`]})},s=t=>{t&&e.invalidateQueries({queryKey:[`messages`,t]})},c=t=>{let n=e.getQueriesData({queryKey:[`conversations`]});for(let[r,i]of n){if(!i?.pages)continue;let n=i.pages.map(t);e.setQueryData(r,{...i,pages:n})}},l=e=>{if(e.status===`draft`&&e.source===`ai`){c(t=>{let n=!1,r=t.data.map(t=>t.id!==e.conversationId||t.hasDrafts?t:(n=!0,{...t,hasDrafts:!0}));return n?{...t,data:r}:t});return}c(t=>{let n=!1,r=t.data.map(t=>t.id===e.conversationId?(n=!0,{...t,lastMessage:{id:e.messageId,body:e.body,direction:e.direction,timestamp:e.timestamp,status:e.direction===`outbound`?`pending`:`delivered`},unreadCount:e.direction===`inbound`?t.unreadCount+1:t.unreadCount}):t);return n?{...t,data:r}:t})},u=e=>{c(t=>{let n=!1,r=t.data.map(t=>t.id!==e.conversationId||!t.lastMessage||t.lastMessage.id!==e.messageId?t:(n=!0,{...t,lastMessage:{...t.lastMessage,status:e.status}}));return n?{...t,data:r}:t})},d=()=>{r||(t=new EventSource(`/api/messages/stream`,{withCredentials:!0}),t.onopen=()=>{r||(i=0,n({connected:!0,fallbackMode:!1}))},t.addEventListener(`connected`,()=>{r||(i=0,n({connected:!0,fallbackMode:!1}))}),t.addEventListener(`message.created`,e=>{try{let t=JSON.parse(e.data);t.conversationId&&t.messageId&&typeof t.body==`string`&&(t.direction===`inbound`||t.direction===`outbound`)&&typeof t.timestamp==`string`?l(t):o(),s(t.conversationId)}catch{o()}}),t.addEventListener(`message.status_updated`,e=>{try{let t=JSON.parse(e.data);t.conversationId&&t.messageId&&typeof t.status==`string`&&u(t),s(t.conversationId)}catch{o()}}),t.addEventListener(`message.updated`,e=>{try{let t=JSON.parse(e.data);t.conversationId&&s(t.conversationId)}catch{o()}}),t.addEventListener(`message.deleted`,e=>{try{let t=JSON.parse(e.data);t.conversationId&&(s(t.conversationId),o())}catch{o()}}),t.addEventListener(`conversation.updated`,t=>{o();try{let n=JSON.parse(t.data??`{}`);n?.conversationId&&(e.invalidateQueries({queryKey:[`conversation-details`,n.conversationId]}),e.invalidateQueries({queryKey:[`conversation-participants`,n.conversationId]}))}catch{}}),t.addEventListener(`inbox.refresh`,()=>{o(),e.invalidateQueries({queryKey:[`messages`]}),e.invalidateQueries({queryKey:[`conversation-details`]})}),t.addEventListener(`presence.updated`,e=>{try{let t=JSON.parse(e.data);if(!t.conversationId||!t.participantJid||!t.state)return;let n=CN(t.conversationId,t.participantJid,{state:t.state,lastSeen:t.lastSeen??null});if(t.state===`composing`||t.state===`recording`){let e=t.conversationId,r=t.participantJid;window.setTimeout(()=>{wN(e,r,n)},gN)}}catch{}}),t.addEventListener(`heartbeat`,()=>{}),t.onerror=()=>{if(r)return;t?.close(),t=null,i+=1,n({connected:!1,fallbackMode:i>=EN});let e=Math.min(1e3*2**Math.max(0,i-1),TN);a=window.setTimeout(d,e)})};return d(),()=>{r=!0,a!==null&&(window.clearTimeout(a),a=null),t?.close(),t=null}},[e]),t}var ON=(0,_.createContext)(null);function kN(){let e=(0,_.useContext)(ON);if(!e)throw Error(`useWhatsAppConnection must be used inside WhatsAppConnectionProvider`);return e}var AN={connected:!1,state:`unknown`,groupOpsEnabled:!0,cloudConnected:!1,cloudRoutingActive:!1,leadLineConnected:!1,groupCreateQuota:null};function jN({children:e}){let{data:t}=vi({queryKey:[`whatsapp-status`],queryFn:()=>H(`/api/whatsapp/status`),refetchInterval:15e3,retry:!1}),n=(0,_.useMemo)(()=>
148{if(!t?.data)return AN;let{baileys:e,cloudApi:n,groupOpsEnabled:r,groupCreateQuota:i}=t.data,a=e.status===`connected`,o=n?.state===`connected`,s=n?.routingActive??!1;return{state:e.status,connected:a,groupOpsEnabled:r??!0,cloudConnected:o,cloudRoutingActive:s,leadLineConnected:s?o:a,groupCreateQuota:i??null}},[t]);return(0,L.jsx)(ON.Provider,{value:n,children:e})}function MN(e){let{leadLineConnected:t,baileysConnected:n,leadLineState:r}=e;return t?n?{tone:`none`,message:``}:{tone:`info`,message:`Group messaging is offline - group replies may be delayed. Lead messaging is unaffected.`}:{tone:`critical`,message:`WhatsApp is ${r===`connecting`?`reconnecting...`:`disconnected`}. Messages may be delayed.`}}var NN=0,PN=1,FN=2,IN=4;function LN(e){return()=>e}function RN(e){e()}function zN(e,t){return n=>e(t(n))}function BN(e,t){return()=>e(t)}function VN(e,t){return n=>e(t,n)}function HN(e){return e!==void 0}function UN(...e){return()=>{e.map(RN)}}function WN(){}function GN(e,t){return t(e),e}function KN(e,t){return t(e)}function qN(...e){return e}function JN(e,t){return e(PN,t)}function YN(e,t){e(NN,t)}function XN(e){e(FN)}function ZN(e){return e(IN)}function QN(e,t){return JN(e,VN(t,NN))}function $N(e,t){let n=e(PN,e=>{n(),t(e)});return n}function eP(e){let t,n;return r=>i=>{t=i,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function tP(e,t){return e===t}function nP(e=tP){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function rP(e){return t=>n=>{e(n)&&t(n)}}function iP(e){return t=>zN(t,e)}function aP(e){return t=>()=>{t(e)}}function Q(e,...t){let n=uP(...t);return((t,r)=>{switch(t){case FN:XN(e);return;case PN:return JN(e,n(r))}})}function oP(e,t){return n=>r=>{n(t=e(t,r))}}function sP(e){return t=>n=>{e>0?e--:t(n)}}function cP(e){let t=null,n;return r=>i=>{t=i,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function lP(...e){let t=Array(e.length),n=0,r=null,i=2**e.length-1;return e.forEach((e,a)=>{let o=2**a;JN(e,e=>{let s=n;n|=o,t[a]=e,s!==i&&n===i&&r&&(r(),r=null)})}),e=>a=>{let o=()=>{e([a].concat(t))};n===i?o():r=o}}function uP(...e){return t=>e.reduceRight(KN,t)}function dP(e){let t,n,r=()=>t?.();return function(i,a){switch(i){case PN:return a?n===a?void 0:(r(),n=a,t=JN(e,a),t):(r(),WN);case FN:r(),n=null;return}}}function $(e){let t=e,n=pP();return((e,r)=>{switch(e){case NN:t=r;break;case PN:r(t);break;case IN:return t}return n(e,r)})}function fP(e,t){return GN($(t),t=>QN(e,t))}function pP(){let e=[];return((t,n)=>{switch(t){case NN:e.slice().forEach(e=>{e(n)});return;case FN:e.splice(0,e.length);return;case PN:return e.push(n),()=>{let t=e.indexOf(n);t>-1&&e.splice(t,1)}}})}function mP(e){return GN(pP(),t=>QN(e,t))}function hP(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:gP(),singleton:n}}var gP=()=>Symbol();function _P(e){let t=new Map,n=({constructor:e,dependencies:r,id:i,singleton:a})=>{if(a&&t.has(i))return t.get(i);let o=e(r.map(e=>n(e)));return a&&t.set(i,o),o};return n(e)}function vP(...e){let t=pP(),n=Array(e.length),r=0,i=2**e.length-1;return e.forEach((e,a)=>{let o=2**a;JN(e,e=>{n[a]=e,r|=o,r===i&&YN(t,n)})}),function(e,a){switch(e){case FN:XN(t);return;case PN:return r===i&&a(n),JN(t,a)}}}function yP(e,t=tP){return Q(e,nP(t))}function bP(...e){return function(t,n){switch(t){case FN:return;case PN:return UN(...e.map(e=>JN(e,n)))}}}var xP={DEBUG:0,INFO:1,WARN:2,ERROR:3},SP={[xP.DEBUG]:`debug`,[xP.ERROR]:`error`,[xP.INFO]:`log`,[xP.WARN]:`warn`},CP=()=>typeof globalThis>`u`?window:globalThis,wP=hP(()=>{let e=$(xP.ERROR);return{log:$((t,n,r=xP.INFO)=>{r>=(CP().VIRTUOSO_LOG_LEVEL??ZN(e))&&console[SP[r]](`%creact-virtuoso: %c%s %o`,`color: #0253b3; font-weight: bold`,`color: initial`,t,n)}),logLevel:e}},[],{singleton:!0});function TP(e,t,n){return EP(e,t,n).callbackRef}function EP(e,t,n){let r=_.useRef(null),i=e=>{},a=_.useMemo(()=>typeof ResizeObserver<`u`?new ResizeObserver(t=>{let r=()=>{let n=t[0].target;n.offsetParent!==null&&e(n)};n?r():requestAnimationFrame(r)}):null,[e,n]);return i=e=>{e&&t?(a?.observe(e),r.current=e):(r.current&&a?.unobserve(r.current),r.current=null)},{callbackRef:i,ref:r}}function DP(e,t,n,r,i,a,o,s,c){return EP(_.useCallback(n=>{let c=OP(n.children,t,s?`offsetWidth`:`offsetHeight`,i),l=n.parentElement;for(;l.dataset.virtuosoScroller===void 0;)l=l.parentElement;let u=l.lastElementChild.dataset.viewportType===`window`,d;u&&(d=l.ownerDocument.defaultView);let f=o?s?o.scrollLeft:o.scrollTop:u?s?d.scrollX||d.document.documentElement.scrollLeft:d.scrollY||d.document.documentElement.scrollTop:s?l.scrollLeft:l.scrollTop,p=o?s?o.scrollWidth:o.scrollHeight:u?s?d.document.documentElement.scrollWidth:d.document.documentElement.scrollHeight:s?l.scrollWidth:l.scrollHeight,m=o?s?o.offsetWidth:o.offsetHeight:u?s?d.innerWidth:d.innerHeight:s?l.offsetWidth:l.offsetHeight;
vendor: 55,032 bytes, line 148
148r({scrollHeight:p,scrollTop:Math.max(f,0),viewportHeight:m}),a?.(s?kP(`column-gap`,getComputedStyle(n).columnGap,i):kP(`row-gap`,getComputedStyle(n).rowGap,i)),c!==null&&e(c)},[e,t,i,a,o,r,s]),n,c)}function OP(e,t,n,r){let i=e.length;if(i===0)return null;let a=[];for(let o=0;o<i;o++){let i=e.item(o);if(i.dataset.index===void 0)continue;let s=parseInt(i.dataset.index),c=parseFloat(i.dataset.knownSize),l=t(i,n);if(l===0&&r(`Zero-sized element, this should not happen`,{child:i},xP.ERROR),l===c)continue;let u=a[a.length-1];a.length===0||u.size!==l||u.endIndex!==s-1?a.push({endIndex:s,size:l,startIndex:s}):a[a.length-1].endIndex++}return a}function kP(e,t,n){return t!==`normal`&&t?.endsWith(`px`)!==!0&&n(`${e} was not resolved to pixel value correctly`,t,xP.WARN),t===`normal`?0:parseInt(t??`0`,10)}function AP(e,t,n){let r=_.useRef(null),i=_.useCallback(n=>{if(!n?.offsetParent)return;let i=n.getBoundingClientRect(),a=i.width,s,c;if(t){let e=t.getBoundingClientRect(),n=i.top-e.top;c=e.height-Math.max(0,n),s=n+t.scrollTop}else{let e=o.current.ownerDocument.defaultView;c=e.innerHeight-Math.max(0,i.top),s=i.top+e.scrollY}r.current={listHeight:i.height,offsetTop:s,visibleHeight:c,visibleWidth:a},e(r.current)},[e,t]),{callbackRef:a,ref:o}=EP(i,!0,n),s=_.useCallback(()=>{i(o.current)},[i,o]);return _.useEffect(()=>{if(t){t.addEventListener(`scroll`,s);let e=new ResizeObserver(()=>{requestAnimationFrame(s)});return e.observe(t),()=>{t.removeEventListener(`scroll`,s),e.unobserve(t)}}let e=o.current?.ownerDocument.defaultView;return e?.addEventListener(`scroll`,s),e?.addEventListener(`resize`,s),()=>{e?.removeEventListener(`scroll`,s),e?.removeEventListener(`resize`,s)}},[s,t,o]),a}var jP=hP(()=>{let e=pP(),t=pP(),n=$(0),r=pP(),i=$(0),a=pP(),o=pP(),s=$(0),c=$(0),l=$(0),u=$(0),d=pP(),f=pP(),p=$(!1),m=$(!1),h=$(!1);return QN(Q(e,iP(({scrollTop:e})=>e)),t),QN(Q(e,iP(({scrollHeight:e})=>e)),o),QN(t,i),{deviation:n,fixedFooterHeight:l,fixedHeaderHeight:c,footerHeight:u,headerHeight:s,horizontalDirection:m,scrollBy:f,scrollContainerState:e,scrollHeight:o,scrollingInProgress:p,scrollTo:d,scrollTop:t,skipAnimationFrameInResizeObserver:h,smoothScrollTargetReached:r,statefulScrollTop:i,viewportHeight:a}},[],{singleton:!0}),MP={lvl:0};function NP(e,t){let n=e.length;if(n===0)return[];let{index:r,value:i}=t(e[0]),a=[];for(let o=1;o<n;o++){let{index:n,value:s}=t(e[o]);a.push({end:n-1,start:r,value:i}),r=n,i=s}return a.push({end:1/0,start:r,value:i}),a}function PP(e){return e===MP}function FP(e,t){if(!PP(e))return t===e.k?e.v:t<e.k?FP(e.l,t):FP(e.r,t)}function IP(e,t,n=`k`){if(PP(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){let r=IP(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return IP(e.l,t,n)}function LP(e,t,n){return PP(e)?JP(t,n,1):t===e.k?WP(e,{k:t,v:n}):t<e.k?YP(WP(e,{l:LP(e.l,t,n)})):YP(WP(e,{r:LP(e.r,t,n)}))}function RP(){return MP}function zP(e,t,n){if(PP(e))return[];let r=IP(e,t)[0];return QP(HP(e,r,n))}function BP(e,t){if(PP(e))return MP;let{k:n,l:r,r:i}=e;if(t===n){if(PP(r))return i;if(PP(i))return r;let[t,n]=qP(r);return UP(WP(e,{k:t,l:GP(r),v:n}))}return UP(t<n?WP(e,{l:BP(r,t)}):WP(e,{r:BP(i,t)}))}function VP(e){return PP(e)?[]:[...VP(e.l),{k:e.k,v:e.v},...VP(e.r)]}function HP(e,t,n){if(PP(e))return[];let{k:r,l:i,r:a,v:o}=e,s=[];return r>t&&(s=s.concat(HP(i,t,n))),r>=t&&r<=n&&s.push({k:r,v:o}),r<=n&&(s=s.concat(HP(a,t,n))),s}function UP(e){let{l:t,lvl:n,r}=e;if(r.lvl>=n-1&&t.lvl>=n-1)return e;if(n>r.lvl+1){if(KP(t))return XP(WP(e,{lvl:n-1}));if(!PP(t)&&!PP(t.r))return WP(t.r,{l:WP(t,{r:t.r.l}),lvl:n,r:WP(e,{l:t.r.r,lvl:n-1})});throw Error(`Unexpected empty nodes`)}if(KP(e))return ZP(WP(e,{lvl:n-1}));if(!PP(r)&&!PP(r.l)){let t=r.l,i=KP(t)?r.lvl-1:r.lvl;return WP(t,{l:WP(e,{lvl:n-1,r:t.l}),lvl:t.lvl+1,r:ZP(WP(r,{l:t.r,lvl:i}))})}throw Error(`Unexpected empty nodes`)}function WP(e,t){return JP(t.k===void 0?e.k:t.k,t.v===void 0?e.v:t.v,t.lvl===void 0?e.lvl:t.lvl,t.l===void 0?e.l:t.l,t.r===void 0?e.r:t.r)}function GP(e){return PP(e.r)?e.l:UP(WP(e,{r:GP(e.r)}))}function KP(e){return PP(e)||e.lvl>e.r.lvl}function qP(e){return PP(e.r)?[e.k,e.v]:qP(e.r)}function JP(e,t,n,r=MP,i=MP){return{k:e,l:r,lvl:n,r:i,v:t}}function YP(e){return ZP(XP(e))}function XP(e){let{l:t}=e;return!PP(t)&&t.lvl===e.lvl?WP(t,{r:WP(e,{l:t.r})}):e}function ZP(e){let{lvl:t,r:n}=e;return!PP(n)&&!PP(n.r)&&n.lvl===t&&n.r.lvl===t?WP(n,{l:WP(e,{r:n.l}),lvl:t+1}):e}function QP(e){return NP(e,({k:e,v:t})=>({index:e,value:t}))}function $P(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function eF(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}var tF=hP(()=>({recalcInProgress:$(!1)}),[],{singleton:!0});function nF(e,t,n){return e[rF(e,t,n)]}function rF(e,t,n,r=0){let i=e.length-1;for(;r<=i;){let a=Math.floor((r+i)/2),o=e[a],s=n(o,t);if(s===0)return a;if(s===-1){if(i-r<2)return a-1;i=a-1}else{if(i===r)return a;r=a+1}}throw Error(`Failed binary finding record in array - ${e.join(`,`)}, searched for ${t}`)}function iF(e,t,n,r){let i=rF(e,t,r),a=rF(e,n,r,i);return e.slice(i,a+1)}function aF(e,t){return Math.round(e.getBoundingClientRect()[t])}function oF(e){return!PP(e.groupOffsetTree)}function sF({index:e},t){return t===e?0:t<e?-1:1}function cF(){return{groupIndices:[],groupOffsetTree:RP(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:RP()}}function lF(e,t){let n=PP(e)?0:1/0;for(let r of t){let{endIndex:t,size:i,startIndex:a}=r;if(n=Math.min(n,a),PP(e)){e=LP(e,0,i);continue}let o=zP(e,a-1,t+1);if(o.some(xF(r)))continue;let s=!1,c=!1;for(let{end:n,start:r,value:a}of o)s?(t>=r||i===a)&&(e=BP(e,r)):(c=a!==i,s=!0),n>t&&t>=r&&a!==i&&(e=LP(e,t+1,a));c&&(e=LP(e,a,i))}return[e,n]}function uF(e){return typeof e.groupIndex<`u`}function dF({offset:e},t){return t===e?0:t<e?-1:1}function fF(e,t,n){if(t.length===0)return 0;let{index:r,offset:i,size:a}=nF(t,e,sF),o=e-r,s=a*o+(o-1)*n+i;return s>0?s+n:s}function pF(e,t){if(!oF(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function mF(e,t,n){if(uF(e))return t.groupIndices[e.groupIndex]+1;let r=pF(e.index===`LAST`?n:e.index,t);return r=Math.max(0,r,Math.min(n,r)),r}function hF(e,t,n,r=0){return r>0&&(t=Math.max(t,nF(e,r,sF).offset)),NP(iF(e,t,n,dF),bF)}function gF(e,[t,n,r,i]){t.length>0&&r(`received item sizes`,t,xP.DEBUG);let a=e.sizeTree,o=a,s=0;if(n.length>0&&PP(a)&&t.length===2){let e=t[0].size,r=t[1].size;o=n.reduce((t,n)=>LP(LP(t,n,e),n+1,r),o)}else [o,s]=lF(o,t);if(o===a)return e;let{lastIndex:c,lastOffset:l,lastSize:u,offsetTree:d}=yF(e.offsetTree,s,o,i);return{groupIndices:n,groupOffsetTree:n.reduce((e,t)=>LP(e,t,fF(t,d,i)),RP()),lastIndex:c,lastOffset:l,lastSize:u,offsetTree:d,sizeTree:o}}function _F(e){return VP(e).map(({k:e,v:t},n,r)=>{let i=r[n+1];return{endIndex:i===void 0?1/0:i.k-1,size:t,startIndex:e}})}function vF(e,t){let n=0,r=0;for(;n<e;)n+=t[r+1]-t[r]-1,r++;return r-(n===e?0:1)}function yF(e,t,n,r){let i=e,a=0,o=0,s=0,c=0;if(t!==0){c=rF(i,t-1,sF),s=i[c].offset;let e=IP(n,t-1);a=e[0],o=e[1],i.length&&i[c].size===IP(n,t)[1]&&--c,i=i.slice(0,c+1)}else i=[];for(let{start:e,value:c}of zP(n,t,1/0)){let t=e-a,n=t*o+s+t*r;i.push({index:e,offset:n,size:c}),a=e,s=n,o=c}return{lastIndex:a,lastOffset:s,lastSize:o,offsetTree:i}}function bF(e){return{index:e.index,value:e}}function xF(e){let{endIndex:t,size:n,startIndex:r}=e;return e=>e.start===r&&(e.end===t||e.end===1/0)&&e.value===n}var SF={offsetHeight:`height`,offsetWidth:`width`},CF=hP(([{log:e},{recalcInProgress:t}])=>{let n=pP(),r=pP(),i=fP(r,0),a=pP(),o=pP(),s=$(0),c=$([]),l=$(void 0),u=$(void 0),d=$(void 0),f=$(void 0),p=$((e,t)=>aF(e,SF[t])),m=$(void 0),h=$(0),g=cF(),_=fP(Q(n,lP(c,e,h),oP(gF,g),nP()),g),v=fP(Q(c,nP(),oP((e,t)=>({current:t,prev:e.current}),{current:[],prev:[]}),iP(({prev:e})=>e)),[]);QN(Q(c,rP(e=>e.length>0),lP(_,h),iP(([e,t,n])=>{let r=e.reduce((e,r,i)=>LP(e,r,fF(r,t.offsetTree,n)||i),RP());return{...t,groupIndices:e,groupOffsetTree:r}})),_),QN(Q(r,lP(_),rP(([e,{lastIndex:t}])=>e<t),iP(([e,{lastIndex:t,lastSize:n}])=>[{endIndex:t,size:n,startIndex:e}])),n),QN(l,u);let y=fP(Q(l,iP(e=>e===void 0)),!0);QN(Q(u,rP(e=>e!==void 0&&PP(ZN(_).sizeTree)),iP(e=>{let t=ZN(d),n=ZN(c).length>0;return t!==void 0&&t!==0?n?[{endIndex:0,size:t,startIndex:0},{endIndex:1,size:e,startIndex:1}]:[]:[{endIndex:0,size:e,startIndex:0}]})),n),QN(Q(f,rP(e=>e!==void 0&&e.length>0&&PP(ZN(_).sizeTree)),iP(e=>{let t=[],n=e[0],r=0;for(let i=1;i<e.length;i++){let a=e[i];a!==n&&(t.push({endIndex:i-1,size:n,startIndex:r}),n=a,r=i)}return t.push({endIndex:e.length-1,size:n,startIndex:r}),t})),n),QN(Q(c,lP(d,u),rP(([,e,t])=>e!==void 0&&t!==void 0),iP(([e,t,n])=>{let r=[];for(let i=0;i<e.length;i++){let a=e[i],o=e[i+1];r.push({startIndex:a,endIndex:a,size:t}),o!==void 0&&r.push({startIndex:a+1,endIndex:o-1,size:n})}return r})),n);let b=mP(Q(n,lP(_),oP(({sizes:e},[t,n])=>({changed:n!==e,sizes:n}),{changed:!1,sizes:g}),iP(e=>e.changed)));JN(Q(s,oP((e,t)=>({diff:e.prev-t,prev:t}),{diff:0,prev:0}),iP(e=>e.diff)),e=>{let{groupIndices:n}=ZN(_);if(e>0)YN(t,!0),YN(a,e+vF(e,n));else if(e<0){let t=ZN(v);t.length>0&&(e-=vF(-e,t)),YN(o,e)}}),JN(Q(s,lP(e)),([e,t])=>{e<0&&t("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:s},xP.ERROR)});let x=mP(a);QN(Q(a,lP(_),iP(([e,t])=>{let n=t.groupIndices.length>0,r=[],i=t.lastSize;if(n){let n=FP(t.sizeTree,0),a=0,o=0;for(;a<e;){let e=t.groupIndices[o],s=t.groupIndices.length===o+1?1/0:t.groupIndices[o+1]-e-1;r.push({endIndex:e,size:n,startIndex:e}),r.push({endIndex:e+1+s-1,size:i,startIndex:e+1}),o++,a+=s+1}let s=VP(t.sizeTree);return a!==e&&s.shift(),s.reduce((t,{k:n,v:r})=>{let i=t.ranges;return t.prevSize!==0&&(i=[...t.ranges,{endIndex:n+e-1,size:t.prevSize,startIndex:t.prevIndex}]),{prevIndex:n+e,prevSize:r,ranges:i}},{prevIndex:e,prevSize:0,ranges:r}).ranges}return VP(t.sizeTree).reduce((t,{k:n,v:r})=>({prevIndex:n+e,prevSize:r,ranges:[...t.ranges,{endIndex:n+e-1,size:t.prevSize,startIndex:t.prevIndex}]}),{prevIndex:0,prevSize:i,ranges:[]}).ranges})),n);let S=mP(Q(o,lP(_,h),iP(([e,{offsetTree:t},n])=>fF(-e,t,n))));return QN(Q(o,lP(_,h),iP(([e,t,n])=>{if(t.groupIndices.length>0){if(PP(t.sizeTree))return t;let r=RP(),i=ZN(v),a=0,o=0,s=0;for(;a<-e;){s=i[o];let e=i[o+1]-s-1;o++,a+=e+1}if(r=VP(t.sizeTree).reduce((t,{k:n,v:r})=>LP(t,Math.max(0,n+e),r),r),a!==-e){let n=FP(t.sizeTree,s);r=LP(r,0,n);let i=IP(t.sizeTree,-e+1)[1];r=LP(r,1,i)}return{...t,sizeTree:r,...yF(t.offsetTree,0,r,n)}}let r=VP(t.sizeTree).reduce((t,{k:n,v:r})=>LP(t,Math.max(0,n+e),r),RP());return{...t,sizeTree:r,...yF(t.offsetTree,0,r,n)}})),_),{beforeUnshiftWith:x,data:m,defaultItemSize:u,firstItemIndex:s,fixedItemSize:l,fixedGroupSize:d,gap:h,groupIndices:c,heightEstimates:f,itemSize:p,listRefresh:b,shiftWith:o,shiftWithOffset:S,sizeRanges:n,sizes:_,statefulTotalCount:i,totalCount:r,trackItemSizes:y,unshiftWith:a}},qN(wP,tF),{singleton:!0});function wF(e){return e.reduce((e,t)=>(e.groupIndices.push(e.totalCount),e.totalCount+=t+1,e),{groupIndices:[],totalCount:0})}var TF=hP(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:i}])=>{let a=pP(),o=pP(),s=mP(Q(a,iP(wF)));return QN(Q(s,iP(e=>e.totalCount)),n),QN(Q(s,iP(e=>e.groupIndices)),e),QN(Q(vP(i,t,r),rP(([e,t])=>oF(t)),iP(([e,t,n])=>IP(t.groupOffsetTree,Math.max(e-n,0),`v`)[0]),nP(),iP(e=>[e])),o),{groupCounts:a,topItemsIndexes:o}},qN(CF,jP)),EF=hP(([{log:e}])=>{let t=$(!1),n=mP(Q(t,rP(e=>e),nP()));return JN(t,t=>{t&&ZN(e)(`props updated`,{},xP.DEBUG)}),{didMount:n,propsReady:t}},qN(wP),{singleton:!0}),DF=typeof document<`u`&&`scrollBehavior`in document.documentElement.style;function OF(e){let t=typeof e==`number`?{index:e}:e;return t.align||=`start`,(!t.behavior||!DF)&&(t.behavior=`auto`),t.offset===void 0&&(t.offset=0),t}var kF=hP(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:i,fixedHeaderHeight:a,footerHeight:o,headerHeight:s,scrollingInProgress:c,scrollTo:l,smoothScrollTargetReached:u,viewportHeight:d},{log:f}])=>{let p=pP(),m=pP(),h=$(0),g=null,_=null,v=null;function y(){g!==null&&(g(),g=null),v!==null&&(v(),v=null),_&&=(clearTimeout(_),null),YN(c,!1)}return QN(Q(p,lP(n,d,r,h,s,o,f),lP(e,a,i),iP(([[e,n,r,i,a,o,s,l],d,f,h])=>{let b=OF(e),{align:x,behavior:S,offset:C}=b,w=i-1,T=mF(b,n,w),E=fF(T,n.offsetTree,d)+o;x===`end`?(E+=f+IP(n.sizeTree,T)[1]-r+h,T===w&&(E+=s)):x===`center`?E+=(f+IP(n.sizeTree,T)[1]-r+h)/2:E-=a,C!==void 0&&C!==0&&(E+=C);let D=t=>{y(),t?(l(`retrying to scroll to`,{location:e},xP.DEBUG),YN(p,e)):(YN(m,!0),l(`list did not change, scroll successful`,{},xP.DEBUG))};if(y(),S===`smooth`){let e=!1;v=JN(t,t=>{e||=t}),g=$N(u,()=>{D(e)})}else g=$N(Q(t,AF(150)),D);return _=setTimeout(()=>{y()},1200),YN(c,!0),l(`scrolling from index to`,{behavior:S,index:T,top:E},xP.DEBUG),{behavior:S,top:E}})),l),{scrollTargetReached:m,scrollToIndex:p,topListHeight:h}},qN(CF,jP,wP),{singleton:!0});function AF(e){return t=>{let n=setTimeout(()=>{t(!1)},e);return e=>{e&&(t(!0),clearTimeout(n))}}}function jF(e,t){e===0?t():requestAnimationFrame(()=>{jF(e-1,t)})}function MF(e,t){let n=t-1;return typeof e==`number`?e:e.index===`LAST`?n:e.index}var NF=hP(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:i,scrollToIndex:a},{didMount:o}])=>{let s=$(!0),c=$(0),l=$(!0);return QN(Q(o,lP(c),rP(([e,t])=>t!==0),aP(!1)),s),QN(Q(o,lP(c),rP(([e,t])=>t!==0),aP(!1)),l),JN(Q(vP(t,o),lP(s,n,e,l),rP(([[,e],t,{sizeTree:n},r,i])=>e&&(!PP(n)||HN(r))&&!t&&!i),lP(c)),([,e])=>{$N(i,()=>{YN(l,!0)}),jF(4,()=>{$N(r,()=>{YN(s,!0)}),YN(a,e)})}),{initialItemFinalLocationReached:l,initialTopMostItemIndex:c,scrolledToInitialItem:s}},qN(CF,jP,kF,EF),{singleton:!0});function PF(e,t){return Math.abs(e-t)<1.01}var FF=`up`,IF=`down`,LF=`none`,RF={atBottom:!1,notAtBottomBecause:`NOT_SHOWING_LAST_ITEM`,state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},zF=0,BF=hP(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:i,viewportHeight:a}])=>{let o=$(!1),s=$(!0),c=pP(),l=pP(),u=$(4),d=$(zF),f=fP(Q(bP(Q(yP(i),sP(1),aP(!0)),Q(yP(i),sP(1),aP(!1),eP(100))),nP()),!1),p=fP(Q(bP(Q(n,aP(!0)),Q(n,aP(!1),eP(200))),nP()),!1);QN(Q(vP(yP(i),yP(d)),iP(([e,t])=>e<=t),nP()),s),QN(Q(s,cP(50)),l);let m=mP(Q(vP(r,yP(a),yP(t),yP(e),yP(u)),oP((e,[{scrollHeight:t,scrollTop:n},r,i,a,o])=>{let s=n+r-t>-o,c={scrollHeight:t,scrollTop:n,viewportHeight:r};if(s){let t,r;return n>e.state.scrollTop?(t=`SCROLLED_DOWN`,r=e.state.scrollTop-n):(t=`SIZE_DECREASED`,r=e.state.scrollTop-n||e.scrollTopDelta),{atBottom:!0,atBottomBecause:t,scrollTopDelta:r,state:c}}let l;return l=c.scrollHeight>e.state.scrollHeight?`SIZE_INCREASED`:r<e.state.viewportHeight?`VIEWPORT_HEIGHT_DECREASING`:n<e.state.scrollTop?`SCROLLING_UPWARDS`:`NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM`,{atBottom:!1,notAtBottomBecause:l,state:c}},RF),nP((e,t)=>e!==void 0&&e.atBottom===t.atBottom))),h=fP(Q(r,oP((e,{scrollHeight:t,scrollTop:n,viewportHeight:r})=>{if(!PF(e.scrollHeight,t)){let i=t-(n+r)<1;return e.scrollTop!==n&&i?{changed:!0,jump:e.scrollTop-n,scrollHeight:t,scrollTop:n}:{changed:!0,jump:0,scrollHeight:t,scrollTop:n}}return{changed:!1,jump:0,scrollHeight:t,scrollTop:n}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),rP(e=>e.changed),iP(e=>e.jump)),0);QN(Q(m,iP(e=>e.atBottom)),o),QN(Q(o,cP(50)),c);let g=$(IF);QN(Q(r,iP(({scrollTop:e})=>e),nP(),oP((e,t)=>ZN(p)?{direction:e.direction,prevScrollTop:t}:{direction:t<e.prevScrollTop?FF:IF,prevScrollTop:t},{direction:IF,prevScrollTop:0}),iP(e=>e.direction)),g),QN(Q(r,cP(50),aP(LF)),g);let _=$(0);return QN(Q(f,rP(e=>!e),aP(0)),_),QN(Q(i,cP(100),lP(f),rP(([e,t])=>t),oP(([e,t],[n])=>[t,n],[0,0]),iP(([e,t])=>t-e)),_),{atBottomState:m,atBottomStateChange:c,atBottomThreshold:u,atTopStateChange:l,atTopThreshold:d,isAtBottom:o,isAtTop:s,isScrolling:f,lastJumpDueToItemResize:h,scrollDirection:g,scrollVelocity:_}},qN(jP)),VF=`top`,HF=`bottom`,UF=`none`;function WF(e,t,n){return typeof e==`number`?n===FF&&t===VF||n===IF&&t===HF?e:0:n===FF?t===VF?e.main:e.reverse:t===HF?e.main:e.reverse}function GF(e,t){return typeof e==`number`?e:e[t]??0}var KF=hP(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:i}])=>{let a=pP(),o=$(0),s=$(0),c=$(0);return{increaseViewportBy:s,listBoundary:a,overscan:c,topListHeight:o,visibleRange:fP(Q(vP(yP(r),yP(i),yP(n),yP(a,eF),yP(c),yP(o),yP(t),yP(e),yP(s)),iP(([e,t,n,[r,i],a,o,s,c,l])=>{let u=e-c,d=o+s,f=Math.max(n-u,0),p=UF,m=GF(l,VF),h=GF(l,HF);return r-=c,r+=n+s,i+=n+s,i-=c,r>e+d-m&&(p=FF),i<e-f+t+h&&(p=IF),p===UF?null:[Math.max(u-n-WF(a,VF,p)-m,0),u-f-s+t+WF(a,HF,p)+h]}),rP(e=>e!==null),nP(eF)),[0,0])}},qN(jP),{singleton:!0});function qF(e,t,n){if(oF(t)){let r=pF(e,t);return[{index:IP(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n?.[0],index:r,offset:0,size:0}]}return[{data:n?.[0],index:e,offset:0,size:0}]}var JF={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function YF(e,t,n,r,i,a){let{lastIndex:o,lastOffset:s,lastSize:c}=i,l=0,u=0;if(e.length>0){l=e[0].offset;let t=e[e.length-1];u=t.offset+t.size}let d=n-o,f=s+d*c+(d-1)*r,p=l,m=f-u;return{bottom:u,firstItemIndex:a,items:ZF(e,i,a),offsetBottom:m,offsetTop:l,top:p,topItems:ZF(t,i,a),topListHeight:t.reduce((e,t)=>t.size+e,0),totalCount:n}}function XF(e,t,n,r,i,a){let o=0;if(n.groupIndices.length>0)for(let t of n.groupIndices){if(t-o>=e)break;o++}let s=e+o,c=MF(t,s);return YF(Array.from({length:s}).map((e,t)=>({data:a[t+c],index:t+c,offset:0,size:0})),[],s,i,n,r)}function ZF(e,t,n){if(e.length===0)return[];if(!oF(t))return e.map(e=>({...e,index:e.index+n,originalIndex:e.index}));let r=e[0].index,i=e[e.length-1].index,a=[],o=zP(t.groupOffsetTree,r,i),s,c=0;for(let r of e){(!s||s.end<r.index)&&(s=o.shift(),c=t.groupIndices.indexOf(s.start));let e;e=r.index===s.start?{index:c,type:`group`}:{groupIndex:c,index:r.index-(c+1)+n},a.push({...e,data:r.data,offset:r.offset,originalIndex:r.index,size:r.size})}return a}function QF(e,t){return e===void 0?0:typeof e==`number`?e:e[t]??0}var $F=hP(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:i},a,{listBoundary:o,topListHeight:s,visibleRange:c},{initialTopMostItemIndex:l,scrolledToInitialItem:u},{topListHeight:d},f,{didMount:p},{recalcInProgress:m}])=>{let h=$([]),g=$(0),_=pP(),v=$(0);QN(a.topItemsIndexes,h);let y=fP(Q(vP(p,m,yP(c,eF),yP(i),yP(r),yP(l),u,yP(h),yP(t),yP(n),yP(v),e),rP(([e,t,,n,,,,,,,,r])=>{let i=r!==void 0&&r.length!==n;return e&&!t&&!i}),iP(([,,[e,t],n,r,i,a,o,s,c,l,u])=>{let d=r,{offsetTree:f,sizeTree:p}=d,m=ZN(g);if(n===0)return{...JF,totalCount:n};if(e===0&&t===0)return m===0?{...JF,totalCount:n}:XF(m,i,r,s,c,u||[]);if(PP(p))return m>0?null:YF(qF(MF(i,n),d,u),[],n,c,d,s);let h=[];if(o.length>0){let e=o[0],t=o[o.length-1],n=0;for(let r of zP(p,e,t)){let i=r.value,a=Math.max(r.start,e),o=Math.min(r.end,t);for(let e=a;e<=o;e++)h.push({data:u?.[e],index:e,offset:n,size:i}),n+=i}}if(!a)return YF([],h,n,c,d,s);let _=o.length>0?o[o.length-1]+1:0,v=hF(f,e,t,_);if(v.length===0)return null;let y=n-1,b=GN([],n=>{for(let r of v){let i=r.value,a=i.offset,o=r.start,s=i.size;if(i.offset<e){o+=Math.floor((e-i.offset+c)/(s+c));let t=o-r.start;a+=t*s+t*c}o<_&&(a+=(_-o)*s,o=_);let l=Math.min(r.end,y);for(let e=o;e<=l&&!(a>=t);e++)n.push({data:u?.[e],index:e,offset:a,size:s}),a+=s+c}}),x=QF(l,VF),S=QF(l,HF);if(b.length>0&&(x>0||S>0)){let e=b[0],t=b[b.length-1];if(x>0&&e.index>_){let t=Math.min(x,e.index-_),n=[],r=e.offset;for(let i=e.index-1;i>=e.index-t;i--){let t=zP(p,i,i)[0]?.value??e.size;r-=t+c,n.unshift({data:u?.[i],index:i,offset:r,size:t})}b.unshift(...n)}if(S>0&&t.index<y){let e=Math.min(S,y-t.index),n=t.offset+t.size+c;for(let r=t.index+1;r<=t.index+e;r++){let e=zP(p,r,r)[0]?.value??t.size;b.push({data:u?.[r],index:r,offset:n,size:e}),n+=e+c}}}return YF(b,h,n,c,d,s)}),rP(e=>e!==null),nP()),JF);QN(Q(e,rP(HN),iP(e=>e?.length)),i),QN(Q(y,iP(e=>e.topListHeight)),d),QN(d,s),QN(Q(y,iP(e=>[e.top,e.bottom])),o),QN(Q(y,iP(e=>e.items)),_);let b=mP(Q(y,rP(({items:e})=>e.length>0),lP(i,e),rP(([{items:e},t])=>e[e.length-1].originalIndex===t-1),iP(([,e,t])=>[e-1,t]),nP(eF),iP(([e])=>e))),x=mP(Q(y,cP(200),rP(({items:e,topItems:t})=>e.length>0&&e[0].originalIndex===t.length),iP(({items:e})=>e[0].index),nP()));return{endReached:b,initialItemCount:g,itemsRendered:_,listState:y,minOverscanItemCount:v,rangeChanged:mP(Q(y,rP(({items:e})=>e.length>0),iP(({items:e})=>{let t=0,n=e.length-1;for(;e[t].type===`group`&&t<n;)t++;for(;e[n].type===`group`&&n>t;)n--;return{endIndex:e[n].index,startIndex:e[t].index}}),nP($P))),startReached:x,topItemsIndexes:h,...f}},qN(CF,TF,KF,NF,kF,BF,EF,tF),{singleton:!0}),eI=hP(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:i}])=>{let a=pP(),o=fP(Q(vP(n,e,r,t,i),iP(([e,t,n,r,i])=>e+t+n+r+i.offsetBottom+i.bottom)),0);return QN(yP(o),a),{totalListHeight:o,totalListHeightChanged:a}},qN(jP,$F),{singleton:!0}),tI=hP(([{viewportHeight:e},{totalListHeight:t}])=>{let n=$(!1);return{alignToBottom:n,paddingTopAddition:fP(Q(vP(n,e,t),rP(([e])=>e),iP(([,e,t])=>Math.max(0,e-t)),cP(0),nP()),0)}},qN(jP,eI),{singleton:!0}),nI=hP(()=>({context:$(null)})),rI=({itemBottom:e,itemTop:t,locationParams:{align:n,behavior:r,...i},viewportBottom:a,viewportTop:o})=>t<o?{...i,align:n??`start`,...r===void 0?{}:{behavior:r}}:e>a?{...i,align:n??`end`,...r===void 0?{}:{behavior:r}}:null,iI=hP(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:i,headerHeight:a,scrollingInProgress:o,scrollTop:s,viewportHeight:c},{scrollToIndex:l}])=>{let u=pP();return QN(Q(u,lP(t,c,n,a,i,r,s),lP(e),iP(([[e,t,n,r,i,a,s,c],l])=>{let{calculateViewLocation:u=rI,done:d,...f}=e,p=mF(e,t,r-1),m=fF(p,t.offsetTree,l)+i+a,h=m+IP(t.sizeTree,p)[1],g=c+a,_=u({itemBottom:h,itemTop:m,locationParams:f,viewportBottom:c+n-s,viewportTop:g});return _===null?d?.():d&&$N(Q(o,rP(e=>!e),sP(ZN(o)?1:2)),d),_}),rP(e=>e!==null)),l),{scrollIntoView:u}},qN(CF,jP,kF,$F,wP),{singleton:!0});function aI(e){return e===!1?!1:e===`smooth`?`smooth`:`auto`}var oI=(e,t)=>typeof e==`function`?aI(e(t)):t&&aI(e),sI=hP(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:i,isAtBottom:a},{scrollToIndex:o},{scrolledToInitialItem:s},{didMount:c,propsReady:l},{log:u},{scrollingInProgress:d},{context:f},{scrollIntoView:p}])=>{let m=$(!1),h=pP(),g=null;function _(e){YN(o,{align:`end`,behavior:e,index:`LAST`})}JN(Q(vP(Q(yP(t),sP(1)),c),lP(yP(m),a,s,d),iP(([[e,t],n,r,i,a])=>{let o=t&&i,s=`auto`;return o&&(s=oI(n,r||a),o&&=s!==!1),{followOutputBehavior:s,shouldFollow:o,totalCount:e}}),rP(({shouldFollow:e})=>e)),({followOutputBehavior:t,totalCount:r})=>{g!==null&&(g(),g=null),ZN(n)===void 0?g=$N(e,()=>{ZN(u)(`following output to `,{totalCount:r},xP.DEBUG),_(t),g=null}):requestAnimationFrame(()=>{ZN(u)(`following output to `,{totalCount:r},xP.DEBUG),_(t)})});function v(e){let t=$N(i,t=>{e&&!t.atBottom&&t.notAtBottomBecause===`SIZE_INCREASED`&&g===null&&(ZN(u)(`scrolling to bottom due to increased size`,{},xP.DEBUG),_(`auto`))});setTimeout(t,100)}JN(Q(vP(yP(m),t,l),rP(([e,,t])=>e!==!1&&t),oP(({value:e},[,t])=>({refreshed:e===t,value:t}),{refreshed:!1,value:0}),rP(({refreshed:e})=>e),lP(m,t)),([,e])=>{ZN(s)&&v(e!==!1)}),JN(h,()=>{v(ZN(m)!==!1)}),JN(vP(yP(m),i),([e,t])=>{e!==!1&&!t.atBottom&&t.notAtBottomBecause===`VIEWPORT_HEIGHT_DECREASING`&&_(`auto`)});let y=$(null),b=pP();return QN(bP(Q(yP(r),iP(e=>e?.length??0)),Q(yP(t))),b),JN(Q(vP(Q(b,sP(1)),c),lP(yP(y),s,d,f),iP(([[e,t],n,r,i,a])=>t&&r&&n?.({context:a,totalCount:e,scrollingInProgress:i})),rP(e=>!!e),cP(0)),t=>{g!==null&&(g(),g=null),ZN(n)===void 0?g=$N(e,()=>{ZN(u)(`scrolling into view`,{}),YN(p,t),g=null}):requestAnimationFrame(()=>{ZN(u)(`scrolling into view`,{}),YN(p,t)})}),{autoscrollToBottom:h,followOutput:m,scrollIntoViewOnChange:y}},qN(CF,BF,kF,NF,EF,wP,jP,nI,iI)),cI=hP(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:i},{initialItemCount:a,listState:o},{didMount:s}])=>(QN(Q(s,lP(a),rP(([,e])=>e!==0),lP(i,r,t,n,e),iP(([[,e],t,n,r,i,a=[]])=>XF(e,t,n,r,i,a))),o),{}),qN(CF,NF,$F,EF),{singleton:!0}),lI=hP(([{didMount:e},{scrollTo:t},{listState:n}])=>{let r=$(0);return JN(Q(e,lP(r),rP(([,e])=>e!==0),iP(([,e])=>({top:e}))),e=>{$N(Q(n,sP(1),rP(e=>e.items.length>1)),()=>{requestAnimationFrame(()=>{YN(t,e)})})}),{initialScrollTop:r}},qN(EF,jP,$F),{singleton:!0}),uI=hP(([{scrollVelocity:e}])=>{let t=$(!1),n=pP(),r=$(!1);return QN(Q(e,lP(r,t,n),rP(([e,t])=>t!==!1&&t!==void 0),iP(([e,t,n,r])=>{let{enter:i,exit:a}=t;if(n){if(a(e,r))return!1}else if(i(e,r))return!0;return n}),nP()),t),JN(Q(vP(t,e,n),lP(r)),([[e,t,n],r])=>{e&&r!==!1&&r!==void 0&&r.change&&r.change(t,n)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},qN(BF),{singleton:!0}),dI=hP(([{scrollContainerState:e,scrollTo:t}])=>{let n=pP(),r=pP(),i=pP(),a=$(!1),o=$(void 0);return QN(Q(vP(n,r),iP(([{scrollTop:e,viewportHeight:t},{offsetTop:n,listHeight:r}])=>({scrollHeight:r,scrollTop:Math.max(0,e-n),viewportHeight:t}))),e),QN(Q(t,lP(r),iP(([e,{offsetTop:t}])=>({...e,top:e.top+t}))),i),{customScrollParent:o,useWindowScroll:a,windowScrollContainerState:n,windowScrollTo:i,windowViewportRect:r}},qN(jP)),fI=hP(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:i},{didMount:a},{useWindowScroll:o,windowScrollContainerState:s,windowViewportRect:c}])=>{let l=pP(),u=$(void 0),d=$(null),f=$(null);return QN(s,d),QN(c,f),JN(Q(l,lP(t,r,o,d,f,n)),([e,t,n,r,i,a,o])=>{let s=_F(t.sizeTree);r&&i!==null&&a!==null&&(n=i.scrollTop-a.offsetTop),n-=o,e({ranges:s,scrollTop:n})}),QN(Q(u,rP(HN),iP(pI)),i),QN(Q(a,lP(u),rP(([,e])=>e!==void 0),nP(),iP(([,e])=>e.ranges)),e),{getState:l,restoreStateFrom:u}},qN(CF,jP,NF,EF,dI));function pI(e){return{align:`start`,index:0,offset:e.scrollTop}}var mI=hP(([{topItemsIndexes:e}])=>{let t=$(0);return QN(Q(t,rP(e=>e>=0),iP(e=>Array.from({length:e}).map((e,t)=>t))),e),{topItemCount:t}},qN($F));function hI(e){let t=!1,n;return(()=>(t||(t=!0,n=e()),n))}var gI=hI(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),_I=hP(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,fixedGroupSize:i,gap:a,groupIndices:o,heightEstimates:s,itemSize:c,sizeRanges:l,sizes:u,statefulTotalCount:d,totalCount:f,trackItemSizes:p},{initialItemFinalLocationReached:m,initialTopMostItemIndex:h,scrolledToInitialItem:g},_,v,y,b,{scrollToIndex:x},S,{topItemCount:C},{groupCounts:w},T])=>{let{listState:E,minOverscanItemCount:D,topItemsIndexes:O,rangeChanged:k,...A}=b;return QN(k,T.scrollSeekRangeChanged),QN(Q(T.windowViewportRect,iP(e=>e.visibleHeight)),_.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,fixedGroupHeight:i,gap:a,groupCounts:w,heightEstimates:s,initialItemFinalLocationReached:m,initialTopMostItemIndex:h,scrolledToInitialItem:g,sizeRanges:l,topItemCount:C,topItemsIndexes:O,totalCount:f,...y,groupIndices:o,itemSize:c,listState:E,minOverscanItemCount:D,scrollToIndex:x,statefulTotalCount:d,trackItemSizes:p,rangeChanged:k,...A,...T,..._,sizes:u,...v}},qN(CF,NF,jP,fI,sI,$F,kF,hP(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:i,isScrolling:a,lastJumpDueToItemResize:o,scrollDirection:s},{listState:c},{beforeUnshiftWith:l,gap:u,shiftWithOffset:d,sizes:f},{log:p},{recalcInProgress:m}])=>{let h=mP(Q(c,lP(o),oP(([,e,t,n],[{bottom:r,items:i,offsetBottom:a,totalCount:o},s])=>{let c=r+a,l=0;return t===o&&e.length>0&&i.length>0&&(i[0].originalIndex===0&&e[0].originalIndex===0||(l=c-n,l!==0&&(l+=s))),[l,i,o,c]},[0,[],0,0]),rP(([e])=>e!==0),lP(r,s,n,i,p,m),rP(([,e,t,n,,,r])=>!r&&!n&&e!==0&&t===FF),iP(([[e],,,,,t])=>(t(`Upward scrolling compensation`,{amount:e},xP.DEBUG),e))));function g(n){n>0?(YN(t,{behavior:`auto`,top:-n}),YN(e,0)):(YN(e,0),YN(t,{behavior:`auto`,top:-n}))}return JN(Q(h,lP(e,a)),([t,n,r])=>{r&&gI()?YN(e,n-t):g(-t)}),JN(Q(vP(fP(a,!1),e,m),rP(([e,t,n])=>!e&&!n&&t!==0),iP(([e,t])=>t),cP(1)),g),QN(Q(d,iP(e=>({top:-e}))),t),JN(Q(l,lP(f,u),iP(([e,{groupIndices:t,lastSize:n,sizeTree:r},i])=>{function a(e){return e*(n+i)}if(t.length===0)return a(e);let o=0,s=FP(r,0),c=0,l=0;for(;c<e;){c++,o+=s;let n=t.length===l+1?1/0:t[l+1]-t[l]-1;c+n>e&&(o-=s,n=e-c+1),c+=n,o+=a(n),l++}return o})),n=>{YN(e,n),requestAnimationFrame(()=>{YN(t,{top:n}),requestAnimationFrame(()=>{YN(e,0),YN(m,!1)})})}),{deviation:e}},qN(jP,BF,$F,CF,wP,tF)),mI,TF,hP(([e,t,n,r,i,a,o,s,c,l,u])=>({...e,...t,...n,...r,...i,...a,...o,...s,...c,...l,...u}),qN(KF,cI,EF,uI,eI,lI,tI,dI,iI,wP,nI))));function vI(e,t){let n={},r={},i=0,a=e.length;for(;i<a;)r[e[i]]=1,i+=1;for(let e in t)Object.hasOwn(r,e)||(n[e]=t[e]);return n}var yI=typeof document<`u`?_.useLayoutEffect:_.useEffect;function bI(e,t,n){let r=Object.keys(t.required||{}),i=Object.keys(t.optional||{}),a=Object.keys(t.methods||{}),o=Object.keys(t.events||{}),s=_.createContext({});function c(e,n){e.propsReady!==void 0&&YN(e.propsReady,!1);for(let i of r){let r=e[t.required[i]];YN(r,n[i])}for(let r of i)if(r in n){let i=e[t.optional[r]];YN(i,n[r])}e.propsReady!==void 0&&YN(e.propsReady,!0)}function l(e){return a.reduce((n,r)=>(n[r]=n=>{let i=e[t.methods[r]];YN(i,n)},n),{})}function u(e){return o.reduce((n,r)=>(n[r]=dP(e[t.events[r]]),n),{})}return{Component:_.forwardRef(function(t,a){let{children:d,...f}=t,[p]=_.useState(()=>GN(_P(e),e=>{c(e,f)})),[m]=_.useState(BN(u,p));yI(()=>{for(let e of o)e in f&&JN(m[e],f[e]);return()=>{Object.values(m).map(XN)}},[f,m,p]),yI(()=>{c(p,f)}),_.useImperativeHandle(a,LN(l(p)));let h=n;return(0,L.jsx)(s.Provider,{value:p,children:n===void 0?d:(0,L.jsx)(h,{...vI([...r,...i,...o],f),children:d})})}),useEmitter:(e,t)=>{let n=_.useContext(s)[e];yI(()=>JN(n,t),[t,n])},useEmitterValue:e=>{let t=_.useContext(s)[e],n=_.useCallback(e=>JN(t,e),[t]);return _.useSyncExternalStore(n,()=>ZN(t),()=>ZN(t))},usePublisher:e=>{let t=_.useContext(s);return _.useCallback(n=>{YN(t[e],n)},[t,e])}}}var xI=_.createContext(void 0),SI=_.createContext(void 0),CI=`-webkit-sticky`,wI=`sticky`,TI=hI(()=>{if(typeof document>`u`)return wI;let e=document.createElement(`div`);return e.style.position=CI,e.style.position===CI?CI:wI}),EI=typeof document<`u`?_.useLayoutEffect:_.useEffect;function DI(e){return`self`in e}function OI(e){return`body`in e}function kI(e,t,n,r=WN,i,a){let o=_.useRef(null),s=_.useRef(null),c=_.useRef(null),l=_.useCallback(n=>{let r,i,o,l=n.target;if(OI(l)||DI(l)){let e=DI(l)?l:l.defaultView;o=a===!0?e.scrollX:e.scrollY,r=a===!0?e.document.documentElement.scrollWidth:e.document.documentElement.scrollHeight,i=a===!0?e.innerWidth:e.innerHeight}else o=a===!0?l.scrollLeft:l.scrollTop,r=a===!0?l.scrollWidth:l.scrollHeight,i=a===!0?l.offsetWidth:l.offsetHeight;let u=()=>{e({scrollHeight:r,scrollTop:Math.max(o,0),viewportHeight:i})};n.suppressFlushSync===!0?u():v.flushSync(u),s.current!==null&&(o===s.current||o<=0||o===r-i)&&(s.current=null,t(!0),c.current&&=(clearTimeout(c.current),null))},[e,t,a]);_.useEffect(()=>{let e=i||o.current;return r(i||o.current),l({suppressFlushSync:!0,target:e}),e.addEventListener(`scroll`,l,{passive:!0}),()=>{r(null),e.removeEventListener(`scroll`,l)}},[o,l,n,r,i]);function u(n){let r=o.current;if(!r||(a===!0?`offsetWidth`in r&&r.offsetWidth===0:`offsetHeight`in r&&r.offsetHeight===0))return;let i=n.behavior===`smooth`,l,u,d;DI(r)?(u=Math.max(aF(r.document.documentElement,a===!0?`width`:`height`),a===!0?r.document.documentElement.scrollWidth:r.document.documentElement.scrollHeight),l=a===!0?r.innerWidth:r.innerHeight,d=a===!0?window.scrollX:window.scrollY):(u=r[a===!0?`scrollWidth`:`scrollHeight`],l=aF(r,a===!0?`width`:`height`),d=r[a===!0?`scrollLeft`:`scrollTop`]);let f=u-l;if(n.top=Math.ceil(Math.max(Math.min(f,n.top),0)),PF(l,u)||n.top===d){e({scrollHeight:u,scrollTop:d,viewportHeight:l}),i&&t(!0);return}i?(s.current=n.top,c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{c.current=null,s.current=null,t(!0)},1e3)):s.current=null,a===!0&&(n={...n.behavior===void 0?{}:{behavior:n.behavior},left:n.top}),r.scrollTo(n)}function d(e){a===!0&&(e={...e.behavior===void 0?{}:{behavior:e.behavior},...e.top===void 0?{}:{left:e.top}}),o.current.scrollBy(e)}return{scrollByCallback:d,scrollerRef:o,scrollToCallback:u}}function AI(e){return e}var jI=hP(([e,t])=>({...e,...t}),qN(_I,hP(()=>{let e=$(e=>`Item ${e}`),t=$(e=>`Group ${e}`),n=$({}),r=$(AI),i=$(`div`),a=$(WN),o=(e,t=null)=>fP(Q(n,iP(t=>t[e]),nP()),t);return{components:n,computeItemKey:r,EmptyPlaceholder:o(`EmptyPlaceholder`),FooterComponent:o(`Footer`),GroupComponent:o(`Group`,`div`),groupContent:t,HeaderComponent:o(`Header`),HeaderFooterTag:i,ItemComponent:o(`Item`,`div`),itemContent:e,ListComponent:o(`List`,`div`),ScrollerComponent:o(`Scroller`,`div`),scrollerRef:a,ScrollSeekPlaceholder:o(`ScrollSeekPlaceholder`),TopItemListComponent:o(`TopItemList`)}}))),MI=({height:e})=>(0,L.jsx)(`div`,{style:{height:e}}),NI={overflowAnchor:`none`,position:TI(),zIndex:1},PI={overflowAnchor:`none`},FI={...PI,display:`inline-block`,height:`100%`},II=_.memo(function({showTopList:e=!1}){let t=QI(`listState`),n=$I(`sizeRanges`),r=QI(`useWindowScroll`),i=QI(`customScrollParent`),a=$I(`windowScrollContainerState`),o=$I(`scrollContainerState`),s=i||r?a:o,c=QI(`itemContent`),l=QI(`context`),u=QI(`groupContent`),d=QI(`trackItemSizes`),f=QI(`itemSize`),p=QI(`log`),m=$I(`gap`),h=QI(`horizontalDirection`),{callbackRef:g}=DP(n,f,d,e?WN:s,p,m,i,h,QI(`skipAnimationFrameInResizeObserver`)),[v,y]=_.useState(0);ZI(`deviation`,e=>{v!==e&&y(e)});let b=QI(`EmptyPlaceholder`),x=QI(`ScrollSeekPlaceholder`)??MI,S=QI(`ListComponent`),C=QI(`ItemComponent`),w=QI(`GroupComponent`),T=QI(`computeItemKey`),E=QI(`isSeeking`),D=QI(`groupIndices`).length>0,O=QI(`alignToBottom`),k=QI(`initialItemFinalLocationReached`),A=e?{}:{boxSizing:`border-box`,...h?{display:`inline-block`,height:`100%`,marginLeft:v===0?O?`auto`:0:v,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:`nowrap`}:{marginTop:v===0?O?`auto`:0:v,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...k?{}:{visibility:`hidden`}};return!e&&t.totalCount===0&&b!=null?(0,L.jsx)(b,{...VI(b,l)}):(0,L.jsx)(S,{...VI(S,l),"data-testid":e?`virtuoso-top-item-list`:`virtuoso-item-list`,ref:g,style:A,children:(e?t.topItems:t.items).map(e=>{let n=e.originalIndex,r=T(n+t.firstItemIndex,e.data,l);return E?(0,_.createElement)(x,{...VI(x,l),height:e.size,index:e.index,key:r,type:e.type||`item`,...e.type===`group`?{}:{groupIndex:e.groupIndex}}):e.type===`group`?(0,_.createElement)(w,{...VI(w,l),"data-index":n,"data-item-index":e.index,"data-known-size":e.size,key:r,style:NI},u(e.index,l)):(0,_.createElement)(C,{...VI(C,l),...HI(C,e.data),"data-index":n,"data-item-group-index":e.groupIndex,"data-item-index":e.index,"data-known-size":e.size,key:r,style:h?FI:PI},D?c(e.index,e.groupIndex,e.data,l):c(e.index,e.data,l))})})}),LI={height:`100%`,outline:`none`,overflowY:`auto`,position:`relative`,WebkitOverflowScrolling:`touch`},RI={outline:`none`,overflowX:`auto`,position:`relative`},zI=e=>({height:`100%`,position:`absolute`,top:0,width:`100%`,...e?{display:`flex`,flexDirection:`column`}:void 0}),BI={position:TI(),top:0,width:`100%`,zIndex:1};function VI(e,t){if(typeof e!=`string`)return{context:t}}function HI(e,t){return{item:typeof e==`string`?void 0:t}}var UI=_.memo(function(){let e=QI(`HeaderComponent`),t=$I(`headerHeight`),n=QI(`HeaderFooterTag`),r=TP(_.useMemo(()=>e=>{t(aF(e,`height`))},[t]),!0,QI(`skipAnimationFrameInResizeObserver`)),i=QI(`context`);return e==null?null:(0,L.jsx)(n,{ref:r,children:(0,L.jsx)(e,{...VI(e,i)})})}),WI=_.memo(function(){let e=QI(`FooterComponent`),t=$I(`footerHeight`),n=QI(`HeaderFooterTag`),r=TP(_.useMemo(()=>e=>{t(aF(e,`height`))},[t]),!0,QI(`skipAnimationFrameInResizeObserver`)),i=QI(`context`);return e==null?null:(0,L.jsx)(n,{ref:r,children:(0,L.jsx)(e,{...VI(e,i)})})});function GI({useEmitter:e,useEmitterValue:t,usePublisher:n}){return _.memo(function({children:r,style:i,context:a,...o}){let s=n(`scrollContainerState`),c=t(`ScrollerComponent`),l=n(`smoothScrollTargetReached`),u=t(`scrollerRef`),d=t(`horizontalDirection`)||!1,{scrollByCallback:f,scrollerRef:p,scrollToCallback:m}=kI(s,l,c,u,void 0,d);return e(`scrollTo`,m),e(`scrollBy`,f),(0,L.jsx)(c,{"data-testid":`virtuoso-scroller`,"data-virtuoso-scroller":!0,ref:p,style:{...d?RI:LI,...i},tabIndex:0,...o,...VI(c,a),children:r})})}function KI({useEmitter:e,useEmitterValue:t,usePublisher:n}){return _.memo(function({children:r,style:i,context:a,...o}){let s=n(`windowScrollContainerState`),c=t(`ScrollerComponent`),l=n(`smoothScrollTargetReached`),u=t(`totalListHeight`),d=t(`deviation`),f=t(`customScrollParent`),p=_.useRef(null),{scrollByCallback:m,scrollerRef:h,scrollToCallback:g}=kI(s,l,c,t(`scrollerRef`),f);return EI(()=>(h.current=f||p.current?.ownerDocument.defaultView,()=>{h.current=null}),[h,f]),e(`windowScrollTo`,g),e(`scrollBy`,m),(0,L.jsx)(c,{ref:p,"data-virtuoso-scroller":!0,style:{position:`relative`,...i,...u===0?void 0:{height:u+d}},...o,...VI(c,a),children:r})})}var qI=({children:e})=>{let t=_.useContext(xI),n=$I(`viewportHeight`),r=$I(`fixedItemHeight`),i=QI(`alignToBottom`),a=QI(`horizontalDirection`),o=TP(_.useMemo(()=>zN(n,e=>aF(e,a?`width`:`height`)),[n,a]),!0,QI(`skipAnimationFrameInResizeObserver`));return _.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),(0,L.jsx)(`div`,{"data-viewport-type":`element`,ref:o,style:zI(i),children:e})},JI=({children:e})=>{let t=_.useContext(xI),n=$I(`windowViewportRect`),r=$I(`fixedItemHeight`),i=AP(n,QI(`customScrollParent`),QI(`skipAnimationFrameInResizeObserver`)),a=QI(`alignToBottom`);return _.useEffect(()=>{t&&(r(t.itemHeight),n({listHeight:0,offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),(0,L.jsx)(`div`,{"data-viewport-type":`window`,ref:i,style:zI(a),children:e})},YI=({children:e})=>{let t=QI(`TopItemListComponent`)??`div`,n=QI(`headerHeight`);return(0,L.jsx)(t,{style:{...BI,marginTop:`${n}px`},...VI(t,QI(`context`)),children:e})},{Component:XI,useEmitter:ZI,useEmitterValue:QI,usePublisher:$I}=bI(jI,{optional:{restoreStateFrom:`restoreStateFrom`,context:`context`,followOutput:`followOutput`,scrollIntoViewOnChange:`scrollIntoViewOnChange`,itemContent:`itemContent`,groupContent:`groupContent`,overscan:`overscan`,increaseViewportBy:`increaseViewportBy`,minOverscanItemCount:`minOverscanItemCount`,totalCount:`totalCount`,groupCounts:`groupCounts`,topItemCount:`topItemCount`,firstItemIndex:`firstItemIndex`,initialTopMostItemIndex:`initialTopMostItemIndex`,components:`components`,atBottomThreshold:`atBottomThreshold`,atTopThreshold:`atTopThreshold`,computeItemKey:`computeItemKey`,defaultItemHeight:`defaultItemHeight`,fixedGroupHeight:`fixedGroupHeight`,fixedItemHeight:`fixedItemHeight`,heightEstimates:`heightEstimates`,itemSize:`itemSize`,scrollSeekConfiguration:`scrollSeekConfiguration`,headerFooterTag:`HeaderFooterTag`,data:`data`,initialItemCount:`initialItemCount`,initialScrollTop:`initialScrollTop`,alignToBottom:`alignToBottom`,useWindowScroll:`useWindowScroll`,customScrollParent:`customScrollParent`,scrollerRef:`scrollerRef`,logLevel:`logLevel`,horizontalDirection:`horizontalDirection`,skipAnimationFrameInResizeObserver:`skipAnimationFrameInResizeObserver`},methods:{scrollToIndex:`scrollToIndex`,scrollIntoView:`scrollIntoView`,scrollTo:`scrollTo`,scrollBy:`scrollBy`,autoscrollToBottom:`autoscrollToBottom`,getState:`getState`},events:{isScrolling:`isScrolling`,endReached:`endReached`,startReached:`startReached`,rangeChanged:`rangeChanged`,atBottomStateChange:`atBottomStateChange`,atTopStateChange:`atTopStateChange`,totalListHeightChanged:`totalListHeightChanged`,itemsRendered:`itemsRendered`,groupIndices:`groupIndices`}},_.memo(function(e){let t=QI(`useWindowScroll`),n=QI(`topItemsIndexes`).length>0,r=QI(`customScrollParent`),i=QI(`context`);return(0,L.jsxs)(r||t?tL:eL,{...e,context:i,children:[n&&(0,L.jsx)(YI,{children:(0,L.jsx)(II,{showTopList:!0})}),(0,L.jsxs)(r||t?JI:qI,{children:[(0,L.jsx)(UI,{}),(0,L.jsx)(II,{}),(0,L.jsx)(WI,{})]})]})})),eL=GI({useEmitter:ZI,useEmitterValue:QI,usePublisher:$I}),tL=KI({useEmitter:ZI,useEmitterValue:QI,usePublisher:$I}),nL=XI,rL=hP(([e,t])=>({...e,...t}),qN(_I,hP(()=>{let e=$(e=>(0,L.jsxs)(`td`,{children:[`Item $`,e]})),t=$(null),n=$(e=>(0,L.jsxs)(`td`,{colSpan:1e3,children:[`Group `,e]})),r=$(null),i=$(null),a=$({}),o=$(AI),s=$(WN),c=(e,t=null)=>fP(Q(a,iP(t=>t[e]),nP()),t);return{components:a,computeItemKey:o,context:t,EmptyPlaceholder:c(`EmptyPlaceholder`),FillerRow:c(`FillerRow`),fixedFooterContent:i,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:c(`Scroller`,`div`),scrollerRef:s,ScrollSeekPlaceholder:c(`ScrollSeekPlaceholder`),TableBodyComponent:c(`TableBody`,`tbody`),TableComponent:c(`Table`,`table`),TableFooterComponent:c(`TableFoot`,`tfoot`),TableHeadComponent:c(`TableHead`,`thead`),TableRowComponent:c(`TableRow`,`tr`),GroupComponent:c(`Group`,`tr`)}}))),iL=({height:e})=>(0,L.jsx)(`tr`,{children:(0,L.jsx)(`td`,{style:{height:e}})}),aL=({height:e})=>(0,L.jsx)(`tr`,{children:(0,L.jsx)(`td`,{style:{border:0,height:e,padding:0}})}),oL={overflowAnchor:`none`},sL={position:TI(),zIndex:2,overflowAnchor:`none`},cL=_.memo(function({showTopList:e=!1}){let t=mL(`listState`),n=mL(`computeItemKey`),r=mL(`firstItemIndex`),i=mL(`context`),a=mL(`isSeeking`),o=mL(`fixedHeaderHeight`),s=mL(`groupIndices`).length>0,c=mL(`itemContent`),l=mL(`groupContent`),u=mL(`ScrollSeekPlaceholder`)??iL,d=mL(`GroupComponent`),f=mL(`TableRowComponent`),p=(e?t.topItems:[]).reduce((e,t,n)=>(n===0?e.push(t.size):e.push(e[n-1]+t.size),e),[]);return(e?t.topItems:t.items).map(t=>{let m=t.originalIndex,h=n(m+r,t.data,i),g=e?m===0?0:p[m-1]:0;return a?(0,_.createElement)(u,{...VI(u,i),height:t.size,index:t.index,key:h,type:t.type||`item`}):t.type===`group`?(0,_.createElement)(d,{...VI(d,i),"data-index":m,"data-item-index":t.index,"data-known-size":t.size,key:h,style:{...sL,top:o}},l(t.index,i)):(0,_.createElement)(f,{...VI(f,i),...HI(f,t.data),"data-index":m,"data-item-index":t.index,"data-known-size":t.size,"data-item-group-index":t.groupIndex,key:h,style:e?{...sL,top:o+g}:oL},s?c(t.index,t.groupIndex,t.data,i):c(t.index,t.data,i))})}),lL=_.memo(function(){let e=mL(`listState`),t=mL(`topItemsIndexes`).length>0,n=hL(`sizeRanges`),r=mL(`useWindowScroll`),i=mL(`customScrollParent`),a=hL(`windowScrollContainerState`),o=hL(`scrollContainerState`),s=i||r?a:o,c=mL(`trackItemSizes`),{callbackRef:l,ref:u}=DP(n,mL(`itemSize`),c,s,mL(`log`),void 0,i,!1,mL(`skipAnimationFrameInResizeObserver`)),[d,f]=_.useState(0);pL(`deviation`,e=>{d!==e&&(u.current.style.marginTop=`${e}px`,f(e))});let p=mL(`EmptyPlaceholder`),m=mL(`FillerRow`)??aL,h=mL(`TableBodyComponent`),g=mL(`paddingTopAddition`),v=mL(`statefulTotalCount`),y=mL(`context`);if(v===0&&p!=null)return(0,L.jsx)(p,{...VI(p,y)});let b=(t?e.topItems:[]).reduce((e,t)=>e+t.size,0),x=e.offsetTop+g+d-b,S=e.offsetBottom,C=x>0?(0,L.jsx)(m,{context:y,height:x},`padding-top`):null,w=S>0?(0,L.jsx)(m,{context:y,height:S},`padding-bottom`):null;return(0,L.jsxs)(h,{"data-testid":`virtuoso-item-list`,ref:l,...VI(h,y),children:[C,t&&(0,L.jsx)(cL,{showTopList:!0}),(0,L.jsx)(cL,{}),w]})}),uL=({children:e})=>{let t=_.useContext(xI),n=hL(`viewportHeight`),r=hL(`fixedItemHeight`),i=TP(_.useMemo(()=>zN(n,e=>aF(e,`height`)),[n]),!0,mL(`skipAnimationFrameInResizeObserver`));return _.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),(0,L.jsx)(`div`,{"data-viewport-type":`element`,ref:i,style:zI(!1),children:e})},dL=({children:e})=>{let t=_.useContext(xI),n=hL(`windowViewportRect`),r=hL(`fixedItemHeight`),i=AP(n,mL(`customScrollParent`),mL(`skipAnimationFrameInResizeObserver`));return _.useEffect(()=>{t&&(r(t.itemHeight),n({listHeight:0,offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),(0,L.jsx)(`div`,{"data-viewport-type":`window`,ref:i,style:zI(!1),children:e})},{Component:fL,useEmitter:pL,useEmitterValue:mL,usePublisher:hL}=bI(rL,{optional:{restoreStateFrom:`restoreStateFrom`,context:`context`,followOutput:`followOutput`,firstItemIndex:`firstItemIndex`,itemContent:`itemContent`,groupContent:`groupContent`,fixedHeaderContent:`fixedHeaderContent`,fixedFooterContent:`fixedFooterContent`,overscan:`overscan`,increaseViewportBy:`increaseViewportBy`,minOverscanItemCount:`minOverscanItemCount`,totalCount:`totalCount`,topItemCount:`topItemCount`,initialTopMostItemIndex:`initialTopMostItemIndex`,components:`components`,groupCounts:`groupCounts`,atBottomThreshold:`atBottomThreshold`,atTopThreshold:`atTopThreshold`,computeItemKey:`computeItemKey`,defaultItemHeight:`defaultItemHeight`,fixedGroupHeight:`fixedGroupHeight`,fixedItemHeight:`fixedItemHeight`,itemSize:`itemSize`,scrollSeekConfiguration:`scrollSeekConfiguration`,data:`data`,initialItemCount:`initialItemCount`,initialScrollTop:`initialScrollTop`,alignToBottom:`alignToBottom`,useWindowScroll:`useWindowScroll`,customScrollParent:`customScrollParent`,scrollerRef:`scrollerRef`,logLevel:`logLevel`},methods:{scrollToIndex:`scrollToIndex`,scrollIntoView:`scrollIntoView`,scrollTo:`scrollTo`,scrollBy:`scrollBy`,getState:`getState`},events:{isScrolling:`isScrolling`,endReached:`endReached`,startReached:`startReached`,rangeChanged:`rangeChanged`,atBottomStateChange:`atBottomStateChange`,atTopStateChange:`atTopStateChange`,totalListHeightChanged:`totalListHeightChanged`,itemsRendered:`itemsRendered`,groupIndices:`groupIndices`}},_.memo(function(e){let t=mL(`useWindowScroll`),n=mL(`customScrollParent`),r=hL(`fixedHeaderHeight`),i=hL(`fixedFooterHeight`),a=mL(`fixedHeaderContent`),o=mL(`fixedFooterContent`),s=mL(`context`),c=TP(_.useMemo(()=>zN(r,e=>aF(e,`height`)),[r]),!0,mL(`skipAnimationFrameInResizeObserver`)),l=TP(_.useMemo(()=>zN(i,e=>aF(e,`height`)),[i]),!0,mL(`skipAnimationFrameInResizeObserver`)),u=n||t?_L:gL,d=n||t?dL:uL,f=mL(`TableComponent`),p=mL(`TableHeadComponent`),m=mL(`TableFooterComponent`),h=a?(0,L.jsx)(p,{ref:c,style:{position:`sticky`,top:0,zIndex:2},...VI(p,s),children:a()},`TableHead`):null,g=o?(0,L.jsx)(m,{ref:l,style:{bottom:0,position:`sticky`,zIndex:1},...VI(m,s),children:o()},`TableFoot`):null;return(0,L.jsx)(u,{...e,...VI(u,s),children:(0,L.jsx)(d,{children:(0,L.jsxs)(f,{style:{borderSpacing:0,overflowAnchor:`none`},...VI(f,s),children:[h,(0,L.jsx)(lL,{},`TableBody`),g]})})})})),gL=GI({useEmitter:pL,useEmitterValue:mL,usePublisher:hL}),_L=KI({useEmitter:pL,useEmitterValue:mL,usePublisher:hL}),vL={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},yL={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:bL,floor:xL,max:SL,min:CL,round:wL}=Math;function TL(e,t,n){return Array.from({length:t-e+1}).map((t,r)=>({data:n===null?null:n[r+e],index:r+e}))}function EL(e){return{...yL,items:e}}function DL(e,t){return e!==void 0&&e.width===t.width&&e.height===t.height}function OL(e,t){return e!==void 0&&e.column===t.column&&e.row===t.row}var kL=hP(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:i,headerHeight:a,scrollBy:o,scrollContainerState:s,scrollTo:c,scrollTop:l,smoothScrollTargetReached:u,viewportHeight:d},f,p,{didMount:m,propsReady:h},{customScrollParent:g,useWindowScroll:_,windowScrollContainerState:v,windowScrollTo:y,windowViewportRect:b},x])=>{let S=$(0),C=$(0),w=$(vL),T=$({height:0,width:0}),E=$({height:0,width:0}),D=pP(),O=pP(),k=$(0),A=$(null),j=$({column:0,row:0}),M=pP(),ee=pP(),N=$(!1),P=$(0),F=$(!0),I=$(!1),te=$(!1);JN(Q(m,lP(P),rP(([e,t])=>t!==0)),()=>{YN(F,!1)}),JN(Q(vP(m,F,E,T,P,I),rP(([e,t,n,r,,i])=>e&&!t&&n.height!==0&&r.height!==0&&!i)),([,,,,e])=>{YN(I,!0),jF(1,()=>{YN(D,e)}),$N(Q(l),()=>{YN(t,[0,0]),YN(F,!0)})}),QN(Q(ee,rP(e=>e!=null&&e.scrollTop>0),aP(0)),C),JN(Q(m,lP(ee),rP(([,e])=>e!=null)),([,e])=>{e&&(YN(T,e.viewport),YN(E,e.item),YN(j,e.gap),e.scrollTop>0&&(YN(N,!0),$N(Q(l,sP(1)),e=>{YN(N,!1)}),YN(c,{top:e.scrollTop})))}),QN(Q(T,iP(({height:e})=>e)),d),QN(Q(vP(yP(T,DL),yP(E,DL),yP(j,(e,t)=>e!==void 0&&e.column===t.column&&e.row===t.row),yP(l)),iP(([e,t,n,r])=>({gap:n,item:t,scrollTop:r,viewport:e}))),M),QN(Q(vP(yP(S),r,yP(j,OL),yP(E,DL),yP(T,DL),yP(A),yP(C),yP(N),yP(F),yP(P)),rP(([,,,,,,,e])=>!e),iP(([e,[t,n],r,i,a,o,s,,c,l])=>{let{column:u,row:d}=r,{height:f,width:p}=i,{width:m}=a;if(s===0&&(e===0||m===0))return vL;if(p===0){let t=MF(l,e);return EL(TL(t,t+Math.max(s-1,0),o))}let h=AL(m,p,u),g,_;c?t===0&&n===0&&s>0?(g=0,_=s-1):(g=h*xL((t+d)/(f+d)),_=h*bL((n+d)/(f+d))-1,_=CL(e-1,SL(_,h-1)),g=CL(_,SL(0,g))):(g=0,_=-1);let v=TL(g,_,o),{bottom:y,top:b}=jL(a,r,i,v),x=bL(e/h);return{bottom:y,itemHeight:f,items:v,itemWidth:p,offsetBottom:x*f+(x-1)*d-y,offsetTop:b,top:b}})),w),QN(Q(A,rP(e=>e!==null),iP(e=>e.length)),S),QN(Q(vP(T,E,w,j),rP(([e,t,{items:n}])=>n.length>0&&t.height!==0&&e.height!==0),iP(([e,t,{items:n},r])=>{let{bottom:i,top:a}=jL(e,r,t,n);return[a,i]}),nP(eF)),t);let ne=$(!1);QN(Q(l,lP(ne),iP(([e,t])=>t||e!==0)),ne);let re=mP(Q(vP(w,S),rP(([{items:e}])=>e.length>0),lP(ne),rP(([[e,t],n])=>{let r=e.items[e.items.length-1].index===t-1;return(n||e.bottom>0&&e.itemHeight>0&&e.offsetBottom===0&&e.items.length===t)&&r}),iP(([[,e]])=>e-1),nP())),ie=mP(Q(yP(w),rP(({items:e})=>e.length>0&&e[0].index===0),aP(0),nP())),ae=mP(Q(yP(w),lP(N),rP(([{items:e},t])=>e.length>0&&!t),iP(([{items:e}])=>({endIndex:e[e.length-1].index,startIndex:e[0].index})),nP($P),cP(0)));QN(ae,p.scrollSeekRangeChanged),QN(Q(D,lP(T,E,S,j),iP(([e,t,n,r,i])=>{let a=OF(e),{align:o,behavior:s,offset:c}=a,l=a.index;l===`LAST`&&(l=r-1),l=SL(0,l,CL(r-1,l));let u=ML(t,i,n,l);return o===`end`?u=wL(u-t.height+n.height):o===`center`&&(u=wL(u-t.height/2+n.height/2)),c!==void 0&&c!==0&&(u+=c),{behavior:s,top:u}})),c);let oe=fP(Q(w,iP(e=>e.offsetBottom+e.bottom)),0);return QN(Q(b,iP(e=>({height:e.visibleHeight,width:e.visibleWidth}))),T),{customScrollParent:g,data:A,deviation:k,footerHeight:i,gap:j,headerHeight:a,increaseViewportBy:e,initialItemCount:C,itemDimensions:E,overscan:n,restoreStateFrom:ee,scrollBy:o,scrollContainerState:s,scrollHeight:O,scrollTo:c,scrollToIndex:D,scrollTop:l,smoothScrollTargetReached:u,totalCount:S,useWindowScroll:_,viewportDimensions:T,windowScrollContainerState:v,windowScrollTo:y,windowViewportRect:b,...p,gridState:w,horizontalDirection:te,initialTopMostItemIndex:P,totalListHeight:oe,...f,endReached:re,propsReady:h,rangeChanged:ae,startReached:ie,stateChanged:M,stateRestoreInProgress:N,...x}},qN(KF,jP,BF,uI,EF,dI,wP));function AL(e,t,n){return SL(1,xL((e+n)/(xL(t)+n)))}function jL(e,t,n,r){let{height:i}=n;if(i===void 0||r.length===0)return{bottom:0,top:0};let a=ML(e,t,n,r[0].index);return{bottom:ML(e,t,n,r[r.length-1].index)+i,top:a}}function ML(e,t,n,r){let i=xL(r/AL(e.width,n.width,t.column)),a=i*n.height+SL(0,i-1)*t.row;return a>0?a+t.row:a}var NL=hP(([e,t])=>({...e,...t}),qN(kL,hP(()=>{let e=$(e=>`Item ${e}`),t=$({}),n=$(null),r=$(`virtuoso-grid-item`),i=$(`virtuoso-grid-list`),a=$(AI),o=$(`div`),s=$(WN),c=(e,n=null)=>fP(Q(t,iP(t=>t[e]),nP()),n),l=$(!1),u=$(!1);return QN(yP(u),l),{components:t,computeItemKey:a,context:n,FooterComponent:c(`Footer`),HeaderComponent:c(`Header`),headerFooterTag:o,itemClassName:r,ItemComponent:c(`Item`,`div`),itemContent:e,listClassName:i,ListComponent:c(`List`,`div`),readyStateChanged:l,reportReadyState:u,ScrollerComponent:c(`Scroller`,`div`),scrollerRef:s,ScrollSeekPlaceholder:c(`ScrollSeekPlaceholder`,`div`)}}))),PL=_.memo(function(){let e=VL(`gridState`),t=VL(`listClassName`),n=VL(`itemClassName`),r=VL(`itemContent`),i=VL(`computeItemKey`),a=VL(`isSeeking`),o=HL(`scrollHeight`),s=VL(`ItemComponent`),c=VL(`ListComponent`),l=VL(`ScrollSeekPlaceholder`),u=VL(`context`),d=HL(`itemDimensions`),f=HL(`gap`),p=VL(`log`),m=VL(`stateRestoreInProgress`),h=HL(`reportReadyState`),g=TP(_.useMemo(()=>e=>{let t=e.parentElement.parentElement.scrollHeight;o(t);let n=e.firstChild;if(n!==null){let{height:e,width:t}=n.getBoundingClientRect();d({height:e,width:t})}f({column:GL(`column-gap`,getComputedStyle(e).columnGap,p),row:GL(`row-gap`,getComputedStyle(e).rowGap,p)})},[o,d,f,p]),!0,!1);return EI(()=>{e.itemHeight>0&&e.itemWidth>0&&h(!0)},[e]),m?null:(0,L.jsx)(c,{className:t,ref:g,...VI(c,u),"data-testid":`virtuoso-item-list`,style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(t=>{let o=i(t.index,t.data,u);return a?(0,L.jsx)(l,{...VI(l,u),height:e.itemHeight,index:t.index,width:e.itemWidth},o):(0,_.createElement)(s,{...VI(s,u),className:n,"data-index":t.index,key:o},r(t.index,t.data,u))})})}),FL=_.memo(function(){let e=VL(`HeaderComponent`),t=HL(`headerHeight`),n=VL(`headerFooterTag`),r=TP(_.useMemo(()=>e=>{t(aF(e,`height`))},[t]),!0,!1),i=VL(`context`);return e==null?null:(0,L.jsx)(n,{ref:r,children:(0,L.jsx)(e,{...VI(e,i)})})}),IL=_.memo(function(){let e=VL(`FooterComponent`),t=HL(`footerHeight`),n=VL(`headerFooterTag`),r=TP(_.useMemo(()=>e=>{t(aF(e,`height`))},[t]),!0,!1),i=VL(`context`);return e==null?null:(0,L.jsx)(n,{ref:r,children:(0,L.jsx)(e,{...VI(e,i)})})}),LL=({children:e})=>{let t=_.useContext(SI),n=HL(`itemDimensions`),r=HL(`viewportDimensions`),i=TP(_.useMemo(()=>e=>{r(e.getBoundingClientRect())},[r]),!0,!1);return _.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),(0,L.jsx)(`div`,{ref:i,style:zI(!1),children:e})},RL=({children:e})=>{let t=_.useContext(SI),n=HL(`windowViewportRect`),r=HL(`itemDimensions`),i=AP(n,VL(`customScrollParent`),!1);return _.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({listHeight:0,offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),(0,L.jsx)(`div`,{ref:i,style:zI(!1),children:e})},{Component:zL,useEmitter:BL,useEmitterValue:VL,usePublisher:HL}=bI(NL,{optional:{context:`context`,totalCount:`totalCount`,overscan:`overscan`,itemContent:`itemContent`,components:`components`,computeItemKey:`computeItemKey`,data:`data`,initialItemCount:`initialItemCount`,scrollSeekConfiguration:`scrollSeekConfiguration`,headerFooterTag:`headerFooterTag`,listClassName:`listClassName`,itemClassName:`itemClassName`,useWindowScroll:`useWindowScroll`,customScrollParent:`customScrollParent`,scrollerRef:`scrollerRef`,logLevel:`logLevel`,restoreStateFrom:`restoreStateFrom`,initialTopMostItemIndex:`initialTopMostItemIndex`,increaseViewportBy:`increaseViewportBy`},methods:{scrollTo:`scrollTo`,scrollBy:`scrollBy`,scrollToIndex:`scrollToIndex`},events:{isScrolling:`isScrolling`,endReached:`endReached`,startReached:`startReached`,rangeChanged:`rangeChanged`,atBottomStateChange:`atBottomStateChange`,atTopStateChange:`atTopStateChange`,stateChanged:`stateChanged`,readyStateChanged:`readyStateChanged`}},_.memo(function({...e}){let t=VL(`useWindowScroll`),n=VL(`customScrollParent`),r=n||t?WL:UL,i=n||t?RL:LL,a=VL(`context`);return(0,L.jsx)(r,{...e,...VI(r,a),children:(0,L.jsxs)(i,{children:[(0,L.jsx)(FL,{}),(0,L.jsx)(PL,{}),(0,L.jsx)(IL,{})]})})})),UL=GI({useEmitter:BL,useEmitterValue:VL,usePublisher:HL}),WL=KI({useEmitter:BL,useEmitterValue:VL,usePublisher:HL});
148function GL(e,t,n){return t!==`normal`&&t?.endsWith(`px`)!==!0&&n(`${e} was not resolved to pixel value correctly`,t,xP.WARN),t===`normal`?0:parseInt(t??`0`,10)}var KL=Iv,qL=_.forwardRef(({className:e,...t},n)=>(0,L.jsx)(Lv,{ref:n,className:V(`inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground`,e),...t}));qL.displayName=Lv.displayName;var JL=_.forwardRef(({className:e,...t},n)=>(0,L.jsx)(Rv,{ref:n,className:V(`inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow`,e),...t}));JL.displayName=Rv.displayName;var YL=_.forwardRef(({className:e,...t},n)=>(0,L.jsx)(zv,{ref:n,className:V(`mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,e),...t}));YL.displayName=zv.displayName;var XL=`inbox:draft:`,ZL=250,QL=1e4,$L=`inbox-draft-change`;function eR(e){return`${XL}${e}`}function tR(e){try{return window.localStorage.getItem(eR(e))??``}catch{return``}}function nR(e){return tR(e)}function rR(e,t){try{let n=eR(e);if(t===``)window.localStorage.removeItem(n);else{let e=t.length>QL?t.slice(0,QL):t;window.localStorage.setItem(n,e)}window.dispatchEvent(new CustomEvent($L,{detail:{conversationId:e}}))}catch{}}function iR(e){let[t,n]=(0,_.useState)(()=>({id:e,text:tR(e)})),r=(0,_.useRef)(null);t.id!==e&&n({id:e,text:tR(e)});let i=(0,_.useCallback)(t=>{n({id:e,text:t}),r.current!==null&&window.clearTimeout(r.current),r.current=window.setTimeout(()=>{rR(e,t)},ZL)},[e]);(0,_.useEffect)(()=>{let t=eR(e),r=r=>{r.key===t&&n({id:e,text:r.newValue??``})};return window.addEventListener(`storage`,r),()=>window.removeEventListener(`storage`,r)},[e]);let a=(0,_.useCallback)(()=>{r.current!==null&&(window.clearTimeout(r.current),r.current=null),n({id:e,text:``}),rR(e,``)},[e]);return[t.text,i,a]}function aR(){let e=new Set;try{for(let t=0;t<window.localStorage.length;t++){let n=window.localStorage.key(t);n?.startsWith(XL)&&e.add(n.slice(12))}}catch{}return e}function oR(){let[e,t]=(0,_.useState)(()=>aR());return(0,_.useEffect)(()=>{let e=()=>t(aR()),n=t=>{(t.key===null||t.key.startsWith(XL))&&e()};return window.addEventListener(`storage`,n),window.addEventListener($L,e),()=>{window.removeEventListener(`storage`,n),window.removeEventListener($L,e)}},[]),e}function sR(e,t){return e===`cloud_api`&&t}function cR(e,t,n,r){return sR(e,t)&&n&&!r}function lR({channel:e,cloudRoutingActive:t,detailsLoaded:n,inWindow:r,isClosed:i,isSimulation:a}){return cR(e,t,n,r)&&!i&&!a}var uR=[{value:`all`,label:`All`,title:`Both WhatsApp numbers`},{value:`cloud_api`,label:`Cloud`,title:`Cloud API 1:1 line (old number)`},{value:`baileys`,label:`Groups`,title:`Linked-device line (new number) - WhatsApp groups & legacy 1:1s`}];function dR(e){if(!e||typeof e!=`object`)return null;let t=e.template;if(!t||typeof t!=`object`)return null;let{kind:n}=t;return typeof n==`string`&&n.length>0?n:null}function fR({channel:e,cloudRoutingActive:t,detailsLoaded:n,inWindow:r,hasTemplate:i}){return!sR(e,t)||!n?`none`:r?`session`:i?`template`:`template_missing`}function pR(e){switch(e){case`session`:return`Send Message`;case`template`:return`Send Template`;case`template_missing`:return`Template Required`;case`none`:return null}}function mR(e,t){switch(e){case`template_missing`:return t?`The 24-hour reply window has closed and this draft has no approved template, so WhatsApp will not accept it. Send a template from the composer instead.`:`The 24-hour reply window has closed and this draft has no approved template, so WhatsApp will not accept it. It can go out once the lead replies.`;case`session`:case`template`:case`none`:return null}}function hR(e,t,n){return sR(e,n)?!0:t}function gR(e){return e===`cloud_api`?`Cloud`:`WhatsApp`}
148function _R(e,t=Date.now()){if(!e)return`expired`;let n=new Date(e).getTime();if(Number.isNaN(n))return`expired`;let r=n-t;if(r<=0)return`expired`;let i=Math.floor(r/6e4),a=Math.floor(i/60),o=i%60;return a>0?`${a}h ${o}m`:o>0?`${o}m`:`under 1m`}var vR=1024;function yR(e,t=vR){let n=e.length;return n<=t?{ok:!0}:{ok:!1,length:n,max:t,message:`Caption is ${n} characters â please keep it under ${t}.`}}function bR(e){if(!e||typeof e!=`object`)return null;let t=e.deliveryError;if(!t||typeof t!=`object`)return null;let{code:n,title:r,details:i}=t;return typeof r!=`string`||r.length===0?null:{code:typeof n==`number`?n:null,title:r,details:typeof i==`string`&&i.length>0?i:null}}function xR(e){let t=bR(e);if(!t)return`Not delivered`;let n=t.code==null?``:` (Meta code ${t.code})`;return`Not delivered - ${t.title}${n}`}function SR(e){return e!=null&&e.used>=e.cap}function CR(e){let t=`Daily group creation limit reached (${e.used}/${e.cap})`;return e.nextFreeAt==null?`${t}. You can still create the group manually on WhatsApp.`:`${t} - next slot ~${new Date(e.nextFreeAt).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}. You can still create the group manually on WhatsApp.`}var wR=(0,_.forwardRef)(function({conversations:e,counts:t,selectedId:n,onSelect:r,filter:i,onFilterChange:a,channel:o,onChannelChange:s,leadsOnly:c,onLeadsOnlyChange:l,hideDrafts:u,onHideDraftsChange:d,search:f,onSearchChange:p,focusedIndex:m,onFocusedIndexChange:h,isLoading:g,isError:v,onRetry:y,onExport:b,hasNextPage:x,isFetchingNextPage:S,onEndReached:C,selectMode:w,onEnterSelectMode:T,selectedIds:E,onToggleSelection:D,onNewGroup:O,onNewChat:k,whatsappConnected:A},j){let M=(0,_.useRef)(null),ee=(0,_.useRef)(null),{groupOpsEnabled:N,groupCreateQuota:P}=kN(),F=SR(P),I=oR(),te=ri();(0,_.useImperativeHandle)(j,()=>({focusSearch:()=>{let e=M.current;e&&(e.focus(),e.select())}}));let ne=R({mutationFn:e=>H(`/api/messages/conversations/${e}/pin`,{method:`POST`}),onSuccess:()=>{te.invalidateQueries({queryKey:[`conversations`]})},onError:e=>{z.error(e.message||`Could not update pin`)}}),{pinned:re,unpinned:ie}=(0,_.useMemo)(()=>{let t=[],n=[];for(let r of e)(r.isPinned?t:n).push(r);return{pinned:t,unpinned:n}},[e]);return(0,_.useEffect)(()=>{e.length!==0&&ee.current?.scrollIntoView({index:m})},[m,e.length]),(0,L.jsxs)(`div`,{className:`flex flex-col h-full w-full border-r bg-background`,children:[(0,L.jsxs)(`div`,{className:`p-3 border-b space-y-2`,children:[(0,L.jsx)(KL,{value:i,onValueChange:e=>a(e),children:(0,L.jsxs)(qL,{className:`w-full grid grid-cols-4`,children:[(0,L.jsx)(JL,{value:`all`,className:`text-xs`,children:`All`}),(0,L.jsx)(JL,{value:`open`,className:`text-xs`,children:`Open`}),(0,L.jsxs)(JL,{value:`flagged`,className:`text-xs`,children:[`Flagged`,t&&t.flagged>0&&(0,L.jsx)(X,{variant:`destructive`,className:`ml-1 h-4 min-w-4 text-[10px] px-1`,title:String(t.flagged),children:DR(t.flagged)})]}),(0,L.jsxs)(JL,{value:`ai_issues`,className:`text-xs`,children:[`AI`,t&&t.aiIssues>0&&(0,L.jsx)(X,{className:`ml-1 h-4 min-w-4 text-[10px] px-1 bg-orange-500`,title:String(t.aiIssues),children:DR(t.aiIssues)})]})]})}),(0,L.jsx)(KL,{value:o,onValueChange:e=>s(e),children:(0,L.jsx)(qL,{className:`w-full grid grid-cols-3`,children:uR.map(e=>(0,L.jsx)(JL,{value:e.value,title:e.title,className:`text-xs`,children:e.label},e.value))})}),(0,L.jsxs)(`div`,{className:`flex items-center gap-4 px-0.5 text-xs`,children:[(0,L.jsxs)(`label`,{className:`flex items-center gap-1.5 cursor-pointer select-none`,children:[(0,L.jsx)(tM,{checked:c,onCheckedChange:e=>l(e===!0),"aria-label":`Show leads only`}),(0,L.jsx)(`span`,{className:`text-muted-foreground`,title:`Show only conversations linked to a lead â hides groups, agent chats, and unknown contacts`,children:`Leads only`})]}),(0,L.jsxs)(`label`,{className:`flex items-center gap-1.5 cursor-pointer select-none`,children:[(0,L.jsx)(tM,{checked:u,onCheckedChange:e=>d(e===!0),"aria-label":`Hide AI draft messages and sort by last real message`}),(0,L.jsx)(`span`,{className:`text-muted-foreground`,title:`Hide AI draft messages inside the open chat and sort this list by each chat's last real message â like the WhatsApp app. Drafts stay queued and the list still shows a draft badge`,children:`Hide drafts`})]})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsxs)(`div`,{className:`relative flex-1`,children:[(0,L.jsx)($w,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground`}),(0,L.jsx)(G,{ref:M,placeholder:`Search conversations...`,value:f,onChange:e=>p(e.target.value),className:`pl-9`})]}),k&&!w&&(0,L.jsx)(W,{variant:`outline`,size:`icon`,className:`h-9 w-9 shrink-0`,onClick:k,disabled:A===!1,title:A===!1?`WhatsApp offline`:`New chat`,"aria-label":`New chat`,children:(0,L.jsx)(Mw,{className:`h-4 w-4`})}),O&&!w&&(0,L.jsx)(W,{variant:`outline`,size:`icon`,className:`h-9 w-9 shrink-0`,onClick:O,disabled:!N||F,title:N?F?CR(P):`New group`:`Temporarily disabled â please do so manually on WhatsApp`,"aria-label":`New group`,children:(0,L.jsx)(DT,{className:`h-4 w-4`})}),T&&!w&&(0,L.jsx)(W,{variant:`outline`,size:`icon`,className:`h-9 w-9 shrink-0`,onClick:T,title:`Select conversations`,"aria-label":`Enter select mode`,children:(0,L.jsx)(uT,{className:`h-4 w-4`})}),b&&!w&&(0,L.jsx)(W,{variant:`outline`,size:`icon`,className:`h-9 w-9 shrink-0`,onClick:b,title:`Export CSV`,children:(0,L.jsx)(iw,{className:`h-4 w-4`})})]})]}),(0,L.jsx)(`div`,{className:`flex-1 min-h-0`,children:g?(0,L.jsx)(`div`,{className:`p-3 space-y-3`,children:Array.from({length:6}).map((e,t)=>(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(rE,{className:`h-8 w-8 rounded-full shrink-0`}),(0,L.jsxs)(`div`,{className:`flex-1 space-y-1.5`,children:[(0,L.jsx)(rE,{className:`h-3.5 w-24`}),(0,L.jsx)(rE,{className:`h-3 w-full`})]})]},t))}):v?(0,L.jsxs)(`div`,{className:`p-6 text-center space-y-3`,children:[(0,L.jsx)(xT,{className:`h-6 w-6 text-destructive mx-auto`}),(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Failed to load`}),y&&(0,L.jsxs)(W,{variant:`outline`,size:`sm`,onClick:y,children:[(0,L.jsx)(Yw,{className:`h-3.5 w-3.5 mr-1.5`}),`Retry`]})]}):e.length===0?(0,L.jsx)(`div`,{className:`p-4 text-center text-sm text-muted-foreground`,children:f?`No conversations match your search`:`No conversations`}):(0,L.jsx)(TR,{virtuosoRef:ee,pinned:re,unpinned:ie,selectedId:n,focusedIndex:m,draftConversationIds:I,pinPendingId:ne.isPending?ne.variables:null,onSelect:(e,t,n
148)=>{h(t),w?D?.(e,t,n?.shiftKey??!1):r(e)},onTogglePin:e=>ne.mutate(e),hasNextPage:x,isFetchingNextPage:S,onEndReached:C,selectMode:w??!1,selectedIds:E})})]})});function TR({virtuosoRef:e,pinned:t,unpinned:n,selectedId:r,focusedIndex:i,draftConversationIds:a,pinPendingId:o,onSelect:s,onTogglePin:c,hasNextPage:l,isFetchingNextPage:u,onEndReached:d,selectMode:f,selectedIds:p}){let{groupCounts:m,groupLabels:h,items:g}=(0,_.useMemo)(()=>{let e=[],r=[],i=[];return t.length>0&&(e.push(t.length),r.push(`Pinned`),i.push(...t)),n.length>0&&(e.push(n.length),r.push(t.length>0?`All conversations`:``),i.push(...n)),{groupCounts:e,groupLabels:r,items:i}},[t,n]);return(0,L.jsx)(nL,{ref:e,className:`h-full`,groupCounts:m,computeItemKey:e=>g[e]?.id??e,endReached:()=>{l&&!u&&d?.()},increaseViewportBy:{top:0,bottom:400},groupContent:e=>{let t=h[e];return t?(0,L.jsx)(OR,{label:t}):(0,L.jsx)(`div`,{className:`h-0`})},itemContent:e=>{let t=g[e];if(!t)return null;let n=a.has(t.id)&&r!==t.id?nR(t.id):null;return(0,L.jsx)(ER,{conversation:t,index:e,isSelected:r===t.id,isFocused:i===e,draftText:n,onSelect:s,onTogglePin:c,isPinPending:o===t.id,selectMode:f,isChecked:p?.has(t.id)??!1})},components:{Footer:()=>u?(0,L.jsxs)(`div`,{className:`flex items-center justify-center py-3 text-xs text-muted-foreground`,children:[(0,L.jsx)(Yw,{className:`h-3.5 w-3.5 animate-spin mr-1.5`}),`Loading more...`]}):null}})}var ER=(0,_.memo)(function({conversation:e,index:t,isSelected:n,isFocused:r,draftText:i,onSelect:a,onTogglePin:o,isPinPending:s,selectMode:c,isChecked:l}){let u=n=>a(e.id,t,n);return(0,L.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:e=>u({shiftKey:e.shiftKey}),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),u({shiftKey:e.shiftKey}))},className:V(`group relative w-full text-left p-3 min-h-11 border-b hover:bg-muted/50 transition-colors cursor-pointer`,n&&`bg-muted`,r&&`ring-2 ring-primary ring-inset`,c&&l&&`bg-primary/10`),children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[c?(0,L.jsx)(`div`,{className:`h-8 w-8 flex items-center justify-center shrink-0`,onClick:e=>e.stopPropagation(),children:(0,L.jsx)(tM,{checked:l,onCheckedChange:()=>u(),"aria-label":l?`Deselect conversation`:`Select conversation`})}):(0,L.jsx)(`div`,{className:V(`h-8 w-8 rounded-full flex items-center justify-center text-xs font-medium shrink-0`,e.type===`group`?`bg-blue-100 text-blue-600`:`bg-primary/10 text-primary`),children:e.type===`group`?(0,L.jsx)(MT,{className:`h-4 w-4`}):NR(e.leadName)}),(0,L.jsxs)(`div`,{className:`min-w-0`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,L.jsx)(`span`,{className:`font-medium text-sm truncate`,children:e.leadName??e.leadPhone??`Unknown`}),(0,L.jsx)(jR,{channel:e.channel}),e.type===`group`&&(0,L.jsx)(`span`,{className:`text-[10px] text-blue-600 font-medium shrink-0`,children:`GROUP`}),e.isSimulation&&(0,L.jsx)(`span`,{className:`text-[10px] text-purple-600 font-medium shrink-0`,children:`SIM`}),e.isSandboxTest&&(0,L.jsx)(`span`,{className:`text-[10px] text-orange-600 font-medium shrink-0`,children:`SANDBOX`})]}),(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.leadPhone??`No phone`})]})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,L.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s||o(e.id)},disabled:s,"aria-label":e.isPinned?`Unpin conversation`:`Pin conversation`,"aria-pressed":e.isPinned,className:V(`h-9 w-9 md:h-6 md:w-6 inline-flex items-center justify-center rounded hover:bg-muted-foreground/10 transition-opacity`,e.isPinned?`opacity-100 text-primary`:`md:opacity-0 md:group-hover:opacity-100 focus:opacity-100 text-muted-foreground`),children:(0,L.jsx)(Uw,{className:V(`h-3.5 w-3.5`,e.isPinned&&`fill-current`)})}),e.flagged&&(0,L.jsx)(kR,{reason:e.flagReason}),(!e.aiEnabled||!e.leadId)&&(0,L.jsx)(jC,{className:`h-3.5 w-3.5 text-orange-500`,"aria-label":e.leadId?`AI off`:`No lead linked`}),e.hasDrafts&&(0,L.jsx)(`span`,{className:`inline-flex items-center justify-center h-5 w-5 rounded-full bg-amber-100 text-amber-700 dark:bg-amber-900/40 dark:text-amber-400`,title:`AI suggestion awaiting review`,"aria-label":`AI suggestion awaiting review`,children:(0,L.jsx)(lT,{className:`h-3 w-3`})}),e.unreadCount>0&&(0,L.jsx)(X,{className:`h-5 min-w-5 text-xs justify-center`,children:e.unreadCount})]})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-1 mt-1 ml-10`,children:[(0,L.jsx)(AR,{type:e.type}),i===null?(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground truncate flex-1`,children:e.lastMessage?.body??`No messages`}):(0,L.jsxs)(`span`,{className:`text-xs truncate flex-1`,children:[(0,L.jsx)(`span`,{className:`text-red-600 font-medium`,children:`Draft: `}),(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:i})]})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-0.5 ml-10`,children:[e.lastMessage&&(0,L.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:PR(e.lastMessage.timestamp)}),e.status===`closed`&&(0,L.jsx)(X,{variant:`secondary`,className:`text-[10px] px-1 py-0`,children:`Closed`}),(0,L.jsx)(MR,{warmth:e.leadWarmth})]})]})});function DR(e){return e>999?`999+`:String(e)}function OR({label:e}){return(0,L.jsx)(`div`,{className:`px-3 pt-3 pb-1 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground bg-background sticky top-0 z-[1]`,children:e})}function kR({reason:e}){return(0,L.jsx)(uw,{className:V(`h-3.5 w-3.5`,{manual:`text-orange-500 fill-orange-500`,bad_ai_reply:`text-red-500 fill-red-500`,ai_stuck:`text-red-500 fill-red-500`,human_escalated:`text-yellow-500 fill-yellow-500`,prompt_injection_suspected:`text-red-600 fill-red-600`,assignment_failed:`text-orange-600 fill-orange-600`}[e??``]??`text-orange-500 fill-orange-500`)})}function AR({type:e}){switch(e){case`group`:return(0,L.jsx)(MT,{className:`h-3 w-3 text-muted-foreground shrink-0`});case`qualification`:return(0,L.jsx)(YC,{className:`h-3 w-3 text-muted-foreground shrink-0`});default:return(0,L.jsx)(Nw,{className:`h-3 w-3 text-muted-foreground shrink-0`})}}function jR({channel:e}){let t=e===`cloud_api`;return(0,L.jsx)(`span`,{className:V(`text-[10px] font-medium shrink-0 rounded px-1 py-px`,t?`bg-emerald-100 text-emerald-700 dark:bg-emerald-900/40 dark:text-emerald-400`:`bg-muted text-muted-foreground`),title:t?`Cloud API number`:`WhatsApp linked device`,children:gR(e)})}function MR({warmth:e}){let t={hot:`bg-red-500`,warm:`bg-orange-500`,cold:`bg-blue-500`};return!e||!t[e]?null:(0,L.jsx)(`span`,{className:V(`h-2 w-2 rounded-full`,t[e])})}function NR(e){return e?e.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2):`?`}function PR(e){let t=Date.now(),n=new Date(e).getTime();if(isNaN(n))return``;let r=t-n;return r<6e4?`just now`:r<36e5?`${Math.floor(r/6e4)}m ago`:r<864e5?`${Math.floor(r/36e5)}h ago`:r<6048e5?`${Math.floor(r/864e5)}d ago`:new Date(e).toLocaleDateString()}var FR=new Intl.DateTimeFormat(`en-SG`,{weekday:`long`}),IR=new Intl.DateTimeFormat(`en-SG`,{month:`short`,day:`numeric`,year:`numeric`});function LR(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function RR(e){let t=LR(new Date),n=LR(e),r=Math.round((t.getTime()-n.getTime())/(1e3*60*60*24));return r===0?`Today`:r===1?`Yesterday`:r>1&&r<7?FR.format(e):IR.format(e)}function zR(e){return(0,_.useSyncExternalStore)(xN,()=>SN(e),()=>({}))}var BR=3e3,VR=5e3;async function HR(e,t){try{await fetch(`/api/messages/typing`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify({conversationId:e,state:t})})}catch{}}function UR(e){let t=(0,_.useRef)(0),n=(0,_.useRef)(null);return(0,_.useEffect)(()=>()=>{t.current=0,n.current!==null&&(window.clearTimeout(n.current),n.current=null)},[e]),{signalTyping:(0,_.useCallback)(()=>{let r=Date.now();r-t.current>=BR&&(t.current=r,HR(e,`composing`)),n.current!==null&&window.clearTimeout(n.current),n.current=window.setTimeout(()=>{n.current=null,t.current=0,HR(e,`paused`)},VR)},[e]),signalStopped:(0,_.useCallback)(()=>{n.current!==null&&(window.clearTimeout(n.current),n.current=null),t.current!==0&&(t.current=0,HR(e,`paused`))},[e]),subscribePresence:(0,_.useCallback)(()=>{HR(e,void 0)},[e])}}function WR(e,t,n){if(!t||t.length===0)return e;let r=e.toLowerCase(),i=t.toLowerCase(),a=[],o=0;for(;o<e.length;){let s=r.indexOf(i,o);if(s===-1){a.push((0,L.jsx)(_.Fragment,{children:e.slice(o)},o));break}s>o&&a.push((0,L.jsx)(_.Fragment,{children:e.slice(o,s)},`t-${o}`)),a.push((0,L.jsx)(`mark`,{className:V(`rounded px-0.5`,n?`bg-yellow-400 text-foreground`:`bg-yellow-200 text-foreground`),children:e.slice(s,s+t.length)},`m-${s}`)),o=s+t.length}return a}
148async function GR(e,t=2,n=250){let r;for(let i=0;i<=t;i++)try{return await e()}catch(e){r=e,i<t&&await new Promise(e=>setTimeout(e,n*(i+1)))}throw r}var KR=(0,_.lazy)(async()=>{let[e,t]=await Promise.all([GR(()=>S(()=>import(`./native-9vIaO2Ji.js`),[])),GR(()=>S(()=>import(`./module-DwlnrV1U.js`),[]))]),n=e.default,r=t.default;return{default:({onSelect:e})=>(0,L.jsx)(r,{data:n,onEmojiSelect:t=>{t.native&&e(t.native)},theme:`light`,previewPosition:`none`,skinTonePosition:`search`,maxFrequentRows:2,perLine:8})}}),qR=(0,L.jsx)(`div`,{className:`rounded-md border bg-popover shadow-md p-4 text-xs text-muted-foreground`,children:`Loading emojisâ¦`}),JR=(0,L.jsxs)(`div`,{className:`flex w-[260px] flex-col items-center gap-2 rounded-md border bg-popover p-4 text-center text-xs text-muted-foreground shadow-md`,children:[(0,L.jsx)(`span`,{children:`Couldn't load emojis. Refresh and try again.`}),(0,L.jsxs)(W,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>window.location.reload(),children:[(0,L.jsx)(Yw,{className:`mr-1.5 h-3.5 w-3.5`}),`Refresh`]})]}),YR=class extends _.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(e){console.error(`[emoji-picker] failed to load emoji chunk:`,e)}render(){return this.state.failed?JR:this.props.children}};function XR({trigger:e,onSelect:t}){let n=KT(),[r,i]=(0,_.useState)(!1);return n?(0,L.jsxs)(YT,{open:r,onOpenChange:i,children:[(0,L.jsx)(XT,{asChild:!0,children:e}),(0,L.jsxs)($T,{side:`bottom`,className:`h-auto max-h-[80vh] p-0 flex flex-col items-center pt-2 pb-[max(0.5rem,env(safe-area-inset-bottom))]`,children:[(0,L.jsx)(tE,{className:`sr-only`,children:`Insert emoji`}),(0,L.jsx)(YR,{children:(0,L.jsx)(_.Suspense,{fallback:qR,children:r&&(0,L.jsx)(KR,{onSelect:e=>{t(e),i(!1)}})})})]})]}):(0,L.jsxs)(wg,{open:r,onOpenChange:i,children:[(0,L.jsx)(Tg,{asChild:!0,children:e}),(0,L.jsx)(Eg,{children:(0,L.jsx)(Dg,{side:`top`,align:`end`,sideOffset:8,className:`z-50`,children:(0,L.jsx)(YR,{children:(0,L.jsx)(_.Suspense,{fallback:qR,children:r&&(0,L.jsx)(KR,{onSelect:t})})})})})]})}var ZR=[`ð`,`â¤ï¸`,`ð`,`ð®`,`ð¢`,`ð`];function QR({onSelect:e,currentEmoji:t,trigger:n}){let[r,i]=(0,_.useState)(!1),a=t=>{e(t),i(!1)};return(0,L.jsxs)(OA,{open:r,onOpenChange:i,children:[(0,L.jsx)(kA,{asChild:!0,children:n}),(0,L.jsx)(AA,{side:`top`,align:`center`,className:`w-auto p-1`,onClick:e=>e.stopPropagation(),children:(0,L.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[ZR.map(e=>(0,L.jsx)(`button`,{type:`button`,onClick:()=>a(e),className:V(`h-8 w-8 rounded text-lg leading-none hover:bg-muted transition-colors`,t===e&&`bg-primary/10 ring-1 ring-primary`),"aria-label":`React with ${e}`,children:e},e)),(0,L.jsx)(XR,{onSelect:a,trigger:(0,L.jsx)(`button`,{type:`button`,className:`h-8 w-8 rounded text-muted-foreground hover:bg-muted transition-colors text-lg leading-none`,"aria-label":`More emojis`,children:`+`})})]})})]})}function $R({url:e,filename:t,onClose:n}){return(0,_.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};window.addEventListener(`keydown`,e);let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{window.removeEventListener(`keydown`,e),document.body.style.overflow=t}},[n]),(0,L.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/90 p-4`,onClick:n,role:`dialog`,"aria-modal":`true`,"aria-label":`Preview of ${t}`,children:[(0,L.jsxs)(`div`,{className:`absolute top-4 right-4 flex items-center gap-2`,children:[(0,L.jsx)(W,{asChild:!0,variant:`secondary`,size:`icon`,"aria-label":`Download image`,onClick:e=>e.stopPropagation(),children:(0,L.jsx)(`a`,{href:e,download:t,target:`_blank`,rel:`noreferrer`,children:(0,L.jsx)(iw,{className:`h-4 w-4`})})}),(0,L.jsx)(W,{variant:`secondary`,size:`icon`,"aria-label":`Close preview`,onClick:n,children:(0,L.jsx)(FT,{className:`h-4 w-4`})})]}),(0,L.jsx)(`img`,{src:e,alt:t,onClick:e=>e.stopPropagation(),className:`max-h-full max-w-full object-contain rounded-lg shadow-2xl`})]})}var ez=[`ð`,`â¤ï¸`,`ð`,`ð®`,`ð¢`,`ð`];function tz(e){return e?e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`:``}var nz=[`text-blue-600`,`text-emerald-600`,`text-purple-600`,`text-orange-600`,`text-pink-600`,`text-teal-600`,`text-red-600`,`text-indigo-600`];function rz(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return nz[Math.abs(t)%nz.length]}var iz=900*1e3;function az({message:e,isGroup:t,highlightText:n,isCurrentMatch:r,onReply:i,onJumpToQuoted:a,pulse:o,onReact:s,onForward:c,onSendDraft:l,onDiscardDraft:u,onRegenerateDraft:d,whatsappConnected:f=!0,onEdit:p,isSimulation:m=!1,draftSendLabel:h=`Send on WA`,draftSendDisabledReason:g,draftSendConnected:v}){let y=g!==void 0,b=e.direction===`outbound`,x=v??f,S=e.contactName?.trim()||null,C=e.contactPhone?.trim()||null,w=S??C,T=t&&!b&&w,E=t&&!b&&S&&C,D=e.reactions??[],O=D.find(e=>e.isMine)?.emoji??null,[k,A]=(0,_.useState)(!1),j=!!e.mediaType,M=e.mediaType===`image`,ee=e.mediaType===`document`||e.mediaType===`audio`||e.mediaType===`video`,N=e.status===`draft`&&(e.source===`ai`||!e.source),P=e.status===`pen
148ding`,F=Date.now()-new Date(e.timestamp).getTime()<iz,I=!!p&&b&&!N&&!j&&(e.status===`sent`||e.status===`delivered`||e.status===`read`)&&F&&(m||!!e.waMessageId&&!e.waMessageId.startsWith(`dry-run-`))&&(m||f),[te,ne]=(0,_.useState)(!1),[re,ie]=(0,_.useState)(e.body),[ae,oe]=(0,_.useState)(null),[se,ce]=(0,_.useState)(null),le=(0,_.useRef)(te);le.current=te,(0,_.useEffect)(()=>{le.current||ie(e.body)},[e.body]);let ue=t=>{s&&(O===t.emoji?s(e.id,``):s(e.id,t.emoji))},de=async()=>{if(!l)return;let t=re.trim();if(t.length===0){ce(`Cannot send an empty draft.`);return}oe(`send`),ce(null);try{let n=t===e.body?void 0:t;await l(e.id,n),ne(!1)}catch(e){ce(e instanceof Error?e.message:`Send failed`)}finally{oe(null)}},fe=async()=>{if(u){oe(`discard`);try{await u(e.id)}catch{oe(null)}}},pe=async()=>{if(d){oe(`regenerate`),ce(null);try{await d(e.id)}catch(e){ce(e instanceof Error?e.message:`Regenerate failed`)}finally{oe(null)}}},me=async()=>{if(!p)return;let t=re.trim();if(t.length===0){ce(`Message can't be empty.`);return}if(t===e.body){ne(!1),ce(null);return}oe(`edit`),ce(null);try{await p(e.id,t),ne(!1)}catch(e){ce(e instanceof Error?e.message:`Edit failed`)}finally{oe(null)}},he=()=>{if(typeof navigator>`u`||!navigator.clipboard){z.error(`Copy not supported`);return}navigator.clipboard.writeText(e.body||``).then(()=>z.success(`Copied`)).catch(()=>z.error(`Copy failed`))};return(0,L.jsxs)(`div`,{className:V(`group flex items-center gap-1 relative`,D.length>0&&`mb-3`,b?`justify-end`:`justify-start`),children:[!N&&b&&(i||c||s||I)&&(0,L.jsx)(sz,{message:e,onReply:i,onForward:c,onReact:s,onCopy:he,onEdit:I&&!te?()=>ne(!0):void 0}),!N&&s&&b&&(0,L.jsx)(oz,{onSelect:t=>s(e.id,t),currentEmoji:O}),I&&!te&&(0,L.jsx)(fz,{onClick:()=>ne(!0)}),!N&&c&&b&&(0,L.jsx)(dz,{onClick:()=>c(e)}),!N&&i&&b&&(0,L.jsx)(uz,{onClick:()=>i(e)}),(0,L.jsxs)(`div`,{className:V(`flex flex-col gap-1`,te?`w-full max-w-[560px]`:`max-w-[85%] lg:max-w-[75%]`),children:[N&&(0,L.jsx)(`div`,{className:V(`flex items-center gap-1 text-[10px] font-medium uppercase tracking-wide`,e.aiGenerationFailed?`text-rose-700 dark:text-rose-400`:`text-amber-700 dark:text-amber-400`,b?`self-end`:`self-start`),children:e.aiGenerationFailed?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(WC,{className:`h-3 w-3`}),(0,L.jsx)(`span`,{children:`AI generation failed · fallback shown · click Regenerate`})]}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(lT,{className:`h-3 w-3`}),(0,L.jsx)(`span`,{children:`AI Suggestion · not yet sent`})]})}),(0,L.jsxs)(`div`,{className:V(`max-w-[100%] rounded-lg px-3 py-2 text-sm transition-shadow`,N?`border-2 border-dashed border-amber-400/70 bg-amber-50 text-foreground dark:bg-amber-950/30 dark:border-amber-500/50`:b?`bg-primary text-primary-foreground`:`bg-muted`,!N&&o&&`ring-2 ring-yellow-400 ring-offset-2 ring-offset-background`,P&&`opacity-70`),children:[T&&(0,L.jsxs)(`p`,{className:V(`text-xs font-medium mb-0.5`,rz(w)),children:[w,E&&(0,L.jsxs)(`span`,{className:`ml-1 font-normal opacity-75`,children:[`· `,C]})]}),e.isForwarded&&(0,L.jsxs)(`p`,{className:V(`flex items-center gap-1 text-[10px] italic mb-0.5 opacity-70`,b&&!N?`text-primary-foreground`:`text-muted-foreground`),children:[(0,L.jsx)(pw,{className:`h-2.5 w-2.5`}),`Forwarded`]}),e.quotedMessage&&(0,L.jsx)(pz,{quoted:e.quotedMessage,parentIsOutbound:b&&!N,onJumpToQuoted:a}),j&&M&&(0,L.jsx)(mz,{url:e.mediaUrl??null,filename:e.mediaFilename??`image`,onOpen:()=>A(!0)}),j&&ee&&(0,L.jsx)(hz,{url:e.mediaUrl??null,filename:e.mediaFilename??`file`,mime:e.mediaMime??`application/octet-stream`,sizeBytes:e.mediaSizeBytes??null,isOutbound:b&&!N}),te?(0,L.jsx)(TD,{value:re,onChange:e=>ie(e.target.value),autoFocus:!0,rows:Math.min(12,Math.max(3,re.split(` 149`).reduce((e,t)=>e+Math.max(1,Math.ceil(t.length/60)),0))),className:V(`resize-y min-h-[80px] text-sm`,N?`border-amber-400/40 bg-background/80 focus-visible:ring-amber-500/50`:`border-input bg-background text-foreground`),"aria-label":N?`Edit AI draft`:`Edit message`}):e.body.length>0&&(0,L.jsx)(`p`,{className:`whitespace-pre-wrap break-words`,children:WR(N?re:e.body,n,r)}),(0,L.jsxs)(`div`,{className:V(`flex items-center justify-end gap-1 mt-1`,N?`text-amber-700 dark:text-amber-400`:b?`text-primary-foreground
149/70`:`text-muted-foreground`),children:[e.editedAt&&!N&&(0,L.jsx)(`span`,{className:`text-[10px] italic opacity-80`,children:`Edited`}),(0,L.jsx)(`span`,{className:`text-[10px]`,children:new Date(e.timestamp).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}),b&&!N&&(0,L.jsx)(_z,{status:e.status})]})]}),b&&!N&&e.status===`failed`&&(0,L.jsxs)(`div`,{className:`flex items-center gap-1 self-end text-[11px] text-destructive`,title:bR(e.rawPayload)?.details??void 0,children:[(0,L.jsx)(WC,{className:`h-3 w-3 shrink-0`}),(0,L.jsx)(`span`,{children:xR(e.rawPayload)})]}),N&&(0,L.jsx)(`div`,{className:V(`flex flex-wrap items-center gap-1.5`,b?`self-end justify-end`:`self-start justify-start`),children:te?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(W,{type:`button`,size:`sm`,variant:`default`,className:`h-7 px-2 text-xs`,onClick:()=>ne(!1),disabled:ae!==null,children:[(0,L.jsx)(RC,{className:`h-3 w-3 mr-1`}),`Save`]}),(0,L.jsxs)(W,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 px-2 text-xs`,onClick:()=>{ie(e.body),ne(!1)},disabled:ae!==null,children:[(0,L.jsx)(FT,{className:`h-3 w-3 mr-1`}),`Cancel`]})]}):(0,L.jsxs)(L.Fragment,{children:[l&&(0,L.jsxs)(tx,{children:[(0,L.jsx)(nx,{asChild:!0,children:(0,L.jsx)(`span`,{className:`inline-block`,children:(0,L.jsxs)(W,{type:`button`,size:`sm`,variant:y?`outline`:`default`,className:V(`h-7 px-2.5 text-xs`,!y&&`bg-emerald-600 hover:bg-emerald-700 text-white`),onClick:de,disabled:ae!==null||P||!x||y,children:[ae===`send`?(0,L.jsx)(Ew,{className:`h-3 w-3 mr-1 animate-spin`}):y?(0,L.jsx)(WC,{className:`h-3 w-3 mr-1`}):(0,L.jsx)(eT,{className:`h-3 w-3 mr-1`}),h]})})}),(0,L.jsx)(rx,{className:`max-w-xs`,children:g??(x?`Send this message via WhatsApp`:`WhatsApp is disconnected - reconnect on the Connect page to send`)})]}),(0,L.jsxs)(W,{type:`button`,size:`sm`,variant:`outline`,className:`h-7 px-2 text-xs`,onClick:()=>ne(!0),disabled:ae!==null||P,children:[(0,L.jsx)(Bw,{className:`h-3 w-3 mr-1`}),`Edit`]}),d&&(0,L.jsxs)(W,{type:`button`,size:`sm`,variant:`outline`,className:`h-7 px-2 text-xs`,onClick:pe,disabled:ae!==null||P,children:[ae===`regenerate`?(0,L.jsx)(Ew,{className:`h-3 w-3 mr-1 animate-spin`}):(0,L.jsx)(Zw,{className:`h-3 w-3 mr-1`}),`Regenerate`]}),u&&(0,L.jsxs)(W,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 px-2 text-xs text-muted-foreground hover:text-destructive`,onClick:fe,disabled:ae!==null||P,children:[ae===`discard`?(0,L.jsx)(Ew,{className:`h-3 w-3 mr-1 animate-spin`}):(0,L.jsx)(vT,{className:`h-3 w-3 mr-1`}),`Discard`]})]})}),!N&&b&&te&&(0,L.jsxs)(`div`,{className:V(`flex flex-wrap items-center gap-1.5`,b?`self-end justify-end`:`self-start justify-start`),children:[(0,L.jsxs)(W,{type:`button`,size:`sm`,variant:`default`,className:`h-7 px-2 text-xs`,onClick:me,disabled:ae!==null,children:[ae===`edit`?(0,L.jsx)(Ew,{className:`h-3 w-3 mr-1 animate-spin`}):(0,L.jsx)(RC,{className:`h-3 w-3 mr-1`}),`Save`]}),(0,L.jsxs)(W,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 px-2 text-xs`,onClick:()=>{ie(e.body),ne(!1),ce(null)},disabled:ae!==null,children:[(0,L.jsx)(FT,{className:`h-3 w-3 mr-1`}),`Cancel`]})]}),se&&(0,L.jsx)(`p`,{className:V(`text-[11px] text-destructive`,b?`self-end`:`self-start`),children:se})]}),!N&&i&&!b&&(0,L.jsx)(uz,{onClick:()=>i(e)}),!N&&c&&!b&&(0,L.jsx)(dz,{onClick:()=>c(e)}),!N&&s&&!b&&(0,L.jsx)(oz,{onSelect:t=>s(e.id,t),currentEmoji:O}),!N&&!b&&(i||c||s)&&(0,L.jsx)(sz,{message:e,onReply:i,onForward:c,onReact:s,onCopy:he}),M&&k&&e.mediaUrl&&(0,L.jsx)($R,{url:e.mediaUrl,filename:e.mediaFilename??`image`,onClose:()=>A(!1)}),D.length>0&&(0,L.jsx)(`div`,{className:V(`flex flex-wrap gap-0.5 absolute -bottom-2.5`,b?`right-2`:`left-2`,`pointer-events-auto`),children:D.map(e=>(0,L.jsx)(cz,{pill:e,onClick:()=>ue(e),clickable:!!s},e.emoji))})]})}function oz({onSelect:e,currentEmoji:t}){return(0,L.jsx)(QR,{onSelect:e,currentEmoji:t??void 0,trigger:(0,L.jsx)(W,{type:`button`,variant:`ghost`,size:`icon`,className:`hidden lg:inline-flex h-6 w-6 opacity-0 group-hover:opacity-100 transition-opacity text-muted-foreground hover:text-foreground`,"aria-label":`Add reaction`,children:(0,L.jsx)(oT,{className:`h-3.5 w-3.5`})})})}function sz({message:e,onReply:t,onForward:n,onReact:r,onCopy:i,onEdit:a}){let[o,s]=(0,_.useState)(!1);return(0,L.jsxs)(Uj,{open:o,onOpenChange:s,children:[(0,L.jsx)(Wj,{asChild:!0,children:(0,L.jsx)(W,{type:`button`,variant:`ghost`,size:`icon`,className:`lg:hidden h-9 w-9 shrink-0 text-muted-foreground
149/60 hover:text-foreground self-center`,"aria-label":`Message actions`,children:(0,L.jsx)(aw,{className:`h-4 w-4`})})}),(0,L.jsxs)(Gj,{align:`end`,className:`w-56`,children:[r&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`div`,{className:`flex items-center justify-between gap-0.5 px-1 py-1`,children:ez.map(t=>(0,L.jsx)(`button`,{type:`button`,onClick:()=>{r(e.id,t),s(!1)},className:`h-9 w-9 rounded text-lg leading-none hover:bg-muted transition-colors`,"aria-label":`React with ${t}`,children:t},t))}),(0,L.jsx)(Jj,{})]}),t&&(0,L.jsxs)(Kj,{onClick:()=>t(e),children:[(0,L.jsx)(nw,{className:`h-4 w-4 mr-2`}),`Reply`]}),n&&(0,L.jsxs)(Kj,{onClick:()=>n(e),children:[(0,L.jsx)(pw,{className:`h-4 w-4 mr-2`}),`Forward`]}),a&&(0,L.jsxs)(Kj,{onClick:()=>{a(),s(!1)},children:[(0,L.jsx)(Bw,{className:`h-4 w-4 mr-2`}),`Edit`]}),(0,L.jsxs)(Kj,{onClick:i,disabled:!e.body,children:[(0,L.jsx)(ew,{className:`h-4 w-4 mr-2`}),`Copy`]})]})]})}function cz({pill:e,onClick:t,clickable:n}){let r=e.senders.map(e=>e.name??lz(e.jid)).join(`, `);return(0,L.jsxs)(`button`,{type:`button`,onClick:t,disabled:!n,title:r,className:V(`inline-flex items-center gap-0.5 rounded-full border bg-background text-[11px] px-1.5 py-0.5 shadow-sm`,e.isMine?`border-primary/50 bg-primary/10 text-primary`:`border-muted hover:bg-muted`,n?`cursor-pointer`:`cursor-default`),"aria-label":e.isMine?`Remove ${e.emoji} reaction`:`Add ${e.emoji} reaction`,children:[(0,L.jsx)(`span`,{children:e.emoji}),e.count>1&&(0,L.jsx)(`span`,{children:e.count})]})}function lz(e){let t=e.replace(/@.*/,``).replace(/[^\d]/g,``);return t.length===0?e.slice(0,6):`â¦${t.slice(-4)}`}function uz({onClick:e}){return(0,L.jsx)(W,{type:`button`,variant:`ghost`,size:`icon`,onClick:e,className:`hidden lg:inline-flex h-6 w-6 opacity-0 group-hover:opacity-100 transition-opacity text-muted-foreground hover:text-foreground`,"aria-label":`Reply to message`,children:(0,L.jsx)(nw,{className:`h-3.5 w-3.5`})})}function dz({onClick:e}){return(0,L.jsx)(W,{type:`button`,variant:`ghost`,size:`icon`,onClick:e,className:`hidden lg:inline-flex h-6 w-6 opacity-0 group-hover:opacity-100 transition-opacity text-muted-foreground hover:text-foreground`,"aria-label":`Forward message`,children:(0,L.jsx)(pw,{className:`h-3.5 w-3.5`})})}function fz({onClick:e}){return(0,L.jsx)(W,{type:`button`,variant:`ghost`,size:`icon`,onClick:e,className:`hidden lg:inline-flex h-6 w-6 opacity-0 group-hover:opacity-100 transition-opacity text-muted-foreground hover:text-foreground`,"aria-label":`Edit message`,children:(0,L.jsx)(Bw,{className:`h-3.5 w-3.5`})})}function pz({quoted:e,parentIsOutbound:t,onJumpToQuoted:n}){let r=e.available&&e.id!==null&&n,i=e.direction===`outbound`?`You`:e.contactName??`Contact`,a=(0,L.jsxs)(`div`,{className:`min-w-0`,children:[(0,L.jsx)(`p`,{className:V(`text-[10px] font-medium mb-0.5`,t?`text-primary-foreground/80`:`text-muted-foreground`),children:i}),(0,L.jsx)(`p`,{className:V(`text-xs line-clamp-2 break-words`,t?`text-primary-foreground/70`:`text-muted-foreground`),children:e.body||`(no text)`})]}),o=V(`border-l-2 pl-2 mb-1 rounded-sm`,t?`border-primary-foreground/40 bg-primary-foreground/10`:`border-foreground
149/30 bg-background/50`,r&&`cursor-pointer hover:opacity-80 transition-opacity`);return r?(0,L.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),n(e.id)},className:V(o,`block text-left w-full`),"aria-label":`Jump to quoted message`,children:a}):(0,L.jsx)(`div`,{className:o,children:a})}function mz({url:e,filename:t,onOpen:n}){let[r,i]=(0,_.useState)(!1);return!e||r?(0,L.jsx)(gz,{filename:t}):(0,L.jsx)(`button`,{type:`button`,onClick:n,className:`block rounded-md overflow-hidden mb-1 max-w-[280px] hover:opacity-90 transition-opacity`,"aria-label":`Open ${t} in fullscreen`,children:(0,L.jsx)(`img`,{src:e,alt:t,onError:()=>i(!0),className:`block max-h-[240px] w-full object-cover`})})}function hz({url:e,filename:t,mime:n,sizeBytes:r,isOutbound:i}){return e?(0,L.jsxs)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,download:t,className:V(`flex items-center gap-2 rounded-md border px-2 py-2 mb-1 hover:bg-foreground/5 transition-colors max-w-[280px]`,i?`border-primary-foreground/30 bg-primary-foreground/10`:`border-border bg-background/60`),children:[(0,L.jsx)(lw,{className:V(`h-6 w-6 shrink-0`,i?`text-primary-foreground`:`text-muted-foreground`)}),(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsx)(`p`,{className:`truncate text-xs font-medium`,children:t}),(0,L.jsxs)(`p`,{className:V(`text-[10px]`,i?`text-primary-foreground/70`:`text-muted-foreground`),children:[n.replace(`application/`,``).toUpperCase(),r!=null&&r>0&&` ⢠${tz(r)}`]})]}),(0,L.jsx)(iw,{className:V(`h-4 w-4 shrink-0`,i?`text-primary-foreground/80`:`text-muted-foreground`)})]}):(0,L.jsx)(gz,{filename:t})}function gz({filename:e}){return(0,L.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border border-destructive/30 bg-destructive/10 px-2 py-2 mb-1 text-xs max-w-[280px]`,children:[(0,L.jsx)(WC,{className:`h-4 w-4 shrink-0 text-destructive`}),(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsx)(`p`,{className:`font-medium`,children:`Media unavailable`}),(0,L.jsx)(`p`,{className:`truncate text-[10px] text-muted-foreground`,children:e})]})]})}function _z({status:e}){switch(e){case`sent`:return(0,L.jsx)(`span`,{className:`text-[10px]`,children:`â`});case`delivered`:return(0,L.jsx)(`span`,{className:`text-[10px]`,children:`ââ`});case`read`:return(0,L.jsx)(`span`,{className:`text-[10px] text-blue-400`,children:`ââ`});case`failed`:return(0,L.jsx)(`span`,{className:`text-[10px] text-red-400`,children:`â`});case`pending`:return(0,L.jsx)(`span`,{className:`text-[10px] opacity-50`,children:`â¯`});default:return null}}function vz(e,t){return t?e.filter(e=>e.status!==`draft`):e}function yz(e,t,n){return n?e.filter(e=>!t.has(e.id)):e}function bz(e,t){return e===``&&t===`/`}function xz(e){return!!(e.length===0||!e.startsWith(`/`)||/\s/.test(e))}function Sz(e,t){switch(e){case`ArrowDown`:return{action:`move-down`};case`ArrowUp`:return{action:`move-up`};case`Enter`:case`Tab`:return t>0?{action:`select`}:{action:`close`};case`Escape`:return{action:`close`};default:return{action:`none`}}}function Cz(e,t){return t<=0||e<0?0:e>=t?t-1:e}function wz(e,t){return t?e.filter(e=>e.name.startsWith(t)):e}var Tz=6;function Ez({query:e,macros:t,highlightedIndex:n,onHighlightChange:r,onSelect:i}){let a=(0,_.useMemo)(()=>wz(t,e),[t,e]);return(0,_.useEffect)(()=>{n>=a.length&&a.length>0?r(a.length-1):a.length===0&&n!==0&&r(0)},[a.length,n,r]),(0,L.jsx)(`div`,{className:`absolute left-0 right-0 bottom-full mb-2 z-20 rounded-md border bg-popover shadow-md`,role:`presentation`,children:a.length===0?(0,L.jsx)(`div`,{className:`px-3 py-2 text-sm text-muted-foreground`,role:`status`,children:`No matches`}):(0,L.jsx)(`ul`,{id:`macro-picker-listbox`,role:`listbox`,"aria-label":`Text macro shortcuts`,className:`overflow-y-auto`,style:{maxHeight:`${Tz*56}px`},children:a.map((e,t)=>(0,L.jsx)(`li`,{children:(0,L.jsxs)(`button`,{id:`macro-row-${t}`,type:`button`,role:`option`,"aria-selected":t===n,onMouseEnter:()=>r(t),onMouseDown:t=>{t.preventDefault(),i(e)},className:V(`w-full text-left px-3 py-2 hover:bg-muted block`,t===n&&`bg-muted`),children:[(0,L.jsxs)(`div`,{className:`font-mono font-medium text-sm`,children:[`/`,e.name]}),e.description?(0,L.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:e.description}):(0,L.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`â`})]})},e.id))})})}var Dz=()=>new Intl.DateTimeFormat(`en-SG`,{timeZone:`Asia/Singapore`,day:`numeric`,month:`short`,year:`numeric`}).format(new Date),Oz=[{token:`lead.name`,label:`Lead â full name`,description:`The lead's full name as stored on the row.`,getValue:e=>e.lead?.name?.trim()||null},{token:`lead.firstName`,label:`Lead â first name`,description:`First word of the lead's full name.`,getValue:e=>e.lead?.name?.trim().split(/\s+/)[0]||null},{token:`lead.source`,label:`Lead â source`,description:`Where the lead came from (e.g. Article Author).`,getValue:e=>e.lead?.source?.trim()||null},{token:`agent.name`,label:`Assigned agent â name`,description:`Name of the agent assigned to this lead.`,getValue:e=>e.agent?.name?.trim()||null},{token:`today`,label:`Today's date (SGT)`,description:`Today's date in Singapore time, e.g. 28 May 2026.`,getValue:()=>Dz()}],kz=new Map(Oz.map(e=>[e.token,e])),Az=/\{\{([^{}]+?)\}\}/g;function jz(e,t){let n=[],r=[],i=e.replace(Az,(e,i)=>{let a=i.trim(),o=kz.get(a);if(!o)return n.includes(a)||n.push(a),``;let s=o.getValue(t);return s==null||s===``?(r.includes(a)||r.push(a),``):s});return n.length>0||r.length>0?{ok:!1,missing:r,unknown:n}:{ok:!0,text:i}}function Mz(e){let t=[];for(let n of e.matchAll(Az)){let e=n[1].trim();t.includes(e)||t.push(e)}return t}function Nz(e){return kz.has(e)}
149var Pz={lead:{id:`sample-lead`,name:`Sarah Tan`,phone:`+6591234567`,email:null,source:`Article Author`,warmth:`warm`,status:`contacted`,qualificationMode:null,qualificationData:null,assignedAgentId:null,assignedAgentName:null,extraColumns:null,sheetDate:null,nextFollowUpAt:null,scheduleSource:null,scheduleReason:null,followUpCount:0,qualificationNudgeCount:0,lastContactedAt:null,createdAt:new Date(0).toISOString()},agent:{id:`sample-agent`,name:`Daniel Lim`,phone:null,isGroup:!1,specialties:null,languages:null,propertyTypes:null,districts:null}},Fz=`stackedhomes.lastConversationId`,Iz=[`image/jpeg`,`image/png`,`image/webp`,`application/pdf`],Lz=16*1024*1024,Rz=Iz.join(`,`);function zz(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Bz({conversationId:e,disabled:t,disabledLabel:n=`This conversation is closed`,disabledAction:r,onTyping:i,onTypingStopped:a,replyingTo:o,onClearReply:s}){let c=GT(),[l,u,d]=iR(e),[f,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(null),g=(0,_.useRef)(null),v=(0,_.useRef)(null),y=(0,_.useRef)(null),b=ri();(0,_.useEffect)(()=>()=>{m&&URL.revokeObjectURL(m)},[m]);let[x,S]=(0,_.useState)(!1),[C,w]=(0,_.useState)(0),[T,E]=(0,_.useState)(e);if(T!==e){E(e),m&&URL.revokeObjectURL(m),p(null),h(null),S(!1),w(0);try{window.localStorage.setItem(Fz,e)}catch{}}let D=vi({queryKey:[`macros`],queryFn:async()=>(await H(`/api/macros`)).data,staleTime:0,refetchOnWindowFocus:!0}),O=vi({queryKey:[`conversation-details`,e],queryFn:()=>H(`/api/messages/conversations/${e}/details`).then(e=>e.data)}),k=O.data?.lead??null,A=O.data?.agent??null,j=x&&l.startsWith(`/`)?l.slice(1).toLowerCase():``;(0,_.useEffect)(()=>{let e=window.visualViewport;if(!e)return;let t=()=>{if(!y.current)return;let t=Math.max(0,window.innerHeight-e.height-e.offsetTop);y.current.style.setProperty(`padding-bottom`,`max(0.75rem, calc(0.75rem + ${t}px))`)};return t(),e.addEventListener(`resize`,t),e.addEventListener(`scroll`,t),()=>{e.removeEventListener(`resize`,t),e.removeEventListener(`scroll`,t)}},[]);let M=R({mutationFn:t=>H(`/api/messages/send`,{method:`POST`,body:JSON.stringify({conversationId:e,body:t.body,quotedMessageId:t.quotedMessageId})}),onSuccess:()=>{d(),a?.(),s?.(),b.invalidateQueries({queryKey:[`messages`,e]}),b.invalidateQueries({queryKey:[`conversations`]}),g.current&&(g.current.style.height=`auto`)},onError:e=>{z.error(e.message||`Failed to send. Try again.`)}}),ee=R({mutationFn:async t=>{let n=new FormData;n.append(`conversationId`,e),n.append(`file`,t.file),t.caption&&n.append(`caption`,t.caption),t.quotedMessageId&&n.append(`quotedMessageId`,t.quotedMessageId);let r=await fetch(`/api/messages/send-media`,{method:`POST`,credentials:`include`,body:n});if(r.status===401)throw window.location.href=`/login`,Error(`Session expired`);let i=await r.json().catch(()=>({}));if(!r.ok||!i.success)throw Error(i.error??`Upload failed: ${r.status}`);return i},onSuccess:()=>{d(),a?.(),s?.(),p(null),h(e=>(e&&URL.revokeObjectURL(e),null)),v.current&&(v.current.value=``),b.invalidateQueries({queryKey:[`messages`,e]}),b.invalidateQueries({queryKey:[`conversations`]}),g.current&&(g.current.style.height=`auto`)},onError:e=>{z.error(e.message||`Failed to send attachment`)}}),N=e=>{let t=e.target.files?.[0];if(e.target.value=``,t){if(!Iz.includes(t.type)){z.error(`Unsupported file type: ${t.type||`unknown`}. Use JPEG, PNG, WebP, or PDF.`);return}if(t.size>Lz){z.error(`File is ${zz(t.size)} â max ${zz(Lz)}.`);return}p(t),h(e=>(e&&URL.revokeObjectURL(e),t.type.startsWith(`image/`)?URL.createObjectURL(t):null))}},P=()=>{p(null),h(e=>(e&&URL.revokeObjectURL(e),null)),v.current&&(v.current.value=``)},F=M.isPending||ee.isPending,I=(0,_.useCallback)(()=>{if(F)return;let e=l.trim();if(f){let t=yR(e);if(!t.ok){z.error(t.message);return}ee.mutate({file:f,caption:e,quotedMessageId:o?.id??null});return}e&&M.mutate({body:e,quotedMessageId:o?.id??null})},[l,f,M,ee,o,F]),te=(0,_.useCallback)(e=>{let t=jz(e.body,{lead:k,agent:A});if(!t.ok){let n=[];t.unknown.length&&n.push(`unknown ${t.unknown.map(e=>`{{${e}}}`).join(`, `)}`),t.missing.length&&n.push(`missing ${t.missing.map(e=>`{{${e}}}`).join(`, `)}`),z.error(`Cannot expand /${e.name}: ${n.join(`; `)}`);return}if(f&&t.text.length>1024){z.error(`Macro /${e.name} expands to ${t.text.length} chars; captions are limited to ${vR}.`);return}u(t.text),S(!1),w(0);let n=g.current;requestAnimationFrame(()=>{if(!n)return;n.focus();let e=t.text.length;n.setSelectionRange(e,e),n.style.height=`auto`,n.style.height=Math.min(n.scrollHeight,120)+`px`,t.text.trim().length>0&&i?.()})},[k,A,f,u,i]),ne=e=>{if(!(e.nativeEvent.isComposing||e.keyCode===229)){if(x){let t=wz(D.data??[],j);switch(Sz(e.key,t.length).action){case`move-down`:e.preventDefault(),w(e=>Cz(e+1,t.length));return;case`move-up`:e.preventDefault(),w(e=>Cz(e-1,t.length));return;case`select`:{e.preventDefault(),e.stopPropagation();let n=t[C];n&&te(n);return}case`close`:e.preventDefault(),S(!1);return;default:break}}c||e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),I())}},re=e=>{let t=l,n=e.target.value;u(n),n.trim().length>0&&i?.(),x?xz(n)&&(S(!1),w(0)):bz(t,n)&&(S(!0),w(0));let r=e.target;r.style.height=`auto`,r.style.height=Math.min(r.scrollHeight,120)+`px`},ie=(0,_.useCallback)(e=>{let t=g.current;if(!t){u(l+e);return}let n=t.selectionStart??l.length,r=t.selectionEnd??l.length;u(l.slice(0,n)+e+l.slice(r)),requestAnimationFrame(()=>{t.focus();let r=n+e.length;t.setSelectionRange(r,r),t.style.height=`auto`,t.style.height=Math.min(t.scrollHeight,120)+`px`})},[l,u]);return(0,L.jsxs)(`div`,{ref:y,className:`border-t p-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[t?(0,L.jsxs)(`div`,{className:`text-center text-sm text-muted-foreground py-2`,children:[n,r&&(0,L.jsx)(`div`,{className:`mt-2 flex justify-center`,children:r})]}):(0,L.jsxs)(`div`,{className:V(`flex flex-col gap-2`),children:[o&&(0,L.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border-l-2 border-primary bg-muted/70 px-3 py-2 text-xs`,children:[(0,L.jsx)(nw,{className:`h-3.5 w-3.5 text-primary shrink-0 mt-0.5`}),(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsx)(`p`,{className:`font-medium text-primary mb-0.5`,children:o.direction===`outbound`?`Replying to yourself`:`Replying to ${o.contactName??`contact`}`}),(0,L.jsx)(`p`,{className:`text-muted-foreground line-clamp-2 break-words`,children:o.body||`(no text)`})]}),(0,L.jsx)(W,{type:`button`,variant:`ghost`,size:`icon`,onClick:s,className:`h-6 w-6 shrink-0 text-muted-foreground`,"aria-label":`Cancel reply`,children:(0,L.jsx)(FT,{className:`h-3.5 w-3.5`})})]}),f&&(0,L.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border bg-muted/50 px-2 py-2 text-xs`,children:[m?(0,L.jsx)(`img`,{src:m,alt:f.name,className:`h-10 w-10 rounded object-cover shrink-0`}):(0,L.jsx)(lw,{className:`h-8 w-8 shrink-0 text-muted-foreground`}),(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsx)(`p`,{className:`truncate font-medium`,children:f.name}),(0,L.jsx)(`p`,{className:`text-muted-foreground`,children:zz(f.size)})]}),(0,L.jsx)(W,{type:`button`,variant:`ghost`,size:`icon`,onClick:P,disabled:F,className:`h-6 w-6 shrink-0 text-muted-foreground`,"aria-label":`Remove attachment`,children:(0,L.jsx)(FT,{className:`h-3.5 w-3.5`})})]}),(0,L.jsx)(`input`,{ref:v,type:`file`,accept:Rz,onChange:N,className:`hidden`}),(0,L.jsxs)(`div`,{className:`relative flex items-end gap-2`,children:[x&&D.data&&(0,L.jsx)(Ez,{query:j,macros:D.data,highlightedIndex:C,onHighlightChange:w,onSelect:te}),(0,L.jsx)(TD,{ref:g,placeholder:f?`Add a caption (optional)...`:`Type a message...`,value:l,onCh
149ange:re,onKeyDown:ne,className:`min-h-[40px] max-h-[120px] resize-none`,rows:1,disabled:F,role:`combobox`,"aria-expanded":x,"aria-controls":x?`macro-picker-listbox`:void 0,"aria-activedescendant":x?`macro-row-${C}`:void 0,"aria-autocomplete":`list`}),(0,L.jsx)(W,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>v.current?.click(),disabled:F||!!f,className:`shrink-0 h-11 w-11 text-muted-foreground`,"aria-label":`Attach file`,children:f?(0,L.jsx)(yw,{className:`h-5 w-5`}):(0,L.jsx)(zw,{className:`h-5 w-5`})}),(0,L.jsx)(XR,{onSelect:ie,trigger:(0,L.jsx)(W,{type:`button`,variant:`ghost`,size:`icon`,disabled:F,className:`shrink-0 h-11 w-11 text-muted-foreground`,"aria-label":`Insert emoji`,children:(0,L.jsx)(sT,{className:`h-5 w-5`})})}),(0,L.jsx)(W,{size:`icon`,onClick:I,disabled:!l.trim()&&!f||F,className:`shrink-0 h-11 w-11`,children:(0,L.jsx)(eT,{className:`h-4 w-4`})})]})]}),M.isError&&(0,L.jsx)(`p`,{className:`text-xs text-destructive mt-1`,children:`Failed to send. Try again.`})]})}function Vz({label:e}){return(0,L.jsx)(`div`,{className:`flex justify-center pointer-events-none py-2`,children:(0,L.jsx)(`span`,{className:`pointer-events-auto rounded-full bg-muted/80 backdrop-blur px-3 py-1 text-xs font-medium text-muted-foreground shadow-sm`,children:e})})}function Hz({visible:e,unreadCount:t,onClick:n}){let r=t>0?`${t} new message${t===1?``:`s`}`:null;return(0,L.jsx)(`div`,{className:V(`pointer-events-none absolute inset-x-0 bottom-3 z-10 flex justify-center`,`transition-opacity duration-150 ease-out`,e?`opacity-100`:`opacity-0`),"aria-hidden":!e,children:(0,L.jsxs)(`button`,{type:`button`,onClick:n,tabIndex:e?0:-1,"aria-label":t>0?`Jump to latest, ${r}`:`Jump to latest message`,className:V(`pointer-events-auto inline-flex items-center gap-1.5 rounded-full`,`bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground`,`shadow-md transition-colors hover:bg-primary/90`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50`),children:[(0,L.jsx)(zC,{className:`h-3.5 w-3.5`}),r&&(0,L.jsx)(`span`,{children:r})]})})}function Uz({value:e,onChange:t,currentIndex:n,totalMatches:r,isLoading:i,onPrev:a,onNext:o,onClose:s}){let c=(0,_.useRef)(null);(0,_.useEffect)(()=>{c.current?.focus(),c.current?.select()},[]);let l=e.trim().length>=2?i&&r===0?`Searchingâ¦`:r===0?`No matches`:`${n} of ${r}`:null;return(0,L.jsxs)(`div`,{className:`flex items-center gap-2 px-4 h-10 border-b bg-background`,children:[(0,L.jsx)(G,{ref:c,value:e,onChange:e=>t(e.target.value),onKeyDown:e=>{e.key===`Escape`?(e.preventDefault(),s()):e.key===`Enter`&&(e.preventDefault(),e.shiftKey?a():o())},placeholder:`Search in conversationâ¦`,className:`h-7 text-sm flex-1 max-w-md`,"aria-label":`Search in conversation`}),l&&(0,L.jsxs)(`span`,{className:`text-xs text-muted-foreground tabular-nums shrink-0 flex items-center gap-1`,children:[i&&(0,L.jsx)(Yw,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}),l]}),(0,L.jsx)(W,{variant:`ghost`,size:`icon`,onClick:a,disabled:r===0,className:`h-7 w-7 shrink-0`,"aria-label":`Previous match`,children:(0,L.jsx)(HC,{className:`h-4 w-4`})}),(0,L.jsx)(W,{variant:`ghost`,size:`icon`,onClick:o,disabled:r===0,className:`h-7 w-7 shrink-0`,"aria-label":`Next match`,children:(0,L.jsx)(zC,{className:`h-4 w-4`})}),(0,L.jsx)(W,{variant:`ghost`,size:`icon`,onClick:s,className:`h-7 w-7 shrink-0`,"aria-label":`Close search`,children:(0,L.jsx)(FT,{className:`h-4 w-4`})})]})}var Wz=3;function Gz({conversation:e,presence:t,messages:n}){let r=Object.entries(t);if(r.length===0)return null;let i=e.type===`group`,a=r.filter(([,e])=>e.state===`composing`||e.state===`recording`).map(([e,t])=>({jid:e,state:t.state}));if(i){if(a.length===0)return null;let e=a.slice(0,Wz).map(e=>qz(e.jid,n)),t;return t=a.length===1?`${e[0]} is typing`:a.length<=Wz?`${e.slice(0,-1).join(`, `)} and ${e[e.length-1]} are typing`:`${a.length} people are typing`,(0,L.jsxs)(`span`,{className:`text-xs text-muted-foreground inline-flex items-center gap-1`,children:[(0,L.jsx)(`span`,{children:t}),(0,L.jsx)(Kz,{})]})}let[,o]=r[0];return o.state===`composing`?(0,L.jsxs)(`span`,{className:`text-xs text-emerald-600 inline-flex items-center gap-1`,children:[(0,L.jsx)(`span`,{children:`typing`}),(0,L.jsx)(Kz,{})]}):o.state===`recording`?(0,L.jsxs)(`span`,{className:`text-xs text-emerald-600 inline-flex items-center gap-1`,children:[(0,L.jsx)(`span`,{children:`recording audio`}),(0,L.jsx)(Kz,{})]}):o.state===`available`?(0,L.jsx)(`span`,{className:`text-xs text-emerald-600`,children:`online`}):o.state===`unavailable`&&o.lastSeen?(0,L.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`last seen `,(0,L.jsx)(Yz,{seconds:o.lastSeen})]}):null}function Kz(){return(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,"aria-hidden":`true`,children:[(0,L.jsx)(`span`,{className:`h-1 w-1 rounded-full bg-current animate-bounce [animation-delay:-0.3s]`}),(0,L.jsx)(`span`,{className:`h-1 w-1 rounded-full bg-current animate-bounce [animation-delay:-0.15s]`}),(0,L.jsx)(`span`,{className:`h-1 w-1 rounded-full bg-current animate-bounce`})]})}function qz(e,t){let n=e.replace(/@.*/,``).replace(/[^\d]/g,``);if(n.length===0)return`Someone`;for(let e=t.length-1;e>=0;e--){let r=t[e];if(!r.contactPhone)continue;let i=r.contactPhone.replace(/[^\d]/g,``);if(i.length!==0&&(n.endsWith(i)||i.endsWith(n))&&r.contactName)return Jz(r.contactName)}return`â¦${n.slice(-4)}`}function Jz(e){return e.trim().split(/\s+/)[0]??e}function Yz({seconds:e}){let[t,n]=(0,_.useState)(()=>Date.now());(0,_.useEffect)(()=>{let e=window.setInterval(()=>n(Date.now()),3e4);return()=>window.clearInterval(e)},[]);let r=Math.max(0,t-e*1e3),i=Math.floor(r/6e4);if(i<1)return(0,L.jsx)(L.Fragment,{children:`just now`});if(i<60)return(0,L.jsxs)(L.Fragment,{children:[i,`m ago`]});let a=Math.floor(i/60);if(a<24)return(0,L.jsxs)(L.Fragment,{children:[a,`h ago`]});let o=Math.floor(a/24);return o===1?(0,L.jsx)(L.Fragment,{children:`yesterday`}):o<7?(0,L.jsxs)(L.Fragment,{children:[o,`d ago`]}
149):(0,L.jsx)(L.Fragment,{children:new Date(e*1e3).toLocaleDateString()})}var Xz=5;function Zz({open:e,onOpenChange:t,message:n,currentConversationId:r}){let[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(new Set),{data:c,isLoading:l}=vi({queryKey:[`forward-modal-conversations`,i],enabled:e,queryFn:async()=>{let e=new URLSearchParams({limit:`100`});return i.trim()&&e.set(`q`,i.trim()),H(`/api/messages/conversations?${e.toString()}`)},staleTime:5e3}),u=(0,_.useMemo)(()=>(c?.data??[]).filter(e=>e.id!==r),[c,r]),d=R({mutationFn:async()=>{if(!n)throw Error(`No message to forward`);return H(`/api/messages/${n.id}/forward`,{method:`POST`,body:JSON.stringify({targetConversationIds:Array.from(o)})})},onSuccess:e=>{let{succeeded:t,total:n,results:r}=e.data,i=r.filter(e=>!e.success);t===n?z.success(`Forwarded to ${t} conversation${t===1?``:`s`}`):t>0?z.warning(`Forwarded to ${t}/${n}. ${i.length} failed.`):z.error(i[0]?.success===!1?i[0].error:`Failed to forward`),p()},onError:e=>{z.error(e.message||`Failed to forward`)}}),f=e=>{s(t=>{let n=new Set(t);if(n.has(e))n.delete(e);else{if(n.size>=Xz)return z.warning(`Max ${Xz} conversations per forward â unselect one first`),t;n.add(e)}return n})},p=()=>{a(``),s(new Set),t(!1)},m=o.size===0||d.isPending||!n;return(0,L.jsx)(aj,{open:e,onOpenChange:e=>{e?t(!0):p()},children:(0,L.jsxs)(lj,{className:`max-w-md`,children:[(0,L.jsxs)(uj,{children:[(0,L.jsx)(fj,{children:`Forward message`}),(0,L.jsxs)(pj,{children:[`Select up to `,Xz,` conversations. The original sender won't be shown in the target threads.`]})]}),(0,L.jsxs)(`div`,{className:`relative`,children:[(0,L.jsx)($w,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,L.jsx)(G,{value:i,onChange:e=>a(e.target.value),placeholder:`Search by name or phone...`,className:`pl-9`,autoFocus:!0})]}),(0,L.jsxs)(`div`,{className:`border rounded-md max-h-[320px] overflow-y-auto`,children:[l&&(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-6`,children:`Loading conversations...`}),!l&&u.length===0&&(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-6`,children:`No conversations found`}),u.map(e=>{let t=o.has(e.id),n=e.leadName??e.leadPhone??`Unknown contact`,r=e.leadPhone&&e.leadName?e.leadPhone:e.type===`group`?`Group`:null;return(0,L.jsxs)(`button`,{type:`button`,onClick:()=>f(e.id),className:V(`w-full flex items-center gap-3 px-3 py-2 text-left text-sm border-b last:border-b-0 hover:bg-muted transition-colors`,t&&`bg-primary/5`),children:[(0,L.jsx)(tM,{checked:t,tabIndex:-1}),(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsx)(`p`,{className:`truncate font-medium`,children:n}),r&&(0,L.jsx)(`p`,{className:`truncate text-xs text-muted-foreground`,children:r})]}),e.type===`group`&&(0,L.jsx)(`span`,{className:`shrink-0 text-[10px] font-medium uppercase text-blue-600`,children:`Group`})]},e.id)})]}),(0,L.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:o.size>0?`${o.size} selected`:`Select at least one conversation`}),(0,L.jsxs)(dj,{children:[(0,L.jsx)(W,{type:`button`,variant:`ghost`,onClick:p,children:`Cancel`}),(0,L.jsxs)(W,{type:`button`,onClick:()=>d.mutate(),disabled:m,className:`gap-2`,children:[(0,L.jsx)(pw,{className:`h-4 w-4`}),d.isPending?`Forwarding...`:`Forward${o.size>0?` (${o.size})`:``}`]})]})]})})}async function Qz(e){if(typeof navigator>`u`||!navigator.clipboard)return!1;try{return await navigator.clipboard.writeText(e),!0}catch{return!1}}function $z(e){return e.kind===`phone`?`phone:${e.phone}`:`${e.kind}:${e.id}`}function eB(e,t){let n=t.trim().toLowerCase();return n?e.filter(e=>!e.isGroup&&e.name.toLowerCase().includes(n)):[]}function tB(e){return e.map(e=>e.kind===`phone`?{kind:`phone`,phone:e.phone}:{kind:e.kind,id:e.id})}function nB({open:e,selected:t,onChange:n}){let[r,i]=(0,_.useState)(``),[a,o]=(0,_.useState)(``),s=vi({queryKey:[`participant-picker-leads`,r],enabled:e&&r.trim().length>0,queryFn:async()=>H(`/api/leads?${new URLSearchParams({limit:`20`,search:r.trim()}).toString()}`),staleTime:5e3}),c=vi({queryKey:[`participant-picker-agents`],enabled:e,queryFn:async()=>H(`/api/agents`),staleTime:3e4}),l=(0,_.useMemo)(()=>new Set(t.map($z)),[t]),u=(0,_.useMemo)(()=>eB(c.data?.data??[],r),[c.data,r]),d=e=>{l.has($z(e))||n([...t,e])},f=e=>{n(t.filter(t=>$z(t)!==e))},p=()=>{let e=a.trim();if(!e)return;let r={kind:`phone`,phone:e,label:e};if(l.has($z(r))){z.warning(`That number is already added`);return}n([...t,r]),o(``)};return(0,L.jsxs)(L.Fragment,{children:[t.length>0&&(0,L.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.map(e=>{let t=$z(e);return(0,L.jsxs)(X,{variant:`secondary`,className:`gap-1 pr-1`,children:[e.label,(0,L.jsx)(`button`,{type:`button`,onClick:()=>f(t),className:`hover:text-destructive`,children:(0,L.jsx)(FT,{className:`h-3 w-3`})})]},t)})}),(0,L.jsxs)(`div`,{className:`relative`,children:[(0,L.jsx)($w,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,L.jsx)(G,{value:r,onChange:e=>i(e.target.value),placeholder:`Search leads or agents...`,className:`pl-9`})]}),r.trim()&&(0,L.jsxs)(`div`,{className:`border rounded-md max-h-[200px] overflow-y-auto`,children:[u.map(e=>{let t=!e.phone,n=`agent:${e.id}`;return(0,L.jsxs)(`button`,{type:`button`,disabled:t||l.has(n),onClick:()=>d({kind:`agent`,id:e.id,label:e.name}),className:V(`w-full flex items-center gap-2 px-3 py-2 text-left text-sm border-b last:border-b-0 hover:bg-muted disabled:opacity-50 disabled:cursor-not-allowed`),children:[(0,L.jsx)(`span`,{className:`text-[10px] font-medium uppercase text-blue-600 shrink-0`,children:`Agent`}),(0,L.jsx)(`span`,{className:`truncate flex-1`,children:e.name}),t&&(0,L.jsx)(`span`,{className:`text-[10px] text-destructive shrink-0`,children:`no phone`})]},n)}),(s.data?.data??[]).map(e=>{let t=`lead:${e.id}`;return(0,L.jsxs)(`button`,{type:`button`,disabled:l.has(t),onClick:()=>d({kind:`lead`,id:e.id,label:e.name,sublabel:e.phone}),className:`w-full flex items-center gap-2 px-3 py-2 text-left text-sm border-b last:border-b-0 hover:bg-muted disabled:opacity-50 disabled:cursor-not-allowed`,children:[(0,L.jsx)(`span`,{className:`text-[10px] font-medium uppercase text-emerald-600 shrink-0`,children:`Lead`}),(0,L.jsx)(`span`,{className:`truncate flex-1`,children:e.name}),(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground shrink-0`,children:e.phone})]},t)}),u.length===0&&(s.data?.data??[]).length===0&&!s.isLoading&&(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-4`,children:`No matches`})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(G,{value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),p())},placeholder:`Add by phone number...`}),(0,L.jsx)(W,{type:`button`,variant:`outline`,size:`icon`,className:`h-9 w-9 shrink-0`,onClick:p,children:(0,L.jsx)(Gw,{className:`h-4 w-4`})})]})]})}function rB({title:e,description:t,items:n,onDone:r}){let i=e=>{Qz(e).then(e=>{e?z.success(`Copied`):z.error(`Could not copy`)})};return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(uj,{children:[(0,L.jsx)(fj,{children:e}),(0,L.jsx)(pj,{children:t})]}),(0,L.jsx)(`div`,{className:`space-y-3 max-h-[360px] overflow-y-auto`,children:n.map(e=>(0,L.jsxs)(`div`,{className:`border rounded-md p-3 space-y-2`,children:[(0,L.jsx)(`p`,{className:`text-sm font-medium`,children:e.name}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(G,{readOnly:!0,value:e.message,className:`text-xs`}),(0,L.jsx)(W,{type:`button`,size:`icon`,variant:`outline`,className:`h-9 w-9 shrink-0`,onClick:()=>i(e.message),children:(0,L.jsx)(ew,{className:`h-4 w-4`})})]})]},e.phone))}),(0,L.jsx)(dj,{children:(0,L.jsx)(W,{onClick:r,children:`Done`})})]})}function iB({conversationId:e,open:t,onOpenChange:n}){let r=ri(),{groupOpsEnabled:i}=kN(),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)(null),l=()=>{o([]),c(null)},u=()=>{l(),n(!1)},d=R({mutationFn:async()=>{let t=await H(`/api/messages/conversations/${e}/participants/add`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({participants:tB(a)})});if(!t.success||!t.data)throw Error(t.error||`Failed to add participants`);return t.data},onSuccess:t=>
149{if(r.invalidateQueries({queryKey:[`conversation-participants`,e]}),t.couldNotAdd.length>0){c(t.couldNotAdd),z.success(`Added â some contacts need an invite link`);return}z.success(t.addedCount>0?`Participant(s) added`:`No new participants added`),u()},onError:e=>z.error(e instanceof Error?e.message:`Failed to add participants`)}),f=a.length>0&&!d.isPending&&i;return s?(0,L.jsx)(aj,{open:t,onOpenChange:e=>e?null:u(),children:(0,L.jsx)(lj,{className:`max-w-md`,children:(0,L.jsx)(rB,{title:`Some contacts need an invite`,description:`These contacts couldn't be added automatically (their privacy settings). Send them the invite link yourself.`,items:s,onDone:u})})}):(0,L.jsx)(aj,{open:t,onOpenChange:e=>e?null:u(),children:(0,L.jsxs)(lj,{className:`max-w-md`,children:[(0,L.jsxs)(uj,{children:[(0,L.jsxs)(fj,{className:`flex items-center gap-2`,children:[(0,L.jsx)(DT,{className:`h-4 w-4`}),` Add participants`]}),(0,L.jsx)(pj,{children:`Add leads, agents, or a phone number to this group.`})]}),(0,L.jsx)(nB,{open:t,selected:a,onChange:o}),!i&&(0,L.jsx)(`div`,{className:`rounded-md border border-amber-300 bg-amber-50 px-3 py-2 text-sm text-amber-900`,children:`Adding participants is temporarily disabled â please add them manually on WhatsApp.`}),(0,L.jsxs)(dj,{children:[(0,L.jsx)(W,{type:`button`,variant:`ghost`,onClick:u,children:`Cancel`}),(0,L.jsxs)(W,{type:`button`,onClick:()=>d.mutate(),disabled:!f,className:`gap-2`,children:[(0,L.jsx)(DT,{className:`h-4 w-4`}),d.isPending?`Adding...`:`Add`]})]})]})})}var aB=`The bot's WhatsApp number is not a participant of this group â re-add it to the group, then retry`;function oB(e,t){return t?aB:e===!1?`Bot is not admin in this group â ask an admin to promote it`:e===null?`Can't verify admin status â check WhatsApp is connected`:``}function sB(e,t,n){return!t&&!n?`Temporarily disabled â please do so manually on WhatsApp`:oB(e,t)}var cB=100,lB=[`SHL`,`Stacked Chat`];function uB(e){if(!e)return!1;let t=e.trim().toLowerCase();return lB.some(e=>
149t.startsWith(e.toLowerCase()))}function dB({conversationId:e,currentSubject:t,botIsGroupAdmin:n,botNotInGroup:r,open:i,onOpenChange:a}){let o=ri(),[s,c]=(0,_.useState)(!1),{groupOpsEnabled:l}=kN(),u=[`conversation-participants`,e],d=i&&!!e,f=r||n!==!0||!l,p=sB(n,r,l),{data:m,isLoading:h,isError:g,isFetching:v,refetch:y}=vi({queryKey:u,enabled:d,queryFn:async()=>{let t=await H(`/api/messages/conversations/${e}/participants`);if(!t.success)throw Error(`Failed to load participants`);return t.data},staleTime:6e4}),b=async()=>{if(!e)return;let t=await H(`/api/messages/conversations/${e}/participants?refresh=1`);t.success?o.setQueryData(u,t.data):y()},x=m??[],S=x.filter(e=>!e.leftAt),C=x.filter(e=>e.leftAt);return(0,L.jsx)(YT,{open:i,onOpenChange:a,children:(0,L.jsxs)($T,{side:`right`,className:`w-full sm:max-w-md flex flex-col p-0`,children:[(0,L.jsxs)(eE,{className:`border-b p-4`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,L.jsx)(tE,{children:`Participants`}),r&&(0,L.jsxs)(tx,{children:[(0,L.jsx)(nx,{asChild:!0,children:(0,L.jsxs)(X,{tabIndex:0,variant:`outline`,className:`text-[10px] border-red-300 bg-red-50 text-red-700 gap-1 py-0 shrink-0`,children:[(0,L.jsx)(kT,{className:`h-2.5 w-2.5`}),`Bot not in group`]})}),(0,L.jsx)(rx,{side:`bottom`,className:`max-w-xs text-xs`,children:`The bot's WhatsApp number is not a participant of this group â re-add it to the group, then retry`})]})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-1`,children:[f?(0,L.jsxs)(tx,{children:[(0,L.jsx)(nx,{asChild:!0,children:(0,L.jsx)(`span`,{tabIndex:0,children:(0,L.jsxs)(W,{variant:`ghost`,size:`sm`,disabled:!0,className:`h-8 text-muted-foreground`,"aria-label":`Add participants (disabled)`,children:[(0,L.jsx)(DT,{className:`h-3.5 w-3.5`}),(0,L.jsx)(`span`,{className:`ml-1.5 text-xs`,children:`Add`})]})})}),(0,L.jsx)(rx,{side:`left`,className:`max-w-xs text-xs`,children:p})]}):(0,L.jsxs)(W,{variant:`ghost`,size:`sm`,onClick:()=>c(!0),className:`h-8`,"aria-label":`Add participants`,children:[(0,L.jsx)(DT,{className:`h-3.5 w-3.5`}),(0,L.jsx)(`span`,{className:`ml-1.5 text-xs`,children:`Add`})]}),(0,L.jsxs)(W,{variant:`ghost`,size:`sm`,onClick:b,disabled:v,className:`h-8`,"aria-label":`Refresh participants`,children:[(0,L.jsx)(Yw,{className:v?`h-3.5 w-3.5 animate-spin`:`h-3.5 w-3.5`}),(0,L.jsx)(`span`,{className:`ml-1.5 text-xs`,children:`Refresh`})]})]})]}),(0,L.jsxs)(nE,{children:[S.length,` active`,C.length>0?` · ${C.length} past`:``]})]}),e&&(0,L.jsx)(pB,{conversationId:e,currentSubject:t,botIsGroupAdmin:n,botNotInGroup:r}),(0,L.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-1`,children:h?(0,L.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-muted-foreground text-sm`,children:[(0,L.jsx)(Ew,{className:`h-4 w-4 animate-spin mr-2`}),`Loading participantsâ¦`]}):g?(0,L.jsx)(`div`,{className:`text-sm text-destructive py-4`,children:`Couldn't load the participant list. Try Refresh.`}):x.length===0?(0,L.jsx)(`div`,{className:`text-sm text-muted-foreground py-4`,children:`No participants on file. Click Refresh to fetch from WhatsApp.`}):(0,L.jsxs)(L.Fragment,{children:[e&&S.map(t=>(0,L.jsx)(fB,{p:t,conversationId:e,botIsGroupAdmin:n,botNotInGroup:r},t.participantJid)),e&&C.length>0&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`div`,{className:`pt-4 pb-1 text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:`Past members`}),C.map(t=>(0,L.jsx)(fB,{p:t,conversationId:e,botIsGroupAdmin:n,botNotInGroup:r},t.participantJid))]})]})}),e&&(0,L.jsx)(iB,{conversationId:e,open:s,onOpenChange:c})]})})}function fB({p:e,conversationId:t,botIsGroupAdmin:n,botNotInGroup:r}){let i=ri(),[a,o]=(0,_.useState)(!1),s=R({mutationFn:async()=>{let n=await H(`/api/messages/conversations/${t}/participants/remove`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({participantJid:e.participantJid})});if(!n.success)throw Error(n.error||`Failed to remove participant`)},onSuccess:()=>{z.success(`Participant removed`),o(!1),i.invalidateQueries({queryKey:[`conversation-participants`,t]})},onError:e=>{z.error(e instanceof Error?e.message:`Failed to remove participant`)}}),c=n===!0&&!r&&!e.isSelf&&!e.leftAt,l=e.lead?.name??e.agent?.name??e.displayName??e.phone??`Unknown`;return(0,L.jsxs)(`div`,{className:`flex items-start gap-3 py-2 px-1 rounded hover:bg-muted/50`,children:[(0,L.jsx)(`div`,{className:`h-9 w-9 rounded-full bg-primary/10 text-primary flex items-center justify-center text-xs font-medium shrink-0`,children:l.replace(/[+\d\s-]+/g,``).split(/\s+/).filter(
149Boolean).map(e=>e[0]).join(``).toUpperCase().slice(0,2)||`?`}),(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[(0,L.jsx)(`span`,{className:`font-medium text-sm truncate`,children:l}),e.isSuperAdmin?(0,L.jsxs)(X,{variant:`outline`,className:`text-[10px] border-amber-300 bg-amber-50 text-amber-700 gap-1 py-0`,children:[(0,L.jsx)(rw,{className:`h-2.5 w-2.5`}),`Owner`]}):e.isAdmin?(0,L.jsxs)(X,{variant:`outline`,className:`text-[10px] border-blue-300 bg-blue-50 text-blue-700 gap-1 py-0`,children:[(0,L.jsx)(nT,{className:`h-2.5 w-2.5`}),`Admin`]}):null,e.lead&&(0,L.jsx)(X,{variant:`outline`,className:`text-[10px] border-emerald-300 bg-emerald-50 text-emerald-700 py-0`,children:`Lead`}),e.agent&&(0,L.jsx)(X,{variant:`outline`,className:`text-[10px] border-purple-300 bg-purple-50 text-purple-700 py-0`,children:`Agent`}),e.leftAt&&(0,L.jsx)(X,{variant:`outline`,className:`text-[10px] text-muted-foreground py-0`,children:`Left`})]}),(0,L.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,L.jsx)(Vw,{className:`h-3 w-3 shrink-0`}),e.phone?(0,L.jsx)(`a`,{href:`tel:${e.phone}`,className:`hover:text-foreground hover:underline`,children:e.phone}):(0,L.jsx)(`span`,{className:`italic opacity-70`,children:`unknown phone`}),e.lead&&(0,L.jsxs)(Cn,{to:`/leads/${e.lead.id}`,className:`ml-auto inline-flex items-center gap-0.5 text-xs text-emerald-700 hover:underline`,children:[`Open lead`,(0,L.jsx)(ow,{className:`h-2.5 w-2.5`})]})]}),e.displayName&&e.displayName!==l&&(0,L.jsxs)(`div`,{className:`text-xs text-muted-foreground opacity-70 truncate`,children:[`WA name: `,e.displayName]})]}),c&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(W,{variant:`ghost`,size:`icon`,onClick:()=>o(!0),className:`h-7 w-7 shrink-0 text-muted-foreground hover:text-destructive`,"aria-label":`Remove ${l}`,children:(0,L.jsx)(ET,{className:`h-3.5 w-3.5`})}),(0,L.jsx)(lA,{open:a,onOpenChange:o,children:(0,L.jsxs)(pA,{children:[(0,L.jsxs)(mA,{children:[(0,L.jsx)(gA,{children:`Remove from group?`}),(0,L.jsxs)(_A,{children:[`Remove `,(0,L.jsx)(`strong`,{children:l}),` from this WhatsApp group? They'll be removed for everyone.`]})]}),(0,L.jsxs)(hA,{children:[(0,L.jsx)(yA,{disabled:s.isPending,children:`Cancel`}),(0,L.jsx)(vA,{onClick:e=>{e.preventDefault(),s.mutate()},disabled:s.isPending,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:s.isPending?`Removingâ¦`:`Remove`})]})]})})]})]})}function pB({conversationId:e,currentSubject:t,botIsGroupAdmin:n,botNotInGroup:r}){let i=ri(),[a,o]=(0,_.useState)(!1),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(!1),d=R({mutationFn:async t=>{let n=await H(`/api/messages/conversations/${e}/group-subject`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({subject:t})});if(!n.success)throw Error(n.error||`Rename failed`);return n.data},onSuccess:()=>{z.success(`Group renamed`),o(!1),u(!1),c(``),i.invalidateQueries({queryKey:[`conversations`]}),i.invalidateQueries({queryKey:[`conversation-details`,e]})},onError:e=>{let t=e instanceof Error?e.message:`Rename failed`;z.error(t)}}),f=r||n!==!0,p=oB(n,r),m=()=>{c(t??``),o(!0)},h=()=>{o(!1),c(``)},g=()=>{let e=s.trim();if(e.length===0){z.error(`Group name cannot be empty`);return}if(e.length>cB){z.error(`Group name must be ${cB} characters or fewer`);return}if(e===t){h();return}u(!0)},v=()=>{d.mutate(s.trim())},y=`${s.length} / ${cB}`,b=s.length>cB,x=s.trim(),S=uB(t)&&!uB(x);return(0,L.jsxs)(`div`,{className:`border-b px-4 py-3`,children:[(0,L.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide mb-1.5`,children:`Group name`}),a?(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(G,{autoFocus:!0,value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),g()):e.key===`Escape`&&(e.preventDefault(),h())},maxLength:cB+10,className:`h-9 text-sm`,placeholder:`Group name`}),(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsx)(`span`,{className:b?`text-xs text-destructive font-medium`:`text-xs text-muted-foreground`,children:y}),(0,L.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(W,{variant:`ghost`,size:`sm`,onClick:h,className:`h-8 px-2`,"aria-label":`Cancel`,children:(0,L.jsx)(FT,{className:`h-3.5 w-3.5`})}),(0,L.jsx)(W,{variant:`default`,size:`sm`,onClick:g,disabled:d.isPending||b||x.length===0,className:`h-8 px-2`,"aria-label":`Save`,children:(0,L.jsx)(RC,{className:`h-3.5 w-3.5`})})]})]})]}):(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,L.jsx)(`span`,{className:`text-sm font-medium truncate`,children:t||(0,L.jsx)(`span`,{className:`italic text-muted-foreground`,children:`No name set`})}),f?(0,L.jsxs)(tx,{children:[(0,L.jsx)(nx,{asChild:!0,children:(0,L.jsx)(`span`,{tabIndex:0,children:(0,L.jsx)(W,{variant:`ghost`,size:`sm`,disabled:!0,className:`h-8 px-2 text-muted-foreground`,"aria-label":`Edit group name (disabled)`,children:(0,L.jsx)(Bw,{className:`h-3.5 w-3.5`})})})}),(0,L.jsx)(rx,{side:`left`,className:`max-w-xs text-xs`,children:p})]}):(0,L.jsx)(W,{variant:`ghost`,size:`sm`,onClick:m,className:`h-8 px-2`,"aria-label":`Edit group name`,children:(0,L.jsx)(Bw,{className:`h-3.5 w-3.5`})})]}),(0,L.jsx)(lA,{open:l,onOpenChange:u,children:(0,L.jsxs)(pA,{children:[(0,L.jsxs)(mA,{children:[(0,L.jsx)(gA,{children:`Rename group on WhatsApp?`}),(0,L.jsxs)(_A,{className:`space-y-2`,children:[S&&(0,L.jsx)(`span`,{className:`block rounded-md bg-amber-50 border border-amber-300 px-3 py-2 text-amber-900 text-sm`,children:`Renaming this group away from its agent-PA prefix detaches it: a client ("Stacked Chat") group stops being monitored; an "SHL" group stops receiving weekly briefs & silence nudges. Continue?`}),(0,L.jsxs)(`span`,{className:`block`,children:[`Rename group to `,(0,L.jsxs)(`strong`,{children:[`"`,x,`"`]}),` on WhatsApp? All members will see the new name.`]})]})]}),(0,L.jsxs)(hA,{children:[(0,L.jsx)(yA,{disabled:d.isPending,children:`Cancel`}),(0,L.jsx)(vA,{onClick:e=>{e.preventDefault(),v()},disabled:d.isPending,children:d.isPending?`Renamingâ¦`:`Rename`})]})]})})]})}var mB={outreach:`Outreach`,followup_due:`Follow-up due`,mop_due:`MOP due`,mop_defer:`MOP defer`,qual_nudge:`Qualification nudge`};
149function hB(e){return mB[e]||e.split(`_`).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function gB(e){return!(e instanceof lC)||e.status===408||e.status===429?!1:e.status>=400&&e.status<500}function _B(e){return e instanceof Error&&e.message.trim().length>0?e.message:`Couldn't load templates.`}function vB({conversationId:e,open:t,onOpenChange:n}){let r=ri(),i=vi({queryKey:[`template-options`,e],enabled:t,staleTime:0,retry:(e,t)=>!gB(t)&&e<1,queryFn:()=>H(`/api/messages/conversations/${e}/template-options`).then(e=>e.data)}),a=i.data?.options??[],[o,s]=(0,_.useState)({kind:`pending`}),[c,l]=(0,_.useState)(null),u=`${e}:${t}`,[d,f]=(0,_.useState)(u),p=d!==u,m=i.data!==void 0&&!i.isFetching&&!i.isError,h=p?{kind:`pending`}:o;if(m){if(h.kind===`picked`){let e=h.id;a.some(t=>t.id===e&&t.fillError===null)||(h={kind:`invalidated`})}else if(h.kind===`pending`){let e=a.find(e=>e.fillError===null);e&&(h={kind:`picked`,id:e.id})}}p&&(f(u),l(null)),h!==o&&s(h);let g=h.kind===`picked`?h.id:null,v=i.isFetching?{kind:`loading`}:i.isError?{kind:`error`,message:_B(i.error),canRetry:!gB(i.error)}:i.data===void 0?{kind:`loading`}:i.data.in_window?{kind:`windowReopened`}:a.length===0?{kind:`empty`}:{kind:`list`},y=v.kind===`windowReopened`;(0,_.useEffect)(()=>{y&&r.invalidateQueries({queryKey:[`conversation-details`,e]})},[y,e,r]);let b=R({mutationFn:t=>H(`/api/messages/send-template`,{method:`POST`,body:JSON.stringify({conversationId:e,templateId:t})}),onSuccess:()=>{z.success(`Template sent.`),r.invalidateQueries({queryKey:[`messages`,e]}),r.invalidateQueries({queryKey:[`conversation-details`,e]}),r.invalidateQueries({queryKey:[`conversations`]}),n(!1)},onError:t=>{l(t instanceof Error?t.message:`Failed to send template.`),r.invalidateQueries({queryKey:[`conversation-details`,e]}),r.invalidateQueries({queryKey:[`template-options`,e]})}}),x=()=>{!g||b.isPending||(l(null),b.mutate(g))},S=c?(0,L.jsxs)(`div`,{className:`flex items-start gap-1.5 rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-xs text-destructive`,children:[(0,L.jsx)(xT,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,L.jsx)(`span`,{children:c})]}):null;return(0,L.jsx)(aj,{open:t,onOpenChange:n,children:(0,L.jsxs)(lj,{className:`sm:max-w-md`,children:[(0,L.jsxs)(uj,{children:[(0,L.jsx)(fj,{children:`Send a template`}),(0,L.jsx)(pj,{children:`The 24-hour reply window is closed - WhatsApp requires an approved template to reach out. Pick one below; the preview is exactly what will be sent.`})]}),v.kind===`list`?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`div`,{role:`radiogroup`,"aria-label":`Approved templates`,className:`max-h-80 overflow-y-auto rounded-md border divide-y`,children:a.map(e=>{let t=e.fillError===null,n=t&&g===e.id;return(0,L.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":n,disabled:!t,onClick:()=>s({kind:`picked`,id:e.id}),className:V(`w-full px-3 py-2.5 text-left transition-colors`,t?`hover:bg-muted`:`cursor-not-allowed opacity-60`,n&&`bg-primary/5`),children:(0,L.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,L.jsx)(`span`,{className:V(`mt-0.5 h-3.5 w-3.5 shrink-0 rounded-full border`,n?`border-primary bg-primary`:`border-muted-foreground/40`)}),(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsx)(`span`,{className:`text-sm font-medium`,children:hB(e.kind)}),(0,L.jsxs)(`p`,{className:`truncate text-xs text-muted-foreground`,children:[e.metaTemplateName,` · `,e.category]}),t?(0,L.jsx)(`p`,{className:`mt-1.5 whitespace-pre-wrap rounded-md border bg-muted/50 px-2 py-1.5 text-xs`,children:e.rendered}):(0,L.jsx)(`p`,{className:`mt-1.5 text-xs text-destructive`,children:e.fillError})]})]})},e.id)})}),h.kind===`invalidated`&&(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`The template you picked is no longer available - pick another one.`}),S,(0,L.jsxs)(dj,{children:[(0,L.jsx)(W,{type:`button`,variant:`outline`,onClick:()=>n(!1),disabled:b.isPending,children:`Cancel`}),(0,L.jsx)(W,{type:`button`,onClick:x,disabled:!g||b.isPending,children:b.isPending?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(Ew,{className:`h-3.5 w-3.5 mr-1.5 animate-spin`}),`Sendingâ¦`]}):`Send template`})]})]}):(0,L.jsxs)(L.Fragment,{children:[v.kind===`loading`&&(0,L.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-sm text-muted-foreground`,children:[(0,L.jsx)(Ew,{className:`h-4 w-4 animate-spin mr-2`}),`Loading templatesâ¦`]}),v.kind===`error`&&(0,L.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-8 text-center text-sm text-muted-foreground`,children:[(0,L.jsx)(`p`,{children:v.message}),v.canRetry&&(0,L.jsx)(W,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>i.refetch(),children:`Retry`})]}),v.kind===`windowReopened`&&(0,L.jsx)(`p`,{className:`py-6 text-center text-sm`,children:`The lead replied - you can reply normally now.`}),v.kind===`empty`&&(0,L.jsxs)(`p`,{className:`py-6 text-center text-sm text-muted-foreground`,children:[`No approved templates yet. Add one in`,` `,(0,L.jsx)(`strong`,{children:`AI & Settings â WhatsApp Templates`}),`.`]}),!y&&S,(0,L.jsx)(dj,{children:(0,L.jsx)(W,{type:`button`,onClick:()=>n(!1),children:`Close`})})]})]})})}function yB(e){let t=[];return e.leadId?e.aiEnabled||t.push(`ai-off`):t.push(`no-lead`),e.isSandboxTest&&t.push(`sandbox`),e.isSimulation&&t.push(`sim`),e.type===`group`&&t.push(`group`),e.status!==`active`&&e.status!==`closed`&&t.push(`status`),t}function bB(e){return e?`Group created - the lead's privacy settings blocked the direct add, so an invite link was drafted in their chat`:`Group created - intro and agent brief drafted for review`}function xB(e){return e.length<=1?e[0]??`them`:`${e.slice(0,-1).join(`, `)} and ${e[e.length-1]}`}function SB(e){let t=xB(e.agentNames),n=e.target===`shl_group`?e.room?`"${e.room}"`:`their SHL group`:`their chat`;return e.outcome===`drafted`?`for ${t} drafted in ${n} - send it from the inbox`:`for ${t} sent to ${n}`}function CB(e){let{agentsNotAdded:t,inviteUrl:n,inviteDeliveries:r}=e;if(!t||t.length===0)return null;let i=t.join(`, `),a=(r??[]).filter(e=>e.outcome!==`failed`),o=a.reduce((e,t)=>
149e+t.agentNames.length,0);if(o===0){let e=`Not added to the group: ${i} - add them on WhatsApp by hand`;return n?`${e}, or send them the group invite link`:e}let s=[`Not added to the group: ${i}`,`Invite link ${a.map(SB).join(`; `)}`];return t.length>o&&s.push(n?`Add the others on WhatsApp by hand, or send them the group invite link`:`Add the others on WhatsApp by hand`),s.join(`. `)}function wB(e,t){if(e)return{label:`Copy invite link`,onClick:()=>{Qz(e).then(e=>{e?t.onCopied():t.onCopyFailed()},()=>t.onCopyFailed())}}}function TB(e,t){let n=wB(e,t);return{duration:1/0,closeButton:!0,...n?{action:n}:{}}}var EB=100,DB=5e3,OB=150,kB=10;function AB({conversation:e,sidebarOpen:t,onToggleSidebar:n,onBackMobile:r,realtimeFallback:i=!1,hideDrafts:a=!1}){let o=ri(),s=(0,_.useRef)(null),{connected:c,groupOpsEnabled:l,groupCreateQuota:u}=kN(),d=(0,_.useMemo)(()=>[`messages`,e.id],[e.id]),{data:f,isLoading:p,isError:m,refetch:h,fetchNextPage:g,hasNextPage:v,isFetchingNextPage:y,isSuccess:b}=yi({queryKey:d,initialPageParam:null,queryFn:async({pageParam:t})=>{let n=new URLSearchParams;n.set(`conversationId`,e.id),n.set(`limit`,String(EB)),t&&n.set(`before`,t);let r=await H(`/api/messages?${n.toString()}`);return{data:r.data,hasMore:r.hasMore,nextCursor:r.nextCursor}},getNextPageParam:e=>e.hasMore?e.nextCursor:void 0,retry:2}),x=(0,_.useMemo)(()=>{if(!f)return[];let e=[];for(let t=f.pages.length-1;t>=0;t--)e.push(...f.pages[t].data);return vz(e,a)},[f,a]),S=x.length>0?x[x.length-1].timestamp:null,[C,w]=(0,_.useState)(!0),[T,E]=(0,_.useState)(0),D=(0,_.useRef)(null);(0,_.useEffect)(()=>{w(!0),E(0),D.current=null},[e.id]),(0,_.useEffect)(()=>{if(S===null)return;let e=D.current;if(e===null){D.current=S;return}S>e&&(C||E(e=>e+1),D.current=S)},[S,C]);let O=()=>{x.length!==0&&(s.current?.scrollToIndex({index:x.length-1,behavior:`smooth`,align:`end`}),E(0))},k=!C&&x.length>0,[A,j]=(0,_.useState)(!1),[M,ee]=(0,_.useState)(``),[N,P]=(0,_.useState)(``),[F,I]=(0,_.useState)(0),te=(0,_.useRef)(0),ne=(0,_.useRef)(null),re=(0,_.useRef)(0),[ie,ae]=(0,_.useState)(null),[oe,se]=(0,_.useState)(null),[ce,le]=(0,_.useState)(null),ue=(0,_.useRef)(0),[de,fe]=(0,_.useState)(null),[pe,me]=(0,_.useState)(!1),[he,ge]=(0,_.useState)(!1);(0,_.useEffect)(()=>{j(!1),ee(``),P(``),I(0),ne.current=null,re.current=0,ae(null),se(null),le(null),fe(null),me(!1),ue.current=0},[e.id]),(0,_.useEffect)(()=>{if(!A)return;let e=window.setTimeout(()=>{P(M.trim()),I(0),re.current=0},OB);return()=>window.clearTimeout(e)},[M,A]);let _e=A&&N.length>=2,ve=vi({queryKey:[`messages-search`,e.id,N],enabled:_e,staleTime:6e4,gcTime:6e4,queryFn:()=>{let t=new URLSearchParams;return t.set(`conversationId`,e.id),t.set(`q`,N),H(`/api/messages/search?${t.toString()}`)}}),ye=(0,_.useMemo)(()=>{let e=new Set;if(f)for(let t of f.pages)for(let n of t.data)n.status===`draft`&&e.add(n.id);return e},[f]),be=(0,_.useMemo)(()=>yz(ve.data?.data??[],ye,a),[ve.data,a,ye]),xe=be.length,Se=(xe>0?be[F%xe]:null)?.id??null,Ce=(0,_.useMemo)(()=>!_e||be.length===0?null:new Set(be.map(e=>e.id)),[_e,be]);(0,_.useEffect)(()=>{if(!Se)return;let e=x.findIndex(e=>e.id===Se);if(e!==-1){re.current=0,s.current?.scrollToIndex({index:e,behavior:`smooth`,align:`center`});return}v&&!y&&re.current<kB&&(re.current+=1,g())},[Se,x,v,y,g]);let we=()=>{ne.current=te.current,j(!0)},Te=()=>{let e=ne.current;j(!1),ee(``),P(``),I(0),ne.current=null,re.current=0,e!==null&&x.length>0&&e<x.length&&s.current?.scrollToIndex({index:e,behavior:`smooth`,align:`start`})},Ee=()=>{xe!==0&&I(e=>(e+1)%xe)},De=()=>{xe!==0&&I(e=>(e-1+xe)%xe)};(0,_.useEffect)(()=>{let e=e=>{!(e.metaKey||e.ctrlKey)||e.key!==`f`||document.querySelector(`[role="dialog"][data-state="open"]`)||(e.preventDefault(),we())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]);let Oe=vi({queryKey:[`messages`,e.id,`delta`,S],enabled:i&&b&&S!==null,refetchInterval:i?DB:!1,staleTime:0,gcTime:0,retry:1,queryFn:async()=>{let t=new URLSearchParams;return t.set(`conversationId`,e.id),t.set(`since`,S),H(`/api/messages?${t.toString()}`)}});(0,_.useEffect)(()=>{let e=Oe.data?.data;!e||e.length===0||o.setQueryData(d,t=>{if(!t||t.pages.length===0)return t;let n=t.pages[0],r=new Set(n.data.map(e=>e.id)),i=e.filter(e=>!r.has(e.id));if(i.length===0)return t;let a=[...t.pages];return a[0]={...n,data:[...n.data,...i]},{...t,pages:a}})},[Oe.data,o,d]);let{groupCounts:ke,groupLabels:Ae}=(0,_.useMemo)(()=>{let e=[],t=[],n=null;for(let r of x){let i=new Date(r.timestamp),a=`${i.getFullYear()}-${i.getMonth()}-${i.getDate()}`;a===n?e[e.length-1]+=1:(e.push(1),t.push(RR(i)),n=a)}return{groupCounts:e,groupLabels:t}},[x]),je=R({mutationFn:t=>H(`/api/messages/conversations/${e.id}/flag`,{method:`POST`,body:JSON.stringify({reason:t})}),onSuccess:()=>o.invalidateQueries({queryKey:[`conversations`]})}),Me=R({mutationFn:()=>H(`/api/messages/conversations/${e.id}/resolve`,{method:`POST`}),onSuccess:()=>{o.invalidateQueries({queryKey:[`conversations`]}
149),o.invalidateQueries({queryKey:[`conversation-details`,e.id]})}}),Ne=R({mutationFn:e=>H(`/api/messages/conversations/${e}/mark-read`,{method:`POST`}),onMutate:e=>{let t=o.getQueriesData({queryKey:[`conversations`]});for(let[n,r]of t)r?.pages&&o.setQueryData(n,{...r,pages:r.pages.map(t=>({...t,data:t.data.map(t=>t.id===e?{...t,unreadCount:0}:t)}))})}}).mutate;(0,_.useEffect)(()=>{e.unreadCount>0&&Ne(e.id)},[e.id,e.unreadCount,Ne]);let Pe=R({mutationFn:({messageId:e,emoji:t})=>H(`/api/messages/${e}/reactions`,{method:`POST`,body:JSON.stringify({emoji:t})}),onSuccess:()=>o.invalidateQueries({queryKey:[`messages`,e.id]})}),Fe=R({mutationFn:async({messageId:e,body:t})=>{let n=await H(`/api/messages/${e}/send-draft`,{method:`POST`,body:JSON.stringify(t?{body:t}:{})});if(!n?.success)throw Error(n?.error||`Send failed`);return n},onSuccess:()=>{o.invalidateQueries({queryKey:[`messages`,e.id]}),o.invalidateQueries({queryKey:[`conversations`]})},onError:t=>{z.error(t instanceof Error?t.message:`Send failed`),o.invalidateQueries({queryKey:[`conversation-details`,e.id]})}}),Ie=R({mutationFn:async e=>{let t=await H(`/api/messages/${e}`,{method:`DELETE`});if(!t?.success)throw Error(t?.error||`Discard failed`);return t},onSuccess:()=>{o.invalidateQueries({queryKey:[`messages`,e.id]}),o.invalidateQueries({queryKey:[`conversations`]})}}),Le=R({mutationFn:async e=>{let t=await H(`/api/messages/${e}/regenerate-brief`,{method:`POST`});if(!t?.success)throw Error(t?.error||`Regenerate failed`);return t},onSuccess:()=>{o.invalidateQueries({queryKey:[`messages`,e.id]})}}),Re=R({mutationFn:async({messageId:e,body:t})=>{let n=await H(`/api/messages/${e}/edit`,{method:`POST`,body:JSON.stringify({body:t})});if(!n?.success)throw Error(n?.error||`Edit failed`);return n},onSuccess:()=>{o.invalidateQueries({queryKey:[`messages`,e.id]}),o.invalidateQueries({queryKey:[`conversations`]})}}),ze=vi({queryKey:[`conversation-details`,e.id],queryFn:()=>H(`/api/messages/conversations/${e.id}/details`).then(e=>e.data),retry:2}),[Be,Ve]=jn(),He=Be.get(`messageId`),Ue=R({mutationFn:async e=>{let t=await H(`/api/assignments/${e}/create-group`,{method:`POST`});if(!t?.success)throw Error(t?.error||`Group creation failed`);return t.data},onSuccess:t=>{o.invalidateQueries({queryKey:[`conversations`]}),o.invalidateQueries({queryKey:[`conversation-details`,e.id]}),o.invalidateQueries({queryKey:[`whatsapp-status`]}
149),z.success(bB(t?.leadAddBlocked===!0));let n=t?.inviteUrl,r=CB({agentsNotAdded:t?.agentsNotAdded,inviteUrl:n,inviteDeliveries:t?.inviteDeliveries});r&&z.warning(r,TB(n,{onCopied:()=>z.success(`Invite link copied`),onCopyFailed:()=>z.error(`Could not copy - copy it from the activity log instead`)}))},onError:e=>{z.error(e instanceof Error?e.message:`Group creation failed`)}}),We=e.status===`closed`,Ge=e.channel,Ke=Ge===`cloud_api`,qe=ze.data?.cloud_routing_active??!1,Je=sR(Ge,qe),Ye=ze.data?.in_window??!1,Xe=ze.data?.session_expires_at??null,Ze=ze.data!==void 0,Qe=cR(Ge,qe,Ze,Ye),$e=lR({channel:Ge,cloudRoutingActive:qe,detailsLoaded:Ze,inWindow:Ye,isClosed:We,isSimulation:e.isSimulation}),[,et]=(0,_.useState)(0);(0,_.useEffect)(()=>{if(!e.aiRateLimitedUntil)return;let t=new Date(e.aiRateLimitedUntil).getTime()-Date.now();if(t<=0)return;let n=setTimeout(()=>et(e=>e+1),t);return()=>clearTimeout(n)},[e.aiRateLimitedUntil]);let tt=zR(e.id),{signalTyping:nt,signalStopped:rt,subscribePresence:it}=UR(e.id);(0,_.useEffect)(()=>{it()},[it]),(0,_.useEffect)(()=>()=>{rt()},[rt]);let at=e=>{le(e),ue.current=0};(0,_.useEffect)(()=>{He&&(le(He),ue.current=0,Ve(e=>{let t=new URLSearchParams(e);return t.delete(`messageId`),t}))},[He,Ve]),(0,_.useEffect)(()=>{if(!ce)return;let e=x.findIndex(e=>e.id===ce);if(e!==-1){ue.current=0,s.current?.scrollToIndex({index:e,behavior:`smooth`,align:`center`}),se(ce),le(null);let t=window.setTimeout(()=>se(null),1500);return()=>window.clearTimeout(t)}v&&!y&&ue.current<10?(ue.current+=1,g()):le(null)},[ce,x,v,y,g]);let ot=yB(e),st=t=>{switch(t){case`no-lead`:return(0,L.jsx)(X,{variant:`secondary`,className:`text-xs shrink-0`,children:`No lead`});case`ai-off`:return(0,L.jsx)(X,{variant:`secondary`,className:`text-xs shrink-0`,children:`AI Off`});case`sandbox`:return(0,L.jsx)(X,{variant:`outline`,className:`text-xs shrink-0 border-orange-300 bg-orange-50 text-orange-700`,children:`Sandbox`});case`sim`:return(0,L.jsx)(X,{variant:`outline`,className:`text-xs shrink-0 border-purple-300 bg-purple-50 text-purple-700`,children:`Simulation`});case`group`:return(0,L.jsxs)(X,{variant:`outline`,className:`text-xs shrink-0 border-blue-300 bg-blue-50 text-blue-700 gap-1`,children:[(0,L.jsx)(MT,{className:`h-3 w-3`}),`Group`]});case`status`:return(0,L.jsx)(X,{variant:`outline`,className:`text-xs shrink-0`,children:e.status})}},ct=ot[0],lt=ot.slice(1),ut=lt.length>0;return(0,L.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0`,children:[(0,L.jsxs)(`div`,{className:`h-14 px-2 sm:px-4 border-b flex items-center justify-between gap-2 shrink-0`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0 flex-1`,children:[r&&(0,L.jsx)(W,{variant:`ghost`,size:`icon`,onClick:r,className:`md:hidden h-11 w-11 shrink-0 -ml-1`,"aria-label":`Back to conversations`,children:(0,L.jsx)(CC,{className:`h-5 w-5`})}),(0,L.jsx)(`div`,{className:`h-8 w-8 rounded-full bg-primary/10 text-primary flex items-center justify-center text-xs font-medium shrink-0`,children:e.leadName?e.leadName.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2):`?`}),(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`span`,{className:`font-medium text-sm truncate`,children:e.leadName??e.leadPhone??`Unknown`}),e.leadName&&e.leadPhone&&(0,L.jsx)(`span`,{className:`hidden lg:inline text-xs text-muted-foreground shrink-0`,children:e.leadPhone})]}),(0,L.jsx)(Gz,{conversation:{id:e.id,type:e.type,leadPhone:e.leadPhone},presence:tt,messages:x}),Je&&(0,L.jsx)(`p`,{className:V(`text-xs truncate`,Ye?`text-emerald-600 dark:text-emerald-400`:`text-amber-600 dark:text-amber-400`),children:Ye?`In window · expires ${_R(Xe)}`:`Window expired â template required`})]}),(0,L.jsx)(X,{variant:`outline`,className:V(`text-xs shrink-0`,Ke?`border-emerald-300 bg-emerald-50 text-emerald-700 dark:border-emerald-500/50 dark:bg-emerald-950/30 dark:text-emerald-400`:`border-muted text-muted-foreground`),title:Ke?`Cloud API number`:`WhatsApp linked device`,children:gR(Ge)}),(0,L.jsxs)(`div`,{className:`flex lg:hidden items-center gap-1 shrink-0`,children:[ct&&st(ct),ut&&(0,L.jsxs)(OA,{children:[(0,L.jsx)(kA,{asChild:!0,children:(0,L.jsx)(W,{variant:`ghost`,size:`icon`,className:`h-9 w-9 text-muted-foreground`,"aria-label":`More conversation details`,children:(0,L.jsx)(xw,{className:`h-4 w-4`})})}),(0,L.jsxs)(AA,{align:`end`,className:`w-auto p-2 space-y-1.5`,children:[e.leadName&&e.leadPhone&&(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.leadPhone}),(0,L.jsx)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:lt.map(e=>(0,L.jsx)(`span`,{children:st(e)},e))})]})]})]}),(0,L.jsx)(`div`,{className:`hidden lg:flex items-center gap-2 shrink-0`,children:ot.map(e=>(0,L.jsx)(`span`,{children:st(e)},e))})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-0.5 sm:gap-1 shrink-0`,children:[e.flagged?(0,L.jsxs)(W,{variant:`ghost`,size:`icon`,onClick:()=>je.mutate(void 0),className:`h-11 w-11 lg:h-9 lg:w-auto lg:px-3 text-orange-500`,"aria-label":`Unflag conversation`,children:[(0,L.jsx)(uw,{className:`h-4 w-4 lg:mr-1 fill-orange-500`}),(0,L.jsx)(`span`,{className:`hidden lg:inline text-sm`,children:`Unflag`})]}):(0,L.jsxs)(Uj,{children:[(0,L.jsx)(Wj,{asChild:!0,children:(0,L.jsxs)(W,{variant:`ghost`,size:`icon`,className:`h-11 w-11 lg:h-9 lg:w-auto lg:px-3`,"aria-label":`Flag conversation`,children:[(0,L.jsx)(uw,{className:`h-4 w-4 lg:mr-1`}),(0,L.jsx)(`span`,{className:`hidden lg:inline text-sm`,children:`Flag`}),(0,L.jsx)(zC,{className:`hidden lg:inline h-3 w-3 ml-1`})]})}),(0,L.jsxs)(Gj,{align:`end`,children:[(0,L.jsx)(Kj,{onClick:()=>je.mutate(`manual`),children:`Flag for review`}),(0,L.jsx)(Kj,{onClick:()=>je.mutate(`bad_ai_reply`),children:`Bad AI reply`})]})]}),We?(0,L.jsxs)(W,{variant:`ghost`,size:`icon`,onClick:()=>Me.mutate(),disabled:Me.isPending,className:`h-11 w-11 lg:h-9 lg:w-auto lg:px-3`,"aria-label":`Reopen conversation`,children:[(0,L.jsx)(Xw,{className:`h-4 w-4 lg:mr-1`}),(0,L.jsx)(`span`,{className:`hidden lg:inline text-sm`,children:`Reopen`})]}):(0,L.jsxs)(W,{variant:`ghost`,size:`icon`,onClick:()=>Me.mutate(),className:`h-11 w-11 lg:h-9 lg:w-auto lg:px-3`,"aria-label":`Resolve conversation`,children:[(0,L.jsx)(GC,{className:`h-4 w-4 lg:mr-1`}),(0,L.jsx)(`span`,{className:`hidden lg:inline text-sm`,children:`Resolve`})]}),e.type===`group`&&(0,L.jsxs)(W,{variant:`ghost`,size:`icon`,onClick:()=>ge(!0),className:`h-11 w-11 lg:h-9 lg:w-auto lg:px-3`,"aria-label":`View group participants`,children:[(0,L.jsx)(MT,{className:`h-4 w-4 lg:mr-1`}),(0,L.jsx)(`span`,{className:`hidden lg:inline text-sm`,children:`Members`})]}),(0,L.jsx)(W,{variant:`ghost`,size:`icon`,onClick:n,className:V(`h-11 w-11 lg:h-9 lg:w-9`,t&&`bg-muted`),"aria-label":`Toggle details panel`,children:(0,L.jsx)(Rw,{className:`h-4 w-4`})})]})]}),A&&(0,L.jsx)(Uz,{value:M,onChange:ee,currentIndex:xe>0?F%xe+1:0,totalMatches:xe,isLoading:_e&&(ve.isFetching||y),onPrev:De,onNext:Ee,onClose:Te}
149),We&&(0,L.jsxs)(`div`,{className:`mx-4 mt-3 flex items-center justify-between rounded-md border border-muted bg-muted/50 px-3 py-2 text-sm text-muted-foreground`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(xw,{className:`h-4 w-4 shrink-0`}),`This conversation is resolved`]}),(0,L.jsxs)(W,{variant:`outline`,size:`sm`,onClick:()=>Me.mutate(),disabled:Me.isPending,className:`h-7 text-xs`,children:[(0,L.jsx)(Xw,{className:`h-3 w-3 mr-1`}),`Reopen`]})]}),e.aiRateLimitedUntil&&new Date(e.aiRateLimitedUntil).getTime()>Date.now()&&(0,L.jsxs)(`div`,{className:`mx-4 mt-3 flex items-center gap-2 rounded-md border border-amber-300 bg-amber-50 px-3 py-2 text-sm text-amber-900`,children:[(0,L.jsx)(xT,{className:`h-4 w-4 shrink-0`}),(0,L.jsxs)(`span`,{children:[`30 AI replies reached â automated responses paused until`,` `,new Date(e.aiRateLimitedUntil).toLocaleString(),`. Manual replies still work.`]})]}),e.type===`direct`&&!e.isSimulation&&!e.isSandboxTest&&ze.data?.assignment?.status===`assigned`&&!ze.data?.assignment?.waGroupId&&(0,L.jsxs)(`div`,{className:`mx-4 mt-3 flex flex-col gap-2 rounded-md border border-emerald-300 bg-emerald-50 px-3 py-2 text-sm text-emerald-900 sm:flex-row sm:items-center sm:justify-between`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(DT,{className:`h-4 w-4 shrink-0`}),(0,L.jsxs)(`span`,{children:[ze.data.lead?.name??`Lead`,` consented. Create a WhatsApp group with`,` `,(0,L.jsx)(`strong`,{children:ze.data.agent?.name??`the assigned agent`}),`?`]})]}),(0,L.jsxs)(tx,{children:[(0,L.jsx)(nx,{asChild:!0,children:(0,L.jsx)(`span`,{className:`inline-block shrink-0`,children:(0,L.jsx)(W,{size:`sm`,onClick:()=>Ue.mutate(ze.data.assignment.id),disabled:!c||!l||SR(u)||Ue.isPending,className:`bg-emerald-600 text-white hover:bg-emerald-700`,children:Ue.isPending?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(Yw,{className:`h-3.5 w-3.5 mr-1.5 animate-spin`}),`Creating group + drafting briefsâ¦`]}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(DT,{className:`h-3.5 w-3.5 mr-1.5`}),`Create group`]})})})}),l?c?SR(u)?(0,L.jsx)(rx,{children:CR(u)}):null:(0,L.jsx)(rx,{children:`WhatsApp is disconnected. Reconnect on the Connect tab to create groups.`}):(0,L.jsx)(rx,{children:`Temporarily disabled â please do so manually on WhatsApp`})]})]}),(0,L.jsxs)(`div`,{className:`flex-1 min-h-0 relative`,children:[p?(0,L.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,L.jsx)(Yw,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):m?(0,L.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3`,children:[(0,L.jsx)(xT,{className:`h-6 w-6 text-destructive`}),(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Failed to load messages`}),(0,L.jsxs)(W,{variant:`outline`,size:`sm`,onClick:()=>h(),children:[(0,L.jsx)(Yw,{className:`h-3.5 w-3.5 mr-1.5`}),`Retry`]})]}):x.length===0?(0,L.jsx)(`div`,{className:`flex items-center justify-center h-full text-sm text-muted-foreground`,children:`No messages yet`}):(0,L.jsx)(nL,{ref:s,className:`h-full`,groupCounts:ke,computeItemKey:e=>x[e]?.id??e,initialTopMostItemIndex:Math.max(x.length-1,0),followOutput:`auto`,atBottomThreshold:200,atBottomStateChange:e=>{w(e),e&&(E(0),D.current=S)},rangeChanged:e=>{te.current=e.startIndex},startReached:()=>{v&&!y&&g()},components:{Header:()=>y?(0,L.jsxs)(`div`,{className:`flex items-center justify-center py-2 text-xs text-muted-foreground`,children:[(0,L.jsx)(Yw,{className:`h-3.5 w-3.5 animate-spin mr-1.5`}),`Loading earlier messages...`]}):v?(0,L.jsx)(`div`,{className:`flex items-center justify-center py-2`,children:(0,L.jsx)(W,{variant:`ghost`,size:`sm`,className:`h-7 text-xs text-muted-foreground`,onClick:()=>void g(),children:`Load earlier messages`})}):null},groupContent:e=>(0,L.jsx)(Vz,{label:Ae[e]??``}),itemContent:t=>{let n=x[t];if(!n)return null;let r=Ce?.has(n.id)??!1,i=n.status===`draft`?fR({channel:Ge,cloudRoutingActive:qe,detailsLoaded:Ze,inWindow:Ye,hasTemplate:dR(n.rawPayload)!==null}):`none`,a=mR(i,$e);return(0,L.jsx)(`div`,{className:`px-4`,children:(0,L.jsx)(`div`,{className:`py-1.5`,children:(0,L.jsx)(az,{message:n,isGroup:e.type===`group`,highlightText:r?N:void 0,isCurrentMatch:r&&n.id===Se,onReply:We?void 0:ae,onJumpToQuoted:at,pulse:oe===n.id,onReact:We?void 0:(e,t)=>Pe.mutate({messageId:e,emoji:t}),onForward:We?void 0:fe,onSendDraft:We?void 0:async(e,t)=>{await Fe.mutateAsync({messageId:e,body:t})},draftSendLabel:pR(i)??void 0,draftSendDisabledReason:a??void 0,onDiscardDraft:We?void 0:async e=>{await Ie.mutateAsync(e)},onRegenerateDraft:We?void 0:async e=>{await Le.mutateAsync(e)},whatsappConnected:c,draftSendConnected:hR(Ge,c,qe),onEdit:We?void 0:async(e,t)=>{await Re.mutateAsync({messageId:e,body:t})},isSimulation:e.isSimulation})})})}}),(0,L.jsx)(Hz,{visible:k,unreadCount:T,onClick:O})]}),(0,L.jsx)(Bz,{conversationId:e.id,disabled:We||Qe,disabledLabel:We?`This conversation is closed`:Qe?`The 24-hour reply window has closed â use a template to reply.`:void 0,disabledAction:$e?(0,L.jsx)(W,{type:`button`,size:`sm`,onClick:()=>me(!0),children:`Send a template`}):void 0,onTyping:nt,onTypingStopped:rt,replyingTo:ie,onClearReply:()=>ae(null)}),(0,L.jsx)(vB,{conversationId:e.id,open:pe,onOpenChange:me}),(0,L.jsx)(Zz,{open:de!==null,onOpenChange:e=>{e||fe(null)},message:de,currentConversationId:e.id}),(0,L.jsx)(dB,{conversationId:e.type===`group`?e.id:null,currentSubject:e.type===`group`?ze.data?.conversation.contactName??e.leadName??null:null,botIsGroupAdmin:ze.data?.botIsGroupAdmin??null,botNotInGroup:ze.data?.botNotInGroup??!1,open:he,onOpenChange:ge})]})}function jB(e){if(!e)return!1;let t=e.replace(/\D/g,``);return t.length===8&&(t=`65${t}`),t.length===10&&t.startsWith(`65`)}function MB(e,t){return e.trim()||t?.trim()||void 0}function NB({assignment:e,open:t,onOpenChange:n,onSuccess:r,allowAllActiveAgents:i=!1,defaultReason:a}){let[o,s]=(0,_.useState)([]),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(!1),g=!e.agentId,v=e.id.startsWith(`lead:`),y=v||!!a,b=y||u.trim().length>0;(0,_.useEffect)(()=>
149{if(!t){l(``),d(``);return}h(!0),H(`/api/agents`).then(t=>{let n=(t.data??[]).filter(e=>i?e.isActive:e.isActive&&e.canTakeLeads&&!e.doNotPassLeads),r=new Set((e.alternatives??[]).map(e=>e.agentId));n.sort((e,t)=>{let n=r.has(e.id),i=r.has(t.id);return n&&!i?-1:!n&&i?1:e.name.localeCompare(t.name)}),s(n)}).catch(()=>z.error(`Failed to load agents`)).finally(()=>h(!1))},[t,e.alternatives,i]);let x=new Map((e.alternatives??[]).map(e=>[e.agentId,e]));async function S(){if(!c||!b)return;p(!0);let t=MB(u,a);try{v?await H(`/api/leads/${e.id.slice(5)}`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({assignedAgentId:c,...t?{reason:t}:{}})}):await H(`/api/assignments/${e.id}/override`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({newAgentId:c,reason:t??``})}),z.success(g?`Agent assigned`:`Assignment updated`),n(!1),r()}catch(e){z.error(e instanceof Error?e.message:g?`Failed to assign agent`:`Failed to reassign agent`)}finally{p(!1)}}return(0,L.jsx)(aj,{open:t,onOpenChange:n,children:(0,L.jsxs)(lj,{className:`max-w-md`,children:[(0,L.jsxs)(uj,{children:[(0,L.jsx)(fj,{children:g?`Assign agent to ${e.leadName??`lead`}`:`Reassign ${e.leadName??`lead`}`}),(0,L.jsx)(pj,{children:g?`Choose an agent to assign to this lead.`:`Currently assigned to ${e.agentName??`unknown agent`}`})]}),(0,L.jsxs)(`div`,{className:`space-y-4`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`label`,{className:`text-sm font-medium mb-1.5 block`,children:`Select new agent`}),m?(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading agents...`}):(0,L.jsx)(`div`,{className:`border rounded-md max-h-48 overflow-y-auto`,children:o.filter(t=>t.id!==e.agentId).map(e=>{let t=x.get(e.id);return(0,L.jsxs)(`button`,{type:`button`,onClick:()=>l(e.id),className:`w-full text-left px-3 py-2 text-sm flex items-center justify-between hover:bg-muted/50 transition-colors border-b last:border-b-0 ${c===e.id?`bg-primary/10`:``}`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`span`,{className:`font-medium`,children:e.name}),t&&(0,L.jsx)(X,{variant:`outline`,className:`text-xs`,children:`AI alternative`}),e.shlGroupName==null&&(0,L.jsx)(X,{variant:`outline`,className:`text-xs text-muted-foreground`,title:`No matched SHL group â briefs/nudges for this lead won't route until one is mapped.`,children:`No SHL group`})]}),(0,L.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[e.activeLeadCount??0,` leads`]})]},e.id)})})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`label`,{className:`text-sm font-medium mb-1.5 block`,children:[g?`Reason`:`Reason for override`,y?` (optional)`:``]}),(0,L.jsx)(TD,{value:u,onChange:e=>d(e.target.value),placeholder:g?`Why are you assigning this agent?`:`Why are you reassigning this lead?`,rows:3})]})]}),(0,L.jsxs)(dj,{children:[(0,L.jsx)(W,{variant:`outline`,onClick:()=>n(!1),children:`Cancel`}),(0,L.jsx)(W,{onClick:S,disabled:!c||!b||f,children:f?g?`Assigning...`:`Reassigning...`:g?`Assign`:`Confirm Reassign`})]})]})})}async function PB(e,t){let n=await fetch(`/api/messages/conversations/${e}/assign-lead`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}),r=await n.json().catch(()=>({}));return{status:n.status,body:r}}function FB(e){return e.contactPhone?e.contactPhone:e.waJid?`+`+e.waJid.split(`@`)[0]:``}function IB({conversation:e,open:t,onOpenChange:n,initialTab:r=`create`,onSuccess:i}){let a=ri(),o=e.type===`direct`,s=FB(e),[c,l]=(0,_.useState)(r),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(e.contactName??``),[m,h]=(0,_.useState)(s),[g,v]=(0,_.useState)(``),[y,b]=(0,_.useState)(``),[x,S]=(0,_.useState)(`contacted`),[C,w]=(0,_.useState)(o),[T,E]=(0,_.useState)(e.contactName??s??``),[D,O]=(0,_.useState)(null),[k,A]=(0,_.useState)(o),{data:j,isFetching:M}=vi({queryKey:[`lead-search`,T],enabled:t&&c===`link`&&T.trim().length>=2,queryFn:()=>H(`/api/leads?search=${encodeURIComponent(T.trim())}&limit=8`).then(e=>e.data)}),ee=t=>
149{a.invalidateQueries({queryKey:[`conversation-details`,e.id]}),a.invalidateQueries({queryKey:[`conversations`]}),i(),n(!1),z.success(t?`Lead linked â AI auto-reply is on`:`Lead linked`)},N=async()=>{if(!f.trim()||!m.trim()){z.error(`Name and phone are required`);return}d(!0);try{let{status:t,body:n}=await PB(e.id,{action:`create`,name:f.trim(),phone:m.trim(),email:g.trim()||void 0,source:y.trim()||void 0,status:x,enableAi:C});if(t===200&&n.success){ee(n.data?.aiEnabled??!1);return}if(t===409&&n.existingLeadId){n.inTrash?z.info(`That lead is in trash. Restore it, then link.`,{description:`Switching to the link tab.`}):z.info(`A lead with this phone already exists â link it instead.`),l(`link`),E(m.trim());return}z.error(n.error??`Could not create lead`)}finally{d(!1)}},P=async(t,n=!1)=>{d(!0);try{n&&await H(`/api/leads/${t}/restore`,{method:`POST`});let{status:r,body:i}=await PB(e.id,{action:`link`,leadId:t,enableAi:k});if(r===200&&i.success){ee(i.data?.aiEnabled??!1);return}if(r===409&&i.inTrash){z.error(`That lead is in trash. Restore it first.`);return}z.error(i.error??`Could not link lead`)}finally{d(!1)}},F=o&&!!D&&!!s&&LB(D.phone)!==LB(s);return(0,L.jsx)(aj,{open:t,onOpenChange:n,children:(0,L.jsxs)(lj,{className:`sm:max-w-md`,children:[(0,L.jsxs)(uj,{children:[(0,L.jsx)(fj,{children:`Link a lead to this chat`}),(0,L.jsx)(pj,{children:o?`Attach a lead so the CRM shows it and AI auto-reply can run.`:`Attach a lead so this group is associated in the CRM. (AI does not auto-reply in groups.)`})]}),(0,L.jsxs)(KL,{value:c,onValueChange:e=>l(e),children:[(0,L.jsxs)(qL,{className:`grid w-full grid-cols-2`,children:[(0,L.jsx)(JL,{value:`create`,children:`Create new`}),(0,L.jsx)(JL,{value:`link`,children:`Link existing`})]}),(0,L.jsxs)(YL,{value:`create`,className:`space-y-3 pt-2`,children:[(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`ll-name`,children:`Name`}),(0,L.jsx)(G,{id:`ll-name`,value:f,onChange:e=>p(e.target.value),placeholder:`Lead name`})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`ll-phone`,children:`Phone`}),(0,L.jsx)(G,{id:`ll-phone`,value:m,onChange:e=>h(e.target.value),placeholder:`+65â¦`}),!o&&!s&&(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Groups have no contact number â enter the lead's phone, or use âLink existingâ instead.`})]}),(0,L.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`ll-email`,children:`Email (optional)`}),(0,L.jsx)(G,{id:`ll-email`,value:g,onChange:e=>v(e.target.value)})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`ll-source`,children:`Source (optional)`}),(0,L.jsx)(G,{id:`ll-source`,value:y,onChange:e=>b(e.target.value)})]})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{children:`Status`}),(0,L.jsxs)(wk,{value:x,onValueChange:e=>S(e),children:[(0,L.jsx)(Dk,{children:(0,L.jsx)(Ek,{})}),(0,L.jsxs)(Ok,{children:[(0,L.jsx)(Ak,{value:`contacted`,children:`Contacted (already reached out)`}),(0,L.jsx)(Ak,{value:`new`,children:`New`})]})]}),x===`new`&&(0,L.jsxs)(`p`,{className:`flex items-start gap-1.5 text-xs text-amber-600`,children:[(0,L.jsx)(xT,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),`The AI will auto-send the initial outreach within ~2 min. Only use âNewâ for a chat with no outbound messages yet.`]})]}),o&&(0,L.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,L.jsx)(tM,{checked:C,onCheckedChange:e=>w(!!e)}),`Enable AI auto-reply`]}),(0,L.jsxs)(dj,{children:[(0,L.jsx)(W,{variant:`outline`,onClick:()=>n(!1),disabled:u,children:`Cancel`}),(0,L.jsx)(W,{onClick:N,disabled:u,children:`Create & link`})]})]}),(0,L.jsxs)(YL,{value:`link`,className:`space-y-3 pt-2`,children:[(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`ll-search`,children:`Search leads`}),(0,L.jsx)(G,{id:`ll-search`,value:T,onChange:e=>{E(e.target.value),O(null)},placeholder:`Name or phoneâ¦`})]}),(0,L.jsx)(`div`,{className:`max-h-52 overflow-y-auto rounded-md border divide-y`,children:T.trim().length<2?(0,L.jsx)(`p`,{className:`p-3 text-xs text-muted-foreground`,children:`Type at least 2 characters to search.`}):M?(0,L.jsx)(`p`,{className:`p-3 text-xs text-muted-foreground`,children:`Searchingâ¦`}):!j||j.length===0?(0,L.jsx)(`p`,{className:`p-3 text-xs text-muted-foreground`,children:`No matching leads.`}):j.map(e=>(0,L.jsxs)(`button`,{type:`button`,onClick:()=>O(e),className:V(`w-full px-3 py-2 text-left text-sm hover:bg-muted transition-colors`,D?.id===e.id&&`bg-muted`),children:[(0,L.jsx)(`div`,{className:`font-medium`,children:e.name}),(0,L.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[e.phone,` · `,e.status]})]},e.id))}),F&&(0,L.jsxs)(`p`,{className:`flex items-start gap-1.5 text-xs text-amber-600`,children:[(0,L.jsx)(xT,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),`This lead's phone (`,D?.phone,`) differs from the chat's number (`,s,`). Linking anyway is allowed.`]}),o&&(0,L.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,L.jsx)(tM,{checked:k,onCheckedChange:e=>A(!!e)}),`Enable AI auto-reply`]}),(0,L.jsxs)(dj,{children:[(0,L.jsx)(W,{variant:`outline`,onClick:()=>n(!1),disabled:u,children:`Cancel`}),(0,L.jsx)(W,{onClick:()=>D&&P(D.id),disabled:u||!D,children:`Link lead`})]})]})]})]})})}function LB(e){return e.replace(/\D/g,``)}function RB({conversationId:e}){let t=ri(),n=et(),[,r]=jn(),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(`create`),{data:u}=uC.useSession(),d=(e,t)=>{r(n=>{let r=new URLSearchParams(n);return r.set(`conversation`,e),t?r.set(`messageId`,t):r.delete(`messageId`),r})},{data:f,isLoading:p,isError:m,refetch:h}
149=vi({queryKey:[`conversation-details`,e],queryFn:()=>H(`/api/messages/conversations/${e}/details`).then(e=>e.data),retry:2}),g=R({mutationFn:()=>H(`/api/messages/conversations/${e}/ai-toggle`,{method:`POST`}),onSuccess:()=>{t.invalidateQueries({queryKey:[`conversation-details`,e]}),t.invalidateQueries({queryKey:[`conversations`]})}}),{data:v}=vi({queryKey:[`ai-config`,`sg-gate`],staleTime:6e4,queryFn:()=>H(`/api/ai-config/sg-gate`).then(e=>e.data)}),y=R({mutationFn:()=>H(`/api/messages/conversations/${e}/sg-bypass-toggle`,{method:`POST`}),onSuccess:()=>{t.invalidateQueries({queryKey:[`conversation-details`,e]}),t.invalidateQueries({queryKey:[`conversations`]})}});if(p)return(0,L.jsx)(`div`,{className:`flex flex-col h-full w-full lg:border-l bg-background`,children:(0,L.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,L.jsx)(rE,{className:`h-6 w-32`}),(0,L.jsx)(rE,{className:`h-24 w-full`}),(0,L.jsx)(rE,{className:`h-24 w-full`})]})});if(m)return(0,L.jsx)(`div`,{className:`flex flex-col h-full w-full lg:border-l bg-background`,children:(0,L.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center gap-3 p-6`,children:[(0,L.jsx)(xT,{className:`h-6 w-6 text-destructive`}),(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Failed to load details`}),(0,L.jsxs)(W,{variant:`outline`,size:`sm`,onClick:()=>h(),children:[(0,L.jsx)(Yw,{className:`h-3.5 w-3.5 mr-1.5`}),`Retry`]})]})});if(!f)return null;let{conversation:b,lead:x,agent:S,assignment:C,related:w}=f,T=!!x&&!b.isSimulation&&!b.isSandboxTest,E=T&&x?C&&C.status!==`failed`?{id:C.id,agentId:C.agentId,agentName:S?.name??null,leadName:x.name,alternatives:C.alternatives}:{id:`lead:${x.id}`,agentId:S?.id??``,agentName:S?.name??null,leadName:x.name,alternatives:null}:null,D=`${S?`Reassigned`:`Assigned`} from inbox by ${u?.user?.name??`an operator`}`;return(0,L.jsx)(`div`,{className:`flex flex-col h-full w-full lg:border-l bg-background overflow-y-auto`,children:(0,L.jsxs)(`div`,{className:`p-4 space-y-4`,children:[x&&(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{className:`pb-2`,children:(0,L.jsxs)(ND,{className:`text-sm flex items-center justify-between gap-2`,children:[(0,L.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(AT,{className:`h-4 w-4`}),`Lead Info`]}),(0,L.jsxs)(W,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-xs`,onClick:()=>n(`/leads?lead=${x.id}`),title:`Open this lead in the Leads table`,children:[(0,L.jsx)(ow,{className:`h-3 w-3 mr-1`}),`View`]})]})}),(0,L.jsxs)(q,{className:`space-y-2 text-sm`,children:[(0,L.jsx)(`div`,{className:`font-medium`,children:x.name}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,children:[(0,L.jsx)(Vw,{className:`h-3 w-3`}),x.phone]}),x.email&&(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,children:[(0,L.jsx)(Ow,{className:`h-3 w-3`}),x.email]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(zB,{warmth:x.warmth}),(0,L.jsx)(X,{variant:`outline`,children:x.status}),x.qualificationMode&&(0,L.jsx)(X,{variant:`secondary`,children:x.qualificationMode})]}),x.source&&(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,children:[(0,L.jsx)(lw,{className:`h-3 w-3`}),(0,L.jsxs)(`span`,{className:`truncate`,title:`Source: ${x.source}`,children:[`From `,x.source]})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,children:[(0,L.jsx)(FC,{className:`h-3 w-3`}),(0,L.jsxs)(`span`,{className:`truncate`,children:[`Added `,VB(x.sheetDate,x.createdAt)]})]})]})]}),w&&(w.groupConvoId||w.agentDmConvoId)&&(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{className:`pb-2`,children:(0,L.jsxs)(ND,{className:`text-sm flex items-center gap-2`,children:[(0,L.jsx)(Cw,{className:`h-4 w-4`}),`Related conversations`]})}),(0,L.jsx)(q,{className:`p-0`,children:(0,L.jsxs)(`ul`,{className:`divide-y`,children:[w.customerConvoId&&(0,L.jsx)(`li`,{children:(0,L.jsxs)(`button`,{type:`button`,onClick:()=>d(w.customerConvoId),className:V(`w-full flex items-center gap-2 px-4 py-2 text-sm text-left hover:bg-muted transition-colors`,e===w.customerConvoId&&`bg-muted font-medium`),children:[(0,L.jsx)(Nw,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,L.jsx)(`span`,{className:`flex-1 truncate`,children:`Customer 1:1`}),e===w.customerConvoId&&(0,L.jsx)(X,{variant:`outline`,className:`text-[10px]`,children:`current`})]})}),w.groupConvoId&&(0,L.jsx)(`li`,{children:(0,L.jsxs)(`button`,{type:`button`,onClick:()=>d(w.groupConvoId),className:V(`w-full flex items-center gap-2 px-4 py-2 text-sm text-left hover:bg-muted transition-colors`,e===w.groupConvoId&&`bg-muted font-medium`),children:[(0,L.jsx)(MT,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,L.jsx)(`span`,{className:`flex-1 truncate`,children:`Group chat`}),e===w.groupConvoId&&(0,L.jsx)(X,{variant:`outline`,className:`text-[10px]`,children:`current`})]})}),w.agentDmConvoId&&(0,L.jsx)(`li`,{children:(0,L.jsxs)(`button`,{type:`button`,onClick:()=>d(w.agentDmConvoId,w.agentDmDraftMessageId),className:V(`w-full flex items-center gap-2 px-4 py-2 text-sm text-left hover:bg-muted transition-colors`,e===w.agentDmConvoId&&`bg-muted font-medium`),children:[(0,L.jsx)(TT,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,L.jsxs)(`span`,{className:`flex-1 truncate`,children:[`Agent DM`,S?.name?` â ${S.name}`:``]}),e===w.agentDmConvoId&&(0,L.jsx)(X,{variant:`outline`,className:`text-[10px]`,children:`current`})]})})]})})]}),x&&(0,L.jsx)(WA,{lead:{id:x.id,status:x.status,qualificationMode:x.qualificationMode,nextFollowUpAt:x.nextFollowUpAt,scheduleSource:x.scheduleSource,scheduleReason:x.scheduleReason,followUpCount:x.followUpCount,qualificationNudgeCount:x.qualificationNudgeCount,lastContactedAt:x.lastContactedAt},variant:`compact`,onUpdate:()=>
149t.invalidateQueries({queryKey:[`conversation-details`,e]})}),!x&&!b.isSimulation&&!b.isSandboxTest&&(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{className:`pb-2`,children:(0,L.jsxs)(ND,{className:`text-sm flex items-center gap-2`,children:[(0,L.jsx)(Cw,{className:`h-4 w-4`}),`Link a lead`]})}),(0,L.jsxs)(q,{className:`space-y-3`,children:[(0,L.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`This chat isn't linked to a lead.`,` `,b.type===`direct`?`Link one to enable AI auto-reply.`:`Link one to associate this group in the CRM.`]}),(0,L.jsxs)(`div`,{className:`flex gap-2`,children:[(0,L.jsx)(W,{size:`sm`,className:`flex-1`,onClick:()=>{l(`create`),s(!0)},children:`Create new lead`}),(0,L.jsx)(W,{size:`sm`,variant:`outline`,className:`flex-1`,onClick:()=>{l(`link`),s(!0)},children:`Link existing`})]})]})]}),(0,L.jsx)(IB,{conversation:b,open:o,onOpenChange:s,initialTab:c,onSuccess:()=>t.invalidateQueries({queryKey:[`conversation-details`,e]})},b.id),(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{className:`pb-2`,children:(0,L.jsxs)(ND,{className:`text-sm flex items-center gap-2`,children:[(0,L.jsx)(MC,{className:`h-4 w-4`}),`AI Control`]})}),(0,L.jsxs)(q,{className:`space-y-3`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsx)(Z,{htmlFor:`ai-toggle`,className:`text-sm`,children:`Auto-reply`}),(0,L.jsx)(Ck,{id:`ai-toggle`,checked:!!x&&b.aiEnabled,onCheckedChange:()=>g.mutate(),disabled:!x||g.isPending})]}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:x?b.aiEnabled?`AI will automatically respond to incoming messages`:`AI is paused. Incoming messages will not get auto-replies`:`No lead linked â AI cannot reply on this conversation`}),b.flagReason&&(0,L.jsx)(`div`,{className:`flex items-center gap-1`,children:(0,L.jsx)(X,{variant:`destructive`,className:`text-xs`,children:UB(b.flagReason)})}),v?.enabled&&x&&!jB(x.phone)&&(0,L.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,L.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,L.jsx)(X,{variant:`outline`,className:`text-xs`,children:`Gated by SG-only mode`})}),(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsx)(Z,{htmlFor:`sg-bypass-toggle`,className:`text-sm`,children:`Allow AI for this lead`}),(0,L.jsx)(Ck,{id:`sg-bypass-toggle`,checked:b.bypassSgGate,onCheckedChange:()=>y.mutate(),disabled:y.isPending})]}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:b.bypassSgGate?`AI is allowed on this conversation despite the global SG-only mode.`:`AI is skipping this conversation because the lead phone is not Singapore. Toggle on to override.`})]})]})]}),x?.qualificationData&&(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{className:`pb-2`,children:(0,L.jsxs)(ND,{className:`text-sm flex items-center gap-2`,children:[(0,L.jsx)(rT,{className:`h-4 w-4`}),`Qualification`]})}),(0,L.jsx)(q,{className:`space-y-1.5 text-sm`,children:KB(x.qualificationData)})]}),T&&(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{className:`pb-2`,children:(0,L.jsxs)(ND,{className:`text-sm flex items-center justify-between`,children:[(0,L.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(AT,{className:`h-4 w-4`}),`Assigned Agent`]}),(0,L.jsxs)(W,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-xs`,onClick:()=>{t.invalidateQueries({queryKey:[`conversation-details`,e]}),a(!0)},children:[(0,L.jsx)(wC,{className:`h-3 w-3 mr-1`}),S?`Reassign`:`Assign`]})]})}),(0,L.jsx)(q,{className:`space-y-2 text-sm`,children:S?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`span`,{className:`font-medium`,children:S.name}),S.isGroup&&(0,L.jsx)(X,{variant:`outline`,className:`text-[10px]`,children:`Pair`}),C?.overriddenFromAgentId&&(0,L.jsx)(X,{variant:`outline`,className:`text-[10px] text-yellow-700 border-yellow-400`,children:`Overridden`})]}),S.phone&&(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,children:[(0,L.jsx)(Vw,{className:`h-3 w-3`}),S.phone]}),S.specialties&&(0,L.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:S.specialties.map(e=>(0,L.jsx)(X,{variant:`outline`,className:`text-[10px]`,children:e},e))}),C&&(0,L.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:C.overriddenFromAgentId&&C.overrideReason?`Override: ${C.overrideReason}`:C.isArticleAttribution?`Assigned via article attribution`:C.reason})]}):(0,L.jsx)(`div`,{className:`text-muted-foreground`,children:`Unassigned`})})]}),E&&(0,L.jsx)(NB,{assignment:E,allowAllActiveAgents:!0,defaultReason:D,open:i,onOpenChange:a,onSuccess:()=>
149{t.invalidateQueries({queryKey:[`conversation-details`,e]}),t.invalidateQueries({queryKey:[`conversations`]}),t.invalidateQueries({queryKey:[`assignments`]})}}),(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{className:`pb-2`,children:(0,L.jsxs)(ND,{className:`text-sm flex items-center gap-2`,children:[(0,L.jsx)(IC,{className:`h-4 w-4`}),`Conversation`]})}),(0,L.jsxs)(q,{className:`space-y-1.5 text-sm text-muted-foreground`,children:[(0,L.jsxs)(`div`,{className:`flex justify-between`,children:[(0,L.jsx)(`span`,{children:`Type`}),(0,L.jsx)(`span`,{className:`font-medium text-foreground`,children:b.type})]}),(0,L.jsxs)(`div`,{className:`flex justify-between`,children:[(0,L.jsx)(`span`,{children:`Created`}),(0,L.jsx)(`span`,{className:`font-medium text-foreground`,children:new Date(b.createdAt).toLocaleDateString()})]}),(0,L.jsxs)(`div`,{className:`flex justify-between`,children:[(0,L.jsx)(`span`,{children:`Status`}),(0,L.jsx)(`span`,{className:`font-medium text-foreground`,children:b.status})]})]})]})]})})}function zB({warmth:e}){return(0,L.jsx)(X,{variant:`outline`,className:{hot:`bg-red-100 text-red-700 border-red-200`,warm:`bg-orange-100 text-orange-700 border-orange-200`,cold:`bg-blue-100 text-blue-700 border-blue-200`}[e]??``,children:e})}var BB={day:`numeric`,month:`short`,year:`numeric`};function VB(e,t){return HB(e)||new Date(t).toLocaleDateString(void 0,BB)}function HB(e){if(!e)return null;let t=new Date(e);if(!isNaN(t.getTime()))return t.toLocaleDateString(void 0,BB);let n=e.match(/\d{4}-\d{2}-\d{2}T[\d:.]+Z?/);if(n){let e=new Date(n[0]);if(!isNaN(e.getTime()))return e.toLocaleDateString(void 0,BB)}let r=e.match(/\d{4}-\d{2}-\d{2}/);if(r){let e=new Date(r[0]);if(!isNaN(e.getTime()))return e.toLocaleDateString(void 0,BB)}return null}function UB(e){return{manual:`Flagged for review`,bad_ai_reply:`Bad AI reply`,ai_stuck:`AI stuck`,human_escalated:`Needs human`,prompt_injection_suspected:`Prompt injection suspected`,assignment_failed:`Assignment failed`}[e]??e}var WB={"0-3months":`0â3 Months`,"3-6months":`3â6 Months`,">6months":`>6 Months`,flexible:`Flexible / Exploring`,unknown:`Unknown`};function GB(e,t){return e===`timeline`&&typeof t==`string`?WB[t]??t:String(t)}function KB(e){return[{key:`openToConsultation`,label:`Open to consultation`},{key:`timeline`,label:`Timeline`},{key:`budget`,label:`Budget`},{key:`propertyType`,label:`Property type`},{key:`transactionType`,label:`Transaction`},{key:`districts`,label:`Districts`}].filter(t=>e[t.key]!=null).map(t=>(0,L.jsxs)(`div`,{className:`flex justify-between`,children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:t.label}),(0,L.jsx)(`span`,{className:`font-medium text-foreground text-right max-w-[60%] truncate`,children:GB(t.key,e[t.key])})]},t.key))}function qB({open:e,onOpenChange:t,bindings:n}){let r=ZB(n);return(0,L.jsx)(aj,{open:e,onOpenChange:t,children:(0,L.jsxs)(lj,{className:`max-w-md`,children:[(0,L.jsxs)(uj,{children:[(0,L.jsx)(fj,{children:`Keyboard shortcuts`}),(0,L.jsxs)(pj,{children:[`Press `,(0,L.jsx)(JB,{children:`?`}),` anytime to show this list.`]})]}),(0,L.jsx)(`div`,{className:`space-y-4`,children:r.map(([e,t])=>(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2`,children:e}),(0,L.jsx)(`ul`,{className:`space-y-1.5`,children:t.map((t,n)=>(0,L.jsxs)(`li`,{className:`flex items-center justify-between gap-4 text-sm`,children:[(0,L.jsx)(`span`,{className:`text-foreground`,children:t.description??``}),(0,L.jsx)(`span`,{className:`flex items-center gap-1 shrink-0`,children:YB(t.keys).map((e,t)=>(0,L.jsx)(JB,{children:e},t))})]},`${e}-${n}`))})]},e))})]})})}function JB({children:e}){return(0,L.jsx)(`kbd`,{className:`inline-flex items-center justify-center min-w-[1.5rem] h-6 px-1.5 rounded border bg-muted text-[11px] font-mono font-medium text-foreground`,children:e})}function YB(e){return(Array.isArray(e)?e[0]:e).split(`+`).map(XB)}function XB(e){let t=e.toLowerCase();return t===`mod`?navigator.platform.match(/Mac|iPod|iPhone|iPad/)?`Cmd`:`Ctrl`:t===`cmd`||t===`meta`?`Cmd`:t===`ctrl`||t===`control`?`Ctrl`:t===`shift`?`Shift`:t===`alt`||t===`option`?`Alt`:t===`enter`?`Enter`:t===`escape`?`Esc`:t===`arrowup`?`â`:t===`arrowdown`?`â`:e.length===1?e.toUpperCase():e}function ZB(e){let t=new Map;for(let n of e){if(!n.description)continue;let e=n.group??`Other`,r=t.get(e);r?r.push(n):t.set(e,[n])}return Array.from(t.entries())}function QB({selectedCount:e,isPending:t,onResolve:n,onFlag:r,onUnflag:i,onExportCsv:a,onExitSelectMode:o,overLimitWarning:s}){let c=e===0||t;return(0,L.jsxs)(`div`,{role:`toolbar`,"aria-label":`Bulk conversation actions`,className:`border-t bg-background px-3 py-2 shrink-0 space-y-1.5`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,L.jsxs)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:[e,` selected`]}),(0,L.jsx)(W,{type:`button`,variant:`ghost`,size:`icon`,onClick:o,className:`h-9 w-9 text-muted-foreground -mr-1`,"aria-label":`Exit select mode`,children:(0,L.jsx)(FT,{className:`h-4 w-4`})})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2 overflow-x-auto md:flex-wrap -mx-1 px-1 pb-0.5`,children:[(0,L.jsxs)(W,{type:`button`,variant:`outline`,size:`sm`,onClick:n,disabled:c,
149className:`h-8 text-xs shrink-0`,children:[(0,L.jsx)(GC,{className:`h-3.5 w-3.5 mr-1`}),`Resolve`]}),(0,L.jsxs)(Uj,{children:[(0,L.jsx)(Wj,{asChild:!0,children:(0,L.jsxs)(W,{type:`button`,variant:`outline`,size:`sm`,disabled:c,className:`h-8 text-xs shrink-0`,children:[(0,L.jsx)(uw,{className:`h-3.5 w-3.5 mr-1`}),`Flag`,(0,L.jsx)(zC,{className:`h-3 w-3 ml-1`})]})}),(0,L.jsxs)(Gj,{align:`start`,children:[(0,L.jsx)(Kj,{onClick:()=>r(`manual`),children:`Flag for review`}),(0,L.jsx)(Kj,{onClick:()=>r(`bad_ai_reply`),children:`Bad AI reply`})]})]}),(0,L.jsxs)(W,{type:`button`,variant:`outline`,size:`sm`,onClick:i,disabled:c,className:`h-8 text-xs shrink-0`,children:[(0,L.jsx)(uw,{className:`h-3.5 w-3.5 mr-1 rotate-180`}),`Unflag`]}),(0,L.jsxs)(W,{type:`button`,variant:`outline`,size:`sm`,onClick:a,disabled:e===0,className:`h-8 text-xs shrink-0`,children:[(0,L.jsx)(iw,{className:`h-3.5 w-3.5 mr-1`}),`Export CSV`]})]}),s&&(0,L.jsx)(`p`,{className:`text-[11px] text-destructive`,children:s})]})}function $B({open:e,onOpenChange:t,onCreated:n}){let{groupOpsEnabled:r,groupCreateQuota:i}=kN(),a=SR(i),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)([]),[u,d]=(0,_.useState)(null),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(null),[y,b]=(0,_.useState)(null),x=R({mutationFn:async e=>{let t=tB(c),n={name:o.trim(),participants:t};e&&(n.confirmations={overwriteAssignment:f,disableAi:m});let r=await fetch(`/api/groups`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)});if(r.status===401)throw window.location.href=`/login`,Error(`Session expired`);return r.json()},onSuccess:e=>{if(e.success){e.data.couldNotAdd.length>0?(v(e.data.couldNotAdd),b(e.data.conversationId),z.success(`Group created â some contacts need an invite link`)):(z.success(`Group created`),w(e.data.conversationId));return}if(`needsConfirmation`in e){d(e.conflicts),e.conflicts.assignment&&p(!1),e.conflicts.ai1to1&&h(!1);return}z.error(e.error||`Failed to create group`)},onError:e=>z.error(e.message||`Failed to create group`)}),S=()=>{s(``),l([]),d(null),p(!1),h(!1),v(null),b(null)},C=()=>{S(),t(!1)},w=e=>{S(),t(!1),n(e)},T=o.trim().length>0&&c.length>0&&!x.isPending&&r&&!a,E=c.filter(e=>e.kind===`lead`).length,D=c.filter(e=>e.kind===`agent`).length,O=E>=1&&D>=1,k=c.find(e=>e.kind===`lead`)?.label;return g?(0,L.jsx)(aj,{open:e,onOpenChange:e=>e?null:C(),children:(0,L.jsx)(lj,{className:`max-w-md`,children:(0,L.jsx)(rB,{title:`Group created`,description:`These contacts couldn't be added automatically (their privacy settings). Send them the invite link yourself.`,items:g,onDone:()=>y&&w(y)})})}):(0,L.jsx)(aj,{open:e,onOpenChange:e=>e?null:C(),children:(0,L.jsxs)(lj,{className:`max-w-md`,children:[(0,L.jsxs)(uj,{children:[(0,L.jsxs)(fj,{className:`flex items-center gap-2`,children:[(0,L.jsx)(MT,{className:`h-4 w-4`}),` New group`]}),(0,L.jsx)(pj,{children:`Create a WhatsApp group. Pick leads, agents, or add a phone number.`})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`group-name`,children:`Group name`}),(0,L.jsx)(G,{id:`group-name`,value:o,onChange:e=>s(e.target.value),placeholder:`e.g. Stacked Chat - John Tan`,autoFocus:!0})]}),(0,L.jsx)(nB,{open:e,selected:c,onChange:l}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`The Stacked main number is added to every group automatically.`}),i&&(0,L.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[i.used,` of `,i.cap,` daily group creates used.`]}),O&&(0,L.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-amber-300 bg-amber-50 px-3 py-2 text-sm text-amber-900`,children:[(0,L.jsx)(xT,{className:`h-4 w-4 shrink-0 mt-0.5`}),(0,L.jsxs)(`span`,{children:[`This looks like an agent handoff. To auto-send the agent's intro, photo & brief, use the green `,(0,L.jsx)(`strong`,{children:`Create group`}),` `,`button on `,k??`the lead`,`'s chat. Creating it here makes an `,(0,L.jsx)(`strong`,{children:`empty`}),` group you'll have to fill manually.`]})]}),u&&(u.assignment||u.ai1to1)&&(0,L.jsxs)(`div`,{className:`border rounded-md p-3 space-y-3 bg-amber-50 border-amber-200`,children:[(0,L.jsx)(`p`,{className:`text-sm font-medium text-amber-900`,children:`Please confirm`}),u.assignment&&(0,L.jsxs)(`label`,{className:`flex items-start gap-2 text-sm`,children:[(0,L.jsx)(tM,{checked:f,onCheckedChange:e=>p(e===!0),className:`mt-0.5`}),(0,L.jsxs)(`span`,{children:[`Reassign this lead from `,(0,L.jsx)(`strong`,{children:u.assignment.currentAgentName}),` to`,` `,(0,L.jsx)(`strong`,{children:u.assignment.newAgentName})]})]}),u.ai1to1&&(0,L.jsxs)(`label`,{className:`flex items-start gap-2 text-sm`,children:[(0,L.jsx)(tM,{checked:m,onCheckedChange:e=>h(e===!0),className:`mt-0.5`}),(0,L.jsx)(`span`,{children:`Turn off AI for the lead's existing 1:1 chat`})]})]}),!r&&(0,L.jsx)(`div`,{className:`rounded-md border border-amber-300 bg-amber-50 px-3 py-2 text-sm text-amber-900`,children:`Group creation is temporarily disabled â please create the group manually on WhatsApp.`}),r&&a&&i&&(0,L.jsxs)(`div`,{className:`rounded-md border border-amber-300 bg-amber-50 px-3 py-2 text-sm text-amber-900`,children:[`Daily group creation limit reached (`,i.used,`/`,i.cap,`) - please create the group manually on WhatsApp.`]}),(0,L.jsxs)(dj,{children:[(0,L.jsx)(W,{type:`button`,variant:`ghost`,onClick:C,children:`Cancel`}),(0,L.jsxs)(W,{type:`button`,onClick:()=>x.mutate(u!==null),disabled:!T,className:`gap-2`,children:[(0,L.jsx)(MT,{className:`h-4 w-4`}),x.isPending?`Creating...`:u?`Confirm & create`:`Create group`]})]})]})})}function eV({open:e,onOpenChange:t,onCreated:n}){let[r,i]=(0,_.useState)(``),[a,o]=(0,_.useState)(!1),s=r.replace(/[^\d]/g,``),
149c=vi({queryKey:[`new-chat-lead-preview`,s],enabled:e&&s.length>=6,queryFn:async()=>H(`/api/leads?${new URLSearchParams({limit:`1`,search:s}).toString()}`),staleTime:5e3}),l=c.data?.data?.[0]??null,u=R({mutationFn:async()=>{let e=await fetch(`/api/conversations`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify({phone:r.trim(),aiEnabled:a})});if(e.status===401)throw window.location.href=`/login`,Error(`Session expired`);return e.json()},onSuccess:e=>{if(e.success){z.success(e.data.existed?`Opened existing chat`:`Chat started`),p(e.data.conversationId);return}z.error(e.error||`Couldn't start the chat`)},onError:e=>z.error(e.message||`Couldn't start the chat`)}),d=()=>{i(``),o(!1)},f=()=>{d(),t(!1)},p=e=>{d(),t(!1),n(e)},m=s.length>=8&&!u.isPending;return(0,L.jsx)(aj,{open:e,onOpenChange:e=>e?null:f(),children:(0,L.jsxs)(lj,{className:`max-w-md`,children:[(0,L.jsxs)(uj,{children:[(0,L.jsxs)(fj,{className:`flex items-center gap-2`,children:[(0,L.jsx)(Mw,{className:`h-4 w-4`}),` New chat`]}),(0,L.jsx)(pj,{children:`Start a WhatsApp chat with any number. We'll link it to a matching lead if one exists.`})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`new-chat-phone`,children:`Phone number`}),(0,L.jsx)(G,{id:`new-chat-phone`,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&m&&(e.preventDefault(),u.mutate())},placeholder:`e.g. +65 9178 5810`,autoFocus:!0,inputMode:`tel`})]}),s.length>=6&&(0,L.jsx)(`div`,{className:`flex items-center gap-2 text-sm rounded-md border px-3 py-2`,children:l?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(wT,{className:`h-4 w-4 text-emerald-600 shrink-0`}),(0,L.jsxs)(`span`,{className:`truncate`,children:[`Links to lead `,(0,L.jsx)(`strong`,{children:l.name})]})]}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(DT,{className:`h-4 w-4 text-muted-foreground shrink-0`}),(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:c.isLoading?`Checking for a matching lead...`:`No matching lead â starts a new contact`})]})}),(0,L.jsxs)(`label`,{className:`flex items-start gap-2 text-sm`,children:[(0,L.jsx)(tM,{checked:a,onCheckedChange:e=>o(e===!0),className:`mt-0.5`}),(0,L.jsxs)(`span`,{children:[`Let AI draft replies on this chat`,(0,L.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:`Off by default. AI only replies after the lead responds â send your first message yourself.`})]})]}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Past chat history loads in the background after you send the first message.`}),(0,L.jsxs)(dj,{children:[(0,L.jsx)(W,{type:`button`,variant:`ghost`,onClick:f,children:`Cancel`}),(0,L.jsxs)(W,{type:`button`,onClick:()=>u.mutate(),disabled:!m,className:`gap-2`,children:[(0,L.jsx)(Mw,{className:`h-4 w-4`}),u.isPending?`Starting...`:`Start chat`]})]})]})})}function tV(e,t){let n=new URLSearchParams;return e.filter!==`all`&&n.set(`filter`,e.filter),e.channel!==`all`&&n.set(`channel`,e.channel),e.leadsOnly&&n.set(`leadsOnly`,`1`),e.hideDrafts&&n.set(`hideDrafts`,`1`),e.search&&n.set(`q`,e.search),n.set(`limit`,String(t.limit)),n.set(`offset`,String(t.offset)),n.toString()}function nV(e){return[`conversations`,e.filter,e.channel,e.search,e.leadsOnly,e.hideDrafts]}var rV=200,iV=50,aV=[`all`,`open`,`flagged`,`ai_issues`],oV=class extends _.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}render(){return this.state.error?(0,L.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center gap-4 p-8 text-center`,children:[(0,L.jsx)(xT,{className:`h-10 w-10 text-destructive`}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`h3`,{className:`font-semibold text-lg`,children:`Something went wrong`}),(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`The inbox encountered an error. Try refreshing.`})]}),(0,L.jsxs)(W,{variant:`outline`,onClick:()=>this.setState({error:null}),children:[(0,L.jsx)(Yw,{className:`h-4 w-4 mr-2`}),`Try again`]})]}):this.props.children}};function sV(){let{leadLineConnected:e,connected:t,cloudRoutingActive:n,state:r,cloudConnected:i}=kN(),a=MN({leadLineConnected:e,baileysConnected:t,leadLineState:n?
149i?`connected`:`disconnected`:r});return a.tone===`none`?null:(0,L.jsxs)(`div`,{className:V(`border-b px-4 py-2 flex items-center gap-2 text-sm shrink-0`,a.tone===`critical`?`bg-amber-50 border-amber-200 text-amber-800`:`bg-muted/60 border-border text-muted-foreground`),children:[(0,L.jsx)(NT,{className:`h-4 w-4 shrink-0`}),(0,L.jsx)(`span`,{children:a.message})]})}function cV(){return(0,L.jsx)(jN,{children:(0,L.jsx)(oV,{children:(0,L.jsx)(uV,{})})})}var lV=250;function uV(){let[e,t]=jn(),n=e.get(`filter`),r=n!==null&&aV.includes(n)?n:`all`,i=e.get(`channel`)??`all`,a=e.get(`leadsOnly`)===`1`,o=e.get(`hideDrafts`)===`1`,s=e.get(`q`)??``,[c,l]=(0,_.useState)(s),u=e.get(`conversation`),d=KT(),f=GT(),[p,m]=(0,_.useState)(()=>typeof window>`u`?!1:new URLSearchParams(window.location.search).get(`contact`)===`1`?!0:window.matchMedia(`(min-width: ${BT}px)`).matches),h=(0,_.useRef)(!1),g=`inbox.appSidebarAutoCollapsed`,{setOpen:v}=dE(),y=(0,_.useRef)(!1);(0,_.useEffect)(()=>{if(!y.current&&d){try{if(window.localStorage.getItem(g)===`1`){y.current=!0;return}window.localStorage.setItem(g,`1`)}catch{}v(!1),y.current=!0}},[d,v]);let[b,x]=(0,_.useState)(0),[S,C]=(0,_.useState)(!1),[w,T]=(0,_.useState)(!1),[E,D]=(0,_.useState)(!1),{connected:O}=kN(),k=(0,_.useRef)(null),A=ri(),[j,M]=(0,_.useState)(!1),[ee,N]=(0,_.useState)(()=>new Set),[P,F]=(0,_.useState)(null),I=(0,_.useCallback)(()=>{M(!1),N(new Set),F(null)},[]),{fallbackMode:te}=DN(),ne=e=>{t(t=>{let n=new URLSearchParams(t);return e?n.set(`conversation`,e):n.delete(`conversation`),n.delete(`contact`),n}),e&&d&&m(!1)},re=e=>{t(t=>{let n=new URLSearchParams(t);return e===`all`?n.delete(`filter`):n.set(`filter`,e),n},{replace:!0})},ie=e=>{t(t=>{let n=new URLSearchParams(t);return e===`all`?n.delete(`channel`):n.set(`channel`,e),n},{replace:!0})},ae=e=>{t(t=>{let n=new URLSearchParams(t);return e?n.set(`leadsOnly`,`1`):n.delete(`leadsOnly`),n},{replace:!0})},oe=e=>{t(t=>{let n=new URLSearchParams(t);return e?n.set(`hideDrafts`,`1`):n.delete(`hideDrafts`),n},{replace:!0})},se=e=>{l(e)};(0,_.useEffect)(()=>{if(c===s)return;let e=window.setTimeout(()=>{t(e=>{let t=new URLSearchParams(e);return c===``?t.delete(`q`):t.set(`q`,c),t},{replace:!0})},lV);return()=>window.clearTimeout(e)},[c,s,t]),(0,_.useEffect)(()=>
149{l(s)},[s]);let ce=(0,_.useMemo)(()=>({filter:r,channel:i,search:s,leadsOnly:a,hideDrafts:o}),[r,i,s,a,o]),{data:le,isLoading:ue,isError:de,error:fe,refetch:pe,fetchNextPage:me,hasNextPage:he,isFetchingNextPage:ge}=yi({queryKey:nV(ce),initialPageParam:0,queryFn:({pageParam:e})=>H(`/api/messages/conversations?${tV(ce,{limit:iV,offset:e})}`),getNextPageParam:e=>e.nextOffset??void 0,refetchInterval:te?1e4:!1,retry:2}),_e=vi({queryKey:[`conversations`,`counts`,i,s,a],queryFn:()=>{let e=new URLSearchParams;return i!==`all`&&e.set(`channel`,i),a&&e.set(`leadsOnly`,`1`),s&&e.set(`q`,s),H(`/api/messages/conversations/counts?${e.toString()}`).then(e=>e.data)},placeholderData:e=>e,refetchInterval:te?1e4:!1,retry:2}),ve=(0,_.useMemo)(()=>le?le.pages.flatMap(e=>e.data):[],[le]),ye=e.get(`lead`),be=vi({queryKey:[`conversation-by-lead`,ye],enabled:ye!==null,queryFn:()=>H(`/api/messages/conversations?leadId=${encodeURIComponent(ye)}`).then(e=>e.data??[]),staleTime:5e3,retry:1});(0,_.useEffect)(()=>{if(!ye||h.current||!be.isSuccess&&!be.isError)return;h.current=!0;let e=be.data?.[0];e?t(t=>{let n=new URLSearchParams(t);return n.delete(`lead`),n.set(`conversation`,e.id),n},{replace:!0}):(z.error(`No conversation found for this lead`),t(e=>{let t=new URLSearchParams(e);return t.delete(`lead`),t},{replace:!0}))},[ye,be.isSuccess,be.isError,be.data,t]);let xe=(0,_.useRef)(!1);(0,_.useEffect)(()=>{if(ve.length===0){b!==0&&x(0);return}if(u&&!xe.current){let e=ve.findIndex(e=>e.id===u);if(e>=0){xe.current=!0,x(e);return}}b>=ve.length&&x(ve.length-1)},[ve,b,u]);let Se=ve.find(e=>e.id===u)??null,Ce=vi({queryKey:[`conversation-row`,u],enabled:u!==null&&Se===null,queryFn:()=>H(`/api/messages/conversations?ids=${encodeURIComponent(u)}`).then(e=>e.data??[]),staleTime:5e3}),we=Se===null&&u!==null?Ce.data?.find(e=>e.id===u)??null:null,Te=Se??we,Ee=e=>({headers:[`Lead Name`,`Phone`,`Type`,`Status`,`Flagged`,`AI Enabled`,`Last Message`,`Unread`,`Created`],rows:e.map(e=>[e.leadName??`(unknown)`,e.leadPhone??``,e.type,e.status,e.flagged?`Yes`:`No`,e.aiEnabled?`Yes`:`No`,e.lastMessage?.body?.slice(0,100)??``,String(e.unreadCount),new Date(e.createdAt).toISOString()])}),De=()=>{let{headers:e,rows:t}=Ee(ve);Wk(e,t,`conversations-${new Date().toISOString().split(`T`)[0]}.csv`)},Oe=()=>{let e=ve.filter(e=>ee.has(e.id));if(e.length===0){z.error(`No conversations selected`);return}let{headers:t,rows:n}=Ee(e);Wk(t,n,`conversations-selected-${new Date().toISOString().split(`T`)[0]}.csv`)},ke=(e,t,n)=>{if(n&&P!==null){let[e,n]=P<=t?[P,t]:[t,P];N(t=>{let r=new Set(t);for(let t=e;t<=n;t++){let e=ve[t];e&&r.add(e.id)}return r});return}F(t),N(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Ae=R({mutationFn:e=>H(`/api/messages/conversations/bulk`,{method:`POST`,body:JSON.stringify(e)}),onSuccess:(e,t)=>{let n=e.data?.updated??0,r=t.action===`resolve`?`resolved`:t.action===`flag`?`flagged`:`unflagged`;z.success(`${n} conversation${n===1?``:`s`} ${r}`),I(),A.invalidateQueries({queryKey:[`conversations`]}
149),t.action===`resolve`&&A.invalidateQueries({queryKey:[`conversation-details`]})},onError:e=>{z.error(e.message||`Bulk action failed`)}}),je=ee.size,Me=je>rV?`Only the first ${rV} will be updated per request â narrow your selection.`:null,Ne=(e,t)=>{if(je===0)return;let n=Array.from(ee).slice(0,rV);Ae.mutate({ids:n,action:e,reason:t})},Pe=f?[]:[{keys:`j`,group:`Navigation`,description:`Next conversation`,handler:e=>{e.preventDefault(),x(e=>Math.min(e+1,Math.max(ve.length-1,0)))}},{keys:`k`,group:`Navigation`,description:`Previous conversation`,handler:e=>{e.preventDefault(),x(e=>Math.max(e-1,0))}},{keys:`Enter`,group:`Navigation`,description:`Open focused conversation`,handler:e=>{let t=ve[b];t&&(e.preventDefault(),ne(t.id))}},{keys:`/`,group:`Navigation`,description:`Focus search`,handler:e=>{e.preventDefault(),k.current?.focusSearch()}},{keys:`Escape`,group:`Actions`,description:`Close modal / exit select mode / blur search`,handler:()=>{if(S){C(!1);return}if(j){I();return}let e=document.activeElement;e instanceof HTMLElement&&e.blur()}},{keys:[`?`,`shift+/`],group:`Actions`,description:`Show keyboard shortcuts`,handler:e=>{e.preventDefault(),C(e=>!e)}}];return ME(Pe,!S),(0,L.jsxs)(`div`,{className:`-m-6 flex flex-col h-[calc(100vh-3.5rem)]`,children:[(0,L.jsx)(sV,{}),te&&(0,L.jsxs)(`div`,{className:`bg-slate-50 border-b border-slate-200 px-4 py-1.5 flex items-center gap-2 text-slate-700 text-xs shrink-0`,children:[(0,L.jsx)(qw,{className:`h-3.5 w-3.5 shrink-0`}),(0,L.jsx)(`span`,{children:`Live updates paused â retrying. Falling back to polling.`})]}),(0,L.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,L.jsxs)(`div`,{className:V(`flex-col min-h-0 md:flex md:w-80 md:shrink-0`,u?`hidden`:`flex flex-1`),children:[(0,L.jsx)(wR,{ref:k,conversations:ve,counts:_e.data,selectedId:u,onSelect:ne,filter:r,onFilterChange:re,channel:i,onChannelChange:ie,leadsOnly:a,onLeadsOnlyChange:ae,hideDrafts:o,onHideDraftsChange:oe,search:c,onSearchChange:se,focusedIndex:b,onFocusedIndexChange:x,isLoading:ue,isError:de,onRetry:()=>pe(),onExport:De,hasNextPage:he,isFetchingNextPage:ge,onEndReached:()=>{he&&!ge&&me()},selectMode:j,onEnterSelectMode:()=>M(!0),selectedIds:ee,onToggleSelection:ke,onNewGroup:()=>T(!0),onNewChat:()=>D(!0),whatsappConnected:O}),j&&(0,L.jsx)(QB,{selectedCount:je,isPending:Ae.isPending,onResolve:()=>Ne(`resolve`),onFlag:e=>Ne(`flag`,e),onUnflag:()=>Ne(`unflag`),onExportCsv:Oe,onExitSelectMode:I,overLimitWarning:Me})]}),(0,L.jsx)(`div`,{className:V(`flex-col min-w-0 md:flex md:flex-1`,u?`flex flex-1`:`hidden`),children:Te?(0,L.jsx)(AB,{conversation:Te,sidebarOpen:p,onToggleSidebar:()=>m(e=>!e),onBackMobile:()=>ne(null),realtimeFallback:te,hideDrafts:o}):(0,L.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-muted-foreground`,children:ue?(0,L.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,children:[(0,L.jsx)(Yw,{className:`h-5 w-5 animate-spin`}),(0,L.jsx)(`span`,{className:`text-sm`,children:`Loading conversations...`})]}):de?(0,L.jsxs)(`div`,{className:`flex flex-col items-center gap-3 text-center`,children:[(0,L.jsx)(xT,{className:`h-8 w-8 text-destructive`}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`p`,{className:`font-medium text-foreground`,children:`Failed to load conversations`}),(0,L.jsx)(`p`,{className:`text-sm mt-1`,children:fe?.message??`Please try again`})]}),(0,L.jsxs)(W,{variant:`outline`,size:`sm`,onClick:()=>pe(),children:[(0,L.jsx)(Yw,{className:`h-4 w-4 mr-2`}),`Retry`]})]}):`Select a conversation to view messages`})}),Te&&!d&&p&&(0,L.jsx)(`div`,{className:`hidden lg:flex flex-col min-w-0 lg:w-80 lg:shrink-0`,children:(0,L.jsx)(RB,{conversationId:Te.id})})]}),Te&&d&&(0,L.jsx)(YT,{open:p,onOpenChange:m,children:(0,L.jsxs)($T,{side:`right`,className:`w-full sm:max-w-[420px] p-0 overflow-y-auto`,children:[(0,L.jsx)(tE,{className:`sr-only`,children:`Conversation details`}),(0,L.jsx)(RB,{conversationId:Te.id})]})}),!f&&(0,L.jsx)(qB,{open:S,onOpenChange:C,bindings:Pe}),(0,L.jsx)($B,{open:w,onOpenChange:T,onCreated:e=>{A.invalidateQueries({queryKey:[`conversations`]}),ne(e)}}),(0,L.jsx)(eV,{open:E,onOpenChange:D,onCreated:e=>
149{A.invalidateQueries({queryKey:[`conversations`]}),ne(e)}})]})}var dV=50,fV={lead_scored:`Lead Scored`,lead_synced:`Lead Synced`,lead_resubmitted:`Lead Re-submitted`,message_sent:`Message Sent`,message_received:`Message Received`,outreach_started:`Outreach Started`,follow_up_sent:`Follow-up Sent`,response_classified:`Response Classified`,sheets_polled:`Sheets Polled`,whatsapp_event:`WhatsApp`,conversation_created_group_join:`Group Joined`,widget_look_updated:`Widget Settings`,error:`Error`},pV=[`lead_scored`,`lead_synced`,`lead_resubmitted`,`message_sent`,`message_received`,`outreach_started`,`follow_up_sent`,`response_classified`,`sheets_polled`,`whatsapp_event`,`conversation_created_group_join`,`widget_look_updated`,`error`];function mV(){let[e,t]=(0,_.useState)(0),[n,r]=(0,_.useState)(new Set),[i,a]=(0,_.useState)(new Set),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)(``),[m,h]=(0,_.useState)(!1);(0,_.useEffect)(()=>{let e=setTimeout(()=>{l(o),t(0)},300);return()=>clearTimeout(e)},[o]),(0,_.useEffect)(()=>{t(0)},[n,u,f]);let g=new URLSearchParams;g.set(`limit`,String(dV)),g.set(`offset`,String(e*dV)),c&&g.set(`search`,c),n.size>0&&g.set(`type`,[...n].join(`,`)),u&&g.set(`dateFrom`,u),f&&g.set(`dateTo`,f);let{data:v,isLoading:y}=vi({queryKey:[`activity`,e,c,[...n].sort().join(`,`),u,f],queryFn:()=>H(`/api/activity?${g.toString()}`)}),b=v?.entries??[],x=v?.total??0,S=Math.max(1,Math.ceil(x/dV)),C=e=>{a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},w=async()=>{h(!0);try{let e=new URLSearchParams;e.set(`limit`,`10000`),e.set(`offset`,`0`),c&&e.set(`search`,c),n.size>0&&e.set(`type`,[...n].join(`,`)),u&&e.set(`dateFrom`,u),f&&e.set(`dateTo`,f);let t=await H(`/api/activity?${e.toString()}`),r=e=>`"${e.replace(/"/g,`""`)}"`,i=[[`Timestamp`,`Type`,`Description`,`Details`].map(r).join(`,`),...t.entries.map(e=>[new Date(e.timestamp).toISOString(),fV[e.type]??e.type,e.description,e.details??``].map(r).join(`,`))].join(` 150`),a=new Blob([i],{type:`text/csv;charset=utf-8;`}),o=URL.createObjectURL(a),s=document.createElement(`a`);s.href=o,s.download=`activity-log-${new Date().toISOString().split(`T`)[0]}.csv`,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(o)}catch(e){console.error(`Failed to export CSV:`,e)}finally{h(!1)}},T=c||n.size>0||u||f,E=()=>{s(``),l(``),r(new Set),d(``),p(``),t(0)},D=e=>{let t=new Date,n=t.toISOString().split(`T`)[0];switch(e){case`today`:d(n),p(n);break;case`yesterday`:{let e=new Date(t);e.setDate(e.getDate()-1);let n=e.toISOString().split(`T`)[0];d(n),p(n);break}case`7d`:{let e=new Date(t);e.setDate(e.getDate()-7),d(e.toISOString().split(`T`)[0]),p(n);break}case`30d`:{let e=new Date(t);e.setDate(e.getDate()-30),d(e.toISOString().split(`T`)[0]),p(n);break}}};return(0,L.jsxs)(`div`,{className:`space-y-6`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,L.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Activity Log`}),(0,L.jsx)(sA,{interval:`on demand`}),(0,L.jsxs)(W,{variant:`outline`,size:`sm`,onClick:w,disabled:m,children:[(0,L.jsx)(iw,{className:`mr-1.5 h-4 w-4`}),m?`Exporting...`:`Export CSV`]})]}),(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`All AI agent actions and system events`})]}),(0,L.jsxs)(`div`,{className:`space-y-3`,children:[(0,L.jsxs)(`div`,{className:`relative max-w-md`,children:[(0,L.jsx)($w,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground`}),(0,L.jsx)(G,{placeholder:`Search activity...`,value:o,onChange:e=>s(e.target.value),className:`pl-9 pr-9`}),o&&(0,L.jsx)(`button`,{onClick:()=>{s(``),l(``)},className:`absolute right-2.5 top-2.5 text-muted-foreground hover:text-foreground`,children:(0,L.jsx)(FT,{className:`h-4 w-4`})})]}),(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,L.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:`Date:`}),(0,L.jsx)(W,{variant:`outline`,size:`sm`,onClick:()=>D(`today`),className:V(u===new Date().toISOString().split(`T`)[0]&&f===new Date().toISOString().split(`T`)[0]&&`bg-primary text-primary-foreground hover:bg-primary/90 hover:text-primary-foreground`),children:`Today`}),(0,L.jsx)(W,{variant:`outline`,size:`sm`,onClick:()=>D(`yesterday`),children:`Yesterday`}),(0,L.jsx)(W,{variant:`outline`,size:`sm`,onClick:()=>D(`7d`),children:`Last 7 days`}),(0,L.jsx)(W,{variant:`outline`,size:`sm`,onClick:()=>D(`30d`),children:`Last 30 days`}),(0,L.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:`|`}),(0,L.jsx)(G,{type:`date`,value:u,onChange:e=>d(e.target.value),className:`h-8 w-auto text-sm`,placeholder:`From`}),(0,L.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:`to`}),(0,L.jsx)(G,{type:`date`,value:f,onChange:e=>p(e.target.value),className:`h-8 w-auto text-sm`,placeholder:`To`}),(u||f)&&(0,L.jsx)(`button`,{onClick:()=>{d(``),p(``)},className:`text-muted-foreground hover:text-foreground`,children:(0,L.jsx)(FT,{className:`h-4 w-4`})})]}),(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,L.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:`Type:`}),(0,L.jsx)(W,{variant:n.size===0?`default`:`outline`,size:`sm`,onClick:()=>r(new Set),children:`All`}),pV.map(e=>(0,L.jsx)(W,{variant:n.has(e)?`default`:`outline`,size:`sm`,onClick:()=>{r(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},children:fV[e]??e},e))]}),T&&(0,L.jsxs)(W,{variant:`ghost`,size:`sm`,onClick:E,className:`text-muted-foreground`,children:[(0,L.jsx)(FT,{className:`mr-1 h-3 w-3`}),`Clear all filters`]})]}),y?(0,L.jsx)(`div`,{className:`rounded-md border p-8 text-center text-muted-foreground`,children:`Loading...`}):b.length===0?(0,L.jsx)(`div`,{className:`rounded-md border p-8 text-center text-muted-foreground`,children:T?`No activity matches your filters.`:`No activity recorded yet. Events will appear here as the agent runs.`}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[x,` `,x===1?`entry`:`entries`]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(W,{variant:`outline`,size:`sm`,disabled:e===0,onClick:()=>t(e=>e-1),children:`Previous`}),(0,L.jsxs)(`span`,{className:`text-sm text-muted-foreground`,children:[`Page `,e+1,` of `,S]}),(0,L.jsx)(W,{variant:`outline`,size:`sm`,disabled:e+1>=S,onClick:()=>t(e=>e+1),children:`Next`})]})]}),(0,L.jsx)(`div`,{className:`space-y-1`,children:b.map(e=>{let t=i.has(e.id),n=!!e.details;return(0,L.jsx)(`div`,{className:V(`rounded-md px-3 py-2 text-sm`,e.type===`error`?`bg-destructive/10`:`hover:bg-muted/50`),children:(0,L.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,L.jsx)(`span`,{className:`shrink-0 font-mono text-xs text-muted-foreground pt-0.5`,children:new Date(e.timestamp).toLocaleTimeString()}),(0,L.jsx)(X,{variant:e.type===`error`?`destructive`:`outline`,className:`shrink-0`,children:fV[e.type]??e.type}),(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsx)(`p`,{children:e.description}),n&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`button`,{onClick:()=>C(e.id),className:`mt-1 inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,children:[t?(0,L.jsx)(zC,{className:`h-3 w-3`}):(0,L.jsx)(VC,{className:`h-3 w-3`}),t?`Hide details`:`Show details`]}),t&&(0,L.jsx)(`pre`,{className:`mt-1 text-xs text-muted-foreground whitespace-pre-wrap break-all rounded bg-muted/50 p-2`,children:e.details})]})]})]})},e.id)})})]})]})}function hV(){let[e,t]=(0,_.useState)({status:`disconnected`}),[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)({status:`idle`,progress:0,lastRun:null,
150stats:null}),[m,h]=(0,_.useState)({total:0,fullySynced:0,inFlight:0,errored:0,averageDepth:0});(0,_.useEffect)(()=>{let e=()=>{fetch(`/api/whatsapp/status`,{credentials:`include`}).then(e=>e.json()).then(e=>{t({...e.data.baileys,dryRun:e.data.dryRun}),r(e.data.cloudApi)}).catch(e=>{console.error(`[connect] WhatsApp status poll failed:`,e),t({status:`disconnected`})})};e();let n=setInterval(e,5e3);return()=>clearInterval(n)},[]),(0,_.useEffect)(()=>{let e=()=>{H(`/api/whatsapp/history-sync/status`).then(e=>p(e.data)).catch(()=>{})};e();let t=setInterval(e,f.status===`syncing`?3e3:1e4);return()=>clearInterval(t)},[f.status]),(0,_.useEffect)(()=>{let e=()=>{H(`/api/whatsapp/backfill/status`).then(e=>h(e.data)).catch(()=>{})};e();let t=setInterval(e,5e3);return()=>clearInterval(t)},[]);let g=async()=>{d(!0);let n=!e.dryRun;try{await H(`/api/whatsapp/dry-run`,{method:`POST`,body:JSON.stringify({enabled:n})}),t(e=>({...e,dryRun:n}))}catch(e){console.error(`[connect] toggle dry run failed:`,e),z.error(`Failed to toggle dry run mode`)}finally{d(!1)}},v=async()=>{s(!0);try{await H(`/api/whatsapp/disconnect`,{method:`POST`}),t({status:`disconnected`})}catch(e){console.error(`[connect] disconnect failed:`,e),z.error(`Failed to disconnect WhatsApp`)}finally{s(!1)}},y=async()=>{l(!0);try{let e=await H(`/api/whatsapp/reconnect`,{method:`POST`});t(t=>({...t,...e.data})),z.success(`Reconnecting â a QR code will appear here shortly to re-pair.`)}catch(e){console.error(`[connect] reconnect failed:`,e),z.error(`Failed to reconnect WhatsApp`)}finally{l(!1)}},b=async()=>{a(!0);try{let e=await H(`/api/whatsapp/cloud/onboard`,{method:`POST`});r(e.data),e.data.state===`connected`?z.success(`Cloud API line verified and connected`):e.data.state===`not_configured`?z.error(`Cloud API is not configured (set WA_CLOUD_* env vars)`):z.error(e.data.error??`Cloud API onboarding failed â needs reconnect`)}catch(e){console.error(`[connect] Cloud API onboard failed:`,e),z.error(`Failed to run Cloud API onboarding`)}finally{a(!1)}},x=e.status===`connected`?`default`:e.status===`qr_needed`||e.status===`connecting`?`secondary`:`destructive`,S=n?.state===`connected`?`default`:n?.state===`not_configured`?`secondary`:`destructive`;return(0,L.jsxs)(`div`,{className:`space-y-6`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Connect`}),(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`WhatsApp connection settings`})]}),(0,L.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{className:`pb-2`,children:[(0,L.jsx)(PD,{children:`Connection Status`}),(0,L.jsx)(ND,{children:(0,L.jsx)(X,{variant:x,className:`text-base`,children:e.status.replace(`_`,` `)})})]}),(0,L.jsxs)(q,{className:`space-y-2 text-sm`,children:[e.phoneNumber&&(0,L.jsxs)(`p`,{children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`Number: `}),(0,L.jsx)(`span`,{className:`font-mono`,children:e.phoneNumber})]}),e.uptime!==void 0&&(0,L.jsxs)(`p`,{children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`Uptime: `}),gV(e.uptime)]}),e.lastEvent&&(0,L.jsxs)(`p`,{children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`Last event: `}),new Date(e.lastEvent).toLocaleString()]}),e.status===`connected`&&(0,L.jsxs)(lA,{children:[(0,L.jsx)(uA,{asChild:!0,children:(0,L.jsx)(W,{variant:`destructive`,size:`sm`,className:`mt-3`,disabled:o,children:o?`Disconnecting...`:`Disconnect`})}),(0,L.jsxs)(pA,{children:[(0,L.jsxs)(mA,{children:[(0,L.jsx)(gA,{children:`Disconnect WhatsApp?`}),(0,L.jsx)(_A,{children:`You'll need to re-scan the QR code to reconnect.`})]}),(0,L.jsxs)(hA,{children:[(0,L.jsx)(yA,{children:`Cancel`}),(0,L.jsx)(vA,{onClick:v,children:`Disconnect`})]})]})]})]})]}),(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{className:`pb-2`,children:[(0,L.jsx)(PD,{children:`Outbound Messages`}),(0,L.jsx)(ND,{children:(0,L.jsx)(X,{variant:e.dryRun?`secondary`:`destructive`,className:`text-base`,children:e.dryRun?`dry run`:`live`})})]}),(0,L.jsxs)(q,{className:`space-y-2 text-sm`,children:[(0,L.jsx)(`p`,{className:`text-muted-foreground`,children:e.dryRun?`Messages are logged but not sent. Safe for testing.`:`Messages will be sent to real WhatsApp numbers.`}),(0,L.jsx)(W,{variant:e.dryRun?`default`:`destructive`,size:`sm`,className:`mt-1`,disabled:u,onClick:g,children:u?`Updating...`:e.dryRun?`Switch to Live`:`Switch to Dry Run`})]})]}),(0,L.jsxs)(K,{className:`md:col-span-2`,children:[(0,L.jsxs)(MD,{className:`pb-2`,children:[(0,L.jsx)(PD,{children:`WhatsApp Cloud API â 1:1 lead line (old number)`}),(0,L.jsx)(ND,{children:(0,L.jsx)(X,{variant:S,className:`text-base`,children:(n?.state??`not_configured`).replace(/_/g,` `)})})]}),(0,L.jsxs)(q,{className:`space-y-2 text-sm`,children:[(0,L.jsx)(`p`,{className:`text-muted-foreground`,children:`The old number's 1:1 lead line runs on Meta's Cloud API (HTTP, no QR). Verify the configured token and subscribe the webhook here.`}),n?.cloudNumber&&(0,L.jsxs)(`p`,{children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`Number: `}),(0,L.jsx)(`span`,{className:`font-mono`,children:n.cloudNumber})]}),n?.phoneNumberId&&(0,L.jsxs)(`p`,{children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`Phone number ID: `}),(0,L.jsx)(`span`,{className:`font-mono`,children:n.phoneNumberId})]}),n?.reauthorizationRequired&&(0,L.jsx)(`p`,{className:`text-destructive`,children:`Token needs re-authorization â re-run onboarding with a fresh token to restore sending.`}),n?.error&&n.state!==`connected`&&(0,L.jsx)(`p`,{className:`text-destructive`,children:n.error}),n?.checkedAt&&(0,L.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Last checked: `,new Date(n.checkedAt).toLocaleStr
150ing()]}),(0,L.jsx)(W,{variant:`default`,size:`sm`,className:`mt-1`,disabled:i,onClick:b,children:i?`Verifying...`:`Verify / Reconnect`})]})]}),e.status===`connected`&&(0,L.jsxs)(K,{className:`md:col-span-2`,children:[(0,L.jsxs)(MD,{className:`pb-2`,children:[(0,L.jsx)(PD,{children:`Chat History`}),(0,L.jsx)(ND,{className:`text-base`,children:`Per-chat backfill`})]}),(0,L.jsxs)(q,{className:`space-y-3`,children:[(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`A background worker walks each conversation backwards via WhatsApp's on-demand history API. Each chat is capped and marked done once WhatsApp returns no more older messages. Survives restarts; resumes from the last checkpoint.`}),m.total>0?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,L.jsxs)(`span`,{children:[m.fullySynced,` / `,m.total,` chats fully synced`]}),(0,L.jsxs)(`span`,{className:`font-mono`,children:[Math.round(m.fullySynced/m.total*100),`%`]})]}),(0,L.jsx)(`div`,{className:`h-2 rounded-full bg-muted overflow-hidden`,children:(0,L.jsx)(`div`,{className:`h-full rounded-full bg-primary transition-all duration-500`,style:{width:`${Math.max(m.fullySynced/m.total*100,2)}%`}})})]}),(0,L.jsxs)(`div`,{className:`rounded-md border p-3 grid grid-cols-2 gap-x-4 gap-y-1 text-sm text-muted-foreground`,children:[(0,L.jsx)(`span`,{children:`In flight:`}),(0,L.jsx)(`span`,{className:`font-mono text-foreground`,children:m.inFlight}),(0,L.jsx)(`span`,{children:`Errored:`}),(0,L.jsx)(`span`,{className:`font-mono text-foreground`,children:m.errored}),(0,L.jsx)(`span`,{children:`Avg msgs / chat:`}),(0,L.jsx)(`span`,{className:`font-mono text-foreground`,children:m.averageDepth})]})]}):(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No chats yet. The worker will start as soon as conversations are seeded (from initial sync, sheets sync, or new messages).`}),f.lastRun&&(0,L.jsxs)(`p`,{className:`text-xs text-muted-foreground border-t pt-2`,children:[`Last initial sync settled: `,new Date(f.lastRun).toLocaleString(),f.stats&&` â ${f.stats.chatsProcessed} chats, ${f.stats.messagesImported} msgs from WA's initial push`]})]})]}),e.status===`qr_needed`&&e.qrCode&&(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{className:`pb-2`,children:[(0,L.jsx)(PD,{children:`Scan QR Code`}),(0,L.jsx)(ND,{className:`text-lg`,children:`Pair WhatsApp`})]}),(0,L.jsxs)(q,{className:`flex flex-col items-center justify-center gap-3`,children:[(0,L.jsx)(`img`,{src:e.qrCode,alt:`WhatsApp QR Code`,className:`max-w-[256px]`}),(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground text-center max-w-xs`,children:`Open WhatsApp on your phone â Settings â Linked Devices â Link a Device â Scan this QR code`})]})]}),e.status===`circuit_open`&&(0,L.jsxs)(K,{className:`md:col-span-2 border-destructive`,children:[(0,L.jsxs)(MD,{className:`pb-2`,children:[(0,L.jsx)(PD,{children:`Auto-reconnect halted`}),(0,L.jsx)(ND,{className:`text-base`,children:`Circuit breaker open â manual reconnect required`})]}),(0,L.jsxs)(q,{className:`space-y-3 text-sm`,children:[(0,L.jsx)(`p`,{className:`text-muted-foreground`,children:`WhatsApp logged this device out (or a reconnect storm was detected), so automatic reconnection was stopped to avoid worsening a restriction. The linked-device session has been cleared. Click Reconnect to start a fresh pairing â a QR code will appear here to re-link the phone.`}),(0,L.jsx)(W,{variant:`default`,size:`sm`,disabled:c,onClick:y,children:c?`Reconnectingâ¦`:`Reconnect`})]})]}),e.status===`disconnected`&&(0,L.jsx)(K,{children:(0,L.jsx)(q,{className:`flex items-center justify-center py-12 text-muted-foreground text-center`,children:`WhatsApp is not connected. The server will display a QR code here when it starts. Make sure the backend is running.`})})]})]})}function gV(e){let t=Math.floor(e/3600),n=Math.floor(e%3600/60);return t>0?`${t}h ${n}m`:`${n}m`}var _V=`Teasers = sessions shown the teaser card. Opens is measured against views, not teasers - the launcher bubble opens the widget without a teaser, and both teaser triggers can be switched off.`;function vV(e){let t=(e,t,n)=>({label:e,value:t,denominator:n,dropPct:n!=null&&n>0?Math.round((n-t)/n*100):null});return[t(`Views`,e.views,null),t(`Teasers`,e.teasers,e.views),t(`Opens`,e.opens,e.views),t(`Step engagement`,e.steps,e.opens),t(`Submits`,e.submits,e.steps)]}function yV(e){let t=e.filter(e=>e.versionId&&e.views>=1);if(t.length<2)return null;let n=null;for(let e of t)(!n||e.conversionPct>n.conversionPct)&&(n=e);return n}function bV(e){let t=[],n=new Set;for(let r of e){let e=t[t.length-1];if(r.pathId!=null&&e&&e.pathId===r.pathId){e.rows.push(r);continue}let i=r.pathId!=null&&n.has(r.pathId);r.pathId!=null&&n.add(r.pathId),t.push({key:`${r.pathId??`spine`}:${r.nodeId}`,pathId:r.pathId,pathLabel:r.pathLabel,isContinuation:i,rows:[r]})}return t}var xV=e=>
150e.toLocaleString();function SV(e){return e>30?`text-red-600 dark:text-red-400`:e>=10?`text-amber-600 dark:text-amber-400`:`text-muted-foreground`}function CV(e,t){return e<=0?null:Math.round(Math.max(0,Math.min(1,(e-t)/e))*100)}function wV({dropPct:e}){return e==null?null:e<=0?(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`0%`}):(0,L.jsxs)(`span`,{className:SV(e),children:[`â`,e,`%`]})}function TV({value:e,scaleMax:t,className:n}){let r=t>0?e/t*100:0;return(0,L.jsx)(`div`,{className:`h-2 overflow-hidden rounded-full bg-muted`,children:e>0&&(0,L.jsx)(`div`,{className:`h-full rounded-full ${n}`,style:{width:`${r}%`,minWidth:`2px`}})})}var EV=`grid grid-cols-[minmax(0,1fr)_10rem_8.5rem] items-center gap-3 text-sm`;function DV({label:e,value:t,scaleMax:n,dropPct:r}){return(0,L.jsxs)(`div`,{className:EV,children:[(0,L.jsx)(`span`,{className:`font-medium`,children:e}),(0,L.jsx)(TV,{value:t,scaleMax:n,className:`bg-primary`}),(0,L.jsxs)(`div`,{className:`text-right leading-tight`,children:[(0,L.jsx)(`div`,{className:`font-medium tabular-nums`,children:xV(t)}),(0,L.jsx)(`div`,{className:`tabular-nums text-xs`,children:(0,L.jsx)(wV,{dropPct:r})})]})]})}function OV({row:e,scaleMax:t,worstDrop:n}){let r=n!=null&&n.nodeId===e.nodeId,i=e.isBranchPoint&&e.splitDropPct!=null&&e.splitDropPct>0;return(0,L.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,L.jsxs)(`div`,{className:EV,children:[(0,L.jsxs)(`div`,{className:`min-w-0`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,L.jsx)(`span`,{className:`truncate`,title:e.label,children:e.label}),r&&(0,L.jsx)(X,{className:`h-4 shrink-0 gap-0.5 border-transparent bg-amber-600 px-1 text-[10px] font-normal text-white dark:bg-amber-500`,children:`Biggest drop`})]}),e.key&&(0,L.jsx)(`span`,{className:`block truncate font-mono text-[11px] text-muted-foreground`,title:e.key,children:e.key})]}),(0,L.jsx)(TV,{value:e.sessions,scaleMax:t,className:`bg-chart-2`}),(0,L.jsxs)(`div`,{className:`text-right leading-tight`,children:[(0,L.jsxs)(`div`,{className:`tabular-nums text-xs text-muted-foreground`,children:[xV(e.sessions),` sess · `,xV(e.events),` ev`]}),(0,L.jsx)(`div`,{className:`tabular-nums text-xs`,children:e.isPathFirst?e.pathSharePct!=null&&(0,L.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.pathSharePct,`% of split`]}):(0,L.jsx)(wV,{dropPct:e.dropPct})})]})]}),i&&(0,L.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[e.splitDropPct,`% answered but went no further`]})]})}function kV({group:e,scaleMax:t,worstDrop:n}){return(0,L.jsxs)(`div`,{className:`space-y-1.5 border-l-2 border-muted pl-3`,style:{marginLeft:`${e.rows[0]?.depth??1}rem`},children:[!e.isContinuation&&(0,L.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground`,children:e.pathLabel??`Branch`}),e.rows.map(e=>(0,L.jsx)(OV,{row:e,scaleMax:t,worstDrop:n},e.nodeId))]})}function AV({worstDrop:e}){let{kind:t,label:n,dropPct:r,denominator:i,lost:a}=e,o=t===`step`?`"${n}" - ${r}% leave here`:t===`split`?`after answering "${n}" - ${r}% go no further`:`after "${n}" - ${r}% never submit`;return(0,L.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-amber-300 bg-amber-50 px-3 py-2 text-sm text-amber-900 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-200`,children:[(0,L.jsx)(yT,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,L.jsxs)(`p`,{children:[(0,L.jsx)(`span`,{className:`font-medium`,children:`Biggest drop-off:`}),` `,o,` (`,xV(a),` of `,xV(i),`)`]})]})}function jV({legacy:e,versionNumber:t}){return(0,L.jsxs)(`details`,{className:`rounded-md border`,children:[(0,L.jsxs)(`summary`,{className:`cursor-pointer px-3 py-2 text-sm font-medium transition-colors hover:bg-muted/50`,children:[`Legacy steps (`,e.length,`)`]}),(0,L.jsxs)(`div`,{className:`space-y-2 border-t px-3 py-3`,children:[(0,L.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`These step keys have events in this date range but aren't in flow version v`,t,` - most likely renamed or retired questions from an older version.`]}),(0,L.jsx)(`div`,{className:`space-y-1`,children:e.map(e=>(0,L.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,L.jsx)(`span`,{className:`truncate font-mono text-xs text-muted-foreground`,title:e.step,children:e.step}),(0,L.jsxs)(`span`,{className:`shrink-0 tabular-nums text-xs text-muted-foreground`,children:[xV(e.sessions),` sess · `,xV(e.events),` ev`]})]},e.step))})]})]})}function MV({data:e,opens:t,teasers:n,views:r}){let i=Math.max(r,1),a=bV(e.rows),o=CV(r,n),s=CV(r,t);return(0,L.jsxs)(`div`,{className:`space-y-4`,children:[(0,L.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Shaped by v`,e.skeleton.versionNumber,` `,(0,L.jsxs)(`span`,{className:`text-muted-foreground
150/70`,children:[`(`,e.skeleton.source===`deployed`?`deployed`:`selected`,`)`]})]}),e.worstDrop&&(0,L.jsx)(AV,{worstDrop:e.worstDrop}),(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(DV,{label:`Views`,value:r,scaleMax:i}),(0,L.jsx)(DV,{label:`Teasers`,value:n,scaleMax:i,dropPct:o}),(0,L.jsx)(DV,{label:`Opens`,value:t,scaleMax:i,dropPct:s}),a.length===0?(0,L.jsx)(`p`,{className:`py-1 text-sm text-muted-foreground`,children:`This flow version has no measurable questions.`}):a.map(t=>t.pathId==null?(0,L.jsx)(OV,{row:t.rows[0],scaleMax:i,worstDrop:e.worstDrop},t.key):(0,L.jsx)(kV,{group:t,scaleMax:i,worstDrop:e.worstDrop},t.key)),(0,L.jsx)(DV,{label:`Submits`,value:e.submits.sessions,scaleMax:i,dropPct:e.submits.dropPct})]}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:_V}),e.legacy.length>0&&(0,L.jsx)(jV,{legacy:e.legacy,versionNumber:e.skeleton.versionNumber})]})}function NV(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}var PV=e=>e.toLocaleString(),FV=(e,t)=>t>0?Math.round(e/t*100):0,IV=50;function LV(e,t,n){return n&&e>=IV?`top ${e} ${t}s`:`${e} ${t}${e===1?``:`s`}`}var RV=`2020-01-01`,zV=[{id:`7d`,label:`7d`,days:7},{id:`30d`,label:`30d`,days:30},{id:`90d`,label:`90d`,days:90},{id:`all`,label:`All`,days:null}];function BV({widgetId:e,versions:t}){let[n,r]=(0,_.useState)(()=>NV(new Date(Date.now()-720*60*60*1e3))),[i,a]=(0,_.useState)(()=>NV(new Date)),[o,s]=(0,_.useState)(`30d`),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)(e);e!==u&&(d(e),l(null));let f=e=>{let t=new Date;a(NV(t)),r(e.days==null?RV:NV(new Date(t.getTime()-e.days*24*60*60*1e3))),s(e.id)},p=(0,_.useMemo)(()=>n?new Date(`${n}T00:00:00`).toISOString():``,[n]),m=(0,_.useMemo)(()=>i?new Date(`${i}T23:59:59.999`).toISOString():``,[i]),{data:h,isLoading:g,isError:v,refetch:y,isFetching:b}=vi({queryKey:[`analytics`,`widget-funnel`,p,m,e??null,c],queryFn:()=>{let t=new URLSearchParams;return p&&t.set(`from`,p),m&&t.set(`to`,m),e&&t.set(`widget`,e),c&&t.set(`version`,c),H(`/api/analytics/widget-funnel?${t.toString()}`).then(e=>e.data)},staleTime:3e4}),x=!!h&&h.funnel.views===0&&h.funnel.teasers===0&&h.funnel.opens===0&&h.funnel.steps===0&&h.funnel.submits===0,S=(h?.byUtmSource??[]).map(e=>e.value===`unknown`?{...e,value:`(direct)`}:e);return(0,L.jsxs)(`div`,{className:`space-y-6`,children:[h&&(0,L.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 md:grid-cols-4`,children:[(0,L.jsx)(UV,{label:`Sessions`,value:PV(h.funnel.views)}),(0,L.jsx)(UV,{label:`Open rate`,value:`${FV(h.funnel.opens,h.funnel.views)}%`}),(0,L.jsx)(UV,{label:`Submits`,value:PV(h.funnel.submits)}),(0,L.jsx)(UV,{label:`Conversion`,value:`${h.funnel.conversionPct}%`})]}),(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{className:`pb-3`,children:(0,L.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(ND,{className:`text-base`,children:`Funnel analytics`}),(0,L.jsx)(PD,{children:h?.flowFunnel?`Every question in the order visitors answer it, with the drop-off at each step.`:`How visitors move through the widget - views â teasers â opens â step engagement â submits.`})]}),(0,L.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,L.jsx)(`div`,{className:`flex items-center gap-1 self-end rounded-md border p-0.5`,children:zV.map(e=>(0,L.jsx)(W,{type:`button`,variant:o===e.id?`secondary`:`ghost`,size:`sm`,className:`h-7 px-2 text-xs`,onClick:()=>f(e),children:e.label},e.id))}),(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsx)(Z,{htmlFor:`funnel-from`,className:`text-xs`,children:`From`}),(0,L.jsx)(G,{id:`funnel-from`,type:`date`,value:n,max:i,onChange:e=>{r(e.target.value),s(null)},className:`h-8 w-[9.5rem]`})]}),(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsx)(Z,{htmlFor:`funnel-to`,className:`text-xs`,children:`To`}),(0,L.jsx)(G,{id:`funnel-to`,type:`date`,value:i,min:n,max:NV(new Date),onChange:e=>{a(e.target.value),s(null)},className:`h-8 w-[9.5rem]`})]}),e&&t&&t.length>0&&(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsx)(Z,{htmlFor:`funnel-version`,className:`text-xs`,children:`Version`}),(0,L.jsxs)(wk,{value:c??`all`,onValueChange:e=>l(e===`all`?null:e),children:[(0,L.jsx)(Dk,{id:`funnel-version`,className:`h-8 w-[8.5rem]`,children:(0,L.jsx)(Ek,{})}),(0,L.jsxs)(Ok,{children:[(0,L.jsx)(Ak,{value:`all`,children:`All versions`}),t.map(e=>(0,L.jsxs)(Ak,{value:e.id,children:[`v`,e.versionNumber,e.deployed?` (live)`:``]},e.id))]})]})]})]})]})}),(0,L.jsxs)(q,{className:`space-y-6`,children:[g&&(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,L.jsx)(Ew,{className:`h-4 w-4 animate-spin`}),`Loading funnelâ¦`]}
150),v&&(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-sm text-destructive`,children:[(0,L.jsx)(`span`,{children:`Failed to load funnel analytics.`}),(0,L.jsxs)(W,{variant:`outline`,size:`sm`,onClick:()=>y(),children:[(0,L.jsx)(Xw,{className:`mr-1.5 h-3.5 w-3.5`}),`Retry`]})]}),h&&!v&&(0,L.jsx)(L.Fragment,{children:x?(0,L.jsx)(`div`,{className:`py-8 text-center text-sm text-muted-foreground`,children:`No widget activity in this date range yet.`}):(0,L.jsxs)(L.Fragment,{children:[h.flowFunnel?(0,L.jsx)(MV,{data:h.flowFunnel,opens:h.funnel.opens,teasers:h.funnel.teasers,views:h.funnel.views}):(0,L.jsx)(VV,{funnel:h.funnel,scoped:!!e}),b&&(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Updatingâ¦`}),(0,L.jsx)(HV,{rows:h.byVersion}),(0,L.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,L.jsx)(WV,{title:`By language`,dimension:`Locale`,rows:h.byLocale}),(0,L.jsx)(WV,{title:`By UTM source`,dimension:`Source`,rows:S,showConversion:!0,hint:`â(direct)â covers visits with no utm_source - direct, bookmark, or a referrer stripped by the browser (referrers arenât stored).`}),(0,L.jsx)(WV,{title:`Top landing pages`,dimension:`Page`,rows:h.byLandingPage,showConversion:!0,className:`md:col-span-2`})]})]})})]})]})]})}function VV({funnel:e,scoped:t}){let n=vV(e),r=Math.max(e.views,1);return(0,L.jsxs)(`div`,{className:`space-y-3`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,L.jsx)(`span`,{className:`font-medium`,children:`Conversion (submits ÷ views)`}),(0,L.jsxs)(X,{variant:`secondary`,className:`tabular-nums`,children:[e.conversionPct,`%`]})]}),n.map(e=>{let t=e.dropPct;return(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,L.jsx)(`span`,{children:e.label}),(0,L.jsxs)(`span`,{className:`font-medium tabular-nums`,children:[PV(e.value),t!=null&&t>0&&(0,L.jsxs)(`span`,{className:`ml-1.5 text-xs text-muted-foreground`,children:[`â`,t,`%`]})]})]}),(0,L.jsx)(`div`,{className:`h-2 overflow-hidden rounded-full bg-muted`,children:(0,L.jsx)(`div`,{className:`h-full rounded-full bg-primary`,style:{width:`${e.value/r*100}%`}})})]},e.label)}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:_V}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t?`Deploy a version to see the step-by-step funnel - the question order, copy and branches all come from the deployed flow.`:`Open a specific widget's Analytics tab to see the step-by-step funnel.`})]})}function HV({rows:e}){let t=yV(e);return(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(`h3`,{className:`text-sm font-medium`,children:`By version`}),(0,L.jsx)(`div`,{className:`rounded-md border`,children:(0,L.jsx)(`div`,{className:`max-h-[22rem] overflow-auto`,children:(0,L.jsxs)(`table`,{className:`w-full caption-bottom text-sm`,children:[(0,L.jsx)(Fk,{className:`sticky top-0 z-10 bg-card shadow-[0_1px_0_0_var(--border)]`,children:(0,L.jsxs)(Lk,{children:[(0,L.jsx)(J,{children:`Version`}),(0,L.jsx)(J,{className:`text-right`,children:`Views`}),(0,L.jsx)(J,{className:`text-right`,children:`Teasers`}),(0,L.jsx)(J,{className:`text-right`,children:`Opens`}),(0,L.jsx)(J,{className:`text-right`,children:`Steps`}),(0,L.jsx)(J,{className:`text-right`,children:`Submits`}),(0,L.jsx)(J,{className:`text-right`,children:`Leads`}),(0,L.jsx)(J,{className:`text-right`,children:`Conv.`})]})}),(0,L.jsx)(Ik,{children:e.length===0?(0,L.jsx)(Lk,{children:(0,L.jsx)(Y,{colSpan:8,className:`py-6 text-center text-muted-foreground`,children:`No data`})}):e.map(e=>{let n=e.versionId?`${e.widgetName??`Unknown widget`} v${e.versionNumber??`?`}`:`(untagged)`,r=t!=null&&e.versionId===t.versionId;return(0,L.jsxs)(Lk,{children:[(0,L.jsx)(Y,{className:`max-w-[16rem] truncate font-medium`,title:n,children:(0,L.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[n,e.deployed&&(0,L.jsx)(X,{className:`h-4 shrink-0 border-transparent bg-emerald-600 px-1 text-[10px] font-normal text-white dark:bg-emerald-500`,children:`Deployed`}),r&&(0,L.jsxs)(X,{variant:`secondary`,className:`h-4 shrink-0 gap-0.5 px-1 text-[10px] font-normal`,title:`Highest conversion among versions with traffic`,children:[(0,L.jsx)(ST,{className:`h-2.5 w-2.5`}),`Best`]})]})}),(0,L.jsx)(Y,{className:`text-right tabular-nums`,children:PV(e.views)}),(0,L.jsx)(Y,{className:`text-right tabular-nums`,children:PV(e.teasers)}),(0,L.jsx)(Y,{className:`text-right tabular-nums`,children:PV(e.opens)}),(0,L.jsx)(Y,{className:`text-right tabular-nums`,children:PV(e.steps)}),(0,L.jsx)(Y,{className:`text-right tabular-nums`,children:PV(e.submits)}),(0,L.jsx)(Y,{className:`text-right tabular-nums`,children:e.leads==null?`-`:PV(e.leads)}),(0,L.jsxs)(Y,{className:`text-right tabular-nums text-muted-foreground`,children:[e.conversionPct,`%`]})]}
150,e.versionId??`untagged`)})})]})})}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:LV(e.length,`version`,!1)})]})}function UV({label:e,value:t}){return(0,L.jsx)(K,{children:(0,L.jsxs)(q,{className:`p-4`,children:[(0,L.jsx)(`div`,{className:`text-2xl font-semibold tabular-nums`,children:t}),(0,L.jsx)(`div`,{className:`mt-1 text-xs text-muted-foreground`,children:e})]})})}function WV({title:e,dimension:t,rows:n,showConversion:r=!1,hint:i,className:a}){let o=r?4:3;return(0,L.jsxs)(`div`,{className:`space-y-2 ${a??``}`,children:[(0,L.jsxs)(`h3`,{className:`flex items-center gap-1.5 text-sm font-medium`,children:[e,i&&(0,L.jsx)(`span`,{title:i,className:`inline-flex cursor-help`,"aria-label":i,children:(0,L.jsx)(xw,{className:`h-3.5 w-3.5 text-muted-foreground`})})]}),(0,L.jsx)(`div`,{className:`rounded-md border`,children:(0,L.jsx)(`div`,{className:`max-h-[22rem] overflow-auto`,children:(0,L.jsxs)(`table`,{className:`w-full caption-bottom text-sm`,children:[(0,L.jsx)(Fk,{className:`sticky top-0 z-10 bg-card shadow-[0_1px_0_0_var(--border)]`,children:(0,L.jsxs)(Lk,{children:[(0,L.jsx)(J,{children:t}),(0,L.jsx)(J,{className:`text-right`,children:`Sessions`}),(0,L.jsx)(J,{className:`text-right`,children:`Events`}),r&&(0,L.jsx)(J,{className:`text-right`,children:`Conv.`})]})}),(0,L.jsx)(Ik,{children:n.length===0?(0,L.jsx)(Lk,{children:(0,L.jsx)(Y,{colSpan:o,className:`py-6 text-center text-muted-foreground`,children:`No data`})}):n.map(e=>(0,L.jsxs)(Lk,{children:[(0,L.jsx)(Y,{className:`max-w-[18rem] truncate font-medium`,title:e.value,children:e.value}),(0,L.jsx)(Y,{className:`text-right tabular-nums`,children:PV(e.sessions)}),(0,L.jsx)(Y,{className:`text-right tabular-nums`,children:PV(e.events)}),r&&(0,L.jsxs)(Y,{className:`text-right tabular-nums text-muted-foreground`,children:[FV(e.submits??0,e.sessions),`%`]})]},e.value))})]})})}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:LV(n.length,t.toLowerCase(),!0)})]})}function GV(e){try{return new URL(e,`http://preview.invalid`).pathname.startsWith(`/api/`)}catch{return!1}}function KV(){return new Response(JSON.stringify({success:!0,data:{leadId:`preview`,warmth:`warm`,existing:!1}}),{status:200,headers:{"Content-Type":`application/json`}})}function qV(e){try{let t=e.HTMLElement?.prototype,n=t?.focus;if(!t||typeof n!=`function`)return;t.focus=function(...t){let r=e.document;if(!(typeof r?.hasFocus==`function`&&!r.hasFocus()))return n.apply(this,t)}}catch{}}function JV(e,t){let n=e.fetch?.bind(e);e.fetch=((e,t)=>GV(typeof e==`string`?e:e instanceof URL?e.href:e.url)?Promise.resolve(KV()):n?n(e,t):Promise.reject(Error(`fetch unavailable`)));try{let t=e.navigator;if(typeof t.sendBeacon==`function`){let e=t.sendBeacon.bind(t);Object.defineProperty(t,`sendBeacon`,{configurable:!0,value:(t,n)=>GV(String(t))?!0:e(t,n)})}}catch{}try{Object.defineProperty(e,`localStorage`,{configurable:!0,value:{get length(){return t.size},clear:()=>t.clear(),getItem:e=>t.get(e)??null,key:e=>[...t.keys()][e]??null,removeItem:e=>void t.delete(e),setItem:(e,n)=>void t.set(e,String(n))}})}catch{}qV(e)}var YV=1280,XV=`sh-preview-root`;function ZV(e,t){let n=t.getElementById(XV);if(n){try{e.SHWidget?.unmount?.(n)}catch{}n.remove()}}var QV=[{id:`en`,label:`EN`},{id:`zh`,label:`䏿`}],$V=new Set([`name`,`phone`,`intent`,`budget`,`timeline`,`propertyType`,`preferredContact`]),eH=$V,tH=/^[A-Za-z0-9_-]{1,64}$/,nH=1e6,rH={intent:[{value:`buy`,label:{en:`Looking to buy`,zh:`æ³è¦è´ä¹°`}},{value:`sell`,label:{en:`Thinking to sell`,zh:`èèåºå®`}},{value:`both`,label:{en:`Both`,zh:`两è
齿`}}],budget:[{value:`Under $800k`,label:{en:`Under $800k`,zh:`80ä¸ä»¥ä¸`}},{value:`$800k - $1.2M`,label:{en:`$800k â $1.2M`,zh:`80ä¸ â 120ä¸`}},{value:`$1.2M - $2M`,label:{en:`$1.2M â $2M`,zh:`120ä¸ â 200ä¸`}},{value:`$2M - $3M`,label:{en:`$2M â $3M`,zh:`200ä¸ â 300ä¸`}},{value:`Above $3M`,label:{en:`$3M+`,zh:`300ä¸ä»¥ä¸`}},{value:`Not sure yet`,label:{en:`Not sure yet`,zh:`è¿ä¸ç¡®å®`}}],timeline:[{value:`Within 3 months`,label:{en:`Within 3 months`,zh:`3个æå
`}},{value:`3-6 months`,label:{en:`3â6 months`,zh:`3è³6个æ`}},{value:`6-12 months`,label:{en:`6â12 months`,zh:`6è³12个æ`}},{value:`Flexible`,label:{en:`Just planning ahead`,zh:`åªæ¯æåè§å`}}],propertyType:[{value:`HDB`,label:{en:`HDB`,zh:`ç»å±`}},{value:`Condo`,label:{en:`Condo/Apt`,zh:`å
¬å¯`}},{value:`Landed`,label:{en:`Landed`,zh:`æå°ä½å®
`}},{value:`Shophouse`,label:{en:`Shophouse`,zh:`åºå±`}}],preferredContact:[{value:`call`,label:{en:`Call`,zh:`çµè¯`}},{value:`whatsapp`,label:{en:`Whatsapp`,zh:`WhatsApp`}},{value:`doesnt_matter`,label:{en:`Doesn't matter`,zh:`é½å¯ä»¥`}}]};function iH(e){let t=rH[e];return t?new Set(t.map(e=>e.value)):null}var aH=[{id:`phone`,label:`Phone`,description:`Singapore mobile. Required to deploy - it's how an agent reaches the lead.`,kind:`tel`,binding:`phone`,smart:!0},{id:`name`,label:`Name`,description:`Required to deploy. Drives the {name} token in the closing message.`,kind:`text`,binding:`name`,smart:!0},{id:`intent`,label:`Intent`,description:`Buy / sell / both. Single-select - it drives branching and scoring.`,kind:`choice`,binding:`intent`,smart:!0},{id:`budget`,label:`Budget`,description:`Budget band. Feeds warmth scoring and agent assignment.`,kind:`choice`,binding:`budget`,smart:!0},{id:`timeline`,label:`Timeline`,description:`How soon they'll move. Feeds warmth scoring.`,kind:`choice`,binding:`timeline`,smart:!0},{id:`propertyType`,label:`Property type`,description:`HDB / Condo / Landed / Shophouse.`,kind:`choice`,binding:`propertyType`,smart:!0},{id:`preferredContact`,label:`Preferred contact`,description:`Call / WhatsApp. Single-select.`,kind:`choice`,binding:`preferredContact`,smart:!0}],oH=[{id:`custom-choice`,label:`Choice`,description:`Your own question with your own answer buttons. Stored for the agent, never scored.`,kind:`choice`,binding:null,smart:!1}
150,{id:`custom-text`,label:`Free text`,description:`An open answer the lead types. Stored for the agent, never scored.`,kind:`text`,binding:null,smart:!1},{id:`custom-statement`,label:`Statement`,description:`A message with no question - auto-advances after a beat.`,kind:`statement`,binding:null,smart:!1}];[...aH,...oH];var sH={name:`Name`,phone:`Phone`,intent:`Intent`,budget:`Budget`,timeline:`Timeline`,propertyType:`Property type`,preferredContact:`Preferred contact`};function cH(e){if(e.kind===`submit`)return`Closing`;let t=`binding`in e?e.binding:null;if(t)return sH[t]??t;switch(e.kind){case`choice`:return`Choice`;case`text`:return`Free text`;case`statement`:return`Statement`;default:return e.kind}}function lH(e,t){let n=e.kind===`statement`?e.text:e.kind===`submit`?e.closing:e.prompt;return n?.[t]||n?.en||``}function uH(e){return`binding`in e&&e.binding!==null}function dH(e){return e.kind===`tel`||`binding`in e&&e.binding===`phone`?`phone`:`binding`in e&&e.binding===`name`?`name`:null}function fH(e){return e.kind===`statement`||e.kind===`submit`?null:(`binding`in e?e.binding:null)||(`fieldKey`in e?e.fieldKey?.trim():``)||null}function pH(e){if(e.kind===`submit`)return[];if(e.kind!==`choice`||e.multiSelect)return e.next?[e.next]:[];let t=[],n=e.options.length===0;for(let r of e.options)r.next?t.push(r.next):n=!0;return n&&e.next&&t.push(e.next),t}function mH(e,t){return e.multiSelect?e.next:t.next??e.next}function hH(e){let t=new Set,n=[],r=[];for(e.nodes[e.rootNodeId]&&r.push(e.rootNodeId);r.length>0;){let i=r.pop();if(t.has(i))continue;let a=e.nodes[i];if(!a)continue;t.add(i),n.push(i);let o=pH(a).filter(n=>e.nodes[n]&&!t.has(n));for(let e=o.length-1;e>=0;e--)r.push(o[e])}let i=new Map;return n.forEach((e,t)=>i.set(e,t+1)),{order:n,number:i,reachable:t,orphans:Object.keys(e.nodes).filter(e=>!t.has(e))}}function gH(e){let t=new Map,n=(e,n)=>{let r=t.get(e);r?r.push(n):t.set(e,[n])};for(let[t,r]of Object.entries(e.nodes))if(r.kind!==`submit`){if(r.kind===`choice`&&!r.multiSelect){let e=r.options.length===0;for(let i of r.options)i.next?n(i.next,{from:t,via:`option`,optionId:i.id}):e=!0;e&&r.next&&n(r.next,{from:t,via:`next`});continue}r.next&&n(r.next,{from:t,via:`next`})}return t}function _H(e,t){let n=new Set;if(!e.nodes[t])return n;let r=[t];for(;r.length>0;){let t=r.shift();if(n.has(t))continue;let i=e.nodes[t];if(i){n.add(t);for(let t of pH(i))e.nodes[t]&&!n.has(t)&&r.push(t)}}return n}function vH(e){return structuredClone(e)}function yH(e){let{number:t,orphans:n}=hH(e),r=t.size;for(let e of n)t.set(e,++r);for(let[n,r]of Object.entries(e.nodes))r.order=t.get(n)??0;return e.sections.forEach((e,t)=>{e.order=t}),e}function bH(e,t){let n=vH(e);return t(n),yH(n)}var xH=()=>crypto.randomUUID();function SH(e,t,n={}){let r=n.newId??xH,i=n.id??`n_${r()}`,a={id:i,sectionId:t,order:0},o={en:``,zh:``};if(e.kind===`statement`)return{...a,kind:`statement`,text:{...o}};if(e.kind===`tel`)return{...a,kind:`tel`,binding:`phone`,prompt:{en:`What's the best number to reach you at?`,zh:`æä»¬å¯ä»¥æ¨æåªä¸ªå·ç èç³»æ¨ï¼`}};if(e.kind===`text`)return{...a,kind:`text`,binding:e.binding===`name`?`name`:null,...e.binding===`name`?{prompt:{en:`Thanks! Now how may we address you?`,zh:`谢谢ï¼è¯·é®æä»¬è¯¥æä¹ç§°å¼æ¨ï¼`}}:{prompt:{...o},fieldKey:n.fieldKey??``,optional:!0}};let s=((e.binding?rH[e.binding]:void 0)??[]).map((e,t)=>({id:`${i}-opt-${t}`,value:e.value,label:{...e.label}})),c={...a,kind:`choice`,prompt:{...o},binding:e.binding,options:s,multiSelect:!1};return e.binding||(c.fieldKey=n.fieldKey??``),c}function CH(e){let t=new Set;for(let n of Object.values(e.nodes)){if(n.kind!==`choice`&&n.kind!==`text`)continue;let e=n.binding??n.fieldKey;e&&t.add(e)}for(let e=1;;e++){let n=`question${e}`;if(!t.has(n))return n}}function wH(e,t){let n=e.nodes[t];return!n||n.kind===`submit`?!1:n.kind===`choice`&&!n.multiSelect&&n.options.length>0?n.options.some(e=>!e.next):!0}function TH(e,t){e.kind!==`submit`&&(t?e.next=t:delete e.next)}function EH(e,t){let n=structuredClone(e);return n.sectionId=e.sectionId||t,n}function DH(e,t,n){return bH(e,e=>{let r=e.nodes[t];
150if(!r||r.kind===`submit`)return;let i=EH(n,r.sectionId);TH(i,r.next),e.nodes[i.id]=i,TH(r,i.id)})}function OH(e,t,n,r){return bH(e,e=>{let i=e.nodes[t];if(!i||i.kind!==`choice`||i.multiSelect)return;let a=i.options.find(e=>e.id===n);if(!a)return;let o=EH(r,i.sectionId);TH(o,a.next??i.next),e.nodes[o.id]=o,a.next=o.id})}function kH(e,t){return bH(e,e=>{let n=e.nodes[e.rootNodeId],r=EH(t,n?.sectionId??e.sections[0]?.id??``),i=Object.values(e.nodes).find(e=>e.kind===`submit`);TH(r,n?e.rootNodeId:i?.id),e.nodes[r.id]=r,e.rootNodeId=r.id})}function AH(e,t){let n=e.nodes[t];return!n||n.kind===`submit`?!1:Object.keys(e.nodes).length>1}function jH(e){let t=t=>t&&t!==e.id?t:void 0;if(e.kind===`submit`)return;let n=t(e.next);if(n)return n;if(e.kind===`choice`)for(let n of e.options){let e=t(n.next);if(e)return e}}function MH(e,t){if((t=>!!t&&!!e.nodes[t]&&e.nodes[t].kind!==`submit`)(t))return t;let n=Object.values(e.nodes).filter(e=>e.kind!==`submit`);if(n.length===0)return;let r=gH(e),i=n.filter(e=>!r.get(e.id)?.length);return[...i.length>0?i:n].sort((e,t)=>e.order-t.order)[0].id}function NH(e,t){return AH(e,t)?bH(e,e=>{let n=e.nodes[t];if(!n)return;let r=jH(n);for(let n of Object.values(e.nodes)){if(n.id===t||n.kind===`submit`)continue;let e=r&&r!==n.id?r:void 0;if(n.next===t&&TH(n,e),n.kind===`choice`)for(let r of n.options)r.next===t&&(e?r.next=e:delete r.next)}if(delete e.nodes[t],e.rootNodeId===t){let t=MH(e,r);t&&(e.rootNodeId=t)}}):e}function PH(e,t,n,r){return bH(e,e=>{let i=e.nodes[t];i&&(i.kind===`statement`?i.text={...i.text,[n]:r}:i.kind===`submit`?i.closing={...i.closing,[n]:r}:i.prompt={...i.prompt,[n]:r})})}function FH(e){return e.replace(/\s+/g,`_`).replace(/[^A-Za-z0-9_-]/g,``).slice(0,64)}function IH(e,t,n){return bH(e,e=>{let r=e.nodes[t];!r||r.kind!==`choice`&&r.kind!==`text`||r.binding||(r.fieldKey=FH(n))})}function LH(e,t,n){return bH(e,e=>{let r=e.nodes[t];r&&e.sections.some(e=>e.id===n)&&(r.sectionId=n)})}function RH(e,t,n){return bH(e,e=>{let r=e.nodes[t];r?.kind===`text`&&(r.optional=n)})}function zH(e,t,n){return bH(e,e=>{let r=e.nodes[t];!r||r.kind===`submit`||(n&&e.nodes[n]?r.next=n:delete r.next)})}function BH(e,t,n){return bH(e,e=>{let r=e.nodes[t];if(r?.kind===`choice`&&(r.multiSelect=n,n)){if(!r.next){let e=r.options.find(e=>e.next&&e.next!==r.id)?.next;e&&(r.next=e)}for(let e of r.options)delete e.next}})}function VH(e,t){let n=e.nodes[t];return n?.kind===`choice`&&!n.multiSelect&&n.options.some(e=>!!e.next)}function HH(e,t,n){return bH(e,e=>{let r=e.nodes[t];r?.kind===`choice`&&n(r,e)})}function UH(e,t,n,r,i){return HH(e,t,e=>{let t=e.options.find(e=>e.id===n);t&&(t.label={...t.label,[r]:i})})}function WH(e,t,n,r){return HH(e,t,e=>{if(e.binding)return;let t=e.options.find(e=>e.id===n);t&&(t.value=r)})}function GH(e,t,n,r){return HH(e,t,(e,t)=>{if(e.multiSelect)return;let i=e.options.find(e=>e.id===n);i&&(r&&t.nodes[r]?i.next=r:delete i.next)})}function KH(e,t,n,r=xH){return HH(e,t,e=>{e.options.push({id:n.id??`${t}-opt-${r()}`,value:n.value,label:{...n.label}})})}function qH(e,t,n){return HH(e,t,e=>{e.options=e.options.filter(e=>e.id!==n)})}function JH(e){if(!e.binding)return[];let t=rH[e.binding]??[],n=new Set(e.options.map(e=>e.value));return t.filter(e=>!n.has(e.value))}function YH(e,t,n={}){let r=n.newId??xH,i=n.id??`s_${r()}`;return bH(e,e=>{e.sections.push({id:i,title:{en:t,zh:t},order:e.sections.length})})}function XH(e,t,n,r){return bH(e,e=>{let i=e.sections.find(e=>e.id===t);i&&(i.title={...i.title,[n]:r})})}function ZH(e,t,n,r){return bH(e,e=>{let i=e.sections.find(e=>e.id===t);if(!i)return;let a={en:i.progressLabel?.en??``,zh:i.progressLabel?.zh??``,[n]:r};!a.en.trim()&&!a.zh.trim()?delete i.progressLabel:i.progressLabel=a})}function QH(e,t,n){return bH(e,e=>{let r=e.sections.findIndex(e=>e.id===t),i=r+n;if(r<0||i<0||i>=e.sections.length)return;let[a]=e.sections.splice(r,1);e.sections.splice(i,0,a)})}function $H(e){return e.sections.length>1}function eU(e,t,n){return!$H(e)||t===n?e:bH(e,e=>{if(e.sections.some(e=>e.id===n)){e.sections=e.sections.filter(e=>e.id!==t);for(let r of Object.values(e.nodes))r.sectionId===t&&(r.sectionId=n)}})}var tU=new Set([`choice`,`text`,`tel`]),nU=new Set([`statement`,`choice`,`text`,`tel`,`submit`]);function rU(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function iU(e,t){if(!t)return`This flow`;let n=e.nodes[t];
150if(!n)return`Step "${t}"`;let r=hH(e).number.get(t),i=cH(n);return r?`Step ${r} (${i})`:`${i} (not reachable)`}function aU(e,t){let n=iU(t.flow,t.nodeId);switch(e){case`invalid_snapshot`:return t.serverMessage??`This flow is malformed and can't be saved.`;case`too_many_nodes`:return`This flow has too many steps (the limit is 500).`;case`snapshot_too_large`:return`This flow is too large to save (the limit is ${nH/1e3}KB of content).`;case`invalid_field_key`:return`${n} has the field key "${t.detail??``}". Use only letters, numbers, "_" and "-" - no spaces (max 64 characters).`;case`deploy_phoneless_path`:return`A lead can reach ${iU(t.flow,t.detail)} without ever being asked for their phone number. Every branch has to pass through the Phone block.`;case`deploy_nameless_path`:return`A lead can reach ${iU(t.flow,t.detail)} without ever being asked for their name. Every branch has to pass through the Name block.`;case`deploy_optional_phone`:return`${n} is optional, so a lead can skip it - and a lead with no number can't be contacted.`;case`deploy_optional_name`:return`${n} is optional, so a lead can skip it. The name block can't be optional in a deployed flow.`;case`node_id_mismatch`:return`${n} has an inconsistent id and can't be routed to. Delete and re-add it.`;case`missing_root`:return`This flow has no starting step.`;case`unknown_section`:return`${n} belongs to a section that no longer exists. Move it to a section.`;case`dangling_next`:return`${n} points at a step that no longer exists.`;case`dangling_option_next`:return`${n} has an answer branching to a step that no longer exists.`;case`missing_answer_key`:return`${n} has no field key, so the lead's answer would be thrown away.`;case`duplicate_answer_key`:return`${n} reuses the field key "${t.detail??``}", which is already answered earlier on the same path - one of the two answers would be overwritten. Reusing a key is only safe on branches a visitor can't both walk.`;case`cycle_detected`:return t.detail===t.nodeId?`${n} points at itself. A lead who reaches it is sent straight to the closing step, skipping every question after it.`:`${n} loops back to ${iU(t.flow,t.detail)}, an earlier step. A lead can't answer a step twice - they'd be sent straight to the closing step, skipping every question in between.`;case`reserved_field_key`:return`"${t.detail??``}" is a built-in field. Use the built-in ${t.detail??``} block instead of a custom question.`;case`binding_kind_mismatch`:return`${n} would file its answer under the wrong field.`;case`multi_select_forbidden`:return`${n} must be single-select - a combined answer carries no usable signal downstream.`;case`multi_select_option_next`:return`${n} is multi-select, so per-answer branching never runs. Route it with the step's own "Next step" instead.`;case`non_canon_option_value`:return`${n} has the answer value "${t.detail??``}", which isn't one this field accepts. Labels are editable; values are locked.`;case`deploy_missing_phone`:return`No phone question - a lead with no number can't be contacted. Add the Phone block before deploying.`;case`deploy_missing_name`:return`No name question. Add the Name block before deploying.`;case`deploy_unreachable_submit`:return`No closing step is reachable from the start, so the lead would never be saved.`;case`deploy_empty_choice`:return`${n} has no answers, so the lead can't move past it.`;default:return t.serverMessage??`This flow can't be saved.`}}function oU(e){return rU(e)&&typeof e.en==`string`&&typeof e.zh==`string`}function sU(e){if(!rU(e))return[];let t=e.nodes;if(rU(t)&&Object.keys(t).length>500)return[{code:`too_many_nodes`,message:aU(`too_many_nodes`,{flow:e}),severity:`error`}];let n;try{n=JSON.stringify(e)?.length??0}catch{n=nH+1}return n>1e6?[{code:`snapshot_too_large`,message:aU(`snapshot_too_large`,{flow:e}),severity:`error`}]:[]}function cU(e){return rU(e)?typeof e.id!=`string`||!e.id?`has no id`:typeof e.value==`string`?oU(e.label)?e.next!==void 0&&typeof e.next!=`string`?`has an invalid next step`:null:`has no label`:`has no value`:`isn't an object`}function lU(e){let t=[],n=(e,n)=>t.push({code:`invalid_snapshot`,message:e,nodeId:n,severity:`error`});if(!rU(e))return n(`Flow must be an object with rootNodeId, sections and nodes.`),t;if((typeof e.rootNodeId!=`string`||!e.rootNodeId)&&n(`Flow is missing a rootNodeId.`),!Array.isArray(e.sections))n(`Flow is missing its sections list.`);else for(let t of e.sections)if(!rU(t)||typeof t.id!=`string`||!t.id){n(`Every section needs a string id.`);break}
150if(!rU(e.nodes)||Object.keys(e.nodes).length===0)return n(`Flow has no steps.`),t;for(let[t,r]of Object.entries(e.nodes)){if(!rU(r)){n(`Step "${t}" is not an object.`,t);continue}if((typeof r.kind!=`string`||!nU.has(r.kind))&&n(`Step "${t}" has an unknown type "${String(r.kind)}".`,t),r.kind===`choice`){if(!Array.isArray(r.options)){n(`Step "${t}" is missing its answers list.`,t);continue}r.options.forEach((e,r)=>{let i=cU(e);i&&n(`Answer ${r+1} on step "${t}" ${i}.`,t)})}}return t}function uU(e,t){let n=new Set,r=e.rootNodeId;if(!e.nodes[r]||t.has(r))return n;let i=[r];for(;i.length>0;){let r=i.shift();if(n.has(r))continue;let a=e.nodes[r];if(a){n.add(r);for(let r of pH(a))!e.nodes[r]||t.has(r)||n.has(r)||i.push(r)}}return n}function dU(e,t){for(let n of uU(e,t)){let t=e.nodes[n];if(t&&(t.kind===`submit`||pH(t).filter(t=>e.nodes[t]).length===0))return n}return null}function fU(e,t,n){let r=[],i=new Set;if(!e.nodes[t])return r;let a=[t];for(;a.length>0;){let o=a.shift();if(i.has(o))continue;let s=e.nodes[o];if(s){i.add(o),o!==t&&n.has(o)&&r.push(o);for(let t of pH(s))e.nodes[t]&&!i.has(t)&&a.push(t)}}return r}function pU(e){let t=[],n=new Map;for(let[t,r]of Object.entries(e.nodes)){if(!tU.has(r.kind))continue;let e=fH(r);if(!e)continue;let i=n.get(e);i?i.push(t):n.set(e,[t])}let r=new Set;for(let[i,a]of n){if(a.length<2)continue;let n=new Set(a);for(let o of a)for(let a of fU(e,o,n))r.has(a)||(r.add(a),t.push({code:`duplicate_answer_key`,message:aU(`duplicate_answer_key`,{flow:e,nodeId:a,detail:i}),nodeId:a,severity:`error`}))}return t}function mU(e){let t=[],n=new Map,r=new Set;for(let i of Object.keys(e.nodes)){if((n.get(i)??0)!==0)continue;let a=[],o=t=>{n.set(t,1);let r=e.nodes[t],i=r?pH(r).filter(t=>e.nodes[t]):[];a.push({id:t,edges:i,i:0})};for(o(i);a.length>0;){let i=a[a.length-1];if(i.i>=i.edges.length){n.set(i.id,2),a.pop();continue}let s=i.edges[i.i++],c=n.get(s)??0;if(c===1){r.has(i.id)||(r.add(i.id),t.push({code:`cycle_detected`,nodeId:i.id,message:aU(`cycle_detected`,{flow:e,nodeId:i.id,detail:s}),severity:`error`}));continue}c===0&&o(s)}}return t}function hU(e,t){let n=new Set;for(let r of Object.keys(e.nodes))_H(e,r).has(t)&&n.add(r);return n}function gU(e){let t=sU(e);if(t.length>0)return t;let n=lU(e);if(n.length>0)return n;let r=e,i=[],a=new Set(Object.keys(r.nodes)),o=new Set(r.sections.map(e=>e.id)),s=(e,t,n)=>i.push({code:e,nodeId:t,message:aU(e,{flow:r,nodeId:t,detail:n}),severity:`error`});a.has(r.rootNodeId)||s(`missing_root`);for(let[e,t]of Object.entries(r.nodes)){t.id!==e&&s(`node_id_mismatch`,e),o.has(t.sectionId)||s(`unknown_section`,e),t.kind!==`submit`&&t.next&&!a.has(t.next)&&s(`dangling_next`,e);let n=`binding`in t?t.binding:void 0;if((t.kind===`tel`?n===`phone`:t.kind===`text`?n===`name`||n==null:t.kind!==`choice`||n!==`phone`&&n!==`name`)||s(`binding_kind_mismatch`,e),t.kind===`choice`){for(let n of t.options)n.next&&!a.has(n.next)&&s(`dangling_option_next`,e);if(t.multiSelect&&t.options.some(e=>e.next)&&s(`multi_select_option_next`,e),t.binding&&eH.has(t.binding)&&t.multiSelect&&s(`multi_select_forbidden`,e),t.binding){let n=iH(t.binding);if(n)for(let r of t.options)n.has(r.value)||s(`non_canon_option_value`,e,r.value)}}if(!tU.has(t.kind))continue;let r=fH(t);if(!r){s(`missing_answer_key`,e);continue}if(!n&&$V.has(r)&&s(`reserved_field_key`,e,r),!n){let n=`fieldKey`in t&&typeof t.fieldKey==`string`?t.fieldKey:``;tH.test(n)||s(`invalid_field_key`,e,n)}}return i.push(...mU(r)),i.push(...pU(r)),i}function _U(e){let t=[],n=(n,r,i)=>t.push({code:n,nodeId:r,message:aU(n,{flow:e,nodeId:r,detail:i}),severity:`warning`}),r=[...hH(e).reachable].map(t=>e.nodes[t]).filter(Boolean),i=[{is:e=>e.kind===`tel`||`binding`in e&&e.binding===`phone`,missing:`deploy_missing_phone`,bypassed:`deploy_phoneless_path`,optional:`deploy_optional_phone`},{is:e=>`binding`in e&&e.binding===`name`,missing:`deploy_missing_name`,bypassed:`deploy_nameless_path`,optional:`deploy_optional_name`}];for(let t of i){let i=r.filter(t.is);if(i.length===0){n(t.missing);continue}let a=dU(e,new Set(i.map(e=>e.id)));a&&n(t.bypassed,void 0,a);for(let e of i)`optional`in e&&e.optional===!0&&n(t.optional,e.id)}r.some(e=>e.kind===`submit`)||n(`deploy_unreachable_submit`);for(let e of r)e.kind===`choice`&&e.options.length===0&&n(`deploy_empty_choice`,e.id);return t}function vU(e){let t=t=>e.some(e=>e.code===t),n=(e,n,r)=>t(e)?`missing`:t(n)?`bypassed`:t(r)?`optional`:`ok`;return{phone:n(`deploy_missing_phone`,`deploy_phoneless_path`,`deploy_optional_phone`),name:n(`deploy_missing_name`,`deploy_nameless_path`,`deploy_optional_name`)}}var yU=new Set([`deploy_missing_phone`,`deploy_phoneless_path`,`deploy_optional_phone`,`deploy_missing_name`,`deploy_nameless_path`,`deploy_optional_name`]);function bU(e){return e.filter(e=>!yU.has(e.code)).length}function xU(e,t,n){let r=n.trim();if(!r)return`A field key is required, or the answer is thrown away.`;if($V.has(r))return`"${r}" is a built-in field. Use the built-in ${r} block instead.`;if(!tH.test(n))return`Use only letters, numbers, "_" and "-" - no spaces (max 64 characters).`;let i=_H(e,t);for(let[n,a]of Object.entries(e.nodes))if(n!==t&&fH(a)===r&&(i.has(n)||_H(e,n).has(t)))return`"${r}" is already answered by ${iU(e,n)} on this path - one answer would overwrite the other.`;return null}function SU(e){let t=new Map;for(let n of e){if(!n.nodeId)continue;let e=t.get(n.nodeId);e?e.push(n):t.set(n.nodeId,[n])}return t}var CU=3e3,wU=5e3,TU=12e4,EU=`#1f2430`,DU=`#ffffff`,OU=`#ffffff`,kU=1600,AU=[`typingDelayMs`,`teaserDelayMs`,`teaserScrollPercent`,`primaryTextColor`,`backgroundColor`,`backgroundTextColor`,`botBubbleColor`,`botBubbleTextColor`,`userBubbleColor`,`userBubbleTextColor`,`windowRadius`,`bubbleRadius`,`
150controlRadius`,`pageMaxWidth`];async function jU(e=!1){return(await H(e?`/api/widgets?archived=true`:`/api/widgets`)).data??[]}async function MU(e,t){return(await H(`/api/widgets/${e}${t?`?version=${encodeURIComponent(t)}`:``}`)).data}async function NU(e){return(await H(`/api/widgets`,{method:`POST`,body:JSON.stringify({name:e})})).data}async function PU(e,t){return(await H(`/api/widgets/${e}/duplicate`,{method:`POST`,body:JSON.stringify(t?{name:t}:{})})).data}async function FU(e,t){return(await H(`/api/widgets/${e}`,{method:`PATCH`,body:JSON.stringify(t)})).data}async function IU(e,t,n){return(await H(`/api/widgets/${e}/versions`,{method:`POST`,body:JSON.stringify({snapshot:t,...n?.trim()?{changeReason:n.trim()}:{}})})).data}async function LU(e,t,n){return(await H(`/api/widgets/${e}/versions/${t}`,{method:`PATCH`,body:JSON.stringify({deployed:n})})).data}async function RU(e,t){await H(`/api/widgets/${e}/versions/${t}`,{method:`DELETE`})}async function zU(e,t){return(await H(`/api/widgets/${e}`,{method:`PATCH`,body:JSON.stringify({archived:t})})).data}async function BU(e,t){let n=await MU(e,t.id);if(!n.editing)throw Error(`That version has no snapshot to restore.`);return IU(e,n.editing.snapshot,`Restored from v${t.versionNumber}`)}async function VU(e){return(await H(`/api/widgets/${e}/links`)).data.links??[]}async function HU(e,t){return(await H(`/api/widgets/${e}/links`,{method:`POST`,body:JSON.stringify(t)})).data.link}async function UU(e,t,n){return(await H(`/api/widgets/${e}/links/${t}`,{method:`PATCH`,body:JSON.stringify(n)})).data.link}async function WU(e,t){await H(`/api/widgets/${e}/links/${t}`,{method:`DELETE`})}var GU=new Set([`invalid_snapshot`,`too_many_nodes`,`snapshot_too_large`,`node_id_mismatch`,`missing_root`,`unknown_section`,`dangling_next`,`dangling_option_next`,`missing_answer_key`,`invalid_field_key`,`duplicate_answer_key`,`cycle_detected`,`reserved_field_key`,`binding_kind_mismatch`,`multi_select_forbidden`,`multi_select_option_next`,`non_canon_option_value`,`deploy_missing_phone`,`deploy_missing_name`,`deploy_phoneless_path`,`deploy_nameless_path`,`deploy_optional_phone`,`deploy_optional_name`,`deploy_unreachable_submit`,`deploy_empty_choice`]);function KU(e,t){if(!(e instanceof lC)||e.status!==422)return null;let n=e.body,r=Array.isArray(n?.errors)?n.errors:[],i=gU(t),a=[...i,...i.length===0?_U(t):[]],o=new Map(a.map(e=>[`${e.code}::${e.nodeId??``}`,e])),s=r.filter(e=>e&&typeof e.code==`string`).map(e=>o.get(`${e.code}::${e.nodeId??``}`)||{code:GU.has(e.code)?e.code:`invalid_snapshot`,nodeId:e.nodeId,severity:`error`,message:e.message});return s.length===0&&i.length>0&&s.push(...i),{message:n?.error??e.message,issues:s}}var qU=/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i,JU=/^#(?:[0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i;function YU(e){return typeof e==`string`&&qU.test(e)}function XU(e){return typeof e==`string`&&JU.test(e)}function ZU(e){if(!JU.test(e))return null;let t=e.slice(1),n=t.length===3?[...t].map(e=>e+e).join(``):t,r=parseInt(n.slice(0,6),16);return[r>>16&255,r>>8&255,r&255]}function QU([e,t,n]){let r=e=>{let t=e/255;return t<=.04045?t/12.92:((t+.055)/1.055)**2.4};return .2126*r(e)+.7152*r(t)+.0722*r(n)}function $U(e,t){let n=Math.max(e,t),r=Math.min(e,t);return(n+.05)/(r+.05)}var eW=QU(ZU(`#1f2430`)??[0,0,0]),tW=QU(ZU(`#ffffff`)??[255,255,255]);function nW(e){let t=ZU(e);if(!t)return EU;let n=QU(t);return $U(n,tW)>$U(n,eW)?DU:EU}function rW(e){let t=e.backgroundColor??`#ffffff`,n=e.botBubbleColor??`#f3f0f7`,r=e.primaryTextColor??nW(e.primaryColor);return{primary:{fill:e.primaryColor,autoText:nW(e.primaryColor)},background:{fill:t,autoText:nW(t)},botBubble:{fill:n,autoText:nW(n)},userBubble:e.userBubbleColor===void 0?{fill:e.primaryColor,autoText:r}:{fill:e.userBubbleColor,autoText:nW(e.userBubbleColor)}}}function iW(e){let t=ZU(e);return t?`#${t.map(e=>e.toString(16).padStart(2,`0`)).join(``)}`:`#000000`}function aW(e){return YU(e.backgroundColor)?e.backgroundColor:OU}function oW(e,t){return AU.filter(n=>e[n]!==void 0&&t[n]===void 0)}var sW=`sh-widget-root`,cW=350;function lW(e){let t=(0,_.useRef)(null),[n,r]=(0,_.useState)(0);return(0,_.useLayoutEffect)(()=>{let n=t.current;if(!e||!n||(r(n.clientWidth),typeof ResizeObserver>`u`))return;let i=new ResizeObserver(([e])=>{e&&r(e.contentRect.width)});return i.observe(n),()=>i.disconnect()},[e]),[t,n]}function uW({flow:e,persona:t,theme:n,locale:r,startNodeId:i,className:a,restartKey:o=0,mode:s=`embed`}){let c=(0,_.useRef)(null),[l,u]=(0,_.useState)(`loading`),d=s===`page`,[f,p]=lW(d),m=d&&p>0?p/YV:1,h=(0,_.useMemo)(()=>!i||!e.nodes[i]?e:{...e,rootNodeId:i},[e,i]),g=(0,_.useMemo)(()=>({persona:t,theme:n,flow:h,locale:r,openOnMount:!0,autoEngage:!1,mode:s}),[t,n,h,r,s]),v=(0,_.useRef)(g);v.current=g;let y=(0,_.useRef)(o);y.current=o;let b=(0,_.useRef)(new Map),x=(0,_.useRef)(null),S=(0,_.useCallback)((e,t)=>{let n=c.current,r=n?.contentWindow,i=n?.contentDocument;if(!r?.SHWidget||!i?.body)return;b.current.clear(),x.current={config:e,restartKey:t},ZV(r,i);let a=i.createElement(`div`);a.id=XV,i.body.appendChild(a),i.body.style.background=e.mode===`page`?aW(e.theme):``,r.SHWidget.mount(a,e)},[]);return(0,_.useEffect)(()=>
150{let e=c.current;if(!e)return;let t=e.contentDocument;if(!t){u(`unavailable`);return}let n={},r=!1,i=()=>{window.clearInterval(n.poll),window.clearTimeout(n.timeout)};t.open(),t.write(`<!doctype html><html><head><meta charset="utf-8"><style>html,body{margin:0;padding:0;height:100%;background:transparent;font-family:system-ui,-apple-system,sans-serif;}</style></head><body></body></html>`),t.close();let a=e.contentWindow;a&&JV(a,b.current);let o=t.createElement(`div`);o.id=sW,o.style.display=`none`,t.body.appendChild(o);let s=t.createElement(`script`);s.src=`/widget/widget.js`,s.defer=!0,s.onerror=()=>{r||(r=!0,i(),u(`unavailable`))},t.body.appendChild(s);let l=Date.now();return n.poll=window.setInterval(()=>{e.contentWindow?.SHWidget?(r=!0,i(),u(`ready`),S(v.current,y.current)):Date.now()-l>8e3&&(r=!0,i(),u(`unavailable`))},100),n.timeout=window.setTimeout(()=>{r||(r=!0,i(),u(`unavailable`))},8500),i},[]),(0,_.useEffect)(()=>{if(l!==`ready`)return;let e=x.current;if(e&&e.config===g&&e.restartKey===o)return;let t=!!e&&e.config.mode!==g.mode,n=window.setTimeout(()=>S(g,o),t?0:cW);return()=>window.clearTimeout(n)},[g,l,S,o]),(0,L.jsxs)(`div`,{ref:f,className:a??(d?`relative w-full overflow-hidden rounded-lg border bg-muted/30`:`relative h-[560px] w-full overflow-hidden rounded-lg border bg-muted/30`),style:d?{height:800*m}:void 0,children:[(0,L.jsx)(`iframe`,{ref:c,title:d?`Hosted link preview`:`Widget preview`,className:d?`absolute left-0 top-0 border-0 bg-transparent`:`h-full w-full border-0 bg-transparent`,style:d?{width:YV,height:800,transform:`scale(${m})`,transformOrigin:`top left`}:void 0}),l===`loading`&&(0,L.jsxs)(`div`,{className:`pointer-events-none absolute inset-0 flex items-center justify-center gap-2 text-sm text-muted-foreground`,children:[(0,L.jsx)(Ew,{className:`h-4 w-4 animate-spin`}),`Loading previewâ¦`]}),l===`unavailable`&&(0,L.jsx)(`div`,{className:`pointer-events-none absolute inset-0 flex items-center justify-center px-6 text-center text-sm text-muted-foreground`,children:`Preview unavailable - the widget bundle isn't served from this API origin.`})]})}var dW={phone:{field:`Phone`,note:`How the agent reaches them. Needed to deploy.`},name:{field:`Name`,note:`Greets them in the closing message. Needed to deploy.`},intent:{field:`Buy / Sell`,note:`Whether they're buying, selling or both.`},budget:{field:`Budget`,note:`Their budget band. Feeds warmth and assignment.`},timeline:{field:`Buying Timeline`,note:`How soon they'll move. Feeds warmth.`},propertyType:{field:`Current Home`,note:`The property they own or are selling - on every branch, not just sellers.`},preferredContact:{field:`Preferred Contact`,note:`Call or WhatsApp.`}};function fW(e){return e&&dW[e]||null}function pW(e){let t=fW(e);return t?`Saves to ${t.field}. ${t.note}`:null}function mW({onPick:e,blockedReason:t,trigger:n,align:r=`start`}){let[i,a]=(0,_.useState)(!1),o=t=>{a(!1),e(t)};return(0,L.jsxs)(OA,{open:i,onOpenChange:a,children:[(0,L.jsx)(kA,{asChild:!0,children:n}),(0,L.jsxs)(AA,{align:r,className:`w-80 p-0`,children:[(0,L.jsx)(hW,{icon:(0,L.jsx)(lT,{className:`h-3.5 w-3.5`}),title:`Smart blocks`,hint:`Each one writes a field on the lead. Scoring, qualification and agent assignment read them.`,blocks:aH,blockedReason:t,onPick:o}),(0,L.jsx)(`div`,{className:`border-t`}),(0,L.jsx)(hW,{icon:(0,L.jsx)(dT,{className:`h-3.5 w-3.5`}),title:`Custom blocks`,hint:`Your own questions. Stored on the lead for the agent to read; never scored.`,blocks:oH,blockedReason:t,onPick:o})]})]})}function hW({icon:e,title:t,hint:n,blocks:r,blockedReason:i,onPick:a}){return(0,L.jsxs)(`div`,{className:`p-2`,children:[(0,L.jsxs)(`div`,{className:`px-2 pb-1 pt-1`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-semibold`,children:[e,t]}),(0,L.jsx)(`p`,{className:`mt-0.5 text-[11px] leading-snug text-muted-foreground`,children:n})]}),(0,L.jsx)(`div`,{className:`space-y-0.5`,children:r.map(e=>{let t=i?.(e)??null,n=pW(e.binding)??e.description;return(0,L.jsxs)(`button`,{type:`button`,disabled:!!t,title:t??n,onClick:()=>a(e),className:`flex w-full flex-col items-start gap-0.5 rounded-md px-2 py-1.5 text-left transition-colors hover:bg-accent disabled:cursor-not-allowed disabled:opacity-45 disabled:hover:bg-transparent`,children:[(0,L.jsxs)(`span`,{className:`flex w-full items-baseline gap-1.5`,children:[(0,L.jsx)(`span`,{className:`text-sm font-medium`,children:e.label}),fW(e.binding)&&(0,L.jsxs)(`span`,{className:`truncate text-[10px] text-muted-foreground`,children:[`â `,fW(e.binding).field]})]}),(0,L.jsx)(`span`,{className:`text-[11px] leading-snug text-muted-foreground`,children:t??n})]},e.id)})})]})}function gW({label:e,onPick:t,blockedReason:n}){return(0,L.jsx)(mW,{onPick:t,blockedReason:n,trigger:(0,L.jsxs)(W,{type:`button`,variant:`outline`,size:`sm`,className:`h-6 gap-1 rounded-full border-dashed px-2 text-[11px] text-muted-foreground hover:border-solid hover:text-foreground`,"aria-label":e,children:[(0,L.jsx)(Gw,{className:`h-3 w-3`}),e]})})}function _W(e,t,n,r){if(!e||!t.nodes[e])return{kind:`end`};let i=n.get(e)??null;return e===r?{kind:`adjacent`,targetId:e,targetNumber:i}:{kind:`jump`,targetId:e,targetNumber:i}}function vW(e){let{order:t,number:n,reachable:r,orphans:i}=hH(e),a=gH(e),o=new Map;t.forEach((e,t)=>
150o.set(e,t)),i.forEach((e,n)=>o.set(e,t.length+n));let s=[...e.sections].sort((e,t)=>e.order-t.order),c=e=>e.sort((e,t)=>(o.get(e)??0)-(o.get(t)??0)),l=s.map(e=>({section:e,nodes:[]})),u=s.map(t=>c(Object.keys(e.nodes).filter(n=>e.nodes[n].sectionId===t.id&&r.has(n)))),d=new Set(u.flat()),f=c(Object.keys(e.nodes).filter(e=>!d.has(e)));return f.length>0&&(l.push({section:null,nodes:[]}),u.push(f)),u.forEach((t,i)=>{t.forEach((o,s)=>{let c=e.nodes[o],u=s+1<t.length?t[s+1]:null,d=c.kind===`choice`?c.options.map(t=>({optionId:t.id,value:t.value,branchable:!c.multiSelect,target:_W(mH(c,t),e,n,u)})):[],f=c.kind!==`submit`&&(c.kind!==`choice`||c.multiSelect||c.options.length===0||c.options.some(e=>!e.next));l[i].nodes.push({id:o,node:c,number:n.get(o)??null,unreachable:!r.has(o),isRoot:e.rootNodeId===o,options:d,fallThrough:f?_W(c.next,e,n,u):null,incoming:a.get(o)??[],isConvergence:(a.get(o)?.length??0)>1,canInsertAfter:wH(e,o)})})}),{bands:l,number:n,reachableCount:t.length}}function yW({flow:e,locale:t,selectedId:n,issues:r,handlers:i}){let a=(0,_.useMemo)(()=>vW(e),[e]),[o,s]=(0,_.useState)(new Set),[c,l]=(0,_.useState)(null),u=(0,_.useRef)(new Map);(0,_.useEffect)(()=>{n&&u.current.get(n)?.scrollIntoView({block:`nearest`,behavior:`smooth`})},[n]);let d=e=>s(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),f=o.size===a.bands.length,p=(0,_.useMemo)(()=>{let t=new Map;for(let n of Object.keys(e.nodes))t.set(n,_H(e,n));return t},[e]),m=(0,_.useCallback)(t=>{let n=t?p.get(t)??new Set:new Set(Object.keys(e.nodes));return r=>{if(!r.binding)return null;for(let[i,a]of Object.entries(e.nodes))if(fH(a)===r.binding&&(n.has(i)||!t||(p.get(i)?.has(t)??!1)))return`Already asked on this path - a second ${r.label} question would overwrite the first.`;return null}},[e,p]);return(0,L.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between border-b px-3 py-2`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`h2`,{className:`text-sm font-medium`,children:`Flow`}),(0,L.jsxs)(X,{variant:`secondary`,className:`text-[11px]`,children:[a.reachableCount,` step`,a.reachableCount===1?``:`s`]})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,L.jsxs)(W,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 px-2 text-xs`,onClick:()=>s(f?new Set:new Set(a.bands.map(e=>e.section?.id??`__strays__`))),children:[(0,L.jsx)(UC,{className:`mr-1 h-3.5 w-3.5`}),f?`Expand all`:`Collapse all`]}),(0,L.jsxs)(W,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 px-2 text-xs`,onClick:i.onAddSection,children:[(0,L.jsx)(Gw,{className:`mr-1 h-3.5 w-3.5`}),`Section`]})]})]}),(0,L.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-3 py-3`,children:[(0,L.jsx)(`div`,{className:`mb-1 flex justify-center`,children:(0,L.jsx)(gW,{label:`Add first step`,onPick:i.onInsertAtRoot,blockedReason:m(e.rootNodeId)})}),a.bands.map(s=>{let f=s.section?.id??`__strays__`,p=o.has(f),h=s.section===null;return(0,L.jsxs)(`section`,{className:`mb-3`,children:[(0,L.jsxs)(`div`,{className:V(`flex items-center gap-1.5 rounded-t-md border border-b-0 px-2 py-1.5`,h?`border-amber-500/40 bg-amber-500/10`:`bg-muted/60`),children:[(0,L.jsxs)(`button`,{type:`button`,onClick:()=>d(f),className:`flex min-w-0 flex-1 items-center gap-1.5 text-left`,"aria-expanded":!p,children:[p?(0,L.jsx)(VC,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}):(0,L.jsx)(zC,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,L.jsx)(`span`,{className:`truncate text-xs font-semibold`,children:h?`Not reachable`:s.section.title[t]||s.section.title.en||`Untitled section`}),(0,L.jsx)(`span`,{className:`shrink-0 text-[11px] text-muted-foreground`,children:s.nodes.length}),!h&&s.section.progressLabel&&(0,L.jsx)(X,{variant:`outline`,className:`ml-1 shrink-0 gap-1 text-[10px] font-normal`,title:`Shown to the lead while they're in this section`,children:s.section.progressLabel[t]||s.section.progressLabel.en})]}),!h&&(0,L.jsxs)(Uj,{children:[(0,L.jsx)(Wj,{asChild:!0,children:(0,L.jsx)(W,{type:`button`,variant:`ghost`,size:`icon`,className:`h-6 w-6 shrink-0`,"aria-label":`Section options`,children:(0,L.jsx)(aw,{className:`h-3.5 w-3.5`})})}),(0,L.jsxs)(Gj,{align:`end`,children:[(0,L.jsx)(Kj,{onClick:()=>i.onEditSection(s.section.id),children:`Rename / progress labelâ¦`}),(0,L.jsx)(Kj,{onClick:()=>i.onMoveSection(s.section.id,-1),children:`Move up`}),(0,L.jsx)(Kj,{onClick:()=>i.onMoveSection(s.section.id,1),children:`Move down`}),(0,L.jsx)(Jj,{}),(0,L.jsx)(Kj,{variant:`destructive`,onClick:()=>i.onDeleteSection(s.section.id),children:`Delete section`})]})]})]}),!p&&(0,L.jsxs)(`div`,{className:V(`space-y-0 rounded-b-md border px-2 py-2`,h?`border-amber-500/40 bg-amber-500/5`:`bg-card`),children:[h&&(0,L.jsx)(`p`,{className:`mb-2 px-1 text-[11px] leading-snug text-amber-700 dark:text-amber-500`,children:`Nothing points at these steps, so a lead never sees them. Branch to one, or delete it.`}),s.nodes.length===0&&!h&&(0,L.jsx)(`p`,{className:`px-1 py-2 text-[11px] text-muted-foreground`,children:`No steps in this section yet. Use a â+â on a
150step above to add one, then move it here from the step editor.`}),s.nodes.map((o,d)=>(0,L.jsx)(bW,{item:o,isLast:d===s.nodes.length-1,flow:e,locale:t,layoutNumber:a.number,selected:n===o.id,highlighted:c===o.id,issues:r.get(o.id)??[],handlers:i,blockerAt:m,onHighlight:l,registerRef:e=>{e?u.current.set(o.id,e):u.current.delete(o.id)}},o.id))]})]},f)})]})]})}function bW({item:e,isLast:t,flow:n,locale:r,layoutNumber:i,selected:a,highlighted:o,issues:s,handlers:c,blockerAt:l,onHighlight:u,registerRef:d}){let{node:f}=e,p=lH(f,r).trim(),m=uH(f),h=fH(f),g=s.length>0,_=e=>{let t=n.nodes[e];if(!t)return e;let r=i.get(e);return`${r?`${r} `:``}${cH(t)}`};return(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`div`,{ref:d,role:`button`,tabIndex:0,onClick:()=>c.onSelect(e.id),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),c.onSelect(e.id))},className:V(`group relative cursor-pointer rounded-lg border bg-background p-2.5 transition-all`,a&&`border-primary ring-2 ring-primary/25`,!a&&o&&`border-primary/60 ring-2 ring-primary/15`,!a&&!o&&`hover:border-muted-foreground/40`,g&&`border-destructive/70`,e.unreachable&&`opacity-70`),children:[(0,L.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,L.jsx)(`span`,{className:V(`mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full text-[11px] font-semibold tabular-nums`,g?`bg-destructive text-destructive-foreground`:a?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground`),children:e.number??`!`}),(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(0,L.jsx)(`span`,{className:`text-xs font-semibold`,children:cH(f)}),m?(0,L.jsxs)(X,{variant:`secondary`,className:`h-4 gap-0.5 px-1 text-[10px] font-normal`,title:`Smart block - feeds scoring, qualification and assignment`,children:[(0,L.jsx)(lT,{className:`h-2.5 w-2.5`}),h]}):h&&(0,L.jsx)(X,{variant:`outline`,className:`h-4 px-1 font-mono text-[10px] font-normal`,title:`Custom field - stored on the lead for the agent`,children:h}),dH(f)&&(0,L.jsx)(X,{variant:`outline`,className:`h-4 border-primary/50 px-1 text-[10px] font-normal text-primary`,title:`Required before this widget can be deployed - every branch must ask for it.`,children:`Required`}),e.isRoot&&(0,L.jsx)(X,{className:`h-4 px-1 text-[10px] font-normal`,children:`Start`}),f.kind===`choice`&&f.multiSelect&&(0,L.jsx)(X,{variant:`outline`,className:`h-4 px-1 text-[10px] font-normal`,children:`Multi-select`}),f.kind===`text`&&f.optional&&(0,L.jsx)(X,{variant:`outline`,className:`h-4 px-1 text-[10px] font-normal`,children:`Skippable`})]}),(0,L.jsx)(`p`,{className:V(`mt-1 line-clamp-2 text-xs leading-snug`,p?`text-muted-foreground`:`italic text-amber-600 dark:text-amber-500`),children:p||`No message yet - the lead would see a blank bubble.`}),e.isConvergence&&(0,L.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-1 text-[10px] text-muted-foreground`,children:[(0,L.jsx)(gw,{className:`h-3 w-3 shrink-0`}),(0,L.jsxs)(`span`,{className:`truncate`,children:[e.incoming.length,` paths lead here:`,` `,e.incoming.map(e=>_(e.from)).join(`, `)]})]}),g&&(0,L.jsx)(`ul`,{className:`mt-1.5 space-y-0.5`,children:s.map((e,t)=>(0,L.jsxs)(`li`,{className:`flex items-start gap-1 text-[11px] leading-snug text-destructive`,children:[(0,L.jsx)(WC,{className:`mt-0.5 h-3 w-3 shrink-0`}),e.message]},`${e.code}-${t}`))})]}),f.kind!==`submit`&&(0,L.jsx)(W,{type:`button`,variant:`ghost`,size:`icon`,className:`h-6 w-6 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100 focus-visible:opacity-100 hover:text-destructive`,"aria-label":`Delete step ${e.number??``}`,onClick:t=>{t.stopPropagation(),c.onDelete(e.id)},children:(0,L.jsx)(vT,{className:`h-3.5 w-3.5`})})]}),e.options.length>0&&(0,L.jsx)(`div`,{className:`mt-2 space-y-1 border-t pt-2`,children:e.options.map(t=>{let n=f.kind===`choice`?f.options.find(e=>e.id===t.optionId):void 0;return(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5`,onMouseEnter:()=>t.target.kind!==`end`&&u(t.target.targetId),onMouseLeave:()=>u(null),children:[(0,L.jsx)(`span`,{className:`max-w-[45%] truncate rounded-full border bg-muted/50 px-2 py-0.5 text-[11px]`,children:n?.label[r]||n?.label.en||n?.value||(0,L.jsx)(`span`,{className:`italic text-amber-600`,children:`no label`})}),(0,L.jsx)(xW,{edge:t.target,label:_,onSelect:c.onSelect,onHighlight:u}),t.branchable&&(0,L.jsx)(`span`,{className:`ml-auto shrink-0 opacity-0 transition-opacity focus-within:opacity-100 group-hover:opacity-100`,onClick:e=>e.stopPropagation(),children:(0,L.jsx)(mW,{align:`end`,blockedReason:l(e.id),onPick:n=>c.onInsertOnOption(e.id,t.optionId,n),trigger:(0,L.jsx)(W,{type:`button`,variant:`ghost`,size:`icon`,className:`h-5 w-5 text-muted-foreground hover:text-foreground`,"aria-label":`Add a step on this answer's branch`,title:`Add a step on this branch`,children:(0,L.jsx)(Gw,{className:`h-3 w-3`})})})})]},t.optionId)})}),e.fallThrough&&(0,L.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5 border-t pt-2`,children:[(0,L.jsx)(tw,{className:`h-3 w-3 shrink-0 text-muted-foreground`}),(0,L.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:e.options.length>0?`Other answers`:`Then`}),(0,L.jsx)(xW,{edge:e.fallThrough,label:_,onSelect:c.onSelect,onHighlight:u})]})]}),(0,L.jsxs)(`div`,{className:`group/ins relative flex h-7 items-center justify-center`,children:[!t&&(0,L.jsx)(`span`,{className:`absolute inset-y-0 left-1/2 w-px -translate-x-1/2 bg-border`,"aria-hidden":!0}),e.canInsertAfter&&(0,L.jsx)(`span`,{className:`relative bg-card px-1 opacity-0 transition-opacity focus-within:opacity-100 group-hover/ins:opacity-100`,children:(0,L.jsx)(gW,{label:`Add step`,onPick:t=>c.onInsertAfter(e.id,t),blockedReason:l(e.id)})})]})]})}function xW({edge:e,label:t,onSelect:n,onHighlight:r}){if(e.kind===`end`)return(0,L.jsx)(`span`,{className:`rounded-full border border-dashed px-1.5 py-0.5 text-[10px] text-muted-foreground`,title:`Nothing follows - the lead is sent straight to the closing step.`,children:`â ends`});let i=e.kind===`jump`;return(0,L.jsxs)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),n(e.targetId)},onMouseEnter:()=>r(e.targetId),onMouseLeave:()=>r(null),className:V(`shrink-0 truncate rounded-full px-1.5 py-0.5 text-[10px] transition-colors`,i?`border border-primary/40 bg-primary/10 text-primary hover:bg-primary/20`:`text-muted-foreground hover:text-foreground`),title:i?`Jumps to this step`:`Continues to the next step`,children:[`â `,t(e.targetId)]})}function SW({flow:e,nodeId:t,locale:n,setLocale:r,issues:i,onChange:a,onDelete:o,onClose:s}){let c=e.nodes[t],l=(0,_.useMemo)(()=>hH(e).number,[e]),u=e=>`${l.get(e.id)??`-`} · ${cH(e)}`,d=(0,_.useMemo)(()=>{let n=hU(e,t);return Object.values(e.nodes).filter(e=>!n.has(e.id)).map(e=>({id:e.id,label:`${l.get(e.id)??`-`} · ${cH(e)}`,rank:l.get(e.id)??2**53-1})).sort((e,t)=>
150e.rank-t.rank)},[e,t,l]);if(!c)return null;let f=t=>!t||!e.nodes[t]||d.some(e=>e.id===t)?d:[{id:t,label:`${u(e.nodes[t])} - loops back`,rank:-1},...d],p=uH(c),m=l.get(t),h=(c.kind===`choice`||c.kind===`text`||c.kind===`tel`)&&!p,g=h?xU(e,t,(`fieldKey`in c?c.fieldKey:``)??``):null,v=c.kind===`statement`?`Message`:c.kind===`submit`?`Closing message`:`Question`,y=c.kind===`statement`?c.text[n]:c.kind===`submit`?c.closing[n]:c.prompt[n],b=c.kind!==`submit`&&(c.kind!==`choice`||c.multiSelect||c.options.length===0||c.options.some(e=>!e.next));return(0,L.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,L.jsxs)(`div`,{className:`flex items-start justify-between gap-2 border-b px-3 py-2`,children:[(0,L.jsxs)(`div`,{className:`min-w-0`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,L.jsxs)(`h2`,{className:`truncate text-sm font-medium`,children:[m?`Step ${m}`:`Step`,` · `,cH(c)]}),p&&(0,L.jsxs)(X,{variant:`secondary`,className:`h-4 gap-0.5 px-1 text-[10px] font-normal`,children:[(0,L.jsx)(lT,{className:`h-2.5 w-2.5`}),`Smart`]})]}),(0,L.jsx)(`p`,{className:`mt-0.5 text-[11px] leading-snug text-muted-foreground`,children:p?pW(`binding`in c?c.binding:null):c.kind===`submit`?`The lead is saved when they reach this step. Use {name} to greet them.`:`Stored on the lead for the agent. Never scored.`}),p&&(0,L.jsx)(`p`,{className:`mt-0.5 text-[11px] leading-snug text-muted-foreground`,children:`Wording and answer labels are yours; the stored values are locked.`})]}),(0,L.jsx)(W,{type:`button`,variant:`ghost`,size:`icon`,className:`h-7 w-7 shrink-0`,onClick:s,"aria-label":`Close step editor`,children:(0,L.jsx)(FT,{className:`h-4 w-4`})})]}),(0,L.jsxs)(`div`,{className:`flex-1 space-y-4 overflow-y-auto p-3`,children:[i.length>0&&(0,L.jsx)(`div`,{className:`space-y-1 rounded-md border border-destructive/50 bg-destructive/5 p-2`,children:i.map((e,t)=>(0,L.jsxs)(`p`,{className:`flex items-start gap-1.5 text-[11px] leading-snug text-destructive`,children:[(0,L.jsx)(WC,{className:`mt-0.5 h-3 w-3 shrink-0`}),e.message]},`${e.code}-${t}`))}),(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsx)(Z,{className:`text-xs`,children:`Language`}),(0,L.jsx)(KL,{value:n,onValueChange:e=>r(e),children:(0,L.jsx)(qL,{className:`h-7`,children:QV.map(e=>(0,L.jsx)(JL,{value:e.id,className:`h-5 px-2 text-[11px]`,children:e.label},e.id))})})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsxs)(Z,{htmlFor:`node-message`,className:`text-xs`,children:[v,` · `,QV.find(e=>e.id===n)?.label]}),(0,L.jsx)(TD,{id:`node-message`,rows:c.kind===`statement`||c.kind===`submit`?4:3,value:y??``,placeholder:c.kind===`submit`?`Thanks {name}! One of our agents will reach out shortly.`:`What the bot says at this stepâ¦`,onChange:r=>a(PH(e,t,n,r.target.value))}),c.kind===`submit`&&(0,L.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[(0,L.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5`,children:`{name}`}),` is replaced with the lead's name.`]})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{className:`text-xs`,children:`Response type`}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border bg-muted/40 px-2.5 py-1.5`,children:[(0,L.jsx)(`span`,{className:`text-xs font-medium`,children:CW[c.kind]}),(0,L.jsx)(xw,{className:`ml-auto h-3 w-3 shrink-0 text-muted-foreground`}),(0,L.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:p?`Set by the field this block feeds`:`Fixed - replace the step to change it`})]})]}),h&&(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`node-fieldkey`,className:`text-xs`,children:`Field key`}),(0,L.jsx)(G,{id:`node-fieldkey`,value:(`fieldKey`in c?c.fieldKey:``)??``,placeholder:`e.g. renovationBudget`,maxLength:64,spellCheck:!1,autoCapitalize:`none`,autoCorrect:`off`,className:V(`font-mono text-sm`,g&&`border-destructive`),onChange:n=>a(IH(e,t,n.target.value))}),(0,L.jsx)(`p`,{className:V(`text-[11px] leading-snug`,g?`text-destructive`:`text-muted-foreground`),children:g??`Where the answer is stored on the lead, for the agent to read. Letters, numbers, "_" and "-" only (spaces become "_").`})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{className:`text-xs`,children:`Section`}),(0,L.jsxs)(wk,{value:c.sectionId,onValueChange:n=>a(LH(e,t,n)),children:[(0,L.jsx)(Dk,{className:`w-full`,children:(0,L.jsx)(Ek,{})}),(0,L.jsx)(Ok,{children:e.sections.map(e=>(0,L.jsx)(Ak,{value:e.id,children:e.title[n]||e.title.en||`Untitled section`},e.id))})]}),(0,L.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Grouping only - it doesn't change where this step leads.`})]}),c.kind===`text`&&(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(Z,{htmlFor:`node-optional`,className:`text-xs`,children:`Let the lead skip this`}),(0,L.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Shows a Skip button under the input.`})]}),(0,L.jsx)(Ck,{id:`node-optional`,checked:c.optional===!0,onCheckedChange:n=>
150a(RH(e,t,n))})]}),c.kind===`choice`&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(JT,{}),(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,L.jsxs)(`div`,{className:`min-w-0`,children:[(0,L.jsx)(Z,{htmlFor:`node-multi`,className:`text-xs`,children:`Allow multiple answers`}),(0,L.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:c.binding&&eH.has(c.binding)?`Off for every smart block. ${cH(c)} is read by the lead pipeline, which parses one value - two answers arrive joined ("A, B") and are scored as neither.`:c.multiSelect?`Per-answer branching is off: a multi-answer step continues via âNext stepâ below.`:VH(e,t)?`Turning this on clears the per-answer branches below (they never run on a multi-answer step).`:`The lead can pick several, then confirm.`})]}),(0,L.jsx)(Ck,{id:`node-multi`,checked:c.multiSelect,disabled:!!c.binding&&eH.has(c.binding),onCheckedChange:n=>a(BH(e,t,n))})]}),(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsx)(Z,{className:`text-xs`,children:`Answers`}),(0,L.jsx)(wW,{flow:e,nodeId:t,onChange:a})]}),c.options.length===0&&(0,L.jsx)(`p`,{className:`rounded-md border border-dashed p-2 text-[11px] text-muted-foreground`,children:`No answers yet - the lead would be stuck here.`}),c.options.map(r=>(0,L.jsxs)(`div`,{className:`space-y-1.5 rounded-md border p-2`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,L.jsx)(G,{value:r.label[n]??``,placeholder:`Button label`,className:`h-8 flex-1 text-sm`,"aria-label":`Answer label`,onChange:i=>a(UH(e,t,r.id,n,i.target.value))}),(0,L.jsx)(W,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0 text-muted-foreground hover:text-destructive`,"aria-label":`Remove answer`,onClick:()=>a(qH(e,t,r.id)),children:(0,L.jsx)(vT,{className:`h-3.5 w-3.5`})})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,L.jsx)(`span`,{className:`w-12 shrink-0 text-[10px] uppercase tracking-wide text-muted-foreground`,children:`Value`}),p?(0,L.jsx)(X,{variant:`outline`,className:`font-mono text-[10px] font-normal`,title:`Locked - the server parsers key on this value`,children:r.value}):(0,L.jsx)(G,{value:r.value,placeholder:`stored value`,className:`h-7 flex-1 font-mono text-xs`,"aria-label":`Stored value`,onChange:n=>a(WH(e,t,r.id,n.target.value))})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,L.jsx)(`span`,{className:`w-12 shrink-0 text-[10px] uppercase tracking-wide text-muted-foreground`,children:`Goes to`}),(0,L.jsxs)(wk,{disabled:c.multiSelect,value:r.next??`__fall__`,onValueChange:n=>a(GH(e,t,r.id,n===`__fall__`?void 0:n)),children:[(0,L.jsx)(Dk,{className:`h-7 flex-1 text-xs`,"aria-label":`Branch target`,children:(0,L.jsx)(Ek,{})}),(0,L.jsxs)(Ok,{children:[(0,L.jsx)(Ak,{value:`__fall__`,children:`Same as âNext stepâ`}),f(r.next).map(e=>(0,L.jsx)(Ak,{value:e.id,children:e.label},e.id))]})]})]}),c.multiSelect&&r.next&&(0,L.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Branch cleared - multi-answer steps continue via âNext stepâ.`})]},r.id))]})]}),c.kind!==`submit`&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(JT,{}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{className:`text-xs`,children:`Next step`}),(0,L.jsxs)(wk,{value:c.next??`__end__`,onValueChange:n=>a(zH(e,t,n===`__end__`?void 0:n)),children:[(0,L.jsx)(Dk,{className:`w-full`,children:(0,L.jsx)(Ek,{})}),(0,L.jsxs)(Ok,{children:[(0,L.jsx)(Ak,{value:`__end__`,children:`End - go to the closing step`}),f(c.next).map(e=>(0,L.jsx)(Ak,{value:e.id,children:e.label},e.id))]})]}),(0,L.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:b?c.kind===`choice`&&c.options.some(e=>e.next)?`Where answers without their own branch continue.`:`Where the lead goes after this step.`:`Every answer branches on its own, so this is never used.`})]})]})]}),AH(e,t)&&(0,L.jsx)(`div`,{className:`border-t p-3`,children:(0,L.jsxs)(W,{type:`button`,variant:`outline`,size:`sm`,className:`w-full text-destructive hover:bg-destructive/5 hover:text-destructive`,onClick:()=>o(t),children:[(0,L.jsx)(vT,{className:`mr-1.5 h-3.5 w-3.5`}),`Delete this step`]})})]})}var CW={choice:`Buttons`,text:`Free text`,tel:`Phone number`,statement:`Statement (auto-advances)`,submit:`Closing (saves the lead)`};function wW({flow:e,nodeId:t,onChange:n}){let r=e.nodes[t];
150if(r?.kind!==`choice`)return null;if(!r.binding)return(0,L.jsx)(W,{type:`button`,variant:`outline`,size:`sm`,className:`h-6 px-2 text-[11px]`,onClick:()=>n(KH(e,t,{value:`option_${r.options.length+1}`,label:{en:``,zh:``}})),children:`Add answer`});let i=JH(r);return(0,L.jsxs)(wk,{value:``,disabled:i.length===0,onValueChange:r=>{let a=i.find(e=>e.value===r);a&&n(KH(e,t,{value:a.value,label:a.label}))},children:[(0,L.jsx)(Dk,{className:`h-6 w-auto gap-1 px-2 text-[11px]`,"aria-label":`Add a built-in answer`,children:i.length===0?`All answers added`:`Add answer`}),(0,L.jsx)(Ok,{children:i.map(e=>(0,L.jsxs)(Ak,{value:e.value,children:[e.label.en,` `,(0,L.jsx)(`span`,{className:`ml-1 font-mono text-[10px] text-muted-foreground`,children:e.value})]},e.value))})]})}function TW({flow:e,onChange:t,issues:n,locale:r,setLocale:i,persona:a,theme:o}){let[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(!0),[d,f]=(0,_.useState)(0),[p,m]=(0,_.useState)(null),[h,g]=(0,_.useState)(null),[v,y]=(0,_.useState)(null),[b,x]=(0,_.useState)(``),S=(0,_.useMemo)(()=>SU(n),[n]),C=s?e.nodes[s]:void 0,w=t=>t&&e.nodes[t]?.sectionId||e.sections[0]?.id||`main`,T=(0,_.useCallback)((n,r)=>{let i=SH(n,``,{fieldKey:n.binding?void 0:CH(e)});t(r(i)),c(i.id)},[e,t]),E=(0,_.useMemo)(()=>({onSelect:e=>c(e),onInsertAfter:(t,n)=>T(n,n=>DH(e,t,{...n,sectionId:w(t)})),onInsertOnOption:(t,n,r)=>T(r,r=>OH(e,t,n,{...r,sectionId:w(t)})),onInsertAtRoot:t=>T(t,t=>kH(e,{...t,sectionId:w(e.rootNodeId)})),onDelete:e=>m(e),onAddSection:()=>g({id:null,titleEn:``,titleZh:``,progressEn:``,progressZh:``}),onEditSection:t=>{let n=e.sections.find(e=>e.id===t);n&&g({id:t,titleEn:n.title.en??``,titleZh:n.title.zh??``,progressEn:n.progressLabel?.en??``,progressZh:n.progressLabel?.zh??``})},onMoveSection:(n,r)=>t(QH(e,n,r)),onDeleteSection:t=>{if(!$H(e)){z.error(`A flow needs at least one section.`);return}y(t),x(e.sections.find(e=>e.id!==t)?.id??``)}}),[e,T,t]),D=()=>{if(!h)return;let n=h.titleEn.trim();if(!n){z.error(`A section needs a name.`);return}let r=e,i=h.id;i||(i=`s_${crypto.randomUUID()}`,r=YH(r,n,{id:i})),r=XH(r,i,`en`,h.titleEn.trim()),r=XH(r,i,`zh`,h.titleZh.trim()||h.titleEn.trim()),r=ZH(r,i,`en`,h.progressEn.trim()),r=ZH(r,i,`zh`,h.progressZh.trim()),t(r),g(null)},O=()=>{p&&(t(NH(e,p)),s===p&&c(null),m(null))},k=p?e.nodes[p]:void 0,A=p?hH(e).number.get(p):void 0,j=k?dH(k):null,M=v?Object.values(e.nodes).filter(e=>e.sectionId===v).length:0;return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(DW,{issues:n}),(0,L.jsxs)(`div`,{className:`grid gap-3 lg:grid-cols-[minmax(0,1.15fr)_minmax(0,0.85fr)_minmax(0,0.9fr)]`,children:[(0,L.jsx)(`div`,{className:`h-[calc(100vh-15rem)] min-h-[520px] overflow-hidden rounded-lg border bg-card`,children:(0,L.jsx)(yW,{flow:e,locale:r,selectedId:s,issues:S,handlers:E})}),(0,L.jsx)(`div`,{className:`h-[calc(100vh-15rem)] min-h-[520px] overflow-hidden rounded-lg border bg-card`,children:C&&s?(0,L.jsx)(SW,{flow:e,nodeId:s,locale:r,setLocale:i,issues:S.get(s)??[],onChange:t,onDelete:e=>m(e),onClose:()=>c(null)}):(0,L.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 px-8 text-center`,children:[(0,L.jsx)(Pw,{className:`h-5 w-5 text-muted-foreground`}),(0,L.jsx)(`p`,{className:`text-sm font-medium`,children:`Pick a step to edit it`}),(0,L.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Or use a `,(0,L.jsx)(`span`,{className:`font-medium`,children:`+`}),` in the flow to add one. The preview follows whatever you select.`]})]})}),(0,L.jsxs)(`div`,{className:`flex h-[calc(100vh-15rem)] min-h-[520px] flex-col overflow-hidden rounded-lg border bg-card`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between border-b px-3 py-2`,children:[(0,L.jsx)(`h2`,{className:`text-sm font-medium`,children:`Live preview`}),(0,L.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(KL,{value:r,onValueChange:e=>i(e),children:(0,L.jsx)(qL,{className:`h-7`,children:QV.map(e=>(0,L.jsx)(JL,{value:e.id,className:`h-5 px-2 text-[11px]`,children:e.label},e.id))})}),(0,L.jsx)(W,{type:`button`,variant:`ghost`,size:`icon`,className:`h-7 w-7`,"aria-label":`Restart preview`,title:`Restart the conversation`,onClick:()=>f(e=>e+1),children:(0,L.jsx)(Xw,{className:`h-3.5 w-3.5`})})]})]}),(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b px-3 py-1.5`,children:[(0,L.jsxs)(Z,{htmlFor:`preview-from-step`,className:`flex min-w-0 items-center gap-1.5 text-[11px] font-normal text-muted-foreground`,children:[(0,L.jsx)(Ww,{className:`h-3 w-3 shrink-0`}),(0,L.jsx)(`span`,{className:`truncate`,children:l&&C?`Starting at step ${hH(e).number.get(s)??`?`} · ${cH(C)}`:`Starting from the beginning`})]}),(0,L.jsx)(Ck,{id:`preview-from-step`,className:`shrink-0`,checked:l,onCheckedChange:u,"aria-label":`Preview from the selected step`})]}),(0,L.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,L.jsx)(uW,{className:`relative h-full w-full bg-muted/30`,flow:e,persona:a,theme:o,locale:r,startNodeId:l?s:null,restartKey:d})}),(0,L.jsx)(`p`,{className:`border-t px-3 py-1.5 text-[11px] leading-snug text-muted-foreground`,children:`The real widget, running your unsaved flow. Submits and analytics are stubbed - nothing here creates a lead.`})]})]}),(0,L.jsx)(lA,{open:!!p,onOpenChange:e=>!e&&m(null),children:(0,L.jsxs)(pA,{children:[(0,L.jsxs)(mA,{children:[(0,L.jsxs)(gA,{children:[`Delete step `,A??``,k?` (${cH(k)})`:``,`?`]}),(0,L.jsx)(_A,{children:`Anything pointing at it will be re-pointed at what follows it, so the rest of the flow stays connected. This only changes your unsaved draft - the deployed version is untouched until you save.`})]}),j&&(0,L.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-amber-500/40 bg-amber-500/5 px-3 py-2 text-[12px] leading-snug text-amber-700 dark:text-amber-500`,children:[(0,L.jsx)(xT,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),(0,L.jsxs)(`span`,{children:[j===`phone`?`Phone`:`Name`,` is a`,` `,(0,L.jsx)(`strong`,{children:`required field`}),`. Removing it means the widget can't be deployed until every branch asks for `,j,` `,`again.`]})]}),(0,L.jsxs)(hA,{children:[(0,L.jsx)(yA,{children:`Cancel`}),(0,L.jsx)(vA,{onClick:O,children:`Delete step`})]})]})}),(0,L.jsx)(lA,{open:!!v,onOpenChange:e=>!e&&y(null),children:(0,L.jsxs)(pA,{children:[(0,L.jsxs)(mA,{children:[(0,L.jsx)(gA,{children:`Delete this section?`}),(0,L.jsxs)(_A,{children:[`Sections are grouping only. Its `,M,` step`,M===1?``:`s`,` will move to another section - no questions are deleted and no branching changes.`]})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{className:`text-xs`,children:`Move its steps to`}),(0,L.jsxs)(wk,{value:b,onValueChange:x,children:[(0,L.jsx)(Dk,{className:`w-full`,children:(0,L.jsx)(Ek,{})}),(0,L.jsx)(Ok,{children:e.sections.filter(e=>e.id!==v).map(e=>(0,L.jsx)(Ak,{value:e.id,children:e.title[r]||e.title.en},e.id))})]})]}),(0,L.jsxs)(hA,{children:[(0,L.jsx)(yA,{children:`Cancel`}),(0,L.jsx)(vA,{disabled:!b,onClick:()=>{v&&b&&t(eU(e,v,b)),y(null)},children:`Delete section`})]})]})}),(0,L.jsx)(aj,{open:!!h,onOpenChange:e=>!e&&g(null),children:(0,L.jsxs)(lj,{children:[(0,L.jsxs)(uj,{children:[(0,L.jsx)(fj,{children:h?.id?`Edit section`:`New section`}),(0,L.jsx)(pj,{children:`Sections group steps in this builder. They don't constrain branching - a branch may cross
150sections freely. A progress label is the only part the lead ever sees.`})]}),h&&(0,L.jsxs)(`div`,{className:`space-y-3`,children:[(0,L.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`sec-title-en`,className:`text-xs`,children:`Name · EN`}),(0,L.jsx)(G,{id:`sec-title-en`,autoFocus:!0,value:h.titleEn,placeholder:`e.g. Contact details`,onChange:e=>g({...h,titleEn:e.target.value})})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`sec-title-zh`,className:`text-xs`,children:`Name · 䏿`}),(0,L.jsx)(G,{id:`sec-title-zh`,value:h.titleZh,placeholder:`(defaults to EN)`,onChange:e=>g({...h,titleZh:e.target.value})})]})]}),(0,L.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`sec-prog-en`,className:`text-xs`,children:`Progress label · EN`}),(0,L.jsx)(G,{id:`sec-prog-en`,value:h.progressEn,placeholder:`(optional)`,onChange:e=>g({...h,progressEn:e.target.value})})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`sec-prog-zh`,className:`text-xs`,children:`Progress label · 䏿`}),(0,L.jsx)(G,{id:`sec-prog-zh`,value:h.progressZh,placeholder:`(optional)`,onChange:e=>g({...h,progressZh:e.target.value})})]})]}),(0,L.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:`Leave the progress label empty to show the lead nothing. When set, it appears above the conversation while they're answering this section's questions.`})]}),(0,L.jsxs)(dj,{children:[(0,L.jsx)(W,{type:`button`,variant:`outline`,onClick:()=>g(null),children:`Cancel`}),(0,L.jsx)(W,{type:`button`,onClick:D,children:h?.id?`Save section`:`Add section`})]})]})})]})}function EW(e,t){switch(t){case`ok`:return`${e} is asked on every branch a lead can take.`;case`missing`:return`No ${e} question yet - add the ${e} block before deploying.`;case`bypassed`:return`Some branch reaches the closing step without asking for ${e}.`;case`optional`:return`${e} is skippable - a required field can't be optional in a deployed flow.`}}function DW({issues:e}){let t=(0,_.useMemo)(()=>vU(e),[e]),n=[{label:`Phone`,status:t.phone},{label:`Name`,status:t.name}],r=n.every(e=>e.status===`ok`),i=(0,_.useMemo)(()=>bU(e),[e]);return(0,L.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-x-3 gap-y-1 rounded-md border px-3 py-2`,children:[(0,L.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:`Deploy readiness`}),n.map(e=>{let t=e.status===`ok`;return(0,L.jsxs)(`span`,{className:V(`inline-flex items-center gap-1 text-xs font-medium`,t?`text-emerald-600 dark:text-emerald-500`:`text-amber-600 dark:text-amber-500`),title:EW(e.label,e.status),children:[t?(0,L.jsx)(RC,{className:`h-3.5 w-3.5`}):(0,L.jsx)(xT,{className:`h-3.5 w-3.5`}),e.label]},e.label)}),(0,L.jsx)(`span`,{className:`ml-auto text-[11px] text-muted-foreground`,children:r?i===1?`Phone and name are covered, but 1 other check still blocks deploy.`:i>1?`Phone and name are covered, but ${i} other checks still block deploy.`:`Every branch asks for both - ready to deploy.`:`Both are required on every branch before this can go live.`})]})}function OW(e){let t=e.toLowerCase();return t===`#1f2430`?`dark`:t===`#ffffff`?`white`:e}function kW(e){return e.trim().replace(/^#?/,`#`)}function AW(e){return e.length===4}function jW({id:e,label:t,value:n,isValid:r,onCommit:i}){let[a,o]=(0,_.useState)(null);return(0,L.jsx)(G,{id:e,value:a??n,onChange:e=>{let t=e.target.value;o(t);let n=kW(t);r(n)&&!AW(n)&&i(n)},onBlur:()=>{if(a!==null){let e=kW(a);r(e)&&AW(e)&&i(e)}o(null)},className:`w-32 font-mono text-sm`,"aria-label":t})}function MW({id:e,label:t,fill:n,fillSet:r=!1,fillHint:i,isValidFill:a,onFillChange:o,onFillReset:s,autoText:c,text:l,onTextChange:u,onTextReset:d}){let f=t.toLowerCase();return(0,L.jsxs)(`div`,{id:`${e}-row`,className:`space-y-2`,children:[(0,L.jsxs)(`div`,{className:`flex min-h-6 items-center justify-between gap-2`,children:[(0,L.jsx)(Z,{htmlFor:e,children:t}),r&&s&&(0,L.jsx)(W,{id:`${e}-reset`,type:`button`,variant:`ghost`,size:`xs`,className:`-mr-2`,"aria-label":`Reset ${f} colour`,onClick:s,children:`Reset`}),!r&&i&&(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:i})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`input`,{id:e,type:`color`,className:`h-9 w-12 cursor-pointer rounded-md border bg-background p-1`,value:iW(n),onChange:e=>o(e.target.value),"aria-label":`${t} colour picker`}),(0,L.jsx)(jW,{id:`${e}-hex`,label:`${t} colour hex`,value:n,isValid:a,onCommit:o})]}),(0,L.jsxs)(`div`,{className:`flex min-h-9 flex-wrap items-center gap-x-3 gap-y-2`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(Ck,{id:`${e}-text-on`,checked:l!==void 0,onCheckedChange:e=>e?u(c):d(),"aria-label":`Custom text colour on ${f}`}),(0,L.jsx)(Z,{htmlFor:`${e}-text-on`,className:`font-normal`,children:`Custom text colour`})]}),l===void 0?(0,L.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Auto: `,OW(c)]}):(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`input`,{id:`${e}-text`,type:`color`,className:`h-9 w-12 cursor-pointer rounded-md border bg-background p-1`,value:iW(l),onChange:e=>u(e.target.value),"aria-label":`${t} text colour picker`}),(0,L.jsx)(jW,{id:`${e}-text-hex`,label:`${t} text colour hex`,value:l,isValid:YU,onCommit:u})]})]})]})}
150function NW({id:e,label:t,hint:n,min:r,max:i,step:a,value:o,readout:s,isSet:c,disabled:l,onChange:u,onReset:d}){return(0,L.jsxs)(`div`,{id:`${e}-row`,className:`space-y-1.5`,children:[(0,L.jsxs)(`div`,{className:`flex min-h-6 items-center justify-between gap-2`,children:[(0,L.jsx)(Z,{htmlFor:e,className:`shrink-0 whitespace-nowrap`,children:t}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[c&&(0,L.jsx)(W,{id:`${e}-reset`,type:`button`,variant:`ghost`,size:`xs`,"aria-label":`Reset ${t.toLowerCase()}`,onClick:d,children:`Reset`}),(0,L.jsx)(`span`,{className:`text-right text-xs tabular-nums text-muted-foreground`,children:s})]})]}),(0,L.jsx)(`input`,{id:e,type:`range`,min:r,max:i,step:a,disabled:l,value:o,onChange:e=>u(Number(e.target.value)),className:`w-full cursor-pointer accent-primary disabled:cursor-not-allowed disabled:opacity-40`}),(0,L.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:n})]})}var PW={teaserDelayMs:wU,teaserScrollPercent:25},FW=`min(95vw, calc(1.6 * (100vh - 8.5rem) + 2rem))`;function IW({draft:e,setDraft:t,savedTheme:n,flow:r,locale:i}){let[a,o]=(0,_.useState)(`embed`),[s,c]=(0,_.useState)(!1),l=(0,_.useRef)(null),u=(n,r)=>t({...e,persona:{...e.persona,[n]:r}}),d=(n,r)=>t({...e,theme:{...e.theme,[n]:r}}),f=n=>{let r={...e.theme};delete r[n],t({...e,theme:r})},p=(n,r)=>t({...e,targeting:{...e.targeting,[n]:r}}),m=e.theme.typingDelayMs??900,h=(e,t)=>{if(!t){d(e,null);return}let r=n[e];r===void 0?f(e):r===null?d(e,PW[e]):d(e,r)},g=e.theme.teaserDelayMs!==null,v=e.theme.teaserScrollPercent!==null,y=e.theme.teaserDelayMs??5e3,b=e.theme.teaserScrollPercent??25,x=!g&&!v,S=rW(e.theme),{windowRadius:C,bubbleRadius:w,controlRadius:T,pageMaxWidth:E}=e.theme,D=typeof n.pageMaxWidth==`number`?n.pageMaxWidth:null,O=e=>{e?d(`pageMaxWidth`,null):D===null?f(`pageMaxWidth`):d(`pageMaxWidth`,D)},k=E===null,A=typeof E==`number`?E:k?D??580:580;return(0,L.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-[minmax(0,1fr)_minmax(0,420px)]`,children:[(0,L.jsxs)(`div`,{className:`space-y-6`,children:[(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{className:`pb-3`,children:[(0,L.jsx)(ND,{className:`text-base`,children:`Persona`}),(0,L.jsx)(PD,{children:`How the bot introduces itself. Shared by every version of this widget, and by both languages.`})]}),(0,L.jsxs)(q,{className:`space-y-4`,children:[(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`persona-name`,children:`Name`}),(0,L.jsx)(G,{id:`persona-name`,value:e.persona.name,onChange:e=>u(`name`,e.target.value)})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`persona-tagline`,children:`Tagline`}),(0,L.jsx)(G,{id:`persona-tagline`,value:e.persona.tagline,onChange:e=>u(`tagline`,e.target.value)})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`persona-avatar`,children:`Avatar URL`}),(0,L.jsx)(G,{id:`persona-avatar`,placeholder:`https://â¦`,value:e.persona.avatarUrl,onChange:e=>u(`avatarUrl`,e.target.value)})]})]})]}),(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{className:`pb-3`,children:[(0,L.jsx)(ND,{className:`text-base`,children:`Colours`}),(0,L.jsx)(PD,{children:`Text on each colour is picked automatically for contrast unless you set it. Applies to the website widget and to hosted links.`})]}),(0,L.jsxs)(q,{className:`space-y-6`,children:[(0,L.jsx)(MW,{id:`colour-primary`,label:`Primary`,fill:S.primary.fill,isValidFill:XU,onFillChange:e=>d(`primaryColor`,e),autoText:S.primary.autoText,text:e.theme.primaryTextColor,onTextChange:e=>d(`primaryTextColor`,e),onTextReset:()=>f(`primaryTextColor`)}),(0,L.jsx)(JT,{}),(0,L.jsx)(MW,{id:`colour-background`,label:`Background`,fill:S.background.fill,fillSet:e.theme.backgroundColor!==void 0,fillHint:`Default`,isValidFill:YU,onFillChange:e=>d(`backgroundColor`,e),onFillReset:()=>f(`backgroundColor`),autoText:S.background.autoText,text:e.theme.backgroundTextColor,onTextChange:e=>d(`backgroundTextColor`,e),onTextReset:()=>f(`backgroundTextColor`)}),(0,L.jsx)(JT,{}),(0,L.jsx)(MW,{id:`colour-bot-bubble`,label:`Bot bubble`,fill:S.botBubble.fill,fillSet:e.theme.botBubbleColor!==void 0,fillHint:`Default`,isValidFill:YU,onFillChange:e=>d(`botBubbleColor`,e),onFillReset:()=>f(`botBubbleColor`),autoText:S.botBubble.autoText,text:e.theme.botBubbleTextColor,onTextChange:e=>d(`botBubbleTextColor`,e),onTextReset:()=>f(`botBubbleTextColor`)}),(0,L.jsx)(JT,{}),(0,L.jsx)(MW,{id:`colour-user-bubble`,label:`User bubble`,fill:S.userBubble.fill,fillSet:e.theme.userBubbleColor!==void 0,fillHint:`Same as primary`,isValidFill:YU,onFillChange:e=>d(`userBubbleColor`,e),onFillReset:()=>f(`userBubbleColor`),autoText:S.userBubble.autoText,text:e.theme.userBubbleTextColor,onTextChange:e=>d(`userBubbleTextColor`,e),onTextReset:()=>f(`userBubbleTextColor`)})]})]}),(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{className:`pb-3`,children:[(0,L.jsx)(ND,{className:`text-base`,children:`Shape`}),(0,L.jsx)(PD,{children:`How rounded the chat is. A slider you don't touch keeps the standard look.`})]}),(0,L.jsxs)(q,{className:`space-y-6`,children:[(0,L.jsx)(NW,{id:`shape-window`,label:`Window corners`,hint:`The chat window and the teaser card. Hosted links fill the screen, so they stay square.`,min:0,max:32,step:1,value:C??16,readout:C===void 0?`
15016px (default)`:`${C}px`,isSet:C!==void 0,onChange:e=>d(`windowRadius`,e),onReset:()=>f(`windowRadius`)}),(0,L.jsx)(NW,{id:`shape-bubble`,label:`Bubble corners`,hint:`Message bubbles, the bot's and the visitor's.`,min:0,max:24,step:1,value:w??14,readout:w===void 0?`14px (default)`:`${w}px`,isSet:w!==void 0,onChange:e=>d(`bubbleRadius`,e),onReset:()=>f(`bubbleRadius`)}),(0,L.jsx)(NW,{id:`shape-control`,label:`Control corners`,hint:`Answer buttons, text fields and Send. At 24 every one is a pill.`,min:0,max:24,step:1,value:T??24,readout:T===void 0?`Default (pill buttons, 10px fields)`:T===24?`24px (pill)`:`${T}px`,isSet:T!==void 0,onChange:e=>d(`controlRadius`,e),onReset:()=>f(`controlRadius`)})]})]}),(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{className:`pb-3`,children:[(0,L.jsx)(ND,{className:`text-base`,children:`Hosted link`}),(0,L.jsx)(PD,{children:`Layout of the full-page form behind your share links. The website widget ignores it.`})]}),(0,L.jsxs)(q,{className:`space-y-4`,children:[(0,L.jsx)(NW,{id:`hosted-width`,label:`Max width`,hint:`How wide the conversation column gets on a desktop screen. The header band and background always fill the window, and phones are unaffected.`,min:360,max:kU,step:20,value:A,disabled:k,readout:E===void 0?`580px (default)`:E===null?`Full width`:`${E}px`,isSet:E!==void 0,onChange:e=>d(`pageMaxWidth`,e),onReset:()=>f(`pageMaxWidth`)}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(Ck,{id:`hosted-full-width`,checked:k,onCheckedChange:O}),(0,L.jsx)(Z,{htmlFor:`hosted-full-width`,className:`font-normal`,children:`Full width`})]})]})]}),(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{className:`pb-3`,children:[(0,L.jsx)(ND,{className:`text-base`,children:`Placement & pacing`}),(0,L.jsx)(PD,{children:`Where the launcher sits on the page, and how long the typing dots show before each message. The launcher keeps the black STACKED tile either way.`})]}),(0,L.jsxs)(q,{className:`space-y-4`,children:[(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`theme-position`,children:`Position`}),(0,L.jsxs)(wk,{value:e.theme.position,onValueChange:e=>d(`position`,e),children:[(0,L.jsx)(Dk,{id:`theme-position`,className:`w-full`,children:(0,L.jsx)(Ek,{})}),(0,L.jsxs)(Ok,{children:[(0,L.jsx)(Ak,{value:`bottom-right`,children:`Bottom right`}),(0,L.jsx)(Ak,{value:`bottom-left`,children:`Bottom left`})]})]})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,L.jsx)(Z,{htmlFor:`theme-typing`,children:`Typing delay`}),(0,L.jsx)(`span`,{className:`text-xs tabular-nums text-muted-foreground`,children:m===0?`Off - instant`:`${m} ms`})]}),(0,L.jsx)(`input`,{id:`theme-typing`,type:`range`,min:0,max:CU,step:100,value:m,onChange:e=>d(`typingDelayMs`,Number(e.target.value)),className:`w-full cursor-pointer accent-primary`}),(0,L.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:`How long the ââ¦â typing dots show before each bot message. Set to 0 for no delay. Visitors who ask their system for reduced motion never see the dots.`})]})]})]}),(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{className:`pb-3`,children:[(0,L.jsx)(ND,{className:`text-base`,children:`Teaser timing`}),(0,L.jsxs)(PD,{children:[`When the teaser card appears on its own. It shows as soon as`,` `,(0,L.jsx)(`strong`,{children:`either`}),` rule is met, so the visitor sees it at whichever comes first - once per page view, on every page. Closing it or finishing the form never hides it on later pages. Turn both off to show the launcher only, with no popup at all.`]})]}),(0,L.jsxs)(q,{className:`space-y-6`,children:[(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,L.jsxs)(Z,{htmlFor:`teaser-delay`,className:`flex items-center gap-2`,children:[(0,L.jsx)(Ck,{id:`teaser-delay-on`,checked:g,onCheckedChange:e=>h(`teaserDelayMs`,e),"aria-label":`Enable the time trigger`}),`Show after`]}),(0,L.jsx)(`span`,{className:`text-xs tabular-nums text-muted-foreground`,children:g?y===0?`Immediately`:`${Math.round(y/1e3)}s`:`Off`})]}),(0,L.jsx)(`input`,{id:`teaser-delay`,type:`range`,min:0,max:TU/1e3,step:1,disabled:!g,value:Math.round(y/1e3),onChange:e=>d(`teaserDelayMs`,Number(e.target.value)*1e3),className:`w-full cursor-pointer accent-primary disabled:cursor-not-allowed disabled:opacity-40`}),(0,L.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:`How long the visitor has been on the page. 0 shows it immediately.`})]}),(0,L.jsx)(JT,{}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,L.jsxs)(Z,{htmlFor:`teaser-scroll`,className:`flex items-center gap-2`,children:[(0,L.jsx)(Ck,{id:`teaser-scroll-on`,checked:v,onCheckedChange:e=>h(`teaserScrollPercent`,e),"aria-label":`Enable the scroll-depth trigger`}),`Show at scroll depth`]}),(0,L.jsx)(`span`,{className:`text-xs tabular-nums text-muted-foreground`,children:v?`${b}%`:`Off`})]}),(0,L.jsx)(`input`,{id:`teaser-scroll`,type:`range`,min:1,max:100,step:1,disabled:!v,value:b,onChange:e=>d(`teaserScrollPercent`,Number(e.target.value)),className:`w-full cursor-pointer accent-primary disabled:cursor-not-allowed disabled:opacity-40`}),(0,L.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:`How far down the page the visitor has read. Pages too short to scroll never trigger this rule.`})]}),x&&(0,L.jsxs)(`p`,{role:`status`,className:`rounded-md border border-dashed px-3 py-2 text-[11px] leading-snug text-muted-foreground`,children:[(0,L.jsx)(`strong`,{children:`Launcher only.`}),` The teaser will never appear on its own. Visitors can still open the chat by clicking the launcher.`]})]})]}),(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{className:`pb-3`,children:[(0,L.jsx)(ND,{className:`text-base`,children:`Page targeting`}),(0,L.jsxs)(PD,{children:[`Which pages this widget may appear on. Leave both empty to allow every page. `,(0,L.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5 text-xs`,children:`*`}),` is a wildcard, matched against the full URL (e.g.`,` `,(0,L.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5 text-xs`,children:`*stackedhomes.com/buy/*`}),`). Exclude always wins. Pages under`,` `,(0,L.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5 text-xs`,children:`/zh`}),` render in Chinese automatically.`]})]}),(0,L.jsxs)(q,{className:`space-y-6`,children:[(0,L.jsx)(LW,{label:`Include URL patterns`,emptyNote:`No include patterns - allowed on every page (unless excluded below).`,patterns:e.targeting.includeUrlPatterns,onChange:e=>p(`includeUrlPatterns`,e)}),(0,L.jsx)(JT,{}),(0,L.jsx)(LW,{label:`Exclude URL patterns`,emptyNote:`No exclude patterns.`,patterns:e.targeting.excludeUrlPatterns,onChange:e=>p(`excludeUrlPatterns`,e)})]})]})]}),(0,L.jsxs)(`div`,{className:`space-y-2 lg:sticky lg:top-4 lg:self-start`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,L.jsx)(`h2`,{className:`text-sm font-medium`,children:`Live preview`}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[a===`page`&&(0,L.jsx)(W,{type:`button`,variant:`outline`,size:`icon`,"aria-label":`Expand hosted link preview`,onClick:()=>c(!0),children:(0,L.jsx)(Aw,{className:`h-4 w-4`})}),(0,L.jsx)(KL,{value:a,onValueChange:e=>
150o(e),children:(0,L.jsxs)(qL,{children:[(0,L.jsx)(JL,{value:`embed`,children:`Widget`}),(0,L.jsx)(JL,{value:`page`,children:`Hosted link`})]})})]})]}),(0,L.jsx)(uW,{flow:r,persona:e.persona,theme:e.theme,locale:i,mode:a}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:a===`page`?`The full-page form behind your share links, at desktop width and scaled to fit, with your unsaved look and the flow version you have open in Build. Nothing here creates a lead.`:`The real widget with your unsaved look, running the flow version you have open in Build. Nothing here creates a lead.`}),(0,L.jsx)(aj,{open:s,onOpenChange:c,children:(0,L.jsxs)(lj,{ref:l,className:`max-w-none gap-3 p-4 sm:max-w-none`,style:{width:FW},onOpenAutoFocus:e=>{e.preventDefault(),l.current?.focus()},children:[(0,L.jsxs)(uj,{children:[(0,L.jsx)(fj,{children:`Hosted link preview`}),(0,L.jsx)(pj,{children:`Your unsaved look on a desktop screen. Nothing here creates a lead.`})]}),(0,L.jsx)(uW,{flow:r,persona:e.persona,theme:e.theme,locale:i,mode:`page`})]})})]})]})}function LW({label:e,emptyNote:t,patterns:n,onChange:r}){return(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(Z,{className:`text-sm font-medium`,children:e}),n.length===0?(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t}):(0,L.jsx)(`div`,{className:`space-y-2`,children:n.map((t,i)=>(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(G,{value:t,placeholder:`e.g. *stackedhomes.com/buy/*`,className:`flex-1 font-mono text-sm`,"aria-label":`${e} pattern ${i+1}`,onChange:e=>r(n.map((t,n)=>n===i?e.target.value:t))}),(0,L.jsx)(W,{type:`button`,variant:`ghost`,size:`icon`,className:`shrink-0`,"aria-label":`Remove ${e} pattern ${i+1}`,onClick:()=>r(n.filter((e,t)=>t!==i)),children:(0,L.jsx)(FT,{className:`h-4 w-4`})})]},i))}),(0,L.jsxs)(W,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>r([...n,``]),children:[(0,L.jsx)(Gw,{className:`mr-1.5 h-3.5 w-3.5`}),`Add pattern`]})]})}function RW(e){if(!e)return`Never`;let t=typeof e==`string`?new Date(e).getTime():NaN;if(Number.isNaN(t))return`-`;let n=Date.now()-t;if(n<0)return`just now`;let r=Math.floor(n/6e4);if(r<1)return`just now`;if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);if(a<7)return`${a}d ago`;let o=Math.floor(a/7);if(o<5)return`${o}w ago`;let s=Math.floor(a/30);return s<12?`${s}mo ago`:`${Math.floor(a/365)}y ago`}var zW=`https://stackedhomes-production.up.railway.app`;function BW(e){return`<script src="${zW}/widget/widget.js?embed=${encodeURIComponent(e)}" defer><\/script>`}function VW(e,t){return`(function(){var s=document.createElement('script');s.src='${e}/widget/widget.js?embed=${encodeURIComponent(t)}';s.defer=true;document.body.appendChild(s);})();`}function HW(){return`https://forms.stackedhomes.voltade.com`.replace(/\/+$/,``)}function UW(e){return`${HW()}/${e}`}var WW=new Set([`api`,`widget`,`widgets`,`robots`,`health`,`login`,`logout`,`assets`,`static`,`admin`,`dashboard`,`f`,`favicon`,`sitemap`,`index`,`null`,`undefined`]),GW=/^[a-z0-9-]+$/;function KW(e){let t=e.trim();return t?t.length>64?`Alias must be 64 characters or fewer.`:GW.test(t)?WW.has(t)?`"${t}" is a reserved word - pick another.`:null:`Use only lowercase letters, numbers, and hyphens.`:null}function qW(e){let t=Math.round(e*1e3)/10;return`${Number.isInteger(t)?t:t.toFixed(1)}%`}function JW(e){if(typeof navigator>`u`||!navigator.clipboard){z.error(`Copy not supported`);return}navigator.clipboard.writeText(e).then(()=>z.success(`Copied`)).catch(()=>z.error(`Copy failed`))}function YW({widgetId:e}){let t=ri(),{data:n,isLoading:r,isError:i}=vi({queryKey:[`widget-links`,e],queryFn:()=>VU(e)}),a=()=>t.invalidateQueries({queryKey:[`widget-links`,e]}),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(null),f=KW(c),p=R({mutationFn:()=>HU(e,{...o.trim()?{label:o.trim()}:{},...c.trim()?{alias:c.trim()}:{}}),onSuccess:e=>{a(),s(``),l(``),d(null),z.success(e.label?`Created "${e.label}".`:`Tracked link created.`)},onError:e=>d(e.message)}),m=()=>{if(f){d(f);return}d(null),p.mutate()},h=R({mutationFn:({linkId:t,patch:n})=>UU(e,t,n),onSuccess:()=>a(),onError:e=>z.error(e.message)}),g=R({mutationFn:t=>WU(e,t),onSuccess:()=>{a(),y(null),z.success(`Link deleted.`)},onError:e=>z.error(e.message)}),[v,y]=(0,_.useState)(null);return r?(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,L.jsx)(Ew,{className:`h-4 w-4 animate-spin`}),`Loading linksâ¦`]}):i||!n?(0,L.jsx)(K,{children:(0,L.jsx)(q,{className:`py-6 text-sm text-destructive`,children:`Failed to load this widget's links.`})}):(0,L.jsxs)(`div`,{className:`space-y-3`,children:[(0,L.jsx)(K,{children:(0,L.jsxs)(q,{className:`space-y-3 p-4`,children:[(0,L.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,L.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Create tracked link`}),(0,L.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:`Each link is a shareable page-form URL with its own attribution label and its own views / leads / conversion. The short address is generated for you; an optional alias gives it a friendlier path.`})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-end`,children:[(0,L.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,L.jsx)(Z,{htmlFor:`new-link-label`,className:`text-xs`,children:`Label (for your reporting)`}),(0,L.jsx)(G,{id:`new-link-label`,value:o,maxLength:120,placeholder:`e.g. March newsletter`,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!p.isPending&&m()}})]}),(0,L.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,L.jsx)(Z,{htmlFor:`new-link-alias`,className:`text-xs`,children:`Alias (optional)`}),(0,L.jsx)(G,{id:`new-link-alias`,value:c,maxLength:64,placeholder:`e.g. newsletter`,"aria-invalid":!!f,onChange:e=>{l(e.target.value),d(null)},onKeyDown:e=>{e.key===`Enter`&&!p.isPending&&m()}})]}),(0,L.jsxs)(W,{type:`button`,size:`sm`,disabled:p.isPending||!!f,onClick:m,children:[p.isPending?(0,L.jsx)(Ew,{className:`mr-1.5 h-3.5 w-3.5 animate-spin`}):(0,L.jsx)(Gw,{className:`mr-1.5 h-3.5 w-3.5`}),`Create`]})]}),(f||u)&&(0,L.jsx)(`p`,{className:`text-[11px] text-destructive`,children:f??u})]})}),n.length===0?(0,L.jsx)(K,{children:(0,L.jsxs)(q,{className:`flex flex-col items-center gap-1 py-8 text-center`,children:[(0,L.jsx)(Cw,{className:`h-5 w-5 text-muted-foreground`}),(0,L.jsx)(`p`,{className:`text-sm font-medium`,children:`No tracked links yet`}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Create one above to get a shareable page-form URL.`})]})}):n.map(e=>(0,L.jsx)(XW,{link:e,isUpdating:h.isPending&&h.variables?.linkId===e.id,onLabel:t=>h.mutate({linkId:e.id,patch:{label:t}}),onAlias:t=>h.mutate({linkId:e.id,patch:{alias:t}}),onToggleDisabled:t=>h.mutate({linkId:e.id,patch:{disabled:t}}),onDelete:()=>y(e)},e.id)),(0,L.jsx)(lA,{open:!!v,onOpenChange:e=>!e&&y(null),children:(0,L.jsxs)(pA,{children:[(0,L.jsxs)(mA,{children:[(0,L.jsxs)(gA,{children:[`Delete `,v?.label?`"${v.label}"`:`this link`,`?`]}),(0,L.jsx)(_A,{children:`The URL stops working immediately. Leads already captured through it keep their attribution (the label is snapshotted onto each lead), but this can't be und
150one.`})]}),(0,L.jsxs)(hA,{children:[(0,L.jsx)(yA,{children:`Cancel`}),(0,L.jsxs)(vA,{disabled:g.isPending,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:e=>{e.preventDefault(),v&&g.mutate(v.id)},children:[g.isPending&&(0,L.jsx)(Ew,{className:`mr-1.5 h-3.5 w-3.5 animate-spin`}),`Delete`]})]})]})})]})}function XW({link:e,isUpdating:t,onLabel:n,onAlias:r,onToggleDisabled:i,onDelete:a}){let[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(e.label??``),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(e.alias??``),m=f.trim(),h=m?KW(m):null,g=()=>{l(e.label??``),s(!0)},v=()=>{let t=c.trim();t!==(e.label??``)&&n(t),s(!1)},y=()=>{p(e.alias??``),d(!0)},b=()=>{if(h)return;let t=m===``?null:m;t!==(e.alias??null)&&r(t),d(!1)},x=UW(e.slug),S=e.alias?UW(e.alias):null;return(0,L.jsx)(K,{className:e.disabled?`opacity-60`:void 0,children:(0,L.jsxs)(q,{className:`space-y-3 p-4`,children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,L.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[o?(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,L.jsx)(G,{autoFocus:!0,value:c,maxLength:120,placeholder:`Label`,className:`h-7 max-w-xs text-sm`,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&v(),e.key===`Escape`&&s(!1)}}),(0,L.jsx)(W,{type:`button`,size:`icon`,variant:`ghost`,className:`h-7 w-7`,"aria-label":`Save label`,onClick:v,children:(0,L.jsx)(RC,{className:`h-3.5 w-3.5`})}),(0,L.jsx)(W,{type:`button`,size:`icon`,variant:`ghost`,className:`h-7 w-7`,"aria-label":`Cancel`,onClick:()=>s(!1),children:(0,L.jsx)(FT,{className:`h-3.5 w-3.5`})})]}):(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,L.jsx)(`span`,{className:`text-sm font-semibold`,children:e.label||(0,L.jsx)(`span`,{className:`italic text-muted-foreground`,children:`Untitled link`})}),(0,L.jsx)(W,{type:`button`,size:`icon`,variant:`ghost`,className:`h-6 w-6`,"aria-label":`Edit label`,onClick:g,children:(0,L.jsx)(Bw,{className:`h-3 w-3`})}),e.isDefault&&(0,L.jsxs)(X,{variant:`secondary`,className:`gap-1 text-[10px]`,children:[(0,L.jsx)(mT,{className:`h-2.5 w-2.5`}),`Default`]}),e.disabled&&(0,L.jsx)(X,{variant:`outline`,className:`text-[10px]`,children:`Disabled`})]}),(0,L.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,title:new Date(e.createdAt).toLocaleString(),children:[`Created `,RW(e.createdAt)]})]}),(0,L.jsxs)(`div`,{className:`flex shrink-0 items-center gap-3`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[t&&(0,L.jsx)(Ew,{className:`h-3.5 w-3.5 animate-spin`}),(0,L.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:e.disabled?`Off`:`Live`}),(0,L.jsx)(Ck,{checked:!e.disabled,disabled:t,"aria-label":e.disabled?`Enable link`:`Disable link`,onCheckedChange:e=>i(!e)})]}),(0,L.jsx)(W,{type:`button`,size:`icon`,variant:`ghost`,className:`h-8 w-8 text-destructive hover:text-destructive`,"aria-label":`Delete link`,onClick:a,children:(0,L.jsx)(vT,{className:`h-3.5 w-3.5`})})]})]}),(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(ZW,{label:`Link`,url:x}),u?(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`span`,{className:`w-10 shrink-0 text-[11px] font-medium text-muted-foreground`,children:`Alias`}),(0,L.jsx)(G,{autoFocus:!0,value:f,maxLength:64,placeholder:`friendly-path (blank to clear)`,"aria-invalid":!!h,className:`h-7 min-w-0 flex-1 text-sm`,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b(),e.key===`Escape`&&d(!1)}}),(0,L.jsx)(W,{type:`button`,size:`icon`,variant:`ghost`,className:`h-7 w-7`,"aria-label":`Save alias`,disabled:!!h,onClick:b,children:(0,L.jsx)(RC,{className:`h-3.5 w-3.5`})}),(0,L.jsx)(W,{type:`button`,size:`icon`,variant:`ghost`,className:`h-7 w-7`,"aria-label":`Cancel alias edit`,onClick:()=>d(!1),children:(0,L.jsx)(FT,{className:`h-3.5 w-3.5`})})]}),h&&(0,L.jsx)(`p`,{className:`pl-12 text-[11px] text-destructive`,children:h})]}):S?(0,L.jsx)(ZW,{label:`Alias`,url:S,onEdit:y}):(0,L.jsxs)(W,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 pl-0 text-[11px] text-muted-foreground hover:text-foreground`,onClick:y,children:[(0,L.jsx)(Gw,{className:`mr-1 h-3 w-3`}),`Add alias`]})]}),(0,L.jsxs)(`div`,{className:`flex flex-wrap gap-4 border-t pt-3 text-xs`,children:[(0,L.jsx)(QW,{label:`Views`,value:String(e.stats.views)}),(0,L.jsx)(QW,{label:`Leads`,value:String(e.stats.leads)}),(0,L.jsx)(QW,{label:`Conversion`,value:qW(e.stats.conversionRate)})]})]})})}function ZW({label:e,url:t,onEdit:n}){return(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`span`,{className:`w-10 shrink-0 text-[11px] font-medium text-muted-foreground`,children:e}),(0,L.jsx)(`code`,{className:`min-w-0 flex-1 select-all overflow-x-auto whitespace-nowrap rounded border bg-muted/50 px-2 py-1.5 font-mono text-[11px]`,children:t}),(0,L.jsx)(W,{type:`button`,size:`sm`,variant:`outline`,className:`shrink-0`,"aria-label":`Copy ${e.toLowerCase()} URL`,onClick:()=>JW(t),children:(0,L.jsx)(ew,{className:`h-3.5 w-3.5`})}),n&&(0,L.jsx)(W,{type:`button`,size:`icon`,variant:`ghost`,className:`h-8 w-8 shrink-0`,"aria-label":`Edit ${e.toLowerCase()}`,onClick:n,children:(0,L.jsx)(Bw,{className:`h-3.5 w-3.5`})})]})}function QW({label:e,value:t}){return(0,L.jsxs)(`div`,{className:`flex items-baseline gap-1.5`,children:[(0,L.jsx)(`span`,{className:`text-sm font-semibold tabular-nums`,children:t}),(0,L.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:e})]})}function $W(e){let t=e.filter(e=>e.deployed);return t.length===0?null:[...t].sort((e,t)=>
150{let n=new Date(t.createdAt).getTime()-new Date(e.createdAt).getTime();return n===0?t.versionNumber-e.versionNumber:n})[0]}function eG(e,t){return!e.deployed&&e.deployedAt==null&&t>1}function tG(e){if(typeof navigator>`u`||!navigator.clipboard){z.error(`Copy not supported`);return}navigator.clipboard.writeText(e).then(()=>z.success(`Copied`)).catch(()=>z.error(`Copy failed`))}function nG({detail:e,widgetId:t}){let n=ri(),r=e.versions,i=r[0]?.id,[a,o]=(0,_.useState)({}),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(null),d=()=>{n.invalidateQueries({queryKey:[`widget`,t]}),n.invalidateQueries({queryKey:[`widgets`]})},f=R({mutationFn:async({version:e,deployed:n})=>{try{return await LU(t,e.id,n)}catch(n){if(n instanceof lC&&n.status===422){let r=await MU(t,e.id),i=r.editing?KU(n,r.editing.snapshot):null,a=Error(i?.message??n.message);throw a.issues=i?.issues??[],a}throw n}},onMutate:({version:e})=>{o(t=>{if(!(e.id in t))return t;let n={...t};return delete n[e.id],n})},onSuccess:e=>{d(),z.success(e.deployed?`v${e.versionNumber} is live.`:`v${e.versionNumber} is off.`)},onError:(e,{version:t})=>{e.issues&&o(n=>({...n,[t.id]:e.issues})),z.error(e.message)}}),p=R({mutationFn:e=>BU(t,e),onSuccess:(e,t)=>{d(),c(null),z.success(`Restored v${t.versionNumber} as v${e.versionNumber} - it is not live until you deploy it.`)},onError:e=>z.error(e.message)}),m=R({mutationFn:e=>RU(t,e.id),onSuccess:(e,t)=>{d(),u(null),z.success(`Deleted v${t.versionNumber}`)},onError:e=>{z.error(e.message)}}),h=$W(r),g=r.filter(e=>e.deployed).length;return(0,L.jsxs)(`div`,{className:`space-y-3`,children:[g>1&&h&&(0,L.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-sky-500/40 bg-sky-500/5 p-2.5 text-[11px] leading-snug text-muted-foreground`,children:[(0,L.jsx)(Jw,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-sky-600 dark:text-sky-500`}),(0,L.jsxs)(`span`,{children:[g,` versions are deployed at once - that's the A/B test, each has its own embed script. The plain widget script (no`,(0,L.jsx)(`code`,{className:`mx-1 rounded bg-muted px-1 py-0.5`,children:`?embed=`}),`in its URL) can only serve one, and always takes the newest deployed:`,` `,(0,L.jsxs)(`span`,{className:`font-medium text-foreground`,children:[`v`,h.versionNumber]}),`.`]})]}),r.map(e=>{let t=e.id===i,n=f.isPending&&f.variables?.version.id===e.id,o=a[e.id]??[],s=BW(e.embedId),l=VW(window.location.origin,e.embedId);return(0,L.jsx)(K,{children:(0,L.jsxs)(q,{className:`space-y-3 p-4`,children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,L.jsxs)(`div`,{className:`min-w-0 space-y-1`,children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,L.jsxs)(`span`,{className:`text-sm font-semibold`,children:[`v`,e.versionNumber]}),t&&(0,L.jsx)(X,{variant:`outline`,className:`text-[10px]`,children:`latest`}),e.deployed?(0,L.jsxs)(X,{className:`gap-1 border-transparent bg-emerald-600 text-[10px] text-white dark:bg-emerald-500`,children:[(0,L.jsx)(Jw,{className:`h-2.5 w-2.5`}),`Deployed`]}):(0,L.jsx)(X,{variant:`secondary`,className:`text-[10px]`,children:`Not deployed`})]}),(0,L.jsxs)(`p`,{className:`text-xs text-muted-foreground`,title:new Date(e.createdAt).toLocaleString(),children:[RW(e.createdAt),e.createdByName?` by ${e.createdByName}`:``]}),(0,L.jsx)(`p`,{className:`text-xs`,children:e.changeReason?e.changeReason:(0,L.jsx)(`span`,{className:`italic text-muted-foreground`,children:`No reason given`})})]}),(0,L.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[n&&(0,L.jsx)(Ew,{className:`h-3.5 w-3.5 animate-spin`}),(0,L.jsx)(Ck,{checked:e.deployed,disabled:n,"aria-label":`Deploy v${e.versionNumber}`,onCheckedChange:t=>f.mutate({version:e,deployed:t})})]})]}),o.length>0&&(0,L.jsxs)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/5 p-2.5`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-medium text-destructive`,children:[(0,L.jsx)(xT,{className:`h-3.5 w-3.5`}),`Can't deploy v`,e.versionNumber]}),(0,L.jsx)(`ul`,{className:`mt-1 space-y-0.5 pl-5`,children:o.map((e,t)=>(0,L.jsx)(`li`,{className:`list-disc text-[11px] leading-snug text-muted-foreground`,children:e.message},`${e.code}-${t}`))})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(`code`,{className:`block select-all overflow-x-auto whitespace-nowrap rounded border bg-muted/50 px-2 py-1.5 font-mono text-[11px]`,children:s}),(0,L.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Two snippets pasted on the site - one per version - is the whole A/B test; WordPress's cookie splitter decides who sees which.`}),(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,L.jsxs)(W,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>tG(s),children:[(0,L.jsx)(ew,{className:`mr-1.5 h-3.5 w-3.5`}),`Copy embed snippet`]}),(0,L.jsxs)(W,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>tG(l),children:[(0,L.jsx)(gT,{className:`mr-1.5 h-3.5 w-3.5`}),`Copy test snippet`]}),!t&&(0,L.jsxs)(W,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>c(e),children:[(0,L.jsx)(Xw,{className:`mr-1.5 h-3.5 w-3.5`}),`Restore`]}),eG(e,r.length)&&(0,L.jsxs)(W,{type:`button`,variant:`ghost`,size:`sm`,className:`text-destructive hover:text-destructive`,onClick:()=>u(e),children:[(0,L.jsx)(vT,{className:`mr-1.5 h-3.5 w-3.5`}),`Delete`]})]})]})]})},e.id)}),(0,L.jsx)(lA,{open:!!s,onOpenChange:e=>!e&&c(null),children:(0,L.jsxs)(pA,{children:[(0,L.jsxs)(mA,{children:[(0,L.jsxs)(gA,{children:[`Restore v`,s?.versionNumber,` as a new version?`]}),(0,L.jsxs)(_A,{children:[`Versions are immutable, so this can't rewrite history - it opens v`,s?.versionNumber,`'s flow and saves it as v`,(r[0]?.versionNumber??0)+1,`. It won't be live until you deploy it.`]})]}),(0,L.jsxs)(hA,{children:[(0,L.jsx)(yA,{children:`Cancel`}),(0,L.jsxs)(vA,{disabled:p.isPending,onClick:e=>{e.preventDefault(),s&&p.mutate(s)},children:[p.isPending&&(0,L.jsx)(Ew,{className:`mr-1.5 h-3.5 w-3.5 animate-spin`}),`Restore`]})]})]})}),(0,L.jsx)(lA,{open:!!l,onOpenChange:e=>!e&&u(null),children:(0,L.jsxs)(pA,{children:[(0,L.jsxs)(mA,{children:[(0,L.jsxs)(gA,{children:[`Delete v`,l?.versionNumber,`?`]}
150),(0,L.jsx)(_A,{children:`This can't be undone. It never went live - but its own embed link still works, so if a lead or a tracked event is already attributed to it, the server will refuse and say so.`})]}),(0,L.jsxs)(hA,{children:[(0,L.jsx)(yA,{children:`Cancel`}),(0,L.jsxs)(vA,{disabled:m.isPending,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:e=>{e.preventDefault(),l&&m.mutate(l)},children:[m.isPending&&(0,L.jsx)(Ew,{className:`mr-1.5 h-3.5 w-3.5 animate-spin`}),`Delete`]})]})]})})]})}var rG=e=>({persona:e.persona,theme:e.theme,targeting:e.targeting});function iG(e){let{data:t,isLoading:n,isError:r}=vi({queryKey:[`widget`,e.widgetId],queryFn:()=>MU(e.widgetId),refetchOnWindowFocus:!1});return n?(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,L.jsx)(Ew,{className:`h-4 w-4 animate-spin`}),`Loading widgetâ¦`]}):r||!t?(0,L.jsx)(K,{children:(0,L.jsxs)(q,{className:`py-6 text-sm text-destructive`,children:[`Failed to load this widget.`,` `,(0,L.jsx)(`button`,{className:`underline`,onClick:e.onBack,children:`Back to widgets`})]})}):t.editing?(0,L.jsx)(aG,{detail:t,...e}):(0,L.jsx)(K,{children:(0,L.jsx)(q,{className:`py-6 text-sm text-muted-foreground`,children:`This widget has no version to edit.`})})}function aG({detail:e,widgetId:t,tab:n,setTab:r,onBack:i}){let a=ri(),o=e.editing,[s,c]=(0,_.useState)(()=>o.snapshot),[l,u]=(0,_.useState)(()=>JSON.stringify(o.snapshot)),[d,f]=(0,_.useState)(()=>rG(e.widget)),[p,m]=(0,_.useState)(()=>JSON.stringify(rG(e.widget))),[h,g]=(0,_.useState)(`en`),[v,y]=(0,_.useState)([]),[b,x]=(0,_.useState)(!1),[S,C]=(0,_.useState)(``),[w,T]=(0,_.useState)(!1),E=e,D=(0,_.useMemo)(()=>JSON.stringify(s)!==l,[s,l]),O=(0,_.useMemo)(()=>JSON.stringify(d)!==p,[d,p]),k=(0,_.useMemo)(()=>JSON.parse(p),[p]),A=(0,_.useCallback)(e=>{c(e),y([])},[]),j=(0,_.useMemo)(()=>{let e=gU(s),t=new Set(e.map(e=>`${e.code}::${e.nodeId??``}`)),n=v.filter(e=>!t.has(`${e.code}::${e.nodeId??``}`));return[...e,...n,..._U(s)]},[s,v]),M=j.filter(e=>e.severity===`error`),ee=j.filter(e=>e.severity===`warning`),N=R({mutationFn:()=>IU(t,s,S),onSuccess:e=>{x(!1),C(``),u(JSON.stringify(s)),a.invalidateQueries({queryKey:[`widget`,t]}),a.invalidateQueries({queryKey:[`widgets`]}),z.success(`Saved as v${e.versionNumber}. It isn't live until you deploy it.`)},onError:e=>{let t=KU(e,s);if(t){x(!1),y(t.issues),z.error(t.message);return}z.error(e.message)}}),P=R({mutationFn:()=>{let e=oW(k.theme,d.theme);return FU(t,e.length>0?{...d,unsetTheme:e}:d)},onSuccess:e=>{let n={persona:e.persona,theme:e.theme,targeting:e.targeting};f(n),m(JSON.stringify(n)),a.invalidateQueries({queryKey:[`widget`,t]}),a.invalidateQueries({queryKey:[`widgets`]}),z.success(`Settings saved - every version of this widget uses them.`)},onError:e=>z.error(e.message)}),F=()=>{if(M.length>0){z.error(`Fix ${M.length} problem${M.length===1?``:`s`} in the flow first - they're marked in red.`);return}x(!0)},I=()=>{D||O?T(!0):i()},te=o.versionId===E.versions[0]?.id;return(0,L.jsxs)(`div`,{className:`space-y-4`,children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,L.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2`,children:[(0,L.jsx)(W,{variant:`ghost`,size:`icon`,className:`mt-0.5 h-8 w-8 shrink-0`,onClick:I,"aria-label":`Back to widgets`,children:(0,L.jsx)(CC,{className:`h-4 w-4`})}),(0,L.jsxs)(`div`,{className:`min-w-0`,children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,L.jsx)(`h1`,{className:`truncate text-xl font-semibold tracking-tight`,children:E.widget.name}),E.widget.isDefault&&(0,L.jsx)(X,{variant:`secondary`,className:`text-[10px]`,children:`Default`}),(0,L.jsxs)(X,{variant:`outline`,className:`text-[10px]`,children:[`v`,o.versionNumber,te?` · latest`:``]}),(D||O)&&(0,L.jsx)(X,{className:`text-[10px]`,children:`Unsaved`})]}),(0,L.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:`Each save creates a new immutable version. Nothing goes live until a version is deployed.`})]})]}),(n===`build`||n===`settings`)&&(0,L.jsx)(`div`,{className:`flex shrink-0 items-center gap-2`,children:n===`settings`?(0,L.jsxs)(W,{size:`sm`,onClick:()=>P.mutate(),disabled:!O||P.isPending,children:[P.isPending?(0,L.jsx)(Ew,{className:`mr-1.5 h-3.5 w-3.5 animate-spin`}):(0,L.jsx)(Qw,{className:`mr-1.5 h-3.5 w-3.5`}),`Save settings`]}):(0,L.jsxs)(W,{size:`sm`,onClick:F,disabled:!D||N.isPending,children:[N.isPending?(0,L.jsx)(Ew,{className:`mr-1.5 h-3.5 w-3.5 animate-spin`}):(0,L.jsx)(Qw,{className:`mr-1.5 h-3.5 w-3.5`}),`Save version`]})})]}),n===`build`&&ee.length>0&&(0,L.jsxs)(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/5 p-2.5`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-medium text-amber-700 dark:text-amber-500`,children:[(0,L.jsx)(xT,{className:`h-3.5 w-3.5`}),`Can be saved, but not deployed yet`]}),(0,L.jsx)(`p`,{className:`mt-0.5 text-[11px] leading-snug text-muted-foreground`,children:`Every branch a visitor can take has to ask for their name and phone before the closing step - a lead we can't contact is a lead lost.`}),(0,L.jsx)(`ul`,{className:`mt-1 space-y-0.5 pl-5`,children:ee.map((e,t)=>(0,L.jsx)(`li`,{className:`list-disc text-[11px] leading-snug text-muted-foreground`,children:e.message},`${e.code}-${t}`))})]}),(0,L.jsxs)(KL,{value:n,onValueChange:e=>
150r(e),children:[(0,L.jsxs)(qL,{children:[(0,L.jsxs)(JL,{value:`build`,children:[(0,L.jsx)(PT,{className:`mr-1.5 h-3.5 w-3.5`}),`Build`,D&&(0,L.jsx)(oG,{})]}),(0,L.jsxs)(JL,{value:`settings`,children:[(0,L.jsx)(Iw,{className:`mr-1.5 h-3.5 w-3.5`}),`Settings`,O&&(0,L.jsx)(oG,{})]}),(0,L.jsxs)(JL,{value:`versions`,children:[(0,L.jsx)(vw,{className:`mr-1.5 h-3.5 w-3.5`}),`Versions`]}),(0,L.jsxs)(JL,{value:`share-links`,children:[(0,L.jsx)(Cw,{className:`mr-1.5 h-3.5 w-3.5`}),`Share links`]}),(0,L.jsxs)(JL,{value:`analytics`,children:[(0,L.jsx)(LC,{className:`mr-1.5 h-3.5 w-3.5`}),`Analytics`]})]}),(0,L.jsx)(YL,{value:`build`,className:`mt-3`,children:(0,L.jsx)(TW,{flow:s,onChange:A,issues:j,locale:h,setLocale:g,persona:d.persona,theme:d.theme})}),(0,L.jsx)(YL,{value:`settings`,className:`mt-3`,children:(0,L.jsx)(IW,{draft:d,setDraft:f,savedTheme:k.theme,flow:s,locale:h})}),(0,L.jsx)(YL,{value:`versions`,className:`mt-3`,children:(0,L.jsx)(nG,{detail:E,widgetId:t})}),(0,L.jsx)(YL,{value:`share-links`,className:`mt-3`,children:(0,L.jsx)(YW,{widgetId:t})}),(0,L.jsx)(YL,{value:`analytics`,className:`mt-3`,children:(0,L.jsx)(BV,{widgetId:t,versions:E.versions})})]}),(0,L.jsx)(aj,{open:b,onOpenChange:x,children:(0,L.jsxs)(lj,{children:[(0,L.jsxs)(uj,{children:[(0,L.jsxs)(fj,{children:[`Save as v`,(E.versions[0]?.versionNumber??0)+1]}),(0,L.jsx)(pj,{children:`Versions are immutable - this freezes the flow as it is now, with your name and the time. It does not go live: deploying a version is a separate, deliberate step.`})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`change-reason`,children:`What changed? (optional)`}),(0,L.jsx)(G,{id:`change-reason`,autoFocus:!0,maxLength:500,value:S,placeholder:`e.g. Ask budget before timeline for buyers`,onChange:e=>C(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!N.isPending&&N.mutate()}}),(0,L.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Shows up in the version history - worth a line when you come back to compare A against B.`})]}),(0,L.jsxs)(dj,{children:[(0,L.jsx)(W,{variant:`outline`,onClick:()=>x(!1),children:`Cancel`}),(0,L.jsxs)(W,{disabled:N.isPending,onClick:()=>N.mutate(),children:[N.isPending&&(0,L.jsx)(Ew,{className:`mr-1.5 h-3.5 w-3.5 animate-spin`}),`Save version`]})]})]})}),(0,L.jsx)(lA,{open:w,onOpenChange:T,children:(0,L.jsxs)(pA,{children:[(0,L.jsxs)(mA,{children:[(0,L.jsx)(gA,{children:`Discard unsaved changes?`}),(0,L.jsx)(_A,{children:`There's no draft state - anything not saved as a version is lost when you leave.`})]}),(0,L.jsxs)(hA,{children:[(0,L.jsx)(yA,{children:`Keep editing`}),(0,L.jsx)(vA,{onClick:i,children:`Discard`})]})]})})]})}function oG(){return(0,L.jsx)(`span`,{"aria-hidden":!0,title:`Unsaved changes`,className:`ml-1.5 inline-block h-1.5 w-1.5 rounded-full bg-primary`})}function sG({onOpen:e}){let t=ri(),[n,r]=(0,_.useState)(!1),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(!1),{data:f,isLoading:p,isError:m}=vi({queryKey:[`widgets`,{archived:u}],queryFn:()=>jU(u)}),h=()=>t.invalidateQueries({queryKey:[`widgets`]}),g=R({mutationFn:e=>NU(e),onSuccess:t=>{h(),r(!1),a(``),z.success(`Created â${t.name}â`),e(t.id)},onError:e=>z.error(e.message)}),v=R({mutationFn:e=>PU(e),onSuccess:t=>{h(),z.success(`Created â${t.name}â - an independent copy you can A/B against the original.`),e(t.id)},onError:e=>z.error(e.message)}),y=R({mutationFn:({id:e,name:t})=>FU(e,{name:t}),onSuccess:()=>{h(),s(null),z.success(`Renamed`)},onError:e=>z.error(e.message)}),b=R({mutationFn:({id:e,archived:t})=>zU(e,t),onSuccess:(e,t)=>{h(),z.success(t.archived?`Archived â${e.name}â`:`Restored â${e.name}â`)},onError:e=>z.error(e.message)});if(p)return(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,L.jsx)(Ew,{className:`h-4 w-4 animate-spin`}),`Loading widgetsâ¦`]});if(m)return(0,L.jsx)(K,{children:(0,L.jsx)(q,{className:`py-6 text-sm text-destructive`,children:`Failed to load widgets.`})});let x=f??[];return(0,L.jsxs)(`div`,{className:`space-y-4`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[x.length,` `,u?`archived `:``,`widget`,x.length===1?``:`s`]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsxs)(W,{type:`button`,size:`sm`,variant:u?`secondary`:`outline`,onClick:()=>d(e=>!e),children:[u?(0,L.jsx)(bC,{className:`mr-1.5 h-3.5 w-3.5`}):(0,L.jsx)(xC,{className:`mr-1.5 h-3.5 w-3.5`}),u?`Back to widgets`:`Show archived`]}),(0,L.jsxs)(W,{size:`sm`,onClick:()=>r(!0),children:[(0,L.jsx)(Gw,{className:`mr-1.5 h-3.5 w-3.5`}),`New widget`]})]})]}),x.length===0?(0,L.jsx)(K,{children:(0,L.jsxs)(q,{className:`flex flex-col items-center gap-2 py-10 text-center`,children:[(0,L.jsx)(`p`,{className:`text-sm font-medium`,children:u?`No archived widgets`:`No widgets yet`}),(0,L.jsx)(`p`,{className:`max-w-sm text-xs text-muted-foreground`,children:u?`Widgets you archive show up here, restorable at any time.`:`A widget is one embeddable chat flow. Create one to start building.`})]})}):(0,L.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 xl:grid-cols-3`,children:x.map(t=>(0,L.jsx)(K,{role:`button`,tabIndex:0,onClick:()=>e(t.id),onKeyDown:n=>{n.key===`Enter`&&e(t.id)}
150,className:`cursor-pointer transition-colors hover:border-primary/50`,children:(0,L.jsxs)(q,{className:`space-y-3 p-4`,children:[(0,L.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,L.jsxs)(`div`,{className:`min-w-0`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,L.jsx)(`h3`,{className:`truncate text-sm font-semibold`,children:t.name}),t.isDefault&&(0,L.jsx)(X,{variant:`secondary`,className:`h-4 shrink-0 px-1 text-[10px] font-normal`,title:`Served to embeds that don't name a version`,children:`Default`}),t.archivedAt&&(0,L.jsx)(X,{variant:`outline`,className:`h-4 shrink-0 px-1 text-[10px] font-normal`,children:`Archived`})]}),(0,L.jsx)(`p`,{className:`mt-0.5 text-[11px] text-muted-foreground`,children:t.lastVersionAt?`Last saved ${RW(t.lastVersionAt)}`:`Never saved`})]}),(0,L.jsxs)(Uj,{children:[(0,L.jsx)(Wj,{asChild:!0,children:(0,L.jsx)(W,{type:`button`,variant:`ghost`,size:`icon`,className:`h-7 w-7 shrink-0`,"aria-label":`Options for ${t.name}`,onClick:e=>e.stopPropagation(),children:(0,L.jsx)(aw,{className:`h-4 w-4`})})}),(0,L.jsxs)(Gj,{align:`end`,onClick:e=>e.stopPropagation(),children:[(0,L.jsxs)(Kj,{onClick:()=>{s(t),l(t.name)},children:[(0,L.jsx)(Bw,{className:`mr-2 h-3.5 w-3.5`}),`Rename`]}),t.archivedAt?(0,L.jsxs)(Kj,{disabled:b.isPending,onClick:()=>b.mutate({id:t.id,archived:!1}),children:[(0,L.jsx)(bC,{className:`mr-2 h-3.5 w-3.5`}),`Restore`]}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(Kj,{disabled:v.isPending,onClick:()=>v.mutate(t.id),children:[(0,L.jsx)(ew,{className:`mr-2 h-3.5 w-3.5`}),`Duplicate (A/B variant)`]}),(0,L.jsxs)(Kj,{className:t.isDefault?`opacity-50`:void 0,title:t.isDefault?`The default widget backs the live embed and can't be archived`:void 0,onClick:()=>{b.isPending||b.mutate({id:t.id,archived:!0})},children:[(0,L.jsx)(xC,{className:`mr-2 h-3.5 w-3.5`}),`Archive`]})]})]})]})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-3 text-[11px] text-muted-foreground`,children:[(0,L.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(vw,{className:`h-3 w-3`}),t.versionCount,` version`,t.versionCount===1?``:`s`]}),(0,L.jsxs)(`span`,{className:t.deployedCount>0?`flex items-center gap-1 text-emerald-600 dark:text-emerald-500`:`flex items-center gap-1`,children:[(0,L.jsx)(Jw,{className:`h-3 w-3`}),t.deployedCount,` deployed`]})]})]})},t.id))}),(0,L.jsx)(aj,{open:n,onOpenChange:r,children:(0,L.jsxs)(lj,{children:[(0,L.jsxs)(uj,{children:[(0,L.jsx)(fj,{children:`New widget`}),(0,L.jsx)(pj,{children:`Starts from a minimal, deployable flow - intent â name â phone â closing - that you can build out.`})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`new-widget-name`,children:`Name`}),(0,L.jsx)(G,{id:`new-widget-name`,autoFocus:!0,value:i,placeholder:`e.g. Seller landing bot`,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&i.trim()&&g.mutate(i.trim())}})]}),(0,L.jsxs)(dj,{children:[(0,L.jsx)(W,{variant:`outline`,onClick:()=>r(!1),children:`Cancel`}),(0,L.jsxs)(W,{disabled:!i.trim()||g.isPending,onClick:()=>g.mutate(i.trim()),children:[g.isPending&&(0,L.jsx)(Ew,{className:`mr-1.5 h-3.5 w-3.5 animate-spin`}),`Create`]})]})]})}),(0,L.jsx)(aj,{open:!!o,onOpenChange:e=>!e&&s(null),children:(0,L.jsxs)(lj,{children:[(0,L.jsx)(uj,{children:(0,L.jsx)(fj,{children:`Rename widget`})}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`rename-widget`,children:`Name`}),(0,L.jsx)(G,{id:`rename-widget`,autoFocus:!0,value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&o&&c.trim()&&y.mutate({id:o.id,name:c.trim()})}})]}),(0,L.jsxs)(dj,{children:[(0,L.jsx)(W,{variant:`outline`,onClick:()=>s(null),children:`Cancel`}),(0,L.jsxs)(W,{disabled:!c.trim()||y.isPending,onClick:()=>o&&y.mutate({id:o.id,name:c.trim()}),children:[y.isPending&&(0,L.jsx)(Ew,{className:`mr-1.5 h-3.5 w-3.5 animate-spin`}),`Save`]})]})]})})]})}var cG=[`widgets`,`analytics`],lG=[`build`,`settings`,`versions`,`share-links`,`analytics`];function uG(){let[e,t]=jn(),n=e.get(`widget`),r=e.get(`tab`)??``,i=(0,_.useCallback)(e=>t(t=>{let n=new URLSearchParams(t);return e(n),n},{replace:!0}),[t]),a=(0,_.useCallback)(e=>i(t=>{t.set(`widget`,e),t.set(`tab`,`build`)}),[i]),o=(0,_.useCallback)(()=>i(e=>{e.delete(`widget`),e.set(`tab`,`widgets`)}),[i]);if(n)return(0,L.jsx)(iG,{widgetId:n,tab:lG.includes(r)?r:`build`,setTab:e=>i(t=>t.set(`tab`,e)),onBack:o});
150let s=cG.includes(r)?r:`widgets`;return(0,L.jsxs)(`div`,{className:`space-y-6`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Website Widget`}),(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`The lead-capture chat flows embedded on stackedhomes.com. Each widget is versioned - build a flow, save a version, deploy it.`})]}),(0,L.jsxs)(KL,{value:s,onValueChange:e=>i(t=>t.set(`tab`,e)),children:[(0,L.jsxs)(qL,{children:[(0,L.jsx)(JL,{value:`widgets`,children:`Widgets`}),(0,L.jsx)(JL,{value:`analytics`,children:`Analytics`})]}),(0,L.jsx)(YL,{value:`widgets`,className:`mt-4`,children:(0,L.jsx)(sG,{onOpen:a})}),(0,L.jsx)(YL,{value:`analytics`,className:`mt-4`,children:(0,L.jsx)(BV,{})})]})]})}var dG=10,fG={new:`new`,contacted:`contacted`,qualified:`qualified`,awaiting_consent:`awaiting consent`,consent_declined:`consent declined`,interested:`interested`,not_interested:`not interested`,lost:`lost`,skipped:`skipped`},pG={qualified:`default`,interested:`default`,contacted:`secondary`,awaiting_consent:`secondary`,new:`outline`,consent_declined:`destructive`,not_interested:`destructive`,lost:`destructive`,skipped:`destructive`};function mG(e,t){let n=t===`active`?[`lost`,`skipped`,`not_interested`]:[],r=[];for(let t of n){let n=e[t]??0;n>0&&r.push(`${n} ${fG[t]}`)}return r.length===0?`No leads.`:`No active leads. ${r.join(` · `)}`}function hG({agentId:e,agentActiveCount:t,onOpenLead:n}){let[r,i]=(0,_.useState)(`active`),[a,o]=(0,_.useState)(dG),{data:s,isLoading:c,error:l,refetch:u,isFetching:d}=vi({queryKey:[`leads`,`for-agent`,e,r],queryFn:()=>H(`/api/agents/${e}/leads${r===`all`?`?status=all`:``}`),staleTime:3e4}),f=s?.data.leads??[],p=f.slice(0,a),m=Math.max(0,f.length-a),h=r===`active`?s?.data.activeCount??t:s?.data.totalCount??t,g=d&&!c,v=e=>{e!==r&&(i(e),o(dG))};return(0,L.jsxs)(`div`,{className:`col-span-full`,children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 mb-2`,children:[(0,L.jsxs)(`div`,{className:`font-medium text-muted-foreground text-xs uppercase flex items-center gap-2`,children:[(0,L.jsx)(`span`,{children:`Leads`}),(0,L.jsxs)(`span`,{className:`text-muted-foreground/70 normal-case`,children:[`· `,h,` `,r===`active`?`active`:`total`]}),g&&(0,L.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70 normal-case`,children:`refreshingâ¦`})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsxs)(`div`,{role:`group`,"aria-label":`Lead status filter`,className:`inline-flex rounded-md border bg-background p-0.5 text-xs`,children:[(0,L.jsx)(`button`,{type:`button`,"aria-pressed":r===`active`,onClick:()=>v(`active`),className:`px-2 py-0.5 rounded ${r===`active`?`bg-foreground text-background`:`text-muted-foreground hover:text-foreground`}`,children:`Active`}),(0,L.jsx)(`button`,{type:`button`,"aria-pressed":r===`all`,onClick:()=>v(`all`),className:`px-2 py-0.5 rounded ${r===`all`?`bg-foreground text-background`:`text-muted-foreground hover:text-foreground`}`,children:`All`})]}),(0,L.jsxs)(Cn,{to:`/leads?filter.assignedAgentId=in:${encodeURIComponent(e)}`,className:`text-xs text-blue-600 dark:text-blue-400 hover:underline inline-flex items-center gap-1`,children:[`Open in Leads page`,(0,L.jsx)(ow,{className:`h-3 w-3`})]})]})]}),c?(0,L.jsx)(gG,{}):l?(0,L.jsxs)(`div`,{className:`text-xs text-muted-foreground flex items-center gap-2`,children:[(0,L.jsx)(`span`,{children:`Couldn't load leads.`}),(0,L.jsx)(`button`,{type:`button`,onClick:()=>u(),className:`text-blue-600 dark:text-blue-400 hover:underline`,children:`Retry`})]}):f.length===0?(0,L.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:mG(s?.data.statusCounts??{},r)}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`div`,{className:`border rounded-md bg-background`,children:(0,L.jsxs)(Pk,{children:[(0,L.jsx)(Fk,{children:(0,L.jsxs)(Lk,{children:[(0,L.jsx)(J,{className:`h-8 text-xs`,children:`Name`}),(0,L.jsx)(J,{className:`h-8 text-xs`,children:`Status`}),(0,L.jsx)(J,{className:`h-8 text-xs`,children:`Warmth`}),(0,L.jsx)(J,{className:`h-8 text-xs`,children:`Last contacted`}),(0,L.jsx)(J,{className:`h-8 text-xs`,children:`Assigned`})]})}),(0,L.jsx)(Ik,{children:p.map(e=>
150(0,L.jsxs)(Lk,{className:`cursor-pointer`,onClick:()=>n(e.id),children:[(0,L.jsx)(Y,{className:`py-2 text-sm font-medium`,children:e.name||`(no name)`}),(0,L.jsx)(Y,{className:`py-2`,children:(0,L.jsx)(X,{variant:pG[e.status]??`outline`,className:`text-[10px]`,children:fG[e.status]??e.status})}),(0,L.jsx)(Y,{className:`py-2`,children:(0,L.jsx)(X,{variant:bM[e.warmth]??`outline`,className:`text-[10px]`,children:e.warmth})}),(0,L.jsx)(Y,{className:`py-2 text-sm text-muted-foreground`,children:RW(e.lastContactedAt)}),(0,L.jsx)(Y,{className:`py-2 text-sm text-muted-foreground`,children:RW(e.createdAt)})]},e.id))})]})}),m>0&&(0,L.jsx)(`div`,{className:`mt-2`,children:(0,L.jsxs)(W,{variant:`ghost`,size:`sm`,onClick:()=>o(e=>Math.min(e+dG,f.length)),children:[`Show `,Math.min(dG,m),` more`]})})]})]})}function gG(){return(0,L.jsx)(`div`,{className:`border rounded-md bg-background`,children:(0,L.jsxs)(Pk,{children:[(0,L.jsx)(Fk,{children:(0,L.jsxs)(Lk,{children:[(0,L.jsx)(J,{className:`h-8 text-xs`,children:`Name`}),(0,L.jsx)(J,{className:`h-8 text-xs`,children:`Status`}),(0,L.jsx)(J,{className:`h-8 text-xs`,children:`Warmth`}),(0,L.jsx)(J,{className:`h-8 text-xs`,children:`Last contacted`}),(0,L.jsx)(J,{className:`h-8 text-xs`,children:`Assigned`})]})}),(0,L.jsx)(Ik,{children:[0,1,2].map(e=>(0,L.jsxs)(Lk,{children:[(0,L.jsx)(Y,{className:`py-2`,children:(0,L.jsx)(`div`,{className:`h-3 bg-muted rounded animate-pulse w-28`})}),(0,L.jsx)(Y,{className:`py-2`,children:(0,L.jsx)(`div`,{className:`h-4 bg-muted rounded animate-pulse w-16`})}),(0,L.jsx)(Y,{className:`py-2`,children:(0,L.jsx)(`div`,{className:`h-4 bg-muted rounded animate-pulse w-12`})}),(0,L.jsx)(Y,{className:`py-2`,children:(0,L.jsx)(`div`,{className:`h-3 bg-muted rounded animate-pulse w-16`})}),(0,L.jsx)(Y,{className:`py-2`,children:(0,L.jsx)(`div`,{className:`h-3 bg-muted rounded animate-pulse w-16`})})]},e))})]})})}function _G(e){if(!e.isGroup)return e.phone;let t=e.members??[];return t.length===0?null:t.map(e=>e.phone||`â`).join(`, `)}function vG(e,t){return e.isGroup?!1:!!t.shlGroupConversationId&&!t.phone.trim()}function yG(e,t,n){let r=e=>e.split(`,`).map(e=>e.trim()).filter(Boolean);return{...e.isGroup?{}:{phone:t.phone||null},specialties:r(t.specialties),languages:r(t.languages),propertyTypes:r(t.propertyTypes),districts:r(t.districts),budgetMin:t.budgetMin?Number(t.budgetMin):null,budgetMax:t.budgetMax?Number(t.budgetMax):null,...t.dailyCap===``?{}:{dailyCap:Number(t.dailyCap)},notes:t.notes||null,introText:t.introText||null,shlGroupConversationId:t.shlGroupConversationId||null,...e.isGroup&&n.a&&n.b?{memberAgentIds:[n.a,n.b]}:{}}}var bG=`image/jpeg,image/png,image/webp`,xG=10*1024*1024,SG=1024,CG=`__auto__`;function wG({agent:e}){let t=_G(e);return t?(0,L.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono`,children:t}):null}function TG(e){return e==null?``:e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(0)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function EG(e){return e==null?`(empty)`:Array.isArray(e)?e.length===0?`(empty)`:e.join(`, `):typeof e==`boolean`?e?`Yes`:`No`:String(e)}function DG(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(!1),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)({}),[u,d]=(0,_.useState)({}),[f,p]=(0,_.useState)({phone:``,specialties:``,languages:``,propertyTypes:``,districts:``,budgetMin:``,budgetMax:``,dailyCap:``,notes:``,introText:``,shlGroupConversationId:``}),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(!1),[y,b]=(0,_.useState)(!1),[x,S]=(0,_.useState)(!1),[C,w]=(0,_.useState)({name:``,phone:``,email:``,agency:``}),[T,E]=(0,_.useState)(!1),[D,O]=(0,_.useState)(!1),[k,A]=(0,_.useState)({name:``,memberA:``,memberB:``}),[j,M]=(0,_.useState)(!1),[ee,N]=(0,_.useState)({a:``,b:``}),[P,F]=(0,_.useState)([]),[I,te]=(0,_.useState)(!1),[ne,re]=(0,_.useState)(!0),[ie,ae]=(0,_.useState)(!0),[oe,se]=(0,_.useState)(!1),ce=e.filter(e=>!(ne&&!e.isActive||ie&&!e.canTakeLeads||oe&&e.shlGroupSource!==`unmapped`)),[le,ue]=jn(),[de,fe]=(0,_.useState)(null),[pe,me]=(0,_.useState)(!1),he=le.get(`lead`);(0,_.useEffect)(()=>{he&&(fe(he),me(!0))},[he]);let ge=e=>{fe(e),me(!0),ue(t=>{let n=new URLSearchParams(t);return n.set(`lead`,e),n},{replace:!0})},_e=()=>{me(!1),fe(null),le.has(`lead`)&&ue(e=>{let t=new URLSearchParams(e);return t.delete(`lead`),t},{replace:!0})},ve=async()=>
150{if(C.name.trim()){E(!0);try{let e={name:C.name.trim()};C.phone.trim()&&(e.phone=C.phone.trim()),C.email.trim()&&(e.email=C.email.trim()),C.agency.trim()&&(e.agency=C.agency.trim()),await H(`/api/agents`,{method:`POST`,body:JSON.stringify(e)}),z.success(`Agent created`),S(!1),w({name:``,phone:``,email:``,agency:``}),Se()}catch(e){z.error(e instanceof Error?e.message:`Failed to create agent`)}finally{E(!1)}}},ye=async e=>{try{let t=(await H(`/api/agents/${e.id}`,{method:`DELETE`})).data.action===`archived`?`archived`:`deleted`;z.success(`Agent "${e.name}" ${t}`),Se()}catch(e){z.error(e instanceof Error?e.message:`Failed to delete agent`)}},be=async e=>{try{await H(`/api/agents/${e.id}/unarchive`,{method:`POST`}),z.success(`Agent "${e.name}" reactivated`),Se()}catch(e){z.error(e instanceof Error?e.message:`Failed to reactivate agent`)}},xe=()=>{b(!0);try{Wk([`Name`,`Phone`,`Email`,`Agency`,`Can Take Leads`,`Do Not Pass`,`Active Lead Count`,`Budget Range`,`Property Types`,`Specialties`,`Languages`,`Districts`,`Years Experience`,`Full Time`,`Personality`,`Communication Preference`,`Lead Restrictions`,`Internal Notes`,`Synced From Sheet`,`Created`],e.map(e=>[e.name,_G(e)??``,e.email??``,e.agency??``,e.canTakeLeads?`Yes`:`No`,e.doNotPassLeads?`Yes`:`No`,String(e.activeLeadCount),e.budgetRange??``,(e.propertyTypes??[]).join(`; `),(e.specialties??[]).join(`; `),(e.languages??[]).join(`; `),(e.districts??[]).join(`; `),e.yearsExperience==null?``:String(e.yearsExperience),e.isFullTime===!0?`Yes`:e.isFullTime===!1?`No`:``,e.personalityType??``,e.communicationPreference??``,e.leadRestrictions??``,e.notes??``,e.syncedFromSheet?`Yes`:`No`,new Date(e.createdAt).toISOString()]),`agents-${new Date().toISOString().split(`T`)[0]}.csv`)}finally{b(!1)}},Se=()=>{H(`/api/agents`).then(e=>t(e.data??[])).catch(e=>{console.error(`[agents] fetch agents failed:`,e),z.error(`Failed to load agents`)})},Ce=()=>H(`/api/agents/shl-groups`).then(e=>F(e.data??[])).catch(e=>console.error(`[agents] fetch SHL groups failed:`,e));(0,_.useEffect)(()=>{Se(),Ce()},[]);let we=async()=>{te(!0);try{let{created:e,shlCreated:t,renamed:n,failed:r,truncated:i,totalGroups:a}=(await H(`/api/whatsapp/groups/reconcile`,{method:`POST`})).data;await Ce();let o=[];t>0&&o.push(`${t} SHL group${t===1?``:`s`} added`);let s=e-t;s>0&&o.push(`${s} other group${s===1?``:`s`}`),n>0&&o.push(`${n} renamed`),r>0?z.error(`${r} group${r===1?``:`s`} could not be saved${o.length>0?` (${o.join(`, `)})`:``}. Check the activity log and try again.`):i?z.warning(`${o.join(`, `)}. More groups matched than one scan handles - some were skipped.`):o.length>0?z.success(o.join(`, `)):z.success(`No new groups. WhatsApp is in ${a} group${a===1?``:`s`}.`)}catch(e){console.error(`[agents] scan WhatsApp groups failed:`,e),z.error(e instanceof Error?e.message:`Failed to scan WhatsApp groups`)}finally{te(!1)}},Te=async()=>{r(!0);try{await H(`/api/agents/sync`,{method:`POST`}),z.success(`Agents synced from sheet`),Se()}catch(e){console.error(`[agents] sync from sheet failed:`,e),z.error(`Failed to sync agents from sheet`)}finally{r(!1)}},Ee=e=>{a(e),p({phone:e.phone??``,specialties:(e.specialties??[]).join(`, `),languages:(e.languages??[]).join(`, `),propertyTypes:(e.propertyTypes??[]).join(`, `),districts:(e.districts??[]).join(`, `),budgetMin:e.budgetMin?.toString()??``,budgetMax:e.budgetMax?.toString()??``,dailyCap:e.dailyCap?.toString()??`1`,notes:e.notes??``,introText:e.introText??``,shlGroupConversationId:e.shlGroupConversationId??``}),N({a:e.memberAgentIds?.[0]??``,b:e.memberAgentIds?.[1]??``})},De=t=>!t.isGroup||!t.memberAgentIds?!1:t.memberAgentIds.some(t=>{let n=e.find(e=>e.id===t);return n?!n.isActive:!0}),Oe=async(e,t)=>{if(!bG.split(`,`).includes(t.type)){z.error(`Unsupported file type. Convert HEIC â JPEG before uploading.`);return}if(t.size>xG){z.error(`File too large (max 10 MB).`);return}h(!0);try{let n=new FormData;n.append(`image`,t);let r=await fetch(`/api/agents/${e}/intro-image`,{method:`POST`,body:n,credentials:`include`}),i=await r.json().catch(()=>({}));if(!r.ok||!i.success)throw Error(i.error??`Upload failed: ${r.status}`);z.success(`Intro image uploaded`),a((await H(`/api/agents/${e}`)).data),Se()}catch(e){z.error(e instanceof Error?e.message:`Failed to upload intro image`)}finally{h(!1)}},ke=async e=>{v(!0);try{await H(`/api/agents/${e}/intro-image`,{method:`DELETE`}),z.success(`Intro image removed`),a((await H(`/api/agents/${e}`)).data),Se()}catch(e){z.error(e instanceof Error?e.message:`Failed to remove intro image`)}finally{v(!1)}},Ae=async e=>{let n=!e.canTakeLeads;t(t=>t.map(t=>
150t.id===e.id?{...t,canTakeLeads:n}:t));try{await H(`/api/agents/${e.id}`,{method:`PUT`,body:JSON.stringify({canTakeLeads:n})}),z.success(n?`${e.name} can now take leads`:`${e.name} won't be assigned new leads`)}catch(r){t(t=>t.map(t=>t.id===e.id?{...t,canTakeLeads:!n}:t)),console.error(`[agents] toggle canTakeLeads failed:`,r),z.error(`Failed to update lead-taking status`)}},je=async e=>{try{await H(`/api/agents/${e.id}/bump-cap`,{method:`POST`}),z.success(`Bumped ${e.name}'s cap +1 for today`),Se()}catch(e){console.error(`[agents] bump cap failed:`,e),z.error(`Failed to bump cap`)}},Me=async()=>{if(i){if(vG(i,f)){z.error(`Phone number is empty â add a phone number before mapping an SHL group.`);return}try{await H(`/api/agents/${i.id}`,{method:`PUT`,body:JSON.stringify(yG(i,f,ee))}),z.success(i.isGroup?`Pair updated`:`Agent updated`),a(null),Se()}catch(e){console.error(`[agents] save agent failed:`,e),z.error(e instanceof Error?e.message:`Failed to save agent`)}}},Ne=async()=>{let{memberA:e,memberB:t}=k;if(!e||!t){z.error(`Pick two agents for the pair`);return}if(e===t){z.error(`A pair needs two different agents`);return}M(!0);try{await H(`/api/agents/pairs`,{method:`POST`,body:JSON.stringify({memberAgentIds:[e,t],...k.name.trim()?{name:k.name.trim()}:{}})}),z.success(`Pair created`),O(!1),A({name:``,memberA:``,memberB:``}),Se()}catch(e){z.error(e instanceof Error?e.message:`Failed to create pair`)}finally{M(!1)}},Pe=e=>{let t=o!==e;s(t=>t===e?null:e),t&&!c[e]&&H(`/api/agents/${e}/articles`).then(t=>{l(n=>({...n,[e]:t.data??[]}))}).catch(t=>{console.error(`[agents] fetch articles failed:`,t),l(t=>({...t,[e]:[]}))}),t&&!u[e]&&H(`/api/agents/${e}/history`).then(t=>{d(n=>({...n,[e]:t.data??[]}))}).catch(t=>{console.error(`[agents] fetch history failed:`,t),d(t=>({...t,[e]:[]}))})};return(0,L.jsxs)(`div`,{className:`space-y-6`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,L.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Agents`}),(0,L.jsx)(sA,{interval:`1 hour`,source:`Google Sheets`})]}),(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Property agents synced from Stacked Partner Agents sheet.`})]}),(0,L.jsxs)(`div`,{className:`flex gap-2`,children:[(0,L.jsxs)(aj,{open:x,onOpenChange:S,children:[(0,L.jsx)(oj,{asChild:!0,children:(0,L.jsxs)(W,{size:`sm`,children:[(0,L.jsx)(Gw,{className:`h-4 w-4 mr-1.5`}),`New Agent`]})}),(0,L.jsxs)(lj,{className:`sm:max-w-md`,children:[(0,L.jsx)(uj,{children:(0,L.jsx)(fj,{children:`Create Agent`})}),(0,L.jsxs)(`div`,{className:`space-y-4`,children:[(0,L.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{children:`N
150ame *`}),(0,L.jsx)(G,{value:C.name,onChange:e=>w(t=>({...t,name:e.target.value})),placeholder:`Agent name`})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{children:`Phone`}),(0,L.jsx)(G,{value:C.phone,onChange:e=>w(t=>({...t,phone:e.target.value})),placeholder:`+65...`})]})]}),(0,L.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{children:`Email`}),(0,L.jsx)(G,{value:C.email,onChange:e=>w(t=>({...t,email:e.target.value})),placeholder:`[email protected]`})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{children:`Agency`}),(0,L.jsx)(G,{value:C.agency,onChange:e=>w(t=>({...t,agency:e.target.value})),placeholder:`Agency name`})]})]})]}),(0,L.jsx)(dj,{children:(0,L.jsx)(W,{onClick:ve,disabled:!C.name.trim()||T,children:T?`Creating...`:`Create Agent`})})]})]}),(0,L.jsxs)(aj,{open:D,onOpenChange:e=>{O(e),e||A({name:``,memberA:``,memberB:``})},children:[(0,L.jsx)(oj,{asChild:!0,children:(0,L.jsxs)(W,{size:`sm`,variant:`outline`,children:[(0,L.jsx)(Gw,{className:`h-4 w-4 mr-1.5`}),`New Pair`]})}),(0,L.jsxs)(lj,{className:`sm:max-w-md`,children:[(0,L.jsx)(uj,{children:(0,L.jsx)(fj,{children:`Create Pair`})}),(0,L.jsxs)(`div`,{className:`space-y-4`,children:[(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`A mentor/mentee pair is treated as one agent with its own capacity, backlog, and preferences. Both members are added to the lead's WhatsApp group on handoff.`}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{children:`Mentor`}),(0,L.jsxs)(wk,{value:k.memberA||void 0,onValueChange:e=>A(t=>({...t,memberA:e})),children:[(0,L.jsx)(Dk,{children:(0,L.jsx)(Ek,{placeholder:`Select agent`})}),(0,L.jsx)(Ok,{children:e.filter(e=>e.isActive&&!e.isGroup&&e.id!==k.memberB).map(e=>(0,L.jsx)(Ak,{value:e.id,children:e.name},e.id))})]})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{children:`Mentee`}),(0,L.jsxs)(wk,{value:k.memberB||void 0,onValueChange:e=>A(t=>({...t,memberB:e})),children:[(0,L.jsx)(Dk,{children:(0,L.jsx)(Ek,{placeholder:`Select agent`})}),(0,L.jsx)(Ok,{children:e.filter(e=>e.isActive&&!e.isGroup&&e.id!==k.memberA).map(e=>(0,L.jsx)(Ak,{value:e.id,children:e.name},e.id))})]})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{children:`N
150ame (optional)`}),(0,L.jsx)(G,{value:k.name,onChange:e=>A(t=>({...t,name:e.target.value})),placeholder:`Defaults to âMentor & Menteeâ`})]})]}),(0,L.jsx)(dj,{children:(0,L.jsx)(W,{onClick:Ne,disabled:!k.memberA||!k.memberB||j,children:j?`Creating...`:`Create Pair`})})]})]}),(0,L.jsxs)(W,{variant:`outline`,size:`sm`,onClick:xe,disabled:y,children:[(0,L.jsx)(iw,{className:`mr-1.5 h-4 w-4`}),y?`Exporting...`:`Export CSV`]}),(0,L.jsxs)(W,{variant:`outline`,size:`sm`,onClick:Te,disabled:n,children:[(0,L.jsx)(Yw,{className:`mr-2 h-4 w-4 ${n?`animate-spin`:``}`}),`Sync from Sheet`]})]})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-4 text-sm`,children:[(0,L.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer select-none`,children:[(0,L.jsx)(tM,{checked:ne,onCheckedChange:e=>re(e===!0)}),(0,L.jsx)(`span`,{children:`Hide archived`})]}),(0,L.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer select-none`,children:[(0,L.jsx)(tM,{checked:ie,onCheckedChange:e=>ae(e===!0)}),(0,L.jsx)(`span`,{children:`Can take leads only`})]}),(0,L.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer select-none`,children:[(0,L.jsx)(tM,{checked:oe,onCheckedChange:e=>se(e===!0)}),(0,L.jsx)(`span`,{children:`Unmapped SHL only`})]}),(0,L.jsxs)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:[ce.length,` of `,e.length,` agents`]})]}),(0,L.jsx)(`div`,{className:`rounded-md border`,children:(0,L.jsxs)(Pk,{children:[(0,L.jsx)(Fk,{children:(0,L.jsxs)(Lk,{children:[(0,L.jsx)(J,{className:`w-[30px]`}
150),(0,L.jsx)(J,{children:`Name`}),(0,L.jsx)(J,{children:`Agency`}),(0,L.jsx)(J,{children:`Can Take`}),(0,L.jsx)(J,{children:`Budget`}),(0,L.jsx)(J,{children:`Product Types`}),(0,L.jsx)(J,{children:`Languages`}),(0,L.jsx)(J,{children:`Leads`}),(0,L.jsx)(J,{children:`Today / Cap`}),(0,L.jsx)(J,{children:`Experience`}),(0,L.jsx)(J,{children:`SHL Group`}),(0,L.jsx)(J,{className:`w-[50px]`})]})}),(0,L.jsx)(Ik,{children:ce.length===0?(0,L.jsx)(Lk,{children:(0,L.jsx)(Y,{colSpan:12,className:`text-center text-muted-foreground py-8`,children:e.length===0?`No agents yet. Click "Sync from Sheet" to import.`:`No agents match the current filters.`})}):ce.map(t=>(0,L.jsxs)(_.Fragment,{children:[(0,L.jsxs)(Lk,{className:`group`,children:[(0,L.jsx)(Y,{children:(0,L.jsx)(W,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>Pe(t.id),children:o===t.id?(0,L.jsx)(HC,{className:`h-3 w-3`}):(0,L.jsx)(zC,{className:`h-3 w-3`})})}),(0,L.jsxs)(Y,{children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`span`,{className:`font-medium ${t.isActive?``:`text-muted-foreground line-through`}`,children:t.name}),t.isGroup&&(0,L.jsx)(X,{variant:`outline`,className:`text-[10px] uppercase tracking-wide border-blue-200 text-blue-700`,title:`Mentor/mentee pair â one logical agent`,children:`Pair`}),!t.isActive&&(0,L.jsx)(X,{variant:`destructive`,className:`text-[10px] uppercase tracking-wide`,children:`Archived`})]}),t.isGroup?(0,L.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-0.5 flex items-center gap-1.5`,children:[(0,L.jsx)(`span`,{children:(t.members??[]).map(e=>e.name??`â`).join(` + `)||`no members`}),De(t)&&(0,L.jsx)(X,{variant:`destructive`,className:`text-[10px]`,children:`member archived`})]}):t.inPairs.length>0?(0,L.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:[`in pair`,t.inPairs.length>1?`s`:``,`:`,` `,t.inPairs.map(e=>e.name).join(`, `)]}):null,(0,L.jsx)(wG,{agent:t})]}),(0,L.jsx)(Y,{className:`text-sm`,children:(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,L.jsx)(`span`,{children:t.agency??(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`â`})}),(0,L.jsxs)(X,{variant:t.hasIntro?`outline`:`secondary`,className:`text-[10px] ${t.hasIntro?`text-green-700 border-green-200`:`text-muted-foreground`}`,title:t.hasIntro?`Intro image/text configured`:`No intro configured`,children:[`Intro `,t.hasIntro?`â`:`missing`]})]})}),(0,L.jsx)(Y,{children:(0,L.jsx)(Ck,{checked:t.canTakeLeads,disabled:!t.isActive,onCheckedChange:()=>Ae(t),"aria-label":`Toggle whether ${t.name} can take leads`,title:t.isActive?t.canTakeLeads?`On â eligible for new leads. Click to stop.`:`Off â won't be assigned new leads. Click to allow.`:`Archived agents can't take leads`})}),(0,L.jsx)(Y,{className:`text-sm`,children:t.budgetRange??(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`â`})}),(0,L.jsx)(Y,{children:(t.propertyTypes??[]).length>0?(0,L.jsxs)(`div`,{className:`flex gap-1 flex-wrap max-w-[200px]`,children:[t.propertyTypes.slice(0,3).map(e=>(0,L.jsx)(X,{variant:`secondary`,className:`text-xs`,children:e},e)),t.propertyTypes.length>3&&(0,L.jsxs)(X,{variant:`outline`,className:`text-xs`,children:[`+`,t.propertyTypes.length-3]})]}):(0,L.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`â`})}),(0,L.jsx)(Y,{className:`text-sm`,children:(t.languages??[]).length>0?t.languages.join(`, `):`â`}),(0,L.jsx)(Y,{children:(0,L.jsx)(`span`,{className:`text-sm tabular-nums`,children:t.activeLeadCount})}),(0,L.jsx)(Y,{children:(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsxs)(X,{variant:t.atCap?`destructive`:`outline`,className:`text-xs tabular-nums`,title:`Assignments today / effective daily cap`,children:[t.leadsToday,` / `,t.capEffective,t.bumpActive?` â¬`:``]}),(0,L.jsx)(W,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,title:`Bump cap +1 for today (resets at 8am SGT)`,onClick:()=>je(t),children:`+1`})]})}),(0,L.jsx)(Y,{className:`text-sm`,children:t.yearsExperience?`${t.yearsExperience}y`:(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`â`})}),(0,L.jsx)(Y,{className:`text-sm`,children:t.shlGroupSource===`unmapped`?(0,L.jsx)(X,{variant:`destructive`,className:`text-[10px] uppercase tracking-wide`,title:`No SHL group resolved â briefs/alerts won't be delivered. Map one in Edit.`,children:`Unmapped`}):(0,L.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,L.jsx)(`span`,{className:`truncate max-w-[150px]`,children:t.shlGroupName??`â`}),(0,L.jsx)(X,{variant:t.shlGroupSource===`manual`?`default`:`secondary`,className:`text-[10px] w-fit`,title:t.shlGroupSource===`manual`?`Manually mapped`:`Auto-matched by group name`,children:t.shlGroupSource===`manual`?`Manual`:`Auto`})]})}),(0,L.jsxs)(Y,{children:[(0,L.jsxs)(aj,{children:[(0,L.jsx)(oj,{asChild:!0,children:(0,L.jsx)(W,{variant:`ghost`,size:`icon`,onClick:()=>Ee(t),children:(0,L.jsx)(Bw,{className:`h-4 w-4`})})}),i?.id===t.id&&(0,L.jsxs)(lj,{className:`sm:max-w-2xl max-h-[85vh] overflow-y-auto`,children:[(0,L.jsx)(uj,{children:(0,L.jsxs)(fj,{children:[`Edit `,t.name]})}),(0,L.jsxs)(KL,{defaultValue:`profile`,className:`py-2`,children:[(0,L.jsxs)(qL,{
150className:`grid grid-cols-2 w-full`,children:[(0,L.jsx)(JL,{value:`profile`,children:`Profile`}),(0,L.jsxs)(JL,{value:`intro`,children:[`Intro`,i?.hasIntro&&(0,L.jsx)(`span`,{className:`ml-1.5 text-green-600`,"aria-label":`Intro configured`,children:`â`})]})]}),(0,L.jsx)(YL,{value:`profile`,className:`mt-4`,children:(0,L.jsxs)(`div`,{className:`grid gap-4`,children:[i?.isGroup&&(0,L.jsxs)(`div`,{className:`grid gap-2 rounded-md border border-blue-200 bg-blue-50/40 p-3`,children:[(0,L.jsx)(Z,{className:`text-blue-800`,children:`Pair members (mentor + mentee)`}),(0,L.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,L.jsxs)(wk,{value:ee.a||void 0,onValueChange:e=>N(t=>({...t,a:e})),children:[(0,L.jsx)(Dk,{children:(0,L.jsx)(Ek,{placeholder:`Mentor`})}),(0,L.jsx)(Ok,{children:e.filter(e=>e.isActive&&!e.isGroup&&e.id!==ee.b).map(e=>(0,L.jsx)(Ak,{value:e.id,children:e.name},e.id))})]}),(0,L.jsxs)(wk,{value:ee.b||void 0,onValueChange:e=>N(t=>({...t,b:e})),children:[(0,L.jsx)(Dk,{children:(0,L.jsx)(Ek,{placeholder:`Mentee`})}),(0,L.jsx)(Ok,{children:e.filter(e=>e.isActive&&!e.isGroup&&e.id!==ee.a).map(e=>(0,L.jsx)(Ak,{value:e.id,children:e.name},e.id))})]})]}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Members stay independent agents. The pair has its own capacity, backlog, and preferences below.`})]}),i?.isGroup?(0,L.jsxs)(`div`,{className:`grid gap-2`,children:[(0,L.jsx)(Z,{children:`Member phones`}),(0,L.jsx)(`div`,{className:`text-sm font-mono text-muted-foreground`,children:_G(i)??`â`}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Read-only. A pair's WhatsApp numbers come from its members â edit them on each agent's own row.`})]}):(0,L.jsxs)(`div`,{className:`grid gap-2`,children:[(0,L.jsx)(Z,{children:`Phone`}),(0,L.jsx)(G,{value:f.phone,onChange:e=>p(t=>({...t,phone:e.target.value})),placeholder:`+6591234567`})]}),(0,L.jsxs)(`div`,{className:`grid gap-2`,children:[(0,L.jsx)(Z,{children:`Specialties (comma-separated)`}),(0,L.jsx)(G,{value:f.specialties,onChange:e=>p(t=>({...t,specialties:e.target.value})),placeholder:`HDB, condo, landed`})]}),(0,L.jsxs)(`div`,{className:`grid gap-2`,children:[(0,L.jsx)(Z,{children:`Languages (comma-separated)`}),(0,L.jsx)(G,{value:f.languages,onChange:e=>p(t=>({...t,languages:e.target.value})),placeholder:`English, Mandarin`})]}),(0,L.jsxs)(`div`,{className:`grid gap-2`,children:[(0,L.jsx)(Z,{children:`Property Types (comma-separated)`}),(0,L.jsx)(G,{value:f.propertyTypes,onChange:e=>p(t=>({...t,propertyTypes:e.target.value})),placeholder:`Resale HDB, New launch condo, Resale condo`})]}),(0,L.jsxs)(`div`,{className:`grid gap-2`,children:[(0,L.jsx)(Z,{children:`Districts (comma-separated)`}),(0,L.jsx)(G,{value:f.districts,onChange:e=>p(t=>({...t,districts:e.target.value})),placeholder:`D10, D15, D21`})]}),(0,L.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,L.jsxs)(`div`,{className:`grid gap-2`,children:[(0,L.jsx)(Z,{children:`Budget Min (SGD k)`}),(0,L.jsx)(G,{type:`number`,value:f.budgetMin,onChange:e=>p(t=>({...t,budgetMin:e.target.value}))})]}),(0,L.jsxs)(`div`,{className:`grid gap-2`,children:[(0,L.jsx)(Z,{children:`Budget Max (SGD k)`}),(0,L.jsx)(G,{type:`number`,value:f.budgetMax,onChange:e=>p(t=>({...t,budgetMax:e.target.value}))})]})]}),(0,L.jsxs)(`div`,{className:`grid gap-2`,children:[(0,L.jsx)(Z,{children:`Daily lead cap`}),(0,L.jsx)(G,{type:`number`,min:0,max:50,value:f.dailyCap,onChange:e=>p(t=>({...t,dailyCap:e.target.value})),placeholder:`1`}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Max leads assigned per day (resets 8am SGT). Default 1.`})]}),(0,L.jsxs)(`div`,{className:`grid gap-2`,children:[(0,L.jsx)(Z,{children:`SHL group (delivery target)`}),(0,L.jsxs)(wk,{value:f.shlGroupConversationId||CG,onValueChange:e=>p(t=>({...t,shlGroupConversationId:e===CG?``:e})),children:[(0,L.jsx)(Dk,{children:(0,L.jsx)(Ek,{placeholder:`Auto (match by group name)`})}),(0,L.jsxs)(Ok,{children:[(0,L.jsx)(Ak,{value:CG,children:`Auto (match by group name)`}),P.map(e=>(0,L.jsx)(Ak,{value:e.conversationId,children:e.contactName??e.conversationId},e.conversationId))]})]}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Where this agent's weekly brief + silence alerts post. Auto matches the "SHL w/ [name]" group; choose one to override a wrong/missing match.`}),(0,L.jsx)(`button`,{type:`button`,onClick:we,disabled:I,className:`self-start text-xs text-muted-foreground underline underline-offset-2 hover:text-foreground disabled:opacity-50`,children:I?`Scanning WhatsApp...`:`Group missing? Scan WhatsApp`})]}),(0,L.jsxs)(`div`,{className:`grid gap-2`,children:[(0,L.jsx)(Z,{children:`Internal Notes`}),(0,L.jsx)(TD,{value:f.notes,onChange:e=>p(t=>({...t,notes:e.target.value})),placeholder:`Internal notes about this agent...`,className:`min-h-[60
150px]`})]})]})}),(0,L.jsx)(YL,{value:`intro`,className:`mt-4`,children:(0,L.jsxs)(`div`,{className:`grid gap-5`,children:[(0,L.jsxs)(`div`,{className:`grid gap-2`,children:[(0,L.jsx)(Z,{children:`Intro image`}),i?.introImageStorageKey?(0,L.jsxs)(`div`,{className:`flex items-center gap-3 rounded-md border p-3`,children:[(0,L.jsx)(`div`,{className:`flex h-12 w-12 items-center justify-center rounded bg-muted text-muted-foreground`,children:(0,L.jsx)(CT,{className:`h-5 w-5`})}),(0,L.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,L.jsx)(`div`,{className:`text-sm font-medium truncate`,children:i.introImageFilename??`intro`}),(0,L.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[TG(i.introImageSizeBytes),i.introImageMime&&` · ${i.introImageMime}`]})]}),(0,L.jsx)(Z,{htmlFor:`intro-replace-${t.id}`,className:`cursor-pointer`,children:(0,L.jsx)(W,{variant:`outline`,size:`sm`,type:`button`,disabled:m,asChild:!0,children:(0,L.jsx)(`span`,{children:m?`Uploading...`:`Replace`})})}),(0,L.jsx)(`input`,{id:`intro-replace-${t.id}`,type:`file`,accept:bG,className:`hidden`,onChange:e=>{let n=e.target.files?.[0];n&&(Oe(t.id,n),e.target.value=``)}}),(0,L.jsx)(W,{variant:`ghost`,size:`icon`,type:`button`,disabled:g,onClick:()=>
150ke(t.id),title:`Remove intro image`,children:(0,L.jsx)(FT,{className:`h-4 w-4`})})]}):(0,L.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`intro-upload-${t.id}`,className:`cursor-pointer`,children:(0,L.jsxs)(`div`,{className:`flex items-center justify-center gap-2 rounded-md border border-dashed py-6 text-sm text-muted-foreground hover:bg-muted/50 transition-colors`,children:[(0,L.jsx)(CT,{className:`h-4 w-4`}),m?`Uploading...`:`Upload intro image`]})}),(0,L.jsx)(`input`,{id:`intro-upload-${t.id}`,type:`file`,accept:bG,className:`hidden`,onChange:e=>{let n=e.target.files?.[0];n&&(Oe(t.id,n),e.target.value=``)}}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`JPG, PNG, or WebP â max 10 MB. Convert HEIC to JPEG first.`})]})]}),(0,L.jsxs)(`div`,{className:`grid gap-2`,children:[(0,L.jsx)(Z,{children:`Intro text`}),(0,L.jsx)(TD,{value:f.introText,onChange:e=>p(t=>({...t,introText:e.target.value})),placeholder:`Hi everyone, I'm Alice â I specialise in resale HDBs across D10-D15. Looking forward to working with you!`,className:`min-h-[100px]`}),(0,L.jsxs)(`p`,{className:`text-xs ${f.introText.length>SG?`text-orange-600`:`text-muted-foreground`}`,children:[f.introText.length,` / `,SG,` (caption limit)`,f.introText.length>SG&&` â text past this limit will be sent as a separate message rather than a caption`]})]}),(0,L.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Sent in the WA group `,(0,L.jsx)(`strong`,{children:`before`}),` the AI handover. Image takes precedence; text becomes the caption.`]})]})}),(0,L.jsx)(`div`,{className:`mt-4`,children:(0,L.jsx)(W,{onClick:Me,disabled:!!i?.isGroup&&(!ee.a||!ee.b),children:`Save`})})]})]})]}),!t.isActive&&(0,L.jsx)(W,{variant:`ghost`,size:`icon`,title:`Reactivate agent`,onClick:()=>be(t),children:(0,L.jsx)(bC,{className:`h-4 w-4 text-muted-foreground`})}),(0,L.jsxs)(lA,{children:[(0,L.jsx)(uA,{asChild:!0,children:(0,L.jsx)(W,{variant:`ghost`,size:`icon`,title:t.activeLeadCount>0?`Archive agent`:`Delete agent`,children:(0,L.jsx)(vT,{className:`h-4 w-4 text-muted-foreground`})})}),(0,L.jsxs)(pA,{children:[(0,L.jsxs)(mA,{children:[(0,L.jsxs)(gA,{children:[t.activeLeadCount>0?`Archive`:`Delete`,` agent?`]}),(0,L.jsx)(_A,{children:t.activeLeadCount>0?`"${t.name}" has ${t.activeLeadCount} active leads and will be archived (marked inactive) instead of deleted.`:`This will permanently delete "${t.name}". This action cannot be undone.`})]}),(0,L.jsxs)(hA,{children:[(0,L.jsx)(yA,{children:`Cancel`}),(0,L.jsx)(vA,{onClick:()=>ye(t),className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:t.activeLeadCount>0?`Archive`:`Delete`})]})]})]})]})]}),o===t.id&&(0,L.jsx)(Lk,{children:(0,L.jsx)(Y,{colSpan:11,className:`bg-muted/50 px-8 py-4`,children:(0,L.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-3 gap-4 text-sm`,children:[(0,L.jsx)(hG,{agentId:t.id,agentActiveCount:t.activeLeadCount,onOpenLead:ge}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`div`,{className:`font-medium text-muted-foreground text-xs uppercase mb-1`,children:`Contact`}),(0,L.jsx)(`div`,{children:_G(t)??`â`}),t.email&&(0,L.jsx)(`div`,{className:`text-muted-foreground`,children:t.email})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`div`,{className:`font-medium text-muted-foreground text-xs uppercase mb-1`,children:`Personality`}),(0,L.jsx)(`div`,{children:t.personalityType??`â`})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`div`,{className:`font-medium text-muted-foreground text-xs uppercase mb-1`,children:`Communication`}),(0,L.jsx)(`div`,{children:t.communicationPreference??`â`})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`div`,{className:`font-medium text-muted-foreground text-xs uppercase mb-1`,children:`Employment`}),(0,L.jsx)(`div`,{children:t.isFullTime===!0?`Full time`:t.isFullTime===!1?`Part time`:`â`})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`div`,{className:`font-medium text-muted-foreground text-xs uppercase mb-1`,children:`Districts`}),(0,L.jsx)(`div`,{className:`flex gap-1 flex-wrap`,children:(t.districts??[]).length>0?t.districts.map(e=>{let t=e.match(/^(D\d+)/);return(0,L.jsx)(X,{variant:`outline`,className:`text-xs`,children:t?t[1]:e},e)}):`â`})]}),t.leadRestrictions&&(0,L.jsxs)(`div`,{className:`col-span-full`,children:[(0,L.jsx)(`div`,{className:`font-medium text-muted-foreground text-xs uppercase mb-1`,children:`Lead Restrictions`}
150),(0,L.jsx)(`div`,{className:`text-orange-600 dark:text-orange-400`,children:t.leadRestrictions})]}),t.notes&&(0,L.jsxs)(`div`,{className:`col-span-full`,children:[(0,L.jsx)(`div`,{className:`font-medium text-muted-foreground text-xs uppercase mb-1`,children:`Internal Notes`}),(0,L.jsx)(`div`,{className:`whitespace-pre-wrap`,children:t.notes})]}),(0,L.jsxs)(`div`,{className:`col-span-full`,children:[(0,L.jsx)(`div`,{className:`font-medium text-muted-foreground text-xs uppercase mb-2`,children:`Articles`}),c[t.id]?c[t.id].length===0?(0,L.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:`No articles found`}):(0,L.jsx)(`div`,{className:`space-y-1.5`,children:c[t.id].map(e=>(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.url?(0,L.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-sm text-blue-600 dark:text-blue-400 hover:underline flex items-center gap-1`,children:[e.title,(0,L.jsx)(ow,{className:`h-3 w-3 flex-shrink-0`})]}):(0,L.jsx)(`span`,{className:`text-sm`,children:e.title}),e.category&&(0,L.jsx)(X,{variant:`outline`,className:`text-xs`,children:e.category})]},e.id))}):(0,L.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:`Loading...`})]}),(0,L.jsxs)(`div`,{className:`col-span-full`,children:[(0,L.jsxs)(`div`,{className:`font-medium text-muted-foreground text-xs uppercase mb-2 flex items-center gap-1.5`,children:[(0,L.jsx)(vw,{className:`h-3 w-3`}),`Change History`]}),u[t.id]?u[t.id].length===0?(0,L.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:`No changes recorded yet`}):(0,L.jsx)(`div`,{className:`space-y-3 max-h-64 overflow-y-auto`,children:u[t.id].map(e=>(0,L.jsxs)(`div`,{className:`border rounded-md p-3 text-xs`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(X,{variant:e.changeType===`manual_edit`?`default`:`secondary`,className:`text-[10px]`,children:e.changeType===`manual_edit`?`Manual Edit`:`Sheet Sync`}),(0,L.jsxs)(`span`,{className:`text-muted-foreground`,children:[`by `,e.changedByName??e.changedBy]})]}),(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:new Date(e.createdAt).toLocaleString()})]}),(0,L.jsx)(`div`,{className:`space-y-1`,children:Object.entries(e.changes).map(([e,t])=>(0,L.jsxs)(`div`,{className:`flex gap-2`,children:[(0,L.jsxs)(`span`,{className:`font-medium min-w-[100px]`,children:[e,`:`]}),(0,L.jsx)(`span`,{className:`text-red-500 line-through`,children:EG(t.old)}),(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`->`}),(0,L.jsx)(`span`,{className:`text-green-600`,children:EG(t.new)})]},e))})]},e.id))}):(0,L.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:`Loading...`})]})]})})},`${t.id}-details`)]},t.id))})]})}),(0,L.jsx)(ij,{leadId:de,open:pe,onClose:_e})]})}var OG=24,kG=60,AG=48,jG=96;function MG(e){let t=e?.silenceHours??OG,n=e?.windowDays??kG;return{triggers:[`We sent this lead a message but they have never replied`,`Our last message was more than ${t} hours ago`,`Only leads contacted in the last ${n} days are shown - older ones age out of this list`],resolve:[`Open the chat with View and send a fresh follow-up - any new message restarts the ${t}-hour clock`,`Not worth chasing? Set the lead to Lost or Not Interested on the Leads page - it leaves this list immediately`,`Leads with no contact for ${n} days drop off this list automatically`]}}function NG(){return{triggers:[`The agent had active leads in the latest weekly digest`,`The agent is active and currently able to take leads`,`No SHL WhatsApp group is mapped to them, and none could be matched from a group name like "SHL w/ <agent>"`],resolve:[`Open the Agents tab, edit the agent and pick their SHL group - the alert clears within about 5 minutes`,`Or rename their WhatsApp group to "SHL w/ <agent name>" so it links automatically`,`If the agent works in a pair, reassign their leads to the pair row instead - solo rows of pair members never get their own group`]}}function PG(e){let t=e?.nudgeAfterHours??AG,n=e?.autoLostAfterHours??jG;return{triggers:[`The AI was qualifying this lead when they stopped replying`,`After ${t} hours of silence the AI sent a nudge - still no reply`,`This is informational: at ${n} hours of silence the lead is automatically marked Lost and leaves this list`],resolve:[`Open the chat with View and send a personal message - a human touch often revives a quiet lead`,`If the lead replies, this alert clears on its own`,`Or set the lead's status yourself on the Leads page (e.g. Lost)`,`If nothing happens, the system marks the lead Lost automatically at ${n} hours`]}}function FG(){return{triggers:[`Shows active pipeline leads only: new, contacted, awaiting consent, interested, qualified, backlogged`,`Ranked hot, then warm, then cold - and within each band, whoever has waited longest since our last message`],resolve:[]}}function IG(e){return e===`baileys`?{triggers:[`Agent-handoff group line (new number) - carries SHL group messages and weekly briefs`],resolve:[`If not connected: open the C
150onnect tab and re-link the number by scanning the QR code`]}:{triggers:[`1:1 lead line (old number) - carries lead outreach and replies via the WhatsApp Cloud API`],resolve:[`If it needs reconnecting or re-authorization: open the Connect tab and follow the Cloud API steps`]}}function LG(e,t,n){return{from:e===0?0:Math.min(t+1,e),to:e===0?0:Math.min(t+n,e),canPrev:t>0,canNext:t+n<e}}var RG={hot:`destructive`,warm:`default`,cold:`secondary`},zG=10,BG=100,VG=5e3;function HG(e){if(e<1)return`just now`;if(e<60)return`${e} minutes ago`;let t=Math.floor(e/60),n=e%60;return t<24?`${t}h ${n}m ago`:`${Math.floor(t/24)}d ${t%24}h ago`}function UG(){let e=et(),{data:t}=vi({queryKey:[`monitoring`,`insights`],queryFn:()=>H(`/api/monitoring/insights`).then(e=>e.data),refetchInterval:3e4}),[n,r]=(0,_.useState)(0),{data:i}=vi({queryKey:[`monitoring`,`priority-queue`,n],queryFn:()=>H(`/api/monitoring/priority-queue?limit=${zG}&offset=${n}`),refetchInterval:3e4,placeholderData:pr}),a=i?.data??[],o=i?.total??0;(0,_.useEffect)(()=>{o>0&&n>=o&&r(0)},[o,n]);let s=vi({queryKey:[`monitoring`,`unresponsive`],queryFn:()=>H(`/api/monitoring/unresponsive`),refetchInterval:3e4}),c=s.data?.data??[],l=s.data?.meta,u=vi({queryKey:[`monitoring`,`stuck`],queryFn:()=>H(`/api/monitoring/stuck`),refetchInterval:3e4}),d=u.data?.data??[],f=u.data?.meta,p=vi({queryKey:[`monitoring`,`no-shl-group-alert`],queryFn:()=>H(`/api/pa/weekly-digests-no-shl-group-alert`).then(e=>e.data),refetchInterval:3e4}),m=p.data,h=m?.agents??[],{data:g}=vi({queryKey:[`whatsapp-status`,`transport`],queryFn:()=>H(`/api/whatsapp/status`).then(e=>e.data),refetchInterval:3e4,retry:!1}),[v,y]=(0,_.useState)(!1),b=async()=>{y(!0);try{let e=new Map,t=0,n=1/0;for(;t<n&&t<VG;){let r=await H(`/api/monitoring/priority-queue?limit=${BG}&offset=${t}`);for(let t of r.data)e.set(t.id,t);if(n=r.total,r.data.length===0)break;t+=BG}Wk([`Section`,`Name`,`Phone`,`Warmth`,`Status`,`Agent`,`Detail`],[...[...e.values()].map(e=>[`Priority Queue`,e.name,e.phone,e.warmth,e.status,e.assignedAgentName??``,e.hoursWaiting==null?``:`${Math.round(e.hoursWaiting)}h waiting`]),...c.map(e=>[`Unresponsive`,e.name,``,e.warmth,e.status,e.assignedAgentName??``,`${Math.round(e.minutesSinceContact/60)}h since contact, ${e.followUpCount} follow-ups`]),...d.map(e=>[`Stuck`,e.name,``,e.warmth,``,``,`${e.qualificationNudgeCount} nudges`])],`monitoring-report-${new Date().toISOString().split(`T`)[0]}.csv`)}catch{z.error(`Export failed - please try again.`)}finally{y(!1)}},x=s.isSuccess&&u.isSuccess&&p.isSuccess,S=s.isError||u.isError||p.isError,C=h.length===0&&c.length===0&&d.length===0,w=l?.silenceHours??24,T=l?.windowDays??60,E=f?.nudgeAfterHours??48,{from:D,to:O,canPrev:k,canNext:A}=LG(o,n,zG);return(0,L.jsxs)(`div`,{className:`space-y-6`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,L.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Dashboard`}),(0,L.jsx)(sA,{interval:`30s`,source:`Server`})]}),(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Operational overview â lead pipeline, unresponsive leads, AI status`})]}),(0,L.jsxs)(W,{variant:`outline`,size:`sm`,onClick:()=>void b(),disabled:v,children:[(0,L.jsx)(iw,{className:`h-4 w-4 mr-1.5`}),v?`Exportingâ¦`:`Export Report`]})]}),(0,L.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-3 xl:grid-cols-6`,children:[(0,L.jsx)(WG,{title:`Leads Today`,value:t?.today.leadsCreated??0,subtitle:`${t?.totals.leads??0} total`,icon:(0,L.jsx)(MT,{className:`h-4 w-4`}),onClick:()=>e(`/leads?createdToday=true`)}),(0,L.jsx)(WG,{title:`Contacted Today`,value:t?.today.contacted??0,subtitle:`${t?.totals.contacted??0} total`,icon:(0,L.jsx)(bT,{className:`h-4 w-4`}),onClick:()=>e(`/leads?status=contacted&contactedToday=true`)}),(0,L.jsx)(WG,{title:`Qualified Today`,value:t?.today.qualified??0,subtitle:`${t?.totals.qualified??0} total`,icon:(0,L.jsx)(bT,{className:`h-4 w-4`}),onClick:()=>e(`/leads?status=qualified&qualifiedToday=true`)}),(0,L.jsx)(WG,{title:`Conversion Rate`,value:`${t?.totals.conversionRate??0}%`,subtitle:`qualified / contacted`,icon:(0,L.jsx)(bT,{className:`h-4 w-4`}),onClick:()=>e(`/leads?status=qualified`)}),(0,L.jsx)(KG,{title:`WhatsApp Groups (Baileys)`,badgeVariant:g?.baileys.status===`connected`?`default`:g?.baileys.status===`qr_needed`?`secondary`:`destructive`,badgeLabel:(g?.baileys.status??`unknown`).replace(/_/g,` `),subtitle:`Agent-handoff group line (new number).`,help:IG(`baileys`),onClick:()=>e(`/connect`)}),(0,L.jsx)(KG,{title:`WhatsApp 1:1 Leads (Cloud API)`,badgeVariant:g?.cloudApi.state===`connected`?`default`:g?.cloudApi.state===`
150not_configured`?`secondary`:`destructive`,badgeLabel:(g?.cloudApi.state??`unknown`).replace(/_/g,` `),subtitle:g?.cloudApi.reauthorizationRequired?`Token needs re-authorization.`:g?.cloudApi.cloudNumber?`Old number ${g.cloudApi.cloudNumber}.`:`1:1 lead line (old number).`,help:IG(`cloud`),onClick:()=>e(`/connect`)})]}),(0,L.jsx)(`p`,{className:`-mt-2 text-xs text-muted-foreground`,children:`"Today" counts from 8am SGT (the agent daily-cap reset), not midnight.`}),C?x?(0,L.jsx)(K,{children:(0,L.jsxs)(q,{className:`flex items-center gap-3 py-4`,children:[(0,L.jsx)(KC,{className:`h-5 w-5 text-emerald-500 shrink-0`}),(0,L.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,L.jsx)(`p`,{className:`text-sm font-medium`,children:`No active alerts`}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Unresponsive leads, unrouted weekly briefs and stuck AI qualifications will appear here.`})]}),(0,L.jsx)(JG,{unresponsiveMeta:l,stuckMeta:f})]})}):S?(0,L.jsx)(K,{children:(0,L.jsxs)(q,{className:`flex items-center gap-3 py-4`,children:[(0,L.jsx)(xT,{className:`h-5 w-5 text-muted-foreground shrink-0`}),(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Alert data is unavailable right now - it will retry automatically.`})]})}):null:(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[h.length>0&&(0,L.jsxs)(K,{className:`border-orange-200 dark:border-orange-900`,children:[(0,L.jsxs)(MD,{className:`pb-2`,children:[(0,L.jsxs)(ND,{className:`text-base flex items-center gap-2`,children:[(0,L.jsx)(xT,{className:`h-4 w-4 text-orange-500`}),`Briefs not reaching an SHL group`,(0,L.jsx)(qG,{ariaLabel:`What triggers this alert?`,help:NG()}),(0,L.jsx)(X,{variant:`secondary`,children:m?.totalLeads??0})]}),(0,L.jsxs)(PD,{children:[m?.totalLeads??0,` active lead`,(m?.totalLeads??0)===1?``:`s`,` across`,` `,h.length,` agent`,h.length===1?``:`s`,` taking leads - no SHL group mapped`]})]}),(0,L.jsx)(q,{children:(0,L.jsxs)(`div`,{className:`space-y-2`,children:[h.slice(0,5).map(t=>(0,L.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,L.jsx)(`span`,{className:`font-medium`,children:t.agentName??`Unknown agent`}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsxs)(`span`,{className:`text-muted-foreground`,children:[t.leadCount,` lead`,t.leadCount===1?``:`s`]}),(0,L.jsx)(W,{variant:`ghost`,size:`sm`,className:`h-6 px-2 text-xs`,onClick:()=>e(`/agents`),children:`Map group`})]})]},t.agentId)),(0,L.jsx)(W,{variant:`link`,size:`sm`,className:`px-0 text-xs`,onClick:()=>e(`/agent-pa/weekly-digests`),children:`View all in Weekly Digests â`})]})})]}),c.length>0&&(0,L.jsxs)(K,{className:`border-orange-200 dark:border-orange-900`,children:[(0,L.jsxs)(MD,{className:`pb-2`,children:[(0,L.jsxs)(ND,{className:`text-base flex items-center gap-2`,children:[(0,L.jsx)(QC,{className:`h-4 w-4 text-orange-500`}),`Unresponsive Leads`,(0,L.jsx)(qG,{ariaLabel:`What triggers this alert?`,help:MG(l)}),(0,L.jsx)(X,{variant:`secondary`,children:c.length})]}),(0,L.jsxs)(PD,{children:[`No reply for `,w,`+ hours - contacted in the last`,` `,T,` days`]})]}),(0,L.jsx)(q,{children:(0,L.jsxs)(`div`,{className:`space-y-2`,children:[c.slice(0,5).map(t=>(0,L.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`span`,{className:`font-medium`,children:t.name}),(0,L.jsx)(X,{variant:RG[t.warmth]??`secondary`,className:`ml-2 text-xs`,children:t.warmth})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsxs)(`span`,{className:`text-muted-foreground`,children:[HG(t.minutesSinceContact),t.followUpCount>0&&` (${t.followUpCount} follow-ups)`]}),(0,L.jsx)(W,{variant:`ghost`,size:`sm`,className:`h-6 px-2 text-xs`,onClick:()=>e(`/messages?lead=${t.id}`),children:`View`})]})]},t.id)),c.length>5&&(0,L.jsxs)(W,{variant:`link`,size:`sm`,className:`px-0 text-xs`,onClick:()=>e(`/leads?status=contacted`),children:[`View all `,c.length,` unresponsive leads â`]})]})})]}),d.length>0&&(0,L.jsxs)(K,{className:`border-red-200 dark:border-red-900`,children:[(0,L.jsxs)(MD,{className:`pb-2`,children:[(0,L.jsxs)(ND,{className:`text-base flex items-center gap-2`,children:[(0,L.jsx)(xT,{className:`h-4 w-4 text-red-500`}),`AI Stuck`,(0,L.jsx)(qG,{ariaLabel:`What triggers this alert?`,help:PG(f)}),(0,L.jsx)(X,{variant:`destructive`,children:d.length})]}),(0,L.jsxs)(PD,{children:[`Went quiet mid-qualification - nudged after `,E,`h of silence`]})]}),(0,L.jsx)(q,{children:(0,L.jsx)(`div`,{className:`space-y-2`,children:d.map(t=>(0,L.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,L.jsx)(`span`,{className:`font-medium`,children:t.name}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsxs)(`span`,{className:`text-muted-foreground`,children:[t.qualificationNudgeCount,` nudge(s) sent`]}),(0,L.jsx)(W,{variant:`ghost`,size:`sm`,className:`h-6 px-2 text-xs`,onClick:()=>e(`/messages?lead=${t.id}`),children:`View`})]})]},t.id))})})]})]}),S&&(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Some alert data is unavailable right now - it will retry automatically.`})]}),(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{className:`pb-3`,children:[(0,L.jsxs)(ND,{className:`text-base flex items-center gap-2`,children:[`Priority Queue`,(0,L.jsx)(qG,{ariaLabel:`What does Priority Queue show?`,help:FG()})]}),(0,L.jsx)(PD,{children:`Leads ranked by urgency â hot first, then by wait time`})]}),(0,L.jsxs)(q,{children:[(0,L.jsx)(`div`,{className:`rounded-md border`,children:(0,L.jsxs)(Pk,{children:[(0,L.jsx)(Fk,{children:(0,L.jsxs)(Lk,{children:[(0,L.jsx)(J,{children:`N
150ame`}),(0,L.jsx)(J,{children:`Warmth`}),(0,L.jsx)(J,{children:`Status`}),(0,L.jsx)(J,{children:`Wait Time`}),(0,L.jsx)(J,{children:`Agent`}),(0,L.jsx)(J,{})]})}),(0,L.jsx)(Ik,{children:a.length===0?(0,L.jsx)(Lk,{children:(0,L.jsx)(Y,{colSpan:6,className:`text-center text-muted-foreground py-8`,children:`No active leads in the pipeline`})}):a.map(t=>(0,L.jsxs)(Lk,{children:[(0,L.jsx)(Y,{className:`font-medium`,children:t.name}),(0,L.jsx)(Y,{children:(0,L.jsx)(X,{variant:RG[t.warmth]??`secondary`,children:t.warmth})}),(0,L.jsxs)(Y,{children:[(0,L.jsx)(X,{variant:`outline`,children:t.status}),t.qualificationMode===`qualifying`&&(0,L.jsx)(X,{variant:`secondary`,className:`ml-1 text-xs`,children:`qualifying`})]}),(0,L.jsx)(Y,{className:`text-muted-foreground`,children:t.hoursWaiting===null?`â`:t.hoursWaiting>=24?`${Math.floor(t.hoursWaiting/24)}d ${t.hoursWaiting%24}h`:`${t.hoursWaiting}h`}),(0,L.jsx)(Y,{className:`text-sm`,children:t.assignedAgentName??(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`â`})}),(0,L.jsx)(Y,{children:(0,L.jsx)(W,{variant:`ghost`,size:`sm`,onClick:()=>e(`/messages?lead=${t.id}`),children:`View`})})]},t.id))})]})}),(0,L.jsxs)(`div`,{className:`flex items-center justify-between pt-3 text-sm text-muted-foreground`,children:[(0,L.jsxs)(`span`,{children:[`Showing `,D,`-`,O,` of `,o]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(W,{variant:`outline`,size:`sm`,disabled:!k,onClick:()=>r(e=>Math.max(0,e-zG)),children:`Prev`}),(0,L.jsx)(W,{variant:`outline`,size:`sm`,disabled:!A,onClick:()=>r(e=>e+zG),children:`Next`})]})]})]})]})]})}function WG({title:e,value:t,subtitle:n,icon:r,onClick:i}){return(0,L.jsxs)(K,{className:i?`cursor-pointer transition-colors hover:bg-muted/50`:void 0,onClick:i,...i?GG(i):{},children:[(0,L.jsxs)(MD,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,L.jsx)(PD,{children:e}),r]}),(0,L.jsxs)(q,{children:[(0,L.jsx)(`div`,{className:`text-2xl font-bold`,children:t}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n})]})]})}function GG(e){return{role:`button`,tabIndex:0,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),e())}}}function KG({title:e,badgeVariant:t,badgeLabel:n,subtitle:r,help:i,onClick:a}){return(0,L.jsxs)(K,{className:`cursor-pointer transition-colors hover:bg-muted/50`,onClick:a,...GG(a),children:[(0,L.jsxs)(MD,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,L.jsx)(PD,{children:e}),(0,L.jsx)(qG,{ariaLabel:`About ${e}`,help:i})]}),(0,L.jsxs)(q,{children:[(0,L.jsx)(X,{variant:t,children:n}),(0,L.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground truncate`,children:r})]})]})}function qG({ariaLabel:e,help:t}){return(0,L.jsxs)(OA,{children:[(0,L.jsx)(kA,{asChild:!0,children:(0,L.jsx)(W,{variant:`ghost`,size:`icon-xs`,className:`text-muted-foreground shrink-0`,"aria-label":e,onClick:e=>e.stopPropagation(),children:(0,L.jsx)(xw,{className:`size-4`})})}),(0,L.jsxs)(AA,{align:`start`,className:`w-80 space-y-3`,onClick:e=>e.stopPropagation(),children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`p`,{className:`text-xs font-semibold text-muted-foreground`,children:`Triggers when`}),(0,L.jsx)(`ul`,{className:`mt-1 list-disc space-y-1 pl-4 text-sm`,children:t.triggers.map(e=>(0,L.jsx)(`li`,{children:e},e))})]}),t.resolve.length>0&&(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`p`,{className:`text-xs font-semibold text-muted-foreground`,children:`How to resolve`}),(0,L.jsx)(`ol`,{className:`mt-1 list-decimal space-y-1 pl-4 text-sm`,children:t.resolve.map(e=>(0,L.jsx)(`li`,{children:e},e))})]})]})]})}function JG({unresponsiveMeta:e,stuckMeta:t}){let n=[{title:`Unresponsive Leads`,help:MG(e)},{title:`Briefs not reaching an SHL group`,help:NG()},{title:`AI Stuck`,help:PG(t)}];return(0,L.jsxs)(OA,{children:[(0,L.jsx)(kA,{asChild:!0,children:(0,L.jsx)(W,{variant:`ghost`,size:`icon-xs`,className:`text-muted-foreground shrink-0`,"aria-label":`What alerts can appear here?`,children:(0,L.jsx)(xw,{className:`size-4`})})}),(0,L.jsx)(AA,{align:`end`,className:`w-80 space-y-3`,children:n.map(e=>(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`p`,{className:`text-xs font-semibold text-muted-foreground`,children:e.title}),(0,L.jsx)(`ul`,{className:`mt-1 list-disc space-y-1 pl-4 text-sm`,children:e.help.triggers.map(e=>(0,L.jsx)(`li`,{children:e},e))})]},e.title))})]})}var YG=`1`,XG=`2026-05`,ZG=e=>
150e.toLocaleString();function QG(e){let[t,n]=e.split(`-`);return new Date(Number(t),Number(n)-1,1).toLocaleDateString(`en-SG`,{month:`short`,year:`numeric`})}function $G(){let{data:e,isLoading:t}=vi({queryKey:[`analytics`,`usage`],queryFn:()=>H(`/api/analytics/usage`).then(e=>e.data)}),n=()=>{if(!e)return;let t=[],n=(e,n,r)=>t.push([e,n,String(r)]);n(`Overview`,`Leads processed`,e.kpis.leadsProcessed),n(`Overview`,`Messages handled`,e.kpis.messagesHandled),n(`Overview`,`AI replies`,e.kpis.aiMessages),n(`Overview`,`Leads qualified`,e.kpis.leadsQualified),n(`Overview`,`Leads assigned`,e.kpis.leadsAssigned),n(`Overview`,`Active agents`,e.kpis.activeAgents),n(`Funnel`,`Total leads`,e.funnel.total),n(`Funnel`,`Contacted`,e.funnel.contacted),n(`Funnel`,`Qualified`,e.funnel.qualified),n(`Funnel`,`Assigned`,e.funnel.assigned),n(`Funnel`,`Interested`,e.funnel.interested),n(`Funnel`,`Not interested`,e.funnel.notInterested),n(`Funnel`,`Lost`,e.funnel.lost),n(`Funnel`,`Conversion rate (%)`,e.funnel.conversionRate),n(`AI automation`,`AI replies generated`,e.automation.aiMessages),n(`AI automation`,`Qualifications completed`,e.automation.qualificationsCompleted),n(`AI automation`,`Auto-assignments`,e.automation.autoAssignments),n(`AI automation`,`Follow-ups sent`,e.automation.followUpsSent),n(`AI automation`,`Automation rate (%)`,e.automation.automationRate);for(let n of e.perAgent)t.push([`Per agent`,`${n.name} â assigned`,String(n.assigned)]),t.push([`Per agent`,`${n.name} â interested`,String(n.interested)]),t.push([`Per agent`,`${n.name} â conversion (%)`,String(n.conversionRate)]);for(let n of e.monthly.filter(e=>e.month>=XG))t.push([`Monthly`,`${n.month} â leads`,String(n.leads)]),t.push([`Monthly`,`${n.month} â messages`,String(n.messages)]);Wk([`Section`,`Metric`,`Value`],t,`stackedhomes-usage-report-${new Date().toISOString().split(`T`)[0]}.csv`)};if(t||!e)return(0,L.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`Loading usage reportâ¦`});let r=[{label:`Total leads`,value:e.funnel.total},{label:`Contacted`,value:e.funnel.contacted},{label:`Qualified`,value:e.funnel.qualified},{label:`Assigned to agent`,value:e.funnel.assigned},{label:`Interested`,value:e.funnel.interested}],i=Math.max(e.funnel.total,1),a=e.monthly.filter(e=>e.month>=XG),o=Math.max(1,...a.map(e=>Math.max(e.leads,e.messages)));return(0,L.jsxs)(`div`,{className:`space-y-6 print:space-y-4`,children:[(0,L.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Usage Report`}),(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`StackedHomes AI platform`})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2 print:hidden`,children:[(0,L.jsxs)(W,{variant:`outline`,size:`sm`,onClick:n,children:[(0,L.jsx)(iw,{className:`h-4 w-4 mr-1.5`}),`Export CSV`]}),(0,L.jsxs)(W,{variant:`outline`,size:`sm`,onClick:()=>window.print(),children:[(0,L.jsx)(Kw,{className:`h-4 w-4 mr-1.5`}),`Print / Save as PDF`]})]})]}),(0,L.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-3 lg:grid-cols-6`,children:[(0,L.jsx)(eK,{title:`Leads processed`,value:ZG(e.kpis.leadsProcessed),icon:(0,L.jsx)(MT,{className:`h-4 w-4`})}),(0,L.jsx)(eK,{title:`Messages handled`,value:ZG(e.kpis.messagesHandled),icon:(0,L.jsx)(eT,{className:`h-4 w-4`})}),(0,L.jsx)(eK,{title:`AI replies`,value:ZG(e.kpis.aiMessages),icon:(0,L.jsx)(MC,{className:`h-4 w-4`})}),(0,L.jsx)(eK,{title:`Leads qualified`,value:ZG(e.kpis.leadsQualified),icon:(0,L.jsx)(KC,{className:`h-4 w-4`})}),(0,L.jsx)(eK,{title:`Leads assigned`,value:ZG(e.kpis.leadsAssigned),icon:(0,L.jsx)(hw,{className:`h-4 w-4`})}),(0,L.jsx)(eK,{title:`Active agents`,value:ZG(e.kpis.activeAgents),icon:(0,L.jsx)(wT,{className:`h-4 w-4`})})]}),(0,L.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{className:`pb-3`,children:[(0,L.jsx)(ND,{className:`text-base`,children:`Lead funnel`}),(0,L.jsxs)(PD,{children:[`Pipeline progression · `,e.funnel.conversionRate,`% qualified of contacted`]})]}),(0,L.jsx)(q,{className:`space-y-3`,children:r.map(e=>(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,L.jsx)(`span`,{children:e.label}),(0,L.jsxs)(`span`,{className:`font-medium tabular-nums`,children:[ZG(e.value),(0,L.jsxs)(`span`,{className:`text-muted-foreground ml-1.5`,children:[Math.round(e.value/i*100),`%`]})]})]}),(0,L.jsx)(`div`,{className:`h-2 rounded-full bg-muted overflow-hidden`,children:(0,L.jsx)(`div`,{className:`h-full rounded-full bg-primary`,style:{width:`${e.value/i*100}%`}})})]},e.label))})]}),(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{className:`pb-3`,children:[(0,L.jsx)(ND,{className:`text-base`,children:`AI automation`}),(0,L.jsxs)(PD,{children:[`Work handled by the AI · `,e.automation.automationRate,`% of outbound messages`]})]}),(0,L.jsx)(q,{children:(0,L.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,L.jsx)(tK,{label:`AI replies generated`,value:ZG(e.automation.aiMessages)}),(0,L.jsx)(tK,{label:`Qualifications completed`,value:ZG(e.automation.qualificationsCompleted)}),(0,L.jsx)(tK,{label:`Auto-assignments`,value:ZG(e.automation.autoAssignments)}),(0,L.jsx)(tK,{label:`Follow-ups sent`,value:ZG(e.automation.followUpsSent)})]})})]})]}),(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{className:`pb-3`,children:[(0,L.jsx)(ND,{className:`text-base`,children:`Per-agent overview`}),(0,L.jsx)(PD,{children:`Leads routed to each agent and their conversion`})]}),(0,L.jsx)(q,{children:(0,L.jsx)(`div`,{className:`rounded-md border`,children:(0,L.jsxs)(Pk,{children:[(0,L.jsx)(Fk,{children:(0,L.jsxs)(Lk,{children:[(0,L.jsx)(J,{children:`Agent`}),(0,L.jsx)(J,{className:`text-right`,children:`Leads assigned`}),(0,L.jsx)(J,{className:`text-right`,children:`Interested`}),(0,L.jsx)(J,{className:`text-right`,children:`Conversion`})]})}),(0,L.jsx)(Ik,{children:e.perAgent.length===0?(0,L.jsx)(Lk,{children:(0,L.jsx)(Y,{colSpan:4,className:`text-center text-muted-foreground py-8`,children:`No agent assignments yet`})}):e.perAgent.map(e=>(0,L.jsxs)(Lk,{children:[(0,L.jsx)(Y,{className:`font-medium`,children:e.name}),(0,L.jsx)(Y,{className:`text-right tabular-nums`,children:ZG(e.assigned)}),(0,L.jsx)(Y,{className:`text-right tabular-nums`,children:ZG(e.interested)}),(0,L.jsxs)(Y,{className:`text-right tabular-nums`,children:[e.conversionRate,`%`]})]},e.agentId))})]})})})]}),(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{className:`pb-3`,children:[(0,L.jsx)(ND,{className:`text-base`,children:`Usage over time`}),(0,L.jsx)(PD,{children:`Leads processed and messages handled per month`})]}),(0,L.jsx)(q,{children:a.length===0?(0,L.jsx)(`div`,{className:`text-center text-muted-foreground py-8 text-sm`,children:`No activity recorded yet`}):(0,L.jsx)(`div`,{className:`space-y-3`,children:a.map(e=>(0,L.jsxs)(`div`,{className:`grid grid-cols-[5rem_1fr] items-center gap-3 text-sm`,children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:QG(e.month)}),(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsx)(nK,{label:`Leads`,value:e.leads,max:o,className:`bg-primary`}),(0,L.jsx)(nK,{label:`Messages`,value:e.messages,max:o,className:`bg-chart-2`})]})]},e.month))})})]}),(0,L.jsxs)(`div`,{className:`pt-4 text-center text-xs text-muted-foreground space-y-0.5`,children:[(0,L.jsxs)(`p`,{children:[`Build `,e.meta.build]}),(0,L.jsxs)(`p`,{children:[`Powered By Voltade (License: Version `,YG,`)`]})]})]})}function eK({title:e,value:t,icon:n}){return(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,L.jsx)(PD,{children:e}),n]}),(0,L.jsx)(q,{children:(0,L.jsx)(`div`,{className:`text-2xl font-bold tabular-nums`,children:t})})]})}function tK({label:e,value:t}){return(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`div`,{className:`text-2xl font-bold tabular-nums`,children:t}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e})]})}function nK({label:e,value:t,max:n,className:r}){return(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`div`,{className:`h-4 flex-1 rounded bg-muted overflow-hidden`,children:(0,L.jsx)(`div`,{className:`h-full rounded ${r}`,style:{width:`${Math.max(t/n*100,t>0?2:0)}%`}})}),(0,L.jsxs)(`span`,{className:`w-28 shrink-0 text-xs text-muted-foreground`,children:[e,`: `,(0,L.jsx)(`span`,{className:`tabular-nums text-foreground`,children:ZG(t)})]})]})}function rK({...e}){return(0,L.jsx)(Ha,{"data-slot":`collapsible`,...e})}function iK({...e}){return(0,L.jsx)(La,{"data-slot":`collapsible-trigger`,...e})}function aK({...e}){return(0,L.jsx)(za,{"data-slot":`collapsible-content`,...e})}function oK(e){let t=Date.now()-new Date(e).getTime(),n=Math.round(t/6e4);if(n<1)return`just now`;if(n<60)return`${n}m ago`;let r=Math.round(n/60);if(r<24)return`${r}h ago`;let i=Math.round(r/24);return i<30?`${i}d ago`:new Date(e).toLocaleDateString()}function sK({configId:e,configLabel:t,onRestored:n}){let[r,i]=(0,_.useState)(!1);return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(W,{variant:`outline`,size:`sm`,onClick:()=>i(!0),className:`gap-1.5`,children:[(0,L.jsx)(vw,{className:`h-3.5 w-3.5`}),`History`]}),r&&(0,L.jsx)(cK,{configId:e,configLabel:t,open:r,onOpenChange:i,onRestored:n})]})}function cK({configId:e,configLabel:t,open:n,onOpenChange:r,onRestored:i}){let[a,o]=(0,_.useState)(!0),[s,c]=(0,_.useState)([]),[l,u]=(0,_.useState)(null),[d,f]=(0,_.useState)(null),[p,m]=(0,_.useState)(!1),h=async()=>{o(!0);try{c((await H(`/api/ai-config/${e}/versions`)).data.versions)}catch(e){console.error(`[version-history] fetch failed:`,e),z.error(`Failed to load version history`)}finally{o(!1)}};(0,_.useEffect)(()=>{h()},[e]);let g=async t=>{m(!0);try{let n=await H(`/api/ai-config/${e}/versions/${t.id}/activate`,{method:`POST`});z.success(`Restored v${t.version}`),i(n.data.value),f(null),r(!1)}catch(e){console.error(`[version-history] restore failed:`,e),z.error(`Failed to restore version`)}finally{m(!1)}};return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(aj,{open:n,onOpenChange:r,children:(0,L.jsxs)(lj,{className:`max-w-3xl max-h-[85vh] overflow-hidden flex flex-col`,children:[(0,L.jsxs)(uj,{children:[(0,L.jsxs)(fj,{className:`flex items-center gap-2`,children:[(0,L.jsx)(vw,{className:`h-5 w-5`}),`Version history`]}),(0,L.jsxs)(pj,{children:[t,` â every save creates a new version.`]})]}),(0,L.jsxs)(`div`,{className:`flex-1 overflow-y-auto -mx-6 px-6`,children:[a&&(0,L.jsxs)(`div`,{className:`flex items-center justify-center py-12 gap-2 text-muted-foreground`,children:[(0,L.jsx)(Ew,{className:`h-4 w-4 animate-spin`}),(0,L.jsx)(`span`,{className:`text-sm`,children:`Loading history...`})]}),!a&&s.length===0&&(0,L.jsx)(`div`,{className:`py-12 text-center text-sm text-muted-foreground`,children:`No version history yet.`}),!a&&s.length>0&&(0,L.jsx)(`ol`,{className:`space-y-2`,children:s.map(e=>{let t=l===e.id;return(0,L.jsxs)(`li`,{className:`rounded-md border bg-card`,children:[(0,L.jsxs)(`button`,{type:`button`,className:`w-full flex items-start gap-3 p-3 text-left hover:bg-muted/50 transition-colors`,onClick:()=>u(t?null:e.id),children:[(0,L.jsx)(`div`,{className:`mt-0.5 shrink-0`,children:t?(0,L.jsx)(zC,{className:`h-4 w-4 text-muted-foreground`}):(0,L.jsx)(VC,{className:`h-4 w-4 text-muted-foreground`})}),(0,L.jsxs)(`div`,{className:`flex-1 min-w-0 space-y-1`,children:[(0,L.jsxs)(`div`,{className:`flex items-center flex-wrap gap-1.5`,children:[(0,L.jsxs)(`span`,{className:`font-medium text-sm`,children:[`v`,e.version]}),e.isActive&&(0,L.jsx)(X,{variant:`default`,className:`text-xs`,children:`Active`}),e.restoredFromVersion!==null&&(0,L.jsxs)(X,{variant:`secondary`,className:`text-xs`,children:[`Restored from v`,e.restoredFromVersion]})]}),(0,L.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[e.authorName??`Unknown`,e.authorEmail&&(0,L.jsxs)(`span`,{className:`text-muted-foreground
150/70`,children:[` `,`· `,e.authorEmail]}),(0,L.jsxs)(`span`,{className:`text-muted-foreground/70`,children:[` · `,oK(e.createdAt)]})]}),e.notes&&(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground italic`,children:e.notes})]}),!e.isActive&&(0,L.jsxs)(W,{variant:`outline`,size:`sm`,className:`shrink-0`,onClick:t=>{t.stopPropagation(),f(e)},children:[(0,L.jsx)(Xw,{className:`h-3.5 w-3.5 mr-1.5`}),`Restore`]})]}),t&&(0,L.jsx)(`div`,{className:`border-t px-3 py-2 bg-muted/30`,children:(0,L.jsx)(`pre`,{className:`text-xs whitespace-pre-wrap font-mono max-h-64 overflow-y-auto`,children:e.value})})]},e.id)})})]})]})}),(0,L.jsx)(lA,{open:!!d,onOpenChange:e=>!e&&!p&&f(null),children:(0,L.jsxs)(pA,{children:[(0,L.jsxs)(mA,{children:[(0,L.jsxs)(gA,{children:[`Restore v`,d?.version,`?`]}),(0,L.jsx)(_A,{children:`This will replace the current active prompt with this version. A new version entry will be created tracking the restore. The current version stays in history.`})]}),(0,L.jsxs)(hA,{children:[(0,L.jsx)(yA,{disabled:p,children:`Cancel`}),(0,L.jsx)(vA,{disabled:p,onClick:e=>{e.preventDefault(),d&&g(d)},children:p?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(Ew,{className:`h-4 w-4 mr-2 animate-spin`}),`Restoring...`]}):`Restore`})]})]})})]})}var lK=/^[a-z0-9]{1,24}$/,uK=`stackedhomes.lastConversationId`;function dK(){let e=ri(),t=vi({queryKey:[`macros`],queryFn:async()=>(await H(`/api/macros`)).data,staleTime:0,refetchOnWindowFocus:!0}),[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(!1),g=(0,_.useMemo)(()=>t.data??[],[t.data]),v=(0,_.useMemo)(()=>{let e=i.trim().toLowerCase();return e?g.filter(t=>t.name.includes(e)||(t.description??``).toLowerCase().includes(e)):g},[g,i]),y=(0,_.useMemo)(()=>n===null||n===`new`?null:g.find(e=>e.id===n)??null,[n,g]),[b,x]=(0,_.useState)(null);b!==n&&(x(n),y?(s(y.name),l(y.description??``),d(y.body),p(null)):n===null&&(s(``),l(``),d(``),p(null)));let S=(0,_.useMemo)(()=>n===`new`?!0:y?o!==y.name||c!==(y.description??``)||u!==y.body:!1,[y,n,o,c,u]),C=()=>e.invalidateQueries({queryKey:[`macros`]}),w=R({mutationFn:e=>H(`/api/macros`,{method:`POST`,body:JSON.stringify(e)}),onSuccess:e=>{z.success(`Created /${e.data.name}`),C(),r(e.data.id)},onError:e=>{z.error(e.message||`Failed to create macro`)}}),T=R({mutationFn:({id:e,body:t})=>H(`/api/macros/${e}`,{method:`PUT`,body:JSON.stringify(t)}),onSuccess:e=>{z.success(`Saved /${e.data.name}`),C()},onError:e=>{z.error(e.message||`Failed to save macro`)}}),E=R({mutationFn:e=>H(`/api/macros/${e}`,{method:`DELETE`}),onSuccess:()=>{z.success(`Macro deleted`),C(),r(null)},onError:e=>{z.error(e.message||`Failed to delete macro`)}}),D=()=>{let e=new Set(g.map(e=>e.name)),t=`macro`,n=2;for(;e.has(t);)t=`macro${n++}`;s(t),l(``),d(``),p(null),r(`new`)},O=e=>{let t=e.trim().toLowerCase();return t.length===0?`Name is required`:t.length>24?`Name cannot exceed 24 characters`:lK.test(t)?null:`Lowercase letters and digits only â no spaces or symbols`},k=()=>{let e=o.trim().replace(/^\//,``).toLowerCase();e!==o&&s(e),p(O(e))},A=()=>{let e=O(o);if(e){p(e);return}let t=o.trim().toLowerCase();if(u.length===0){z.error(`Macro body is required`);return}if(u.length>4e3){z.error(`Macro body cannot exceed 4000 characters`);return}let r={name:t,description:c.trim()||null,body:u};n===`new`?w.mutate(r):n&&T.mutate({id:n,body:r})},j=()=>{y&&(E.mutate(y.id),h(!1))},M=(0,_.useRef)(null),[ee,N]=(0,_.useState)(!1),[P,F]=(0,_.useState)(``),[I,te]=(0,_.useState)(0),ne=(e,t)=>{let n=e.slice(0,t),r=n.lastIndexOf(`{{`);if(r===-1){N(!1);return}let i=n.slice(r+2);if(i.includes(`}}`)){N(!1);return}if(/\s/.test(i)){N(!1);return}N(!0),F(i.trim()),te(0)},re=(0,_.useMemo)(()=>{let e=P.toLowerCase();return e?Oz.filter(t=>t.token.toLowerCase().includes(e)):Oz},[P]),ie=e=>{let t=M.current;if(!t){d(t=>t+e);return}let n=t.selectionStart??u.length,r=t.selectionEnd??u.length;d(u.slice(0,n)+e+u.slice(r)),requestAnimationFrame(()=>{t.focus();let r=n+e.length;t.setSelectionRange(r,r)}
150)},ae=e=>{let t=M.current;if(ee&&t){let n=t.selectionStart??u.length,r=u.slice(0,n).lastIndexOf(`{{`);if(r!==-1){let i=u.slice(n),a=`{{${e}}}`;d(u.slice(0,r)+a+i),N(!1),requestAnimationFrame(()=>{t.focus();let e=r+a.length;t.setSelectionRange(e,e)});return}}ie(`{{${e}}}`)},oe=e=>{if(!(e.nativeEvent.isComposing||e.keyCode===229)&&ee)switch(e.key){case`ArrowDown`:e.preventDefault(),te(e=>Math.min(e+1,re.length-1));return;case`ArrowUp`:e.preventDefault(),te(e=>Math.max(e-1,0));return;case`Enter`:case`Tab`:{let t=re[I];t&&(e.preventDefault(),e.stopPropagation(),ae(t.token));return}case`Escape`:e.preventDefault(),N(!1);return}},se=typeof window<`u`?window.localStorage.getItem(uK):null,ce=e.getQueryData([`conversation-details`,se]),le=ce?{lead:ce.lead,agent:ce.agent}:null,[ue,de]=(0,_.useState)(le?`real`:`sample`),fe=jz(u,ue===`real`&&le?le:Pz),pe=(0,_.useMemo)(()=>Mz(u),[u]).filter(e=>!Nz(e)),me=w.isPending||T.isPending,he=n!==null;return(0,L.jsx)(ex,{delayDuration:300,children:(0,L.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,L.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Text shortcuts used by Joey in the inbox composer. Not used by AI. Type `,(0,L.jsx)(`code`,{className:`rounded bg-muted px-1 text-xs`,children:`/`}),` in the inbox to bring up the picker.`]}),(0,L.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-[280px_1fr] gap-4 min-h-[600px]`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-2 border rounded-md p-2`,children:[(0,L.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,L.jsxs)(W,{type:`button`,size:`sm`,variant:`default`,onClick:D,className:`flex-1`,children:[(0,L.jsx)(Gw,{className:`h-4 w-4 mr-1`}),`New macro`]})}),(0,L.jsx)(G,{type:`search`,placeholder:`Search macros...`,value:i,onChange:e=>a(e.target.value),className:`h-8 text-sm`}),(0,L.jsx)(`div`,{className:`flex-1 overflow-y-auto -mx-1 px-1`,children:t.isLoading?(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground py-2`,children:`Loading...`}):v.length===0?(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground py-2`,children:g.length===0?`No macros yet`:`No matches for that search`}):(0,L.jsx)(`ul`,{className:`flex flex-col`,children:v.map(e=>(0,L.jsx)(`li`,{children:(0,L.jsxs)(`button`,{type:`button`,onClick:()=>r(e.id),className:V(`w-full text-left px-2 py-1.5 rounded text-sm hover:bg-muted`,n===e.id&&`bg-muted`),children:[(0,L.jsxs)(`div`,{className:`font-mono font-medium`,children:[`/`,e.name]}),e.description&&(0,L.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:e.description})]})},e.id))})})]}),he?(0,L.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-[1fr_240px] gap-4`,children:[(0,L.jsxs)(`div`,{className:`space-y-3`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(Z,{htmlFor:`macro-name`,children:[`Name `,(0,L.jsxs)(`span`,{className:`text-muted-foreground`,children:[`(used as /`,o||`name`,`)`]})]}),(0,L.jsx)(G,{id:`macro-name`,value:o,onChange:e=>s(e.target.value),onBlur:k,placeholder:`intro`,className:V(`font-mono`,f&&`border-destructive`),autoComplete:`off`}),f&&(0,L.jsx)(`p`,{className:`text-xs text-destructive mt-1`,children:f})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(Z,{htmlFor:`macro-description`,children:`Description (optional)`}),(0,L.jsx)(G,{id:`macro-description`,value:c,onChange:e=>l(e.target.value),placeholder:`First reply to a new lead`,maxLength:500})]}),(0,L.jsxs)(`div`,{className:`relative`,children:[(0,L.jsx)(Z,{htmlFor:`macro-body`,children:`Body`}),(0,L.jsx)(TD,{ref:M,id:`macro-body`,value:u,onChange:e=>{d(e.target.value),ne(e.target.value,e.target.selectionStart)},onKeyDown:oe,onSelect:e=>ne(u,e.target.selectionStart),onBlur:()=>{setTimeout(()=>N(!1),150)},rows:10,placeholder:`Hi {{lead.firstName}}, thanks for reaching out!`,className:`font-mono text-sm resize-y`}),(0,L.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1 flex items-center justify-between`,children:[(0,L.jsxs)(`span`,{children:[u.length,` / 4000 characters`]}),pe.length>0&&(0,L.jsxs)(`span`,{className:`text-destructive flex items-center gap-1`,children:[(0,L.jsx)(xT,{className:`h-3 w-3`}),`Unknown:`,` `,pe.map(e=>`{{${e}}}`).join(`, `)]})]}),ee&&re.length>0&&(0,L.jsx)(`div`,{role:`listbox`,className:`absolute left-0 right-0 top-full mt-1 z-10 border bg-popover rounded-md shadow-md max-h-48 overflow-y-auto`,children:re.map((e,t)=>(0,L.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t===I,onMouseEnter:()=>te(t),onMouseDown:t=>{t.preventDefault(),ae(e.token)},className:V(`w-full text-left px-3 py-1.5 text-sm font-mono hover:bg-muted`,t===I&&`bg-muted`),children:[(0,L.jsx)(`div`,{children:`{{${e.token}}}`}),(0,L.jsx)(`div`,{className:`text-xs text-muted-foreground font-sans`,children:e.description})]},e.token))})]}),(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsx)(Z,{children:`Live preview`}),le&&(0,L.jsxs)(`div`,{className:`flex items-center gap-1 text-xs`,children:[(0,L.jsxs)(`button`,{type:`button`,onClick:()=>de(`real`),className:V(`px-2 py-0.5 rounded`,ue===`real`?`bg-primary text-primary-foreground`:`text-muted-foreground hover:bg-muted`),children:[`Use `,le.lead?.name??`last lead`]}),(0,L.jsx)(`button`,{type:`button`,onClick:()=>de(`sample`),className:V(`px-2 py-0.5 rounded`,ue===`sample`?`bg-primary text-primary-foreground`:`text-muted-foreground hover:bg-muted`),children:`Use sample lead`})]})]}),(0,L.jsx)(K,{children:(0,L.jsx)(q,{className:`p-3 text-sm whitespace-pre-wrap`,children:fe.ok?fe.text||(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`Preview will appear once you t
150ype a body.`}):(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsxs)(`p`,{className:`text-destructive flex items-center gap-1 text-xs`,children:[(0,L.jsx)(xT,{className:`h-3 w-3`}),`Cannot render preview`]}),fe.unknown.length>0&&(0,L.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Unknown:`,` `,fe.unknown.map(e=>`{{${e}}}`).join(`, `)]}),fe.missing.length>0&&(0,L.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Missing on`,` `,ue===`real`?`real`:`sample`,` `,`lead:`,` `,fe.missing.map(e=>`{{${e}}}`).join(`, `)]})]})})})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,L.jsx)(W,{type:`button`,onClick:A,disabled:!S||me||!!f,children:me?`Saving...`:n===`new`?`Create macro`:`Save`}),y&&(0,L.jsxs)(lA,{open:m,onOpenChange:h,children:[(0,L.jsx)(uA,{asChild:!0,children:(0,L.jsxs)(W,{type:`button`,variant:`ghost`,className:`text-destructive hover:text-destructive`,children:[(0,L.jsx)(vT,{className:`h-4 w-4 mr-1`}),`Delete`]})}),(0,L.jsxs)(pA,{children:[(0,L.jsxs)(mA,{children:[(0,L.jsxs)(gA,{children:[`Delete /`,y.name,`?`]}),(0,L.jsx)(_A,{children:`This cannot be undone.`})]}),(0,L.jsxs)(hA,{children:[(0,L.jsx)(yA,{children:`Cancel`}),(0,L.jsx)(vA,{onClick:j,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]})]})]}),y?.updatedByName&&(0,L.jsxs)(`span`,{className:`ml-auto text-xs text-muted-foreground`,children:[`Last edited by `,y.updatedByName]})]})]}),(0,L.jsxs)(`div`,{className:`border rounded-md p-3 h-fit`,children:[(0,L.jsx)(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2`,children:`Variables`}),(0,L.jsx)(`div`,{className:`flex flex-col gap-1`,children:Oz.map(e=>(0,L.jsxs)(tx,{children:[(0,L.jsx)(nx,{asChild:!0,children:(0,L.jsx)(`button`,{type:`button`,onClick:()=>ae(e.token),className:`text-left px-2 py-1 rounded text-xs font-mono hover:bg-muted`,children:`{{${e.token}}}`})}),(0,L.jsxs)(rx,{side:`left`,className:`max-w-xs`,children:[(0,L.jsx)(`p`,{className:`font-medium`,children:e.label}),(0,L.jsx)(`p`,{className:`text-xs`,children:e.description})]})]},e.token))}),(0,L.jsxs)(`p`,{className:`text-[11px] text-muted-foreground mt-3`,children:[`Click a variable to insert it at the cursor. Or type`,` `,(0,L.jsx)(`code`,{children:`{{`}),` to autocomplete.`]})]})]}):(0,L.jsx)(K,{className:`flex items-center justify-center`,children:(0,L.jsx)(q,{className:`text-center text-sm text-muted-foreground py-8`,children:g.length===0?(0,L.jsxs)(L.Fragment,{children:[`No macros yet. Click `,(0,L.jsx)(`strong`,{children:`+ New macro`}),` to create your first shortcut.`]}):(0,L.jsx)(L.Fragment,{children:`Select a macro on the left to edit, or create a new one.`})})})]})]})})}function fK(e){let t=e.match(/\{\{\s*([A-Za-z0-9_]+)\s*\}\}/g)??[],n=new Set,r=[],i=[];for(let e of t){let t=e.replace(/[{}\s]/g,``);t.length===0||n.has(t)||(n.add(t),/^\d+$/.test(t)?r.push({index:Number(t),source:``}):i.push({name:t,source:``}))}return r.sort((e,t)=>(e.index??0)-(t.index??0)),[...r,...i]}var pK=[{value:`outreach`,label:`Initial outreach`},{value:`mop_defer`,label:`MOP defer ack`},{value:`followup_due`,label:`Follow-up due`},{value:`mop_due`,label:`MOP re-engage`},{value:`qual_nudge`,label:`Qualification nudge`},{value:`weekend_hold`,label:`Weekend holding`},{value:`holiday_hold`,label:`Holiday holding`}],mK=[`MARKETING`,`UTILITY`],hK=Object.fromEntries(pK.map(e=>[e.value,e.label]));function gK(e){return e===`rejected`?`destructive`:`secondary`}function _K(e){return e===`approved`?`bg-emerald-600 text-white border-transparent`:``}var vK={kind:`outreach`,metaTemplateName:``,language:`en`,category:`UTILITY`,bodyPreview:``,variablePlanText:`[]`,isActive:!0};function yK(){let e=ri(),t=vi({queryKey:[`whatsapp-templates`],queryFn:async()=>(await H(`/api/templates`)).data,staleTime:0,refetchOnWindowFocus:!0}),n=(0,_.useMemo)(()=>t.data??[],[t.data]),r=vi({queryKey:[`whatsapp-templates-meta`],queryFn:async()=>(await H(`/api/templates/meta`)).data,staleTime:6e4}),i=(0,_.useMemo)(()=>(r.data?.templates??[]).filter(e=>e.mappedKind===null),[r.data]),a=r.isError||r.data?.ok===!1,[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(vK),[u,d]=(0,_.useState)(!1),f=(0,_.useMemo)(()=>o===null||o===`new`?null:n.find(e=>e.id===o)??null,[o,n]),[p,m]=(0,_.useState)(null);p!==o&&(m(o),f?l({kind:f.kind,metaTemplateName:f.metaTemplateName,language:f.language,category:f.category,bodyPreview:f.bodyPreview,variablePlanText:JSON.stringify(f.variablePlan??[],null,2),isActive:f.isActive}):o===null&&l(vK));let h=()=>
150{e.invalidateQueries({queryKey:[`whatsapp-templates`]}),e.invalidateQueries({queryKey:[`whatsapp-templates-meta`]})},g=R({mutationFn:e=>H(`/api/templates`,{method:`POST`,body:JSON.stringify(e)}),onSuccess:e=>{z.success(`Created ${e.data.metaTemplateName}`),h(),s(e.data.id)},onError:e=>z.error(e.message||`Failed to create template`)}),v=R({mutationFn:({id:e,body:t})=>H(`/api/templates/${e}`,{method:`PUT`,body:JSON.stringify(t)}),onSuccess:e=>{z.success(`Saved ${e.data.metaTemplateName}`),h()},onError:e=>z.error(e.message||`Failed to save template`)}),y=R({mutationFn:e=>H(`/api/templates/${e}`,{method:`DELETE`}),onSuccess:()=>{z.success(`Template deleted`),h(),s(null)},onError:e=>z.error(e.message||`Failed to delete template`)}),b=R({mutationFn:()=>H(`/api/templates/sync`,{method:`POST`}),onSuccess:e=>{z.success(`Synced ${e.data.matched} mapped template(s) from Meta`),h()},onError:e=>z.error(e.message||`Sync failed`)}),x=()=>{l(vK),s(`new`)},S=e=>{l({...vK,metaTemplateName:e.name,language:e.language||`en`,category:e.category===`MARKETING`?`MARKETING`:`UTILITY`,bodyPreview:e.body,variablePlanText:JSON.stringify(fK(e.body),null,2)}),s(`new`)},C=()=>{let e;try{let t=JSON.parse(c.variablePlanText||`[]`);if(!Array.isArray(t))throw Error(`must be an array`);e=t}catch(e){return z.error(`Variable plan must be valid JSON array: ${e instanceof Error?e.message:String(e)}`),null}return c.metaTemplateName.trim()?c.bodyPreview.trim()?{kind:c.kind,metaTemplateName:c.metaTemplateName.trim(),language:c.language.trim()||`en`,category:c.category,bodyPreview:c.bodyPreview,variablePlan:e}:(z.error(`Body preview is required`),null):(z.error(`Meta template name is required`),null)},w=()=>{let e=C();e&&(o===`new`?g.mutate(e):o&&v.mutate({id:o,body:{metaTemplateName:e.metaTemplateName,language:e.language,category:e.category,bodyPreview:e.bodyPreview,variablePlan:e.variablePlan,isActive:c.isActive}}))},T=()=>{f&&(y.mutate(f.id),d(!1))},E=g.isPending||v.isPending,D=o!==null;return(0,L.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,L.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Maps each business-initiated message type to a Meta-approved WhatsApp template. The body is owned by Meta â we mirror it and sync approval status. Auto-send only fires once a template is`,` `,(0,L.jsx)(`strong`,{children:`approved`}),`.`]}),(0,L.jsxs)(W,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>b.mutate(),disabled:b.isPending,children:[(0,L.jsx)(Yw,{className:V(`h-4 w-4 mr-1`,b.isPending&&`animate-spin`)}),`Sync from Meta`]})]}),(0,L.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-[300px_1fr] gap-4 min-h-[500px]`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-2 border rounded-md p-2`,children:[(0,L.jsxs)(W,{type:`button`,size:`sm`,variant:`default`,onClick:x,className:`w-full`,children:[(0,L.jsx)(Gw,{className:`h-4 w-4 mr-1`}),`New template`]}),(0,L.jsxs)(`div`,{className:`flex-1 overflow-y-auto -mx-1 px-1`,children:[t.isLoading?(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground py-2`,children:`Loading...`}):n.length===0?(0,L.jsxs)(`p`,{className:`text-xs text-muted-foreground py-2`,children:[`No templates yet. Click `,(0,L.jsx)(`strong`,{children:`New template`}),` to map one.`]}):(0,L.jsx)(`ul`,{className:`flex flex-col gap-1`,children:n.map(e=>(0,L.jsx)(`li`,{children:(0,L.jsxs)(`button`,{type:`button`,onClick:()=>s(e.id),className:V(`w-full text-left px-2 py-1.5 rounded hover:bg-muted`,o===e.id&&`bg-muted`),children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,L.jsx)(`span`,{className:`text-sm font-medium truncate`,children:hK[e.kind]}),(0,L.jsx)(X,{variant:gK(e.status),className:_K(e.status),children:e.status})]}),(0,L.jsxs)(`div`,{className:`text-xs text-muted-foreground font-mono truncate`,children:[e.metaTemplateName,` · `,e.language,!e.isActive&&` · inactive`]})]})},e.id))}),a&&(0,L.jsx)(`p`,{className:`text-xs text-destructive pt-2 px-2`,children:`Couldn't load the full Meta template list â templates missing below may still exist on Meta.`}),i.length>0&&(0,L.jsxs)(`div`,{className:`pt-2 mt-2 border-t`,children:[(0,L.jsxs)(`p`,{className:`text-[11px] font-medium uppercase tracking-wide text-muted-foreground px-2 pb-1`,children:[`On Meta, not mapped (`,i.length,`)`]}),(0,L.jsx)(`ul`,{className:`flex flex-col gap-1`,children:i.map(e=>(0,L.jsx)(`li`,{children:(0,L.jsxs)(`button`,{type:`button`,onClick:()=>S(e),title:`Map this Meta template to a message type`,className:`w-full text-left px-2 py-1.5 rounded hover:bg-muted`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,L.jsx)(`span`,{className:`text-xs font-mono truncate`,children:e.name}),(0,L.jsx)(X,{variant:`secondary`,className:`shrink-0`,children:e.category.toLowerCase()})]}),(0,L.jsxs)(`div`,{className:`text-[11px] text-muted-foreground truncate`,children:[e.language,` · `,e.status.toLowerCase(),` · click to map`]})]})},`${e.name}:${e.language}`))})]})]})]}),D?(0,L.jsxs)(`div`,{className:`space-y-3`,children:[(0,L.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(Z,{htmlFor:`tmpl-kind`,children:`Kind (message type)`}),(0,L.jsxs)(wk,{value:c.kind,onValueChange:e=>l(t=>({...t,kind:e})),disabled:o!==`new`,children:[(0,L.jsx)(Dk,{id:`tmpl-kind`,children:(0,L.jsx)(Ek,{})}),(0,L.jsx)(Ok,{children:pK.map(e=>(0,L.jsx)(Ak,{value:e.value,children:e.label},e.value))})]}),o!==`new`&&(0,L.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:`Kind is fixed after creation.`})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(Z,{htmlFor:`tmpl-category`,children:`Category`}),(0,L.jsxs)(wk,{value:c.category,onValueChange:e=>l(t=>({...t,category:e})),children:[(0,L.jsx)(Dk,{id:`tmpl-category`,children:(0,L.jsx)(Ek,{})}),(0,L.jsx)(Ok,{children:mK.map(e=>(0,L.jsx)(Ak,{value:e,children:e},e))})]})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(Z,{htmlFor:`tmpl-name`,children:`Meta template name`}),(0,L.jsx)(G,{id:`tmpl-name`,value:c.metaTemplateName,onChange:e=>l(t=>({...t,metaTemplateName:e.target.value})),placeholder:`lead_outreach_v1`,className:`font-mono`,autoComplete:`off`})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(Z,{htmlFor:`tmpl-language`,children:`Language`}),(0,L.jsx)(G,{id:`tmpl-language`,value:c.language,onChange:e=>l(t=>({...t,language:e.target.value})),placeholder:`en`,className:`font-mono`,autoComplete:`off`})]})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(Z,{htmlFor:`tmpl-body`,children:`Body preview (mirrors Meta copy)`}),(0,L.jsx)(TD,{id:`tmpl-body`,value:c.bodyPreview,onChange:e=>l(t=>({...t,bodyPreview:e.target.value})),rows:4,placeholder:`Hi {{1}}, thanks for your interest in {{2}}...`,className:`font-mono text-sm resize-y`})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(Z,{htmlFor:`tmpl-vars`,children:[`Variable plan (JSON â positional `,`{{1}}`,` or named)`]}),(0,L.jsx)(TD,{id:`tmpl-vars`,value:c.variablePlanText,onChange:e=>l(t=>({...t,variablePlanText:e.target.value})),rows:6,placeholder:`[{ "index": 1, "source": "lead.name" }]`,className:`font-mono text-sm resize-y`}),(0,L.jsxs)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:[`Each slot maps a template variable to a lead field, e.g.`,` `,(0,L.jsx)(`code`,{className:`rounded bg-muted px-1`,children:`{ "index": 1, "source": "lead.firstName" }`}),`. Supported sources: `,(0,L.jsx)(`code`,{children:`lead.name`}),`,`,` `,(0,L.jsx)(`code`,{children:`lead.firstName`}),`, `,(0,L.jsx)(`code`,{children:`lead.phone`}),`,`,` `,(0,L.jsx)(`code`,{children:`lead.email`}),`, `,(0,L.jsx)(`code`,{children:`lead.source`}),`,`,` `,(0,L.jsx)(`code`,{children:`lead.profile.<key>`}),`,`,` `,(0,L.jsx)(`code`,{children:`static:<value>`}),`. An unresolvable slot fails closed to a draft (never fires with a blank variable).`]})]}),o!==`new`&&(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(Ck,{id:`tmpl-active`,checked:c.isActive,onCheckedChange:e=>l(t=>({...t,isActive:e}))}
150),(0,L.jsx)(Z,{htmlFor:`tmpl-active`,className:`cursor-pointer`,children:`Active (the send path picks the active template for a kind)`})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,L.jsx)(W,{type:`button`,onClick:w,disabled:E,children:E?`Saving...`:o===`new`?`Create template`:`Save`}),f&&(0,L.jsxs)(lA,{open:u,onOpenChange:d,children:[(0,L.jsx)(uA,{asChild:!0,children:(0,L.jsxs)(W,{type:`button`,variant:`ghost`,className:`text-destructive hover:text-destructive`,children:[(0,L.jsx)(vT,{className:`h-4 w-4 mr-1`}),`Delete`]})}),(0,L.jsxs)(pA,{children:[(0,L.jsxs)(mA,{children:[(0,L.jsxs)(gA,{children:[`Delete this `,hK[f.kind],` template?`]}),(0,L.jsx)(_A,{children:`This removes the mapping only â the template in Meta Business Manager is untouched. This cannot be undone.`})]}),(0,L.jsxs)(hA,{children:[(0,L.jsx)(yA,{children:`Cancel`}),(0,L.jsx)(vA,{onClick:T,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]})]})]}),f?.status&&(0,L.jsxs)(`span`,{className:`ml-auto text-xs text-muted-foreground`,children:[`Meta status:`,` `,(0,L.jsx)(X,{variant:gK(f.status),className:_K(f.status),children:f.status})]})]})]}):(0,L.jsx)(K,{className:`flex items-center justify-center`,children:(0,L.jsx)(q,{className:`text-center text-sm text-muted-foreground py-8`,children:`Select a template on the left to edit, or create a new one.`})})]})]})}function bK(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)([]),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(``),[m,h]=(0,_.useState)(!1),g=(0,_.useCallback)(async()=>{let e=await H(`/api/config-chat/sessions`);return t(e.data),e.data},[]),v=(0,_.useCallback)(async(e,t)=>{r(e),t?.silent||l(!0);try{let t=await H(`/api/config-chat/sessions/${e}`);a(t.data.messages),s(t.data.proposals)}catch(e){z.error(e instanceof Error?e.message:`Failed to load chat`)}finally{l(!1)}},[]);(0,_.useEffect)(()=>{(async()=>{let e=await g().catch(()=>[]);e.length>0&&v(e[0].id)})()},[g,v]);let y=(0,_.useCallback)(async()=>{let e=await H(`/api/config-chat/sessions`,{method:`POST`,body:JSON.stringify({})});return t(t=>[e.data,...t]),e.data},[]),b=(0,_.useCallback)(async()=>{u||(r((await y()).id),a([]),s([]))},[y,u]),x=(0,_.useCallback)(async(e,n)=>{try{let r=await H(`/api/config-chat/sessions/${e}`,{method:`PATCH`,body:JSON.stringify({title:n})});t(t=>t.map(t=>t.id===e?r.data:t))}catch(e){z.error(e instanceof Error?e.message:`Rename failed`)}},[]),S=(0,_.useCallback)(async e=>{try{await H(`/api/config-chat/sessions/${e}`,{method:`DELETE`}),t(t=>t.filter(t=>t.id!==e)),n===e&&(r(null),a([]),s([]))}catch(e){z.error(e instanceof Error?e.message:`Delete failed`)}},[n]),C=(0,_.useCallback)(async e=>{let t=e.trim();if(!t||u)return;let i=n;if(!i){let e=await y();i=e.id,r(e.id),a([]),s([])}let o={id:`temp-${Date.now()}`,sessionId:i,role:`user`,content:t,createdAt:new Date().toISOString()};a(e=>[...e,o]),h(!0),p(``),d(!0);let c=``,l=null;try{let e=await fetch(`/api/config-chat/sessions/${i}/chat`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify({message:t})});if(e.status===401){window.location.href=`/login`;return}if(!e.ok||!e.body)throw Error(`Request failed: ${e.status}`);let n=e.body.getReader(),r=new TextDecoder,o=``,u=e=>{if(!e.trim())return;let t;try{t=JSON.parse(e)}catch{return}t.type===`text`?(c+=t.text,p(c)):t.type===`proposal`?s(e=>e.some(e=>e.id===t.proposal.id)?e:[...e,t.proposal]):t.type===`done`?l=t.messageId:t.type===`error`&&z.error(t.message)};for(;;){let{done:e,value:t}=await n.read();if(e)break;o+=r.decode(t,{stream:!0});let i=o.split(` 151`);o=i.pop()??``;for(let e of i)u(e)}if(o.trim()&&u(o),l){let e=c.trim(),t=l;a(n=>[...n,{id:t,sessionId:i,role:`assistant`,content:e,createdAt:new Date().toISOString()}])}g()}catch(e){z.error(e instanceof Error?e.message:`Chat failed`),i&&v(i,{silent:!0})}finally{h(!1),p(``),d(!1)}},[n,y,g,v,u]),w=(0,_.useCallback)(async(e,t)=>{try{let n=await H(`/api/config-chat/proposals/${e}/${t}`,{method:`POST`});s(t=>t.map(t=>
151t.id===e?n.data.proposal:t)),z.success(t===`approve`?`Change applied`:t===`reject`?`Proposal rejected`:`Change reverted`)}catch(e){z.error(e instanceof Error?e.message:`Could not ${t}`)}},[]);return{sessions:e,activeId:n,messages:i,proposals:o,loadingSession:c,streaming:u,liveActive:m,liveText:f,newChat:b,selectSession:v,renameSession:x,deleteSession:S,sendMessage:C,approve:e=>w(e,`approve`),reject:e=>w(e,`reject`),revert:e=>w(e,`revert`)}}function xK(e){let t=Date.now()-new Date(e).getTime(),n=Math.round(t/6e4);if(n<1)return`just now`;if(n<60)return`${n}m ago`;let r=Math.round(n/60);return r<24?`${r}h ago`:`${Math.round(r/24)}d ago`}function SK({sessions:e,activeId:t,onSelect:n,onNew:r,onRename:i,onDelete:a}){let[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(``),u=e=>{let t=c.trim();t&&i(e,t),s(null)};return(0,L.jsxs)(`div`,{className:`flex w-64 shrink-0 flex-col border-r`,children:[(0,L.jsx)(`div`,{className:`p-3`,children:(0,L.jsxs)(W,{onClick:r,className:`w-full justify-start`,variant:`outline`,children:[(0,L.jsx)(Mw,{className:`mr-2 h-4 w-4`}),`New chat`]})}),(0,L.jsxs)(`div`,{className:`flex-1 space-y-1 overflow-y-auto px-2 pb-3`,children:[e.length===0&&(0,L.jsx)(`p`,{className:`px-2 py-4 text-center text-xs text-muted-foreground`,children:`No chats yet`}),e.map(e=>(0,L.jsxs)(`div`,{className:V(`group flex items-center gap-1 rounded-md px-2 py-1.5 text-sm`,e.id===t?`bg-accent`:`hover:bg-accent/50`),children:[o===e.id?(0,L.jsx)(G,{autoFocus:!0,value:c,onChange:e=>l(e.target.value),onBlur:()=>u(e.id),onKeyDown:t=>{t.key===`Enter`&&u(e.id),t.key===`Escape`&&s(null)},className:`h-7 text-sm`}):(0,L.jsxs)(`button`,{type:`button`,onClick:()=>n(e.id),onDoubleClick:()=>{s(e.id),l(e.title)},className:`min-w-0 flex-1 text-left`,title:`Double-click to rename`,children:[(0,L.jsx)(`div`,{className:`truncate font-medium`,children:e.title}),(0,L.jsxs)(`div`,{className:`truncate text-[11px] text-muted-foreground`,children:[e.createdByName?`${e.createdByName} · `:``,xK(e.updatedAt)]})]}),(0,L.jsx)(`button`,{type:`button`,onClick:()=>a(e.id),className:`shrink-0 rounded p-1 text-muted-foreground opacity-0 hover:text-destructive group-hover:opacity-100`,title:`Delete chat`,children:(0,L.jsx)(vT,{className:`h-3.5 w-3.5`})})]},e.id))]})]})}function CK(e,t){let n=e.split(` 152`),r=t.split(` 153`),i=n.length,a=r.length,o=Array.from({length:i+1},()=>Array(a+1).fill(0));for(let e=i-1;e>=0;e--)for(let t=a-1;t>=0;t--)o[e][t]=n[e]===r[t]?o[e+1][t+1]+1:Math.max(o[e+1][t],o[e][t+1]);let s=[],c=0,l=0;for(;c<i&&l<a;)n[c]===r[l]?(s.push({type:`same`,text:n[c]}),c++,l++):o[c+1][l]>=o[c][l+1]?(s.push({type:`remove`,text:n[c]}),c++):(s.push({type:`add`,text:r[l]}),l++);for(;c<i;)s.push({type:`remove`,text:n[c++]});for(;l<a;)s.push({type:`add`,text:r[l++]});return s}function wK({proposal:e,label:t,busy:n,onApprove:r,onReject:i,onRevert:a}){let[o,s]=(0,_.useState)(!0),c=CK(e.oldValue,e.newValue),l=!!e.revertedAt;return(0,L.jsxs)(`div`,{className:`rounded-lg border bg-card text-card-foreground shadow-sm`,children:[(0,L.jsxs)(`div`,{className:`flex items-start justify-between gap-2 border-b p-3`,children:[(0,L.jsx)(`div`,{className:`min-w-0`,children:(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`span`,{className:`text-sm font-medium`,children:t}),(0,L.jsxs)(X,{variant:`outline`,className:`font-mono text-[10px]`,children:[e.category,`/`,e.key]})]})}),(0,L.jsx)(TK,{proposal:e,reverted:l})]}),(0,L.jsxs)(`div`,{className:`space-y-2 p-3 text-sm`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`span`,{className:`font-medium text-muted-foreground`,children:`Problem: `}),e.problem]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`span`,{className:`font-medium text-muted-foreground`,children:`Outcome: `}),e.outcome]}),(0,L.jsxs)(`button`,{type:`button`,onClick:()=>s(e=>!e),className:`flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground`,children:[o?(0,L.jsx)(zC,{className:`h-3 w-3`}):(0,L.jsx)(VC,{className:`h-3 w-3`}),o?`Hide changes`:`Show changes`]}),o&&(0,L.jsx)(`pre`,{className:`max-h-72 overflow-y-auto whitespace-pre-wrap [overflow-wrap:anywhere] rounded-md border bg-muted/40 p-2 text-xs leading-relaxed`,children:c.map((e,t)=>(0,L.jsxs)(`div`,{className:e.type===`add`?`bg-green-500/15 text-green-700 dark:text-green-300`:e.type===`remove`?`bg-red-500/15 text-red-700 dark:text-red-300`:`text-muted-foreground`,children:[(0,L.jsx)(`span`,{className:`select-none opacity-60`,children:e.type===`add`?`+ `:e.type===`remove`?`- `:` `}),e.text||`\xA0`]},t))})]}),(0,L.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t p-3`,children:[e.status===`pen
153ding`&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(W,{variant:`outline`,size:`sm`,disabled:n,onClick:i,children:[(0,L.jsx)(FT,{className:`mr-1 h-4 w-4`}),`Reject`]}),(0,L.jsxs)(W,{size:`sm`,disabled:n,onClick:r,children:[(0,L.jsx)(RC,{className:`mr-1 h-4 w-4`}),`Approve`]})]}),e.status===`approved`&&!l&&(0,L.jsxs)(W,{variant:`ghost`,size:`sm`,disabled:n,onClick:a,children:[(0,L.jsx)(Xw,{className:`mr-1 h-4 w-4`}),`Revert`]})]})]})}function TK({proposal:e,reverted:t}){return e.status===`pending`?(0,L.jsx)(X,{variant:`secondary`,children:`Pending`}):e.status===`rejected`?(0,L.jsx)(X,{variant:`outline`,children:`Rejected`}):t?(0,L.jsx)(X,{variant:`outline`,children:`Reverted`}):(0,L.jsx)(X,{className:`bg-green-600 hover:bg-green-600`,children:`Applied`})}function EK({messages:e,proposals:t,liveActive:n,liveText:r,labelFor:i,busyId:a,onApprove:o,onReject:s,onRevert:c}){let l=(0,_.useRef)(null);(0,_.useEffect)(()=>{l.current?.scrollIntoView({behavior:`smooth`})},[e,r,n,t]);let u=e=>t.filter(t=>t.messageId===e),d=t.filter(t=>!e.some(e=>e.id===t.messageId)),f=e=>e.length>0?(0,L.jsx)(`div`,{className:`mt-2 space-y-2`,children:e.map(e=>(0,L.jsx)(wK,{proposal:e,label:i(e.category,e.key),busy:a===e.id,onApprove:()=>o(e.id),onReject:()=>s(e.id),onRevert:()=>c(e.id)},e.id))}):null;return(0,L.jsxs)(`div`,{className:`flex-1 space-y-4 overflow-y-auto p-4`,children:[e.length===0&&!n&&(0,L.jsxs)(`div`,{className:`mx-auto mt-16 max-w-md text-center text-muted-foreground`,children:[(0,L.jsx)(lT,{className:`mx-auto mb-3 h-8 w-8 opacity-60`}),(0,L.jsx)(`p`,{className:`text-sm`,children:`Describe what you'd like to change about the AI's behaviour â its tone, what it asks leads, the handoff messages, and more. I'll draft the change and you approve it.`})]}),e.map(e=>(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`div`,{className:e.role===`user`?`flex justify-end`:`flex justify-start`,children:(0,L.jsx)(`div`,{className:e.role===`user`?`max-w-[80%] whitespace-pre-wrap rounded-2xl bg-primary px-4 py-2 text-sm text-primary-foreground`:`max-w-[85%] whitespace-pre-wrap rounded-2xl bg-muted px-4 py-2 text-sm`,children:e.content||(e.role===`assistant`?`â¦`:``)})}),e.role===`assistant`&&f(u(e.id))]},e.id)),n&&(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`div`,{className:`flex justify-start`,children:(0,L.jsx)(`div`,{className:`max-w-[85%] whitespace-pre-wrap rounded-2xl bg-muted px-4 py-2 text-sm`,children:r||(0,L.jsx)(Ew,{className:`h-4 w-4 animate-spin opacity-60`})})}),f(d)]}),(0,L.jsx)(`div`,{ref:l})]})}function DK({disabled:e,onSend:t}){let[n,r]=(0,_.useState)(``),i=()=>{let i=n.trim();!i||e||(t(i),r(``))};return(0,L.jsxs)(`div`,{className:`border-t p-3`,children:[(0,L.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,L.jsx)(TD,{value:n,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),i())},placeholder:`e.g. Make the weekend message a bit warmer and mention we reply Monday morning`,rows:2,className:`max-h-40 min-h-[44px] resize-none`}),(0,L.jsx)(W,{onClick:i,disabled:e||!n.trim(),size:`icon`,children:e?(0,L.jsx)(Ew,{className:`h-4 w-4 animate-spin`}):(0,L.jsx)(eT,{className:`h-4 w-4`})})]}),(0,L.jsx)(`p`,{className:`mt-1 text-[11px] text-muted-foreground`,children:`Enter to send · Shift+Enter for a new line`})]})}function OK(){let e=bK(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(null);(0,_.useEffect)(()=>{H(`/api/config-chat/catalog`).then(e=>n(e.data)).catch(()=>{})},[]);let a=(0,_.useMemo)(()=>{let e=new Map(t.map(e=>[`${e.category}/${e.key}`,e.label]));return(t,n)=>e.get(`${t}/${n}`)??n},[t]),o=async(e,t)=>{i(e);try{await t(e)}finally{i(null)}};return(0,L.jsxs)(`div`,{className:`flex h-[calc(100vh-15rem)] min-h-[500px] overflow-hidden rounded-lg border`,children:[(0,L.jsx)(SK,{sessions:e.sessions,activeId:e.activeId,onSelect:e.selectSession,onNew:e.newChat,onRename:e.renameSession,onDelete:e.deleteSession}),(0,L.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,L.jsx)(EK,{messages:e.messages,proposals:e.proposals,liveActive:e.liveActive,liveText:e.liveText,labelFor:a,busyId:r,onApprove:t=>o(t,e.approve),onReject:t=>o(t,e.reject),onRevert:t=>o(t,e.revert)}),(0,L.jsx)(DK,{disabled:e.streaming,onSend:e.sendMessage})]})]})}var kK=new Set([`agent`,`assignment`,`group_intro`,`agent_brief`,`widget`,`auto_notes`]),AK=new Set([`agent`,`assignment`]),jK={article_author:`Article Author`,stacked_general:`Stacked General Page`,client_needs:`Client Needs Filled`,budget_in_needs:`Budget in Needs Text`,action_needed:`Action Needed`,agent_assigned:`Agent Assigned`,budget_specified:`Budget Specified (Form)`,location_preference:`Location Preference`,urgent_timeline:`Urgent Timeline`,has_timeline:`Has Any Timeline`,buyer_with_type:`Buyer with Property Type`,not_working_with_agent:`Not Working with Agent`},MK=`Hi, I'm interested in buying a condo in Singapore`,NK={"agent/master_prompt":`The single master prompt that governs the AI's entire behavior â voice, flow from outreach through qualification to consent, and which tools to call. Edits here change the whole conversation experience.`,"knowledge_base/min_similarity":`Minimum cosine similarity (0â1) for a chunk to be returned by search_knowledge_base. Higher = stricter, fewer false positives; lower = more recall but noisier. Default 0.35.`,"outreach/reply_delay_ms":`Delay (ms) before sending AI replies. 0 = instant. Was previously 2000 to feel human â now disabled by default.`,"outreach/weekend_message_template":`Sent to leads that come in between Sat 00:00 SGT and Mon 08:00 SGT, when initial outreach is paused (Joey doesn't work weekends). Monday 08:00 cron then runs normal outreach. Tokens: {{first_name}}, {{name}}.`,"outreach/holiday_message_template":`Sent to leads that come in on a Singapore public holiday (or pre-08:00 SGT the next working day). Same flow as the weekend template but worded for a workday PH. Tokens: {{first_name}}, {{name}}.`,"outreach/sg_public_holidays":`JSON array of ISO dates (e.g. ["2026-02-17", "2026-02-18"]) on which the AI pauses, same as a weekend. Paste the official MOM list each year; include in-lieu observances when a PH falls on a Sunday. Seed covers fixed-date holidays through 2027.`,"agent_pa/weekly_digest_per_lead_system_prompt":`System prompt for the per-lead one-line entry in the Monday
153weekly digest. AI may escalate the silence-based baseline tier but never downgrade it.`,"agent_pa/weekly_digest_activity_window_weeks":`Lookback window (weeks). Leads with no group activity inside this window are excluded from the digest.`,"agent_pa/weekly_digest_tier_yellow_min_days":`Days of group silence before a lead's baseline tier flips green â yellow.`,"agent_pa/weekly_digest_tier_red_min_days":`Days of group silence before a lead's baseline tier flips yellow â red.`,"agent_pa/nudge_system_prompt":`System prompt for generating suggested follow-up messages when conversations go silent.`,"agent_pa/silence_threshold_hours":`Hours of silence before the system nudges the agent with a suggested follow-up.`,"agent_pa/escalation_threshold_hours":`Hours of silence before escalating to admin (after nudge was already sent).`,"agent_pa/admin_phone":`Phone number that receives escalation alerts when agents are unresponsive.`},PK={"agent/master_prompt":`Master Prompt`,"group_intro/system_prompt":`Group Handoff Intro`,"agent_brief/system_prompt":`Consultant DM Brief`,"outreach/weekend_message_template":`Weekend Holding Message`,"outreach/holiday_message_template":`Public Holiday Holding Message`,"outreach/sg_public_holidays":`Singapore Public Holiday Dates`};function FK(){let[e,t]=(0,_.useState)(`chat`),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)({}),[o,s]=(0,_.useState)({}),[c,l]=(0,_.useState)({}),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)(``),[m,h]=(0,_.useState)([]),[g,v]=(0,_.useState)(``),[y,b]=(0,_.useState)(!1),[x,S]=(0,_.useState)(!1),C=(0,_.useRef)(null),[w,T]=(0,_.useState)(``),[E,D]=(0,_.useState)(``),[O,k]=(0,_.useState)(``),[A,j]=(0,_.useState)({leadName:``,source:``,questionnaireData:``}),[M,ee]=(0,_.useState)(!1),[N,P]=(0,_.useState)(null),[F,I]=(0,_.useState)(!1),[te,ne]=(0,_.useState)(!1),[re,ie]=(0,_.useState)(null),ae=(0,_.useCallback)(async(e,t)=>{I(!0),ne(!0),ie(null);try{let n=await H(`/api/ai-config/compare`,{method:`POST`,body:JSON.stringify({configId:e.id,testInput:MK,modifiedPrompt:t})});ie({current:n.data.current,modified:n.data.modified,configLabel:e.description||e.key.replace(/_/g,` `)})}catch(e){console.error(`[ai-training] compare failed:`,e),z.error(`Failed to run comparison`),I(!1)}finally{ne(!1)}},[]);(0,_.useEffect)(()=>{H(`/api/ai-config`).then(e=>{let t=e.data??[];r(t);let n={};for(let e of t)n[e.id]=e.value;a(n)}).catch(e=>{console.error(`[ai-training] fetch config failed:`,e),z.error(`Failed to load AI config`)})},[]);let oe=async e=>{let t=e.value,n=kK.has(e.category),a=n?(o[e.id]??``).trim():``;l(t=>({...t,[e.id]:!0}));try{let o=await H(`/api/ai-config/${e.id}`,{method:`PUT`,body:JSON.stringify({value:i[e.id],...a?{notes:a}:{}})}),c={...e,value:i[e.id],updatedAt:o.data.updatedAt,updatedBy:o.data.updatedBy,currentVersion:o.data.currentVersion??e.currentVersion};r(t=>t.map(t=>t.id===e.id?c:t)),n&&s(t=>({...t,[e.id]:``}));let l=o.data.newVersionCreated?`Saved as v${o.data.currentVersion}`:`Prompt saved`,u=AK.has(e.category);z.success(u?`${l}! Want to see how the AI response changed?`:`${l}!`,{...u&&{action:{label:`Compare`,onClick:()=>ae(c,t)}},duration:8e3})}catch(e){console.error(`[ai-training] save config failed:`,e),z.error(`Failed to save config`)}finally{l(t=>({...t,[e.id]:!1}))}},se=(e,t)=>{r(n=>n.map(n=>n.id===e?{...n,value:t,updatedAt:new Date().toISOString()}:n)),a(n=>({...n,[e]:t})),s(t=>({...t,[e]:``}))};(0,_.useEffect)(()=>{C.current?.scrollIntoView({behavior:`smooth`})},[m,y]);let ce=n,le=n.find(e=>e.id===u),ue=le?f!==le.value:!1,de=e=>{let t=n.find(t=>t.id===e);t&&(d(e),p(t.value),h([]),v(``),S(!1))},fe=()=>{le&&p(le.value)},pe=()=>{h([]),v(``)},me=async()=>{let e=g.trim();if(!e||!f||y)return;let t={role:`user`,content:e},n=[...m,t];h(n),v(``),b(!0);try{let e=await H(`/api/ai-config/test`,{method:`POST`,body:JSON.stringify({prompt:f,messages:n})});h(t=>[...t,{role:`assistant`,content:e.data.response}])}catch{h(e=>[...e,{role:`assistant`,content:`[Error: test failed]`}])}finally{b(!1)}},he=n.find(e=>e.id===w),ge=e=>{let t=n.find(t=>t.id===e);t&&(T(e),D(t.value),P(null))},_e=async()=>
153{if(!(!w||!O.trim()||!E.trim()||M)){ee(!0),P(null);try{let e=A.leadName||A.source||A.questionnaireData?A:void 0;P((await H(`/api/ai-config/compare`,{method:`POST`,body:JSON.stringify({configId:w,testInput:O.trim(),modifiedPrompt:E,context:e})})).data)}catch{z.error(`Comparison failed`)}finally{ee(!1)}}},ve=e=>n.filter(t=>t.category===e),ye=e=>i[e.id]!==e.value;return(0,L.jsxs)(`div`,{className:`space-y-6`,children:[(0,L.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`AI & Settings`}),(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e===`chat`?`Chat with the assistant to update the AI's prompts and message templates`:`Configure AI prompts, message templates, and operator shortcuts`})]}),(0,L.jsxs)(`div`,{className:`inline-flex shrink-0 rounded-md border p-0.5`,children:[(0,L.jsx)(W,{variant:e===`chat`?`secondary`:`ghost`,size:`sm`,onClick:()=>t(`chat`),children:`Chat`}),(0,L.jsx)(W,{variant:e===`advanced`?`secondary`:`ghost`,size:`sm`,onClick:()=>t(`advanced`),children:`Advanced`})]})]}),e===`chat`&&(0,L.jsx)(OK,{}),e===`advanced`&&(0,L.jsxs)(KL,{defaultValue:`agent`,children:[(0,L.jsxs)(qL,{children:[(0,L.jsx)(JL,{value:`agent`,children:`Agent`}),(0,L.jsx)(JL,{value:`assignment`,children:`Assignment`}),(0,L.jsx)(JL,{value:`outreach`,children:`Outreach Timing`}),(0,L.jsx)(JL,{value:`agent_pa`,children:`Agent PA`}),(0,L.jsx)(JL,{value:`scheduling`,children:`Scheduling`}),(0,L.jsx)(JL,{value:`lead_scoring`,children:`Lead Scoring`}),(0,L.jsx)(JL,{value:`test`,children:`Test Prompt`}),(0,L.jsx)(JL,{value:`compare`,children:`Compare Prompts`}),(0,L.jsx)(JL,{value:`macros`,children:`Macros`}),(0,L.jsx)(JL,{value:`wa_templates`,children:`WhatsApp Templates`})]}),(0,L.jsxs)(YL,{value:`agent`,className:`space-y-4`,children:[(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Prompts controlling the AI agent's lead-facing conversation and the one-shot messages generated when a consultant is handed off.`}),[...ve(`agent`),...ve(`group_intro`),...ve(`agent_brief`)].map(e=>(0,L.jsx)(zK,{entry:e,value:i[e.id]??``,onChange:t=>a(n=>({...n,[e.id]:t})),onSave:()=>oe(e),saving:c[e.id],changed:ye(e),versionable:!0,notes:o[e.id]??``,onNotesChange:t=>s(n=>({...n,[e.id]:t})),onRestored:t=>se(e.id,t)},e.id))]}),(0,L.jsxs)(YL,{value:`assignment`,className:`space-y-4`,children:[(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`The system prompt below controls how the AI assigns agents to qualified leads.`}),ve(`assignment`).map(e=>(0,L.jsx)(zK,{entry:e,value:i[e.id]??``,onChange:t=>a(n=>({...n,[e.id]:t})),onSave:()=>oe(e),saving:c[e.id],changed:ye(e),versionable:!0,notes:o[e.id]??``,onNotesChange:t=>s(n=>({...n,[e.id]:t})),onRestored:t=>se(e.id,t)},e.id))]}),(0,L.jsxs)(YL,{value:`outreach`,className:`space-y-4`,children:[(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Timing knobs for outreach replies. Opener and follow-up message wording now lives in the Agent tab â the master prompt generates them contextually per lead, no static templates.`}),(0,L.jsx)(IK,{}),(()=>{let e=ve(`outreach`).filter(e=>e.key===`reply_delay_ms`);return e.length===0?null:(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{className:`pb-3`,children:[(0,L.jsx)(ND,{className:`text-base`,children:`Response Timing`}),(0,L.jsx)(PD,{children:`Control how quickly the AI replies to make conversations feel more natural`})]}),(0,L.jsx)(q,{className:`space-y-4`,children:e.map(e=>{let t=NK[`${e.category}/${e.key}`];return(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(Z,{htmlFor:`timing-${e.id}`,children:e.description||e.key.replace(/_/g,` `)}),t&&(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground/70 italic`,children:t}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(G,{id:`timing-${e.id}`,type:`number`,min:0,step:500,value:i[e.id]??``,onChange:t=>a(n=>({...n,[e.id]:t.target.value})),className:`w-32 font-mono text-sm`}),(0,L.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:`ms`}),(0,L.jsx)(W,{size:`sm`,disabled:c[e.id]||!ye(e),onClick:()=>oe(e),className:`ml-auto`,children:c[e.id]?`Saving...`:`Save`})]}),(0,L.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Last updated: `,new Date(e.updatedAt).toLocaleStr
153ing(),e.updatedBy&&` by ${e.updatedBy}`]})]},e.id)})})]})})(),ve(`outreach`).filter(e=>e.key!==`reply_delay_ms`&&e.key!==`sg_only_enabled`).map(e=>(0,L.jsx)(zK,{entry:e,value:i[e.id]??``,onChange:t=>a(n=>({...n,[e.id]:t})),onSave:()=>oe(e),saving:c[e.id],changed:ye(e)},e.id))]}),(0,L.jsxs)(YL,{value:`agent_pa`,className:`space-y-4`,children:[(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Configure prompts and thresholds for the Agent PA system â weekly digest, silence nudges, and escalation settings.`}),(0,L.jsx)(WK,{}),ve(`agent_pa`).map(e=>(0,L.jsx)(zK,{entry:e,value:i[e.id]??``,onChange:t=>a(n=>({...n,[e.id]:t})),onSave:()=>oe(e),saving:c[e.id],changed:ye(e)},e.id))]}),(0,L.jsx)(YL,{value:`scheduling`,className:`space-y-4`,children:(0,L.jsx)(RK,{})}),(0,L.jsxs)(YL,{value:`lead_scoring`,className:`space-y-4`,children:[(0,L.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Configure how leads are scored for warmth. Each signal adds points when detected â the total score determines whether a lead is`,` `,(0,L.jsx)(X,{variant:`outline`,className:`text-xs font-normal`,children:`hot`}),`,`,` `,(0,L.jsx)(X,{variant:`outline`,className:`text-xs font-normal`,children:`warm`}),`, or`,` `,(0,L.jsx)(X,{variant:`outline`,className:`text-xs font-normal`,children:`cold`}),`.`]}),(0,L.jsx)(rK,{children:(0,L.jsxs)(K,{children:[(0,L.jsx)(iK,{asChild:!0,children:(0,L.jsx)(MD,{className:`pb-3 cursor-pointer select-none group`,children:(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(ND,{className:`text-base`,children:`How Scoring Works`}),(0,L.jsx)(PD,{children:`Each lead is assigned points based on the signals below. The total score determines the warmth level.`})]}),(0,L.jsx)(zC,{className:`h-4 w-4 text-muted-foreground transition-transform group-data-[state=closed]:-rotate-90`})]})})}),(0,L.jsx)(aK,{children:(0,L.jsxs)(q,{className:`space-y-4 pt-0`,children:[(0,L.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border p-3`,children:[(0,L.jsx)(dw,{className:`h-5 w-5 text-red-500 shrink-0`}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`p`,{className:`text-sm font-medium`,children:`Hot`}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Score ⥠5 points`})]})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border p-3`,children:[(0,L.jsx)(hT,{className:`h-5 w-5 text-amber-500 shrink-0`}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`p`,{className:`text-sm font-medium`,children:`Warm`}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Score ⥠2 points`})]})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border p-3`,children:[(0,L.jsx)(cT,{className:`h-5 w-5 text-blue-500 shrink-0`}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`p`,{className:`text-sm font-medium`,children:`Cold`}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Score < 2 points`})]})]})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`h4`,{className:`text-sm font-medium mb-2`,children:`Scoring Signals`}),(0,L.jsx)(`div`,{className:`rounded-lg border overflow-hidden`,children:(0,L.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,L.jsx)(`thead`,{children:(0,L.jsxs)(`tr`,{className:`border-b bg-muted/50`,children:[(0,L.jsx)(`th`,{className:`text-left p-3 font-medium`,children:`Signal`}),(0,L.jsx)(`th`,{className:`text-center p-3 font-medium w-20`,children:`Points`}),(0,L.jsx)(`th`,{className:`text-left p-3 font-medium`,children:`Condition`})]})}),(0,L.jsxs)(`tbody`,{className:`divide-y`,children:[(0,L.jsxs)(`tr`,{children:[(0,L.jsx)(`td`,{className:`p-3 font-medium`,children:`Article source`}),(0,L.jsx)(`td`,{className:`p-3 text-center`,children:(0,L.jsx)(X,{variant:`default`,children:`+3`})}),(0,L.jsx)(`td`,{className:`p-3 text-muted-foreground`,children:`Lead came from a specific author's article (not "Stacked" or "No Signup Page")`})]}),(0,L.jsxs)(`tr`,{children:[(0,L.jsx)(`td`,{className:`p-3 font-medium`,children:`Stacked general page`}),(0,L.jsx)(`td`,{className:`p-3 text-center`,children:(0,L.jsx)(X,{variant:`secondary`,children:`+1`})}),(0,L.jsx)(`td`,{className:`p-3 text-muted-foreground`,children:`Lead came from the general Stacked page`})]}),(0,L.jsxs)(`tr`,{children:[(0,L.jsx)(`td`,{className:`p-3 font-medium`,children:`Client needs provided`}),(0,L.jsx)(`td`,{className:`p-3 text-center`,children:(0,L.jsx)(X,{variant:`default`,children:`+2`})}),(0,L.jsx)(`td`,{className:`p-3 text-muted-foreground`,children:`Lead filled in their property needs/requirements`})]}),(0,L.jsxs)(`tr`,{children:[(0,L.jsx)(`td`,{className:`p-3 font-medium`,children:`Budget mentioned`}),(0,L.jsx)(`td`,{className:`p-3 text-center`,children:(0,L.jsx)(X,{variant:`secondary`,children:`+1`})}),(0,L.jsx)(`td`,{className:`p-3 text-muted-foreground`,children:`Budget amount or keyword found in client needs text`})]}),(0,L.jsxs)(`tr`,{children:[(0,L.jsx)(`td`,{className:`p-3 font-medium`,children:`Action needed`}),(0,L.jsx)(`td`,{className:`p-3 text-center`,children:(0,L.jsx)(X,{variant:`secondary`,children:`+1`})}),(0,L.jsx)(`td`,{className:`p-3 text-muted-foreground`,children:`Action needed field is set
153(and not "None")`})]}),(0,L.jsxs)(`tr`,{children:[(0,L.jsx)(`td`,{className:`p-3 font-medium`,children:`Agent assigned`}),(0,L.jsx)(`td`,{className:`p-3 text-center`,children:(0,L.jsx)(X,{variant:`secondary`,children:`+1`})}),(0,L.jsx)(`td`,{className:`p-3 text-muted-foreground`,children:`Lead already has an assigned agent (further in pipeline)`})]}),(0,L.jsxs)(`tr`,{children:[(0,L.jsx)(`td`,{className:`p-3 font-medium`,children:`Budget specified (form)`}),(0,L.jsx)(`td`,{className:`p-3 text-center`,children:(0,L.jsx)(X,{variant:`default`,children:`+2`})}),(0,L.jsx)(`td`,{className:`p-3 text-muted-foreground`,children:`Lead provided a specific budget via the lead database form`})]}),(0,L.jsxs)(`tr`,{children:[(0,L.jsx)(`td`,{className:`p-3 font-medium`,children:`Location preference`}),(0,L.jsx)(`td`,{className:`p-3 text-center`,children:(0,L.jsx)(X,{variant:`secondary`,children:`+1`})}),(0,L.jsx)(`td`,{className:`p-3 text-muted-foreground`,children:`Lead has a preferred location/district`})]}),(0,L.jsxs)(`tr`,{children:[(0,L.jsx)(`td`,{className:`p-3 font-medium`,children:`Urgent timeline`}),(0,L.jsx)(`td`,{className:`p-3 text-center`,children:(0,L.jsx)(X,{variant:`default`,children:`+2`})}),(0,L.jsx)(`td`,{className:`p-3 text-muted-foreground`,children:`Buying timeline is "0-3 months", "1-3 months", "immediate", "ASAP", or "within"`})]}),(0,L.jsxs)(`tr`,{children:[(0,L.jsx)(`td`,{className:`p-3 font-medium`,children:`Has buying timeline`}),(0,L.jsx)(`td`,{className:`p-3 text-center`,children:(0,L.jsx)(X,{variant:`secondary`,children:`+1`})}),(0,L.jsx)(`td`,{className:`p-3 text-muted-foreground`,children:`Any buying timeline specified (non-urgent, excluding "unknown")`})]}),(0,L.jsxs)(`tr`,{children:[(0,L.jsx)(`td`,{className:`p-3 font-medium`,children:`Buyer with property type`}),(0,L.jsx)(`td`,{className:`p-3 text-center`,children:(0,L.jsx)(X,{variant:`secondary`,children:`+1`})}),(0,L.jsx)(`td`,{className:`p-3 text-muted-foreground`,children:`Lead is a buyer and specified a property type`})]}),(0,L.jsxs)(`tr`,{children:[(0,L.jsx)(`td`,{className:`p-3 font-medium`,children:`Not working with agent`}),(0,L.jsx)(`td`,{className:`p-3 text-center`,children:(0,L.jsx)(X,{variant:`secondary`,children:`+1`})}),(0,L.jsx)(`td`,{className:`p-3 text-muted-foreground`,children:`Lead is not currently working with another agent`})]})]})]})})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`h4`,{className:`text-sm font-medium mb-2`,children:`Automatic Cold Classification`}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground mb-2`,children:`Leads matching any of the following conditions are immediately classified as cold, regardless of their score:`}),(0,L.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,L.jsxs)(X,{variant:`outline`,className:`text-xs`,children:[(0,L.jsx)(cT,{className:`h-3 w-3 mr-1`}),`Status contains "not interested"`]}),(0,L.jsxs)(X,{variant:`outline`,className:`text-xs`,children:[(0,L.jsx)(cT,{className:`h-3 w-3 mr-1`}),`Status contains "no reply"`]}),(0,L.jsxs)(X,{variant:`outline`,className:`text-xs`,children:[(0,L.jsx)(cT,{className:`h-3 w-3 mr-1`}),`Stage contains "lost"`]})]})]}),(0,L.jsx)(`div`,{className:`rounded-lg bg-muted/50 p-3`,children:(0,L.jsxs)(`p`,{className:`text-sm`,children:[(0,L.jsx)(`span`,{className:`font-medium`,children:`Contact eligibility:`}),` `,`Only `,(0,L.jsx)(`span`,{className:`font-medium text-red-500`,children:`hot`}),` and`,` `,(0,L.jsx)(`span`,{className:`font-medium text-amber-500`,children:`warm`}),` leads proceed to automatic outreach.`,` `,(0,L.jsx)(`span`,{className:`font-medium text-blue-500`,children:`Cold`}),` leads are skipped.`]})})]})})]})}),ve(`lead_scoring`).map(e=>e.key===`weights`?(0,L.jsx)(BK,{entry:e,rawValue:i[e.id]??`{}`,onRawChange:t=>a(n=>({...n,[e.id]:t})),onSave:()=>oe(e),saving:c[e.id],changed:ye(e)},e.id):e.key===`thresholds`?(0,L.jsx)(VK,{entry:e,rawValue:i[e.id]??`{}`,onRawChange:t=>a(n=>({...n,[e.id]:t})),onSave:()=>oe(e),saving:c[e.id],changed:ye(e)},e.id):e.key===`skip_statuses`?(0,L.jsx)(HK,{entry:e,rawValue:i[e.id]??`[]`,onRawChange:t=>a(n=>({...n,[e.id]:t})),onSave:()=>
153oe(e),saving:c[e.id],changed:ye(e)},e.id):(0,L.jsx)(zK,{entry:e,value:i[e.id]??``,onChange:t=>a(n=>({...n,[e.id]:t})),onSave:()=>oe(e),saving:c[e.id],changed:ye(e)},e.id))]}),(0,L.jsx)(aj,{open:F,onOpenChange:I,children:(0,L.jsxs)(lj,{className:`max-w-3xl max-h-[80vh] overflow-y-auto`,children:[(0,L.jsxs)(uj,{children:[(0,L.jsx)(fj,{children:`AI Response Comparison`}),(0,L.jsx)(pj,{children:re?`Comparing responses for "${re.configLabel}" with test input: "${MK}"`:`Running comparison...`})]}),te&&(0,L.jsxs)(`div`,{className:`flex items-center justify-center py-12 gap-2 text-muted-foreground`,children:[(0,L.jsx)(Ew,{className:`h-5 w-5 animate-spin`}),(0,L.jsx)(`span`,{children:`Running both prompts through AI...`})]}),re&&(0,L.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsx)(`h4`,{className:`text-sm font-medium`,children:`Previous Prompt`}),(0,L.jsxs)(X,{variant:`outline`,className:`text-xs`,children:[re.modified.responseTimeMs,`ms`]})]}),(0,L.jsx)(`div`,{className:`rounded-md border bg-muted/30 p-3 text-sm whitespace-pre-wrap min-h-[120px]`,children:re.modified.text}),re.modified.classification&&(0,L.jsxs)(`div`,{className:`rounded-md border p-2`,children:[(0,L.jsx)(`p`,{className:`text-xs font-medium mb-1`,children:`Classification`}),(0,L.jsx)(`pre`,{className:`text-xs text-muted-foreground overflow-x-auto`,children:JSON.stringify(re.modified.classification,null,2)})]})]}),(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsx)(`h4`,{className:`text-sm font-medium`,children:`Current Prompt`}),(0,L.jsxs)(X,{variant:`outline`,className:`text-xs`,children:[re.current.responseTimeMs,`ms`]})]}),(0,L.jsx)(`div`,{className:`rounded-md border bg-muted/30 p-3 text-sm whitespace-pre-wrap min-h-[120px]`,children:re.current.text}),re.current.classification&&(0,L.jsxs)(`div`,{className:`rounded-md border p-2`,children:[(0,L.jsx)(`p`,{className:`text-xs font-medium mb-1`,children:`Classification`}),(0,L.jsx)(`pre`,{className:`text-xs text-muted-foreground overflow-x-auto`,children:JSON.stringify(re.current.classification,null,2)})]})]})]})]})}),(0,L.jsx)(YL,{value:`test`,className:`space-y-4`,children:(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{className:`pb-3`,children:(0,L.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(ND,{className:`text-base`,children:`Test Prompt`}),(0,L.jsx)(PD,{children:`Test your saved prompts against GPT-4o without sending to WhatsApp`})]}),(0,L.jsxs)(`div`,{className:`flex gap-2`,children:[(0,L.jsxs)(W,{variant:`outline`,size:`sm`,onClick:fe,disabled:!ue,children:[(0,L.jsx)(Xw,{className:`h-3.5 w-3.5 mr-1.5`}),`Reset to Saved`]}),(0,L.jsxs)(W,{variant:`outline`,size:`sm`,onClick:pe,disabled:m.length===0&&!g,children:[(0,L.jsx)(vT,{className:`h-3.5 w-3.5 mr-1.5`}),`Clear Session`]})]})]})}),(0,L.jsxs)(q,{className:`space-y-4`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(Z,{className:`mb-1.5 block`,children:`Select a prompt to test`}),(0,L.jsxs)(wk,{value:u,onValueChange:de,children:[(0,L.jsx)(Dk,{className:`w-full`,children:(0,L.jsx)(Ek,{placeholder:`Choose a prompt...`})}),(0,L.jsx)(Ok,{children:[{cat:`classification`,label:`Classification`},{cat:`qualification`,label:`Qualification`},{cat:`outreach`,label:`Outreach & Follow-ups`},{cat:`assignment`,label:`Assignment`},{cat:`agent_pa`,label:`Agent PA`}].map(({cat:e,label:t})=>{let n=ce.filter(t=>t.category===e);return n.length===0?null:(0,L.jsxs)(Tk,{children:[(0,L.jsx)(kk,{children:t}),n.map(e=>(0,L.jsx)(Ak,{value:e.id,children:e.description||e.key.replace(/_/g,` `)},e.id))]},e)})})]})]}),u&&(0,L.jsxs)(`div`,{className:`rounded-md border`,children:[(0,L.jsxs)(`button`,{type:`button`,className:`flex w-full items-center justify-between px-3 py-2 text-sm font-medium hover:bg-muted/50 transition-colors`,onClick:()=>S(!x),children:[(0,L.jsxs)(`span`,{className:`flex items-center gap-2`,children:[x?(0,L.jsx)(VC,{className:`h-4 w-4`}):(0,L.jsx)(zC,{className:`h-4 w-4`}),`System Prompt`,ue&&(0,L.jsx)(X,{variant:`secondary`,className:`text-xs`,children:`Modified`})]}),(0,L.jsxs)(X,{variant:`outline`,className:`text-xs font-normal`,children:[le?.category,`/`,le?.key]})]}),!x&&(0,L.jsxs)(`div`,{className:`border-t px-3 py-2`,children:[(0,L.jsx)(TD,{value:f,onChange:e=>p(e.target.value),rows:Math.min(10,Math.max(4,f.split(` 154`).length)),className:`font-mono text-sm`}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:`Edits here are temporary and won't be saved.`})]})]}),u&&(0,L.jsxs)(`div`,{className:`rounded-md border flex flex-col`,style:{height:400},children:[(0,L.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-3`,children:[m.length===0&&!y&&(0,L.jsx)(`div`,{className:`flex items-center justify-center h-full text-sm text-muted-foreground`,children:`Send a message to start testing this prompt`}),m.map((e,t)=>(0,L.jsx)(`div`,{className:`flex ${e.role===`user`?`justify-end`:`justify-start`}`,children:(0,L.jsx)(`div`,{className:`max-w-[80%] rounded-lg px-3 py-2 text-sm whitespace-pre-wrap ${e.role===`user`?`bg-primary text-primary-foreground`:`bg-muted`}`,children:e.content})},t)),y&&(0,L.jsx)(`div`,{className:`flex justify-start`,children:(0,L.jsx)(`div`,{className:`bg-muted rounded-lg px-3 py-2 text-sm text-muted-foreground`,children:`Thinking...`})}),(0,L.jsx)(`div`,{ref:C})]}),(0,L.jsx)(`div`,{className:`border-t p-3`,children:(0,L.jsxs)(`form`,{className:`flex gap-2`,onSubmit:e=>{e.preventDefault(),me()},children:[(0,L.jsx)(G,{value:g,onChange:e=>v(e.target.value),placeholder:`Type a message...`,disabled:y,className:`flex-1`}),(0,L.jsx)(W,{type:`submit`,size:`sm`,disabled:y||!g.trim(),children:(0,L.jsx)(eT,{className:`h-4 w-4`})})]})})]})]})]})}),(0,L.jsx)(YL,{value:`compare`,className:`space-y-4`,children:(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{className:`pb-3`,children:[(0,L.jsxs)(ND,{className:`text-base flex items-center gap-2`,children:[(0,L.jsx)(fT,{className:`h-4 w-4`}),`Compare Prompts`]}),(0,L.jsx)(PD,{children:`Run the same input through the current prompt and a modified version side by side`})]}),(0,L.jsxs)(q,{className:`space-y-4`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(Z,{className:`mb-1.5 block`,children:`Select prompt to compare`}),(0,L.jsxs)(wk,{value:w,onValueChange:ge,children:[(0,L.jsx)(Dk,{className:`w-full`,children:(0,L.jsx)(Ek,{placeholder:`Choose a prompt...`})}),(0,L.jsx)(Ok,{children:[{cat:`classification`,label:`Classification`},{cat:`qualification`,label:`Qualification`},{cat:`outreach`,label:`Outreach & Follow-ups`},{cat:`assignment`,label:`Assignment`},{cat:`agent_pa`,label:`Agent PA`}].map(({cat:e,label:t})=>{let r=n.filter(t=>t.category===e);return r.length===0?null:(0,L.jsxs)(Tk,{children:[(0,L.jsx)(kk,{children:t}),r.map(e=>(0,L.jsx)(Ak,{value:e.id,children:e.description||e.key.replace(/_/g,` `)},e.id))]},e)})})]})]}),w&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(Z,{className:`mb-1.5 block`,children:`Test message (what a lead would say)`}),(0,L.jsx)(TD,{value:O,onChange:e=>k(e.target.value),placeholder:`e.g. Hi, I'm looking to buy a 3-bedroom condo in Orchard area...`,rows:2})]}),(0,L.jsxs)(`details`,{className:`rounded-md border`,children:[(0,L.jsx)(`summary`,{className:`px-3 py-2 text-sm font-medium cursor-pointer hover:bg-muted/50 transition-colors`,children:`Context fields (optional)`}),(0,L.jsxs)(`div`,{className:`border-t px-3 py-3 grid grid-cols-1 md:grid-cols-3 gap-3`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(Z,{className:`mb-1 block text-xs`,children:`Lead name`}),(0,L.jsx)(G,{value:A.leadName,onChange:e=>j(t=>({...t,leadName:e.target.value})),placeholder:`John`})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(Z,{className:`mb-1 block text-xs`,children:`Source`}
154),(0,L.jsx)(G,{value:A.source,onChange:e=>j(t=>({...t,source:e.target.value})),placeholder:`StackedHomes article`})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(Z,{className:`mb-1 block text-xs`,children:`Questionnaire data`}),(0,L.jsx)(G,{value:A.questionnaireData,onChange:e=>j(t=>({...t,questionnaireData:e.target.value})),placeholder:`{"budget":"1.5M","type":"condo"}`})]})]})]}),(0,L.jsx)(JT,{}),(0,L.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,L.jsx)(Z,{children:`Current prompt`}),(0,L.jsxs)(X,{variant:`outline`,className:`text-xs`,children:[he?.category,`/`,he?.key]})]}),(0,L.jsx)(TD,{value:he?.value??``,readOnly:!0,rows:8,className:`font-mono text-sm bg-muted/30 cursor-default`})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,L.jsx)(Z,{children:`Modified prompt`}),E!==(he?.value??``)&&(0,L.jsx)(X,{variant:`secondary`,className:`text-xs`,children:`Edited`})]}),(0,L.jsx)(TD,{value:E,onChange:e=>D(e.target.value),rows:8,className:`font-mono text-sm`})]})]}),(0,L.jsx)(`div`,{className:`flex justify-center`,children:(0,L.jsx)(W,{onClick:_e,disabled:M||!O.trim()||!E.trim(),className:`min-w-[160px]`,children:M?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(Ew,{className:`h-4 w-4 mr-2 animate-spin`}),`Comparing...`]}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(fT,{className:`h-4 w-4 mr-2`}),`Compare`]})})}),N&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(JT,{}),(0,L.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[(0,L.jsx)(UK,{label:`Current`,result:N.current,variant:`outline`}),(0,L.jsx)(UK,{label:`Modified`,result:N.modified,variant:`default`})]})]})]})]})]})}),(0,L.jsx)(YL,{value:`macros`,className:`space-y-4`,children:(0,L.jsx)(dK,{})}),(0,L.jsx)(YL,{value:`wa_templates`,className:`space-y-4`,children:(0,L.jsx)(yK,{})})]})]})}function IK(){let e=ri(),[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)(!0),[l,u]=(0,_.useState)(!1),d=(0,_.useCallback)(async()=>{try{let e=await H(`/api/ai-config/sg-gate`);n(e.data.enabled),i(e.data.updatedAt),o(e.data.updatedBy)}catch(e){z.error(e instanceof Error?e.message:`Failed to load SG-gate`)}finally{c(!1)}},[]);return(0,_.useEffect)(()=>{d()},[d]),(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{className:`pb-3`,children:[(0,L.jsx)(ND,{className:`text-base`,children:`Singapore-Only Mode`}),(0,L.jsx)(PD,{children:`When on, AI skips outreach, replies, and follow-ups for any lead whose phone number is not a valid Singapore number (+65). Non-SG leads are routed to manual handling. You can override this per-conversation in the inbox sidebar.`})]}),(0,L.jsxs)(q,{className:`space-y-3`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,L.jsx)(Z,{htmlFor:`sg-only-toggle`,className:`text-sm`,children:s?`Loadingâ¦`:t?`On â AI handles SG leads only`:`Off â AI handles all leads`}),(0,L.jsx)(Ck,{id:`sg-only-toggle`,checked:!!t,disabled:s||l,onCheckedChange:async r=>{if(l||t===null)return;let a=t;n(r),u(!0);try{let t=await H(`/api/ai-config/sg-gate`,{method:`PUT`,body:JSON.stringify({enabled:r})});i(t.data.updatedAt),o(t.data.updatedBy),e.invalidateQueries({queryKey:[`ai-config`,`sg-gate`]}),z.success(r?`Singapore-only mode enabled`:`Singapore-only mode disabled`)}catch(e){n(a),z.error(e instanceof Error?e.message:`Save failed`)}finally{u(!1)}}})]}),r&&(0,L.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Last updated: `,new Date(r).toLocaleString(),a&&` by ${a}`]})]})]})}var LK={intervals:[1,3,7],maxFollowups:3,qualificationTimeoutHours:48,qualificationLostHours:96,gracePeriodDays:3,mopFollowUpLeadTimeDays:60,mopDeferThresholdDays:90};function RK(){let e=ri(),[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(LK),[a,o]=(0,_.useState)(!0),[s,c]=(0,_.useState)(!1),[l,u]=(0,_.useState)(null),[d,f]=(0,_.useState)(null),p=(0,_.useCallback)(async()=>{try{let e=await H(`/api/ai-config/scheduling`),t={intervals:e.data.follow_up_intervals,maxFollowups:e.data.max_followups,qualificationTimeoutHours:e.data.qualification_timeout_hours,qualificationLostHours:e.data.qualification_lost_hours,gracePeriodDays:e.data.grace_peri
154od_days_before_lost,mopFollowUpLeadTimeDays:e.data.mop_followup_lead_time_days,mopDeferThresholdDays:e.data.mop_defer_threshold_days};n(t),i(t)}catch(e){z.error(e instanceof Error?e.message:`Failed to load scheduling config`)}finally{o(!1)}},[]);(0,_.useEffect)(()=>{p()},[p]);let m=r.intervals.length>=1&&r.intervals.length<=10&&r.intervals.every(e=>Number.isInteger(e)&&e>=1&&e<=180),h=Number.isInteger(r.maxFollowups)&&r.maxFollowups>=0&&r.maxFollowups<=20,g=Number.isInteger(r.qualificationTimeoutHours)&&r.qualificationTimeoutHours>=1&&r.qualificationTimeoutHours<=720,v=Number.isInteger(r.qualificationLostHours)&&r.qualificationLostHours>=1&&r.qualificationLostHours<=1440,y=Number.isInteger(r.gracePeriodDays)&&r.gracePeriodDays>=0&&r.gracePeriodDays<=90,b=Number.isInteger(r.mopFollowUpLeadTimeDays)&&r.mopFollowUpLeadTimeDays>=1&&r.mopFollowUpLeadTimeDays<=365,x=Number.isInteger(r.mopDeferThresholdDays)&&r.mopDeferThresholdDays>=1&&r.mopDeferThresholdDays<=730,S=r.qualificationLostHours>r.qualificationTimeoutHours,C=r.mopDeferThresholdDays>r.mopFollowUpLeadTimeDays,w=m&&h&&g&&v&&y&&b&&x&&S&&C,T=t!==null&&(JSON.stringify(r.intervals)!==JSON.stringify(t.intervals)||r.maxFollowups!==t.maxFollowups||r.qualificationTimeoutHours!==t.qualificationTimeoutHours||r.qualificationLostHours!==t.qualificationLostHours||r.gracePeriodDays!==t.gracePeriodDays||r.mopFollowUpLeadTimeDays!==t.mopFollowUpLeadTimeDays||r.mopDeferThresholdDays!==t.mopDeferThresholdDays),E=Math.min(r.maxFollowups,r.intervals.length),D=r.maxFollowups>r.intervals.length,O=(e,t)=>i(n=>({...n,intervals:n.intervals.map((n,r)=>r===e?t:n)})),k=e=>i(t=>({...t,intervals:t.intervals.filter((t,n)=>n!==e)}));return a?(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,L.jsx)(Ew,{className:`h-4 w-4 animate-spin`}),`Loading scheduling configâ¦`]}):(0,L.jsxs)(`div`,{className:`space-y-4`,children:[(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Configure the cadence at which the system follows up with non-responsive leads, and how long qualification waits before nudging or marking lost. Changes apply to new follow-ups scheduled after save â leads with an existing scheduled time keep their current send time.`}),(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{className:`pb-3`,children:[(0,L.jsx)(ND,{className:`text-base`,children:`Follow-ups`}),(0,L.jsx)(PD,{children:`Days between successive follow-ups, and the ceiling at which a lead is marked lost.`})]}),(0,L.jsxs)(q,{className:`space-y-4`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(Z,{className:`text-sm font-medium`,children:`Follow-up schedule`}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1 mb-2`,children:`Each row is one follow-up. The number is how many days after the previous step.`}),(0,L.jsx)(`div`,{className:`space-y-2`,children:r.intervals.map((e,t)=>(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsxs)(`span`,{className:`text-xs text-muted-foreground w-28 shrink-0`,children:[`Follow-up `,t+1]}),(0,L.jsx)(G,{type:`number`,min:1,max:180,step:1,value:e,onChange:e=>O(t,Number.parseInt(e.target.value,10)||0),className:`w-24 h-8 text-sm`}),(0,L.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`days after `,t===0?`initial contact`:`Follow-up ${t}`]}),(0,L.jsx)(W,{type:`button`,variant:`ghost`,size:`icon`,className:`h-7 w-7 ml-auto`,onClick:()=>k(t),disabled:r.intervals.length<=1,"aria-label":`Remove Follow-up ${t+1}`,children:(0,L.jsx)(FT,{className:`h-3.5 w-3.5`})})]},t))}),r.intervals.length<10&&(0,L.jsxs)(W,{type:`button`,variant:`outline`,size:`sm`,className:`mt-2 text-xs h-7`,onClick:()=>i(e=>({...e,intervals:[...e.intervals,7]})),children:[(0,L.jsx)(Gw,{className:`h-3 w-3 mr-1`}),`Add another follow-up`]}),!m&&(0,L.jsx)(`p`,{className:`text-xs text-destructive mt-2`,children:`Each interval must be a whole number of days between 1 and 180. List length 1â10.`})]}),(0,L.jsx)(JT,{}),(0,L.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`max-followups`,className:`text-sm`,children:`Max follow-ups (ceiling)`}),(0,L.jsx)(G,{id:`max-followups`,type:`number`,min:0,max:20,step:1,value:r.maxFollowups,onChange:e=>i(t=>({...t,maxFollowups:Number.parseInt(e.target.value,10)||0})),className:`h-8 text-sm w-32`}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Lead is marked lost when this count is reached, OR when the schedule above is exhausted â whichever comes first.`}),!h&&(0,L.jsx)(`p`,{className:`text-xs text-destructive`,children:`Whole number between 0 and 20.`})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`grace-period`,className:`text-sm`,children:`Grace window before marking lost (days)`}),(0,L.jsx)(G,{id:`grace-period`,type:`number`,min:0,max:90,step:1,value:r.gracePeriodDays,onChange:e=>i(t=>({...t,gracePeriodDays:Number.parseInt(e.target.value,10)||0})),className:`h-8 text-sm w-32`}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Days to wait after the final follow-up before marking the lead lost. Leaves a quiet window for a late reply.`}),!y&&(0,L.jsx)(`p`,{className:`text-xs text-destructive`,children:`Whole number between 0 and 90.`})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`mop-lead-time`,className:`text-sm`,children:`MOP re-engagement lead time (days)`}),(0,L.jsx)(G,{id:`mop-lead-time`,type:`number`,min:1,max:365,step:1,value:r.mopFollowUpLeadTimeDays,onChange:e=>i(t=>({...t,mopFollowUpLeadTimeDays:Number.parseInt(e.target.value,10)||0})),className:`h-8 text-sm w-32`}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`When a deferred lead is re-engaged, the message fires this many days before their MOP date (default 60 â 2 months).`}),!b&&(0,L.jsx)(`p`,{className:`text-xs text-destructive`,children:`Whole number between 1 and 365.`})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`mop-defer-threshold`,className:`text-sm`,children:`MOP defer threshold (days)`}),(0,L.jsx)(G,{id:`mop-defer-threshold`,type:`number`,min:1,max:730,step:1,value:r.mopDeferThresholdDays,onChange:e=>i(t=>({...t,mopDeferThresholdDays:Number.parseInt(e.target.value,10)||0})),className:`h-8 text-sm w-32`}),(0,L.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Only park leads whose MOP date is at least this many days away. Closer leads engage normally instead of deferring. Must be greater than the re-engagement lead time.`,C&&b&&x&&(0,L.jsxs)(L.Fragment,{children:[` `,`At the threshold, the re-engagement message arrives`,` `,(0,L.jsxs)(`strong`,{children:[r.mopDeferThresholdDays-r.mopFollowUpLeadTimeDays,` days`]}),` `,`after the initial defer.`]})]}),!x&&(0,L.jsx)(`p`,{className:`text-xs text-destructive`,children:`Whole number between 1 and 730.`}),x&&b&&!C&&(0,L.jsxs)(`p`,{className:`text-xs text-destructive`,children:[`Defer threshold must be greater than the re-engagement lead time (`,r.mopFollowUpLeadTimeDays,`d).`]})]})]}),D&&m&&(0,L.jsxs)(`div`,{className:`rounded-md bg-amber-50 border border-amber-200 px-3 py-2 text-xs text-amber-800`,children:[`Max is `,(0,L.jsx)(`strong`,{children:r.maxFollowups}),` but only`,` `,(0,L.jsx)(`strong`,{children:r.intervals.length}),` intervals defined â leads will be marked lost after follow-up `,E,`.`]})]})]}),(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{className:`pb-3`,children:[(0,L.jsx)(ND,{className:`text-base`,children:`Qualification`}),(0,L.jsx)(PD,{children:`How long the qualification flow waits before nudging a quiet lead, and before giving up entirely.`})]}),(0,L.jsxs)(q,{className:`space-y-4`,children:[(0,L.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`qual-timeout`,className:`text-sm`,children:`Nudge after (hours)`}),(0,L.jsx)(G,{id:`qual-timeout`,type:`number`,min:1,max:720,step:1,value:r.qualificationTimeoutHours,onChange:e=>i(t=>({...t,qualificationTimeoutHours:Number.parseInt(e.target.value,10)||0})),className:`h-8 text-sm w-32`}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Hours of silence during qualification before a nudge is sent.`}),!g&&(0,L.jsx)(`p`,{className:`text-xs text-destructive`,children:`Whole number between 1 and 720.`})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`qual-lost`,className:`text-sm`,children:`Mark lost after (hours)`}),(0,L.jsx)(G,{id:`qual-lost`,type:`number`,min:1,max:1440,step:1,value:r.qualificationLostHours,onChange:e=>i(t=>({...t,qualificationLostHours:Number.parseInt(e.target.value,10)||0})),className:`h-8 text-sm w-32`}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Hours of silence during qualification before the lead is marked lost.`}),!v&&(0,L.jsx)(`p`,{className:`text-xs text-destructive`,children:`Whole number between 1 and 1440.`})]})]}),!S&&v&&g&&(0,L.jsx)(`div`,{className:`rounded-md bg-destructive/10 border border-destructive/30 px-3 py-2 text-xs text-destructive`,children:`"Mark lost after" must be greater than "Nudge after".`})]})]}),(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-3 pt-1`,children:[(0,L.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:l&&(0,L.jsxs)(L.Fragment,{children:[`Last saved `,new Date(l).toLocaleStr
154ing(),d?` by ${d}`:``,`.`]})}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(W,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{t&&i(t)},disabled:!T||s,children:`Revert`}),(0,L.jsx)(W,{type:`button`,size:`sm`,onClick:async()=>{if(!(!w||!T)){c(!0);try{let t=await H(`/api/ai-config/scheduling`,{method:`PUT`,body:JSON.stringify({follow_up_intervals:r.intervals,max_followups:r.maxFollowups,qualification_timeout_hours:r.qualificationTimeoutHours,qualification_lost_hours:r.qualificationLostHours,grace_period_days_before_lost:r.gracePeriodDays,mop_followup_lead_time_days:r.mopFollowUpLeadTimeDays,mop_defer_threshold_days:r.mopDeferThresholdDays})});n(r),u(t.data.updatedAt),f(t.data.updatedBy),e.invalidateQueries({queryKey:[`ai-config`,`scheduling`]}),z.success(`Scheduling saved`)}catch(e){z.error(e instanceof Error?e.message:`Save failed`)}finally{c(!1)}}},disabled:!T||!w||s,children:s?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(Ew,{className:`h-3.5 w-3.5 mr-1.5 animate-spin`}),`Savingâ¦`]}):`Save Scheduling`})]})]})]})}function zK({entry:e,value:t,onChange:n,onSave:r,saving:i,changed:a,versionable:o,notes:s,onNotesChange:c,onRestored:l}){let u=t.length>100,d=`${e.category}/${e.key}`,f=NK[d],p=PK[d]??e.key.replace(/_/g,` `),m=e.description||p;return(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{className:`pb-3`,children:(0,L.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsxs)(ND,{className:`text-base flex items-center gap-2`,children:[p,o&&e.currentVersion!==void 0&&(0,L.jsxs)(X,{variant:`secondary`,className:`text-xs font-normal`,children:[`v`,e.currentVersion]})]}),e.description&&(0,L.jsx)(PD,{children:e.description}),f&&(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground/70 italic`,children:f})]}),(0,L.jsxs)(X,{variant:`outline`,className:`shrink-0 text-xs`,children:[e.category,`/`,e.key]})]})}),(0,L.jsxs)(q,{className:`space-y-3`,children:[u?(0,L.jsx)(TD,{value:t,onChange:e=>n(e.target.value),rows:o?Math.min(60,Math.max(12,t.split(` 155`).length)):Math.min(12,Math.max(3,t.split(` 156`).length)),className:`font-mono text-sm resize-y`}):(0,L.jsx)(G,{value:t,onChange:e=>n(e.target.value),className:`font-mono text-sm`}),o&&a&&c&&(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsx)(Z,{htmlFor:`notes-${e.id}`,className:`text-xs text-muted-foreground`,children:`What changed? (optional)`}),(0,L.jsx)(G,{id:`notes-${e.id}`,value:s??``,onChange:e=>c(e.target.value),placeholder:`e.g. Softened opener tone`,maxLength:500,className:`text-sm`})]}),(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,L.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Last updated: `,new Date(e.updatedAt).toLocaleString(),e.updatedBy&&` by ${e.updatedBy}`]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[o&&l&&(0,L.jsx)(sK,{configId:e.id,configLabel:m,onRestored:l}),(0,L.jsx)(W,{size:`sm`,disabled:i||!a,onClick:r,children:i?`Saving...`:`Save`})]})]})]})]})}function BK({entry:e,rawValue:t,onRawChange:n,onSave:r,saving:i,changed:a}){let o=(()=>{try{return JSON.parse(t)}catch{return{}}})(),s=(e,t)=>{let r={...o,[e]:t};n(JSON.stringify(r))};return(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{className:`pb-3`,children:(0,L.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsx)(ND,{className:`text-base`,children:`Signal Weights`}),(0,L.jsx)(PD,{children:e.description})]}),(0,L.jsxs)(X,{variant:`outline`,className:`shrink-0 text-xs`,children:[e.category,`/`,e.key]})]})}),(0,L.jsxs)(q,{className:`space-y-4`,children:[(0,L.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4`,children:Object.entries(jK).map(([e,t])=>(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`weight-${e}`,className:`text-sm`,children:t}),(0,L.jsx)(G,{id:`weight-${e}`,type:`number`,min:0,step:1,value:o[e]??0,onChange:t=>s(e,Number(t.target.value)||0),className:`font-mono text-sm`})]},e))}
156),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground/70 italic`,children:`Each signal adds its weight to the lead's total score when detected. Increase a weight to make that signal more important in scoring.`}),(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Last updated: `,new Date(e.updatedAt).toLocaleString(),e.updatedBy&&` by ${e.updatedBy}`]}),(0,L.jsx)(W,{size:`sm`,disabled:i||!a,onClick:r,children:i?`Saving...`:`Save`})]})]})]})}function VK({entry:e,rawValue:t,onRawChange:n,onSave:r,saving:i,changed:a}){let o=(()=>{try{return JSON.parse(t)}catch{return{hot:5,warm:2}}})(),s=(e,t)=>{let r={...o,[e]:t};n(JSON.stringify(r))};return(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{className:`pb-3`,children:(0,L.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsx)(ND,{className:`text-base`,children:`Warmth Thresholds`}),(0,L.jsx)(PD,{children:e.description})]}),(0,L.jsxs)(X,{variant:`outline`,className:`shrink-0 text-xs`,children:[e.category,`/`,e.key]})]})}),(0,L.jsxs)(q,{className:`space-y-4`,children:[(0,L.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-4`,children:[(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`threshold-hot`,className:`text-sm`,children:`Hot Threshold`}),(0,L.jsx)(G,{id:`threshold-hot`,type:`number`,min:0,step:1,value:o.hot,onChange:e=>s(`hot`,Number(e.target.value)||0),className:`font-mono text-sm`})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`threshold-warm`,className:`text-sm`,children:`Warm Threshold`}),(0,L.jsx)(G,{id:`threshold-warm`,type:`number`,min:0,step:1,value:o.warm,onChange:e=>s(`warm`,Number(e.target.value)||0),className:`font-mono text-sm`})]})]}),(0,L.jsxs)(`p`,{className:`text-xs text-muted-foreground/70 italic`,children:[`Score ⥠`,o.hot,` = hot, score ⥠`,o.warm,` = warm, below `,o.warm,` = cold. Hot threshold should be higher than warm.`]}),(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Last updated: `,new Date(e.updatedAt).toLocaleString(),e.updatedBy&&` by ${e.updatedBy}`]}),(0,L.jsx)(W,{size:`sm`,disabled:i||!a,onClick:r,children:i?`Saving...`:`Save`})]})]})]})}function HK({entry:e,rawValue:t,onRawChange:n,onSave:r,saving:i,changed:a}){let o=(()=>{try{return JSON.parse(t)}catch{return[]}})().join(`, `),s=e=>{let t=e.split(`,`).map(e=>e.trim()).filter(Boolean);n(JSON.stringify(t))};return(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{className:`pb-3`,children:(0,L.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsx)(ND,{className:`text-base`,children:`Skip Statuses`}),(0,L.jsx)(PD,{children:e.description})]}),(0,L.jsxs)(X,{variant:`outline`,className:`shrink-0 text-xs`,children:[e.category,`/`,e.key]})]})}),(0,L.jsxs)(q,{className:`space-y-4`,children:[(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`skip-statuses`,className:`text-sm`,children:`Statuses (comma-separated)`}),(0,L.jsx)(G,{id:`skip-statuses`,value:o,onChange:e=>s(e.target.value),placeholder:`not interested, no reply, lost`,className:`font-mono text-sm`})]}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground/70 italic`,children:`Leads with any of these statuses will skip scoring and be automatically marked as cold.`}),(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Last updated: `,new Date(e.updatedAt).toLocaleString(),e.updatedBy&&` by ${e.updatedBy}`]}),(0,L.jsx)(W,{size:`sm`,disabled:i||!a,onClick:r,children:i?`Saving...`:`Save`})]})]})]})}function UK({label:e,result:t,variant:n}){return(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{className:`pb-2`,children:(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsxs)(ND,{className:`text-sm`,children:[e,` prompt`]}),(0,L.jsxs)(X,{variant:n,className:`text-xs`,children:[t.responseTimeMs,`ms`]})]})}),(0,L.jsxs)(q,{className:`space-y-3`,children:[(0,L.jsx)(`div`,{className:`rounded-md bg-muted/50 p-3 text-sm whitespace-pre-wrap min-h-[80px]`,children:t.text||(0,L.jsx)(`span`,{className:`text-muted-foreground italic`,children:`No response`})}),t.classification&&(0,L.jsxs)(`div`,{children:[(0,L.jsx)(Z,{className:`text-xs mb-1 block`,children:`Classification`}),(0,L.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:Object.entries(t.classification).map(([e,t])=>(0,L.jsxs)(X,{variant:`secondary`,className:`text-xs font-mono`,children:[e,`: `,String(t)]},e))})]})]})]})}function WK(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(null);return(0,_.useEffect)(()=>{H(`/api/agents`).then(e=>t(e.data??[])).catch(()=>{})},[]),(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{className:`pb-3`,children:[(0,L.jsx)(ND,{className:`text-base`,children:`Preview weekly digest`}),(0,L.jsx)(PD,{children:`Force-runs this Monday's digest for one agent. Honors dry-run, so by default it creates a draft in the agent's DM thread for review.`})]}),(0,L.jsxs)(q,{className:`space-y-3`,children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,L.jsxs)(wk,{value:n,onValueChange:r,children:[(0,L.jsx)(Dk,{className:`w-[260px]`,children:(0,L.jsx)(Ek,{placeholder:`Pick an agent...`})}),(0,L.jsx)(Ok,{children:e.map(e=>(0,L.jsx)(Ak,{value:e.id,children:e.name},e.id))})]}),(0,L.jsx)(W,{onClick:async()=>
156{if(!n){z.error(`Pick an agent first`);return}a(!0),s(null);try{let e=await H(`/api/pa/weekly-digests/run-for-agent/${n}`,{method:`POST`});s(e.data),e.data.dmDrafted?z.success(`Draft created â ${e.data.leadCount} leads. Review in the agent's DM thread.`):e.data.dmSent?z.success(`Sent â ${e.data.leadCount} leads.`):z.error(`Digest generated but DM failed â check activity log`)}catch(e){z.error(e instanceof Error?e.message:`Failed to run weekly digest`)}finally{a(!1)}},disabled:!n||i,children:i?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(Ew,{className:`h-4 w-4 animate-spin mr-2`}),`Running...`]}):`Send draft now`})]}),o&&(0,L.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:o.dmDrafted?`â Drafted â ${o.leadCount} lead${o.leadCount===1?``:`s`}. Open the agent's DM thread to preview.`:o.dmSent?`â Sent â ${o.leadCount} lead${o.leadCount===1?``:`s`}.`:`â DM failed â check the activity log for details.`})]})]})}var GK={pending:`outline`,assigned:`secondary`,group_created:`secondary`,intro_sent:`default`,awaiting_agent_phone:`destructive`,failed:`destructive`},KK={"0-3months":`0â3 Months`,"3-6months":`3â6 Months`,">6months":`>6 Months`,flexible:`Flexible / Exploring`,unknown:`Unknown`};function qK(e,t){return t==null?`â`:e===`budgetMin`||e===`budgetMax`?`$${Number(t).toLocaleString()}`:e===`timeline`&&typeof t==`string`?KK[t]??t:typeof t==`string`?t.charAt(0).toUpperCase()+t.slice(1).replace(/_/g,` `):String(t)}var JK={propertyType:`Property Type`,transactionType:`Transaction`,budgetMin:`Budget Min`,budgetMax:`Budget Max`,districtPreference:`District`,timeline:`Timeline`,openToConsultation:`Open to Consult`};function YK({data:e}){let t=Object.entries(JK).filter(([t])=>e[t]!=null);return t.length===0?null:(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`span`,{className:`font-medium text-sm`,children:`Lead Context:`}),(0,L.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 gap-x-4 gap-y-1 mt-1 text-xs`,children:t.map(([t,n])=>(0,L.jsxs)(`div`,{className:`flex gap-1`,children:[(0,L.jsxs)(`span`,{className:`text-muted-foreground`,children:[n,`:`]}),(0,L.jsx)(`span`,{className:`font-medium`,children:qK(t,e[t])})]},t))})]})}function XK(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(!1),o=()=>{a(!0);try{Wk([`Lead`,`Agent`,`Status`,`Type`,`Reason`,`Group Created`,`Intro Sent`,`Failure Reason`,`Overridden`,`Override Reason`,`Date`],e.map(e=>[e.leadName,e.agentName,e.status.replace(/_/g,` `),e.isArticleAttribution?`Article`:`AI`,e.reason,e.waGroupId?`Yes`:`No`,e.introMessageSent?`Yes`:`No`,e.failureReason??``,e.overriddenFromAgentId?`Yes`:`No`,e.overrideReason??``,new Date(e.createdAt).toISOString()]),`assignment-log-${new Date().toISOString().split(`T`)[0]}.csv`)}finally{a(!1)}};function s(){H(`/api/assignments`).then(e=>t(e.data??[])).catch(e=>{console.error(`[assignments] fetch failed:`,e),z.error(`Failed to load assignments`)})}return(0,_.useEffect)(()=>{s()},[]),(0,L.jsxs)(`div`,{className:`space-y-6`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,L.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Assignment Log`}),(0,L.jsx)(sA,{interval:`on demand`}),(0,L.jsxs)(W,{variant:`outline`,size:`sm`,onClick:o,disabled:i,children:[(0,L.jsx)(iw,{className:`mr-1.5 h-4 w-4`}),i?`Exporting...`:`Export CSV`]})]}),(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Agent assignment history with AI rationale and override controls`})]}),(0,L.jsx)(`div`,{className:`rounded-md border`,children:(0,L.jsxs)(Pk,{children:[(0,L.jsx)(Fk,{children:(0,L.jsxs)(Lk,{children:[(0,L.jsx)(J,{className:`w-[30px]`}),(0,L.jsx)(J,{children:`Lead`}),(0,L.jsx)(J,{children:`Agent`}),(0,L.jsx)(J,{children:`Status`}),(0,L.jsx)(J,{children:`Type`}),(0,L.jsx)(J,{children:`Group`}),(0,L.jsx)(J,{children:`Date`}),(0,L.jsx)(J,{className:`w-[80px]`,children:`Actions`})]})}),(0,L.jsx)(Ik,{children:e.length===0?(0,L.jsx)(Lk,{children:(0,L.jsx)(Y,{colSpan:8,className:`text-center text-muted-foreground py-8`,children:`No assignments yet. Leads will be assigned after qualification.`})}):e.map(e=>(0,L.jsx)(rK,{asChild:!0,children:(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(iK,{asChild:!0,children:(0,L.jsxs)(Lk,{className:`curs
156or-pointer hover:bg-muted/50`,children:[(0,L.jsx)(Y,{children:(0,L.jsx)(zC,{className:`h-4 w-4`})}),(0,L.jsx)(Y,{className:`font-medium`,children:e.leadName}),(0,L.jsx)(Y,{children:(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[e.agentName,e.overriddenFromAgentId&&(0,L.jsx)(X,{variant:`outline`,className:`text-xs text-yellow-600 border-yellow-400`,children:`Overridden`})]})}),(0,L.jsx)(Y,{children:(0,L.jsx)(X,{variant:GK[e.status]??`outline`,children:e.status.replace(/_/g,` `)})}),(0,L.jsx)(Y,{children:e.id.startsWith(`lead:`)?(0,L.jsx)(X,{variant:`outline`,className:`capitalize`,children:e.status}):e.isArticleAttribution?(0,L.jsx)(X,{variant:`secondary`,children:`Article`}):(0,L.jsx)(X,{variant:`outline`,children:`AI`})}),(0,L.jsx)(Y,{children:e.waGroupId?(0,L.jsx)(X,{variant:`default`,children:e.introMessageSent?`Intro sent`:`Created`}):(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`â`})}),(0,L.jsx)(Y,{className:`text-sm text-muted-foreground`,children:new Date(e.createdAt).toLocaleDateString()}),(0,L.jsx)(Y,{children:e.status!==`failed`&&(0,L.jsx)(W,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:t=>{t.stopPropagation(),r(e)},title:`Reassign agent`,children:(0,L.jsx)(wC,{className:`h-3.5 w-3.5`})})})]})}),(0,L.jsx)(aK,{asChild:!0,children:(0,L.jsx)(Lk,{children:(0,L.jsx)(Y,{colSpan:8,className:`bg-muted/30 p-4`,children:(0,L.jsxs)(`div`,{className:`space-y-4 text-sm`,children:[e.overriddenFromAgentId&&(0,L.jsxs)(`div`,{className:`flex items-start gap-2 bg-yellow-50 dark:bg-yellow-950/30 border border-yellow-200 dark:border-yellow-800 rounded-md p-3 text-xs`,children:[(0,L.jsx)(xT,{className:`h-4 w-4 text-yellow-600 shrink-0 mt-0.5`}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`span`,{className:`font-medium text-yellow-700 dark:text-yellow-400`,children:`Manually overridden`}),e.overrideReason&&(0,L.jsxs)(`span`,{className:`text-muted-foreground`,children:[` `,`â `,e.overrideReason]}),e.overriddenAt&&(0,L.jsxs)(`span`,{className:`text-muted-foreground`,children:[` `,`(`,new Date(e.overriddenAt).toLocaleDateString(),`)`]})]})]}),(e.status===`failed`||e.status===`awaiting_agent_phone`)&&e.failureReason&&(0,L.jsxs)(`div`,{className:`flex items-start gap-2 bg-destructive/10 border border-destructive/30 rounded-md p-3 text-xs`,children:[(0,L.jsx)(xT,{className:`h-4 w-4 text-destructive shrink-0 mt-0.5`}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`span`,{className:`font-medium text-destructive`,children:`Failure reason`}),(0,L.jsx)(`p`,{className:`text-muted-foreground mt-0.5`,children:e.failureReason})]})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`span`,{className:`font-medium`,children:`AI Rationale:`}),(0,L.jsx)(`p`,{className:`mt-1 text-muted-foreground whitespace-pre-wrap`,children:e.reason})]}),e.qualificationData&&(0,L.jsx)(YK,{data:e.qualificationData}),e.alternatives&&e.alternatives.length>0&&(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`span`,{className:`font-medium mb-1 block`,children:`Alternatives Considered:`}),(0,L.jsx)(`div`,{className:`space-y-2`,children:e.alternatives.map((e,t)=>(0,L.jsxs)(`div`,{className:`bg-background rounded px-3 py-2 text-xs border`,children:[(0,L.jsx)(`span`,{className:`font-medium`,children:e.agentName}),e.rationale&&(0,L.jsx)(`p`,{className:`text-muted-foreground mt-0.5`,children:e.rationale}),e.totalScore!=null&&(0,L.jsxs)(`span`,{className:`text-muted-foreground`,children:[` `,`(score: `,e.totalScore,`)`]})]},t))})]})]})})})})]})},e.id))})]})}),n&&(0,L.jsx)(NB,{assignment:n,open:!!n,onOpenChange:e=>{e||r(null)},onSuccess:s})]})}var ZK={capacity:{label:`capacity`,variant:`outline`,hint:`Every covering agent was at their daily cap. At the next 8am reset we re-engage with a âstill interested?â follow-up before assigning.`},capacity_consented:{label:`capacity (consented)`,variant:`default`,hint:`Already consented, but no agent had a free slot. Assigned directly at the next 8am reset â no re-confirmation. Stays here if every agent is still full.`},weekend:{label:`weekend pause`,variant:`secondary`,hint:`Arrived during the weekend pause and has never been contacted. Gets the normal opener on the next working day, once an agent has a slot.`},holiday:{label:`holiday pause`,variant:`secondary`,hint:`Arrived during a public holiday and has never been contacted. Gets the normal opener on the next working day, once an agent has a slot.`},weekend_assignment:{label:`weekend (consented)`,variant:`default`,hint:`Consented during the weekend pause. Assigned directly on the next working day â no re-confirmation.`},holiday_assignment:{label:`holiday (consented)`,variant:`default`,hint:`Consented during a public holiday. Assigned directly on the next working day â no re-confirmation.`}};function QK(e){let t=e?.trim();return t?ZK[t]??{label:t.replace(/_/g,` `),variant:`outline`,hint:`Unrecognised backlog reason "${t}". It will be re-engaged with a âstill interested?â follow-up at the next 8am reset (the default branch).`}:{label:`unknown`,variant:`destructive`,hint:`No backlog reason recorded â unexpected. This lead would be re-engaged as if it were waiting on capacity. Worth checking how it got here.`}}var $K={hot:`destructive`,warm:`default`,cold:`outline`,new:`secondary`};function eq(e){return e==null?`â`:e<1?`<1h`:e<24?`${e}h`:`${Math.floor(e/24)}d`}function tq(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(!0),[i,a]=(0,_.useState)(null);async function o(){r(!0),a(null);try{t((await H(`/api/backlog`)).data)}catch(e){a(e instanceof Error?e.message:`Failed to load backlog`)}finally{r(!1)}}return(0,_.useEffect)(()=>{o()},[]),(0,L.jsxs)(`div`,{className:`p-6 space-y-4`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`h1`,{className:`text-2xl font-semibold tracking-tight flex items-center gap-2`,children:[(0,L.jsx)(QC,{className:`size-6`}),` Backlog`]}),(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Leads parked until the next working morning â waiting on agent capacity, or held over a weekend/holiday pause. Cleared oldest-first each morning (8am SGT) when daily caps reset; hover a reason to see what happens to that lead.`})]}),(0,L.jsxs)(W,{variant:`outline`,size:`sm`,onClick:o,disabled:n,children:[(0,L.jsx)(Yw,{className:`size-4 ${n?`animate-spin`:``}`}),`Refresh`]})]}),i&&(0,L.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded-md p-3`,children:i}),!n&&e.length===0&&!i?(0,L.jsxs)(`div`,{className:`text-center py-16 text-muted-foreground`,children:[(0,L.jsx)(QC,{className:`size-10 mx-auto mb-3 opacity-40`}),(0,L.jsx)(`p`,{className:`font-medium`,children:`Backlog is empty`}),(0,L.jsx)(`p`,{className:`text-sm`,children:`Every lead has been matched to an agent.`})]}):(0,L.jsx)(`div`,{className:`rounded-md border`,children:(0,L.jsxs)(Pk,{children:[(0,L.jsx)(Fk,{children:(0,L.jsxs)(Lk,{children:[(0,L.jsx)(J,{children:`#`}),(0,L.jsx)(J,{children:`Lead`}),(0,L.jsx)(J,{children:`Warmth`}),(0,L.jsx)(J,{children:`Reason`}),(0,L.jsx)(J,{children:`Intended agent`}),(0,L.jsx)(J,{children:`Source`}),(0,L.jsx)(J,{className:`text-right`,children:`Waiting`})]})}),(0,L.jsx)(Ik,{children:e.map((e,t)=>{let n=QK(e.backlogReason);return(0,L.jsxs)(Lk,{children:[(0,L.jsx)(Y,{className:`text-muted-foreground tabular-nums`,children:t+1}),(0,L.jsxs)(Y,{children:[(0,L.jsx)(`div`,{className:`font-medium`,children:e.name}),(0,L.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:e.phone})]}),(0,L.jsx)(Y,{children:(0,L.jsx)(X,{variant:$K[e.warmth??`new`]??`secondary`,children:e.warmth??`new`})}),(0,L.jsx)(Y,{children:(0,L.jsx)(X,{variant:n.variant,title:n.hint,children:n.label})}),(0,L.jsx)(Y,{children:e.intendedAgentName??`â`}),(0,L.jsx)(Y,{className:`text-sm text-muted-foreground`,children:e.source??`â`}),(0,L.jsx)(Y,{className:`text-right tabular-nums`,children:eq(e.ageHours)})]},e.id)})})]})})]})}var nq=[{key:`scored`,label:`Scored`},{key:`awaiting_reply`,label:`Outreach`},{key:`qualifying`,label:`Qualifying`},{key:`awaiting_consent`,label:`Consent`},{key:`qualified`,label:`Qualified`},{key:`assigned`,label:`Assigned`},{key:`group_simulated`,label:`Group Created`}],rq={};nq.forEach((e,t)=>{rq[e.key]=t}),rq.not_interested=-1,rq.consent_declined=-1,rq.lost=-1,rq.idle=-1;var iq=[`scored`,`awaiting_reply`,`qualifying`,`awaiting_consent`,`qualified`];function aq(e){return rq[e]??-1}function oq(e){return e===`cloud_api`?`Cloud API`:e===`baileys`?`Baileys`:`â`}function sq(e){let t=e?.sendPlan?.category;return t?t===`template`?e?.missingTemplate?`Template (missing)`:`Template`:t===`session`?`Free-form`:t===`group`?`Group`:null:null}var cq={budget:``,bedrooms:``,location:``,buyOrSell:``,buyingTimeline:``,buyPropertyType:``,preferences:``,ownStayOrInvestment:``},lq={hot:{name:`John Tan`,source:`Ryan J`,profile:{...cq,budget:`$1.5M - $2M`,bedrooms:`3`,location:`D15 - East Coast / Marine Parade`,buyOrSell:`Buying`,buyingTimeline:`Within 3 months`,buyPropertyType:`Private (Condo/EC/Landed)`,ownStayOrInvestment:`For Own Stay only`}}
156,warm:{name:`Sarah Lee`,source:`Stacked`,profile:{...cq,budget:`$1M - $1.5M`,buyOrSell:`Buying`,buyingTimeline:`3-6 months from now`,buyPropertyType:`Private (Condo/EC/Landed)`,preferences:`Close to MRT,Spacious Units`,ownStayOrInvestment:`For Own Stay only`}},cold:{name:`Mike Wong`,source:``,profile:cq}};function uq(){let[e,t]=jn(),[n,r]=(0,_.useState)(`simulation`),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)([]),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(!1),g=(0,_.useRef)(!1),[v,y]=(0,_.useState)(``),b=(0,_.useRef)(!1),[x,S]=(0,_.useState)(null),[C,w]=(0,_.useState)({name:``,source:``,profile:{...cq}}),T=(0,_.useRef)(!1),E=(0,_.useRef)(null);(0,_.useEffect)(()=>{E.current?.scrollIntoView({behavior:`smooth`})},[c]),(0,_.useEffect)(()=>{if(T.current||i)return;let n=e.get(`preset`);if(n===`hot`||n===`warm`||n===`cold`){T.current=!0;let e=lq[n];w({name:e.name,source:e.source,profile:{...e.profile}}),t({},{replace:!0})}},[e,t,i]);async function D(e){let t=await H(`/api/simulation/${e}/state`);t.success&&(a(t.data.state),l(t.data.messages),s(t.data.lead))}async function O(){if(!C.name.trim()){z.error(`Name is required`);return}d(!0);try{let e=Object.entries(C.profile).filter(([,e])=>e.trim()!==``),t={name:C.name,source:C.source||void 0,leadProfileData:e.length>0?Object.fromEntries(e):void 0},n=await H(`/api/simulation/create`,{method:`POST`,body:JSON.stringify(t)});n.success?(a(n.data),l([]),z.success(`Simulation created â lead scored as ${n.data.scoringResult.warmth}`)):z.error(n.error??`Failed to create simulation`)}catch(e){z.error(e instanceof Error?e.message:`Failed to create simulation`)}finally{d(!1)}}async function k(){if(i){d(!0);try{(await H(`/api/simulation/${i.simulationId}/outreach`,{method:`POST`})).success&&(await D(i.simulationId),z.success(`Outreach message sent`))}catch(e){z.error(e instanceof Error?e.message:`Outreach failed`)}finally{d(!1)}}}function A(e){let t=e instanceof Error?e.message:String(e);return/Simulation (lead |conversation )?not found/i.test(t)?(l(e=>e.filter(e=>!e.id.startsWith(`optimistic-`))),a(null),l([]),s(null),p(!1),b.current=!1,z.error(`Your test session was reset â probably by a deployment. Start a new simulation to continue.`,{duration:8e3}),!0):!1}async function j(){if(!i||!v.trim())return;let e=v.trim();y(``);let t={id:`optimistic-${Date.now()}`,direction:`inbound`,body:e,contactName:null,timestamp:new Date().toISOString()};l(e=>[...e,t]);try{let t=await H(`/api/simulation/${i.simulationId}/reply`,{method:`POST`,body:JSON.stringify({text:e})});if(!t.success){if(l(e=>e.filter(e=>!e.id.startsWith(`optimistic-`))),t.error&&/Simulation (lead |conversation )?not found/i.test(t.error)){A(Error(t.error));return}z.error(t.error??`Reply failed`);return}if(p(!0),!b.current){b.current=!0;let e=i.simulationId,t=Date.now();(async()=>{try{for(;Date.now()-t<6e4&&(await new Promise(e=>setTimeout(e,1e4)),(await H(`/api/simulation/${e}/pending-ai`)).data.pending););await D(e)}catch(e){if(!A(e))throw e}finally{b.current=!1,p(!1)}})()}}catch(e){if(A(e))return;l(e=>e.filter(e=>!e.id.startsWith(`optimistic-`))),z.error(e instanceof Error?e.message:`Reply failed`),p(!1)}}async function M(){if(i){d(!0);try{let e=await H(`/api/simulation/${i.simulationId}/assign`,{method:`POST`});e.success?(a(e.data),z.success(`Assigned to ${e.data.assignmentResult?.agentName}`)):z.error(e.error??`Assignment failed`)}catch(e){z.error(e instanceof Error?e.message:`Assignment failed`)}finally{d(!1)}}}async function ee(){if(i){d(!0);try{(await H(`/api/simulation/${i.simulationId}/group`,{method:`POST`})).success&&(await D(i.simulationId),z.success(`Group created (simulated)`))}catch(e){z.error(e instanceof Error?e.message:`Group creation failed`)}finally{d(!1)}}}async function N(){if(i){d(!0);try{await H(`/api/simulation/${i.simulationId}`,{method:`DELETE`}),a(null),s(null),l([]),w({name:``,source:``,profile:{...cq}}),z.success(`Simulation cleaned up`)}catch(e){z.error(e instanceof Error?e.message:`Cleanup failed`)}finally{d(!1)}}}async function P(){d(!0);try{let e=await H(`/api/simulation/cleanup-all`,{method:`DELETE`});e.success&&(a(null),s(null),l([]),w({name:``,source:``,profile:{...cq}}),z.success(`Cleaned up ${e.data.deleted} simulation(s)`))}catch(e){z.error(e instanceof Error?e.message:`Cleanup failed`)}finally{d(!1)}}async function F(e){if(i){d(!0);try{let t=await H(`/api/simulation/${i.simulationId}/inject-error`,{method:`POST`,body:JSON.stringify({type:e})});t.success?(await D(i.simulationId),z.success(t.data.result)):z.error(t.error??`Error injection failed`)}catch(e){z.error(e instanceof Error?e.message:`Error injection failed`)}finally{d(!1)}}}async function I(){if(i){p(!0);try{let e=await H(`/api/simulation/${i.simulationId}/auto-step`,{method:`POST`});if(e.success){await D(i.simulationId);let t=e.data.action;e.data.generatedReply?z.success(`AI replied (${t})`):z.success(`Step completed: ${t}`)}}catch(e){z.error(e instanceof Error?e.message:`Auto step failed`)}finally{p(!1)}}}async function te(){if(!i)return;h(!0),g.current=!1;let e=i.simulationId;try{let t=!0,n=0;for(;t&&n<20&&!g.current;){n++;let r=await H(`/api/simulation/${e}/auto-step`,{method:`POST`});if(!r.success)break;await D(e),t=r.data.hasMore,t&&!g.current&&await new Promise(e=>setTimeout(e,500))}await D(e),g.current?z.info(`Auto-run stopped`):z.success(`Auto-run complete (${n} steps)`)}catch(e){z.error(e instanceof Error?e.message:`Auto-run failed`)}finally{h(!1),g.current=!1}}function ne(){g.current=!0}function re(e){w({...lq[e]})}async function ie(e){if(i){d(!0);try{let t=await H(`/api/simulation/${i.simulationId}/reset-to-stage`,{method:`POST`,body:JSON.stringify({stage:e})});t.success?(a(t.data.state),l(t.data.messages),z.success(`Reset to ${e} â ready to continue`)):z.error(t.error??`Reset failed`)}catch(e){z.error(e instanceof Error?e.message:`Reset failed`)}finally{d(!1),S(null)}}}async function ae(e){if(i){d(!0);try{let t=await H(`/api/simulation/${i.simulationId}/time-skip`,{method:`POST`,body:JSON.stringify({days:e})});if(t.success)if(await D(i.simulationId),t.data.markedAsLost)z.info(`Lead marked as lost â all follow-ups exhausted`);else if(t.data.followUpSent)z.success(`Follow-up ${t.data.followUpNumber} of 3 sent (skipped ${e}d)`);else{let n=t.data.nextFollowUpAt?new Date(t.data.nextFollowUpAt):null,r=new Date(t.data.simulatedTime);if(n){let t=Math.round((n.getTime()-r.getTime())/(1e3*60*60)),i=Math.round(t/24);z.info(`Skipped ${e}d â follow-up not due yet (${i>0?`${i}d`:`${t}h`} remaining)`)}else z.info(`Skipped ${e}d â no follow-up scheduled`)}else z.error(t.error??`Time skip failed`)}catch(e){z.error(e instanceof Error?e.message:`Time skip failed`)}finally{d(!1)}}}async function oe(){if(i){d(!0);try{let e=await H(`/api/simulation/${i.simulationId}/trigger-follow-up`,{method:`POST`});e.success?(await D(i.simulationId),e.data.markedAsLost?z.info(`Lead marked as lost â all follow-ups exhausted`):e.data.followUpSent&&z.success(`Follow-up ${e.data.followUpNumber} of 3 sent`)):z.error(e.error??`Trigger follow-up failed`)}catch(e){z.error(e instanceof Error?e.message:`Trigger follow-up failed`)}finally{d(!1)}}}function se(){a(null),s(null),l([]),w({name:``,source:``,profile:{...cq}})}let ce=i?.stage??`idle`,le=aq(ce),ue=ce===`not_interested`||ce===`lost`||ce===`group_simulated`;return(0,L.jsxs)(`div`,{className:`space-y-6`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`h1`,{className:`text-2xl font-semibold tracking-tight flex items-center gap-2`,children:[(0,L.jsx)(fw,{className:`h-6 w-6`}),`Lead Flow Simulation`]}),(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Test the end-to-e
156nd pipeline safely â no real WhatsApp messages sent`})]}),(0,L.jsxs)(`div`,{className:`flex gap-2`,children:[(0,L.jsxs)(`div`,{className:`flex rounded-md border`,children:[(0,L.jsxs)(W,{variant:n===`simulation`?`default`:`ghost`,size:`sm`,className:`rounded-r-none`,onClick:()=>r(`simulation`),children:[(0,L.jsx)(fw,{className:`mr-1 h-4 w-4`}),`Simulation`]}),(0,L.jsxs)(W,{variant:n===`bulk-run`?`default`:`ghost`,size:`sm`,className:`rounded-none border-x`,onClick:()=>r(`bulk-run`),children:[(0,L.jsx)(Tw,{className:`mr-1 h-4 w-4`}),`Bulk Run`]}),(0,L.jsxs)(W,{variant:n===`history`?`default`:`ghost`,size:`sm`,className:`rounded-l-none`,onClick:()=>r(`history`),children:[(0,L.jsx)(vw,{className:`mr-1 h-4 w-4`}),`History`]})]}),n===`simulation`&&i&&(0,L.jsxs)(W,{variant:`outline`,size:`sm`,onClick:se,children:[(0,L.jsx)(Xw,{className:`mr-1 h-4 w-4`}),`New`]}),(0,L.jsxs)(lA,{children:[(0,L.jsx)(uA,{asChild:!0,children:(0,L.jsxs)(W,{variant:`outline`,size:`sm`,disabled:u,children:[(0,L.jsx)(vT,{className:`mr-1 h-4 w-4`}),`Cleanup All`]})}),(0,L.jsxs)(pA,{children:[(0,L.jsxs)(mA,{children:[(0,L.jsx)(gA,{children:`Delete all simulations?`}),(0,L.jsx)(_A,{children:`This cannot be undone.`})]}),(0,L.jsxs)(hA,{children:[(0,L.jsx)(yA,{children:`Cancel`}),(0,L.jsx)(vA,{onClick:P,children:`Delete All`})]})]})]})]})]}),n===`bulk-run`&&(0,L.jsx)(dq,{}),n===`history`&&(0,L.jsx)(fq,{}),n===`simulation`&&(0,L.jsxs)(L.Fragment,{children:[i&&(0,L.jsx)(K,{children:(0,L.jsx)(q,{className:`pt-6`,children:(0,L.jsx)(`div`,{className:`flex items-center justify-between`,children:nq.map((e,t)=>{let n=e.key===ce,r=le>t,i=(ce===`not_interested`||ce===`lost`||ce===`consent_declined`)&&e.key===ce,a=r&&iq.includes(e.key);return(0,L.jsxs)(`div`,{className:`flex items-center flex-1`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col items-center gap-1 flex-1`,children:[(0,L.jsx)(`button`,{type:`button`,disabled:!a||u,onClick:()=>{a&&S(e.key)},className:`h-8 w-8 rounded-full flex items-center justify-center text-xs font-medium transition-colors ${r?`bg-green-500 text-white`:n&&!i?`bg-blue-500 text-white animate-pulse`:i?`bg-red-500 text-white`:`bg-muted text-muted-foreground`} ${a?`cursor-pointer hover:ring-2 hover:ring-green-300 hover:ring-offset-2`:``}`,title:a?`Reset to ${e.label}`:void 0,children:r?(0,L.jsx)(KC,{className:`h-4 w-4`}):(0,L.jsx)(`span`,{children:t+1})}),(0,L.jsx)(`span`,{className:`text-xs ${n?`font-semibold`:`text-muted-foreground`}`,children:e.label})]}),t<nq.length-1&&(0,L.jsx)(`div`,{className:`h-0.5 flex-1 mx-1 ${r?`bg-green-500`:`bg-muted`}`})]},e.key)})})})}),(0,L.jsx)(lA,{open:x!==null,onOpenChange:e=>{e||S(null)},children:(0,L.jsxs)(pA,{children:[(0,L.jsxs)(mA,{children:[(0,L.jsxs)(gA,{children:[`Reset to `,x,`?`]}),(0,L.jsx)(_A,{children:`Messages and progress after this stage will be deleted. This cannot be undone.`})]}),(0,L.jsxs)(hA,{children:[(0,L.jsx)(yA,{children:`Cancel`}),(0,L.jsx)(vA,{onClick:()=>{x&&ie(x)},children:`Reset`})]})]})}),(0,L.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-[400px_1fr]`,children:[(0,L.jsx)(`div`,{className:`space-y-4`,children:i?(0,L.jsx)(gq,{state:i,onCleanup:N,onInjectError:F,loading:u}):(0,L.jsx)(hq,{formData:C,setFormData:w,onSubmit:O,onPreset:re,loading:u})}),(0,L.jsxs)(K,{className:`flex flex-col h-[calc(100vh-14rem)] min-h-[500px]`,children:[(0,L.jsxs)(MD,{className:`pb-3`,children:[(0,L.jsxs)(ND,{className:`text-base flex items-center gap-2`,children:[(0,L.jsx)(Nw,{className:`h-4 w-4`}),`Conversation`]}),(0,L.jsx)(PD,{children:i?`You are playing the role of the lead`:`Create a simulation to start testing`})]}),(0,L.jsx)(JT,{}),(0,L.jsxs)(q,{className:`flex-1 overflow-y-auto p-4 space-y-3`,children:[c.length===0&&i&&(0,L.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:ce===`scored`?`Click 'Send Outreach' to begin`:`No messages yet`}),!i&&(0,L.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:`Fill in the lead form and create a simulation to start`}),c.map((e,t)=>{let n=t>0?c[t-1]:null;return(0,L.jsxs)(`div`,{children:[e.conversationType===`group`&&n?.conversationType!==`group`&&(0,L.jsxs)(`div`,{className:`flex items-center gap-2 my-4`,children:[(0,L.jsx)(`div`,{className:`flex-1 border-t border-blue-200`}),(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5 px-3 py-1 rounded-full bg-blue-50 border border-blue-200`,children:[(0,L.jsx)(MT,{className:`h-3 w-3 text-blue-600`}),(0,L.jsx)(`span`,{className:`text-xs font-medium text-blue-600`,children:`WhatsApp Group Created`})]}),(0,L.jsx)(`div`,{className:`flex-1 border-t border-blue-200`})]}),(0,L.jsx)(`div`,{className:`flex ${e.direction===`outbound`?`justify-end`:`justify-start`}`,children:(0,L.jsxs)(`div`,{className:`max-w-[85%] rounded-lg px-3 py-2 text-sm ${e.conversationType===`group`?`bg-blue-50 text-foreground border border-blue-100`:e.direction===`outbound`?`bg-primary/10 text-foreground`:`bg-muted text-foreground`}`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1 mb-1 flex-wrap`,children:[e.direction===`outbound`?(0,L.jsx)(MC,{className:`h-3 w-3 text-muted-foreground`}):(0,L.jsx)(MT,{className:`h-3 w-3 text-muted-foreground`}),(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground font-medium`,children:e.direction===`outbound`?`Joey (AI)`:`You (Lead)`}),(0,L.jsx)(X,{variant:`outline`,className:`text-[9px] px-1 py-0 h-4 leading-none`,children:oq(e.channel)}),e.direction===`outbound`&&sq(e.rawPayload)&&(0,L.jsx)(X,{variant:`secondary`,className:`text-[9px] px-1 py-0 h-4 leading-none`,children:sq(e.rawPayload)})]}),(0,L.jsx)(`p`,{className:`whitespace-pre-wrap`,children:e.body}),e.rawPayload?.template&&(0,L.jsxs)(`div`,{className:`mt-1 text-[10px] text-muted-foreground border-t border-border/50 pt-1`,children:[`Template:`,` `,(0,L.jsx)(`span`,{className:`font-mono`,children:e.rawPayload.template.name}),` `,`(`,e.rawPayload.template.kind,`)`]}),(0,L.jsx)(`div`,{className:`flex items-center justify-end gap-1 mt-1`,children:(0,L.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:new Date(e.timestamp).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})})})]})})]},e.id)}),f&&(0,L.jsx)(`div`,{className:`flex justify-end`,children:(0,L.jsxs)(`div`,{className:`max-w-[85%] rounded-lg px-3 py-2 bg-primary/10`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1 mb-1`,children:[(0,L.jsx)(MC,{className:`h-3 w-3 text-muted-foreground`}),(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground font-medium`,children:`Joey (AI)`})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-1 py-1`,children:[(0,L.jsx)(`span`,{className:`h-2 w-2 rounded-full bg-muted-foreground
156/50 animate-bounce [animation-delay:0ms]`}),(0,L.jsx)(`span`,{className:`h-2 w-2 rounded-full bg-muted-foreground/50 animate-bounce [animation-delay:150ms]`}),(0,L.jsx)(`span`,{className:`h-2 w-2 rounded-full bg-muted-foreground/50 animate-bounce [animation-delay:300ms]`})]})]})}),(0,L.jsx)(`div`,{ref:E})]}),(0,L.jsx)(JT,{}),(0,L.jsxs)(`div`,{className:`p-4 space-y-2`,children:[!i&&(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground text-center`,children:`Create a simulation first`}),i&&ce===`scored`&&(0,L.jsxs)(W,{onClick:k,disabled:u||m,className:`w-full`,children:[u?(0,L.jsx)(Ew,{className:`mr-2 h-4 w-4 animate-spin`}):(0,L.jsx)(eT,{className:`mr-2 h-4 w-4`}),`Send Outreach Message`]}),i&&(ce===`awaiting_reply`||ce===`qualifying`||ce===`awaiting_consent`)&&(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsxs)(`div`,{className:`flex gap-2`,children:[(0,L.jsx)(G,{placeholder:`Type your reply as the lead...`,value:v,onChange:e=>y(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),j())}}),(0,L.jsxs)(tx,{children:[(0,L.jsx)(nx,{asChild:!0,children:(0,L.jsx)(W,{onClick:j,disabled:!v.trim(),size:`icon`,children:(0,L.jsx)(eT,{className:`h-4 w-4`})})}),(0,L.jsx)(rx,{children:`Send reply as lead`})]}),(0,L.jsxs)(tx,{children:[(0,L.jsx)(nx,{asChild:!0,children:(0,L.jsx)(W,{onClick:I,disabled:f||m,size:`icon`,variant:`outline`,children:(0,L.jsx)(cw,{className:`h-4 w-4`})})}),(0,L.jsx)(rx,{children:`Auto Step â AI generates a reply`})]})]}),ce===`awaiting_reply`&&(0,L.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsxs)(`span`,{className:`text-xs text-muted-foreground flex items-center gap-1`,children:[(0,L.jsx)(QC,{className:`h-3 w-3`}),`Time Skip:`]}),(0,L.jsx)(W,{onClick:()=>ae(1),disabled:u||f||m,size:`sm`,variant:`outline`,className:`h-7 text-xs`,children:`+1 Day`}),(0,L.jsx)(W,{onClick:()=>ae(3),disabled:u||f||m,size:`sm`,variant:`outline`,className:`h-7 text-xs`,children:`+3 Days`}),(0,L.jsx)(W,{onClick:()=>ae(7),disabled:u||f||m,size:`sm`,variant:`outline`,className:`h-7 text-xs`,children:`+7 Days`})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsxs)(W,{onClick:oe,disabled:u||f||m,size:`sm`,variant:`outline`,className:`h-7 text-xs`,children:[(0,L.jsx)(Nw,{className:`mr-1 h-3 w-3`}),`Trigger Follow-up`]}),(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:o?`${o.followUpCount} of 3 sent`:``})]})]})]}),i&&ce===`qualified`&&(0,L.jsxs)(W,{onClick:M,disabled:u||m,className:`w-full`,children:[u?(0,L.jsx)(Ew,{className:`mr-2 h-4 w-4 animate-spin`}):(0,L.jsx)(IT,{className:`mr-2 h-4 w-4`}),`Assign Agent`]}),i&&ce===`assigned`&&(0,L.jsxs)(W,{onClick:ee,disabled:u||m,className:`w-full`,children:[u?(0,L.jsx)(Ew,{className:`mr-2 h-4 w-4 animate-spin`}):(0,L.jsx)(MT,{className:`mr-2 h-4 w-4`}),`Create WhatsApp Group (Simulated)`]}),i&&!ue&&(0,L.jsx)(`div`,{className:`flex gap-2`,children:m?(0,L.jsxs)(W,{onClick:ne,variant:`destructive`,className:`w-full`,children:[(0,L.jsx)(pT,{className:`mr-2 h-4 w-4`}),`Stop Auto Run`]}):(0,L.jsxs)(W,{onClick:te,disabled:u||f,variant:`outline`,className:`w-full`,children:[(0,L.jsx)(Ww,{className:`mr-2 h-4 w-4`}),`Auto Run Full Pipeline`]})}),m&&(0,L.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-sm text-muted-foreground`,children:[(0,L.jsx)(Ew,{className:`h-4 w-4 animate-spin`}),`Running pipeline automatically...`]}),i&&ue&&(0,L.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,L.jsx)(X,{variant:ce===`group_simulated`?`default`:`destructive`,children:ce===`group_simulated`?`Simulation Complete`:ce===`not_interested`?`Lead Not Interested`:`Lead Lost`}),(0,L.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[(0,L.jsxs)(W,{variant:`outline`,size:`sm`,onClick:se,children:[(0,L.jsx)(Xw,{className:`mr-1 h-4 w-4`}),`New Simulation`]}),(0,L.jsxs)(lA,{children:[(0,L.jsx)(uA,{asChild:!0,children:(0,L.jsxs)(W,{variant:`outline`,size:`sm`,disabled:u,children:[(0,L.jsx)(vT,{className:`mr-1 h-4 w-4`}),`Clean Up`]})}),(0,L.jsxs)(pA,{children:[(0,L.jsxs)(mA,{children:[(0,L.jsx)(gA,{children:`Delete this simulation?`}),(0,L.jsx)(_A,{children:`This will remove the simulation and its data.`})]}),(0,L.jsxs)(hA,{children:[(0,L.jsx)(yA,{children:`Cancel`}),(0,L.jsx)(vA,{onClick:N,children:`Delete`})]})]})]})]})]})]})]})]})]})]})}function dq(){let[e,t]=(0,_.useState)(new Set),[n,r]=(0,_.useState)(!1),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(null),{data:c,isLoading:l}=vi({queryKey:[`simulation-scenarios`],queryFn:async()=>(await H(`/api/simulation/scenarios`)).data});function u(e){t(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function d(){c&&(e.size===c.length?t(new Set):t(new Set(c.map(e=>e.key))))}async function f(){if(e.size===0){z.error(`Select at least one scenario`);return}r(!0),a(null),s(null);try{let t=await H(`/api/simulation/bulk-run`,{method:`POST`,body:JSON.stringify({scenarioKeys:Array.from(e)})});if(t.success){a(t.data.results),s(t.data.batchId);let e=t.data.results.filter(e=>!e.error).length,n=t.data.results.filter(e=>e.error).length;z.success(`Bulk run complete: ${e} passed, ${n} failed`)}else z.error(t.error??`Bulk run failed`)}catch(e){z.error(e instanceof Error?e.message:`Bulk run failed`)}finally{r(!1)}}let p=e=>{if(e<1e3)return`${e}ms`;let t=Math.floor(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`},m=e=>e===`group_simulated`?`default`:e===`not_interested`||e===`lost`?`destructive`:`secondary`;return l?(0,L.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,L.jsx)(Ew,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):(0,L.jsxs)(`div`,{className:`space-y-6`,children:[(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{children:[(0,L.jsxs)(ND,{className:`text-base flex items-center gap-2`,children:[(0,L.jsx)(Tw,{className:`h-4 w-4`}),`Scenario Library`]}),(0,L.jsx)(PD,{children:`Select scenarios to run in bulk and validate AI behavior after prompt changes`})]}),(0,L.jsxs)(q,{className:`space-y-4`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(tM,{id:`select-all`,checked:c?e.size===c.length:!1,onCheckedChange:d,disabled:n}),(0,L.jsx)(Z,{htmlFor:`select-all`,className:`text-sm font-medium cursor-pointer`,children:`Select All`})]}),(0,L.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[e.size,` of `,c?.length??0,` selected`]})]}),(0,L.jsx)(JT,{}),(0,L.jsx)(`div`,{className:`space-y-3`,children:c?.map(t=>(0,L.jsxs)(`div`,{className:`flex items-start gap-3 p-3 rounded-lg border transition-colors cursor-pointer ${e.has(t.key)?`border-primary bg-primary/5`:`border-border hover:border-primary/50`}`,onClick:()=>!n&&u(t.key),children:[(0,L.jsx)(tM,{checked:e.has(t.key),onCheckedChange:()=>u(t.key),disabled:n,className:`mt-0.5`}),(0,L.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,L.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,L.jsx)(`span`,{className:`font-medium text-sm`,children:t.name})}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:t.description}),(0,L.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-muted-foreground mt-1.5`,children:[(0,L.jsxs)(`span`,{children:[`Lead: `,t.leadData.name]}),t.leadData.source&&(0,L.jsxs)(`span`,{children:[`Source: `,t.leadData.source]})]})]})]},t.key))}),(0,L.jsx)(W,{onClick:f,disabled:n||e.size===0,className:`w-full`,children:n?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(Ew,{className:`mr-2 h-4 w-4 animate-spin`}),`Running `,e.size,` scenario`,e.size===1?``:`s`,`...`]}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(Ww,{className:`mr-2 h-4 w-4`}),`Run Selected (`,e.size,`)`]})})]})]}),n&&(0,L.jsx)(K,{children:(0,L.jsx)(q,{className:`py-8`,children:(0,L.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,L.jsx)(Ew,{className:`h-8 w-8 animate-spin text-primary`}),(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Running scenarios sequentially... This may take a few minutes.`}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Each scenario runs the full pipeline (outreach, classification, qualification, assignment)`})]})})}),i&&(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsxs)(ND,{className:`text-base flex items-center gap-2`,children:[(0,L.jsx)(KC,{className:`h-4 w-4`}),`Bulk Run Results`]}),o&&(0,L.jsxs)(X,{variant:`outline`,className:`text-xs font-mono`,children:[`Batch: `,o.slice(0,8)]})]}),(0,L.jsxs)(PD,{children:[i.filter(e=>!e.error).length,` passed,`,` `,i.filter(e=>e.error).length,` failed,`,` `,`total time: `,p(i.reduce((e,t)=>
156e+t.durationMs,0))]})]}),(0,L.jsxs)(q,{children:[(0,L.jsxs)(Pk,{children:[(0,L.jsx)(Fk,{children:(0,L.jsxs)(Lk,{children:[(0,L.jsx)(J,{children:`Scenario`}),(0,L.jsx)(J,{children:`Status`}),(0,L.jsx)(J,{children:`Final Stage`}),(0,L.jsx)(J,{children:`Classification`}),(0,L.jsx)(J,{children:`Agent`}),(0,L.jsx)(J,{className:`text-right`,children:`Steps`}),(0,L.jsx)(J,{className:`text-right`,children:`Messages`}),(0,L.jsx)(J,{className:`text-right`,children:`Duration`})]})}),(0,L.jsx)(Ik,{children:i.map(e=>(0,L.jsxs)(Lk,{children:[(0,L.jsx)(Y,{children:(0,L.jsx)(`div`,{children:(0,L.jsx)(`span`,{className:`font-medium text-sm`,children:e.scenarioName})})}),(0,L.jsx)(Y,{children:e.error?(0,L.jsxs)(X,{variant:`destructive`,className:`gap-1`,children:[(0,L.jsx)(XC,{className:`h-3 w-3`}),`Error`]}):(0,L.jsxs)(X,{variant:`default`,className:`gap-1`,children:[(0,L.jsx)(KC,{className:`h-3 w-3`}),`Done`]})}),(0,L.jsx)(Y,{children:(0,L.jsx)(X,{variant:m(e.finalStage),className:`text-xs`,children:e.finalStage.replace(/_/g,` `)})}),(0,L.jsx)(Y,{children:e.classificationResult?(0,L.jsx)(X,{variant:e.classificationResult===`interested`?`default`:e.classificationResult===`not_interested`?`destructive`:e.classificationResult===`deferred`||e.classificationResult===`unclear`?`outline`:`secondary`,className:`text-xs`,children:e.classificationResult}):(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`--`})}),(0,L.jsx)(Y,{children:e.assignmentResult?(0,L.jsx)(`span`,{className:`text-sm`,children:e.assignmentResult.agentName}):(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`--`})}),(0,L.jsx)(Y,{className:`text-right font-mono text-sm`,children:e.totalSteps}),(0,L.jsx)(Y,{className:`text-right font-mono text-sm`,children:e.messageCount}),(0,L.jsx)(Y,{className:`text-right`,children:(0,L.jsxs)(`span`,{className:`flex items-center justify-end gap-1 text-sm`,children:[(0,L.jsx)(_T,{className:`h-3 w-3 text-muted-foreground`}),p(e.durationMs)]})})]},e.scenarioKey))})]}),i.some(e=>e.error)&&(0,L.jsxs)(`div`,{className:`mt-4 space-y-2`,children:[(0,L.jsx)(`p`,{className:`text-sm font-medium text-destructive`,children:`Errors:`}),i.filter(e=>e.error).map(e=>(0,L.jsxs)(`div`,{className:`text-xs p-2 rounded bg-destructive/10 text-destructive`,children:[(0,L.jsxs)(`span`,{className:`font-medium`,children:[e.scenarioName,`:`]}),` `,e.error]},e.scenarioKey))]})]})]})]})}function fq(){let e=ri(),[t,n]=(0,_.useState)(null),{data:r,isLoading:i}=vi({queryKey:[`simulation-history`],queryFn:async()=>(await H(`/api/simulation/history`)).data}),{data:a,isLoading:o}=vi({queryKey:[`simulation-history`,t],queryFn:async()=>t?(await H(`/api/simulation/history/${t}`)).data:null,enabled:!!t}),s=R({mutationFn:async e=>{await H(`/api/simulation/history/${e}`,{method:`DELETE`})},onSuccess:()=>{e.invalidateQueries({queryKey:[`simulation-history`]}),n(null),z.success(`History entry deleted`)},onError:e=>{z.error(e instanceof Error?e.message:`Delete failed`)}}),c=(0,_.useCallback)(e=>{if(e===null)return`--`;if(e<1e3)return`${e}ms`;let t=Math.floor(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`},[]),l=(0,_.useCallback)(e=>new Date(e).toLocaleDateString(`en-SG`,{day:`numeric`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`}),[]),u=(0,_.useCallback)(e=>e===`group_simulated`?`default`:e===`not_interested`||e===`lost`?`destructive`:`secondary`,[]);return t?o?(0,L.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,L.jsx)(Ew,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):a?(0,L.jsx)(pq,{run:a,onBack:()=>n(null)}):(0,L.jsxs)(`div`,{className:`text-center py-10 text-muted-foreground`,children:[`History entry not found.`,(0,L.jsx)(W,{variant:`link`,onClick:()=>n(null),children:`Back to list`})]}):i?(0,L.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,L.jsx)(Ew,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):!r||r.length===0?(0,L.jsx)(K,{children:(0,L.jsxs)(q,{className:`py-10 text-center text-muted-foreground`,children:[(0,L.jsx)(vw,{className:`mx-auto h-10 w-10 mb-3 opacity-40`}),(0,L.jsx)(`p`,{children:`No simulation history yet.`}),(0,L.jsx)(`p`,{className:`text-xs mt-1`,children:`Completed simulations will appear here automatically.`})]})}):(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{children:[(0,L.jsxs)(ND,{className:`text-base flex items-center gap-2`,children:[(0,L.jsx)(vw,{className:`h-4 w-4`}),`Past Simulation Runs`]}),(0,L.jsxs)(PD,{children:[r.length,` run`,r.length===1?``:`s`,` recorded`]})]}
156),(0,L.jsx)(q,{children:(0,L.jsx)(`div`,{className:`divide-y`,children:r.map(e=>(0,L.jsxs)(`div`,{className:`flex items-center justify-between py-3 first:pt-0 last:pb-0`,children:[(0,L.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`span`,{className:`font-medium text-sm truncate`,children:e.leadName}),(0,L.jsx)(X,{variant:u(e.finalStage),className:`text-xs shrink-0`,children:e.finalStage.replace(/_/g,` `)})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-muted-foreground mt-1`,children:[(0,L.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(Nw,{className:`h-3 w-3`}),e.messageCount??0,` msgs`]}),(0,L.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,L.jsx)(QC,{className:`h-3 w-3`}),c(e.durationMs)]}),(0,L.jsx)(`span`,{children:l(e.completedAt)})]})]}),(0,L.jsxs)(`div`,{className:`flex gap-1 shrink-0 ml-2`,children:[(0,L.jsx)(W,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>n(e.id),children:(0,L.jsx)(sw,{className:`h-4 w-4`})}),(0,L.jsxs)(lA,{children:[(0,L.jsx)(uA,{asChild:!0,children:(0,L.jsx)(W,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-destructive hover:text-destructive`,children:(0,L.jsx)(vT,{className:`h-4 w-4`})})}),(0,L.jsxs)(pA,{children:[(0,L.jsxs)(mA,{children:[(0,L.jsx)(gA,{children:`Delete history entry?`}),(0,L.jsx)(_A,{children:`This will permanently remove this simulation record.`})]}),(0,L.jsxs)(hA,{children:[(0,L.jsx)(yA,{children:`Cancel`}),(0,L.jsx)(vA,{onClick:()=>s.mutate(e.id),children:`Delete`})]})]})]})]})]},e.id))})})]})}function pq({run:e,onBack:t}){return(0,L.jsxs)(`div`,{className:`space-y-4`,children:[(0,L.jsxs)(W,{variant:`ghost`,size:`sm`,onClick:t,children:[(0,L.jsx)(CC,{className:`mr-1 h-4 w-4`}),`Back to history`]}),(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{className:`pb-3`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsx)(ND,{className:`text-base`,children:e.leadName}),(0,L.jsx)(X,{variant:(e=>e===`group_simulated`?`default`:e===`not_interested`||e===`lost`?`destructive`:`secondary`)(e.finalStage),children:e.finalStage.replace(/_/g,` `)})]}),(0,L.jsxs)(PD,{className:`flex items-center gap-3 text-xs`,children:[e.source&&(0,L.jsxs)(`span`,{children:[`Source: `,e.source]}),(0,L.jsxs)(`span`,{children:[e.messageCount??0,` messages`]}),(0,L.jsxs)(`span`,{children:[`Duration: `,(e=>{if(e===null)return`--`;if(e<1e3)return`${e}ms`;let t=Math.floor(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`})(e.durationMs)]})]})]}),e.clientNeeds&&(0,L.jsx)(q,{className:`pt-0`,children:(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.clientNeeds})})]}),(0,L.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-[400px_1fr]`,children:[(0,L.jsxs)(`div`,{className:`space-y-4`,children:[e.scoringResult&&(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{className:`pb-3`,children:(0,L.jsx)(ND,{className:`text-sm font-medium`,children:`Lead Scoring`})}),(0,L.jsxs)(q,{className:`space-y-2`,children:[(0,L.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,L.jsxs)(X,{variant:`outline`,className:`gap-1`,children:[(0,L.jsx)(`span`,{className:`h-2 w-2 rounded-full ${{hot:`bg-red-500`,warm:`bg-orange-500`,cold:`bg-blue-500`}[e.scoringResult.warmth]??`bg-gray-400`}`}),e.scoringResult.warmth.toUpperCase()]})}),(0,L.jsx)(`ul`,{className:`text-xs text-muted-foreground space-y-1`,children:e.scoringResult.reasons.map((e,t)=>(0,L.jsxs)(`li`,{className:`flex items-start gap-1`,children:[(0,L.jsx)(ZC,{className:`h-2 w-2 mt-1.5 flex-shrink-0`}),e]},t))})]})]}),e.classificationResult&&(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{className:`pb-3`,children:(0,L.jsx)(ND,{className:`text-sm font-medium`,children:`Classification`})}),(0,L.jsx)(q,{children:(0,L.jsx)(X,{variant:e.classificationResult===`interested`?`default`:e.classificationResult===`not_interested`?`destructive`:`secondary`,children:e.classificationResult})})]}),e.qualificationData&&(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{className:`pb-3`,children:(0,L.jsx)(ND,{className:`text-sm font-medium`,children:`Qualification`})}),(0,L.jsx)(q,{children:(0,L.jsxs)(`div`,{className:`space-y-2 text-sm`,children:[(0,L.jsx)(vq,{label:`Consultation`,value:e.qualificationData.openToConsultation}),(0,L.jsx)(vq,{label:`Timeline`,value:e.qualificationData.timeline}),(0,L.jsx)(vq,{label:`Budget`,value:e.qualificationData.budgetMin||e.qualificationData.budgetMax?`$${e.qualificationData.budgetMin??`?`}-$${e.qualificationData.budgetMax??`?`}`:null}),(0,L.jsx)(vq,{label:`Property Type`,value:e.qualificationData.propertyType}),(0,L.jsx)(vq,{label:`Transaction`,value:e.qualificationData.transactionType}),(0,L.jsx)(vq,{label:`District`,value:e.qualificationData.districtPreference}),e.qualificationData.isComplete&&(0,L.jsx)(X,{className:`mt-2`,children:`Complete`}),e.qualificationData.dropOff&&(0,L.jsx)(X,{variant:`destructive`,className:`mt-2`,children:`Dropped Off`})]})})]}),e.assignmentResult&&(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{className:`pb-3`,children:(0,L.jsx)(ND,{className:`text-sm font-medium`,children:`Agent Assignment`})}),(0,L.jsxs)(q,{className:`space-y-2`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(X,{children:e.assignmentResult.agentName}),e.assignmentResult.isArticleAttribution&&(0,L.jsx)(X,{variant:`outline`,children:`Article Attribution`})]}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.assignmentResult.reason})]})]}),e.groupResult&&(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{className:`pb-3`,children:(0,L.jsx)(ND,{className:`text-sm font-medium`,children:`WhatsApp Group`})}),(0,L.jsxs)(q,{className:`space-y-2 text-sm`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`Group: `}),(0,L.jsx)(`span`,{className:`font-medium`,children:e.groupResult.groupName})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`Agent: `}),(0,L.jsx)(`span`,{children:e.groupResult.agentName})]})]})]})]}),(0,L.jsxs)(K,{className:`flex flex-col h-[calc(100vh-14rem)] min-h-[400px]`,children:[(0,L.jsx)(MD,{className:`pb-3`,children:(0,L.jsxs)(ND,{className:`text-base flex items-center gap-2`,children:[(0,L.jsx)(Nw,{className:`h-4 w-4`}),`Conversation (`,e.messageCount??0,` messages)`]})}),(0,L.jsx)(JT,{}),(0,L.jsxs)(q,{className:`flex-1 overflow-y-auto p-4 space-y-3`,children:[(!e.messages||e.messages.length===0)&&(0,L.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:`No messages recorded`}),e.messages?.map((e,t)=>(0,L.jsx)(`div`,{className:`flex ${e.direction===`outbound`?`justify-end`:`justify-start`}`,children:(0,L.jsxs)(`div`,{className:`max-w-[85%] rounded-lg px-3 py-2 text-sm ${e.direction===`outbound`?`bg-primary/10 text-foreground`:`bg-muted text-foreground`}`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1 mb-1`,children:[e.direction===`outbound`?(0,L.jsx)(MC,{className:`h-3 w-3 text-muted-foreground`}):(0,L.jsx)(MT,{className:`h-3 w-3 text-muted-foreground`}),(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground font-medium`,children:e.direction===`outbound`?e.contactName??`Joey (AI)`:e.contactName??`Lead`}),(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:new Date(e.timestamp).toLocaleTimeString(`en-SG`,{hour:`2-digit`,minute:`2-digit`})})]}),(0,L.jsx)(`p`,{className:`whitespace-pre-wrap`,children:e.body})]})},t))]})]})]})]})}function mq({open:e,onOpenChange:t,onPick:n}){let[r,i]=(0,_.useState)(``),a=(0,_.useDeferredValue)(r),{data:o,isLoading:s}=vi({queryKey:[`leads-picker`,a],queryFn:async()=>{let e=new URLSearchParams({limit:`20`});return a&&e.set(`search`,a),(await H(`/api/leads?${e}`)).data},enabled:e}),c={hot:`bg-red-500`,warm:`bg-orange-500`,cold:`bg-blue-500`,new:`bg-gray-400`};return(0,L.jsx)(aj,{open:e,onOpenChange:t,children:(0,L.jsxs)(lj,{className:`max-w-md max-h-[70vh] flex flex-col`,children:[(0,L.jsx)(uj,{children:(0,L.jsx)(fj,{children:`Pick an Existing Lead`})}),(0,L.jsxs)(`div`,{className:`relative`,children:[(0,L.jsx)($w,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground`}),(0,L.jsx)(G,{placeholder:`Search by name, phone, source...`,value:r,onChange:e=>i(e.target.value),className:`pl-9`})]}),(0,L.jsx)(`div`,{className:`flex-1 overflow-y-auto min-h-0 -mx-1 px-1`,children:s?(0,L.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,L.jsx)(Ew,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):o?.length?(0,L.jsx)(`div`,{className:`space-y-1`,children:o.map(e=>(0,L.jsxs)(`button`,{type:`button`,onClick:()=>{n(e),t(!1)},className:`w-full text-left px-3 py-2.5 rounded-md hover:bg-muted transition-colors flex items-center gap-3`,children:[(0,L.jsx)(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${c[e.warmth]??`bg-gray-400`}`}),(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsx)(`div`,{className:`text-sm font-medium truncate`,children:e.name}),(0,L.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:[e.source,e.status].filter(
156Boolean).join(` · `)})]}),(0,L.jsx)(X,{variant:`outline`,className:`text-[10px] shrink-0`,children:e.warmth})]},e.id))}):(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-8`,children:`No leads found`})})]})})}function hq({formData:e,setFormData:t,onSubmit:n,onPreset:r,loading:i}){let[a,o]=(0,_.useState)(!1);function s(e){let n=e.leadProfileData??{};t({name:e.name,source:e.source??``,profile:{budget:n.budget??``,bedrooms:n.bedrooms??``,location:n.location??``,buyOrSell:n.buyOrSell??``,buyingTimeline:n.buyingTimeline??``,buyPropertyType:n.buyPropertyType??``,preferences:n.preferences??``,ownStayOrInvestment:n.ownStayOrInvestment??``}})}function c(n,r){t({...e,profile:{...e.profile,[n]:r}})}return(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{children:[(0,L.jsx)(ND,{className:`text-base`,children:`Create Simulation Lead`}),(0,L.jsx)(PD,{children:`Fill in test lead details or use a preset`})]}),(0,L.jsxs)(q,{className:`space-y-4`,children:[(0,L.jsxs)(`div`,{className:`flex gap-2`,children:[(0,L.jsxs)(W,{variant:`outline`,size:`sm`,onClick:()=>r(`hot`),className:`flex-1`,children:[(0,L.jsx)(`span`,{className:`mr-1 h-2 w-2 rounded-full bg-red-500 inline-block`}),`Hot Lead`]}),(0,L.jsxs)(W,{variant:`outline`,size:`sm`,onClick:()=>r(`warm`),className:`flex-1`,children:[(0,L.jsx)(`span`,{className:`mr-1 h-2 w-2 rounded-full bg-orange-500 inline-block`}),`Warm Lead`]}),(0,L.jsxs)(W,{variant:`outline`,size:`sm`,onClick:()=>r(`cold`),className:`flex-1`,children:[(0,L.jsx)(`span`,{className:`mr-1 h-2 w-2 rounded-full bg-blue-500 inline-block`}),`Cold Lead`]})]}),(0,L.jsxs)(`div`,{className:`relative flex items-center`,children:[(0,L.jsx)(JT,{className:`flex-1`}),(0,L.jsxs)(W,{variant:`ghost`,size:`sm`,onClick:()=>o(!0),className:`mx-2 text-xs text-muted-foreground hover:text-foreground`,children:[(0,L.jsx)(OT,{className:`mr-1.5 h-3.5 w-3.5`}),`Pick Existing Lead`]}),(0,L.jsx)(JT,{className:`flex-1`})]}),(0,L.jsx)(mq,{open:a,onOpenChange:o,onPick:s}),(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(Z,{htmlFor:`name`,children:`Name *`}),(0,L.jsx)(G,{id:`name`,placeholder:`John Tan`,value:e.name,onChange:n=>t({...e,name:n.target.value})})]}),(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(Z,{htmlFor:`source`,children:`Source / Article Author`}),(0,L.jsx)(G,{id:`source`,placeholder:`e.g. Ryan J, Stacked, etc.`,value:e.source,onChange:n=>t({...e,source:n.target.value})})]}),(0,L.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`buyOrSell`,className:`text-xs`,children:`Buy / Sell`}),(0,L.jsx)(G,{id:`buyOrSell`,placeholder:`e.g. Buying`,value:e.profile.buyOrSell,onChange:e=>c(`buyOrSell`,e.target.value)})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`budget`,className:`text-xs`,children:`Budget`}),(0,L.jsx)(G,{id:`budget`,placeholder:`e.g. $1.5M - $2M`,value:e.profile.budget,onChange:e=>c(`budget`,e.target.value)})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`propertyType`,className:`text-xs`,children:`Property Type`}),(0,L.jsx)(G,{id:`propertyType`,placeholder:`e.g. Condo, HDB, Landed`,value:e.profile.buyPropertyType,onChange:e=>c(`buyPropertyType`,e.target.value)})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`bedrooms`,className:`text-xs`,children:`Bedrooms`}),(0,L.jsx)(G,{id:`bedrooms`,placeholder:`e.g. 3`,value:e.profile.bedrooms,onChange:e=>c(`bedrooms`,e.target.value)})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`location`,className:`text-xs`,children:`Location / District`}),(0,L.jsx)(G,{id:`location`,placeholder:`e.g. D15 - East Coast`,value:e.profile.location,onChange:e=>c(`location`,e.target.value)})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`timeline`,className:`text-xs`,children:`Timeline`}),(0,L.jsx)(G,{id:`timeline`,placeholder:`e.g. Within 3 months`,value:e.profile.buyingTimeline,onChange:e=>c(`buyingTimeline`,e.target.value)})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5 col-span-2`,children:[(0,L.jsx)(Z,{htmlFor:`purpose`,className:`text-xs`,children:`Purpose`}),(0,L.jsx)(G,{id:`purpose`,placeholder:`e.g. For Own Stay only, Investment`,value:e.profile.ownStayOrInvestment,onChange:e=>c(`ownStayOrInvestment`,e.target.value)})]})]}),(0,L.jsxs)(W,{onClick:n,disabled:i,className:`w-full`,children:[i?(0,L.jsx)(Ew,{className:`mr-2 h-4 w-4 animate-spin`}):(0,L.jsx)(TC,{className:`mr-2 h-4 w-4`}),`Create Simulation`]})]})]})}function gq({state:e,onCleanup:t,onInjectError:n,loading:r}){return(0,L.jsxs)(`div`,{className:`space-y-4`,children:[(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{className:`pb-3`,children:(0,L.jsx)(ND,{className:`text-sm font-medium`,children:`Lead Scoring`})}),(0,L.jsxs)(q,{className:`space-y-2`,children:[(0,L.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,L.jsxs)(X,{variant:`outline`,className:`gap-1`,children:[(0,L.jsx)(`span`,{className:`h-2 w-2 rounded-full ${{hot:`bg-red-500`,warm:`bg-orange-500`,cold:`bg-blue-500`}[e.scoringResult.warmth]??`bg-gray-400`}`}),e.scoringResult.warmth.toUpperCase()]})}),(0,L.jsx)(`ul`,{className:`text-xs text-muted-foreground space-y-1`,children:e.scoringResult.reasons.map((e,t)=>(0,L.jsxs)(`li`,{className:`flex items-start gap-1`,children:[(0,L.jsx)(ZC,{className:`h-2 w-2 mt-1.5 flex-shrink-0`}),e]},t))})]})]}),e.classificationResult&&(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{className:`pb-3`,children:(0,L.jsx)(ND,{className:`text-sm font-medium`,children:`Classification Result`})}),(0,L.jsxs)(q,{className:`space-y-2`,children:[(0,L.jsx)(X,{variant:e.classificationResult===`interested`?`default`:e.classificationResult===`not_interested`?`destructive`:e.classificationResult===`deferred`||e.classificationResult===`unclear`?`outline`:`secondary`,children:e.classificationResult}),e.classificationResult===`deferred`&&e.classificationFollowUpHours!=null&&(0,L.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Follow-up in `,e.classificationFollowUpHours>=24?`${Math.round(e.classificationFollowUpHours/24)}d`:`${e.classificationFollowUpHours}h`]})]})]}),e.qualificationData&&(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{className:`pb-3`,children:(0,L.jsx)(ND,{className:`text-sm font-medium`,children:`Qualification Progress`})}),(0,L.jsx)(q,{children:(0,L.jsxs)(`div`,{className:`space-y-2 text-sm`,children:[(0,L.jsx)(vq,{label:`Consultation`,value:e.qualificationData.openToConsultation}),(0,L.jsx)(vq,{label:`Timeline`,value:e.qualificationData.timeline}),(0,L.jsx)(vq,{label:`Budget`,value:e.qualificationData.budgetMin||e.qualificationData.budgetMax?`$${e.qualificationData.budgetMin??`?`}â$${e.qualificationData.budgetMax??`?`}`:null}),(0,L.jsx)(vq,{label:`Property Type`,value:e.qualificationData.propertyType}),(0,L.jsx)(vq,{label:`Transaction`,value:e.qualificationData.transactionType}),(0,L.jsx)(vq,{label:`District`,value:e.qualificationData.districtPreference}),e.qualificationData.isComplete&&(0,L.jsx)(X,{className:`mt-2`,children:`Qualification Complete`})]})})]}),e.assignmentResult&&(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{className:`pb-3`,children:(0,L.jsx)(ND,{className:`text-sm font-medium`,children:`Agent Assignment`})}),(0,L.jsxs)(q,{className:`space-y-2`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(X,{children:e.assignmentResult.agentName}),e.assignmentResult.isArticleAttribution&&(0,L.jsx)(X,{variant:`outline`,children:`Article Attribution`})]}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.assignmentResult.reason}),e.assignmentResult.scores&&(0,L.jsxs)(`div`,{className:`text-xs space-y-1 mt-2`,children:[(0,L.jsx)(`p`,{className:`font-medium`,children:`Score Breakdown:`}),Object.entries(e.assignmentResult.scores).map(([e,t])=>(0,L.jsxs)(`div`,{className:`flex justify-between`,children:[(0,L.jsx)(`span`,{className:`text-muted-foreground capitalize`,children:e}),(0,L.jsx)(`span`,{children:typeof t==`number`?t.toFixed(1):String(t)})]},e))]}),e.assignmentResult.alternatives&&e.assignmentResult.alternatives.length>0&&(0,L.jsxs)(`div`,{className:`text-xs mt-2`,children:[(0,L.jsx)(`p`,{className:`font-medium text-muted-foreground`,children:`Alternatives:`}),e.assignmentResult.alternatives.map((t,n)=>(0,L.jsxs)(`span`,{className:`text-muted-foreground`,children:[t.agentName,` (`,t.totalScore?.toFixed(1),`)`,n<e.assignmentResult.alternatives.length-1?`, `:``]},n))]})]})]}),e.groupResult&&(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{className:`pb-3`,children:(0,L.jsx)(ND,{className:`text-sm font-medium`,children:`WhatsApp Group (Simulated)`})}),(0,L.jsxs)(q,{className:`space-y-2 text-sm`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`Group: `}),(0,L.jsx)(`span`,{className:`font-medium`,children:e.groupResult.groupName})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`Agent: `}),(0,L.jsx)(`span`,{children:e.groupResult.agentName})]})]})]}),(0,L.jsx)(_q,{stage:e.stage,onInjectError:n,loading:r}),(0,L.jsxs)(lA,{children:[(0,L.jsx)(uA,{asChild:!0,children:(0,L.jsxs)(W,{variant:`outline`,size:`sm`,disabled:r,className:`w-full`,children:[(0,L.jsx)(vT,{className:`mr-1 h-4 w-4`}),`Clean Up This Simulation`]})}),(0,L.jsxs)(pA,{children:[(0,L.jsxs)(mA,{children:[(0,L.jsx)(gA,{children:`Delete this simulation?`}),(0,L.jsx)(_A,{children:`This will remove the simulation and its data.`})]}),(0,L.jsxs)(hA,{children:[(0,L.jsx)(yA,{children:`Cancel`}),(0,L.jsx)(vA,{onClick:t,children:`Delete`})]})]})]})]})}function _q({stage:e,onInjectError:t,loading:n}){let r=e===`awaiting_reply`||e===`qualifying`,i=e===`qualified`,a=e===`assigned`,o=r||i||a,[s,c]=(0,_.useState)(!1);return o?(0,L.jsx)(rK,{open:s,onOpenChange:c,children:(0,L.jsxs)(K,{children:[(0,L.jsx)(iK,{asChild:!0,children:(0,L.jsx)(MD,{className:`pb-3 cursor-pointer select-none hover:bg-muted/50 transition-colors`,children:(0,L.jsxs)(ND,{className:`text-sm font-medium flex items-center justify-between`,children:[(0,L.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(xT,{className:`h-4 w-4 text-amber-500`}),`Error Injection`]}),(0,L.jsx)(zC,{className:`h-4 w-4 text-muted-foreground transition-transform ${s?`rotate-180`:``}`})]})})}),(0,L.jsx)(aK,{children:(0,L.jsxs)(q,{className:`space-y-2 pt-0`,children:[(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground mb-3`,children:`Test edge cases by injecting errors into the pipeline`}),r&&(0,L.jsxs)(W,{variant:`outline`,size:`sm`,className:`w-full justify-start`,disabled:n,onClick:()=>t(`gibberish`),children:[n?(0,L.jsx)(Ew,{className:`mr-2 h-4 w-4 animate-spin`}):(0,L.jsx)(Nw,{className:`mr-2 h-4 w-4`}),`Send Gibberish Reply`]}),i&&(0,L.jsxs)(W,{variant:`outline`,size:`sm`,className:`w-full justify-start`,disabled:n,onClick:()=>t(`no_agents`),children:[n?(0,L.jsx)(Ew,{className:`mr-2 h-4 w-4 animate-spin`}):(0,L.jsx)(MT,{className:`mr-2 h-4 w-4`}),`No Eligible Agents`]}),a&&(0,L.jsxs)(W,{variant:`outline`,size:`sm`,className:`w-full justify-start`,disabled:n,onClick:()=>t(`missing_phone`),children:[n?(0,L.jsx)(Ew,{className:`mr-2 h-4 w-4 animate-spin`}):(0,L.jsx)(xT,{className:`mr-2 h-4 w-4`}),`Agent Missing Phone`]})]})})]})}):null}function vq({label:e,value:t}){return(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:e}),t==null?(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground
156/50`,children:`--`}):(0,L.jsx)(X,{variant:`outline`,className:`text-xs`,children:String(t)})]})}var yq=[{key:`awaiting_reply`,label:`Outreach Sent`},{key:`qualifying`,label:`Qualifying`},{key:`awaiting_consent`,label:`Consent`},{key:`qualified`,label:`Qualified`},{key:`assigned`,label:`Assigned`},{key:`completed`,label:`Group Created`}],bq={};yq.forEach((e,t)=>{bq[e.key]=t}),bq.started=-1,bq.not_interested=-1,bq.lost=-1;function xq(e){return bq[e]??-1}var Sq={budget:``,bedrooms:``,location:``,buyOrSell:``,buyingTimeline:``,buyPropertyType:``,ownStayOrInvestment:``},Cq={hot:{phone:``,name:`John Tan`,source:`Ryan J`,profile:{...Sq,budget:`$1.5M - $2M`,bedrooms:`3`,location:`D15 - East Coast / Marine Parade`,buyOrSell:`Buying`,buyingTimeline:`Within 3 months`,buyPropertyType:`Private (Condo/EC/Landed)`,ownStayOrInvestment:`For Own Stay only`}},warm:{phone:``,name:`Sarah Lee`,source:`Stacked`,profile:{...Sq,budget:`$1M - $1.5M`,buyOrSell:`Buying`,buyingTimeline:`3-6 months from now`,buyPropertyType:`Private (Condo/EC/Landed)`,ownStayOrInvestment:`For Own Stay only`}}};function wq(){let e=ri(),[t,n]=(0,_.useState)(!1),[r,i]=(0,_.useState)({phone:``,name:``,source:``,testAgentPhone:``,profile:{...Sq}}),a=(0,_.useRef)(null),o=(0,_.useRef)(0),{data:s}=vi({queryKey:[`sandbox-status`],queryFn:async()=>(await H(`/api/sandbox/status`)).data,refetchInterval:3e3}),c=s??{active:!1},l=c.stage??`started`,u=l===`completed`||l===`not_interested`||l===`lost`,{data:d}=vi({queryKey:[`sandbox-messages`,c.leadId],queryFn:async()=>{if(!c.leadId)return[];let e=((await H(`/api/messages/conversations`)).data??[]).filter(e=>e.isSandboxTest===!0);if(e.length===0)return[];let t=[];for(let n of e){let e=await H(`/api/messages?conversationId=${n.id}`);e.data&&t.push(...e.data.map(e=>({...e,conversationType:n.type})))}return t.sort((e,t)=>new Date(e.timestamp).getTime()-new Date(t.timestamp).getTime()),t},enabled:c.active,refetchInterval:3e3}),f=d??[];(0,_.useEffect)(()=>{f.length>o.current&&a.current&&(a.current.scrollTop=a.current.scrollHeight),o.current=f.length},[f.length]);async function p(){if(!r.phone.trim()){z.error(`Phone number is required`);return}if(!r.name.trim()){z.error(`Name is required`);return}n(!0);try{let t=Object.entries(r.profile).filter(([,e])=>e.trim()!==``),n=t.length>0?Object.fromEntries(t):void 0,i=await H(`/api/sandbox/start`,{method:`POST`,body:JSON.stringify({phone:r.phone,name:r.name,source:r.source,leadProfileData:n,testAgentPhone:r.testAgentPhone.trim()||void 0})});i.success?(e.invalidateQueries({queryKey:[`sandbox-status`]}),z.success(`Sandbox test started â outreach message sent`)):z.error(i.error??`Failed to start sandbox test`)}catch(e){z.error(e instanceof Error?e.message:`Failed to start sandbox test`)}finally{n(!1)}}async function m(){n(!0);try{await H(`/api/sandbox/cancel`,{method:`POST`}),e.invalidateQueries({queryKey:[`sandbox-status`]}),e.invalidateQueries({queryKey:[`sandbox-messages`]}),z.success(`Sandbox test cancelled`)}catch(e){z.error(e instanceof Error?e.message:`Failed to cancel`)}finally{n(!1)}}async function h(){n(!0);try{let t=await H(`/api/sandbox/cleanup`,{method:`POST`});if(t.success){e.invalidateQueries({queryKey:[`sandbox-status`]}),e.invalidateQueries({queryKey:[`sandbox-messages`]});let n=t.data.deleted;z.success(`Cleaned up ${n.leads} lead(s), ${n.conversations} conversation(s), ${n.assignments} assignment(s)`)}}catch(e){z.error(e instanceof Error?e.message:`Cleanup failed`)}finally{n(!1)}}function g(e){let t=Cq[e];i({phone:r.phone,name:t.name,source:t.source,testAgentPhone:r.testAgentPhone,profile:{...t.profile}})}return(0,L.jsxs)(`div`,{className:`p-6 max-w-6xl mx-auto space-y-6`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`h1`,{className:`text-2xl font-bold tracking-tight`,children:`Sandbox Testing`}),(0,L.jsx)(`p`,{className:`text-muted-foreground text-sm mt-1`,children:`Test the full pipeline with real WhatsApp messages. The recipient replies on their phone and the system processes everything live.`})]}),(0,L.jsxs)(`div`,{className:`flex items-start gap-3 p-3 rounded-lg border border-orange-200 bg-orange-50 text-sm`,children:[(0,L.jsx)(xT,{className:`h-5 w-5 text-orange-600 shrink-0 mt-0.5`}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`p`,{className:`font-medium text-orange-800`,children:`This sends real WhatsApp messages`}),(0,L.jsx)(`p`,{className:`text-orange-700 mt-0.5`,children:`Messages bypass the DRY_RUN gate for the sandbox conversation only. Use a test phone number you control. Max 1 active test at a time.`})]})]}),c.active&&(0,L.jsx)(K,{children:(0,L.jsx)(q,{className:`py-4`,children:(0,L.jsx)(`div`,{className:`flex items-center justify-between`,children:yq.map((e,t)=>{let n=xq(l)>xq(e.key),r=l===e.key;return(0,L.jsxs)(`div`,{className:`flex items-center flex-1 last:flex-none`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col items-center gap-1`,children:[(0,L.jsx)(`div`,{className:`h-8 w-8 rounded-full flex items-center justify-center text-xs font-medium border-2 transition-colors ${n?`bg-green-500 border-green-500 text-white`:r?l===`
156not_interested`||l===`lost`?`bg-red-100 border-red-500 text-red-700`:`bg-blue-100 border-blue-500 text-blue-700 animate-pulse`:`bg-muted border-muted-foreground/20 text-muted-foreground`}`,children:n?(0,L.jsx)(KC,{className:`h-4 w-4`}):t+1}),(0,L.jsx)(`span`,{className:`text-xs ${r?`font-medium`:`text-muted-foreground`}`,children:e.label})]}),t<yq.length-1&&(0,L.jsx)(`div`,{className:`flex-1 h-0.5 mx-2 mt-[-16px] ${n?`bg-green-500`:`bg-muted`}`})]},e.key)})})})}),(0,L.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-[400px_1fr]`,children:[(0,L.jsx)(`div`,{className:`space-y-4`,children:c.active?(0,L.jsx)(Oq,{status:c,onCancel:m,onCleanup:h,loading:t,isTerminal:u}):(0,L.jsx)(Dq,{formData:r,setFormData:i,onSubmit:p,onPreset:g,loading:t})}),(0,L.jsxs)(`div`,{className:`flex flex-col h-[calc(100vh-12rem)] min-h-[500px] rounded-lg border bg-card`,children:[(0,L.jsxs)(`div`,{className:`h-14 px-4 border-b flex items-center justify-between shrink-0`,children:[(0,L.jsx)(`div`,{className:`flex items-center gap-2 min-w-0`,children:c.active?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`div`,{className:`h-8 w-8 rounded-full bg-primary/10 text-primary flex items-center justify-center text-xs font-medium shrink-0`,children:c.name?c.name.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2):`?`}),(0,L.jsxs)(`div`,{className:`min-w-0`,children:[(0,L.jsx)(`span`,{className:`font-medium text-sm`,children:c.name??`Unknown`}),(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground ml-2`,children:c.phone??``})]}),(0,L.jsx)(X,{variant:`outline`,className:`text-xs shrink-0 border-purple-300 bg-purple-50 text-purple-700`,children:`Sandbox`}),c.channel&&(0,L.jsx)(X,{variant:`outline`,className:`text-[10px] shrink-0`,children:c.channel===`cloud_api`?`Cloud API`:`Baileys`}),c.groupChannel&&(0,L.jsxs)(X,{variant:`outline`,className:`text-[10px] shrink-0`,children:[`Group: `,c.groupChannel===`baileys`?`Baileys`:c.groupChannel]}),(0,L.jsx)(X,{variant:`secondary`,className:`text-[10px] shrink-0`,title:`Sandbox conversations bypass the DRY_RUN gate per-conversation`,children:`Dry-run: bypassed`})]}):(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(Nw,{className:`h-4 w-4 text-muted-foreground`}),(0,L.jsx)(`span`,{className:`text-sm font-medium`,children:`Live Conversation`})]})}),c.active&&!u&&(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,L.jsxs)(`span`,{className:`relative flex h-2 w-2`,children:[(0,L.jsx)(`span`,{className:`animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75`}),(0,L.jsx)(`span`,{className:`relative inline-flex rounded-full h-2 w-2 bg-green-500`})]}),`Live`]})]}),(0,L.jsxs)(`div`,{ref:a,className:`flex-1 overflow-y-auto p-4 space-y-3`,children:[!c.active&&(0,L.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:(0,L.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,L.jsx)(aT,{className:`h-10 w-10 mx-auto opacity-40`}),(0,L.jsx)(`p`,{children:`Start a sandbox test to see the live conversation`})]})}),c.active&&f.length===0&&(0,L.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:(0,L.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,L.jsx)(Ew,{className:`h-6 w-6 mx-auto animate-spin opacity-40`}),(0,L.jsx)(`p`,{children:`Waiting for messages...`})]})}),f.map((e,t)=>{let n=t>0?f[t-1]:null;return(0,L.jsxs)(`div`,{children:[e.conversationType===`group`&&n?.conversationType!==`group`&&(0,L.jsxs)(`div`,{className:`flex items-center gap-2 my-4`,children:[(0,L.jsx)(`div`,{className:`flex-1 border-t border-blue-200`}),(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5 px-3 py-1 rounded-full bg-blue-50 border border-blue-200`,children:[(0,L.jsx)(MT,{className:`h-3 w-3 text-blue-600`}),(0,L.jsx)(`span`,{className:`text-xs font-medium text-blue-600`,children:`WhatsApp Group Created`})]}),(0,L.jsx)(`div`,{className:`flex-1 border-t border-blue-200`})]}),(0,L.jsx)(Tq,{message:e,leadName:c.name??`Lead`})]},e.id)}),c.active&&!u&&f.length>0&&f[f.length-1]?.direction===`outbound`&&(0,L.jsx)(`div`,{className:`flex justify-start`,children:(0,L.jsx)(`div`,{className:`max-w-[70%] rounded-lg px-3 py-2 bg-muted`,children:(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5 py-1 text-xs text-muted-foreground`,children:[(0,L.jsx)(Ew,{className:`h-3 w-3 animate-spin`}),`Waiting for reply on WhatsApp...`]})})}),c.active&&!u&&f.length>
1560&&f[f.length-1]?.direction===`inbound`&&(l===`awaiting_reply`||l===`qualifying`)&&(0,L.jsx)(`div`,{className:`flex justify-end`,children:(0,L.jsx)(`div`,{className:`max-w-[70%] rounded-lg px-3 py-2 bg-primary/10`,children:(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5 py-1 text-xs text-muted-foreground`,children:[(0,L.jsx)(MC,{className:`h-3 w-3`}),(0,L.jsx)(Ew,{className:`h-3 w-3 animate-spin`}),`AI is processing...`]})})})]}),(0,L.jsxs)(`div`,{className:`border-t px-4 py-3`,children:[!c.active&&(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground text-center`,children:`Start a sandbox test to see the live conversation`}),c.active&&!u&&(0,L.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-sm text-muted-foreground`,children:[(0,L.jsx)(Vw,{className:`h-3.5 w-3.5`}),(0,L.jsx)(`span`,{children:`Replies come from the recipient's real phone`})]}),c.active&&u&&(0,L.jsxs)(`div`,{className:`flex items-center justify-center gap-3`,children:[(0,L.jsx)(X,{variant:l===`completed`?`default`:`destructive`,children:l===`completed`?`Test Complete â Group Created`:l===`not_interested`?`Lead Not Interested`:`Lead Lost`}),(0,L.jsxs)(lA,{children:[(0,L.jsx)(uA,{asChild:!0,children:(0,L.jsxs)(W,{variant:`outline`,size:`sm`,disabled:t,children:[(0,L.jsx)(vT,{className:`mr-1 h-4 w-4`}),`Clean Up`]})}),(0,L.jsxs)(pA,{children:[(0,L.jsxs)(mA,{children:[(0,L.jsx)(gA,{children:`Clean up sandbox data?`}),(0,L.jsx)(_A,{children:`This removes all sandbox test records from the database (leads, conversations, messages, assignments).`})]}),(0,L.jsxs)(hA,{children:[(0,L.jsx)(yA,{children:`Cancel`}),(0,L.jsx)(vA,{onClick:h,children:`Clean Up`})]})]})]})]})]})]})]})]})}function Tq({message:e,leadName:t}){let n=e.direction===`outbound`,r=e.conversationType===`group`;return(0,L.jsx)(`div`,{className:V(`flex`,n?`justify-end`:`justify-start`),children:(0,L.jsxs)(`div`,{className:V(`max-w-[70%] rounded-lg px-3 py-2 text-sm`,r?`bg-blue-50 border border-blue-100`:n?`bg-primary text-primary-foreground`:`bg-muted`),children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1 mb-0.5`,children:[n?(0,L.jsx)(MC,{className:`h-3 w-3 opacity-70`}):(0,L.jsx)(Vw,{className:`h-3 w-3 opacity-70`}),(0,L.jsx)(`span`,{className:V(`text-xs font-medium`,n&&!r?`text-primary-foreground/70`:`text-muted-foreground`),children:n?`Joey (AI)`:t})]}),(0,L.jsx)(`p`,{className:`whitespace-pre-wrap break-words`,children:e.body}),(0,L.jsxs)(`div`,{className:V(`flex items-center justify-end gap-1 mt-1`,n&&!r?`text-primary-foreground/70`:`text-muted-foreground`),children:[(0,L.jsx)(`span`,{className:`text-[10px]`,children:new Date(e.timestamp).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}),n&&(0,L.jsx)(Eq,{status:e.status,isGroup:r})]})]})})}function Eq({status:e,isGroup:t}){let n=t?`text-blue-400`:`text-blue-300`;switch(e){case`sent`:return(0,L.jsx)(`span`,{className:`text-[10px]`,children:`â`});case`delivered`:return(0,L.jsx)(`span`,{className:`text-[10px]`,children:`ââ`});case`read`:return(0,L.jsx)(`span`,{className:V(`text-[10px]`,n),children:`ââ`});case`failed`:return(0,L.jsx)(`span`,{className:`text-[10px] text-red-400`,children:`â`});case`pending`:return(0,L.jsx)(`span`,{className:`text-[10px] opacity-50`,children:`â¯`});default:return null}}function Dq({formData:e,setFormData:t,onSubmit:n,onPreset:r,loading:i}){function a(n,r){t({...e,profile:{...e.profile,[n]:r}})}return(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{children:[(0,L.jsxs)(ND,{className:`text-base flex items-center gap-2`,children:[(0,L.jsx)(aT,{className:`h-4 w-4`}),`Start Sandbox Test`]}),(0,L.jsx)(PD,{children:`Enter the recipient's real phone number and lead details`})]}),(0,L.jsxs)(q,{className:`space-y-4`,children:[(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(Z,{htmlFor:`phone`,children:`Phone Number *`}),(0,L.jsx)(G,{id:`phone`,placeholder:`+6591234567`,value:e.phone,onChange:n=>t({...e,phone:n.target.value})}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`International format with country code`})]}),(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsxs)(Z,{htmlFor:`testAgentPhone`,children:[`Test Agent Phone `,(0,L.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(optional)`})]}),(0,L.jsx)(G,{id:`testAgentPhone`,placeholder:`+6591234567`,value:e.testAgentPhone,onChange:n=>t({...e,testAgentPhone:n.target.value})}),(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`If set, the WhatsApp group adds this number instead of the real assigned agent. Leave blank to create the group with just the recipient (no agent pinged).`})]}),(0,L.jsx)(JT,{}),(0,L.jsxs)(`div`,{className:`flex gap-2`,children:[(0,L.jsxs)(W,{variant:`outline`,size:`sm`,onClick:()=>r(`hot`),className:`flex-1`,children:[(0,L.jsx)(`span`,{className:`mr-1 h-2 w-2 rounded-full bg-red-500
156inline-block`}),`Hot Lead`]}),(0,L.jsxs)(W,{variant:`outline`,size:`sm`,onClick:()=>r(`warm`),className:`flex-1`,children:[(0,L.jsx)(`span`,{className:`mr-1 h-2 w-2 rounded-full bg-orange-500 inline-block`}),`Warm Lead`]})]}),(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(Z,{htmlFor:`name`,children:`Name *`}),(0,L.jsx)(G,{id:`name`,placeholder:`John Tan`,value:e.name,onChange:n=>t({...e,name:n.target.value})})]}),(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(Z,{htmlFor:`source`,children:`Source / Article Author`}),(0,L.jsx)(G,{id:`source`,placeholder:`e.g. Ryan J, Stacked, etc.`,value:e.source,onChange:n=>t({...e,source:n.target.value})})]}),(0,L.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`buyOrSell`,className:`text-xs`,children:`Buy / Sell`}),(0,L.jsx)(G,{id:`buyOrSell`,placeholder:`e.g. Buying`,value:e.profile.buyOrSell,onChange:e=>a(`buyOrSell`,e.target.value)})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`budget`,className:`text-xs`,children:`Budget`}),(0,L.jsx)(G,{id:`budget`,placeholder:`e.g. $1.5M - $2M`,value:e.profile.budget,onChange:e=>a(`budget`,e.target.value)})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`propertyType`,className:`text-xs`,children:`Property Type`}),(0,L.jsx)(G,{id:`propertyType`,placeholder:`e.g. Condo, HDB, Landed`,value:e.profile.buyPropertyType,onChange:e=>a(`buyPropertyType`,e.target.value)})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`bedrooms`,className:`text-xs`,children:`Bedrooms`}),(0,L.jsx)(G,{id:`bedrooms`,placeholder:`e.g. 3`,value:e.profile.bedrooms,onChange:e=>a(`bedrooms`,e.target.value)})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`location`,className:`text-xs`,children:`Location / District`}),(0,L.jsx)(G,{id:`location`,placeholder:`e.g. D15 - East Coast`,value:e.profile.location,onChange:e=>a(`location`,e.target.value)})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsx)(Z,{htmlFor:`timeline`,className:`text-xs`,children:`Timeline`}),(0,L.jsx)(G,{id:`timeline`,placeholder:`e.g. Within 3 months`,value:e.profile.buyingTimeline,onChange:e=>a(`buyingTimeline`,e.target.value)})]}),(0,L.jsxs)(`div`,{className:`space-y-1.5 col-span-2`,children:[(0,L.jsx)(Z,{htmlFor:`purpose`,className:`text-xs`,children:`Purpose`}),(0,L.jsx)(G,{id:`purpose`,placeholder:`e.g. For Own Stay only, Investment`,value:e.profile.ownStayOrInvestment,onChange:e=>a(`ownStayOrInvestment`,e.target.value)})]})]}),(0,L.jsxs)(W,{onClick:n,disabled:i,className:`w-full`,children:[i?(0,L.jsx)(Ew,{className:`mr-2 h-4 w-4 animate-spin`}):(0,L.jsx)(eT,{className:`mr-2 h-4 w-4`}),`Start Sandbox Test`]})]})]})}function Oq({status:e,onCancel:t,onCleanup:n,loading:r,isTerminal:i}){let a={hot:`bg-red-500`,warm:`bg-orange-500`,cold:`bg-blue-500`},o=e.qualificationData??e.lead?.qualificationData??null;return(0,L.jsxs)(`div`,{className:`space-y-4`,children:[(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{className:`pb-3`,children:(0,L.jsx)(ND,{className:`text-sm font-medium`,children:`Active Test`})}),(0,L.jsxs)(q,{className:`space-y-2 text-sm`,children:[(0,L.jsxs)(`div`,{className:`flex justify-between`,children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`Name`}),(0,L.jsx)(`span`,{className:`font-medium`,children:e.name})]}),(0,L.jsxs)(`div`,{className:`flex justify-between`,children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`Phone`}),(0,L.jsx)(`span`,{className:`font-mono text-xs`,children:e.phone})]}),e.lead?.warmth&&(0,L.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`Warmth`}),(0,L.jsxs)(X,{variant:`outline`,className:`gap-1`,children:[(0,L.jsx)(`span`,{className:`h-2 w-2 rounded-full ${a[e.lead.warmth]??`bg-gray-400`}`}),e.lead.warmth.toUpperCase()]})]}),(()=>{let t=e.lead?.responseType;return t?(0,L.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`Classification`}),(0,L.jsx)(X,{variant:`secondary`,className:`text-xs`,children:String(t)})]}):null})(),(0,L.jsxs)(`div`,{className:`flex justify-between`,children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`Messages`}),(0,L.jsx)(`span`,{children:e.messageCount??0})]}),e.startedAt&&(0,L.jsxs)(`div`,{className:`flex justify-between`,children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`Started`}),(0,L.jsx)(`span`,{className:`text-xs`,children:new Date(e.startedAt).toLocaleTimeString(`en-SG`,{hour:`2-digit`,minute:`2-digit`})})]})]})]}),o&&Object.values(o).some(e=>e!=null&&e!==!1)&&(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{className:`pb-3`,children:(0,L.jsx)(ND,{className:`text-sm font-medium`,children:`Qualification Progress`})}),(0,L.jsx)(q,{children:(0,L.jsxs)(`div`,{className:`space-y-2 text-sm`,children:[(0,L.jsx)(jq,{label:`Consultation`,value:o.openToConsultation}),(0,L.jsx)(jq,{label:`Timeline`,value:o.timeline}),(0,L.jsx)(jq,{label:`Budget`,value:o.budgetMin||o.budgetMax?`$${o.budgetMin??`?`}â$${o.budgetMax??`?`}`:null}),(0,L.jsx)(jq,{label:`Property Type`,value:o.propertyType}),(0,L.jsx)(jq,{label:`Transaction`,value:o.transactionType}),(0,L.jsx)(jq,{label:`District`,value:o.districtPreference}),o.isComplete&&(0,L.jsx)(X,{className:`mt-2`,children:`Qualification Complete`})]})})]}),e.assignment&&(0,L.jsx)(Aq,{assignment:e.assignment,testAgentPhone:e.testAgentPhone}),!i&&(0,L.jsxs)(lA,{children:[(0,L.jsx)(uA,{asChild:!0,children:(0,L.jsxs)(W,{variant:`outline`,size:`sm`,disabled:r,className:`w-full text-destructive hover:text-destructive`,children:[(0,L.jsx)(XC,{className:`mr-1 h-4 w-4`}),`Cancel Test`]})}),(0,L.jsxs)(pA,{children:[(0,L.jsxs)(mA,{children:[(0,L.jsx)(gA,{children:`Cancel sandbox test?`}),(0,L.jsx)(_A,{children:`This will stop the test and mark the lead as lost. No further messages will be processed. The test data will remain in the database until cleaned up.`})]}),(0,L.jsxs)(hA,{children:[(0,L.jsx)(yA,{children:`Keep Running`}),(0,L.jsx)(vA,{onClick:t,children:`Cancel Test`})]})]})]}),i&&(0,L.jsxs)(lA,{children:[(0,L.jsx)(uA,{asChild:!0,children:(0,L.jsxs)(W,{variant:`outline`,size:`sm`,disabled:r,className:`w-full`,children:[(0,L.jsx)(vT,{className:`mr-1 h-4 w-4`}),`Clean Up All Sandbox Data`]})}),(0,L.jsxs)(pA,{children:[(0,L.jsxs)(mA,{children:[(0,L.jsx)(gA,{children:`Clean up sandbox data?`}),(0,L.jsx)(_A,{children:`This removes all sandbox test records from the database.`})]}),(0,L.jsxs)(hA,{children:[(0,L.jsx)(yA,{children:`Cancel`}),(0,L.jsx)(vA,{onClick:n,children:`Clean Up`})]})]})]})]})}var kq={assigned:{label:`Agent picked â group not created yet`,tone:`info`},group_created:{label:`WhatsApp group created`,tone:`success`},intro_sent:{label:`Intro message sent in group`,tone:`success`}
156,invite_link_sent:{label:`Invite link sent (lead privacy)`,tone:`warning`},awaiting_agent_phone:{label:`Agent has no phone â blocked`,tone:`danger`},failed:{label:`Assignment failed`,tone:`danger`}};function Aq({assignment:e,testAgentPhone:t}){let n=kq[e.status]??{label:e.status,tone:`info`},r={info:`border-blue-200 bg-blue-50 text-blue-700`,success:`border-green-200 bg-green-50 text-green-700`,warning:`border-amber-200 bg-amber-50 text-amber-700`,danger:`border-red-200 bg-red-50 text-red-700`},i=n.tone===`success`?KC:n.tone===`warning`?WC:n.tone===`danger`?XC:Ew,a=!!t,o=!a&&e.effectiveAgentPhone===null&&(e.status===`group_created`||e.status===`intro_sent`);return(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{className:`pb-3`,children:(0,L.jsxs)(ND,{className:`text-sm font-medium flex items-center gap-2`,children:[(0,L.jsx)(wT,{className:`h-3.5 w-3.5`}),`Agent Assignment`]})}),(0,L.jsxs)(q,{className:`space-y-3 text-sm`,children:[(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Assigned to`}),(0,L.jsx)(`div`,{className:`font-medium`,children:e.agentName??`Unknown agent`}),e.agentPhone&&(0,L.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono`,children:e.agentPhone}),e.isArticleAttribution&&(0,L.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,children:[(0,L.jsx)(lw,{className:`h-3 w-3`}),(0,L.jsx)(`span`,{children:`Article attribution`})]})]}),(0,L.jsxs)(`div`,{className:V(`flex items-start gap-2 rounded-md border px-2.5 py-2 text-xs`,r[n.tone]),children:[(0,L.jsx)(i,{className:V(`h-3.5 w-3.5 mt-0.5 shrink-0`,n.tone===`info`&&`animate-spin`)}),(0,L.jsx)(`span`,{className:`font-medium`,children:n.label})]}),e.waGroupId&&(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsxs)(`div`,{className:`text-xs text-muted-foreground flex items-center gap-1`,children:[(0,L.jsx)(MT,{className:`h-3 w-3`}),`WhatsApp group`]}),(0,L.jsx)(`div`,{className:`text-xs font-mono break-all text-muted-foreground/80`,children:e.waGroupId})]}),(a||o)&&(0,L.jsxs)(`div`,{className:`rounded-md border border-purple-200 bg-purple-50 px-2.5 py-2 text-xs text-purple-700 space-y-0.5`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-1 font-medium`,children:[(0,L.jsx)(aT,{className:`h-3 w-3`}),`Sandbox handoff`]}),a?(0,L.jsxs)(`div`,{children:[`Group adds test agent`,` `,(0,L.jsx)(`span`,{className:`font-mono`,children:t}),` instead of the real agent. Real agent received no message.`]}):(0,L.jsx)(`div`,{children:`No test agent set â group created with just the recipient. Real agent received no message.`})]}),e.status===`invite_link_sent`&&(0,L.jsxs)(`div`,{className:`flex items-start gap-2 text-xs text-muted-foreground`,children:[(0,L.jsx)(ww,{className:`h-3 w-3 mt-0.5 shrink-0`}),(0,L.jsx)(`span`,{children:`Lead's privacy settings blocked direct add â they got a join link via DM.`})]})]})]})}function jq({label:e,value:t}){return(0,L.jsxs)(`div`,{className:`flex justify-between`,children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:e}),t?(0,L.jsx)(`span`,{className:`font-medium`,children:String(t)}):(0,L.jsx)(ZC,{className:`h-3 w-3 text-muted-foreground/30 mt-1`})]})}var Mq=[{value:`24h`,label:`Active in last 24 hours`,hours:24},{value:`7d`,label:`Active in last 7 days`,hours:168},{value:`2w`,label:`Active in last 2 weeks`,hours:336},{value:`4w`,label:`Active in last 4 weeks`,hours:672},{value:`all`,label:`All groups (incl. stale)`,hours:0}],Nq=`4w`,Pq=[`silence_desc`,`silence_asc`,`last_activity_desc`,`last_activity_asc`,`messages_24h_desc`,`messages_24h_asc`],Fq=`silence_desc`;function Iq(e){let t=Math.round(e*60);if(t<60)return`${t}m`;let n=Math.floor(t/60),r=t%60;return n<24?`${n}h ${r}m`:`${Math.floor(n/24)}d ${n%24}h`}function Lq(e){if(e<24)return(0,L.jsx)(X,{className:`bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400`,children:`Active`});let t=`${Iq(e)} silent`;return e<48?(0,L.jsx)(X,{className:`bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-400`,children:t}):(0,L.jsx)(X,{className:`bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400`,children:t})}function Rq(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/(1e3*60*60));return n<1?`just now`:n<24?`${n}h ago`:`${Math.floor(n/24)}d ago`}
156function zq(e){return new Date(e).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function Bq(e){if(e<1)return`${Math.round(e*60)}m`;if(e<24)return`${Math.round(e)}h`;let t=Math.floor(e/24),n=Math.round(e%24);return n>0?`${t}d ${n}h`:`${t}d`}function Vq({conversationId:e,currentThreshold:t}){let[n,r]=(0,_.useState)(!1),[i,a]=(0,_.useState)(t?.toString()??``),o=ri(),s=async()=>{let t=i===``?null:parseInt(i,10);if(t!==null&&(isNaN(t)||t<=0)){z.error(`Threshold must be a positive number or empty for default`);return}try{await H(`/api/pa/groups/${e}/threshold`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({silenceThresholdHours:t})}),z.success(t?`Threshold set to ${t}h`:`Reset to global default`),r(!1),o.invalidateQueries({queryKey:[`pa-groups`]})}catch{z.error(`Failed to update threshold`)}};if(!n)return(0,L.jsx)(`button`,{onClick:e=>{e.stopPropagation(),r(!0),a(t?.toString()??``)},className:`text-sm font-medium hover:underline`,children:t?`${t}h`:`Default (global)`});let c=i===``?null:parseInt(i,10);return(0,L.jsxs)(`div`,{onClick:e=>e.stopPropagation(),children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(G,{type:`number`,min:1,placeholder:`Hours (empty = default)`,value:i,onChange:e=>a(e.target.value),className:`w-32 h-8 text-sm`,autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&s(),e.key===`Escape`&&r(!1)}}),(0,L.jsx)(W,{size:`sm`,variant:`ghost`,className:`h-8 px-2`,onClick:s,children:`Save`}),(0,L.jsx)(W,{size:`sm`,variant:`ghost`,className:`h-8 px-2`,onClick:()=>r(!1),children:`Cancel`})]}),c!==null&&!isNaN(c)&&c>0&&c<6&&(0,L.jsx)(`p`,{className:`text-xs text-orange-500 mt-1`,children:`Warning: Low thresholds may trigger frequent nudges.`})]})}function Hq({conversationId:e}){let t=(0,_.useRef)(null),n=(0,_.useRef)(null),r=yi({queryKey:[`pa-timeline`,e],queryFn:({pageParam:t=0})=>H(`/api/pa/groups/${e}/timeline?limit=50&offset=${t}`).then(e=>e.data??[]),initialPageParam:0,getNextPageParam:(e,t,n)=>{if(!(e.length<50))return n+50}}),i=(0,_.useMemo)(()=>r.data?.pages.flat()??[],[r.data]),{hasNextPage:a,isFetchingNextPage:o,fetchNextPage:s}=r;return(0,_.useEffect)(()=>{let e=t.current,r=n.current;if(!e||!r||!a)return;let i=new IntersectionObserver(e=>{e[0]?.isIntersecting&&!o&&s()},{root:e,rootMargin:`120px`});return i.observe(r),()=>i.disconnect()},[a,o,s]),r.isLoading?(0,L.jsx)(`div`,{className:`py-6 text-center text-sm text-muted-foreground`,children:`Loading timeline...`}):i.length===0?(0,L.jsx)(`div`,{className:`py-6 text-center text-sm text-muted-foreground`,children:`No messages yet`}):(0,L.jsx)(`div`,{ref:t,className:`max-h-[500px] overflow-y-auto`,children:(0,L.jsxs)(`div`,{className:`space-y-3 py-4 px-2`,children:[i.map((e,t)=>{if(e.type===`silence_gap`)return(0,L.jsxs)(`div`,{className:`flex items-center gap-3 py-1`,children:[(0,L.jsx)(`div`,{className:`flex-1 border-t border-orange-300 dark:border-orange-700`}),(0,L.jsxs)(`span`,{className:`text-xs font-medium text-orange-600 dark:text-orange-400 whitespace-nowrap`,children:[`Silent for `,Bq(e.durationHours)]}),(0,L.jsx)(`div`,{className:`flex-1 border-t border-orange-300 dark:border-orange-700`})]},t);let n=e.direction===`inbound`,r=e.direction===`outbound`&&!e.contactName?.toLowerCase().includes(`stacked`);return(0,L.jsxs)(`div`,{className:`rounded-lg border p-3 ${n?`bg-blue-50 border-blue-200 dark:bg-blue-950/30 dark:border-blue-800`:r?`bg-green-50 border-green-200 dark:bg-green-950/30 dark:border-green-800`:`bg-muted border-border`} max-w-[85%] ${n?`mr-auto`:`ml-auto`}`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-3 mb-1`,children:[(0,L.jsx)(`span`,{className:`text-xs font-semibold`,children:e.contactName}),(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground whitespace-nowrap`,children:zq(e.timestamp)})]}),(0,L.jsx)(`p`,{className:`text-sm whitespace-pre-wrap break-words`,children:e.body})]},t)}),a&&(0,L.jsx)(`div`,{ref:n,className:`flex justify-center py-2 text-xs text-muted-foreground`,children:o?`Loading more...`:``})]})})}function Uq(e){let t=Mq.find(t=>t.value===e);return t?t.value:Nq}function Wq(e){return Pq.includes(e??``)?e:Fq}function Gq(e){return e===`alert`||e===`ok`?e:`all`}function Kq(e){return e===`assignment`||e===`inbox`?e:`all`}
156function qq(e){return e===`yes`||e===`no`?e:`all`}function Jq(){let[e,t]=(0,_.useState)(null),[n,r]=jn(),i=Uq(n.get(`silence`)),a=Mq.find(e=>e.value===i)?.hours??672,o=n.get(`agent`)??``,s=Gq(n.get(`status`)),c=Kq(n.get(`source`)),l=qq(n.get(`activity24h`)),u=Wq(n.get(`sort`)),d=n.get(`search`)??``,[f,p]=(0,_.useState)(d);(0,_.useEffect)(()=>{let e=setTimeout(()=>{f!==d&&r(e=>{let t=new URLSearchParams(e);return f.trim()?t.set(`search`,f.trim()):t.delete(`search`),t},{replace:!0})},300);return()=>clearTimeout(e)},[f,d,r]),(0,_.useEffect)(()=>{d!==f&&p(d)},[d]);let m=(e,t)=>{r(n=>{let r=new URLSearchParams(n);return t===null||t===``?r.delete(e):r.set(e,t),r},{replace:!0})},h=()=>{r(new URLSearchParams,{replace:!0}),p(``)},g=e=>{let t=`${e}_desc`,n=`${e}_asc`,r=u===t?n:t;m(`sort`,r===Fq?null:r)},v=e=>u===`${e}_desc`?(0,L.jsx)(zC,{className:`h-3 w-3`}):u===`${e}_asc`?(0,L.jsx)(HC,{className:`h-3 w-3`}):null,y=(0,_.useMemo)(()=>{let e=new URLSearchParams;return e.set(`silenceMaxHours`,String(a)),d&&e.set(`search`,d),o&&e.set(`agentId`,o),s!==`all`&&e.set(`status`,s),c!==`all`&&e.set(`source`,c),l!==`all`&&e.set(`activity24h`,l),u!==Fq&&e.set(`sort`,u),e},[a,d,o,s,c,l,u]),b=y.toString(),{data:x}=vi({queryKey:[`pa-stats`,b],queryFn:()=>{let e=new URLSearchParams(y);return e.delete(`sort`),H(`/api/pa/stats?${e.toString()}`).then(e=>e.data)},refetchInterval:3e4}),{data:S}=vi({queryKey:[`pa-agents-for-filter`],queryFn:()=>H(`/api/agents`),staleTime:5*6e4}),C=S?.data??[],[w,T]=(0,_.useState)(0);(0,_.useEffect)(()=>{T(0)},[b]);let E=vi({queryKey:[`pa-groups`,b,w],queryFn:()=>{let e=new URLSearchParams(y);return e.set(`limit`,`10`),e.set(`offset`,String(w*10)),H(`/api/pa/groups?${e.toString()}`)},refetchInterval:3e4,placeholderData:e=>e}),D=E.data?.data??[],O=E.data?.total??0,k=Math.max(1,Math.ceil(O/10)),A=E.isLoading;(0,_.useEffect)(()=>{w>0&&w>=k&&T(k-1)},[w,k]);let j=Mq.find(e=>e.value===i)?.label??``,M=C.find(e=>e.id===o)?.name??o,ee=i!==Nq||!!d||!!o||s!==`all`||c!==`all`||l!==`all`;return(0,L.jsxs)(`div`,{className:`space-y-6`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,L.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Agent PA â Groups`}),(0,L.jsx)(sA,{interval:`30s`,source:`Server`})]}),(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Active agent-lead groups with conversation activity and silence monitoring`})]}),(0,L.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-4`,children:[(0,L.jsx)(Xq,{title:`Active Groups`,value:x?.activeGroups??0,icon:(0,L.jsx)(jT,{className:`h-4 w-4`})}),(0,L.jsx)(Xq,{title:`Nudges Sent`,value:x?.nudgesSent??0,icon:(0,L.jsx)(Nw,{className:`h-4 w-4`})}),(0,L.jsx)(Xq,{title:`Escalations`,value:x?.escalations??0,icon:(0,L.jsx)(OC,{className:`h-4 w-4`})}),(0,L.jsx)(Xq,{title:`Avg Silence`,value:x?.avgSilenceHours==null?`â`:`${Math.round(x.avgSilenceHours)}h`,icon:(0,L.jsx)(QC,{className:`h-4 w-4`})})]}),(0,L.jsxs)(`div`,{className:`space-y-3`,children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,L.jsxs)(`div`,{className:`relative w-full sm:w-72`,children:[(0,L.jsx)($w,{className:`pointer-events-none absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground`}),(0,L.jsx)(G,{placeholder:`Search lead, agent, or group...`,value:f,onChange:e=>p(e.target.value),className:`pl-9 pr-9 h-9`}),f&&(0,L.jsx)(`button`,{onClick:()=>p(``),className:`absolute right-2.5 top-2.5 text-muted-foreground hover:text-foreground`,"aria-label":`Clear search`,children:(0,L.jsx)(FT,{className:`h-4 w-4`})})]}),(0,L.jsxs)(wk,{value:i,onValueChange:e=>m(`silence`,e===Nq?null:e),children:[(0,L.jsx)(Dk,{className:`h-9 w-[210px]`,children:(0,L.jsx)(Ek,{})}),(0,L.jsx)(Ok,{children:Mq.map(e=>(0,L.jsx)(Ak,{value:e.value,children:e.label},e.value))})]}),(0,L.jsxs)(wk,{value:o||`all`,onValueChange:e=>m(`agent`,e===`all`?null:e),children:[(0,L.jsx)(Dk,{className:`h-9 w-[180px]`,children:(0,L.jsx)(Ek,{placeholder:`All agents`})}),(0,L.jsxs)(Ok,{children:[(0,L.jsx)(Ak,{value:`all`,children:`All agents`}),C.map(e=>(0,L.jsx)(Ak,{value:e.id,children:e.name},e.id))]})]}),(0,L.jsxs)(wk,{value:s,onValueChange:e=>m(`status`,e===`all`?null:e),children:[(0,L.jsx)(Dk,{className:`h-9 w-[140px]`,children:(0,L.jsx)(Ek,{})}),(0,L.jsxs)(Ok,{children:[(0,L.jsx)(Ak,{value:`all`,children:`Any status`}),(0,L.jsx)(Ak,{value:`alert`,children:`Alert only`}),(0,L.jsx)(Ak,{value:`ok`,children:`OK only`})]})]}),(0,L.jsxs)(wk,{value:c,onValueChange:e=>m(`source`,e===`all`?null:e),children:[(0,L.jsx)(Dk,{className:`h-9 w-[150px]`,children:(0,L.jsx)(Ek,{})}),(0,L.jsxs)(Ok,{children:[(0,L.jsx)(Ak,{value:`all`,children:`Any source`}),(0,L.jsx)(Ak,{value:`assignment`,children:`Assignment`}),(0,L.jsx)(Ak,{value:`inbox`,children:`Inbox-tracked`})]})]}),(0,L.jsxs)(wk,{value:l,onValueChange:e=>m(`activity24h`,e===`all`?null:e),children:[(0,L.jsx)(Dk,{className:`h-9 w-[160px]`,children:(0,L.jsx)(Ek,{})}),(0,L.jsxs)(Ok,{children:[(0,L.jsx)(Ak,{value:`all`,children:`Any 24h activity`}),(0,L.jsx)(Ak,{value:`yes`,children:`With 24h messages`}),(0,L.jsx)(Ak,{value:`no`,children:`Silent past 24h`})]})]}),ee&&(0,L.jsx)(W,{variant:`ghost`,size:`sm`,onClick:h,children:`Clear all`})]}),(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,L.jsx)(Yq,{label:`Silence: ${j}`,onClear:()=>m(`silence`,`all`)}),d&&(0,L.jsx)(Yq,{label:`Search: "${d}"`,onClear:()=>{p(``),m(`search`,null)}}),o&&(0,L.jsx)(Yq,{label:`Agent: ${M}`,onClear:()=>m(`agent`,null)}),s!==`all`&&(0,L.jsx)(Yq,{label:`Status: ${s===`alert`?`Alert`:`OK`}`,onClear:()=>m(`status`,null)}),c!==`all`&&(0,L.jsx)(Yq,{label:`Source: ${c===`assignment`?`Assignment`:`Inbox-tracked`}`,onClear:()=>m(`source`,null)}),l!==`all`&&(0,L.jsx)(Yq,{label:`24h activity: ${l===`yes`?`Yes`:`No`}`,onClear:()=>m(`activity24h`,null)})]})]}),(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{className:`pb-3`,children:(0,L.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(ND,{className:`text-base`,children:`Group Activity`}),(0,L.jsxs)(PD,{children:[u===`silence_desc`&&`Sorted by silence duration â most silent first`,u===`silence_asc`&&`Sorted by silence duration â least silent first`,u===`last_activity_desc`&&`Sorted by last activity â most recent first`,u===`last_activity_asc`&&`Sorted by last activity â oldest first`,u===`messages_24h_desc`&&`Sorted by 24h messages â most first`,u===`messages_24h_asc`&&`Sorted by 24h messages â fewest first`]})]}),O>0&&(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsxs)(`span`,{className:`text-sm text-muted-foreground whitespace-nowrap`,children:[`Page `,w+1,` of `,k,` · `,O,` groups`]}),(0,L.jsx)(W,{variant:`outline`,size:`icon`,className:`h-8 w-8`,onClick:()=>T(e=>Math.max(0,e-1)),disabled:w===0||E.isFetching,"aria-label":`Previous page`,children:(0,L.jsx)(BC,{className:`h-4 w-4`})}),(0,L.jsx)(W,{variant:`outline`,size:`icon`,className:`h-8 w-8`,onClick:()=>T(e=>Math.min(k-1,e+1)),disabled:w+1>=k||E.isFetching,"aria-label":`Next page`,children:(0,L.jsx)(VC,{className:`h-4 w-4`})})]})]})}),(0,L.jsx)(q,{children:(0,L.jsx)(`div`,{className:`rounded-md border`,children:(0,L.jsxs)(Pk,{children:[(0,L.jsx)(Fk,{children:(0,L.jsxs)(Lk,{children:[(0,L.jsx)(J,{className:`w-8`}),(0,L.jsx)(J,{children:`Lead`}),(0,L.jsx)(J,{children:`Agent`}
156),(0,L.jsx)(J,{className:`cursor-pointer select-none`,onClick:()=>g(`last_activity`),children:(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`Last Activity `,v(`last_activity`)]})}),(0,L.jsx)(J,{className:`cursor-pointer select-none`,onClick:()=>g(`silence`),children:(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`Silence `,v(`silence`)]})}),(0,L.jsx)(J,{className:`cursor-pointer select-none`,onClick:()=>g(`messages_24h`),children:(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`Messages (24h) `,v(`messages_24h`)]})}),(0,L.jsx)(J,{children:`Status`})]})}),(0,L.jsx)(Ik,{children:A?(0,L.jsx)(Lk,{children:(0,L.jsx)(Y,{colSpan:7,className:`text-center text-muted-foreground py-8`,children:`Loading groups...`})}):D.length===0?(0,L.jsx)(Lk,{children:(0,L.jsx)(Y,{colSpan:7,className:`text-center text-muted-foreground py-8`,children:ee?(0,L.jsxs)(`span`,{children:[`No groups match your filters.`,` `,(0,L.jsx)(`button`,{onClick:h,className:`underline hover:no-underline`,children:`Clear all`})]}):(0,L.jsx)(L.Fragment,{children:`No active groups yet. Groups appear here after leads are assigned to agents (or when an inbox group name starts with "Stacked Chat"). SHL groups are delivery channels, not monitored here.`})})}):D.map(n=>{let r=e===n.conversationId;return(0,L.jsxs)(_.Fragment,{children:[(0,L.jsxs)(Lk,{className:`cursor-pointer`,onClick:()=>t(r?null:n.conversationId),children:[(0,L.jsx)(Y,{className:`w-8 pr-0`,children:r?(0,L.jsx)(zC,{className:`h-4 w-4 text-muted-foreground`}):(0,L.jsx)(VC,{className:`h-4 w-4 text-muted-foreground`})}),(0,L.jsx)(Y,{className:`font-medium`,children:(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`span`,{children:n.leadName}),n.source===`inbox`&&(0,L.jsx)(X,{variant:`outline`,className:`text-[10px] uppercase tracking-wide`,title:`Inbox-tracked group (matched by name prefix; no assignment)`,children:`Inbox`})]})}),(0,L.jsx)(Y,{children:n.agentName}),(0,L.jsx)(Y,{className:`text-muted-foreground`,children:n.lastActivityAt?Rq(n.lastActivityAt):`No activity`}),(0,L.jsx)(Y,{children:n.silenceDurationHours==null?(0,L.jsx)(X,{variant:`outline`,children:`Unknown`}):Lq(n.silenceDurationHours)}),(0,L.jsx)(Y,{className:`text-muted-foreground`,children:n.messageCount24h}),(0,L.jsx)(Y,{children:n.hasActiveAlert?(0,L.jsx)(X,{variant:`destructive`,children:`Alert`}):(0,L.jsx)(X,{variant:`outline`,children:`OK`})})]}),r&&(0,L.jsx)(Lk,{children:(0,L.jsxs)(Y,{colSpan:7,className:`p-0 bg-muted/30`,children:[(0,L.jsxs)(`div`,{className:`px-6 pt-4 pb-2 flex items-center gap-3 border-b border-border/50`,children:[(0,L.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:`Silence threshold:`}),(0,L.jsx)(Vq,{conversationId:n.conversationId,currentThreshold:n.silenceThresholdHours})]}),(0,L.jsx)(Hq,{conversationId:n.conversationId})]})})]},n.conversationId)})})]})})})]})]})}function Yq({label:e,onClear:t}){return(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-muted px-2.5 py-1 text-xs`,children:[e,(0,L.jsx)(`button`,{onClick:t,className:`text-muted-foreground hover:text-foreground`,"aria-label":`Remove ${e}`,children:(0,L.jsx)(FT,{className:`h-3 w-3`})})]})}function Xq({title:e,value:t,icon:n}){return(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,L.jsx)(PD,{children:e}),n]}),(0,L.jsx)(q,{children:(0,L.jsx)(`div`,{className:`text-2xl font-bold`,children:t})})]})}var Zq=20;function Qq(e){return new Date(e).toLocaleDateString(`en-SG`,{day:`numeric`,month:`short`,year:`numeric`})}function $q(e){return new Date(e).toLocaleString(`en-SG`,{day:`numeric`,month:`short`,hour:`2-digit`,minute:`2-digit`})}function eJ(e){return e===`sent`?(0,L.jsx)(X,{className:`bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-300`,children:`Sent`}):e===`drafted`?(0,L.jsx)(X,{className:`bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-300`,children:`Draft`}):e===`empty`?(0,L.jsx)(X,{className:`bg-slate-100 text-slate-700 dark:bg-slate-800 dark:text-slate-300`,children:`No leads`}):e===`missing_phone`?(0,L.jsx)(X,{className:`bg-slate-100 text-slate-700 dark:bg-slate-800 dark:text-slate-300`,children:`No phone`}):(0,L.jsx)(X,{className:`bg-orange-100 text-orange-800 dark:bg-orange-900/30 dark:text-orange-300`,children:`Not delivered`})}function tJ(e,t){let n=`${e.leadCount} lead${e.leadCount===1?``:`s`}`;switch(e.outcome){case`sent`:z.success(`Sent to ${t}'s SHL group â ${n}.`);return;case`drafted`:z.success(`Draft created in ${t}'s SHL group â ${n}. Review & send from the inbox.`);return;case`empty`:z.info(`No active leads for ${t} â nothing to send.`);return;case`unrouted`:z.error(e.unroutedReason===`multi_owner`?`${t}'s SHL group names a 2-agent pair (not supported).`:e.unroutedReason===`agent_absent`?`${t} isn't a member of their SHL group.`:e.unroutedReason===`ambiguous`?`SHL group subject matches multiple agents.`:`No SHL group mapped for ${t} â map it in the Agents tab.`);return;case`failed`:z.error(`Delivery failed: ${e.error??`unknown error`}`);return;case`busy`:z.info(`A digest run for ${t} is already in progress.`);return;case`skipped`:z.info(`Already up to date for this week.`);return}}function nJ({agentId:e,agentName:t,status:n,size:r=`sm`,stopPropagation:i=!1}
156){let a=ri(),{data:o}=vi({queryKey:[`whatsapp-status`],queryFn:()=>H(`/api/whatsapp/status`),refetchInterval:15e3,retry:!1}),s=o?.data.dryRun??!0,c=o?.data.baileys.status===`connected`,l=!s&&!c,u=t??`this agent`,d=R({mutationFn:()=>H(`/api/pa/weekly-digests/run-for-agent/${e}`,{method:`POST`}).then(e=>e.data),onSuccess:e=>{tJ(e,u),a.invalidateQueries({queryKey:[`pa-weekly-digests`]}),a.invalidateQueries({queryKey:[`pa-weekly-digests-banner`]})},onError:e=>{z.error(e instanceof Error?e.message:`Failed to run digest`)}}),f=s?`Draft to SHL group`:`Send to SHL group`;return(0,L.jsxs)(lA,{children:[(0,L.jsx)(uA,{asChild:!0,children:(0,L.jsx)(W,{size:r,variant:`outline`,disabled:l||d.isPending,title:l?`WhatsApp disconnected`:void 0,onClick:i?e=>e.stopPropagation():void 0,children:d.isPending?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(Ew,{className:`mr-2 h-4 w-4 animate-spin`}),`Running...`]}):f})}),(0,L.jsxs)(pA,{children:[(0,L.jsxs)(mA,{children:[(0,L.jsx)(gA,{children:s?`Draft weekly digest?`:`Send weekly digest?`}),(0,L.jsxs)(_A,{children:[`Regenerate this week's digest for `,u,` and`,` `,s?`create a draft in`:`post it to`,` their SHL group.`,n===`sent`&&(0,L.jsx)(`span`,{className:`mt-2 block font-medium text-destructive`,children:`This agent's brief for this week was already sent â continuing posts a second message to the group.`})]})]}),(0,L.jsxs)(hA,{children:[(0,L.jsx)(yA,{children:`Cancel`}),(0,L.jsx)(vA,{onClick:()=>d.mutate(),children:s?`Create draft`:`Send now`})]})]})]})}function rJ(){let[e,t]=(0,_.useState)(`all`),[n,r]=(0,_.useState)(null),i=vi({queryKey:[`pa-weekly-digests-banner`],queryFn:()=>H(`/api/pa/weekly-digests-banner`).then(e=>e.data),refetchInterval:6e4}),a=vi({queryKey:[`pa-weekly-digests-no-shl-group`],queryFn:()=>H(`/api/pa/weekly-digests-no-shl-group-alert`).then(e=>e.data),refetchInterval:6e4}),o=a.data?.agents??[],s=vi({queryKey:[`agents`],queryFn:()=>H(`/api/agents`)}).data?.data??[],c=yi({queryKey:[`pa-weekly-digests`,e],queryFn:({pageParam:t=0})=>{let n=new URLSearchParams;return n.set(`limit`,String(Zq)),n.set(`offset`,String(t)),e&&e!==`all`&&n.set(`agentId`,e),H(`/api/pa/weekly-digests?${n.toString()}`)},initialPageParam:0,getNextPageParam:(e,t,n)=>{if(!(n+Zq>=(e.total??0)))return n+Zq}}),l=(0,_.useMemo)(()=>c.data?.pages.flatMap(e=>e.data??[])??[],[c.data]),u=c.data?.pages[0]?.total??0;return(0,L.jsxs)(`div`,{className:`space-y-6`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Weekly Digests`}),(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Per-agent Monday-morning briefs covering all active leads from the past 4 weeks.`})]}),(0,L.jsx)(K,{children:(0,L.jsx)(q,{className:`py-4`,children:i.isLoading?(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading status...`}):i.data?.periodEnd?(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2 text-sm`,children:[(0,L.jsxs)(`span`,{className:`font-medium`,children:[`Latest: `,Qq(i.data.periodEnd)]}),(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),(0,L.jsxs)(`span`,{children:[(0,L.jsx)(`span`,{className:`font-semibold text-green-700 dark:text-green-400`,children:i.data.sent}),` `,`sent`]}),(0,L.jsxs)(`span`,{children:[(0,L.jsx)(`span`,{className:`font-semibold text-yellow-700 dark:text-yellow-400`,children:i.data.drafted}),` `,`drafted`]}),i.data.undelivered>0&&(0,L.jsxs)(`span`,{children:[(0,L.jsx)(`span`,{className:`font-semibold text-orange-700 dark:text-orange-400`,children:i.data.undelivered}),` `,`not delivered`]}),i.data.empty>0&&(0,L.jsxs)(`span`,{children:[(0,L.jsx)(`span`,{className:`font-semibold text-slate-700 dark:text-slate-300`,children:i.data.empty}),` `,`no leads`]}),i.data.missingPhone>0&&(0,L.jsxs)(`span`,{children:[(0,L.jsx)(`span`,{className:`font-semibold text-slate-700 dark:text-slate-300`,children:i.data.missingPhone}),` `,`no phone`]}),(0,L.jsxs)(`span`,{className:`text-muted-foreground`,children:[`of `,i.data.agentsTotal,` agents`]}),i.data.unroutedGroups>0&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),(0,L.jsxs)(`span`,{className:`text-orange-700 dark:text-orange-400`,children:[`â `,i.data.unroutedGroups,` inbox-tracked group`,i.data.unroutedGroups===1?``:`s`,` need agent assignment`]})]})]}):(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No digests have been generated yet. Use the AI Training tab to send a preview, or wait until Monday 08:00 SGT for the first scheduled run.`})})}),o.length>0&&(0,L.jsx)(K,{className:`border-orange-200 dark:border-orange-900`,children:(0,L.jsxs)(q,{className:`py-4`,children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1 text-sm`,children:[(0,L.jsxs)(`span`,{className:`font-medium text-orange-700 dark:text-orange-400`,children:[`â `,a.data?.totalLeads??0,` active lead`,(a.data?.totalLeads??0)===1?``:`s`,` not reaching an SHL group`]}),(0,L.jsxs)(`span`,{className:`text-muted-foreground`,children:[`across `,o.length,` agent`,o.length===1?``:`s`,` with no SHL group mapped â assign these leads to the pair, or map a group in the Agents tab.`]})]}),(0,L.jsx)(`div`,{className:`mt-3 grid gap-x-6 gap-y-1 sm:grid-cols-2`,children:o.map(e=>(0,L.jsxs)(Cn,{to:`/agents`,className:`flex items-center justify-between text-sm hover:underline`,children:[(0,L.jsx)(`span`,{className:`font-medium`,children:e.agentName??`Unknown agent`}),(0,L.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.leadCount,` lead`,e.leadCount===1?``:`s`]})]},e.agentId))})]})}),(0,L.jsx)(`div`,{className:`flex flex-wrap items-center gap-3`,children:(0,L.jsxs)(wk,{value:e,onValueChange:t,children:[(0,L.jsx)(Dk,{className:`w-[220px]`,children:(0,L.jsx)(Ek,{placeholder:`All Agents`})}),(0,L.jsxs)(Ok,{children:[(0,L.jsx)(Ak,{value:`all`,children:`All Agents`}),s.map(e=>(0,L.jsx)(Ak,{value:e.id,children:e.name},e.id))]})]})}),c.isLoading?(0,L.jsx)(`div`,{className:`rounded-md border p-8 text-center text-muted-foreground`,children:`Loading...`}):l.length===0?(0,L.jsx)(`div`,{className:`rounded-md border p-8 text-center text-muted-foreground`,children:`No digests yet. The first scheduled run is Monday 08:00 SGT â or trigger a preview from the AI Training tab.`}):(0,L.jsxs)(`div`,{className:`space-y-3`,children:[(0,L.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Showing `,l.length,` of `,u,` digests`]}),l.map(e=>(0,L.jsx)(iJ,{row:e,onClick:()=>r(e.id)},e.id)),c.hasNextPage&&(0,L.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,L.jsx)(W,{variant:`outline`,onClick:()=>c.fetchNextPage(),disabled:c.isFetchingNextPage,children:c.isFetchingNextPage?`Loading...`:`Load More`})})]}),(0,L.jsx)(aJ,{digestId:n,open:n!==null,onOpenChange:e=>{e||r(null)}})]})}function iJ({row:e,onClick:t}){let{tierBreakdown:n}=e;
156return(0,L.jsx)(K,{className:`cursor-pointer transition hover:bg-muted/30`,onClick:t,children:(0,L.jsx)(q,{className:`py-4`,children:(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,L.jsxs)(`div`,{className:`space-y-1`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,L.jsx)(`span`,{className:`font-semibold`,children:e.agentName??`(unknown agent)`}),(0,L.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),(0,L.jsxs)(`span`,{className:`text-sm text-muted-foreground`,children:[`Week of `,Qq(e.periodEnd)]})]}),(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 text-sm`,children:[(0,L.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.leadCount,` lead`,e.leadCount===1?``:`s`]}),(0,L.jsxs)(`span`,{className:`font-mono text-xs`,children:[(0,L.jsxs)(`span`,{className:`text-red-700 dark:text-red-400`,children:[n.red,`ð´`]}),` `,(0,L.jsxs)(`span`,{className:`text-yellow-700 dark:text-yellow-400`,children:[n.yellow,`ð¡`]}),` `,(0,L.jsxs)(`span`,{className:`text-green-700 dark:text-green-400`,children:[n.green,`ð¢`]})]})]})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-3`,children:[eJ(e.status),e.dmSentAt&&(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:$q(e.dmSentAt)}),(0,L.jsx)(nJ,{agentId:e.agentId,agentName:e.agentName,status:e.status,stopPropagation:!0})]})]})})})}function aJ({digestId:e,open:t,onOpenChange:n}){let r=vi({queryKey:[`pa-weekly-digest`,e],queryFn:()=>H(`/api/pa/weekly-digests/${e}`).then(e=>e.data),enabled:e!==null});return(0,L.jsx)(aj,{open:t,onOpenChange:n,children:(0,L.jsx)(lj,{className:`max-w-2xl max-h-[85vh] overflow-y-auto`,children:r.isLoading?(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground py-6`,children:`Loading...`}):r.data?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(uj,{children:[(0,L.jsxs)(fj,{children:[r.data.agentName??`(unknown agent)`,` ·`,` `,Qq(r.data.periodEnd)]}),(0,L.jsxs)(pj,{children:[r.data.leadCount,` lead`,r.data.leadCount===1?``:`s`,` ·`,` `,oJ(r.data)]})]}),(0,L.jsxs)(`div`,{className:`space-y-4`,children:[(0,L.jsxs)(`section`,{children:[(0,L.jsx)(`h3`,{className:`text-sm font-medium mb-2`,children:`Message body`}),(0,L.jsx)(`pre`,{className:`rounded-md bg-muted/50 p-3 text-sm whitespace-pre-wrap font-sans`,children:r.data.messageBody})]}),(0,L.jsxs)(`section`,{children:[(0,L.jsx)(`h3`,{className:`text-sm font-medium mb-2`,children:`Per-lead breakdown`}),(0,L.jsx)(`div`,{className:`space-y-2`,children:r.data.leadSummaries.map((e,t)=>(0,L.jsxs)(`div`,{className:`rounded-md border p-2 text-sm flex items-start gap-2`,children:[(0,L.jsx)(sJ,{tier:e.finalTier}),(0,L.jsxs)(`div`,{className:`flex-1`,children:[(0,L.jsx)(`div`,{className:`font-medium`,children:e.leadName}),(0,L.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:e.summary}),(0,L.jsxs)(`div`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70 mt-1`,children:[`baseline: `,e.baselineTier,` · final: `,e.finalTier,e.aiFailed&&` · AI failed`]})]})]},t))})]}),r.data.dmConversationId&&(0,L.jsx)(`section`,{children:(0,L.jsx)(`a`,{href:`/inbox?conversation=${r.data.dmConversationId}`,className:`text-sm text-primary underline`,children:`Open SHL group in inbox â`})}),(0,L.jsx)(`div`,{className:`flex justify-end border-t pt-4`,children:(0,L.jsx)(nJ,{agentId:r.data.agentId,agentName:r.data.agentName,status:r.data.status,size:`default`})})]})]}):(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground py-6`,children:`Not found.`})})})}function oJ(e){return e.dmSentAt?`Sent ${$q(e.dmSentAt)}`:e.dmMessageId?`Drafted (awaiting manual send)`:e.leadCount===0?`No active leads â nothing to send`:e.agentPhone?`Not delivered â no routable SHL group`:`Agent has no phone number on file`}function sJ({tier:e}){return(0,L.jsx)(`span`,{className:`mt-1.5 h-2 w-2 shrink-0 rounded-full ${e===`red`?`bg-red-500`:e===`yellow`?`bg-yellow-500`:`bg-green-500`}`})}var cJ=20,lJ=[{value:`all`,label:`All`},{value:`pending`,label:`Pending`},{value:`sent`,label:`Sent`},{value:`agent_responded`,label:`Agent Responded`},{value:`escalated`,label:`Escalated`},{value:`resolved`,label:`Resolved`}],uJ={pending:`secondary`,sent:`default`,agent_responded:`default`,escalated:`destructive`,resolved:`outline`},dJ={pending:`bg-gray-100 text-gray-700 border-gray-300`,sent:`bg-blue-100 text-blue-700 border-blue-300`,agent_responded:`bg-green-100 text-green-700 border-green-300`,escalated:``,resolved:`border-green-400 text-green-600`};function fJ(e){if(e<1)return`${Math.round(e*60)}m`;if(e<24)return`${e.toFixed(1)}h`;let t=Math.floor(e/24),n=e%24;return n>0?`${t}d ${n.toFixed(0)}h`:`${t}d`}function pJ(e){if(!e.dmSentAt||!e.agentRespondedAt)return`--`;let t=new Date(e.dmSentAt).getTime();return fJ((new Date(e.agentRespondedAt).getTime()-t)/(1e3*60*60))}function mJ(e){return e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function hJ(){let[e,t]=(0,_.useState)(`all`),[n,r]=(0,_.useState)(`all`),[i,a]=(0,_.useState)(null),o=vi({queryKey:[`pa-stats`],queryFn:()=>H(`/api/pa/stats`)}),s=vi({queryKey:[`agents`],queryFn:()=>H(`/api/agents`)}),c=yi({queryKey:[`pa-alerts`,e,n],queryFn:({pageParam:t=0})=>{let r=new URLSearchParams({limit:String(cJ),offset:String(t)});return e!==`all`&&r.set(`status`,e),n!==`all`&&r.set(`agentId`,n),H(`/api/pa/alerts?${r}`)},initialPageParam:0,getNextPageParam:(e,t,n)=>{if(!(n+cJ>=(e.total??0)))return n+cJ}}),l=e=>{t(e)},u=e=>{r(e)},d=o.data?.data,f=s.data?.data??[],p=c.data?.pages[0]?.total??0,m=(0,_.useMemo)(()=>c.data?.pages.flatMap(e=>e.data??[])??[],[c.data]);return(0,L.jsxs)(`div`,{className:`space-y-6`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Silence Alerts`}),(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Nudge history and agent response tracking for quiet conversations`})]}),(0,L.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,L.jsx)(K,{children:(0,L.jsxs)(q,{className:`pt-6`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,L.jsx)(OC,{
156className:`h-4 w-4`}),(0,L.jsx)(`span`,{children:`Total Nudges`})]}),(0,L.jsx)(`p`,{className:`text-2xl font-bold mt-1`,children:d?.totalNudges??`--`})]})}),(0,L.jsx)(K,{children:(0,L.jsxs)(q,{className:`pt-6`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,L.jsx)(wT,{className:`h-4 w-4`}),(0,L.jsx)(`span`,{children:`Response Rate`})]}),(0,L.jsx)(`p`,{className:`text-2xl font-bold mt-1`,children:d?`${d.responseRate}%`:`--`})]})}),(0,L.jsx)(K,{children:(0,L.jsxs)(q,{className:`pt-6`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,L.jsx)(QC,{className:`h-4 w-4`}),(0,L.jsx)(`span`,{children:`Avg Response Time`})]}),(0,L.jsx)(`p`,{className:`text-2xl font-bold mt-1`,children:d?fJ(d.avgResponseTimeHours):`--`})]})}),(0,L.jsx)(K,{children:(0,L.jsxs)(q,{className:`pt-6`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,L.jsx)(xT,{className:`h-4 w-4`}),(0,L.jsx)(`span`,{children:`Total Escalations`})]}),(0,L.jsx)(`p`,{className:`text-2xl font-bold mt-1`,children:d?.totalEscalations??`--`})]})})]}),(0,L.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,L.jsx)(`div`,{className:`w-48`,children:(0,L.jsxs)(wk,{value:e,onValueChange:l,children:[(0,L.jsx)(Dk,{children:(0,L.jsx)(Ek,{placeholder:`Filter by status`})}),(0,L.jsx)(Ok,{children:lJ.map(e=>(0,L.jsx)(Ak,{value:e.value,children:e.label},e.value))})]})}),(0,L.jsx)(`div`,{className:`w-48`,children:(0,L.jsxs)(wk,{value:n,onValueChange:u,children:[(0,L.jsx)(Dk,{children:(0,L.jsx)(Ek,{placeholder:`Filter by agent`})}),(0,L.jsxs)(Ok,{children:[(0,L.jsx)(Ak,{value:`all`,children:`All Agents`}),f.map(e=>(0,L.jsx)(Ak,{value:e.id,children:e.name},e.id))]})]})})]}),m.length>0&&(0,L.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Showing `,m.length,` of `,p,` alerts`]}),(0,L.jsx)(`div`,{className:`rounded-md border`,children:(0,L.jsxs)(Pk,{children:[(0,L.jsx)(Fk,{children:(0,L.jsxs)(Lk,{children:[(0,L.jsx)(J,{className:`w-[30px]`}),(0,L.jsx)(J,{children:`Lead`}),(0,L.jsx)(J,{children:`Agent`}),(0,L.jsx)(J,{children:`Type`}),(0,L.jsx)(J,{children:`Silence Duration`}),(0,L.jsx)(J,{children:`Sent At`}),(0,L.jsx)(J,{children:`Status`}),(0,L.jsx)(J,{children:`Response Time`})]})}),(0,L.jsx)(Ik,{children:m.length===0?(0,L.jsx)(Lk,{children:(0,L.jsx)(Y,{colSpan:8,className:`text-center text-muted-foreground py-8`,children:`No silence alerts yet. Alerts are triggered when agent-lead groups go quiet.`})}):m.map(e=>{let t=i===e.id;return(0,L.jsxs)(_.Fragment,{children:[(0,L.jsxs)(Lk,{className:`cursor-pointer hover:bg-muted/50`,onClick:()=>a(t?null:e.id),children:[(0,L.jsx)(Y,{children:(0,L.jsx)(zC,{className:`h-4 w-4 transition-transform ${t?``:`-rotate-90`}`})}),(0,L.jsx)(Y,{className:`font-medium`,children:e.leadName}),(0,L.jsx)(Y,{children:e.agentName}),(0,L.jsx)(Y,{children:(0,L.jsx)(X,{variant:e.type===`escalation`?`destructive`:`secondary`,children:e.type===`escalation`?`Escalation`:`Nudge`})}),(0,L.jsx)(Y,{children:fJ(e.silenceDurationHours)}),(0,L.jsx)(Y,{className:`text-sm text-muted-foreground`,children:e.dmSentAt?new Date(e.dmSentAt).toLocaleString():`--`}),(0,L.jsx)(Y,{children:(0,L.jsx)(X,{variant:uJ[e.status],className:dJ[e.status],children:mJ(e.status)})}),(0,L.jsx)(Y,{className:`text-sm`,children:pJ(e)})]}),t&&(0,L.jsx)(Lk,{children:(0,L.jsx)(Y,{colSpan:8,className:`bg-muted/30 p-4`,children:(0,L.jsx)(gJ,{alert:e})})})]},e.id)})})]})}),c.hasNextPage&&(0,L.jsx)(`div`,{className:`flex justify-center p-4`,children:(0,L.jsx)(W,{variant:`outline`,onClick:()=>c.fetchNextPage(),disabled:c.isFetchingNextPage,children:c.isFetchingNextPage?`Loading...`:`Load More`})})]})}function gJ({alert:e}){let t=ri(),n=R({mutationFn:()=>H(`/api/pa/alerts/${e.id}/resolve`,{method:`PUT`}),onSuccess:()=>{z.success(`Alert resolved`),t.invalidateQueries({queryKey:[`pa-alerts`]}),t.invalidateQueries({queryKey:[`pa-stats`]})},onError:()=>{z.error(`Failed to resolve alert`)}}),r=[`pending`,`sent`,`escalated`].includes(e.status);return(0,L.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[e.suggestedMessage&&(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`span`,{className:`font-medium`,children:`Suggested Message:`}),(0,L.jsx)(`p`,{className:`mt-1 text-muted-foreground whitespace-pre-wrap bg-background rounded px-3 py-2 border`,children:e.suggestedMessage})]}),e.agentRespondedAt&&e.dmSentAt&&(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-green-600`,children:[(0,L.jsx)(wT,{className:`h-4 w-4`}),(0,L.jsxs)(`span`,{children:[`Agent responded after `,pJ(e)]})]}),e.status===`escalated`&&(0,L.jsxs)(`div`,{className:`flex items-start gap-2 bg-destructive/10 border border-destructive/30 rounded-md p-3 text-xs`,children:[(0,L.jsx)(xT,{className:`h-4 w-4 text-destructive shrink-0 mt-0.5`}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`span`,{className:`font-medium text-destructive`,children:`Escalated`}),e.escalatedTo&&(0,L.jsxs)(`span`,{className:`text-muted-foreground`,children:[` to `,e.escalatedTo]}),e.escalatedAt&&(0,L.jsxs)(`span`,{className:`text-muted-foreground`,children:[` on `,new Date(e.escalatedAt).toLocaleStr
vendor: 7,550 bytes, line 156
156ing()]})]})]}),r&&(0,L.jsx)(W,{size:`sm`,variant:`outline`,onClick:()=>n.mutate(),disabled:n.isPending,children:n.isPending?`Resolving...`:`Mark Resolved`})]})}var _J=typeof window<`u`?_.useLayoutEffect:_.useEffect;function vJ(e){if(e!==void 0)switch(typeof e){case`number`:return e;case`string`:if(e.endsWith(`px`))return parseFloat(e);break}}function yJ({box:e,defaultHeight:t,defaultWidth:n,disabled:r,element:i,mode:a,style:o}){let{styleHeight:s,styleWidth:c}=(0,_.useMemo)(()=>({styleHeight:vJ(o?.height),styleWidth:vJ(o?.width)}),[o?.height,o?.width]),[l,u]=(0,_.useState)({height:t,width:n}),d=r||a===`only-height`&&s!==void 0||a===`only-width`&&c!==void 0||s!==void 0&&c!==void 0;return _J(()=>{if(i===null||d)return;let t=new ResizeObserver(e=>{for(let t of e){let{contentRect:e,target:n}=t;i===n&&u(t=>t.height===e.height&&t.width===e.width?t:{height:e.height,width:e.width})}});return t.observe(i,{box:e}),()=>{t?.unobserve(i)}},[e,d,i,s,c]),(0,_.useMemo)(()=>({height:s??l.height,width:c??l.width}),[l,s,c])}function bJ(e){let t=(0,_.useRef)(()=>{throw Error(`Cannot call during render.`)});return _J(()=>{t.current=e},[e]),(0,_.useCallback)(e=>t.current?.(e),[t])}var xJ=null;function SJ(e=!1){if(xJ===null||e){let e=document.createElement(`div`),t=e.style;t.width=`50px`,t.height=`50px`,t.overflow=`scroll`,t.direction=`rtl`;let n=document.createElement(`div`),r=n.style;return r.width=`100px`,r.height=`100px`,e.appendChild(n),document.body.appendChild(e),e.scrollLeft>0?xJ=`positive-descending`:(e.scrollLeft=1,xJ=e.scrollLeft===0?`negative`:`positive-ascending`),document.body.removeChild(e),xJ}return xJ}function CJ({containerElement:e,direction:t,isRtl:n,scrollOffset:r}){if(t===`horizontal`&&n)switch(SJ()){case`negative`:return-r;case`positive-descending`:if(e){let{clientWidth:t,scrollLeft:n,scrollWidth:r}=e;return r-t-n}break}return r}function wJ(e,t=`Assertion error`){if(!e)throw console.error(t),Error(t)}function TJ(e,t){if(e===t)return!0;if(!!e!=!!t||(wJ(e!==void 0),wJ(t!==void 0),Object.keys(e).length!==Object.keys(t).length))return!1;for(let n in e)if(!Object.is(t[n],e[n]))return!1;return!0}function EJ({cachedBounds:e,itemCount:t,itemSize:n}){if(t===0)return 0;if(typeof n==`number`)return t*n;{let n=e.get(e.size===0?0:e.size-1);return wJ(n!==void 0,`Unexpected bounds cache miss`),t*((n.scrollOffset+n.size)/e.size)}}function DJ({align:e,cachedBounds:t,index:n,itemCount:r,itemSize:i,containerScrollOffset:a,containerSize:o}){if(n<0||n>=r)throw RangeError(`Invalid index specified: ${n}`,{cause:`Index ${n} is not within the range of 0 - ${r-1}`});let s=EJ({cachedBounds:t,itemCount:r,itemSize:i}),c=t.get(n),l=Math.max(0,Math.min(s-o,c.scrollOffset)),u=Math.max(0,c.scrollOffset-o+c.size);switch(e===`smart`&&(e=a>=u&&a<=l?`auto`:`center`),e){case`start`:return l;case`end`:return u;case`center`:return c.scrollOffset<=o/2?0:c.scrollOffset+c.size/2>=s-o/2?s-o:c.scrollOffset+c.size/2-o/2;default:return a>=u&&a<=l?a:a<u?u:l}}function OJ({cachedBounds:e,containerScrollOffset:t,containerSize:n,itemCount:r,overscanCount:i}){let a=r-1,o=0,s=-1,c=0,l=-1,u=0;for(;u<a;){let n=e.get(u);if(n.scrollOffset+n.size>t)break;u++}for(o=u,c=Math.max(0,o-i);u<a;){let r=e.get(u);if(r.scrollOffset+r.size>=t+n)break;u++}return s=Math.min(a,u),l=Math.min(r-1,s+i),o<0&&(o=0,s=-1,c=0,l=-1),{startIndexVisible:o,stopIndexVisible:s,startIndexOverscan:c,stopIndexOverscan:l}}function kJ({itemCount:e,itemProps:t,itemSize:n}){let r=new Map;return{get(i){for(wJ(i<e,`Invalid index ${i}`);r.size-1<i;){let e=r.size,a;switch(typeof n){case`function`:a=n(e,t);break;case`number`:a=n;break}if(e===0)r.set(e,{size:a,scrollOffset:0});else{let t=r.get(e-1);wJ(t!==void 0,`Unexpected bounds cache miss for index ${i}`),r.set(e,{scrollOffset:t.scrollOffset+t.size,size:a})}}let a=r.get(i);return wJ(a!==void 0,`Unexpected bounds cache miss for index ${i}`),a},set(e,t){r.set(e,t)},get size(){return r.size}}}function AJ({itemCount:e,itemProps:t,itemSize:n}){return(0,_.useMemo)(()=>kJ({itemCount:e,itemProps:t,itemSize:n}),[e,t,n])}function jJ({containerSize:e,itemSize:t}){let n;switch(typeof t){case`string`:wJ(t.endsWith(`%`),`Invalid item size: "${t}"; string values must be percentages (e.g. "100%")`),wJ(e!==void 0,`Container size must be defined if a percentage item size is specified`),n=e*parseInt(t)/100;break;default:n=t;break}return n}function MJ({containerElement:e,containerStyle:t,defaultContainerSize:n=0,direction:r,isRtl:i=!1,itemCount:a,itemProps:o,itemSize:s,onResize:c,overscanCount:l}){let{height:u=n,width:d=n}=yJ({defaultHeight:r===`vertical`?n:void 0,defaultWidth:r===`horizontal`?n:void 0,element:e,mode:r===`vertical`?`only-height`:`only-width`,style:t}),f=(0,_.useRef)({height:0,width:0}),p=r===`vertical`?u:d,m=jJ({containerSize:p,itemSize:s});(0,_.useLayoutEffect)(()=>{if(typeof c==`function`){let e=f.current;(e.height!==u||e.width!==d)&&(c({height:u,width:d},{...e}),e.height=u,e.width=d)}},[u,c,d]);let h=AJ({itemCount:a,itemProps:o,itemSize:m}),g=(0,_.useCallback)(e=>h.get(e),[h]),[v,y]=(0,_.useState)(()=>OJ({cachedBounds:h,containerScrollOffset:0,containerSize:p,itemCount:a,overscanCount:l})),{startIndexVisible:b,startIndexOverscan:x,stopIndexVisible:S,stopIndexOverscan:C}={startIndexVisible:Math.min(a-1,v.startIndexVisible),startIndexOverscan:Math.min(a-1,v.startIndexOverscan),stopIndexVisible:Math.min(a-1,v.stopIndexVisible),stopIndexOverscan:Math.min(a-1,v.stopIndexOverscan)},w=(0,_.useCallback)(()=>EJ({cachedBounds:h,itemCount:a,itemSize:m}),[h,a,m]),T=(0,_.useCallback)(t=>OJ({cachedBounds:h,containerScrollOffset:CJ({containerElement:e,direction:r,isRtl:i,scrollOffset:t}),containerSize:p,itemCount:a,overscanCount:l}),[h,e,p,r,i,a,l]);return _J(()=>{y(T((r===`vertical`?e?.scrollTop:e?.scrollLeft)??0))},[e,r,T]),_J(()=>{if(!e)return;let t=()=>{y(t=>{let{scrollLeft:n,scrollTop:o}=e,s=OJ({cachedBounds:h,containerScrollOffset:CJ({containerElement:e,direction:r,isRtl:i,scrollOffset:r===`vertical`?o:n}),containerSize:p,itemCount:a,overscanCount:l});return TJ(s,t)?t:s})};return e.addEventListener(`scroll`,t),()=>{e.removeEventListener(`scroll`,t)}},[h,e,p,r,a,l]),{getCellBounds:g,getEstimatedSize:w,scrollToIndex:bJ(({align:t=`auto`,containerScrollOffset:n,index:o})=>{let s=DJ({align:t,cachedBounds:h,containerScrollOffset:n,containerSize:p,index:o,itemCount:a,itemSize:m});if(e){if(s=CJ({containerElement:e,direction:r,isRtl:i,scrollOffset:s}),typeof e.scrollTo!=`function`){let e=T(s);TJ(v,e)||y(e)}return s}}),startIndexOverscan:x,startIndexVisible:b,stopIndexOverscan:C,stopIndexVisible:S}}function NJ(e){return(0,_.useMemo)(()=>e,Object.values(e))}function PJ(e,t){let{ariaAttributes:n,style:r,...i}=e,{ariaAttributes:a,style:o,...s}=t;return TJ(n,a)&&TJ(r,o)&&TJ(i,s)}function FJ(e){return typeof e==`object`&&!!e&&`getAverageRowHeight`in e&&typeof e.getAverageRowHeight==`function`}var IJ=`data-react-window-index`;function LJ({children:e,className:t,defaultHeight:n=0,listRef:r,onResize:i,onRowsRendered:a,overscanCount:o=3,rowComponent:s,rowCount:c,rowHeight:l,rowProps:u,tagName:d=`div`,style:f,...p}){let m=NJ(u),h=(0,_.useMemo)(()=>(0,_.memo)(s,PJ),[s]),[g,v]=(0,_.useState)(null),y=FJ(l),{getCellBounds:b,getEstimatedSize:x,scrollToIndex:S,startIndexOverscan:C,startIndexVisible:w,stopIndexOverscan:T,stopIndexVisible:E}=MJ({containerElement:g,containerStyle:f,defaultContainerSize:n,direction:`vertical`,itemCount:c,itemProps:m,itemSize:(0,_.useMemo)(()=>y?e=>l.getRowHeight(e)??l.getAverageRowHeight():l,[y,l]),onResize:i,overscanCount:o});(0,_.useImperativeHandle)(r,()=>
156({get element(){return g},scrollToRow({align:e=`auto`,behavior:t=`auto`,index:n}){let r=S({align:e,containerScrollOffset:g?.scrollTop??0,index:n});typeof g?.scrollTo==`function`&&g.scrollTo({behavior:t,top:r})}}),[g,S]),_J(()=>{if(!g)return;let e=Array.from(g.children).filter((e,t)=>{if(e.hasAttribute(`aria-hidden`))return!1;let n=`${C+t}`;return e.setAttribute(IJ,n),!0});if(y)return l.observeRowElements(e)},[g,y,l,C,T]),(0,_.useEffect)(()=>{C>=0&&T>=0&&a&&a({startIndex:w,stopIndex:E},{startIndex:C,stopIndex:T})},[a,C,w,T,E]);let D=(0,_.useMemo)(()=>{let e=[];if(c>0)for(let t=C;t<=T;t++){let n=b(t);e.push((0,_.createElement)(h,{...m,ariaAttributes:{"aria-posinset":t+1,"aria-setsize":c,role:`listitem`},key:t,index:t,style:{position:`absolute`,left:0,transform:`translateY(${n.scrollOffset}px)`,height:y?void 0:n.size,width:`100%`}}))}return e},[h,b,y,c,m,C,T]),O=(0,L.jsx)(`div`,{"aria-hidden":!0,style:{height:x(),width:`100%`,zIndex:-1}});return(0,_.createElement)(d,{role:`list`,...p,className:t,ref:v,style:{position:`relative`,maxHeight:`100%`,flexGrow:1,overflowY:`auto`,...f}},D,e,O)}var RJ=`.txt,.md,.csv,.pdf,.png,.jpg,.jpeg,.webp,.json`,zJ=20*1024*1024;function BJ(){let e=ri(),[t,n]=(0,_.useState)(!1),[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)(null),l=(0,_.useRef)(null),u=vi({queryKey:[`kb`,`documents`],queryFn:async()=>(await H(`/api/knowledge-base/documents`)).data,refetchInterval:e=>e.state.data?.some(e=>e.status===`processing`)?2e3:!1}),d=(0,_.useMemo)(()=>u.data??[],[u.data]),f=u.isLoading,p=(0,_.useCallback)(()=>e.invalidateQueries({queryKey:[`kb`,`documents`]}),[e]),m=(0,_.useCallback)(async e=>{let t=Array.from(e);if(t.length!==0){n(!0);try{for(let e of t){if(e.size>zJ){z.error(`${e.name}: exceeds 20 MB limit`);continue}let t=new FormData;t.append(`file`,e);let n=await fetch(`/api/knowledge-base/documents`,{method:`POST`,credentials:`include`,body:t});if(!n.ok){let t=await n.json().catch(()=>({}));z.error(`${e.name}: ${t.error??n.statusText}`);continue}z.success(`Uploaded ${e.name} â processingâ¦`)}await p()}finally{n(!1),l.current&&(l.current.value=``)}}},[p]),h=R({mutationFn:e=>H(`/api/knowledge-base/documents/${e}`,{method:`DELETE`}),onSuccess:()=>{z.success(`Document deleted`),o(null),p()},onError:e=>{z.error(e instanceof Error?e.message:`Delete failed`),o(null)}}),g=(0,_.useMemo)(()=>d.find(e=>e.id===s)??null,[d,s]);return(0,L.jsxs)(`div`,{className:`p-6 space-y-6`,children:[(0,L.jsxs)(`header`,{className:`flex items-center justify-between`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,L.jsx)(`div`,{className:`p-2 rounded-lg bg-primary/10`,children:(0,L.jsx)(kC,{className:`w-6 h-6 text-primary`})}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`h1`,{className:`text-2xl font-semibold`,children:`Knowledge Base`}),(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Documents the AI can retrieve from when answering lead questions.`})]})]}),(0,L.jsxs)(W,{variant:`outline`,size:`sm`,onClick:()=>void u.refetch(),children:[(0,L.jsx)(Yw,{className:`w-4 h-4 mr-2`}),` Refresh`]})]}),(0,L.jsx)(VJ,{accept:RJ,uploading:t,onFilesSelected:m,onOpenPaste:()=>i(!0),fileInputRef:l}),(0,L.jsx)(HJ,{docs:d,loading:f,onView:e=>c(e),onDelete:e=>o(e)}),(0,L.jsx)(qJ,{}),(0,L.jsx)(KJ,{open:r,onOpenChange:i,onCreated:()=>void p()}),(0,L.jsx)(WJ,{open:g!==null,doc:g,onClose:()=>c(null)}),(0,L.jsx)(lA,{open:a!==null,onOpenChange:e=>!e&&o(null),children:(0,L.jsxs)(pA,{children:[(0,L.jsxs)(mA,{children:[(0,L.jsx)(gA,{children:`Delete this document?`}),(0,L.jsxs)(_A,{children:[`All `,d.find(e=>e.id===a)?.chunkCount??0,` chunks and their embeddings will be removed. The agent will no longer retrieve this content. This cannot be undone.`]})]}),(0,L.jsxs)(hA,{children:[(0,L.jsx)(yA,{children:`Cancel`}),(0,L.jsx)(vA,{onClick:()=>a&&h.mutate(a),children:`Delete`})]})]})})]})}function VJ({accept:e,uploading:t,onFilesSelected:n,onOpenPaste:r,fileInputRef:i}){let[a,o]=(0,_.useState)(!1),s=(0,_.useCallback)(e=>{e.preventDefault(),o(!1),e.dataTransfer.files?.length&&n(e.dataTransfer.files)},[n]);return(0,L.jsxs)(K,{children:[(0,L.jsxs)(MD,{children:[(0,L.jsx)(ND,{children:`Add knowledge`}),(0,L.jsx)(PD,{children:`Supported: .txt, .md, .csv, .pdf, .png, .jpg, .jpeg, .webp, .json (max 20 MB). Images are OCR'd via the vision model. Files are chunked and embedded â no raw file storage yet.`})]}),(0,L.jsx)(q,{className:`space-y-4`,children:(0,L.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),o(!0)},onDragLeave:()=>o(!1),onDrop:s,className:` 157 border-2 border-dashed rounded-lg p-8 text-center transition-colors 158 ${a?`border-primary bg-primary/5`:`border-muted-foreground
158/25`} 159 `,children:[(0,L.jsx)(CT,{className:`w-8 h-8 mx-auto mb-2 text-muted-foreground`}),(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground mb-3`,children:`Drag files here, or`}),(0,L.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,L.jsx)(W,{size:`sm`,disabled:t,onClick:()=>i.current?.click(),children:t?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(Ew,{className:`w-4 h-4 mr-2 animate-spin`}),` Uploadingâ¦`]}):(0,L.jsx)(L.Fragment,{children:`Choose file`})}),(0,L.jsx)(W,{size:`sm`,variant:`outline`,onClick:r,children:`Paste text`})]}),(0,L.jsx)(`input`,{ref:i,type:`file`,multiple:!0,accept:e,className:`hidden`,onChange:e=>e.target.files&&n(e.target.files)})]})})]})}function HJ({docs:e,loading:t,onView:n,onDelete:r}){return(0,L.jsxs)(K,{children:[(0,L.jsx)(MD,{children:(0,L.jsxs)(ND,{className:`flex items-center justify-between`,children:[(0,L.jsx)(`span`,{children:`Documents`}),(0,L.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[e.length,` total`]})]})}),(0,L.jsx)(q,{children:t?(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loadingâ¦`}):e.length===0?(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No documents yet. Upload a file or paste text to get started.`}):(0,L.jsxs)(Pk,{children:[(0,L.jsx)(Fk,{children:(0,L.jsxs)(Lk,{children:[(0,L.jsx)(J,{children:`Filename`}),(0,L.jsx)(J,{children:`Type`}),(0,L.jsx)(J,{className:`text-right`,children:`Size`}),(0,L.jsx)(J,{className:`text-right`,children:`Chunks`}),(0,L.jsx)(J,{children:`Status`}),(0,L.jsx)(J,{children:`Uploaded`}),(0,L.jsx)(J,{className:`text-right`,children:`Actions`})]})}),(0,L.jsx)(Ik,{children:e.map(e=>(0,L.jsxs)(Lk,{children:[(0,L.jsx)(Y,{className:`font-medium`,children:(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(lw,{className:`w-4 h-4 text-muted-foreground`}),(0,L.jsx)(`span`,{className:`truncate max-w-[280px]`,children:e.filename})]})}),(0,L.jsx)(Y,{children:(0,L.jsx)(X,{variant:`outline`,children:JJ(e.mimeType)})}),(0,L.jsx)(Y,{className:`text-right tabular-nums`,children:YJ(e.sizeBytes)}),(0,L.jsx)(Y,{className:`text-right tabular-nums`,children:e.chunkCount}),(0,L.jsx)(Y,{children:(0,L.jsx)(UJ,{status:e.status,errorMessage:e.errorMessage})}),(0,L.jsx)(Y,{className:`text-sm text-muted-foreground`,children:XJ(e.createdAt)}),(0,L.jsx)(Y,{className:`text-right`,children:(0,L.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,L.jsx)(W,{size:`sm`,variant:`ghost`,disabled:e.status!==`ready`,onClick:()=>n(e.id),children:`View`}),(0,L.jsx)(W,{size:`sm`,variant:`ghost`,onClick:()=>r(e.id),children:(0,L.jsx)(vT,{className:`w-4 h-4 text-destructive`})})]})})]},e.id))})]})})]})}function UJ({status:e,errorMessage:t}){return e===`ready`?(0,L.jsx)(X,{variant:`default`,className:`bg-green-100 text-green-700 hover:bg-green-100`,children:`ready`}):e===`processing`?(0,L.jsxs)(X,{variant:`secondary`,className:`flex items-center gap-1`,children:[(0,L.jsx)(Ew,{className:`w-3 h-3 animate-spin`}),` processing`]}):(0,L.jsx)(X,{variant:`destructive`,title:t??void 0,children:`failed`})}function WJ({open:e,doc:t,onClose:n}){let r=vi({queryKey:[`kb`,`chunks`,t?.id],enabled:e&&t!==null,queryFn:async()=>t?(await H(`/api/knowledge-base/documents/${t.id}/chunks?limit=200`)).data:[]}),i=r.data??[];return(0,L.jsx)(aj,{open:e,onOpenChange:e=>!e&&n(),children:(0,L.jsxs)(lj,{className:`max-w-3xl`,children:[(0,L.jsxs)(uj,{children:[(0,L.jsxs)(fj,{className:`flex items-center gap-2`,children:[(0,L.jsx)(lw,{className:`w-5 h-5`}),t?.filename]}),(0,L.jsx)(pj,{children:t?`${t.chunkCount} chunks · ${t.charCount.toLocaleString()} chars · ${YJ(t.sizeBytes)}`:``})]}),(0,L.jsx)(`div`,{className:`h-[60vh]`,children:r.isLoading?(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading chunksâ¦`}):i.length===0?(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No chunks available.`}):(0,L.jsx)(LJ,{rowComponent:GJ,rowCount:i.length,rowHeight:180,rowProps:{chunks:i}})})]})})}function GJ({index:e,style:t,chunks:n}){let r=n[e];return(0,L.jsx)(`div`,{style:t,className:`px-1 pb-3`,children:(0,L.jsxs)(`div`,{className:`border rounded-md p-3 h-full overflow-hidden flex flex-col`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between mb-2 text-xs text-muted-foreground`,children:[(0,L.jsxs)(`span`,{children:[`# `,(0,L.jsx)(`span`,{className:`font-mono`,children:r.chunkIndex})]}),(0,L.jsxs)(`span`,{children:[`~`,r.tokenCount,` tokens`]})]}),(0,L.jsx)(`div`,{className:`text-sm overflow-y-auto flex-1 whitespace-pre-wrap`,children:r.content})]})})}function KJ({open:e,onOpenChange:t,onCreated:n}){let[r,i]=(0,_.useState)(``),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(!1),l=(0,_.useCallback)(async()=>
159{if(r.trim().length===0){z.error(`Filename is required`);return}if(a.length<20){z.error(`Content must be at least 20 characters`);return}c(!0);try{await H(`/api/knowledge-base/text`,{method:`POST`,body:JSON.stringify({filename:r.trim(),content:a})}),z.success(`Saved â processingâ¦`),i(``),o(``),t(!1),n()}catch(e){z.error(e instanceof Error?e.message:`Failed to save`)}finally{c(!1)}},[r,a,t,n]);return(0,L.jsx)(aj,{open:e,onOpenChange:t,children:(0,L.jsxs)(lj,{className:`max-w-2xl`,children:[(0,L.jsxs)(uj,{children:[(0,L.jsx)(fj,{children:`Paste text`}),(0,L.jsx)(pj,{children:`Saves the content as a markdown document in the knowledge base.`})]}),(0,L.jsxs)(`div`,{className:`space-y-4`,children:[(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(Z,{htmlFor:`kb-paste-filename`,children:`Filename`}),(0,L.jsx)(G,{id:`kb-paste-filename`,placeholder:`e.g. private-property-policy.md`,value:r,onChange:e=>i(e.target.value)})]}),(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(Z,{htmlFor:`kb-paste-content`,children:`Content`}),(0,L.jsx)(TD,{id:`kb-paste-content`,rows:14,placeholder:`# Title 160 161Your content here â markdown is supported.`,value:a,onChange:e=>o(e.target.value)}),(0,L.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[a.length.toLocaleString(),` chars · minimum 20`]})]})]}),(0,L.jsxs)(dj,{children:[(0,L.jsx)(W,{variant:`outline`,onClick:()=>t(!1),children:`Cancel`}),(0,L.jsxs)(W,{onClick:l,disabled:s,children:[s&&(0,L.jsx)(Ew,{className:`w-4 h-4 mr-2 animate-spin`}),`Save`]})]})]})})}function qJ(){let[e,t]=(0,_.useState)(!1),[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(!1),c=(0,_.useCallback)(async()=>{if(!(n.trim().length<2)){s(!0);try{a((await H(`/api/knowledge-base/search`,{method:`POST`,body:JSON.stringify({query:n.trim(),limit:8})})).data)}catch(e){z.error(e instanceof Error?e.message:`Search failed`)}finally{s(!1)}}},[n]);return(0,L.jsx)(K,{children:(0,L.jsxs)(rK,{open:e,onOpenChange:t,children:[(0,L.jsx)(iK,{asChild:!0,children:(0,L.jsxs)(`button`,{type:`button`,className:`w-full text-left flex items-center justify-between p-6 hover:bg-muted/30 transition-colors rounded-t-lg`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`h3`,{className:`font-semibold`,children:`Test search`}),(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Run a query the way the agent would â check what chunks come back.`})]}),e?(0,L.jsx)(zC,{className:`w-4 h-4`}):(0,L.jsx)(VC,{className:`w-4 h-4`})]})}),(0,L.jsx)(aK,{children:(0,L.jsxs)(q,{className:`pt-0 space-y-3`,children:[(0,L.jsxs)(`div`,{className:`flex gap-2`,children:[(0,L.jsx)(G,{placeholder:`e.g. consultation fees commission HDB`,value:n,onChange:e=>r(e.target.value),onKeyDown:e=>e.key===`Enter`&&c()}),(0,L.jsx)(W,{onClick:c,disabled:o,children:o?(0,L.jsx)(Ew,{className:`w-4 h-4 animate-spin`}):(0,L.jsx)($w,{className:`w-4 h-4`})})]}),i&&(0,L.jsx)(`div`,{className:`space-y-2`,children:i.length===0?(0,L.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`No results above the similarity threshold. The agent would call`,` `,(0,L.jsx)(`code`,{children:`flag_for_human`}),` in this case.`]}):i.map(e=>(0,L.jsxs)(`div`,{className:`border rounded-md p-3`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between mb-1 text-xs text-muted-foreground`,children:[(0,L.jsx)(`span`,{className:`font-medium`,children:e.filename}),(0,L.jsx)(X,{variant:`outline`,className:`tabular-nums`,children:e.similarity.toFixed(3)})]}),(0,L.jsx)(`div`,{className:`text-sm whitespace-pre-wrap`,children:e.content})]},e.chunkId))})]})})]})})}function JJ(e){return e===`application/pdf`?`pdf`:e===`text/plain`?`txt`:e===`text/markdown`?`md`:e===`text/csv`?`csv`:e===`application/json`?`json`:e.startsWith(`image/`)?e.slice(6):e}function YJ(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function XJ(e){let t=new Date(e),n=Date.now(),r=Math.floor((n-t.getTime())/1e3);return r<60?`${r}s ago`:r<3600?`${Math.floor(r/60)}m ago`:r<86400?`${Math.floor(r/3600)}h ago`:t.toLocaleDateString()}function ZJ(){return(0,L.jsxs)(`div`,{className:`flex min-h-screen flex-col items-center justify-center gap-4 text-center`,children:[(0,L.jsx)(`h1`,{className:`text-6xl font-bold text-muted-foreground`,children:`404`}),(0,L.jsx)(`p`,{className:`text-xl text-muted-foreground`,children:`Page not found`}),(0,L.jsx)(W,{asChild:!0,variant:`outline`,children:(0,L.jsx)(Cn,{to:`/`,children:`Go home`})})]})}function QJ(){let e=St(),t=Ae(e)?`${e.status} â ${e.statusText}`:e instanceof Error?e.message:`An unexpected error occurred`;return(0,L.jsxs)(`div`,{className:`flex min-h-screen flex-col items-center justify-center gap-4 text-center`,children:[(0,L.jsx)(`h1`,{className:`text-6xl font-bold text-muted-foreground`,children:`Oops`}),(0,L.jsx)(`p`,{className:`text-xl text-muted-foreground`,children:`Something went wrong`}
161),(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground/70`,children:t}),(0,L.jsxs)(`div`,{className:`flex gap-2`,children:[(0,L.jsx)(W,{variant:`outline`,onClick:()=>window.location.reload(),children:`Reload`}),(0,L.jsx)(W,{asChild:!0,variant:`outline`,children:(0,L.jsx)(Cn,{to:`/`,children:`Go home`})})]})]})}function $J(){return(0,L.jsxs)(ii,{client:jD,children:[(0,L.jsx)(Yi,{position:`top-right`,richColors:!0,closeButton:!0}),(0,L.jsx)(bn,{children:(0,L.jsx)(ex,{children:(0,L.jsxs)(jt,{children:[(0,L.jsx)(kt,{path:`login`,element:(0,L.jsx)(FD,{})}),(0,L.jsx)(kt,{path:`leads/print`,element:(0,L.jsx)(dC,{children:(0,L.jsx)(hN,{})}),errorElement:(0,L.jsx)(QJ,{})}),(0,L.jsxs)(kt,{element:(0,L.jsx)(dC,{children:(0,L.jsx)(AD,{})}),errorElement:(0,L.jsx)(QJ,{}),children:[(0,L.jsx)(kt,{index:!0,element:(0,L.jsx)(UG,{})}),(0,L.jsx)(kt,{path:`leads`,element:(0,L.jsx)(lN,{})}),(0,L.jsx)(kt,{path:`messages`,element:(0,L.jsx)(cV,{})}),(0,L.jsx)(kt,{path:`agents`,element:(0,L.jsx)(DG,{})}),(0,L.jsx)(kt,{path:`assignments`,element:(0,L.jsx)(XK,{})}),(0,L.jsx)(kt,{path:`backlog`,element:(0,L.jsx)(tq,{})}),(0,L.jsx)(kt,{path:`ai-training`,element:(0,L.jsx)(FK,{})}),(0,L.jsx)(kt,{path:`knowledge-base`,element:(0,L.jsx)(BJ,{})}),(0,L.jsx)(kt,{path:`analytics`,element:(0,L.jsx)($G,{})}),(0,L.jsx)(kt,{path:`activity`,element:(0,L.jsx)(mV,{})}),(0,L.jsx)(kt,{path:`connect`,element:(0,L.jsx)(hV,{})}),(0,L.jsx)(kt,{path:`website-widget`,element:(0,L.jsx)(uG,{})}),(0,L.jsx)(kt,{path:`simulation`,element:(0,L.jsx)(uq,{})}),(0,L.jsx)(kt,{path:`sandbox`,element:(0,L.jsx)(wq,{})}),(0,L.jsx)(kt,{path:`agent-pa`,element:(0,L.jsx)(Jq,{})}),(0,L.jsx)(kt,{path:`agent-pa/weekly-digests`,element:(0,L.jsx)(rJ,{})}),(0,L.jsx)(kt,{path:`agent-pa/alerts`,element:(0,L.jsx)(hJ,{})})]}),(0,L.jsx)(kt,{path:`*`,element:(0,L.jsx)(ZJ,{})})]})})})]})}var eY=console.error;console.error=(...e)=>{typeof e[0]==`string`&&e[0].includes(`react-virtuoso`)&&e.some(e=>typeof e==`string`&&e.includes(`Zero-sized element`))||eY(...e)},(0,g.createRoot)(document.getElementById(`root`)).render((0,L.jsx)(_.StrictMode,{children:(0,L.jsx)($J,{})}));export{c as n,u as t};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.