forge-openclaw-plugin 0.2.100 → 0.2.101

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 (103) hide show
  1. package/dist/assets/{activity-page-5oyCFOns.js → activity-page-CpjuNSHw.js} +1 -1
  2. package/dist/assets/{ai-surface-workspace-qgk_B57-.js → ai-surface-workspace-DEAFZruS.js} +1 -1
  3. package/dist/assets/{atlas-panel-rfH2qOez.js → atlas-panel-CdVNPotj.js} +1 -1
  4. package/dist/assets/{calendar-page-Bo2iua-a.js → calendar-page-DNNt6lfz.js} +1 -1
  5. package/dist/assets/{calendar-rules-DA1g3QUk.js → calendar-rules-DNJFNsxi.js} +1 -1
  6. package/dist/assets/{calendar-week-toolbar-DU1Q4RYj.js → calendar-week-toolbar-BbPwYeN0.js} +1 -1
  7. package/dist/assets/{companion-sync-lab-page-CosNknOK.js → companion-sync-lab-page-KxEDigM6.js} +1 -1
  8. package/dist/assets/{daily-metrics-dashboard-LjuGAB3f.js → daily-metrics-dashboard-B3cqJgDt.js} +1 -1
  9. package/dist/assets/{entity-note-count-link-BmGDB572.js → entity-note-count-link-DrhjJZ4i.js} +1 -1
  10. package/dist/assets/{entity-notes-surface-DgEgicaE.js → entity-notes-surface-CkcRsKJQ.js} +1 -1
  11. package/dist/assets/{execution-board-CDRXQB85.js → execution-board-D07gOocB.js} +1 -1
  12. package/dist/assets/{faceted-token-search-CE1YauRd.js → faceted-token-search-BxRRcM3q.js} +1 -1
  13. package/dist/assets/{flagship-signal-deck-DDds90Gl.js → flagship-signal-deck-cmy82b8_.js} +1 -1
  14. package/dist/assets/{floating-action-menu-CJkI2iFy.js → floating-action-menu-Fs_ZiUMo.js} +1 -1
  15. package/dist/assets/{goal-detail-page-cJvHaLMQ.js → goal-detail-page-CqLiNz4f.js} +1 -1
  16. package/dist/assets/{goals-page-f_39hvUV.js → goals-page-BTk7mg_T.js} +1 -1
  17. package/dist/assets/{habits-page-DKb96_mj.js → habits-page-BJxagdzx.js} +1 -1
  18. package/dist/assets/{index-BHTUu_4M.js → index-CF4J4R9L.js} +2 -2
  19. package/dist/assets/{insight-flow-dialog-pzAzyayN.js → insight-flow-dialog-8f3D0GuC.js} +1 -1
  20. package/dist/assets/{insights-page-Dc9oFltJ.js → insights-page-D6rOa7uk.js} +1 -1
  21. package/dist/assets/{kanban-page-JAxerYh6.js → kanban-page-XQ7Se6dH.js} +1 -1
  22. package/dist/assets/{knowledge-graph-page-UQ3skqEi.js → knowledge-graph-page-BtAg8iv3.js} +1 -1
  23. package/dist/assets/{life-force-page-BGDbQuVh.js → life-force-page-Dy0JTS2G.js} +1 -1
  24. package/dist/assets/{life-force-workspace-B1fYSXRC.js → life-force-workspace-OfyB9HJM.js} +1 -1
  25. package/dist/assets/{metric-tile-DX6TclqM.js → metric-tile-DKpo-8xw.js} +1 -1
  26. package/dist/assets/{movement-page-6HP6nGJx.js → movement-page-Bg_T_Stx.js} +1 -1
  27. package/dist/assets/{note-markdown-DiW2-5d3.js → note-markdown-N-uxD3Xt.js} +1 -1
  28. package/dist/assets/{note-tags-input-DDLXf54U.js → note-tags-input-Cdu7wiw6.js} +1 -1
  29. package/dist/assets/{notes-page-BuguDjhz.js → notes-page-CKXnF_KU.js} +1 -1
  30. package/dist/assets/{open-in-graph-button-Cg5VrKsC.js → open-in-graph-button-IXe9SGth.js} +1 -1
  31. package/dist/assets/{orbit-map-GD05-0oS.js → orbit-map-Dzi6KliQ.js} +1 -1
  32. package/dist/assets/{overview-page-DuOs2OCB.js → overview-page-1miYqaVS.js} +1 -1
  33. package/dist/assets/{page-hero-CQWo1Mm_.js → page-hero-DRy5b2MU.js} +1 -1
  34. package/dist/assets/{pill-cluster-BJogDRDJ.js → pill-cluster-C9QczVJ2.js} +1 -1
  35. package/dist/assets/{preference-entity-handoff-button-D4WAs9pC.js → preference-entity-handoff-button-5PzUn42S.js} +1 -1
  36. package/dist/assets/{preferences-page-BaJTMU1I.js → preferences-page-DtNaF5Q3.js} +1 -1
  37. package/dist/assets/{project-collections-DvaX20q_.js → project-collections-xPz2mlRr.js} +1 -1
  38. package/dist/assets/{project-detail-page-drPIFZGb.js → project-detail-page-BXK5-4xW.js} +1 -1
  39. package/dist/assets/{project-management-hierarchy-page-BUbRXvny.js → project-management-hierarchy-page-DtRpMABw.js} +1 -1
  40. package/dist/assets/{project-management-section-nav-C2Ud8Zdd.js → project-management-section-nav-P3ixzPa-.js} +1 -1
  41. package/dist/assets/{projects-page-BGzEZUtg.js → projects-page-C5ViRuf4.js} +1 -1
  42. package/dist/assets/{psyche-behaviors-page-Dmm_Io9D.js → psyche-behaviors-page-Dco46sC4.js} +1 -1
  43. package/dist/assets/{psyche-flashcards-page-BgNKJ6QJ.js → psyche-flashcards-page-ZcoEB8gV.js} +1 -1
  44. package/dist/assets/{psyche-goal-map-page-DXJs98Vr.js → psyche-goal-map-page-CLBAQOI0.js} +1 -1
  45. package/dist/assets/{psyche-graph-CFgs_Bqc.js → psyche-graph-k4tX2tdp.js} +1 -1
  46. package/dist/assets/{psyche-metrics-page-zYTJDbyZ.js → psyche-metrics-page-CuR9oqEy.js} +1 -1
  47. package/dist/assets/{psyche-mode-guide-page-XPgRfCOf.js → psyche-mode-guide-page-hIVXcCnE.js} +1 -1
  48. package/dist/assets/{psyche-modes-page-B-GA8oRF.js → psyche-modes-page-0lYtBlhO.js} +1 -1
  49. package/dist/assets/{psyche-page--r6a3e1t.js → psyche-page-VZ9k9ISp.js} +1 -1
  50. package/dist/assets/{psyche-patterns-page-BM5-3bMm.js → psyche-patterns-page-gx5nmdGq.js} +1 -1
  51. package/dist/assets/{psyche-questionnaire-builder-page-CJshQ-mg.js → psyche-questionnaire-builder-page-Bn0TOISd.js} +1 -1
  52. package/dist/assets/{psyche-questionnaire-detail-page-USmR5G5A.js → psyche-questionnaire-detail-page-CmVzSd_s.js} +1 -1
  53. package/dist/assets/{psyche-questionnaire-run-detail-page-D7iBCmTi.js → psyche-questionnaire-run-detail-page-BsMbmXCG.js} +1 -1
  54. package/dist/assets/{psyche-questionnaire-run-page-Cpil-kDh.js → psyche-questionnaire-run-page-CgkRL2vi.js} +1 -1
  55. package/dist/assets/{psyche-questionnaires-page-C-_y3VwS.js → psyche-questionnaires-page-D7V8uLXM.js} +1 -1
  56. package/dist/assets/{psyche-report-detail-page--dkSPRaj.js → psyche-report-detail-page-OlFq57eL.js} +1 -1
  57. package/dist/assets/{psyche-reports-page-CUaOXmIN.js → psyche-reports-page-dVUZjna1.js} +1 -1
  58. package/dist/assets/{psyche-schemas-beliefs-page-BX6xaap3.js → psyche-schemas-beliefs-page-BCgc8FUd.js} +1 -1
  59. package/dist/assets/{psyche-screen-time-page-CAAI4mD7.js → psyche-screen-time-page-B_6BT_WN.js} +1 -1
  60. package/dist/assets/{psyche-self-observation-page-BZ6FLuwa.js → psyche-self-observation-page-CEG5mluK.js} +1 -1
  61. package/dist/assets/{psyche-values-page-yEV6MGt8.js → psyche-values-page-DRbRfEd6.js} +1 -1
  62. package/dist/assets/{report-chain-fields-fZ8Xd4H6.js → report-chain-fields-CALCV3V5.js} +1 -1
  63. package/dist/assets/{rewards-page-C2HQjIAf.js → rewards-page-DmC4R_Ps.js} +1 -1
  64. package/dist/assets/{scheduling-rules-editor-BHOpHOrV.js → scheduling-rules-editor-D02s70hr.js} +1 -1
  65. package/dist/assets/{schema-badge-DyKbxb51.js → schema-badge-BZO-qNhO.js} +1 -1
  66. package/dist/assets/{select-menu-BX-pZNqL.js → select-menu-fYyreSdQ.js} +1 -1
  67. package/dist/assets/{settings-agents-page-VuYXTiyc.js → settings-agents-page-C_v_hMJF.js} +1 -1
  68. package/dist/assets/{settings-bin-page-BNzvYaOk.js → settings-bin-page-DY5bg81n.js} +1 -1
  69. package/dist/assets/{settings-calendar-page-CjSFB53S.js → settings-calendar-page-D1CzE6cg.js} +1 -1
  70. package/dist/assets/{settings-data-page-CGSlryuI.js → settings-data-page-CHRQFU9H.js} +1 -1
  71. package/dist/assets/{settings-logs-page-BTK5fine.js → settings-logs-page-B04pUwEv.js} +1 -1
  72. package/dist/assets/{settings-mobile-page-CRaObOGo.js → settings-mobile-page-D9kTlYDS.js} +1 -1
  73. package/dist/assets/{settings-models-page-DFshpYF8.js → settings-models-page-D26270R2.js} +1 -1
  74. package/dist/assets/{settings-page-BP81Mb5R.js → settings-page-DYDTFlnv.js} +1 -1
  75. package/dist/assets/{settings-rewards-page-CDJ1PH2G.js → settings-rewards-page-cl4vqqO_.js} +1 -1
  76. package/dist/assets/{settings-section-nav-CCFm27r2.js → settings-section-nav-DSOuht_F.js} +1 -1
  77. package/dist/assets/{settings-users-page-TdUocFPa.js → settings-users-page-BU79JB_T.js} +1 -1
  78. package/dist/assets/{settings-wiki-page-B2zX0QQG.js → settings-wiki-page-DwAUlyA3.js} +1 -1
  79. package/dist/assets/{sleep-page-cI1GMVzk.js → sleep-page-D8NbdhyS.js} +1 -1
  80. package/dist/assets/{sports-page-06LTqp0V.js → sports-page-CV4Cnzwn.js} +1 -1
  81. package/dist/assets/{strategies-page-DXP9Kx8s.js → strategies-page-C4qvXnql.js} +1 -1
  82. package/dist/assets/{strategy-detail-page-D6mx_Mik.js → strategy-detail-page-DJLo5rfy.js} +1 -1
  83. package/dist/assets/{strategy-dialog-BvzomTaF.js → strategy-dialog-D3AuUlVz.js} +1 -1
  84. package/dist/assets/{task-detail-page-BIWIggdp.js → task-detail-page-z-9u9rF0.js} +1 -1
  85. package/dist/assets/{timebox-planning-dialog-CaCnoslG.js → timebox-planning-dialog-DB6FLqmI.js} +1 -1
  86. package/dist/assets/{today-page-DO2mRPT2.js → today-page-BKlu6gx5.js} +1 -1
  87. package/dist/assets/{training-load-page-CyZ0mlEr.js → training-load-page-CyJQqo_3.js} +1 -1
  88. package/dist/assets/{vitals-page-BQvEjTc6.js → vitals-page-qre17Nw8.js} +1 -1
  89. package/dist/assets/{weekly-review-page-Tp6Q9CRj.js → weekly-review-page-Cz4vkRcx.js} +1 -1
  90. package/dist/assets/weight-loss-page-BQrnOI0y.js +1 -0
  91. package/dist/assets/{wiki-article-markdown-DQYohmW2.js → wiki-article-markdown-DdiR2TJE.js} +1 -1
  92. package/dist/assets/{wiki-editor-page-Dem_3eZv.js → wiki-editor-page-DqwoqVFb.js} +1 -1
  93. package/dist/assets/{wiki-ingest-history-page-BxoOcCoJ.js → wiki-ingest-history-page--evBLbOw.js} +1 -1
  94. package/dist/assets/{wiki-ingest-modal-DhguKk3J.js → wiki-ingest-modal--ohzFnj2.js} +1 -1
  95. package/dist/assets/{wiki-page-BLRxVXkl.js → wiki-page-B_VJFBPA.js} +1 -1
  96. package/dist/assets/{workbench-flow-page-DqMkCCTy.js → workbench-flow-page-Du62mtJU.js} +1 -1
  97. package/dist/assets/{workbench-page-BWd02wPw.js → workbench-page-4MKr3iRm.js} +1 -1
  98. package/dist/assets/{workout-detail-page-BD8u7GyL.js → workout-detail-page-DfUbYYw1.js} +1 -1
  99. package/dist/index.html +1 -1
  100. package/dist/server/server/src/watch-mobile.js +22 -10
  101. package/openclaw.plugin.json +1 -1
  102. package/package.json +1 -1
  103. package/dist/assets/weight-loss-page-BBzlhLVV.js +0 -1
@@ -1 +1 @@
1
- import{b5 as V,r as f,j as e,aC as y,c2 as Q}from"./vendor-DHkYh85p.js";import{i as F}from"./state-B-4sS1xO.js";import{A as U}from"./ai-surface-workspace-qgk_B57-.js";import{b as z,P as Z}from"./psyche-graph-CFgs_Bqc.js";import{u as H,Q as J,j as X,F as Y,b as k,C as R,Z as K,S as ee,E as te,a8 as se,ck as ae,B as ie,V as re,c as C,cm as ne,ad as le,cn as oe}from"./index-BHTUu_4M.js";import{P as de}from"./page-hero-CQWo1Mm_.js";import"./board-BkDRaMp6.js";import"./ui-C13Nbgas.js";import"./motion-BeD44FeG.js";import"./forms-BFlTgZ3W.js";import"./graph-D6JLqDbD.js";const W={intent:"trigger_report",linkedGoalId:"",linkedProjectId:"",linkedTaskId:""};function ce({open:t,onOpenChange:l}){const d=V(),o=H(),[c,b]=f.useState(W),N=[{id:"intent",eyebrow:"Reflect",title:"What do you want to reflect on?",description:"Choose the entrypoint first. Forge will route you into the right guided flow instead of dropping you into a generic form.",render:(r,a)=>e.jsx(X,{columns:3,value:r.intent,onChange:s=>a({intent:s}),options:[{value:"trigger_report",label:"A situation",description:"Start a Spark-to-Pivot report about something that happened."},{value:"behavior",label:"A behavior",description:"Trace an away move, committed action, or recovery path."},{value:"belief",label:"A belief script",description:"Capture or refine the belief beneath the reaction."},{value:"pattern",label:"A recurring pattern",description:"Map the loop, payoff, cost, and better response."},{value:"value",label:"A blocked value",description:"Clarify which value is being challenged or needs support."},{value:"execution_tension",label:"A goal tension",description:"Reflect on a goal, project, or task that carries friction."}]})},{id:"placement",eyebrow:"Placement",title:"Attach the reflection to the wider system",description:"This keeps the reflection connected to values, behaviors, and live work instead of becoming an isolated note.",render:(r,a)=>e.jsx("div",{className:"grid gap-4",children:e.jsx(Y,{label:"Goal / project / task tension",children:e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(k,{kind:"goal",label:"Goal",compact:!0,gradient:!1}),e.jsx(k,{kind:"project",label:"Project",compact:!0,gradient:!1}),e.jsx(k,{kind:"task",label:"Task",compact:!0,gradient:!1})]}),e.jsxs("select",{className:"rounded-[18px] border border-white/8 bg-white/6 px-4 py-3 text-sm text-white",value:r.linkedGoalId,onChange:s=>a({linkedGoalId:s.target.value}),children:[e.jsx("option",{value:"",children:"No goal selected"}),o.snapshot.goals.map(s=>e.jsxs("option",{value:s.id,children:["Goal · ",s.title]},s.id))]}),e.jsxs("select",{className:"rounded-[18px] border border-white/8 bg-white/6 px-4 py-3 text-sm text-white",value:r.linkedProjectId,onChange:s=>a({linkedProjectId:s.target.value}),children:[e.jsx("option",{value:"",children:"No project selected"}),o.snapshot.dashboard.projects.map(s=>e.jsxs("option",{value:s.id,children:["Project · ",s.title]},s.id))]}),e.jsxs("select",{className:"rounded-[18px] border border-white/8 bg-white/6 px-4 py-3 text-sm text-white",value:r.linkedTaskId,onChange:s=>a({linkedTaskId:s.target.value}),children:[e.jsx("option",{value:"",children:"No task selected"}),o.snapshot.tasks.slice(0,40).map(s=>e.jsxs("option",{value:s.id,children:["Task · ",s.title]},s.id))]})]})})})}],x=async()=>{const r=new URLSearchParams({create:"1",intent:c.intent});switch(c.linkedGoalId&&r.set("goalId",c.linkedGoalId),c.linkedProjectId&&r.set("projectId",c.linkedProjectId),c.linkedTaskId&&r.set("taskId",c.linkedTaskId),c.intent){case"behavior":d(`/psyche/behaviors?${r.toString()}`);break;case"belief":d(`/psyche/schemas-beliefs?${r.toString()}`);break;case"pattern":d(`/psyche/patterns?${r.toString()}`);break;case"value":d(`/psyche/values?${r.toString()}`);break;case"execution_tension":case"trigger_report":default:d(`/psyche/reports?${r.toString()}`);break}l(!1),b(W)};return e.jsx(J,{open:t,onOpenChange:l,eyebrow:"Reflect",title:"Start from the right reflective doorway",description:"Choose what you want to reflect on first. Forge will take you into the right guided flow instead of leaving you in a generic form.",value:c,onChange:b,draftPersistenceKey:"psyche.reflect.launcher",steps:N,submitLabel:"Open guided reflection",onSubmit:x})}function I({to:t,children:l,className:d}){return e.jsx(y,{to:t,className:"group block transition-transform duration-[var(--motion-medium)] ease-[var(--ease-standard)] hover:-translate-y-0.5 focus-visible:outline-none",children:e.jsx(R,{className:K("transition-[transform,box-shadow,background,border-color] duration-[var(--motion-medium)] ease-[var(--ease-standard)] group-hover:border-[var(--ui-border-strong)] group-hover:bg-[var(--ui-surface-hover)] group-hover:shadow-[var(--card-shadow-hover)] group-focus-visible:shadow-[var(--card-shadow-hover)]",d),children:l})})}function P(t){return`${t.toFixed(t>=10?0:1)}%`}function v(t){return new Intl.NumberFormat().format(Math.round(t))}function M(t,l){return l==="percent"?P(t):v(t)}function he({metric:t}){const l=t.history.slice(0,7).reverse(),d=Math.max(1,...l.map(o=>o.rawSwearCount));return e.jsxs(R,{className:"min-w-0 border border-amber-200/12 bg-[linear-gradient(180deg,rgba(39,31,17,0.96),rgba(19,21,17,0.95))] p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-amber-100/72",children:"Devrage metric"}),e.jsxs("div",{className:"mt-2 font-display text-[clamp(1.4rem,2.5vw,2.15rem)] leading-none text-white",children:[v(t.rawSwearCount)," swears"]})]}),e.jsx(C,{className:"bg-amber-200/10 text-amber-50",children:t.latestDateKey??"No history"})]}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[18px] bg-white/[0.045] px-4 py-3",children:[e.jsx("div",{className:"text-xs text-white/48",children:"Swearing messages"}),e.jsx("div",{className:"mt-1 text-2xl font-semibold text-white",children:P(t.swearingMessagePercent)})]}),e.jsxs("div",{className:"rounded-[18px] bg-white/[0.045] px-4 py-3",children:[e.jsx("div",{className:"text-xs text-white/48",children:"Daily average"}),e.jsx("div",{className:"mt-1 text-2xl font-semibold text-white",children:M(t.dailyAverage.rawSwearCount,"count")})]}),e.jsxs("div",{className:"rounded-[18px] bg-white/[0.045] px-4 py-3",children:[e.jsx("div",{className:"text-xs text-white/48",children:"Weekly average"}),e.jsx("div",{className:"mt-1 text-2xl font-semibold text-white",children:M(t.weeklyAverage.rawSwearCount,"count")})]})]}),e.jsx("div",{className:"mt-4 flex h-16 items-end gap-1.5",children:l.length>0?l.map(o=>e.jsx("div",{className:"min-w-0 flex-1 rounded-t-[6px] bg-amber-200/50",style:{height:`${Math.max(8,o.rawSwearCount/d*64)}px`},title:`${o.dateKey}: ${v(o.rawSwearCount)} swears, ${P(o.swearingMessagePercent)} swearing messages`},o.dateKey)):e.jsx("div",{className:"self-center text-sm text-white/48",children:"History will appear after the first local backfill."})}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2 text-xs text-white/50",children:[e.jsxs("span",{children:[v(t.conversationsScanned)," conversations"]}),e.jsxs("span",{children:[v(t.messagesScanned)," messages"]}),e.jsxs("span",{children:[v(t.messagesWithSwears)," flagged"]})]}),e.jsx(y,{to:"/psyche/metrics",className:"mt-4 inline-flex min-h-10 items-center justify-center rounded-[var(--radius-control)] border border-amber-200/14 bg-amber-200/10 px-4 py-2 text-sm font-medium text-amber-50 transition hover:bg-amber-200/14",children:"Open metrics"})]})}function Ne(){var T,G;const t=H(),[l,d]=Q(),[o,c]=f.useState(l.get("reflect")==="1"),[b,N]=f.useState(null),x=F({queryKey:["forge-psyche-overview"],queryFn:le}),r=F({queryKey:["forge-psyche-questionnaires-hub"],queryFn:()=>oe()}),a=(T=x.data)==null?void 0:T.overview,s=f.useMemo(()=>a?t.snapshot.goals.slice(0,3).map(i=>{const m=a.values.filter(h=>h.linkedGoalIds.includes(i.id)),S=t.snapshot.dashboard.projects.filter(h=>h.goalId===i.id),D=t.snapshot.habits.filter(h=>h.linkedGoalIds.includes(i.id)||h.linkedValueIds.some(w=>m.some(j=>j.id===w))),B=a.reports.filter(h=>h.linkedGoalIds.includes(i.id)),O=a.behaviors.filter(h=>h.linkedValueIds.some(w=>m.some(j=>j.id===w))),L=a.beliefs.filter(h=>h.linkedValueIds.some(w=>m.some(j=>j.id===w)));return{goal:i,linkedValues:m,linkedProjects:S,linkedHabits:D,linkedReports:B,linkedBehaviors:O,linkedBeliefs:L}}):[],[a,t.snapshot.dashboard.projects,t.snapshot.goals,t.snapshot.habits]),p=f.useMemo(()=>z(s,{compact:!0}),[s]);if(f.useEffect(()=>{N(p.defaultSelectedId)},[p.defaultSelectedId]),x.isLoading)return e.jsx(ee,{});if(x.isError||!a)return e.jsx(te,{eyebrow:"Psyche",error:x.error,onRetry:()=>void x.refetch()});const n=p.inspectors[b??p.defaultSelectedId]??p.inspectors[p.defaultSelectedId],g=a.patterns[0]??null,A=a.reports[0]??null,u=[...((G=r.data)==null?void 0:G.instruments)??[]].sort((i,m)=>{const S=i.latestRunAt?new Date(i.latestRunAt).getTime():0;return(m.latestRunAt?new Date(m.latestRunAt).getTime():0)-S})[0]??null,E="Values, patterns, behaviors, beliefs, habits, and reports in one live field.",$=a.devrageMetric.hasData||a.devrageMetric.conversationsScanned>0||a.devrageMetric.history.length>0,_=e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[e.jsx(se,{metrics:t.snapshot.metrics}),e.jsx(y,{to:"/psyche/goal-map",className:"inline-flex min-h-10 min-w-0 max-w-full items-center justify-center rounded-full bg-white/[0.08] px-4 py-2 text-sm whitespace-nowrap text-white transition hover:bg-white/[0.12]",children:"Open goal map"})]}),q=[{id:"hero",title:"Psyche",description:"Top route composition",defaultWidth:12,defaultHeight:1,removable:!1,surfaceChrome:"none",defaultTitleVisible:!1,defaultDescriptionVisible:!1,render:()=>e.jsx(de,{title:"Psyche",titleText:"Psyche",description:E,actions:_})},{id:"sections",title:"Psyche sections",description:"Section switcher",defaultWidth:12,defaultHeight:1,surfaceChrome:"none",defaultTitleVisible:!1,defaultDescriptionVisible:!1,render:()=>e.jsx(ae,{})},{id:"field",title:"Live field",description:"Graph and inspector stay as movable widgets.",defaultWidth:8,defaultHeight:5,minWidth:6,render:()=>e.jsx(Z,{testId:"psyche-hub-graph",compact:!0,title:"Reflective pulse and live entity field",hint:"Select any goal, value, habit, belief, behavior, project, or report.",nodes:p.nodes,edges:p.edges,fields:p.fields,selectedNodeId:b,onSelectNode:N,minHeightClassName:"min-h-[20rem] sm:min-h-[24rem] lg:min-h-[34rem]",legend:[{label:"Goals",kind:"goal"},{label:"Values",kind:"value"},{label:"Habits",kind:"habit"},{label:"Behaviors",kind:"behavior"}],action:e.jsxs(e.Fragment,{children:[e.jsx(y,{to:"/psyche/goal-map",className:"inline-flex min-h-10 min-w-0 max-w-full items-center justify-center rounded-[var(--radius-control)] bg-white/8 px-4 py-2 text-sm font-medium whitespace-nowrap text-white transition hover:bg-white/12",children:"Open goal map"}),e.jsx(ie,{size:"sm",className:"min-w-0 sm:min-w-[6.5rem]",onClick:()=>c(!0),children:"Reflect"})]})})},{id:"inspector",title:"Inspector",description:"Selected-node inspector widget.",defaultWidth:4,defaultHeight:5,minWidth:4,render:()=>e.jsxs(R,{className:"h-full min-w-0",children:[e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:n.entityKind?e.jsx(k,{kind:n.entityKind,compact:!0,gradient:!1,iconOnly:!0}):e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/42",children:n.eyebrow})}),e.jsx("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:n.entityKind?e.jsx(re,{kind:n.entityKind,label:n.title,variant:"heading",size:"lg",showKind:!1}):e.jsx("h2",{className:"font-display text-[clamp(1.25rem,2.2vw,1.8rem)] leading-none text-white",children:n.title})}),e.jsx("p",{className:"mt-3 text-sm leading-6 text-white/60",children:n.summary}),n.chips.length>0?e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:n.chips.map(i=>e.jsx(C,{className:"bg-white/[0.08] text-white/74",children:i},i))}):null,n.stats.length>0?e.jsx("div",{className:"mt-4 grid gap-2",children:n.stats.map(i=>e.jsx("div",{className:"rounded-[18px] bg-white/[0.04] px-3 py-3 text-sm text-white/68",children:i},i))}):null,e.jsx("div",{className:"mt-5",children:e.jsx(y,{to:n.href,className:K("inline-flex min-h-11 w-full items-center justify-center rounded-[var(--radius-control)] px-4 py-2.5 text-sm font-medium whitespace-nowrap shadow-[0_12px_30px_rgba(192,193,255,0.08)]",n.entityKind?ne(n.entityKind,!0):"bg-[linear-gradient(135deg,rgba(192,193,255,0.36),rgba(192,193,255,0.22))] text-white"),children:n.ctaLabel})})]})},...$?[{id:"devrage",title:"Devrage metric",description:"Daily user-message frustration metric.",defaultWidth:4,defaultHeight:3,minWidth:4,render:()=>e.jsx(he,{metric:a.devrageMetric})}]:[],{id:"actions",title:"Open threads",description:"Action and pulse cards.",defaultWidth:8,defaultHeight:3,render:()=>e.jsxs("div",{className:"grid min-w-0 gap-4 lg:grid-cols-[minmax(0,1.05fr)_minmax(0,0.95fr)]",children:[e.jsxs(I,{to:"/psyche/behaviors",className:"rounded-[28px] border border-white/8 bg-[linear-gradient(180deg,rgba(17,29,32,0.96),rgba(11,21,23,0.94))] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[rgba(110,231,183,0.82)]",children:"Best next reflective move"}),e.jsx("div",{className:"mt-3 font-display text-[clamp(1.45rem,2.2vw,2rem)] leading-none text-white",children:(g==null?void 0:g.preferredResponse)||"Map the active loop, then name the committed move that brings you back."}),e.jsx("p",{className:"mt-3 text-sm leading-6 text-white/58",children:(g==null?void 0:g.targetBehavior)||"When the loop is explicit, the return path stops feeling abstract."})]}),e.jsxs(I,{to:A?`/psyche/reports/${A.id}`:"/psyche/reports",className:"rounded-[28px] border border-white/8 bg-[linear-gradient(180deg,rgba(24,19,37,0.96),rgba(13,12,22,0.94))] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-violet-100/72",children:"Open threads"}),e.jsxs("div",{className:"mt-3 grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"rounded-[22px] bg-white/[0.04] px-4 py-4",children:[e.jsx("div",{className:"text-sm text-white/58",children:"Insights"}),e.jsx("div",{className:"mt-2 font-display text-4xl text-white",children:a.openInsights})]}),e.jsxs("div",{className:"rounded-[22px] bg-white/[0.04] px-4 py-4",children:[e.jsx("div",{className:"text-sm text-white/58",children:"Notes"}),e.jsx("div",{className:"mt-2 font-display text-4xl text-white",children:a.openNotes})]})]})]})]})},{id:"questionnaires",title:"Questionnaire pulse",description:"Recent questionnaire state.",defaultWidth:12,defaultHeight:2,render:()=>{var i;return e.jsxs(I,{to:u!=null&&u.latestRunId?`/psyche/questionnaire-runs/${u.latestRunId}`:"/psyche/questionnaires",className:"rounded-[28px] border border-white/8 bg-[linear-gradient(180deg,rgba(17,31,39,0.97),rgba(10,18,24,0.95))] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-sky-100/72",children:"Questionnaire pulse"}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"font-display text-[clamp(1.4rem,2.2vw,2rem)] leading-none text-white",children:(u==null?void 0:u.title)??"Questionnaire library ready"}),e.jsxs(C,{className:"bg-white/[0.08] text-white/78",children:[(((i=r.data)==null?void 0:i.instruments)??[]).length," available"]})]})]})}}];return e.jsxs("div",{className:"grid min-w-0 gap-4 overflow-x-clip",children:[e.jsx(U,{surfaceId:"psyche",baseWidgets:q}),e.jsx(ce,{open:o,onOpenChange:i=>{c(i);const m=new URLSearchParams(l);m.delete("reflect"),d(m,{replace:!0})}})]})}export{Ne as PsychePage};
1
+ import{b5 as V,r as f,j as e,aC as y,c2 as Q}from"./vendor-DHkYh85p.js";import{i as F}from"./state-B-4sS1xO.js";import{A as U}from"./ai-surface-workspace-DEAFZruS.js";import{b as z,P as Z}from"./psyche-graph-k4tX2tdp.js";import{u as H,Q as J,j as X,F as Y,b as k,C as R,Z as K,S as ee,E as te,a8 as se,ck as ae,B as ie,V as re,c as C,cm as ne,ad as le,cn as oe}from"./index-CF4J4R9L.js";import{P as de}from"./page-hero-DRy5b2MU.js";import"./board-BkDRaMp6.js";import"./ui-C13Nbgas.js";import"./motion-BeD44FeG.js";import"./forms-BFlTgZ3W.js";import"./graph-D6JLqDbD.js";const W={intent:"trigger_report",linkedGoalId:"",linkedProjectId:"",linkedTaskId:""};function ce({open:t,onOpenChange:l}){const d=V(),o=H(),[c,b]=f.useState(W),N=[{id:"intent",eyebrow:"Reflect",title:"What do you want to reflect on?",description:"Choose the entrypoint first. Forge will route you into the right guided flow instead of dropping you into a generic form.",render:(r,a)=>e.jsx(X,{columns:3,value:r.intent,onChange:s=>a({intent:s}),options:[{value:"trigger_report",label:"A situation",description:"Start a Spark-to-Pivot report about something that happened."},{value:"behavior",label:"A behavior",description:"Trace an away move, committed action, or recovery path."},{value:"belief",label:"A belief script",description:"Capture or refine the belief beneath the reaction."},{value:"pattern",label:"A recurring pattern",description:"Map the loop, payoff, cost, and better response."},{value:"value",label:"A blocked value",description:"Clarify which value is being challenged or needs support."},{value:"execution_tension",label:"A goal tension",description:"Reflect on a goal, project, or task that carries friction."}]})},{id:"placement",eyebrow:"Placement",title:"Attach the reflection to the wider system",description:"This keeps the reflection connected to values, behaviors, and live work instead of becoming an isolated note.",render:(r,a)=>e.jsx("div",{className:"grid gap-4",children:e.jsx(Y,{label:"Goal / project / task tension",children:e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(k,{kind:"goal",label:"Goal",compact:!0,gradient:!1}),e.jsx(k,{kind:"project",label:"Project",compact:!0,gradient:!1}),e.jsx(k,{kind:"task",label:"Task",compact:!0,gradient:!1})]}),e.jsxs("select",{className:"rounded-[18px] border border-white/8 bg-white/6 px-4 py-3 text-sm text-white",value:r.linkedGoalId,onChange:s=>a({linkedGoalId:s.target.value}),children:[e.jsx("option",{value:"",children:"No goal selected"}),o.snapshot.goals.map(s=>e.jsxs("option",{value:s.id,children:["Goal · ",s.title]},s.id))]}),e.jsxs("select",{className:"rounded-[18px] border border-white/8 bg-white/6 px-4 py-3 text-sm text-white",value:r.linkedProjectId,onChange:s=>a({linkedProjectId:s.target.value}),children:[e.jsx("option",{value:"",children:"No project selected"}),o.snapshot.dashboard.projects.map(s=>e.jsxs("option",{value:s.id,children:["Project · ",s.title]},s.id))]}),e.jsxs("select",{className:"rounded-[18px] border border-white/8 bg-white/6 px-4 py-3 text-sm text-white",value:r.linkedTaskId,onChange:s=>a({linkedTaskId:s.target.value}),children:[e.jsx("option",{value:"",children:"No task selected"}),o.snapshot.tasks.slice(0,40).map(s=>e.jsxs("option",{value:s.id,children:["Task · ",s.title]},s.id))]})]})})})}],x=async()=>{const r=new URLSearchParams({create:"1",intent:c.intent});switch(c.linkedGoalId&&r.set("goalId",c.linkedGoalId),c.linkedProjectId&&r.set("projectId",c.linkedProjectId),c.linkedTaskId&&r.set("taskId",c.linkedTaskId),c.intent){case"behavior":d(`/psyche/behaviors?${r.toString()}`);break;case"belief":d(`/psyche/schemas-beliefs?${r.toString()}`);break;case"pattern":d(`/psyche/patterns?${r.toString()}`);break;case"value":d(`/psyche/values?${r.toString()}`);break;case"execution_tension":case"trigger_report":default:d(`/psyche/reports?${r.toString()}`);break}l(!1),b(W)};return e.jsx(J,{open:t,onOpenChange:l,eyebrow:"Reflect",title:"Start from the right reflective doorway",description:"Choose what you want to reflect on first. Forge will take you into the right guided flow instead of leaving you in a generic form.",value:c,onChange:b,draftPersistenceKey:"psyche.reflect.launcher",steps:N,submitLabel:"Open guided reflection",onSubmit:x})}function I({to:t,children:l,className:d}){return e.jsx(y,{to:t,className:"group block transition-transform duration-[var(--motion-medium)] ease-[var(--ease-standard)] hover:-translate-y-0.5 focus-visible:outline-none",children:e.jsx(R,{className:K("transition-[transform,box-shadow,background,border-color] duration-[var(--motion-medium)] ease-[var(--ease-standard)] group-hover:border-[var(--ui-border-strong)] group-hover:bg-[var(--ui-surface-hover)] group-hover:shadow-[var(--card-shadow-hover)] group-focus-visible:shadow-[var(--card-shadow-hover)]",d),children:l})})}function P(t){return`${t.toFixed(t>=10?0:1)}%`}function v(t){return new Intl.NumberFormat().format(Math.round(t))}function M(t,l){return l==="percent"?P(t):v(t)}function he({metric:t}){const l=t.history.slice(0,7).reverse(),d=Math.max(1,...l.map(o=>o.rawSwearCount));return e.jsxs(R,{className:"min-w-0 border border-amber-200/12 bg-[linear-gradient(180deg,rgba(39,31,17,0.96),rgba(19,21,17,0.95))] p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-amber-100/72",children:"Devrage metric"}),e.jsxs("div",{className:"mt-2 font-display text-[clamp(1.4rem,2.5vw,2.15rem)] leading-none text-white",children:[v(t.rawSwearCount)," swears"]})]}),e.jsx(C,{className:"bg-amber-200/10 text-amber-50",children:t.latestDateKey??"No history"})]}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[18px] bg-white/[0.045] px-4 py-3",children:[e.jsx("div",{className:"text-xs text-white/48",children:"Swearing messages"}),e.jsx("div",{className:"mt-1 text-2xl font-semibold text-white",children:P(t.swearingMessagePercent)})]}),e.jsxs("div",{className:"rounded-[18px] bg-white/[0.045] px-4 py-3",children:[e.jsx("div",{className:"text-xs text-white/48",children:"Daily average"}),e.jsx("div",{className:"mt-1 text-2xl font-semibold text-white",children:M(t.dailyAverage.rawSwearCount,"count")})]}),e.jsxs("div",{className:"rounded-[18px] bg-white/[0.045] px-4 py-3",children:[e.jsx("div",{className:"text-xs text-white/48",children:"Weekly average"}),e.jsx("div",{className:"mt-1 text-2xl font-semibold text-white",children:M(t.weeklyAverage.rawSwearCount,"count")})]})]}),e.jsx("div",{className:"mt-4 flex h-16 items-end gap-1.5",children:l.length>0?l.map(o=>e.jsx("div",{className:"min-w-0 flex-1 rounded-t-[6px] bg-amber-200/50",style:{height:`${Math.max(8,o.rawSwearCount/d*64)}px`},title:`${o.dateKey}: ${v(o.rawSwearCount)} swears, ${P(o.swearingMessagePercent)} swearing messages`},o.dateKey)):e.jsx("div",{className:"self-center text-sm text-white/48",children:"History will appear after the first local backfill."})}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2 text-xs text-white/50",children:[e.jsxs("span",{children:[v(t.conversationsScanned)," conversations"]}),e.jsxs("span",{children:[v(t.messagesScanned)," messages"]}),e.jsxs("span",{children:[v(t.messagesWithSwears)," flagged"]})]}),e.jsx(y,{to:"/psyche/metrics",className:"mt-4 inline-flex min-h-10 items-center justify-center rounded-[var(--radius-control)] border border-amber-200/14 bg-amber-200/10 px-4 py-2 text-sm font-medium text-amber-50 transition hover:bg-amber-200/14",children:"Open metrics"})]})}function Ne(){var T,G;const t=H(),[l,d]=Q(),[o,c]=f.useState(l.get("reflect")==="1"),[b,N]=f.useState(null),x=F({queryKey:["forge-psyche-overview"],queryFn:le}),r=F({queryKey:["forge-psyche-questionnaires-hub"],queryFn:()=>oe()}),a=(T=x.data)==null?void 0:T.overview,s=f.useMemo(()=>a?t.snapshot.goals.slice(0,3).map(i=>{const m=a.values.filter(h=>h.linkedGoalIds.includes(i.id)),S=t.snapshot.dashboard.projects.filter(h=>h.goalId===i.id),D=t.snapshot.habits.filter(h=>h.linkedGoalIds.includes(i.id)||h.linkedValueIds.some(w=>m.some(j=>j.id===w))),B=a.reports.filter(h=>h.linkedGoalIds.includes(i.id)),O=a.behaviors.filter(h=>h.linkedValueIds.some(w=>m.some(j=>j.id===w))),L=a.beliefs.filter(h=>h.linkedValueIds.some(w=>m.some(j=>j.id===w)));return{goal:i,linkedValues:m,linkedProjects:S,linkedHabits:D,linkedReports:B,linkedBehaviors:O,linkedBeliefs:L}}):[],[a,t.snapshot.dashboard.projects,t.snapshot.goals,t.snapshot.habits]),p=f.useMemo(()=>z(s,{compact:!0}),[s]);if(f.useEffect(()=>{N(p.defaultSelectedId)},[p.defaultSelectedId]),x.isLoading)return e.jsx(ee,{});if(x.isError||!a)return e.jsx(te,{eyebrow:"Psyche",error:x.error,onRetry:()=>void x.refetch()});const n=p.inspectors[b??p.defaultSelectedId]??p.inspectors[p.defaultSelectedId],g=a.patterns[0]??null,A=a.reports[0]??null,u=[...((G=r.data)==null?void 0:G.instruments)??[]].sort((i,m)=>{const S=i.latestRunAt?new Date(i.latestRunAt).getTime():0;return(m.latestRunAt?new Date(m.latestRunAt).getTime():0)-S})[0]??null,E="Values, patterns, behaviors, beliefs, habits, and reports in one live field.",$=a.devrageMetric.hasData||a.devrageMetric.conversationsScanned>0||a.devrageMetric.history.length>0,_=e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[e.jsx(se,{metrics:t.snapshot.metrics}),e.jsx(y,{to:"/psyche/goal-map",className:"inline-flex min-h-10 min-w-0 max-w-full items-center justify-center rounded-full bg-white/[0.08] px-4 py-2 text-sm whitespace-nowrap text-white transition hover:bg-white/[0.12]",children:"Open goal map"})]}),q=[{id:"hero",title:"Psyche",description:"Top route composition",defaultWidth:12,defaultHeight:1,removable:!1,surfaceChrome:"none",defaultTitleVisible:!1,defaultDescriptionVisible:!1,render:()=>e.jsx(de,{title:"Psyche",titleText:"Psyche",description:E,actions:_})},{id:"sections",title:"Psyche sections",description:"Section switcher",defaultWidth:12,defaultHeight:1,surfaceChrome:"none",defaultTitleVisible:!1,defaultDescriptionVisible:!1,render:()=>e.jsx(ae,{})},{id:"field",title:"Live field",description:"Graph and inspector stay as movable widgets.",defaultWidth:8,defaultHeight:5,minWidth:6,render:()=>e.jsx(Z,{testId:"psyche-hub-graph",compact:!0,title:"Reflective pulse and live entity field",hint:"Select any goal, value, habit, belief, behavior, project, or report.",nodes:p.nodes,edges:p.edges,fields:p.fields,selectedNodeId:b,onSelectNode:N,minHeightClassName:"min-h-[20rem] sm:min-h-[24rem] lg:min-h-[34rem]",legend:[{label:"Goals",kind:"goal"},{label:"Values",kind:"value"},{label:"Habits",kind:"habit"},{label:"Behaviors",kind:"behavior"}],action:e.jsxs(e.Fragment,{children:[e.jsx(y,{to:"/psyche/goal-map",className:"inline-flex min-h-10 min-w-0 max-w-full items-center justify-center rounded-[var(--radius-control)] bg-white/8 px-4 py-2 text-sm font-medium whitespace-nowrap text-white transition hover:bg-white/12",children:"Open goal map"}),e.jsx(ie,{size:"sm",className:"min-w-0 sm:min-w-[6.5rem]",onClick:()=>c(!0),children:"Reflect"})]})})},{id:"inspector",title:"Inspector",description:"Selected-node inspector widget.",defaultWidth:4,defaultHeight:5,minWidth:4,render:()=>e.jsxs(R,{className:"h-full min-w-0",children:[e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:n.entityKind?e.jsx(k,{kind:n.entityKind,compact:!0,gradient:!1,iconOnly:!0}):e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/42",children:n.eyebrow})}),e.jsx("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:n.entityKind?e.jsx(re,{kind:n.entityKind,label:n.title,variant:"heading",size:"lg",showKind:!1}):e.jsx("h2",{className:"font-display text-[clamp(1.25rem,2.2vw,1.8rem)] leading-none text-white",children:n.title})}),e.jsx("p",{className:"mt-3 text-sm leading-6 text-white/60",children:n.summary}),n.chips.length>0?e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:n.chips.map(i=>e.jsx(C,{className:"bg-white/[0.08] text-white/74",children:i},i))}):null,n.stats.length>0?e.jsx("div",{className:"mt-4 grid gap-2",children:n.stats.map(i=>e.jsx("div",{className:"rounded-[18px] bg-white/[0.04] px-3 py-3 text-sm text-white/68",children:i},i))}):null,e.jsx("div",{className:"mt-5",children:e.jsx(y,{to:n.href,className:K("inline-flex min-h-11 w-full items-center justify-center rounded-[var(--radius-control)] px-4 py-2.5 text-sm font-medium whitespace-nowrap shadow-[0_12px_30px_rgba(192,193,255,0.08)]",n.entityKind?ne(n.entityKind,!0):"bg-[linear-gradient(135deg,rgba(192,193,255,0.36),rgba(192,193,255,0.22))] text-white"),children:n.ctaLabel})})]})},...$?[{id:"devrage",title:"Devrage metric",description:"Daily user-message frustration metric.",defaultWidth:4,defaultHeight:3,minWidth:4,render:()=>e.jsx(he,{metric:a.devrageMetric})}]:[],{id:"actions",title:"Open threads",description:"Action and pulse cards.",defaultWidth:8,defaultHeight:3,render:()=>e.jsxs("div",{className:"grid min-w-0 gap-4 lg:grid-cols-[minmax(0,1.05fr)_minmax(0,0.95fr)]",children:[e.jsxs(I,{to:"/psyche/behaviors",className:"rounded-[28px] border border-white/8 bg-[linear-gradient(180deg,rgba(17,29,32,0.96),rgba(11,21,23,0.94))] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[rgba(110,231,183,0.82)]",children:"Best next reflective move"}),e.jsx("div",{className:"mt-3 font-display text-[clamp(1.45rem,2.2vw,2rem)] leading-none text-white",children:(g==null?void 0:g.preferredResponse)||"Map the active loop, then name the committed move that brings you back."}),e.jsx("p",{className:"mt-3 text-sm leading-6 text-white/58",children:(g==null?void 0:g.targetBehavior)||"When the loop is explicit, the return path stops feeling abstract."})]}),e.jsxs(I,{to:A?`/psyche/reports/${A.id}`:"/psyche/reports",className:"rounded-[28px] border border-white/8 bg-[linear-gradient(180deg,rgba(24,19,37,0.96),rgba(13,12,22,0.94))] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-violet-100/72",children:"Open threads"}),e.jsxs("div",{className:"mt-3 grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"rounded-[22px] bg-white/[0.04] px-4 py-4",children:[e.jsx("div",{className:"text-sm text-white/58",children:"Insights"}),e.jsx("div",{className:"mt-2 font-display text-4xl text-white",children:a.openInsights})]}),e.jsxs("div",{className:"rounded-[22px] bg-white/[0.04] px-4 py-4",children:[e.jsx("div",{className:"text-sm text-white/58",children:"Notes"}),e.jsx("div",{className:"mt-2 font-display text-4xl text-white",children:a.openNotes})]})]})]})]})},{id:"questionnaires",title:"Questionnaire pulse",description:"Recent questionnaire state.",defaultWidth:12,defaultHeight:2,render:()=>{var i;return e.jsxs(I,{to:u!=null&&u.latestRunId?`/psyche/questionnaire-runs/${u.latestRunId}`:"/psyche/questionnaires",className:"rounded-[28px] border border-white/8 bg-[linear-gradient(180deg,rgba(17,31,39,0.97),rgba(10,18,24,0.95))] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-sky-100/72",children:"Questionnaire pulse"}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"font-display text-[clamp(1.4rem,2.2vw,2rem)] leading-none text-white",children:(u==null?void 0:u.title)??"Questionnaire library ready"}),e.jsxs(C,{className:"bg-white/[0.08] text-white/78",children:[(((i=r.data)==null?void 0:i.instruments)??[]).length," available"]})]})]})}}];return e.jsxs("div",{className:"grid min-w-0 gap-4 overflow-x-clip",children:[e.jsx(U,{surfaceId:"psyche",baseWidgets:q}),e.jsx(ce,{open:o,onOpenChange:i=>{c(i);const m=new URLSearchParams(l);m.delete("reflect"),d(m,{replace:!0})}})]})}export{Ne as PsychePage};
@@ -1,4 +1,4 @@
1
- import{c2 as ke,r as y,j as t}from"./vendor-DHkYh85p.js";import{j as je,i as f,k as Ie}from"./state-B-4sS1xO.js";import{u as Ne,s as Se,i as Ce,cC as Pe,cr as Te,cD as re,bm as Le,bk as K,bl as Q,cq as $,L as Be,E as Ee,B as F,V as ne,ck as Fe,b as q,_ as qe,U as Me,c as Ae,Q as Oe,a0 as Ke,a1 as Qe,F as l,I as $e,T as w,m as M,cs as De,ct as Re,cE as Ue,bx as Ve,bw as We,cu as ze,bA as _e,bz as Ge,by as He}from"./index-BHTUu_4M.js";import{E as Je}from"./entity-note-count-link-BmGDB572.js";import{A as oe}from"./atlas-panel-rfH2qOez.js";import{O as Xe}from"./orbit-map-GD05-0oS.js";import{S as D}from"./schema-badge-DyKbxb51.js";import{u as Ye,p as Ze}from"./use-psyche-focus-target-C1C_XjYG.js";import{P as et}from"./page-hero-CQWo1Mm_.js";import{p as R}from"./query-cache-IQ8W-LNC.js";import{c as le}from"./psyche-schemas-HFmg37Wj.js";import{g as tt,f as de}from"./schema-visuals-D6nxjbYC.js";import"./board-BkDRaMp6.js";import"./ui-C13Nbgas.js";import"./motion-BeD44FeG.js";import"./forms-BFlTgZ3W.js";import"./graph-D6JLqDbD.js";const k={title:"",description:"",targetBehavior:"",cueContexts:[],shortTermPayoff:"",longTermCost:"",preferredResponse:"",linkedValueIds:[],linkedSchemaLabels:[],linkedModeIds:[],linkedBeliefIds:[],userId:null};function st(r){return{title:r.title,description:r.description,targetBehavior:r.targetBehavior,cueContexts:r.cueContexts,shortTermPayoff:r.shortTermPayoff,longTermCost:r.longTermCost,preferredResponse:r.preferredResponse,linkedValueIds:r.linkedValueIds,linkedSchemaLabels:r.linkedSchemaLabels,linkedModeIds:r.linkedModeIds,linkedBeliefIds:r.linkedBeliefIds,userId:r.userId??null}}function at(r){const n=new Set;return r.filter(d=>{const j=`${d.entityType}:${d.entityId}:${d.anchorKey??""}`;return n.has(j)?!1:(n.add(j),!0)})}function it(r){const n=r.replace(/\s+/g," ").trim();return n.length<=180?n:`${n.slice(0,177).trimEnd()}...`}function kt(){var X,Y,Z,ee,te,se;const r=Ne(),n=je(),[d,j]=ke(),[ce,h]=y.useState(!1),[u,x]=y.useState(null),[c,v]=y.useState(null),[I,p]=y.useState(k),[ue,N]=y.useState(null),S=f({queryKey:["forge-psyche-patterns"],queryFn:Ve}),C=f({queryKey:["forge-psyche-values"],queryFn:We}),P=f({queryKey:["forge-psyche-schema-catalog"],queryFn:ze}),T=f({queryKey:["forge-psyche-modes"],queryFn:_e}),L=f({queryKey:["forge-psyche-beliefs"],queryFn:Ge}),B=f({queryKey:["forge-psyche-behaviors"],queryFn:He}),m=((X=S.data)==null?void 0:X.patterns)??[],U=((Y=C.data)==null?void 0:Y.values)??[],A=((Z=P.data)==null?void 0:Z.schemas)??[],V=((ee=T.data)==null?void 0:ee.modes)??[],W=((te=L.data)==null?void 0:te.beliefs)??[],z=((se=B.data)==null?void 0:se.behaviors)??[],g=Se(r.selectedUserIds),_=d.get("focus"),he=r.snapshot.dashboard.notesSummaryByEntity,b=f({enabled:c!==null,queryKey:["forge-note",c],queryFn:()=>re(c)});Ye(_),y.useEffect(()=>{if(d.get("create")==="1"){h(!0),x(null),p({...k,userId:d.get("userId")??g}),v(d.get("sourceObservationNoteId"));const e=new URLSearchParams(d);e.delete("create"),e.delete("sourceObservationNoteId"),e.delete("userId"),j(e,{replace:!0})}},[g,d,j]);const G=Ie({mutationFn:async e=>{var o,E;const s=le.parse(e);if(u)return Pe(u.id,s);const a=await Te(s);if(c){const O=((E=(o=b.data)==null?void 0:o.note)==null?void 0:E.id)===c?b.data.note:(await re(c)).note;await Le(c,{links:at([...O.links,{entityType:"behavior_pattern",entityId:a.pattern.id,anchorKey:null}])})}return a},onSuccess:async()=>{h(!1),x(null),v(null),p({...k,userId:g}),N(null),await Promise.all([n.invalidateQueries({queryKey:["forge-psyche-patterns"]}),n.invalidateQueries({queryKey:["forge-psyche-overview"]}),n.invalidateQueries({queryKey:["forge-psyche-self-observation-calendar"]}),Ce(n),n.invalidateQueries({queryKey:["notes-index"]})])}}),pe=U.map(e=>({value:e.id,label:$(e.title,e.user),description:Q(e.valuedDirection,e.user),searchText:K([e.title,e.valuedDirection,e.description],e),kind:"value"})),me=A.map(e=>({value:e.title,label:e.title,description:`${e.description} ${tt(e.family)}`,searchText:`${e.slug} ${e.family} ${e.schemaType}`,badge:t.jsx(D,{label:e.title,schemaType:e.schemaType,compact:!0}),menuBadge:t.jsx(D,{label:e.title,schemaType:e.schemaType,compact:!0})})),ge=V.map(e=>({value:e.id,label:$(e.title,e.user),description:Q(e.archetype||e.family,e.user),searchText:K([e.title,e.archetype,e.family,e.persona],e),kind:"mode"})),ye=W.map(e=>({value:e.id,label:$(e.statement,e.user),description:Q(e.flexibleAlternative||e.originNote,e.user),searchText:K([e.statement,e.flexibleAlternative,e.originNote,e.beliefType],e),kind:"belief"})),fe=async e=>{const{mode:s}=await Re({family:"coping",archetype:"",title:e,persona:"",imagery:"",symbolicForm:"",facialExpression:"",fear:"",burden:"",protectiveJob:"",originContext:"",firstAppearanceAt:null,linkedPatternIds:[],linkedBehaviorIds:[],linkedValueIds:[],userId:I.userId});return R(n,["forge-psyche-modes"],"modes",s),await n.invalidateQueries({queryKey:["forge-psyche-overview"]}),{value:s.id,label:s.title,description:s.archetype||s.family,kind:"mode"}},xe=async e=>{const{value:s}=await De({title:e,description:"",valuedDirection:e,whyItMatters:"",linkedGoalIds:[],linkedProjectIds:[],linkedTaskIds:[],committedActions:[],userId:I.userId});return R(n,["forge-psyche-values"],"values",s),await n.invalidateQueries({queryKey:["forge-psyche-overview"]}),{value:s.id,label:s.title,description:s.valuedDirection,kind:"value"}},ve=async e=>{const{belief:s}=await Ue({schemaId:null,statement:e,beliefType:"absolute",originNote:"",confidence:60,evidenceFor:[],evidenceAgainst:[],flexibleAlternative:"",linkedValueIds:[],linkedBehaviorIds:[],linkedModeIds:[],linkedReportIds:[],userId:I.userId});return R(n,["forge-psyche-beliefs"],"beliefs",s),await n.invalidateQueries({queryKey:["forge-psyche-overview"]}),{value:s.id,label:s.statement,description:s.flexibleAlternative||s.originNote,kind:"belief"}},H=y.useMemo(()=>m.filter(e=>!z.some(s=>s.kind==="away"&&s.linkedPatternIds.includes(e.id))),[m,z]),be=m.slice(0,5).map((e,s)=>({id:e.id,label:`${e.linkedValueIds.length} values`,title:e.title,detail:e.preferredResponse,href:`/psyche/patterns?focus=${e.id}#pattern-lanes`,angle:-92+s*70,radius:150+s%2*14,tone:["rose","sky","violet","mint"][s%4]})),we=[{id:"loop",eyebrow:"Loop",title:"Name the pattern and the behavior it keeps producing",description:"This should feel like a recognizable loop, not a diagnostic label.",render:(e,s)=>{var a;return t.jsxs(t.Fragment,{children:[c?t.jsxs("div",{className:"rounded-[22px] border border-[rgba(110,231,183,0.18)] bg-[rgba(110,231,183,0.08)] p-4",children:[t.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[rgba(110,231,183,0.82)]",children:"Source observation"}),t.jsx("div",{className:"mt-2 text-sm leading-6 text-white/78",children:b.isLoading?"Loading the saved observation note...":(a=b.data)!=null&&a.note?it(b.data.note.contentPlain||b.data.note.contentMarkdown):"Forge will link this pattern back to the saved observation when you submit it."})]}):null,t.jsx(Ke,{value:e.userId??null,users:r.snapshot.users,onChange:o=>s({userId:o}),defaultLabel:Qe(r.snapshot.users.find(o=>o.id===g)??null,"Choose pattern owner"),help:"Patterns can belong to a human or bot user even when linked values, modes, or beliefs cross owners."}),t.jsx(l,{label:"Pattern name",description:"Give the loop a name you will recognize quickly later.",children:t.jsx($e,{value:e.title,onChange:o=>s({title:o.target.value}),placeholder:"Anxious reassurance loop"})}),t.jsx(l,{label:"What happens in the loop",description:"Describe the actual sequence of behavior, not the diagnosis.",children:t.jsx(w,{value:e.targetBehavior,onChange:o=>s({targetBehavior:o.target.value}),placeholder:"What do you actually do when the trigger hits?"})}),t.jsx(l,{label:"Description",description:"Write the loop in plain language so it stays usable in the future.",children:t.jsx(w,{value:e.description,onChange:o=>s({description:o.target.value}),placeholder:"Describe the loop in plain human language so it stays recognizable later."})})]})}},{id:"dynamics",eyebrow:"Dynamics",title:"Capture cues, payoff, cost, and the desired response",description:"The goal is to make the action map obvious at a glance.",render:(e,s)=>t.jsxs(t.Fragment,{children:[t.jsx(l,{label:"Common cues",description:"Add one cue per line so the trigger pattern stays easy to scan.",children:t.jsx(w,{value:e.cueContexts.join(`
1
+ import{c2 as ke,r as y,j as t}from"./vendor-DHkYh85p.js";import{j as je,i as f,k as Ie}from"./state-B-4sS1xO.js";import{u as Ne,s as Se,i as Ce,cC as Pe,cr as Te,cD as re,bm as Le,bk as K,bl as Q,cq as $,L as Be,E as Ee,B as F,V as ne,ck as Fe,b as q,_ as qe,U as Me,c as Ae,Q as Oe,a0 as Ke,a1 as Qe,F as l,I as $e,T as w,m as M,cs as De,ct as Re,cE as Ue,bx as Ve,bw as We,cu as ze,bA as _e,bz as Ge,by as He}from"./index-CF4J4R9L.js";import{E as Je}from"./entity-note-count-link-DrhjJZ4i.js";import{A as oe}from"./atlas-panel-CdVNPotj.js";import{O as Xe}from"./orbit-map-Dzi6KliQ.js";import{S as D}from"./schema-badge-BZO-qNhO.js";import{u as Ye,p as Ze}from"./use-psyche-focus-target-C1C_XjYG.js";import{P as et}from"./page-hero-DRy5b2MU.js";import{p as R}from"./query-cache-IQ8W-LNC.js";import{c as le}from"./psyche-schemas-HFmg37Wj.js";import{g as tt,f as de}from"./schema-visuals-D6nxjbYC.js";import"./board-BkDRaMp6.js";import"./ui-C13Nbgas.js";import"./motion-BeD44FeG.js";import"./forms-BFlTgZ3W.js";import"./graph-D6JLqDbD.js";const k={title:"",description:"",targetBehavior:"",cueContexts:[],shortTermPayoff:"",longTermCost:"",preferredResponse:"",linkedValueIds:[],linkedSchemaLabels:[],linkedModeIds:[],linkedBeliefIds:[],userId:null};function st(r){return{title:r.title,description:r.description,targetBehavior:r.targetBehavior,cueContexts:r.cueContexts,shortTermPayoff:r.shortTermPayoff,longTermCost:r.longTermCost,preferredResponse:r.preferredResponse,linkedValueIds:r.linkedValueIds,linkedSchemaLabels:r.linkedSchemaLabels,linkedModeIds:r.linkedModeIds,linkedBeliefIds:r.linkedBeliefIds,userId:r.userId??null}}function at(r){const n=new Set;return r.filter(d=>{const j=`${d.entityType}:${d.entityId}:${d.anchorKey??""}`;return n.has(j)?!1:(n.add(j),!0)})}function it(r){const n=r.replace(/\s+/g," ").trim();return n.length<=180?n:`${n.slice(0,177).trimEnd()}...`}function kt(){var X,Y,Z,ee,te,se;const r=Ne(),n=je(),[d,j]=ke(),[ce,h]=y.useState(!1),[u,x]=y.useState(null),[c,v]=y.useState(null),[I,p]=y.useState(k),[ue,N]=y.useState(null),S=f({queryKey:["forge-psyche-patterns"],queryFn:Ve}),C=f({queryKey:["forge-psyche-values"],queryFn:We}),P=f({queryKey:["forge-psyche-schema-catalog"],queryFn:ze}),T=f({queryKey:["forge-psyche-modes"],queryFn:_e}),L=f({queryKey:["forge-psyche-beliefs"],queryFn:Ge}),B=f({queryKey:["forge-psyche-behaviors"],queryFn:He}),m=((X=S.data)==null?void 0:X.patterns)??[],U=((Y=C.data)==null?void 0:Y.values)??[],A=((Z=P.data)==null?void 0:Z.schemas)??[],V=((ee=T.data)==null?void 0:ee.modes)??[],W=((te=L.data)==null?void 0:te.beliefs)??[],z=((se=B.data)==null?void 0:se.behaviors)??[],g=Se(r.selectedUserIds),_=d.get("focus"),he=r.snapshot.dashboard.notesSummaryByEntity,b=f({enabled:c!==null,queryKey:["forge-note",c],queryFn:()=>re(c)});Ye(_),y.useEffect(()=>{if(d.get("create")==="1"){h(!0),x(null),p({...k,userId:d.get("userId")??g}),v(d.get("sourceObservationNoteId"));const e=new URLSearchParams(d);e.delete("create"),e.delete("sourceObservationNoteId"),e.delete("userId"),j(e,{replace:!0})}},[g,d,j]);const G=Ie({mutationFn:async e=>{var o,E;const s=le.parse(e);if(u)return Pe(u.id,s);const a=await Te(s);if(c){const O=((E=(o=b.data)==null?void 0:o.note)==null?void 0:E.id)===c?b.data.note:(await re(c)).note;await Le(c,{links:at([...O.links,{entityType:"behavior_pattern",entityId:a.pattern.id,anchorKey:null}])})}return a},onSuccess:async()=>{h(!1),x(null),v(null),p({...k,userId:g}),N(null),await Promise.all([n.invalidateQueries({queryKey:["forge-psyche-patterns"]}),n.invalidateQueries({queryKey:["forge-psyche-overview"]}),n.invalidateQueries({queryKey:["forge-psyche-self-observation-calendar"]}),Ce(n),n.invalidateQueries({queryKey:["notes-index"]})])}}),pe=U.map(e=>({value:e.id,label:$(e.title,e.user),description:Q(e.valuedDirection,e.user),searchText:K([e.title,e.valuedDirection,e.description],e),kind:"value"})),me=A.map(e=>({value:e.title,label:e.title,description:`${e.description} ${tt(e.family)}`,searchText:`${e.slug} ${e.family} ${e.schemaType}`,badge:t.jsx(D,{label:e.title,schemaType:e.schemaType,compact:!0}),menuBadge:t.jsx(D,{label:e.title,schemaType:e.schemaType,compact:!0})})),ge=V.map(e=>({value:e.id,label:$(e.title,e.user),description:Q(e.archetype||e.family,e.user),searchText:K([e.title,e.archetype,e.family,e.persona],e),kind:"mode"})),ye=W.map(e=>({value:e.id,label:$(e.statement,e.user),description:Q(e.flexibleAlternative||e.originNote,e.user),searchText:K([e.statement,e.flexibleAlternative,e.originNote,e.beliefType],e),kind:"belief"})),fe=async e=>{const{mode:s}=await Re({family:"coping",archetype:"",title:e,persona:"",imagery:"",symbolicForm:"",facialExpression:"",fear:"",burden:"",protectiveJob:"",originContext:"",firstAppearanceAt:null,linkedPatternIds:[],linkedBehaviorIds:[],linkedValueIds:[],userId:I.userId});return R(n,["forge-psyche-modes"],"modes",s),await n.invalidateQueries({queryKey:["forge-psyche-overview"]}),{value:s.id,label:s.title,description:s.archetype||s.family,kind:"mode"}},xe=async e=>{const{value:s}=await De({title:e,description:"",valuedDirection:e,whyItMatters:"",linkedGoalIds:[],linkedProjectIds:[],linkedTaskIds:[],committedActions:[],userId:I.userId});return R(n,["forge-psyche-values"],"values",s),await n.invalidateQueries({queryKey:["forge-psyche-overview"]}),{value:s.id,label:s.title,description:s.valuedDirection,kind:"value"}},ve=async e=>{const{belief:s}=await Ue({schemaId:null,statement:e,beliefType:"absolute",originNote:"",confidence:60,evidenceFor:[],evidenceAgainst:[],flexibleAlternative:"",linkedValueIds:[],linkedBehaviorIds:[],linkedModeIds:[],linkedReportIds:[],userId:I.userId});return R(n,["forge-psyche-beliefs"],"beliefs",s),await n.invalidateQueries({queryKey:["forge-psyche-overview"]}),{value:s.id,label:s.statement,description:s.flexibleAlternative||s.originNote,kind:"belief"}},H=y.useMemo(()=>m.filter(e=>!z.some(s=>s.kind==="away"&&s.linkedPatternIds.includes(e.id))),[m,z]),be=m.slice(0,5).map((e,s)=>({id:e.id,label:`${e.linkedValueIds.length} values`,title:e.title,detail:e.preferredResponse,href:`/psyche/patterns?focus=${e.id}#pattern-lanes`,angle:-92+s*70,radius:150+s%2*14,tone:["rose","sky","violet","mint"][s%4]})),we=[{id:"loop",eyebrow:"Loop",title:"Name the pattern and the behavior it keeps producing",description:"This should feel like a recognizable loop, not a diagnostic label.",render:(e,s)=>{var a;return t.jsxs(t.Fragment,{children:[c?t.jsxs("div",{className:"rounded-[22px] border border-[rgba(110,231,183,0.18)] bg-[rgba(110,231,183,0.08)] p-4",children:[t.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[rgba(110,231,183,0.82)]",children:"Source observation"}),t.jsx("div",{className:"mt-2 text-sm leading-6 text-white/78",children:b.isLoading?"Loading the saved observation note...":(a=b.data)!=null&&a.note?it(b.data.note.contentPlain||b.data.note.contentMarkdown):"Forge will link this pattern back to the saved observation when you submit it."})]}):null,t.jsx(Ke,{value:e.userId??null,users:r.snapshot.users,onChange:o=>s({userId:o}),defaultLabel:Qe(r.snapshot.users.find(o=>o.id===g)??null,"Choose pattern owner"),help:"Patterns can belong to a human or bot user even when linked values, modes, or beliefs cross owners."}),t.jsx(l,{label:"Pattern name",description:"Give the loop a name you will recognize quickly later.",children:t.jsx($e,{value:e.title,onChange:o=>s({title:o.target.value}),placeholder:"Anxious reassurance loop"})}),t.jsx(l,{label:"What happens in the loop",description:"Describe the actual sequence of behavior, not the diagnosis.",children:t.jsx(w,{value:e.targetBehavior,onChange:o=>s({targetBehavior:o.target.value}),placeholder:"What do you actually do when the trigger hits?"})}),t.jsx(l,{label:"Description",description:"Write the loop in plain language so it stays usable in the future.",children:t.jsx(w,{value:e.description,onChange:o=>s({description:o.target.value}),placeholder:"Describe the loop in plain human language so it stays recognizable later."})})]})}},{id:"dynamics",eyebrow:"Dynamics",title:"Capture cues, payoff, cost, and the desired response",description:"The goal is to make the action map obvious at a glance.",render:(e,s)=>t.jsxs(t.Fragment,{children:[t.jsx(l,{label:"Common cues",description:"Add one cue per line so the trigger pattern stays easy to scan.",children:t.jsx(w,{value:e.cueContexts.join(`
2
2
  `),onChange:a=>s({cueContexts:a.target.value.split(`
3
3
  `).map(o=>o.trim()).filter(Boolean)}),placeholder:`One line per cue
4
4
  Silence after vulnerability
@@ -1 +1 @@
1
- import{cc as E,b5 as k,r as d,j as e,aC as D,cM as O,cN as M,cO as I,cP as T}from"./vendor-DHkYh85p.js";import{i as B,k as x}from"./state-B-4sS1xO.js";import{cF as L,cG as Q,cH as R,cI as A,cJ as F,L as V,E as $,B as b,ck as z,C as p,Z as Y,a as G,c as H,cK as K}from"./index-BHTUu_4M.js";import{P as U}from"./page-hero-CQWo1Mm_.js";import"./board-BkDRaMp6.js";import"./ui-C13Nbgas.js";import"./motion-BeD44FeG.js";import"./forms-BFlTgZ3W.js";import"./graph-D6JLqDbD.js";const Z={locale:"en",instructions:"Add questionnaire instructions here.",completionNote:"",presentationMode:"single_question",responseStyle:"four_point_frequency",itemIds:["item_1"],items:[{id:"item_1",prompt:"Sample question",shortLabel:"",description:"",helperText:"",required:!0,visibility:null,tags:[],options:[{key:"0",label:"Not at all",value:0,description:""},{key:"1",label:"Several days",value:1,description:""},{key:"2",label:"More than half the days",value:2,description:""},{key:"3",label:"Nearly every day",value:3,description:""}]}],sections:[{id:"section_1",title:"Section 1",description:"",visibility:null,itemIds:["item_1"]}],pageSize:null},W={scores:[{key:"total",label:"Total score",description:"",valueType:"number",expression:{kind:"sum",itemIds:["item_1"]},dependsOnItemIds:["item_1"],missingPolicy:{mode:"require_all"},bands:[],roundTo:null,unitLabel:""}]},X={retrievalDate:"2026-04-06",sourceClass:"secondary_verified",scoringNotes:"Describe the scoring method and provenance here.",sources:[{label:"Primary source",url:"https://example.com",citation:"Replace with a real citation.",notes:""}]};function h(s){const r=(s==null?void 0:s.draftVersion)??(s==null?void 0:s.currentVersion);return{title:(s==null?void 0:s.title)??"",subtitle:(s==null?void 0:s.subtitle)??"",description:(s==null?void 0:s.description)??"",aliases:(s==null?void 0:s.aliases.join(", "))??"",symptomDomains:(s==null?void 0:s.symptomDomains.join(", "))??"",tags:(s==null?void 0:s.tags.join(", "))??"",sourceClass:(s==null?void 0:s.sourceClass)??"secondary_verified",availability:(s==null?void 0:s.availability)??"custom",isSelfReport:(s==null?void 0:s.isSelfReport)??!0,label:(r==null?void 0:r.label)??"Draft 1",definitionJson:JSON.stringify((r==null?void 0:r.definition)??Z,null,2),scoringJson:JSON.stringify((r==null?void 0:r.scoring)??W,null,2),provenanceJson:JSON.stringify((r==null?void 0:r.provenance)??X,null,2)}}function w(s){return s.split(",").map(r=>r.trim()).filter(Boolean)}function _(s){return{title:s.title.trim(),subtitle:s.subtitle.trim(),description:s.description.trim(),aliases:w(s.aliases),symptomDomains:w(s.symptomDomains),tags:w(s.tags),sourceClass:s.sourceClass,availability:s.availability,isSelfReport:s.isSelfReport,versionLabel:s.label.trim()||"Draft 1",definition:JSON.parse(s.definitionJson),scoring:JSON.parse(s.scoringJson),provenance:JSON.parse(s.provenanceJson),userId:"user_operator"}}const ee=[{id:"metadata",label:"Metadata",icon:O},{id:"structure",label:"Structure",icon:M},{id:"scoring",label:"Scoring",icon:I},{id:"publish",label:"Publish",icon:T}];function de(){var S,J;const{instrumentId:s}=E(),r=k(),[c,C]=d.useState("metadata"),[n,a]=d.useState(()=>h(null)),[g,N]=d.useState(null),l=B({queryKey:["forge-psyche-questionnaire-builder",s],queryFn:()=>K(s),enabled:!!s}),u=x({mutationFn:async()=>{var i;if(!s)throw new Error("Missing questionnaire id");const t=(i=l.data)==null?void 0:i.instrument;return t!=null&&t.isSystem?L(s,{userId:"user_operator"}):Q(s)},onSuccess:t=>{a(h(t.instrument)),t.instrument.id!==s&&r(`/psyche/questionnaires/${t.instrument.id}/edit`,{replace:!0})}}),y=x({mutationFn:async()=>R(_(n)),onSuccess:t=>{r(`/psyche/questionnaires/${t.instrument.id}/edit`,{replace:!0})}}),f=x({mutationFn:async()=>{if(!s)throw new Error("Missing questionnaire id");const t=_(n);return A(s,{...t,label:t.versionLabel})}}),v=x({mutationFn:async()=>{if(!s)throw new Error("Missing questionnaire id");return F(s,{label:n.label})},onSuccess:t=>{r(`/psyche/questionnaires/${t.instrument.id}`)}});d.useEffect(()=>{var i;if(!s){a(h(null));return}const t=(i=l.data)==null?void 0:i.instrument;if(t){if(!t.draftVersion&&!u.isPending){u.mutate();return}a(h(t))}},[(S=l.data)==null?void 0:S.instrument,s,u]);const P=s?"Edit questionnaire":"Build questionnaire",o=((J=l.data)==null?void 0:J.instrument)??null,j=l.isLoading||u.isPending||y.isPending||f.isPending||v.isPending,m=d.useMemo(()=>{try{return{definition:JSON.parse(n.definitionJson),scoring:JSON.parse(n.scoringJson)}}catch{return null}},[n.definitionJson,n.scoringJson]);if(s&&l.isLoading&&!o)return e.jsx(V,{eyebrow:"Questionnaire builder",title:"Loading editable draft",description:"Preparing the current questionnaire draft so the builder can open on real versioned data."});if(l.isError)return e.jsx($,{eyebrow:"Questionnaire builder",error:l.error,onRetry:()=>void l.refetch()});const q=async()=>{try{N(null),s?await f.mutateAsync():await y.mutateAsync()}catch(t){N(t instanceof Error?t.message:"Unable to save questionnaire draft.")}};return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(U,{eyebrow:"Psyche",title:P,description:"Edit versioned questionnaire metadata, structure, scoring, and publication state directly in the app. Seeded instruments branch into editable drafts before any change is made.",badge:s?(o==null?void 0:o.title)??"Draft":"New draft",actions:s?e.jsx(D,{to:`/psyche/questionnaires/${s}`,children:e.jsx(b,{variant:"secondary",children:"Back to detail"})}):null}),e.jsx(z,{}),e.jsx(p,{className:"bg-[linear-gradient(180deg,rgba(15,23,34,0.98),rgba(8,13,20,0.98))]",children:e.jsx("div",{className:"grid gap-3 md:grid-cols-4",children:ee.map(t=>e.jsxs("button",{type:"button",className:Y("rounded-[22px] border px-4 py-4 text-left transition",c===t.id?"border-[rgba(110,231,183,0.24)] bg-[rgba(110,231,183,0.12)] text-white":"border-white/8 bg-white/[0.03] text-white/64 hover:bg-white/[0.05]"),onClick:()=>C(t.id),children:[e.jsx(t.icon,{className:"size-4"}),e.jsx("div",{className:"mt-3 text-sm font-medium",children:t.label})]},t.id))})}),e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.1fr)_minmax(18rem,0.9fr)]",children:[e.jsxs(p,{className:"bg-[linear-gradient(180deg,rgba(16,24,34,0.98),rgba(10,15,24,0.96))]",children:[c==="metadata"?e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/72",children:"Title"}),e.jsx("input",{value:n.title,onChange:t=>a(i=>({...i,title:t.target.value})),className:"rounded-[18px] border border-white/8 bg-white/[0.04] px-4 py-3 text-sm text-white outline-none"})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/72",children:"Subtitle"}),e.jsx("input",{value:n.subtitle,onChange:t=>a(i=>({...i,subtitle:t.target.value})),className:"rounded-[18px] border border-white/8 bg-white/[0.04] px-4 py-3 text-sm text-white outline-none"})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/72",children:"Description"}),e.jsx("textarea",{value:n.description,onChange:t=>a(i=>({...i,description:t.target.value})),className:"min-h-28 rounded-[18px] border border-white/8 bg-white/[0.04] px-4 py-3 text-sm text-white outline-none"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/72",children:"Aliases"}),e.jsx("input",{value:n.aliases,onChange:t=>a(i=>({...i,aliases:t.target.value})),className:"rounded-[18px] border border-white/8 bg-white/[0.04] px-4 py-3 text-sm text-white outline-none"})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/72",children:"Symptom domains"}),e.jsx("input",{value:n.symptomDomains,onChange:t=>a(i=>({...i,symptomDomains:t.target.value})),className:"rounded-[18px] border border-white/8 bg-white/[0.04] px-4 py-3 text-sm text-white outline-none"})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/72",children:"Tags"}),e.jsx("input",{value:n.tags,onChange:t=>a(i=>({...i,tags:t.target.value})),className:"rounded-[18px] border border-white/8 bg-white/[0.04] px-4 py-3 text-sm text-white outline-none"})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/72",children:"Source class"}),e.jsx("select",{value:n.sourceClass,onChange:t=>a(i=>({...i,sourceClass:t.target.value})),className:"rounded-[18px] border border-white/8 bg-white/[0.04] px-4 py-3 text-sm text-white outline-none",children:["public_domain","free_use","open_access","open_noncommercial","free_clinician","secondary_verified"].map(t=>e.jsx("option",{value:t,children:t.replaceAll("_"," ")},t))})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/72",children:"Availability"}),e.jsx("select",{value:n.availability,onChange:t=>a(i=>({...i,availability:t.target.value})),className:"rounded-[18px] border border-white/8 bg-white/[0.04] px-4 py-3 text-sm text-white outline-none",children:["open","free_clinician","custom"].map(t=>e.jsx("option",{value:t,children:t.replaceAll("_"," ")},t))})]})]})]}):null,c==="structure"?e.jsxs("div",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/72",children:"Definition JSON"}),e.jsxs("div",{className:"text-sm leading-6 text-white/56",children:["Items and sections can declare",e.jsx("code",{className:"mx-1 rounded bg-white/[0.06] px-1.5 py-0.5 text-xs text-white",children:"visibility.script"}),"rules such as",e.jsx("code",{className:"mx-1 rounded bg-white/[0.06] px-1.5 py-0.5 text-xs text-white",children:"audit_1 > 0"}),"or",e.jsx("code",{className:"mx-1 rounded bg-white/[0.06] px-1.5 py-0.5 text-xs text-white",children:'answered(question_12) and option(question_12) == "yes"'}),"."]}),e.jsx("textarea",{value:n.definitionJson,onChange:t=>a(i=>({...i,definitionJson:t.target.value})),className:"min-h-[32rem] rounded-[18px] border border-white/8 bg-white/[0.04] px-4 py-3 font-mono text-sm text-white outline-none"})]}):null,c==="scoring"?e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/72",children:"Scoring JSON"}),e.jsx("textarea",{value:n.scoringJson,onChange:t=>a(i=>({...i,scoringJson:t.target.value})),className:"min-h-[24rem] rounded-[18px] border border-white/8 bg-white/[0.04] px-4 py-3 font-mono text-sm text-white outline-none"})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/72",children:"Provenance JSON"}),e.jsx("textarea",{value:n.provenanceJson,onChange:t=>a(i=>({...i,provenanceJson:t.target.value})),className:"min-h-[16rem] rounded-[18px] border border-white/8 bg-white/[0.04] px-4 py-3 font-mono text-sm text-white outline-none"})]})]}):null,c==="publish"?e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/72",children:"Version label"}),e.jsx("input",{value:n.label,onChange:t=>a(i=>({...i,label:t.target.value})),className:"rounded-[18px] border border-white/8 bg-white/[0.04] px-4 py-3 text-sm text-white outline-none"})]}),m?e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[20px] border border-white/8 bg-white/[0.03] px-4 py-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"Items"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold text-white",children:m.definition.items.length})]}),e.jsxs("div",{className:"rounded-[20px] border border-white/8 bg-white/[0.03] px-4 py-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"Sections"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold text-white",children:m.definition.sections.length})]}),e.jsxs("div",{className:"rounded-[20px] border border-white/8 bg-white/[0.03] px-4 py-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"Scores"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold text-white",children:m.scoring.scores.length})]})]}):null,e.jsx("p",{className:"text-sm leading-6 text-white/58",children:"Publishing freezes the current draft into an immutable version for future runs. Past run history will always keep the version it was scored against."})]}):null]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs(p,{className:"bg-[linear-gradient(180deg,rgba(14,21,31,0.98),rgba(9,14,22,0.96))]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/42",children:"Draft posture"}),o!=null&&o.isSystem?e.jsx("div",{className:"mt-4",children:e.jsx(G,{eyebrow:"System seed",title:"This started as a read-only seed",description:"The builder branched it into a user-owned draft before exposing any editable state."})}):e.jsxs("div",{className:"mt-4 grid gap-2",children:[e.jsx(H,{className:"w-fit bg-white/[0.08] text-white/78",children:o!=null&&o.draftVersion?"Draft available":"New draft"}),e.jsx("div",{className:"text-sm leading-6 text-white/60",children:"Save updates whenever the metadata or JSON changes, then publish once the definition is ready for scoring and longitudinal history."})]})]}),e.jsxs(p,{className:"bg-[linear-gradient(180deg,rgba(15,23,33,0.98),rgba(9,15,23,0.96))]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/42",children:"Actions"}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsx(b,{onClick:()=>void q(),disabled:j,children:"Save draft"}),s?e.jsx(b,{variant:"secondary",onClick:()=>v.mutate(),disabled:j||!!g,children:"Publish version"}):null,g?e.jsx("div",{className:"rounded-[18px] border border-rose-400/20 bg-rose-400/10 px-4 py-3 text-sm text-rose-100",children:g}):null]})]})]})]})]})}export{de as PsycheQuestionnaireBuilderPage};
1
+ import{cc as E,b5 as k,r as d,j as e,aC as D,cM as O,cN as M,cO as I,cP as T}from"./vendor-DHkYh85p.js";import{i as B,k as x}from"./state-B-4sS1xO.js";import{cF as L,cG as Q,cH as R,cI as A,cJ as F,L as V,E as $,B as b,ck as z,C as p,Z as Y,a as G,c as H,cK as K}from"./index-CF4J4R9L.js";import{P as U}from"./page-hero-DRy5b2MU.js";import"./board-BkDRaMp6.js";import"./ui-C13Nbgas.js";import"./motion-BeD44FeG.js";import"./forms-BFlTgZ3W.js";import"./graph-D6JLqDbD.js";const Z={locale:"en",instructions:"Add questionnaire instructions here.",completionNote:"",presentationMode:"single_question",responseStyle:"four_point_frequency",itemIds:["item_1"],items:[{id:"item_1",prompt:"Sample question",shortLabel:"",description:"",helperText:"",required:!0,visibility:null,tags:[],options:[{key:"0",label:"Not at all",value:0,description:""},{key:"1",label:"Several days",value:1,description:""},{key:"2",label:"More than half the days",value:2,description:""},{key:"3",label:"Nearly every day",value:3,description:""}]}],sections:[{id:"section_1",title:"Section 1",description:"",visibility:null,itemIds:["item_1"]}],pageSize:null},W={scores:[{key:"total",label:"Total score",description:"",valueType:"number",expression:{kind:"sum",itemIds:["item_1"]},dependsOnItemIds:["item_1"],missingPolicy:{mode:"require_all"},bands:[],roundTo:null,unitLabel:""}]},X={retrievalDate:"2026-04-06",sourceClass:"secondary_verified",scoringNotes:"Describe the scoring method and provenance here.",sources:[{label:"Primary source",url:"https://example.com",citation:"Replace with a real citation.",notes:""}]};function h(s){const r=(s==null?void 0:s.draftVersion)??(s==null?void 0:s.currentVersion);return{title:(s==null?void 0:s.title)??"",subtitle:(s==null?void 0:s.subtitle)??"",description:(s==null?void 0:s.description)??"",aliases:(s==null?void 0:s.aliases.join(", "))??"",symptomDomains:(s==null?void 0:s.symptomDomains.join(", "))??"",tags:(s==null?void 0:s.tags.join(", "))??"",sourceClass:(s==null?void 0:s.sourceClass)??"secondary_verified",availability:(s==null?void 0:s.availability)??"custom",isSelfReport:(s==null?void 0:s.isSelfReport)??!0,label:(r==null?void 0:r.label)??"Draft 1",definitionJson:JSON.stringify((r==null?void 0:r.definition)??Z,null,2),scoringJson:JSON.stringify((r==null?void 0:r.scoring)??W,null,2),provenanceJson:JSON.stringify((r==null?void 0:r.provenance)??X,null,2)}}function w(s){return s.split(",").map(r=>r.trim()).filter(Boolean)}function _(s){return{title:s.title.trim(),subtitle:s.subtitle.trim(),description:s.description.trim(),aliases:w(s.aliases),symptomDomains:w(s.symptomDomains),tags:w(s.tags),sourceClass:s.sourceClass,availability:s.availability,isSelfReport:s.isSelfReport,versionLabel:s.label.trim()||"Draft 1",definition:JSON.parse(s.definitionJson),scoring:JSON.parse(s.scoringJson),provenance:JSON.parse(s.provenanceJson),userId:"user_operator"}}const ee=[{id:"metadata",label:"Metadata",icon:O},{id:"structure",label:"Structure",icon:M},{id:"scoring",label:"Scoring",icon:I},{id:"publish",label:"Publish",icon:T}];function de(){var S,J;const{instrumentId:s}=E(),r=k(),[c,C]=d.useState("metadata"),[n,a]=d.useState(()=>h(null)),[g,N]=d.useState(null),l=B({queryKey:["forge-psyche-questionnaire-builder",s],queryFn:()=>K(s),enabled:!!s}),u=x({mutationFn:async()=>{var i;if(!s)throw new Error("Missing questionnaire id");const t=(i=l.data)==null?void 0:i.instrument;return t!=null&&t.isSystem?L(s,{userId:"user_operator"}):Q(s)},onSuccess:t=>{a(h(t.instrument)),t.instrument.id!==s&&r(`/psyche/questionnaires/${t.instrument.id}/edit`,{replace:!0})}}),y=x({mutationFn:async()=>R(_(n)),onSuccess:t=>{r(`/psyche/questionnaires/${t.instrument.id}/edit`,{replace:!0})}}),f=x({mutationFn:async()=>{if(!s)throw new Error("Missing questionnaire id");const t=_(n);return A(s,{...t,label:t.versionLabel})}}),v=x({mutationFn:async()=>{if(!s)throw new Error("Missing questionnaire id");return F(s,{label:n.label})},onSuccess:t=>{r(`/psyche/questionnaires/${t.instrument.id}`)}});d.useEffect(()=>{var i;if(!s){a(h(null));return}const t=(i=l.data)==null?void 0:i.instrument;if(t){if(!t.draftVersion&&!u.isPending){u.mutate();return}a(h(t))}},[(S=l.data)==null?void 0:S.instrument,s,u]);const P=s?"Edit questionnaire":"Build questionnaire",o=((J=l.data)==null?void 0:J.instrument)??null,j=l.isLoading||u.isPending||y.isPending||f.isPending||v.isPending,m=d.useMemo(()=>{try{return{definition:JSON.parse(n.definitionJson),scoring:JSON.parse(n.scoringJson)}}catch{return null}},[n.definitionJson,n.scoringJson]);if(s&&l.isLoading&&!o)return e.jsx(V,{eyebrow:"Questionnaire builder",title:"Loading editable draft",description:"Preparing the current questionnaire draft so the builder can open on real versioned data."});if(l.isError)return e.jsx($,{eyebrow:"Questionnaire builder",error:l.error,onRetry:()=>void l.refetch()});const q=async()=>{try{N(null),s?await f.mutateAsync():await y.mutateAsync()}catch(t){N(t instanceof Error?t.message:"Unable to save questionnaire draft.")}};return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(U,{eyebrow:"Psyche",title:P,description:"Edit versioned questionnaire metadata, structure, scoring, and publication state directly in the app. Seeded instruments branch into editable drafts before any change is made.",badge:s?(o==null?void 0:o.title)??"Draft":"New draft",actions:s?e.jsx(D,{to:`/psyche/questionnaires/${s}`,children:e.jsx(b,{variant:"secondary",children:"Back to detail"})}):null}),e.jsx(z,{}),e.jsx(p,{className:"bg-[linear-gradient(180deg,rgba(15,23,34,0.98),rgba(8,13,20,0.98))]",children:e.jsx("div",{className:"grid gap-3 md:grid-cols-4",children:ee.map(t=>e.jsxs("button",{type:"button",className:Y("rounded-[22px] border px-4 py-4 text-left transition",c===t.id?"border-[rgba(110,231,183,0.24)] bg-[rgba(110,231,183,0.12)] text-white":"border-white/8 bg-white/[0.03] text-white/64 hover:bg-white/[0.05]"),onClick:()=>C(t.id),children:[e.jsx(t.icon,{className:"size-4"}),e.jsx("div",{className:"mt-3 text-sm font-medium",children:t.label})]},t.id))})}),e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.1fr)_minmax(18rem,0.9fr)]",children:[e.jsxs(p,{className:"bg-[linear-gradient(180deg,rgba(16,24,34,0.98),rgba(10,15,24,0.96))]",children:[c==="metadata"?e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/72",children:"Title"}),e.jsx("input",{value:n.title,onChange:t=>a(i=>({...i,title:t.target.value})),className:"rounded-[18px] border border-white/8 bg-white/[0.04] px-4 py-3 text-sm text-white outline-none"})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/72",children:"Subtitle"}),e.jsx("input",{value:n.subtitle,onChange:t=>a(i=>({...i,subtitle:t.target.value})),className:"rounded-[18px] border border-white/8 bg-white/[0.04] px-4 py-3 text-sm text-white outline-none"})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/72",children:"Description"}),e.jsx("textarea",{value:n.description,onChange:t=>a(i=>({...i,description:t.target.value})),className:"min-h-28 rounded-[18px] border border-white/8 bg-white/[0.04] px-4 py-3 text-sm text-white outline-none"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/72",children:"Aliases"}),e.jsx("input",{value:n.aliases,onChange:t=>a(i=>({...i,aliases:t.target.value})),className:"rounded-[18px] border border-white/8 bg-white/[0.04] px-4 py-3 text-sm text-white outline-none"})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/72",children:"Symptom domains"}),e.jsx("input",{value:n.symptomDomains,onChange:t=>a(i=>({...i,symptomDomains:t.target.value})),className:"rounded-[18px] border border-white/8 bg-white/[0.04] px-4 py-3 text-sm text-white outline-none"})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/72",children:"Tags"}),e.jsx("input",{value:n.tags,onChange:t=>a(i=>({...i,tags:t.target.value})),className:"rounded-[18px] border border-white/8 bg-white/[0.04] px-4 py-3 text-sm text-white outline-none"})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/72",children:"Source class"}),e.jsx("select",{value:n.sourceClass,onChange:t=>a(i=>({...i,sourceClass:t.target.value})),className:"rounded-[18px] border border-white/8 bg-white/[0.04] px-4 py-3 text-sm text-white outline-none",children:["public_domain","free_use","open_access","open_noncommercial","free_clinician","secondary_verified"].map(t=>e.jsx("option",{value:t,children:t.replaceAll("_"," ")},t))})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/72",children:"Availability"}),e.jsx("select",{value:n.availability,onChange:t=>a(i=>({...i,availability:t.target.value})),className:"rounded-[18px] border border-white/8 bg-white/[0.04] px-4 py-3 text-sm text-white outline-none",children:["open","free_clinician","custom"].map(t=>e.jsx("option",{value:t,children:t.replaceAll("_"," ")},t))})]})]})]}):null,c==="structure"?e.jsxs("div",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/72",children:"Definition JSON"}),e.jsxs("div",{className:"text-sm leading-6 text-white/56",children:["Items and sections can declare",e.jsx("code",{className:"mx-1 rounded bg-white/[0.06] px-1.5 py-0.5 text-xs text-white",children:"visibility.script"}),"rules such as",e.jsx("code",{className:"mx-1 rounded bg-white/[0.06] px-1.5 py-0.5 text-xs text-white",children:"audit_1 > 0"}),"or",e.jsx("code",{className:"mx-1 rounded bg-white/[0.06] px-1.5 py-0.5 text-xs text-white",children:'answered(question_12) and option(question_12) == "yes"'}),"."]}),e.jsx("textarea",{value:n.definitionJson,onChange:t=>a(i=>({...i,definitionJson:t.target.value})),className:"min-h-[32rem] rounded-[18px] border border-white/8 bg-white/[0.04] px-4 py-3 font-mono text-sm text-white outline-none"})]}):null,c==="scoring"?e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/72",children:"Scoring JSON"}),e.jsx("textarea",{value:n.scoringJson,onChange:t=>a(i=>({...i,scoringJson:t.target.value})),className:"min-h-[24rem] rounded-[18px] border border-white/8 bg-white/[0.04] px-4 py-3 font-mono text-sm text-white outline-none"})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/72",children:"Provenance JSON"}),e.jsx("textarea",{value:n.provenanceJson,onChange:t=>a(i=>({...i,provenanceJson:t.target.value})),className:"min-h-[16rem] rounded-[18px] border border-white/8 bg-white/[0.04] px-4 py-3 font-mono text-sm text-white outline-none"})]})]}):null,c==="publish"?e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/72",children:"Version label"}),e.jsx("input",{value:n.label,onChange:t=>a(i=>({...i,label:t.target.value})),className:"rounded-[18px] border border-white/8 bg-white/[0.04] px-4 py-3 text-sm text-white outline-none"})]}),m?e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[20px] border border-white/8 bg-white/[0.03] px-4 py-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"Items"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold text-white",children:m.definition.items.length})]}),e.jsxs("div",{className:"rounded-[20px] border border-white/8 bg-white/[0.03] px-4 py-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"Sections"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold text-white",children:m.definition.sections.length})]}),e.jsxs("div",{className:"rounded-[20px] border border-white/8 bg-white/[0.03] px-4 py-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"Scores"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold text-white",children:m.scoring.scores.length})]})]}):null,e.jsx("p",{className:"text-sm leading-6 text-white/58",children:"Publishing freezes the current draft into an immutable version for future runs. Past run history will always keep the version it was scored against."})]}):null]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs(p,{className:"bg-[linear-gradient(180deg,rgba(14,21,31,0.98),rgba(9,14,22,0.96))]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/42",children:"Draft posture"}),o!=null&&o.isSystem?e.jsx("div",{className:"mt-4",children:e.jsx(G,{eyebrow:"System seed",title:"This started as a read-only seed",description:"The builder branched it into a user-owned draft before exposing any editable state."})}):e.jsxs("div",{className:"mt-4 grid gap-2",children:[e.jsx(H,{className:"w-fit bg-white/[0.08] text-white/78",children:o!=null&&o.draftVersion?"Draft available":"New draft"}),e.jsx("div",{className:"text-sm leading-6 text-white/60",children:"Save updates whenever the metadata or JSON changes, then publish once the definition is ready for scoring and longitudinal history."})]})]}),e.jsxs(p,{className:"bg-[linear-gradient(180deg,rgba(15,23,33,0.98),rgba(9,15,23,0.96))]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/42",children:"Actions"}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsx(b,{onClick:()=>void q(),disabled:j,children:"Save draft"}),s?e.jsx(b,{variant:"secondary",onClick:()=>v.mutate(),disabled:j||!!g,children:"Publish version"}):null,g?e.jsx("div",{className:"rounded-[18px] border border-rose-400/20 bg-rose-400/10 px-4 py-3 text-sm text-rose-100",children:g}):null]})]})]})]})]})}export{de as PsycheQuestionnaireBuilderPage};
@@ -1 +1 @@
1
- import{cc as x,j as e,aC as a,bB as h,cM as p,cQ as g}from"./vendor-DHkYh85p.js";import{i as j}from"./state-B-4sS1xO.js";import{L as u,E as b,B as l,ck as v,C as c,c as n,a as N,cK as y}from"./index-BHTUu_4M.js";import{P as w}from"./page-hero-CQWo1Mm_.js";import{R as f,L as k,X as S,Y as L,T as P,b as C}from"./charts-P7EVhIog.js";import"./board-BkDRaMp6.js";import"./ui-C13Nbgas.js";import"./motion-BeD44FeG.js";import"./forms-BFlTgZ3W.js";import"./graph-D6JLqDbD.js";function B(){var o;const{instrumentId:d=""}=x(),i=j({queryKey:["forge-psyche-questionnaire",d],queryFn:()=>y(d),enabled:d.length>0});if(i.isLoading)return e.jsx(u,{eyebrow:"Questionnaire",title:"Loading questionnaire detail",description:"Hydrating the versioned definition, source provenance, and run history."});if(i.isError||!((o=i.data)!=null&&o.instrument))return e.jsx(b,{eyebrow:"Questionnaire",error:i.error,onRetry:()=>void i.refetch()});const t=i.data.instrument,r=t.currentVersion??t.draftVersion,m=!t.isSystem;return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(w,{eyebrow:"Psyche",title:t.title,description:t.description,badge:`${t.itemCount} items`,actions:e.jsxs(e.Fragment,{children:[e.jsx(a,{to:`/psyche/questionnaires/${t.id}/take`,children:e.jsxs(l,{children:[e.jsx(h,{className:"mr-2 size-4"}),"Start run"]})}),m?e.jsx(a,{to:`/psyche/questionnaires/${t.id}/edit`,children:e.jsxs(l,{variant:"secondary",children:[e.jsx(p,{className:"mr-2 size-4"}),"Edit draft"]})}):e.jsx(a,{to:`/psyche/questionnaires/${t.id}/edit`,children:e.jsxs(l,{variant:"secondary",children:[e.jsx(g,{className:"mr-2 size-4"}),"Clone to draft"]})})]})}),e.jsx(v,{}),e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.05fr)_minmax(18rem,0.95fr)]",children:[e.jsxs(c,{className:"bg-[linear-gradient(180deg,rgba(15,23,34,0.98),rgba(9,14,22,0.96))]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[rgba(110,231,183,0.74)]",children:"Guided definition"}),e.jsxs("div",{className:"mt-4 grid gap-4 md:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[22px] bg-white/[0.04] px-4 py-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"Flow"}),e.jsx("div",{className:"mt-2 text-sm text-white/84",children:t.presentationMode.replaceAll("_"," ")})]}),e.jsxs("div",{className:"rounded-[22px] bg-white/[0.04] px-4 py-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"Response style"}),e.jsx("div",{className:"mt-2 text-sm text-white/84",children:t.responseStyle.replaceAll("_"," ")})]}),e.jsxs("div",{className:"rounded-[22px] bg-white/[0.04] px-4 py-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"Version"}),e.jsx("div",{className:"mt-2 text-sm text-white/84",children:t.currentVersionNumber?`v${t.currentVersionNumber}`:"Draft"})]})]}),r?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mt-5 text-sm leading-6 text-white/62",children:r.definition.instructions}),e.jsx("div",{className:"mt-5 grid gap-3",children:r.definition.sections.map(s=>e.jsx("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.03] px-4 py-4",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-white",children:s.title}),s.description?e.jsx("div",{className:"mt-1 text-sm text-white/54",children:s.description}):null]}),e.jsxs(n,{className:"bg-white/[0.08] text-white/78",children:[s.itemIds.length," items"]})]})},s.id))})]}):null]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs(c,{className:"bg-[linear-gradient(180deg,rgba(17,25,34,0.98),rgba(10,15,24,0.96))]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/42",children:"Provenance"}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsx(n,{className:"bg-[rgba(125,211,252,0.12)] text-sky-100/88",children:t.sourceClass.replaceAll("_"," ")}),e.jsx(n,{className:"bg-[rgba(192,193,255,0.12)] text-white/84",children:t.availability.replaceAll("_"," ")}),t.symptomDomains.map(s=>e.jsx(n,{className:"bg-white/[0.06] text-white/72",children:s},s))]}),r?e.jsx("div",{className:"mt-4 grid gap-3",children:r.provenance.sources.map(s=>e.jsxs("a",{href:s.url,target:"_blank",rel:"noreferrer",className:"rounded-[20px] border border-white/8 bg-white/[0.03] px-4 py-4 transition hover:bg-white/[0.05]",children:[e.jsx("div",{className:"text-sm font-medium text-white",children:s.label}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-white/56",children:s.citation})]},s.url))}):null]}),e.jsxs(c,{className:"bg-[linear-gradient(180deg,rgba(15,23,33,0.98),rgba(9,15,23,0.96))]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/42",children:"History over time"}),t.history.length===0?e.jsx("div",{className:"mt-4",children:e.jsx(N,{eyebrow:"Run history",title:"No completed runs yet",description:"Complete the first guided run and the longitudinal score trace will appear here."})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-4 h-56",children:e.jsx(f,{width:"100%",height:"100%",children:e.jsxs(k,{data:[...t.history].reverse(),children:[e.jsx(S,{dataKey:"completedAt",tickFormatter:s=>new Date(s).toLocaleDateString(void 0,{month:"short",day:"numeric"}),stroke:"rgba(255,255,255,0.38)"}),e.jsx(L,{stroke:"rgba(255,255,255,0.38)"}),e.jsx(P,{contentStyle:{background:"rgba(10,15,24,0.96)",border:"1px solid rgba(255,255,255,0.08)",borderRadius:18},labelFormatter:s=>new Date(String(s)).toLocaleString()}),e.jsx(C,{type:"monotone",dataKey:"primaryScore",stroke:"rgba(110,231,183,0.95)",strokeWidth:3,dot:{r:4}})]})})}),e.jsx("div",{className:"mt-4 grid gap-3",children:t.history.slice(0,5).map(s=>e.jsx(a,{to:`/psyche/questionnaire-runs/${s.runId}`,className:"rounded-[20px] border border-white/8 bg-white/[0.03] px-4 py-4 transition hover:bg-white/[0.05]",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-white",children:s.primaryScoreLabel||"Primary score"}),e.jsx("div",{className:"mt-1 text-sm text-white/56",children:new Date(s.completedAt).toLocaleString()})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"text-lg font-semibold text-white",children:s.primaryScore??"—"}),s.bandLabel?e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-[rgba(110,231,183,0.78)]",children:s.bandLabel}):null]})]})},s.runId))})]})]})]})]})]})}export{B as PsycheQuestionnaireDetailPage};
1
+ import{cc as x,j as e,aC as a,bB as h,cM as p,cQ as g}from"./vendor-DHkYh85p.js";import{i as j}from"./state-B-4sS1xO.js";import{L as u,E as b,B as l,ck as v,C as c,c as n,a as N,cK as y}from"./index-CF4J4R9L.js";import{P as w}from"./page-hero-DRy5b2MU.js";import{R as f,L as k,X as S,Y as L,T as P,b as C}from"./charts-P7EVhIog.js";import"./board-BkDRaMp6.js";import"./ui-C13Nbgas.js";import"./motion-BeD44FeG.js";import"./forms-BFlTgZ3W.js";import"./graph-D6JLqDbD.js";function B(){var o;const{instrumentId:d=""}=x(),i=j({queryKey:["forge-psyche-questionnaire",d],queryFn:()=>y(d),enabled:d.length>0});if(i.isLoading)return e.jsx(u,{eyebrow:"Questionnaire",title:"Loading questionnaire detail",description:"Hydrating the versioned definition, source provenance, and run history."});if(i.isError||!((o=i.data)!=null&&o.instrument))return e.jsx(b,{eyebrow:"Questionnaire",error:i.error,onRetry:()=>void i.refetch()});const t=i.data.instrument,r=t.currentVersion??t.draftVersion,m=!t.isSystem;return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(w,{eyebrow:"Psyche",title:t.title,description:t.description,badge:`${t.itemCount} items`,actions:e.jsxs(e.Fragment,{children:[e.jsx(a,{to:`/psyche/questionnaires/${t.id}/take`,children:e.jsxs(l,{children:[e.jsx(h,{className:"mr-2 size-4"}),"Start run"]})}),m?e.jsx(a,{to:`/psyche/questionnaires/${t.id}/edit`,children:e.jsxs(l,{variant:"secondary",children:[e.jsx(p,{className:"mr-2 size-4"}),"Edit draft"]})}):e.jsx(a,{to:`/psyche/questionnaires/${t.id}/edit`,children:e.jsxs(l,{variant:"secondary",children:[e.jsx(g,{className:"mr-2 size-4"}),"Clone to draft"]})})]})}),e.jsx(v,{}),e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.05fr)_minmax(18rem,0.95fr)]",children:[e.jsxs(c,{className:"bg-[linear-gradient(180deg,rgba(15,23,34,0.98),rgba(9,14,22,0.96))]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[rgba(110,231,183,0.74)]",children:"Guided definition"}),e.jsxs("div",{className:"mt-4 grid gap-4 md:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[22px] bg-white/[0.04] px-4 py-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"Flow"}),e.jsx("div",{className:"mt-2 text-sm text-white/84",children:t.presentationMode.replaceAll("_"," ")})]}),e.jsxs("div",{className:"rounded-[22px] bg-white/[0.04] px-4 py-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"Response style"}),e.jsx("div",{className:"mt-2 text-sm text-white/84",children:t.responseStyle.replaceAll("_"," ")})]}),e.jsxs("div",{className:"rounded-[22px] bg-white/[0.04] px-4 py-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"Version"}),e.jsx("div",{className:"mt-2 text-sm text-white/84",children:t.currentVersionNumber?`v${t.currentVersionNumber}`:"Draft"})]})]}),r?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mt-5 text-sm leading-6 text-white/62",children:r.definition.instructions}),e.jsx("div",{className:"mt-5 grid gap-3",children:r.definition.sections.map(s=>e.jsx("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.03] px-4 py-4",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-white",children:s.title}),s.description?e.jsx("div",{className:"mt-1 text-sm text-white/54",children:s.description}):null]}),e.jsxs(n,{className:"bg-white/[0.08] text-white/78",children:[s.itemIds.length," items"]})]})},s.id))})]}):null]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs(c,{className:"bg-[linear-gradient(180deg,rgba(17,25,34,0.98),rgba(10,15,24,0.96))]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/42",children:"Provenance"}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsx(n,{className:"bg-[rgba(125,211,252,0.12)] text-sky-100/88",children:t.sourceClass.replaceAll("_"," ")}),e.jsx(n,{className:"bg-[rgba(192,193,255,0.12)] text-white/84",children:t.availability.replaceAll("_"," ")}),t.symptomDomains.map(s=>e.jsx(n,{className:"bg-white/[0.06] text-white/72",children:s},s))]}),r?e.jsx("div",{className:"mt-4 grid gap-3",children:r.provenance.sources.map(s=>e.jsxs("a",{href:s.url,target:"_blank",rel:"noreferrer",className:"rounded-[20px] border border-white/8 bg-white/[0.03] px-4 py-4 transition hover:bg-white/[0.05]",children:[e.jsx("div",{className:"text-sm font-medium text-white",children:s.label}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-white/56",children:s.citation})]},s.url))}):null]}),e.jsxs(c,{className:"bg-[linear-gradient(180deg,rgba(15,23,33,0.98),rgba(9,15,23,0.96))]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/42",children:"History over time"}),t.history.length===0?e.jsx("div",{className:"mt-4",children:e.jsx(N,{eyebrow:"Run history",title:"No completed runs yet",description:"Complete the first guided run and the longitudinal score trace will appear here."})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-4 h-56",children:e.jsx(f,{width:"100%",height:"100%",children:e.jsxs(k,{data:[...t.history].reverse(),children:[e.jsx(S,{dataKey:"completedAt",tickFormatter:s=>new Date(s).toLocaleDateString(void 0,{month:"short",day:"numeric"}),stroke:"rgba(255,255,255,0.38)"}),e.jsx(L,{stroke:"rgba(255,255,255,0.38)"}),e.jsx(P,{contentStyle:{background:"rgba(10,15,24,0.96)",border:"1px solid rgba(255,255,255,0.08)",borderRadius:18},labelFormatter:s=>new Date(String(s)).toLocaleString()}),e.jsx(C,{type:"monotone",dataKey:"primaryScore",stroke:"rgba(110,231,183,0.95)",strokeWidth:3,dot:{r:4}})]})})}),e.jsx("div",{className:"mt-4 grid gap-3",children:t.history.slice(0,5).map(s=>e.jsx(a,{to:`/psyche/questionnaire-runs/${s.runId}`,className:"rounded-[20px] border border-white/8 bg-white/[0.03] px-4 py-4 transition hover:bg-white/[0.05]",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-white",children:s.primaryScoreLabel||"Primary score"}),e.jsx("div",{className:"mt-1 text-sm text-white/56",children:new Date(s.completedAt).toLocaleString()})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"text-lg font-semibold text-white",children:s.primaryScore??"—"}),s.bandLabel?e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-[rgba(110,231,183,0.78)]",children:s.bandLabel}):null]})]})},s.runId))})]})]})]})]})]})}export{B as PsycheQuestionnaireDetailPage};
@@ -1 +1 @@
1
- import{cc as x,j as e,aC as d}from"./vendor-DHkYh85p.js";import{i as u}from"./state-B-4sS1xO.js";import{P as p}from"./page-hero-CQWo1Mm_.js";import{L as g,E as h,B as o,C as c,a as b,c as j,cL as y}from"./index-BHTUu_4M.js";import"./board-BkDRaMp6.js";import"./ui-C13Nbgas.js";import"./motion-BeD44FeG.js";import"./forms-BFlTgZ3W.js";import"./graph-D6JLqDbD.js";function B(){const{runId:a=""}=x(),s=u({queryKey:["forge-psyche-questionnaire-run",a],queryFn:()=>y(a),enabled:a.length>0});if(s.isLoading)return e.jsx(g,{eyebrow:"Questionnaire result",title:"Loading scored run",description:"Hydrating the recorded answers, stored scores, and longitudinal context."});if(s.isError||!s.data)return e.jsx(h,{eyebrow:"Questionnaire result",error:s.error,onRetry:()=>void s.refetch()});const t=s.data,l=new Map(t.answers.map(r=>[r.itemId,r]));return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(p,{eyebrow:"Questionnaire result",title:t.instrument.title,description:"Stored raw answers, computed scores, and score history all remain attached to the exact version used for this run.",badge:t.run.completedAt?"Completed":"Draft",actions:e.jsxs(e.Fragment,{children:[e.jsx(d,{to:`/psyche/questionnaires/${t.instrument.id}`,children:e.jsx(o,{variant:"secondary",children:"Back to questionnaire"})}),e.jsx(d,{to:`/psyche/questionnaires/${t.instrument.id}/take`,children:e.jsx(o,{children:"Take again"})})]})}),e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,0.9fr)_minmax(18rem,1.1fr)]",children:[e.jsxs(c,{className:"bg-[linear-gradient(180deg,rgba(16,24,34,0.98),rgba(10,15,24,0.96))]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/42",children:"Stored scores"}),t.scores.length===0?e.jsx("div",{className:"mt-4",children:e.jsx(b,{eyebrow:"Scores",title:"No scores stored yet",description:"This run has not been completed, so there are no persisted score rows yet."})}):e.jsx("div",{className:"mt-4 grid gap-3",children:t.scores.map(r=>e.jsx("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.03] px-4 py-4",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-white",children:r.label}),r.bandLabel?e.jsx("div",{className:"mt-2 text-xs uppercase tracking-[0.16em] text-[rgba(110,231,183,0.74)]",children:r.bandLabel}):null]}),e.jsx("div",{className:"text-right text-lg font-semibold text-white",children:r.valueText??r.valueNumeric??"—"})]})},r.scoreKey))})]}),e.jsxs(c,{className:"bg-[linear-gradient(180deg,rgba(15,23,33,0.98),rgba(9,15,23,0.96))]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/42",children:"Answer ledger"}),e.jsx("div",{className:"mt-4 grid gap-3",children:t.version.definition.items.map(r=>{const i=l.get(r.id);return e.jsxs("div",{className:"rounded-[20px] border border-white/8 bg-white/[0.03] px-4 py-4",children:[e.jsx("div",{className:"text-sm font-medium leading-6 text-white",children:r.prompt}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:r.options.map(n=>{const m=(i==null?void 0:i.optionKey)===n.key;return e.jsx(j,{className:m?"bg-[rgba(110,231,183,0.16)] text-[rgba(187,247,208,0.94)]":"bg-white/[0.05] text-white/54",children:n.label},`${r.id}-${n.key}`)})})]},r.id)})})]})]})]})}export{B as PsycheQuestionnaireRunDetailPage};
1
+ import{cc as x,j as e,aC as d}from"./vendor-DHkYh85p.js";import{i as u}from"./state-B-4sS1xO.js";import{P as p}from"./page-hero-DRy5b2MU.js";import{L as g,E as h,B as o,C as c,a as b,c as j,cL as y}from"./index-CF4J4R9L.js";import"./board-BkDRaMp6.js";import"./ui-C13Nbgas.js";import"./motion-BeD44FeG.js";import"./forms-BFlTgZ3W.js";import"./graph-D6JLqDbD.js";function B(){const{runId:a=""}=x(),s=u({queryKey:["forge-psyche-questionnaire-run",a],queryFn:()=>y(a),enabled:a.length>0});if(s.isLoading)return e.jsx(g,{eyebrow:"Questionnaire result",title:"Loading scored run",description:"Hydrating the recorded answers, stored scores, and longitudinal context."});if(s.isError||!s.data)return e.jsx(h,{eyebrow:"Questionnaire result",error:s.error,onRetry:()=>void s.refetch()});const t=s.data,l=new Map(t.answers.map(r=>[r.itemId,r]));return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(p,{eyebrow:"Questionnaire result",title:t.instrument.title,description:"Stored raw answers, computed scores, and score history all remain attached to the exact version used for this run.",badge:t.run.completedAt?"Completed":"Draft",actions:e.jsxs(e.Fragment,{children:[e.jsx(d,{to:`/psyche/questionnaires/${t.instrument.id}`,children:e.jsx(o,{variant:"secondary",children:"Back to questionnaire"})}),e.jsx(d,{to:`/psyche/questionnaires/${t.instrument.id}/take`,children:e.jsx(o,{children:"Take again"})})]})}),e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,0.9fr)_minmax(18rem,1.1fr)]",children:[e.jsxs(c,{className:"bg-[linear-gradient(180deg,rgba(16,24,34,0.98),rgba(10,15,24,0.96))]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/42",children:"Stored scores"}),t.scores.length===0?e.jsx("div",{className:"mt-4",children:e.jsx(b,{eyebrow:"Scores",title:"No scores stored yet",description:"This run has not been completed, so there are no persisted score rows yet."})}):e.jsx("div",{className:"mt-4 grid gap-3",children:t.scores.map(r=>e.jsx("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.03] px-4 py-4",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-white",children:r.label}),r.bandLabel?e.jsx("div",{className:"mt-2 text-xs uppercase tracking-[0.16em] text-[rgba(110,231,183,0.74)]",children:r.bandLabel}):null]}),e.jsx("div",{className:"text-right text-lg font-semibold text-white",children:r.valueText??r.valueNumeric??"—"})]})},r.scoreKey))})]}),e.jsxs(c,{className:"bg-[linear-gradient(180deg,rgba(15,23,33,0.98),rgba(9,15,23,0.96))]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/42",children:"Answer ledger"}),e.jsx("div",{className:"mt-4 grid gap-3",children:t.version.definition.items.map(r=>{const i=l.get(r.id);return e.jsxs("div",{className:"rounded-[20px] border border-white/8 bg-white/[0.03] px-4 py-4",children:[e.jsx("div",{className:"text-sm font-medium leading-6 text-white",children:r.prompt}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:r.options.map(n=>{const m=(i==null?void 0:i.optionKey)===n.key;return e.jsx(j,{className:m?"bg-[rgba(110,231,183,0.16)] text-[rgba(187,247,208,0.94)]":"bg-white/[0.05] text-white/54",children:n.label},`${r.id}-${n.key}`)})})]},r.id)})})]})]})]})}export{B as PsycheQuestionnaireRunDetailPage};
@@ -1 +1 @@
1
- import{cc as O,b5 as Q,r as S,j as s,aC as U,b7 as T,d6 as Z,bk as K,b8 as q}from"./vendor-DHkYh85p.js";import{k as $}from"./state-B-4sS1xO.js";import{P as H}from"./page-hero-CQWo1Mm_.js";import{c_ as G,c$ as J,d0 as W,L as X,E as Y,B as j,C as D,Z as z,c as ee}from"./index-BHTUu_4M.js";import"./board-BkDRaMp6.js";import"./ui-C13Nbgas.js";import"./motion-BeD44FeG.js";import"./forms-BFlTgZ3W.js";import"./graph-D6JLqDbD.js";const B=new Map;function k(t){return new Error(t)}function te(t){const i=[];let e=0;for(;e<t.length;){const l=t[e];if(/\s/.test(l)){e+=1;continue}const r=t.slice(e,e+2);if(r==="=="||r==="!="||r===">="||r==="<="||r==="&&"||r==="||"){i.push({type:r}),e+=2;continue}if("(),><+-*/!".includes(l)){i.push({type:l}),e+=1;continue}if(l==="'"||l==='"'){const d=l;e+=1;let u="";for(;e<t.length&&t[e]!==d;){const n=t[e];if(n==="\\"&&e+1<t.length){u+=t[e+1],e+=2;continue}u+=n,e+=1}if(t[e]!==d)throw k(`Unterminated string in flow rule: ${t}`);e+=1,i.push({type:"string",value:u});continue}if(/\d/.test(l)){let d=l;for(e+=1;e<t.length&&/[\d.]/.test(t[e]);)d+=t[e],e+=1;i.push({type:"number",value:Number(d)});continue}if(/[A-Za-z_]/.test(l)){let d=l;for(e+=1;e<t.length&&/[A-Za-z0-9_]/.test(t[e]);)d+=t[e],e+=1;const u=d.toLowerCase();u==="and"?i.push({type:"&&"}):u==="or"?i.push({type:"||"}):u==="not"?i.push({type:"!"}):u==="true"?i.push({type:"boolean",value:!0}):u==="false"?i.push({type:"boolean",value:!1}):u==="null"?i.push({type:"null"}):i.push({type:"identifier",value:d});continue}throw k(`Unexpected token '${l}' in flow rule: ${t}`)}return i}function ne(t,i){let e=0;function l(){return t[e]}function r(a){const o=t[e];return!o||a&&o.type!==a?null:(e+=1,o)}function d(a){const o=r(a);if(!o)throw k(`Expected '${a}' in flow rule: ${i}`);return o}function u(){const a=l();if(!a)throw k(`Unexpected end of flow rule: ${i}`);if(r("(")){const o=b();return d(")"),o}if(a.type==="number")return r("number"),{kind:"literal",value:a.value};if(a.type==="string")return r("string"),{kind:"literal",value:a.value};if(a.type==="boolean")return r("boolean"),{kind:"literal",value:a.value};if(a.type==="null")return r("null"),{kind:"literal",value:null};if(a.type==="identifier"){const o=r("identifier").value;if(r("(")){const m=[];if(!r(")")){do m.push(b());while(r(","));d(")")}if(o!=="answered"&&o!=="option"&&o!=="label"&&o!=="value")throw k(`Unknown flow function '${o}' in rule: ${i}`);return{kind:"call",name:o,args:m}}return{kind:"reference",itemId:o}}throw k(`Unexpected token '${a.type}' in flow rule: ${i}`)}function n(){return r("!")?{kind:"unary",operator:"!",operand:n()}:r("-")?{kind:"unary",operator:"-",operand:n()}:u()}function g(){let a=n();for(;;){if(r("*")){a={kind:"binary",operator:"*",left:a,right:n()};continue}if(r("/")){a={kind:"binary",operator:"/",left:a,right:n()};continue}return a}}function w(){let a=g();for(;;){if(r("+")){a={kind:"binary",operator:"+",left:a,right:g()};continue}if(r("-")){a={kind:"binary",operator:"-",left:a,right:g()};continue}return a}}function x(){let a=w();for(;;){const o=l(),m=o&&(o.type==="=="||o.type==="!="||o.type===">="||o.type==="<="||o.type===">"||o.type==="<")?o.type:null;if(!m)return a;e+=1,a={kind:"binary",operator:m,left:a,right:w()}}}function p(){let a=x();for(;r("&&");)a={kind:"binary",operator:"&&",left:a,right:x()};return a}function b(){let a=p();for(;r("||");)a={kind:"binary",operator:"||",left:a,right:p()};return a}const N=b();if(e<t.length)throw k(`Unexpected trailing tokens in flow rule: ${i}`);return N}function ie(t){const i=B.get(t);if(i)return i;const e=ne(te(t),t);return B.set(t,e),e}function re(t){return t.kind==="reference"?t.itemId:t.kind==="literal"&&typeof t.value=="string"&&t.value.trim().length>0?t.value.trim():null}function M(t){return typeof t=="boolean"?t:typeof t=="number"?t!==0:typeof t=="string"?t.length>0:!1}function h(t){if(typeof t=="number"&&Number.isFinite(t))return t;if(typeof t=="boolean")return t?1:0;if(typeof t=="string"){const i=Number(t);return Number.isFinite(i)?i:null}return null}function se(t,i,e){const l=h(t),r=h(e);if(l!==null&&r!==null)switch(i){case"==":return l===r;case"!=":return l!==r;case">":return l>r;case">=":return l>=r;case"<":return l<r;case"<=":return l<=r}return i==="=="||i==="!="?i==="=="?t===e:t!==e:!1}function P(t,i){switch(t.kind){case"literal":return t.value;case"reference":return i.getAnswerValue(t.itemId);case"unary":{const e=P(t.operand,i);if(t.operator==="!")return!M(e);const l=h(e);return l===null?null:-l}case"binary":{const e=P(t.left,i),l=P(t.right,i);switch(t.operator){case"&&":return M(e)&&M(l);case"||":return M(e)||M(l);case"+":return e===null||l===null?null:(h(e)??0)+(h(l)??0);case"-":return e===null||l===null?null:(h(e)??0)-(h(l)??0);case"*":return e===null||l===null?null:(h(e)??0)*(h(l)??0);case"/":{const r=h(l);return e===null||r===null||r===0?null:(h(e)??0)/r}default:return se(e,t.operator,l)}}case"call":{const e=t.args[0]?re(t.args[0]):null;if(!e)return null;switch(t.name){case"answered":return i.isAnswered(e);case"option":return i.getOptionKey(e);case"label":return i.getLabel(e);case"value":return i.getAnswerValue(e)}}}}function le(t){return new Map(t.map(i=>[i.itemId,{optionKey:i.optionKey??null,numericValue:i.numericValue??null,valueText:i.valueText??null}]))}function F(t,i,e){const l=ie(t),r=le(i),d=P(l,{getAnswerValue:u=>{if(!e.has(u))return null;const n=r.get(u);return(n==null?void 0:n.numericValue)??(n==null?void 0:n.optionKey)??(n==null?void 0:n.valueText)??null},getOptionKey:u=>{var n;return e.has(u)?((n=r.get(u))==null?void 0:n.optionKey)??null:null},getLabel:u=>{var n;return e.has(u)?((n=r.get(u))==null?void 0:n.valueText)??null:null},isAnswered:u=>{if(!e.has(u))return!1;const n=r.get(u);return!!(n&&(n.optionKey!==null||n.numericValue!==null||(n.valueText??"").trim().length>0))}});return M(d)}function ae(t,i){const e=new Set,l=new Set,r=new Map(t.items.map(u=>[u.id,u])),d=new Map;for(const u of t.sections){if(!(!u.visibility||F(u.visibility.script,i,e)))continue;const g=u.itemIds.filter(w=>{const x=r.get(w);if(!x)return!1;const p=!x.visibility||F(x.visibility.script,i,e);return p&&e.add(x.id),p});g.length>0&&(l.add(u.id),d.set(u.id,g))}return{visibleItemIds:e,visibleSectionIds:l,visibleItemIdsBySection:d}}function oe(t,i){const e=t.options.find(l=>l.key===i);return e?{itemId:t.id,optionKey:e.key,valueText:e.label,numericValue:e.value,answer:{label:e.label,value:e.value}}:null}function be(){const{instrumentId:t=""}=O(),i=Q(),[e,l]=S.useState(null),r=$({mutationFn:()=>G(t,{userId:"user_operator"}),onSuccess:c=>l(c)}),d=$({mutationFn:c=>J(e.run.id,c),onSuccess:c=>l(c)}),u=$({mutationFn:()=>W(e.run.id),onSuccess:c=>{l(c),i(`/psyche/questionnaire-runs/${c.run.id}`)}});S.useEffect(()=>{t&&r.mutate()},[t]);const n=e,g=S.useMemo(()=>new Map(((n==null?void 0:n.answers)??[]).map(c=>[c.itemId,c.optionKey??""])),[n]),w=(n==null?void 0:n.version.definition.sections)??[],x=(n==null?void 0:n.version.definition.items)??[],p=S.useMemo(()=>n?ae(n.version.definition,n.answers):{visibleItemIds:new Set,visibleSectionIds:new Set,visibleItemIdsBySection:new Map},[n]),b=S.useMemo(()=>x.filter(c=>p.visibleItemIds.has(c.id)),[x,p]),N=S.useMemo(()=>w.filter(c=>p.visibleSectionIds.has(c.id)).map(c=>({...c,itemIds:p.visibleItemIdsBySection.get(c.id)??[]})),[w,p]),a=(n==null?void 0:n.version.definition.presentationMode)==="single_question"?b.length:N.length,o=a>0?Math.min((n==null?void 0:n.run.progressIndex)??0,a-1):0,m=N[o]??null,I=(n==null?void 0:n.version.definition.presentationMode)==="single_question"?b[o]??null:null,V=b.every(c=>!c.required||g.has(c.id)),C=async c=>{n&&(l(f=>f&&{...f,run:{...f.run,progressIndex:c}}),await d.mutateAsync({answers:[],progressIndex:c}))},E=async(c,f,y)=>{const v=oe(c,f);!v||!n||(l(A=>{if(!A)return A;const L=A.answers.filter(_=>_.itemId!==c.id);return{...A,run:{...A.run,progressIndex:y},answers:[...L,{...v,optionKey:v.optionKey??null,numericValue:v.numericValue??null,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}]}}),await d.mutateAsync({answers:[v],progressIndex:y}))};if(r.isPending||!n)return s.jsx(X,{eyebrow:"Questionnaire run",title:"Preparing guided run",description:"Opening the current questionnaire version, loading any draft answers, and restoring your place."});if(r.isError)return s.jsx(Y,{eyebrow:"Questionnaire run",error:r.error,onRetry:()=>r.mutate()});const R=a>0?(o+1)/a*100:0;return s.jsxs("div",{className:"grid gap-5",children:[s.jsx(H,{eyebrow:"Guided questionnaire",title:n.instrument.title,description:n.version.definition.instructions,badge:`v${n.version.versionNumber}`,actions:s.jsx(U,{to:`/psyche/questionnaires/${n.instrument.id}`,children:s.jsx(j,{variant:"secondary",children:"Back to detail"})})}),s.jsxs(D,{className:"overflow-hidden bg-[linear-gradient(180deg,rgba(15,23,34,0.98),rgba(8,13,20,0.98))] p-0",children:[s.jsxs("div",{className:"border-b border-white/8 px-5 py-4",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[s.jsxs("div",{children:[s.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/42",children:"Progress"}),s.jsxs("div",{className:"mt-2 text-sm text-white/72",children:["Step ",o+1," of ",a]})]}),s.jsx("div",{className:"flex items-center gap-2 text-sm text-white/56",children:d.isPending?s.jsxs(s.Fragment,{children:[s.jsx(T,{className:"size-4 animate-spin"}),"Autosaving"]}):s.jsxs(s.Fragment,{children:[s.jsx(Z,{className:"size-4 text-[var(--tertiary)]"}),"Saved"]})})]}),s.jsx("div",{className:"mt-3 h-1.5 rounded-full bg-white/[0.06]",children:s.jsx("div",{className:"h-full rounded-full bg-[linear-gradient(90deg,rgba(110,231,183,0.92),rgba(125,211,252,0.86))] transition-[width] duration-300",style:{width:`${R}%`}})})]}),n.version.definition.presentationMode==="single_question"&&I?s.jsx("div",{className:"px-5 py-6 sm:px-6",children:s.jsxs("div",{className:"mx-auto max-w-3xl",children:[s.jsx("div",{className:"font-display text-[clamp(1.7rem,3vw,2.4rem)] leading-tight text-white",children:I.prompt}),s.jsx("div",{className:"mt-6 grid gap-3",children:I.options.map(c=>{const f=g.get(I.id)===c.key;return s.jsx("button",{type:"button",className:z("rounded-[24px] border px-5 py-5 text-left transition",f?"border-[rgba(110,231,183,0.35)] bg-[rgba(110,231,183,0.14)] text-white":"border-white/8 bg-white/[0.03] text-white/74 hover:bg-white/[0.06]"),onClick:()=>void E(I,c.key,o),children:s.jsx("div",{className:"text-base font-medium",children:c.label})},c.key)})}),s.jsxs("div",{className:"mt-6 flex flex-wrap items-center justify-between gap-3",children:[s.jsxs(j,{variant:"secondary",disabled:o===0,onClick:()=>void C(Math.max(0,o-1)),children:[s.jsx(K,{className:"mr-2 size-4"}),"Previous"]}),o<b.length-1?s.jsxs(j,{onClick:()=>void C(Math.min(b.length-1,o+1)),children:["Next",s.jsx(q,{className:"ml-2 size-4"})]}):s.jsx(j,{disabled:!V||u.isPending,onClick:()=>u.mutate(),children:"Finish and score"})]})]})}):m?s.jsx("div",{className:"px-5 py-6 sm:px-6",children:s.jsxs("div",{className:"mx-auto max-w-5xl",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[s.jsxs("div",{children:[s.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[rgba(110,231,183,0.72)]",children:m.title}),m.description?s.jsx("div",{className:"mt-2 text-sm text-white/56",children:m.description}):null]}),s.jsxs(ee,{className:"bg-white/[0.08] text-white/78",children:[m.itemIds.length," items"]})]}),s.jsx("div",{className:"mt-6 grid gap-4",children:m.itemIds.map(c=>{const f=b.find(y=>y.id===c);return f?s.jsxs("div",{className:"rounded-[24px] border border-white/8 bg-white/[0.03] px-4 py-4",children:[s.jsx("div",{className:"text-sm leading-6 text-white",children:f.prompt}),s.jsx("div",{className:"mt-4 grid gap-2 md:grid-cols-3 xl:grid-cols-6",children:f.options.map(y=>{const v=g.get(f.id)===y.key;return s.jsx("button",{type:"button",className:z("rounded-[18px] border px-3 py-3 text-sm transition",v?"border-[rgba(110,231,183,0.35)] bg-[rgba(110,231,183,0.14)] text-white":"border-white/8 bg-white/[0.03] text-white/66 hover:bg-white/[0.06]"),onClick:()=>void E(f,y.key,o),children:y.label},y.key)})})]},f.id):null})}),s.jsxs("div",{className:"mt-6 flex flex-wrap items-center justify-between gap-3",children:[s.jsxs(j,{variant:"secondary",disabled:o===0,onClick:()=>void C(Math.max(0,o-1)),children:[s.jsx(K,{className:"mr-2 size-4"}),"Previous section"]}),o<N.length-1?s.jsxs(j,{onClick:()=>void C(Math.min(N.length-1,o+1)),children:["Next section",s.jsx(q,{className:"ml-2 size-4"})]}):s.jsx(j,{disabled:!V||u.isPending,onClick:()=>u.mutate(),children:"Finish and score"})]})]})}):null]})]})}export{be as PsycheQuestionnaireRunPage};
1
+ import{cc as O,b5 as Q,r as S,j as s,aC as U,b7 as T,d6 as Z,bk as K,b8 as q}from"./vendor-DHkYh85p.js";import{k as $}from"./state-B-4sS1xO.js";import{P as H}from"./page-hero-DRy5b2MU.js";import{c_ as G,c$ as J,d0 as W,L as X,E as Y,B as j,C as D,Z as z,c as ee}from"./index-CF4J4R9L.js";import"./board-BkDRaMp6.js";import"./ui-C13Nbgas.js";import"./motion-BeD44FeG.js";import"./forms-BFlTgZ3W.js";import"./graph-D6JLqDbD.js";const B=new Map;function k(t){return new Error(t)}function te(t){const i=[];let e=0;for(;e<t.length;){const l=t[e];if(/\s/.test(l)){e+=1;continue}const r=t.slice(e,e+2);if(r==="=="||r==="!="||r===">="||r==="<="||r==="&&"||r==="||"){i.push({type:r}),e+=2;continue}if("(),><+-*/!".includes(l)){i.push({type:l}),e+=1;continue}if(l==="'"||l==='"'){const d=l;e+=1;let u="";for(;e<t.length&&t[e]!==d;){const n=t[e];if(n==="\\"&&e+1<t.length){u+=t[e+1],e+=2;continue}u+=n,e+=1}if(t[e]!==d)throw k(`Unterminated string in flow rule: ${t}`);e+=1,i.push({type:"string",value:u});continue}if(/\d/.test(l)){let d=l;for(e+=1;e<t.length&&/[\d.]/.test(t[e]);)d+=t[e],e+=1;i.push({type:"number",value:Number(d)});continue}if(/[A-Za-z_]/.test(l)){let d=l;for(e+=1;e<t.length&&/[A-Za-z0-9_]/.test(t[e]);)d+=t[e],e+=1;const u=d.toLowerCase();u==="and"?i.push({type:"&&"}):u==="or"?i.push({type:"||"}):u==="not"?i.push({type:"!"}):u==="true"?i.push({type:"boolean",value:!0}):u==="false"?i.push({type:"boolean",value:!1}):u==="null"?i.push({type:"null"}):i.push({type:"identifier",value:d});continue}throw k(`Unexpected token '${l}' in flow rule: ${t}`)}return i}function ne(t,i){let e=0;function l(){return t[e]}function r(a){const o=t[e];return!o||a&&o.type!==a?null:(e+=1,o)}function d(a){const o=r(a);if(!o)throw k(`Expected '${a}' in flow rule: ${i}`);return o}function u(){const a=l();if(!a)throw k(`Unexpected end of flow rule: ${i}`);if(r("(")){const o=b();return d(")"),o}if(a.type==="number")return r("number"),{kind:"literal",value:a.value};if(a.type==="string")return r("string"),{kind:"literal",value:a.value};if(a.type==="boolean")return r("boolean"),{kind:"literal",value:a.value};if(a.type==="null")return r("null"),{kind:"literal",value:null};if(a.type==="identifier"){const o=r("identifier").value;if(r("(")){const m=[];if(!r(")")){do m.push(b());while(r(","));d(")")}if(o!=="answered"&&o!=="option"&&o!=="label"&&o!=="value")throw k(`Unknown flow function '${o}' in rule: ${i}`);return{kind:"call",name:o,args:m}}return{kind:"reference",itemId:o}}throw k(`Unexpected token '${a.type}' in flow rule: ${i}`)}function n(){return r("!")?{kind:"unary",operator:"!",operand:n()}:r("-")?{kind:"unary",operator:"-",operand:n()}:u()}function g(){let a=n();for(;;){if(r("*")){a={kind:"binary",operator:"*",left:a,right:n()};continue}if(r("/")){a={kind:"binary",operator:"/",left:a,right:n()};continue}return a}}function w(){let a=g();for(;;){if(r("+")){a={kind:"binary",operator:"+",left:a,right:g()};continue}if(r("-")){a={kind:"binary",operator:"-",left:a,right:g()};continue}return a}}function x(){let a=w();for(;;){const o=l(),m=o&&(o.type==="=="||o.type==="!="||o.type===">="||o.type==="<="||o.type===">"||o.type==="<")?o.type:null;if(!m)return a;e+=1,a={kind:"binary",operator:m,left:a,right:w()}}}function p(){let a=x();for(;r("&&");)a={kind:"binary",operator:"&&",left:a,right:x()};return a}function b(){let a=p();for(;r("||");)a={kind:"binary",operator:"||",left:a,right:p()};return a}const N=b();if(e<t.length)throw k(`Unexpected trailing tokens in flow rule: ${i}`);return N}function ie(t){const i=B.get(t);if(i)return i;const e=ne(te(t),t);return B.set(t,e),e}function re(t){return t.kind==="reference"?t.itemId:t.kind==="literal"&&typeof t.value=="string"&&t.value.trim().length>0?t.value.trim():null}function M(t){return typeof t=="boolean"?t:typeof t=="number"?t!==0:typeof t=="string"?t.length>0:!1}function h(t){if(typeof t=="number"&&Number.isFinite(t))return t;if(typeof t=="boolean")return t?1:0;if(typeof t=="string"){const i=Number(t);return Number.isFinite(i)?i:null}return null}function se(t,i,e){const l=h(t),r=h(e);if(l!==null&&r!==null)switch(i){case"==":return l===r;case"!=":return l!==r;case">":return l>r;case">=":return l>=r;case"<":return l<r;case"<=":return l<=r}return i==="=="||i==="!="?i==="=="?t===e:t!==e:!1}function P(t,i){switch(t.kind){case"literal":return t.value;case"reference":return i.getAnswerValue(t.itemId);case"unary":{const e=P(t.operand,i);if(t.operator==="!")return!M(e);const l=h(e);return l===null?null:-l}case"binary":{const e=P(t.left,i),l=P(t.right,i);switch(t.operator){case"&&":return M(e)&&M(l);case"||":return M(e)||M(l);case"+":return e===null||l===null?null:(h(e)??0)+(h(l)??0);case"-":return e===null||l===null?null:(h(e)??0)-(h(l)??0);case"*":return e===null||l===null?null:(h(e)??0)*(h(l)??0);case"/":{const r=h(l);return e===null||r===null||r===0?null:(h(e)??0)/r}default:return se(e,t.operator,l)}}case"call":{const e=t.args[0]?re(t.args[0]):null;if(!e)return null;switch(t.name){case"answered":return i.isAnswered(e);case"option":return i.getOptionKey(e);case"label":return i.getLabel(e);case"value":return i.getAnswerValue(e)}}}}function le(t){return new Map(t.map(i=>[i.itemId,{optionKey:i.optionKey??null,numericValue:i.numericValue??null,valueText:i.valueText??null}]))}function F(t,i,e){const l=ie(t),r=le(i),d=P(l,{getAnswerValue:u=>{if(!e.has(u))return null;const n=r.get(u);return(n==null?void 0:n.numericValue)??(n==null?void 0:n.optionKey)??(n==null?void 0:n.valueText)??null},getOptionKey:u=>{var n;return e.has(u)?((n=r.get(u))==null?void 0:n.optionKey)??null:null},getLabel:u=>{var n;return e.has(u)?((n=r.get(u))==null?void 0:n.valueText)??null:null},isAnswered:u=>{if(!e.has(u))return!1;const n=r.get(u);return!!(n&&(n.optionKey!==null||n.numericValue!==null||(n.valueText??"").trim().length>0))}});return M(d)}function ae(t,i){const e=new Set,l=new Set,r=new Map(t.items.map(u=>[u.id,u])),d=new Map;for(const u of t.sections){if(!(!u.visibility||F(u.visibility.script,i,e)))continue;const g=u.itemIds.filter(w=>{const x=r.get(w);if(!x)return!1;const p=!x.visibility||F(x.visibility.script,i,e);return p&&e.add(x.id),p});g.length>0&&(l.add(u.id),d.set(u.id,g))}return{visibleItemIds:e,visibleSectionIds:l,visibleItemIdsBySection:d}}function oe(t,i){const e=t.options.find(l=>l.key===i);return e?{itemId:t.id,optionKey:e.key,valueText:e.label,numericValue:e.value,answer:{label:e.label,value:e.value}}:null}function be(){const{instrumentId:t=""}=O(),i=Q(),[e,l]=S.useState(null),r=$({mutationFn:()=>G(t,{userId:"user_operator"}),onSuccess:c=>l(c)}),d=$({mutationFn:c=>J(e.run.id,c),onSuccess:c=>l(c)}),u=$({mutationFn:()=>W(e.run.id),onSuccess:c=>{l(c),i(`/psyche/questionnaire-runs/${c.run.id}`)}});S.useEffect(()=>{t&&r.mutate()},[t]);const n=e,g=S.useMemo(()=>new Map(((n==null?void 0:n.answers)??[]).map(c=>[c.itemId,c.optionKey??""])),[n]),w=(n==null?void 0:n.version.definition.sections)??[],x=(n==null?void 0:n.version.definition.items)??[],p=S.useMemo(()=>n?ae(n.version.definition,n.answers):{visibleItemIds:new Set,visibleSectionIds:new Set,visibleItemIdsBySection:new Map},[n]),b=S.useMemo(()=>x.filter(c=>p.visibleItemIds.has(c.id)),[x,p]),N=S.useMemo(()=>w.filter(c=>p.visibleSectionIds.has(c.id)).map(c=>({...c,itemIds:p.visibleItemIdsBySection.get(c.id)??[]})),[w,p]),a=(n==null?void 0:n.version.definition.presentationMode)==="single_question"?b.length:N.length,o=a>0?Math.min((n==null?void 0:n.run.progressIndex)??0,a-1):0,m=N[o]??null,I=(n==null?void 0:n.version.definition.presentationMode)==="single_question"?b[o]??null:null,V=b.every(c=>!c.required||g.has(c.id)),C=async c=>{n&&(l(f=>f&&{...f,run:{...f.run,progressIndex:c}}),await d.mutateAsync({answers:[],progressIndex:c}))},E=async(c,f,y)=>{const v=oe(c,f);!v||!n||(l(A=>{if(!A)return A;const L=A.answers.filter(_=>_.itemId!==c.id);return{...A,run:{...A.run,progressIndex:y},answers:[...L,{...v,optionKey:v.optionKey??null,numericValue:v.numericValue??null,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}]}}),await d.mutateAsync({answers:[v],progressIndex:y}))};if(r.isPending||!n)return s.jsx(X,{eyebrow:"Questionnaire run",title:"Preparing guided run",description:"Opening the current questionnaire version, loading any draft answers, and restoring your place."});if(r.isError)return s.jsx(Y,{eyebrow:"Questionnaire run",error:r.error,onRetry:()=>r.mutate()});const R=a>0?(o+1)/a*100:0;return s.jsxs("div",{className:"grid gap-5",children:[s.jsx(H,{eyebrow:"Guided questionnaire",title:n.instrument.title,description:n.version.definition.instructions,badge:`v${n.version.versionNumber}`,actions:s.jsx(U,{to:`/psyche/questionnaires/${n.instrument.id}`,children:s.jsx(j,{variant:"secondary",children:"Back to detail"})})}),s.jsxs(D,{className:"overflow-hidden bg-[linear-gradient(180deg,rgba(15,23,34,0.98),rgba(8,13,20,0.98))] p-0",children:[s.jsxs("div",{className:"border-b border-white/8 px-5 py-4",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[s.jsxs("div",{children:[s.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/42",children:"Progress"}),s.jsxs("div",{className:"mt-2 text-sm text-white/72",children:["Step ",o+1," of ",a]})]}),s.jsx("div",{className:"flex items-center gap-2 text-sm text-white/56",children:d.isPending?s.jsxs(s.Fragment,{children:[s.jsx(T,{className:"size-4 animate-spin"}),"Autosaving"]}):s.jsxs(s.Fragment,{children:[s.jsx(Z,{className:"size-4 text-[var(--tertiary)]"}),"Saved"]})})]}),s.jsx("div",{className:"mt-3 h-1.5 rounded-full bg-white/[0.06]",children:s.jsx("div",{className:"h-full rounded-full bg-[linear-gradient(90deg,rgba(110,231,183,0.92),rgba(125,211,252,0.86))] transition-[width] duration-300",style:{width:`${R}%`}})})]}),n.version.definition.presentationMode==="single_question"&&I?s.jsx("div",{className:"px-5 py-6 sm:px-6",children:s.jsxs("div",{className:"mx-auto max-w-3xl",children:[s.jsx("div",{className:"font-display text-[clamp(1.7rem,3vw,2.4rem)] leading-tight text-white",children:I.prompt}),s.jsx("div",{className:"mt-6 grid gap-3",children:I.options.map(c=>{const f=g.get(I.id)===c.key;return s.jsx("button",{type:"button",className:z("rounded-[24px] border px-5 py-5 text-left transition",f?"border-[rgba(110,231,183,0.35)] bg-[rgba(110,231,183,0.14)] text-white":"border-white/8 bg-white/[0.03] text-white/74 hover:bg-white/[0.06]"),onClick:()=>void E(I,c.key,o),children:s.jsx("div",{className:"text-base font-medium",children:c.label})},c.key)})}),s.jsxs("div",{className:"mt-6 flex flex-wrap items-center justify-between gap-3",children:[s.jsxs(j,{variant:"secondary",disabled:o===0,onClick:()=>void C(Math.max(0,o-1)),children:[s.jsx(K,{className:"mr-2 size-4"}),"Previous"]}),o<b.length-1?s.jsxs(j,{onClick:()=>void C(Math.min(b.length-1,o+1)),children:["Next",s.jsx(q,{className:"ml-2 size-4"})]}):s.jsx(j,{disabled:!V||u.isPending,onClick:()=>u.mutate(),children:"Finish and score"})]})]})}):m?s.jsx("div",{className:"px-5 py-6 sm:px-6",children:s.jsxs("div",{className:"mx-auto max-w-5xl",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[s.jsxs("div",{children:[s.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[rgba(110,231,183,0.72)]",children:m.title}),m.description?s.jsx("div",{className:"mt-2 text-sm text-white/56",children:m.description}):null]}),s.jsxs(ee,{className:"bg-white/[0.08] text-white/78",children:[m.itemIds.length," items"]})]}),s.jsx("div",{className:"mt-6 grid gap-4",children:m.itemIds.map(c=>{const f=b.find(y=>y.id===c);return f?s.jsxs("div",{className:"rounded-[24px] border border-white/8 bg-white/[0.03] px-4 py-4",children:[s.jsx("div",{className:"text-sm leading-6 text-white",children:f.prompt}),s.jsx("div",{className:"mt-4 grid gap-2 md:grid-cols-3 xl:grid-cols-6",children:f.options.map(y=>{const v=g.get(f.id)===y.key;return s.jsx("button",{type:"button",className:z("rounded-[18px] border px-3 py-3 text-sm transition",v?"border-[rgba(110,231,183,0.35)] bg-[rgba(110,231,183,0.14)] text-white":"border-white/8 bg-white/[0.03] text-white/66 hover:bg-white/[0.06]"),onClick:()=>void E(f,y.key,o),children:y.label},y.key)})})]},f.id):null})}),s.jsxs("div",{className:"mt-6 flex flex-wrap items-center justify-between gap-3",children:[s.jsxs(j,{variant:"secondary",disabled:o===0,onClick:()=>void C(Math.max(0,o-1)),children:[s.jsx(K,{className:"mr-2 size-4"}),"Previous section"]}),o<N.length-1?s.jsxs(j,{onClick:()=>void C(Math.min(N.length-1,o+1)),children:["Next section",s.jsx(q,{className:"ml-2 size-4"})]}):s.jsx(j,{disabled:!V||u.isPending,onClick:()=>u.mutate(),children:"Finish and score"})]})]})}):null]})]})}export{be as PsycheQuestionnaireRunPage};
@@ -1 +1 @@
1
- import{r as p,j as e,aC as m,d7 as f,bf as b}from"./vendor-DHkYh85p.js";import{i as w}from"./state-B-4sS1xO.js";import{F as j}from"./faceted-token-search-CE1YauRd.js";import{L as v,E as N,B as h,ck as S,a as C,C as y,c as d,Z as $,cn as q}from"./index-BHTUu_4M.js";import{P as Q}from"./page-hero-CQWo1Mm_.js";import"./board-BkDRaMp6.js";import"./ui-C13Nbgas.js";import"./motion-BeD44FeG.js";import"./forms-BFlTgZ3W.js";import"./graph-D6JLqDbD.js";function c(o,a){return`${o}: ${a}`}function A(o){const a=new Map;for(const t of o){const r=(s,n,u)=>{a.has(s)||a.set(s,{id:s,label:n,description:u})};for(const s of t.aliases)r(`alias:${s}`,c("Alias",s),"Filter by questionnaire alias.");for(const s of t.symptomDomains)r(`domain:${s}`,c("Domain",s),"Filter by symptom domain.");r(`source:${t.sourceClass}`,c("Source",t.sourceClass.replaceAll("_"," ")),"Filter by source and licence class."),r(`presentation:${t.presentationMode}`,c("Flow",t.presentationMode.replaceAll("_"," ")),"Filter by runner presentation mode."),r(`response:${t.responseStyle}`,c("Response",t.responseStyle.replaceAll("_"," ")),"Filter by response style."),r(`availability:${t.availability}`,c("Availability",t.availability.replaceAll("_"," ")),"Filter by availability."),r(`size:${t.itemCount>=50?"long":t.itemCount>=15?"medium":"short"}`,c("Length",t.itemCount>=50?"long":t.itemCount>=15?"medium":"short"),"Filter by approximate questionnaire length."),r(`self:${t.isSelfReport?"self_report":"other"}`,c("Type",t.isSelfReport?"self report":"other"),"Filter by self-report availability.")}return Array.from(a.values()).sort((t,r)=>t.label.localeCompare(r.label))}function F(o,a){return o.every(t=>{const[r,s]=t.split(":",2);if(!r||!s)return!0;switch(r){case"alias":return a.aliases.includes(s);case"domain":return a.symptomDomains.includes(s);case"source":return a.sourceClass===s;case"presentation":return a.presentationMode===s;case"response":return a.responseStyle===s;case"availability":return a.availability===s;case"size":return s==="long"?a.itemCount>=50:s==="medium"?a.itemCount>=15&&a.itemCount<50:a.itemCount<15;case"self":return s==="self_report"?a.isSelfReport:!a.isSelfReport;default:return!0}})}function H(){var g;const[o,a]=p.useState(""),[t,r]=p.useState([]),s=w({queryKey:["forge-psyche-questionnaires"],queryFn:()=>q()}),n=((g=s.data)==null?void 0:g.instruments)??[],u=p.useMemo(()=>A(n),[n]),x=p.useMemo(()=>{const i=o.trim().toLowerCase();return n.filter(l=>(i.length===0||`${l.title} ${l.subtitle} ${l.description} ${l.aliases.join(" ")} ${l.symptomDomains.join(" ")} ${l.tags.join(" ")}`.toLowerCase().includes(i))&&F(t,l))},[n,o,t]);return s.isLoading?e.jsx(v,{eyebrow:"Questionnaires",title:"Loading the questionnaire library",description:"Hydrating the seeded assessment catalog, versions, and latest run history."}):s.isError?e.jsx(N,{eyebrow:"Questionnaires",error:s.error,onRetry:()=>void s.refetch()}):e.jsxs("div",{className:"grid gap-5",children:[e.jsx(Q,{eyebrow:"Psyche",title:"Questionnaires",description:"Browse the seeded mental health questionnaire library, narrow it with facet chips, launch guided runs, and build your own versioned instruments.",badge:`${n.length} instruments`,actions:e.jsx(m,{to:"/psyche/questionnaires/new",children:e.jsx(h,{children:"Build questionnaire"})})}),e.jsx(S,{}),e.jsx(j,{title:"Questionnaire filters",description:"Search by title or alias, then pin chips for symptom domain, source class, item count, response style, flow mode, self-report status, or availability.",query:o,onQueryChange:a,options:u,selectedOptionIds:t,onSelectedOptionIdsChange:r,resultSummary:`${x.length} of ${n.length} questionnaires visible`}),x.length===0?e.jsx(C,{eyebrow:"Questionnaire library",title:"No questionnaires match the current filters",description:"Clear one or two chips and the seeded catalog will come back into view."}):e.jsx("section",{className:"grid gap-4 xl:grid-cols-2",children:x.map(i=>e.jsxs(y,{className:"overflow-hidden bg-[linear-gradient(180deg,rgba(16,24,34,0.97),rgba(10,16,24,0.95))]",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[rgba(110,231,183,0.74)]",children:i.subtitle||"Questionnaire"}),e.jsx("h2",{className:"mt-3 font-display text-[clamp(1.35rem,2vw,1.9rem)] leading-none text-white",children:i.title}),e.jsx("p",{className:"mt-3 text-sm leading-6 text-white/60",children:i.description})]}),e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.04] px-3 py-3 text-right",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"Latest"}),e.jsx("div",{className:"mt-2 text-sm text-white/78",children:i.latestRunAt?new Date(i.latestRunAt).toLocaleDateString():"Not taken yet"})]})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsxs(d,{className:"bg-white/[0.08] text-white/80",children:[i.itemCount," items"]}),e.jsx(d,{className:"bg-[rgba(110,231,183,0.12)] text-[rgba(187,247,208,0.9)]",children:i.presentationMode.replaceAll("_"," ")}),e.jsx(d,{className:"bg-[rgba(125,211,252,0.12)] text-sky-100/90",children:i.responseStyle.replaceAll("_"," ")}),e.jsx(d,{className:"bg-[rgba(192,193,255,0.12)] text-white/84",children:i.sourceClass.replaceAll("_"," ")})]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:i.symptomDomains.map(l=>e.jsx(d,{className:"bg-white/[0.05] text-white/66",children:l},`${i.id}-${l}`))}),e.jsxs("div",{className:"mt-5 grid gap-3 sm:grid-cols-[minmax(0,1fr)_auto_auto]",children:[e.jsx("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.03] px-4 py-3 text-sm text-white/60",children:i.completedRunCount>0?`${i.completedRunCount} completed runs saved in history`:"No saved history yet"}),e.jsx(m,{to:`/psyche/questionnaires/${i.id}`,children:e.jsx(h,{variant:"secondary",className:"w-full sm:w-auto",children:"Open detail"})}),e.jsx(m,{to:`/psyche/questionnaires/${i.id}/take`,children:e.jsx(h,{className:"w-full sm:w-auto",children:"Start guided run"})})]})]},i.id))}),e.jsxs("section",{className:"grid gap-4 lg:grid-cols-[minmax(0,1.05fr)_minmax(0,0.95fr)]",children:[e.jsxs(y,{className:"bg-[linear-gradient(180deg,rgba(15,22,34,0.98),rgba(9,14,22,0.96))]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(f,{className:"size-5 text-[var(--tertiary)]"}),e.jsx("div",{className:"font-display text-2xl text-white",children:"Seeded first wave"})]}),e.jsx("p",{className:"mt-3 text-sm leading-6 text-white/62",children:"The current library ships a verified first wave: PHQ-9, GAD-7, WHO-5, PCL-5, AUDIT, SRQ-20, and YSQ-R, each stored in SQLite as a versioned definition with scoring and provenance."})]}),e.jsxs(y,{className:"bg-[linear-gradient(180deg,rgba(18,26,36,0.98),rgba(11,17,26,0.96))]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(b,{className:"size-5 text-[var(--secondary)]"}),e.jsx("div",{className:"font-display text-2xl text-white",children:"Builder ready"})]}),e.jsx("p",{className:"mt-3 text-sm leading-6 text-white/62",children:"System questionnaires stay read-only. Custom drafts can branch from any seed, edit structure and scoring JSON safely, and publish new immutable versions without rewriting past runs."}),e.jsx("div",{className:"mt-4",children:e.jsx(m,{to:"/psyche/questionnaires/new",children:e.jsx(h,{variant:"secondary",className:$("w-full sm:w-auto"),children:"Open builder"})})})]})]})]})}export{H as PsycheQuestionnairesPage};
1
+ import{r as p,j as e,aC as m,d7 as f,bf as b}from"./vendor-DHkYh85p.js";import{i as w}from"./state-B-4sS1xO.js";import{F as j}from"./faceted-token-search-BxRRcM3q.js";import{L as v,E as N,B as h,ck as S,a as C,C as y,c as d,Z as $,cn as q}from"./index-CF4J4R9L.js";import{P as Q}from"./page-hero-DRy5b2MU.js";import"./board-BkDRaMp6.js";import"./ui-C13Nbgas.js";import"./motion-BeD44FeG.js";import"./forms-BFlTgZ3W.js";import"./graph-D6JLqDbD.js";function c(o,a){return`${o}: ${a}`}function A(o){const a=new Map;for(const t of o){const r=(s,n,u)=>{a.has(s)||a.set(s,{id:s,label:n,description:u})};for(const s of t.aliases)r(`alias:${s}`,c("Alias",s),"Filter by questionnaire alias.");for(const s of t.symptomDomains)r(`domain:${s}`,c("Domain",s),"Filter by symptom domain.");r(`source:${t.sourceClass}`,c("Source",t.sourceClass.replaceAll("_"," ")),"Filter by source and licence class."),r(`presentation:${t.presentationMode}`,c("Flow",t.presentationMode.replaceAll("_"," ")),"Filter by runner presentation mode."),r(`response:${t.responseStyle}`,c("Response",t.responseStyle.replaceAll("_"," ")),"Filter by response style."),r(`availability:${t.availability}`,c("Availability",t.availability.replaceAll("_"," ")),"Filter by availability."),r(`size:${t.itemCount>=50?"long":t.itemCount>=15?"medium":"short"}`,c("Length",t.itemCount>=50?"long":t.itemCount>=15?"medium":"short"),"Filter by approximate questionnaire length."),r(`self:${t.isSelfReport?"self_report":"other"}`,c("Type",t.isSelfReport?"self report":"other"),"Filter by self-report availability.")}return Array.from(a.values()).sort((t,r)=>t.label.localeCompare(r.label))}function F(o,a){return o.every(t=>{const[r,s]=t.split(":",2);if(!r||!s)return!0;switch(r){case"alias":return a.aliases.includes(s);case"domain":return a.symptomDomains.includes(s);case"source":return a.sourceClass===s;case"presentation":return a.presentationMode===s;case"response":return a.responseStyle===s;case"availability":return a.availability===s;case"size":return s==="long"?a.itemCount>=50:s==="medium"?a.itemCount>=15&&a.itemCount<50:a.itemCount<15;case"self":return s==="self_report"?a.isSelfReport:!a.isSelfReport;default:return!0}})}function H(){var g;const[o,a]=p.useState(""),[t,r]=p.useState([]),s=w({queryKey:["forge-psyche-questionnaires"],queryFn:()=>q()}),n=((g=s.data)==null?void 0:g.instruments)??[],u=p.useMemo(()=>A(n),[n]),x=p.useMemo(()=>{const i=o.trim().toLowerCase();return n.filter(l=>(i.length===0||`${l.title} ${l.subtitle} ${l.description} ${l.aliases.join(" ")} ${l.symptomDomains.join(" ")} ${l.tags.join(" ")}`.toLowerCase().includes(i))&&F(t,l))},[n,o,t]);return s.isLoading?e.jsx(v,{eyebrow:"Questionnaires",title:"Loading the questionnaire library",description:"Hydrating the seeded assessment catalog, versions, and latest run history."}):s.isError?e.jsx(N,{eyebrow:"Questionnaires",error:s.error,onRetry:()=>void s.refetch()}):e.jsxs("div",{className:"grid gap-5",children:[e.jsx(Q,{eyebrow:"Psyche",title:"Questionnaires",description:"Browse the seeded mental health questionnaire library, narrow it with facet chips, launch guided runs, and build your own versioned instruments.",badge:`${n.length} instruments`,actions:e.jsx(m,{to:"/psyche/questionnaires/new",children:e.jsx(h,{children:"Build questionnaire"})})}),e.jsx(S,{}),e.jsx(j,{title:"Questionnaire filters",description:"Search by title or alias, then pin chips for symptom domain, source class, item count, response style, flow mode, self-report status, or availability.",query:o,onQueryChange:a,options:u,selectedOptionIds:t,onSelectedOptionIdsChange:r,resultSummary:`${x.length} of ${n.length} questionnaires visible`}),x.length===0?e.jsx(C,{eyebrow:"Questionnaire library",title:"No questionnaires match the current filters",description:"Clear one or two chips and the seeded catalog will come back into view."}):e.jsx("section",{className:"grid gap-4 xl:grid-cols-2",children:x.map(i=>e.jsxs(y,{className:"overflow-hidden bg-[linear-gradient(180deg,rgba(16,24,34,0.97),rgba(10,16,24,0.95))]",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[rgba(110,231,183,0.74)]",children:i.subtitle||"Questionnaire"}),e.jsx("h2",{className:"mt-3 font-display text-[clamp(1.35rem,2vw,1.9rem)] leading-none text-white",children:i.title}),e.jsx("p",{className:"mt-3 text-sm leading-6 text-white/60",children:i.description})]}),e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.04] px-3 py-3 text-right",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"Latest"}),e.jsx("div",{className:"mt-2 text-sm text-white/78",children:i.latestRunAt?new Date(i.latestRunAt).toLocaleDateString():"Not taken yet"})]})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsxs(d,{className:"bg-white/[0.08] text-white/80",children:[i.itemCount," items"]}),e.jsx(d,{className:"bg-[rgba(110,231,183,0.12)] text-[rgba(187,247,208,0.9)]",children:i.presentationMode.replaceAll("_"," ")}),e.jsx(d,{className:"bg-[rgba(125,211,252,0.12)] text-sky-100/90",children:i.responseStyle.replaceAll("_"," ")}),e.jsx(d,{className:"bg-[rgba(192,193,255,0.12)] text-white/84",children:i.sourceClass.replaceAll("_"," ")})]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:i.symptomDomains.map(l=>e.jsx(d,{className:"bg-white/[0.05] text-white/66",children:l},`${i.id}-${l}`))}),e.jsxs("div",{className:"mt-5 grid gap-3 sm:grid-cols-[minmax(0,1fr)_auto_auto]",children:[e.jsx("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.03] px-4 py-3 text-sm text-white/60",children:i.completedRunCount>0?`${i.completedRunCount} completed runs saved in history`:"No saved history yet"}),e.jsx(m,{to:`/psyche/questionnaires/${i.id}`,children:e.jsx(h,{variant:"secondary",className:"w-full sm:w-auto",children:"Open detail"})}),e.jsx(m,{to:`/psyche/questionnaires/${i.id}/take`,children:e.jsx(h,{className:"w-full sm:w-auto",children:"Start guided run"})})]})]},i.id))}),e.jsxs("section",{className:"grid gap-4 lg:grid-cols-[minmax(0,1.05fr)_minmax(0,0.95fr)]",children:[e.jsxs(y,{className:"bg-[linear-gradient(180deg,rgba(15,22,34,0.98),rgba(9,14,22,0.96))]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(f,{className:"size-5 text-[var(--tertiary)]"}),e.jsx("div",{className:"font-display text-2xl text-white",children:"Seeded first wave"})]}),e.jsx("p",{className:"mt-3 text-sm leading-6 text-white/62",children:"The current library ships a verified first wave: PHQ-9, GAD-7, WHO-5, PCL-5, AUDIT, SRQ-20, and YSQ-R, each stored in SQLite as a versioned definition with scoring and provenance."})]}),e.jsxs(y,{className:"bg-[linear-gradient(180deg,rgba(18,26,36,0.98),rgba(11,17,26,0.96))]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(b,{className:"size-5 text-[var(--secondary)]"}),e.jsx("div",{className:"font-display text-2xl text-white",children:"Builder ready"})]}),e.jsx("p",{className:"mt-3 text-sm leading-6 text-white/62",children:"System questionnaires stay read-only. Custom drafts can branch from any seed, edit structure and scoring JSON safely, and publish new immutable versions without rewriting past runs."}),e.jsx("div",{className:"mt-4",children:e.jsx(m,{to:"/psyche/questionnaires/new",children:e.jsx(h,{variant:"secondary",className:$("w-full sm:w-auto"),children:"Open builder"})})})]})]})]})}export{H as PsycheQuestionnairesPage};
@@ -1,3 +1,3 @@
1
- import{r as m,j as e,d8 as ie,bi as ae,cc as ne}from"./vendor-DHkYh85p.js";import{j as re,i as x,k as R}from"./state-B-4sS1xO.js";import{B as b,Z as oe,d1 as de,ai as le,S as ce,E as D,T as H,aq as U,ah as V,I as C,b as G,ck as he,d2 as me,by as pe,bz as xe,bA as ge,cu as ue,d3 as ye,d4 as ve}from"./index-BHTUu_4M.js";import{A as Y,m as Z}from"./motion-BeD44FeG.js";import{I as fe}from"./insight-flow-dialog-pzAzyayN.js";import{O as be}from"./open-in-graph-button-Cg5VrKsC.js";import{E as we}from"./entity-notes-surface-DgEgicaE.js";import{S as f,B as je,M as ke,T as Te,E as Ne}from"./report-chain-fields-fZ8Xd4H6.js";import{P as Ie}from"./page-hero-CQWo1Mm_.js";import{t as Se}from"./psyche-schemas-HFmg37Wj.js";import{b as Le,a as Ce,c as Ee,f as Me,t as Be}from"./schema-visuals-D6nxjbYC.js";import"./board-BkDRaMp6.js";import"./ui-C13Nbgas.js";import"./forms-BFlTgZ3W.js";import"./graph-D6JLqDbD.js";import"./note-markdown-DiW2-5d3.js";import"./note-tags-input-DDLXf54U.js";const J="(max-width: 1023px)";function qe(){const[i,o]=m.useState(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia(J).matches);return m.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const d=window.matchMedia(J),h=s=>o(s.matches);return o(d.matches),typeof d.addEventListener=="function"?(d.addEventListener("change",h),()=>d.removeEventListener("change",h)):(d.addListener(h),()=>d.removeListener(h))},[]),i}function Ae({stages:i,activeStageId:o,onStageChange:d,stageContent:h,inspector:s}){const a=qe(),[w,u]=m.useState(!1),r=i.find(l=>l.id===o);return m.useEffect(()=>{u(!a)},[a]),e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1fr)_18rem]",children:[e.jsxs("div",{className:"rounded-[30px] border border-white/8 bg-[radial-gradient(circle_at_top,rgba(196,181,253,0.12),transparent_38%),linear-gradient(180deg,rgba(21,20,38,0.98),rgba(10,12,22,0.96))] p-4",children:[e.jsxs("div",{className:"mb-4 flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/38",children:"Tracing the chain"}),e.jsx("div",{className:"mt-1 text-sm text-white/58",children:r==null?void 0:r.summary})]}),s?e.jsxs(b,{variant:"secondary",size:"sm",onClick:()=>u(l=>!l),children:[w?e.jsx(ie,{className:"size-4"}):e.jsx(ae,{className:"size-4"}),"Inspector"]}):null]}),e.jsx("div",{className:"mb-4 overflow-x-auto pb-1",children:e.jsx("div",{className:"flex min-w-max items-center gap-3",children:i.map((l,y)=>e.jsxs("button",{type:"button",className:oe("rounded-[22px] px-4 py-3 text-left transition",l.id===o?"bg-[rgba(196,181,253,0.18)] text-white shadow-[0_18px_40px_rgba(15,12,28,0.28)]":"bg-white/[0.04] text-white/58 hover:bg-white/[0.07] hover:text-white"),onClick:()=>d(l.id),children:[e.jsxs("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/34",children:[y+1,". ",l.label]}),a?null:e.jsx("div",{className:"mt-1.5 text-sm leading-5",children:l.summary})]},l.id))})}),e.jsxs("div",{className:"rounded-[28px] border border-white/8 bg-[linear-gradient(180deg,rgba(255,255,255,0.04),rgba(255,255,255,0.02))] p-4 md:p-5",children:[e.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"rounded-full bg-white/[0.07] px-3 py-1.5 text-[11px] uppercase tracking-[0.18em] text-white/42",children:r==null?void 0:r.label}),e.jsx("span",{className:"text-sm text-white/54",children:r==null?void 0:r.summary})]}),e.jsx(Y,{mode:"wait",children:e.jsx(Z.div,{initial:{opacity:0,y:14},animate:{opacity:1,y:0},exit:{opacity:0,y:-14},transition:{duration:.26,ease:"easeOut"},children:h},o)})]})]}),s?e.jsx(Y,{initial:!1,children:w?e.jsxs(Z.div,{initial:{opacity:0,x:16},animate:{opacity:1,x:0},exit:{opacity:0,x:16},transition:{duration:.22,ease:"easeOut"},className:"rounded-[26px] border border-white/8 bg-[linear-gradient(180deg,rgba(17,24,35,0.96),rgba(11,16,24,0.94))] p-3.5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/42",children:"Linked inspectors"}),e.jsx("div",{className:"mt-3 grid gap-3",children:s})]}):null}):null]})}function Pe(i){return i.join(`
1
+ import{r as m,j as e,d8 as ie,bi as ae,cc as ne}from"./vendor-DHkYh85p.js";import{j as re,i as x,k as R}from"./state-B-4sS1xO.js";import{B as b,Z as oe,d1 as de,ai as le,S as ce,E as D,T as H,aq as U,ah as V,I as C,b as G,ck as he,d2 as me,by as pe,bz as xe,bA as ge,cu as ue,d3 as ye,d4 as ve}from"./index-CF4J4R9L.js";import{A as Y,m as Z}from"./motion-BeD44FeG.js";import{I as fe}from"./insight-flow-dialog-8f3D0GuC.js";import{O as be}from"./open-in-graph-button-IXe9SGth.js";import{E as we}from"./entity-notes-surface-CkcRsKJQ.js";import{S as f,B as je,M as ke,T as Te,E as Ne}from"./report-chain-fields-CALCV3V5.js";import{P as Ie}from"./page-hero-DRy5b2MU.js";import{t as Se}from"./psyche-schemas-HFmg37Wj.js";import{b as Le,a as Ce,c as Ee,f as Me,t as Be}from"./schema-visuals-D6nxjbYC.js";import"./board-BkDRaMp6.js";import"./ui-C13Nbgas.js";import"./forms-BFlTgZ3W.js";import"./graph-D6JLqDbD.js";import"./note-markdown-N-uxD3Xt.js";import"./note-tags-input-Cdu7wiw6.js";const J="(max-width: 1023px)";function qe(){const[i,o]=m.useState(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia(J).matches);return m.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const d=window.matchMedia(J),h=s=>o(s.matches);return o(d.matches),typeof d.addEventListener=="function"?(d.addEventListener("change",h),()=>d.removeEventListener("change",h)):(d.addListener(h),()=>d.removeListener(h))},[]),i}function Ae({stages:i,activeStageId:o,onStageChange:d,stageContent:h,inspector:s}){const a=qe(),[w,u]=m.useState(!1),r=i.find(l=>l.id===o);return m.useEffect(()=>{u(!a)},[a]),e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1fr)_18rem]",children:[e.jsxs("div",{className:"rounded-[30px] border border-white/8 bg-[radial-gradient(circle_at_top,rgba(196,181,253,0.12),transparent_38%),linear-gradient(180deg,rgba(21,20,38,0.98),rgba(10,12,22,0.96))] p-4",children:[e.jsxs("div",{className:"mb-4 flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/38",children:"Tracing the chain"}),e.jsx("div",{className:"mt-1 text-sm text-white/58",children:r==null?void 0:r.summary})]}),s?e.jsxs(b,{variant:"secondary",size:"sm",onClick:()=>u(l=>!l),children:[w?e.jsx(ie,{className:"size-4"}):e.jsx(ae,{className:"size-4"}),"Inspector"]}):null]}),e.jsx("div",{className:"mb-4 overflow-x-auto pb-1",children:e.jsx("div",{className:"flex min-w-max items-center gap-3",children:i.map((l,y)=>e.jsxs("button",{type:"button",className:oe("rounded-[22px] px-4 py-3 text-left transition",l.id===o?"bg-[rgba(196,181,253,0.18)] text-white shadow-[0_18px_40px_rgba(15,12,28,0.28)]":"bg-white/[0.04] text-white/58 hover:bg-white/[0.07] hover:text-white"),onClick:()=>d(l.id),children:[e.jsxs("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/34",children:[y+1,". ",l.label]}),a?null:e.jsx("div",{className:"mt-1.5 text-sm leading-5",children:l.summary})]},l.id))})}),e.jsxs("div",{className:"rounded-[28px] border border-white/8 bg-[linear-gradient(180deg,rgba(255,255,255,0.04),rgba(255,255,255,0.02))] p-4 md:p-5",children:[e.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"rounded-full bg-white/[0.07] px-3 py-1.5 text-[11px] uppercase tracking-[0.18em] text-white/42",children:r==null?void 0:r.label}),e.jsx("span",{className:"text-sm text-white/54",children:r==null?void 0:r.summary})]}),e.jsx(Y,{mode:"wait",children:e.jsx(Z.div,{initial:{opacity:0,y:14},animate:{opacity:1,y:0},exit:{opacity:0,y:-14},transition:{duration:.26,ease:"easeOut"},children:h},o)})]})]}),s?e.jsx(Y,{initial:!1,children:w?e.jsxs(Z.div,{initial:{opacity:0,x:16},animate:{opacity:1,x:0},exit:{opacity:0,x:16},transition:{duration:.22,ease:"easeOut"},className:"rounded-[26px] border border-white/8 bg-[linear-gradient(180deg,rgba(17,24,35,0.96),rgba(11,16,24,0.94))] p-3.5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/42",children:"Linked inspectors"}),e.jsx("div",{className:"mt-3 grid gap-3",children:s})]}):null}):null]})}function Pe(i){return i.join(`
2
2
  `)}function E(i,o){return i.includes(o)?i.filter(d=>d!==o):[...i,o]}function Oe(i){return{title:i.title,status:i.status,eventTypeId:i.eventTypeId??"",customEventType:i.customEventType,eventSituation:i.eventSituation,occurredAt:i.occurredAt?i.occurredAt.slice(0,16):"",emotions:i.emotions,thoughts:i.thoughts,behaviors:i.behaviors,selfShortTerm:i.consequences.selfShortTerm,selfLongTerm:i.consequences.selfLongTerm,othersShortTerm:i.consequences.othersShortTerm,othersLongTerm:i.consequences.othersLongTerm,modeOverlaysText:Pe(i.modeOverlays),schemaLinks:i.schemaLinks,modeTimeline:i.modeTimeline,nextMoves:i.nextMoves,linkedBehaviorIds:i.linkedBehaviorIds,linkedBeliefIds:i.linkedBeliefIds,linkedModeIds:i.linkedModeIds}}function et(){var F,Q,K,W,_,z;const{reportId:i}=ne(),o=re(),[d,h]=m.useState("spark"),[s,a]=m.useState(null),[w,u]=m.useState(!1),r=x({queryKey:["forge-psyche-report",i],queryFn:()=>me(i),enabled:!!i}),l=x({queryKey:["forge-psyche-behaviors"],queryFn:pe}),y=x({queryKey:["forge-psyche-beliefs"],queryFn:xe}),k=x({queryKey:["forge-psyche-modes"],queryFn:ge}),T=x({queryKey:["forge-psyche-schema-catalog"],queryFn:ue}),N=x({queryKey:["forge-psyche-event-types"],queryFn:ye}),I=x({queryKey:["forge-psyche-emotions"],queryFn:ve});m.useEffect(()=>{var t;(t=r.data)!=null&&t.report&&a(Oe(r.data.report))},[r.data]);const M=R({mutationFn:async t=>{var j;const n=(j=r.data)==null?void 0:j.report,p=Se.parse({title:t.title,status:t.status,eventTypeId:t.eventTypeId||null,customEventType:t.customEventType,eventSituation:t.eventSituation,occurredAt:t.occurredAt?new Date(t.occurredAt).toISOString():null,emotions:t.emotions.filter(c=>c.label.trim().length>0),thoughts:t.thoughts.filter(c=>c.text.trim().length>0),behaviors:t.behaviors.filter(c=>c.text.trim().length>0),consequences:{selfShortTerm:t.selfShortTerm,selfLongTerm:t.selfLongTerm,othersShortTerm:t.othersShortTerm,othersLongTerm:t.othersLongTerm},linkedPatternIds:(n==null?void 0:n.linkedPatternIds)??[],linkedValueIds:(n==null?void 0:n.linkedValueIds)??[],linkedGoalIds:(n==null?void 0:n.linkedGoalIds)??[],linkedProjectIds:(n==null?void 0:n.linkedProjectIds)??[],linkedTaskIds:(n==null?void 0:n.linkedTaskIds)??[],linkedBehaviorIds:t.linkedBehaviorIds,linkedBeliefIds:t.linkedBeliefIds,linkedModeIds:t.linkedModeIds,modeOverlays:t.modeOverlaysText.split(`
3
3
  `).map(c=>c.trim()).filter(Boolean),schemaLinks:t.schemaLinks.filter(Boolean),modeTimeline:t.modeTimeline.filter(c=>c.stage.trim().length>0&&c.label.trim().length>0),nextMoves:t.nextMoves.filter(Boolean)});return de(i,p)},onSuccess:async()=>{await Promise.all([o.invalidateQueries({queryKey:["forge-psyche-report",i]}),o.invalidateQueries({queryKey:["forge-psyche-reports"]}),o.invalidateQueries({queryKey:["forge-psyche-overview"]}),o.invalidateQueries({queryKey:["forge-reward-ledger"]})])}}),S=R({mutationFn:le,onSuccess:async()=>{await o.invalidateQueries({queryKey:["forge-psyche-report",i]}),await o.invalidateQueries({queryKey:["forge-insights"]})}}),B=r.error??l.error??y.error??k.error??T.error??N.error??I.error??null;if(r.isLoading||!s)return e.jsx(ce,{});if(B)return e.jsx(D,{eyebrow:"Trigger report",error:B,onRetry:()=>void Promise.all([r.refetch(),l.refetch(),y.refetch(),k.refetch(),T.refetch(),N.refetch(),I.refetch()])});if(!r.data)return e.jsx(D,{eyebrow:"Trigger report",error:new Error("Forge returned an empty trigger report payload."),onRetry:()=>void r.refetch()});const q=r.data,g=q.report,A=((F=l.data)==null?void 0:F.behaviors)??[],L=((Q=y.data)==null?void 0:Q.beliefs)??[],v=((K=k.data)==null?void 0:K.modes)??[],P=((W=T.data)==null?void 0:W.schemas)??[],X=((_=N.data)==null?void 0:_.eventTypes)??[],ee=((z=I.data)==null?void 0:z.emotions)??[],O=[{id:"spark",label:"Spark",summary:"What happened concretely?"},{id:"wave",label:"Wave",summary:"What emotional wave moved through you?"},{id:"script",label:"Script",summary:"What did the mind start saying?"},{id:"lens",label:"Lens",summary:"Which schemas and beliefs got activated?"},{id:"state",label:"State",summary:"Which modes took the wheel?"},{id:"move",label:"Move",summary:"What did you do or want to do?"},{id:"horizon",label:"Horizon",summary:"What were the consequences?"},{id:"pivot",label:"Pivot",summary:"What is the next move now?"}],te={spark:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-[minmax(0,1fr)_13rem]",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/58",children:"Title"}),e.jsx(C,{value:s.title,onChange:t=>a({...s,title:t.target.value})})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/58",children:"Status"}),e.jsxs("select",{className:"rounded-[22px] border border-white/8 bg-white/6 px-4 py-3 text-sm text-white",value:s.status,onChange:t=>a({...s,status:t.target.value}),children:[e.jsx("option",{value:"draft",children:"draft"}),e.jsx("option",{value:"reviewed",children:"reviewed"}),e.jsx("option",{value:"integrated",children:"integrated"})]})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/58",children:"Event type"}),e.jsxs("select",{className:"rounded-[22px] border border-white/8 bg-white/6 px-4 py-3 text-sm text-white",value:s.eventTypeId,onChange:t=>a({...s,eventTypeId:t.target.value}),children:[e.jsx("option",{value:"",children:"Custom or uncategorized"}),X.map(t=>e.jsx("option",{value:t.id,children:t.label},t.id))]})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/58",children:"Occurred at"}),e.jsx(C,{type:"datetime-local",value:s.occurredAt,onChange:t=>a({...s,occurredAt:t.target.value})})]})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/58",children:"Custom event label"}),e.jsx(C,{value:s.customEventType,onChange:t=>a({...s,customEventType:t.target.value})})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/58",children:"Situation"}),e.jsx(H,{value:s.eventSituation,onChange:t=>a({...s,eventSituation:t.target.value})})]})]}),wave:e.jsx(Ne,{items:s.emotions,onChange:t=>a({...s,emotions:t}),definitions:ee}),script:e.jsx(Te,{items:s.thoughts,onChange:t=>a({...s,thoughts:t}),beliefs:L,modes:v}),lens:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-4 rounded-[24px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"text-sm font-medium text-white",children:"Schema links"}),e.jsx(U,{content:"Use maladaptive schemas for recurring old patterns that were active here. Use adaptive schemas for healthier patterns you want this response to build on.",label:"Explain schema links"})]}),e.jsx(V,{children:"Choose the schemas that were active here or that you want the repair move to strengthen."}),[{title:"Maladaptive schemas",schemas:P.filter(t=>t.schemaType==="maladaptive"),schemaType:"maladaptive",description:"Recurring old patterns that felt active in this moment."},{title:"Adaptive schemas",schemas:P.filter(t=>t.schemaType==="adaptive"),schemaType:"adaptive",description:"Healthier stable themes you want this chain to strengthen."}].map(t=>{const n=Le(t.schemaType);return e.jsxs("div",{className:`rounded-[22px] border p-4 ${n.cardTone}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"text-sm font-medium text-white",children:t.title}),e.jsx(U,{content:Ee(t.schemaType),label:`Explain ${Ce(t.schemaType)}`})]}),e.jsx(V,{className:"mt-2",children:t.description}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:t.schemas.map(p=>{const j=s.schemaLinks.some(c=>{var $;return(($=Me(c,[p]))==null?void 0:$.id)===p.id});return e.jsx("button",{type:"button",className:`rounded-full border px-3 py-2 text-sm transition ${j?`${n.badgeTone} ring-1 ring-white/18`:"border-white/8 bg-white/[0.04] text-white/58 hover:bg-white/[0.08] hover:text-white"}`,onClick:()=>a({...s,schemaLinks:Be(s.schemaLinks,p)}),children:p.title},p.id)})})]},t.schemaType)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-white/58",children:"Linked beliefs"}),e.jsx("div",{className:"mt-3 flex max-h-56 flex-wrap gap-2 overflow-y-auto",children:L.map(t=>{const n=s.linkedBeliefIds.includes(t.id);return e.jsx("button",{type:"button",className:`rounded-full px-3 py-2 text-sm transition ${n?"bg-[rgba(196,181,253,0.18)] text-violet-100":"bg-white/[0.05] text-white/58 hover:bg-white/[0.08] hover:text-white"}`,onClick:()=>a({...s,linkedBeliefIds:E(s.linkedBeliefIds,t.id)}),children:t.statement},t.id)})})]})]}),state:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-white/58",children:"Mode overlays"}),e.jsx(H,{value:s.modeOverlaysText,onChange:t=>a({...s,modeOverlaysText:t.target.value})})]}),e.jsx(ke,{items:s.modeTimeline,onChange:t=>a({...s,modeTimeline:t}),modes:v,stages:O.map(t=>t.label)}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-white/58",children:"Linked modes"}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:v.map(t=>{const n=s.linkedModeIds.includes(t.id);return e.jsx("button",{type:"button",className:`rounded-full px-3 py-2 text-sm transition ${n?"bg-[rgba(251,191,36,0.18)] text-amber-100":"bg-white/[0.05] text-white/58 hover:bg-white/[0.08] hover:text-white"}`,onClick:()=>a({...s,linkedModeIds:E(s.linkedModeIds,t.id)}),children:t.title},t.id)})})]})]}),move:e.jsxs("div",{className:"grid gap-4",children:[e.jsx(je,{items:s.behaviors,onChange:t=>a({...s,behaviors:t}),behaviors:A,modes:v}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-white/58",children:"Linked behaviors"}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:A.map(t=>{const n=s.linkedBehaviorIds.includes(t.id);return e.jsx("button",{type:"button",className:`rounded-full px-3 py-2 text-sm transition ${n?"bg-[rgba(251,113,133,0.16)] text-rose-100":"bg-white/[0.05] text-white/58 hover:bg-white/[0.08] hover:text-white"}`,onClick:()=>a({...s,linkedBehaviorIds:E(s.linkedBehaviorIds,t.id)}),children:t.title},t.id)})})]})]}),horizon:e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(f,{title:"Short-term impact on you",description:"What happened to you right away?",addLabel:"Add self effect",items:s.selfShortTerm,onChange:t=>a({...s,selfShortTerm:t}),placeholder:"I shut down and lost the evening."}),e.jsx(f,{title:"Long-term impact on you",description:"What does this cost if it keeps repeating?",addLabel:"Add self cost",items:s.selfLongTerm,onChange:t=>a({...s,selfLongTerm:t}),placeholder:"It keeps training the same abandonment script."}),e.jsx(f,{title:"Short-term impact on others",description:"What happened to other people right away?",addLabel:"Add other effect",items:s.othersShortTerm,onChange:t=>a({...s,othersShortTerm:t}),placeholder:"They felt shut out."}),e.jsx(f,{title:"Long-term impact on others",description:"What pattern does this create over time?",addLabel:"Add other cost",items:s.othersLongTerm,onChange:t=>a({...s,othersLongTerm:t}),placeholder:"Trust gets thinner each time."})]}),pivot:e.jsxs("div",{className:"grid gap-4",children:[e.jsx(f,{title:"What is the next move now?",description:"Finish with concrete repairs, boundaries, or committed actions.",addLabel:"Add next move",items:s.nextMoves,onChange:t=>a({...s,nextMoves:t}),placeholder:"Send one honest repair message tomorrow morning."}),e.jsx("div",{className:"flex justify-end",children:e.jsx(b,{pending:M.isPending,onClick:()=>void M.mutateAsync(s),children:"Save chain"})})]})},se=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rounded-[22px] bg-white/[0.04] p-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/38",children:"Linked modes"}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[v.filter(t=>s.linkedModeIds.includes(t.id)).map(t=>e.jsx(G,{kind:"mode",label:t.title,compact:!0},t.id)),s.linkedModeIds.length===0?e.jsx(b,{variant:"secondary",size:"sm",onClick:()=>h("state"),children:"Link mode"}):null]})]}),e.jsxs("div",{className:"rounded-[22px] bg-white/[0.04] p-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/38",children:"Linked beliefs"}),e.jsxs("div",{className:"mt-3 grid gap-2",children:[L.filter(t=>s.linkedBeliefIds.includes(t.id)).map(t=>e.jsx("div",{className:"rounded-[16px] bg-white/[0.04] px-3 py-3",children:e.jsx(G,{kind:"belief",label:t.statement,compact:!0})},t.id)),s.linkedBeliefIds.length===0?e.jsx(b,{variant:"secondary",size:"sm",onClick:()=>h("lens"),children:"Link belief"}):null]})]}),e.jsx(we,{entityType:"trigger_report",entityId:g.id,anchorKey:d,includeAnchorlessWhenAnchored:!0,compact:!0,title:`Stage notes on ${d}`,description:"Use anchored Markdown notes to capture what became clear at this stage of the chain.",invalidateQueryKeys:[["forge-psyche-report",i],["forge-psyche-reports"],["forge-psyche-overview"]]}),e.jsxs("div",{className:"rounded-[22px] bg-white/[0.04] p-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/38",children:"Insights"}),e.jsxs("div",{className:"mt-3 grid gap-2",children:[q.insights.map(t=>e.jsxs("div",{className:"rounded-[16px] bg-white/[0.04] px-3 py-3 text-sm text-white/72",children:[e.jsx("div",{className:"font-medium text-white",children:t.title}),e.jsx("div",{className:"mt-2 text-white/62",children:t.summary})]},t.id)),e.jsx(b,{variant:"secondary",pending:S.isPending,onClick:()=>u(!0),children:"Store insight"})]})]})]});return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(Ie,{eyebrow:"Trigger report",title:g.title,description:"Move through Spark to Pivot in one chain canvas.",badge:g.status,actions:e.jsx(be,{entityType:"trigger_report",entityId:g.id})}),e.jsx(he,{}),e.jsx(Ae,{stages:O,activeStageId:d,onStageChange:h,stageContent:te[d],inspector:se}),e.jsx(fe,{open:w,onOpenChange:u,eyebrow:"Report insight",title:"Store report insight",description:"Capture the insight from this report as a guided recommendation instead of a raw side-panel form.",submitLabel:"Store insight",pending:S.isPending,lockedEntity:{entityType:"trigger_report",entityId:g.id,kind:"report",label:g.title,description:`Anchored to the ${d} stage of this reflective chain.`},initialValue:{originType:"user",originLabel:"Forge Psyche",timeframeLabel:"Current trigger report",rationale:`Captured from the ${d} stage of the Psyche chain canvas.`},onSubmit:async t=>{await S.mutateAsync(t)}})]})}export{et as PsycheReportDetailPage};