@codeyam/codeyam-cli 0.1.17 → 0.1.19

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 (54) hide show
  1. package/analyzer-template/.build-info.json +6 -6
  2. package/analyzer-template/log.txt +3 -3
  3. package/codeyam-cli/src/cli.js +15 -0
  4. package/codeyam-cli/src/cli.js.map +1 -1
  5. package/codeyam-cli/src/commands/__tests__/editor.stepDispatch.test.js +9 -9
  6. package/codeyam-cli/src/commands/editor.js +455 -257
  7. package/codeyam-cli/src/commands/editor.js.map +1 -1
  8. package/codeyam-cli/src/utils/__tests__/editorAudit.test.js +160 -0
  9. package/codeyam-cli/src/utils/__tests__/editorAudit.test.js.map +1 -1
  10. package/codeyam-cli/src/utils/__tests__/editorEntityHelpers.test.js +66 -0
  11. package/codeyam-cli/src/utils/__tests__/editorEntityHelpers.test.js.map +1 -1
  12. package/codeyam-cli/src/utils/__tests__/editorGuardMiddleware.test.js +67 -0
  13. package/codeyam-cli/src/utils/__tests__/editorGuardMiddleware.test.js.map +1 -0
  14. package/codeyam-cli/src/utils/__tests__/entityChangeStatus.test.js +213 -0
  15. package/codeyam-cli/src/utils/__tests__/entityChangeStatus.test.js.map +1 -1
  16. package/codeyam-cli/src/utils/__tests__/journalCaptureStabilization.test.js +16 -1
  17. package/codeyam-cli/src/utils/__tests__/journalCaptureStabilization.test.js.map +1 -1
  18. package/codeyam-cli/src/utils/editorAudit.js +44 -14
  19. package/codeyam-cli/src/utils/editorAudit.js.map +1 -1
  20. package/codeyam-cli/src/utils/editorGuard.js +36 -0
  21. package/codeyam-cli/src/utils/editorGuard.js.map +1 -0
  22. package/codeyam-cli/src/utils/editorRecapture.js +109 -0
  23. package/codeyam-cli/src/utils/editorRecapture.js.map +1 -0
  24. package/codeyam-cli/src/utils/editorScenarios.js +1 -1
  25. package/codeyam-cli/src/utils/entityChangeStatus.js +30 -2
  26. package/codeyam-cli/src/utils/entityChangeStatus.js.map +1 -1
  27. package/codeyam-cli/src/utils/scenariosManifest.js +22 -0
  28. package/codeyam-cli/src/utils/scenariosManifest.js.map +1 -1
  29. package/codeyam-cli/src/utils/simulationGateMiddleware.js +9 -0
  30. package/codeyam-cli/src/utils/simulationGateMiddleware.js.map +1 -1
  31. package/codeyam-cli/src/webserver/__tests__/idleDetector.test.js +17 -6
  32. package/codeyam-cli/src/webserver/__tests__/idleDetector.test.js.map +1 -1
  33. package/codeyam-cli/src/webserver/__tests__/stripClaudeCommand.test.js +79 -0
  34. package/codeyam-cli/src/webserver/__tests__/stripClaudeCommand.test.js.map +1 -0
  35. package/codeyam-cli/src/webserver/build/client/assets/api.editor-recapture-stale-l0sNRNKZ.js +1 -0
  36. package/codeyam-cli/src/webserver/build/client/assets/{editor.entity.(_sha)-Bnx7yUP0.js → editor.entity.(_sha)-CGzKlIHg.js} +13 -13
  37. package/codeyam-cli/src/webserver/build/client/assets/globals-Yn9W3zp3.css +1 -0
  38. package/codeyam-cli/src/webserver/build/client/assets/manifest-2ef99f38.js +1 -0
  39. package/codeyam-cli/src/webserver/build/client/assets/{root-DB3O9_9j.js → root-BxUQigda.js} +5 -5
  40. package/codeyam-cli/src/webserver/build/server/assets/{analysisRunner-BMmkgAkg.js → analysisRunner-BPmOG9bE.js} +1 -1
  41. package/codeyam-cli/src/webserver/build/server/assets/{index-DxB0pOSt.js → index-Cd-ufawF.js} +1 -1
  42. package/codeyam-cli/src/webserver/build/server/assets/{init-DLYLaqqP.js → init-CzeBGOto.js} +1 -1
  43. package/codeyam-cli/src/webserver/build/server/assets/{server-build-CcyitQLQ.js → server-build-Dht7CKXY.js} +114 -113
  44. package/codeyam-cli/src/webserver/build/server/index.js +1 -1
  45. package/codeyam-cli/src/webserver/build-info.json +5 -5
  46. package/codeyam-cli/src/webserver/terminalServer.js +85 -19
  47. package/codeyam-cli/src/webserver/terminalServer.js.map +1 -1
  48. package/codeyam-cli/templates/__tests__/editor-step-hook.prompt-capture.test.ts +118 -0
  49. package/codeyam-cli/templates/codeyam-editor-claude.md +2 -0
  50. package/codeyam-cli/templates/codeyam-editor-reference.md +1 -1
  51. package/codeyam-cli/templates/editor-step-hook.py +72 -46
  52. package/package.json +1 -1
  53. package/codeyam-cli/src/webserver/build/client/assets/globals-fAqOD9ex.css +0 -1
  54. package/codeyam-cli/src/webserver/build/client/assets/manifest-3157d6b8.js +0 -1
@@ -1,7 +1,7 @@
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 Is=Object.defineProperty;var Ts=(t,s,n)=>s in t?Is(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var At=(t,s,n)=>Ts(t,typeof s!="symbol"?s+"":s,n);import{r as a,w as $s,u as Rs,b as As,a as Ls,c as _s,O as Ds}from"./chunk-JZWAC4HX-BAdwhyCx.js";import{j as e}from"./jsx-runtime-D_zvdyIk.js";import{u as Fs,C as Bs}from"./useCustomSizes-DhXHbEjP.js";import{g as Lt,s as Os,r as st,b as nt,c as zs,l as Ws,d as Us,e as Hs,f as Js,a as Gs,T as Vs,D as qs}from"./editorPreview-oepecPae.js";import{C as ve}from"./CopyButton-CLe80MMu.js";import{_ as it}from"./preload-helper-ckwbz45p.js";import{c as Ys}from"./cy-logo-cli-DcX-ZS3p.js";import{u as Xs,S as at}from"./Spinner-D0LgAaSa.js";import"./copy-C6iF61Xs.js";import"./createLucideIcon-4ImjHTVC.js";import"./useLastLogLine-BNd5hYuW.js";function $e(t){var l;if(!t.startsWith("app/")&&!t.startsWith("("))return"/";const n=t.replace(/^app\//,"").split("/"),r=n.pop(),c=((l=r.match(/\.(tsx?|jsx?|js)$/))==null?void 0:l[0])||"",i=r.slice(0,-c.length);let o;return i==="page"||i==="index"?o=n:o=[...n,i],o=o.filter(m=>!m.startsWith("(")),o.length===0?"/":"/"+o.join("/")}function Re(t){return t==="/"?"Home":t.replace(/^\//,"").split("/").map(n=>n.startsWith("[")?n:n.charAt(0).toUpperCase()+n.slice(1)).join(" / ")}function We(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 Xt(t){return t?t.includes("/isolated-components")||t.includes("/codeyam-isolate"):!1}function Ks(t,s){return!s||Object.keys(s).length===0?t:t.filter(n=>s[n.name])}const ze=[{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 Qs(t){if(!t)return ze;const s=Object.entries(t).map(([r,c])=>({name:r,width:c.width,height:c.height})),n=new Set(s.map(r=>r.name));return[...s,...ze.filter(r=>!n.has(r.name))]}function Zs({featureName:t,editorStep:s,editorStepLabel:n,onContinue:r}){const c=a.useCallback(i=>{i.key==="Enter"&&(i.preventDefault(),r())},[r]);return a.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:r,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"})]})})}function lt(t){const[s,n]=a.useState(null),[r,c]=a.useState(!1),i=a.useCallback(()=>{t&&(c(!0),fetch(`/api/editor-test-results?testFile=${encodeURIComponent(t)}`).then(o=>o.json()).then(o=>{n(o),c(!1)}).catch(()=>{n({testFilePath:t,status:"error",testCases:[],errorMessage:"Failed to fetch test results"}),c(!1)}))},[t]);return{results:s,isRunning:r,runTests:i}}function Ue({scenarioId:t,updatedAt:s,alt:n,className:r="",imgClassName:c=""}){const[i,o]=a.useState(!1),l=`/api/editor-scenario-image/${t}.png${s?`?v=${encodeURIComponent(s)}`:""}`;return a.useEffect(()=>{o(!1)},[t]),i?e.jsx("div",{className:`flex items-center justify-center ${r}`,children:e.jsx("span",{className:"text-[8px] text-gray-500",children:"No img"})}):e.jsx("div",{className:r,children:e.jsx("img",{src:l,alt:n,className:c,loading:"lazy",onError:()=>o(!0)})})}function Ie({scenarioId:t,updatedAt:s,hasScreenshot:n,imgSrc:r,name:c,isActive:i,onSelect:o}){const l=t&&n,m=!t&&r;return e.jsxs("button",{onClick:o,className:"flex flex-col items-center gap-1 cursor-pointer group",title:c,children:[e.jsx("div",{className:`w-32 h-32 rounded overflow-hidden border-2 transition-all bg-[#1a1a1a] ${i?"border-[#005c75] ring-1 ring-[#005c75]":"border-transparent hover:border-[#4d4d4d]"}`,children:l?e.jsx(Ue,{scenarioId:t,updatedAt:s,alt:c,className:"w-full h-full",imgClassName:"w-full h-full object-contain"}):m?e.jsx("img",{src:r,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-32 ${i?"text-white":"text-gray-500 group-hover:text-gray-300"}`,children:c})]})}function rt({testFile:t,entityName:s}){const{results:n,isRunning:r,runTests:c}=lt(t);if(r&&!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(m=>m.fullName.startsWith(s)):n.testCases,o=i.length>0?i:n.testCases;if(o.length===0)return null;const l=s?`${s} > `:"";return e.jsxs("div",{className:"px-2 pt-1 space-y-0.5",children:[o.map(m=>{var v;const S=l&&m.fullName.startsWith(l)?m.fullName.slice(l.length):m.fullName;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[m.status==="passed"?e.jsx("span",{className:"text-green-400 text-[10px]",children:"✓"}):m.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] ${m.status==="passed"?"text-green-400":m.status==="failed"?"text-red-400":"text-gray-500"}`,children:S})]}),m.status==="failed"&&((v=m.failureMessages)==null?void 0:v.map((C,j)=>e.jsx("div",{className:"pl-4 text-[9px] text-red-300/70 truncate max-w-full",title:C,children:C.split(`
3
- `)[0]},j)))]},m.fullName)}),e.jsx("button",{onClick:c,disabled:r,className:"mt-1 text-[10px] text-[#00a0c4] hover:text-[#00c4ee] transition-colors cursor-pointer disabled:opacity-50 bg-transparent border-none p-0",children:r?"Running...":"Re-run"})]})}function me({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(ve,{content:t,icon:!0,iconSize:10,className:"shrink-0 text-gray-500 hover:text-gray-300 transition-colors"})]}):null}function en({scenarios:t,projectRoot:s,activeScenarioId:n,onScenarioSelect:r,zoomComponent:c,focusedEntity:i,onZoomChange:o,analyzedEntities:l=[],glossaryFunctions:m=[],activeAnalyzedScenarioId:S,onAnalyzedScenarioSelect:v,entityImports:C,pageFilePaths:j={}}){const{pageGroups:T,componentGroups:h}=a.useMemo(()=>{var f;const x=new Map,y=new Map;for(const b of t)if(b.componentName){const E=y.get(b.componentName)||[];E.push(b),y.set(b.componentName,E)}else if(Xt(b.url)){const E=(f=b.url)==null?void 0:f.match(/[?&]c=([^&]+)/),L=E?decodeURIComponent(E[1]):"Isolated",F=y.get(L)||[];F.push(b),y.set(L,F)}else{const E=b.pageFilePath?Re($e(b.pageFilePath)):We(b.url),L=x.get(E)||[];L.push(b),x.set(E,L)}const p=new Map([...y.entries()].sort(([b],[E])=>b.localeCompare(E)));return{pageGroups:x,componentGroups:p}},[t]),B=a.useMemo(()=>{const x=new Set((l||[]).filter(p=>p.entityType==="visual").map(p=>p.name)),y=new Map;for(const[p,f]of h)x.has(p)||y.set(p,f);return y},[h,l]),{visualEntities:I,libraryEntities:_}=a.useMemo(()=>{const x=l.filter(p=>p.entityType==="visual").sort((p,f)=>p.name.localeCompare(f.name)),y=l.filter(p=>p.entityType==="library"||p.entityType==="functionCall").sort((p,f)=>p.name.localeCompare(f.name));return{visualEntities:x,libraryEntities:y}},[l]),D=a.useMemo(()=>{const x=new Set(_.map(y=>y.name));return m.filter(y=>!x.has(y.name)).sort((y,p)=>y.name.localeCompare(p.name))},[m,_]),$=l.some(x=>x.isAnalyzing),w=a.useRef(null),M=a.useRef(0),O=a.useCallback(()=>{w.current&&(M.current=w.current.scrollTop)},[]);if(a.useEffect(()=>{w.current&&M.current>0&&(w.current.scrollTop=M.current)}),t.length===0&&l.length===0&&D.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 x=i.name,y=i.filePath,p=i.sha,f=t.filter(N=>N.componentName===x||N.componentPath===y||!N.componentName&&(N.pageFilePath===y||p&&N.entitySha===p)),b=new Set((C==null?void 0:C[x])||[]),E=b.size>0,L=E?I.filter(N=>b.has(N.name)):[],F=E?_.filter(N=>b.has(N.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:()=>o(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:f.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-gray-500",children:"No scenarios for this component"}):f.map(N=>e.jsx(Ie,{scenarioId:N.id,updatedAt:N.updatedAt,hasScreenshot:!!N.screenshotPath,name:N.name,isActive:N.id===n,onSelect:()=>r(N)},N.id))}),L.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"})}),L.map(N=>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:()=>o(N.name),className:"text-[11px] font-medium text-gray-400 truncate cursor-pointer hover:text-white transition-colors bg-transparent border-none p-0",children:N.name})}),e.jsx(me,{filePath:N.filePath,projectRoot:s}),(N.scenarios.length>0||N.pendingScenarios.length>0)&&e.jsx("div",{className:"flex flex-wrap gap-2 px-2 pt-1",children:N.scenarios.map(J=>e.jsx(Ie,{imgSrc:J.screenshotPath?`/api/screenshot/${J.screenshotPath}`:null,name:J.name,isActive:J.id===S,onSelect:()=>v==null?void 0:v({analysisId:N.analysisId,scenarioId:J.id,scenarioName:J.name,entitySha:N.sha,entityName:N.name})},J.id))})]},N.sha))]}),F.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"})}),F.map(N=>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:N.name})}),e.jsx(me,{filePath:N.filePath,projectRoot:s}),N.testFile&&e.jsx(rt,{testFile:N.testFile,entityName:N.name})]},N.sha))]})]})})}return e.jsx("div",{ref:w,onScroll:O,className:"flex-1 overflow-auto",children:e.jsxs("div",{className:"p-3 space-y-3",children:[T.size>0&&e.jsxs("div",{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:"Application"})}),[...T.entries()].sort(([x],[y])=>x==="Home"?-1:y==="Home"?1:x.localeCompare(y)).map(([x,y])=>{var p,f;return e.jsxs("div",{className:"px-2 pt-1",children:[e.jsx("div",{className:"py-0.5",children:e.jsx("span",{className:"text-[11px] font-medium text-gray-400",children:x})}),(((p=y[0])==null?void 0:p.pageFilePath)||j[x])&&e.jsx(me,{filePath:((f=y[0])==null?void 0:f.pageFilePath)||j[x],projectRoot:s}),e.jsx("div",{className:"flex flex-wrap gap-2 pt-1",children:y.map(b=>e.jsx(Ie,{scenarioId:b.id,updatedAt:b.updatedAt,hasScreenshot:!!b.screenshotPath,name:b.name,isActive:b.id===n&&!S,onSelect:()=>r(b)},b.id))})]},x)})]}),B.size>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"})}),[...B.entries()].map(([x,y])=>{var p;return e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"flex items-center justify-between px-2 py-1",children:e.jsx("button",{onClick:()=>o(x),className:"text-[11px] font-medium text-gray-400 truncate cursor-pointer hover:text-white transition-colors bg-transparent border-none p-0",children:x})}),((p=y[0])==null?void 0:p.componentPath)&&e.jsx(me,{filePath:y[0].componentPath,projectRoot:s}),e.jsx("div",{className:"flex flex-wrap gap-2 px-2 pt-1",children:y.map(f=>e.jsx(Ie,{scenarioId:f.id,updatedAt:f.updatedAt,hasScreenshot:!!f.screenshotPath,name:f.name,isActive:f.id===n&&!S,onSelect:()=>r(f)},f.id))})]},x)})]}),I.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"}),$&&t.length===0&&l.every(x=>x.scenarioCount===0)&&e.jsx("span",{className:"ml-2 text-[10px] text-gray-500",children:"— Entities are being analyzed..."})]}),I.map(x=>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:()=>o(x.name),className:"text-[11px] font-medium text-gray-400 truncate cursor-pointer hover:text-white transition-colors bg-transparent border-none p-0",children:x.name}),x.isAnalyzing&&x.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(me,{filePath:x.filePath,projectRoot:s}),(x.scenarios.length>0||x.pendingScenarios.length>0)&&e.jsxs("div",{className:"flex flex-wrap gap-2 px-2 pt-1",children:[x.scenarios.map(y=>e.jsx(Ie,{imgSrc:y.screenshotPath?`/api/screenshot/${y.screenshotPath}`:null,name:y.name,isActive:y.id===S,onSelect:()=>v==null?void 0:v({analysisId:x.analysisId,scenarioId:y.id,scenarioName:y.name,entitySha:x.sha,entityName:x.name})},y.id)),x.pendingScenarios.map(y=>e.jsx("div",{className:"px-2.5 py-1 bg-[#2a2a2a] text-gray-400 text-[10px] rounded-full",title:y,children:y},y))]})]},x.sha))]}),(_.length>0||D.length>0)&&e.jsxs("div",{className:`pt-2 mt-1 ${I.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"})}),_.map(x=>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:x.name}),x.isAnalyzing&&x.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(me,{filePath:x.filePath,projectRoot:s}),x.testFile?e.jsx(rt,{testFile:x.testFile,entityName:x.name}):e.jsx("div",{className:"px-2 pt-1",children:e.jsx("span",{className:"text-[10px] text-gray-500",children:"No test file"})})]},x.sha)),D.map(x=>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:x.name})}),e.jsx(me,{filePath:x.filePath,projectRoot:s}),e.jsx(rt,{testFile:x.testFile,entityName:x.name})]},x.name))]})]})})}function tn(t,s,n=new Date){const r={"1d":1,"3d":3,"7d":7,"30d":30}[s],c=new Date(n);c.setDate(c.getDate()-r);const i=c.toISOString().split("T")[0],o=t.filter(C=>C.date>=i),l=new Set(o.map(C=>C.commitSha).filter(Boolean)),m=new Map;for(const C of o)if(C.scenarioScreenshots)for(const j of C.scenarioScreenshots){m.has(j.name)||m.set(j.name,[]);const T=m.get(j.name);T.some(h=>h.path===j.path)||T.push({path:j.path,time:C.time})}for(const C of m.values())C.sort((j,T)=>j.time.localeCompare(T.time));const S=[],v=new Map;for(const[C,j]of m){const T=C.indexOf(" - ");if(T!==-1){const h=C.slice(0,T);v.has(h)||v.set(h,[]),v.get(h).push({name:C,screenshots:j})}else S.push({name:C,screenshots:j})}return{commitCount:l.size,entryCount:o.length,appScenarios:S,componentGroups:v,totalScenarios:m.size}}function sn(t){const s=new Map;for(const n of[...t].reverse()){const r=s.get(n.date)||[];r.push(n),s.set(n.date,r)}return s}function nn(t){const s=new Map;for(const n of t){let r;if("componentName"in n&&n.componentName)r=n.componentName;else if("componentName"in n&&n.componentName===null)r="App";else{const i=n.name.indexOf(" - ");r=i!==-1?n.name.slice(0,i):"App"}const c=s.get(r)||[];c.push(n),s.set(r,c)}return[...s.entries()].sort(([n],[r])=>n==="App"?-1:r==="App"?1:n.localeCompare(r))}const _t=120;function Kt({text:t,theme:s}){const[n,r]=a.useState(!1),c=t.length>_t,i=c&&!n?t.slice(0,_t)+"…":t,o=s==="light";return e.jsxs("div",{className:`px-4 py-2 ${o?"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 ${o?"text-gray-600":"text-gray-400"}`,children:[i,c&&e.jsx("button",{onClick:()=>r(!n),className:`ml-1 text-[11px] font-medium bg-transparent border-none p-0 cursor-pointer ${o?"text-blue-500 hover:text-blue-700":"text-[#00a0c4] hover:text-[#00c0e8]"}`,children:n?"Show less":"Read more…"})]})]})}function Dt({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 an({testFile:t,entityName:s}){const{results:n,isRunning:r,runTests:c}=lt(t);if(r&&!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(m=>m.fullName.startsWith(s)):n.testCases,o=i.length>0?i:n.testCases;if(o.length===0)return null;const l=s?`${s} > `:"";return e.jsxs("div",{className:"pt-1 space-y-0.5",children:[o.map(m=>{var v;const S=l&&m.fullName.startsWith(l)?m.fullName.slice(l.length):m.fullName;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[m.status==="passed"?e.jsx("span",{className:"text-green-400 text-[10px]",children:"✓"}):m.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] ${m.status==="passed"?"text-green-400":m.status==="failed"?"text-red-400":"text-gray-500"}`,children:S})]}),m.status==="failed"&&((v=m.failureMessages)==null?void 0:v.map((C,j)=>e.jsx("div",{className:"pl-4 text-[9px] text-red-400/70 truncate max-w-full",title:C,children:C.split(`
4
- `)[0]},j)))]},m.fullName)}),e.jsx("button",{onClick:c,disabled:r,className:"mt-1 text-[10px] text-[#00a0c4] hover:text-[#38bdf8] transition-colors cursor-pointer disabled:opacity-50 bg-transparent border-none p-0",children:r?"Running...":"Re-run"})]})}const rn={added:"text-green-400",untracked:"text-green-400",modified:"text-blue-400",renamed:"text-purple-400"};function on({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 ${rn[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 ln={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 cn(t){try{return new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return""}}function dn(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 xn({entries:t,onScreenshotClick:s}){const[n,r]=a.useState(!1),[c,i]=a.useState("7d"),o=a.useMemo(()=>tn(t,c),[t,c]);return e.jsxs("div",{className:"bg-[#2d2d2d] rounded-lg overflow-hidden",children:[e.jsxs("button",{onClick:()=>r(!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:mn.map(l=>e.jsx("button",{onClick:()=>i(l.value),className:`px-2.5 py-1 text-[10px] font-medium rounded transition-colors cursor-pointer border ${c===l.value?"bg-[#005c75] text-white border-[#005c75]":"bg-transparent text-gray-400 border-[#4d4d4d] hover:text-white hover:border-[#005c75]"}`,children:l.label},l.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:o.commitCount})," ",o.commitCount===1?"commit":"commits"]}),e.jsx("span",{className:"text-[#3d3d3d]",children:"|"}),e.jsxs("span",{children:[e.jsx("span",{className:"text-white font-medium",children:o.totalScenarios})," ",o.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:o.entryCount})," ",o.entryCount===1?"entry":"entries"]})]}),o.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:[o.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"}),o.appScenarios.map(l=>e.jsx(Ft,{scenario:l,onScreenshotClick:s},l.name))]}),o.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"}),[...o.componentGroups.entries()].sort(([l],[m])=>l.localeCompare(m)).map(([l,m])=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{className:"text-[10px] font-medium text-gray-400",children:l}),m.map(S=>e.jsx(Ft,{scenario:S,onScreenshotClick:s},S.name))]},l))]})]})]})]})}function Ft({scenario:t,onScreenshotClick:s}){const n=t.name.indexOf(" - "),r=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:r}),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:n=[]}){const[r,c]=a.useState([]),[i,o]=a.useState(!0),[l,m]=a.useState(new Set),S=a.useCallback(j=>{m(T=>{const h=new Set(T);return h.has(j)?h.delete(j):h.add(j),h})},[]),v=a.useCallback(async()=>{try{const j=await fetch("/api/editor-journal");if(j.ok){const T=await j.json();c(T.entries||[])}}catch{}finally{o(!1)}},[]);if(a.useEffect(()=>{v()},[v]),a.useEffect(()=>{t&&v()},[t,v]),a.useEffect(()=>{if(!t)return;const j=setInterval(()=>void v(),5e3);return()=>clearInterval(j)},[t,v]),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(r.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 C=sn(r);return e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsxs("div",{className:"p-3 space-y-4",children:[e.jsx(xn,{entries:r,onScreenshotClick:s}),[...C.entries()].map(([j,T])=>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:dn(j)})}),e.jsx("div",{className:"space-y-2",children:T.map((h,B)=>{const I=ln[h.type]||{label:h.type,color:"bg-gray-600"},_=`${h.time}-${B}`,D=l.has(_);return e.jsxs("div",{className:"bg-[#2d2d2d] rounded-lg overflow-hidden",children:[e.jsxs("div",{className:`p-3 space-y-2 ${D?"":"max-h-[300px] overflow-y-auto"}`,children:[e.jsx("div",{className:"flex items-start gap-2 cursor-pointer",onClick:()=>S(_),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:`${I.color} text-white text-[9px] font-bold px-1.5 py-0.5 rounded uppercase tracking-wider shrink-0`,children:I.label})]}),e.jsx("span",{className:"text-[10px] text-gray-500",children:cn(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(Kt,{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 $=nn(h.scenarioScreenshots),w=h.entityChangeStatus,M=$.filter(([f])=>f==="App").flatMap(([,f])=>f),O=$.filter(([f])=>f!=="App"),x=new Map;for(const f of M){const b=f,E=b.pageFilePath?Re($e(b.pageFilePath)):We(b.url??null),L=x.get(E)||[];L.push(f),x.set(E,L)}const y=[...x.entries()],p=f=>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/${f.path.replace("screenshots/","")}`,commitSha:h.commitSha,commitMessage:h.commitMessage,scenarioName:f.name}),children:e.jsx("img",{src:`/api/editor-journal-image/${f.path.replace("screenshots/","")}`,alt:f.name,title:f.name,className:"max-w-full max-h-full object-contain",loading:"lazy"})},f.path);return e.jsxs("div",{className:"space-y-2",children:[y.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"}),y.map(([f,b])=>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:f}),(w==null?void 0:w[f])&&e.jsx(Dt,{status:w[f]})]}),e.jsx("div",{className:"flex flex-wrap gap-1 mt-0.5",children:b.map(p)})]},f))]}),O.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"}),O.map(([f,b])=>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:f}),(w==null?void 0:w[f])&&e.jsx(Dt,{status:w[f]})]}),e.jsx("div",{className:"flex flex-wrap gap-1 mt-0.5",children:b.map(p)})]},f))]})]})})(),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($=>e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] font-medium text-gray-200",children:$.name}),e.jsx("span",{className:"text-[9px] text-gray-500 truncate block",children:$.filePath}),$.testFile?e.jsx(an,{testFile:$.testFile,entityName:$.name}):e.jsx("div",{className:"pt-1",children:e.jsx("span",{className:"text-[10px] text-gray-500",children:"No test file"})})]},$.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})]}),D&&h.modifiedFiles&&h.modifiedFiles.length>0&&e.jsx(on,{files:h.modifiedFiles})]}),e.jsxs("button",{onClick:()=>S(_),className:"w-full py-1.5 text-[10px] text-gray-500 hover:text-gray-300 border-t border-[#3d3d3d] transition-colors cursor-pointer",children:["——— ",D?"Collapse":"Expand"," ———"]})]},_)})})]},j))]})})}function un({prompt:t,height:s=300,onClose:n}){const r=a.useRef(null),c=a.useRef(null),i=a.useRef(null),o=a.useRef(!1),l=a.useRef(t);return a.useEffect(()=>{const m=r.current;if(!m)return;let S=!1,v=null;async function C(){const[j,T]=await Promise.all([it(()=>import("./xterm-BqvuqXEL.js"),[]),it(()=>import("./addon-fit-YJmn1quW.js"),[])]);if(S)return;{let x=document.getElementById("xterm-css");x||(x=document.createElement("style"),x.id="xterm-css",document.head.appendChild(x)),x.textContent=`
2
+ var Ts=Object.defineProperty;var Is=(t,s,n)=>s in t?Ts(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var $t=(t,s,n)=>Is(t,typeof s!="symbol"?s+"":s,n);import{r as a,w as Rs,u as As,b as $s,a as Ls,c as _s,O as Ds}from"./chunk-JZWAC4HX-BAdwhyCx.js";import{j as e}from"./jsx-runtime-D_zvdyIk.js";import{u as Fs,C as Bs}from"./useCustomSizes-DhXHbEjP.js";import{g as Lt,s as Os,r as st,b as nt,c as zs,l as Ws,d as Us,e as Hs,f as Js,a as Gs,T as Vs,D as qs}from"./editorPreview-oepecPae.js";import{C as ve}from"./CopyButton-CLe80MMu.js";import{_ as it}from"./preload-helper-ckwbz45p.js";import{c as Ys}from"./cy-logo-cli-DcX-ZS3p.js";import{u as Xs,S as at}from"./Spinner-D0LgAaSa.js";import"./copy-C6iF61Xs.js";import"./createLucideIcon-4ImjHTVC.js";import"./useLastLogLine-BNd5hYuW.js";function Re(t){var l;if(!t.startsWith("app/")&&!t.startsWith("("))return"/";const n=t.replace(/^app\//,"").split("/"),r=n.pop(),c=((l=r.match(/\.(tsx?|jsx?|js)$/))==null?void 0:l[0])||"",i=r.slice(0,-c.length);let o;return i==="page"||i==="index"?o=n:o=[...n,i],o=o.filter(m=>!m.startsWith("(")),o.length===0?"/":"/"+o.join("/")}function Ae(t){return t==="/"?"Home":t.replace(/^\//,"").split("/").map(n=>n.startsWith("[")?n:n.charAt(0).toUpperCase()+n.slice(1)).join(" / ")}function We(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 Xt(t){return t?t.includes("/isolated-components")||t.includes("/codeyam-isolate"):!1}function Ks(t,s){return!s||Object.keys(s).length===0?t:t.filter(n=>s[n.name])}const ze=[{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 Qs(t){if(!t)return ze;const s=Object.entries(t).map(([r,c])=>({name:r,width:c.width,height:c.height})),n=new Set(s.map(r=>r.name));return[...s,...ze.filter(r=>!n.has(r.name))]}function Zs({featureName:t,editorStep:s,editorStepLabel:n,onContinue:r}){const c=a.useCallback(i=>{i.key==="Enter"&&(i.preventDefault(),r())},[r]);return a.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:r,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 en={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"},tn={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."},sn={1:"Survey",2:"App Scenarios",3:"Component Scenarios",4:"Preview",5:"Discuss",6:"Decompose",7:"Extract",8:"Recapture",9:"Journal",10:"Present"},nn={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."},an=18,rn=10;function on({projectTitle:t,featureName:s,editorStep:n,editorStepLabel:r,migrationMode:c}){const[i,o]=a.useState(!1),[l,m]=a.useState(null),w=a.useRef(null);a.useEffect(()=>{if(!i)return;const P=_=>{w.current&&!w.current.contains(_.target)&&o(!1)};return document.addEventListener("mousedown",P),()=>document.removeEventListener("mousedown",P)},[i]);const v=s&&n!=null,k=c==="active",g=k?sn:en,R=k?nn:tn,u=k?rn:an,B=v?r||g[n]||"?":null,I=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:I})]}),v&&e.jsxs("div",{className:"relative",ref:w,children:[e.jsxs("button",{onClick:()=>o(P=>!P),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:["/",u]}),": ",B]}),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:u},(P,_)=>_+1).map(P=>{const _=P===n,A=P<n,N=l===P,E=R[P];return e.jsxs("div",{onClick:()=>m(N?null:P),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] ${_?"text-green-400 font-medium":A?"text-[#ccc]":"text-[#999]"}`,children:[e.jsxs("span",{className:"w-5 text-right tabular-nums shrink-0",children:[P,"."]}),e.jsx("span",{className:"flex-1",children:g[P]||`Step ${P}`}),E&&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 ${N?"rotate-180":""}`,children:e.jsx("path",{d:"M2 4l3 3 3-3"})})]}),N&&E&&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:E})})]},P)})})]})]})}function lt(t){const[s,n]=a.useState(null),[r,c]=a.useState(!1),i=a.useCallback(()=>{t&&(c(!0),fetch(`/api/editor-test-results?testFile=${encodeURIComponent(t)}`).then(o=>o.json()).then(o=>{n(o),c(!1)}).catch(()=>{n({testFilePath:t,status:"error",testCases:[],errorMessage:"Failed to fetch test results"}),c(!1)}))},[t]);return{results:s,isRunning:r,runTests:i}}function Ue({scenarioId:t,updatedAt:s,alt:n,className:r="",imgClassName:c=""}){const[i,o]=a.useState(!1),l=`/api/editor-scenario-image/${t}.png${s?`?v=${encodeURIComponent(s)}`:""}`;return a.useEffect(()=>{o(!1)},[t]),i?e.jsx("div",{className:`flex items-center justify-center ${r}`,children:e.jsx("span",{className:"text-[8px] text-gray-500",children:"No img"})}):e.jsx("div",{className:r,children:e.jsx("img",{src:l,alt:n,className:c,loading:"lazy",onError:()=>o(!0)})})}function Te({scenarioId:t,updatedAt:s,hasScreenshot:n,imgSrc:r,name:c,isActive:i,onSelect:o}){const l=t&&n,m=!t&&r;return e.jsxs("button",{onClick:o,className:"flex flex-col items-center gap-1 cursor-pointer group",title:c,children:[e.jsx("div",{className:`w-32 h-32 rounded overflow-hidden border-2 transition-all bg-[#1a1a1a] ${i?"border-[#005c75] ring-1 ring-[#005c75]":"border-transparent hover:border-[#4d4d4d]"}`,children:l?e.jsx(Ue,{scenarioId:t,updatedAt:s,alt:c,className:"w-full h-full",imgClassName:"w-full h-full object-contain"}):m?e.jsx("img",{src:r,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-32 ${i?"text-white":"text-gray-500 group-hover:text-gray-300"}`,children:c})]})}function rt({testFile:t,entityName:s}){const{results:n,isRunning:r,runTests:c}=lt(t);if(r&&!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(m=>m.fullName.startsWith(s)):n.testCases,o=i.length>0?i:n.testCases;if(o.length===0)return null;const l=s?`${s} > `:"";return e.jsxs("div",{className:"px-2 pt-1 space-y-0.5",children:[o.map(m=>{var v;const w=l&&m.fullName.startsWith(l)?m.fullName.slice(l.length):m.fullName;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[m.status==="passed"?e.jsx("span",{className:"text-green-400 text-[10px]",children:"✓"}):m.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] ${m.status==="passed"?"text-green-400":m.status==="failed"?"text-red-400":"text-gray-500"}`,children:w})]}),m.status==="failed"&&((v=m.failureMessages)==null?void 0:v.map((k,g)=>e.jsx("div",{className:"pl-4 text-[9px] text-red-300/70 truncate max-w-full",title:k,children:k.split(`
3
+ `)[0]},g)))]},m.fullName)}),e.jsx("button",{onClick:c,disabled:r,className:"mt-1 text-[10px] text-[#00a0c4] hover:text-[#00c4ee] transition-colors cursor-pointer disabled:opacity-50 bg-transparent border-none p-0",children:r?"Running...":"Re-run"})]})}function me({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(ve,{content:t,icon:!0,iconSize:10,className:"shrink-0 text-gray-500 hover:text-gray-300 transition-colors"})]}):null}function ln({scenarios:t,projectRoot:s,activeScenarioId:n,onScenarioSelect:r,zoomComponent:c,focusedEntity:i,onZoomChange:o,analyzedEntities:l=[],glossaryFunctions:m=[],activeAnalyzedScenarioId:w,onAnalyzedScenarioSelect:v,entityImports:k,pageFilePaths:g={}}){const{pageGroups:R,componentGroups:u}=a.useMemo(()=>{var f;const x=new Map,y=new Map;for(const b of t)if(b.componentName){const T=y.get(b.componentName)||[];T.push(b),y.set(b.componentName,T)}else if(Xt(b.url)){const T=(f=b.url)==null?void 0:f.match(/[?&]c=([^&]+)/),D=T?decodeURIComponent(T[1]):"Isolated",F=y.get(D)||[];F.push(b),y.set(D,F)}else{const T=b.pageFilePath?Ae(Re(b.pageFilePath)):We(b.url),D=x.get(T)||[];D.push(b),x.set(T,D)}const p=new Map([...y.entries()].sort(([b],[T])=>b.localeCompare(T)));return{pageGroups:x,componentGroups:p}},[t]),B=a.useMemo(()=>{const x=new Set((l||[]).filter(p=>p.entityType==="visual").map(p=>p.name)),y=new Map;for(const[p,f]of u)x.has(p)||y.set(p,f);return y},[u,l]),{visualEntities:I,libraryEntities:P}=a.useMemo(()=>{const x=l.filter(p=>p.entityType==="visual").sort((p,f)=>p.name.localeCompare(f.name)),y=l.filter(p=>p.entityType==="library"||p.entityType==="functionCall").sort((p,f)=>p.name.localeCompare(f.name));return{visualEntities:x,libraryEntities:y}},[l]),_=a.useMemo(()=>{const x=new Set(P.map(y=>y.name));return m.filter(y=>!x.has(y.name)).sort((y,p)=>y.name.localeCompare(p.name))},[m,P]),A=l.some(x=>x.isAnalyzing),N=a.useRef(null),E=a.useRef(0),O=a.useCallback(()=>{N.current&&(E.current=N.current.scrollTop)},[]);if(a.useEffect(()=>{N.current&&E.current>0&&(N.current.scrollTop=E.current)}),t.length===0&&l.length===0&&_.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 x=i.name,y=i.filePath,p=i.sha,f=t.filter(S=>S.componentName===x||S.componentPath===y||!S.componentName&&(S.pageFilePath===y||p&&S.entitySha===p)),b=new Set((k==null?void 0:k[x])||[]),T=b.size>0,D=T?I.filter(S=>b.has(S.name)):[],F=T?P.filter(S=>b.has(S.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:()=>o(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:f.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-gray-500",children:"No scenarios for this component"}):f.map(S=>e.jsx(Te,{scenarioId:S.id,updatedAt:S.updatedAt,hasScreenshot:!!S.screenshotPath,name:S.name,isActive:S.id===n,onSelect:()=>r(S)},S.id))}),D.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"})}),D.map(S=>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:()=>o(S.name),className:"text-[11px] font-medium text-gray-400 truncate cursor-pointer hover:text-white transition-colors bg-transparent border-none p-0",children:S.name})}),e.jsx(me,{filePath:S.filePath,projectRoot:s}),(S.scenarios.length>0||S.pendingScenarios.length>0)&&e.jsx("div",{className:"flex flex-wrap gap-2 px-2 pt-1",children:S.scenarios.map(J=>e.jsx(Te,{imgSrc:J.screenshotPath?`/api/screenshot/${J.screenshotPath}`:null,name:J.name,isActive:J.id===w,onSelect:()=>v==null?void 0:v({analysisId:S.analysisId,scenarioId:J.id,scenarioName:J.name,entitySha:S.sha,entityName:S.name})},J.id))})]},S.sha))]}),F.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"})}),F.map(S=>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:S.name})}),e.jsx(me,{filePath:S.filePath,projectRoot:s}),S.testFile&&e.jsx(rt,{testFile:S.testFile,entityName:S.name})]},S.sha))]})]})})}return e.jsx("div",{ref:N,onScroll:O,className:"flex-1 overflow-auto",children:e.jsxs("div",{className:"p-3 space-y-3",children:[R.size>0&&e.jsxs("div",{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:"Application"})}),[...R.entries()].sort(([x],[y])=>x==="Home"?-1:y==="Home"?1:x.localeCompare(y)).map(([x,y])=>{var p,f;return e.jsxs("div",{className:"px-2 pt-1",children:[e.jsx("div",{className:"py-0.5",children:e.jsx("span",{className:"text-[11px] font-medium text-gray-400",children:x})}),(((p=y[0])==null?void 0:p.pageFilePath)||g[x])&&e.jsx(me,{filePath:((f=y[0])==null?void 0:f.pageFilePath)||g[x],projectRoot:s}),e.jsx("div",{className:"flex flex-wrap gap-2 pt-1",children:y.map(b=>e.jsx(Te,{scenarioId:b.id,updatedAt:b.updatedAt,hasScreenshot:!!b.screenshotPath,name:b.name,isActive:b.id===n&&!w,onSelect:()=>r(b)},b.id))})]},x)})]}),B.size>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"})}),[...B.entries()].map(([x,y])=>{var p;return e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"flex items-center justify-between px-2 py-1",children:e.jsx("button",{onClick:()=>o(x),className:"text-[11px] font-medium text-gray-400 truncate cursor-pointer hover:text-white transition-colors bg-transparent border-none p-0",children:x})}),((p=y[0])==null?void 0:p.componentPath)&&e.jsx(me,{filePath:y[0].componentPath,projectRoot:s}),e.jsx("div",{className:"flex flex-wrap gap-2 px-2 pt-1",children:y.map(f=>e.jsx(Te,{scenarioId:f.id,updatedAt:f.updatedAt,hasScreenshot:!!f.screenshotPath,name:f.name,isActive:f.id===n&&!w,onSelect:()=>r(f)},f.id))})]},x)})]}),I.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"}),A&&t.length===0&&l.every(x=>x.scenarioCount===0)&&e.jsx("span",{className:"ml-2 text-[10px] text-gray-500",children:"— Entities are being analyzed..."})]}),I.map(x=>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:()=>o(x.name),className:"text-[11px] font-medium text-gray-400 truncate cursor-pointer hover:text-white transition-colors bg-transparent border-none p-0",children:x.name}),x.isAnalyzing&&x.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(me,{filePath:x.filePath,projectRoot:s}),(x.scenarios.length>0||x.pendingScenarios.length>0)&&e.jsxs("div",{className:"flex flex-wrap gap-2 px-2 pt-1",children:[x.scenarios.map(y=>e.jsx(Te,{imgSrc:y.screenshotPath?`/api/screenshot/${y.screenshotPath}`:null,name:y.name,isActive:y.id===w,onSelect:()=>v==null?void 0:v({analysisId:x.analysisId,scenarioId:y.id,scenarioName:y.name,entitySha:x.sha,entityName:x.name})},y.id)),x.pendingScenarios.map(y=>e.jsx("div",{className:"px-2.5 py-1 bg-[#2a2a2a] text-gray-400 text-[10px] rounded-full",title:y,children:y},y))]})]},x.sha))]}),(P.length>0||_.length>0)&&e.jsxs("div",{className:`pt-2 mt-1 ${I.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"})}),P.map(x=>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:x.name}),x.isAnalyzing&&x.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(me,{filePath:x.filePath,projectRoot:s}),x.testFile?e.jsx(rt,{testFile:x.testFile,entityName:x.name}):e.jsx("div",{className:"px-2 pt-1",children:e.jsx("span",{className:"text-[10px] text-gray-500",children:"No test file"})})]},x.sha)),_.map(x=>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:x.name})}),e.jsx(me,{filePath:x.filePath,projectRoot:s}),e.jsx(rt,{testFile:x.testFile,entityName:x.name})]},x.name))]})]})})}function cn(t,s,n=new Date){const r={"1d":1,"3d":3,"7d":7,"30d":30}[s],c=new Date(n);c.setDate(c.getDate()-r);const i=c.toISOString().split("T")[0],o=t.filter(k=>k.date>=i),l=new Set(o.map(k=>k.commitSha).filter(Boolean)),m=new Map;for(const k of o)if(k.scenarioScreenshots)for(const g of k.scenarioScreenshots){m.has(g.name)||m.set(g.name,[]);const R=m.get(g.name);R.some(u=>u.path===g.path)||R.push({path:g.path,time:k.time})}for(const k of m.values())k.sort((g,R)=>g.time.localeCompare(R.time));const w=[],v=new Map;for(const[k,g]of m){const R=k.indexOf(" - ");if(R!==-1){const u=k.slice(0,R);v.has(u)||v.set(u,[]),v.get(u).push({name:k,screenshots:g})}else w.push({name:k,screenshots:g})}return{commitCount:l.size,entryCount:o.length,appScenarios:w,componentGroups:v,totalScenarios:m.size}}function dn(t){const s=new Map;for(const n of[...t].reverse()){const r=s.get(n.date)||[];r.push(n),s.set(n.date,r)}return s}function mn(t){const s=new Map;for(const n of t){let r;if("componentName"in n&&n.componentName)r=n.componentName;else if("componentName"in n&&n.componentName===null)r="App";else{const i=n.name.indexOf(" - ");r=i!==-1?n.name.slice(0,i):"App"}const c=s.get(r)||[];c.push(n),s.set(r,c)}return[...s.entries()].sort(([n],[r])=>n==="App"?-1:r==="App"?1:n.localeCompare(r))}const _t=120;function Kt({text:t,theme:s}){const[n,r]=a.useState(!1),c=t.length>_t,i=c&&!n?t.slice(0,_t)+"…":t,o=s==="light";return e.jsxs("div",{className:`px-4 py-2 ${o?"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 ${o?"text-gray-600":"text-gray-400"}`,children:[i,c&&e.jsx("button",{onClick:()=>r(!n),className:`ml-1 text-[11px] font-medium bg-transparent border-none p-0 cursor-pointer ${o?"text-blue-500 hover:text-blue-700":"text-[#00a0c4] hover:text-[#00c0e8]"}`,children:n?"Show less":"Read more…"})]})]})}function Dt({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 xn({testFile:t,entityName:s}){const{results:n,isRunning:r,runTests:c}=lt(t);if(r&&!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(m=>m.fullName.startsWith(s)):n.testCases,o=i.length>0?i:n.testCases;if(o.length===0)return null;const l=s?`${s} > `:"";return e.jsxs("div",{className:"pt-1 space-y-0.5",children:[o.map(m=>{var v;const w=l&&m.fullName.startsWith(l)?m.fullName.slice(l.length):m.fullName;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[m.status==="passed"?e.jsx("span",{className:"text-green-400 text-[10px]",children:"✓"}):m.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] ${m.status==="passed"?"text-green-400":m.status==="failed"?"text-red-400":"text-gray-500"}`,children:w})]}),m.status==="failed"&&((v=m.failureMessages)==null?void 0:v.map((k,g)=>e.jsx("div",{className:"pl-4 text-[9px] text-red-400/70 truncate max-w-full",title:k,children:k.split(`
4
+ `)[0]},g)))]},m.fullName)}),e.jsx("button",{onClick:c,disabled:r,className:"mt-1 text-[10px] text-[#00a0c4] hover:text-[#38bdf8] transition-colors cursor-pointer disabled:opacity-50 bg-transparent border-none p-0",children:r?"Running...":"Re-run"})]})}const pn={added:"text-green-400",untracked:"text-green-400",modified:"text-blue-400",renamed:"text-purple-400"};function un({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 ${pn[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 hn={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 fn(t){try{return new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return""}}function gn(t){try{return new Date(t+"T00:00:00").toLocaleDateString([],{weekday:"long",month:"long",day:"numeric"})}catch{return t}}const jn=[{value:"1d",label:"1 Day"},{value:"3d",label:"3 Days"},{value:"7d",label:"1 Week"},{value:"30d",label:"1 Month"}];function bn({entries:t,onScreenshotClick:s}){const[n,r]=a.useState(!1),[c,i]=a.useState("7d"),o=a.useMemo(()=>cn(t,c),[t,c]);return e.jsxs("div",{className:"bg-[#2d2d2d] rounded-lg overflow-hidden",children:[e.jsxs("button",{onClick:()=>r(!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:jn.map(l=>e.jsx("button",{onClick:()=>i(l.value),className:`px-2.5 py-1 text-[10px] font-medium rounded transition-colors cursor-pointer border ${c===l.value?"bg-[#005c75] text-white border-[#005c75]":"bg-transparent text-gray-400 border-[#4d4d4d] hover:text-white hover:border-[#005c75]"}`,children:l.label},l.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:o.commitCount})," ",o.commitCount===1?"commit":"commits"]}),e.jsx("span",{className:"text-[#3d3d3d]",children:"|"}),e.jsxs("span",{children:[e.jsx("span",{className:"text-white font-medium",children:o.totalScenarios})," ",o.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:o.entryCount})," ",o.entryCount===1?"entry":"entries"]})]}),o.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:[o.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"}),o.appScenarios.map(l=>e.jsx(Ft,{scenario:l,onScreenshotClick:s},l.name))]}),o.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"}),[...o.componentGroups.entries()].sort(([l],[m])=>l.localeCompare(m)).map(([l,m])=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{className:"text-[10px] font-medium text-gray-400",children:l}),m.map(w=>e.jsx(Ft,{scenario:w,onScreenshotClick:s},w.name))]},l))]})]})]})]})}function Ft({scenario:t,onScreenshotClick:s}){const n=t.name.indexOf(" - "),r=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:r}),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 yn({isActive:t,onScreenshotClick:s,glossaryFunctions:n=[]}){const[r,c]=a.useState([]),[i,o]=a.useState(!0),[l,m]=a.useState(new Set),w=a.useCallback(g=>{m(R=>{const u=new Set(R);return u.has(g)?u.delete(g):u.add(g),u})},[]),v=a.useCallback(async()=>{try{const g=await fetch("/api/editor-journal");if(g.ok){const R=await g.json();c(R.entries||[])}}catch{}finally{o(!1)}},[]);if(a.useEffect(()=>{v()},[v]),a.useEffect(()=>{t&&v()},[t,v]),a.useEffect(()=>{if(!t)return;const g=setInterval(()=>void v(),5e3);return()=>clearInterval(g)},[t,v]),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(r.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 k=dn(r);return e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsxs("div",{className:"p-3 space-y-4",children:[e.jsx(bn,{entries:r,onScreenshotClick:s}),[...k.entries()].map(([g,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:gn(g)})}),e.jsx("div",{className:"space-y-2",children:R.map((u,B)=>{const I=hn[u.type]||{label:u.type,color:"bg-gray-600"},P=`${u.time}-${B}`,_=l.has(P);return e.jsxs("div",{className:"bg-[#2d2d2d] rounded-lg overflow-hidden",children:[e.jsxs("div",{className:`p-3 space-y-2 ${_?"":"max-h-[300px] overflow-y-auto"}`,children:[e.jsx("div",{className:"flex items-start gap-2 cursor-pointer",onClick:()=>w(P),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:u.title}),e.jsx("span",{className:`${I.color} text-white text-[9px] font-bold px-1.5 py-0.5 rounded uppercase tracking-wider shrink-0`,children:I.label})]}),e.jsx("span",{className:"text-[10px] text-gray-500",children:fn(u.time)}),u.featureName&&e.jsx("span",{className:"text-[10px] text-gray-500 italic truncate",title:u.featureName,children:u.featureName})]})}),u.userPrompt&&e.jsx(Kt,{text:u.userPrompt,theme:"dark"}),e.jsx("p",{className:"text-xs text-gray-400 leading-relaxed",children:u.description}),u.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/${u.screenshot.replace("screenshots/","")}`,commitSha:u.commitSha,commitMessage:u.commitMessage,scenarioName:u.title}),children:e.jsx("img",{src:`/api/editor-journal-image/${u.screenshot.replace("screenshots/","")}`,alt:u.title,className:"max-w-full max-h-full object-contain",loading:"lazy"})}),u.scenarioScreenshots&&u.scenarioScreenshots.length>0&&(()=>{const A=mn(u.scenarioScreenshots),N=u.entityChangeStatus,E=A.filter(([f])=>f==="App").flatMap(([,f])=>f),O=A.filter(([f])=>f!=="App"),x=new Map;for(const f of E){const b=f,T=b.pageFilePath?Ae(Re(b.pageFilePath)):We(b.url??null),D=x.get(T)||[];D.push(f),x.set(T,D)}const y=[...x.entries()],p=f=>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/${f.path.replace("screenshots/","")}`,commitSha:u.commitSha,commitMessage:u.commitMessage,scenarioName:f.name}),children:e.jsx("img",{src:`/api/editor-journal-image/${f.path.replace("screenshots/","")}`,alt:f.name,title:f.name,className:"max-w-full max-h-full object-contain",loading:"lazy"})},f.path);return e.jsxs("div",{className:"space-y-2",children:[y.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"}),y.map(([f,b])=>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:f}),(N==null?void 0:N[f])&&e.jsx(Dt,{status:N[f]})]}),e.jsx("div",{className:"flex flex-wrap gap-1 mt-0.5",children:b.map(p)})]},f))]}),O.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"}),O.map(([f,b])=>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:f}),(N==null?void 0:N[f])&&e.jsx(Dt,{status:N[f]})]}),e.jsx("div",{className:"flex flex-wrap gap-1 mt-0.5",children:b.map(p)})]},f))]})]})})(),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(A=>e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] font-medium text-gray-200",children:A.name}),e.jsx("span",{className:"text-[9px] text-gray-500 truncate block",children:A.filePath}),A.testFile?e.jsx(xn,{testFile:A.testFile,entityName:A.name}):e.jsx("div",{className:"pt-1",children:e.jsx("span",{className:"text-[10px] text-gray-500",children:"No test file"})})]},A.name))})]}),u.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:u.commitSha.slice(0,7)}),e.jsx("span",{className:"text-gray-500 truncate",children:u.commitMessage})]}),_&&u.modifiedFiles&&u.modifiedFiles.length>0&&e.jsx(un,{files:u.modifiedFiles})]}),e.jsxs("button",{onClick:()=>w(P),className:"w-full py-1.5 text-[10px] text-gray-500 hover:text-gray-300 border-t border-[#3d3d3d] transition-colors cursor-pointer",children:["——— ",_?"Collapse":"Expand"," ———"]})]},P)})})]},g))]})})}function vn({prompt:t,height:s=300,onClose:n}){const r=a.useRef(null),c=a.useRef(null),i=a.useRef(null),o=a.useRef(!1),l=a.useRef(t);return a.useEffect(()=>{const m=r.current;if(!m)return;let w=!1,v=null;async function k(){const[g,R]=await Promise.all([it(()=>import("./xterm-BqvuqXEL.js"),[]),it(()=>import("./addon-fit-YJmn1quW.js"),[])]);if(w)return;{let x=document.getElementById("xterm-css");x||(x=document.createElement("style"),x.id="xterm-css",document.head.appendChild(x)),x.textContent=`
5
5
  .xterm { cursor: text; position: relative; user-select: none; -ms-user-select: none; -webkit-user-select: none; }
6
6
  .xterm.focus, .xterm:focus { outline: none; }
7
7
  .xterm .xterm-helpers { position: absolute; top: 0; z-index: 5; }
@@ -32,27 +32,27 @@ var Is=Object.defineProperty;var Ts=(t,s,n)=>s in t?Is(t,s,{enumerable:!0,config
32
32
  .xterm-screen .xterm-decoration-container .xterm-decoration.xterm-decoration-top-layer { z-index: 7; }
33
33
  .xterm-decoration-overview-ruler { z-index: 8; position: absolute; top: 0; right: 0; pointer-events: none; }
34
34
  .xterm-decoration-top { z-index: 2; position: relative; }
35
- `}const h=new j.Terminal({theme:{background:"#1a1a1a",foreground:"#d4d4d4",cursor:"#d4d4d4",selectionBackground:"#264f78"},fontSize:12,fontFamily:"'IBM Plex Mono', 'Menlo', 'Monaco', monospace",cursorBlink:!0,scrollback:5e3,allowProposedApi:!0}),B=new T.FitAddon;h.loadAddon(B),h.open(m),requestAnimationFrame(()=>{try{B.fit()}catch{}}),i.current=h;let I=null;try{const x=await fetch("/api/editor-scenario-prompt",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:l.current})});x.ok&&(I=(await x.json()).promptFile)}catch{}if(S)return;const _=window.location.protocol==="https:"?"wss:":"ws:",D=window.location.host,$=new URLSearchParams;$.set("entityName","inline-claude");const w=`${_}//${D}/ws/terminal?${$.toString()}`,M=new WebSocket(w);c.current=M,M.onopen=()=>{M.send(JSON.stringify({type:"resize",cols:h.cols,rows:h.rows}))};let O=!1;M.onmessage=x=>{try{const y=JSON.parse(x.data);if(y.type==="session-id"&&!O){O=!0,setTimeout(()=>{const p=I?`claude "Read the file at '${I.replace(/'/g,"'\\''")}' for your instructions."`:"claude";M.send(JSON.stringify({type:"input",data:p+"\r"}))},300);return}if(y.type==="output"&&y.data){h.write(y.data);return}}catch{h.write(x.data)}},M.onclose=()=>{o.current||h.write(`\r
35
+ `}const u=new g.Terminal({theme:{background:"#1a1a1a",foreground:"#d4d4d4",cursor:"#d4d4d4",selectionBackground:"#264f78"},fontSize:12,fontFamily:"'IBM Plex Mono', 'Menlo', 'Monaco', monospace",cursorBlink:!0,scrollback:5e3,allowProposedApi:!0}),B=new R.FitAddon;u.loadAddon(B),u.open(m),requestAnimationFrame(()=>{try{B.fit()}catch{}}),i.current=u;let I=null;try{const x=await fetch("/api/editor-scenario-prompt",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:l.current})});x.ok&&(I=(await x.json()).promptFile)}catch{}if(w)return;const P=window.location.protocol==="https:"?"wss:":"ws:",_=window.location.host,A=new URLSearchParams;A.set("entityName","inline-claude");const N=`${P}//${_}/ws/terminal?${A.toString()}`,E=new WebSocket(N);c.current=E,E.onopen=()=>{E.send(JSON.stringify({type:"resize",cols:u.cols,rows:u.rows}))};let O=!1;E.onmessage=x=>{try{const y=JSON.parse(x.data);if(y.type==="session-id"&&!O){O=!0,setTimeout(()=>{const p=I?`claude "Read the file at '${I.replace(/'/g,"'\\''")}' for your instructions."`:"claude";E.send(JSON.stringify({type:"input",data:p+"\r"}))},300);return}if(y.type==="output"&&y.data){u.write(y.data);return}}catch{u.write(x.data)}},E.onclose=()=>{o.current||u.write(`\r
36
36
  \x1B[90m--- Session ended ---\x1B[0m\r
37
- `)},M.onerror=()=>{h.write(`\r
37
+ `)},E.onerror=()=>{u.write(`\r
38
38
  \x1B[31mConnection error\x1B[0m\r
39
- `)},h.onData(x=>{M.readyState===WebSocket.OPEN&&M.send(JSON.stringify({type:"input",data:x}))}),v=new ResizeObserver(()=>{try{B.fit(),M.readyState===WebSocket.OPEN&&M.send(JSON.stringify({type:"resize",cols:h.cols,rows:h.rows}))}catch{}}),v.observe(m)}return C(),()=>{var j,T;S=!0,o.current=!0,v==null||v.disconnect(),((j=c.current)==null?void 0:j.readyState)===WebSocket.OPEN&&c.current.close(),(T=i.current)==null||T.dispose()}},[]),e.jsxs("div",{className:"border-t border-[#2d2d2d]",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 bg-[#1e1e1e]",children:[e.jsx("span",{className:"text-[10px] font-medium text-[#00a0c4]",children:"Claude"}),n&&e.jsx("button",{onClick:n,className:"text-gray-500 hover:text-gray-300 text-[10px] bg-transparent border-none cursor-pointer",children:"Close"})]}),e.jsx("div",{ref:r,style:{height:s,background:"#1a1a1a",padding:"4px 0",position:"relative",overflow:"hidden"}})]})}const Bt=()=>e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:"text-gray-500 shrink-0",children:e.jsx("path",{d:"M4.5 3L7.5 6L4.5 9",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})});function hn(t,s){if(t.length<=s)return t;const n=s-2;return[t[0],"ellipsis",...t.slice(t.length-n)]}function Ot({items:t,onNavigate:s}){if(t.length===0)return null;const n=hn(t,4);return e.jsx("nav",{className:"flex items-center gap-1 text-xs min-w-0",children:n.map((r,c)=>{if(r==="ellipsis")return e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Bt,{}),e.jsx("span",{className:"text-gray-500",children:"..."})]},"ellipsis");const i=c===n.length-1;return e.jsxs("span",{className:"flex items-center gap-1 min-w-0",children:[c>0&&e.jsx(Bt,{}),i?e.jsx("span",{className:"text-white font-medium truncate",children:r.name}):e.jsx("button",{onClick:()=>s(r.componentName,r.entitySha),className:"text-gray-400 hover:text-white transition-colors cursor-pointer bg-transparent border-none p-0 truncate",children:r.name})]},r.componentName||"app")})})}function Qt(t){var c,i;const s=new Map,n=new Map;for(const o of t)if(o.componentName){const l=n.get(o.componentName)||[];l.push(o),n.set(o.componentName,l)}else if(Xt(o.url)){const l=(c=o.url)==null?void 0:c.match(/[?&]c=([^&]+)/),m=l?decodeURIComponent(l[1]):"Isolated",S=n.get(m)||[];S.push(o),n.set(m,S)}else{const l=o.displayName||((i=o.pageFilePath)!=null&&i.startsWith("app/")?Re($e(o.pageFilePath)):We(o.url)),m=s.get(l)||[];m.push(o),s.set(l,m)}const r=new Map([...n.entries()].sort(([o],[l])=>o.localeCompare(l)));return{pageGroups:s,componentGroups:r}}function fn(t,s){var r,c;const n=new Map;for(const[i,o]of t){const l=(r=o.find(m=>m.entitySha))==null?void 0:r.entitySha;l&&n.set(i,l)}for(const[i,o]of s){const l=(c=o.find(m=>m.entitySha))==null?void 0:c.entitySha;l&&n.set(i,l)}return n}function gn(t){const s=new Set;for(const[n,r]of Object.entries(t)){s.add(n);for(const c of r)s.add(c)}return s}function jn(t,s,n,r){if(s.has(t))return!0;const c=n.find(i=>i.sha===t);return c?r.has(c.name):!1}function bn(t,s,n,r){const c=[];for(const[i,o]of t){const l=n.get(i);l?r(l)||c.push({name:i,scenarios:o,reason:"incomplete"}):c.push({name:i,scenarios:o,reason:"missing"})}for(const[i,o]of s){const l=n.get(i);l?r(l)||c.push({name:i,scenarios:o,reason:"incomplete"}):c.push({name:i,scenarios:o,reason:"missing"})}return c}function yn(t,s,n){if(!t)return null;const r=s.find(c=>c.sha===t);return r?{sha:t,name:r.name,filePath:r.filePath,entityType:r.entityType,displayName:r.name}:null}const zt={new:0,edited:1,impacted:2};function Wt({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],r=s&&(t.status==="edited"||t.status==="impacted");return e.jsx("button",{onClick:r?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 ${r?"cursor-pointer hover:opacity-80 transition-opacity":"cursor-default"}`,children:n.label})}function Ut({filePath:t}){const[s,n]=a.useState(null),[r,c]=a.useState(!0),[i,o]=a.useState(null);return a.useEffect(()=>{it(()=>import("./index-DE3jI_dv.js"),__vite__mapDeps([0,1,2])).then(l=>{o(()=>l.default)})},[]),a.useEffect(()=>{c(!0),fetch(`/api/editor-file-diff?path=${encodeURIComponent(t)}`).then(l=>l.json()).then(l=>{n({oldContent:l.oldContent,newContent:l.newContent})}).catch(()=>{n(null)}).finally(()=>c(!1))},[t]),r?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 Ht({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 Jt({scenarioId:t,name:s,isActive:n,onSelect:r,updatedAt:c}){const i=a.useRef(null);return a.useEffect(()=>{n&&i.current&&i.current.scrollIntoView({block:"nearest",behavior:"smooth"})},[n]),e.jsxs("button",{ref:i,onClick:r,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(Ue,{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 vn({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(ve,{content:t,icon:!0,iconSize:10,className:"shrink-0 text-gray-400 hover:text-gray-600 transition-colors"})]}):null}function ot({testFile:t,entityName:s}){const{results:n,isRunning:r,runTests:c}=lt(t);if(r&&!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(m=>m.fullName.startsWith(s)):n.testCases,o=i.length>0?i:n.testCases;if(o.length===0)return null;const l=s?`${s} > `:"";return e.jsxs("div",{className:"pt-1 space-y-0.5",children:[o.map(m=>{var v;const S=l&&m.fullName.startsWith(l)?m.fullName.slice(l.length):m.fullName;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[m.status==="passed"?e.jsx("span",{className:"text-green-600 text-[10px]",children:"✓"}):m.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] ${m.status==="passed"?"text-green-600":m.status==="failed"?"text-red-500":"text-gray-400"}`,children:S})]}),m.status==="failed"&&((v=m.failureMessages)==null?void 0:v.map((C,j)=>e.jsx("div",{className:"pl-4 text-[9px] text-red-400 truncate max-w-full",title:C,children:C.split(`
40
- `)[0]},j)))]},m.fullName)}),e.jsx("button",{onClick:c,disabled:r,className:"mt-1 text-[10px] text-[#0ea5e9] hover:text-[#38bdf8] transition-colors cursor-pointer disabled:opacity-50 bg-transparent border-none p-0",children:r?"Running...":"Re-run"})]})}function Gt(t){const s=t.indexOf(" - ");return s!==-1?t.slice(s+3):t}function Vt(t,s){return!s||Object.keys(s).length===0?t:[...t].sort(([n],[r])=>{var l,m;const c=((l=s[n])==null?void 0:l.status)||"impacted",i=((m=s[r])==null?void 0:m.status)||"impacted",o=(zt[c]??2)-(zt[i]??2);return o!==0?o:n.localeCompare(r)})}function Nn({scenarios:t,allScenarios:s=[],glossaryFunctions:n=[],projectRoot:r,activeScenarioId:c,onScenarioSelect:i,onClose:o,entityChangeStatus:l={},modifiedFiles:m=[],featureName:S,userPrompt:v}){const C=a.useMemo(()=>{if(s.length===0||Object.keys(l).length===0)return t;const p=new Set(t.map(b=>b.id)),f=s.filter(b=>{var L,F;if(p.has(b.id))return!1;const E=b.componentName||b.displayName||((L=b.pageFilePath)!=null&&L.startsWith("app/")?Re($e(b.pageFilePath)):We(b.url));return((F=l[E])==null?void 0:F.status)==="impacted"});return f.length===0?t:[...t,...f]},[t,s,l]),j=a.useMemo(()=>Object.entries(l).filter(([,p])=>p.status==="new"||p.status==="edited").map(([p,f])=>({name:p,status:f.status})),[l]),[T,h]=a.useState(null),B=a.useCallback(p=>{h(f=>f===p?null:p)},[]),{pageGroups:I,componentGroups:_}=a.useMemo(()=>Qt(C),[C]),D=a.useMemo(()=>Vt([...I.entries()],l),[I,l]),$=a.useMemo(()=>Vt([..._.entries()],l),[_,l]),w=D,M=$,O=a.useMemo(()=>Ks(n,l),[n,l]),x=a.useMemo(()=>{const p=[];for(const[,f]of w)p.push(...f);for(const[,f]of M)p.push(...f);return p},[w,M]),y=a.useRef(!1);return a.useEffect(()=>{y.current||x.length!==0&&(c&&x.some(p=>p.id===c)||(y.current=!0,i(x[0])))},[x,c,i]),a.useEffect(()=>{if(x.length===0)return;const p=f=>{if(f.key!=="ArrowLeft"&&f.key!=="ArrowRight")return;const b=f.target,E=b==null?void 0:b.tagName;if(E==="INPUT"||E==="SELECT"||E==="TEXTAREA"&&!b.classList.contains("xterm-helper-textarea"))return;f.preventDefault();const L=x.findIndex(N=>N.id===c);let F;f.key==="ArrowLeft"?F=L<=0?x.length-1:L-1:F=L>=x.length-1?0:L+1,i(x[F])};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[x,c,i]),C.length===0&&n.length===0?e.jsxs("div",{className:"h-full bg-white flex items-center justify-center relative",children:[e.jsx("button",{onClick:o,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:o,className:"text-gray-400 hover:text-gray-700 text-lg leading-none cursor-pointer bg-transparent border-none shrink-0",title:"Close results",children:"×"})]}),v&&e.jsx(Kt,{text:v,theme:"light"}),e.jsx("div",{className:"flex-1 overflow-auto p-4",children:e.jsxs("div",{className:"space-y-5",children:[w.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:w.map(([p,f])=>{var F;const b=l[p],E=T===p,L=(F=f[0])==null?void 0:F.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:p}),b&&e.jsx(Wt,{status:b,onClick:()=>B(p)})]}),E&&(b==null?void 0:b.status)==="edited"&&L&&e.jsx(Ut,{filePath:L}),E&&(b==null?void 0:b.status)==="impacted"&&e.jsx(Ht,{impactedBy:b.impactedBy,changedEntities:j}),e.jsx("div",{className:"flex flex-wrap gap-3",children:f.map(N=>e.jsx(Jt,{scenarioId:N.id,name:Gt(N.name),isActive:N.id===c,onSelect:()=>i(N),updatedAt:N.updatedAt},N.id))})]},p)})})]}),M.length>0&&e.jsxs("div",{className:w.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:M.map(([p,f])=>{var F;const b=l[p],E=T===p,L=(F=f[0])==null?void 0:F.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:p}),b&&e.jsx(Wt,{status:b,onClick:()=>B(p)})]}),E&&(b==null?void 0:b.status)==="edited"&&L&&e.jsx(Ut,{filePath:L}),E&&(b==null?void 0:b.status)==="impacted"&&e.jsx(Ht,{impactedBy:b.impactedBy,changedEntities:j}),e.jsx("div",{className:"flex flex-wrap gap-3",children:f.map(N=>e.jsx(Jt,{scenarioId:N.id,name:Gt(N.name),isActive:N.id===c,onSelect:()=>i(N),updatedAt:N.updatedAt},N.id))})]},p)})})]}),O.length>0&&e.jsxs("div",{className:w.length>0||M.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:O.map(p=>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:p.name})}),e.jsx(vn,{filePath:p.filePath,projectRoot:r}),p.testFile?e.jsx(ot,{testFile:p.testFile,entityName:p.name}):e.jsx("div",{className:"pt-1",children:e.jsx("span",{className:"text-[10px] text-gray-400",children:"No test file"})})]},p.name))})]}),m.length>0&&e.jsxs("div",{className:w.length>0||M.length>0||O.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 (",m.length,")"]})}),e.jsx("div",{className:"space-y-0.5 pl-1 max-h-[200px] overflow-auto",children:m.map(p=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`text-[9px] font-bold uppercase w-[14px] text-center ${p.status==="added"||p.status==="untracked"?"text-green-600":p.status==="modified"?"text-blue-600":p.status==="renamed"?"text-purple-600":"text-gray-400"}`,children:p.status==="added"||p.status==="untracked"?"A":p.status==="modified"?"M":p.status==="renamed"?"R":"?"}),e.jsx("span",{className:"text-[10px] text-gray-500 truncate font-mono",children:p.path})]},p.path))})]})]})})]})}function wn(t,s,n,r){var m;const c=r.length>0?r.map(S=>`- "${S.name}" (ID: ${S.id})${S.url?` — URL: ${S.url}`:""}`).join(`
41
- `):"(no scenarios yet)",i=s.endsWith("/page.tsx")||s.endsWith("/page.js"),o=((m=r.find(S=>S.url))==null?void 0:m.url)||"/",l=[`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?l.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":"${o}","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":"${o}","dimensions":["Laptop"],"seed":{"user":[...],"feedback":[...]}}`,"SCENARIO_EOF","codeyam editor register @.codeyam/tmp/scenario.json","```"):l.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"}}'`,"```"),l.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":[...]}'`,"```"),l.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."),l.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"}`),l.join(`
39
+ `)},u.onData(x=>{E.readyState===WebSocket.OPEN&&E.send(JSON.stringify({type:"input",data:x}))}),v=new ResizeObserver(()=>{try{B.fit(),E.readyState===WebSocket.OPEN&&E.send(JSON.stringify({type:"resize",cols:u.cols,rows:u.rows}))}catch{}}),v.observe(m)}return k(),()=>{var g,R;w=!0,o.current=!0,v==null||v.disconnect(),((g=c.current)==null?void 0:g.readyState)===WebSocket.OPEN&&c.current.close(),(R=i.current)==null||R.dispose()}},[]),e.jsxs("div",{className:"border-t border-[#2d2d2d]",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 bg-[#1e1e1e]",children:[e.jsx("span",{className:"text-[10px] font-medium text-[#00a0c4]",children:"Claude"}),n&&e.jsx("button",{onClick:n,className:"text-gray-500 hover:text-gray-300 text-[10px] bg-transparent border-none cursor-pointer",children:"Close"})]}),e.jsx("div",{ref:r,style:{height:s,background:"#1a1a1a",padding:"4px 0",position:"relative",overflow:"hidden"}})]})}const Bt=()=>e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:"text-gray-500 shrink-0",children:e.jsx("path",{d:"M4.5 3L7.5 6L4.5 9",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})});function Nn(t,s){if(t.length<=s)return t;const n=s-2;return[t[0],"ellipsis",...t.slice(t.length-n)]}function Ot({items:t,onNavigate:s}){if(t.length===0)return null;const n=Nn(t,4);return e.jsx("nav",{className:"flex items-center gap-1 text-xs min-w-0",children:n.map((r,c)=>{if(r==="ellipsis")return e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Bt,{}),e.jsx("span",{className:"text-gray-500",children:"..."})]},"ellipsis");const i=c===n.length-1;return e.jsxs("span",{className:"flex items-center gap-1 min-w-0",children:[c>0&&e.jsx(Bt,{}),i?e.jsx("span",{className:"text-white font-medium truncate",children:r.name}):e.jsx("button",{onClick:()=>s(r.componentName,r.entitySha),className:"text-gray-400 hover:text-white transition-colors cursor-pointer bg-transparent border-none p-0 truncate",children:r.name})]},r.componentName||"app")})})}function Qt(t){var c,i;const s=new Map,n=new Map;for(const o of t)if(o.componentName){const l=n.get(o.componentName)||[];l.push(o),n.set(o.componentName,l)}else if(Xt(o.url)){const l=(c=o.url)==null?void 0:c.match(/[?&]c=([^&]+)/),m=l?decodeURIComponent(l[1]):"Isolated",w=n.get(m)||[];w.push(o),n.set(m,w)}else{const l=o.displayName||((i=o.pageFilePath)!=null&&i.startsWith("app/")?Ae(Re(o.pageFilePath)):We(o.url)),m=s.get(l)||[];m.push(o),s.set(l,m)}const r=new Map([...n.entries()].sort(([o],[l])=>o.localeCompare(l)));return{pageGroups:s,componentGroups:r}}function wn(t,s){var r,c;const n=new Map;for(const[i,o]of t){const l=(r=o.find(m=>m.entitySha))==null?void 0:r.entitySha;l&&n.set(i,l)}for(const[i,o]of s){const l=(c=o.find(m=>m.entitySha))==null?void 0:c.entitySha;l&&n.set(i,l)}return n}function Sn(t){const s=new Set;for(const[n,r]of Object.entries(t)){s.add(n);for(const c of r)s.add(c)}return s}function kn(t,s,n,r){if(s.has(t))return!0;const c=n.find(i=>i.sha===t);return c?r.has(c.name):!1}function Cn(t,s,n,r){const c=[];for(const[i,o]of t){const l=n.get(i);l?r(l)||c.push({name:i,scenarios:o,reason:"incomplete"}):c.push({name:i,scenarios:o,reason:"missing"})}for(const[i,o]of s){const l=n.get(i);l?r(l)||c.push({name:i,scenarios:o,reason:"incomplete"}):c.push({name:i,scenarios:o,reason:"missing"})}return c}function Pn(t,s,n){if(!t)return null;const r=s.find(c=>c.sha===t);return r?{sha:t,name:r.name,filePath:r.filePath,entityType:r.entityType,displayName:r.name}:null}const zt={new:0,edited:1,impacted:2};function Wt({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],r=s&&(t.status==="edited"||t.status==="impacted");return e.jsx("button",{onClick:r?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 ${r?"cursor-pointer hover:opacity-80 transition-opacity":"cursor-default"}`,children:n.label})}function Ut({filePath:t}){const[s,n]=a.useState(null),[r,c]=a.useState(!0),[i,o]=a.useState(null);return a.useEffect(()=>{it(()=>import("./index-DE3jI_dv.js"),__vite__mapDeps([0,1,2])).then(l=>{o(()=>l.default)})},[]),a.useEffect(()=>{c(!0),fetch(`/api/editor-file-diff?path=${encodeURIComponent(t)}`).then(l=>l.json()).then(l=>{n({oldContent:l.oldContent,newContent:l.newContent})}).catch(()=>{n(null)}).finally(()=>c(!1))},[t]),r?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 Ht({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 Jt({scenarioId:t,name:s,isActive:n,onSelect:r,updatedAt:c}){const i=a.useRef(null);return a.useEffect(()=>{n&&i.current&&i.current.scrollIntoView({block:"nearest",behavior:"smooth"})},[n]),e.jsxs("button",{ref:i,onClick:r,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(Ue,{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 En({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(ve,{content:t,icon:!0,iconSize:10,className:"shrink-0 text-gray-400 hover:text-gray-600 transition-colors"})]}):null}function ot({testFile:t,entityName:s}){const{results:n,isRunning:r,runTests:c}=lt(t);if(r&&!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(m=>m.fullName.startsWith(s)):n.testCases,o=i.length>0?i:n.testCases;if(o.length===0)return null;const l=s?`${s} > `:"";return e.jsxs("div",{className:"pt-1 space-y-0.5",children:[o.map(m=>{var v;const w=l&&m.fullName.startsWith(l)?m.fullName.slice(l.length):m.fullName;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[m.status==="passed"?e.jsx("span",{className:"text-green-600 text-[10px]",children:"✓"}):m.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] ${m.status==="passed"?"text-green-600":m.status==="failed"?"text-red-500":"text-gray-400"}`,children:w})]}),m.status==="failed"&&((v=m.failureMessages)==null?void 0:v.map((k,g)=>e.jsx("div",{className:"pl-4 text-[9px] text-red-400 truncate max-w-full",title:k,children:k.split(`
40
+ `)[0]},g)))]},m.fullName)}),e.jsx("button",{onClick:c,disabled:r,className:"mt-1 text-[10px] text-[#0ea5e9] hover:text-[#38bdf8] transition-colors cursor-pointer disabled:opacity-50 bg-transparent border-none p-0",children:r?"Running...":"Re-run"})]})}function Gt(t){const s=t.indexOf(" - ");return s!==-1?t.slice(s+3):t}function Vt(t,s){return!s||Object.keys(s).length===0?t:[...t].sort(([n],[r])=>{var l,m;const c=((l=s[n])==null?void 0:l.status)||"impacted",i=((m=s[r])==null?void 0:m.status)||"impacted",o=(zt[c]??2)-(zt[i]??2);return o!==0?o:n.localeCompare(r)})}function Mn({scenarios:t,allScenarios:s=[],glossaryFunctions:n=[],projectRoot:r,activeScenarioId:c,onScenarioSelect:i,onClose:o,entityChangeStatus:l={},modifiedFiles:m=[],featureName:w,userPrompt:v}){const k=a.useMemo(()=>{if(s.length===0||Object.keys(l).length===0)return t;const p=new Set(t.map(b=>b.id)),f=s.filter(b=>{var D,F;if(p.has(b.id))return!1;const T=b.componentName||b.displayName||((D=b.pageFilePath)!=null&&D.startsWith("app/")?Ae(Re(b.pageFilePath)):We(b.url));return((F=l[T])==null?void 0:F.status)==="impacted"});return f.length===0?t:[...t,...f]},[t,s,l]),g=a.useMemo(()=>Object.entries(l).filter(([,p])=>p.status==="new"||p.status==="edited").map(([p,f])=>({name:p,status:f.status})),[l]),[R,u]=a.useState(null),B=a.useCallback(p=>{u(f=>f===p?null:p)},[]),{pageGroups:I,componentGroups:P}=a.useMemo(()=>Qt(k),[k]),_=a.useMemo(()=>Vt([...I.entries()],l),[I,l]),A=a.useMemo(()=>Vt([...P.entries()],l),[P,l]),N=_,E=A,O=a.useMemo(()=>Ks(n,l),[n,l]),x=a.useMemo(()=>{const p=[];for(const[,f]of N)p.push(...f);for(const[,f]of E)p.push(...f);return p},[N,E]),y=a.useRef(!1);return a.useEffect(()=>{y.current||x.length!==0&&(c&&x.some(p=>p.id===c)||(y.current=!0,i(x[0])))},[x,c,i]),a.useEffect(()=>{if(x.length===0)return;const p=f=>{if(f.key!=="ArrowLeft"&&f.key!=="ArrowRight")return;const b=f.target,T=b==null?void 0:b.tagName;if(T==="INPUT"||T==="SELECT"||T==="TEXTAREA"&&!b.classList.contains("xterm-helper-textarea"))return;f.preventDefault();const D=x.findIndex(S=>S.id===c);let F;f.key==="ArrowLeft"?F=D<=0?x.length-1:D-1:F=D>=x.length-1?0:D+1,i(x[F])};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[x,c,i]),k.length===0&&n.length===0?e.jsxs("div",{className:"h-full bg-white flex items-center justify-center relative",children:[e.jsx("button",{onClick:o,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"}),w&&e.jsx("div",{className:"text-[11px] text-gray-400 truncate",title:w,children:w})]}),e.jsx("button",{onClick:o,className:"text-gray-400 hover:text-gray-700 text-lg leading-none cursor-pointer bg-transparent border-none shrink-0",title:"Close results",children:"×"})]}),v&&e.jsx(Kt,{text:v,theme:"light"}),e.jsx("div",{className:"flex-1 overflow-auto p-4",children:e.jsxs("div",{className:"space-y-5",children:[N.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:N.map(([p,f])=>{var F;const b=l[p],T=R===p,D=(F=f[0])==null?void 0:F.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:p}),b&&e.jsx(Wt,{status:b,onClick:()=>B(p)})]}),T&&(b==null?void 0:b.status)==="edited"&&D&&e.jsx(Ut,{filePath:D}),T&&(b==null?void 0:b.status)==="impacted"&&e.jsx(Ht,{impactedBy:b.impactedBy,changedEntities:g}),e.jsx("div",{className:"flex flex-wrap gap-3",children:f.map(S=>e.jsx(Jt,{scenarioId:S.id,name:Gt(S.name),isActive:S.id===c,onSelect:()=>i(S),updatedAt:S.updatedAt},S.id))})]},p)})})]}),E.length>0&&e.jsxs("div",{className:N.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:E.map(([p,f])=>{var F;const b=l[p],T=R===p,D=(F=f[0])==null?void 0:F.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:p}),b&&e.jsx(Wt,{status:b,onClick:()=>B(p)})]}),T&&(b==null?void 0:b.status)==="edited"&&D&&e.jsx(Ut,{filePath:D}),T&&(b==null?void 0:b.status)==="impacted"&&e.jsx(Ht,{impactedBy:b.impactedBy,changedEntities:g}),e.jsx("div",{className:"flex flex-wrap gap-3",children:f.map(S=>e.jsx(Jt,{scenarioId:S.id,name:Gt(S.name),isActive:S.id===c,onSelect:()=>i(S),updatedAt:S.updatedAt},S.id))})]},p)})})]}),O.length>0&&e.jsxs("div",{className:N.length>0||E.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:O.map(p=>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:p.name})}),e.jsx(En,{filePath:p.filePath,projectRoot:r}),p.testFile?e.jsx(ot,{testFile:p.testFile,entityName:p.name}):e.jsx("div",{className:"pt-1",children:e.jsx("span",{className:"text-[10px] text-gray-400",children:"No test file"})})]},p.name))})]}),m.length>0&&e.jsxs("div",{className:N.length>0||E.length>0||O.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 (",m.length,")"]})}),e.jsx("div",{className:"space-y-0.5 pl-1 max-h-[200px] overflow-auto",children:m.map(p=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`text-[9px] font-bold uppercase w-[14px] text-center ${p.status==="added"||p.status==="untracked"?"text-green-600":p.status==="modified"?"text-blue-600":p.status==="renamed"?"text-purple-600":"text-gray-400"}`,children:p.status==="added"||p.status==="untracked"?"A":p.status==="modified"?"M":p.status==="renamed"?"R":"?"}),e.jsx("span",{className:"text-[10px] text-gray-500 truncate font-mono",children:p.path})]},p.path))})]})]})})]})}function Tn(t,s,n,r){var m;const c=r.length>0?r.map(w=>`- "${w.name}" (ID: ${w.id})${w.url?` — URL: ${w.url}`:""}`).join(`
41
+ `):"(no scenarios yet)",i=s.endsWith("/page.tsx")||s.endsWith("/page.js"),o=((m=r.find(w=>w.url))==null?void 0:m.url)||"/",l=[`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?l.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":"${o}","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":"${o}","dimensions":["Laptop"],"seed":{"user":[...],"feedback":[...]}}`,"SCENARIO_EOF","codeyam editor register @.codeyam/tmp/scenario.json","```"):l.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"}}'`,"```"),l.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":[...]}'`,"```"),l.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."),l.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"}`),l.join(`
42
42
  `)}function Zt(t,s){var c;const n=s.some(i=>!i.componentName),r=s.map(i=>`'${i.id}'`).join(", ");if(n){const i=((c=s.find(l=>l.url))==null?void 0:c.url)||null,o=s.map(l=>`.codeyam/editor-scenarios/${l.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 (${r});"`,"","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 (${r});"`,"","Step E: Add pageFilePath to the scenario JSON files so this fix persists across clones.",`For each file (${o}), read it and add \`"pageFilePath": "PAGE_FILE_PATH"\` to the \`_metadata\` object (after the \`"type"\` field). Then commit the updated JSON files.`].join(`
43
43
  `)}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 (${r});"`].join(`
44
44
  `)}function qt({name:t,scenarios:s,reason:n="missing"}){var i,o;const r=((i=s[0])==null?void 0:i.componentPath)||((o=s[0])==null?void 0:o.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": "${r||"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(`
45
45
  `):[`The "${t}" ${s.some(l=>!l.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:","",Zt(t,s),"","Step 3: Reload the editor page in the browser and verify the scenarios appear."].join(`
46
- `);return e.jsx(ve,{content:c,label:"Copy Fix Prompt",copiedLabel:"Copied!",className:"text-[9px] text-amber-400 hover:text-amber-300 bg-transparent border border-amber-400/30 rounded px-1.5 py-0.5 cursor-pointer transition-colors ml-2"})}function Sn({brokenEntities:t}){if(t.length===0)return null;const s=t.reduce((i,o)=>i+o.scenarios.length,0),n=t.filter(i=>i.reason==="incomplete"),r=t.filter(i=>i.reason==="missing"),c=[`${t.length} entities are missing data in the CodeYam database. ${s} 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:","",...n.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:","",...n.map(i=>{var l,m;const o=((l=i.scenarios[0])==null?void 0:l.componentPath)||((m=i.scenarios[0])==null?void 0:m.pageFilePath)||"FILL_IN_PATH";return`- "${i.name}" (filePath: "${o}")`}),"",'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","",...r.length>0?["## Step 3: Fix missing entity associations","",...r.map(i=>Zt(i.name,i.scenarios)),""]:[],`## Step ${r.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(`
47
- `);return e.jsxs("div",{className:"mb-3 p-2 rounded border border-amber-400/30 bg-amber-400/5",children:[e.jsxs("p",{className:"text-[10px] text-amber-400/80 m-0 leading-relaxed",children:[t.length," ",t.length===1?"entity is":"entities are"," missing data (",s," hidden scenario",s!==1?"s":"","). Copy this prompt into Claude to fix them all at once."]}),e.jsx("div",{className:"mt-1.5",children:e.jsx(ve,{content:c,label:"Copy Fix All Prompt",copiedLabel:"Copied!",className:"text-[9px] text-amber-400 hover:text-amber-300 bg-transparent border border-amber-400/30 rounded px-1.5 py-0.5 cursor-pointer transition-colors"})})]})}function kn({scenarios:t,entityName:s,entityFilePath:n,entityType:r,onSwitchToBuild:c,onScenarioSelect:i}){const[o,l]=a.useState(!1),[m,S]=a.useState(null),[v,C]=a.useState(""),[j,T]=a.useState(!1),[h,B]=a.useState(null),[I,_]=a.useState(!1),D=a.useCallback(async w=>{if(!(!v.trim()||j)){T(!0);try{(await fetch("/api/editor-rename-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioId:w,name:v.trim()})})).ok&&S(null)}catch{}finally{T(!1)}}},[v,j]),$=a.useCallback(async w=>{if(confirm(`Delete scenario "${w.name}"?`)){B(w.id);try{const M=w.screenshotPaths?Object.values(w.screenshotPaths):w.screenshotPath?[w.screenshotPath]:[];await fetch("/api/delete-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioId:w.id,screenshotPaths:M})})}catch{}finally{B(null)}}},[]);return o?e.jsxs("div",{className:"border border-[#3d3d3d] rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 bg-[#1e1e1e]",children:[e.jsx("span",{className:"text-xs font-medium text-gray-400",children:"Edit Scenarios"}),e.jsx("button",{onClick:()=>{l(!1),S(null)},className:"text-gray-500 hover:text-gray-300 text-xs bg-transparent border-none cursor-pointer",children:"Close"})]}),e.jsx("div",{className:"divide-y divide-[#2d2d2d]",children:t.map(w=>e.jsxs("div",{className:"px-3 py-2 flex items-center gap-2 hover:bg-[#252525] cursor-pointer transition-colors",style:{opacity:h===w.id?.4:1},onClick:()=>{m!==w.id&&i(w)},children:[w.screenshotPath?e.jsx(Ue,{scenarioId:w.id,updatedAt:w.updatedAt,alt:"",className:"rounded w-[40px] h-[40px] shrink-0 overflow-hidden",imgClassName:"w-full h-full object-cover"}):e.jsx("div",{className:"rounded bg-[#1e1e1e]",style:{width:40,height:40,flexShrink:0}}),m===w.id?e.jsxs("form",{className:"flex-1 flex items-center gap-1.5 min-w-0",onSubmit:M=>{M.preventDefault(),D(w.id)},children:[e.jsx("input",{type:"text",value:v,onChange:M=>C(M.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:j}),e.jsx("button",{type:"submit",disabled:j||!v.trim(),className:"px-2 py-1 text-[10px] bg-[#005c75] text-white rounded hover:bg-[#004d63] disabled:opacity-40 cursor-pointer border-none",children:j?"...":"Save"}),e.jsx("button",{type:"button",onClick:()=>S(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:"flex-1 text-xs text-gray-300 truncate min-w-0",children:w.name}),e.jsx("button",{onClick:M=>{M.stopPropagation(),S(w.id),C(w.name)},className:"text-[10px] text-gray-500 hover:text-gray-300 cursor-pointer bg-transparent border-none px-1",title:"Rename",children:"Rename"}),e.jsx("button",{onClick:M=>{M.stopPropagation(),$(w)},disabled:h===w.id,className:"text-[10px] text-red-400/60 hover:text-red-400 cursor-pointer bg-transparent border-none px-1",title:"Delete",children:"Delete"})]})]},w.id))}),I?e.jsx(un,{prompt:wn(s,n,r,t),height:500,onClose:()=>_(!1)}):e.jsx("div",{className:"px-3 py-2.5 bg-[#1e1e1e] border-t border-[#2d2d2d] flex justify-center",children:e.jsx("button",{onClick:()=>_(!0),className:"px-5 py-2 text-xs font-medium text-white cursor-pointer bg-[#005c75] hover:bg-[#004d63] border-none rounded-md transition-colors",children:"Modify with Claude"})})]}):e.jsx("div",{className:"flex justify-center",children:e.jsx("button",{onClick:()=>l(!0),className:"px-5 py-2 text-xs font-medium text-gray-300 hover:text-white transition-colors cursor-pointer bg-[#2a2a2a] hover:bg-[#333] border border-[#4a4a4a] hover:border-[#666] rounded-md",children:"Edit Scenarios"})})}function ye({scenarioId:t,updatedAt:s,hasScreenshot:n,imgSrc:r,name:c,isActive:i,onSelect:o}){const l=t&&n,m=!t&&r;return e.jsxs("button",{onClick:o,className:"flex flex-col items-center gap-1 cursor-pointer group w-full",title:c,children:[e.jsx("div",{className:`w-full aspect-square rounded overflow-hidden border-2 transition-all bg-[#1a1a1a] ${i?"border-[#005c75] ring-1 ring-[#005c75]":"border-transparent hover:border-[#4d4d4d]"}`,children:l?e.jsx(Ue,{scenarioId:t,updatedAt:s,alt:c,className:"w-full h-full",imgClassName:"w-full h-full object-contain"}):m?e.jsx("img",{src:r,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 Te({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-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(ve,{content:t,icon:!0,iconSize:10,className:"shrink-0 text-gray-500 hover:text-gray-300 transition-colors"})]}):null}function Cn({hasProject:t,scenarios:s,analyzedEntities:n,allEntities:r=[],glossaryFunctions:c=[],glossaryEntries:i=[],projectRoot:o,activeScenarioId:l,onScenarioSelect:m,onAnalyzedScenarioSelect:S,onSwitchToBuild:v,zoomComponent:C,focusedEntity:j,onZoomChange:T,entityImports:h,pageFilePaths:B={},projectTitle:I,projectDescription:_,migrationMode:D="none",migrationState:$,onStartMigration:w,breadcrumbItems:M=[]}){var te;const{pageGroups:O,componentGroups:x}=a.useMemo(()=>Qt(s),[s]),y=a.useMemo(()=>fn(O,x),[O,x]),p=a.useMemo(()=>new Set(n.map(k=>k.sha)),[n]),f=a.useMemo(()=>gn(h||{}),[h]),b=a.useCallback(k=>jn(k,p,r,f),[p,r,f]),E=a.useMemo(()=>{const k=new Map;for(const R of r)k.set(R.sha,R.name);return k},[r]),L=a.useMemo(()=>bn(O,x,y,b),[O,x,y,b]),F=a.useMemo(()=>n.filter(k=>k.entityType==="visual").sort((k,R)=>k.name.localeCompare(R.name)),[n]),N=a.useMemo(()=>{const k=new Map;for(const R of c)k.set(R.name,R);return k},[c]),J=a.useRef(null),xe=a.useRef(0),Ne=a.useCallback(()=>{J.current&&(xe.current=J.current.scrollTop)},[]);a.useEffect(()=>{J.current&&xe.current>0&&(J.current.scrollTop=xe.current)});const we=(j==null?void 0:j.sha)??"overview";if(!t)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx("h2",{className:"text-lg font-medium text-white font-['IBM_Plex_Sans'] m-0",children:"Ready to build something?"}),e.jsx("button",{onClick:v,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(D==="candidate")return e.jsx("div",{className:"flex-1 flex items-center justify-center",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 font-['IBM_Plex_Sans'] m-0",children:"Migrate Your Project"}),e.jsx("p",{className:"text-sm text-gray-400 m-0 font-['IBM_Plex_Sans'] 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:w,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:v,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(D==="active"&&$){const k=$.pages||[],R=k.filter(A=>A.status==="complete").length,G=k.length,V=G>0?Math.round(R/G*100):0;return e.jsxs("div",{className:"flex-1 flex flex-col overflow-auto p-4",children:[e.jsx("h2",{className:"text-lg font-medium text-white font-['IBM_Plex_Sans'] 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 font-['IBM_Plex_Sans']",children:[R,"/",G," pages (",V,"%)"]})}),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:`${V}%`}})})]}),e.jsx("div",{className:"space-y-1.5",children:k.map((A,se)=>{const ae=A.status==="complete"?"✓":A.status==="in-progress"?"→":"○",q=A.status==="complete"?"text-green-400":A.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 ${q} w-3 text-center`,children:ae}),e.jsx("span",{className:`text-xs font-['IBM_Plex_Sans'] ${A.status==="in-progress"?"text-white font-medium":A.status==="complete"?"text-gray-400":"text-gray-600"}`,children:A.name}),e.jsx("span",{className:"text-[10px] text-gray-600",children:A.route}),A.status==="complete"&&e.jsxs("span",{className:"text-[10px] text-gray-600",children:[(A.extractedComponents||[]).length,"c"," ",(A.extractedFunctions||[]).length,"f"," ",A.scenarioCount||0,"s"]})]},se)})}),($.sharedComponents||[]).length>0&&e.jsxs("div",{className:"mt-4",children:[e.jsx("h3",{className:"text-xs font-medium text-gray-400 font-['IBM_Plex_Sans'] mb-1.5",children:"Shared Components"}),($.sharedComponents||[]).map((A,se)=>e.jsxs("div",{className:"text-[10px] text-gray-500 mb-0.5",children:[A.name," ",e.jsxs("span",{className:"text-gray-600",children:["— used in: ",(A.usedInPages||[]).join(", ")]})]},se))]}),e.jsx("div",{className:"mt-4",children:e.jsx("button",{onClick:v,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"})})]})}if(!(s.length>0||F.length>0))return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-4 px-8 text-center",children:[I?e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-lg font-medium text-white font-['IBM_Plex_Sans'] m-0",children:I}),_&&e.jsx("p",{className:"text-sm text-gray-400 m-0 font-['IBM_Plex_Sans'] leading-relaxed",children:_})]}):e.jsx("h2",{className:"text-lg font-medium text-white font-['IBM_Plex_Sans'] m-0",children:"Your project is ready"}),e.jsx("p",{className:"text-sm text-gray-400 m-0 font-['IBM_Plex_Sans'] leading-relaxed",children:"Describe what you want to build in the Chat and your pages and components will appear here."}),e.jsx("button",{onClick:v,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(j){const k=j.filePath,R=j.name,G=n.some(u=>u.sha===j.sha||u.filePath===k),V=!!((te=h==null?void 0:h[R])!=null&&te.length);if(!G&&!V){s.some(z=>z.componentName===R&&z.entitySha===j.sha);const u=s.filter(z=>z.entitySha===j.sha),U=[`The "${j.displayName}" entity (${k}) 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 "${R}" to the glossary if it's not already there:`,` Check: cat .codeyam/glossary.json | grep "${R}"`,"",` If not found, add an entry with name "${R}" and filePath "${k}" 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(`
48
- `);return e.jsx("div",{ref:J,onScroll:Ne,className:"flex-1 overflow-auto",children:e.jsxs("div",{className:"p-4 space-y-3",children:[e.jsx(Ot,{items:M,onNavigate:T}),e.jsx("h2",{className:"text-sm font-semibold text-white m-0 font-['IBM_Plex_Sans'] uppercase tracking-wider",children:j.displayName}),k&&e.jsx(Te,{filePath:k,projectRoot:o}),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(ve,{content:U,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(z=>e.jsx(ye,{scenarioId:z.id,updatedAt:z.updatedAt,hasScreenshot:!!z.screenshotPath,name:z.name,isActive:z.id===l,onSelect:()=>m(z)},z.id))})]})},we)}const A=j.sha,se=s.filter(u=>!u.componentName&&(u.pageFilePath===k||A&&u.entitySha===A)),ae=s.filter(u=>u.componentName===R||u.componentPath===k),q=F.find(u=>u.filePath===k||u.name===R),re=N.get(R)||c.find(u=>u.filePath===k),ie=[...se,...ae],oe=new Set((h==null?void 0:h[R])||[]),ke=V?[...x.entries()].filter(([u])=>oe.has(u)):[],Ae=V?F.filter(u=>oe.has(u.name)&&!ke.some(([U])=>U===u.name)):[],Le=V?i.filter(u=>oe.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})):[],le=ke.length>0||Ae.length>0,ee=Le.length>0,Y=le||ee;return e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsxs("div",{className:"p-4 space-y-3",children:[e.jsx(Ot,{items:M,onNavigate:T}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-semibold text-white m-0 font-['IBM_Plex_Sans'] uppercase tracking-wider",children:j.displayName}),j.filePath&&e.jsx(Te,{filePath:j.filePath,projectRoot:o})]}),ie.length>0&&e.jsx("div",{className:"grid grid-cols-3 gap-2",children:ie.map(u=>e.jsx(ye,{scenarioId:u.id,updatedAt:u.updatedAt,hasScreenshot:!!u.screenshotPath,name:u.name,isActive:u.id===l,onSelect:()=>m(u)},u.id))}),q&&(q.scenarios.length>0||q.pendingScenarios.length>0)&&e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[q.scenarios.map(u=>e.jsx(ye,{imgSrc:u.screenshotPath?`/api/screenshot/${u.screenshotPath}`:null,name:u.name,isActive:!1,onSelect:()=>S({analysisId:q.analysisId,scenarioId:u.id,scenarioName:u.name,entitySha:q.sha,entityName:q.name})},u.id)),q.pendingScenarios.map(u=>e.jsx("div",{className:"px-2.5 py-1 bg-[#2a2a2a] text-gray-400 text-[10px] rounded-full",title:u,children:u},u))]}),re&&re.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(Te,{filePath:re.testFile,projectRoot:o})]}),e.jsx(ot,{testFile:re.testFile,entityName:R})]}),ie.length===0&&!q&&!re&&e.jsx("div",{className:"text-xs text-gray-500",children:"No scenarios for this entity"}),ie.length>0&&e.jsx(kn,{scenarios:ie,entityName:j.displayName,entityFilePath:j.filePath,entityType:j.entityType,onSwitchToBuild:v,onScenarioSelect:m}),Y&&e.jsxs("div",{className:"pt-3 mt-2 border-t border-[#3d3d3d] space-y-3",children:[le&&e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:"Components"}),ke.map(([u,U])=>e.jsx("div",{className:"mt-3",children:y.has(u)?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"py-1",children:e.jsx("button",{onClick:()=>T(u,y.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})}),U.length>0&&e.jsx("div",{className:"grid grid-cols-3 gap-2 pt-1",children:U.map(z=>e.jsx(ye,{scenarioId:z.id,updatedAt:z.updatedAt,hasScreenshot:!!z.screenshotPath,name:z.name,isActive:z.id===l,onSelect:()=>m(z)},z.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(qt,{name:u,scenarios:U})})]})},u)),Ae.map(u=>e.jsxs("div",{className:"mt-3",children:[e.jsx("div",{className:"py-1",children:e.jsx("button",{onClick:()=>T(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(U=>e.jsx(ye,{imgSrc:U.screenshotPath?`/api/screenshot/${U.screenshotPath}`:null,name:U.name,isActive:!1,onSelect:()=>S({analysisId:u.analysisId,scenarioId:U.id,scenarioName:U.name,entitySha:u.sha,entityName:u.name})},U.id)),u.pendingScenarios.map(U=>e.jsx("div",{className:"px-2.5 py-1 bg-[#2a2a2a] text-gray-400 text-[10px] rounded-full",title:U,children:U},U))]})]},u.sha))]}),ee&&e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:"Functions"}),Le.map(u=>e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"py-1",children:e.jsx("button",{onClick:()=>T(u.name,y.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(Te,{filePath:u.filePath,projectRoot:o}),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(ot,{testFile:u.testFile,entityName:u.name})]})]},u.name))]})]})]})})}return e.jsx("div",{ref:J,onScroll:Ne,className:"flex-1 overflow-auto",children:e.jsxs("div",{className:"p-4 space-y-4",children:[I&&e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-white m-0 font-['IBM_Plex_Sans']",children:I}),_&&e.jsx("p",{className:"text-xs text-gray-400 m-0 mt-1 font-['IBM_Plex_Sans'] leading-relaxed",children:_})]}),L.length>1&&e.jsx(Sn,{brokenEntities:L}),O.size>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:"Application"}),e.jsx("button",{onClick:v,className:"px-2.5 py-1 text-[10px] font-medium text-gray-400 bg-[#2a2a2a] border border-[#4d4d4d] rounded hover:bg-[#333] hover:text-white hover:border-[#005c75] transition-colors cursor-pointer",children:"+ New Page"})]}),e.jsxs("p",{className:"text-[11px] text-gray-500 m-0 mt-1.5 font-['IBM_Plex_Sans'] leading-relaxed",children:["Select a page scenario below and switch to"," ",e.jsx("button",{onClick:v,className:"text-[#00a0c4] hover:text-[#00c4eb] bg-transparent border-none p-0 cursor-pointer underline font-inherit text-inherit",children:"Build"})," ","to change or enhance an existing page or"," ",e.jsx("button",{onClick:v,className:"text-[#00a0c4] hover:text-[#00c4eb] bg-transparent border-none p-0 cursor-pointer underline font-inherit text-inherit",children:"create a new page"})]}),[...O.entries()].sort(([k],[R])=>k==="Home"?-1:R==="Home"?1:k.localeCompare(R)).map(([k,R])=>{var G,V;return e.jsx("div",{className:"mt-2",children:y.has(k)&&b(y.get(k))?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"py-1",children:(()=>{const A=y.get(k),ae=(A?E.get(A):void 0)||k;return e.jsx("button",{onClick:()=>T(k,y.get(k)),className:"text-[11px] font-medium text-gray-400 cursor-pointer hover:text-white transition-colors bg-transparent border-none p-0",children:ae})})()}),(((G=R[0])==null?void 0:G.pageFilePath)||B[k])&&e.jsx(Te,{filePath:((V=R[0])==null?void 0:V.pageFilePath)||B[k],projectRoot:o}),e.jsx("div",{className:"grid grid-cols-3 gap-2 pt-1",children:R.map(A=>e.jsx(ye,{scenarioId:A.id,updatedAt:A.updatedAt,hasScreenshot:!!A.screenshotPath,name:A.name,isActive:A.id===l,onSelect:()=>m(A)},A.id))})]}):e.jsxs("div",{className:"py-2",children:[e.jsx("span",{className:"text-[11px] font-medium text-gray-500",children:(()=>{const A=y.get(k);return A&&E.get(A)||k})()}),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 page. 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(qt,{name:k,scenarios:R,reason:y.has(k)?"incomplete":"missing"})})]})},k)})]})]})},we)}const Pn=[{key:"app",label:"App"},{key:"build",label:"Build"},{key:"data",label:"Structure"},{key:"journal",label:"Journal"}];function En({activeTab:t,onTabChange:s,buildIdle:n}){return e.jsxs("div",{className:"bg-[#3d3d3d] h-10 flex items-center px-3 gap-3 shrink-0 z-20 border-b border-[#2d2d2d]",children:[e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("img",{src:Ys,alt:"CodeYam",className:"h-5 brightness-0 invert"}),e.jsx("span",{className:"text-white font-medium text-xs whitespace-nowrap",children:"Codeyam Editor"})]}),e.jsx("div",{className:"flex-1"}),e.jsx("div",{className:"flex items-center gap-2 shrink-0",children:e.jsx("div",{className:"flex items-center gap-0.5 bg-[#4a3232] rounded-lg p-0.5",children:Pn.map(r=>e.jsxs("button",{onClick:()=>s(r.key),className:`px-2.5 py-1 text-xs font-medium rounded-md transition-colors cursor-pointer ${t===r.key?"bg-[#7a4444] text-white":"text-gray-300 hover:text-white"}`,children:[r.label,r.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"})]},r.key))})})]})}function Mn({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 Yt=300,Oe=150;function In(t){const[s,n]=a.useState(null),[r,c]=a.useState(!1),i=a.useRef(0),o=a.useRef(null);a.useEffect(()=>{t.current&&n(Math.round(t.current.offsetWidth*.5))},[t]);const l=a.useCallback(()=>{var I;return((I=t.current)==null?void 0:I.offsetWidth)??(typeof window<"u"?window.innerWidth:1024)},[t]),m=a.useCallback(I=>{I.preventDefault(),c(!0)},[]),S=a.useCallback(()=>{n(Math.round(l()*.5))},[l]),v=a.useCallback(()=>{n(I=>(I&&I>0&&(o.current=I),0))},[]),C=a.useCallback(()=>{const I=o.current;o.current=null,n(I&&I>=Yt?I:Math.round(l()*.5))},[l]),j=a.useCallback(()=>{n(Math.round(l()*.5))},[l]);a.useEffect(()=>{if(!r)return;document.body.style.cursor="col-resize",document.body.style.userSelect="none";const I=D=>{cancelAnimationFrame(i.current),i.current=requestAnimationFrame(()=>{var p;const $=(p=t.current)==null?void 0:p.getBoundingClientRect(),w=($==null?void 0:$.left)??0,O=(($==null?void 0:$.width)??window.innerWidth)-Oe,x=D.clientX-w,y=Math.min(Math.max(x,Yt),O);n(y)})},_=D=>{var x;cancelAnimationFrame(i.current),c(!1);const $=(x=t.current)==null?void 0:x.getBoundingClientRect(),w=($==null?void 0:$.left)??0,M=($==null?void 0:$.width)??window.innerWidth,O=D.clientX-w;O<Oe?n(0):M-O<Oe&&n(M)};return document.addEventListener("mousemove",I),document.addEventListener("mouseup",_),()=>{cancelAnimationFrame(i.current),document.removeEventListener("mousemove",I),document.removeEventListener("mouseup",_),document.body.style.cursor="",document.body.style.userSelect=""}},[r,t]),a.useEffect(()=>{const I=()=>{n(_=>{if(_===null||_===0)return _;const D=l();return _>=D?D:Math.min(_,D-Oe)})};if(!(typeof window>"u"))return window.addEventListener("resize",I),()=>window.removeEventListener("resize",I)},[l]);const T=l(),h=s===0,B=s!==null&&s>=T;return{editorWidth:s,isDragging:r,isEditorCollapsed:h,isPreviewCollapsed:B,handleMouseDown:m,handleDoubleClick:S,collapseEditor:v,expandEditor:C,expandPreview:j}}function Tn({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($n,{commitSha:t.commitSha,onLoadCommit:n})})]})}function $n({commitSha:t,onLoadCommit:s}){const[n,r]=a.useState(!1),[c,i]=a.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{r(!0),i(null),s(t).then(o=>{o.success||i(o.error||"Failed to load commit")}).catch(o=>{i(o instanceof Error?o.message:"Network error")}).finally(()=>r(!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 Rn({analysisId:t,scenarioId:s,scenarioName:n,entityName:r,projectSlug:c,onStateChange:i}){const{interactiveServerUrl:o,isStarting:l,isLoading:m}=Xs({analysisId:t,scenarioId:s,scenarioName:n,entityName:r,projectSlug:c,enabled:!0});return a.useEffect(()=>{i(o,l||m)},[o,l,m,i]),null}function An({onSaveToCurrent:t,onSaveAsNew:s,onDismiss:n,isSaving:r,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:r,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:r?"Saving...":"Save to Scenario"}),e.jsx("button",{onClick:s,disabled:r,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:r,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 Ln(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 _n(t){const[s,n]=a.useState({url:null,proxyUrl:null,isStarting:!1,error:null,canStartServer:!0,autoStartAttempted:!1}),r=a.useRef(s);r.current=s,a.useEffect(()=>{let o=!1,l=null;const m=async()=>{try{const S=await fetch("/api/editor-dev-server");if(o)return;const v=await S.json(),C=Ln(r.current,v),{shouldAutoStart:j,...T}=C;if(n(T),j&&!(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(o)return;h.ok?n(B=>({...B,isStarting:!0})):n(B=>({...B,canStartServer:!1}))}catch{}}catch{}};return m(),l=setInterval(()=>void m(),2e3),()=>{o=!0,l&&clearInterval(l)}},[s.url]);const c=a.useCallback(()=>{n(o=>({...o,error:null,isStarting:!0})),fetch("/api/editor-dev-server",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"restart"})}).catch(()=>{})},[]),i=a.useCallback(()=>{n(o=>({...o,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 Dn(t){const s=a.useRef(null),n=a.useRef(null);a.useEffect(()=>{if(typeof document>"u")return;n.current||(n.current=document.createElement("canvas"),n.current.width=64,n.current.height=64);const r=document.querySelector('link[rel="icon"]');if(!r)return;if(s.current||(s.current=r.href),!t){r.href=s.current;return}const c=new Image;c.crossOrigin="anonymous",c.onload=()=>{const i=n.current,o=i.getContext("2d");o.clearRect(0,0,64,64);const l=56,m=(64-l)/2;o.drawImage(c,m,m,l,l);const S=12,v=64-S-1,C=S+1;o.beginPath(),o.arc(v,C,S+3,0,2*Math.PI),o.fillStyle="#ffffff",o.fill(),o.beginPath(),o.arc(v,C,S,0,2*Math.PI),o.fillStyle="#ef4444",o.fill(),r.href=i.toDataURL("image/png")},c.src=s.current},[t]),a.useEffect(()=>()=>{if(typeof document>"u")return;const r=document.querySelector('link[rel="icon"]');r&&s.current&&(r.href=s.current)},[])}function Kn({currentUrl:t,nextUrl:s,formMethod:n,defaultShouldRevalidate:r}){return n||t.pathname===s.pathname?r:t.pathname.startsWith("/editor")&&s.pathname.startsWith("/editor")?!1:r}const Qn=()=>[{title:"Editor - CodeYam"},{name:"description",content:"CodeYam Code + Data Editor"}];class Fn extends a.Component{constructor(){super(...arguments);At(this,"state",{error:null,errorInfo:null})}static getDerivedStateFromError(n){return{error:n,errorInfo:null}}componentDidCatch(n,r){console.error("[EditorErrorBoundary] Error:",n.message),console.error("[EditorErrorBoundary] Component stack:",r.componentStack),console.error("[EditorErrorBoundary] Loader snapshot:",JSON.stringify(this.props.loaderSnapshot,null,2)),this.setState({errorInfo:r})}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 Zn=$s(function(){var Tt;const{projectSlug:s,projectRoot:n,hasProject:r,scenarios:c,allScenarios:i,analyzedEntities:o,allEntities:l,glossaryFunctions:m,glossaryEntries:S,entityImports:v,pageFilePaths:C,entityChangeStatus:j,modifiedFiles:T,featureName:h,userPrompt:B,projectTitle:I,projectDescription:_,defaultScreenSize:D,screenSizes:$,editorStep:w,editorStepLabel:M,claudeSessionId:O,focusedEntitySha:x,newerEntitySha:y,focusedEntity:p,migrationMode:f,migrationState:b}=Rs(),[E,L]=As(),F=Ls(),N=a.useRef(null),J=a.useRef(null),xe=a.useRef(null),Ne=a.useRef(null),[we,Se]=a.useState(x);a.useEffect(()=>{Se(x)},[x]);const te=a.useMemo(()=>yn(we,l),[we,l,i]),k=(te==null?void 0:te.displayName)??void 0,R=E.get("scenario")||void 0,[G,V]=a.useState(()=>k?[k]:[]),A=a.useRef(null),se=a.useRef([]),ae=a.useRef(null);a.useEffect(()=>{var H;const d=R||((H=Lt(i))==null?void 0:H.id);if(!Os(d,A.current))return;const g=i.find(Q=>Q.id===d);if(!g)return;A.current=d;const P=st(g,se.current,ae.current);P&&pe(P);const W=nt(g.name);fetch("/api/editor-switch-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioSlug:W,scenarioId:g.id,scenarioName:g.name,scenarioType:g.type})}).catch(()=>{})},[R,i]),a.useEffect(()=>{const d=new BroadcastChannel("codeyam-editor");return d.onmessage=g=>{var P;if(((P=g.data)==null?void 0:P.type)==="switch-scenario"&&g.data.scenarioId){const W=g.data.scenarioId,H=i.find(be=>be.id===W);if(!H)return;A.current=W;const Q=new URLSearchParams(E);Q.set("scenario",W),Q.delete("zoom"),L(Q),u(null),z(null),ce(null),Ce(!0);const Me=nt(H.name);fetch("/api/editor-switch-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioSlug:Me,scenarioId:W,scenarioType:H.type})}).then(()=>{ee(!1),Fe(be=>be+1)}).catch(()=>{Ce(!1)})}},()=>d.close()},[E,L,i]),a.useEffect(()=>{if(E.get("ref")!=="link"||!R)return;const d=new BroadcastChannel("codeyam-editor");d.postMessage({type:"switch-scenario",scenarioId:R}),d.close(),window.close()},[]);const{devServerUrl:q,proxyUrl:re,isStarting:ie,error:oe,canStartServer:ke,retryServer:Ae,startServer:Le}=_n({skipAutoStart:f==="candidate"||f==="active"}),[le,ee]=a.useState(!1),[Y,u]=a.useState(null),[U,z]=a.useState(null),[He,ct]=a.useState(!1),[Je,ce]=a.useState(null),es=a.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&&(ce(null),ee(!1)),P},[]),ts=a.useCallback((d,g)=>{z(P=>(d&&d!==P&&ee(!1),d)),!g&&d&&ee(!0),ct(g)},[]),dt=a.useCallback(d=>{ce(null),u(P=>(P&&P.analysisId===d.analysisId||(z(null),Fe(H=>H+1)),d)),ct(!0),ee(!1);const g=new URLSearchParams(E);g.delete("scenario"),g.delete("zoom"),L(g)},[E,L]),[X,pe]=a.useState(D?{name:D.name,width:D.width,height:D.height}:{name:"Desktop",width:1440,height:900}),[mt,xt]=a.useState(!1),[Z,pt]=a.useState(!1),ut=D?{name:D.name,width:D.width,height:D.height}:null;ae.current=ut;const ht=_s(),K=a.useMemo(()=>{const d=ht.pathname.split("/").filter(Boolean),g=d[d.length-1];return g==="build"||g==="journal"?g:g==="structure"?"data":"app"},[ht.pathname]),ne=a.useCallback(d=>{Se(null),V([]);const g=d==="app"?"":`/${d==="data"?"structure":d}`,P=E.get("scenario"),W=P?`?scenario=${P}`:"";F(`/editor${g}${W}`)},[F,E]),ss=a.useCallback(()=>{ne("build"),ue(!0)},[ne]),ns=a.useCallback(()=>{ne("build"),ue(!0),setTimeout(()=>{var d;(d=N.current)==null||d.sendInput("codeyam editor migrate")},300)},[ne]),[as,ue]=a.useState(K==="build"),rs=!!(h&&w),[_e,is]=a.useState(rs?"pending":"no-session");a.useEffect(()=>{_e==="pending"&&(ne("build"),ue(!0))},[_e,ne]);const os=a.useCallback(()=>{is("continue")},[]),[Ge,Ve]=a.useState(!1),[ls,ft]=a.useState(!1),gt=a.useRef(!1),De=a.useRef(0),cs=a.useCallback(d=>{Ve(d),d&&!gt.current&&(ft(!1),De.current=Date.now()),d||(De.current=0),gt.current=d},[]);Dn(Ge);const{editorWidth:jt,isDragging:bt,isEditorCollapsed:de,isPreviewCollapsed:qe,handleMouseDown:ds,handleDoubleClick:ms,collapseEditor:xs,expandEditor:yt,expandPreview:ps}=In(Ne),[Ye,vt]=a.useState(!1),us=a.useCallback(()=>{vt(!0),ne("build"),ue(!0)},[ne]),Nt=a.useCallback(()=>{vt(!1)},[]),hs=a.useCallback(d=>{pe(d),fetch("/api/editor-project-info",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultScreenSize:d,skipBroadcast:!0})})},[]),[wt,St]=a.useState(zs);a.useEffect(()=>{const d=Ws();St(d),d.systemNotification&&typeof Notification<"u"&&Notification.permission==="default"&&Notification.requestPermission()},[]);const fs=a.useCallback(d=>{St(d),Us(d)},[]);a.useEffect(()=>{if(K==="build"){Ve(!1);const d=setTimeout(()=>{var g,P;(g=N.current)==null||g.scrollToBottom(),(P=N.current)==null||P.focus()},50);return()=>clearTimeout(d)}},[K]),a.useEffect(()=>{function d(){!document.hidden&&K==="build"&&Ve(!1)}return document.addEventListener("visibilitychange",d),()=>document.removeEventListener("visibilitychange",d)},[K]);const[he,gs]=a.useState(null);a.useEffect(()=>{const d=xe.current;if(!d)return;const g=new ResizeObserver(P=>{const W=P[0];W&&gs({width:W.contentRect.width,height:W.contentRect.height})});return g.observe(d),()=>g.disconnect()},[]);const fe=a.useMemo(()=>he?Hs(he,X):1,[he,X]),[ge,Fe]=a.useState(0),[kt,Xe]=a.useState(null),[Be,Ce]=a.useState(!1),[js,Pe]=a.useState(!1),[bs,Ct]=a.useState(!1),Ke=a.useRef(0);a.useEffect(()=>{ge>0&&(Ke.current=Date.now()+3e3)},[ge]);const ys=a.useCallback(()=>{if(Date.now()<Ke.current)return;const d=De.current;d===0||Date.now()-d<5e3||Pe(!0)},[]);a.useEffect(()=>{const d=g=>{var P;if(((P=g.data)==null?void 0:P.type)==="codeyam-localstorage-changed"){if(Date.now()<Ke.current)return;const W=De.current;if(W===0||Date.now()-W<5e3)return;Pe(!0)}};return window.addEventListener("message",d),()=>window.removeEventListener("message",d)},[]);const Pt=a.useCallback(async d=>{Ct(!0);try{let g;const P=J.current;P!=null&&P.contentWindow&&(g=await new Promise(Q=>{const Me=setTimeout(()=>Q(void 0),2e3),be=$t=>{var Rt;((Rt=$t.data)==null?void 0:Rt.type)==="codeyam-localstorage-state"&&(clearTimeout(Me),window.removeEventListener("message",be),Q($t.data.data))};window.addEventListener("message",be),P.contentWindow.postMessage({type:"codeyam-get-localstorage"},"*")}));const H=await(await fetch("/api/editor-save-seed-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mode:d,localStorage:g})})).json();H.success?Pe(!1):console.error("[editor] Save seed state failed:",H.error)}catch(g){console.error("[editor] Save seed state error:",g)}finally{Ct(!1)}},[]),vs=a.useCallback((d,g)=>{if(Xe(d||null),g){const P=new URLSearchParams(E);P.set("scenario",g),A.current=g,L(P);const W=i.find(H=>H.id===g);if(W){const H=st(W,se.current,ae.current);H&&pe(H)}}ce(null),ee(!1),Fe(P=>P+1)},[E,L,i]),{customSizes:Qe,addCustomSize:Ns,removeCustomSize:ws}=Fs(s),Ze=a.useMemo(()=>Qs($),[$]),et=a.useMemo(()=>[...Ze,...Qe],[Ze,Qe]);se.current=et;const Et=a.useMemo(()=>{const d=new Map;for(const g of l){d.set(g.name,g.sha);const P=Re($e(g.filePath));P!==g.name&&d.set(P,g.sha)}return d},[l]),Ss=a.useMemo(()=>{const d=[{name:"App"}];for(const g of G)d.push({name:g,componentName:g,entitySha:Et.get(g)});return d},[G,Et]),Mt=a.useCallback((d,g)=>{if(!d){V([]),Se(null);const Q=E.get("scenario"),Me=Q?`?scenario=${Q}`:"";F(`/editor${Me}`);return}if(!g){console.error(`[editor] No entity SHA for "${d}" — entity missing from database`);return}const P=G.indexOf(d);P>=0?V(G.slice(0,P+1)):V([...G,d]);const W=i.find(Q=>Q.entitySha===g);Se(g);const H=W?`?scenario=${W.id}`:"";F(`/editor/entity/${g}${H}`)},[F,i,G,E]),Ee=a.useCallback(d=>{u(null),z(null),ce(null),Xe(null);const g=st(d,et,ut);g&&pe(g),A.current=d.id;const P=new URLSearchParams(E);P.set("scenario",d.id),L(P),Ce(!0),Pe(!1);const W=nt(d.name);fetch("/api/editor-switch-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioSlug:W,scenarioId:d.id,scenarioType:d.type,skipBroadcast:!0})}).then(()=>{ee(!1),Fe(H=>H+1)}).catch(()=>{Ce(!1)})},[E,L,et]),ks=a.useCallback(d=>{if(!d.commitSha){const g=i.find(P=>P.name===d.scenarioName);if(g){Ee(g);return}}ce(d)},[i,Ee]),Cs=d=>{const g={name:d.name,width:d.width,height:d.height};pe(g),fetch("/api/editor-project-info",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultScreenSize:g,skipBroadcast:!0})})},Ps=(d,g,P)=>{Ns(d,g,P)},Es=d=>{pe(d),fetch("/api/editor-project-info",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultScreenSize:d,skipBroadcast:!0})})},It=()=>{Y||ee(!0),Ce(!1)},je=a.useMemo(()=>Js({activeAnalyzedScenario:!!Y,analyzedPreviewUrl:U,activeScenarioId:R||null,scenarios:i,proxyUrl:re,devServerUrl:q,zoomComponent:k||null}),[re,q,k,R,i,Y,U]),tt=a.useMemo(()=>{const d=Gs(je,kt);if(!d)return null;const g=d.includes("?")?"&":"?";return`${d}${g}__cb=${ge}`},[je,kt,ge]),Ms=a.useMemo(()=>({projectSlug:s,hasProject:r,scenarioCount:c==null?void 0:c.length,allScenarioCount:i==null?void 0:i.length,analyzedEntityCount:o==null?void 0:o.length,glossaryFunctionCount:m==null?void 0:m.length,entityChangeStatusKeys:j?Object.keys(j):[],featureName:h}),[s,r,c,i,o,m,j,h]);return e.jsxs(e.Fragment,{children:[e.jsx(Fn,{loaderSnapshot:Ms,children:e.jsxs("div",{className:"fixed inset-0 bg-[#2d2d2d] flex flex-col",children:[Y&&e.jsx(Rn,{analysisId:Y.analysisId,scenarioId:Y.scenarioId,scenarioName:Y.scenarioName,entityName:Y.entityName,projectSlug:s,onStateChange:ts},Y.analysisId),e.jsxs("div",{ref:Ne,className:"flex-1 flex min-h-0",children:[de&&e.jsx("div",{className:"shrink-0 flex items-center justify-center cursor-pointer hover:bg-[#3d3d3d] transition-colors",style:{width:8,backgroundColor:"#2d2d2d"},onClick:yt,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:{...de?{display:"none"}:jt!==null?{width:`${jt}px`}:{width:"50%"}},children:[y&&te&&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:te.name}),". A newer version exists."]}),e.jsx("a",{href:`/editor/entity/${y}`,className:"px-2 py-0.5 rounded text-xs",style:{background:"#3d2e00",color:"#f0c040",textDecoration:"none"},children:"View latest"})]}),e.jsx(En,{activeTab:K,onTabChange:d=>{ne(d),d==="build"&&ue(!0),fetch("/api/telemetry-page-view",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({route:`/editor/${d}`})}).catch(()=>{})},buildIdle:Ge}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-hidden relative",children:[Ge&&K!=="build"&&!ls&&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:`
46
+ `);return e.jsx(ve,{content:c,label:"Copy Fix Prompt",copiedLabel:"Copied!",className:"text-[9px] text-amber-400 hover:text-amber-300 bg-transparent border border-amber-400/30 rounded px-1.5 py-0.5 cursor-pointer transition-colors ml-2"})}function In({brokenEntities:t}){if(t.length===0)return null;const s=t.reduce((i,o)=>i+o.scenarios.length,0),n=t.filter(i=>i.reason==="incomplete"),r=t.filter(i=>i.reason==="missing"),c=[`${t.length} entities are missing data in the CodeYam database. ${s} 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:","",...n.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:","",...n.map(i=>{var l,m;const o=((l=i.scenarios[0])==null?void 0:l.componentPath)||((m=i.scenarios[0])==null?void 0:m.pageFilePath)||"FILL_IN_PATH";return`- "${i.name}" (filePath: "${o}")`}),"",'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","",...r.length>0?["## Step 3: Fix missing entity associations","",...r.map(i=>Zt(i.name,i.scenarios)),""]:[],`## Step ${r.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(`
47
+ `);return e.jsxs("div",{className:"mb-3 p-2 rounded border border-amber-400/30 bg-amber-400/5",children:[e.jsxs("p",{className:"text-[10px] text-amber-400/80 m-0 leading-relaxed",children:[t.length," ",t.length===1?"entity is":"entities are"," missing data (",s," hidden scenario",s!==1?"s":"","). Copy this prompt into Claude to fix them all at once."]}),e.jsx("div",{className:"mt-1.5",children:e.jsx(ve,{content:c,label:"Copy Fix All Prompt",copiedLabel:"Copied!",className:"text-[9px] text-amber-400 hover:text-amber-300 bg-transparent border border-amber-400/30 rounded px-1.5 py-0.5 cursor-pointer transition-colors"})})]})}function Rn({scenarios:t,entityName:s,entityFilePath:n,entityType:r,onSwitchToBuild:c,onScenarioSelect:i}){const[o,l]=a.useState(!1),[m,w]=a.useState(null),[v,k]=a.useState(""),[g,R]=a.useState(!1),[u,B]=a.useState(null),[I,P]=a.useState(!1),_=a.useCallback(async N=>{if(!(!v.trim()||g)){R(!0);try{(await fetch("/api/editor-rename-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioId:N,name:v.trim()})})).ok&&w(null)}catch{}finally{R(!1)}}},[v,g]),A=a.useCallback(async N=>{if(confirm(`Delete scenario "${N.name}"?`)){B(N.id);try{const E=N.screenshotPaths?Object.values(N.screenshotPaths):N.screenshotPath?[N.screenshotPath]:[];await fetch("/api/delete-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioId:N.id,screenshotPaths:E})})}catch{}finally{B(null)}}},[]);return o?e.jsxs("div",{className:"border border-[#3d3d3d] rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 bg-[#1e1e1e]",children:[e.jsx("span",{className:"text-xs font-medium text-gray-400",children:"Edit Scenarios"}),e.jsx("button",{onClick:()=>{l(!1),w(null)},className:"text-gray-500 hover:text-gray-300 text-xs bg-transparent border-none cursor-pointer",children:"Close"})]}),e.jsx("div",{className:"divide-y divide-[#2d2d2d]",children:t.map(N=>e.jsxs("div",{className:"px-3 py-2 flex items-center gap-2 hover:bg-[#252525] cursor-pointer transition-colors",style:{opacity:u===N.id?.4:1},onClick:()=>{m!==N.id&&i(N)},children:[N.screenshotPath?e.jsx(Ue,{scenarioId:N.id,updatedAt:N.updatedAt,alt:"",className:"rounded w-[40px] h-[40px] shrink-0 overflow-hidden",imgClassName:"w-full h-full object-cover"}):e.jsx("div",{className:"rounded bg-[#1e1e1e]",style:{width:40,height:40,flexShrink:0}}),m===N.id?e.jsxs("form",{className:"flex-1 flex items-center gap-1.5 min-w-0",onSubmit:E=>{E.preventDefault(),_(N.id)},children:[e.jsx("input",{type:"text",value:v,onChange:E=>k(E.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:g}),e.jsx("button",{type:"submit",disabled:g||!v.trim(),className:"px-2 py-1 text-[10px] bg-[#005c75] text-white rounded hover:bg-[#004d63] disabled:opacity-40 cursor-pointer border-none",children:g?"...":"Save"}),e.jsx("button",{type:"button",onClick:()=>w(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:"flex-1 text-xs text-gray-300 truncate min-w-0",children:N.name}),e.jsx("button",{onClick:E=>{E.stopPropagation(),w(N.id),k(N.name)},className:"text-[10px] text-gray-500 hover:text-gray-300 cursor-pointer bg-transparent border-none px-1",title:"Rename",children:"Rename"}),e.jsx("button",{onClick:E=>{E.stopPropagation(),A(N)},disabled:u===N.id,className:"text-[10px] text-red-400/60 hover:text-red-400 cursor-pointer bg-transparent border-none px-1",title:"Delete",children:"Delete"})]})]},N.id))}),I?e.jsx(vn,{prompt:Tn(s,n,r,t),height:500,onClose:()=>P(!1)}):e.jsx("div",{className:"px-3 py-2.5 bg-[#1e1e1e] border-t border-[#2d2d2d] flex justify-center",children:e.jsx("button",{onClick:()=>P(!0),className:"px-5 py-2 text-xs font-medium text-white cursor-pointer bg-[#005c75] hover:bg-[#004d63] border-none rounded-md transition-colors",children:"Modify with Claude"})})]}):e.jsx("div",{className:"flex justify-center",children:e.jsx("button",{onClick:()=>l(!0),className:"px-5 py-2 text-xs font-medium text-gray-300 hover:text-white transition-colors cursor-pointer bg-[#2a2a2a] hover:bg-[#333] border border-[#4a4a4a] hover:border-[#666] rounded-md",children:"Edit Scenarios"})})}function ye({scenarioId:t,updatedAt:s,hasScreenshot:n,imgSrc:r,name:c,isActive:i,onSelect:o}){const l=t&&n,m=!t&&r;return e.jsxs("button",{onClick:o,className:"flex flex-col items-center gap-1 cursor-pointer group w-full",title:c,children:[e.jsx("div",{className:`w-full aspect-square rounded overflow-hidden border-2 transition-all bg-[#1a1a1a] ${i?"border-[#005c75] ring-1 ring-[#005c75]":"border-transparent hover:border-[#4d4d4d]"}`,children:l?e.jsx(Ue,{scenarioId:t,updatedAt:s,alt:c,className:"w-full h-full",imgClassName:"w-full h-full object-contain"}):m?e.jsx("img",{src:r,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 Ie({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-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(ve,{content:t,icon:!0,iconSize:10,className:"shrink-0 text-gray-500 hover:text-gray-300 transition-colors"})]}):null}function An({hasProject:t,scenarios:s,analyzedEntities:n,allEntities:r=[],glossaryFunctions:c=[],glossaryEntries:i=[],projectRoot:o,activeScenarioId:l,onScenarioSelect:m,onAnalyzedScenarioSelect:w,onSwitchToBuild:v,zoomComponent:k,focusedEntity:g,onZoomChange:R,entityImports:u,pageFilePaths:B={},projectTitle:I,projectDescription:P,migrationMode:_="none",migrationState:A,onStartMigration:N,breadcrumbItems:E=[]}){var te;const{pageGroups:O,componentGroups:x}=a.useMemo(()=>Qt(s),[s]),y=a.useMemo(()=>wn(O,x),[O,x]),p=a.useMemo(()=>new Set(n.map(C=>C.sha)),[n]),f=a.useMemo(()=>Sn(u||{}),[u]),b=a.useCallback(C=>kn(C,p,r,f),[p,r,f]),T=a.useMemo(()=>{const C=new Map;for(const $ of r)C.set($.sha,$.name);return C},[r]),D=a.useMemo(()=>Cn(O,x,y,b),[O,x,y,b]),F=a.useMemo(()=>n.filter(C=>C.entityType==="visual").sort((C,$)=>C.name.localeCompare($.name)),[n]),S=a.useMemo(()=>{const C=new Map;for(const $ of c)C.set($.name,$);return C},[c]),J=a.useRef(null),xe=a.useRef(0),Ne=a.useCallback(()=>{J.current&&(xe.current=J.current.scrollTop)},[]);a.useEffect(()=>{J.current&&xe.current>0&&(J.current.scrollTop=xe.current)});const we=(g==null?void 0:g.sha)??"overview";if(!t)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx("h2",{className:"text-lg font-medium text-white font-['IBM_Plex_Sans'] m-0",children:"Ready to build something?"}),e.jsx("button",{onClick:v,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(_==="candidate")return e.jsx("div",{className:"flex-1 flex items-center justify-center",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 font-['IBM_Plex_Sans'] m-0",children:"Migrate Your Project"}),e.jsx("p",{className:"text-sm text-gray-400 m-0 font-['IBM_Plex_Sans'] 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:N,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:v,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(_==="active"&&A){const C=A.pages||[],$=C.filter(L=>L.status==="complete").length,G=C.length,V=G>0?Math.round($/G*100):0;return e.jsxs("div",{className:"flex-1 flex flex-col overflow-auto p-4",children:[e.jsx("h2",{className:"text-lg font-medium text-white font-['IBM_Plex_Sans'] 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 font-['IBM_Plex_Sans']",children:[$,"/",G," pages (",V,"%)"]})}),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:`${V}%`}})})]}),e.jsx("div",{className:"space-y-1.5",children:C.map((L,se)=>{const ae=L.status==="complete"?"✓":L.status==="in-progress"?"→":"○",q=L.status==="complete"?"text-green-400":L.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 ${q} w-3 text-center`,children:ae}),e.jsx("span",{className:`text-xs font-['IBM_Plex_Sans'] ${L.status==="in-progress"?"text-white font-medium":L.status==="complete"?"text-gray-400":"text-gray-600"}`,children:L.name}),e.jsx("span",{className:"text-[10px] text-gray-600",children:L.route}),L.status==="complete"&&e.jsxs("span",{className:"text-[10px] text-gray-600",children:[(L.extractedComponents||[]).length,"c"," ",(L.extractedFunctions||[]).length,"f"," ",L.scenarioCount||0,"s"]})]},se)})}),(A.sharedComponents||[]).length>0&&e.jsxs("div",{className:"mt-4",children:[e.jsx("h3",{className:"text-xs font-medium text-gray-400 font-['IBM_Plex_Sans'] mb-1.5",children:"Shared Components"}),(A.sharedComponents||[]).map((L,se)=>e.jsxs("div",{className:"text-[10px] text-gray-500 mb-0.5",children:[L.name," ",e.jsxs("span",{className:"text-gray-600",children:["— used in: ",(L.usedInPages||[]).join(", ")]})]},se))]}),e.jsx("div",{className:"mt-4",children:e.jsx("button",{onClick:v,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"})})]})}if(!(s.length>0||F.length>0))return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-4 px-8 text-center",children:[I?e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-lg font-medium text-white font-['IBM_Plex_Sans'] m-0",children:I}),P&&e.jsx("p",{className:"text-sm text-gray-400 m-0 font-['IBM_Plex_Sans'] leading-relaxed",children:P})]}):e.jsx("h2",{className:"text-lg font-medium text-white font-['IBM_Plex_Sans'] m-0",children:"Your project is ready"}),e.jsx("p",{className:"text-sm text-gray-400 m-0 font-['IBM_Plex_Sans'] leading-relaxed",children:"Describe what you want to build in the Chat and your pages and components will appear here."}),e.jsx("button",{onClick:v,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(g){const C=g.filePath,$=g.name,G=n.some(h=>h.sha===g.sha||h.filePath===C),V=!!((te=u==null?void 0:u[$])!=null&&te.length);if(!G&&!V){s.some(z=>z.componentName===$&&z.entitySha===g.sha);const h=s.filter(z=>z.entitySha===g.sha),U=[`The "${g.displayName}" entity (${C}) 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 "${$}" to the glossary if it's not already there:`,` Check: cat .codeyam/glossary.json | grep "${$}"`,"",` If not found, add an entry with name "${$}" and filePath "${C}" 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(`
48
+ `);return e.jsx("div",{ref:J,onScroll:Ne,className:"flex-1 overflow-auto",children:e.jsxs("div",{className:"p-4 space-y-3",children:[e.jsx(Ot,{items:E,onNavigate:R}),e.jsx("h2",{className:"text-sm font-semibold text-white m-0 font-['IBM_Plex_Sans'] uppercase tracking-wider",children:g.displayName}),C&&e.jsx(Ie,{filePath:C,projectRoot:o}),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(ve,{content:U,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"})})]}),h.length>0&&e.jsx("div",{className:"grid grid-cols-3 gap-2",children:h.map(z=>e.jsx(ye,{scenarioId:z.id,updatedAt:z.updatedAt,hasScreenshot:!!z.screenshotPath,name:z.name,isActive:z.id===l,onSelect:()=>m(z)},z.id))})]})},we)}const L=g.sha,se=s.filter(h=>!h.componentName&&(h.pageFilePath===C||L&&h.entitySha===L)),ae=s.filter(h=>h.componentName===$||h.componentPath===C),q=F.find(h=>h.filePath===C||h.name===$),re=S.get($)||c.find(h=>h.filePath===C),ie=[...se,...ae],oe=new Set((u==null?void 0:u[$])||[]),ke=V?[...x.entries()].filter(([h])=>oe.has(h)):[],$e=V?F.filter(h=>oe.has(h.name)&&!ke.some(([U])=>U===h.name)):[],Le=V?i.filter(h=>oe.has(h.name)&&h.returnType!=="JSX.Element"&&h.returnType!=="React.ReactNode").map(h=>({name:h.name,filePath:h.filePath,description:h.description||"",testFile:h.testFile,feature:h.feature})):[],le=ke.length>0||$e.length>0,ee=Le.length>0,Y=le||ee;return e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsxs("div",{className:"p-4 space-y-3",children:[e.jsx(Ot,{items:E,onNavigate:R}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-semibold text-white m-0 font-['IBM_Plex_Sans'] uppercase tracking-wider",children:g.displayName}),g.filePath&&e.jsx(Ie,{filePath:g.filePath,projectRoot:o})]}),ie.length>0&&e.jsx("div",{className:"grid grid-cols-3 gap-2",children:ie.map(h=>e.jsx(ye,{scenarioId:h.id,updatedAt:h.updatedAt,hasScreenshot:!!h.screenshotPath,name:h.name,isActive:h.id===l,onSelect:()=>m(h)},h.id))}),q&&(q.scenarios.length>0||q.pendingScenarios.length>0)&&e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[q.scenarios.map(h=>e.jsx(ye,{imgSrc:h.screenshotPath?`/api/screenshot/${h.screenshotPath}`:null,name:h.name,isActive:!1,onSelect:()=>w({analysisId:q.analysisId,scenarioId:h.id,scenarioName:h.name,entitySha:q.sha,entityName:q.name})},h.id)),q.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))]}),re&&re.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(Ie,{filePath:re.testFile,projectRoot:o})]}),e.jsx(ot,{testFile:re.testFile,entityName:$})]}),ie.length===0&&!q&&!re&&e.jsx("div",{className:"text-xs text-gray-500",children:"No scenarios for this entity"}),ie.length>0&&e.jsx(Rn,{scenarios:ie,entityName:g.displayName,entityFilePath:g.filePath,entityType:g.entityType,onSwitchToBuild:v,onScenarioSelect:m}),Y&&e.jsxs("div",{className:"pt-3 mt-2 border-t border-[#3d3d3d] space-y-3",children:[le&&e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:"Components"}),ke.map(([h,U])=>e.jsx("div",{className:"mt-3",children:y.has(h)?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"py-1",children:e.jsx("button",{onClick:()=>R(h,y.get(h)),className:"text-[11px] font-medium text-gray-400 cursor-pointer hover:text-white transition-colors bg-transparent border-none p-0",children:h})}),U.length>0&&e.jsx("div",{className:"grid grid-cols-3 gap-2 pt-1",children:U.map(z=>e.jsx(ye,{scenarioId:z.id,updatedAt:z.updatedAt,hasScreenshot:!!z.screenshotPath,name:z.name,isActive:z.id===l,onSelect:()=>m(z)},z.id))})]}):e.jsxs("div",{className:"py-2",children:[e.jsx("span",{className:"text-[11px] font-medium text-gray-500",children:h}),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(qt,{name:h,scenarios:U})})]})},h)),$e.map(h=>e.jsxs("div",{className:"mt-3",children:[e.jsx("div",{className:"py-1",children:e.jsx("button",{onClick:()=>R(h.name,h.sha),className:"text-[11px] font-medium text-gray-400 cursor-pointer hover:text-white transition-colors bg-transparent border-none p-0",children:h.name})}),(h.scenarios.length>0||h.pendingScenarios.length>0)&&e.jsxs("div",{className:"grid grid-cols-3 gap-2 pt-1",children:[h.scenarios.map(U=>e.jsx(ye,{imgSrc:U.screenshotPath?`/api/screenshot/${U.screenshotPath}`:null,name:U.name,isActive:!1,onSelect:()=>w({analysisId:h.analysisId,scenarioId:U.id,scenarioName:U.name,entitySha:h.sha,entityName:h.name})},U.id)),h.pendingScenarios.map(U=>e.jsx("div",{className:"px-2.5 py-1 bg-[#2a2a2a] text-gray-400 text-[10px] rounded-full",title:U,children:U},U))]})]},h.sha))]}),ee&&e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:"Functions"}),Le.map(h=>e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"py-1",children:e.jsx("button",{onClick:()=>R(h.name,y.get(h.name)),className:"text-[11px] font-medium text-gray-400 cursor-pointer hover:text-white transition-colors bg-transparent border-none p-0",children:h.name})}),e.jsx(Ie,{filePath:h.filePath,projectRoot:o}),h.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:h.testFile})]}),e.jsx(ot,{testFile:h.testFile,entityName:h.name})]})]},h.name))]})]})]})})}return e.jsx("div",{ref:J,onScroll:Ne,className:"flex-1 overflow-auto",children:e.jsxs("div",{className:"p-4 space-y-4",children:[I&&e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-white m-0 font-['IBM_Plex_Sans']",children:I}),P&&e.jsx("p",{className:"text-xs text-gray-400 m-0 mt-1 font-['IBM_Plex_Sans'] leading-relaxed",children:P})]}),D.length>1&&e.jsx(In,{brokenEntities:D}),O.size>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:"Application"}),e.jsx("button",{onClick:v,className:"px-2.5 py-1 text-[10px] font-medium text-gray-400 bg-[#2a2a2a] border border-[#4d4d4d] rounded hover:bg-[#333] hover:text-white hover:border-[#005c75] transition-colors cursor-pointer",children:"+ New Page"})]}),e.jsxs("p",{className:"text-[11px] text-gray-500 m-0 mt-1.5 font-['IBM_Plex_Sans'] leading-relaxed",children:["Select a page scenario below and switch to"," ",e.jsx("button",{onClick:v,className:"text-[#00a0c4] hover:text-[#00c4eb] bg-transparent border-none p-0 cursor-pointer underline font-inherit text-inherit",children:"Build"})," ","to change or enhance an existing page or"," ",e.jsx("button",{onClick:v,className:"text-[#00a0c4] hover:text-[#00c4eb] bg-transparent border-none p-0 cursor-pointer underline font-inherit text-inherit",children:"create a new page"})]}),[...O.entries()].sort(([C],[$])=>C==="Home"?-1:$==="Home"?1:C.localeCompare($)).map(([C,$])=>{var G,V;return e.jsx("div",{className:"mt-2",children:y.has(C)&&b(y.get(C))?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"py-1",children:(()=>{const L=y.get(C),ae=(L?T.get(L):void 0)||C;return e.jsx("button",{onClick:()=>R(C,y.get(C)),className:"text-[11px] font-medium text-gray-400 cursor-pointer hover:text-white transition-colors bg-transparent border-none p-0",children:ae})})()}),(((G=$[0])==null?void 0:G.pageFilePath)||B[C])&&e.jsx(Ie,{filePath:((V=$[0])==null?void 0:V.pageFilePath)||B[C],projectRoot:o}),e.jsx("div",{className:"grid grid-cols-3 gap-2 pt-1",children:$.map(L=>e.jsx(ye,{scenarioId:L.id,updatedAt:L.updatedAt,hasScreenshot:!!L.screenshotPath,name:L.name,isActive:L.id===l,onSelect:()=>m(L)},L.id))})]}):e.jsxs("div",{className:"py-2",children:[e.jsx("span",{className:"text-[11px] font-medium text-gray-500",children:(()=>{const L=y.get(C);return L&&T.get(L)||C})()}),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 page. 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(qt,{name:C,scenarios:$,reason:y.has(C)?"incomplete":"missing"})})]})},C)})]})]})},we)}const $n=[{key:"app",label:"App"},{key:"build",label:"Build"},{key:"data",label:"Structure"},{key:"journal",label:"Journal"}];function Ln({activeTab:t,onTabChange:s,buildIdle:n}){return e.jsxs("div",{className:"bg-[#3d3d3d] h-10 flex items-center px-3 gap-3 shrink-0 z-20 border-b border-[#2d2d2d]",children:[e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("img",{src:Ys,alt:"CodeYam",className:"h-5 brightness-0 invert"}),e.jsx("span",{className:"text-white font-medium text-xs whitespace-nowrap",children:"Codeyam Editor"})]}),e.jsx("div",{className:"flex-1"}),e.jsx("div",{className:"flex items-center gap-2 shrink-0",children:e.jsx("div",{className:"flex items-center gap-0.5 bg-[#4a3232] rounded-lg p-0.5",children:$n.map(r=>e.jsxs("button",{onClick:()=>s(r.key),className:`px-2.5 py-1 text-xs font-medium rounded-md transition-colors cursor-pointer ${t===r.key?"bg-[#7a4444] text-white":"text-gray-300 hover:text-white"}`,children:[r.label,r.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"})]},r.key))})})]})}function _n({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 Yt=300,Oe=150;function Dn(t){const[s,n]=a.useState(null),[r,c]=a.useState(!1),i=a.useRef(0),o=a.useRef(null);a.useEffect(()=>{t.current&&n(Math.round(t.current.offsetWidth*.5))},[t]);const l=a.useCallback(()=>{var I;return((I=t.current)==null?void 0:I.offsetWidth)??(typeof window<"u"?window.innerWidth:1024)},[t]),m=a.useCallback(I=>{I.preventDefault(),c(!0)},[]),w=a.useCallback(()=>{n(Math.round(l()*.5))},[l]),v=a.useCallback(()=>{n(I=>(I&&I>0&&(o.current=I),0))},[]),k=a.useCallback(()=>{const I=o.current;o.current=null,n(I&&I>=Yt?I:Math.round(l()*.5))},[l]),g=a.useCallback(()=>{n(Math.round(l()*.5))},[l]);a.useEffect(()=>{if(!r)return;document.body.style.cursor="col-resize",document.body.style.userSelect="none";const I=_=>{cancelAnimationFrame(i.current),i.current=requestAnimationFrame(()=>{var p;const A=(p=t.current)==null?void 0:p.getBoundingClientRect(),N=(A==null?void 0:A.left)??0,O=((A==null?void 0:A.width)??window.innerWidth)-Oe,x=_.clientX-N,y=Math.min(Math.max(x,Yt),O);n(y)})},P=_=>{var x;cancelAnimationFrame(i.current),c(!1);const A=(x=t.current)==null?void 0:x.getBoundingClientRect(),N=(A==null?void 0:A.left)??0,E=(A==null?void 0:A.width)??window.innerWidth,O=_.clientX-N;O<Oe?n(0):E-O<Oe&&n(E)};return document.addEventListener("mousemove",I),document.addEventListener("mouseup",P),()=>{cancelAnimationFrame(i.current),document.removeEventListener("mousemove",I),document.removeEventListener("mouseup",P),document.body.style.cursor="",document.body.style.userSelect=""}},[r,t]),a.useEffect(()=>{const I=()=>{n(P=>{if(P===null||P===0)return P;const _=l();return P>=_?_:Math.min(P,_-Oe)})};if(!(typeof window>"u"))return window.addEventListener("resize",I),()=>window.removeEventListener("resize",I)},[l]);const R=l(),u=s===0,B=s!==null&&s>=R;return{editorWidth:s,isDragging:r,isEditorCollapsed:u,isPreviewCollapsed:B,handleMouseDown:m,handleDoubleClick:w,collapseEditor:v,expandEditor:k,expandPreview:g}}function Fn({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(Bn,{commitSha:t.commitSha,onLoadCommit:n})})]})}function Bn({commitSha:t,onLoadCommit:s}){const[n,r]=a.useState(!1),[c,i]=a.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{r(!0),i(null),s(t).then(o=>{o.success||i(o.error||"Failed to load commit")}).catch(o=>{i(o instanceof Error?o.message:"Network error")}).finally(()=>r(!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 On({analysisId:t,scenarioId:s,scenarioName:n,entityName:r,projectSlug:c,onStateChange:i}){const{interactiveServerUrl:o,isStarting:l,isLoading:m}=Xs({analysisId:t,scenarioId:s,scenarioName:n,entityName:r,projectSlug:c,enabled:!0});return a.useEffect(()=>{i(o,l||m)},[o,l,m,i]),null}function zn({onSaveToCurrent:t,onSaveAsNew:s,onDismiss:n,isSaving:r,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:r,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:r?"Saving...":"Save to Scenario"}),e.jsx("button",{onClick:s,disabled:r,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:r,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 Wn(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 Un(t){const[s,n]=a.useState({url:null,proxyUrl:null,isStarting:!1,error:null,canStartServer:!0,autoStartAttempted:!1}),r=a.useRef(s);r.current=s,a.useEffect(()=>{let o=!1,l=null;const m=async()=>{try{const w=await fetch("/api/editor-dev-server");if(o)return;const v=await w.json(),k=Wn(r.current,v),{shouldAutoStart:g,...R}=k;if(n(R),g&&!(t!=null&&t.skipAutoStart))try{const u=await fetch("/api/editor-dev-server",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"start"})});if(o)return;u.ok?n(B=>({...B,isStarting:!0})):n(B=>({...B,canStartServer:!1}))}catch{}}catch{}};return m(),l=setInterval(()=>void m(),2e3),()=>{o=!0,l&&clearInterval(l)}},[s.url]);const c=a.useCallback(()=>{n(o=>({...o,error:null,isStarting:!0})),fetch("/api/editor-dev-server",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"restart"})}).catch(()=>{})},[]),i=a.useCallback(()=>{n(o=>({...o,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 Hn(t){const s=a.useRef(null),n=a.useRef(null);a.useEffect(()=>{if(typeof document>"u")return;n.current||(n.current=document.createElement("canvas"),n.current.width=64,n.current.height=64);const r=document.querySelector('link[rel="icon"]');if(!r)return;if(s.current||(s.current=r.href),!t){r.href=s.current;return}const c=new Image;c.crossOrigin="anonymous",c.onload=()=>{const i=n.current,o=i.getContext("2d");o.clearRect(0,0,64,64);const l=56,m=(64-l)/2;o.drawImage(c,m,m,l,l);const w=12,v=64-w-1,k=w+1;o.beginPath(),o.arc(v,k,w+3,0,2*Math.PI),o.fillStyle="#ffffff",o.fill(),o.beginPath(),o.arc(v,k,w,0,2*Math.PI),o.fillStyle="#ef4444",o.fill(),r.href=i.toDataURL("image/png")},c.src=s.current},[t]),a.useEffect(()=>()=>{if(typeof document>"u")return;const r=document.querySelector('link[rel="icon"]');r&&s.current&&(r.href=s.current)},[])}function aa({currentUrl:t,nextUrl:s,formMethod:n,defaultShouldRevalidate:r}){return n||t.pathname===s.pathname?r:t.pathname.startsWith("/editor")&&s.pathname.startsWith("/editor")?!1:r}const ra=()=>[{title:"Editor - CodeYam"},{name:"description",content:"CodeYam Code + Data Editor"}];class Jn extends a.Component{constructor(){super(...arguments);$t(this,"state",{error:null,errorInfo:null})}static getDerivedStateFromError(n){return{error:n,errorInfo:null}}componentDidCatch(n,r){console.error("[EditorErrorBoundary] Error:",n.message),console.error("[EditorErrorBoundary] Component stack:",r.componentStack),console.error("[EditorErrorBoundary] Loader snapshot:",JSON.stringify(this.props.loaderSnapshot,null,2)),this.setState({errorInfo:r})}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 ia=Rs(function(){var It;const{projectSlug:s,projectRoot:n,hasProject:r,scenarios:c,allScenarios:i,analyzedEntities:o,allEntities:l,glossaryFunctions:m,glossaryEntries:w,entityImports:v,pageFilePaths:k,entityChangeStatus:g,modifiedFiles:R,featureName:u,userPrompt:B,projectTitle:I,projectDescription:P,defaultScreenSize:_,screenSizes:A,editorStep:N,editorStepLabel:E,claudeSessionId:O,focusedEntitySha:x,newerEntitySha:y,focusedEntity:p,migrationMode:f,migrationState:b}=As(),[T,D]=$s(),F=Ls(),S=a.useRef(null),J=a.useRef(null),xe=a.useRef(null),Ne=a.useRef(null),[we,Se]=a.useState(x);a.useEffect(()=>{Se(x)},[x]);const te=a.useMemo(()=>Pn(we,l),[we,l,i]),C=(te==null?void 0:te.displayName)??void 0,$=T.get("scenario")||void 0,[G,V]=a.useState(()=>C?[C]:[]),L=a.useRef(null),se=a.useRef([]),ae=a.useRef(null);a.useEffect(()=>{var H;const d=$||((H=Lt(i))==null?void 0:H.id);if(!Os(d,L.current))return;const j=i.find(Q=>Q.id===d);if(!j)return;L.current=d;const M=st(j,se.current,ae.current);M&&pe(M);const W=nt(j.name);fetch("/api/editor-switch-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioSlug:W,scenarioId:j.id,scenarioName:j.name,scenarioType:j.type})}).catch(()=>{})},[$,i]),a.useEffect(()=>{const d=new BroadcastChannel("codeyam-editor");return d.onmessage=j=>{var M;if(((M=j.data)==null?void 0:M.type)==="switch-scenario"&&j.data.scenarioId){const W=j.data.scenarioId,H=i.find(be=>be.id===W);if(!H)return;L.current=W;const Q=new URLSearchParams(T);Q.set("scenario",W),Q.delete("zoom"),D(Q),h(null),z(null),ce(null),Ce(!0);const Me=nt(H.name);fetch("/api/editor-switch-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioSlug:Me,scenarioId:W,scenarioType:H.type})}).then(()=>{ee(!1),Fe(be=>be+1)}).catch(()=>{Ce(!1)})}},()=>d.close()},[T,D,i]),a.useEffect(()=>{if(T.get("ref")!=="link"||!$)return;const d=new BroadcastChannel("codeyam-editor");d.postMessage({type:"switch-scenario",scenarioId:$}),d.close(),window.close()},[]);const{devServerUrl:q,proxyUrl:re,isStarting:ie,error:oe,canStartServer:ke,retryServer:$e,startServer:Le}=Un({skipAutoStart:f==="candidate"||f==="active"}),[le,ee]=a.useState(!1),[Y,h]=a.useState(null),[U,z]=a.useState(null),[He,ct]=a.useState(!1),[Je,ce]=a.useState(null),es=a.useCallback(async d=>{const M=await(await fetch("/api/editor-load-commit",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({commitSha:d})})).json();return M.success&&(ce(null),ee(!1)),M},[]),ts=a.useCallback((d,j)=>{z(M=>(d&&d!==M&&ee(!1),d)),!j&&d&&ee(!0),ct(j)},[]),dt=a.useCallback(d=>{ce(null),h(M=>(M&&M.analysisId===d.analysisId||(z(null),Fe(H=>H+1)),d)),ct(!0),ee(!1);const j=new URLSearchParams(T);j.delete("scenario"),j.delete("zoom"),D(j)},[T,D]),[X,pe]=a.useState(_?{name:_.name,width:_.width,height:_.height}:{name:"Desktop",width:1440,height:900}),[mt,xt]=a.useState(!1),[Z,pt]=a.useState(!1),ut=_?{name:_.name,width:_.width,height:_.height}:null;ae.current=ut;const ht=_s(),K=a.useMemo(()=>{const d=ht.pathname.split("/").filter(Boolean),j=d[d.length-1];return j==="build"||j==="journal"?j:j==="structure"?"data":"app"},[ht.pathname]),ne=a.useCallback(d=>{Se(null),V([]);const j=d==="app"?"":`/${d==="data"?"structure":d}`,M=T.get("scenario"),W=M?`?scenario=${M}`:"";F(`/editor${j}${W}`)},[F,T]),ss=a.useCallback(()=>{ne("build"),ue(!0)},[ne]),ns=a.useCallback(()=>{ne("build"),ue(!0),setTimeout(()=>{var d;(d=S.current)==null||d.sendInput("codeyam editor migrate")},300)},[ne]),[as,ue]=a.useState(K==="build"),rs=!!(u&&N),[_e,is]=a.useState(rs?"pending":"no-session");a.useEffect(()=>{_e==="pending"&&(ne("build"),ue(!0))},[_e,ne]);const os=a.useCallback(()=>{is("continue")},[]),[Ge,Ve]=a.useState(!1),[ls,ft]=a.useState(!1),gt=a.useRef(!1),De=a.useRef(0),cs=a.useCallback(d=>{Ve(d),d&&!gt.current&&(ft(!1),De.current=Date.now()),d||(De.current=0),gt.current=d},[]);Hn(Ge);const{editorWidth:jt,isDragging:bt,isEditorCollapsed:de,isPreviewCollapsed:qe,handleMouseDown:ds,handleDoubleClick:ms,collapseEditor:xs,expandEditor:yt,expandPreview:ps}=Dn(Ne),[Ye,vt]=a.useState(!1),us=a.useCallback(()=>{vt(!0),ne("build"),ue(!0)},[ne]),Nt=a.useCallback(()=>{vt(!1)},[]),hs=a.useCallback(d=>{pe(d),fetch("/api/editor-project-info",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultScreenSize:d,skipBroadcast:!0})})},[]),[wt,St]=a.useState(zs);a.useEffect(()=>{const d=Ws();St(d),d.systemNotification&&typeof Notification<"u"&&Notification.permission==="default"&&Notification.requestPermission()},[]);const fs=a.useCallback(d=>{St(d),Us(d)},[]);a.useEffect(()=>{if(K==="build"){Ve(!1);const d=setTimeout(()=>{var j,M;(j=S.current)==null||j.scrollToBottom(),(M=S.current)==null||M.focus()},50);return()=>clearTimeout(d)}},[K]),a.useEffect(()=>{function d(){!document.hidden&&K==="build"&&Ve(!1)}return document.addEventListener("visibilitychange",d),()=>document.removeEventListener("visibilitychange",d)},[K]);const[he,gs]=a.useState(null);a.useEffect(()=>{const d=xe.current;if(!d)return;const j=new ResizeObserver(M=>{const W=M[0];W&&gs({width:W.contentRect.width,height:W.contentRect.height})});return j.observe(d),()=>j.disconnect()},[]);const fe=a.useMemo(()=>he?Hs(he,X):1,[he,X]),[ge,Fe]=a.useState(0),[kt,Xe]=a.useState(null),[Be,Ce]=a.useState(!1),[js,Pe]=a.useState(!1),[bs,Ct]=a.useState(!1),Ke=a.useRef(0);a.useEffect(()=>{ge>0&&(Ke.current=Date.now()+3e3)},[ge]);const ys=a.useCallback(()=>{if(Date.now()<Ke.current)return;const d=De.current;d===0||Date.now()-d<5e3||Pe(!0)},[]);a.useEffect(()=>{const d=j=>{var M;if(((M=j.data)==null?void 0:M.type)==="codeyam-localstorage-changed"){if(Date.now()<Ke.current)return;const W=De.current;if(W===0||Date.now()-W<5e3)return;Pe(!0)}};return window.addEventListener("message",d),()=>window.removeEventListener("message",d)},[]);const Pt=a.useCallback(async d=>{Ct(!0);try{let j;const M=J.current;M!=null&&M.contentWindow&&(j=await new Promise(Q=>{const Me=setTimeout(()=>Q(void 0),2e3),be=Rt=>{var At;((At=Rt.data)==null?void 0:At.type)==="codeyam-localstorage-state"&&(clearTimeout(Me),window.removeEventListener("message",be),Q(Rt.data.data))};window.addEventListener("message",be),M.contentWindow.postMessage({type:"codeyam-get-localstorage"},"*")}));const H=await(await fetch("/api/editor-save-seed-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mode:d,localStorage:j})})).json();H.success?Pe(!1):console.error("[editor] Save seed state failed:",H.error)}catch(j){console.error("[editor] Save seed state error:",j)}finally{Ct(!1)}},[]),vs=a.useCallback((d,j)=>{if(Xe(d||null),j){const M=new URLSearchParams(T);M.set("scenario",j),L.current=j,D(M);const W=i.find(H=>H.id===j);if(W){const H=st(W,se.current,ae.current);H&&pe(H)}}ce(null),ee(!1),Fe(M=>M+1)},[T,D,i]),{customSizes:Qe,addCustomSize:Ns,removeCustomSize:ws}=Fs(s),Ze=a.useMemo(()=>Qs(A),[A]),et=a.useMemo(()=>[...Ze,...Qe],[Ze,Qe]);se.current=et;const Et=a.useMemo(()=>{const d=new Map;for(const j of l){d.set(j.name,j.sha);const M=Ae(Re(j.filePath));M!==j.name&&d.set(M,j.sha)}return d},[l]),Ss=a.useMemo(()=>{const d=[{name:"App"}];for(const j of G)d.push({name:j,componentName:j,entitySha:Et.get(j)});return d},[G,Et]),Mt=a.useCallback((d,j)=>{if(!d){V([]),Se(null);const Q=T.get("scenario"),Me=Q?`?scenario=${Q}`:"";F(`/editor${Me}`);return}if(!j){console.error(`[editor] No entity SHA for "${d}" — entity missing from database`);return}const M=G.indexOf(d);M>=0?V(G.slice(0,M+1)):V([...G,d]);const W=i.find(Q=>Q.entitySha===j);Se(j);const H=W?`?scenario=${W.id}`:"";F(`/editor/entity/${j}${H}`)},[F,i,G,T]),Ee=a.useCallback(d=>{h(null),z(null),ce(null),Xe(null);const j=st(d,et,ut);j&&pe(j),L.current=d.id;const M=new URLSearchParams(T);M.set("scenario",d.id),D(M),Ce(!0),Pe(!1);const W=nt(d.name);fetch("/api/editor-switch-scenario",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scenarioSlug:W,scenarioId:d.id,scenarioType:d.type,skipBroadcast:!0})}).then(()=>{ee(!1),Fe(H=>H+1)}).catch(()=>{Ce(!1)})},[T,D,et]),ks=a.useCallback(d=>{if(!d.commitSha){const j=i.find(M=>M.name===d.scenarioName);if(j){Ee(j);return}}ce(d)},[i,Ee]),Cs=d=>{const j={name:d.name,width:d.width,height:d.height};pe(j),fetch("/api/editor-project-info",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultScreenSize:j,skipBroadcast:!0})})},Ps=(d,j,M)=>{Ns(d,j,M)},Es=d=>{pe(d),fetch("/api/editor-project-info",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultScreenSize:d,skipBroadcast:!0})})},Tt=()=>{Y||ee(!0),Ce(!1)},je=a.useMemo(()=>Js({activeAnalyzedScenario:!!Y,analyzedPreviewUrl:U,activeScenarioId:$||null,scenarios:i,proxyUrl:re,devServerUrl:q,zoomComponent:C||null}),[re,q,C,$,i,Y,U]),tt=a.useMemo(()=>{const d=Gs(je,kt);if(!d)return null;const j=d.includes("?")?"&":"?";return`${d}${j}__cb=${ge}`},[je,kt,ge]),Ms=a.useMemo(()=>({projectSlug:s,hasProject:r,scenarioCount:c==null?void 0:c.length,allScenarioCount:i==null?void 0:i.length,analyzedEntityCount:o==null?void 0:o.length,glossaryFunctionCount:m==null?void 0:m.length,entityChangeStatusKeys:g?Object.keys(g):[],featureName:u}),[s,r,c,i,o,m,g,u]);return e.jsxs(e.Fragment,{children:[e.jsx(Jn,{loaderSnapshot:Ms,children:e.jsxs("div",{className:"fixed inset-0 bg-[#2d2d2d] flex flex-col",children:[Y&&e.jsx(On,{analysisId:Y.analysisId,scenarioId:Y.scenarioId,scenarioName:Y.scenarioName,entityName:Y.entityName,projectSlug:s,onStateChange:ts},Y.analysisId),e.jsxs("div",{ref:Ne,className:"flex-1 flex min-h-0",children:[de&&e.jsx("div",{className:"shrink-0 flex items-center justify-center cursor-pointer hover:bg-[#3d3d3d] transition-colors",style:{width:8,backgroundColor:"#2d2d2d"},onClick:yt,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:{...de?{display:"none"}:jt!==null?{width:`${jt}px`}:{width:"50%"}},children:[y&&te&&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:te.name}),". A newer version exists."]}),e.jsx("a",{href:`/editor/entity/${y}`,className:"px-2 py-0.5 rounded text-xs",style:{background:"#3d2e00",color:"#f0c040",textDecoration:"none"},children:"View latest"})]}),e.jsx(Ln,{activeTab:K,onTabChange:d=>{ne(d),d==="build"&&ue(!0),fetch("/api/telemetry-page-view",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({route:`/editor/${d}`})}).catch(()=>{})},buildIdle:Ge}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-hidden relative",children:[Ge&&K!=="build"&&!ls&&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:`
49
49
  @keyframes slideDown {
50
50
  from { transform: translate(-50%, -100%); opacity: 0; }
51
51
  to { transform: translate(-50%, 0); opacity: 1; }
52
52
  }
53
- `}),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:()=>{ne("build"),ue(!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(),ft(!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"})})})]})]}),as&&e.jsxs("div",{className:"absolute inset-0 flex flex-col overflow-hidden",style:{visibility:K==="build"?"visible":"hidden"},children:[e.jsx("div",{className:"flex-1 min-h-0",style:Ye?{flex:"1 1 50%"}:void 0,children:_e==="pending"?e.jsx(Zs,{featureName:h,editorStep:w,editorStepLabel:M,onContinue:os}):e.jsx(Vs,{ref:N,entityName:"Editor",projectSlug:s,entityFilePath:null,scenarioName:null,onRefreshPreview:vs,onShowResults:us,onHideResults:Nt,onSetViewport:hs,onDataMutationForwarded:ys,editorMode:!0,onIdleChange:cs,notificationSettings:wt,buildTabActive:K==="build",claudeStartMode:_e==="continue"?"resume":"fresh",claudeSessionId:O,resultsOpen:Ye})}),Ye&&e.jsx("div",{style:{flex:"1 1 50%"},className:"min-h-0 border-t-2 border-gray-300",children:e.jsx(Nn,{scenarios:c,allScenarios:i,glossaryFunctions:m,projectRoot:n,activeScenarioId:R,onScenarioSelect:Ee,onClose:Nt,entityChangeStatus:j,modifiedFiles:T,featureName:h,userPrompt:B})})]}),e.jsx("div",{className:"absolute inset-0 flex flex-col overflow-hidden",style:{visibility:K==="app"?"visible":"hidden"},children:e.jsx(Cn,{hasProject:r,scenarios:i,analyzedEntities:o,allEntities:l,glossaryFunctions:m,glossaryEntries:S,projectRoot:n,activeScenarioId:R,onScenarioSelect:Ee,onAnalyzedScenarioSelect:dt,onSwitchToBuild:ss,zoomComponent:k,focusedEntity:te,onZoomChange:Mt,entityImports:v,pageFilePaths:C,projectTitle:I,projectDescription:_,breadcrumbItems:Ss,migrationMode:f,migrationState:b,onStartMigration:ns})}),e.jsx("div",{className:"absolute inset-0 flex flex-col overflow-hidden",style:{visibility:K==="data"?"visible":"hidden"},children:e.jsx(en,{scenarios:i,projectRoot:n,activeScenarioId:R,onScenarioSelect:Ee,zoomComponent:k,focusedEntity:te,onZoomChange:Mt,analyzedEntities:[],glossaryFunctions:m,activeAnalyzedScenarioId:Y==null?void 0:Y.scenarioId,onAnalyzedScenarioSelect:dt,entityImports:v,pageFilePaths:C})}),e.jsx("div",{className:"absolute inset-0 flex flex-col overflow-hidden",style:{visibility:K==="journal"?"visible":"hidden"},children:e.jsx(pn,{isActive:K==="journal",onScreenshotClick:ks,glossaryFunctions:m})})]}),e.jsx(qs,{serverUrl:q,isStarting:ie,projectSlug:s,devServerError:oe,onStartServer:ke?Le:void 0,notificationSettings:wt,onChangeNotificationSettings:fs})]}),!de&&!qe&&e.jsx(Mn,{onMouseDown:ds,onDoubleClick:ms,isDragging:bt}),qe&&e.jsx("div",{className:"shrink-0 flex items-center justify-center cursor-pointer hover:bg-[#3d3d3d] transition-colors",style:{width:8,backgroundColor:"#2d2d2d"},onClick:ps,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:{...qe?{display:"none"}:void 0,...bt?{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:()=>{de?(yt(),setTimeout(()=>{var d;return(d=N.current)==null?void 0:d.focus()},50)):xs()},className:`p-1.5 rounded transition-colors cursor-pointer ${de?"text-white bg-[#666] hover:bg-[#777]":"text-gray-500 hover:text-gray-300"}`,title:de?"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:de?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:[ze.map(d=>e.jsxs("button",{onClick:()=>{Z&&pt(!1),Cs(d)},className:`p-1.5 rounded transition-colors cursor-pointer ${!Z&&X.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:()=>{Z||xt(d=>!d)},className:`flex items-center gap-1.5 px-2 py-1 rounded transition-colors ${Z?"":"cursor-pointer"} ${Z||mt||!ze.some(d=>d.name===X.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:Z&&he?`${Math.round(he.width)} × ${Math.round(he.height)}`:`${X.width} × ${X.height??900}`})]}),mt&&e.jsx(Bs,{currentWidth:X.width,currentHeight:X.height??900,devicePresets:Ze,customSizes:Qe,onApply:Es,onSave:Ps,onRemove:ws,onClose:()=>xt(!1)})]}),e.jsx("button",{onClick:()=>{pt(d=>!d)},className:`p-1.5 rounded transition-colors cursor-pointer ${Z?"text-white bg-[#555]":"text-gray-500 hover:text-gray-300"}`,title:Z?"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:Z?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=tt||je;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(An,{onSaveToCurrent:()=>void Pt("overwrite"),onSaveAsNew:()=>void Pt("new"),onDismiss:()=>Pe(!1),isSaving:bs,scenarioName:(Tt=i.find(d=>{var g;return d.id===(R||((g=Lt(i))==null?void 0:g.id))}))==null?void 0:Tt.name}),e.jsx("div",{ref:xe,className:`flex-1 flex overflow-hidden ${Z?"":"items-center justify-center p-8"}`,style:Z?{backgroundColor:"#fff"}:Je?{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)"}:{backgroundImage:`
53
+ `}),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:()=>{ne("build"),ue(!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(),ft(!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"})})})]})]}),as&&e.jsxs("div",{className:"absolute inset-0 flex flex-col overflow-hidden",style:{visibility:K==="build"?"visible":"hidden"},children:[e.jsx(on,{projectTitle:I,featureName:u,editorStep:N,editorStepLabel:E,migrationMode:f}),e.jsx("div",{className:"flex-1 min-h-0",style:Ye?{flex:"1 1 50%"}:void 0,children:_e==="pending"?e.jsx(Zs,{featureName:u,editorStep:N,editorStepLabel:E,onContinue:os}):e.jsx(Vs,{ref:S,entityName:"Editor",projectSlug:s,entityFilePath:null,scenarioName:null,onRefreshPreview:vs,onShowResults:us,onHideResults:Nt,onSetViewport:hs,onDataMutationForwarded:ys,editorMode:!0,onIdleChange:cs,notificationSettings:wt,buildTabActive:K==="build",claudeStartMode:_e==="continue"?"resume":"fresh",claudeSessionId:O,resultsOpen:Ye})}),Ye&&e.jsx("div",{style:{flex:"1 1 50%"},className:"min-h-0 border-t-2 border-gray-300",children:e.jsx(Mn,{scenarios:c,allScenarios:i,glossaryFunctions:m,projectRoot:n,activeScenarioId:$,onScenarioSelect:Ee,onClose:Nt,entityChangeStatus:g,modifiedFiles:R,featureName:u,userPrompt:B})})]}),e.jsx("div",{className:"absolute inset-0 flex flex-col overflow-hidden",style:{visibility:K==="app"?"visible":"hidden"},children:e.jsx(An,{hasProject:r,scenarios:i,analyzedEntities:o,allEntities:l,glossaryFunctions:m,glossaryEntries:w,projectRoot:n,activeScenarioId:$,onScenarioSelect:Ee,onAnalyzedScenarioSelect:dt,onSwitchToBuild:ss,zoomComponent:C,focusedEntity:te,onZoomChange:Mt,entityImports:v,pageFilePaths:k,projectTitle:I,projectDescription:P,breadcrumbItems:Ss,migrationMode:f,migrationState:b,onStartMigration:ns})}),e.jsx("div",{className:"absolute inset-0 flex flex-col overflow-hidden",style:{visibility:K==="data"?"visible":"hidden"},children:e.jsx(ln,{scenarios:i,projectRoot:n,activeScenarioId:$,onScenarioSelect:Ee,zoomComponent:C,focusedEntity:te,onZoomChange:Mt,analyzedEntities:[],glossaryFunctions:m,activeAnalyzedScenarioId:Y==null?void 0:Y.scenarioId,onAnalyzedScenarioSelect:dt,entityImports:v,pageFilePaths:k})}),e.jsx("div",{className:"absolute inset-0 flex flex-col overflow-hidden",style:{visibility:K==="journal"?"visible":"hidden"},children:e.jsx(yn,{isActive:K==="journal",onScreenshotClick:ks,glossaryFunctions:m})})]}),e.jsx(qs,{serverUrl:q,isStarting:ie,projectSlug:s,devServerError:oe,onStartServer:ke?Le:void 0,notificationSettings:wt,onChangeNotificationSettings:fs})]}),!de&&!qe&&e.jsx(_n,{onMouseDown:ds,onDoubleClick:ms,isDragging:bt}),qe&&e.jsx("div",{className:"shrink-0 flex items-center justify-center cursor-pointer hover:bg-[#3d3d3d] transition-colors",style:{width:8,backgroundColor:"#2d2d2d"},onClick:ps,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:{...qe?{display:"none"}:void 0,...bt?{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:()=>{de?(yt(),setTimeout(()=>{var d;return(d=S.current)==null?void 0:d.focus()},50)):xs()},className:`p-1.5 rounded transition-colors cursor-pointer ${de?"text-white bg-[#666] hover:bg-[#777]":"text-gray-500 hover:text-gray-300"}`,title:de?"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:de?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:[ze.map(d=>e.jsxs("button",{onClick:()=>{Z&&pt(!1),Cs(d)},className:`p-1.5 rounded transition-colors cursor-pointer ${!Z&&X.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:()=>{Z||xt(d=>!d)},className:`flex items-center gap-1.5 px-2 py-1 rounded transition-colors ${Z?"":"cursor-pointer"} ${Z||mt||!ze.some(d=>d.name===X.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:Z&&he?`${Math.round(he.width)} × ${Math.round(he.height)}`:`${X.width} × ${X.height??900}`})]}),mt&&e.jsx(Bs,{currentWidth:X.width,currentHeight:X.height??900,devicePresets:Ze,customSizes:Qe,onApply:Es,onSave:Ps,onRemove:ws,onClose:()=>xt(!1)})]}),e.jsx("button",{onClick:()=>{pt(d=>!d)},className:`p-1.5 rounded transition-colors cursor-pointer ${Z?"text-white bg-[#555]":"text-gray-500 hover:text-gray-300"}`,title:Z?"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:Z?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=tt||je;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(zn,{onSaveToCurrent:()=>void Pt("overwrite"),onSaveAsNew:()=>void Pt("new"),onDismiss:()=>Pe(!1),isSaving:bs,scenarioName:(It=i.find(d=>{var j;return d.id===($||((j=Lt(i))==null?void 0:j.id))}))==null?void 0:It.name}),e.jsx("div",{ref:xe,className:`flex-1 flex overflow-hidden ${Z?"":"items-center justify-center p-8"}`,style:Z?{backgroundColor:"#fff"}:Je?{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)"}:{backgroundImage:`
54
54
  linear-gradient(45deg, #333 25%, transparent 25%),
55
55
  linear-gradient(-45deg, #333 25%, transparent 25%),
56
56
  linear-gradient(45deg, transparent 75%, #333 75%),
57
57
  linear-gradient(-45deg, transparent 75%, #333 75%)
58
- `,backgroundSize:"16px 16px",backgroundPosition:"0 0, 0 8px, 8px -8px, -8px 0px",backgroundColor:"#2d2d2d"},children:Je?e.jsx(Tn,{preview:Je,onDismiss:()=>ce(null),onLoadCommit:es}):je?Z?e.jsxs("div",{className:"relative w-full h-full bg-white",children:[!le&&!Be&&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(at,{})}),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"})]})]})}),Be&&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:J,src:tt||je,className:"w-full h-full border-none",title:"Editor preview",onLoad:It,style:{opacity:le?1:0}},ge)]}):e.jsx("div",{style:{width:`${X.width*fe}px`,height:`${(X.height??900)*fe}px`},children:e.jsxs("div",{className:"relative bg-white origin-top-left",style:{width:`${X.width}px`,height:`${X.height??900}px`,transform:fe<1?`scale(${fe})`:void 0},children:[!le&&!Be&&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(at,{})}),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"})]})]})}),Be&&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:J,src:tt||je,className:"w-full h-full border-none",title:"Editor preview",onLoad:It,style:{opacity:le?1:0}},ge)]})}):e.jsx("div",{className:"bg-[#2a2a2a] rounded-lg flex flex-col items-center justify-center",style:{width:`${X.width*fe}px`,height:`${(X.height??900)*fe}px`},children:oe?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:oe}),e.jsx("button",{onClick:Ae,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"})]}):ie||He?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mb-4",children:e.jsx(at,{})}),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:He?"Starting Interactive Mode":"Starting Dev Server"}),e.jsx("p",{className:"text-sm text-gray-400 leading-5 m-0 font-['IBM_Plex_Sans']",children:He?"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(Ds,{})]})});export{Zn as default,Qn as meta,Kn as shouldRevalidate};
58
+ `,backgroundSize:"16px 16px",backgroundPosition:"0 0, 0 8px, 8px -8px, -8px 0px",backgroundColor:"#2d2d2d"},children:Je?e.jsx(Fn,{preview:Je,onDismiss:()=>ce(null),onLoadCommit:es}):je?Z?e.jsxs("div",{className:"relative w-full h-full bg-white",children:[!le&&!Be&&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(at,{})}),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"})]})]})}),Be&&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:J,src:tt||je,className:"w-full h-full border-none",title:"Editor preview",onLoad:Tt,style:{opacity:le?1:0}},ge)]}):e.jsx("div",{style:{width:`${X.width*fe}px`,height:`${(X.height??900)*fe}px`},children:e.jsxs("div",{className:"relative bg-white origin-top-left",style:{width:`${X.width}px`,height:`${X.height??900}px`,transform:fe<1?`scale(${fe})`:void 0},children:[!le&&!Be&&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(at,{})}),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"})]})]})}),Be&&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:J,src:tt||je,className:"w-full h-full border-none",title:"Editor preview",onLoad:Tt,style:{opacity:le?1:0}},ge)]})}):e.jsx("div",{className:"bg-[#2a2a2a] rounded-lg flex flex-col items-center justify-center",style:{width:`${X.width*fe}px`,height:`${(X.height??900)*fe}px`},children:oe?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:oe}),e.jsx("button",{onClick:$e,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"})]}):ie||He?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mb-4",children:e.jsx(at,{})}),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:He?"Starting Interactive Mode":"Starting Dev Server"}),e.jsx("p",{className:"text-sm text-gray-400 leading-5 m-0 font-['IBM_Plex_Sans']",children:He?"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(Ds,{})]})});export{ia as default,ra as meta,aa as shouldRevalidate};