forge-openclaw-plugin 0.2.107 → 0.2.108
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{activity-page-Dv6X5ZCV.js → activity-page-DWHZ8_sJ.js} +1 -1
- package/dist/assets/{ai-surface-workspace-CutiG6uS.js → ai-surface-workspace-DPygfyhc.js} +1 -1
- package/dist/assets/{atlas-panel-jgMRyaHn.js → atlas-panel-D261RUQF.js} +1 -1
- package/dist/assets/{calendar-page-q7Nm5E2U.js → calendar-page-BQbJkdPF.js} +1 -1
- package/dist/assets/{calendar-rules-DPFsfiRl.js → calendar-rules-BoFsuvZ8.js} +1 -1
- package/dist/assets/{calendar-week-toolbar-nVhgB-0s.js → calendar-week-toolbar-LetevPI7.js} +1 -1
- package/dist/assets/{companion-sync-lab-page-CJ8UTij8.js → companion-sync-lab-page-Bid-4B8W.js} +1 -1
- package/dist/assets/{daily-metrics-dashboard-CiJkkkd1.js → daily-metrics-dashboard-CqnGJNeI.js} +1 -1
- package/dist/assets/{entity-note-count-link-RzBB6ujx.js → entity-note-count-link-VMURwBMi.js} +1 -1
- package/dist/assets/{entity-notes-surface-Djz50HvD.js → entity-notes-surface-DGXcyNzo.js} +1 -1
- package/dist/assets/{execution-board-CtPhI-58.js → execution-board-BGf6zZqJ.js} +1 -1
- package/dist/assets/{faceted-token-search-DEC6ANa9.js → faceted-token-search-CAsZrhZ4.js} +1 -1
- package/dist/assets/{flagship-signal-deck-CtHC3mql.js → flagship-signal-deck-DJsq3jn2.js} +1 -1
- package/dist/assets/{floating-action-menu-CKQRhff9.js → floating-action-menu-B3tQStUN.js} +1 -1
- package/dist/assets/{goal-detail-page-CF5fNQeR.js → goal-detail-page-DBs-9wpk.js} +1 -1
- package/dist/assets/{goals-page-fsY8NzGB.js → goals-page-CPmhjsG-.js} +1 -1
- package/dist/assets/{habits-page-COoGz4kj.js → habits-page-DkW8zT6_.js} +1 -1
- package/dist/assets/index-BhkubYaC.js +19 -0
- package/dist/assets/{insight-flow-dialog-DtX_5W7g.js → insight-flow-dialog-BvgRjkPi.js} +1 -1
- package/dist/assets/{insights-page-cBd74ObU.js → insights-page-Dtij6pm5.js} +1 -1
- package/dist/assets/{kanban-page-CYav9THw.js → kanban-page-R1x5hUU-.js} +1 -1
- package/dist/assets/{knowledge-graph-page-D2A-W1jE.js → knowledge-graph-page-BRBB5Vvz.js} +1 -1
- package/dist/assets/{life-force-page-CACGlNhq.js → life-force-page-DGPWKM9I.js} +1 -1
- package/dist/assets/{life-force-workspace-BJ4N1I78.js → life-force-workspace-DoRIQoU_.js} +1 -1
- package/dist/assets/{metric-tile-CMadwnGz.js → metric-tile-NJiFcFxW.js} +1 -1
- package/dist/assets/{movement-page-D5VqFd2q.js → movement-page-Dk8aV737.js} +1 -1
- package/dist/assets/{note-markdown-BzK2Qlgr.js → note-markdown-CZHjJDve.js} +1 -1
- package/dist/assets/{note-tags-input-CZzqJMLc.js → note-tags-input-DFpxZHPg.js} +1 -1
- package/dist/assets/{notes-page-D3Hsh90C.js → notes-page-r3kymlqg.js} +1 -1
- package/dist/assets/{open-in-graph-button-BFPKfyK3.js → open-in-graph-button-B_XHtHZD.js} +1 -1
- package/dist/assets/{orbit-map-CnyfSmOG.js → orbit-map-C_xy4kYC.js} +1 -1
- package/dist/assets/{overview-page-CXdWrOV1.js → overview-page-Dwg4uYe9.js} +1 -1
- package/dist/assets/{page-hero-ffKzgyW3.js → page-hero-DzEsy8i5.js} +1 -1
- package/dist/assets/{pill-cluster-C2D0h3lx.js → pill-cluster-DcBUeEMT.js} +1 -1
- package/dist/assets/{preference-entity-handoff-button-Dj3V6VxL.js → preference-entity-handoff-button-BX2n07ob.js} +1 -1
- package/dist/assets/{preferences-page-Jo8Gw386.js → preferences-page-BSnwiWBt.js} +1 -1
- package/dist/assets/{project-collections-qSqp90HN.js → project-collections-BR6YdlCZ.js} +1 -1
- package/dist/assets/{project-detail-page-BifhiLQX.js → project-detail-page-DeYshcCb.js} +1 -1
- package/dist/assets/{project-management-hierarchy-page-DZ_9klIc.js → project-management-hierarchy-page-Bhdt79Ea.js} +1 -1
- package/dist/assets/{project-management-section-nav-BImLCVvf.js → project-management-section-nav-DnXuWUfe.js} +1 -1
- package/dist/assets/{projects-page-ptcx6H38.js → projects-page-BA9W0ZPk.js} +1 -1
- package/dist/assets/{psyche-behaviors-page-BDwXyDta.js → psyche-behaviors-page-DpTj53GI.js} +1 -1
- package/dist/assets/{psyche-flashcards-page-DL1BP1jX.js → psyche-flashcards-page-CV58hAJA.js} +1 -1
- package/dist/assets/{psyche-goal-map-page-ovcpisx1.js → psyche-goal-map-page-C07CALFg.js} +1 -1
- package/dist/assets/{psyche-graph-EP5GL612.js → psyche-graph-CP7mxfMP.js} +1 -1
- package/dist/assets/{psyche-metrics-page-Bcu813Rg.js → psyche-metrics-page-CY8e9R0D.js} +1 -1
- package/dist/assets/{psyche-mode-guide-page-C0g27Xpt.js → psyche-mode-guide-page-DYt6AmHl.js} +1 -1
- package/dist/assets/{psyche-modes-page-BjKjX5MR.js → psyche-modes-page-Dd77kTtJ.js} +1 -1
- package/dist/assets/{psyche-page-F4tF2W70.js → psyche-page-DNXZjIKp.js} +1 -1
- package/dist/assets/{psyche-patterns-page-B-14hukK.js → psyche-patterns-page-DxGzpeT5.js} +1 -1
- package/dist/assets/{psyche-questionnaire-builder-page-BdXmoHvK.js → psyche-questionnaire-builder-page-5EQctRHO.js} +1 -1
- package/dist/assets/{psyche-questionnaire-detail-page-Cu5uwlJu.js → psyche-questionnaire-detail-page-W8nhUGAc.js} +1 -1
- package/dist/assets/{psyche-questionnaire-run-detail-page-C3R4PClg.js → psyche-questionnaire-run-detail-page-DVwzSuqg.js} +1 -1
- package/dist/assets/{psyche-questionnaire-run-page-Div3iDdt.js → psyche-questionnaire-run-page-BHResQgL.js} +1 -1
- package/dist/assets/{psyche-questionnaires-page-DpqAPQCp.js → psyche-questionnaires-page-DFTOXpyp.js} +1 -1
- package/dist/assets/{psyche-report-detail-page-BvWVDKP3.js → psyche-report-detail-page-BqDE_tf7.js} +1 -1
- package/dist/assets/{psyche-reports-page-BrbWUlAq.js → psyche-reports-page-B75pDz0l.js} +1 -1
- package/dist/assets/{psyche-schemas-beliefs-page-DYKvAtSD.js → psyche-schemas-beliefs-page-BjSO4tYL.js} +1 -1
- package/dist/assets/{psyche-screen-time-page-CAOKCyQw.js → psyche-screen-time-page-B7lKf1g7.js} +1 -1
- package/dist/assets/{psyche-self-observation-page-F0MVA0UH.js → psyche-self-observation-page-C6RMThwc.js} +1 -1
- package/dist/assets/{psyche-values-page-DyvX-d0o.js → psyche-values-page-1O158mIJ.js} +1 -1
- package/dist/assets/{report-chain-fields-CeC1cJFS.js → report-chain-fields-CyJ_VFY5.js} +1 -1
- package/dist/assets/{rewards-page-C2loyODo.js → rewards-page-sPlDYuVo.js} +1 -1
- package/dist/assets/{scheduling-rules-editor-D40AC2jR.js → scheduling-rules-editor-DGgcBs1W.js} +1 -1
- package/dist/assets/{schema-badge-FY7818qB.js → schema-badge-Do-YvNHm.js} +1 -1
- package/dist/assets/{select-menu-DJsCG6rM.js → select-menu-CAM7rMdO.js} +1 -1
- package/dist/assets/{settings-agents-page-BFkJ5AAD.js → settings-agents-page-BsZY71kz.js} +1 -1
- package/dist/assets/{settings-bin-page-D3-Ab-iA.js → settings-bin-page-kB3jtHo_.js} +1 -1
- package/dist/assets/{settings-calendar-page-ly_mSTAD.js → settings-calendar-page-C-IGNk3_.js} +1 -1
- package/dist/assets/{settings-data-page-D7QOqNf-.js → settings-data-page-CFGSL9g3.js} +1 -1
- package/dist/assets/{settings-logs-page-Ca87HEUx.js → settings-logs-page-C7e9FIN_.js} +1 -1
- package/dist/assets/{settings-mobile-page-D0jejZot.js → settings-mobile-page-DzKeZQDM.js} +1 -1
- package/dist/assets/{settings-models-page-DPDsZjSc.js → settings-models-page-dFhaOV3E.js} +1 -1
- package/dist/assets/{settings-page-1cArlSPM.js → settings-page-C0fSyYUx.js} +1 -1
- package/dist/assets/{settings-rewards-page-Db4BV1DC.js → settings-rewards-page-D-LuZHhv.js} +1 -1
- package/dist/assets/{settings-section-nav-DP9o4peU.js → settings-section-nav-kFFQSJEe.js} +1 -1
- package/dist/assets/{settings-users-page-BHFyDSsd.js → settings-users-page-CX797HPB.js} +1 -1
- package/dist/assets/{settings-wiki-page-BNaiupBm.js → settings-wiki-page-CWLAvcsf.js} +1 -1
- package/dist/assets/{sleep-page-BmOPF0yD.js → sleep-page-QgBkKyk_.js} +1 -1
- package/dist/assets/{sports-page-BldIiclr.js → sports-page-C8tLMl7V.js} +1 -1
- package/dist/assets/{strategies-page-CaTN99qj.js → strategies-page-CGgh-KXu.js} +1 -1
- package/dist/assets/{strategy-detail-page-DsgFTd-U.js → strategy-detail-page-CnzqjjoD.js} +1 -1
- package/dist/assets/{strategy-dialog-7X7peRzu.js → strategy-dialog-C6AThZ9L.js} +1 -1
- package/dist/assets/{surface-CJI17F3n.js → surface-CIDhCEsF.js} +1 -1
- package/dist/assets/{task-detail-page-M1sIIPA8.js → task-detail-page-Dp0r_qZP.js} +1 -1
- package/dist/assets/{timebox-planning-dialog-ByojN0AN.js → timebox-planning-dialog-B3uaSsWI.js} +1 -1
- package/dist/assets/{today-page-BjDijtn8.js → today-page-CTnMYrPi.js} +1 -1
- package/dist/assets/{training-load-page-BPRmaWmF.js → training-load-page-D0WB5_Tq.js} +1 -1
- package/dist/assets/{vitals-page-CE9zdGLF.js → vitals-page-0vg8nqwj.js} +1 -1
- package/dist/assets/{weekly-review-page-CzhTv90n.js → weekly-review-page-CSSKlkbH.js} +1 -1
- package/dist/assets/{weight-loss-page-Bp_cIk78.js → weight-loss-page-Dcr4wjjy.js} +1 -1
- package/dist/assets/{wiki-article-markdown-Dok2uy2p.js → wiki-article-markdown-CBFvfJx_.js} +1 -1
- package/dist/assets/{wiki-editor-page-BuW32Y3f.js → wiki-editor-page-CL1uxpih.js} +1 -1
- package/dist/assets/{wiki-ingest-history-page-DZKSBNHV.js → wiki-ingest-history-page-XX8DeNCC.js} +1 -1
- package/dist/assets/{wiki-ingest-modal-DyqBEZcC.js → wiki-ingest-modal-j-ftDmzp.js} +1 -1
- package/dist/assets/{wiki-page-DqxlbLKG.js → wiki-page-B46TQYpy.js} +1 -1
- package/dist/assets/{workbench-flow-page-C4nc9jUg.js → workbench-flow-page-CicEuBKq.js} +1 -1
- package/dist/assets/{workbench-page-BnyR7SL0.js → workbench-page-tXezYLh_.js} +1 -1
- package/dist/assets/{workout-detail-page-DT-c5cHL.js → workout-detail-page-BTO5X0Of.js} +1 -1
- package/dist/index.html +1 -1
- package/dist/server/server/src/repositories/agent-runtime-sessions.js +0 -26
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/dist/assets/index-EqQsXoat.js +0 -19
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as a,b4 as De,aG as ta,b3 as na,cm as Aa,dx as Ea,cG as _a,bL as _e,bX as $a,cK as ra,ce as Ta,c7 as sa,dy as Da,dz as Ia,bE as ia,dA as La,dB as Pa,r as F,d8 as Ra,bH as Qe,dC as Wa,bF as Ba,bu as Ha}from"./vendor-Dnkkx2co.js";import{j as qa,i as za,k as q}from"./state-vCcAT5Hq.js";import{P as Oa}from"./page-hero-ffKzgyW3.js";import{C as z,B as K,aq as de,I as k,Z as oa,c as $,Q as je,F as y,j as Ve,T as ve,u as Ua,eW as Qa,eX as Va,eY as Ye,eZ as Ya,e_ as Ja,e$ as Za,f0 as Xa,f1 as Je,f2 as et,f3 as at,f4 as tt,L as nt,E as rt,f5 as st}from"./index-EqQsXoat.js";import{S as D,a as N}from"./surface-CJI17F3n.js";import{f as $e}from"./date-keys-Cj1G3TOn.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";function it({view:e,onOpenPlan:t,onOpenFoodSearch:n,onOpenCustomFood:r,onOpenChatGptFood:s,onOpenCheckin:d,onOpenHistory:g}){return a.jsxs(z,{className:"grid gap-4 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-section)] p-5 lg:grid-cols-[minmax(0,1fr)_auto] lg:items-center",children:[a.jsxs("div",{className:"min-w-0",children:[a.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Control center"}),a.jsx("h2",{className:"mt-1 text-xl font-semibold text-[var(--ui-ink-strong)]",children:e.target.bodyGoal?`Goal: ${e.target.bodyGoal}`:"Set the body objective"}),a.jsxs("p",{className:"mt-2 max-w-3xl text-sm leading-6 text-[var(--ui-ink-soft)]",children:["Current target: ",e.target.calorieTarget.toFixed(0)," kcal,"," ",e.target.proteinGramsTarget.toFixed(0),"g protein,"," ",e.target.fiberGramsTarget.toFixed(0),"g fiber. Adjust the plan, add food with exact quantities, or record body signals from guided flows."]})]}),a.jsxs("div",{className:"grid min-w-0 gap-2 sm:grid-cols-2 xl:grid-cols-3",children:[a.jsxs(K,{type:"button",onClick:r,children:[a.jsx(De,{className:"size-4"}),"Custom food"]}),a.jsxs(K,{type:"button",variant:"secondary",onClick:s,children:[a.jsx(ta,{className:"size-4"}),"Ask ChatGPT"]}),a.jsxs(K,{type:"button",variant:"secondary",onClick:n,children:[a.jsx(na,{className:"size-4"}),"Search food"]}),a.jsxs(K,{type:"button",variant:"secondary",onClick:t,children:[a.jsx(Aa,{className:"size-4"}),"Plan settings"]}),a.jsxs(K,{type:"button",variant:"secondary",onClick:d,children:[a.jsx(Ea,{className:"size-4"}),"Add measure"]}),a.jsxs(K,{type:"button",variant:"secondary",onClick:g,children:[a.jsx(_a,{className:"size-4"}),"Food history"]})]})]})}function A(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function ie(e){return typeof e=="string"&&e.trim()?e:null}function i(e,t=0){const n=A(e);return n===null?"n/a":n.toFixed(t)}function W(e,t=0){const n=A(e);return n===null?"n/a":`${n>0?"+":""}${n.toFixed(t)}`}function be(e){const t=A(e);return t===null?"n/a":`${t.toFixed(1)}/10`}function ot(e){return Array.isArray(e)?e.filter(t=>!!t&&typeof t=="object"&&!Array.isArray(t)):[]}function lt(e){switch(e){case"user_override":return"Manual override for today";case"today_healthkit_active_energy":return"HealthKit active energy today";case"today_workout_movement_energy":return"Workout + movement today";case"today_workout_movement_step_energy":return"Workout + movement + steps today";case"today_workout_step_energy":return"Workout + steps today";case"today_movement_step_energy":return"Movement + steps today";case"today_workout_energy":return"Workout energy today";case"today_movement_trip_calories":return"Movement trips today";case"today_step_estimate":return"Step estimate today";default:return"Default daily active calories"}}function ct(e){switch(e){case"user_override":return"Using your manual value for today.";case"today_healthkit_active_energy":return"Using same-day HealthKit active energy instead of the default.";case"today_workout_movement_energy":return"Using today's workout and movement calories instead of the default.";case"today_workout_movement_step_energy":return"Using today's workouts, movement, and steps instead of the default.";case"today_workout_step_energy":return"Using today's workouts and steps instead of the default.";case"today_movement_step_energy":return"Using today's movement and steps instead of the default.";case"today_workout_energy":return"Using today's workout calories instead of the default.";case"today_movement_trip_calories":return"Using today's movement calories instead of the default.";case"today_step_estimate":return"Using today's step estimate because it is above the default.";default:return"No meaningful same-day active evidence yet, so the default active calories are used."}}function dt({view:e,draftValue:t,pending:n,error:r,onDraftChange:s,onSave:d,onReset:g}){const l=e.energyModel,o=e.todayLedger,c=l.todayActiveOverride,w=l.todayActiveCaloriesSource,b=`${o.plannedTargetCalories.toFixed(0)} + (${l.todayActiveCaloriesKcal.toFixed(0)} - ${l.baselineActiveCaloriesKcal.toFixed(0)}) = ${o.targetCalories.toFixed(0)} kcal`;return a.jsxs(z,{className:"grid min-w-0 gap-3 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[a.jsxs("div",{className:"flex min-w-0 items-start justify-between gap-3",children:[a.jsxs("div",{className:"min-w-0",children:[a.jsxs("div",{className:"flex items-center gap-1 text-[11px] uppercase tracking-[0.14em] text-[var(--ui-ink-faint)]",children:["Active kcal",a.jsx(de,{label:"Explain active calories",content:`Today target = baseline food target + (today active calories - default active calories). ${b}. Same-day HealthKit active energy, workouts, movement, or steps replace the default. A manual edit overrides today only.`})]}),a.jsxs("div",{className:"mt-1 text-2xl font-semibold leading-tight text-[var(--ui-ink-strong)]",children:[l.todayActiveCaloriesKcal.toFixed(0)," kcal"]})]}),a.jsx("div",{className:"rounded-[8px] bg-[var(--ui-info-soft)] p-2 text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]",children:a.jsx(_e,{className:"size-4"})})]}),a.jsxs("div",{className:"grid gap-1 text-xs leading-5 text-[var(--ui-ink-soft)]",children:[a.jsx("div",{className:"break-words font-medium text-[var(--ui-ink-medium)]",children:ct(w)}),a.jsxs("div",{children:["Default ",l.baselineActiveCaloriesKcal.toFixed(0)," kcal"," · ","observed"," ",l.todayObservedActiveCaloriesKcal!=null?`${l.todayObservedActiveCaloriesKcal.toFixed(0)} kcal`:"n/a"]}),a.jsxs("div",{className:"break-words",children:["Source: ",lt(w)]})]}),a.jsxs("div",{className:"grid min-w-0 grid-cols-[minmax(0,1fr)_auto] gap-2",children:[a.jsx(k,{inputMode:"decimal",value:t,onChange:x=>s(x.target.value),"aria-label":"Today active calories",className:"py-2.5"}),a.jsxs(K,{type:"button",onClick:d,pending:n,pendingLabel:"Applying",children:[a.jsx($a,{className:"size-4"}),"Apply"]})]}),a.jsxs(K,{type:"button",variant:"secondary",onClick:g,disabled:!c||n,children:[a.jsx(ra,{className:"size-4"}),"Use evidence"]}),r?a.jsx("div",{className:"rounded-[8px] border border-[var(--danger)]/20 bg-[var(--ui-danger-soft)] px-3 py-2 text-xs leading-5 text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]",children:r}):null]})}const ut={default:"bg-[color-mix(in_srgb,var(--primary)_14%,transparent)] text-[var(--primary)]",green:"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]",amber:"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_76%,var(--ui-ink-strong)_24%)]",rose:"bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]",cyan:"bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]"};function Y({label:e,value:t,detail:n,icon:r,tone:s="default",help:d,helpMaxWidthPx:g}){return a.jsxs(z,{className:"grid gap-4 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-5",children:[a.jsxs("div",{className:"flex items-center justify-between gap-3",children:[a.jsx("div",{className:oa("rounded-2xl p-2.5",ut[s]),children:a.jsx(r,{className:"size-5"})}),a.jsxs("div",{className:"flex items-center justify-end gap-1 text-right text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:[a.jsx("span",{children:e}),d?a.jsx(de,{content:d,label:`Explain ${e}`,maxWidthPx:g}):null]})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-3xl font-semibold text-[var(--ui-ink-strong)]",children:t}),a.jsx("p",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:n})]})]})}function gt({meal:e,onLogAgain:t,onEdit:n,onDelete:r,pending:s=!1}){const d=e.items[0]??null,g=Math.max(0,e.items.length-1),l=d?`${d.name}${g>0?` + ${g} more`:""}`:e.mealLabel??"Meal",o=e.items.slice(0,3).map(c=>{const w=Number.isFinite(c.quantity)&&c.quantity>0?Number.isInteger(c.quantity)?String(c.quantity):c.quantity.toFixed(2).replace(/\.?0+$/,""):null,b=c.unit??"serving",x=c.grams!=null?`${c.grams.toFixed(0)}g`:null;return[w,b,x?`(${x})`:null].filter(Boolean).join(" ")}).filter(Boolean).join(" · ");return a.jsxs(D,{className:"grid min-w-0 gap-3",children:[a.jsxs("div",{className:"flex min-w-0 flex-wrap items-start justify-between gap-3",children:[a.jsxs("div",{className:"min-w-0",children:[a.jsx("div",{className:"break-words text-base font-semibold leading-6 text-[var(--ui-ink-strong)]",children:l}),a.jsx("div",{className:"mt-1 text-xs leading-5 text-[var(--ui-ink-faint)]",children:o||e.notes||"No quantity recorded"})]}),a.jsxs("div",{className:"flex flex-wrap justify-end gap-2",children:[e.mealLabel?a.jsx($,{tone:"meta",children:e.mealLabel}):null,a.jsxs($,{tone:"meta",children:[e.totals.calories.toFixed(0)," kcal"]})]})]}),a.jsxs("div",{className:"grid gap-2 text-xs text-[var(--ui-ink-soft)] sm:grid-cols-3 xl:grid-cols-6",children:[a.jsxs("span",{children:[e.totals.proteinGrams.toFixed(0),"g protein"]}),a.jsxs("span",{children:[e.totals.carbohydrateGrams.toFixed(0),"g carbs"]}),a.jsxs("span",{children:[e.totals.fatGrams.toFixed(0),"g fat"]}),a.jsxs("span",{children:[e.totals.fiberGrams.toFixed(0),"g fiber"]}),a.jsxs("span",{children:[e.totals.sodiumMg.toFixed(0),"mg sodium"]}),a.jsx("span",{children:e.confirmationState})]}),a.jsxs("div",{className:"flex flex-wrap gap-2",children:[n?a.jsxs(K,{type:"button",size:"sm",variant:"secondary",onClick:()=>n(e),children:[a.jsx(Ta,{className:"size-4"}),"Edit"]}):null,r?a.jsxs(K,{type:"button",size:"sm",variant:"ghost",pending:s,onClick:()=>r(e),children:[a.jsx(sa,{className:"size-4"}),"Delete"]}):null,t?a.jsxs(K,{type:"button",size:"sm",variant:"ghost",pending:s,onClick:()=>t(e),children:[a.jsx(ra,{className:"size-4"}),"Log again"]}):null]})]})}function Ie({children:e}){return a.jsx(D,{className:"border-dashed border-[var(--ui-border-strong)] p-5 text-sm text-[var(--ui-ink-soft)]",children:e})}function mt({ledger:e,remainingCalories:t,intakePercent:n,logSavedPending:r,onLogAgain:s,onEditMeal:d,onDeleteMeal:g}){const l=e.totals;return a.jsxs(z,{className:"grid gap-5 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-5",children:[a.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Food log"}),a.jsxs("h2",{className:"mt-1 flex items-center gap-2 text-xl font-semibold text-[var(--ui-ink-strong)]",children:[a.jsx("span",{children:"Calories, macros, and meal evidence"}),a.jsx(de,{label:"Explain food log",content:"The food log is today's editable record of what was eaten. Edit a meal to change quantities, remove items, correct food parameters, or delete the meal entirely."})]})]}),a.jsxs($,{tone:"meta",children:[e.meals.length," meals"]})]}),a.jsxs("div",{children:[a.jsx("div",{className:"h-3 overflow-hidden rounded-full bg-[var(--ui-surface-2)]",children:a.jsx("div",{className:oa("h-full rounded-full",t>=0?"bg-[color-mix(in_srgb,var(--success)_82%,var(--secondary)_18%)]":"bg-[color-mix(in_srgb,var(--danger)_82%,var(--tertiary)_18%)]"),style:{width:`${Math.min(100,n)}%`}})}),a.jsxs("div",{className:"mt-3 grid gap-2 text-sm text-[var(--ui-ink-soft)] sm:grid-cols-4",children:[a.jsxs("span",{children:[l.carbohydrateGrams.toFixed(0),"g carbs"]}),a.jsxs("span",{children:[l.fatGrams.toFixed(0),"g fat"]}),a.jsxs("span",{children:[l.fiberGrams.toFixed(0),"g fiber"]}),a.jsxs("span",{children:[e.unconfirmedCount," unconfirmed"]})]})]}),a.jsx("div",{className:"grid gap-3",children:e.meals.length>0?e.meals.map(o=>a.jsx(gt,{meal:o,pending:r,onLogAgain:s,onEdit:d,onDelete:g},o.id)):a.jsx(Ie,{children:"No meals logged today yet."})})]})}function ht({hypotheses:e}){return a.jsxs(z,{className:"grid gap-4 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-5",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Hypotheses"}),a.jsx("h2",{className:"mt-1 text-xl font-semibold text-[var(--ui-ink-strong)]",children:"Food and body pattern candidates"})]}),a.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:e.length>0?e.slice(0,6).map((t,n)=>a.jsxs(D,{children:[a.jsxs("div",{className:"flex items-center justify-between gap-3",children:[a.jsx($,{tone:"signal",children:ie(t.metric)??"pattern"}),a.jsx("span",{className:"text-xs text-[var(--ui-ink-faint)]",children:i(t.confidence,2)})]}),a.jsx("div",{className:"mt-3 text-sm font-medium text-[var(--ui-ink-strong)]",children:ie(t.label)??"Candidate pattern"}),a.jsx("p",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:ie(t.description)??"Forge needs more paired meals and check-ins to harden this signal."})]},String(t.key??n))):a.jsx("div",{className:"md:col-span-2",children:a.jsx(Ie,{children:"Log meals plus energy, gut, and look check-ins for a few days to generate pattern candidates."})})})]})}function pt({experiments:e}){return a.jsxs(z,{className:"grid content-start gap-4 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-5",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"rounded-2xl bg-[var(--ui-info-soft)] p-2.5 text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]",children:a.jsx(Da,{className:"size-5"})}),a.jsxs("div",{children:[a.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Experiments"}),a.jsx("h2",{className:"text-xl font-semibold text-[var(--ui-ink-strong)]",children:"N-of-1 lab"})]})]}),a.jsxs("div",{className:"grid gap-3",children:[e.slice(0,4).map((t,n)=>a.jsxs(D,{children:[a.jsx("div",{className:"text-sm font-medium text-[var(--ui-ink-strong)]",children:ie(t.title)??"Nutrition experiment"}),a.jsx("p",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:ie(t.hypothesis)??ie(t.intervention)??"No hypothesis recorded."})]},String(t.id??n))),e.length===0?a.jsx(Ie,{children:"Start experiments from OpenClaw or the API: caffeine timing, fiber ramp, low-FODMAP trial, carb timing, sodium/puffiness, or pre-training fueling."}):null]})]})}function xt({view:e}){const t=e.dataQuality,n=e.todayLedger;return a.jsxs(z,{className:"grid gap-4 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-5",children:[a.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Data quality"}),a.jsx("h2",{className:"mt-1 text-xl font-semibold text-[var(--ui-ink-strong)]",children:"Confidence, coverage, and next evidence"})]}),a.jsxs($,{tone:"meta",children:[e.summary.dataQualityScore.toFixed(0),"% coverage"]})]}),a.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[a.jsx(bt,{label:"Source confidence",value:t.sourceConfidence,children:"Food parsing stays candidate-based until accepted; wearable burn is treated as a trend input."}),a.jsxs(D,{children:[a.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Missing check-ins"}),a.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:t.missingHighValueCheckins.length>0?t.missingHighValueCheckins.map(r=>a.jsx($,{tone:"signal",children:r},r)):a.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Core evidence loop is covered."})})]}),a.jsxs(D,{children:[a.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Next best cue"}),a.jsx("p",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:t.notes}),a.jsxs("div",{className:"mt-3 text-xs text-[var(--ui-ink-faint)]",children:[n.unconfirmedCount," unconfirmed candidate",n.unconfirmedCount===1?"":"s"]})]})]})]})}function bt({label:e,value:t,children:n}){return a.jsxs(D,{children:[a.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:e}),a.jsx("div",{className:"mt-2 text-lg font-semibold text-[var(--ui-ink-strong)]",children:t}),a.jsx("p",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:n})]})}function R(e,t,n){return a.jsxs("li",{className:"grid gap-0.5",children:[a.jsx("span",{className:"font-medium text-[var(--ui-ink)]",children:e}),a.jsx("code",{className:"rounded-[6px] bg-[var(--ui-surface-2)] px-1.5 py-0.5 font-mono text-[11px] text-[var(--ui-ink-soft)]",children:t}),n?a.jsx("span",{className:"text-xs text-[var(--ui-ink-faint)]",children:n}):null]})}function la({values:e,label:t="Show calorie and macro formulas"}){const r=((e==null?void 0:e.sex)??"male")==="male"?"+ 5":"- 161",s=(e==null?void 0:e.proteinFactor)!=null?`${e.proteinFactor.toFixed(1)}g/kg`:"1.6-2.0g/kg";return a.jsx(de,{label:t,title:"Weight Loss Formulas",maxWidthPx:520,panelClassName:"text-xs leading-5",content:a.jsxs("div",{className:"grid gap-3",children:[a.jsx("p",{children:"Forge keeps activity independent from the goal. The goal only adds a deficit, surplus, or zero adjustment to resting plus active calories."}),a.jsxs("ol",{className:"grid gap-2",children:[R("Mifflin-St Jeor BMR",`10 x weight kg + 6.25 x height cm - 5 x age ${r}`,`Current formula value: ${i(e==null?void 0:e.bmrKcal)} kcal/day.`),R("Resting calories","HealthKit basal/resting kcal when present, otherwise BMR",`Using: ${i(e==null?void 0:e.restingKcal)} kcal/day${e!=null&&e.restingSource?` (${e.restingSource})`:""}.`),R("Maintenance calories","resting calories + active calories",`${i(e==null?void 0:e.restingKcal)} + ${i(e==null?void 0:e.activeKcal)} = ${i(e==null?void 0:e.maintenanceKcal)} kcal/day.`),R("Objective adjustment","weekly change kg x 7700 kcal/kg / 7",`Weekly rate ${W(e==null?void 0:e.weeklyRateKg,2)} kg/week gives ${W(e==null?void 0:e.dailyAdjustmentKcal)} kcal/day.`),R("Daily calorie target","max(sex floor, maintenance + objective adjustment)",`Floor ${i(e==null?void 0:e.calorieFloor)} kcal; target ${i(e==null?void 0:e.calorieTarget)} kcal/day.`),R("Protein target",`min(reference weight x ${s}, 45% of kcal / 4)`,`Reference ${i(e==null?void 0:e.proteinReferenceWeightKg,1)} kg; target ${i(e==null?void 0:e.proteinGrams)} g/day.`),R("Fat target","saved plan fat when present; otherwise min(remaining kcal after protein, 35% kcal / 9, max(0.6g/kg reference, 25% kcal / 9))",`Target ${i(e==null?void 0:e.fatGrams)} g/day.`),R("Carbohydrate target","(calorie target - protein g x 4 - fat g x 9) / 4",`Target ${i(e==null?void 0:e.carbohydrateGrams)} g/day. The 130g DRI is shown as reference, not forced if it breaks calories.`),R("Fiber target","14g per 1000 kcal; adult sex/age AI shown as reference",`Target ${i(e==null?void 0:e.fiberGrams)} g/day; energy-adjusted ${i(e==null?void 0:e.fiberEnergyAdjustedGrams)} g/day; adult AI reference ${i(e==null?void 0:e.fiberDriGrams)} g/day.`),R("Sport-loss estimate","training hours ~= active kcal / 500; sweat ~= 0.4-0.8 L/h; sodium ~= 500-1000 mg/L","Shown as expected loss ranges, not rigid supplement instructions.")]})]})})}function ca(e,t){var r;if(!e)return null;const n=e.match(new RegExp(`${t}=([^;]+)`));return((r=n==null?void 0:n[1])==null?void 0:r.trim())??null}function ce(e,t){const n=typeof e=="string"?Number(e):A(e);return typeof n=="number"&&Number.isFinite(n)?n:t}function ft(e){return ca(e.target.notes,"sex")==="female"?"female":"male"}function vt(e){return ce(ca(e.target.notes,"age_years"),35)}function p(e,t,n,r,s,d){return{id:e,label:t,target:typeof n=="number"?Te(n):n,unit:r,note:s,source:d}}function Te(e){return Number.isFinite(e)?Math.abs(e)>=100?e.toFixed(0):e.toFixed(1).replace(/\.0$/,""):"n/a"}function se(e,t){return`${Te(e)}-${Te(t)}`}function yt(e,t,n,r){const s=Math.round(n/1e3*14);return r>0?r:s}function jt({calorieTarget:e,currentWeightKg:t,protein:n,savedFat:r}){const s=Math.max(0,(e-n*4)/9),d=Math.max(0,Math.min(s,e*.35/9,Math.max(t*.6,e*.25/9))),g=r??d;return{carbs:Math.max(0,(e-n*4-g*9)/4),fat:g}}function kt(e,t){return e==="male"?t>=51?14:17:t>=51?11:12}function Nt(e,t){const n=t>70,r=t>=51;return[p("vitamin_a","Vitamin A",e==="male"?900:700,"ug RAE","Retinol activity equivalent target.","NASEM DRI"),p("vitamin_c","Vitamin C",e==="male"?90:75,"mg","Adult RDA.","NASEM DRI"),p("vitamin_d","Vitamin D",n?20:15,"ug","Assumes limited sun exposure; older adults need more.","NASEM DRI"),p("vitamin_e","Vitamin E",15,"mg alpha-tocopherol","Adult RDA.","NASEM DRI"),p("vitamin_k","Vitamin K",e==="male"?120:90,"ug","Adult AI.","NASEM DRI"),p("thiamin_b1","Thiamin B1",e==="male"?1.2:1.1,"mg","Adult RDA.","NASEM DRI"),p("riboflavin_b2","Riboflavin B2",e==="male"?1.3:1.1,"mg","Adult RDA.","NASEM DRI"),p("niacin_b3","Niacin B3",e==="male"?16:14,"mg NE","Adult RDA.","NASEM DRI"),p("vitamin_b6","Vitamin B6",r?e==="male"?1.7:1.5:1.3,"mg","RDA rises after 50.","NASEM DRI"),p("folate","Folate",400,"ug DFE","Adult RDA.","NASEM DRI"),p("vitamin_b12","Vitamin B12",2.4,"ug","Adult RDA.","NASEM DRI"),p("pantothenic_acid","Pantothenic acid",5,"mg","Adult AI.","NASEM DRI"),p("biotin","Biotin",30,"ug","Adult AI.","NASEM DRI"),p("choline","Choline",e==="male"?550:425,"mg","Adult AI.","NASEM DRI")]}function wt(e,t){const n=t>70||e==="female"&&t>=51?1200:1e3,r=e==="male"?t>=31?420:400:t>=31?320:310,s=e==="male"?t>=51?30:35:t>=51?20:25,d=t>=71?1800:t>=51?2e3:2300;return[p("calcium","Calcium",n,"mg","Bone and muscle target; higher for older adults and women 51+.","NASEM DRI"),p("iron","Iron",e==="female"&&t<=50?18:8,"mg","Menstruating-age female target is higher.","NASEM DRI"),p("magnesium","Magnesium",r,"mg","Adult RDA.","NASEM DRI"),p("phosphorus","Phosphorus",700,"mg","Adult RDA.","NASEM DRI"),p("zinc","Zinc",e==="male"?11:8,"mg","Adult RDA.","NASEM DRI"),p("iodine","Iodine",150,"ug","Adult RDA.","NASEM DRI"),p("selenium","Selenium",55,"ug","Adult RDA.","NASEM DRI"),p("copper","Copper",.9,"mg","Adult RDA.","NASEM DRI"),p("manganese","Manganese",e==="male"?2.3:1.8,"mg","Adult AI.","NASEM DRI"),p("chromium","Chromium",s,"ug","Adult AI.","NASEM DRI"),p("molybdenum","Molybdenum",45,"ug","Adult RDA.","NASEM DRI"),p("fluoride","Fluoride",e==="male"?4:3,"mg","Adult AI.","NASEM DRI"),p("chloride","Chloride",d,"mg","Adult AI.","NASEM DRI"),p("potassium","Potassium",e==="male"?3400:2600,"mg","Current adult AI for non-pregnant adults.","NASEM DRI"),p("sodium_limit","Sodium ceiling",2300,"mg max","Default daily ceiling unless medically individualized.","U.S. Dietary Guidelines")]}function Ct(e){const t=ft(e),n=vt(e),r=ce(e.weightTrend.latestWeightKg,80),s=Math.max(1,ce(e.target.calorieTarget,2200)),d=ce(e.target.proteinGramsTarget,r*1.8),{carbs:g,fat:l}=jt({calorieTarget:s,currentWeightKg:r,protein:d,savedFat:A(e.target.fatGramsTarget)}),o=yt(t,n,s,ce(e.target.fiberGramsTarget,0)),c=A(e.energyModel.activeBurnKcal)??A(e.energyModel.activeEnergyCalories)??null,w=A(e.energyModel.movementCaloriesKcal),b=A(e.energyModel.restingEnergyCalories);return da({sex:t,ageYears:n,currentWeightKg:r,calorieTarget:s,proteinGramsTarget:d,carbohydrateGramsTarget:g,fatGramsTarget:l,fiberGramsTarget:o,activeBurnKcal:c,movementCaloriesKcal:w,restingEnergyKcal:b})}function da(e){const{sex:t,ageYears:n,currentWeightKg:r,calorieTarget:s,proteinGramsTarget:d,carbohydrateGramsTarget:g,fatGramsTarget:l,fiberGramsTarget:o,activeBurnKcal:c,movementCaloriesKcal:w,restingEnergyKcal:b}=e,x=c!=null?Math.min(4,Math.max(.1,c/500)):null,m=x!=null?x*.4:null,S=x!=null?x*.8:null,E=m!=null?m*500:null,M=S!=null?S*1e3:null,_=m!=null?m*78:null,T=S!=null?S*312:null,L=c!=null?c*7/7700:null;return{profile:{sex:t,ageYears:n,currentWeightKg:r,calorieTarget:s,activeBurnKcal:c,movementCaloriesKcal:w,restingEnergyKcal:b},macros:[p("calories","Calories",s,"kcal","Plan target from BMR, active burn, and chosen weekly rate.","Forge plan"),p("protein","Protein",d,"g","Higher than the population RDA to preserve lean mass during weight change.","ISSN + Forge plan"),p("carbohydrate","Carbohydrate",g,"g","Remaining fuel after protein and fat. It may sit below the 130g/day adult DRI reference when needed to preserve the calorie target.","NASEM DRI + Forge plan"),p("fat","Total fat",l,"g","Uses the saved plan fat target when present; generated defaults aim for a practical floor around 0.6g/kg or 20-35% of calories when possible.","NASEM AMDR + Forge plan"),p("fiber","Fiber",o,"g","Uses 14g per 1000 kcal as the plan target; the sex/age adult AI remains a reference or stretch value when calories are low.","NASEM DRI"),p("saturated_fat","Saturated fat",s*.1/9,"g max","Keep below 10% of energy.","U.S. Dietary Guidelines"),p("added_sugar","Added sugar",s*.1/4,"g max","Keep below 10% of energy; lower is better when feasible.","U.S. Dietary Guidelines"),p("linoleic_acid","Linoleic acid",kt(t,n),"g","Essential n-6 fatty acid AI.","NASEM DRI"),p("ala","ALA omega-3",t==="male"?1.6:1.1,"g","Essential n-3 fatty acid AI.","NASEM DRI"),p("water","Total water",t==="male"?3.7:2.7,"L","All beverages and food water before extra training replacement.","NASEM DRI")],vitamins:Nt(t,n),minerals:wt(t,n),sportLosses:[p("training_time","Estimated training time",x??"n/a","h/day","Derived from active burn at roughly 500 kcal/h.","Forge sport-loss model"),p("sweat_fluid","Expected sweat fluid",m!=null&&S!=null?se(m,S):"n/a","L/day","Planning range uses 0.4-0.8 L/h; measure body mass change to calibrate.","ACSM"),p("sweat_sodium","Expected sweat sodium",E!=null&&M!=null?se(E,M):"n/a","mg/day","Sodium varies widely; this uses a conservative range around common sweat sodium values.","ACSM + Sports Medicine review"),p("sweat_potassium","Expected sweat potassium",_!=null&&T!=null?se(_,T):"n/a","mg/day","Potassium is usually much smaller than sodium but useful for long/hot sessions.","Sports Medicine review"),p("gross_sport_equivalent","Gross sport burn equivalent",L??"n/a","kg/week","Energy equivalent if the active burn were not eaten back; the plan may already include it.","7700 kcal/kg model")],sportSummary:{trainingHours:x,fluidLossLiters:m!=null&&S!=null?se(m,S):"n/a",sodiumLossMg:E!=null&&M!=null?se(E,M):"n/a",potassiumLossMg:_!=null&&T!=null?se(_,T):"n/a",grossSportWeightEquivalentKgPerWeek:L}}}function Ae({rows:e,compact:t=!1}){return a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"grid gap-2 md:hidden",children:e.map(n=>a.jsxs("div",{className:"grid min-w-0 gap-2 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-3",children:[a.jsxs("div",{className:"flex min-w-0 items-start justify-between gap-3",children:[a.jsx("div",{className:"min-w-0 break-words text-sm font-semibold text-[var(--ui-ink)]",children:n.label}),a.jsxs("div",{className:"shrink-0 text-right text-sm font-semibold text-[var(--ui-ink)]",children:[n.target,a.jsx("div",{className:"text-xs font-normal text-[var(--ui-ink-faint)]",children:n.unit})]})]}),a.jsx("p",{className:"min-w-0 break-words text-xs leading-5 text-[var(--ui-ink-muted)]",children:n.note}),t?null:a.jsx($,{tone:"meta",wrap:!0,className:"justify-self-start",children:n.source})]},n.id))}),a.jsx("div",{className:"hidden overflow-hidden rounded-[20px] border border-[var(--ui-border-subtle)] md:block",children:a.jsx("div",{className:"max-h-[460px] overflow-auto",children:a.jsxs("table",{className:"w-full min-w-[620px] border-collapse text-left text-sm",children:[a.jsx("thead",{className:"sticky top-0 bg-[var(--ui-surface-2)] text-xs uppercase text-[var(--ui-ink-faint)]",children:a.jsxs("tr",{children:[a.jsx("th",{className:"px-4 py-3 font-semibold",children:"Target"}),a.jsx("th",{className:"px-4 py-3 font-semibold",children:"Amount"}),a.jsx("th",{className:"px-4 py-3 font-semibold",children:"Rationale"}),t?null:a.jsx("th",{className:"px-4 py-3 font-semibold",children:"Source"})]})}),a.jsx("tbody",{className:"divide-y divide-[var(--ui-border-subtle)]",children:e.map(n=>a.jsxs("tr",{className:"bg-[var(--ui-surface-1)]",children:[a.jsx("td",{className:"px-4 py-3 font-medium text-[var(--ui-ink)]",children:n.label}),a.jsxs("td",{className:"px-4 py-3 text-[var(--ui-ink)]",children:[a.jsx("span",{className:"font-semibold",children:n.target})," ",a.jsx("span",{className:"text-[var(--ui-ink-faint)]",children:n.unit})]}),a.jsx("td",{className:"px-4 py-3 text-[var(--ui-ink-muted)]",children:n.note}),t?null:a.jsx("td",{className:"px-4 py-3",children:a.jsx($,{tone:"meta",children:n.source})})]},n.id))})]})})})]})}function le({title:e,description:t,children:n}){return a.jsxs(D,{children:[a.jsxs("div",{className:"mb-4",children:[a.jsx("h3",{className:"text-sm font-semibold text-[var(--ui-ink)]",children:e}),a.jsx("p",{className:"mt-1 text-sm text-[var(--ui-ink-muted)]",children:t})]}),n]})}function Ft({view:e}){const t=Ct(e),n=e.target.weeklyRateGoalKg??null,r=n!=null&&Number.isFinite(n)?n*7700/7:null,s=t.profile.restingEnergyKcal,d=t.profile.activeBurnKcal,g=s!=null&&d!=null?s+d:null,l=e.target.bodyGoal??"maintain",o=l.includes("lose")?2:l.includes("gain")?1.8:1.6,c=m=>{var M;const S=(M=t.macros.find(_=>_.id===m))==null?void 0:M.target,E=Number(S);return Number.isFinite(E)?E:null},w=t.profile.sex==="male"?t.profile.ageYears>=51?30:38:t.profile.ageYears>=51?21:25,b=Math.round(t.profile.calorieTarget/1e3*14),x=t.sportSummary.grossSportWeightEquivalentKgPerWeek!=null?`${t.sportSummary.grossSportWeightEquivalentKgPerWeek.toFixed(2)} kg/week`:"n/a";return a.jsx("section",{className:"grid gap-4",children:a.jsxs(z,{className:"p-5",children:[a.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-[var(--ui-ink)]",children:[a.jsx(Ia,{className:"size-4 text-[var(--ui-accent)]"}),"Macro And Micronutrient Targets",a.jsx(la,{values:{sex:t.profile.sex,ageYears:t.profile.ageYears,currentWeightKg:t.profile.currentWeightKg,bmrKcal:null,restingKcal:s,restingSource:s!=null?"saved HealthKit basal/resting or plan value":null,activeKcal:d,maintenanceKcal:g,weeklyRateKg:n,dailyAdjustmentKcal:r,calorieTarget:t.profile.calorieTarget,calorieFloor:t.profile.sex==="male"?1500:1200,proteinReferenceWeightKg:null,proteinFactor:o,proteinGrams:c("protein"),fatGrams:c("fat"),carbohydrateGrams:c("carbohydrate"),fiberGrams:c("fiber"),fiberEnergyAdjustedGrams:b,fiberDriGrams:w}})]}),a.jsx("p",{className:"mt-1 max-w-3xl text-sm text-[var(--ui-ink-muted)]",children:"Daily targets use Forge plan values first, then adult DRI/Dietary Guidelines defaults for nutrients the food log can score as catalog detail improves."})]}),a.jsxs("div",{className:"flex flex-wrap gap-2",children:[a.jsxs($,{tone:"signal",children:[t.profile.calorieTarget.toFixed(0)," kcal"]}),a.jsxs($,{tone:"meta",children:[t.profile.sex,", ",t.profile.ageYears.toFixed(0),"y"]})]})]}),a.jsxs("div",{className:"mt-5 grid gap-4 2xl:grid-cols-[minmax(0,1fr)_minmax(320px,0.58fr)]",children:[a.jsxs("div",{className:"grid gap-4",children:[a.jsx(le,{title:"All macro targets",description:"Calories, protein, carbs, fat, fiber, sugar ceiling, saturated fat ceiling, essential fats, and water.",children:a.jsx(Ae,{rows:t.macros,compact:!0})}),a.jsx(le,{title:"Vitamins",description:"Adult daily vitamin targets from DRI values, adjusted for sex and age where the reference differs.",children:a.jsx(Ae,{rows:t.vitamins})})]}),a.jsxs("div",{className:"grid content-start gap-4",children:[a.jsxs(le,{title:"Expected sport losses",description:"Planning range from active burn. Calibrate with pre/post workout weight when possible.",children:[a.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[a.jsx(N,{label:"Active burn",value:t.profile.activeBurnKcal!=null?`${t.profile.activeBurnKcal.toFixed(0)} kcal`:"n/a"}),a.jsx(N,{label:"Sport equivalent",value:x}),a.jsx(N,{label:"Sweat fluid",value:`${t.sportSummary.fluidLossLiters} L`}),a.jsx(N,{label:"Sodium loss",value:`${t.sportSummary.sodiumLossMg} mg`})]}),a.jsxs("div",{className:"mt-4 flex items-start gap-3 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-3 text-sm text-[var(--ui-ink-muted)]",children:[a.jsx(ia,{className:"mt-0.5 size-4 shrink-0 text-[var(--ui-accent)]"}),a.jsx("span",{children:"Sport burn is shown as gross energy equivalent, not a promise of scale loss. The calorie plan may already include active burn, and replacement depends on appetite, heat, sodium loss, and actual intake."})]})]}),a.jsx(le,{title:"Minerals & oligoelements",description:"Daily mineral and trace-element targets including sodium ceiling and potassium AI.",children:a.jsx(Ae,{rows:t.minerals,compact:!0})}),a.jsx(le,{title:"Sport electrolyte model",description:"Use these as expected losses, not rigid supplement prescriptions.",children:a.jsx("div",{className:"grid gap-3",children:t.sportLosses.map(m=>a.jsxs("div",{className:"flex items-start justify-between gap-3 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-3",children:[a.jsxs("div",{className:"min-w-0",children:[a.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-[var(--ui-ink)]",children:[m.id==="sweat_fluid"?a.jsx(La,{className:"size-4 text-[var(--ui-accent)]"}):a.jsx(Pa,{className:"size-4 text-[var(--ui-accent)]"}),m.label]}),a.jsx("p",{className:"mt-1 text-xs text-[var(--ui-ink-faint)]",children:m.note})]}),a.jsxs("div",{className:"shrink-0 text-right text-sm font-semibold text-[var(--ui-ink)]",children:[m.target,a.jsx("div",{className:"text-xs font-normal text-[var(--ui-ink-faint)]",children:m.unit})]})]},m.id))})})]})]})]})})}function ee(e,t){var r;if(!e)return null;const n=e.match(new RegExp(`${t}=([^;]+)`));return((r=n==null?void 0:n[1])==null?void 0:r.trim())??null}function ae(e){const t=typeof e=="number"?e:Number(e);return Number.isFinite(t)&&t>0?t:null}function ua(e,t){if(t==="maintain")return 0;const n=t==="gain"?.0025:.005,r=t==="gain"?.1:.2,s=t==="gain"?.35:Math.max(.5,e*.01);return Math.min(s,Math.max(r,e*n))}function ga(e,t){return t==="gain"?e*1.03:t==="maintain"?e:e*.95}function ma(e){return e.toFixed(1)}function Mt(e,t){return e==="male"?t>=51?30:38:t>=51?21:25}function Ze(e,t){const n=e/100;return n>0?t*n*n:null}function Gt(e){const t=e.goalMode==="lose"&&e.goalWeightKg!=null?Math.min(e.currentWeightKg,e.goalWeightKg):e.currentWeightKg,n=Ze(e.heightCm,30),r=Ze(e.heightCm,25);if(n!=null&&r!=null&&e.currentWeightKg>n){const s=r+(e.currentWeightKg-r)*.25;return Math.min(t,s)}return t}function St(e,t){const n=ae(e.currentWeightKg)??80;return{...e,goalMode:t,goalWeightKg:ma(ga(n,t)),weeklyRateKg:ua(n,t).toFixed(2)}}function Ee(e){const t=A(e.weightTrend.latestWeightKg),n=e.target,r=ee(n.notes,"sex"),s=ee(n.notes,"age_years"),d=ee(n.notes,"height_cm"),g=A(e.energyModel.activeBurnKcal)??A(e.energyModel.activeEnergyCalories)??A(e.energyModel.movementCaloriesKcal)??A(ee(n.notes,"activity_kcal"))??0,l=A(e.energyModel.restingEnergyCalories)??A(ee(n.notes,"resting_kcal"))??null,o=n.bodyGoal??"",c=o.includes("gain")?"gain":o.includes("maintain")?"maintain":"lose",w=n.weightGoalKg??n.goalBodyWeightKg??null,b=t??80;return{goalMode:c,sex:r==="female"?"female":"male",ageYears:ae(s)?String(s):"",heightCm:ae(d)?String(d):"",currentWeightKg:t?t.toFixed(1):"",goalWeightKg:w?String(w):ma(ga(b,c)),weeklyRateKg:n.weeklyRateGoalKg!==null&&n.weeklyRateGoalKg!==void 0?String(Math.abs(n.weeklyRateGoalKg)):ua(b,c).toFixed(2),activeCaloriesKcal:g.toFixed(0),restingCaloriesKcal:l!=null?l.toFixed(0):"",dietStyle:n.dietStyle??""}}function Kt(e){const t=ae(ee(e.target.notes,"age_years"))!=null,n=ae(ee(e.target.notes,"height_cm"))!=null,r=A(e.weightTrend.latestWeightKg)!=null,s=typeof e.target.bodyGoal=="string"&&e.target.bodyGoal.trim().length>0&&e.target.calorieTarget>0&&e.target.proteinGramsTarget>0;return t&&n&&r&&s}function At(e){const t=e.energyModel;return`This is the default active allowance used when today has no same-day workout, movement, step, or active-energy evidence. ${t.energySourceConfidence==="healthkit_daily_active_energy"?"HealthKit daily active energy is the active-burn source; workout and movement values are only visible evidence and are not added again.":t.energySourceConfidence==="workout_movement_fallback"?"HealthKit daily active energy is missing, so active burn already equals workout average plus movement-trip average.":"No measured active-burn stream is available, so Forge is using the plan/default estimate."} Current evidence: active burn ${i(t.activeBurnKcal)} kcal/day, workout average ${i(t.workoutEnergyKcal)} kcal/day, movement average ${i(t.movementCaloriesKcal)} kcal/day, today's workout ${i(t.todayWorkoutEnergyKcal)} kcal, today's movement ${i(t.todayMovementCaloriesKcal)} kcal.`}function ha(e){const t=Number(e.currentWeightKg)||80,n=Number(e.heightCm)||178,r=Number(e.ageYears)||35,s=ae(e.goalWeightKg),d=Math.max(0,Number(e.activeCaloriesKcal)||0),g=ae(e.restingCaloriesKcal),l=e.sex==="male"?5:-161,o=10*t+6.25*n-5*r+l,c=g??o,w=c+d,b=Math.abs(Number(e.weeklyRateKg)||0),x=e.goalMode==="lose"?-b:e.goalMode==="gain"?b:0,m=x*7700/7,S=e.sex==="male"?1500:1200,E=Math.round(w+m),M=Math.max(S,E),_=Gt({currentWeightKg:t,goalWeightKg:s,heightCm:n,goalMode:e.goalMode}),T=e.goalMode==="lose"?2:e.goalMode==="gain"?1.8:1.6,L=Math.round(_*T),B=Math.floor(M*.45/4),P=Math.max(1,Math.min(L,B)),H=_*.6,te=M*.25/9,J=Math.max(0,(M-P*4)/9),O=Math.max(0,Math.floor(Math.min(J,M*.35/9,Math.max(H,te)))),U=Math.max(0,Math.floor((M-P*4-O*9)/4)),ne=Math.round(M/1e3*14),re=Mt(e.sex,r),oe=ne,Z=Math.round(M*.1/9),Q=Math.round(M*.1/4);return{bmr:Math.round(o),restingCalories:Math.round(c),restingSource:g!=null?"HealthKit basal/resting":"Mifflin-St Jeor",activeCalories:Math.round(d),maintenanceCalories:Math.round(w),plannedCalorieTarget:E,minimumCalorieFloor:S,weeklyRateGoalKg:x,dailyEnergyAdjustment:Math.round(m),calorieTarget:M,proteinReferenceWeight:Math.round(_*10)/10,proteinGramsTarget:P,carbohydrateGramsTarget:U,fatGramsTarget:O,fiberGramsTarget:oe,fiberEnergyAdjustedGrams:ne,fiberDriGrams:re,saturatedFatLimitGrams:Z,addedSugarLimitGrams:Q}}function Et(e){const t=[],n=Number(e.ageYears),r=Number(e.heightCm),s=Number(e.currentWeightKg),d=Number(e.goalWeightKg),g=Number(e.weeklyRateKg),l=e.activeCaloriesKcal.trim()?Number(e.activeCaloriesKcal):Number.NaN,o=e.restingCaloriesKcal.trim()?Number(e.restingCaloriesKcal):null;return(!Number.isFinite(n)||n<13||n>100)&&t.push("- Enter the user's real age. Forge uses it in Mifflin-St Jeor resting metabolism."),(!Number.isFinite(r)||r<120||r>230)&&t.push("- Enter height in cm. Height changes BMR and protein reference weight."),(!Number.isFinite(s)||s<30||s>300)&&t.push("- Enter current weight in kg. Use the latest known body measure as the starting state."),e.goalMode!=="maintain"&&(!Number.isFinite(d)||d<30||d>300)&&t.push("- Enter a target weight for the selected loss or gain objective."),(!Number.isFinite(g)||g<0)&&t.push("- Enter a non-negative weekly change rate in kg/week."),Number.isFinite(g)&&g>Math.max(1.5,s*.02)&&t.push("- The weekly rate is very aggressive. Choose a slower default unless this is a supervised plan."),(!Number.isFinite(l)||l<0||l>3e3)&&t.push("- Enter average active calories per day. Zero is valid only when Forge has no activity evidence."),o!=null&&(!Number.isFinite(o)||o<900||o>3500)&&t.push("- Resting calories should be blank for formula mode or a plausible HealthKit basal/resting value."),t.length>0?t.join(`
|
|
1
|
+
import{j as a,b4 as De,aG as ta,b3 as na,cm as Aa,dx as Ea,cG as _a,bL as _e,bX as $a,cK as ra,ce as Ta,c7 as sa,dy as Da,dz as Ia,bE as ia,dA as La,dB as Pa,r as F,d8 as Ra,bH as Qe,dC as Wa,bF as Ba,bu as Ha}from"./vendor-Dnkkx2co.js";import{j as qa,i as za,k as q}from"./state-vCcAT5Hq.js";import{P as Oa}from"./page-hero-DzEsy8i5.js";import{C as z,B as K,aq as de,I as k,Z as oa,c as $,Q as je,F as y,j as Ve,T as ve,u as Ua,eW as Qa,eX as Va,eY as Ye,eZ as Ya,e_ as Ja,e$ as Za,f0 as Xa,f1 as Je,f2 as et,f3 as at,f4 as tt,L as nt,E as rt,f5 as st}from"./index-BhkubYaC.js";import{S as D,a as N}from"./surface-CIDhCEsF.js";import{f as $e}from"./date-keys-Cj1G3TOn.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";function it({view:e,onOpenPlan:t,onOpenFoodSearch:n,onOpenCustomFood:r,onOpenChatGptFood:s,onOpenCheckin:d,onOpenHistory:g}){return a.jsxs(z,{className:"grid gap-4 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-section)] p-5 lg:grid-cols-[minmax(0,1fr)_auto] lg:items-center",children:[a.jsxs("div",{className:"min-w-0",children:[a.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Control center"}),a.jsx("h2",{className:"mt-1 text-xl font-semibold text-[var(--ui-ink-strong)]",children:e.target.bodyGoal?`Goal: ${e.target.bodyGoal}`:"Set the body objective"}),a.jsxs("p",{className:"mt-2 max-w-3xl text-sm leading-6 text-[var(--ui-ink-soft)]",children:["Current target: ",e.target.calorieTarget.toFixed(0)," kcal,"," ",e.target.proteinGramsTarget.toFixed(0),"g protein,"," ",e.target.fiberGramsTarget.toFixed(0),"g fiber. Adjust the plan, add food with exact quantities, or record body signals from guided flows."]})]}),a.jsxs("div",{className:"grid min-w-0 gap-2 sm:grid-cols-2 xl:grid-cols-3",children:[a.jsxs(K,{type:"button",onClick:r,children:[a.jsx(De,{className:"size-4"}),"Custom food"]}),a.jsxs(K,{type:"button",variant:"secondary",onClick:s,children:[a.jsx(ta,{className:"size-4"}),"Ask ChatGPT"]}),a.jsxs(K,{type:"button",variant:"secondary",onClick:n,children:[a.jsx(na,{className:"size-4"}),"Search food"]}),a.jsxs(K,{type:"button",variant:"secondary",onClick:t,children:[a.jsx(Aa,{className:"size-4"}),"Plan settings"]}),a.jsxs(K,{type:"button",variant:"secondary",onClick:d,children:[a.jsx(Ea,{className:"size-4"}),"Add measure"]}),a.jsxs(K,{type:"button",variant:"secondary",onClick:g,children:[a.jsx(_a,{className:"size-4"}),"Food history"]})]})]})}function A(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function ie(e){return typeof e=="string"&&e.trim()?e:null}function i(e,t=0){const n=A(e);return n===null?"n/a":n.toFixed(t)}function W(e,t=0){const n=A(e);return n===null?"n/a":`${n>0?"+":""}${n.toFixed(t)}`}function be(e){const t=A(e);return t===null?"n/a":`${t.toFixed(1)}/10`}function ot(e){return Array.isArray(e)?e.filter(t=>!!t&&typeof t=="object"&&!Array.isArray(t)):[]}function lt(e){switch(e){case"user_override":return"Manual override for today";case"today_healthkit_active_energy":return"HealthKit active energy today";case"today_workout_movement_energy":return"Workout + movement today";case"today_workout_movement_step_energy":return"Workout + movement + steps today";case"today_workout_step_energy":return"Workout + steps today";case"today_movement_step_energy":return"Movement + steps today";case"today_workout_energy":return"Workout energy today";case"today_movement_trip_calories":return"Movement trips today";case"today_step_estimate":return"Step estimate today";default:return"Default daily active calories"}}function ct(e){switch(e){case"user_override":return"Using your manual value for today.";case"today_healthkit_active_energy":return"Using same-day HealthKit active energy instead of the default.";case"today_workout_movement_energy":return"Using today's workout and movement calories instead of the default.";case"today_workout_movement_step_energy":return"Using today's workouts, movement, and steps instead of the default.";case"today_workout_step_energy":return"Using today's workouts and steps instead of the default.";case"today_movement_step_energy":return"Using today's movement and steps instead of the default.";case"today_workout_energy":return"Using today's workout calories instead of the default.";case"today_movement_trip_calories":return"Using today's movement calories instead of the default.";case"today_step_estimate":return"Using today's step estimate because it is above the default.";default:return"No meaningful same-day active evidence yet, so the default active calories are used."}}function dt({view:e,draftValue:t,pending:n,error:r,onDraftChange:s,onSave:d,onReset:g}){const l=e.energyModel,o=e.todayLedger,c=l.todayActiveOverride,w=l.todayActiveCaloriesSource,b=`${o.plannedTargetCalories.toFixed(0)} + (${l.todayActiveCaloriesKcal.toFixed(0)} - ${l.baselineActiveCaloriesKcal.toFixed(0)}) = ${o.targetCalories.toFixed(0)} kcal`;return a.jsxs(z,{className:"grid min-w-0 gap-3 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[a.jsxs("div",{className:"flex min-w-0 items-start justify-between gap-3",children:[a.jsxs("div",{className:"min-w-0",children:[a.jsxs("div",{className:"flex items-center gap-1 text-[11px] uppercase tracking-[0.14em] text-[var(--ui-ink-faint)]",children:["Active kcal",a.jsx(de,{label:"Explain active calories",content:`Today target = baseline food target + (today active calories - default active calories). ${b}. Same-day HealthKit active energy, workouts, movement, or steps replace the default. A manual edit overrides today only.`})]}),a.jsxs("div",{className:"mt-1 text-2xl font-semibold leading-tight text-[var(--ui-ink-strong)]",children:[l.todayActiveCaloriesKcal.toFixed(0)," kcal"]})]}),a.jsx("div",{className:"rounded-[8px] bg-[var(--ui-info-soft)] p-2 text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]",children:a.jsx(_e,{className:"size-4"})})]}),a.jsxs("div",{className:"grid gap-1 text-xs leading-5 text-[var(--ui-ink-soft)]",children:[a.jsx("div",{className:"break-words font-medium text-[var(--ui-ink-medium)]",children:ct(w)}),a.jsxs("div",{children:["Default ",l.baselineActiveCaloriesKcal.toFixed(0)," kcal"," · ","observed"," ",l.todayObservedActiveCaloriesKcal!=null?`${l.todayObservedActiveCaloriesKcal.toFixed(0)} kcal`:"n/a"]}),a.jsxs("div",{className:"break-words",children:["Source: ",lt(w)]})]}),a.jsxs("div",{className:"grid min-w-0 grid-cols-[minmax(0,1fr)_auto] gap-2",children:[a.jsx(k,{inputMode:"decimal",value:t,onChange:x=>s(x.target.value),"aria-label":"Today active calories",className:"py-2.5"}),a.jsxs(K,{type:"button",onClick:d,pending:n,pendingLabel:"Applying",children:[a.jsx($a,{className:"size-4"}),"Apply"]})]}),a.jsxs(K,{type:"button",variant:"secondary",onClick:g,disabled:!c||n,children:[a.jsx(ra,{className:"size-4"}),"Use evidence"]}),r?a.jsx("div",{className:"rounded-[8px] border border-[var(--danger)]/20 bg-[var(--ui-danger-soft)] px-3 py-2 text-xs leading-5 text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]",children:r}):null]})}const ut={default:"bg-[color-mix(in_srgb,var(--primary)_14%,transparent)] text-[var(--primary)]",green:"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]",amber:"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_76%,var(--ui-ink-strong)_24%)]",rose:"bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]",cyan:"bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]"};function Y({label:e,value:t,detail:n,icon:r,tone:s="default",help:d,helpMaxWidthPx:g}){return a.jsxs(z,{className:"grid gap-4 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-5",children:[a.jsxs("div",{className:"flex items-center justify-between gap-3",children:[a.jsx("div",{className:oa("rounded-2xl p-2.5",ut[s]),children:a.jsx(r,{className:"size-5"})}),a.jsxs("div",{className:"flex items-center justify-end gap-1 text-right text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:[a.jsx("span",{children:e}),d?a.jsx(de,{content:d,label:`Explain ${e}`,maxWidthPx:g}):null]})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-3xl font-semibold text-[var(--ui-ink-strong)]",children:t}),a.jsx("p",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:n})]})]})}function gt({meal:e,onLogAgain:t,onEdit:n,onDelete:r,pending:s=!1}){const d=e.items[0]??null,g=Math.max(0,e.items.length-1),l=d?`${d.name}${g>0?` + ${g} more`:""}`:e.mealLabel??"Meal",o=e.items.slice(0,3).map(c=>{const w=Number.isFinite(c.quantity)&&c.quantity>0?Number.isInteger(c.quantity)?String(c.quantity):c.quantity.toFixed(2).replace(/\.?0+$/,""):null,b=c.unit??"serving",x=c.grams!=null?`${c.grams.toFixed(0)}g`:null;return[w,b,x?`(${x})`:null].filter(Boolean).join(" ")}).filter(Boolean).join(" · ");return a.jsxs(D,{className:"grid min-w-0 gap-3",children:[a.jsxs("div",{className:"flex min-w-0 flex-wrap items-start justify-between gap-3",children:[a.jsxs("div",{className:"min-w-0",children:[a.jsx("div",{className:"break-words text-base font-semibold leading-6 text-[var(--ui-ink-strong)]",children:l}),a.jsx("div",{className:"mt-1 text-xs leading-5 text-[var(--ui-ink-faint)]",children:o||e.notes||"No quantity recorded"})]}),a.jsxs("div",{className:"flex flex-wrap justify-end gap-2",children:[e.mealLabel?a.jsx($,{tone:"meta",children:e.mealLabel}):null,a.jsxs($,{tone:"meta",children:[e.totals.calories.toFixed(0)," kcal"]})]})]}),a.jsxs("div",{className:"grid gap-2 text-xs text-[var(--ui-ink-soft)] sm:grid-cols-3 xl:grid-cols-6",children:[a.jsxs("span",{children:[e.totals.proteinGrams.toFixed(0),"g protein"]}),a.jsxs("span",{children:[e.totals.carbohydrateGrams.toFixed(0),"g carbs"]}),a.jsxs("span",{children:[e.totals.fatGrams.toFixed(0),"g fat"]}),a.jsxs("span",{children:[e.totals.fiberGrams.toFixed(0),"g fiber"]}),a.jsxs("span",{children:[e.totals.sodiumMg.toFixed(0),"mg sodium"]}),a.jsx("span",{children:e.confirmationState})]}),a.jsxs("div",{className:"flex flex-wrap gap-2",children:[n?a.jsxs(K,{type:"button",size:"sm",variant:"secondary",onClick:()=>n(e),children:[a.jsx(Ta,{className:"size-4"}),"Edit"]}):null,r?a.jsxs(K,{type:"button",size:"sm",variant:"ghost",pending:s,onClick:()=>r(e),children:[a.jsx(sa,{className:"size-4"}),"Delete"]}):null,t?a.jsxs(K,{type:"button",size:"sm",variant:"ghost",pending:s,onClick:()=>t(e),children:[a.jsx(ra,{className:"size-4"}),"Log again"]}):null]})]})}function Ie({children:e}){return a.jsx(D,{className:"border-dashed border-[var(--ui-border-strong)] p-5 text-sm text-[var(--ui-ink-soft)]",children:e})}function mt({ledger:e,remainingCalories:t,intakePercent:n,logSavedPending:r,onLogAgain:s,onEditMeal:d,onDeleteMeal:g}){const l=e.totals;return a.jsxs(z,{className:"grid gap-5 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-5",children:[a.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Food log"}),a.jsxs("h2",{className:"mt-1 flex items-center gap-2 text-xl font-semibold text-[var(--ui-ink-strong)]",children:[a.jsx("span",{children:"Calories, macros, and meal evidence"}),a.jsx(de,{label:"Explain food log",content:"The food log is today's editable record of what was eaten. Edit a meal to change quantities, remove items, correct food parameters, or delete the meal entirely."})]})]}),a.jsxs($,{tone:"meta",children:[e.meals.length," meals"]})]}),a.jsxs("div",{children:[a.jsx("div",{className:"h-3 overflow-hidden rounded-full bg-[var(--ui-surface-2)]",children:a.jsx("div",{className:oa("h-full rounded-full",t>=0?"bg-[color-mix(in_srgb,var(--success)_82%,var(--secondary)_18%)]":"bg-[color-mix(in_srgb,var(--danger)_82%,var(--tertiary)_18%)]"),style:{width:`${Math.min(100,n)}%`}})}),a.jsxs("div",{className:"mt-3 grid gap-2 text-sm text-[var(--ui-ink-soft)] sm:grid-cols-4",children:[a.jsxs("span",{children:[l.carbohydrateGrams.toFixed(0),"g carbs"]}),a.jsxs("span",{children:[l.fatGrams.toFixed(0),"g fat"]}),a.jsxs("span",{children:[l.fiberGrams.toFixed(0),"g fiber"]}),a.jsxs("span",{children:[e.unconfirmedCount," unconfirmed"]})]})]}),a.jsx("div",{className:"grid gap-3",children:e.meals.length>0?e.meals.map(o=>a.jsx(gt,{meal:o,pending:r,onLogAgain:s,onEdit:d,onDelete:g},o.id)):a.jsx(Ie,{children:"No meals logged today yet."})})]})}function ht({hypotheses:e}){return a.jsxs(z,{className:"grid gap-4 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-5",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Hypotheses"}),a.jsx("h2",{className:"mt-1 text-xl font-semibold text-[var(--ui-ink-strong)]",children:"Food and body pattern candidates"})]}),a.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:e.length>0?e.slice(0,6).map((t,n)=>a.jsxs(D,{children:[a.jsxs("div",{className:"flex items-center justify-between gap-3",children:[a.jsx($,{tone:"signal",children:ie(t.metric)??"pattern"}),a.jsx("span",{className:"text-xs text-[var(--ui-ink-faint)]",children:i(t.confidence,2)})]}),a.jsx("div",{className:"mt-3 text-sm font-medium text-[var(--ui-ink-strong)]",children:ie(t.label)??"Candidate pattern"}),a.jsx("p",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:ie(t.description)??"Forge needs more paired meals and check-ins to harden this signal."})]},String(t.key??n))):a.jsx("div",{className:"md:col-span-2",children:a.jsx(Ie,{children:"Log meals plus energy, gut, and look check-ins for a few days to generate pattern candidates."})})})]})}function pt({experiments:e}){return a.jsxs(z,{className:"grid content-start gap-4 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-5",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"rounded-2xl bg-[var(--ui-info-soft)] p-2.5 text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]",children:a.jsx(Da,{className:"size-5"})}),a.jsxs("div",{children:[a.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Experiments"}),a.jsx("h2",{className:"text-xl font-semibold text-[var(--ui-ink-strong)]",children:"N-of-1 lab"})]})]}),a.jsxs("div",{className:"grid gap-3",children:[e.slice(0,4).map((t,n)=>a.jsxs(D,{children:[a.jsx("div",{className:"text-sm font-medium text-[var(--ui-ink-strong)]",children:ie(t.title)??"Nutrition experiment"}),a.jsx("p",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:ie(t.hypothesis)??ie(t.intervention)??"No hypothesis recorded."})]},String(t.id??n))),e.length===0?a.jsx(Ie,{children:"Start experiments from OpenClaw or the API: caffeine timing, fiber ramp, low-FODMAP trial, carb timing, sodium/puffiness, or pre-training fueling."}):null]})]})}function xt({view:e}){const t=e.dataQuality,n=e.todayLedger;return a.jsxs(z,{className:"grid gap-4 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-5",children:[a.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Data quality"}),a.jsx("h2",{className:"mt-1 text-xl font-semibold text-[var(--ui-ink-strong)]",children:"Confidence, coverage, and next evidence"})]}),a.jsxs($,{tone:"meta",children:[e.summary.dataQualityScore.toFixed(0),"% coverage"]})]}),a.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[a.jsx(bt,{label:"Source confidence",value:t.sourceConfidence,children:"Food parsing stays candidate-based until accepted; wearable burn is treated as a trend input."}),a.jsxs(D,{children:[a.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Missing check-ins"}),a.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:t.missingHighValueCheckins.length>0?t.missingHighValueCheckins.map(r=>a.jsx($,{tone:"signal",children:r},r)):a.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Core evidence loop is covered."})})]}),a.jsxs(D,{children:[a.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Next best cue"}),a.jsx("p",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:t.notes}),a.jsxs("div",{className:"mt-3 text-xs text-[var(--ui-ink-faint)]",children:[n.unconfirmedCount," unconfirmed candidate",n.unconfirmedCount===1?"":"s"]})]})]})]})}function bt({label:e,value:t,children:n}){return a.jsxs(D,{children:[a.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:e}),a.jsx("div",{className:"mt-2 text-lg font-semibold text-[var(--ui-ink-strong)]",children:t}),a.jsx("p",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:n})]})}function R(e,t,n){return a.jsxs("li",{className:"grid gap-0.5",children:[a.jsx("span",{className:"font-medium text-[var(--ui-ink)]",children:e}),a.jsx("code",{className:"rounded-[6px] bg-[var(--ui-surface-2)] px-1.5 py-0.5 font-mono text-[11px] text-[var(--ui-ink-soft)]",children:t}),n?a.jsx("span",{className:"text-xs text-[var(--ui-ink-faint)]",children:n}):null]})}function la({values:e,label:t="Show calorie and macro formulas"}){const r=((e==null?void 0:e.sex)??"male")==="male"?"+ 5":"- 161",s=(e==null?void 0:e.proteinFactor)!=null?`${e.proteinFactor.toFixed(1)}g/kg`:"1.6-2.0g/kg";return a.jsx(de,{label:t,title:"Weight Loss Formulas",maxWidthPx:520,panelClassName:"text-xs leading-5",content:a.jsxs("div",{className:"grid gap-3",children:[a.jsx("p",{children:"Forge keeps activity independent from the goal. The goal only adds a deficit, surplus, or zero adjustment to resting plus active calories."}),a.jsxs("ol",{className:"grid gap-2",children:[R("Mifflin-St Jeor BMR",`10 x weight kg + 6.25 x height cm - 5 x age ${r}`,`Current formula value: ${i(e==null?void 0:e.bmrKcal)} kcal/day.`),R("Resting calories","HealthKit basal/resting kcal when present, otherwise BMR",`Using: ${i(e==null?void 0:e.restingKcal)} kcal/day${e!=null&&e.restingSource?` (${e.restingSource})`:""}.`),R("Maintenance calories","resting calories + active calories",`${i(e==null?void 0:e.restingKcal)} + ${i(e==null?void 0:e.activeKcal)} = ${i(e==null?void 0:e.maintenanceKcal)} kcal/day.`),R("Objective adjustment","weekly change kg x 7700 kcal/kg / 7",`Weekly rate ${W(e==null?void 0:e.weeklyRateKg,2)} kg/week gives ${W(e==null?void 0:e.dailyAdjustmentKcal)} kcal/day.`),R("Daily calorie target","max(sex floor, maintenance + objective adjustment)",`Floor ${i(e==null?void 0:e.calorieFloor)} kcal; target ${i(e==null?void 0:e.calorieTarget)} kcal/day.`),R("Protein target",`min(reference weight x ${s}, 45% of kcal / 4)`,`Reference ${i(e==null?void 0:e.proteinReferenceWeightKg,1)} kg; target ${i(e==null?void 0:e.proteinGrams)} g/day.`),R("Fat target","saved plan fat when present; otherwise min(remaining kcal after protein, 35% kcal / 9, max(0.6g/kg reference, 25% kcal / 9))",`Target ${i(e==null?void 0:e.fatGrams)} g/day.`),R("Carbohydrate target","(calorie target - protein g x 4 - fat g x 9) / 4",`Target ${i(e==null?void 0:e.carbohydrateGrams)} g/day. The 130g DRI is shown as reference, not forced if it breaks calories.`),R("Fiber target","14g per 1000 kcal; adult sex/age AI shown as reference",`Target ${i(e==null?void 0:e.fiberGrams)} g/day; energy-adjusted ${i(e==null?void 0:e.fiberEnergyAdjustedGrams)} g/day; adult AI reference ${i(e==null?void 0:e.fiberDriGrams)} g/day.`),R("Sport-loss estimate","training hours ~= active kcal / 500; sweat ~= 0.4-0.8 L/h; sodium ~= 500-1000 mg/L","Shown as expected loss ranges, not rigid supplement instructions.")]})]})})}function ca(e,t){var r;if(!e)return null;const n=e.match(new RegExp(`${t}=([^;]+)`));return((r=n==null?void 0:n[1])==null?void 0:r.trim())??null}function ce(e,t){const n=typeof e=="string"?Number(e):A(e);return typeof n=="number"&&Number.isFinite(n)?n:t}function ft(e){return ca(e.target.notes,"sex")==="female"?"female":"male"}function vt(e){return ce(ca(e.target.notes,"age_years"),35)}function p(e,t,n,r,s,d){return{id:e,label:t,target:typeof n=="number"?Te(n):n,unit:r,note:s,source:d}}function Te(e){return Number.isFinite(e)?Math.abs(e)>=100?e.toFixed(0):e.toFixed(1).replace(/\.0$/,""):"n/a"}function se(e,t){return`${Te(e)}-${Te(t)}`}function yt(e,t,n,r){const s=Math.round(n/1e3*14);return r>0?r:s}function jt({calorieTarget:e,currentWeightKg:t,protein:n,savedFat:r}){const s=Math.max(0,(e-n*4)/9),d=Math.max(0,Math.min(s,e*.35/9,Math.max(t*.6,e*.25/9))),g=r??d;return{carbs:Math.max(0,(e-n*4-g*9)/4),fat:g}}function kt(e,t){return e==="male"?t>=51?14:17:t>=51?11:12}function Nt(e,t){const n=t>70,r=t>=51;return[p("vitamin_a","Vitamin A",e==="male"?900:700,"ug RAE","Retinol activity equivalent target.","NASEM DRI"),p("vitamin_c","Vitamin C",e==="male"?90:75,"mg","Adult RDA.","NASEM DRI"),p("vitamin_d","Vitamin D",n?20:15,"ug","Assumes limited sun exposure; older adults need more.","NASEM DRI"),p("vitamin_e","Vitamin E",15,"mg alpha-tocopherol","Adult RDA.","NASEM DRI"),p("vitamin_k","Vitamin K",e==="male"?120:90,"ug","Adult AI.","NASEM DRI"),p("thiamin_b1","Thiamin B1",e==="male"?1.2:1.1,"mg","Adult RDA.","NASEM DRI"),p("riboflavin_b2","Riboflavin B2",e==="male"?1.3:1.1,"mg","Adult RDA.","NASEM DRI"),p("niacin_b3","Niacin B3",e==="male"?16:14,"mg NE","Adult RDA.","NASEM DRI"),p("vitamin_b6","Vitamin B6",r?e==="male"?1.7:1.5:1.3,"mg","RDA rises after 50.","NASEM DRI"),p("folate","Folate",400,"ug DFE","Adult RDA.","NASEM DRI"),p("vitamin_b12","Vitamin B12",2.4,"ug","Adult RDA.","NASEM DRI"),p("pantothenic_acid","Pantothenic acid",5,"mg","Adult AI.","NASEM DRI"),p("biotin","Biotin",30,"ug","Adult AI.","NASEM DRI"),p("choline","Choline",e==="male"?550:425,"mg","Adult AI.","NASEM DRI")]}function wt(e,t){const n=t>70||e==="female"&&t>=51?1200:1e3,r=e==="male"?t>=31?420:400:t>=31?320:310,s=e==="male"?t>=51?30:35:t>=51?20:25,d=t>=71?1800:t>=51?2e3:2300;return[p("calcium","Calcium",n,"mg","Bone and muscle target; higher for older adults and women 51+.","NASEM DRI"),p("iron","Iron",e==="female"&&t<=50?18:8,"mg","Menstruating-age female target is higher.","NASEM DRI"),p("magnesium","Magnesium",r,"mg","Adult RDA.","NASEM DRI"),p("phosphorus","Phosphorus",700,"mg","Adult RDA.","NASEM DRI"),p("zinc","Zinc",e==="male"?11:8,"mg","Adult RDA.","NASEM DRI"),p("iodine","Iodine",150,"ug","Adult RDA.","NASEM DRI"),p("selenium","Selenium",55,"ug","Adult RDA.","NASEM DRI"),p("copper","Copper",.9,"mg","Adult RDA.","NASEM DRI"),p("manganese","Manganese",e==="male"?2.3:1.8,"mg","Adult AI.","NASEM DRI"),p("chromium","Chromium",s,"ug","Adult AI.","NASEM DRI"),p("molybdenum","Molybdenum",45,"ug","Adult RDA.","NASEM DRI"),p("fluoride","Fluoride",e==="male"?4:3,"mg","Adult AI.","NASEM DRI"),p("chloride","Chloride",d,"mg","Adult AI.","NASEM DRI"),p("potassium","Potassium",e==="male"?3400:2600,"mg","Current adult AI for non-pregnant adults.","NASEM DRI"),p("sodium_limit","Sodium ceiling",2300,"mg max","Default daily ceiling unless medically individualized.","U.S. Dietary Guidelines")]}function Ct(e){const t=ft(e),n=vt(e),r=ce(e.weightTrend.latestWeightKg,80),s=Math.max(1,ce(e.target.calorieTarget,2200)),d=ce(e.target.proteinGramsTarget,r*1.8),{carbs:g,fat:l}=jt({calorieTarget:s,currentWeightKg:r,protein:d,savedFat:A(e.target.fatGramsTarget)}),o=yt(t,n,s,ce(e.target.fiberGramsTarget,0)),c=A(e.energyModel.activeBurnKcal)??A(e.energyModel.activeEnergyCalories)??null,w=A(e.energyModel.movementCaloriesKcal),b=A(e.energyModel.restingEnergyCalories);return da({sex:t,ageYears:n,currentWeightKg:r,calorieTarget:s,proteinGramsTarget:d,carbohydrateGramsTarget:g,fatGramsTarget:l,fiberGramsTarget:o,activeBurnKcal:c,movementCaloriesKcal:w,restingEnergyKcal:b})}function da(e){const{sex:t,ageYears:n,currentWeightKg:r,calorieTarget:s,proteinGramsTarget:d,carbohydrateGramsTarget:g,fatGramsTarget:l,fiberGramsTarget:o,activeBurnKcal:c,movementCaloriesKcal:w,restingEnergyKcal:b}=e,x=c!=null?Math.min(4,Math.max(.1,c/500)):null,m=x!=null?x*.4:null,S=x!=null?x*.8:null,E=m!=null?m*500:null,M=S!=null?S*1e3:null,_=m!=null?m*78:null,T=S!=null?S*312:null,L=c!=null?c*7/7700:null;return{profile:{sex:t,ageYears:n,currentWeightKg:r,calorieTarget:s,activeBurnKcal:c,movementCaloriesKcal:w,restingEnergyKcal:b},macros:[p("calories","Calories",s,"kcal","Plan target from BMR, active burn, and chosen weekly rate.","Forge plan"),p("protein","Protein",d,"g","Higher than the population RDA to preserve lean mass during weight change.","ISSN + Forge plan"),p("carbohydrate","Carbohydrate",g,"g","Remaining fuel after protein and fat. It may sit below the 130g/day adult DRI reference when needed to preserve the calorie target.","NASEM DRI + Forge plan"),p("fat","Total fat",l,"g","Uses the saved plan fat target when present; generated defaults aim for a practical floor around 0.6g/kg or 20-35% of calories when possible.","NASEM AMDR + Forge plan"),p("fiber","Fiber",o,"g","Uses 14g per 1000 kcal as the plan target; the sex/age adult AI remains a reference or stretch value when calories are low.","NASEM DRI"),p("saturated_fat","Saturated fat",s*.1/9,"g max","Keep below 10% of energy.","U.S. Dietary Guidelines"),p("added_sugar","Added sugar",s*.1/4,"g max","Keep below 10% of energy; lower is better when feasible.","U.S. Dietary Guidelines"),p("linoleic_acid","Linoleic acid",kt(t,n),"g","Essential n-6 fatty acid AI.","NASEM DRI"),p("ala","ALA omega-3",t==="male"?1.6:1.1,"g","Essential n-3 fatty acid AI.","NASEM DRI"),p("water","Total water",t==="male"?3.7:2.7,"L","All beverages and food water before extra training replacement.","NASEM DRI")],vitamins:Nt(t,n),minerals:wt(t,n),sportLosses:[p("training_time","Estimated training time",x??"n/a","h/day","Derived from active burn at roughly 500 kcal/h.","Forge sport-loss model"),p("sweat_fluid","Expected sweat fluid",m!=null&&S!=null?se(m,S):"n/a","L/day","Planning range uses 0.4-0.8 L/h; measure body mass change to calibrate.","ACSM"),p("sweat_sodium","Expected sweat sodium",E!=null&&M!=null?se(E,M):"n/a","mg/day","Sodium varies widely; this uses a conservative range around common sweat sodium values.","ACSM + Sports Medicine review"),p("sweat_potassium","Expected sweat potassium",_!=null&&T!=null?se(_,T):"n/a","mg/day","Potassium is usually much smaller than sodium but useful for long/hot sessions.","Sports Medicine review"),p("gross_sport_equivalent","Gross sport burn equivalent",L??"n/a","kg/week","Energy equivalent if the active burn were not eaten back; the plan may already include it.","7700 kcal/kg model")],sportSummary:{trainingHours:x,fluidLossLiters:m!=null&&S!=null?se(m,S):"n/a",sodiumLossMg:E!=null&&M!=null?se(E,M):"n/a",potassiumLossMg:_!=null&&T!=null?se(_,T):"n/a",grossSportWeightEquivalentKgPerWeek:L}}}function Ae({rows:e,compact:t=!1}){return a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"grid gap-2 md:hidden",children:e.map(n=>a.jsxs("div",{className:"grid min-w-0 gap-2 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-3",children:[a.jsxs("div",{className:"flex min-w-0 items-start justify-between gap-3",children:[a.jsx("div",{className:"min-w-0 break-words text-sm font-semibold text-[var(--ui-ink)]",children:n.label}),a.jsxs("div",{className:"shrink-0 text-right text-sm font-semibold text-[var(--ui-ink)]",children:[n.target,a.jsx("div",{className:"text-xs font-normal text-[var(--ui-ink-faint)]",children:n.unit})]})]}),a.jsx("p",{className:"min-w-0 break-words text-xs leading-5 text-[var(--ui-ink-muted)]",children:n.note}),t?null:a.jsx($,{tone:"meta",wrap:!0,className:"justify-self-start",children:n.source})]},n.id))}),a.jsx("div",{className:"hidden overflow-hidden rounded-[20px] border border-[var(--ui-border-subtle)] md:block",children:a.jsx("div",{className:"max-h-[460px] overflow-auto",children:a.jsxs("table",{className:"w-full min-w-[620px] border-collapse text-left text-sm",children:[a.jsx("thead",{className:"sticky top-0 bg-[var(--ui-surface-2)] text-xs uppercase text-[var(--ui-ink-faint)]",children:a.jsxs("tr",{children:[a.jsx("th",{className:"px-4 py-3 font-semibold",children:"Target"}),a.jsx("th",{className:"px-4 py-3 font-semibold",children:"Amount"}),a.jsx("th",{className:"px-4 py-3 font-semibold",children:"Rationale"}),t?null:a.jsx("th",{className:"px-4 py-3 font-semibold",children:"Source"})]})}),a.jsx("tbody",{className:"divide-y divide-[var(--ui-border-subtle)]",children:e.map(n=>a.jsxs("tr",{className:"bg-[var(--ui-surface-1)]",children:[a.jsx("td",{className:"px-4 py-3 font-medium text-[var(--ui-ink)]",children:n.label}),a.jsxs("td",{className:"px-4 py-3 text-[var(--ui-ink)]",children:[a.jsx("span",{className:"font-semibold",children:n.target})," ",a.jsx("span",{className:"text-[var(--ui-ink-faint)]",children:n.unit})]}),a.jsx("td",{className:"px-4 py-3 text-[var(--ui-ink-muted)]",children:n.note}),t?null:a.jsx("td",{className:"px-4 py-3",children:a.jsx($,{tone:"meta",children:n.source})})]},n.id))})]})})})]})}function le({title:e,description:t,children:n}){return a.jsxs(D,{children:[a.jsxs("div",{className:"mb-4",children:[a.jsx("h3",{className:"text-sm font-semibold text-[var(--ui-ink)]",children:e}),a.jsx("p",{className:"mt-1 text-sm text-[var(--ui-ink-muted)]",children:t})]}),n]})}function Ft({view:e}){const t=Ct(e),n=e.target.weeklyRateGoalKg??null,r=n!=null&&Number.isFinite(n)?n*7700/7:null,s=t.profile.restingEnergyKcal,d=t.profile.activeBurnKcal,g=s!=null&&d!=null?s+d:null,l=e.target.bodyGoal??"maintain",o=l.includes("lose")?2:l.includes("gain")?1.8:1.6,c=m=>{var M;const S=(M=t.macros.find(_=>_.id===m))==null?void 0:M.target,E=Number(S);return Number.isFinite(E)?E:null},w=t.profile.sex==="male"?t.profile.ageYears>=51?30:38:t.profile.ageYears>=51?21:25,b=Math.round(t.profile.calorieTarget/1e3*14),x=t.sportSummary.grossSportWeightEquivalentKgPerWeek!=null?`${t.sportSummary.grossSportWeightEquivalentKgPerWeek.toFixed(2)} kg/week`:"n/a";return a.jsx("section",{className:"grid gap-4",children:a.jsxs(z,{className:"p-5",children:[a.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-[var(--ui-ink)]",children:[a.jsx(Ia,{className:"size-4 text-[var(--ui-accent)]"}),"Macro And Micronutrient Targets",a.jsx(la,{values:{sex:t.profile.sex,ageYears:t.profile.ageYears,currentWeightKg:t.profile.currentWeightKg,bmrKcal:null,restingKcal:s,restingSource:s!=null?"saved HealthKit basal/resting or plan value":null,activeKcal:d,maintenanceKcal:g,weeklyRateKg:n,dailyAdjustmentKcal:r,calorieTarget:t.profile.calorieTarget,calorieFloor:t.profile.sex==="male"?1500:1200,proteinReferenceWeightKg:null,proteinFactor:o,proteinGrams:c("protein"),fatGrams:c("fat"),carbohydrateGrams:c("carbohydrate"),fiberGrams:c("fiber"),fiberEnergyAdjustedGrams:b,fiberDriGrams:w}})]}),a.jsx("p",{className:"mt-1 max-w-3xl text-sm text-[var(--ui-ink-muted)]",children:"Daily targets use Forge plan values first, then adult DRI/Dietary Guidelines defaults for nutrients the food log can score as catalog detail improves."})]}),a.jsxs("div",{className:"flex flex-wrap gap-2",children:[a.jsxs($,{tone:"signal",children:[t.profile.calorieTarget.toFixed(0)," kcal"]}),a.jsxs($,{tone:"meta",children:[t.profile.sex,", ",t.profile.ageYears.toFixed(0),"y"]})]})]}),a.jsxs("div",{className:"mt-5 grid gap-4 2xl:grid-cols-[minmax(0,1fr)_minmax(320px,0.58fr)]",children:[a.jsxs("div",{className:"grid gap-4",children:[a.jsx(le,{title:"All macro targets",description:"Calories, protein, carbs, fat, fiber, sugar ceiling, saturated fat ceiling, essential fats, and water.",children:a.jsx(Ae,{rows:t.macros,compact:!0})}),a.jsx(le,{title:"Vitamins",description:"Adult daily vitamin targets from DRI values, adjusted for sex and age where the reference differs.",children:a.jsx(Ae,{rows:t.vitamins})})]}),a.jsxs("div",{className:"grid content-start gap-4",children:[a.jsxs(le,{title:"Expected sport losses",description:"Planning range from active burn. Calibrate with pre/post workout weight when possible.",children:[a.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[a.jsx(N,{label:"Active burn",value:t.profile.activeBurnKcal!=null?`${t.profile.activeBurnKcal.toFixed(0)} kcal`:"n/a"}),a.jsx(N,{label:"Sport equivalent",value:x}),a.jsx(N,{label:"Sweat fluid",value:`${t.sportSummary.fluidLossLiters} L`}),a.jsx(N,{label:"Sodium loss",value:`${t.sportSummary.sodiumLossMg} mg`})]}),a.jsxs("div",{className:"mt-4 flex items-start gap-3 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-3 text-sm text-[var(--ui-ink-muted)]",children:[a.jsx(ia,{className:"mt-0.5 size-4 shrink-0 text-[var(--ui-accent)]"}),a.jsx("span",{children:"Sport burn is shown as gross energy equivalent, not a promise of scale loss. The calorie plan may already include active burn, and replacement depends on appetite, heat, sodium loss, and actual intake."})]})]}),a.jsx(le,{title:"Minerals & oligoelements",description:"Daily mineral and trace-element targets including sodium ceiling and potassium AI.",children:a.jsx(Ae,{rows:t.minerals,compact:!0})}),a.jsx(le,{title:"Sport electrolyte model",description:"Use these as expected losses, not rigid supplement prescriptions.",children:a.jsx("div",{className:"grid gap-3",children:t.sportLosses.map(m=>a.jsxs("div",{className:"flex items-start justify-between gap-3 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-3",children:[a.jsxs("div",{className:"min-w-0",children:[a.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-[var(--ui-ink)]",children:[m.id==="sweat_fluid"?a.jsx(La,{className:"size-4 text-[var(--ui-accent)]"}):a.jsx(Pa,{className:"size-4 text-[var(--ui-accent)]"}),m.label]}),a.jsx("p",{className:"mt-1 text-xs text-[var(--ui-ink-faint)]",children:m.note})]}),a.jsxs("div",{className:"shrink-0 text-right text-sm font-semibold text-[var(--ui-ink)]",children:[m.target,a.jsx("div",{className:"text-xs font-normal text-[var(--ui-ink-faint)]",children:m.unit})]})]},m.id))})})]})]})]})})}function ee(e,t){var r;if(!e)return null;const n=e.match(new RegExp(`${t}=([^;]+)`));return((r=n==null?void 0:n[1])==null?void 0:r.trim())??null}function ae(e){const t=typeof e=="number"?e:Number(e);return Number.isFinite(t)&&t>0?t:null}function ua(e,t){if(t==="maintain")return 0;const n=t==="gain"?.0025:.005,r=t==="gain"?.1:.2,s=t==="gain"?.35:Math.max(.5,e*.01);return Math.min(s,Math.max(r,e*n))}function ga(e,t){return t==="gain"?e*1.03:t==="maintain"?e:e*.95}function ma(e){return e.toFixed(1)}function Mt(e,t){return e==="male"?t>=51?30:38:t>=51?21:25}function Ze(e,t){const n=e/100;return n>0?t*n*n:null}function Gt(e){const t=e.goalMode==="lose"&&e.goalWeightKg!=null?Math.min(e.currentWeightKg,e.goalWeightKg):e.currentWeightKg,n=Ze(e.heightCm,30),r=Ze(e.heightCm,25);if(n!=null&&r!=null&&e.currentWeightKg>n){const s=r+(e.currentWeightKg-r)*.25;return Math.min(t,s)}return t}function St(e,t){const n=ae(e.currentWeightKg)??80;return{...e,goalMode:t,goalWeightKg:ma(ga(n,t)),weeklyRateKg:ua(n,t).toFixed(2)}}function Ee(e){const t=A(e.weightTrend.latestWeightKg),n=e.target,r=ee(n.notes,"sex"),s=ee(n.notes,"age_years"),d=ee(n.notes,"height_cm"),g=A(e.energyModel.activeBurnKcal)??A(e.energyModel.activeEnergyCalories)??A(e.energyModel.movementCaloriesKcal)??A(ee(n.notes,"activity_kcal"))??0,l=A(e.energyModel.restingEnergyCalories)??A(ee(n.notes,"resting_kcal"))??null,o=n.bodyGoal??"",c=o.includes("gain")?"gain":o.includes("maintain")?"maintain":"lose",w=n.weightGoalKg??n.goalBodyWeightKg??null,b=t??80;return{goalMode:c,sex:r==="female"?"female":"male",ageYears:ae(s)?String(s):"",heightCm:ae(d)?String(d):"",currentWeightKg:t?t.toFixed(1):"",goalWeightKg:w?String(w):ma(ga(b,c)),weeklyRateKg:n.weeklyRateGoalKg!==null&&n.weeklyRateGoalKg!==void 0?String(Math.abs(n.weeklyRateGoalKg)):ua(b,c).toFixed(2),activeCaloriesKcal:g.toFixed(0),restingCaloriesKcal:l!=null?l.toFixed(0):"",dietStyle:n.dietStyle??""}}function Kt(e){const t=ae(ee(e.target.notes,"age_years"))!=null,n=ae(ee(e.target.notes,"height_cm"))!=null,r=A(e.weightTrend.latestWeightKg)!=null,s=typeof e.target.bodyGoal=="string"&&e.target.bodyGoal.trim().length>0&&e.target.calorieTarget>0&&e.target.proteinGramsTarget>0;return t&&n&&r&&s}function At(e){const t=e.energyModel;return`This is the default active allowance used when today has no same-day workout, movement, step, or active-energy evidence. ${t.energySourceConfidence==="healthkit_daily_active_energy"?"HealthKit daily active energy is the active-burn source; workout and movement values are only visible evidence and are not added again.":t.energySourceConfidence==="workout_movement_fallback"?"HealthKit daily active energy is missing, so active burn already equals workout average plus movement-trip average.":"No measured active-burn stream is available, so Forge is using the plan/default estimate."} Current evidence: active burn ${i(t.activeBurnKcal)} kcal/day, workout average ${i(t.workoutEnergyKcal)} kcal/day, movement average ${i(t.movementCaloriesKcal)} kcal/day, today's workout ${i(t.todayWorkoutEnergyKcal)} kcal, today's movement ${i(t.todayMovementCaloriesKcal)} kcal.`}function ha(e){const t=Number(e.currentWeightKg)||80,n=Number(e.heightCm)||178,r=Number(e.ageYears)||35,s=ae(e.goalWeightKg),d=Math.max(0,Number(e.activeCaloriesKcal)||0),g=ae(e.restingCaloriesKcal),l=e.sex==="male"?5:-161,o=10*t+6.25*n-5*r+l,c=g??o,w=c+d,b=Math.abs(Number(e.weeklyRateKg)||0),x=e.goalMode==="lose"?-b:e.goalMode==="gain"?b:0,m=x*7700/7,S=e.sex==="male"?1500:1200,E=Math.round(w+m),M=Math.max(S,E),_=Gt({currentWeightKg:t,goalWeightKg:s,heightCm:n,goalMode:e.goalMode}),T=e.goalMode==="lose"?2:e.goalMode==="gain"?1.8:1.6,L=Math.round(_*T),B=Math.floor(M*.45/4),P=Math.max(1,Math.min(L,B)),H=_*.6,te=M*.25/9,J=Math.max(0,(M-P*4)/9),O=Math.max(0,Math.floor(Math.min(J,M*.35/9,Math.max(H,te)))),U=Math.max(0,Math.floor((M-P*4-O*9)/4)),ne=Math.round(M/1e3*14),re=Mt(e.sex,r),oe=ne,Z=Math.round(M*.1/9),Q=Math.round(M*.1/4);return{bmr:Math.round(o),restingCalories:Math.round(c),restingSource:g!=null?"HealthKit basal/resting":"Mifflin-St Jeor",activeCalories:Math.round(d),maintenanceCalories:Math.round(w),plannedCalorieTarget:E,minimumCalorieFloor:S,weeklyRateGoalKg:x,dailyEnergyAdjustment:Math.round(m),calorieTarget:M,proteinReferenceWeight:Math.round(_*10)/10,proteinGramsTarget:P,carbohydrateGramsTarget:U,fatGramsTarget:O,fiberGramsTarget:oe,fiberEnergyAdjustedGrams:ne,fiberDriGrams:re,saturatedFatLimitGrams:Z,addedSugarLimitGrams:Q}}function Et(e){const t=[],n=Number(e.ageYears),r=Number(e.heightCm),s=Number(e.currentWeightKg),d=Number(e.goalWeightKg),g=Number(e.weeklyRateKg),l=e.activeCaloriesKcal.trim()?Number(e.activeCaloriesKcal):Number.NaN,o=e.restingCaloriesKcal.trim()?Number(e.restingCaloriesKcal):null;return(!Number.isFinite(n)||n<13||n>100)&&t.push("- Enter the user's real age. Forge uses it in Mifflin-St Jeor resting metabolism."),(!Number.isFinite(r)||r<120||r>230)&&t.push("- Enter height in cm. Height changes BMR and protein reference weight."),(!Number.isFinite(s)||s<30||s>300)&&t.push("- Enter current weight in kg. Use the latest known body measure as the starting state."),e.goalMode!=="maintain"&&(!Number.isFinite(d)||d<30||d>300)&&t.push("- Enter a target weight for the selected loss or gain objective."),(!Number.isFinite(g)||g<0)&&t.push("- Enter a non-negative weekly change rate in kg/week."),Number.isFinite(g)&&g>Math.max(1.5,s*.02)&&t.push("- The weekly rate is very aggressive. Choose a slower default unless this is a supervised plan."),(!Number.isFinite(l)||l<0||l>3e3)&&t.push("- Enter average active calories per day. Zero is valid only when Forge has no activity evidence."),o!=null&&(!Number.isFinite(o)||o<900||o>3500)&&t.push("- Resting calories should be blank for formula mode or a plausible HealthKit basal/resting value."),t.length>0?t.join(`
|
|
2
2
|
`):null}function _t(e){const t=ha(e),n=Number(e.goalWeightKg);return{calorieTarget:t.calorieTarget,proteinGramsTarget:t.proteinGramsTarget,fiberGramsTarget:t.fiberGramsTarget,carbohydrateGramsTarget:t.carbohydrateGramsTarget,fatGramsTarget:t.fatGramsTarget,weightGoalKg:Number.isFinite(n)?n:null,weeklyRateGoalKg:t.weeklyRateGoalKg,dietStyle:e.dietStyle,bodyGoal:e.goalMode,notes:["Forge science plan",`height_cm=${Number(e.heightCm)||"unknown"}`,`age_years=${Number(e.ageYears)||"unknown"}`,`sex=${e.sex}`,"bmr_formula=Mifflin-St Jeor",`resting_kcal=${t.restingCalories}`,`activity_kcal=${t.activeCalories}`,`maintenance_kcal=${t.maintenanceCalories}`,"rate_model=7700 kcal/kg"].join("; ")}}function $t({open:e,onOpenChange:t,view:n,value:r,onChange:s,onSubmit:d,pending:g,error:l}){const o=F.useMemo(()=>ha(r),[r]),c=F.useMemo(()=>da({sex:r.sex,ageYears:Number(r.ageYears)||35,currentWeightKg:Number(r.currentWeightKg)||80,calorieTarget:o.calorieTarget,proteinGramsTarget:o.proteinGramsTarget,carbohydrateGramsTarget:o.carbohydrateGramsTarget,fatGramsTarget:o.fatGramsTarget,fiberGramsTarget:o.fiberGramsTarget,activeBurnKcal:o.activeCalories,movementCaloriesKcal:A(n.energyModel.movementCaloriesKcal),restingEnergyKcal:o.restingCalories}),[o,r,n.energyModel.movementCaloriesKcal]),w=[{id:"profile",eyebrow:"Current state",title:"Confirm the body data Forge knows",description:"These fields drive resting metabolism. Saved values are reused when Forge has them.",render:(b,x)=>a.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[a.jsx(y,{label:"Sex",children:a.jsx(Ve,{value:b.sex,onChange:m=>x({sex:m}),options:[{value:"male",label:"Male"},{value:"female",label:"Female"}]})}),a.jsx(y,{label:"Age",children:a.jsx(k,{inputMode:"numeric",value:b.ageYears,onChange:m=>x({ageYears:m.target.value}),placeholder:"35"})}),a.jsx(y,{label:"Height cm",children:a.jsx(k,{inputMode:"decimal",value:b.heightCm,onChange:m=>x({heightCm:m.target.value}),placeholder:"178"})}),a.jsx(y,{label:"Current weight kg",children:a.jsx(k,{inputMode:"decimal",value:b.currentWeightKg,onChange:m=>x({currentWeightKg:m.target.value}),placeholder:"80.0"})})]})},{id:"objective",eyebrow:"Goal",title:"Choose what should happen next",description:"Forge proposes a default target and weekly rate from current weight; you can change both.",render:(b,x)=>a.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[a.jsx("div",{className:"md:col-span-2",children:a.jsx(Ve,{columns:3,value:b.goalMode,onChange:m=>x(St(b,m)),options:[{value:"lose",label:"Lose fat",description:"Default: about 0.5% body weight per week."},{value:"gain",label:"Gain mass",description:"Default: small surplus around 0.25% per week."},{value:"maintain",label:"Maintain",description:"Hold weight while optimizing signals."}]})}),a.jsx(y,{label:"Target weight kg",hint:"Filled from the objective; change it anytime.",children:a.jsx(k,{inputMode:"decimal",value:b.goalWeightKg,onChange:m=>x({goalWeightKg:m.target.value}),placeholder:"75.0"})}),a.jsx(y,{label:"Weekly change kg",hint:"Loss/gain rate is converted to kcal/day with the 7700 kcal/kg planning model.",children:a.jsx(k,{inputMode:"decimal",value:b.weeklyRateKg,onChange:m=>x({weeklyRateKg:m.target.value}),placeholder:"0.35"})})]})},{id:"activity",eyebrow:"Activity",title:"Add active burn to resting burn",description:"Active calories are independent evidence from HealthKit, workouts, and movement. The objective only changes the deficit or surplus.",render:(b,x)=>a.jsxs("div",{className:"grid gap-4",children:[a.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[a.jsx(y,{label:"Resting calories/day",hint:`Forge uses HealthKit basal energy when present, otherwise Mifflin-St Jeor BMR. Current formula value: ${o.bmr} kcal.`,children:a.jsx(k,{inputMode:"decimal",value:b.restingCaloriesKcal,onChange:m=>x({restingCaloriesKcal:m.target.value}),placeholder:String(o.bmr)})}),a.jsx(y,{label:"Average active calories/day",hint:At(n),children:a.jsx(k,{inputMode:"decimal",value:b.activeCaloriesKcal,onChange:m=>x({activeCaloriesKcal:m.target.value}),placeholder:"350"})})]}),a.jsxs("div",{className:"grid gap-3 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4 md:grid-cols-3",children:[a.jsx(N,{label:o.restingSource,value:`${o.restingCalories} kcal`}),a.jsx(N,{label:"Maintenance",value:`${o.maintenanceCalories} kcal`}),a.jsx(N,{label:"Daily adjustment",value:`${o.dailyEnergyAdjustment>0?"+":""}${o.dailyEnergyAdjustment} kcal`})]})]})},{id:"macros",eyebrow:"Macros",title:"Validate calories, macros, and limits",description:"Target intake equals resting burn plus active burn plus the objective adjustment. Macros are generated from protein-per-kg, a practical fat floor, remaining carbohydrates, fiber density, and dietary limits.",render:(b,x)=>a.jsxs("div",{className:"grid gap-4",children:[a.jsxs("div",{className:"flex items-start justify-between gap-3 rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3",children:[a.jsx("div",{className:"min-w-0 text-sm leading-6 text-[var(--ui-ink-muted)]",children:"Inspect the exact math behind the current calories, macro targets, and sport-loss preview."}),a.jsx(la,{values:{sex:b.sex,ageYears:Number(b.ageYears)||null,currentWeightKg:Number(b.currentWeightKg)||null,heightCm:Number(b.heightCm)||null,bmrKcal:o.bmr,restingKcal:o.restingCalories,restingSource:o.restingSource,activeKcal:o.activeCalories,maintenanceKcal:o.maintenanceCalories,weeklyRateKg:o.weeklyRateGoalKg,dailyAdjustmentKcal:o.dailyEnergyAdjustment,calorieTarget:o.calorieTarget,calorieFloor:o.minimumCalorieFloor,proteinReferenceWeightKg:o.proteinReferenceWeight,proteinFactor:b.goalMode==="lose"?2:b.goalMode==="gain"?1.8:1.6,proteinGrams:o.proteinGramsTarget,fatGrams:o.fatGramsTarget,carbohydrateGrams:o.carbohydrateGramsTarget,fiberGrams:o.fiberGramsTarget,fiberEnergyAdjustedGrams:o.fiberEnergyAdjustedGrams,fiberDriGrams:o.fiberDriGrams}})]}),a.jsxs("div",{className:"grid gap-3 md:grid-cols-4 xl:grid-cols-7",children:[a.jsx(N,{label:"Calories",value:`${o.calorieTarget}`}),a.jsx(N,{label:"Protein",value:`${o.proteinGramsTarget}g`}),a.jsx(N,{label:"Carbs",value:`${o.carbohydrateGramsTarget}g`}),a.jsx(N,{label:"Fat",value:`${o.fatGramsTarget}g`}),a.jsx(N,{label:"Fiber",value:`${o.fiberGramsTarget}g`}),a.jsx(N,{label:"Sat fat max",value:`${o.saturatedFatLimitGrams}g`}),a.jsx(N,{label:"Added sugar max",value:`${o.addedSugarLimitGrams}g`})]}),a.jsxs("div",{className:"grid gap-4 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[a.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-sm font-semibold text-[var(--ui-ink)]",children:"Micronutrient and sport-loss preview"}),a.jsx("div",{className:"mt-1 text-sm leading-6 text-[var(--ui-ink-muted)]",children:"The dashboard will track vitamin, mineral, trace-element, water, sodium-ceiling, essential-fat, and sport-loss targets from this plan."})]}),a.jsxs("div",{className:"flex flex-wrap gap-2",children:[a.jsxs($,{tone:"meta",children:[c.vitamins.length," vitamins"]}),a.jsxs($,{tone:"meta",children:[c.minerals.length," minerals"]}),a.jsxs($,{tone:"signal",children:[c.sportSummary.fluidLossLiters," L sweat"]})]})]}),a.jsxs("div",{className:"grid gap-3 md:grid-cols-4",children:[a.jsx(N,{label:"Sport sodium loss",value:`${c.sportSummary.sodiumLossMg} mg`}),a.jsx(N,{label:"Sport potassium loss",value:`${c.sportSummary.potassiumLossMg} mg`}),a.jsx(N,{label:"Water baseline",value:r.sex==="male"?"3.7 L":"2.7 L"}),a.jsx(N,{label:"Essential fats",value:r.sex==="male"?"17g LA / 1.6g ALA":"12g LA / 1.1g ALA"})]})]}),a.jsx(y,{label:"Diet style or constraints",children:a.jsx(ve,{value:b.dietStyle,onChange:m=>x({dietStyle:m.target.value}),placeholder:"Mediterranean, high protein, no lactose, low FODMAP trial..."})})]})}];return a.jsx(je,{open:e,onOpenChange:t,eyebrow:"Weight plan",title:"Set weight objective",description:"Build an editable calorie and macro plan.",value:r,onChange:s,steps:w,onSubmit:d,submitLabel:"Save plan",pending:g,pendingLabel:"Saving plan",error:l,draftPersistenceKey:"weight-loss-plan"})}const Tt={tsp:5,tbsp:15,cup:240};function fe(){return{mealLabel:"Meal",notes:"",source:"search",selectedItems:[]}}function G(e,t,n){return typeof e!="number"||!Number.isFinite(e)?null:xa(n)==="grams"?e:t>0?Math.round(e/t*10)/10:e}function Dt(e){const t=Number.isFinite(e.quantity)&&e.quantity>0?e.quantity:1,n=e.unit??"serving",r=n==="grams"?e.grams??t:e.grams!=null&&t>0?e.grams/t:e.grams;return{id:e.foodId??e.id,source:"saved_meal",sourceId:e.foodId??e.id,name:e.name,brand:e.brand??null,barcode:null,servingLabel:n,servingGrams:r??null,calories:G(e.calories,t,n),proteinGrams:G(e.proteinGrams,t,n),carbohydrateGrams:G(e.carbohydrateGrams,t,n),fatGrams:G(e.fatGrams,t,n),fiberGrams:G(e.fiberGrams,t,n),sugarGrams:G(e.sugarGrams,t,n),sodiumMg:G(e.sodiumMg,t,n),potassiumMg:G(e.potassiumMg,t,n),caffeineMg:G(e.caffeineMg,t,n),alcoholGrams:G(e.alcoholGrams,t,n),glycemicIndex:e.glycemicIndex??null,novaGroup:e.novaGroup??null,tags:e.tags??[],confidence:e.confidence??null}}function It(e,t,n){const r=Number.isFinite(e.quantity)&&e.quantity>0?e.quantity:1,s=e.unit??"serving",d=s==="grams"||s==="g"?e.grams??r:e.grams!=null&&r>0?e.grams/r:e.grams;return{id:e.foodId??`${n}_${t}_${Date.now()}`,source:n,sourceId:e.foodId??null,name:e.name,brand:e.brand??null,barcode:null,servingLabel:s,servingGrams:d??null,calories:G(e.calories,r,s),proteinGrams:G(e.proteinGrams,r,s),carbohydrateGrams:G(e.carbohydrateGrams,r,s),fatGrams:G(e.fatGrams,r,s),fiberGrams:G(e.fiberGrams,r,s),sugarGrams:G(e.sugarGrams,r,s),sodiumMg:G(e.sodiumMg,r,s),potassiumMg:G(e.potassiumMg,r,s),caffeineMg:G(e.caffeineMg,r,s),alcoholGrams:G(e.alcoholGrams,r,s),glycemicIndex:e.glycemicIndex??null,novaGroup:e.novaGroup??null,tags:e.tags??[],confidence:e.confidence??null}}function Lt(e){if(!e)return null;const n=e.toLowerCase().replace(",",".").match(/(\d+(?:\.\d+)?)\s*(kg|g|gram|grams|ml|l)\b/);if(!n)return null;const r=Number(n[1]);if(!Number.isFinite(r)||r<=0)return null;const s=n[2];return s==="kg"||s==="l"?r*1e3:r}function ue(e){return typeof e.servingGrams=="number"&&Number.isFinite(e.servingGrams)&&e.servingGrams>0?e.servingGrams:Lt(e.servingLabel)}function Pt(e){const t=ue(e);return t!=null?`${i(t)} g`:e.servingLabel??"serving"}function pa(e){const t=Number(e.amount)||0;if(t<=0)return null;const n=ue(e.food);return e.unit==="grams"?t:e.unit==="tsp"||e.unit==="tbsp"||e.unit==="cup"?t*Tt[e.unit]:n!=null?t*n:null}function Xe(e){return!(e.unit==="grams"||e.unit==="tsp"||e.unit==="tbsp"||e.unit==="cup")||ue(e.food)!=null?null:"Add base grams before using grams or household measures. Without a denominator, Forge will not guess a ratio."}function xa(e){const t=e==null?void 0:e.trim().toLowerCase();return t==="g"||t==="gram"||t==="grams"?"grams":t==="tsp"||t==="teaspoon"?"tsp":t==="tbsp"||t==="tablespoon"?"tbsp":t==="cup"?"cup":t==="serving"||t==="servings"?"serving":"unit"}function Rt(e){switch(e){case"manual":case"search":case"barcode":case"chatgpt":case"photo":case"saved_meal":return e;default:return"manual"}}function Wt(e){return{mealLabel:e.mealLabel??"Meal",notes:e.notes??"",loggedAt:e.loggedAt,dayKey:e.dayKey,source:Rt(e.source),selectedItems:e.items.map(t=>({localId:t.id,food:Dt(t),amount:String(t.quantity||1),unit:t.unit??"serving"}))}}function Bt(e,t=e.source??"manual"){return{mealLabel:e.mealLabel??"Meal",notes:e.notes??"",loggedAt:e.loggedAt,dayKey:e.dayKey,source:e.source??"manual",selectedItems:e.items.map((n,r)=>({localId:`${t}-${r}-${Date.now()}`,food:It(n,r,t),amount:String(n.quantity||1),unit:xa(n.unit)}))}}function ba(){return{id:`custom_food_${Date.now()}`,source:"manual",sourceId:null,name:"Custom food",brand:null,barcode:null,servingLabel:"100 g",servingGrams:100,calories:null,proteinGrams:null,carbohydrateGrams:null,fatGrams:null,fiberGrams:null,sugarGrams:null,sodiumMg:null,potassiumMg:null,caffeineMg:null,alcoholGrams:null,glycemicIndex:null,novaGroup:null,tags:["custom"],confidence:1}}function Ht(){return{mealLabel:"Meal",notes:"",source:"manual",selectedItems:[{localId:`custom-${Date.now()}`,food:ba(),amount:"100",unit:"grams"}]}}function qt({open:e,onOpenChange:t,value:n,onChange:r,foodResults:s,searchPending:d,chatGptPending:g=!1,chatGptError:l=null,logPending:o,onSearch:c,onParseWithChatGpt:w,onSubmit:b,mode:x="create",intent:m="search",initialStepId:S}){const[E,M]=F.useState(""),[_,T]=F.useState(""),[L,B]=F.useState(null),P=F.useMemo(()=>Yt(n.selectedItems),[n.selectedItems]),H=f=>r({...n,...f}),te=f=>{H({selectedItems:[...n.selectedItems,{localId:`${f.id}-${Date.now()}`,food:f,amount:"1",unit:"serving"}]}),B(null)},J=()=>{te(ba())},O=async()=>{const f=_.trim();!f||!w||(await w(f),T(""))},U=(f,v)=>{H({selectedItems:n.selectedItems.map(j=>j.localId===f?{...j,...v}:j)})},ne=(f,v)=>{H({selectedItems:n.selectedItems.map(j=>j.localId===f?{...j,food:{...j.food,...v}}:j)})},re=f=>{H({selectedItems:n.selectedItems.filter(v=>v.localId!==f)})},oe=async()=>{n.selectedItems.length!==0&&await b()},Z=a.jsxs(D,{className:"grid gap-3",children:[a.jsx(y,{label:"Ask ChatGPT",labelHelp:"Uses the connected OpenAI Codex OAuth / ChatGPT subscription model to create a reviewable candidate meal draft. It does not use the metered OpenAI Platform API.",children:a.jsx(ve,{value:_,onChange:f=>T(f.target.value),placeholder:"Example: 2 eggs, 150g Greek yogurt, one banana, and a cappuccino..."})}),l?a.jsx("div",{className:"rounded-[18px] border border-[var(--ui-danger-soft)] bg-[var(--ui-danger-soft)] px-3 py-2 text-xs leading-5 text-[var(--ui-ink)]",children:l}):null,a.jsxs(K,{type:"button",variant:m==="chatgpt"?"primary":"secondary",pending:g,pendingLabel:"Parsing",disabled:!_.trim()||!w,onClick:()=>void O(),children:[a.jsx(ta,{className:"size-4"}),"Parse with ChatGPT"]})]}),Q=a.jsx(D,{className:"grid gap-3",children:a.jsxs("div",{className:"flex items-start justify-between gap-3",children:[a.jsxs("div",{className:"min-w-0",children:[a.jsx("div",{className:"text-sm font-semibold text-[var(--ui-ink-strong)]",children:"Create custom food"}),a.jsx("div",{className:"mt-1 text-xs leading-5 text-[var(--ui-ink-soft)]",children:"Start from a blank food, then define base grams, calories, macros, sodium, and exact quantity in the next step."})]}),a.jsxs(K,{type:"button",size:"sm",onClick:J,children:[a.jsx(De,{className:"size-4"}),"Add custom"]})]})}),V=m==="chatgpt"?[Z,Q]:[Q,Z],ge=[{id:"search",eyebrow:m==="chatgpt"?"ChatGPT food parser":"Food",title:m==="chatgpt"?"Describe the meal, then review every item":"Search, create, or ask ChatGPT",description:m==="chatgpt"?"ChatGPT creates a candidate meal through the subscription-backed connection; you still review quantities and nutrients before saving.":"Search the catalog, create a custom food, or use ChatGPT to turn rough meal text into editable items.",render:()=>a.jsxs("div",{className:"grid gap-4",children:[a.jsxs("div",{className:"grid gap-3 md:grid-cols-[minmax(0,1fr)_auto]",children:[a.jsx(y,{label:"Food search",labelHelp:"Search returns food candidates with per-serving nutrition. Click a result to inspect macros before adding it to the meal draft.",children:a.jsx(k,{value:E,onChange:f=>M(f.target.value),placeholder:"Search eggs, yogurt, sourdough..."})}),a.jsxs(K,{type:"button",variant:"secondary",pending:d,disabled:!E.trim(),onClick:()=>c(E),children:[a.jsx(na,{className:"size-4"}),"Search"]})]}),a.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:V.map((f,v)=>a.jsx("div",{children:f},`${m}-assistant-panel-${v}`))}),L?a.jsx(Vt,{food:L,onAdd:()=>te(L)}):null,a.jsx("div",{className:"grid gap-3",children:s.map(f=>a.jsx(D,{interactive:!0,className:"p-0",children:a.jsx("button",{type:"button",className:"block w-full rounded-[22px] p-4 text-left",onClick:()=>B(f),children:a.jsxs("div",{className:"flex items-start justify-between gap-3",children:[a.jsxs("div",{className:"min-w-0",children:[a.jsx("div",{className:"truncate text-sm font-semibold text-[var(--ui-ink-strong)]",children:f.name}),a.jsx("div",{className:"mt-1 truncate text-xs text-[var(--ui-ink-faint)]",children:[f.brand,f.servingLabel,f.source].filter(Boolean).join(" · ")})]}),a.jsxs($,{tone:"meta",children:[i(f.calories)," kcal"]})]})})},f.id))})]})},{id:"amounts",eyebrow:m==="custom"?"Custom food":"Quantity",title:m==="custom"?"Define the food and exact dose":"Set exactly how much you ate",description:"Scale by grams, servings, household measures, or units before saving the meal.",render:f=>a.jsxs("div",{className:"grid gap-4",children:[f.selectedItems.length===0?a.jsx("div",{className:"rounded-[22px] border border-dashed border-[var(--ui-border-strong)] bg-[var(--ui-surface-1)] p-5 text-sm text-[var(--ui-ink-soft)]",children:"Add at least one food from the search step."}):null,f.selectedItems.map(v=>a.jsxs(D,{className:"grid gap-3",children:[a.jsxs("div",{className:"flex items-start justify-between gap-3",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-sm font-semibold text-[var(--ui-ink-strong)]",children:v.food.name}),a.jsxs("div",{className:"text-xs text-[var(--ui-ink-faint)]",children:["Base: ",i(v.food.calories)," kcal per"," ",Pt(v.food)]})]}),a.jsxs(K,{type:"button",size:"sm",variant:"ghost",onClick:()=>re(v.localId),children:[a.jsx(sa,{className:"size-4"}),"Remove"]})]}),a.jsxs("div",{className:"grid gap-3 md:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto]",children:[a.jsx(y,{label:"Quantity",labelHelp:"This is the amount actually eaten. Forge converts the selected unit to an eaten gram equivalent when base grams are known, then scales every nutrient by eaten grams divided by base grams.",children:a.jsx(k,{inputMode:"decimal",value:v.amount,onChange:j=>U(v.localId,{amount:j.target.value}),placeholder:"1"})}),a.jsx(y,{label:"Unit",labelHelp:"Servings multiply the base serving. Grams, teaspoons, tablespoons, and cups use a gram conversion table and require base grams.",children:a.jsxs("select",{className:"interactive-tap w-full rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3 text-[15px] text-[var(--ui-ink-strong)] outline-none",value:v.unit,onChange:j=>U(v.localId,{unit:j.target.value}),children:[a.jsx("option",{value:"serving",children:"serving"}),a.jsx("option",{value:"grams",children:"grams"}),a.jsx("option",{value:"unit",children:"unit"}),a.jsx("option",{value:"tsp",children:"teaspoon"}),a.jsx("option",{value:"tbsp",children:"tablespoon"}),a.jsx("option",{value:"cup",children:"cup"})]})}),a.jsxs($,{tone:"signal",children:[i(ye(v).calories)," kcal"]})]}),Xe(v)?a.jsx("div",{className:"rounded-[18px] border border-[var(--ui-warning-soft)] bg-[var(--ui-warning-soft)] px-3 py-2 text-xs leading-5 text-[var(--ui-ink)]",children:Xe(v)}):a.jsxs("div",{className:"text-xs text-[var(--ui-ink-faint)]",children:[i(Number(v.amount)||0)," ",v.unit," ="," ",i(pa(v))," g eaten; ratio ="," ",i(ye(v).scale),"x the base nutrition."]}),a.jsx(Qt,{item:v,onChange:j=>ne(v.localId,j)})]},v.localId)),a.jsxs("div",{className:"grid gap-3 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4 md:grid-cols-4",children:[a.jsx(N,{label:"Calories",value:i(P.calories)}),a.jsx(N,{label:"Protein",value:`${i(P.proteinGrams)}g`}),a.jsx(N,{label:"Carbs",value:`${i(P.carbohydrateGrams)}g`}),a.jsx(N,{label:"Fat",value:`${i(P.fatGrams)}g`})]})]})},{id:"context",eyebrow:"Context",title:"Meal label and notes",description:"Add how it felt, where it happened, or anything relevant to future pattern detection.",render:(f,v)=>a.jsxs("div",{className:"grid gap-4",children:[a.jsx(y,{label:"Meal label",labelHelp:"The label groups the edited items as breakfast, lunch, snack, dinner, or any personal meal name.",children:a.jsx(k,{value:f.mealLabel,onChange:j=>v({mealLabel:j.target.value}),placeholder:"Breakfast"})}),a.jsx(y,{label:"Notes",labelHelp:"Use notes for context the numbers do not capture: hunger, cravings, gut comfort, energy, timing, place, or workout relationship.",children:a.jsx(ve,{value:f.notes,onChange:j=>v({notes:j.target.value}),placeholder:"Energy, cravings, gut comfort, training effect..."})})]})}];return a.jsx(je,{open:e,onOpenChange:t,eyebrow:"Food log",title:x==="edit"?"Edit food":"Add food",description:"Search, inspect, scale, edit nutrition parameters, and save meal items.",value:n,onChange:r,steps:ge,initialStepId:S,onSubmit:oe,submitLabel:x==="edit"?"Update meal":"Save meal",pending:o,pendingLabel:"Saving meal",resolveError:f=>f!=="search"&&n.selectedItems.length===0?"Select at least one food before saving.":null,draftPersistenceKey:`weight-loss-food-log.${x}.${m}`})}function fa(e){return{loggedAt:e.loggedAt,dayKey:e.dayKey??$e(),mealLabel:ea(e.mealLabel,"Meal"),source:e.source??"search",confirmationState:"confirmed",notes:ea(e.notes),items:e.selectedItems.map(t=>{const n=ye(t);return{foodId:zt(t),name:t.food.name,brand:t.food.brand,quantity:Number(t.amount)||1,unit:t.unit,grams:n.grams,calories:n.calories,proteinGrams:n.proteinGrams,carbohydrateGrams:n.carbohydrateGrams,fatGrams:n.fatGrams,fiberGrams:n.fiberGrams,sugarGrams:n.sugarGrams,sodiumMg:n.sodiumMg,potassiumMg:n.potassiumMg,caffeineMg:n.caffeineMg,alcoholGrams:n.alcoholGrams,novaGroup:t.food.novaGroup,tags:t.food.tags,confidence:.9}})}}function ea(e,t=""){return typeof e=="string"?e:t}function zt(e){return e.food.source==="manual"||e.food.source==="chatgpt"||e.food.id.startsWith("custom_food_")||e.food.id.startsWith("chatgpt_")?null:e.food.id}function Ot(e){return fa(e)}function Ut(e){const t=Number(e);return Number.isFinite(t)?t:null}function Qt({item:e,onChange:t}){const n=e.food,r=(s,d)=>t({[s]:Ut(d)});return a.jsxs("div",{className:"grid gap-3 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-3",children:[a.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-[var(--ui-ink-strong)]",children:["Food parameters",a.jsx(de,{label:`Explain editable food parameters for ${n.name}`,content:"These are the nutrient values for the base serving shown above. Changing them recalculates the eaten quantity and stores the corrected values in Forge."})]}),a.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[a.jsx(y,{label:"Base label",labelHelp:"Human-readable denominator shown for the nutrition values, such as 100 g, 220 g, one burger, or one scoop.",children:a.jsx(k,{value:n.servingLabel??"",onChange:s=>t({servingLabel:s.target.value||null}),placeholder:"100 g"})}),a.jsx(y,{label:"Base grams",labelHelp:"Gram denominator for the base nutrition values. If kcal is per 220 g, enter 220. If kcal is per 100 g, enter 100.",children:a.jsx(k,{inputMode:"decimal",value:n.servingGrams??"",onChange:s=>r("servingGrams",s.target.value),placeholder:"100"})}),a.jsx(y,{label:"Food name",labelHelp:"Rename the item when the database result is too generic or wrong.",children:a.jsx(k,{value:n.name,onChange:s=>t({name:s.target.value})})}),a.jsx(y,{label:"Brand",labelHelp:"Optional brand or preparation source, useful when the same food has different nutrition.",children:a.jsx(k,{value:n.brand??"",onChange:s=>t({brand:s.target.value||null})})})]}),a.jsxs("div",{className:"grid gap-3 md:grid-cols-4",children:[a.jsx(y,{label:"kcal",labelHelp:"Kilocalories for the base amount above. Forge multiplies this by eaten grams divided by base grams, so 2 g of a 220 g base is not treated as 2 servings.",children:a.jsx(k,{inputMode:"decimal",value:n.calories??"",onChange:s=>r("calories",s.target.value)})}),a.jsx(y,{label:"Protein g",labelHelp:"Protein grams for the base amount above. This is scaled by the same gram ratio as calories.",children:a.jsx(k,{inputMode:"decimal",value:n.proteinGrams??"",onChange:s=>r("proteinGrams",s.target.value)})}),a.jsx(y,{label:"Carbs g",labelHelp:"Carbohydrate grams for the base amount above. Carbs are training fuel after protein and fat are allocated.",children:a.jsx(k,{inputMode:"decimal",value:n.carbohydrateGrams??"",onChange:s=>r("carbohydrateGrams",s.target.value)})}),a.jsx(y,{label:"Fat g",labelHelp:"Fat grams for the base amount above. Fat supports the practical floor and AMDR context in the plan.",children:a.jsx(k,{inputMode:"decimal",value:n.fatGrams??"",onChange:s=>r("fatGrams",s.target.value)})}),a.jsx(y,{label:"Fiber g",labelHelp:"Fiber grams for the base amount above. Forge compares this to the 14g per 1000 kcal planning target.",children:a.jsx(k,{inputMode:"decimal",value:n.fiberGrams??"",onChange:s=>r("fiberGrams",s.target.value)})}),a.jsx(y,{label:"Sugar g",labelHelp:"Sugar grams for the base amount above. Added sugar is tracked as a ceiling, not a goal.",children:a.jsx(k,{inputMode:"decimal",value:n.sugarGrams??"",onChange:s=>r("sugarGrams",s.target.value)})}),a.jsx(y,{label:"Sodium mg",labelHelp:"Sodium milligrams for the base amount above. Sodium affects daily ceiling, sport loss replacement, and water retention hypotheses.",children:a.jsx(k,{inputMode:"decimal",value:n.sodiumMg??"",onChange:s=>r("sodiumMg",s.target.value)})})]})]})}function Vt({food:e,onAdd:t}){return a.jsxs(z,{className:"grid gap-4 border-[var(--primary)]/20 bg-[var(--ui-accent-soft)] p-4",children:[a.jsxs("div",{className:"flex items-start justify-between gap-3",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-lg font-semibold text-[var(--ui-ink-strong)]",children:e.name}),a.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:[e.brand,e.servingLabel,e.source].filter(Boolean).join(" · ")})]}),a.jsxs(K,{type:"button",onClick:t,children:[a.jsx(De,{className:"size-4"}),"Add"]})]}),a.jsxs("div",{className:"grid gap-3 md:grid-cols-4",children:[a.jsx(N,{label:"Calories",value:i(e.calories)}),a.jsx(N,{label:"Protein",value:`${i(e.proteinGrams)}g`}),a.jsx(N,{label:"Carbs",value:`${i(e.carbohydrateGrams)}g`}),a.jsx(N,{label:"Fat",value:`${i(e.fatGrams)}g`}),a.jsx(N,{label:"Fiber",value:`${i(e.fiberGrams)}g`}),a.jsx(N,{label:"Sugar",value:`${i(e.sugarGrams)}g`}),a.jsx(N,{label:"Sodium",value:`${i(e.sodiumMg)}mg`}),a.jsx(N,{label:"NOVA",value:e.novaGroup?String(e.novaGroup):"n/a"})]}),a.jsxs("div",{className:"flex items-center gap-2 text-xs text-[var(--ui-ink-soft)]",children:[a.jsx(Ra,{className:"size-4"}),"Base grams: ",i(ue(e)),". Adjust exact intake in the next step."]})]})}function ye(e){const t=Number(e.amount)||0,n=ue(e.food),r=pa(e),s=e.unit==="serving"||e.unit==="unit",d=t<=0?0:n!=null&&r!=null?r/n:s?t:null,g=l=>d!=null&&typeof l=="number"&&Number.isFinite(l)?Math.round(l*d*10)/10:null;return{grams:r,scale:d,calories:g(e.food.calories),proteinGrams:g(e.food.proteinGrams),carbohydrateGrams:g(e.food.carbohydrateGrams),fatGrams:g(e.food.fatGrams),fiberGrams:g(e.food.fiberGrams),sugarGrams:g(e.food.sugarGrams),sodiumMg:g(e.food.sodiumMg),potassiumMg:g(e.food.potassiumMg),caffeineMg:g(e.food.caffeineMg),alcoholGrams:g(e.food.alcoholGrams)}}function Yt(e){return e.reduce((t,n)=>{const r=ye(n);return{calories:t.calories+(r.calories??0),proteinGrams:t.proteinGrams+(r.proteinGrams??0),carbohydrateGrams:t.carbohydrateGrams+(r.carbohydrateGrams??0),fatGrams:t.fatGrams+(r.fatGrams??0)}},{calories:0,proteinGrams:0,carbohydrateGrams:0,fatGrams:0})}function aa(){return{weightKg:"",waistCm:"",bodyFatPercent:"",energy:"",hunger:"",cravings:"",bloating:"",facePuffiness:"",leanness:"",notes:""}}function Jt({open:e,onOpenChange:t,value:n,onChange:r,onSubmit:s,pending:d}){const g=[{id:"body",eyebrow:"Body",title:"Measurements",description:"Add weight and body measures when you have them. Empty fields are ignored.",render:(l,o)=>a.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[a.jsx(y,{label:"Weight kg",children:a.jsx(k,{inputMode:"decimal",value:l.weightKg,onChange:c=>o({weightKg:c.target.value})})}),a.jsx(y,{label:"Waist cm",children:a.jsx(k,{inputMode:"decimal",value:l.waistCm,onChange:c=>o({waistCm:c.target.value})})}),a.jsx(y,{label:"Body fat %",children:a.jsx(k,{inputMode:"decimal",value:l.bodyFatPercent,onChange:c=>o({bodyFatPercent:c.target.value})})})]})},{id:"state",eyebrow:"State",title:"Energy, appetite, and gut",description:"These subjective signals are what make the view more useful than a calorie ledger.",render:(l,o)=>a.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[a.jsx(y,{label:"Energy 0-10",children:a.jsx(k,{inputMode:"decimal",value:l.energy,onChange:c=>o({energy:c.target.value})})}),a.jsx(y,{label:"Hunger 0-10",children:a.jsx(k,{inputMode:"decimal",value:l.hunger,onChange:c=>o({hunger:c.target.value})})}),a.jsx(y,{label:"Cravings 0-10",children:a.jsx(k,{inputMode:"decimal",value:l.cravings,onChange:c=>o({cravings:c.target.value})})}),a.jsx(y,{label:"Bloating 0-10",children:a.jsx(k,{inputMode:"decimal",value:l.bloating,onChange:c=>o({bloating:c.target.value})})}),a.jsx(y,{label:"Face puffiness 0-10",children:a.jsx(k,{inputMode:"decimal",value:l.facePuffiness,onChange:c=>o({facePuffiness:c.target.value})})}),a.jsx(y,{label:"Leanness 0-10",children:a.jsx(k,{inputMode:"decimal",value:l.leanness,onChange:c=>o({leanness:c.target.value})})})]})},{id:"notes",eyebrow:"Context",title:"Notes",description:"Capture anything that explains the signal.",render:(l,o)=>a.jsx(y,{label:"Notes",children:a.jsx(ve,{value:l.notes,onChange:c=>o({notes:c.target.value}),placeholder:"Sleep, sodium, workout soreness, stressful day..."})})}];return a.jsx(je,{open:e,onOpenChange:t,eyebrow:"Check-in",title:"Add body signal",description:"Add measurements, energy, gut, and appearance signals.",value:n,onChange:r,steps:g,onSubmit:s,submitLabel:"Save check-in",pending:d,pendingLabel:"Saving check-in",draftPersistenceKey:"weight-loss-checkin"})}function Zt(e){const t=n=>{const r=Number(n);return Number.isFinite(r)?r:null};return{body:{weightKg:t(e.weightKg),waistCm:t(e.waistCm),bodyFatPercent:t(e.bodyFatPercent),notes:e.notes},subjective:{energy:t(e.energy),hunger:t(e.hunger),cravings:t(e.cravings),timeRelation:"unspecified",notes:e.notes},gut:{bloating:t(e.bloating),notes:e.notes},appearance:{facePuffiness:t(e.facePuffiness),leanness:t(e.leanness),notes:e.notes}}}function Xt(e){const t=e.items[0]??null,n=Math.max(0,e.items.length-1);return t?`${t.name}${n>0?` + ${n} more`:""}`:e.mealLabel??"Meal"}function en(e){return e.items.slice(0,3).map(t=>{const n=Number.isFinite(t.quantity)&&t.quantity>0?Number.isInteger(t.quantity)?String(t.quantity):t.quantity.toFixed(2).replace(/\.?0+$/,""):null,r=t.unit??"serving",s=t.grams!=null?`${t.grams.toFixed(0)}g`:null;return[n,r,s?`(${s})`:null].filter(Boolean).join(" ")}).filter(Boolean).join(" · ")}function an({open:e,onOpenChange:t,meals:n,onLogAgain:r,onEdit:s,onDelete:d,pending:g}){return a.jsx(je,{open:e,onOpenChange:t,eyebrow:"History",title:"Food history",description:"Review recent foods and quickly log a previous meal again.",value:{},onChange:()=>{},steps:[{id:"history",title:"Recent meal history",render:()=>a.jsx("div",{className:"grid gap-3",children:n.map(l=>a.jsxs(D,{className:"grid gap-3",children:[a.jsxs("div",{className:"flex items-start justify-between gap-3",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-sm font-semibold text-[var(--ui-ink-strong)]",children:Xt(l)}),a.jsxs("div",{className:"mt-1 text-xs text-[var(--ui-ink-faint)]",children:[l.loggedAt.slice(0,10)," ·"," ",en(l)||l.mealLabel||"No quantity recorded"]})]}),a.jsxs($,{tone:"meta",children:[l.totals.calories.toFixed(0)," kcal"]})]}),a.jsxs("div",{className:"flex flex-wrap gap-2",children:[a.jsx(K,{type:"button",size:"sm",variant:"secondary",onClick:()=>s(l),children:"Edit"}),a.jsx(K,{type:"button",size:"sm",variant:"ghost",pending:g,onClick:()=>d(l),children:"Delete"}),a.jsx(K,{type:"button",size:"sm",variant:"secondary",pending:g,onClick:()=>r(l),children:"Log again"})]})]},l.id))})}],onSubmit:async()=>t(!1),submitLabel:"Done"})}function tn(e){switch(e){case"healthkit_daily_active_energy":return"HealthKit daily active energy";case"workout_movement_fallback":return"workout + movement fallback";case"target_inference_only":return"plan target inference";default:return e||"unknown source"}}function nn(e){const t=e.energyModel,n=t.sourceAvailability,r=[n.healthKitDailyEnergy?"HealthKit active energy":null,t.restingEnergyCalories!=null?"HealthKit resting energy":null,n.workoutEnergy?"workout energy":null,n.movementTripCalories?"movement-trip calories":null].filter(Boolean);return r.length>0?r.join(", "):"no measured expenditure streams"}function rn(e){const t=e.energyModel,n=t.recentFoodLogDayCount>0?`${t.recentFoodLogCount} recent food log${t.recentFoodLogCount===1?"":"s"} across ${t.recentFoodLogDayCount} logged day${t.recentFoodLogDayCount===1?"":"s"}`:"no recent logged food days";if(t.estimatedTdeeKcal==null)return`No TDEE estimate yet. Average logged intake is ${i(t.averageCalorieIntake)} kcal/day from ${n}.`;const r=`Recent average balance: intake ${i(t.averageCalorieIntake)} - TDEE ${i(t.estimatedTdeeKcal)} = ${W(t.estimatedDailyEnergyBalanceKcal)} kcal/day.`,s=t.restingEnergyCalories!=null&&t.activeBurnKcal!=null?`TDEE = resting ${i(t.restingEnergyCalories)} + active burn ${i(t.activeBurnKcal)}.`:`TDEE is falling back to the configured plan estimate ${i(t.inferredTdee)}.`,d=t.energySourceConfidence==="healthkit_daily_active_energy"?`Active burn uses HealthKit daily active energy ${i(t.activeBurnKcal)}; workout and movement are evidence only.`:t.energySourceConfidence==="workout_movement_fallback"?`Active burn fallback = workout ${i(t.workoutEnergyKcal)} + movement ${i(t.movementCaloriesKcal)} = ${i(t.activeBurnKcal)}, so movement is not added again.`:"Active burn is not measured yet.";return`${r} ${s} ${d} Food window: ${n}. Negative means estimated deficit; this is not today's remaining calories.`}function sn(e){const t=e.energyModel,n=t.restingEnergyCalories!=null&&t.activeBurnKcal!=null,r=e.todayLedger.dateKey,s=t.recentFoodLogDayCount>0?`${t.recentFoodLogCount} recent food log${t.recentFoodLogCount===1?"":"s"} across ${t.recentFoodLogDayCount} distinct logged day${t.recentFoodLogDayCount===1?"":"s"}`:"no recent logged food days",d=t.energySourceConfidence==="healthkit_daily_active_energy"?`active burn = HealthKit daily active energy average = ${i(t.activeBurnKcal)} kcal/day`:t.energySourceConfidence==="workout_movement_fallback"?`active burn = workout average ${i(t.workoutEnergyKcal)} + movement-trip average ${i(t.movementCaloriesKcal)} = ${i(t.activeBurnKcal)} kcal/day`:"active burn is not measured; Forge falls back to plan inference",g=t.restingEnergyCalories!=null&&t.activeBurnKcal!=null?`TDEE = resting energy average ${i(t.restingEnergyCalories)} + active burn average ${i(t.activeBurnKcal)} = ${i(t.estimatedTdeeKcal)} kcal/day.`:`TDEE = ${i(t.estimatedTdeeKcal)} kcal/day from the configured plan because complete resting + active energy is not available.`,l=t.estimatedTdeeKcal!=null?`Energy gap = average logged intake - TDEE = ${i(t.averageCalorieIntake)} - ${i(t.estimatedTdeeKcal)} = ${W(t.estimatedDailyEnergyBalanceKcal)} kcal/day.`:"Energy gap cannot be computed until Forge has either measured expenditure or an inferred TDEE.",o=t.energySourceConfidence==="healthkit_daily_active_energy"?`selected active burn = HealthKit daily active energy average = ${i(t.activeBurnKcal)} kcal/day. Workout and movement are visible as evidence but are not added.`:t.energySourceConfidence==="workout_movement_fallback"?`selected active burn = workout average ${i(t.workoutEnergyKcal)} + movement-trip average ${i(t.movementCaloriesKcal)} = ${i(t.activeBurnKcal)} kcal/day. This is why movement can appear next to active burn: it is a component of active burn here, not a separate add-on.`:"selected active burn is unavailable, so TDEE falls back to the configured plan estimate.",c=t.restingEnergyCalories!=null&&t.activeBurnKcal!=null&&t.estimatedTdeeKcal!=null?t.energySourceConfidence==="healthkit_daily_active_energy"?`Arithmetic shown here: active burn ${i(t.activeBurnKcal)} = HealthKit daily active energy average; TDEE ${i(t.estimatedTdeeKcal)} = resting ${i(t.restingEnergyCalories)} + active burn ${i(t.activeBurnKcal)}; energy gap ${W(t.estimatedDailyEnergyBalanceKcal)} = intake ${i(t.averageCalorieIntake)} - TDEE ${i(t.estimatedTdeeKcal)}.`:t.energySourceConfidence==="workout_movement_fallback"?`Arithmetic shown here: active burn ${i(t.activeBurnKcal)} = workout ${i(t.workoutEnergyKcal)} + movement ${i(t.movementCaloriesKcal)}; TDEE ${i(t.estimatedTdeeKcal)} = resting ${i(t.restingEnergyCalories)} + active burn ${i(t.activeBurnKcal)}; energy gap ${W(t.estimatedDailyEnergyBalanceKcal)} = intake ${i(t.averageCalorieIntake)} - TDEE ${i(t.estimatedTdeeKcal)}.`:`Arithmetic shown here: TDEE ${i(t.estimatedTdeeKcal)} = resting ${i(t.restingEnergyCalories)} + active burn ${i(t.activeBurnKcal)}; energy gap ${W(t.estimatedDailyEnergyBalanceKcal)} = intake ${i(t.averageCalorieIntake)} - TDEE ${i(t.estimatedTdeeKcal)}.`:"Arithmetic shown here uses the available expenditure branch; some terms are unavailable because Forge does not yet have both resting and active energy evidence.",w=t.recentFoodLogDayCount>0?`Average intake = total calories in the latest ${t.recentFoodLogCount} non-discarded food log${t.recentFoodLogCount===1?"":"s"} / ${t.recentFoodLogDayCount} logged day${t.recentFoodLogDayCount===1?"":"s"}. It does not divide by silent calendar days.`:"Average logged intake is 0 because there are no recent food logs in the current window.",b=t.energySourceConfidence==="healthkit_daily_active_energy"?"Active burn is using HealthKit daily active energy first. Workout and movement values remain visible as evidence, but movement is not added again on top of HealthKit active energy.":t.energySourceConfidence==="workout_movement_fallback"?"HealthKit daily active energy is missing, so active burn falls back to workout energy plus movement-trip calories.":"No measured active-burn stream is available, so this is driven by the plan target and should be treated as low-confidence.",x=`Today is separate: today's target = baseline plan target + (today active calories - default active calories). Today active calories currently use ${va(t.todayActiveCaloriesSource)}: ${i(t.todayActiveCaloriesKcal)} kcal. Default active calories: ${i(t.baselineActiveCaloriesKcal)} kcal. Today's adjustment: ${W(t.todayTargetAdjustmentKcal)} kcal.`,m=t.energySourceConfidence==="healthkit_daily_active_energy"?"Data path: recent food logs provide intake; HealthKit daily active-energy rows provide active burn; resting-energy rows provide basal/resting expenditure.":t.energySourceConfidence==="workout_movement_fallback"?"Data path: recent food logs provide intake; HealthKit resting-energy rows provide resting expenditure; workout-session energy plus movement-trip calories provide fallback active burn.":"Data path: recent food logs provide intake; expenditure is using the configured plan inference because measured expenditure streams are incomplete.";return a.jsxs("span",{className:"grid gap-2",children:[a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"What this card means:"})," ","this is a historical energy-balance estimate, not the remaining food budget for today. Negative means estimated deficit; positive means estimated surplus."]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"Formula:"})," ",l]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"TDEE:"})," ","TDEE means total daily energy expenditure: the estimated calories burned per day. Forge uses"," ",n?"measured resting energy plus the selected active-burn branch":"the configured/inferred plan estimate because measured resting plus active expenditure is incomplete",". Objective deficit or surplus is not subtracted here; that belongs to the intake target."]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"Selected branch:"})," ",t.energySourceConfidence==="healthkit_daily_active_energy"?"HealthKit daily active energy exists, so active burn uses that value. Workout, movement, and step values are shown only as evidence.":t.energySourceConfidence==="workout_movement_fallback"?"HealthKit daily active energy is missing, so active burn uses workout calories plus movement-trip calories.":"Measured expenditure is incomplete, so TDEE falls back to the configured plan estimate."]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"Active-burn branch:"})," ",o]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"Arithmetic:"})," ",c]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"Why these numbers:"})," ","The displayed movement value is therefore"," ",t.energySourceConfidence==="workout_movement_fallback"?"part of the active-burn calculation":"supporting evidence only",", and it is not the same thing as today's editable active-calorie budget."]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"Current data:"})," ","intake ",i(t.averageCalorieIntake)," kcal/day; TDEE"," ",i(t.estimatedTdeeKcal)," kcal/day; resting"," ",i(t.restingEnergyCalories)," kcal/day; active burn"," ",i(t.activeBurnKcal)," kcal/day; workout"," ",i(t.workoutEnergyKcal)," kcal/day; movement"," ",i(t.movementCaloriesKcal)," kcal/day."," ",t.energySourceConfidence==="workout_movement_fallback"?"On this branch, active burn already equals workout plus movement, so movement is not an extra add-on after active burn.":"On this branch, movement is shown as evidence and is not added on top of active burn."]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"Data lineage:"})," ",m]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"Food window:"})," ",w," Current denominator: ",s,"."]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"Expenditure:"})," ",g," ",d,". TDEE means total daily energy expenditure, the estimated calories burned per day before applying the weight-loss or weight-gain objective."]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"TDEE source:"})," ",n?"measured expenditure branch: resting energy average plus selected active-burn branch":"plan-inference branch because Forge does not yet have both resting and active expenditure streams",". TDEE is an expenditure estimate; the goal deficit or surplus is applied when planning intake targets, not when calculating historical TDEE."]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"Calculation path:"})," ","Forge first tries HealthKit daily active energy for active burn. If that is missing, it uses workout energy plus movement-trip calories. TDEE is resting energy plus whichever active-burn branch was selected. The objective deficit or surplus is not part of this historical TDEE."]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"Source:"})," ",tn(t.energySourceConfidence)," across"," ",t.evidenceDays," expenditure evidence day",t.evidenceDays===1?"":"s"," ending the selected day (",r,"). Available streams: ",nn(e),"."," ",b]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"Movement:"})," ","movement kcal is a component of fallback active burn. If HealthKit daily active energy exists, Forge shows movement as supporting evidence but does not add it again. If HealthKit active energy is missing, fallback active burn is workout average + movement average; the displayed active burn number already includes that movement component."]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"Today:"})," ",x]})]})}function on(e){const t=W(e);return t==="n/a"?t:`${t} kcal/d`}function va(e){switch(e){case"today_workout_energy":return"today's workout energy";case"today_healthkit_active_energy":return"today's HealthKit active energy";case"today_workout_movement_energy":return"today's workout and movement energy";case"today_workout_movement_step_energy":return"today's workout, movement, and step energy";case"today_workout_step_energy":return"today's workout and step energy";case"today_movement_step_energy":return"today's movement and step energy";case"today_movement_trip_calories":return"today's movement trip calories";case"today_step_estimate":return"today's estimated step calories";case"user_override":return"your manual active-calorie override";default:return"the default daily active calories"}}function ln(e){const[t,n,r]=e.split("-").map(Number),s=new Date(t,n-1,r),d=new Date(t,n-1,r+1);return{dayStartAt:s.toISOString(),dayEndAt:d.toISOString()}}function cn(){const e=new Date,t=new Date(e);return t.setHours(24,0,2,0),Math.max(1e3,t.getTime()-e.getTime())}function jn(){const e=Ua(),t=qa(),n=e.selectedUserIds,[r,s]=F.useState(()=>$e()),d=F.useMemo(()=>ln(r),[r]),g=F.useMemo(()=>["forge-weight-loss-view",r,...n],[r,n]),[l,o]=F.useState(!1),[c,w]=F.useState(!1),[b,x]=F.useState(!1),[m,S]=F.useState(!1),[E,M]=F.useState(!1),[_,T]=F.useState(null),[L,B]=F.useState(null),[P,H]=F.useState(""),[te,J]=F.useState(null),[O,U]=F.useState(null),[ne,re]=F.useState("search"),[oe,Z]=F.useState(void 0),[Q,V]=F.useState(()=>fe()),[ge,f]=F.useState(()=>aa()),v=za({queryKey:g,queryFn:async()=>(await st(n,{dateKey:r,...d})).weightLoss}),j=v.data;F.useEffect(()=>{const u=()=>{s(Oe=>{const Ue=$e();return Ue===Oe?Oe:Ue})},h=window.setTimeout(u,cn());return window.addEventListener("focus",u),document.addEventListener("visibilitychange",u),()=>{window.clearTimeout(h),window.removeEventListener("focus",u),document.removeEventListener("visibilitychange",u)}},[r]),F.useEffect(()=>{!j||c||l||Kt(j)||(w(!0),J(Ee(j)),T(`Forge needs the missing profile fields before the calorie and macro plan can be trusted.
|
|
3
3
|
|
|
4
4
|
- Confirm age, height, current weight, objective, weekly rate, and active calories.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as a,aC as j,r as w}from"./vendor-Dnkkx2co.js";import{Z as u,bq as N,cL as $}from"./index-
|
|
1
|
+
import{j as a,aC as j,r as w}from"./vendor-Dnkkx2co.js";import{Z as u,bq as N,cL as $}from"./index-BhkubYaC.js";function k(i){const e=[];let n,r;for(const s of i){const t=s.trim();if(!t)continue;const o=t.indexOf(":");if(o<=0){e.push({label:"Note",value:t});continue}const c=t.slice(0,o).trim(),p=t.slice(o+1).trim();if(!p)continue;const m=c.toLowerCase();if(m==="title"){n=p;continue}if(m==="summary"){r=p;continue}e.push({label:c,value:p})}return{title:n,summary:r,rows:e}}function C(i){const e=[],n=/(!?\[\[([^\]]+)\]\]|\[([^\]]+)\]\(([^)]+)\)|`([^`]+)`|\*\*([^*]+)\*\*|\*([^*]+)\*)/g;let r=0,s=null;for(;(s=n.exec(i))!==null;){if(s.index>r&&e.push({type:"text",value:i.slice(r,s.index)}),s[1]&&s[2]){const t=s[2].trim(),o=s[1].startsWith("!"),c=t.indexOf("|"),p=c>=0?t.slice(0,c).trim():t,m=c>=0?t.slice(c+1).trim():p;if(p.toLowerCase().startsWith("forge:")){const[,g,...l]=p.split(":");e.push({type:"forge-link",entityType:g??"",entityId:l.join(":").trim(),label:m})}else e.push({type:"wiki-link",target:p,label:m,embed:o})}else s[3]&&s[4]?e.push({type:"link",label:s[3],href:s[4].trim()}):s[5]?e.push({type:"code",value:s[5]}):s[6]?e.push({type:"strong",value:s[6]}):s[7]&&e.push({type:"em",value:s[7]});r=n.lastIndex}return r<i.length&&e.push({type:"text",value:i.slice(r)}),e}function L(i){const e=i.replace(/\r/g,"").split(`
|
|
2
2
|
`),n=[],r=[];let s=null,t=0;for(;t<e.length;){const o=e[t]??"",c=o.trim();if(!c){t+=1;continue}if(c.startsWith("```")){const l=[];for(t+=1;t<e.length&&!(e[t]??"").trim().startsWith("```");)l.push(e[t]??""),t+=1;t+=1,n.push({type:"code",code:l.join(`
|
|
3
3
|
`)});continue}const p=c.match(/^:::([a-z0-9-]+)\s*$/i);if(p){const l=p[1].toLowerCase(),d=[];for(t+=1;t<e.length&&(e[t]??"").trim()!==":::";)d.push(e[t]??""),t+=1;t<e.length&&(t+=1);const y=[`:::${l}`,...d,":::"].join(`
|
|
4
4
|
`);r.push({kind:l,lines:d,raw:y}),l==="forge-infobox"?s=k(d):l==="note"||l==="tip"||l==="warning"||l==="danger"?n.push({type:"admonition",kind:l,lines:d}):(l==="forge-links"||l==="forge-media"||l==="forge-related")&&n.push({type:l,lines:d});continue}const m=o.match(/^(#{1,6})\s+(.*)$/);if(m){n.push({type:"heading",level:m[1].length,text:m[2].trim()}),t+=1;continue}if(/^>\s?/.test(o)){const l=[];for(;t<e.length&&/^>\s?/.test(e[t]??"");)l.push((e[t]??"").replace(/^>\s?/,"")),t+=1;n.push({type:"quote",text:l.join(" ").trim()});continue}if(/^[-*+]\s+/.test(o)||/^\d+\.\s+/.test(o)){const l=/^\d+\.\s+/.test(o),d=[];for(;t<e.length&&(/^[-*+]\s+/.test(e[t]??"")||/^\d+\.\s+/.test(e[t]??""));)d.push((e[t]??"").replace(/^[-*+]\s+/,"").replace(/^\d+\.\s+/,"").trim()),t+=1;n.push({type:"list",ordered:l,items:d});continue}const g=[];for(;t<e.length;){const l=e[t]??"",d=l.trim();if(!d||d.startsWith("```")||d.startsWith(":::")||/^#{1,6}\s+/.test(l)||/^>\s?/.test(l)||/^[-*+]\s+/.test(l)||/^\d+\.\s+/.test(l))break;g.push(d),t+=1}if(g.length>0){n.push({type:"paragraph",text:g.join(" ")});continue}t+=1}return{blocks:n,infobox:s,directives:r}}const x="text-[var(--ui-ink-medium)]",W="text-[var(--ui-ink-soft)]",f="text-[var(--ui-ink-faint)]",q="text-[var(--ui-ink-strong)]",b="border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)]",I="border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",T="rounded-sm bg-[var(--ui-surface-2)] px-1.5 py-0.5 text-[var(--ui-ink-strong)] no-underline ring-1 ring-[var(--ui-border-subtle)] transition hover:bg-[var(--ui-surface-hover)]";function M(i,e,n){return i.map((r,s)=>{const t=`${e}-${s}`;switch(r.type){case"text":return a.jsx(w.Fragment,{children:r.value},t);case"code":return a.jsx("code",{className:"rounded bg-[var(--ui-surface-2)] px-1.5 py-0.5 font-mono text-[0.92em] text-[var(--ui-ink-strong)] ring-1 ring-[var(--ui-border-subtle)]",children:r.value},t);case"strong":return a.jsx("strong",{className:"font-semibold text-[var(--ui-ink-strong)]",children:r.value},t);case"em":return a.jsx("em",{className:"italic text-[var(--ui-ink-medium)]",children:r.value},t);case"link":{const o=/^https?:\/\//i.test(r.href);return a.jsx("a",{href:r.href,target:o?"_blank":void 0,rel:o?"noreferrer":void 0,className:"text-[var(--secondary)] underline decoration-current/30 underline-offset-2 transition hover:text-[var(--ui-ink-strong)]",children:r.label},t)}case"forge-link":{const o=N(r.entityType,r.entityId),c=o?$(o):null;return c?a.jsx("a",{href:c,className:T,children:r.label},t):a.jsx("span",{className:"rounded-sm bg-[var(--ui-surface-2)] px-1.5 py-0.5 text-[var(--ui-ink-soft)] ring-1 ring-[var(--ui-border-subtle)]",children:r.label},t)}case"wiki-link":return a.jsx(j,{to:{pathname:`/wiki/page/${encodeURIComponent(r.target)}`,search:n?`?spaceId=${encodeURIComponent(n)}`:""},className:u("underline decoration-current/30 underline-offset-2 transition hover:text-[var(--ui-ink-strong)]",r.embed?"text-[var(--primary)]":"text-[var(--secondary)]"),children:r.label},t)}})}function h(i,e,n){return M(C(i),e,n)}function P(i,e){const n=i.map(r=>r.trim()).filter(Boolean);return n.length===0?null:a.jsx("ul",{className:u("space-y-1.5 pl-4 text-[13px] leading-6",x),children:n.map((r,s)=>a.jsx("li",{children:h(r,`directive-${s}`,e)},`${r}-${s}`))})}function v(i,e,n){switch(i.type){case"heading":{const r=i.level===1?"text-[1.9rem] leading-[1.08]":i.level===2?"text-[1.25rem] leading-[1.2]":i.level===3?"text-[1.05rem] leading-[1.3]":"text-[0.92rem] leading-[1.35]";return a.jsx("h2",{className:u("font-semibold tracking-[-0.02em]",q,e>0&&"mt-6",r),children:h(i.text,`heading-${e}`,n)},`heading-${e}`)}case"paragraph":return a.jsx("p",{className:u("text-[14px] leading-7",x),children:h(i.text,`paragraph-${e}`,n)},`paragraph-${e}`);case"quote":return a.jsx("blockquote",{className:u("border-l-[3px] border-[var(--ui-border-strong)] pl-4 text-[14px] leading-7",W),children:h(i.text,`quote-${e}`,n)},`quote-${e}`);case"list":{const r=i.ordered?"ol":"ul";return a.jsx(r,{className:u("space-y-1.5 pl-5 text-[14px] leading-7",x,i.ordered?"list-decimal":"list-disc"),children:i.items.map((s,t)=>a.jsx("li",{children:h(s,`list-${e}-${t}`,n)},`item-${e}-${t}`))},`list-${e}`)}case"code":return a.jsx("pre",{className:"max-w-full overflow-x-auto rounded-xl border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-code)] px-4 py-3 text-[12px] leading-6 text-[var(--ui-ink-strong)]",children:a.jsx("code",{children:i.code})},`code-${e}`);case"admonition":return a.jsxs("aside",{className:u("rounded-xl border px-4 py-3",i.kind==="warning"||i.kind==="danger"?"border-[color-mix(in_srgb,var(--warning)_32%,transparent)] bg-[var(--ui-warning-soft)]":I),children:[a.jsx("div",{className:u("mb-2 text-[11px] font-semibold uppercase tracking-[0.16em]",f),children:i.kind}),a.jsx("div",{className:u("grid gap-2 text-[13px] leading-6",x),children:i.lines.map((r,s)=>a.jsx("p",{children:h(r,`admonition-${e}-${s}`,n)},`admonition-line-${s}`))})]},`admonition-${e}`);case"forge-links":case"forge-media":case"forge-related":return a.jsxs("section",{className:u("rounded-xl border px-4 py-3",b),children:[a.jsx("div",{className:u("mb-2 text-[11px] font-semibold uppercase tracking-[0.16em]",f),children:i.type.replace("forge-","")}),P(i.lines,n)]},`${i.type}-${e}`)}}function R(i,e,n){return a.jsx("div",{className:u("text-[13px] leading-6",x),children:h(i,e,n)})}function _({infobox:i,spaceId:e,className:n}){return a.jsxs("aside",{className:u("wiki-infobox rounded-2xl border p-4",b,n),children:[i.title?a.jsx("div",{className:"text-[1rem] font-semibold leading-tight text-[var(--ui-ink-strong)]",children:i.title}):null,i.summary?a.jsx("p",{className:"mt-2 text-[13px] leading-6 text-[var(--ui-ink-soft)]",children:h(i.summary,"infobox-summary",e)}):null,a.jsx("dl",{className:"mt-3 grid gap-2",children:i.rows.map((r,s)=>a.jsxs("div",{className:"grid gap-1 border-t border-[var(--ui-border-subtle)] pt-2 first:border-t-0 first:pt-0",children:[a.jsx("dt",{className:"text-[10px] font-semibold uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:r.label}),a.jsx("dd",{children:R(r.value,`infobox-row-${s}`,e)})]},`${r.label}-${s}`))})]})}function z(i){const e=[],n=[];let r=!1;for(const s of i)!r&&s.type==="heading"&&s.level<=2&&e.length>0&&(r=!0),r?n.push(s):e.push(s);return{intro:e.length>0?e:i.slice(0,1),rest:e.length>0?n:i.slice(1)}}function A({markdown:i,spaceId:e,className:n}){const r=L(i),{intro:s,rest:t}=z(r.blocks);return a.jsxs("div",{className:u("grid gap-4",n),children:[a.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1fr)_19rem] xl:items-start",children:[a.jsx("div",{className:"grid gap-4",children:s.map((o,c)=>v(o,c,e))}),r.infobox?a.jsx(_,{infobox:r.infobox,spaceId:e,className:"order-2 xl:order-none"}):null]}),t.length>0?a.jsx("div",{className:"grid gap-4",children:t.map((o,c)=>v(o,c+s.length,e))}):null]})}export{A as W};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{aJ as Be,b5 as Qe,cc as qe,c2 as De,r as d,j as e,cw as Ke,cx as Ve,bk as He,bX as Ue,cb as Je,aU as Xe,aR as Ye,cg as Ze,dH as Ge,dI as ea,aK as we,bl as aa}from"./vendor-Dnkkx2co.js";import{R as ye,P as Ne,O as Ce,C as Se,T as Ie,D as Te,a as $e}from"./ui-C1iwpj2-.js";import{j as sa,i as X,k as ta}from"./state-vCcAT5Hq.js";import{u as ra,c as g,g as P,fl as ia,fm as na,L as la,E as oa,a as da,B as C,Z as j,I as T,T as E,m as F,aq as ve,bY as ca,fn as ua,fo as pa}from"./index-
|
|
1
|
+
import{aJ as Be,b5 as Qe,cc as qe,c2 as De,r as d,j as e,cw as Ke,cx as Ve,bk as He,bX as Ue,cb as Je,aU as Xe,aR as Ye,cg as Ze,dH as Ge,dI as ea,aK as we,bl as aa}from"./vendor-Dnkkx2co.js";import{R as ye,P as Ne,O as Ce,C as Se,T as Ie,D as Te,a as $e}from"./ui-C1iwpj2-.js";import{j as sa,i as X,k as ta}from"./state-vCcAT5Hq.js";import{u as ra,c as g,g as P,fl as ia,fm as na,L as la,E as oa,a as da,B as C,Z as j,I as T,T as E,m as F,aq as ve,bY as ca,fn as ua,fo as pa}from"./index-BhkubYaC.js";import{W as xa}from"./wiki-article-markdown-CBFvfJx_.js";import"./motion-Lt5B1XuE.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";const _="rounded-[28px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] shadow-[var(--ui-shadow-card)]",x="text-[11px] font-semibold uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",ma="w-full rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3.5 py-3 text-[13px] text-[var(--ui-ink-strong)] outline-none transition focus:border-[color-mix(in_srgb,var(--primary)_40%,transparent)]",b="border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",fe="min-w-0 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3 text-left transition hover:bg-[var(--ui-surface-hover)]";function M(t,r){return`${t}:${r}`}function ha(t){const r=t.indexOf(":");return r<=0||r>=t.length-1?null:{entityType:t.slice(0,r),entityId:t.slice(r+1)}}function Le(t){return t.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function $(t){return Array.from(new Set(t.split(",").map(r=>r.trim()).filter(Boolean)))}function ga(t){if(!t.trim())return{};try{const r=JSON.parse(t);return r&&typeof r=="object"&&!Array.isArray(r)?r:{}}catch{return{}}}function Me(){return{pageId:null,kind:"wiki",title:"",slug:"",parentSlug:"index",indexOrder:0,showInIndex:!0,summary:"",aliasesText:"",contentMarkdown:`# Untitled
|
|
2
2
|
|
|
3
3
|
`,author:"",tagsText:"",frontmatterText:`{
|
|
4
4
|
"status": "draft"
|
package/dist/assets/{wiki-ingest-history-page-DZKSBNHV.js → wiki-ingest-history-page-XX8DeNCC.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b5 as F,c2 as J,r as R,j as s,aG as D,c7 as E,b7 as Q}from"./vendor-Dnkkx2co.js";import{j as H,i as q,k as z}from"./state-vCcAT5Hq.js";import{W as A}from"./wiki-ingest-modal-
|
|
1
|
+
import{b5 as F,c2 as J,r as R,j as s,aG as D,c7 as E,b7 as Q}from"./vendor-Dnkkx2co.js";import{j as H,i as q,k as z}from"./state-vCcAT5Hq.js";import{W as A}from"./wiki-ingest-modal-j-ftDmzp.js";import{P as _}from"./page-hero-DzEsy8i5.js";import{fg as U,S as O,E as B,C as W,B as f,I as w,Z as G,a as $,bY as Y,fk as Z}from"./index-BhkubYaC.js";import"./ui-C1iwpj2-.js";import"./motion-Lt5B1XuE.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";const V=[{value:"all",label:"All"},{value:"queued",label:"Queued"},{value:"processing",label:"Processing"},{value:"completed",label:"Completed"},{value:"failed",label:"Failed"},{value:"review",label:"Review"},{value:"reviewed",label:"Reviewed"}];function X(l){return new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(new Date(l))}function ee(l,o){return o==="all"?!0:l.job.status===o||l.job.phase===o}function me(){var N,y,S,C,I,P;const l=F(),o=H(),[i,m]=J(),c=i.get("spaceId")||"",j=i.get("q")||"",h=i.get("tag")||"all",g=i.get("from")||"",p=i.get("to")||"",K=i.get("ingest")==="1",k=i.get("ingestJobId"),r=q({queryKey:["forge-wiki-settings"],queryFn:Y}),d=q({queryKey:["forge-wiki-ingest-history",c],queryFn:()=>Z({spaceId:c||void 0,limit:200}),enabled:r.isSuccess}),x=z({mutationFn:e=>U(e),onSuccess:async(e,a)=>{if(await o.invalidateQueries({queryKey:["forge-wiki-ingest-history"]}),await o.invalidateQueries({queryKey:["forge-wiki-ingest-jobs"]}),k===a){const t=new URLSearchParams(i);t.delete("ingest"),t.delete("ingestJobId"),m(t,{replace:!0})}}}),u=(e,a)=>{const t=new URLSearchParams(i);a.trim()?t.set(e,a.trim()):t.delete(e),m(t,{replace:!0})},v=R.useMemo(()=>{var t;const e=((t=d.data)==null?void 0:t.jobs)??[],a=j.trim().toLowerCase();return e.filter(n=>{if(!ee(n,h))return!1;const L=n.job.createdAt.slice(0,10);return g&&L<g||p&&L>p?!1:a?[n.job.titleHint,n.job.latestMessage,n.job.sourceLocator,n.job.status,n.job.phase,n.job.mimeType].join(" ").toLowerCase().includes(a):!0})},[g,(N=d.data)==null?void 0:N.jobs,j,h,p]),M=c||((S=(y=r.data)==null?void 0:y.settings.spaces[0])==null?void 0:S.id)||"",b=e=>{const a=new URLSearchParams(i);a.set("ingest","1"),e?a.set("ingestJobId",e):a.delete("ingestJobId"),m(a,{replace:!0})},T=()=>{const e=new URLSearchParams(i);e.delete("ingest"),e.delete("ingestJobId"),m(e,{replace:!0})};return r.isLoading||d.isLoading?s.jsx(O,{eyebrow:"KarpaWiki",title:"Loading ingest history",description:"Gathering prior imports, statuses, and review state.",columns:1,blocks:6}):r.isError||d.isError?s.jsx(B,{eyebrow:"KarpaWiki",error:r.error??d.error,onRetry:()=>{r.refetch(),d.refetch()}}):s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-3 py-4 sm:px-5 lg:px-6",children:s.jsxs("div",{className:"mx-auto grid w-full max-w-[1480px] gap-5",children:[s.jsx(_,{title:"KarpaWiki Ingest History",description:"Search prior ingests, reopen a review, or clear ingest records without touching pages and entities that were already published.",badge:`${v.length} matching jobs`}),s.jsxs(W,{className:"grid gap-4",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[s.jsxs("div",{children:[s.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"History Filters"}),s.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Narrow by free text, date range, space, or status tags."})]}),s.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.jsx(f,{variant:"secondary",onClick:()=>l(`/wiki${c?`?spaceId=${encodeURIComponent(c)}`:""}`),children:"Back to KarpaWiki"}),s.jsxs(f,{onClick:()=>b(),children:[s.jsx(D,{className:"size-3.5"}),"New ingest"]})]})]}),s.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,1.4fr)_minmax(0,0.8fr)_minmax(0,0.8fr)_minmax(0,0.8fr)]",children:[s.jsxs("label",{className:"grid gap-2",children:[s.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Free text"}),s.jsx(w,{value:j,onChange:e=>u("q",e.target.value),placeholder:"title, source, status, failure message…"})]}),s.jsxs("label",{className:"grid gap-2",children:[s.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"From"}),s.jsx(w,{type:"date",value:g,onChange:e=>u("from",e.target.value)})]}),s.jsxs("label",{className:"grid gap-2",children:[s.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"To"}),s.jsx(w,{type:"date",value:p,onChange:e=>u("to",e.target.value)})]}),s.jsxs("label",{className:"grid gap-2",children:[s.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Space"}),s.jsxs("select",{className:"h-11 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 text-sm text-[var(--ui-ink-strong)]",value:c,onChange:e=>u("spaceId",e.target.value),children:[s.jsx("option",{value:"",children:"All spaces"}),(((C=r.data)==null?void 0:C.settings.spaces)??[]).map(e=>s.jsx("option",{value:e.id,children:e.label},e.id))]})]})]}),s.jsx("div",{className:"flex flex-wrap gap-2",children:V.map(e=>s.jsx("button",{type:"button",className:G("rounded-full px-3 py-2 text-xs font-semibold uppercase tracking-[0.14em] transition",h===e.value?"bg-[var(--primary)]/[0.18] text-[var(--primary)]":"bg-[var(--ui-surface-1)] text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>u("tag",e.value==="all"?"":e.value),children:e.label},e.value))})]}),v.length===0?s.jsx($,{eyebrow:"KarpaWiki ingest",title:"No ingest jobs match these filters",description:"Try widening the dates or clearing a status tag."}):s.jsx("div",{className:"grid gap-3",children:v.map(e=>{const a=e.job.titleHint||e.job.latestMessage||e.job.sourceLocator||"KarpaWiki ingest",t=!["queued","processing"].includes(e.job.status);return s.jsxs(W,{className:"grid min-w-0 gap-4",children:[s.jsxs("div",{className:"grid min-w-0 gap-3 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-start",children:[s.jsxs("button",{type:"button",className:"min-w-0 max-w-full text-left",onClick:()=>b(e.job.id),children:[s.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[s.jsx("span",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"KarpaWiki ingest"}),s.jsx("span",{className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-2.5 py-1 text-[10px] uppercase tracking-[0.16em] text-[var(--ui-ink-soft)]",children:e.job.status}),s.jsx("span",{className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-2.5 py-1 text-[10px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:e.job.phase})]}),s.jsx("div",{className:"mt-3 break-words text-lg font-semibold text-[var(--ui-ink-strong)]",children:a}),s.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap gap-x-4 gap-y-1 text-sm text-[var(--ui-ink-soft)]",children:[s.jsxs("span",{children:[e.job.progressPercent,"% ·"," ",e.job.createdPageCount," pages ·"," ",e.job.createdEntityCount," entities"]}),s.jsx("span",{children:X(e.job.createdAt)}),e.job.sourceLocator?s.jsx("span",{className:"min-w-0 max-w-full break-all",children:e.job.sourceLocator}):null]})]}),s.jsxs("div",{className:"flex min-w-0 flex-wrap gap-2 sm:justify-end",children:[s.jsx(f,{variant:"secondary",size:"sm",className:"max-sm:flex-1",onClick:()=>b(e.job.id),children:"Open review"}),s.jsxs(f,{variant:"secondary",size:"sm",className:"max-sm:flex-1",disabled:!t||x.isPending,pending:x.isPending&&x.variables===e.job.id,pendingLabel:"Deleting",onClick:()=>{!t||!window.confirm("Delete this ingest history entry? Published pages and entities will stay, but discarded or unreviewed ingest artifacts will be removed.")||x.mutateAsync(e.job.id)},children:[s.jsx(E,{className:"size-3.5"}),"Delete"]})]})]}),e.job.errorMessage?s.jsx("div",{className:"rounded-[18px] border border-rose-400/18 bg-rose-500/[0.08] px-4 py-3 text-sm text-rose-100/86",children:e.job.errorMessage}):null,["queued","processing"].includes(e.job.status)?s.jsxs("div",{className:"inline-flex items-center gap-2 text-sm text-[var(--ui-ink-soft)]",children:[s.jsx(Q,{className:"size-4 animate-spin"}),"This ingest is still active and cannot be deleted yet."]}):null]},e.job.id)})})]})}),s.jsx(A,{open:K,onOpenChange:e=>{e||T()},spaces:((I=r.data)==null?void 0:I.settings.spaces)??[],llmProfiles:((P=r.data)==null?void 0:P.settings.llmProfiles)??[],initialSpaceId:M,selectedJobId:k,onJobSelected:e=>b(e)})]})}export{me as WikiIngestHistoryPage};
|