@codeyam/codeyam-cli 0.1.22 → 0.1.24

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 (102) hide show
  1. package/analyzer-template/.build-info.json +7 -7
  2. package/analyzer-template/log.txt +3 -3
  3. package/analyzer-template/packages/ai/src/lib/astScopes/methodSemantics.ts +135 -0
  4. package/analyzer-template/packages/ai/src/lib/astScopes/nodeToSource.ts +19 -0
  5. package/analyzer-template/packages/ai/src/lib/astScopes/paths.ts +11 -4
  6. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateDataStructure.ts +5 -1
  7. package/analyzer-template/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.ts +1632 -1554
  8. package/analyzer-template/packages/database/src/lib/loadAnalysis.ts +7 -1
  9. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalysis.d.ts.map +1 -1
  10. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalysis.js +7 -1
  11. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalysis.js.map +1 -1
  12. package/analyzer-template/project/runMultiScenarioServer.ts +26 -3
  13. package/background/src/lib/virtualized/project/runMultiScenarioServer.js +23 -3
  14. package/background/src/lib/virtualized/project/runMultiScenarioServer.js.map +1 -1
  15. package/codeyam-cli/src/commands/__tests__/editor.analyzeImportsArgs.test.js +47 -0
  16. package/codeyam-cli/src/commands/__tests__/editor.analyzeImportsArgs.test.js.map +1 -0
  17. package/codeyam-cli/src/commands/__tests__/editor.auditNoAutoAnalysis.test.js +17 -9
  18. package/codeyam-cli/src/commands/__tests__/editor.auditNoAutoAnalysis.test.js.map +1 -1
  19. package/codeyam-cli/src/commands/__tests__/editor.designSystem.test.js +30 -0
  20. package/codeyam-cli/src/commands/__tests__/editor.designSystem.test.js.map +1 -0
  21. package/codeyam-cli/src/commands/editor.js +207 -41
  22. package/codeyam-cli/src/commands/editor.js.map +1 -1
  23. package/codeyam-cli/src/commands/editorAnalyzeImportsArgs.js +23 -0
  24. package/codeyam-cli/src/commands/editorAnalyzeImportsArgs.js.map +1 -0
  25. package/codeyam-cli/src/data/designSystems.js +27 -0
  26. package/codeyam-cli/src/data/designSystems.js.map +1 -0
  27. package/codeyam-cli/src/utils/__tests__/editorApi.test.js +44 -0
  28. package/codeyam-cli/src/utils/__tests__/editorApi.test.js.map +1 -1
  29. package/codeyam-cli/src/utils/__tests__/editorAudit.test.js +103 -1
  30. package/codeyam-cli/src/utils/__tests__/editorAudit.test.js.map +1 -1
  31. package/codeyam-cli/src/utils/__tests__/editorScenarios.test.js +140 -1
  32. package/codeyam-cli/src/utils/__tests__/editorScenarios.test.js.map +1 -1
  33. package/codeyam-cli/src/utils/__tests__/editorSeedAdapter.test.js +50 -1
  34. package/codeyam-cli/src/utils/__tests__/editorSeedAdapter.test.js.map +1 -1
  35. package/codeyam-cli/src/utils/editorApi.js +16 -0
  36. package/codeyam-cli/src/utils/editorApi.js.map +1 -1
  37. package/codeyam-cli/src/utils/editorAudit.js +38 -2
  38. package/codeyam-cli/src/utils/editorAudit.js.map +1 -1
  39. package/codeyam-cli/src/utils/editorScenarios.js +60 -0
  40. package/codeyam-cli/src/utils/editorScenarios.js.map +1 -1
  41. package/codeyam-cli/src/utils/editorSeedAdapter.js +42 -2
  42. package/codeyam-cli/src/utils/editorSeedAdapter.js.map +1 -1
  43. package/codeyam-cli/src/utils/queue/__tests__/job.interactiveStart.test.js +159 -0
  44. package/codeyam-cli/src/utils/queue/__tests__/job.interactiveStart.test.js.map +1 -0
  45. package/codeyam-cli/src/utils/queue/job.js +9 -1
  46. package/codeyam-cli/src/utils/queue/job.js.map +1 -1
  47. package/codeyam-cli/src/webserver/__tests__/api.interactive-switch-scenario.test.js +98 -0
  48. package/codeyam-cli/src/webserver/__tests__/api.interactive-switch-scenario.test.js.map +1 -0
  49. package/codeyam-cli/src/webserver/__tests__/editorProxy.test.js +30 -11
  50. package/codeyam-cli/src/webserver/__tests__/editorProxy.test.js.map +1 -1
  51. package/codeyam-cli/src/webserver/app/routes/api.interactive-switch-scenario.js +34 -0
  52. package/codeyam-cli/src/webserver/app/routes/api.interactive-switch-scenario.js.map +1 -0
  53. package/codeyam-cli/src/webserver/build/client/assets/{InteractivePreview-CKeQT5Ty.js → InteractivePreview-DtYTSPL2.js} +1 -1
  54. package/codeyam-cli/src/webserver/build/client/assets/{ScenarioViewer-DUMfcNVK.js → ScenarioViewer-CefgqbCr.js} +1 -1
  55. package/codeyam-cli/src/webserver/build/client/assets/Spinner-Bc8BG-Lw.js +34 -0
  56. package/codeyam-cli/src/webserver/build/client/assets/{_index-BAWd-Xjf.js → _index-C1YkzTAV.js} +1 -1
  57. package/codeyam-cli/src/webserver/build/client/assets/{activity.(_tab)-BOARiB-g.js → activity.(_tab)-yH46LLUz.js} +1 -1
  58. package/codeyam-cli/src/webserver/build/client/assets/api.editor-verify-routes-l0sNRNKZ.js +1 -0
  59. package/codeyam-cli/src/webserver/build/client/assets/api.interactive-switch-scenario-l0sNRNKZ.js +1 -0
  60. package/codeyam-cli/src/webserver/build/client/assets/{dev.empty-C8y4mmyv.js → dev.empty-CRepiabR.js} +1 -1
  61. package/codeyam-cli/src/webserver/build/client/assets/{editor.entity.(_sha)-aIHKLB-m.js → editor.entity.(_sha)-oBrbke_R.js} +19 -19
  62. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha._-ByHz6rAQ.js → entity._sha._-DYJRGiDI.js} +1 -1
  63. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha.scenarios._scenarioId.dev-CmLO432x.js → entity._sha.scenarios._scenarioId.dev-wdiwx5-Z.js} +1 -1
  64. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha.scenarios._scenarioId.fullscreen-Bz9sCUF_.js → entity._sha.scenarios._scenarioId.fullscreen-BrkN-40Y.js} +1 -1
  65. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.create-scenario-DQM8E7L4.js → entity._sha_.create-scenario-DxfhekTZ.js} +1 -1
  66. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.edit._scenarioId-CAoXLsQr.js → entity._sha_.edit._scenarioId-CRXJWmpB.js} +1 -1
  67. package/codeyam-cli/src/webserver/build/client/assets/manifest-694b698a.js +1 -0
  68. package/codeyam-cli/src/webserver/build/client/assets/{root-D2_tktnk.js → root-DXjFYOxD.js} +1 -1
  69. package/codeyam-cli/src/webserver/build/client/assets/useLastLogLine-D9QZKaLJ.js +2 -0
  70. package/codeyam-cli/src/webserver/build/server/assets/{analysisRunner-DjF-soOH.js → analysisRunner-zEYtiv0T.js} +1 -1
  71. package/codeyam-cli/src/webserver/build/server/assets/{index-nAvHGWbz.js → index-CcHPEbhi.js} +1 -1
  72. package/codeyam-cli/src/webserver/build/server/assets/{init-XhpIt-OT.js → init-D68IyWbU.js} +1 -1
  73. package/codeyam-cli/src/webserver/build/server/assets/{server-build-DVwiibFu.js → server-build-Cxzo0Zp2.js} +192 -148
  74. package/codeyam-cli/src/webserver/build/server/index.js +1 -1
  75. package/codeyam-cli/src/webserver/build-info.json +5 -5
  76. package/codeyam-cli/src/webserver/editorProxy.js +55 -3
  77. package/codeyam-cli/src/webserver/editorProxy.js.map +1 -1
  78. package/codeyam-cli/src/webserver/terminalServer.js +1 -2
  79. package/codeyam-cli/src/webserver/terminalServer.js.map +1 -1
  80. package/codeyam-cli/templates/codeyam-editor-reference.md +8 -6
  81. package/codeyam-cli/templates/design-systems/clean-dashboard-design-system.md +255 -0
  82. package/codeyam-cli/templates/design-systems/editorial-design-system.md +267 -0
  83. package/codeyam-cli/templates/design-systems/mono-brutalist-design-system.md +256 -0
  84. package/codeyam-cli/templates/design-systems/neo-brutalist-design-system.md +294 -0
  85. package/codeyam-cli/templates/nextjs-prisma-sqlite/seed-adapter.ts +47 -34
  86. package/codeyam-cli/templates/seed-adapters/supabase.ts +14 -5
  87. package/package.json +1 -1
  88. package/packages/ai/src/lib/astScopes/methodSemantics.js +99 -0
  89. package/packages/ai/src/lib/astScopes/methodSemantics.js.map +1 -1
  90. package/packages/ai/src/lib/astScopes/nodeToSource.js +16 -0
  91. package/packages/ai/src/lib/astScopes/nodeToSource.js.map +1 -1
  92. package/packages/ai/src/lib/astScopes/paths.js +12 -3
  93. package/packages/ai/src/lib/astScopes/paths.js.map +1 -1
  94. package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js +5 -1
  95. package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js.map +1 -1
  96. package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js +1330 -1270
  97. package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js.map +1 -1
  98. package/packages/database/src/lib/loadAnalysis.js +7 -1
  99. package/packages/database/src/lib/loadAnalysis.js.map +1 -1
  100. package/codeyam-cli/src/webserver/build/client/assets/Spinner-D0LgAaSa.js +0 -34
  101. package/codeyam-cli/src/webserver/build/client/assets/manifest-bcbb3d49.js +0 -1
  102. package/codeyam-cli/src/webserver/build/client/assets/useLastLogLine-BNd5hYuW.js +0 -2
@@ -1,16 +1,16 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-DE3jI_dv.js","assets/jsx-runtime-D_zvdyIk.js","assets/chunk-JZWAC4HX-BAdwhyCx.js"])))=>i.map(i=>d[i]);
2
- var on=Object.defineProperty;var ln=(t,s,n)=>s in t?on(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var ns=(t,s,n)=>ln(t,typeof s!="symbol"?s+"":s,n);import{r,w as cn,u as dn,b as xn,a as un,c as mn,O as hn}from"./chunk-JZWAC4HX-BAdwhyCx.js";import{j as e}from"./jsx-runtime-D_zvdyIk.js";import{u as pn,C as fn}from"./useCustomSizes-DhXHbEjP.js";import{g as Ke,s as gn,r as bt,b as Me,c as bn,l as yn,d as jn,e as vn,f as Nn,a as wn,T as Sn,D as kn}from"./editorPreview-CluPkvXJ.js";import{C as Te}from"./CopyButton-CLe80MMu.js";import{M as $e}from"./MiniClaudeChat-CQENLSrF.js";import{_ as Cn}from"./preload-helper-ckwbz45p.js";import{c as Pn}from"./cy-logo-cli-Coe5NhbS.js";import{u as En,S as yt}from"./Spinner-D0LgAaSa.js";import"./copy-C6iF61Xs.js";import"./createLucideIcon-4ImjHTVC.js";import"./useLastLogLine-BNd5hYuW.js";function Re(t){var o;if(!t.startsWith("app/")&&!t.startsWith("("))return"/";const n=t.replace(/^app\//,"").split("/"),a=n.pop(),c=((o=a.match(/\.(tsx?|jsx?|js)$/))==null?void 0:o[0])||"",i=a.slice(0,-c.length);let l;return i==="page"||i==="index"?l=n:l=[...n,i],l=l.filter(x=>!x.startsWith("(")),l.length===0?"/":"/"+l.join("/")}function Oe(t){return t==="/"?"Home":t.replace(/^\//,"").split("/").map(n=>n.startsWith("[")?n:n.charAt(0).toUpperCase()+n.slice(1)).join(" / ")}function Qe(t){if(!t||t==="/")return"Home";const s=t.split("?")[0].replace(/^\//,"");if(!s)return"Home";const n=s.split("/")[0].replace(/\.[^.]+$/,"");return n.charAt(0).toUpperCase()+n.slice(1)}function bs(t){return t?t.includes("/isolated-components")||t.includes("/codeyam-isolate"):!1}function Fn(t,s){return!s||Object.keys(s).length===0?t:t.filter(n=>s[n.name])}const Xe=[{name:"Desktop",width:1440,height:900},{name:"Laptop",width:1024,height:768},{name:"Tablet",width:768,height:1024},{name:"Mobile",width:375,height:667}];function Dn(t){if(!t)return Xe;const s=Object.entries(t).map(([a,c])=>({name:a,width:c.width,height:c.height})),n=new Set(s.map(a=>a.name));return[...s,...Xe.filter(a=>!n.has(a.name))]}function Tn({featureName:t,editorStep:s,editorStepLabel:n,onContinue:a}){const c=r.useCallback(i=>{i.key==="Enter"&&(i.preventDefault(),a())},[a]);return r.useEffect(()=>(window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)),[c]),e.jsx("div",{className:"flex items-center justify-center h-full bg-[#1e1e1e] text-[#d4d4d4]",children:e.jsxs("div",{className:"max-w-md w-full mx-4 p-6 bg-[#252526] border border-[#3d3d3d] rounded-lg",children:[e.jsx("h2",{className:"text-lg font-semibold mb-3 text-white",children:"Resume Previous Session?"}),e.jsx("p",{className:"text-sm text-[#999] mb-4",children:"An editor session is still in progress:"}),e.jsxs("div",{className:"bg-[#1e1e1e] rounded p-3 mb-5 text-sm",children:[t&&e.jsxs("div",{className:"mb-1",children:[e.jsx("span",{className:"text-[#999]",children:"Feature:"})," ",e.jsx("span",{className:"text-white",children:t})]}),s!=null&&n&&e.jsxs("div",{children:[e.jsx("span",{className:"text-[#999]",children:"Step:"})," ",e.jsxs("span",{className:"text-white",children:[s," (",n,")"]})]})]}),e.jsx("button",{onClick:a,className:"w-full px-4 py-2 text-sm rounded transition-colors cursor-pointer bg-[#005c75] text-white font-medium hover:bg-[#004d63] ring-2 ring-white/50",children:"Continue Session"})]})})}const Ln={1:"Plan",2:"Prepare",3:"Prototype",4:"Verify Prototype",5:"Confirm",6:"Deconstruct",7:"Extract",8:"Glossary",9:"Analyze",10:"App Scenarios",11:"User Scenarios",12:"Verify",13:"Journal",14:"Review",15:"Present",16:"Commit",17:"Finalize",18:"Push"},Mn={1:"Plan the feature and confirm the approach with the user before writing any code.",2:"Prepare the project environment and dependencies for prototyping.",3:"Build a working prototype quickly to validate the concept.",4:"Verify the prototype works correctly and fix any issues.",5:"Confirm the prototype looks right and get user approval to proceed.",6:"Read the code and plan all component and function extractions.",7:"Extract components and functions via TDD — components first, then functions.",8:"Record all extracted functions and components in the glossary.",9:"Analyze imports and verify all components are captured correctly.",10:"Create app-level scenarios that show full pages with realistic data.",11:"Create user-persona scenarios that exercise the app from different perspectives.",12:"Review all screenshots and check for visual errors or regressions.",13:"Create or update the journal entry documenting what was built.",14:"Final review of screenshots, audit for completeness.",15:"Present a summary of all work to the user for approval.",16:"Commit all changes to git.",17:"Update the journal with final details and amend the commit.",18:"Push the branch to the remote repository."},An={1:"Survey",2:"App Scenarios",3:"Component Scenarios",4:"Preview",5:"Discuss",6:"Decompose",7:"Extract",8:"Recapture",9:"Journal",10:"Present"},In={1:"Survey the existing codebase to understand pages, components, and dependencies.",2:"Create app-level scenarios showing full pages with realistic data.",3:"Create component-level scenarios for isolated component previews.",4:"Preview all captured scenarios and verify they look correct.",5:"Discuss the migration plan and prioritize which pages to decompose.",6:"Plan the decomposition of pages into clean, reusable components.",7:"Extract components and functions with tests via TDD.",8:"Recapture scenarios after extraction to verify nothing broke.",9:"Document the migration progress in a journal entry.",10:"Present the migration results for review and approval."},$n=18,Rn=10;function On({projectTitle:t,featureName:s,editorStep:n,editorStepLabel:a,migrationMode:c}){const[i,l]=r.useState(!1),[o,x]=r.useState(null),S=r.useRef(null);r.useEffect(()=>{if(!i)return;const y=E=>{S.current&&!S.current.contains(E.target)&&l(!1)};return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[i]);const g=s&&n!=null,m=c==="active",p=m?An:Ln,R=m?In:Mn,h=m?Rn:$n,N=g?a||p[n]||"?":null,f=s||"New Working Session";return e.jsxs("div",{className:"h-8 shrink-0 flex items-center justify-between px-3 bg-[#2a2a2a] border-b border-[#333] text-xs select-none",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"text-[#888] truncate",children:t||"New Project"}),e.jsx("span",{className:"text-[#555]",children:">"}),e.jsx("span",{className:"text-[#ccc] font-medium truncate",children:f})]}),g&&e.jsxs("div",{className:"relative",ref:S,children:[e.jsxs("button",{onClick:()=>l(y=>!y),className:"flex items-center gap-1.5 text-[#ccc] hover:text-white transition-colors cursor-pointer",children:[e.jsx("span",{className:"text-[#555]",children:"::"}),e.jsxs("span",{children:["Step ",n,e.jsxs("span",{className:"text-[#888]",children:[" / ",h]}),":"," ",N]}),e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",className:`transition-transform ${i?"rotate-180":""}`,children:e.jsx("path",{d:"M2 4l3 3 3-3"})})]}),i&&e.jsx("div",{className:"absolute right-0 top-full mt-1 w-48 bg-[#2d2d2d] border border-[#444] rounded-lg shadow-lg z-30 py-1",children:Array.from({length:h},(y,E)=>E+1).map(y=>{const E=y===n,C=y<n,O=o===y,J=R[y];return e.jsxs("div",{onClick:()=>x(O?null:y),className:"cursor-pointer",children:[e.jsxs("div",{className:`w-full px-3 py-1 flex items-center gap-2 text-left transition-colors hover:bg-[#383838] ${E?"text-cygreen font-medium":C?"text-[#ccc]":"text-[#999]"}`,children:[e.jsxs("span",{className:"w-5 text-right tabular-nums shrink-0",children:[y,"."]}),e.jsx("span",{className:"flex-1",children:p[y]||`Step ${y}`}),J&&e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",className:`shrink-0 opacity-40 transition-transform ${O?"rotate-180":""}`,children:e.jsx("path",{d:"M2 4l3 3 3-3"})})]}),O&&J&&e.jsx("div",{className:"px-3 pb-1.5 pl-10",children:e.jsx("p",{className:"text-[10px] text-[#888] m-0 leading-relaxed",children:J})})]},y)})})]})]})}function Nt(t){const[s,n]=r.useState(null),[a,c]=r.useState(!1),i=r.useCallback(()=>{t&&(c(!0),fetch(`/api/editor-test-results?testFile=${encodeURIComponent(t)}`).then(l=>l.json()).then(l=>{n(l),c(!1)}).catch(()=>{n({testFilePath:t,status:"error",testCases:[],errorMessage:"Failed to fetch test results"}),c(!1)}))},[t]);return{results:s,isRunning:a,runTests:i}}function _e({scenarioId:t,updatedAt:s,alt:n,className:a="",imgClassName:c=""}){const[i,l]=r.useState(!1),o=`/api/editor-scenario-image/${t}.png${s?`?v=${encodeURIComponent(s)}`:""}`;return r.useEffect(()=>{l(!1)},[t]),i?e.jsx("div",{className:`flex items-center justify-center ${a}`,children:e.jsx("span",{className:"text-[8px] text-gray-500",children:"No img"})}):e.jsx("div",{className:a,children:e.jsx("img",{src:o,alt:n,className:c,loading:"lazy",onError:()=>l(!0)})})}function Ae({scenarioId:t,updatedAt:s,hasScreenshot:n,imgSrc:a,name:c,isActive:i,onSelect:l}){const o=t&&n,x=!t&&a;return e.jsxs("button",{onClick:l,className:"flex flex-col items-center gap-1 cursor-pointer group w-full",title:c,children:[e.jsx("div",{className:`w-full aspect-[16/10] rounded overflow-hidden border-2 transition-all bg-[#1a1a1a] ${i?"border-[#D7FF63]/40 ring-1 ring-[#D7FF63]/20":"border-transparent hover:border-[#4d4d4d]"}`,children:o?e.jsx(_e,{scenarioId:t,updatedAt:s,alt:c,className:"w-full h-full",imgClassName:"w-full h-full object-contain"}):x?e.jsx("img",{src:a,alt:c,className:"w-full h-full object-contain",loading:"lazy"}):e.jsx("div",{className:"w-full h-full bg-[#1a1a1a] flex items-center justify-center",children:e.jsx("span",{className:"text-[8px] text-gray-600",children:"No img"})})}),e.jsx("span",{className:`text-[10px] leading-tight text-center truncate w-full ${i?"text-white":"text-gray-500 group-hover:text-gray-300"}`,children:c})]})}function jt({testFile:t,entityName:s}){const{results:n,isRunning:a,runTests:c}=Nt(t);if(a&&!n)return e.jsxs("div",{className:"px-2 pt-1 flex items-center gap-1.5",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-[#005c75] animate-pulse"}),e.jsx("span",{className:"text-[10px] text-gray-400",children:"Running tests..."})]});if(!n)return null;if(n.status==="error")return e.jsx("div",{className:"px-2 pt-1",children:e.jsx("span",{className:"text-[10px] text-red-400",children:n.errorMessage})});const i=s?n.testCases.filter(x=>x.fullName.startsWith(s)):n.testCases,l=i.length>0?i:n.testCases;if(l.length===0)return null;const o=s?`${s} > `:"";return e.jsxs("div",{className:"px-2 pt-1 space-y-0.5",children:[l.map(x=>{var g;const S=o&&x.fullName.startsWith(o)?x.fullName.slice(o.length):x.fullName;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[x.status==="passed"?e.jsx("span",{className:"text-green-400 text-[10px]",children:"✓"}):x.status==="failed"?e.jsx("span",{className:"text-red-400 text-[10px]",children:"✗"}):e.jsx("span",{className:"text-gray-500 text-[10px]",children:"—"}),e.jsx("span",{className:`text-[10px] ${x.status==="passed"?"text-green-400":x.status==="failed"?"text-red-400":"text-gray-500"}`,children:S})]}),x.status==="failed"&&((g=x.failureMessages)==null?void 0:g.map((m,p)=>e.jsx("div",{className:"pl-4 text-[9px] text-red-300/70 truncate max-w-full",title:m,children:m.split(`
3
- `)[0]},p)))]},x.fullName)}),e.jsx("button",{onClick:c,disabled:a,className:"mt-1 text-[10px] text-[#00a0c4] hover:text-[#00c4ee] transition-colors cursor-pointer disabled:opacity-50 bg-transparent border-none p-0",children:a?"Running...":"Re-run"})]})}function Ie({filePath:t}){return t?e.jsxs("div",{className:"flex items-center gap-1 px-2 mt-0.5",children:[e.jsxs("a",{href:`/api/editor-file?path=${encodeURIComponent(t)}`,target:"_blank",rel:"noopener noreferrer",title:"Open file",className:"flex items-center gap-1 text-gray-500 hover:text-gray-300 transition-colors min-w-0",children:[e.jsx("span",{className:"text-[9px] truncate",children:t}),e.jsx("svg",{className:"shrink-0",width:"10",height:"10",viewBox:"0 0 12 12",fill:"none",children:e.jsx("path",{d:"M4.5 1.5H2.5C1.95 1.5 1.5 1.95 1.5 2.5V9.5C1.5 10.05 1.95 10.5 2.5 10.5H9.5C10.05 10.5 10.5 10.05 10.5 9.5V7.5M7.5 1.5H10.5M10.5 1.5V4.5M10.5 1.5L5 7",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})})]}),e.jsx(Te,{content:t,icon:!0,iconSize:10,className:"shrink-0 text-gray-500 hover:text-gray-300 transition-colors"})]}):null}function _n({scenarios:t,projectRoot:s,activeScenarioId:n,onScenarioSelect:a,zoomComponent:c,focusedEntity:i,onZoomChange:l,analyzedEntities:o=[],glossaryFunctions:x=[],activeAnalyzedScenarioId:S,onAnalyzedScenarioSelect:g,entityImports:m,pageFilePaths:p={},onSwitchToBuild:R,entityShaMap:h,structureTab:N="application",onStructureTabChange:f}){const[y,E]=r.useState(""),[C,O]=r.useState(N),J=f?N:C,Z=f||O,{pageGroups:B,componentGroups:q}=r.useMemo(()=>{var j;const v=new Map,A=new Map;for(const D of t)if(D.componentName){const T=A.get(D.componentName)||[];T.push(D),A.set(D.componentName,T)}else if(bs(D.url)){const T=(j=D.url)==null?void 0:j.match(/[?&]c=([^&]+)/),U=T?decodeURIComponent(T[1]):"Isolated",Q=A.get(U)||[];Q.push(D),A.set(U,Q)}else{const T=D.pageFilePath?Oe(Re(D.pageFilePath)):Qe(D.url),U=v.get(T)||[];U.push(D),v.set(T,U)}const _=new Map([...A.entries()].sort(([D],[T])=>D.localeCompare(T)));return{pageGroups:v,componentGroups:_}},[t]),w=r.useMemo(()=>{const v=new Set((o||[]).filter(_=>_.entityType==="visual").map(_=>_.name)),A=new Map;for(const[_,j]of q)v.has(_)||A.set(_,j);return A},[q,o]),{visualEntities:k,libraryEntities:F}=r.useMemo(()=>{const v=o.filter(_=>_.entityType==="visual").sort((_,j)=>_.name.localeCompare(j.name)),A=o.filter(_=>_.entityType==="library"||_.entityType==="functionCall").sort((_,j)=>_.name.localeCompare(j.name));return{visualEntities:v,libraryEntities:A}},[o]),M=r.useMemo(()=>{const v=new Set(F.map(A=>A.name));return x.filter(A=>!v.has(A.name)).sort((A,_)=>A.name.localeCompare(_.name))},[x,F]),I=o.some(v=>v.isAnalyzing),V=r.useRef(null),W=r.useRef(0),le=r.useCallback(()=>{V.current&&(W.current=V.current.scrollTop)},[]);if(r.useEffect(()=>{V.current&&W.current>0&&(V.current.scrollTop=W.current)}),t.length===0&&o.length===0&&M.length===0)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center text-gray-500 px-8",children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:"No scenarios yet"}),e.jsx("p",{className:"text-xs",children:"Scenarios will appear here as Claude creates them alongside your code. Each scenario represents a different state of your app's data."})]})});if(c&&i){const v=i.name,A=i.filePath,_=i.sha,j=t.filter($=>$.componentName===v||$.componentPath===A||!$.componentName&&($.pageFilePath===A||_&&$.entitySha===_)),D=new Set((m==null?void 0:m[v])||[]),T=D.size>0,U=T?k.filter($=>D.has($.name)):[],Q=T?F.filter($=>D.has($.name)):[];return e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsxs("div",{className:"p-3 space-y-1",children:[e.jsxs("button",{onClick:()=>l(void 0),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-gray-400 hover:text-white transition-colors cursor-pointer",children:[e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:"shrink-0",children:e.jsx("path",{d:"M7.5 9L4.5 6L7.5 3",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),"All scenarios"]}),e.jsx("div",{className:"px-3 py-1.5",children:e.jsx("span",{className:"text-xs font-semibold text-white uppercase tracking-wider",children:i.displayName})}),e.jsx("div",{className:"flex flex-wrap gap-2 px-2",children:j.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-gray-500",children:"No scenarios for this component"}):j.map($=>e.jsx(Ae,{scenarioId:$.id,updatedAt:$.updatedAt,hasScreenshot:!!$.screenshotPath,name:$.name,isActive:$.id===n,onSelect:()=>a($)},$.id))}),U.length>0&&e.jsxs("div",{className:"pt-2 mt-1 border-t border-[#3d3d3d]",children:[e.jsx("div",{className:"px-2 py-1",children:e.jsx("span",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:"Components"})}),U.map($=>e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"flex items-center gap-2 px-2 py-1",children:e.jsx("button",{onClick:()=>l($.name),className:"text-[11px] font-medium text-gray-400 truncate cursor-pointer hover:text-white transition-colors bg-transparent border-none p-0",children:$.name})}),e.jsx(Ie,{filePath:$.filePath,projectRoot:s}),($.scenarios.length>0||$.pendingScenarios.length>0)&&e.jsx("div",{className:"flex flex-wrap gap-2 px-2 pt-1",children:$.scenarios.map(L=>e.jsx(Ae,{imgSrc:L.screenshotPath?`/api/screenshot/${L.screenshotPath}`:null,name:L.name,isActive:L.id===S,onSelect:()=>g==null?void 0:g({analysisId:$.analysisId,scenarioId:L.id,scenarioName:L.name,entitySha:$.sha,entityName:$.name})},L.id))})]},$.sha))]}),Q.length>0&&e.jsxs("div",{className:"pt-2 mt-1",children:[e.jsx("div",{className:"px-2 py-1",children:e.jsx("span",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:"Functions"})}),Q.map($=>e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"px-2 py-1",children:e.jsx("span",{className:"text-[11px] font-medium text-gray-300",children:$.name})}),e.jsx(Ie,{filePath:$.filePath,projectRoot:s}),$.testFile&&e.jsx(jt,{testFile:$.testFile,entityName:$.name})]},$.sha))]})]})})}return e.jsx("div",{ref:V,onScroll:le,className:"flex-1 overflow-auto font-['IBM_Plex_Sans']",children:e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3 font-['IBM_Plex_Mono']",children:[e.jsx("button",{onClick:()=>Z("application"),className:`text-xs font-bold uppercase tracking-wider shrink-0 bg-transparent border-none cursor-pointer p-0 transition-colors ${J==="application"?"text-white":"text-gray-500 hover:text-gray-300"}`,children:"Application"}),e.jsx("button",{onClick:()=>Z("components"),className:`text-xs font-bold uppercase tracking-wider shrink-0 bg-transparent border-none cursor-pointer p-0 transition-colors ${J==="components"?"text-white":"text-gray-500 hover:text-gray-300"}`,children:"Components"}),e.jsx("div",{className:"flex-1"}),e.jsxs("div",{className:"relative",style:{width:170},children:[e.jsxs("svg",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-500",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("path",{d:"M21 21l-4.35-4.35"})]}),e.jsx("input",{type:"text",placeholder:"SEARCH...",value:y,onChange:v=>E(v.target.value),className:"w-full pl-9 pr-3 py-2 text-xs bg-[#2a2a2a] border border-[#3d3d3d] rounded-md text-gray-300 placeholder-gray-600 outline-none focus:border-[#D7FF63]/50 transition-colors tracking-wider"})]}),R&&e.jsxs("button",{onClick:R,className:"flex items-center gap-1.5 px-4 py-2 text-xs font-semibold text-[#1e1e1e] bg-[#D7FF63] rounded-md hover:bg-[#D7FF63]/80 transition-colors cursor-pointer shrink-0 uppercase tracking-wider",children:[e.jsx("span",{children:"+"})," New Feature"]})]}),e.jsx("div",{className:"border-b border-[#2d2d2d]"}),J==="application"&&B.size>0&&e.jsx("div",{children:[...B.entries()].sort(([v],[A])=>v==="Home"?-1:A==="Home"?1:v.localeCompare(A)).filter(([v])=>y.trim()?v.toLowerCase().includes(y.trim().toLowerCase()):!0).map(([v,A])=>{const _=A.some(j=>j.id===n&&!S);return e.jsxs("div",{className:"mt-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 py-1",children:[e.jsxs("button",{onClick:()=>l(v,h==null?void 0:h.get(v)),className:`flex items-center gap-1.5 text-sm font-normal cursor-pointer hover:text-white transition-colors bg-transparent border-none p-0 ${_?"text-[#D7FF63]":"text-gray-300"}`,children:[v,e.jsxs("span",{className:`text-xs ${_?"text-[#D7FF63]/60":"text-gray-500"}`,children:["(",A.length,")"]}),e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 12 12",fill:"none",className:_?"text-[#D7FF63]/60":"text-gray-500",children:e.jsx("path",{d:"M4.5 3L7.5 6L4.5 9",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]}),_&&e.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[e.jsx("button",{onClick:()=>l(v,h==null?void 0:h.get(v)),className:"p-1.5 rounded-md bg-[#3d3d3d] hover:bg-[#4d4d4d] text-gray-300 hover:text-white transition-colors cursor-pointer border-none",title:"Edit scenarios",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),e.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})}),R&&e.jsx("button",{onClick:R,className:"p-1.5 rounded-md bg-[#3d3d3d] hover:bg-[#4d4d4d] text-gray-300 hover:text-white transition-colors cursor-pointer border-none",title:"Add scenario",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-2 pt-1",children:A.map(j=>e.jsx(Ae,{scenarioId:j.id,updatedAt:j.updatedAt,hasScreenshot:!!j.screenshotPath,name:j.name,isActive:j.id===n&&!S,onSelect:()=>a(j)},j.id))})]},v)})}),J==="components"&&w.size>0&&e.jsx("div",{children:[...w.entries()].filter(([v])=>y.trim()?v.toLowerCase().includes(y.trim().toLowerCase()):!0).map(([v,A])=>{const _=A.some(j=>j.id===n&&!S);return e.jsxs("div",{className:"mt-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 py-1",children:[e.jsxs("button",{onClick:()=>l(v,h==null?void 0:h.get(v)),className:`flex items-center gap-1.5 text-sm font-normal cursor-pointer hover:text-white transition-colors bg-transparent border-none p-0 ${_?"text-[#D7FF63]":"text-gray-300"}`,children:[v,e.jsxs("span",{className:`text-xs ${_?"text-[#D7FF63]/60":"text-gray-500"}`,children:["(",A.length,")"]}),e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 12 12",fill:"none",className:_?"text-[#D7FF63]/60":"text-gray-500",children:e.jsx("path",{d:"M4.5 3L7.5 6L4.5 9",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]}),_&&e.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[e.jsx("button",{onClick:()=>l(v,h==null?void 0:h.get(v)),className:"p-1.5 rounded-md bg-[#3d3d3d] hover:bg-[#4d4d4d] text-gray-300 hover:text-white transition-colors cursor-pointer border-none",title:"Edit scenarios",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),e.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})}),R&&e.jsx("button",{onClick:R,className:"p-1.5 rounded-md bg-[#3d3d3d] hover:bg-[#4d4d4d] text-gray-300 hover:text-white transition-colors cursor-pointer border-none",title:"Add scenario",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-2 pt-1",children:A.map(j=>e.jsx(Ae,{scenarioId:j.id,updatedAt:j.updatedAt,hasScreenshot:!!j.screenshotPath,name:j.name,isActive:j.id===n&&!S,onSelect:()=>a(j)},j.id))})]},v)})}),k.length>0&&e.jsxs("div",{className:"pt-2 mt-1 border-t border-[#3d3d3d]",children:[e.jsxs("div",{className:"px-2 py-1",children:[e.jsx("span",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:"Components"}),I&&t.length===0&&o.every(v=>v.scenarioCount===0)&&e.jsx("span",{className:"ml-2 text-[10px] text-gray-500",children:"— Entities are being analyzed..."})]}),k.map(v=>e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1",children:[e.jsx("button",{onClick:()=>l(v.name),className:"text-[11px] font-medium text-gray-400 truncate cursor-pointer hover:text-white transition-colors bg-transparent border-none p-0",children:v.name}),v.isAnalyzing&&v.scenarioCount===0&&e.jsxs("span",{className:"flex items-center gap-1.5 text-[10px] text-gray-400",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-[#005c75] animate-pulse"}),"Analyzing..."]})]}),e.jsx(Ie,{filePath:v.filePath,projectRoot:s}),(v.scenarios.length>0||v.pendingScenarios.length>0)&&e.jsxs("div",{className:"flex flex-wrap gap-2 px-2 pt-1",children:[v.scenarios.map(A=>e.jsx(Ae,{imgSrc:A.screenshotPath?`/api/screenshot/${A.screenshotPath}`:null,name:A.name,isActive:A.id===S,onSelect:()=>g==null?void 0:g({analysisId:v.analysisId,scenarioId:A.id,scenarioName:A.name,entitySha:v.sha,entityName:v.name})},A.id)),v.pendingScenarios.map(A=>e.jsx("div",{className:"px-2.5 py-1 bg-[#2a2a2a] text-gray-400 text-[10px] rounded-full",title:A,children:A},A))]})]},v.sha))]}),(F.length>0||M.length>0)&&e.jsxs("div",{className:`pt-2 mt-1 ${k.length>0?"":"border-t border-[#3d3d3d]"}`,children:[e.jsx("div",{className:"px-2 py-1",children:e.jsx("span",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:"Functions"})}),F.map(v=>e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"px-2 py-1",children:[e.jsx("span",{className:"text-[11px] font-medium text-gray-300",children:v.name}),v.isAnalyzing&&v.scenarioCount===0&&e.jsxs("span",{className:"ml-2 inline-flex items-center gap-1.5 text-[10px] text-gray-400",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-[#005c75] animate-pulse"}),"Analyzing..."]})]}),e.jsx(Ie,{filePath:v.filePath,projectRoot:s}),v.testFile?e.jsx(jt,{testFile:v.testFile,entityName:v.name}):e.jsx("div",{className:"px-2 pt-1",children:e.jsx("span",{className:"text-[10px] text-gray-500",children:"No test file"})})]},v.sha)),M.map(v=>e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"px-2 py-1",children:e.jsx("span",{className:"text-[11px] font-medium text-gray-300",children:v.name})}),e.jsx(Ie,{filePath:v.filePath,projectRoot:s}),e.jsx(jt,{testFile:v.testFile,entityName:v.name})]},v.name))]})]})})}function ys(t){const s={};for(const[n,a]of Object.entries(t))if(typeof a=="string")try{const c=JSON.parse(a);Array.isArray(c)?s[n]=c:typeof c=="object"&&c!==null&&(s[n]=[c])}catch{}else Array.isArray(a)&&(s[n]=a);return s}function js(t,s){return t.length===0||s.length===0?!1:t.filter(a=>s.includes(a)).length>=Math.min(t.length,s.length)*.5}function Bn(t,s){const{_metadata:n,...a}=s,c=a.localStorage&&typeof a.localStorage=="object"&&!Array.isArray(a.localStorage)?ys(a.localStorage):{},i={};if(a.seed&&typeof a.seed=="object"&&!Array.isArray(a.seed))for(const[m,p]of Object.entries(a.seed))Array.isArray(p)&&(i[m]=p);const l={},o=[],x=new Set,S=new Set,g=new Set;for(const m of t){const p=m.fields.filter(y=>!y.isRelation),R=p.map(y=>y.name),h=m.name.charAt(0).toLowerCase()+m.name.slice(1);let N=null,f=[];for(const y of[m.name,h,`${h}s`])if(y in a&&Array.isArray(a[y])){N=y,f=a[y],S.add(y);break}if(!N){for(const y of[m.name,h,`${h}s`])if(y in i){N=y,f=i[y],g.add(y),y in c&&x.add(y);break}}if(!N){for(const y of[m.name,h,`${h}s`])if(y in c){N=h,f=c[y],x.add(y);break}}if(!N){for(const[y,E]of Object.entries(c))if(!x.has(y)&&E.length>0&&js(R,Object.keys(E[0]))){N=h,f=E,x.add(y);break}}N||(N=h),l[N]=f,o.push({label:m.name,dataKey:N,schemaFields:p.map(y=>({name:y.name,type:y.type,isId:y.isId}))})}for(const[m,p]of Object.entries(a))m==="_metadata"||m==="localStorage"||m==="seed"||m==="type"||S.has(m)||Array.isArray(p)&&(l[m]=p,o.push({label:m,dataKey:m}));for(const[m,p]of Object.entries(i))g.has(m)||(l[m]=p,o.push({label:m,dataKey:m}));for(const[m,p]of Object.entries(c))x.has(m)||(l[m]=p,o.push({label:m,dataKey:m}));return{data:l,tabs:o}}function Wn(t){return t==null?"null":typeof t=="number"?Number.isInteger(t)?"int4":"float":typeof t=="boolean"?"bool":typeof t=="object"?Array.isArray(t)?"array":"json":"text"}function zn(t,s){return t.length>0?Object.keys(t[0]):s?s.map(n=>n.name):[]}function Un(t,s,n){const a=new Map((n||[]).map(i=>[i.name,i.type])),c={};for(const i of t)c[i]=a.get(i)||(s.length>0?Wn(s[0][i]):"text");return c}function Hn(t,s){var n;return((n=s==null?void 0:s.find(a=>a.isId))==null?void 0:n.name)||t.find(a=>a==="id")||null}function Vn(t,s){const{_metadata:n,...a}=s,c=a.localStorage&&typeof a.localStorage=="object"&&!Array.isArray(a.localStorage)?ys(a.localStorage):{},i={};if(a.seed&&typeof a.seed=="object"&&!Array.isArray(a.seed))for(const[m,p]of Object.entries(a.seed))Array.isArray(p)&&(i[m]=p);const l={},o=[],x=new Set,S=new Set,g=new Set;for(const m of t){const p=m.name.charAt(0).toLowerCase()+m.name.slice(1),R=m.fields.map(f=>f.name);let h=null,N=[];for(const f of[m.name,p,`${p}s`])if(f in a&&Array.isArray(a[f])){h=f,N=a[f],S.add(f);break}if(!h){for(const f of[m.name,p,`${p}s`])if(f in i){h=f,N=i[f],g.add(f),f in c&&x.add(f);break}}if(!h){for(const f of[m.name,p,`${p}s`])if(f in c){h=p,N=c[f],x.add(f);break}}if(!h){for(const[f,y]of Object.entries(c))if(!x.has(f)&&y.length>0&&js(R,Object.keys(y[0]))){h=p,N=y,x.add(f);break}}h||(h=p),l[h]=N,o.push({label:m.name,dataKey:h,category:m.category,description:m.description,schemaFields:m.fields.map(f=>({name:f.name,type:f.type,isId:f.isId??!1}))})}for(const[m,p]of Object.entries(a))m==="_metadata"||m==="localStorage"||m==="seed"||m==="type"||S.has(m)||Array.isArray(p)&&(l[m]=p,o.push({label:m,dataKey:m}));for(const[m,p]of Object.entries(i))g.has(m)||(l[m]=p,o.push({label:m,dataKey:m}));for(const[m,p]of Object.entries(c))x.has(m)||(l[m]=p,o.push({label:m,dataKey:m}));return{data:l,tabs:o}}function wt(t){var c,i;const s=new Map,n=new Map;for(const l of t)if(l.componentName){const o=n.get(l.componentName)||[];o.push(l),n.set(l.componentName,o)}else if(bs(l.url)){const o=(c=l.url)==null?void 0:c.match(/[?&]c=([^&]+)/),x=o?decodeURIComponent(o[1]):"Isolated",S=n.get(x)||[];S.push(l),n.set(x,S)}else{const o=l.displayName||((i=l.pageFilePath)!=null&&i.startsWith("app/")?Oe(Re(l.pageFilePath)):Qe(l.url)),x=s.get(o)||[];x.push(l),s.set(o,x)}const a=new Map([...n.entries()].sort(([l],[o])=>l.localeCompare(o)));return{pageGroups:s,componentGroups:a}}function vs(t,s){var a,c;const n=new Map;for(const[i,l]of t){const o=(a=l.find(x=>x.entitySha))==null?void 0:a.entitySha;o&&n.set(i,o)}for(const[i,l]of s){const o=(c=l.find(x=>x.entitySha))==null?void 0:c.entitySha;o&&n.set(i,o)}return n}function Jn(t){const s=new Set;for(const[n,a]of Object.entries(t)){s.add(n);for(const c of a)s.add(c)}return s}function Kn(t,s,n,a){if(s.has(t))return!0;const c=n.find(i=>i.sha===t);return c?a.has(c.name):!1}function Gn(t,s,n,a){const c=[];for(const[i,l]of t){const o=n.get(i);o?a(o)||c.push({name:i,scenarios:l,reason:"incomplete"}):c.push({name:i,scenarios:l,reason:"missing"})}for(const[i,l]of s){const o=n.get(i);o?a(o)||c.push({name:i,scenarios:l,reason:"incomplete"}):c.push({name:i,scenarios:l,reason:"missing"})}return c}function rs(t,s,n){if(!t)return null;const a=s.find(c=>c.sha===t);return a?{sha:t,name:a.name,filePath:a.filePath,entityType:a.entityType,displayName:a.name}:null}const as=120;function Ns({text:t,theme:s}){const[n,a]=r.useState(!1),c=t.length>as,i=c&&!n?t.slice(0,as)+"…":t,l=s==="light";return e.jsxs("div",{className:`px-4 py-2 ${l?"border-b border-gray-200 bg-gray-50":"border-b border-[#3d3d3d] bg-[#252525]"}`,children:[e.jsx("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-gray-500",children:"User Prompt"}),e.jsxs("p",{className:`text-[11px] mt-0.5 mb-0 leading-relaxed ${l?"text-gray-600":"text-gray-400"}`,children:[i,c&&e.jsx("button",{onClick:()=>a(!n),className:`ml-1 text-[11px] font-medium bg-transparent border-none p-0 cursor-pointer ${l?"text-blue-500 hover:text-blue-700":"text-[#00a0c4] hover:text-[#00c0e8]"}`,children:n?"Show less":"Read more…"})]})]})}const is={new:0,edited:1,impacted:2};function os({status:t,onClick:s}){const n={new:{label:"New",bg:"bg-green-100",text:"text-green-700",border:"border-green-200"},edited:{label:"Edited",bg:"bg-blue-100",text:"text-blue-700",border:"border-blue-200"},impacted:{label:"Impacted",bg:"bg-amber-100",text:"text-amber-700",border:"border-amber-200"}}[t.status],a=s&&(t.status==="edited"||t.status==="impacted");return e.jsx("button",{onClick:a?s:void 0,className:`${n.bg} ${n.text} ${n.border} border text-[9px] font-bold px-1.5 py-0.5 rounded-full uppercase tracking-wider shrink-0 ${a?"cursor-pointer hover:opacity-80 transition-opacity":"cursor-default"}`,children:n.label})}function ls({filePath:t}){const[s,n]=r.useState(null),[a,c]=r.useState(!0),[i,l]=r.useState(null);return r.useEffect(()=>{Cn(()=>import("./index-DE3jI_dv.js"),__vite__mapDeps([0,1,2])).then(o=>{l(()=>o.default)})},[]),r.useEffect(()=>{c(!0),fetch(`/api/editor-file-diff?path=${encodeURIComponent(t)}`).then(o=>o.json()).then(o=>{n({oldContent:o.oldContent,newContent:o.newContent})}).catch(()=>{n(null)}).finally(()=>c(!1))},[t]),a?e.jsx("div",{className:"p-2 text-[10px] text-gray-400",children:"Loading diff..."}):!s||!i?e.jsx("div",{className:"p-2 text-[10px] text-gray-400",children:"Could not load diff"}):e.jsx("div",{className:"mt-2 border border-gray-200 rounded-lg overflow-hidden max-h-[300px] overflow-auto text-xs",children:e.jsx(i,{oldValue:s.oldContent,newValue:s.newContent,splitView:!1,useDarkTheme:!1,showDiffOnly:!0,styles:{contentText:{fontSize:"11px",lineHeight:"1.4"},line:{padding:"1px 8px",fontSize:"11px"}}})})}function cs({impactedBy:t,changedEntities:s}){return e.jsx("div",{className:"mt-2 bg-amber-50 border border-amber-200 rounded-lg p-2.5",children:t&&t.length>0?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[10px] font-semibold text-amber-700 uppercase tracking-wider",children:"Re-captured because these dependencies changed"}),e.jsx("ul",{className:"mt-1.5 space-y-1",children:t.map(n=>e.jsxs("li",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`text-[9px] font-bold px-1 py-0 rounded-full uppercase tracking-wider border ${n.changeType==="new"?"bg-green-100 text-green-700 border-green-200":"bg-blue-100 text-blue-700 border-blue-200"}`,children:n.changeType==="new"?"New":"Edited"}),e.jsx("span",{className:"text-[11px] font-medium text-amber-800",children:n.name}),e.jsx("span",{className:"text-[9px] text-amber-500 truncate",children:n.filePath})]},n.filePath))})]}):s&&s.length>0?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[10px] font-semibold text-amber-700 uppercase tracking-wider",children:"Unchanged — these entities were modified in this session"}),e.jsx("ul",{className:"mt-1.5 space-y-1",children:s.map(n=>e.jsxs("li",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`text-[9px] font-bold px-1 py-0 rounded-full uppercase tracking-wider border ${n.status==="new"?"bg-green-100 text-green-700 border-green-200":"bg-blue-100 text-blue-700 border-blue-200"}`,children:n.status==="new"?"New":"Edited"}),e.jsx("span",{className:"text-[11px] font-medium text-amber-800",children:n.name})]},n.name))})]}):e.jsx("span",{className:"text-[10px] text-amber-600",children:"This component was re-captured because a dependency changed"})})}function ds({scenarioId:t,name:s,isActive:n,onSelect:a,updatedAt:c}){const i=r.useRef(null);return r.useEffect(()=>{n&&i.current&&i.current.scrollIntoView({block:"nearest",behavior:"smooth"})},[n]),e.jsxs("button",{ref:i,onClick:a,className:"flex flex-col items-center gap-1.5 cursor-pointer group",title:s,children:[e.jsx("div",{className:`w-32 h-32 rounded-lg overflow-hidden border-2 transition-all ${n?"border-[#0ea5e9] ring-2 ring-[#0ea5e9]/40 shadow-lg shadow-[#0ea5e9]/20":"border-gray-200 hover:border-gray-400 shadow-sm"}`,children:e.jsx(_e,{scenarioId:t,updatedAt:c,alt:s,className:"w-full h-full bg-white",imgClassName:"w-full h-full object-contain bg-white"})}),e.jsx("span",{className:`text-[11px] leading-tight text-center truncate w-32 font-medium ${n?"text-gray-900":"text-gray-600 group-hover:text-gray-900"}`,children:s})]})}function Yn({filePath:t}){return t?e.jsxs("div",{className:"flex items-center gap-1 mt-0.5",children:[e.jsxs("a",{href:`/api/editor-file?path=${encodeURIComponent(t)}`,target:"_blank",rel:"noopener noreferrer",title:"Open file",className:"flex items-center gap-1 text-gray-400 hover:text-gray-600 transition-colors min-w-0",children:[e.jsx("span",{className:"text-[9px] truncate",children:t}),e.jsx("svg",{className:"shrink-0",width:"10",height:"10",viewBox:"0 0 12 12",fill:"none",children:e.jsx("path",{d:"M4.5 1.5H2.5C1.95 1.5 1.5 1.95 1.5 2.5V9.5C1.5 10.05 1.95 10.5 2.5 10.5H9.5C10.05 10.5 10.5 10.05 10.5 9.5V7.5M7.5 1.5H10.5M10.5 1.5V4.5M10.5 1.5L5 7",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})})]}),e.jsx(Te,{content:t,icon:!0,iconSize:10,className:"shrink-0 text-gray-400 hover:text-gray-600 transition-colors"})]}):null}function vt({testFile:t,entityName:s}){const{results:n,isRunning:a,runTests:c}=Nt(t);if(a&&!n)return e.jsxs("div",{className:"pt-1 flex items-center gap-1.5",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-[#0ea5e9] animate-pulse"}),e.jsx("span",{className:"text-[10px] text-gray-400",children:"Running tests..."})]});if(!n)return null;if(n.status==="error")return e.jsx("div",{className:"pt-1",children:e.jsx("span",{className:"text-[10px] text-red-500",children:n.errorMessage})});const i=s?n.testCases.filter(x=>x.fullName.startsWith(s)):n.testCases,l=i.length>0?i:n.testCases;if(l.length===0)return null;const o=s?`${s} > `:"";return e.jsxs("div",{className:"pt-1 space-y-0.5",children:[l.map(x=>{var g;const S=o&&x.fullName.startsWith(o)?x.fullName.slice(o.length):x.fullName;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[x.status==="passed"?e.jsx("span",{className:"text-green-600 text-[10px]",children:"✓"}):x.status==="failed"?e.jsx("span",{className:"text-red-500 text-[10px]",children:"✗"}):e.jsx("span",{className:"text-gray-400 text-[10px]",children:"—"}),e.jsx("span",{className:`text-[10px] ${x.status==="passed"?"text-green-600":x.status==="failed"?"text-red-500":"text-gray-400"}`,children:S})]}),x.status==="failed"&&((g=x.failureMessages)==null?void 0:g.map((m,p)=>e.jsx("div",{className:"pl-4 text-[9px] text-red-400 truncate max-w-full",title:m,children:m.split(`
4
- `)[0]},p)))]},x.fullName)}),e.jsx("button",{onClick:c,disabled:a,className:"mt-1 text-[10px] text-[#0ea5e9] hover:text-[#38bdf8] transition-colors cursor-pointer disabled:opacity-50 bg-transparent border-none p-0",children:a?"Running...":"Re-run"})]})}function xs(t){const s=t.indexOf(" - ");return s!==-1?t.slice(s+3):t}function us(t,s){return!s||Object.keys(s).length===0?t:[...t].sort(([n],[a])=>{var o,x;const c=((o=s[n])==null?void 0:o.status)||"impacted",i=((x=s[a])==null?void 0:x.status)||"impacted",l=(is[c]??2)-(is[i]??2);return l!==0?l:n.localeCompare(a)})}function qn({scenarios:t,allScenarios:s=[],glossaryFunctions:n=[],projectRoot:a,activeScenarioId:c,onScenarioSelect:i,onClose:l,entityChangeStatus:o={},modifiedFiles:x=[],featureName:S,userPrompt:g}){const m=r.useMemo(()=>{if(s.length===0||Object.keys(o).length===0)return t;const w=new Set(t.map(F=>F.id)),k=s.filter(F=>{var I,V;if(w.has(F.id))return!1;const M=F.componentName||F.displayName||((I=F.pageFilePath)!=null&&I.startsWith("app/")?Oe(Re(F.pageFilePath)):Qe(F.url));return((V=o[M])==null?void 0:V.status)==="impacted"});return k.length===0?t:[...t,...k]},[t,s,o]),p=r.useMemo(()=>Object.entries(o).filter(([,w])=>w.status==="new"||w.status==="edited").map(([w,k])=>({name:w,status:k.status})),[o]),[R,h]=r.useState(null),N=r.useCallback(w=>{h(k=>k===w?null:w)},[]),{pageGroups:f,componentGroups:y}=r.useMemo(()=>wt(m),[m]),E=r.useMemo(()=>us([...f.entries()],o),[f,o]),C=r.useMemo(()=>us([...y.entries()],o),[y,o]),O=E,J=C,Z=r.useMemo(()=>Fn(n,o),[n,o]),B=r.useMemo(()=>{const w=[];for(const[,k]of O)w.push(...k);for(const[,k]of J)w.push(...k);return w},[O,J]),q=r.useRef(!1);return r.useEffect(()=>{q.current||B.length!==0&&(q.current=!0,console.log("[ResultsPanel] Auto-selecting first scenario: %s",B[0].name),i(B[0]))},[B,i]),r.useEffect(()=>{if(B.length===0)return;const w=k=>{if(k.key!=="ArrowLeft"&&k.key!=="ArrowRight")return;const F=k.target,M=F==null?void 0:F.tagName;if(M==="INPUT"||M==="SELECT"||M==="TEXTAREA"&&!F.classList.contains("xterm-helper-textarea"))return;k.preventDefault();const I=B.findIndex(W=>W.id===c);let V;k.key==="ArrowLeft"?V=I<=0?B.length-1:I-1:V=I>=B.length-1?0:I+1,i(B[V])};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[B,c,i]),m.length===0&&n.length===0?e.jsxs("div",{className:"h-full bg-white flex items-center justify-center relative",children:[e.jsx("button",{onClick:l,className:"absolute top-2 right-3 text-gray-400 hover:text-gray-700 text-lg leading-none cursor-pointer bg-transparent border-none",title:"Close results",children:"×"}),e.jsx("span",{className:"text-sm text-gray-400",children:"No scenarios registered yet"})]}):e.jsxs("div",{className:"h-full bg-white flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5 border-b border-gray-200 shrink-0",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:"Working Session Results"}),S&&e.jsx("div",{className:"text-[11px] text-gray-400 truncate",title:S,children:S})]}),e.jsx("button",{onClick:l,className:"text-gray-400 hover:text-gray-700 text-lg leading-none cursor-pointer bg-transparent border-none shrink-0",title:"Close results",children:"×"})]}),g&&e.jsx(Ns,{text:g,theme:"light"}),e.jsx("div",{className:"flex-1 overflow-auto p-4",children:e.jsxs("div",{className:"space-y-5",children:[O.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"mb-2",children:e.jsx("span",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:"Application"})}),e.jsx("div",{className:"space-y-3 pl-1",children:O.map(([w,k])=>{var V;const F=o[w],M=R===w,I=(V=k[0])==null?void 0:V.componentPath;return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-2",children:[e.jsx("span",{className:"text-[11px] font-medium text-gray-600",children:w}),F&&e.jsx(os,{status:F,onClick:()=>N(w)})]}),M&&(F==null?void 0:F.status)==="edited"&&I&&e.jsx(ls,{filePath:I}),M&&(F==null?void 0:F.status)==="impacted"&&e.jsx(cs,{impactedBy:F.impactedBy,changedEntities:p}),e.jsx("div",{className:"flex flex-wrap gap-3",children:k.map(W=>e.jsx(ds,{scenarioId:W.id,name:xs(W.name),isActive:W.id===c,onSelect:()=>i(W),updatedAt:W.updatedAt},W.id))})]},w)})})]}),J.length>0&&e.jsxs("div",{className:O.length>0?"pt-3 border-t border-gray-200":"",children:[e.jsx("div",{className:"mb-2",children:e.jsx("span",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:"Components"})}),e.jsx("div",{className:"space-y-3 pl-1",children:J.map(([w,k])=>{var V;const F=o[w],M=R===w,I=(V=k[0])==null?void 0:V.componentPath;return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-2",children:[e.jsx("span",{className:"text-[11px] font-medium text-gray-600",children:w}),F&&e.jsx(os,{status:F,onClick:()=>N(w)})]}),M&&(F==null?void 0:F.status)==="edited"&&I&&e.jsx(ls,{filePath:I}),M&&(F==null?void 0:F.status)==="impacted"&&e.jsx(cs,{impactedBy:F.impactedBy,changedEntities:p}),e.jsx("div",{className:"flex flex-wrap gap-3",children:k.map(W=>e.jsx(ds,{scenarioId:W.id,name:xs(W.name),isActive:W.id===c,onSelect:()=>i(W),updatedAt:W.updatedAt},W.id))})]},w)})})]}),Z.length>0&&e.jsxs("div",{className:O.length>0||J.length>0?"pt-3 border-t border-gray-200":"",children:[e.jsx("div",{className:"mb-2",children:e.jsx("span",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:"Functions"})}),e.jsx("div",{className:"space-y-2 pl-1",children:Z.map(w=>e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"text-[11px] font-medium text-gray-700",children:w.name})}),e.jsx(Yn,{filePath:w.filePath,projectRoot:a}),w.testFile?e.jsx(vt,{testFile:w.testFile,entityName:w.name}):e.jsx("div",{className:"pt-1",children:e.jsx("span",{className:"text-[10px] text-gray-400",children:"No test file"})})]},w.name))})]}),x.length>0&&e.jsxs("div",{className:O.length>0||J.length>0||Z.length>0?"pt-3 border-t border-gray-200":"",children:[e.jsx("div",{className:"mb-2",children:e.jsxs("span",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:["Modified Files (",x.length,")"]})}),e.jsx("div",{className:"space-y-0.5 pl-1 max-h-[200px] overflow-auto",children:x.map(w=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`text-[9px] font-bold uppercase w-[14px] text-center ${w.status==="added"||w.status==="untracked"?"text-green-600":w.status==="modified"?"text-blue-600":w.status==="renamed"?"text-purple-600":"text-gray-400"}`,children:w.status==="added"||w.status==="untracked"?"A":w.status==="modified"?"M":w.status==="renamed"?"R":"?"}),e.jsx("span",{className:"text-[10px] text-gray-500 truncate font-mono",children:w.path})]},w.path))})]})]})})]})}function ms(t,s,n,a){var x;const c=a.length>0?a.map(S=>`- "${S.name}" (ID: ${S.id})${S.url?` — URL: ${S.url}`:""}`).join(`
2
+ var or=Object.defineProperty;var lr=(t,s,r)=>s in t?or(t,s,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[s]=r;var ns=(t,s,r)=>lr(t,typeof s!="symbol"?s+"":s,r);import{r as n,w as cr,u as dr,b as xr,a as ur,c as mr,O as hr}from"./chunk-JZWAC4HX-BAdwhyCx.js";import{j as e}from"./jsx-runtime-D_zvdyIk.js";import{u as pr,C as fr}from"./useCustomSizes-DhXHbEjP.js";import{g as Ge,s as gr,r as yt,b as Me,c as br,l as yr,d as jr,e as vr,f as Nr,a as wr,T as Sr,D as kr}from"./editorPreview-CluPkvXJ.js";import{C as Te}from"./CopyButton-CLe80MMu.js";import{M as $e}from"./MiniClaudeChat-CQENLSrF.js";import{_ as Cr}from"./preload-helper-ckwbz45p.js";import{c as Pr}from"./cy-logo-cli-Coe5NhbS.js";import{u as Er,S as jt}from"./Spinner-Bc8BG-Lw.js";import"./copy-C6iF61Xs.js";import"./createLucideIcon-4ImjHTVC.js";import"./useLastLogLine-D9QZKaLJ.js";function Re(t){var o;if(!t.startsWith("app/")&&!t.startsWith("("))return"/";const r=t.replace(/^app\//,"").split("/"),a=r.pop(),c=((o=a.match(/\.(tsx?|jsx?|js)$/))==null?void 0:o[0])||"",i=a.slice(0,-c.length);let l;return i==="page"||i==="index"?l=r:l=[...r,i],l=l.filter(x=>!x.startsWith("(")),l.length===0?"/":"/"+l.join("/")}function Oe(t){return t==="/"?"Home":t.replace(/^\//,"").split("/").map(r=>r.startsWith("[")?r:r.charAt(0).toUpperCase()+r.slice(1)).join(" / ")}function Ze(t){if(!t||t==="/")return"Home";const s=t.split("?")[0].replace(/^\//,"");if(!s)return"Home";const r=s.split("/")[0].replace(/\.[^.]+$/,"");return r.charAt(0).toUpperCase()+r.slice(1)}function ys(t){return t?t.includes("/isolated-components")||t.includes("/codeyam-isolate"):!1}function Fr(t,s){return!s||Object.keys(s).length===0?t:t.filter(r=>s[r.name])}const Qe=[{name:"Desktop",width:1440,height:900},{name:"Laptop",width:1024,height:768},{name:"Tablet",width:768,height:1024},{name:"Mobile",width:375,height:667}];function Dr(t){if(!t)return Qe;const s=Object.entries(t).map(([a,c])=>({name:a,width:c.width,height:c.height})),r=new Set(s.map(a=>a.name));return[...s,...Qe.filter(a=>!r.has(a.name))]}function Tr({featureName:t,editorStep:s,editorStepLabel:r,onContinue:a}){const c=n.useCallback(i=>{i.key==="Enter"&&(i.preventDefault(),a())},[a]);return n.useEffect(()=>(window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)),[c]),e.jsx("div",{className:"flex items-center justify-center h-full bg-[#1e1e1e] text-[#d4d4d4]",children:e.jsxs("div",{className:"max-w-md w-full mx-4 p-6 bg-[#252526] border border-[#3d3d3d] rounded-lg",children:[e.jsx("h2",{className:"text-lg font-semibold mb-3 text-white",children:"Resume Previous Session?"}),e.jsx("p",{className:"text-sm text-[#999] mb-4",children:"An editor session is still in progress:"}),e.jsxs("div",{className:"bg-[#1e1e1e] rounded p-3 mb-5 text-sm",children:[t&&e.jsxs("div",{className:"mb-1",children:[e.jsx("span",{className:"text-[#999]",children:"Feature:"})," ",e.jsx("span",{className:"text-white",children:t})]}),s!=null&&r&&e.jsxs("div",{children:[e.jsx("span",{className:"text-[#999]",children:"Step:"})," ",e.jsxs("span",{className:"text-white",children:[s," (",r,")"]})]})]}),e.jsx("button",{onClick:a,className:"w-full px-4 py-2 text-sm rounded transition-colors cursor-pointer bg-[#005c75] text-white font-medium hover:bg-[#004d63] ring-2 ring-white/50",children:"Continue Session"})]})})}const Lr={1:"Plan",2:"Prepare",3:"Prototype",4:"Verify Prototype",5:"Confirm",6:"Deconstruct",7:"Extract",8:"Glossary",9:"Analyze",10:"App Scenarios",11:"User Scenarios",12:"Verify",13:"Journal",14:"Review",15:"Present",16:"Commit",17:"Finalize",18:"Push"},Mr={1:"Plan the feature and confirm the approach with the user before writing any code.",2:"Prepare the project environment and dependencies for prototyping.",3:"Build a working prototype quickly to validate the concept.",4:"Verify the prototype works correctly and fix any issues.",5:"Confirm the prototype looks right and get user approval to proceed.",6:"Read the code and plan all component and function extractions.",7:"Extract components and functions via TDD — components first, then functions.",8:"Record all extracted functions and components in the glossary.",9:"Analyze imports and verify all components are captured correctly.",10:"Create app-level scenarios that show full pages with realistic data.",11:"Create user-persona scenarios that exercise the app from different perspectives.",12:"Review all screenshots and check for visual errors or regressions.",13:"Create or update the journal entry documenting what was built.",14:"Final review of screenshots, audit for completeness.",15:"Present a summary of all work to the user for approval.",16:"Commit all changes to git.",17:"Update the journal with final details and amend the commit.",18:"Push the branch to the remote repository."},Ar={1:"Survey",2:"App Scenarios",3:"Component Scenarios",4:"Preview",5:"Discuss",6:"Decompose",7:"Extract",8:"Recapture",9:"Journal",10:"Present"},Ir={1:"Survey the existing codebase to understand pages, components, and dependencies.",2:"Create app-level scenarios showing full pages with realistic data.",3:"Create component-level scenarios for isolated component previews.",4:"Preview all captured scenarios and verify they look correct.",5:"Discuss the migration plan and prioritize which pages to decompose.",6:"Plan the decomposition of pages into clean, reusable components.",7:"Extract components and functions with tests via TDD.",8:"Recapture scenarios after extraction to verify nothing broke.",9:"Document the migration progress in a journal entry.",10:"Present the migration results for review and approval."},$r=18,Rr=10;function Or({projectTitle:t,featureName:s,editorStep:r,editorStepLabel:a,migrationMode:c}){const[i,l]=n.useState(!1),[o,x]=n.useState(null),S=n.useRef(null);n.useEffect(()=>{if(!i)return;const y=E=>{S.current&&!S.current.contains(E.target)&&l(!1)};return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[i]);const b=s&&r!=null,m=c==="active",p=m?Ar:Lr,R=m?Ir:Mr,h=m?Rr:$r,N=b?a||p[r]||"?":null,f=s||"New Working Session";return e.jsxs("div",{className:"h-8 shrink-0 flex items-center justify-between px-3 bg-[#2a2a2a] border-b border-[#333] text-xs select-none",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"text-[#888] truncate",children:t||"New Project"}),e.jsx("span",{className:"text-[#555]",children:">"}),e.jsx("span",{className:"text-[#ccc] font-medium truncate",children:f})]}),b&&e.jsxs("div",{className:"relative",ref:S,children:[e.jsxs("button",{onClick:()=>l(y=>!y),className:"flex items-center gap-1.5 text-[#ccc] hover:text-white transition-colors cursor-pointer",children:[e.jsx("span",{className:"text-[#555]",children:"::"}),e.jsxs("span",{children:["Step ",r,e.jsxs("span",{className:"text-[#888]",children:[" / ",h]}),":"," ",N]}),e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",className:`transition-transform ${i?"rotate-180":""}`,children:e.jsx("path",{d:"M2 4l3 3 3-3"})})]}),i&&e.jsx("div",{className:"absolute right-0 top-full mt-1 w-48 bg-[#2d2d2d] border border-[#444] rounded-lg shadow-lg z-30 py-1",children:Array.from({length:h},(y,E)=>E+1).map(y=>{const E=y===r,P=y<r,O=o===y,J=R[y];return e.jsxs("div",{onClick:()=>x(O?null:y),className:"cursor-pointer",children:[e.jsxs("div",{className:`w-full px-3 py-1 flex items-center gap-2 text-left transition-colors hover:bg-[#383838] ${E?"text-cygreen font-medium":P?"text-[#ccc]":"text-[#999]"}`,children:[e.jsxs("span",{className:"w-5 text-right tabular-nums shrink-0",children:[y,"."]}),e.jsx("span",{className:"flex-1",children:p[y]||`Step ${y}`}),J&&e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",className:`shrink-0 opacity-40 transition-transform ${O?"rotate-180":""}`,children:e.jsx("path",{d:"M2 4l3 3 3-3"})})]}),O&&J&&e.jsx("div",{className:"px-3 pb-1.5 pl-10",children:e.jsx("p",{className:"text-[10px] text-[#888] m-0 leading-relaxed",children:J})})]},y)})})]})]})}function wt(t){const[s,r]=n.useState(null),[a,c]=n.useState(!1),i=n.useCallback(()=>{t&&(c(!0),fetch(`/api/editor-test-results?testFile=${encodeURIComponent(t)}`).then(l=>l.json()).then(l=>{r(l),c(!1)}).catch(()=>{r({testFilePath:t,status:"error",testCases:[],errorMessage:"Failed to fetch test results"}),c(!1)}))},[t]);return{results:s,isRunning:a,runTests:i}}function _e({scenarioId:t,updatedAt:s,alt:r,className:a="",imgClassName:c=""}){const[i,l]=n.useState(!1),o=`/api/editor-scenario-image/${t}.png${s?`?v=${encodeURIComponent(s)}`:""}`;return n.useEffect(()=>{l(!1)},[t]),i?e.jsx("div",{className:`flex items-center justify-center ${a}`,children:e.jsx("span",{className:"text-[8px] text-gray-500",children:"No img"})}):e.jsx("div",{className:a,children:e.jsx("img",{src:o,alt:r,className:c,loading:"lazy",onError:()=>l(!0)})})}function Ae({scenarioId:t,updatedAt:s,hasScreenshot:r,imgSrc:a,name:c,isActive:i,onSelect:l}){const o=t&&r,x=!t&&a;return e.jsxs("button",{onClick:l,className:"flex flex-col items-center gap-1 cursor-pointer group w-full",title:c,children:[e.jsx("div",{className:`w-full aspect-[16/10] rounded overflow-hidden border-2 transition-all bg-[#1a1a1a] ${i?"border-[#D7FF63]/40 ring-1 ring-[#D7FF63]/20":"border-transparent hover:border-[#4d4d4d]"}`,children:o?e.jsx(_e,{scenarioId:t,updatedAt:s,alt:c,className:"w-full h-full",imgClassName:"w-full h-full object-contain"}):x?e.jsx("img",{src:a,alt:c,className:"w-full h-full object-contain",loading:"lazy"}):e.jsx("div",{className:"w-full h-full bg-[#1a1a1a] flex items-center justify-center",children:e.jsx("span",{className:"text-[8px] text-gray-600",children:"No img"})})}),e.jsx("span",{className:`text-[10px] leading-tight text-center truncate w-full ${i?"text-white":"text-gray-500 group-hover:text-gray-300"}`,children:c})]})}function vt({testFile:t,entityName:s}){const{results:r,isRunning:a,runTests:c}=wt(t);if(a&&!r)return e.jsxs("div",{className:"px-2 pt-1 flex items-center gap-1.5",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-[#005c75] animate-pulse"}),e.jsx("span",{className:"text-[10px] text-gray-400",children:"Running tests..."})]});if(!r)return null;if(r.status==="error")return e.jsx("div",{className:"px-2 pt-1",children:e.jsx("span",{className:"text-[10px] text-red-400",children:r.errorMessage})});const i=s?r.testCases.filter(x=>x.fullName.startsWith(s)):r.testCases,l=i.length>0?i:r.testCases;if(l.length===0)return null;const o=s?`${s} > `:"";return e.jsxs("div",{className:"px-2 pt-1 space-y-0.5",children:[l.map(x=>{var b;const S=o&&x.fullName.startsWith(o)?x.fullName.slice(o.length):x.fullName;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[x.status==="passed"?e.jsx("span",{className:"text-green-400 text-[10px]",children:"✓"}):x.status==="failed"?e.jsx("span",{className:"text-red-400 text-[10px]",children:"✗"}):e.jsx("span",{className:"text-gray-500 text-[10px]",children:"—"}),e.jsx("span",{className:`text-[10px] ${x.status==="passed"?"text-green-400":x.status==="failed"?"text-red-400":"text-gray-500"}`,children:S})]}),x.status==="failed"&&((b=x.failureMessages)==null?void 0:b.map((m,p)=>e.jsx("div",{className:"pl-4 text-[9px] text-red-300/70 truncate max-w-full",title:m,children:m.split(`
3
+ `)[0]},p)))]},x.fullName)}),e.jsx("button",{onClick:c,disabled:a,className:"mt-1 text-[10px] text-[#00a0c4] hover:text-[#00c4ee] transition-colors cursor-pointer disabled:opacity-50 bg-transparent border-none p-0",children:a?"Running...":"Re-run"})]})}function Ie({filePath:t}){return t?e.jsxs("div",{className:"flex items-center gap-1 px-2 mt-0.5",children:[e.jsxs("a",{href:`/api/editor-file?path=${encodeURIComponent(t)}`,target:"_blank",rel:"noopener noreferrer",title:"Open file",className:"flex items-center gap-1 text-gray-500 hover:text-gray-300 transition-colors min-w-0",children:[e.jsx("span",{className:"text-[9px] truncate",children:t}),e.jsx("svg",{className:"shrink-0",width:"10",height:"10",viewBox:"0 0 12 12",fill:"none",children:e.jsx("path",{d:"M4.5 1.5H2.5C1.95 1.5 1.5 1.95 1.5 2.5V9.5C1.5 10.05 1.95 10.5 2.5 10.5H9.5C10.05 10.5 10.5 10.05 10.5 9.5V7.5M7.5 1.5H10.5M10.5 1.5V4.5M10.5 1.5L5 7",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})})]}),e.jsx(Te,{content:t,icon:!0,iconSize:10,className:"shrink-0 text-gray-500 hover:text-gray-300 transition-colors"})]}):null}function _r({scenarios:t,projectRoot:s,activeScenarioId:r,onScenarioSelect:a,zoomComponent:c,focusedEntity:i,onZoomChange:l,analyzedEntities:o=[],glossaryFunctions:x=[],activeAnalyzedScenarioId:S,onAnalyzedScenarioSelect:b,entityImports:m,pageFilePaths:p={},onSwitchToBuild:R,entityShaMap:h,structureTab:N="application",onStructureTabChange:f}){const[y,E]=n.useState(""),[P,O]=n.useState(N),J=f?N:P,Z=f||O,{pageGroups:B,componentGroups:q}=n.useMemo(()=>{var j;const v=new Map,A=new Map;for(const D of t)if(D.componentName){const T=A.get(D.componentName)||[];T.push(D),A.set(D.componentName,T)}else if(ys(D.url)){const T=(j=D.url)==null?void 0:j.match(/[?&]c=([^&]+)/),U=T?decodeURIComponent(T[1]):"Isolated",Q=A.get(U)||[];Q.push(D),A.set(U,Q)}else{const T=D.pageFilePath?Oe(Re(D.pageFilePath)):Ze(D.url),U=v.get(T)||[];U.push(D),v.set(T,U)}const _=new Map([...A.entries()].sort(([D],[T])=>D.localeCompare(T)));return{pageGroups:v,componentGroups:_}},[t]),w=n.useMemo(()=>{const v=new Set((o||[]).filter(_=>_.entityType==="visual").map(_=>_.name)),A=new Map;for(const[_,j]of q)v.has(_)||A.set(_,j);return A},[q,o]),{visualEntities:k,libraryEntities:F}=n.useMemo(()=>{const v=o.filter(_=>_.entityType==="visual").sort((_,j)=>_.name.localeCompare(j.name)),A=o.filter(_=>_.entityType==="library"||_.entityType==="functionCall").sort((_,j)=>_.name.localeCompare(j.name));return{visualEntities:v,libraryEntities:A}},[o]),M=n.useMemo(()=>{const v=new Set(F.map(A=>A.name));return x.filter(A=>!v.has(A.name)).sort((A,_)=>A.name.localeCompare(_.name))},[x,F]),I=o.some(v=>v.isAnalyzing),V=n.useRef(null),W=n.useRef(0),ce=n.useCallback(()=>{V.current&&(W.current=V.current.scrollTop)},[]);if(n.useEffect(()=>{V.current&&W.current>0&&(V.current.scrollTop=W.current)}),t.length===0&&o.length===0&&M.length===0)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center text-gray-500 px-8",children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:"No scenarios yet"}),e.jsx("p",{className:"text-xs",children:"Scenarios will appear here as Claude creates them alongside your code. Each scenario represents a different state of your app's data."})]})});if(c&&i){const v=i.name,A=i.filePath,_=i.sha,j=t.filter($=>$.componentName===v||$.componentPath===A||!$.componentName&&($.pageFilePath===A||_&&$.entitySha===_)),D=new Set((m==null?void 0:m[v])||[]),T=D.size>0,U=T?k.filter($=>D.has($.name)):[],Q=T?F.filter($=>D.has($.name)):[];return e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsxs("div",{className:"p-3 space-y-1",children:[e.jsxs("button",{onClick:()=>l(void 0),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-gray-400 hover:text-white transition-colors cursor-pointer",children:[e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:"shrink-0",children:e.jsx("path",{d:"M7.5 9L4.5 6L7.5 3",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),"All scenarios"]}),e.jsx("div",{className:"px-3 py-1.5",children:e.jsx("span",{className:"text-xs font-semibold text-white uppercase tracking-wider",children:i.displayName})}),e.jsx("div",{className:"flex flex-wrap gap-2 px-2",children:j.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-gray-500",children:"No scenarios for this component"}):j.map($=>e.jsx(Ae,{scenarioId:$.id,updatedAt:$.updatedAt,hasScreenshot:!!$.screenshotPath,name:$.name,isActive:$.id===r,onSelect:()=>a($)},$.id))}),U.length>0&&e.jsxs("div",{className:"pt-2 mt-1 border-t border-[#3d3d3d]",children:[e.jsx("div",{className:"px-2 py-1",children:e.jsx("span",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:"Components"})}),U.map($=>e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"flex items-center gap-2 px-2 py-1",children:e.jsx("button",{onClick:()=>l($.name),className:"text-[11px] font-medium text-gray-400 truncate cursor-pointer hover:text-white transition-colors bg-transparent border-none p-0",children:$.name})}),e.jsx(Ie,{filePath:$.filePath,projectRoot:s}),($.scenarios.length>0||$.pendingScenarios.length>0)&&e.jsx("div",{className:"flex flex-wrap gap-2 px-2 pt-1",children:$.scenarios.map(L=>e.jsx(Ae,{imgSrc:L.screenshotPath?`/api/screenshot/${L.screenshotPath}`:null,name:L.name,isActive:L.id===S,onSelect:()=>b==null?void 0:b({analysisId:$.analysisId,scenarioId:L.id,scenarioName:L.name,entitySha:$.sha,entityName:$.name})},L.id))})]},$.sha))]}),Q.length>0&&e.jsxs("div",{className:"pt-2 mt-1",children:[e.jsx("div",{className:"px-2 py-1",children:e.jsx("span",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:"Functions"})}),Q.map($=>e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"px-2 py-1",children:e.jsx("span",{className:"text-[11px] font-medium text-gray-300",children:$.name})}),e.jsx(Ie,{filePath:$.filePath,projectRoot:s}),$.testFile&&e.jsx(vt,{testFile:$.testFile,entityName:$.name})]},$.sha))]})]})})}return e.jsx("div",{ref:V,onScroll:ce,className:"flex-1 overflow-auto font-['IBM_Plex_Sans']",children:e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3 font-['IBM_Plex_Mono']",children:[e.jsx("button",{onClick:()=>Z("application"),className:`text-xs font-bold uppercase tracking-wider shrink-0 bg-transparent border-none cursor-pointer p-0 transition-colors ${J==="application"?"text-white":"text-gray-500 hover:text-gray-300"}`,children:"Application"}),e.jsx("button",{onClick:()=>Z("components"),className:`text-xs font-bold uppercase tracking-wider shrink-0 bg-transparent border-none cursor-pointer p-0 transition-colors ${J==="components"?"text-white":"text-gray-500 hover:text-gray-300"}`,children:"Components"}),e.jsx("div",{className:"flex-1"}),e.jsxs("div",{className:"relative",style:{width:170},children:[e.jsxs("svg",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-500",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("path",{d:"M21 21l-4.35-4.35"})]}),e.jsx("input",{type:"text",placeholder:"SEARCH...",value:y,onChange:v=>E(v.target.value),className:"w-full pl-9 pr-3 py-2 text-xs bg-[#2a2a2a] border border-[#3d3d3d] rounded-md text-gray-300 placeholder-gray-600 outline-none focus:border-[#D7FF63]/50 transition-colors tracking-wider"})]}),R&&e.jsxs("button",{onClick:R,className:"flex items-center gap-1.5 px-4 py-2 text-xs font-semibold text-[#1e1e1e] bg-[#D7FF63] rounded-md hover:bg-[#D7FF63]/80 transition-colors cursor-pointer shrink-0 uppercase tracking-wider",children:[e.jsx("span",{children:"+"})," New Feature"]})]}),e.jsx("div",{className:"border-b border-[#2d2d2d]"}),J==="application"&&B.size>0&&e.jsx("div",{children:[...B.entries()].sort(([v],[A])=>v==="Home"?-1:A==="Home"?1:v.localeCompare(A)).filter(([v])=>y.trim()?v.toLowerCase().includes(y.trim().toLowerCase()):!0).map(([v,A])=>{const _=A.some(j=>j.id===r&&!S);return e.jsxs("div",{className:"mt-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 py-1",children:[e.jsxs("button",{onClick:()=>l(v,h==null?void 0:h.get(v)),className:`flex items-center gap-1.5 text-sm font-normal cursor-pointer hover:text-white transition-colors bg-transparent border-none p-0 ${_?"text-[#D7FF63]":"text-gray-300"}`,children:[v,e.jsxs("span",{className:`text-xs ${_?"text-[#D7FF63]/60":"text-gray-500"}`,children:["(",A.length,")"]}),e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 12 12",fill:"none",className:_?"text-[#D7FF63]/60":"text-gray-500",children:e.jsx("path",{d:"M4.5 3L7.5 6L4.5 9",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]}),_&&e.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[e.jsx("button",{onClick:()=>l(v,h==null?void 0:h.get(v)),className:"p-1.5 rounded-md bg-[#3d3d3d] hover:bg-[#4d4d4d] text-gray-300 hover:text-white transition-colors cursor-pointer border-none",title:"Edit scenarios",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),e.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})}),R&&e.jsx("button",{onClick:R,className:"p-1.5 rounded-md bg-[#3d3d3d] hover:bg-[#4d4d4d] text-gray-300 hover:text-white transition-colors cursor-pointer border-none",title:"Add scenario",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-2 pt-1",children:A.map(j=>e.jsx(Ae,{scenarioId:j.id,updatedAt:j.updatedAt,hasScreenshot:!!j.screenshotPath,name:j.name,isActive:j.id===r&&!S,onSelect:()=>a(j)},j.id))})]},v)})}),J==="components"&&w.size>0&&e.jsx("div",{children:[...w.entries()].filter(([v])=>y.trim()?v.toLowerCase().includes(y.trim().toLowerCase()):!0).map(([v,A])=>{const _=A.some(j=>j.id===r&&!S);return e.jsxs("div",{className:"mt-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 py-1",children:[e.jsxs("button",{onClick:()=>l(v,h==null?void 0:h.get(v)),className:`flex items-center gap-1.5 text-sm font-normal cursor-pointer hover:text-white transition-colors bg-transparent border-none p-0 ${_?"text-[#D7FF63]":"text-gray-300"}`,children:[v,e.jsxs("span",{className:`text-xs ${_?"text-[#D7FF63]/60":"text-gray-500"}`,children:["(",A.length,")"]}),e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 12 12",fill:"none",className:_?"text-[#D7FF63]/60":"text-gray-500",children:e.jsx("path",{d:"M4.5 3L7.5 6L4.5 9",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]}),_&&e.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[e.jsx("button",{onClick:()=>l(v,h==null?void 0:h.get(v)),className:"p-1.5 rounded-md bg-[#3d3d3d] hover:bg-[#4d4d4d] text-gray-300 hover:text-white transition-colors cursor-pointer border-none",title:"Edit scenarios",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),e.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})}),R&&e.jsx("button",{onClick:R,className:"p-1.5 rounded-md bg-[#3d3d3d] hover:bg-[#4d4d4d] text-gray-300 hover:text-white transition-colors cursor-pointer border-none",title:"Add scenario",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-2 pt-1",children:A.map(j=>e.jsx(Ae,{scenarioId:j.id,updatedAt:j.updatedAt,hasScreenshot:!!j.screenshotPath,name:j.name,isActive:j.id===r&&!S,onSelect:()=>a(j)},j.id))})]},v)})}),k.length>0&&e.jsxs("div",{className:"pt-2 mt-1 border-t border-[#3d3d3d]",children:[e.jsxs("div",{className:"px-2 py-1",children:[e.jsx("span",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:"Components"}),I&&t.length===0&&o.every(v=>v.scenarioCount===0)&&e.jsx("span",{className:"ml-2 text-[10px] text-gray-500",children:"— Entities are being analyzed..."})]}),k.map(v=>e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1",children:[e.jsx("button",{onClick:()=>l(v.name),className:"text-[11px] font-medium text-gray-400 truncate cursor-pointer hover:text-white transition-colors bg-transparent border-none p-0",children:v.name}),v.isAnalyzing&&v.scenarioCount===0&&e.jsxs("span",{className:"flex items-center gap-1.5 text-[10px] text-gray-400",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-[#005c75] animate-pulse"}),"Analyzing..."]})]}),e.jsx(Ie,{filePath:v.filePath,projectRoot:s}),(v.scenarios.length>0||v.pendingScenarios.length>0)&&e.jsxs("div",{className:"flex flex-wrap gap-2 px-2 pt-1",children:[v.scenarios.map(A=>e.jsx(Ae,{imgSrc:A.screenshotPath?`/api/screenshot/${A.screenshotPath}`:null,name:A.name,isActive:A.id===S,onSelect:()=>b==null?void 0:b({analysisId:v.analysisId,scenarioId:A.id,scenarioName:A.name,entitySha:v.sha,entityName:v.name})},A.id)),v.pendingScenarios.map(A=>e.jsx("div",{className:"px-2.5 py-1 bg-[#2a2a2a] text-gray-400 text-[10px] rounded-full",title:A,children:A},A))]})]},v.sha))]}),(F.length>0||M.length>0)&&e.jsxs("div",{className:`pt-2 mt-1 ${k.length>0?"":"border-t border-[#3d3d3d]"}`,children:[e.jsx("div",{className:"px-2 py-1",children:e.jsx("span",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:"Functions"})}),F.map(v=>e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"px-2 py-1",children:[e.jsx("span",{className:"text-[11px] font-medium text-gray-300",children:v.name}),v.isAnalyzing&&v.scenarioCount===0&&e.jsxs("span",{className:"ml-2 inline-flex items-center gap-1.5 text-[10px] text-gray-400",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-[#005c75] animate-pulse"}),"Analyzing..."]})]}),e.jsx(Ie,{filePath:v.filePath,projectRoot:s}),v.testFile?e.jsx(vt,{testFile:v.testFile,entityName:v.name}):e.jsx("div",{className:"px-2 pt-1",children:e.jsx("span",{className:"text-[10px] text-gray-500",children:"No test file"})})]},v.sha)),M.map(v=>e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"px-2 py-1",children:e.jsx("span",{className:"text-[11px] font-medium text-gray-300",children:v.name})}),e.jsx(Ie,{filePath:v.filePath,projectRoot:s}),e.jsx(vt,{testFile:v.testFile,entityName:v.name})]},v.name))]})]})})}function js(t){const s={};for(const[r,a]of Object.entries(t))if(typeof a=="string")try{const c=JSON.parse(a);Array.isArray(c)?s[r]=c:typeof c=="object"&&c!==null&&(s[r]=[c])}catch{}else Array.isArray(a)&&(s[r]=a);return s}function vs(t,s){return t.length===0||s.length===0?!1:t.filter(a=>s.includes(a)).length>=Math.min(t.length,s.length)*.5}function Br(t,s){const{_metadata:r,...a}=s,c=a.localStorage&&typeof a.localStorage=="object"&&!Array.isArray(a.localStorage)?js(a.localStorage):{},i={};if(a.seed&&typeof a.seed=="object"&&!Array.isArray(a.seed))for(const[m,p]of Object.entries(a.seed))Array.isArray(p)&&(i[m]=p);const l={},o=[],x=new Set,S=new Set,b=new Set;for(const m of t){const p=m.fields.filter(y=>!y.isRelation),R=p.map(y=>y.name),h=m.name.charAt(0).toLowerCase()+m.name.slice(1);let N=null,f=[];for(const y of[m.name,h,`${h}s`])if(y in a&&Array.isArray(a[y])){N=y,f=a[y],S.add(y);break}if(!N){for(const y of[m.name,h,`${h}s`])if(y in i){N=y,f=i[y],b.add(y),y in c&&x.add(y);break}}if(!N){for(const y of[m.name,h,`${h}s`])if(y in c){N=h,f=c[y],x.add(y);break}}if(!N){for(const[y,E]of Object.entries(c))if(!x.has(y)&&E.length>0&&vs(R,Object.keys(E[0]))){N=h,f=E,x.add(y);break}}N||(N=h),l[N]=f,o.push({label:m.name,dataKey:N,schemaFields:p.map(y=>({name:y.name,type:y.type,isId:y.isId}))})}for(const[m,p]of Object.entries(a))m==="_metadata"||m==="localStorage"||m==="seed"||m==="type"||S.has(m)||Array.isArray(p)&&(l[m]=p,o.push({label:m,dataKey:m}));for(const[m,p]of Object.entries(i))b.has(m)||(l[m]=p,o.push({label:m,dataKey:m}));for(const[m,p]of Object.entries(c))x.has(m)||(l[m]=p,o.push({label:m,dataKey:m}));return{data:l,tabs:o}}function Wr(t){return t==null?"null":typeof t=="number"?Number.isInteger(t)?"int4":"float":typeof t=="boolean"?"bool":typeof t=="object"?Array.isArray(t)?"array":"json":"text"}function zr(t,s){return t.length>0?Object.keys(t[0]):s?s.map(r=>r.name):[]}function Ur(t,s,r){const a=new Map((r||[]).map(i=>[i.name,i.type])),c={};for(const i of t)c[i]=a.get(i)||(s.length>0?Wr(s[0][i]):"text");return c}function Hr(t,s){var r;return((r=s==null?void 0:s.find(a=>a.isId))==null?void 0:r.name)||t.find(a=>a==="id")||null}function Vr(t,s){const{_metadata:r,...a}=s,c=a.localStorage&&typeof a.localStorage=="object"&&!Array.isArray(a.localStorage)?js(a.localStorage):{},i={};if(a.seed&&typeof a.seed=="object"&&!Array.isArray(a.seed))for(const[m,p]of Object.entries(a.seed))Array.isArray(p)&&(i[m]=p);const l={},o=[],x=new Set,S=new Set,b=new Set;for(const m of t){const p=m.name.charAt(0).toLowerCase()+m.name.slice(1),R=m.fields.map(f=>f.name);let h=null,N=[];for(const f of[m.name,p,`${p}s`])if(f in a&&Array.isArray(a[f])){h=f,N=a[f],S.add(f);break}if(!h){for(const f of[m.name,p,`${p}s`])if(f in i){h=f,N=i[f],b.add(f),f in c&&x.add(f);break}}if(!h){for(const f of[m.name,p,`${p}s`])if(f in c){h=p,N=c[f],x.add(f);break}}if(!h){for(const[f,y]of Object.entries(c))if(!x.has(f)&&y.length>0&&vs(R,Object.keys(y[0]))){h=p,N=y,x.add(f);break}}h||(h=p),l[h]=N,o.push({label:m.name,dataKey:h,category:m.category,description:m.description,schemaFields:m.fields.map(f=>({name:f.name,type:f.type,isId:f.isId??!1}))})}for(const[m,p]of Object.entries(a))m==="_metadata"||m==="localStorage"||m==="seed"||m==="type"||S.has(m)||Array.isArray(p)&&(l[m]=p,o.push({label:m,dataKey:m}));for(const[m,p]of Object.entries(i))b.has(m)||(l[m]=p,o.push({label:m,dataKey:m}));for(const[m,p]of Object.entries(c))x.has(m)||(l[m]=p,o.push({label:m,dataKey:m}));return{data:l,tabs:o}}function St(t){var c,i;const s=new Map,r=new Map;for(const l of t)if(l.componentName){const o=r.get(l.componentName)||[];o.push(l),r.set(l.componentName,o)}else if(ys(l.url)){const o=(c=l.url)==null?void 0:c.match(/[?&]c=([^&]+)/),x=o?decodeURIComponent(o[1]):"Isolated",S=r.get(x)||[];S.push(l),r.set(x,S)}else{const o=l.displayName||((i=l.pageFilePath)!=null&&i.startsWith("app/")?Oe(Re(l.pageFilePath)):Ze(l.url)),x=s.get(o)||[];x.push(l),s.set(o,x)}const a=new Map([...r.entries()].sort(([l],[o])=>l.localeCompare(o)));return{pageGroups:s,componentGroups:a}}function Ns(t,s){var a,c;const r=new Map;for(const[i,l]of t){const o=(a=l.find(x=>x.entitySha))==null?void 0:a.entitySha;o&&r.set(i,o)}for(const[i,l]of s){const o=(c=l.find(x=>x.entitySha))==null?void 0:c.entitySha;o&&r.set(i,o)}return r}function Jr(t){const s=new Set;for(const[r,a]of Object.entries(t)){s.add(r);for(const c of a)s.add(c)}return s}function Kr(t,s,r,a){if(s.has(t))return!0;const c=r.find(i=>i.sha===t);return c?a.has(c.name):!1}function Gr(t,s,r,a){const c=[];for(const[i,l]of t){const o=r.get(i);o?a(o)||c.push({name:i,scenarios:l,reason:"incomplete"}):c.push({name:i,scenarios:l,reason:"missing"})}for(const[i,l]of s){const o=r.get(i);o?a(o)||c.push({name:i,scenarios:l,reason:"incomplete"}):c.push({name:i,scenarios:l,reason:"missing"})}return c}function as(t,s,r){if(!t)return null;const a=s.find(c=>c.sha===t);return a?{sha:t,name:a.name,filePath:a.filePath,entityType:a.entityType,displayName:a.name}:null}const is=120;function ws({text:t,theme:s}){const[r,a]=n.useState(!1),c=t.length>is,i=c&&!r?t.slice(0,is)+"…":t,l=s==="light";return e.jsxs("div",{className:`px-4 py-2 ${l?"border-b border-gray-200 bg-gray-50":"border-b border-[#3d3d3d] bg-[#252525]"}`,children:[e.jsx("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-gray-500",children:"User Prompt"}),e.jsxs("p",{className:`text-[11px] mt-0.5 mb-0 leading-relaxed ${l?"text-gray-600":"text-gray-400"}`,children:[i,c&&e.jsx("button",{onClick:()=>a(!r),className:`ml-1 text-[11px] font-medium bg-transparent border-none p-0 cursor-pointer ${l?"text-blue-500 hover:text-blue-700":"text-[#00a0c4] hover:text-[#00c0e8]"}`,children:r?"Show less":"Read more…"})]})]})}const os={new:0,edited:1,impacted:2};function ls({status:t,onClick:s}){const r={new:{label:"New",bg:"bg-green-100",text:"text-green-700",border:"border-green-200"},edited:{label:"Edited",bg:"bg-blue-100",text:"text-blue-700",border:"border-blue-200"},impacted:{label:"Impacted",bg:"bg-amber-100",text:"text-amber-700",border:"border-amber-200"}}[t.status],a=s&&(t.status==="edited"||t.status==="impacted");return e.jsx("button",{onClick:a?s:void 0,className:`${r.bg} ${r.text} ${r.border} border text-[9px] font-bold px-1.5 py-0.5 rounded-full uppercase tracking-wider shrink-0 ${a?"cursor-pointer hover:opacity-80 transition-opacity":"cursor-default"}`,children:r.label})}function cs({filePath:t}){const[s,r]=n.useState(null),[a,c]=n.useState(!0),[i,l]=n.useState(null);return n.useEffect(()=>{Cr(()=>import("./index-DE3jI_dv.js"),__vite__mapDeps([0,1,2])).then(o=>{l(()=>o.default)})},[]),n.useEffect(()=>{c(!0),fetch(`/api/editor-file-diff?path=${encodeURIComponent(t)}`).then(o=>o.json()).then(o=>{r({oldContent:o.oldContent,newContent:o.newContent})}).catch(()=>{r(null)}).finally(()=>c(!1))},[t]),a?e.jsx("div",{className:"p-2 text-[10px] text-gray-400",children:"Loading diff..."}):!s||!i?e.jsx("div",{className:"p-2 text-[10px] text-gray-400",children:"Could not load diff"}):e.jsx("div",{className:"mt-2 border border-gray-200 rounded-lg overflow-hidden max-h-[300px] overflow-auto text-xs",children:e.jsx(i,{oldValue:s.oldContent,newValue:s.newContent,splitView:!1,useDarkTheme:!1,showDiffOnly:!0,styles:{contentText:{fontSize:"11px",lineHeight:"1.4"},line:{padding:"1px 8px",fontSize:"11px"}}})})}function ds({impactedBy:t,changedEntities:s}){return e.jsx("div",{className:"mt-2 bg-amber-50 border border-amber-200 rounded-lg p-2.5",children:t&&t.length>0?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[10px] font-semibold text-amber-700 uppercase tracking-wider",children:"Re-captured because these dependencies changed"}),e.jsx("ul",{className:"mt-1.5 space-y-1",children:t.map(r=>e.jsxs("li",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`text-[9px] font-bold px-1 py-0 rounded-full uppercase tracking-wider border ${r.changeType==="new"?"bg-green-100 text-green-700 border-green-200":"bg-blue-100 text-blue-700 border-blue-200"}`,children:r.changeType==="new"?"New":"Edited"}),e.jsx("span",{className:"text-[11px] font-medium text-amber-800",children:r.name}),e.jsx("span",{className:"text-[9px] text-amber-500 truncate",children:r.filePath})]},r.filePath))})]}):s&&s.length>0?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[10px] font-semibold text-amber-700 uppercase tracking-wider",children:"Unchanged — these entities were modified in this session"}),e.jsx("ul",{className:"mt-1.5 space-y-1",children:s.map(r=>e.jsxs("li",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`text-[9px] font-bold px-1 py-0 rounded-full uppercase tracking-wider border ${r.status==="new"?"bg-green-100 text-green-700 border-green-200":"bg-blue-100 text-blue-700 border-blue-200"}`,children:r.status==="new"?"New":"Edited"}),e.jsx("span",{className:"text-[11px] font-medium text-amber-800",children:r.name})]},r.name))})]}):e.jsx("span",{className:"text-[10px] text-amber-600",children:"This component was re-captured because a dependency changed"})})}function xs({scenarioId:t,name:s,isActive:r,onSelect:a,updatedAt:c}){const i=n.useRef(null);return n.useEffect(()=>{r&&i.current&&i.current.scrollIntoView({block:"nearest",behavior:"smooth"})},[r]),e.jsxs("button",{ref:i,onClick:a,className:"flex flex-col items-center gap-1.5 cursor-pointer group",title:s,children:[e.jsx("div",{className:`w-32 h-32 rounded-lg overflow-hidden border-2 transition-all ${r?"border-[#0ea5e9] ring-2 ring-[#0ea5e9]/40 shadow-lg shadow-[#0ea5e9]/20":"border-gray-200 hover:border-gray-400 shadow-sm"}`,children:e.jsx(_e,{scenarioId:t,updatedAt:c,alt:s,className:"w-full h-full bg-white",imgClassName:"w-full h-full object-contain bg-white"})}),e.jsx("span",{className:`text-[11px] leading-tight text-center truncate w-32 font-medium ${r?"text-gray-900":"text-gray-600 group-hover:text-gray-900"}`,children:s})]})}function Yr({filePath:t}){return t?e.jsxs("div",{className:"flex items-center gap-1 mt-0.5",children:[e.jsxs("a",{href:`/api/editor-file?path=${encodeURIComponent(t)}`,target:"_blank",rel:"noopener noreferrer",title:"Open file",className:"flex items-center gap-1 text-gray-400 hover:text-gray-600 transition-colors min-w-0",children:[e.jsx("span",{className:"text-[9px] truncate",children:t}),e.jsx("svg",{className:"shrink-0",width:"10",height:"10",viewBox:"0 0 12 12",fill:"none",children:e.jsx("path",{d:"M4.5 1.5H2.5C1.95 1.5 1.5 1.95 1.5 2.5V9.5C1.5 10.05 1.95 10.5 2.5 10.5H9.5C10.05 10.5 10.5 10.05 10.5 9.5V7.5M7.5 1.5H10.5M10.5 1.5V4.5M10.5 1.5L5 7",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})})]}),e.jsx(Te,{content:t,icon:!0,iconSize:10,className:"shrink-0 text-gray-400 hover:text-gray-600 transition-colors"})]}):null}function Nt({testFile:t,entityName:s}){const{results:r,isRunning:a,runTests:c}=wt(t);if(a&&!r)return e.jsxs("div",{className:"pt-1 flex items-center gap-1.5",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-[#0ea5e9] animate-pulse"}),e.jsx("span",{className:"text-[10px] text-gray-400",children:"Running tests..."})]});if(!r)return null;if(r.status==="error")return e.jsx("div",{className:"pt-1",children:e.jsx("span",{className:"text-[10px] text-red-500",children:r.errorMessage})});const i=s?r.testCases.filter(x=>x.fullName.startsWith(s)):r.testCases,l=i.length>0?i:r.testCases;if(l.length===0)return null;const o=s?`${s} > `:"";return e.jsxs("div",{className:"pt-1 space-y-0.5",children:[l.map(x=>{var b;const S=o&&x.fullName.startsWith(o)?x.fullName.slice(o.length):x.fullName;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[x.status==="passed"?e.jsx("span",{className:"text-green-600 text-[10px]",children:"✓"}):x.status==="failed"?e.jsx("span",{className:"text-red-500 text-[10px]",children:"✗"}):e.jsx("span",{className:"text-gray-400 text-[10px]",children:"—"}),e.jsx("span",{className:`text-[10px] ${x.status==="passed"?"text-green-600":x.status==="failed"?"text-red-500":"text-gray-400"}`,children:S})]}),x.status==="failed"&&((b=x.failureMessages)==null?void 0:b.map((m,p)=>e.jsx("div",{className:"pl-4 text-[9px] text-red-400 truncate max-w-full",title:m,children:m.split(`
4
+ `)[0]},p)))]},x.fullName)}),e.jsx("button",{onClick:c,disabled:a,className:"mt-1 text-[10px] text-[#0ea5e9] hover:text-[#38bdf8] transition-colors cursor-pointer disabled:opacity-50 bg-transparent border-none p-0",children:a?"Running...":"Re-run"})]})}function us(t){const s=t.indexOf(" - ");return s!==-1?t.slice(s+3):t}function ms(t,s){return!s||Object.keys(s).length===0?t:[...t].sort(([r],[a])=>{var o,x;const c=((o=s[r])==null?void 0:o.status)||"impacted",i=((x=s[a])==null?void 0:x.status)||"impacted",l=(os[c]??2)-(os[i]??2);return l!==0?l:r.localeCompare(a)})}function qr({scenarios:t,allScenarios:s=[],glossaryFunctions:r=[],projectRoot:a,activeScenarioId:c,onScenarioSelect:i,onClose:l,entityChangeStatus:o={},modifiedFiles:x=[],featureName:S,userPrompt:b}){const m=n.useMemo(()=>{if(s.length===0||Object.keys(o).length===0)return t;const w=new Set(t.map(F=>F.id)),k=s.filter(F=>{var I,V;if(w.has(F.id))return!1;const M=F.componentName||F.displayName||((I=F.pageFilePath)!=null&&I.startsWith("app/")?Oe(Re(F.pageFilePath)):Ze(F.url));return((V=o[M])==null?void 0:V.status)==="impacted"});return k.length===0?t:[...t,...k]},[t,s,o]),p=n.useMemo(()=>Object.entries(o).filter(([,w])=>w.status==="new"||w.status==="edited").map(([w,k])=>({name:w,status:k.status})),[o]),[R,h]=n.useState(null),N=n.useCallback(w=>{h(k=>k===w?null:w)},[]),{pageGroups:f,componentGroups:y}=n.useMemo(()=>St(m),[m]),E=n.useMemo(()=>ms([...f.entries()],o),[f,o]),P=n.useMemo(()=>ms([...y.entries()],o),[y,o]),O=E,J=P,Z=n.useMemo(()=>Fr(r,o),[r,o]),B=n.useMemo(()=>{const w=[];for(const[,k]of O)w.push(...k);for(const[,k]of J)w.push(...k);return w},[O,J]),q=n.useRef(!1);return n.useEffect(()=>{q.current||B.length!==0&&(q.current=!0,console.log("[ResultsPanel] Auto-selecting first scenario: %s",B[0].name),i(B[0]))},[B,i]),n.useEffect(()=>{if(B.length===0)return;const w=k=>{if(k.key!=="ArrowLeft"&&k.key!=="ArrowRight")return;const F=k.target,M=F==null?void 0:F.tagName;if(M==="INPUT"||M==="SELECT"||M==="TEXTAREA"&&!F.classList.contains("xterm-helper-textarea"))return;k.preventDefault();const I=B.findIndex(W=>W.id===c);let V;k.key==="ArrowLeft"?V=I<=0?B.length-1:I-1:V=I>=B.length-1?0:I+1,i(B[V])};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[B,c,i]),m.length===0&&r.length===0?e.jsxs("div",{className:"h-full bg-white flex items-center justify-center relative",children:[e.jsx("button",{onClick:l,className:"absolute top-2 right-3 text-gray-400 hover:text-gray-700 text-lg leading-none cursor-pointer bg-transparent border-none",title:"Close results",children:"×"}),e.jsx("span",{className:"text-sm text-gray-400",children:"No scenarios registered yet"})]}):e.jsxs("div",{className:"h-full bg-white flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5 border-b border-gray-200 shrink-0",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:"Working Session Results"}),S&&e.jsx("div",{className:"text-[11px] text-gray-400 truncate",title:S,children:S})]}),e.jsx("button",{onClick:l,className:"text-gray-400 hover:text-gray-700 text-lg leading-none cursor-pointer bg-transparent border-none shrink-0",title:"Close results",children:"×"})]}),b&&e.jsx(ws,{text:b,theme:"light"}),e.jsx("div",{className:"flex-1 overflow-auto p-4",children:e.jsxs("div",{className:"space-y-5",children:[O.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"mb-2",children:e.jsx("span",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:"Application"})}),e.jsx("div",{className:"space-y-3 pl-1",children:O.map(([w,k])=>{var V;const F=o[w],M=R===w,I=(V=k[0])==null?void 0:V.componentPath;return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-2",children:[e.jsx("span",{className:"text-[11px] font-medium text-gray-600",children:w}),F&&e.jsx(ls,{status:F,onClick:()=>N(w)})]}),M&&(F==null?void 0:F.status)==="edited"&&I&&e.jsx(cs,{filePath:I}),M&&(F==null?void 0:F.status)==="impacted"&&e.jsx(ds,{impactedBy:F.impactedBy,changedEntities:p}),e.jsx("div",{className:"flex flex-wrap gap-3",children:k.map(W=>e.jsx(xs,{scenarioId:W.id,name:us(W.name),isActive:W.id===c,onSelect:()=>i(W),updatedAt:W.updatedAt},W.id))})]},w)})})]}),J.length>0&&e.jsxs("div",{className:O.length>0?"pt-3 border-t border-gray-200":"",children:[e.jsx("div",{className:"mb-2",children:e.jsx("span",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:"Components"})}),e.jsx("div",{className:"space-y-3 pl-1",children:J.map(([w,k])=>{var V;const F=o[w],M=R===w,I=(V=k[0])==null?void 0:V.componentPath;return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-2",children:[e.jsx("span",{className:"text-[11px] font-medium text-gray-600",children:w}),F&&e.jsx(ls,{status:F,onClick:()=>N(w)})]}),M&&(F==null?void 0:F.status)==="edited"&&I&&e.jsx(cs,{filePath:I}),M&&(F==null?void 0:F.status)==="impacted"&&e.jsx(ds,{impactedBy:F.impactedBy,changedEntities:p}),e.jsx("div",{className:"flex flex-wrap gap-3",children:k.map(W=>e.jsx(xs,{scenarioId:W.id,name:us(W.name),isActive:W.id===c,onSelect:()=>i(W),updatedAt:W.updatedAt},W.id))})]},w)})})]}),Z.length>0&&e.jsxs("div",{className:O.length>0||J.length>0?"pt-3 border-t border-gray-200":"",children:[e.jsx("div",{className:"mb-2",children:e.jsx("span",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:"Functions"})}),e.jsx("div",{className:"space-y-2 pl-1",children:Z.map(w=>e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"text-[11px] font-medium text-gray-700",children:w.name})}),e.jsx(Yr,{filePath:w.filePath,projectRoot:a}),w.testFile?e.jsx(Nt,{testFile:w.testFile,entityName:w.name}):e.jsx("div",{className:"pt-1",children:e.jsx("span",{className:"text-[10px] text-gray-400",children:"No test file"})})]},w.name))})]}),x.length>0&&e.jsxs("div",{className:O.length>0||J.length>0||Z.length>0?"pt-3 border-t border-gray-200":"",children:[e.jsx("div",{className:"mb-2",children:e.jsxs("span",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:["Modified Files (",x.length,")"]})}),e.jsx("div",{className:"space-y-0.5 pl-1 max-h-[200px] overflow-auto",children:x.map(w=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`text-[9px] font-bold uppercase w-[14px] text-center ${w.status==="added"||w.status==="untracked"?"text-green-600":w.status==="modified"?"text-blue-600":w.status==="renamed"?"text-purple-600":"text-gray-400"}`,children:w.status==="added"||w.status==="untracked"?"A":w.status==="modified"?"M":w.status==="renamed"?"R":"?"}),e.jsx("span",{className:"text-[10px] text-gray-500 truncate font-mono",children:w.path})]},w.path))})]})]})})]})}function hs(t,s,r,a){var x;const c=a.length>0?a.map(S=>`- "${S.name}" (ID: ${S.id})${S.url?` — URL: ${S.url}`:""}`).join(`
5
5
  `):"(no scenarios yet)",i=s.endsWith("/page.tsx")||s.endsWith("/page.js"),l=((x=a.find(S=>S.url))==null?void 0:x.url)||"/",o=[`You are helping edit scenarios for the "${t}" entity in a CodeYam project.`,"","## Entity",`- **Name:** ${t}`,`- **File:** ${s}`,`- **Type:** ${i?"Page (application scenario with seed data)":"Component (component scenario with mock props)"}`,"","## Existing Scenarios",c,""];return i?o.push("## How Seed Data Works","","Application scenarios use `seed` data to populate the database before the page is captured.","The seed is a JSON object where each key is a Prisma model name in camelCase singular (matching the Prisma client accessor name) and the value is an array of records.","","### Seed Key Naming Convention","The key must be the camelCase singular form of the Prisma model name:",'- `model User` → key `"user"`','- `model BlogPost` → key `"blogPost"`','- `model Feedback` → key `"feedback"`',"",'**WARNING:** Do NOT use plural forms like "users", "blogPosts", or "feedbacks" — the seed adapter will silently fail to match them.',"","To understand the data models, read the Prisma schema at `prisma/schema.prisma`.","To see examples of existing seed data, look at `.codeyam/editor-scenarios/*.seed.json` files.","",`Also read the source file at \`${s}\` to understand what data the page queries and renders.`,"","## Registering a Scenario","","For small seed data, pass it inline:","```",`codeyam editor register '{"name":"Scenario Name","type":"application","url":"${l}","dimensions":["Laptop"],"seed":{"user":[...],"feedback":[...]}}'`,"```","","For large seed data, write it to a temp file and use @file syntax:","```","# Write JSON to a temp file","cat > .codeyam/tmp/scenario.json << 'SCENARIO_EOF'",`{"name":"Scenario Name","type":"application","url":"${l}","dimensions":["Laptop"],"seed":{"user":[...],"feedback":[...]}}`,"SCENARIO_EOF","codeyam editor register @.codeyam/tmp/scenario.json","```"):o.push("## Registering a Scenario","",`Read the source file at \`${s}\` to understand what props the component expects.`,"","```",`codeyam editor register '{"name":"Scenario Name","type":"component","componentName":"${t}","componentPath":"${s}","dimensions":["Laptop"],"mockData":{"propName":"value"}}'`,"```"),o.push("","## Deleting a Scenario","","To delete a scenario, use its ID from the list above:","```","codeyam editor delete <scenarioId>","```","","## Validating Seed Data","","Before registering, you can validate seed data structure and check that keys match Prisma models:","```",`codeyam editor validate-seed '{"user":[...]}'`,"```"),o.push("","## Recapturing Scenarios After Code Changes","",`If the user asks you to modify the code for this ${i?"page":"component"} (CSS, layout, logic, etc.), you MUST re-register all existing scenarios after the code change so their screenshots are updated.`,"","Re-registering a scenario with the same name overwrites it and captures a fresh screenshot.","","To recapture, re-register each existing scenario using `codeyam editor register` with its current configuration. You can read the scenario JSON files in `.codeyam/editor-scenarios/` to get the exact registration data for each scenario."),o.push("","## Important","- DO NOT take any action until the user tells you what they want","- Start by briefly listing the existing scenarios",'- Then ask: "Would you like to modify an existing scenario or add a new one?"',"- Wait for the user's answer before proceeding",'- Keep scenario names descriptive: "Empty State", "With Comments", "Admin View", etc.',`- Each scenario should capture a distinct, meaningful state of the ${i?"page":"component"}`),o.join(`
6
- `)}function ws(t,s){var c;const n=s.some(i=>!i.componentName),a=s.map(i=>`'${i.id}'`).join(", ");if(n){const i=((c=s.find(o=>o.url))==null?void 0:c.url)||null,l=s.map(o=>`.codeyam/editor-scenarios/${o.id}.json`).join(", ");return[`### Page: "${t}" (${s.length} scenario(s))`,...i?["",`Scenario URL: \`${i}\``]:[],"",...i?["Step A: Find the source file that renders this page. In Next.js App Router, URLs map to page.tsx files:"," - `/` → `app/page.tsx`"," - `/about` → `app/about/page.tsx`"," - `/c/my-slug` → `app/c/[slug]/page.tsx` (dynamic segment)","",`Based on the URL \`${i}\`, find the corresponding page.tsx file. Confirm it exists with \`cat <filepath> | head -5\`.`]:["Step A: Find the source file that renders this page by running:",' find src app -name "App.tsx" -o -name "App.jsx" -o -name "page.tsx" -o -name "page.jsx" -o -name "index.tsx" 2>/dev/null',"","Pick the file that is the main app entry point or the page component for this route. Confirm it exists with `cat <filepath> | head -5`."],"","Step B: Set page_file_path on all scenarios for this page (replace PAGE_FILE_PATH with the path from Step A):",` sqlite3 .codeyam/db.sqlite3 "UPDATE editor_scenarios SET page_file_path = 'PAGE_FILE_PATH' WHERE id IN (${a});"`,"","Step C: Get the entity SHA (after running analyze-imports in the shared step above):",` sqlite3 .codeyam/db.sqlite3 "SELECT sha FROM entities WHERE file_path = 'PAGE_FILE_PATH' ORDER BY created_at DESC LIMIT 1;"`,"","If no rows appear, the path was wrong — go back to Step A.","","Step D: Set entity_sha and display_name on all scenarios (replace ENTITY_SHA with the SHA from Step C):",` sqlite3 .codeyam/db.sqlite3 "UPDATE editor_scenarios SET entity_sha = 'ENTITY_SHA', display_name = '${t}' WHERE id IN (${a});"`,"","Step E: Add pageFilePath to the scenario JSON files so this fix persists across clones.",`For each file (${l}), read it and add \`"pageFilePath": "PAGE_FILE_PATH"\` to the \`_metadata\` object (after the \`"type"\` field). Then commit the updated JSON files.`].join(`
6
+ `)}function Ss(t,s){var c;const r=s.some(i=>!i.componentName),a=s.map(i=>`'${i.id}'`).join(", ");if(r){const i=((c=s.find(o=>o.url))==null?void 0:c.url)||null,l=s.map(o=>`.codeyam/editor-scenarios/${o.id}.json`).join(", ");return[`### Page: "${t}" (${s.length} scenario(s))`,...i?["",`Scenario URL: \`${i}\``]:[],"",...i?["Step A: Find the source file that renders this page. In Next.js App Router, URLs map to page.tsx files:"," - `/` → `app/page.tsx`"," - `/about` → `app/about/page.tsx`"," - `/c/my-slug` → `app/c/[slug]/page.tsx` (dynamic segment)","",`Based on the URL \`${i}\`, find the corresponding page.tsx file. Confirm it exists with \`cat <filepath> | head -5\`.`]:["Step A: Find the source file that renders this page by running:",' find src app -name "App.tsx" -o -name "App.jsx" -o -name "page.tsx" -o -name "page.jsx" -o -name "index.tsx" 2>/dev/null',"","Pick the file that is the main app entry point or the page component for this route. Confirm it exists with `cat <filepath> | head -5`."],"","Step B: Set page_file_path on all scenarios for this page (replace PAGE_FILE_PATH with the path from Step A):",` sqlite3 .codeyam/db.sqlite3 "UPDATE editor_scenarios SET page_file_path = 'PAGE_FILE_PATH' WHERE id IN (${a});"`,"","Step C: Get the entity SHA (after running analyze-imports in the shared step above):",` sqlite3 .codeyam/db.sqlite3 "SELECT sha FROM entities WHERE file_path = 'PAGE_FILE_PATH' ORDER BY created_at DESC LIMIT 1;"`,"","If no rows appear, the path was wrong — go back to Step A.","","Step D: Set entity_sha and display_name on all scenarios (replace ENTITY_SHA with the SHA from Step C):",` sqlite3 .codeyam/db.sqlite3 "UPDATE editor_scenarios SET entity_sha = 'ENTITY_SHA', display_name = '${t}' WHERE id IN (${a});"`,"","Step E: Add pageFilePath to the scenario JSON files so this fix persists across clones.",`For each file (${l}), read it and add \`"pageFilePath": "PAGE_FILE_PATH"\` to the \`_metadata\` object (after the \`"type"\` field). Then commit the updated JSON files.`].join(`
7
7
  `)}else return[`### Component: "${t}" (${s.length} scenario(s))`,"","Step A: Get the entity SHA (after running analyze-imports in the shared step above):",` sqlite3 .codeyam/db.sqlite3 "SELECT sha FROM entities WHERE name = '${t}' ORDER BY created_at DESC LIMIT 1;"`,"","If no rows appear, check that .codeyam/glossary.json contains an entry for this component.","","Step B: Set entity_sha and display_name on all scenarios (replace ENTITY_SHA with the SHA from Step A):",` sqlite3 .codeyam/db.sqlite3 "UPDATE editor_scenarios SET entity_sha = 'ENTITY_SHA', display_name = '${t}' WHERE id IN (${a});"`].join(`
8
- `)}function qe({scenarioId:t,updatedAt:s,hasScreenshot:n,imgSrc:a,name:c,isActive:i,onSelect:l}){const o=t&&n,x=!t&&a;return e.jsxs("button",{onClick:l,className:"flex flex-col items-center gap-1 cursor-pointer group w-full",title:c,children:[e.jsx("div",{className:`w-full aspect-[16/10] rounded overflow-hidden border-2 transition-all bg-[#1a1a1a] ${i?"border-[#D7FF63]/40 ring-1 ring-[#D7FF63]/20":"border-transparent hover:border-[#4d4d4d]"}`,children:o?e.jsx(_e,{scenarioId:t,updatedAt:s,alt:c,className:"w-full h-full",imgClassName:"w-full h-full object-contain"}):x?e.jsx("img",{src:a,alt:c,className:"w-full h-full object-contain",loading:"lazy"}):e.jsx("div",{className:"w-full h-full bg-[#1a1a1a] flex items-center justify-center",children:e.jsx("span",{className:"text-[8px] text-gray-600",children:"No img"})})}),e.jsx("span",{className:`text-[10px] leading-tight text-center truncate w-full ${i?"text-white":"text-gray-500 group-hover:text-gray-300"}`,children:c})]})}function Ge({filePath:t}){return t?e.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[e.jsxs("a",{href:`/api/editor-file?path=${encodeURIComponent(t)}`,target:"_blank",rel:"noopener noreferrer",title:"Open file",className:"flex items-center gap-1.5 text-gray-500 hover:text-gray-300 transition-colors min-w-0",children:[e.jsx("span",{className:"text-sm truncate font-['IBM_Plex_Mono']",children:t}),e.jsx("svg",{className:"shrink-0",width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:e.jsx("path",{d:"M4.5 1.5H2.5C1.95 1.5 1.5 1.95 1.5 2.5V9.5C1.5 10.05 1.95 10.5 2.5 10.5H9.5C10.05 10.5 10.5 10.05 10.5 9.5V7.5M7.5 1.5H10.5M10.5 1.5V4.5M10.5 1.5L5 7",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})})]}),e.jsx(Te,{content:t,icon:!0,iconSize:12,className:"shrink-0 text-gray-500 hover:text-gray-300 transition-colors"})]}):null}function Ss({name:t,scenarios:s,reason:n="missing"}){var i,l;const a=((i=s[0])==null?void 0:i.componentPath)||((l=s[0])==null?void 0:l.pageFilePath)||null,c=n==="incomplete"?[`The "${t}" entity exists but has not been fully analyzed — its components and functions cannot be displayed.`,"","Follow these steps:","",`Step 1: Check if "${t}" is in the glossary:`,` cat .codeyam/glossary.json | grep "${t}"`,"","If not found, add an entry to .codeyam/glossary.json:",` { "name": "${t}", "filePath": "${a||"FILL_IN_PATH"}", "description": "...", "returnType": "JSX.Element" }`,"","Step 2: Run: codeyam editor analyze-imports","","Step 3: Reload the editor page and verify components/functions appear."].join(`
9
- `):[`The "${t}" ${s.some(o=>!o.componentName)?"page":"component"} is missing entity data in the CodeYam database. Its scenarios are hidden until this is fixed.`,"","IMPORTANT: Do NOT re-register scenarios — that would overwrite their screenshots. Instead, update the database and scenario JSON files directly.","","Follow these steps EXACTLY:","","Step 1: Run: codeyam editor analyze-imports","","Step 2: Fix this entity:","",ws(t,s),"","Step 3: Reload the editor page in the browser and verify the scenarios appear."].join(`
10
- `);return e.jsx(Te,{content:c,label:"Copy Fix Prompt",copiedLabel:"Copied!",className:"text-[10px] text-[#E0D400] hover:text-[#E0D400]/80 bg-transparent border border-[#E0D400]/30 rounded px-2 py-0.5 cursor-pointer transition-colors ml-2"})}function Xn({brokenEntities:t}){const[s,n]=r.useState(!1),a=r.useCallback(x=>{navigator.clipboard.writeText(x).then(()=>{n(!0),setTimeout(()=>n(!1),2e3)})},[]);if(t.length===0)return null;const c=t.reduce((x,S)=>x+S.scenarios.length,0),i=t.filter(x=>x.reason==="incomplete"),l=t.filter(x=>x.reason==="missing"),o=[`${t.length} entities are missing data in the CodeYam database. ${c} total scenario(s) are hidden until this is fixed.`,"","IMPORTANT: Do NOT re-register scenarios — that would overwrite their screenshots. Instead, update the database and scenario JSON files directly.","","Follow these steps EXACTLY:","",...i.length>0?["## Step 1: Add missing entries to the glossary","","Read `.codeyam/glossary.json` and check if these entities have entries. For each one that is missing, add an entry:","",...i.map(x=>{var g,m;const S=((g=x.scenarios[0])==null?void 0:g.componentPath)||((m=x.scenarios[0])==null?void 0:m.pageFilePath)||"FILL_IN_PATH";return`- "${x.name}" (filePath: "${S}")`}),"",'Each glossary entry needs: name, filePath, description, returnType (use "JSX.Element" for components/pages).',""]:["## Step 1: No glossary changes needed",""],"## Step 2: Run import analysis"," codeyam editor analyze-imports","",...l.length>0?["## Step 3: Fix missing entity associations","",...l.map(x=>ws(x.name,x.scenarios)),""]:[],`## Step ${l.length>0?"4":"3"}: Reload the editor page in the browser and verify all scenarios appear. Then commit the updated scenario JSON files so the fix persists across clones.`].join(`
11
- `);return e.jsx("div",{className:"p-4 rounded-lg border border-[#E0D400]/40 bg-[#E0D400]/8",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"#E0D400",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),e.jsxs("p",{className:"flex-1 min-w-0 text-sm text-[#E0D400]/90 m-0 leading-snug font-['IBM_Plex_Sans']",children:[t.length," ",t.length===1?"entity is":"entities are"," missing data, resulting in ",c," hidden scenario",c!==1?"s":"","."," ",e.jsx("button",{type:"button",className:"font-bold underline bg-transparent border-none text-[#E0D400] cursor-pointer p-0 text-sm inline hover:text-[#E0D400]/70 transition-colors",onClick:()=>a(o),children:s?e.jsxs("span",{className:"inline-flex items-center gap-1",children:["Copied",e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",className:"inline",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})})]}):"Copy this prompt"})," ","into Claude to fix them all at once."]}),e.jsx(Te,{content:o,label:e.jsxs("span",{className:"flex items-center gap-2",children:["COPY PROMPT",e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})]}),copiedLabel:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"invisible",children:"COPY PROMPT"}),e.jsx("span",{className:"absolute inset-0 flex items-center justify-center",children:"COPIED!"}),e.jsx("span",{className:"invisible",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",children:e.jsx("rect",{x:"9",y:"9",width:"13",height:"13"})})})]}),className:"relative text-xs font-semibold text-[#1e1e1e] bg-[#E0D400] hover:bg-[#E0D400]/80 border-none rounded px-4 py-2 cursor-pointer transition-colors shrink-0 tracking-wide font-['IBM_Plex_Mono']"})]})})}function ks({focusedEntity:t,breadcrumbItems:s,onZoomChange:n,projectRoot:a,scenarios:c,analyzedEntities:i,activeScenarioId:l,onScenarioSelect:o,onAnalyzedScenarioSelect:x,onSwitchToBuild:S,entityImports:g,glossaryFunctions:m,glossaryEntries:p,entityShaMap:R,componentGroups:h,visualEntities:N,isEntityComplete:f,onReseedPreview:y}){var re;const E=t.filePath,C=t.name,[O,J]=r.useState("scenarios"),[Z,B]=r.useState(null),[q,w]=r.useState(""),[k,F]=r.useState(!1),[M,I]=r.useState(null),[V,W]=r.useState(!1),[le,v]=r.useState(!1),[A,_]=r.useState(null);r.useEffect(()=>{J("scenarios"),B(null),W(!1),v(!1),_(null)},[t.sha]);const j=r.useMemo(()=>{const u=new Map;for(const H of m)u.set(H.name,H);return u},[m]),D=i.some(u=>u.sha===t.sha||u.filePath===E),T=!!((re=g==null?void 0:g[C])!=null&&re.length),U=r.useCallback(async u=>{if(!(!q.trim()||k)){F(!0);try{(await fetch("/api/editor-rename-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioId:u,name:q.trim()})})).ok&&B(null)}catch{}finally{F(!1)}}},[q,k]),Q=r.useCallback(async u=>{if(confirm(`Delete scenario "${u.name}"?`)){I(u.id);try{const H=u.screenshotPaths?Object.values(u.screenshotPaths):u.screenshotPath?[u.screenshotPath]:[];await fetch("/api/delete-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioId:u.id,screenshotPaths:H})})}catch{}finally{I(null)}}},[]);if(!D&&!T){const u=c.filter(Y=>Y.entitySha===t.sha),H=[`The "${t.displayName}" entity (${E}) exists in the database but has not been fully analyzed. Its components and functions cannot be shown until it has import metadata.`,"","Follow these steps:","",`Step 1: Add "${C}" to the glossary if it's not already there:`,` Check: cat .codeyam/glossary.json | grep "${C}"`,"",` If not found, add an entry with name "${C}" and filePath "${E}" to .codeyam/glossary.json`,"","Step 2: Run import analysis:"," codeyam editor analyze-imports","","Step 3: Reload the editor page and verify components/functions appear."].join(`
12
- `);return e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsxs("div",{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>{if(s.length>1){const Y=s[s.length-2];n(Y.componentName,Y.entitySha)}else n()},className:"text-gray-400 hover:text-white transition-colors cursor-pointer bg-transparent border-none p-0 shrink-0 text-lg",title:"Go back",children:"←"}),e.jsx("h2",{className:"text-lg font-medium text-white m-0 font-['IBM_Plex_Sans']",children:t.displayName})]}),E&&e.jsx(Ge,{filePath:E,projectRoot:a}),e.jsxs("div",{className:"py-2",children:[e.jsx("p",{className:"text-[11px] text-amber-400/80 m-0 leading-relaxed",children:"This entity has not been fully analyzed. Its components and functions cannot be displayed. Please copy and paste this prompt into Claude to fix the data."}),e.jsx("div",{className:"mt-2",children:e.jsx(Te,{content:H,label:"Copy Fix Prompt",copiedLabel:"Copied!",className:"text-[10px] text-amber-400 hover:text-amber-300 bg-transparent border border-amber-400/30 rounded px-2 py-1 cursor-pointer transition-colors"})})]}),u.length>0&&e.jsx("div",{className:"grid grid-cols-3 gap-2",children:u.map(Y=>e.jsx(qe,{scenarioId:Y.id,updatedAt:Y.updatedAt,hasScreenshot:!!Y.screenshotPath,name:Y.name,isActive:Y.id===l,onSelect:()=>o(Y)},Y.id))})]})})}const $=t.sha,L=c.filter(u=>!u.componentName&&(u.pageFilePath===E||$&&u.entitySha===$)),X=c.filter(u=>u.componentName===C||u.componentPath===E),ee=N.find(u=>u.filePath===E||u.name===C),K=j.get(C)||m.find(u=>u.filePath===E),G=[...L,...X],ue=r.useMemo(()=>{const u=[];if(u.push(`# Create a New Scenario for "${t.displayName}"`),u.push(""),u.push(`**Entity**: ${t.displayName}`),u.push(`**Type**: ${t.entityType}`),u.push(`**File**: ${E}`),u.push(""),G.length>0){u.push("## Existing Scenarios");for(const H of G)u.push(`- **${H.name}**${H.url?` — URL: ${H.url}`:""}`);u.push("")}return u.push("## Your Task"),u.push("Ask the user what scenario they would like to create. Offer two options:"),u.push("1. **Describe a scenario** — the user tells you what they want and you create it"),u.push("2. **Analyze gaps** — you review the existing scenarios and source code to suggest scenarios that would improve coverage"),u.push(""),u.push("Once you know what scenario to create, use the `codeyam editor register` CLI command to register it. Write the scenario JSON to `.codeyam/tmp/scenario.json` first, then run `codeyam editor register @.codeyam/tmp/scenario.json`."),u.join(`
13
- `)},[t.displayName,t.entityType,E,G]),xe=new Set((g==null?void 0:g[C])||[]),he=T?[...h.entries()].filter(([u])=>xe.has(u)):[],Be=T?N.filter(u=>xe.has(u.name)&&!he.some(([H])=>H===u.name)):[],We=T?p.filter(u=>xe.has(u.name)&&u.returnType!=="JSX.Element"&&u.returnType!=="React.ReactNode").map(u=>({name:u.name,filePath:u.filePath,description:u.description||"",testFile:u.testFile,feature:u.feature})):[],be=he.length>0||Be.length>0,ce=We.length>0;return e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsxs("div",{className:"p-5",children:[e.jsxs("div",{className:"mb-5",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("button",{onClick:()=>{if(s.length>1){const u=s[s.length-2];n(u.componentName,u.entitySha)}else n()},className:"text-gray-400 hover:text-white transition-colors cursor-pointer bg-transparent border-none p-0 shrink-0 text-xl",title:"Go back",children:"←"}),e.jsx("h2",{className:"text-xl font-medium text-white m-0 font-['IBM_Plex_Sans']",children:t.displayName})]}),t.filePath&&e.jsx("div",{className:"mt-1.5 ml-7",children:e.jsx(Ge,{filePath:t.filePath,projectRoot:a})})]}),e.jsx("div",{className:"-mx-5 px-5 border-t border-b border-[#3d3d3d] flex items-center gap-6",children:[["scenarios","Scenarios"],["components","Components"],["functions","Functions"],["data-structure","Data Structure"]].map(([u,H])=>e.jsx("button",{onClick:()=>J(u),className:`text-xs font-normal uppercase tracking-wider transition-colors bg-transparent border-none cursor-pointer px-0 font-['IBM_Plex_Mono'] border-b-2 leading-none ${O===u?"text-[#D7FF63] border-b-[#D7FF63]":"text-gray-500 hover:text-gray-300 border-b-transparent"}`,style:{marginBottom:-1,paddingTop:16,paddingBottom:14},children:H},u))}),O==="scenarios"&&e.jsxs("div",{className:"space-y-3 mt-5",children:[G.map(u=>{const H=u.id===l,Y=Z===u.id;return e.jsxs("div",{children:[e.jsxs("div",{onClick:()=>{Y||o(u)},className:`flex items-center gap-4 p-3 rounded-lg cursor-pointer transition-colors ${H?"bg-[#1a2e1a] border border-[#D7FF63]/40":"bg-[#252525] hover:bg-[#2a2a2a] border border-transparent"}`,style:{opacity:M===u.id?.4:1},children:[u.screenshotPath?e.jsx(_e,{scenarioId:u.id,updatedAt:u.updatedAt,alt:"",className:"rounded w-[160px] h-[100px] shrink-0 overflow-hidden border border-[#3d3d3d]",imgClassName:"w-full h-full object-cover"}):e.jsx("div",{className:"rounded bg-[#1a1a1a] w-[160px] h-[100px] shrink-0 flex items-center justify-center border border-[#3d3d3d]",children:e.jsx("span",{className:"text-[10px] text-gray-600",children:"No image"})}),e.jsx("div",{className:"flex-1 min-w-0",children:Y?e.jsxs("form",{className:"flex items-center gap-1.5",onSubmit:se=>{se.preventDefault(),U(u.id)},onClick:se=>se.stopPropagation(),children:[e.jsx("input",{type:"text",value:q,onChange:se=>w(se.target.value),className:"flex-1 px-2 py-1 text-xs bg-[#1e1e1e] text-white border border-[#3d3d3d] rounded outline-none focus:border-[#005c75] min-w-0",autoFocus:!0,disabled:k}),e.jsx("button",{type:"submit",disabled:k||!q.trim(),className:"px-2 py-1 text-[10px] bg-[#005c75] text-white rounded hover:bg-[#004d63] disabled:opacity-40 cursor-pointer border-none",children:k?"...":"Save"}),e.jsx("button",{type:"button",onClick:()=>B(null),className:"px-2 py-1 text-[10px] text-gray-400 hover:text-white cursor-pointer bg-transparent border-none",children:"Cancel"})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-xs text-gray-300 truncate block",children:u.name}),H&&e.jsxs("div",{className:"flex items-center gap-3 mt-1.5",children:[e.jsx("button",{onClick:se=>{se.stopPropagation(),_(A===u.id?null:u.id)},className:"text-[10px] text-[#D7FF63] hover:text-[#D7FF63]/70 cursor-pointer bg-transparent border-none p-0",children:"View Data"}),e.jsx("button",{onClick:se=>{se.stopPropagation(),v(!1),W(!0)},className:"text-[10px] text-gray-400 hover:text-white cursor-pointer bg-transparent border-none p-0",children:"Edit with Claude"}),e.jsx("button",{onClick:se=>{se.stopPropagation(),B(u.id),w(u.name)},className:"text-[10px] text-gray-400 hover:text-white cursor-pointer bg-transparent border-none p-0",children:"Rename"}),e.jsx("button",{onClick:se=>{se.stopPropagation(),Q(u)},disabled:M===u.id,className:"text-[10px] text-red-400/60 hover:text-red-400 cursor-pointer bg-transparent border-none p-0",children:"Delete"})]})]})})]}),A===u.id&&e.jsx(Qn,{scenarioId:u.id,onClose:()=>_(null),editPrompt:ms(t.displayName,t.filePath,t.entityType,G),onReseedPreview:y})]},u.id)}),ee&&(ee.scenarios.length>0||ee.pendingScenarios.length>0)&&e.jsxs("div",{className:"space-y-1 mt-2",children:[ee.scenarios.map(u=>e.jsxs("div",{onClick:()=>x({analysisId:ee.analysisId,scenarioId:u.id,scenarioName:u.name,entitySha:ee.sha,entityName:ee.name}),className:"flex items-center gap-3 p-2 rounded cursor-pointer transition-colors hover:bg-[#252525] border border-transparent",children:[u.screenshotPath?e.jsx("img",{src:`/api/screenshot/${u.screenshotPath}`,alt:u.name,className:"rounded w-[48px] h-[48px] shrink-0 object-cover",loading:"lazy"}):e.jsx("div",{className:"rounded bg-[#1a1a1a] w-[48px] h-[48px] shrink-0 flex items-center justify-center",children:e.jsx("span",{className:"text-[8px] text-gray-600",children:"No img"})}),e.jsx("span",{className:"text-xs text-gray-300 truncate",children:u.name})]},u.id)),ee.pendingScenarios.map(u=>e.jsxs("div",{className:"flex items-center gap-3 p-2",children:[e.jsx("div",{className:"rounded bg-[#1a1a1a] w-[48px] h-[48px] shrink-0 flex items-center justify-center",children:e.jsx("span",{className:"text-[8px] text-gray-600",children:"..."})}),e.jsx("span",{className:"text-xs text-gray-500 truncate",children:u})]},u))]}),G.length===0&&!ee&&!K&&e.jsx("div",{className:"text-xs text-gray-500 py-2",children:"No scenarios for this entity"}),e.jsxs("button",{onClick:()=>{W(!1),v(!0)},className:"flex items-center gap-2.5 mt-4 text-xs text-[#D7FF63] hover:text-[#D7FF63]/70 bg-transparent border-none cursor-pointer p-0 font-normal uppercase tracking-wider font-['IBM_Plex_Mono'] transition-colors",children:[e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"16"}),e.jsx("line",{x1:"8",y1:"12",x2:"16",y2:"12"})]}),"Create New Scenario"]}),le&&e.jsx("div",{className:"mt-2 border border-[#3d3d3d] rounded-lg overflow-hidden",children:e.jsx($e,{prompt:ue,height:500,onClose:()=>v(!1)})}),V&&G.length>0&&e.jsx("div",{className:"mt-2 border border-[#3d3d3d] rounded-lg overflow-hidden",children:e.jsx($e,{prompt:ms(t.displayName,t.filePath,t.entityType,G),height:500,onClose:()=>W(!1)})})]}),O==="components"&&e.jsx("div",{className:"space-y-3",children:be?e.jsxs(e.Fragment,{children:[he.map(([u,H])=>e.jsx("div",{children:R.has(u)?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"py-1",children:e.jsx("button",{onClick:()=>n(u,R.get(u)),className:"text-[11px] font-medium text-gray-400 cursor-pointer hover:text-white transition-colors bg-transparent border-none p-0",children:u})}),H.length>0&&e.jsx("div",{className:"grid grid-cols-3 gap-2 pt-1",children:H.map(Y=>e.jsx(qe,{scenarioId:Y.id,updatedAt:Y.updatedAt,hasScreenshot:!!Y.screenshotPath,name:Y.name,isActive:Y.id===l,onSelect:()=>o(Y)},Y.id))})]}):e.jsxs("div",{className:"py-2",children:[e.jsx("span",{className:"text-[11px] font-medium text-gray-500",children:u}),e.jsx("p",{className:"text-[10px] text-amber-400/80 m-0 mt-1.5 leading-relaxed",children:"There is data missing that is required to show the scenarios for this component. Please copy and paste this prompt into Claude to ask Claude to fix the data."}),e.jsx("div",{className:"mt-1.5",children:e.jsx(Ss,{name:u,scenarios:H})})]})},u)),Be.map(u=>e.jsxs("div",{children:[e.jsx("div",{className:"py-1",children:e.jsx("button",{onClick:()=>n(u.name,u.sha),className:"text-[11px] font-medium text-gray-400 cursor-pointer hover:text-white transition-colors bg-transparent border-none p-0",children:u.name})}),(u.scenarios.length>0||u.pendingScenarios.length>0)&&e.jsxs("div",{className:"grid grid-cols-3 gap-2 pt-1",children:[u.scenarios.map(H=>e.jsx(qe,{imgSrc:H.screenshotPath?`/api/screenshot/${H.screenshotPath}`:null,name:H.name,isActive:!1,onSelect:()=>x({analysisId:u.analysisId,scenarioId:H.id,scenarioName:H.name,entitySha:u.sha,entityName:u.name})},H.id)),u.pendingScenarios.map(H=>e.jsx("div",{className:"px-2.5 py-1 bg-[#2a2a2a] text-gray-400 text-[10px] rounded-full",title:H,children:H},H))]})]},u.sha))]}):e.jsx("div",{className:"text-xs text-gray-500 py-2",children:"No component dependencies"})}),O==="functions"&&e.jsxs("div",{className:"space-y-3",children:[K&&K.testFile&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[10px] text-gray-500",children:"Tests:"}),e.jsx(Ge,{filePath:K.testFile,projectRoot:a})]}),e.jsx(vt,{testFile:K.testFile,entityName:C})]}),ce?e.jsx("div",{children:We.map(u=>e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"py-1",children:e.jsx("button",{onClick:()=>n(u.name,R.get(u.name)),className:"text-[11px] font-medium text-gray-400 cursor-pointer hover:text-white transition-colors bg-transparent border-none p-0",children:u.name})}),e.jsx(Ge,{filePath:u.filePath,projectRoot:a}),u.testFile&&e.jsxs("div",{className:"mt-0.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[9px] text-gray-600",children:"test:"}),e.jsx("span",{className:"text-[9px] text-gray-500 truncate",children:u.testFile})]}),e.jsx(vt,{testFile:u.testFile,entityName:u.name})]})]},u.name))}):K!=null&&K.testFile?null:e.jsx("div",{className:"text-xs text-gray-500 py-2",children:"No function dependencies"})]}),O==="data-structure"&&e.jsx(Zn,{})]})})}function Qn({scenarioId:t,onClose:s,editPrompt:n,onReseedPreview:a}){const[c,i]=r.useState(null),[l,o]=r.useState([]),[x,S]=r.useState(!0),[g,m]=r.useState(null),[p,R]=r.useState(null),[h,N]=r.useState(!1),[f,y]=r.useState(null),[E,C]=r.useState(""),[O,J]=r.useState(""),[Z,B]=r.useState(0),[q,w]=r.useState(!1),[k,F]=r.useState(!1),M=r.useRef(null);if(r.useEffect(()=>{S(!0),m(null),Promise.all([fetch("/api/editor-schema").then(j=>j.json()).catch(()=>({models:[]})),fetch(`/api/editor-scenario-data?scenarioId=${t}`).then(j=>j.json())]).then(([j,D])=>{const T=j.source==="explicit"?Vn(j.dataStructures||[],D):Bn(j.models||[],D);i(T.data),o(T.tabs),T.tabs.length>0&&!p&&R(T.tabs[0].dataKey)}).catch(()=>m("Failed to load scenario data")).finally(()=>S(!1))},[t,Z]),x)return e.jsx("div",{className:"mt-1 mb-1 border border-[#3d3d3d] rounded-lg p-4 text-xs text-gray-400",children:"Loading mock data..."});if(g||!c)return e.jsx("div",{className:"mt-1 mb-1 border border-[#3d3d3d] rounded-lg p-4 text-xs text-red-400",children:g||"No data available"});if(l.length===0)return e.jsxs("div",{className:"mt-1 mb-1 border border-[#3d3d3d] rounded-lg p-4 text-xs text-gray-500",children:["No mock data found for this scenario.",e.jsx("button",{onClick:s,className:"ml-2 text-gray-400 hover:text-white bg-transparent border-none cursor-pointer text-[10px]",children:"Dismiss"})]});const I=l.find(j=>j.dataKey===p)||l[0],V=p?c[p]||[]:[],W=zn(V,I.schemaFields),le=Un(W,V,I.schemaFields),v=Hn(W,I.schemaFields);return e.jsxs("div",{className:"mt-1 mb-1 border border-[#3d3d3d] rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1.5 bg-[#252525] border-b border-[#3d3d3d] flex-wrap",children:[l.map(j=>{const D=p===j.dataKey,T=j.category==="datastore"?D?"text-[#D7FF63] bg-[#D7FF63]/15 border-[#D7FF63]/40":"text-[#D7FF63]/60 bg-transparent border-transparent hover:text-[#D7FF63]/80":j.category==="mock-api"?D?"text-blue-400 bg-blue-400/15 border-blue-400/40":"text-blue-400/60 bg-transparent border-transparent hover:text-blue-400/80":D?"text-white bg-[#3d3d3d] border-[#4d4d4d]":"text-gray-500 bg-transparent border-transparent hover:text-gray-300";return e.jsx("button",{onClick:()=>R(j.dataKey),className:`px-2.5 py-0.5 text-[10px] font-semibold uppercase tracking-wider rounded cursor-pointer border transition-colors ${T}`,children:j.label},j.dataKey)}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:s,className:"w-5 h-5 flex items-center justify-center text-gray-500 hover:text-white bg-[#3d3d3d] hover:bg-[#4d4d4d] rounded-full border-none cursor-pointer text-xs transition-colors",title:"Close",children:"×"})]}),(I.description||I.category)&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 bg-[#1e1e1e] border-b border-[#2d2d2d]",children:[I.category&&e.jsx("span",{className:`text-[9px] rounded px-1.5 py-0 border ${I.category==="datastore"?"text-[#D7FF63]/80 bg-[#D7FF63]/10 border-[#D7FF63]/30":I.category==="mock-api"?"text-blue-400/80 bg-blue-400/10 border-blue-400/30":"text-gray-400 bg-gray-700/30 border-gray-600/30"}`,children:I.category==="mock-api"?"API Mock":I.category}),I.description&&e.jsx("span",{className:"text-[10px] text-gray-500",children:I.description})]}),W.length===0?e.jsx("div",{className:"px-3 py-4 text-[10px] text-gray-500 text-center",children:"No columns defined for this table"}):e.jsx("div",{className:"overflow-x-auto max-h-[300px] overflow-y-auto",children:e.jsxs("table",{className:"w-full text-[10px] border-collapse table-fixed",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-[#1e1e1e] sticky top-0 z-10",children:[e.jsx("th",{className:"text-right text-gray-600 font-normal px-2 py-1.5 border-b border-[#3d3d3d] w-8",children:"#"}),W.map(j=>e.jsxs("th",{className:"text-left px-2 py-1.5 border-b border-[#3d3d3d] whitespace-nowrap overflow-hidden",children:[j===v&&e.jsx("span",{className:"inline-block text-[8px] font-bold text-white bg-[#D7FF63] rounded px-1 py-0 mr-1.5 align-middle",children:"PK"}),e.jsx("span",{className:"text-gray-300 font-medium",children:j}),e.jsx("span",{className:"text-gray-600 font-normal ml-1",children:le[j]})]},j))]})}),e.jsx("tbody",{children:V.map((j,D)=>e.jsxs("tr",{className:"border-b border-[#2d2d2d] hover:bg-[#252525] group/row",children:[e.jsx("td",{className:"text-right text-gray-600 px-2 py-1.5 w-8 select-none",children:D+1}),W.map(T=>e.jsxs("td",{className:`px-2 py-1.5 overflow-hidden relative group/cell ${T===v?"text-[#D7FF63] font-medium":"text-gray-300"}`,title:String(j[T]??""),children:[e.jsx("span",{className:"truncate block whitespace-nowrap",children:j[T]===null?e.jsx("span",{className:"text-gray-600 italic",children:"null"}):typeof j[T]=="object"?e.jsx("span",{className:"text-gray-500",children:JSON.stringify(j[T])}):typeof j[T]=="number"?e.jsx("span",{className:"text-amber-400",children:String(j[T])}):String(j[T])}),e.jsx("button",{onClick:U=>{U.stopPropagation(),y({row:D,col:T});const Q=j[T]===null?"":typeof j[T]=="object"?JSON.stringify(j[T]):String(j[T]);C(Q),J(Q)},className:"absolute right-1 top-1/2 -translate-y-1/2 opacity-0 group-hover/cell:opacity-100 text-gray-500 hover:text-white bg-[#252525] border border-[#4d4d4d] rounded cursor-pointer p-0.5 transition-opacity",title:"Edit",children:e.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),e.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})})]},T))]},D))})]})}),f&&e.jsxs("div",{className:"border-t border-[#3d3d3d] bg-[#1e1e1e] px-3 py-2",children:[e.jsx("div",{className:"flex items-center gap-2 mb-1.5",children:e.jsxs("span",{className:"text-[10px] text-gray-400",children:["Editing"," ",e.jsx("strong",{className:"text-gray-200",children:f.col})," in row ",f.row+1]})}),e.jsx("textarea",{value:E,onChange:j=>{const D=j.target.value;C(D),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{_(I.dataKey,f.row,f.col,D)},600)},className:"w-full px-2 py-1.5 text-[11px] bg-[#252525] text-white border border-[#4d4d4d] rounded outline-none focus:border-[#D7FF63]/50 resize-y min-h-[60px] max-h-[200px] font-mono",autoFocus:!0,rows:E.length>100?4:2,onKeyDown:j=>{j.key==="Escape"&&A(),j.key==="Enter"&&(j.metaKey||j.ctrlKey)&&(M.current&&clearTimeout(M.current),_(I.dataKey,f.row,f.col,E),y(null))}}),e.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[e.jsx("button",{onClick:()=>{M.current&&clearTimeout(M.current),_(I.dataKey,f.row,f.col,E),y(null)},className:"px-3 py-1 text-[10px] font-medium text-[#1e1e1e] bg-[#D7FF63] rounded cursor-pointer border-none hover:bg-[#D7FF63]/80 transition-colors",children:"Save"}),e.jsx("button",{onClick:()=>A(),className:"px-3 py-1 text-[10px] text-gray-400 hover:text-white bg-transparent border-none cursor-pointer",children:"Cancel"}),e.jsxs("span",{className:"text-[9px] text-gray-600 ml-auto",children:["⌘","+Enter to save, Esc to cancel"]})]})]}),q&&!f&&e.jsxs("div",{className:"border-t border-[#3d3d3d] bg-amber-500/5 px-3 py-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-amber-400/80",children:"Data modified — recapture to update the screenshot"}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:()=>{F(!0),Promise.resolve().then(()=>(a&&a(),new Promise(j=>setTimeout(j,2e3)))).then(()=>fetch("/api/editor-capture-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioId:t})})).then(()=>w(!1)).catch(()=>{}).finally(()=>F(!1))},disabled:k,className:"px-3 py-1 text-[10px] font-medium text-white bg-amber-600 rounded cursor-pointer border-none hover:bg-amber-500 disabled:opacity-50 transition-colors",children:k?"Recapturing...":"Recapture Screenshot"})]}),n&&e.jsxs("div",{className:"border-t border-[#3d3d3d]",children:[e.jsx("div",{className:"flex justify-center py-2",children:e.jsx("button",{onClick:()=>N(!h),className:"px-3 py-1 text-[10px] font-medium text-[#D7FF63] border border-[#D7FF63]/40 rounded cursor-pointer transition-colors hover:bg-[#D7FF63]/10 bg-transparent",children:h?"Hide Claude":"Edit with Claude"})}),h&&e.jsx("div",{className:"border-t border-[#3d3d3d]",children:e.jsx($e,{prompt:n,height:400,onClose:()=>{N(!1),B(j=>j+1)}})})]})]});function A(){if(M.current&&clearTimeout(M.current),!!f){if(E!==O){if(c&&p){const j=c[p];if(j&&j[f.row]){let D=O;O===""?D="":O==="null"?D=null:O==="true"?D=!0:O==="false"?D=!1:isNaN(Number(O))||(D=Number(O));const T=[...j];T[f.row]={...T[f.row],[f.col]:D},i({...c,[p]:T})}}fetch("/api/editor-save-scenario-data",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioId:t,table:I.dataKey,rowIndex:f.row,column:f.col,value:O})}).then(()=>{a&&a()}).catch(()=>{})}y(null),w(!1)}}async function _(j,D,T,U){if(c&&p){const Q=c[p];if(Q&&Q[D]){let $=U;U==="null"?$=null:U==="true"?$=!0:U==="false"?$=!1:U!==""&&!isNaN(Number(U))&&($=Number(U));const L=[...Q];L[D]={...L[D],[T]:$},i({...c,[p]:L})}}w(!0);try{await fetch("/api/editor-save-scenario-data",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioId:t,table:j,rowIndex:D,column:T,value:U})}),a&&a()}catch{}}}function Zn(){const[t,s]=r.useState([]),[n,a]=r.useState([]),[c,i]=r.useState(!0),[l,o]=r.useState(null),[x,S]=r.useState(!1),[g,m]=r.useState(null);if(r.useEffect(()=>{fetch("/api/editor-schema").then(N=>N.json()).then(N=>{var f,y;m(N.source||null),N.source==="explicit"?(a(N.dataStructures||[]),((f=N.dataStructures)==null?void 0:f.length)>0&&o(N.dataStructures[0].name)):(s(N.models||[]),((y=N.models)==null?void 0:y.length)>0&&o(N.models[0].name))}).catch(()=>{}).finally(()=>i(!1))},[]),c)return e.jsx("div",{className:"text-xs text-gray-400 py-4",children:"Loading schema..."});if(!(g==="explicit"?n.length>0:t.length>0))return e.jsx("div",{className:"text-xs text-gray-500 py-4",children:"No data structure found. Use the chat below to have Claude analyze your codebase and generate one."});const R=g==="explicit"?sr(n):tr(t,g);return g==="explicit"?e.jsxs("div",{className:"space-y-2",children:[n.map(N=>{const f=l===N.name,y=N.category==="datastore"?"text-[#D7FF63]/80 bg-[#D7FF63]/10 border border-[#D7FF63]/30":N.category==="mock-api"?"text-blue-400/80 bg-blue-400/10 border border-blue-400/30":"text-gray-400 bg-gray-700/30 border border-gray-600/30";return e.jsxs("div",{className:"border border-[#3d3d3d] rounded-lg overflow-hidden",children:[e.jsxs("button",{onClick:()=>o(f?null:N.name),className:"w-full flex items-center gap-2 px-3 py-2 bg-[#252525] text-left cursor-pointer border-none transition-colors hover:bg-[#2a2a2a]",children:[e.jsx("svg",{className:`text-gray-500 transition-transform shrink-0 ${f?"rotate-90":""}`,width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M9 18l6-6-6-6"})}),e.jsx("span",{className:"text-xs font-semibold text-gray-200",children:N.name}),N.order===1&&e.jsx("span",{className:"text-[9px] text-amber-400/70",children:"Primary"}),e.jsx("span",{className:`text-[9px] rounded px-1.5 py-0 ${y}`,children:N.category==="mock-api"?"API Mock":N.category}),e.jsxs("span",{className:"text-[10px] text-gray-500",children:[N.fields.length," fields"]})]}),f&&e.jsxs("div",{className:"border-t border-[#3d3d3d]",children:[N.description&&e.jsx("div",{className:"px-3 py-1.5 text-[10px] text-gray-400 border-b border-[#2d2d2d]",children:N.description}),e.jsx("table",{className:"w-full text-[10px]",children:e.jsx("tbody",{children:N.fields.map(E=>e.jsxs("tr",{className:"border-b border-[#2d2d2d] last:border-b-0",children:[e.jsxs("td",{className:"px-3 py-1.5 text-gray-300 font-medium w-1/3",children:[E.isId&&e.jsx("span",{className:"text-amber-400 mr-1",title:"Primary key",children:"•"}),E.name]}),e.jsx("td",{className:"px-3 py-1.5 text-gray-500",children:E.type}),e.jsx("td",{className:"px-3 py-1.5 text-gray-600 w-16 text-right",children:E.required===!1?"optional":""})]},E.name))})})]})]},N.name)}),e.jsx("div",{className:"flex justify-center pt-2",children:e.jsx("button",{onClick:()=>S(!x),className:"px-4 py-1.5 text-[11px] font-medium text-[#D7FF63] border border-[#D7FF63]/40 rounded-lg cursor-pointer transition-colors hover:bg-[#D7FF63]/10 bg-transparent",children:x?"Hide Chat":"Chat with Claude about the Data Structure"})}),x&&e.jsx("div",{className:"border border-[#3d3d3d] rounded-lg overflow-hidden",children:e.jsx($e,{prompt:R,height:500,onClose:()=>S(!1)})})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(er,{prompt:`Analyze this codebase and generate a .codeyam/data-structure.json file that describes the app's data structures.
8
+ `)}function Xe({scenarioId:t,updatedAt:s,hasScreenshot:r,imgSrc:a,name:c,isActive:i,onSelect:l}){const o=t&&r,x=!t&&a;return e.jsxs("button",{onClick:l,className:"flex flex-col items-center gap-1 cursor-pointer group w-full",title:c,children:[e.jsx("div",{className:`w-full aspect-[16/10] rounded overflow-hidden border-2 transition-all bg-[#1a1a1a] ${i?"border-[#D7FF63]/40 ring-1 ring-[#D7FF63]/20":"border-transparent hover:border-[#4d4d4d]"}`,children:o?e.jsx(_e,{scenarioId:t,updatedAt:s,alt:c,className:"w-full h-full",imgClassName:"w-full h-full object-contain"}):x?e.jsx("img",{src:a,alt:c,className:"w-full h-full object-contain",loading:"lazy"}):e.jsx("div",{className:"w-full h-full bg-[#1a1a1a] flex items-center justify-center",children:e.jsx("span",{className:"text-[8px] text-gray-600",children:"No img"})})}),e.jsx("span",{className:`text-[10px] leading-tight text-center truncate w-full ${i?"text-white":"text-gray-500 group-hover:text-gray-300"}`,children:c})]})}function Ye({filePath:t}){return t?e.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[e.jsxs("a",{href:`/api/editor-file?path=${encodeURIComponent(t)}`,target:"_blank",rel:"noopener noreferrer",title:"Open file",className:"flex items-center gap-1.5 text-gray-500 hover:text-gray-300 transition-colors min-w-0",children:[e.jsx("span",{className:"text-sm truncate font-['IBM_Plex_Mono']",children:t}),e.jsx("svg",{className:"shrink-0",width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:e.jsx("path",{d:"M4.5 1.5H2.5C1.95 1.5 1.5 1.95 1.5 2.5V9.5C1.5 10.05 1.95 10.5 2.5 10.5H9.5C10.05 10.5 10.5 10.05 10.5 9.5V7.5M7.5 1.5H10.5M10.5 1.5V4.5M10.5 1.5L5 7",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})})]}),e.jsx(Te,{content:t,icon:!0,iconSize:12,className:"shrink-0 text-gray-500 hover:text-gray-300 transition-colors"})]}):null}function ks({name:t,scenarios:s,reason:r="missing"}){var i,l;const a=((i=s[0])==null?void 0:i.componentPath)||((l=s[0])==null?void 0:l.pageFilePath)||null,c=r==="incomplete"?[`The "${t}" entity exists but has not been fully analyzed — its components and functions cannot be displayed.`,"","Follow these steps:","",`Step 1: Check if "${t}" is in the glossary:`,` cat .codeyam/glossary.json | grep "${t}"`,"","If not found, add an entry to .codeyam/glossary.json:",` { "name": "${t}", "filePath": "${a||"FILL_IN_PATH"}", "description": "...", "returnType": "JSX.Element" }`,"","Step 2: Run: codeyam editor analyze-imports","","Step 3: Reload the editor page and verify components/functions appear."].join(`
9
+ `):[`The "${t}" ${s.some(o=>!o.componentName)?"page":"component"} is missing entity data in the CodeYam database. Its scenarios are hidden until this is fixed.`,"","IMPORTANT: Do NOT re-register scenarios — that would overwrite their screenshots. Instead, update the database and scenario JSON files directly.","","Follow these steps EXACTLY:","","Step 1: Run: codeyam editor analyze-imports","","Step 2: Fix this entity:","",Ss(t,s),"","Step 3: Reload the editor page in the browser and verify the scenarios appear."].join(`
10
+ `);return e.jsx(Te,{content:c,label:"Copy Fix Prompt",copiedLabel:"Copied!",className:"text-[10px] text-[#E0D400] hover:text-[#E0D400]/80 bg-transparent border border-[#E0D400]/30 rounded px-2 py-0.5 cursor-pointer transition-colors ml-2"})}function Xr({brokenEntities:t}){const[s,r]=n.useState(!1),a=n.useCallback(x=>{navigator.clipboard.writeText(x).then(()=>{r(!0),setTimeout(()=>r(!1),2e3)})},[]);if(t.length===0)return null;const c=t.reduce((x,S)=>x+S.scenarios.length,0),i=t.filter(x=>x.reason==="incomplete"),l=t.filter(x=>x.reason==="missing"),o=[`${t.length} entities are missing data in the CodeYam database. ${c} total scenario(s) are hidden until this is fixed.`,"","IMPORTANT: Do NOT re-register scenarios — that would overwrite their screenshots. Instead, update the database and scenario JSON files directly.","","Follow these steps EXACTLY:","",...i.length>0?["## Step 1: Add missing entries to the glossary","","Read `.codeyam/glossary.json` and check if these entities have entries. For each one that is missing, add an entry:","",...i.map(x=>{var b,m;const S=((b=x.scenarios[0])==null?void 0:b.componentPath)||((m=x.scenarios[0])==null?void 0:m.pageFilePath)||"FILL_IN_PATH";return`- "${x.name}" (filePath: "${S}")`}),"",'Each glossary entry needs: name, filePath, description, returnType (use "JSX.Element" for components/pages).',""]:["## Step 1: No glossary changes needed",""],"## Step 2: Run import analysis"," codeyam editor analyze-imports","",...l.length>0?["## Step 3: Fix missing entity associations","",...l.map(x=>Ss(x.name,x.scenarios)),""]:[],`## Step ${l.length>0?"4":"3"}: Reload the editor page in the browser and verify all scenarios appear. Then commit the updated scenario JSON files so the fix persists across clones.`].join(`
11
+ `);return e.jsx("div",{className:"p-4 rounded-lg border border-[#E0D400]/40 bg-[#E0D400]/8",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"#E0D400",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),e.jsxs("p",{className:"flex-1 min-w-0 text-sm text-[#E0D400]/90 m-0 leading-snug font-['IBM_Plex_Sans']",children:[t.length," ",t.length===1?"entity is":"entities are"," missing data, resulting in ",c," hidden scenario",c!==1?"s":"","."," ",e.jsx("button",{type:"button",className:"font-bold underline bg-transparent border-none text-[#E0D400] cursor-pointer p-0 text-sm inline hover:text-[#E0D400]/70 transition-colors",onClick:()=>a(o),children:s?e.jsxs("span",{className:"inline-flex items-center gap-1",children:["Copied",e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",className:"inline",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})})]}):"Copy this prompt"})," ","into Claude to fix them all at once."]}),e.jsx(Te,{content:o,label:e.jsxs("span",{className:"flex items-center gap-2",children:["COPY PROMPT",e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})]}),copiedLabel:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"invisible",children:"COPY PROMPT"}),e.jsx("span",{className:"absolute inset-0 flex items-center justify-center",children:"COPIED!"}),e.jsx("span",{className:"invisible",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",children:e.jsx("rect",{x:"9",y:"9",width:"13",height:"13"})})})]}),className:"relative text-xs font-semibold text-[#1e1e1e] bg-[#E0D400] hover:bg-[#E0D400]/80 border-none rounded px-4 py-2 cursor-pointer transition-colors shrink-0 tracking-wide font-['IBM_Plex_Mono']"})]})})}function Cs({focusedEntity:t,breadcrumbItems:s,onZoomChange:r,projectRoot:a,scenarios:c,analyzedEntities:i,activeScenarioId:l,onScenarioSelect:o,onAnalyzedScenarioSelect:x,onSwitchToBuild:S,entityImports:b,glossaryFunctions:m,glossaryEntries:p,entityShaMap:R,componentGroups:h,visualEntities:N,isEntityComplete:f,onReseedPreview:y}){var se;const E=t.filePath,P=t.name,[O,J]=n.useState("scenarios"),[Z,B]=n.useState(null),[q,w]=n.useState(""),[k,F]=n.useState(!1),[M,I]=n.useState(null),[V,W]=n.useState(!1),[ce,v]=n.useState(!1),[A,_]=n.useState(null);n.useEffect(()=>{J("scenarios"),B(null),W(!1),v(!1),_(null)},[t.sha]);const j=n.useMemo(()=>{const u=new Map;for(const H of m)u.set(H.name,H);return u},[m]),D=i.some(u=>u.sha===t.sha||u.filePath===E),T=!!((se=b==null?void 0:b[P])!=null&&se.length),U=n.useCallback(async u=>{if(!(!q.trim()||k)){F(!0);try{(await fetch("/api/editor-rename-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioId:u,name:q.trim()})})).ok&&B(null)}catch{}finally{F(!1)}}},[q,k]),Q=n.useCallback(async u=>{if(confirm(`Delete scenario "${u.name}"?`)){I(u.id);try{const H=u.screenshotPaths?Object.values(u.screenshotPaths):u.screenshotPath?[u.screenshotPath]:[];await fetch("/api/delete-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioId:u.id,screenshotPaths:H})})}catch{}finally{I(null)}}},[]);if(!D&&!T){const u=c.filter(Y=>Y.entitySha===t.sha),H=[`The "${t.displayName}" entity (${E}) exists in the database but has not been fully analyzed. Its components and functions cannot be shown until it has import metadata.`,"","Follow these steps:","",`Step 1: Add "${P}" to the glossary if it's not already there:`,` Check: cat .codeyam/glossary.json | grep "${P}"`,"",` If not found, add an entry with name "${P}" and filePath "${E}" to .codeyam/glossary.json`,"","Step 2: Run import analysis:"," codeyam editor analyze-imports","","Step 3: Reload the editor page and verify components/functions appear."].join(`
12
+ `);return e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsxs("div",{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>{if(s.length>1){const Y=s[s.length-2];r(Y.componentName,Y.entitySha)}else r()},className:"text-gray-400 hover:text-white transition-colors cursor-pointer bg-transparent border-none p-0 shrink-0 text-lg",title:"Go back",children:"←"}),e.jsx("h2",{className:"text-lg font-medium text-white m-0 font-['IBM_Plex_Sans']",children:t.displayName})]}),E&&e.jsx(Ye,{filePath:E,projectRoot:a}),e.jsxs("div",{className:"py-2",children:[e.jsx("p",{className:"text-[11px] text-amber-400/80 m-0 leading-relaxed",children:"This entity has not been fully analyzed. Its components and functions cannot be displayed. Please copy and paste this prompt into Claude to fix the data."}),e.jsx("div",{className:"mt-2",children:e.jsx(Te,{content:H,label:"Copy Fix Prompt",copiedLabel:"Copied!",className:"text-[10px] text-amber-400 hover:text-amber-300 bg-transparent border border-amber-400/30 rounded px-2 py-1 cursor-pointer transition-colors"})})]}),u.length>0&&e.jsx("div",{className:"grid grid-cols-3 gap-2",children:u.map(Y=>e.jsx(Xe,{scenarioId:Y.id,updatedAt:Y.updatedAt,hasScreenshot:!!Y.screenshotPath,name:Y.name,isActive:Y.id===l,onSelect:()=>o(Y)},Y.id))})]})})}const $=t.sha,L=c.filter(u=>!u.componentName&&(u.pageFilePath===E||$&&u.entitySha===$)),X=c.filter(u=>u.componentName===P||u.componentPath===E),ee=N.find(u=>u.filePath===E||u.name===P),K=j.get(P)||m.find(u=>u.filePath===E),G=[...L,...X],ue=n.useMemo(()=>{const u=[];if(u.push(`# Create a New Scenario for "${t.displayName}"`),u.push(""),u.push(`**Entity**: ${t.displayName}`),u.push(`**Type**: ${t.entityType}`),u.push(`**File**: ${E}`),u.push(""),G.length>0){u.push("## Existing Scenarios");for(const H of G)u.push(`- **${H.name}**${H.url?` — URL: ${H.url}`:""}`);u.push("")}return u.push("## Your Task"),u.push("Ask the user what scenario they would like to create. Offer two options:"),u.push("1. **Describe a scenario** — the user tells you what they want and you create it"),u.push("2. **Analyze gaps** — you review the existing scenarios and source code to suggest scenarios that would improve coverage"),u.push(""),u.push("Once you know what scenario to create, use the `codeyam editor register` CLI command to register it. Write the scenario JSON to `.codeyam/tmp/scenario.json` first, then run `codeyam editor register @.codeyam/tmp/scenario.json`."),u.join(`
13
+ `)},[t.displayName,t.entityType,E,G]),xe=new Set((b==null?void 0:b[P])||[]),pe=T?[...h.entries()].filter(([u])=>xe.has(u)):[],Be=T?N.filter(u=>xe.has(u.name)&&!pe.some(([H])=>H===u.name)):[],We=T?p.filter(u=>xe.has(u.name)&&u.returnType!=="JSX.Element"&&u.returnType!=="React.ReactNode").map(u=>({name:u.name,filePath:u.filePath,description:u.description||"",testFile:u.testFile,feature:u.feature})):[],be=pe.length>0||Be.length>0,ae=We.length>0;return e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsxs("div",{className:"p-5",children:[e.jsxs("div",{className:"mb-5",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("button",{onClick:()=>{if(s.length>1){const u=s[s.length-2];r(u.componentName,u.entitySha)}else r()},className:"text-gray-400 hover:text-white transition-colors cursor-pointer bg-transparent border-none p-0 shrink-0 text-xl",title:"Go back",children:"←"}),e.jsx("h2",{className:"text-xl font-medium text-white m-0 font-['IBM_Plex_Sans']",children:t.displayName})]}),t.filePath&&e.jsx("div",{className:"mt-1.5 ml-7",children:e.jsx(Ye,{filePath:t.filePath,projectRoot:a})})]}),e.jsx("div",{className:"-mx-5 px-5 border-t border-b border-[#3d3d3d] flex items-center gap-6",children:[["scenarios","Scenarios"],["components","Components"],["functions","Functions"],["data-structure","Data Structure"]].map(([u,H])=>e.jsx("button",{onClick:()=>J(u),className:`text-xs font-normal uppercase tracking-wider transition-colors bg-transparent border-none cursor-pointer px-0 font-['IBM_Plex_Mono'] border-b-2 leading-none ${O===u?"text-[#D7FF63] border-b-[#D7FF63]":"text-gray-500 hover:text-gray-300 border-b-transparent"}`,style:{marginBottom:-1,paddingTop:16,paddingBottom:14},children:H},u))}),O==="scenarios"&&e.jsxs("div",{className:"space-y-3 mt-5",children:[G.map(u=>{const H=u.id===l,Y=Z===u.id;return e.jsxs("div",{children:[e.jsxs("div",{onClick:()=>{Y||o(u)},className:`flex items-center gap-4 p-3 rounded-lg cursor-pointer transition-colors ${H?"bg-[#1a2e1a] border border-[#D7FF63]/40":"bg-[#252525] hover:bg-[#2a2a2a] border border-transparent"}`,style:{opacity:M===u.id?.4:1},children:[u.screenshotPath?e.jsx(_e,{scenarioId:u.id,updatedAt:u.updatedAt,alt:"",className:"rounded w-[160px] h-[100px] shrink-0 overflow-hidden border border-[#3d3d3d]",imgClassName:"w-full h-full object-cover"}):e.jsx("div",{className:"rounded bg-[#1a1a1a] w-[160px] h-[100px] shrink-0 flex items-center justify-center border border-[#3d3d3d]",children:e.jsx("span",{className:"text-[10px] text-gray-600",children:"No image"})}),e.jsx("div",{className:"flex-1 min-w-0",children:Y?e.jsxs("form",{className:"flex items-center gap-1.5",onSubmit:re=>{re.preventDefault(),U(u.id)},onClick:re=>re.stopPropagation(),children:[e.jsx("input",{type:"text",value:q,onChange:re=>w(re.target.value),className:"flex-1 px-2 py-1 text-xs bg-[#1e1e1e] text-white border border-[#3d3d3d] rounded outline-none focus:border-[#005c75] min-w-0",autoFocus:!0,disabled:k}),e.jsx("button",{type:"submit",disabled:k||!q.trim(),className:"px-2 py-1 text-[10px] bg-[#005c75] text-white rounded hover:bg-[#004d63] disabled:opacity-40 cursor-pointer border-none",children:k?"...":"Save"}),e.jsx("button",{type:"button",onClick:()=>B(null),className:"px-2 py-1 text-[10px] text-gray-400 hover:text-white cursor-pointer bg-transparent border-none",children:"Cancel"})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-xs text-gray-300 truncate block",children:u.name}),H&&e.jsxs("div",{className:"flex items-center gap-3 mt-1.5",children:[e.jsx("button",{onClick:re=>{re.stopPropagation(),_(A===u.id?null:u.id)},className:"text-[10px] text-[#D7FF63] hover:text-[#D7FF63]/70 cursor-pointer bg-transparent border-none p-0",children:"View Data"}),e.jsx("button",{onClick:re=>{re.stopPropagation(),v(!1),W(!0)},className:"text-[10px] text-gray-400 hover:text-white cursor-pointer bg-transparent border-none p-0",children:"Edit with Claude"}),e.jsx("button",{onClick:re=>{re.stopPropagation(),B(u.id),w(u.name)},className:"text-[10px] text-gray-400 hover:text-white cursor-pointer bg-transparent border-none p-0",children:"Rename"}),e.jsx("button",{onClick:re=>{re.stopPropagation(),Q(u)},disabled:M===u.id,className:"text-[10px] text-red-400/60 hover:text-red-400 cursor-pointer bg-transparent border-none p-0",children:"Delete"})]})]})})]}),A===u.id&&e.jsx(Qr,{scenarioId:u.id,onClose:()=>_(null),editPrompt:hs(t.displayName,t.filePath,t.entityType,G),onReseedPreview:y})]},u.id)}),ee&&(ee.scenarios.length>0||ee.pendingScenarios.length>0)&&e.jsxs("div",{className:"space-y-1 mt-2",children:[ee.scenarios.map(u=>e.jsxs("div",{onClick:()=>x({analysisId:ee.analysisId,scenarioId:u.id,scenarioName:u.name,entitySha:ee.sha,entityName:ee.name}),className:"flex items-center gap-3 p-2 rounded cursor-pointer transition-colors hover:bg-[#252525] border border-transparent",children:[u.screenshotPath?e.jsx("img",{src:`/api/screenshot/${u.screenshotPath}`,alt:u.name,className:"rounded w-[48px] h-[48px] shrink-0 object-cover",loading:"lazy"}):e.jsx("div",{className:"rounded bg-[#1a1a1a] w-[48px] h-[48px] shrink-0 flex items-center justify-center",children:e.jsx("span",{className:"text-[8px] text-gray-600",children:"No img"})}),e.jsx("span",{className:"text-xs text-gray-300 truncate",children:u.name})]},u.id)),ee.pendingScenarios.map(u=>e.jsxs("div",{className:"flex items-center gap-3 p-2",children:[e.jsx("div",{className:"rounded bg-[#1a1a1a] w-[48px] h-[48px] shrink-0 flex items-center justify-center",children:e.jsx("span",{className:"text-[8px] text-gray-600",children:"..."})}),e.jsx("span",{className:"text-xs text-gray-500 truncate",children:u})]},u))]}),G.length===0&&!ee&&!K&&e.jsx("div",{className:"text-xs text-gray-500 py-2",children:"No scenarios for this entity"}),e.jsxs("button",{onClick:()=>{W(!1),v(!0)},className:"flex items-center gap-2.5 mt-4 text-xs text-[#D7FF63] hover:text-[#D7FF63]/70 bg-transparent border-none cursor-pointer p-0 font-normal uppercase tracking-wider font-['IBM_Plex_Mono'] transition-colors",children:[e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"16"}),e.jsx("line",{x1:"8",y1:"12",x2:"16",y2:"12"})]}),"Create New Scenario"]}),ce&&e.jsx("div",{className:"mt-2 border border-[#3d3d3d] rounded-lg overflow-hidden",children:e.jsx($e,{prompt:ue,height:500,onClose:()=>v(!1)})}),V&&G.length>0&&e.jsx("div",{className:"mt-2 border border-[#3d3d3d] rounded-lg overflow-hidden",children:e.jsx($e,{prompt:hs(t.displayName,t.filePath,t.entityType,G),height:500,onClose:()=>W(!1)})})]}),O==="components"&&e.jsx("div",{className:"space-y-3",children:be?e.jsxs(e.Fragment,{children:[pe.map(([u,H])=>e.jsx("div",{children:R.has(u)?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"py-1",children:e.jsx("button",{onClick:()=>r(u,R.get(u)),className:"text-[11px] font-medium text-gray-400 cursor-pointer hover:text-white transition-colors bg-transparent border-none p-0",children:u})}),H.length>0&&e.jsx("div",{className:"grid grid-cols-3 gap-2 pt-1",children:H.map(Y=>e.jsx(Xe,{scenarioId:Y.id,updatedAt:Y.updatedAt,hasScreenshot:!!Y.screenshotPath,name:Y.name,isActive:Y.id===l,onSelect:()=>o(Y)},Y.id))})]}):e.jsxs("div",{className:"py-2",children:[e.jsx("span",{className:"text-[11px] font-medium text-gray-500",children:u}),e.jsx("p",{className:"text-[10px] text-amber-400/80 m-0 mt-1.5 leading-relaxed",children:"There is data missing that is required to show the scenarios for this component. Please copy and paste this prompt into Claude to ask Claude to fix the data."}),e.jsx("div",{className:"mt-1.5",children:e.jsx(ks,{name:u,scenarios:H})})]})},u)),Be.map(u=>e.jsxs("div",{children:[e.jsx("div",{className:"py-1",children:e.jsx("button",{onClick:()=>r(u.name,u.sha),className:"text-[11px] font-medium text-gray-400 cursor-pointer hover:text-white transition-colors bg-transparent border-none p-0",children:u.name})}),(u.scenarios.length>0||u.pendingScenarios.length>0)&&e.jsxs("div",{className:"grid grid-cols-3 gap-2 pt-1",children:[u.scenarios.map(H=>e.jsx(Xe,{imgSrc:H.screenshotPath?`/api/screenshot/${H.screenshotPath}`:null,name:H.name,isActive:!1,onSelect:()=>x({analysisId:u.analysisId,scenarioId:H.id,scenarioName:H.name,entitySha:u.sha,entityName:u.name})},H.id)),u.pendingScenarios.map(H=>e.jsx("div",{className:"px-2.5 py-1 bg-[#2a2a2a] text-gray-400 text-[10px] rounded-full",title:H,children:H},H))]})]},u.sha))]}):e.jsx("div",{className:"text-xs text-gray-500 py-2",children:"No component dependencies"})}),O==="functions"&&e.jsxs("div",{className:"space-y-3",children:[K&&K.testFile&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[10px] text-gray-500",children:"Tests:"}),e.jsx(Ye,{filePath:K.testFile,projectRoot:a})]}),e.jsx(Nt,{testFile:K.testFile,entityName:P})]}),ae?e.jsx("div",{children:We.map(u=>e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"py-1",children:e.jsx("button",{onClick:()=>r(u.name,R.get(u.name)),className:"text-[11px] font-medium text-gray-400 cursor-pointer hover:text-white transition-colors bg-transparent border-none p-0",children:u.name})}),e.jsx(Ye,{filePath:u.filePath,projectRoot:a}),u.testFile&&e.jsxs("div",{className:"mt-0.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[9px] text-gray-600",children:"test:"}),e.jsx("span",{className:"text-[9px] text-gray-500 truncate",children:u.testFile})]}),e.jsx(Nt,{testFile:u.testFile,entityName:u.name})]})]},u.name))}):K!=null&&K.testFile?null:e.jsx("div",{className:"text-xs text-gray-500 py-2",children:"No function dependencies"})]}),O==="data-structure"&&e.jsx(Zr,{})]})})}function Qr({scenarioId:t,onClose:s,editPrompt:r,onReseedPreview:a}){const[c,i]=n.useState(null),[l,o]=n.useState([]),[x,S]=n.useState(!0),[b,m]=n.useState(null),[p,R]=n.useState(null),[h,N]=n.useState(!1),[f,y]=n.useState(null),[E,P]=n.useState(""),[O,J]=n.useState(""),[Z,B]=n.useState(0),[q,w]=n.useState(!1),[k,F]=n.useState(!1),M=n.useRef(null);if(n.useEffect(()=>{S(!0),m(null),Promise.all([fetch("/api/editor-schema").then(j=>j.json()).catch(()=>({models:[]})),fetch(`/api/editor-scenario-data?scenarioId=${t}`).then(j=>j.json())]).then(([j,D])=>{const T=j.source==="explicit"?Vr(j.dataStructures||[],D):Br(j.models||[],D);i(T.data),o(T.tabs),T.tabs.length>0&&!p&&R(T.tabs[0].dataKey)}).catch(()=>m("Failed to load scenario data")).finally(()=>S(!1))},[t,Z]),x)return e.jsx("div",{className:"mt-1 mb-1 border border-[#3d3d3d] rounded-lg p-4 text-xs text-gray-400",children:"Loading mock data..."});if(b||!c)return e.jsx("div",{className:"mt-1 mb-1 border border-[#3d3d3d] rounded-lg p-4 text-xs text-red-400",children:b||"No data available"});if(l.length===0)return e.jsxs("div",{className:"mt-1 mb-1 border border-[#3d3d3d] rounded-lg p-4 text-xs text-gray-500",children:["No mock data found for this scenario.",e.jsx("button",{onClick:s,className:"ml-2 text-gray-400 hover:text-white bg-transparent border-none cursor-pointer text-[10px]",children:"Dismiss"})]});const I=l.find(j=>j.dataKey===p)||l[0],V=p?c[p]||[]:[],W=zr(V,I.schemaFields),ce=Ur(W,V,I.schemaFields),v=Hr(W,I.schemaFields);return e.jsxs("div",{className:"mt-1 mb-1 border border-[#3d3d3d] rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1.5 bg-[#252525] border-b border-[#3d3d3d] flex-wrap",children:[l.map(j=>{const D=p===j.dataKey,T=j.category==="datastore"?D?"text-[#D7FF63] bg-[#D7FF63]/15 border-[#D7FF63]/40":"text-[#D7FF63]/60 bg-transparent border-transparent hover:text-[#D7FF63]/80":j.category==="mock-api"?D?"text-blue-400 bg-blue-400/15 border-blue-400/40":"text-blue-400/60 bg-transparent border-transparent hover:text-blue-400/80":D?"text-white bg-[#3d3d3d] border-[#4d4d4d]":"text-gray-500 bg-transparent border-transparent hover:text-gray-300";return e.jsx("button",{onClick:()=>R(j.dataKey),className:`px-2.5 py-0.5 text-[10px] font-semibold uppercase tracking-wider rounded cursor-pointer border transition-colors ${T}`,children:j.label},j.dataKey)}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:s,className:"w-5 h-5 flex items-center justify-center text-gray-500 hover:text-white bg-[#3d3d3d] hover:bg-[#4d4d4d] rounded-full border-none cursor-pointer text-xs transition-colors",title:"Close",children:"×"})]}),(I.description||I.category)&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 bg-[#1e1e1e] border-b border-[#2d2d2d]",children:[I.category&&e.jsx("span",{className:`text-[9px] rounded px-1.5 py-0 border ${I.category==="datastore"?"text-[#D7FF63]/80 bg-[#D7FF63]/10 border-[#D7FF63]/30":I.category==="mock-api"?"text-blue-400/80 bg-blue-400/10 border-blue-400/30":"text-gray-400 bg-gray-700/30 border-gray-600/30"}`,children:I.category==="mock-api"?"API Mock":I.category}),I.description&&e.jsx("span",{className:"text-[10px] text-gray-500",children:I.description})]}),W.length===0?e.jsx("div",{className:"px-3 py-4 text-[10px] text-gray-500 text-center",children:"No columns defined for this table"}):e.jsx("div",{className:"overflow-x-auto max-h-[300px] overflow-y-auto",children:e.jsxs("table",{className:"w-full text-[10px] border-collapse table-fixed",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-[#1e1e1e] sticky top-0 z-10",children:[e.jsx("th",{className:"text-right text-gray-600 font-normal px-2 py-1.5 border-b border-[#3d3d3d] w-8",children:"#"}),W.map(j=>e.jsxs("th",{className:"text-left px-2 py-1.5 border-b border-[#3d3d3d] whitespace-nowrap overflow-hidden",children:[j===v&&e.jsx("span",{className:"inline-block text-[8px] font-bold text-white bg-[#D7FF63] rounded px-1 py-0 mr-1.5 align-middle",children:"PK"}),e.jsx("span",{className:"text-gray-300 font-medium",children:j}),e.jsx("span",{className:"text-gray-600 font-normal ml-1",children:ce[j]})]},j))]})}),e.jsx("tbody",{children:V.map((j,D)=>e.jsxs("tr",{className:"border-b border-[#2d2d2d] hover:bg-[#252525] group/row",children:[e.jsx("td",{className:"text-right text-gray-600 px-2 py-1.5 w-8 select-none",children:D+1}),W.map(T=>e.jsxs("td",{className:`px-2 py-1.5 overflow-hidden relative group/cell ${T===v?"text-[#D7FF63] font-medium":"text-gray-300"}`,title:String(j[T]??""),children:[e.jsx("span",{className:"truncate block whitespace-nowrap",children:j[T]===null?e.jsx("span",{className:"text-gray-600 italic",children:"null"}):typeof j[T]=="object"?e.jsx("span",{className:"text-gray-500",children:JSON.stringify(j[T])}):typeof j[T]=="number"?e.jsx("span",{className:"text-amber-400",children:String(j[T])}):String(j[T])}),e.jsx("button",{onClick:U=>{U.stopPropagation(),y({row:D,col:T});const Q=j[T]===null?"":typeof j[T]=="object"?JSON.stringify(j[T]):String(j[T]);P(Q),J(Q)},className:"absolute right-1 top-1/2 -translate-y-1/2 opacity-0 group-hover/cell:opacity-100 text-gray-500 hover:text-white bg-[#252525] border border-[#4d4d4d] rounded cursor-pointer p-0.5 transition-opacity",title:"Edit",children:e.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),e.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})})]},T))]},D))})]})}),f&&e.jsxs("div",{className:"border-t border-[#3d3d3d] bg-[#1e1e1e] px-3 py-2",children:[e.jsx("div",{className:"flex items-center gap-2 mb-1.5",children:e.jsxs("span",{className:"text-[10px] text-gray-400",children:["Editing"," ",e.jsx("strong",{className:"text-gray-200",children:f.col})," in row ",f.row+1]})}),e.jsx("textarea",{value:E,onChange:j=>{const D=j.target.value;P(D),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{_(I.dataKey,f.row,f.col,D)},600)},className:"w-full px-2 py-1.5 text-[11px] bg-[#252525] text-white border border-[#4d4d4d] rounded outline-none focus:border-[#D7FF63]/50 resize-y min-h-[60px] max-h-[200px] font-mono",autoFocus:!0,rows:E.length>100?4:2,onKeyDown:j=>{j.key==="Escape"&&A(),j.key==="Enter"&&(j.metaKey||j.ctrlKey)&&(M.current&&clearTimeout(M.current),_(I.dataKey,f.row,f.col,E),y(null))}}),e.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[e.jsx("button",{onClick:()=>{M.current&&clearTimeout(M.current),_(I.dataKey,f.row,f.col,E),y(null)},className:"px-3 py-1 text-[10px] font-medium text-[#1e1e1e] bg-[#D7FF63] rounded cursor-pointer border-none hover:bg-[#D7FF63]/80 transition-colors",children:"Save"}),e.jsx("button",{onClick:()=>A(),className:"px-3 py-1 text-[10px] text-gray-400 hover:text-white bg-transparent border-none cursor-pointer",children:"Cancel"}),e.jsxs("span",{className:"text-[9px] text-gray-600 ml-auto",children:["⌘","+Enter to save, Esc to cancel"]})]})]}),q&&!f&&e.jsxs("div",{className:"border-t border-[#3d3d3d] bg-amber-500/5 px-3 py-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-amber-400/80",children:"Data modified — recapture to update the screenshot"}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:()=>{F(!0),Promise.resolve().then(()=>(a&&a(),new Promise(j=>setTimeout(j,2e3)))).then(()=>fetch("/api/editor-capture-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioId:t})})).then(()=>w(!1)).catch(()=>{}).finally(()=>F(!1))},disabled:k,className:"px-3 py-1 text-[10px] font-medium text-white bg-amber-600 rounded cursor-pointer border-none hover:bg-amber-500 disabled:opacity-50 transition-colors",children:k?"Recapturing...":"Recapture Screenshot"})]}),r&&e.jsxs("div",{className:"border-t border-[#3d3d3d]",children:[e.jsx("div",{className:"flex justify-center py-2",children:e.jsx("button",{onClick:()=>N(!h),className:"px-3 py-1 text-[10px] font-medium text-[#D7FF63] border border-[#D7FF63]/40 rounded cursor-pointer transition-colors hover:bg-[#D7FF63]/10 bg-transparent",children:h?"Hide Claude":"Edit with Claude"})}),h&&e.jsx("div",{className:"border-t border-[#3d3d3d]",children:e.jsx($e,{prompt:r,height:400,onClose:()=>{N(!1),B(j=>j+1)}})})]})]});function A(){if(M.current&&clearTimeout(M.current),!!f){if(E!==O){if(c&&p){const j=c[p];if(j&&j[f.row]){let D=O;O===""?D="":O==="null"?D=null:O==="true"?D=!0:O==="false"?D=!1:isNaN(Number(O))||(D=Number(O));const T=[...j];T[f.row]={...T[f.row],[f.col]:D},i({...c,[p]:T})}}fetch("/api/editor-save-scenario-data",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioId:t,table:I.dataKey,rowIndex:f.row,column:f.col,value:O})}).then(()=>{a&&a()}).catch(()=>{})}y(null),w(!1)}}async function _(j,D,T,U){if(c&&p){const Q=c[p];if(Q&&Q[D]){let $=U;U==="null"?$=null:U==="true"?$=!0:U==="false"?$=!1:U!==""&&!isNaN(Number(U))&&($=Number(U));const L=[...Q];L[D]={...L[D],[T]:$},i({...c,[p]:L})}}w(!0);try{await fetch("/api/editor-save-scenario-data",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioId:t,table:j,rowIndex:D,column:T,value:U})}),a&&a()}catch{}}}function Zr(){const[t,s]=n.useState([]),[r,a]=n.useState([]),[c,i]=n.useState(!0),[l,o]=n.useState(null),[x,S]=n.useState(!1),[b,m]=n.useState(null);if(n.useEffect(()=>{fetch("/api/editor-schema").then(N=>N.json()).then(N=>{var f,y;m(N.source||null),N.source==="explicit"?(a(N.dataStructures||[]),((f=N.dataStructures)==null?void 0:f.length)>0&&o(N.dataStructures[0].name)):(s(N.models||[]),((y=N.models)==null?void 0:y.length)>0&&o(N.models[0].name))}).catch(()=>{}).finally(()=>i(!1))},[]),c)return e.jsx("div",{className:"text-xs text-gray-400 py-4",children:"Loading schema..."});if(!(b==="explicit"?r.length>0:t.length>0))return e.jsx("div",{className:"text-xs text-gray-500 py-4",children:"No data structure found. Use the chat below to have Claude analyze your codebase and generate one."});const R=b==="explicit"?sn(r):tn(t,b);return b==="explicit"?e.jsxs("div",{className:"space-y-2",children:[r.map(N=>{const f=l===N.name,y=N.category==="datastore"?"text-[#D7FF63]/80 bg-[#D7FF63]/10 border border-[#D7FF63]/30":N.category==="mock-api"?"text-blue-400/80 bg-blue-400/10 border border-blue-400/30":"text-gray-400 bg-gray-700/30 border border-gray-600/30";return e.jsxs("div",{className:"border border-[#3d3d3d] rounded-lg overflow-hidden",children:[e.jsxs("button",{onClick:()=>o(f?null:N.name),className:"w-full flex items-center gap-2 px-3 py-2 bg-[#252525] text-left cursor-pointer border-none transition-colors hover:bg-[#2a2a2a]",children:[e.jsx("svg",{className:`text-gray-500 transition-transform shrink-0 ${f?"rotate-90":""}`,width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M9 18l6-6-6-6"})}),e.jsx("span",{className:"text-xs font-semibold text-gray-200",children:N.name}),N.order===1&&e.jsx("span",{className:"text-[9px] text-amber-400/70",children:"Primary"}),e.jsx("span",{className:`text-[9px] rounded px-1.5 py-0 ${y}`,children:N.category==="mock-api"?"API Mock":N.category}),e.jsxs("span",{className:"text-[10px] text-gray-500",children:[N.fields.length," fields"]})]}),f&&e.jsxs("div",{className:"border-t border-[#3d3d3d]",children:[N.description&&e.jsx("div",{className:"px-3 py-1.5 text-[10px] text-gray-400 border-b border-[#2d2d2d]",children:N.description}),e.jsx("table",{className:"w-full text-[10px]",children:e.jsx("tbody",{children:N.fields.map(E=>e.jsxs("tr",{className:"border-b border-[#2d2d2d] last:border-b-0",children:[e.jsxs("td",{className:"px-3 py-1.5 text-gray-300 font-medium w-1/3",children:[E.isId&&e.jsx("span",{className:"text-amber-400 mr-1",title:"Primary key",children:"•"}),E.name]}),e.jsx("td",{className:"px-3 py-1.5 text-gray-500",children:E.type}),e.jsx("td",{className:"px-3 py-1.5 text-gray-600 w-16 text-right",children:E.required===!1?"optional":""})]},E.name))})})]})]},N.name)}),e.jsx("div",{className:"flex justify-center pt-2",children:e.jsx("button",{onClick:()=>S(!x),className:"px-4 py-1.5 text-[11px] font-medium text-[#D7FF63] border border-[#D7FF63]/40 rounded-lg cursor-pointer transition-colors hover:bg-[#D7FF63]/10 bg-transparent",children:x?"Hide Chat":"Chat with Claude about the Data Structure"})}),x&&e.jsx("div",{className:"border border-[#3d3d3d] rounded-lg overflow-hidden",children:e.jsx($e,{prompt:R,height:500,onClose:()=>S(!1)})})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(en,{prompt:`Analyze this codebase and generate a .codeyam/data-structure.json file that describes the app's data structures.
14
14
 
15
15
  The file should be a JSON array where each entry has:
16
16
  - "name": display name for the data structure
@@ -26,7 +26,7 @@ Look at:
26
26
  - API response types that need mocking
27
27
  - Do NOT include types that are only used as component props
28
28
 
29
- Write the file to .codeyam/data-structure.json.`}),t.map(N=>{const f=l===N.name,y=N.fields.filter(C=>C.isRelation),E=N.fields.filter(C=>!C.isRelation);return e.jsxs("div",{className:"border border-[#3d3d3d] rounded-lg overflow-hidden",children:[e.jsxs("button",{onClick:()=>o(f?null:N.name),className:"w-full flex items-center gap-2 px-3 py-2 bg-[#252525] text-left cursor-pointer border-none transition-colors hover:bg-[#2a2a2a]",children:[e.jsx("svg",{className:`text-gray-500 transition-transform ${f?"rotate-90":""}`,width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M9 18l6-6-6-6"})}),e.jsx("span",{className:"text-xs font-semibold text-gray-200",children:N.name}),e.jsxs("span",{className:"text-[10px] text-gray-500",children:[E.length," fields"]}),y.length>0&&e.jsxs("span",{className:"text-[10px] text-[#D7FF63]/70",children:[y.length," relation",y.length>1?"s":""]})]}),f&&e.jsx("div",{className:"border-t border-[#3d3d3d]",children:e.jsx("table",{className:"w-full text-[10px]",children:e.jsxs("tbody",{children:[E.map(C=>e.jsxs("tr",{className:"border-b border-[#2d2d2d] last:border-b-0",children:[e.jsxs("td",{className:"px-3 py-1.5 text-gray-300 font-medium w-1/3",children:[C.isId&&e.jsx("span",{className:"text-amber-400 mr-1",title:"Primary key",children:"•"}),C.name]}),e.jsxs("td",{className:"px-3 py-1.5 text-gray-500",children:[C.type,C.isOptional&&"?",C.isList&&"[]"]})]},C.name)),y.length>0&&e.jsx("tr",{children:e.jsxs("td",{colSpan:2,className:"px-3 py-1.5 border-t border-[#3d3d3d]",children:[e.jsx("span",{className:"text-[9px] text-gray-500 uppercase tracking-wider",children:"Relations"}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-1.5",children:y.map(C=>e.jsx("button",{onClick:()=>o(C.relatedModel??null),className:"text-[10px] text-[#D7FF63] hover:text-[#D7FF63]/80 bg-[#D7FF63]/10 border border-[#D7FF63]/30 rounded px-1.5 py-0.5 cursor-pointer transition-colors",children:C.isList?`${C.relatedModel}[]`:C.relatedModel},C.name))})]})})]})})})]},N.name)}),e.jsx("div",{className:"flex justify-center pt-2",children:e.jsx("button",{onClick:()=>S(!x),className:"px-4 py-1.5 text-[11px] font-medium text-[#D7FF63] border border-[#D7FF63]/40 rounded-lg cursor-pointer transition-colors hover:bg-[#D7FF63]/10 bg-transparent",children:x?"Hide Chat":"Chat with Claude about the Data Structure"})}),x&&e.jsx("div",{className:"border border-[#3d3d3d] rounded-lg overflow-hidden",children:e.jsx($e,{prompt:R,height:500,onClose:()=>S(!1)})})]})}function er({prompt:t}){const[s,n]=r.useState(!1),[a,c]=r.useState(()=>typeof window>"u"?!1:localStorage.getItem("codeyam-ds-migration-dismissed")==="1");return a?null:e.jsxs("div",{className:"relative border border-amber-500/30 bg-amber-500/5 rounded-lg p-3 pr-8",children:[e.jsx("button",{onClick:()=>{c(!0),localStorage.setItem("codeyam-ds-migration-dismissed","1")},className:"absolute top-2 right-2 text-gray-500 hover:text-white bg-transparent border-none cursor-pointer p-0.5",title:"Dismiss",children:e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:e.jsx("path",{d:"M2 2l8 8M10 2l-8 8"})})}),e.jsx("p",{className:"text-[11px] text-amber-400/90 m-0 font-['IBM_Plex_Sans'] leading-relaxed",children:"This data structure was auto-detected. For better results, ask Claude to generate an explicit data structure config."}),e.jsx("button",{onClick:()=>{navigator.clipboard.writeText(t),n(!0),setTimeout(()=>n(!1),2e3)},className:"mt-2 px-3 py-1 text-[10px] font-medium text-amber-400 border border-amber-500/40 rounded cursor-pointer transition-colors hover:bg-amber-500/10 bg-transparent",children:s?"Copied!":"Copy prompt for Claude"})]})}function tr(t,s){const n=t.map(c=>{const i=c.fields.map(l=>{let o=` ${l.name}: ${l.type}`;return l.isList&&(o+="[]"),l.isOptional&&(o+=" (optional)"),l.isId&&(o+=" [PK]"),l.isRelation&&(o+=` → ${l.relatedModel}`),o}).join(`
29
+ Write the file to .codeyam/data-structure.json.`}),t.map(N=>{const f=l===N.name,y=N.fields.filter(P=>P.isRelation),E=N.fields.filter(P=>!P.isRelation);return e.jsxs("div",{className:"border border-[#3d3d3d] rounded-lg overflow-hidden",children:[e.jsxs("button",{onClick:()=>o(f?null:N.name),className:"w-full flex items-center gap-2 px-3 py-2 bg-[#252525] text-left cursor-pointer border-none transition-colors hover:bg-[#2a2a2a]",children:[e.jsx("svg",{className:`text-gray-500 transition-transform ${f?"rotate-90":""}`,width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M9 18l6-6-6-6"})}),e.jsx("span",{className:"text-xs font-semibold text-gray-200",children:N.name}),e.jsxs("span",{className:"text-[10px] text-gray-500",children:[E.length," fields"]}),y.length>0&&e.jsxs("span",{className:"text-[10px] text-[#D7FF63]/70",children:[y.length," relation",y.length>1?"s":""]})]}),f&&e.jsx("div",{className:"border-t border-[#3d3d3d]",children:e.jsx("table",{className:"w-full text-[10px]",children:e.jsxs("tbody",{children:[E.map(P=>e.jsxs("tr",{className:"border-b border-[#2d2d2d] last:border-b-0",children:[e.jsxs("td",{className:"px-3 py-1.5 text-gray-300 font-medium w-1/3",children:[P.isId&&e.jsx("span",{className:"text-amber-400 mr-1",title:"Primary key",children:"•"}),P.name]}),e.jsxs("td",{className:"px-3 py-1.5 text-gray-500",children:[P.type,P.isOptional&&"?",P.isList&&"[]"]})]},P.name)),y.length>0&&e.jsx("tr",{children:e.jsxs("td",{colSpan:2,className:"px-3 py-1.5 border-t border-[#3d3d3d]",children:[e.jsx("span",{className:"text-[9px] text-gray-500 uppercase tracking-wider",children:"Relations"}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-1.5",children:y.map(P=>e.jsx("button",{onClick:()=>o(P.relatedModel??null),className:"text-[10px] text-[#D7FF63] hover:text-[#D7FF63]/80 bg-[#D7FF63]/10 border border-[#D7FF63]/30 rounded px-1.5 py-0.5 cursor-pointer transition-colors",children:P.isList?`${P.relatedModel}[]`:P.relatedModel},P.name))})]})})]})})})]},N.name)}),e.jsx("div",{className:"flex justify-center pt-2",children:e.jsx("button",{onClick:()=>S(!x),className:"px-4 py-1.5 text-[11px] font-medium text-[#D7FF63] border border-[#D7FF63]/40 rounded-lg cursor-pointer transition-colors hover:bg-[#D7FF63]/10 bg-transparent",children:x?"Hide Chat":"Chat with Claude about the Data Structure"})}),x&&e.jsx("div",{className:"border border-[#3d3d3d] rounded-lg overflow-hidden",children:e.jsx($e,{prompt:R,height:500,onClose:()=>S(!1)})})]})}function en({prompt:t}){const[s,r]=n.useState(!1),[a,c]=n.useState(()=>typeof window>"u"?!1:localStorage.getItem("codeyam-ds-migration-dismissed")==="1");return a?null:e.jsxs("div",{className:"relative border border-amber-500/30 bg-amber-500/5 rounded-lg p-3 pr-8",children:[e.jsx("button",{onClick:()=>{c(!0),localStorage.setItem("codeyam-ds-migration-dismissed","1")},className:"absolute top-2 right-2 text-gray-500 hover:text-white bg-transparent border-none cursor-pointer p-0.5",title:"Dismiss",children:e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:e.jsx("path",{d:"M2 2l8 8M10 2l-8 8"})})}),e.jsx("p",{className:"text-[11px] text-amber-400/90 m-0 font-['IBM_Plex_Sans'] leading-relaxed",children:"This data structure was auto-detected. For better results, ask Claude to generate an explicit data structure config."}),e.jsx("button",{onClick:()=>{navigator.clipboard.writeText(t),r(!0),setTimeout(()=>r(!1),2e3)},className:"mt-2 px-3 py-1 text-[10px] font-medium text-amber-400 border border-amber-500/40 rounded cursor-pointer transition-colors hover:bg-amber-500/10 bg-transparent",children:s?"Copied!":"Copy prompt for Claude"})]})}function tn(t,s){const r=t.map(c=>{const i=c.fields.map(l=>{let o=` ${l.name}: ${l.type}`;return l.isList&&(o+="[]"),l.isOptional&&(o+=" (optional)"),l.isId&&(o+=" [PK]"),l.isRelation&&(o+=` → ${l.relatedModel}`),o}).join(`
30
30
  `);return`${c.name}:
31
31
  ${i}`}).join(`
32
32
 
@@ -36,7 +36,7 @@ ${s==="prisma"?"The data structure is defined in `prisma/schema.prisma`.":s==="t
36
36
 
37
37
  Here is the current data structure:
38
38
 
39
- ${n}
39
+ ${r}
40
40
 
41
41
  Wait for the user to tell you what they want to do. They might want to:
42
42
  - Add new models/tables
@@ -50,14 +50,14 @@ ${s==="prisma"?"- Edit `prisma/schema.prisma` directly":"- Edit the TypeScript i
50
50
  - After schema changes, update any affected scenario seed data
51
51
  - Explain the impact of changes on existing data
52
52
 
53
- Do NOT start making changes until the user tells you what they want.`}function sr(t){return`You are helping the user understand and modify the data structure of their application.
53
+ Do NOT start making changes until the user tells you what they want.`}function sn(t){return`You are helping the user understand and modify the data structure of their application.
54
54
 
55
55
  The data structure is explicitly defined in \`.codeyam/data-structure.json\`.
56
56
 
57
57
  Here is the current data structure:
58
58
 
59
- ${t.map(n=>{const a=n.category==="datastore"?"[datastore]":n.category==="mock-api"?"[mock-api]":`[${n.category}]`,c=n.fields.map(l=>{let o=` ${l.name}: ${l.type}`;return l.isId&&(o+=" [PK]"),l.required===!1&&(o+=" (optional)"),o}).join(`
60
- `),i=n.description?` ${n.description}`:"";return`${n.name} ${a}${i?`
59
+ ${t.map(r=>{const a=r.category==="datastore"?"[datastore]":r.category==="mock-api"?"[mock-api]":`[${r.category}]`,c=r.fields.map(l=>{let o=` ${l.name}: ${l.type}`;return l.isId&&(o+=" [PK]"),l.required===!1&&(o+=" (optional)"),o}).join(`
60
+ `),i=r.description?` ${r.description}`:"";return`${r.name} ${a}${i?`
61
61
  ${i}`:""}
62
62
  ${c}`}).join(`
63
63
 
@@ -82,15 +82,15 @@ When making changes:
82
82
  - Update descriptions to reflect changes
83
83
  - After data structure changes, update affected scenario seed data
84
84
 
85
- Do NOT start making changes until the user tells you what they want.`}function nr(t,s,n=new Date){const a={"1d":1,"3d":3,"7d":7,"30d":30}[s],c=new Date(n);c.setDate(c.getDate()-a);const i=c.toISOString().split("T")[0],l=t.filter(m=>m.date>=i),o=new Set(l.map(m=>m.commitSha).filter(Boolean)),x=new Map;for(const m of l)if(m.scenarioScreenshots)for(const p of m.scenarioScreenshots){x.has(p.name)||x.set(p.name,[]);const R=x.get(p.name);R.some(h=>h.path===p.path)||R.push({path:p.path,time:m.time})}for(const m of x.values())m.sort((p,R)=>p.time.localeCompare(R.time));const S=[],g=new Map;for(const[m,p]of x){const R=m.indexOf(" - ");if(R!==-1){const h=m.slice(0,R);g.has(h)||g.set(h,[]),g.get(h).push({name:m,screenshots:p})}else S.push({name:m,screenshots:p})}return{commitCount:o.size,entryCount:l.length,appScenarios:S,componentGroups:g,totalScenarios:x.size}}function rr(t){const s=new Map;for(const n of[...t].reverse()){const a=s.get(n.date)||[];a.push(n),s.set(n.date,a)}return s}function ar(t){const s=new Map;for(const n of t){let a;if("componentName"in n&&n.componentName)a=n.componentName;else if("componentName"in n&&n.componentName===null)a="App";else{const i=n.name.indexOf(" - ");a=i!==-1?n.name.slice(0,i):"App"}const c=s.get(a)||[];c.push(n),s.set(a,c)}return[...s.entries()].sort(([n],[a])=>n==="App"?-1:a==="App"?1:n.localeCompare(a))}function hs({status:t}){const s={new:{label:"New",bg:"bg-green-900/40",text:"text-green-400",border:"border-green-700/50"},edited:{label:"Edited",bg:"bg-blue-900/40",text:"text-blue-400",border:"border-blue-700/50"},impacted:{label:"Impacted",bg:"bg-amber-900/40",text:"text-amber-400",border:"border-amber-700/50"}}[t.status];return e.jsx("span",{className:`${s.bg} ${s.text} ${s.border} border text-[8px] font-bold px-1 py-0 rounded-full uppercase tracking-wider`,children:s.label})}function ir({testFile:t,entityName:s}){const{results:n,isRunning:a,runTests:c}=Nt(t);if(a&&!n)return e.jsxs("div",{className:"pt-1 flex items-center gap-1.5",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-[#00a0c4] animate-pulse"}),e.jsx("span",{className:"text-[10px] text-gray-500",children:"Running tests..."})]});if(!n)return null;if(n.status==="error")return e.jsx("div",{className:"pt-1",children:e.jsx("span",{className:"text-[10px] text-red-400",children:n.errorMessage})});const i=s?n.testCases.filter(x=>x.fullName.startsWith(s)):n.testCases,l=i.length>0?i:n.testCases;if(l.length===0)return null;const o=s?`${s} > `:"";return e.jsxs("div",{className:"pt-1 space-y-0.5",children:[l.map(x=>{var g;const S=o&&x.fullName.startsWith(o)?x.fullName.slice(o.length):x.fullName;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[x.status==="passed"?e.jsx("span",{className:"text-green-400 text-[10px]",children:"✓"}):x.status==="failed"?e.jsx("span",{className:"text-red-400 text-[10px]",children:"✗"}):e.jsx("span",{className:"text-gray-500 text-[10px]",children:"—"}),e.jsx("span",{className:`text-[10px] ${x.status==="passed"?"text-green-400":x.status==="failed"?"text-red-400":"text-gray-500"}`,children:S})]}),x.status==="failed"&&((g=x.failureMessages)==null?void 0:g.map((m,p)=>e.jsx("div",{className:"pl-4 text-[9px] text-red-400/70 truncate max-w-full",title:m,children:m.split(`
86
- `)[0]},p)))]},x.fullName)}),e.jsx("button",{onClick:c,disabled:a,className:"mt-1 text-[10px] text-[#00a0c4] hover:text-[#38bdf8] transition-colors cursor-pointer disabled:opacity-50 bg-transparent border-none p-0",children:a?"Running...":"Re-run"})]})}const or={added:"text-green-400",untracked:"text-green-400",modified:"text-blue-400",renamed:"text-purple-400"};function lr({files:t}){return e.jsxs("div",{className:"border-t border-[#3d3d3d] pt-2 mt-1",children:[e.jsxs("span",{className:"text-[10px] font-semibold text-gray-500 uppercase tracking-wider",children:["Modified Files (",t.length,")"]}),e.jsx("div",{className:"mt-1 space-y-0.5 max-h-[150px] overflow-auto",children:t.map(s=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`text-[9px] font-bold uppercase w-[14px] text-center ${or[s.status]||"text-gray-500"}`,children:s.status==="added"||s.status==="untracked"?"A":s.status==="modified"?"M":s.status==="renamed"?"R":"?"}),e.jsx("span",{className:"text-[10px] text-gray-400 truncate font-mono",children:s.path})]},s.path))})]})}const cr={feature:{label:"Feature",color:"bg-[#005c75]"},fix:{label:"Fix",color:"bg-amber-700"},refactor:{label:"Refactor",color:"bg-purple-700"},scaffold:{label:"Scaffold",color:"bg-green-700"},data:{label:"Data",color:"bg-blue-700"},milestone:{label:"Milestone",color:"bg-yellow-600"}};function dr(t){try{return new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return""}}function xr(t){try{return new Date(t+"T00:00:00").toLocaleDateString([],{weekday:"long",month:"long",day:"numeric"})}catch{return t}}const ur=[{value:"1d",label:"1 Day"},{value:"3d",label:"3 Days"},{value:"7d",label:"1 Week"},{value:"30d",label:"1 Month"}];function mr({entries:t,onScreenshotClick:s}){const[n,a]=r.useState(!1),[c,i]=r.useState("7d"),l=r.useMemo(()=>nr(t,c),[t,c]);return e.jsxs("div",{className:"bg-[#2d2d2d] rounded-lg overflow-hidden",children:[e.jsxs("button",{onClick:()=>a(!n),className:"w-full flex items-center justify-between px-3 py-2.5 cursor-pointer bg-transparent border-none text-left hover:bg-[#333] transition-colors",children:[e.jsx("span",{className:"text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Timeframe Summary"}),e.jsx("span",{className:`text-gray-500 text-[10px] transition-transform ${n?"rotate-180":""}`,children:"▼"})]}),n&&e.jsxs("div",{className:"px-3 pb-3 space-y-3 border-t border-[#3d3d3d]",children:[e.jsx("div",{className:"flex gap-1 pt-2.5",children:ur.map(o=>e.jsx("button",{onClick:()=>i(o.value),className:`px-2.5 py-1 text-[10px] font-medium rounded transition-colors cursor-pointer border ${c===o.value?"bg-[#005c75] text-white border-[#005c75]":"bg-transparent text-gray-400 border-[#4d4d4d] hover:text-white hover:border-[#005c75]"}`,children:o.label},o.value))}),e.jsxs("div",{className:"flex items-center gap-3 text-[11px] text-gray-400",children:[e.jsxs("span",{children:[e.jsx("span",{className:"text-white font-medium",children:l.commitCount})," ",l.commitCount===1?"commit":"commits"]}),e.jsx("span",{className:"text-[#3d3d3d]",children:"|"}),e.jsxs("span",{children:[e.jsx("span",{className:"text-white font-medium",children:l.totalScenarios})," ",l.totalScenarios===1?"scenario changed":"scenarios changed"]}),e.jsx("span",{className:"text-[#3d3d3d]",children:"|"}),e.jsxs("span",{children:[e.jsx("span",{className:"text-white font-medium",children:l.entryCount})," ",l.entryCount===1?"entry":"entries"]})]}),l.totalScenarios===0?e.jsx("p",{className:"text-[11px] text-gray-500 italic m-0",children:"No scenario changes in this period."}):e.jsxs("div",{className:"space-y-3",children:[l.appScenarios.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("span",{className:"text-[10px] font-semibold text-gray-500 uppercase tracking-wider",children:"Application"}),l.appScenarios.map(o=>e.jsx(ps,{scenario:o,onScreenshotClick:s},o.name))]}),l.componentGroups.size>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("span",{className:"text-[10px] font-semibold text-gray-500 uppercase tracking-wider",children:"Components"}),[...l.componentGroups.entries()].sort(([o],[x])=>o.localeCompare(x)).map(([o,x])=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{className:"text-[10px] font-medium text-gray-400",children:o}),x.map(S=>e.jsx(ps,{scenario:S,onScreenshotClick:s},S.name))]},o))]})]})]})]})}function ps({scenario:t,onScreenshotClick:s}){const n=t.name.indexOf(" - "),a=n!==-1?t.name.slice(n+3):t.name;return e.jsxs("div",{className:"pl-2",children:[e.jsx("span",{className:"text-[10px] text-gray-500 block mb-1",children:a}),e.jsx("div",{className:"flex items-center gap-1 overflow-x-auto",children:t.screenshots.map((c,i)=>e.jsxs("div",{className:"flex items-center shrink-0",children:[i>0&&e.jsx("span",{className:"text-[8px] text-gray-600 mx-0.5",children:"→"}),e.jsx("button",{type:"button",className:"w-16 h-16 rounded overflow-hidden border border-[#3d3d3d] hover:border-[#00a0c4] bg-[#1e1e1e] shrink-0 flex items-center justify-center cursor-pointer transition-colors",title:`${t.name} (${new Date(c.time).toLocaleDateString()})`,onClick:()=>s==null?void 0:s({screenshotUrl:`/api/editor-journal-image/${c.path.replace("screenshots/","")}`,commitSha:null,commitMessage:null,scenarioName:t.name}),children:e.jsx("img",{src:`/api/editor-journal-image/${c.path.replace("screenshots/","")}`,alt:t.name,className:"max-w-full max-h-full object-contain",loading:"lazy"})})]},c.path))})]})}function hr({isActive:t,onScreenshotClick:s,glossaryFunctions:n=[]}){const[a,c]=r.useState([]),[i,l]=r.useState(!0),[o,x]=r.useState(new Set),S=r.useCallback(p=>{x(R=>{const h=new Set(R);return h.has(p)?h.delete(p):h.add(p),h})},[]),g=r.useCallback(async()=>{try{const p=await fetch("/api/editor-journal");if(p.ok){const R=await p.json();c(R.entries||[])}}catch{}finally{l(!1)}},[]);if(r.useEffect(()=>{g()},[g]),r.useEffect(()=>{t&&g()},[t,g]),r.useEffect(()=>{if(!t)return;const p=setInterval(()=>void g(),5e3);return()=>clearInterval(p)},[t,g]),i)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx("span",{className:"text-gray-500 text-sm",children:"Loading journal..."})});if(a.length===0)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center text-gray-500 px-8",children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:"No journal entries yet"}),e.jsx("p",{className:"text-xs",children:"Journal entries will appear as you build. Claude records features, screenshots, and commits as the project evolves."})]})});const m=rr(a);return e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsxs("div",{className:"p-3 space-y-4",children:[e.jsx(mr,{entries:a,onScreenshotClick:s}),[...m.entries()].map(([p,R])=>e.jsxs("div",{children:[e.jsx("div",{className:"px-3 py-1.5 sticky top-0 bg-[#1e1e1e] z-10",children:e.jsx("span",{className:"text-[10px] font-semibold text-gray-500 uppercase tracking-wider",children:xr(p)})}),e.jsx("div",{className:"space-y-2",children:R.map((h,N)=>{const f=cr[h.type]||{label:h.type,color:"bg-gray-600"},y=`${h.time}-${N}`,E=o.has(y);return e.jsxs("div",{className:"bg-[#2d2d2d] rounded-lg overflow-hidden",children:[e.jsxs("div",{className:`p-3 space-y-2 ${E?"":"max-h-[300px] overflow-y-auto"}`,children:[e.jsx("div",{className:"flex items-start gap-2 cursor-pointer",onClick:()=>S(y),children:e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-white truncate",children:h.title}),e.jsx("span",{className:`${f.color} text-white text-[9px] font-bold px-1.5 py-0.5 rounded uppercase tracking-wider shrink-0`,children:f.label})]}),e.jsx("span",{className:"text-[10px] text-gray-500",children:dr(h.time)}),h.featureName&&e.jsx("span",{className:"text-[10px] text-gray-500 italic truncate",title:h.featureName,children:h.featureName})]})}),h.userPrompt&&e.jsx(Ns,{text:h.userPrompt,theme:"dark"}),e.jsx("p",{className:"text-xs text-gray-400 leading-relaxed",children:h.description}),h.screenshot&&e.jsx("button",{type:"button",className:"rounded overflow-hidden border border-[#3d3d3d] hover:border-[#00a0c4] bg-[#1e1e1e] flex items-center justify-center p-1 cursor-pointer transition-colors w-full",onClick:()=>s==null?void 0:s({screenshotUrl:`/api/editor-journal-image/${h.screenshot.replace("screenshots/","")}`,commitSha:h.commitSha,commitMessage:h.commitMessage,scenarioName:h.title}),children:e.jsx("img",{src:`/api/editor-journal-image/${h.screenshot.replace("screenshots/","")}`,alt:h.title,className:"max-w-full max-h-full object-contain",loading:"lazy"})}),h.scenarioScreenshots&&h.scenarioScreenshots.length>0&&(()=>{const C=ar(h.scenarioScreenshots),O=h.entityChangeStatus,J=C.filter(([k])=>k==="App").flatMap(([,k])=>k),Z=C.filter(([k])=>k!=="App"),B=new Map;for(const k of J){const F=k,M=F.pageFilePath?Oe(Re(F.pageFilePath)):Qe(F.url??null),I=B.get(M)||[];I.push(k),B.set(M,I)}const q=[...B.entries()],w=k=>e.jsx("button",{type:"button",className:"w-[4.5rem] h-[4.5rem] rounded overflow-hidden border border-[#3d3d3d] hover:border-[#00a0c4] bg-[#1e1e1e] shrink-0 flex items-center justify-center cursor-pointer transition-colors",onClick:()=>s==null?void 0:s({screenshotUrl:`/api/editor-journal-image/${k.path.replace("screenshots/","")}`,commitSha:h.commitSha,commitMessage:h.commitMessage,scenarioName:k.name}),children:e.jsx("img",{src:`/api/editor-journal-image/${k.path.replace("screenshots/","")}`,alt:k.name,title:k.name,className:"max-w-full max-h-full object-contain",loading:"lazy"})},k.path);return e.jsxs("div",{className:"space-y-2",children:[q.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{className:"text-[10px] font-semibold text-gray-500 uppercase tracking-wider",children:"Application"}),q.map(([k,F])=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[10px] font-medium text-gray-400",children:k}),(O==null?void 0:O[k])&&e.jsx(hs,{status:O[k]})]}),e.jsx("div",{className:"flex flex-wrap gap-1 mt-0.5",children:F.map(w)})]},k))]}),Z.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{className:"text-[10px] font-semibold text-gray-500 uppercase tracking-wider",children:"Components"}),Z.map(([k,F])=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[10px] font-medium text-gray-400",children:k}),(O==null?void 0:O[k])&&e.jsx(hs,{status:O[k]})]}),e.jsx("div",{className:"flex flex-wrap gap-1 mt-0.5",children:F.map(w)})]},k))]})]})})(),n.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{className:"text-[10px] font-semibold text-gray-500 uppercase tracking-wider",children:"Functions"}),e.jsx("div",{className:"space-y-2",children:n.map(C=>e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] font-medium text-gray-200",children:C.name}),e.jsx("span",{className:"text-[9px] text-gray-500 truncate block",children:C.filePath}),C.testFile?e.jsx(ir,{testFile:C.testFile,entityName:C.name}):e.jsx("div",{className:"pt-1",children:e.jsx("span",{className:"text-[10px] text-gray-500",children:"No test file"})})]},C.name))})]}),h.commitSha&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px]",children:[e.jsx("span",{className:"font-mono text-[#00a0c4] bg-[#00a0c4]/10 px-1.5 py-0.5 rounded",children:h.commitSha.slice(0,7)}),e.jsx("span",{className:"text-gray-500 truncate",children:h.commitMessage})]}),E&&h.modifiedFiles&&h.modifiedFiles.length>0&&e.jsx(lr,{files:h.modifiedFiles})]}),e.jsxs("button",{onClick:()=>S(y),className:"w-full py-1.5 text-[10px] text-gray-500 hover:text-gray-300 border-t border-[#3d3d3d] transition-colors cursor-pointer",children:["——— ",E?"Collapse":"Expand"," ———"]})]},y)})})]},p))]})})}function pr({hasProject:t,scenarios:s,analyzedEntities:n,allEntities:a=[],glossaryFunctions:c=[],glossaryEntries:i=[],projectRoot:l,activeScenarioId:o,onScenarioSelect:x,onAnalyzedScenarioSelect:S,onSwitchToBuild:g,zoomComponent:m,focusedEntity:p,onZoomChange:R,entityImports:h,pageFilePaths:N={},projectTitle:f,projectDescription:y,migrationMode:E="none",migrationState:C,onStartMigration:O,breadcrumbItems:J=[],onReseedPreview:Z}){const{pageGroups:B,componentGroups:q}=r.useMemo(()=>wt(s),[s]),w=r.useMemo(()=>vs(B,q),[B,q]),k=r.useMemo(()=>new Set(n.map(L=>L.sha)),[n]),F=r.useMemo(()=>Jn(h||{}),[h]),M=r.useCallback(L=>Kn(L,k,a,F),[k,a,F]),I=r.useMemo(()=>{const L=new Map;for(const X of a)L.set(X.sha,X.name);return L},[a]),V=r.useMemo(()=>Gn(B,q,w,M),[B,q,w,M]),W=r.useMemo(()=>n.filter(L=>L.entityType==="visual").sort((L,X)=>L.name.localeCompare(X.name)),[n]),[le,v]=r.useState(()=>{try{return localStorage.getItem("codeyam-app-banner-dismissed")==="true"}catch{return!1}}),A=r.useCallback(()=>{v(!0);try{localStorage.setItem("codeyam-app-banner-dismissed","true")}catch{}},[]),[_,j]=r.useState(""),D=r.useRef(null),T=r.useRef(0),U=r.useCallback(()=>{D.current&&(T.current=D.current.scrollTop)},[]);r.useEffect(()=>{D.current&&T.current>0&&(D.current.scrollTop=T.current)});const Q=(p==null?void 0:p.sha)??"overview";if(!t)return e.jsx("div",{className:"flex-1 flex items-center justify-center font-['IBM_Plex_Sans']",children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx("h2",{className:"text-lg font-medium text-white m-0",children:"Ready to build something?"}),e.jsx("button",{onClick:g,className:"px-6 py-3 bg-[#005c75] text-white text-sm font-medium rounded-lg hover:bg-[#004d63] transition-colors cursor-pointer",children:"Start Building"})]})});if(E==="candidate")return e.jsx("div",{className:"flex-1 flex items-center justify-center font-['IBM_Plex_Sans']",children:e.jsxs("div",{className:"flex flex-col items-center gap-5 px-8 text-center max-w-[420px]",children:[e.jsx("h2",{className:"text-lg font-medium text-white m-0",children:"Migrate Your Project"}),e.jsx("p",{className:"text-sm text-gray-400 m-0 leading-relaxed",children:"It looks like you have an existing project. Claude can survey your codebase and systematically migrate it — deconstructing pages into clean components, extracting functions with tests, and creating scenarios. One page per session."}),e.jsx("button",{onClick:O,className:"px-6 py-3 bg-[#005c75] text-white text-sm font-medium rounded-lg hover:bg-[#004d63] transition-colors cursor-pointer",children:"Get Started"}),e.jsx("button",{onClick:g,className:"text-xs text-gray-500 hover:text-gray-300 bg-transparent border-none p-0 cursor-pointer underline",children:"Skip — build a new feature instead"})]})});if(E==="active"&&C){const L=C.pages||[],X=L.filter(G=>G.status==="complete").length,ee=L.length,K=ee>0?Math.round(X/ee*100):0;return e.jsxs("div",{className:"flex-1 flex flex-col overflow-auto p-4 font-['IBM_Plex_Sans']",children:[e.jsx("h2",{className:"text-lg font-medium text-white m-0 mb-3",children:"Project Migration"}),e.jsxs("div",{className:"mb-4",children:[e.jsx("div",{className:"flex items-center gap-2 mb-1",children:e.jsxs("span",{className:"text-xs text-gray-400",children:[X,"/",ee," pages (",K,"%)"]})}),e.jsx("div",{className:"w-full h-1.5 bg-[#2d2d2d] rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-[#005c75] rounded-full transition-all",style:{width:`${K}%`}})})]}),e.jsx("div",{className:"space-y-1.5",children:L.map((G,ue)=>{const xe=G.status==="complete"?"✓":G.status==="in-progress"?"→":"○",he=G.status==="complete"?"text-green-400":G.status==="in-progress"?"text-cyan-400":"text-gray-600";return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`text-xs ${he} w-3 text-center`,children:xe}),e.jsx("span",{className:`text-xs ${G.status==="in-progress"?"text-white font-medium":G.status==="complete"?"text-gray-400":"text-gray-600"}`,children:G.name}),e.jsx("span",{className:"text-[10px] text-gray-600",children:G.route}),G.status==="complete"&&e.jsxs("span",{className:"text-[10px] text-gray-600",children:[(G.extractedComponents||[]).length,"c"," ",(G.extractedFunctions||[]).length,"f"," ",G.scenarioCount||0,"s"]})]},ue)})}),(C.sharedComponents||[]).length>0&&e.jsxs("div",{className:"mt-4",children:[e.jsx("h3",{className:"text-xs font-medium text-gray-400 mb-1.5",children:"Shared Components"}),(C.sharedComponents||[]).map((G,ue)=>e.jsxs("div",{className:"text-[10px] text-gray-500 mb-0.5",children:[G.name," ",e.jsxs("span",{className:"text-gray-600",children:["— used in: ",(G.usedInPages||[]).join(", ")]})]},ue))]}),e.jsx("div",{className:"mt-4",children:e.jsx("button",{onClick:g,className:"px-4 py-2 bg-[#005c75] text-white text-xs font-medium rounded-lg hover:bg-[#004d63] transition-colors cursor-pointer",children:"Continue in Chat"})})]})}return s.length>0||W.length>0?p?e.jsx(ks,{focusedEntity:p,breadcrumbItems:J,onZoomChange:R,projectRoot:l,scenarios:s,analyzedEntities:n,activeScenarioId:o,onScenarioSelect:x,onAnalyzedScenarioSelect:S,onSwitchToBuild:g,entityImports:h,glossaryFunctions:c,glossaryEntries:i,entityShaMap:w,componentGroups:q,visualEntities:W,isEntityComplete:M,onReseedPreview:Z}):e.jsx("div",{ref:D,onScroll:U,className:"flex-1 overflow-auto font-['IBM_Plex_Sans']",children:e.jsxs("div",{className:"p-4 space-y-4",children:[V.length>1&&e.jsx(Xn,{brokenEntities:V}),!le&&e.jsxs("div",{className:"relative border border-[#2e7d32]/40 bg-cybg rounded-lg p-4 pr-10",children:[e.jsx("button",{onClick:A,className:"absolute top-3 right-3 text-[#D7FF63] hover:text-white bg-transparent border-none cursor-pointer p-0.5",title:"Dismiss",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:e.jsx("path",{d:"M2 2l8 8M10 2l-8 8"})})}),e.jsx("p",{className:"text-sm text-white font-medium m-0 leading-snug",children:"These are all the pages in your project."}),e.jsxs("p",{className:"text-sm text-gray-400 m-0 leading-snug mt-0.5",children:["(1) Select a scenario below and switch to"," ",e.jsx("button",{type:"button",onClick:g,className:"underline text-[#D7FF63] bg-transparent border-none cursor-pointer p-0 text-sm inline hover:text-[#D7FF63]/70 transition-colors",children:"build"})," ","to change or enhance an existing page."]}),e.jsx("p",{className:"text-sm text-gray-400 m-0 leading-snug mt-0.5",children:"(2) Select a page to see all of its sub-components and edit scenarios."})]}),B.size>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-3 font-['IBM_Plex_Mono']",children:[e.jsx("span",{className:"text-xs font-bold text-gray-400 uppercase tracking-wider shrink-0",children:"Pages"}),e.jsx("div",{className:"flex-1"}),e.jsxs("div",{className:"relative",style:{width:170},children:[e.jsxs("svg",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-500",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("path",{d:"M21 21l-4.35-4.35"})]}),e.jsx("input",{type:"text",placeholder:"SEARCH...",value:_,onChange:L=>j(L.target.value),className:"w-full pl-9 pr-3 py-2 text-xs bg-[#2a2a2a] border border-[#3d3d3d] rounded-md text-gray-300 placeholder-gray-600 outline-none focus:border-[#D7FF63]/50 transition-colors tracking-wider"})]}),e.jsxs("button",{onClick:g,className:"flex items-center gap-1.5 px-4 py-2 text-xs font-semibold text-[#1e1e1e] bg-[#D7FF63] rounded-md hover:bg-[#D7FF63]/80 transition-colors cursor-pointer shrink-0 uppercase tracking-wider",children:[e.jsx("span",{children:"+"})," New Page"]})]}),e.jsx("div",{className:"border-b border-[#2d2d2d] mt-3"}),[...B.entries()].sort(([L],[X])=>L==="Home"?-1:X==="Home"?1:L.localeCompare(X)).filter(([L])=>{if(!_.trim())return!0;const X=w.get(L);return((X?I.get(X):void 0)||L).toLowerCase().includes(_.trim().toLowerCase())}).map(([L,X])=>{const ee=X.some(K=>K.id===o);return e.jsx("div",{className:"mt-2",children:w.has(L)&&M(w.get(L))?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-center gap-1.5 py-1",children:e.jsxs("button",{onClick:()=>R(L,w.get(L)),className:`flex items-center gap-1.5 text-sm font-normal cursor-pointer hover:text-white transition-colors bg-transparent border-none p-0 ${ee?"text-[#D7FF63]":"text-gray-300"}`,children:[(()=>{const K=w.get(L);return(K?I.get(K):void 0)||L})(),e.jsxs("span",{className:`font-normal text-sm ${ee?"text-[#D7FF63]/60":"text-gray-500"}`,children:["(",X.length,")"]}),e.jsx("svg",{className:ee?"text-[#D7FF63]/60":"text-gray-500",width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M9 18l6-6-6-6"})})]})}),e.jsx("div",{className:"grid grid-cols-3 gap-2 pt-1",children:X.map(K=>e.jsx(qe,{scenarioId:K.id,updatedAt:K.updatedAt,hasScreenshot:!!K.screenshotPath,name:K.name,isActive:K.id===o,onSelect:()=>x(K)},K.id))})]}):e.jsxs("div",{className:"py-2",children:[e.jsx("span",{className:"text-sm font-normal text-gray-500",children:(()=>{const K=w.get(L);return K&&I.get(K)||L})()}),e.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#E0D400",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),e.jsx("p",{className:"text-xs text-[#E0D400]/80 m-0 leading-relaxed",children:"Data missing for this page."}),e.jsx(Ss,{name:L,scenarios:X,reason:w.has(L)?"incomplete":"missing"})]})]})},L)})]})]})},Q):e.jsx("div",{className:"flex-1 flex items-center justify-center font-['IBM_Plex_Sans']",children:e.jsxs("div",{className:"flex flex-col items-center gap-4 px-8 text-center",children:[f?e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-lg font-medium text-white m-0",children:f}),y&&e.jsx("p",{className:"text-sm text-gray-400 m-0 leading-relaxed",children:y})]}):e.jsx("h2",{className:"text-lg font-medium text-white m-0",children:"Your project is ready"}),e.jsx("p",{className:"text-sm text-gray-400 m-0 leading-relaxed",children:"Describe what you want to build in the Chat and your pages and components will appear here."}),e.jsx("button",{onClick:g,className:"px-6 py-3 bg-[#005c75] text-white text-sm font-medium rounded-lg hover:bg-[#004d63] transition-colors cursor-pointer",children:"Start Building"})]})})}const fs=[{key:"app",label:"App"},{key:"build",label:"Build"},{key:"data",label:"Structure"},{key:"history",label:"History"}],fr=()=>e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 12 12",fill:"none",className:"text-[#8E8E8E] shrink-0",children:e.jsx("path",{d:"M4.5 3L7.5 6L4.5 9",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})});function gr({activeTab:t,onTabChange:s,buildIdle:n,projectTitle:a,breadcrumbItems:c,onBreadcrumbNavigate:i}){const[l,o]=r.useState(!1),x=r.useRef(null);r.useEffect(()=>{if(!l)return;const g=m=>{x.current&&!x.current.contains(m.target)&&o(!1)};return document.addEventListener("mousedown",g),()=>document.removeEventListener("mousedown",g)},[l]);const S=c&&c.length>0;return e.jsxs("div",{className:"shrink-0 z-20 @container",children:[e.jsxs("div",{className:"bg-black h-10 flex items-center px-4 gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("img",{src:Pn,alt:"CodeYam",className:"h-5 shrink-0"}),e.jsx("span",{className:"text-sm font-medium text-white whitespace-nowrap hidden @min-[500px]:inline",children:"CodeYam Editor"})]}),e.jsx("span",{className:"text-[#8E8E8E] text-sm shrink-0",children:"/"}),e.jsx("div",{className:"hidden @min-[350px]:flex items-center gap-1",children:fs.map(g=>e.jsxs("button",{onClick:()=>s(g.key),className:`px-2.5 py-2.5 text-sm transition-colors cursor-pointer border-b ${t===g.key?"text-[#D7FF63] border-[#D7FF63] font-medium":"text-[#8E8E8E] border-transparent hover:text-white font-light"}`,children:[g.label,g.key==="build"&&n&&t!=="build"&&e.jsx("span",{className:"ml-1 inline-block w-1.5 h-1.5 rounded-full bg-amber-400 animate-pulse"})]},g.key))})]}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:()=>s("settings"),className:`hidden @min-[350px]:block p-1.5 rounded-md transition-colors cursor-pointer ${t==="settings"?"text-[#D7FF63]":"text-[#8E8E8E] hover:text-white"}`,title:"Settings",children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"3"}),e.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})}),e.jsxs("div",{className:"@min-[350px]:hidden relative",ref:x,children:[e.jsx("button",{onClick:()=>o(!l),className:"p-1.5 rounded-md transition-colors cursor-pointer text-[#8E8E8E] hover:text-white",title:"Menu",children:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[e.jsx("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),e.jsx("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),e.jsx("line",{x1:"3",y1:"18",x2:"21",y2:"18"})]})}),l&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 bg-[#2d2d2d] border border-[#3d3d3d] rounded-lg shadow-lg py-1 min-w-[140px] z-50",children:[fs.map(g=>e.jsxs("button",{onClick:()=>{s(g.key),o(!1)},className:`w-full text-left px-4 py-2 text-sm transition-colors cursor-pointer bg-transparent border-none ${t===g.key?"text-[#D7FF63]":"text-[#8E8E8E] hover:text-white hover:bg-[#3d3d3d]"}`,children:[g.label,g.key==="build"&&n&&t!=="build"&&e.jsx("span",{className:"ml-1 inline-block w-1.5 h-1.5 rounded-full bg-amber-400 animate-pulse"})]},g.key)),e.jsx("div",{className:"border-t border-[#3d3d3d] my-1"}),e.jsx("button",{onClick:()=>{s("settings"),o(!1)},className:`w-full text-left px-4 py-2 text-sm transition-colors cursor-pointer bg-transparent border-none ${t==="settings"?"text-[#D7FF63]":"text-[#8E8E8E] hover:text-white hover:bg-[#3d3d3d]"}`,children:"Settings"})]})]})]}),e.jsx("div",{className:"bg-[#161616] h-8 flex items-center px-4 border-b border-[#2d2d2d]",children:e.jsx("nav",{className:"flex items-center gap-2 text-sm min-w-0",children:S?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>i==null?void 0:i(),className:"text-[#8E8E8E] hover:text-white transition-colors bg-transparent border-none p-0 cursor-pointer shrink-0",children:a||"Untitled Project"}),c.slice(1).map((g,m)=>{const p=m===c.length-2;return e.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(fr,{}),p?e.jsx("span",{className:"text-white truncate",children:g.name}):e.jsx("button",{type:"button",onClick:()=>i==null?void 0:i(g.componentName,g.entitySha),className:"text-[#8E8E8E] hover:text-white transition-colors bg-transparent border-none p-0 cursor-pointer truncate",children:g.name})]},g.componentName||g.name)})]}):e.jsx("span",{className:"text-[#8E8E8E]",children:a||"Untitled Project"})})})]})}function br({onMouseDown:t,onDoubleClick:s,isDragging:n}){return e.jsxs("div",{className:"shrink-0 relative flex items-center justify-center cursor-col-resize group",style:{width:12},onMouseDown:t,onDoubleClick:s,children:[e.jsx("div",{className:"absolute inset-y-0 left-1/2 -translate-x-1/2",style:{width:n?3:1,backgroundColor:n?"#3b82f6":"#3d3d3d",transition:"width 100ms, background-color 100ms"}}),!n&&e.jsx("div",{className:"absolute inset-0 bg-blue-500/0 group-hover:bg-blue-500/20 transition-colors pointer-events-none"}),e.jsxs("div",{className:"relative z-10 flex flex-col gap-[3px] opacity-0 group-hover:opacity-100 transition-opacity",style:n?{opacity:1}:void 0,children:[e.jsx("div",{className:"w-2 h-px bg-gray-400"}),e.jsx("div",{className:"w-2 h-px bg-gray-400"}),e.jsx("div",{className:"w-2 h-px bg-gray-400"})]})]})}const gs=300,Ye=150;function yr(t){const[s,n]=r.useState(null),[a,c]=r.useState(!1),i=r.useRef(0),l=r.useRef(null);r.useEffect(()=>{t.current&&n(Math.round(t.current.offsetWidth*.5))},[t]);const o=r.useCallback(()=>{var f;return((f=t.current)==null?void 0:f.offsetWidth)??(typeof window<"u"?window.innerWidth:1024)},[t]),x=r.useCallback(f=>{f.preventDefault(),c(!0)},[]),S=r.useCallback(()=>{n(Math.round(o()*.5))},[o]),g=r.useCallback(()=>{n(f=>(f&&f>0&&(l.current=f),0))},[]),m=r.useCallback(()=>{const f=l.current;l.current=null,n(f&&f>=gs?f:Math.round(o()*.5))},[o]),p=r.useCallback(()=>{n(Math.round(o()*.5))},[o]);r.useEffect(()=>{if(!a)return;document.body.style.cursor="col-resize",document.body.style.userSelect="none";const f=E=>{cancelAnimationFrame(i.current),i.current=requestAnimationFrame(()=>{var w;const C=(w=t.current)==null?void 0:w.getBoundingClientRect(),O=(C==null?void 0:C.left)??0,Z=((C==null?void 0:C.width)??window.innerWidth)-Ye,B=E.clientX-O,q=Math.min(Math.max(B,gs),Z);n(q)})},y=E=>{var B;cancelAnimationFrame(i.current),c(!1);const C=(B=t.current)==null?void 0:B.getBoundingClientRect(),O=(C==null?void 0:C.left)??0,J=(C==null?void 0:C.width)??window.innerWidth,Z=E.clientX-O;Z<Ye?n(0):J-Z<Ye&&n(J)};return document.addEventListener("mousemove",f),document.addEventListener("mouseup",y),()=>{cancelAnimationFrame(i.current),document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",y),document.body.style.cursor="",document.body.style.userSelect=""}},[a,t]),r.useEffect(()=>{const f=()=>{n(y=>{if(y===null||y===0)return y;const E=o();return y>=E?E:Math.min(y,E-Ye)})};if(!(typeof window>"u"))return window.addEventListener("resize",f),()=>window.removeEventListener("resize",f)},[o]);const R=o(),h=s===0,N=s!==null&&s>=R;return{editorWidth:s,isDragging:a,isEditorCollapsed:h,isPreviewCollapsed:N,handleMouseDown:x,handleDoubleClick:S,collapseEditor:g,expandEditor:m,expandPreview:p}}function jr({preview:t,onDismiss:s,onLoadCommit:n}){return e.jsxs("div",{className:"flex flex-col items-center gap-6 max-w-[700px] w-full",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("h2",{className:"text-lg font-semibold text-[#333] m-0 font-['IBM_Plex_Sans']",children:"Journal Screenshot"}),e.jsx("p",{className:"text-sm text-[#888] mt-1 m-0 font-['IBM_Plex_Sans']",children:"This is a snapshot from a previous version — not a live preview"})]}),e.jsx("div",{className:"rounded-lg overflow-hidden border-2 border-[#ccc] shadow-md max-w-full w-fit",children:e.jsx("img",{src:t.screenshotUrl,alt:t.scenarioName,className:"max-w-full h-auto block"})}),e.jsxs("div",{className:"flex items-center gap-2 text-sm text-[#666]",children:[t.commitSha&&e.jsx("span",{className:"font-mono text-xs text-[#00a0c4] bg-[#00a0c4]/15 px-2 py-0.5 rounded",children:t.commitSha.slice(0,7)}),e.jsxs("span",{className:"truncate",children:[t.scenarioName,t.commitMessage&&` — ${t.commitMessage}`]})]}),e.jsx("div",{className:"flex items-center gap-3",children:t.commitSha&&n&&e.jsx(vr,{commitSha:t.commitSha,onLoadCommit:n})})]})}function vr({commitSha:t,onLoadCommit:s}){const[n,a]=r.useState(!1),[c,i]=r.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{a(!0),i(null),s(t).then(l=>{l.success||i(l.error||"Failed to load commit")}).catch(l=>{i(l instanceof Error?l.message:"Network error")}).finally(()=>a(!1))},disabled:n,className:"bg-[#005c75] hover:bg-[#004d63] disabled:opacity-50 text-white text-sm font-medium px-4 py-1.5 rounded transition-colors cursor-pointer",children:n?"Reverting...":"Revert to this code and load this version"}),c&&e.jsx("div",{className:"bg-red-50 border border-red-200 rounded px-4 py-2 text-sm text-red-600 w-full text-center",children:c})]})}function Nr({preview:t,onDismiss:s}){return e.jsxs("div",{className:"flex flex-col items-center gap-6 max-w-[700px] w-full",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-200 m-0 font-['IBM_Plex_Sans']",children:t.scenarioName}),e.jsxs("div",{className:"flex items-center justify-center gap-2 mt-2",children:[e.jsx("span",{className:"inline-block w-2 h-2 rounded-full bg-amber-400 animate-pulse"}),e.jsx("p",{className:"text-sm text-amber-400/90 m-0 font-['IBM_Plex_Sans']",children:"The app is being edited - you can control the live preview when building is paused or complete."})]})]}),t.hasScreenshot?e.jsx("div",{className:"rounded-lg overflow-hidden border-2 border-[#4d4d4d] shadow-md max-w-full w-fit",children:e.jsx(_e,{scenarioId:t.scenarioId,updatedAt:t.updatedAt,alt:t.scenarioName,className:"max-w-full",imgClassName:"max-w-full h-auto block"})}):e.jsx("div",{className:"rounded-lg border-2 border-[#4d4d4d] bg-[#1a1a1a] flex items-center justify-center w-[400px] h-[300px]",children:e.jsx("span",{className:"text-sm text-gray-500",children:"No screenshot available"})}),e.jsx("button",{onClick:s,className:"text-xs text-gray-500 hover:text-gray-300 bg-transparent border-none cursor-pointer transition-colors",children:"Dismiss"})]})}function wr({analysisId:t,scenarioId:s,scenarioName:n,entityName:a,projectSlug:c,onStateChange:i}){const{interactiveServerUrl:l,isStarting:o,isLoading:x}=En({analysisId:t,scenarioId:s,scenarioName:n,entityName:a,projectSlug:c,enabled:!0});return r.useEffect(()=>{i(l,o||x)},[l,o,x,i]),null}function Sr({onSaveToCurrent:t,onSaveAsNew:s,onDismiss:n,isSaving:a,scenarioName:c}){return e.jsxs("div",{className:"flex items-center justify-between px-4 py-1.5 bg-emerald-900/60 border-b border-emerald-700/50 text-emerald-200 text-xs",children:[e.jsx("span",{className:"font-medium",children:c?e.jsxs(e.Fragment,{children:["Data modified in “",c,"”."]}):"Data modified."}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:t,disabled:a,className:"px-2.5 py-0.5 bg-emerald-600 hover:bg-emerald-500 disabled:opacity-50 text-white text-xs font-medium rounded transition-colors cursor-pointer disabled:cursor-not-allowed",children:a?"Saving...":"Save to Scenario"}),e.jsx("button",{onClick:s,disabled:a,className:"px-2.5 py-0.5 bg-emerald-800 hover:bg-emerald-700 disabled:opacity-50 text-emerald-200 text-xs font-medium rounded transition-colors cursor-pointer disabled:cursor-not-allowed",children:"Save as New"}),e.jsx("button",{onClick:n,disabled:a,className:"text-emerald-400 hover:text-emerald-200 disabled:opacity-50 transition-colors cursor-pointer disabled:cursor-not-allowed",title:"Dismiss",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]})}function kr(t,s){return s.status==="error"?{url:null,proxyUrl:null,isStarting:!1,error:s.errorMessage||"Dev server crashed",canStartServer:t.canStartServer,autoStartAttempted:t.autoStartAttempted,shouldAutoStart:!1}:s.url?{url:s.url,proxyUrl:s.proxyUrl||null,isStarting:!1,error:null,canStartServer:!0,autoStartAttempted:t.autoStartAttempted,shouldAutoStart:!1}:s.status==="starting"?{...t,isStarting:!0,error:null,canStartServer:!0,shouldAutoStart:!1}:s.status==="stopped"?t.url?{...t,url:null,isStarting:!1,shouldAutoStart:!1}:t.autoStartAttempted?{...t,isStarting:!1,shouldAutoStart:!1}:{...t,autoStartAttempted:!0,shouldAutoStart:!0}:{...t,shouldAutoStart:!1}}function Cr(t){const[s,n]=r.useState({url:null,proxyUrl:null,isStarting:!1,error:null,canStartServer:!0,autoStartAttempted:!1}),a=r.useRef(s);a.current=s,r.useEffect(()=>{let l=!1,o=null;const x=async()=>{try{const S=await fetch("/api/editor-dev-server");if(l)return;const g=await S.json(),m=kr(a.current,g),{shouldAutoStart:p,...R}=m;if(n(R),p&&!(t!=null&&t.skipAutoStart))try{const h=await fetch("/api/editor-dev-server",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"start"})});if(l)return;h.ok?n(N=>({...N,isStarting:!0})):n(N=>({...N,canStartServer:!1}))}catch{}}catch{}};return x(),o=setInterval(()=>void x(),2e3),()=>{l=!0,o&&clearInterval(o)}},[s.url]);const c=r.useCallback(()=>{n(l=>({...l,error:null,isStarting:!0})),fetch("/api/editor-dev-server",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"restart"})}).catch(()=>{})},[]),i=r.useCallback(()=>{n(l=>({...l,error:null,isStarting:!0})),fetch("/api/editor-dev-server",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"start"})}).catch(()=>{})},[]);return{devServerUrl:s.url,proxyUrl:s.proxyUrl,isStarting:s.isStarting,error:s.error,canStartServer:s.canStartServer,retryServer:c,startServer:i}}function Pr(t){const s=r.useRef(null),n=r.useRef(null);r.useEffect(()=>{if(typeof document>"u")return;n.current||(n.current=document.createElement("canvas"),n.current.width=64,n.current.height=64);const a=document.querySelector('link[rel="icon"]');if(!a)return;if(s.current||(s.current=a.href),!t){a.href=s.current;return}const c=new Image;c.crossOrigin="anonymous",c.onload=()=>{const i=n.current,l=i.getContext("2d");l.clearRect(0,0,64,64);const o=56,x=(64-o)/2;l.drawImage(c,x,x,o,o);const S=12,g=64-S-1,m=S+1;l.beginPath(),l.arc(g,m,S,0,2*Math.PI),l.fillStyle="#ef4444",l.fill(),a.href=i.toDataURL("image/png")},c.src=s.current},[t]),r.useEffect(()=>()=>{if(typeof document>"u")return;const a=document.querySelector('link[rel="icon"]');a&&s.current&&(a.href=s.current)},[])}function zr({currentUrl:t,nextUrl:s,formMethod:n,defaultShouldRevalidate:a}){return n||t.pathname===s.pathname?a:t.pathname.startsWith("/editor")&&s.pathname.startsWith("/editor")?!1:a}const Ur=()=>[{title:"Editor - CodeYam"},{name:"description",content:"CodeYam Code + Data Editor"}];class Er extends r.Component{constructor(){super(...arguments);ns(this,"state",{error:null,errorInfo:null})}static getDerivedStateFromError(n){return{error:n,errorInfo:null}}componentDidCatch(n,a){console.error("[EditorErrorBoundary] Error:",n.message),console.error("[EditorErrorBoundary] Component stack:",a.componentStack),console.error("[EditorErrorBoundary] Loader snapshot:",JSON.stringify(this.props.loaderSnapshot,null,2)),this.setState({errorInfo:a})}render(){var n;return this.state.error?e.jsx("div",{className:"fixed inset-0 bg-[#1e1e1e] flex items-center justify-center p-8",children:e.jsxs("div",{className:"max-w-[600px] w-full space-y-4",children:[e.jsx("h2",{className:"text-lg font-semibold text-red-400 font-['IBM_Plex_Sans'] m-0",children:"Something went wrong"}),e.jsx("pre",{className:"text-xs text-gray-300 bg-[#2d2d2d] p-3 rounded overflow-auto max-h-[120px]",children:this.state.error.message}),((n=this.state.errorInfo)==null?void 0:n.componentStack)&&e.jsxs("details",{className:"text-xs text-gray-500",children:[e.jsx("summary",{className:"cursor-pointer hover:text-gray-300 transition-colors",children:"Component stack"}),e.jsx("pre",{className:"mt-2 bg-[#2d2d2d] p-3 rounded overflow-auto max-h-[200px] text-yellow-300",children:this.state.errorInfo.componentStack})]}),e.jsx("p",{className:"text-xs text-gray-500 m-0",children:"Full diagnostics are in the browser console."}),e.jsx("button",{onClick:()=>window.location.reload(),className:"px-4 py-2 bg-[#005c75] text-white text-sm rounded hover:bg-[#004d63] transition-colors cursor-pointer",children:"Reload"})]})}):this.props.children}}const Hr=cn(function(){var Zt,es;const{projectSlug:s,projectRoot:n,hasProject:a,scenarios:c,allScenarios:i,analyzedEntities:l,allEntities:o,glossaryFunctions:x,glossaryEntries:S,entityImports:g,pageFilePaths:m,entityChangeStatus:p,modifiedFiles:R,featureName:h,userPrompt:N,projectTitle:f,projectDescription:y,defaultScreenSize:E,screenSizes:C,editorStep:O,editorStepLabel:J,claudeSessionId:Z,focusedEntitySha:B,newerEntitySha:q,focusedEntity:w,migrationMode:k,migrationState:F}=dn(),[M,I]=xn(),V=un(),W=r.useRef(null),le=r.useRef(null),v=r.useRef(null),A=r.useRef(null),[_,j]=r.useState(B);r.useEffect(()=>{j(B)},[B]),r.useEffect(()=>{const d=b=>{const P=b.target;(P.tagName==="BUTTON"||P.closest("button"))&&(P.closest("button")??P).blur()};return document.addEventListener("mouseup",d),()=>document.removeEventListener("mouseup",d)},[]);const D=r.useMemo(()=>rs(_,o),[_,o,i]),T=(D==null?void 0:D.displayName)??void 0,U=M.get("scenario")||((Zt=Ke(i))==null?void 0:Zt.id)||void 0,[Q,$]=r.useState(()=>T?[T]:[]),L=r.useRef(null),X=r.useRef([]),ee=r.useRef(null);r.useEffect(()=>{var te;const d=U||((te=Ke(i))==null?void 0:te.id);if(!gn(d,L.current))return;const b=i.find(ae=>ae.id===d);if(!b)return;L.current=d;const P=bt(b,X.current,ee.current);P&&je(P);const z=Me(b.name);fetch("/api/editor-switch-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioSlug:z,scenarioId:b.id,scenarioName:b.name,scenarioType:b.type})}).catch(()=>{})},[U,i]),r.useEffect(()=>{const d=new BroadcastChannel("codeyam-editor");return d.onmessage=b=>{var P;if(((P=b.data)==null?void 0:P.type)==="switch-scenario"&&b.data.scenarioId){const z=b.data.scenarioId,te=i.find(De=>De.id===z);if(!te)return;L.current=z;const ae=new URLSearchParams(M);ae.set("scenario",z),ae.delete("zoom"),I(ae),u(null),Y(null),pe(null),ge(!0);const Le=Me(te.name);fetch("/api/editor-switch-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioSlug:Le,scenarioId:z,scenarioType:te.type})}).then(()=>{ce(!1),ke(De=>De+1)}).catch(()=>{ge(!1)})}},()=>d.close()},[M,I,i]),r.useEffect(()=>{if(M.get("ref")!=="link"||!U)return;const d=new BroadcastChannel("codeyam-editor");d.postMessage({type:"switch-scenario",scenarioId:U}),d.close(),window.close()},[]);const{devServerUrl:K,proxyUrl:G,isStarting:ue,error:xe,canStartServer:he,retryServer:Be,startServer:We}=Cr({skipAutoStart:k==="candidate"||k==="active"}),[be,ce]=r.useState(!1),[re,u]=r.useState(null),[H,Y]=r.useState(null),[se,St]=r.useState(!1),[Ze,pe]=r.useState(null),[et,ye]=r.useState(null),Cs=r.useCallback(async d=>{const P=await(await fetch("/api/editor-load-commit",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({commitSha:d})})).json();return P.success&&(pe(null),ce(!1)),P},[]),Ps=r.useCallback((d,b)=>{Y(P=>(d&&d!==P&&ce(!1),d)),!b&&d&&ce(!0),St(b)},[]),tt=r.useCallback(d=>{pe(null),u(P=>(P&&P.analysisId===d.analysisId||(Y(null),ke(te=>te+1)),d)),St(!0),ce(!1);const b=new URLSearchParams(M);b.delete("scenario"),b.delete("zoom"),I(b)},[M,I]),[ie,je]=r.useState(E?{name:E.name,width:E.width,height:E.height}:{name:"Desktop",width:1440,height:900}),[kt,Ct]=r.useState(!1),[oe,Pt]=r.useState(!1),Et=E?{name:E.name,width:E.width,height:E.height}:null;ee.current=Et;const Ft=mn(),ne=r.useMemo(()=>{const d=Ft.pathname.split("/").filter(Boolean),b=d[d.length-1];return b==="build"||b==="history"||b==="settings"?b:b==="structure"?"data":"app"},[Ft.pathname]),de=r.useCallback(d=>{j(null),$([]);const b=d==="app"?"":`/${d==="data"?"structure":d}`,P=M.get("scenario"),z=P?`?scenario=${P}`:"";V(`/editor${b}${z}`)},[V,M]),st=r.useCallback(()=>{de("build"),ve(!0)},[de]),Es=r.useCallback(()=>{de("build"),ve(!0),setTimeout(()=>{var d;(d=W.current)==null||d.sendInput("codeyam editor migrate")},300)},[de]),[Fs,ve]=r.useState(ne==="build"),Ds=!!(h&&O),[ze,Ts]=r.useState(Ds?"pending":"no-session"),Dt=r.useRef(!1);r.useEffect(()=>{ze==="pending"&&!Dt.current&&(Dt.current=!0,de("build"),ve(!0))},[ze,de]);const Ls=r.useCallback(()=>{Ts("continue")},[]),[nt,rt]=r.useState(!1),[Ms,Tt]=r.useState(!1),Lt=r.useRef(!1),Ue=r.useRef(0),As=r.useRef(!1),Is=r.useCallback(d=>{rt(d),d||(As.current=!0),d&&!Lt.current&&(Tt(!1),Ue.current=Date.now()),d||(Ue.current=0),Lt.current=d},[]),[me,$s]=r.useState(!1),at=r.useRef(!1),Rs=r.useCallback(d=>{d!==at.current&&(console.log("[Editor] claudeBuilding: %s → %s",at.current,d),at.current=d,$s(d))},[]);Pr(nt);const Mt=r.useRef(me);r.useEffect(()=>{var b;const d=Mt.current&&!me;if(Mt.current=me,!me)if(d){const P=M.get("scenario")||((b=Ke(i))==null?void 0:b.id),z=i.find(te=>te.id===P);if(z){console.log("[Editor] Building stopped, loading live preview for: %s",z.name),ye(null);const te=Me(z.name);L.current=z.id,ge(!0),Ce(!1),fetch("/api/editor-switch-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioSlug:te,scenarioId:z.id,scenarioType:z.type,skipBroadcast:!0})}).then(()=>{ce(!1),ke(ae=>ae+1)}).catch(()=>{ge(!1)})}else ye(null)}else ye(null)},[me,M,i]);const{editorWidth:At,isDragging:It,isEditorCollapsed:fe,isPreviewCollapsed:it,handleMouseDown:Os,handleDoubleClick:_s,collapseEditor:Bs,expandEditor:$t,expandPreview:Ws}=yr(A),[ot,Rt]=r.useState(!1),zs=r.useCallback(()=>{Rt(!0),de("build"),ve(!0)},[de]),Ot=r.useCallback(()=>{Rt(!1)},[]),Us=r.useCallback(d=>{je(d),fetch("/api/editor-project-info",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultScreenSize:d,skipBroadcast:!0})})},[]),[_t,Bt]=r.useState(bn);r.useEffect(()=>{const d=yn();Bt(d),d.systemNotification&&typeof Notification<"u"&&Notification.permission==="default"&&Notification.requestPermission()},[]);const Hs=r.useCallback(d=>{Bt(d),jn(d)},[]);r.useEffect(()=>{if(ne==="build"){rt(!1);const d=setTimeout(()=>{var b,P;(b=W.current)==null||b.scrollToBottom(),(P=W.current)==null||P.focus()},50);return()=>clearTimeout(d)}},[ne]),r.useEffect(()=>{function d(){!document.hidden&&ne==="build"&&rt(!1)}return document.addEventListener("visibilitychange",d),()=>document.removeEventListener("visibilitychange",d)},[ne]);const[Ne,Vs]=r.useState(null);r.useEffect(()=>{const d=v.current;if(!d)return;const b=new ResizeObserver(P=>{const z=P[0];z&&Vs({width:z.contentRect.width,height:z.contentRect.height})});return b.observe(d),()=>b.disconnect()},[]);const we=r.useMemo(()=>Ne?vn(Ne,ie):1,[Ne,ie]),[Se,ke]=r.useState(0),[Wt,lt]=r.useState(null),[He,ge]=r.useState(!1),[Js,Ce]=r.useState(!1),[Ks,zt]=r.useState(!1),ct=r.useRef(0);r.useEffect(()=>{Se>0&&(ct.current=Date.now()+3e3)},[Se]);const Gs=r.useCallback(()=>{if(Date.now()<ct.current)return;const d=Ue.current;d===0||Date.now()-d<5e3||Ce(!0)},[]);r.useEffect(()=>{const d=b=>{var P;if(((P=b.data)==null?void 0:P.type)==="codeyam-localstorage-changed"){if(Date.now()<ct.current)return;const z=Ue.current;if(z===0||Date.now()-z<5e3)return;Ce(!0)}};return window.addEventListener("message",d),()=>window.removeEventListener("message",d)},[]);const Ut=r.useCallback(async d=>{zt(!0);try{let b;const P=le.current;P!=null&&P.contentWindow&&(b=await new Promise(ae=>{const Le=setTimeout(()=>ae(void 0),2e3),De=ts=>{var ss;((ss=ts.data)==null?void 0:ss.type)==="codeyam-localstorage-state"&&(clearTimeout(Le),window.removeEventListener("message",De),ae(ts.data.data))};window.addEventListener("message",De),P.contentWindow.postMessage({type:"codeyam-get-localstorage"},"*")}));const te=await(await fetch("/api/editor-save-seed-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mode:d,localStorage:b})})).json();te.success?Ce(!1):console.error("[editor] Save seed state failed:",te.error)}catch(b){console.error("[editor] Save seed state error:",b)}finally{zt(!1)}},[]),Ys=r.useCallback((d,b)=>{if(lt(d||null),b){const P=new URLSearchParams(M);P.set("scenario",b),L.current=b,I(P);const z=i.find(te=>te.id===b);if(z){const te=bt(z,X.current,ee.current);te&&je(te)}}pe(null),ce(!1),ke(P=>P+1)},[M,I,i]),{customSizes:dt,addCustomSize:qs,removeCustomSize:Xs}=pn(s),xt=r.useMemo(()=>Dn(C),[C]),ut=r.useMemo(()=>[...xt,...dt],[xt,dt]);X.current=ut;const Ve=r.useMemo(()=>{const d=new Map;for(const b of o){d.set(b.name,b.sha);const P=Oe(Re(b.filePath));P!==b.name&&d.set(P,b.sha)}return d},[o]),Ht=r.useMemo(()=>{const d=new Map;for(const b of o)d.set(b.sha,b.name);return d},[o]),Vt=r.useMemo(()=>{const d=[{name:"App"}];for(const b of Q){const P=Ve.get(b),z=P?Ht.get(P):void 0;d.push({name:z||b,componentName:b,entitySha:P})}return d},[Q,Ve,Ht]),{pageGroups:Jt,componentGroups:mt}=r.useMemo(()=>wt(i),[i]),Je=r.useMemo(()=>vs(Jt,mt),[Jt,mt]),[Qs,Zs]=r.useState("application"),[Pe,ht]=r.useState([]),[pt,Kt]=r.useState(null),Gt=r.useMemo(()=>pt?rs(pt,o):null,[pt,o,i]),Yt=r.useMemo(()=>{const d=[{name:"App"}];for(const b of Pe)d.push({name:b,componentName:b,entitySha:Ve.get(b)});return d},[Pe,Ve]),ft=r.useCallback((d,b)=>{if(!d){ht([]),Kt(null);return}const P=b||Je.get(d);if(!P)return;const z=Pe.indexOf(d);z>=0?ht(Pe.slice(0,z+1)):ht([...Pe,d]),Kt(P)},[Pe,Je]),qt=r.useCallback((d,b)=>{if(!d){$([]),j(null);const ae=M.get("scenario"),Le=ae?`?scenario=${ae}`:"";V(`/editor${Le}`);return}if(!b){console.error(`[editor] No entity SHA for "${d}" — entity missing from database`);return}const P=Q.indexOf(d);P>=0?$(Q.slice(0,P+1)):$([...Q,d]);const z=i.find(ae=>ae.entitySha===b);j(b);const te=z?`?scenario=${z.id}`:"";V(`/editor/entity/${b}${te}`)},[V,i,Q,M]),Xt=r.useCallback(d=>{ge(!0),Ce(!1);const b=Me(d.name);fetch("/api/editor-switch-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioSlug:b,scenarioId:d.id,scenarioType:d.type,skipBroadcast:!0})}).then(()=>{ce(!1),ke(P=>P+1)}).catch(()=>{ge(!1)})},[]),Ee=r.useCallback(d=>{console.log("[Editor] Scenario selected: %s (claudeBuilding=%s)",d.name,me),u(null),Y(null),pe(null),lt(null);const b=bt(d,ut,Et);b&&je(b),L.current=d.id;const P=new URLSearchParams(M);P.set("scenario",d.id),I(P),me?ye({scenarioId:d.id,scenarioName:d.name,updatedAt:d.updatedAt,hasScreenshot:!!d.screenshotPath}):(ye(null),Xt(d))},[M,I,ut,me,Xt]),en=r.useCallback(()=>{const d=U;if(!d)return;const b=i.find(z=>z.id===d);if(!b)return;const P=Me(b.name);fetch("/api/editor-switch-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioSlug:P,scenarioId:b.id,scenarioType:b.type})}).then(()=>{ke(z=>z+1)})},[U,i]),tn=r.useCallback(d=>{if(!d.commitSha){const b=i.find(P=>P.name===d.scenarioName);if(b){Ee(b);return}}pe(d)},[i,Ee]),sn=d=>{const b={name:d.name,width:d.width,height:d.height};je(b),fetch("/api/editor-project-info",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultScreenSize:b,skipBroadcast:!0})})},nn=(d,b,P)=>{qs(d,b,P)},rn=d=>{je(d),fetch("/api/editor-project-info",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultScreenSize:d,skipBroadcast:!0})})},Qt=()=>{re||ce(!0),ge(!1)},Fe=r.useMemo(()=>Nn({activeAnalyzedScenario:!!re,analyzedPreviewUrl:H,activeScenarioId:U||null,scenarios:i,proxyUrl:G,devServerUrl:K,zoomComponent:T||null}),[G,K,T,U,i,re,H]),gt=r.useMemo(()=>{const d=wn(Fe,Wt);if(!d)return null;const b=d.includes("?")?"&":"?";return`${d}${b}__cb=${Se}`},[Fe,Wt,Se]),an=r.useMemo(()=>({projectSlug:s,hasProject:a,scenarioCount:c==null?void 0:c.length,allScenarioCount:i==null?void 0:i.length,analyzedEntityCount:l==null?void 0:l.length,glossaryFunctionCount:x==null?void 0:x.length,entityChangeStatusKeys:p?Object.keys(p):[],featureName:h}),[s,a,c,i,l,x,p,h]);return e.jsxs(e.Fragment,{children:[e.jsx(Er,{loaderSnapshot:an,children:e.jsxs("div",{className:"fixed inset-0 bg-[#2d2d2d] flex flex-col",children:[re&&e.jsx(wr,{analysisId:re.analysisId,scenarioId:re.scenarioId,scenarioName:re.scenarioName,entityName:re.entityName,projectSlug:s,onStateChange:Ps},re.analysisId),e.jsxs("div",{ref:A,className:"flex-1 flex min-h-0",children:[fe&&e.jsx("div",{className:"shrink-0 flex items-center justify-center cursor-pointer hover:bg-[#3d3d3d] transition-colors",style:{width:8,backgroundColor:"#2d2d2d"},onClick:$t,title:"Expand editor",children:e.jsx("svg",{width:"6",height:"10",viewBox:"0 0 6 10",fill:"none",stroke:"#888",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M1 1l4 4-4 4"})})}),e.jsxs("aside",{className:"bg-[#1e1e1e] shrink-0 flex flex-col overflow-hidden",style:{...fe?{display:"none"}:At!==null?{width:`${At}px`}:{width:"50%"}},children:[q&&D&&e.jsxs("div",{className:"px-3 py-2 text-xs flex items-center justify-between",style:{background:"#2a1f00",borderBottom:"1px solid #3d2e00",color:"#f0c040"},children:[e.jsxs("span",{children:["Viewing an older version of"," ",e.jsx("strong",{children:D.name}),". A newer version exists."]}),e.jsx("a",{href:`/editor/entity/${q}`,className:"px-2 py-0.5 rounded text-xs",style:{background:"#3d2e00",color:"#f0c040",textDecoration:"none"},children:"View latest"})]}),e.jsx(gr,{activeTab:ne,onTabChange:d=>{de(d),d==="build"&&ve(!0),fetch("/api/telemetry-page-view",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({route:`/editor/${d}`})}).catch(()=>{})},buildIdle:nt,projectTitle:f,breadcrumbItems:ne==="data"?Yt:Vt,onBreadcrumbNavigate:ne==="data"?ft:qt}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-hidden relative",children:[nt&&ne!=="build"&&!Ms&&e.jsxs("div",{className:"absolute top-3 left-1/2 -translate-x-1/2 z-50 animate-[slideDown_0.3s_ease-out]",children:[e.jsx("style",{children:`
85
+ Do NOT start making changes until the user tells you what they want.`}function rn(t,s,r=new Date){const a={"1d":1,"3d":3,"7d":7,"30d":30}[s],c=new Date(r);c.setDate(c.getDate()-a);const i=c.toISOString().split("T")[0],l=t.filter(m=>m.date>=i),o=new Set(l.map(m=>m.commitSha).filter(Boolean)),x=new Map;for(const m of l)if(m.scenarioScreenshots)for(const p of m.scenarioScreenshots){x.has(p.name)||x.set(p.name,[]);const R=x.get(p.name);R.some(h=>h.path===p.path)||R.push({path:p.path,time:m.time})}for(const m of x.values())m.sort((p,R)=>p.time.localeCompare(R.time));const S=[],b=new Map;for(const[m,p]of x){const R=m.indexOf(" - ");if(R!==-1){const h=m.slice(0,R);b.has(h)||b.set(h,[]),b.get(h).push({name:m,screenshots:p})}else S.push({name:m,screenshots:p})}return{commitCount:o.size,entryCount:l.length,appScenarios:S,componentGroups:b,totalScenarios:x.size}}function nn(t){const s=new Map;for(const r of[...t].reverse()){const a=s.get(r.date)||[];a.push(r),s.set(r.date,a)}return s}function an(t){const s=new Map;for(const r of t){let a;if("componentName"in r&&r.componentName)a=r.componentName;else if("componentName"in r&&r.componentName===null)a="App";else{const i=r.name.indexOf(" - ");a=i!==-1?r.name.slice(0,i):"App"}const c=s.get(a)||[];c.push(r),s.set(a,c)}return[...s.entries()].sort(([r],[a])=>r==="App"?-1:a==="App"?1:r.localeCompare(a))}function ps({status:t}){const s={new:{label:"New",bg:"bg-green-900/40",text:"text-green-400",border:"border-green-700/50"},edited:{label:"Edited",bg:"bg-blue-900/40",text:"text-blue-400",border:"border-blue-700/50"},impacted:{label:"Impacted",bg:"bg-amber-900/40",text:"text-amber-400",border:"border-amber-700/50"}}[t.status];return e.jsx("span",{className:`${s.bg} ${s.text} ${s.border} border text-[8px] font-bold px-1 py-0 rounded-full uppercase tracking-wider`,children:s.label})}function on({testFile:t,entityName:s}){const{results:r,isRunning:a,runTests:c}=wt(t);if(a&&!r)return e.jsxs("div",{className:"pt-1 flex items-center gap-1.5",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-[#00a0c4] animate-pulse"}),e.jsx("span",{className:"text-[10px] text-gray-500",children:"Running tests..."})]});if(!r)return null;if(r.status==="error")return e.jsx("div",{className:"pt-1",children:e.jsx("span",{className:"text-[10px] text-red-400",children:r.errorMessage})});const i=s?r.testCases.filter(x=>x.fullName.startsWith(s)):r.testCases,l=i.length>0?i:r.testCases;if(l.length===0)return null;const o=s?`${s} > `:"";return e.jsxs("div",{className:"pt-1 space-y-0.5",children:[l.map(x=>{var b;const S=o&&x.fullName.startsWith(o)?x.fullName.slice(o.length):x.fullName;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[x.status==="passed"?e.jsx("span",{className:"text-green-400 text-[10px]",children:"✓"}):x.status==="failed"?e.jsx("span",{className:"text-red-400 text-[10px]",children:"✗"}):e.jsx("span",{className:"text-gray-500 text-[10px]",children:"—"}),e.jsx("span",{className:`text-[10px] ${x.status==="passed"?"text-green-400":x.status==="failed"?"text-red-400":"text-gray-500"}`,children:S})]}),x.status==="failed"&&((b=x.failureMessages)==null?void 0:b.map((m,p)=>e.jsx("div",{className:"pl-4 text-[9px] text-red-400/70 truncate max-w-full",title:m,children:m.split(`
86
+ `)[0]},p)))]},x.fullName)}),e.jsx("button",{onClick:c,disabled:a,className:"mt-1 text-[10px] text-[#00a0c4] hover:text-[#38bdf8] transition-colors cursor-pointer disabled:opacity-50 bg-transparent border-none p-0",children:a?"Running...":"Re-run"})]})}const ln={added:"text-green-400",untracked:"text-green-400",modified:"text-blue-400",renamed:"text-purple-400"};function cn({files:t}){return e.jsxs("div",{className:"border-t border-[#3d3d3d] pt-2 mt-1",children:[e.jsxs("span",{className:"text-[10px] font-semibold text-gray-500 uppercase tracking-wider",children:["Modified Files (",t.length,")"]}),e.jsx("div",{className:"mt-1 space-y-0.5 max-h-[150px] overflow-auto",children:t.map(s=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`text-[9px] font-bold uppercase w-[14px] text-center ${ln[s.status]||"text-gray-500"}`,children:s.status==="added"||s.status==="untracked"?"A":s.status==="modified"?"M":s.status==="renamed"?"R":"?"}),e.jsx("span",{className:"text-[10px] text-gray-400 truncate font-mono",children:s.path})]},s.path))})]})}const dn={feature:{label:"Feature",color:"bg-[#005c75]"},fix:{label:"Fix",color:"bg-amber-700"},refactor:{label:"Refactor",color:"bg-purple-700"},scaffold:{label:"Scaffold",color:"bg-green-700"},data:{label:"Data",color:"bg-blue-700"},milestone:{label:"Milestone",color:"bg-yellow-600"}};function xn(t){try{return new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return""}}function un(t){try{return new Date(t+"T00:00:00").toLocaleDateString([],{weekday:"long",month:"long",day:"numeric"})}catch{return t}}const mn=[{value:"1d",label:"1 Day"},{value:"3d",label:"3 Days"},{value:"7d",label:"1 Week"},{value:"30d",label:"1 Month"}];function hn({entries:t,onScreenshotClick:s}){const[r,a]=n.useState(!1),[c,i]=n.useState("7d"),l=n.useMemo(()=>rn(t,c),[t,c]);return e.jsxs("div",{className:"bg-[#2d2d2d] rounded-lg overflow-hidden",children:[e.jsxs("button",{onClick:()=>a(!r),className:"w-full flex items-center justify-between px-3 py-2.5 cursor-pointer bg-transparent border-none text-left hover:bg-[#333] transition-colors",children:[e.jsx("span",{className:"text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Timeframe Summary"}),e.jsx("span",{className:`text-gray-500 text-[10px] transition-transform ${r?"rotate-180":""}`,children:"▼"})]}),r&&e.jsxs("div",{className:"px-3 pb-3 space-y-3 border-t border-[#3d3d3d]",children:[e.jsx("div",{className:"flex gap-1 pt-2.5",children:mn.map(o=>e.jsx("button",{onClick:()=>i(o.value),className:`px-2.5 py-1 text-[10px] font-medium rounded transition-colors cursor-pointer border ${c===o.value?"bg-[#005c75] text-white border-[#005c75]":"bg-transparent text-gray-400 border-[#4d4d4d] hover:text-white hover:border-[#005c75]"}`,children:o.label},o.value))}),e.jsxs("div",{className:"flex items-center gap-3 text-[11px] text-gray-400",children:[e.jsxs("span",{children:[e.jsx("span",{className:"text-white font-medium",children:l.commitCount})," ",l.commitCount===1?"commit":"commits"]}),e.jsx("span",{className:"text-[#3d3d3d]",children:"|"}),e.jsxs("span",{children:[e.jsx("span",{className:"text-white font-medium",children:l.totalScenarios})," ",l.totalScenarios===1?"scenario changed":"scenarios changed"]}),e.jsx("span",{className:"text-[#3d3d3d]",children:"|"}),e.jsxs("span",{children:[e.jsx("span",{className:"text-white font-medium",children:l.entryCount})," ",l.entryCount===1?"entry":"entries"]})]}),l.totalScenarios===0?e.jsx("p",{className:"text-[11px] text-gray-500 italic m-0",children:"No scenario changes in this period."}):e.jsxs("div",{className:"space-y-3",children:[l.appScenarios.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("span",{className:"text-[10px] font-semibold text-gray-500 uppercase tracking-wider",children:"Application"}),l.appScenarios.map(o=>e.jsx(fs,{scenario:o,onScreenshotClick:s},o.name))]}),l.componentGroups.size>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("span",{className:"text-[10px] font-semibold text-gray-500 uppercase tracking-wider",children:"Components"}),[...l.componentGroups.entries()].sort(([o],[x])=>o.localeCompare(x)).map(([o,x])=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{className:"text-[10px] font-medium text-gray-400",children:o}),x.map(S=>e.jsx(fs,{scenario:S,onScreenshotClick:s},S.name))]},o))]})]})]})]})}function fs({scenario:t,onScreenshotClick:s}){const r=t.name.indexOf(" - "),a=r!==-1?t.name.slice(r+3):t.name;return e.jsxs("div",{className:"pl-2",children:[e.jsx("span",{className:"text-[10px] text-gray-500 block mb-1",children:a}),e.jsx("div",{className:"flex items-center gap-1 overflow-x-auto",children:t.screenshots.map((c,i)=>e.jsxs("div",{className:"flex items-center shrink-0",children:[i>0&&e.jsx("span",{className:"text-[8px] text-gray-600 mx-0.5",children:"→"}),e.jsx("button",{type:"button",className:"w-16 h-16 rounded overflow-hidden border border-[#3d3d3d] hover:border-[#00a0c4] bg-[#1e1e1e] shrink-0 flex items-center justify-center cursor-pointer transition-colors",title:`${t.name} (${new Date(c.time).toLocaleDateString()})`,onClick:()=>s==null?void 0:s({screenshotUrl:`/api/editor-journal-image/${c.path.replace("screenshots/","")}`,commitSha:null,commitMessage:null,scenarioName:t.name}),children:e.jsx("img",{src:`/api/editor-journal-image/${c.path.replace("screenshots/","")}`,alt:t.name,className:"max-w-full max-h-full object-contain",loading:"lazy"})})]},c.path))})]})}function pn({isActive:t,onScreenshotClick:s,glossaryFunctions:r=[]}){const[a,c]=n.useState([]),[i,l]=n.useState(!0),[o,x]=n.useState(new Set),S=n.useCallback(p=>{x(R=>{const h=new Set(R);return h.has(p)?h.delete(p):h.add(p),h})},[]),b=n.useCallback(async()=>{try{const p=await fetch("/api/editor-journal");if(p.ok){const R=await p.json();c(R.entries||[])}}catch{}finally{l(!1)}},[]);if(n.useEffect(()=>{b()},[b]),n.useEffect(()=>{t&&b()},[t,b]),n.useEffect(()=>{if(!t)return;const p=setInterval(()=>void b(),5e3);return()=>clearInterval(p)},[t,b]),i)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx("span",{className:"text-gray-500 text-sm",children:"Loading journal..."})});if(a.length===0)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center text-gray-500 px-8",children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:"No journal entries yet"}),e.jsx("p",{className:"text-xs",children:"Journal entries will appear as you build. Claude records features, screenshots, and commits as the project evolves."})]})});const m=nn(a);return e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsxs("div",{className:"p-3 space-y-4",children:[e.jsx(hn,{entries:a,onScreenshotClick:s}),[...m.entries()].map(([p,R])=>e.jsxs("div",{children:[e.jsx("div",{className:"px-3 py-1.5 sticky top-0 bg-[#1e1e1e] z-10",children:e.jsx("span",{className:"text-[10px] font-semibold text-gray-500 uppercase tracking-wider",children:un(p)})}),e.jsx("div",{className:"space-y-2",children:R.map((h,N)=>{const f=dn[h.type]||{label:h.type,color:"bg-gray-600"},y=`${h.time}-${N}`,E=o.has(y);return e.jsxs("div",{className:"bg-[#2d2d2d] rounded-lg overflow-hidden",children:[e.jsxs("div",{className:`p-3 space-y-2 ${E?"":"max-h-[300px] overflow-y-auto"}`,children:[e.jsx("div",{className:"flex items-start gap-2 cursor-pointer",onClick:()=>S(y),children:e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-white truncate",children:h.title}),e.jsx("span",{className:`${f.color} text-white text-[9px] font-bold px-1.5 py-0.5 rounded uppercase tracking-wider shrink-0`,children:f.label})]}),e.jsx("span",{className:"text-[10px] text-gray-500",children:xn(h.time)}),h.featureName&&e.jsx("span",{className:"text-[10px] text-gray-500 italic truncate",title:h.featureName,children:h.featureName})]})}),h.userPrompt&&e.jsx(ws,{text:h.userPrompt,theme:"dark"}),e.jsx("p",{className:"text-xs text-gray-400 leading-relaxed",children:h.description}),h.screenshot&&e.jsx("button",{type:"button",className:"rounded overflow-hidden border border-[#3d3d3d] hover:border-[#00a0c4] bg-[#1e1e1e] flex items-center justify-center p-1 cursor-pointer transition-colors w-full",onClick:()=>s==null?void 0:s({screenshotUrl:`/api/editor-journal-image/${h.screenshot.replace("screenshots/","")}`,commitSha:h.commitSha,commitMessage:h.commitMessage,scenarioName:h.title}),children:e.jsx("img",{src:`/api/editor-journal-image/${h.screenshot.replace("screenshots/","")}`,alt:h.title,className:"max-w-full max-h-full object-contain",loading:"lazy"})}),h.scenarioScreenshots&&h.scenarioScreenshots.length>0&&(()=>{const P=an(h.scenarioScreenshots),O=h.entityChangeStatus,J=P.filter(([k])=>k==="App").flatMap(([,k])=>k),Z=P.filter(([k])=>k!=="App"),B=new Map;for(const k of J){const F=k,M=F.pageFilePath?Oe(Re(F.pageFilePath)):Ze(F.url??null),I=B.get(M)||[];I.push(k),B.set(M,I)}const q=[...B.entries()],w=k=>e.jsx("button",{type:"button",className:"w-[4.5rem] h-[4.5rem] rounded overflow-hidden border border-[#3d3d3d] hover:border-[#00a0c4] bg-[#1e1e1e] shrink-0 flex items-center justify-center cursor-pointer transition-colors",onClick:()=>s==null?void 0:s({screenshotUrl:`/api/editor-journal-image/${k.path.replace("screenshots/","")}`,commitSha:h.commitSha,commitMessage:h.commitMessage,scenarioName:k.name}),children:e.jsx("img",{src:`/api/editor-journal-image/${k.path.replace("screenshots/","")}`,alt:k.name,title:k.name,className:"max-w-full max-h-full object-contain",loading:"lazy"})},k.path);return e.jsxs("div",{className:"space-y-2",children:[q.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{className:"text-[10px] font-semibold text-gray-500 uppercase tracking-wider",children:"Application"}),q.map(([k,F])=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[10px] font-medium text-gray-400",children:k}),(O==null?void 0:O[k])&&e.jsx(ps,{status:O[k]})]}),e.jsx("div",{className:"flex flex-wrap gap-1 mt-0.5",children:F.map(w)})]},k))]}),Z.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{className:"text-[10px] font-semibold text-gray-500 uppercase tracking-wider",children:"Components"}),Z.map(([k,F])=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[10px] font-medium text-gray-400",children:k}),(O==null?void 0:O[k])&&e.jsx(ps,{status:O[k]})]}),e.jsx("div",{className:"flex flex-wrap gap-1 mt-0.5",children:F.map(w)})]},k))]})]})})(),r.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{className:"text-[10px] font-semibold text-gray-500 uppercase tracking-wider",children:"Functions"}),e.jsx("div",{className:"space-y-2",children:r.map(P=>e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] font-medium text-gray-200",children:P.name}),e.jsx("span",{className:"text-[9px] text-gray-500 truncate block",children:P.filePath}),P.testFile?e.jsx(on,{testFile:P.testFile,entityName:P.name}):e.jsx("div",{className:"pt-1",children:e.jsx("span",{className:"text-[10px] text-gray-500",children:"No test file"})})]},P.name))})]}),h.commitSha&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px]",children:[e.jsx("span",{className:"font-mono text-[#00a0c4] bg-[#00a0c4]/10 px-1.5 py-0.5 rounded",children:h.commitSha.slice(0,7)}),e.jsx("span",{className:"text-gray-500 truncate",children:h.commitMessage})]}),E&&h.modifiedFiles&&h.modifiedFiles.length>0&&e.jsx(cn,{files:h.modifiedFiles})]}),e.jsxs("button",{onClick:()=>S(y),className:"w-full py-1.5 text-[10px] text-gray-500 hover:text-gray-300 border-t border-[#3d3d3d] transition-colors cursor-pointer",children:["——— ",E?"Collapse":"Expand"," ———"]})]},y)})})]},p))]})})}function fn({hasProject:t,scenarios:s,analyzedEntities:r,allEntities:a=[],glossaryFunctions:c=[],glossaryEntries:i=[],projectRoot:l,activeScenarioId:o,onScenarioSelect:x,onAnalyzedScenarioSelect:S,onSwitchToBuild:b,zoomComponent:m,focusedEntity:p,onZoomChange:R,entityImports:h,pageFilePaths:N={},projectTitle:f,projectDescription:y,migrationMode:E="none",migrationState:P,onStartMigration:O,breadcrumbItems:J=[],onReseedPreview:Z}){const{pageGroups:B,componentGroups:q}=n.useMemo(()=>St(s),[s]),w=n.useMemo(()=>Ns(B,q),[B,q]),k=n.useMemo(()=>new Set(r.map(L=>L.sha)),[r]),F=n.useMemo(()=>Jr(h||{}),[h]),M=n.useCallback(L=>Kr(L,k,a,F),[k,a,F]),I=n.useMemo(()=>{const L=new Map;for(const X of a)L.set(X.sha,X.name);return L},[a]),V=n.useMemo(()=>Gr(B,q,w,M),[B,q,w,M]),W=n.useMemo(()=>r.filter(L=>L.entityType==="visual").sort((L,X)=>L.name.localeCompare(X.name)),[r]),[ce,v]=n.useState(()=>{try{return localStorage.getItem("codeyam-app-banner-dismissed")==="true"}catch{return!1}}),A=n.useCallback(()=>{v(!0);try{localStorage.setItem("codeyam-app-banner-dismissed","true")}catch{}},[]),[_,j]=n.useState(""),D=n.useRef(null),T=n.useRef(0),U=n.useCallback(()=>{D.current&&(T.current=D.current.scrollTop)},[]);n.useEffect(()=>{D.current&&T.current>0&&(D.current.scrollTop=T.current)});const Q=(p==null?void 0:p.sha)??"overview";if(!t)return e.jsx("div",{className:"flex-1 flex items-center justify-center font-['IBM_Plex_Sans']",children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx("h2",{className:"text-lg font-medium text-white m-0",children:"Ready to build something?"}),e.jsx("button",{onClick:b,className:"px-6 py-3 bg-[#005c75] text-white text-sm font-medium rounded-lg hover:bg-[#004d63] transition-colors cursor-pointer",children:"Start Building"})]})});if(E==="candidate")return e.jsx("div",{className:"flex-1 flex items-center justify-center font-['IBM_Plex_Sans']",children:e.jsxs("div",{className:"flex flex-col items-center gap-5 px-8 text-center max-w-[420px]",children:[e.jsx("h2",{className:"text-lg font-medium text-white m-0",children:"Migrate Your Project"}),e.jsx("p",{className:"text-sm text-gray-400 m-0 leading-relaxed",children:"It looks like you have an existing project. Claude can survey your codebase and systematically migrate it — deconstructing pages into clean components, extracting functions with tests, and creating scenarios. One page per session."}),e.jsx("button",{onClick:O,className:"px-6 py-3 bg-[#005c75] text-white text-sm font-medium rounded-lg hover:bg-[#004d63] transition-colors cursor-pointer",children:"Get Started"}),e.jsx("button",{onClick:b,className:"text-xs text-gray-500 hover:text-gray-300 bg-transparent border-none p-0 cursor-pointer underline",children:"Skip — build a new feature instead"})]})});if(E==="active"&&P){const L=P.pages||[],X=L.filter(G=>G.status==="complete").length,ee=L.length,K=ee>0?Math.round(X/ee*100):0;return e.jsxs("div",{className:"flex-1 flex flex-col overflow-auto p-4 font-['IBM_Plex_Sans']",children:[e.jsx("h2",{className:"text-lg font-medium text-white m-0 mb-3",children:"Project Migration"}),e.jsxs("div",{className:"mb-4",children:[e.jsx("div",{className:"flex items-center gap-2 mb-1",children:e.jsxs("span",{className:"text-xs text-gray-400",children:[X,"/",ee," pages (",K,"%)"]})}),e.jsx("div",{className:"w-full h-1.5 bg-[#2d2d2d] rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-[#005c75] rounded-full transition-all",style:{width:`${K}%`}})})]}),e.jsx("div",{className:"space-y-1.5",children:L.map((G,ue)=>{const xe=G.status==="complete"?"✓":G.status==="in-progress"?"→":"○",pe=G.status==="complete"?"text-green-400":G.status==="in-progress"?"text-cyan-400":"text-gray-600";return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`text-xs ${pe} w-3 text-center`,children:xe}),e.jsx("span",{className:`text-xs ${G.status==="in-progress"?"text-white font-medium":G.status==="complete"?"text-gray-400":"text-gray-600"}`,children:G.name}),e.jsx("span",{className:"text-[10px] text-gray-600",children:G.route}),G.status==="complete"&&e.jsxs("span",{className:"text-[10px] text-gray-600",children:[(G.extractedComponents||[]).length,"c"," ",(G.extractedFunctions||[]).length,"f"," ",G.scenarioCount||0,"s"]})]},ue)})}),(P.sharedComponents||[]).length>0&&e.jsxs("div",{className:"mt-4",children:[e.jsx("h3",{className:"text-xs font-medium text-gray-400 mb-1.5",children:"Shared Components"}),(P.sharedComponents||[]).map((G,ue)=>e.jsxs("div",{className:"text-[10px] text-gray-500 mb-0.5",children:[G.name," ",e.jsxs("span",{className:"text-gray-600",children:["— used in: ",(G.usedInPages||[]).join(", ")]})]},ue))]}),e.jsx("div",{className:"mt-4",children:e.jsx("button",{onClick:b,className:"px-4 py-2 bg-[#005c75] text-white text-xs font-medium rounded-lg hover:bg-[#004d63] transition-colors cursor-pointer",children:"Continue in Chat"})})]})}return s.length>0||W.length>0?p?e.jsx(Cs,{focusedEntity:p,breadcrumbItems:J,onZoomChange:R,projectRoot:l,scenarios:s,analyzedEntities:r,activeScenarioId:o,onScenarioSelect:x,onAnalyzedScenarioSelect:S,onSwitchToBuild:b,entityImports:h,glossaryFunctions:c,glossaryEntries:i,entityShaMap:w,componentGroups:q,visualEntities:W,isEntityComplete:M,onReseedPreview:Z}):e.jsx("div",{ref:D,onScroll:U,className:"flex-1 overflow-auto font-['IBM_Plex_Sans']",children:e.jsxs("div",{className:"p-4 space-y-4",children:[V.length>1&&e.jsx(Xr,{brokenEntities:V}),!ce&&e.jsxs("div",{className:"relative border border-[#2e7d32]/40 bg-cybg rounded-lg p-4 pr-10",children:[e.jsx("button",{onClick:A,className:"absolute top-3 right-3 text-[#D7FF63] hover:text-white bg-transparent border-none cursor-pointer p-0.5",title:"Dismiss",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:e.jsx("path",{d:"M2 2l8 8M10 2l-8 8"})})}),e.jsx("p",{className:"text-sm text-white font-medium m-0 leading-snug",children:"These are all the pages in your project."}),e.jsxs("p",{className:"text-sm text-gray-400 m-0 leading-snug mt-0.5",children:["(1) Select a scenario below and switch to"," ",e.jsx("button",{type:"button",onClick:b,className:"underline text-[#D7FF63] bg-transparent border-none cursor-pointer p-0 text-sm inline hover:text-[#D7FF63]/70 transition-colors",children:"build"})," ","to change or enhance an existing page."]}),e.jsx("p",{className:"text-sm text-gray-400 m-0 leading-snug mt-0.5",children:"(2) Select a page to see all of its sub-components and edit scenarios."})]}),B.size>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-3 font-['IBM_Plex_Mono']",children:[e.jsx("span",{className:"text-xs font-bold text-gray-400 uppercase tracking-wider shrink-0",children:"Pages"}),e.jsx("div",{className:"flex-1"}),e.jsxs("div",{className:"relative",style:{width:170},children:[e.jsxs("svg",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-500",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("path",{d:"M21 21l-4.35-4.35"})]}),e.jsx("input",{type:"text",placeholder:"SEARCH...",value:_,onChange:L=>j(L.target.value),className:"w-full pl-9 pr-3 py-2 text-xs bg-[#2a2a2a] border border-[#3d3d3d] rounded-md text-gray-300 placeholder-gray-600 outline-none focus:border-[#D7FF63]/50 transition-colors tracking-wider"})]}),e.jsxs("button",{onClick:b,className:"flex items-center gap-1.5 px-4 py-2 text-xs font-semibold text-[#1e1e1e] bg-[#D7FF63] rounded-md hover:bg-[#D7FF63]/80 transition-colors cursor-pointer shrink-0 uppercase tracking-wider",children:[e.jsx("span",{children:"+"})," New Page"]})]}),e.jsx("div",{className:"border-b border-[#2d2d2d] mt-3"}),[...B.entries()].sort(([L],[X])=>L==="Home"?-1:X==="Home"?1:L.localeCompare(X)).filter(([L])=>{if(!_.trim())return!0;const X=w.get(L);return((X?I.get(X):void 0)||L).toLowerCase().includes(_.trim().toLowerCase())}).map(([L,X])=>{const ee=X.some(K=>K.id===o);return e.jsx("div",{className:"mt-2",children:w.has(L)&&M(w.get(L))?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-center gap-1.5 py-1",children:e.jsxs("button",{onClick:()=>R(L,w.get(L)),className:`flex items-center gap-1.5 text-sm font-normal cursor-pointer hover:text-white transition-colors bg-transparent border-none p-0 ${ee?"text-[#D7FF63]":"text-gray-300"}`,children:[(()=>{const K=w.get(L);return(K?I.get(K):void 0)||L})(),e.jsxs("span",{className:`font-normal text-sm ${ee?"text-[#D7FF63]/60":"text-gray-500"}`,children:["(",X.length,")"]}),e.jsx("svg",{className:ee?"text-[#D7FF63]/60":"text-gray-500",width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M9 18l6-6-6-6"})})]})}),e.jsx("div",{className:"grid grid-cols-3 gap-2 pt-1",children:X.map(K=>e.jsx(Xe,{scenarioId:K.id,updatedAt:K.updatedAt,hasScreenshot:!!K.screenshotPath,name:K.name,isActive:K.id===o,onSelect:()=>x(K)},K.id))})]}):e.jsxs("div",{className:"py-2",children:[e.jsx("span",{className:"text-sm font-normal text-gray-500",children:(()=>{const K=w.get(L);return K&&I.get(K)||L})()}),e.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#E0D400",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),e.jsx("p",{className:"text-xs text-[#E0D400]/80 m-0 leading-relaxed",children:"Data missing for this page."}),e.jsx(ks,{name:L,scenarios:X,reason:w.has(L)?"incomplete":"missing"})]})]})},L)})]})]})},Q):e.jsx("div",{className:"flex-1 flex items-center justify-center font-['IBM_Plex_Sans']",children:e.jsxs("div",{className:"flex flex-col items-center gap-4 px-8 text-center",children:[f?e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-lg font-medium text-white m-0",children:f}),y&&e.jsx("p",{className:"text-sm text-gray-400 m-0 leading-relaxed",children:y})]}):e.jsx("h2",{className:"text-lg font-medium text-white m-0",children:"Your project is ready"}),e.jsx("p",{className:"text-sm text-gray-400 m-0 leading-relaxed",children:"Describe what you want to build in the Chat and your pages and components will appear here."}),e.jsx("button",{onClick:b,className:"px-6 py-3 bg-[#005c75] text-white text-sm font-medium rounded-lg hover:bg-[#004d63] transition-colors cursor-pointer",children:"Start Building"})]})})}const gs=[{key:"app",label:"App"},{key:"build",label:"Build"},{key:"data",label:"Structure"},{key:"history",label:"History"}],gn=()=>e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 12 12",fill:"none",className:"text-[#8E8E8E] shrink-0",children:e.jsx("path",{d:"M4.5 3L7.5 6L4.5 9",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})});function bn({activeTab:t,onTabChange:s,buildIdle:r,projectTitle:a,breadcrumbItems:c,onBreadcrumbNavigate:i}){const[l,o]=n.useState(!1),x=n.useRef(null);n.useEffect(()=>{if(!l)return;const b=m=>{x.current&&!x.current.contains(m.target)&&o(!1)};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[l]);const S=c&&c.length>0;return e.jsxs("div",{className:"shrink-0 z-20 @container",children:[e.jsxs("div",{className:"bg-black h-10 flex items-center px-4 gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("img",{src:Pr,alt:"CodeYam",className:"h-5 shrink-0"}),e.jsx("span",{className:"text-sm font-medium text-white whitespace-nowrap hidden @min-[500px]:inline",children:"CodeYam Editor"})]}),e.jsx("span",{className:"text-[#8E8E8E] text-sm shrink-0",children:"/"}),e.jsx("div",{className:"hidden @min-[350px]:flex items-center gap-1",children:gs.map(b=>e.jsxs("button",{onClick:()=>s(b.key),className:`px-2.5 py-2.5 text-sm transition-colors cursor-pointer border-b ${t===b.key?"text-[#D7FF63] border-[#D7FF63] font-medium":"text-[#8E8E8E] border-transparent hover:text-white font-light"}`,children:[b.label,b.key==="build"&&r&&t!=="build"&&e.jsx("span",{className:"ml-1 inline-block w-1.5 h-1.5 rounded-full bg-amber-400 animate-pulse"})]},b.key))})]}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:()=>s("settings"),className:`hidden @min-[350px]:block p-1.5 rounded-md transition-colors cursor-pointer ${t==="settings"?"text-[#D7FF63]":"text-[#8E8E8E] hover:text-white"}`,title:"Settings",children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"3"}),e.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})}),e.jsxs("div",{className:"@min-[350px]:hidden relative",ref:x,children:[e.jsx("button",{onClick:()=>o(!l),className:"p-1.5 rounded-md transition-colors cursor-pointer text-[#8E8E8E] hover:text-white",title:"Menu",children:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[e.jsx("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),e.jsx("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),e.jsx("line",{x1:"3",y1:"18",x2:"21",y2:"18"})]})}),l&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 bg-[#2d2d2d] border border-[#3d3d3d] rounded-lg shadow-lg py-1 min-w-[140px] z-50",children:[gs.map(b=>e.jsxs("button",{onClick:()=>{s(b.key),o(!1)},className:`w-full text-left px-4 py-2 text-sm transition-colors cursor-pointer bg-transparent border-none ${t===b.key?"text-[#D7FF63]":"text-[#8E8E8E] hover:text-white hover:bg-[#3d3d3d]"}`,children:[b.label,b.key==="build"&&r&&t!=="build"&&e.jsx("span",{className:"ml-1 inline-block w-1.5 h-1.5 rounded-full bg-amber-400 animate-pulse"})]},b.key)),e.jsx("div",{className:"border-t border-[#3d3d3d] my-1"}),e.jsx("button",{onClick:()=>{s("settings"),o(!1)},className:`w-full text-left px-4 py-2 text-sm transition-colors cursor-pointer bg-transparent border-none ${t==="settings"?"text-[#D7FF63]":"text-[#8E8E8E] hover:text-white hover:bg-[#3d3d3d]"}`,children:"Settings"})]})]})]}),e.jsx("div",{className:"bg-[#161616] h-8 flex items-center px-4 border-b border-[#2d2d2d]",children:e.jsx("nav",{className:"flex items-center gap-2 text-sm min-w-0",children:S?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>i==null?void 0:i(),className:"text-[#8E8E8E] hover:text-white transition-colors bg-transparent border-none p-0 cursor-pointer shrink-0",children:a||"Untitled Project"}),c.slice(1).map((b,m)=>{const p=m===c.length-2;return e.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(gn,{}),p?e.jsx("span",{className:"text-white truncate",children:b.name}):e.jsx("button",{type:"button",onClick:()=>i==null?void 0:i(b.componentName,b.entitySha),className:"text-[#8E8E8E] hover:text-white transition-colors bg-transparent border-none p-0 cursor-pointer truncate",children:b.name})]},b.componentName||b.name)})]}):e.jsx("span",{className:"text-[#8E8E8E]",children:a||"Untitled Project"})})})]})}function yn({onMouseDown:t,onDoubleClick:s,isDragging:r}){return e.jsxs("div",{className:"shrink-0 relative flex items-center justify-center cursor-col-resize group",style:{width:12},onMouseDown:t,onDoubleClick:s,children:[e.jsx("div",{className:"absolute inset-y-0 left-1/2 -translate-x-1/2",style:{width:r?3:1,backgroundColor:r?"#3b82f6":"#3d3d3d",transition:"width 100ms, background-color 100ms"}}),!r&&e.jsx("div",{className:"absolute inset-0 bg-blue-500/0 group-hover:bg-blue-500/20 transition-colors pointer-events-none"}),e.jsxs("div",{className:"relative z-10 flex flex-col gap-[3px] opacity-0 group-hover:opacity-100 transition-opacity",style:r?{opacity:1}:void 0,children:[e.jsx("div",{className:"w-2 h-px bg-gray-400"}),e.jsx("div",{className:"w-2 h-px bg-gray-400"}),e.jsx("div",{className:"w-2 h-px bg-gray-400"})]})]})}const bs=300,qe=150;function jn(t){const[s,r]=n.useState(null),[a,c]=n.useState(!1),i=n.useRef(0),l=n.useRef(null);n.useEffect(()=>{t.current&&r(Math.round(t.current.offsetWidth*.5))},[t]);const o=n.useCallback(()=>{var f;return((f=t.current)==null?void 0:f.offsetWidth)??(typeof window<"u"?window.innerWidth:1024)},[t]),x=n.useCallback(f=>{f.preventDefault(),c(!0)},[]),S=n.useCallback(()=>{r(Math.round(o()*.5))},[o]),b=n.useCallback(()=>{r(f=>(f&&f>0&&(l.current=f),0))},[]),m=n.useCallback(()=>{const f=l.current;l.current=null,r(f&&f>=bs?f:Math.round(o()*.5))},[o]),p=n.useCallback(()=>{r(Math.round(o()*.5))},[o]);n.useEffect(()=>{if(!a)return;document.body.style.cursor="col-resize",document.body.style.userSelect="none";const f=E=>{cancelAnimationFrame(i.current),i.current=requestAnimationFrame(()=>{var w;const P=(w=t.current)==null?void 0:w.getBoundingClientRect(),O=(P==null?void 0:P.left)??0,Z=((P==null?void 0:P.width)??window.innerWidth)-qe,B=E.clientX-O,q=Math.min(Math.max(B,bs),Z);r(q)})},y=E=>{var B;cancelAnimationFrame(i.current),c(!1);const P=(B=t.current)==null?void 0:B.getBoundingClientRect(),O=(P==null?void 0:P.left)??0,J=(P==null?void 0:P.width)??window.innerWidth,Z=E.clientX-O;Z<qe?r(0):J-Z<qe&&r(J)};return document.addEventListener("mousemove",f),document.addEventListener("mouseup",y),()=>{cancelAnimationFrame(i.current),document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",y),document.body.style.cursor="",document.body.style.userSelect=""}},[a,t]),n.useEffect(()=>{const f=()=>{r(y=>{if(y===null||y===0)return y;const E=o();return y>=E?E:Math.min(y,E-qe)})};if(!(typeof window>"u"))return window.addEventListener("resize",f),()=>window.removeEventListener("resize",f)},[o]);const R=o(),h=s===0,N=s!==null&&s>=R;return{editorWidth:s,isDragging:a,isEditorCollapsed:h,isPreviewCollapsed:N,handleMouseDown:x,handleDoubleClick:S,collapseEditor:b,expandEditor:m,expandPreview:p}}function vn({preview:t,onDismiss:s,onLoadCommit:r}){return e.jsxs("div",{className:"flex flex-col items-center gap-6 max-w-[700px] w-full",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("h2",{className:"text-lg font-semibold text-[#333] m-0 font-['IBM_Plex_Sans']",children:"Journal Screenshot"}),e.jsx("p",{className:"text-sm text-[#888] mt-1 m-0 font-['IBM_Plex_Sans']",children:"This is a snapshot from a previous version — not a live preview"})]}),e.jsx("div",{className:"rounded-lg overflow-hidden border-2 border-[#ccc] shadow-md max-w-full w-fit",children:e.jsx("img",{src:t.screenshotUrl,alt:t.scenarioName,className:"max-w-full h-auto block"})}),e.jsxs("div",{className:"flex items-center gap-2 text-sm text-[#666]",children:[t.commitSha&&e.jsx("span",{className:"font-mono text-xs text-[#00a0c4] bg-[#00a0c4]/15 px-2 py-0.5 rounded",children:t.commitSha.slice(0,7)}),e.jsxs("span",{className:"truncate",children:[t.scenarioName,t.commitMessage&&` — ${t.commitMessage}`]})]}),e.jsx("div",{className:"flex items-center gap-3",children:t.commitSha&&r&&e.jsx(Nn,{commitSha:t.commitSha,onLoadCommit:r})})]})}function Nn({commitSha:t,onLoadCommit:s}){const[r,a]=n.useState(!1),[c,i]=n.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{a(!0),i(null),s(t).then(l=>{l.success||i(l.error||"Failed to load commit")}).catch(l=>{i(l instanceof Error?l.message:"Network error")}).finally(()=>a(!1))},disabled:r,className:"bg-[#005c75] hover:bg-[#004d63] disabled:opacity-50 text-white text-sm font-medium px-4 py-1.5 rounded transition-colors cursor-pointer",children:r?"Reverting...":"Revert to this code and load this version"}),c&&e.jsx("div",{className:"bg-red-50 border border-red-200 rounded px-4 py-2 text-sm text-red-600 w-full text-center",children:c})]})}function wn({preview:t,onDismiss:s}){return e.jsxs("div",{className:"flex flex-col items-center gap-6 max-w-[700px] w-full",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-200 m-0 font-['IBM_Plex_Sans']",children:t.scenarioName}),e.jsxs("div",{className:"flex items-center justify-center gap-2 mt-2",children:[e.jsx("span",{className:"inline-block w-2 h-2 rounded-full bg-amber-400 animate-pulse"}),e.jsx("p",{className:"text-sm text-amber-400/90 m-0 font-['IBM_Plex_Sans']",children:"The app is being edited - you can control the live preview when building is paused or complete."})]})]}),t.hasScreenshot?e.jsx("div",{className:"rounded-lg overflow-hidden border-2 border-[#4d4d4d] shadow-md max-w-full w-fit",children:e.jsx(_e,{scenarioId:t.scenarioId,updatedAt:t.updatedAt,alt:t.scenarioName,className:"max-w-full",imgClassName:"max-w-full h-auto block"})}):e.jsx("div",{className:"rounded-lg border-2 border-[#4d4d4d] bg-[#1a1a1a] flex items-center justify-center w-[400px] h-[300px]",children:e.jsx("span",{className:"text-sm text-gray-500",children:"No screenshot available"})}),e.jsx("button",{onClick:s,className:"text-xs text-gray-500 hover:text-gray-300 bg-transparent border-none cursor-pointer transition-colors",children:"Dismiss"})]})}function Sn({analysisId:t,scenarioId:s,scenarioName:r,entityName:a,projectSlug:c,onStateChange:i}){const{interactiveServerUrl:l,isStarting:o,isLoading:x}=Er({analysisId:t,scenarioId:s,scenarioName:r,entityName:a,projectSlug:c,enabled:!0});return n.useEffect(()=>{i(l,o||x)},[l,o,x,i]),null}function kn({onSaveToCurrent:t,onSaveAsNew:s,onDismiss:r,isSaving:a,scenarioName:c}){return e.jsxs("div",{className:"flex items-center justify-between px-4 py-1.5 bg-emerald-900/60 border-b border-emerald-700/50 text-emerald-200 text-xs",children:[e.jsx("span",{className:"font-medium",children:c?e.jsxs(e.Fragment,{children:["Data modified in “",c,"”."]}):"Data modified."}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:t,disabled:a,className:"px-2.5 py-0.5 bg-emerald-600 hover:bg-emerald-500 disabled:opacity-50 text-white text-xs font-medium rounded transition-colors cursor-pointer disabled:cursor-not-allowed",children:a?"Saving...":"Save to Scenario"}),e.jsx("button",{onClick:s,disabled:a,className:"px-2.5 py-0.5 bg-emerald-800 hover:bg-emerald-700 disabled:opacity-50 text-emerald-200 text-xs font-medium rounded transition-colors cursor-pointer disabled:cursor-not-allowed",children:"Save as New"}),e.jsx("button",{onClick:r,disabled:a,className:"text-emerald-400 hover:text-emerald-200 disabled:opacity-50 transition-colors cursor-pointer disabled:cursor-not-allowed",title:"Dismiss",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]})}function Cn(t,s){return s.status==="error"?{url:null,proxyUrl:null,isStarting:!1,error:s.errorMessage||"Dev server crashed",canStartServer:t.canStartServer,autoStartAttempted:t.autoStartAttempted,shouldAutoStart:!1}:s.url?{url:s.url,proxyUrl:s.proxyUrl||null,isStarting:!1,error:null,canStartServer:!0,autoStartAttempted:t.autoStartAttempted,shouldAutoStart:!1}:s.status==="starting"?{...t,isStarting:!0,error:null,canStartServer:!0,shouldAutoStart:!1}:s.status==="stopped"?t.url?{...t,url:null,isStarting:!1,shouldAutoStart:!1}:t.autoStartAttempted?{...t,isStarting:!1,shouldAutoStart:!1}:{...t,autoStartAttempted:!0,shouldAutoStart:!0}:{...t,shouldAutoStart:!1}}function Pn(t){const[s,r]=n.useState({url:null,proxyUrl:null,isStarting:!1,error:null,canStartServer:!0,autoStartAttempted:!1}),a=n.useRef(s);a.current=s,n.useEffect(()=>{let l=!1,o=null;const x=async()=>{try{const S=await fetch("/api/editor-dev-server");if(l)return;const b=await S.json(),m=Cn(a.current,b),{shouldAutoStart:p,...R}=m;if(r(R),p&&!(t!=null&&t.skipAutoStart))try{const h=await fetch("/api/editor-dev-server",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"start"})});if(l)return;h.ok?r(N=>({...N,isStarting:!0})):r(N=>({...N,canStartServer:!1}))}catch{}}catch{}};return x(),o=setInterval(()=>void x(),2e3),()=>{l=!0,o&&clearInterval(o)}},[s.url]);const c=n.useCallback(()=>{r(l=>({...l,error:null,isStarting:!0})),fetch("/api/editor-dev-server",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"restart"})}).catch(()=>{})},[]),i=n.useCallback(()=>{r(l=>({...l,error:null,isStarting:!0})),fetch("/api/editor-dev-server",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"start"})}).catch(()=>{})},[]);return{devServerUrl:s.url,proxyUrl:s.proxyUrl,isStarting:s.isStarting,error:s.error,canStartServer:s.canStartServer,retryServer:c,startServer:i}}function En(t){const s=n.useRef(null),r=n.useRef(null);n.useEffect(()=>{if(typeof document>"u")return;r.current||(r.current=document.createElement("canvas"),r.current.width=64,r.current.height=64);const a=document.querySelector('link[rel="icon"]');if(!a)return;if(s.current||(s.current=a.href),!t){a.href=s.current;return}const c=new Image;c.crossOrigin="anonymous",c.onload=()=>{const i=r.current,l=i.getContext("2d");l.clearRect(0,0,64,64);const o=56,x=(64-o)/2;l.drawImage(c,x,x,o,o);const S=12,b=64-S-1,m=S+1;l.beginPath(),l.arc(b,m,S,0,2*Math.PI),l.fillStyle="#ef4444",l.fill(),a.href=i.toDataURL("image/png")},c.src=s.current},[t]),n.useEffect(()=>()=>{if(typeof document>"u")return;const a=document.querySelector('link[rel="icon"]');a&&s.current&&(a.href=s.current)},[])}function Un({currentUrl:t,nextUrl:s,formMethod:r,defaultShouldRevalidate:a}){return r||t.pathname===s.pathname?a:t.pathname.startsWith("/editor")&&s.pathname.startsWith("/editor")?!1:a}const Hn=()=>[{title:"Editor - CodeYam"},{name:"description",content:"CodeYam Code + Data Editor"}];class Fn extends n.Component{constructor(){super(...arguments);ns(this,"state",{error:null,errorInfo:null})}static getDerivedStateFromError(r){return{error:r,errorInfo:null}}componentDidCatch(r,a){console.error("[EditorErrorBoundary] Error:",r.message),console.error("[EditorErrorBoundary] Component stack:",a.componentStack),console.error("[EditorErrorBoundary] Loader snapshot:",JSON.stringify(this.props.loaderSnapshot,null,2)),this.setState({errorInfo:a})}render(){var r;return this.state.error?e.jsx("div",{className:"fixed inset-0 bg-[#1e1e1e] flex items-center justify-center p-8",children:e.jsxs("div",{className:"max-w-[600px] w-full space-y-4",children:[e.jsx("h2",{className:"text-lg font-semibold text-red-400 font-['IBM_Plex_Sans'] m-0",children:"Something went wrong"}),e.jsx("pre",{className:"text-xs text-gray-300 bg-[#2d2d2d] p-3 rounded overflow-auto max-h-[120px]",children:this.state.error.message}),((r=this.state.errorInfo)==null?void 0:r.componentStack)&&e.jsxs("details",{className:"text-xs text-gray-500",children:[e.jsx("summary",{className:"cursor-pointer hover:text-gray-300 transition-colors",children:"Component stack"}),e.jsx("pre",{className:"mt-2 bg-[#2d2d2d] p-3 rounded overflow-auto max-h-[200px] text-yellow-300",children:this.state.errorInfo.componentStack})]}),e.jsx("p",{className:"text-xs text-gray-500 m-0",children:"Full diagnostics are in the browser console."}),e.jsx("button",{onClick:()=>window.location.reload(),className:"px-4 py-2 bg-[#005c75] text-white text-sm rounded hover:bg-[#004d63] transition-colors cursor-pointer",children:"Reload"})]})}):this.props.children}}const Vn=cr(function(){var es,ts;const{projectSlug:s,projectRoot:r,hasProject:a,scenarios:c,allScenarios:i,analyzedEntities:l,allEntities:o,glossaryFunctions:x,glossaryEntries:S,entityImports:b,pageFilePaths:m,entityChangeStatus:p,modifiedFiles:R,featureName:h,userPrompt:N,projectTitle:f,projectDescription:y,defaultScreenSize:E,screenSizes:P,editorStep:O,editorStepLabel:J,claudeSessionId:Z,focusedEntitySha:B,newerEntitySha:q,focusedEntity:w,migrationMode:k,migrationState:F}=dr(),[M,I]=xr(),V=ur(),W=n.useRef(null),ce=n.useRef(null),v=n.useRef(null),A=n.useRef(null),[_,j]=n.useState(B);n.useEffect(()=>{j(B)},[B]),n.useEffect(()=>{const d=g=>{const C=g.target;(C.tagName==="BUTTON"||C.closest("button"))&&(C.closest("button")??C).blur()};return document.addEventListener("mouseup",d),()=>document.removeEventListener("mouseup",d)},[]);const D=n.useMemo(()=>as(_,o),[_,o,i]),T=(D==null?void 0:D.displayName)??void 0,U=M.get("scenario")||((es=Ge(i))==null?void 0:es.id)||void 0,[Q,$]=n.useState(()=>T?[T]:[]),L=n.useRef(null),X=n.useRef([]),ee=n.useRef(null);n.useEffect(()=>{var te;const d=U||((te=Ge(i))==null?void 0:te.id);if(!gr(d,L.current))return;const g=i.find(ie=>ie.id===d);if(!g)return;L.current=d;const C=yt(g,X.current,ee.current);C&&je(C);const z=Me(g.name);fetch("/api/editor-switch-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioSlug:z,scenarioId:g.id,scenarioName:g.name,scenarioType:g.type})}).catch(()=>{})},[U,i]),n.useEffect(()=>{const d=new BroadcastChannel("codeyam-editor");return d.onmessage=g=>{var C;if(((C=g.data)==null?void 0:C.type)==="switch-scenario"&&g.data.scenarioId){const z=g.data.scenarioId,te=i.find(De=>De.id===z);if(!te)return;L.current=z;const ie=new URLSearchParams(M);ie.set("scenario",z),ie.delete("zoom"),I(ie),u(null),Y(null),fe(null),he(!0);const Le=Me(te.name);fetch("/api/editor-switch-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioSlug:Le,scenarioId:z,scenarioType:te.type})}).then(()=>{ae(!1),ke(De=>De+1)}).catch(()=>{he(!1)})}},()=>d.close()},[M,I,i]),n.useEffect(()=>{if(M.get("ref")!=="link"||!U)return;const d=new BroadcastChannel("codeyam-editor");d.postMessage({type:"switch-scenario",scenarioId:U}),d.close(),window.close()},[]);const{devServerUrl:K,proxyUrl:G,isStarting:ue,error:xe,canStartServer:pe,retryServer:Be,startServer:We}=Pn({skipAutoStart:k==="candidate"||k==="active"}),[be,ae]=n.useState(!1),[se,u]=n.useState(null),[H,Y]=n.useState(null),[re,kt]=n.useState(!1),[et,fe]=n.useState(null),[tt,ye]=n.useState(null),Ps=n.useCallback(async d=>{const C=await(await fetch("/api/editor-load-commit",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({commitSha:d})})).json();return C.success&&(fe(null),ae(!1)),C},[]),Es=n.useCallback((d,g)=>{Y(C=>(d&&d!==C&&ae(!1),d)),!g&&d&&ae(!0),kt(g)},[]),st=n.useCallback(d=>{fe(null),u(C=>(C&&C.analysisId===d.analysisId||(Y(null),ke(te=>te+1)),d)),kt(!0),ae(!1);const g=new URLSearchParams(M);g.delete("scenario"),g.delete("zoom"),I(g)},[M,I]),[oe,je]=n.useState(E?{name:E.name,width:E.width,height:E.height}:{name:"Desktop",width:1440,height:900}),[Ct,Pt]=n.useState(!1),[le,Et]=n.useState(!1),Ft=E?{name:E.name,width:E.width,height:E.height}:null;ee.current=Ft;const Dt=mr(),ne=n.useMemo(()=>{const d=Dt.pathname.split("/").filter(Boolean),g=d[d.length-1];return g==="build"||g==="history"||g==="settings"?g:g==="structure"?"data":"app"},[Dt.pathname]),de=n.useCallback(d=>{j(null),$([]);const g=d==="app"?"":`/${d==="data"?"structure":d}`,C=M.get("scenario"),z=C?`?scenario=${C}`:"";V(`/editor${g}${z}`)},[V,M]),rt=n.useCallback(()=>{de("build"),ve(!0)},[de]),Fs=n.useCallback(()=>{de("build"),ve(!0),setTimeout(()=>{var d;(d=W.current)==null||d.sendInput("codeyam editor migrate")},300)},[de]),[Ds,ve]=n.useState(ne==="build"),Ts=!!(h&&O),[ze,Ls]=n.useState(Ts?"pending":"no-session"),Tt=n.useRef(!1);n.useEffect(()=>{ze==="pending"&&!Tt.current&&(Tt.current=!0,de("build"),ve(!0))},[ze,de]);const Ms=n.useCallback(()=>{Ls("continue")},[]),[nt,at]=n.useState(!1),[As,Lt]=n.useState(!1),Mt=n.useRef(!1),Ue=n.useRef(0),Is=n.useRef(!1),$s=n.useCallback(d=>{at(d),d||(Is.current=!0),d&&!Mt.current&&(Lt(!1),Ue.current=Date.now()),d||(Ue.current=0),Mt.current=d},[]),[me,Rs]=n.useState(!1),it=n.useRef(!1),Os=n.useCallback(d=>{d!==it.current&&(console.log("[Editor] claudeBuilding: %s → %s",it.current,d),it.current=d,Rs(d))},[]);En(nt);const At=n.useRef(me);n.useEffect(()=>{var g;const d=At.current&&!me;if(At.current=me,!me)if(d){const C=M.get("scenario")||((g=Ge(i))==null?void 0:g.id),z=i.find(te=>te.id===C);if(z){console.log("[Editor] Building stopped, loading live preview for: %s",z.name),ye(null);const te=Me(z.name);L.current=z.id,he(!0),Ce(!1),ae(!1),fetch("/api/editor-switch-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioSlug:te,scenarioId:z.id,scenarioType:z.type,skipBroadcast:!0})}).then(()=>{ke(ie=>ie+1)}).catch(()=>{he(!1),ae(!0)})}else ye(null)}else ye(null)},[me,M,i]);const{editorWidth:It,isDragging:$t,isEditorCollapsed:ge,isPreviewCollapsed:ot,handleMouseDown:_s,handleDoubleClick:Bs,collapseEditor:Ws,expandEditor:Rt,expandPreview:zs}=jn(A),[lt,Ot]=n.useState(!1),Us=n.useCallback(()=>{Ot(!0),de("build"),ve(!0)},[de]),_t=n.useCallback(()=>{Ot(!1)},[]),Hs=n.useCallback(d=>{je(d),fetch("/api/editor-project-info",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultScreenSize:d,skipBroadcast:!0})})},[]),[Bt,Wt]=n.useState(br);n.useEffect(()=>{const d=yr();Wt(d),d.systemNotification&&typeof Notification<"u"&&Notification.permission==="default"&&Notification.requestPermission()},[]);const Vs=n.useCallback(d=>{Wt(d),jr(d)},[]);n.useEffect(()=>{if(ne==="build"){at(!1);const d=setTimeout(()=>{var g,C;(g=W.current)==null||g.scrollToBottom(),(C=W.current)==null||C.focus()},50);return()=>clearTimeout(d)}},[ne]),n.useEffect(()=>{function d(){!document.hidden&&ne==="build"&&at(!1)}return document.addEventListener("visibilitychange",d),()=>document.removeEventListener("visibilitychange",d)},[ne]);const[Ne,Js]=n.useState(null);n.useEffect(()=>{const d=v.current;if(!d)return;const g=new ResizeObserver(C=>{const z=C[0];z&&Js({width:z.contentRect.width,height:z.contentRect.height})});return g.observe(d),()=>g.disconnect()},[]);const we=n.useMemo(()=>Ne?vr(Ne,oe):1,[Ne,oe]),[Se,ke]=n.useState(0),[zt,ct]=n.useState(null),[He,he]=n.useState(!1),Ve=n.useRef(!1),[Ks,Ce]=n.useState(!1),[Gs,Ut]=n.useState(!1),dt=n.useRef(0);n.useEffect(()=>{Se>0&&(dt.current=Date.now()+3e3)},[Se]);const Ys=n.useCallback(()=>{if(Date.now()<dt.current)return;const d=Ue.current;d===0||Date.now()-d<5e3||Ce(!0)},[]);n.useEffect(()=>{const d=g=>{var C;if(((C=g.data)==null?void 0:C.type)==="codeyam-localstorage-changed"){if(Date.now()<dt.current)return;const z=Ue.current;if(z===0||Date.now()-z<5e3)return;Ce(!0)}};return window.addEventListener("message",d),()=>window.removeEventListener("message",d)},[]);const Ht=n.useCallback(async d=>{Ut(!0);try{let g;const C=ce.current;C!=null&&C.contentWindow&&(g=await new Promise(ie=>{const Le=setTimeout(()=>ie(void 0),2e3),De=ss=>{var rs;((rs=ss.data)==null?void 0:rs.type)==="codeyam-localstorage-state"&&(clearTimeout(Le),window.removeEventListener("message",De),ie(ss.data.data))};window.addEventListener("message",De),C.contentWindow.postMessage({type:"codeyam-get-localstorage"},"*")}));const te=await(await fetch("/api/editor-save-seed-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mode:d,localStorage:g})})).json();te.success?Ce(!1):console.error("[editor] Save seed state failed:",te.error)}catch(g){console.error("[editor] Save seed state error:",g)}finally{Ut(!1)}},[]),qs=n.useCallback((d,g)=>{if(ct(d||null),g){const C=new URLSearchParams(M);C.set("scenario",g),L.current=g,I(C);const z=i.find(te=>te.id===g);if(z){const te=yt(z,X.current,ee.current);te&&je(te)}}fe(null),ae(!1),ke(C=>C+1)},[M,I,i]),{customSizes:xt,addCustomSize:Xs,removeCustomSize:Qs}=pr(s),ut=n.useMemo(()=>Dr(P),[P]),mt=n.useMemo(()=>[...ut,...xt],[ut,xt]);X.current=mt;const Je=n.useMemo(()=>{const d=new Map;for(const g of o){d.set(g.name,g.sha);const C=Oe(Re(g.filePath));C!==g.name&&d.set(C,g.sha)}return d},[o]),Vt=n.useMemo(()=>{const d=new Map;for(const g of o)d.set(g.sha,g.name);return d},[o]),Jt=n.useMemo(()=>{const d=[{name:"App"}];for(const g of Q){const C=Je.get(g),z=C?Vt.get(C):void 0;d.push({name:z||g,componentName:g,entitySha:C})}return d},[Q,Je,Vt]),{pageGroups:Kt,componentGroups:ht}=n.useMemo(()=>St(i),[i]),Ke=n.useMemo(()=>Ns(Kt,ht),[Kt,ht]),[Zs,er]=n.useState("application"),[Pe,pt]=n.useState([]),[ft,Gt]=n.useState(null),Yt=n.useMemo(()=>ft?as(ft,o):null,[ft,o,i]),qt=n.useMemo(()=>{const d=[{name:"App"}];for(const g of Pe)d.push({name:g,componentName:g,entitySha:Je.get(g)});return d},[Pe,Je]),gt=n.useCallback((d,g)=>{if(!d){pt([]),Gt(null);return}const C=g||Ke.get(d);if(!C)return;const z=Pe.indexOf(d);z>=0?pt(Pe.slice(0,z+1)):pt([...Pe,d]),Gt(C)},[Pe,Ke]),Xt=n.useCallback((d,g)=>{if(!d){$([]),j(null);const ie=M.get("scenario"),Le=ie?`?scenario=${ie}`:"";V(`/editor${Le}`);return}if(!g){console.error(`[editor] No entity SHA for "${d}" — entity missing from database`);return}const C=Q.indexOf(d);C>=0?$(Q.slice(0,C+1)):$([...Q,d]);const z=i.find(ie=>ie.entitySha===g);j(g);const te=z?`?scenario=${z.id}`:"";V(`/editor/entity/${g}${te}`)},[V,i,Q,M]),Qt=n.useCallback(d=>{he(!0),Ve.current=!0,Ce(!1),ae(!1);const g=Me(d.name);fetch("/api/editor-switch-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioSlug:g,scenarioId:d.id,scenarioType:d.type,skipBroadcast:!0})}).then(()=>{Ve.current=!1,ke(C=>C+1)}).catch(()=>{Ve.current=!1,he(!1),ae(!0)})},[]),Ee=n.useCallback(d=>{console.log("[Editor] Scenario selected: %s (claudeBuilding=%s)",d.name,me),u(null),Y(null),fe(null),ct(null);const g=yt(d,mt,Ft);g&&je(g),L.current=d.id;const C=new URLSearchParams(M);C.set("scenario",d.id),I(C),me?ye({scenarioId:d.id,scenarioName:d.name,updatedAt:d.updatedAt,hasScreenshot:!!d.screenshotPath}):(ye(null),Qt(d))},[M,I,mt,me,Qt]),tr=n.useCallback(()=>{const d=U;if(!d)return;const g=i.find(z=>z.id===d);if(!g)return;const C=Me(g.name);ae(!1),fetch("/api/editor-switch-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioSlug:C,scenarioId:g.id,scenarioType:g.type})}).then(()=>{ke(z=>z+1)})},[U,i]),sr=n.useCallback(d=>{if(!d.commitSha){const g=i.find(C=>C.name===d.scenarioName);if(g){Ee(g);return}}fe(d)},[i,Ee]),rr=d=>{const g={name:d.name,width:d.width,height:d.height};je(g),fetch("/api/editor-project-info",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultScreenSize:g,skipBroadcast:!0})})},nr=(d,g,C)=>{Xs(d,g,C)},ar=d=>{je(d),fetch("/api/editor-project-info",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultScreenSize:d,skipBroadcast:!0})})};n.useEffect(()=>{const d=g=>{var C;if(((C=g.data)==null?void 0:C.type)==="codeyam-preview-ready"&&!se){if(Ve.current)return;ae(!0),he(!1)}};return window.addEventListener("message",d),()=>window.removeEventListener("message",d)},[se]);const Zt=()=>{se||setTimeout(()=>{ae(d=>(d||he(!1),!0))},5e3)},Fe=n.useMemo(()=>Nr({activeAnalyzedScenario:!!se,analyzedPreviewUrl:H,activeScenarioId:U||null,scenarios:i,proxyUrl:G,devServerUrl:K,zoomComponent:T||null}),[G,K,T,U,i,se,H]),bt=n.useMemo(()=>{const d=wr(Fe,zt);if(!d)return null;const g=d.includes("?")?"&":"?";return`${d}${g}__cb=${Se}`},[Fe,zt,Se]),ir=n.useMemo(()=>({projectSlug:s,hasProject:a,scenarioCount:c==null?void 0:c.length,allScenarioCount:i==null?void 0:i.length,analyzedEntityCount:l==null?void 0:l.length,glossaryFunctionCount:x==null?void 0:x.length,entityChangeStatusKeys:p?Object.keys(p):[],featureName:h}),[s,a,c,i,l,x,p,h]);return e.jsxs(e.Fragment,{children:[e.jsx(Fn,{loaderSnapshot:ir,children:e.jsxs("div",{className:"fixed inset-0 bg-[#2d2d2d] flex flex-col",children:[se&&e.jsx(Sn,{analysisId:se.analysisId,scenarioId:se.scenarioId,scenarioName:se.scenarioName,entityName:se.entityName,projectSlug:s,onStateChange:Es},se.analysisId),e.jsxs("div",{ref:A,className:"flex-1 flex min-h-0",children:[ge&&e.jsx("div",{className:"shrink-0 flex items-center justify-center cursor-pointer hover:bg-[#3d3d3d] transition-colors",style:{width:8,backgroundColor:"#2d2d2d"},onClick:Rt,title:"Expand editor",children:e.jsx("svg",{width:"6",height:"10",viewBox:"0 0 6 10",fill:"none",stroke:"#888",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M1 1l4 4-4 4"})})}),e.jsxs("aside",{className:"bg-[#1e1e1e] shrink-0 flex flex-col overflow-hidden",style:{...ge?{display:"none"}:It!==null?{width:`${It}px`}:{width:"50%"}},children:[q&&D&&e.jsxs("div",{className:"px-3 py-2 text-xs flex items-center justify-between",style:{background:"#2a1f00",borderBottom:"1px solid #3d2e00",color:"#f0c040"},children:[e.jsxs("span",{children:["Viewing an older version of"," ",e.jsx("strong",{children:D.name}),". A newer version exists."]}),e.jsx("a",{href:`/editor/entity/${q}`,className:"px-2 py-0.5 rounded text-xs",style:{background:"#3d2e00",color:"#f0c040",textDecoration:"none"},children:"View latest"})]}),e.jsx(bn,{activeTab:ne,onTabChange:d=>{de(d),d==="build"&&ve(!0),fetch("/api/telemetry-page-view",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({route:`/editor/${d}`})}).catch(()=>{})},buildIdle:nt,projectTitle:f,breadcrumbItems:ne==="data"?qt:Jt,onBreadcrumbNavigate:ne==="data"?gt:Xt}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-hidden relative",children:[nt&&ne!=="build"&&!As&&e.jsxs("div",{className:"absolute top-3 left-1/2 -translate-x-1/2 z-50 animate-[slideDown_0.3s_ease-out]",children:[e.jsx("style",{children:`
87
87
  @keyframes slideDown {
88
88
  from { transform: translate(-50%, -100%); opacity: 0; }
89
89
  to { transform: translate(-50%, 0); opacity: 1; }
90
90
  }
91
- `}),e.jsxs("div",{className:"flex items-center gap-1 bg-amber-50 border-2 border-amber-300 rounded-lg shadow-lg",children:[e.jsxs("button",{onClick:()=>{de("build"),ve(!0)},className:"flex items-center gap-2 px-4 py-2 cursor-pointer hover:bg-amber-100 transition-colors rounded-l-md",children:[e.jsx("span",{className:"inline-block w-2 h-2 rounded-full bg-amber-400 animate-pulse"}),e.jsx("span",{className:"text-sm font-medium text-amber-900",children:"Claude is waiting for you"}),e.jsx("span",{className:"text-xs text-amber-600 ml-1",children:"Go to Build"})]}),e.jsx("button",{onClick:d=>{d.stopPropagation(),Tt(!0)},className:"px-2 py-2 cursor-pointer hover:bg-amber-100 transition-colors rounded-r-md text-amber-400 hover:text-amber-600","aria-label":"Dismiss",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:e.jsx("path",{d:"M3 3l8 8M11 3l-8 8"})})})]})]}),Fs&&e.jsxs("div",{className:"absolute inset-0 flex flex-col overflow-hidden",style:{visibility:ne==="build"?"visible":"hidden"},children:[e.jsx(On,{projectTitle:f,featureName:h,editorStep:O,editorStepLabel:J,migrationMode:k}),e.jsx("div",{className:"flex-1 min-h-0",style:ot?{flex:"1 1 50%"}:void 0,children:ze==="pending"?e.jsx(Tn,{featureName:h,editorStep:O,editorStepLabel:J,onContinue:Ls}):e.jsx(Sn,{ref:W,entityName:"Editor",projectSlug:s,entityFilePath:null,scenarioName:null,onRefreshPreview:Ys,onShowResults:zs,onHideResults:Ot,onSetViewport:Us,onDataMutationForwarded:Gs,editorMode:!0,onIdleChange:Is,onBuildingChange:Rs,notificationSettings:_t,buildTabActive:ne==="build",claudeStartMode:ze==="continue"?"resume":"fresh",claudeSessionId:Z,editorStepLabel:J,resultsOpen:ot})}),ot&&e.jsx("div",{style:{flex:"1 1 50%"},className:"min-h-0 border-t-2 border-gray-300",children:e.jsx(qn,{scenarios:c,allScenarios:i,glossaryFunctions:x,projectRoot:n,activeScenarioId:U,onScenarioSelect:Ee,onClose:Ot,entityChangeStatus:p,modifiedFiles:R,featureName:h,userPrompt:N})})]}),e.jsx("div",{className:"absolute inset-0 flex flex-col overflow-hidden",style:{visibility:ne==="app"?"visible":"hidden"},children:e.jsx(pr,{hasProject:a,scenarios:i,analyzedEntities:l,allEntities:o,glossaryFunctions:x,glossaryEntries:S,projectRoot:n,activeScenarioId:U,onScenarioSelect:Ee,onAnalyzedScenarioSelect:tt,onSwitchToBuild:st,zoomComponent:T,focusedEntity:D,onZoomChange:qt,entityImports:g,pageFilePaths:m,projectTitle:f,projectDescription:y,breadcrumbItems:Vt,migrationMode:k,migrationState:F,onStartMigration:Es,onReseedPreview:en})}),e.jsx("div",{className:"absolute inset-0 flex flex-col overflow-hidden",style:{visibility:ne==="data"?"visible":"hidden"},children:Gt?e.jsx(ks,{focusedEntity:Gt,breadcrumbItems:Yt,onZoomChange:ft,projectRoot:n,scenarios:i,analyzedEntities:[],activeScenarioId:U,onScenarioSelect:Ee,onAnalyzedScenarioSelect:tt,onSwitchToBuild:st,entityImports:g,glossaryFunctions:x,glossaryEntries:S,entityShaMap:Je,componentGroups:mt,visualEntities:[],isEntityComplete:()=>!0}):e.jsx(_n,{scenarios:i,projectRoot:n,activeScenarioId:U,onScenarioSelect:Ee,zoomComponent:void 0,focusedEntity:null,onZoomChange:ft,analyzedEntities:[],glossaryFunctions:x,activeAnalyzedScenarioId:re==null?void 0:re.scenarioId,onAnalyzedScenarioSelect:tt,entityImports:g,pageFilePaths:m,onSwitchToBuild:st,entityShaMap:Je,structureTab:Qs,onStructureTabChange:Zs})}),e.jsx("div",{className:"absolute inset-0 flex flex-col overflow-hidden",style:{visibility:ne==="history"?"visible":"hidden"},children:e.jsx(hr,{isActive:ne==="history",onScreenshotClick:tn,glossaryFunctions:x})}),e.jsx("div",{className:"absolute inset-0 flex flex-col overflow-hidden",style:{visibility:ne==="settings"?"visible":"hidden"},children:e.jsxs("div",{className:"flex-1 overflow-auto p-4",children:[e.jsx("h2",{className:"text-sm font-semibold text-white mb-4",children:"Settings"}),e.jsx("p",{className:"text-xs text-gray-400",children:"Settings panel coming soon."})]})})]}),e.jsx(kn,{serverUrl:K,isStarting:ue,projectSlug:s,devServerError:xe,onStartServer:he?We:void 0,notificationSettings:_t,onChangeNotificationSettings:Hs})]}),!fe&&!it&&e.jsx(br,{onMouseDown:Os,onDoubleClick:_s,isDragging:It}),it&&e.jsx("div",{className:"shrink-0 flex items-center justify-center cursor-pointer hover:bg-[#3d3d3d] transition-colors",style:{width:8,backgroundColor:"#2d2d2d"},onClick:Ws,title:"Expand preview",children:e.jsx("svg",{width:"6",height:"10",viewBox:"0 0 6 10",fill:"none",stroke:"#888",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M5 1l-4 4 4 4"})})}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0",style:{...it?{display:"none"}:void 0,...It?{pointerEvents:"none"}:void 0},children:[e.jsxs("div",{className:"bg-[#2d2d2d] border-b border-[#3d3d3d] shrink-0 z-10 h-10 flex items-center pr-4 relative",children:[e.jsx("div",{className:"flex items-center gap-1 shrink-0 z-10",children:e.jsx("button",{onClick:()=>{fe?($t(),setTimeout(()=>{var d;return(d=W.current)==null?void 0:d.focus()},50)):Bs()},className:`p-1.5 rounded transition-colors cursor-pointer ${fe?"text-white bg-[#666] hover:bg-[#777]":"text-gray-500 hover:text-gray-300"}`,title:fe?"Show chat":"Hide chat",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:fe?e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M13 17l5-5-5-5"}),e.jsx("path",{d:"M6 17l5-5-5-5"})]}):e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M11 17l-5-5 5-5"}),e.jsx("path",{d:"M18 17l-5-5 5-5"})]})})})}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center gap-1 pointer-events-none",children:e.jsxs("div",{className:"flex items-center gap-1 pointer-events-auto",children:[Xe.map(d=>e.jsxs("button",{onClick:()=>{oe&&Pt(!1),sn(d)},className:`p-1.5 rounded transition-colors cursor-pointer ${!oe&&ie.name===d.name?"text-white bg-[#555]":"text-gray-500 hover:text-gray-300"}`,title:`${d.name} (${d.width}×${d.height})`,children:[d.name==="Desktop"&&e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),e.jsx("path",{d:"M8 21h8M12 17v4"})]}),d.name==="Laptop"&&e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M4 6a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v8H4V6z"}),e.jsx("path",{d:"M2 18h20"})]}),d.name==="Tablet"&&e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"5",y:"2",width:"14",height:"20",rx:"2"}),e.jsx("path",{d:"M12 18h.01"})]}),d.name==="Mobile"&&e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"7",y:"2",width:"10",height:"20",rx:"2"}),e.jsx("path",{d:"M12 18h.01"})]})]},d.name)),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{onClick:()=>{oe||Ct(d=>!d)},className:`flex items-center gap-1.5 px-2 py-1 rounded transition-colors ${oe?"":"cursor-pointer"} ${oe||kt||!Xe.some(d=>d.name===ie.name)?"text-white bg-[#555]":"text-gray-400 hover:text-gray-200 hover:bg-[#444]"}`,title:"Custom dimensions",children:[e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M17 3a2.83 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})}),e.jsx("span",{className:"text-xs font-mono",children:oe&&Ne?`${Math.round(Ne.width)} × ${Math.round(Ne.height)}`:`${ie.width} × ${ie.height??900}`})]}),kt&&e.jsx(fn,{currentWidth:ie.width,currentHeight:ie.height??900,devicePresets:xt,customSizes:dt,onApply:rn,onSave:nn,onRemove:Xs,onClose:()=>Ct(!1)})]}),e.jsx("button",{onClick:()=>{Pt(d=>!d)},className:`p-1.5 rounded transition-colors cursor-pointer ${oe?"text-white bg-[#555]":"text-gray-500 hover:text-gray-300"}`,title:oe?"Exit fullscreen":"Fill page with preview",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:oe?e.jsxs(e.Fragment,{children:[e.jsx("polyline",{points:"4 14 10 14 10 20"}),e.jsx("polyline",{points:"20 10 14 10 14 4"}),e.jsx("line",{x1:"14",y1:"10",x2:"21",y2:"3"}),e.jsx("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]}):e.jsxs(e.Fragment,{children:[e.jsx("polyline",{points:"15 3 21 3 21 9"}),e.jsx("polyline",{points:"9 21 3 21 3 15"}),e.jsx("line",{x1:"21",y1:"3",x2:"14",y2:"10"}),e.jsx("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]})})}),e.jsx("button",{onClick:()=>{const d=gt||Fe;d&&window.open(d,"_blank")},className:"p-1.5 rounded text-gray-500 hover:text-gray-300 transition-colors cursor-pointer",title:"Open preview in new window",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),e.jsx("polyline",{points:"15 3 21 3 21 9"}),e.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})})]})})]}),Js&&e.jsx(Sr,{onSaveToCurrent:()=>void Ut("overwrite"),onSaveAsNew:()=>void Ut("new"),onDismiss:()=>Ce(!1),isSaving:Ks,scenarioName:(es=i.find(d=>{var b;return d.id===(U||((b=Ke(i))==null?void 0:b.id))}))==null?void 0:es.name}),e.jsx("div",{ref:v,className:`flex-1 flex overflow-hidden ${oe?"":"items-center justify-center p-8"}`,style:oe?{backgroundColor:"#fff"}:Ze?{backgroundColor:"#f5f0e8",backgroundImage:"repeating-linear-gradient(0deg, transparent, transparent 19px, #e8e0d0 19px, #e8e0d0 20px), repeating-linear-gradient(90deg, transparent, transparent 19px, #e8e0d0 19px, #e8e0d0 20px)"}:et?{backgroundColor:"#1e1e1e"}:{backgroundImage:`
91
+ `}),e.jsxs("div",{className:"flex items-center gap-1 bg-amber-50 border-2 border-amber-300 rounded-lg shadow-lg",children:[e.jsxs("button",{onClick:()=>{de("build"),ve(!0)},className:"flex items-center gap-2 px-4 py-2 cursor-pointer hover:bg-amber-100 transition-colors rounded-l-md",children:[e.jsx("span",{className:"inline-block w-2 h-2 rounded-full bg-amber-400 animate-pulse"}),e.jsx("span",{className:"text-sm font-medium text-amber-900",children:"Claude is waiting for you"}),e.jsx("span",{className:"text-xs text-amber-600 ml-1",children:"Go to Build"})]}),e.jsx("button",{onClick:d=>{d.stopPropagation(),Lt(!0)},className:"px-2 py-2 cursor-pointer hover:bg-amber-100 transition-colors rounded-r-md text-amber-400 hover:text-amber-600","aria-label":"Dismiss",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:e.jsx("path",{d:"M3 3l8 8M11 3l-8 8"})})})]})]}),Ds&&e.jsxs("div",{className:"absolute inset-0 flex flex-col overflow-hidden",style:{visibility:ne==="build"?"visible":"hidden"},children:[e.jsx(Or,{projectTitle:f,featureName:h,editorStep:O,editorStepLabel:J,migrationMode:k}),e.jsx("div",{className:"flex-1 min-h-0",style:lt?{flex:"1 1 50%"}:void 0,children:ze==="pending"?e.jsx(Tr,{featureName:h,editorStep:O,editorStepLabel:J,onContinue:Ms}):e.jsx(Sr,{ref:W,entityName:"Editor",projectSlug:s,entityFilePath:null,scenarioName:null,onRefreshPreview:qs,onShowResults:Us,onHideResults:_t,onSetViewport:Hs,onDataMutationForwarded:Ys,editorMode:!0,onIdleChange:$s,onBuildingChange:Os,notificationSettings:Bt,buildTabActive:ne==="build",claudeStartMode:ze==="continue"?"resume":"fresh",claudeSessionId:Z,editorStepLabel:J,resultsOpen:lt})}),lt&&e.jsx("div",{style:{flex:"1 1 50%"},className:"min-h-0 border-t-2 border-gray-300",children:e.jsx(qr,{scenarios:c,allScenarios:i,glossaryFunctions:x,projectRoot:r,activeScenarioId:U,onScenarioSelect:Ee,onClose:_t,entityChangeStatus:p,modifiedFiles:R,featureName:h,userPrompt:N})})]}),e.jsx("div",{className:"absolute inset-0 flex flex-col overflow-hidden",style:{visibility:ne==="app"?"visible":"hidden"},children:e.jsx(fn,{hasProject:a,scenarios:i,analyzedEntities:l,allEntities:o,glossaryFunctions:x,glossaryEntries:S,projectRoot:r,activeScenarioId:U,onScenarioSelect:Ee,onAnalyzedScenarioSelect:st,onSwitchToBuild:rt,zoomComponent:T,focusedEntity:D,onZoomChange:Xt,entityImports:b,pageFilePaths:m,projectTitle:f,projectDescription:y,breadcrumbItems:Jt,migrationMode:k,migrationState:F,onStartMigration:Fs,onReseedPreview:tr})}),e.jsx("div",{className:"absolute inset-0 flex flex-col overflow-hidden",style:{visibility:ne==="data"?"visible":"hidden"},children:Yt?e.jsx(Cs,{focusedEntity:Yt,breadcrumbItems:qt,onZoomChange:gt,projectRoot:r,scenarios:i,analyzedEntities:[],activeScenarioId:U,onScenarioSelect:Ee,onAnalyzedScenarioSelect:st,onSwitchToBuild:rt,entityImports:b,glossaryFunctions:x,glossaryEntries:S,entityShaMap:Ke,componentGroups:ht,visualEntities:[],isEntityComplete:()=>!0}):e.jsx(_r,{scenarios:i,projectRoot:r,activeScenarioId:U,onScenarioSelect:Ee,zoomComponent:void 0,focusedEntity:null,onZoomChange:gt,analyzedEntities:[],glossaryFunctions:x,activeAnalyzedScenarioId:se==null?void 0:se.scenarioId,onAnalyzedScenarioSelect:st,entityImports:b,pageFilePaths:m,onSwitchToBuild:rt,entityShaMap:Ke,structureTab:Zs,onStructureTabChange:er})}),e.jsx("div",{className:"absolute inset-0 flex flex-col overflow-hidden",style:{visibility:ne==="history"?"visible":"hidden"},children:e.jsx(pn,{isActive:ne==="history",onScreenshotClick:sr,glossaryFunctions:x})}),e.jsx("div",{className:"absolute inset-0 flex flex-col overflow-hidden",style:{visibility:ne==="settings"?"visible":"hidden"},children:e.jsxs("div",{className:"flex-1 overflow-auto p-4",children:[e.jsx("h2",{className:"text-sm font-semibold text-white mb-4",children:"Settings"}),e.jsx("p",{className:"text-xs text-gray-400",children:"Settings panel coming soon."})]})})]}),e.jsx(kr,{serverUrl:K,isStarting:ue,projectSlug:s,devServerError:xe,onStartServer:pe?We:void 0,notificationSettings:Bt,onChangeNotificationSettings:Vs})]}),!ge&&!ot&&e.jsx(yn,{onMouseDown:_s,onDoubleClick:Bs,isDragging:$t}),ot&&e.jsx("div",{className:"shrink-0 flex items-center justify-center cursor-pointer hover:bg-[#3d3d3d] transition-colors",style:{width:8,backgroundColor:"#2d2d2d"},onClick:zs,title:"Expand preview",children:e.jsx("svg",{width:"6",height:"10",viewBox:"0 0 6 10",fill:"none",stroke:"#888",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M5 1l-4 4 4 4"})})}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0",style:{...ot?{display:"none"}:void 0,...$t?{pointerEvents:"none"}:void 0},children:[e.jsxs("div",{className:"bg-[#2d2d2d] border-b border-[#3d3d3d] shrink-0 z-10 h-10 flex items-center pr-4 relative",children:[e.jsx("div",{className:"flex items-center gap-1 shrink-0 z-10",children:e.jsx("button",{onClick:()=>{ge?(Rt(),setTimeout(()=>{var d;return(d=W.current)==null?void 0:d.focus()},50)):Ws()},className:`p-1.5 rounded transition-colors cursor-pointer ${ge?"text-white bg-[#666] hover:bg-[#777]":"text-gray-500 hover:text-gray-300"}`,title:ge?"Show chat":"Hide chat",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:ge?e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M13 17l5-5-5-5"}),e.jsx("path",{d:"M6 17l5-5-5-5"})]}):e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M11 17l-5-5 5-5"}),e.jsx("path",{d:"M18 17l-5-5 5-5"})]})})})}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center gap-1 pointer-events-none",children:e.jsxs("div",{className:"flex items-center gap-1 pointer-events-auto",children:[Qe.map(d=>e.jsxs("button",{onClick:()=>{le&&Et(!1),rr(d)},className:`p-1.5 rounded transition-colors cursor-pointer ${!le&&oe.name===d.name?"text-white bg-[#555]":"text-gray-500 hover:text-gray-300"}`,title:`${d.name} (${d.width}×${d.height})`,children:[d.name==="Desktop"&&e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),e.jsx("path",{d:"M8 21h8M12 17v4"})]}),d.name==="Laptop"&&e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M4 6a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v8H4V6z"}),e.jsx("path",{d:"M2 18h20"})]}),d.name==="Tablet"&&e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"5",y:"2",width:"14",height:"20",rx:"2"}),e.jsx("path",{d:"M12 18h.01"})]}),d.name==="Mobile"&&e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"7",y:"2",width:"10",height:"20",rx:"2"}),e.jsx("path",{d:"M12 18h.01"})]})]},d.name)),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{onClick:()=>{le||Pt(d=>!d)},className:`flex items-center gap-1.5 px-2 py-1 rounded transition-colors ${le?"":"cursor-pointer"} ${le||Ct||!Qe.some(d=>d.name===oe.name)?"text-white bg-[#555]":"text-gray-400 hover:text-gray-200 hover:bg-[#444]"}`,title:"Custom dimensions",children:[e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M17 3a2.83 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})}),e.jsx("span",{className:"text-xs font-mono",children:le&&Ne?`${Math.round(Ne.width)} × ${Math.round(Ne.height)}`:`${oe.width} × ${oe.height??900}`})]}),Ct&&e.jsx(fr,{currentWidth:oe.width,currentHeight:oe.height??900,devicePresets:ut,customSizes:xt,onApply:ar,onSave:nr,onRemove:Qs,onClose:()=>Pt(!1)})]}),e.jsx("button",{onClick:()=>{Et(d=>!d)},className:`p-1.5 rounded transition-colors cursor-pointer ${le?"text-white bg-[#555]":"text-gray-500 hover:text-gray-300"}`,title:le?"Exit fullscreen":"Fill page with preview",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:le?e.jsxs(e.Fragment,{children:[e.jsx("polyline",{points:"4 14 10 14 10 20"}),e.jsx("polyline",{points:"20 10 14 10 14 4"}),e.jsx("line",{x1:"14",y1:"10",x2:"21",y2:"3"}),e.jsx("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]}):e.jsxs(e.Fragment,{children:[e.jsx("polyline",{points:"15 3 21 3 21 9"}),e.jsx("polyline",{points:"9 21 3 21 3 15"}),e.jsx("line",{x1:"21",y1:"3",x2:"14",y2:"10"}),e.jsx("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]})})}),e.jsx("button",{onClick:()=>{const d=bt||Fe;d&&window.open(d,"_blank")},className:"p-1.5 rounded text-gray-500 hover:text-gray-300 transition-colors cursor-pointer",title:"Open preview in new window",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),e.jsx("polyline",{points:"15 3 21 3 21 9"}),e.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})})]})})]}),Ks&&e.jsx(kn,{onSaveToCurrent:()=>void Ht("overwrite"),onSaveAsNew:()=>void Ht("new"),onDismiss:()=>Ce(!1),isSaving:Gs,scenarioName:(ts=i.find(d=>{var g;return d.id===(U||((g=Ge(i))==null?void 0:g.id))}))==null?void 0:ts.name}),e.jsx("div",{ref:v,className:`flex-1 flex overflow-hidden ${le?"":"items-center justify-center p-8"}`,style:le?{backgroundColor:"#fff"}:et?{backgroundColor:"#f5f0e8",backgroundImage:"repeating-linear-gradient(0deg, transparent, transparent 19px, #e8e0d0 19px, #e8e0d0 20px), repeating-linear-gradient(90deg, transparent, transparent 19px, #e8e0d0 19px, #e8e0d0 20px)"}:tt?{backgroundColor:"#1e1e1e"}:{backgroundImage:`
92
92
  linear-gradient(45deg, #333 25%, transparent 25%),
93
93
  linear-gradient(-45deg, #333 25%, transparent 25%),
94
94
  linear-gradient(45deg, transparent 75%, #333 75%),
95
95
  linear-gradient(-45deg, transparent 75%, #333 75%)
96
- `,backgroundSize:"16px 16px",backgroundPosition:"0 0, 0 8px, 8px -8px, -8px 0px",backgroundColor:"#2d2d2d"},children:Ze?e.jsx(jr,{preview:Ze,onDismiss:()=>pe(null),onLoadCommit:Cs}):et?e.jsx(Nr,{preview:et,onDismiss:()=>ye(null)}):Fe?oe?e.jsxs("div",{className:"relative w-full h-full bg-white",children:[!be&&!He&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center z-10",children:e.jsxs("div",{className:"flex flex-col items-center justify-center gap-6 bg-[#2a2a2a] rounded-lg p-8 w-[500px] h-[300px]",children:[e.jsx("div",{className:"mb-4",children:e.jsx(yt,{})}),e.jsxs("div",{className:"flex flex-col gap-3 text-center",children:[e.jsx("h2",{className:"text-xl font-medium text-gray-200 leading-[28px] m-0 font-['IBM_Plex_Sans']",children:"Loading Preview"}),e.jsx("p",{className:"text-sm text-gray-400 leading-5 m-0 font-['IBM_Plex_Sans']",children:"Waiting for the app to render"})]})]})}),He&&e.jsx("div",{className:"absolute inset-0 z-20 flex items-center justify-center",style:{backgroundColor:"rgba(0, 0, 0, 0.25)",backdropFilter:"blur(1px)",transition:"opacity 200ms ease-out"},children:e.jsxs("div",{className:"flex flex-col items-center gap-3 animate-pulse",children:[e.jsx("svg",{className:"w-6 h-6 text-white/80 animate-spin",viewBox:"0 0 24 24",fill:"none",children:e.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeDasharray:"50 100"})}),e.jsx("span",{className:"text-white/70 text-xs font-['IBM_Plex_Sans']",children:"Switching scenario"})]})}),e.jsx("iframe",{ref:le,src:gt||Fe,className:"w-full h-full border-none",title:"Editor preview",onLoad:Qt,style:{opacity:be?1:0}},Se)]}):e.jsx("div",{style:{width:`${ie.width*we}px`,height:`${(ie.height??900)*we}px`},children:e.jsxs("div",{className:"relative bg-white origin-top-left",style:{width:`${ie.width}px`,height:`${ie.height??900}px`,transform:we<1?`scale(${we})`:void 0},children:[!be&&!He&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center z-10",children:e.jsxs("div",{className:"flex flex-col items-center justify-center gap-6 bg-[#2a2a2a] rounded-lg p-8 w-[500px] h-[300px]",children:[e.jsx("div",{className:"mb-4",children:e.jsx(yt,{})}),e.jsxs("div",{className:"flex flex-col gap-3 text-center",children:[e.jsx("h2",{className:"text-xl font-medium text-gray-200 leading-[28px] m-0 font-['IBM_Plex_Sans']",children:"Loading Preview"}),e.jsx("p",{className:"text-sm text-gray-400 leading-5 m-0 font-['IBM_Plex_Sans']",children:"Waiting for the app to render"})]})]})}),He&&e.jsx("div",{className:"absolute inset-0 z-20 flex items-center justify-center",style:{backgroundColor:"rgba(0, 0, 0, 0.25)",backdropFilter:"blur(1px)",transition:"opacity 200ms ease-out"},children:e.jsxs("div",{className:"flex flex-col items-center gap-3 animate-pulse",children:[e.jsx("svg",{className:"w-6 h-6 text-white/80 animate-spin",viewBox:"0 0 24 24",fill:"none",children:e.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeDasharray:"50 100"})}),e.jsx("span",{className:"text-white/70 text-xs font-['IBM_Plex_Sans']",children:"Switching scenario"})]})}),e.jsx("iframe",{ref:le,src:gt||Fe,className:"w-full h-full border-none",title:"Editor preview",onLoad:Qt,style:{opacity:be?1:0}},Se)]})}):e.jsx("div",{className:"bg-[#2a2a2a] rounded-lg flex flex-col items-center justify-center",style:{width:`${ie.width*we}px`,height:`${(ie.height??900)*we}px`},children:xe?e.jsxs("div",{className:"flex flex-col gap-4 text-center px-8 max-w-[600px]",children:[e.jsx("h2",{className:"text-xl font-medium text-red-400 leading-[28px] m-0 font-['IBM_Plex_Sans']",children:"Dev Server Failed"}),e.jsx("pre",{className:"text-xs text-left bg-[#1e1e1e] text-gray-300 p-4 rounded overflow-auto max-h-[300px] w-full font-mono whitespace-pre-wrap",children:xe}),e.jsx("button",{onClick:Be,className:"mx-auto px-4 py-2 bg-[#005c75] text-white text-sm font-medium rounded hover:bg-[#004d63] transition-colors cursor-pointer",children:"Retry"})]}):ue||se?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mb-4",children:e.jsx(yt,{})}),e.jsxs("div",{className:"flex flex-col gap-3 text-center",children:[e.jsx("h2",{className:"text-xl font-medium text-gray-200 leading-[28px] m-0 font-['IBM_Plex_Sans']",children:se?"Starting Interactive Mode":"Starting Dev Server"}),e.jsx("p",{className:"text-sm text-gray-400 leading-5 m-0 font-['IBM_Plex_Sans']",children:se?"Loading component preview...":"Your dev server is starting up..."})]})]}):e.jsxs("div",{className:"flex flex-col gap-3 text-center px-8",children:[e.jsx("h2",{className:"text-xl font-medium text-gray-200 leading-[28px] m-0 font-['IBM_Plex_Sans']",children:"Live Preview"}),e.jsx("p",{className:"text-sm text-gray-500 leading-5 m-0 font-['IBM_Plex_Sans']",children:"Describe what you want to build in the Build tab"})]})})})]})]})]})}),e.jsx(hn,{})]})});export{Hr as default,Ur as meta,zr as shouldRevalidate};
96
+ `,backgroundSize:"16px 16px",backgroundPosition:"0 0, 0 8px, 8px -8px, -8px 0px",backgroundColor:"#2d2d2d"},children:et?e.jsx(vn,{preview:et,onDismiss:()=>fe(null),onLoadCommit:Ps}):tt?e.jsx(wn,{preview:tt,onDismiss:()=>ye(null)}):Fe?le?e.jsxs("div",{className:"relative w-full h-full bg-white",children:[!be&&!He&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center z-10",children:e.jsxs("div",{className:"flex flex-col items-center justify-center gap-6 bg-[#2a2a2a] rounded-lg p-8 w-[500px] h-[300px]",children:[e.jsx("div",{className:"mb-4",children:e.jsx(jt,{})}),e.jsxs("div",{className:"flex flex-col gap-3 text-center",children:[e.jsx("h2",{className:"text-xl font-medium text-gray-200 leading-[28px] m-0 font-['IBM_Plex_Sans']",children:"Loading Preview"}),e.jsx("p",{className:"text-sm text-gray-400 leading-5 m-0 font-['IBM_Plex_Sans']",children:"Waiting for the app to render"})]})]})}),He&&e.jsx("div",{className:"absolute inset-0 z-20 flex items-center justify-center",style:{backgroundColor:"rgba(0, 0, 0, 0.25)",backdropFilter:"blur(1px)",transition:"opacity 200ms ease-out"},children:e.jsxs("div",{className:"flex flex-col items-center gap-3 animate-pulse",children:[e.jsx("svg",{className:"w-6 h-6 text-white/80 animate-spin",viewBox:"0 0 24 24",fill:"none",children:e.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeDasharray:"50 100"})}),e.jsx("span",{className:"text-white/70 text-xs font-['IBM_Plex_Sans']",children:"Switching scenario"})]})}),e.jsx("iframe",{ref:ce,src:bt||Fe,className:"w-full h-full border-none",title:"Editor preview",onLoad:Zt,style:{opacity:be?1:0}},Se)]}):e.jsx("div",{style:{width:`${oe.width*we}px`,height:`${(oe.height??900)*we}px`},children:e.jsxs("div",{className:"relative bg-white origin-top-left",style:{width:`${oe.width}px`,height:`${oe.height??900}px`,transform:we<1?`scale(${we})`:void 0},children:[!be&&!He&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center z-10",children:e.jsxs("div",{className:"flex flex-col items-center justify-center gap-6 bg-[#2a2a2a] rounded-lg p-8 w-[500px] h-[300px]",children:[e.jsx("div",{className:"mb-4",children:e.jsx(jt,{})}),e.jsxs("div",{className:"flex flex-col gap-3 text-center",children:[e.jsx("h2",{className:"text-xl font-medium text-gray-200 leading-[28px] m-0 font-['IBM_Plex_Sans']",children:"Loading Preview"}),e.jsx("p",{className:"text-sm text-gray-400 leading-5 m-0 font-['IBM_Plex_Sans']",children:"Waiting for the app to render"})]})]})}),He&&e.jsx("div",{className:"absolute inset-0 z-20 flex items-center justify-center",style:{backgroundColor:"rgba(0, 0, 0, 0.25)",backdropFilter:"blur(1px)",transition:"opacity 200ms ease-out"},children:e.jsxs("div",{className:"flex flex-col items-center gap-3 animate-pulse",children:[e.jsx("svg",{className:"w-6 h-6 text-white/80 animate-spin",viewBox:"0 0 24 24",fill:"none",children:e.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeDasharray:"50 100"})}),e.jsx("span",{className:"text-white/70 text-xs font-['IBM_Plex_Sans']",children:"Switching scenario"})]})}),e.jsx("iframe",{ref:ce,src:bt||Fe,className:"w-full h-full border-none",title:"Editor preview",onLoad:Zt,style:{opacity:be?1:0}},Se)]})}):e.jsx("div",{className:"bg-[#2a2a2a] rounded-lg flex flex-col items-center justify-center",style:{width:`${oe.width*we}px`,height:`${(oe.height??900)*we}px`},children:xe?e.jsxs("div",{className:"flex flex-col gap-4 text-center px-8 max-w-[600px]",children:[e.jsx("h2",{className:"text-xl font-medium text-red-400 leading-[28px] m-0 font-['IBM_Plex_Sans']",children:"Dev Server Failed"}),e.jsx("pre",{className:"text-xs text-left bg-[#1e1e1e] text-gray-300 p-4 rounded overflow-auto max-h-[300px] w-full font-mono whitespace-pre-wrap",children:xe}),e.jsx("button",{onClick:Be,className:"mx-auto px-4 py-2 bg-[#005c75] text-white text-sm font-medium rounded hover:bg-[#004d63] transition-colors cursor-pointer",children:"Retry"})]}):ue||re?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mb-4",children:e.jsx(jt,{})}),e.jsxs("div",{className:"flex flex-col gap-3 text-center",children:[e.jsx("h2",{className:"text-xl font-medium text-gray-200 leading-[28px] m-0 font-['IBM_Plex_Sans']",children:re?"Starting Interactive Mode":"Starting Dev Server"}),e.jsx("p",{className:"text-sm text-gray-400 leading-5 m-0 font-['IBM_Plex_Sans']",children:re?"Loading component preview...":"Your dev server is starting up..."})]})]}):e.jsxs("div",{className:"flex flex-col gap-3 text-center px-8",children:[e.jsx("h2",{className:"text-xl font-medium text-gray-200 leading-[28px] m-0 font-['IBM_Plex_Sans']",children:"Live Preview"}),e.jsx("p",{className:"text-sm text-gray-500 leading-5 m-0 font-['IBM_Plex_Sans']",children:"Describe what you want to build in the Build tab"})]})})})]})]})]})}),e.jsx(hr,{})]})});export{Vn as default,Hn as meta,Un as shouldRevalidate};