forge-openclaw-plugin 0.3.0 → 0.3.1

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.
Files changed (119) hide show
  1. package/dist/assets/{activity-page-DPPiiyLO.js → activity-page-DRRbpVK-.js} +1 -1
  2. package/dist/assets/{ai-surface-workspace-B_fV9C4s.js → ai-surface-workspace-DJPt-OaW.js} +1 -1
  3. package/dist/assets/{atlas-panel-BPTJyMcI.js → atlas-panel-G3wGxjYf.js} +1 -1
  4. package/dist/assets/{calendar-page-D4DcRQv7.js → calendar-page-y8G1ige8.js} +1 -1
  5. package/dist/assets/{calendar-rules-Cl_xMrBn.js → calendar-rules-CRhXqGQu.js} +1 -1
  6. package/dist/assets/{calendar-week-toolbar-BARSOEO9.js → calendar-week-toolbar-CWSK5hJl.js} +1 -1
  7. package/dist/assets/{companion-sync-lab-page-COFYDI3w.js → companion-sync-lab-page-kEgOF3c6.js} +1 -1
  8. package/dist/assets/daily-metrics-dashboard-BJjUIZVA.js +1 -0
  9. package/dist/assets/{entity-note-count-link-BX93WYgh.js → entity-note-count-link-ef3ZOpKM.js} +1 -1
  10. package/dist/assets/{entity-notes-surface-CBlKc-x-.js → entity-notes-surface-CaCjjUaq.js} +1 -1
  11. package/dist/assets/{execution-board-Dh41UeKR.js → execution-board-RRWm2srb.js} +1 -1
  12. package/dist/assets/{faceted-token-search-BgxYH_gW.js → faceted-token-search-CZmtyJTT.js} +1 -1
  13. package/dist/assets/{flagship-signal-deck-bolzzK8q.js → flagship-signal-deck-DxRfmfpN.js} +1 -1
  14. package/dist/assets/{floating-action-menu-C5H-Wr2B.js → floating-action-menu-cKjNsPYD.js} +1 -1
  15. package/dist/assets/{goal-detail-page-CQeFnGDJ.js → goal-detail-page-BgQlK7yT.js} +1 -1
  16. package/dist/assets/{goals-page-BTg9crEK.js → goals-page-Cz2i3pVy.js} +1 -1
  17. package/dist/assets/{habits-page-C4vqk346.js → habits-page-BmEmWCGv.js} +1 -1
  18. package/dist/assets/index-Bcem7l5u.css +1 -0
  19. package/dist/assets/{index-By3tQxiE.js → index-QJkjKYzZ.js} +2 -2
  20. package/dist/assets/{insight-flow-dialog-JPYCsTKI.js → insight-flow-dialog-CdYMHwMP.js} +1 -1
  21. package/dist/assets/{insights-page-CFhVMlVL.js → insights-page-DHG-o9P_.js} +1 -1
  22. package/dist/assets/{kanban-page-DC3IDsnh.js → kanban-page-C6S_fJRc.js} +1 -1
  23. package/dist/assets/{knowledge-graph-page-DucyRYTZ.js → knowledge-graph-page-juA9QCy0.js} +1 -1
  24. package/dist/assets/{life-force-page-UrXfxaSO.js → life-force-page-ChTIA4mV.js} +1 -1
  25. package/dist/assets/{life-force-workspace-BhPNH7ad.js → life-force-workspace-sszLD-Yn.js} +1 -1
  26. package/dist/assets/{metric-tile-DtRPjN4V.js → metric-tile-B-tDTcBt.js} +1 -1
  27. package/dist/assets/{movement-page-DCIdTQEN.js → movement-page-Dx3T3HrG.js} +1 -1
  28. package/dist/assets/{note-markdown-CepDxj3v.js → note-markdown-CCyyE85h.js} +1 -1
  29. package/dist/assets/{note-tags-input-BXYaDkOr.js → note-tags-input-BS14YXHn.js} +1 -1
  30. package/dist/assets/{notes-page-Bl1LlCLo.js → notes-page-D3yGl8TN.js} +1 -1
  31. package/dist/assets/{open-in-graph-button-C263zl5l.js → open-in-graph-button-CMjJZX7G.js} +1 -1
  32. package/dist/assets/{orbit-map-Cb_AJyIj.js → orbit-map-v2Pv9RU_.js} +1 -1
  33. package/dist/assets/{overview-page-C2yLity7.js → overview-page-DSOpBpHf.js} +1 -1
  34. package/dist/assets/{page-hero-5RTqAI88.js → page-hero-CONuJu5J.js} +1 -1
  35. package/dist/assets/{pill-cluster-CBrrtZBm.js → pill-cluster-W2fY48OM.js} +1 -1
  36. package/dist/assets/{preference-entity-handoff-button-BQzg2J4k.js → preference-entity-handoff-button-CKDxCnbl.js} +1 -1
  37. package/dist/assets/{preferences-page-DekYF-Yz.js → preferences-page-Br3zrLlH.js} +1 -1
  38. package/dist/assets/{project-collections-BVXB8PPF.js → project-collections-NBwk6yV-.js} +1 -1
  39. package/dist/assets/{project-detail-page-CQlrLEn9.js → project-detail-page-BIU9_TRN.js} +1 -1
  40. package/dist/assets/{project-management-hierarchy-page--mzM_zRE.js → project-management-hierarchy-page-C2H620xD.js} +1 -1
  41. package/dist/assets/{project-management-section-nav-DQl0qRWy.js → project-management-section-nav-DRPVS1Eh.js} +1 -1
  42. package/dist/assets/{projects-page-Dr_0NdVP.js → projects-page-w7a_L2-z.js} +1 -1
  43. package/dist/assets/{psyche-behaviors-page-DOUaCWON.js → psyche-behaviors-page-Dt4CMC-q.js} +1 -1
  44. package/dist/assets/{psyche-flashcards-page-BA84fO_X.js → psyche-flashcards-page-rXz06dqO.js} +1 -1
  45. package/dist/assets/{psyche-goal-map-page-DpXAg1Vf.js → psyche-goal-map-page-BCcD6Jkl.js} +1 -1
  46. package/dist/assets/{psyche-graph-BxcbAbXt.js → psyche-graph-CXlAj4ED.js} +1 -1
  47. package/dist/assets/psyche-metrics-page-B1otiir6.js +1 -0
  48. package/dist/assets/{psyche-mode-guide-page-CBlIS5N_.js → psyche-mode-guide-page-C6AdVIAv.js} +1 -1
  49. package/dist/assets/{psyche-modes-page-DE6KDK_1.js → psyche-modes-page-DoUqz2mR.js} +1 -1
  50. package/dist/assets/psyche-page-BJNLQn8W.js +1 -0
  51. package/dist/assets/{psyche-patterns-page-DbCNRuww.js → psyche-patterns-page-CzpMSAPu.js} +1 -1
  52. package/dist/assets/{psyche-questionnaire-builder-page-DnraDj1H.js → psyche-questionnaire-builder-page-DjzatGVZ.js} +1 -1
  53. package/dist/assets/{psyche-questionnaire-detail-page-DQ6zNQkk.js → psyche-questionnaire-detail-page-B0Qfowfg.js} +1 -1
  54. package/dist/assets/{psyche-questionnaire-run-detail-page-BGrOIX0B.js → psyche-questionnaire-run-detail-page-B2dNj4jJ.js} +1 -1
  55. package/dist/assets/{psyche-questionnaire-run-page-Bg3BhBHb.js → psyche-questionnaire-run-page-DyD9Ui-g.js} +1 -1
  56. package/dist/assets/{psyche-questionnaires-page-BEreTNjG.js → psyche-questionnaires-page-BxfKcoi3.js} +1 -1
  57. package/dist/assets/{psyche-report-detail-page-Br9KlJBG.js → psyche-report-detail-page-Ci14mNUK.js} +1 -1
  58. package/dist/assets/{psyche-reports-page-Bk6QpAEF.js → psyche-reports-page-ALhNueiV.js} +1 -1
  59. package/dist/assets/{psyche-schemas-beliefs-page-Db8d2ga7.js → psyche-schemas-beliefs-page-C0P2Vw6-.js} +1 -1
  60. package/dist/assets/{psyche-screen-time-page-NazHUAkT.js → psyche-screen-time-page-BYnaT3cb.js} +1 -1
  61. package/dist/assets/{psyche-self-observation-page-H6FToucM.js → psyche-self-observation-page-eM9vpwIB.js} +1 -1
  62. package/dist/assets/{psyche-values-page-DqM382-6.js → psyche-values-page-BqrGIDok.js} +1 -1
  63. package/dist/assets/{report-chain-fields-nW4zndrM.js → report-chain-fields-CbkT7WOO.js} +1 -1
  64. package/dist/assets/{rewards-page-C-tZVnIK.js → rewards-page-DpAJ8IxE.js} +1 -1
  65. package/dist/assets/{scheduling-rules-editor-DGF-044c.js → scheduling-rules-editor-BUGnZJ0g.js} +1 -1
  66. package/dist/assets/{schema-badge-57AJ3FY-.js → schema-badge-CLAA4p-b.js} +1 -1
  67. package/dist/assets/{select-menu-mfaklv7r.js → select-menu-Cqs5t3ng.js} +1 -1
  68. package/dist/assets/{settings-agents-page-CPJeeYg0.js → settings-agents-page-pmkVrOO8.js} +1 -1
  69. package/dist/assets/{settings-bin-page-D3eX5aNf.js → settings-bin-page-BwtLrweW.js} +1 -1
  70. package/dist/assets/{settings-calendar-page-Bgx8NIsP.js → settings-calendar-page-BBjAMOCf.js} +1 -1
  71. package/dist/assets/{settings-data-page-BuMSUjpp.js → settings-data-page-Bqy5SukM.js} +1 -1
  72. package/dist/assets/{settings-logs-page-CHb2GNUM.js → settings-logs-page-8khtrf4T.js} +1 -1
  73. package/dist/assets/{settings-mobile-page-ClUvXhJg.js → settings-mobile-page-BcyRjEU_.js} +1 -1
  74. package/dist/assets/{settings-models-page-njK6D7zc.js → settings-models-page-DlSnO9WX.js} +1 -1
  75. package/dist/assets/{settings-page-Dm--cx6B.js → settings-page-CyBQ2qcB.js} +1 -1
  76. package/dist/assets/{settings-rewards-page-3aShLM3A.js → settings-rewards-page-BBX2WtVM.js} +1 -1
  77. package/dist/assets/{settings-section-nav-BWox23Qv.js → settings-section-nav-Co0AaDG-.js} +1 -1
  78. package/dist/assets/{settings-users-page-D-hEPpgQ.js → settings-users-page-JSnfFFPu.js} +1 -1
  79. package/dist/assets/{settings-wiki-page-CC-rOtDm.js → settings-wiki-page--nT23Fdy.js} +1 -1
  80. package/dist/assets/{sleep-page-Cm_Ei2w1.js → sleep-page-CGMi3MtV.js} +1 -1
  81. package/dist/assets/{sports-page-CqSI-j-H.js → sports-page-Kv5bBoLr.js} +1 -1
  82. package/dist/assets/{strategies-page-BuJ4zLLv.js → strategies-page-Br7RdUJO.js} +1 -1
  83. package/dist/assets/{strategy-detail-page-CLmy0jbW.js → strategy-detail-page-CBWXjUhC.js} +1 -1
  84. package/dist/assets/{strategy-dialog-DnJix1ys.js → strategy-dialog-BTwkaSxI.js} +1 -1
  85. package/dist/assets/{surface-DRNu5Fpz.js → surface-CyWI7e1R.js} +1 -1
  86. package/dist/assets/{task-detail-page-DTnNjW33.js → task-detail-page-Qis9354n.js} +1 -1
  87. package/dist/assets/{timebox-planning-dialog-DckIr1K4.js → timebox-planning-dialog-DB8snOBD.js} +1 -1
  88. package/dist/assets/{today-page-Cgk4HBPK.js → today-page-D9A5PU0S.js} +1 -1
  89. package/dist/assets/{training-load-page-C-7iINaB.js → training-load-page-Bpd4DQAh.js} +1 -1
  90. package/dist/assets/vitals-page-CVYC-4RG.js +1 -0
  91. package/dist/assets/{weekly-review-page-DFmuzzig.js → weekly-review-page-BP7N3fNB.js} +1 -1
  92. package/dist/assets/{weight-loss-page-CWtgeuti.js → weight-loss-page-_fX3N1UK.js} +1 -1
  93. package/dist/assets/{wiki-article-markdown-BkQg8Hne.js → wiki-article-markdown-Bi02AsVt.js} +1 -1
  94. package/dist/assets/{wiki-editor-page-BYKcdX5I.js → wiki-editor-page-OZf9l4Tg.js} +1 -1
  95. package/dist/assets/{wiki-ingest-history-page-D_p4myw1.js → wiki-ingest-history-page-CzeNSL7N.js} +1 -1
  96. package/dist/assets/{wiki-ingest-modal-C-CidueO.js → wiki-ingest-modal-Ig_xnyc6.js} +1 -1
  97. package/dist/assets/wiki-page-B4xuNgY4.js +1 -0
  98. package/dist/assets/{workbench-flow-page-Q3r2IJty.js → workbench-flow-page-BhRJCALC.js} +1 -1
  99. package/dist/assets/{workbench-page-BFfWMGm6.js → workbench-page-DxVs2AOY.js} +1 -1
  100. package/dist/assets/{workout-detail-page-DeDyz1Kk.js → workout-detail-page-D4wfkE98.js} +1 -1
  101. package/dist/index.html +2 -2
  102. package/dist/server/server/migrations/069_psyche_devrage_cumulative_rage.sql +5 -0
  103. package/dist/server/server/src/app.js +3 -2
  104. package/dist/server/server/src/openapi.js +48 -8
  105. package/dist/server/server/src/psyche-types.js +18 -4
  106. package/dist/server/server/src/services/devrage-scanner.js +115 -10
  107. package/dist/server/server/src/services/devrage.js +61 -11
  108. package/openclaw.plugin.json +1 -1
  109. package/package.json +1 -1
  110. package/server/migrations/069_psyche_devrage_cumulative_rage.sql +5 -0
  111. package/skills/forge-openclaw/SKILL.md +7 -0
  112. package/skills/forge-openclaw/entity_conversation_playbooks.md +23 -0
  113. package/skills/forge-openclaw/psyche_entity_playbooks.md +32 -0
  114. package/dist/assets/daily-metrics-dashboard-BNGQlJkQ.js +0 -1
  115. package/dist/assets/index-BAXYM89v.css +0 -1
  116. package/dist/assets/psyche-metrics-page-D8JQEoOl.js +0 -1
  117. package/dist/assets/psyche-page-Dkh7R2Dc.js +0 -1
  118. package/dist/assets/vitals-page-CqE4bYMf.js +0 -1
  119. package/dist/assets/wiki-page-DYpg9ZEO.js +0 -1
@@ -1 +1 @@
1
- import{cc as F,b5 as q,r as o,j as e,aC as p}from"./vendor-Dnkkx2co.js";import{j as A,k as H}from"./state-vCcAT5Hq.js";import{P as L,u as z,s as K,i as Q,R as $,a as X,V as T,U as C,B as x,C as j,b as k,c as u,W as _,X as V,Y as W}from"./index-By3tQxiE.js";import{O as Y}from"./open-in-graph-button-C263zl5l.js";import{N as J}from"./note-markdown-CepDxj3v.js";import{E as Z}from"./entity-notes-surface-CBlKc-x-.js";import{P as ee}from"./preference-entity-handoff-button-BQzg2J4k.js";import{b as te,f as ae,P as se}from"./project-collections-BVXB8PPF.js";import{P as ie}from"./page-hero-5RTqAI88.js";import{g as ne,a as le}from"./activity-copy-Bj4h9OcF.js";import{g as oe}from"./entity-links-DwpxhW2H.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";import"./note-tags-input-BXYaDkOr.js";function we(){const{t:a}=L(),i=z(),d=F(),G=q(),v=A(),[O,N]=o.useState(!1),[S,y]=o.useState(!1),[m,B]=o.useState("active"),f=K(i.selectedUserIds),[E,b]=o.useState(null),D=H({mutationFn:()=>$(d.goalId),onSuccess:async()=>{await Promise.all([Q(v),v.invalidateQueries({queryKey:["project-board"]}),v.invalidateQueries({queryKey:["task-context"]})]),G("/goals")}}),s=i.snapshot.dashboard.goals.find(t=>t.id===d.goalId)??null,g=o.useMemo(()=>i.snapshot.dashboard.projects.filter(t=>t.goalId===d.goalId),[d.goalId,i.snapshot.dashboard.projects]),R=o.useMemo(()=>te(g),[g]),l=o.useMemo(()=>ae(g,m),[g,m]),w=new Set(g.map(t=>t.id)),I=new Set(i.snapshot.tasks.filter(t=>w.has(t.projectId??"")).map(t=>t.id)),h=i.snapshot.activity.filter(t=>t.entityId===d.goalId||w.has(t.entityId)||I.has(t.entityId)||t.entityType==="task_run"&&typeof t.metadata.taskId=="string"&&I.has(t.metadata.taskId));if(!s)return e.jsx(X,{eyebrow:a("common.goalDetail.eyebrow"),title:a("common.goalDetail.missingTitle"),description:a("common.goalDetail.missingDescription"),action:e.jsx(p,{to:"/goals",className:"inline-flex min-h-10 min-w-0 max-w-full items-center justify-center whitespace-nowrap rounded-full bg-[var(--primary)] px-4 py-2 text-sm font-medium text-[var(--ui-ink-on-accent)] transition hover:opacity-90",children:a("common.goalDetail.backToGoals")})});const n=l.find(t=>t.nextTaskTitle)??l[0]??null,r=i.snapshot.overview.neglectedGoals.find(t=>t.goalId===s.id)??null,c=h[0]??null,M=async t=>{b(t);try{await i.patchProject(t,{status:"active"})}finally{b(null)}},U=async()=>{window.confirm(a("common.goalDetail.deleteGoalConfirm",{title:s.title}))&&await D.mutateAsync()};return e.jsxs("div",{className:"grid min-w-0 gap-5",children:[e.jsx(ie,{entityKind:"goal",title:e.jsx(T,{kind:"goal",label:s.title,variant:"heading",size:"lg"}),titleText:s.title,description:s.description?e.jsx(J,{markdown:s.description,className:"[&>p]:text-[13px] [&>p]:leading-6 [&>blockquote]:text-[13px] [&>ul]:text-[13px] [&>ol]:text-[13px]"}):"No strategic description yet.",badge:a(l.length===1?"common.goalDetail.heroBadgeOne":"common.goalDetail.heroBadgeOther",{count:l.length}),actions:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(ee,{userId:f,domain:"projects",entityType:"goal",entityId:s.id,label:s.title,description:s.description}),e.jsx(Y,{entityType:"goal",entityId:s.id})]})}),s.user?e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm text-[var(--ui-ink-soft)]",children:[e.jsx("span",{className:"text-[var(--ui-ink-faint)]",children:"Owned by"}),e.jsx(C,{user:s.user})]}):null,e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsx(x,{onClick:()=>N(!0),children:a("common.goalDetail.edit")}),e.jsx(x,{variant:"secondary",onClick:()=>y(!0),children:a("common.goalDetail.addProject")}),e.jsx(x,{variant:"ghost",className:"text-[var(--danger)] hover:bg-[var(--ui-danger-soft)]",pending:D.isPending,pendingLabel:a("common.goalDetail.deleting"),onClick:()=>void U(),children:a("common.goalDetail.deleteGoal")})]}),e.jsxs("section",{className:"grid min-w-0 gap-5 xl:grid-cols-[minmax(0,1.15fr)_minmax(0,0.85fr)]",children:[e.jsxs(j,{children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:a("common.goalDetail.sectionProjects")}),e.jsx(se,{value:m,counts:R,onChange:B,className:"justify-end"})]}),l.length===0?e.jsx("div",{className:"mt-4 rounded-[20px] bg-[var(--ui-surface-2)] p-4 text-sm text-[var(--ui-ink-soft)]",children:m==="active"?a("common.goalDetail.noProjects"):"No projects match this lifecycle filter yet. Switch filters or restart one to make it active again."}):e.jsx("div",{className:"mt-4 grid gap-4 lg:grid-cols-2",children:l.map(t=>e.jsxs("div",{className:"rounded-[22px] bg-[var(--ui-surface-2)] p-5 transition hover:bg-[var(--ui-surface-2)]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(k,{kind:"project",compact:!0,gradient:!1}),t.user?e.jsx(C,{user:t.user,compact:!0}):null]}),e.jsx(u,{children:t.status})]}),e.jsx("div",{className:"mt-4",children:e.jsx(p,{to:`/projects/${t.id}`,className:"transition hover:opacity-90",children:e.jsx(T,{kind:"project",label:t.title,variant:"heading",size:"lg"})})}),e.jsx("p",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-soft)]",children:t.description}),e.jsx("div",{className:"mt-4",children:e.jsx(_,{value:t.progress})}),e.jsx("div",{className:"mt-4 text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:t.nextTaskTitle?a("common.goalDetail.nextMove",{value:t.nextTaskTitle}):a("common.goalDetail.addNextTask")}),e.jsxs("div",{className:"mt-4 flex flex-wrap justify-between gap-3",children:[e.jsx(p,{to:`/projects/${t.id}`,children:e.jsx(x,{variant:"ghost",children:"Open project"})}),m!=="active"&&t.status!=="active"?e.jsx(x,{variant:"secondary",size:"sm",pending:E===t.id,pendingLabel:"Restarting…",onClick:()=>void M(t.id),children:"Restart"}):null]})]},t.id))})]}),e.jsx("div",{className:"grid min-w-0 gap-5",children:e.jsxs(j,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:a("common.goalDetail.sectionHealth")}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-2",children:[e.jsx(k,{kind:"goal",compact:!0,gradient:!1}),e.jsx(u,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",children:a("common.goalDetail.progressTitle",{progress:s.progress,count:s.completedTasks})}),e.jsx(u,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",children:a("common.goalDetail.progressDetail",{xp:s.earnedPoints})}),e.jsx(u,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",children:a(l.length===1?"common.goalDetail.heroBadgeOne":"common.goalDetail.heroBadgeOther",{count:l.length})})]}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:a("common.goalDetail.fieldProgress")}),e.jsxs("div",{className:"mt-2 font-display text-xl text-[var(--ui-ink-strong)]",children:[s.progress,"%"]})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:a("common.goalDetail.fieldCompletedTasks")}),e.jsx("div",{className:"mt-2 font-display text-xl text-[var(--ui-ink-strong)]",children:s.completedTasks})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:a("common.goalDetail.fieldXpBanked")}),e.jsx("div",{className:"mt-2 font-display text-xl text-[var(--ui-ink-strong)]",children:s.earnedPoints})]})]}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:a("common.goalDetail.signalNext")}),n?e.jsx(k,{kind:"project",compact:!0,gradient:!1}):null]}),e.jsx("div",{className:"mt-2 font-medium text-[var(--ui-ink-strong)]",children:(n==null?void 0:n.title)??a("common.goalDetail.noProject")}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:n!=null&&n.nextTaskTitle?a("common.goalDetail.nextMove",{value:n.nextTaskTitle}):(n==null?void 0:n.description)||a("common.goalDetail.noProjectDetail")})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:a("common.goalDetail.signalRisk")}),e.jsx("div",{className:"mt-2 font-medium text-[var(--ui-ink-strong)]",children:(r==null?void 0:r.title)??a("common.goalDetail.noRisk")}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:(r==null?void 0:r.summary)||a("common.goalDetail.noRiskDetail")})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:a("common.goalDetail.signalEvidence")}),e.jsx("div",{className:"mt-2 font-medium text-[var(--ui-ink-strong)]",children:(c==null?void 0:c.title)??a("common.goalDetail.noEvidence")}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:(c==null?void 0:c.description)||a("common.goalDetail.noEvidenceDetail")})]})]})]})]})})]}),e.jsx(Z,{entityType:"goal",entityId:s.id,title:"Goal notes",description:"Use notes to capture strategy changes, meaning shifts, and progress context that belongs at the goal level."}),e.jsxs(j,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:a("common.goalDetail.sectionEvidence")}),h.length===0?e.jsx("div",{className:"mt-4 rounded-[20px] bg-[var(--ui-surface-2)] p-4 text-sm text-[var(--ui-ink-soft)]",children:a("common.goalDetail.noEvidenceLogged")}):e.jsx("div",{className:"mt-4 grid gap-3 lg:grid-cols-2",children:h.slice(0,6).map(t=>e.jsxs(p,{to:oe(t)??`/activity?eventId=${t.id}`,className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4 transition hover:bg-[var(--ui-surface-2)]",children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:ne(t)}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:le(t)})]},t.id))})]}),e.jsx(V,{open:O,editingGoal:s,tags:i.snapshot.tags,users:i.snapshot.users,defaultUserId:s.userId??f,onOpenChange:N,onSubmit:async(t,P)=>{P&&await i.patchGoal(P,t)}}),e.jsx(W,{open:S,goals:i.snapshot.goals,users:i.snapshot.users,editingProject:null,initialGoalId:s.id,defaultUserId:s.userId??f,onOpenChange:y,onSubmit:async t=>{await i.createProject(t)}})]})}export{we as GoalDetailPage};
1
+ import{cc as F,b5 as q,r as o,j as e,aC as p}from"./vendor-Dnkkx2co.js";import{j as A,k as H}from"./state-vCcAT5Hq.js";import{P as L,u as z,s as K,i as Q,R as $,a as X,V as T,U as C,B as x,C as j,b as k,c as u,W as _,X as V,Y as W}from"./index-QJkjKYzZ.js";import{O as Y}from"./open-in-graph-button-CMjJZX7G.js";import{N as J}from"./note-markdown-CCyyE85h.js";import{E as Z}from"./entity-notes-surface-CaCjjUaq.js";import{P as ee}from"./preference-entity-handoff-button-CKDxCnbl.js";import{b as te,f as ae,P as se}from"./project-collections-NBwk6yV-.js";import{P as ie}from"./page-hero-CONuJu5J.js";import{g as ne,a as le}from"./activity-copy-Bj4h9OcF.js";import{g as oe}from"./entity-links-DwpxhW2H.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";import"./note-tags-input-BS14YXHn.js";function we(){const{t:a}=L(),i=z(),d=F(),G=q(),v=A(),[O,N]=o.useState(!1),[S,y]=o.useState(!1),[m,B]=o.useState("active"),f=K(i.selectedUserIds),[E,b]=o.useState(null),D=H({mutationFn:()=>$(d.goalId),onSuccess:async()=>{await Promise.all([Q(v),v.invalidateQueries({queryKey:["project-board"]}),v.invalidateQueries({queryKey:["task-context"]})]),G("/goals")}}),s=i.snapshot.dashboard.goals.find(t=>t.id===d.goalId)??null,g=o.useMemo(()=>i.snapshot.dashboard.projects.filter(t=>t.goalId===d.goalId),[d.goalId,i.snapshot.dashboard.projects]),R=o.useMemo(()=>te(g),[g]),l=o.useMemo(()=>ae(g,m),[g,m]),w=new Set(g.map(t=>t.id)),I=new Set(i.snapshot.tasks.filter(t=>w.has(t.projectId??"")).map(t=>t.id)),h=i.snapshot.activity.filter(t=>t.entityId===d.goalId||w.has(t.entityId)||I.has(t.entityId)||t.entityType==="task_run"&&typeof t.metadata.taskId=="string"&&I.has(t.metadata.taskId));if(!s)return e.jsx(X,{eyebrow:a("common.goalDetail.eyebrow"),title:a("common.goalDetail.missingTitle"),description:a("common.goalDetail.missingDescription"),action:e.jsx(p,{to:"/goals",className:"inline-flex min-h-10 min-w-0 max-w-full items-center justify-center whitespace-nowrap rounded-full bg-[var(--primary)] px-4 py-2 text-sm font-medium text-[var(--ui-ink-on-accent)] transition hover:opacity-90",children:a("common.goalDetail.backToGoals")})});const n=l.find(t=>t.nextTaskTitle)??l[0]??null,r=i.snapshot.overview.neglectedGoals.find(t=>t.goalId===s.id)??null,c=h[0]??null,M=async t=>{b(t);try{await i.patchProject(t,{status:"active"})}finally{b(null)}},U=async()=>{window.confirm(a("common.goalDetail.deleteGoalConfirm",{title:s.title}))&&await D.mutateAsync()};return e.jsxs("div",{className:"grid min-w-0 gap-5",children:[e.jsx(ie,{entityKind:"goal",title:e.jsx(T,{kind:"goal",label:s.title,variant:"heading",size:"lg"}),titleText:s.title,description:s.description?e.jsx(J,{markdown:s.description,className:"[&>p]:text-[13px] [&>p]:leading-6 [&>blockquote]:text-[13px] [&>ul]:text-[13px] [&>ol]:text-[13px]"}):"No strategic description yet.",badge:a(l.length===1?"common.goalDetail.heroBadgeOne":"common.goalDetail.heroBadgeOther",{count:l.length}),actions:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(ee,{userId:f,domain:"projects",entityType:"goal",entityId:s.id,label:s.title,description:s.description}),e.jsx(Y,{entityType:"goal",entityId:s.id})]})}),s.user?e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm text-[var(--ui-ink-soft)]",children:[e.jsx("span",{className:"text-[var(--ui-ink-faint)]",children:"Owned by"}),e.jsx(C,{user:s.user})]}):null,e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsx(x,{onClick:()=>N(!0),children:a("common.goalDetail.edit")}),e.jsx(x,{variant:"secondary",onClick:()=>y(!0),children:a("common.goalDetail.addProject")}),e.jsx(x,{variant:"ghost",className:"text-[var(--danger)] hover:bg-[var(--ui-danger-soft)]",pending:D.isPending,pendingLabel:a("common.goalDetail.deleting"),onClick:()=>void U(),children:a("common.goalDetail.deleteGoal")})]}),e.jsxs("section",{className:"grid min-w-0 gap-5 xl:grid-cols-[minmax(0,1.15fr)_minmax(0,0.85fr)]",children:[e.jsxs(j,{children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:a("common.goalDetail.sectionProjects")}),e.jsx(se,{value:m,counts:R,onChange:B,className:"justify-end"})]}),l.length===0?e.jsx("div",{className:"mt-4 rounded-[20px] bg-[var(--ui-surface-2)] p-4 text-sm text-[var(--ui-ink-soft)]",children:m==="active"?a("common.goalDetail.noProjects"):"No projects match this lifecycle filter yet. Switch filters or restart one to make it active again."}):e.jsx("div",{className:"mt-4 grid gap-4 lg:grid-cols-2",children:l.map(t=>e.jsxs("div",{className:"rounded-[22px] bg-[var(--ui-surface-2)] p-5 transition hover:bg-[var(--ui-surface-2)]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(k,{kind:"project",compact:!0,gradient:!1}),t.user?e.jsx(C,{user:t.user,compact:!0}):null]}),e.jsx(u,{children:t.status})]}),e.jsx("div",{className:"mt-4",children:e.jsx(p,{to:`/projects/${t.id}`,className:"transition hover:opacity-90",children:e.jsx(T,{kind:"project",label:t.title,variant:"heading",size:"lg"})})}),e.jsx("p",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-soft)]",children:t.description}),e.jsx("div",{className:"mt-4",children:e.jsx(_,{value:t.progress})}),e.jsx("div",{className:"mt-4 text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:t.nextTaskTitle?a("common.goalDetail.nextMove",{value:t.nextTaskTitle}):a("common.goalDetail.addNextTask")}),e.jsxs("div",{className:"mt-4 flex flex-wrap justify-between gap-3",children:[e.jsx(p,{to:`/projects/${t.id}`,children:e.jsx(x,{variant:"ghost",children:"Open project"})}),m!=="active"&&t.status!=="active"?e.jsx(x,{variant:"secondary",size:"sm",pending:E===t.id,pendingLabel:"Restarting…",onClick:()=>void M(t.id),children:"Restart"}):null]})]},t.id))})]}),e.jsx("div",{className:"grid min-w-0 gap-5",children:e.jsxs(j,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:a("common.goalDetail.sectionHealth")}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-2",children:[e.jsx(k,{kind:"goal",compact:!0,gradient:!1}),e.jsx(u,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",children:a("common.goalDetail.progressTitle",{progress:s.progress,count:s.completedTasks})}),e.jsx(u,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",children:a("common.goalDetail.progressDetail",{xp:s.earnedPoints})}),e.jsx(u,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",children:a(l.length===1?"common.goalDetail.heroBadgeOne":"common.goalDetail.heroBadgeOther",{count:l.length})})]}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:a("common.goalDetail.fieldProgress")}),e.jsxs("div",{className:"mt-2 font-display text-xl text-[var(--ui-ink-strong)]",children:[s.progress,"%"]})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:a("common.goalDetail.fieldCompletedTasks")}),e.jsx("div",{className:"mt-2 font-display text-xl text-[var(--ui-ink-strong)]",children:s.completedTasks})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:a("common.goalDetail.fieldXpBanked")}),e.jsx("div",{className:"mt-2 font-display text-xl text-[var(--ui-ink-strong)]",children:s.earnedPoints})]})]}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:a("common.goalDetail.signalNext")}),n?e.jsx(k,{kind:"project",compact:!0,gradient:!1}):null]}),e.jsx("div",{className:"mt-2 font-medium text-[var(--ui-ink-strong)]",children:(n==null?void 0:n.title)??a("common.goalDetail.noProject")}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:n!=null&&n.nextTaskTitle?a("common.goalDetail.nextMove",{value:n.nextTaskTitle}):(n==null?void 0:n.description)||a("common.goalDetail.noProjectDetail")})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:a("common.goalDetail.signalRisk")}),e.jsx("div",{className:"mt-2 font-medium text-[var(--ui-ink-strong)]",children:(r==null?void 0:r.title)??a("common.goalDetail.noRisk")}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:(r==null?void 0:r.summary)||a("common.goalDetail.noRiskDetail")})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:a("common.goalDetail.signalEvidence")}),e.jsx("div",{className:"mt-2 font-medium text-[var(--ui-ink-strong)]",children:(c==null?void 0:c.title)??a("common.goalDetail.noEvidence")}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:(c==null?void 0:c.description)||a("common.goalDetail.noEvidenceDetail")})]})]})]})]})})]}),e.jsx(Z,{entityType:"goal",entityId:s.id,title:"Goal notes",description:"Use notes to capture strategy changes, meaning shifts, and progress context that belongs at the goal level."}),e.jsxs(j,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:a("common.goalDetail.sectionEvidence")}),h.length===0?e.jsx("div",{className:"mt-4 rounded-[20px] bg-[var(--ui-surface-2)] p-4 text-sm text-[var(--ui-ink-soft)]",children:a("common.goalDetail.noEvidenceLogged")}):e.jsx("div",{className:"mt-4 grid gap-3 lg:grid-cols-2",children:h.slice(0,6).map(t=>e.jsxs(p,{to:oe(t)??`/activity?eventId=${t.id}`,className:"rounded-[18px] bg-[var(--ui-surface-2)] p-4 transition hover:bg-[var(--ui-surface-2)]",children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:ne(t)}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:le(t)})]},t.id))})]}),e.jsx(V,{open:O,editingGoal:s,tags:i.snapshot.tags,users:i.snapshot.users,defaultUserId:s.userId??f,onOpenChange:N,onSubmit:async(t,P)=>{P&&await i.patchGoal(P,t)}}),e.jsx(W,{open:S,goals:i.snapshot.goals,users:i.snapshot.users,editingProject:null,initialGoalId:s.id,defaultUserId:s.userId??f,onOpenChange:y,onSubmit:async t=>{await i.createProject(t)}})]})}export{we as GoalDetailPage};
@@ -1 +1 @@
1
- import{r as p,j as e,aC as b,c4 as P,b8 as C}from"./vendor-Dnkkx2co.js";import{P as S}from"./page-hero-5RTqAI88.js";import{E as G}from"./entity-note-count-link-BX93WYgh.js";import{C as k,B as y,b as w,V as h,c as l,X as E,Z as N,u as z,s as L,a as T,_ as B,U as I,W as R}from"./index-By3tQxiE.js";import{P as D}from"./pill-cluster-CBrrtZBm.js";import{b as F,f as U,P as M}from"./project-collections-BVXB8PPF.js";import"./state-vCcAT5Hq.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";function O({goals:t,tags:r,users:d,defaultUserId:o=null,pending:c=!1,onCreate:n,onUpdate:v}){const[f,m]=p.useState(!1),[g,u]=p.useState(null),a=t.find(s=>s.id===g)??null;return e.jsxs(e.Fragment,{children:[e.jsxs(k,{children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Goal arcs"}),e.jsx("h3",{className:"mt-2 font-display text-3xl text-[var(--ui-ink-strong)]",children:"Strategic arcs before tickets"}),e.jsx("p",{className:"mt-3 max-w-3xl text-sm leading-7 text-[var(--ui-ink-soft)]",children:"This is the long-horizon map. Each arc shows why it matters, how much ground has been covered, and which project should move next."})]}),e.jsx(y,{onClick:()=>{u(null),m(!0)},children:"Create goal"})]}),e.jsxs("div",{className:"mt-5 grid gap-3 xl:grid-cols-2",children:[t.length===0?e.jsx("div",{className:"rounded-[24px] bg-[var(--ui-surface-2)] p-5 text-sm leading-7 text-[var(--ui-ink-soft)] xl:col-span-2",children:"Start with a life goal. Once the destination is clear, you can attach projects and then fill those projects with tasks."}):null,t.map(s=>{const x=`${Math.max(6,Math.min(100,s.progress))}%`;return e.jsxs(b,{to:`/goals/${s.id}`,className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4 transition hover:bg-[var(--ui-surface-hover)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx(w,{kind:"goal",compact:!0,gradient:!1}),e.jsx("div",{className:"mt-2",children:e.jsx(h,{kind:"goal",label:s.title,variant:"heading",size:"lg",showKind:!1,lines:2})}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:s.description||"No strategic note attached yet."})]}),e.jsx("button",{className:"rounded-full bg-[var(--ui-surface-2)] p-2 text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",type:"button",onClick:i=>{i.preventDefault(),i.stopPropagation(),u(s.id),m(!0)},children:e.jsx(P,{className:"size-4"})})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsx(l,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",children:s.horizon}),e.jsx(l,{className:s.status==="active"?"text-[var(--success)]":s.status==="paused"?"text-[var(--warning)]":"text-[var(--tertiary)]",children:s.status}),e.jsxs(l,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",children:[s.earnedPoints," / ",s.targetPoints," xp"]}),e.jsxs(l,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",children:[s.totalTasks," tasks"]})]}),e.jsx("div",{className:"mt-4 h-1.5 rounded-full bg-[var(--ui-surface-2)]",children:e.jsx("div",{className:"h-full rounded-full bg-[var(--primary)]",style:{width:x}})}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:s.tags.map(i=>e.jsx(l,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",children:i.name},i.id))}),e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate",children:s.momentumLabel}),e.jsxs("span",{className:"inline-flex shrink-0 items-center gap-2",style:{color:s.themeColor},children:["Open arc",e.jsx(C,{className:"size-3.5"})]})]})]},s.id)})]})]}),e.jsx(E,{open:f,pending:c,editingGoal:a,tags:r,users:d,defaultUserId:o,onOpenChange:s=>{m(s),s||u(null)},onSubmit:async(s,x)=>{if(x){await v(x,s);return}await n(s)}})]})}function $({eyebrow:t,title:r,description:d,meta:o,actions:c,className:n}){return e.jsxs("div",{className:N("flex flex-wrap items-start justify-between gap-3",n),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[t?e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:t}):null,e.jsxs("div",{className:N("min-w-0",t&&"mt-2"),children:[e.jsx("div",{className:"min-w-0 text-lg text-[var(--ui-ink-strong)]",children:r}),d?e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:d}):null]})]}),o||c?e.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-2",children:[o,c]}):null]})}function ee(){const t=z(),[r,d]=p.useState("active"),[o,c]=p.useState(null),n=t.snapshot.dashboard.goals.length>0,v=F(t.snapshot.dashboard.projects),f=U(t.snapshot.dashboard.projects,r),m=L(t.selectedUserIds),g=new Map(t.snapshot.dashboard.goals.map(a=>[a.id,f.filter(s=>s.goalId===a.id)])),u=async a=>{c(a);try{await t.patchProject(a,{status:"active"})}finally{c(null)}};return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(S,{entityKind:"goal",title:e.jsx(h,{kind:"goal",label:"Life Goals",variant:"heading",size:"lg"}),titleText:"Life Goals",description:"Life goals are the destinations you care about over the long run. Each one can hold several projects, and those projects turn direction into real work.",badge:`${t.snapshot.dashboard.goals.length} active goals`,actions:n?e.jsxs("div",{className:"inline-flex min-h-10 items-center rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-2 text-sm whitespace-nowrap text-[var(--ui-ink-soft)]",children:[t.snapshot.dashboard.projects.length," live project",t.snapshot.dashboard.projects.length===1?"":"s"," ","attached"]}):null}),e.jsx(O,{goals:t.snapshot.dashboard.goals,tags:t.snapshot.tags,users:t.snapshot.users,defaultUserId:m,onCreate:t.createGoal,onUpdate:t.patchGoal}),n?e.jsx(M,{value:r,counts:v,onChange:d}):null,n?null:e.jsx(T,{eyebrow:"Life goals",title:"No life goals yet",description:"Define the first long-horizon direction above so Forge can attach projects, tasks, momentum, and evidence to something meaningful."}),n?e.jsx("div",{className:"grid gap-4",children:t.snapshot.dashboard.goals.map(a=>{const s=g.get(a.id)??[],x=B(t.snapshot.dashboard.notesSummaryByEntity,"goal",a.id);return e.jsx(b,{to:`/goals/${a.id}`,className:"min-w-0 overflow-hidden rounded-[28px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4 transition hover:bg-[var(--ui-surface-hover)] sm:p-5",children:e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.15fr)_minmax(0,0.85fr)] xl:gap-5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs(D,{children:[a.tags.slice(0,3).map(i=>e.jsx(l,{className:"bg-[var(--ui-surface-2)]",style:{color:i.color},children:i.name},i.id)),e.jsx(l,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",children:a.horizon}),e.jsx(I,{user:a.user,compact:!0})]}),e.jsx("div",{className:"mt-4",children:e.jsx(h,{kind:"goal",label:a.title,variant:"heading",size:"xl",lines:2})}),e.jsx("p",{className:"mt-3 max-w-2xl text-sm leading-7 text-[var(--ui-ink-soft)]",children:a.description}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-3.5 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Progress"}),e.jsxs("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:[a.progress,"%"]})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-3.5 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Tasks done"}),e.jsxs("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:[a.completedTasks,"/",Math.max(a.totalTasks,1)]})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-3.5 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"XP banked"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:a.earnedPoints})]})]}),e.jsx("div",{className:"mt-4",children:e.jsx(R,{value:a.progress})}),e.jsx("div",{className:"mt-4",children:e.jsx(G,{entityType:"goal",entityId:a.id,count:x.count})})]}),e.jsxs("div",{className:"min-w-0 rounded-[24px] bg-[var(--ui-surface-2)] p-4",children:[e.jsx($,{title:"Projects carrying this direction",meta:e.jsx("div",{className:"shrink-0 text-sm text-[var(--ui-ink-faint)]",children:s.length}),className:"gap-2"}),s.length===0?e.jsx("div",{className:"mt-4 text-sm leading-6 text-[var(--ui-ink-soft)]",children:r==="active"?"No active project is attached yet. Create one so this direction starts producing visible work.":"No projects in this lifecycle view are attached yet. Switch filters or restart one to bring it back into active motion."}):e.jsx("div",{className:"mt-4 grid gap-3",children:s.slice(0,3).map(i=>e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-hover)] px-4 py-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e.jsx(w,{kind:"project",compact:!0,gradient:!1}),e.jsx(h,{kind:"project",label:i.title,className:"min-w-0",showIcon:!1,lines:2})]}),e.jsx(l,{className:"shrink-0",children:i.status})]}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:i.description}),e.jsxs("div",{className:"mt-3 text-sm text-[var(--ui-ink-faint)]",children:["Next move:"," ",i.nextTaskTitle??"Define the first attached task"]}),r!=="active"&&i.status!=="active"?e.jsx("div",{className:"mt-4 flex justify-end",children:e.jsx(y,{variant:"secondary",size:"sm",pending:o===i.id,pendingLabel:"Restarting…",onClick:j=>{j.preventDefault(),j.stopPropagation(),u(i.id)},children:"Restart"})}):null]},i.id))})]})]})},a.id)})}):e.jsx(k,{children:e.jsx("div",{className:"rounded-[20px] bg-[var(--ui-surface-2)] p-4 text-sm text-[var(--ui-ink-soft)]",children:"Goal cards will appear here once the first long-horizon direction is created."})})]})}export{ee as GoalsPage};
1
+ import{r as p,j as e,aC as b,c4 as P,b8 as C}from"./vendor-Dnkkx2co.js";import{P as S}from"./page-hero-CONuJu5J.js";import{E as G}from"./entity-note-count-link-ef3ZOpKM.js";import{C as k,B as y,b as w,V as h,c as l,X as E,Z as N,u as z,s as L,a as T,_ as B,U as I,W as R}from"./index-QJkjKYzZ.js";import{P as D}from"./pill-cluster-W2fY48OM.js";import{b as F,f as U,P as M}from"./project-collections-NBwk6yV-.js";import"./state-vCcAT5Hq.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";function O({goals:t,tags:r,users:d,defaultUserId:o=null,pending:c=!1,onCreate:n,onUpdate:v}){const[f,m]=p.useState(!1),[g,u]=p.useState(null),a=t.find(s=>s.id===g)??null;return e.jsxs(e.Fragment,{children:[e.jsxs(k,{children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Goal arcs"}),e.jsx("h3",{className:"mt-2 font-display text-3xl text-[var(--ui-ink-strong)]",children:"Strategic arcs before tickets"}),e.jsx("p",{className:"mt-3 max-w-3xl text-sm leading-7 text-[var(--ui-ink-soft)]",children:"This is the long-horizon map. Each arc shows why it matters, how much ground has been covered, and which project should move next."})]}),e.jsx(y,{onClick:()=>{u(null),m(!0)},children:"Create goal"})]}),e.jsxs("div",{className:"mt-5 grid gap-3 xl:grid-cols-2",children:[t.length===0?e.jsx("div",{className:"rounded-[24px] bg-[var(--ui-surface-2)] p-5 text-sm leading-7 text-[var(--ui-ink-soft)] xl:col-span-2",children:"Start with a life goal. Once the destination is clear, you can attach projects and then fill those projects with tasks."}):null,t.map(s=>{const x=`${Math.max(6,Math.min(100,s.progress))}%`;return e.jsxs(b,{to:`/goals/${s.id}`,className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4 transition hover:bg-[var(--ui-surface-hover)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx(w,{kind:"goal",compact:!0,gradient:!1}),e.jsx("div",{className:"mt-2",children:e.jsx(h,{kind:"goal",label:s.title,variant:"heading",size:"lg",showKind:!1,lines:2})}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:s.description||"No strategic note attached yet."})]}),e.jsx("button",{className:"rounded-full bg-[var(--ui-surface-2)] p-2 text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",type:"button",onClick:i=>{i.preventDefault(),i.stopPropagation(),u(s.id),m(!0)},children:e.jsx(P,{className:"size-4"})})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsx(l,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",children:s.horizon}),e.jsx(l,{className:s.status==="active"?"text-[var(--success)]":s.status==="paused"?"text-[var(--warning)]":"text-[var(--tertiary)]",children:s.status}),e.jsxs(l,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",children:[s.earnedPoints," / ",s.targetPoints," xp"]}),e.jsxs(l,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",children:[s.totalTasks," tasks"]})]}),e.jsx("div",{className:"mt-4 h-1.5 rounded-full bg-[var(--ui-surface-2)]",children:e.jsx("div",{className:"h-full rounded-full bg-[var(--primary)]",style:{width:x}})}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:s.tags.map(i=>e.jsx(l,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",children:i.name},i.id))}),e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate",children:s.momentumLabel}),e.jsxs("span",{className:"inline-flex shrink-0 items-center gap-2",style:{color:s.themeColor},children:["Open arc",e.jsx(C,{className:"size-3.5"})]})]})]},s.id)})]})]}),e.jsx(E,{open:f,pending:c,editingGoal:a,tags:r,users:d,defaultUserId:o,onOpenChange:s=>{m(s),s||u(null)},onSubmit:async(s,x)=>{if(x){await v(x,s);return}await n(s)}})]})}function $({eyebrow:t,title:r,description:d,meta:o,actions:c,className:n}){return e.jsxs("div",{className:N("flex flex-wrap items-start justify-between gap-3",n),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[t?e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:t}):null,e.jsxs("div",{className:N("min-w-0",t&&"mt-2"),children:[e.jsx("div",{className:"min-w-0 text-lg text-[var(--ui-ink-strong)]",children:r}),d?e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:d}):null]})]}),o||c?e.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-2",children:[o,c]}):null]})}function ee(){const t=z(),[r,d]=p.useState("active"),[o,c]=p.useState(null),n=t.snapshot.dashboard.goals.length>0,v=F(t.snapshot.dashboard.projects),f=U(t.snapshot.dashboard.projects,r),m=L(t.selectedUserIds),g=new Map(t.snapshot.dashboard.goals.map(a=>[a.id,f.filter(s=>s.goalId===a.id)])),u=async a=>{c(a);try{await t.patchProject(a,{status:"active"})}finally{c(null)}};return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(S,{entityKind:"goal",title:e.jsx(h,{kind:"goal",label:"Life Goals",variant:"heading",size:"lg"}),titleText:"Life Goals",description:"Life goals are the destinations you care about over the long run. Each one can hold several projects, and those projects turn direction into real work.",badge:`${t.snapshot.dashboard.goals.length} active goals`,actions:n?e.jsxs("div",{className:"inline-flex min-h-10 items-center rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-2 text-sm whitespace-nowrap text-[var(--ui-ink-soft)]",children:[t.snapshot.dashboard.projects.length," live project",t.snapshot.dashboard.projects.length===1?"":"s"," ","attached"]}):null}),e.jsx(O,{goals:t.snapshot.dashboard.goals,tags:t.snapshot.tags,users:t.snapshot.users,defaultUserId:m,onCreate:t.createGoal,onUpdate:t.patchGoal}),n?e.jsx(M,{value:r,counts:v,onChange:d}):null,n?null:e.jsx(T,{eyebrow:"Life goals",title:"No life goals yet",description:"Define the first long-horizon direction above so Forge can attach projects, tasks, momentum, and evidence to something meaningful."}),n?e.jsx("div",{className:"grid gap-4",children:t.snapshot.dashboard.goals.map(a=>{const s=g.get(a.id)??[],x=B(t.snapshot.dashboard.notesSummaryByEntity,"goal",a.id);return e.jsx(b,{to:`/goals/${a.id}`,className:"min-w-0 overflow-hidden rounded-[28px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4 transition hover:bg-[var(--ui-surface-hover)] sm:p-5",children:e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.15fr)_minmax(0,0.85fr)] xl:gap-5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs(D,{children:[a.tags.slice(0,3).map(i=>e.jsx(l,{className:"bg-[var(--ui-surface-2)]",style:{color:i.color},children:i.name},i.id)),e.jsx(l,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",children:a.horizon}),e.jsx(I,{user:a.user,compact:!0})]}),e.jsx("div",{className:"mt-4",children:e.jsx(h,{kind:"goal",label:a.title,variant:"heading",size:"xl",lines:2})}),e.jsx("p",{className:"mt-3 max-w-2xl text-sm leading-7 text-[var(--ui-ink-soft)]",children:a.description}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-3.5 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Progress"}),e.jsxs("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:[a.progress,"%"]})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-3.5 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Tasks done"}),e.jsxs("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:[a.completedTasks,"/",Math.max(a.totalTasks,1)]})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-3.5 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"XP banked"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:a.earnedPoints})]})]}),e.jsx("div",{className:"mt-4",children:e.jsx(R,{value:a.progress})}),e.jsx("div",{className:"mt-4",children:e.jsx(G,{entityType:"goal",entityId:a.id,count:x.count})})]}),e.jsxs("div",{className:"min-w-0 rounded-[24px] bg-[var(--ui-surface-2)] p-4",children:[e.jsx($,{title:"Projects carrying this direction",meta:e.jsx("div",{className:"shrink-0 text-sm text-[var(--ui-ink-faint)]",children:s.length}),className:"gap-2"}),s.length===0?e.jsx("div",{className:"mt-4 text-sm leading-6 text-[var(--ui-ink-soft)]",children:r==="active"?"No active project is attached yet. Create one so this direction starts producing visible work.":"No projects in this lifecycle view are attached yet. Switch filters or restart one to bring it back into active motion."}):e.jsx("div",{className:"mt-4 grid gap-3",children:s.slice(0,3).map(i=>e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-hover)] px-4 py-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e.jsx(w,{kind:"project",compact:!0,gradient:!1}),e.jsx(h,{kind:"project",label:i.title,className:"min-w-0",showIcon:!1,lines:2})]}),e.jsx(l,{className:"shrink-0",children:i.status})]}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:i.description}),e.jsxs("div",{className:"mt-3 text-sm text-[var(--ui-ink-faint)]",children:["Next move:"," ",i.nextTaskTitle??"Define the first attached task"]}),r!=="active"&&i.status!=="active"?e.jsx("div",{className:"mt-4 flex justify-end",children:e.jsx(y,{variant:"secondary",size:"sm",pending:o===i.id,pendingLabel:"Restarting…",onClick:j=>{j.preventDefault(),j.stopPropagation(),u(i.id)},children:"Restart"})}):null]},i.id))})]})]})},a.id)})}):e.jsx(k,{children:e.jsx("div",{className:"rounded-[20px] bg-[var(--ui-surface-2)] p-4 text-sm text-[var(--ui-ink-soft)]",children:"Goal cards will appear here once the first long-horizon direction is created."})})]})}export{ee as GoalsPage};
@@ -1 +1 @@
1
- import{r as p,j as e,c2 as Ye,aG as Ze,cd as Je,aV as Ve,ce as es,c7 as ss,c5 as Ce,bO as Ie,cf as Pe,cg as as,aK as De,ch as ts,ci as rs,cj as is,ck as ns}from"./vendor-Dnkkx2co.js";import{R as Le,P as Se,O as Te,C as He,T as Ee,D as Ae,a as Be}from"./ui-C1iwpj2-.js";import{j as ls,i as me,k as ge}from"./state-vCcAT5Hq.js";import{E as os}from"./entity-note-count-link-BX93WYgh.js";import{N as ds}from"./note-markdown-CepDxj3v.js";import{Q as cs,$ as us,F as b,I as q,T as ve,a0 as ms,a1 as gs,j as oe,b as F,u as xs,a2 as hs,s as bs,a3 as vs,a4 as ps,a5 as fs,a6 as ks,a7 as xe,a8 as ys,B as L,V as Fe,C as A,h as U,d as Me,a as js,_ as ws,Z as P,U as _s,c as v,a9 as Ns,aa as Cs,ab as Ke,ac as Is,ad as Ps,O as Ds}from"./index-By3tQxiE.js";import{u as Ls,p as Ss}from"./use-psyche-focus-target-Ct-acS9G.js";import{P as Ts}from"./page-hero-5RTqAI88.js";import{S as Hs}from"./select-menu-mfaklv7r.js";import{f as Es}from"./date-keys-Cj1G3TOn.js";import"./motion-Lt5B1XuE.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";const he={title:"",description:"",status:"active",userId:null,polarity:"positive",frequency:"daily",targetCount:1,weekDays:[],linkedGoalIds:[],linkedProjectIds:[],linkedTaskIds:[],linkedValueIds:[],linkedPatternIds:[],linkedBehaviorIds:[],linkedBeliefIds:[],linkedModeIds:[],linkedReportIds:[],linkedBehaviorId:"",rewardXp:12,penaltyXp:8,generatedHealthEventTemplate:{enabled:!1,workoutType:"workout",title:"",durationMinutes:45,xpReward:0,tags:[],links:[],notesTemplate:""}},As=[{value:1,label:"Mon"},{value:2,label:"Tue"},{value:3,label:"Wed"},{value:4,label:"Thu"},{value:5,label:"Fri"},{value:6,label:"Sat"},{value:0,label:"Sun"}];function Bs(s){return{title:s.title,description:s.description,status:s.status,userId:s.userId??null,polarity:s.polarity,frequency:s.frequency,targetCount:s.targetCount,weekDays:s.weekDays,linkedGoalIds:s.linkedGoalIds,linkedProjectIds:s.linkedProjectIds,linkedTaskIds:s.linkedTaskIds,linkedValueIds:s.linkedValueIds,linkedPatternIds:s.linkedPatternIds,linkedBehaviorIds:s.linkedBehaviorIds,linkedBeliefIds:s.linkedBeliefIds,linkedModeIds:s.linkedModeIds,linkedReportIds:s.linkedReportIds,linkedBehaviorId:s.linkedBehaviorId??"",rewardXp:s.rewardXp,penaltyXp:s.penaltyXp,generatedHealthEventTemplate:s.generatedHealthEventTemplate}}function Fs({open:s,pending:o=!1,editingHabit:d,values:f,patterns:k,behaviors:T,beliefs:c,modes:y,reports:m,goals:j,projects:H,tasks:D,users:M,defaultUserId:w=null,onOpenChange:N,onSubmit:E}){const[R,S]=p.useState(he),[te,K]=p.useState(null),[C,Z]=p.useState({});p.useEffect(()=>{s&&(S(d?Bs(d):{...he,userId:w}),K(null),Z({}))},[w,d,s]);const O=M.find(r=>r.id===w)??null,z=p.useMemo(()=>T.slice().sort((r,i)=>r.title.localeCompare(i.title)),[T]),I=r=>({linkedBehaviorIds:r,linkedBehaviorId:r[0]??""}),_=(r,i)=>r.includes(i)?r.filter(t=>t!==i):[...r,i],G=[{id:"intent",eyebrow:"Habit",title:"Name the recurring move",description:"Use habits for recurring commitments and recurring slips. Keep the title concrete so the daily check-in never needs interpretation.",render:(r,i)=>e.jsxs(e.Fragment,{children:[e.jsx(b,{label:"Title",error:C.title??null,children:e.jsx(q,{value:r.title,onChange:t=>i({title:t.target.value}),placeholder:"Train lower body"})}),e.jsx(b,{label:"Description",children:e.jsx(ve,{value:r.description,onChange:t=>i({description:t.target.value}),placeholder:"Write the habit description in Markdown. Define what counts, edge cases, and examples."})}),e.jsx(ms,{value:r.userId,users:M,onChange:t=>i({userId:t}),label:"Owner user",defaultLabel:gs(O),help:"Habits can be owned by humans or bots. When one scoped user is active, Forge uses that as the default."})]})},{id:"shape",eyebrow:"Shape",title:"Set direction and cadence",description:"Forge uses polarity to decide whether doing the habit is good or bad, and cadence to know when it should show up.",render:(r,i)=>e.jsxs(e.Fragment,{children:[e.jsx(b,{label:"Polarity",children:e.jsx(oe,{value:r.polarity,onChange:t=>i({polarity:t}),options:[{value:"positive",label:"Positive",description:"Doing it is aligned and should award XP."},{value:"negative",label:"Negative",description:"Doing it is a slip and should cost XP."}],columns:2})}),e.jsx(b,{label:"Frequency",children:e.jsx(oe,{value:r.frequency,onChange:t=>i({frequency:t}),options:[{value:"daily",label:"Daily",description:"Track against each day."},{value:"weekly",label:"Weekly",description:"Track only on the selected weekdays."}],columns:2})}),r.frequency==="weekly"?e.jsx(b,{label:"Weekdays",error:C.weekDays??null,children:e.jsx("div",{className:"flex flex-wrap gap-2",children:As.map(t=>{const n=r.weekDays.includes(t.value);return e.jsx("button",{type:"button",className:`rounded-full border px-3 py-2 text-sm transition ${n?"border-[color-mix(in_srgb,var(--primary)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-accent-soft)] 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-hover)] hover:text-[var(--ui-ink-strong)]"}`,onClick:()=>i({weekDays:n?r.weekDays.filter(J=>J!==t.value):[...r.weekDays,t.value].sort()}),children:t.label},t.value)})})}):null,e.jsx(b,{label:"Status",children:e.jsx(oe,{value:r.status,onChange:t=>i({status:t}),options:[{value:"active",label:"Active",description:"Show it in the daily operating flow."},{value:"paused",label:"Paused",description:"Keep it visible but not currently due."},{value:"archived",label:"Archived",description:"Keep the record but retire it from active work."}]})})]})},{id:"generation",eyebrow:"Generation",title:"Decide whether this habit should create a workout record",description:"Use this when a completed habit should generate a structured sports or recovery session in Forge, then reconcile with HealthKit later if the same session gets imported.",render:(r,i)=>e.jsxs(e.Fragment,{children:[e.jsx(b,{label:"Generate workout record",children:e.jsx(oe,{value:r.generatedHealthEventTemplate.enabled?"enabled":"disabled",onChange:t=>i({generatedHealthEventTemplate:{...r.generatedHealthEventTemplate,enabled:t==="enabled"}}),options:[{value:"disabled",label:"Disabled",description:"This habit only affects the habit ledger."},{value:"enabled",label:"Enabled",description:"A completed check-in creates a workout or recovery session."}],columns:2})}),r.generatedHealthEventTemplate.enabled?e.jsxs(e.Fragment,{children:[e.jsx(b,{label:"Workout type",children:e.jsx(q,{value:r.generatedHealthEventTemplate.workoutType,onChange:t=>i({generatedHealthEventTemplate:{...r.generatedHealthEventTemplate,workoutType:t.target.value}}),placeholder:"mobility, walk, strength, recovery"})}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(b,{label:"Duration (minutes)",children:e.jsx(q,{type:"number",min:1,max:1440,value:r.generatedHealthEventTemplate.durationMinutes,onChange:t=>i({generatedHealthEventTemplate:{...r.generatedHealthEventTemplate,durationMinutes:Number(t.target.value)||45}})})}),e.jsx(b,{label:"Workout XP",children:e.jsx(q,{type:"number",min:0,max:500,value:r.generatedHealthEventTemplate.xpReward,onChange:t=>i({generatedHealthEventTemplate:{...r.generatedHealthEventTemplate,xpReward:Number(t.target.value)||0}})})})]}),e.jsx(b,{label:"Generated session note",children:e.jsx(ve,{value:r.generatedHealthEventTemplate.notesTemplate,onChange:t=>i({generatedHealthEventTemplate:{...r.generatedHealthEventTemplate,notesTemplate:t.target.value}}),placeholder:"Morning routine session generated from habit completion."})})]}):null]})},{id:"links",eyebrow:"Links",title:"Connect the habit to real Forge work",description:"Link habits to the goals, projects, and tasks they support so they stay anchored in the same operating graph as everything else.",render:(r,i)=>e.jsxs(e.Fragment,{children:[e.jsx(b,{label:"Goals",children:e.jsx("div",{className:"flex flex-wrap gap-2",children:j.map(t=>{const n=r.linkedGoalIds.includes(t.id);return e.jsx("button",{type:"button",onClick:()=>i({linkedGoalIds:_(r.linkedGoalIds,t.id)}),children:e.jsx(F,{kind:"goal",label:t.title,gradient:n,className:n?"":"opacity-75"})},t.id)})})}),e.jsx(b,{label:"Projects",children:e.jsx("div",{className:"flex flex-wrap gap-2",children:H.map(t=>{const n=r.linkedProjectIds.includes(t.id);return e.jsx("button",{type:"button",onClick:()=>i({linkedProjectIds:_(r.linkedProjectIds,t.id)}),children:e.jsx(F,{kind:"project",label:t.title,gradient:n,className:n?"":"opacity-75"})},t.id)})})}),e.jsx(b,{label:"Tasks",children:e.jsx("div",{className:"flex max-h-48 flex-wrap gap-2 overflow-y-auto",children:D.map(t=>{const n=r.linkedTaskIds.includes(t.id);return e.jsx("button",{type:"button",onClick:()=>i({linkedTaskIds:_(r.linkedTaskIds,t.id)}),children:e.jsx(F,{kind:"task",label:t.title,gradient:n,className:n?"":"opacity-75",wrap:!0})},t.id)})})}),e.jsx(b,{label:"Values",children:e.jsx("div",{className:"flex flex-wrap gap-2",children:f.map(t=>{const n=r.linkedValueIds.includes(t.id);return e.jsx("button",{type:"button",onClick:()=>i({linkedValueIds:_(r.linkedValueIds,t.id)}),children:e.jsx(F,{kind:"value",label:t.title,gradient:n,className:n?"":"opacity-75"})},t.id)})})}),e.jsx(b,{label:"Patterns",children:e.jsx("div",{className:"flex max-h-44 flex-wrap gap-2 overflow-y-auto",children:k.map(t=>{const n=r.linkedPatternIds.includes(t.id);return e.jsx("button",{type:"button",onClick:()=>i({linkedPatternIds:_(r.linkedPatternIds,t.id)}),children:e.jsx(F,{kind:"pattern",label:t.title,gradient:n,className:n?"":"opacity-75",wrap:!0})},t.id)})})})]})},{id:"reward",eyebrow:"Reward",title:"Link the behavior and XP logic",description:"Habits can point back to a Psyche behavior. Reward XP is granted for aligned outcomes; penalty XP is applied for misaligned ones.",render:(r,i)=>e.jsxs(e.Fragment,{children:[e.jsx(b,{label:"Linked behavior",children:e.jsx("div",{className:"flex max-h-44 flex-wrap gap-2 overflow-y-auto",children:z.map(t=>{const n=r.linkedBehaviorIds.includes(t.id);return e.jsx("button",{type:"button",onClick:()=>i(I(_(r.linkedBehaviorIds,t.id))),children:e.jsx(F,{kind:"behavior",label:t.title,gradient:n,className:n?"":"opacity-75",wrap:!0})},t.id)})})}),e.jsx(b,{label:"Beliefs",children:e.jsx("div",{className:"flex max-h-44 flex-wrap gap-2 overflow-y-auto",children:c.map(t=>{const n=r.linkedBeliefIds.includes(t.id);return e.jsx("button",{type:"button",onClick:()=>i({linkedBeliefIds:_(r.linkedBeliefIds,t.id)}),children:e.jsx(F,{kind:"belief",label:t.statement,gradient:n,className:n?"":"opacity-75",wrap:!0})},t.id)})})}),e.jsx(b,{label:"Modes",children:e.jsx("div",{className:"flex max-h-44 flex-wrap gap-2 overflow-y-auto",children:y.map(t=>{const n=r.linkedModeIds.includes(t.id);return e.jsx("button",{type:"button",onClick:()=>i({linkedModeIds:_(r.linkedModeIds,t.id)}),children:e.jsx(F,{kind:"mode",label:t.title,gradient:n,className:n?"":"opacity-75",wrap:!0})},t.id)})})}),e.jsx(b,{label:"Reports",children:e.jsx("div",{className:"flex max-h-44 flex-wrap gap-2 overflow-y-auto",children:m.map(t=>{const n=r.linkedReportIds.includes(t.id);return e.jsx("button",{type:"button",onClick:()=>i({linkedReportIds:_(r.linkedReportIds,t.id)}),children:e.jsx(F,{kind:"report",label:t.title,gradient:n,className:n?"":"opacity-75",wrap:!0})},t.id)})})}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-3",children:[e.jsx(b,{label:"Target count",error:C.targetCount??null,children:e.jsx(q,{type:"number",value:r.targetCount,onChange:t=>i({targetCount:Number(t.target.value)||1})})}),e.jsx(b,{label:"Reward XP",error:C.rewardXp??null,children:e.jsx(q,{type:"number",value:r.rewardXp,onChange:t=>i({rewardXp:Number(t.target.value)||1})})}),e.jsx(b,{label:"Penalty XP",error:C.penaltyXp??null,children:e.jsx(q,{type:"number",value:r.penaltyXp,onChange:t=>i({penaltyXp:Number(t.target.value)||1})})})]})]})}];return e.jsx(cs,{open:s,onOpenChange:N,eyebrow:"Habit",title:d?"Edit habit":"Create habit",description:"Habits are recurring commitments or recurring slips with explicit XP consequences.",value:R,onChange:S,draftPersistenceKey:d?`habit.${d.id}`:"habit.new",steps:G,pending:o,pendingLabel:d?"Save habit":"Create habit",submitLabel:d?"Save habit":"Create habit",error:te,onSubmit:async()=>{K(null);const r=us.safeParse(R);if(!r.success){Z(Object.fromEntries(Object.entries(r.error.flatten().fieldErrors).map(([i,t])=>[i,t==null?void 0:t[0]]))),K("Some habit fields still need attention.");return}Z({});try{await E(r.data,d==null?void 0:d.id),S(he),N(!1)}catch(i){K(i instanceof Error?i.message:"Habit update failed.")}}})}const Ms=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Ks=["S","M","T","W","T","F","S"],Xs=[{value:"name",label:"Name A-Z",description:"Keep the list stable alphabetically."},{value:"needs_attention",label:"Needs attention",description:"Bubble up habits still waiting on today."},{value:"streak",label:"Longest streak",description:"Put the strongest current streaks first."},{value:"created_at",label:"Newest created",description:"Show the most recently created habits first."},{value:"updated_at",label:"Recently updated",description:"Sort by the most recently changed habits."}];function Rs(s){return s.frequency==="daily"?`${s.targetCount}x daily`:`${s.targetCount}x weekly · ${s.weekDays.map(o=>Ms[o]).join(", ")}`}function W(s){return Es(s)}function ze(s){const[o,d,f]=s.split("-").map(Number);return new Date(o,d-1,f)}function $e(s){return new Date(s.getFullYear(),s.getMonth(),s.getDate())}function de(s,o){const d=new Date(s);return d.setDate(d.getDate()+o),d}function Xe(s){const o=$e(s),d=(o.getDay()+6)%7;return o.setDate(o.getDate()-d),o}function ee(s){const o=typeof s=="string"?ze(s):s;return new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric"}).format(o)}function ue(s,o){return s.polarity==="positive"&&o==="done"||s.polarity==="negative"&&o==="missed"}function pe(s,o){return s.polarity==="positive"?o==="done"?"Done":"Missed":o==="done"?"Performed":"Resisted"}function qe(s){const o=W(new Date),d=s.checkIns.find(f=>f.dateKey===o)??null;return s.dueToday?{tone:"pending",label:s.frequency==="daily"?"Waiting for today":"Awaiting this week's check-in",cardClass:"border-[color-mix(in_srgb,var(--warning)_28%,var(--ui-border-subtle)_72%)] shadow-[var(--ui-shadow-soft)]",overlayClass:"bg-[radial-gradient(circle_at_top_right,color-mix(in_srgb,var(--warning)_18%,transparent),transparent_44%)]",pillClass:"border border-[color-mix(in_srgb,var(--warning)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]"}:d?ue(s,d.status)?{tone:"aligned",label:`${pe(s,d.status)} today`,cardClass:"border-[color-mix(in_srgb,var(--success)_24%,var(--ui-border-subtle)_76%)] shadow-[var(--ui-shadow-soft)]",overlayClass:"bg-[radial-gradient(circle_at_top_right,color-mix(in_srgb,var(--success)_16%,transparent),transparent_44%)]",pillClass:"border border-[color-mix(in_srgb,var(--success)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)]"}:{tone:"unaligned",label:`${pe(s,d.status)} today`,cardClass:"border-[color-mix(in_srgb,var(--danger)_24%,var(--ui-border-subtle)_76%)] shadow-[var(--ui-shadow-soft)]",overlayClass:"bg-[radial-gradient(circle_at_top_right,color-mix(in_srgb,var(--danger)_16%,transparent),transparent_44%)]",pillClass:"border border-[color-mix(in_srgb,var(--danger)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]"}:s.polarity==="positive"?{tone:"neutral",label:"No update due right now",cardClass:"",overlayClass:"bg-[radial-gradient(circle_at_top_right,color-mix(in_srgb,var(--success)_9%,transparent),transparent_40%)]",pillClass:"border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]"}:{tone:"neutral",label:"No update due right now",cardClass:"",overlayClass:"bg-[radial-gradient(circle_at_top_right,color-mix(in_srgb,var(--danger)_9%,transparent),transparent_40%)]",pillClass:"border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]"}}function Os(s){return s>=10?{Icon:ts,className:"border border-[color-mix(in_srgb,var(--warning)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)] shadow-[var(--ui-shadow-soft)]",iconClass:"text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]",valueClass:"text-[var(--ui-ink-strong)]",label:"Celebration pace"}:s>=5?{Icon:rs,className:"border border-[color-mix(in_srgb,var(--success)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)] shadow-[var(--ui-shadow-soft)]",iconClass:"text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)]",valueClass:"text-[var(--ui-ink-strong)]",label:"Locked in"}:s>=1?{Icon:is,className:"border border-[color-mix(in_srgb,var(--info)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_76%,var(--ui-ink-strong)_24%)] shadow-[var(--ui-shadow-soft)]",iconClass:"text-[color-mix(in_srgb,var(--info)_76%,var(--ui-ink-strong)_24%)]",valueClass:"text-[var(--ui-ink-strong)]",label:"Building rhythm"}:{Icon:ns,className:"border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)] shadow-[var(--ui-shadow-soft)]",iconClass:"text-[var(--ui-ink-soft)]",valueClass:"text-[var(--ui-ink-strong)]",label:"Cold start"}}function zs(s){return s>=80?"border-[color-mix(in_srgb,var(--success)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)]":s>=50?"border-[color-mix(in_srgb,var(--warning)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]":"border-[color-mix(in_srgb,var(--danger)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]"}const se="border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",Re="border-[color-mix(in_srgb,var(--success)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)]",Oe="border-[color-mix(in_srgb,var(--danger)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]",ce="border-[color-mix(in_srgb,var(--warning)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]",be="border-[color-mix(in_srgb,var(--info)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_76%,var(--ui-ink-strong)_24%)]",ae="border-[color-mix(in_srgb,var(--primary)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-accent-soft)] text-[color-mix(in_srgb,var(--primary)_72%,var(--ui-ink-strong)_28%)]";function $s(s){var T;const o=new Date;if(s.frequency==="daily"){const c=$e(o),y=[];for(let m=-6;m<=0;m+=1){const j=de(c,m),H=W(j),D=s.checkIns.find(N=>N.dateKey===H)??null,M=Ks[j.getDay()],w=m===0;y.push({id:H,label:M,current:w,actionDateKey:H,actionLabel:ee(j),state:D?ue(s,D.status)?"aligned":"unaligned":"unknown",title:`${ee(j)} · ${D?pe(s,D.status):"Not informed"}`})}return{caption:"7-day rhythm",rangeLabel:"Past 7 days",showLabels:!0,startLabel:"",endLabel:"",cells:y}}const d=Xe(o),f=new Map;for(const c of s.checkIns){const y=W(Xe(ze(c.dateKey))),m=f.get(y)??[];m.push(c),f.set(y,m)}const k=[];for(let c=-6;c<=0;c+=1){const y=de(d,c*7),m=W(y),j=f.get(m)??[],H=s.weekDays.length>0?[...s.weekDays].sort((E,R)=>R-E)[0]:0,D=W(de(y,H)),M=((T=j[0])==null?void 0:T.dateKey)??D,w=j.filter(E=>ue(s,E.status)).length,N=j.length-w;k.push({id:m,label:"",current:c===0,actionDateKey:M,actionLabel:`Week of ${ee(y)}`,state:j.length===0?"unknown":w>=N?"aligned":"unaligned",title:`${ee(y)} week · ${j.length===0?"Not informed":w>=N?"Mostly aligned":"Mostly off track"}`})}return{caption:"7-week rhythm",rangeLabel:"Past 7 weeks",showLabels:!1,startLabel:ee(de(d,-42)),endLabel:"This week",cells:k}}function qs(s,o){return P("h-8 w-full rounded-[10px] border transition",s==="aligned"&&"border-[color-mix(in_srgb,var(--success)_30%,var(--ui-border-subtle)_70%)] bg-[color-mix(in_srgb,var(--success)_58%,var(--ui-surface-1)_42%)] shadow-[var(--ui-shadow-soft)]",s==="unaligned"&&"border-[color-mix(in_srgb,var(--danger)_30%,var(--ui-border-subtle)_70%)] bg-[color-mix(in_srgb,var(--danger)_54%,var(--ui-surface-1)_46%)] shadow-[var(--ui-shadow-soft)]",s==="unknown"&&"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",o&&"ring-1 ring-[color-mix(in_srgb,var(--primary)_34%,transparent)]")}function Ws({habit:s,onSelectCell:o}){const d=$s(s),f=qe(s);return e.jsxs("div",{className:"w-full rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-2.5 shadow-[var(--ui-shadow-soft)]",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"shrink-0",children:[e.jsx("div",{className:"font-label text-[10px] uppercase tracking-[0.16em] text-[var(--ui-ink-muted)]",children:d.caption}),e.jsx("div",{className:"text-[11px] text-[var(--ui-ink-soft)]",children:d.rangeLabel})]}),e.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:d.cells.map(k=>e.jsxs("button",{type:"button",className:"group flex min-w-0 flex-1 items-center gap-1 rounded-[10px] transition hover:bg-[var(--ui-surface-hover)]",onClick:()=>o(s,k),title:`Log check-in for ${k.actionLabel}`,"aria-label":`Log check-in for ${k.actionLabel}`,children:[e.jsx("div",{className:P(qs(k.state,k.current),"h-6 min-w-0 flex-1 rounded-[8px] transition duration-150 group-hover:-translate-y-0.5 group-hover:shadow-[var(--ui-shadow-soft)]")}),d.showLabels?e.jsx("span",{className:"hidden text-[9px] uppercase tracking-[0.14em] text-[var(--ui-ink-muted)] transition group-hover:text-[var(--ui-ink-medium)] sm:inline",children:k.label}):null]},k.id))}),e.jsx("div",{className:P("shrink-0 rounded-full px-2.5 py-1 text-[10px] font-medium",f.pillClass),children:f.label})]}),d.showLabels?null:e.jsxs("div",{className:"mt-1 text-right text-[10px] uppercase tracking-[0.14em] text-[var(--ui-ink-muted)]",children:[d.startLabel," - ",d.endLabel]})]})}function Gs(s){return s.polarity==="positive"?{alignedLabel:"Done",alignedDescription:"Log that the intended habit happened.",unalignedLabel:"Missed",unalignedDescription:"Log that the habit did not happen."}:{alignedLabel:"Resisted",alignedDescription:"Log that the unwanted behavior was resisted.",unalignedLabel:"Performed",unalignedDescription:"Log that the unwanted behavior happened."}}function Q(s,o){return s.polarity==="positive"?o==="aligned"?"done":"missed":o==="aligned"?"missed":"done"}function Y(s,o){return ue(s,o)?"aligned":"unaligned"}function oa(){var ke,ye,je,we,_e,Ne;const s=xs(),o=ls(),[d,f]=Ye(),[k,T]=p.useState(null),[c,y]=p.useState(null),[m,j]=p.useState(null),[H,D]=p.useState(""),[M,w]=p.useState(!1),[N,E]=p.useState(null),[R,S]=p.useState(null),te=d.get("focus"),K=d.get("orderBy")??"name",C=hs(s.selectedUserIds),Z=bs(C),O=["forge-habits",K,...C];Ls(te);const z=me({queryKey:O,queryFn:async()=>(await Is({userIds:C,orderBy:K})).habits}),I=me({queryKey:["forge-psyche-overview",...C],queryFn:async()=>(await Ps(C)).overview}),_=me({queryKey:["forge-life-force",...C],queryFn:async()=>(await Ds(C)).lifeForce});p.useEffect(()=>{d.get("create")==="1"&&(T(null),w(!0),f(a=>{const h=new URLSearchParams(a);return h.delete("create"),h},{replace:!0}))},[d,f]);const G=async()=>{await o.invalidateQueries({queryKey:["forge-habits"]}),await s.refresh()},r=ge({mutationFn:async({input:a,habitId:h})=>h?(await vs(h,a)).habit:(await ps(a)).habit,onSuccess:async()=>{S(null),await G()},onError:a=>{S(a instanceof Error?a.message:"Habit save failed.")}}),i=ge({mutationFn:async({habitId:a,status:h,dateKey:u,note:$})=>fs(a,{status:h,dateKey:u,note:$}),onSuccess:async()=>{S(null),await G()},onError:a=>{S(a instanceof Error?a.message:"Habit check-in failed.")}}),t=ge({mutationFn:async a=>ks(a),onMutate:async a=>{await o.cancelQueries({queryKey:O});const h=o.getQueryData(O);return o.setQueryData(O,u=>(u==null?void 0:u.filter($=>$.id!==a))??[]),{previousHabits:h}},onSuccess:async()=>{S(null),E(null),await G()},onError:(a,h,u)=>{u!=null&&u.previousHabits&&o.setQueryData(O,u.previousHabits),S(a instanceof Error?a.message:"Habit delete failed.")}}),n=p.useMemo(()=>(z.data??[]).filter(a=>a.status!=="archived"),[z.data]),J=p.useMemo(()=>n.filter(a=>a.dueToday),[n]),We=p.useMemo(()=>J.reduce((a,h)=>{var re;const u=Ke().totalAp,$=((re=xe(h))==null?void 0:re.totalAp)??0;return a+u+$},0),[J]),Ge=p.useMemo(()=>n.reduce((a,h)=>{var u;return a+(((u=xe(h))==null?void 0:u.totalAp)??0)},0),[n]),X=p.useMemo(()=>c?c.habit.checkIns.find(a=>a.dateKey===c.cell.actionDateKey)??null:null,[c]);if(p.useEffect(()=>{if(!c){j(null),D("");return}j((X==null?void 0:X.status)??null),D((X==null?void 0:X.note)??"")},[c,X]),z.error)throw z.error;const Ue=a=>{f(h=>{const u=new URLSearchParams(h);return a==="name"?u.delete("orderBy"):u.set("orderBy",a),u},{replace:!0})},V=c?Gs(c.habit):null,fe=m==="done"||m==="missed"||X!==null;return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(Ts,{entityKind:"habit",title:e.jsx(Fe,{kind:"habit",label:"Habits",variant:"heading",size:"lg"}),titleText:"Habits",description:"Habits track recurring commitments and recurring slips with explicit daily consequences, linked behaviors, and real XP movement.",badge:`${n.length} habits`,actions:e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[e.jsx(ys,{metrics:s.snapshot.metrics}),e.jsxs(L,{onClick:()=>{T(null),w(!0)},children:[e.jsx(Ze,{className:"size-4"}),"New habit"]})]})}),R?e.jsx(A,{className:"border-[color-mix(in_srgb,var(--danger)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Je,{className:"mt-0.5 size-4 shrink-0"}),e.jsx("div",{children:R})]})}):null,e.jsxs("section",{className:"grid gap-4 lg:grid-cols-4",children:[e.jsxs(A,{className:"border-[color-mix(in_srgb,var(--warning)_22%,var(--ui-border-subtle)_78%)] shadow-[var(--ui-shadow-soft)]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Due today"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--primary)]",children:J.length}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Habits that still need a check-in today."})]}),e.jsxs(A,{className:"border-[color-mix(in_srgb,var(--primary)_22%,var(--ui-border-subtle)_78%)] shadow-[var(--ui-shadow-soft)]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Habit AP due"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--primary)]",children:U(We)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Default Action Point load if every due habit is logged today."})]}),e.jsxs(A,{className:"border-[color-mix(in_srgb,var(--success)_22%,var(--ui-border-subtle)_78%)] shadow-[var(--ui-shadow-soft)]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Best streak"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)]",children:Math.max(0,...n.map(a=>a.streakCount))}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Longest current aligned streak across active habits."})]}),e.jsxs(A,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Average alignment"}),e.jsxs("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:[n.length>0?Math.round(n.reduce((a,h)=>a+h.completionRate,0)/n.length):0,"%"]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Share of recent habit check-ins that matched the intended direction."})]})]}),e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)]",children:[e.jsxs(A,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Life Force sync"}),e.jsx("div",{className:"mt-3 text-2xl font-display text-[var(--ui-ink-strong)]",children:_.data?`${U(_.data.spentTodayAp)} / ${U(_.data.dailyBudgetAp)}`:"Loading..."}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Habit check-ins debit the same Action Point ledger as work, notes, movement, and workouts."})]}),e.jsxs(A,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Instant headroom"}),e.jsx("div",{className:"mt-3 text-2xl font-display text-[var(--ui-ink-strong)]",children:_.data?Me(_.data.instantFreeApPerHour):"Loading..."}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Use this to tell whether now is a good moment for heavier habits or just a light check-in."})]}),e.jsxs(A,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Workout-linked load"}),e.jsx("div",{className:"mt-3 text-2xl font-display text-[var(--ui-ink-strong)]",children:U(Ge)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Habit-generated workout templates stay visible as Action Point cost instead of hiding behind the XP reward."})]})]}),z.isLoading?e.jsx(A,{children:"Loading habits..."}):n.length===0?e.jsx(js,{eyebrow:"Habits",title:"No recurring habits yet",description:"Create the recurring commitments or recurring slips you want Forge to track explicitly. Positive habits pay out when completed. Negative habits invert that logic.",action:e.jsx(L,{onClick:()=>{T(null),w(!0)},children:"Create habit"})}):e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4 shadow-[var(--ui-shadow-soft)] sm:flex-row sm:items-end sm:justify-between",children:[e.jsxs("div",{className:"max-w-xl",children:[e.jsx("div",{className:"text-sm font-medium text-[var(--ui-ink-strong)]",children:"Habit list order"}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:"Choose a stable ordering so the list does not reshuffle while you are logging check-ins."})]}),e.jsx(Hs,{label:"Order by",value:K,options:Xs,onChange:Ue,className:"w-full sm:w-[19rem]"})]}),e.jsx("div",{className:"grid gap-4 xl:grid-cols-2",children:n.map(a=>{const h=qe(a),u=Os(a.streakCount),$=u.Icon,re=Ke(),ie=xe(a),Qe=ws(s.snapshot.dashboard.notesSummaryByEntity,"habit",a.id).count,ne=a.polarity==="positive"?{label:"Done",status:Q(a,"aligned"),Icon:Ie,className:"border-[color-mix(in_srgb,var(--success)_34%,var(--ui-border-subtle)_66%)] bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)] shadow-[var(--ui-shadow-soft)] hover:bg-[color-mix(in_srgb,var(--success)_24%,var(--ui-surface-hover)_76%)]"}:{label:"Resisted",status:Q(a,"aligned"),Icon:Ce,className:"border-[color-mix(in_srgb,var(--success)_34%,var(--ui-border-subtle)_66%)] bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)] shadow-[var(--ui-shadow-soft)] hover:bg-[color-mix(in_srgb,var(--success)_24%,var(--ui-surface-hover)_76%)]"},le=a.polarity==="positive"?{label:"Missed",status:Q(a,"unaligned"),Icon:Pe,className:"border-[color-mix(in_srgb,var(--danger)_34%,var(--ui-border-subtle)_66%)] bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)] shadow-[var(--ui-shadow-soft)] hover:bg-[color-mix(in_srgb,var(--danger)_22%,var(--ui-surface-hover)_78%)]"}:{label:"Performed",status:Q(a,"unaligned"),Icon:as,className:"border-[color-mix(in_srgb,var(--danger)_34%,var(--ui-border-subtle)_66%)] bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)] shadow-[var(--ui-shadow-soft)] hover:bg-[color-mix(in_srgb,var(--danger)_22%,var(--ui-surface-hover)_78%)]"};return e.jsxs(A,{className:P("relative flex h-full flex-col overflow-hidden",h.cardClass,Ss(te===a.id)),"data-psyche-focus-id":a.id,children:[e.jsx("div",{className:P("pointer-events-none absolute inset-0 opacity-100",h.overlayClass)}),e.jsxs("div",{className:"relative z-10 flex h-full flex-col",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Fe,{kind:"habit",label:a.title,variant:"heading",size:"sm"}),e.jsx(_s,{user:a.user,compact:!0}),e.jsx(v,{className:se,children:a.status}),e.jsxs(v,{className:se,children:[e.jsx(Ve,{className:"mr-1 size-3.5"}),Rs(a)]}),e.jsx(v,{className:a.polarity==="positive"?Re:Oe,children:a.polarity==="positive"?"Positive":"Negative"}),a.dueToday?e.jsx(v,{className:ce,children:"Needs check-in"}):null,a.linkedGoalIds.slice(0,1).map(g=>{const l=s.snapshot.goals.find(x=>x.id===g);return l?e.jsxs(v,{className:ce,children:["Goal · ",l.title]},l.id):null}),a.linkedProjectIds.slice(0,1).map(g=>{const l=s.snapshot.dashboard.projects.find(x=>x.id===g);return l?e.jsxs(v,{className:be,children:["Project · ",l.title]},l.id):null}),a.linkedTaskIds.slice(0,1).map(g=>{const l=s.snapshot.tasks.find(x=>x.id===g);return l?e.jsxs(v,{className:ae,children:["Task · ",l.title]},l.id):null})]}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-medium)]",children:a.description?e.jsx(ds,{markdown:a.description,className:"[&>p]:text-sm [&>p]:leading-6 [&>blockquote]:text-sm [&>ul]:text-sm [&>ol]:text-sm"}):"No extra notes yet."})]}),e.jsxs("div",{className:"ml-auto inline-flex shrink-0 flex-col items-end gap-2 self-start text-right",children:[e.jsxs("div",{className:P("inline-flex flex-col self-end rounded-[20px] px-3 py-2.5 text-right",u.className),children:[e.jsxs("div",{className:"flex items-center justify-end gap-1.5 text-[10px] uppercase tracking-[0.16em]",children:[e.jsx("span",{children:"Streak"}),e.jsx($,{className:P("size-3.5 shrink-0",u.iconClass)})]}),e.jsx("div",{className:P("mt-1.5 font-display text-[2.75rem] leading-none",u.valueClass),children:a.streakCount}),e.jsx("div",{className:"mt-1 text-[11px] leading-tight text-[var(--ui-ink-soft)]",children:u.label})]}),e.jsxs("div",{className:"ml-auto grid grid-cols-2 gap-1.5",children:[e.jsx(L,{variant:"ghost",size:"sm",className:"h-7 min-w-0 rounded-[11px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",disabled:r.isPending,onClick:()=>{T(a),w(!0)},"aria-label":`Edit ${a.title}`,title:"Edit habit",children:e.jsx(es,{className:"size-4"})}),e.jsx(L,{variant:"ghost",size:"sm",className:"h-7 min-w-0 rounded-[11px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",disabled:t.isPending,onClick:()=>E(a),"aria-label":`Delete ${a.title}`,title:"Delete habit",children:e.jsx(ss,{className:"size-4"})})]})]})]}),e.jsxs("div",{className:"mt-auto grid gap-4 pt-5",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(v,{className:P("",zs(a.completionRate)),children:["Alignment ",a.completionRate,"%"]}),e.jsx(v,{className:se,children:a.polarity==="positive"?`+${a.rewardXp} XP done`:`+${a.rewardXp} XP resisted`}),e.jsx(v,{className:se,children:a.polarity==="positive"?`-${a.penaltyXp} XP missed`:`-${a.penaltyXp} XP performed`}),e.jsxs(v,{className:ae,children:[U(re.totalAp)," check-in"]}),ie?e.jsxs(v,{className:ce,children:[U(ie.totalAp)," ","workout"]}):null,ie?e.jsx(v,{className:se,children:Me(ie.rateApPerHour)}):null,e.jsx(os,{entityType:"habit",entityId:a.id,count:Qe,className:"min-h-8 rounded-full border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-1.5 text-[12px] text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-hover)]"}),a.linkedBehaviorTitles.slice(0,2).map(g=>e.jsxs(v,{className:ce,children:[e.jsx(Ce,{className:"mr-1 size-3.5"}),g]},g)),a.linkedProjectIds.slice(1,2).map(g=>{const l=s.snapshot.dashboard.projects.find(x=>x.id===g);return l?e.jsxs(v,{className:be,children:["Project · ",l.title]},l.id):null}),a.linkedTaskIds.slice(1,2).map(g=>{const l=s.snapshot.tasks.find(x=>x.id===g);return l?e.jsxs(v,{className:ae,children:["Task · ",l.title]},l.id):null}),a.linkedValueIds.slice(0,2).map(g=>{var x;const l=(x=I.data)==null?void 0:x.values.find(B=>B.id===g);return l?e.jsxs(v,{className:Re,children:["Value · ",l.title]},l.id):null}),a.linkedPatternIds.slice(0,2).map(g=>{var x;const l=(x=I.data)==null?void 0:x.patterns.find(B=>B.id===g);return l?e.jsxs(v,{className:be,children:["Pattern · ",l.title]},l.id):null}),a.linkedBeliefIds.slice(0,2).map(g=>{var x;const l=(x=I.data)==null?void 0:x.beliefs.find(B=>B.id===g);return l?e.jsxs(v,{className:Oe,children:["Belief · ",l.statement]},l.id):null}),a.linkedModeIds.slice(0,2).map(g=>{var x;const l=(x=I.data)==null?void 0:x.modes.find(B=>B.id===g);return l?e.jsxs(v,{className:ae,children:["Mode · ",l.title]},l.id):null}),a.linkedReportIds.slice(0,2).map(g=>{var x;const l=(x=I.data)==null?void 0:x.reports.find(B=>B.id===g);return l?e.jsxs(v,{className:ae,children:["Report · ",l.title]},l.id):null})]}),e.jsx("div",{className:"grid gap-4",children:e.jsx(Ws,{habit:a,onSelectCell:(g,l)=>{y({habit:g,cell:l}),S(null)}})}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsxs(L,{variant:"secondary",className:P("h-11 rounded-[16px] border",ne.className),disabled:i.isPending,onClick:()=>void i.mutateAsync({habitId:a.id,status:ne.status,dateKey:W(new Date)}),children:[e.jsx(ne.Icon,{className:"size-4"}),ne.label]}),e.jsxs(L,{variant:"secondary",className:P("h-11 rounded-[16px] border",le.className),disabled:i.isPending,onClick:()=>void i.mutateAsync({habitId:a.id,status:le.status,dateKey:W(new Date)}),children:[e.jsx(le.Icon,{className:"size-4"}),le.label]})]})]})]})]},a.id)})})]}),e.jsx(Fs,{open:M,pending:r.isPending,editingHabit:k,values:((ke=I.data)==null?void 0:ke.values)??[],patterns:((ye=I.data)==null?void 0:ye.patterns)??[],behaviors:((je=I.data)==null?void 0:je.behaviors)??[],beliefs:((we=I.data)==null?void 0:we.beliefs)??[],modes:((_e=I.data)==null?void 0:_e.modes)??[],reports:((Ne=I.data)==null?void 0:Ne.reports)??[],goals:s.snapshot.dashboard.goals,projects:s.snapshot.dashboard.projects,tasks:s.snapshot.tasks,users:s.snapshot.users,defaultUserId:(k==null?void 0:k.userId)??Z,onOpenChange:w,onSubmit:async(a,h)=>{try{await r.mutateAsync({input:a,habitId:h})}catch(u){throw u instanceof Ns,u}}}),e.jsx(Le,{open:N!==null,onOpenChange:a=>{!a&&!t.isPending&&E(null)},children:e.jsxs(Se,{children:[e.jsx(Te,{className:"surface-overlay fixed inset-0 z-40 backdrop-blur-xl"}),e.jsxs(He,{className:"surface-modal-panel fixed inset-x-4 top-1/2 z-50 mx-auto w-[min(30rem,calc(100vw-2rem))] max-w-[30rem] -translate-y-1/2 overflow-hidden rounded-[30px] border",children:[e.jsx("div",{className:"border-b border-[var(--ui-border-subtle)] px-5 py-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Delete habit"}),e.jsx(Ee,{className:"mt-2 text-lg font-semibold text-[var(--ui-ink-strong)]",children:(N==null?void 0:N.title)??"Delete this habit?"}),e.jsx(Ae,{className:"mt-3 text-sm text-[var(--ui-ink-soft)]",children:"Remove this habit from Forge. The habit card disappears immediately after delete succeeds."})]}),e.jsx(Be,{asChild:!0,children:e.jsx(L,{variant:"ghost",size:"sm",className:"h-10 w-10 rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-0 text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]","aria-label":"Close delete habit modal",title:"Close",disabled:t.isPending,children:e.jsx(De,{className:"size-4"})})})]})}),e.jsxs("div",{className:"grid gap-4 p-5",children:[e.jsx("div",{className:"rounded-[20px] border border-[color-mix(in_srgb,var(--danger)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-danger-soft)] px-4 py-3 text-sm leading-6 text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]",children:"This removes the habit and its check-in history from the habits page."}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-3",children:[e.jsx(L,{variant:"secondary",onClick:()=>E(null),disabled:t.isPending,children:"Cancel"}),e.jsx(L,{className:"border border-[color-mix(in_srgb,var(--danger)_34%,var(--ui-border-subtle)_66%)] bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)] hover:bg-[color-mix(in_srgb,var(--danger)_22%,var(--ui-surface-hover)_78%)]",pending:t.isPending,pendingLabel:"Deleting",onClick:()=>{N&&t.mutateAsync(N.id)},children:"Delete habit"})]})]})]})]})}),e.jsx(Le,{open:c!==null,onOpenChange:a=>{a||y(null)},children:e.jsxs(Se,{children:[e.jsx(Te,{className:"surface-overlay fixed inset-0 z-40 backdrop-blur-xl"}),e.jsxs(He,{className:"surface-modal-panel fixed inset-x-4 top-1/2 z-50 mx-auto w-[min(42rem,calc(100vw-2rem))] max-w-[42rem] -translate-y-1/2 overflow-hidden rounded-[30px] border",children:[e.jsx(Ee,{className:"sr-only",children:"Habit history"}),e.jsx(Ae,{className:"sr-only",children:"Log or revise a habit check-in for a selected history point."}),c&&V?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-b border-[var(--ui-border-subtle)] px-5 py-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Habit history"}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"text-lg font-semibold text-[var(--ui-ink-strong)]",children:c.habit.title}),e.jsx(v,{children:c.cell.actionLabel})]}),e.jsx("div",{className:"mt-3 text-sm text-[var(--ui-ink-soft)]",children:c.habit.frequency==="daily"?"Log or revise the check-in for this specific day.":"Log or revise the representative check-in for this week."})]}),e.jsx(Be,{asChild:!0,children:e.jsx(L,{variant:"ghost",size:"sm",className:"h-10 w-10 rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-0 text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]","aria-label":"Close history modal",title:"Close",children:e.jsx(De,{className:"size-4"})})})]})}),e.jsxs("div",{className:"grid gap-4 p-5",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("button",{type:"button","aria-pressed":m!==null&&Y(c.habit,m)==="aligned",className:P("rounded-[22px] border px-4 py-4 text-left transition",m!==null&&Y(c.habit,m)==="aligned"?"border-[color-mix(in_srgb,var(--success)_34%,var(--ui-border-subtle)_66%)] bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)] shadow-[var(--ui-shadow-soft)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-hover)]"),onClick:()=>j(a=>a!==null&&Y(c.habit,a)==="aligned"?null:Q(c.habit,"aligned")),children:[e.jsxs("div",{className:"flex items-center gap-2 text-base font-medium",children:[e.jsx(Ie,{className:"size-4"}),V.alignedLabel]}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:V.alignedDescription})]}),e.jsxs("button",{type:"button","aria-pressed":m!==null&&Y(c.habit,m)==="unaligned",className:P("rounded-[22px] border px-4 py-4 text-left transition",m!==null&&Y(c.habit,m)==="unaligned"?"border-[color-mix(in_srgb,var(--danger)_34%,var(--ui-border-subtle)_66%)] bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)] shadow-[var(--ui-shadow-soft)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-hover)]"),onClick:()=>j(a=>a!==null&&Y(c.habit,a)==="unaligned"?null:Q(c.habit,"unaligned")),children:[e.jsxs("div",{className:"flex items-center gap-2 text-base font-medium",children:[e.jsx(Pe,{className:"size-4"}),V.unalignedLabel]}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:V.unalignedDescription})]})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-[var(--ui-ink-strong)]",children:"Optional note"}),e.jsx(ve,{value:H,onChange:a=>D(a.target.value),placeholder:"Add context for what happened on this day or week.",className:"min-h-24"})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-3",children:[e.jsx(L,{variant:"secondary",onClick:()=>y(null),disabled:i.isPending,children:"Cancel"}),e.jsx(L,{disabled:i.isPending||!fe,pending:i.isPending,pendingLabel:"Saving",onClick:async()=>{fe&&(m===null?(await Cs(c.habit.id,c.cell.actionDateKey),await G()):await i.mutateAsync({habitId:c.habit.id,status:m,dateKey:c.cell.actionDateKey,note:H.trim()||void 0}),y(null))},children:"Save check-in"})]})]})]}):null]})]})})]})}export{oa as HabitsPage};
1
+ import{r as p,j as e,c2 as Ye,aG as Ze,cd as Je,aV as Ve,ce as es,c7 as ss,c5 as Ce,bO as Ie,cf as Pe,cg as as,aK as De,ch as ts,ci as rs,cj as is,ck as ns}from"./vendor-Dnkkx2co.js";import{R as Le,P as Se,O as Te,C as He,T as Ee,D as Ae,a as Be}from"./ui-C1iwpj2-.js";import{j as ls,i as me,k as ge}from"./state-vCcAT5Hq.js";import{E as os}from"./entity-note-count-link-ef3ZOpKM.js";import{N as ds}from"./note-markdown-CCyyE85h.js";import{Q as cs,$ as us,F as b,I as q,T as ve,a0 as ms,a1 as gs,j as oe,b as F,u as xs,a2 as hs,s as bs,a3 as vs,a4 as ps,a5 as fs,a6 as ks,a7 as xe,a8 as ys,B as L,V as Fe,C as A,h as U,d as Me,a as js,_ as ws,Z as P,U as _s,c as v,a9 as Ns,aa as Cs,ab as Ke,ac as Is,ad as Ps,O as Ds}from"./index-QJkjKYzZ.js";import{u as Ls,p as Ss}from"./use-psyche-focus-target-Ct-acS9G.js";import{P as Ts}from"./page-hero-CONuJu5J.js";import{S as Hs}from"./select-menu-Cqs5t3ng.js";import{f as Es}from"./date-keys-Cj1G3TOn.js";import"./motion-Lt5B1XuE.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";const he={title:"",description:"",status:"active",userId:null,polarity:"positive",frequency:"daily",targetCount:1,weekDays:[],linkedGoalIds:[],linkedProjectIds:[],linkedTaskIds:[],linkedValueIds:[],linkedPatternIds:[],linkedBehaviorIds:[],linkedBeliefIds:[],linkedModeIds:[],linkedReportIds:[],linkedBehaviorId:"",rewardXp:12,penaltyXp:8,generatedHealthEventTemplate:{enabled:!1,workoutType:"workout",title:"",durationMinutes:45,xpReward:0,tags:[],links:[],notesTemplate:""}},As=[{value:1,label:"Mon"},{value:2,label:"Tue"},{value:3,label:"Wed"},{value:4,label:"Thu"},{value:5,label:"Fri"},{value:6,label:"Sat"},{value:0,label:"Sun"}];function Bs(s){return{title:s.title,description:s.description,status:s.status,userId:s.userId??null,polarity:s.polarity,frequency:s.frequency,targetCount:s.targetCount,weekDays:s.weekDays,linkedGoalIds:s.linkedGoalIds,linkedProjectIds:s.linkedProjectIds,linkedTaskIds:s.linkedTaskIds,linkedValueIds:s.linkedValueIds,linkedPatternIds:s.linkedPatternIds,linkedBehaviorIds:s.linkedBehaviorIds,linkedBeliefIds:s.linkedBeliefIds,linkedModeIds:s.linkedModeIds,linkedReportIds:s.linkedReportIds,linkedBehaviorId:s.linkedBehaviorId??"",rewardXp:s.rewardXp,penaltyXp:s.penaltyXp,generatedHealthEventTemplate:s.generatedHealthEventTemplate}}function Fs({open:s,pending:o=!1,editingHabit:d,values:f,patterns:k,behaviors:T,beliefs:c,modes:y,reports:m,goals:j,projects:H,tasks:D,users:M,defaultUserId:w=null,onOpenChange:N,onSubmit:E}){const[R,S]=p.useState(he),[te,K]=p.useState(null),[C,Z]=p.useState({});p.useEffect(()=>{s&&(S(d?Bs(d):{...he,userId:w}),K(null),Z({}))},[w,d,s]);const O=M.find(r=>r.id===w)??null,z=p.useMemo(()=>T.slice().sort((r,i)=>r.title.localeCompare(i.title)),[T]),I=r=>({linkedBehaviorIds:r,linkedBehaviorId:r[0]??""}),_=(r,i)=>r.includes(i)?r.filter(t=>t!==i):[...r,i],G=[{id:"intent",eyebrow:"Habit",title:"Name the recurring move",description:"Use habits for recurring commitments and recurring slips. Keep the title concrete so the daily check-in never needs interpretation.",render:(r,i)=>e.jsxs(e.Fragment,{children:[e.jsx(b,{label:"Title",error:C.title??null,children:e.jsx(q,{value:r.title,onChange:t=>i({title:t.target.value}),placeholder:"Train lower body"})}),e.jsx(b,{label:"Description",children:e.jsx(ve,{value:r.description,onChange:t=>i({description:t.target.value}),placeholder:"Write the habit description in Markdown. Define what counts, edge cases, and examples."})}),e.jsx(ms,{value:r.userId,users:M,onChange:t=>i({userId:t}),label:"Owner user",defaultLabel:gs(O),help:"Habits can be owned by humans or bots. When one scoped user is active, Forge uses that as the default."})]})},{id:"shape",eyebrow:"Shape",title:"Set direction and cadence",description:"Forge uses polarity to decide whether doing the habit is good or bad, and cadence to know when it should show up.",render:(r,i)=>e.jsxs(e.Fragment,{children:[e.jsx(b,{label:"Polarity",children:e.jsx(oe,{value:r.polarity,onChange:t=>i({polarity:t}),options:[{value:"positive",label:"Positive",description:"Doing it is aligned and should award XP."},{value:"negative",label:"Negative",description:"Doing it is a slip and should cost XP."}],columns:2})}),e.jsx(b,{label:"Frequency",children:e.jsx(oe,{value:r.frequency,onChange:t=>i({frequency:t}),options:[{value:"daily",label:"Daily",description:"Track against each day."},{value:"weekly",label:"Weekly",description:"Track only on the selected weekdays."}],columns:2})}),r.frequency==="weekly"?e.jsx(b,{label:"Weekdays",error:C.weekDays??null,children:e.jsx("div",{className:"flex flex-wrap gap-2",children:As.map(t=>{const n=r.weekDays.includes(t.value);return e.jsx("button",{type:"button",className:`rounded-full border px-3 py-2 text-sm transition ${n?"border-[color-mix(in_srgb,var(--primary)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-accent-soft)] 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-hover)] hover:text-[var(--ui-ink-strong)]"}`,onClick:()=>i({weekDays:n?r.weekDays.filter(J=>J!==t.value):[...r.weekDays,t.value].sort()}),children:t.label},t.value)})})}):null,e.jsx(b,{label:"Status",children:e.jsx(oe,{value:r.status,onChange:t=>i({status:t}),options:[{value:"active",label:"Active",description:"Show it in the daily operating flow."},{value:"paused",label:"Paused",description:"Keep it visible but not currently due."},{value:"archived",label:"Archived",description:"Keep the record but retire it from active work."}]})})]})},{id:"generation",eyebrow:"Generation",title:"Decide whether this habit should create a workout record",description:"Use this when a completed habit should generate a structured sports or recovery session in Forge, then reconcile with HealthKit later if the same session gets imported.",render:(r,i)=>e.jsxs(e.Fragment,{children:[e.jsx(b,{label:"Generate workout record",children:e.jsx(oe,{value:r.generatedHealthEventTemplate.enabled?"enabled":"disabled",onChange:t=>i({generatedHealthEventTemplate:{...r.generatedHealthEventTemplate,enabled:t==="enabled"}}),options:[{value:"disabled",label:"Disabled",description:"This habit only affects the habit ledger."},{value:"enabled",label:"Enabled",description:"A completed check-in creates a workout or recovery session."}],columns:2})}),r.generatedHealthEventTemplate.enabled?e.jsxs(e.Fragment,{children:[e.jsx(b,{label:"Workout type",children:e.jsx(q,{value:r.generatedHealthEventTemplate.workoutType,onChange:t=>i({generatedHealthEventTemplate:{...r.generatedHealthEventTemplate,workoutType:t.target.value}}),placeholder:"mobility, walk, strength, recovery"})}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(b,{label:"Duration (minutes)",children:e.jsx(q,{type:"number",min:1,max:1440,value:r.generatedHealthEventTemplate.durationMinutes,onChange:t=>i({generatedHealthEventTemplate:{...r.generatedHealthEventTemplate,durationMinutes:Number(t.target.value)||45}})})}),e.jsx(b,{label:"Workout XP",children:e.jsx(q,{type:"number",min:0,max:500,value:r.generatedHealthEventTemplate.xpReward,onChange:t=>i({generatedHealthEventTemplate:{...r.generatedHealthEventTemplate,xpReward:Number(t.target.value)||0}})})})]}),e.jsx(b,{label:"Generated session note",children:e.jsx(ve,{value:r.generatedHealthEventTemplate.notesTemplate,onChange:t=>i({generatedHealthEventTemplate:{...r.generatedHealthEventTemplate,notesTemplate:t.target.value}}),placeholder:"Morning routine session generated from habit completion."})})]}):null]})},{id:"links",eyebrow:"Links",title:"Connect the habit to real Forge work",description:"Link habits to the goals, projects, and tasks they support so they stay anchored in the same operating graph as everything else.",render:(r,i)=>e.jsxs(e.Fragment,{children:[e.jsx(b,{label:"Goals",children:e.jsx("div",{className:"flex flex-wrap gap-2",children:j.map(t=>{const n=r.linkedGoalIds.includes(t.id);return e.jsx("button",{type:"button",onClick:()=>i({linkedGoalIds:_(r.linkedGoalIds,t.id)}),children:e.jsx(F,{kind:"goal",label:t.title,gradient:n,className:n?"":"opacity-75"})},t.id)})})}),e.jsx(b,{label:"Projects",children:e.jsx("div",{className:"flex flex-wrap gap-2",children:H.map(t=>{const n=r.linkedProjectIds.includes(t.id);return e.jsx("button",{type:"button",onClick:()=>i({linkedProjectIds:_(r.linkedProjectIds,t.id)}),children:e.jsx(F,{kind:"project",label:t.title,gradient:n,className:n?"":"opacity-75"})},t.id)})})}),e.jsx(b,{label:"Tasks",children:e.jsx("div",{className:"flex max-h-48 flex-wrap gap-2 overflow-y-auto",children:D.map(t=>{const n=r.linkedTaskIds.includes(t.id);return e.jsx("button",{type:"button",onClick:()=>i({linkedTaskIds:_(r.linkedTaskIds,t.id)}),children:e.jsx(F,{kind:"task",label:t.title,gradient:n,className:n?"":"opacity-75",wrap:!0})},t.id)})})}),e.jsx(b,{label:"Values",children:e.jsx("div",{className:"flex flex-wrap gap-2",children:f.map(t=>{const n=r.linkedValueIds.includes(t.id);return e.jsx("button",{type:"button",onClick:()=>i({linkedValueIds:_(r.linkedValueIds,t.id)}),children:e.jsx(F,{kind:"value",label:t.title,gradient:n,className:n?"":"opacity-75"})},t.id)})})}),e.jsx(b,{label:"Patterns",children:e.jsx("div",{className:"flex max-h-44 flex-wrap gap-2 overflow-y-auto",children:k.map(t=>{const n=r.linkedPatternIds.includes(t.id);return e.jsx("button",{type:"button",onClick:()=>i({linkedPatternIds:_(r.linkedPatternIds,t.id)}),children:e.jsx(F,{kind:"pattern",label:t.title,gradient:n,className:n?"":"opacity-75",wrap:!0})},t.id)})})})]})},{id:"reward",eyebrow:"Reward",title:"Link the behavior and XP logic",description:"Habits can point back to a Psyche behavior. Reward XP is granted for aligned outcomes; penalty XP is applied for misaligned ones.",render:(r,i)=>e.jsxs(e.Fragment,{children:[e.jsx(b,{label:"Linked behavior",children:e.jsx("div",{className:"flex max-h-44 flex-wrap gap-2 overflow-y-auto",children:z.map(t=>{const n=r.linkedBehaviorIds.includes(t.id);return e.jsx("button",{type:"button",onClick:()=>i(I(_(r.linkedBehaviorIds,t.id))),children:e.jsx(F,{kind:"behavior",label:t.title,gradient:n,className:n?"":"opacity-75",wrap:!0})},t.id)})})}),e.jsx(b,{label:"Beliefs",children:e.jsx("div",{className:"flex max-h-44 flex-wrap gap-2 overflow-y-auto",children:c.map(t=>{const n=r.linkedBeliefIds.includes(t.id);return e.jsx("button",{type:"button",onClick:()=>i({linkedBeliefIds:_(r.linkedBeliefIds,t.id)}),children:e.jsx(F,{kind:"belief",label:t.statement,gradient:n,className:n?"":"opacity-75",wrap:!0})},t.id)})})}),e.jsx(b,{label:"Modes",children:e.jsx("div",{className:"flex max-h-44 flex-wrap gap-2 overflow-y-auto",children:y.map(t=>{const n=r.linkedModeIds.includes(t.id);return e.jsx("button",{type:"button",onClick:()=>i({linkedModeIds:_(r.linkedModeIds,t.id)}),children:e.jsx(F,{kind:"mode",label:t.title,gradient:n,className:n?"":"opacity-75",wrap:!0})},t.id)})})}),e.jsx(b,{label:"Reports",children:e.jsx("div",{className:"flex max-h-44 flex-wrap gap-2 overflow-y-auto",children:m.map(t=>{const n=r.linkedReportIds.includes(t.id);return e.jsx("button",{type:"button",onClick:()=>i({linkedReportIds:_(r.linkedReportIds,t.id)}),children:e.jsx(F,{kind:"report",label:t.title,gradient:n,className:n?"":"opacity-75",wrap:!0})},t.id)})})}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-3",children:[e.jsx(b,{label:"Target count",error:C.targetCount??null,children:e.jsx(q,{type:"number",value:r.targetCount,onChange:t=>i({targetCount:Number(t.target.value)||1})})}),e.jsx(b,{label:"Reward XP",error:C.rewardXp??null,children:e.jsx(q,{type:"number",value:r.rewardXp,onChange:t=>i({rewardXp:Number(t.target.value)||1})})}),e.jsx(b,{label:"Penalty XP",error:C.penaltyXp??null,children:e.jsx(q,{type:"number",value:r.penaltyXp,onChange:t=>i({penaltyXp:Number(t.target.value)||1})})})]})]})}];return e.jsx(cs,{open:s,onOpenChange:N,eyebrow:"Habit",title:d?"Edit habit":"Create habit",description:"Habits are recurring commitments or recurring slips with explicit XP consequences.",value:R,onChange:S,draftPersistenceKey:d?`habit.${d.id}`:"habit.new",steps:G,pending:o,pendingLabel:d?"Save habit":"Create habit",submitLabel:d?"Save habit":"Create habit",error:te,onSubmit:async()=>{K(null);const r=us.safeParse(R);if(!r.success){Z(Object.fromEntries(Object.entries(r.error.flatten().fieldErrors).map(([i,t])=>[i,t==null?void 0:t[0]]))),K("Some habit fields still need attention.");return}Z({});try{await E(r.data,d==null?void 0:d.id),S(he),N(!1)}catch(i){K(i instanceof Error?i.message:"Habit update failed.")}}})}const Ms=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Ks=["S","M","T","W","T","F","S"],Xs=[{value:"name",label:"Name A-Z",description:"Keep the list stable alphabetically."},{value:"needs_attention",label:"Needs attention",description:"Bubble up habits still waiting on today."},{value:"streak",label:"Longest streak",description:"Put the strongest current streaks first."},{value:"created_at",label:"Newest created",description:"Show the most recently created habits first."},{value:"updated_at",label:"Recently updated",description:"Sort by the most recently changed habits."}];function Rs(s){return s.frequency==="daily"?`${s.targetCount}x daily`:`${s.targetCount}x weekly · ${s.weekDays.map(o=>Ms[o]).join(", ")}`}function W(s){return Es(s)}function ze(s){const[o,d,f]=s.split("-").map(Number);return new Date(o,d-1,f)}function $e(s){return new Date(s.getFullYear(),s.getMonth(),s.getDate())}function de(s,o){const d=new Date(s);return d.setDate(d.getDate()+o),d}function Xe(s){const o=$e(s),d=(o.getDay()+6)%7;return o.setDate(o.getDate()-d),o}function ee(s){const o=typeof s=="string"?ze(s):s;return new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric"}).format(o)}function ue(s,o){return s.polarity==="positive"&&o==="done"||s.polarity==="negative"&&o==="missed"}function pe(s,o){return s.polarity==="positive"?o==="done"?"Done":"Missed":o==="done"?"Performed":"Resisted"}function qe(s){const o=W(new Date),d=s.checkIns.find(f=>f.dateKey===o)??null;return s.dueToday?{tone:"pending",label:s.frequency==="daily"?"Waiting for today":"Awaiting this week's check-in",cardClass:"border-[color-mix(in_srgb,var(--warning)_28%,var(--ui-border-subtle)_72%)] shadow-[var(--ui-shadow-soft)]",overlayClass:"bg-[radial-gradient(circle_at_top_right,color-mix(in_srgb,var(--warning)_18%,transparent),transparent_44%)]",pillClass:"border border-[color-mix(in_srgb,var(--warning)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]"}:d?ue(s,d.status)?{tone:"aligned",label:`${pe(s,d.status)} today`,cardClass:"border-[color-mix(in_srgb,var(--success)_24%,var(--ui-border-subtle)_76%)] shadow-[var(--ui-shadow-soft)]",overlayClass:"bg-[radial-gradient(circle_at_top_right,color-mix(in_srgb,var(--success)_16%,transparent),transparent_44%)]",pillClass:"border border-[color-mix(in_srgb,var(--success)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)]"}:{tone:"unaligned",label:`${pe(s,d.status)} today`,cardClass:"border-[color-mix(in_srgb,var(--danger)_24%,var(--ui-border-subtle)_76%)] shadow-[var(--ui-shadow-soft)]",overlayClass:"bg-[radial-gradient(circle_at_top_right,color-mix(in_srgb,var(--danger)_16%,transparent),transparent_44%)]",pillClass:"border border-[color-mix(in_srgb,var(--danger)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]"}:s.polarity==="positive"?{tone:"neutral",label:"No update due right now",cardClass:"",overlayClass:"bg-[radial-gradient(circle_at_top_right,color-mix(in_srgb,var(--success)_9%,transparent),transparent_40%)]",pillClass:"border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]"}:{tone:"neutral",label:"No update due right now",cardClass:"",overlayClass:"bg-[radial-gradient(circle_at_top_right,color-mix(in_srgb,var(--danger)_9%,transparent),transparent_40%)]",pillClass:"border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]"}}function Os(s){return s>=10?{Icon:ts,className:"border border-[color-mix(in_srgb,var(--warning)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)] shadow-[var(--ui-shadow-soft)]",iconClass:"text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]",valueClass:"text-[var(--ui-ink-strong)]",label:"Celebration pace"}:s>=5?{Icon:rs,className:"border border-[color-mix(in_srgb,var(--success)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)] shadow-[var(--ui-shadow-soft)]",iconClass:"text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)]",valueClass:"text-[var(--ui-ink-strong)]",label:"Locked in"}:s>=1?{Icon:is,className:"border border-[color-mix(in_srgb,var(--info)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_76%,var(--ui-ink-strong)_24%)] shadow-[var(--ui-shadow-soft)]",iconClass:"text-[color-mix(in_srgb,var(--info)_76%,var(--ui-ink-strong)_24%)]",valueClass:"text-[var(--ui-ink-strong)]",label:"Building rhythm"}:{Icon:ns,className:"border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)] shadow-[var(--ui-shadow-soft)]",iconClass:"text-[var(--ui-ink-soft)]",valueClass:"text-[var(--ui-ink-strong)]",label:"Cold start"}}function zs(s){return s>=80?"border-[color-mix(in_srgb,var(--success)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)]":s>=50?"border-[color-mix(in_srgb,var(--warning)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]":"border-[color-mix(in_srgb,var(--danger)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]"}const se="border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",Re="border-[color-mix(in_srgb,var(--success)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)]",Oe="border-[color-mix(in_srgb,var(--danger)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]",ce="border-[color-mix(in_srgb,var(--warning)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]",be="border-[color-mix(in_srgb,var(--info)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_76%,var(--ui-ink-strong)_24%)]",ae="border-[color-mix(in_srgb,var(--primary)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-accent-soft)] text-[color-mix(in_srgb,var(--primary)_72%,var(--ui-ink-strong)_28%)]";function $s(s){var T;const o=new Date;if(s.frequency==="daily"){const c=$e(o),y=[];for(let m=-6;m<=0;m+=1){const j=de(c,m),H=W(j),D=s.checkIns.find(N=>N.dateKey===H)??null,M=Ks[j.getDay()],w=m===0;y.push({id:H,label:M,current:w,actionDateKey:H,actionLabel:ee(j),state:D?ue(s,D.status)?"aligned":"unaligned":"unknown",title:`${ee(j)} · ${D?pe(s,D.status):"Not informed"}`})}return{caption:"7-day rhythm",rangeLabel:"Past 7 days",showLabels:!0,startLabel:"",endLabel:"",cells:y}}const d=Xe(o),f=new Map;for(const c of s.checkIns){const y=W(Xe(ze(c.dateKey))),m=f.get(y)??[];m.push(c),f.set(y,m)}const k=[];for(let c=-6;c<=0;c+=1){const y=de(d,c*7),m=W(y),j=f.get(m)??[],H=s.weekDays.length>0?[...s.weekDays].sort((E,R)=>R-E)[0]:0,D=W(de(y,H)),M=((T=j[0])==null?void 0:T.dateKey)??D,w=j.filter(E=>ue(s,E.status)).length,N=j.length-w;k.push({id:m,label:"",current:c===0,actionDateKey:M,actionLabel:`Week of ${ee(y)}`,state:j.length===0?"unknown":w>=N?"aligned":"unaligned",title:`${ee(y)} week · ${j.length===0?"Not informed":w>=N?"Mostly aligned":"Mostly off track"}`})}return{caption:"7-week rhythm",rangeLabel:"Past 7 weeks",showLabels:!1,startLabel:ee(de(d,-42)),endLabel:"This week",cells:k}}function qs(s,o){return P("h-8 w-full rounded-[10px] border transition",s==="aligned"&&"border-[color-mix(in_srgb,var(--success)_30%,var(--ui-border-subtle)_70%)] bg-[color-mix(in_srgb,var(--success)_58%,var(--ui-surface-1)_42%)] shadow-[var(--ui-shadow-soft)]",s==="unaligned"&&"border-[color-mix(in_srgb,var(--danger)_30%,var(--ui-border-subtle)_70%)] bg-[color-mix(in_srgb,var(--danger)_54%,var(--ui-surface-1)_46%)] shadow-[var(--ui-shadow-soft)]",s==="unknown"&&"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",o&&"ring-1 ring-[color-mix(in_srgb,var(--primary)_34%,transparent)]")}function Ws({habit:s,onSelectCell:o}){const d=$s(s),f=qe(s);return e.jsxs("div",{className:"w-full rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-2.5 shadow-[var(--ui-shadow-soft)]",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"shrink-0",children:[e.jsx("div",{className:"font-label text-[10px] uppercase tracking-[0.16em] text-[var(--ui-ink-muted)]",children:d.caption}),e.jsx("div",{className:"text-[11px] text-[var(--ui-ink-soft)]",children:d.rangeLabel})]}),e.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:d.cells.map(k=>e.jsxs("button",{type:"button",className:"group flex min-w-0 flex-1 items-center gap-1 rounded-[10px] transition hover:bg-[var(--ui-surface-hover)]",onClick:()=>o(s,k),title:`Log check-in for ${k.actionLabel}`,"aria-label":`Log check-in for ${k.actionLabel}`,children:[e.jsx("div",{className:P(qs(k.state,k.current),"h-6 min-w-0 flex-1 rounded-[8px] transition duration-150 group-hover:-translate-y-0.5 group-hover:shadow-[var(--ui-shadow-soft)]")}),d.showLabels?e.jsx("span",{className:"hidden text-[9px] uppercase tracking-[0.14em] text-[var(--ui-ink-muted)] transition group-hover:text-[var(--ui-ink-medium)] sm:inline",children:k.label}):null]},k.id))}),e.jsx("div",{className:P("shrink-0 rounded-full px-2.5 py-1 text-[10px] font-medium",f.pillClass),children:f.label})]}),d.showLabels?null:e.jsxs("div",{className:"mt-1 text-right text-[10px] uppercase tracking-[0.14em] text-[var(--ui-ink-muted)]",children:[d.startLabel," - ",d.endLabel]})]})}function Gs(s){return s.polarity==="positive"?{alignedLabel:"Done",alignedDescription:"Log that the intended habit happened.",unalignedLabel:"Missed",unalignedDescription:"Log that the habit did not happen."}:{alignedLabel:"Resisted",alignedDescription:"Log that the unwanted behavior was resisted.",unalignedLabel:"Performed",unalignedDescription:"Log that the unwanted behavior happened."}}function Q(s,o){return s.polarity==="positive"?o==="aligned"?"done":"missed":o==="aligned"?"missed":"done"}function Y(s,o){return ue(s,o)?"aligned":"unaligned"}function oa(){var ke,ye,je,we,_e,Ne;const s=xs(),o=ls(),[d,f]=Ye(),[k,T]=p.useState(null),[c,y]=p.useState(null),[m,j]=p.useState(null),[H,D]=p.useState(""),[M,w]=p.useState(!1),[N,E]=p.useState(null),[R,S]=p.useState(null),te=d.get("focus"),K=d.get("orderBy")??"name",C=hs(s.selectedUserIds),Z=bs(C),O=["forge-habits",K,...C];Ls(te);const z=me({queryKey:O,queryFn:async()=>(await Is({userIds:C,orderBy:K})).habits}),I=me({queryKey:["forge-psyche-overview",...C],queryFn:async()=>(await Ps(C)).overview}),_=me({queryKey:["forge-life-force",...C],queryFn:async()=>(await Ds(C)).lifeForce});p.useEffect(()=>{d.get("create")==="1"&&(T(null),w(!0),f(a=>{const h=new URLSearchParams(a);return h.delete("create"),h},{replace:!0}))},[d,f]);const G=async()=>{await o.invalidateQueries({queryKey:["forge-habits"]}),await s.refresh()},r=ge({mutationFn:async({input:a,habitId:h})=>h?(await vs(h,a)).habit:(await ps(a)).habit,onSuccess:async()=>{S(null),await G()},onError:a=>{S(a instanceof Error?a.message:"Habit save failed.")}}),i=ge({mutationFn:async({habitId:a,status:h,dateKey:u,note:$})=>fs(a,{status:h,dateKey:u,note:$}),onSuccess:async()=>{S(null),await G()},onError:a=>{S(a instanceof Error?a.message:"Habit check-in failed.")}}),t=ge({mutationFn:async a=>ks(a),onMutate:async a=>{await o.cancelQueries({queryKey:O});const h=o.getQueryData(O);return o.setQueryData(O,u=>(u==null?void 0:u.filter($=>$.id!==a))??[]),{previousHabits:h}},onSuccess:async()=>{S(null),E(null),await G()},onError:(a,h,u)=>{u!=null&&u.previousHabits&&o.setQueryData(O,u.previousHabits),S(a instanceof Error?a.message:"Habit delete failed.")}}),n=p.useMemo(()=>(z.data??[]).filter(a=>a.status!=="archived"),[z.data]),J=p.useMemo(()=>n.filter(a=>a.dueToday),[n]),We=p.useMemo(()=>J.reduce((a,h)=>{var re;const u=Ke().totalAp,$=((re=xe(h))==null?void 0:re.totalAp)??0;return a+u+$},0),[J]),Ge=p.useMemo(()=>n.reduce((a,h)=>{var u;return a+(((u=xe(h))==null?void 0:u.totalAp)??0)},0),[n]),X=p.useMemo(()=>c?c.habit.checkIns.find(a=>a.dateKey===c.cell.actionDateKey)??null:null,[c]);if(p.useEffect(()=>{if(!c){j(null),D("");return}j((X==null?void 0:X.status)??null),D((X==null?void 0:X.note)??"")},[c,X]),z.error)throw z.error;const Ue=a=>{f(h=>{const u=new URLSearchParams(h);return a==="name"?u.delete("orderBy"):u.set("orderBy",a),u},{replace:!0})},V=c?Gs(c.habit):null,fe=m==="done"||m==="missed"||X!==null;return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(Ts,{entityKind:"habit",title:e.jsx(Fe,{kind:"habit",label:"Habits",variant:"heading",size:"lg"}),titleText:"Habits",description:"Habits track recurring commitments and recurring slips with explicit daily consequences, linked behaviors, and real XP movement.",badge:`${n.length} habits`,actions:e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[e.jsx(ys,{metrics:s.snapshot.metrics}),e.jsxs(L,{onClick:()=>{T(null),w(!0)},children:[e.jsx(Ze,{className:"size-4"}),"New habit"]})]})}),R?e.jsx(A,{className:"border-[color-mix(in_srgb,var(--danger)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Je,{className:"mt-0.5 size-4 shrink-0"}),e.jsx("div",{children:R})]})}):null,e.jsxs("section",{className:"grid gap-4 lg:grid-cols-4",children:[e.jsxs(A,{className:"border-[color-mix(in_srgb,var(--warning)_22%,var(--ui-border-subtle)_78%)] shadow-[var(--ui-shadow-soft)]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Due today"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--primary)]",children:J.length}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Habits that still need a check-in today."})]}),e.jsxs(A,{className:"border-[color-mix(in_srgb,var(--primary)_22%,var(--ui-border-subtle)_78%)] shadow-[var(--ui-shadow-soft)]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Habit AP due"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--primary)]",children:U(We)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Default Action Point load if every due habit is logged today."})]}),e.jsxs(A,{className:"border-[color-mix(in_srgb,var(--success)_22%,var(--ui-border-subtle)_78%)] shadow-[var(--ui-shadow-soft)]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Best streak"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)]",children:Math.max(0,...n.map(a=>a.streakCount))}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Longest current aligned streak across active habits."})]}),e.jsxs(A,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Average alignment"}),e.jsxs("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:[n.length>0?Math.round(n.reduce((a,h)=>a+h.completionRate,0)/n.length):0,"%"]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Share of recent habit check-ins that matched the intended direction."})]})]}),e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)]",children:[e.jsxs(A,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Life Force sync"}),e.jsx("div",{className:"mt-3 text-2xl font-display text-[var(--ui-ink-strong)]",children:_.data?`${U(_.data.spentTodayAp)} / ${U(_.data.dailyBudgetAp)}`:"Loading..."}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Habit check-ins debit the same Action Point ledger as work, notes, movement, and workouts."})]}),e.jsxs(A,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Instant headroom"}),e.jsx("div",{className:"mt-3 text-2xl font-display text-[var(--ui-ink-strong)]",children:_.data?Me(_.data.instantFreeApPerHour):"Loading..."}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Use this to tell whether now is a good moment for heavier habits or just a light check-in."})]}),e.jsxs(A,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Workout-linked load"}),e.jsx("div",{className:"mt-3 text-2xl font-display text-[var(--ui-ink-strong)]",children:U(Ge)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Habit-generated workout templates stay visible as Action Point cost instead of hiding behind the XP reward."})]})]}),z.isLoading?e.jsx(A,{children:"Loading habits..."}):n.length===0?e.jsx(js,{eyebrow:"Habits",title:"No recurring habits yet",description:"Create the recurring commitments or recurring slips you want Forge to track explicitly. Positive habits pay out when completed. Negative habits invert that logic.",action:e.jsx(L,{onClick:()=>{T(null),w(!0)},children:"Create habit"})}):e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4 shadow-[var(--ui-shadow-soft)] sm:flex-row sm:items-end sm:justify-between",children:[e.jsxs("div",{className:"max-w-xl",children:[e.jsx("div",{className:"text-sm font-medium text-[var(--ui-ink-strong)]",children:"Habit list order"}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:"Choose a stable ordering so the list does not reshuffle while you are logging check-ins."})]}),e.jsx(Hs,{label:"Order by",value:K,options:Xs,onChange:Ue,className:"w-full sm:w-[19rem]"})]}),e.jsx("div",{className:"grid gap-4 xl:grid-cols-2",children:n.map(a=>{const h=qe(a),u=Os(a.streakCount),$=u.Icon,re=Ke(),ie=xe(a),Qe=ws(s.snapshot.dashboard.notesSummaryByEntity,"habit",a.id).count,ne=a.polarity==="positive"?{label:"Done",status:Q(a,"aligned"),Icon:Ie,className:"border-[color-mix(in_srgb,var(--success)_34%,var(--ui-border-subtle)_66%)] bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)] shadow-[var(--ui-shadow-soft)] hover:bg-[color-mix(in_srgb,var(--success)_24%,var(--ui-surface-hover)_76%)]"}:{label:"Resisted",status:Q(a,"aligned"),Icon:Ce,className:"border-[color-mix(in_srgb,var(--success)_34%,var(--ui-border-subtle)_66%)] bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)] shadow-[var(--ui-shadow-soft)] hover:bg-[color-mix(in_srgb,var(--success)_24%,var(--ui-surface-hover)_76%)]"},le=a.polarity==="positive"?{label:"Missed",status:Q(a,"unaligned"),Icon:Pe,className:"border-[color-mix(in_srgb,var(--danger)_34%,var(--ui-border-subtle)_66%)] bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)] shadow-[var(--ui-shadow-soft)] hover:bg-[color-mix(in_srgb,var(--danger)_22%,var(--ui-surface-hover)_78%)]"}:{label:"Performed",status:Q(a,"unaligned"),Icon:as,className:"border-[color-mix(in_srgb,var(--danger)_34%,var(--ui-border-subtle)_66%)] bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)] shadow-[var(--ui-shadow-soft)] hover:bg-[color-mix(in_srgb,var(--danger)_22%,var(--ui-surface-hover)_78%)]"};return e.jsxs(A,{className:P("relative flex h-full flex-col overflow-hidden",h.cardClass,Ss(te===a.id)),"data-psyche-focus-id":a.id,children:[e.jsx("div",{className:P("pointer-events-none absolute inset-0 opacity-100",h.overlayClass)}),e.jsxs("div",{className:"relative z-10 flex h-full flex-col",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Fe,{kind:"habit",label:a.title,variant:"heading",size:"sm"}),e.jsx(_s,{user:a.user,compact:!0}),e.jsx(v,{className:se,children:a.status}),e.jsxs(v,{className:se,children:[e.jsx(Ve,{className:"mr-1 size-3.5"}),Rs(a)]}),e.jsx(v,{className:a.polarity==="positive"?Re:Oe,children:a.polarity==="positive"?"Positive":"Negative"}),a.dueToday?e.jsx(v,{className:ce,children:"Needs check-in"}):null,a.linkedGoalIds.slice(0,1).map(g=>{const l=s.snapshot.goals.find(x=>x.id===g);return l?e.jsxs(v,{className:ce,children:["Goal · ",l.title]},l.id):null}),a.linkedProjectIds.slice(0,1).map(g=>{const l=s.snapshot.dashboard.projects.find(x=>x.id===g);return l?e.jsxs(v,{className:be,children:["Project · ",l.title]},l.id):null}),a.linkedTaskIds.slice(0,1).map(g=>{const l=s.snapshot.tasks.find(x=>x.id===g);return l?e.jsxs(v,{className:ae,children:["Task · ",l.title]},l.id):null})]}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-medium)]",children:a.description?e.jsx(ds,{markdown:a.description,className:"[&>p]:text-sm [&>p]:leading-6 [&>blockquote]:text-sm [&>ul]:text-sm [&>ol]:text-sm"}):"No extra notes yet."})]}),e.jsxs("div",{className:"ml-auto inline-flex shrink-0 flex-col items-end gap-2 self-start text-right",children:[e.jsxs("div",{className:P("inline-flex flex-col self-end rounded-[20px] px-3 py-2.5 text-right",u.className),children:[e.jsxs("div",{className:"flex items-center justify-end gap-1.5 text-[10px] uppercase tracking-[0.16em]",children:[e.jsx("span",{children:"Streak"}),e.jsx($,{className:P("size-3.5 shrink-0",u.iconClass)})]}),e.jsx("div",{className:P("mt-1.5 font-display text-[2.75rem] leading-none",u.valueClass),children:a.streakCount}),e.jsx("div",{className:"mt-1 text-[11px] leading-tight text-[var(--ui-ink-soft)]",children:u.label})]}),e.jsxs("div",{className:"ml-auto grid grid-cols-2 gap-1.5",children:[e.jsx(L,{variant:"ghost",size:"sm",className:"h-7 min-w-0 rounded-[11px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",disabled:r.isPending,onClick:()=>{T(a),w(!0)},"aria-label":`Edit ${a.title}`,title:"Edit habit",children:e.jsx(es,{className:"size-4"})}),e.jsx(L,{variant:"ghost",size:"sm",className:"h-7 min-w-0 rounded-[11px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",disabled:t.isPending,onClick:()=>E(a),"aria-label":`Delete ${a.title}`,title:"Delete habit",children:e.jsx(ss,{className:"size-4"})})]})]})]}),e.jsxs("div",{className:"mt-auto grid gap-4 pt-5",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(v,{className:P("",zs(a.completionRate)),children:["Alignment ",a.completionRate,"%"]}),e.jsx(v,{className:se,children:a.polarity==="positive"?`+${a.rewardXp} XP done`:`+${a.rewardXp} XP resisted`}),e.jsx(v,{className:se,children:a.polarity==="positive"?`-${a.penaltyXp} XP missed`:`-${a.penaltyXp} XP performed`}),e.jsxs(v,{className:ae,children:[U(re.totalAp)," check-in"]}),ie?e.jsxs(v,{className:ce,children:[U(ie.totalAp)," ","workout"]}):null,ie?e.jsx(v,{className:se,children:Me(ie.rateApPerHour)}):null,e.jsx(os,{entityType:"habit",entityId:a.id,count:Qe,className:"min-h-8 rounded-full border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-1.5 text-[12px] text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-hover)]"}),a.linkedBehaviorTitles.slice(0,2).map(g=>e.jsxs(v,{className:ce,children:[e.jsx(Ce,{className:"mr-1 size-3.5"}),g]},g)),a.linkedProjectIds.slice(1,2).map(g=>{const l=s.snapshot.dashboard.projects.find(x=>x.id===g);return l?e.jsxs(v,{className:be,children:["Project · ",l.title]},l.id):null}),a.linkedTaskIds.slice(1,2).map(g=>{const l=s.snapshot.tasks.find(x=>x.id===g);return l?e.jsxs(v,{className:ae,children:["Task · ",l.title]},l.id):null}),a.linkedValueIds.slice(0,2).map(g=>{var x;const l=(x=I.data)==null?void 0:x.values.find(B=>B.id===g);return l?e.jsxs(v,{className:Re,children:["Value · ",l.title]},l.id):null}),a.linkedPatternIds.slice(0,2).map(g=>{var x;const l=(x=I.data)==null?void 0:x.patterns.find(B=>B.id===g);return l?e.jsxs(v,{className:be,children:["Pattern · ",l.title]},l.id):null}),a.linkedBeliefIds.slice(0,2).map(g=>{var x;const l=(x=I.data)==null?void 0:x.beliefs.find(B=>B.id===g);return l?e.jsxs(v,{className:Oe,children:["Belief · ",l.statement]},l.id):null}),a.linkedModeIds.slice(0,2).map(g=>{var x;const l=(x=I.data)==null?void 0:x.modes.find(B=>B.id===g);return l?e.jsxs(v,{className:ae,children:["Mode · ",l.title]},l.id):null}),a.linkedReportIds.slice(0,2).map(g=>{var x;const l=(x=I.data)==null?void 0:x.reports.find(B=>B.id===g);return l?e.jsxs(v,{className:ae,children:["Report · ",l.title]},l.id):null})]}),e.jsx("div",{className:"grid gap-4",children:e.jsx(Ws,{habit:a,onSelectCell:(g,l)=>{y({habit:g,cell:l}),S(null)}})}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsxs(L,{variant:"secondary",className:P("h-11 rounded-[16px] border",ne.className),disabled:i.isPending,onClick:()=>void i.mutateAsync({habitId:a.id,status:ne.status,dateKey:W(new Date)}),children:[e.jsx(ne.Icon,{className:"size-4"}),ne.label]}),e.jsxs(L,{variant:"secondary",className:P("h-11 rounded-[16px] border",le.className),disabled:i.isPending,onClick:()=>void i.mutateAsync({habitId:a.id,status:le.status,dateKey:W(new Date)}),children:[e.jsx(le.Icon,{className:"size-4"}),le.label]})]})]})]})]},a.id)})})]}),e.jsx(Fs,{open:M,pending:r.isPending,editingHabit:k,values:((ke=I.data)==null?void 0:ke.values)??[],patterns:((ye=I.data)==null?void 0:ye.patterns)??[],behaviors:((je=I.data)==null?void 0:je.behaviors)??[],beliefs:((we=I.data)==null?void 0:we.beliefs)??[],modes:((_e=I.data)==null?void 0:_e.modes)??[],reports:((Ne=I.data)==null?void 0:Ne.reports)??[],goals:s.snapshot.dashboard.goals,projects:s.snapshot.dashboard.projects,tasks:s.snapshot.tasks,users:s.snapshot.users,defaultUserId:(k==null?void 0:k.userId)??Z,onOpenChange:w,onSubmit:async(a,h)=>{try{await r.mutateAsync({input:a,habitId:h})}catch(u){throw u instanceof Ns,u}}}),e.jsx(Le,{open:N!==null,onOpenChange:a=>{!a&&!t.isPending&&E(null)},children:e.jsxs(Se,{children:[e.jsx(Te,{className:"surface-overlay fixed inset-0 z-40 backdrop-blur-xl"}),e.jsxs(He,{className:"surface-modal-panel fixed inset-x-4 top-1/2 z-50 mx-auto w-[min(30rem,calc(100vw-2rem))] max-w-[30rem] -translate-y-1/2 overflow-hidden rounded-[30px] border",children:[e.jsx("div",{className:"border-b border-[var(--ui-border-subtle)] px-5 py-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Delete habit"}),e.jsx(Ee,{className:"mt-2 text-lg font-semibold text-[var(--ui-ink-strong)]",children:(N==null?void 0:N.title)??"Delete this habit?"}),e.jsx(Ae,{className:"mt-3 text-sm text-[var(--ui-ink-soft)]",children:"Remove this habit from Forge. The habit card disappears immediately after delete succeeds."})]}),e.jsx(Be,{asChild:!0,children:e.jsx(L,{variant:"ghost",size:"sm",className:"h-10 w-10 rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-0 text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]","aria-label":"Close delete habit modal",title:"Close",disabled:t.isPending,children:e.jsx(De,{className:"size-4"})})})]})}),e.jsxs("div",{className:"grid gap-4 p-5",children:[e.jsx("div",{className:"rounded-[20px] border border-[color-mix(in_srgb,var(--danger)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-danger-soft)] px-4 py-3 text-sm leading-6 text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]",children:"This removes the habit and its check-in history from the habits page."}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-3",children:[e.jsx(L,{variant:"secondary",onClick:()=>E(null),disabled:t.isPending,children:"Cancel"}),e.jsx(L,{className:"border border-[color-mix(in_srgb,var(--danger)_34%,var(--ui-border-subtle)_66%)] bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)] hover:bg-[color-mix(in_srgb,var(--danger)_22%,var(--ui-surface-hover)_78%)]",pending:t.isPending,pendingLabel:"Deleting",onClick:()=>{N&&t.mutateAsync(N.id)},children:"Delete habit"})]})]})]})]})}),e.jsx(Le,{open:c!==null,onOpenChange:a=>{a||y(null)},children:e.jsxs(Se,{children:[e.jsx(Te,{className:"surface-overlay fixed inset-0 z-40 backdrop-blur-xl"}),e.jsxs(He,{className:"surface-modal-panel fixed inset-x-4 top-1/2 z-50 mx-auto w-[min(42rem,calc(100vw-2rem))] max-w-[42rem] -translate-y-1/2 overflow-hidden rounded-[30px] border",children:[e.jsx(Ee,{className:"sr-only",children:"Habit history"}),e.jsx(Ae,{className:"sr-only",children:"Log or revise a habit check-in for a selected history point."}),c&&V?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-b border-[var(--ui-border-subtle)] px-5 py-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Habit history"}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"text-lg font-semibold text-[var(--ui-ink-strong)]",children:c.habit.title}),e.jsx(v,{children:c.cell.actionLabel})]}),e.jsx("div",{className:"mt-3 text-sm text-[var(--ui-ink-soft)]",children:c.habit.frequency==="daily"?"Log or revise the check-in for this specific day.":"Log or revise the representative check-in for this week."})]}),e.jsx(Be,{asChild:!0,children:e.jsx(L,{variant:"ghost",size:"sm",className:"h-10 w-10 rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-0 text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]","aria-label":"Close history modal",title:"Close",children:e.jsx(De,{className:"size-4"})})})]})}),e.jsxs("div",{className:"grid gap-4 p-5",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("button",{type:"button","aria-pressed":m!==null&&Y(c.habit,m)==="aligned",className:P("rounded-[22px] border px-4 py-4 text-left transition",m!==null&&Y(c.habit,m)==="aligned"?"border-[color-mix(in_srgb,var(--success)_34%,var(--ui-border-subtle)_66%)] bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)] shadow-[var(--ui-shadow-soft)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-hover)]"),onClick:()=>j(a=>a!==null&&Y(c.habit,a)==="aligned"?null:Q(c.habit,"aligned")),children:[e.jsxs("div",{className:"flex items-center gap-2 text-base font-medium",children:[e.jsx(Ie,{className:"size-4"}),V.alignedLabel]}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:V.alignedDescription})]}),e.jsxs("button",{type:"button","aria-pressed":m!==null&&Y(c.habit,m)==="unaligned",className:P("rounded-[22px] border px-4 py-4 text-left transition",m!==null&&Y(c.habit,m)==="unaligned"?"border-[color-mix(in_srgb,var(--danger)_34%,var(--ui-border-subtle)_66%)] bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)] shadow-[var(--ui-shadow-soft)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-hover)]"),onClick:()=>j(a=>a!==null&&Y(c.habit,a)==="unaligned"?null:Q(c.habit,"unaligned")),children:[e.jsxs("div",{className:"flex items-center gap-2 text-base font-medium",children:[e.jsx(Pe,{className:"size-4"}),V.unalignedLabel]}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:V.unalignedDescription})]})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-[var(--ui-ink-strong)]",children:"Optional note"}),e.jsx(ve,{value:H,onChange:a=>D(a.target.value),placeholder:"Add context for what happened on this day or week.",className:"min-h-24"})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-3",children:[e.jsx(L,{variant:"secondary",onClick:()=>y(null),disabled:i.isPending,children:"Cancel"}),e.jsx(L,{disabled:i.isPending||!fe,pending:i.isPending,pendingLabel:"Saving",onClick:async()=>{fe&&(m===null?(await Cs(c.habit.id,c.cell.actionDateKey),await G()):await i.mutateAsync({habitId:c.habit.id,status:m,dateKey:c.cell.actionDateKey,note:H.trim()||void 0}),y(null))},children:"Save check-in"})]})]})]}):null]})]})})]})}export{oa as HabitsPage};