import{b as t,A as p,o as h,n as k,e as v}from"./vendor-lit-BtHfzs80.js";import{at as I,au as w,aw as g,ax as y,x as C,y as S,av as _}from"./index-rvuS68Al.js";import{getResult as H,gateBadge as R}from"./GateToolRenderers-BmeWvfkn.js";import{ad as x}from"./vendor-lucide-DBEJLfdn.js";import"./vendor-mini-lit-Cx886NBU.js";import"./vendor-marked-_iteVaMm.js";import"./vendor-sortable-B1o3v0Qs.js";function T(a){return a>=6e4?`${(a/6e4).toFixed(1)}m`:`${(a/1e3).toFixed(1)}s`}function F(a){return a==="passed"?t`<span class="text-green-600 dark:text-green-400">✓</span>`:a==="failed"?t`<span class="text-red-600 dark:text-red-400">✗</span>`:a==="skipped"?t`<span class="text-muted-foreground">⊘</span>`:t`<span class="text-blue-600 dark:text-blue-400">●</span>`}function A(a){return a.skipped?"skipped":a.passed===!0?"passed":a.passed===!1?"failed":"running"}class M{render(c,o,i){I();const d=w(o,i),n=c?.gate_id||"gate";if(!o)return{content:t`<div>${g(d,x,t`Inspecting gate <span class="font-mono">${n}</span>…`)}</div>`,isCustom:!1};const{data:r,text:l}=H(o);if(o.isError){const e=y(o);return{content:t`<div>
					${g(d,x,e?t`Aborted inspect of gate <span class="font-mono">${n}</span>`:t`Failed to inspect gate <span class="font-mono">${n}</span>`)}
					<div class="mt-1 text-xs ${e?"text-amber-600 dark:text-amber-400":"text-destructive"}">${l}</div>
				</div>`,isCustom:!1}}switch(r?.section||c?.section||"content"){case"content":return this._renderContent(d,n,r);case"verification":return this._renderVerification(d,n,r,o);case"signals":return this._renderSignals(d,n,r);default:return this._renderContent(d,n,r)}}_renderContent(c,o,i){const d=i?.signalIndex??"?",n=i?.signalId||"",r=i?.text;return{content:t`<div>
				${g(c,x,t`Inspect gate <span class="font-mono">${o}</span> — content`)}
				<div class="text-xs text-muted-foreground mt-1">Signal #${d}${n?t` · ${n}`:p}</div>
				${r?t`<div class="mt-2 text-xs bg-muted/50 rounded p-3 border border-border max-h-[400px] overflow-y-auto"><markdown-block .content=${r}></markdown-block></div>`:t`<div class="mt-2 text-xs text-muted-foreground italic">No content</div>`}
			</div>`,isCustom:!1}}_renderVerification(c,o,i,d){const n=i?.signalIndex??"?",r=i?.signalId||"",l=i?.steps||[],s=e=>{const $=e.currentTarget.parentElement,m=$.querySelector("[data-step-output]"),u=$.querySelector("[data-step-chevron]");if(!m)return;const f=m.classList.contains("hidden");m.classList.toggle("hidden"),u&&(u.textContent=f?"▴":"▾")};return{content:t`<div>
				${g(c,x,t`Inspect gate <span class="font-mono">${o}</span> — verification`)}
				<div class="text-xs text-muted-foreground mt-1">Signal #${n}${r?t` · ${r}`:p}</div>
				<div class="mt-2 space-y-1">
					${l.map((e,$)=>{const m=A(e),u=!!e.output,f=m==="failed",b=e.type==="command"?"bg-muted text-muted-foreground":"bg-purple-500/20 text-purple-600 dark:text-purple-400";return t`
							<div class="border border-border rounded text-sm">
								<div
									class="p-2 flex items-center gap-2 ${u?"cursor-pointer hover:bg-accent/50":""}"
									@click=${u?s:null}
								>
									${F(m)}
									<span class="font-mono text-xs flex-1 min-w-0 truncate">${e.name}</span>
									<span class="px-1.5 py-0.5 rounded text-[10px] font-medium ${b}">${e.type}</span>
									${e.duration_ms!=null?t`<span class="text-xs text-muted-foreground tabular-nums">${T(e.duration_ms)}</span>`:p}
									${u?t`<span data-step-chevron class="text-muted-foreground text-[10px] shrink-0">${f?"▴":"▾"}</span>`:p}
								</div>
								${u?e.type!=="command"?t`<div data-step-output class="${f?"":"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=${e.output}></markdown-block></div>`:t`<pre data-step-output class="${f?"":"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">${C(e.output)?h(S(e.output)):e.output}</pre>`:p}
							</div>
						`})}
				</div>
			</div>`,isCustom:!1}}_renderSignals(c,o,i){const d=i?.signals||[],n=d.length,r=s=>{try{return new Date(s).toLocaleString()}catch{return s}},l=t`
			<div class="mt-2 space-y-0.5">
				${d.map(s=>t`
					<div class="flex items-center gap-2 text-xs py-0.5">
						<span class="text-muted-foreground">#${s.index}</span>
						${R(s.verdict)}
						<span class="text-muted-foreground">${r(s.timestamp)}</span>
						${s.hasContent?t`<span title="Has content">📄</span>`:p}
						${s.sessionId?t`<span class="font-mono text-muted-foreground">${s.sessionId.slice(0,8)}</span>`:p}
					</div>
				`)}
			</div>
		`;if(n>5){const s=v(),e=v();return{content:t`<div>
					${_(c,x,t`Inspect gate <span class="font-mono">${o}</span> — ${n} signal${n!==1?"s":""}`,s,e,!1)}
					<div ${k(s)} class="max-h-0 overflow-hidden transition-all duration-300">
						${l}
					</div>
				</div>`,isCustom:!1}}return{content:t`<div>
				${g(c,x,t`Inspect gate <span class="font-mono">${o}</span> — ${n} signal${n!==1?"s":""}`)}
				${l}
			</div>`,isCustom:!1}}}export{M as GateInspectRenderer};
