forge-openclaw-plugin 0.3.2 → 0.3.3
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/action-bar-5Ii4UzHa.js +1 -0
- package/dist/assets/activity-page-CWjTKFY3.js +1 -0
- package/dist/assets/ai-surface-workspace-Dd2FSRom.js +1 -0
- package/dist/assets/{atlas-panel-G3wGxjYf.js → atlas-panel-Dinteouh.js} +1 -1
- package/dist/assets/{board-dIX6etHh.js → board-CLOHbg6t.js} +1 -1
- package/dist/assets/calendar-page-BWkXhzDf.js +1 -0
- package/dist/assets/calendar-rules-CjyuTu2I.js +1 -0
- package/dist/assets/{calendar-week-toolbar-CWSK5hJl.js → calendar-week-toolbar-D-nd9tkk.js} +1 -1
- package/dist/assets/{charts-DFnEuIMB.js → charts-DwTguE_x.js} +1 -1
- package/dist/assets/companion-sync-lab-page-G0t1TqqZ.js +1 -0
- package/dist/assets/daily-metrics-dashboard-DpIAdzFX.js +1 -0
- package/dist/assets/define-workbench-box-BIOZopF2.js +1 -0
- package/dist/assets/entity-link-multiselect-DZZjpL_d.js +1 -0
- package/dist/assets/{entity-note-count-link-ef3ZOpKM.js → entity-note-count-link-CmRRdXAr.js} +1 -1
- package/dist/assets/entity-notes-surface-8MPDscsu.js +1 -0
- package/dist/assets/execution-board-Bi8gi8J6.js +1 -0
- package/dist/assets/{faceted-token-search-CZmtyJTT.js → faceted-token-search-BGs4TqxT.js} +1 -1
- package/dist/assets/{flagship-signal-deck-DxRfmfpN.js → flagship-signal-deck-jLxHEHvb.js} +1 -1
- package/dist/assets/{floating-action-menu-cKjNsPYD.js → floating-action-menu-Itpm7T2_.js} +1 -1
- package/dist/assets/{forms-hB0SqEh-.js → forms-C5d5hTf2.js} +1 -1
- package/dist/assets/generic-node-view-KePoUF3Z.js +10 -0
- package/dist/assets/goal-detail-page-a1lEswpJ.js +1 -0
- package/dist/assets/goal-dialog-CYgRzl4y.js +1 -0
- package/dist/assets/goals-page-JY_EJq9U.js +1 -0
- package/dist/assets/{graph-DDUZNRsO.js → graph-Cd5WF3lw.js} +1 -1
- package/dist/assets/habits-page-BRI8AoaQ.js +1 -0
- package/dist/assets/health-boxes-DZJOFTOI.js +1 -0
- package/dist/assets/index-wEZUnRh0.js +2 -0
- package/dist/assets/inline-note-fields-CUVRzQkI.js +1 -0
- package/dist/assets/insight-flow-dialog-By73oG1H.js +1 -0
- package/dist/assets/{insights-page-DHG-o9P_.js → insights-page-DLyN-9yz.js} +3 -3
- package/dist/assets/kanban-boxes-M71CejV4.js +1 -0
- package/dist/assets/kanban-page-InKHhJQD.js +1 -0
- package/dist/assets/knowledge-graph-page-C-GEQGRY.js +1 -0
- package/dist/assets/life-force-page-Dq88NzNp.js +1 -0
- package/dist/assets/{life-force-workspace-sszLD-Yn.js → life-force-workspace-Bl_0slZi.js} +1 -1
- package/dist/assets/{maps-C-yOWiDN.js → maps-D0Mm6WPG.js} +1 -1
- package/dist/assets/{metric-tile-B-tDTcBt.js → metric-tile-yQJgjYrN.js} +1 -1
- package/dist/assets/{motion-Lt5B1XuE.js → motion-DwjmC9aq.js} +1 -1
- package/dist/assets/movement-boxes-C-rc3N8Z.js +1 -0
- package/dist/assets/movement-page-DK-d1uYa.js +1 -0
- package/dist/assets/{note-markdown-CCyyE85h.js → note-markdown-7czv-KMH.js} +1 -1
- package/dist/assets/note-tags-input-CkgkqiT3.js +1 -0
- package/dist/assets/notes-boxes-BQuR1MiB.js +1 -0
- package/dist/assets/notes-page-ec9g1mPh.js +1 -0
- package/dist/assets/{open-in-graph-button-CMjJZX7G.js → open-in-graph-button-B_4fdm4l.js} +1 -1
- package/dist/assets/{orbit-map-v2Pv9RU_.js → orbit-map-DPQNBqS-.js} +1 -1
- package/dist/assets/overview-page-CZjMab2o.js +1 -0
- package/dist/assets/page-hero-BRcqE3a4.js +1 -0
- package/dist/assets/pill-cluster-dy6jG_dV.js +1 -0
- package/dist/assets/{preference-entity-handoff-button-CKDxCnbl.js → preference-entity-handoff-button-DOV-_2Vm.js} +1 -1
- package/dist/assets/preferences-page-Co8w5hzp.js +1 -0
- package/dist/assets/{project-collections-NBwk6yV-.js → project-collections-DNgKleDl.js} +1 -1
- package/dist/assets/project-detail-page-C-Ib1x8w.js +1 -0
- package/dist/assets/project-dialog-D_hgOdB9.js +1 -0
- package/dist/assets/project-management-hierarchy-page-asf61KSz.js +1 -0
- package/dist/assets/project-management-section-nav-DAZA1oXG.js +1 -0
- package/dist/assets/projects-boxes-CHLr1Bs-.js +1 -0
- package/dist/assets/projects-page-BsM8yCqQ.js +1 -0
- package/dist/assets/psyche-behaviors-page-COSZeP4J.js +5 -0
- package/dist/assets/psyche-flashcards-page-CJmgGL9x.js +1 -0
- package/dist/assets/psyche-goal-map-page-avrWNSs9.js +1 -0
- package/dist/assets/psyche-graph-BmwbnNBY.js +1 -0
- package/dist/assets/psyche-metrics-page-CY0J_aMx.js +1 -0
- package/dist/assets/psyche-mode-guide-page-COcswIHZ.js +1 -0
- package/dist/assets/psyche-modes-page-BXF_GZoP.js +1 -0
- package/dist/assets/psyche-page-VsMBNG1F.js +1 -0
- package/dist/assets/psyche-patterns-page-DVoIro0Q.js +5 -0
- package/dist/assets/psyche-questionnaire-builder-page-CahcrbQj.js +1 -0
- package/dist/assets/psyche-questionnaire-detail-page-CYSgADAD.js +1 -0
- package/dist/assets/psyche-questionnaire-run-detail-page-D5q5URTu.js +1 -0
- package/dist/assets/psyche-questionnaire-run-page-DUoA-VSs.js +1 -0
- package/dist/assets/psyche-questionnaires-page-dbQlqbKh.js +1 -0
- package/dist/assets/{psyche-report-detail-page-Ci14mNUK.js → psyche-report-detail-page-D_Mmlf2D.js} +3 -3
- package/dist/assets/psyche-reports-page-CO3J4Js3.js +1 -0
- package/dist/assets/{psyche-schemas-Dxj554nU.js → psyche-schemas-Dtskzvv1.js} +1 -1
- package/dist/assets/psyche-schemas-beliefs-page-BUNGL4zW.js +9 -0
- package/dist/assets/psyche-screen-time-page-Bm18uHDg.js +1 -0
- package/dist/assets/psyche-self-observation-page-VdPMBuK4.js +1 -0
- package/dist/assets/psyche-values-page-DivSQodJ.js +5 -0
- package/dist/assets/question-flow-dialog-Dsnsc8be.js +2 -0
- package/dist/assets/{report-chain-fields-CbkT7WOO.js → report-chain-fields-Bf-WCSJQ.js} +1 -1
- package/dist/assets/rewards-page-CI53Cp0i.js +1 -0
- package/dist/assets/{scheduling-rules-editor-BUGnZJ0g.js → scheduling-rules-editor-Bg3QU_qt.js} +1 -1
- package/dist/assets/{schema-badge-CLAA4p-b.js → schema-badge-CRThEDqP.js} +1 -1
- package/dist/assets/schemas-B8-kIOFQ.js +1 -0
- package/dist/assets/{select-menu-Cqs5t3ng.js → select-menu-rT3Qd5t5.js} +1 -1
- package/dist/assets/{settings-agents-page-pmkVrOO8.js → settings-agents-page-VDUv2WuO.js} +4 -4
- package/dist/assets/settings-bin-page-DfuGJVqc.js +1 -0
- package/dist/assets/{settings-calendar-page-BBjAMOCf.js → settings-calendar-page-ex7eHB1y.js} +3 -3
- package/dist/assets/settings-data-page-BPWyPVGo.js +1 -0
- package/dist/assets/settings-logs-page-CwTT4n63.js +1 -0
- package/dist/assets/settings-mobile-page-B6sVk872.js +1 -0
- package/dist/assets/settings-models-page-Dq5XViZd.js +1 -0
- package/dist/assets/settings-page-BRxdAxbS.js +1 -0
- package/dist/assets/settings-rewards-page-DRvxTwv3.js +1 -0
- package/dist/assets/{settings-section-nav-Co0AaDG-.js → settings-section-nav-D_vKvOWd.js} +1 -1
- package/dist/assets/settings-users-page-B6oSpOaV.js +1 -0
- package/dist/assets/settings-wiki-page-Bkv-SS3J.js +1 -0
- package/dist/assets/sleep-page-DELXxo6j.js +1 -0
- package/dist/assets/sports-page-ByWQL0Gf.js +1 -0
- package/dist/assets/{state-vCcAT5Hq.js → state-BtwEvpO6.js} +1 -1
- package/dist/assets/strategies-page-PuUHsaSJ.js +1 -0
- package/dist/assets/strategy-detail-page-CSyVdv29.js +1 -0
- package/dist/assets/strategy-dialog-Fgpc0z1M.js +1 -0
- package/dist/assets/{surface-CyWI7e1R.js → surface-DzVqQDmf.js} +1 -1
- package/dist/assets/{table-BNqMG3_S.js → table-BuONJH1s.js} +1 -1
- package/dist/assets/task-detail-page-BoLvJ_4F.js +1 -0
- package/dist/assets/task-dialog-B2cGkhLk.js +6 -0
- package/dist/assets/timebox-planning-dialog-BjiC2jh0.js +1 -0
- package/dist/assets/today-boxes-B4f4sBXg.js +1 -0
- package/dist/assets/today-page-Cusp2JI8.js +1 -0
- package/dist/assets/training-load-page-CsZbK6rY.js +1 -0
- package/dist/assets/{ui-C1iwpj2-.js → ui-B9O-eUim.js} +1 -1
- package/dist/assets/use-anchored-overlay-position-BrQ4cqKn.js +1 -0
- package/dist/assets/{use-psyche-focus-target-Ct-acS9G.js → use-psyche-focus-target-Cuxni3SK.js} +1 -1
- package/dist/assets/user-badge-CQygGKVs.js +1 -0
- package/dist/assets/user-ownership-DJGl4rAj.js +1 -0
- package/dist/assets/user-select-field-BNqv8-wd.js +1 -0
- package/dist/assets/utility-widgets-DRESNarT.js +3 -0
- package/dist/assets/{vendor-Dnkkx2co.js → vendor-Cpmju3nw.js} +1 -1
- package/dist/assets/vitals-page-BlTZ4f78.js +1 -0
- package/dist/assets/weekly-review-page-3Pk3NeGE.js +1 -0
- package/dist/assets/weight-loss-page-CRCtv1fX.js +5 -0
- package/dist/assets/{wiki-article-markdown-Bi02AsVt.js → wiki-article-markdown-D0PWvioX.js} +2 -2
- package/dist/assets/{wiki-editor-page-OZf9l4Tg.js → wiki-editor-page-OZMYUgFo.js} +5 -5
- package/dist/assets/wiki-ingest-history-page-DXZHzAqU.js +1 -0
- package/dist/assets/wiki-ingest-modal-Ro0V4UMB.js +1 -0
- package/dist/assets/wiki-page-B1g3Rfxy.js +1 -0
- package/dist/assets/workbench-flow-page-qh5nItU6.js +5 -0
- package/dist/assets/workbench-page-CFWfAYMV.js +1 -0
- package/dist/assets/workout-detail-page-Cw6t6Xj9.js +2 -0
- package/dist/index.html +7 -9
- package/dist/server/server/src/app.js +10 -0
- package/dist/server/server/src/health-weight-loss.js +11 -3
- package/dist/server/server/src/services/dashboard.js +4 -4
- package/dist/server/server/src/services/gamification.js +71 -32
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/dist/assets/activity-page-DRRbpVK-.js +0 -1
- package/dist/assets/ai-surface-workspace-DJPt-OaW.js +0 -1
- package/dist/assets/calendar-page-y8G1ige8.js +0 -1
- package/dist/assets/calendar-rules-CRhXqGQu.js +0 -1
- package/dist/assets/companion-sync-lab-page-kEgOF3c6.js +0 -1
- package/dist/assets/daily-metrics-dashboard-BJjUIZVA.js +0 -1
- package/dist/assets/entity-notes-surface-CaCjjUaq.js +0 -1
- package/dist/assets/execution-board-RRWm2srb.js +0 -1
- package/dist/assets/goal-detail-page-BgQlK7yT.js +0 -1
- package/dist/assets/goals-page-Cz2i3pVy.js +0 -1
- package/dist/assets/habits-page-BmEmWCGv.js +0 -1
- package/dist/assets/index-QJkjKYzZ.js +0 -19
- package/dist/assets/insight-flow-dialog-CdYMHwMP.js +0 -1
- package/dist/assets/kanban-page-C6S_fJRc.js +0 -1
- package/dist/assets/knowledge-graph-page-juA9QCy0.js +0 -1
- package/dist/assets/life-force-page-ChTIA4mV.js +0 -1
- package/dist/assets/movement-page-Dx3T3HrG.js +0 -1
- package/dist/assets/note-tags-input-BS14YXHn.js +0 -1
- package/dist/assets/notes-page-D3yGl8TN.js +0 -1
- package/dist/assets/overview-page-DSOpBpHf.js +0 -1
- package/dist/assets/page-hero-CONuJu5J.js +0 -1
- package/dist/assets/pill-cluster-W2fY48OM.js +0 -1
- package/dist/assets/preferences-page-Br3zrLlH.js +0 -1
- package/dist/assets/project-detail-page-BIU9_TRN.js +0 -1
- package/dist/assets/project-management-hierarchy-page-C2H620xD.js +0 -1
- package/dist/assets/project-management-section-nav-DRPVS1Eh.js +0 -1
- package/dist/assets/projects-page-w7a_L2-z.js +0 -1
- package/dist/assets/psyche-behaviors-page-Dt4CMC-q.js +0 -5
- package/dist/assets/psyche-flashcards-page-rXz06dqO.js +0 -1
- package/dist/assets/psyche-goal-map-page-BCcD6Jkl.js +0 -1
- package/dist/assets/psyche-graph-CXlAj4ED.js +0 -1
- package/dist/assets/psyche-metrics-page-B1otiir6.js +0 -1
- package/dist/assets/psyche-mode-guide-page-C6AdVIAv.js +0 -1
- package/dist/assets/psyche-modes-page-DoUqz2mR.js +0 -1
- package/dist/assets/psyche-page-BJNLQn8W.js +0 -1
- package/dist/assets/psyche-patterns-page-CzpMSAPu.js +0 -5
- package/dist/assets/psyche-questionnaire-builder-page-DjzatGVZ.js +0 -1
- package/dist/assets/psyche-questionnaire-detail-page-B0Qfowfg.js +0 -1
- package/dist/assets/psyche-questionnaire-run-detail-page-B2dNj4jJ.js +0 -1
- package/dist/assets/psyche-questionnaire-run-page-DyD9Ui-g.js +0 -1
- package/dist/assets/psyche-questionnaires-page-BxfKcoi3.js +0 -1
- package/dist/assets/psyche-reports-page-ALhNueiV.js +0 -1
- package/dist/assets/psyche-schemas-beliefs-page-C0P2Vw6-.js +0 -9
- package/dist/assets/psyche-screen-time-page-BYnaT3cb.js +0 -1
- package/dist/assets/psyche-self-observation-page-eM9vpwIB.js +0 -1
- package/dist/assets/psyche-values-page-BqrGIDok.js +0 -5
- package/dist/assets/rewards-page-DpAJ8IxE.js +0 -1
- package/dist/assets/settings-bin-page-BwtLrweW.js +0 -1
- package/dist/assets/settings-data-page-Bqy5SukM.js +0 -1
- package/dist/assets/settings-logs-page-8khtrf4T.js +0 -1
- package/dist/assets/settings-mobile-page-BcyRjEU_.js +0 -1
- package/dist/assets/settings-models-page-DlSnO9WX.js +0 -1
- package/dist/assets/settings-page-CyBQ2qcB.js +0 -1
- package/dist/assets/settings-rewards-page-BBX2WtVM.js +0 -1
- package/dist/assets/settings-users-page-JSnfFFPu.js +0 -1
- package/dist/assets/settings-wiki-page--nT23Fdy.js +0 -1
- package/dist/assets/sleep-page-CGMi3MtV.js +0 -1
- package/dist/assets/sports-page-Kv5bBoLr.js +0 -1
- package/dist/assets/strategies-page-Br7RdUJO.js +0 -1
- package/dist/assets/strategy-detail-page-CBWXjUhC.js +0 -1
- package/dist/assets/strategy-dialog-BTwkaSxI.js +0 -1
- package/dist/assets/task-detail-page-Qis9354n.js +0 -1
- package/dist/assets/timebox-planning-dialog-DB8snOBD.js +0 -1
- package/dist/assets/today-page-D9A5PU0S.js +0 -1
- package/dist/assets/training-load-page-Bpd4DQAh.js +0 -1
- package/dist/assets/vitals-page-CVYC-4RG.js +0 -1
- package/dist/assets/weekly-review-page-BP7N3fNB.js +0 -1
- package/dist/assets/weight-loss-page-_fX3N1UK.js +0 -5
- package/dist/assets/wiki-ingest-history-page-CzeNSL7N.js +0 -1
- package/dist/assets/wiki-ingest-modal-Ig_xnyc6.js +0 -1
- package/dist/assets/wiki-page-B4xuNgY4.js +0 -1
- package/dist/assets/workbench-flow-page-BhRJCALC.js +0 -5
- package/dist/assets/workbench-page-DxVs2AOY.js +0 -1
- package/dist/assets/workout-detail-page-D4wfkE98.js +0 -2
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as w,j as e,aD as ve,d8 as be,aC as fe,aG as ye,bl as je,d9 as Ne,aQ as we}from"./vendor-Dnkkx2co.js";import{j as ke,i as L,k as M}from"./state-vCcAT5Hq.js";import{u as Se}from"./forms-hB0SqEh-.js";import{Q as Ce,db as ee,F as R,I as _,j as Te,dc as Fe,T as Pe,dd as A,B as k,de as te,P as _e,aI as $e,df as De,dg as Q,dh as Ae,di as Ee,dj as Ie,dk as Le,dl as se,S as Me,E as ae,C as $,dm as Qe,dn as Re,dp as qe,dq as ze,dr as Je,ds as Ke,dt as Oe,du as Ge,dv as He,dw as Ue,dx as Be}from"./index-QJkjKYzZ.js";import{S as We}from"./settings-section-nav-Co0AaDG-.js";import{P as Ye}from"./page-hero-CONuJu5J.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";function K({theme:a,title:l,description:n}){return e.jsx("div",{className:"overflow-hidden rounded-[24px] border border-[var(--ui-border-subtle)]",style:{background:`linear-gradient(180deg, ${a.panelHigh}, ${a.panelLow})`,color:a.ink},children:e.jsxs("div",{className:"px-4 py-4",style:{background:`radial-gradient(circle at top left, ${a.primary}33, transparent 42%), radial-gradient(circle at top right, ${a.secondary}2a, transparent 36%), linear-gradient(180deg, ${a.panel}, ${a.canvas})`},children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.2em] opacity-60",children:"Preview"}),e.jsx("div",{className:"mt-2 font-display text-xl",children:l}),e.jsx("div",{className:"mt-2 text-sm leading-6 opacity-72",children:n}),e.jsx("div",{className:"mt-5 flex gap-2",children:[a.primary,a.secondary,a.tertiary,a.panelHigh].map(t=>e.jsx("div",{className:"h-9 flex-1 rounded-[14px] border border-[var(--ui-border-subtle)]",style:{background:t}},t))})]})})}function j({label:a,value:l,onChange:n,description:t}){return e.jsx(R,{label:a,description:t,children:e.jsxs("div",{className:"grid gap-3 sm:grid-cols-[5.5rem_minmax(0,1fr)]",children:[e.jsx("input",{type:"color",value:l,onChange:d=>n(d.target.value),className:"h-12 w-full cursor-pointer rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-1"}),e.jsx(_,{value:l,onChange:d=>n(d.target.value),placeholder:"#7cc7ff"})]})})}function Xe({open:a,onOpenChange:l,value:n,onSave:t}){const[d,m]=w.useState(n),[g,u]=w.useState(""),[f,b]=w.useState(null),S=w.useRef(null),c=r=>{const i=ee.parse(JSON.parse(r));m(i),u(JSON.stringify(i,null,2)),b(null)},x=r=>{const i=te(r);m({...i,label:d.label.trim().length>0?d.label:`${i.label} Custom`})},C=async r=>{var o;const i=(o=r.target.files)==null?void 0:o[0];if(i)try{c(await i.text())}catch(T){b(T instanceof Error?T.message:"Forge could not parse that JSON theme.")}finally{r.target.value=""}},E=[{id:"identity",eyebrow:"Custom theme",title:"Name the mood and choose a starting point",description:"Start from a Forge preset, then tune the accents and surfaces in the next steps.",render:(r,i)=>e.jsxs("div",{className:"grid gap-5",children:[e.jsx(R,{label:"Theme label",description:"This label appears in Settings when the custom theme is active.",children:e.jsx(_,{value:r.label,onChange:o=>i({label:o.target.value}),placeholder:"Midnight Circuit"})}),e.jsx(R,{label:"Starter preset",children:e.jsx(Te,{value:"",onChange:o=>x(o),options:Object.entries(Fe).map(([o,T])=>({value:o,label:T.label,description:T.description})),columns:2})}),e.jsx(K,{theme:r,title:r.label,description:"Live preview of the current custom theme draft."})]})},{id:"accents",eyebrow:"Custom theme",title:"Set the accent colors",description:"These colors drive buttons, highlights, charts, and the ambient shell lighting.",render:(r,i)=>e.jsxs("div",{className:"grid gap-4",children:[e.jsx(j,{label:"Primary",description:"Main emphasis color for actions and active state.",value:r.primary,onChange:o=>i({primary:o})}),e.jsx(j,{label:"Secondary",description:"Support accent for positive or secondary emphasis.",value:r.secondary,onChange:o=>i({secondary:o})}),e.jsx(j,{label:"Tertiary",description:"Warm contrast color for warnings, highlights, and supporting metrics.",value:r.tertiary,onChange:o=>i({tertiary:o})})]})},{id:"surfaces",eyebrow:"Custom theme",title:"Tune the shell surfaces",description:"Forge currently assumes a dark shell, so these should remain fairly deep colors for legibility.",render:(r,i)=>e.jsxs("div",{className:"grid gap-4",children:[e.jsx(j,{label:"Canvas",description:"Primary app background.",value:r.canvas,onChange:o=>i({canvas:o})}),e.jsx(j,{label:"Panel",description:"Default card and rail background.",value:r.panel,onChange:o=>i({panel:o})}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(j,{label:"Panel high",description:"Raised highlights and stronger sections.",value:r.panelHigh,onChange:o=>i({panelHigh:o})}),e.jsx(j,{label:"Panel low",description:"Lower contrast and deeper card areas.",value:r.panelLow,onChange:o=>i({panelLow:o})})]}),e.jsx(j,{label:"Ink",description:"Main text and readable foreground color.",value:r.ink,onChange:o=>i({ink:o})}),e.jsx(K,{theme:r,title:r.label,description:"Live preview after the current surface edits."})]})},{id:"import",eyebrow:"Custom theme",title:"Import or paste JSON directly",description:"You can skip the picker workflow entirely by uploading a JSON file or pasting a valid theme object.",render:r=>e.jsxs("div",{className:"grid gap-4",children:[e.jsx(R,{label:"Direct JSON",description:"Paste a full custom theme object, then click Apply JSON.",children:e.jsx(Pe,{value:g,onChange:i=>u(i.target.value),className:"min-h-52 font-mono text-[13px] leading-6",placeholder:JSON.stringify(A,null,2)})}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsx(k,{type:"button",variant:"secondary",onClick:()=>{try{c(g)}catch(i){b(i instanceof Error?i.message:"Forge could not parse that JSON theme.")}},children:"Apply JSON"}),e.jsx(k,{type:"button",variant:"ghost",onClick:()=>{var i;return(i=S.current)==null?void 0:i.click()},children:"Upload JSON file"}),e.jsx("input",{ref:S,type:"file",accept:"application/json,.json",className:"hidden",onChange:C})]}),e.jsx(K,{theme:r,title:r.label,description:"Preview of the theme that will be saved if you submit now."})]})}];return e.jsx(Ce,{open:a,onOpenChange:r=>{r&&(m(n),u(""),b(null)),l(r)},eyebrow:"Settings",title:"Forge custom theme",description:"Build a dark Forge palette visually, or import one directly as JSON.",value:d,onChange:r=>{m(r),b(null)},draftPersistenceKey:"settings.theme-customizer",steps:E,error:f,onSubmit:async()=>{try{const r=ee.parse(d);t(r),l(!1)}catch(r){b(r instanceof Error?r.message:"Forge could not save that custom theme.")}},submitLabel:"Save custom theme",contentClassName:"lg:w-[min(62rem,calc(100vw-1.5rem))]"})}const N="font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",F="text-sm leading-6 text-[var(--ui-ink-soft)]",ie="text-xs leading-5 text-[var(--ui-ink-faint)]",P="rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",q="rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]";function Ze({theme:a}){return e.jsx("div",{className:"mt-3 grid grid-cols-4 gap-2",children:[a.primary,a.secondary,a.tertiary,a.panelHigh].map(l=>e.jsx("div",{className:"h-6 rounded-[10px] border border-[var(--ui-border-subtle)]",style:{background:l}},l))})}function Ve({selected:a,theme:l}){return e.jsxs("div",{className:"relative min-h-[138px] overflow-hidden rounded-[18px] border border-[var(--ui-border-subtle)] bg-[linear-gradient(145deg,var(--ui-surface-2),var(--ui-surface-1))]",children:[e.jsx("div",{className:"absolute inset-x-0 bottom-0 h-16 bg-[linear-gradient(0deg,color-mix(in_srgb,var(--ui-surface-3)_82%,transparent),transparent)]"}),e.jsx("img",{src:Je(l),alt:`${l} neutral Forge Smith mascot preview`,className:"absolute bottom-1 left-1/2 h-[124px] w-[124px] -translate-x-1/2 object-contain drop-shadow-[0_18px_30px_color-mix(in_srgb,var(--ui-shadow-color)_30%,transparent)]"}),e.jsxs("div",{className:"absolute left-3 top-3 flex items-center gap-2 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-glass)] px-2.5 py-1 text-[9px] font-semibold uppercase tracking-[0.14em] text-[var(--ui-ink-medium)] backdrop-blur-md",children:[e.jsx(ye,{className:"size-3 text-[var(--warning)]"}),"Live rewards"]}),e.jsx("div",{className:"absolute bottom-3 left-3 flex items-center gap-1.5",children:Ke.map(n=>e.jsx("span",{className:"grid size-11 place-items-center overflow-hidden rounded-[12px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-glass)] p-1 shadow-[var(--ui-shadow-soft)] backdrop-blur-md",children:e.jsx("img",{src:Oe(l,n),alt:`${l} reward thumbnail`,className:"size-full object-contain"})},n))}),e.jsx("span",{className:`absolute right-3 top-3 grid size-7 place-items-center rounded-full border ${a?"border-[color-mix(in_srgb,var(--success)_42%,var(--ui-border-subtle)_58%)] bg-[var(--ui-success-soft)] text-[var(--success)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-glass)] text-[var(--ui-ink-faint)]"}`,children:a?e.jsx(je,{className:"size-4"}):null})]})}function re({healthy:a}){return e.jsx($,{className:"p-4",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:N,children:"Mobile companion"}),e.jsx("div",{className:"mt-1 text-base font-medium text-[var(--ui-ink-strong)]",children:a?"iPhone bridge is syncing":"Connect the iPhone bridge"}),e.jsx("div",{className:`mt-1 max-w-3xl ${F}`,children:a?"Review HealthKit, movement, and background sync permissions.":"Pair or refresh the native companion before relying on HealthKit, movement, or watch signals."})]}),e.jsx(fe,{to:"/settings/mobile",className:"inline-flex min-h-10 items-center rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 py-2 text-sm text-[var(--ui-ink-strong)] transition hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]",children:"Open mobile settings"})]})})}function z(a){return new Date(a).toLocaleString()}function ne({integrityScore:a,storageMode:l,lastAuditAt:n,doctor:t}){return t?[t.integrity.headline,t.integrity.topIssues.length>0?t.integrity.topIssues[0].summary:"No active Doctor warnings are holding back integrity.",`Storage mode: ${l}. Latest Doctor run: ${z(t.integrity.lastCheckedAt)}.`]:a>=100?["All currently reported settings and storage checks passed.",`Latest audit: ${z(n)}.`]:[`Forge is holding back ${Math.max(0,100-a)}% because the latest settings and storage audit reported a consistency warning.`,"The current audit only exposes the aggregate score, so per-check details are not available yet.",`Storage mode: ${l}. Latest audit: ${z(n)}.`]}function le({integrityScore:a,storageMode:l,lastAuditAt:n,doctor:t}){const d=(t==null?void 0:t.integrity.score)??a,m=ne({integrityScore:a,storageMode:l,lastAuditAt:n,doctor:t});return e.jsxs("details",{className:"group relative inline-flex",children:[e.jsxs("summary",{className:"inline-flex cursor-pointer list-none items-center gap-1 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-2.5 py-1 text-[11px] font-medium normal-case tracking-normal text-[var(--ui-ink-soft)] transition marker:hidden hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[color-mix(in_srgb,var(--primary)_32%,transparent)] [&::-webkit-details-marker]:hidden",onKeyDown:g=>{var u;g.key==="Escape"&&((u=g.currentTarget.parentElement)==null||u.removeAttribute("open"))},children:[e.jsx(be,{className:"size-3.5","aria-hidden":"true"}),d,"% integrity"]}),e.jsxs("span",{role:"tooltip",className:"surface-modal-panel absolute right-0 top-[calc(100%+0.55rem)] z-50 hidden w-[min(19rem,calc(100vw-2rem))] rounded-[16px] border px-3 py-2.5 text-left text-xs leading-5 tracking-normal text-[var(--ui-ink-soft)] normal-case shadow-[var(--ui-shadow-strong)] group-open:block",children:[e.jsx("span",{className:"block font-medium text-[var(--ui-ink-strong)]",children:d>=100?"Integrity is complete":`Why this is ${d}%`}),m.map(g=>e.jsx("span",{className:"mt-1 block",children:g},g))]})]})}function es({integrityScore:a,storageMode:l,lastAuditAt:n,doctor:t,doctorLoading:d,onRefreshDoctor:m,onApplyFix:g,applyingFixId:u}){const f=(t==null?void 0:t.integrity.score)??a,b=(t==null?void 0:t.integrity.lastCheckedAt)??n,S=(t==null?void 0:t.issues.filter(x=>x.severity!=="info").slice(0,4))??[],[c]=ne({integrityScore:a,storageMode:l,lastAuditAt:n,doctor:t});return e.jsxs($,{className:"p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:N,children:"Security posture"}),e.jsx("div",{className:`mt-1 ${F}`,children:"Local-first means Forge stores its runtime data on this machine. Integrity is the latest internal consistency score from settings and data checks."}),e.jsx("div",{className:`mt-2 ${ie}`,children:c})]}),e.jsx(le,{integrityScore:a,storageMode:l,lastAuditAt:n,doctor:t})]}),e.jsxs("div",{className:"mt-3 grid gap-2 md:grid-cols-2",children:[e.jsxs("div",{className:`${q} px-3 py-3`,children:[e.jsx("div",{className:"text-xs text-[var(--ui-ink-soft)]",children:"Storage mode"}),e.jsx("div",{className:"mt-1 text-base font-medium text-[var(--ui-ink-strong)]",children:l})]}),e.jsxs("div",{className:`${q} px-3 py-3`,children:[e.jsx("div",{className:"text-xs text-[var(--ui-ink-soft)]",children:"Last Doctor run"}),e.jsx("div",{className:"mt-1 text-base font-medium text-[var(--ui-ink-strong)]",children:z(b)})]})]}),e.jsxs("div",{className:`mt-3 ${q} p-3`,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-[var(--ui-ink-strong)]",children:[e.jsx(Ne,{className:"size-4 text-[var(--info)]"}),"Forge Doctor"]}),e.jsxs(k,{type:"button",variant:"secondary",pending:d,onClick:m,children:[e.jsx(we,{className:"size-4"}),"Run"]})]}),e.jsx("div",{className:`mt-2 ${F}`,children:t?`${f}% integrity. ${t.integrity.headline}`:"Run Doctor to check settings, storage, entities, rewards, and runtime consistency."}),S.length>0?e.jsx("div",{className:"mt-3 grid gap-2",children:S.map(x=>{var C;return e.jsx(ss,{issue:x,applying:u===((C=x.fix)==null?void 0:C.id),onApplyFix:g},x.id)})}):t?e.jsx("div",{className:"mt-3 rounded-[12px] border border-[color-mix(in_srgb,var(--success)_24%,var(--ui-border-subtle)_76%)] bg-[var(--ui-success-soft)] px-3 py-2 text-sm text-[var(--success)]",children:"No active consistency warnings."}):null]})]})}function ss({issue:a,applying:l,onApplyFix:n}){var t;return e.jsx("div",{className:`${q} px-3 py-2`,children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"text-xs uppercase tracking-[0.14em] text-[var(--ui-ink-faint)]",children:[a.group," / ",a.severity]}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-medium)]",children:a.summary})]}),((t=a.fix)==null?void 0:t.kind)==="safe_auto_fix"?e.jsx(k,{type:"button",variant:"secondary",pending:l,onClick:()=>n(a.fix.id),children:"Apply fix"}):null]})})}function ms(){var W,Y,X,Z,V;const{t:a}=_e(),l=$e(),n=ke(),[t,d]=w.useState(!1),m=L({queryKey:["forge-operator-session"],queryFn:Ge}),g=m.isSuccess,u=L({queryKey:["forge-settings"],queryFn:He,enabled:g}),f=De(void 0,{skip:!g}),b=L({queryKey:["forge-companion-overview"],queryFn:async()=>(await Ue()).overview,enabled:g,staleTime:3e4}),S=L({queryKey:["forge-gamification-assets"],queryFn:Be,enabled:g,staleTime:3e4}),c=Se({defaultValues:{profile:{operatorName:"",operatorEmail:"",operatorTitle:""},notifications:{goalDriftAlerts:!0,dailyQuestReminders:!0,achievementCelebrations:!0},execution:{maxActiveTasks:2,timeAccountingMode:"split"},themePreference:"obsidian",gamificationTheme:"dramatic-smithie",customTheme:A,localePreference:"en"}}),x=async()=>{await Promise.all([n.invalidateQueries({queryKey:["forge-operator-session"]}),n.invalidateQueries({queryKey:["forge-settings"]})])},C=M({mutationFn:s=>Q(s),onSuccess:x}),E=M({mutationFn:s=>Q(s),onSuccess:async s=>{n.setQueryData(["forge-settings"],s),await x()}}),r=M({mutationFn:s=>Q(s),onSuccess:async s=>{n.setQueryData(["forge-settings"],s),await x()}}),i=M({mutationFn:async s=>(await Ae(s),Q({gamificationTheme:s})),onSuccess:async s=>{n.setQueryData(["forge-settings"],s),await Promise.all([n.invalidateQueries({queryKey:["forge-settings"]}),n.invalidateQueries({queryKey:["forge-gamification-assets"]})])}}),[o,T]=Ee(),[oe,ce]=Ie(),[de,O]=w.useState(),ue=async()=>{await o().unwrap(),l(qe([])),l(ze.util.resetApiState()),n.removeQueries({predicate:s=>{const[v]=s.queryKey;return typeof v=="string"&&v.startsWith("forge-")}}),await Promise.all([x(),m.refetch()])};w.useEffect(()=>{var s;(s=u.data)!=null&&s.settings&&c.reset(Le.parse(u.data.settings))},[u.data,c]);const p=(W=u.data)==null?void 0:W.settings,me=(Y=f.data)==null?void 0:Y.doctor,D=c.watch("themePreference"),G=c.watch("gamificationTheme"),H=((X=S.data)==null?void 0:X.assets.styles)??[],J=H.find(s=>s.id===G),y=c.watch("customTheme")??A,U=((Z=b.data)==null?void 0:Z.healthState)==="healthy_sync",pe=async s=>{if(window.confirm("Apply this Forge Doctor fix? Forge will only run the selected safe repair.")){O(s);try{await oe({fixIds:[s]}).unwrap(),await Promise.all([u.refetch(),f.refetch()])}finally{O(void 0)}}},B=async(s,v=y)=>{c.setValue("themePreference",s,{shouldDirty:!0}),c.setValue("customTheme",v??A,{shouldDirty:!0}),await E.mutateAsync({themePreference:s,customTheme:v??A})},ge=async s=>{c.setValue("gamificationTheme",s,{shouldDirty:!0}),await r.mutateAsync({gamificationTheme:s})};return w.useEffect(()=>{if(p)return se(D,y),()=>{se(p.themePreference,p.customTheme??null)}},[y,D,p,p==null?void 0:p.customTheme,p==null?void 0:p.themePreference]),m.isLoading||u.isLoading?e.jsx(Me,{eyebrow:"Settings",title:"Loading settings",description:"Establishing the operator session and fetching current configuration.",columns:2,blocks:6}):m.isError?e.jsx(ae,{eyebrow:"Settings",error:m.error,onRetry:()=>void m.refetch()}):u.isError||!p?e.jsx(ae,{eyebrow:"Settings",error:u.error??new Error("Forge returned an empty settings payload."),onRetry:()=>void u.refetch()}):e.jsxs("div",{className:"mx-auto grid w-full max-w-[1220px] gap-5",children:[e.jsx(Ye,{title:"Settings",description:"Tune execution policy, timer behaviour, and personal preferences.",badge:e.jsx(le,{integrityScore:p.security.integrityScore,storageMode:p.security.storageMode,lastAuditAt:p.security.lastAuditAt})}),null,e.jsx(We,{}),(V=m.data)!=null&&V.session?e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 rounded-[18px] border border-[color-mix(in_srgb,var(--success)_26%,var(--ui-border-subtle)_74%)] bg-[var(--ui-success-soft)] px-4 py-3 text-sm text-[var(--ui-ink-medium)]",children:[e.jsxs("div",{children:["Operator session active as"," ",e.jsx("span",{className:"font-medium text-[var(--ui-ink-strong)]",children:m.data.session.actorLabel}),"."]}),e.jsx(k,{variant:"secondary",size:"sm",pending:T.isLoading,pendingLabel:"Resetting session",onClick:()=>void ue(),children:"Reset operator session"})]}):null,e.jsxs("div",{className:"grid gap-4",children:[U?null:e.jsx(re,{healthy:!1}),e.jsxs("form",{className:"grid gap-4",onSubmit:c.handleSubmit(async s=>{await C.mutateAsync(s)}),children:[e.jsxs($,{className:"p-4",children:[e.jsx("div",{className:N,children:"Operator profile"}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Name"}),e.jsx(_,{...c.register("profile.operatorName")})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Email"}),e.jsx(_,{...c.register("profile.operatorEmail")})]})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Title"}),e.jsx(_,{...c.register("profile.operatorTitle")})]}),e.jsx("div",{className:`mt-2 ${N}`,children:"Execution policy"}),e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,0.7fr)_minmax(0,1.3fr)]",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Maximum active tasks"}),e.jsx(_,{type:"number",min:1,max:8,...c.register("execution.maxActiveTasks",{valueAsNumber:!0})})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Time accounting mode"}),e.jsx("div",{className:"grid gap-2 md:grid-cols-3",children:[{value:"split",label:"Split",description:"Multitasking divides credited time across active tasks."},{value:"parallel",label:"Parallel",description:"Every active task receives full credited wall time."},{value:"primary_only",label:"Primary only",description:"Only the highlighted task earns credited time during overlap."}].map(s=>e.jsxs("label",{className:`grid gap-2 ${P} px-3 py-3`,children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"radio",value:s.value,...c.register("execution.timeAccountingMode")}),e.jsx("span",{className:"text-[var(--ui-ink-strong)]",children:s.label})]}),e.jsx("span",{className:ie,children:s.description})]},s.value))})]})]}),e.jsx("div",{className:`mt-2 ${N}`,children:"Notification rules"}),e.jsxs("label",{className:`flex items-center justify-between ${P} px-3 py-2.5`,children:[e.jsx("span",{className:"text-[var(--ui-ink-medium)]",children:"Goal drift alerts"}),e.jsx("input",{type:"checkbox",...c.register("notifications.goalDriftAlerts")})]}),e.jsxs("label",{className:`flex items-center justify-between ${P} px-3 py-2.5`,children:[e.jsx("span",{className:"text-[var(--ui-ink-medium)]",children:"Daily quest reminders"}),e.jsx("input",{type:"checkbox",...c.register("notifications.dailyQuestReminders")})]}),e.jsxs("label",{className:`flex items-center justify-between ${P} px-3 py-2.5`,children:[e.jsx("span",{className:"text-[var(--ui-ink-medium)]",children:"Achievement celebrations"}),e.jsx("input",{type:"checkbox",...c.register("notifications.achievementCelebrations")})]})]}),e.jsxs($,{className:"p-4",children:[e.jsx("div",{className:N,children:"Theme calibration"}),e.jsx("p",{className:F,children:"Switch between Forge dark and light presets, follow the system palette, or save your own shell theme."}),e.jsx("div",{className:"grid gap-2 xl:grid-cols-3",children:Qe.map(s=>{const v=te(s.value,y),h=D===s.value;return e.jsxs("button",{type:"button",onClick:()=>void B(s.value,(s.value==="custom",y)),className:`rounded-[18px] border px-3 py-3 text-left transition ${h?"border-[color-mix(in_srgb,var(--primary)_34%,var(--ui-border-subtle)_66%)] bg-[var(--ui-accent-soft)] shadow-[var(--ui-shadow-soft)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]"}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold text-[var(--ui-ink-strong)]",children:s.value==="custom"?y.label:s.label}),e.jsx("div",{className:"mt-1 line-clamp-2 text-xs leading-5 text-[var(--ui-ink-soft)]",children:s.description})]}),e.jsx("div",{className:`mt-1 size-4 rounded-full border ${h?"border-[color-mix(in_srgb,var(--primary)_65%,var(--ui-border-subtle)_35%)] bg-[var(--primary)]":"border-[var(--ui-border-strong)]"}`})]}),e.jsx(Ze,{theme:v})]},s.value)})}),e.jsxs("div",{className:`mt-3 flex flex-wrap items-center justify-between gap-3 ${P} px-3 py-3`,children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-[var(--ui-ink-strong)]",children:"Custom theme editor"}),e.jsx("div",{className:`mt-1 ${F}`,children:"Save a custom Forge palette through a guided modal, or paste and upload JSON directly."})]}),e.jsx(k,{type:"button",variant:D==="custom"?"secondary":"ghost",onClick:()=>d(!0),pending:E.isPending,children:D==="custom"?"Edit custom theme":"Create custom theme"})]})]}),e.jsxs($,{className:"p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:N,children:"Gamification style"}),e.jsx("p",{className:F,children:"Choose the reward art style and download its optional trophy, unlock, and mascot sprites."})]}),J!=null&&J.installed?e.jsx("span",{className:"inline-flex rounded-full border border-[color-mix(in_srgb,var(--success)_26%,var(--ui-border-subtle)_74%)] bg-[var(--ui-success-soft)] px-3 py-1 text-xs font-medium text-[var(--success)]",children:"Selected style downloaded"}):e.jsx("span",{className:"inline-flex rounded-full border border-[color-mix(in_srgb,var(--warning)_26%,var(--ui-border-subtle)_74%)] bg-[var(--ui-warning-soft)] px-3 py-1 text-xs font-medium text-[var(--warning)]",children:"Selected style not downloaded"})]}),e.jsx("div",{className:"mt-3 grid gap-2 xl:grid-cols-3",children:Re.map(s=>{const v=G===s.value,h=H.find(he=>he.id===s.value),I=(h==null?void 0:h.installed)??!1,xe=i.isPending&&i.variables===s.value;return e.jsxs("div",{className:`grid gap-2 rounded-[18px] border p-2.5 text-left transition ${v?"border-[color-mix(in_srgb,var(--warning)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-warning-soft)] shadow-[var(--ui-shadow-soft)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]"}`,children:[e.jsx("button",{type:"button",onClick:()=>void ge(s.value),className:"grid gap-2 text-left","aria-label":`Select ${s.label}`,"aria-pressed":v,children:e.jsx(Ve,{selected:v,theme:s.value})}),e.jsxs("span",{className:"grid gap-1 px-1 pb-1",children:[e.jsx("span",{className:"text-sm font-semibold text-[var(--ui-ink-strong)]",children:s.label}),e.jsx("span",{className:"line-clamp-2 text-xs leading-5 text-[var(--ui-ink-soft)]",children:s.description}),e.jsx("span",{className:"mt-1 text-[11px] uppercase tracking-[0.14em] text-[var(--ui-ink-faint)]",children:I?`Downloaded ${(h==null?void 0:h.spriteCount)??0}/${(h==null?void 0:h.expectedSpriteCount)??0}`:"Not downloaded"}),e.jsxs(k,{type:"button",variant:I?"secondary":"primary",pending:xe,disabled:I||i.isPending,onClick:()=>i.mutate(s.value),children:[e.jsx(ve,{className:"size-4"}),I?"Downloaded":"Download"]})]})]},s.value)})}),r.isPending?e.jsx("div",{className:"text-sm text-[var(--ui-ink-faint)]",children:"Saving reward style…"}):null,i.isError?e.jsx("div",{className:"mt-3 rounded-[14px] border border-[color-mix(in_srgb,var(--danger)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-danger-soft)] px-3 py-2 text-sm text-[var(--danger)]",children:i.error instanceof Error?i.error.message:"Could not download the selected reward art."}):null]}),e.jsxs($,{className:"p-4",children:[e.jsx("div",{className:N,children:a("common.settings.localeLabel")}),e.jsx("p",{className:F,children:a("common.settings.localeDescription")}),e.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:[{value:"en",label:a("common.settings.localeEnglish")},{value:"fr",label:a("common.settings.localeFrench")}].map(s=>e.jsxs("label",{className:`flex items-center gap-3 ${P} px-3 py-3`,children:[e.jsx("input",{type:"radio",value:s.value,...c.register("localePreference")}),e.jsx("span",{className:"text-[var(--ui-ink-medium)]",children:s.label})]},s.value))}),e.jsx(k,{type:"submit",pending:C.isPending,pendingLabel:"Saving settings",children:"Save settings"})]})]}),U?e.jsx(re,{healthy:!0}):null,e.jsx(es,{integrityScore:p.security.integrityScore,storageMode:p.security.storageMode,lastAuditAt:p.security.lastAuditAt,doctor:me,doctorLoading:f.isFetching||ce.isLoading,onRefreshDoctor:()=>void f.refetch(),onApplyFix:s=>void pe(s),applyingFixId:de})]}),e.jsx(Xe,{open:t,onOpenChange:d,value:y,onSave:s=>void B("custom",s)})]})}export{ms as SettingsPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e,r as v}from"./vendor-Dnkkx2co.js";import{j as de,i as k,k as U}from"./state-vCcAT5Hq.js";import{u as Y}from"./forms-hB0SqEh-.js";import{S as ce}from"./settings-section-nav-Co0AaDG-.js";import{c as p,Z as _,W as ee,f as oe,u as me,eq as ue,er as xe,S as ge,E as pe,C as he,I as J,T as E,B as se,du as be,cW as ve,es as fe,et as je,ad as we}from"./index-QJkjKYzZ.js";import{m as ae}from"./motion-Lt5B1XuE.js";import{P as ye}from"./page-hero-CONuJu5J.js";import{M as re}from"./metric-tile-B-tDTcBt.js";import"./ui-C1iwpj2-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";function Ne(r){switch(r){case"platinum":return"bg-[var(--ui-accent-soft)] text-[var(--primary)]";case"gold":return"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]";case"silver":return"bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]";default:return"bg-[var(--ui-warning-soft)] text-[var(--warning)]"}}function ke(r){switch(r){case"surging":return"bg-[color-mix(in_srgb,var(--ui-accent-soft)_62%,var(--ui-success-soft)_38%)]";case"steady":return"bg-[var(--ui-accent-soft)]";default:return"bg-[color-mix(in_srgb,var(--ui-warning-soft)_54%,var(--ui-accent-soft)_46%)]"}}const P="min-w-0 overflow-hidden rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",te="min-w-0 overflow-hidden rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",A="font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",S="text-[var(--ui-ink-strong)]",$="text-[var(--ui-ink-soft)]",I="text-[var(--ui-ink-faint)]",q="bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]";function _e({profile:r,achievements:m,milestoneRewards:d,momentumPulse:u,recentLedger:R=[],className:j,tone:X="core"}){const w=m.filter(t=>t.unlocked),h=(w.length>0?w:m).slice(0,3),C=d.slice(0,3),M=R.slice(0,3),F=Math.min(100,Math.round(r.currentLevelXp/r.nextLevelXp*100));return e.jsxs("section",{className:_("min-w-0 overflow-hidden rounded-[30px] border border-[var(--ui-border-subtle)] bg-[var(--card-gradient)] shadow-[var(--card-shadow)]",X==="psyche"&&"border-[color-mix(in_srgb,var(--success)_18%,var(--ui-border-subtle)_82%)]",j),children:[e.jsx("div",{className:_("px-5 py-5",ke(u.status)),children:e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:A,children:"Weekly progress"}),e.jsx("h2",{className:`mt-3 font-display text-3xl leading-none lg:text-4xl ${S}`,children:u.headline}),e.jsx("p",{className:`mt-3 max-w-3xl text-sm leading-7 ${$}`,children:u.detail})]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap gap-2",children:[e.jsxs(p,{wrap:!0,className:q,children:["Level ",r.level]}),e.jsxs(p,{wrap:!0,className:q,children:[r.streakDays," day streak"]}),e.jsxs(p,{wrap:!0,className:q,children:[r.weeklyXp," weekly XP"]})]})]})}),e.jsxs("div",{className:"grid gap-5 px-5 py-5 xl:grid-cols-[minmax(0,1.2fr)_minmax(0,0.8fr)]",children:[e.jsxs("div",{className:"grid gap-5",children:[e.jsxs(ae.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{duration:.24,ease:"easeOut"},className:P,children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:`font-medium ${S}`,children:"Next reward"}),e.jsx("div",{className:`mt-2 text-sm ${$}`,children:u.nextMilestoneLabel})]}),e.jsx(p,{wrap:!0,className:"max-w-[12rem] shrink-0 self-start text-[var(--tertiary)]",children:u.celebrationLabel})]}),e.jsx("div",{className:"mt-5",children:e.jsx(ee,{value:F})}),e.jsxs("div",{className:`mt-3 flex flex-wrap items-center justify-between gap-3 text-xs uppercase tracking-[0.16em] ${I}`,children:[e.jsxs("span",{children:[r.currentLevelXp,"/",r.nextLevelXp," XP"]}),e.jsxs("span",{children:[r.comboMultiplier.toFixed(2),"x combo"]})]})]}),e.jsx("div",{className:"grid gap-3 md:grid-cols-3",children:h.map((t,c)=>e.jsxs(ae.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{duration:.24,delay:.04*c,ease:"easeOut"},className:P,children:[e.jsxs("div",{className:"flex min-w-0 items-start justify-between gap-3",children:[e.jsx("div",{className:`min-w-0 flex-1 font-medium ${S}`,children:t.title}),e.jsx(p,{wrap:!0,className:_("max-w-[8rem] shrink-0 self-start",Ne(t.tier)),children:t.tier})]}),e.jsx("div",{className:`mt-2 text-sm leading-6 ${$}`,children:t.summary}),e.jsx("div",{className:`mt-4 text-xs uppercase tracking-[0.16em] ${I}`,children:t.progressLabel})]},t.id))})]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:P,children:[e.jsx("div",{className:A,children:"Rewards in progress"}),e.jsx("div",{className:"mt-4 grid gap-3",children:C.map(t=>{const c=Math.min(100,Math.round(t.current/t.target*100));return e.jsxs("div",{className:te,children:[e.jsxs("div",{className:"flex min-w-0 items-start justify-between gap-3",children:[e.jsx("div",{className:`min-w-0 flex-1 font-medium ${S}`,children:t.title}),e.jsx(p,{wrap:!0,className:_("max-w-[10.5rem] shrink-0 self-start",t.completed?"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)]":q),children:t.rewardLabel})]}),e.jsx("div",{className:`mt-2 text-sm ${$}`,children:t.summary}),e.jsx("div",{className:"mt-4",children:e.jsx(ee,{value:c})}),e.jsx("div",{className:`mt-3 text-xs uppercase tracking-[0.16em] ${I}`,children:t.progressLabel})]},t.id)})})]}),M.length>0?e.jsxs("div",{className:P,children:[e.jsx("div",{className:A,children:"Recent XP changes"}),e.jsx("div",{className:"mt-4 grid gap-3",children:M.map(t=>e.jsxs("div",{className:te,children:[e.jsxs("div",{className:"flex min-w-0 items-start justify-between gap-3",children:[e.jsx("div",{className:`min-w-0 flex-1 font-medium ${S}`,children:t.reasonTitle}),e.jsxs(p,{wrap:!0,className:_("max-w-[8rem] shrink-0 self-start",t.deltaXp>=0?"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)]":"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]"),children:[t.deltaXp>0?"+":"",t.deltaXp," XP"]})]}),e.jsx("div",{className:`mt-2 text-sm ${$}`,children:t.reasonSummary}),e.jsx("div",{className:`mt-3 text-xs uppercase tracking-[0.16em] ${I}`,children:oe(t.createdAt)})]},t.id))})]}):null]})]})]})}const Q="min-w-0 rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",ie="min-w-0 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",B="min-w-0 rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-3 text-sm text-[var(--ui-ink-strong)] outline-none transition focus:border-[var(--primary)]/35 focus:bg-[var(--ui-surface-3)]",Se="font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",O="text-[var(--ui-ink-strong)]",n="text-[var(--ui-ink-soft)]",$e="text-[var(--ui-ink-faint)]",ne="text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]",Re="mt-4 rounded-[18px] border border-[color-mix(in_srgb,var(--success)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-success-soft)] p-4 text-sm text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)]";function Xe(r){return JSON.stringify(r,null,2)}function le(r){const m=r.trim();if(!m)return{};const d=JSON.parse(m);if(!d||typeof d!="object"||Array.isArray(d))throw new Error("Expected a JSON object.");return d}function Qe(){var W,G,H;const r=me(),m=de(),[d,u]=v.useState(""),[R,j]=v.useState(null),[X,w]=v.useState(null),h=k({queryKey:["forge-operator-session"],queryFn:be}),C=h.isSuccess,M=k({queryKey:["forge-xp-metrics"],queryFn:ve}),F=k({queryKey:["forge-reward-rules"],queryFn:fe,enabled:C}),t=k({queryKey:["forge-reward-ledger"],queryFn:()=>je(30),enabled:C}),c=k({queryKey:["forge-psyche-overview"],queryFn:async()=>(await we()).overview}),b=Y({defaultValues:{title:"",description:"",active:!0,configJson:"{}"}}),l=Y({defaultValues:{entityType:"task",entityId:"",deltaXp:15,reasonTitle:"Operator bonus",reasonSummary:"Manual boost for a meaningful action captured with good provenance.",metadataJson:"{}"}}),K=async()=>{await Promise.all([m.invalidateQueries({queryKey:["forge-xp-metrics"]}),m.invalidateQueries({queryKey:["forge-reward-rules"]}),m.invalidateQueries({queryKey:["forge-reward-ledger"]})])},D=U({mutationFn:s=>ue(s.ruleId,{title:s.title,description:s.description,active:s.active,config:s.config}),onSuccess:K}),f=U({mutationFn:xe,onSuccess:K}),x=((W=F.data)==null?void 0:W.rules)??[],T=v.useMemo(()=>{var s,i,y,N,L,Z,z;return{system:[{id:"operator_manual_reward",label:"Operator reward ledger"}],goal:r.snapshot.goals.map(a=>({id:a.id,label:a.title})),project:r.snapshot.dashboard.projects.map(a=>({id:a.id,label:a.title})),task:r.snapshot.tasks.map(a=>({id:a.id,label:a.title})),habit:r.snapshot.habits.map(a=>({id:a.id,label:a.title})),tag:r.snapshot.tags.map(a=>({id:a.id,label:a.name})),note:[],insight:[],psyche_value:(((s=c.data)==null?void 0:s.values)??[]).map(a=>({id:a.id,label:a.title})),behavior_pattern:(((i=c.data)==null?void 0:i.patterns)??[]).map(a=>({id:a.id,label:a.title})),behavior:(((y=c.data)==null?void 0:y.behaviors)??[]).map(a=>({id:a.id,label:a.title})),belief_entry:(((N=c.data)==null?void 0:N.beliefs)??[]).map(a=>({id:a.id,label:a.statement})),mode_profile:(((L=c.data)==null?void 0:L.modes)??[]).map(a=>({id:a.id,label:a.title})),flashcard:(((Z=c.data)==null?void 0:Z.flashcards)??[]).map(a=>({id:a.id,label:a.title||a.message})),trigger_report:(((z=c.data)==null?void 0:z.reports)??[]).map(a=>({id:a.id,label:a.title}))}},[c.data,r.snapshot.dashboard.projects,r.snapshot.goals,r.snapshot.habits,r.snapshot.tags,r.snapshot.tasks]);v.useEffect(()=>{var N;const s=l.getValues("entityType"),i=l.getValues("entityId"),y=T[s]??[];i&&y.some(L=>L.id===i)||l.setValue("entityId",((N=y[0])==null?void 0:N.id)??"")},[l,T]),v.useEffect(()=>{x.length&&(!d||!x.some(s=>s.id===d))&&u(x[0].id)},[x,d]);const g=x.find(s=>s.id===d)??x[0]??null;v.useEffect(()=>{g&&(b.reset({title:g.title,description:g.description,active:g.active,configJson:Xe(g.config)}),j(null))},[g,b]);const o=(G=M.data)==null?void 0:G.metrics,V=(((H=t.data)==null?void 0:H.ledger)??[]).filter(s=>s.metadata.manual===!0).slice(0,8);return h.isLoading?e.jsx(ge,{eyebrow:"Settings · Rewards",title:"Loading reward controls",description:"Establishing the operator session and fetching reward configuration.",columns:2,blocks:6}):h.isError?e.jsx(pe,{eyebrow:"Settings · Rewards",error:h.error,onRetry:()=>void h.refetch()}):e.jsxs("div",{className:"mx-auto grid w-full max-w-[1220px] gap-5",children:[e.jsx(ye,{title:"Rewards",description:"XP command deck, reward rule editor, manual bonus grants, and ledger history."}),e.jsx(ce,{}),e.jsx("div",{className:"grid gap-5",children:e.jsxs(he,{children:[e.jsx("div",{className:Se,children:"Reward operations"}),e.jsxs("div",{className:"mt-4 grid gap-4",children:[o?e.jsx(_e,{profile:o.profile,achievements:o.achievements,milestoneRewards:o.milestoneRewards,momentumPulse:o.momentumPulse,recentLedger:o.recentLedger}):null,o?e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsx(re,{label:"Total XP",value:o.profile.totalXp,tone:"core"}),e.jsx(re,{label:"Daily ambient",value:`${o.dailyAmbientXp} / ${o.dailyAmbientCap}`,tone:"core"})]}):null,e.jsxs("div",{className:"grid gap-4 xl:grid-cols-2",children:[e.jsxs("div",{className:Q,children:[e.jsx("div",{className:`font-medium ${O}`,children:"Reward rule editor"}),x.length>0?e.jsxs("form",{className:"mt-4 grid gap-4",onSubmit:b.handleSubmit(async s=>{try{j(null);const i=le(s.configJson);if(!g)return;await D.mutateAsync({ruleId:g.id,title:s.title,description:s.description,active:s.active,config:i})}catch(i){j(i instanceof Error?i.message:"Invalid reward rule config.")}}),children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:`text-sm ${n}`,children:"Rule"}),e.jsx("select",{className:B,value:d,onChange:s=>u(s.target.value),children:x.map(s=>e.jsx("option",{value:s.id,children:s.title},s.id))})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:`text-sm ${n}`,children:"Title"}),e.jsx(J,{...b.register("title")})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:`text-sm ${n}`,children:"Description"}),e.jsx(E,{className:"min-h-24",...b.register("description")})]}),e.jsxs("label",{className:"flex min-w-0 items-center justify-between gap-3 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsx("span",{className:n,children:"Rule is active"}),e.jsx("input",{type:"checkbox",...b.register("active")})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:`text-sm ${n}`,children:"Config JSON"}),e.jsx(E,{className:"min-h-28 font-mono text-xs",...b.register("configJson")})]}),R?e.jsx("div",{className:`text-sm ${ne}`,children:R}):null,e.jsx(se,{type:"submit",pending:D.isPending,pendingLabel:"Saving rule",children:"Save reward rule"})]}):e.jsx("div",{className:`mt-4 text-sm ${n}`,children:"Loading reward rules..."})]}),e.jsxs("div",{className:Q,children:[e.jsx("div",{className:`font-medium ${O}`,children:"Manual bonus XP"}),e.jsxs("form",{className:"mt-4 grid gap-4",onSubmit:l.handleSubmit(async s=>{try{w(null);const i=le(s.metadataJson);await f.mutateAsync({entityType:s.entityType,entityId:s.entityId,deltaXp:s.deltaXp,reasonTitle:s.reasonTitle,reasonSummary:s.reasonSummary,metadata:i}),l.reset({...s,entityId:"",reasonTitle:"Operator bonus",reasonSummary:"Manual boost for a meaningful action captured with good provenance.",metadataJson:"{}"})}catch(i){w(i instanceof Error?i.message:"Invalid metadata payload.")}}),children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:`text-sm ${n}`,children:"Entity type"}),e.jsx("select",{className:B,...l.register("entityType"),children:Object.keys(T).map(s=>e.jsx("option",{value:s,children:s.replaceAll("_"," ")},s))})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:`text-sm ${n}`,children:"Entity id"}),e.jsx("select",{className:B,...l.register("entityId"),children:(T[l.watch("entityType")]??[]).map(s=>e.jsx("option",{value:s.id,children:s.label},s.id))})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:`text-sm ${n}`,children:"Delta XP"}),e.jsx(J,{type:"number",...l.register("deltaXp",{valueAsNumber:!0})})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:`text-sm ${n}`,children:"Reason title"}),e.jsx(J,{...l.register("reasonTitle")})]})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:`text-sm ${n}`,children:"Reason summary"}),e.jsx(E,{className:"min-h-24",...l.register("reasonSummary")})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:`text-sm ${n}`,children:"Metadata JSON"}),e.jsx(E,{className:"min-h-24 font-mono text-xs",...l.register("metadataJson")})]}),X?e.jsx("div",{className:`text-sm ${ne}`,children:X}):null,e.jsx(se,{type:"submit",pending:f.isPending,pendingLabel:"Issuing bonus",children:"Issue bonus XP"})]}),f.data?e.jsxs("div",{className:Re,children:["Granted ",f.data.reward.deltaXp>0?"+":"",f.data.reward.deltaXp," XP for"," ",e.jsx("strong",{children:f.data.reward.reasonTitle}),"."]}):null]})]}),e.jsxs("div",{className:Q,children:[e.jsx("div",{className:`font-medium ${O}`,children:"Manual bonus history"}),e.jsx("div",{className:"mt-4 grid gap-3",children:V.length===0?e.jsx("div",{className:`${ie} text-sm ${n}`,children:"No manual bonus grants yet."}):V.map(s=>e.jsxs("div",{className:ie,children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:`min-w-0 break-words font-medium ${O}`,children:s.reasonTitle}),e.jsxs(p,{wrap:!0,className:s.deltaXp>=0?"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)]":"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]",children:[s.deltaXp>0?"+":"",s.deltaXp," XP"]})]}),e.jsx("div",{className:`mt-2 text-sm leading-6 ${n}`,children:s.reasonSummary||"No summary supplied."}),e.jsxs("div",{className:`mt-2 break-words text-xs uppercase tracking-[0.16em] [overflow-wrap:anywhere] ${$e}`,children:[s.entityType," · ",s.entityId," ·"," ",new Date(s.createdAt).toLocaleString()]})]},s.id))})]})]})]})})]})}export{Qe as SettingsRewardsPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as g,j as e,aC as ce}from"./vendor-Dnkkx2co.js";import{i as de,k as Z}from"./state-vCcAT5Hq.js";import{S as he}from"./settings-section-nav-Co0AaDG-.js";import{P as ue}from"./page-hero-CONuJu5J.js";import{i as pe,C as ge,B as me,M as xe}from"./graph-DDUZNRsO.js";import{C as F,aq as fe,c as b,U as E,Q as ie,F as $,j as H,I as T,T as be,W as ve,u as je,eu as we,ev as ye,ew as Ne,B as J,ex as ke}from"./index-QJkjKYzZ.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";const ae=[{id:"visibility",label:"Discovery and visibility",description:"What the source user can discover, inspect, and pull into read flows on the target side.",rights:[{key:"discoverable",label:"Discoverable",description:"The target appears as a reachable collaborator in the source user's graph and pickers."},{key:"canListUsers",label:"List users",description:"The source user can include the target in directory, comparison, and routing surfaces."},{key:"canReadProfile",label:"Read profile",description:"The source user can inspect the target's identity card, handle, type, and description."},{key:"canReadEntities",label:"Read entities",description:"The source user can read the target's goals, projects, tasks, notes, strategies, and related records."},{key:"canSearchEntities",label:"Search entities",description:"The source user can find the target's work through Forge search and entity pickers."}]},{id:"coordination",label:"Messaging, context, and handoff",description:"What the source user can message, connect, and coordinate on the target side before changing execution.",rights:[{key:"canLinkEntities",label:"Share context",description:"The source user can attach the target's records into shared notes, strategies, calendar context, and cross-owner plans."},{key:"canCoordinate",label:"Message and coordinate",description:"The source user can communicate with the target through Forge, hand off work, and coordinate execution."},{key:"canViewMetrics",label:"View metrics",description:"The source user can inspect the target's XP, alignment, and progress metrics."},{key:"canViewActivity",label:"View activity",description:"The source user can inspect the target's activity stream, evidence, and execution trail."}]},{id:"execution",label:"Plan and execution control",description:"What the source user can actually change on the target side once collaboration is trusted.",rights:[{key:"canManageStrategies",label:"Manage strategies",description:"The source user can draft and update strategies that belong to the target."},{key:"canCreateOnBehalf",label:"Create on behalf",description:"The source user can intentionally create new target-owned entities."},{key:"canAffectEntities",label:"Affect entities",description:"The source user can mutate work that belongs to the target."}]}],Ce=[{id:"full_collab",label:"Full collaboration",description:"Use when two humans or agents can see, coordinate, plan, and change each other's work.",rights:{discoverable:!0,canListUsers:!0,canReadProfile:!0,canReadEntities:!0,canSearchEntities:!0,canLinkEntities:!0,canCoordinate:!0,canAffectEntities:!0,canManageStrategies:!0,canCreateOnBehalf:!0,canViewMetrics:!0,canViewActivity:!0}},{id:"coordination_only",label:"Coordinate only",description:"Use when the source user may see and coordinate with the target but should not directly mutate target-owned work.",rights:{discoverable:!0,canListUsers:!0,canReadProfile:!0,canReadEntities:!0,canSearchEntities:!0,canLinkEntities:!0,canCoordinate:!0,canAffectEntities:!1,canManageStrategies:!0,canCreateOnBehalf:!1,canViewMetrics:!0,canViewActivity:!0}},{id:"observe_only",label:"Observe only",description:"Use when the source user should keep visibility into the target without planning or execution control.",rights:{discoverable:!0,canListUsers:!0,canReadProfile:!0,canReadEntities:!0,canSearchEntities:!0,canLinkEntities:!1,canCoordinate:!1,canAffectEntities:!1,canManageStrategies:!1,canCreateOnBehalf:!1,canViewMetrics:!0,canViewActivity:!0}},{id:"hidden",label:"Hidden edge",description:"Use when this direction should stop discovering, reading, or acting on the target.",rights:{discoverable:!1,canListUsers:!1,canReadProfile:!1,canReadEntities:!1,canSearchEntities:!1,canLinkEntities:!1,canCoordinate:!1,canAffectEntities:!1,canManageStrategies:!1,canCreateOnBehalf:!1,canViewMetrics:!1,canViewActivity:!1}}],A=ae.reduce((s,n)=>s+n.rights.length,0);function P(s){return Object.values(s.config.rights).filter(Boolean).length}function re(s){const n=[];return s.config.rights.canReadEntities&&n.push("See"),s.config.rights.canCoordinate&&n.push("Message"),s.config.rights.canManageStrategies&&n.push("Plan"),s.config.rights.canAffectEntities&&n.push("Affect"),n.join(" · ")||"Hidden"}function Ue(s){return!s.config.rights.discoverable&&!s.config.rights.canReadEntities?"Hidden":s.config.rights.canAffectEntities&&s.config.rights.canManageStrategies?"Trusted":s.config.rights.canCoordinate||s.config.rights.canLinkEntities?"Coordinated":"Observed"}function ne(s){return[{id:"see",label:"See",enabled:s.config.rights.discoverable&&s.config.rights.canReadEntities&&s.config.rights.canSearchEntities},{id:"message",label:"Message",enabled:s.config.rights.canCoordinate},{id:"share",label:"Share context",enabled:s.config.rights.canLinkEntities},{id:"plan",label:"Plan",enabled:s.config.rights.canManageStrategies},{id:"affect",label:"Affect",enabled:s.config.rights.canAffectEntities||s.config.rights.canCreateOnBehalf}]}function Ee(s,n){return Object.entries(n.rights).every(([i,u])=>s.config.rights[i]===u)}function Se(s,n){const i=s.filter(a=>a.kind==="human"),u=s.filter(a=>a.kind==="bot"),p={x:560,y:360},m={width:226,height:132},d=i[0]??null,w=[...i.slice(d?1:0).map(a=>({user:a,radius:245,offset:-90})),...u.map(a=>({user:a,radius:390,offset:-90}))],f=w.length,y=[...d?[{user:d,position:{x:p.x-m.width/2,y:p.y-m.height/2}}]:[],...w.map((a,c)=>{const h=(a.offset+360/Math.max(f,1)*c)*Math.PI/180;return{user:a.user,position:{x:p.x+Math.cos(h)*a.radius-m.width/2,y:p.y+Math.sin(h)*a.radius-m.height/2}}})],C=new Set(n.selectedGrant?[n.selectedGrant.subjectUserId,n.selectedGrant.targetUserId]:n.selectedUserId?[n.selectedUserId]:[]);return y.map(({user:a,position:c})=>{const h=C.has(a.id),t=a.id===n.selectedUserId;return{id:a.id,position:c,draggable:!1,selectable:!1,data:{label:e.jsxs("div",{className:`min-w-[206px] rounded-[22px] border px-4 py-4 shadow-[var(--ui-shadow-soft)] transition ${t?"border-[color-mix(in_srgb,var(--warning)_45%,var(--ui-border-subtle)_55%)] bg-[var(--ui-warning-soft)]":h?"border-[color-mix(in_srgb,var(--primary)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-accent-soft)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)]"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(E,{user:a}),e.jsx(b,{tone:"meta",children:a.kind})]}),e.jsxs("div",{className:"mt-3 text-xs text-[var(--ui-ink-soft)]",children:["@",a.handle]}),e.jsx("div",{className:"mt-2 line-clamp-2 text-xs leading-5 text-[var(--ui-ink-faint)]",children:a.description||"No user description yet."})]})},style:{background:"transparent",border:"none",padding:0}}})}function Ie(s,n,i){return s.filter(u=>u.subjectUserId!==u.targetUserId).map(u=>{const p=n===u.id,m=i!==null&&(u.subjectUserId===i||u.targetUserId===i),d=P(u),v=p?"var(--warning)":!u.config.rights.discoverable&&!u.config.rights.canReadEntities?"var(--danger)":m?"var(--primary)":"var(--ui-border-strong)";return{id:u.id,source:u.subjectUserId,target:u.targetUserId,label:`${re(u)} · ${d}/${A}`,markerEnd:{type:xe.ArrowClosed,color:v},labelStyle:{fill:p?"var(--warning)":"var(--ui-ink-medium)",fontSize:11,fontWeight:600},labelBgStyle:{fill:p?"var(--ui-warning-soft)":"var(--ui-surface-1)",stroke:p?"color-mix(in_srgb,var(--warning)_36%,var(--ui-border-subtle)_64%)":"var(--ui-border-subtle)",strokeWidth:1},labelBgPadding:[7,5],labelBgBorderRadius:8,style:{stroke:v,strokeWidth:p?2.5:m?1.8:1.25},animated:p}})}function Me({users:s,grants:n,selectedGrantId:i=null,selectedUserId:u=null,onOpenGrant:p,onOpenUser:m}){const d=n.find(c=>c.id===i)??null,v=g.useMemo(()=>Se(s,{selectedUserId:u,selectedGrant:d}),[d,u,s]),w=g.useMemo(()=>Ie(n,i,u),[n,i,u]),f=g.useMemo(()=>n.filter(c=>c.subjectUserId!==c.targetUserId),[n]),y=f.filter(c=>P(c)===A).length,C=f.filter(c=>c.config.rights.canCoordinate).length,a=f.filter(c=>c.config.rights.canAffectEntities||c.config.rights.canCreateOnBehalf).length;return e.jsxs(F,{className:"overflow-hidden p-0",children:[e.jsxs("div",{className:"grid gap-4 border-b border-[var(--ui-border-subtle)] px-5 py-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"max-w-3xl",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Directed relationship graph"}),e.jsx(fe,{content:"Keep Forge, OpenClaw, Hermes, and the browser on the same runtime and storage root when these arrows should describe one shared human and bot system.",label:"Explain the shared runtime rule"})]}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Click a user card to open that user's settings. Click any arrow to open the exact directional relationship flow for that lane."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(b,{tone:"meta",children:[f.length," edges"]}),e.jsxs(b,{className:"bg-[var(--ui-success-soft)] text-[var(--success)]",children:[y," fully open"]})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Full collaboration"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:y}),e.jsx("div",{className:"text-xs leading-5 text-[var(--ui-ink-faint)]",children:"Directions still running with the default fully open posture."})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Coordination lanes"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:C}),e.jsx("div",{className:"text-xs leading-5 text-[var(--ui-ink-faint)]",children:"Directions allowed to coordinate directly through Forge."})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Execution control"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:a}),e.jsx("div",{className:"text-xs leading-5 text-[var(--ui-ink-faint)]",children:"Directions allowed to create or mutate target-owned work."})]})]})]}),e.jsx("div",{className:"h-[clamp(26rem,58vh,42rem)] bg-[linear-gradient(180deg,var(--ui-surface-2),var(--ui-surface-1))] sm:h-[min(72vh,54rem)] sm:min-h-[34rem]",children:e.jsxs(pe,{className:"user-relationship-flow",nodes:v,edges:w,fitView:!0,fitViewOptions:{padding:.1,maxZoom:.95},nodesDraggable:!1,nodesConnectable:!1,elementsSelectable:!0,onNodeClick:(c,h)=>{m(h.id)},onEdgeClick:(c,h)=>{p(h.id)},attributionPosition:"bottom-left",children:[e.jsx(ge,{showInteractive:!1}),e.jsx(me,{gap:28,size:1,color:"var(--ui-border-subtle)"})]})})]})}const O="rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",Y="text-sm font-medium text-[var(--ui-ink-strong)]",Oe="text-sm leading-6 text-[var(--ui-ink-soft)]",Re={kind:"human",handle:"",displayName:"",description:"",accentColor:"#c0c1ff"};function ee(s){return s?{kind:s.kind,handle:s.handle,displayName:s.displayName,description:s.description,accentColor:s.accentColor}:Re}function Fe({open:s,onOpenChange:n,user:i,grants:u,ownership:p,xp:m,pending:d=!1,onSubmit:v,onOpenRelationship:w}){const[f,y]=g.useState(()=>ee(i)),[C,a]=g.useState(null);g.useEffect(()=>{s&&(y(ee(i)),a(null))},[s,i]);const c=g.useMemo(()=>u.filter(o=>o.subjectUserId!==o.targetUserId),[u]),h=g.useMemo(()=>i?c.filter(o=>o.subjectUserId===i.id):[],[c,i]),t=g.useMemo(()=>i?c.filter(o=>o.targetUserId===i.id):[],[c,i]),N=[{id:"identity",eyebrow:i?"Edit user":"Create user",title:i?"Update the user identity":"Add a human or bot user",description:"Set the owner type and the public identity Forge will use across ownership, routing, and collaboration surfaces.",render:(o,x)=>e.jsxs(e.Fragment,{children:[e.jsx($,{label:"Kind",description:"Humans represent real people. Bots represent agents or automations with their own ownership lane.",children:e.jsx(H,{columns:2,value:o.kind,onChange:k=>x({kind:k}),options:[{value:"human",label:"Human",description:"Use for a real person in the Forge runtime."},{value:"bot",label:"Bot",description:"Use for an agent, assistant, or automation actor."}]})}),e.jsx($,{label:"Handle",description:"This becomes the stable short id shown as @handle.",hint:"Use lowercase and a durable label, for example forge-operator or planner-bot.",children:e.jsx(T,{value:o.handle,onChange:k=>x({handle:k.target.value}),placeholder:"forge-operator"})}),e.jsx($,{label:"Display name",description:"This is the human-readable label used across the UI.",children:e.jsx(T,{value:o.displayName,onChange:k=>x({displayName:k.target.value}),placeholder:"Forge Operator"})})]})},{id:"profile",eyebrow:"Profile",title:"Describe the user lane",description:"Capture what this user represents in the shared Forge runtime and pick the accent color that helps the lane stay recognizable.",render:(o,x)=>e.jsxs(e.Fragment,{children:[e.jsx($,{label:"Description",description:"Explain what this user is responsible for and what side of the system it represents.",children:e.jsx(be,{value:o.description,onChange:k=>x({description:k.target.value}),className:"min-h-36",placeholder:"Primary human operator for strategy, execution, and review."})}),e.jsx($,{label:"Accent color",description:"Forge uses this accent to help the user stand out in ownership and collaboration surfaces.",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(T,{value:o.accentColor,onChange:k=>x({accentColor:k.target.value}),placeholder:"#c0c1ff"}),e.jsx("div",{className:"size-10 shrink-0 rounded-full border border-[var(--ui-border-subtle)]",style:{backgroundColor:o.accentColor||"#c0c1ff"}})]})}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:`${O} px-4 py-3`,children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Owned records"}),e.jsx("div",{className:"mt-2 text-[var(--ui-ink-strong)]",children:(p==null?void 0:p.totalOwnedEntities)??0})]}),e.jsxs("div",{className:`${O} px-4 py-3`,children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Total XP"}),e.jsx("div",{className:"mt-2 text-[var(--ui-ink-strong)]",children:(m==null?void 0:m.totalXp)??0})]}),e.jsxs("div",{className:`${O} px-4 py-3`,children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Weekly XP"}),e.jsx("div",{className:"mt-2 text-[var(--ui-ink-strong)]",children:(m==null?void 0:m.weeklyXp)??0})]})]})]})},{id:"relationships",eyebrow:"Relationships",title:"Open directional relationship settings",description:"Each arrow is a separate contract. Open the exact lane you want to adjust and Forge will take you into the relationship flow.",render:()=>i?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`${O} p-4`,children:[e.jsx(E,{user:i}),e.jsxs("div",{className:`mt-3 ${Oe}`,children:["@",i.handle," · ",i.description||"No description yet."]})]}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:Y,children:"Outbound lanes"}),h.length>0?h.map(o=>e.jsxs("button",{type:"button",className:`${O} px-4 py-4 text-left transition hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]`,onClick:()=>w(o.id),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(E,{user:o.subjectUser}),e.jsx("span",{className:"text-[var(--ui-ink-faint)]",children:"→"}),e.jsx(E,{user:o.targetUser})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(b,{tone:"meta",children:re(o)}),e.jsxs(b,{tone:"meta",children:[P(o),"/",A," rights"]})]})]},o.id)):e.jsx("div",{className:"rounded-[20px] border border-dashed border-[var(--ui-border-subtle)] px-4 py-4 text-sm text-[var(--ui-ink-soft)]",children:"No outbound relationship lanes yet."})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:Y,children:"Inbound lanes"}),t.length>0?t.map(o=>e.jsxs("button",{type:"button",className:`${O} px-4 py-4 text-left transition hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]`,onClick:()=>w(o.id),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(E,{user:o.subjectUser}),e.jsx("span",{className:"text-[var(--ui-ink-faint)]",children:"→"}),e.jsx(E,{user:o.targetUser})]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:ne(o).map(x=>e.jsx(b,{className:x.enabled?"bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)]":"bg-[var(--ui-surface-1)] text-[var(--ui-ink-faint)] opacity-70",children:x.label},`${o.id}-${x.id}`))})]},o.id)):e.jsx("div",{className:"rounded-[20px] border border-dashed border-[var(--ui-border-subtle)] px-4 py-4 text-sm text-[var(--ui-ink-soft)]",children:"No inbound relationship lanes yet."})]})]})]}):e.jsx("div",{className:"rounded-[20px] border border-dashed border-[var(--ui-border-subtle)] px-4 py-4 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Create the user first, then Forge will generate the directional relationship lanes you can tune from here."})}];return e.jsx(ie,{open:s,onOpenChange:n,eyebrow:i?"User settings":"Create user",title:i?"User settings":"Create user",description:"Edit the user identity, clarify what this lane represents, and jump into relationship settings without crowding the page.",value:f,onChange:y,draftPersistenceKey:i?`users.settings.${i.id}`:"users.settings.new",steps:N,submitLabel:i?"Save user":"Create user",pending:d,pendingLabel:i?"Saving user":"Creating user",error:C,contentClassName:"lg:w-[min(58rem,calc(100vw-1.5rem))]",onSubmit:async()=>{const o=f.handle.trim(),x=f.displayName.trim();if(o.length===0){a("Add a handle before saving this user.");return}if(x.length===0){a("Add a display name before saving this user.");return}await v({userId:i==null?void 0:i.id,input:{kind:f.kind,handle:o,displayName:x,description:f.description.trim(),accentColor:f.accentColor.trim()||"#c0c1ff"}}),n(!1)}})}const _="rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",S="text-sm font-medium text-[var(--ui-ink-strong)]",G="text-sm leading-6 text-[var(--ui-ink-soft)]",Ae="text-xs leading-5 text-[var(--ui-ink-faint)]";function se(s,n){return{accessLevel:(s==null?void 0:s.accessLevel)??"manage",applyScope:"this_arrow",rights:{discoverable:(s==null?void 0:s.config.rights.discoverable)??!0,canListUsers:(s==null?void 0:s.config.rights.canListUsers)??!0,canReadProfile:(s==null?void 0:s.config.rights.canReadProfile)??!0,canReadEntities:(s==null?void 0:s.config.rights.canReadEntities)??!0,canSearchEntities:(s==null?void 0:s.config.rights.canSearchEntities)??!0,canLinkEntities:(s==null?void 0:s.config.rights.canLinkEntities)??!0,canCoordinate:(s==null?void 0:s.config.rights.canCoordinate)??!0,canAffectEntities:(s==null?void 0:s.config.rights.canAffectEntities)??!0,canManageStrategies:(s==null?void 0:s.config.rights.canManageStrategies)??!0,canCreateOnBehalf:(s==null?void 0:s.config.rights.canCreateOnBehalf)??!0,canViewMetrics:(s==null?void 0:s.config.rights.canViewMetrics)??!0,canViewActivity:(s==null?void 0:s.config.rights.canViewActivity)??!0}}}function $e({open:s,onOpenChange:n,grant:i,grants:u,pending:p=!1,onSubmit:m}){const d=g.useMemo(()=>i?u.find(a=>a.subjectUserId===i.targetUserId&&a.targetUserId===i.subjectUserId)??null:null,[i,u]),[v,w]=g.useState(()=>se(i,!!d));g.useEffect(()=>{s&&w(se(i,!!d))},[i,s,d]);const f=g.useMemo(()=>Object.values(v.rights).filter(Boolean).length,[v.rights]),y=Math.round(f/A*100),C=[{id:"posture",eyebrow:"Relationship posture",title:"Set the trust mode for this arrow",description:"Each arrow is directional. Decide whether you want to tune only this lane or mirror the same contract onto both directions.",render:(a,c)=>e.jsxs(e.Fragment,{children:[i?e.jsxs("div",{className:`${_} p-4`,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(E,{user:i.subjectUser}),e.jsx("span",{className:"text-[var(--ui-ink-faint)]",children:"→"}),e.jsx(E,{user:i.targetUser})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(b,{tone:"meta",children:Ue(i)}),e.jsxs(b,{tone:"meta",children:[P(i),"/",A," rights"]})]})]}):null,e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:S,children:"Access level"}),e.jsx(H,{columns:2,value:a.accessLevel,onChange:h=>c({accessLevel:h}),options:[{value:"view",label:"View",description:"Use when this lane should stay mostly observational."},{value:"manage",label:"Manage",description:"Use when the source side can actively collaborate or act."}]})]}),d?e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:S,children:"Apply scope"}),e.jsx(H,{columns:2,value:a.applyScope,onChange:h=>c({applyScope:h}),options:[{value:"this_arrow",label:"This arrow",description:"Only change the exact direction you opened."},{value:"both_arrows",label:"Both arrows",description:"Mirror the same contract onto the reverse direction too."}]})]}):null]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:S,children:"Quick preset"}),e.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:Ce.map(h=>e.jsxs("button",{type:"button",className:`rounded-[22px] border p-4 text-left transition ${i&&Ee(i,h)?"border-[color-mix(in_srgb,var(--warning)_32%,var(--ui-border-subtle)_68%)] bg-[var(--ui-warning-soft)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]"}`,onClick:()=>c({rights:{...a.rights,...h.rights}}),children:[e.jsx("div",{className:S,children:h.label}),e.jsx("div",{className:`mt-2 ${G}`,children:h.description})]},h.id))})]})]})},{id:"rights",eyebrow:"Rights",title:"Tune the individual permissions",description:"Use the preset as the starting point, then sharpen the exact boundaries only where this relationship needs them.",render:(a,c)=>e.jsx(e.Fragment,{children:ae.map(h=>e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:S,children:h.label}),e.jsx("div",{className:`mt-1 ${G}`,children:h.description})]}),e.jsx("div",{className:"grid gap-2",children:h.rights.map(t=>e.jsxs("label",{className:"flex items-start justify-between gap-3 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:S,children:t.label}),e.jsx("div",{className:`mt-1 ${Ae}`,children:t.description})]}),e.jsx("input",{type:"checkbox",checked:a.rights[t.key],onChange:N=>c({rights:{...a.rights,[t.key]:N.target.checked}})})]},t.key))})]},h.id))})},{id:"review",eyebrow:"Review",title:"Review the final relationship contract",description:"Check the enabled capabilities, confirm whether both directions should match, and then save the relationship.",render:a=>{var c,h;return e.jsx(e.Fragment,{children:e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:`${_} p-4`,children:[e.jsx("div",{className:S,children:"Capability coverage"}),e.jsx("div",{className:"mt-4",children:e.jsx(ve,{value:y})}),e.jsxs("div",{className:"mt-3 text-sm text-[var(--ui-ink-soft)]",children:[f,"/",A," rights enabled"]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:ne({...i??{id:"draft",subjectUserId:"",targetUserId:"",accessLevel:a.accessLevel,config:{self:!1,mutable:!0,linkedEntities:!0,rights:a.rights},createdAt:"",updatedAt:"",subjectUser:null,targetUser:null},accessLevel:a.accessLevel,config:{...(i==null?void 0:i.config)??{self:!1,mutable:!0,linkedEntities:!0},rights:a.rights}}).map(t=>e.jsx(b,{className:t.enabled?"bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)]":"bg-[var(--ui-surface-1)] text-[var(--ui-ink-faint)] opacity-70",children:t.label},t.id))})]}),e.jsxs("div",{className:`${_} p-4`,children:[e.jsx("div",{className:S,children:"Save scope"}),e.jsx("div",{className:`mt-3 ${G}`,children:a.applyScope==="both_arrows"&&d?"Forge will apply the same access level and rights to both directions of this pair.":"Forge will only update the exact arrow you opened."}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsxs(b,{tone:"meta",children:["access ",a.accessLevel]}),e.jsxs(b,{tone:"meta",children:["scope"," ",a.applyScope==="both_arrows"&&d?"both arrows":"this arrow"]})]}),d?e.jsxs("div",{className:"mt-4 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3 text-sm text-[var(--ui-ink-soft)]",children:["Reverse arrow available:"," ",((c=d.subjectUser)==null?void 0:c.displayName)??d.subjectUserId," ","→"," ",((h=d.targetUser)==null?void 0:h.displayName)??d.targetUserId]}):null]})]})})}}];return e.jsx(ie,{open:s,onOpenChange:n,eyebrow:"Relationship settings",title:"Relationship settings",description:"Edit the exact directional contract between two users without keeping the full rights editor pinned on the page.",value:v,onChange:w,draftPersistenceKey:i?`users.relationship.${i.id}`:"users.relationship.new",steps:C,submitLabel:"Save relationship",pending:p,pendingLabel:"Saving relationship",contentClassName:"lg:w-[min(62rem,calc(100vw-1.5rem))]",onSubmit:async()=>{i&&(await m({grantId:i.id,patch:{accessLevel:v.accessLevel,rights:v.rights},reverseGrantId:(d==null?void 0:d.id)??null,applyToReverse:v.applyScope==="both_arrows"&&d!==null}),n(!1))}})}const U="font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",M="text-sm leading-6 text-[var(--ui-ink-soft)]",te="text-xs leading-5 text-[var(--ui-ink-faint)]",R="rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]";function We(){var X;const s=je(),[n,i]=g.useState(null),[u,p]=g.useState(null),[m,d]=g.useState(!1),[v,w]=g.useState(!1),[f,y]=g.useState(""),C=de({queryKey:["forge-user-directory"],queryFn:ke}),a=async()=>{await Promise.all([s.refresh(),C.refetch()])},c=Z({mutationFn:async({input:r,userId:l})=>l?(await we(l,r)).user:(await ye(r)).user,onSuccess:async()=>{i(null),d(!1),await a()}}),h=Z({mutationFn:async({grantId:r,patch:l})=>(await Ne(r,l)).grant,onSuccess:a}),t=(X=C.data)==null?void 0:X.directory,N=(t==null?void 0:t.grants.find(r=>r.id===u))??null,o=g.useMemo(()=>new Map(((t==null?void 0:t.ownership)??[]).map(r=>[r.userId,r])),[t==null?void 0:t.ownership]),x=g.useMemo(()=>new Map(((t==null?void 0:t.xp)??[]).map(r=>[r.userId,r])),[t==null?void 0:t.xp]),k=g.useMemo(()=>{const r=new Map;for(const l of(t==null?void 0:t.grants)??[]){if(!l.targetUser||l.subjectUserId===l.targetUserId)continue;const j=r.get(l.subjectUserId)??[];j.push(l.targetUser),r.set(l.subjectUserId,j)}return r},[t==null?void 0:t.grants]),L=g.useMemo(()=>{const r=((t==null?void 0:t.grants)??[]).filter(l=>l.subjectUserId!==l.targetUserId);return{totalEdges:r.length,fullyOpenEdges:r.filter(l=>Object.values(l.config.rights).every(Boolean)).length,coordinationEdges:r.filter(l=>l.config.rights.canCoordinate).length,executionEdges:r.filter(l=>l.config.rights.canAffectEntities||l.config.rights.canCreateOnBehalf).length}},[t==null?void 0:t.grants]),B=f.trim().toLowerCase(),V=g.useMemo(()=>{const l=((t==null?void 0:t.users)??s.snapshot.users).filter(j=>B?[j.displayName,j.handle,j.kind,j.description].join(" ").toLowerCase().includes(B):!0);return{humans:l.filter(j=>j.kind==="human"),bots:l.filter(j=>j.kind==="bot")}},[t==null?void 0:t.users,B,s.snapshot.users]),le=(N==null?void 0:N.subjectUserId)??(n==null?void 0:n.id)??null,oe=(N==null?void 0:N.id)??null;return e.jsxs("div",{className:"mx-auto grid w-full max-w-[1440px] gap-5",children:[e.jsx(ue,{title:"Users",description:"Forge users can be human or bot. Ownership, search, and routing are prepared so work can move across both sides of the system.",badge:`${s.snapshot.users.length} users`}),e.jsx(he,{}),e.jsx(Fe,{open:m,onOpenChange:d,user:n,grants:(t==null?void 0:t.grants)??[],ownership:n?o.get(n.id)??null:null,xp:n?x.get(n.id)??null:null,pending:c.isPending,onSubmit:async r=>{await c.mutateAsync(r)},onOpenRelationship:r=>{d(!1),p(r),w(!0)}}),e.jsx($e,{open:v,onOpenChange:w,grant:N,grants:(t==null?void 0:t.grants)??[],pending:h.isPending,onSubmit:async r=>{await h.mutateAsync({grantId:r.grantId,patch:r.patch}),r.applyToReverse&&r.reverseGrantId&&await h.mutateAsync({grantId:r.reverseGrantId,patch:r.patch})}}),e.jsxs(F,{className:"grid gap-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:U,children:"Multi-user posture"}),e.jsx("div",{className:`mt-2 ${M}`,children:(t==null?void 0:t.posture.summary)??"Forge is preparing modular user access while keeping the current posture permissive."})]}),e.jsx(b,{tone:"meta",children:(t==null?void 0:t.posture.accessModel)??"permissive"})]}),e.jsx("div",{className:`flex items-center gap-3 ${R} px-4 py-3`,children:e.jsx(T,{value:f,onChange:r=>y(r.target.value),placeholder:"Search human, bot, @handle, or description"})})]}),e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:"grid gap-5",children:[e.jsxs(F,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:U,children:"Multi-agent onboarding"}),e.jsx("div",{className:`mt-2 ${M}`,children:"Forge now treats the users graph as the collaboration control plane. Create each human or bot here, keep the runtime shared, then narrow only the specific arrows that should stop seeing, coordinating, planning, or affecting another user."})]}),e.jsx(b,{tone:"meta",children:"default open"})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsxs("div",{className:`${R} px-4 py-3`,children:[e.jsx("div",{className:U,children:"Directional edges"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:L.totalEdges})]}),e.jsxs("div",{className:`${R} px-4 py-3`,children:[e.jsx("div",{className:U,children:"Fully open"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:L.fullyOpenEdges})]}),e.jsxs("div",{className:`${R} px-4 py-3`,children:[e.jsx("div",{className:U,children:"Coordination"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:L.coordinationEdges})]}),e.jsxs("div",{className:`${R} px-4 py-3`,children:[e.jsx("div",{className:U,children:"Execution control"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:L.executionEdges})]})]}),e.jsxs("div",{className:`grid gap-2 ${M}`,children:[e.jsx("div",{children:"1. Create the human and bot users that should exist in the shared Forge system."}),e.jsx("div",{children:"2. Point OpenClaw, Hermes, and the browser at the same Forge runtime and storage root."}),e.jsx("div",{children:"3. Use the graph below to decide what each direction can see, message, plan, or change."}),e.jsx("div",{children:"4. Keep strategy drafting open while the plan is negotiated, then lock the strategy once it becomes the contract."})]})]}),e.jsx(Me,{users:(t==null?void 0:t.users)??s.snapshot.users,grants:(t==null?void 0:t.grants)??[],selectedGrantId:oe,selectedUserId:le,onOpenUser:r=>{const l=((t==null?void 0:t.users)??s.snapshot.users).find(j=>j.id===r)??null;p(null),i(l),d(!0)},onOpenGrant:r=>{i(null),p(r),w(!0)}}),e.jsxs(F,{className:"grid gap-3",children:[e.jsx("div",{className:U,children:"Agent onboarding"}),e.jsx("div",{className:M,children:"OpenClaw, Hermes, and the Forge UI all read this same multi-user graph. Keep the defaults open while you are still wiring collaboration, then narrow specific arrows when one user or agent should stop seeing, messaging, planning, or changing another user's work."}),e.jsx("div",{className:M,children:"Forge now treats every owner as either human or bot, keeps search cross-user by default, and allows cross-owner links plus explicit coordination lanes between projects, tasks, notes, and strategies."}),e.jsx("div",{children:e.jsx(ce,{to:"/settings/agents",className:"inline-flex min-h-10 items-center justify-center rounded-[var(--radius-control)] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 py-2 text-[13px] font-medium text-[var(--ui-ink-strong)] transition hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]",children:"Open agent onboarding"})})]})]}),e.jsx(F,{children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:U,children:"User directory"}),e.jsx("div",{className:`mt-2 ${M}`,children:"Open any user to edit its identity and jump into the exact directional relationship lanes from the user settings flow."})]}),e.jsx(J,{onClick:()=>{p(null),i(null),d(!0)},children:"Create user"})]})}),e.jsx("div",{className:"grid gap-5",children:[{title:"Human users",users:V.humans},{title:"Bot users",users:V.bots}].map(r=>e.jsxs(F,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:U,children:r.title}),e.jsx(b,{tone:"meta",children:r.users.length})]}),e.jsx("div",{className:"mt-4 grid gap-3",children:r.users.map(l=>{var j,W,z,K,Q,q;return e.jsx("div",{className:`${R} px-4 py-4`,children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx(E,{user:l}),e.jsxs("div",{className:"mt-3 text-sm text-[var(--ui-ink-soft)]",children:["@",l.handle]}),e.jsx("div",{className:`mt-2 ${M}`,children:l.description||"No description yet."}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsxs(b,{className:"bg-[var(--primary)]/14 text-[var(--primary)]",children:[((j=x.get(l.id))==null?void 0:j.totalXp)??0," XP"]}),e.jsxs(b,{tone:"meta",children:[((W=x.get(l.id))==null?void 0:W.weeklyXp)??0," weekly"]}),e.jsxs(b,{tone:"meta",children:[((z=x.get(l.id))==null?void 0:z.rewardEventCount)??0," ","rewards"]}),Object.entries(((K=o.get(l.id))==null?void 0:K.entityCounts)??{}).sort((I,D)=>D[1]-I[1]).slice(0,4).map(([I,D])=>e.jsxs(b,{tone:"meta",children:[D," ",I]},`${l.id}-${I}`)),e.jsxs(b,{tone:"meta",children:[((Q=o.get(l.id))==null?void 0:Q.totalOwnedEntities)??0," ","owned"]})]}),e.jsxs("div",{className:`mt-3 ${te}`,children:["Can currently read:"," ",(k.get(l.id)??[]).map(I=>`${I.displayName} (${I.kind})`).join(", ")||"no other users"]}),(q=x.get(l.id))!=null&&q.lastRewardAt?e.jsxs("div",{className:`mt-2 ${te}`,children:["Last XP movement:"," ",new Date(x.get(l.id).lastRewardAt).toLocaleString()]}):null]}),e.jsx("div",{className:"flex gap-2",children:e.jsx(J,{variant:"secondary",onClick:()=>{p(null),i(l),d(!0)},children:"Open settings"})})]})},l.id)})})]},r.title))})]})]})}export{We as SettingsUsersPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as d,j as e,aC as y,bg as k,cD as W}from"./vendor-Dnkkx2co.js";import{j as K,i as L,k as l}from"./state-vCcAT5Hq.js";import{S as P}from"./settings-section-nav-Co0AaDG-.js";import{P as M}from"./page-hero-CONuJu5J.js";import{bV as Q,bW as $,bX as A,L as F,E as j,B as c,C as N,aq as R,I as S,bY as q}from"./index-QJkjKYzZ.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";const C="inline-flex min-h-11 max-w-full items-center justify-center rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3 text-sm font-medium text-[var(--ui-ink-strong)] shadow-[var(--ui-shadow-soft)] transition hover:bg-[var(--ui-surface-hover)]",E="grid min-w-0 gap-3 rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",I="grid min-w-0 gap-1 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-4",O="min-w-0 rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-3 text-sm text-[var(--ui-ink-strong)] outline-none transition focus:border-[var(--primary)]/35 focus:bg-[var(--ui-surface-3)]",p="text-[var(--ui-ink-strong)]",T="text-[var(--ui-ink-soft)]",n="text-[var(--ui-ink-faint)]";function _(){var w;const t=K(),[r,g]=d.useState(""),[m,u]=d.useState(""),[x,h]=d.useState("personal"),s=L({queryKey:["forge-wiki-settings"],queryFn:q}),o=async()=>{await Promise.all([t.invalidateQueries({queryKey:["forge-wiki-settings"]}),t.invalidateQueries({queryKey:["forge-wiki-pages"]}),t.invalidateQueries({queryKey:["forge-wiki-page"]}),t.invalidateQueries({queryKey:["forge-wiki-search"]})])},v=l({mutationFn:()=>Q({label:r.trim(),description:m.trim(),visibility:x}),onSuccess:async()=>{g(""),u(""),h("personal"),await o()}}),b=l({mutationFn:()=>$(),onSuccess:o}),f=l({mutationFn:()=>A(),onSuccess:o});if(s.isLoading)return e.jsx(F,{eyebrow:"KarpaWiki settings",title:"Loading KarpaWiki controls",description:"Fetching spaces and profile configuration for KarpaWiki."});if(s.isError)return e.jsx(j,{eyebrow:"KarpaWiki settings",error:s.error,onRetry:()=>void s.refetch()});const a=(w=s.data)==null?void 0:w.settings;return a?e.jsxs("div",{className:"mx-auto grid w-full max-w-[1440px] gap-5",children:[e.jsx(M,{eyebrow:"SQLite memory",title:"KarpaWiki Settings",titleText:"KarpaWiki Settings",description:"Manage SQLite-backed spaces and refresh KarpaWiki indexes. Model, OAuth, and embedding profile setup lives in Models.",badge:`${a.spaces.length} spaces · ${a.embeddingProfiles.length} embedding profiles`,actions:e.jsxs(e.Fragment,{children:[e.jsxs(y,{to:"/settings/models",className:C,children:["Open model settings",e.jsx(k,{className:"ml-2 size-4"})]}),e.jsx(c,{variant:"secondary",pending:b.isPending,pendingLabel:"Syncing",onClick:()=>void b.mutateAsync(),children:"Refresh indexes"}),e.jsx(c,{pending:f.isPending,pendingLabel:"Reindexing",onClick:()=>void f.mutateAsync(),disabled:a.embeddingProfiles.length===0,children:"Reindex embeddings"})]})}),e.jsx(P,{}),e.jsxs("div",{className:"grid gap-5",children:[e.jsxs(N,{className:"grid gap-4",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("div",{children:[e.jsx("div",{className:`text-sm ${p}`,children:"Model configuration moved"}),e.jsx("div",{className:`text-xs leading-5 ${n}`,children:"KarpaWiki ingest uses the OpenAI Codex OAuth connection selected in Models. OpenAI Platform API keys and embedding profile setup are not configured from this page."})]})}),e.jsxs(y,{to:"/settings/models",className:`${C} w-fit`,children:["Manage KarpaWiki models and embeddings",e.jsx(k,{className:"ml-2 size-4"})]})]}),e.jsx("div",{className:"grid gap-5",children:e.jsxs(N,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(W,{className:"size-4 text-[var(--secondary)]"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:`text-sm ${p}`,children:"Spaces"}),e.jsx(R,{content:"Canonical knowledge lives in SQLite notes, with Forge maintaining metadata, links, search, and optional embedding indexes in the database. Text search and entity-linked search work without embeddings, while semantic search stays additive and profile-driven. Ingest jobs can create pages and media assets now, with room for richer OCR, transcription, and multimodal compilation later.",label:"Explain the wiki operating model"})]}),e.jsx("div",{className:`text-xs leading-5 ${n}`,children:"Personal and shared wiki spaces map to explicit SQLite namespaces."})]})]}),e.jsx("div",{className:"grid gap-3",children:a.spaces.map(i=>e.jsxs("div",{className:I,children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:`min-w-0 break-words [overflow-wrap:anywhere] ${p}`,children:i.label}),e.jsx("div",{className:`text-xs uppercase tracking-[0.16em] ${n}`,children:i.visibility})]}),e.jsx("div",{className:`break-words text-xs [overflow-wrap:anywhere] ${n}`,children:i.slug}),e.jsx("div",{className:`text-sm ${T}`,children:i.description||"No description yet."})]},i.id))}),e.jsxs("div",{className:E,children:[e.jsx(S,{value:r,onChange:i=>g(i.target.value),placeholder:"New space label"}),e.jsx(S,{value:m,onChange:i=>u(i.target.value),placeholder:"Description"}),e.jsxs("select",{className:O,value:x,onChange:i=>h(i.target.value),children:[e.jsx("option",{value:"personal",children:"Personal"}),e.jsx("option",{value:"shared",children:"Shared"})]}),e.jsx(c,{pending:v.isPending,pendingLabel:"Creating",disabled:!r.trim(),onClick:()=>void v.mutateAsync(),children:"Create space"})]})]})})]})]}):e.jsx(j,{eyebrow:"KarpaWiki settings",error:new Error("Forge returned an empty KarpaWiki settings payload."),onRetry:()=>void s.refetch()})}export{_ as SettingsWikiPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as g,j as e,aV as re,cq as ae,bX as te}from"./vendor-Dnkkx2co.js";import{j as se,i as _,k as ie}from"./state-vCcAT5Hq.js";import{u as ne,eC as de,S as le,E as ce,ch as oe,eD as ue,eE as me,C as w,c as v,eF as xe,Z as b,B as C,I as Q,T as ve,m as pe,bL as ge,eG as he,bw as fe,bx as be,by as je,bz as ye,bC as ke}from"./index-QJkjKYzZ.js";import{P as Ne}from"./page-hero-CONuJu5J.js";import{p as we,b as Se}from"./health-link-options-Cpx8w7uM.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";const _e=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],W={awake:{label:"Awake",strong:"var(--warning)",soft:"var(--ui-warning-soft)",text:"text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]"},core:{label:"Core",strong:"var(--primary)",soft:"var(--ui-accent-soft)",text:"text-[color-mix(in_srgb,var(--primary)_78%,var(--ui-ink-strong)_22%)]"},deep:{label:"Deep",strong:"var(--success)",soft:"var(--ui-success-soft)",text:"text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]"},rem:{label:"REM",strong:"var(--info)",soft:"var(--ui-info-soft)",text:"text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]"},in_bed:{label:"In bed",strong:"color-mix(in_srgb,var(--ui-ink-strong)_46%,transparent)",soft:"var(--ui-surface-3)",text:"text-[var(--ui-ink-medium)]"},asleep_unspecified:{label:"Asleep",strong:"var(--primary)",soft:"var(--ui-accent-soft)",text:"text-[color-mix(in_srgb,var(--primary)_78%,var(--ui-ink-strong)_22%)]"}};function I(r){return W[r]??W.asleep_unspecified}function p(r){if(r<=0)return"0m";const a=Math.floor(r/3600),t=Math.round(r%3600/60);return a===0?`${t}m`:t===0?`${a}h`:`${a}h ${t}m`}function Ae(r){const a=Math.round(r/60);return a===0?"on baseline":`${a>0?"+":"-"}${Math.abs(a)}m`}function T(r){return`${Math.round(r*100)}%`}function A(r,a){return r?new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit",timeZone:a}).format(new Date(r)):"n/a"}function O(r,a){return new Intl.DateTimeFormat(void 0,{weekday:"long",day:"numeric",month:"long",timeZone:a}).format(new Date(r))}function q(r,a,t){return`${A(r,t)} - ${A(a,t)}`}function Te(r){const[a,t]=r.split("-").map(Number);return new Intl.DateTimeFormat(void 0,{month:"long",year:"numeric"}).format(new Date(a,(t??1)-1,1))}function U(r){const a=new Date(r),t=(r.getDay()+6)%7;return a.setDate(r.getDate()-t),a}function Re(r){const a=U(r);return a.setDate(a.getDate()+6),a}function Me(r){const a=r.getFullYear(),t=`${r.getMonth()+1}`.padStart(2,"0"),s=`${r.getDate()}`.padStart(2,"0");return`${a}-${t}-${s}`}function B(r){return{qualitySummary:typeof r.annotations.qualitySummary=="string"?r.annotations.qualitySummary:"",notes:typeof r.annotations.notes=="string"?r.annotations.notes:"",tagsText:Array.isArray(r.annotations.tags)?r.annotations.tags.join(", "):"",linkValues:Array.isArray(r.links)?r.links.map(a=>`${a.entityType}:${a.entityId}`):[]}}function De(r,a){if(!r)return[];const[t,s]=r.split("-").map(Number),n=new Date(t,(s??1)-1,1),u=new Date(t,s??1,0),d=U(n),x=Re(u),l=new Map(a.map(c=>[c.dateKey,c])),i=[];for(const c=new Date(d);c<=x;c.setDate(c.getDate()+1)){const y=Me(c);i.push({dateKey:y,dayNumber:c.getDate(),outsideMonth:c.getMonth()!==n.getMonth(),sleep:l.get(y)??null})}return i}function Ie(r){return r>0?"text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]":r<0?"text-[color-mix(in_srgb,var(--danger)_78%,var(--ui-ink-strong)_22%)]":"text-[var(--ui-ink-medium)]"}function G(r){return r==="recharged"||r==="recovered"?"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]":r==="steady"||r==="stable"?"bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]":r==="fragile"||r==="strained"?"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]":r==="depleted"?"bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_78%,var(--ui-ink-strong)_22%)]":"bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]"}function Be(r){return r==="provider_raw"?"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]":r==="historical_raw"?"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]":"bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]"}function qe(r){return r==="provider_raw"?"Provider raw data":r==="historical_raw"?"Historical raw data":"Raw data unavailable"}function Ce(r){return r.qualityKind==="provider_native"?"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]":"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]"}function $e(r,a){const t=r.stage;if(typeof t=="string"&&t.trim().length>0)return t;const s=r.sourceType;if(typeof s=="string"&&s.trim().length>0)return s;const n=r.stageBreakdown;if(Array.isArray(n)&&n.length>0){const u=n[0];if(u&&typeof u=="object"&&typeof u.stage=="string")return(u.stage||"asleep_unspecified").trim()}return a.includes("awake")?"awake":"asleep_unspecified"}function Ee(r){const a=r,t=(a==null?void 0:a.segments)??(a==null?void 0:a.rawSegments)??[],s=(a==null?void 0:a.auditLogs)??(a==null?void 0:a.rawLogs)??[],n=a!=null&&a.sourceRecords&&a.sourceRecords.length>0?a.sourceRecords:s.filter(d=>typeof d.startedAt=="string"&&typeof d.endedAt=="string").map(d=>({id:d.id,importRunId:d.importRunId,pairingSessionId:d.pairingSessionId,sleepSessionId:d.sleepSessionId,userId:d.userId,provider:d.source,providerRecordType:d.logType,providerRecordUid:d.externalUid??d.id,sourceDevice:"",sourceTimezone:d.sourceTimezone,localDateKey:d.localDateKey,startedAt:d.startedAt,endedAt:d.endedAt,rawStage:$e(d.payload,d.logType),rawValue:null,qualityKind:"historical_import",payload:d.payload,metadata:d.metadata,ingestedAt:d.createdAt})),u=(a==null?void 0:a.rawDataStatus)??(n.length>0?"historical_raw":"raw_unavailable");return{sourceRecords:n,segments:t,auditLogs:s,rawDataStatus:u}}function J({stages:r}){const a=r.reduce((t,s)=>t+s.seconds,0);return r.length===0||a===0?e.jsx("div",{className:"rounded-[18px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4 text-sm text-[var(--ui-ink-muted)]",children:"No stage composition was stored for this night yet."}):e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"flex h-3 overflow-hidden rounded-full bg-[var(--ui-surface-2)]",children:r.map(t=>{const s=I(t.stage);return e.jsx("div",{className:"h-full",style:{width:`${Math.max(4,t.seconds/a*100)}%`,background:s.strong},title:`${s.label} · ${p(t.seconds)}`},t.stage)})}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 xl:grid-cols-4",children:r.map(t=>{const s=I(t.stage),n="percentage"in t&&typeof t.percentage=="number"?t.percentage:a>0?t.seconds/a:0;return e.jsxs("div",{className:"rounded-[16px] border border-[var(--ui-border-subtle)] px-3 py-3",style:{background:s.soft},children:[e.jsx("div",{className:b("text-sm font-medium",s.text),children:s.label}),e.jsx("div",{className:"mt-1 text-lg text-[var(--ui-ink-strong)]",children:p(t.seconds)}),e.jsx("div",{className:"text-xs text-[var(--ui-ink-muted)]",children:T(n)})]},t.stage)})})]})}function H({blocks:r,selectedBlockId:a,onSelect:t}){return e.jsxs("div",{className:"relative h-12 overflow-hidden rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",children:[e.jsx("div",{className:"pointer-events-none absolute inset-0 bg-[image:var(--ui-surface-section)] bg-[length:25%_100%]"}),r.map(s=>{const n=I(s.stage),u=a===s.id;return e.jsx("button",{type:"button",onClick:()=>t(s.id),className:b("absolute inset-y-[5px] rounded-[12px] border transition",u?"border-[var(--ui-border-strong)] shadow-[var(--ui-shadow-soft)]":"border-[var(--ui-border-subtle)]"),style:{left:`${s.offsetRatio*100}%`,width:`${Math.max(s.widthRatio*100,1.8)}%`,background:n.strong},title:`${s.label} · ${p(s.durationSeconds)} · ${s.startedAt} - ${s.endedAt}`,children:s.widthRatio>.13?e.jsx("span",{className:"truncate px-2 text-[10px] font-medium text-[var(--ui-ink-on-accent)]",children:s.label}):null},s.id)})]})}function Ke({timeline:r,timeZone:a}){var l,i;const t=r.blocks.filter(c=>c.lane==="in_bed"),s=r.blocks.filter(c=>c.lane==="sleep"),n=((l=s[0])==null?void 0:l.id)??((i=t[0])==null?void 0:i.id)??null,[u,d]=g.useState(n);g.useEffect(()=>{d(n)},[n,r.startedAt,r.endedAt,r.totalSeconds]);const x=r.blocks.find(c=>c.id===u)??null;return r.hasRawSegments?e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-3",children:[t.length>0?e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"In bed window"}),e.jsx(H,{blocks:t,selectedBlockId:u,onSelect:d})]}):null,e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:r.hasSleepStageData?"Sleep phases":"Recorded sleep coverage"}),e.jsx(H,{blocks:s.length>0?s:t,selectedBlockId:u,onSelect:d})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs text-[var(--ui-ink-muted)]",children:[e.jsx("span",{children:A(r.startedAt,a)}),e.jsx("span",{children:p(r.totalSeconds)}),e.jsx("span",{children:A(r.endedAt,a)})]}),x?e.jsx("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:b("text-sm font-medium",I(x.stage).text),children:x.label}),e.jsxs("div",{className:"mt-1 text-sm text-[var(--ui-ink-muted)]",children:[A(x.startedAt,a)," -"," ",A(x.endedAt,a)]})]}),e.jsx(v,{tone:"meta",children:p(x.durationSeconds)})]})}):null]}):e.jsx("div",{className:"rounded-[18px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-5 text-sm text-[var(--ui-ink-muted)]",children:"Phase timing is unavailable for this night. Forge still keeps the canonical overnight summary, but the companion did not store segment-level timing."})}function Fe({latestNight:r}){return r?e.jsx(w,{className:"overflow-hidden border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-0",children:e.jsxs("div",{className:"relative overflow-hidden px-6 py-6 sm:px-7 sm:py-7",children:[e.jsx("div",{className:"pointer-events-none absolute inset-0 bg-[image:var(--ui-surface-section)]"}),e.jsxs("div",{className:"relative grid gap-6 xl:grid-cols-[minmax(0,1.2fr)_minmax(0,0.8fr)]",children:[e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx(v,{className:b("border-transparent",G(r.recoveryState)),children:r.qualitativeState}),e.jsx(v,{tone:"meta",children:r.sourceTimezone}),r.hasReflection?e.jsx(v,{tone:"meta",children:"Has reflection"}):null,r.hasRawSegments?e.jsxs(v,{tone:"meta",children:[r.rawSegmentCount," raw segments"]}):null]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Last night"}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-end gap-x-4 gap-y-2",children:[e.jsx("div",{className:"text-[clamp(2.5rem,6vw,5rem)] font-medium leading-none text-[var(--ui-ink-strong)]",children:p(r.asleepSeconds)}),e.jsxs("div",{className:"pb-2 text-sm text-[var(--ui-ink-muted)]",children:["asleep across ",q(r.startedAt,r.endedAt,r.sourceTimezone)]})]}),e.jsx("div",{className:"mt-3 text-sm text-[var(--ui-ink-medium)]",children:O(r.endedAt,r.sourceTimezone)}),r.qualitySummary?e.jsx("div",{className:"mt-4 max-w-2xl text-sm leading-6 text-[var(--ui-ink-medium)]",children:r.qualitySummary}):e.jsx("div",{className:"mt-4 max-w-2xl text-sm leading-6 text-[var(--ui-ink-muted)]",children:"Canonical overnight summary computed from synced sleep segments, with raw evidence still available underneath."})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"In bed"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:p(r.timeInBedSeconds)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Score"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:r.score??"n/a"})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Regularity"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:r.regularity??"n/a"})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Efficiency"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:T(r.efficiency)})]})]})]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-5 py-5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Baseline"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:"Compared with recent nights"})]}),e.jsx(ae,{className:"size-5 text-[var(--primary)]"})]}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"7-night average"}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-strong)]",children:p(r.weeklyAverageSleepSeconds)})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"Versus baseline"}),e.jsx("span",{className:b("text-sm",Ie(r.deltaFromWeeklyAverageSeconds)),children:Ae(r.deltaFromWeeklyAverageSeconds)})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"Bedtime drift"}),e.jsxs("span",{className:"text-sm text-[var(--ui-ink-strong)]",children:[r.bedtimeDriftMinutes??0,"m"]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"Wake drift"}),e.jsxs("span",{className:"text-sm text-[var(--ui-ink-strong)]",children:[r.wakeDriftMinutes??0,"m"]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"Restorative share"}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-strong)]",children:T(r.restorativeShare)})]})]})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-5 py-5",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Stage composition"}),e.jsx("div",{className:"mt-4",children:e.jsx(J,{stages:r.stageBreakdown})})]})]})]})]})}):e.jsxs(w,{className:"overflow-hidden p-6",children:[e.jsx("div",{className:"text-sm uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Sleep"}),e.jsx("div",{className:"mt-4 text-2xl text-[var(--ui-ink-strong)]",children:"No overnight sleep yet"}),e.jsx("div",{className:"mt-3 max-w-2xl text-sm leading-6 text-[var(--ui-ink-muted)]",children:"The sleep page will switch to a night-first summary once the companion syncs a canonical overnight session."})]})}function F({title:r,value:a,description:t}){return e.jsxs(w,{className:"h-full border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:r}),e.jsx("div",{className:"mt-3 text-3xl text-[var(--ui-ink-strong)]",children:a}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-muted)]",children:t})]})}function ze({days:r,selectedSleepId:a,onSelect:t}){const s=g.useMemo(()=>Array.from(new Set(r.map(l=>l.dateKey.slice(0,7)))).sort((l,i)=>l.localeCompare(i)),[r]),[n,u]=g.useState(s[s.length-1]??"");g.useEffect(()=>{if(s.length===0){u("");return}s.includes(n)||u(s[s.length-1]??"")},[n,s]);const d=s.indexOf(n),x=g.useMemo(()=>De(n,r),[r,n]);return n?e.jsx(w,{className:"overflow-hidden border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-0",children:e.jsxs("div",{className:"grid gap-5 px-5 py-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Sleep calendar"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:Te(n)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{type:"button",variant:"secondary",className:"h-9 rounded-full",disabled:d<=0,onClick:()=>u(s[Math.max(0,d-1)]??n),children:"Previous"}),e.jsx(C,{type:"button",variant:"secondary",className:"h-9 rounded-full",disabled:d===-1||d>=s.length-1,onClick:()=>u(s[Math.min(s.length-1,d+1)]??n),children:"Next"})]})]}),e.jsx("div",{className:"grid grid-cols-7 gap-2 text-center text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-muted)]",children:_e.map(l=>e.jsx("div",{children:l},l))}),e.jsx("div",{className:"grid grid-cols-7 gap-2",children:x.map(l=>{const i=l.sleep,c=(i==null?void 0:i.sleepId)===a,y=i&&typeof i.score=="number"?i.score>=80?"var(--ui-success-soft)":i.score>=65?"var(--ui-info-soft)":"var(--ui-warning-soft)":"var(--ui-surface-2)";return e.jsxs("button",{type:"button",disabled:!i,"aria-pressed":c,"aria-label":`Select sleep for ${l.dateKey}`,onClick:()=>{i&&(u(i.dateKey.slice(0,7)),t(i.sleepId,i.dateKey.slice(0,7)))},className:b("min-h-[90px] rounded-[18px] border px-2 py-2 text-left transition",i?"border-[var(--ui-border-subtle)] hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-3)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",c&&"border-[var(--primary)] bg-[var(--primary)]/12",l.outsideMonth&&!i&&"opacity-35"),style:i?{background:y}:void 0,children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("span",{className:b("text-sm",l.outsideMonth?"text-[var(--ui-ink-muted)]":"text-[var(--ui-ink-medium)]"),children:l.dayNumber}),i!=null&&i.hasReflection?e.jsx("span",{className:"size-2 rounded-full bg-[var(--success)]"}):null]}),i?e.jsxs("div",{className:"mt-4 grid gap-1",children:[e.jsxs("div",{className:"text-lg text-[var(--ui-ink-strong)]",children:[i.sleepHours.toFixed(1),"h"]}),e.jsxs("div",{className:"text-xs text-[var(--ui-ink-muted)]",children:[i.score??"n/a"," score"]}),e.jsx("div",{className:"text-xs text-[var(--ui-ink-muted)]",children:i.hasRawSegments?"phases available":"summary only"})]}):null]},l.dateKey)})})]})}):e.jsx(w,{className:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-5 py-8 text-sm leading-6 text-[var(--ui-ink-muted)]",children:"No canonical nights are available for the calendar yet."})}function z({active:r,children:a,onClick:t}){return e.jsx("button",{type:"button",onClick:t,className:b("rounded-full border px-4 py-2 text-sm transition",r?"border-[var(--primary)] bg-[var(--primary)]/12 text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)] hover:text-[var(--ui-ink-strong)]"),children:a})}function Le({session:r,draft:a,rawDetail:t,rawDetailLoading:s,pending:n,tab:u,linkOptions:d,onTabChange:x,onDraftChange:l,onSave:i}){const[c,y]=g.useState(null),k=g.useMemo(()=>Ee(t),[t]),$=typeof r.derived.efficiency=="number"?r.derived.efficiency:r.timeInBedSeconds>0?r.asleepSeconds/r.timeInBedSeconds:0,E=typeof r.derived.restorativeShare=="number"?r.derived.restorativeShare:0,R=typeof r.derived.recoveryState=="string"?r.derived.recoveryState:null;return e.jsx(w,{className:"overflow-hidden border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-0",children:e.jsxs("div",{className:"grid gap-5 px-5 py-5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(v,{className:b("border-transparent",G(R)),children:R?R.replaceAll("_"," "):"Canonical night"}),e.jsxs(v,{tone:"meta",children:[r.rawSegmentCount," raw segments"]}),e.jsx(v,{tone:"meta",children:r.sourceTimezone})]}),e.jsx("div",{className:"mt-3 text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Selected night"}),e.jsx("div",{className:"mt-2 text-2xl text-[var(--ui-ink-strong)]",children:O(r.endedAt,r.sourceTimezone)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:q(r.startedAt,r.endedAt,r.sourceTimezone)})]}),e.jsxs("div",{className:"grid gap-2 text-right",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Summary"}),e.jsx("div",{className:"text-3xl text-[var(--ui-ink-strong)]",children:p(r.asleepSeconds)}),e.jsx("div",{className:"text-sm text-[var(--ui-ink-muted)]",children:"asleep"})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"In bed"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:p(r.timeInBedSeconds)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Awake"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:p(r.awakeSeconds)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Efficiency"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:T($)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Restorative"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:T(E)})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(z,{active:u==="summary",onClick:()=>x("summary"),children:"Summary"}),e.jsx(z,{active:u==="reflection",onClick:()=>x("reflection"),children:"Reflection"}),e.jsx(z,{active:u==="raw",onClick:()=>x("raw"),children:"Show raw data"})]}),u==="summary"?e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Phase timeline"}),e.jsx("div",{className:"mt-4",children:s?e.jsx("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-6 text-sm text-[var(--ui-ink-muted)]",children:"Loading phase timing from raw sleep segments…"}):e.jsx(Ke,{timeline:(t==null?void 0:t.phaseTimeline)??{startedAt:r.startedAt,endedAt:r.endedAt,totalSeconds:Math.max(0,Math.round((new Date(r.endedAt).getTime()-new Date(r.startedAt).getTime())/1e3)),hasRawSegments:!1,hasSleepStageData:!1,blocks:[]},timeZone:r.sourceTimezone})})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Stage composition"}),e.jsx("div",{className:"mt-4",children:e.jsx(J,{stages:r.stageBreakdown})})]})]}):null,u==="reflection"?e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Quality summary"}),e.jsx(Q,{value:a.qualitySummary,onChange:o=>l({qualitySummary:o.target.value}),placeholder:"Recovered after a late evening, but sleep onset drifted."})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Night notes"}),e.jsx(ve,{className:"min-h-[200px]",value:a.notes,onChange:o=>l({notes:o.target.value}),placeholder:"What shaped this night, and what should we remember about it?"})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Tags"}),e.jsx(Q,{value:a.tagsText,onChange:o=>l({tagsText:o.target.value}),placeholder:"travel, stress, good-routine, late-caffeine"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Linked context"}),e.jsx(pe,{options:d,selectedValues:a.linkValues,onChange:o=>l({linkValues:o}),placeholder:"Search goals, tasks, habits, beliefs, reports, or patterns…"})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(C,{type:"button",pending:n,pendingLabel:"Saving",onClick:i,children:[e.jsx(te,{className:"size-4"}),"Save reflection"]})})]}):null,u==="raw"?e.jsxs("div",{className:"grid gap-5",children:[e.jsx("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4 text-sm leading-6 text-[var(--ui-ink-muted)]",children:"Forge shows the canonical overnight session by default. This view reveals the evidence stack underneath it: raw provider or historical imported records first, then Forge-normalized sleep segments."}),s?e.jsx("div",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Loading raw sleep evidence…"}):null,s?null:e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(v,{className:b("border-transparent",Be(k.rawDataStatus)),children:qe(k.rawDataStatus)}),k.rawDataStatus==="historical_raw"?e.jsx(v,{tone:"meta",children:"Partial evidence"}):null]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Raw data"}),k.sourceRecords.length?k.sourceRecords.map(o=>e.jsxs("div",{className:"rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(v,{className:b("border-transparent",Ce(o)),children:o.qualityKind==="provider_native"?"Provider raw":"Historical raw"}),e.jsx(v,{tone:"meta",className:"capitalize",children:o.rawStage.replaceAll("_"," ")}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:q(o.startedAt,o.endedAt,o.sourceTimezone)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-[var(--ui-ink-muted)]",children:o.providerRecordType.replaceAll("_"," ")}),e.jsx(C,{type:"button",variant:"secondary",className:"h-8 rounded-full px-3",onClick:()=>y(M=>M===o.id?null:o.id),children:c===o.id?"Hide JSON":"See JSON"})]})]}),e.jsx("div",{className:"mt-3 text-sm text-[var(--ui-ink-muted)]",children:p(Math.max(0,Math.round((new Date(o.endedAt).getTime()-new Date(o.startedAt).getTime())/1e3)))}),c===o.id?e.jsx("pre",{className:"mt-3 overflow-x-auto rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-code-bg)] p-3 text-xs leading-6 text-[var(--ui-ink-medium)]",children:JSON.stringify({payload:o.payload,metadata:o.metadata},null,2)}):null]},o.id)):e.jsx("div",{className:"rounded-[16px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4 text-sm text-[var(--ui-ink-muted)]",children:"No raw data was stored for this night."})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Sleep segments"}),k.segments.length?k.segments.map(o=>e.jsx("div",{className:"rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(v,{tone:"meta",className:"capitalize",children:o.stage.replaceAll("_"," ")}),e.jsx(v,{tone:"meta",children:o.qualityKind==="provider_native"?"provider-backed":"historical"}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:q(o.startedAt,o.endedAt,o.sourceTimezone)})]}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:p(Math.max(0,Math.round((new Date(o.endedAt).getTime()-new Date(o.startedAt).getTime())/1e3)))})]})},o.id)):e.jsx("div",{className:"rounded-[16px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4 text-sm text-[var(--ui-ink-muted)]",children:"No normalized sleep segments were stored for this night."})]})]})]}):null]})})}function Xe(){var V;const r=ne(),a=se(),[t,s]=g.useState({}),[n,u]=g.useState(null),[d,x]=g.useState("summary"),l=Array.isArray(r==null?void 0:r.selectedUserIds)?r.selectedUserIds:[],i=r==null?void 0:r.snapshot,c=_({queryKey:["forge-sleep",...l],queryFn:async()=>(await ge(l)).sleep}),y=_({queryKey:["forge-sleep-raw",n],enabled:!!n,queryFn:async()=>he(n)}),k=_({queryKey:["forge-sleep-values",...l],queryFn:async()=>(await fe(l)).values}),$=_({queryKey:["forge-sleep-patterns",...l],queryFn:async()=>(await be(l)).patterns}),E=_({queryKey:["forge-sleep-behaviors",...l],queryFn:async()=>(await je(l)).behaviors}),R=_({queryKey:["forge-sleep-beliefs",...l],queryFn:async()=>(await ye(l)).beliefs}),o=_({queryKey:["forge-sleep-reports",...l],queryFn:async()=>(await ke(l)).reports});g.useEffect(()=>{c.data&&s(Object.fromEntries(c.data.sessions.map(m=>[m.id,B(m)])))},[c.data]),g.useEffect(()=>{var N,j,S;if(!((N=c.data)!=null&&N.sessions.length)){u(null);return}c.data.sessions.some(K=>K.id===n)||u(((j=c.data.latestNight)==null?void 0:j.sleepId)??((S=c.data.sessions[0])==null?void 0:S.id)??null)},[n,c.data]),g.useEffect(()=>{x("summary")},[n]);const M=ie({mutationFn:async m=>de(m.sleepId,{qualitySummary:m.qualitySummary,notes:m.notes,tags:m.tagsText.split(",").map(N=>N.trim()).filter(Boolean),links:we(m.linkValues)}),onSuccess:async()=>{await a.invalidateQueries({queryKey:["forge-sleep"]}),await a.invalidateQueries({queryKey:["forge-sleep-raw"]})}});if(c.isLoading)return e.jsx(le,{eyebrow:"Sleep",title:"Loading sleep surface",description:"Reading canonical nights, calendar summaries, and sleep phase detail.",columns:2,blocks:6});if(c.isError||!c.data)return e.jsx(ce,{eyebrow:"Sleep",error:c.error??new Error("Sleep data unavailable"),onRetry:()=>void c.refetch()});const h=c.data,D=h.sessions,L=new Map(D.map(m=>[m.id,m])),f=(n?L.get(n):null)??(h.latestNight?L.get(h.latestNight.sleepId):null)??D[0]??null,P=f?t[f.id]??B(f):null,Y=Se({goals:(i==null?void 0:i.dashboard.goals)??[],projects:(i==null?void 0:i.dashboard.projects)??[],tasks:(i==null?void 0:i.dashboard.tasks)??[],habits:(i==null?void 0:i.dashboard.habits)??[],values:k.data??[],patterns:$.data??[],behaviors:E.data??[],beliefs:R.data??[],reports:o.data??[]});function X(m,N){s(j=>{const S=D.find(ee=>ee.id===m),K=j[m]??(S?B(S):{qualitySummary:"",notes:"",tagsText:"",linkValues:[]});return{...j,[m]:{...K,...N}}})}async function Z(m){const N=D.find(S=>S.id===m);if(!N)return;const j=t[m]??B(N);await M.mutateAsync({sleepId:m,qualitySummary:j.qualitySummary,notes:j.notes,tagsText:j.tagsText,linkValues:j.linkValues})}return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(Ne,{eyebrow:"Health",title:"Sleep",description:"Canonical overnight sessions first, with last-night recovery, a clickable night calendar, and raw segment evidence only when you ask for it.",badge:`${D.length} nights`}),e.jsx(oe,{}),e.jsx(ue,{children:e.jsx(Fe,{latestNight:h.latestNight})}),e.jsx(me,{children:e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,0.95fr)_minmax(0,1.05fr)]",children:[e.jsx(F,{title:"Weekly average",value:p(h.summary.averageSleepSeconds),description:"Average overnight sleep duration across the recent week, used as the baseline for the latest-night comparison."}),e.jsx(F,{title:"Regularity",value:`${h.summary.averageRegularityScore}`,description:`Average bedtime drift ${h.summary.averageBedtimeConsistencyMinutes}m and wake drift ${h.summary.averageWakeConsistencyMinutes}m.`}),e.jsx(F,{title:"Restorative share",value:T(h.summary.averageRestorativeShare),description:`Deep + REM share across recent nights, with ${h.summary.reflectiveNightCount} nights already carrying context.`}),e.jsxs(w,{className:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Recent stage mix"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:"Average nightly phases"})]}),e.jsx(re,{className:"size-5 text-[var(--primary)]"})]}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:h.stageAverages.length>0?h.stageAverages.slice(0,5).map(m=>e.jsxs(v,{tone:"meta",children:[I(m.stage).label," ",p(m.averageSeconds)]},m.stage)):e.jsx("div",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Stage averages will appear once nights include phase data."})})]})]})}),e.jsx(xe,{children:e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,25rem)_minmax(0,1fr)]",children:[e.jsx(ze,{days:h.calendarDays,selectedSleepId:(f==null?void 0:f.id)??null,onSelect:m=>u(m)}),f&&P?e.jsx(Le,{session:f,draft:P,rawDetail:y.data??null,rawDetailLoading:y.isLoading,pending:M.isPending&&((V=M.variables)==null?void 0:V.sleepId)===f.id,tab:d,linkOptions:Y,onTabChange:x,onDraftChange:m=>X(f.id,m),onSave:()=>void Z(f.id)}):e.jsx(w,{className:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-6 py-8 text-sm leading-6 text-[var(--ui-ink-muted)]",children:"Pick a night from the calendar to inspect its phase timing, stage summary, and reflection context."})]})})]})}export{Xe as SleepPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as h,j as e,aC as Pe,bE as we,aV as qe,b8 as Se,bG as Qe,bX as Ze}from"./vendor-Dnkkx2co.js";import{j as Ue,i as O,k as Ge}from"./state-vCcAT5Hq.js";import{u as Xe,eH as Ye,S as Je,E as et,eI as tt,C as g,eJ as J,c,I as F,eK as at,aT as st,T as rt,m as it,B as ie,bM as nt,bw as lt,bx as ot,by as dt,bz as ct,bC as ut}from"./index-QJkjKYzZ.js";import{F as je}from"./faceted-token-search-CZmtyJTT.js";import{P as xt}from"./page-hero-CONuJu5J.js";import{f as mt}from"./date-keys-Cj1G3TOn.js";import{p as ht,b as pt}from"./health-link-options-Cpx8w7uM.js";import{R as P,A as vt,C as ee,X as q,Y as W,T as Q,a as ye,e as ke,B as ne,f as gt,d as ft,g as bt,c as le,S as jt,h as yt}from"./charts-DFnEuIMB.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";function Z({className:t,children:r}){const s=h.useRef(null),[l,o]=h.useState(!1);return h.useEffect(()=>{const p=()=>{const b=s.current;o(!!(b&&b.clientWidth>0&&b.clientHeight>0))},f=window.requestAnimationFrame(p),j=typeof ResizeObserver>"u"?null:new ResizeObserver(p);return s.current&&j&&j.observe(s.current),window.addEventListener("resize",p),()=>{window.cancelAnimationFrame(f),j==null||j.disconnect(),window.removeEventListener("resize",p)}},[]),e.jsx("div",{ref:s,className:t,children:l?r:null})}const G={below_z1:"#94a3b8",zone_1:"#38bdf8",zone_2:"#22c55e",zone_3:"#eab308",zone_4:"#f97316",zone_5:"#ef4444"},V=["below_z1","zone_1","zone_2","zone_3","zone_4","zone_5"];function z(t){return t?t.replace(/^activity_/i,"").replaceAll("_"," ").replace(/\s+/g," ").replace(/\b\w/g,r=>r.toUpperCase()):"Unknown"}function B(t){return`${Math.round(t/60)}m`}function de(t){return t?`${(t/1e3).toFixed(1)} km`:"n/a"}function X(t,r){const s=new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short"}),l=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"});return`${s.format(new Date(t))} · ${l.format(new Date(t))} - ${l.format(new Date(r))}`}function ae(t){return mt(new Date(t))}function U(t){return{subjectiveEffort:t.subjectiveEffort!==null?String(t.subjectiveEffort):"",moodBefore:t.moodBefore??"",moodAfter:t.moodAfter??"",meaningText:t.meaningText??"",plannedContext:t.plannedContext??"",socialContext:t.socialContext??"",tagsText:Array.isArray(t.tags)?t.tags.join(", "):"",linkValues:Array.isArray(t.links)?t.links.map(r=>`${r.entityType}:${r.entityId}`):[]}}function Ae(t){return t.trim().toLowerCase()}function y(t){var r;return((r=t.workoutTypeLabel)==null?void 0:r.trim())||z(t.workoutType)}function _(t){var r;return((r=t.activityFamilyLabel)==null?void 0:r.trim())||z(t.activityFamily)}function Ce(t){return z(t.sourceSystem??t.source)}function kt(t){return t==null?"n/a":typeof t=="boolean"?t?"Yes":"No":typeof t=="number"?Number.isInteger(t)?String(t):t.toFixed(1):t}function Nt(t){const r=kt(t.value);return!t.unit||t.unit==="count"?r:`${r} ${t.unit}`}function wt(t,r){return Ae([t.workoutType,y(t),t.activityFamily,_(t),t.sourceSystem,Ce(t),t.sourceType,t.sourceDevice,t.reconciliationStatus,t.moodBefore,t.moodAfter,t.meaningText,t.plannedContext,t.socialContext,t.tags.join(" "),r.moodBefore,r.moodAfter,r.meaningText,r.plannedContext,r.socialContext,r.tagsText,X(t.startedAt,t.endedAt)].join(" "))}function St(t){const r=new Map;for(const s of t)r.set(`workout:${s.workoutType}`,{id:`workout:${s.workoutType}`,label:y(s),description:"Workout type",searchText:`${y(s)} workout`,badge:e.jsx(c,{tone:"meta",children:y(s)})}),r.set(`source:${s.sourceType}`,{id:`source:${s.sourceType}`,label:s.sourceType.replaceAll("_"," "),description:"Source type",searchText:`${s.sourceType} source`,badge:e.jsx(c,{tone:"meta",className:"capitalize",children:s.sourceType.replaceAll("_"," ")})}),r.set(`status:${s.reconciliationStatus}`,{id:`status:${s.reconciliationStatus}`,label:s.reconciliationStatus.replaceAll("_"," "),description:"Reconciliation status",searchText:`${s.reconciliationStatus} status`,badge:e.jsx(c,{tone:"meta",className:"capitalize",children:s.reconciliationStatus.replaceAll("_"," ")})});return r.set("linked:yes",{id:"linked:yes",label:"Linked",description:"Already tied to Forge or Psyche context",badge:e.jsx(c,{tone:"meta",children:"Linked"})}),r.set("linked:no",{id:"linked:no",label:"Needs links",description:"No Forge or Psyche links yet",badge:e.jsx(c,{tone:"meta",children:"Needs links"})}),r.set("habit:yes",{id:"habit:yes",label:"Habit-generated",description:"Created from a habit completion",badge:e.jsx(c,{tone:"meta",children:"Habit-generated"})}),r.set("effort:rated",{id:"effort:rated",label:"Effort rated",description:"Already has a subjective effort score",badge:e.jsx(c,{tone:"meta",children:"Effort rated"})}),Array.from(r.values())}function At(t,r){return r.every(s=>s.startsWith("workout:")?t.workoutType===s.slice(8):s.startsWith("source:")?t.sourceType===s.slice(7):s.startsWith("status:")?t.reconciliationStatus===s.slice(7):s==="linked:yes"?t.links.length>0:s==="linked:no"?t.links.length===0:s==="habit:yes"?!!t.generatedFromHabitId:s==="effort:rated"?t.subjectiveEffort!==null:!0)}function te(t,r,s){if(!t||t.length===0)return null;const l=[...t].filter(o=>o.dateKey<=r&&o[s]!=null).sort((o,p)=>p.dateKey.localeCompare(o.dateKey))[0];return(l==null?void 0:l[s])??null}function Ct(t){return[t.workoutType,t.workoutTypeLabel,t.activityFamily,t.activityFamilyLabel].filter(Boolean).join(" ").toLowerCase().includes("kickboxing")}function Tt(t){const r=new Map;for(const s of t){const l=`type:${s.workoutType}`;r.set(l,{id:l,label:y(s),description:_(s),searchText:`${y(s)} ${_(s)} ${s.workoutType}`,badge:e.jsx(c,{tone:"meta",children:y(s)})})}return[...r.values()].sort((s,l)=>s.label.localeCompare(l.label))}function Mt(t,r,s,l,o){const p=r.filter(u=>u.startsWith("type:")).map(u=>u.slice(5)),f=new Set(p),j=ae(new Date().toISOString()),b=new Date(`${j}T12:00:00.000Z`);b.setUTCDate(b.getUTCDate()-90);const n=b.toISOString().slice(0,10);return t.filter(u=>{if(f.size>0&&!f.has(u.workoutType))return!1;const x=ae(u.startedAt);return s==="recent_90"?x>=n:!(s==="custom"&&(l&&x<l||o&&x>o))}).sort((u,x)=>Date.parse(u.startedAt)-Date.parse(x.startedAt))}function oe(t){var s;const r=Object.fromEntries(V.map(l=>[l,0]));for(const l of t)for(const o of((s=l.analytics)==null?void 0:s.zoneDurations)??[])V.includes(o.key)&&(r[o.key]+=o.seconds);return r}function Ne(t){const r=Object.values(t).reduce((s,l)=>s+l,0);return Object.fromEntries(V.map(s=>[s,r>0?Number((t[s]/r*100).toFixed(1)):0]))}function Rt(t,r,s){const l=typeof(s==null?void 0:s.dataKey)=="string"?s.dataKey:typeof r=="string"?r:"",o=typeof t=="number"?Number(t.toFixed(1)):String(t??"n/a");return l==="restingHeartRate"||r==="Resting HR"?[`${o} bpm`,"Resting HR"]:l==="vo2Max"||r==="VO2max"?[`${o} ml/kg/min`,"VO2max"]:[`${o}%`,z(l)]}function Et(t,r){const s=t.map((n,u)=>{var k,M,D;const x=ae(n.startedAt),w=t.slice(Math.max(0,u-2),u+1),N=oe(w),T=Ne(N);return{id:n.id,dateKey:x,date:x.slice(5),session:y(n),durationMinutes:Math.round(n.durationSeconds/60),confidence:((k=n.analytics)==null?void 0:k.confidence)??"unavailable",restingHeartRate:((D=(M=n.analytics)==null?void 0:M.hrSummary)==null?void 0:D.restingHr)??te(r,x,"restingHeartRate"),vo2Max:te(r,x,"vo2Max"),...T}}),l=t.map((n,u)=>{var T,k,M;const x=ae(n.startedAt),w=oe(t.slice(0,u+1)),N=Ne(w);return{id:n.id,dateKey:x,date:x.slice(5),session:y(n),durationMinutes:Math.round(n.durationSeconds/60),confidence:((T=n.analytics)==null?void 0:T.confidence)??"unavailable",restingHeartRate:((M=(k=n.analytics)==null?void 0:k.hrSummary)==null?void 0:M.restingHr)??te(r,x,"restingHeartRate"),vo2Max:te(r,x,"vo2Max"),...N}}),o=oe(t),p=Object.values(o).reduce((n,u)=>n+u,0),f=V.map(n=>{var x;const u=((x=t.flatMap(w=>{var N;return((N=w.analytics)==null?void 0:N.zoneDurations)??[]}).find(w=>w.key===n))==null?void 0:x.label)??z(n);return{key:n,zone:u,percentage:p>0?Number((o[n]/p*100).toFixed(1)):0,fill:G[n]??"#f8fafc"}}),j=t.filter(n=>{var u,x;return(((x=(u=n.analytics)==null?void 0:u.dataQuality)==null?void 0:x.heartRateSampleCount)??0)>0}).length,b=[...new Set(t.map(n=>y(n)))];return{sessions:t,lineData:s,expandingLineData:l,averageZoneData:f,rawHrCount:j,exerciseLabels:b}}function zt({session:t,draft:r,linkOptions:s,pending:l,step:o,onStepChange:p,onDraftChange:f,onSave:j}){var n,u,x,w,N,T,k,M,D;const b=[{id:"context",title:"Session context",description:"Quick facts, effort, and how this session happened."},{id:"reflection",title:"Reflection",description:"Mood, meaning, and what the session actually did for you."},{id:"links",title:"Links",description:"Tie the session back to Forge and Psyche context."}];return e.jsxs("div",{className:"grid gap-5",children:[e.jsx("div",{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 text-lg text-[var(--ui-ink-strong)]",children:[e.jsx(we,{className:"size-4 text-[var(--primary)]"}),e.jsx("span",{children:y(t)})]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:X(t.startedAt,t.endedAt)})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(c,{children:B(t.durationSeconds)}),t.totalEnergyKcal?e.jsxs(c,{tone:"meta",children:[Math.round(t.totalEnergyKcal)," kcal"]}):null,t.distanceMeters?e.jsx(c,{tone:"meta",children:de(t.distanceMeters)}):null,e.jsx(c,{tone:"meta",children:_(t)}),e.jsx(c,{tone:"meta",className:"capitalize",children:t.reconciliationStatus.replaceAll("_"," ")})]})]})}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-3",children:b.map((i,L)=>e.jsxs("button",{type:"button",onClick:()=>p(L),className:`rounded-[20px] border px-4 py-3 text-left transition ${o===L?"border-[var(--primary)] bg-[var(--primary)]/10 text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]"}`,children:[e.jsxs("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:["Step ",L+1]}),e.jsx("div",{className:"mt-2 text-sm font-medium",children:i.title})]},i.id))}),e.jsxs("div",{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:b[o].title}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:b[o].description}),o===0?e.jsxs("div",{className:"mt-4 grid gap-4",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Activity family"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)] capitalize",children:_(t)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Source system"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:Ce(t)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Source device"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:t.sourceDevice||"n/a"})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Steps"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:t.stepCount??"n/a"})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Avg HR"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:t.averageHeartRate?Math.round(t.averageHeartRate):"n/a"})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Max HR"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:t.maxHeartRate?Math.round(t.maxHeartRate):"n/a"})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Effort"}),e.jsx(F,{type:"number",min:1,max:10,value:r.subjectiveEffort,onChange:i=>f({subjectiveEffort:i.target.value})})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Planned vs spontaneous"}),e.jsx(F,{value:r.plannedContext,onChange:i=>f({plannedContext:i.target.value}),placeholder:"Planned recovery block"})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Social context"}),e.jsx(F,{value:r.socialContext,onChange:i=>f({socialContext:i.target.value}),placeholder:"Solo, coach, group class, partner"})]})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Tags"}),e.jsx(F,{value:r.tagsText,onChange:i=>f({tagsText:i.target.value}),placeholder:"recovery, interval-block, stress-release"})]})]}):null,o===1?e.jsxs("div",{className:"mt-4 grid gap-4",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Mood before"}),e.jsx(F,{value:r.moodBefore,onChange:i=>f({moodBefore:i.target.value})})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Mood after"}),e.jsx(F,{value:r.moodAfter,onChange:i=>f({moodAfter:i.target.value})})]})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Meaning, impact, and why this session mattered"}),e.jsx(rt,{className:"min-h-[160px]",value:r.meaningText,onChange:i=>f({meaningText:i.target.value}),placeholder:"This session was planned as active recovery after a heavy work block and helped reset stress before sleep."})]})]}):null,o===2?e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Search goals, projects, habits, values, beliefs, patterns, or reports and attach the ones that explain this session."}),e.jsx(it,{options:s,selectedValues:r.linkValues,onChange:i=>f({linkValues:i}),placeholder:"Search Forge and Psyche records…"})]}):null,e.jsxs("div",{className:"mt-5 grid gap-4 border-t border-[var(--ui-border-subtle)] pt-5",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Captured data"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Source-native workout metrics, events, and phases exposed through the adapter layer."})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-3",children:[(((n=t.details)==null?void 0:n.metrics)??[]).slice(0,12).map(i=>e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:i.label}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:Nt(i)}),e.jsxs("div",{className:"mt-1 text-xs uppercase tracking-[0.14em] text-[var(--ui-ink-faint)]",children:[z(i.category)," ·"," ",z(i.statistic)]})]},`${i.category}:${i.key}:${i.statistic}`)),(((x=(u=t.details)==null?void 0:u.metrics)==null?void 0:x.length)??0)===0?e.jsx("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4 text-sm text-[var(--ui-ink-faint)]",children:"No provider metrics were captured for this session yet."}):null]}),(((N=(w=t.details)==null?void 0:w.events)==null?void 0:N.length)??0)>0?e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Workout events"}),e.jsx("div",{className:"grid gap-2",children:(T=t.details)==null?void 0:T.events.map(i=>e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("div",{className:"text-[var(--ui-ink-strong)]",children:i.label}),e.jsx(c,{tone:"meta",children:B(i.durationSeconds)})]}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:X(i.startedAt,i.endedAt??i.startedAt)})]},`${i.type}:${i.startedAt}`))})]}):null,(((M=(k=t.details)==null?void 0:k.components)==null?void 0:M.length)??0)>0?e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Workout phases"}),e.jsx("div",{className:"grid gap-2",children:(D=t.details)==null?void 0:D.components.map(i=>e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("div",{className:"text-[var(--ui-ink-strong)]",children:i.activity.canonicalLabel}),e.jsx(c,{tone:"meta",children:B(i.durationSeconds)})]}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:X(i.startedAt,i.endedAt??i.startedAt)})]},i.externalUid))})]}):null]})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-faint)]",children:o<b.length-1?"Move through the session one step at a time, then save when the context is clean.":"Everything is in place. Save the session metadata back into Forge."}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(ie,{type:"button",variant:"secondary",onClick:()=>p(Math.max(0,o-1)),disabled:o===0,children:"Back"}),o<b.length-1?e.jsxs(ie,{type:"button",onClick:()=>p(o+1),children:["Next",e.jsx(Se,{className:"size-4"})]}):null,e.jsxs(ie,{type:"button",pending:l,pendingLabel:"Saving",onClick:j,children:[e.jsx(Ze,{className:"size-4"}),"Save session"]})]})]})]})}function qt(){var fe,be;const t=Xe(),r=Ue(),s=Array.isArray(t.selectedUserIds)?t.selectedUserIds:[],[l,o]=h.useState({}),[p,f]=h.useState(""),[j,b]=h.useState([]),[n,u]=h.useState([]),[x,w]=h.useState(""),[N,T]=h.useState("all"),[k,M]=h.useState("rolling_stack"),[D,i]=h.useState(""),[L,Te]=h.useState(""),[ce,Me]=h.useState(!1),[ue,se]=h.useState(null),[Re,Y]=h.useState(0),S=O({queryKey:["forge-fitness",...s],queryFn:async()=>(await nt(s)).fitness}),Ee=O({queryKey:["forge-health-values",...s],queryFn:async()=>(await lt(s)).values}),ze=O({queryKey:["forge-health-patterns",...s],queryFn:async()=>(await ot(s)).patterns}),De=O({queryKey:["forge-health-behaviors",...s],queryFn:async()=>(await dt(s)).behaviors}),He=O({queryKey:["forge-health-beliefs",...s],queryFn:async()=>(await ct(s)).beliefs}),Fe=O({queryKey:["forge-health-reports",...s],queryFn:async()=>(await ut(s)).reports});h.useEffect(()=>{S.data&&o(Object.fromEntries(S.data.sessions.map(a=>[a.id,U(a)])))},[S.data]),h.useEffect(()=>{if(ce||!S.data)return;const d=(S.data.analysisSessions??S.data.sessions).find(Ct);d&&u([`type:${d.workoutType}`]),Me(!0)},[ce,S.data]);const re=Ge({mutationFn:async a=>Ye(a.workoutId,{subjectiveEffort:a.subjectiveEffort.trim().length>0?Number(a.subjectiveEffort):null,moodBefore:a.moodBefore,moodAfter:a.moodAfter,meaningText:a.meaningText,plannedContext:a.plannedContext,socialContext:a.socialContext,tags:a.tagsText.split(",").map(d=>d.trim()).filter(Boolean),links:ht(a.linkValues)}),onSuccess:async()=>{await r.invalidateQueries({queryKey:["forge-fitness"]})}}),H=S.data,A=(H==null?void 0:H.sessions)??[],K=(H==null?void 0:H.analysisSessions)??A,Le=pt({goals:t.snapshot.dashboard.goals,projects:t.snapshot.dashboard.projects,tasks:t.snapshot.dashboard.tasks,habits:t.snapshot.dashboard.habits,values:Ee.data??[],patterns:ze.data??[],behaviors:De.data??[],beliefs:He.data??[],reports:Fe.data??[]}),$e=h.useMemo(()=>St(A),[A]),_e=h.useMemo(()=>Tt(K),[K]),I=h.useMemo(()=>{const a=Ae(p);return[...A].sort((d,m)=>new Date(m.startedAt).getTime()-new Date(d.startedAt).getTime()).filter(d=>{const m=l[d.id]??U(d);return(a.length===0||wt(d,m).includes(a))&&At(d,j)})},[l,p,j,A]),xe=h.useMemo(()=>Mt(K,n,N,D,L),[N,L,K,D,n]),me=I.length===A.length&&p.trim().length===0&&j.length===0?`${A.length} workout sessions visible`:`${I.length} of ${A.length} workout sessions visible`,R=I.find(a=>a.id===ue)??A.find(a=>a.id===ue)??null,he=R?l[R.id]??U(R):null;if(S.isLoading)return e.jsx(Je,{eyebrow:"Sports",title:"Loading sports view",description:"Reading synced workouts and local reflection metadata.",columns:2,blocks:6});if(S.isError||!H)return e.jsx(et,{eyebrow:"Sports",error:S.error??new Error("Sports data unavailable"),onRetry:()=>void S.refetch()});const{summary:v,weeklyTrend:pe,typeBreakdown:Ke}=H,ve=v.zoneMix??[],C=Et(xe,H.vitalsTrend),ge=n.length===0?"All exercise types":C.exerciseLabels.length>0?C.exerciseLabels.join(", "):`${n.length} selected types`,Oe=ve.map(a=>({zone:a.label,minutes:Math.round(a.seconds/60),percentage:Math.round(a.percentage*100),fill:G[a.key]??"#f8fafc"})),We=pe.map(a=>{const d=Object.fromEntries((a.zoneDurations??[]).map(m=>[m.key,Math.round(m.seconds/60)]));return{date:a.dateKey.slice(5),duration:a.durationMinutes,load:a.trainingLoad??0,coverage:Math.round((a.heartRateCoverage??0)*100),...d}}),Be=K.map(a=>{var d,m,E,$;return{duration:Math.round(a.durationSeconds/60),intensity:Math.round((((m=(d=a.analytics)==null?void 0:d.load)==null?void 0:m.intensity)??0)*100),load:(($=(E=a.analytics)==null?void 0:E.load)==null?void 0:$.trimp)??0,type:y(a),name:y(a)}});function Ve(a,d){o(m=>{const E=m[a]??U(A.find($=>$.id===a));return{...m,[a]:{...E,...d}}})}async function Ie(a){const d=A.find(E=>E.id===a);if(!d)return;const m=l[a]??U(d);await re.mutateAsync({workoutId:a,subjectiveEffort:m.subjectiveEffort,moodBefore:m.moodBefore,moodAfter:m.moodAfter,meaningText:m.meaningText,plannedContext:m.plannedContext,socialContext:m.socialContext,tagsText:m.tagsText,linkValues:m.linkValues}),se(null),Y(0)}return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(xt,{entityKind:"project",title:"Sports",description:"A session-first training surface for workout data, subjective meaning, and links back into Forge execution and Psyche.",badge:`${A.length} sessions`}),e.jsx(tt,{children:e.jsxs("section",{className:"grid gap-4 lg:grid-cols-4",children:[e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Weekly volume"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--primary)]",children:B(v.weeklyVolumeSeconds)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Total training time in the recent week."})]}),e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Exercise minutes"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:v.exerciseMinutes}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Aggregate exercise minutes from synced sessions."})]}),e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Energy burned"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:v.energyBurnedKcal}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Recent weekly kcal."})]}),e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Training streak"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:v.streakDays}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Distinct workout days in the recent week."})]}),e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Average session"}),e.jsxs("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:[v.averageSessionMinutes,"m"]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Mean duration across recent sessions."})]}),e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Training load"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:v.totalTrainingLoad??"n/a"}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Forge TRIMP across recent sessions."})]}),e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Linked sessions"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:v.linkedSessionCount}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Sessions already tied to Forge or Psyche entities."})]}),e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"HR coverage"}),e.jsxs("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:[Math.round((v.averageHeartRateCoverage??0)*100),"%"]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Average raw HR sample coverage."})]})]})}),e.jsx(J,{children:e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.1fr)_minmax(320px,0.9fr)]",children:[e.jsxs(g,{className:"min-h-[320px]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Load and volume trend"}),e.jsx(Z,{className:"mt-4 h-[260px]",children:e.jsx(P,{width:"100%",height:"100%",minWidth:1,minHeight:1,children:e.jsxs(vt,{data:We,children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"sportsLoad",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"#f97316",stopOpacity:.36}),e.jsx("stop",{offset:"100%",stopColor:"#f97316",stopOpacity:.04})]})}),e.jsx(ee,{stroke:"var(--ui-border-subtle)",vertical:!1}),e.jsx(q,{dataKey:"date",tick:{fill:"var(--ui-ink-faint)",fontSize:11}}),e.jsx(W,{tick:{fill:"var(--ui-ink-faint)",fontSize:11},width:34}),e.jsx(Q,{contentStyle:{background:"var(--ui-surface-popover)",border:"1px solid var(--ui-border-strong)",borderRadius:8,color:"var(--ui-ink-strong)"}}),e.jsx(ye,{type:"monotone",dataKey:"load",stroke:"#f97316",fill:"url(#sportsLoad)",strokeWidth:2}),e.jsx(ye,{type:"monotone",dataKey:"duration",stroke:"#38bdf8",fill:"var(--ui-info-soft)",strokeWidth:2})]})})})]}),e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Zone distribution"}),e.jsx("div",{className:"mt-4 grid gap-3",children:ve.map(a=>e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 text-sm",children:[e.jsx("span",{className:"text-[var(--ui-ink)]",children:a.label}),e.jsxs("span",{className:"text-[var(--ui-ink-strong)]",children:[Math.round(a.percentage*100),"% ·"," ",B(a.seconds)]})]}),e.jsx("div",{className:"h-2 overflow-hidden rounded-full bg-[var(--ui-surface-3)]",children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${Math.max(1,a.percentage*100)}%`,background:G[a.key]??"#f8fafc"}})})]},a.key))}),e.jsx(Z,{className:"mt-5 h-[180px]",children:e.jsx(P,{width:"100%",height:"100%",minWidth:1,minHeight:1,children:e.jsxs(ke,{data:Oe,children:[e.jsx(q,{dataKey:"zone",tick:{fill:"var(--ui-ink-faint)",fontSize:10}}),e.jsx(W,{tick:{fill:"var(--ui-ink-faint)",fontSize:10},width:34}),e.jsx(Q,{contentStyle:{background:"var(--ui-surface-popover)",border:"1px solid var(--ui-border-strong)",borderRadius:8,color:"var(--ui-ink-strong)"}}),e.jsx(ne,{dataKey:"minutes",fill:"#f97316",radius:[4,4,0,0]})]})})})]})]})}),e.jsx(J,{children:e.jsxs("section",{className:"grid gap-4",children:[e.jsxs(g,{className:"grid gap-4 overflow-hidden",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"HR zone analysis"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:"Filter all-time workout evidence by exercise type and date."})]}),e.jsxs(c,{tone:"meta",children:[xe.length," of ",K.length," ","sessions"]})]}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1fr)_minmax(280px,0.8fr)]",children:[e.jsx(je,{title:"Exercise types",description:"Select one, many, or none for all exercise types.",query:x,onQueryChange:w,options:_e,selectedOptionIds:n,onSelectedOptionIdsChange:u,resultSummary:ge,placeholder:"Search exercise types",emptyStateMessage:"No exercise type matches."}),e.jsxs("div",{className:"grid gap-3 rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Date range"}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:[["all","All time"],["recent_90","90 days"],["custom","Custom"]].map(([a,d])=>e.jsx("button",{type:"button",className:`rounded-[8px] border px-3 py-2 text-sm transition ${N===a?"border-[var(--primary)] bg-[var(--primary)]/12 text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]"}`,onClick:()=>T(a),children:d},a))}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Start"}),e.jsx(F,{type:"date",value:D,onChange:a=>{i(a.target.value),T("custom")}})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"End"}),e.jsx(F,{type:"date",value:L,onChange:a=>{Te(a.target.value),T("custom")}})]})]})]})]})]}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,0.85fr)_minmax(0,1.15fr)]",children:[e.jsxs(g,{className:"min-h-[330px] overflow-hidden",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Average zones"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:"Duration-weighted proportion of time in each HR zone."})]}),e.jsx(c,{tone:"meta",children:ge})]}),e.jsx(Z,{className:"mt-4 h-[235px]",children:C.sessions.length>0?e.jsx(P,{width:"100%",height:"100%",minWidth:1,minHeight:1,children:e.jsxs(ke,{data:C.averageZoneData,children:[e.jsx(ee,{stroke:"var(--ui-border-subtle)",vertical:!1}),e.jsx(q,{dataKey:"zone",interval:0,tick:{fill:"var(--ui-ink-faint)",fontSize:10}}),e.jsx(W,{unit:"%",domain:[0,100],ticks:[0,25,50,75,100],tick:{fill:"var(--ui-ink-faint)",fontSize:10},width:38}),e.jsx(Q,{formatter:a=>[`${a}%`,"Average time"],contentStyle:{background:"var(--ui-surface-popover)",border:"1px solid var(--ui-border-strong)",borderRadius:8,color:"var(--ui-ink-strong)"}}),e.jsx(ne,{dataKey:"percentage",radius:[4,4,0,0],children:C.averageZoneData.map(a=>e.jsx(gt,{fill:a.fill},a.key))})]})}):e.jsx("div",{className:"grid h-full place-items-center rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-6 text-center text-sm leading-6 text-[var(--ui-ink-soft)]",children:"No selected sessions with zone analytics are available yet."})}),C.sessions.length>0?e.jsxs("div",{className:"mt-3 grid gap-2 text-sm text-[var(--ui-ink-soft)] sm:grid-cols-3",children:[e.jsxs("div",{children:[C.rawHrCount," sessions have raw HR timelines"]}),e.jsxs("div",{children:["Latest: ",((fe=C.lineData.at(-1))==null?void 0:fe.dateKey)??"n/a"]}),e.jsxs("div",{children:["VO2max points:"," ",C.lineData.filter(a=>a.vo2Max!=null).length]})]}):null]}),e.jsxs(g,{className:"min-h-[330px] overflow-hidden",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:k==="expanding_lines"?"Expanding zone lines":"Zone drift"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:k==="expanding_lines"?"Expanding all-session average with resting HR and VO2max overlay.":"Rolling duration-weighted zone mix with resting HR and VO2max overlay."})]}),e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:items-end",children:[e.jsx("div",{className:"grid grid-cols-2 gap-1 rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-1","aria-label":"Zone chart display",children:[["rolling_stack","Stacked"],["expanding_lines","Lines"]].map(([a,d])=>e.jsx("button",{type:"button",className:`min-h-9 rounded-[6px] px-3 py-1.5 text-xs font-medium transition ${k===a?"bg-[var(--primary)]/18 text-[var(--ui-ink-strong)]":"text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]"}`,onClick:()=>M(a),children:d},a))}),e.jsx(c,{tone:"meta",children:"HRR zones"})]})]}),e.jsx(Z,{className:"mt-4 h-[255px]",children:C.lineData.length>0?e.jsx(P,{width:"100%",height:"100%",minWidth:1,minHeight:1,children:e.jsxs(ft,{data:k==="expanding_lines"?C.expandingLineData:C.lineData,children:[e.jsx(ee,{stroke:"var(--ui-border-subtle)",vertical:!1}),e.jsx(q,{dataKey:"date",tick:{fill:"var(--ui-ink-faint)",fontSize:10}}),e.jsx(W,{yAxisId:"zones",domain:[0,100],ticks:[0,25,50,75,100],unit:"%",tick:{fill:"var(--ui-ink-faint)",fontSize:10},width:38}),e.jsx(W,{yAxisId:"vitals",orientation:"right",tick:{fill:"var(--ui-ink-faint)",fontSize:10},width:42}),e.jsx(Q,{formatter:(a,d,m)=>Rt(a,d,m),contentStyle:{background:"var(--ui-surface-popover)",border:"1px solid var(--ui-border-strong)",borderRadius:8,color:"var(--ui-ink-strong)"}}),e.jsx(bt,{wrapperStyle:{color:"var(--ui-ink)",fontSize:11}}),k==="expanding_lines"?V.map(a=>e.jsx(le,{yAxisId:"zones",type:"monotone",dataKey:a,name:z(a),stroke:G[a],strokeWidth:2,dot:{r:2.5},activeDot:{r:4},connectNulls:!0},a)):V.map(a=>e.jsx(ne,{yAxisId:"zones",dataKey:a,stackId:"zones",fill:G[a],isAnimationActive:!1},a)),e.jsx(le,{yAxisId:"vitals",type:"monotone",dataKey:"restingHeartRate",name:"Resting HR",stroke:"var(--ui-ink-soft)",strokeWidth:2,dot:{r:3},connectNulls:!0}),e.jsx(le,{yAxisId:"vitals",type:"monotone",dataKey:"vo2Max",name:"VO2max",stroke:"#a78bfa",strokeWidth:2,dot:{r:3},connectNulls:!0})]})}):e.jsx("div",{className:"grid h-full place-items-center rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-6 text-center text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Select workouts with HR evidence to unlock the time-series plot."})})]})]})]})}),e.jsx(J,{children:e.jsxs("section",{className:"grid gap-4 lg:grid-cols-[minmax(0,1fr)_360px]",children:[e.jsxs(g,{className:"min-h-[300px]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Duration vs intensity"}),e.jsx(Z,{className:"mt-4 h-[250px]",children:e.jsx(P,{width:"100%",height:"100%",minWidth:1,minHeight:1,children:e.jsxs(jt,{data:Be,children:[e.jsx(ee,{stroke:"var(--ui-border-subtle)"}),e.jsx(q,{type:"number",dataKey:"duration",name:"minutes",tick:{fill:"var(--ui-ink-faint)",fontSize:11}}),e.jsx(W,{type:"number",dataKey:"intensity",name:"intensity",tick:{fill:"var(--ui-ink-faint)",fontSize:11},width:38}),e.jsx(Q,{cursor:{strokeDasharray:"3 3"},contentStyle:{background:"var(--ui-surface-popover)",border:"1px solid var(--ui-border-strong)",borderRadius:8,color:"var(--ui-ink-strong)"}}),e.jsx(yt,{dataKey:"load",fill:"#f97316"})]})})})]}),e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Evidence quality"}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsxs("div",{className:"rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Raw HR coverage"}),e.jsxs("div",{className:"mt-2 text-2xl text-[var(--ui-ink-strong)]",children:[Math.round((v.averageHeartRateCoverage??0)*100),"%"]})]}),e.jsxs("div",{className:"rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Route-backed workouts"}),e.jsx("div",{className:"mt-2 text-2xl text-[var(--ui-ink-strong)]",children:v.routeWorkoutCount??0})]}),e.jsxs("div",{className:"rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Top sport"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:v.topWorkoutTypeLabel??v.topWorkoutType??"n/a"})]})]})]})]})}),e.jsx(J,{children:e.jsxs("section",{className:"grid gap-4 lg:grid-cols-[1.05fr_0.95fr]",children:[e.jsxs(g,{className:"grid gap-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Recent volume"}),e.jsx("div",{className:"grid gap-3",children:pe.map(a=>e.jsxs("div",{className:"grid gap-2 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3 md:grid-cols-[110px_150px_minmax(0,1fr)_90px]",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:a.dateKey}),e.jsx("div",{className:"text-sm text-[var(--ui-ink-strong)]",children:a.workoutTypeLabel??z(a.workoutType)}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"h-2 flex-1 overflow-hidden rounded-full bg-[var(--ui-surface-3)]",children:e.jsx("div",{className:"h-full rounded-full bg-[var(--primary)]",style:{width:`${Math.min(100,a.durationMinutes/120*100)}%`}})}),e.jsxs("div",{className:"text-sm text-[var(--ui-ink-strong)]",children:[a.durationMinutes,"m"]})]}),e.jsxs("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:[a.energyKcal," kcal"]})]},a.id))}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Distance"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:de(v.distanceMeters)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Planned sessions"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:v.plannedSessionCount})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Imported / merged"}),e.jsxs("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:[v.importedSessionCount," /"," ",v.reconciledSessionCount]})]})]})]}),e.jsxs(g,{className:"grid gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Training composition"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:"Workout type and provenance mix"})]}),e.jsx("div",{className:"grid gap-3",children:Ke.slice(0,6).map(a=>e.jsxs("div",{className:"grid gap-2 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3 md:grid-cols-[minmax(0,1fr)_90px_90px]",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[var(--ui-ink-strong)]",children:a.workoutTypeLabel??z(a.workoutType)}),e.jsxs("div",{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:[a.sessionCount," sessions ·"," ",a.activityFamilyLabel??"Other"]})]}),e.jsxs("div",{className:"text-sm text-[var(--ui-ink)]",children:[a.totalMinutes,"m"]}),e.jsxs("div",{className:"text-sm text-[var(--ui-ink)]",children:[a.energyKcal," kcal"]})]},a.workoutType))}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Habit-generated"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:v.habitGeneratedSessionCount})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Forge-linked"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:v.linkedSessionCount})]})]})]})]})}),e.jsx(at,{children:e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,25rem)_minmax(0,1fr)]",children:[e.jsx(je,{title:"Session browser",description:"Search past activities by workout type, source, reconciliation state, or whether they still need context.",query:p,onQueryChange:f,options:$e,selectedOptionIds:j,onSelectedOptionIdsChange:b,resultSummary:me,placeholder:"Search workouts, devices, notes, moods, or filter chips",emptyStateMessage:"Keep typing or pick a filter chip to narrow the activity history."}),e.jsxs(g,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Activity history"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:"Open a workout to add reflection and links in a guided modal."})]}),e.jsx(c,{tone:"meta",children:me})]}),e.jsx("div",{className:"max-h-[34rem] overflow-y-auto rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-3",children:I.length===0?e.jsx("div",{className:"flex min-h-[18rem] items-center justify-center p-6 text-center text-sm leading-6 text-[var(--ui-ink-faint)]",children:"No workout matches the current search yet. Clear some filters or search by workout type, device, or reflection text."}):e.jsx("div",{className:"grid gap-3",children:I.map(a=>{var m,E,$;const d=a.meaningText.trim().length>0||a.moodBefore.trim().length>0||a.moodAfter.trim().length>0||a.tags.length>0||a.links.length>0;return e.jsxs("div",{className:"grid w-full min-w-0 gap-3 rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3 text-left transition hover:bg-[var(--ui-surface-2)]",children:[e.jsxs("div",{className:"grid min-w-0 gap-3 sm:flex sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs(Pe,{to:`/sports/workouts/${a.id}`,className:"flex min-w-0 items-center gap-2 text-[var(--ui-ink-strong)] transition hover:text-[var(--primary)]",children:[e.jsx(we,{className:"size-4 shrink-0 text-[var(--primary)]"}),e.jsx("span",{className:"truncate text-base font-medium",children:y(a)})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 items-center gap-2 text-sm text-[var(--ui-ink-soft)]",children:[e.jsx(qe,{className:"size-3.5 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate",children:X(a.startedAt,a.endedAt)})]}),e.jsxs("div",{className:"mt-2 text-sm text-[var(--ui-ink-faint)]",children:[_(a)," ·"," ",a.sourceDevice]})]}),e.jsxs("button",{type:"button","aria-label":`Edit ${y(a)} reflection`,className:"inline-flex w-fit max-w-full items-center gap-2 rounded-full bg-[var(--ui-surface-2)] px-3 py-1.5 text-xs text-[var(--ui-ink)] transition hover:bg-[var(--ui-surface-3)] hover:text-[var(--ui-ink-strong)]",onClick:()=>{se(a.id),Y(0)},children:[e.jsx("span",{className:"truncate",children:d?"Reflected":"Needs reflection"}),e.jsx(Se,{className:"size-3.5 shrink-0"})]})]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap gap-2",children:[e.jsx(c,{children:B(a.durationSeconds)}),a.totalEnergyKcal?e.jsxs(c,{tone:"meta",children:[Math.round(a.totalEnergyKcal)," kcal"]}):null,a.distanceMeters?e.jsx(c,{tone:"meta",children:de(a.distanceMeters)}):null,a.averageHeartRate?e.jsxs(c,{tone:"meta",children:[e.jsx(Qe,{className:"mr-1 size-3.5"}),Math.round(a.averageHeartRate)," bpm"]}):null,e.jsx(c,{tone:"meta",children:_(a)}),e.jsx(c,{tone:"meta",className:"capitalize",children:a.sourceType.replaceAll("_"," ")}),e.jsx(c,{tone:"meta",className:"capitalize",children:a.reconciliationStatus.replaceAll("_"," ")}),(m=a.analytics)!=null&&m.confidence?e.jsxs(c,{tone:"meta",children:[a.analytics.confidence," zones"]}):null,($=(E=a.analytics)==null?void 0:E.routeSummary)!=null&&$.hasRoute?e.jsx(c,{tone:"meta",children:"Route"}):null]})]},a.id)})})})]})]})}),R&&he?e.jsx(st,{open:!!R,onOpenChange:a=>{a||(se(null),Y(0))},eyebrow:"Sports session",title:y(R),description:"Add contextual meaning without crowding the main training surface.",children:e.jsx(zt,{session:R,draft:he,linkOptions:Le,pending:re.isPending&&((be=re.variables)==null?void 0:be.workoutId)===R.id,step:Re,onStepChange:Y,onDraftChange:a=>Ve(R.id,a),onSave:()=>void Ie(R.id)})}):null]})}export{qt as SportsPage,Rt as formatZoneTrendTooltipValue};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{b5 as q,c2 as U,r as n,j as e,b4 as z,b3 as A,ce as $,c7 as O}from"./vendor-Dnkkx2co.js";import{j as Q,k as I}from"./state-vCcAT5Hq.js";import{b as F,S as G}from"./strategy-dialog-BTwkaSxI.js";import{P as R}from"./page-hero-CONuJu5J.js";import{u as H,s as K,bZ as Z,b_ as J,b$ as V,B as o,C as M,I as W,a as X,U as Y,c as x}from"./index-QJkjKYzZ.js";import"./board-dIX6etHh.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./graph-DDUZNRsO.js";function ee(a){return a.trim().toLowerCase()}function xe(){const a=H(),h=q(),B=Q(),[v,j]=U(),[E,l]=n.useState(!1),[T,d]=n.useState(null),[m,_]=n.useState(""),D=K(a.selectedUserIds);n.useEffect(()=>{v.get("create")==="1"&&(d(null),l(!0),j(s=>{const t=new URLSearchParams(s);return t.delete("create"),t},{replace:!0}))},[v,j]);const f=async()=>{await B.invalidateQueries({queryKey:["strategy-detail"]}),await a.refresh()},N=I({mutationFn:async({input:s,strategyId:t})=>t?(await Z(t,s)).strategy:(await J(s)).strategy,onSuccess:async()=>{await f()}}),u=I({mutationFn:async s=>V(s),onSuccess:async()=>{await f()}}),k=n.useMemo(()=>new Map(a.snapshot.goals.map(s=>[s.id,s])),[a.snapshot.goals]),p=n.useMemo(()=>new Map(a.snapshot.dashboard.projects.map(s=>[s.id,s])),[a.snapshot.dashboard.projects]),b=n.useMemo(()=>new Map(a.snapshot.tasks.map(s=>[s.id,s])),[a.snapshot.tasks]),S=n.useMemo(()=>{const s=ee(m);return s?a.snapshot.strategies.filter(t=>{var w,y,C;const g=t.targetGoalIds.map(c=>{var r;return((r=k.get(c))==null?void 0:r.title)??""}).join(" "),i=t.targetProjectIds.map(c=>{var r;return((r=p.get(c))==null?void 0:r.title)??""}).join(" "),L=t.graph.nodes.map(c=>{var r,P;return c.entityType==="project"?((r=p.get(c.entityId))==null?void 0:r.title)??"":((P=b.get(c.entityId))==null?void 0:P.title)??""}).join(" ");return[t.title,t.overview,t.endStateDescription,t.status,((w=t.user)==null?void 0:w.displayName)??"",((y=t.user)==null?void 0:y.handle)??"",((C=t.user)==null?void 0:C.kind)??"",g,i,L].join(" ").toLowerCase().includes(s)}):a.snapshot.strategies},[k,p,m,a.snapshot.strategies,b]);return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(R,{title:"Strategies",titleText:"Strategies",description:"Strategies connect human and bot work into a directed plan, with explicit end goals, ownership, and live alignment metrics.",badge:`${a.snapshot.strategies.length} strategies`,actions:e.jsxs(o,{onClick:()=>{d(null),l(!0)},children:[e.jsx(z,{className:"size-4"}),"New strategy"]})}),e.jsxs(M,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(A,{className:"size-4 text-[var(--ui-ink-muted)]"}),e.jsx(W,{value:m,onChange:s=>_(s.target.value),placeholder:"Search strategy title, target, graph node, human, or bot"})]}),e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Search includes owners, target goals/projects, and graph nodes so cross-user plans stay discoverable."})]}),S.length===0?e.jsx(X,{eyebrow:"Strategies",title:"No strategies in this scope",description:"Create a strategy to connect projects and tasks into a non-looping execution plan across human and bot actors.",action:e.jsx(o,{onClick:()=>{d(null),l(!0)},children:"Create strategy"})}):e.jsx("div",{className:"grid gap-4",children:S.map(s=>{const t=s.graph.nodes.filter(i=>s.metrics.activeNodeIds.includes(i.id)),g=F(s.metrics);return e.jsxs(M,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsx("div",{className:"min-w-0",children:e.jsxs("button",{type:"button",className:"text-left",onClick:()=>h(`/strategies/${s.id}`),children:[e.jsx("div",{className:"font-display text-2xl text-[var(--ui-ink-strong)]",children:s.title}),e.jsx("div",{className:"mt-2 max-w-3xl text-sm leading-6 text-[var(--ui-ink-soft)]",children:s.overview||s.endStateDescription})]})}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(Y,{user:s.user}),e.jsx(x,{className:s.isLocked?"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_76%,var(--ui-ink-strong)_24%)]":"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)]",children:s.isLocked?"Contract locked":"Editable draft"}),e.jsx(x,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:s.status}),e.jsxs(x,{className:"bg-[var(--primary)]/14 text-[var(--primary)]",children:[s.metrics.alignmentScore,"% aligned"]})]})]}),e.jsxs("div",{className:"grid gap-3 lg:grid-cols-4",children:[e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Graph progress"}),e.jsxs("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:[s.metrics.startedNodeCount,"/",s.metrics.totalNodeCount]}),e.jsxs("div",{className:"text-xs leading-5 text-[var(--ui-ink-soft)]",children:[s.metrics.completedNodeCount," completed"]})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Ready branches"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:s.metrics.readyNodeCount}),e.jsx("div",{className:"text-xs leading-5 text-[var(--ui-ink-soft)]",children:"Nodes whose prerequisites are already satisfied."})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"End targets"}),e.jsxs("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:[s.metrics.completedTargetCount,"/",s.metrics.totalTargetCount||0]}),e.jsxs("div",{className:"text-xs leading-5 text-[var(--ui-ink-soft)]",children:[s.metrics.targetProgressScore,"% target progress"]})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Sequencing"}),e.jsxs("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:[s.metrics.sequencingScore,"%"]})]})]}),e.jsxs("div",{className:"grid gap-3 xl:grid-cols-[minmax(0,1.2fr)_minmax(16rem,0.8fr)]",children:[e.jsx("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-4 py-4",children:e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Active next nodes"}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:t.length===0?e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"No currently open branch."}):t.map(i=>e.jsx(x,{className:"bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)]",children:i.title},i.id))})]}),e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Alignment breakdown"}),e.jsx("div",{className:"mt-3 grid gap-2 text-sm text-[var(--ui-ink-soft)]",children:g.map(i=>e.jsxs("div",{children:[i.label," ",i.value,"%"]},i.id))})]})]})}),e.jsxs("div",{className:"flex flex-wrap items-end justify-end gap-2",children:[s.isLocked?null:e.jsxs(o,{variant:"secondary",onClick:()=>{d(s),l(!0)},children:[e.jsx($,{className:"size-4"}),"Edit"]}),e.jsxs(o,{variant:"secondary",pending:u.isPending&&u.variables===s.id,pendingLabel:"Deleting strategy",onClick:()=>{window.confirm(`Delete strategy "${s.title}"?`)&&u.mutateAsync(s.id)},children:[e.jsx(O,{className:"size-4"}),"Delete"]}),e.jsx(o,{onClick:()=>h(`/strategies/${s.id}`),children:"Open strategy"})]})]})]},s.id)})}),e.jsx(G,{open:E,pending:N.isPending,editingStrategy:T,goals:a.snapshot.dashboard.goals,projects:a.snapshot.dashboard.projects,tasks:a.snapshot.tasks,habits:a.snapshot.habits,strategies:a.snapshot.strategies,users:a.snapshot.users,defaultUserId:D,onOpenChange:l,onSubmit:async(s,t)=>{await N.mutateAsync({input:s,strategyId:t})}})]})}export{xe as StrategiesPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as p,j as e,cA as W,cx as K,cE as V,cC as Z,aC as B,cc as J,b5 as X}from"./vendor-Dnkkx2co.js";import{j as Y,i as ee,k as A}from"./state-vCcAT5Hq.js";import{O as se}from"./open-in-graph-button-CMjJZX7G.js";import{P as te}from"./preference-entity-handoff-button-CKDxCnbl.js";import{a as ae,i as re,b as ie,S as ne}from"./strategy-dialog-BTwkaSxI.js";import{i as le,C as oe,B as de,M as ce}from"./graph-DDUZNRsO.js";import{c as m,U as _,u as ue,s as xe,bZ as F,b$ as me,L as ge,E as G,B as L,C as k,W as pe,bq as he,c0 as fe}from"./index-QJkjKYzZ.js";import{P as ve}from"./page-hero-CONuJu5J.js";import"./board-dIX6etHh.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";function Q(a){const i=new Map;for(const r of a.nodes)i.set(r.id,[]);for(const r of a.edges)i.set(r.to,[...i.get(r.to)??[],r.from]);const o=new Map,d=r=>{const c=o.get(r);if(c!==void 0)return c;const j=i.get(r)??[],h=j.length===0?0:Math.max(...j.map(l=>d(l)))+1;return o.set(r,h),h};for(const r of a.nodes)d(r.id);return o}function be(a){const i=Q(a),o=new Map;for(const d of a.nodes){const r=i.get(d.id)??0;o.set(r,[...o.get(r)??[],d.id])}return Array.from(o.entries()).sort((d,r)=>d[0]-r[0]).map(([d,r])=>({level:d,nodeIds:r}))}function je(a,i){const o=Q(a.graph),d=new Map;for(const r of a.graph.nodes){const c=o.get(r.id)??0;d.set(c,[...d.get(c)??[],r.id])}return a.graph.nodes.map(r=>{const c=o.get(r.id)??0,j=(d.get(c)??[]).indexOf(r.id),h=a.metrics.activeNodeIds.includes(r.id),l=a.metrics.blockedNodeIds.includes(r.id),x=a.metrics.outOfOrderNodeIds.includes(r.id),v=!h&&!l&&!x,s=(i==null?void 0:i.get(r.id))??null;let g="border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",n="bg-[var(--ui-surface-3)] text-[var(--ui-ink-soft)]";return h?(g="border-[color-mix(in_srgb,var(--success)_34%,var(--ui-border-subtle))] bg-[var(--ui-success-soft)]",n="bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]"):l?(g="border-[color-mix(in_srgb,var(--danger)_32%,var(--ui-border-subtle))] bg-[var(--ui-danger-soft)]",n="bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_78%,var(--ui-ink-strong)_22%)]"):x?(g="border-[color-mix(in_srgb,var(--warning)_34%,var(--ui-border-subtle))] bg-[var(--ui-warning-soft)]",n="bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]"):a.metrics.completedNodeCount>0&&(g="border-[color-mix(in_srgb,var(--info)_30%,var(--ui-border-subtle))] bg-[var(--ui-info-soft)]",n="bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]"),{id:r.id,position:{x:72+c*308,y:56+j*168},draggable:!1,selectable:!1,data:{label:e.jsxs("div",{className:`w-[min(17rem,calc(100vw-5rem))] min-w-0 max-w-[17rem] rounded-[22px] border px-4 py-4 shadow-[var(--ui-shadow-soft)] ${g}`,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(m,{className:"bg-[var(--ui-surface-3)] text-[var(--ui-ink-soft)]",children:r.entityType}),h?e.jsx(m,{className:n,children:"Active"}):null,l?e.jsx(m,{className:n,children:"Blocked"}):null,x?e.jsx(m,{className:n,children:"Out of order"}):null,v&&!l&&!x?e.jsx(m,{className:n,children:"In plan"}):null]}),e.jsx("div",{className:"mt-3 break-words text-base font-medium leading-6 text-[var(--ui-ink-strong)]",children:r.title}),r.branchLabel?e.jsx("div",{className:"mt-2 break-words text-xs uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:r.branchLabel}):null,r.notes?e.jsx("div",{className:"mt-2 break-words text-sm leading-5 text-[var(--ui-ink-soft)]",children:r.notes}):null,s?e.jsxs("div",{className:"mt-3 flex min-w-0 items-center gap-2 text-xs text-[var(--ui-ink-faint)]",children:[e.jsx("span",{className:"inline-block size-2.5 rounded-full",style:{backgroundColor:s.color}}),e.jsx("span",{className:"min-w-0 break-words",children:s.label})]}):null]})},style:{background:"transparent",border:"none",padding:0}}})}function ye(a){return a.graph.edges.map(i=>{const o=a.metrics.activeNodeIds.includes(i.to),d=a.metrics.blockedNodeIds.includes(i.to),r=a.metrics.outOfOrderNodeIds.includes(i.to);let c="var(--ui-border-strong)";return o?c="var(--success)":d?c="var(--danger)":r&&(c="var(--warning)"),{id:`${i.from}->${i.to}`,source:i.from,target:i.to,label:i.label||void 0,animated:o,markerEnd:{type:ce.ArrowClosed,color:c},style:{stroke:c,strokeWidth:o?2.4:1.5},labelStyle:{fill:"var(--ui-ink-soft)",fontSize:11,fontWeight:600}}})}function we({strategy:a,ownerByNodeId:i,heightClassName:o="h-[540px]"}){const d=p.useMemo(()=>je(a,i),[i,a]),r=p.useMemo(()=>ye(a),[a]);return e.jsx("div",{className:`${o} min-w-0 overflow-hidden rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] shadow-[var(--ui-shadow-soft)]`,children:e.jsxs(le,{fitView:!0,nodes:d,edges:r,nodesDraggable:!1,nodesConnectable:!1,elementsSelectable:!1,attributionPosition:"bottom-left",children:[e.jsx(oe,{showInteractive:!1}),e.jsx(de,{gap:28,size:1,color:"var(--ui-border-subtle)"})]})})}function Ne(a,i){const o=a.metrics.activeNodeIds.includes(i),d=a.metrics.blockedNodeIds.includes(i),r=a.metrics.outOfOrderNodeIds.includes(i);return d?{label:"Blocked",className:"bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_78%,var(--ui-ink-strong)_22%)]"}:r?{label:"Out of order",className:"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]"}:o?{label:"Ready now",className:"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]"}:{label:"In plan",className:"bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]"}}function ke({strategy:a,projectsById:i,tasksById:o,className:d}){const r=p.useMemo(()=>be(a.graph),[a.graph]),c=p.useMemo(()=>{const l=new Map;for(const x of a.graph.nodes)l.set(x.id,[]);for(const x of a.graph.edges)l.set(x.to,[...l.get(x.to)??[],x.from]);return l},[a.graph]),[j,h]=p.useState([]);return e.jsxs("div",{className:d??"grid gap-3",children:[r.map(l=>{const x=j.includes(l.level),v=l.level===0?"Launch phase":`Phase ${l.level+1}`,s=l.nodeIds.length>1;return e.jsxs("div",{className:"min-w-0 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] shadow-[var(--ui-shadow-soft)]",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 px-4 py-4",children:[e.jsxs("button",{type:"button",className:"flex min-w-0 max-w-full items-center gap-3 text-left",onClick:()=>h(g=>x?g.filter(n=>n!==l.level):[...g,l.level]),children:[e.jsx("span",{className:"rounded-full bg-[var(--ui-surface-3)] p-2 text-[var(--ui-ink-soft)]",children:x?e.jsx(W,{className:"size-4"}):e.jsx(K,{className:"size-4"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"break-words font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:v}),e.jsx("div",{className:"mt-1 break-words text-sm text-[var(--ui-ink-soft)]",children:s?"These branches can progress in parallel once the previous phase is complete.":"This phase advances as one focused step in the strategy."})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(m,{className:"bg-[var(--ui-surface-3)] text-[var(--ui-ink-soft)]",children:[l.nodeIds.length," node",l.nodeIds.length===1?"":"s"]}),e.jsx(m,{className:"bg-[var(--ui-surface-3)] text-[var(--ui-ink-soft)]",children:s?e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"mr-1 size-3.5"}),"Parallel"]}):e.jsxs(e.Fragment,{children:[e.jsx(Z,{className:"mr-1 size-3.5"}),"Sequential"]})})]})]}),x?null:e.jsx("div",{className:"grid min-w-0 gap-3 border-t border-[var(--ui-border-subtle)] px-4 py-4 lg:grid-cols-2",children:l.nodeIds.map(g=>{var T,N,O;const n=a.graph.nodes.find(f=>f.id===g);if(!n)return null;const w=n.entityType==="project"?i.get(n.entityId):o.get(n.entityId),M=n.entityType==="project"?`/projects/${n.entityId}`:`/tasks/${n.entityId}`,I=n.entityType==="project"?(T=i.get(n.entityId))==null?void 0:T.user:(N=o.get(n.entityId))==null?void 0:N.user,b=((O=c.get(n.id))==null?void 0:O.map(f=>{var P;return((P=a.graph.nodes.find($=>$.id===f))==null?void 0:P.title)??f}))??[],y=Ne(a,n.id);return e.jsxs("div",{className:"min-w-0 rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(m,{className:"bg-[var(--ui-surface-3)] text-[var(--ui-ink-soft)]",children:n.entityType}),e.jsx(m,{className:y.className,children:y.label})]}),e.jsx(B,{to:M,className:"mt-3 block break-words text-lg font-medium text-[var(--ui-ink-strong)] transition hover:text-[var(--primary)]",children:n.title}),e.jsx("div",{className:"mt-2 break-words text-sm leading-6 text-[var(--ui-ink-soft)]",children:n.notes||("description"in(w??{})?w==null?void 0:w.description:"")||"No extra step note attached yet."})]}),e.jsx(_,{user:I,compact:!0})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[n.branchLabel?e.jsx(m,{className:"bg-[var(--ui-accent-soft)] text-[var(--primary)]",children:n.branchLabel}):null,b.length===0?e.jsx(m,{className:"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]",children:"Start node"}):b.map(f=>e.jsxs(m,{className:"max-w-full break-words bg-[var(--ui-surface-3)] text-[var(--ui-ink-soft)]",children:["Depends on ",f]},`${n.id}:${f}`))]})]},n.id)})})]},l.level)}),r.length===0?e.jsx("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-4 text-sm text-[var(--ui-ink-soft)]",children:"No phases mapped yet."}):null]})}function De(){var $;const a=ue(),{strategyId:i}=J(),o=X(),d=Y(),[r,c]=p.useState(!1),[j,h]=p.useState(),l=xe(a.selectedUserIds),x=a.snapshot.strategies.find(t=>t.id===i)??null,v=ee({queryKey:["strategy-detail",i],queryFn:async()=>(await fe(i)).strategy,enabled:!!(i&&!x)}),s=x??v.data??null,g=async()=>{await Promise.all([d.invalidateQueries({queryKey:["strategy-detail",i]}),a.refresh()])},n=A({mutationFn:async({input:t,currentStrategyId:u})=>(await F(u,t)).strategy,onSuccess:g}),w=A({mutationFn:async t=>me(t),onSuccess:async()=>{await g(),o("/strategies")}}),M=A({mutationFn:async t=>(await F(i,{isLocked:t,lockedByUserId:t?l??(s==null?void 0:s.userId)??"user_operator":null})).strategy,onSuccess:g}),I=p.useMemo(()=>new Map(a.snapshot.goals.map(t=>[t.id,t])),[a.snapshot.goals]),b=p.useMemo(()=>new Map(a.snapshot.dashboard.projects.map(t=>[t.id,t])),[a.snapshot.dashboard.projects]),y=p.useMemo(()=>new Map(a.snapshot.tasks.map(t=>[t.id,t])),[a.snapshot.tasks]),T=p.useMemo(()=>s?new Map(s.graph.nodes.map(t=>{var S,C;const u=t.entityType==="project"?(S=b.get(t.entityId))==null?void 0:S.user:(C=y.get(t.entityId))==null?void 0:C.user;return[t.id,u?{label:`${u.displayName} (${u.kind})`,color:u.accentColor}:null]})):new Map,[b,s,y]),N=s??{title:"",overview:"",endStateDescription:"",targetGoalIds:[],targetProjectIds:[],graph:{nodes:[],edges:[]}},O=p.useMemo(()=>ae(N),[N]),f=p.useMemo(()=>re(N),[N]),P=p.useMemo(()=>ie((s==null?void 0:s.metrics)??{planCoverageScore:0,sequencingScore:0,scopeDisciplineScore:0,qualityScore:0,targetProgressScore:0,startedNodeCount:0,totalNodeCount:1,offPlanEntityCount:0,offPlanActiveEntityCount:0,blockedNodeIds:[],outOfOrderNodeIds:[]}),[s==null?void 0:s.metrics]);return v.isLoading&&!s?e.jsx(ge,{eyebrow:"Strategy",title:"Loading strategy",description:"Resolving the directed plan, targets, and current alignment."}):v.isError?e.jsx(G,{eyebrow:"Strategy",error:v.error,onRetry:()=>void v.refetch()}):s?e.jsxs("div",{className:"grid gap-5",children:[e.jsx(ve,{title:s.title,titleText:s.title,description:s.overview||s.endStateDescription,badge:`${s.metrics.alignmentScore}% aligned`,actions:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(te,{userId:l,domain:"strategies",entityType:"strategy",entityId:s.id,label:s.title,description:s.overview||s.endStateDescription}),e.jsx(se,{entityType:"strategy",entityId:s.id}),s.isLocked?null:e.jsx(L,{variant:"secondary",onClick:()=>{h(void 0),c(!0)},children:"Edit strategy"}),e.jsx(L,{variant:"secondary",disabled:!s.isLocked&&!f,pending:M.isPending,pendingLabel:s.isLocked?"Unlocking contract":"Locking contract",onClick:()=>{M.mutateAsync(!s.isLocked)},children:s.isLocked?"Unlock contract":"Lock as contract"}),e.jsx(L,{variant:"secondary",pending:w.isPending,pendingLabel:"Deleting strategy",onClick:()=>{window.confirm(`Delete strategy "${s.title}"?`)&&w.mutateAsync(s.id)},children:"Delete"})]})}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(_,{user:s.user}),e.jsx(m,{className:s.isLocked?"bg-amber-500/12 text-amber-200":"bg-emerald-500/12 text-emerald-200",children:s.isLocked?"Contract locked":"Editable draft"}),e.jsx(m,{className:"bg-white/[0.08] text-white/76",children:s.status}),e.jsxs(m,{className:"bg-white/[0.08] text-white/76",children:[s.graph.nodes.length," nodes"]}),e.jsxs(m,{className:"bg-white/[0.08] text-white/76",children:[s.graph.edges.length," edges"]})]}),e.jsxs("div",{className:"grid gap-5 xl:grid-cols-[minmax(0,1.15fr)_minmax(18rem,0.85fr)]",children:[e.jsxs("div",{className:"grid gap-5",children:[e.jsxs(k,{className:"grid gap-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/45",children:"End state"}),e.jsx("div",{className:"text-sm leading-7 text-white/64",children:s.endStateDescription||"No end-state description yet."})]}),e.jsxs(k,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/45",children:"Directed execution graph"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-white/58",children:"The graph is the contract surface for this strategy. It shows which branches are available now, where work is blocked, and whether any node is moving out of sequence."})]}),s.isLocked?null:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(L,{variant:"secondary",onClick:()=>{h("sequence"),c(!0)},children:"Refine sequence"}),e.jsx(L,{onClick:()=>{h("sequence"),c(!0)},children:"Add parallel work"})]})]}),e.jsx(we,{strategy:s,ownerByNodeId:T}),e.jsx(ke,{strategy:s,projectsById:b,tasksById:y})]})]}),e.jsxs("div",{className:"grid gap-5",children:[e.jsxs(k,{className:"grid gap-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/45",children:"Contract state"}),e.jsxs("div",{className:"rounded-[18px] bg-white/[0.04] px-4 py-4",children:[e.jsx("div",{className:"text-sm text-white/58",children:s.isLocked?"This strategy is currently locked as a contract. The graph, targets, and descriptive plan stay frozen until you explicitly unlock it.":"This strategy is still a draft. Agents and users can keep refining the plan until you lock it."}),s.isLocked?e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2 text-sm text-white/60",children:[e.jsxs("span",{children:["Locked by"," ",(($=s.lockedByUser)==null?void 0:$.displayName)??"Unknown user"]}),s.lockedAt?e.jsxs("span",{children:["· ",new Date(s.lockedAt).toLocaleString()]}):null]}):null,s.isLocked?null:e.jsx("div",{className:"mt-4 grid gap-2",children:O.map(t=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[14px] bg-white/[0.03] px-3 py-2",children:[e.jsx("div",{className:"text-sm text-white/64",children:t.label}),e.jsx(m,{className:t.satisfied?"bg-emerald-500/12 text-emerald-200":"bg-amber-500/12 text-amber-200",children:t.satisfied?"Ready":"Missing"})]},t.id))})]}),!s.isLocked&&!f?e.jsx("div",{className:"rounded-[18px] border border-amber-400/18 bg-amber-500/[0.08] px-4 py-3 text-sm leading-6 text-amber-100/86",children:"Add a target goal or project plus an overview or end state before locking this draft as the execution contract."}):null,s.isLocked?null:e.jsx("div",{className:"mt-4 text-xs leading-5 text-white/46",children:"Drafts may stay incomplete while humans and agents negotiate the plan. Only the lock action requires the contract checks to pass."})]}),e.jsxs(k,{className:"grid gap-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/45",children:"Alignment metrics"}),e.jsxs("div",{className:"rounded-[18px] bg-white/[0.04] px-4 py-4",children:[e.jsx("div",{className:"text-sm text-white/56",children:"Alignment score"}),e.jsxs("div",{className:"mt-2 font-display text-3xl text-[var(--primary)]",children:[s.metrics.alignmentScore,"%"]}),e.jsxs("div",{className:"mt-3 text-xs leading-5 text-white/48",children:[s.metrics.startedNodeCount,"/",s.metrics.totalNodeCount," planned nodes started,"," ",s.metrics.completedNodeCount," completed,"," ",s.metrics.readyNodeCount," ready now."]})]}),P.map(t=>e.jsxs("div",{className:"rounded-[18px] bg-white/[0.04] px-4 py-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-sm text-white/56",children:t.label}),e.jsxs("div",{className:"text-sm font-medium text-white",children:[t.value,"%"]})]}),e.jsx(pe,{value:t.value,className:"mt-3"}),e.jsx("div",{className:"mt-3 text-xs leading-5 text-white/48",children:t.detail})]},t.id))]}),e.jsxs(k,{className:"grid gap-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/45",children:"End targets"}),s.targetGoalIds.map(t=>{const u=I.get(t);return u?e.jsx(B,{to:`/goals/${u.id}`,className:"rounded-[16px] bg-white/[0.04] px-4 py-3 text-sm text-white/78 transition hover:bg-white/[0.08]",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("span",{children:["Goal: ",u.title]}),e.jsx(_,{user:u.user,compact:!0})]})},u.id):null}),s.targetProjectIds.map(t=>{const u=b.get(t);return u?e.jsx(B,{to:`/projects/${u.id}`,className:"rounded-[16px] bg-white/[0.04] px-4 py-3 text-sm text-white/78 transition hover:bg-white/[0.08]",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("span",{children:["Project: ",u.title]}),e.jsx(_,{user:u.user,compact:!0})]})},u.id):null}),s.targetGoalIds.length===0&&s.targetProjectIds.length===0?e.jsx("div",{className:"rounded-[16px] bg-white/[0.04] px-4 py-3 text-sm text-white/52",children:"No end targets linked yet."}):null]}),e.jsxs(k,{className:"grid gap-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/45",children:"Linked entities"}),s.linkedEntities.length===0?e.jsx("div",{className:"rounded-[16px] bg-white/[0.04] px-4 py-3 text-sm text-white/52",children:"No additional linked entities."}):s.linkedEntities.map(t=>{var C,D,E,q,R,U,z;const u=he(t.entityType,t.entityId),S=t.entityType==="goal"?(C=I.get(t.entityId))==null?void 0:C.title:t.entityType==="project"?(D=b.get(t.entityId))==null?void 0:D.title:t.entityType==="task"?(E=y.get(t.entityId))==null?void 0:E.title:`${t.entityType}:${t.entityId}`;return u?e.jsx(B,{to:u,className:"rounded-[16px] bg-white/[0.04] px-4 py-3 text-sm text-white/78 transition hover:bg-white/[0.08]",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:S}),e.jsx(_,{user:t.entityType==="goal"?(q=I.get(t.entityId))==null?void 0:q.user:t.entityType==="project"?(R=b.get(t.entityId))==null?void 0:R.user:t.entityType==="task"?(U=y.get(t.entityId))==null?void 0:U.user:t.entityType==="strategy"?(z=a.snapshot.strategies.find(H=>H.id===t.entityId))==null?void 0:z.user:null,compact:!0})]})},`${t.entityType}:${t.entityId}`):e.jsx("div",{className:"rounded-[16px] bg-white/[0.04] px-4 py-3 text-sm text-white/52",children:S},`${t.entityType}:${t.entityId}`)})]})]})]}),e.jsx(ne,{open:r,pending:n.isPending,editingStrategy:s,goals:a.snapshot.dashboard.goals,projects:a.snapshot.dashboard.projects,tasks:a.snapshot.tasks,habits:a.snapshot.habits,strategies:a.snapshot.strategies,users:a.snapshot.users,defaultUserId:l,initialStepId:j,onOpenChange:t=>{c(t),t||h(void 0)},onSubmit:async t=>{await n.mutateAsync({input:t,currentStrategyId:s.id})}})]}):e.jsx(G,{eyebrow:"Strategy",error:new Error("Strategy not found."),onRetry:()=>o("/strategies")})}export{De as StrategyDetailPage};
|