From df39a8dc0815d6d4a22d0cf183614555cf8c5f91 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 1 Jul 2026 03:45:34 +0000 Subject: [PATCH] feat: Agent Connect page + /api/agent/config endpoint - New AgentConnect.jsx page with MCP URL, token, setup instructions - Claude Desktop config snippet with copy button - Claude Code CLI command with copy button - Agent capabilities overview - Added to bottom nav bar (6th item, plug icon) - Backend /api/agent/config endpoint returns deployment-aware MCP details - Nav padding adjusted for 6 items - Frontend rebuilt with new page --- diligence/frontend/assets/index-DIoo6DtB.js | 68 ------ diligence/frontend/assets/index-De1TwOuS.js | 68 ++++++ ...{index-CRHpiAro.css => index-ciTnvXdZ.css} | 2 +- diligence/frontend/index.html | 4 +- diligence/main.py | 2 + diligence/routers/agent.py | 35 +++ frontend/src/App.jsx | 5 + frontend/src/api.js | 3 + frontend/src/index.css | 2 +- frontend/src/pages/AgentConnect.jsx | 208 ++++++++++++++++++ 10 files changed, 325 insertions(+), 72 deletions(-) delete mode 100644 diligence/frontend/assets/index-DIoo6DtB.js create mode 100644 diligence/frontend/assets/index-De1TwOuS.js rename diligence/frontend/assets/{index-CRHpiAro.css => index-ciTnvXdZ.css} (99%) create mode 100644 diligence/routers/agent.py create mode 100644 frontend/src/pages/AgentConnect.jsx diff --git a/diligence/frontend/assets/index-DIoo6DtB.js b/diligence/frontend/assets/index-DIoo6DtB.js deleted file mode 100644 index 4e5afaa..0000000 --- a/diligence/frontend/assets/index-DIoo6DtB.js +++ /dev/null @@ -1,68 +0,0 @@ -function Jf(o,c){for(var s=0;sd[p]})}}}return Object.freeze(Object.defineProperty(o,Symbol.toStringTag,{value:"Module"}))}(function(){const c=document.createElement("link").relList;if(c&&c.supports&&c.supports("modulepreload"))return;for(const p of document.querySelectorAll('link[rel="modulepreload"]'))d(p);new MutationObserver(p=>{for(const y of p)if(y.type==="childList")for(const g of y.addedNodes)g.tagName==="LINK"&&g.rel==="modulepreload"&&d(g)}).observe(document,{childList:!0,subtree:!0});function s(p){const y={};return p.integrity&&(y.integrity=p.integrity),p.referrerPolicy&&(y.referrerPolicy=p.referrerPolicy),p.crossOrigin==="use-credentials"?y.credentials="include":p.crossOrigin==="anonymous"?y.credentials="omit":y.credentials="same-origin",y}function d(p){if(p.ep)return;p.ep=!0;const y=s(p);fetch(p.href,y)}})();function Wc(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}var Zo={exports:{}},Lr={},ea={exports:{}},ce={};/** - * @license React - * react.production.min.js - * - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */var sc;function Yf(){if(sc)return ce;sc=1;var o=Symbol.for("react.element"),c=Symbol.for("react.portal"),s=Symbol.for("react.fragment"),d=Symbol.for("react.strict_mode"),p=Symbol.for("react.profiler"),y=Symbol.for("react.provider"),g=Symbol.for("react.context"),P=Symbol.for("react.forward_ref"),S=Symbol.for("react.suspense"),T=Symbol.for("react.memo"),z=Symbol.for("react.lazy"),v=Symbol.iterator;function L(w){return w===null||typeof w!="object"?null:(w=v&&w[v]||w["@@iterator"],typeof w=="function"?w:null)}var A={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},R=Object.assign,N={};function j(w,O,ae){this.props=w,this.context=O,this.refs=N,this.updater=ae||A}j.prototype.isReactComponent={},j.prototype.setState=function(w,O){if(typeof w!="object"&&typeof w!="function"&&w!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,w,O,"setState")},j.prototype.forceUpdate=function(w){this.updater.enqueueForceUpdate(this,w,"forceUpdate")};function F(){}F.prototype=j.prototype;function _(w,O,ae){this.props=w,this.context=O,this.refs=N,this.updater=ae||A}var W=_.prototype=new F;W.constructor=_,R(W,j.prototype),W.isPureReactComponent=!0;var B=Array.isArray,Z=Object.prototype.hasOwnProperty,fe={current:null},we={key:!0,ref:!0,__self:!0,__source:!0};function xe(w,O,ae){var ue,se={},b=null,ee=null;if(O!=null)for(ue in O.ref!==void 0&&(ee=O.ref),O.key!==void 0&&(b=""+O.key),O)Z.call(O,ue)&&!we.hasOwnProperty(ue)&&(se[ue]=O[ue]);var ie=arguments.length-2;if(ie===1)se.children=ae;else if(1>>1,O=H[w];if(0>>1;wp(se,V))bp(ee,se)?(H[w]=ee,H[b]=V,w=b):(H[w]=se,H[ue]=V,w=ue);else if(bp(ee,V))H[w]=ee,H[b]=V,w=b;else break e}}return I}function p(H,I){var V=H.sortIndex-I.sortIndex;return V!==0?V:H.id-I.id}if(typeof performance=="object"&&typeof performance.now=="function"){var y=performance;o.unstable_now=function(){return y.now()}}else{var g=Date,P=g.now();o.unstable_now=function(){return g.now()-P}}var S=[],T=[],z=1,v=null,L=3,A=!1,R=!1,N=!1,j=typeof setTimeout=="function"?setTimeout:null,F=typeof clearTimeout=="function"?clearTimeout:null,_=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function W(H){for(var I=s(T);I!==null;){if(I.callback===null)d(T);else if(I.startTime<=H)d(T),I.sortIndex=I.expirationTime,c(S,I);else break;I=s(T)}}function B(H){if(N=!1,W(H),!R)if(s(S)!==null)R=!0,We(Z);else{var I=s(T);I!==null&&Se(B,I.startTime-H)}}function Z(H,I){R=!1,N&&(N=!1,F(xe),xe=-1),A=!0;var V=L;try{for(W(I),v=s(S);v!==null&&(!(v.expirationTime>I)||H&&!pe());){var w=v.callback;if(typeof w=="function"){v.callback=null,L=v.priorityLevel;var O=w(v.expirationTime<=I);I=o.unstable_now(),typeof O=="function"?v.callback=O:v===s(S)&&d(S),W(I)}else d(S);v=s(S)}if(v!==null)var ae=!0;else{var ue=s(T);ue!==null&&Se(B,ue.startTime-I),ae=!1}return ae}finally{v=null,L=V,A=!1}}var fe=!1,we=null,xe=-1,re=5,oe=-1;function pe(){return!(o.unstable_now()-oeH||125w?(H.sortIndex=V,c(T,H),s(S)===null&&H===s(T)&&(N?(F(xe),xe=-1):N=!0,Se(B,V-w))):(H.sortIndex=O,c(S,H),R||A||(R=!0,We(Z))),H},o.unstable_shouldYield=pe,o.unstable_wrapCallback=function(H){var I=L;return function(){var V=L;L=I;try{return H.apply(this,arguments)}finally{L=V}}}})(ra)),ra}var pc;function ep(){return pc||(pc=1,na.exports=Zf()),na.exports}/** - * @license React - * react-dom.production.min.js - * - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */var mc;function tp(){if(mc)return lt;mc=1;var o=ua(),c=ep();function s(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,n=1;n"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),S=Object.prototype.hasOwnProperty,T=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,z={},v={};function L(e){return S.call(v,e)?!0:S.call(z,e)?!1:T.test(e)?v[e]=!0:(z[e]=!0,!1)}function A(e,t,n,r){if(n!==null&&n.type===0)return!1;switch(typeof t){case"function":case"symbol":return!0;case"boolean":return r?!1:n!==null?!n.acceptsBooleans:(e=e.toLowerCase().slice(0,5),e!=="data-"&&e!=="aria-");default:return!1}}function R(e,t,n,r){if(t===null||typeof t>"u"||A(e,t,n,r))return!0;if(r)return!1;if(n!==null)switch(n.type){case 3:return!t;case 4:return t===!1;case 5:return isNaN(t);case 6:return isNaN(t)||1>t}return!1}function N(e,t,n,r,i,a,u){this.acceptsBooleans=t===2||t===3||t===4,this.attributeName=r,this.attributeNamespace=i,this.mustUseProperty=n,this.propertyName=e,this.type=t,this.sanitizeURL=a,this.removeEmptyString=u}var j={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){j[e]=new N(e,0,!1,e,null,!1,!1)}),[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];j[t]=new N(t,1,!1,e[1],null,!1,!1)}),["contentEditable","draggable","spellCheck","value"].forEach(function(e){j[e]=new N(e,2,!1,e.toLowerCase(),null,!1,!1)}),["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){j[e]=new N(e,2,!1,e,null,!1,!1)}),"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(e){j[e]=new N(e,3,!1,e.toLowerCase(),null,!1,!1)}),["checked","multiple","muted","selected"].forEach(function(e){j[e]=new N(e,3,!0,e,null,!1,!1)}),["capture","download"].forEach(function(e){j[e]=new N(e,4,!1,e,null,!1,!1)}),["cols","rows","size","span"].forEach(function(e){j[e]=new N(e,6,!1,e,null,!1,!1)}),["rowSpan","start"].forEach(function(e){j[e]=new N(e,5,!1,e.toLowerCase(),null,!1,!1)});var F=/[\-:]([a-z])/g;function _(e){return e[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(e){var t=e.replace(F,_);j[t]=new N(t,1,!1,e,null,!1,!1)}),"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var t=e.replace(F,_);j[t]=new N(t,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)}),["xml:base","xml:lang","xml:space"].forEach(function(e){var t=e.replace(F,_);j[t]=new N(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)}),["tabIndex","crossOrigin"].forEach(function(e){j[e]=new N(e,1,!1,e.toLowerCase(),null,!1,!1)}),j.xlinkHref=new N("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1),["src","href","action","formAction"].forEach(function(e){j[e]=new N(e,1,!1,e.toLowerCase(),null,!0,!0)});function W(e,t,n,r){var i=j.hasOwnProperty(t)?j[t]:null;(i!==null?i.type!==0:r||!(2f||i[u]!==a[f]){var h=` -`+i[u].replace(" at new "," at ");return e.displayName&&h.includes("")&&(h=h.replace("",e.displayName)),h}while(1<=u&&0<=f);break}}}finally{ae=!1,Error.prepareStackTrace=n}return(e=e?e.displayName||e.name:"")?O(e):""}function se(e){switch(e.tag){case 5:return O(e.type);case 16:return O("Lazy");case 13:return O("Suspense");case 19:return O("SuspenseList");case 0:case 2:case 15:return e=ue(e.type,!1),e;case 11:return e=ue(e.type.render,!1),e;case 1:return e=ue(e.type,!0),e;default:return""}}function b(e){if(e==null)return null;if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case we:return"Fragment";case fe:return"Portal";case re:return"Profiler";case xe:return"StrictMode";case ve:return"Suspense";case Te:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case pe:return(e.displayName||"Context")+".Consumer";case oe:return(e._context.displayName||"Context")+".Provider";case Ne:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case Me:return t=e.displayName||null,t!==null?t:b(e.type)||"Memo";case We:t=e._payload,e=e._init;try{return b(e(t))}catch{}}return null}function ee(e){var t=e.type;switch(e.tag){case 24:return"Cache";case 9:return(t.displayName||"Context")+".Consumer";case 10:return(t._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return e=t.render,e=e.displayName||e.name||"",t.displayName||(e!==""?"ForwardRef("+e+")":"ForwardRef");case 7:return"Fragment";case 5:return t;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return b(t);case 8:return t===xe?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t}return null}function ie(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function de(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function ye(e){var t=de(e)?"checked":"value",n=Object.getOwnPropertyDescriptor(e.constructor.prototype,t),r=""+e[t];if(!e.hasOwnProperty(t)&&typeof n<"u"&&typeof n.get=="function"&&typeof n.set=="function"){var i=n.get,a=n.set;return Object.defineProperty(e,t,{configurable:!0,get:function(){return i.call(this)},set:function(u){r=""+u,a.call(this,u)}}),Object.defineProperty(e,t,{enumerable:n.enumerable}),{getValue:function(){return r},setValue:function(u){r=""+u},stopTracking:function(){e._valueTracker=null,delete e[t]}}}}function Or(e){e._valueTracker||(e._valueTracker=ye(e))}function ma(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r="";return e&&(r=de(e)?e.checked?"true":"false":e.value),e=r,e!==n?(t.setValue(e),!0):!1}function Mr(e){if(e=e||(typeof document<"u"?document:void 0),typeof e>"u")return null;try{return e.activeElement||e.body}catch{return e.body}}function ii(e,t){var n=t.checked;return V({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??e._wrapperState.initialChecked})}function ha(e,t){var n=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;n=ie(t.value!=null?t.value:n),e._wrapperState={initialChecked:r,initialValue:n,controlled:t.type==="checkbox"||t.type==="radio"?t.checked!=null:t.value!=null}}function ga(e,t){t=t.checked,t!=null&&W(e,"checked",t,!1)}function oi(e,t){ga(e,t);var n=ie(t.value),r=t.type;if(n!=null)r==="number"?(n===0&&e.value===""||e.value!=n)&&(e.value=""+n):e.value!==""+n&&(e.value=""+n);else if(r==="submit"||r==="reset"){e.removeAttribute("value");return}t.hasOwnProperty("value")?ai(e,t.type,n):t.hasOwnProperty("defaultValue")&&ai(e,t.type,ie(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function va(e,t,n){if(t.hasOwnProperty("value")||t.hasOwnProperty("defaultValue")){var r=t.type;if(!(r!=="submit"&&r!=="reset"||t.value!==void 0&&t.value!==null))return;t=""+e._wrapperState.initialValue,n||t===e.value||(e.value=t),e.defaultValue=t}n=e.name,n!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,n!==""&&(e.name=n)}function ai(e,t,n){(t!=="number"||Mr(e.ownerDocument)!==e)&&(n==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+n&&(e.defaultValue=""+n))}var Jn=Array.isArray;function Sn(e,t,n,r){if(e=e.options,t){t={};for(var i=0;i"+t.valueOf().toString()+"",t=Dr.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function Yn(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var Gn={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},Xc=["Webkit","ms","Moz","O"];Object.keys(Gn).forEach(function(e){Xc.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),Gn[t]=Gn[e]})});function ka(e,t,n){return t==null||typeof t=="boolean"||t===""?"":n||typeof t!="number"||t===0||Gn.hasOwnProperty(e)&&Gn[e]?(""+t).trim():t+"px"}function _a(e,t){e=e.style;for(var n in t)if(t.hasOwnProperty(n)){var r=n.indexOf("--")===0,i=ka(n,t[n],r);n==="float"&&(n="cssFloat"),r?e.setProperty(n,i):e[n]=i}}var qc=V({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function ci(e,t){if(t){if(qc[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(s(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(s(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(s(61))}if(t.style!=null&&typeof t.style!="object")throw Error(s(62))}}function di(e,t){if(e.indexOf("-")===-1)return typeof t.is=="string";switch(e){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var fi=null;function pi(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var mi=null,wn=null,jn=null;function Ca(e){if(e=yr(e)){if(typeof mi!="function")throw Error(s(280));var t=e.stateNode;t&&(t=ul(t),mi(e.stateNode,e.type,t))}}function Na(e){wn?jn?jn.push(e):jn=[e]:wn=e}function Ea(){if(wn){var e=wn,t=jn;if(jn=wn=null,Ca(e),t)for(e=0;e>>=0,e===0?32:31-(ud(e)/cd|0)|0}var Hr=64,Qr=4194304;function er(e){switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return e&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return e&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return e}}function Kr(e,t){var n=e.pendingLanes;if(n===0)return 0;var r=0,i=e.suspendedLanes,a=e.pingedLanes,u=n&268435455;if(u!==0){var f=u&~i;f!==0?r=er(f):(a&=u,a!==0&&(r=er(a)))}else u=n&~i,u!==0?r=er(u):a!==0&&(r=er(a));if(r===0)return 0;if(t!==0&&t!==r&&(t&i)===0&&(i=r&-r,a=t&-t,i>=a||i===16&&(a&4194240)!==0))return t;if((r&4)!==0&&(r|=n&16),t=e.entangledLanes,t!==0)for(e=e.entanglements,t&=r;0n;n++)t.push(e);return t}function tr(e,t,n){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-ht(t),e[t]=n}function md(e,t){var n=e.pendingLanes&~t;e.pendingLanes=t,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=t,e.mutableReadLanes&=t,e.entangledLanes&=t,t=e.entanglements;var r=e.eventTimes;for(e=e.expirationTimes;0=ur),ts=" ",ns=!1;function rs(e,t){switch(e){case"keyup":return $d.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function ls(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Cn=!1;function Vd(e,t){switch(e){case"compositionend":return ls(t);case"keypress":return t.which!==32?null:(ns=!0,ts);case"textInput":return e=t.data,e===ts&&ns?null:e;default:return null}}function Hd(e,t){if(Cn)return e==="compositionend"||!Ri&&rs(e,t)?(e=Ya(),qr=Ni=$t=null,Cn=!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:n,offset:t-e};e=r}e:{for(;n;){if(n.nextSibling){n=n.nextSibling;break e}n=n.parentNode}n=void 0}n=ds(n)}}function ps(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?ps(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function ms(){for(var e=window,t=Mr();t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href=="string"}catch{n=!1}if(n)e=t.contentWindow;else break;t=Mr(e.document)}return t}function Fi(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")}function ef(e){var t=ms(),n=e.focusedElem,r=e.selectionRange;if(t!==n&&n&&n.ownerDocument&&ps(n.ownerDocument.documentElement,n)){if(r!==null&&Fi(n)){if(t=r.start,e=r.end,e===void 0&&(e=t),"selectionStart"in n)n.selectionStart=t,n.selectionEnd=Math.min(e,n.value.length);else if(e=(t=n.ownerDocument||document)&&t.defaultView||window,e.getSelection){e=e.getSelection();var i=n.textContent.length,a=Math.min(r.start,i);r=r.end===void 0?a:Math.min(r.end,i),!e.extend&&a>r&&(i=r,r=a,a=i),i=fs(n,a);var u=fs(n,r);i&&u&&(e.rangeCount!==1||e.anchorNode!==i.node||e.anchorOffset!==i.offset||e.focusNode!==u.node||e.focusOffset!==u.offset)&&(t=t.createRange(),t.setStart(i.node,i.offset),e.removeAllRanges(),a>r?(e.addRange(t),e.extend(u.node,u.offset)):(t.setEnd(u.node,u.offset),e.addRange(t)))}}for(t=[],e=n;e=e.parentNode;)e.nodeType===1&&t.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof n.focus=="function"&&n.focus(),n=0;n=document.documentMode,Nn=null,Wi=null,pr=null,Bi=!1;function hs(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;Bi||Nn==null||Nn!==Mr(r)||(r=Nn,"selectionStart"in r&&Fi(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),pr&&fr(pr,r)||(pr=r,r=ol(Wi,"onSelect"),0bn||(e.current=Yi[bn],Yi[bn]=null,bn--)}function je(e,t){bn++,Yi[bn]=e.current,e.current=t}var Qt={},Qe=Ht(Qt),Ze=Ht(!1),sn=Qt;function Rn(e,t){var n=e.type.contextTypes;if(!n)return Qt;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===t)return r.__reactInternalMemoizedMaskedChildContext;var i={},a;for(a in n)i[a]=t[a];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=t,e.__reactInternalMemoizedMaskedChildContext=i),i}function et(e){return e=e.childContextTypes,e!=null}function cl(){_e(Ze),_e(Qe)}function Ts(e,t,n){if(Qe.current!==Qt)throw Error(s(168));je(Qe,t),je(Ze,n)}function bs(e,t,n){var r=e.stateNode;if(t=t.childContextTypes,typeof r.getChildContext!="function")return n;r=r.getChildContext();for(var i in r)if(!(i in t))throw Error(s(108,ee(e)||"Unknown",i));return V({},n,r)}function dl(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||Qt,sn=Qe.current,je(Qe,e),je(Ze,Ze.current),!0}function Rs(e,t,n){var r=e.stateNode;if(!r)throw Error(s(169));n?(e=bs(e,t,sn),r.__reactInternalMemoizedMergedChildContext=e,_e(Ze),_e(Qe),je(Qe,e)):_e(Ze),je(Ze,n)}var Pt=null,fl=!1,Gi=!1;function Ls(e){Pt===null?Pt=[e]:Pt.push(e)}function pf(e){fl=!0,Ls(e)}function Kt(){if(!Gi&&Pt!==null){Gi=!0;var e=0,t=ge;try{var n=Pt;for(ge=1;e>=u,i-=u,zt=1<<32-ht(t)+i|n<le?($e=ne,ne=null):$e=ne.sibling;var he=M(k,ne,C[le],U);if(he===null){ne===null&&(ne=$e);break}e&&ne&&he.alternate===null&&t(k,ne),x=a(he,x,le),te===null?q=he:te.sibling=he,te=he,ne=$e}if(le===C.length)return n(k,ne),Ce&&cn(k,le),q;if(ne===null){for(;lele?($e=ne,ne=null):$e=ne.sibling;var nn=M(k,ne,he.value,U);if(nn===null){ne===null&&(ne=$e);break}e&&ne&&nn.alternate===null&&t(k,ne),x=a(nn,x,le),te===null?q=nn:te.sibling=nn,te=nn,ne=$e}if(he.done)return n(k,ne),Ce&&cn(k,le),q;if(ne===null){for(;!he.done;le++,he=C.next())he=$(k,he.value,U),he!==null&&(x=a(he,x,le),te===null?q=he:te.sibling=he,te=he);return Ce&&cn(k,le),q}for(ne=r(k,ne);!he.done;le++,he=C.next())he=Q(ne,k,le,he.value,U),he!==null&&(e&&he.alternate!==null&&ne.delete(he.key===null?le:he.key),x=a(he,x,le),te===null?q=he:te.sibling=he,te=he);return e&&ne.forEach(function(Kf){return t(k,Kf)}),Ce&&cn(k,le),q}function Le(k,x,C,U){if(typeof C=="object"&&C!==null&&C.type===we&&C.key===null&&(C=C.props.children),typeof C=="object"&&C!==null){switch(C.$$typeof){case Z:e:{for(var q=C.key,te=x;te!==null;){if(te.key===q){if(q=C.type,q===we){if(te.tag===7){n(k,te.sibling),x=i(te,C.props.children),x.return=k,k=x;break e}}else if(te.elementType===q||typeof q=="object"&&q!==null&&q.$$typeof===We&&Ms(q)===te.type){n(k,te.sibling),x=i(te,C.props),x.ref=xr(k,te,C),x.return=k,k=x;break e}n(k,te);break}else t(k,te);te=te.sibling}C.type===we?(x=yn(C.props.children,k.mode,U,C.key),x.return=k,k=x):(U=Dl(C.type,C.key,C.props,null,k.mode,U),U.ref=xr(k,x,C),U.return=k,k=U)}return u(k);case fe:e:{for(te=C.key;x!==null;){if(x.key===te)if(x.tag===4&&x.stateNode.containerInfo===C.containerInfo&&x.stateNode.implementation===C.implementation){n(k,x.sibling),x=i(x,C.children||[]),x.return=k,k=x;break e}else{n(k,x);break}else t(k,x);x=x.sibling}x=Jo(C,k.mode,U),x.return=k,k=x}return u(k);case We:return te=C._init,Le(k,x,te(C._payload),U)}if(Jn(C))return G(k,x,C,U);if(I(C))return X(k,x,C,U);gl(k,C)}return typeof C=="string"&&C!==""||typeof C=="number"?(C=""+C,x!==null&&x.tag===6?(n(k,x.sibling),x=i(x,C),x.return=k,k=x):(n(k,x),x=Ko(C,k.mode,U),x.return=k,k=x),u(k)):n(k,x)}return Le}var Wn=Ds(!0),As=Ds(!1),vl=Ht(null),yl=null,Bn=null,no=null;function ro(){no=Bn=yl=null}function lo(e){var t=vl.current;_e(vl),e._currentValue=t}function io(e,t,n){for(;e!==null;){var r=e.alternate;if((e.childLanes&t)!==t?(e.childLanes|=t,r!==null&&(r.childLanes|=t)):r!==null&&(r.childLanes&t)!==t&&(r.childLanes|=t),e===n)break;e=e.return}}function On(e,t){yl=e,no=Bn=null,e=e.dependencies,e!==null&&e.firstContext!==null&&((e.lanes&t)!==0&&(tt=!0),e.firstContext=null)}function dt(e){var t=e._currentValue;if(no!==e)if(e={context:e,memoizedValue:t,next:null},Bn===null){if(yl===null)throw Error(s(308));Bn=e,yl.dependencies={lanes:0,firstContext:e}}else Bn=Bn.next=e;return t}var dn=null;function oo(e){dn===null?dn=[e]:dn.push(e)}function $s(e,t,n,r){var i=t.interleaved;return i===null?(n.next=n,oo(t)):(n.next=i.next,i.next=n),t.interleaved=n,bt(e,r)}function bt(e,t){e.lanes|=t;var n=e.alternate;for(n!==null&&(n.lanes|=t),n=e,e=e.return;e!==null;)e.childLanes|=t,n=e.alternate,n!==null&&(n.childLanes|=t),n=e,e=e.return;return n.tag===3?n.stateNode:null}var Jt=!1;function ao(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function Us(e,t){e=e.updateQueue,t.updateQueue===e&&(t.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,effects:e.effects})}function Rt(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function Yt(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,(me&2)!==0){var i=r.pending;return i===null?t.next=t:(t.next=i.next,i.next=t),r.pending=t,bt(e,n)}return i=r.interleaved,i===null?(t.next=t,oo(r)):(t.next=i.next,i.next=t),r.interleaved=t,bt(e,n)}function xl(e,t,n){if(t=t.updateQueue,t!==null&&(t=t.shared,(n&4194240)!==0)){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,wi(e,n)}}function Vs(e,t){var n=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,n===r)){var i=null,a=null;if(n=n.firstBaseUpdate,n!==null){do{var u={eventTime:n.eventTime,lane:n.lane,tag:n.tag,payload:n.payload,callback:n.callback,next:null};a===null?i=a=u:a=a.next=u,n=n.next}while(n!==null);a===null?i=a=t:a=a.next=t}else i=a=t;n={baseState:r.baseState,firstBaseUpdate:i,lastBaseUpdate:a,shared:r.shared,effects:r.effects},e.updateQueue=n;return}e=n.lastBaseUpdate,e===null?n.firstBaseUpdate=t:e.next=t,n.lastBaseUpdate=t}function Sl(e,t,n,r){var i=e.updateQueue;Jt=!1;var a=i.firstBaseUpdate,u=i.lastBaseUpdate,f=i.shared.pending;if(f!==null){i.shared.pending=null;var h=f,E=h.next;h.next=null,u===null?a=E:u.next=E,u=h;var D=e.alternate;D!==null&&(D=D.updateQueue,f=D.lastBaseUpdate,f!==u&&(f===null?D.firstBaseUpdate=E:f.next=E,D.lastBaseUpdate=h))}if(a!==null){var $=i.baseState;u=0,D=E=h=null,f=a;do{var M=f.lane,Q=f.eventTime;if((r&M)===M){D!==null&&(D=D.next={eventTime:Q,lane:0,tag:f.tag,payload:f.payload,callback:f.callback,next:null});e:{var G=e,X=f;switch(M=t,Q=n,X.tag){case 1:if(G=X.payload,typeof G=="function"){$=G.call(Q,$,M);break e}$=G;break e;case 3:G.flags=G.flags&-65537|128;case 0:if(G=X.payload,M=typeof G=="function"?G.call(Q,$,M):G,M==null)break e;$=V({},$,M);break e;case 2:Jt=!0}}f.callback!==null&&f.lane!==0&&(e.flags|=64,M=i.effects,M===null?i.effects=[f]:M.push(f))}else Q={eventTime:Q,lane:M,tag:f.tag,payload:f.payload,callback:f.callback,next:null},D===null?(E=D=Q,h=$):D=D.next=Q,u|=M;if(f=f.next,f===null){if(f=i.shared.pending,f===null)break;M=f,f=M.next,M.next=null,i.lastBaseUpdate=M,i.shared.pending=null}}while(!0);if(D===null&&(h=$),i.baseState=h,i.firstBaseUpdate=E,i.lastBaseUpdate=D,t=i.shared.interleaved,t!==null){i=t;do u|=i.lane,i=i.next;while(i!==t)}else a===null&&(i.shared.lanes=0);mn|=u,e.lanes=u,e.memoizedState=$}}function Hs(e,t,n){if(e=t.effects,t.effects=null,e!==null)for(t=0;tn?n:4,e(!0);var r=po.transition;po.transition={};try{e(!1),t()}finally{ge=n,po.transition=r}}function cu(){return ft().memoizedState}function vf(e,t,n){var r=Zt(e);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},du(e))fu(t,n);else if(n=$s(e,t,n,r),n!==null){var i=qe();wt(n,e,r,i),pu(n,t,r)}}function yf(e,t,n){var r=Zt(e),i={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(du(e))fu(t,i);else{var a=e.alternate;if(e.lanes===0&&(a===null||a.lanes===0)&&(a=t.lastRenderedReducer,a!==null))try{var u=t.lastRenderedState,f=a(u,n);if(i.hasEagerState=!0,i.eagerState=f,gt(f,u)){var h=t.interleaved;h===null?(i.next=i,oo(t)):(i.next=h.next,h.next=i),t.interleaved=i;return}}catch{}finally{}n=$s(e,t,i,r),n!==null&&(i=qe(),wt(n,e,r,i),pu(n,t,r))}}function du(e){var t=e.alternate;return e===Pe||t!==null&&t===Pe}function fu(e,t){kr=kl=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function pu(e,t,n){if((n&4194240)!==0){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,wi(e,n)}}var Nl={readContext:dt,useCallback:Ke,useContext:Ke,useEffect:Ke,useImperativeHandle:Ke,useInsertionEffect:Ke,useLayoutEffect:Ke,useMemo:Ke,useReducer:Ke,useRef:Ke,useState:Ke,useDebugValue:Ke,useDeferredValue:Ke,useTransition:Ke,useMutableSource:Ke,useSyncExternalStore:Ke,useId:Ke,unstable_isNewReconciler:!1},xf={readContext:dt,useCallback:function(e,t){return Ct().memoizedState=[e,t===void 0?null:t],e},useContext:dt,useEffect:nu,useImperativeHandle:function(e,t,n){return n=n!=null?n.concat([e]):null,_l(4194308,4,iu.bind(null,t,e),n)},useLayoutEffect:function(e,t){return _l(4194308,4,e,t)},useInsertionEffect:function(e,t){return _l(4,2,e,t)},useMemo:function(e,t){var n=Ct();return t=t===void 0?null:t,e=e(),n.memoizedState=[e,t],e},useReducer:function(e,t,n){var r=Ct();return t=n!==void 0?n(t):t,r.memoizedState=r.baseState=t,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:t},r.queue=e,e=e.dispatch=vf.bind(null,Pe,e),[r.memoizedState,e]},useRef:function(e){var t=Ct();return e={current:e},t.memoizedState=e},useState:eu,useDebugValue:So,useDeferredValue:function(e){return Ct().memoizedState=e},useTransition:function(){var e=eu(!1),t=e[0];return e=gf.bind(null,e[1]),Ct().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,n){var r=Pe,i=Ct();if(Ce){if(n===void 0)throw Error(s(407));n=n()}else{if(n=t(),Ae===null)throw Error(s(349));(pn&30)!==0||Ys(r,t,n)}i.memoizedState=n;var a={value:n,getSnapshot:t};return i.queue=a,nu(Xs.bind(null,r,a,e),[e]),r.flags|=2048,Nr(9,Gs.bind(null,r,a,n,t),void 0,null),n},useId:function(){var e=Ct(),t=Ae.identifierPrefix;if(Ce){var n=Tt,r=zt;n=(r&~(1<<32-ht(r)-1)).toString(32)+n,t=":"+t+"R"+n,n=_r++,0<\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=u.createElement(n,{is:r.is}):(e=u.createElement(n),n==="select"&&(u=e,r.multiple?u.multiple=!0:r.size&&(u.size=r.size))):e=u.createElementNS(e,n),e[kt]=t,e[vr]=r,Lu(e,t,!1,!1),t.stateNode=e;e:{switch(u=di(n,r),n){case"dialog":ke("cancel",e),ke("close",e),i=r;break;case"iframe":case"object":case"embed":ke("load",e),i=r;break;case"video":case"audio":for(i=0;iUn&&(t.flags|=128,r=!0,Er(a,!1),t.lanes=4194304)}else{if(!r)if(e=wl(u),e!==null){if(t.flags|=128,r=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),Er(a,!0),a.tail===null&&a.tailMode==="hidden"&&!u.alternate&&!Ce)return Je(t),null}else 2*Re()-a.renderingStartTime>Un&&n!==1073741824&&(t.flags|=128,r=!0,Er(a,!1),t.lanes=4194304);a.isBackwards?(u.sibling=t.child,t.child=u):(n=a.last,n!==null?n.sibling=u:t.child=u,a.last=u)}return a.tail!==null?(t=a.tail,a.rendering=t,a.tail=t.sibling,a.renderingStartTime=Re(),t.sibling=null,n=Ee.current,je(Ee,r?n&1|2:n&1),t):(Je(t),null);case 22:case 23:return Vo(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&(t.mode&1)!==0?(st&1073741824)!==0&&(Je(t),t.subtreeFlags&6&&(t.flags|=8192)):Je(t),null;case 24:return null;case 25:return null}throw Error(s(156,t.tag))}function Ef(e,t){switch(qi(t),t.tag){case 1:return et(t.type)&&cl(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return Mn(),_e(Ze),_e(Qe),fo(),e=t.flags,(e&65536)!==0&&(e&128)===0?(t.flags=e&-65537|128,t):null;case 5:return uo(t),null;case 13:if(_e(Ee),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(s(340));Fn()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return _e(Ee),null;case 4:return Mn(),null;case 10:return lo(t.type._context),null;case 22:case 23:return Vo(),null;case 24:return null;default:return null}}var Tl=!1,Ye=!1,Pf=typeof WeakSet=="function"?WeakSet:Set,Y=null;function An(e,t){var n=e.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){be(e,t,r)}else n.current=null}function Ro(e,t,n){try{n()}catch(r){be(e,t,r)}}var Wu=!1;function zf(e,t){if(Ui=Gr,e=ms(),Fi(e)){if("selectionStart"in e)var n={start:e.selectionStart,end:e.selectionEnd};else e:{n=(n=e.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var i=r.anchorOffset,a=r.focusNode;r=r.focusOffset;try{n.nodeType,a.nodeType}catch{n=null;break e}var u=0,f=-1,h=-1,E=0,D=0,$=e,M=null;t:for(;;){for(var Q;$!==n||i!==0&&$.nodeType!==3||(f=u+i),$!==a||r!==0&&$.nodeType!==3||(h=u+r),$.nodeType===3&&(u+=$.nodeValue.length),(Q=$.firstChild)!==null;)M=$,$=Q;for(;;){if($===e)break t;if(M===n&&++E===i&&(f=u),M===a&&++D===r&&(h=u),(Q=$.nextSibling)!==null)break;$=M,M=$.parentNode}$=Q}n=f===-1||h===-1?null:{start:f,end:h}}else n=null}n=n||{start:0,end:0}}else n=null;for(Vi={focusedElem:e,selectionRange:n},Gr=!1,Y=t;Y!==null;)if(t=Y,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,Y=e;else for(;Y!==null;){t=Y;try{var G=t.alternate;if((t.flags&1024)!==0)switch(t.tag){case 0:case 11:case 15:break;case 1:if(G!==null){var X=G.memoizedProps,Le=G.memoizedState,k=t.stateNode,x=k.getSnapshotBeforeUpdate(t.elementType===t.type?X:yt(t.type,X),Le);k.__reactInternalSnapshotBeforeUpdate=x}break;case 3:var C=t.stateNode.containerInfo;C.nodeType===1?C.textContent="":C.nodeType===9&&C.documentElement&&C.removeChild(C.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(s(163))}}catch(U){be(t,t.return,U)}if(e=t.sibling,e!==null){e.return=t.return,Y=e;break}Y=t.return}return G=Wu,Wu=!1,G}function Pr(e,t,n){var r=t.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var i=r=r.next;do{if((i.tag&e)===e){var a=i.destroy;i.destroy=void 0,a!==void 0&&Ro(t,n,a)}i=i.next}while(i!==r)}}function bl(e,t){if(t=t.updateQueue,t=t!==null?t.lastEffect:null,t!==null){var n=t=t.next;do{if((n.tag&e)===e){var r=n.create;n.destroy=r()}n=n.next}while(n!==t)}}function Lo(e){var t=e.ref;if(t!==null){var n=e.stateNode;switch(e.tag){case 5:e=n;break;default:e=n}typeof t=="function"?t(e):t.current=e}}function Bu(e){var t=e.alternate;t!==null&&(e.alternate=null,Bu(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[kt],delete t[vr],delete t[Ji],delete t[df],delete t[ff])),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}function Ou(e){return e.tag===5||e.tag===3||e.tag===4}function Mu(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||Ou(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function Io(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.nodeType===8?n.parentNode.insertBefore(e,t):n.insertBefore(e,t):(n.nodeType===8?(t=n.parentNode,t.insertBefore(e,n)):(t=n,t.appendChild(e)),n=n._reactRootContainer,n!=null||t.onclick!==null||(t.onclick=sl));else if(r!==4&&(e=e.child,e!==null))for(Io(e,t,n),e=e.sibling;e!==null;)Io(e,t,n),e=e.sibling}function Fo(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.insertBefore(e,t):n.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(Fo(e,t,n),e=e.sibling;e!==null;)Fo(e,t,n),e=e.sibling}var Ue=null,xt=!1;function Gt(e,t,n){for(n=n.child;n!==null;)Du(e,t,n),n=n.sibling}function Du(e,t,n){if(jt&&typeof jt.onCommitFiberUnmount=="function")try{jt.onCommitFiberUnmount(Vr,n)}catch{}switch(n.tag){case 5:Ye||An(n,t);case 6:var r=Ue,i=xt;Ue=null,Gt(e,t,n),Ue=r,xt=i,Ue!==null&&(xt?(e=Ue,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):Ue.removeChild(n.stateNode));break;case 18:Ue!==null&&(xt?(e=Ue,n=n.stateNode,e.nodeType===8?Ki(e.parentNode,n):e.nodeType===1&&Ki(e,n),or(e)):Ki(Ue,n.stateNode));break;case 4:r=Ue,i=xt,Ue=n.stateNode.containerInfo,xt=!0,Gt(e,t,n),Ue=r,xt=i;break;case 0:case 11:case 14:case 15:if(!Ye&&(r=n.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){i=r=r.next;do{var a=i,u=a.destroy;a=a.tag,u!==void 0&&((a&2)!==0||(a&4)!==0)&&Ro(n,t,u),i=i.next}while(i!==r)}Gt(e,t,n);break;case 1:if(!Ye&&(An(n,t),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(f){be(n,t,f)}Gt(e,t,n);break;case 21:Gt(e,t,n);break;case 22:n.mode&1?(Ye=(r=Ye)||n.memoizedState!==null,Gt(e,t,n),Ye=r):Gt(e,t,n);break;default:Gt(e,t,n)}}function Au(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new Pf),t.forEach(function(r){var i=Of.bind(null,e,r);n.has(r)||(n.add(r),r.then(i,i))})}}function St(e,t){var n=t.deletions;if(n!==null)for(var r=0;ri&&(i=u),r&=~a}if(r=i,r=Re()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*bf(r/1960))-r,10e?16:e,qt===null)var r=!1;else{if(e=qt,qt=null,Wl=0,(me&6)!==0)throw Error(s(331));var i=me;for(me|=4,Y=e.current;Y!==null;){var a=Y,u=a.child;if((Y.flags&16)!==0){var f=a.deletions;if(f!==null){for(var h=0;hRe()-Oo?gn(e,0):Bo|=n),rt(e,t)}function ec(e,t){t===0&&((e.mode&1)===0?t=1:(t=Qr,Qr<<=1,(Qr&130023424)===0&&(Qr=4194304)));var n=qe();e=bt(e,t),e!==null&&(tr(e,t,n),rt(e,n))}function Bf(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),ec(e,n)}function Of(e,t){var n=0;switch(e.tag){case 13:var r=e.stateNode,i=e.memoizedState;i!==null&&(n=i.retryLane);break;case 19:r=e.stateNode;break;default:throw Error(s(314))}r!==null&&r.delete(t),ec(e,n)}var tc;tc=function(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps||Ze.current)tt=!0;else{if((e.lanes&n)===0&&(t.flags&128)===0)return tt=!1,Cf(e,t,n);tt=(e.flags&131072)!==0}else tt=!1,Ce&&(t.flags&1048576)!==0&&Is(t,ml,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;zl(e,t),e=t.pendingProps;var i=Rn(t,Qe.current);On(t,n),i=ho(null,t,r,e,i,n);var a=go();return t.flags|=1,typeof i=="object"&&i!==null&&typeof i.render=="function"&&i.$$typeof===void 0?(t.tag=1,t.memoizedState=null,t.updateQueue=null,et(r)?(a=!0,dl(t)):a=!1,t.memoizedState=i.state!==null&&i.state!==void 0?i.state:null,ao(t),i.updater=El,t.stateNode=i,i._reactInternals=t,jo(t,r,e,n),t=No(null,t,r,!0,a,n)):(t.tag=0,Ce&&a&&Xi(t),Xe(null,t,i,n),t=t.child),t;case 16:r=t.elementType;e:{switch(zl(e,t),e=t.pendingProps,i=r._init,r=i(r._payload),t.type=r,i=t.tag=Df(r),e=yt(r,e),i){case 0:t=Co(null,t,r,e,n);break e;case 1:t=Eu(null,t,r,e,n);break e;case 11:t=ju(null,t,r,e,n);break e;case 14:t=ku(null,t,r,yt(r.type,e),n);break e}throw Error(s(306,r,""))}return t;case 0:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:yt(r,i),Co(e,t,r,i,n);case 1:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:yt(r,i),Eu(e,t,r,i,n);case 3:e:{if(Pu(t),e===null)throw Error(s(387));r=t.pendingProps,a=t.memoizedState,i=a.element,Us(e,t),Sl(t,r,null,n);var u=t.memoizedState;if(r=u.element,a.isDehydrated)if(a={element:r,isDehydrated:!1,cache:u.cache,pendingSuspenseBoundaries:u.pendingSuspenseBoundaries,transitions:u.transitions},t.updateQueue.baseState=a,t.memoizedState=a,t.flags&256){i=Dn(Error(s(423)),t),t=zu(e,t,r,n,i);break e}else if(r!==i){i=Dn(Error(s(424)),t),t=zu(e,t,r,n,i);break e}else for(at=Vt(t.stateNode.containerInfo.firstChild),ot=t,Ce=!0,vt=null,n=As(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(Fn(),r===i){t=Lt(e,t,n);break e}Xe(e,t,r,n)}t=t.child}return t;case 5:return Qs(t),e===null&&eo(t),r=t.type,i=t.pendingProps,a=e!==null?e.memoizedProps:null,u=i.children,Hi(r,i)?u=null:a!==null&&Hi(r,a)&&(t.flags|=32),Nu(e,t),Xe(e,t,u,n),t.child;case 6:return e===null&&eo(t),null;case 13:return Tu(e,t,n);case 4:return so(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=Wn(t,null,r,n):Xe(e,t,r,n),t.child;case 11:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:yt(r,i),ju(e,t,r,i,n);case 7:return Xe(e,t,t.pendingProps,n),t.child;case 8:return Xe(e,t,t.pendingProps.children,n),t.child;case 12:return Xe(e,t,t.pendingProps.children,n),t.child;case 10:e:{if(r=t.type._context,i=t.pendingProps,a=t.memoizedProps,u=i.value,je(vl,r._currentValue),r._currentValue=u,a!==null)if(gt(a.value,u)){if(a.children===i.children&&!Ze.current){t=Lt(e,t,n);break e}}else for(a=t.child,a!==null&&(a.return=t);a!==null;){var f=a.dependencies;if(f!==null){u=a.child;for(var h=f.firstContext;h!==null;){if(h.context===r){if(a.tag===1){h=Rt(-1,n&-n),h.tag=2;var E=a.updateQueue;if(E!==null){E=E.shared;var D=E.pending;D===null?h.next=h:(h.next=D.next,D.next=h),E.pending=h}}a.lanes|=n,h=a.alternate,h!==null&&(h.lanes|=n),io(a.return,n,t),f.lanes|=n;break}h=h.next}}else if(a.tag===10)u=a.type===t.type?null:a.child;else if(a.tag===18){if(u=a.return,u===null)throw Error(s(341));u.lanes|=n,f=u.alternate,f!==null&&(f.lanes|=n),io(u,n,t),u=a.sibling}else u=a.child;if(u!==null)u.return=a;else for(u=a;u!==null;){if(u===t){u=null;break}if(a=u.sibling,a!==null){a.return=u.return,u=a;break}u=u.return}a=u}Xe(e,t,i.children,n),t=t.child}return t;case 9:return i=t.type,r=t.pendingProps.children,On(t,n),i=dt(i),r=r(i),t.flags|=1,Xe(e,t,r,n),t.child;case 14:return r=t.type,i=yt(r,t.pendingProps),i=yt(r.type,i),ku(e,t,r,i,n);case 15:return _u(e,t,t.type,t.pendingProps,n);case 17:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:yt(r,i),zl(e,t),t.tag=1,et(r)?(e=!0,dl(t)):e=!1,On(t,n),hu(t,r,i),jo(t,r,i,n),No(null,t,r,!0,e,n);case 19:return Ru(e,t,n);case 22:return Cu(e,t,n)}throw Error(s(156,t.tag))};function nc(e,t){return Fa(e,t)}function Mf(e,t,n,r){this.tag=e,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function mt(e,t,n,r){return new Mf(e,t,n,r)}function Qo(e){return e=e.prototype,!(!e||!e.isReactComponent)}function Df(e){if(typeof e=="function")return Qo(e)?1:0;if(e!=null){if(e=e.$$typeof,e===Ne)return 11;if(e===Me)return 14}return 2}function tn(e,t){var n=e.alternate;return n===null?(n=mt(e.tag,t,e.key,e.mode),n.elementType=e.elementType,n.type=e.type,n.stateNode=e.stateNode,n.alternate=e,e.alternate=n):(n.pendingProps=t,n.type=e.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=e.flags&14680064,n.childLanes=e.childLanes,n.lanes=e.lanes,n.child=e.child,n.memoizedProps=e.memoizedProps,n.memoizedState=e.memoizedState,n.updateQueue=e.updateQueue,t=e.dependencies,n.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},n.sibling=e.sibling,n.index=e.index,n.ref=e.ref,n}function Dl(e,t,n,r,i,a){var u=2;if(r=e,typeof e=="function")Qo(e)&&(u=1);else if(typeof e=="string")u=5;else e:switch(e){case we:return yn(n.children,i,a,t);case xe:u=8,i|=8;break;case re:return e=mt(12,n,t,i|2),e.elementType=re,e.lanes=a,e;case ve:return e=mt(13,n,t,i),e.elementType=ve,e.lanes=a,e;case Te:return e=mt(19,n,t,i),e.elementType=Te,e.lanes=a,e;case Se:return Al(n,i,a,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case oe:u=10;break e;case pe:u=9;break e;case Ne:u=11;break e;case Me:u=14;break e;case We:u=16,r=null;break e}throw Error(s(130,e==null?e:typeof e,""))}return t=mt(u,n,t,i),t.elementType=e,t.type=r,t.lanes=a,t}function yn(e,t,n,r){return e=mt(7,e,r,t),e.lanes=n,e}function Al(e,t,n,r){return e=mt(22,e,r,t),e.elementType=Se,e.lanes=n,e.stateNode={isHidden:!1},e}function Ko(e,t,n){return e=mt(6,e,null,t),e.lanes=n,e}function Jo(e,t,n){return t=mt(4,e.children!==null?e.children:[],e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function Af(e,t,n,r,i){this.tag=t,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Si(0),this.expirationTimes=Si(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Si(0),this.identifierPrefix=r,this.onRecoverableError=i,this.mutableSourceEagerHydrationData=null}function Yo(e,t,n,r,i,a,u,f,h){return e=new Af(e,t,n,f,h),t===1?(t=1,a===!0&&(t|=8)):t=0,a=mt(3,null,null,t),e.current=a,a.stateNode=e,a.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},ao(a),e}function $f(e,t,n){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(o)}catch(c){console.error(c)}}return o(),ta.exports=tp(),ta.exports}var gc;function np(){if(gc)return Jl;gc=1;var o=Oc();return Jl.createRoot=o.createRoot,Jl.hydrateRoot=o.hydrateRoot,Jl}var rp=np();const lp=Wc(rp);Oc();/** - * @remix-run/router v1.23.3 - * - * Copyright (c) Remix Software Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE.md file in the root directory of this source tree. - * - * @license MIT - */function Wr(){return Wr=Object.assign?Object.assign.bind():function(o){for(var c=1;c"u")throw new Error(c)}function ca(o,c){if(!o){typeof console<"u"&&console.warn(c);try{throw new Error(c)}catch{}}}function op(){return Math.random().toString(36).substr(2,8)}function yc(o,c){return{usr:o.state,key:o.key,idx:c}}function ia(o,c,s,d){return s===void 0&&(s=null),Wr({pathname:typeof o=="string"?o:o.pathname,search:"",hash:""},typeof c=="string"?Qn(c):c,{state:s,key:c&&c.key||d||op()})}function Zl(o){let{pathname:c="/",search:s="",hash:d=""}=o;return s&&s!=="?"&&(c+=s.charAt(0)==="?"?s:"?"+s),d&&d!=="#"&&(c+=d.charAt(0)==="#"?d:"#"+d),c}function Qn(o){let c={};if(o){let s=o.indexOf("#");s>=0&&(c.hash=o.substr(s),o=o.substr(0,s));let d=o.indexOf("?");d>=0&&(c.search=o.substr(d),o=o.substr(0,d)),o&&(c.pathname=o)}return c}function ap(o,c,s,d){d===void 0&&(d={});let{window:p=document.defaultView,v5Compat:y=!1}=d,g=p.history,P=rn.Pop,S=null,T=z();T==null&&(T=0,g.replaceState(Wr({},g.state,{idx:T}),""));function z(){return(g.state||{idx:null}).idx}function v(){P=rn.Pop;let j=z(),F=j==null?null:j-T;T=j,S&&S({action:P,location:N.location,delta:F})}function L(j,F){P=rn.Push;let _=ia(N.location,j,F);T=z()+1;let W=yc(_,T),B=N.createHref(_);try{g.pushState(W,"",B)}catch(Z){if(Z instanceof DOMException&&Z.name==="DataCloneError")throw Z;p.location.assign(B)}y&&S&&S({action:P,location:N.location,delta:1})}function A(j,F){P=rn.Replace;let _=ia(N.location,j,F);T=z();let W=yc(_,T),B=N.createHref(_);g.replaceState(W,"",B),y&&S&&S({action:P,location:N.location,delta:0})}function R(j){let F=p.location.origin!=="null"?p.location.origin:p.location.href,_=typeof j=="string"?j:Zl(j);return _=_.replace(/ $/,"%20"),ze(F,"No window.location.(origin|href) available to create URL for href: "+_),new URL(_,F)}let N={get action(){return P},get location(){return o(p,g)},listen(j){if(S)throw new Error("A history only accepts one active listener");return p.addEventListener(vc,v),S=j,()=>{p.removeEventListener(vc,v),S=null}},createHref(j){return c(p,j)},createURL:R,encodeLocation(j){let F=R(j);return{pathname:F.pathname,search:F.search,hash:F.hash}},push:L,replace:A,go(j){return g.go(j)}};return N}var xc;(function(o){o.data="data",o.deferred="deferred",o.redirect="redirect",o.error="error"})(xc||(xc={}));function sp(o,c,s){return s===void 0&&(s="/"),up(o,c,s)}function up(o,c,s,d){let p=typeof c=="string"?Qn(c):c,y=Hn(p.pathname||"/",s);if(y==null)return null;let g=Mc(o);cp(g);let P=null,S=wp(y);for(let T=0;P==null&&T{let S={relativePath:P===void 0?y.path||"":P,caseSensitive:y.caseSensitive===!0,childrenIndex:g,route:y};S.relativePath.startsWith("/")&&(ze(S.relativePath.startsWith(d),'Absolute route path "'+S.relativePath+'" nested under path '+('"'+d+'" is not valid. An absolute child route path ')+"must start with the combined path of all its parent routes."),S.relativePath=S.relativePath.slice(d.length));let T=ln([d,S.relativePath]),z=s.concat(S);y.children&&y.children.length>0&&(ze(y.index!==!0,"Index routes must not have child routes. Please remove "+('all child routes from route path "'+T+'".')),Mc(y.children,c,z,T)),!(y.path==null&&!y.index)&&c.push({path:T,score:vp(T,y.index),routesMeta:z})};return o.forEach((y,g)=>{var P;if(y.path===""||!((P=y.path)!=null&&P.includes("?")))p(y,g);else for(let S of Dc(y.path))p(y,g,S)}),c}function Dc(o){let c=o.split("/");if(c.length===0)return[];let[s,...d]=c,p=s.endsWith("?"),y=s.replace(/\?$/,"");if(d.length===0)return p?[y,""]:[y];let g=Dc(d.join("/")),P=[];return P.push(...g.map(S=>S===""?y:[y,S].join("/"))),p&&P.push(...g),P.map(S=>o.startsWith("/")&&S===""?"/":S)}function cp(o){o.sort((c,s)=>c.score!==s.score?s.score-c.score:yp(c.routesMeta.map(d=>d.childrenIndex),s.routesMeta.map(d=>d.childrenIndex)))}const dp=/^:[\w-]+$/,fp=3,pp=2,mp=1,hp=10,gp=-2,Sc=o=>o==="*";function vp(o,c){let s=o.split("/"),d=s.length;return s.some(Sc)&&(d+=gp),c&&(d+=pp),s.filter(p=>!Sc(p)).reduce((p,y)=>p+(dp.test(y)?fp:y===""?mp:hp),d)}function yp(o,c){return o.length===c.length&&o.slice(0,-1).every((d,p)=>d===c[p])?o[o.length-1]-c[c.length-1]:0}function xp(o,c,s){let{routesMeta:d}=o,p={},y="/",g=[];for(let P=0;P{let{paramName:L,isOptional:A}=z;if(L==="*"){let N=P[v]||"";g=y.slice(0,y.length-N.length).replace(/(.)\/+$/,"$1")}const R=P[v];return A&&!R?T[L]=void 0:T[L]=(R||"").replace(/%2F/g,"/"),T},{}),pathname:y,pathnameBase:g,pattern:o}}function Sp(o,c,s){c===void 0&&(c=!1),s===void 0&&(s=!0),ca(o==="*"||!o.endsWith("*")||o.endsWith("/*"),'Route path "'+o+'" will be treated as if it were '+('"'+o.replace(/\*$/,"/*")+'" because the `*` character must ')+"always follow a `/` in the pattern. To get rid of this warning, "+('please change the route path to "'+o.replace(/\*$/,"/*")+'".'));let d=[],p="^"+o.replace(/\/*\*?$/,"").replace(/^\/*/,"/").replace(/[\\.*+^${}|()[\]]/g,"\\$&").replace(/\/:([\w-]+)(\?)?/g,(g,P,S)=>(d.push({paramName:P,isOptional:S!=null}),S?"/?([^\\/]+)?":"/([^\\/]+)"));return o.endsWith("*")?(d.push({paramName:"*"}),p+=o==="*"||o==="/*"?"(.*)$":"(?:\\/(.+)|\\/*)$"):s?p+="\\/*$":o!==""&&o!=="/"&&(p+="(?:(?=\\/|$))"),[new RegExp(p,c?void 0:"i"),d]}function wp(o){try{return o.split("/").map(c=>decodeURIComponent(c).replace(/\//g,"%2F")).join("/")}catch(c){return ca(!1,'The URL path "'+o+'" could not be decoded because it is is a malformed URL segment. This is probably due to a bad percent '+("encoding ("+c+").")),o}}function Hn(o,c){if(c==="/")return o;if(!o.toLowerCase().startsWith(c.toLowerCase()))return null;let s=c.endsWith("/")?c.length-1:c.length,d=o.charAt(s);return d&&d!=="/"?null:o.slice(s)||"/"}const jp=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,kp=o=>jp.test(o);function _p(o,c){c===void 0&&(c="/");let{pathname:s,search:d="",hash:p=""}=typeof o=="string"?Qn(o):o,y;if(s)if(kp(s))y=s;else{if(s.includes("//")){let g=s;s=Ac(s),ca(!1,"Pathnames cannot have embedded double slashes - normalizing "+(g+" -> "+s))}s.startsWith("/")?y=wc(s.substring(1),"/"):y=wc(s,c)}else y=c;return{pathname:y,search:Ep(d),hash:Pp(p)}}function wc(o,c){let s=c.replace(/\/+$/,"").split("/");return o.split("/").forEach(p=>{p===".."?s.length>1&&s.pop():p!=="."&&s.push(p)}),s.length>1?s.join("/"):"/"}function la(o,c,s,d){return"Cannot include a '"+o+"' character in a manually specified "+("`to."+c+"` field ["+JSON.stringify(d)+"]. Please separate it out to the ")+("`to."+s+"` field. Alternatively you may provide the full path as ")+'a string in and the router will parse it for you.'}function Cp(o){return o.filter((c,s)=>s===0||c.route.path&&c.route.path.length>0)}function da(o,c){let s=Cp(o);return c?s.map((d,p)=>p===s.length-1?d.pathname:d.pathnameBase):s.map(d=>d.pathnameBase)}function fa(o,c,s,d){d===void 0&&(d=!1);let p;typeof o=="string"?p=Qn(o):(p=Wr({},o),ze(!p.pathname||!p.pathname.includes("?"),la("?","pathname","search",p)),ze(!p.pathname||!p.pathname.includes("#"),la("#","pathname","hash",p)),ze(!p.search||!p.search.includes("#"),la("#","search","hash",p)));let y=o===""||p.pathname==="",g=y?"/":p.pathname,P;if(g==null)P=s;else{let v=c.length-1;if(!d&&g.startsWith("..")){let L=g.split("/");for(;L[0]==="..";)L.shift(),v-=1;p.pathname=L.join("/")}P=v>=0?c[v]:"/"}let S=_p(p,P),T=g&&g!=="/"&&g.endsWith("/"),z=(y||g===".")&&s.endsWith("/");return!S.pathname.endsWith("/")&&(T||z)&&(S.pathname+="/"),S}const Ac=o=>o.replace(/\/\/+/g,"/"),ln=o=>Ac(o.join("/")),Np=o=>o.replace(/\/+$/,"").replace(/^\/*/,"/"),Ep=o=>!o||o==="?"?"":o.startsWith("?")?o:"?"+o,Pp=o=>!o||o==="#"?"":o.startsWith("#")?o:"#"+o;function zp(o){return o!=null&&typeof o.status=="number"&&typeof o.statusText=="string"&&typeof o.internal=="boolean"&&"data"in o}const $c=["post","put","patch","delete"];new Set($c);const Tp=["get",...$c];new Set(Tp);/** - * React Router v6.30.4 - * - * Copyright (c) Remix Software Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE.md file in the root directory of this source tree. - * - * @license MIT - */function Br(){return Br=Object.assign?Object.assign.bind():function(o){for(var c=1;c{P.current=!0}),m.useCallback(function(T,z){if(z===void 0&&(z={}),!P.current)return;if(typeof T=="number"){d.go(T);return}let v=fa(T,JSON.parse(g),y,z.relative==="path");o==null&&c!=="/"&&(v.pathname=v.pathname==="/"?c:ln([c,v.pathname])),(z.replace?d.replace:d.push)(v,z.state,z)},[c,d,g,y,o])}function pa(){let{matches:o}=m.useContext(Bt),c=o[o.length-1];return c?c.params:{}}function li(o,c){let{relative:s}=c===void 0?{}:c,{future:d}=m.useContext(Wt),{matches:p}=m.useContext(Bt),{pathname:y}=xn(),g=JSON.stringify(da(p,d.v7_relativeSplatPath));return m.useMemo(()=>fa(o,JSON.parse(g),y,s==="path"),[o,g,y,s])}function Lp(o,c){return Ip(o,c)}function Ip(o,c,s,d){Kn()||ze(!1);let{navigator:p}=m.useContext(Wt),{matches:y}=m.useContext(Bt),g=y[y.length-1],P=g?g.params:{};g&&g.pathname;let S=g?g.pathnameBase:"/";g&&g.route;let T=xn(),z;if(c){var v;let j=typeof c=="string"?Qn(c):c;S==="/"||(v=j.pathname)!=null&&v.startsWith(S)||ze(!1),z=j}else z=T;let L=z.pathname||"/",A=L;if(S!=="/"){let j=S.replace(/^\//,"").split("/");A="/"+L.replace(/^\//,"").split("/").slice(j.length).join("/")}let R=sp(o,{pathname:A}),N=Mp(R&&R.map(j=>Object.assign({},j,{params:Object.assign({},P,j.params),pathname:ln([S,p.encodeLocation?p.encodeLocation(j.pathname).pathname:j.pathname]),pathnameBase:j.pathnameBase==="/"?S:ln([S,p.encodeLocation?p.encodeLocation(j.pathnameBase).pathname:j.pathnameBase])})),y,s,d);return c&&N?m.createElement(ri.Provider,{value:{location:Br({pathname:"/",search:"",hash:"",state:null,key:"default"},z),navigationType:rn.Pop}},N):N}function Fp(){let o=Up(),c=zp(o)?o.status+" "+o.statusText:o instanceof Error?o.message:JSON.stringify(o),s=o instanceof Error?o.stack:null,p={padding:"0.5rem",backgroundColor:"rgba(200,200,200, 0.5)"};return m.createElement(m.Fragment,null,m.createElement("h2",null,"Unexpected Application Error!"),m.createElement("h3",{style:{fontStyle:"italic"}},c),s?m.createElement("pre",{style:p},s):null,null)}const Wp=m.createElement(Fp,null);class Bp extends m.Component{constructor(c){super(c),this.state={location:c.location,revalidation:c.revalidation,error:c.error}}static getDerivedStateFromError(c){return{error:c}}static getDerivedStateFromProps(c,s){return s.location!==c.location||s.revalidation!=="idle"&&c.revalidation==="idle"?{error:c.error,location:c.location,revalidation:c.revalidation}:{error:c.error!==void 0?c.error:s.error,location:s.location,revalidation:c.revalidation||s.revalidation}}componentDidCatch(c,s){console.error("React Router caught the following error during render",c,s)}render(){return this.state.error!==void 0?m.createElement(Bt.Provider,{value:this.props.routeContext},m.createElement(Vc.Provider,{value:this.state.error,children:this.props.component})):this.props.children}}function Op(o){let{routeContext:c,match:s,children:d}=o,p=m.useContext(ni);return p&&p.static&&p.staticContext&&(s.route.errorElement||s.route.ErrorBoundary)&&(p.staticContext._deepestRenderedBoundaryId=s.route.id),m.createElement(Bt.Provider,{value:c},d)}function Mp(o,c,s,d){var p;if(c===void 0&&(c=[]),s===void 0&&(s=null),d===void 0&&(d=null),o==null){var y;if(!s)return null;if(s.errors)o=s.matches;else if((y=d)!=null&&y.v7_partialHydration&&c.length===0&&!s.initialized&&s.matches.length>0)o=s.matches;else return null}let g=o,P=(p=s)==null?void 0:p.errors;if(P!=null){let z=g.findIndex(v=>v.route.id&&(P==null?void 0:P[v.route.id])!==void 0);z>=0||ze(!1),g=g.slice(0,Math.min(g.length,z+1))}let S=!1,T=-1;if(s&&d&&d.v7_partialHydration)for(let z=0;z=0?g=g.slice(0,T+1):g=[g[0]];break}}}return g.reduceRight((z,v,L)=>{let A,R=!1,N=null,j=null;s&&(A=P&&v.route.id?P[v.route.id]:void 0,N=v.route.errorElement||Wp,S&&(T<0&&L===0?(Hp("route-fallback"),R=!0,j=null):T===L&&(R=!0,j=v.route.hydrateFallbackElement||null)));let F=c.concat(g.slice(0,L+1)),_=()=>{let W;return A?W=N:R?W=j:v.route.Component?W=m.createElement(v.route.Component,null):v.route.element?W=v.route.element:W=z,m.createElement(Op,{match:v,routeContext:{outlet:z,matches:F,isDataRoute:s!=null},children:W})};return s&&(v.route.ErrorBoundary||v.route.errorElement||L===0)?m.createElement(Bp,{location:s.location,revalidation:s.revalidation,component:N,error:A,children:_(),routeContext:{outlet:null,matches:F,isDataRoute:!0}}):_()},null)}var Qc=(function(o){return o.UseBlocker="useBlocker",o.UseRevalidator="useRevalidator",o.UseNavigateStable="useNavigate",o})(Qc||{}),Kc=(function(o){return o.UseBlocker="useBlocker",o.UseLoaderData="useLoaderData",o.UseActionData="useActionData",o.UseRouteError="useRouteError",o.UseNavigation="useNavigation",o.UseRouteLoaderData="useRouteLoaderData",o.UseMatches="useMatches",o.UseRevalidator="useRevalidator",o.UseNavigateStable="useNavigate",o.UseRouteId="useRouteId",o})(Kc||{});function Dp(o){let c=m.useContext(ni);return c||ze(!1),c}function Ap(o){let c=m.useContext(Uc);return c||ze(!1),c}function $p(o){let c=m.useContext(Bt);return c||ze(!1),c}function Jc(o){let c=$p(),s=c.matches[c.matches.length-1];return s.route.id||ze(!1),s.route.id}function Up(){var o;let c=m.useContext(Vc),s=Ap(),d=Jc();return c!==void 0?c:(o=s.errors)==null?void 0:o[d]}function Vp(){let{router:o}=Dp(Qc.UseNavigateStable),c=Jc(Kc.UseNavigateStable),s=m.useRef(!1);return Hc(()=>{s.current=!0}),m.useCallback(function(p,y){y===void 0&&(y={}),s.current&&(typeof p=="number"?o.navigate(p):o.navigate(p,Br({fromRouteId:c},y)))},[o,c])}const jc={};function Hp(o,c,s){jc[o]||(jc[o]=!0)}function Qp(o,c){o==null||o.v7_startTransition,o==null||o.v7_relativeSplatPath}function Kp(o){let{to:c,replace:s,state:d,relative:p}=o;Kn()||ze(!1);let{future:y,static:g}=m.useContext(Wt),{matches:P}=m.useContext(Bt),{pathname:S}=xn(),T=Ge(),z=fa(c,da(P,y.v7_relativeSplatPath),S,p==="path"),v=JSON.stringify(z);return m.useEffect(()=>T(JSON.parse(v),{replace:s,state:d,relative:p}),[T,v,p,s,d]),null}function Fe(o){ze(!1)}function Jp(o){let{basename:c="/",children:s=null,location:d,navigationType:p=rn.Pop,navigator:y,static:g=!1,future:P}=o;Kn()&&ze(!1);let S=c.replace(/^\/*/,"/"),T=m.useMemo(()=>({basename:S,navigator:y,static:g,future:Br({v7_relativeSplatPath:!1},P)}),[S,P,y,g]);typeof d=="string"&&(d=Qn(d));let{pathname:z="/",search:v="",hash:L="",state:A=null,key:R="default"}=d,N=m.useMemo(()=>{let j=Hn(z,S);return j==null?null:{location:{pathname:j,search:v,hash:L,state:A,key:R},navigationType:p}},[S,z,v,L,A,R,p]);return N==null?null:m.createElement(Wt.Provider,{value:T},m.createElement(ri.Provider,{children:s,value:N}))}function Yp(o){let{children:c,location:s}=o;return Lp(aa(c),s)}new Promise(()=>{});function aa(o,c){c===void 0&&(c=[]);let s=[];return m.Children.forEach(o,(d,p)=>{if(!m.isValidElement(d))return;let y=[...c,p];if(d.type===m.Fragment){s.push.apply(s,aa(d.props.children,y));return}d.type!==Fe&&ze(!1),!d.props.index||!d.props.children||ze(!1);let g={id:d.props.id||y.join("-"),caseSensitive:d.props.caseSensitive,element:d.props.element,Component:d.props.Component,index:d.props.index,path:d.props.path,loader:d.props.loader,action:d.props.action,errorElement:d.props.errorElement,ErrorBoundary:d.props.ErrorBoundary,hasErrorBoundary:d.props.ErrorBoundary!=null||d.props.errorElement!=null,shouldRevalidate:d.props.shouldRevalidate,handle:d.props.handle,lazy:d.props.lazy};d.props.children&&(g.children=aa(d.props.children,y)),s.push(g)}),s}/** - * React Router DOM v6.30.4 - * - * Copyright (c) Remix Software Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE.md file in the root directory of this source tree. - * - * @license MIT - */function ei(){return ei=Object.assign?Object.assign.bind():function(o){for(var c=1;c{T&&kc?kc(()=>S(v)):S(v)},[S,T]);return m.useLayoutEffect(()=>g.listen(z),[g,z]),m.useEffect(()=>Qp(d),[d]),m.createElement(Jp,{basename:c,children:s,location:P.location,navigationType:P.action,navigator:g,future:d})}const lm=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",im=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,Gc=m.forwardRef(function(c,s){let{onClick:d,relative:p,reloadDocument:y,replace:g,state:P,target:S,to:T,preventScrollReset:z,viewTransition:v}=c,L=Yc(c,qp),{basename:A}=m.useContext(Wt),R,N=!1;if(typeof T=="string"&&im.test(T)&&(R=T,lm))try{let W=new URL(window.location.href),B=T.startsWith("//")?new URL(W.protocol+T):new URL(T),Z=Hn(B.pathname,A);B.origin===W.origin&&Z!=null?T=Z+B.search+B.hash:N=!0}catch{}let j=bp(T,{relative:p}),F=am(T,{replace:g,state:P,target:S,preventScrollReset:z,relative:p,viewTransition:v});function _(W){d&&d(W),W.defaultPrevented||F(W)}return m.createElement("a",ei({},L,{href:R||j,onClick:N||y?d:_,ref:s,target:S}))}),Ir=m.forwardRef(function(c,s){let{"aria-current":d="page",caseSensitive:p=!1,className:y="",end:g=!1,style:P,to:S,viewTransition:T,children:z}=c,v=Yc(c,Zp),L=li(S,{relative:v.relative}),A=xn(),R=m.useContext(Uc),{navigator:N,basename:j}=m.useContext(Wt),F=R!=null&&sm(L)&&T===!0,_=N.encodeLocation?N.encodeLocation(L).pathname:L.pathname,W=A.pathname,B=R&&R.navigation&&R.navigation.location?R.navigation.location.pathname:null;p||(W=W.toLowerCase(),B=B?B.toLowerCase():null,_=_.toLowerCase()),B&&j&&(B=Hn(B,j)||B);const Z=_!=="/"&&_.endsWith("/")?_.length-1:_.length;let fe=W===_||!g&&W.startsWith(_)&&W.charAt(Z)==="/",we=B!=null&&(B===_||!g&&B.startsWith(_)&&B.charAt(_.length)==="/"),xe={isActive:fe,isPending:we,isTransitioning:F},re=fe?d:void 0,oe;typeof y=="function"?oe=y(xe):oe=[y,fe?"active":null,we?"pending":null,F?"transitioning":null].filter(Boolean).join(" ");let pe=typeof P=="function"?P(xe):P;return m.createElement(Gc,ei({},v,{"aria-current":re,className:oe,ref:s,style:pe,to:S,viewTransition:T}),typeof z=="function"?z(xe):z)});var sa;(function(o){o.UseScrollRestoration="useScrollRestoration",o.UseSubmit="useSubmit",o.UseSubmitFetcher="useSubmitFetcher",o.UseFetcher="useFetcher",o.useViewTransitionState="useViewTransitionState"})(sa||(sa={}));var _c;(function(o){o.UseFetcher="useFetcher",o.UseFetchers="useFetchers",o.UseScrollRestoration="useScrollRestoration"})(_c||(_c={}));function om(o){let c=m.useContext(ni);return c||ze(!1),c}function am(o,c){let{target:s,replace:d,state:p,preventScrollReset:y,relative:g,viewTransition:P}=c===void 0?{}:c,S=Ge(),T=xn(),z=li(o,{relative:g});return m.useCallback(v=>{if(Xp(v,s)){v.preventDefault();let L=d!==void 0?d:Zl(T)===Zl(z);S(o,{replace:L,state:p,preventScrollReset:y,relative:g,viewTransition:P})}},[T,S,z,d,p,s,o,y,g,P])}function sm(o,c){c===void 0&&(c={});let s=m.useContext(tm);s==null&&ze(!1);let{basename:d}=om(sa.useViewTransitionState),p=li(o,{relative:c.relative});if(!s.isTransitioning)return!1;let y=Hn(s.currentLocation.pathname,d)||s.currentLocation.pathname,g=Hn(s.nextLocation.pathname,d)||s.nextLocation.pathname;return oa(p.pathname,g)!=null||oa(p.pathname,y)!=null}const um="/api";function cm(){return localStorage.getItem("fitness_token")}async function K(o,c={}){const s=cm(),d={"Content-Type":"application/json",...c.headers};s&&(d.Authorization=`Bearer ${s}`);const p=await fetch(`${um}${o}`,{...c,headers:d});if(p.status===401)throw localStorage.removeItem("fitness_token"),window.location.href="/login",new Error("Unauthorized");if(!p.ok){const y=await p.json().catch(()=>({detail:"Request failed"}));throw new Error(y.detail||`HTTP ${p.status}`)}return p.json()}const J={login:(o,c)=>K("/auth/login",{method:"POST",body:JSON.stringify({username:o,password:c})}),register:(o,c,s)=>K("/auth/register",{method:"POST",body:JSON.stringify({username:o,password:c,display_name:s})}),me:()=>K("/auth/me"),onboardingStatus:()=>K("/onboarding/status"),savePhase1:o=>K("/onboarding/phase1",{method:"POST",body:JSON.stringify(o)}),savePhase2:o=>K("/onboarding/phase2",{method:"POST",body:JSON.stringify(o)}),getRecommendations:()=>K("/onboarding/recommendations"),today:()=>K("/points/today"),week:o=>K(`/points/week${o?`?start=${o}`:""}`),getRules:()=>K("/points/rules"),updateRule:(o,c)=>K(`/points/rules/${o}`,{method:"PATCH",body:JSON.stringify(c)}),getTargets:()=>K("/points/targets"),updateTargets:o=>K("/points/targets",{method:"PATCH",body:JSON.stringify(o)}),listActivities:o=>K(`/activities${o?`?date=${o}`:""}`),logActivity:o=>K("/activities",{method:"POST",body:JSON.stringify(o)}),deleteActivity:o=>K(`/activities/${o}`,{method:"DELETE"}),listFood:o=>K(`/food${o?`?date=${o}`:""}`),logFood:o=>K("/food",{method:"POST",body:JSON.stringify(o)}),deleteFood:o=>K(`/food/${o}`,{method:"DELETE"}),scanBarcode:o=>K(`/food/scan/${o}`),searchFood:o=>K(`/food/search?q=${encodeURIComponent(o)}`),nutritionToday:()=>K("/nutrition/today"),getNutritionGoals:()=>K("/nutrition/goals"),updateNutritionGoals:o=>K("/nutrition/goals",{method:"PATCH",body:JSON.stringify(o)}),startFast:o=>K("/nutrition/fasts",{method:"POST",body:JSON.stringify(o)}),endFast:(o,c)=>K(`/nutrition/fasts/${o}`,{method:"PATCH",body:JSON.stringify(c||{})}),listFasts:o=>K(`/nutrition/fasts${o?`?limit=${o}`:""}`),getActiveFast:()=>K("/nutrition/fasts/active"),deleteFast:o=>K(`/nutrition/fasts/${o}`,{method:"DELETE"}),logElectrolytes:o=>K("/nutrition/electrolytes",{method:"POST",body:JSON.stringify(o)}),getElectrolytesToday:()=>K("/nutrition/electrolytes/today"),listRewards:()=>K("/rewards"),createReward:o=>K("/rewards",{method:"POST",body:JSON.stringify(o)}),redeemReward:(o,c)=>K(`/rewards/${o}/redeem`,{method:"POST",body:JSON.stringify({date:c})}),listPrograms:()=>K("/programs"),createProgram:o=>K("/programs",{method:"POST",body:JSON.stringify(o)}),getProgram:o=>K(`/programs/${o}`),searchCatalog:o=>K(`/programs/catalog${o?`?q=${encodeURIComponent(o)}`:""}`),getCatalogProgram:o=>K(`/programs/catalog/${o}`),researchProgram:o=>K("/programs/research",{method:"POST",body:JSON.stringify({name:o})}),adoptProgram:(o,c)=>K(`/programs/catalog/${o}/adopt`,{method:"POST",body:JSON.stringify({start_date:c})}),getProgramSchedule:o=>K(`/programs/${o}/schedule`),getWorkoutDetail:(o,c)=>K(`/programs/${o}/workout/${c}`),completeWorkout:(o,c,s)=>K(`/programs/${o}/workout/${c}/complete`,{method:"POST",body:JSON.stringify(s)}),getProgramProgress:o=>K(`/programs/${o}/progress`),getThread:()=>K("/support/thread"),sendSupportMessage:o=>K("/support/messages",{method:"POST",body:JSON.stringify({body:o})}),getUnreadCount:()=>K("/support/unread"),listSupportThreads:()=>K("/support/admin/threads"),getAdminThread:o=>K(`/support/admin/threads/${o}`),replySupportThread:(o,c)=>K(`/support/admin/threads/${o}/reply`,{method:"POST",body:JSON.stringify({body:c})}),integrationStatus:()=>K("/integrations"),stravaAuth:()=>K("/integrations/strava/auth"),stravaSync:()=>K("/integrations/strava/sync",{method:"POST"}),polarAuth:()=>K("/integrations/polar/auth"),polarSync:()=>K("/integrations/polar/sync",{method:"POST"}),disconnect:o=>K(`/integrations/${o}`,{method:"DELETE"}),listMealPlans:()=>K("/meal-plans"),createMealPlan:o=>K("/meal-plans",{method:"POST",body:JSON.stringify(o)}),getMealPlanToday:()=>K("/meal-plans/today"),getMealPlan:o=>K("/meal-plans/"+o),updateMealPlanStatus:(o,c)=>K("/meal-plans/"+o,{method:"PATCH",body:JSON.stringify({status:c})}),logMealCompliance:o=>K("/meal-plans/compliance",{method:"POST",body:JSON.stringify(o)}),getMealPlanProgress:o=>K("/meal-plans/"+o+"/progress"),fullIntegrationStatus:()=>K("/integrations/status"),listProviders:()=>K("/integrations/providers"),configureIntegration:(o,c)=>K("/integrations/configure",{method:"POST",body:JSON.stringify({provider:o,credentials:c})}),getAIStatus:()=>K("/ai/status"),getResourceRecommendations:()=>K("/onboarding/recommendations")};function dm(o){localStorage.setItem("fitness_token",o)}function fm(){localStorage.removeItem("fitness_token")}function ti(){return!!localStorage.getItem("fitness_token")}function pm(){const[o,c]=m.useState("login"),[s,d]=m.useState(""),[p,y]=m.useState(""),[g,P]=m.useState(""),[S,T]=m.useState(""),[z,v]=m.useState(!1),L=Ge();async function A(R){R.preventDefault(),T(""),v(!0);try{const N=o==="login"?await J.login(s,p):await J.register(s,p,g||s);dm(N.access_token);const j=await J.onboardingStatus();L(j.phase1_completed?"/":"/onboarding")}catch(N){T(N.message)}finally{v(!1)}}return l.jsx("div",{style:{minHeight:"100dvh",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"24px",background:"linear-gradient(170deg, var(--accent-light) 0%, var(--accent) 30%, var(--accent-dark) 60%, var(--text) 100%)"},children:l.jsxs("div",{style:{width:"100%",maxWidth:"380px"},children:[l.jsxs("div",{style:{textAlign:"center",marginBottom:"32px",color:"#fff"},children:[l.jsx("div",{style:{fontSize:"3.2rem",marginBottom:"8px",filter:"drop-shadow(0 4px 12px rgba(0,0,0,0.2))"},children:"🔥"}),l.jsx("h1",{style:{fontFamily:"var(--font-display)",fontSize:"2.2rem",fontWeight:900,letterSpacing:"-0.03em"},children:"Fitness Rewards"}),l.jsx("p",{style:{opacity:.8,marginTop:"4px",fontSize:"0.95rem",fontWeight:500},children:"Earn your rewards. Every single day."})]}),l.jsxs("div",{style:{background:"var(--card)",borderRadius:"var(--r-lg)",padding:"28px",boxShadow:"0 20px 60px rgba(0,0,0,0.3)"},children:[l.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"4px",background:"rgba(0,0,0,0.04)",borderRadius:"var(--r)",padding:"4px",marginBottom:"24px"},children:["login","register"].map(R=>l.jsx("button",{type:"button",onClick:()=>c(R),style:{borderRadius:"var(--r-sm)",padding:"10px",fontWeight:700,fontSize:"0.85rem",background:o===R?"var(--accent)":"transparent",color:o===R?"#fff":"var(--text-2)",boxShadow:o===R?"var(--shadow-accent)":"none"},children:R==="login"?"Sign In":"Sign Up"},R))}),S&&l.jsx("div",{className:"error-msg",children:S}),l.jsxs("form",{onSubmit:A,children:[l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Username"}),l.jsx("input",{value:s,onChange:R=>d(R.target.value),required:!0,autoComplete:"username"})]}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Password"}),l.jsx("input",{type:"password",value:p,onChange:R=>y(R.target.value),required:!0,autoComplete:"current-password"})]}),o==="register"&&l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Display Name"}),l.jsx("input",{value:g,onChange:R=>P(R.target.value),placeholder:"What should we call you?"})]}),l.jsx("button",{type:"submit",className:"btn-primary btn-full",disabled:z,style:{padding:"14px",fontSize:"0.95rem",marginTop:"8px",borderRadius:"var(--r)"},children:z?"...":o==="login"?"Sign In":"Create Account"})]})]})]})})}function Yl({text:o,children:c}){const[s,d]=m.useState(!1);return l.jsxs("span",{style:{position:"relative",display:"inline-flex",alignItems:"center"},children:[c,l.jsx("span",{onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),onClick:p=>{p.stopPropagation(),d(y=>!y)},style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:"18px",height:"18px",borderRadius:"50%",marginLeft:"6px",background:"rgba(0,0,0,0.06)",color:"var(--text-3)",cursor:"help",fontSize:"0.7rem",fontWeight:800,flexShrink:0},children:"?"}),s&&l.jsx("span",{style:{position:"absolute",bottom:"calc(100% + 8px)",left:"50%",transform:"translateX(-50%)",background:"var(--text)",color:"#fff",padding:"10px 14px",borderRadius:"var(--r-sm)",fontSize:"0.78rem",lineHeight:1.45,fontWeight:500,width:"240px",boxShadow:"var(--shadow-3)",zIndex:50,pointerEvents:"none"},children:o})]})}function mm(){var _,W;const[o,c]=m.useState(null),[s,d]=m.useState(null),[p,y]=m.useState(!0),[g,P]=m.useState(null),S=Ge();m.useEffect(()=>{T()},[]);async function T(){try{const[B,Z]=await Promise.all([J.today(),J.integrationStatus()]);c(B),d(Z)}catch(B){console.error(B)}finally{y(!1)}}async function z(B){P(B);try{const Z=await(B==="strava"?J.stravaSync:J.polarSync)();await T(),Z.imported>0?alert(`Synced ${Z.imported} activities from ${B}!`):alert(`No new activities found on ${B}.`)}catch(Z){alert(`Sync failed: ${Z.message}`)}finally{P(null)}}async function v(B){try{const Z=await(B==="strava"?J.stravaAuth:J.polarAuth)();window.location.href=Z.auth_url}catch(Z){alert(`Connect failed: ${Z.message}`)}}if(p)return l.jsx("div",{className:"page",children:l.jsx("div",{className:"loading",children:"Loading..."})});if(!o)return l.jsx("div",{className:"page",children:l.jsx("div",{className:"error-msg",children:"Failed to load"})});const L=o.daily_minimum>0?Math.min(100,Math.round(o.points_earned/o.daily_minimum*100)):0,A=o.weekly_target>0?Math.min(100,Math.round(o.week_points/o.weekly_target*100)):0,R=new Set(o.activities_today.map(B=>B.category)),N=(_=s==null?void 0:s.strava)==null?void 0:_.connected,j=(W=s==null?void 0:s.polar)==null?void 0:W.connected,F=[{key:"workout",label:"Workout",icon:"💪",pts:50,color:"var(--accent)",tip:"Any exercise session — running, weights, yoga, etc. Logged manually or synced from Strava/Polar."},{key:"food_log",label:"Food logged",icon:"🥗",pts:30,color:"var(--green)",tip:"Log what you eat. Barcode scan or manual entry. Building food awareness is a key habit."},{key:"steps_target",label:"Steps target",icon:"👟",pts:20,color:"#2979FF",tip:"Hit your daily step goal. Steps are the foundation of an active lifestyle."},{key:"screen_free",label:"Screen-free",icon:"📖",pts:"20/hr",color:"#7C4DFF",tip:"Time away from screens — reading, walking, hobbies. Points scale with hours logged."},{key:"daily_checkin",label:"Check-in",icon:"✅",pts:10,color:"#00BCD4",tip:"Just show up and check in. The easiest points — consistency matters more than intensity."}];return l.jsxs("div",{className:"page",children:[o.program_name&&l.jsxs("div",{onClick:()=>o.program_id&&S(`/programs/${o.program_id}`),style:{background:"var(--accent-bg)",borderRadius:"var(--r)",padding:"12px 16px",marginBottom:"14px",display:"flex",alignItems:"center",gap:"12px",border:"1px solid rgba(41,121,255,0.1)",cursor:o.program_id?"pointer":"default"},children:[l.jsx("div",{style:{fontSize:"1.1rem"},children:"📋"}),l.jsxs("div",{style:{flex:1},children:[l.jsx("div",{style:{fontSize:"0.78rem",fontWeight:700,color:"var(--accent)"},children:o.program_name}),l.jsx("div",{className:"progress-bar",style:{height:"5px",marginTop:"4px"},children:l.jsx("div",{className:"progress-bar-fill",style:{width:`${Math.round(o.program_day/o.program_total_days*100)}%`,background:"var(--accent)"}})})]}),l.jsxs("div",{style:{fontFamily:"var(--font-display)",fontWeight:800,fontSize:"0.85rem",color:"var(--accent)",whiteSpace:"nowrap"},children:[o.program_day,"/",o.program_total_days]})]}),l.jsxs("div",{className:`gate-banner ${o.gate_passed?"gate-earned":"gate-locked"}`,children:[l.jsx("div",{className:"section-label",style:{marginBottom:"4px"},children:l.jsx(Yl,{text:`Hit ${o.daily_minimum} points to unlock your rewards for today. Points reset weekly. This is your daily "gate" — earn first, enjoy second.`,children:"Today"})}),l.jsxs("div",{className:"gate-pts",children:[l.jsx("span",{style:{color:o.gate_passed?"var(--green)":"var(--accent)"},children:o.points_earned}),l.jsxs("span",{style:{fontFamily:"var(--font)",fontSize:"1rem",fontWeight:600,color:"var(--text-3)"},children:["/",o.daily_minimum]})]}),l.jsx("div",{className:"progress-bar",style:{marginTop:"12px",height:"12px"},children:l.jsx("div",{className:"progress-bar-fill",style:{width:`${L}%`,background:o.gate_passed?"linear-gradient(90deg, #00C853, #69F0AE)":"linear-gradient(90deg, var(--accent), var(--accent-light))"}})}),l.jsx("div",{style:{marginTop:"12px",fontSize:"0.88rem",fontWeight:700},children:o.gate_passed?l.jsx("span",{style:{color:"var(--green-dark)"},children:"✨ Rewards unlocked!"}):l.jsxs("span",{style:{color:"var(--text-2)"},children:["🔒 ",o.points_remaining," more to unlock"]})})]}),l.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"10px",marginBottom:"14px"},children:[l.jsx("button",{className:"btn-primary btn-full",onClick:()=>S("/log"),style:{padding:"14px",fontSize:"0.9rem"},children:"+ Log Activity"}),l.jsx("button",{className:"btn-outline btn-full",onClick:()=>S("/food"),style:{padding:"14px",fontSize:"0.9rem"},children:"🍽️ Log Food"})]}),l.jsxs("div",{className:"card",children:[l.jsx("div",{className:"section-label",children:"Activities"}),F.map(B=>{const Z=R.has(B.key);return l.jsxs("div",{className:"checklist-item",style:{opacity:Z?1:.6},children:[l.jsx("span",{style:{width:"32px",height:"32px",borderRadius:"8px",background:Z?B.color:"rgba(0,0,0,0.04)",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"0.9rem",transition:"all 0.3s"},children:Z?"✓":B.icon}),l.jsx("span",{style:{fontWeight:600,fontSize:"0.88rem"},children:l.jsx(Yl,{text:B.tip,children:B.label})}),l.jsxs("span",{className:"checklist-points",children:["+",B.pts]})]},B.key)})]}),l.jsxs("div",{className:"card",style:{background:"var(--accent-bg)"},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px"},children:[l.jsx("div",{className:"section-label",style:{margin:0},children:l.jsx(Yl,{text:`Earn ${o.weekly_target} total points across the week for a bonus. Consistent daily effort beats one big day.`,children:"This Week"})}),l.jsx(Gc,{to:"/week",style:{fontSize:"0.8rem"},children:"Details →"})]}),l.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"4px",marginBottom:"8px"},children:[l.jsx("span",{style:{fontFamily:"var(--font-display)",fontWeight:900,fontSize:"1.4rem"},children:o.week_points}),l.jsxs("span",{style:{fontSize:"0.85rem",color:"var(--text-3)",fontWeight:600},children:["/ ",o.weekly_target," pts"]})]}),l.jsx("div",{className:"progress-bar",children:l.jsx("div",{className:"progress-bar-fill",style:{width:`${A}%`,background:"linear-gradient(90deg, #7C4DFF, #B388FF)"}})})]}),o.gate_passed&&o.rewards_available.length>0&&l.jsxs("div",{className:"card",style:{background:"var(--green-bg)",border:"2px solid rgba(0,200,83,0.15)"},children:[l.jsx("div",{className:"section-label",style:{color:"var(--green-dark)"},children:"🎮 Rewards Available"}),o.rewards_available.map(B=>l.jsxs("div",{className:"reward-card",children:[l.jsxs("div",{children:[l.jsx("div",{style:{fontWeight:700},children:B.name}),l.jsxs("div",{style:{fontSize:"0.78rem",color:"var(--text-3)",fontWeight:600},children:[B.point_cost," pts"]})]}),l.jsx("button",{className:"btn-success btn-sm",onClick:async()=>{try{await J.redeemReward(B.id),await T()}catch(Z){alert(Z.message)}},children:"Redeem"})]},B.id))]}),l.jsxs("div",{className:"card",children:[l.jsx("div",{className:"section-label",children:l.jsx(Yl,{text:"Connect your fitness trackers to automatically import workouts. Go to Settings → Integrations to connect.",children:"Integrations"})}),l.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[N?l.jsx("button",{className:"btn-outline btn-sm btn-full",onClick:()=>z("strava"),disabled:g==="strava",children:g==="strava"?"⏳ Syncing...":"🔄 Sync Strava"}):l.jsx("button",{className:"btn-ghost btn-sm btn-full",onClick:()=>v("strava"),style:{border:"2px dashed var(--divider)"},children:"🔗 Connect Strava"}),j?l.jsx("button",{className:"btn-outline btn-sm btn-full",onClick:()=>z("polar"),disabled:g==="polar",children:g==="polar"?"⏳ Syncing...":"🔄 Sync Polar"}):l.jsx("button",{className:"btn-ghost btn-sm btn-full",onClick:()=>v("polar"),style:{border:"2px dashed var(--divider)"},children:"🔗 Connect Polar"})]})]})]})}const Cc=[{value:"workout",label:"Workout",icon:"💪",desc:"Any exercise session",color:"var(--accent)"},{value:"steps_target",label:"Steps",icon:"👟",desc:"Hit your daily goal",color:"#2979FF"},{value:"screen_free",label:"Screen-Free",icon:"📖",desc:"Reading, outdoors",color:"#7C4DFF"},{value:"daily_checkin",label:"Check-in",icon:"✅",desc:"Just show up",color:"#00BCD4"}];function hm(){const[o,c]=m.useState(""),[s,d]=m.useState(""),[p,y]=m.useState(""),[g,P]=m.useState(""),[S,T]=m.useState(!1),[z,v]=m.useState(""),[L,A]=m.useState(null),[R,N]=m.useState(null),[j,F]=m.useState([]),[_,W]=m.useState(null),B=Ge();m.useEffect(()=>{Z()},[]);async function Z(){try{const oe=(await J.listPrograms()||[]).find(ve=>ve.status==="active"&&ve.catalog_id);if(!oe)return;A(oe);const pe=await J.getProgramSchedule(oe.id);pe.today_workout&&!pe.today_workout.rest_day&&!pe.today_workout.completed&&N(pe.today_workout);const Ne=(pe.schedule||[]).filter(ve=>{var Te;return ve.week_number===pe.current_week&&!ve.rest_day&&!ve.completed&&ve.id!==((Te=pe.today_workout)==null?void 0:Te.id)}).slice(0,3);F(Ne)}catch(re){console.warn("Could not load active program:",re.message)}}async function fe(re){if(!(!L||!re||_)){W(re.id);try{const oe=await J.completeWorkout(L.id,re.id,{});let Ne=`+${oe.total_points||oe.points_earned} points!`;oe.weekly_bonus>0&&(Ne+=" (week bonus!)"),oe.completion_bonus>0&&(Ne+=" (program complete!)"),v(Ne),setTimeout(()=>B("/"),1500)}catch(oe){alert(oe.message),W(null)}}}async function we(re){var oe;if(re.preventDefault(),!!o){T(!0);try{const pe=new Date().toISOString().split("T")[0],Ne=await J.logActivity({category:o,title:s||((oe=Cc.find(ve=>ve.value===o))==null?void 0:oe.label),description:g||null,duration_minutes:p?parseInt(p):null,activity_date:pe});v(`+${Ne.points_earned} points!`),c(""),d(""),y(""),P(""),setTimeout(()=>B("/"),1200)}catch(pe){alert(pe.message)}finally{T(!1)}}}const xe=o==="workout"&&L;return l.jsxs("div",{className:"page",children:[l.jsx("h1",{className:"page-title",children:"Log Activity"}),z&&l.jsxs("div",{style:{textAlign:"center",padding:"24px",marginBottom:"14px",background:"var(--green-bg)",borderRadius:"var(--r-lg)",border:"2px solid rgba(0,200,83,0.15)"},children:[l.jsx("div",{style:{fontSize:"2rem",marginBottom:"4px"},children:"🎉"}),l.jsx("div",{style:{fontFamily:"var(--font-display)",fontWeight:900,fontSize:"1.3rem",color:"var(--green-dark)"},children:z})]}),l.jsxs("div",{style:{marginBottom:"18px"},children:[l.jsx("div",{className:"section-label",children:"What did you do?"}),l.jsx("div",{className:"option-grid",children:Cc.map(re=>l.jsxs("div",{className:`option-btn ${o===re.value?"selected":""}`,onClick:()=>c(re.value),style:o===re.value?{borderColor:re.color,background:re.color+"0A"}:{},children:[l.jsx("div",{style:{fontSize:"1.5rem",marginBottom:"6px"},children:re.icon}),l.jsx("div",{style:{fontWeight:800,fontSize:"0.85rem"},children:re.label}),l.jsx("div",{style:{fontSize:"0.72rem",color:"var(--text-3)",marginTop:"2px",fontWeight:400},children:re.desc})]},re.value))})]}),xe&&l.jsxs("div",{style:{animation:"fadeUp 0.25s ease-out",marginBottom:"18px"},children:[l.jsxs("div",{onClick:()=>B(`/programs/${L.id}`),style:{background:"var(--accent-bg)",borderRadius:"var(--r-sm)",padding:"10px 14px",marginBottom:"12px",display:"flex",alignItems:"center",justifyContent:"space-between",cursor:"pointer",border:"1px solid rgba(41,121,255,0.15)"},children:[l.jsxs("div",{children:[l.jsx("div",{style:{fontSize:"0.7rem",fontWeight:700,color:"var(--accent)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Active Program"}),l.jsx("div",{style:{fontWeight:800,fontSize:"0.92rem",color:"var(--text-1)"},children:L.name})]}),l.jsxs("div",{style:{fontSize:"0.78rem",color:"var(--accent)",fontWeight:700},children:["Week ",L.current_week||1," →"]})]}),R&&l.jsx(Nc,{workout:R,featured:!0,completing:_===R.id,onComplete:()=>fe(R)}),j.length>0&&l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"section-label",style:{marginTop:"14px",marginBottom:"8px"},children:R?"Or another from this week":"Workouts this week"}),j.map(re=>l.jsx(Nc,{workout:re,completing:_===re.id,onComplete:()=>fe(re)},re.id))]}),!R&&j.length===0&&l.jsx("div",{style:{padding:"14px",borderRadius:"var(--r-sm)",background:"var(--green-bg)",color:"var(--green-dark)",fontSize:"0.85rem",textAlign:"center",fontWeight:600},children:"✓ All workouts for this week are complete. Log a freeform workout below or rest up."}),l.jsx("div",{style:{textAlign:"center",color:"var(--text-3)",fontSize:"0.78rem",margin:"14px 0 6px",textTransform:"uppercase",letterSpacing:"0.06em",fontWeight:700},children:"— or log freeform —"})]}),o&&l.jsxs("form",{onSubmit:we,className:"card",style:{animation:"fadeUp 0.25s ease-out"},children:[l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Title (optional)"}),l.jsx("input",{value:s,onChange:re=>d(re.target.value),placeholder:"e.g. Morning run, evening yoga"})]}),(o==="workout"||o==="screen_free")&&l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Duration (minutes)"}),l.jsx("input",{type:"number",value:p,onChange:re=>y(re.target.value),placeholder:"30"})]}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Notes (optional)"}),l.jsx("textarea",{value:g,onChange:re=>P(re.target.value),rows:2,placeholder:"How did it go?"})]}),l.jsx("button",{type:"submit",className:"btn-primary btn-full",disabled:S,style:{borderRadius:"var(--r)"},children:S?"Saving...":"Log Activity"})]})]})}function Nc({workout:o,featured:c,completing:s,onComplete:d}){return l.jsxs("div",{style:{background:"var(--card)",borderRadius:"var(--r)",padding:"14px",marginBottom:"10px",boxShadow:"var(--shadow-1)",border:c?"2px solid var(--accent-glow)":"1px solid var(--divider)"},children:[c&&l.jsx("div",{style:{fontSize:"0.65rem",fontWeight:800,color:"var(--accent)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:"4px"},children:"⭐ Today"}),l.jsx("div",{style:{fontFamily:"var(--font-display)",fontWeight:800,fontSize:"1rem",marginBottom:"2px"},children:o.workout_name||`Day ${o.day_number}`}),l.jsxs("div",{style:{fontSize:"0.74rem",color:"var(--text-3)",marginBottom:"10px"},children:["Week ",o.week_number," · Day ",o.day_number," · ",(o.exercises||[]).length," exercises"]}),l.jsx("div",{style:{background:"var(--bg-warm)",borderRadius:"var(--r-sm)",padding:"8px 10px",marginBottom:"10px"},children:(o.exercises||[]).slice(0,4).map((p,y)=>l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:"0.76rem",padding:"2px 0",color:"var(--text-2)"},children:[l.jsx("span",{children:p.name}),l.jsx("span",{style:{color:"var(--text-3)",fontWeight:600},children:p.sets&&p.reps&&`${p.sets}×${p.reps}`})]},y))}),l.jsx("button",{onClick:d,disabled:s,style:{width:"100%",background:s?"var(--text-3)":"var(--green)",color:"#fff",padding:"11px",fontWeight:800,fontSize:"0.88rem",boxShadow:s?"none":"var(--shadow-green)"},children:s?"Logging...":"✓ Complete — 75 pts"})]})}const Ec=["breakfast","lunch","dinner","snack"];function gm(){const[o,c]=m.useState("log"),[s,d]=m.useState("lunch"),[p,y]=m.useState(""),[g,P]=m.useState(""),[S,T]=m.useState(""),[z,v]=m.useState(""),[L,A]=m.useState(""),[R,N]=m.useState(""),[j,F]=m.useState("1"),[_,W]=m.useState(""),[B,Z]=m.useState(""),[fe,we]=m.useState([]),[xe,re]=m.useState(null),[oe,pe]=m.useState(!1),[Ne,ve]=m.useState("");m.useEffect(()=>{Te()},[]);async function Te(){try{const I=new Date().toISOString().split("T")[0],V=await J.listFood(I);re(V)}catch(I){console.error(I)}}function Me(I){y(I.product_name||""),P(I.brand||""),T(I.calories_100g?String(Math.round(I.calories_100g)):""),v(I.protein_100g?String(Math.round(I.protein_100g)):""),A(I.carbs_100g?String(Math.round(I.carbs_100g)):""),N(I.fat_100g?String(Math.round(I.fat_100g)):""),c("log")}async function We(){if(_.trim()){pe(!0);try{const I=await J.scanBarcode(_.trim());Me(I)}catch{alert("Product not found. Try manual entry.")}finally{pe(!1)}}}async function Se(){if(B.trim()){pe(!0);try{const I=await J.searchFood(B);we(I.results||[])}catch(I){alert(I.message)}finally{pe(!1)}}}async function H(I){if(I.preventDefault(),!!p.trim()){pe(!0);try{const V=new Date().toISOString().split("T")[0];await J.logFood({meal_type:s,food_name:p,brand:g||null,calories:S?parseFloat(S)*parseFloat(j||1):null,protein_g:z?parseFloat(z)*parseFloat(j||1):null,carbs_g:L?parseFloat(L)*parseFloat(j||1):null,fat_g:R?parseFloat(R)*parseFloat(j||1):null,servings:parseFloat(j||1),food_date:V}),ve("Food logged!"),y(""),P(""),T(""),v(""),A(""),N(""),F("1"),await Te(),setTimeout(()=>ve(""),2e3)}catch(V){alert(V.message)}finally{pe(!1)}}}return l.jsxs("div",{className:"page",children:[l.jsx("h1",{className:"page-title",children:"Food Log"}),Ne&&l.jsx("div",{style:{padding:"12px",background:"var(--green-bg)",borderRadius:"var(--radius-sm)",color:"var(--green-dark)",textAlign:"center",marginBottom:"12px",fontWeight:600},children:Ne}),l.jsxs("div",{style:{display:"flex",gap:"8px",marginBottom:"16px"},children:[l.jsx("button",{className:o==="log"?"btn-primary btn-sm":"btn-outline btn-sm",onClick:()=>c("log"),children:"Manual"}),l.jsx("button",{className:o==="scan"?"btn-primary btn-sm":"btn-outline btn-sm",onClick:()=>c("scan"),children:"📷 Scan"}),l.jsx("button",{className:o==="search"?"btn-primary btn-sm":"btn-outline btn-sm",onClick:()=>c("search"),children:"🔍 Search"})]}),o==="scan"&&l.jsxs("div",{className:"card",children:[l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Barcode number"}),l.jsx("input",{value:_,onChange:I=>W(I.target.value),placeholder:"Enter or scan barcode",inputMode:"numeric"})]}),l.jsx("button",{className:"btn-primary btn-full",onClick:We,disabled:oe,children:oe?"Looking up...":"Lookup"}),l.jsx("p",{style:{fontSize:"0.8rem",color:"var(--text-3)",marginTop:"8px",textAlign:"center"},children:"Powered by Open Food Facts (4M+ products)"})]}),o==="search"&&l.jsxs("div",{className:"card",children:[l.jsxs("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:[l.jsx("input",{value:B,onChange:I=>Z(I.target.value),placeholder:"Search foods...",onKeyDown:I=>I.key==="Enter"&&Se()}),l.jsx("button",{className:"btn-primary btn-sm",onClick:Se,disabled:oe,children:"Go"})]}),fe.map((I,V)=>l.jsxs("div",{style:{padding:"10px 0",borderBottom:"1px solid var(--divider)",cursor:"pointer"},onClick:()=>Me(I),children:[l.jsx("div",{style:{fontWeight:600,fontSize:"0.9rem"},children:I.product_name||"Unknown"}),l.jsxs("div",{style:{fontSize:"0.8rem",color:"var(--text-3)"},children:[I.brand&&`${I.brand} · `,I.calories_100g?`${Math.round(I.calories_100g)} cal/100g`:""]})]},V))]}),o==="log"&&l.jsx("form",{onSubmit:H,children:l.jsxs("div",{className:"card",children:[l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Meal"}),l.jsx("div",{style:{display:"flex",gap:"6px"},children:Ec.map(I=>l.jsx("button",{type:"button",className:s===I?"btn-primary btn-sm":"btn-outline btn-sm",onClick:()=>d(I),children:I.charAt(0).toUpperCase()+I.slice(1)},I))})]}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Food name"}),l.jsx("input",{value:p,onChange:I=>y(I.target.value),placeholder:"e.g. Grilled chicken breast",required:!0})]}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Brand (optional)"}),l.jsx("input",{value:g,onChange:I=>P(I.target.value),placeholder:""})]}),l.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"10px"},children:[l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Calories"}),l.jsx("input",{type:"number",value:S,onChange:I=>T(I.target.value),placeholder:"per serving"})]}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Servings"}),l.jsx("input",{type:"number",step:"0.5",value:j,onChange:I=>F(I.target.value)})]}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Protein (g)"}),l.jsx("input",{type:"number",value:z,onChange:I=>v(I.target.value)})]}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Carbs (g)"}),l.jsx("input",{type:"number",value:L,onChange:I=>A(I.target.value)})]}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Fat (g)"}),l.jsx("input",{type:"number",value:R,onChange:I=>N(I.target.value)})]})]}),l.jsx("button",{type:"submit",className:"btn-primary btn-full",disabled:oe,children:oe?"Saving...":"Log Food"})]})}),xe&&l.jsxs("div",{className:"card",style:{marginTop:"8px"},children:[l.jsxs("div",{style:{fontFamily:"var(--font-display)",fontWeight:800,marginBottom:"10px"},children:["Today: ",Math.round(xe.total_calories)," cal"]}),Ec.map(I=>{const V=xe.meals[I]||[];return V.length===0?null:l.jsxs("div",{className:"meal-section",children:[l.jsx("div",{className:"meal-title",children:I}),V.map(w=>l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",padding:"4px 0",fontSize:"0.9rem"},children:[l.jsx("span",{children:w.food_name}),l.jsx("span",{style:{color:"var(--text-3)"},children:w.calories?`${Math.round(w.calories)} cal`:""})]},w.id))]},I)})]})]})}const Pc=[{label:"16:8 Daily",hours:16,type:"daily"},{label:"18:6",hours:18,type:"daily"},{label:"20:4",hours:20,type:"daily"},{label:"24h Weekly",hours:24,type:"weekly_24"},{label:"48h",hours:48,type:"long_48"},{label:"72h Kickoff",hours:72,type:"long_72"}];function Gl({label:o,value:c,target:s,unit:d,color:p,inverse:y}){const g=s>0?Math.min(100,Math.round(c/s*100)):0,P=y?c<=s:c>=s*.85;return l.jsxs("div",{style:{marginBottom:"14px"},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"4px",fontSize:"0.85rem"},children:[l.jsx("span",{style:{fontWeight:700},children:o}),l.jsxs("span",{style:{color:P?"var(--green-dark)":"var(--text-3)",fontWeight:600},children:[Math.round(c),y?"":` / ${s}`," ",d,y&&` / ${s} cap`]})]}),l.jsx("div",{className:"progress-bar",style:{height:"8px"},children:l.jsx("div",{className:"progress-bar-fill",style:{width:`${g}%`,background:y?c<=s?"var(--green)":"var(--red)":p}})})]})}function vm({fast:o}){const[,c]=m.useState(0);m.useEffect(()=>{const P=setInterval(()=>c(S=>S+1),6e4);return()=>clearInterval(P)},[]);const s=(new Date-new Date(o.started_at))/1e3/3600,d=Math.min(100,s/o.target_hours*100),p=s>=o.target_hours,y=Math.floor(s),g=Math.floor((s-y)*60);return l.jsxs("div",{children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"8px"},children:[l.jsxs("span",{style:{fontFamily:"var(--font-display)",fontWeight:900,fontSize:"1.6rem"},children:[y,"h ",g,"m"]}),l.jsxs("span",{style:{fontSize:"0.85rem",color:"var(--text-3)",fontWeight:600},children:["/ ",o.target_hours,"h target"]})]}),l.jsx("div",{className:"progress-bar",style:{height:"12px"},children:l.jsx("div",{className:"progress-bar-fill",style:{width:`${d}%`,background:p?"linear-gradient(90deg, #00C853, #69F0AE)":"linear-gradient(90deg, #7C4DFF, #B388FF)"}})}),p&&l.jsx("div",{style:{marginTop:"8px",fontSize:"0.9rem",color:"var(--green-dark)",fontWeight:700},children:"✓ Target reached — you can end now or push further"})]})}function ym(){const[o,c]=m.useState(null),[s,d]=m.useState(null),[p,y]=m.useState(!0),[g,P]=m.useState(Pc[0]),[S,T]=m.useState(!1),z=Ge();m.useEffect(()=>{v()},[]);async function v(){try{const[W,B]=await Promise.all([J.nutritionToday(),J.getElectrolytesToday()]);c(W),d(B)}catch(W){console.error(W)}finally{y(!1)}}async function L(){T(!0);try{await J.startFast({target_hours:g.hours,fast_type:g.type}),await v()}catch(W){alert(W.message)}finally{T(!1)}}async function A(){if(confirm("End this fast now?")){T(!0);try{const W=await J.endFast(o.active_fast.id);alert(`Fast ended. +${W.points_awarded} pts earned.`),await v()}catch(W){alert(W.message)}finally{T(!1)}}}async function R(W){const B={morning:{sodium_mg:2300,potassium_mg:800,magnesium_mg:0,notes:"Morning drink"},midday:{sodium_mg:2300,potassium_mg:800,magnesium_mg:0,notes:"Midday drink"},mag_pm:{sodium_mg:0,potassium_mg:0,magnesium_mg:400,notes:"Magnesium glycinate PM"}};try{await J.logElectrolytes(B[W]),await v()}catch(Z){alert(Z.message)}}if(p)return l.jsx("div",{className:"page",children:l.jsx("div",{className:"loading",children:"Loading..."})});if(!o)return l.jsx("div",{className:"page",children:l.jsx("div",{className:"error-msg",children:"Failed to load"})});const N=o.macros,j=o.targets,F=o.compliance,_=o.eating_window;return l.jsxs("div",{className:"page",children:[l.jsx("h1",{className:"page-title",children:"Nutrition"}),l.jsxs("div",{className:`gate-banner ${F.compliant_day?"gate-earned":"gate-locked"}`,children:[l.jsx("div",{className:"section-label",style:{marginBottom:"4px"},children:"Today's Keto Day"}),l.jsx("div",{style:{fontFamily:"var(--font-display)",fontWeight:900,fontSize:"1.4rem",color:F.compliant_day?"var(--green)":"var(--accent)"},children:F.compliant_day?"✓ Compliant":"⏳ In progress"}),l.jsxs("div",{style:{fontSize:"0.82rem",color:"var(--text-2)",marginTop:"6px"},children:[F.carb_ok?"✓":"✗"," Net carbs under cap  · ",F.protein_ok?"✓":"✗"," Protein target"]})]}),l.jsxs("div",{className:"card",children:[l.jsx("div",{className:"section-label",children:"Fasting"}),o.active_fast?l.jsxs("div",{children:[l.jsxs("div",{style:{fontSize:"0.8rem",color:"var(--text-3)",marginBottom:"8px"},children:[o.active_fast.fast_type.replace("_"," ")," fast in progress"]}),l.jsx(vm,{fast:o.active_fast}),l.jsx("button",{className:"btn-outline btn-full",onClick:A,disabled:S,style:{marginTop:"14px"},children:"End Fast"})]}):l.jsxs("div",{children:[l.jsxs("div",{style:{marginBottom:"10px",fontSize:"0.85rem",color:"var(--text-2)"},children:["Eating window: ",l.jsx("strong",{children:_.display}),_.in_window_now?l.jsx("span",{style:{color:"var(--green-dark)",marginLeft:"8px"},children:"● open"}):l.jsx("span",{style:{color:"var(--text-3)",marginLeft:"8px"},children:"○ closed"})]}),l.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:"6px",marginBottom:"12px"},children:Pc.map(W=>l.jsx("button",{className:g.hours===W.hours?"btn-primary btn-sm":"btn-outline btn-sm",onClick:()=>P(W),children:W.label},W.hours))}),l.jsxs("button",{className:"btn-primary btn-full",onClick:L,disabled:S,children:["Start ",g.label," Fast"]})]})]}),l.jsxs("div",{className:"card",children:[l.jsx("div",{className:"section-label",children:"Today's Macros"}),l.jsx(Gl,{label:"Net carbs",value:N.net_carbs_g,target:j.net_carbs_cap,unit:"g",inverse:!0}),l.jsx(Gl,{label:"Protein",value:N.protein_g,target:j.protein_g,unit:"g",color:"var(--accent)"}),l.jsx(Gl,{label:"Fat",value:N.fat_g,target:j.fat_g,unit:"g",color:"#FFA726"}),l.jsx(Gl,{label:"Calories",value:N.calories,target:j.calories,unit:"kcal",color:"#2979FF"}),l.jsx("button",{className:"btn-outline btn-full btn-sm",onClick:()=>z("/food"),style:{marginTop:"8px"},children:"+ Log Food"})]}),s&&l.jsxs("div",{className:"card",children:[l.jsx("div",{className:"section-label",children:"Electrolytes Today"}),l.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:"10px",marginBottom:"12px"},children:[l.jsxs("div",{style:{textAlign:"center"},children:[l.jsx("div",{style:{fontSize:"0.72rem",color:"var(--text-3)",fontWeight:700},children:"SODIUM"}),l.jsx("div",{style:{fontFamily:"var(--font-display)",fontWeight:900,fontSize:"1.1rem"},children:s.sodium_mg}),l.jsxs("div",{style:{fontSize:"0.7rem",color:"var(--text-3)"},children:["/ ",s.targets.sodium_mg,"mg"]})]}),l.jsxs("div",{style:{textAlign:"center"},children:[l.jsx("div",{style:{fontSize:"0.72rem",color:"var(--text-3)",fontWeight:700},children:"POTASSIUM"}),l.jsx("div",{style:{fontFamily:"var(--font-display)",fontWeight:900,fontSize:"1.1rem"},children:s.potassium_mg}),l.jsxs("div",{style:{fontSize:"0.7rem",color:"var(--text-3)"},children:["/ ",s.targets.potassium_mg,"mg"]})]}),l.jsxs("div",{style:{textAlign:"center"},children:[l.jsx("div",{style:{fontSize:"0.72rem",color:"var(--text-3)",fontWeight:700},children:"MAGNESIUM"}),l.jsx("div",{style:{fontFamily:"var(--font-display)",fontWeight:900,fontSize:"1.1rem"},children:s.magnesium_mg}),l.jsxs("div",{style:{fontSize:"0.7rem",color:"var(--text-3)"},children:["/ ",s.targets.magnesium_mg,"mg"]})]})]}),l.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:"6px"},children:[l.jsx("button",{className:"btn-outline btn-sm",onClick:()=>R("morning"),children:"+ Morning"}),l.jsx("button",{className:"btn-outline btn-sm",onClick:()=>R("midday"),children:"+ Midday"}),l.jsx("button",{className:"btn-outline btn-sm",onClick:()=>R("mag_pm"),children:"+ Mag PM"})]})]})]})}function xm(){const[o,c]=m.useState([]),[s,d]=m.useState(""),[p,y]=m.useState("100"),[g,P]=m.useState(null),[S,T]=m.useState(!0);m.useEffect(()=>{z()},[]);async function z(){try{const[A,R]=await Promise.all([J.listRewards(),J.today()]);c(A),P(R)}catch(A){console.error(A)}finally{T(!1)}}async function v(A){if(A.preventDefault(),!!s.trim())try{await J.createReward({name:s,point_cost:parseInt(p)||100}),d(""),y("100"),await z()}catch(R){alert(R.message)}}async function L(A){try{await J.redeemReward(A),await z()}catch(R){alert(R.message)}}return S?l.jsx("div",{className:"page",children:l.jsx("div",{className:"loading",children:"Loading..."})}):l.jsxs("div",{className:"page",children:[l.jsx("h1",{className:"page-title",children:"🎮 Rewards"}),g&&l.jsxs("div",{className:`gate-banner ${g.gate_passed?"gate-earned":"gate-locked"}`,style:{padding:"18px",marginBottom:"14px"},children:[l.jsx("div",{style:{fontWeight:800,fontSize:"1rem",fontFamily:"var(--font-display)"},children:g.gate_passed?l.jsx("span",{style:{color:"var(--green-dark)"},children:"✨ Rewards Unlocked"}):l.jsxs("span",{style:{color:"var(--text-2)"},children:["🔒 Earn ",g.points_remaining," more pts"]})}),l.jsxs("div",{style:{fontSize:"0.82rem",color:"var(--text-3)",fontWeight:600,marginTop:"2px"},children:[g.points_earned," / ",g.daily_minimum," pts today"]})]}),l.jsxs("div",{className:"card",children:[l.jsx("div",{className:"section-label",children:"Your Rewards"}),o.length===0&&l.jsx("div",{style:{textAlign:"center",color:"var(--text-3)",padding:"20px",fontWeight:500},children:"No rewards yet — add one below!"}),o.map(A=>l.jsxs("div",{className:"reward-card",children:[l.jsxs("div",{children:[l.jsx("div",{style:{fontWeight:700,fontSize:"0.95rem"},children:A.name}),l.jsxs("div",{style:{fontSize:"0.78rem",color:"var(--text-3)",fontWeight:600},children:[A.point_cost," pts"]})]}),l.jsx("button",{className:g!=null&&g.gate_passed?"btn-success btn-sm":"btn-outline btn-sm",disabled:!(g!=null&&g.gate_passed),onClick:()=>L(A.id),style:{opacity:g!=null&&g.gate_passed?1:.4},children:g!=null&&g.gate_passed?"Redeem":"Locked"})]},A.id))]}),l.jsxs("div",{className:"card",children:[l.jsx("div",{className:"section-label",children:"Add New Reward"}),l.jsxs("form",{onSubmit:v,children:[l.jsxs("div",{style:{display:"grid",gridTemplateColumns:"2fr 1fr",gap:"10px",marginBottom:"10px"},children:[l.jsx("input",{value:s,onChange:A=>d(A.target.value),placeholder:"e.g. 1hr gaming",required:!0}),l.jsx("input",{type:"number",value:p,onChange:A=>y(A.target.value),placeholder:"pts"})]}),l.jsx("button",{type:"submit",className:"btn-primary btn-full btn-sm",children:"Add Reward"})]})]})]})}function Sm(){const[o,c]=m.useState(null),[s,d]=m.useState([]),[p,y]=m.useState(null),[g,P]=m.useState(null),[S,T]=m.useState(!0),z=Ge();m.useEffect(()=>{v()},[]);async function v(){try{const[j,F,_,W]=await Promise.all([J.me(),J.getRules(),J.getTargets(),J.integrationStatus()]);c(j),d(F),y(_),P(W)}catch(j){console.error(j)}finally{T(!1)}}async function L(j,F){try{await J.updateRule(j,{points:parseInt(F)})}catch(_){alert(_.message)}}async function A(j,F){const _={[j]:parseInt(F)};try{await J.updateTargets(_),y({...p,..._})}catch(W){alert(W.message)}}async function R(j){try{const F=await(j==="strava"?J.stravaAuth:J.polarAuth)();window.location.href=F.auth_url}catch(F){alert(F.message)}}async function N(j){if(confirm(`Disconnect ${j}?`))try{await J.disconnect(j),await v()}catch(F){alert(F.message)}}return S?l.jsx("div",{className:"page",children:l.jsx("div",{className:"loading",children:"Loading..."})}):l.jsxs("div",{className:"page",children:[l.jsx("h1",{className:"page-title",children:"Settings"}),o&&l.jsxs("div",{className:"card",style:{display:"flex",alignItems:"center",gap:"14px"},children:[l.jsx("div",{style:{width:"48px",height:"48px",borderRadius:"14px",background:"linear-gradient(135deg, var(--accent), var(--accent-light))",display:"flex",alignItems:"center",justifyContent:"center",color:"#fff",fontFamily:"var(--font-display)",fontWeight:900,fontSize:"1.2rem"},children:o.display_name.charAt(0).toUpperCase()}),l.jsxs("div",{children:[l.jsx("div",{style:{fontWeight:700,fontSize:"1rem"},children:o.display_name}),l.jsxs("div",{style:{fontSize:"0.82rem",color:"var(--text-3)",fontWeight:500},children:["@",o.username]})]})]}),l.jsxs("div",{className:"card",children:[l.jsx("div",{className:"section-label",children:"Features"}),l.jsxs("div",{onClick:()=>z("/meal-plan"),style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 0",borderBottom:"1px solid var(--divider)",cursor:"pointer"},children:[l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[l.jsx("span",{style:{fontSize:"1.2rem"},children:"🍽️"}),l.jsxs("div",{children:[l.jsx("div",{style:{fontWeight:700,fontSize:"0.95rem"},children:"Meal Plans"}),l.jsx("div",{style:{fontSize:"0.78rem",color:"var(--text-3)",fontWeight:500},children:"AI-generated plans with compliance tracking"})]})]}),l.jsx("span",{style:{color:"var(--text-3)",fontSize:"1.1rem"},children:"›"})]}),l.jsxs("div",{onClick:()=>z("/settings/integrations"),style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 0",borderBottom:"1px solid var(--divider)",cursor:"pointer"},children:[l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[l.jsx("span",{style:{fontSize:"1.2rem"},children:"🔗"}),l.jsxs("div",{children:[l.jsx("div",{style:{fontWeight:700,fontSize:"0.95rem"},children:"All Integrations"}),l.jsx("div",{style:{fontSize:"0.78rem",color:"var(--text-3)",fontWeight:500},children:"Strava, Polar, Garmin, Fitbit, USDA, and more"})]})]}),l.jsx("span",{style:{color:"var(--text-3)",fontSize:"1.1rem"},children:"›"})]}),l.jsxs("div",{onClick:()=>z("/rewards"),style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 0",borderBottom:"1px solid var(--divider)",cursor:"pointer"},children:[l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[l.jsx("span",{style:{fontSize:"1.2rem"},children:"🎮"}),l.jsxs("div",{children:[l.jsx("div",{style:{fontWeight:700,fontSize:"0.95rem"},children:"Rewards"}),l.jsx("div",{style:{fontSize:"0.78rem",color:"var(--text-3)",fontWeight:500},children:"Configure and redeem your rewards"})]})]}),l.jsx("span",{style:{color:"var(--text-3)",fontSize:"1.1rem"},children:"›"})]}),l.jsxs("div",{onClick:()=>z("/week"),style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 0",cursor:"pointer"},children:[l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[l.jsx("span",{style:{fontSize:"1.2rem"},children:"📊"}),l.jsxs("div",{children:[l.jsx("div",{style:{fontWeight:700,fontSize:"0.95rem"},children:"Week View"}),l.jsx("div",{style:{fontSize:"0.78rem",color:"var(--text-3)",fontWeight:500},children:"Weekly progress and day-by-day breakdown"})]})]}),l.jsx("span",{style:{color:"var(--text-3)",fontSize:"1.1rem"},children:"›"})]})]}),l.jsxs("div",{className:"card",children:[l.jsx("div",{className:"section-label",children:"Point Rules"}),s.map(j=>l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 0",borderBottom:"1px solid var(--divider)"},children:[l.jsx("div",{style:{flex:1,fontSize:"0.88rem",fontWeight:600},children:j.description}),l.jsx("input",{type:"number",style:{width:"64px",textAlign:"center",padding:"8px",fontWeight:700},defaultValue:j.points,onBlur:F=>L(j.id,F.target.value)}),l.jsx("span",{style:{fontSize:"0.78rem",color:"var(--text-3)",fontWeight:600},children:"pts"})]},j.id))]}),p&&l.jsxs("div",{className:"card",children:[l.jsx("div",{className:"section-label",children:"Daily Targets"}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Daily minimum (unlock rewards)"}),l.jsx("input",{type:"number",defaultValue:p.daily_minimum_pts,onBlur:j=>A("daily_minimum_pts",j.target.value)})]}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Weekly target"}),l.jsx("input",{type:"number",defaultValue:p.weekly_target_pts,onBlur:j=>A("weekly_target_pts",j.target.value)})]}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Weekly bonus"}),l.jsx("input",{type:"number",defaultValue:p.weekly_bonus_pts,onBlur:j=>A("weekly_bonus_pts",j.target.value)})]})]}),l.jsxs("div",{className:"card",children:[l.jsx("div",{className:"section-label",children:"Integrations"}),["strava","polar"].map(j=>{const F=(g==null?void 0:g[j])||{connected:!1};return l.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 0",borderBottom:"1px solid var(--divider)"},children:[l.jsxs("div",{children:[l.jsx("div",{style:{fontWeight:700,textTransform:"capitalize",fontSize:"0.95rem"},children:j}),l.jsx("div",{style:{fontSize:"0.78rem",color:F.connected?"var(--green-dark)":"var(--text-3)",fontWeight:600},children:F.connected?"● Connected":"Not connected"})]}),F.connected?l.jsx("button",{className:"btn-outline btn-sm",onClick:()=>N(j),children:"Disconnect"}):l.jsx("button",{className:"btn-primary btn-sm",onClick:()=>R(j),children:"Connect"})]},j)}),l.jsx("div",{onClick:()=>z("/settings/integrations"),style:{padding:"12px 0",textAlign:"center",cursor:"pointer",color:"var(--accent)",fontSize:"0.88rem",fontWeight:600},children:"Configure all 11 providers →"})]}),l.jsx("button",{className:"btn-danger btn-full",style:{marginTop:"10px"},onClick:()=>{fm(),z("/login")},children:"Sign Out"})]})}function Ft({text:o,children:c}){const[s,d]=m.useState(!1);return l.jsxs("span",{style:{position:"relative",display:"inline-flex",alignItems:"center"},children:[c,l.jsx("span",{onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),onClick:p=>{p.stopPropagation(),d(y=>!y)},style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:"18px",height:"18px",borderRadius:"50%",marginLeft:"6px",background:"rgba(0,0,0,0.06)",color:"var(--text-3)",cursor:"help",fontSize:"0.7rem",fontWeight:800,flexShrink:0},children:"?"}),s&&l.jsx("span",{style:{position:"absolute",bottom:"calc(100% + 8px)",left:"50%",transform:"translateX(-50%)",background:"var(--text)",color:"#fff",padding:"10px 14px",borderRadius:"var(--r-sm)",fontSize:"0.78rem",lineHeight:1.45,fontWeight:500,width:"240px",boxShadow:"var(--shadow-3)",zIndex:50,pointerEvents:"none"},children:o})]})}const wm=[{value:"lose_weight",label:"Lose Weight",icon:"⚖️",tip:"Focus on caloric deficit through cardio and portion-controlled nutrition."},{value:"build_strength",label:"Build Strength",icon:"💪",tip:"Progressive overload training — gradually increasing weight or resistance."},{value:"get_active",label:"Get More Active",icon:"🏃",tip:"Building a consistent movement habit. Walking counts!"},{value:"feel_better",label:"Feel Better Overall",icon:"😊",tip:"Mind-body balance — stress relief, sleep quality, energy levels."}],jm=[{value:"precontemplation",label:"I'm not exercising and haven't thought about starting",tip:"Pre-contemplation: No intention to act. We'll start with awareness and gentle nudges."},{value:"contemplation",label:"I've been thinking about getting more active but haven't started",tip:"Contemplation: Weighing pros and cons. We'll help tip the balance toward action."},{value:"preparation",label:"I do some exercise but not consistently",tip:"Preparation: Ready to commit. We'll help you build a sustainable routine."},{value:"action",label:"I've been exercising regularly for a few months",tip:"Action: Building the habit. We'll help you stay consistent and avoid burnout."},{value:"maintenance",label:"I've been exercising regularly for 6+ months",tip:"Maintenance: Solid habit. We'll help you progress and keep things interesting."}],km=["Walking","Hiking","Running","Cycling","Swimming","Bodyweight","Weights","Yoga","Martial Arts","Dance","Team Sports","Pilates","Rowing","Jump Rope","Stretching"],_m=[{value:"bicycle",label:"🚲 Bicycle"},{value:"pool",label:"🏊 Pool"},{value:"free_weights",label:"🏋️ Free Weights"},{value:"squat_rack",label:"🦵 Squat Rack"},{value:"bench_press",label:"💺 Bench Press"},{value:"machines",label:"⚙️ Machines"},{value:"resistance_bands",label:"🔗 Resistance Bands"},{value:"pull_up_bar",label:"🔩 Pull-up Bar"},{value:"kettlebell",label:"🔔 Kettlebell"},{value:"jump_rope",label:"⏩ Jump Rope"},{value:"yoga_mat",label:"🧘 Yoga Mat"},{value:"treadmill",label:"🏃 Treadmill"},{value:"stationary_bike",label:"🚴 Stationary Bike"},{value:"rowing_machine",label:"🚣 Rowing Machine"}],Cm=[{key:"ext",label:'"People important to me say I should exercise"',tip:"External regulation: exercising because others push you to. Least self-determined motivation."},{key:"intro",label:'"I feel bad about myself when I skip exercise"',tip:"Introjected regulation: guilt or obligation as a driver. Better than external, but still fragile."},{key:"ident",label:'"I value what exercise does for my health"',tip:"Identified regulation: you see exercise as personally important. A strong, durable motivator."},{key:"intr",label:'"I find exercise enjoyable and satisfying"',tip:"Intrinsic motivation: you exercise because it's fun. The most sustainable form of motivation."},{key:"amot",label:`"I don't really see why I should bother"`,tip:"Amotivation: no perceived reason to exercise. If this is high, we'll start with very small wins."}];function Nm(){const[o,c]=m.useState(0),[s,d]=m.useState(""),[p,y]=m.useState(""),[g,P]=m.useState(""),[S,T]=m.useState(""),[z,v]=m.useState(""),[L,A]=m.useState(""),[R,N]=m.useState({heart:!1,joints:!1,meds:!1}),[j,F]=m.useState({ext:0,intro:0,ident:0,intr:0,amot:0}),[_,W]=m.useState([]),[B,Z]=m.useState([]),[fe,we]=m.useState(3),[xe,re]=m.useState(30),[oe,pe]=m.useState([{name:"",cost:100}]),[Ne,ve]=m.useState([]),[Te,Me]=m.useState(!1),We=Ge(),Se=8;function H({label:b,value:ee,onChange:ie,tip:de}){return l.jsxs("div",{style:{marginBottom:"16px"},children:[l.jsx("div",{style:{fontSize:"0.9rem",marginBottom:"6px"},children:de?l.jsx(Ft,{text:de,children:b}):b}),l.jsx("div",{className:"likert-row",children:[1,2,3,4,5].map(ye=>l.jsx("button",{type:"button",className:`likert-btn ${ee===ye?"selected":""}`,onClick:()=>ie(ye),children:ye},ye))}),l.jsxs("div",{className:"likert-labels",children:[l.jsx("span",{children:"Not at all"}),l.jsx("span",{children:"Very true"})]})]})}async function I(){Me(!0);try{await J.savePhase1({primary_goal:s,ttm_stage:p}),c(2)}catch(b){alert(b.message)}finally{Me(!1)}}async function V(){Me(!0);try{let b="none";const ee=["squat_rack","bench_press","machines"],ie=["free_weights","resistance_bands","pull_up_bar","kettlebell","yoga_mat","jump_rope"];B.some(ye=>ee.includes(ye))?b="full_gym":B.some(ye=>ie.includes(ye))&&(b="basic_home"),await J.savePhase2({age:g?parseInt(g):null,height_cm:S?parseFloat(S):null,weight_kg:z?parseFloat(z):null,gender:L||null,parq_heart_condition:R.heart,parq_joint_issues:R.joints,parq_medications:R.meds,motivation_external:j.ext||null,motivation_introjected:j.intro||null,motivation_identified:j.ident||null,motivation_intrinsic:j.intr||null,motivation_amotivation:j.amot||null,activity_preferences:_.map(ye=>ye.toLowerCase().replace(/ /g,"_")),equipment_access:b,equipment_list:B,days_per_week:fe,minutes_per_session:xe});for(const ye of oe)ye.name.trim()&&await J.createReward({name:ye.name,point_cost:ye.cost||100});const de=await J.getRecommendations();ve(de.recommendations||[]),c(7)}catch(b){alert(b.message)}finally{Me(!1)}}async function w(b){try{const ee=new Date,ie=new Date(ee);ie.setDate(ee.getDate()+((8-ee.getDay())%7||7));const de=ie.toISOString().split("T")[0];await J.createProgram({name:b.name,source:b.source,source_url:b.url,start_date:de,duration_days:b.duration_days||90}),We("/")}catch(ee){alert(ee.message)}}function O(b){W(ee=>ee.includes(b)?ee.filter(ie=>ie!==b):[...ee,b])}function ae(b){Z(ee=>ee.includes(b)?ee.filter(ie=>ie!==b):[...ee,b])}const ue=Math.round((o+1)/Se*100),se={fontFamily:"var(--font-display)",fontWeight:900,letterSpacing:"-0.02em",marginBottom:"10px",fontSize:"1.4rem"};return l.jsxs("div",{className:"page",style:{paddingTop:"40px"},children:[l.jsx("div",{className:"progress-bar",style:{marginBottom:"24px"},children:l.jsx("div",{className:"progress-bar-fill",style:{width:`${ue}%`,background:"var(--accent)"}})}),o===0&&l.jsxs("div",{children:[l.jsx("h2",{style:se,children:l.jsx(Ft,{text:"Your primary goal shapes which programs we recommend, how we structure your points, and what success looks like for you.",children:"What matters most to you?"})}),l.jsx("p",{style:{color:"var(--text-3)",marginBottom:"20px",fontSize:"0.9rem"},children:"Pick one — you can change this anytime."}),l.jsx("div",{className:"option-grid",children:wm.map(b=>l.jsxs("div",{className:`option-btn ${s===b.value?"selected":""}`,onClick:()=>d(b.value),children:[l.jsx("div",{style:{fontSize:"1.5rem",marginBottom:"6px"},children:b.icon}),l.jsx(Ft,{text:b.tip,children:b.label})]},b.value))}),l.jsx("button",{className:"btn-primary btn-full",style:{marginTop:"20px"},disabled:!s,onClick:()=>c(1),children:"Continue"})]}),o===1&&l.jsxs("div",{children:[l.jsx("h2",{style:se,children:l.jsx(Ft,{text:"Based on the Transtheoretical Model (Stages of Change). This helps us match you with the right intensity — pushing too hard too early is the #1 reason people quit.",children:"Where are you now?"})}),l.jsx("p",{style:{color:"var(--text-3)",marginBottom:"20px",fontSize:"0.9rem"},children:"Be honest — there's no wrong answer."}),jm.map(b=>l.jsx("div",{className:`option-btn ${p===b.value?"selected":""}`,style:{textAlign:"left",marginBottom:"10px"},onClick:()=>y(b.value),children:l.jsx(Ft,{text:b.tip,children:b.label})},b.value)),l.jsx("button",{className:"btn-primary btn-full",style:{marginTop:"16px"},disabled:!p||Te,onClick:I,children:Te?"...":"Continue"})]}),o===2&&l.jsxs("div",{children:[l.jsx("h2",{style:se,children:l.jsx(Ft,{text:"Based on the PAR-Q+ (Physical Activity Readiness Questionnaire). A standard pre-exercise safety screening used by fitness professionals worldwide.",children:"Quick health check"})}),l.jsx("p",{style:{color:"var(--text-3)",marginBottom:"20px",fontSize:"0.9rem"},children:"For your safety — this takes 10 seconds."}),[{key:"heart",label:"I have a heart condition or high blood pressure"},{key:"joints",label:"I have bone or joint problems that could worsen with exercise"},{key:"meds",label:"I take prescription medications for a chronic condition"}].map(b=>l.jsxs("label",{style:{display:"flex",gap:"12px",padding:"12px 0",cursor:"pointer",borderBottom:"1px solid var(--divider)"},children:[l.jsx("input",{type:"checkbox",checked:R[b.key],onChange:ee=>N({...R,[b.key]:ee.target.checked}),style:{width:"auto"}}),l.jsx("span",{style:{fontSize:"0.9rem"},children:b.label})]},b.key)),(R.heart||R.joints||R.meds)&&l.jsx("div",{style:{marginTop:"12px",padding:"12px",background:"#FFF3E0",borderRadius:"var(--r-sm)",fontSize:"0.85rem",color:"#E65100"},children:"⚠️ We recommend checking with your doctor before starting. This won't stop you — just be mindful."}),l.jsx("button",{className:"btn-primary btn-full",style:{marginTop:"20px"},onClick:()=>c(3),children:"Continue"})]}),o===3&&l.jsxs("div",{children:[l.jsx("h2",{style:se,children:"About you"}),l.jsx("p",{style:{color:"var(--text-3)",marginBottom:"20px",fontSize:"0.9rem"},children:"Optional — helps estimate nutrition needs."}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Age"}),l.jsx("input",{type:"number",value:g,onChange:b=>P(b.target.value),placeholder:"e.g. 35"})]}),l.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Height (cm)"}),l.jsx("input",{type:"number",value:S,onChange:b=>T(b.target.value),placeholder:"175"})]}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Weight (kg)"}),l.jsx("input",{type:"number",value:z,onChange:b=>v(b.target.value),placeholder:"80"})]})]}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Gender"}),l.jsxs("select",{value:L,onChange:b=>A(b.target.value),children:[l.jsx("option",{value:"",children:"Prefer not to say"}),l.jsx("option",{value:"male",children:"Male"}),l.jsx("option",{value:"female",children:"Female"})]})]}),l.jsxs("div",{style:{display:"flex",gap:"10px"},children:[l.jsx("button",{className:"btn-outline btn-full",onClick:()=>c(4),children:"Skip"}),l.jsx("button",{className:"btn-primary btn-full",onClick:()=>c(4),children:"Continue"})]})]}),o===4&&l.jsxs("div",{children:[l.jsx("h2",{style:se,children:l.jsx(Ft,{text:"Based on BREQ-2 (Behavioural Regulation in Exercise Questionnaire). Measures your motivation type from external pressure to intrinsic enjoyment. Your Relative Autonomy Index (RAI) score helps us calibrate how much we push vs. encourage.",children:"What drives you?"})}),l.jsx("p",{style:{color:"var(--text-3)",marginBottom:"20px",fontSize:"0.9rem"},children:"Rate each honestly — helps us calibrate your experience."}),Cm.map(b=>l.jsx(H,{label:b.label,tip:b.tip,value:j[b.key],onChange:ee=>F({...j,[b.key]:ee})},b.key)),l.jsx("button",{className:"btn-primary btn-full",onClick:()=>c(5),children:"Continue"})]}),o===5&&l.jsxs("div",{children:[l.jsx("h2",{style:se,children:"What sounds fun?"}),l.jsx("p",{style:{color:"var(--text-3)",marginBottom:"16px",fontSize:"0.9rem"},children:"Pick all that interest you."}),l.jsx("div",{className:"chip-grid",style:{marginBottom:"24px"},children:km.map(b=>l.jsx("div",{className:`chip ${_.includes(b)?"selected":""}`,onClick:()=>O(b),children:b},b))}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:l.jsx(Ft,{text:"Select everything you have access to. This helps us recommend programs that match your available equipment — no point suggesting barbell work if you don't have a rack.",children:"Equipment you have access to"})}),l.jsx("div",{className:"chip-grid",children:_m.map(b=>l.jsx("div",{className:`chip ${B.includes(b.value)?"selected":""}`,onClick:()=>ae(b.value),children:b.label},b.value))}),B.length===0&&l.jsx("p",{style:{color:"var(--text-3)",fontSize:"0.8rem",marginTop:"8px",fontStyle:"italic"},children:"No selection = bodyweight only. That's perfectly fine!"})]}),l.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px",marginTop:"16px",marginBottom:"16px"},children:[l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Days/week"}),l.jsx("select",{value:fe,onChange:b=>we(parseInt(b.target.value)),children:[1,2,3,4,5,6,7].map(b=>l.jsx("option",{value:b,children:b},b))})]}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Minutes/session"}),l.jsx("select",{value:xe,onChange:b=>re(parseInt(b.target.value)),children:[15,20,30,45,60,90].map(b=>l.jsx("option",{value:b,children:b},b))})]})]}),l.jsx("button",{className:"btn-primary btn-full",onClick:()=>c(6),children:"Continue"})]}),o===6&&l.jsxs("div",{children:[l.jsx("h2",{style:se,children:l.jsx(Ft,{text:"The reward gate is the core mechanic: you can't access your rewards until you hit your daily point minimum. This creates a behavioral contract — earn first, enjoy second.",children:"Define your rewards"})}),l.jsx("p",{style:{color:"var(--text-3)",marginBottom:"20px",fontSize:"0.9rem"},children:"What guilty pleasures do you want to earn?"}),oe.map((b,ee)=>l.jsxs("div",{style:{display:"grid",gridTemplateColumns:"2fr 1fr",gap:"10px",marginBottom:"12px"},children:[l.jsx("input",{placeholder:"e.g. 1hr gaming",value:b.name,onChange:ie=>{const de=[...oe];de[ee]={...b,name:ie.target.value},pe(de)}}),l.jsx("input",{type:"number",placeholder:"100",value:b.cost,onChange:ie=>{const de=[...oe];de[ee]={...b,cost:parseInt(ie.target.value)||0},pe(de)}})]},ee)),l.jsx("button",{className:"btn-outline btn-sm",style:{marginBottom:"20px"},onClick:()=>pe([...oe,{name:"",cost:100}]),children:"+ Add another reward"}),l.jsx("button",{className:"btn-primary btn-full",disabled:Te,onClick:V,children:Te?"Saving...":"See Recommendations"})]}),o===7&&l.jsxs("div",{children:[l.jsx("h2",{style:se,children:"Recommended for you"}),l.jsx("p",{style:{color:"var(--text-3)",marginBottom:"20px",fontSize:"0.9rem"},children:"Pick a program and commit to 90 days."}),Ne.map(b=>l.jsxs("div",{className:"card",children:[l.jsx("div",{style:{fontWeight:700,marginBottom:"4px"},children:b.name}),l.jsxs("div",{style:{fontSize:"0.85rem",color:"var(--text-3)",marginBottom:"8px"},children:[b.difficulty," • ",b.duration_days?`${b.duration_days} days`:"Ongoing"," • ",b.source]}),l.jsx("p",{style:{fontSize:"0.9rem",marginBottom:"12px"},children:b.description}),l.jsxs("div",{style:{display:"flex",gap:"8px"},children:[l.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",className:"btn-outline btn-sm",style:{display:"inline-block"},children:"View ↗"}),l.jsx("button",{className:"btn-primary btn-sm",onClick:()=>w(b),children:"Select & Commit"})]})]},b.id)),l.jsx("button",{className:"btn-outline btn-full",style:{marginTop:"8px"},onClick:()=>We("/"),children:"Skip for now"})]})]})}function Em(){const[o,c]=m.useState(null),[s,d]=m.useState(!0);m.useEffect(()=>{p()},[]);async function p(){try{c(await J.week())}catch(S){console.error(S)}finally{d(!1)}}if(s)return l.jsx("div",{className:"page",children:l.jsx("div",{className:"loading",children:"Loading..."})});if(!o)return l.jsx("div",{className:"page",children:l.jsx("div",{className:"error-msg",children:"Failed to load"})});const y=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],g=o.weekly_target>0?Math.min(100,Math.round(o.total_points_earned/o.weekly_target*100)):0,P=new Date().toISOString().split("T")[0];return l.jsxs("div",{className:"page",children:[l.jsx("h1",{className:"page-title",children:"This Week"}),l.jsxs("div",{className:"card",style:{textAlign:"center",background:"var(--accent-bg)"},children:[l.jsx("div",{className:"section-label",children:"Weekly Total"}),l.jsx("div",{style:{fontFamily:"var(--font-display)",fontSize:"2.6rem",fontWeight:900,letterSpacing:"-0.03em"},children:o.total_points_earned}),l.jsxs("div",{style:{color:"var(--text-3)",fontWeight:600,fontSize:"0.88rem",marginBottom:"12px"},children:["/ ",o.weekly_target," pts"]}),l.jsx("div",{className:"progress-bar",style:{height:"12px"},children:l.jsx("div",{className:"progress-bar-fill",style:{width:`${g}%`,background:o.hit_weekly_target?"linear-gradient(90deg, #00C853, #69F0AE)":"linear-gradient(90deg, #7C4DFF, #B388FF)"}})}),o.hit_weekly_target&&l.jsxs("div",{style:{marginTop:"10px",color:"var(--green-dark)",fontWeight:700,fontSize:"0.9rem"},children:["🏆 Target hit! +",o.weekly_bonus_earned," bonus"]}),l.jsxs("div",{style:{display:"flex",justifyContent:"center",gap:"28px",marginTop:"14px"},children:[l.jsxs("div",{children:[l.jsx("div",{style:{fontFamily:"var(--font-display)",fontWeight:900,fontSize:"1.3rem"},children:o.active_days}),l.jsx("div",{style:{fontSize:"0.72rem",color:"var(--text-3)",fontWeight:600},children:"active days"})]}),l.jsxs("div",{children:[l.jsx("div",{style:{fontFamily:"var(--font-display)",fontWeight:900,fontSize:"1.3rem"},children:o.gate_passed_days}),l.jsx("div",{style:{fontSize:"0.72rem",color:"var(--text-3)",fontWeight:600},children:"rewards earned"})]})]})]}),l.jsxs("div",{className:"card",children:[l.jsx("div",{className:"section-label",children:"Daily Breakdown"}),o.daily_breakdown.map((S,T)=>{const z=S.daily_minimum>0?Math.min(100,Math.round(S.points_earned/S.daily_minimum*100)):0,v=S.date===P;return l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 0",borderBottom:T<6?"1px solid var(--divider)":"none"},children:[l.jsx("div",{style:{width:"38px",fontWeight:v?800:600,fontSize:"0.85rem",color:v?"var(--accent)":"var(--text)"},children:y[T]}),l.jsx("div",{style:{flex:1},children:l.jsx("div",{className:"progress-bar",style:{height:"8px"},children:l.jsx("div",{className:"progress-bar-fill",style:{width:`${z}%`,background:S.gate_passed?"var(--green)":S.points_earned>0?"var(--amber)":"transparent"}})})}),l.jsx("div",{style:{width:"46px",textAlign:"right",fontFamily:"var(--font-display)",fontWeight:800,fontSize:"0.9rem"},children:S.points_earned}),l.jsx("div",{style:{width:"22px",textAlign:"center",fontSize:"0.9rem"},children:S.gate_passed?"✅":S.points_earned>0?"🟡":"⬜"})]},S.date)})]})]})}function Pm(){const o=Ge();return l.jsxs("div",{className:"page",style:{maxWidth:600,margin:"0 auto",padding:"40px 20px",textAlign:"center"},children:[l.jsx("div",{style:{fontSize:"3rem",marginBottom:16},children:"💪"}),l.jsx("h1",{style:{fontSize:"1.8rem",fontWeight:700,marginBottom:8},children:"Earn Before You Spend"}),l.jsx("p",{style:{color:"var(--text-2)",fontSize:"1rem",lineHeight:1.6,marginBottom:32},children:"This app runs on a simple idea: you earn points by doing healthy things (workouts, logging meals, hitting step goals), and you spend points on guilty pleasures you configure yourself."}),l.jsxs("div",{style:{background:"var(--surface-2)",borderRadius:"var(--r-md)",padding:24,marginBottom:24,textAlign:"left"},children:[l.jsxs("div",{style:{display:"flex",gap:16,marginBottom:16},children:[l.jsx("span",{style:{fontSize:"1.5rem"},children:"🔒"}),l.jsxs("div",{children:[l.jsx("strong",{children:"Daily Gate"}),l.jsx("p",{style:{color:"var(--text-2)",margin:"4px 0 0",fontSize:"0.9rem"},children:"Until you earn enough points today, your rewards stay locked. Hit your target, and the gate opens."})]})]}),l.jsxs("div",{style:{display:"flex",gap:16,marginBottom:16},children:[l.jsx("span",{style:{fontSize:"1.5rem"},children:"🎮"}),l.jsxs("div",{children:[l.jsx("strong",{children:"Your Rules"}),l.jsx("p",{style:{color:"var(--text-2)",margin:"4px 0 0",fontSize:"0.9rem"},children:"You set the rewards — gaming time, takeout, screen time, whatever you want. You hold yourself accountable."})]})]}),l.jsxs("div",{style:{display:"flex",gap:16},children:[l.jsx("span",{style:{fontSize:"1.5rem"},children:"🤖"}),l.jsxs("div",{children:[l.jsx("strong",{children:"AI Agent (Optional)"}),l.jsx("p",{style:{color:"var(--text-2)",margin:"4px 0 0",fontSize:"0.9rem"},children:"Connect an AI agent to log activities by voice, get nudged when you're behind, and have a fitness companion that knows your goals."})]})]})]}),l.jsx("button",{onClick:()=>o("/register"),style:{background:"var(--accent)",color:"#fff",border:"none",borderRadius:"var(--r-sm)",padding:"14px 32px",fontSize:"1rem",fontWeight:600,cursor:"pointer",width:"100%"},children:"Get Started"}),l.jsx("p",{style:{color:"var(--text-3)",fontSize:"0.8rem",marginTop:16},children:"Points reset weekly. Each week is a fresh start."})]})}const zc={connected:"var(--green)",configured:"var(--amber)",not_configured:"var(--text-3)"},zm={connected:"Connected",configured:"Configured",not_configured:"Not configured"};function Tm(){const[o,c]=m.useState({}),[s,d]=m.useState({}),[p,y]=m.useState(!0),[g,P]=m.useState(null),[S,T]=m.useState({}),[z,v]=m.useState(!1);m.useEffect(()=>{L()},[]);async function L(){try{const[N,j]=await Promise.all([J.listProviders(),J.fullIntegrationStatus()]);c(N),d(j)}catch(N){console.error(N)}finally{y(!1)}}function A(N){var F;P(N);const j=((F=o[N])==null?void 0:F.fields)||[];T(Object.fromEntries(j.map(_=>[_,""])))}async function R(N){v(!0);try{await J.configureIntegration(N,S),P(null),await L()}catch(j){alert(`Failed: ${j.message}`)}finally{v(!1)}}return p?l.jsx("div",{className:"page",children:l.jsx("div",{className:"loading",children:"Loading..."})}):l.jsxs("div",{className:"page",style:{maxWidth:700,margin:"0 auto"},children:[l.jsx("h1",{style:{fontSize:"1.4rem",fontWeight:700,marginBottom:24},children:"Integrations"}),l.jsx("p",{style:{color:"var(--text-2)",marginBottom:24,fontSize:"0.9rem"},children:"Configure your fitness devices and services. Credentials are encrypted and stored locally — never sent to any external server."}),Object.entries(o).map(([N,j])=>l.jsxs("div",{style:{background:"var(--surface-2)",borderRadius:"var(--r-md)",padding:20,marginBottom:12,border:s[N]==="connected"?"2px solid var(--accent)":"1px solid var(--border)"},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:8},children:[l.jsx("strong",{style:{fontSize:"1rem"},children:j.name}),l.jsx("span",{style:{fontSize:"0.75rem",padding:"3px 10px",borderRadius:20,fontWeight:600,background:zc[s[N]||"not_configured"]+"22",color:zc[s[N]||"not_configured"]},children:zm[s[N]||"not_configured"]})]}),l.jsx("p",{style:{color:"var(--text-2)",fontSize:"0.85rem",margin:"0 0 12px"},children:j.help_text}),j.help_url&&l.jsx("a",{href:j.help_url,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"0.8rem",color:"var(--accent)"},children:"Developer portal →"}),g===N?l.jsxs("div",{style:{marginTop:12,padding:16,background:"var(--surface)",borderRadius:"var(--r-sm)"},children:[j.fields.map(F=>l.jsxs("div",{style:{marginBottom:10},children:[l.jsx("label",{style:{fontSize:"0.8rem",fontWeight:600,display:"block",marginBottom:4},children:F.replace(/_/g," ")}),l.jsx("input",{type:F.includes("secret")||F.includes("token")||F.includes("key")?"password":"text",value:S[F]||"",onChange:_=>T({...S,[F]:_.target.value}),style:{width:"100%",padding:"8px 12px",borderRadius:"var(--r-sm)",border:"1px solid var(--border)",fontSize:"0.9rem",boxSizing:"border-box"},placeholder:`Enter ${F.replace(/_/g," ")}`})]},F)),l.jsxs("div",{style:{display:"flex",gap:8,marginTop:8},children:[l.jsx("button",{onClick:()=>R(N),disabled:z,style:{background:"var(--accent)",color:"#fff",border:"none",padding:"8px 20px",borderRadius:"var(--r-sm)",cursor:"pointer",fontWeight:600},children:z?"Saving...":"Save"}),l.jsx("button",{onClick:()=>P(null),style:{background:"transparent",color:"var(--text-2)",border:"1px solid var(--border)",padding:"8px 20px",borderRadius:"var(--r-sm)",cursor:"pointer"},children:"Cancel"})]})]}):l.jsx("button",{onClick:()=>A(N),style:{marginTop:8,background:"transparent",color:"var(--accent)",border:"1px solid var(--accent)",padding:"6px 16px",borderRadius:"var(--r-sm)",cursor:"pointer",fontSize:"0.85rem",fontWeight:600},children:s[N]==="not_configured"?"Configure":"Reconfigure"})]},N))]})}const bm={breakfast:"🌅",lunch:"🌞",dinner:"🌙",snack:"🍎"};function Rm(){var z;const[o,c]=m.useState(null),[s,d]=m.useState([]),[p,y]=m.useState(!0),[g,P]=m.useState({});m.useEffect(()=>{S()},[]);async function S(){try{const[v,L]=await Promise.all([J.getMealPlanToday(),J.listMealPlans()]);c(v),d(L)}catch(v){console.error(v)}finally{y(!1)}}async function T(v,L){try{await J.logMealCompliance({plan_item_id:v,status:L}),P(A=>({...A,[v]:L}))}catch(A){alert(`Failed: ${A.message}`)}}return p?l.jsx("div",{className:"page",children:l.jsx("div",{className:"loading",children:"Loading..."})}):l.jsxs("div",{className:"page",style:{maxWidth:600,margin:"0 auto"},children:[l.jsx("h1",{style:{fontSize:"1.4rem",fontWeight:700,marginBottom:8},children:"Meal Plan"}),o!=null&&o.active_plan?l.jsxs(l.Fragment,{children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:20,color:"var(--text-2)",fontSize:"0.9rem"},children:[l.jsx("span",{children:o.active_plan}),l.jsxs("span",{style:{background:"var(--accent)",color:"#fff",padding:"3px 10px",borderRadius:20,fontSize:"0.75rem",fontWeight:600},children:["Day ",o.day," / ",o.duration_days]})]}),o.daily_calories&&l.jsxs("div",{style:{background:"var(--surface-2)",borderRadius:"var(--r-sm)",padding:12,marginBottom:16,textAlign:"center",fontSize:"0.85rem",color:"var(--text-2)"},children:["Target: ",o.daily_calories," cal · ",o.diet_type||"balanced"]}),((z=o.meals)==null?void 0:z.length)>0?o.meals.map(v=>{const L=g[v.id];return l.jsxs("div",{style:{background:"var(--surface-2)",borderRadius:"var(--r-md)",padding:16,marginBottom:10,borderLeft:L==="followed"?"4px solid var(--green)":L==="skipped"?"4px solid var(--red)":L==="substituted"?"4px solid var(--amber)":"4px solid transparent"},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[l.jsxs("div",{children:[l.jsxs("div",{style:{fontSize:"0.75rem",color:"var(--text-3)",textTransform:"uppercase",marginBottom:4},children:[bm[v.meal_type]||"🍽️"," ",v.meal_type]}),l.jsx("div",{style:{fontWeight:600,marginBottom:4},children:v.food_name}),v.description&&l.jsx("div",{style:{fontSize:"0.85rem",color:"var(--text-2)"},children:v.description})]}),v.calories&&l.jsxs("div",{style:{fontSize:"0.85rem",fontWeight:600,color:"var(--text-2)",flexShrink:0,marginLeft:12},children:[v.calories," cal"]})]}),v.protein_g&&l.jsxs("div",{style:{fontSize:"0.75rem",color:"var(--text-3)",marginTop:6},children:["P: ",v.protein_g,"g · C: ",v.carbs_g,"g · F: ",v.fat_g,"g"]}),!L&&l.jsx("div",{style:{display:"flex",gap:6,marginTop:10},children:["followed","substituted","skipped"].map(A=>l.jsxs("button",{onClick:()=>T(v.id,A),style:{background:"transparent",border:"1px solid var(--border)",padding:"4px 12px",borderRadius:"var(--r-sm)",fontSize:"0.75rem",cursor:"pointer",color:"var(--text-2)",textTransform:"capitalize"},children:[A==="followed"?"✅":A==="skipped"?"⏭️":"🔄"," ",A]},A))})]},v.id)}):l.jsx("p",{style:{color:"var(--text-2)",textAlign:"center"},children:o.message||"No meals for today."})]}):l.jsxs("div",{style:{background:"var(--surface-2)",borderRadius:"var(--r-md)",padding:32,textAlign:"center",color:"var(--text-2)"},children:[l.jsx("div",{style:{fontSize:"2rem",marginBottom:12},children:"🍽️"}),l.jsx("p",{style:{marginBottom:8},children:"No active meal plan."}),l.jsx("p",{style:{fontSize:"0.85rem"},children:'Ask your AI agent to create one: "Generate a 7-day keto meal plan for me"'})]}),s.length>0&&l.jsxs("div",{style:{marginTop:32},children:[l.jsx("h2",{style:{fontSize:"1.1rem",fontWeight:600,marginBottom:12},children:"All Plans"}),s.map(v=>l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"10px 0",borderBottom:"1px solid var(--border)"},children:[l.jsxs("div",{children:[l.jsx("div",{style:{fontWeight:500},children:v.name}),l.jsxs("div",{style:{fontSize:"0.8rem",color:"var(--text-3)"},children:[v.diet_type," · ",v.duration_days," days · started ",v.start_date]})]}),l.jsx("span",{style:{fontSize:"0.75rem",padding:"2px 8px",borderRadius:12,background:v.status==="active"?"var(--green)22":"var(--text-3)22",color:v.status==="active"?"var(--green)":"var(--text-3)",fontWeight:600},children:v.status})]},v.id))]})]})}const Tc={beginner:"var(--green)",intermediate:"var(--accent)",advanced:"var(--accent-light)"},Lm={strength:"🏋️",cardio:"🏃",flexibility:"🧘",hybrid:"⚡"},bc={pending:{label:"Queued",color:"var(--amber)"},crawling:{label:"Fetching...",color:"var(--accent)"},extracting:{label:"Analyzing...",color:"var(--accent-light)"},ready:{label:"Ready",color:"var(--green)"},failed:{label:"Failed",color:"var(--red)"}};function Im(){const[o,c]=m.useState(""),[s,d]=m.useState([]),[p,y]=m.useState([]),[g,P]=m.useState(!0),[S,T]=m.useState(!1),[z,v]=m.useState(null),L=Ge();m.useEffect(()=>{A()},[]);async function A(){try{const[_,W]=await Promise.all([J.searchCatalog(""),J.listPrograms()]);d(_),y(W)}catch(_){console.error(_)}finally{P(!1)}}async function R(_){if(_.preventDefault(),!!o.trim())try{const W=await J.searchCatalog(o);d(W)}catch(W){console.error(W)}}async function N(){if(o.trim()){T(!0),v(null);try{const _=await J.researchProgram(o);_.already_exists?v({type:"info",text:`"${_.name}" is already in the catalog.`}):v({type:"success",text:_.message||"Program queued for research!"}),await A()}catch(_){v({type:"error",text:_.message})}finally{T(!1)}}}async function j(_){const W=new Date().toISOString().slice(0,10);try{await J.adoptProgram(_,W),v({type:"success",text:"Program started! Check your dashboard."}),await A()}catch(B){v({type:"error",text:B.message})}}function F(_){return p.some(W=>W.status==="active"&&W.catalog_id===_)}return g?l.jsx("div",{style:{padding:"2rem",textAlign:"center",color:"var(--text-3)"},children:"Loading..."}):l.jsxs("div",{style:{padding:"1rem",paddingBottom:"96px",maxWidth:"600px",margin:"0 auto"},children:[l.jsx("h1",{style:{fontFamily:"var(--font-display)",fontSize:"1.6rem",fontWeight:900,marginBottom:"0.5rem"},children:"Programs"}),l.jsx("p",{style:{color:"var(--text-3)",fontSize:"0.85rem",marginBottom:"1.5rem"},children:"Find a program or tell us what you're doing — we'll set it up for you."}),l.jsxs("form",{onSubmit:R,style:{display:"flex",gap:"0.5rem",marginBottom:"1rem"},children:[l.jsx("input",{type:"text",value:o,onChange:_=>c(_.target.value),placeholder:'e.g. "StrongLifts 5x5" or "Couch to 5K"',style:{flex:1,padding:"12px 16px",borderRadius:"var(--r)",border:"1px solid var(--divider)",fontFamily:"var(--font)",fontSize:"0.9rem",background:"var(--card)"}}),l.jsx("button",{type:"submit",style:{background:"var(--accent)",color:"#fff",padding:"12px 18px",boxShadow:"var(--shadow-1)"},children:"Search"})]}),l.jsx("button",{onClick:N,disabled:S||!o.trim(),style:{width:"100%",background:S?"var(--text-3)":"var(--accent)",color:"#fff",padding:"14px",marginBottom:"1rem",boxShadow:S?"none":"var(--shadow-accent)",opacity:o.trim()?1:.5},children:S?"Researching...":`Research "${o||"..."}" for me`}),z&&l.jsx("div",{style:{padding:"12px 16px",borderRadius:"var(--r-sm)",marginBottom:"1rem",fontSize:"0.85rem",fontWeight:600,background:z.type==="error"?"var(--red-ghost)":z.type==="success"?"var(--green-bg)":"var(--accent-bg)",color:z.type==="error"?"var(--red)":z.type==="success"?"var(--green-dark)":"var(--accent)"},children:z.text}),p.filter(_=>_.status==="active").length>0&&l.jsxs(l.Fragment,{children:[l.jsx("h2",{style:{fontFamily:"var(--font-display)",fontSize:"1.1rem",fontWeight:800,marginBottom:"0.75rem"},children:"Your Active Programs"}),p.filter(_=>_.status==="active").map(_=>l.jsxs("div",{onClick:()=>L(`/programs/${_.id}`),style:{background:"var(--card)",borderRadius:"var(--r)",padding:"16px",marginBottom:"0.75rem",boxShadow:"var(--shadow-1)",cursor:"pointer",border:"2px solid var(--accent-glow)"},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[l.jsx("strong",{style:{fontFamily:"var(--font-display)",fontSize:"1rem"},children:_.name}),l.jsxs("span",{style:{fontSize:"0.8rem",color:"var(--accent)",fontWeight:700},children:["Day ",_.current_day,"/",_.total_days]})]}),l.jsx("div",{style:{marginTop:"8px",height:"6px",borderRadius:"3px",background:"var(--divider)"},children:l.jsx("div",{style:{height:"100%",borderRadius:"3px",background:"var(--accent)",width:`${Math.min(100,_.current_day/_.total_days*100)}%`,transition:"width 0.3s ease"}})})]},_.id))]}),l.jsx("h2",{style:{fontFamily:"var(--font-display)",fontSize:"1.1rem",fontWeight:800,marginTop:"1.5rem",marginBottom:"0.75rem"},children:"Program Catalog"}),s.length===0&&l.jsx("p",{style:{color:"var(--text-3)",fontSize:"0.85rem",textAlign:"center",padding:"2rem 0"},children:"No programs found. Try searching or researching a program above."}),s.map(_=>{const W=bc[_.crawl_status]||bc.pending,B=F(_.id);return l.jsxs("div",{style:{background:"var(--card)",borderRadius:"var(--r)",padding:"16px",marginBottom:"0.75rem",boxShadow:"var(--shadow-1)"},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[l.jsxs("div",{children:[l.jsxs("strong",{style:{fontFamily:"var(--font-display)",fontSize:"1rem"},children:[Lm[_.category]||"📋"," ",_.name]}),_.description&&l.jsx("p",{style:{color:"var(--text-2)",fontSize:"0.82rem",marginTop:"4px"},children:_.description})]}),l.jsx("span",{style:{fontSize:"0.7rem",fontWeight:700,padding:"3px 8px",borderRadius:"var(--r-full)",color:"#fff",background:W.color,whiteSpace:"nowrap"},children:W.label})]}),l.jsxs("div",{style:{display:"flex",gap:"0.5rem",flexWrap:"wrap",marginTop:"10px"},children:[_.duration_weeks&&l.jsxs("span",{style:Xl,children:[_.duration_weeks," weeks"]}),_.frequency_per_week&&l.jsxs("span",{style:Xl,children:[_.frequency_per_week,"x/week"]}),_.difficulty&&l.jsx("span",{style:{...Xl,color:Tc[_.difficulty]||"var(--text-3)",background:`${Tc[_.difficulty]||"var(--text-3)"}11`},children:_.difficulty}),(_.equipment||[]).slice(0,3).map(Z=>l.jsx("span",{style:Xl,children:Z},Z))]}),_.crawl_status==="ready"&&!B&&l.jsx("button",{onClick:()=>j(_.id),style:{marginTop:"12px",width:"100%",background:"var(--green)",color:"#fff",padding:"10px",fontSize:"0.85rem",boxShadow:"var(--shadow-green)"},children:"Start Program"}),B&&l.jsx("div",{style:{marginTop:"12px",textAlign:"center",fontSize:"0.82rem",color:"var(--green-dark)",fontWeight:700},children:"✓ Active"}),_.crawl_status==="ready"&&l.jsx("button",{onClick:()=>L(`/catalog/${_.id}`),style:{marginTop:B?"4px":"8px",width:"100%",background:"transparent",color:"var(--accent)",padding:"8px",fontSize:"0.82rem",border:"1px solid var(--divider)"},children:"View Details"})]},_.id)})]})}const Xl={fontSize:"0.72rem",fontWeight:600,padding:"3px 10px",borderRadius:"var(--r-full)",background:"var(--divider)",color:"var(--text-2)"};function Fm(){const{id:o}=pa(),c=Ge(),[s,d]=m.useState(null),[p,y]=m.useState(null),[g,P]=m.useState(!0),[S,T]=m.useState(null),[z,v]=m.useState(null),[L,A]=m.useState(null);m.useEffect(()=>{R()},[o]);async function R(){try{const[F,_]=await Promise.all([J.getProgramSchedule(o),J.getProgramProgress(o)]);d(F),y(_)}catch(F){console.error(F)}finally{P(!1)}}async function N(F){T(F);try{const _=await J.completeWorkout(o,F,{});A(_),v(null),await R()}catch(_){alert(_.message)}finally{T(null)}}if(g)return l.jsx("div",{style:{padding:"2rem",textAlign:"center",color:"var(--text-3)"},children:"Loading..."});if(!s)return l.jsx("div",{style:{padding:"2rem",textAlign:"center"},children:"Program not found"});const j=p?p.completion_pct:0;return l.jsxs("div",{style:{padding:"1rem",paddingBottom:"96px",maxWidth:"600px",margin:"0 auto"},children:[l.jsx("button",{onClick:()=>c("/programs"),style:{background:"transparent",color:"var(--text-3)",padding:"8px 0",fontSize:"0.85rem",marginBottom:"0.5rem"},children:"← Programs"}),l.jsxs("div",{style:{background:"var(--card)",borderRadius:"var(--r-lg)",padding:"20px",boxShadow:"var(--shadow-2)",marginBottom:"1.5rem"},children:[l.jsx("h1",{style:{fontFamily:"var(--font-display)",fontSize:"1.5rem",fontWeight:900},children:s.program_name}),l.jsxs("div",{style:{display:"flex",gap:"1.5rem",marginTop:"10px",fontSize:"0.82rem",color:"var(--text-2)"},children:[l.jsxs("span",{children:["Week ",s.current_week]}),l.jsxs("span",{children:[(p==null?void 0:p.completed_workouts)||0,"/",(p==null?void 0:p.total_workouts)||0," workouts"]}),l.jsxs("span",{style:{color:"var(--accent)",fontWeight:700},children:[j,"%"]})]}),l.jsx("div",{style:{marginTop:"12px",height:"8px",borderRadius:"4px",background:"var(--divider)"},children:l.jsx("div",{style:{height:"100%",borderRadius:"4px",background:j>=100?"var(--green)":"var(--accent)",width:`${Math.min(100,j)}%`,transition:"width 0.4s ease"}})}),s.progression_rules&&l.jsxs("p",{style:{marginTop:"12px",fontSize:"0.8rem",color:"var(--text-3)",lineHeight:1.5,borderTop:"1px solid var(--divider)",paddingTop:"12px"},children:["📈 ",s.progression_rules]})]}),L&&l.jsxs("div",{style:{background:"var(--green-bg)",borderRadius:"var(--r)",padding:"16px",marginBottom:"1rem",textAlign:"center"},children:[l.jsx("div",{style:{fontSize:"1.8rem",marginBottom:"4px"},children:"🎉"}),l.jsxs("strong",{style:{color:"var(--green-dark)"},children:["+",L.total_points," points!"]}),l.jsxs("div",{style:{fontSize:"0.8rem",color:"var(--text-2)",marginTop:"4px"},children:["Workout: +",L.points_earned,L.weekly_bonus>0&&` • Week bonus: +${L.weekly_bonus}`,L.completion_bonus>0&&` • Program complete: +${L.completion_bonus}!`]}),l.jsx("button",{onClick:()=>A(null),style:{marginTop:"10px",background:"transparent",color:"var(--green-dark)",fontSize:"0.8rem",padding:"6px 16px",border:"1px solid var(--green)"},children:"Dismiss"})]}),s.today_workout&&!s.today_workout.completed&&!s.today_workout.rest_day&&l.jsxs("div",{style:{background:"var(--card)",borderRadius:"var(--r)",padding:"16px",marginBottom:"1.5rem",boxShadow:"var(--shadow-2)",border:"2px solid var(--accent-glow)"},children:[l.jsx("div",{style:{fontSize:"0.72rem",fontWeight:700,color:"var(--accent)",textTransform:"uppercase",letterSpacing:"0.05em",marginBottom:"6px"},children:"Today's Workout"}),l.jsx("strong",{style:{fontFamily:"var(--font-display)",fontSize:"1.1rem"},children:s.today_workout.workout_name||`Day ${s.today_workout.day_number}`}),l.jsx("div",{style:{marginTop:"12px"},children:(s.today_workout.exercises||[]).map((F,_)=>l.jsx(Rc,{exercise:F},_))}),l.jsx("button",{onClick:()=>N(s.today_workout.id),disabled:S===s.today_workout.id,style:{marginTop:"14px",width:"100%",padding:"14px",background:S?"var(--text-3)":"var(--green)",color:"#fff",fontSize:"0.95rem",fontWeight:800,boxShadow:"var(--shadow-green)"},children:S===s.today_workout.id?"Logging...":"✓ Complete Workout — 75 pts"})]}),l.jsx("h2",{style:{fontFamily:"var(--font-display)",fontSize:"1.1rem",fontWeight:800,marginBottom:"0.75rem"},children:"Full Schedule"}),Wm(s.schedule).map(([F,_])=>l.jsxs("div",{style:{marginBottom:"1.25rem"},children:[l.jsxs("div",{style:{fontSize:"0.78rem",fontWeight:700,color:"var(--text-3)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:"0.5rem",display:"flex",alignItems:"center",gap:"0.5rem"},children:["Week ",F,F===s.current_week&&l.jsx("span",{style:{fontSize:"0.65rem",background:"var(--accent)",color:"#fff",padding:"2px 8px",borderRadius:"var(--r-full)"},children:"Current"})]}),_.map(W=>l.jsxs("div",{style:{background:"var(--card)",borderRadius:"var(--r-sm)",padding:"12px 14px",marginBottom:"0.4rem",boxShadow:"var(--shadow-1)",opacity:W.completed?.7:1,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[l.jsxs("div",{children:[l.jsx("span",{style:{fontSize:"0.85rem",fontWeight:600},children:W.rest_day?"😴 Rest Day":W.workout_name||`Day ${W.day_number}`}),!W.rest_day&&l.jsxs("span",{style:{fontSize:"0.75rem",color:"var(--text-3)",marginLeft:"8px"},children:[(W.exercises||[]).length," exercises"]})]}),l.jsx("div",{children:W.completed?l.jsx("span",{style:{color:"var(--green)",fontSize:"0.85rem",fontWeight:700},children:"✓"}):W.rest_day?null:l.jsx("button",{onClick:()=>v(W),style:{background:"var(--green-bg)",color:"var(--green-dark)",padding:"6px 12px",fontSize:"0.75rem",fontWeight:700},children:"Do it"})})]},W.id))]},F)),z&&l.jsx("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"flex-end",justifyContent:"center",zIndex:100},onClick:()=>v(null),children:l.jsxs("div",{style:{background:"var(--card)",borderRadius:"var(--r-lg) var(--r-lg) 0 0",padding:"24px 20px",width:"100%",maxWidth:"600px",maxHeight:"80vh",overflow:"auto"},onClick:F=>F.stopPropagation(),children:[l.jsx("h3",{style:{fontFamily:"var(--font-display)",fontSize:"1.2rem",fontWeight:800,marginBottom:"4px"},children:z.workout_name||`Week ${z.week_number}, Day ${z.day_number}`}),l.jsx("p",{style:{color:"var(--text-3)",fontSize:"0.82rem",marginBottom:"16px"},children:'Complete the exercises below and tap "Done" when finished.'}),(z.exercises||[]).map((F,_)=>l.jsx(Rc,{exercise:F,detailed:!0},_)),z.notes&&l.jsxs("p",{style:{marginTop:"12px",fontSize:"0.8rem",color:"var(--text-2)",background:"var(--accent-bg)",padding:"10px 12px",borderRadius:"var(--r-sm)"},children:["💡 ",z.notes]}),l.jsxs("div",{style:{display:"flex",gap:"0.5rem",marginTop:"20px"},children:[l.jsx("button",{onClick:()=>v(null),style:{flex:1,background:"var(--divider)",color:"var(--text-2)",padding:"14px"},children:"Cancel"}),l.jsx("button",{onClick:()=>N(z.id),disabled:S===z.id,style:{flex:2,background:"var(--green)",color:"#fff",padding:"14px",fontWeight:800,boxShadow:"var(--shadow-green)"},children:S===z.id?"Logging...":"✓ Done — 75 pts"})]})]})})]})}function Rc({exercise:o,detailed:c}){return l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:c?"10px 0":"6px 0",borderBottom:"1px solid var(--divider)"},children:[l.jsxs("div",{children:[l.jsx("span",{style:{fontWeight:600,fontSize:c?"0.9rem":"0.82rem"},children:o.name}),c&&o.notes&&l.jsx("div",{style:{fontSize:"0.75rem",color:"var(--text-3)",marginTop:"2px"},children:o.notes}),c&&o.weight_instruction&&l.jsxs("div",{style:{fontSize:"0.75rem",color:"var(--accent)",marginTop:"2px"},children:["🏋️ ",o.weight_instruction]})]}),l.jsxs("div",{style:{textAlign:"right",fontSize:"0.8rem",color:"var(--text-2)",fontWeight:600,whiteSpace:"nowrap"},children:[o.sets&&o.reps&&`${o.sets}×${o.reps}`,o.rest_seconds&&c&&l.jsx("div",{style:{fontSize:"0.7rem",color:"var(--text-3)"},children:o.rest_seconds>=60?`${Math.floor(o.rest_seconds/60)}m rest`:`${o.rest_seconds}s rest`})]})]})}function Wm(o){const c={};for(const s of o||[]){const d=s.week_number;c[d]||(c[d]=[]),c[d].push(s)}return Object.entries(c).sort(([s],[d])=>Number(s)-Number(d))}const Lc={beginner:"var(--green)",intermediate:"var(--accent)",advanced:"var(--accent-light)"},Bm={strength:"🏋️",cardio:"🏃",flexibility:"🧘",hybrid:"⚡"},Ic={pending:{label:"Queued",color:"var(--amber)"},crawling:{label:"Fetching...",color:"var(--accent)"},extracting:{label:"Analyzing...",color:"var(--accent-light)"},ready:{label:"Ready",color:"var(--green)"},failed:{label:"Failed",color:"var(--red)"}};function Om(){const{id:o}=pa(),c=Ge(),[s,d]=m.useState(null),[p,y]=m.useState([]),[g,P]=m.useState(!0),[S,T]=m.useState(!1),[z,v]=m.useState(null);m.useEffect(()=>{L()},[o]);async function L(){P(!0);try{const[_,W]=await Promise.all([J.getCatalogProgram(o),J.listPrograms()]);d(_),y(W)}catch(_){v({type:"error",text:_.message||"Could not load program"})}finally{P(!1)}}async function A(){T(!0),v(null);const _=new Date().toISOString().slice(0,10);try{const W=await J.adoptProgram(o,_);v({type:"success",text:"Program started! Redirecting…"}),setTimeout(()=>c(`/programs/${W.id}`),800)}catch(W){v({type:"error",text:W.message}),T(!1)}}if(g)return l.jsx("div",{style:{padding:"2rem",textAlign:"center",color:"var(--text-3)"},children:"Loading..."});if(!s)return l.jsxs("div",{style:{padding:"2rem",textAlign:"center"},children:[l.jsx("p",{style:{color:"var(--text-2)",marginBottom:"1rem"},children:"Program not found."}),l.jsx("button",{onClick:()=>c("/programs"),style:{background:"var(--accent)",color:"#fff",padding:"10px 20px"},children:"← Back to Programs"})]});const R=p.some(_=>_.status==="active"&&_.catalog_id===s.id),N=p.find(_=>_.status==="active"&&_.catalog_id===s.id),j=Ic[s.crawl_status]||Ic.pending,F=Mm(s.workouts);return l.jsxs("div",{style:{padding:"1rem",paddingBottom:"96px",maxWidth:"600px",margin:"0 auto"},children:[l.jsx("button",{onClick:()=>c("/programs"),style:{background:"transparent",color:"var(--text-3)",padding:"8px 0",fontSize:"0.85rem",marginBottom:"0.5rem"},children:"← Programs"}),l.jsxs("div",{style:{background:"var(--card)",borderRadius:"var(--r-lg)",padding:"20px",boxShadow:"var(--shadow-2)",marginBottom:"1rem"},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:"1rem"},children:[l.jsxs("h1",{style:{fontFamily:"var(--font-display)",fontSize:"1.5rem",fontWeight:900,lineHeight:1.2},children:[Bm[s.category]||"📋"," ",s.name]}),l.jsx("span",{style:{fontSize:"0.7rem",fontWeight:700,padding:"4px 10px",borderRadius:"var(--r-full)",color:"#fff",background:j.color,whiteSpace:"nowrap"},children:j.label})]}),s.description&&l.jsx("p",{style:{color:"var(--text-2)",fontSize:"0.88rem",marginTop:"12px",lineHeight:1.5},children:s.description}),l.jsxs("div",{style:{display:"flex",gap:"0.5rem",flexWrap:"wrap",marginTop:"14px"},children:[s.duration_weeks&&l.jsxs("span",{style:ql,children:[s.duration_weeks," weeks"]}),s.frequency_per_week&&l.jsxs("span",{style:ql,children:[s.frequency_per_week,"x/week"]}),s.difficulty&&l.jsx("span",{style:{...ql,color:Lc[s.difficulty]||"var(--text-3)",background:`${Lc[s.difficulty]||"var(--text-3)"}15`},children:s.difficulty}),(s.equipment||[]).map(_=>l.jsx("span",{style:ql,children:_},_))]}),s.source_url&&l.jsx("a",{href:s.source_url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",marginTop:"14px",fontSize:"0.78rem",color:"var(--accent)",textDecoration:"none"},children:"🔗 Original source ↗"})]}),z&&l.jsx("div",{style:{padding:"12px 16px",borderRadius:"var(--r-sm)",marginBottom:"1rem",fontSize:"0.85rem",fontWeight:600,background:z.type==="error"?"var(--red-ghost)":"var(--green-bg)",color:z.type==="error"?"var(--red)":"var(--green-dark)"},children:z.text}),s.crawl_status==="ready"&&!R&&l.jsx("button",{onClick:A,disabled:S,style:{width:"100%",background:S?"var(--text-3)":"var(--green)",color:"#fff",padding:"14px",fontSize:"0.95rem",fontWeight:800,marginBottom:"1.25rem",boxShadow:S?"none":"var(--shadow-green)"},children:S?"Starting...":"Start This Program"}),R&&N&&l.jsx("button",{onClick:()=>c(`/programs/${N.id}`),style:{width:"100%",background:"var(--accent)",color:"#fff",padding:"14px",fontSize:"0.95rem",fontWeight:800,marginBottom:"1.25rem",boxShadow:"var(--shadow-accent)"},children:"✓ Active — Open Your Program"}),s.crawl_status!=="ready"&&l.jsx("div",{style:{padding:"14px",borderRadius:"var(--r)",background:"var(--accent-bg)",color:"var(--accent)",fontSize:"0.85rem",marginBottom:"1.25rem",textAlign:"center"},children:s.crawl_status==="failed"?`Crawl failed: ${s.crawl_error||"unknown error"}`:"Program is being researched. Check back soon."}),s.progression_rules&&l.jsxs("div",{style:{background:"var(--card)",borderRadius:"var(--r)",padding:"16px",marginBottom:"1.25rem",boxShadow:"var(--shadow-1)"},children:[l.jsx("div",{style:{fontSize:"0.72rem",fontWeight:700,color:"var(--accent)",textTransform:"uppercase",letterSpacing:"0.05em",marginBottom:"8px"},children:"📈 Progression"}),l.jsx("p",{style:{fontSize:"0.85rem",color:"var(--text-2)",lineHeight:1.5},children:s.progression_rules})]}),F.length>0&&l.jsxs(l.Fragment,{children:[l.jsx("h2",{style:{fontFamily:"var(--font-display)",fontSize:"1.1rem",fontWeight:800,marginBottom:"0.75rem"},children:"Workouts"}),F.map(([_,W])=>l.jsxs("div",{style:{marginBottom:"1.25rem"},children:[l.jsxs("div",{style:{fontSize:"0.78rem",fontWeight:700,color:"var(--text-3)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:"0.5rem"},children:["Week ",_]}),W.map(B=>l.jsxs("div",{style:{background:"var(--card)",borderRadius:"var(--r-sm)",padding:"14px",marginBottom:"0.5rem",boxShadow:"var(--shadow-1)"},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:B.rest_day?0:"8px"},children:[l.jsx("strong",{style:{fontSize:"0.92rem",fontFamily:"var(--font-display)"},children:B.rest_day?"😴 Rest Day":B.workout_name||`Day ${B.day_number}`}),!B.rest_day&&l.jsxs("span",{style:{fontSize:"0.72rem",color:"var(--text-3)",fontWeight:600},children:[(B.exercises||[]).length," exercises"]})]}),!B.rest_day&&(B.exercises||[]).map((Z,fe)=>l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderTop:fe===0?"1px solid var(--divider)":"none",borderBottom:fed.day_number-p.day_number);return Object.entries(c).sort(([s],[d])=>Number(s)-Number(d))}function Dm(){const[o,c]=m.useState([]),[s,d]=m.useState(!0),[p,y]=m.useState(!1),[g,P]=m.useState(""),[S,T]=m.useState(null),z=m.useRef(null),v=Ge();m.useEffect(()=>{L()},[]),m.useEffect(()=>{var N;(N=z.current)==null||N.scrollIntoView({behavior:"smooth"})},[o]);async function L(){try{const N=await J.getThread();c(N.messages||[])}catch(N){console.error(N)}finally{d(!1)}}async function A(N){N.preventDefault();const j=g.trim();if(!(!j||p)){y(!0),T(null);try{const F=await J.sendSupportMessage(j);P(""),T(F.message),await L()}catch(F){T(F.message)}finally{y(!1)}}}function R(N){const j=new Date(N),_=new Date-j;return _<6e4?"Just now":_<36e5?`${Math.floor(_/6e4)}m ago`:_<864e5?`${Math.floor(_/36e5)}h ago`:j.toLocaleDateString(void 0,{month:"short",day:"numeric"})+" "+j.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"})}return s?l.jsx("div",{style:{padding:"2rem",textAlign:"center",color:"var(--text-3)"},children:"Loading..."}):l.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"calc(100dvh - 64px)",maxWidth:"600px",margin:"0 auto"},children:[l.jsxs("div",{style:{padding:"16px",borderBottom:"1px solid var(--divider)",display:"flex",alignItems:"center",gap:"12px"},children:[l.jsx("button",{onClick:()=>v("/"),style:{background:"transparent",color:"var(--text-3)",padding:"4px 0",fontSize:"1.2rem"},children:"←"}),l.jsxs("div",{children:[l.jsx("h1",{style:{fontFamily:"var(--font-display)",fontSize:"1.2rem",fontWeight:800,margin:0},children:"Support"}),l.jsx("p",{style:{color:"var(--text-3)",fontSize:"0.75rem",margin:0},children:"Ask a question — we'll get back to you"})]})]}),l.jsxs("div",{style:{flex:1,overflow:"auto",padding:"16px",display:"flex",flexDirection:"column",gap:"12px"},children:[o.length===0&&l.jsxs("div",{style:{textAlign:"center",color:"var(--text-3)",fontSize:"0.85rem",marginTop:"2rem"},children:[l.jsx("div",{style:{fontSize:"2rem",marginBottom:"8px"},children:"💬"}),"No messages yet. Ask anything about your workouts, program, or the app."]}),o.map(N=>l.jsx("div",{style:{display:"flex",justifyContent:N.sender==="user"?"flex-end":"flex-start"},children:l.jsxs("div",{style:{maxWidth:"80%",padding:"10px 14px",borderRadius:N.sender==="user"?"var(--r) var(--r) 4px var(--r)":"var(--r) var(--r) var(--r) 4px",background:N.sender==="user"?"var(--accent)":"var(--card)",color:N.sender==="user"?"#fff":"var(--text)",boxShadow:"var(--shadow-1)",fontSize:"0.88rem",lineHeight:1.5},children:[l.jsx("div",{children:N.body}),l.jsxs("div",{style:{fontSize:"0.68rem",marginTop:"4px",opacity:.7,textAlign:"right"},children:[R(N.created_at),N.sender==="user"&&N.read_at&&" ✓"]})]})},N.id)),S&&l.jsx("div",{style:{textAlign:"center",fontSize:"0.8rem",color:"var(--green-dark)",padding:"8px",background:"var(--green-bg)",borderRadius:"var(--r-sm)"},children:S}),l.jsx("div",{ref:z})]}),l.jsxs("form",{onSubmit:A,style:{padding:"12px 16px",borderTop:"1px solid var(--divider)",display:"flex",gap:"8px",background:"var(--card)"},children:[l.jsx("input",{type:"text",value:g,onChange:N=>P(N.target.value),placeholder:"Type your question...",maxLength:2e3,style:{flex:1,padding:"12px 14px",borderRadius:"var(--r-full)",border:"1px solid var(--divider)",fontFamily:"var(--font)",fontSize:"0.88rem",background:"var(--bg)"}}),l.jsx("button",{type:"submit",disabled:!g.trim()||p,style:{background:p?"var(--text-3)":"var(--accent)",color:"#fff",borderRadius:"var(--r-full)",width:"44px",height:"44px",padding:0,display:"flex",alignItems:"center",justifyContent:"center",fontSize:"1.1rem",boxShadow:"var(--shadow-accent)",opacity:g.trim()?1:.5},children:"↑"})]})]})}function Fc(){const{threadId:o}=pa();return o?l.jsx($m,{threadId:o}):l.jsx(Am,{})}function Am(){const[o,c]=m.useState([]),[s,d]=m.useState(!0),[p,y]=m.useState(null),g=Ge();m.useEffect(()=>{P()},[]);async function P(){try{const S=await J.listSupportThreads();c(S)}catch(S){y(S.message)}finally{d(!1)}}return s?l.jsx("div",{style:{padding:"2rem",textAlign:"center",color:"var(--text-3)"},children:"Loading..."}):p?l.jsx("div",{style:{padding:"2rem",textAlign:"center",color:"var(--red)"},children:p}):l.jsxs("div",{style:{padding:"1rem",paddingBottom:"96px",maxWidth:"600px",margin:"0 auto"},children:[l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px",marginBottom:"1.5rem"},children:[l.jsx("button",{onClick:()=>g("/"),style:{background:"transparent",color:"var(--text-3)",padding:"4px 0",fontSize:"1.2rem"},children:"←"}),l.jsx("h1",{style:{fontFamily:"var(--font-display)",fontSize:"1.4rem",fontWeight:900,margin:0},children:"Support Inbox"})]}),o.length===0&&l.jsx("p",{style:{textAlign:"center",color:"var(--text-3)",fontSize:"0.85rem",marginTop:"3rem"},children:"No support conversations yet."}),o.map(S=>l.jsxs("div",{onClick:()=>g(`/support/admin/${S.id}`),style:{background:"var(--card)",borderRadius:"var(--r)",padding:"14px 16px",marginBottom:"0.6rem",boxShadow:"var(--shadow-1)",cursor:"pointer",border:S.unread_admin>0?"2px solid var(--accent-glow)":"1px solid var(--card-border)"},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[l.jsx("strong",{style:{fontFamily:"var(--font-display)",fontSize:"0.95rem"},children:S.user_name}),l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[S.unread_admin>0&&l.jsx("span",{style:{background:"var(--accent)",color:"#fff",fontSize:"0.65rem",fontWeight:800,width:"20px",height:"20px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center"},children:S.unread_admin}),l.jsxs("span",{style:{fontSize:"0.72rem",color:"var(--text-3)"},children:[S.message_count," msgs"]})]})]}),S.last_message&&l.jsxs("p",{style:{color:"var(--text-2)",fontSize:"0.82rem",marginTop:"4px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[l.jsx("span",{style:{color:"var(--text-3)",fontWeight:600},children:S.last_message.sender==="admin"?"You: ":""}),S.last_message.body]})]},S.id))]})}function $m({threadId:o}){const[c,s]=m.useState(null),[d,p]=m.useState(!0),[y,g]=m.useState(!1),[P,S]=m.useState(""),T=m.useRef(null),z=Ge();m.useEffect(()=>{v()},[o]),m.useEffect(()=>{var N;(N=T.current)==null||N.scrollIntoView({behavior:"smooth"})},[c]);async function v(){try{const N=await J.getAdminThread(o);s(N)}catch(N){console.error(N)}finally{p(!1)}}async function L(N){N.preventDefault();const j=P.trim();if(!(!j||y)){g(!0);try{await J.replySupportThread(o,j),S(""),await v()}catch(F){alert(F.message)}finally{g(!1)}}}function A(N){const j=new Date(N);return j.toLocaleDateString(void 0,{month:"short",day:"numeric"})+" "+j.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"})}if(d)return l.jsx("div",{style:{padding:"2rem",textAlign:"center",color:"var(--text-3)"},children:"Loading..."});if(!c)return l.jsx("div",{style:{padding:"2rem",textAlign:"center"},children:"Thread not found"});const R=c.latest_context||{};return l.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"calc(100dvh - 64px)",maxWidth:"600px",margin:"0 auto"},children:[l.jsxs("div",{style:{padding:"14px 16px",borderBottom:"1px solid var(--divider)"},children:[l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[l.jsx("button",{onClick:()=>z("/support/admin"),style:{background:"transparent",color:"var(--text-3)",padding:"4px 0",fontSize:"1.2rem"},children:"←"}),l.jsx("h2",{style:{fontFamily:"var(--font-display)",fontSize:"1.1rem",fontWeight:800,margin:0},children:c.user_name})]}),R.program_name&&l.jsxs("div",{style:{display:"flex",gap:"0.5rem",flexWrap:"wrap",marginTop:"8px",marginLeft:"36px"},children:[l.jsx("span",{style:Fr,children:R.program_name}),R.program_day&&l.jsxs("span",{style:Fr,children:["Day ",R.program_day,"/",R.program_total_days]}),R.program_completion_pct!==void 0&&l.jsxs("span",{style:Fr,children:[R.program_completion_pct,"%"]}),l.jsxs("span",{style:{...Fr,background:R.gate_passed?"var(--green-bg)":"var(--red-ghost)",color:R.gate_passed?"var(--green-dark)":"var(--red)"},children:[R.points_today,"/",R.daily_target," pts ",R.gate_passed?"✓":"✗"]}),R.last_workout&&l.jsxs("span",{style:Fr,children:["Last: ",R.last_workout]})]})]}),l.jsxs("div",{style:{flex:1,overflow:"auto",padding:"16px",display:"flex",flexDirection:"column",gap:"12px"},children:[(c.messages||[]).map(N=>l.jsx("div",{style:{display:"flex",justifyContent:N.sender==="admin"?"flex-end":"flex-start"},children:l.jsxs("div",{style:{maxWidth:"80%",padding:"10px 14px",borderRadius:N.sender==="admin"?"var(--r) var(--r) 4px var(--r)":"var(--r) var(--r) var(--r) 4px",background:N.sender==="admin"?"var(--accent)":"var(--card)",color:N.sender==="admin"?"#fff":"var(--text)",boxShadow:"var(--shadow-1)",fontSize:"0.88rem",lineHeight:1.5},children:[l.jsx("div",{children:N.body}),l.jsxs("div",{style:{fontSize:"0.68rem",marginTop:"4px",opacity:.7,textAlign:"right"},children:[A(N.created_at),N.read_at&&" ✓"]})]})},N.id)),l.jsx("div",{ref:T})]}),l.jsxs("form",{onSubmit:L,style:{padding:"12px 16px",borderTop:"1px solid var(--divider)",display:"flex",gap:"8px",background:"var(--card)"},children:[l.jsx("input",{type:"text",value:P,onChange:N=>S(N.target.value),placeholder:"Reply...",style:{flex:1,padding:"12px 14px",borderRadius:"var(--r-full)",border:"1px solid var(--divider)",fontFamily:"var(--font)",fontSize:"0.88rem",background:"var(--bg)"}}),l.jsx("button",{type:"submit",disabled:!P.trim()||y,style:{background:y?"var(--text-3)":"var(--accent)",color:"#fff",borderRadius:"var(--r-full)",width:"44px",height:"44px",padding:0,display:"flex",alignItems:"center",justifyContent:"center",fontSize:"1.1rem",opacity:P.trim()?1:.5},children:"↑"})]})]})}const Fr={fontSize:"0.68rem",fontWeight:600,padding:"2px 8px",borderRadius:"var(--r-full)",background:"var(--divider)",color:"var(--text-2)"};function Um(){const[o,c]=m.useState([]),[s,d]=m.useState(""),[p,y]=m.useState(!1),[g,P]=m.useState(null),S=m.useRef(null);m.useEffect(()=>{J.getAIStatus().then(P).catch(()=>P({configured:!1}))},[]),m.useEffect(()=>{var v;(v=S.current)==null||v.scrollIntoView({behavior:"smooth"})},[o]);const T=async()=>{const v=s.trim();if(!v||p)return;const L={role:"user",content:v};c(A=>[...A,L]),d(""),y(!0),c(A=>[...A,{role:"assistant",content:""}]);try{const A=o.map(W=>({role:W.role,content:W.content})),R=localStorage.getItem("fitness_token"),j=(await fetch("/api/ai/chat",{method:"POST",headers:{"Content-Type":"application/json",...R?{Authorization:`Bearer ${R}`}:{}},body:JSON.stringify({message:v,history:A})})).body.getReader(),F=new TextDecoder;let _="";for(;;){const{done:W,value:B}=await j.read();if(W)break;_+=F.decode(B,{stream:!0});const Z=_.split(` -`);_=Z.pop()||"";for(const fe of Z)if(fe.startsWith("data: ")&&fe.trim()!=="data: [DONE]")try{const{text:we}=JSON.parse(fe.slice(6));we&&c(xe=>{const re=[...xe],oe=re[re.length-1];return re[re.length-1]={...oe,content:oe.content+we},re})}catch{}}}catch{c(R=>{const N=[...R];return N[N.length-1]={role:"assistant",content:"Connection error. Check that the backend is running and an AI provider is configured in Settings → Integrations."},N})}y(!1)},z=["What should I eat today?","Log my 30-minute run","How am I doing this week?","Create a meal plan for me"];return g&&!g.configured?l.jsxs("div",{className:"page",children:[l.jsx("h1",{className:"page-title",children:"AI Coach"}),l.jsxs("div",{className:"card",style:{textAlign:"center",padding:"32px 20px"},children:[l.jsx("div",{style:{fontSize:"2rem",marginBottom:"12px"},children:"🤖"}),l.jsx("h3",{style:{marginBottom:"8px"},children:"No AI provider connected"}),l.jsx("p",{style:{color:"var(--text-2)",fontSize:"0.9rem",marginBottom:"16px"},children:"Connect OpenAI, OpenRouter, Claude, Ollama, or any other provider to start chatting with your AI fitness coach."}),l.jsx("a",{href:"/settings/integrations",className:"btn-primary",style:{display:"inline-block",padding:"12px 24px",borderRadius:"var(--r)",background:"var(--accent)",color:"var(--text-inv)",textDecoration:"none",fontWeight:600,fontSize:"0.88rem"},children:"Configure AI Provider"})]})]}):l.jsxs("div",{className:"page",style:{display:"flex",flexDirection:"column",paddingBottom:"96px"},children:[l.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"12px"},children:[l.jsx("h1",{className:"page-title",style:{marginBottom:0},children:"AI Coach"}),(g==null?void 0:g.provider)&&l.jsxs("span",{style:{fontFamily:"var(--font-mono)",fontSize:"0.7rem",color:"var(--text-3)",background:"var(--accent-bg)",padding:"4px 10px",borderRadius:"var(--r-full)"},children:[g.provider," · ",g.model]})]}),l.jsxs("div",{style:{flex:1,overflowY:"auto",marginBottom:"12px"},children:[o.length===0&&l.jsxs("div",{style:{textAlign:"center",padding:"24px 0"},children:[l.jsx("p",{style:{color:"var(--text-3)",fontSize:"0.9rem",marginBottom:"16px"},children:"Ask me anything about your fitness, nutrition, or program."}),l.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",justifyContent:"center"},children:z.map(v=>l.jsx("button",{className:"btn-outline btn-sm",onClick:()=>{d(v)},style:{fontSize:"0.8rem"},children:v},v))})]}),o.map((v,L)=>l.jsx("div",{style:{display:"flex",justifyContent:v.role==="user"?"flex-end":"flex-start",marginBottom:"10px"},children:l.jsx("div",{style:{maxWidth:"85%",padding:"10px 14px",borderRadius:v.role==="user"?"var(--r-lg) var(--r-lg) var(--r-sm) var(--r-lg)":"var(--r-lg) var(--r-lg) var(--r-lg) var(--r-sm)",background:v.role==="user"?"var(--accent)":"var(--card)",color:v.role==="user"?"var(--text-inv)":"var(--text)",border:v.role==="user"?"none":"1px solid var(--card-border)",fontSize:"0.9rem",lineHeight:"1.5",whiteSpace:"pre-wrap"},children:v.content||(p&&L===o.length-1?"...":"")})},L)),l.jsx("div",{ref:S})]}),l.jsxs("div",{style:{display:"flex",gap:"8px",position:"sticky",bottom:"72px",background:"var(--bg)",padding:"8px 0"},children:[l.jsx("input",{value:s,onChange:v=>d(v.target.value),onKeyDown:v=>v.key==="Enter"&&!v.shiftKey&&T(),placeholder:p?"Thinking...":"Ask your AI coach...",disabled:p,style:{flex:1}}),l.jsx("button",{onClick:T,disabled:p||!s.trim(),className:"btn-primary",style:{padding:"12px 18px",minWidth:"auto"},children:p?"···":"→"})]})]})}function He({children:o}){return ti()?o:l.jsx(Kp,{to:"/login"})}function Vm(){const[o,c]=m.useState(0),s=Ge(),d=xn(),p=["/login","/onboarding","/support"].some(y=>d.pathname.startsWith(y));return m.useEffect(()=>{if(p||!ti())return;J.getUnreadCount().then(g=>c(g.unread||0)).catch(()=>{});const y=setInterval(()=>{J.getUnreadCount().then(g=>c(g.unread||0)).catch(()=>{})},6e4);return()=>clearInterval(y)},[d.pathname,p]),p?null:l.jsxs("button",{onClick:()=>s("/support"),style:{position:"fixed",top:"12px",right:"12px",zIndex:90,width:"40px",height:"40px",borderRadius:"50%",background:"var(--card)",boxShadow:"var(--shadow-2)",border:"1px solid var(--divider)",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"1.1rem",padding:0,cursor:"pointer"},children:["?",o>0&&l.jsx("span",{style:{position:"absolute",top:"-4px",right:"-4px",background:"var(--red)",color:"#fff",fontSize:"0.6rem",fontWeight:800,width:"18px",height:"18px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",border:"2px solid var(--bg)"},children:o})]})}function Hm(){return l.jsxs("nav",{className:"nav-bar",children:[l.jsxs(Ir,{to:"/",className:({isActive:o})=>`nav-item ${o?"active":""}`,children:[l.jsx("span",{className:"nav-icon",children:"🏠"})," Home"]}),l.jsxs(Ir,{to:"/log",className:({isActive:o})=>`nav-item ${o?"active":""}`,children:[l.jsx("span",{className:"nav-icon",children:"💪"})," Log"]}),l.jsxs(Ir,{to:"/nutrition",className:({isActive:o})=>`nav-item ${o?"active":""}`,children:[l.jsx("span",{className:"nav-icon",children:"🥑"})," Keto"]}),l.jsxs(Ir,{to:"/programs",className:({isActive:o})=>`nav-item ${o?"active":""}`,children:[l.jsx("span",{className:"nav-icon",children:"📋"})," Programs"]}),l.jsxs(Ir,{to:"/chat",className:({isActive:o})=>`nav-item ${o?"active":""}`,children:[l.jsx("span",{className:"nav-icon",children:"🧠"})," Coach"]})]})}function Qm(){return l.jsxs(l.Fragment,{children:[ti()&&l.jsx(Vm,{}),l.jsxs(Yp,{children:[l.jsx(Fe,{path:"/login",element:l.jsx(pm,{})}),l.jsx(Fe,{path:"/onboarding",element:l.jsx(He,{children:l.jsx(Nm,{})})}),l.jsx(Fe,{path:"/",element:l.jsx(He,{children:l.jsx(mm,{})})}),l.jsx(Fe,{path:"/log",element:l.jsx(He,{children:l.jsx(hm,{})})}),l.jsx(Fe,{path:"/food",element:l.jsx(He,{children:l.jsx(gm,{})})}),l.jsx(Fe,{path:"/nutrition",element:l.jsx(He,{children:l.jsx(ym,{})})}),l.jsx(Fe,{path:"/programs",element:l.jsx(He,{children:l.jsx(Im,{})})}),l.jsx(Fe,{path:"/programs/:id",element:l.jsx(He,{children:l.jsx(Fm,{})})}),l.jsx(Fe,{path:"/catalog/:id",element:l.jsx(He,{children:l.jsx(Om,{})})}),l.jsx(Fe,{path:"/rewards",element:l.jsx(He,{children:l.jsx(xm,{})})}),l.jsx(Fe,{path:"/week",element:l.jsx(He,{children:l.jsx(Em,{})})}),l.jsx(Fe,{path:"/settings",element:l.jsx(He,{children:l.jsx(Sm,{})})}),l.jsx(Fe,{path:"/support",element:l.jsx(He,{children:l.jsx(Dm,{})})}),l.jsx(Fe,{path:"/support/admin",element:l.jsx(He,{children:l.jsx(Fc,{})})}),l.jsx(Fe,{path:"/support/admin/:threadId",element:l.jsx(He,{children:l.jsx(Fc,{})})}),l.jsx(Fe,{path:"/welcome",element:l.jsx(Pm,{})}),l.jsx(Fe,{path:"/settings/integrations",element:l.jsx(He,{children:l.jsx(Tm,{})})}),l.jsx(Fe,{path:"/meal-plan",element:l.jsx(He,{children:l.jsx(Rm,{})})}),l.jsx(Fe,{path:"/chat",element:l.jsx(He,{children:l.jsx(Um,{})})})]}),ti()&&l.jsx(Hm,{})]})}lp.createRoot(document.getElementById("root")).render(l.jsx(Bc.StrictMode,{children:l.jsx(rm,{children:l.jsx(Qm,{})})})); diff --git a/diligence/frontend/assets/index-De1TwOuS.js b/diligence/frontend/assets/index-De1TwOuS.js new file mode 100644 index 0000000..a915e23 --- /dev/null +++ b/diligence/frontend/assets/index-De1TwOuS.js @@ -0,0 +1,68 @@ +function Gf(o,c){for(var s=0;sd[f]})}}}return Object.freeze(Object.defineProperty(o,Symbol.toStringTag,{value:"Module"}))}(function(){const c=document.createElement("link").relList;if(c&&c.supports&&c.supports("modulepreload"))return;for(const f of document.querySelectorAll('link[rel="modulepreload"]'))d(f);new MutationObserver(f=>{for(const v of f)if(v.type==="childList")for(const g of v.addedNodes)g.tagName==="LINK"&&g.rel==="modulepreload"&&d(g)}).observe(document,{childList:!0,subtree:!0});function s(f){const v={};return f.integrity&&(v.integrity=f.integrity),f.referrerPolicy&&(v.referrerPolicy=f.referrerPolicy),f.crossOrigin==="use-credentials"?v.credentials="include":f.crossOrigin==="anonymous"?v.credentials="omit":v.credentials="same-origin",v}function d(f){if(f.ep)return;f.ep=!0;const v=s(f);fetch(f.href,v)}})();function Oc(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}var Zo={exports:{}},Ir={},ea={exports:{}},ce={};/** + * @license React + * react.production.min.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */var uc;function Xf(){if(uc)return ce;uc=1;var o=Symbol.for("react.element"),c=Symbol.for("react.portal"),s=Symbol.for("react.fragment"),d=Symbol.for("react.strict_mode"),f=Symbol.for("react.profiler"),v=Symbol.for("react.provider"),g=Symbol.for("react.context"),P=Symbol.for("react.forward_ref"),S=Symbol.for("react.suspense"),T=Symbol.for("react.memo"),z=Symbol.for("react.lazy"),y=Symbol.iterator;function L(w){return w===null||typeof w!="object"?null:(w=y&&w[y]||w["@@iterator"],typeof w=="function"?w:null)}var A={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},R=Object.assign,N={};function j(w,O,ae){this.props=w,this.context=O,this.refs=N,this.updater=ae||A}j.prototype.isReactComponent={},j.prototype.setState=function(w,O){if(typeof w!="object"&&typeof w!="function"&&w!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,w,O,"setState")},j.prototype.forceUpdate=function(w){this.updater.enqueueForceUpdate(this,w,"forceUpdate")};function F(){}F.prototype=j.prototype;function _(w,O,ae){this.props=w,this.context=O,this.refs=N,this.updater=ae||A}var B=_.prototype=new F;B.constructor=_,R(B,j.prototype),B.isPureReactComponent=!0;var W=Array.isArray,Z=Object.prototype.hasOwnProperty,fe={current:null},we={key:!0,ref:!0,__self:!0,__source:!0};function xe(w,O,ae){var ue,se={},b=null,ee=null;if(O!=null)for(ue in O.ref!==void 0&&(ee=O.ref),O.key!==void 0&&(b=""+O.key),O)Z.call(O,ue)&&!we.hasOwnProperty(ue)&&(se[ue]=O[ue]);var ie=arguments.length-2;if(ie===1)se.children=ae;else if(1>>1,O=H[w];if(0>>1;wf(se,V))bf(ee,se)?(H[w]=ee,H[b]=V,w=b):(H[w]=se,H[ue]=V,w=ue);else if(bf(ee,V))H[w]=ee,H[b]=V,w=b;else break e}}return I}function f(H,I){var V=H.sortIndex-I.sortIndex;return V!==0?V:H.id-I.id}if(typeof performance=="object"&&typeof performance.now=="function"){var v=performance;o.unstable_now=function(){return v.now()}}else{var g=Date,P=g.now();o.unstable_now=function(){return g.now()-P}}var S=[],T=[],z=1,y=null,L=3,A=!1,R=!1,N=!1,j=typeof setTimeout=="function"?setTimeout:null,F=typeof clearTimeout=="function"?clearTimeout:null,_=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function B(H){for(var I=s(T);I!==null;){if(I.callback===null)d(T);else if(I.startTime<=H)d(T),I.sortIndex=I.expirationTime,c(S,I);else break;I=s(T)}}function W(H){if(N=!1,B(H),!R)if(s(S)!==null)R=!0,Be(Z);else{var I=s(T);I!==null&&Se(W,I.startTime-H)}}function Z(H,I){R=!1,N&&(N=!1,F(xe),xe=-1),A=!0;var V=L;try{for(B(I),y=s(S);y!==null&&(!(y.expirationTime>I)||H&&!pe());){var w=y.callback;if(typeof w=="function"){y.callback=null,L=y.priorityLevel;var O=w(y.expirationTime<=I);I=o.unstable_now(),typeof O=="function"?y.callback=O:y===s(S)&&d(S),B(I)}else d(S);y=s(S)}if(y!==null)var ae=!0;else{var ue=s(T);ue!==null&&Se(W,ue.startTime-I),ae=!1}return ae}finally{y=null,L=V,A=!1}}var fe=!1,we=null,xe=-1,re=5,oe=-1;function pe(){return!(o.unstable_now()-oeH||125w?(H.sortIndex=V,c(T,H),s(S)===null&&H===s(T)&&(N?(F(xe),xe=-1):N=!0,Se(W,V-w))):(H.sortIndex=O,c(S,H),R||A||(R=!0,Be(Z))),H},o.unstable_shouldYield=pe,o.unstable_wrapCallback=function(H){var I=L;return function(){var V=L;L=I;try{return H.apply(this,arguments)}finally{L=V}}}})(ra)),ra}var mc;function np(){return mc||(mc=1,na.exports=tp()),na.exports}/** + * @license React + * react-dom.production.min.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */var hc;function rp(){if(hc)return lt;hc=1;var o=ca(),c=np();function s(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,n=1;n"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),S=Object.prototype.hasOwnProperty,T=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,z={},y={};function L(e){return S.call(y,e)?!0:S.call(z,e)?!1:T.test(e)?y[e]=!0:(z[e]=!0,!1)}function A(e,t,n,r){if(n!==null&&n.type===0)return!1;switch(typeof t){case"function":case"symbol":return!0;case"boolean":return r?!1:n!==null?!n.acceptsBooleans:(e=e.toLowerCase().slice(0,5),e!=="data-"&&e!=="aria-");default:return!1}}function R(e,t,n,r){if(t===null||typeof t>"u"||A(e,t,n,r))return!0;if(r)return!1;if(n!==null)switch(n.type){case 3:return!t;case 4:return t===!1;case 5:return isNaN(t);case 6:return isNaN(t)||1>t}return!1}function N(e,t,n,r,i,a,u){this.acceptsBooleans=t===2||t===3||t===4,this.attributeName=r,this.attributeNamespace=i,this.mustUseProperty=n,this.propertyName=e,this.type=t,this.sanitizeURL=a,this.removeEmptyString=u}var j={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){j[e]=new N(e,0,!1,e,null,!1,!1)}),[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];j[t]=new N(t,1,!1,e[1],null,!1,!1)}),["contentEditable","draggable","spellCheck","value"].forEach(function(e){j[e]=new N(e,2,!1,e.toLowerCase(),null,!1,!1)}),["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){j[e]=new N(e,2,!1,e,null,!1,!1)}),"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(e){j[e]=new N(e,3,!1,e.toLowerCase(),null,!1,!1)}),["checked","multiple","muted","selected"].forEach(function(e){j[e]=new N(e,3,!0,e,null,!1,!1)}),["capture","download"].forEach(function(e){j[e]=new N(e,4,!1,e,null,!1,!1)}),["cols","rows","size","span"].forEach(function(e){j[e]=new N(e,6,!1,e,null,!1,!1)}),["rowSpan","start"].forEach(function(e){j[e]=new N(e,5,!1,e.toLowerCase(),null,!1,!1)});var F=/[\-:]([a-z])/g;function _(e){return e[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(e){var t=e.replace(F,_);j[t]=new N(t,1,!1,e,null,!1,!1)}),"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var t=e.replace(F,_);j[t]=new N(t,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)}),["xml:base","xml:lang","xml:space"].forEach(function(e){var t=e.replace(F,_);j[t]=new N(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)}),["tabIndex","crossOrigin"].forEach(function(e){j[e]=new N(e,1,!1,e.toLowerCase(),null,!1,!1)}),j.xlinkHref=new N("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1),["src","href","action","formAction"].forEach(function(e){j[e]=new N(e,1,!1,e.toLowerCase(),null,!0,!0)});function B(e,t,n,r){var i=j.hasOwnProperty(t)?j[t]:null;(i!==null?i.type!==0:r||!(2p||i[u]!==a[p]){var h=` +`+i[u].replace(" at new "," at ");return e.displayName&&h.includes("")&&(h=h.replace("",e.displayName)),h}while(1<=u&&0<=p);break}}}finally{ae=!1,Error.prepareStackTrace=n}return(e=e?e.displayName||e.name:"")?O(e):""}function se(e){switch(e.tag){case 5:return O(e.type);case 16:return O("Lazy");case 13:return O("Suspense");case 19:return O("SuspenseList");case 0:case 2:case 15:return e=ue(e.type,!1),e;case 11:return e=ue(e.type.render,!1),e;case 1:return e=ue(e.type,!0),e;default:return""}}function b(e){if(e==null)return null;if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case we:return"Fragment";case fe:return"Portal";case re:return"Profiler";case xe:return"StrictMode";case ve:return"Suspense";case Te:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case pe:return(e.displayName||"Context")+".Consumer";case oe:return(e._context.displayName||"Context")+".Provider";case Ne:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case Me:return t=e.displayName||null,t!==null?t:b(e.type)||"Memo";case Be:t=e._payload,e=e._init;try{return b(e(t))}catch{}}return null}function ee(e){var t=e.type;switch(e.tag){case 24:return"Cache";case 9:return(t.displayName||"Context")+".Consumer";case 10:return(t._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return e=t.render,e=e.displayName||e.name||"",t.displayName||(e!==""?"ForwardRef("+e+")":"ForwardRef");case 7:return"Fragment";case 5:return t;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return b(t);case 8:return t===xe?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t}return null}function ie(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function de(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function ye(e){var t=de(e)?"checked":"value",n=Object.getOwnPropertyDescriptor(e.constructor.prototype,t),r=""+e[t];if(!e.hasOwnProperty(t)&&typeof n<"u"&&typeof n.get=="function"&&typeof n.set=="function"){var i=n.get,a=n.set;return Object.defineProperty(e,t,{configurable:!0,get:function(){return i.call(this)},set:function(u){r=""+u,a.call(this,u)}}),Object.defineProperty(e,t,{enumerable:n.enumerable}),{getValue:function(){return r},setValue:function(u){r=""+u},stopTracking:function(){e._valueTracker=null,delete e[t]}}}}function Or(e){e._valueTracker||(e._valueTracker=ye(e))}function ha(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r="";return e&&(r=de(e)?e.checked?"true":"false":e.value),e=r,e!==n?(t.setValue(e),!0):!1}function Mr(e){if(e=e||(typeof document<"u"?document:void 0),typeof e>"u")return null;try{return e.activeElement||e.body}catch{return e.body}}function ii(e,t){var n=t.checked;return V({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??e._wrapperState.initialChecked})}function ga(e,t){var n=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;n=ie(t.value!=null?t.value:n),e._wrapperState={initialChecked:r,initialValue:n,controlled:t.type==="checkbox"||t.type==="radio"?t.checked!=null:t.value!=null}}function va(e,t){t=t.checked,t!=null&&B(e,"checked",t,!1)}function oi(e,t){va(e,t);var n=ie(t.value),r=t.type;if(n!=null)r==="number"?(n===0&&e.value===""||e.value!=n)&&(e.value=""+n):e.value!==""+n&&(e.value=""+n);else if(r==="submit"||r==="reset"){e.removeAttribute("value");return}t.hasOwnProperty("value")?ai(e,t.type,n):t.hasOwnProperty("defaultValue")&&ai(e,t.type,ie(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function ya(e,t,n){if(t.hasOwnProperty("value")||t.hasOwnProperty("defaultValue")){var r=t.type;if(!(r!=="submit"&&r!=="reset"||t.value!==void 0&&t.value!==null))return;t=""+e._wrapperState.initialValue,n||t===e.value||(e.value=t),e.defaultValue=t}n=e.name,n!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,n!==""&&(e.name=n)}function ai(e,t,n){(t!=="number"||Mr(e.ownerDocument)!==e)&&(n==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+n&&(e.defaultValue=""+n))}var Yn=Array.isArray;function Sn(e,t,n,r){if(e=e.options,t){t={};for(var i=0;i"+t.valueOf().toString()+"",t=Dr.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function Gn(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var Xn={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},Zc=["Webkit","ms","Moz","O"];Object.keys(Xn).forEach(function(e){Zc.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),Xn[t]=Xn[e]})});function _a(e,t,n){return t==null||typeof t=="boolean"||t===""?"":n||typeof t!="number"||t===0||Xn.hasOwnProperty(e)&&Xn[e]?(""+t).trim():t+"px"}function Ca(e,t){e=e.style;for(var n in t)if(t.hasOwnProperty(n)){var r=n.indexOf("--")===0,i=_a(n,t[n],r);n==="float"&&(n="cssFloat"),r?e.setProperty(n,i):e[n]=i}}var ed=V({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function ci(e,t){if(t){if(ed[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(s(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(s(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(s(61))}if(t.style!=null&&typeof t.style!="object")throw Error(s(62))}}function di(e,t){if(e.indexOf("-")===-1)return typeof t.is=="string";switch(e){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var fi=null;function pi(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var mi=null,wn=null,jn=null;function Na(e){if(e=xr(e)){if(typeof mi!="function")throw Error(s(280));var t=e.stateNode;t&&(t=ul(t),mi(e.stateNode,e.type,t))}}function Ea(e){wn?jn?jn.push(e):jn=[e]:wn=e}function Pa(){if(wn){var e=wn,t=jn;if(jn=wn=null,Na(e),t)for(e=0;e>>=0,e===0?32:31-(dd(e)/fd|0)|0}var Hr=64,Qr=4194304;function tr(e){switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return e&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return e&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return e}}function Kr(e,t){var n=e.pendingLanes;if(n===0)return 0;var r=0,i=e.suspendedLanes,a=e.pingedLanes,u=n&268435455;if(u!==0){var p=u&~i;p!==0?r=tr(p):(a&=u,a!==0&&(r=tr(a)))}else u=n&~i,u!==0?r=tr(u):a!==0&&(r=tr(a));if(r===0)return 0;if(t!==0&&t!==r&&(t&i)===0&&(i=r&-r,a=t&-t,i>=a||i===16&&(a&4194240)!==0))return t;if((r&4)!==0&&(r|=n&16),t=e.entangledLanes,t!==0)for(e=e.entanglements,t&=r;0n;n++)t.push(e);return t}function nr(e,t,n){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-ht(t),e[t]=n}function gd(e,t){var n=e.pendingLanes&~t;e.pendingLanes=t,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=t,e.mutableReadLanes&=t,e.entangledLanes&=t,t=e.entanglements;var r=e.eventTimes;for(e=e.expirationTimes;0=cr),ns=" ",rs=!1;function ls(e,t){switch(e){case"keyup":return Vd.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function is(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Cn=!1;function Qd(e,t){switch(e){case"compositionend":return is(t);case"keypress":return t.which!==32?null:(rs=!0,ns);case"textInput":return e=t.data,e===ns&&rs?null:e;default:return null}}function Kd(e,t){if(Cn)return e==="compositionend"||!Ri&&ls(e,t)?(e=Ga(),qr=Ni=$t=null,Cn=!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:n,offset:t-e};e=r}e:{for(;n;){if(n.nextSibling){n=n.nextSibling;break e}n=n.parentNode}n=void 0}n=fs(n)}}function ms(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?ms(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function hs(){for(var e=window,t=Mr();t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href=="string"}catch{n=!1}if(n)e=t.contentWindow;else break;t=Mr(e.document)}return t}function Fi(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")}function nf(e){var t=hs(),n=e.focusedElem,r=e.selectionRange;if(t!==n&&n&&n.ownerDocument&&ms(n.ownerDocument.documentElement,n)){if(r!==null&&Fi(n)){if(t=r.start,e=r.end,e===void 0&&(e=t),"selectionStart"in n)n.selectionStart=t,n.selectionEnd=Math.min(e,n.value.length);else if(e=(t=n.ownerDocument||document)&&t.defaultView||window,e.getSelection){e=e.getSelection();var i=n.textContent.length,a=Math.min(r.start,i);r=r.end===void 0?a:Math.min(r.end,i),!e.extend&&a>r&&(i=r,r=a,a=i),i=ps(n,a);var u=ps(n,r);i&&u&&(e.rangeCount!==1||e.anchorNode!==i.node||e.anchorOffset!==i.offset||e.focusNode!==u.node||e.focusOffset!==u.offset)&&(t=t.createRange(),t.setStart(i.node,i.offset),e.removeAllRanges(),a>r?(e.addRange(t),e.extend(u.node,u.offset)):(t.setEnd(u.node,u.offset),e.addRange(t)))}}for(t=[],e=n;e=e.parentNode;)e.nodeType===1&&t.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof n.focus=="function"&&n.focus(),n=0;n=document.documentMode,Nn=null,Bi=null,mr=null,Wi=!1;function gs(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;Wi||Nn==null||Nn!==Mr(r)||(r=Nn,"selectionStart"in r&&Fi(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),mr&&pr(mr,r)||(mr=r,r=ol(Bi,"onSelect"),0bn||(e.current=Yi[bn],Yi[bn]=null,bn--)}function je(e,t){bn++,Yi[bn]=e.current,e.current=t}var Qt={},Qe=Ht(Qt),Ze=Ht(!1),sn=Qt;function Rn(e,t){var n=e.type.contextTypes;if(!n)return Qt;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===t)return r.__reactInternalMemoizedMaskedChildContext;var i={},a;for(a in n)i[a]=t[a];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=t,e.__reactInternalMemoizedMaskedChildContext=i),i}function et(e){return e=e.childContextTypes,e!=null}function cl(){_e(Ze),_e(Qe)}function bs(e,t,n){if(Qe.current!==Qt)throw Error(s(168));je(Qe,t),je(Ze,n)}function Rs(e,t,n){var r=e.stateNode;if(t=t.childContextTypes,typeof r.getChildContext!="function")return n;r=r.getChildContext();for(var i in r)if(!(i in t))throw Error(s(108,ee(e)||"Unknown",i));return V({},n,r)}function dl(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||Qt,sn=Qe.current,je(Qe,e),je(Ze,Ze.current),!0}function Ls(e,t,n){var r=e.stateNode;if(!r)throw Error(s(169));n?(e=Rs(e,t,sn),r.__reactInternalMemoizedMergedChildContext=e,_e(Ze),_e(Qe),je(Qe,e)):_e(Ze),je(Ze,n)}var Pt=null,fl=!1,Gi=!1;function Is(e){Pt===null?Pt=[e]:Pt.push(e)}function hf(e){fl=!0,Is(e)}function Kt(){if(!Gi&&Pt!==null){Gi=!0;var e=0,t=ge;try{var n=Pt;for(ge=1;e>=u,i-=u,zt=1<<32-ht(t)+i|n<le?($e=ne,ne=null):$e=ne.sibling;var he=M(k,ne,C[le],U);if(he===null){ne===null&&(ne=$e);break}e&&ne&&he.alternate===null&&t(k,ne),x=a(he,x,le),te===null?q=he:te.sibling=he,te=he,ne=$e}if(le===C.length)return n(k,ne),Ce&&cn(k,le),q;if(ne===null){for(;lele?($e=ne,ne=null):$e=ne.sibling;var nn=M(k,ne,he.value,U);if(nn===null){ne===null&&(ne=$e);break}e&&ne&&nn.alternate===null&&t(k,ne),x=a(nn,x,le),te===null?q=nn:te.sibling=nn,te=nn,ne=$e}if(he.done)return n(k,ne),Ce&&cn(k,le),q;if(ne===null){for(;!he.done;le++,he=C.next())he=$(k,he.value,U),he!==null&&(x=a(he,x,le),te===null?q=he:te.sibling=he,te=he);return Ce&&cn(k,le),q}for(ne=r(k,ne);!he.done;le++,he=C.next())he=Q(ne,k,le,he.value,U),he!==null&&(e&&he.alternate!==null&&ne.delete(he.key===null?le:he.key),x=a(he,x,le),te===null?q=he:te.sibling=he,te=he);return e&&ne.forEach(function(Yf){return t(k,Yf)}),Ce&&cn(k,le),q}function Le(k,x,C,U){if(typeof C=="object"&&C!==null&&C.type===we&&C.key===null&&(C=C.props.children),typeof C=="object"&&C!==null){switch(C.$$typeof){case Z:e:{for(var q=C.key,te=x;te!==null;){if(te.key===q){if(q=C.type,q===we){if(te.tag===7){n(k,te.sibling),x=i(te,C.props.children),x.return=k,k=x;break e}}else if(te.elementType===q||typeof q=="object"&&q!==null&&q.$$typeof===Be&&Ds(q)===te.type){n(k,te.sibling),x=i(te,C.props),x.ref=Sr(k,te,C),x.return=k,k=x;break e}n(k,te);break}else t(k,te);te=te.sibling}C.type===we?(x=yn(C.props.children,k.mode,U,C.key),x.return=k,k=x):(U=Dl(C.type,C.key,C.props,null,k.mode,U),U.ref=Sr(k,x,C),U.return=k,k=U)}return u(k);case fe:e:{for(te=C.key;x!==null;){if(x.key===te)if(x.tag===4&&x.stateNode.containerInfo===C.containerInfo&&x.stateNode.implementation===C.implementation){n(k,x.sibling),x=i(x,C.children||[]),x.return=k,k=x;break e}else{n(k,x);break}else t(k,x);x=x.sibling}x=Jo(C,k.mode,U),x.return=k,k=x}return u(k);case Be:return te=C._init,Le(k,x,te(C._payload),U)}if(Yn(C))return G(k,x,C,U);if(I(C))return X(k,x,C,U);gl(k,C)}return typeof C=="string"&&C!==""||typeof C=="number"?(C=""+C,x!==null&&x.tag===6?(n(k,x.sibling),x=i(x,C),x.return=k,k=x):(n(k,x),x=Ko(C,k.mode,U),x.return=k,k=x),u(k)):n(k,x)}return Le}var Bn=As(!0),$s=As(!1),vl=Ht(null),yl=null,Wn=null,no=null;function ro(){no=Wn=yl=null}function lo(e){var t=vl.current;_e(vl),e._currentValue=t}function io(e,t,n){for(;e!==null;){var r=e.alternate;if((e.childLanes&t)!==t?(e.childLanes|=t,r!==null&&(r.childLanes|=t)):r!==null&&(r.childLanes&t)!==t&&(r.childLanes|=t),e===n)break;e=e.return}}function On(e,t){yl=e,no=Wn=null,e=e.dependencies,e!==null&&e.firstContext!==null&&((e.lanes&t)!==0&&(tt=!0),e.firstContext=null)}function dt(e){var t=e._currentValue;if(no!==e)if(e={context:e,memoizedValue:t,next:null},Wn===null){if(yl===null)throw Error(s(308));Wn=e,yl.dependencies={lanes:0,firstContext:e}}else Wn=Wn.next=e;return t}var dn=null;function oo(e){dn===null?dn=[e]:dn.push(e)}function Us(e,t,n,r){var i=t.interleaved;return i===null?(n.next=n,oo(t)):(n.next=i.next,i.next=n),t.interleaved=n,bt(e,r)}function bt(e,t){e.lanes|=t;var n=e.alternate;for(n!==null&&(n.lanes|=t),n=e,e=e.return;e!==null;)e.childLanes|=t,n=e.alternate,n!==null&&(n.childLanes|=t),n=e,e=e.return;return n.tag===3?n.stateNode:null}var Jt=!1;function ao(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function Vs(e,t){e=e.updateQueue,t.updateQueue===e&&(t.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,effects:e.effects})}function Rt(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function Yt(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,(me&2)!==0){var i=r.pending;return i===null?t.next=t:(t.next=i.next,i.next=t),r.pending=t,bt(e,n)}return i=r.interleaved,i===null?(t.next=t,oo(r)):(t.next=i.next,i.next=t),r.interleaved=t,bt(e,n)}function xl(e,t,n){if(t=t.updateQueue,t!==null&&(t=t.shared,(n&4194240)!==0)){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,wi(e,n)}}function Hs(e,t){var n=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,n===r)){var i=null,a=null;if(n=n.firstBaseUpdate,n!==null){do{var u={eventTime:n.eventTime,lane:n.lane,tag:n.tag,payload:n.payload,callback:n.callback,next:null};a===null?i=a=u:a=a.next=u,n=n.next}while(n!==null);a===null?i=a=t:a=a.next=t}else i=a=t;n={baseState:r.baseState,firstBaseUpdate:i,lastBaseUpdate:a,shared:r.shared,effects:r.effects},e.updateQueue=n;return}e=n.lastBaseUpdate,e===null?n.firstBaseUpdate=t:e.next=t,n.lastBaseUpdate=t}function Sl(e,t,n,r){var i=e.updateQueue;Jt=!1;var a=i.firstBaseUpdate,u=i.lastBaseUpdate,p=i.shared.pending;if(p!==null){i.shared.pending=null;var h=p,E=h.next;h.next=null,u===null?a=E:u.next=E,u=h;var D=e.alternate;D!==null&&(D=D.updateQueue,p=D.lastBaseUpdate,p!==u&&(p===null?D.firstBaseUpdate=E:p.next=E,D.lastBaseUpdate=h))}if(a!==null){var $=i.baseState;u=0,D=E=h=null,p=a;do{var M=p.lane,Q=p.eventTime;if((r&M)===M){D!==null&&(D=D.next={eventTime:Q,lane:0,tag:p.tag,payload:p.payload,callback:p.callback,next:null});e:{var G=e,X=p;switch(M=t,Q=n,X.tag){case 1:if(G=X.payload,typeof G=="function"){$=G.call(Q,$,M);break e}$=G;break e;case 3:G.flags=G.flags&-65537|128;case 0:if(G=X.payload,M=typeof G=="function"?G.call(Q,$,M):G,M==null)break e;$=V({},$,M);break e;case 2:Jt=!0}}p.callback!==null&&p.lane!==0&&(e.flags|=64,M=i.effects,M===null?i.effects=[p]:M.push(p))}else Q={eventTime:Q,lane:M,tag:p.tag,payload:p.payload,callback:p.callback,next:null},D===null?(E=D=Q,h=$):D=D.next=Q,u|=M;if(p=p.next,p===null){if(p=i.shared.pending,p===null)break;M=p,p=M.next,M.next=null,i.lastBaseUpdate=M,i.shared.pending=null}}while(!0);if(D===null&&(h=$),i.baseState=h,i.firstBaseUpdate=E,i.lastBaseUpdate=D,t=i.shared.interleaved,t!==null){i=t;do u|=i.lane,i=i.next;while(i!==t)}else a===null&&(i.shared.lanes=0);mn|=u,e.lanes=u,e.memoizedState=$}}function Qs(e,t,n){if(e=t.effects,t.effects=null,e!==null)for(t=0;tn?n:4,e(!0);var r=po.transition;po.transition={};try{e(!1),t()}finally{ge=n,po.transition=r}}function du(){return ft().memoizedState}function xf(e,t,n){var r=Zt(e);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},fu(e))pu(t,n);else if(n=Us(e,t,n,r),n!==null){var i=qe();wt(n,e,r,i),mu(n,t,r)}}function Sf(e,t,n){var r=Zt(e),i={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(fu(e))pu(t,i);else{var a=e.alternate;if(e.lanes===0&&(a===null||a.lanes===0)&&(a=t.lastRenderedReducer,a!==null))try{var u=t.lastRenderedState,p=a(u,n);if(i.hasEagerState=!0,i.eagerState=p,gt(p,u)){var h=t.interleaved;h===null?(i.next=i,oo(t)):(i.next=h.next,h.next=i),t.interleaved=i;return}}catch{}finally{}n=Us(e,t,i,r),n!==null&&(i=qe(),wt(n,e,r,i),mu(n,t,r))}}function fu(e){var t=e.alternate;return e===Pe||t!==null&&t===Pe}function pu(e,t){_r=kl=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function mu(e,t,n){if((n&4194240)!==0){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,wi(e,n)}}var Nl={readContext:dt,useCallback:Ke,useContext:Ke,useEffect:Ke,useImperativeHandle:Ke,useInsertionEffect:Ke,useLayoutEffect:Ke,useMemo:Ke,useReducer:Ke,useRef:Ke,useState:Ke,useDebugValue:Ke,useDeferredValue:Ke,useTransition:Ke,useMutableSource:Ke,useSyncExternalStore:Ke,useId:Ke,unstable_isNewReconciler:!1},wf={readContext:dt,useCallback:function(e,t){return Ct().memoizedState=[e,t===void 0?null:t],e},useContext:dt,useEffect:ru,useImperativeHandle:function(e,t,n){return n=n!=null?n.concat([e]):null,_l(4194308,4,ou.bind(null,t,e),n)},useLayoutEffect:function(e,t){return _l(4194308,4,e,t)},useInsertionEffect:function(e,t){return _l(4,2,e,t)},useMemo:function(e,t){var n=Ct();return t=t===void 0?null:t,e=e(),n.memoizedState=[e,t],e},useReducer:function(e,t,n){var r=Ct();return t=n!==void 0?n(t):t,r.memoizedState=r.baseState=t,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:t},r.queue=e,e=e.dispatch=xf.bind(null,Pe,e),[r.memoizedState,e]},useRef:function(e){var t=Ct();return e={current:e},t.memoizedState=e},useState:tu,useDebugValue:So,useDeferredValue:function(e){return Ct().memoizedState=e},useTransition:function(){var e=tu(!1),t=e[0];return e=yf.bind(null,e[1]),Ct().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,n){var r=Pe,i=Ct();if(Ce){if(n===void 0)throw Error(s(407));n=n()}else{if(n=t(),Ae===null)throw Error(s(349));(pn&30)!==0||Gs(r,t,n)}i.memoizedState=n;var a={value:n,getSnapshot:t};return i.queue=a,ru(qs.bind(null,r,a,e),[e]),r.flags|=2048,Er(9,Xs.bind(null,r,a,n,t),void 0,null),n},useId:function(){var e=Ct(),t=Ae.identifierPrefix;if(Ce){var n=Tt,r=zt;n=(r&~(1<<32-ht(r)-1)).toString(32)+n,t=":"+t+"R"+n,n=Cr++,0<\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=u.createElement(n,{is:r.is}):(e=u.createElement(n),n==="select"&&(u=e,r.multiple?u.multiple=!0:r.size&&(u.size=r.size))):e=u.createElementNS(e,n),e[kt]=t,e[yr]=r,Iu(e,t,!1,!1),t.stateNode=e;e:{switch(u=di(n,r),n){case"dialog":ke("cancel",e),ke("close",e),i=r;break;case"iframe":case"object":case"embed":ke("load",e),i=r;break;case"video":case"audio":for(i=0;iUn&&(t.flags|=128,r=!0,Pr(a,!1),t.lanes=4194304)}else{if(!r)if(e=wl(u),e!==null){if(t.flags|=128,r=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),Pr(a,!0),a.tail===null&&a.tailMode==="hidden"&&!u.alternate&&!Ce)return Je(t),null}else 2*Re()-a.renderingStartTime>Un&&n!==1073741824&&(t.flags|=128,r=!0,Pr(a,!1),t.lanes=4194304);a.isBackwards?(u.sibling=t.child,t.child=u):(n=a.last,n!==null?n.sibling=u:t.child=u,a.last=u)}return a.tail!==null?(t=a.tail,a.rendering=t,a.tail=t.sibling,a.renderingStartTime=Re(),t.sibling=null,n=Ee.current,je(Ee,r?n&1|2:n&1),t):(Je(t),null);case 22:case 23:return Vo(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&(t.mode&1)!==0?(st&1073741824)!==0&&(Je(t),t.subtreeFlags&6&&(t.flags|=8192)):Je(t),null;case 24:return null;case 25:return null}throw Error(s(156,t.tag))}function zf(e,t){switch(qi(t),t.tag){case 1:return et(t.type)&&cl(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return Mn(),_e(Ze),_e(Qe),fo(),e=t.flags,(e&65536)!==0&&(e&128)===0?(t.flags=e&-65537|128,t):null;case 5:return uo(t),null;case 13:if(_e(Ee),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(s(340));Fn()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return _e(Ee),null;case 4:return Mn(),null;case 10:return lo(t.type._context),null;case 22:case 23:return Vo(),null;case 24:return null;default:return null}}var Tl=!1,Ye=!1,Tf=typeof WeakSet=="function"?WeakSet:Set,Y=null;function An(e,t){var n=e.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){be(e,t,r)}else n.current=null}function Ro(e,t,n){try{n()}catch(r){be(e,t,r)}}var Wu=!1;function bf(e,t){if(Ui=Gr,e=hs(),Fi(e)){if("selectionStart"in e)var n={start:e.selectionStart,end:e.selectionEnd};else e:{n=(n=e.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var i=r.anchorOffset,a=r.focusNode;r=r.focusOffset;try{n.nodeType,a.nodeType}catch{n=null;break e}var u=0,p=-1,h=-1,E=0,D=0,$=e,M=null;t:for(;;){for(var Q;$!==n||i!==0&&$.nodeType!==3||(p=u+i),$!==a||r!==0&&$.nodeType!==3||(h=u+r),$.nodeType===3&&(u+=$.nodeValue.length),(Q=$.firstChild)!==null;)M=$,$=Q;for(;;){if($===e)break t;if(M===n&&++E===i&&(p=u),M===a&&++D===r&&(h=u),(Q=$.nextSibling)!==null)break;$=M,M=$.parentNode}$=Q}n=p===-1||h===-1?null:{start:p,end:h}}else n=null}n=n||{start:0,end:0}}else n=null;for(Vi={focusedElem:e,selectionRange:n},Gr=!1,Y=t;Y!==null;)if(t=Y,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,Y=e;else for(;Y!==null;){t=Y;try{var G=t.alternate;if((t.flags&1024)!==0)switch(t.tag){case 0:case 11:case 15:break;case 1:if(G!==null){var X=G.memoizedProps,Le=G.memoizedState,k=t.stateNode,x=k.getSnapshotBeforeUpdate(t.elementType===t.type?X:yt(t.type,X),Le);k.__reactInternalSnapshotBeforeUpdate=x}break;case 3:var C=t.stateNode.containerInfo;C.nodeType===1?C.textContent="":C.nodeType===9&&C.documentElement&&C.removeChild(C.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(s(163))}}catch(U){be(t,t.return,U)}if(e=t.sibling,e!==null){e.return=t.return,Y=e;break}Y=t.return}return G=Wu,Wu=!1,G}function zr(e,t,n){var r=t.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var i=r=r.next;do{if((i.tag&e)===e){var a=i.destroy;i.destroy=void 0,a!==void 0&&Ro(t,n,a)}i=i.next}while(i!==r)}}function bl(e,t){if(t=t.updateQueue,t=t!==null?t.lastEffect:null,t!==null){var n=t=t.next;do{if((n.tag&e)===e){var r=n.create;n.destroy=r()}n=n.next}while(n!==t)}}function Lo(e){var t=e.ref;if(t!==null){var n=e.stateNode;switch(e.tag){case 5:e=n;break;default:e=n}typeof t=="function"?t(e):t.current=e}}function Ou(e){var t=e.alternate;t!==null&&(e.alternate=null,Ou(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[kt],delete t[yr],delete t[Ji],delete t[pf],delete t[mf])),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}function Mu(e){return e.tag===5||e.tag===3||e.tag===4}function Du(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||Mu(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function Io(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.nodeType===8?n.parentNode.insertBefore(e,t):n.insertBefore(e,t):(n.nodeType===8?(t=n.parentNode,t.insertBefore(e,n)):(t=n,t.appendChild(e)),n=n._reactRootContainer,n!=null||t.onclick!==null||(t.onclick=sl));else if(r!==4&&(e=e.child,e!==null))for(Io(e,t,n),e=e.sibling;e!==null;)Io(e,t,n),e=e.sibling}function Fo(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.insertBefore(e,t):n.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(Fo(e,t,n),e=e.sibling;e!==null;)Fo(e,t,n),e=e.sibling}var Ve=null,xt=!1;function Gt(e,t,n){for(n=n.child;n!==null;)Au(e,t,n),n=n.sibling}function Au(e,t,n){if(jt&&typeof jt.onCommitFiberUnmount=="function")try{jt.onCommitFiberUnmount(Vr,n)}catch{}switch(n.tag){case 5:Ye||An(n,t);case 6:var r=Ve,i=xt;Ve=null,Gt(e,t,n),Ve=r,xt=i,Ve!==null&&(xt?(e=Ve,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):Ve.removeChild(n.stateNode));break;case 18:Ve!==null&&(xt?(e=Ve,n=n.stateNode,e.nodeType===8?Ki(e.parentNode,n):e.nodeType===1&&Ki(e,n),ar(e)):Ki(Ve,n.stateNode));break;case 4:r=Ve,i=xt,Ve=n.stateNode.containerInfo,xt=!0,Gt(e,t,n),Ve=r,xt=i;break;case 0:case 11:case 14:case 15:if(!Ye&&(r=n.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){i=r=r.next;do{var a=i,u=a.destroy;a=a.tag,u!==void 0&&((a&2)!==0||(a&4)!==0)&&Ro(n,t,u),i=i.next}while(i!==r)}Gt(e,t,n);break;case 1:if(!Ye&&(An(n,t),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(p){be(n,t,p)}Gt(e,t,n);break;case 21:Gt(e,t,n);break;case 22:n.mode&1?(Ye=(r=Ye)||n.memoizedState!==null,Gt(e,t,n),Ye=r):Gt(e,t,n);break;default:Gt(e,t,n)}}function $u(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new Tf),t.forEach(function(r){var i=Df.bind(null,e,r);n.has(r)||(n.add(r),r.then(i,i))})}}function St(e,t){var n=t.deletions;if(n!==null)for(var r=0;ri&&(i=u),r&=~a}if(r=i,r=Re()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*Lf(r/1960))-r,10e?16:e,qt===null)var r=!1;else{if(e=qt,qt=null,Bl=0,(me&6)!==0)throw Error(s(331));var i=me;for(me|=4,Y=e.current;Y!==null;){var a=Y,u=a.child;if((Y.flags&16)!==0){var p=a.deletions;if(p!==null){for(var h=0;hRe()-Oo?gn(e,0):Wo|=n),rt(e,t)}function tc(e,t){t===0&&((e.mode&1)===0?t=1:(t=Qr,Qr<<=1,(Qr&130023424)===0&&(Qr=4194304)));var n=qe();e=bt(e,t),e!==null&&(nr(e,t,n),rt(e,n))}function Mf(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),tc(e,n)}function Df(e,t){var n=0;switch(e.tag){case 13:var r=e.stateNode,i=e.memoizedState;i!==null&&(n=i.retryLane);break;case 19:r=e.stateNode;break;default:throw Error(s(314))}r!==null&&r.delete(t),tc(e,n)}var nc;nc=function(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps||Ze.current)tt=!0;else{if((e.lanes&n)===0&&(t.flags&128)===0)return tt=!1,Ef(e,t,n);tt=(e.flags&131072)!==0}else tt=!1,Ce&&(t.flags&1048576)!==0&&Fs(t,ml,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;zl(e,t),e=t.pendingProps;var i=Rn(t,Qe.current);On(t,n),i=ho(null,t,r,e,i,n);var a=go();return t.flags|=1,typeof i=="object"&&i!==null&&typeof i.render=="function"&&i.$$typeof===void 0?(t.tag=1,t.memoizedState=null,t.updateQueue=null,et(r)?(a=!0,dl(t)):a=!1,t.memoizedState=i.state!==null&&i.state!==void 0?i.state:null,ao(t),i.updater=El,t.stateNode=i,i._reactInternals=t,jo(t,r,e,n),t=No(null,t,r,!0,a,n)):(t.tag=0,Ce&&a&&Xi(t),Xe(null,t,i,n),t=t.child),t;case 16:r=t.elementType;e:{switch(zl(e,t),e=t.pendingProps,i=r._init,r=i(r._payload),t.type=r,i=t.tag=$f(r),e=yt(r,e),i){case 0:t=Co(null,t,r,e,n);break e;case 1:t=Pu(null,t,r,e,n);break e;case 11:t=ku(null,t,r,e,n);break e;case 14:t=_u(null,t,r,yt(r.type,e),n);break e}throw Error(s(306,r,""))}return t;case 0:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:yt(r,i),Co(e,t,r,i,n);case 1:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:yt(r,i),Pu(e,t,r,i,n);case 3:e:{if(zu(t),e===null)throw Error(s(387));r=t.pendingProps,a=t.memoizedState,i=a.element,Vs(e,t),Sl(t,r,null,n);var u=t.memoizedState;if(r=u.element,a.isDehydrated)if(a={element:r,isDehydrated:!1,cache:u.cache,pendingSuspenseBoundaries:u.pendingSuspenseBoundaries,transitions:u.transitions},t.updateQueue.baseState=a,t.memoizedState=a,t.flags&256){i=Dn(Error(s(423)),t),t=Tu(e,t,r,n,i);break e}else if(r!==i){i=Dn(Error(s(424)),t),t=Tu(e,t,r,n,i);break e}else for(at=Vt(t.stateNode.containerInfo.firstChild),ot=t,Ce=!0,vt=null,n=$s(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(Fn(),r===i){t=Lt(e,t,n);break e}Xe(e,t,r,n)}t=t.child}return t;case 5:return Ks(t),e===null&&eo(t),r=t.type,i=t.pendingProps,a=e!==null?e.memoizedProps:null,u=i.children,Hi(r,i)?u=null:a!==null&&Hi(r,a)&&(t.flags|=32),Eu(e,t),Xe(e,t,u,n),t.child;case 6:return e===null&&eo(t),null;case 13:return bu(e,t,n);case 4:return so(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=Bn(t,null,r,n):Xe(e,t,r,n),t.child;case 11:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:yt(r,i),ku(e,t,r,i,n);case 7:return Xe(e,t,t.pendingProps,n),t.child;case 8:return Xe(e,t,t.pendingProps.children,n),t.child;case 12:return Xe(e,t,t.pendingProps.children,n),t.child;case 10:e:{if(r=t.type._context,i=t.pendingProps,a=t.memoizedProps,u=i.value,je(vl,r._currentValue),r._currentValue=u,a!==null)if(gt(a.value,u)){if(a.children===i.children&&!Ze.current){t=Lt(e,t,n);break e}}else for(a=t.child,a!==null&&(a.return=t);a!==null;){var p=a.dependencies;if(p!==null){u=a.child;for(var h=p.firstContext;h!==null;){if(h.context===r){if(a.tag===1){h=Rt(-1,n&-n),h.tag=2;var E=a.updateQueue;if(E!==null){E=E.shared;var D=E.pending;D===null?h.next=h:(h.next=D.next,D.next=h),E.pending=h}}a.lanes|=n,h=a.alternate,h!==null&&(h.lanes|=n),io(a.return,n,t),p.lanes|=n;break}h=h.next}}else if(a.tag===10)u=a.type===t.type?null:a.child;else if(a.tag===18){if(u=a.return,u===null)throw Error(s(341));u.lanes|=n,p=u.alternate,p!==null&&(p.lanes|=n),io(u,n,t),u=a.sibling}else u=a.child;if(u!==null)u.return=a;else for(u=a;u!==null;){if(u===t){u=null;break}if(a=u.sibling,a!==null){a.return=u.return,u=a;break}u=u.return}a=u}Xe(e,t,i.children,n),t=t.child}return t;case 9:return i=t.type,r=t.pendingProps.children,On(t,n),i=dt(i),r=r(i),t.flags|=1,Xe(e,t,r,n),t.child;case 14:return r=t.type,i=yt(r,t.pendingProps),i=yt(r.type,i),_u(e,t,r,i,n);case 15:return Cu(e,t,t.type,t.pendingProps,n);case 17:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:yt(r,i),zl(e,t),t.tag=1,et(r)?(e=!0,dl(t)):e=!1,On(t,n),gu(t,r,i),jo(t,r,i,n),No(null,t,r,!0,e,n);case 19:return Lu(e,t,n);case 22:return Nu(e,t,n)}throw Error(s(156,t.tag))};function rc(e,t){return Ba(e,t)}function Af(e,t,n,r){this.tag=e,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function mt(e,t,n,r){return new Af(e,t,n,r)}function Qo(e){return e=e.prototype,!(!e||!e.isReactComponent)}function $f(e){if(typeof e=="function")return Qo(e)?1:0;if(e!=null){if(e=e.$$typeof,e===Ne)return 11;if(e===Me)return 14}return 2}function tn(e,t){var n=e.alternate;return n===null?(n=mt(e.tag,t,e.key,e.mode),n.elementType=e.elementType,n.type=e.type,n.stateNode=e.stateNode,n.alternate=e,e.alternate=n):(n.pendingProps=t,n.type=e.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=e.flags&14680064,n.childLanes=e.childLanes,n.lanes=e.lanes,n.child=e.child,n.memoizedProps=e.memoizedProps,n.memoizedState=e.memoizedState,n.updateQueue=e.updateQueue,t=e.dependencies,n.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},n.sibling=e.sibling,n.index=e.index,n.ref=e.ref,n}function Dl(e,t,n,r,i,a){var u=2;if(r=e,typeof e=="function")Qo(e)&&(u=1);else if(typeof e=="string")u=5;else e:switch(e){case we:return yn(n.children,i,a,t);case xe:u=8,i|=8;break;case re:return e=mt(12,n,t,i|2),e.elementType=re,e.lanes=a,e;case ve:return e=mt(13,n,t,i),e.elementType=ve,e.lanes=a,e;case Te:return e=mt(19,n,t,i),e.elementType=Te,e.lanes=a,e;case Se:return Al(n,i,a,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case oe:u=10;break e;case pe:u=9;break e;case Ne:u=11;break e;case Me:u=14;break e;case Be:u=16,r=null;break e}throw Error(s(130,e==null?e:typeof e,""))}return t=mt(u,n,t,i),t.elementType=e,t.type=r,t.lanes=a,t}function yn(e,t,n,r){return e=mt(7,e,r,t),e.lanes=n,e}function Al(e,t,n,r){return e=mt(22,e,r,t),e.elementType=Se,e.lanes=n,e.stateNode={isHidden:!1},e}function Ko(e,t,n){return e=mt(6,e,null,t),e.lanes=n,e}function Jo(e,t,n){return t=mt(4,e.children!==null?e.children:[],e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function Uf(e,t,n,r,i){this.tag=t,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Si(0),this.expirationTimes=Si(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Si(0),this.identifierPrefix=r,this.onRecoverableError=i,this.mutableSourceEagerHydrationData=null}function Yo(e,t,n,r,i,a,u,p,h){return e=new Uf(e,t,n,p,h),t===1?(t=1,a===!0&&(t|=8)):t=0,a=mt(3,null,null,t),e.current=a,a.stateNode=e,a.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},ao(a),e}function Vf(e,t,n){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(o)}catch(c){console.error(c)}}return o(),ta.exports=rp(),ta.exports}var vc;function lp(){if(vc)return Jl;vc=1;var o=Dc();return Jl.createRoot=o.createRoot,Jl.hydrateRoot=o.hydrateRoot,Jl}var ip=lp();const op=Oc(ip);Dc();/** + * @remix-run/router v1.23.3 + * + * Copyright (c) Remix Software Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE.md file in the root directory of this source tree. + * + * @license MIT + */function Br(){return Br=Object.assign?Object.assign.bind():function(o){for(var c=1;c"u")throw new Error(c)}function da(o,c){if(!o){typeof console<"u"&&console.warn(c);try{throw new Error(c)}catch{}}}function sp(){return Math.random().toString(36).substr(2,8)}function xc(o,c){return{usr:o.state,key:o.key,idx:c}}function ia(o,c,s,d){return s===void 0&&(s=null),Br({pathname:typeof o=="string"?o:o.pathname,search:"",hash:""},typeof c=="string"?Kn(c):c,{state:s,key:c&&c.key||d||sp()})}function Zl(o){let{pathname:c="/",search:s="",hash:d=""}=o;return s&&s!=="?"&&(c+=s.charAt(0)==="?"?s:"?"+s),d&&d!=="#"&&(c+=d.charAt(0)==="#"?d:"#"+d),c}function Kn(o){let c={};if(o){let s=o.indexOf("#");s>=0&&(c.hash=o.substr(s),o=o.substr(0,s));let d=o.indexOf("?");d>=0&&(c.search=o.substr(d),o=o.substr(0,d)),o&&(c.pathname=o)}return c}function up(o,c,s,d){d===void 0&&(d={});let{window:f=document.defaultView,v5Compat:v=!1}=d,g=f.history,P=rn.Pop,S=null,T=z();T==null&&(T=0,g.replaceState(Br({},g.state,{idx:T}),""));function z(){return(g.state||{idx:null}).idx}function y(){P=rn.Pop;let j=z(),F=j==null?null:j-T;T=j,S&&S({action:P,location:N.location,delta:F})}function L(j,F){P=rn.Push;let _=ia(N.location,j,F);T=z()+1;let B=xc(_,T),W=N.createHref(_);try{g.pushState(B,"",W)}catch(Z){if(Z instanceof DOMException&&Z.name==="DataCloneError")throw Z;f.location.assign(W)}v&&S&&S({action:P,location:N.location,delta:1})}function A(j,F){P=rn.Replace;let _=ia(N.location,j,F);T=z();let B=xc(_,T),W=N.createHref(_);g.replaceState(B,"",W),v&&S&&S({action:P,location:N.location,delta:0})}function R(j){let F=f.location.origin!=="null"?f.location.origin:f.location.href,_=typeof j=="string"?j:Zl(j);return _=_.replace(/ $/,"%20"),ze(F,"No window.location.(origin|href) available to create URL for href: "+_),new URL(_,F)}let N={get action(){return P},get location(){return o(f,g)},listen(j){if(S)throw new Error("A history only accepts one active listener");return f.addEventListener(yc,y),S=j,()=>{f.removeEventListener(yc,y),S=null}},createHref(j){return c(f,j)},createURL:R,encodeLocation(j){let F=R(j);return{pathname:F.pathname,search:F.search,hash:F.hash}},push:L,replace:A,go(j){return g.go(j)}};return N}var Sc;(function(o){o.data="data",o.deferred="deferred",o.redirect="redirect",o.error="error"})(Sc||(Sc={}));function cp(o,c,s){return s===void 0&&(s="/"),dp(o,c,s)}function dp(o,c,s,d){let f=typeof c=="string"?Kn(c):c,v=Qn(f.pathname||"/",s);if(v==null)return null;let g=Ac(o);fp(g);let P=null,S=kp(v);for(let T=0;P==null&&T{let S={relativePath:P===void 0?v.path||"":P,caseSensitive:v.caseSensitive===!0,childrenIndex:g,route:v};S.relativePath.startsWith("/")&&(ze(S.relativePath.startsWith(d),'Absolute route path "'+S.relativePath+'" nested under path '+('"'+d+'" is not valid. An absolute child route path ')+"must start with the combined path of all its parent routes."),S.relativePath=S.relativePath.slice(d.length));let T=ln([d,S.relativePath]),z=s.concat(S);v.children&&v.children.length>0&&(ze(v.index!==!0,"Index routes must not have child routes. Please remove "+('all child routes from route path "'+T+'".')),Ac(v.children,c,z,T)),!(v.path==null&&!v.index)&&c.push({path:T,score:xp(T,v.index),routesMeta:z})};return o.forEach((v,g)=>{var P;if(v.path===""||!((P=v.path)!=null&&P.includes("?")))f(v,g);else for(let S of $c(v.path))f(v,g,S)}),c}function $c(o){let c=o.split("/");if(c.length===0)return[];let[s,...d]=c,f=s.endsWith("?"),v=s.replace(/\?$/,"");if(d.length===0)return f?[v,""]:[v];let g=$c(d.join("/")),P=[];return P.push(...g.map(S=>S===""?v:[v,S].join("/"))),f&&P.push(...g),P.map(S=>o.startsWith("/")&&S===""?"/":S)}function fp(o){o.sort((c,s)=>c.score!==s.score?s.score-c.score:Sp(c.routesMeta.map(d=>d.childrenIndex),s.routesMeta.map(d=>d.childrenIndex)))}const pp=/^:[\w-]+$/,mp=3,hp=2,gp=1,vp=10,yp=-2,wc=o=>o==="*";function xp(o,c){let s=o.split("/"),d=s.length;return s.some(wc)&&(d+=yp),c&&(d+=hp),s.filter(f=>!wc(f)).reduce((f,v)=>f+(pp.test(v)?mp:v===""?gp:vp),d)}function Sp(o,c){return o.length===c.length&&o.slice(0,-1).every((d,f)=>d===c[f])?o[o.length-1]-c[c.length-1]:0}function wp(o,c,s){let{routesMeta:d}=o,f={},v="/",g=[];for(let P=0;P{let{paramName:L,isOptional:A}=z;if(L==="*"){let N=P[y]||"";g=v.slice(0,v.length-N.length).replace(/(.)\/+$/,"$1")}const R=P[y];return A&&!R?T[L]=void 0:T[L]=(R||"").replace(/%2F/g,"/"),T},{}),pathname:v,pathnameBase:g,pattern:o}}function jp(o,c,s){c===void 0&&(c=!1),s===void 0&&(s=!0),da(o==="*"||!o.endsWith("*")||o.endsWith("/*"),'Route path "'+o+'" will be treated as if it were '+('"'+o.replace(/\*$/,"/*")+'" because the `*` character must ')+"always follow a `/` in the pattern. To get rid of this warning, "+('please change the route path to "'+o.replace(/\*$/,"/*")+'".'));let d=[],f="^"+o.replace(/\/*\*?$/,"").replace(/^\/*/,"/").replace(/[\\.*+^${}|()[\]]/g,"\\$&").replace(/\/:([\w-]+)(\?)?/g,(g,P,S)=>(d.push({paramName:P,isOptional:S!=null}),S?"/?([^\\/]+)?":"/([^\\/]+)"));return o.endsWith("*")?(d.push({paramName:"*"}),f+=o==="*"||o==="/*"?"(.*)$":"(?:\\/(.+)|\\/*)$"):s?f+="\\/*$":o!==""&&o!=="/"&&(f+="(?:(?=\\/|$))"),[new RegExp(f,c?void 0:"i"),d]}function kp(o){try{return o.split("/").map(c=>decodeURIComponent(c).replace(/\//g,"%2F")).join("/")}catch(c){return da(!1,'The URL path "'+o+'" could not be decoded because it is is a malformed URL segment. This is probably due to a bad percent '+("encoding ("+c+").")),o}}function Qn(o,c){if(c==="/")return o;if(!o.toLowerCase().startsWith(c.toLowerCase()))return null;let s=c.endsWith("/")?c.length-1:c.length,d=o.charAt(s);return d&&d!=="/"?null:o.slice(s)||"/"}const _p=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,Cp=o=>_p.test(o);function Np(o,c){c===void 0&&(c="/");let{pathname:s,search:d="",hash:f=""}=typeof o=="string"?Kn(o):o,v;if(s)if(Cp(s))v=s;else{if(s.includes("//")){let g=s;s=Uc(s),da(!1,"Pathnames cannot have embedded double slashes - normalizing "+(g+" -> "+s))}s.startsWith("/")?v=jc(s.substring(1),"/"):v=jc(s,c)}else v=c;return{pathname:v,search:zp(d),hash:Tp(f)}}function jc(o,c){let s=c.replace(/\/+$/,"").split("/");return o.split("/").forEach(f=>{f===".."?s.length>1&&s.pop():f!=="."&&s.push(f)}),s.length>1?s.join("/"):"/"}function la(o,c,s,d){return"Cannot include a '"+o+"' character in a manually specified "+("`to."+c+"` field ["+JSON.stringify(d)+"]. Please separate it out to the ")+("`to."+s+"` field. Alternatively you may provide the full path as ")+'a string in and the router will parse it for you.'}function Ep(o){return o.filter((c,s)=>s===0||c.route.path&&c.route.path.length>0)}function fa(o,c){let s=Ep(o);return c?s.map((d,f)=>f===s.length-1?d.pathname:d.pathnameBase):s.map(d=>d.pathnameBase)}function pa(o,c,s,d){d===void 0&&(d=!1);let f;typeof o=="string"?f=Kn(o):(f=Br({},o),ze(!f.pathname||!f.pathname.includes("?"),la("?","pathname","search",f)),ze(!f.pathname||!f.pathname.includes("#"),la("#","pathname","hash",f)),ze(!f.search||!f.search.includes("#"),la("#","search","hash",f)));let v=o===""||f.pathname==="",g=v?"/":f.pathname,P;if(g==null)P=s;else{let y=c.length-1;if(!d&&g.startsWith("..")){let L=g.split("/");for(;L[0]==="..";)L.shift(),y-=1;f.pathname=L.join("/")}P=y>=0?c[y]:"/"}let S=Np(f,P),T=g&&g!=="/"&&g.endsWith("/"),z=(v||g===".")&&s.endsWith("/");return!S.pathname.endsWith("/")&&(T||z)&&(S.pathname+="/"),S}const Uc=o=>o.replace(/\/\/+/g,"/"),ln=o=>Uc(o.join("/")),Pp=o=>o.replace(/\/+$/,"").replace(/^\/*/,"/"),zp=o=>!o||o==="?"?"":o.startsWith("?")?o:"?"+o,Tp=o=>!o||o==="#"?"":o.startsWith("#")?o:"#"+o;function bp(o){return o!=null&&typeof o.status=="number"&&typeof o.statusText=="string"&&typeof o.internal=="boolean"&&"data"in o}const Vc=["post","put","patch","delete"];new Set(Vc);const Rp=["get",...Vc];new Set(Rp);/** + * React Router v6.30.4 + * + * Copyright (c) Remix Software Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE.md file in the root directory of this source tree. + * + * @license MIT + */function Wr(){return Wr=Object.assign?Object.assign.bind():function(o){for(var c=1;c{P.current=!0}),m.useCallback(function(T,z){if(z===void 0&&(z={}),!P.current)return;if(typeof T=="number"){d.go(T);return}let y=pa(T,JSON.parse(g),v,z.relative==="path");o==null&&c!=="/"&&(y.pathname=y.pathname==="/"?c:ln([c,y.pathname])),(z.replace?d.replace:d.push)(y,z.state,z)},[c,d,g,v,o])}function ma(){let{matches:o}=m.useContext(Wt),c=o[o.length-1];return c?c.params:{}}function li(o,c){let{relative:s}=c===void 0?{}:c,{future:d}=m.useContext(Bt),{matches:f}=m.useContext(Wt),{pathname:v}=xn(),g=JSON.stringify(fa(f,d.v7_relativeSplatPath));return m.useMemo(()=>pa(o,JSON.parse(g),v,s==="path"),[o,g,v,s])}function Fp(o,c){return Bp(o,c)}function Bp(o,c,s,d){Jn()||ze(!1);let{navigator:f}=m.useContext(Bt),{matches:v}=m.useContext(Wt),g=v[v.length-1],P=g?g.params:{};g&&g.pathname;let S=g?g.pathnameBase:"/";g&&g.route;let T=xn(),z;if(c){var y;let j=typeof c=="string"?Kn(c):c;S==="/"||(y=j.pathname)!=null&&y.startsWith(S)||ze(!1),z=j}else z=T;let L=z.pathname||"/",A=L;if(S!=="/"){let j=S.replace(/^\//,"").split("/");A="/"+L.replace(/^\//,"").split("/").slice(j.length).join("/")}let R=cp(o,{pathname:A}),N=Ap(R&&R.map(j=>Object.assign({},j,{params:Object.assign({},P,j.params),pathname:ln([S,f.encodeLocation?f.encodeLocation(j.pathname).pathname:j.pathname]),pathnameBase:j.pathnameBase==="/"?S:ln([S,f.encodeLocation?f.encodeLocation(j.pathnameBase).pathname:j.pathnameBase])})),v,s,d);return c&&N?m.createElement(ri.Provider,{value:{location:Wr({pathname:"/",search:"",hash:"",state:null,key:"default"},z),navigationType:rn.Pop}},N):N}function Wp(){let o=Hp(),c=bp(o)?o.status+" "+o.statusText:o instanceof Error?o.message:JSON.stringify(o),s=o instanceof Error?o.stack:null,f={padding:"0.5rem",backgroundColor:"rgba(200,200,200, 0.5)"};return m.createElement(m.Fragment,null,m.createElement("h2",null,"Unexpected Application Error!"),m.createElement("h3",{style:{fontStyle:"italic"}},c),s?m.createElement("pre",{style:f},s):null,null)}const Op=m.createElement(Wp,null);class Mp extends m.Component{constructor(c){super(c),this.state={location:c.location,revalidation:c.revalidation,error:c.error}}static getDerivedStateFromError(c){return{error:c}}static getDerivedStateFromProps(c,s){return s.location!==c.location||s.revalidation!=="idle"&&c.revalidation==="idle"?{error:c.error,location:c.location,revalidation:c.revalidation}:{error:c.error!==void 0?c.error:s.error,location:s.location,revalidation:c.revalidation||s.revalidation}}componentDidCatch(c,s){console.error("React Router caught the following error during render",c,s)}render(){return this.state.error!==void 0?m.createElement(Wt.Provider,{value:this.props.routeContext},m.createElement(Qc.Provider,{value:this.state.error,children:this.props.component})):this.props.children}}function Dp(o){let{routeContext:c,match:s,children:d}=o,f=m.useContext(ni);return f&&f.static&&f.staticContext&&(s.route.errorElement||s.route.ErrorBoundary)&&(f.staticContext._deepestRenderedBoundaryId=s.route.id),m.createElement(Wt.Provider,{value:c},d)}function Ap(o,c,s,d){var f;if(c===void 0&&(c=[]),s===void 0&&(s=null),d===void 0&&(d=null),o==null){var v;if(!s)return null;if(s.errors)o=s.matches;else if((v=d)!=null&&v.v7_partialHydration&&c.length===0&&!s.initialized&&s.matches.length>0)o=s.matches;else return null}let g=o,P=(f=s)==null?void 0:f.errors;if(P!=null){let z=g.findIndex(y=>y.route.id&&(P==null?void 0:P[y.route.id])!==void 0);z>=0||ze(!1),g=g.slice(0,Math.min(g.length,z+1))}let S=!1,T=-1;if(s&&d&&d.v7_partialHydration)for(let z=0;z=0?g=g.slice(0,T+1):g=[g[0]];break}}}return g.reduceRight((z,y,L)=>{let A,R=!1,N=null,j=null;s&&(A=P&&y.route.id?P[y.route.id]:void 0,N=y.route.errorElement||Op,S&&(T<0&&L===0?(Kp("route-fallback"),R=!0,j=null):T===L&&(R=!0,j=y.route.hydrateFallbackElement||null)));let F=c.concat(g.slice(0,L+1)),_=()=>{let B;return A?B=N:R?B=j:y.route.Component?B=m.createElement(y.route.Component,null):y.route.element?B=y.route.element:B=z,m.createElement(Dp,{match:y,routeContext:{outlet:z,matches:F,isDataRoute:s!=null},children:B})};return s&&(y.route.ErrorBoundary||y.route.errorElement||L===0)?m.createElement(Mp,{location:s.location,revalidation:s.revalidation,component:N,error:A,children:_(),routeContext:{outlet:null,matches:F,isDataRoute:!0}}):_()},null)}var Jc=(function(o){return o.UseBlocker="useBlocker",o.UseRevalidator="useRevalidator",o.UseNavigateStable="useNavigate",o})(Jc||{}),Yc=(function(o){return o.UseBlocker="useBlocker",o.UseLoaderData="useLoaderData",o.UseActionData="useActionData",o.UseRouteError="useRouteError",o.UseNavigation="useNavigation",o.UseRouteLoaderData="useRouteLoaderData",o.UseMatches="useMatches",o.UseRevalidator="useRevalidator",o.UseNavigateStable="useNavigate",o.UseRouteId="useRouteId",o})(Yc||{});function $p(o){let c=m.useContext(ni);return c||ze(!1),c}function Up(o){let c=m.useContext(Hc);return c||ze(!1),c}function Vp(o){let c=m.useContext(Wt);return c||ze(!1),c}function Gc(o){let c=Vp(),s=c.matches[c.matches.length-1];return s.route.id||ze(!1),s.route.id}function Hp(){var o;let c=m.useContext(Qc),s=Up(),d=Gc();return c!==void 0?c:(o=s.errors)==null?void 0:o[d]}function Qp(){let{router:o}=$p(Jc.UseNavigateStable),c=Gc(Yc.UseNavigateStable),s=m.useRef(!1);return Kc(()=>{s.current=!0}),m.useCallback(function(f,v){v===void 0&&(v={}),s.current&&(typeof f=="number"?o.navigate(f):o.navigate(f,Wr({fromRouteId:c},v)))},[o,c])}const kc={};function Kp(o,c,s){kc[o]||(kc[o]=!0)}function Jp(o,c){o==null||o.v7_startTransition,o==null||o.v7_relativeSplatPath}function Yp(o){let{to:c,replace:s,state:d,relative:f}=o;Jn()||ze(!1);let{future:v,static:g}=m.useContext(Bt),{matches:P}=m.useContext(Wt),{pathname:S}=xn(),T=Ge(),z=pa(c,fa(P,v.v7_relativeSplatPath),S,f==="path"),y=JSON.stringify(z);return m.useEffect(()=>T(JSON.parse(y),{replace:s,state:d,relative:f}),[T,y,f,s,d]),null}function Ie(o){ze(!1)}function Gp(o){let{basename:c="/",children:s=null,location:d,navigationType:f=rn.Pop,navigator:v,static:g=!1,future:P}=o;Jn()&&ze(!1);let S=c.replace(/^\/*/,"/"),T=m.useMemo(()=>({basename:S,navigator:v,static:g,future:Wr({v7_relativeSplatPath:!1},P)}),[S,P,v,g]);typeof d=="string"&&(d=Kn(d));let{pathname:z="/",search:y="",hash:L="",state:A=null,key:R="default"}=d,N=m.useMemo(()=>{let j=Qn(z,S);return j==null?null:{location:{pathname:j,search:y,hash:L,state:A,key:R},navigationType:f}},[S,z,y,L,A,R,f]);return N==null?null:m.createElement(Bt.Provider,{value:T},m.createElement(ri.Provider,{children:s,value:N}))}function Xp(o){let{children:c,location:s}=o;return Fp(aa(c),s)}new Promise(()=>{});function aa(o,c){c===void 0&&(c=[]);let s=[];return m.Children.forEach(o,(d,f)=>{if(!m.isValidElement(d))return;let v=[...c,f];if(d.type===m.Fragment){s.push.apply(s,aa(d.props.children,v));return}d.type!==Ie&&ze(!1),!d.props.index||!d.props.children||ze(!1);let g={id:d.props.id||v.join("-"),caseSensitive:d.props.caseSensitive,element:d.props.element,Component:d.props.Component,index:d.props.index,path:d.props.path,loader:d.props.loader,action:d.props.action,errorElement:d.props.errorElement,ErrorBoundary:d.props.ErrorBoundary,hasErrorBoundary:d.props.ErrorBoundary!=null||d.props.errorElement!=null,shouldRevalidate:d.props.shouldRevalidate,handle:d.props.handle,lazy:d.props.lazy};d.props.children&&(g.children=aa(d.props.children,v)),s.push(g)}),s}/** + * React Router DOM v6.30.4 + * + * Copyright (c) Remix Software Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE.md file in the root directory of this source tree. + * + * @license MIT + */function ei(){return ei=Object.assign?Object.assign.bind():function(o){for(var c=1;c{T&&_c?_c(()=>S(y)):S(y)},[S,T]);return m.useLayoutEffect(()=>g.listen(z),[g,z]),m.useEffect(()=>Jp(d),[d]),m.createElement(Gp,{basename:c,children:s,location:P.location,navigationType:P.action,navigator:g,future:d})}const om=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",am=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,qc=m.forwardRef(function(c,s){let{onClick:d,relative:f,reloadDocument:v,replace:g,state:P,target:S,to:T,preventScrollReset:z,viewTransition:y}=c,L=Xc(c,em),{basename:A}=m.useContext(Bt),R,N=!1;if(typeof T=="string"&&am.test(T)&&(R=T,om))try{let B=new URL(window.location.href),W=T.startsWith("//")?new URL(B.protocol+T):new URL(T),Z=Qn(W.pathname,A);W.origin===B.origin&&Z!=null?T=Z+W.search+W.hash:N=!0}catch{}let j=Lp(T,{relative:f}),F=um(T,{replace:g,state:P,target:S,preventScrollReset:z,relative:f,viewTransition:y});function _(B){d&&d(B),B.defaultPrevented||F(B)}return m.createElement("a",ei({},L,{href:R||j,onClick:N||v?d:_,ref:s,target:S}))}),Hn=m.forwardRef(function(c,s){let{"aria-current":d="page",caseSensitive:f=!1,className:v="",end:g=!1,style:P,to:S,viewTransition:T,children:z}=c,y=Xc(c,tm),L=li(S,{relative:y.relative}),A=xn(),R=m.useContext(Hc),{navigator:N,basename:j}=m.useContext(Bt),F=R!=null&&cm(L)&&T===!0,_=N.encodeLocation?N.encodeLocation(L).pathname:L.pathname,B=A.pathname,W=R&&R.navigation&&R.navigation.location?R.navigation.location.pathname:null;f||(B=B.toLowerCase(),W=W?W.toLowerCase():null,_=_.toLowerCase()),W&&j&&(W=Qn(W,j)||W);const Z=_!=="/"&&_.endsWith("/")?_.length-1:_.length;let fe=B===_||!g&&B.startsWith(_)&&B.charAt(Z)==="/",we=W!=null&&(W===_||!g&&W.startsWith(_)&&W.charAt(_.length)==="/"),xe={isActive:fe,isPending:we,isTransitioning:F},re=fe?d:void 0,oe;typeof v=="function"?oe=v(xe):oe=[v,fe?"active":null,we?"pending":null,F?"transitioning":null].filter(Boolean).join(" ");let pe=typeof P=="function"?P(xe):P;return m.createElement(qc,ei({},y,{"aria-current":re,className:oe,ref:s,style:pe,to:S,viewTransition:T}),typeof z=="function"?z(xe):z)});var sa;(function(o){o.UseScrollRestoration="useScrollRestoration",o.UseSubmit="useSubmit",o.UseSubmitFetcher="useSubmitFetcher",o.UseFetcher="useFetcher",o.useViewTransitionState="useViewTransitionState"})(sa||(sa={}));var Cc;(function(o){o.UseFetcher="useFetcher",o.UseFetchers="useFetchers",o.UseScrollRestoration="useScrollRestoration"})(Cc||(Cc={}));function sm(o){let c=m.useContext(ni);return c||ze(!1),c}function um(o,c){let{target:s,replace:d,state:f,preventScrollReset:v,relative:g,viewTransition:P}=c===void 0?{}:c,S=Ge(),T=xn(),z=li(o,{relative:g});return m.useCallback(y=>{if(Zp(y,s)){y.preventDefault();let L=d!==void 0?d:Zl(T)===Zl(z);S(o,{replace:L,state:f,preventScrollReset:v,relative:g,viewTransition:P})}},[T,S,z,d,f,s,o,v,g,P])}function cm(o,c){c===void 0&&(c={});let s=m.useContext(rm);s==null&&ze(!1);let{basename:d}=sm(sa.useViewTransitionState),f=li(o,{relative:c.relative});if(!s.isTransitioning)return!1;let v=Qn(s.currentLocation.pathname,d)||s.currentLocation.pathname,g=Qn(s.nextLocation.pathname,d)||s.nextLocation.pathname;return oa(f.pathname,g)!=null||oa(f.pathname,v)!=null}const dm="/api";function fm(){return localStorage.getItem("fitness_token")}async function K(o,c={}){const s=fm(),d={"Content-Type":"application/json",...c.headers};s&&(d.Authorization=`Bearer ${s}`);const f=await fetch(`${dm}${o}`,{...c,headers:d});if(f.status===401)throw localStorage.removeItem("fitness_token"),window.location.href="/login",new Error("Unauthorized");if(!f.ok){const v=await f.json().catch(()=>({detail:"Request failed"}));throw new Error(v.detail||`HTTP ${f.status}`)}return f.json()}const J={login:(o,c)=>K("/auth/login",{method:"POST",body:JSON.stringify({username:o,password:c})}),register:(o,c,s)=>K("/auth/register",{method:"POST",body:JSON.stringify({username:o,password:c,display_name:s})}),me:()=>K("/auth/me"),onboardingStatus:()=>K("/onboarding/status"),savePhase1:o=>K("/onboarding/phase1",{method:"POST",body:JSON.stringify(o)}),savePhase2:o=>K("/onboarding/phase2",{method:"POST",body:JSON.stringify(o)}),getRecommendations:()=>K("/onboarding/recommendations"),today:()=>K("/points/today"),week:o=>K(`/points/week${o?`?start=${o}`:""}`),getRules:()=>K("/points/rules"),updateRule:(o,c)=>K(`/points/rules/${o}`,{method:"PATCH",body:JSON.stringify(c)}),getTargets:()=>K("/points/targets"),updateTargets:o=>K("/points/targets",{method:"PATCH",body:JSON.stringify(o)}),listActivities:o=>K(`/activities${o?`?date=${o}`:""}`),logActivity:o=>K("/activities",{method:"POST",body:JSON.stringify(o)}),deleteActivity:o=>K(`/activities/${o}`,{method:"DELETE"}),listFood:o=>K(`/food${o?`?date=${o}`:""}`),logFood:o=>K("/food",{method:"POST",body:JSON.stringify(o)}),deleteFood:o=>K(`/food/${o}`,{method:"DELETE"}),scanBarcode:o=>K(`/food/scan/${o}`),searchFood:o=>K(`/food/search?q=${encodeURIComponent(o)}`),nutritionToday:()=>K("/nutrition/today"),getNutritionGoals:()=>K("/nutrition/goals"),updateNutritionGoals:o=>K("/nutrition/goals",{method:"PATCH",body:JSON.stringify(o)}),startFast:o=>K("/nutrition/fasts",{method:"POST",body:JSON.stringify(o)}),endFast:(o,c)=>K(`/nutrition/fasts/${o}`,{method:"PATCH",body:JSON.stringify(c||{})}),listFasts:o=>K(`/nutrition/fasts${o?`?limit=${o}`:""}`),getActiveFast:()=>K("/nutrition/fasts/active"),deleteFast:o=>K(`/nutrition/fasts/${o}`,{method:"DELETE"}),logElectrolytes:o=>K("/nutrition/electrolytes",{method:"POST",body:JSON.stringify(o)}),getElectrolytesToday:()=>K("/nutrition/electrolytes/today"),listRewards:()=>K("/rewards"),createReward:o=>K("/rewards",{method:"POST",body:JSON.stringify(o)}),redeemReward:(o,c)=>K(`/rewards/${o}/redeem`,{method:"POST",body:JSON.stringify({date:c})}),listPrograms:()=>K("/programs"),createProgram:o=>K("/programs",{method:"POST",body:JSON.stringify(o)}),getProgram:o=>K(`/programs/${o}`),searchCatalog:o=>K(`/programs/catalog${o?`?q=${encodeURIComponent(o)}`:""}`),getCatalogProgram:o=>K(`/programs/catalog/${o}`),researchProgram:o=>K("/programs/research",{method:"POST",body:JSON.stringify({name:o})}),adoptProgram:(o,c)=>K(`/programs/catalog/${o}/adopt`,{method:"POST",body:JSON.stringify({start_date:c})}),getProgramSchedule:o=>K(`/programs/${o}/schedule`),getWorkoutDetail:(o,c)=>K(`/programs/${o}/workout/${c}`),completeWorkout:(o,c,s)=>K(`/programs/${o}/workout/${c}/complete`,{method:"POST",body:JSON.stringify(s)}),getProgramProgress:o=>K(`/programs/${o}/progress`),getThread:()=>K("/support/thread"),sendSupportMessage:o=>K("/support/messages",{method:"POST",body:JSON.stringify({body:o})}),getUnreadCount:()=>K("/support/unread"),listSupportThreads:()=>K("/support/admin/threads"),getAdminThread:o=>K(`/support/admin/threads/${o}`),replySupportThread:(o,c)=>K(`/support/admin/threads/${o}/reply`,{method:"POST",body:JSON.stringify({body:c})}),integrationStatus:()=>K("/integrations"),stravaAuth:()=>K("/integrations/strava/auth"),stravaSync:()=>K("/integrations/strava/sync",{method:"POST"}),polarAuth:()=>K("/integrations/polar/auth"),polarSync:()=>K("/integrations/polar/sync",{method:"POST"}),disconnect:o=>K(`/integrations/${o}`,{method:"DELETE"}),listMealPlans:()=>K("/meal-plans"),createMealPlan:o=>K("/meal-plans",{method:"POST",body:JSON.stringify(o)}),getMealPlanToday:()=>K("/meal-plans/today"),getMealPlan:o=>K("/meal-plans/"+o),updateMealPlanStatus:(o,c)=>K("/meal-plans/"+o,{method:"PATCH",body:JSON.stringify({status:c})}),logMealCompliance:o=>K("/meal-plans/compliance",{method:"POST",body:JSON.stringify(o)}),getMealPlanProgress:o=>K("/meal-plans/"+o+"/progress"),fullIntegrationStatus:()=>K("/integrations/status"),listProviders:()=>K("/integrations/providers"),configureIntegration:(o,c)=>K("/integrations/configure",{method:"POST",body:JSON.stringify({provider:o,credentials:c})}),getAIStatus:()=>K("/ai/status"),getResourceRecommendations:()=>K("/onboarding/recommendations"),agentConfig:()=>K("/agent/config")};function pm(o){localStorage.setItem("fitness_token",o)}function mm(){localStorage.removeItem("fitness_token")}function ti(){return!!localStorage.getItem("fitness_token")}function hm(){const[o,c]=m.useState("login"),[s,d]=m.useState(""),[f,v]=m.useState(""),[g,P]=m.useState(""),[S,T]=m.useState(""),[z,y]=m.useState(!1),L=Ge();async function A(R){R.preventDefault(),T(""),y(!0);try{const N=o==="login"?await J.login(s,f):await J.register(s,f,g||s);pm(N.access_token);const j=await J.onboardingStatus();L(j.phase1_completed?"/":"/onboarding")}catch(N){T(N.message)}finally{y(!1)}}return l.jsx("div",{style:{minHeight:"100dvh",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"24px",background:"linear-gradient(170deg, var(--accent-light) 0%, var(--accent) 30%, var(--accent-dark) 60%, var(--text) 100%)"},children:l.jsxs("div",{style:{width:"100%",maxWidth:"380px"},children:[l.jsxs("div",{style:{textAlign:"center",marginBottom:"32px",color:"#fff"},children:[l.jsx("div",{style:{fontSize:"3.2rem",marginBottom:"8px",filter:"drop-shadow(0 4px 12px rgba(0,0,0,0.2))"},children:"🔥"}),l.jsx("h1",{style:{fontFamily:"var(--font-display)",fontSize:"2.2rem",fontWeight:900,letterSpacing:"-0.03em"},children:"Fitness Rewards"}),l.jsx("p",{style:{opacity:.8,marginTop:"4px",fontSize:"0.95rem",fontWeight:500},children:"Earn your rewards. Every single day."})]}),l.jsxs("div",{style:{background:"var(--card)",borderRadius:"var(--r-lg)",padding:"28px",boxShadow:"0 20px 60px rgba(0,0,0,0.3)"},children:[l.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"4px",background:"rgba(0,0,0,0.04)",borderRadius:"var(--r)",padding:"4px",marginBottom:"24px"},children:["login","register"].map(R=>l.jsx("button",{type:"button",onClick:()=>c(R),style:{borderRadius:"var(--r-sm)",padding:"10px",fontWeight:700,fontSize:"0.85rem",background:o===R?"var(--accent)":"transparent",color:o===R?"#fff":"var(--text-2)",boxShadow:o===R?"var(--shadow-accent)":"none"},children:R==="login"?"Sign In":"Sign Up"},R))}),S&&l.jsx("div",{className:"error-msg",children:S}),l.jsxs("form",{onSubmit:A,children:[l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Username"}),l.jsx("input",{value:s,onChange:R=>d(R.target.value),required:!0,autoComplete:"username"})]}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Password"}),l.jsx("input",{type:"password",value:f,onChange:R=>v(R.target.value),required:!0,autoComplete:"current-password"})]}),o==="register"&&l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Display Name"}),l.jsx("input",{value:g,onChange:R=>P(R.target.value),placeholder:"What should we call you?"})]}),l.jsx("button",{type:"submit",className:"btn-primary btn-full",disabled:z,style:{padding:"14px",fontSize:"0.95rem",marginTop:"8px",borderRadius:"var(--r)"},children:z?"...":o==="login"?"Sign In":"Create Account"})]})]})]})})}function Yl({text:o,children:c}){const[s,d]=m.useState(!1);return l.jsxs("span",{style:{position:"relative",display:"inline-flex",alignItems:"center"},children:[c,l.jsx("span",{onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),onClick:f=>{f.stopPropagation(),d(v=>!v)},style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:"18px",height:"18px",borderRadius:"50%",marginLeft:"6px",background:"rgba(0,0,0,0.06)",color:"var(--text-3)",cursor:"help",fontSize:"0.7rem",fontWeight:800,flexShrink:0},children:"?"}),s&&l.jsx("span",{style:{position:"absolute",bottom:"calc(100% + 8px)",left:"50%",transform:"translateX(-50%)",background:"var(--text)",color:"#fff",padding:"10px 14px",borderRadius:"var(--r-sm)",fontSize:"0.78rem",lineHeight:1.45,fontWeight:500,width:"240px",boxShadow:"var(--shadow-3)",zIndex:50,pointerEvents:"none"},children:o})]})}function gm(){var _,B;const[o,c]=m.useState(null),[s,d]=m.useState(null),[f,v]=m.useState(!0),[g,P]=m.useState(null),S=Ge();m.useEffect(()=>{T()},[]);async function T(){try{const[W,Z]=await Promise.all([J.today(),J.integrationStatus()]);c(W),d(Z)}catch(W){console.error(W)}finally{v(!1)}}async function z(W){P(W);try{const Z=await(W==="strava"?J.stravaSync:J.polarSync)();await T(),Z.imported>0?alert(`Synced ${Z.imported} activities from ${W}!`):alert(`No new activities found on ${W}.`)}catch(Z){alert(`Sync failed: ${Z.message}`)}finally{P(null)}}async function y(W){try{const Z=await(W==="strava"?J.stravaAuth:J.polarAuth)();window.location.href=Z.auth_url}catch(Z){alert(`Connect failed: ${Z.message}`)}}if(f)return l.jsx("div",{className:"page",children:l.jsx("div",{className:"loading",children:"Loading..."})});if(!o)return l.jsx("div",{className:"page",children:l.jsx("div",{className:"error-msg",children:"Failed to load"})});const L=o.daily_minimum>0?Math.min(100,Math.round(o.points_earned/o.daily_minimum*100)):0,A=o.weekly_target>0?Math.min(100,Math.round(o.week_points/o.weekly_target*100)):0,R=new Set(o.activities_today.map(W=>W.category)),N=(_=s==null?void 0:s.strava)==null?void 0:_.connected,j=(B=s==null?void 0:s.polar)==null?void 0:B.connected,F=[{key:"workout",label:"Workout",icon:"💪",pts:50,color:"var(--accent)",tip:"Any exercise session — running, weights, yoga, etc. Logged manually or synced from Strava/Polar."},{key:"food_log",label:"Food logged",icon:"🥗",pts:30,color:"var(--green)",tip:"Log what you eat. Barcode scan or manual entry. Building food awareness is a key habit."},{key:"steps_target",label:"Steps target",icon:"👟",pts:20,color:"#2979FF",tip:"Hit your daily step goal. Steps are the foundation of an active lifestyle."},{key:"screen_free",label:"Screen-free",icon:"📖",pts:"20/hr",color:"#7C4DFF",tip:"Time away from screens — reading, walking, hobbies. Points scale with hours logged."},{key:"daily_checkin",label:"Check-in",icon:"✅",pts:10,color:"#00BCD4",tip:"Just show up and check in. The easiest points — consistency matters more than intensity."}];return l.jsxs("div",{className:"page",children:[o.program_name&&l.jsxs("div",{onClick:()=>o.program_id&&S(`/programs/${o.program_id}`),style:{background:"var(--accent-bg)",borderRadius:"var(--r)",padding:"12px 16px",marginBottom:"14px",display:"flex",alignItems:"center",gap:"12px",border:"1px solid rgba(41,121,255,0.1)",cursor:o.program_id?"pointer":"default"},children:[l.jsx("div",{style:{fontSize:"1.1rem"},children:"📋"}),l.jsxs("div",{style:{flex:1},children:[l.jsx("div",{style:{fontSize:"0.78rem",fontWeight:700,color:"var(--accent)"},children:o.program_name}),l.jsx("div",{className:"progress-bar",style:{height:"5px",marginTop:"4px"},children:l.jsx("div",{className:"progress-bar-fill",style:{width:`${Math.round(o.program_day/o.program_total_days*100)}%`,background:"var(--accent)"}})})]}),l.jsxs("div",{style:{fontFamily:"var(--font-display)",fontWeight:800,fontSize:"0.85rem",color:"var(--accent)",whiteSpace:"nowrap"},children:[o.program_day,"/",o.program_total_days]})]}),l.jsxs("div",{className:`gate-banner ${o.gate_passed?"gate-earned":"gate-locked"}`,children:[l.jsx("div",{className:"section-label",style:{marginBottom:"4px"},children:l.jsx(Yl,{text:`Hit ${o.daily_minimum} points to unlock your rewards for today. Points reset weekly. This is your daily "gate" — earn first, enjoy second.`,children:"Today"})}),l.jsxs("div",{className:"gate-pts",children:[l.jsx("span",{style:{color:o.gate_passed?"var(--green)":"var(--accent)"},children:o.points_earned}),l.jsxs("span",{style:{fontFamily:"var(--font)",fontSize:"1rem",fontWeight:600,color:"var(--text-3)"},children:["/",o.daily_minimum]})]}),l.jsx("div",{className:"progress-bar",style:{marginTop:"12px",height:"12px"},children:l.jsx("div",{className:"progress-bar-fill",style:{width:`${L}%`,background:o.gate_passed?"linear-gradient(90deg, #00C853, #69F0AE)":"linear-gradient(90deg, var(--accent), var(--accent-light))"}})}),l.jsx("div",{style:{marginTop:"12px",fontSize:"0.88rem",fontWeight:700},children:o.gate_passed?l.jsx("span",{style:{color:"var(--green-dark)"},children:"✨ Rewards unlocked!"}):l.jsxs("span",{style:{color:"var(--text-2)"},children:["🔒 ",o.points_remaining," more to unlock"]})})]}),l.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"10px",marginBottom:"14px"},children:[l.jsx("button",{className:"btn-primary btn-full",onClick:()=>S("/log"),style:{padding:"14px",fontSize:"0.9rem"},children:"+ Log Activity"}),l.jsx("button",{className:"btn-outline btn-full",onClick:()=>S("/food"),style:{padding:"14px",fontSize:"0.9rem"},children:"🍽️ Log Food"})]}),l.jsxs("div",{className:"card",children:[l.jsx("div",{className:"section-label",children:"Activities"}),F.map(W=>{const Z=R.has(W.key);return l.jsxs("div",{className:"checklist-item",style:{opacity:Z?1:.6},children:[l.jsx("span",{style:{width:"32px",height:"32px",borderRadius:"8px",background:Z?W.color:"rgba(0,0,0,0.04)",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"0.9rem",transition:"all 0.3s"},children:Z?"✓":W.icon}),l.jsx("span",{style:{fontWeight:600,fontSize:"0.88rem"},children:l.jsx(Yl,{text:W.tip,children:W.label})}),l.jsxs("span",{className:"checklist-points",children:["+",W.pts]})]},W.key)})]}),l.jsxs("div",{className:"card",style:{background:"var(--accent-bg)"},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px"},children:[l.jsx("div",{className:"section-label",style:{margin:0},children:l.jsx(Yl,{text:`Earn ${o.weekly_target} total points across the week for a bonus. Consistent daily effort beats one big day.`,children:"This Week"})}),l.jsx(qc,{to:"/week",style:{fontSize:"0.8rem"},children:"Details →"})]}),l.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"4px",marginBottom:"8px"},children:[l.jsx("span",{style:{fontFamily:"var(--font-display)",fontWeight:900,fontSize:"1.4rem"},children:o.week_points}),l.jsxs("span",{style:{fontSize:"0.85rem",color:"var(--text-3)",fontWeight:600},children:["/ ",o.weekly_target," pts"]})]}),l.jsx("div",{className:"progress-bar",children:l.jsx("div",{className:"progress-bar-fill",style:{width:`${A}%`,background:"linear-gradient(90deg, #7C4DFF, #B388FF)"}})})]}),o.gate_passed&&o.rewards_available.length>0&&l.jsxs("div",{className:"card",style:{background:"var(--green-bg)",border:"2px solid rgba(0,200,83,0.15)"},children:[l.jsx("div",{className:"section-label",style:{color:"var(--green-dark)"},children:"🎮 Rewards Available"}),o.rewards_available.map(W=>l.jsxs("div",{className:"reward-card",children:[l.jsxs("div",{children:[l.jsx("div",{style:{fontWeight:700},children:W.name}),l.jsxs("div",{style:{fontSize:"0.78rem",color:"var(--text-3)",fontWeight:600},children:[W.point_cost," pts"]})]}),l.jsx("button",{className:"btn-success btn-sm",onClick:async()=>{try{await J.redeemReward(W.id),await T()}catch(Z){alert(Z.message)}},children:"Redeem"})]},W.id))]}),l.jsxs("div",{className:"card",children:[l.jsx("div",{className:"section-label",children:l.jsx(Yl,{text:"Connect your fitness trackers to automatically import workouts. Go to Settings → Integrations to connect.",children:"Integrations"})}),l.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[N?l.jsx("button",{className:"btn-outline btn-sm btn-full",onClick:()=>z("strava"),disabled:g==="strava",children:g==="strava"?"⏳ Syncing...":"🔄 Sync Strava"}):l.jsx("button",{className:"btn-ghost btn-sm btn-full",onClick:()=>y("strava"),style:{border:"2px dashed var(--divider)"},children:"🔗 Connect Strava"}),j?l.jsx("button",{className:"btn-outline btn-sm btn-full",onClick:()=>z("polar"),disabled:g==="polar",children:g==="polar"?"⏳ Syncing...":"🔄 Sync Polar"}):l.jsx("button",{className:"btn-ghost btn-sm btn-full",onClick:()=>y("polar"),style:{border:"2px dashed var(--divider)"},children:"🔗 Connect Polar"})]})]})]})}const Nc=[{value:"workout",label:"Workout",icon:"💪",desc:"Any exercise session",color:"var(--accent)"},{value:"steps_target",label:"Steps",icon:"👟",desc:"Hit your daily goal",color:"#2979FF"},{value:"screen_free",label:"Screen-Free",icon:"📖",desc:"Reading, outdoors",color:"#7C4DFF"},{value:"daily_checkin",label:"Check-in",icon:"✅",desc:"Just show up",color:"#00BCD4"}];function vm(){const[o,c]=m.useState(""),[s,d]=m.useState(""),[f,v]=m.useState(""),[g,P]=m.useState(""),[S,T]=m.useState(!1),[z,y]=m.useState(""),[L,A]=m.useState(null),[R,N]=m.useState(null),[j,F]=m.useState([]),[_,B]=m.useState(null),W=Ge();m.useEffect(()=>{Z()},[]);async function Z(){try{const oe=(await J.listPrograms()||[]).find(ve=>ve.status==="active"&&ve.catalog_id);if(!oe)return;A(oe);const pe=await J.getProgramSchedule(oe.id);pe.today_workout&&!pe.today_workout.rest_day&&!pe.today_workout.completed&&N(pe.today_workout);const Ne=(pe.schedule||[]).filter(ve=>{var Te;return ve.week_number===pe.current_week&&!ve.rest_day&&!ve.completed&&ve.id!==((Te=pe.today_workout)==null?void 0:Te.id)}).slice(0,3);F(Ne)}catch(re){console.warn("Could not load active program:",re.message)}}async function fe(re){if(!(!L||!re||_)){B(re.id);try{const oe=await J.completeWorkout(L.id,re.id,{});let Ne=`+${oe.total_points||oe.points_earned} points!`;oe.weekly_bonus>0&&(Ne+=" (week bonus!)"),oe.completion_bonus>0&&(Ne+=" (program complete!)"),y(Ne),setTimeout(()=>W("/"),1500)}catch(oe){alert(oe.message),B(null)}}}async function we(re){var oe;if(re.preventDefault(),!!o){T(!0);try{const pe=new Date().toISOString().split("T")[0],Ne=await J.logActivity({category:o,title:s||((oe=Nc.find(ve=>ve.value===o))==null?void 0:oe.label),description:g||null,duration_minutes:f?parseInt(f):null,activity_date:pe});y(`+${Ne.points_earned} points!`),c(""),d(""),v(""),P(""),setTimeout(()=>W("/"),1200)}catch(pe){alert(pe.message)}finally{T(!1)}}}const xe=o==="workout"&&L;return l.jsxs("div",{className:"page",children:[l.jsx("h1",{className:"page-title",children:"Log Activity"}),z&&l.jsxs("div",{style:{textAlign:"center",padding:"24px",marginBottom:"14px",background:"var(--green-bg)",borderRadius:"var(--r-lg)",border:"2px solid rgba(0,200,83,0.15)"},children:[l.jsx("div",{style:{fontSize:"2rem",marginBottom:"4px"},children:"🎉"}),l.jsx("div",{style:{fontFamily:"var(--font-display)",fontWeight:900,fontSize:"1.3rem",color:"var(--green-dark)"},children:z})]}),l.jsxs("div",{style:{marginBottom:"18px"},children:[l.jsx("div",{className:"section-label",children:"What did you do?"}),l.jsx("div",{className:"option-grid",children:Nc.map(re=>l.jsxs("div",{className:`option-btn ${o===re.value?"selected":""}`,onClick:()=>c(re.value),style:o===re.value?{borderColor:re.color,background:re.color+"0A"}:{},children:[l.jsx("div",{style:{fontSize:"1.5rem",marginBottom:"6px"},children:re.icon}),l.jsx("div",{style:{fontWeight:800,fontSize:"0.85rem"},children:re.label}),l.jsx("div",{style:{fontSize:"0.72rem",color:"var(--text-3)",marginTop:"2px",fontWeight:400},children:re.desc})]},re.value))})]}),xe&&l.jsxs("div",{style:{animation:"fadeUp 0.25s ease-out",marginBottom:"18px"},children:[l.jsxs("div",{onClick:()=>W(`/programs/${L.id}`),style:{background:"var(--accent-bg)",borderRadius:"var(--r-sm)",padding:"10px 14px",marginBottom:"12px",display:"flex",alignItems:"center",justifyContent:"space-between",cursor:"pointer",border:"1px solid rgba(41,121,255,0.15)"},children:[l.jsxs("div",{children:[l.jsx("div",{style:{fontSize:"0.7rem",fontWeight:700,color:"var(--accent)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Active Program"}),l.jsx("div",{style:{fontWeight:800,fontSize:"0.92rem",color:"var(--text-1)"},children:L.name})]}),l.jsxs("div",{style:{fontSize:"0.78rem",color:"var(--accent)",fontWeight:700},children:["Week ",L.current_week||1," →"]})]}),R&&l.jsx(Ec,{workout:R,featured:!0,completing:_===R.id,onComplete:()=>fe(R)}),j.length>0&&l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"section-label",style:{marginTop:"14px",marginBottom:"8px"},children:R?"Or another from this week":"Workouts this week"}),j.map(re=>l.jsx(Ec,{workout:re,completing:_===re.id,onComplete:()=>fe(re)},re.id))]}),!R&&j.length===0&&l.jsx("div",{style:{padding:"14px",borderRadius:"var(--r-sm)",background:"var(--green-bg)",color:"var(--green-dark)",fontSize:"0.85rem",textAlign:"center",fontWeight:600},children:"✓ All workouts for this week are complete. Log a freeform workout below or rest up."}),l.jsx("div",{style:{textAlign:"center",color:"var(--text-3)",fontSize:"0.78rem",margin:"14px 0 6px",textTransform:"uppercase",letterSpacing:"0.06em",fontWeight:700},children:"— or log freeform —"})]}),o&&l.jsxs("form",{onSubmit:we,className:"card",style:{animation:"fadeUp 0.25s ease-out"},children:[l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Title (optional)"}),l.jsx("input",{value:s,onChange:re=>d(re.target.value),placeholder:"e.g. Morning run, evening yoga"})]}),(o==="workout"||o==="screen_free")&&l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Duration (minutes)"}),l.jsx("input",{type:"number",value:f,onChange:re=>v(re.target.value),placeholder:"30"})]}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Notes (optional)"}),l.jsx("textarea",{value:g,onChange:re=>P(re.target.value),rows:2,placeholder:"How did it go?"})]}),l.jsx("button",{type:"submit",className:"btn-primary btn-full",disabled:S,style:{borderRadius:"var(--r)"},children:S?"Saving...":"Log Activity"})]})]})}function Ec({workout:o,featured:c,completing:s,onComplete:d}){return l.jsxs("div",{style:{background:"var(--card)",borderRadius:"var(--r)",padding:"14px",marginBottom:"10px",boxShadow:"var(--shadow-1)",border:c?"2px solid var(--accent-glow)":"1px solid var(--divider)"},children:[c&&l.jsx("div",{style:{fontSize:"0.65rem",fontWeight:800,color:"var(--accent)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:"4px"},children:"⭐ Today"}),l.jsx("div",{style:{fontFamily:"var(--font-display)",fontWeight:800,fontSize:"1rem",marginBottom:"2px"},children:o.workout_name||`Day ${o.day_number}`}),l.jsxs("div",{style:{fontSize:"0.74rem",color:"var(--text-3)",marginBottom:"10px"},children:["Week ",o.week_number," · Day ",o.day_number," · ",(o.exercises||[]).length," exercises"]}),l.jsx("div",{style:{background:"var(--bg-warm)",borderRadius:"var(--r-sm)",padding:"8px 10px",marginBottom:"10px"},children:(o.exercises||[]).slice(0,4).map((f,v)=>l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:"0.76rem",padding:"2px 0",color:"var(--text-2)"},children:[l.jsx("span",{children:f.name}),l.jsx("span",{style:{color:"var(--text-3)",fontWeight:600},children:f.sets&&f.reps&&`${f.sets}×${f.reps}`})]},v))}),l.jsx("button",{onClick:d,disabled:s,style:{width:"100%",background:s?"var(--text-3)":"var(--green)",color:"#fff",padding:"11px",fontWeight:800,fontSize:"0.88rem",boxShadow:s?"none":"var(--shadow-green)"},children:s?"Logging...":"✓ Complete — 75 pts"})]})}const Pc=["breakfast","lunch","dinner","snack"];function ym(){const[o,c]=m.useState("log"),[s,d]=m.useState("lunch"),[f,v]=m.useState(""),[g,P]=m.useState(""),[S,T]=m.useState(""),[z,y]=m.useState(""),[L,A]=m.useState(""),[R,N]=m.useState(""),[j,F]=m.useState("1"),[_,B]=m.useState(""),[W,Z]=m.useState(""),[fe,we]=m.useState([]),[xe,re]=m.useState(null),[oe,pe]=m.useState(!1),[Ne,ve]=m.useState("");m.useEffect(()=>{Te()},[]);async function Te(){try{const I=new Date().toISOString().split("T")[0],V=await J.listFood(I);re(V)}catch(I){console.error(I)}}function Me(I){v(I.product_name||""),P(I.brand||""),T(I.calories_100g?String(Math.round(I.calories_100g)):""),y(I.protein_100g?String(Math.round(I.protein_100g)):""),A(I.carbs_100g?String(Math.round(I.carbs_100g)):""),N(I.fat_100g?String(Math.round(I.fat_100g)):""),c("log")}async function Be(){if(_.trim()){pe(!0);try{const I=await J.scanBarcode(_.trim());Me(I)}catch{alert("Product not found. Try manual entry.")}finally{pe(!1)}}}async function Se(){if(W.trim()){pe(!0);try{const I=await J.searchFood(W);we(I.results||[])}catch(I){alert(I.message)}finally{pe(!1)}}}async function H(I){if(I.preventDefault(),!!f.trim()){pe(!0);try{const V=new Date().toISOString().split("T")[0];await J.logFood({meal_type:s,food_name:f,brand:g||null,calories:S?parseFloat(S)*parseFloat(j||1):null,protein_g:z?parseFloat(z)*parseFloat(j||1):null,carbs_g:L?parseFloat(L)*parseFloat(j||1):null,fat_g:R?parseFloat(R)*parseFloat(j||1):null,servings:parseFloat(j||1),food_date:V}),ve("Food logged!"),v(""),P(""),T(""),y(""),A(""),N(""),F("1"),await Te(),setTimeout(()=>ve(""),2e3)}catch(V){alert(V.message)}finally{pe(!1)}}}return l.jsxs("div",{className:"page",children:[l.jsx("h1",{className:"page-title",children:"Food Log"}),Ne&&l.jsx("div",{style:{padding:"12px",background:"var(--green-bg)",borderRadius:"var(--radius-sm)",color:"var(--green-dark)",textAlign:"center",marginBottom:"12px",fontWeight:600},children:Ne}),l.jsxs("div",{style:{display:"flex",gap:"8px",marginBottom:"16px"},children:[l.jsx("button",{className:o==="log"?"btn-primary btn-sm":"btn-outline btn-sm",onClick:()=>c("log"),children:"Manual"}),l.jsx("button",{className:o==="scan"?"btn-primary btn-sm":"btn-outline btn-sm",onClick:()=>c("scan"),children:"📷 Scan"}),l.jsx("button",{className:o==="search"?"btn-primary btn-sm":"btn-outline btn-sm",onClick:()=>c("search"),children:"🔍 Search"})]}),o==="scan"&&l.jsxs("div",{className:"card",children:[l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Barcode number"}),l.jsx("input",{value:_,onChange:I=>B(I.target.value),placeholder:"Enter or scan barcode",inputMode:"numeric"})]}),l.jsx("button",{className:"btn-primary btn-full",onClick:Be,disabled:oe,children:oe?"Looking up...":"Lookup"}),l.jsx("p",{style:{fontSize:"0.8rem",color:"var(--text-3)",marginTop:"8px",textAlign:"center"},children:"Powered by Open Food Facts (4M+ products)"})]}),o==="search"&&l.jsxs("div",{className:"card",children:[l.jsxs("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:[l.jsx("input",{value:W,onChange:I=>Z(I.target.value),placeholder:"Search foods...",onKeyDown:I=>I.key==="Enter"&&Se()}),l.jsx("button",{className:"btn-primary btn-sm",onClick:Se,disabled:oe,children:"Go"})]}),fe.map((I,V)=>l.jsxs("div",{style:{padding:"10px 0",borderBottom:"1px solid var(--divider)",cursor:"pointer"},onClick:()=>Me(I),children:[l.jsx("div",{style:{fontWeight:600,fontSize:"0.9rem"},children:I.product_name||"Unknown"}),l.jsxs("div",{style:{fontSize:"0.8rem",color:"var(--text-3)"},children:[I.brand&&`${I.brand} · `,I.calories_100g?`${Math.round(I.calories_100g)} cal/100g`:""]})]},V))]}),o==="log"&&l.jsx("form",{onSubmit:H,children:l.jsxs("div",{className:"card",children:[l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Meal"}),l.jsx("div",{style:{display:"flex",gap:"6px"},children:Pc.map(I=>l.jsx("button",{type:"button",className:s===I?"btn-primary btn-sm":"btn-outline btn-sm",onClick:()=>d(I),children:I.charAt(0).toUpperCase()+I.slice(1)},I))})]}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Food name"}),l.jsx("input",{value:f,onChange:I=>v(I.target.value),placeholder:"e.g. Grilled chicken breast",required:!0})]}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Brand (optional)"}),l.jsx("input",{value:g,onChange:I=>P(I.target.value),placeholder:""})]}),l.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"10px"},children:[l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Calories"}),l.jsx("input",{type:"number",value:S,onChange:I=>T(I.target.value),placeholder:"per serving"})]}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Servings"}),l.jsx("input",{type:"number",step:"0.5",value:j,onChange:I=>F(I.target.value)})]}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Protein (g)"}),l.jsx("input",{type:"number",value:z,onChange:I=>y(I.target.value)})]}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Carbs (g)"}),l.jsx("input",{type:"number",value:L,onChange:I=>A(I.target.value)})]}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Fat (g)"}),l.jsx("input",{type:"number",value:R,onChange:I=>N(I.target.value)})]})]}),l.jsx("button",{type:"submit",className:"btn-primary btn-full",disabled:oe,children:oe?"Saving...":"Log Food"})]})}),xe&&l.jsxs("div",{className:"card",style:{marginTop:"8px"},children:[l.jsxs("div",{style:{fontFamily:"var(--font-display)",fontWeight:800,marginBottom:"10px"},children:["Today: ",Math.round(xe.total_calories)," cal"]}),Pc.map(I=>{const V=xe.meals[I]||[];return V.length===0?null:l.jsxs("div",{className:"meal-section",children:[l.jsx("div",{className:"meal-title",children:I}),V.map(w=>l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",padding:"4px 0",fontSize:"0.9rem"},children:[l.jsx("span",{children:w.food_name}),l.jsx("span",{style:{color:"var(--text-3)"},children:w.calories?`${Math.round(w.calories)} cal`:""})]},w.id))]},I)})]})]})}const zc=[{label:"16:8 Daily",hours:16,type:"daily"},{label:"18:6",hours:18,type:"daily"},{label:"20:4",hours:20,type:"daily"},{label:"24h Weekly",hours:24,type:"weekly_24"},{label:"48h",hours:48,type:"long_48"},{label:"72h Kickoff",hours:72,type:"long_72"}];function Gl({label:o,value:c,target:s,unit:d,color:f,inverse:v}){const g=s>0?Math.min(100,Math.round(c/s*100)):0,P=v?c<=s:c>=s*.85;return l.jsxs("div",{style:{marginBottom:"14px"},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"4px",fontSize:"0.85rem"},children:[l.jsx("span",{style:{fontWeight:700},children:o}),l.jsxs("span",{style:{color:P?"var(--green-dark)":"var(--text-3)",fontWeight:600},children:[Math.round(c),v?"":` / ${s}`," ",d,v&&` / ${s} cap`]})]}),l.jsx("div",{className:"progress-bar",style:{height:"8px"},children:l.jsx("div",{className:"progress-bar-fill",style:{width:`${g}%`,background:v?c<=s?"var(--green)":"var(--red)":f}})})]})}function xm({fast:o}){const[,c]=m.useState(0);m.useEffect(()=>{const P=setInterval(()=>c(S=>S+1),6e4);return()=>clearInterval(P)},[]);const s=(new Date-new Date(o.started_at))/1e3/3600,d=Math.min(100,s/o.target_hours*100),f=s>=o.target_hours,v=Math.floor(s),g=Math.floor((s-v)*60);return l.jsxs("div",{children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"8px"},children:[l.jsxs("span",{style:{fontFamily:"var(--font-display)",fontWeight:900,fontSize:"1.6rem"},children:[v,"h ",g,"m"]}),l.jsxs("span",{style:{fontSize:"0.85rem",color:"var(--text-3)",fontWeight:600},children:["/ ",o.target_hours,"h target"]})]}),l.jsx("div",{className:"progress-bar",style:{height:"12px"},children:l.jsx("div",{className:"progress-bar-fill",style:{width:`${d}%`,background:f?"linear-gradient(90deg, #00C853, #69F0AE)":"linear-gradient(90deg, #7C4DFF, #B388FF)"}})}),f&&l.jsx("div",{style:{marginTop:"8px",fontSize:"0.9rem",color:"var(--green-dark)",fontWeight:700},children:"✓ Target reached — you can end now or push further"})]})}function Sm(){const[o,c]=m.useState(null),[s,d]=m.useState(null),[f,v]=m.useState(!0),[g,P]=m.useState(zc[0]),[S,T]=m.useState(!1),z=Ge();m.useEffect(()=>{y()},[]);async function y(){try{const[B,W]=await Promise.all([J.nutritionToday(),J.getElectrolytesToday()]);c(B),d(W)}catch(B){console.error(B)}finally{v(!1)}}async function L(){T(!0);try{await J.startFast({target_hours:g.hours,fast_type:g.type}),await y()}catch(B){alert(B.message)}finally{T(!1)}}async function A(){if(confirm("End this fast now?")){T(!0);try{const B=await J.endFast(o.active_fast.id);alert(`Fast ended. +${B.points_awarded} pts earned.`),await y()}catch(B){alert(B.message)}finally{T(!1)}}}async function R(B){const W={morning:{sodium_mg:2300,potassium_mg:800,magnesium_mg:0,notes:"Morning drink"},midday:{sodium_mg:2300,potassium_mg:800,magnesium_mg:0,notes:"Midday drink"},mag_pm:{sodium_mg:0,potassium_mg:0,magnesium_mg:400,notes:"Magnesium glycinate PM"}};try{await J.logElectrolytes(W[B]),await y()}catch(Z){alert(Z.message)}}if(f)return l.jsx("div",{className:"page",children:l.jsx("div",{className:"loading",children:"Loading..."})});if(!o)return l.jsx("div",{className:"page",children:l.jsx("div",{className:"error-msg",children:"Failed to load"})});const N=o.macros,j=o.targets,F=o.compliance,_=o.eating_window;return l.jsxs("div",{className:"page",children:[l.jsx("h1",{className:"page-title",children:"Nutrition"}),l.jsxs("div",{className:`gate-banner ${F.compliant_day?"gate-earned":"gate-locked"}`,children:[l.jsx("div",{className:"section-label",style:{marginBottom:"4px"},children:"Today's Keto Day"}),l.jsx("div",{style:{fontFamily:"var(--font-display)",fontWeight:900,fontSize:"1.4rem",color:F.compliant_day?"var(--green)":"var(--accent)"},children:F.compliant_day?"✓ Compliant":"⏳ In progress"}),l.jsxs("div",{style:{fontSize:"0.82rem",color:"var(--text-2)",marginTop:"6px"},children:[F.carb_ok?"✓":"✗"," Net carbs under cap  · ",F.protein_ok?"✓":"✗"," Protein target"]})]}),l.jsxs("div",{className:"card",children:[l.jsx("div",{className:"section-label",children:"Fasting"}),o.active_fast?l.jsxs("div",{children:[l.jsxs("div",{style:{fontSize:"0.8rem",color:"var(--text-3)",marginBottom:"8px"},children:[o.active_fast.fast_type.replace("_"," ")," fast in progress"]}),l.jsx(xm,{fast:o.active_fast}),l.jsx("button",{className:"btn-outline btn-full",onClick:A,disabled:S,style:{marginTop:"14px"},children:"End Fast"})]}):l.jsxs("div",{children:[l.jsxs("div",{style:{marginBottom:"10px",fontSize:"0.85rem",color:"var(--text-2)"},children:["Eating window: ",l.jsx("strong",{children:_.display}),_.in_window_now?l.jsx("span",{style:{color:"var(--green-dark)",marginLeft:"8px"},children:"● open"}):l.jsx("span",{style:{color:"var(--text-3)",marginLeft:"8px"},children:"○ closed"})]}),l.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:"6px",marginBottom:"12px"},children:zc.map(B=>l.jsx("button",{className:g.hours===B.hours?"btn-primary btn-sm":"btn-outline btn-sm",onClick:()=>P(B),children:B.label},B.hours))}),l.jsxs("button",{className:"btn-primary btn-full",onClick:L,disabled:S,children:["Start ",g.label," Fast"]})]})]}),l.jsxs("div",{className:"card",children:[l.jsx("div",{className:"section-label",children:"Today's Macros"}),l.jsx(Gl,{label:"Net carbs",value:N.net_carbs_g,target:j.net_carbs_cap,unit:"g",inverse:!0}),l.jsx(Gl,{label:"Protein",value:N.protein_g,target:j.protein_g,unit:"g",color:"var(--accent)"}),l.jsx(Gl,{label:"Fat",value:N.fat_g,target:j.fat_g,unit:"g",color:"#FFA726"}),l.jsx(Gl,{label:"Calories",value:N.calories,target:j.calories,unit:"kcal",color:"#2979FF"}),l.jsx("button",{className:"btn-outline btn-full btn-sm",onClick:()=>z("/food"),style:{marginTop:"8px"},children:"+ Log Food"})]}),s&&l.jsxs("div",{className:"card",children:[l.jsx("div",{className:"section-label",children:"Electrolytes Today"}),l.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:"10px",marginBottom:"12px"},children:[l.jsxs("div",{style:{textAlign:"center"},children:[l.jsx("div",{style:{fontSize:"0.72rem",color:"var(--text-3)",fontWeight:700},children:"SODIUM"}),l.jsx("div",{style:{fontFamily:"var(--font-display)",fontWeight:900,fontSize:"1.1rem"},children:s.sodium_mg}),l.jsxs("div",{style:{fontSize:"0.7rem",color:"var(--text-3)"},children:["/ ",s.targets.sodium_mg,"mg"]})]}),l.jsxs("div",{style:{textAlign:"center"},children:[l.jsx("div",{style:{fontSize:"0.72rem",color:"var(--text-3)",fontWeight:700},children:"POTASSIUM"}),l.jsx("div",{style:{fontFamily:"var(--font-display)",fontWeight:900,fontSize:"1.1rem"},children:s.potassium_mg}),l.jsxs("div",{style:{fontSize:"0.7rem",color:"var(--text-3)"},children:["/ ",s.targets.potassium_mg,"mg"]})]}),l.jsxs("div",{style:{textAlign:"center"},children:[l.jsx("div",{style:{fontSize:"0.72rem",color:"var(--text-3)",fontWeight:700},children:"MAGNESIUM"}),l.jsx("div",{style:{fontFamily:"var(--font-display)",fontWeight:900,fontSize:"1.1rem"},children:s.magnesium_mg}),l.jsxs("div",{style:{fontSize:"0.7rem",color:"var(--text-3)"},children:["/ ",s.targets.magnesium_mg,"mg"]})]})]}),l.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:"6px"},children:[l.jsx("button",{className:"btn-outline btn-sm",onClick:()=>R("morning"),children:"+ Morning"}),l.jsx("button",{className:"btn-outline btn-sm",onClick:()=>R("midday"),children:"+ Midday"}),l.jsx("button",{className:"btn-outline btn-sm",onClick:()=>R("mag_pm"),children:"+ Mag PM"})]})]})]})}function wm(){const[o,c]=m.useState([]),[s,d]=m.useState(""),[f,v]=m.useState("100"),[g,P]=m.useState(null),[S,T]=m.useState(!0);m.useEffect(()=>{z()},[]);async function z(){try{const[A,R]=await Promise.all([J.listRewards(),J.today()]);c(A),P(R)}catch(A){console.error(A)}finally{T(!1)}}async function y(A){if(A.preventDefault(),!!s.trim())try{await J.createReward({name:s,point_cost:parseInt(f)||100}),d(""),v("100"),await z()}catch(R){alert(R.message)}}async function L(A){try{await J.redeemReward(A),await z()}catch(R){alert(R.message)}}return S?l.jsx("div",{className:"page",children:l.jsx("div",{className:"loading",children:"Loading..."})}):l.jsxs("div",{className:"page",children:[l.jsx("h1",{className:"page-title",children:"🎮 Rewards"}),g&&l.jsxs("div",{className:`gate-banner ${g.gate_passed?"gate-earned":"gate-locked"}`,style:{padding:"18px",marginBottom:"14px"},children:[l.jsx("div",{style:{fontWeight:800,fontSize:"1rem",fontFamily:"var(--font-display)"},children:g.gate_passed?l.jsx("span",{style:{color:"var(--green-dark)"},children:"✨ Rewards Unlocked"}):l.jsxs("span",{style:{color:"var(--text-2)"},children:["🔒 Earn ",g.points_remaining," more pts"]})}),l.jsxs("div",{style:{fontSize:"0.82rem",color:"var(--text-3)",fontWeight:600,marginTop:"2px"},children:[g.points_earned," / ",g.daily_minimum," pts today"]})]}),l.jsxs("div",{className:"card",children:[l.jsx("div",{className:"section-label",children:"Your Rewards"}),o.length===0&&l.jsx("div",{style:{textAlign:"center",color:"var(--text-3)",padding:"20px",fontWeight:500},children:"No rewards yet — add one below!"}),o.map(A=>l.jsxs("div",{className:"reward-card",children:[l.jsxs("div",{children:[l.jsx("div",{style:{fontWeight:700,fontSize:"0.95rem"},children:A.name}),l.jsxs("div",{style:{fontSize:"0.78rem",color:"var(--text-3)",fontWeight:600},children:[A.point_cost," pts"]})]}),l.jsx("button",{className:g!=null&&g.gate_passed?"btn-success btn-sm":"btn-outline btn-sm",disabled:!(g!=null&&g.gate_passed),onClick:()=>L(A.id),style:{opacity:g!=null&&g.gate_passed?1:.4},children:g!=null&&g.gate_passed?"Redeem":"Locked"})]},A.id))]}),l.jsxs("div",{className:"card",children:[l.jsx("div",{className:"section-label",children:"Add New Reward"}),l.jsxs("form",{onSubmit:y,children:[l.jsxs("div",{style:{display:"grid",gridTemplateColumns:"2fr 1fr",gap:"10px",marginBottom:"10px"},children:[l.jsx("input",{value:s,onChange:A=>d(A.target.value),placeholder:"e.g. 1hr gaming",required:!0}),l.jsx("input",{type:"number",value:f,onChange:A=>v(A.target.value),placeholder:"pts"})]}),l.jsx("button",{type:"submit",className:"btn-primary btn-full btn-sm",children:"Add Reward"})]})]})]})}function jm(){const[o,c]=m.useState(null),[s,d]=m.useState([]),[f,v]=m.useState(null),[g,P]=m.useState(null),[S,T]=m.useState(!0),z=Ge();m.useEffect(()=>{y()},[]);async function y(){try{const[j,F,_,B]=await Promise.all([J.me(),J.getRules(),J.getTargets(),J.integrationStatus()]);c(j),d(F),v(_),P(B)}catch(j){console.error(j)}finally{T(!1)}}async function L(j,F){try{await J.updateRule(j,{points:parseInt(F)})}catch(_){alert(_.message)}}async function A(j,F){const _={[j]:parseInt(F)};try{await J.updateTargets(_),v({...f,..._})}catch(B){alert(B.message)}}async function R(j){try{const F=await(j==="strava"?J.stravaAuth:J.polarAuth)();window.location.href=F.auth_url}catch(F){alert(F.message)}}async function N(j){if(confirm(`Disconnect ${j}?`))try{await J.disconnect(j),await y()}catch(F){alert(F.message)}}return S?l.jsx("div",{className:"page",children:l.jsx("div",{className:"loading",children:"Loading..."})}):l.jsxs("div",{className:"page",children:[l.jsx("h1",{className:"page-title",children:"Settings"}),o&&l.jsxs("div",{className:"card",style:{display:"flex",alignItems:"center",gap:"14px"},children:[l.jsx("div",{style:{width:"48px",height:"48px",borderRadius:"14px",background:"linear-gradient(135deg, var(--accent), var(--accent-light))",display:"flex",alignItems:"center",justifyContent:"center",color:"#fff",fontFamily:"var(--font-display)",fontWeight:900,fontSize:"1.2rem"},children:o.display_name.charAt(0).toUpperCase()}),l.jsxs("div",{children:[l.jsx("div",{style:{fontWeight:700,fontSize:"1rem"},children:o.display_name}),l.jsxs("div",{style:{fontSize:"0.82rem",color:"var(--text-3)",fontWeight:500},children:["@",o.username]})]})]}),l.jsxs("div",{className:"card",children:[l.jsx("div",{className:"section-label",children:"Features"}),l.jsxs("div",{onClick:()=>z("/meal-plan"),style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 0",borderBottom:"1px solid var(--divider)",cursor:"pointer"},children:[l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[l.jsx("span",{style:{fontSize:"1.2rem"},children:"🍽️"}),l.jsxs("div",{children:[l.jsx("div",{style:{fontWeight:700,fontSize:"0.95rem"},children:"Meal Plans"}),l.jsx("div",{style:{fontSize:"0.78rem",color:"var(--text-3)",fontWeight:500},children:"AI-generated plans with compliance tracking"})]})]}),l.jsx("span",{style:{color:"var(--text-3)",fontSize:"1.1rem"},children:"›"})]}),l.jsxs("div",{onClick:()=>z("/settings/integrations"),style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 0",borderBottom:"1px solid var(--divider)",cursor:"pointer"},children:[l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[l.jsx("span",{style:{fontSize:"1.2rem"},children:"🔗"}),l.jsxs("div",{children:[l.jsx("div",{style:{fontWeight:700,fontSize:"0.95rem"},children:"All Integrations"}),l.jsx("div",{style:{fontSize:"0.78rem",color:"var(--text-3)",fontWeight:500},children:"Strava, Polar, Garmin, Fitbit, USDA, and more"})]})]}),l.jsx("span",{style:{color:"var(--text-3)",fontSize:"1.1rem"},children:"›"})]}),l.jsxs("div",{onClick:()=>z("/rewards"),style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 0",borderBottom:"1px solid var(--divider)",cursor:"pointer"},children:[l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[l.jsx("span",{style:{fontSize:"1.2rem"},children:"🎮"}),l.jsxs("div",{children:[l.jsx("div",{style:{fontWeight:700,fontSize:"0.95rem"},children:"Rewards"}),l.jsx("div",{style:{fontSize:"0.78rem",color:"var(--text-3)",fontWeight:500},children:"Configure and redeem your rewards"})]})]}),l.jsx("span",{style:{color:"var(--text-3)",fontSize:"1.1rem"},children:"›"})]}),l.jsxs("div",{onClick:()=>z("/week"),style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 0",cursor:"pointer"},children:[l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[l.jsx("span",{style:{fontSize:"1.2rem"},children:"📊"}),l.jsxs("div",{children:[l.jsx("div",{style:{fontWeight:700,fontSize:"0.95rem"},children:"Week View"}),l.jsx("div",{style:{fontSize:"0.78rem",color:"var(--text-3)",fontWeight:500},children:"Weekly progress and day-by-day breakdown"})]})]}),l.jsx("span",{style:{color:"var(--text-3)",fontSize:"1.1rem"},children:"›"})]})]}),l.jsxs("div",{className:"card",children:[l.jsx("div",{className:"section-label",children:"Point Rules"}),s.map(j=>l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 0",borderBottom:"1px solid var(--divider)"},children:[l.jsx("div",{style:{flex:1,fontSize:"0.88rem",fontWeight:600},children:j.description}),l.jsx("input",{type:"number",style:{width:"64px",textAlign:"center",padding:"8px",fontWeight:700},defaultValue:j.points,onBlur:F=>L(j.id,F.target.value)}),l.jsx("span",{style:{fontSize:"0.78rem",color:"var(--text-3)",fontWeight:600},children:"pts"})]},j.id))]}),f&&l.jsxs("div",{className:"card",children:[l.jsx("div",{className:"section-label",children:"Daily Targets"}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Daily minimum (unlock rewards)"}),l.jsx("input",{type:"number",defaultValue:f.daily_minimum_pts,onBlur:j=>A("daily_minimum_pts",j.target.value)})]}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Weekly target"}),l.jsx("input",{type:"number",defaultValue:f.weekly_target_pts,onBlur:j=>A("weekly_target_pts",j.target.value)})]}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Weekly bonus"}),l.jsx("input",{type:"number",defaultValue:f.weekly_bonus_pts,onBlur:j=>A("weekly_bonus_pts",j.target.value)})]})]}),l.jsxs("div",{className:"card",children:[l.jsx("div",{className:"section-label",children:"Integrations"}),["strava","polar"].map(j=>{const F=(g==null?void 0:g[j])||{connected:!1};return l.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 0",borderBottom:"1px solid var(--divider)"},children:[l.jsxs("div",{children:[l.jsx("div",{style:{fontWeight:700,textTransform:"capitalize",fontSize:"0.95rem"},children:j}),l.jsx("div",{style:{fontSize:"0.78rem",color:F.connected?"var(--green-dark)":"var(--text-3)",fontWeight:600},children:F.connected?"● Connected":"Not connected"})]}),F.connected?l.jsx("button",{className:"btn-outline btn-sm",onClick:()=>N(j),children:"Disconnect"}):l.jsx("button",{className:"btn-primary btn-sm",onClick:()=>R(j),children:"Connect"})]},j)}),l.jsx("div",{onClick:()=>z("/settings/integrations"),style:{padding:"12px 0",textAlign:"center",cursor:"pointer",color:"var(--accent)",fontSize:"0.88rem",fontWeight:600},children:"Configure all 11 providers →"})]}),l.jsx("button",{className:"btn-danger btn-full",style:{marginTop:"10px"},onClick:()=>{mm(),z("/login")},children:"Sign Out"})]})}function Ft({text:o,children:c}){const[s,d]=m.useState(!1);return l.jsxs("span",{style:{position:"relative",display:"inline-flex",alignItems:"center"},children:[c,l.jsx("span",{onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),onClick:f=>{f.stopPropagation(),d(v=>!v)},style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:"18px",height:"18px",borderRadius:"50%",marginLeft:"6px",background:"rgba(0,0,0,0.06)",color:"var(--text-3)",cursor:"help",fontSize:"0.7rem",fontWeight:800,flexShrink:0},children:"?"}),s&&l.jsx("span",{style:{position:"absolute",bottom:"calc(100% + 8px)",left:"50%",transform:"translateX(-50%)",background:"var(--text)",color:"#fff",padding:"10px 14px",borderRadius:"var(--r-sm)",fontSize:"0.78rem",lineHeight:1.45,fontWeight:500,width:"240px",boxShadow:"var(--shadow-3)",zIndex:50,pointerEvents:"none"},children:o})]})}const km=[{value:"lose_weight",label:"Lose Weight",icon:"⚖️",tip:"Focus on caloric deficit through cardio and portion-controlled nutrition."},{value:"build_strength",label:"Build Strength",icon:"💪",tip:"Progressive overload training — gradually increasing weight or resistance."},{value:"get_active",label:"Get More Active",icon:"🏃",tip:"Building a consistent movement habit. Walking counts!"},{value:"feel_better",label:"Feel Better Overall",icon:"😊",tip:"Mind-body balance — stress relief, sleep quality, energy levels."}],_m=[{value:"precontemplation",label:"I'm not exercising and haven't thought about starting",tip:"Pre-contemplation: No intention to act. We'll start with awareness and gentle nudges."},{value:"contemplation",label:"I've been thinking about getting more active but haven't started",tip:"Contemplation: Weighing pros and cons. We'll help tip the balance toward action."},{value:"preparation",label:"I do some exercise but not consistently",tip:"Preparation: Ready to commit. We'll help you build a sustainable routine."},{value:"action",label:"I've been exercising regularly for a few months",tip:"Action: Building the habit. We'll help you stay consistent and avoid burnout."},{value:"maintenance",label:"I've been exercising regularly for 6+ months",tip:"Maintenance: Solid habit. We'll help you progress and keep things interesting."}],Cm=["Walking","Hiking","Running","Cycling","Swimming","Bodyweight","Weights","Yoga","Martial Arts","Dance","Team Sports","Pilates","Rowing","Jump Rope","Stretching"],Nm=[{value:"bicycle",label:"🚲 Bicycle"},{value:"pool",label:"🏊 Pool"},{value:"free_weights",label:"🏋️ Free Weights"},{value:"squat_rack",label:"🦵 Squat Rack"},{value:"bench_press",label:"💺 Bench Press"},{value:"machines",label:"⚙️ Machines"},{value:"resistance_bands",label:"🔗 Resistance Bands"},{value:"pull_up_bar",label:"🔩 Pull-up Bar"},{value:"kettlebell",label:"🔔 Kettlebell"},{value:"jump_rope",label:"⏩ Jump Rope"},{value:"yoga_mat",label:"🧘 Yoga Mat"},{value:"treadmill",label:"🏃 Treadmill"},{value:"stationary_bike",label:"🚴 Stationary Bike"},{value:"rowing_machine",label:"🚣 Rowing Machine"}],Em=[{key:"ext",label:'"People important to me say I should exercise"',tip:"External regulation: exercising because others push you to. Least self-determined motivation."},{key:"intro",label:'"I feel bad about myself when I skip exercise"',tip:"Introjected regulation: guilt or obligation as a driver. Better than external, but still fragile."},{key:"ident",label:'"I value what exercise does for my health"',tip:"Identified regulation: you see exercise as personally important. A strong, durable motivator."},{key:"intr",label:'"I find exercise enjoyable and satisfying"',tip:"Intrinsic motivation: you exercise because it's fun. The most sustainable form of motivation."},{key:"amot",label:`"I don't really see why I should bother"`,tip:"Amotivation: no perceived reason to exercise. If this is high, we'll start with very small wins."}];function Pm(){const[o,c]=m.useState(0),[s,d]=m.useState(""),[f,v]=m.useState(""),[g,P]=m.useState(""),[S,T]=m.useState(""),[z,y]=m.useState(""),[L,A]=m.useState(""),[R,N]=m.useState({heart:!1,joints:!1,meds:!1}),[j,F]=m.useState({ext:0,intro:0,ident:0,intr:0,amot:0}),[_,B]=m.useState([]),[W,Z]=m.useState([]),[fe,we]=m.useState(3),[xe,re]=m.useState(30),[oe,pe]=m.useState([{name:"",cost:100}]),[Ne,ve]=m.useState([]),[Te,Me]=m.useState(!1),Be=Ge(),Se=8;function H({label:b,value:ee,onChange:ie,tip:de}){return l.jsxs("div",{style:{marginBottom:"16px"},children:[l.jsx("div",{style:{fontSize:"0.9rem",marginBottom:"6px"},children:de?l.jsx(Ft,{text:de,children:b}):b}),l.jsx("div",{className:"likert-row",children:[1,2,3,4,5].map(ye=>l.jsx("button",{type:"button",className:`likert-btn ${ee===ye?"selected":""}`,onClick:()=>ie(ye),children:ye},ye))}),l.jsxs("div",{className:"likert-labels",children:[l.jsx("span",{children:"Not at all"}),l.jsx("span",{children:"Very true"})]})]})}async function I(){Me(!0);try{await J.savePhase1({primary_goal:s,ttm_stage:f}),c(2)}catch(b){alert(b.message)}finally{Me(!1)}}async function V(){Me(!0);try{let b="none";const ee=["squat_rack","bench_press","machines"],ie=["free_weights","resistance_bands","pull_up_bar","kettlebell","yoga_mat","jump_rope"];W.some(ye=>ee.includes(ye))?b="full_gym":W.some(ye=>ie.includes(ye))&&(b="basic_home"),await J.savePhase2({age:g?parseInt(g):null,height_cm:S?parseFloat(S):null,weight_kg:z?parseFloat(z):null,gender:L||null,parq_heart_condition:R.heart,parq_joint_issues:R.joints,parq_medications:R.meds,motivation_external:j.ext||null,motivation_introjected:j.intro||null,motivation_identified:j.ident||null,motivation_intrinsic:j.intr||null,motivation_amotivation:j.amot||null,activity_preferences:_.map(ye=>ye.toLowerCase().replace(/ /g,"_")),equipment_access:b,equipment_list:W,days_per_week:fe,minutes_per_session:xe});for(const ye of oe)ye.name.trim()&&await J.createReward({name:ye.name,point_cost:ye.cost||100});const de=await J.getRecommendations();ve(de.recommendations||[]),c(7)}catch(b){alert(b.message)}finally{Me(!1)}}async function w(b){try{const ee=new Date,ie=new Date(ee);ie.setDate(ee.getDate()+((8-ee.getDay())%7||7));const de=ie.toISOString().split("T")[0];await J.createProgram({name:b.name,source:b.source,source_url:b.url,start_date:de,duration_days:b.duration_days||90}),Be("/")}catch(ee){alert(ee.message)}}function O(b){B(ee=>ee.includes(b)?ee.filter(ie=>ie!==b):[...ee,b])}function ae(b){Z(ee=>ee.includes(b)?ee.filter(ie=>ie!==b):[...ee,b])}const ue=Math.round((o+1)/Se*100),se={fontFamily:"var(--font-display)",fontWeight:900,letterSpacing:"-0.02em",marginBottom:"10px",fontSize:"1.4rem"};return l.jsxs("div",{className:"page",style:{paddingTop:"40px"},children:[l.jsx("div",{className:"progress-bar",style:{marginBottom:"24px"},children:l.jsx("div",{className:"progress-bar-fill",style:{width:`${ue}%`,background:"var(--accent)"}})}),o===0&&l.jsxs("div",{children:[l.jsx("h2",{style:se,children:l.jsx(Ft,{text:"Your primary goal shapes which programs we recommend, how we structure your points, and what success looks like for you.",children:"What matters most to you?"})}),l.jsx("p",{style:{color:"var(--text-3)",marginBottom:"20px",fontSize:"0.9rem"},children:"Pick one — you can change this anytime."}),l.jsx("div",{className:"option-grid",children:km.map(b=>l.jsxs("div",{className:`option-btn ${s===b.value?"selected":""}`,onClick:()=>d(b.value),children:[l.jsx("div",{style:{fontSize:"1.5rem",marginBottom:"6px"},children:b.icon}),l.jsx(Ft,{text:b.tip,children:b.label})]},b.value))}),l.jsx("button",{className:"btn-primary btn-full",style:{marginTop:"20px"},disabled:!s,onClick:()=>c(1),children:"Continue"})]}),o===1&&l.jsxs("div",{children:[l.jsx("h2",{style:se,children:l.jsx(Ft,{text:"Based on the Transtheoretical Model (Stages of Change). This helps us match you with the right intensity — pushing too hard too early is the #1 reason people quit.",children:"Where are you now?"})}),l.jsx("p",{style:{color:"var(--text-3)",marginBottom:"20px",fontSize:"0.9rem"},children:"Be honest — there's no wrong answer."}),_m.map(b=>l.jsx("div",{className:`option-btn ${f===b.value?"selected":""}`,style:{textAlign:"left",marginBottom:"10px"},onClick:()=>v(b.value),children:l.jsx(Ft,{text:b.tip,children:b.label})},b.value)),l.jsx("button",{className:"btn-primary btn-full",style:{marginTop:"16px"},disabled:!f||Te,onClick:I,children:Te?"...":"Continue"})]}),o===2&&l.jsxs("div",{children:[l.jsx("h2",{style:se,children:l.jsx(Ft,{text:"Based on the PAR-Q+ (Physical Activity Readiness Questionnaire). A standard pre-exercise safety screening used by fitness professionals worldwide.",children:"Quick health check"})}),l.jsx("p",{style:{color:"var(--text-3)",marginBottom:"20px",fontSize:"0.9rem"},children:"For your safety — this takes 10 seconds."}),[{key:"heart",label:"I have a heart condition or high blood pressure"},{key:"joints",label:"I have bone or joint problems that could worsen with exercise"},{key:"meds",label:"I take prescription medications for a chronic condition"}].map(b=>l.jsxs("label",{style:{display:"flex",gap:"12px",padding:"12px 0",cursor:"pointer",borderBottom:"1px solid var(--divider)"},children:[l.jsx("input",{type:"checkbox",checked:R[b.key],onChange:ee=>N({...R,[b.key]:ee.target.checked}),style:{width:"auto"}}),l.jsx("span",{style:{fontSize:"0.9rem"},children:b.label})]},b.key)),(R.heart||R.joints||R.meds)&&l.jsx("div",{style:{marginTop:"12px",padding:"12px",background:"#FFF3E0",borderRadius:"var(--r-sm)",fontSize:"0.85rem",color:"#E65100"},children:"⚠️ We recommend checking with your doctor before starting. This won't stop you — just be mindful."}),l.jsx("button",{className:"btn-primary btn-full",style:{marginTop:"20px"},onClick:()=>c(3),children:"Continue"})]}),o===3&&l.jsxs("div",{children:[l.jsx("h2",{style:se,children:"About you"}),l.jsx("p",{style:{color:"var(--text-3)",marginBottom:"20px",fontSize:"0.9rem"},children:"Optional — helps estimate nutrition needs."}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Age"}),l.jsx("input",{type:"number",value:g,onChange:b=>P(b.target.value),placeholder:"e.g. 35"})]}),l.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Height (cm)"}),l.jsx("input",{type:"number",value:S,onChange:b=>T(b.target.value),placeholder:"175"})]}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Weight (kg)"}),l.jsx("input",{type:"number",value:z,onChange:b=>y(b.target.value),placeholder:"80"})]})]}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Gender"}),l.jsxs("select",{value:L,onChange:b=>A(b.target.value),children:[l.jsx("option",{value:"",children:"Prefer not to say"}),l.jsx("option",{value:"male",children:"Male"}),l.jsx("option",{value:"female",children:"Female"})]})]}),l.jsxs("div",{style:{display:"flex",gap:"10px"},children:[l.jsx("button",{className:"btn-outline btn-full",onClick:()=>c(4),children:"Skip"}),l.jsx("button",{className:"btn-primary btn-full",onClick:()=>c(4),children:"Continue"})]})]}),o===4&&l.jsxs("div",{children:[l.jsx("h2",{style:se,children:l.jsx(Ft,{text:"Based on BREQ-2 (Behavioural Regulation in Exercise Questionnaire). Measures your motivation type from external pressure to intrinsic enjoyment. Your Relative Autonomy Index (RAI) score helps us calibrate how much we push vs. encourage.",children:"What drives you?"})}),l.jsx("p",{style:{color:"var(--text-3)",marginBottom:"20px",fontSize:"0.9rem"},children:"Rate each honestly — helps us calibrate your experience."}),Em.map(b=>l.jsx(H,{label:b.label,tip:b.tip,value:j[b.key],onChange:ee=>F({...j,[b.key]:ee})},b.key)),l.jsx("button",{className:"btn-primary btn-full",onClick:()=>c(5),children:"Continue"})]}),o===5&&l.jsxs("div",{children:[l.jsx("h2",{style:se,children:"What sounds fun?"}),l.jsx("p",{style:{color:"var(--text-3)",marginBottom:"16px",fontSize:"0.9rem"},children:"Pick all that interest you."}),l.jsx("div",{className:"chip-grid",style:{marginBottom:"24px"},children:Cm.map(b=>l.jsx("div",{className:`chip ${_.includes(b)?"selected":""}`,onClick:()=>O(b),children:b},b))}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:l.jsx(Ft,{text:"Select everything you have access to. This helps us recommend programs that match your available equipment — no point suggesting barbell work if you don't have a rack.",children:"Equipment you have access to"})}),l.jsx("div",{className:"chip-grid",children:Nm.map(b=>l.jsx("div",{className:`chip ${W.includes(b.value)?"selected":""}`,onClick:()=>ae(b.value),children:b.label},b.value))}),W.length===0&&l.jsx("p",{style:{color:"var(--text-3)",fontSize:"0.8rem",marginTop:"8px",fontStyle:"italic"},children:"No selection = bodyweight only. That's perfectly fine!"})]}),l.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px",marginTop:"16px",marginBottom:"16px"},children:[l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Days/week"}),l.jsx("select",{value:fe,onChange:b=>we(parseInt(b.target.value)),children:[1,2,3,4,5,6,7].map(b=>l.jsx("option",{value:b,children:b},b))})]}),l.jsxs("div",{className:"form-group",children:[l.jsx("label",{className:"form-label",children:"Minutes/session"}),l.jsx("select",{value:xe,onChange:b=>re(parseInt(b.target.value)),children:[15,20,30,45,60,90].map(b=>l.jsx("option",{value:b,children:b},b))})]})]}),l.jsx("button",{className:"btn-primary btn-full",onClick:()=>c(6),children:"Continue"})]}),o===6&&l.jsxs("div",{children:[l.jsx("h2",{style:se,children:l.jsx(Ft,{text:"The reward gate is the core mechanic: you can't access your rewards until you hit your daily point minimum. This creates a behavioral contract — earn first, enjoy second.",children:"Define your rewards"})}),l.jsx("p",{style:{color:"var(--text-3)",marginBottom:"20px",fontSize:"0.9rem"},children:"What guilty pleasures do you want to earn?"}),oe.map((b,ee)=>l.jsxs("div",{style:{display:"grid",gridTemplateColumns:"2fr 1fr",gap:"10px",marginBottom:"12px"},children:[l.jsx("input",{placeholder:"e.g. 1hr gaming",value:b.name,onChange:ie=>{const de=[...oe];de[ee]={...b,name:ie.target.value},pe(de)}}),l.jsx("input",{type:"number",placeholder:"100",value:b.cost,onChange:ie=>{const de=[...oe];de[ee]={...b,cost:parseInt(ie.target.value)||0},pe(de)}})]},ee)),l.jsx("button",{className:"btn-outline btn-sm",style:{marginBottom:"20px"},onClick:()=>pe([...oe,{name:"",cost:100}]),children:"+ Add another reward"}),l.jsx("button",{className:"btn-primary btn-full",disabled:Te,onClick:V,children:Te?"Saving...":"See Recommendations"})]}),o===7&&l.jsxs("div",{children:[l.jsx("h2",{style:se,children:"Recommended for you"}),l.jsx("p",{style:{color:"var(--text-3)",marginBottom:"20px",fontSize:"0.9rem"},children:"Pick a program and commit to 90 days."}),Ne.map(b=>l.jsxs("div",{className:"card",children:[l.jsx("div",{style:{fontWeight:700,marginBottom:"4px"},children:b.name}),l.jsxs("div",{style:{fontSize:"0.85rem",color:"var(--text-3)",marginBottom:"8px"},children:[b.difficulty," • ",b.duration_days?`${b.duration_days} days`:"Ongoing"," • ",b.source]}),l.jsx("p",{style:{fontSize:"0.9rem",marginBottom:"12px"},children:b.description}),l.jsxs("div",{style:{display:"flex",gap:"8px"},children:[l.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",className:"btn-outline btn-sm",style:{display:"inline-block"},children:"View ↗"}),l.jsx("button",{className:"btn-primary btn-sm",onClick:()=>w(b),children:"Select & Commit"})]})]},b.id)),l.jsx("button",{className:"btn-outline btn-full",style:{marginTop:"8px"},onClick:()=>Be("/"),children:"Skip for now"})]})]})}function zm(){const[o,c]=m.useState(null),[s,d]=m.useState(!0);m.useEffect(()=>{f()},[]);async function f(){try{c(await J.week())}catch(S){console.error(S)}finally{d(!1)}}if(s)return l.jsx("div",{className:"page",children:l.jsx("div",{className:"loading",children:"Loading..."})});if(!o)return l.jsx("div",{className:"page",children:l.jsx("div",{className:"error-msg",children:"Failed to load"})});const v=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],g=o.weekly_target>0?Math.min(100,Math.round(o.total_points_earned/o.weekly_target*100)):0,P=new Date().toISOString().split("T")[0];return l.jsxs("div",{className:"page",children:[l.jsx("h1",{className:"page-title",children:"This Week"}),l.jsxs("div",{className:"card",style:{textAlign:"center",background:"var(--accent-bg)"},children:[l.jsx("div",{className:"section-label",children:"Weekly Total"}),l.jsx("div",{style:{fontFamily:"var(--font-display)",fontSize:"2.6rem",fontWeight:900,letterSpacing:"-0.03em"},children:o.total_points_earned}),l.jsxs("div",{style:{color:"var(--text-3)",fontWeight:600,fontSize:"0.88rem",marginBottom:"12px"},children:["/ ",o.weekly_target," pts"]}),l.jsx("div",{className:"progress-bar",style:{height:"12px"},children:l.jsx("div",{className:"progress-bar-fill",style:{width:`${g}%`,background:o.hit_weekly_target?"linear-gradient(90deg, #00C853, #69F0AE)":"linear-gradient(90deg, #7C4DFF, #B388FF)"}})}),o.hit_weekly_target&&l.jsxs("div",{style:{marginTop:"10px",color:"var(--green-dark)",fontWeight:700,fontSize:"0.9rem"},children:["🏆 Target hit! +",o.weekly_bonus_earned," bonus"]}),l.jsxs("div",{style:{display:"flex",justifyContent:"center",gap:"28px",marginTop:"14px"},children:[l.jsxs("div",{children:[l.jsx("div",{style:{fontFamily:"var(--font-display)",fontWeight:900,fontSize:"1.3rem"},children:o.active_days}),l.jsx("div",{style:{fontSize:"0.72rem",color:"var(--text-3)",fontWeight:600},children:"active days"})]}),l.jsxs("div",{children:[l.jsx("div",{style:{fontFamily:"var(--font-display)",fontWeight:900,fontSize:"1.3rem"},children:o.gate_passed_days}),l.jsx("div",{style:{fontSize:"0.72rem",color:"var(--text-3)",fontWeight:600},children:"rewards earned"})]})]})]}),l.jsxs("div",{className:"card",children:[l.jsx("div",{className:"section-label",children:"Daily Breakdown"}),o.daily_breakdown.map((S,T)=>{const z=S.daily_minimum>0?Math.min(100,Math.round(S.points_earned/S.daily_minimum*100)):0,y=S.date===P;return l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 0",borderBottom:T<6?"1px solid var(--divider)":"none"},children:[l.jsx("div",{style:{width:"38px",fontWeight:y?800:600,fontSize:"0.85rem",color:y?"var(--accent)":"var(--text)"},children:v[T]}),l.jsx("div",{style:{flex:1},children:l.jsx("div",{className:"progress-bar",style:{height:"8px"},children:l.jsx("div",{className:"progress-bar-fill",style:{width:`${z}%`,background:S.gate_passed?"var(--green)":S.points_earned>0?"var(--amber)":"transparent"}})})}),l.jsx("div",{style:{width:"46px",textAlign:"right",fontFamily:"var(--font-display)",fontWeight:800,fontSize:"0.9rem"},children:S.points_earned}),l.jsx("div",{style:{width:"22px",textAlign:"center",fontSize:"0.9rem"},children:S.gate_passed?"✅":S.points_earned>0?"🟡":"⬜"})]},S.date)})]})]})}function Tm(){const o=Ge();return l.jsxs("div",{className:"page",style:{maxWidth:600,margin:"0 auto",padding:"40px 20px",textAlign:"center"},children:[l.jsx("div",{style:{fontSize:"3rem",marginBottom:16},children:"💪"}),l.jsx("h1",{style:{fontSize:"1.8rem",fontWeight:700,marginBottom:8},children:"Earn Before You Spend"}),l.jsx("p",{style:{color:"var(--text-2)",fontSize:"1rem",lineHeight:1.6,marginBottom:32},children:"This app runs on a simple idea: you earn points by doing healthy things (workouts, logging meals, hitting step goals), and you spend points on guilty pleasures you configure yourself."}),l.jsxs("div",{style:{background:"var(--surface-2)",borderRadius:"var(--r-md)",padding:24,marginBottom:24,textAlign:"left"},children:[l.jsxs("div",{style:{display:"flex",gap:16,marginBottom:16},children:[l.jsx("span",{style:{fontSize:"1.5rem"},children:"🔒"}),l.jsxs("div",{children:[l.jsx("strong",{children:"Daily Gate"}),l.jsx("p",{style:{color:"var(--text-2)",margin:"4px 0 0",fontSize:"0.9rem"},children:"Until you earn enough points today, your rewards stay locked. Hit your target, and the gate opens."})]})]}),l.jsxs("div",{style:{display:"flex",gap:16,marginBottom:16},children:[l.jsx("span",{style:{fontSize:"1.5rem"},children:"🎮"}),l.jsxs("div",{children:[l.jsx("strong",{children:"Your Rules"}),l.jsx("p",{style:{color:"var(--text-2)",margin:"4px 0 0",fontSize:"0.9rem"},children:"You set the rewards — gaming time, takeout, screen time, whatever you want. You hold yourself accountable."})]})]}),l.jsxs("div",{style:{display:"flex",gap:16},children:[l.jsx("span",{style:{fontSize:"1.5rem"},children:"🤖"}),l.jsxs("div",{children:[l.jsx("strong",{children:"AI Agent (Optional)"}),l.jsx("p",{style:{color:"var(--text-2)",margin:"4px 0 0",fontSize:"0.9rem"},children:"Connect an AI agent to log activities by voice, get nudged when you're behind, and have a fitness companion that knows your goals."})]})]})]}),l.jsx("button",{onClick:()=>o("/register"),style:{background:"var(--accent)",color:"#fff",border:"none",borderRadius:"var(--r-sm)",padding:"14px 32px",fontSize:"1rem",fontWeight:600,cursor:"pointer",width:"100%"},children:"Get Started"}),l.jsx("p",{style:{color:"var(--text-3)",fontSize:"0.8rem",marginTop:16},children:"Points reset weekly. Each week is a fresh start."})]})}const Tc={connected:"var(--green)",configured:"var(--amber)",not_configured:"var(--text-3)"},bm={connected:"Connected",configured:"Configured",not_configured:"Not configured"};function Rm(){const[o,c]=m.useState({}),[s,d]=m.useState({}),[f,v]=m.useState(!0),[g,P]=m.useState(null),[S,T]=m.useState({}),[z,y]=m.useState(!1);m.useEffect(()=>{L()},[]);async function L(){try{const[N,j]=await Promise.all([J.listProviders(),J.fullIntegrationStatus()]);c(N),d(j)}catch(N){console.error(N)}finally{v(!1)}}function A(N){var F;P(N);const j=((F=o[N])==null?void 0:F.fields)||[];T(Object.fromEntries(j.map(_=>[_,""])))}async function R(N){y(!0);try{await J.configureIntegration(N,S),P(null),await L()}catch(j){alert(`Failed: ${j.message}`)}finally{y(!1)}}return f?l.jsx("div",{className:"page",children:l.jsx("div",{className:"loading",children:"Loading..."})}):l.jsxs("div",{className:"page",style:{maxWidth:700,margin:"0 auto"},children:[l.jsx("h1",{style:{fontSize:"1.4rem",fontWeight:700,marginBottom:24},children:"Integrations"}),l.jsx("p",{style:{color:"var(--text-2)",marginBottom:24,fontSize:"0.9rem"},children:"Configure your fitness devices and services. Credentials are encrypted and stored locally — never sent to any external server."}),Object.entries(o).map(([N,j])=>l.jsxs("div",{style:{background:"var(--surface-2)",borderRadius:"var(--r-md)",padding:20,marginBottom:12,border:s[N]==="connected"?"2px solid var(--accent)":"1px solid var(--border)"},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:8},children:[l.jsx("strong",{style:{fontSize:"1rem"},children:j.name}),l.jsx("span",{style:{fontSize:"0.75rem",padding:"3px 10px",borderRadius:20,fontWeight:600,background:Tc[s[N]||"not_configured"]+"22",color:Tc[s[N]||"not_configured"]},children:bm[s[N]||"not_configured"]})]}),l.jsx("p",{style:{color:"var(--text-2)",fontSize:"0.85rem",margin:"0 0 12px"},children:j.help_text}),j.help_url&&l.jsx("a",{href:j.help_url,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"0.8rem",color:"var(--accent)"},children:"Developer portal →"}),g===N?l.jsxs("div",{style:{marginTop:12,padding:16,background:"var(--surface)",borderRadius:"var(--r-sm)"},children:[j.fields.map(F=>l.jsxs("div",{style:{marginBottom:10},children:[l.jsx("label",{style:{fontSize:"0.8rem",fontWeight:600,display:"block",marginBottom:4},children:F.replace(/_/g," ")}),l.jsx("input",{type:F.includes("secret")||F.includes("token")||F.includes("key")?"password":"text",value:S[F]||"",onChange:_=>T({...S,[F]:_.target.value}),style:{width:"100%",padding:"8px 12px",borderRadius:"var(--r-sm)",border:"1px solid var(--border)",fontSize:"0.9rem",boxSizing:"border-box"},placeholder:`Enter ${F.replace(/_/g," ")}`})]},F)),l.jsxs("div",{style:{display:"flex",gap:8,marginTop:8},children:[l.jsx("button",{onClick:()=>R(N),disabled:z,style:{background:"var(--accent)",color:"#fff",border:"none",padding:"8px 20px",borderRadius:"var(--r-sm)",cursor:"pointer",fontWeight:600},children:z?"Saving...":"Save"}),l.jsx("button",{onClick:()=>P(null),style:{background:"transparent",color:"var(--text-2)",border:"1px solid var(--border)",padding:"8px 20px",borderRadius:"var(--r-sm)",cursor:"pointer"},children:"Cancel"})]})]}):l.jsx("button",{onClick:()=>A(N),style:{marginTop:8,background:"transparent",color:"var(--accent)",border:"1px solid var(--accent)",padding:"6px 16px",borderRadius:"var(--r-sm)",cursor:"pointer",fontSize:"0.85rem",fontWeight:600},children:s[N]==="not_configured"?"Configure":"Reconfigure"})]},N))]})}const Lm={breakfast:"🌅",lunch:"🌞",dinner:"🌙",snack:"🍎"};function Im(){var z;const[o,c]=m.useState(null),[s,d]=m.useState([]),[f,v]=m.useState(!0),[g,P]=m.useState({});m.useEffect(()=>{S()},[]);async function S(){try{const[y,L]=await Promise.all([J.getMealPlanToday(),J.listMealPlans()]);c(y),d(L)}catch(y){console.error(y)}finally{v(!1)}}async function T(y,L){try{await J.logMealCompliance({plan_item_id:y,status:L}),P(A=>({...A,[y]:L}))}catch(A){alert(`Failed: ${A.message}`)}}return f?l.jsx("div",{className:"page",children:l.jsx("div",{className:"loading",children:"Loading..."})}):l.jsxs("div",{className:"page",style:{maxWidth:600,margin:"0 auto"},children:[l.jsx("h1",{style:{fontSize:"1.4rem",fontWeight:700,marginBottom:8},children:"Meal Plan"}),o!=null&&o.active_plan?l.jsxs(l.Fragment,{children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:20,color:"var(--text-2)",fontSize:"0.9rem"},children:[l.jsx("span",{children:o.active_plan}),l.jsxs("span",{style:{background:"var(--accent)",color:"#fff",padding:"3px 10px",borderRadius:20,fontSize:"0.75rem",fontWeight:600},children:["Day ",o.day," / ",o.duration_days]})]}),o.daily_calories&&l.jsxs("div",{style:{background:"var(--surface-2)",borderRadius:"var(--r-sm)",padding:12,marginBottom:16,textAlign:"center",fontSize:"0.85rem",color:"var(--text-2)"},children:["Target: ",o.daily_calories," cal · ",o.diet_type||"balanced"]}),((z=o.meals)==null?void 0:z.length)>0?o.meals.map(y=>{const L=g[y.id];return l.jsxs("div",{style:{background:"var(--surface-2)",borderRadius:"var(--r-md)",padding:16,marginBottom:10,borderLeft:L==="followed"?"4px solid var(--green)":L==="skipped"?"4px solid var(--red)":L==="substituted"?"4px solid var(--amber)":"4px solid transparent"},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[l.jsxs("div",{children:[l.jsxs("div",{style:{fontSize:"0.75rem",color:"var(--text-3)",textTransform:"uppercase",marginBottom:4},children:[Lm[y.meal_type]||"🍽️"," ",y.meal_type]}),l.jsx("div",{style:{fontWeight:600,marginBottom:4},children:y.food_name}),y.description&&l.jsx("div",{style:{fontSize:"0.85rem",color:"var(--text-2)"},children:y.description})]}),y.calories&&l.jsxs("div",{style:{fontSize:"0.85rem",fontWeight:600,color:"var(--text-2)",flexShrink:0,marginLeft:12},children:[y.calories," cal"]})]}),y.protein_g&&l.jsxs("div",{style:{fontSize:"0.75rem",color:"var(--text-3)",marginTop:6},children:["P: ",y.protein_g,"g · C: ",y.carbs_g,"g · F: ",y.fat_g,"g"]}),!L&&l.jsx("div",{style:{display:"flex",gap:6,marginTop:10},children:["followed","substituted","skipped"].map(A=>l.jsxs("button",{onClick:()=>T(y.id,A),style:{background:"transparent",border:"1px solid var(--border)",padding:"4px 12px",borderRadius:"var(--r-sm)",fontSize:"0.75rem",cursor:"pointer",color:"var(--text-2)",textTransform:"capitalize"},children:[A==="followed"?"✅":A==="skipped"?"⏭️":"🔄"," ",A]},A))})]},y.id)}):l.jsx("p",{style:{color:"var(--text-2)",textAlign:"center"},children:o.message||"No meals for today."})]}):l.jsxs("div",{style:{background:"var(--surface-2)",borderRadius:"var(--r-md)",padding:32,textAlign:"center",color:"var(--text-2)"},children:[l.jsx("div",{style:{fontSize:"2rem",marginBottom:12},children:"🍽️"}),l.jsx("p",{style:{marginBottom:8},children:"No active meal plan."}),l.jsx("p",{style:{fontSize:"0.85rem"},children:'Ask your AI agent to create one: "Generate a 7-day keto meal plan for me"'})]}),s.length>0&&l.jsxs("div",{style:{marginTop:32},children:[l.jsx("h2",{style:{fontSize:"1.1rem",fontWeight:600,marginBottom:12},children:"All Plans"}),s.map(y=>l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"10px 0",borderBottom:"1px solid var(--border)"},children:[l.jsxs("div",{children:[l.jsx("div",{style:{fontWeight:500},children:y.name}),l.jsxs("div",{style:{fontSize:"0.8rem",color:"var(--text-3)"},children:[y.diet_type," · ",y.duration_days," days · started ",y.start_date]})]}),l.jsx("span",{style:{fontSize:"0.75rem",padding:"2px 8px",borderRadius:12,background:y.status==="active"?"var(--green)22":"var(--text-3)22",color:y.status==="active"?"var(--green)":"var(--text-3)",fontWeight:600},children:y.status})]},y.id))]})]})}const bc={beginner:"var(--green)",intermediate:"var(--accent)",advanced:"var(--accent-light)"},Fm={strength:"🏋️",cardio:"🏃",flexibility:"🧘",hybrid:"⚡"},Rc={pending:{label:"Queued",color:"var(--amber)"},crawling:{label:"Fetching...",color:"var(--accent)"},extracting:{label:"Analyzing...",color:"var(--accent-light)"},ready:{label:"Ready",color:"var(--green)"},failed:{label:"Failed",color:"var(--red)"}};function Bm(){const[o,c]=m.useState(""),[s,d]=m.useState([]),[f,v]=m.useState([]),[g,P]=m.useState(!0),[S,T]=m.useState(!1),[z,y]=m.useState(null),L=Ge();m.useEffect(()=>{A()},[]);async function A(){try{const[_,B]=await Promise.all([J.searchCatalog(""),J.listPrograms()]);d(_),v(B)}catch(_){console.error(_)}finally{P(!1)}}async function R(_){if(_.preventDefault(),!!o.trim())try{const B=await J.searchCatalog(o);d(B)}catch(B){console.error(B)}}async function N(){if(o.trim()){T(!0),y(null);try{const _=await J.researchProgram(o);_.already_exists?y({type:"info",text:`"${_.name}" is already in the catalog.`}):y({type:"success",text:_.message||"Program queued for research!"}),await A()}catch(_){y({type:"error",text:_.message})}finally{T(!1)}}}async function j(_){const B=new Date().toISOString().slice(0,10);try{await J.adoptProgram(_,B),y({type:"success",text:"Program started! Check your dashboard."}),await A()}catch(W){y({type:"error",text:W.message})}}function F(_){return f.some(B=>B.status==="active"&&B.catalog_id===_)}return g?l.jsx("div",{style:{padding:"2rem",textAlign:"center",color:"var(--text-3)"},children:"Loading..."}):l.jsxs("div",{style:{padding:"1rem",paddingBottom:"96px",maxWidth:"600px",margin:"0 auto"},children:[l.jsx("h1",{style:{fontFamily:"var(--font-display)",fontSize:"1.6rem",fontWeight:900,marginBottom:"0.5rem"},children:"Programs"}),l.jsx("p",{style:{color:"var(--text-3)",fontSize:"0.85rem",marginBottom:"1.5rem"},children:"Find a program or tell us what you're doing — we'll set it up for you."}),l.jsxs("form",{onSubmit:R,style:{display:"flex",gap:"0.5rem",marginBottom:"1rem"},children:[l.jsx("input",{type:"text",value:o,onChange:_=>c(_.target.value),placeholder:'e.g. "StrongLifts 5x5" or "Couch to 5K"',style:{flex:1,padding:"12px 16px",borderRadius:"var(--r)",border:"1px solid var(--divider)",fontFamily:"var(--font)",fontSize:"0.9rem",background:"var(--card)"}}),l.jsx("button",{type:"submit",style:{background:"var(--accent)",color:"#fff",padding:"12px 18px",boxShadow:"var(--shadow-1)"},children:"Search"})]}),l.jsx("button",{onClick:N,disabled:S||!o.trim(),style:{width:"100%",background:S?"var(--text-3)":"var(--accent)",color:"#fff",padding:"14px",marginBottom:"1rem",boxShadow:S?"none":"var(--shadow-accent)",opacity:o.trim()?1:.5},children:S?"Researching...":`Research "${o||"..."}" for me`}),z&&l.jsx("div",{style:{padding:"12px 16px",borderRadius:"var(--r-sm)",marginBottom:"1rem",fontSize:"0.85rem",fontWeight:600,background:z.type==="error"?"var(--red-ghost)":z.type==="success"?"var(--green-bg)":"var(--accent-bg)",color:z.type==="error"?"var(--red)":z.type==="success"?"var(--green-dark)":"var(--accent)"},children:z.text}),f.filter(_=>_.status==="active").length>0&&l.jsxs(l.Fragment,{children:[l.jsx("h2",{style:{fontFamily:"var(--font-display)",fontSize:"1.1rem",fontWeight:800,marginBottom:"0.75rem"},children:"Your Active Programs"}),f.filter(_=>_.status==="active").map(_=>l.jsxs("div",{onClick:()=>L(`/programs/${_.id}`),style:{background:"var(--card)",borderRadius:"var(--r)",padding:"16px",marginBottom:"0.75rem",boxShadow:"var(--shadow-1)",cursor:"pointer",border:"2px solid var(--accent-glow)"},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[l.jsx("strong",{style:{fontFamily:"var(--font-display)",fontSize:"1rem"},children:_.name}),l.jsxs("span",{style:{fontSize:"0.8rem",color:"var(--accent)",fontWeight:700},children:["Day ",_.current_day,"/",_.total_days]})]}),l.jsx("div",{style:{marginTop:"8px",height:"6px",borderRadius:"3px",background:"var(--divider)"},children:l.jsx("div",{style:{height:"100%",borderRadius:"3px",background:"var(--accent)",width:`${Math.min(100,_.current_day/_.total_days*100)}%`,transition:"width 0.3s ease"}})})]},_.id))]}),l.jsx("h2",{style:{fontFamily:"var(--font-display)",fontSize:"1.1rem",fontWeight:800,marginTop:"1.5rem",marginBottom:"0.75rem"},children:"Program Catalog"}),s.length===0&&l.jsx("p",{style:{color:"var(--text-3)",fontSize:"0.85rem",textAlign:"center",padding:"2rem 0"},children:"No programs found. Try searching or researching a program above."}),s.map(_=>{const B=Rc[_.crawl_status]||Rc.pending,W=F(_.id);return l.jsxs("div",{style:{background:"var(--card)",borderRadius:"var(--r)",padding:"16px",marginBottom:"0.75rem",boxShadow:"var(--shadow-1)"},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[l.jsxs("div",{children:[l.jsxs("strong",{style:{fontFamily:"var(--font-display)",fontSize:"1rem"},children:[Fm[_.category]||"📋"," ",_.name]}),_.description&&l.jsx("p",{style:{color:"var(--text-2)",fontSize:"0.82rem",marginTop:"4px"},children:_.description})]}),l.jsx("span",{style:{fontSize:"0.7rem",fontWeight:700,padding:"3px 8px",borderRadius:"var(--r-full)",color:"#fff",background:B.color,whiteSpace:"nowrap"},children:B.label})]}),l.jsxs("div",{style:{display:"flex",gap:"0.5rem",flexWrap:"wrap",marginTop:"10px"},children:[_.duration_weeks&&l.jsxs("span",{style:Xl,children:[_.duration_weeks," weeks"]}),_.frequency_per_week&&l.jsxs("span",{style:Xl,children:[_.frequency_per_week,"x/week"]}),_.difficulty&&l.jsx("span",{style:{...Xl,color:bc[_.difficulty]||"var(--text-3)",background:`${bc[_.difficulty]||"var(--text-3)"}11`},children:_.difficulty}),(_.equipment||[]).slice(0,3).map(Z=>l.jsx("span",{style:Xl,children:Z},Z))]}),_.crawl_status==="ready"&&!W&&l.jsx("button",{onClick:()=>j(_.id),style:{marginTop:"12px",width:"100%",background:"var(--green)",color:"#fff",padding:"10px",fontSize:"0.85rem",boxShadow:"var(--shadow-green)"},children:"Start Program"}),W&&l.jsx("div",{style:{marginTop:"12px",textAlign:"center",fontSize:"0.82rem",color:"var(--green-dark)",fontWeight:700},children:"✓ Active"}),_.crawl_status==="ready"&&l.jsx("button",{onClick:()=>L(`/catalog/${_.id}`),style:{marginTop:W?"4px":"8px",width:"100%",background:"transparent",color:"var(--accent)",padding:"8px",fontSize:"0.82rem",border:"1px solid var(--divider)"},children:"View Details"})]},_.id)})]})}const Xl={fontSize:"0.72rem",fontWeight:600,padding:"3px 10px",borderRadius:"var(--r-full)",background:"var(--divider)",color:"var(--text-2)"};function Wm(){const{id:o}=ma(),c=Ge(),[s,d]=m.useState(null),[f,v]=m.useState(null),[g,P]=m.useState(!0),[S,T]=m.useState(null),[z,y]=m.useState(null),[L,A]=m.useState(null);m.useEffect(()=>{R()},[o]);async function R(){try{const[F,_]=await Promise.all([J.getProgramSchedule(o),J.getProgramProgress(o)]);d(F),v(_)}catch(F){console.error(F)}finally{P(!1)}}async function N(F){T(F);try{const _=await J.completeWorkout(o,F,{});A(_),y(null),await R()}catch(_){alert(_.message)}finally{T(null)}}if(g)return l.jsx("div",{style:{padding:"2rem",textAlign:"center",color:"var(--text-3)"},children:"Loading..."});if(!s)return l.jsx("div",{style:{padding:"2rem",textAlign:"center"},children:"Program not found"});const j=f?f.completion_pct:0;return l.jsxs("div",{style:{padding:"1rem",paddingBottom:"96px",maxWidth:"600px",margin:"0 auto"},children:[l.jsx("button",{onClick:()=>c("/programs"),style:{background:"transparent",color:"var(--text-3)",padding:"8px 0",fontSize:"0.85rem",marginBottom:"0.5rem"},children:"← Programs"}),l.jsxs("div",{style:{background:"var(--card)",borderRadius:"var(--r-lg)",padding:"20px",boxShadow:"var(--shadow-2)",marginBottom:"1.5rem"},children:[l.jsx("h1",{style:{fontFamily:"var(--font-display)",fontSize:"1.5rem",fontWeight:900},children:s.program_name}),l.jsxs("div",{style:{display:"flex",gap:"1.5rem",marginTop:"10px",fontSize:"0.82rem",color:"var(--text-2)"},children:[l.jsxs("span",{children:["Week ",s.current_week]}),l.jsxs("span",{children:[(f==null?void 0:f.completed_workouts)||0,"/",(f==null?void 0:f.total_workouts)||0," workouts"]}),l.jsxs("span",{style:{color:"var(--accent)",fontWeight:700},children:[j,"%"]})]}),l.jsx("div",{style:{marginTop:"12px",height:"8px",borderRadius:"4px",background:"var(--divider)"},children:l.jsx("div",{style:{height:"100%",borderRadius:"4px",background:j>=100?"var(--green)":"var(--accent)",width:`${Math.min(100,j)}%`,transition:"width 0.4s ease"}})}),s.progression_rules&&l.jsxs("p",{style:{marginTop:"12px",fontSize:"0.8rem",color:"var(--text-3)",lineHeight:1.5,borderTop:"1px solid var(--divider)",paddingTop:"12px"},children:["📈 ",s.progression_rules]})]}),L&&l.jsxs("div",{style:{background:"var(--green-bg)",borderRadius:"var(--r)",padding:"16px",marginBottom:"1rem",textAlign:"center"},children:[l.jsx("div",{style:{fontSize:"1.8rem",marginBottom:"4px"},children:"🎉"}),l.jsxs("strong",{style:{color:"var(--green-dark)"},children:["+",L.total_points," points!"]}),l.jsxs("div",{style:{fontSize:"0.8rem",color:"var(--text-2)",marginTop:"4px"},children:["Workout: +",L.points_earned,L.weekly_bonus>0&&` • Week bonus: +${L.weekly_bonus}`,L.completion_bonus>0&&` • Program complete: +${L.completion_bonus}!`]}),l.jsx("button",{onClick:()=>A(null),style:{marginTop:"10px",background:"transparent",color:"var(--green-dark)",fontSize:"0.8rem",padding:"6px 16px",border:"1px solid var(--green)"},children:"Dismiss"})]}),s.today_workout&&!s.today_workout.completed&&!s.today_workout.rest_day&&l.jsxs("div",{style:{background:"var(--card)",borderRadius:"var(--r)",padding:"16px",marginBottom:"1.5rem",boxShadow:"var(--shadow-2)",border:"2px solid var(--accent-glow)"},children:[l.jsx("div",{style:{fontSize:"0.72rem",fontWeight:700,color:"var(--accent)",textTransform:"uppercase",letterSpacing:"0.05em",marginBottom:"6px"},children:"Today's Workout"}),l.jsx("strong",{style:{fontFamily:"var(--font-display)",fontSize:"1.1rem"},children:s.today_workout.workout_name||`Day ${s.today_workout.day_number}`}),l.jsx("div",{style:{marginTop:"12px"},children:(s.today_workout.exercises||[]).map((F,_)=>l.jsx(Lc,{exercise:F},_))}),l.jsx("button",{onClick:()=>N(s.today_workout.id),disabled:S===s.today_workout.id,style:{marginTop:"14px",width:"100%",padding:"14px",background:S?"var(--text-3)":"var(--green)",color:"#fff",fontSize:"0.95rem",fontWeight:800,boxShadow:"var(--shadow-green)"},children:S===s.today_workout.id?"Logging...":"✓ Complete Workout — 75 pts"})]}),l.jsx("h2",{style:{fontFamily:"var(--font-display)",fontSize:"1.1rem",fontWeight:800,marginBottom:"0.75rem"},children:"Full Schedule"}),Om(s.schedule).map(([F,_])=>l.jsxs("div",{style:{marginBottom:"1.25rem"},children:[l.jsxs("div",{style:{fontSize:"0.78rem",fontWeight:700,color:"var(--text-3)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:"0.5rem",display:"flex",alignItems:"center",gap:"0.5rem"},children:["Week ",F,F===s.current_week&&l.jsx("span",{style:{fontSize:"0.65rem",background:"var(--accent)",color:"#fff",padding:"2px 8px",borderRadius:"var(--r-full)"},children:"Current"})]}),_.map(B=>l.jsxs("div",{style:{background:"var(--card)",borderRadius:"var(--r-sm)",padding:"12px 14px",marginBottom:"0.4rem",boxShadow:"var(--shadow-1)",opacity:B.completed?.7:1,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[l.jsxs("div",{children:[l.jsx("span",{style:{fontSize:"0.85rem",fontWeight:600},children:B.rest_day?"😴 Rest Day":B.workout_name||`Day ${B.day_number}`}),!B.rest_day&&l.jsxs("span",{style:{fontSize:"0.75rem",color:"var(--text-3)",marginLeft:"8px"},children:[(B.exercises||[]).length," exercises"]})]}),l.jsx("div",{children:B.completed?l.jsx("span",{style:{color:"var(--green)",fontSize:"0.85rem",fontWeight:700},children:"✓"}):B.rest_day?null:l.jsx("button",{onClick:()=>y(B),style:{background:"var(--green-bg)",color:"var(--green-dark)",padding:"6px 12px",fontSize:"0.75rem",fontWeight:700},children:"Do it"})})]},B.id))]},F)),z&&l.jsx("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"flex-end",justifyContent:"center",zIndex:100},onClick:()=>y(null),children:l.jsxs("div",{style:{background:"var(--card)",borderRadius:"var(--r-lg) var(--r-lg) 0 0",padding:"24px 20px",width:"100%",maxWidth:"600px",maxHeight:"80vh",overflow:"auto"},onClick:F=>F.stopPropagation(),children:[l.jsx("h3",{style:{fontFamily:"var(--font-display)",fontSize:"1.2rem",fontWeight:800,marginBottom:"4px"},children:z.workout_name||`Week ${z.week_number}, Day ${z.day_number}`}),l.jsx("p",{style:{color:"var(--text-3)",fontSize:"0.82rem",marginBottom:"16px"},children:'Complete the exercises below and tap "Done" when finished.'}),(z.exercises||[]).map((F,_)=>l.jsx(Lc,{exercise:F,detailed:!0},_)),z.notes&&l.jsxs("p",{style:{marginTop:"12px",fontSize:"0.8rem",color:"var(--text-2)",background:"var(--accent-bg)",padding:"10px 12px",borderRadius:"var(--r-sm)"},children:["💡 ",z.notes]}),l.jsxs("div",{style:{display:"flex",gap:"0.5rem",marginTop:"20px"},children:[l.jsx("button",{onClick:()=>y(null),style:{flex:1,background:"var(--divider)",color:"var(--text-2)",padding:"14px"},children:"Cancel"}),l.jsx("button",{onClick:()=>N(z.id),disabled:S===z.id,style:{flex:2,background:"var(--green)",color:"#fff",padding:"14px",fontWeight:800,boxShadow:"var(--shadow-green)"},children:S===z.id?"Logging...":"✓ Done — 75 pts"})]})]})})]})}function Lc({exercise:o,detailed:c}){return l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:c?"10px 0":"6px 0",borderBottom:"1px solid var(--divider)"},children:[l.jsxs("div",{children:[l.jsx("span",{style:{fontWeight:600,fontSize:c?"0.9rem":"0.82rem"},children:o.name}),c&&o.notes&&l.jsx("div",{style:{fontSize:"0.75rem",color:"var(--text-3)",marginTop:"2px"},children:o.notes}),c&&o.weight_instruction&&l.jsxs("div",{style:{fontSize:"0.75rem",color:"var(--accent)",marginTop:"2px"},children:["🏋️ ",o.weight_instruction]})]}),l.jsxs("div",{style:{textAlign:"right",fontSize:"0.8rem",color:"var(--text-2)",fontWeight:600,whiteSpace:"nowrap"},children:[o.sets&&o.reps&&`${o.sets}×${o.reps}`,o.rest_seconds&&c&&l.jsx("div",{style:{fontSize:"0.7rem",color:"var(--text-3)"},children:o.rest_seconds>=60?`${Math.floor(o.rest_seconds/60)}m rest`:`${o.rest_seconds}s rest`})]})]})}function Om(o){const c={};for(const s of o||[]){const d=s.week_number;c[d]||(c[d]=[]),c[d].push(s)}return Object.entries(c).sort(([s],[d])=>Number(s)-Number(d))}const Ic={beginner:"var(--green)",intermediate:"var(--accent)",advanced:"var(--accent-light)"},Mm={strength:"🏋️",cardio:"🏃",flexibility:"🧘",hybrid:"⚡"},Fc={pending:{label:"Queued",color:"var(--amber)"},crawling:{label:"Fetching...",color:"var(--accent)"},extracting:{label:"Analyzing...",color:"var(--accent-light)"},ready:{label:"Ready",color:"var(--green)"},failed:{label:"Failed",color:"var(--red)"}};function Dm(){const{id:o}=ma(),c=Ge(),[s,d]=m.useState(null),[f,v]=m.useState([]),[g,P]=m.useState(!0),[S,T]=m.useState(!1),[z,y]=m.useState(null);m.useEffect(()=>{L()},[o]);async function L(){P(!0);try{const[_,B]=await Promise.all([J.getCatalogProgram(o),J.listPrograms()]);d(_),v(B)}catch(_){y({type:"error",text:_.message||"Could not load program"})}finally{P(!1)}}async function A(){T(!0),y(null);const _=new Date().toISOString().slice(0,10);try{const B=await J.adoptProgram(o,_);y({type:"success",text:"Program started! Redirecting…"}),setTimeout(()=>c(`/programs/${B.id}`),800)}catch(B){y({type:"error",text:B.message}),T(!1)}}if(g)return l.jsx("div",{style:{padding:"2rem",textAlign:"center",color:"var(--text-3)"},children:"Loading..."});if(!s)return l.jsxs("div",{style:{padding:"2rem",textAlign:"center"},children:[l.jsx("p",{style:{color:"var(--text-2)",marginBottom:"1rem"},children:"Program not found."}),l.jsx("button",{onClick:()=>c("/programs"),style:{background:"var(--accent)",color:"#fff",padding:"10px 20px"},children:"← Back to Programs"})]});const R=f.some(_=>_.status==="active"&&_.catalog_id===s.id),N=f.find(_=>_.status==="active"&&_.catalog_id===s.id),j=Fc[s.crawl_status]||Fc.pending,F=Am(s.workouts);return l.jsxs("div",{style:{padding:"1rem",paddingBottom:"96px",maxWidth:"600px",margin:"0 auto"},children:[l.jsx("button",{onClick:()=>c("/programs"),style:{background:"transparent",color:"var(--text-3)",padding:"8px 0",fontSize:"0.85rem",marginBottom:"0.5rem"},children:"← Programs"}),l.jsxs("div",{style:{background:"var(--card)",borderRadius:"var(--r-lg)",padding:"20px",boxShadow:"var(--shadow-2)",marginBottom:"1rem"},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:"1rem"},children:[l.jsxs("h1",{style:{fontFamily:"var(--font-display)",fontSize:"1.5rem",fontWeight:900,lineHeight:1.2},children:[Mm[s.category]||"📋"," ",s.name]}),l.jsx("span",{style:{fontSize:"0.7rem",fontWeight:700,padding:"4px 10px",borderRadius:"var(--r-full)",color:"#fff",background:j.color,whiteSpace:"nowrap"},children:j.label})]}),s.description&&l.jsx("p",{style:{color:"var(--text-2)",fontSize:"0.88rem",marginTop:"12px",lineHeight:1.5},children:s.description}),l.jsxs("div",{style:{display:"flex",gap:"0.5rem",flexWrap:"wrap",marginTop:"14px"},children:[s.duration_weeks&&l.jsxs("span",{style:ql,children:[s.duration_weeks," weeks"]}),s.frequency_per_week&&l.jsxs("span",{style:ql,children:[s.frequency_per_week,"x/week"]}),s.difficulty&&l.jsx("span",{style:{...ql,color:Ic[s.difficulty]||"var(--text-3)",background:`${Ic[s.difficulty]||"var(--text-3)"}15`},children:s.difficulty}),(s.equipment||[]).map(_=>l.jsx("span",{style:ql,children:_},_))]}),s.source_url&&l.jsx("a",{href:s.source_url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",marginTop:"14px",fontSize:"0.78rem",color:"var(--accent)",textDecoration:"none"},children:"🔗 Original source ↗"})]}),z&&l.jsx("div",{style:{padding:"12px 16px",borderRadius:"var(--r-sm)",marginBottom:"1rem",fontSize:"0.85rem",fontWeight:600,background:z.type==="error"?"var(--red-ghost)":"var(--green-bg)",color:z.type==="error"?"var(--red)":"var(--green-dark)"},children:z.text}),s.crawl_status==="ready"&&!R&&l.jsx("button",{onClick:A,disabled:S,style:{width:"100%",background:S?"var(--text-3)":"var(--green)",color:"#fff",padding:"14px",fontSize:"0.95rem",fontWeight:800,marginBottom:"1.25rem",boxShadow:S?"none":"var(--shadow-green)"},children:S?"Starting...":"Start This Program"}),R&&N&&l.jsx("button",{onClick:()=>c(`/programs/${N.id}`),style:{width:"100%",background:"var(--accent)",color:"#fff",padding:"14px",fontSize:"0.95rem",fontWeight:800,marginBottom:"1.25rem",boxShadow:"var(--shadow-accent)"},children:"✓ Active — Open Your Program"}),s.crawl_status!=="ready"&&l.jsx("div",{style:{padding:"14px",borderRadius:"var(--r)",background:"var(--accent-bg)",color:"var(--accent)",fontSize:"0.85rem",marginBottom:"1.25rem",textAlign:"center"},children:s.crawl_status==="failed"?`Crawl failed: ${s.crawl_error||"unknown error"}`:"Program is being researched. Check back soon."}),s.progression_rules&&l.jsxs("div",{style:{background:"var(--card)",borderRadius:"var(--r)",padding:"16px",marginBottom:"1.25rem",boxShadow:"var(--shadow-1)"},children:[l.jsx("div",{style:{fontSize:"0.72rem",fontWeight:700,color:"var(--accent)",textTransform:"uppercase",letterSpacing:"0.05em",marginBottom:"8px"},children:"📈 Progression"}),l.jsx("p",{style:{fontSize:"0.85rem",color:"var(--text-2)",lineHeight:1.5},children:s.progression_rules})]}),F.length>0&&l.jsxs(l.Fragment,{children:[l.jsx("h2",{style:{fontFamily:"var(--font-display)",fontSize:"1.1rem",fontWeight:800,marginBottom:"0.75rem"},children:"Workouts"}),F.map(([_,B])=>l.jsxs("div",{style:{marginBottom:"1.25rem"},children:[l.jsxs("div",{style:{fontSize:"0.78rem",fontWeight:700,color:"var(--text-3)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:"0.5rem"},children:["Week ",_]}),B.map(W=>l.jsxs("div",{style:{background:"var(--card)",borderRadius:"var(--r-sm)",padding:"14px",marginBottom:"0.5rem",boxShadow:"var(--shadow-1)"},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:W.rest_day?0:"8px"},children:[l.jsx("strong",{style:{fontSize:"0.92rem",fontFamily:"var(--font-display)"},children:W.rest_day?"😴 Rest Day":W.workout_name||`Day ${W.day_number}`}),!W.rest_day&&l.jsxs("span",{style:{fontSize:"0.72rem",color:"var(--text-3)",fontWeight:600},children:[(W.exercises||[]).length," exercises"]})]}),!W.rest_day&&(W.exercises||[]).map((Z,fe)=>l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderTop:fe===0?"1px solid var(--divider)":"none",borderBottom:fed.day_number-f.day_number);return Object.entries(c).sort(([s],[d])=>Number(s)-Number(d))}function $m(){const[o,c]=m.useState([]),[s,d]=m.useState(!0),[f,v]=m.useState(!1),[g,P]=m.useState(""),[S,T]=m.useState(null),z=m.useRef(null),y=Ge();m.useEffect(()=>{L()},[]),m.useEffect(()=>{var N;(N=z.current)==null||N.scrollIntoView({behavior:"smooth"})},[o]);async function L(){try{const N=await J.getThread();c(N.messages||[])}catch(N){console.error(N)}finally{d(!1)}}async function A(N){N.preventDefault();const j=g.trim();if(!(!j||f)){v(!0),T(null);try{const F=await J.sendSupportMessage(j);P(""),T(F.message),await L()}catch(F){T(F.message)}finally{v(!1)}}}function R(N){const j=new Date(N),_=new Date-j;return _<6e4?"Just now":_<36e5?`${Math.floor(_/6e4)}m ago`:_<864e5?`${Math.floor(_/36e5)}h ago`:j.toLocaleDateString(void 0,{month:"short",day:"numeric"})+" "+j.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"})}return s?l.jsx("div",{style:{padding:"2rem",textAlign:"center",color:"var(--text-3)"},children:"Loading..."}):l.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"calc(100dvh - 64px)",maxWidth:"600px",margin:"0 auto"},children:[l.jsxs("div",{style:{padding:"16px",borderBottom:"1px solid var(--divider)",display:"flex",alignItems:"center",gap:"12px"},children:[l.jsx("button",{onClick:()=>y("/"),style:{background:"transparent",color:"var(--text-3)",padding:"4px 0",fontSize:"1.2rem"},children:"←"}),l.jsxs("div",{children:[l.jsx("h1",{style:{fontFamily:"var(--font-display)",fontSize:"1.2rem",fontWeight:800,margin:0},children:"Support"}),l.jsx("p",{style:{color:"var(--text-3)",fontSize:"0.75rem",margin:0},children:"Ask a question — we'll get back to you"})]})]}),l.jsxs("div",{style:{flex:1,overflow:"auto",padding:"16px",display:"flex",flexDirection:"column",gap:"12px"},children:[o.length===0&&l.jsxs("div",{style:{textAlign:"center",color:"var(--text-3)",fontSize:"0.85rem",marginTop:"2rem"},children:[l.jsx("div",{style:{fontSize:"2rem",marginBottom:"8px"},children:"💬"}),"No messages yet. Ask anything about your workouts, program, or the app."]}),o.map(N=>l.jsx("div",{style:{display:"flex",justifyContent:N.sender==="user"?"flex-end":"flex-start"},children:l.jsxs("div",{style:{maxWidth:"80%",padding:"10px 14px",borderRadius:N.sender==="user"?"var(--r) var(--r) 4px var(--r)":"var(--r) var(--r) var(--r) 4px",background:N.sender==="user"?"var(--accent)":"var(--card)",color:N.sender==="user"?"#fff":"var(--text)",boxShadow:"var(--shadow-1)",fontSize:"0.88rem",lineHeight:1.5},children:[l.jsx("div",{children:N.body}),l.jsxs("div",{style:{fontSize:"0.68rem",marginTop:"4px",opacity:.7,textAlign:"right"},children:[R(N.created_at),N.sender==="user"&&N.read_at&&" ✓"]})]})},N.id)),S&&l.jsx("div",{style:{textAlign:"center",fontSize:"0.8rem",color:"var(--green-dark)",padding:"8px",background:"var(--green-bg)",borderRadius:"var(--r-sm)"},children:S}),l.jsx("div",{ref:z})]}),l.jsxs("form",{onSubmit:A,style:{padding:"12px 16px",borderTop:"1px solid var(--divider)",display:"flex",gap:"8px",background:"var(--card)"},children:[l.jsx("input",{type:"text",value:g,onChange:N=>P(N.target.value),placeholder:"Type your question...",maxLength:2e3,style:{flex:1,padding:"12px 14px",borderRadius:"var(--r-full)",border:"1px solid var(--divider)",fontFamily:"var(--font)",fontSize:"0.88rem",background:"var(--bg)"}}),l.jsx("button",{type:"submit",disabled:!g.trim()||f,style:{background:f?"var(--text-3)":"var(--accent)",color:"#fff",borderRadius:"var(--r-full)",width:"44px",height:"44px",padding:0,display:"flex",alignItems:"center",justifyContent:"center",fontSize:"1.1rem",boxShadow:"var(--shadow-accent)",opacity:g.trim()?1:.5},children:"↑"})]})]})}function Bc(){const{threadId:o}=ma();return o?l.jsx(Vm,{threadId:o}):l.jsx(Um,{})}function Um(){const[o,c]=m.useState([]),[s,d]=m.useState(!0),[f,v]=m.useState(null),g=Ge();m.useEffect(()=>{P()},[]);async function P(){try{const S=await J.listSupportThreads();c(S)}catch(S){v(S.message)}finally{d(!1)}}return s?l.jsx("div",{style:{padding:"2rem",textAlign:"center",color:"var(--text-3)"},children:"Loading..."}):f?l.jsx("div",{style:{padding:"2rem",textAlign:"center",color:"var(--red)"},children:f}):l.jsxs("div",{style:{padding:"1rem",paddingBottom:"96px",maxWidth:"600px",margin:"0 auto"},children:[l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px",marginBottom:"1.5rem"},children:[l.jsx("button",{onClick:()=>g("/"),style:{background:"transparent",color:"var(--text-3)",padding:"4px 0",fontSize:"1.2rem"},children:"←"}),l.jsx("h1",{style:{fontFamily:"var(--font-display)",fontSize:"1.4rem",fontWeight:900,margin:0},children:"Support Inbox"})]}),o.length===0&&l.jsx("p",{style:{textAlign:"center",color:"var(--text-3)",fontSize:"0.85rem",marginTop:"3rem"},children:"No support conversations yet."}),o.map(S=>l.jsxs("div",{onClick:()=>g(`/support/admin/${S.id}`),style:{background:"var(--card)",borderRadius:"var(--r)",padding:"14px 16px",marginBottom:"0.6rem",boxShadow:"var(--shadow-1)",cursor:"pointer",border:S.unread_admin>0?"2px solid var(--accent-glow)":"1px solid var(--card-border)"},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[l.jsx("strong",{style:{fontFamily:"var(--font-display)",fontSize:"0.95rem"},children:S.user_name}),l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[S.unread_admin>0&&l.jsx("span",{style:{background:"var(--accent)",color:"#fff",fontSize:"0.65rem",fontWeight:800,width:"20px",height:"20px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center"},children:S.unread_admin}),l.jsxs("span",{style:{fontSize:"0.72rem",color:"var(--text-3)"},children:[S.message_count," msgs"]})]})]}),S.last_message&&l.jsxs("p",{style:{color:"var(--text-2)",fontSize:"0.82rem",marginTop:"4px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[l.jsx("span",{style:{color:"var(--text-3)",fontWeight:600},children:S.last_message.sender==="admin"?"You: ":""}),S.last_message.body]})]},S.id))]})}function Vm({threadId:o}){const[c,s]=m.useState(null),[d,f]=m.useState(!0),[v,g]=m.useState(!1),[P,S]=m.useState(""),T=m.useRef(null),z=Ge();m.useEffect(()=>{y()},[o]),m.useEffect(()=>{var N;(N=T.current)==null||N.scrollIntoView({behavior:"smooth"})},[c]);async function y(){try{const N=await J.getAdminThread(o);s(N)}catch(N){console.error(N)}finally{f(!1)}}async function L(N){N.preventDefault();const j=P.trim();if(!(!j||v)){g(!0);try{await J.replySupportThread(o,j),S(""),await y()}catch(F){alert(F.message)}finally{g(!1)}}}function A(N){const j=new Date(N);return j.toLocaleDateString(void 0,{month:"short",day:"numeric"})+" "+j.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"})}if(d)return l.jsx("div",{style:{padding:"2rem",textAlign:"center",color:"var(--text-3)"},children:"Loading..."});if(!c)return l.jsx("div",{style:{padding:"2rem",textAlign:"center"},children:"Thread not found"});const R=c.latest_context||{};return l.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"calc(100dvh - 64px)",maxWidth:"600px",margin:"0 auto"},children:[l.jsxs("div",{style:{padding:"14px 16px",borderBottom:"1px solid var(--divider)"},children:[l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[l.jsx("button",{onClick:()=>z("/support/admin"),style:{background:"transparent",color:"var(--text-3)",padding:"4px 0",fontSize:"1.2rem"},children:"←"}),l.jsx("h2",{style:{fontFamily:"var(--font-display)",fontSize:"1.1rem",fontWeight:800,margin:0},children:c.user_name})]}),R.program_name&&l.jsxs("div",{style:{display:"flex",gap:"0.5rem",flexWrap:"wrap",marginTop:"8px",marginLeft:"36px"},children:[l.jsx("span",{style:Fr,children:R.program_name}),R.program_day&&l.jsxs("span",{style:Fr,children:["Day ",R.program_day,"/",R.program_total_days]}),R.program_completion_pct!==void 0&&l.jsxs("span",{style:Fr,children:[R.program_completion_pct,"%"]}),l.jsxs("span",{style:{...Fr,background:R.gate_passed?"var(--green-bg)":"var(--red-ghost)",color:R.gate_passed?"var(--green-dark)":"var(--red)"},children:[R.points_today,"/",R.daily_target," pts ",R.gate_passed?"✓":"✗"]}),R.last_workout&&l.jsxs("span",{style:Fr,children:["Last: ",R.last_workout]})]})]}),l.jsxs("div",{style:{flex:1,overflow:"auto",padding:"16px",display:"flex",flexDirection:"column",gap:"12px"},children:[(c.messages||[]).map(N=>l.jsx("div",{style:{display:"flex",justifyContent:N.sender==="admin"?"flex-end":"flex-start"},children:l.jsxs("div",{style:{maxWidth:"80%",padding:"10px 14px",borderRadius:N.sender==="admin"?"var(--r) var(--r) 4px var(--r)":"var(--r) var(--r) var(--r) 4px",background:N.sender==="admin"?"var(--accent)":"var(--card)",color:N.sender==="admin"?"#fff":"var(--text)",boxShadow:"var(--shadow-1)",fontSize:"0.88rem",lineHeight:1.5},children:[l.jsx("div",{children:N.body}),l.jsxs("div",{style:{fontSize:"0.68rem",marginTop:"4px",opacity:.7,textAlign:"right"},children:[A(N.created_at),N.read_at&&" ✓"]})]})},N.id)),l.jsx("div",{ref:T})]}),l.jsxs("form",{onSubmit:L,style:{padding:"12px 16px",borderTop:"1px solid var(--divider)",display:"flex",gap:"8px",background:"var(--card)"},children:[l.jsx("input",{type:"text",value:P,onChange:N=>S(N.target.value),placeholder:"Reply...",style:{flex:1,padding:"12px 14px",borderRadius:"var(--r-full)",border:"1px solid var(--divider)",fontFamily:"var(--font)",fontSize:"0.88rem",background:"var(--bg)"}}),l.jsx("button",{type:"submit",disabled:!P.trim()||v,style:{background:v?"var(--text-3)":"var(--accent)",color:"#fff",borderRadius:"var(--r-full)",width:"44px",height:"44px",padding:0,display:"flex",alignItems:"center",justifyContent:"center",fontSize:"1.1rem",opacity:P.trim()?1:.5},children:"↑"})]})]})}const Fr={fontSize:"0.68rem",fontWeight:600,padding:"2px 8px",borderRadius:"var(--r-full)",background:"var(--divider)",color:"var(--text-2)"};function Hm(){const[o,c]=m.useState([]),[s,d]=m.useState(""),[f,v]=m.useState(!1),[g,P]=m.useState(null),S=m.useRef(null);m.useEffect(()=>{J.getAIStatus().then(P).catch(()=>P({configured:!1}))},[]),m.useEffect(()=>{var y;(y=S.current)==null||y.scrollIntoView({behavior:"smooth"})},[o]);const T=async()=>{const y=s.trim();if(!y||f)return;const L={role:"user",content:y};c(A=>[...A,L]),d(""),v(!0),c(A=>[...A,{role:"assistant",content:""}]);try{const A=o.map(B=>({role:B.role,content:B.content})),R=localStorage.getItem("fitness_token"),j=(await fetch("/api/ai/chat",{method:"POST",headers:{"Content-Type":"application/json",...R?{Authorization:`Bearer ${R}`}:{}},body:JSON.stringify({message:y,history:A})})).body.getReader(),F=new TextDecoder;let _="";for(;;){const{done:B,value:W}=await j.read();if(B)break;_+=F.decode(W,{stream:!0});const Z=_.split(` +`);_=Z.pop()||"";for(const fe of Z)if(fe.startsWith("data: ")&&fe.trim()!=="data: [DONE]")try{const{text:we}=JSON.parse(fe.slice(6));we&&c(xe=>{const re=[...xe],oe=re[re.length-1];return re[re.length-1]={...oe,content:oe.content+we},re})}catch{}}}catch{c(R=>{const N=[...R];return N[N.length-1]={role:"assistant",content:"Connection error. Check that the backend is running and an AI provider is configured in Settings → Integrations."},N})}v(!1)},z=["What should I eat today?","Log my 30-minute run","How am I doing this week?","Create a meal plan for me"];return g&&!g.configured?l.jsxs("div",{className:"page",children:[l.jsx("h1",{className:"page-title",children:"AI Coach"}),l.jsxs("div",{className:"card",style:{textAlign:"center",padding:"32px 20px"},children:[l.jsx("div",{style:{fontSize:"2rem",marginBottom:"12px"},children:"🤖"}),l.jsx("h3",{style:{marginBottom:"8px"},children:"No AI provider connected"}),l.jsx("p",{style:{color:"var(--text-2)",fontSize:"0.9rem",marginBottom:"16px"},children:"Connect OpenAI, OpenRouter, Claude, Ollama, or any other provider to start chatting with your AI fitness coach."}),l.jsx("a",{href:"/settings/integrations",className:"btn-primary",style:{display:"inline-block",padding:"12px 24px",borderRadius:"var(--r)",background:"var(--accent)",color:"var(--text-inv)",textDecoration:"none",fontWeight:600,fontSize:"0.88rem"},children:"Configure AI Provider"})]})]}):l.jsxs("div",{className:"page",style:{display:"flex",flexDirection:"column",paddingBottom:"96px"},children:[l.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"12px"},children:[l.jsx("h1",{className:"page-title",style:{marginBottom:0},children:"AI Coach"}),(g==null?void 0:g.provider)&&l.jsxs("span",{style:{fontFamily:"var(--font-mono)",fontSize:"0.7rem",color:"var(--text-3)",background:"var(--accent-bg)",padding:"4px 10px",borderRadius:"var(--r-full)"},children:[g.provider," · ",g.model]})]}),l.jsxs("div",{style:{flex:1,overflowY:"auto",marginBottom:"12px"},children:[o.length===0&&l.jsxs("div",{style:{textAlign:"center",padding:"24px 0"},children:[l.jsx("p",{style:{color:"var(--text-3)",fontSize:"0.9rem",marginBottom:"16px"},children:"Ask me anything about your fitness, nutrition, or program."}),l.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",justifyContent:"center"},children:z.map(y=>l.jsx("button",{className:"btn-outline btn-sm",onClick:()=>{d(y)},style:{fontSize:"0.8rem"},children:y},y))})]}),o.map((y,L)=>l.jsx("div",{style:{display:"flex",justifyContent:y.role==="user"?"flex-end":"flex-start",marginBottom:"10px"},children:l.jsx("div",{style:{maxWidth:"85%",padding:"10px 14px",borderRadius:y.role==="user"?"var(--r-lg) var(--r-lg) var(--r-sm) var(--r-lg)":"var(--r-lg) var(--r-lg) var(--r-lg) var(--r-sm)",background:y.role==="user"?"var(--accent)":"var(--card)",color:y.role==="user"?"var(--text-inv)":"var(--text)",border:y.role==="user"?"none":"1px solid var(--card-border)",fontSize:"0.9rem",lineHeight:"1.5",whiteSpace:"pre-wrap"},children:y.content||(f&&L===o.length-1?"...":"")})},L)),l.jsx("div",{ref:S})]}),l.jsxs("div",{style:{display:"flex",gap:"8px",position:"sticky",bottom:"72px",background:"var(--bg)",padding:"8px 0"},children:[l.jsx("input",{value:s,onChange:y=>d(y.target.value),onKeyDown:y=>y.key==="Enter"&&!y.shiftKey&&T(),placeholder:f?"Thinking...":"Ask your AI coach...",disabled:f,style:{flex:1}}),l.jsx("button",{onClick:T,disabled:f||!s.trim(),className:"btn-primary",style:{padding:"12px 18px",minWidth:"auto"},children:f?"···":"→"})]})]})}function ua({text:o,label:c}){const[s,d]=m.useState(!1),f=async()=>{try{await navigator.clipboard.writeText(o),d(!0),setTimeout(()=>d(!1),2e3)}catch{}};return l.jsx("button",{onClick:f,className:"btn-outline btn-sm",style:{fontSize:"0.75rem",padding:"6px 12px",whiteSpace:"nowrap"},children:s?"Copied":c||"Copy"})}function Wc({children:o,copyText:c}){return l.jsxs("div",{style:{background:"var(--bg)",border:"1px solid var(--divider)",borderRadius:"var(--r-sm)",padding:"14px 16px",fontFamily:"var(--font-mono)",fontSize:"0.78rem",lineHeight:1.6,overflowX:"auto",position:"relative",whiteSpace:"pre"},children:[c&&l.jsx("div",{style:{position:"absolute",top:"8px",right:"8px"},children:l.jsx(ua,{text:c})}),o]})}function Qm(){const[o,c]=m.useState(null),[s,d]=m.useState(!0),[f,v]=m.useState(!1);if(m.useEffect(()=>{J.agentConfig().then(c).catch(console.error).finally(()=>d(!1))},[]),s)return l.jsx("div",{className:"page",children:l.jsx("div",{className:"loading",children:"Loading..."})});if(!o)return l.jsx("div",{className:"page",children:l.jsx("div",{className:"error-msg",children:"Failed to load agent config"})});const g=o.api_token?o.api_token.slice(0,8)+"…"+o.api_token.slice(-4):null,P=JSON.stringify({mcpServers:{diligence:{url:o.mcp_url,...o.api_token?{headers:{Authorization:`Bearer ${o.api_token}`}}:{}}}},null,2);return l.jsxs("div",{className:"page",children:[l.jsxs("div",{style:{marginBottom:"20px"},children:[l.jsx("h1",{style:{fontFamily:"var(--font-display)",fontWeight:800,fontSize:"1.3rem",marginBottom:"4px"},children:"Connect Your AI Agent"}),l.jsx("p",{style:{color:"var(--text-3)",fontSize:"0.85rem"},children:"Use any MCP-compatible AI to log workouts, track food, and manage your fitness."})]}),l.jsxs("div",{className:"card",children:[l.jsx("div",{className:"section-label",children:"Connection"}),l.jsxs("div",{style:{marginBottom:"14px"},children:[l.jsx("div",{style:{fontSize:"0.75rem",color:"var(--text-3)",fontWeight:600,marginBottom:"4px"},children:"MCP Endpoint"}),l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",background:"var(--bg)",borderRadius:"var(--r-sm)",padding:"10px 12px",border:"1px solid var(--divider)"},children:[l.jsx("code",{style:{flex:1,fontFamily:"var(--font-mono)",fontSize:"0.82rem",color:"var(--accent)",wordBreak:"break-all"},children:o.mcp_url}),l.jsx(ua,{text:o.mcp_url})]})]}),o.api_token&&l.jsxs("div",{style:{marginBottom:"14px"},children:[l.jsx("div",{style:{fontSize:"0.75rem",color:"var(--text-3)",fontWeight:600,marginBottom:"4px"},children:"API Token"}),l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",background:"var(--bg)",borderRadius:"var(--r-sm)",padding:"10px 12px",border:"1px solid var(--divider)"},children:[l.jsx("code",{onClick:()=>v(!f),style:{flex:1,fontFamily:"var(--font-mono)",fontSize:"0.82rem",cursor:"pointer",wordBreak:"break-all"},children:f?o.api_token:g}),l.jsx(ua,{text:o.api_token})]}),l.jsx("div",{style:{fontSize:"0.7rem",color:"var(--text-3)",marginTop:"4px"},children:"Tap token to reveal. Only visible to admins."})]}),!o.api_token&&o.api_token_set&&l.jsx("div",{style:{fontSize:"0.8rem",color:"var(--text-3)",fontStyle:"italic",padding:"8px 0"},children:"API token is set but only visible to admin users."}),l.jsxs("div",{style:{display:"flex",gap:"12px",flexWrap:"wrap",fontSize:"0.78rem",color:"var(--text-3)"},children:[l.jsxs("span",{children:[o.tools_count," tools available"]}),l.jsx("span",{style:{color:"var(--divider)"},children:"|"}),l.jsx("span",{children:o.deployment==="local"?"Local (SQLite)":"Docker (PostgreSQL)"})]})]}),l.jsxs("div",{className:"card",children:[l.jsx("div",{className:"section-label",children:"Claude Desktop"}),l.jsx("p",{style:{fontSize:"0.82rem",color:"var(--text-2)",marginBottom:"12px"},children:"Add this to your Claude Desktop MCP config:"}),l.jsx(Wc,{copyText:P,children:P}),l.jsxs("p",{style:{fontSize:"0.75rem",color:"var(--text-3)",marginTop:"10px"},children:["On macOS: ",l.jsx("code",{style:{fontFamily:"var(--font-mono)",fontSize:"0.72rem"},children:"~/Library/Application Support/Claude/claude_desktop_config.json"})]})]}),l.jsxs("div",{className:"card",children:[l.jsx("div",{className:"section-label",children:"Claude Code"}),l.jsx("p",{style:{fontSize:"0.82rem",color:"var(--text-2)",marginBottom:"12px"},children:"Add the MCP server from your terminal:"}),l.jsx(Wc,{copyText:`claude mcp add diligence --transport sse ${o.mcp_url}`,children:`claude mcp add diligence --transport sse ${o.mcp_url}`})]}),l.jsxs("div",{className:"card",children:[l.jsx("div",{className:"section-label",children:"What Your Agent Can Do"}),l.jsx("div",{style:{display:"grid",gap:"8px"},children:[["Log workouts","Track any activity and earn points automatically"],["Track food","Search 400K+ foods, log meals with full macros"],["Manage meal plans","Create plans, track compliance, adjust portions"],["Check progress","Daily points, weekly summary, program status"],["Redeem rewards","Spend earned points on rewards you set up"]].map(([S,T])=>l.jsxs("div",{style:{display:"flex",gap:"10px",alignItems:"flex-start",padding:"8px 0",borderBottom:"1px solid var(--divider)"},children:[l.jsx("span",{style:{color:"var(--green)",fontSize:"0.9rem",marginTop:"1px"},children:"✓"}),l.jsxs("div",{children:[l.jsx("div",{style:{fontWeight:700,fontSize:"0.85rem"},children:S}),l.jsx("div",{style:{fontSize:"0.78rem",color:"var(--text-3)"},children:T})]})]},S))})]})]})}function Ue({children:o}){return ti()?o:l.jsx(Yp,{to:"/login"})}function Km(){const[o,c]=m.useState(0),s=Ge(),d=xn(),f=["/login","/onboarding","/support"].some(v=>d.pathname.startsWith(v));return m.useEffect(()=>{if(f||!ti())return;J.getUnreadCount().then(g=>c(g.unread||0)).catch(()=>{});const v=setInterval(()=>{J.getUnreadCount().then(g=>c(g.unread||0)).catch(()=>{})},6e4);return()=>clearInterval(v)},[d.pathname,f]),f?null:l.jsxs("button",{onClick:()=>s("/support"),style:{position:"fixed",top:"12px",right:"12px",zIndex:90,width:"40px",height:"40px",borderRadius:"50%",background:"var(--card)",boxShadow:"var(--shadow-2)",border:"1px solid var(--divider)",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"1.1rem",padding:0,cursor:"pointer"},children:["?",o>0&&l.jsx("span",{style:{position:"absolute",top:"-4px",right:"-4px",background:"var(--red)",color:"#fff",fontSize:"0.6rem",fontWeight:800,width:"18px",height:"18px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",border:"2px solid var(--bg)"},children:o})]})}function Jm(){return l.jsxs("nav",{className:"nav-bar",children:[l.jsxs(Hn,{to:"/",className:({isActive:o})=>`nav-item ${o?"active":""}`,children:[l.jsx("span",{className:"nav-icon",children:"🏠"})," Home"]}),l.jsxs(Hn,{to:"/log",className:({isActive:o})=>`nav-item ${o?"active":""}`,children:[l.jsx("span",{className:"nav-icon",children:"💪"})," Log"]}),l.jsxs(Hn,{to:"/nutrition",className:({isActive:o})=>`nav-item ${o?"active":""}`,children:[l.jsx("span",{className:"nav-icon",children:"🥑"})," Keto"]}),l.jsxs(Hn,{to:"/programs",className:({isActive:o})=>`nav-item ${o?"active":""}`,children:[l.jsx("span",{className:"nav-icon",children:"📋"})," Programs"]}),l.jsxs(Hn,{to:"/chat",className:({isActive:o})=>`nav-item ${o?"active":""}`,children:[l.jsx("span",{className:"nav-icon",children:"🧠"})," Coach"]}),l.jsxs(Hn,{to:"/agent",className:({isActive:o})=>`nav-item ${o?"active":""}`,children:[l.jsx("span",{className:"nav-icon",children:"🔌"})," Agent"]})]})}function Ym(){return l.jsxs(l.Fragment,{children:[ti()&&l.jsx(Km,{}),l.jsxs(Xp,{children:[l.jsx(Ie,{path:"/login",element:l.jsx(hm,{})}),l.jsx(Ie,{path:"/onboarding",element:l.jsx(Ue,{children:l.jsx(Pm,{})})}),l.jsx(Ie,{path:"/",element:l.jsx(Ue,{children:l.jsx(gm,{})})}),l.jsx(Ie,{path:"/log",element:l.jsx(Ue,{children:l.jsx(vm,{})})}),l.jsx(Ie,{path:"/food",element:l.jsx(Ue,{children:l.jsx(ym,{})})}),l.jsx(Ie,{path:"/nutrition",element:l.jsx(Ue,{children:l.jsx(Sm,{})})}),l.jsx(Ie,{path:"/programs",element:l.jsx(Ue,{children:l.jsx(Bm,{})})}),l.jsx(Ie,{path:"/programs/:id",element:l.jsx(Ue,{children:l.jsx(Wm,{})})}),l.jsx(Ie,{path:"/catalog/:id",element:l.jsx(Ue,{children:l.jsx(Dm,{})})}),l.jsx(Ie,{path:"/rewards",element:l.jsx(Ue,{children:l.jsx(wm,{})})}),l.jsx(Ie,{path:"/week",element:l.jsx(Ue,{children:l.jsx(zm,{})})}),l.jsx(Ie,{path:"/settings",element:l.jsx(Ue,{children:l.jsx(jm,{})})}),l.jsx(Ie,{path:"/support",element:l.jsx(Ue,{children:l.jsx($m,{})})}),l.jsx(Ie,{path:"/support/admin",element:l.jsx(Ue,{children:l.jsx(Bc,{})})}),l.jsx(Ie,{path:"/support/admin/:threadId",element:l.jsx(Ue,{children:l.jsx(Bc,{})})}),l.jsx(Ie,{path:"/welcome",element:l.jsx(Tm,{})}),l.jsx(Ie,{path:"/settings/integrations",element:l.jsx(Ue,{children:l.jsx(Rm,{})})}),l.jsx(Ie,{path:"/meal-plan",element:l.jsx(Ue,{children:l.jsx(Im,{})})}),l.jsx(Ie,{path:"/chat",element:l.jsx(Ue,{children:l.jsx(Hm,{})})}),l.jsx(Ie,{path:"/agent",element:l.jsx(Ue,{children:l.jsx(Qm,{})})})]}),ti()&&l.jsx(Jm,{})]})}op.createRoot(document.getElementById("root")).render(l.jsx(Mc.StrictMode,{children:l.jsx(im,{children:l.jsx(Ym,{})})})); diff --git a/diligence/frontend/assets/index-CRHpiAro.css b/diligence/frontend/assets/index-ciTnvXdZ.css similarity index 99% rename from diligence/frontend/assets/index-CRHpiAro.css rename to diligence/frontend/assets/index-ciTnvXdZ.css index 4bf3276..8afd293 100644 --- a/diligence/frontend/assets/index-CRHpiAro.css +++ b/diligence/frontend/assets/index-ciTnvXdZ.css @@ -1 +1 @@ -@import"https://fonts.googleapis.com/css2?family=Instrument+Sans:ital,wght@0,400;0,500;0,600;0,700;1,400&family=IBM+Plex+Mono:wght@400;500;600&display=swap";:root{--accent: #2952CC;--accent-dark: #1e3fa8;--accent-light: #4A78E0;--accent-bg: #edf1fc;--accent-glow: rgba(41, 82, 204, .18);--green: #0d7d5a;--green-dark: #065c40;--green-light: #30C090;--green-bg: rgba(13, 125, 90, .08);--red: #C62828;--red-bg: rgba(198, 40, 40, .06);--amber: #b07800;--amber-bg: rgba(176, 120, 0, .08);--text: #1a1f2e;--text-2: #3d4660;--text-3: #6b7490;--text-inv: #FFFFFF;--bg: #fafbfe;--bg-warm: linear-gradient(170deg, #f0f2fa 0%, #fafbfe 50%, #f5f7fd 100%);--card: #FFFFFF;--card-border: rgba(216, 220, 232, .6);--divider: rgba(216, 220, 232, .8);--shadow-1: 0 1px 3px rgba(26, 31, 46, .06);--shadow-2: 0 4px 16px rgba(26, 31, 46, .08);--shadow-3: 0 12px 40px rgba(26, 31, 46, .12);--shadow-accent: 0 4px 20px rgba(41, 82, 204, .2);--shadow-green: 0 4px 20px rgba(13, 125, 90, .2);--r: 8px;--r-sm: 6px;--r-lg: 12px;--r-full: 999px;--font: "Instrument Sans", -apple-system, sans-serif;--font-display: "Instrument Sans", -apple-system, sans-serif;--font-mono: "IBM Plex Mono", monospace}*,*:before,*:after{margin:0;padding:0;box-sizing:border-box}body{font-family:var(--font);background:var(--bg);color:var(--text);min-height:100dvh;-webkit-font-smoothing:antialiased;font-size:15px;line-height:1.5}h1,h2,h3{font-family:var(--font-display);letter-spacing:-.02em;line-height:1.2}a{color:var(--accent);text-decoration:none;font-weight:600}a:hover{opacity:.8}button{font-family:var(--font);cursor:pointer;border:none;border-radius:var(--r);padding:12px 24px;font-size:.88rem;font-weight:700;letter-spacing:.01em;transition:all .2s cubic-bezier(.4,0,.2,1);-webkit-tap-highlight-color:transparent}button:active{transform:scale(.97)}.btn-primary{background:var(--accent);color:var(--text-inv);box-shadow:var(--shadow-accent)}.btn-primary:hover{background:var(--accent-dark)}.btn-primary:disabled{opacity:.4;cursor:not-allowed;transform:none;box-shadow:none}.btn-success{background:var(--green);color:var(--text-inv);box-shadow:var(--shadow-green)}.btn-outline{background:var(--card);border:2px solid var(--divider);color:var(--text)}.btn-outline:hover{border-color:var(--accent);color:var(--accent)}.btn-ghost{background:transparent;color:var(--text-2);padding:10px 16px}.btn-ghost:hover{background:var(--accent-bg);color:var(--accent)}.btn-danger{background:var(--red);color:var(--text-inv)}.btn-sm{padding:8px 16px;font-size:.82rem;border-radius:var(--r-sm)}.btn-full{width:100%}input,select,textarea{font-family:var(--font);background:var(--card);color:var(--text);border:2px solid var(--divider);border-radius:var(--r);padding:12px 16px;font-size:.88rem;font-weight:500;width:100%;outline:none;transition:border-color .2s}input:focus,select:focus,textarea:focus{border-color:var(--accent);box-shadow:0 0 0 3px var(--accent-glow)}input::placeholder,textarea::placeholder{color:var(--text-3);font-weight:400}.card{background:var(--card);border:1px solid var(--card-border);border-radius:var(--r-lg);padding:20px;margin-bottom:14px;box-shadow:var(--shadow-1)}.page{max-width:440px;margin:0 auto;padding:16px 16px 96px;min-height:100dvh;background:var(--bg-warm)}.page-title{font-family:var(--font-display);font-size:1.5rem;font-weight:600;margin-bottom:18px}.progress-bar{width:100%;height:10px;background:#0000000d;border-radius:var(--r-full);overflow:hidden}.progress-bar-fill{height:100%;border-radius:var(--r-full);transition:width .6s cubic-bezier(.4,0,.2,1)}.status-earned{color:var(--green)}.status-locked{color:var(--red)}.section-label{font-family:var(--font-mono);font-size:.72rem;font-weight:700;text-transform:uppercase;letter-spacing:.08em;color:var(--text-3);margin-bottom:10px}.checklist-item{display:flex;align-items:center;gap:12px;padding:11px 0;border-bottom:1px solid var(--divider);font-size:.9rem;font-weight:500}.checklist-item:last-child{border-bottom:none}.checklist-check{font-size:1.15rem;min-width:26px}.checklist-points{margin-left:auto;font-family:var(--font-mono);font-size:.78rem;font-weight:700;color:var(--text-3);background:#0000000a;padding:3px 10px;border-radius:var(--r-full)}.nav-bar{position:fixed;bottom:0;left:0;right:0;background:#ffffffeb;backdrop-filter:blur(16px);-webkit-backdrop-filter:blur(16px);border-top:1px solid var(--divider);display:flex;justify-content:space-around;padding:4px 0 env(safe-area-inset-bottom,6px);z-index:100}.nav-item{display:flex;flex-direction:column;align-items:center;gap:1px;color:var(--text-3);font-size:.62rem;font-weight:700;letter-spacing:.03em;padding:6px 14px;text-decoration:none;transition:color .15s;border-radius:var(--r-sm);position:relative}.nav-item.active{color:var(--accent)}.nav-item.active:before{content:"";position:absolute;top:-4px;left:50%;transform:translate(-50%);width:20px;height:3px;background:var(--accent);border-radius:2px}.nav-icon{font-size:1.2rem;margin-bottom:1px}.form-group{margin-bottom:16px}.form-label{display:block;font-size:.78rem;font-weight:700;color:var(--text-2);margin-bottom:6px;letter-spacing:.02em}.option-grid{display:grid;grid-template-columns:1fr 1fr;gap:10px}.option-btn{background:var(--card);border:2px solid var(--divider);border-radius:var(--r-lg);padding:18px 12px;text-align:center;color:var(--text);font-size:.88rem;font-weight:600;cursor:pointer;transition:all .2s;box-shadow:var(--shadow-1)}.option-btn:hover{border-color:var(--accent-light);transform:translateY(-2px);box-shadow:var(--shadow-2)}.option-btn.selected{border-color:var(--accent);background:var(--accent-bg);box-shadow:0 0 0 3px var(--accent-glow)}.chip-grid{display:flex;flex-wrap:wrap;gap:8px}.chip{background:var(--card);border:2px solid var(--divider);border-radius:var(--r-full);padding:8px 18px;font-size:.84rem;font-weight:600;cursor:pointer;transition:all .2s}.chip:hover{border-color:var(--accent-light)}.chip.selected{border-color:var(--accent);background:var(--accent);color:var(--text-inv)}.reward-card{display:flex;align-items:center;justify-content:space-between;padding:14px 0;border-bottom:1px solid var(--divider)}.reward-card:last-child{border-bottom:none}.likert-row{display:flex;align-items:center;gap:10px;margin:8px 0 18px;justify-content:center}.likert-btn{width:44px;height:44px;border-radius:50%;background:var(--card);border:2px solid var(--divider);color:var(--text);font-weight:600;font-size:.88rem;display:flex;align-items:center;justify-content:center;cursor:pointer;transition:all .2s;box-shadow:var(--shadow-1)}.likert-btn:hover{border-color:var(--accent);transform:scale(1.1)}.likert-btn.selected{border-color:transparent;background:var(--accent);color:var(--text-inv);box-shadow:var(--shadow-accent);transform:scale(1.1)}.likert-labels{display:flex;justify-content:space-between;font-size:.68rem;color:var(--text-3);font-weight:700;text-transform:uppercase;letter-spacing:.06em}.gate-banner{text-align:center;padding:28px 20px;border-radius:var(--r-lg);margin-bottom:14px;position:relative}.gate-earned{background:linear-gradient(135deg,#e8f5e9,#c8e6c9,#e0f2f1);border:2px solid rgba(0,200,83,.2)}.gate-locked{background:linear-gradient(135deg,#fff3e0,#ffe0b2,#fff8e1);border:2px solid rgba(255,87,34,.15)}.gate-pts{font-family:var(--font-mono);font-size:2.8rem;font-weight:700;letter-spacing:-.04em;line-height:1;margin:8px 0}.meal-section{margin-bottom:18px}.meal-title{font-size:.72rem;font-weight:600;text-transform:uppercase;letter-spacing:.06em;color:var(--text-3);margin-bottom:6px;padding-bottom:6px;border-bottom:2px solid var(--divider)}.loading{display:flex;justify-content:center;padding:60px;color:var(--text-3);font-weight:600}.error-msg{background:var(--red-ghost);border:2px solid rgba(255,23,68,.15);padding:12px 16px;border-radius:var(--r);color:var(--red);font-weight:600;font-size:.88rem;margin-bottom:14px}@keyframes fadeUp{0%{opacity:0;transform:translateY(16px)}to{opacity:1;transform:translateY(0)}}@keyframes popIn{0%{opacity:0;transform:scale(.92)}to{opacity:1;transform:scale(1)}}@keyframes countUp{0%{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}.page>.card:nth-child(1){animation:fadeUp .3s ease-out both}.page>.card:nth-child(2){animation:fadeUp .3s ease-out .06s both}.page>.card:nth-child(3){animation:fadeUp .3s ease-out .12s both}.page>.card:nth-child(4){animation:fadeUp .3s ease-out .18s both}.gate-banner{animation:popIn .35s cubic-bezier(.4,0,.2,1) both}.gate-pts{animation:countUp .4s ease-out .15s both}@media(prefers-color-scheme:dark){:root{--accent: #6B9BFF;--accent-dark: #4A78E0;--accent-light: #8BB5FF;--accent-bg: #101630;--accent-glow: rgba(107, 155, 255, .18);--green: #30C090;--green-dark: #20A070;--green-light: #50D8A8;--green-bg: rgba(48, 192, 144, .1);--red: #EF5350;--red-bg: rgba(239, 83, 80, .1);--amber: #F0B040;--amber-bg: rgba(240, 176, 64, .1);--text: #eaecf4;--text-2: #b0b8d0;--text-3: #7882a0;--text-inv: #0a0b12;--bg: #0a0b12;--bg-warm: linear-gradient(170deg, #0e1020 0%, #0a0b12 50%, #0c0e1a 100%);--card: #12131d;--card-border: rgba(34, 40, 64, .8);--divider: rgba(34, 40, 64, .8);--shadow-1: 0 1px 3px rgba(0, 0, 0, .3);--shadow-2: 0 4px 16px rgba(0, 0, 0, .4);--shadow-3: 0 12px 40px rgba(0, 0, 0, .5);--shadow-accent: 0 4px 20px rgba(107, 155, 255, .15);--shadow-green: 0 4px 20px rgba(48, 192, 144, .15)}body{background:var(--bg);color:var(--text)}.nav-bar{background:#0a0b12eb}input,select,textarea{background:var(--bg);color:var(--text)}.gate-earned{background:linear-gradient(135deg,#30c0901f,#30c0900f);border-color:#30c09040}.gate-locked{background:linear-gradient(135deg,#6b9bff1a,#6b9bff0d);border-color:#6b9bff26}.option-btn,.chip,.likert-btn{background:var(--card)}}:root[data-theme=dark]{--accent: #6B9BFF;--accent-dark: #4A78E0;--accent-light: #8BB5FF;--accent-bg: #101630;--accent-glow: rgba(107, 155, 255, .18);--green: #30C090;--green-dark: #20A070;--green-light: #50D8A8;--green-bg: rgba(48, 192, 144, .1);--red: #EF5350;--red-bg: rgba(239, 83, 80, .1);--amber: #F0B040;--amber-bg: rgba(240, 176, 64, .1);--text: #eaecf4;--text-2: #b0b8d0;--text-3: #7882a0;--text-inv: #0a0b12;--bg: #0a0b12;--bg-warm: linear-gradient(170deg, #0e1020 0%, #0a0b12 50%, #0c0e1a 100%);--card: #12131d;--card-border: rgba(34, 40, 64, .8);--divider: rgba(34, 40, 64, .8);--shadow-1: 0 1px 3px rgba(0, 0, 0, .3);--shadow-2: 0 4px 16px rgba(0, 0, 0, .4);--shadow-3: 0 12px 40px rgba(0, 0, 0, .5);--shadow-accent: 0 4px 20px rgba(107, 155, 255, .15);--shadow-green: 0 4px 20px rgba(48, 192, 144, .15)}::-webkit-scrollbar{width:4px}::-webkit-scrollbar-track{background:transparent}::-webkit-scrollbar-thumb{background:var(--divider);border-radius:4px}@media(max-width:380px){.page{padding:12px 10px 96px}.gate-pts{font-size:2.2rem}.option-grid{gap:8px}.option-btn{padding:14px 10px}} +@import"https://fonts.googleapis.com/css2?family=Instrument+Sans:ital,wght@0,400;0,500;0,600;0,700;1,400&family=IBM+Plex+Mono:wght@400;500;600&display=swap";:root{--accent: #2952CC;--accent-dark: #1e3fa8;--accent-light: #4A78E0;--accent-bg: #edf1fc;--accent-glow: rgba(41, 82, 204, .18);--green: #0d7d5a;--green-dark: #065c40;--green-light: #30C090;--green-bg: rgba(13, 125, 90, .08);--red: #C62828;--red-bg: rgba(198, 40, 40, .06);--amber: #b07800;--amber-bg: rgba(176, 120, 0, .08);--text: #1a1f2e;--text-2: #3d4660;--text-3: #6b7490;--text-inv: #FFFFFF;--bg: #fafbfe;--bg-warm: linear-gradient(170deg, #f0f2fa 0%, #fafbfe 50%, #f5f7fd 100%);--card: #FFFFFF;--card-border: rgba(216, 220, 232, .6);--divider: rgba(216, 220, 232, .8);--shadow-1: 0 1px 3px rgba(26, 31, 46, .06);--shadow-2: 0 4px 16px rgba(26, 31, 46, .08);--shadow-3: 0 12px 40px rgba(26, 31, 46, .12);--shadow-accent: 0 4px 20px rgba(41, 82, 204, .2);--shadow-green: 0 4px 20px rgba(13, 125, 90, .2);--r: 8px;--r-sm: 6px;--r-lg: 12px;--r-full: 999px;--font: "Instrument Sans", -apple-system, sans-serif;--font-display: "Instrument Sans", -apple-system, sans-serif;--font-mono: "IBM Plex Mono", monospace}*,*:before,*:after{margin:0;padding:0;box-sizing:border-box}body{font-family:var(--font);background:var(--bg);color:var(--text);min-height:100dvh;-webkit-font-smoothing:antialiased;font-size:15px;line-height:1.5}h1,h2,h3{font-family:var(--font-display);letter-spacing:-.02em;line-height:1.2}a{color:var(--accent);text-decoration:none;font-weight:600}a:hover{opacity:.8}button{font-family:var(--font);cursor:pointer;border:none;border-radius:var(--r);padding:12px 24px;font-size:.88rem;font-weight:700;letter-spacing:.01em;transition:all .2s cubic-bezier(.4,0,.2,1);-webkit-tap-highlight-color:transparent}button:active{transform:scale(.97)}.btn-primary{background:var(--accent);color:var(--text-inv);box-shadow:var(--shadow-accent)}.btn-primary:hover{background:var(--accent-dark)}.btn-primary:disabled{opacity:.4;cursor:not-allowed;transform:none;box-shadow:none}.btn-success{background:var(--green);color:var(--text-inv);box-shadow:var(--shadow-green)}.btn-outline{background:var(--card);border:2px solid var(--divider);color:var(--text)}.btn-outline:hover{border-color:var(--accent);color:var(--accent)}.btn-ghost{background:transparent;color:var(--text-2);padding:10px 16px}.btn-ghost:hover{background:var(--accent-bg);color:var(--accent)}.btn-danger{background:var(--red);color:var(--text-inv)}.btn-sm{padding:8px 16px;font-size:.82rem;border-radius:var(--r-sm)}.btn-full{width:100%}input,select,textarea{font-family:var(--font);background:var(--card);color:var(--text);border:2px solid var(--divider);border-radius:var(--r);padding:12px 16px;font-size:.88rem;font-weight:500;width:100%;outline:none;transition:border-color .2s}input:focus,select:focus,textarea:focus{border-color:var(--accent);box-shadow:0 0 0 3px var(--accent-glow)}input::placeholder,textarea::placeholder{color:var(--text-3);font-weight:400}.card{background:var(--card);border:1px solid var(--card-border);border-radius:var(--r-lg);padding:20px;margin-bottom:14px;box-shadow:var(--shadow-1)}.page{max-width:440px;margin:0 auto;padding:16px 16px 96px;min-height:100dvh;background:var(--bg-warm)}.page-title{font-family:var(--font-display);font-size:1.5rem;font-weight:600;margin-bottom:18px}.progress-bar{width:100%;height:10px;background:#0000000d;border-radius:var(--r-full);overflow:hidden}.progress-bar-fill{height:100%;border-radius:var(--r-full);transition:width .6s cubic-bezier(.4,0,.2,1)}.status-earned{color:var(--green)}.status-locked{color:var(--red)}.section-label{font-family:var(--font-mono);font-size:.72rem;font-weight:700;text-transform:uppercase;letter-spacing:.08em;color:var(--text-3);margin-bottom:10px}.checklist-item{display:flex;align-items:center;gap:12px;padding:11px 0;border-bottom:1px solid var(--divider);font-size:.9rem;font-weight:500}.checklist-item:last-child{border-bottom:none}.checklist-check{font-size:1.15rem;min-width:26px}.checklist-points{margin-left:auto;font-family:var(--font-mono);font-size:.78rem;font-weight:700;color:var(--text-3);background:#0000000a;padding:3px 10px;border-radius:var(--r-full)}.nav-bar{position:fixed;bottom:0;left:0;right:0;background:#ffffffeb;backdrop-filter:blur(16px);-webkit-backdrop-filter:blur(16px);border-top:1px solid var(--divider);display:flex;justify-content:space-around;padding:4px 0 env(safe-area-inset-bottom,6px);z-index:100}.nav-item{display:flex;flex-direction:column;align-items:center;gap:1px;color:var(--text-3);font-size:.62rem;font-weight:700;letter-spacing:.03em;padding:6px 10px;text-decoration:none;transition:color .15s;border-radius:var(--r-sm);position:relative}.nav-item.active{color:var(--accent)}.nav-item.active:before{content:"";position:absolute;top:-4px;left:50%;transform:translate(-50%);width:20px;height:3px;background:var(--accent);border-radius:2px}.nav-icon{font-size:1.2rem;margin-bottom:1px}.form-group{margin-bottom:16px}.form-label{display:block;font-size:.78rem;font-weight:700;color:var(--text-2);margin-bottom:6px;letter-spacing:.02em}.option-grid{display:grid;grid-template-columns:1fr 1fr;gap:10px}.option-btn{background:var(--card);border:2px solid var(--divider);border-radius:var(--r-lg);padding:18px 12px;text-align:center;color:var(--text);font-size:.88rem;font-weight:600;cursor:pointer;transition:all .2s;box-shadow:var(--shadow-1)}.option-btn:hover{border-color:var(--accent-light);transform:translateY(-2px);box-shadow:var(--shadow-2)}.option-btn.selected{border-color:var(--accent);background:var(--accent-bg);box-shadow:0 0 0 3px var(--accent-glow)}.chip-grid{display:flex;flex-wrap:wrap;gap:8px}.chip{background:var(--card);border:2px solid var(--divider);border-radius:var(--r-full);padding:8px 18px;font-size:.84rem;font-weight:600;cursor:pointer;transition:all .2s}.chip:hover{border-color:var(--accent-light)}.chip.selected{border-color:var(--accent);background:var(--accent);color:var(--text-inv)}.reward-card{display:flex;align-items:center;justify-content:space-between;padding:14px 0;border-bottom:1px solid var(--divider)}.reward-card:last-child{border-bottom:none}.likert-row{display:flex;align-items:center;gap:10px;margin:8px 0 18px;justify-content:center}.likert-btn{width:44px;height:44px;border-radius:50%;background:var(--card);border:2px solid var(--divider);color:var(--text);font-weight:600;font-size:.88rem;display:flex;align-items:center;justify-content:center;cursor:pointer;transition:all .2s;box-shadow:var(--shadow-1)}.likert-btn:hover{border-color:var(--accent);transform:scale(1.1)}.likert-btn.selected{border-color:transparent;background:var(--accent);color:var(--text-inv);box-shadow:var(--shadow-accent);transform:scale(1.1)}.likert-labels{display:flex;justify-content:space-between;font-size:.68rem;color:var(--text-3);font-weight:700;text-transform:uppercase;letter-spacing:.06em}.gate-banner{text-align:center;padding:28px 20px;border-radius:var(--r-lg);margin-bottom:14px;position:relative}.gate-earned{background:linear-gradient(135deg,#e8f5e9,#c8e6c9,#e0f2f1);border:2px solid rgba(0,200,83,.2)}.gate-locked{background:linear-gradient(135deg,#fff3e0,#ffe0b2,#fff8e1);border:2px solid rgba(255,87,34,.15)}.gate-pts{font-family:var(--font-mono);font-size:2.8rem;font-weight:700;letter-spacing:-.04em;line-height:1;margin:8px 0}.meal-section{margin-bottom:18px}.meal-title{font-size:.72rem;font-weight:600;text-transform:uppercase;letter-spacing:.06em;color:var(--text-3);margin-bottom:6px;padding-bottom:6px;border-bottom:2px solid var(--divider)}.loading{display:flex;justify-content:center;padding:60px;color:var(--text-3);font-weight:600}.error-msg{background:var(--red-ghost);border:2px solid rgba(255,23,68,.15);padding:12px 16px;border-radius:var(--r);color:var(--red);font-weight:600;font-size:.88rem;margin-bottom:14px}@keyframes fadeUp{0%{opacity:0;transform:translateY(16px)}to{opacity:1;transform:translateY(0)}}@keyframes popIn{0%{opacity:0;transform:scale(.92)}to{opacity:1;transform:scale(1)}}@keyframes countUp{0%{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}.page>.card:nth-child(1){animation:fadeUp .3s ease-out both}.page>.card:nth-child(2){animation:fadeUp .3s ease-out .06s both}.page>.card:nth-child(3){animation:fadeUp .3s ease-out .12s both}.page>.card:nth-child(4){animation:fadeUp .3s ease-out .18s both}.gate-banner{animation:popIn .35s cubic-bezier(.4,0,.2,1) both}.gate-pts{animation:countUp .4s ease-out .15s both}@media(prefers-color-scheme:dark){:root{--accent: #6B9BFF;--accent-dark: #4A78E0;--accent-light: #8BB5FF;--accent-bg: #101630;--accent-glow: rgba(107, 155, 255, .18);--green: #30C090;--green-dark: #20A070;--green-light: #50D8A8;--green-bg: rgba(48, 192, 144, .1);--red: #EF5350;--red-bg: rgba(239, 83, 80, .1);--amber: #F0B040;--amber-bg: rgba(240, 176, 64, .1);--text: #eaecf4;--text-2: #b0b8d0;--text-3: #7882a0;--text-inv: #0a0b12;--bg: #0a0b12;--bg-warm: linear-gradient(170deg, #0e1020 0%, #0a0b12 50%, #0c0e1a 100%);--card: #12131d;--card-border: rgba(34, 40, 64, .8);--divider: rgba(34, 40, 64, .8);--shadow-1: 0 1px 3px rgba(0, 0, 0, .3);--shadow-2: 0 4px 16px rgba(0, 0, 0, .4);--shadow-3: 0 12px 40px rgba(0, 0, 0, .5);--shadow-accent: 0 4px 20px rgba(107, 155, 255, .15);--shadow-green: 0 4px 20px rgba(48, 192, 144, .15)}body{background:var(--bg);color:var(--text)}.nav-bar{background:#0a0b12eb}input,select,textarea{background:var(--bg);color:var(--text)}.gate-earned{background:linear-gradient(135deg,#30c0901f,#30c0900f);border-color:#30c09040}.gate-locked{background:linear-gradient(135deg,#6b9bff1a,#6b9bff0d);border-color:#6b9bff26}.option-btn,.chip,.likert-btn{background:var(--card)}}:root[data-theme=dark]{--accent: #6B9BFF;--accent-dark: #4A78E0;--accent-light: #8BB5FF;--accent-bg: #101630;--accent-glow: rgba(107, 155, 255, .18);--green: #30C090;--green-dark: #20A070;--green-light: #50D8A8;--green-bg: rgba(48, 192, 144, .1);--red: #EF5350;--red-bg: rgba(239, 83, 80, .1);--amber: #F0B040;--amber-bg: rgba(240, 176, 64, .1);--text: #eaecf4;--text-2: #b0b8d0;--text-3: #7882a0;--text-inv: #0a0b12;--bg: #0a0b12;--bg-warm: linear-gradient(170deg, #0e1020 0%, #0a0b12 50%, #0c0e1a 100%);--card: #12131d;--card-border: rgba(34, 40, 64, .8);--divider: rgba(34, 40, 64, .8);--shadow-1: 0 1px 3px rgba(0, 0, 0, .3);--shadow-2: 0 4px 16px rgba(0, 0, 0, .4);--shadow-3: 0 12px 40px rgba(0, 0, 0, .5);--shadow-accent: 0 4px 20px rgba(107, 155, 255, .15);--shadow-green: 0 4px 20px rgba(48, 192, 144, .15)}::-webkit-scrollbar{width:4px}::-webkit-scrollbar-track{background:transparent}::-webkit-scrollbar-thumb{background:var(--divider);border-radius:4px}@media(max-width:380px){.page{padding:12px 10px 96px}.gate-pts{font-size:2.2rem}.option-grid{gap:8px}.option-btn{padding:14px 10px}} diff --git a/diligence/frontend/index.html b/diligence/frontend/index.html index 2fe4956..ee243d6 100644 --- a/diligence/frontend/index.html +++ b/diligence/frontend/index.html @@ -7,8 +7,8 @@ Fitness Rewards - - + +
diff --git a/diligence/main.py b/diligence/main.py index fd860d2..ee88768 100644 --- a/diligence/main.py +++ b/diligence/main.py @@ -98,6 +98,7 @@ from diligence.routers.support import router as support_router from diligence.routers.nutrition import router as nutrition_router from diligence.routers.meal_plans import router as meal_plans_router from diligence.routers.ai_chat import router as ai_chat_router +from diligence.routers.agent import router as agent_router app.include_router(auth_router) app.include_router(onboarding_router) @@ -112,6 +113,7 @@ app.include_router(programs_router) app.include_router(nutrition_router) app.include_router(meal_plans_router) app.include_router(ai_chat_router) +app.include_router(agent_router) @app.get("/api/health") diff --git a/diligence/routers/agent.py b/diligence/routers/agent.py new file mode 100644 index 0000000..21639f1 --- /dev/null +++ b/diligence/routers/agent.py @@ -0,0 +1,35 @@ +"""Agent connection endpoint — returns MCP config for AI agent setup.""" +from __future__ import annotations + +from fastapi import APIRouter, Depends +from diligence.config import get_settings +from diligence.utils.auth import get_current_user + +router = APIRouter(prefix="/api/agent", tags=["agent"]) + + +@router.get("/config") +async def agent_config(user=Depends(get_current_user)): + """Return MCP connection details for the authenticated user.""" + settings = get_settings() + + # Determine MCP URL based on deployment mode + base = settings.base_url.rstrip("/") + if settings.is_sqlite: + # pip install path — MCP served from same process + mcp_url = f"{base}/mcp/sse" + else: + # Docker path — MCP on separate container port 3001 + from urllib.parse import urlparse + parsed = urlparse(base) + docker_host = parsed.hostname or "localhost" + mcp_url = f"http://{docker_host}:3001/sse" + + return { + "mcp_url": mcp_url, + "api_token": settings.api_token if getattr(user, "is_admin", False) else None, + "api_token_set": bool(settings.api_token), + "deployment": "local" if settings.is_sqlite else "docker", + "base_url": base, + "tools_count": 14, + } diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 5ca3fe2..8f2f68e 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -19,6 +19,7 @@ import CatalogDetail from './pages/CatalogDetail' import Support from './pages/Support' import SupportAdmin from './pages/SupportAdmin' import ChatCoach from './pages/ChatCoach' +import AgentConnect from './pages/AgentConnect' function ProtectedRoute({ children }) { if (!hasToken()) return @@ -95,6 +96,9 @@ function NavBar() { `nav-item ${isActive ? 'active' : ''}`}> 🧠 Coach + `nav-item ${isActive ? 'active' : ''}`}> + 🔌 Agent + ) } @@ -123,6 +127,7 @@ export default function App() { } /> } /> } /> + } /> {hasToken() && } diff --git a/frontend/src/api.js b/frontend/src/api.js index c027719..fe8a1b2 100644 --- a/frontend/src/api.js +++ b/frontend/src/api.js @@ -145,6 +145,9 @@ export const api = { // Resources getResourceRecommendations: () => request('/onboarding/recommendations'), + + // Agent + agentConfig: () => request('/agent/config'), }; export function setToken(token) { diff --git a/frontend/src/index.css b/frontend/src/index.css index 5cd6aae..e33d9b7 100644 --- a/frontend/src/index.css +++ b/frontend/src/index.css @@ -233,7 +233,7 @@ input::placeholder, textarea::placeholder { color: var(--text-3); font-weight: 4 font-size: 0.62rem; font-weight: 700; letter-spacing: 0.03em; - padding: 6px 14px; + padding: 6px 10px; text-decoration: none; transition: color 0.15s; border-radius: var(--r-sm); diff --git a/frontend/src/pages/AgentConnect.jsx b/frontend/src/pages/AgentConnect.jsx new file mode 100644 index 0000000..d6de371 --- /dev/null +++ b/frontend/src/pages/AgentConnect.jsx @@ -0,0 +1,208 @@ +import { useState, useEffect } from 'react' +import { api } from '../api' + +function CopyButton({ text, label }) { + const [copied, setCopied] = useState(false) + const handleCopy = async () => { + try { + await navigator.clipboard.writeText(text) + setCopied(true) + setTimeout(() => setCopied(false), 2000) + } catch { /* fallback for non-HTTPS */ } + } + return ( + + ) +} + +function CodeBlock({ children, copyText }) { + return ( +
+ {copyText && ( +
+ +
+ )} + {children} +
+ ) +} + +export default function AgentConnect() { + const [config, setConfig] = useState(null) + const [loading, setLoading] = useState(true) + const [showToken, setShowToken] = useState(false) + + useEffect(() => { + api.agentConfig() + .then(setConfig) + .catch(console.error) + .finally(() => setLoading(false)) + }, []) + + if (loading) return
Loading...
+ if (!config) return
Failed to load agent config
+ + const maskedToken = config.api_token + ? config.api_token.slice(0, 8) + '\u2026' + config.api_token.slice(-4) + : null + + const claudeDesktopConfig = JSON.stringify({ + "mcpServers": { + "diligence": { + "url": config.mcp_url, + ...(config.api_token ? { "headers": { "Authorization": `Bearer ${config.api_token}` } } : {}) + } + } + }, null, 2) + + return ( +
+
+

+ Connect Your AI Agent +

+

+ Use any MCP-compatible AI to log workouts, track food, and manage your fitness. +

+
+ + {/* Connection Details */} +
+
Connection
+ +
+
+ MCP Endpoint +
+
+ + {config.mcp_url} + + +
+
+ + {config.api_token && ( +
+
+ API Token +
+
+ setShowToken(!showToken)} + style={{ + flex: 1, fontFamily: 'var(--font-mono)', fontSize: '0.82rem', + cursor: 'pointer', wordBreak: 'break-all', + }} + > + {showToken ? config.api_token : maskedToken} + + +
+
+ Tap token to reveal. Only visible to admins. +
+
+ )} + + {!config.api_token && config.api_token_set && ( +
+ API token is set but only visible to admin users. +
+ )} + +
+ {config.tools_count} tools available + | + {config.deployment === 'local' ? 'Local (SQLite)' : 'Docker (PostgreSQL)'} +
+
+ + {/* Claude Desktop Setup */} +
+
Claude Desktop
+

+ Add this to your Claude Desktop MCP config: +

+ + {claudeDesktopConfig} + +

+ On macOS: + ~/Library/Application Support/Claude/claude_desktop_config.json + +

+
+ + {/* Claude Code Setup */} +
+
Claude Code
+

+ Add the MCP server from your terminal: +

+ + {`claude mcp add diligence --transport sse ${config.mcp_url}`} + +
+ + {/* What your agent can do */} +
+
What Your Agent Can Do
+
+ {[ + ['Log workouts', 'Track any activity and earn points automatically'], + ['Track food', 'Search 400K+ foods, log meals with full macros'], + ['Manage meal plans', 'Create plans, track compliance, adjust portions'], + ['Check progress', 'Daily points, weekly summary, program status'], + ['Redeem rewards', 'Spend earned points on rewards you set up'], + ].map(([title, desc]) => ( +
+ + ✓ + +
+
{title}
+
{desc}
+
+
+ ))} +
+
+
+ ) +}