import{u,r as n,q as S,d,t as h,j as t,E as v,W as P,e as w,g as N,s as j,h as k,v as T,w as D,C as R,c as I}from"./index-CUDottTv.js";import{T as C}from"./tabs-BoJRkfaU.js";import{B as E}from"./textarea-DAwdLdON.js";import{P as A,O as y}from"./overview-page-j5X9SBqW.js";import{NetworkPage as O}from"./network-page-CiQu5Dem.js";import{ConsolePage as z}from"./console-page-B3sYOQK9.js";import{RendersPage as B}from"./renders-page-C9THhZZ3.js";import{StatePage as M}from"./state-page-CQDLPZ5t.js";import{PerformancePage as W}from"./performance-page-ImE9xvEt.js";import{IssuesPage as _}from"./issues-page-8abUxnvT.js";import{ApiMapPage as L}from"./api-map-page-Btbazs5z.js";import{DatabasePage as F}from"./database-page-DYOGNtgK.js";import{ProcessesPage as K}from"./processes-page-BIMoApg0.js";import{InfraPage as q}from"./infra-page-Cwb8--Fc.js";import{SessionsPage as U}from"./sessions-page-BYNnSmUH.js";import{EventsPage as $}from"./events-page-d6_fhDSn.js";import{BreadcrumbsPage as V}from"./breadcrumbs-page-ahYuYyrd.js";import{L as G}from"./project-view-DnnhNMhS.js";import{P as H}from"./play-Cx2BEZVZ.js";import"./zap-D8s7B8fi.js";import"./metric-card-DE3zVnFg.js";import"./sparkline-BYGr_Iny.js";import"./minus-BzY257S7.js";import"./wifi-B9CHDUUG.js";import"./clock-CmDPWLyG.js";import"./hard-drive-D8jrlixH.js";import"./use-connected-3Ljk-Uwv.js";import"./issue-detector-CH2FjMfV.js";import"./topbar-892TvyNb.js";import"./badge-BOfEUuSW.js";import"./data-table-A2Iq_hk5.js";import"./detail-panel-YWSVnqP_.js";import"./filter-bar-CP39inkf.js";import"./status-dot-C1nxHZIG.js";import"./download-CwvkYJyJ.js";import"./export-button-D7y2ugNf.js";import"./format-CF_gowqw.js";import"./json-viewer-Dup5M0px.js";import"./chevron-right-Df1qu9CE.js";import"./info-C0v7mgTM.js";import"./empty-config-state-ReVUjdJ_.js";import"./code-block-D47Pz1qB.js";import"./square-C1plLKPb.js";import"./tag-Czqgl1tA.js";function J(e){const a=u(r=>r.projects);return n.useMemo(()=>{const r=w(a,{runtimescopeProject:e.runtimescopeProject,runtimeApps:e.runtimeApps,name:e.name});return r!=null&&r.isConnected?"live":e.sdkInstalled||r?"installed":"not-installed"},[e.runtimescopeProject,e.runtimeApps,e.name,e.sdkInstalled,a])}const x=[{id:"overview",label:"Overview"},{id:"network",label:"Network"},{id:"console",label:"Console"},{id:"renders",label:"Renders"},{id:"state",label:"State"},{id:"performance",label:"Performance"},{id:"api",label:"API Map"},{id:"database",label:"Database"},{id:"breadcrumbs",label:"Breadcrumbs"},{id:"issues",label:"Issues"},{id:"processes",label:"Processes"},{id:"infra",label:"Infra"},{id:"sessions",label:"Sessions"},{id:"events",label:"Events"}],Q={overview:y,network:O,console:z,renders:B,state:M,performance:W,api:L,database:F,breadcrumbs:V,issues:_,processes:K,infra:q,sessions:U,events:$};function X({projectId:e}){const a=d(l=>l.servers.get(e)),[r,m]=n.useState(!0),o=n.useRef(null);return n.useEffect(()=>{r&&o.current&&o.current.scrollIntoView({behavior:"smooth"})},[a==null?void 0:a.logs.length,r]),!a||a.logs.length===0?null:t.jsxs("div",{className:"w-full max-w-2xl mt-4",children:[t.jsxs("button",{type:"button",onClick:()=>m(!r),className:"w-full flex items-center justify-between px-3 py-2 rounded-t bg-bg-surface border border-border-default text-xs text-text-muted hover:bg-bg-hover transition-colors cursor-pointer",children:[t.jsxs("span",{className:"flex items-center gap-2",children:[t.jsx(D,{size:12}),"Dev Server Output",t.jsxs("span",{className:"text-text-tertiary",children:["(",a.logs.length," lines)"]})]}),t.jsx(R,{size:12,className:I("transition-transform",r&&"rotate-180")})]}),r&&t.jsxs("div",{className:"h-48 overflow-auto bg-[#0a0a14] border border-t-0 border-border-default rounded-b p-3",children:[t.jsx("pre",{className:"text-[11px] font-mono whitespace-pre-wrap break-all",children:a.logs.map((l,s)=>t.jsxs("span",{className:l.stream==="stderr"?"text-amber":"text-text-secondary",children:[l.line,`
`]},s))}),t.jsx("div",{ref:o})]})]})}function Y({project:e}){const a=d(s=>{var i;return(i=s.servers.get(e.id))==null?void 0:i.status}),[r,m]=n.useState(null),o=a==="starting",l=n.useCallback(async()=>{m(null),d.getState().setOptimisticStarting(e.id);try{const s=await N(e.id),i=(s==null?void 0:s.recommended)??"dev";if(!await j(e.id,{script:i})){m("Failed to start dev server"),d.getState().setStatus(e.id,"idle");return}k(),T.track("dev_server_started",{projectId:e.id,projectName:e.name,script:i})}catch(s){m(s.message),d.getState().setStatus(e.id,"idle")}},[e.id]);return t.jsxs("div",{className:"flex flex-col items-center gap-2",children:[t.jsx(E,{variant:"primary",size:"sm",onClick:l,disabled:o,children:o?t.jsxs(t.Fragment,{children:[t.jsx(G,{size:14,className:"animate-spin"}),"Starting..."]}):t.jsxs(t.Fragment,{children:[t.jsx(H,{size:14}),"Start Dev Server"]})}),r&&t.jsx("p",{className:"text-xs text-red",children:r}),t.jsx(X,{projectId:e.id})]})}function Ue({project:e}){const a=u(s=>s.runtimeSubTab),r=u(s=>s.setRuntimeSubTab),m=n.useRef(null);n.useEffect(()=>{const s=e.runtimescopeProject??null,i=u.getState().selectedProject;(s!==m.current||i!==s)&&(S.getState().clearAll(),u.getState().setSelectedProject(s),m.current=s)},[e.id,e.runtimescopeProject]),n.useEffect(()=>{const s=d.getState().servers.get(e.id);s&&s.logs.length>0||h(e.id).then(i=>{var c;if(i&&i.status!=="stopped"){const f=d.getState();if(f.setStatus(e.id,i.status,i.pid),(c=i.logs)!=null&&c.length)for(const p of i.logs){const b=p.startsWith("[stderr]")?"stderr":"stdout",g=p.replace(/^\[(stdout|stderr)] /,"");f.appendLog(e.id,b,g,Date.now())}}}).catch(()=>{})},[e.id]);const o=J(e);if(o!=="live"){const s=!!e.path;return t.jsx("div",{className:"flex-1 flex flex-col min-h-0 overflow-hidden",children:o==="not-installed"?t.jsx(v,{icon:t.jsx(A,{size:40,strokeWidth:1.25}),title:"SDK Not Installed",description:`Install @runtimescope/sdk in ${e.name} to capture live runtime events — network requests, console logs, renders, performance metrics, and more.`}):t.jsx(v,{icon:t.jsx(P,{size:40,strokeWidth:1.25}),title:"SDK Not Connected",description:`The RuntimeScope SDK is installed in ${e.name} but isn't connected. Start the dev server to see live runtime data.`,action:s?t.jsx(Y,{project:e}):void 0})})}const l=n.useRef(new Set(["overview"]));return l.current.add(a),t.jsxs("div",{className:"flex-1 flex flex-col min-h-0 overflow-hidden",children:[t.jsx(C,{tabs:x,activeTab:a,onTabChange:r}),t.jsx("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",children:x.filter(s=>l.current.has(s.id)).map(s=>{const i=Q[s.id];if(!i)return null;const c=a===s.id;return t.jsx("div",{className:c?"flex-1 flex flex-col min-h-0 overflow-hidden":"hidden",children:t.jsx(i,{})},s.id)})})]})}export{Ue as RuntimePage};
