forge-openclaw-plugin 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. package/dist/assets/action-bar-5Ii4UzHa.js +1 -0
  2. package/dist/assets/activity-page-CWjTKFY3.js +1 -0
  3. package/dist/assets/ai-surface-workspace-Dd2FSRom.js +1 -0
  4. package/dist/assets/{atlas-panel-G3wGxjYf.js → atlas-panel-Dinteouh.js} +1 -1
  5. package/dist/assets/{board-dIX6etHh.js → board-CLOHbg6t.js} +1 -1
  6. package/dist/assets/calendar-page-BWkXhzDf.js +1 -0
  7. package/dist/assets/calendar-rules-CjyuTu2I.js +1 -0
  8. package/dist/assets/{calendar-week-toolbar-CWSK5hJl.js → calendar-week-toolbar-D-nd9tkk.js} +1 -1
  9. package/dist/assets/{charts-DFnEuIMB.js → charts-DwTguE_x.js} +1 -1
  10. package/dist/assets/companion-sync-lab-page-G0t1TqqZ.js +1 -0
  11. package/dist/assets/daily-metrics-dashboard-DpIAdzFX.js +1 -0
  12. package/dist/assets/define-workbench-box-BIOZopF2.js +1 -0
  13. package/dist/assets/entity-link-multiselect-DZZjpL_d.js +1 -0
  14. package/dist/assets/{entity-note-count-link-ef3ZOpKM.js → entity-note-count-link-CmRRdXAr.js} +1 -1
  15. package/dist/assets/entity-notes-surface-8MPDscsu.js +1 -0
  16. package/dist/assets/execution-board-Bi8gi8J6.js +1 -0
  17. package/dist/assets/{faceted-token-search-CZmtyJTT.js → faceted-token-search-BGs4TqxT.js} +1 -1
  18. package/dist/assets/{flagship-signal-deck-DxRfmfpN.js → flagship-signal-deck-jLxHEHvb.js} +1 -1
  19. package/dist/assets/{floating-action-menu-cKjNsPYD.js → floating-action-menu-Itpm7T2_.js} +1 -1
  20. package/dist/assets/{forms-hB0SqEh-.js → forms-C5d5hTf2.js} +1 -1
  21. package/dist/assets/generic-node-view-KePoUF3Z.js +10 -0
  22. package/dist/assets/goal-detail-page-a1lEswpJ.js +1 -0
  23. package/dist/assets/goal-dialog-CYgRzl4y.js +1 -0
  24. package/dist/assets/goals-page-JY_EJq9U.js +1 -0
  25. package/dist/assets/{graph-DDUZNRsO.js → graph-Cd5WF3lw.js} +1 -1
  26. package/dist/assets/habits-page-BRI8AoaQ.js +1 -0
  27. package/dist/assets/health-boxes-DZJOFTOI.js +1 -0
  28. package/dist/assets/index-wEZUnRh0.js +2 -0
  29. package/dist/assets/inline-note-fields-CUVRzQkI.js +1 -0
  30. package/dist/assets/insight-flow-dialog-By73oG1H.js +1 -0
  31. package/dist/assets/{insights-page-DHG-o9P_.js → insights-page-DLyN-9yz.js} +3 -3
  32. package/dist/assets/kanban-boxes-M71CejV4.js +1 -0
  33. package/dist/assets/kanban-page-InKHhJQD.js +1 -0
  34. package/dist/assets/knowledge-graph-page-C-GEQGRY.js +1 -0
  35. package/dist/assets/life-force-page-Dq88NzNp.js +1 -0
  36. package/dist/assets/{life-force-workspace-sszLD-Yn.js → life-force-workspace-Bl_0slZi.js} +1 -1
  37. package/dist/assets/{maps-C-yOWiDN.js → maps-D0Mm6WPG.js} +1 -1
  38. package/dist/assets/{metric-tile-B-tDTcBt.js → metric-tile-yQJgjYrN.js} +1 -1
  39. package/dist/assets/{motion-Lt5B1XuE.js → motion-DwjmC9aq.js} +1 -1
  40. package/dist/assets/movement-boxes-C-rc3N8Z.js +1 -0
  41. package/dist/assets/movement-page-DK-d1uYa.js +1 -0
  42. package/dist/assets/{note-markdown-CCyyE85h.js → note-markdown-7czv-KMH.js} +1 -1
  43. package/dist/assets/note-tags-input-CkgkqiT3.js +1 -0
  44. package/dist/assets/notes-boxes-BQuR1MiB.js +1 -0
  45. package/dist/assets/notes-page-ec9g1mPh.js +1 -0
  46. package/dist/assets/{open-in-graph-button-CMjJZX7G.js → open-in-graph-button-B_4fdm4l.js} +1 -1
  47. package/dist/assets/{orbit-map-v2Pv9RU_.js → orbit-map-DPQNBqS-.js} +1 -1
  48. package/dist/assets/overview-page-CZjMab2o.js +1 -0
  49. package/dist/assets/page-hero-BRcqE3a4.js +1 -0
  50. package/dist/assets/pill-cluster-dy6jG_dV.js +1 -0
  51. package/dist/assets/{preference-entity-handoff-button-CKDxCnbl.js → preference-entity-handoff-button-DOV-_2Vm.js} +1 -1
  52. package/dist/assets/preferences-page-Co8w5hzp.js +1 -0
  53. package/dist/assets/{project-collections-NBwk6yV-.js → project-collections-DNgKleDl.js} +1 -1
  54. package/dist/assets/project-detail-page-C-Ib1x8w.js +1 -0
  55. package/dist/assets/project-dialog-D_hgOdB9.js +1 -0
  56. package/dist/assets/project-management-hierarchy-page-asf61KSz.js +1 -0
  57. package/dist/assets/project-management-section-nav-DAZA1oXG.js +1 -0
  58. package/dist/assets/projects-boxes-CHLr1Bs-.js +1 -0
  59. package/dist/assets/projects-page-BsM8yCqQ.js +1 -0
  60. package/dist/assets/psyche-behaviors-page-COSZeP4J.js +5 -0
  61. package/dist/assets/psyche-flashcards-page-CJmgGL9x.js +1 -0
  62. package/dist/assets/psyche-goal-map-page-avrWNSs9.js +1 -0
  63. package/dist/assets/psyche-graph-BmwbnNBY.js +1 -0
  64. package/dist/assets/psyche-metrics-page-CY0J_aMx.js +1 -0
  65. package/dist/assets/psyche-mode-guide-page-COcswIHZ.js +1 -0
  66. package/dist/assets/psyche-modes-page-BXF_GZoP.js +1 -0
  67. package/dist/assets/psyche-page-VsMBNG1F.js +1 -0
  68. package/dist/assets/psyche-patterns-page-DVoIro0Q.js +5 -0
  69. package/dist/assets/psyche-questionnaire-builder-page-CahcrbQj.js +1 -0
  70. package/dist/assets/psyche-questionnaire-detail-page-CYSgADAD.js +1 -0
  71. package/dist/assets/psyche-questionnaire-run-detail-page-D5q5URTu.js +1 -0
  72. package/dist/assets/psyche-questionnaire-run-page-DUoA-VSs.js +1 -0
  73. package/dist/assets/psyche-questionnaires-page-dbQlqbKh.js +1 -0
  74. package/dist/assets/{psyche-report-detail-page-Ci14mNUK.js → psyche-report-detail-page-D_Mmlf2D.js} +3 -3
  75. package/dist/assets/psyche-reports-page-CO3J4Js3.js +1 -0
  76. package/dist/assets/{psyche-schemas-Dxj554nU.js → psyche-schemas-Dtskzvv1.js} +1 -1
  77. package/dist/assets/psyche-schemas-beliefs-page-BUNGL4zW.js +9 -0
  78. package/dist/assets/psyche-screen-time-page-Bm18uHDg.js +1 -0
  79. package/dist/assets/psyche-self-observation-page-VdPMBuK4.js +1 -0
  80. package/dist/assets/psyche-values-page-DivSQodJ.js +5 -0
  81. package/dist/assets/question-flow-dialog-Dsnsc8be.js +2 -0
  82. package/dist/assets/{report-chain-fields-CbkT7WOO.js → report-chain-fields-Bf-WCSJQ.js} +1 -1
  83. package/dist/assets/rewards-page-CI53Cp0i.js +1 -0
  84. package/dist/assets/{scheduling-rules-editor-BUGnZJ0g.js → scheduling-rules-editor-Bg3QU_qt.js} +1 -1
  85. package/dist/assets/{schema-badge-CLAA4p-b.js → schema-badge-CRThEDqP.js} +1 -1
  86. package/dist/assets/schemas-B8-kIOFQ.js +1 -0
  87. package/dist/assets/{select-menu-Cqs5t3ng.js → select-menu-rT3Qd5t5.js} +1 -1
  88. package/dist/assets/{settings-agents-page-pmkVrOO8.js → settings-agents-page-VDUv2WuO.js} +4 -4
  89. package/dist/assets/settings-bin-page-DfuGJVqc.js +1 -0
  90. package/dist/assets/{settings-calendar-page-BBjAMOCf.js → settings-calendar-page-ex7eHB1y.js} +3 -3
  91. package/dist/assets/settings-data-page-BPWyPVGo.js +1 -0
  92. package/dist/assets/settings-logs-page-CwTT4n63.js +1 -0
  93. package/dist/assets/settings-mobile-page-B6sVk872.js +1 -0
  94. package/dist/assets/settings-models-page-Dq5XViZd.js +1 -0
  95. package/dist/assets/settings-page-BRxdAxbS.js +1 -0
  96. package/dist/assets/settings-rewards-page-DRvxTwv3.js +1 -0
  97. package/dist/assets/{settings-section-nav-Co0AaDG-.js → settings-section-nav-D_vKvOWd.js} +1 -1
  98. package/dist/assets/settings-users-page-B6oSpOaV.js +1 -0
  99. package/dist/assets/settings-wiki-page-Bkv-SS3J.js +1 -0
  100. package/dist/assets/sleep-page-DELXxo6j.js +1 -0
  101. package/dist/assets/sports-page-ByWQL0Gf.js +1 -0
  102. package/dist/assets/{state-vCcAT5Hq.js → state-BtwEvpO6.js} +1 -1
  103. package/dist/assets/strategies-page-PuUHsaSJ.js +1 -0
  104. package/dist/assets/strategy-detail-page-CSyVdv29.js +1 -0
  105. package/dist/assets/strategy-dialog-Fgpc0z1M.js +1 -0
  106. package/dist/assets/{surface-CyWI7e1R.js → surface-DzVqQDmf.js} +1 -1
  107. package/dist/assets/{table-BNqMG3_S.js → table-BuONJH1s.js} +1 -1
  108. package/dist/assets/task-detail-page-BoLvJ_4F.js +1 -0
  109. package/dist/assets/task-dialog-B2cGkhLk.js +6 -0
  110. package/dist/assets/timebox-planning-dialog-BjiC2jh0.js +1 -0
  111. package/dist/assets/today-boxes-B4f4sBXg.js +1 -0
  112. package/dist/assets/today-page-Cusp2JI8.js +1 -0
  113. package/dist/assets/training-load-page-CsZbK6rY.js +1 -0
  114. package/dist/assets/{ui-C1iwpj2-.js → ui-B9O-eUim.js} +1 -1
  115. package/dist/assets/use-anchored-overlay-position-BrQ4cqKn.js +1 -0
  116. package/dist/assets/{use-psyche-focus-target-Ct-acS9G.js → use-psyche-focus-target-Cuxni3SK.js} +1 -1
  117. package/dist/assets/user-badge-CQygGKVs.js +1 -0
  118. package/dist/assets/user-ownership-DJGl4rAj.js +1 -0
  119. package/dist/assets/user-select-field-BNqv8-wd.js +1 -0
  120. package/dist/assets/utility-widgets-DRESNarT.js +3 -0
  121. package/dist/assets/{vendor-Dnkkx2co.js → vendor-Cpmju3nw.js} +1 -1
  122. package/dist/assets/vitals-page-BlTZ4f78.js +1 -0
  123. package/dist/assets/weekly-review-page-3Pk3NeGE.js +1 -0
  124. package/dist/assets/weight-loss-page-CRCtv1fX.js +5 -0
  125. package/dist/assets/{wiki-article-markdown-Bi02AsVt.js → wiki-article-markdown-D0PWvioX.js} +2 -2
  126. package/dist/assets/{wiki-editor-page-OZf9l4Tg.js → wiki-editor-page-OZMYUgFo.js} +5 -5
  127. package/dist/assets/wiki-ingest-history-page-DXZHzAqU.js +1 -0
  128. package/dist/assets/wiki-ingest-modal-Ro0V4UMB.js +1 -0
  129. package/dist/assets/wiki-page-B1g3Rfxy.js +1 -0
  130. package/dist/assets/workbench-flow-page-qh5nItU6.js +5 -0
  131. package/dist/assets/workbench-page-CFWfAYMV.js +1 -0
  132. package/dist/assets/workout-detail-page-Cw6t6Xj9.js +2 -0
  133. package/dist/index.html +7 -9
  134. package/dist/server/server/src/app.js +10 -0
  135. package/dist/server/server/src/health-weight-loss.js +11 -3
  136. package/dist/server/server/src/services/dashboard.js +4 -4
  137. package/dist/server/server/src/services/gamification.js +71 -32
  138. package/openclaw.plugin.json +1 -1
  139. package/package.json +1 -1
  140. package/dist/assets/activity-page-DRRbpVK-.js +0 -1
  141. package/dist/assets/ai-surface-workspace-DJPt-OaW.js +0 -1
  142. package/dist/assets/calendar-page-y8G1ige8.js +0 -1
  143. package/dist/assets/calendar-rules-CRhXqGQu.js +0 -1
  144. package/dist/assets/companion-sync-lab-page-kEgOF3c6.js +0 -1
  145. package/dist/assets/daily-metrics-dashboard-BJjUIZVA.js +0 -1
  146. package/dist/assets/entity-notes-surface-CaCjjUaq.js +0 -1
  147. package/dist/assets/execution-board-RRWm2srb.js +0 -1
  148. package/dist/assets/goal-detail-page-BgQlK7yT.js +0 -1
  149. package/dist/assets/goals-page-Cz2i3pVy.js +0 -1
  150. package/dist/assets/habits-page-BmEmWCGv.js +0 -1
  151. package/dist/assets/index-QJkjKYzZ.js +0 -19
  152. package/dist/assets/insight-flow-dialog-CdYMHwMP.js +0 -1
  153. package/dist/assets/kanban-page-C6S_fJRc.js +0 -1
  154. package/dist/assets/knowledge-graph-page-juA9QCy0.js +0 -1
  155. package/dist/assets/life-force-page-ChTIA4mV.js +0 -1
  156. package/dist/assets/movement-page-Dx3T3HrG.js +0 -1
  157. package/dist/assets/note-tags-input-BS14YXHn.js +0 -1
  158. package/dist/assets/notes-page-D3yGl8TN.js +0 -1
  159. package/dist/assets/overview-page-DSOpBpHf.js +0 -1
  160. package/dist/assets/page-hero-CONuJu5J.js +0 -1
  161. package/dist/assets/pill-cluster-W2fY48OM.js +0 -1
  162. package/dist/assets/preferences-page-Br3zrLlH.js +0 -1
  163. package/dist/assets/project-detail-page-BIU9_TRN.js +0 -1
  164. package/dist/assets/project-management-hierarchy-page-C2H620xD.js +0 -1
  165. package/dist/assets/project-management-section-nav-DRPVS1Eh.js +0 -1
  166. package/dist/assets/projects-page-w7a_L2-z.js +0 -1
  167. package/dist/assets/psyche-behaviors-page-Dt4CMC-q.js +0 -5
  168. package/dist/assets/psyche-flashcards-page-rXz06dqO.js +0 -1
  169. package/dist/assets/psyche-goal-map-page-BCcD6Jkl.js +0 -1
  170. package/dist/assets/psyche-graph-CXlAj4ED.js +0 -1
  171. package/dist/assets/psyche-metrics-page-B1otiir6.js +0 -1
  172. package/dist/assets/psyche-mode-guide-page-C6AdVIAv.js +0 -1
  173. package/dist/assets/psyche-modes-page-DoUqz2mR.js +0 -1
  174. package/dist/assets/psyche-page-BJNLQn8W.js +0 -1
  175. package/dist/assets/psyche-patterns-page-CzpMSAPu.js +0 -5
  176. package/dist/assets/psyche-questionnaire-builder-page-DjzatGVZ.js +0 -1
  177. package/dist/assets/psyche-questionnaire-detail-page-B0Qfowfg.js +0 -1
  178. package/dist/assets/psyche-questionnaire-run-detail-page-B2dNj4jJ.js +0 -1
  179. package/dist/assets/psyche-questionnaire-run-page-DyD9Ui-g.js +0 -1
  180. package/dist/assets/psyche-questionnaires-page-BxfKcoi3.js +0 -1
  181. package/dist/assets/psyche-reports-page-ALhNueiV.js +0 -1
  182. package/dist/assets/psyche-schemas-beliefs-page-C0P2Vw6-.js +0 -9
  183. package/dist/assets/psyche-screen-time-page-BYnaT3cb.js +0 -1
  184. package/dist/assets/psyche-self-observation-page-eM9vpwIB.js +0 -1
  185. package/dist/assets/psyche-values-page-BqrGIDok.js +0 -5
  186. package/dist/assets/rewards-page-DpAJ8IxE.js +0 -1
  187. package/dist/assets/settings-bin-page-BwtLrweW.js +0 -1
  188. package/dist/assets/settings-data-page-Bqy5SukM.js +0 -1
  189. package/dist/assets/settings-logs-page-8khtrf4T.js +0 -1
  190. package/dist/assets/settings-mobile-page-BcyRjEU_.js +0 -1
  191. package/dist/assets/settings-models-page-DlSnO9WX.js +0 -1
  192. package/dist/assets/settings-page-CyBQ2qcB.js +0 -1
  193. package/dist/assets/settings-rewards-page-BBX2WtVM.js +0 -1
  194. package/dist/assets/settings-users-page-JSnfFFPu.js +0 -1
  195. package/dist/assets/settings-wiki-page--nT23Fdy.js +0 -1
  196. package/dist/assets/sleep-page-CGMi3MtV.js +0 -1
  197. package/dist/assets/sports-page-Kv5bBoLr.js +0 -1
  198. package/dist/assets/strategies-page-Br7RdUJO.js +0 -1
  199. package/dist/assets/strategy-detail-page-CBWXjUhC.js +0 -1
  200. package/dist/assets/strategy-dialog-BTwkaSxI.js +0 -1
  201. package/dist/assets/task-detail-page-Qis9354n.js +0 -1
  202. package/dist/assets/timebox-planning-dialog-DB8snOBD.js +0 -1
  203. package/dist/assets/today-page-D9A5PU0S.js +0 -1
  204. package/dist/assets/training-load-page-Bpd4DQAh.js +0 -1
  205. package/dist/assets/vitals-page-CVYC-4RG.js +0 -1
  206. package/dist/assets/weekly-review-page-BP7N3fNB.js +0 -1
  207. package/dist/assets/weight-loss-page-_fX3N1UK.js +0 -5
  208. package/dist/assets/wiki-ingest-history-page-CzeNSL7N.js +0 -1
  209. package/dist/assets/wiki-ingest-modal-Ig_xnyc6.js +0 -1
  210. package/dist/assets/wiki-page-B4xuNgY4.js +0 -1
  211. package/dist/assets/workbench-flow-page-BhRJCALC.js +0 -5
  212. package/dist/assets/workbench-page-DxVs2AOY.js +0 -1
  213. package/dist/assets/workout-detail-page-D4wfkE98.js +0 -2
@@ -5,7 +5,7 @@ import { listHabits } from "../repositories/habits.js";
5
5
  import { buildNotesSummaryByEntity } from "../repositories/notes.js";
6
6
  import { listTagsByIds, listTags } from "../repositories/tags.js";
7
7
  import { listTasks } from "../repositories/tasks.js";
8
- import { buildAchievementSignals, buildGamificationProfile, buildMilestoneRewards } from "./gamification.js";
8
+ import { buildGamificationDashboardSignals } from "./gamification.js";
9
9
  import { listProjectSummaries } from "./projects.js";
10
10
  import { dashboardExecutionBucketSchema, dashboardPayloadSchema, dashboardStatsSchema } from "../types.js";
11
11
  function startOfWeek(date) {
@@ -153,9 +153,9 @@ export function getDashboard(options = {}) {
153
153
  const suggestedTags = tags.filter((tag) => ["value", "execution"].includes(tag.kind)).slice(0, 6);
154
154
  const owners = [...new Set(tasks.map((task) => task.owner).filter(Boolean))].sort((left, right) => left.localeCompare(right));
155
155
  const executionBuckets = buildExecutionBuckets(tasks, todayIso, weekEndIso);
156
- const gamification = buildGamificationProfile(goals, tasks, habits, now);
157
- const achievements = buildAchievementSignals(goals, tasks, habits, now);
158
- const milestoneRewards = buildMilestoneRewards(goals, tasks, habits, now);
156
+ const { profile: gamification, achievements, milestoneRewards } = buildGamificationDashboardSignals(goals, tasks, habits, now, {
157
+ userIds: options.userIds
158
+ });
159
159
  const visibleIds = {
160
160
  goal: new Set(goals.map((goal) => goal.id)),
161
161
  project: new Set(projects.map((project) => project.id)),
@@ -850,6 +850,47 @@ function syncCatalog(input) {
850
850
  });
851
851
  }
852
852
  function buildGamificationState(goals, tasks, habits, options = {}) {
853
+ const profileState = buildGamificationProfileState(goals, tasks, habits, options);
854
+ const { scope, scopedRewards, profile, persistableUserId, activeDateKeys, missedDays, lastActiveDateKey } = profileState;
855
+ const now = options.now ?? new Date();
856
+ const equipment = persistableUserId
857
+ ? getGamificationEquipment(persistableUserId)
858
+ : emptyGamificationEquipment();
859
+ const metricValues = buildMetricValues({
860
+ scope,
861
+ profile,
862
+ scopedRewards,
863
+ tasks,
864
+ habits,
865
+ activeDateKeys
866
+ });
867
+ const mascot = buildMascotState({
868
+ profile,
869
+ equipment,
870
+ missedDays,
871
+ lastActiveDateKey
872
+ });
873
+ const catalog = syncCatalog({
874
+ scope,
875
+ persistableUserId,
876
+ profile,
877
+ metricValues,
878
+ equipment,
879
+ mascot,
880
+ now
881
+ });
882
+ return {
883
+ scope,
884
+ scopedRewards,
885
+ profile,
886
+ metricValues,
887
+ equipment,
888
+ mascot,
889
+ catalog,
890
+ persistableUserId
891
+ };
892
+ }
893
+ function buildGamificationProfileState(goals, tasks, habits, options = {}) {
853
894
  const now = options.now ?? new Date();
854
895
  const scope = resolveGamificationScope(options.userIds);
855
896
  const persistableUserId = persistableUserIdForScope(scope);
@@ -906,45 +947,18 @@ function buildGamificationState(goals, tasks, habits, options = {}) {
906
947
  topGoalId: topGoal?.goalId ?? null,
907
948
  topGoalTitle: topGoal?.goalTitle ?? null
908
949
  });
909
- const equipment = persistableUserId
910
- ? getGamificationEquipment(persistableUserId)
911
- : emptyGamificationEquipment();
912
- const metricValues = buildMetricValues({
950
+ return {
913
951
  scope,
914
- profile,
915
952
  scopedRewards,
916
- tasks,
917
- habits,
918
- activeDateKeys
919
- });
920
- const mascot = buildMascotState({
921
953
  profile,
922
- equipment,
954
+ persistableUserId,
955
+ activeDateKeys,
923
956
  missedDays,
924
957
  lastActiveDateKey
925
- });
926
- const catalog = syncCatalog({
927
- scope,
928
- persistableUserId,
929
- profile,
930
- metricValues,
931
- equipment,
932
- mascot,
933
- now
934
- });
935
- return {
936
- scope,
937
- scopedRewards,
938
- profile,
939
- metricValues,
940
- equipment,
941
- mascot,
942
- catalog,
943
- persistableUserId
944
958
  };
945
959
  }
946
960
  export function buildGamificationProfile(goals, tasks, habits, now = new Date(), options = {}) {
947
- return buildGamificationState(goals, tasks, habits, {
961
+ return buildGamificationProfileState(goals, tasks, habits, {
948
962
  userIds: options.userIds,
949
963
  now
950
964
  }).profile;
@@ -1036,7 +1050,7 @@ function buildAchievementSignalsFromProfile(input) {
1036
1050
  ].map((achievement) => achievementSignalSchema.parse(achievement));
1037
1051
  }
1038
1052
  export function buildAchievementSignals(goals, tasks, habits, now = new Date(), options = {}) {
1039
- const state = buildGamificationState(goals, tasks, habits, {
1053
+ const state = buildGamificationProfileState(goals, tasks, habits, {
1040
1054
  userIds: options.userIds,
1041
1055
  now
1042
1056
  });
@@ -1123,6 +1137,31 @@ export function buildMilestoneRewards(goals, tasks, habits, now = new Date(), op
1123
1137
  const profile = buildGamificationProfile(goals, tasks, habits, now, options);
1124
1138
  return buildMilestoneRewardsFromProfile({ goals, tasks, habits, now, profile });
1125
1139
  }
1140
+ export function buildGamificationDashboardSignals(goals, tasks, habits, now = new Date(), options = {}) {
1141
+ const state = buildGamificationProfileState(goals, tasks, habits, {
1142
+ userIds: options.userIds,
1143
+ now
1144
+ });
1145
+ const achievements = buildAchievementSignalsFromProfile({
1146
+ goals,
1147
+ tasks,
1148
+ habits,
1149
+ now,
1150
+ profile: state.profile
1151
+ });
1152
+ const milestoneRewards = buildMilestoneRewardsFromProfile({
1153
+ goals,
1154
+ tasks,
1155
+ habits,
1156
+ now,
1157
+ profile: state.profile
1158
+ });
1159
+ return {
1160
+ profile: state.profile,
1161
+ achievements,
1162
+ milestoneRewards
1163
+ };
1164
+ }
1126
1165
  function buildXpMomentumPulseFromParts(input) {
1127
1166
  const { profile, achievements, milestoneRewards } = input;
1128
1167
  const nextMilestone = milestoneRewards.find((reward) => !reward.completed) ??
@@ -2,7 +2,7 @@
2
2
  "id": "forge-openclaw-plugin",
3
3
  "name": "Forge",
4
4
  "description": "Curated OpenClaw adapter for the Forge collaboration API, UI entrypoint, and localhost auto-start runtime.",
5
- "version": "0.3.2",
5
+ "version": "0.3.3",
6
6
  "activation": {
7
7
  "onStartup": true,
8
8
  "onCapabilities": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "forge-openclaw-plugin",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "Curated OpenClaw adapter for the Forge collaboration API, UI entrypoint, and localhost auto-start runtime.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -1 +0,0 @@
1
- import{j as e,aC as p,c2 as C}from"./vendor-Dnkkx2co.js";import{j as E,i as _,k as I}from"./state-vCcAT5Hq.js";import{C as b,U as k,f as v,B as g,u as P,i as S,r as L,L as R,E as T,a as U,l as q}from"./index-QJkjKYzZ.js";import{P as Q}from"./page-hero-CONuJu5J.js";import{u as F,f as y,g as H,c as M}from"./table-BNqMG3_S.js";import{g as m,a as f}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";const o=M(),j=[o.accessor("title",{header:"Event",cell:r=>{const a=m(r.row.original);return a?e.jsx(p,{to:a,className:"font-medium text-[var(--ui-ink-strong)] transition hover:text-[var(--primary)]",children:r.getValue()}):e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:r.getValue()})}}),o.accessor("source",{header:"Source",cell:r=>e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:r.getValue()})}),o.display({id:"owner",header:"Owner",cell:r=>r.row.original.user?e.jsx(k,{user:r.row.original.user,compact:!0}):e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Unowned"})}),o.accessor("createdAt",{header:"When",cell:r=>e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:v(r.getValue())})}),o.display({id:"actions",header:"Open",cell:r=>{const a=m(r.row.original);return a?e.jsx(p,{to:a,className:"inline-flex text-[11px] uppercase tracking-[0.16em] text-[var(--primary)] transition hover:text-[var(--ui-ink-strong)]",children:"Open"}):e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Archive only"})}})];function O({rows:r,onRemove:a}){const l=a?[...j,o.display({id:"remove",header:"Correct",cell:t=>e.jsx(g,{variant:"ghost",className:"h-auto px-0 py-0 text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-soft)]",onClick:()=>{a(t.row.original.id)},children:"Remove log"})})]:j,c=F({columns:l,data:r,getCoreRowModel:H()});return e.jsxs(b,{className:"min-w-0 overflow-hidden p-0",children:[e.jsxs("table",{className:"hidden w-full border-collapse md:table",children:[e.jsx("thead",{children:c.getHeaderGroups().map(t=>e.jsx("tr",{className:"bg-[var(--ui-surface-2)]",children:t.headers.map(i=>e.jsx("th",{className:"px-5 py-4 text-left font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:i.isPlaceholder?null:y(i.column.columnDef.header,i.getContext())},i.id))},t.id))}),e.jsx("tbody",{children:c.getRowModel().rows.map(t=>e.jsx("tr",{className:"border-t border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] transition hover:bg-[var(--ui-surface-hover)]",children:t.getVisibleCells().map(i=>e.jsx("td",{className:"px-5 py-4 align-top",children:y(i.column.columnDef.cell,i.getContext())},i.id))},t.id))})]}),e.jsx("div",{className:"grid gap-3 p-3 md:hidden",children:r.map(t=>{const i=m(t);return e.jsxs("article",{className:"min-w-0 rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsxs("div",{className:"flex min-w-0 items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:t.source}),e.jsx("div",{className:"mt-2 break-words text-sm font-semibold text-[var(--ui-ink-strong)]",children:t.title})]}),t.user?e.jsx(k,{user:t.user,compact:!0}):null]}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:t.description}),e.jsx("div",{className:"mt-3 text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:v(t.createdAt)}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-3",children:[i?e.jsx(p,{to:i,className:"inline-flex text-[11px] uppercase tracking-[0.16em] text-[var(--primary)] transition hover:text-[var(--ui-ink-strong)]",children:"Open"}):null,a?e.jsx(g,{variant:"ghost",className:"h-auto px-0 py-0 text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-soft)]",onClick:()=>{a(t.id)},children:"Remove log"}):null]})]},t.id)})})]})}function Z(){var h;const r=P(),a=Array.isArray(r.selectedUserIds)?r.selectedUserIds:[],[l]=C(),c=E(),t=l.get("entityId")??void 0,i=l.get("entityType")??void 0,N=l.get("eventId"),d=_({queryKey:["activity-archive",i,t,...a],queryFn:()=>q({limit:100,entityType:i,entityId:t,userIds:a})}),w=I({mutationFn:n=>L(n),onSuccess:async()=>{await Promise.all([c.invalidateQueries({queryKey:["activity-archive"]}),S(c),c.invalidateQueries({queryKey:["task-context"]}),c.invalidateQueries({queryKey:["project-board"]})])}}),u=((h=d.data)==null?void 0:h.activity)??[];if(d.isLoading)return e.jsx(R,{eyebrow:"Evidence archive",title:"Loading activity",description:"Pulling the visible audit trail, grouped evidence, and correction history."});if(d.isError)return e.jsx(T,{eyebrow:"Evidence archive",error:d.error,onRetry:()=>void d.refetch()});if(u.length===0)return e.jsx(U,{eyebrow:"Evidence archive",title:t?"No evidence matched this filter":"No activity recorded yet",description:t?"Forge could not find visible events for this specific entity yet. Try a broader archive view or create some work first.":"As you complete work, log runs, or make corrections, the audit trail will appear here."});const A=u.reduce((n,x)=>{const s=x.createdAt.slice(0,10);return n[s]=[...n[s]??[],x],n},{});return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(Q,{title:"Activity",description:t?"This filtered archive shows the evidence connected to the item you opened, so you can confirm what changed and when.":"Activity is your visible audit trail. Use it to inspect progress, confirm corrections, and trace work back to the goal, project, or task it came from.",badge:`${u.length} recent events`}),e.jsxs("section",{className:"grid gap-5 xl:grid-cols-[minmax(0,1.1fr)_minmax(0,0.9fr)]",children:[e.jsx(O,{rows:u,onRemove:async n=>{await w.mutateAsync(n)}}),e.jsx("div",{className:"grid gap-4",children:Object.entries(A).slice(0,6).map(([n,x])=>e.jsxs(b,{className:"min-w-0",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:n}),e.jsx("div",{className:"mt-4 grid gap-3",children:x.slice(0,3).map(s=>e.jsxs("div",{className:`min-w-0 rounded-[18px] border p-4 ${N===s.id?"border-[color-mix(in_srgb,var(--primary)_30%,transparent)] bg-[var(--ui-accent-soft)] shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--primary)_16%,transparent)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]"}`,children:[e.jsx("div",{className:"break-words font-medium text-[var(--ui-ink-strong)]",children:s.title}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:s.description}),e.jsx("div",{className:"mt-3 text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:v(s.createdAt)}),m(s)&&f(s)?e.jsx(p,{to:m(s),className:"mt-3 inline-flex text-[11px] uppercase tracking-[0.16em] text-[var(--primary)] transition hover:text-[var(--ui-ink-strong)]",children:f(s)}):null]},s.id))})]},n))})]})]})}export{Z as ActivityPage};
@@ -1 +0,0 @@
1
- import{r as x,j as i,cK as Y,cS as ee,bJ as te,cT as ie,cU as re,cV as ne,cW as se,cX as ae,aC as le,b1 as oe}from"./vendor-Dnkkx2co.js";import{u as ue,a as ce,P as de,D as fe,c as me,S as xe,v as he,d as ve,b as be,C as pe}from"./board-dIX6etHh.js";import{i as ge,k as B}from"./state-vCcAT5Hq.js";import{cR as je,cS as Ne,B as H,Z as W,cT as ye,C as Se,cU as ke}from"./index-QJkjKYzZ.js";const k={lg:1280,md:996,sm:768,xs:480},A={lg:12,md:10,sm:6,xs:4,xxs:2},We="forge.surface-layout.v3";function I(e){return`${We}.${e}`}function T(e,r,n){return Math.min(Math.max(e,r),n)}function Ce(e){return e>=k.lg?"lg":e>=k.md?"md":e>=k.sm?"sm":e>=k.xs?"xs":"xxs"}function Ee(e,r){const n=A[r];if(r==="lg")return T(e.defaultWidth,e.minWidth??1,Math.min(e.maxWidth??n,n));const s=Math.round(e.defaultWidth/A.lg*n);return T(Math.max(e.minWidth??1,s||(e.minWidth??1)),e.minWidth??1,Math.min(e.maxWidth??n,n))}function Me(e){return{hidden:e.defaultHidden??!1,fullWidth:e.defaultFullWidth??!1,titleVisible:e.defaultTitleVisible??!0,descriptionVisible:e.defaultDescriptionVisible??!0}}function P(e,r){const n=[...r.filter(s=>s.defaultPlacement==="top"),...r.filter(s=>s.defaultPlacement!=="top")];return{surfaceId:e,order:n.map(s=>s.id),widgets:Object.fromEntries(r.map(s=>[s.id,Me(s)])),updatedAt:new Date(0).toISOString()}}function V(e,r,n){const s=P(e,r),l=new Set(r.map(o=>o.id)),c=((n==null?void 0:n.order)??[]).filter(o=>l.has(o)),h=s.order.filter(o=>!c.includes(o)),d=Object.fromEntries(r.map(o=>{var N,g,m,b,p;const f=(N=n==null?void 0:n.widgets)==null?void 0:N[o.id];return[o.id,{...s.widgets[o.id],hidden:(f==null?void 0:f.hidden)??((g=s.widgets[o.id])==null?void 0:g.hidden)??!1,fullWidth:(f==null?void 0:f.fullWidth)??((m=s.widgets[o.id])==null?void 0:m.fullWidth)??!1,titleVisible:(f==null?void 0:f.titleVisible)??((b=s.widgets[o.id])==null?void 0:b.titleVisible)??!0,descriptionVisible:(f==null?void 0:f.descriptionVisible)??((p=s.widgets[o.id])==null?void 0:p.descriptionVisible)??!0}]}));return{surfaceId:e,order:[...c,...h],widgets:d,updatedAt:typeof(n==null?void 0:n.updatedAt)=="string"?n.updatedAt:s.updatedAt}}function Ve(e,r){const n=new Map(r.order.map((s,l)=>[s,l]));return[...e].sort((s,l)=>{const c=n.get(s.id)??Number.MAX_SAFE_INTEGER,h=n.get(l.id)??Number.MAX_SAFE_INTEGER;return c!==h?c-h:s.id.localeCompare(l.id)})}function Re(e,r,n){const s=e.indexOf(r);if(s===-1)return e;const l=T(n,0,e.length-1);if(s===l)return e;const c=[...e];return c.splice(s,1),c.splice(l,0,r),c}function R(e){if(typeof window>"u")return null;try{const r=window.localStorage.getItem(I(e));return r?JSON.parse(r):null}catch{return null}}function O(e){if(!(typeof window>"u"))try{window.localStorage.setItem(I(e.surfaceId),JSON.stringify(e))}catch{}}const Oe=500;function G(e,r){return e.surfaceId===r.surfaceId&&JSON.stringify(e.order)===JSON.stringify(r.order)&&JSON.stringify(e.widgets)===JSON.stringify(r.widgets)}function Ae({definition:e,preferences:r,editing:n,width:s,children:l}){const c=s<=4;return e.surfaceChrome==="none"?i.jsx("div",{"data-surface-card":"true",className:W("min-w-0",n&&"rounded-[28px] ring-1 ring-[var(--ui-border-subtle)] ring-inset"),children:l}):i.jsxs(Se,{"data-surface-card":"true",className:W("surface-grid-card flex min-w-0 flex-col gap-3 overflow-visible p-4 md:p-5",n&&"ring-1 ring-[var(--ui-border-subtle)]"),children:[r.titleVisible||r.descriptionVisible&&e.description?i.jsxs("div",{className:"min-w-0",children:[r.titleVisible?i.jsx("div",{className:"truncate text-[0.72rem] font-semibold uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:e.title}):null,r.descriptionVisible&&e.description&&!c?i.jsx("div",{className:"mt-1 text-[12px] leading-5 text-[var(--ui-ink-soft)]",children:e.description}):null]}):null,i.jsx("div",{className:"min-h-0 flex-1",children:l})]})}function Te({widget:e,preferences:r,index:n,total:s,onMove:l,onToggleHidden:c,onToggleFullWidth:h}){const d=be({id:e.id});return i.jsxs("div",{ref:d.setNodeRef,style:{transform:pe.Transform.toString(d.transform),transition:d.transition},className:"flex min-w-0 items-center gap-2 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 py-2.5",children:[i.jsx("button",{type:"button",className:"inline-flex size-8 shrink-0 items-center justify-center rounded-full bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]","aria-label":`Drag ${e.title}`,...d.attributes,...d.listeners,children:i.jsx(te,{className:"size-4"})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("div",{className:"truncate text-sm font-medium text-[var(--ui-ink-strong)]",children:e.title}),e.description?i.jsx("div",{className:"truncate text-[12px] text-[var(--ui-ink-faint)]",children:e.description}):null]}),i.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[i.jsx("button",{type:"button",className:"inline-flex size-8 items-center justify-center rounded-full bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)] disabled:opacity-40",onClick:()=>l(n-1),disabled:n===0,"aria-label":`Move ${e.title} up`,children:i.jsx(ie,{className:"size-3.5"})}),i.jsx("button",{type:"button",className:"inline-flex size-8 items-center justify-center rounded-full bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)] disabled:opacity-40",onClick:()=>l(n+1),disabled:n===s-1,"aria-label":`Move ${e.title} down`,children:i.jsx(re,{className:"size-3.5"})}),i.jsxs("button",{type:"button",className:W("inline-flex h-8 items-center gap-2 rounded-full px-3 text-[12px] transition",r.fullWidth?"bg-[var(--primary)] text-[var(--ui-ink-on-accent)]":"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]"),onClick:h,children:[r.fullWidth?i.jsx(ne,{className:"size-3.5"}):i.jsx(se,{className:"size-3.5"}),r.fullWidth?"Normal width":"Full width"]}),e.removable!==!1?i.jsxs("button",{type:"button",className:"inline-flex h-8 items-center gap-2 rounded-full bg-[var(--ui-surface-2)] px-3 text-[12px] text-[var(--ui-ink-medium)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",onClick:c,children:[i.jsx(ae,{className:"size-3.5"}),"Hide"]}):null]})]})}function Pe({surfaceId:e,widgets:r,defaultEditing:n=!1,actions:s,normalizeLayout:l}){var U;const c=x.useMemo(()=>JSON.stringify(r.map(t=>({id:t.id,defaultWidth:t.defaultWidth,defaultHidden:t.defaultHidden,defaultPlacement:t.defaultPlacement,defaultFullWidth:t.defaultFullWidth,defaultTitleVisible:t.defaultTitleVisible,defaultDescriptionVisible:t.defaultDescriptionVisible}))),[r]),h=x.useMemo(()=>{const t=P(e,r);return l?l(t):t},[l,e,c]),d=t=>l?l(t):t,[o,f]=x.useState(n),[N,g]=x.useState(1280),[m,b]=x.useState(()=>d(V(e,r,R(e)??h))),p=x.useRef(null),F=x.useRef(!1),y=x.useRef(d(V(e,r,R(e)??h))),z=x.useRef(null),K=ue(ce(de,{activationConstraint:{distance:6}})),C=ge({queryKey:["forge-surface-layout",e],queryFn:()=>ke(e)}),D=(U=C==null?void 0:C.data)==null?void 0:U.layout,L=B({mutationFn:t=>je(e,{order:t.order,widgets:t.widgets})}),X=B({mutationFn:()=>Ne(e)});x.useEffect(()=>{const t=d(V(e,r,D??R(e)??h));b(a=>G(a,t)?a:t),O(t),y.current=t,F.current=!0},[h,D,l,e,c,r]),x.useEffect(()=>{const t=z.current;if(!t||typeof ResizeObserver>"u")return;const a=new ResizeObserver(u=>{var j;const v=((j=u[0])==null?void 0:j.contentRect.width)??t.clientWidth;g(Math.max(320,Math.round(v)))});return a.observe(t),g(Math.max(320,Math.round(t.clientWidth||1280))),()=>a.disconnect()},[]),x.useEffect(()=>{if(F.current&&!G(m,y.current))return O(m),p.current!==null&&window.clearTimeout(p.current),p.current=window.setTimeout(()=>{const t=m;L.mutateAsync(t).then(()=>{y.current=t})},Oe),()=>{p.current!==null&&window.clearTimeout(p.current)}},[m,L,e]);const $=Ce(N),E=A[$],_=x.useMemo(()=>Ve(r,m),[m,r]),S=_.filter(t=>{var a;return!((a=m.widgets[t.id])!=null&&a.hidden)}),J=_.filter(t=>{var a;return(a=m.widgets[t.id])==null?void 0:a.hidden});function M(t,a){b(u=>d({...u,widgets:{...u.widgets,[t]:{...u.widgets[t],...a}}}))}function q(t,a){b(u=>d({...u,order:Re(u.order,t,a)}))}function Z(t){const{active:a,over:u}=t;!u||a.id===u.id||b(v=>{const j=v.order.indexOf(String(a.id)),w=v.order.indexOf(String(u.id));return j===-1||w===-1?v:d({...v,order:ve(v.order,j,w)})})}function Q(){const t=d(P(e,r));b(t),O(t),y.current=t,X.mutateAsync()}return i.jsxs("div",{className:"grid gap-4",children:[o?i.jsx(fe,{sensors:K,collisionDetection:me,onDragEnd:Z,children:i.jsxs("div",{className:"grid gap-3 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[i.jsx("div",{className:"text-[12px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Visible boxes"}),i.jsx(xe,{items:S.map(t=>t.id),strategy:he,children:i.jsx("div",{className:"grid gap-2",children:S.map((t,a)=>{const u=m.widgets[t.id]??{hidden:!1,fullWidth:!1,titleVisible:!0,descriptionVisible:!0};return i.jsx(Te,{widget:t,preferences:u,index:a,total:S.length,onMove:v=>q(t.id,v),onToggleHidden:()=>M(t.id,{hidden:!0}),onToggleFullWidth:()=>M(t.id,{fullWidth:!u.fullWidth})},t.id)})})}),J.length>0?i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"pt-2 text-[12px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Hidden boxes"}),i.jsx("div",{className:"flex flex-wrap gap-2",children:J.map(t=>i.jsx("button",{type:"button",className:"rounded-full bg-[var(--ui-surface-2)] px-3 py-2 text-sm text-[var(--ui-ink-medium)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",onClick:()=>M(t.id,{hidden:!1}),children:t.title},t.id))})]}):null]})}):null,i.jsxs("div",{ref:z,className:"relative",children:[i.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 flex max-w-[calc(100%-1.5rem)] flex-wrap items-center justify-end gap-1.5",children:i.jsxs("div",{className:"pointer-events-auto flex flex-wrap items-center justify-end gap-1.5",children:[s,o?i.jsxs(H,{type:"button",size:"sm",variant:"secondary",className:"h-8 rounded-full border-[var(--ui-border-subtle)] bg-[var(--surface-glass)] px-2.5 text-[12px] text-[var(--ui-ink-medium)] backdrop-blur-xl hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",onClick:Q,children:[i.jsx(Y,{className:"size-3.5"}),i.jsx("span",{className:"hidden sm:inline",children:"Reset"})]}):null,i.jsxs(H,{type:"button",size:"sm",variant:o?"primary":"secondary",className:W("h-8 rounded-full px-2 text-[12px] backdrop-blur-xl [&>span]:gap-1.5",o?"bg-[var(--primary)] text-[var(--ui-ink-on-accent)] hover:opacity-95":"border-[var(--ui-border-subtle)] bg-[var(--surface-glass)] text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>f(t=>!t),children:[i.jsx(ee,{className:"size-3.5"}),i.jsx("span",{className:"hidden xl:inline",children:o?"Done":"Layout"})]})]})}),i.jsx("div",{className:"surface-flow-grid",style:{display:"grid",gap:"16px",gridTemplateColumns:`repeat(${E}, minmax(0, 1fr))`,alignItems:"start"},children:S.map(t=>{const a=m.widgets[t.id]??{hidden:!1,fullWidth:!1,titleVisible:!0,descriptionVisible:!0},u=a.fullWidth?E:Math.min(Ee(t,$),E);return i.jsx("div",{style:{gridColumn:`span ${u} / span ${u}`},children:i.jsx(Ae,{definition:t,preferences:a,editing:o,width:u,children:i.jsx(ye,{boxId:t.workbenchBoxId??`surface:${e}:${t.id}`,surfaceId:e,children:t.render({compact:u<=4,width:u,editing:o,preferences:a})})})},t.id)})})]})]})}function $e({surfaceId:e,baseWidgets:r,actions:n,normalizeLayout:s}){return i.jsx(Pe,{surfaceId:e,widgets:r,normalizeLayout:s,actions:i.jsxs(i.Fragment,{children:[n,i.jsxs(le,{to:`/workbench?surface=${encodeURIComponent(e)}`,className:"inline-flex h-8 items-center gap-1.5 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--surface-glass)] px-2.5 text-[12px] font-medium text-[var(--ui-ink-medium)] backdrop-blur-xl transition hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",children:[i.jsx(oe,{className:"size-3.5"}),i.jsx("span",{className:"hidden sm:inline",children:"Workbench"})]})]})})}export{$e as A};
@@ -1 +0,0 @@
1
- import{r as g,j as e,aV as rt,aG as We,c3 as Ut,b5 as Wt,c2 as Qt,c4 as le,c5 as Me,c6 as qt,c7 as _e,c8 as Gt,c9 as Zt,bK as st,ca as ze,bc as Yt,cb as nt,bg as Xt}from"./vendor-Dnkkx2co.js";import{w as Jt,j as Vt,i as ot,k as z}from"./state-vCcAT5Hq.js";import{g as jt,b as Qe,F as j,I as P,T as ea,e as ye,c as S,d as ee,h as ce,j as be,k as Ge,m as ta,n as At,Q as Ze,o as St,p as Nt,q as aa,u as ia,s as ra,t as sa,v as na,w as oa,x as la,y as lt,z as da,A as ca,D as ua,G as ma,H as xe,S as pa,E as ga,C as G,J as va,K as ha,B as Z,M as xa,i as ya,N as ba,O as fa}from"./index-QJkjKYzZ.js";import{C as ka}from"./calendar-week-toolbar-CWSK5hJl.js";import{T as wa,a as ja}from"./timebox-planning-dialog-DB8snOBD.js";import{W as qe,m as dt,a as Aa,s as $e,b as Le,c as Sa,f as Re}from"./calendar-ui-Cy1XRwzV.js";import{P as Na}from"./page-hero-CONuJu5J.js";import{F as Ca}from"./floating-action-menu-cKjNsPYD.js";import{r as Ta,b as Ia,g as ct}from"./calendar-display-preferences-Cid-2RnL.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";import"./scheduling-rules-editor-BUGnZJ0g.js";const ut="rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",mt="bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)]",Ke="rounded-[22px] border px-4 py-4 text-left transition",He="border-[color-mix(in_srgb,var(--primary)_30%,var(--ui-border-subtle)_70%)] bg-[var(--ui-accent-soft)] text-[var(--ui-ink-strong)]",Be="border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)] hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)]";function pt(a,s){const d=new Date(a);return Number.isNaN(d.getTime())?s:d.toISOString()}function de(a){const s=new Date(a);return new Date(s.getTime()-s.getTimezoneOffset()*6e4).toISOString().slice(0,16)}function gt(a,s){var x,y,f,u,N;const d=new Date,b=new Date(d.getTime()+30*6e4),h=new Date(b.getTime()+60*6e4);return{title:(s==null?void 0:s.title)??(a==null?void 0:a.title)??"",description:(s==null?void 0:s.description)??(a==null?void 0:a.description)??"",location:(s==null?void 0:s.location)??(a==null?void 0:a.location)??"",placeAddress:((x=s==null?void 0:s.place)==null?void 0:x.address)??((y=a==null?void 0:a.place)==null?void 0:y.address)??"",placeTimezone:((f=s==null?void 0:s.place)==null?void 0:f.timezone)??((u=a==null?void 0:a.place)==null?void 0:u.timezone)??"",startAtLocal:a?de(a.startAt):s!=null&&s.startAt?de(s.startAt):de(b.toISOString()),endAtLocal:a?de(a.endAt):s!=null&&s.endAt?de(s.endAt):de(h.toISOString()),timezone:(s==null?void 0:s.timezone)??(a==null?void 0:a.timezone)??Intl.DateTimeFormat().resolvedOptions().timeZone??"UTC",availability:(s==null?void 0:s.availability)??(a==null?void 0:a.availability)??"busy",activityPresetKey:Nt(a==null?void 0:a.actionProfile),customSustainRateApPerHour:St(a==null?void 0:a.actionProfile),preferredCalendarId:s&&"preferredCalendarId"in s?s.preferredCalendarId:(a==null?void 0:a.calendarId)??void 0,categoriesText:((N=s==null?void 0:s.categories)==null?void 0:N.join(", "))??(a==null?void 0:a.categories.join(", "))??"",linkQuery:"",links:(s==null?void 0:s.links)??(a==null?void 0:a.links.map(E=>({entityType:E.entityType,entityId:E.entityId,relationshipType:E.relationshipType,label:`${E.entityType.replaceAll("_"," ")} · ${E.entityId}`})))??[]}}function Pa({open:a,onOpenChange:s,writableCalendars:d,linkOptions:b,event:h,seed:x,onSubmit:y,pending:f=!1}){const[u,N]=g.useState(()=>gt(h,x)),[E,c]=g.useState(null);g.useEffect(()=>{a&&(N(gt(h,x)),c(null))},[h,a,x]);const A=g.useMemo(()=>b.map(n=>{const v=jt(n.entityType);return{value:`${n.entityType}:${n.entityId}`,label:n.label,description:n.subtitle,searchText:`${n.label} ${n.subtitle} ${n.entityType}`,kind:v??void 0,menuBadge:v?e.jsx(Qe,{kind:v,label:n.label,compact:!0,gradient:!1}):void 0,badge:v?e.jsx(Qe,{kind:v,label:n.label,compact:!0}):void 0}}),[b]),m=g.useMemo(()=>[{id:"identity",eyebrow:"Event",title:h?"Refine the Forge event":"Create a Forge calendar event",description:"This event belongs to Forge first. If you choose a writable calendar, Forge will also project it to the connected provider.",render:(n,v)=>e.jsxs("div",{className:"grid gap-4",children:[e.jsx(j,{label:"Title",children:e.jsx(P,{value:n.title,onChange:l=>v({title:l.target.value}),placeholder:"Weekly research supervision"})}),e.jsx(j,{label:"Description",children:e.jsx(ea,{value:n.description,onChange:l=>v({description:l.target.value}),placeholder:"Agenda, context, or outcomes you want this event to carry."})}),e.jsx(j,{label:"Location",children:e.jsx(P,{value:n.location,onChange:l=>v({location:l.target.value}),placeholder:"Clinic room 2 or Zoom"})}),e.jsx(j,{label:"Place address",children:e.jsx(P,{value:n.placeAddress,onChange:l=>v({placeAddress:l.target.value}),placeholder:"Bahnhofstrasse 10, Zurich"})}),e.jsx(j,{label:"Place timezone",children:e.jsx(P,{value:n.placeTimezone,onChange:l=>v({placeTimezone:l.target.value}),placeholder:"Europe/Zurich"})})]})},{id:"timing",eyebrow:"Timing",title:"Set the time and visibility",description:"Forge stores the real event window, timezone, and whether it should behave like a busy or free slot for scheduling rules.",render:(n,v)=>e.jsxs("div",{className:"grid gap-4",children:[(()=>{const l=new Date().toISOString(),$=new Date(Date.now()+3600*1e3).toISOString(),M=ye({title:n.title,availability:n.availability,activityPresetKey:n.activityPresetKey,customSustainRateApPerHour:n.customSustainRateApPerHour,startAt:pt(n.startAtLocal,l),endAt:pt(n.endAtLocal,$)});return e.jsxs("div",{className:`${ut} p-4`,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(S,{className:mt,children:ee(M.rateApPerHour)}),e.jsx(S,{className:mt,children:ce(M.totalAp)})]}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Availability controls whether the event blocks planning. The activity profile controls AP drain, and you can override it with a custom AP per hour."})]})})(),e.jsx(j,{label:"Activity profile",children:e.jsx(be,{value:n.activityPresetKey??(n.availability==="busy"?"meeting":"light_context"),columns:3,onChange:l=>v({activityPresetKey:l}),options:Ge().filter(l=>l.key!=="task_inherited").map(l=>({value:l.key,label:l.label,description:`${ee(l.defaultRateApPerHour)} · ${l.description}`}))})}),e.jsx(j,{label:"Custom AP per hour",children:e.jsx(P,{type:"number",min:0,step:.5,value:n.customSustainRateApPerHour??"",onChange:l=>v({customSustainRateApPerHour:l.target.value.trim()===""?null:Number(l.target.value)}),placeholder:"Leave empty to use the activity default"})}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(j,{label:"Starts",children:e.jsx(P,{type:"datetime-local",value:n.startAtLocal,onChange:l=>v({startAtLocal:l.target.value})})}),e.jsx(j,{label:"Ends",children:e.jsx(P,{type:"datetime-local",value:n.endAtLocal,onChange:l=>v({endAtLocal:l.target.value})})})]}),e.jsx(j,{label:"Timezone",children:e.jsx(P,{value:n.timezone,onChange:l=>v({timezone:l.target.value}),placeholder:"Europe/Zurich"})}),e.jsx(j,{label:"Availability",children:e.jsx(be,{value:n.availability,onChange:l=>v({availability:l}),options:[{value:"busy",label:"Busy",description:"This event should block timebox recommendations and rule checks."},{value:"free",label:"Free",description:"This event stays visible in the calendar without blocking work."}]})})]})},{id:"links",eyebrow:"Meaning",title:"Connect the event to Forge entities",description:"Attach this event to strategies, goals, projects, tasks, or habits so the calendar carries multi-user operating context instead of staying isolated.",render:(n,v)=>e.jsx("div",{className:"grid gap-4",children:e.jsx(j,{label:"Search Forge entities",description:"Search across human and bot-owned entities; the linked records use the same icon, color, and owner system as the rest of Forge.",children:e.jsx(ta,{options:A,selectedValues:n.links.map(l=>`${l.entityType}:${l.entityId}`),onChange:l=>{v({links:l.map($=>{const[M,...L]=$.split(":"),R=L.join(":"),te=b.find(ue=>ue.entityType===M&&ue.entityId===R);return te?{entityType:te.entityType,entityId:te.entityId,relationshipType:"context",label:te.label}:null}).filter($=>$!==null)})},placeholder:"Search strategies, goals, projects, tasks, habits, human, or bot owners",emptyMessage:"No matching Forge entities found."})})})},{id:"projection",eyebrow:"Projection",title:"Choose where this event should live remotely",description:"You can keep the event local to Forge, or choose a writable connected calendar so Forge also keeps a synced remote copy.",render:(n,v)=>e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-3",children:[d.length>0?e.jsxs("button",{type:"button",onClick:()=>v({preferredCalendarId:void 0}),className:`${Ke} ${n.preferredCalendarId===void 0?He:Be}`,children:[e.jsxs("div",{className:"flex items-center gap-2 font-medium",children:[e.jsx(rt,{className:"size-4"}),"Default synced calendar"]}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Let Forge use the default writable connected calendar automatically."})]}):null,e.jsxs("button",{type:"button",onClick:()=>v({preferredCalendarId:null}),className:`${Ke} ${n.preferredCalendarId===null?He:Be}`,children:[e.jsxs("div",{className:"flex items-center gap-2 font-medium",children:[e.jsx(We,{className:"size-4"}),"Forge only"]}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Keep the event in Forge without creating a remote provider copy yet."})]}),d.map(l=>e.jsxs("button",{type:"button",onClick:()=>v({preferredCalendarId:l.id}),className:`${Ke} ${n.preferredCalendarId===l.id?He:Be}`,children:[e.jsxs("div",{className:"flex items-center gap-2 font-medium",children:[e.jsx(rt,{className:"size-4"}),At(l)]}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:l.description||`${l.timezone} · writable`})]},l.id))]}),e.jsxs("div",{className:`${ut} grid gap-2 p-4 text-sm text-[var(--ui-ink-medium)]`,children:[e.jsxs("div",{className:"flex items-center gap-2 font-medium text-[var(--ui-ink-strong)]",children:[e.jsx(Ut,{className:"size-4 text-[var(--primary)]"}),"Categories and filtering"]}),e.jsx(P,{value:n.categoriesText,onChange:l=>v({categoriesText:l.target.value}),placeholder:"meeting, clinic, research"})]})]})}],[h,b,A,d]);return e.jsx(Ze,{open:a,onOpenChange:s,eyebrow:h?"Edit event":"New event",title:h?"Edit calendar event":"Create calendar event",description:"Forge-owned events can stay local or publish to a connected provider calendar.",value:u,onChange:N,draftPersistenceKey:h?`calendar.event.${h.id}`:"calendar.event.new",steps:m,onSubmit:async()=>{if(!u.title.trim()){c("Add an event title before saving.");return}if(!u.startAtLocal||!u.endAtLocal){c("Set both the start and end time before saving.");return}if(new Date(u.endAtLocal).getTime()<=new Date(u.startAtLocal).getTime()){c("The event end time must be after the start time.");return}c(null),await y({title:u.title.trim(),description:u.description.trim(),location:u.location.trim(),place:{label:u.location.trim(),address:u.placeAddress.trim(),timezone:u.placeTimezone.trim(),latitude:null,longitude:null,source:u.placeAddress.trim()?"manual":"",externalPlaceId:""},startAt:new Date(u.startAtLocal).toISOString(),endAt:new Date(u.endAtLocal).toISOString(),timezone:u.timezone.trim()||"UTC",availability:u.availability,activityPresetKey:u.activityPresetKey,customSustainRateApPerHour:u.customSustainRateApPerHour,categories:u.categoriesText.split(",").map(n=>n.trim()).filter(Boolean),links:u.links.map(n=>({entityType:n.entityType,entityId:n.entityId,relationshipType:n.relationshipType})),...u.preferredCalendarId!==void 0?{preferredCalendarId:u.preferredCalendarId}:{}})},submitLabel:h?"Save event":"Create event",pending:f,pendingLabel:h?"Saving":"Creating",error:E})}function Da({open:a,onOpenChange:s,initialTitle:d,pending:b=!1,onSubmit:h}){const[x,y]=g.useState(d),[f,u]=g.useState(null);return g.useEffect(()=>{a&&(y(d),u(null))},[d,a]),e.jsx(Ze,{open:a,onOpenChange:s,eyebrow:"Calendar",title:"Quick rename",description:"Rename the event without reopening the full event guide.",value:{title:x},onChange:N=>y(N.title),draftPersistenceKey:`calendar.quick-rename.${d}`,steps:[{id:"rename",eyebrow:"Rename",title:"Update the event title",description:"Keep the rename fast and direct. Everything else on the event stays unchanged.",render:(N,E)=>e.jsx(j,{label:"Event title",children:e.jsx(P,{value:N.title,onChange:c=>E({title:c.target.value}),placeholder:"Weekly research supervision"})})}],submitLabel:"Save title",pending:b,pendingLabel:"Saving",error:f,onSubmit:async()=>{const N=x.trim();if(!N){u("Add a title before saving.");return}u(null),await h(N),s(!1)}})}function vt(a){if(a)return{title:a.title,kind:a.kind,color:a.color,timezone:a.timezone,weekDays:a.weekDays,startMinute:a.startMinute,endMinute:a.endMinute,startsOn:a.startsOn,endsOn:a.endsOn,blockingState:a.blockingState,activityPresetKey:Nt(a.actionProfile),customSustainRateApPerHour:St(a.actionProfile)};const s=qe[0];return{title:s.title,kind:s.kind,color:s.color,timezone:typeof Intl<"u"&&Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC",weekDays:[1,2,3,4,5],startMinute:s.startMinute,endMinute:s.endMinute,startsOn:null,endsOn:null,blockingState:s.blockingState,activityPresetKey:s.kind==="main_activity"?"deep_work":s.kind==="secondary_activity"?"admin":s.kind==="holiday"?"holiday_leisure":s.kind==="rest"?"recovery_break":"maintenance",customSustainRateApPerHour:null}}function ht(a){return a??""}function Ue({draft:a}){const s=aa({kind:a.kind,startMinute:a.startMinute,endMinute:a.endMinute,activityPresetKey:a.activityPresetKey,customSustainRateApPerHour:a.customSustainRateApPerHour}),d=a.endMinute>a.startMinute?a.endMinute-a.startMinute:1440-a.startMinute+a.endMinute;return e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(S,{className:"bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)]",children:ee(s.rateApPerHour)}),e.jsxs(S,{className:"bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)]",children:[ce(s.totalAp)," / block"]}),e.jsxs(S,{className:"bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)]",children:[Math.round(d/60),"h ",d%60,"m"]})]}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"This is the default Life Force container drain for each occurrence of the block when no richer task run or timebox already covers that window."})]})}function Oa({open:a,onOpenChange:s,onSubmit:d,pending:b=!1,template:h=null}){const[x,y]=g.useState(()=>vt(h)),[f,u]=g.useState(null),N=h!==null;g.useEffect(()=>{a&&(u(null),y(vt(h)))},[a,h]);const E=g.useMemo(()=>[{id:"preset",eyebrow:"Preset",title:"Start from a recurring block that already matches the rhythm",description:"Use a preset to seed the schedule, then tune the dates and recurrence in the next step.",render:(c,A)=>e.jsxs("div",{className:"grid gap-4",children:[e.jsx(Ue,{draft:c}),e.jsx(j,{label:"Activity profile",children:e.jsx(be,{value:c.activityPresetKey??"maintenance",columns:3,onChange:m=>A({activityPresetKey:m,customSustainRateApPerHour:c.customSustainRateApPerHour}),options:Ge().filter(m=>m.key!=="task_inherited").map(m=>({value:m.key,label:m.label,description:`${ee(m.defaultRateApPerHour)} · ${m.description}`}))})}),e.jsx(j,{label:"Custom AP per hour",children:e.jsx(P,{type:"number",min:0,step:.5,value:c.customSustainRateApPerHour??"",onChange:m=>A({customSustainRateApPerHour:m.target.value.trim()===""?null:Number(m.target.value)}),placeholder:"Leave empty to use the activity default"})}),e.jsx(j,{label:"Block type",children:e.jsx(be,{value:c.kind,columns:3,onChange:m=>{const n=qe.find(v=>v.kind===m);if(n){const v=n.kind==="holiday"?[0,1,2,3,4,5,6]:[1,2,3,4,5];A({kind:n.kind,title:n.title,color:n.color,weekDays:v,startMinute:n.startMinute,endMinute:n.endMinute,blockingState:n.blockingState,activityPresetKey:n.kind==="main_activity"?"deep_work":n.kind==="secondary_activity"?"admin":n.kind==="holiday"?"holiday_leisure":n.kind==="rest"?"recovery_break":"maintenance",customSustainRateApPerHour:null});return}A({kind:"custom",title:"Custom block",color:"#7dd3fc",activityPresetKey:"maintenance",customSustainRateApPerHour:null})},options:[...qe.map(m=>({value:m.kind,label:m.title,description:`${dt(m.startMinute)}-${dt(m.endMinute)}`})),{value:"custom",label:"Custom",description:"Build a different recurring window."}]})})]})},{id:"shape",eyebrow:"Schedule",title:"Define when this recurring block should exist",description:"Weekdays and times describe the recurring pattern. Optional start and end dates bound when the template is active.",render:(c,A)=>e.jsxs("div",{className:"grid gap-4",children:[e.jsx(Ue,{draft:c}),e.jsx(j,{label:"Block title",children:e.jsx(P,{value:c.title,onChange:m=>A({title:m.target.value}),placeholder:"Main Activity"})}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(j,{label:"Start minute",children:e.jsx(P,{type:"number",min:0,max:1440,step:15,value:c.startMinute,onChange:m=>A({startMinute:Number(m.target.value)||0})})}),e.jsx(j,{label:"End minute",children:e.jsx(P,{type:"number",min:0,max:1440,step:15,value:c.endMinute,onChange:m=>A({endMinute:Number(m.target.value)||0})})})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(j,{label:"Start date",children:e.jsx(P,{type:"date",value:ht(c.startsOn),onChange:m=>A({startsOn:m.target.value.trim()||null})})}),e.jsx(j,{label:"End date",children:e.jsx(P,{type:"date",value:ht(c.endsOn),onChange:m=>A({endsOn:m.target.value.trim()||null})})})]}),e.jsx("div",{className:"text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Leave the end date empty to keep repeating indefinitely. Holiday blocks work well with all seven weekdays and `0-1440`, and they still carry AP load because leisure and holiday time are real activities."}),e.jsx(j,{label:"Weekdays",children:e.jsx("div",{className:"flex flex-wrap gap-2",children:Aa.map((m,n)=>{const v=c.weekDays.includes(n);return e.jsx("button",{type:"button",onClick:()=>A({weekDays:v?c.weekDays.filter(l=>l!==n):[...c.weekDays,n].sort((l,$)=>l-$)}),className:`rounded-full px-3 py-2 text-sm transition ${v?"bg-[var(--ui-accent-soft)] text-[var(--primary)] ring-1 ring-[color-mix(in_srgb,var(--primary)_24%,transparent)]":"bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]"}`,children:m},m)})})})]})},{id:"policy",eyebrow:"Policy",title:"Tell Forge whether this block allows or blocks work",description:"Use blocked mode for time that should normally stop optional work. Use allowed mode for protected focus windows.",render:(c,A)=>e.jsxs("div",{className:"grid gap-4",children:[e.jsx(Ue,{draft:c}),e.jsx(j,{label:"Work effect",children:e.jsx(be,{value:c.blockingState,onChange:m=>A({blockingState:m}),options:[{value:"blocked",label:"Blocks work",description:"Starting blocked tasks should require an explicit override."},{value:"allowed",label:"Allows work",description:"Use this for protected windows where the right tasks should fit."}]})}),e.jsx(j,{label:"Color",children:e.jsxs("div",{className:"flex items-center gap-3 rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("input",{className:"h-10 w-12 rounded-lg border border-[var(--ui-border-subtle)] bg-transparent",type:"color",value:c.color,onChange:m=>A({color:m.target.value})}),e.jsx(P,{className:"border-none bg-transparent px-0 py-0",value:c.color,onChange:m=>A({color:m.target.value})})]})})]})}],[]);return e.jsx(Ze,{open:a,onOpenChange:s,eyebrow:"Calendar",title:N?"Edit work block":"Create a work block",description:N?"Adjust the recurring pattern, date bounds, or work policy for this block.":"Build recurring half-day, holiday, or custom blocks so Forge can understand when work should be protected or blocked.",value:x,onChange:y,draftPersistenceKey:h?`calendar.work-block.${h.id}`:"calendar.work-block.new",steps:E,submitLabel:N?"Save changes":"Save work block",pending:b,pendingLabel:N?"Saving changes":"Saving",error:f,onSubmit:async()=>{if(!x.title.trim()){u("Give the block a title so it stays readable in the calendar.");return}if(x.weekDays.length===0){u("Select at least one weekday for the recurring block.");return}if(x.endMinute<=x.startMinute){u("The end minute needs to be later than the start minute.");return}if(x.startsOn&&x.endsOn&&x.endsOn<x.startsOn){u("The end date needs to be on or after the start date.");return}try{u(null),await d({...x,title:x.title.trim()}),s(!1)}catch(c){u(c instanceof Error?c.message:"Forge could not save this work block.")}}})}const Ne=Jt(a=>({entry:null,setEntry:s=>a({entry:s}),clear:()=>a({entry:null}),completePaste:()=>a(s=>{var d;return{entry:((d=s.entry)==null?void 0:d.mode)==="cut"?null:s.entry}})}));function Ea(a){const s=new Date(a);s.setUTCHours(9,0,0,0);const d=new Date(s.getTime()+3600*1e3);return{startAt:s.toISOString(),endAt:d.toISOString(),timezone:Intl.DateTimeFormat().resolvedOptions().timeZone??"UTC",availability:"busy"}}function xt(a){var y;const s=Math.max(60,Math.floor((Date.parse(a.endsAt)-Date.parse(a.startsAt))/1e3)),d=((y=Ge().find(f=>f.key===a.activityPresetKey))==null?void 0:y.defaultRateApPerHour)??100/24,b=a.customSustainRateApPerHour??d,h=Number((s/3600*b).toFixed(2)),x=new Date().toISOString();return{id:`preview_${a.entityType}_${a.entityId}`,profileKey:`${String(a.entityType)}_${a.entityId}`,title:a.title,entityType:a.entityType,mode:"container",startupAp:0,totalCostAp:h,expectedDurationSeconds:s,sustainRateApPerHour:b,demandWeights:{activation:.1,focus:.35,vigor:.1,composure:.15,flow:.3},doubleCountPolicy:"container_only",sourceMethod:a.customSustainRateApPerHour!==null&&a.customSustainRateApPerHour!==void 0?"manual":a.activityPresetKey?"seeded":"inferred",costBand:b>=10?"standard":"light",recoveryEffect:0,metadata:{activityPresetKey:a.activityPresetKey??null,customSustainRateApPerHour:a.customSustainRateApPerHour??null},createdAt:x,updatedAt:x}}function yt(a){const s=typeof a.location=="string"?a.location:"",d=a.place??{label:s,address:"",timezone:"",latitude:null,longitude:null,source:"",externalPlaceId:""};return{...a,place:{label:d.label||s,address:d.address??"",timezone:d.timezone??"",latitude:d.latitude??null,longitude:d.longitude??null,source:d.source??"",externalPlaceId:d.externalPlaceId??""}}}function bt(a,s){const d=new Date(a.startAt),h=new Date(a.endAt).getTime()-d.getTime(),x=new Date(s);x.setUTCHours(d.getUTCHours(),d.getUTCMinutes(),0,0);const y=new Date(x.getTime()+h);return{startAt:x.toISOString(),endAt:y.toISOString()}}function ft(a){return{type:"calendar_event",eventId:a.id,title:a.title,description:a.description,location:a.location,startAt:a.startAt,endAt:a.endAt,timezone:a.timezone,availability:a.availability,preferredCalendarId:a.calendarId,categories:a.categories,links:a.links.map(s=>({entityType:s.entityType,entityId:s.entityId,relationshipType:s.relationshipType}))}}function Fa(a){switch(a){case"apple":return"Apple";case"google":return"Google";case"caldav":return"CalDAV";case"native":return"Forge";default:return"Derived"}}function Ma(a,s){var d;if(a.calendarId){const b=(d=s.get(a.calendarId))==null?void 0:d.trim();if(b)return b}return a.originType==="native"?"Forge only":Fa(a.originType)}function kt(a){switch(a){case"main_activity":return"Main activity";case"secondary_activity":return"Secondary activity";case"third_activity":return"Third activity";case"rest":return"Rest";case"holiday":return"Holiday";default:return"Custom"}}function wt(a){return a.startsOn&&a.endsOn?`${a.startsOn} to ${a.endsOn}`:a.startsOn?`From ${a.startsOn}`:a.endsOn?`Until ${a.endsOn}`:"Repeats with no end date"}function Xa(){var Ve,et,tt,at,it;const a=Wt(),[s,d]=Qt(),b=ia(),h=Array.isArray(b.selectedUserIds)?b.selectedUserIds:[],x=ra(h),y=Vt(),f=Ne(t=>t.entry),u=Ne(t=>t.setEntry),N=Ne(t=>t.clear),E=Ne(t=>t.completePaste),[c,A]=g.useState(()=>$e()),[m,n]=g.useState(null),[v,l]=g.useState(null),[$,M]=g.useState(!1),[L,R]=g.useState(null),[te,ue]=g.useState(!1),[Ce,ae]=g.useState(!1),[Y,me]=g.useState(null),[Ct,ie]=g.useState(!1),[Te,re]=g.useState(null),[se,Ie]=g.useState(null),pe=g.useMemo(()=>Ta(),[]),[Tt,ne]=g.useState(null),[w,ge]=g.useState(null),[Pe,K]=g.useState(null),fe=s.get("timeboxId"),H=g.useMemo(()=>{const t=c.toISOString(),r=Le(c,7).toISOString();return{from:t,to:r}},[c]),X=ot({queryKey:["forge-calendar-overview",H.from,H.to,...h],queryFn:()=>ba({...H,userIds:h})}),B=ot({queryKey:["forge-life-force",...h],queryFn:()=>fa(h)}),_=["forge-calendar-overview",H.from,H.to,...h],ke=t=>{if(t.deletedAt)return!1;const r=new Date(t.startAt).getTime();return r>=new Date(H.from).getTime()&&r<new Date(H.to).getTime()},ve=t=>{y.setQueryData(_,r=>r&&t(r))},F=async()=>{await Promise.all([y.invalidateQueries({queryKey:["forge-calendar-overview"]}),ya(y),y.invalidateQueries({queryKey:["task-context"]}),y.invalidateQueries({queryKey:["project-board"]})])},Ye=z({mutationFn:t=>sa({...t,userId:t.userId??x}),onSuccess:F}),Xe=z({mutationFn:({templateId:t,patch:r})=>na(t,r),onSuccess:F}),De=z({mutationFn:oa,onSuccess:F}),It=z({mutationFn:t=>la({...t,userId:x}),onSuccess:F}),Pt=z({mutationFn:({timeboxId:t,startsAt:r,endsAt:o})=>lt(t,{startsAt:r,endsAt:o}),onSuccess:F}),Dt=z({mutationFn:({timeboxId:t,patch:r})=>lt(t,r),onSuccess:F}),Ot=z({mutationFn:da,onSuccess:async()=>{me(null),ae(!1),await F()}}),we=z({mutationFn:t=>ca({...t,userId:t.userId??x}),onMutate:async t=>{var p,T,U,W,oe,V,D;K({tone:"saving",message:"Saving event changes in the background…"}),await y.cancelQueries({queryKey:_});const r=y.getQueryData(_),o=(r==null?void 0:r.calendar.calendars.find(I=>I.canWrite&&I.selectedForSync))??(r==null?void 0:r.calendar.calendars.find(I=>I.canWrite))??null,C=new Date().toISOString(),O=`calendar_event_optimistic_${Date.now()}`,i={id:O,connectionId:(o==null?void 0:o.connectionId)??null,calendarId:t.preferredCalendarId===void 0?(o==null?void 0:o.id)??null:t.preferredCalendarId,remoteId:null,ownership:"forge",originType:"native",status:"confirmed",title:t.title,description:t.description??"",location:t.location??"",place:{label:((p=t.place)==null?void 0:p.label)??t.location??"",address:((T=t.place)==null?void 0:T.address)??"",timezone:((U=t.place)==null?void 0:U.timezone)??t.timezone??Intl.DateTimeFormat().resolvedOptions().timeZone??"UTC",latitude:((W=t.place)==null?void 0:W.latitude)??null,longitude:((oe=t.place)==null?void 0:oe.longitude)??null,source:((V=t.place)==null?void 0:V.source)??"forge",externalPlaceId:((D=t.place)==null?void 0:D.externalPlaceId)??""},startAt:t.startAt,endAt:t.endAt,timezone:t.timezone??Intl.DateTimeFormat().resolvedOptions().timeZone??"UTC",isAllDay:t.isAllDay??!1,availability:t.availability??"busy",eventType:t.eventType??"general",categories:t.categories??[],sourceMappings:[],links:(t.links??[]).map((I,Q)=>({id:`calendar_event_link_optimistic_${Date.now()}_${Q}`,entityType:I.entityType,entityId:I.entityId,relationshipType:I.relationshipType??"context",createdAt:C,updatedAt:C})),actionProfile:xt({entityType:"calendar_event",entityId:O,title:t.title,startsAt:t.startAt,endsAt:t.endAt,activityPresetKey:t.activityPresetKey??null,customSustainRateApPerHour:t.customSustainRateApPerHour??null}),remoteUpdatedAt:null,deletedAt:null,createdAt:C,updatedAt:C};return r&&ke(i)&&ve(I=>({...I,calendar:{...I.calendar,events:[i,...I.calendar.events]}})),{previous:r,optimisticEventId:i.id}},onError:(t,r,o)=>{o!=null&&o.previous&&y.setQueryData(_,o.previous),K({tone:"error",message:t instanceof Error?t.message:"Forge could not sync that event change."})},onSuccess:({event:t},r,o)=>{K(null),ve(C=>({...C,calendar:{...C.calendar,events:(ke(t)?[t,...C.calendar.events.filter(O=>O.id!==(o==null?void 0:o.optimisticEventId))]:C.calendar.events.filter(O=>O.id!==(o==null?void 0:o.optimisticEventId))).filter((O,i,p)=>p.findIndex(T=>T.id===O.id)===i)}}))},onSettled:F}),J=z({mutationFn:({eventId:t,patch:r})=>ua(t,r),onMutate:async({eventId:t,patch:r})=>{K({tone:"saving",message:"Saving event changes in the background…"}),await y.cancelQueries({queryKey:_});const o=y.getQueryData(_);return o&&ve(C=>{var T,U,W,oe,V;const O=C.calendar.events.find(D=>D.id===t);if(!O)return C;const i=yt(O),p={...i,...r,place:r.place?{...i.place,...r.place}:i.place,calendarId:r.preferredCalendarId===void 0?i.calendarId:r.preferredCalendarId,links:((T=r.links)==null?void 0:T.map((D,I)=>{var Q,Se;return{id:((Q=i.links[I])==null?void 0:Q.id)??`calendar_event_link_optimistic_${Date.now()}_${I}`,entityType:D.entityType,entityId:D.entityId,relationshipType:D.relationshipType??"context",createdAt:((Se=i.links[I])==null?void 0:Se.createdAt)??i.createdAt,updatedAt:new Date().toISOString()}}))??i.links,actionProfile:xt({entityType:"calendar_event",entityId:t,title:r.title??i.title,startsAt:r.startAt??i.startAt,endsAt:r.endAt??i.endAt,activityPresetKey:r.activityPresetKey===void 0?(W=(U=i.actionProfile)==null?void 0:U.metadata)==null?void 0:W.activityPresetKey:r.activityPresetKey,customSustainRateApPerHour:r.customSustainRateApPerHour===void 0?typeof((V=(oe=i.actionProfile)==null?void 0:oe.metadata)==null?void 0:V.customSustainRateApPerHour)=="number"?i.actionProfile.metadata.customSustainRateApPerHour:null:r.customSustainRateApPerHour}),updatedAt:new Date().toISOString()};return{...C,calendar:{...C.calendar,events:C.calendar.events.map(D=>D.id===t?p:D).filter(ke)}}}),{previous:o}},onError:(t,r,o)=>{o!=null&&o.previous&&y.setQueryData(_,o.previous),K({tone:"error",message:t instanceof Error?t.message:"Forge could not sync that event change."})},onSuccess:({event:t})=>{K(null),ve(r=>({...r,calendar:{...r.calendar,events:r.calendar.events.map(o=>o.id===t.id?t:o).filter(ke)}}))},onSettled:F}),Oe=z({mutationFn:ma,onMutate:async t=>{K({tone:"saving",message:"Removing the event in the background…"}),await y.cancelQueries({queryKey:_});const r=y.getQueryData(_);return r&&ve(o=>({...o,calendar:{...o.calendar,events:o.calendar.events.filter(C=>C.id!==t)}})),{previous:r}},onError:(t,r,o)=>{o!=null&&o.previous&&y.setQueryData(_,o.previous),K({tone:"error",message:t instanceof Error?t.message:"Forge could not delete that event."})},onSuccess:()=>{K(null)},onSettled:F}),je=(Ve=X.data)==null?void 0:Ve.calendar,Ae=g.useMemo(()=>Sa(c),[c]),k=g.useMemo(()=>je?{...je,events:je.events.map(yt)}:{generatedAt:"",providers:[],connections:[],calendars:[],events:[],workBlockTemplates:[],workBlockInstances:[],timeboxes:[]},[je]),Et=g.useMemo(()=>new Map(k.calendars.map(t=>[t.id,At(t)])),[k.calendars]),Ee=g.useMemo(()=>Ia(k.calendars,pe.calendarColors),[pe.calendarColors,k.calendars]),Ft=we.isPending||J.isPending||Oe.isPending,Mt=k.timeboxes.filter(t=>t.status==="planned"),_t=k.calendars.filter(t=>t.canWrite),he=(t,r)=>r?`${t} · ${r}`:t,Fe=[...b.snapshot.goals.map(t=>({entityType:"goal",entityId:t.id,label:t.title,subtitle:he("Goal",xe(t.user))})),...b.snapshot.projects.map(t=>({entityType:"project",entityId:t.id,label:t.title,subtitle:he("Project",xe(t.user))})),...b.snapshot.tasks.map(t=>({entityType:"task",entityId:t.id,label:t.title,subtitle:he("Task",xe(t.user))})),...b.snapshot.strategies.map(t=>({entityType:"strategy",entityId:t.id,label:t.title,subtitle:he("Strategy",xe(t.user))})),...b.snapshot.habits.map(t=>({entityType:"habit",entityId:t.id,label:t.title,subtitle:he("Habit",xe(t.user))}))],zt=g.useMemo(()=>new Map(Fe.map(t=>[`${t.entityType}:${t.entityId}`,t.label])),[Fe]),$t=k.connections.length===0?"No providers connected":`${k.connections.filter(t=>t.status==="connected").length}/${k.connections.length} healthy`,q=(f==null?void 0:f.items.filter(t=>t.type==="calendar_event"))??[];g.useEffect(()=>{if(!fe)return;const t=k.timeboxes.find(o=>o.id===fe);if(!t)return;const r=$e(new Date(t.startsAt));if(r.getTime()!==c.getTime()){A(r);return}((Y==null?void 0:Y.id)!==t.id||!Ce)&&(me(t),ae(!0))},[fe,k.timeboxes,Y==null?void 0:Y.id,Ce,c]);const Je=()=>{if(!fe)return;const t=new URLSearchParams(s);t.delete("timeboxId"),d(t,{replace:!0})},Lt=t=>{ae(t),t||(me(null),Je())},Rt=t=>{re(null),ne(Ea(t)),ie(!0)},Kt=async(t,r)=>{const o=bt({startAt:t.startAt,endAt:t.endAt},r);await J.mutateAsync({eventId:t.id,patch:o})},Ht=async t=>{if(q.length!==0){for(const r of q){const o=bt(r,t);(f==null?void 0:f.mode)==="cut"?await J.mutateAsync({eventId:r.eventId,patch:o}):await we.mutateAsync({title:r.title,description:r.description,location:r.location,startAt:o.startAt,endAt:o.endAt,timezone:r.timezone,availability:r.availability,preferredCalendarId:r.preferredCalendarId,categories:r.categories,links:r.links})}E()}},Bt=g.useMemo(()=>{if(!w)return[];if(w.kind==="day"){const r=Ae.find(o=>o.toISOString().slice(0,10)===w.dayKey);return r?[{id:"create-event",label:"Create event",description:"Open the event guide with this day already selected.",icon:le,onSelect:()=>Rt(r)},{id:"create-work-block",label:"Create work block",description:"Open the guided work-block flow while you are looking at this day.",icon:Me,onSelect:()=>{R(null),M(!0)}},{id:"paste",label:(f==null?void 0:f.mode)==="cut"?"Paste moved event":"Paste copied event",description:q.length>0?`${q.length} calendar item${q.length===1?"":"s"} ready to paste here.`:f?"The current clipboard entry does not contain calendar events.":"Copy or cut an event first, then paste it into this day.",icon:qt,disabled:q.length===0,onSelect:()=>void Ht(r)}]:[]}if(w.kind==="work-block"){const r=k.workBlockTemplates.find(o=>o.id===w.templateId);return r?[{id:"edit-work-block",label:"Edit",description:"Adjust the recurring pattern, date bounds, or work policy.",icon:le,onSelect:()=>{R(r),M(!0)}},{id:"delete-work-block",label:"Delete",description:"Remove this recurring work block from Forge.",icon:_e,tone:"danger",onSelect:()=>{(L==null?void 0:L.id)===r.id&&R(null),De.mutateAsync(r.id)}}]:[]}const t=k.events.find(r=>r.id===w.eventId);return t?[{id:"rename",label:"Quick rename",description:"Change the event title without opening the full event flow.",icon:le,onSelect:()=>Ie(t)},{id:"copy",label:"Copy",description:"Put this event on the Forge clipboard so you can paste it into another day.",icon:Gt,onSelect:()=>u({id:`clipboard_${t.id}_${Date.now()}`,mode:"copy",source:"calendar",label:t.title,createdAt:new Date().toISOString(),items:[ft(t)]})},{id:"cut",label:"Cut",description:"Move this event by pasting it into another day.",icon:Zt,onSelect:()=>u({id:`clipboard_cut_${t.id}_${Date.now()}`,mode:"cut",source:"calendar",label:t.title,createdAt:new Date().toISOString(),items:[ft(t)]})},{id:"delete",label:"Delete",description:"Remove the event from Forge and delete any connected remote projection.",icon:_e,tone:"danger",onSelect:()=>{(f==null?void 0:f.mode)==="cut"&&q.some(r=>r.eventId===t.id)&&N(),Oe.mutateAsync(t.id)}}]:[]},[N,q,f,Ae,Oe,De,w,k.events,k.workBlockTemplates,L,u]);return X.isLoading?e.jsx(pa,{}):X.isError||!X.data?e.jsx(ga,{eyebrow:"Calendar",error:X.error??new Error("Calendar data is unavailable"),onRetry:()=>void X.refetch()}):e.jsxs("div",{className:"grid gap-5",children:[e.jsx(Na,{entityKind:"project",titleText:"Calendar",title:"Calendar",description:"See the real week first, then open guided flows for work blocks, task rules, timeboxing, and provider setup.",badge:`${k.connections.length} connection${k.connections.length===1?"":"s"}`}),(et=B.data)!=null&&et.lifeForce?e.jsxs(G,{className:"grid gap-3 rounded-[28px] border border-[var(--ui-border-subtle)] !bg-[var(--ui-surface-1)] p-4 shadow-[var(--ui-shadow-soft)] md:grid-cols-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Life Force today"}),e.jsxs("div",{className:"mt-2 text-3xl font-semibold text-[var(--ui-ink-strong)]",children:[Math.round(B.data.lifeForce.spentTodayAp),e.jsxs("span",{className:"ml-2 text-lg text-[var(--ui-ink-muted)]",children:["/ ",Math.round(B.data.lifeForce.dailyBudgetAp)," AP"]})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Instant headroom"}),e.jsxs("div",{className:"mt-2 text-2xl font-semibold text-[var(--primary)]",children:[B.data.lifeForce.instantFreeApPerHour.toFixed(1)," ","AP/h"]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Calendar containers now speak the same AP language as live work."})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Forecast"}),e.jsxs("div",{className:"mt-2 text-2xl font-semibold text-[var(--ui-ink-strong)]",children:[Math.round(B.data.lifeForce.forecastAp)," AP"]}),e.jsxs("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:["Planned remaining"," ",ce(B.data.lifeForce.plannedRemainingAp)]})]})]}):null,e.jsxs(G,{className:"grid gap-4 rounded-[32px] border border-[var(--ui-border-subtle)] !bg-[var(--ui-surface-1)] shadow-[var(--ui-shadow-soft)]",children:[e.jsx(ka,{description:"The calendar is the priority surface here. Connected provider events, recurring work blocks, and owned task timeboxes all stay visible together.",weekStart:c,status:Pe?e.jsx("div",{className:`inline-flex max-w-full items-center gap-2 rounded-full px-3 py-1.5 text-xs ${Pe.tone==="error"?"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%)]":"border border-[var(--primary)]/18 bg-[var(--primary)]/12 text-[var(--primary)]"}`,children:Pe.message}):null,badges:e.jsxs(e.Fragment,{children:[(tt=B.data)!=null&&tt.lifeForce?e.jsxs(S,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:[Math.round(B.data.lifeForce.spentTodayAp),"/",Math.round(B.data.lifeForce.dailyBudgetAp)," AP"]}):null,Ft?e.jsxs(S,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:[e.jsx(st,{className:"mr-1 size-3.5 animate-spin"}),"Syncing changes"]}):null,f?e.jsxs(S,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:[f.mode==="cut"?"Cut":"Copied"," ·"," ",f.label]}):null]}),onPrevious:()=>A(Le(c,-7)),onCurrent:()=>A($e()),onNext:()=>A(Le(c,7))}),e.jsx("div",{className:"grid gap-3 [grid-template-columns:repeat(auto-fit,minmax(min(100%,17rem),1fr))] 2xl:[grid-template-columns:repeat(7,minmax(0,1fr))]",children:Ae.map(t=>{const r=t.toISOString().slice(0,10),o=k.events.filter(i=>i.startAt.slice(0,10)===r&&!i.deletedAt),C=k.workBlockInstances.filter(i=>i.dateKey===r),O=k.timeboxes.filter(i=>i.startsAt.slice(0,10)===r);return e.jsxs("div",{"data-calendar-day":r,onClick:i=>{i.target.closest("[data-calendar-item='true']")||ge({kind:"day",dayKey:r,position:{x:i.clientX,y:i.clientY}})},onDragOver:i=>{i.preventDefault()},onDrop:i=>{i.preventDefault();const p=i.dataTransfer.getData("text/forge-event-id")||v;if(p){const Q=k.events.find(Se=>Se.id===p);Q&&Kt(Q,t),l(null);return}const T=i.dataTransfer.getData("text/forge-timebox-id")||m;if(!T)return;const U=k.timeboxes.find(Q=>Q.id===T);if(!U)return;const W=new Date(U.startsAt),V=new Date(U.endsAt).getTime()-W.getTime(),D=new Date(t);D.setUTCHours(W.getUTCHours(),W.getUTCMinutes(),0,0);const I=new Date(D.getTime()+V);Pt.mutateAsync({timeboxId:T,startsAt:D.toISOString(),endsAt:I.toISOString()}),n(null)},className:"min-w-0 overflow-hidden rounded-[24px] border border-[var(--ui-border-subtle)] !bg-[var(--ui-surface-2)] p-3 transition hover:border-[var(--ui-border-strong)] hover:!bg-[var(--ui-surface-hover)]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 py-2 text-sm font-medium text-[var(--ui-ink-strong)]",children:[e.jsx("span",{className:"min-w-0 truncate",children:Re(t)}),e.jsx("button",{type:"button","aria-label":`Open actions for ${Re(t)}`,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)]",onClick:i=>{i.stopPropagation(),ge({kind:"day",dayKey:r,position:{x:i.clientX,y:i.clientY}})},children:e.jsx(ze,{className:"size-4"})})]}),e.jsxs("div",{className:"mt-3 grid min-w-0 gap-2",children:[C.map(i=>e.jsxs("div",{"data-calendar-item":"true",className:"min-w-0 overflow-hidden rounded-[18px] px-3 py-2 text-sm text-[var(--ui-ink-strong)]",style:{backgroundColor:`${i.color}22`,border:`1px solid ${i.color}55`},children:[(()=>{const p=va(i);return e.jsxs("div",{className:"flex min-w-0 items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"min-w-0 [overflow-wrap:anywhere] font-medium",children:i.title}),e.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1.5",children:[e.jsx(S,{size:"sm",className:"shrink-0 bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:i.blockingState}),e.jsx(S,{size:"sm",className:"shrink-0 bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:kt(i.kind)}),p.rateApPerHour>0?e.jsxs(e.Fragment,{children:[e.jsx(S,{size:"sm",className:"shrink-0 bg-[var(--primary)]/14 text-[var(--primary)]",children:ee(p.rateApPerHour)}),e.jsx(S,{size:"sm",className:"shrink-0 bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:ce(p.totalAp)})]}):e.jsx(S,{size:"sm",className:"shrink-0 bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)]",children:"Recovery"})]})]}),e.jsx("button",{type:"button","aria-label":`Open actions for ${i.title}`,className:"rounded-full bg-[var(--ui-surface-2)] p-1.5 text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",onClick:T=>{T.stopPropagation(),ge({kind:"work-block",templateId:i.templateId,position:{x:T.clientX,y:T.clientY}})},children:e.jsx(ze,{className:"size-4"})})]})})(),e.jsxs("div",{className:"mt-1 text-[var(--ui-ink-soft)]",children:[new Date(i.startAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})," ","-"," ",new Date(i.endAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]}),e.jsx("div",{className:"mt-2 text-xs text-[var(--ui-ink-muted)]",children:wt(k.workBlockTemplates.find(p=>p.id===i.templateId)??{id:i.templateId,title:i.title,kind:i.kind,color:i.color,startsOn:null,endsOn:null,blockingState:i.blockingState,createdAt:i.createdAt,updatedAt:i.updatedAt})})]},i.id)),o.map(i=>e.jsxs("div",{"data-calendar-item":"true",draggable:!0,onDragStart:p=>{l(i.id),p.dataTransfer.setData("text/forge-event-id",i.id)},onClick:p=>{p.stopPropagation(),re(i),ne(null),ie(!0)},className:`min-w-0 cursor-move overflow-hidden rounded-[18px] px-3 py-2 text-left text-sm text-[var(--ui-ink-strong)] transition ${pe.useCalendarColors?"hover:brightness-110":"border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)] hover:shadow-[var(--ui-shadow-soft)]"}`,style:pe.useCalendarColors?{backgroundColor:`${(i.calendarId?Ee[i.calendarId]:null)??ct(`origin:${i.originType}`)}1f`,border:`1px solid ${(i.calendarId?Ee[i.calendarId]:null)??ct(`origin:${i.originType}`)}55`}:void 0,children:[(ye(i),e.jsxs("div",{className:"flex min-w-0 items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"line-clamp-2 [overflow-wrap:anywhere] font-medium",children:i.title}),e.jsxs("div",{className:"mt-1 text-[var(--ui-ink-soft)]",children:[new Date(i.startAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})," ","-"," ",new Date(i.endAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:e.jsx("button",{type:"button","aria-label":`Open quick actions for ${i.title}`,className:"rounded-full bg-[var(--ui-surface-2)] p-1.5 text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",onClick:p=>{p.stopPropagation(),ge({kind:"event",eventId:i.id,position:{x:p.clientX,y:p.clientY}})},children:e.jsx(ze,{className:"size-4"})})})]})),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[e.jsx(S,{size:"sm",className:"max-w-full bg-[var(--ui-surface-2)] px-2 py-0.5 text-[10px] uppercase tracking-[0.14em] text-[var(--ui-ink-medium)]",children:Ma(i,Et)}),ye(i).rateApPerHour>0?e.jsxs(e.Fragment,{children:[e.jsx(S,{size:"sm",className:"bg-[var(--primary)]/14 px-2 py-0.5 text-[10px] uppercase tracking-[0.14em] text-[var(--primary)]",children:ee(ye(i).rateApPerHour)}),e.jsx(S,{size:"sm",className:"bg-[var(--ui-surface-2)] px-2 py-0.5 text-[10px] uppercase tracking-[0.14em] text-[var(--ui-ink-medium)]",children:ce(ye(i).totalAp)})]}):null,i.calendarId&&pe.useCalendarColors?e.jsx("span",{"aria-hidden":"true",className:"size-2.5 shrink-0 rounded-full",style:{backgroundColor:Ee[i.calendarId]}}):null]}),i.place.address||i.place.timezone?e.jsxs("div",{className:"mt-2 text-xs leading-5 text-[var(--ui-ink-muted)]",children:[i.place.address||i.location,i.place.address&&i.place.timezone?" · ":"",i.place.timezone]}):null,i.links.length>0?e.jsx("div",{className:"mt-2 flex min-w-0 flex-wrap gap-1.5",children:i.links.slice(0,3).map(p=>{const T=jt(p.entityType);return T?e.jsx(Qe,{kind:T,label:zt.get(`${p.entityType}:${p.entityId}`)??p.entityType,compact:!0,gradient:!1},p.id):e.jsx(S,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:p.entityType},p.id)})}):null]},i.id)),O.map(i=>e.jsxs("div",{"data-calendar-item":"true",draggable:!0,onDragStart:p=>{n(i.id),p.dataTransfer.setData("text/forge-timebox-id",i.id)},onClick:()=>{me(i),ae(!0)},className:"min-w-0 cursor-move overflow-hidden rounded-[18px] border border-[color-mix(in_srgb,var(--primary)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-accent-soft)] px-3 py-2 text-left text-sm text-[var(--ui-ink-strong)] shadow-[var(--ui-shadow-soft)] transition hover:border-[color-mix(in_srgb,var(--primary)_42%,var(--ui-border-strong)_58%)] hover:bg-[var(--ui-accent-soft-hover)]",children:[(()=>{const p=ha(i);return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex min-w-0 items-start justify-between gap-2",children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"line-clamp-2 font-medium leading-5 text-[var(--ui-ink-strong)]",children:i.title}),e.jsxs("div",{className:"mt-1 flex items-center gap-2 text-[var(--ui-ink-soft)]",children:[e.jsx(Yt,{className:"size-3.5 shrink-0"}),new Date(i.startsAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})," ","-"," ",new Date(i.endsAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]})]})}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[e.jsx(S,{size:"sm",className:"bg-[var(--ui-surface-2)] px-2 py-0.5 text-[10px] uppercase tracking-[0.14em] text-[var(--ui-ink-medium)]",children:i.status}),e.jsx(S,{size:"sm",className:"bg-[var(--primary)]/14 px-2 py-0.5 text-[10px] uppercase tracking-[0.14em] text-[var(--primary)]",children:ee(p.rateApPerHour)}),e.jsx(S,{size:"sm",className:"bg-[var(--ui-surface-2)] px-2 py-0.5 text-[10px] uppercase tracking-[0.14em] text-[var(--ui-ink-medium)]",children:ce(p.totalAp)})]})]})})(),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",onClick:p=>{p.stopPropagation(),me(i),ae(!0)},className:"rounded-[999px] bg-[var(--ui-surface-2)] px-2.5 py-1 text-[10px] uppercase tracking-[0.14em] text-[var(--ui-ink-medium)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",children:"Edit"}),e.jsx("button",{type:"button",onClick:p=>{p.stopPropagation(),a(`/tasks/${i.taskId}`)},className:"rounded-[999px] bg-[var(--ui-surface-2)] px-2.5 py-1 text-[10px] uppercase tracking-[0.14em] text-[var(--ui-ink-medium)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",children:"Open task"})]})]},i.id)),C.length===0&&o.length===0&&O.length===0?e.jsx("div",{className:"min-h-[10rem] rounded-[18px] border border-dashed border-[var(--ui-border-subtle)] px-3 py-4 text-sm leading-8 text-[var(--ui-ink-muted)]",children:"Nothing scheduled here yet. Click inside this day to create, block, or paste."}):null]})]},r)})})]}),e.jsxs("section",{className:"grid gap-5 xl:grid-cols-[minmax(0,1.2fr)_minmax(0,0.8fr)]",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs(G,{className:"rounded-[28px] border border-[var(--ui-border-subtle)] !bg-[var(--ui-surface-1)] shadow-[var(--ui-shadow-soft)]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"rounded-[18px] bg-[var(--primary)]/14 p-3 text-[var(--primary)]",children:e.jsx(le,{className:"size-4"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:"Create event"}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:"Add a native Forge event with linked context."})]})]}),e.jsx("p",{className:"mt-4 text-sm leading-6 text-[var(--ui-ink-medium)]",children:"Create a real calendar event even with no provider connected, then project it remotely whenever you choose."}),e.jsx("div",{className:"mt-4",children:e.jsxs(Z,{onClick:()=>{R(null),re(null),ne(null),ie(!0)},children:[e.jsx(le,{className:"size-4"}),"Open event guide"]})})]}),e.jsxs(G,{className:"rounded-[28px] border border-[var(--ui-border-subtle)] !bg-[var(--ui-surface-1)] shadow-[var(--ui-shadow-soft)]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"rounded-[18px] bg-[var(--primary)]/14 p-3 text-[var(--primary)]",children:e.jsx(Me,{className:"size-4"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:"Create work block"}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:"Block main activity or protect creative windows."})]})]}),e.jsx("p",{className:"mt-4 text-sm leading-6 text-[var(--ui-ink-medium)]",children:"Open the guided flow to create half-day presets, holidays, or custom recurring work blocks."}),e.jsx("div",{className:"mt-4",children:e.jsxs(Z,{onClick:()=>{R(null),M(!0)},children:[e.jsx(Me,{className:"size-4"}),"Open work-block guide"]})})]}),e.jsxs(G,{className:"rounded-[28px] border border-[var(--ui-border-subtle)] !bg-[var(--ui-surface-1)] shadow-[var(--ui-shadow-soft)]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"rounded-[18px] bg-[var(--primary)]/14 p-3 text-[var(--primary)]",children:e.jsx(We,{className:"size-4"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:"Plan timebox"}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:"Let Forge recommend valid upcoming slots."})]})]}),e.jsx("p",{className:"mt-4 text-sm leading-6 text-[var(--ui-ink-medium)]",children:"Choose a task, review the suggested windows, and schedule directly into the calendar."}),e.jsx("div",{className:"mt-4",children:e.jsxs(Z,{onClick:()=>ae(!0),children:[e.jsx(We,{className:"size-4"}),"Open planning guide"]})})]}),e.jsxs(G,{className:"rounded-[28px] border border-[var(--ui-border-subtle)] !bg-[var(--ui-surface-1)] shadow-[var(--ui-shadow-soft)]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"rounded-[18px] bg-[var(--primary)]/14 p-3 text-[var(--primary)]",children:e.jsx(nt,{className:"size-4"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:"Manage provider settings"}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:$t})]})]}),e.jsx("p",{className:"mt-4 text-sm leading-6 text-[var(--ui-ink-medium)]",children:"Provider connections and setup instructions now live in Settings so the calendar view can stay focused on the week."}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsxs(Z,{variant:"secondary",onClick:()=>a("/settings/calendar"),children:[e.jsx(Xt,{className:"size-4"}),"Open calendar settings"]}),e.jsxs(Z,{variant:"secondary",onClick:()=>a("/settings/calendar?intent=connect"),children:[e.jsx(nt,{className:"size-4"}),"Connect provider"]})]})]})]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs(G,{className:"rounded-[28px] border border-[var(--ui-border-subtle)] !bg-[var(--ui-surface-1)] shadow-[var(--ui-shadow-soft)]",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"This week"}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Quick status for the currently visible week."})]}),e.jsxs(Z,{variant:"secondary",onClick:()=>void X.refetch(),children:[e.jsx(st,{className:"size-4"}),"Refresh view"]})]}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] !bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Provider events"}),e.jsx("div",{className:"mt-2 font-display text-3xl text-[var(--ui-ink-strong)]",children:k.events.length})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] !bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Work blocks"}),e.jsx("div",{className:"mt-2 font-display text-3xl text-[var(--ui-ink-strong)]",children:k.workBlockInstances.length})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] !bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Planned timeboxes"}),e.jsx("div",{className:"mt-2 font-display text-3xl text-[var(--ui-ink-strong)]",children:Mt.length})]})]})]}),e.jsxs(G,{className:"rounded-[28px] border border-[var(--ui-border-subtle)] !bg-[var(--ui-surface-1)] shadow-[var(--ui-shadow-soft)]",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Guided actions"}),e.jsxs("div",{className:"mt-3 grid gap-3",children:[e.jsxs("button",{type:"button",onClick:()=>ue(!0),className:"rounded-[22px] border border-[var(--ui-border-subtle)] !bg-[var(--ui-surface-2)] px-4 py-4 text-left transition hover:border-[var(--ui-border-strong)] hover:!bg-[var(--ui-surface-hover)]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:"Adjust task blocking rules"}),e.jsx(S,{className:"bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)]",children:"Guided"})]}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Decide which work blocks, calendar conditions, and event keywords should block or allow a task."})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] !bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:"Active templates"}),e.jsx(S,{className:"bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)]",children:k.workBlockTemplates.length})]}),e.jsxs("div",{className:"mt-3 grid gap-2",children:[k.workBlockTemplates.slice(0,4).map(t=>e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] !bg-[var(--ui-surface-1)] px-3 py-3 text-sm text-[var(--ui-ink-medium)]",children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:t.title}),e.jsxs("div",{className:"mt-1 text-[var(--ui-ink-soft)]",children:[kt(t.kind)," ·"," ",t.weekDays.length," day",t.weekDays.length===1?"":"s"," ·"," ",t.blockingState]}),e.jsx("div",{className:"mt-1 text-[var(--ui-ink-muted)]",children:wt(t)}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsxs(Z,{variant:"secondary",size:"sm",onClick:()=>{R(t),M(!0)},children:[e.jsx(le,{className:"size-3.5"}),"Edit"]}),e.jsxs(Z,{variant:"secondary",size:"sm",onClick:()=>void De.mutateAsync(t.id),children:[e.jsx(_e,{className:"size-3.5"}),"Delete"]})]})]},t.id)),k.workBlockTemplates.length===0?e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"No recurring templates yet. Open the work-block guide to create the first one."}):null]})]})]})]})]})]}),e.jsx(Oa,{open:$,onOpenChange:t=>{M(t),t||R(null)},pending:Ye.isPending||Xe.isPending,template:L,onSubmit:async t=>{if(L){await Xe.mutateAsync({templateId:L.id,patch:t});return}await Ye.mutateAsync(t)}}),e.jsx(wa,{open:te,onOpenChange:ue,tasks:b.snapshot.tasks,onSave:async({taskId:t,schedulingRules:r,plannedDurationSeconds:o})=>{await xa(t,{schedulingRules:r,plannedDurationSeconds:o}),await b.refresh(),await F(),await y.invalidateQueries({queryKey:["task-context",t]})}}),e.jsx(ja,{open:Ce,onOpenChange:Lt,tasks:b.snapshot.tasks,editingTimebox:Y,from:H.from,to:H.to,onCreateTimebox:async t=>{await It.mutateAsync(t)},onUpdateTimebox:async(t,r)=>{await Dt.mutateAsync({timeboxId:t,patch:r})},onDeleteTimebox:async t=>{await Ot.mutateAsync(t),Je()}}),e.jsx(Pa,{open:Ct,onOpenChange:t=>{ie(t),t||(re(null),ne(null))},writableCalendars:_t,linkOptions:Fe,event:Te,seed:Tt??void 0,onSubmit:async t=>{if(Te){const r=Te.id;ie(!1),re(null),ne(null),J.mutateAsync({eventId:r,patch:t}).catch(()=>{});return}else{ie(!1),re(null),ne(null),we.mutateAsync(t).catch(()=>{});return}},pending:we.isPending||J.isPending}),e.jsx(Da,{open:se!==null,onOpenChange:t=>{t||Ie(null)},initialTitle:(se==null?void 0:se.title)??"",pending:J.isPending,onSubmit:async t=>{if(!se)return;const r=se.id;Ie(null),J.mutateAsync({eventId:r,patch:{title:t}}).catch(()=>{})}}),e.jsx(Ca,{open:w!==null,title:(w==null?void 0:w.kind)==="event"?((at=k.events.find(t=>t.id===w.eventId))==null?void 0:at.title)??"Event actions":(w==null?void 0:w.kind)==="work-block"?((it=k.workBlockTemplates.find(t=>t.id===w.templateId))==null?void 0:it.title)??"Work block actions":(w==null?void 0:w.kind)==="day"?Re(Ae.find(t=>t.toISOString().slice(0,10)===w.dayKey)??c):"Calendar actions",subtitle:(w==null?void 0:w.kind)==="day"?"Choose what to create or paste into this day.":(w==null?void 0:w.kind)==="work-block"?"Edit or remove this recurring work block.":f?`Clipboard ready: ${f.label}`:"Quick calendar event actions.",items:Bt,position:(w==null?void 0:w.position)??null,onClose:()=>ge(null)})]})}export{Xa as CalendarPage};
@@ -1 +0,0 @@
1
- import{r as v,j as a}from"./vendor-Dnkkx2co.js";import{i as D}from"./state-vCcAT5Hq.js";import{Q as K,cV as C,F as y,j as I,I as B,B as R,T as S,cW as W}from"./index-QJkjKYzZ.js";const $=[10,15,30,45,60];function A(){return{mode:"add",minutes:15,note:""}}function U({open:s,onOpenChange:t,entityType:p,entityId:u,targetLabel:l,currentCreditedSeconds:m,pending:k=!1,onSubmit:h}){const[c,b]=v.useState(A),[g,f]=v.useState(null);v.useEffect(()=>{s&&(b(A()),f(null))},[s]);const e=D({queryKey:["forge-xp-metrics"],queryFn:W,enabled:s}),d=v.useMemo(()=>{var x;const o=(x=e.data)==null?void 0:x.metrics.rules.find(w=>w.code==="task_run_progress"),i=Math.max(1,Number((o==null?void 0:o.config.intervalMinutes)??10)),n=Number((o==null?void 0:o.config.fixedXp)??4);return{intervalMinutes:i,fixedXp:n,intervalSeconds:i*60}},[e.data]),r=v.useMemo(()=>{const o=Math.max(0,Math.trunc(c.minutes||0)),i=c.mode==="add"?o:-o,n=Math.max(0,Math.floor(m/60)),x=i>=0?i:-Math.min(Math.abs(i),n),w=Math.max(0,m+x*60),T=Math.floor(Math.max(0,m)/d.intervalSeconds),M=Math.floor(w/d.intervalSeconds)-T;return{requestedDeltaMinutes:i,appliedDeltaMinutes:x,nextCreditedSeconds:w,bucketDelta:M,xpDelta:M*d.fixedXp,maxRemovableMinutes:n}},[d.fixedXp,d.intervalSeconds,m,c.minutes,c.mode]),N=[{id:"adjustment",eyebrow:p==="task"?"Task work":"Project work",title:`Adjust tracked work for ${l}`,description:"Use this for retrospective minute corrections. Forge will add or remove tracked minutes and adjust progress XP automatically when a reward bucket is crossed.",render:(o,i)=>a.jsxs(a.Fragment,{children:[a.jsx(y,{label:"Mode",labelHelp:"Add minutes when work happened off-timer. Remove minutes when the tracked total needs a correction.",children:a.jsx(I,{value:o.mode,onChange:n=>i({mode:n}),options:[{value:"add",label:"Add minutes",description:"Record extra work that already happened."},{value:"remove",label:"Remove minutes",description:"Correct tracked time without deleting the work history."}]})}),a.jsx(y,{label:"Minutes",description:`Currently tracked: ${Math.floor(m/60)} minutes.`,hint:o.mode==="remove"?`You can remove up to ${r.maxRemovableMinutes} whole minutes from the current credited total.`:void 0,children:a.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[a.jsx(B,{type:"number",min:1,className:"w-36",value:o.minutes,onChange:n=>i({minutes:Number(n.target.value)||0})}),a.jsx("div",{className:"flex flex-wrap gap-2",children:$.map(n=>a.jsxs(R,{type:"button",variant:o.minutes===n?"primary":"secondary",onClick:()=>i({minutes:n}),children:[n," min"]},n))})]})}),a.jsxs("div",{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[a.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Preview"}),a.jsxs("div",{className:"mt-3 grid gap-3 md:grid-cols-3",children:[a.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-1)] px-4 py-3",children:[a.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Applied minutes"}),a.jsxs("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:[r.appliedDeltaMinutes>0?"+":"",r.appliedDeltaMinutes]})]}),a.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-1)] px-4 py-3",children:[a.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"XP delta"}),a.jsxs("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:[r.xpDelta>0?"+":"",r.xpDelta]})]}),a.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-1)] px-4 py-3",children:[a.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"New tracked total"}),a.jsxs("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:[Math.floor(r.nextCreditedSeconds/60)," min"]})]})]}),a.jsxs("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-soft)]",children:["Reward cadence: ",d.fixedXp," XP every"," ",d.intervalMinutes," credited minutes."," ",r.bucketDelta===0?"This change does not cross a reward bucket.":`This change crosses ${Math.abs(r.bucketDelta)} reward bucket${Math.abs(r.bucketDelta)===1?"":"s"}.`]})]}),a.jsx(y,{label:"Note",description:"Optional context for why this correction is being added. The note stays attached to the adjustment metadata.",children:a.jsx(S,{className:"min-h-28",value:o.note,onChange:n=>i({note:n.target.value}),placeholder:"Captured the review session that happened away from the live timer."})})]})}];return a.jsx(K,{open:s,onOpenChange:t,eyebrow:p==="task"?"Adjust task work":"Adjust project work",title:`Adjust work for ${l}`,description:"Add or remove tracked minutes without creating a live task run.",value:c,onChange:b,draftPersistenceKey:`work-adjustment.${p}.${u}`,steps:N,submitLabel:"Save adjustment",pending:k,pendingLabel:"Saving adjustment...",error:g,onSubmit:async()=>{var x;f(null);const o=Math.max(0,Math.trunc(c.minutes||0)),i=c.mode==="add"?o:-o,n=C.safeParse({entityType:p,entityId:u,deltaMinutes:i,note:c.note});if(!n.success){f(((x=n.error.issues[0])==null?void 0:x.message)??"Enter a valid minute adjustment.");return}try{await h({entityType:p,entityId:u,deltaMinutes:n.data.deltaMinutes,note:n.data.note||void 0}),t(!1)}catch(w){f(w instanceof Error?w.message:"Could not save the work adjustment right now.")}}})}const E={allowWorkBlockKinds:[],blockWorkBlockKinds:[],allowCalendarIds:[],blockCalendarIds:[],allowEventTypes:[],blockEventTypes:[],allowEventKeywords:[],blockEventKeywords:[],allowAvailability:[],blockAvailability:[]};function X(s){return s.map(t=>t.trim().toLowerCase()).filter(Boolean)}function j(s,t){const p=X(s);if(p.length===0)return!1;const u=t.join(" ").toLowerCase();return p.some(l=>u.includes(l))}function F(s){return s.allowWorkBlockKinds.length>0||s.allowCalendarIds.length>0||s.allowEventTypes.length>0||s.allowEventKeywords.length>0||s.allowAvailability.length>0}function P(s,t){return s??t??E}function z(s){const t=s.rules??E,u=(s.at??new Date).getTime(),l=s.overview,m=(l==null?void 0:l.workBlockInstances.filter(e=>{const d=new Date(e.startAt).getTime(),r=new Date(e.endAt).getTime();return d<=u&&u<r}))??[],k=(l==null?void 0:l.events.filter(e=>{if(e.deletedAt)return!1;const d=new Date(e.startAt).getTime(),r=new Date(e.endAt).getTime();return d<=u&&u<r}))??[],h=[],c=m.some(e=>t.blockWorkBlockKinds.includes(e.kind))||k.some(e=>(e.calendarId?t.blockCalendarIds.includes(e.calendarId):!1)||t.blockEventTypes.includes(e.eventType)||t.blockAvailability.includes(e.availability)||j(t.blockEventKeywords,[e.title,e.description,e.location,...e.categories]));c&&(m.some(e=>t.blockWorkBlockKinds.includes(e.kind))&&h.push("The current work block is marked as blocked."),k.some(e=>e.calendarId?t.blockCalendarIds.includes(e.calendarId):!1)&&h.push("The active calendar belongs to a blocked calendar source."),k.some(e=>t.blockEventTypes.includes(e.eventType))&&h.push("The active calendar event type is blocked."),k.some(e=>t.blockAvailability.includes(e.availability))&&h.push("The active calendar availability is blocked."),k.some(e=>j(t.blockEventKeywords,[e.title,e.description,e.location,...e.categories]))&&h.push("The active calendar event matches a blocked keyword."));const b=F(t),g=m.some(e=>t.allowWorkBlockKinds.includes(e.kind))||k.some(e=>(e.calendarId?t.allowCalendarIds.includes(e.calendarId):!1)||t.allowEventTypes.includes(e.eventType)||t.allowAvailability.includes(e.availability)||j(t.allowEventKeywords,[e.title,e.description,e.location,...e.categories]));!c&&b&&!g&&h.push("The current calendar context does not match the allowed rules yet.");const f=[...m.map(e=>`${e.title} (${e.kind.replaceAll("_"," ")})`),...k.map(e=>e.title)];return h.length>0?{blocked:!0,label:"Blocked right now",tone:"blocked",conflicts:h,context:f}:f.length>0?{blocked:!1,label:"Allowed right now",tone:"allowed",conflicts:[],context:f}:{blocked:!1,label:b?"Waiting for an allowed calendar context":"No live calendar conflict right now",tone:b?"waiting":"allowed",conflicts:[],context:[]}}function Y(s,t){return P(s.schedulingRules,t)}export{U as W,z as e,Y as g};
@@ -1 +0,0 @@
1
- import{j as e}from"./vendor-Dnkkx2co.js";import{C as h,c as d}from"./index-QJkjKYzZ.js";import{P as $}from"./page-hero-CONuJu5J.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";const B=[{id:"health-ready",title:"Health ready",desiredEnabled:!0,appliedEnabled:!0,authorizationStatus:"approved",syncEligible:!0,lastObservedAt:"2026-04-12T09:00:00.000Z"},{id:"movement-pending-phone",title:"Movement pending on phone",desiredEnabled:!0,appliedEnabled:!1,authorizationStatus:"pending",syncEligible:!1,lastObservedAt:"2026-04-12T09:04:00.000Z"},{id:"screen-time-denied",title:"Screen Time denied",desiredEnabled:!0,appliedEnabled:!0,authorizationStatus:"denied",syncEligible:!1,lastObservedAt:"2026-04-12T08:54:00.000Z"},{id:"health-off",title:"Health off",desiredEnabled:!1,appliedEnabled:!1,authorizationStatus:"disabled",syncEligible:!1,lastObservedAt:null}],Z=[{id:"gap-stay",title:"Quiet short gap",gapSeconds:1080,displacementMeters:42,hasStartBoundary:!0,hasEndBoundary:!0},{id:"gap-short-jump",title:"Suppressed short jump",gapSeconds:240,displacementMeters:260,hasStartBoundary:!0,hasEndBoundary:!0},{id:"gap-trip",title:"Repaired move",gapSeconds:1320,displacementMeters:1850,hasStartBoundary:!0,hasEndBoundary:!0},{id:"gap-missing-long",title:"Long missing gap",gapSeconds:7200,displacementMeters:320,hasStartBoundary:!0,hasEndBoundary:!0},{id:"gap-missing-boundary",title:"Missing boundary anchor",gapSeconds:960,displacementMeters:null,hasStartBoundary:!1,hasEndBoundary:!0}],D=[{id:"overnight-gap-before-move",title:"Exact overnight stay-gap-move bug",rangeStart:"2026-04-05T21:15:00.000Z",rangeEnd:"2026-04-06T02:40:00.000Z",segments:[{id:"stay-home-evening",kind:"stay",startedAt:"2026-04-05T21:15:00.000Z",endedAt:"2026-04-05T21:30:00.000Z",placeLabel:"Home",placeExternalUid:"place_home",startCoordinate:{latitude:46.5191,longitude:6.6323},endCoordinate:{latitude:46.5191,longitude:6.6323}},{id:"trip-night-move",kind:"trip",startedAt:"2026-04-06T02:34:00.000Z",endedAt:"2026-04-06T02:40:00.000Z",placeLabel:"Night move",placeExternalUid:null,startCoordinate:{latitude:46.5216,longitude:6.6404},endCoordinate:{latitude:46.5226,longitude:6.6424}}]},{id:"repeated-home-stays",title:"Repeated home stays coalesce",rangeStart:"2026-04-05T07:00:00.000Z",rangeEnd:"2026-04-05T08:44:00.000Z",segments:[{id:"stay-home-1",kind:"stay",startedAt:"2026-04-05T07:00:00.000Z",endedAt:"2026-04-05T08:00:00.000Z",placeLabel:"Home",placeExternalUid:"place_home",startCoordinate:{latitude:46.5191,longitude:6.6323},endCoordinate:{latitude:46.5191,longitude:6.6323}},{id:"stay-home-2",kind:"stay",startedAt:"2026-04-05T08:20:00.000Z",endedAt:"2026-04-05T08:40:00.000Z",placeLabel:"Home",placeExternalUid:"place_home",startCoordinate:{latitude:46.51912,longitude:6.63231},endCoordinate:{latitude:46.51912,longitude:6.63231}},{id:"trip-start-anchor",kind:"trip",startedAt:"2026-04-05T08:44:00.000Z",endedAt:"2026-04-05T08:49:00.000Z",placeLabel:"Walk out",placeExternalUid:null,startCoordinate:{latitude:46.5217,longitude:6.6405},endCoordinate:{latitude:46.5221,longitude:6.6412}}]}],U=[{id:"user-override-home-window",title:"User-defined missing box overrides one automatic home stay",rawMeasurements:[{id:"raw-stay-home",label:"Raw stay · Home",startedAt:"2026-04-05T08:00:00.000Z",endedAt:"2026-04-05T10:00:00.000Z"}],automaticBoxes:[{id:"auto-stay-home",kind:"stay",origin:"recorded",startedAt:"2026-04-05T08:00:00.000Z",endedAt:"2026-04-05T10:00:00.000Z",title:"Home"}],userBoxes:[{id:"user-missing-home-window",kind:"missing",origin:"user_invalidated",startedAt:"2026-04-05T08:30:00.000Z",endedAt:"2026-04-05T09:00:00.000Z",title:"User invalidated automatic movement",overrideCount:1}],projectedBoxes:[{id:"projected-home-early",kind:"stay",sourceKind:"automatic",origin:"recorded",startedAt:"2026-04-05T08:00:00.000Z",endedAt:"2026-04-05T08:30:00.000Z",title:"Home",overrideCount:0},{id:"projected-home-user-missing",kind:"missing",sourceKind:"user_defined",origin:"user_invalidated",startedAt:"2026-04-05T08:30:00.000Z",endedAt:"2026-04-05T09:00:00.000Z",title:"User invalidated automatic movement",overrideCount:1},{id:"projected-home-late",kind:"stay",sourceKind:"automatic",origin:"recorded",startedAt:"2026-04-05T09:00:00.000Z",endedAt:"2026-04-05T10:00:00.000Z",title:"Home",overrideCount:0}]}],T=3600,O=300,R=100;function N(t,s){return Math.max(0,Math.round((Date.parse(s)-Date.parse(t))/1e3))}function L(t,s){if(!t||!s)return null;const i=6371e3,g=(s.latitude-t.latitude)*Math.PI/180,l=(s.longitude-t.longitude)*Math.PI/180,u=t.latitude*Math.PI/180,c=s.latitude*Math.PI/180,m=Math.sin(g/2)**2+Math.cos(u)*Math.cos(c)*Math.sin(l/2)**2,r=2*Math.atan2(Math.sqrt(m),Math.sqrt(1-m));return i*r}function I(t,s){if(t.placeExternalUid&&s.placeExternalUid&&t.placeExternalUid===s.placeExternalUid)return!0;const i=L(t.endCoordinate,s.startCoordinate);return i!==null&&i<=R}function H(t){return t.gapSeconds>3600?{kind:"missing",origin:"missing",reason:"Gap exceeded one hour, so Forge keeps it as explicit missing data.",suppressedShortJump:!1}:!t.hasStartBoundary||!t.hasEndBoundary||t.displacementMeters===null?{kind:"missing",origin:"missing",reason:"One or both boundary anchors were missing, so the gap stays missing instead of inventing movement.",suppressedShortJump:!1}:t.displacementMeters<=100?{kind:"stay",origin:"repaired_gap",reason:"Boundary displacement stayed within 100 m, so the gap repairs into one stay.",suppressedShortJump:!1}:t.gapSeconds<300?{kind:"stay",origin:"repaired_gap",reason:"The jump crossed 100 m but stayed under five minutes, so Forge suppresses it into stay continuity.",suppressedShortJump:!0}:{kind:"trip",origin:"repaired_gap",reason:"The gap stayed under one hour, crossed 100 m, and lasted at least five minutes, so Forge repairs it into a move.",suppressedShortJump:!1}}function P(t){var E,w,_,C;const s=[...t.segments].sort((a,o)=>a.startedAt.localeCompare(o.startedAt)),i=[];if(s.length===0)return{segments:[],uncoveredIntervals:[]};const g=s[0];N(t.rangeStart,g.startedAt)>0&&i.push({id:`missing_${t.rangeStart}_${g.startedAt}`,kind:"missing",origin:"missing",startedAt:t.rangeStart,endedAt:g.startedAt,title:"Missing data"}),s.forEach((a,o)=>{if(o>0){const n=s[o-1],y=N(n.endedAt,a.startedAt);y>0&&(y>T?i.push({id:`missing_${n.id}_${a.id}`,kind:"missing",origin:"missing",startedAt:n.endedAt,endedAt:a.startedAt,title:"Missing data"}):I(n,a)?i.push({id:`repaired_stay_${n.id}_${a.id}`,kind:"stay",origin:"repaired_gap",startedAt:n.endedAt,endedAt:a.startedAt,title:n.placeLabel??a.placeLabel??"Repaired stay"}):L(n.endCoordinate,a.startCoordinate)===null?i.push({id:`missing_${n.id}_${a.id}`,kind:"missing",origin:"missing",startedAt:n.endedAt,endedAt:a.startedAt,title:"Missing data"}):y<O?i.push({id:`repaired_short_jump_${n.id}_${a.id}`,kind:"stay",origin:"repaired_gap",startedAt:n.endedAt,endedAt:a.startedAt,title:n.placeLabel??a.placeLabel??"Repaired stay"}):i.push({id:`repaired_trip_${n.id}_${a.id}`,kind:"trip",origin:"repaired_gap",startedAt:n.endedAt,endedAt:a.startedAt,title:"Repaired move"}))}i.push({id:a.id,kind:a.kind,origin:"recorded",startedAt:a.startedAt,endedAt:a.endedAt,title:a.placeLabel??a.kind})});const l=s[s.length-1],u=N(l.endedAt,t.rangeEnd);u>0&&(l.kind==="stay"&&u<=T?i.push({id:`continued_${l.id}_${t.rangeEnd}`,kind:"stay",origin:"continued_stay",startedAt:l.endedAt,endedAt:t.rangeEnd,title:l.placeLabel??"Continued stay"}):i.push({id:`missing_${l.endedAt}_${t.rangeEnd}`,kind:"missing",origin:"missing",startedAt:l.endedAt,endedAt:t.rangeEnd,title:"Missing data"}));const c=[];for(const a of i){const o=c[c.length-1];if(o&&o.kind==="stay"&&a.kind==="stay"&&(o.origin!=="recorded"||a.origin!=="recorded")&&o.endedAt===a.startedAt){c[c.length-1]={...o,id:`${o.id}_${a.id}`,origin:o.origin==="continued_stay"||a.origin==="continued_stay"?"continued_stay":"repaired_gap",endedAt:a.endedAt};continue}c.push(a)}const m=[],r=[...c].sort((a,o)=>a.startedAt.localeCompare(o.startedAt));((E=r[0])==null?void 0:E.startedAt)!==t.rangeStart&&m.push({startedAt:t.rangeStart,endedAt:((w=r[0])==null?void 0:w.startedAt)??t.rangeEnd});for(let a=1;a<r.length;a+=1)r[a-1].endedAt!==r[a].startedAt&&m.push({startedAt:r[a-1].endedAt,endedAt:r[a].startedAt});return((_=r[r.length-1])==null?void 0:_.endedAt)!==t.rangeEnd&&m.push({startedAt:((C=r[r.length-1])==null?void 0:C.endedAt)??t.rangeStart,endedAt:t.rangeEnd}),{segments:r,uncoveredIntervals:m}}function F(t){return t?new Date(t).toLocaleString():"Waiting for device update"}const v="grid min-w-0 gap-4 rounded-[28px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-5",x="grid min-w-0 gap-2 rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",b="grid min-w-0 gap-2 rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-3",j="rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 py-2 text-xs text-[var(--ui-ink-soft)]",A="font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",S="text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",f="text-sm font-medium text-[var(--ui-ink-strong)]",p="text-[var(--ui-ink-soft)]",k="text-[var(--ui-ink-faint)]",z="bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]",G="bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)]",M="bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]",J="bg-[var(--ui-accent-soft)] text-[var(--primary)]";function ae(){return e.jsxs("div",{className:"mx-auto grid min-w-0 w-full max-w-[1180px] gap-5",children:[e.jsx($,{title:"Companion Sync Lab",description:"Deterministic fixtures for source-state reconciliation and movement gap repair. This route is dev-only and exists to make QA faster than recreating every phone state by hand.",badge:"Dev only"}),e.jsxs("section",{className:"grid min-w-0 gap-4 lg:grid-cols-[1.05fr_0.95fr]",children:[e.jsxs(h,{className:v,children:[e.jsxs("div",{children:[e.jsx("div",{className:A,children:"Source matrix"}),e.jsx("div",{className:`mt-2 text-sm leading-6 ${p}`,children:"These rows mirror the pairing source-state contract that the web and phone now share."})]}),e.jsx("div",{className:"grid gap-3",children:B.map(t=>e.jsxs("div",{className:x,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:f,children:t.title}),e.jsx(d,{tone:t.desiredEnabled?"signal":"meta",children:t.desiredEnabled?"Enabled":"Off"}),e.jsx(d,{tone:"meta",children:t.desiredEnabled===t.appliedEnabled?"Applied":"Pending on phone"})]}),e.jsxs("div",{className:`grid gap-1 text-xs ${p} sm:grid-cols-2`,children:[e.jsxs("div",{children:["Authorization: ",t.authorizationStatus]}),e.jsxs("div",{children:["Sync eligible: ",t.syncEligible?"Yes":"No"]}),e.jsxs("div",{children:["Desired: ",t.desiredEnabled?"On":"Off"]}),e.jsxs("div",{children:["Applied: ",t.appliedEnabled?"On":"Off"]}),e.jsxs("div",{className:"sm:col-span-2",children:["Last observed: ",F(t.lastObservedAt)]})]})]},t.id))})]}),e.jsxs(h,{className:v,children:[e.jsxs("div",{children:[e.jsx("div",{className:A,children:"Gap classifier"}),e.jsxs("div",{className:`mt-2 text-sm leading-6 ${p}`,children:["Every gap resolves to exactly one of ",e.jsx("code",{children:"stay"}),","," ",e.jsx("code",{children:"trip"}),", or ",e.jsx("code",{children:"missing"}),"."]})]}),e.jsx("div",{className:"grid gap-3",children:Z.map(t=>{const s=H(t);return e.jsxs("div",{className:x,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:f,children:t.title}),e.jsx(d,{tone:s.kind==="missing"?"meta":s.kind==="trip"?"signal":"default",children:s.kind}),e.jsx(d,{tone:"meta",children:s.origin}),s.suppressedShortJump?e.jsx(d,{className:z,children:"Suppressed short jump"}):null]}),e.jsxs("div",{className:`grid gap-1 text-xs ${p} sm:grid-cols-2`,children:[e.jsxs("div",{children:["Gap: ",Math.round(t.gapSeconds/60)," min"]}),e.jsxs("div",{children:["Displacement:"," ",t.displacementMeters===null?"unknown":`${Math.round(t.displacementMeters)} m`]}),e.jsxs("div",{children:["Start boundary:"," ",t.hasStartBoundary?"present":"missing"]}),e.jsxs("div",{children:["End boundary:"," ",t.hasEndBoundary?"present":"missing"]})]}),e.jsx("div",{className:`text-sm leading-6 ${p}`,children:s.reason})]},t.id)})})]})]}),e.jsxs(h,{className:v,children:[e.jsxs("div",{children:[e.jsx("div",{className:A,children:"Coverage preview"}),e.jsx("div",{className:`mt-2 text-sm leading-6 ${p}`,children:"These fixtures normalize a full window and highlight whether any interval would still be left uncovered."})]}),e.jsx("div",{className:"grid gap-3",children:D.map(t=>{const s=P(t);return e.jsxs("div",{className:x,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:f,children:t.title}),e.jsx(d,{className:s.uncoveredIntervals.length===0?G:M,children:s.uncoveredIntervals.length===0?"Coverage locked":"Coverage broken"}),e.jsxs(d,{tone:"meta",children:[s.segments.length," normalized segment",s.segments.length===1?"":"s"]})]}),e.jsx("div",{className:"grid gap-2",children:s.segments.map(i=>e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 py-2 text-xs text-[var(--ui-ink-soft)]",children:[e.jsx(d,{tone:i.kind==="trip"?"signal":i.kind==="missing"?"meta":"default",children:i.kind}),e.jsx(d,{tone:"meta",children:i.origin}),e.jsxs("span",{children:[new Date(i.startedAt).toLocaleTimeString()," →"," ",new Date(i.endedAt).toLocaleTimeString()]}),e.jsx("span",{className:k,children:i.title})]},i.id))}),s.uncoveredIntervals.length>0?e.jsx("div",{className:"grid gap-2",children:s.uncoveredIntervals.map(i=>e.jsxs("div",{className:`rounded-[14px] border border-[color-mix(in_srgb,var(--danger)_28%,var(--ui-border-subtle)_72%)] bg-[var(--ui-danger-soft)] px-3 py-2 text-xs ${M}`,children:["Uncovered:"," ",new Date(i.startedAt).toLocaleTimeString()," →"," ",new Date(i.endedAt).toLocaleTimeString()]},`${i.startedAt}-${i.endedAt}`))}):null]},t.id)})})]}),e.jsxs(h,{className:v,children:[e.jsxs("div",{children:[e.jsx("div",{className:A,children:"Canonical box layers"}),e.jsx("div",{className:`mt-2 text-sm leading-6 ${p}`,children:"Raw phone measurements stay immutable. Forge generates automatic boxes from them, user-defined boxes override them, and the final projected boxes are what both the web and iPhone should render."})]}),e.jsx("div",{className:"grid gap-4",children:U.map(t=>e.jsxs("div",{className:x,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:f,children:t.title}),e.jsxs(d,{tone:"meta",children:["Raw: ",t.rawMeasurements.length]}),e.jsxs(d,{tone:"meta",children:["Automatic: ",t.automaticBoxes.length]}),e.jsxs(d,{tone:"meta",children:["User: ",t.userBoxes.length]}),e.jsxs(d,{tone:"signal",children:["Projected: ",t.projectedBoxes.length]})]}),e.jsxs("div",{className:"grid gap-3 xl:grid-cols-4",children:[e.jsxs("div",{className:b,children:[e.jsx("div",{className:S,children:"Raw measurements"}),t.rawMeasurements.map(s=>e.jsxs("div",{className:j,children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:s.label}),e.jsxs("div",{children:[new Date(s.startedAt).toLocaleTimeString()," →"," ",new Date(s.endedAt).toLocaleTimeString()]})]},s.id))]}),e.jsxs("div",{className:b,children:[e.jsx("div",{className:S,children:"Automatic boxes"}),t.automaticBoxes.map(s=>e.jsxs("div",{className:j,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(d,{tone:s.kind==="trip"?"signal":s.kind==="missing"?"meta":"default",children:s.kind}),e.jsx(d,{tone:"meta",children:s.origin})]}),e.jsx("div",{className:"mt-2 font-medium text-[var(--ui-ink-strong)]",children:s.title}),e.jsxs("div",{children:[new Date(s.startedAt).toLocaleTimeString()," →"," ",new Date(s.endedAt).toLocaleTimeString()]})]},s.id))]}),e.jsxs("div",{className:b,children:[e.jsx("div",{className:S,children:"User-defined boxes"}),t.userBoxes.map(s=>e.jsxs("div",{className:j,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(d,{tone:s.kind==="missing"?"meta":"default",children:s.kind}),e.jsx(d,{className:J,children:s.origin})]}),e.jsx("div",{className:"mt-2 font-medium text-[var(--ui-ink-strong)]",children:s.title}),e.jsxs("div",{children:[new Date(s.startedAt).toLocaleTimeString()," →"," ",new Date(s.endedAt).toLocaleTimeString()]}),e.jsxs("div",{className:`mt-1 ${k}`,children:["Overrides ",s.overrideCount," automatic box",s.overrideCount===1?"":"es"]})]},s.id))]}),e.jsxs("div",{className:b,children:[e.jsx("div",{className:S,children:"Projected visible boxes"}),t.projectedBoxes.map(s=>e.jsxs("div",{className:j,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(d,{tone:s.kind==="trip"?"signal":s.kind==="missing"?"meta":"default",children:s.kind}),e.jsx(d,{tone:"meta",children:s.sourceKind})]}),e.jsx("div",{className:"mt-2 font-medium text-[var(--ui-ink-strong)]",children:s.title}),e.jsxs("div",{children:[new Date(s.startedAt).toLocaleTimeString()," →"," ",new Date(s.endedAt).toLocaleTimeString()]}),e.jsxs("div",{className:`mt-1 ${k}`,children:[s.origin,s.overrideCount>0?` · overrides ${s.overrideCount}`:""]})]},s.id))]})]})]},t.id))})]})]})}export{ae as CompanionSyncLabPage};
@@ -1 +0,0 @@
1
- import{r as w,j as e,bL as A,d0 as re,d1 as te,aI as ie,d2 as ne,d3 as le,d4 as oe,aG as de,aX as ue,cW as ce,aK as xe}from"./vendor-Dnkkx2co.js";import{R as ge,P as ve,O as me,C as fe,T as pe,D as he,a as be}from"./ui-C1iwpj2-.js";import{C as N,c,aq as D,Z as h}from"./index-QJkjKYzZ.js";import{R as _,d as O,C as I,X as B,Y as L,T as z,B as G,a as W,c as T,b as je}from"./charts-DFnEuIMB.js";function C(a){return a?new Date(`${a}T12:00:00`).toLocaleDateString(void 0,{month:"short",day:"numeric"}):"No date yet"}function E(a,s){return s==="cumulative"?a.total??a.latest??a.maximum??a.average:a.latest??a.average??a.maximum??a.minimum}function x(a,s){if(s==null)return"No reading";const r=a.unit==="steps"||a.unit==="flights"||a.unit==="kcal"||a.unit==="min"||a.unit==="swears"||a.unit==="conversations"||a.unit==="messages"?0:(a.unit==="%",1);return`${s.toLocaleString(void 0,{maximumFractionDigits:r,minimumFractionDigits:r===0||s>=100?0:1})} ${a.unit}`}function $(a){return a.deltaValue==null?"No baseline yet":`${a.deltaValue>0?"+":""}${x(a,a.deltaValue)}`}function S(a){const s="Baseline is the average of the previous up to seven stored daily readings for this metric, excluding the latest day. Delta is latest reading minus that previous-window average.";return a.category!=="conversationTone"?s:a.metric==="devrageSwearCount"?`${s} For devrage swears, days with scanned conversations and zero swears count as 0, but days with no stored scanner rows are not invented into the average.`:a.metric==="devrageAverageMaxCumulativeRage"||a.metric==="devrageMaxCumulativeRage"?`${s} For cumulative rage, each swear-bearing user message adds its swear count and each clean user message cools the running score by 1, floored at 0. The baseline is the previous tracked-days average of that daily peak metric.`:a.metric==="swearingMessagePercent"?`${s} For swearing rate, the daily value is swear-bearing user messages divided by scanned user messages for that day.`:s}function we(a){return Math.round(a*10)/10}const j={fill:"var(--ui-ink-faint)",fontSize:11},H={stroke:"var(--ui-border-subtle)"},X="var(--ui-border-subtle)",Y={stroke:"var(--ui-border-strong)",strokeWidth:1};function q(a,s){return E(a,s)}function K(a){const s=a.days.map(r=>q(r,a.aggregation)).filter(r=>r!=null);return s.length===0?{minimum:null,average:null,maximum:null,count:0}:{minimum:Math.min(...s),average:s.reduce((r,t)=>r+t,0)/s.length,maximum:Math.max(...s),count:s.length}}function V(a){return new Date(`${a}T12:00:00`).toLocaleDateString(void 0,{month:"short",day:"numeric"})}function ke({active:a,payload:s,label:r,metric:t}){var i;if(!a||!(s!=null&&s.length)||typeof r!="string")return null;const n=((i=s.find(l=>typeof l.value=="number"))==null?void 0:i.value)??null;return e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--surface-glass)] px-3 py-2 text-[var(--ui-ink-medium)] shadow-[var(--ui-shadow-floating)] backdrop-blur-xl",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:V(r)}),e.jsx("div",{className:"mt-1 text-sm font-semibold text-[var(--ui-ink-strong)]",children:x(t,n)})]})}function Z({metric:a,height:s=180,detailed:r=!1}){const t=w.useMemo(()=>K(a),[a]),n=w.useMemo(()=>a.days.map(d=>({dateKey:d.dateKey,value:q(d,a.aggregation),sampleCount:d.sampleCount})),[a]),i=n.map(d=>d.value).filter(d=>d!=null),l=i.length>0?Math.min(...i):0,v=i.length>0?Math.max(...i):1,p=Math.max((v-l)*.12,a.unit==="%"?2:1),u=f(a.category),m=`metric-gradient-${a.metric.replace(/[^a-z0-9]/gi,"-")}`;return i.length===0?e.jsx("div",{className:"flex items-center justify-center rounded-[22px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 text-center text-sm text-[var(--ui-ink-faint)]",style:{height:s},children:"Waiting for chart data"}):e.jsx("div",{className:h("overflow-hidden rounded-[22px] border bg-[var(--ui-surface-1)] p-3",u.ring),style:{height:s},children:e.jsx(_,{width:"100%",height:"100%",children:e.jsxs(O,{data:n,margin:{top:r?18:8,right:r?18:4,bottom:r?12:0,left:r?8:0},children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:m,x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"var(--primary)",stopOpacity:.55}),e.jsx("stop",{offset:"56%",stopColor:"var(--warning)",stopOpacity:.22}),e.jsx("stop",{offset:"100%",stopColor:"var(--warning)",stopOpacity:.02})]})}),e.jsx(I,{stroke:X,vertical:r}),e.jsx(B,{dataKey:"dateKey",tickFormatter:V,minTickGap:r?22:34,tick:j,axisLine:H,tickLine:!1}),e.jsx(L,{width:r?62:36,domain:[Math.max(0,l-p),v+p],tickFormatter:d=>x(a,Number(d)).replace(` ${a.unit}`,""),tick:j,axisLine:!1,tickLine:!1}),t.average!=null?e.jsx(je,{y:we(t.average),stroke:"var(--ui-ink-faint)",strokeDasharray:"5 5",ifOverflow:"extendDomain"}):null,e.jsx(z,{cursor:Y,content:e.jsx(ke,{metric:a})}),a.aggregation==="cumulative"?e.jsx(G,{dataKey:"value",radius:[8,8,2,2],fill:`url(#${m})`,maxBarSize:r?34:20}):e.jsx(W,{type:"monotone",dataKey:"value",stroke:"var(--primary)",strokeWidth:r?3:2,fill:`url(#${m})`,dot:r?{r:3,fill:"var(--warning)"}:!1,activeDot:{r:5,fill:"var(--warning)"}})]})})})}function ye({metric:a,open:s,onOpenChange:r}){const t=K(a),n=f(a.category);return e.jsx(ge,{open:s,onOpenChange:r,children:e.jsxs(ve,{children:[e.jsx(me,{className:"fixed inset-0 z-50 bg-[var(--overlay)] backdrop-blur-xl"}),e.jsxs(fe,{className:"fixed inset-3 z-[51] grid min-h-0 overflow-hidden rounded-[32px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-modal)] shadow-[var(--ui-shadow-floating)] sm:inset-5",children:[e.jsxs(pe,{className:"sr-only",children:[a.label," chart"]}),e.jsx(he,{className:"sr-only",children:"Full-screen time-series chart for the selected daily metric."}),e.jsxs("div",{className:"grid min-h-0 grid-rows-[auto_minmax(0,1fr)]",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4 border-b border-[var(--ui-border-subtle)] px-5 py-4 sm:px-6",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:[a.category," time series"]}),e.jsx("div",{className:"mt-1 break-words text-2xl font-semibold text-[var(--ui-ink-strong)] sm:text-3xl",children:a.label}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-2 text-xs text-[var(--ui-ink-soft)]",children:[e.jsx(c,{className:n.badge,children:a.aggregation}),e.jsxs(c,{tone:"meta",children:[a.coverageDays," tracked days"]}),e.jsxs(c,{tone:"meta",children:["latest ",C(a.latestDateKey)]})]})]}),e.jsx(be,{asChild:!0,children:e.jsx("button",{type:"button",className:"inline-flex size-11 items-center justify-center rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]","aria-label":"Close metric chart",children:e.jsx(xe,{className:"size-5"})})})]}),e.jsxs("div",{className:"grid min-h-0 gap-4 overflow-y-auto p-4 sm:p-6 lg:grid-cols-[minmax(0,1fr)_18rem]",children:[e.jsx(Z,{metric:a,height:560,detailed:!0}),e.jsx("div",{className:"grid content-start gap-3",children:[["Latest",a.latestValue],["Period min",t.minimum],["Period average",t.average],["Period max",t.maximum],["Baseline",a.baselineValue],["Delta",a.deltaValue]].map(([i,l])=>e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[e.jsx("span",{children:i}),i==="Baseline"?e.jsx(D,{label:`Explain ${a.label} baseline`,title:"Baseline calculation",content:S(a)}):null]})}),e.jsx("div",{className:"mt-1 break-words text-xl font-semibold text-[var(--ui-ink-strong)]",children:x(a,typeof l=="number"?l:null)})]},String(i)))})]})]})]})]})})}function Ne(a){return a.deltaValue==null||a.deltaValue===0?"steady":a.deltaValue>0?"up":"down"}function f(a){switch(a){case"recovery":return{ring:"border-[var(--danger)]/20",badge:"bg-[var(--ui-danger-soft)] text-[var(--danger)]",glow:"from-[var(--ui-danger-soft)] via-[var(--ui-surface-2)] to-transparent"};case"cardio":return{ring:"border-[var(--info)]/24",badge:"bg-[var(--ui-info-soft)] text-[var(--info)]",glow:"from-[var(--ui-info-soft)] via-[var(--ui-surface-2)] to-transparent"};case"breathing":return{ring:"border-[var(--success)]/22",badge:"bg-[var(--ui-success-soft)] text-[var(--success)]",glow:"from-[var(--ui-success-soft)] via-[var(--ui-surface-2)] to-transparent"};case"composition":return{ring:"border-[var(--warning)]/22",badge:"bg-[var(--ui-warning-soft)] text-[var(--warning)]",glow:"from-[var(--ui-warning-soft)] via-[var(--ui-surface-2)] to-transparent"};case"temperature":return{ring:"border-[var(--warning)]/22",badge:"bg-[var(--ui-warning-soft)] text-[var(--warning)]",glow:"from-[var(--ui-warning-soft)] via-[var(--ui-surface-2)] to-transparent"};case"conversationTone":return{ring:"border-[var(--warning)]/22",badge:"bg-[var(--ui-warning-soft)] text-[var(--warning)]",glow:"from-[var(--ui-warning-soft)] via-[var(--ui-surface-2)] to-transparent"};default:return{ring:"border-[var(--ui-border-subtle)]",badge:"bg-[var(--ui-accent-soft)] text-[var(--primary)]",glow:"from-[var(--ui-accent-soft)] via-[var(--ui-surface-2)] to-transparent"}}}function J(a){switch(a){case"restingHeartRate":case"walkingHeartRateAverage":case"heartRateRecoveryOneMinute":return ue;case"heartRateVariabilitySDNN":case"vo2Max":return de;case"oxygenSaturation":case"respiratoryRate":return oe;case"bodyMass":case"bodyFatPercentage":case"leanBodyMass":return le;case"stepCount":case"flightsClimbed":case"appleExerciseTime":return ne;case"basalEnergyBurned":return ie;case"swearingMessagePercent":return te;case"devrageSwearCount":case"devrageAverageMaxCumulativeRage":case"devrageMaxCumulativeRage":return re;default:return A}}function k(a,s){if(!a)return null;const r=a.aggregation,t=a.days.find(n=>n.dateKey===s);return t?E(t,r):null}function Q(a,s){return a?x(a,s):"No signal"}function De({active:a,payload:s,label:r,swearMetric:t,percentMetric:n,averageRageMetric:i,maxRageMetric:l}){if(!a||!(s!=null&&s.length)||typeof r!="string")return null;const v=new Map(s.filter(u=>typeof u.dataKey=="string").map(u=>[String(u.dataKey),u.value??null])),p=[["Max rage peak",l,v.get("maxPeak")??null],["Average rage peak",i,v.get("averagePeak")??null],["Swears",t,v.get("swears")??null],["Swearing rate",n,v.get("rate")??null]];return e.jsxs("div",{className:"min-w-56 rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--surface-glass)] p-3 shadow-[var(--ui-shadow-floating)] backdrop-blur-xl",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:V(r)}),e.jsx("div",{className:"mt-2 grid gap-2",children:p.map(([u,m,d])=>e.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3 text-xs",children:[e.jsx("span",{className:"min-w-0 text-[var(--ui-ink-soft)]",children:u}),e.jsx("span",{className:"min-w-0 break-words text-right font-semibold text-[var(--ui-ink-strong)]",children:Q(m,d)})]},u))})]})}function y({label:a,metric:s,fallback:r="No signal"}){const t=f("conversationTone");return e.jsxs("div",{className:"min-w-0 rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:a}),e.jsx("div",{className:"mt-1 break-words text-2xl font-semibold text-[var(--ui-ink-strong)]",children:s?x(s,s.latestValue):r}),s?e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap gap-2 text-xs",children:[e.jsx(c,{className:t.badge,children:$(s)}),e.jsxs(c,{tone:"meta",children:[s.coverageDays," days"]})]}):null]})}function $e({swearMetric:a,percentMetric:s,averageRageMetric:r,maxRageMetric:t,compact:n=!1}){var F;const i=w.useId().replace(/:/g,""),l=`devrage-rage-${i}`,v=`devrage-swears-${i}`,p=`devrage-panel-${i}`,u=w.useMemo(()=>Array.from(new Set([a,s,r,t].flatMap(g=>(g==null?void 0:g.days.map(se=>se.dateKey))??[]))).sort().slice(n?-14:-28).map(g=>({dateKey:g,swears:k(a,g),rate:k(s,g),averagePeak:k(r,g),maxPeak:k(t,g)})),[r,n,t,s,a]),m=u.flatMap(o=>[o.swears,o.averagePeak,o.maxPeak]).filter(o=>o!=null),d=u.map(o=>o.rate).filter(o=>o!=null),U=m.length>0||d.length>0,M=Math.max(1,...m),R=Math.max(10,...d),ee=(t==null?void 0:t.latestDateKey)??(r==null?void 0:r.latestDateKey)??(a==null?void 0:a.latestDateKey)??(s==null?void 0:s.latestDateKey)??null,b=t??r??a??s,P=(b==null?void 0:b.deltaValue)??null,ae=P==null?"Baseline forming":P>0?"Rage pressure rising":P<0?"Rage pressure cooling":"Rage pressure steady";return U?e.jsxs(N,{className:"relative overflow-hidden rounded-[30px] border border-[color-mix(in_srgb,var(--warning)_22%,var(--ui-border-subtle)_78%)] bg-[linear-gradient(135deg,color-mix(in_srgb,var(--ui-warning-soft)_30%,var(--ui-surface-section)_70%),var(--ui-surface-section)_48%,color-mix(in_srgb,var(--ui-info-soft)_18%,var(--ui-surface-section)_82%))] p-0 shadow-[var(--card-shadow)]",children:[e.jsx("div",{className:"pointer-events-none absolute inset-0 opacity-55 [background-image:linear-gradient(rgba(255,255,255,0.055)_1px,transparent_1px),linear-gradient(90deg,rgba(255,255,255,0.04)_1px,transparent_1px)] [background-size:32px_32px]"}),e.jsxs("div",{className:"relative grid gap-5 p-5 sm:p-6 lg:grid-cols-[minmax(0,1.45fr)_minmax(280px,0.75fr)]",children:[e.jsxs("div",{className:"grid min-w-0 gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--warning)]",children:"Conversation tone figure"}),e.jsx("div",{className:"mt-1 break-words text-3xl font-semibold leading-tight text-[var(--ui-ink-strong)] sm:text-4xl",children:"Cumulative rage profile"}),e.jsx("div",{className:"mt-2 max-w-2xl text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Swear volume, swearing-message rate, average thread peak, and maximum thread peak on one daily surface."})]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap gap-2",children:[e.jsx(c,{className:"bg-[var(--ui-warning-soft)] text-[var(--warning)]",children:ae}),b?e.jsx(D,{label:"Explain devrage baseline",title:"Baseline calculation",content:S(b)}):null,e.jsxs(c,{tone:"meta",children:["Latest ",C(ee)]})]})]}),e.jsx("div",{className:"overflow-hidden rounded-[26px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-3",style:{height:n?280:340},children:e.jsx(_,{width:"100%",height:"100%",children:e.jsxs(O,{data:u,margin:{top:18,right:12,bottom:0,left:0},children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:p,x1:"0",y1:"0",x2:"1",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"var(--warning)",stopOpacity:.36}),e.jsx("stop",{offset:"52%",stopColor:"var(--primary)",stopOpacity:.12}),e.jsx("stop",{offset:"100%",stopColor:"var(--info)",stopOpacity:.18})]}),e.jsxs("linearGradient",{id:l,x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"var(--warning)",stopOpacity:.62}),e.jsx("stop",{offset:"58%",stopColor:"var(--danger)",stopOpacity:.2}),e.jsx("stop",{offset:"100%",stopColor:"var(--danger)",stopOpacity:.02})]}),e.jsxs("linearGradient",{id:v,x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"var(--ui-ink-strong)",stopOpacity:.34}),e.jsx("stop",{offset:"100%",stopColor:"var(--ui-ink-faint)",stopOpacity:.06})]})]}),e.jsx(I,{stroke:X,strokeDasharray:"4 10",vertical:!1}),e.jsx(B,{dataKey:"dateKey",tickFormatter:V,minTickGap:n?36:24,tick:j,axisLine:H,tickLine:!1}),e.jsx(L,{yAxisId:"rage",width:42,domain:[0,Math.ceil(M*1.18)],tickFormatter:o=>Number(o).toFixed(0),tick:j,axisLine:!1,tickLine:!1}),e.jsx(L,{yAxisId:"rate",orientation:"right",width:42,domain:[0,Math.min(100,Math.ceil(R*1.22))],tickFormatter:o=>`${Number(o).toFixed(0)}%`,tick:j,axisLine:!1,tickLine:!1}),e.jsx(z,{cursor:Y,content:e.jsx(De,{swearMetric:a,percentMetric:s,averageRageMetric:r,maxRageMetric:t})}),e.jsx(G,{yAxisId:"rage",dataKey:"swears",radius:[10,10,3,3],fill:`url(#${v})`,maxBarSize:n?16:22}),e.jsx(W,{yAxisId:"rage",type:"monotone",dataKey:"averagePeak",stroke:"var(--warning)",strokeWidth:2,fill:`url(#${l})`,dot:!1,activeDot:{r:5,fill:"var(--warning)"}}),e.jsx(T,{yAxisId:"rage",type:"monotone",dataKey:"maxPeak",stroke:"var(--danger)",strokeWidth:3,dot:{r:3,fill:"var(--danger)"},activeDot:{r:6,fill:"var(--danger)"}}),e.jsx(T,{yAxisId:"rate",type:"monotone",dataKey:"rate",stroke:"var(--info)",strokeWidth:2,strokeDasharray:"6 6",dot:!1,activeDot:{r:5,fill:"var(--info)"}})]})})}),e.jsx("div",{className:"flex min-w-0 flex-wrap gap-2 text-xs text-[var(--ui-ink-soft)]",children:[["Swears","bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]"],["Average peak","bg-[var(--ui-warning-soft)] text-[var(--warning)]"],["Max peak","bg-[var(--ui-danger-soft)] text-[var(--danger)]"],["Swearing rate","bg-[var(--ui-info-soft)] text-[var(--info)]"]].map(([o,g])=>e.jsx(c,{className:g,children:o},o))})]}),e.jsxs("div",{className:"grid min-w-0 content-start gap-3",children:[e.jsxs("div",{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-5",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Latest peak"}),e.jsx("div",{className:"mt-2 break-words text-5xl font-semibold leading-none text-[var(--ui-ink-strong)]",children:Q(t??r,((F=t??r)==null?void 0:F.latestValue)??null)}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Peak score is the highest cumulative swear streak pressure reached inside any scanned thread for the day."})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-1 xl:grid-cols-2",children:[e.jsx(y,{label:"Average thread peak",metric:r}),e.jsx(y,{label:"Swearing rate",metric:s}),e.jsx(y,{label:"Swears",metric:a}),e.jsx(y,{label:"Max thread peak",metric:t})]})]})]})]}):e.jsxs(N,{className:"rounded-[30px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-section)] p-6",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Cumulative rage profile"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold text-[var(--ui-ink-strong)]",children:"Waiting for devrage history"}),e.jsx("p",{className:"mt-2 max-w-3xl text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Forge will draw the rage profile after the local scanner stores daily conversation-tone rows."})]})}function Ke({title:a,description:s,metric:r,emptyDescription:t}){const n=r?J(r.metric):A,i=f(r?r.category:"default"),l=r?Ne(r):"steady";return e.jsxs(N,{className:h("relative overflow-hidden rounded-[28px] border bg-[var(--ui-surface-section)] p-5 shadow-[var(--card-shadow)]",i.ring),children:[e.jsx("div",{className:h("pointer-events-none absolute inset-0 bg-gradient-to-br opacity-90",i.glow)}),e.jsxs("div",{className:"relative grid gap-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"grid min-w-0 gap-1",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:a}),e.jsx("div",{className:"break-words text-sm leading-6 text-[var(--ui-ink-soft)]",children:s})]}),e.jsx("div",{className:"shrink-0 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-3 text-[var(--ui-ink-medium)]",children:e.jsx(n,{className:"size-5"})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"break-words text-xl font-semibold text-[var(--ui-ink-strong)]",children:r?x(r,r.latestValue):"No signal yet"}),e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2 text-xs text-[var(--ui-ink-soft)]",children:[r?e.jsx(c,{className:i.badge,children:r.label}):null,r?e.jsx(c,{className:h("border-none",l==="up"?"bg-[var(--ui-success-soft)] text-[var(--success)]":l==="down"?"bg-[var(--ui-danger-soft)] text-[var(--danger)]":"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]"),children:$(r)}):null,r?e.jsx(D,{label:`Explain ${r.label} delta`,title:"Delta calculation",content:S(r)}):null,r?e.jsxs(c,{tone:"meta",children:[r.coverageDays," days tracked"]}):null]}),e.jsx("div",{className:"break-words text-xs text-[var(--ui-ink-faint)]",children:r?`Latest reading on ${C(r.latestDateKey)}`:t??"Forge will populate this card as soon as daily readings are available."})]})]})]})}function Ce({metric:a}){const[s,r]=w.useState(!1),t=J(a.metric),n=f(a.category),i=a.days.at(-1),l=K(a);return e.jsxs(N,{className:h("overflow-hidden rounded-[28px] border bg-[var(--ui-surface-section)] p-5",n.ring),children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-4 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-4",children:[e.jsx("div",{className:"shrink-0 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-3 text-[var(--ui-ink-medium)]",children:e.jsx(t,{className:"size-5"})}),e.jsxs("div",{className:"grid min-w-0 gap-1",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:a.category}),e.jsx("div",{className:"break-words text-xl font-semibold text-[var(--ui-ink-strong)]",children:a.label}),e.jsxs("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:[a.coverageDays," tracked day",a.coverageDays===1?"":"s"]})]})]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2 sm:shrink-0 sm:justify-end",children:[e.jsx(c,{className:n.badge,children:a.aggregation}),e.jsxs("button",{type:"button",className:"inline-flex min-h-9 min-w-0 max-w-full items-center gap-2 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 py-1.5 text-xs font-medium text-[var(--ui-ink-medium)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",onClick:()=>r(!0),children:[e.jsx(ce,{className:"size-3.5"}),"Full screen"]})]})]}),e.jsxs("div",{className:"mt-5 grid gap-4 md:grid-cols-[minmax(0,0.95fr)_minmax(220px,1.05fr)]",children:[e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Latest"}),e.jsx("div",{className:"mt-1 break-words text-3xl font-semibold text-[var(--ui-ink-strong)]",children:x(a,a.latestValue)}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:a.latestDateKey?`Latest reading on ${C(a.latestDateKey)}`:"Waiting for the first successful reading"})]}),e.jsxs("div",{className:"grid gap-2 rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4 text-sm text-[var(--ui-ink-medium)]",children:[e.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-2",children:[e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[e.jsx("span",{className:"min-w-0",children:"Baseline"}),e.jsx(D,{label:`Explain ${a.label} baseline`,title:"Baseline calculation",content:S(a)})]}),e.jsx("span",{className:"min-w-0 break-words text-right font-medium text-[var(--ui-ink-strong)]",children:x(a,a.baselineValue)})]}),e.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-2",children:[e.jsx("span",{className:"min-w-0",children:"Delta"}),e.jsx("span",{className:h("min-w-0 break-words text-right font-medium",a.deltaValue==null?"text-[var(--ui-ink-soft)]":a.deltaValue>0?"text-[var(--success)]":a.deltaValue<0?"text-[var(--danger)]":"text-[var(--ui-ink-strong)]"),children:$(a)})]}),e.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-2",children:[e.jsx("span",{className:"min-w-0",children:"Latest samples"}),e.jsx("span",{className:"min-w-0 break-words text-right font-medium text-[var(--ui-ink-strong)]",children:(i==null?void 0:i.sampleCount)??0})]})]})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsx(Z,{metric:a}),e.jsxs("div",{className:"grid gap-2 text-xs text-[var(--ui-ink-faint)] sm:grid-cols-3",children:[e.jsxs("div",{className:"min-w-0 rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 py-2",children:[e.jsx("div",{children:"Period min"}),e.jsx("div",{className:"mt-1 break-words font-medium text-[var(--ui-ink-medium)]",children:x(a,l.minimum)})]}),e.jsxs("div",{className:"min-w-0 rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 py-2",children:[e.jsx("div",{children:"Period avg"}),e.jsx("div",{className:"mt-1 break-words font-medium text-[var(--ui-ink-medium)]",children:x(a,l.average)})]}),e.jsxs("div",{className:"min-w-0 rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 py-2",children:[e.jsx("div",{children:"Period max"}),e.jsx("div",{className:"mt-1 break-words font-medium text-[var(--ui-ink-medium)]",children:x(a,l.maximum)})]})]})]})]}),e.jsx(ye,{metric:a,open:s,onOpenChange:r})]})}function Fe({groups:a}){return e.jsx("section",{className:"grid gap-5",children:a.map(s=>e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:s.category}),e.jsxs("div",{className:"mt-1 break-words text-2xl font-semibold text-[var(--ui-ink-strong)]",children:[s.metrics.length," signals in this lane"]})]}),e.jsxs(c,{className:f(s.category).badge,children:[s.coverageDays," days of coverage"]})]}),e.jsx("div",{className:"grid gap-4 xl:grid-cols-2",children:s.metrics.map(r=>e.jsx(Ce,{metric:r},r.metric))})]},s.category))})}export{$e as D,Fe as M,Ke as S,C as f,f as m};
@@ -1 +0,0 @@
1
- import{r as l,j as e,b4 as $e,b3 as We,cQ as Ke,ce as Xe,c7 as Pe}from"./vendor-Dnkkx2co.js";import{j as Ye,i as y,k as X}from"./state-vCcAT5Hq.js";import{u as Ze,bv as Y,cM as es,cn as u,ao as ss,bm as ts,bn as as,C as rs,aq as is,c as b,cN as ns,B as v,I as j,T as ze,bu as N,i as ls,bD as os,bw as ds,bx as cs,by as us,bz as ms,bA as ps,bB as xs,bC as ys}from"./index-QJkjKYzZ.js";import{N as Z}from"./note-markdown-CCyyE85h.js";import{n as ee,N as Me,f as vs,p as gs,b as hs}from"./note-tags-input-BS14YXHn.js";function fs(o,d,c){return o.links.filter(p=>!(p.entityType===d&&p.entityId===c))}function bs(o,d){return o.entityType===d.entityType&&o.entityId===d.entityId&&(o.anchorKey??null)===(d.anchorKey??null)}function se(o){const d=new Set;return o.filter(c=>{const p=`${c.entityType}:${c.entityId}:${c.anchorKey??""}`;return d.has(p)?!1:(d.add(p),!0)})}function Fe(o,d,c){return gs(o)??hs(d,c)}function Cs({entityType:o,entityId:d,anchorKey:c,includeAnchorlessWhenAnchored:p=!1,title:Qe="Notes",description:Be="Markdown notes linked to this entity stay searchable, editable, and visible alongside the work.",invalidateQueryKeys:Ve=[],compact:te=!1}){var Ce,Se,De,Te,Le,Ie,Ee,Ae,qe;const m=Ze(),L=Ye(),[I,Oe]=l.useState(""),[ae,E]=l.useState(!1),[h,A]=l.useState(""),[re,q]=l.useState(!1),[Ue,$]=l.useState({entityType:"goal",entityId:""}),[ie,K]=l.useState([]),[ne,P]=l.useState([]),[le,z]=l.useState(""),[oe,M]=l.useState(""),[de,F]=l.useState("days"),[He,Q]=l.useState(null),[f,B]=l.useState(""),[ce,k]=l.useState(!1),[V,O]=l.useState([]),[Re,U]=l.useState({entityType:"goal",entityId:""}),[ue,w]=l.useState([]),[me,_]=l.useState(""),[pe,C]=l.useState(""),[xe,S]=l.useState("days"),H=Y(c),ye=es(o,c),g=y({queryKey:["notes",o,d],queryFn:()=>os({linkedEntityType:o,linkedEntityId:d,limit:100})}),ve=y({queryKey:["forge-psyche-values"],queryFn:ds}),ge=y({queryKey:["forge-psyche-patterns"],queryFn:cs}),he=y({queryKey:["forge-psyche-behaviors"],queryFn:us}),fe=y({queryKey:["forge-psyche-beliefs"],queryFn:ms}),be=y({queryKey:["forge-psyche-modes"],queryFn:ps}),je=y({queryKey:["forge-psyche-flashcards"],queryFn:xs}),Ne=y({queryKey:["forge-psyche-reports"],queryFn:ys}),R=l.useMemo(()=>{var s,n,r,a,x,i,D,T;return{goal:m.snapshot.goals.map(t=>({id:t.id,label:u(t.title,t.user)})),project:m.snapshot.dashboard.projects.map(t=>({id:t.id,label:u(t.title,t.user)})),task:m.snapshot.tasks.map(t=>({id:t.id,label:u(t.title,t.user)})),strategy:m.snapshot.strategies.map(t=>({id:t.id,label:u(t.title,t.user)})),habit:m.snapshot.habits.map(t=>({id:t.id,label:u(t.title,t.user)})),tag:m.snapshot.tags.map(t=>({id:t.id,label:u(t.name,t.user)})),note:(((s=g.data)==null?void 0:s.notes)??[]).map(t=>({id:t.id,label:t.contentPlain||t.contentMarkdown})),insight:[],psyche_value:(((n=ve.data)==null?void 0:n.values)??[]).map(t=>({id:t.id,label:u(t.title,t.user)})),behavior_pattern:(((r=ge.data)==null?void 0:r.patterns)??[]).map(t=>({id:t.id,label:u(t.title,t.user)})),behavior:(((a=he.data)==null?void 0:a.behaviors)??[]).map(t=>({id:t.id,label:u(t.title,t.user)})),belief_entry:(((x=fe.data)==null?void 0:x.beliefs)??[]).map(t=>({id:t.id,label:u(t.statement,t.user)})),mode_profile:(((i=be.data)==null?void 0:i.modes)??[]).map(t=>({id:t.id,label:u(t.title,t.user)})),flashcard:(((D=je.data)==null?void 0:D.flashcards)??[]).map(t=>({id:t.id,label:u(t.title||t.message,t.user)})),mode_guide_session:[],event_type:[],emotion_definition:[],trigger_report:(((T=Ne.data)==null?void 0:T.reports)??[]).map(t=>({id:t.id,label:u(t.title,t.user)})),calendar_event:[],work_block_template:[],task_timebox:[],preference_catalog:[],preference_catalog_item:[],preference_context:[],preference_item:[],questionnaire_instrument:[],sleep_session:[],workout_session:[]}},[(Ce=he.data)==null?void 0:Ce.behaviors,(Se=fe.data)==null?void 0:Se.beliefs,(De=je.data)==null?void 0:De.flashcards,(Te=be.data)==null?void 0:Te.modes,(Le=g.data)==null?void 0:Le.notes,(Ie=ge.data)==null?void 0:Ie.patterns,(Ee=Ne.data)==null?void 0:Ee.reports,m.snapshot.dashboard.projects,m.snapshot.goals,m.snapshot.habits,m.snapshot.strategies,m.snapshot.tags,m.snapshot.tasks,(Ae=ve.data)==null?void 0:Ae.values]),G=async()=>{await Promise.all([L.invalidateQueries({queryKey:["notes",o,d]}),ls(L),...Ve.map(s=>L.invalidateQueries({queryKey:s}))])},ke=X({mutationFn:async s=>ss({contentMarkdown:s,tags:ee(ne),destroyAt:Fe(le,oe,de),links:se([{entityType:o,entityId:d,anchorKey:c??null},...ie])}),onSuccess:async()=>{A(""),q(!1),K([]),$({entityType:"goal",entityId:""}),P([]),z(""),M(""),F("days"),await G()}}),we=X({mutationFn:async({noteId:s,contentMarkdown:n,links:r,tags:a,destroyAt:x})=>ts(s,{contentMarkdown:n,links:r,tags:a,destroyAt:x}),onSuccess:async()=>{Q(null),B(""),k(!1),O([]),U({entityType:"goal",entityId:""}),w([]),_(""),C(""),S("days"),await G()}}),Ge=X({mutationFn:async s=>as(s),onSuccess:G}),J=l.useMemo(()=>{var n;return(((n=g.data)==null?void 0:n.notes)??[]).filter(r=>c===void 0?!0:r.links.some(a=>a.entityType===o&&a.entityId===d&&((a.anchorKey??null)===c||p&&(a.anchorKey??null)===null))).filter(r=>{const a=I.trim().toLowerCase();return a?`${r.contentPlain} ${r.author??""} ${(r.tags??[]).join(" ")}`.toLowerCase().includes(a):!0})},[c,d,o,p,(qe=g.data)==null?void 0:qe.notes,I]),Je=(s,n,r)=>{const a=s.entityId.trim();return a?(n(se([...r,{entityType:s.entityType,entityId:a,anchorKey:null}])),!0):!1},W=s=>{var r,a;const n=(r=R[s.entityType])==null?void 0:r.find(x=>x.id===s.entityId);return(a=n==null?void 0:n.label)!=null&&a.trim()?n.label.trim():`Deleted ${N(s.entityType)}`},_e=(s,n,r,a,x)=>e.jsxs("div",{className:"min-w-0 rounded-[20px] bg-[var(--ui-surface-1)] p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Linked entities"}),e.jsxs(b,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:[s.length," linked"]})]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:s.map(i=>{const D=s.length>1;return e.jsxs("div",{className:"inline-flex max-w-full items-center gap-2 rounded-full bg-[var(--ui-surface-2)] px-3 py-2 text-sm text-[var(--ui-ink-medium)]",children:[e.jsxs("span",{className:"min-w-0 break-words [overflow-wrap:anywhere]",children:[N(i.entityType)," · ",W(i)]}),i.anchorKey?e.jsx("span",{className:"shrink-0 rounded-full bg-[var(--ui-surface-3)] px-2 py-0.5 text-[11px] text-[var(--ui-ink-soft)]",children:Y(i.anchorKey)}):null,e.jsx("button",{type:"button",disabled:!D,className:"shrink-0 text-[var(--ui-ink-faint)] transition hover:text-[var(--ui-ink-strong)] disabled:cursor-not-allowed disabled:opacity-30",onClick:()=>n(s.filter(T=>!bs(T,i))),"aria-label":`Remove ${N(i.entityType)} link to ${W(i)}`,children:e.jsx(Pe,{className:"size-3.5"})})]},`${x}-${i.entityType}-${i.entityId}-${i.anchorKey??""}`)})}),e.jsxs("div",{className:"mt-4 grid gap-3 md:grid-cols-[minmax(0,11rem)_minmax(0,1fr)_auto]",children:[e.jsx("select",{className:"rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-3 text-[var(--ui-ink-strong)] outline-none transition focus:border-[var(--ui-border-strong)]",value:r.entityType,onChange:i=>a({...r,entityType:i.target.value,entityId:""}),children:["goal","project","task","strategy","habit","tag","note","psyche_value","behavior_pattern","behavior","belief_entry","mode_profile","mode_guide_session","flashcard","event_type","emotion_definition","trigger_report"].map(i=>e.jsx("option",{value:i,children:N(i)},i))}),e.jsxs("select",{className:"min-w-0 rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-3 text-[var(--ui-ink-strong)] outline-none transition focus:border-[var(--ui-border-strong)]",value:r.entityId,onChange:i=>a({...r,entityId:i.target.value}),children:[e.jsx("option",{value:"",children:(R[r.entityType]??[]).length>0?"Choose linked item":"No linked items available"}),(R[r.entityType]??[]).map(i=>e.jsx("option",{value:i.id,children:i.label},i.id))]}),e.jsx(v,{variant:"secondary",disabled:!r.entityId,onClick:()=>{Je(r,n,s)&&a({...r,entityId:""})},children:"Add link"})]})]});return e.jsx(rs,{id:"notes",className:te?"min-w-0 overflow-hidden p-0":"min-w-0 overflow-hidden",children:e.jsxs("div",{className:te?"p-4":void 0,children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:Qe}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:Be}),H?e.jsxs("div",{className:"mt-3 inline-flex max-w-full items-center gap-2 rounded-full bg-[var(--ui-surface-1)] px-3 py-2 text-xs text-[var(--ui-ink-soft)]",children:[e.jsxs("span",{children:["Pinned to ",H]}),ye?e.jsx(is,{content:ye,label:`Explain ${H}`}):null]}):null]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(b,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:ns(J.length)}),ae?null:e.jsxs(v,{type:"button",size:"sm",onClick:()=>E(!0),children:[e.jsx($e,{className:"size-4"}),"Add note"]})]})]}),e.jsxs("div",{className:"mt-4 flex items-center gap-2 rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 py-3",children:[e.jsx(We,{className:"size-4 text-[var(--ui-ink-faint)]"}),e.jsx(j,{value:I,onChange:s=>Oe(s.target.value),placeholder:"Search notes by content, author, or note tag",className:"border-0 bg-transparent px-0 py-0"})]}),ae?e.jsxs("div",{className:"mt-4 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-[var(--ui-ink-medium)]",children:[e.jsx($e,{className:"size-4 text-[var(--secondary)]"}),"Add note"]}),e.jsxs(v,{type:"button",variant:"secondary",size:"sm",className:"gap-2",onClick:()=>q(s=>!s),children:[e.jsx(Ke,{className:"size-4"}),re?"Back to editor":"Preview"]})]}),e.jsx("div",{className:"mt-3",children:re?e.jsxs("div",{className:"rounded-[20px] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Preview"}),e.jsx("div",{className:"mt-3",children:h.trim()?e.jsx(Z,{markdown:h}):e.jsx("div",{className:"text-sm leading-6 text-[var(--ui-ink-faint)]",children:"Markdown preview appears here once you have note content."})})]}):e.jsx(ze,{value:h,onChange:s=>A(s.target.value),placeholder:"Write in Markdown. Summaries, blockers, what changed, and why all work well here.",className:"min-h-[12rem]"})}),e.jsx("div",{className:"mt-3",children:_e(se([{entityType:o,entityId:d,anchorKey:c??null},...ie]),s=>K(s.filter(n=>!(n.entityType===o&&n.entityId===d&&(n.anchorKey??null)===(c??null)))),Ue,$,"composer-note-links")}),e.jsxs("div",{className:"mt-3 grid gap-3 lg:grid-cols-[minmax(0,1.15fr)_minmax(0,0.85fr)]",children:[e.jsx(Me,{value:ne,onChange:P}),e.jsxs("div",{className:"grid gap-3 rounded-[20px] bg-[var(--ui-surface-1)] p-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Ephemeral auto-destroy"}),e.jsx("div",{className:"mt-2 text-xs leading-5 text-[var(--ui-ink-faint)]",children:"Set an exact destroy time or a relative delay. Leaving both blank keeps the note durable."})]}),e.jsx(j,{type:"datetime-local",value:le,onChange:s=>z(s.target.value)}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-[minmax(0,1fr)_10rem]",children:[e.jsx(j,{type:"number",min:"1",value:oe,onChange:s=>M(s.target.value),placeholder:"Destroy after"}),e.jsxs("select",{className:"rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 py-3 text-sm text-[var(--ui-ink-strong)] outline-none transition focus:border-[var(--ui-border-strong)]",value:de,onChange:s=>F(s.target.value),children:[e.jsx("option",{value:"hours",children:"Hours"}),e.jsx("option",{value:"days",children:"Days"})]})]})]})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap justify-end gap-2",children:[e.jsx(v,{type:"button",variant:"secondary",onClick:()=>{E(!1),q(!1),A(""),K([]),$({entityType:"goal",entityId:""}),P([]),z(""),M(""),F("days")},children:"Cancel"}),e.jsx(v,{pending:ke.isPending,pendingLabel:"Saving",disabled:h.trim().length===0,onClick:async()=>{await ke.mutateAsync(h.trim()),E(!1)},children:"Save note"})]})]}):null,e.jsxs("div",{className:"mt-4 grid gap-3",children:[g.isLoading?e.jsx("div",{className:"rounded-[20px] bg-[var(--ui-surface-1)] p-4 text-sm text-[var(--ui-ink-soft)]",children:"Loading notes…"}):null,!g.isLoading&&J.length===0?e.jsx("div",{className:"rounded-[20px] bg-[var(--ui-surface-1)] p-4 text-sm text-[var(--ui-ink-soft)]",children:"No notes are linked here yet."}):null,J.map(s=>{const n=He===s.id,r=fs(s,o,d);return e.jsxs("article",{className:"min-w-0 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"break-words text-xs uppercase tracking-[0.16em] text-[var(--ui-ink-faint)] [overflow-wrap:anywhere]",children:[(s.author??"Unknown author").toString()," •"," ",new Date(s.updatedAt).toLocaleString()]}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-2",children:[r.map(a=>e.jsxs(b,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",wrap:!0,children:[N(a.entityType)," ·"," ",W(a),a.anchorKey?` · ${Y(a.anchorKey)}`:""]},`${s.id}-${a.entityType}-${a.entityId}-${a.anchorKey??""}`)),(s.tags??[]).map(a=>e.jsx(b,{className:"bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]",wrap:!0,children:a},`${s.id}-tag-${a}`)),s.destroyAt?e.jsxs(b,{className:"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]",wrap:!0,children:["Ephemeral · deletes"," ",new Date(s.destroyAt).toLocaleString()]}):null]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",className:"inline-flex size-9 items-center justify-center rounded-full bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",onClick:()=>{Q(s.id),B(s.contentMarkdown),k(!1),O(s.links),U({entityType:"goal",entityId:""}),w(ee(s.tags??[])),_(vs(s.destroyAt??null)),C(""),S("days")},children:e.jsx(Xe,{className:"size-4"})}),e.jsx("button",{type:"button",className:"inline-flex size-9 items-center justify-center rounded-full bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)] transition hover:bg-[color-mix(in_srgb,var(--danger)_18%,var(--ui-surface-hover)_82%)]",onClick:()=>{Ge.mutateAsync(s.id)},children:e.jsx(Pe,{className:"size-4"})})]})]}),n?e.jsxs("div",{className:"mt-4",children:[e.jsx("div",{className:"flex flex-wrap items-center justify-end gap-2",children:e.jsxs(v,{type:"button",variant:"secondary",size:"sm",className:"gap-2",onClick:()=>k(a=>!a),children:[e.jsx(Ke,{className:"size-4"}),ce?"Back to editor":"Preview"]})}),e.jsx("div",{className:"mt-3",children:ce?e.jsxs("div",{className:"rounded-[20px] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Preview"}),e.jsx("div",{className:"mt-3",children:f.trim()?e.jsx(Z,{markdown:f}):e.jsx("div",{className:"text-sm text-[var(--ui-ink-faint)]",children:"No content yet."})})]}):e.jsx(ze,{value:f,onChange:a=>B(a.target.value),className:"min-h-[12rem]"})}),e.jsxs("div",{className:"mt-3 grid gap-3 lg:grid-cols-[minmax(0,1.15fr)_minmax(0,0.85fr)]",children:[e.jsx(Me,{value:ue,onChange:w}),e.jsxs("div",{className:"grid gap-3 rounded-[20px] bg-[var(--ui-surface-1)] p-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Ephemeral auto-destroy"}),e.jsx("div",{className:"mt-2 text-xs leading-5 text-[var(--ui-ink-faint)]",children:"Set an exact destroy time or a relative delay. Leaving both blank keeps the note durable."})]}),e.jsx(j,{type:"datetime-local",value:me,onChange:a=>_(a.target.value)}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-[minmax(0,1fr)_10rem]",children:[e.jsx(j,{type:"number",min:"1",value:pe,onChange:a=>C(a.target.value),placeholder:"Destroy after"}),e.jsxs("select",{className:"rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 py-3 text-sm text-[var(--ui-ink-strong)] outline-none transition focus:border-[var(--ui-border-strong)]",value:xe,onChange:a=>S(a.target.value),children:[e.jsx("option",{value:"hours",children:"Hours"}),e.jsx("option",{value:"days",children:"Days"})]})]})]})]}),e.jsx("div",{className:"mt-3",children:_e(V,O,Re,U,`edit-note-links-${s.id}`)}),e.jsxs("div",{className:"mt-3 flex flex-wrap justify-end gap-2",children:[e.jsx(v,{variant:"secondary",onClick:()=>{Q(null),k(!1),w([]),_(""),C(""),S("days")},children:"Cancel"}),e.jsx(v,{pending:we.isPending,pendingLabel:"Saving",disabled:f.trim().length===0||V.length===0,onClick:async()=>{await we.mutateAsync({noteId:s.id,contentMarkdown:f.trim(),links:V,tags:ee(ue),destroyAt:Fe(me,pe,xe)})},children:"Save changes"})]})]}):e.jsx("div",{className:"mt-4",children:e.jsx(Z,{markdown:s.contentMarkdown})})]},s.id)})]})]})})}export{Cs as E};