import{a,r as d,i as u,A as f,b as i,o as _,t as m}from"./vendor-lit-B2r-dKc0.js";import{aw as g,aI as v}from"./app-session-runtime-CeFJDILJ.js";import{h as b,a as x}from"./index-DV9GoJhq.js";var y=Object.defineProperty,k=Object.getOwnPropertyDescriptor,n=(t,e,o,c)=>{for(var r=c>1?void 0:c?k(e,o):e,l=t.length-1,p;l>=0;l--)(p=t[l])&&(r=(c?p(e,o,r):p(r))||r);return c&&r&&y(e,o,r),r};let s=class extends u{constructor(){super(...arguments),this.goalId="",this.gateId="",this.signalId="",this.stepIndex=0,this.stepName="",this.open=!1,this.initialOutput="",this.stepType="",this._chunks=[],this._completed=!1,this._finalStatus="",this._userScrolledUp=!1,this._seenEvents=new Set,this._seenEventsOrder=[],this._bootstrapSeqHighWater=-1}createRenderRoot(){return this}connectedCallback(){g(),super.connectedCallback(),this._abortCtrl=new AbortController;const t=this._abortCtrl.signal;document.addEventListener("gate-verification-event",e=>this._onEvent(e),{signal:t}),document.addEventListener("keydown",e=>this._onKeyDown(e),{signal:t})}disconnectedCallback(){super.disconnectedCallback(),this._abortCtrl?.abort(),this._abortCtrl=void 0,this._seenEvents.clear(),this._seenEventsOrder.length=0}_markEventSeen(t){if(!t)return!0;if(this._seenEvents.has(t))return!1;if(this._seenEvents.add(t),this._seenEventsOrder.push(t),this._seenEventsOrder.length>s._SEEN_CAP){const e=this._seenEventsOrder.shift();e!==void 0&&this._seenEvents.delete(e)}return!0}updated(t){if(t.has("open")&&this.open){if(this._chunks=[],this._completed=!1,this._finalStatus="",this._userScrolledUp=!1,this._seenEvents.clear(),this._seenEventsOrder.length=0,this._bootstrapSeqHighWater=-1,this.initialOutput){this._chunks=[{stream:"stdout",text:this.initialOutput}];const e=this.initialOutputSeq;typeof e=="number"&&(this._bootstrapSeqHighWater=e)}else this.goalId&&this.signalId&&this._fetchBootstrapOutput();this.requestUpdate(),requestAnimationFrame(()=>this._scrollToBottom())}}async _fetchBootstrapOutput(){try{const t=localStorage.getItem("gateway.token")||"",e=t?{Authorization:`Bearer ${t}`}:{},o=await fetch(`/api/goals/${this.goalId}/verifications/active`,{headers:e});if(!o.ok)return;const l=((await o.json()).verifications||[]).find(h=>h.signalId===this.signalId);if(!l)return;const p=l.steps?.[this.stepIndex];p?.output&&this._chunks.length===0&&(this._chunks=[{stream:"stdout",text:p.output}],this.requestUpdate(),requestAnimationFrame(()=>this._scrollToBottom()))}catch{}}_onEvent(t){const e=t.detail;if(!e||!this.open||e.signalId!==this.signalId)return;const o=v(e);if(this._markEventSeen(o)){if(e.type==="gate_verification_step_output"&&e.stepIndex===this.stepIndex){if(typeof e.seq=="number"&&e.seq<=this._bootstrapSeqHighWater)return;this._chunks=[...this._chunks,{stream:e.stream,text:e.text}],this._userScrolledUp||requestAnimationFrame(()=>this._scrollToBottom())}e.type==="gate_verification_step_complete"&&e.stepIndex===this.stepIndex&&(this._completed=!0,this._finalStatus=e.status==="passed"?"passed":"failed")}}_onKeyDown(t){t.key==="Escape"&&this.open&&this._close()}_onScroll(t){const e=t.target,o=e.scrollHeight-e.scrollTop-e.clientHeight<30;this._userScrolledUp=!o}_scrollToBottom(){const t=this.querySelector(".verif-output-body");t&&(t.scrollTop=t.scrollHeight)}_close(){this.dispatchEvent(new Event("close"))}_onBackdropClick(t){t.target.classList.contains("verif-output-backdrop")&&this._close()}render(){return this.open?i`
			<div class="verif-output-backdrop fixed inset-0 z-50 flex items-center justify-center"
				style="background:rgba(0,0,0,0.6);backdrop-filter:blur(2px);"
				@click=${this._onBackdropClick}>
				<div class="verif-output-container flex flex-col rounded-lg overflow-hidden shadow-2xl"
					style="background:#18181b;max-width:56rem;width:calc(100% - 2rem);max-height:80vh;">
					<!-- Header -->
					<div class="flex items-center justify-between px-4 py-2.5 border-b" style="border-color:#27272a;">
						<div class="flex items-center gap-2">
							${this._completed?i`<span class="${this._finalStatus==="passed"?"text-green-500":"text-red-500"}">${this._finalStatus==="passed"?"✓":"✗"}</span>`:i`<span class="text-amber-400 animate-pulse">\u25CF</span>`}
							<span class="font-mono text-sm" style="color:#d4d4d8;">${this.stepName||`Step ${this.stepIndex+1}`}</span>
							${this._completed?i`
								<span class="text-xs px-1.5 py-0.5 rounded ${this._finalStatus==="passed"?"text-green-400":"text-red-400"}"
									style="background:${this._finalStatus==="passed"?"rgba(34,197,94,0.15)":"rgba(239,68,68,0.15)"}">
									${this._finalStatus}
								</span>
							`:i`
								<span class="text-xs px-1.5 py-0.5 rounded text-amber-400" style="background:rgba(245,158,11,0.15)">running</span>
							`}
						</div>
						<button class="text-zinc-400 hover:text-zinc-200 transition-colors" style="font-size:18px;line-height:1;padding:2px 6px;" @click=${this._close} title="Close">\u2715</button>
					</div>
					<!-- Body -->
					${this._isAgentStep()?i`<div class="verif-output-body flex-1 overflow-y-auto px-4 py-3 text-sm leading-relaxed"
							style="background:#18181b;margin:0;color:#d4d4d8;"
							@scroll=${this._onScroll}>${this._renderMarkdownOutput()}</div>`:i`<pre class="verif-output-body flex-1 overflow-y-auto px-4 py-3 text-xs leading-relaxed"
							style="background:#18181b;font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;margin:0;white-space:pre-wrap;word-break:break-all;"
							@scroll=${this._onScroll}>${this._renderOutput()}</pre>`}
				</div>
			</div>
		`:f}_isAgentStep(){return this.stepType!==""&&this.stepType!=="command"}_renderMarkdownOutput(){if(this._chunks.length===0)return i`<span style="color:#71717a;">Waiting for output\u2026</span>`;const t=this._chunks.map(e=>e.text).join("");return i`<markdown-block .content=${t}></markdown-block>`}_renderOutput(){return this._chunks.length===0?i`<span style="color:#71717a;">Waiting for output\u2026</span>`:i`${this._chunks.map(t=>b(t.text)?i`<span style="color:${t.stream==="stderr"?"#fbbf24":"#d4d4d8"};">${_(x(t.text))}</span>`:t.stream==="stderr"?i`<span style="color:#fbbf24;">${t.text}</span>`:i`<span style="color:#d4d4d8;">${t.text}</span>`)}`}};s._SEEN_CAP=2048;n([a()],s.prototype,"goalId",2);n([a()],s.prototype,"gateId",2);n([a()],s.prototype,"signalId",2);n([a({type:Number})],s.prototype,"stepIndex",2);n([a()],s.prototype,"stepName",2);n([a({type:Boolean})],s.prototype,"open",2);n([a()],s.prototype,"initialOutput",2);n([a()],s.prototype,"stepType",2);n([d()],s.prototype,"_chunks",2);n([d()],s.prototype,"_completed",2);n([d()],s.prototype,"_finalStatus",2);s=n([m("verification-output-modal")],s);
