diff --git "a/static/assets/index-BtW_vZUt.js" "b/static/assets/index-BtW_vZUt.js" new file mode 100644--- /dev/null +++ "b/static/assets/index-BtW_vZUt.js" @@ -0,0 +1,11 @@ +(function(){const y=document.createElement("link").relList;if(y&&y.supports&&y.supports("modulepreload"))return;for(const C of document.querySelectorAll('link[rel="modulepreload"]'))o(C);new MutationObserver(C=>{for(const M of C)if(M.type==="childList")for(const q of M.addedNodes)q.tagName==="LINK"&&q.rel==="modulepreload"&&o(q)}).observe(document,{childList:!0,subtree:!0});function p(C){const M={};return C.integrity&&(M.integrity=C.integrity),C.referrerPolicy&&(M.referrerPolicy=C.referrerPolicy),C.crossOrigin==="use-credentials"?M.credentials="include":C.crossOrigin==="anonymous"?M.credentials="omit":M.credentials="same-origin",M}function o(C){if(C.ep)return;C.ep=!0;const M=p(C);fetch(C.href,M)}})();var hs={exports:{}},Dn={};var Td;function Pm(){if(Td)return Dn;Td=1;var m=Symbol.for("react.transitional.element"),y=Symbol.for("react.fragment");function p(o,C,M){var q=null;if(M!==void 0&&(q=""+M),C.key!==void 0&&(q=""+C.key),"key"in C){M={};for(var Z in C)Z!=="key"&&(M[Z]=C[Z])}else M=C;return C=M.ref,{$$typeof:m,type:o,key:q,ref:C!==void 0?C:null,props:M}}return Dn.Fragment=y,Dn.jsx=p,Dn.jsxs=p,Dn}var _d;function e0(){return _d||(_d=1,hs.exports=Pm()),hs.exports}var c=e0(),ms={exports:{}},I={};var jd;function t0(){if(jd)return I;jd=1;var m=Symbol.for("react.transitional.element"),y=Symbol.for("react.portal"),p=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),C=Symbol.for("react.profiler"),M=Symbol.for("react.consumer"),q=Symbol.for("react.context"),Z=Symbol.for("react.forward_ref"),R=Symbol.for("react.suspense"),x=Symbol.for("react.memo"),O=Symbol.for("react.lazy"),H=Symbol.for("react.activity"),V=Symbol.iterator;function me(r){return r===null||typeof r!="object"?null:(r=V&&r[V]||r["@@iterator"],typeof r=="function"?r:null)}var ie={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},k=Object.assign,Ee={};function de(r,_,U){this.props=r,this.context=_,this.refs=Ee,this.updater=U||ie}de.prototype.isReactComponent={},de.prototype.setState=function(r,_){if(typeof r!="object"&&typeof r!="function"&&r!=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,r,_,"setState")},de.prototype.forceUpdate=function(r){this.updater.enqueueForceUpdate(this,r,"forceUpdate")};function He(){}He.prototype=de.prototype;function Ne(r,_,U){this.props=r,this.context=_,this.refs=Ee,this.updater=U||ie}var xe=Ne.prototype=new He;xe.constructor=Ne,k(xe,de.prototype),xe.isPureReactComponent=!0;var Ce=Array.isArray;function le(){}var A={H:null,A:null,T:null,S:null},w=Object.prototype.hasOwnProperty;function B(r,_,U){var G=U.ref;return{$$typeof:m,type:r,key:_,ref:G!==void 0?G:null,props:U}}function ye(r,_){return B(r.type,_,r.props)}function fe(r){return typeof r=="object"&&r!==null&&r.$$typeof===m}function ae(r){var _={"=":"=0",":":"=2"};return"$"+r.replace(/[=:]/g,function(U){return _[U]})}var ue=/\/+/g;function Oe(r,_){return typeof r=="object"&&r!==null&&r.key!=null?ae(""+r.key):_.toString(36)}function Be(r){switch(r.status){case"fulfilled":return r.value;case"rejected":throw r.reason;default:switch(typeof r.status=="string"?r.then(le,le):(r.status="pending",r.then(function(_){r.status==="pending"&&(r.status="fulfilled",r.value=_)},function(_){r.status==="pending"&&(r.status="rejected",r.reason=_)})),r.status){case"fulfilled":return r.value;case"rejected":throw r.reason}}throw r}function b(r,_,U,G,F){var ne=typeof r;(ne==="undefined"||ne==="boolean")&&(r=null);var ve=!1;if(r===null)ve=!0;else switch(ne){case"bigint":case"string":case"number":ve=!0;break;case"object":switch(r.$$typeof){case m:case y:ve=!0;break;case O:return ve=r._init,b(ve(r._payload),_,U,G,F)}}if(ve)return F=F(r),ve=G===""?"."+Oe(r,0):G,Ce(F)?(U="",ve!=null&&(U=ve.replace(ue,"$&/")+"/"),b(F,_,U,"",function(Dl){return Dl})):F!=null&&(fe(F)&&(F=ye(F,U+(F.key==null||r&&r.key===F.key?"":(""+F.key).replace(ue,"$&/")+"/")+ve)),_.push(F)),1;ve=0;var Ie=G===""?".":G+":";if(Ce(r))for(var qe=0;qe>>1,$=b[L];if(0>>1;LC(U,Y))G<$&&0>C(F,U)?(b[L]=F,b[G]=Y,L=G):(b[L]=U,b[_]=Y,L=_);else if(G<$&&0>C(F,Y))b[L]=F,b[G]=Y,L=G;else break e}}return D}function C(b,D){var Y=b.sortIndex-D.sortIndex;return Y!==0?Y:b.id-D.id}if(m.unstable_now=void 0,typeof performance=="object"&&typeof performance.now=="function"){var M=performance;m.unstable_now=function(){return M.now()}}else{var q=Date,Z=q.now();m.unstable_now=function(){return q.now()-Z}}var R=[],x=[],O=1,H=null,V=3,me=!1,ie=!1,k=!1,Ee=!1,de=typeof setTimeout=="function"?setTimeout:null,He=typeof clearTimeout=="function"?clearTimeout:null,Ne=typeof setImmediate<"u"?setImmediate:null;function xe(b){for(var D=p(x);D!==null;){if(D.callback===null)o(x);else if(D.startTime<=b)o(x),D.sortIndex=D.expirationTime,y(R,D);else break;D=p(x)}}function Ce(b){if(k=!1,xe(b),!ie)if(p(R)!==null)ie=!0,le||(le=!0,ae());else{var D=p(x);D!==null&&Be(Ce,D.startTime-b)}}var le=!1,A=-1,w=5,B=-1;function ye(){return Ee?!0:!(m.unstable_now()-Bb&&ye());){var L=H.callback;if(typeof L=="function"){H.callback=null,V=H.priorityLevel;var $=L(H.expirationTime<=b);if(b=m.unstable_now(),typeof $=="function"){H.callback=$,xe(b),D=!0;break t}H===p(R)&&o(R),xe(b)}else o(R);H=p(R)}if(H!==null)D=!0;else{var r=p(x);r!==null&&Be(Ce,r.startTime-b),D=!1}}break e}finally{H=null,V=Y,me=!1}D=void 0}}finally{D?ae():le=!1}}}var ae;if(typeof Ne=="function")ae=function(){Ne(fe)};else if(typeof MessageChannel<"u"){var ue=new MessageChannel,Oe=ue.port2;ue.port1.onmessage=fe,ae=function(){Oe.postMessage(null)}}else ae=function(){de(fe,0)};function Be(b,D){A=de(function(){b(m.unstable_now())},D)}m.unstable_IdlePriority=5,m.unstable_ImmediatePriority=1,m.unstable_LowPriority=4,m.unstable_NormalPriority=3,m.unstable_Profiling=null,m.unstable_UserBlockingPriority=2,m.unstable_cancelCallback=function(b){b.callback=null},m.unstable_forceFrameRate=function(b){0>b||125L?(b.sortIndex=Y,y(x,b),p(R)===null&&b===p(x)&&(k?(He(A),A=-1):k=!0,Be(Ce,Y-L))):(b.sortIndex=$,y(R,b),ie||me||(ie=!0,le||(le=!0,ae()))),b},m.unstable_shouldYield=ye,m.unstable_wrapCallback=function(b){var D=V;return function(){var Y=V;V=D;try{return b.apply(this,arguments)}finally{V=Y}}}})(gs)),gs}var Nd;function a0(){return Nd||(Nd=1,vs.exports=l0()),vs.exports}var Ss={exports:{}},nt={};var Od;function n0(){if(Od)return nt;Od=1;var m=xs();function y(R){var x="https://react.dev/errors/"+R;if(1"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(m)}catch(y){console.error(y)}}return m(),Ss.exports=n0(),Ss.exports}var Cd;function u0(){if(Cd)return Un;Cd=1;var m=a0(),y=xs(),p=i0();function o(e){var t="https://react.dev/errors/"+e;if(1$||(e.current=L[$],L[$]=null,$--)}function U(e,t){$++,L[$]=e.current,e.current=t}var G=r(null),F=r(null),ne=r(null),ve=r(null);function Ie(e,t){switch(U(ne,t),U(F,e),U(G,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?Kr(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=Kr(t),e=Jr(t,e);else switch(e){case"svg":e=1;break;case"math":e=2;break;default:e=0}}_(G),U(G,e)}function qe(){_(G),_(F),_(ne)}function Dl(e){e.memoizedState!==null&&U(ve,e);var t=G.current,l=Jr(t,e.type);t!==l&&(U(F,e),U(G,l))}function Ul(e){F.current===e&&(_(G),_(F)),ve.current===e&&(_(ve),On._currentValue=Y)}var qa,Hn;function Qt(e){if(qa===void 0)try{throw Error()}catch(l){var t=l.stack.trim().match(/\n( *(at )?)/);qa=t&&t[1]||"",Hn=-1)":-1n||f[a]!==g[n]){var T=` +`+f[a].replace(" at new "," at ");return e.displayName&&T.includes("")&&(T=T.replace("",e.displayName)),T}while(1<=a&&0<=n);break}}}finally{Ya=!1,Error.prepareStackTrace=l}return(l=e?e.displayName||e.name:"")?Qt(l):""}function eu(e,t){switch(e.tag){case 26:case 27:case 5:return Qt(e.type);case 16:return Qt("Lazy");case 13:return e.child!==t&&t!==null?Qt("Suspense Fallback"):Qt("Suspense");case 19:return Qt("SuspenseList");case 0:case 15:return Ga(e.type,!1);case 11:return Ga(e.type.render,!1);case 1:return Ga(e.type,!0);case 31:return Qt("Activity");default:return""}}function Bn(e){try{var t="",l=null;do t+=eu(e,l),l=e,e=e.return;while(e);return t}catch(a){return` +Error generating stack: `+a.message+` +`+a.stack}}var N=Object.prototype.hasOwnProperty,ee=m.unstable_scheduleCallback,pe=m.unstable_cancelCallback,Le=m.unstable_shouldYield,it=m.unstable_requestPaint,ke=m.unstable_now,Dd=m.unstable_getCurrentPriorityLevel,Es=m.unstable_ImmediatePriority,Ts=m.unstable_UserBlockingPriority,qn=m.unstable_NormalPriority,Ud=m.unstable_LowPriority,_s=m.unstable_IdlePriority,Hd=m.log,Bd=m.unstable_setDisableYieldValue,La=null,yt=null;function sl(e){if(typeof Hd=="function"&&Bd(e),yt&&typeof yt.setStrictMode=="function")try{yt.setStrictMode(La,e)}catch{}}var vt=Math.clz32?Math.clz32:Gd,qd=Math.log,Yd=Math.LN2;function Gd(e){return e>>>=0,e===0?32:31-(qd(e)/Yd|0)|0}var Yn=256,Gn=262144,Ln=4194304;function Hl(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 wn(e,t,l){var a=e.pendingLanes;if(a===0)return 0;var n=0,i=e.suspendedLanes,u=e.pingedLanes;e=e.warmLanes;var s=a&134217727;return s!==0?(a=s&~i,a!==0?n=Hl(a):(u&=s,u!==0?n=Hl(u):l||(l=s&~e,l!==0&&(n=Hl(l))))):(s=a&~i,s!==0?n=Hl(s):u!==0?n=Hl(u):l||(l=a&~e,l!==0&&(n=Hl(l)))),n===0?0:t!==0&&t!==n&&(t&i)===0&&(i=n&-n,l=t&-t,i>=l||i===32&&(l&4194048)!==0)?t:n}function wa(e,t){return(e.pendingLanes&~(e.suspendedLanes&~e.pingedLanes)&t)===0}function Ld(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 js(){var e=Ln;return Ln<<=1,(Ln&62914560)===0&&(Ln=4194304),e}function tu(e){for(var t=[],l=0;31>l;l++)t.push(e);return t}function Xa(e,t){e.pendingLanes|=t,t!==268435456&&(e.suspendedLanes=0,e.pingedLanes=0,e.warmLanes=0)}function wd(e,t,l,a,n,i){var u=e.pendingLanes;e.pendingLanes=l,e.suspendedLanes=0,e.pingedLanes=0,e.warmLanes=0,e.expiredLanes&=l,e.entangledLanes&=l,e.errorRecoveryDisabledLanes&=l,e.shellSuspendCounter=0;var s=e.entanglements,f=e.expirationTimes,g=e.hiddenUpdates;for(l=u&~l;0"u")return null;try{return e.activeElement||e.body}catch{return e.body}}var Jd=/[\n"\\]/g;function jt(e){return e.replace(Jd,function(t){return"\\"+t.charCodeAt(0).toString(16)+" "})}function cu(e,t,l,a,n,i,u,s){e.name="",u!=null&&typeof u!="function"&&typeof u!="symbol"&&typeof u!="boolean"?e.type=u:e.removeAttribute("type"),t!=null?u==="number"?(t===0&&e.value===""||e.value!=t)&&(e.value=""+_t(t)):e.value!==""+_t(t)&&(e.value=""+_t(t)):u!=="submit"&&u!=="reset"||e.removeAttribute("value"),t!=null?su(e,u,_t(t)):l!=null?su(e,u,_t(l)):a!=null&&e.removeAttribute("value"),n==null&&i!=null&&(e.defaultChecked=!!i),n!=null&&(e.checked=n&&typeof n!="function"&&typeof n!="symbol"),s!=null&&typeof s!="function"&&typeof s!="symbol"&&typeof s!="boolean"?e.name=""+_t(s):e.removeAttribute("name")}function Ys(e,t,l,a,n,i,u,s){if(i!=null&&typeof i!="function"&&typeof i!="symbol"&&typeof i!="boolean"&&(e.type=i),t!=null||l!=null){if(!(i!=="submit"&&i!=="reset"||t!=null)){uu(e);return}l=l!=null?""+_t(l):"",t=t!=null?""+_t(t):l,s||t===e.value||(e.value=t),e.defaultValue=t}a=a??n,a=typeof a!="function"&&typeof a!="symbol"&&!!a,e.checked=s?e.checked:!!a,e.defaultChecked=!!a,u!=null&&typeof u!="function"&&typeof u!="symbol"&&typeof u!="boolean"&&(e.name=u),uu(e)}function su(e,t,l){t==="number"&&Zn(e.ownerDocument)===e||e.defaultValue===""+l||(e.defaultValue=""+l)}function na(e,t,l,a){if(e=e.options,t){t={};for(var n=0;n"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),hu=!1;if(Kt)try{var Ka={};Object.defineProperty(Ka,"passive",{get:function(){hu=!0}}),window.addEventListener("test",Ka,Ka),window.removeEventListener("test",Ka,Ka)}catch{hu=!1}var ol=null,mu=null,Kn=null;function Vs(){if(Kn)return Kn;var e,t=mu,l=t.length,a,n="value"in ol?ol.value:ol.textContent,i=n.length;for(e=0;e=ka),$s=" ",Is=!1;function Ps(e,t){switch(e){case"keyup":return xh.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function ef(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var sa=!1;function Th(e,t){switch(e){case"compositionend":return ef(t);case"keypress":return t.which!==32?null:(Is=!0,$s);case"textInput":return e=t.data,e===$s&&Is?null:e;default:return null}}function _h(e,t){if(sa)return e==="compositionend"||!pu&&Ps(e,t)?(e=Vs(),Kn=mu=ol=null,sa=!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)return{node:l,offset:t-e};e=a}e:{for(;l;){if(l.nextSibling){l=l.nextSibling;break e}l=l.parentNode}l=void 0}l=ff(l)}}function rf(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?rf(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function df(e){e=e!=null&&e.ownerDocument!=null&&e.ownerDocument.defaultView!=null?e.ownerDocument.defaultView:window;for(var t=Zn(e.document);t instanceof e.HTMLIFrameElement;){try{var l=typeof t.contentWindow.location.href=="string"}catch{l=!1}if(l)e=t.contentWindow;else break;t=Zn(e.document)}return t}function Eu(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 Rh=Kt&&"documentMode"in document&&11>=document.documentMode,fa=null,Tu=null,Pa=null,_u=!1;function hf(e,t,l){var a=l.window===l?l.document:l.nodeType===9?l:l.ownerDocument;_u||fa==null||fa!==Zn(a)||(a=fa,"selectionStart"in a&&Eu(a)?a={start:a.selectionStart,end:a.selectionEnd}:(a=(a.ownerDocument&&a.ownerDocument.defaultView||window).getSelection(),a={anchorNode:a.anchorNode,anchorOffset:a.anchorOffset,focusNode:a.focusNode,focusOffset:a.focusOffset}),Pa&&Ia(Pa,a)||(Pa=a,a=Gi(Tu,"onSelect"),0>=u,n-=u,Yt=1<<32-vt(t)+n|l<te?(re=Q,Q=null):re=Q.sibling;var Se=S(h,Q,v[te],j);if(Se===null){Q===null&&(Q=re);break}e&&Q&&Se.alternate===null&&t(h,Q),d=i(Se,d,te),ge===null?K=Se:ge.sibling=Se,ge=Se,Q=re}if(te===v.length)return l(h,Q),he&&Ft(h,te),K;if(Q===null){for(;tete?(re=Q,Q=null):re=Q.sibling;var Rl=S(h,Q,Se.value,j);if(Rl===null){Q===null&&(Q=re);break}e&&Q&&Rl.alternate===null&&t(h,Q),d=i(Rl,d,te),ge===null?K=Rl:ge.sibling=Rl,ge=Rl,Q=re}if(Se.done)return l(h,Q),he&&Ft(h,te),K;if(Q===null){for(;!Se.done;te++,Se=v.next())Se=z(h,Se.value,j),Se!==null&&(d=i(Se,d,te),ge===null?K=Se:ge.sibling=Se,ge=Se);return he&&Ft(h,te),K}for(Q=a(Q);!Se.done;te++,Se=v.next())Se=E(Q,h,te,Se.value,j),Se!==null&&(e&&Se.alternate!==null&&Q.delete(Se.key===null?te:Se.key),d=i(Se,d,te),ge===null?K=Se:ge.sibling=Se,ge=Se);return e&&Q.forEach(function(Im){return t(h,Im)}),he&&Ft(h,te),K}function Ae(h,d,v,j){if(typeof v=="object"&&v!==null&&v.type===k&&v.key===null&&(v=v.props.children),typeof v=="object"&&v!==null){switch(v.$$typeof){case me:e:{for(var K=v.key;d!==null;){if(d.key===K){if(K=v.type,K===k){if(d.tag===7){l(h,d.sibling),j=n(d,v.props.children),j.return=h,h=j;break e}}else if(d.elementType===K||typeof K=="object"&&K!==null&&K.$$typeof===w&&Kl(K)===d.type){l(h,d.sibling),j=n(d,v.props),un(j,v),j.return=h,h=j;break e}l(h,d);break}else t(h,d);d=d.sibling}v.type===k?(j=wl(v.props.children,h.mode,j,v.key),j.return=h,h=j):(j=li(v.type,v.key,v.props,null,h.mode,j),un(j,v),j.return=h,h=j)}return u(h);case ie:e:{for(K=v.key;d!==null;){if(d.key===K)if(d.tag===4&&d.stateNode.containerInfo===v.containerInfo&&d.stateNode.implementation===v.implementation){l(h,d.sibling),j=n(d,v.children||[]),j.return=h,h=j;break e}else{l(h,d);break}else t(h,d);d=d.sibling}j=Cu(v,h.mode,j),j.return=h,h=j}return u(h);case w:return v=Kl(v),Ae(h,d,v,j)}if(Be(v))return X(h,d,v,j);if(ae(v)){if(K=ae(v),typeof K!="function")throw Error(o(150));return v=K.call(v),W(h,d,v,j)}if(typeof v.then=="function")return Ae(h,d,fi(v),j);if(v.$$typeof===Ne)return Ae(h,d,ii(h,v),j);oi(h,v)}return typeof v=="string"&&v!==""||typeof v=="number"||typeof v=="bigint"?(v=""+v,d!==null&&d.tag===6?(l(h,d.sibling),j=n(d,v),j.return=h,h=j):(l(h,d),j=Mu(v,h.mode,j),j.return=h,h=j),u(h)):l(h,d)}return function(h,d,v,j){try{nn=0;var K=Ae(h,d,v,j);return ba=null,K}catch(Q){if(Q===pa||Q===ci)throw Q;var ge=St(29,Q,null,h.mode);return ge.lanes=j,ge.return=h,ge}}}var Fl=Bf(!0),qf=Bf(!1),yl=!1;function Qu(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,lanes:0,hiddenCallbacks:null},callbacks:null}}function Zu(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 vl(e){return{lane:e,tag:0,payload:null,callback:null,next:null}}function gl(e,t,l){var a=e.updateQueue;if(a===null)return null;if(a=a.shared,(be&2)!==0){var n=a.pending;return n===null?t.next=t:(t.next=n.next,n.next=t),a.pending=t,t=ti(e),bf(e,null,l),t}return ei(e,a,t,l),ti(e)}function cn(e,t,l){if(t=t.updateQueue,t!==null&&(t=t.shared,(l&4194048)!==0)){var a=t.lanes;a&=e.pendingLanes,l|=a,t.lanes=l,As(e,l)}}function Vu(e,t){var l=e.updateQueue,a=e.alternate;if(a!==null&&(a=a.updateQueue,l===a)){var n=null,i=null;if(l=l.firstBaseUpdate,l!==null){do{var u={lane:l.lane,tag:l.tag,payload:l.payload,callback:null,next:null};i===null?n=i=u:i=i.next=u,l=l.next}while(l!==null);i===null?n=i=t:i=i.next=t}else n=i=t;l={baseState:a.baseState,firstBaseUpdate:n,lastBaseUpdate:i,shared:a.shared,callbacks:a.callbacks},e.updateQueue=l;return}e=l.lastBaseUpdate,e===null?l.firstBaseUpdate=t:e.next=t,l.lastBaseUpdate=t}var Ku=!1;function sn(){if(Ku){var e=Sa;if(e!==null)throw e}}function fn(e,t,l,a){Ku=!1;var n=e.updateQueue;yl=!1;var i=n.firstBaseUpdate,u=n.lastBaseUpdate,s=n.shared.pending;if(s!==null){n.shared.pending=null;var f=s,g=f.next;f.next=null,u===null?i=g:u.next=g,u=f;var T=e.alternate;T!==null&&(T=T.updateQueue,s=T.lastBaseUpdate,s!==u&&(s===null?T.firstBaseUpdate=g:s.next=g,T.lastBaseUpdate=f))}if(i!==null){var z=n.baseState;u=0,T=g=f=null,s=i;do{var S=s.lane&-536870913,E=S!==s.lane;if(E?(oe&S)===S:(a&S)===S){S!==0&&S===ga&&(Ku=!0),T!==null&&(T=T.next={lane:0,tag:s.tag,payload:s.payload,callback:null,next:null});e:{var X=e,W=s;S=t;var Ae=l;switch(W.tag){case 1:if(X=W.payload,typeof X=="function"){z=X.call(Ae,z,S);break e}z=X;break e;case 3:X.flags=X.flags&-65537|128;case 0:if(X=W.payload,S=typeof X=="function"?X.call(Ae,z,S):X,S==null)break e;z=H({},z,S);break e;case 2:yl=!0}}S=s.callback,S!==null&&(e.flags|=64,E&&(e.flags|=8192),E=n.callbacks,E===null?n.callbacks=[S]:E.push(S))}else E={lane:S,tag:s.tag,payload:s.payload,callback:s.callback,next:null},T===null?(g=T=E,f=z):T=T.next=E,u|=S;if(s=s.next,s===null){if(s=n.shared.pending,s===null)break;E=s,s=E.next,E.next=null,n.lastBaseUpdate=E,n.shared.pending=null}}while(!0);T===null&&(f=z),n.baseState=f,n.firstBaseUpdate=g,n.lastBaseUpdate=T,i===null&&(n.shared.lanes=0),El|=u,e.lanes=u,e.memoizedState=z}}function Yf(e,t){if(typeof e!="function")throw Error(o(191,e));e.call(t)}function Gf(e,t){var l=e.callbacks;if(l!==null)for(e.callbacks=null,e=0;ei?i:8;var u=b.T,s={};b.T=s,rc(e,!1,t,l);try{var f=n(),g=b.S;if(g!==null&&g(s,f),f!==null&&typeof f=="object"&&typeof f.then=="function"){var T=wh(f,a);dn(e,t,T,Tt(e))}else dn(e,t,a,Tt(e))}catch(z){dn(e,t,{then:function(){},status:"rejected",reason:z},Tt())}finally{D.p=i,u!==null&&s.types!==null&&(u.types=s.types),b.T=u}}function Jh(){}function fc(e,t,l,a){if(e.tag!==5)throw Error(o(476));var n=So(e).queue;go(e,n,t,Y,l===null?Jh:function(){return po(e),l(a)})}function So(e){var t=e.memoizedState;if(t!==null)return t;t={memoizedState:Y,baseState:Y,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:It,lastRenderedState:Y},next:null};var l={};return t.next={memoizedState:l,baseState:l,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:It,lastRenderedState:l},next:null},e.memoizedState=t,e=e.alternate,e!==null&&(e.memoizedState=t),t}function po(e){var t=So(e);t.next===null&&(t=e.alternate.memoizedState),dn(e,t.next.queue,{},Tt())}function oc(){return tt(On)}function bo(){return Xe().memoizedState}function xo(){return Xe().memoizedState}function Fh(e){for(var t=e.return;t!==null;){switch(t.tag){case 24:case 3:var l=Tt();e=vl(l);var a=gl(t,e,l);a!==null&&(mt(a,t,l),cn(a,t,l)),t={cache:Gu()},e.payload=t;return}t=t.return}}function kh(e,t,l){var a=Tt();l={lane:a,revertLane:0,gesture:null,action:l,hasEagerState:!1,eagerState:null,next:null},bi(e)?To(t,l):(l=Nu(e,t,l,a),l!==null&&(mt(l,e,a),_o(l,t,a)))}function Eo(e,t,l){var a=Tt();dn(e,t,l,a)}function dn(e,t,l,a){var n={lane:a,revertLane:0,gesture:null,action:l,hasEagerState:!1,eagerState:null,next:null};if(bi(e))To(t,n);else{var i=e.alternate;if(e.lanes===0&&(i===null||i.lanes===0)&&(i=t.lastRenderedReducer,i!==null))try{var u=t.lastRenderedState,s=i(u,l);if(n.hasEagerState=!0,n.eagerState=s,gt(s,u))return ei(e,t,n,0),Me===null&&Pn(),!1}catch{}if(l=Nu(e,t,n,a),l!==null)return mt(l,e,a),_o(l,t,a),!0}return!1}function rc(e,t,l,a){if(a={lane:2,revertLane:Qc(),gesture:null,action:a,hasEagerState:!1,eagerState:null,next:null},bi(e)){if(t)throw Error(o(479))}else t=Nu(e,l,a,2),t!==null&&mt(t,e,2)}function bi(e){var t=e.alternate;return e===P||t!==null&&t===P}function To(e,t){Ea=hi=!0;var l=e.pending;l===null?t.next=t:(t.next=l.next,l.next=t),e.pending=t}function _o(e,t,l){if((l&4194048)!==0){var a=t.lanes;a&=e.pendingLanes,l|=a,t.lanes=l,As(e,l)}}var hn={readContext:tt,use:vi,useCallback:Ye,useContext:Ye,useEffect:Ye,useImperativeHandle:Ye,useLayoutEffect:Ye,useInsertionEffect:Ye,useMemo:Ye,useReducer:Ye,useRef:Ye,useState:Ye,useDebugValue:Ye,useDeferredValue:Ye,useTransition:Ye,useSyncExternalStore:Ye,useId:Ye,useHostTransitionStatus:Ye,useFormState:Ye,useActionState:Ye,useOptimistic:Ye,useMemoCache:Ye,useCacheRefresh:Ye};hn.useEffectEvent=Ye;var jo={readContext:tt,use:vi,useCallback:function(e,t){return ut().memoizedState=[e,t===void 0?null:t],e},useContext:tt,useEffect:co,useImperativeHandle:function(e,t,l){l=l!=null?l.concat([e]):null,Si(4194308,4,ro.bind(null,t,e),l)},useLayoutEffect:function(e,t){return Si(4194308,4,e,t)},useInsertionEffect:function(e,t){Si(4,2,e,t)},useMemo:function(e,t){var l=ut();t=t===void 0?null:t;var a=e();if(kl){sl(!0);try{e()}finally{sl(!1)}}return l.memoizedState=[a,t],a},useReducer:function(e,t,l){var a=ut();if(l!==void 0){var n=l(t);if(kl){sl(!0);try{l(t)}finally{sl(!1)}}}else n=t;return a.memoizedState=a.baseState=n,e={pending:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:n},a.queue=e,e=e.dispatch=kh.bind(null,P,e),[a.memoizedState,e]},useRef:function(e){var t=ut();return e={current:e},t.memoizedState=e},useState:function(e){e=nc(e);var t=e.queue,l=Eo.bind(null,P,t);return t.dispatch=l,[e.memoizedState,l]},useDebugValue:cc,useDeferredValue:function(e,t){var l=ut();return sc(l,e,t)},useTransition:function(){var e=nc(!1);return e=go.bind(null,P,e.queue,!0,!1),ut().memoizedState=e,[!1,e]},useSyncExternalStore:function(e,t,l){var a=P,n=ut();if(he){if(l===void 0)throw Error(o(407));l=l()}else{if(l=t(),Me===null)throw Error(o(349));(oe&127)!==0||Vf(a,t,l)}n.memoizedState=l;var i={value:l,getSnapshot:t};return n.queue=i,co(Jf.bind(null,a,i,e),[e]),a.flags|=2048,_a(9,{destroy:void 0},Kf.bind(null,a,i,l,t),null),l},useId:function(){var e=ut(),t=Me.identifierPrefix;if(he){var l=Gt,a=Yt;l=(a&~(1<<32-vt(a)-1)).toString(32)+l,t="_"+t+"R_"+l,l=mi++,0<\/script>",i=i.removeChild(i.firstChild);break;case"select":i=typeof a.is=="string"?u.createElement("select",{is:a.is}):u.createElement("select"),a.multiple?i.multiple=!0:a.size&&(i.size=a.size);break;default:i=typeof a.is=="string"?u.createElement(n,{is:a.is}):u.createElement(n)}}i[Pe]=t,i[st]=a;e:for(u=t.child;u!==null;){if(u.tag===5||u.tag===6)i.appendChild(u.stateNode);else if(u.tag!==4&&u.tag!==27&&u.child!==null){u.child.return=u,u=u.child;continue}if(u===t)break e;for(;u.sibling===null;){if(u.return===null||u.return===t)break e;u=u.return}u.sibling.return=u.return,u=u.sibling}t.stateNode=i;e:switch(at(i,n,a),n){case"button":case"input":case"select":case"textarea":a=!!a.autoFocus;break e;case"img":a=!0;break e;default:a=!1}a&&el(t)}}return De(t),jc(t,t.type,e===null?null:e.memoizedProps,t.pendingProps,l),null;case 6:if(e&&t.stateNode!=null)e.memoizedProps!==a&&el(t);else{if(typeof a!="string"&&t.stateNode===null)throw Error(o(166));if(e=ne.current,ya(t)){if(e=t.stateNode,l=t.memoizedProps,a=null,n=et,n!==null)switch(n.tag){case 27:case 5:a=n.memoizedProps}e[Pe]=t,e=!!(e.nodeValue===l||a!==null&&a.suppressHydrationWarning===!0||Zr(e.nodeValue,l)),e||hl(t,!0)}else e=Li(e).createTextNode(a),e[Pe]=t,t.stateNode=e}return De(t),null;case 31:if(l=t.memoizedState,e===null||e.memoizedState!==null){if(a=ya(t),l!==null){if(e===null){if(!a)throw Error(o(318));if(e=t.memoizedState,e=e!==null?e.dehydrated:null,!e)throw Error(o(557));e[Pe]=t}else Xl(),(t.flags&128)===0&&(t.memoizedState=null),t.flags|=4;De(t),e=!1}else l=Hu(),e!==null&&e.memoizedState!==null&&(e.memoizedState.hydrationErrors=l),e=!0;if(!e)return t.flags&256?(bt(t),t):(bt(t),null);if((t.flags&128)!==0)throw Error(o(558))}return De(t),null;case 13:if(a=t.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(n=ya(t),a!==null&&a.dehydrated!==null){if(e===null){if(!n)throw Error(o(318));if(n=t.memoizedState,n=n!==null?n.dehydrated:null,!n)throw Error(o(317));n[Pe]=t}else Xl(),(t.flags&128)===0&&(t.memoizedState=null),t.flags|=4;De(t),n=!1}else n=Hu(),e!==null&&e.memoizedState!==null&&(e.memoizedState.hydrationErrors=n),n=!0;if(!n)return t.flags&256?(bt(t),t):(bt(t),null)}return bt(t),(t.flags&128)!==0?(t.lanes=l,t):(l=a!==null,e=e!==null&&e.memoizedState!==null,l&&(a=t.child,n=null,a.alternate!==null&&a.alternate.memoizedState!==null&&a.alternate.memoizedState.cachePool!==null&&(n=a.alternate.memoizedState.cachePool.pool),i=null,a.memoizedState!==null&&a.memoizedState.cachePool!==null&&(i=a.memoizedState.cachePool.pool),i!==n&&(a.flags|=2048)),l!==e&&l&&(t.child.flags|=8192),ji(t,t.updateQueue),De(t),null);case 4:return qe(),e===null&&Jc(t.stateNode.containerInfo),De(t),null;case 10:return Wt(t.type),De(t),null;case 19:if(_(we),a=t.memoizedState,a===null)return De(t),null;if(n=(t.flags&128)!==0,i=a.rendering,i===null)if(n)yn(a,!1);else{if(Ge!==0||e!==null&&(e.flags&128)!==0)for(e=t.child;e!==null;){if(i=di(e),i!==null){for(t.flags|=128,yn(a,!1),e=i.updateQueue,t.updateQueue=e,ji(t,e),t.subtreeFlags=0,e=l,l=t.child;l!==null;)xf(l,e),l=l.sibling;return U(we,we.current&1|2),he&&Ft(t,a.treeForkCount),t.child}e=e.sibling}a.tail!==null&&ke()>Mi&&(t.flags|=128,n=!0,yn(a,!1),t.lanes=4194304)}else{if(!n)if(e=di(i),e!==null){if(t.flags|=128,n=!0,e=e.updateQueue,t.updateQueue=e,ji(t,e),yn(a,!0),a.tail===null&&a.tailMode==="hidden"&&!i.alternate&&!he)return De(t),null}else 2*ke()-a.renderingStartTime>Mi&&l!==536870912&&(t.flags|=128,n=!0,yn(a,!1),t.lanes=4194304);a.isBackwards?(i.sibling=t.child,t.child=i):(e=a.last,e!==null?e.sibling=i:t.child=i,a.last=i)}return a.tail!==null?(e=a.tail,a.rendering=e,a.tail=e.sibling,a.renderingStartTime=ke(),e.sibling=null,l=we.current,U(we,n?l&1|2:l&1),he&&Ft(t,a.treeForkCount),e):(De(t),null);case 22:case 23:return bt(t),Fu(),a=t.memoizedState!==null,e!==null?e.memoizedState!==null!==a&&(t.flags|=8192):a&&(t.flags|=8192),a?(l&536870912)!==0&&(t.flags&128)===0&&(De(t),t.subtreeFlags&6&&(t.flags|=8192)):De(t),l=t.updateQueue,l!==null&&ji(t,l.retryQueue),l=null,e!==null&&e.memoizedState!==null&&e.memoizedState.cachePool!==null&&(l=e.memoizedState.cachePool.pool),a=null,t.memoizedState!==null&&t.memoizedState.cachePool!==null&&(a=t.memoizedState.cachePool.pool),a!==l&&(t.flags|=2048),e!==null&&_(Vl),null;case 24:return l=null,e!==null&&(l=e.memoizedState.cache),t.memoizedState.cache!==l&&(t.flags|=2048),Wt(Qe),De(t),null;case 25:return null;case 30:return null}throw Error(o(156,t.tag))}function em(e,t){switch(Du(t),t.tag){case 1:return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return Wt(Qe),qe(),e=t.flags,(e&65536)!==0&&(e&128)===0?(t.flags=e&-65537|128,t):null;case 26:case 27:case 5:return Ul(t),null;case 31:if(t.memoizedState!==null){if(bt(t),t.alternate===null)throw Error(o(340));Xl()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 13:if(bt(t),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(o(340));Xl()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return _(we),null;case 4:return qe(),null;case 10:return Wt(t.type),null;case 22:case 23:return bt(t),Fu(),e!==null&&_(Vl),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 24:return Wt(Qe),null;case 25:return null;default:return null}}function ko(e,t){switch(Du(t),t.tag){case 3:Wt(Qe),qe();break;case 26:case 27:case 5:Ul(t);break;case 4:qe();break;case 31:t.memoizedState!==null&&bt(t);break;case 13:bt(t);break;case 19:_(we);break;case 10:Wt(t.type);break;case 22:case 23:bt(t),Fu(),e!==null&&_(Vl);break;case 24:Wt(Qe)}}function vn(e,t){try{var l=t.updateQueue,a=l!==null?l.lastEffect:null;if(a!==null){var n=a.next;l=n;do{if((l.tag&e)===e){a=void 0;var i=l.create,u=l.inst;a=i(),u.destroy=a}l=l.next}while(l!==n)}}catch(s){_e(t,t.return,s)}}function bl(e,t,l){try{var a=t.updateQueue,n=a!==null?a.lastEffect:null;if(n!==null){var i=n.next;a=i;do{if((a.tag&e)===e){var u=a.inst,s=u.destroy;if(s!==void 0){u.destroy=void 0,n=t;var f=l,g=s;try{g()}catch(T){_e(n,f,T)}}}a=a.next}while(a!==i)}}catch(T){_e(t,t.return,T)}}function Wo(e){var t=e.updateQueue;if(t!==null){var l=e.stateNode;try{Gf(t,l)}catch(a){_e(e,e.return,a)}}}function $o(e,t,l){l.props=Wl(e.type,e.memoizedProps),l.state=e.memoizedState;try{l.componentWillUnmount()}catch(a){_e(e,t,a)}}function gn(e,t){try{var l=e.ref;if(l!==null){switch(e.tag){case 26:case 27:case 5:var a=e.stateNode;break;case 30:a=e.stateNode;break;default:a=e.stateNode}typeof l=="function"?e.refCleanup=l(a):l.current=a}}catch(n){_e(e,t,n)}}function Lt(e,t){var l=e.ref,a=e.refCleanup;if(l!==null)if(typeof a=="function")try{a()}catch(n){_e(e,t,n)}finally{e.refCleanup=null,e=e.alternate,e!=null&&(e.refCleanup=null)}else if(typeof l=="function")try{l(null)}catch(n){_e(e,t,n)}else l.current=null}function Io(e){var t=e.type,l=e.memoizedProps,a=e.stateNode;try{e:switch(t){case"button":case"input":case"select":case"textarea":l.autoFocus&&a.focus();break e;case"img":l.src?a.src=l.src:l.srcSet&&(a.srcset=l.srcSet)}}catch(n){_e(e,e.return,n)}}function zc(e,t,l){try{var a=e.stateNode;Em(a,e.type,l,t),a[st]=t}catch(n){_e(e,e.return,n)}}function Po(e){return e.tag===5||e.tag===3||e.tag===26||e.tag===27&&Al(e.type)||e.tag===4}function Ac(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||Po(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&&Al(e.type)||e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function Nc(e,t,l){var a=e.tag;if(a===5||a===6)e=e.stateNode,t?(l.nodeType===9?l.body:l.nodeName==="HTML"?l.ownerDocument.body:l).insertBefore(e,t):(t=l.nodeType===9?l.body:l.nodeName==="HTML"?l.ownerDocument.body:l,t.appendChild(e),l=l._reactRootContainer,l!=null||t.onclick!==null||(t.onclick=Vt));else if(a!==4&&(a===27&&Al(e.type)&&(l=e.stateNode,t=null),e=e.child,e!==null))for(Nc(e,t,l),e=e.sibling;e!==null;)Nc(e,t,l),e=e.sibling}function zi(e,t,l){var a=e.tag;if(a===5||a===6)e=e.stateNode,t?l.insertBefore(e,t):l.appendChild(e);else if(a!==4&&(a===27&&Al(e.type)&&(l=e.stateNode),e=e.child,e!==null))for(zi(e,t,l),e=e.sibling;e!==null;)zi(e,t,l),e=e.sibling}function er(e){var t=e.stateNode,l=e.memoizedProps;try{for(var a=e.type,n=t.attributes;n.length;)t.removeAttributeNode(n[0]);at(t,a,l),t[Pe]=e,t[st]=l}catch(i){_e(e,e.return,i)}}var tl=!1,Ke=!1,Oc=!1,tr=typeof WeakSet=="function"?WeakSet:Set,$e=null;function tm(e,t){if(e=e.containerInfo,Wc=Ji,e=df(e),Eu(e)){if("selectionStart"in e)var l={start:e.selectionStart,end:e.selectionEnd};else e:{l=(l=e.ownerDocument)&&l.defaultView||window;var a=l.getSelection&&l.getSelection();if(a&&a.rangeCount!==0){l=a.anchorNode;var n=a.anchorOffset,i=a.focusNode;a=a.focusOffset;try{l.nodeType,i.nodeType}catch{l=null;break e}var u=0,s=-1,f=-1,g=0,T=0,z=e,S=null;t:for(;;){for(var E;z!==l||n!==0&&z.nodeType!==3||(s=u+n),z!==i||a!==0&&z.nodeType!==3||(f=u+a),z.nodeType===3&&(u+=z.nodeValue.length),(E=z.firstChild)!==null;)S=z,z=E;for(;;){if(z===e)break t;if(S===l&&++g===n&&(s=u),S===i&&++T===a&&(f=u),(E=z.nextSibling)!==null)break;z=S,S=z.parentNode}z=E}l=s===-1||f===-1?null:{start:s,end:f}}else l=null}l=l||{start:0,end:0}}else l=null;for($c={focusedElem:e,selectionRange:l},Ji=!1,$e=t;$e!==null;)if(t=$e,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,$e=e;else for(;$e!==null;){switch(t=$e,i=t.alternate,e=t.flags,t.tag){case 0:if((e&4)!==0&&(e=t.updateQueue,e=e!==null?e.events:null,e!==null))for(l=0;l title"))),at(i,a,l),i[Pe]=e,We(i),a=i;break e;case"link":var u=cd("link","href",n).get(a+(l.href||""));if(u){for(var s=0;sAe&&(u=Ae,Ae=W,W=u);var h=of(s,W),d=of(s,Ae);if(h&&d&&(E.rangeCount!==1||E.anchorNode!==h.node||E.anchorOffset!==h.offset||E.focusNode!==d.node||E.focusOffset!==d.offset)){var v=z.createRange();v.setStart(h.node,h.offset),E.removeAllRanges(),W>Ae?(E.addRange(v),E.extend(d.node,d.offset)):(v.setEnd(d.node,d.offset),E.addRange(v))}}}}for(z=[],E=s;E=E.parentNode;)E.nodeType===1&&z.push({element:E,left:E.scrollLeft,top:E.scrollTop});for(typeof s.focus=="function"&&s.focus(),s=0;sl?32:l,b.T=null,l=Bc,Bc=null;var i=_l,u=ul;if(Fe=0,Oa=_l=null,ul=0,(be&6)!==0)throw Error(o(331));var s=be;if(be|=4,dr(i.current),fr(i,i.current,u,l),be=s,Tn(0,!1),yt&&typeof yt.onPostCommitFiberRoot=="function")try{yt.onPostCommitFiberRoot(La,i)}catch{}return!0}finally{D.p=n,b.T=a,Mr(e,t)}}function Rr(e,t,l){t=At(l,t),t=yc(e.stateNode,t,2),e=gl(e,t,2),e!==null&&(Xa(e,2),wt(e))}function _e(e,t,l){if(e.tag===3)Rr(e,e,l);else for(;t!==null;){if(t.tag===3){Rr(t,e,l);break}else if(t.tag===1){var a=t.stateNode;if(typeof t.type.getDerivedStateFromError=="function"||typeof a.componentDidCatch=="function"&&(Tl===null||!Tl.has(a))){e=At(l,e),l=Do(2),a=gl(t,l,2),a!==null&&(Uo(l,a,t,e),Xa(a,2),wt(a));break}}t=t.return}}function Lc(e,t,l){var a=e.pingCache;if(a===null){a=e.pingCache=new nm;var n=new Set;a.set(t,n)}else n=a.get(t),n===void 0&&(n=new Set,a.set(t,n));n.has(l)||(Rc=!0,n.add(l),e=fm.bind(null,e,t,l),t.then(e,e))}function fm(e,t,l){var a=e.pingCache;a!==null&&a.delete(t),e.pingedLanes|=e.suspendedLanes&l,e.warmLanes&=~l,Me===e&&(oe&l)===l&&(Ge===4||Ge===3&&(oe&62914560)===oe&&300>ke()-Oi?(be&2)===0&&Ma(e,0):Dc|=l,Na===oe&&(Na=0)),wt(e)}function Dr(e,t){t===0&&(t=js()),e=Ll(e,t),e!==null&&(Xa(e,t),wt(e))}function om(e){var t=e.memoizedState,l=0;t!==null&&(l=t.retryLane),Dr(e,l)}function rm(e,t){var l=0;switch(e.tag){case 31:case 13:var a=e.stateNode,n=e.memoizedState;n!==null&&(l=n.retryLane);break;case 19:a=e.stateNode;break;case 22:a=e.stateNode._retryCache;break;default:throw Error(o(314))}a!==null&&a.delete(t),Dr(e,l)}function dm(e,t){return ee(e,t)}var Bi=null,Ra=null,wc=!1,qi=!1,Xc=!1,zl=0;function wt(e){e!==Ra&&e.next===null&&(Ra===null?Bi=Ra=e:Ra=Ra.next=e),qi=!0,wc||(wc=!0,mm())}function Tn(e,t){if(!Xc&&qi){Xc=!0;do for(var l=!1,a=Bi;a!==null;){if(e!==0){var n=a.pendingLanes;if(n===0)var i=0;else{var u=a.suspendedLanes,s=a.pingedLanes;i=(1<<31-vt(42|e)+1)-1,i&=n&~(u&~s),i=i&201326741?i&201326741|1:i?i|2:0}i!==0&&(l=!0,qr(a,i))}else i=oe,i=wn(a,a===Me?i:0,a.cancelPendingCommit!==null||a.timeoutHandle!==-1),(i&3)===0||wa(a,i)||(l=!0,qr(a,i));a=a.next}while(l);Xc=!1}}function hm(){Ur()}function Ur(){qi=wc=!1;var e=0;zl!==0&&_m()&&(e=zl);for(var t=ke(),l=null,a=Bi;a!==null;){var n=a.next,i=Hr(a,t);i===0?(a.next=null,l===null?Bi=n:l.next=n,n===null&&(Ra=l)):(l=a,(e!==0||(i&3)!==0)&&(qi=!0)),a=n}Fe!==0&&Fe!==5||Tn(e),zl!==0&&(zl=0)}function Hr(e,t){for(var l=e.suspendedLanes,a=e.pingedLanes,n=e.expirationTimes,i=e.pendingLanes&-62914561;0s)break;var T=f.transferSize,z=f.initiatorType;T&&Vr(z)&&(f=f.responseEnd,u+=T*(f"u"?null:document;function ad(e,t,l){var a=Da;if(a&&typeof t=="string"&&t){var n=jt(t);n='link[rel="'+e+'"][href="'+n+'"]',typeof l=="string"&&(n+='[crossorigin="'+l+'"]'),ld.has(n)||(ld.add(n),e={rel:e,crossOrigin:l,href:t},a.querySelector(n)===null&&(t=a.createElement("link"),at(t,"link",e),We(t),a.head.appendChild(t)))}}function Dm(e){cl.D(e),ad("dns-prefetch",e,null)}function Um(e,t){cl.C(e,t),ad("preconnect",e,t)}function Hm(e,t,l){cl.L(e,t,l);var a=Da;if(a&&e&&t){var n='link[rel="preload"][as="'+jt(t)+'"]';t==="image"&&l&&l.imageSrcSet?(n+='[imagesrcset="'+jt(l.imageSrcSet)+'"]',typeof l.imageSizes=="string"&&(n+='[imagesizes="'+jt(l.imageSizes)+'"]')):n+='[href="'+jt(e)+'"]';var i=n;switch(t){case"style":i=Ua(e);break;case"script":i=Ha(e)}Dt.has(i)||(e=H({rel:"preload",href:t==="image"&&l&&l.imageSrcSet?void 0:e,as:t},l),Dt.set(i,e),a.querySelector(n)!==null||t==="style"&&a.querySelector(An(i))||t==="script"&&a.querySelector(Nn(i))||(t=a.createElement("link"),at(t,"link",e),We(t),a.head.appendChild(t)))}}function Bm(e,t){cl.m(e,t);var l=Da;if(l&&e){var a=t&&typeof t.as=="string"?t.as:"script",n='link[rel="modulepreload"][as="'+jt(a)+'"][href="'+jt(e)+'"]',i=n;switch(a){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":i=Ha(e)}if(!Dt.has(i)&&(e=H({rel:"modulepreload",href:e},t),Dt.set(i,e),l.querySelector(n)===null)){switch(a){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":if(l.querySelector(Nn(i)))return}a=l.createElement("link"),at(a,"link",e),We(a),l.head.appendChild(a)}}}function qm(e,t,l){cl.S(e,t,l);var a=Da;if(a&&e){var n=la(a).hoistableStyles,i=Ua(e);t=t||"default";var u=n.get(i);if(!u){var s={loading:0,preload:null};if(u=a.querySelector(An(i)))s.loading=5;else{e=H({rel:"stylesheet",href:e,"data-precedence":t},l),(l=Dt.get(i))&&ns(e,l);var f=u=a.createElement("link");We(f),at(f,"link",e),f._p=new Promise(function(g,T){f.onload=g,f.onerror=T}),f.addEventListener("load",function(){s.loading|=1}),f.addEventListener("error",function(){s.loading|=2}),s.loading|=4,Xi(u,t,a)}u={type:"stylesheet",instance:u,count:1,state:s},n.set(i,u)}}}function Ym(e,t){cl.X(e,t);var l=Da;if(l&&e){var a=la(l).hoistableScripts,n=Ha(e),i=a.get(n);i||(i=l.querySelector(Nn(n)),i||(e=H({src:e,async:!0},t),(t=Dt.get(n))&&is(e,t),i=l.createElement("script"),We(i),at(i,"link",e),l.head.appendChild(i)),i={type:"script",instance:i,count:1,state:null},a.set(n,i))}}function Gm(e,t){cl.M(e,t);var l=Da;if(l&&e){var a=la(l).hoistableScripts,n=Ha(e),i=a.get(n);i||(i=l.querySelector(Nn(n)),i||(e=H({src:e,async:!0,type:"module"},t),(t=Dt.get(n))&&is(e,t),i=l.createElement("script"),We(i),at(i,"link",e),l.head.appendChild(i)),i={type:"script",instance:i,count:1,state:null},a.set(n,i))}}function nd(e,t,l,a){var n=(n=ne.current)?wi(n):null;if(!n)throw Error(o(446));switch(e){case"meta":case"title":return null;case"style":return typeof l.precedence=="string"&&typeof l.href=="string"?(t=Ua(l.href),l=la(n).hoistableStyles,a=l.get(t),a||(a={type:"style",instance:null,count:0,state:null},l.set(t,a)),a):{type:"void",instance:null,count:0,state:null};case"link":if(l.rel==="stylesheet"&&typeof l.href=="string"&&typeof l.precedence=="string"){e=Ua(l.href);var i=la(n).hoistableStyles,u=i.get(e);if(u||(n=n.ownerDocument||n,u={type:"stylesheet",instance:null,count:0,state:{loading:0,preload:null}},i.set(e,u),(i=n.querySelector(An(e)))&&!i._p&&(u.instance=i,u.state.loading=5),Dt.has(e)||(l={rel:"preload",as:"style",href:l.href,crossOrigin:l.crossOrigin,integrity:l.integrity,media:l.media,hrefLang:l.hrefLang,referrerPolicy:l.referrerPolicy},Dt.set(e,l),i||Lm(n,e,l,u.state))),t&&a===null)throw Error(o(528,""));return u}if(t&&a!==null)throw Error(o(529,""));return null;case"script":return t=l.async,l=l.src,typeof l=="string"&&t&&typeof t!="function"&&typeof t!="symbol"?(t=Ha(l),l=la(n).hoistableScripts,a=l.get(t),a||(a={type:"script",instance:null,count:0,state:null},l.set(t,a)),a):{type:"void",instance:null,count:0,state:null};default:throw Error(o(444,e))}}function Ua(e){return'href="'+jt(e)+'"'}function An(e){return'link[rel="stylesheet"]['+e+"]"}function id(e){return H({},e,{"data-precedence":e.precedence,precedence:null})}function Lm(e,t,l,a){e.querySelector('link[rel="preload"][as="style"]['+t+"]")?a.loading=1:(t=e.createElement("link"),a.preload=t,t.addEventListener("load",function(){return a.loading|=1}),t.addEventListener("error",function(){return a.loading|=2}),at(t,"link",l),We(t),e.head.appendChild(t))}function Ha(e){return'[src="'+jt(e)+'"]'}function Nn(e){return"script[async]"+e}function ud(e,t,l){if(t.count++,t.instance===null)switch(t.type){case"style":var a=e.querySelector('style[data-href~="'+jt(l.href)+'"]');if(a)return t.instance=a,We(a),a;var n=H({},l,{"data-href":l.href,"data-precedence":l.precedence,href:null,precedence:null});return a=(e.ownerDocument||e).createElement("style"),We(a),at(a,"style",n),Xi(a,l.precedence,e),t.instance=a;case"stylesheet":n=Ua(l.href);var i=e.querySelector(An(n));if(i)return t.state.loading|=4,t.instance=i,We(i),i;a=id(l),(n=Dt.get(n))&&ns(a,n),i=(e.ownerDocument||e).createElement("link"),We(i);var u=i;return u._p=new Promise(function(s,f){u.onload=s,u.onerror=f}),at(i,"link",a),t.state.loading|=4,Xi(i,l.precedence,e),t.instance=i;case"script":return i=Ha(l.src),(n=e.querySelector(Nn(i)))?(t.instance=n,We(n),n):(a=l,(n=Dt.get(i))&&(a=H({},l),is(a,n)),e=e.ownerDocument||e,n=e.createElement("script"),We(n),at(n,"link",a),e.head.appendChild(n),t.instance=n);case"void":return null;default:throw Error(o(443,t.type))}else t.type==="stylesheet"&&(t.state.loading&4)===0&&(a=t.instance,t.state.loading|=4,Xi(a,l.precedence,e));return t.instance}function Xi(e,t,l){for(var a=l.querySelectorAll('link[rel="stylesheet"][data-precedence],style[data-precedence]'),n=a.length?a[a.length-1]:null,i=n,u=0;u title"):null)}function wm(e,t,l){if(l===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;return t.rel==="stylesheet"?(e=t.disabled,typeof t.precedence=="string"&&e==null):!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 fd(e){return!(e.type==="stylesheet"&&(e.state.loading&3)===0)}function Xm(e,t,l,a){if(l.type==="stylesheet"&&(typeof a.media!="string"||matchMedia(a.media).matches!==!1)&&(l.state.loading&4)===0){if(l.instance===null){var n=Ua(a.href),i=t.querySelector(An(n));if(i){t=i._p,t!==null&&typeof t=="object"&&typeof t.then=="function"&&(e.count++,e=Zi.bind(e),t.then(e,e)),l.state.loading|=4,l.instance=i,We(i);return}i=t.ownerDocument||t,a=id(a),(n=Dt.get(n))&&ns(a,n),i=i.createElement("link"),We(i);var u=i;u._p=new Promise(function(s,f){u.onload=s,u.onerror=f}),at(i,"link",a),l.instance=i}e.stylesheets===null&&(e.stylesheets=new Map),e.stylesheets.set(l,t),(t=l.state.preload)&&(l.state.loading&3)===0&&(e.count++,l=Zi.bind(e),t.addEventListener("load",l),t.addEventListener("error",l))}}var us=0;function Qm(e,t){return e.stylesheets&&e.count===0&&Ki(e,e.stylesheets),0us?50:800)+t);return e.unsuspend=l,function(){e.unsuspend=null,clearTimeout(a),clearTimeout(n)}}:null}function Zi(){if(this.count--,this.count===0&&(this.imgCount===0||!this.waitingForImages)){if(this.stylesheets)Ki(this,this.stylesheets);else if(this.unsuspend){var e=this.unsuspend;this.unsuspend=null,e()}}}var Vi=null;function Ki(e,t){e.stylesheets=null,e.unsuspend!==null&&(e.count++,Vi=new Map,t.forEach(Zm,e),Vi=null,Zi.call(e))}function Zm(e,t){if(!(t.state.loading&4)){var l=Vi.get(e);if(l)var a=l.get(null);else{l=new Map,Vi.set(e,l);for(var n=e.querySelectorAll("link[data-precedence],style[data-precedence]"),i=0;i"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(m)}catch(y){console.error(y)}}return m(),ys.exports=u0(),ys.exports}var s0=c0();const f0=Object.freeze({active:!1,collecting:!1,target:null,index:0,numPoints:0,done:!1,success:!1}),ps=(m={})=>({...f0,...m}),bs=m=>`${m>0?"+":""}${m.toFixed(0)}`,o0=m=>`yaw:${bs(m.yaw)} pitch:${bs(m.pitch)} roll:${bs(m.roll)}`;class Je{constructor(y){this.callbacks=y||{},this.localVideoElement=null,this.displayVideoElement=null,this.canvas=null,this.stream=null,this.ws=null,this.isStreaming=!1,this.sessionId=null,this.sessionStartTime=null,this.frameRate=15,this.captureInterval=null,this.reconnectTimeout=null,this.currentStatus=!1,this.statusBuffer=[],this.bufferSize=3,this.latestDetectionData=null,this.lastConfidence=0,this._tessellation=null,this._animFrameId=null,this.calibration=ps(),this.stats={framesSent:0,framesProcessed:0,avgLatency:0,lastLatencies:[]}}async initCamera(y,p){try{return console.log("Initializing local camera..."),this.stream=await navigator.mediaDevices.getUserMedia({video:{width:{ideal:640},height:{ideal:480},facingMode:"user"},audio:!1}),this.localVideoElement=y,this.displayCanvas=p,this.localVideoElement&&(this.localVideoElement.srcObject=this.stream,this.localVideoElement.play()),this.canvas=document.createElement("canvas"),this.canvas.width=640,this.canvas.height=480,console.log("Local camera initialized"),!0}catch(o){throw console.error("Camera init error:",o),o}}async startStreaming(){if(!this.stream)throw new Error("Camera not initialized");if(this.isStreaming){console.warn("Already streaming");return}console.log("Starting WebSocket streaming..."),this.isStreaming=!0;try{if(!this._tessellation)try{const p=await(await fetch("/api/mesh-topology")).json();this._tessellation=p.tessellation}catch(y){console.warn("Failed to fetch mesh topology:",y)}await this.connectWebSocket(),this.startCapture(),this._lastDetection=null,this._startRenderLoop(),console.log("Streaming started")}catch(y){if(this.isStreaming=!1,this._stopRenderLoop(),this._lastDetection=null,this.captureInterval&&(clearInterval(this.captureInterval),this.captureInterval=null),this.reconnectTimeout&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=null),this.ws){this.ws.onopen=null,this.ws.onmessage=null,this.ws.onerror=null,this.ws.onclose=null;try{this.ws.close()}catch{}this.ws=null}throw y instanceof Error?y:new Error("Failed to start video streaming.")}}async connectWebSocket(){return new Promise((y,p)=>{const C=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws/video`;console.log("Connecting to WebSocket:",C);const M=new WebSocket(C);this.ws=M;let q=!1,Z=!1;const R=x=>{q||(q=!0,p(new Error(x)))};M.onopen=()=>{Z=!0,q=!0,console.log("WebSocket connected"),M.send(JSON.stringify({type:"start_session"})),y()},M.onmessage=x=>{try{const O=JSON.parse(x.data);this.handleServerMessage(O)}catch(O){console.error("Failed to parse message:",O)}},M.onerror=()=>{console.error("WebSocket error:",{url:C,readyState:M.readyState}),R(`Failed to connect to ${C}. Check that the backend server is running and reachable.`)},M.onclose=x=>{if(console.log("WebSocket disconnected",x.code,x.reason),this.ws===M&&(this.ws=null),!Z){R(`WebSocket closed before connection was established (${x.code||"no code"}). Check that the backend server is running on the expected port.`);return}this.isStreaming&&(console.log("Attempting to reconnect..."),this.reconnectTimeout&&clearTimeout(this.reconnectTimeout),this.reconnectTimeout=setTimeout(()=>{this.reconnectTimeout=null,this.isStreaming&&this.connectWebSocket().catch(O=>{console.error("Reconnect failed:",O)})},2e3))}})}startCapture(){const y=1e3/this.frameRate;this._sendingBlob=!1,this.captureInterval=setInterval(()=>{if(!(!this.isStreaming||!this.ws||this.ws.readyState!==WebSocket.OPEN)&&!this._sendingBlob)try{this.canvas.getContext("2d").drawImage(this.localVideoElement,0,0,this.canvas.width,this.canvas.height),this._sendingBlob=!0,this.canvas.toBlob(o=>{this._sendingBlob=!1,o&&this.ws&&this.ws.readyState===WebSocket.OPEN&&(this.ws.send(o),this.stats.framesSent++)},"image/jpeg",.75)}catch(p){this._sendingBlob=!1,console.error("Capture error:",p)}},y),console.log(`Capturing at ${this.frameRate} FPS`)}_startRenderLoop(){const y=()=>{if(this.isStreaming){if(this.displayCanvas&&this.localVideoElement&&this.localVideoElement.readyState>=2){const p=this.displayCanvas.getContext("2d"),o=this.displayCanvas.width,C=this.displayCanvas.height;p.drawImage(this.localVideoElement,0,0,o,C);const M=this._lastDetection;if(M){M.landmarks&&this.drawFaceMesh(p,M.landmarks,o,C),p.fillStyle="rgba(0,0,0,0.7)",p.fillRect(0,0,o,55);const q=M.focused?"FOCUSED":"NOT FOCUSED",Z=M.focused?"#00FF00":"#FF0000";p.fillStyle=Z,p.font="bold 18px Arial",p.fillText(q,10,22),M.model&&(p.fillStyle="#FFFFFF",p.font="12px Arial",p.textAlign="right",p.fillText(M.model.toUpperCase(),o-10,22),p.textAlign="left"),p.fillStyle="#FFFFFF",p.font="12px Arial";let R=`conf:${(M.confidence||0).toFixed(2)}`;M.sf!==void 0&&(R+=` S_face:${M.sf.toFixed(2)}`),M.se!==void 0&&(R+=` S_eye:${M.se.toFixed(2)}`),M.mar!==void 0&&(R+=` MAR:${M.mar.toFixed(2)}`),p.fillText(R,10,38),M.yaw!==void 0&&(p.fillStyle="#B4B4B4",p.font="11px Arial",p.textAlign="right",p.fillText(o0(M),o-10,48),p.textAlign="left")}if(M&&M.gaze_x!==void 0&&M.gaze_y!==void 0){const x=o-120-10,O=C-80-30;p.fillStyle="rgba(0, 0, 0, 0.7)",p.beginPath(),p.roundRect?p.roundRect(x-4,O-4,128,88,6):p.rect(x-4,O-4,128,88),p.fill(),p.fillStyle=M.on_screen?"rgba(30, 40, 60, 0.9)":"rgba(60, 20, 20, 0.9)",p.fillRect(x,O,120,80),p.strokeStyle=M.on_screen?"rgba(100, 180, 255, 0.6)":"rgba(255, 100, 100, 0.6)",p.lineWidth=1,p.strokeRect(x,O,120,80);const H=x+Math.max(0,Math.min(1,M.gaze_x))*120,V=O+Math.max(0,Math.min(1,M.gaze_y))*80,me=M.on_screen?"#00FF00":"#FF4444";p.beginPath(),p.arc(H,V,8,0,2*Math.PI),p.fillStyle=M.on_screen?"rgba(0, 255, 0, 0.15)":"rgba(255, 68, 68, 0.15)",p.fill(),p.beginPath(),p.arc(H,V,4,0,2*Math.PI),p.fillStyle=me,p.fill(),p.strokeStyle="#FFFFFF",p.lineWidth=1.5,p.stroke(),p.fillStyle="rgba(255, 255, 255, 0.6)",p.font="9px Arial",p.textAlign="left",p.fillText("GAZE",x+3,O+10)}p.fillStyle="rgba(0,0,0,0.5)",p.fillRect(0,C-25,o,25),p.font="12px Arial",p.fillStyle="#FFFFFF",p.fillText(`FPS: ${this.frameRate} | Latency: ${this.stats.avgLatency.toFixed(0)}ms`,10,C-8)}this._animFrameId=requestAnimationFrame(y)}};this._animFrameId=requestAnimationFrame(y)}_stopRenderLoop(){this._animFrameId&&(cancelAnimationFrame(this._animFrameId),this._animFrameId=null)}handleServerMessage(y){switch(y.type){case"session_started":this.sessionId=y.session_id,this.sessionStartTime=Date.now(),console.log("Session started:",this.sessionId),this.callbacks.onSessionStart&&this.callbacks.onSessionStart(this.sessionId);break;case"detection":this.stats.framesProcessed++;const p=performance.now();if(this._lastSendTime){const C=p-this._lastSendTime;this.stats.lastLatencies.push(C),this.stats.lastLatencies.length>10&&this.stats.lastLatencies.shift();const M=this.stats.lastLatencies.reduce((q,Z)=>q+Z,0);this.stats.avgLatency=M/this.stats.lastLatencies.length}this.updateStatus(y.focused),this.latestDetectionData={confidence:y.confidence||0,focused:y.focused,timestamp:p},this.lastConfidence=y.confidence||0,this.callbacks.onStatusUpdate&&this.callbacks.onStatusUpdate(this.currentStatus);const o={focused:y.focused,confidence:y.confidence||0,model:y.model,landmarks:y.lm||y.landmarks||null,yaw:y.yaw,pitch:y.pitch,roll:y.roll,mar:y.mar,sf:y.sf,se:y.se,gaze_x:y.gaze_x,gaze_y:y.gaze_y,on_screen:y.on_screen,gaze_yaw:y.gaze_yaw,gaze_pitch:y.gaze_pitch};this.drawDetectionResult(o);break;case"session_ended":console.log("Received session_ended message"),console.log("Session summary:",y.summary),this.callbacks.onSessionEnd?(console.log("Calling onSessionEnd callback"),this.callbacks.onSessionEnd(y.summary)):console.warn("No onSessionEnd callback registered"),this.sessionId=null,this.sessionStartTime=null;break;case"calibration_started":this.calibration={active:!0,collecting:!0,target:y.target,index:y.index,numPoints:y.num_points,done:!1,success:!1},this.callbacks.onCalibrationUpdate&&this.callbacks.onCalibrationUpdate({...this.calibration});break;case"calibration_point":this.calibration.target=y.target,this.calibration.index=y.index,this.callbacks.onCalibrationUpdate&&this.callbacks.onCalibrationUpdate({...this.calibration});break;case"calibration_verify":this.calibration.collecting=!0,this.calibration.target=y.target,this.calibration.index=-1,this.calibration.verifying=!0,this.calibration.verifyMessage=y.message||"Verify calibration",this.callbacks.onCalibrationUpdate&&this.callbacks.onCalibrationUpdate({...this.calibration});break;case"calibration_done":this.calibration.collecting=!1,this.calibration.verifying=!1,this.calibration.done=!0,this.calibration.success=y.success,this.callbacks.onCalibrationUpdate&&this.callbacks.onCalibrationUpdate({...this.calibration}),setTimeout(()=>{this.calibration.active=!1,this.callbacks.onCalibrationUpdate&&this.callbacks.onCalibrationUpdate({...this.calibration})},2e3);break;case"calibration_cancelled":this.calibration=ps(),this.callbacks.onCalibrationUpdate&&this.callbacks.onCalibrationUpdate({...this.calibration});break;case"error":console.error("Server error:",y.message);break;default:console.log("Unknown message type:",y.type)}}startCalibration(){this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.send(JSON.stringify({type:"calibration_start"}))}nextCalibrationPoint(){this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.send(JSON.stringify({type:"calibration_next"}))}cancelCalibration(){this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.send(JSON.stringify({type:"calibration_cancel"})),this.calibration=ps(),this.callbacks.onCalibrationUpdate&&this.callbacks.onCalibrationUpdate({...this.calibration})}static FACE_OVAL=[10,338,297,332,284,251,389,356,454,323,361,288,397,365,379,378,400,377,152,148,176,149,150,136,172,58,132,93,234,127,162,21,54,103,67,109,10];static LEFT_EYE=[33,7,163,144,145,153,154,155,133,173,157,158,159,160,161,246];static RIGHT_EYE=[362,382,381,380,374,373,390,249,263,466,388,387,386,385,384,398];static LEFT_IRIS=[468,469,470,471,472];static RIGHT_IRIS=[473,474,475,476,477];static LEFT_EYEBROW=[70,63,105,66,107,55,65,52,53,46];static RIGHT_EYEBROW=[300,293,334,296,336,285,295,282,283,276];static NOSE_BRIDGE=[6,197,195,5,4,1,19,94,2];static LIPS_OUTER=[61,146,91,181,84,17,314,405,321,375,291,409,270,269,267,0,37,39,40,185,61];static LIPS_INNER=[78,95,88,178,87,14,317,402,318,324,308,415,310,311,312,13,82,81,80,191,78];static LEFT_EAR_POINTS=[33,160,158,133,153,145];static RIGHT_EAR_POINTS=[362,385,387,263,373,380];static LEFT_IRIS_CENTER=468;static RIGHT_IRIS_CENTER=473;static LEFT_EYE_INNER=133;static LEFT_EYE_OUTER=33;static RIGHT_EYE_INNER=362;static RIGHT_EYE_OUTER=263;_drawPolyline(y,p,o,C,M,q,Z,R=!1){if(!p||o.length<2)return;const O=Array.isArray(p)?V=>p[V]:V=>p[String(V)];y.beginPath();const H=O(o[0]);if(H){y.moveTo(H[0]*C,H[1]*M);for(let V=1;Vp[k]:k=>p[String(k)];if(this._tessellation&&M){y.strokeStyle="rgba(200,200,200,0.25)",y.lineWidth=1,y.beginPath();for(const[k,Ee]of this._tessellation){const de=p[k],He=p[Ee];!de||!He||(y.moveTo(de[0]*o,de[1]*C),y.lineTo(He[0]*o,He[1]*C))}y.stroke()}this._drawPolyline(y,p,Je.FACE_OVAL,o,C,"rgba(0,255,255,0.5)",1,!0),this._drawPolyline(y,p,Je.LEFT_EYEBROW,o,C,"#90EE90",2),this._drawPolyline(y,p,Je.RIGHT_EYEBROW,o,C,"#90EE90",2),this._drawPolyline(y,p,Je.LEFT_EYE,o,C,"#00FF00",2,!0),this._drawPolyline(y,p,Je.RIGHT_EYE,o,C,"#00FF00",2,!0),this._drawPolyline(y,p,Je.NOSE_BRIDGE,o,C,"rgba(0,165,255,0.6)",1),this._drawPolyline(y,p,Je.LIPS_OUTER,o,C,"#FF00FF",1),this._drawPolyline(y,p,Je.LIPS_INNER,o,C,"rgba(200,0,200,0.7)",1);for(const k of[Je.LEFT_EAR_POINTS,Je.RIGHT_EAR_POINTS])for(const Ee of k){const de=q(Ee);de&&(y.beginPath(),y.arc(de[0]*o,de[1]*C,3,0,2*Math.PI),y.fillStyle="#FFFF00",y.fill())}const Z=[{iris:Je.LEFT_IRIS,center:Je.LEFT_IRIS_CENTER,inner:Je.LEFT_EYE_INNER,outer:Je.LEFT_EYE_OUTER},{iris:Je.RIGHT_IRIS,center:Je.RIGHT_IRIS_CENTER,inner:Je.RIGHT_EYE_INNER,outer:Je.RIGHT_EYE_OUTER}],R=this._lastDetection,x=R?R.gaze_yaw:void 0,O=R?R.gaze_pitch:void 0,H=R?R.on_screen:void 0,V=x!==void 0&&O!==void 0,me=H===!1?"#FF0000":"#00FF00",ie=100;for(const{iris:k,center:Ee,inner:de,outer:He}of Z){const Ne=q(k[0]);if(!Ne)continue;const xe=Ne[0]*o,Ce=Ne[1]*C;let le=0,A=0;for(let B=1;B0?le/A:3,2);if(y.beginPath(),y.arc(xe,Ce,w,0,2*Math.PI),y.strokeStyle="#FF00FF",y.lineWidth=2,y.stroke(),y.beginPath(),y.arc(xe,Ce,3,0,2*Math.PI),y.fillStyle=me,y.fill(),y.strokeStyle="#FFFFFF",y.lineWidth=1,y.stroke(),V){const B=-ie*Math.sin(O)*Math.cos(x),ye=-ie*Math.sin(x),fe=xe+B,ae=Ce+ye;y.beginPath(),y.moveTo(xe,Ce),y.lineTo(fe,ae),y.strokeStyle=me,y.lineWidth=3,y.stroke();const ue=Math.atan2(ae-Ce,fe-xe),Oe=10;y.beginPath(),y.moveTo(fe,ae),y.lineTo(fe-Oe*Math.cos(ue-.4),ae-Oe*Math.sin(ue-.4)),y.moveTo(fe,ae),y.lineTo(fe-Oe*Math.cos(ue+.4),ae-Oe*Math.sin(ue+.4)),y.strokeStyle=me,y.lineWidth=2,y.stroke()}else{const B=q(de),ye=q(He);if(B&&ye){const fe=(B[0]+ye[0])/2*o,ae=(B[1]+ye[1])/2*C,ue=xe-fe,Oe=Ce-ae,Be=Math.hypot(ue,Oe);if(Be>.5){const b=ie/Be;y.beginPath(),y.moveTo(xe,Ce),y.lineTo(xe+ue*b,Ce+Oe*b),y.strokeStyle="#00FFFF",y.lineWidth=2,y.stroke()}}}}}drawDetectionResult(y){this._lastDetection=y}updateStatus(y){if(this.statusBuffer.push(y),this.statusBuffer.length>this.bufferSize&&this.statusBuffer.shift(),this.statusBuffer.lengthC).length/this.statusBuffer.length;this.currentStatus,o>=.75?this.currentStatus=!0:o<=.25&&(this.currentStatus=!1)}async stopStreaming(){if(console.log("Stopping streaming..."),this.isStreaming=!1,this.reconnectTimeout&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=null),this._stopRenderLoop(),this._lastDetection=null,this.captureInterval&&(clearInterval(this.captureInterval),this.captureInterval=null),this.ws&&this.ws.readyState===WebSocket.OPEN&&this.sessionId){const y=this.sessionId,p=new Promise(o=>{const C=this.ws.onmessage,M=setTimeout(()=>{this.ws.onmessage=C,console.log("Session end timeout, proceeding anyway"),o()},2e3);this.ws.onmessage=q=>{try{const Z=JSON.parse(q.data);Z.type==="session_ended"?(clearTimeout(M),this.handleServerMessage(Z),this.ws.onmessage=C,o()):this.handleServerMessage(Z)}catch(Z){console.error("Failed to parse message:",Z)}}});console.log("Sending end_session request for session:",y),this.ws.send(JSON.stringify({type:"end_session",session_id:y})),await p}await new Promise(y=>setTimeout(y,200)),this.ws&&(this.ws.close(),this.ws=null),this.stream&&(this.stream.getTracks().forEach(y=>y.stop()),this.stream=null),this.localVideoElement&&(this.localVideoElement.srcObject=null),this.displayCanvas&&this.displayCanvas.getContext("2d").clearRect(0,0,this.displayCanvas.width,this.displayCanvas.height),console.log("Streaming stopped"),console.log("Stats:",this.stats)}setFrameRate(y){this.frameRate=Math.max(10,Math.min(30,y)),console.log(`Frame rate set to ${this.frameRate} FPS`),this.isStreaming&&this.captureInterval&&(clearInterval(this.captureInterval),this.startCapture())}getStats(){return{...this.stats,isStreaming:this.isStreaming,sessionId:this.sessionId,currentStatus:this.currentStatus,lastConfidence:this.lastConfidence}}}function r0({setActiveTab:m}){return c.jsxs("main",{id:"page-a",className:"page",children:[c.jsx("h1",{children:"FocusGuard"}),c.jsx("p",{children:"Your productivity monitor assistant."}),c.jsx("div",{className:"home-button-grid",children:c.jsx("button",{type:"button",className:"btn-main",onClick:()=>m("focus"),children:"Start Focus"})})]})}const d0=2e3,h0=3e3,m0=3e3;function y0({calibration:m,videoManager:y}){const[p,o]=J.useState(0),C=J.useRef(null),M=J.useRef(null),q=J.useRef(null),Z=J.useCallback(()=>{const k=q.current;if(!k)return;const Ee=k.requestFullscreen||k.webkitRequestFullscreen||k.msRequestFullscreen;Ee&&Ee.call(k).catch(()=>{})},[]),R=J.useCallback(()=>{if(document.fullscreenElement||document.webkitFullscreenElement){const k=document.exitFullscreen||document.webkitExitFullscreen||document.msExitFullscreen;k&&k.call(document).catch(()=>{})}},[]);J.useEffect(()=>{if(m&&m.active&&!m.done){const k=setTimeout(Z,100);return()=>clearTimeout(k)}},[m?.active]),J.useEffect(()=>{(!m||!m.active)&&R()},[m?.active]),J.useEffect(()=>{if(!m||!m.collecting||m.done){o(0),C.current&&cancelAnimationFrame(C.current);return}M.current=performance.now();const k=m.verifying?m0:m.index===0?h0:d0,Ee=()=>{const de=Math.min((performance.now()-M.current)/k,1);o(de),de>=1&&(y&&y.nextCalibrationPoint(),M.current=performance.now(),o(0)),C.current=requestAnimationFrame(Ee)};return C.current=requestAnimationFrame(Ee),()=>{C.current&&cancelAnimationFrame(C.current)}},[m?.index,m?.collecting,m?.done]);const x=()=>{y&&y.cancelCalibration(),R()};if(!m||!m.active)return null;if(m.done){const k=m.success;return c.jsx("div",{ref:q,className:"cal-overlay",children:c.jsxs("div",{className:`cal-done-card ${k?"cal-done-success":"cal-done-fail"}`,children:[c.jsx("div",{className:"cal-done-eyebrow",children:k?"Complete":"Failed"}),c.jsx("h2",{className:"cal-done-title",children:k?"Calibration Complete":"Calibration Failed"}),c.jsx("p",{className:"cal-done-subtitle",children:k?"Gaze tracking is now active.":"Not enough samples collected. Try again."})]})})}const[O,H]=m.target||[.5,.5],V=m.verifying,me=V?"#007BFF":"#28a745",ie=V?"rgba(0, 123, 255, 0.6)":"rgba(40, 167, 69, 0.6)";return c.jsxs("div",{ref:q,className:"cal-overlay",children:[c.jsx("div",{className:"cal-header",children:V?c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"cal-eyebrow cal-eyebrow-verify",children:"Verification"}),c.jsx("p",{className:"cal-instruction",children:"Look at the dot to confirm calibration accuracy"})]}):c.jsxs(c.Fragment,{children:[c.jsxs("span",{className:"cal-eyebrow cal-eyebrow-collect",children:["Point ",m.index+1," of ",m.numPoints]}),c.jsx("p",{className:"cal-instruction",children:m.index===0?"Look at the center dot — this sets your baseline":"Hold your gaze steady on the target"})]})}),c.jsxs("div",{className:"cal-target",style:{left:`${O*100}%`,top:`${H*100}%`},children:[c.jsxs("svg",{width:"60",height:"60",className:"cal-ring",children:[c.jsx("circle",{cx:"30",cy:"30",r:"24",fill:"none",stroke:"rgba(255,255,255,0.12)",strokeWidth:"3"}),c.jsx("circle",{cx:"30",cy:"30",r:"24",fill:"none",stroke:me,strokeWidth:"3",strokeDasharray:`${p*150.8} 150.8`,strokeLinecap:"round",transform:"rotate(-90, 30, 30)"})]}),c.jsx("div",{className:"cal-dot",style:{background:`radial-gradient(circle, #fff 30%, ${me} 100%)`,boxShadow:`0 0 24px ${ie}`}})]}),c.jsx("button",{onClick:x,className:"cal-cancel",children:"Cancel Calibration"})]})}const Xt={intro:"intro",permission:"permission",ready:"ready"},qt={pending:"pending",focused:"focused",notFocused:"not-focused"};function v0(){return c.jsxs("svg",{width:"96",height:"96",viewBox:"0 0 96 96","aria-hidden":"true",children:[c.jsx("circle",{cx:"48",cy:"48",r:"40",fill:"#007BFF"}),c.jsx("path",{d:"M30 38c0-4 2.7-7 6-7s6 3 6 7",fill:"none",stroke:"#fff",strokeWidth:"6",strokeLinecap:"round"}),c.jsx("path",{d:"M54 38c0-4 2.7-7 6-7s6 3 6 7",fill:"none",stroke:"#fff",strokeWidth:"6",strokeLinecap:"round"}),c.jsx("path",{d:"M30 52c3 11 10 17 18 17s15-6 18-17",fill:"none",stroke:"#fff",strokeWidth:"6",strokeLinecap:"round"})]})}function g0(){return c.jsxs("svg",{width:"110",height:"110",viewBox:"0 0 110 110","aria-hidden":"true",children:[c.jsx("rect",{x:"30",y:"36",width:"50",height:"34",rx:"5",fill:"none",stroke:"#007BFF",strokeWidth:"6"}),c.jsx("path",{d:"M24 72h62c0 9-7 16-16 16H40c-9 0-16-7-16-16Z",fill:"none",stroke:"#007BFF",strokeWidth:"6"}),c.jsx("path",{d:"M55 28v8",stroke:"#007BFF",strokeWidth:"6",strokeLinecap:"round"}),c.jsx("circle",{cx:"55",cy:"36",r:"14",fill:"none",stroke:"#007BFF",strokeWidth:"6"}),c.jsx("circle",{cx:"55",cy:"36",r:"4",fill:"#007BFF"}),c.jsx("path",{d:"M46 83h18",stroke:"#007BFF",strokeWidth:"6",strokeLinecap:"round"})]})}const S0=["hybrid","xgboost","mlp","geometric"],ct={hybrid:{label:"Hybrid",tagline:"Best overall — combines ML with geometric scoring",how:"Fuses XGBoost predictions (30%) with geometric face/eye scores (70%). A logistic regression meta-classifier combines both signals for the final decision.",accuracy:"84.3%",f1:"0.864",auc:"0.880",threshold:"0.46",evaluation:"Leave-One-Person-Out (9 participants, 144K frames)",features:"10 features: head deviation, face score, eye scores (EAR), gaze offset, pitch, horizontal gaze, PERCLOS",strengths:"Most robust across different people. Geometric scoring generalises well; ML catches subtle patterns.",badge:"Recommended"},xgboost:{label:"XGBoost",tagline:"Highest raw accuracy — gradient-boosted decision trees",how:"Ensemble of 600 decision trees (max depth 8). Each tree learns to correct errors from previous trees. Outputs probability of focused state.",accuracy:"84.3%",f1:"0.859",auc:"0.880",threshold:"0.38",evaluation:"Leave-One-Person-Out (9 participants, 144K frames)",features:"10 features: head deviation, face score, eye scores (EAR), gaze offset, pitch, horizontal gaze, PERCLOS",strengths:"Strong pattern recognition. Handles non-linear feature interactions. 95.9% accuracy on random split (but LOPO is the fairer test).",badge:null},mlp:{label:"MLP",tagline:"Lightweight neural network — fast and efficient",how:"Two-layer neural network (64→32 neurons). Takes 10 face features, applies learned weights, outputs focused/unfocused probability via softmax.",accuracy:"82.7%",f1:"0.858",auc:"0.862",threshold:"0.23",evaluation:"Leave-One-Person-Out (9 participants, 144K frames)",features:"10 features: head deviation, face score, eye scores (EAR), gaze offset, pitch, horizontal gaze, PERCLOS",strengths:"Fastest inference. Smallest model size. Good baseline. 92.9% accuracy on random split.",badge:null},geometric:{label:"Geometric",tagline:"Baseline only — hardcoded thresholds, no learning",how:"Uses fixed thresholds on head orientation (70%) and eye openness (30%). No training — just hand-tuned rules on 478 face landmarks. Cannot adapt to new faces or environments.",accuracy:"~77%",f1:"0.772",auc:"N/A",threshold:"0.55",evaluation:"Leave-One-Person-Out geometric sweep",features:"Head yaw/pitch/roll angles, eye aspect ratio (EAR), iris gaze offset, mouth aspect ratio (MAR)",strengths:"No model files needed. Useful as a fallback. This is the baseline that motivated building the ML models — its fixed thresholds struggle with different face shapes, lighting, and camera angles.",badge:"Baseline"}};function p0({videoManager:m,sessionResult:y,setSessionResult:p,isActive:o}){const[C,M]=J.useState(15),[q,Z]=J.useState([]),[R,x]=J.useState(null),[O,H]=J.useState(null),[V,me]=J.useState([]),[ie,k]=J.useState("mlp"),[Ee,de]=J.useState(Xt.intro),[He,Ne]=J.useState(!1),[xe,Ce]=J.useState(!1),[le,A]=J.useState(qt.pending),[w,B]=J.useState(""),[ye,fe]=J.useState(null),[ae,ue]=J.useState(!1),[Oe,Be]=J.useState(!1),b=J.useRef(null),D=J.useRef(null),Y=J.useRef(null),L=J.useRef(null),$=J.useRef(null),r=N=>{if(N===0)return"0s";const ee=Math.floor(N/60),pe=Math.floor(N%60);return`${ee}m ${pe}s`},_=()=>{$.current&&(cancelAnimationFrame($.current),$.current=null)},U=()=>{_();const N=()=>{const ee=D.current,pe=b.current;if(!ee||!pe||!He||m?.isStreaming){$.current=null;return}pe.readyState>=2&&ee.getContext("2d").drawImage(pe,0,0,ee.width,ee.height),$.current=requestAnimationFrame(N)};$.current=requestAnimationFrame(N)},G=N=>N?.name==="NotAllowedError"?"Camera permission denied. Please allow camera access.":N?.name==="NotFoundError"?"No camera found. Please connect a camera.":N?.name==="NotReadableError"?"Camera is already in use by another application.":N?.target?.url?`WebSocket connection failed: ${N.target.url}. Check that the backend server is running.`:N?.message||"Failed to start focus session.";J.useEffect(()=>{if(!m)return;const N=m.callbacks.onStatusUpdate,ee=m.callbacks.onSessionEnd;m.callbacks.onStatusUpdate=Le=>{Z(it=>{const ke=[...it,{isFocused:Le,timestamp:Date.now()}];return ke.length>60&&ke.shift(),ke}),A(Le?qt.focused:qt.notFocused),N&&N(Le)},m.callbacks.onSessionEnd=Le=>{A(qt.pending),Ne(!1),ee&&ee(Le)},m.callbacks.onCalibrationUpdate=Le=>{fe(Le&&Le.active?{...Le}:null)};const pe=setInterval(()=>{m&&m.getStats&&x(m.getStats())},1e3);return()=>{m&&(m.callbacks.onStatusUpdate=N,m.callbacks.onSessionEnd=ee,m.callbacks.onCalibrationUpdate=null),clearInterval(pe)}},[m]),J.useEffect(()=>{fetch("/api/models").then(N=>N.json()).then(N=>{if(N.available&&me(N.available),N.current)if(N.current==="l2cs"){const ee=N.available.find(pe=>pe!=="l2cs")||"mlp";k(ee),F(ee)}else k(N.current);N.l2cs_boost!==void 0&&ue(N.l2cs_boost),N.l2cs_boost_available!==void 0&&Be(N.l2cs_boost_available)}).catch(N=>console.error("Failed to fetch models:",N))},[]),J.useEffect(()=>{if(Ee===Xt.ready&&He&&!m?.isStreaming){U();return}_()},[He,Ee,m?.isStreaming]),J.useEffect(()=>{o||_()},[o]),J.useEffect(()=>()=>{_(),Y.current&&(Y.current.pause(),Y.current.srcObject=null),L.current&&(L.current.getTracks().forEach(N=>N.stop()),L.current=null)},[]),J.useEffect(()=>{const N=()=>{fetch("/api/stats/system").then(pe=>pe.json()).then(pe=>H(pe)).catch(()=>H(null))};N();const ee=setInterval(N,3e3);return()=>clearInterval(ee)},[]);const F=async N=>{try{(await(await fetch("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({model_name:N})})).json()).updated&&k(N)}catch(ee){console.error("Failed to switch model:",ee)}},ne=async()=>{if(m)try{B(""),await m.initCamera(b.current,D.current),Ne(!0),de(Xt.ready),A(qt.pending)}catch(N){const ee=G(N);B(ee),console.error("Camera init error:",N)}},ve=async()=>{const N=!ae;try{if(!(await fetch("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({l2cs_boost:N})})).ok)return;ue(N),N&&m&&m.isStreaming?m.startCalibration():!N&&m&&m.cancelCalibration()}catch(ee){console.error("Failed to toggle eye gaze:",ee)}},Ie=async()=>{try{Ce(!0),p(null),Z([]),A(qt.pending),B(""),He||(await m.initCamera(b.current,D.current),Ne(!0),de(Xt.ready)),await m.startStreaming()}catch(N){const ee=G(N);B(ee),A(qt.pending),console.error("Start error:",N),alert(`Failed to start: ${ee} + +Check browser console for details.`)}finally{Ce(!1)}},qe=async()=>{m&&await m.stopStreaming();try{document.pictureInPictureElement===Y.current&&await document.exitPictureInPicture()}catch{}Y.current&&(Y.current.pause(),Y.current.srcObject=null),L.current&&(L.current.getTracks().forEach(N=>N.stop()),L.current=null),_(),A(qt.pending),Ne(!1)},Dl=async()=>{try{if(!m||!m.isStreaming){alert("Please start the video first.");return}if(!D.current){alert("Video not ready.");return}if(document.pictureInPictureElement===Y.current){await document.exitPictureInPicture(),console.log("PiP exited");return}if(!document.pictureInPictureEnabled){alert("Picture-in-Picture is not supported in this browser.");return}const N=Y.current;if(!N){alert("PiP video element not ready.");return}const ee=typeof N.webkitSetPresentationMode=="function";let pe=L.current;if(!pe){const Le=D.current.captureStream;if(typeof Le=="function"&&(pe=Le.call(D.current,30)),!pe||pe.getTracks().length===0){const it=b.current?.srcObject;if(!it){alert("Camera stream not ready.");return}pe=it}L.current=pe}if(!pe||pe.getTracks().length===0){alert("Failed to capture video stream from canvas.");return}N.srcObject=pe,N.readyState<2&&await new Promise(Le=>{const it=()=>{N.removeEventListener("loadeddata",it),N.removeEventListener("canplay",it),Le()};N.addEventListener("loadeddata",it),N.addEventListener("canplay",it),setTimeout(Le,600)});try{await N.play()}catch{}if(ee)try{N.webkitSetPresentationMode("picture-in-picture"),console.log("PiP activated (Safari)");return}catch(Le){const it=b.current?.srcObject;if(it&&it!==N.srcObject){N.srcObject=it;try{await N.play()}catch{}N.webkitSetPresentationMode("picture-in-picture"),console.log("PiP activated (Safari fallback)");return}throw Le}typeof N.requestPictureInPicture=="function"?(await N.requestPictureInPicture(),console.log("PiP activated")):alert("Picture-in-Picture is not supported in this browser.")}catch(N){console.error("PiP error:",N),alert(`Failed to enter Picture-in-Picture: ${N.message}`)}},Ul=N=>{const ee=parseInt(N,10);M(ee),m&&m.setFrameRate(ee)},qa=()=>{if(!m||!m.isStreaming){alert("Please start a session first.");return}const N=m.getStats();if(!N.sessionId){alert("No active session.");return}const ee=Math.floor((Date.now()-(m.sessionStartTime||Date.now()))/1e3),pe=N.framesProcessed>0?N.framesProcessed*(N.currentStatus?1:0)/N.framesProcessed:0;p({duration_seconds:ee,focus_score:pe,total_frames:N.framesProcessed,focused_frames:Math.floor(N.framesProcessed*pe)})},Hn=()=>{p(null)},Qt=o?void 0:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",opacity:0,pointerEvents:"none"},Ya={[qt.pending]:"Pending",[qt.focused]:"Focused",[qt.notFocused]:"Not Focused"}[le],Ga=[{title:"Live focus tracking",text:"Head pose, gaze, and eye openness are read continuously during the session."},{title:"Quick setup",text:"Front-facing light and a stable camera angle give the cleanest preview."},{title:"Private by default",text:"Only session metadata is stored, not the raw camera footage."}],eu=[{title:"Allow browser access",text:"Approve the camera prompt so the preview can appear immediately."},{title:"Check your framing",text:"Keep your face visible and centered for more stable landmark detection."},{title:"Start when ready",text:"After the preview appears, use the page controls to begin or stop."}],Bn=()=>Ee===Xt.intro?c.jsx("div",{className:"focus-flow-overlay",children:c.jsxs("div",{className:"focus-flow-card",children:[c.jsxs("div",{className:"focus-flow-header",children:[c.jsxs("div",{children:[c.jsx("div",{className:"focus-flow-eyebrow",children:"Focus Session"}),c.jsx("h2",{children:"Before you begin"})]}),c.jsx("div",{className:"focus-flow-icon",children:c.jsx(v0,{})})]}),c.jsx("p",{className:"focus-flow-lead",children:"The focus page uses your live camera preview to estimate attention in real time. Review the setup notes below, then continue to camera access."}),c.jsx("div",{className:"focus-flow-grid",children:Ga.map(N=>c.jsxs("article",{className:"focus-flow-panel",children:[c.jsx("h3",{children:N.title}),c.jsx("p",{children:N.text})]},N.title))}),c.jsxs("div",{className:"focus-flow-footer",children:[c.jsx("div",{className:"focus-flow-note",children:"You can still change frame rate and available model options after the preview loads."}),c.jsx("button",{className:"focus-flow-button",onClick:()=>de(Xt.permission),children:"Continue"})]})]})}):Ee===Xt.permission&&!He?c.jsx("div",{className:"focus-flow-overlay",children:c.jsxs("div",{className:"focus-flow-card",children:[c.jsxs("div",{className:"focus-flow-header",children:[c.jsxs("div",{children:[c.jsx("div",{className:"focus-flow-eyebrow",children:"Camera Setup"}),c.jsx("h2",{children:"Enable camera access"})]}),c.jsx("div",{className:"focus-flow-icon",children:c.jsx(g0,{})})]}),c.jsx("p",{className:"focus-flow-lead",children:"Once access is granted, your preview appears here and the rest of the Focus page behaves like the other dashboard screens."}),c.jsx("div",{className:"focus-flow-steps",children:eu.map((N,ee)=>c.jsxs("div",{className:"focus-flow-step",children:[c.jsx("div",{className:"focus-flow-step-number",children:ee+1}),c.jsxs("div",{className:"focus-flow-step-copy",children:[c.jsx("h3",{children:N.title}),c.jsx("p",{children:N.text})]})]},N.title))}),w?c.jsx("div",{className:"focus-inline-error",children:w}):null,c.jsxs("div",{className:"focus-flow-footer",children:[c.jsx("button",{type:"button",className:"focus-flow-secondary",onClick:()=>de(Xt.intro),children:"Back"}),c.jsx("button",{className:"focus-flow-button",onClick:ne,children:"Enable Camera"})]})]})}):null;return c.jsxs("main",{id:"page-b",className:"page",style:Qt,children:[Bn(),c.jsxs("section",{id:"display-area",className:"focus-display-shell",children:[c.jsx("video",{ref:Y,muted:!0,playsInline:!0,autoPlay:!0,style:{position:"absolute",width:"1px",height:"1px",opacity:0,pointerEvents:"none"}}),c.jsx("video",{ref:b,muted:!0,playsInline:!0,autoPlay:!0,style:{display:"none"}}),c.jsx("canvas",{ref:D,width:640,height:480,style:{width:"100%",height:"100%",objectFit:"contain",backgroundColor:"#101010"}}),Ee===Xt.ready?c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:`focus-state-pill ${le}`,children:[c.jsx("span",{className:"focus-state-dot"}),Ya]}),!He&&!m?.isStreaming?c.jsxs("div",{className:"focus-idle-overlay",children:[c.jsx("p",{children:"Camera is paused."}),c.jsx("span",{children:"Use Start to enable the camera and begin detection."})]}):null]}):null,y&&c.jsxs("div",{className:"session-result-overlay",children:[c.jsx("h3",{children:"Session Complete!"}),c.jsxs("div",{className:"result-item",children:[c.jsx("span",{className:"label",children:"Duration:"}),c.jsx("span",{className:"value",children:r(y.duration_seconds)})]}),c.jsxs("div",{className:"result-item",children:[c.jsx("span",{className:"label",children:"Focus Score:"}),c.jsxs("span",{className:"value",children:[(y.focus_score*100).toFixed(1),"%"]})]}),c.jsx("button",{onClick:Hn,style:{marginTop:"20px",padding:"8px 20px",background:"transparent",border:"1px solid white",color:"white",borderRadius:"20px",cursor:"pointer"},children:"Close"})]})]}),Ee===Xt.ready?c.jsxs(c.Fragment,{children:[V.length>0?c.jsxs("section",{className:"focus-model-strip",children:[c.jsx("span",{className:"focus-model-label",children:"Model:"}),S0.filter(N=>V.includes(N)).map(N=>c.jsx("button",{onClick:()=>F(N),className:`focus-model-button ${ie===N?"active":""}`,children:ct[N]?.label||N},N)),Oe&&c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"focus-model-sep"}),c.jsxs("button",{onClick:ve,className:`eye-gaze-toggle ${ae?"on":"off"}`,title:ae?"Eye gaze tracking active — click to disable":"Enable eye gaze tracking (requires calibration)",children:[c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",className:"eye-gaze-icon","aria-hidden":"true",children:[c.jsx("ellipse",{cx:"8",cy:"8",rx:"7",ry:"4.5",fill:"none",stroke:"currentColor",strokeWidth:"1.4"}),c.jsx("circle",{cx:"8",cy:"8",r:"2.2",fill:"currentColor"})]}),ae?"Eye Gaze On":"Eye Gaze"]}),ae&&R&&R.isStreaming&&c.jsx("button",{onClick:()=>m&&m.startCalibration(),className:"focus-model-button recalibrate",title:"Re-run gaze calibration",children:"Recalibrate"})]})]}):null,O&&O.cpu_percent!=null&&c.jsxs("section",{className:"focus-system-stats",children:[c.jsxs("span",{children:["CPU: ",c.jsxs("strong",{children:[O.cpu_percent,"%"]})]}),c.jsx("span",{className:"focus-system-stats-sep"}),c.jsxs("span",{children:["RAM: ",c.jsxs("strong",{children:[O.memory_percent,"%"]})," (",O.memory_used_mb,"/",O.memory_total_mb," MB)"]})]}),c.jsxs("section",{id:"timeline-area",children:[c.jsx("div",{className:"timeline-label",children:"Timeline"}),c.jsx("div",{id:"timeline-visuals",children:q.map((N,ee)=>c.jsx("div",{className:"timeline-block",style:{backgroundColor:N.isFocused?"#28a745":"#dc3545",width:"10px",height:"20px",display:"inline-block",marginRight:"2px",borderRadius:"2px"},title:N.isFocused?"Focused":"Distracted"},ee))}),c.jsx("div",{id:"timeline-line"})]}),c.jsxs("section",{id:"control-panel",children:[c.jsx("button",{id:"btn-cam-start",className:"action-btn green",onClick:Ie,disabled:xe,children:xe?"Starting...":"Start"}),c.jsx("button",{id:"btn-floating",className:"action-btn blue",onClick:Dl,children:"Floating Window"}),c.jsx("button",{id:"btn-preview",className:"action-btn orange",onClick:qa,children:"Preview Result"}),c.jsx("button",{id:"btn-cam-stop",className:"action-btn red",onClick:qe,children:"Stop"})]}),w?c.jsx("div",{className:"focus-inline-error focus-inline-error-standalone",children:w}):null,ct[ie]&&c.jsxs("section",{className:"model-card",children:[c.jsxs("div",{className:"model-card-header",children:[c.jsx("h3",{className:"model-card-title",children:ct[ie].label}),ct[ie].badge&&c.jsx("span",{className:ct[ie].badge==="Baseline"?"model-card-badge-baseline":"model-card-badge",children:ct[ie].badge})]}),c.jsx("p",{className:"model-card-tagline",children:ct[ie].tagline}),c.jsxs("div",{className:"model-card-metrics",children:[c.jsxs("div",{className:"model-card-metric",children:[c.jsx("span",{className:"model-card-metric-value",children:ct[ie].accuracy}),c.jsx("span",{className:"model-card-metric-label",children:"Accuracy"})]}),c.jsxs("div",{className:"model-card-metric",children:[c.jsx("span",{className:"model-card-metric-value",children:ct[ie].f1}),c.jsx("span",{className:"model-card-metric-label",children:"F1 Score"})]}),c.jsxs("div",{className:"model-card-metric",children:[c.jsx("span",{className:"model-card-metric-value",children:ct[ie].auc}),c.jsx("span",{className:"model-card-metric-label",children:"ROC-AUC"})]}),c.jsxs("div",{className:"model-card-metric",children:[c.jsx("span",{className:"model-card-metric-value",children:ct[ie].threshold}),c.jsx("span",{className:"model-card-metric-label",children:"Threshold"})]})]}),c.jsxs("div",{className:"model-card-details",children:[c.jsxs("div",{className:"model-card-section",children:[c.jsx("h4",{children:"How it works"}),c.jsx("p",{children:ct[ie].how})]}),c.jsxs("div",{className:"model-card-section",children:[c.jsx("h4",{children:"Features used"}),c.jsx("p",{children:ct[ie].features})]}),c.jsxs("div",{className:"model-card-section",children:[c.jsx("h4",{children:"Strengths"}),c.jsx("p",{children:ct[ie].strengths})]})]}),c.jsxs("div",{className:"model-card-eval",children:["Evaluated with ",ct[ie].evaluation]})]}),c.jsxs("section",{id:"frame-control",children:[c.jsx("label",{htmlFor:"frame-slider",children:"Frame Rate (FPS)"}),c.jsx("input",{type:"range",id:"frame-slider",min:"10",max:"30",value:C,onChange:N=>Ul(N.target.value)}),c.jsx("input",{type:"number",id:"frame-input",min:"10",max:"30",value:C,onChange:N=>Ul(N.target.value)})]})]}):null,c.jsx(y0,{calibration:ye,videoManager:m})]})}function b0(){const[m,y]=J.useState({total_sessions:0,total_focus_time:0,avg_focus_score:0,streak_days:0}),[p,o]=J.useState(null),[C,M]=J.useState([]),[q,Z]=J.useState(!0),R=O=>{const H=Math.floor(O/3600),V=Math.floor(O%3600/60);return H>0?`${H}h ${V}m`:`${V}m`};J.useEffect(()=>{fetch("/api/stats/summary").then(O=>O.json()).then(O=>{y(O),x(O),Z(!1)}).catch(O=>{console.error("Failed to load stats:",O),Z(!1)})},[]),J.useEffect(()=>{const O=()=>{fetch("/api/stats/system").then(V=>V.json()).then(V=>o(V)).catch(()=>o(null))};O();const H=setInterval(O,3e3);return()=>clearInterval(H)},[]);const x=O=>{O.total_sessions>=1,O.total_sessions>=10,O.total_sessions>=50,O.avg_focus_score>=.8&&O.total_sessions>=5,O.streak_days>=7,O.streak_days>=30,O.total_focus_time>=36e3;const H=[{id:"first-session",name:"First Step",description:"Complete your first focus session",icon:"🎯",unlocked:O.total_sessions>=1},{id:"ten-sessions",name:"Getting Started",description:"Complete 10 focus sessions",icon:"⭐",unlocked:O.total_sessions>=10},{id:"fifty-sessions",name:"Dedicated",description:"Complete 50 focus sessions",icon:"🏆",unlocked:O.total_sessions>=50},{id:"focus-master",name:"Focus Master",description:"Maintain 80%+ average focus score",icon:"🧠",unlocked:O.avg_focus_score>=.8&&O.total_sessions>=5},{id:"week-streak",name:"Week Warrior",description:"7 day streak",icon:"🔥",unlocked:O.streak_days>=7},{id:"month-streak",name:"Month Master",description:"30 day streak",icon:"💎",unlocked:O.streak_days>=30},{id:"ten-hours",name:"Endurance",description:"10+ hours total focus time",icon:"⏱️",unlocked:O.total_focus_time>=36e3},{id:"hundred-sessions",name:"Centurion",description:"Complete 100 focus sessions",icon:"👑",unlocked:O.total_sessions>=100}];M(H)};return c.jsxs("main",{id:"page-c",className:"page",children:[c.jsx("h1",{className:"page-title",children:"My Achievement"}),q?c.jsx("div",{style:{textAlign:"center",padding:"40px",color:"#888"},children:"Loading stats..."}):c.jsxs(c.Fragment,{children:[p&&p.cpu_percent!=null&&c.jsxs("div",{style:{textAlign:"center",marginBottom:"12px",padding:"8px 12px",background:"rgba(0,0,0,0.2)",borderRadius:"8px",fontSize:"13px",color:"#aaa"},children:["Server: CPU ",c.jsxs("strong",{style:{color:"#8f8"},children:[p.cpu_percent,"%"]})," · ","RAM ",c.jsxs("strong",{style:{color:"#8af"},children:[p.memory_percent,"%"]}),p.memory_used_mb!=null&&` (${p.memory_used_mb}/${p.memory_total_mb} MB)`]}),c.jsxs("div",{className:"stats-grid",children:[c.jsxs("div",{className:"stat-card",children:[c.jsx("div",{className:"stat-number",id:"total-sessions",children:m.total_sessions}),c.jsx("div",{className:"stat-label",children:"Total Sessions"})]}),c.jsxs("div",{className:"stat-card",children:[c.jsx("div",{className:"stat-number",id:"total-hours",children:R(m.total_focus_time)}),c.jsx("div",{className:"stat-label",children:"Total Focus Time"})]}),c.jsxs("div",{className:"stat-card",children:[c.jsxs("div",{className:"stat-number",id:"avg-focus",children:[(m.avg_focus_score*100).toFixed(1),"%"]}),c.jsx("div",{className:"stat-label",children:"Average Focus"})]}),c.jsxs("div",{className:"stat-card",children:[c.jsx("div",{className:"stat-number",id:"current-streak",children:m.streak_days}),c.jsx("div",{className:"stat-label",children:"Day Streak"})]})]}),c.jsxs("div",{className:"achievements-section",children:[c.jsx("h2",{children:"Badges"}),c.jsx("div",{id:"badges-container",className:"badges-grid",children:C.map(O=>c.jsxs("div",{className:`badge ${O.unlocked?"unlocked":"locked"}`,style:{padding:"20px",textAlign:"center",border:"2px solid",borderColor:O.unlocked?"#00FF00":"#444",borderRadius:"10px",backgroundColor:O.unlocked?"rgba(0, 255, 0, 0.1)":"rgba(68, 68, 68, 0.1)",opacity:O.unlocked?1:.5,transition:"all 0.3s"},children:[c.jsx("div",{style:{fontSize:"48px",marginBottom:"10px"},children:O.unlocked?O.icon:"🔒"}),c.jsx("div",{style:{fontWeight:"bold",marginBottom:"5px"},children:O.name}),c.jsx("div",{style:{fontSize:"12px",color:"#888"},children:O.description})]},O.id))})]})]})]})}function x0(){const[m,y]=J.useState("all"),[p,o]=J.useState([]),[C,M]=J.useState(!1),[q,Z]=J.useState({open:!1,loading:!1,error:"",session:null}),R=J.useRef(null),x=A=>{const w=Math.max(0,Number(A)||0),B=Math.floor(w/60),ye=w%60;return`${B}m ${ye}s`},O=A=>new Date(A).toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}),H=A=>A?new Date(A).toLocaleString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"}):"Not available",V=A=>{if(!A)return{};if(typeof A=="object")return A;try{return JSON.parse(A)}catch{return{}}},me=A=>{const w=A.filter(B=>Number.isFinite(B));return w.length===0?null:w.reduce((B,ye)=>B+ye,0)/w.length},ie=(A,w=48)=>{if(!A.length)return[];const B=Math.ceil(A.length/w),ye=[];for(let fe=0;feD.isFocused).length/ae.length,Be=me(ae.map(D=>D.confidence));let b="distracted";Oe>=.75?b="focused":Oe>=.35&&(b="mixed"),ye.push({tone:b,focusRatio:Oe,confidence:Be,count:ae.length})}return ye},k=A=>{if(!A)return null;const w=(A.events||[]).map(L=>{const $=V(L.detection_data);return{...L,metadata:$,isFocused:!!L.is_focused,confidence:Number(L.confidence)||0}}),B=A.total_frames?A.focused_frames/A.total_frames:w.length?w.filter(L=>L.isFocused).length/w.length:0,ye=w.reduce((L,$)=>{const r=$.metadata?.model;return r&&(L[r]=(L[r]||0)+1),L},{}),fe=Object.entries(ye).sort((L,$)=>$[1]-L[1])[0]?.[0]||"Unavailable",ae=me(w.map(L=>L.confidence)),ue=me(w.map(L=>Number(L.metadata?.s_face))),Oe=me(w.map(L=>Number(L.metadata?.s_eye))),Be=me(w.map(L=>Number(L.metadata?.mar))),b=A.start_time?new Date(A.start_time):null,D=ie(w),Y=w.slice(-10).reverse();return{parsedEvents:w,focusRatio:B,dominantModel:fe,avgConfidence:ae,avgFaceScore:ue,avgEyeScore:Oe,avgMar:Be,timeline:D,recentEvents:Y,formatOffset(L){if(!b||!L)return"--";const $=Math.max(0,Math.round((new Date(L)-b)/1e3)),r=Math.floor($/60),_=$%60;return r>0?`${r}m ${_}s`:`${_}s`}}},Ee=A=>A>=.8?"excellent":A>=.6?"good":A>=.4?"fair":"low",de=()=>{Z({open:!1,loading:!1,error:"",session:null})},He=async A=>{M(!0);try{const B=await(await fetch(`/api/sessions?filter=${A}&limit=50`)).json();o(B),Ne(B)}catch(w){console.error("Failed to load sessions:",w)}finally{M(!1)}},Ne=A=>{const w=R.current;if(!w)return;const B=w.getContext("2d"),ye=w.width=w.offsetWidth,fe=w.height=300;if(B.clearRect(0,0,ye,fe),A.length===0){B.fillStyle="#999",B.font="16px Nunito",B.textAlign="center",B.fillText("No data available",ye/2,fe/2);return}const ae=A.slice(0,20).reverse(),ue=50,Oe=ye-ue*2,Be=fe-ue*2,b=Oe/ae.length,D=1;B.strokeStyle="#E0E0E0",B.lineWidth=2,B.beginPath(),B.moveTo(ue,ue),B.lineTo(ue,fe-ue),B.lineTo(ye-ue,fe-ue),B.stroke(),B.fillStyle="#666",B.font="12px Nunito",B.textAlign="right";for(let Y=0;Y<=4;Y++){const L=fe-ue-Be*Y/4,$=(D*Y/4*100).toFixed(0);B.fillText($+"%",ue-10,L+4),B.strokeStyle="#F0F0F0",B.lineWidth=1,B.beginPath(),B.moveTo(ue,L),B.lineTo(ye-ue,L),B.stroke()}ae.forEach((Y,L)=>{const $=Y.focus_score/D*Be,r=ue+L*b+b*.1,_=fe-ue-$,U=b*.8,G=Y.focus_score;let F;G>=.8?F="#4A90E2":G>=.6?F="#5DADE2":G>=.4?F="#85C1E9":F="#AED6F1",B.fillStyle=F,B.fillRect(r,_,U,$),B.strokeStyle=F,B.lineWidth=1,B.strokeRect(r,_,U,$)}),B.textAlign="left",B.font="bold 14px Nunito",B.fillStyle="#4A90E2",B.fillText("Focus Score by Session",ue,30)};J.useEffect(()=>{He(m)},[m]),J.useEffect(()=>{if(!q.open)return;const A=document.body.style.overflow;document.body.style.overflow="hidden";const w=B=>{B.key==="Escape"&&de()};return window.addEventListener("keydown",w),()=>{document.body.style.overflow=A,window.removeEventListener("keydown",w)}},[q.open]);const xe=A=>{y(A)},Ce=async A=>{Z({open:!0,loading:!0,error:"",session:null});try{const w=await fetch(`/api/sessions/${A}`);if(!w.ok)throw new Error("Failed to load session details.");const B=await w.json();Z({open:!0,loading:!1,error:"",session:B})}catch(w){Z({open:!0,loading:!1,error:w.message||"Failed to load session details.",session:null})}},le=k(q.session);return c.jsxs("main",{id:"page-d",className:"page",children:[c.jsx("h1",{className:"page-title",children:"My Records"}),c.jsxs("div",{className:"records-controls",style:{display:"flex",justifyContent:"center",gap:"10px",marginBottom:"30px"},children:[c.jsx("button",{id:"filter-today",onClick:()=>xe("today"),style:{padding:"10px 30px",borderRadius:"8px",border:m==="today"?"none":"2px solid #4A90E2",background:m==="today"?"#4A90E2":"transparent",color:m==="today"?"white":"#4A90E2",fontSize:"14px",fontWeight:"500",cursor:"pointer",transition:"all 0.3s"},children:"Today"}),c.jsx("button",{id:"filter-week",onClick:()=>xe("week"),style:{padding:"10px 30px",borderRadius:"8px",border:m==="week"?"none":"2px solid #4A90E2",background:m==="week"?"#4A90E2":"transparent",color:m==="week"?"white":"#4A90E2",fontSize:"14px",fontWeight:"500",cursor:"pointer",transition:"all 0.3s"},children:"This Week"}),c.jsx("button",{id:"filter-month",onClick:()=>xe("month"),style:{padding:"10px 30px",borderRadius:"8px",border:m==="month"?"none":"2px solid #4A90E2",background:m==="month"?"#4A90E2":"transparent",color:m==="month"?"white":"#4A90E2",fontSize:"14px",fontWeight:"500",cursor:"pointer",transition:"all 0.3s"},children:"This Month"}),c.jsx("button",{id:"filter-all",onClick:()=>xe("all"),style:{padding:"10px 30px",borderRadius:"8px",border:m==="all"?"none":"2px solid #4A90E2",background:m==="all"?"#4A90E2":"transparent",color:m==="all"?"white":"#4A90E2",fontSize:"14px",fontWeight:"500",cursor:"pointer",transition:"all 0.3s"},children:"All Time"})]}),c.jsx("div",{className:"chart-container",style:{background:"white",padding:"20px",borderRadius:"10px",marginBottom:"30px",boxShadow:"0 2px 8px rgba(0,0,0,0.1)"},children:c.jsx("canvas",{ref:R,id:"focus-chart",style:{width:"100%",height:"300px"}})}),c.jsxs("div",{className:"sessions-list",style:{background:"white",padding:"20px",borderRadius:"10px",boxShadow:"0 2px 8px rgba(0,0,0,0.1)"},children:[c.jsx("h2",{style:{color:"#333",marginBottom:"20px",fontSize:"18px",fontWeight:"600"},children:"Recent Sessions"}),C?c.jsx("div",{style:{textAlign:"center",padding:"40px",color:"#999"},children:"Loading sessions..."}):p.length===0?c.jsx("div",{style:{textAlign:"center",padding:"40px",color:"#999"},children:"No sessions found for this period."}):c.jsxs("table",{id:"sessions-table",style:{width:"100%",borderCollapse:"collapse",borderRadius:"10px",overflow:"hidden"},children:[c.jsx("thead",{children:c.jsxs("tr",{style:{background:"#4A90E2"},children:[c.jsx("th",{style:{padding:"15px",textAlign:"left",color:"white",fontWeight:"600",fontSize:"14px"},children:"Date"}),c.jsx("th",{style:{padding:"15px",textAlign:"center",color:"white",fontWeight:"600",fontSize:"14px"},children:"Duration"}),c.jsx("th",{style:{padding:"15px",textAlign:"center",color:"white",fontWeight:"600",fontSize:"14px"},children:"Focus Score"}),c.jsx("th",{style:{padding:"15px",textAlign:"center",color:"white",fontWeight:"600",fontSize:"14px"},children:"Action"})]})}),c.jsx("tbody",{id:"sessions-tbody",children:p.map((A,w)=>c.jsxs("tr",{style:{background:w%2===0?"#f8f9fa":"white",borderBottom:"1px solid #e9ecef"},children:[c.jsx("td",{style:{padding:"15px",color:"#333",fontSize:"13px"},children:O(A.start_time)}),c.jsx("td",{style:{padding:"15px",textAlign:"center",color:"#333",fontSize:"13px"},children:x(A.duration_seconds)}),c.jsx("td",{style:{padding:"15px",textAlign:"center"},children:c.jsxs("span",{style:{color:A.focus_score>=.8?"#28a745":A.focus_score>=.6?"#ffc107":A.focus_score>=.4?"#fd7e14":"#dc3545",fontWeight:"600",fontSize:"13px"},children:[(A.focus_score*100).toFixed(1),"%"]})}),c.jsx("td",{style:{padding:"15px",textAlign:"center"},children:c.jsx("button",{onClick:()=>Ce(A.id),className:"btn-view",children:"View"})})]},A.id))})]})]}),q.open?c.jsx("div",{className:"modal-overlay",onClick:de,children:c.jsxs("div",{className:"modal-content records-detail-modal",onClick:A=>A.stopPropagation(),children:[c.jsxs("div",{className:"records-detail-header",children:[c.jsxs("div",{children:[c.jsx("div",{className:"records-detail-kicker",children:"Session Detail"}),c.jsx("h2",{children:q.session?H(q.session.start_time):"Loading session"}),c.jsx("p",{className:"records-detail-subtitle",children:"Review score, capture quality, and a condensed event timeline for this session."})]}),c.jsx("button",{type:"button",className:"records-detail-close",onClick:de,children:"Close"})]}),q.loading?c.jsx("div",{className:"records-detail-feedback",children:"Loading session details..."}):q.error?c.jsx("div",{className:"records-detail-feedback records-detail-feedback-error",children:q.error}):q.session&&le?c.jsxs(c.Fragment,{children:[c.jsxs("section",{className:"records-detail-summary",children:[c.jsxs("article",{className:`records-detail-stat ${Ee(q.session.focus_score)}`,children:[c.jsx("span",{className:"records-detail-stat-label",children:"Focus Score"}),c.jsxs("strong",{className:"records-detail-stat-value",children:[(q.session.focus_score*100).toFixed(1),"%"]})]}),c.jsxs("article",{className:"records-detail-stat",children:[c.jsx("span",{className:"records-detail-stat-label",children:"Duration"}),c.jsx("strong",{className:"records-detail-stat-value",children:x(q.session.duration_seconds)})]}),c.jsxs("article",{className:"records-detail-stat",children:[c.jsx("span",{className:"records-detail-stat-label",children:"Frames Analysed"}),c.jsx("strong",{className:"records-detail-stat-value",children:q.session.total_frames})]}),c.jsxs("article",{className:"records-detail-stat",children:[c.jsx("span",{className:"records-detail-stat-label",children:"Focused Frames"}),c.jsxs("strong",{className:"records-detail-stat-value",children:[(le.focusRatio*100).toFixed(1),"%"]})]})]}),c.jsxs("section",{className:"records-detail-grid",children:[c.jsxs("article",{className:"records-detail-card",children:[c.jsx("h3",{children:"Session Info"}),c.jsxs("div",{className:"records-detail-list",children:[c.jsxs("div",{className:"records-detail-item",children:[c.jsx("span",{className:"records-detail-item-label",children:"Started"}),c.jsx("span",{className:"records-detail-item-value",children:H(q.session.start_time)})]}),c.jsxs("div",{className:"records-detail-item",children:[c.jsx("span",{className:"records-detail-item-label",children:"Ended"}),c.jsx("span",{className:"records-detail-item-value",children:H(q.session.end_time)})]}),c.jsxs("div",{className:"records-detail-item",children:[c.jsx("span",{className:"records-detail-item-label",children:"Dominant Model"}),c.jsx("span",{className:"records-detail-item-value",children:le.dominantModel})]}),c.jsxs("div",{className:"records-detail-item",children:[c.jsx("span",{className:"records-detail-item-label",children:"Event Samples"}),c.jsx("span",{className:"records-detail-item-value",children:le.parsedEvents.length})]})]})]}),c.jsxs("article",{className:"records-detail-card",children:[c.jsx("h3",{children:"Signal Quality"}),c.jsxs("div",{className:"records-detail-list",children:[c.jsxs("div",{className:"records-detail-item",children:[c.jsx("span",{className:"records-detail-item-label",children:"Avg Confidence"}),c.jsx("span",{className:"records-detail-item-value",children:le.avgConfidence!==null?`${(le.avgConfidence*100).toFixed(1)}%`:"--"})]}),c.jsxs("div",{className:"records-detail-item",children:[c.jsx("span",{className:"records-detail-item-label",children:"Avg Face Score"}),c.jsx("span",{className:"records-detail-item-value",children:le.avgFaceScore!==null?le.avgFaceScore.toFixed(3):"--"})]}),c.jsxs("div",{className:"records-detail-item",children:[c.jsx("span",{className:"records-detail-item-label",children:"Avg Eye Score"}),c.jsx("span",{className:"records-detail-item-value",children:le.avgEyeScore!==null?le.avgEyeScore.toFixed(3):"--"})]}),c.jsxs("div",{className:"records-detail-item",children:[c.jsx("span",{className:"records-detail-item-label",children:"Avg MAR"}),c.jsx("span",{className:"records-detail-item-value",children:le.avgMar!==null?le.avgMar.toFixed(3):"--"})]})]})]})]}),c.jsxs("section",{className:"records-detail-card",children:[c.jsxs("div",{className:"records-detail-section-head",children:[c.jsx("h3",{children:"Focus Timeline"}),c.jsxs("span",{children:[le.parsedEvents.length," events condensed"]})]}),le.timeline.length>0?c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"records-detail-timeline",children:le.timeline.map((A,w)=>c.jsx("div",{className:`records-detail-segment ${A.tone}`,title:`${(A.focusRatio*100).toFixed(0)}% focused, ${A.count} events`},`${A.tone}-${w}`))}),c.jsxs("div",{className:"records-detail-legend",children:[c.jsxs("span",{children:[c.jsx("i",{className:"records-detail-dot focused"}),"Focused"]}),c.jsxs("span",{children:[c.jsx("i",{className:"records-detail-dot mixed"}),"Mixed"]}),c.jsxs("span",{children:[c.jsx("i",{className:"records-detail-dot distracted"}),"Distracted"]})]})]}):c.jsx("div",{className:"records-detail-empty",children:"No event timeline was recorded for this session."})]}),c.jsxs("section",{className:"records-detail-card",children:[c.jsxs("div",{className:"records-detail-section-head",children:[c.jsx("h3",{children:"Recent Events"}),c.jsxs("span",{children:["Last ",le.recentEvents.length," samples"]})]}),le.recentEvents.length>0?c.jsx("div",{className:"records-detail-events",children:le.recentEvents.map(A=>c.jsxs("article",{className:"records-detail-event",children:[c.jsx("div",{className:"records-detail-event-time",children:le.formatOffset(A.timestamp)}),c.jsxs("div",{className:"records-detail-event-copy",children:[c.jsx("div",{className:"records-detail-event-status",children:A.isFocused?"Focused":"Distracted"}),c.jsxs("div",{className:"records-detail-event-meta",children:[A.metadata?.model||"model n/a"," · confidence ",(A.confidence*100).toFixed(1),"%"]})]}),c.jsx("div",{className:`records-detail-event-badge ${A.isFocused?"focused":"distracted"}`,children:A.isFocused?"OK":"Alert"})]},A.id))}):c.jsx("div",{className:"records-detail-empty",children:"No individual event samples are available."})]})]}):null]})}):null]})}function E0(){const m=J.useRef(null),y=async()=>{try{const M=await fetch("/api/sessions?filter=all");if(!M.ok)throw new Error("Failed to fetch data");const q=await M.json(),Z=JSON.stringify(q,null,2);localStorage.setItem("focus_magic_backup",Z);const R=new Blob([Z],{type:"application/json"}),x=URL.createObjectURL(R),O=document.createElement("a");O.href=x,O.download=`focus-guard-backup-${new Date().toISOString().slice(0,10)}.json`,document.body.appendChild(O),O.click(),document.body.removeChild(O),URL.revokeObjectURL(x)}catch(M){console.error(M),alert("Export failed: "+M.message)}},p=()=>{m.current.click()},o=async M=>{const q=M.target.files[0];if(!q)return;const Z=new FileReader;Z.onload=async R=>{try{const x=R.target.result,O=JSON.parse(x);if(!Array.isArray(O))throw new Error("Invalid file format: Expected a list of sessions.");const H=await fetch("/api/import",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(O)});if(H.ok){const V=await H.json();alert(`Success! Imported ${V.count} sessions.`)}else alert("Import failed on server side.")}catch(x){alert("Error parsing file: "+x.message)}M.target.value=""},Z.readAsText(q)},C=async()=>{if(window.confirm("Are you sure? This will delete ALL your session history permanently."))try{(await fetch("/api/history",{method:"DELETE"})).ok?alert("All history has been cleared."):alert("Failed to clear history.")}catch(M){alert("Error: "+M.message)}};return c.jsxs("main",{id:"page-e",className:"page",children:[c.jsx("h1",{className:"page-title",children:"Customise"}),c.jsx("div",{className:"settings-container",children:c.jsxs("div",{className:"setting-group",children:[c.jsx("h2",{children:"Data Management"}),c.jsx("input",{type:"file",ref:m,style:{display:"none"},accept:".json",onChange:o}),c.jsxs("div",{style:{display:"flex",gap:"10px",justifyContent:"center",flexWrap:"wrap"},children:[c.jsx("button",{id:"export-data",className:"action-btn blue",onClick:y,style:{width:"30%",minWidth:"120px"},children:"Export Data"}),c.jsx("button",{id:"import-data",className:"action-btn yellow",onClick:p,style:{width:"30%",minWidth:"120px"},children:"Import Data"}),c.jsx("button",{id:"clear-history",className:"action-btn red",onClick:C,style:{width:"30%",minWidth:"120px"},children:"Clear History"})]})]})})]})}function T0(){const[m,y]=J.useState(""),p=async()=>{if(window.confirm("Delete all saved sessions? My Records and My Achievement will reset.")){y("");try{const o=await fetch("/api/history",{method:"DELETE"}),C=await o.json().catch(()=>({}));o.ok&&C.status==="success"?y("Session history cleared."):y(C.message||"Could not clear history.")}catch{y("Request failed.")}}};return c.jsxs("main",{id:"page-f",className:"page",children:[c.jsx("h1",{className:"page-title",children:"Help"}),c.jsxs("div",{className:"help-container",children:[c.jsxs("section",{className:"help-section",children:[c.jsx("h2",{children:"How to Use Focus Guard"}),c.jsxs("ol",{children:[c.jsx("li",{children:"Navigate to the Focus page from the menu"}),c.jsx("li",{children:"Allow camera access when prompted"}),c.jsx("li",{children:'Click the green "Start" button to begin monitoring'}),c.jsx("li",{children:"Position yourself in front of the camera"}),c.jsx("li",{children:"The system will track your focus in real-time using face mesh analysis"}),c.jsx("li",{children:"Use the model selector to switch between detection models (MLP, XGBoost, Geometric, Hybrid)"}),c.jsx("li",{children:`Click "Stop" when you're done to save the session`})]})]}),c.jsxs("section",{className:"help-section",children:[c.jsx("h2",{children:'What is "Focused"?'}),c.jsx("p",{children:"The system considers you focused when:"}),c.jsxs("ul",{children:[c.jsx("li",{children:"Your face is detected and visible in the camera frame"}),c.jsx("li",{children:"Your head is oriented toward the screen (low yaw/pitch deviation)"}),c.jsx("li",{children:"Your eyes are open and gaze is directed forward"}),c.jsx("li",{children:"You are not yawning"})]}),c.jsx("p",{children:"The system uses MediaPipe Face Mesh to extract 478 facial landmarks, then computes features like head pose, eye aspect ratio (EAR), gaze offset, PERCLOS, and blink rate to determine focus."})]}),c.jsxs("section",{className:"help-section",children:[c.jsx("h2",{children:"Available Models"}),c.jsxs("p",{children:[c.jsx("strong",{children:"MLP:"})," Neural network trained on extracted facial features. Good balance of speed and accuracy."]}),c.jsxs("p",{children:[c.jsx("strong",{children:"XGBoost:"})," Gradient-boosted tree model using 10 selected features. Strong on tabular data with fast inference."]}),c.jsxs("p",{children:[c.jsx("strong",{children:"Geometric:"})," Rule-based scoring using head pose and eye openness. No ML model needed, lightweight."]}),c.jsxs("p",{children:[c.jsx("strong",{children:"Hybrid:"})," Combines MLP predictions with geometric scoring for robust results."]})]}),c.jsxs("section",{className:"help-section",children:[c.jsx("h2",{children:"Adjusting Settings"}),c.jsxs("p",{children:[c.jsx("strong",{children:"Frame Rate:"})," Controls how many frames per second are sent for analysis. Recommended: 15-30 FPS. Minimum is 10 FPS to ensure temporal features (blink rate, PERCLOS) remain accurate."]}),c.jsxs("p",{children:[c.jsx("strong",{children:"Model Selection:"})," Switch models in real-time using the pill buttons above the timeline. Different models may perform better depending on your lighting and setup."]})]}),c.jsxs("section",{className:"help-section",children:[c.jsx("h2",{children:"Privacy & Data"}),c.jsxs("p",{children:["Video frames are processed in real-time on the server and are never stored. Only focus status metadata (timestamps, confidence scores) is saved to the session database. View past runs under ",c.jsx("strong",{children:"My Records"}),"; stats and badges live under ",c.jsx("strong",{children:"My Achievement"}),"."]}),c.jsxs("p",{style:{marginTop:"12px"},children:[c.jsx("button",{type:"button",onClick:p,style:{padding:"8px 16px",borderRadius:"8px",border:"1px solid #c44",background:"transparent",color:"#e88",cursor:"pointer",fontSize:"14px"},children:"Clear all session history"}),m&&c.jsx("span",{style:{marginLeft:"12px",color:"#aaa",fontSize:"14px"},children:m})]})]}),c.jsxs("section",{className:"help-section",children:[c.jsx("h2",{children:"FAQ"}),c.jsxs("details",{children:[c.jsx("summary",{children:"Why is my focus score low?"}),c.jsx("p",{children:"Ensure good lighting so the face mesh can detect your landmarks clearly. Face the camera directly and avoid large head movements. Try switching to a different model if one isn't working well for your setup."})]}),c.jsxs("details",{children:[c.jsx("summary",{children:"Can I use this without a camera?"}),c.jsx("p",{children:"No, camera access is required. The system relies on real-time face landmark detection to determine focus."})]}),c.jsxs("details",{children:[c.jsx("summary",{children:"Does this work on mobile?"}),c.jsx("p",{children:"Yes, it works on mobile browsers that support camera access and WebSocket connections. Performance depends on your device and network speed."})]}),c.jsxs("details",{children:[c.jsx("summary",{children:"Is my data private?"}),c.jsx("p",{children:"Yes. No video frames are stored. Processing happens in real-time and only metadata (focus/unfocused status, confidence, timestamps) is saved."})]}),c.jsxs("details",{children:[c.jsx("summary",{children:"Why does the face mesh lag behind my movements?"}),c.jsx("p",{children:"The face mesh overlay updates each time the server returns a detection result. The camera feed itself renders at 60fps locally. Any visible lag depends on network latency and server processing time."})]})]}),c.jsxs("section",{className:"help-section",children:[c.jsx("h2",{children:"Technical Info"}),c.jsxs("p",{children:[c.jsx("strong",{children:"Face Detection:"})," MediaPipe Face Mesh (478 landmarks)"]}),c.jsxs("p",{children:[c.jsx("strong",{children:"Feature Extraction:"})," Head pose (yaw/pitch/roll), EAR, MAR, gaze offset, PERCLOS, blink rate"]}),c.jsxs("p",{children:[c.jsx("strong",{children:"ML Models:"})," MLP (scikit-learn), XGBoost, Geometric, Hybrid"]}),c.jsxs("p",{children:[c.jsx("strong",{children:"Storage:"})," SQLite database"]}),c.jsxs("p",{children:[c.jsx("strong",{children:"Framework:"})," FastAPI + React (Vite) + WebSocket"]})]})]})]})}function _0(){const[m,y]=J.useState("home"),p=J.useRef(null),[o,C]=J.useState(!1),[M,q]=J.useState(null);J.useEffect(()=>{const R={onSessionStart:()=>{C(!0),q(null)},onSessionEnd:x=>{C(!1),x&&q(x)}};return p.current=new Je(R),()=>{p.current&&p.current.stopStreaming()}},[]);const Z=(R,x)=>c.jsx("button",{className:`menu-btn ${m===R?"active":""}`,onClick:()=>y(R),children:x});return c.jsxs("div",{className:"app-container",children:[c.jsx("nav",{id:"top-menu",children:c.jsxs("div",{className:"top-menu-links",children:[c.jsx("button",{type:"button",className:`menu-btn ${m==="home"?"active":""}`,onClick:()=>y("home"),children:"Home"}),c.jsx("div",{className:"separator","aria-hidden":!0}),c.jsxs("button",{className:`menu-btn ${m==="focus"?"active":""}`,onClick:()=>y("focus"),children:["Start Focus ",o&&c.jsx("span",{style:{marginLeft:"8px",color:"#00FF00"},children:"●"})]}),c.jsx("div",{className:"separator"}),Z("achievement","My Achievement"),c.jsx("div",{className:"separator"}),Z("records","My Records"),c.jsx("div",{className:"separator"}),Z("customise","Customise"),c.jsx("div",{className:"separator"}),Z("help","Help")]})}),m==="home"&&c.jsx(r0,{setActiveTab:y}),c.jsx(p0,{videoManager:p.current,sessionResult:M,setSessionResult:q,isActive:m==="focus"}),m==="achievement"&&c.jsx(b0,{}),m==="records"&&c.jsx(x0,{}),m==="customise"&&c.jsx(E0,{}),m==="help"&&c.jsx(T0,{})]})}s0.createRoot(document.getElementById("root")).render(c.jsx(J.StrictMode,{children:c.jsx(_0,{})}));