import{b as n,A as p,o as C,n as I,e as b}from"./vendor-lit-B2r-dKc0.js";import{aw as _,aC as L,aE as $,aF as T,aD as F}from"./app-session-runtime-CeFJDILJ.js";import{getResult as A,gateBadge as B}from"./GateToolRenderers-QU-IFKOa.js";import{h as H,a as R}from"./index-DV9GoJhq.js";import{ae as g}from"./vendor-lucide-B9Yl1Gez.js";import"./vendor-mini-lit-CpUQub-j.js";import"./vendor-marked-_iteVaMm.js";import"./app-review-C3CmcSYC.js";import"./app-panel-workspace-C3XDRCgE.js";import"./app-routing-C_r2pdnC.js";import"./app-message-reducer-wATqnZGf.js";import"./vendor-sortable-B1o3v0Qs.js";import"./app-inbox-CaZD85aD.js";import"./app-pr-walkthrough-WipZACSB.js";function D(e){return e>=6e4?`${(e/6e4).toFixed(1)}m`:`${(e/1e3).toFixed(1)}s`}const h={passed:"passed",failed:"failed",skipped:"skipped",running:"running",waiting:"waiting",blocked:"blocked"};function E(e){if(typeof e!="string")return;const t=e.toLowerCase().replace(/_/g,"-");if(t==="passed"||t==="success"||t==="completed")return"passed";if(t==="failed"||t==="failure"||t==="error"||t==="timeout")return"failed";if(t==="skipped")return"skipped";if(t==="running"||t==="in-progress"||t==="starting")return"running";if(t==="waiting"||t==="pending"||t==="queued"||t==="yet-to-run")return"waiting";if(t==="blocked"||t==="blocked-by-earlier-failure")return"blocked"}function q(e){return e==="passed"?n`<span class="text-green-600 dark:text-green-400">✓</span>`:e==="failed"?n`<span class="text-red-600 dark:text-red-400">✗</span>`:e==="skipped"?n`<span class="text-muted-foreground">⊘</span>`:e==="waiting"?n`<span class="text-muted-foreground">○</span>`:e==="blocked"?n`<span class="text-muted-foreground">—</span>`:n`<span class="text-blue-600 dark:text-blue-400">●</span>`}function N(e){return e==="passed"?"bg-green-500/15 text-green-700 dark:text-green-300":e==="failed"?"bg-red-500/15 text-red-700 dark:text-red-300":e==="running"?"bg-blue-500/15 text-blue-700 dark:text-blue-300":"bg-muted text-muted-foreground"}function y(e){const t=E(e?.status);return t||(e.skipped?"skipped":e.passed===!0?"passed":e.passed===!1?"failed":"running")}function V(e,t){return typeof t!="number"||!Number.isFinite(t)||(e==="waiting"||e==="blocked"||e==="skipped")&&t<=0?!1:e==="running"||e==="passed"||e==="failed"||t>0}function k(e){return e?["passed","failed","running","waiting","blocked","skipped"].map(s=>{const o=Number(e[s]??0);return o>0?`${o} ${h[s]}`:""}).filter(Boolean).join(", "):""}function j(e,t){if(typeof e?.summary=="string")return e.summary;const s=e?.statusCounts||e?.counts||e?.summary?.counts,o=k(s);if(o)return o;const i={};for(const r of t){const a=y(r);i[a]=(i[a]||0)+1}return k(i)}class te{render(t,s,o){_();const i=L(s,o),r=t?.gate_id||"gate";if(!s)return{content:n`<div>${$(i,g,n`Inspecting gate <span class="font-mono">${r}</span>…`)}</div>`,isCustom:!1};const{data:a,text:l}=A(s);if(s.isError){const m=T(s);return{content:n`<div>
					${$(i,g,m?n`Aborted inspect of gate <span class="font-mono">${r}</span>`:n`Failed to inspect gate <span class="font-mono">${r}</span>`)}
					<div class="mt-1 text-xs ${m?"text-amber-600 dark:text-amber-400":"text-destructive"}">${l}</div>
				</div>`,isCustom:!1}}switch(a?.section||t?.section||"content"){case"content":return this._renderContent(i,r,a);case"verification":return this._renderVerification(i,r,a,s);case"signals":return this._renderSignals(i,r,a);default:return this._renderContent(i,r,a)}}_renderContent(t,s,o){const i=o?.signalIndex??"?",r=o?.signalId||"",a=o?.text;return{content:n`<div>
				${$(t,g,n`Inspect gate <span class="font-mono">${s}</span> — content`)}
				<div class="text-xs text-muted-foreground mt-1">Signal #${i}${r?n` · ${r}`:p}</div>
				${a?n`<div class="mt-2 text-xs bg-muted/50 rounded p-3 border border-border max-h-[400px] overflow-y-auto"><markdown-block .content=${a}></markdown-block></div>`:n`<div class="mt-2 text-xs text-muted-foreground italic">No content</div>`}
			</div>`,isCustom:!1}}_renderVerification(t,s,o,i){const r=o?.signalIndex??"?",a=o?.signalId||"",l=o?.steps||[],d=j(o,l),m=u=>{const v=u.currentTarget.parentElement,c=v.querySelector("[data-step-output]"),f=v.querySelector("[data-step-chevron]");if(!c)return;const x=c.classList.contains("hidden");c.classList.toggle("hidden"),f&&(f.textContent=x?"▴":"▾")};return{content:n`<div>
				${$(t,g,n`Inspect gate <span class="font-mono">${s}</span> — verification`)}
				<div class="text-xs text-muted-foreground mt-1">Signal #${r}${a?n` · ${a}`:p}${d?n` · ${d}`:p}</div>
				<div class="mt-2 space-y-1">
					${l.map((u,v)=>{const c=y(u),f=!!u.output,x=c==="failed",w=h[c]||c,S=u.type==="command"?"bg-muted text-muted-foreground":"bg-purple-500/20 text-purple-600 dark:text-purple-400";return n`
							<div class="border border-border rounded text-sm">
								<div
									class="p-2 flex items-center gap-2 ${f?"cursor-pointer hover:bg-accent/50":""}"
									@click=${f?m:null}
								>
									${q(c)}
									<span class="font-mono text-xs flex-1 min-w-0 truncate">${u.name}</span>
									<span class="px-1.5 py-0.5 rounded text-[10px] font-medium ${N(c)}">${w}</span>
									<span class="px-1.5 py-0.5 rounded text-[10px] font-medium ${S}">${u.type}</span>
									${V(c,u.duration_ms)?n`<span class="text-xs text-muted-foreground tabular-nums">${D(u.duration_ms)}</span>`:p}
									${f?n`<span data-step-chevron class="text-muted-foreground text-[10px] shrink-0">${x?"▴":"▾"}</span>`:p}
								</div>
								${f?u.type!=="command"?n`<div data-step-output class="${x?"":"hidden"} text-xs text-muted-foreground max-h-[300px] overflow-y-auto bg-muted/50 rounded-b p-2 border-t border-border"><markdown-block .content=${u.output}></markdown-block></div>`:n`<pre data-step-output class="${x?"":"hidden"} text-xs text-muted-foreground whitespace-pre-wrap max-h-[300px] overflow-y-auto bg-muted/50 rounded-b p-2 border-t border-border">${H(u.output)?C(R(u.output)):u.output}</pre>`:p}
							</div>
						`})}
				</div>
			</div>`,isCustom:!1}}_renderSignals(t,s,o){const i=o?.signals||[],r=i.length,a=d=>{try{return new Date(d).toLocaleString()}catch{return d}},l=n`
			<div class="mt-2 space-y-0.5">
				${i.map(d=>n`
					<div class="flex items-center gap-2 text-xs py-0.5">
						<span class="text-muted-foreground">#${d.index}</span>
						${B(d.verdict)}
						<span class="text-muted-foreground">${a(d.timestamp)}</span>
						${d.hasContent?n`<span title="Has content">📄</span>`:p}
						${d.sessionId?n`<span class="font-mono text-muted-foreground">${d.sessionId.slice(0,8)}</span>`:p}
					</div>
				`)}
			</div>
		`;if(r>5){const d=b(),m=b();return{content:n`<div>
					${F(t,g,n`Inspect gate <span class="font-mono">${s}</span> — ${r} signal${r!==1?"s":""}`,d,m,!1)}
					<div ${I(d)} class="max-h-0 overflow-hidden transition-all duration-300">
						${l}
					</div>
				</div>`,isCustom:!1}}return{content:n`<div>
				${$(t,g,n`Inspect gate <span class="font-mono">${s}</span> — ${r} signal${r!==1?"s":""}`)}
				${l}
			</div>`,isCustom:!1}}}export{te as GateInspectRenderer};
