import{D as h,n as m,c as u,B as f}from"./vendor-mini-lit-CpUQub-j.js";import{A as c,b as o,r as l,t as x}from"./vendor-lit-B2r-dKc0.js";import{p as g}from"./app-review-C3CmcSYC.js";import"./app-session-runtime-CeFJDILJ.js";import"./vendor-lucide-B9Yl1Gez.js";import"./vendor-marked-_iteVaMm.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";var v=Object.defineProperty,y=Object.getOwnPropertyDescriptor,a=(t,e,n,s)=>{for(var r=s>1?void 0:s?y(e,n):e,d=t.length-1,p;d>=0;d--)(p=t[d])&&(r=(s?p(e,n,r):p(r))||r);return s&&r&&v(e,n,r),r};let i=class extends h{constructor(){super(...arguments),this.sections=[],this.totalTokens=0,this.loading=!0,this.error="",this.expandedSections=new Set,this.copied=!1,this.sessionId="",this.modalWidth="min(700px, 90vw)",this.modalHeight="min(80vh, 800px)"}createRenderRoot(){return this}static show(t){const e=new i;e.sessionId=t,document.body.appendChild(e),e.open(),e.fetchSections()}async fetchSections(){try{const t=await g(`/api/sessions/${this.sessionId}/prompt-sections`);if(!t.ok){this.error=`Failed to load prompt sections (${t.status})`,this.loading=!1;return}const e=await t.json();this.sections=e.sections??[],this.totalTokens=e.totalTokens??0}catch(t){this.error=`Failed to load prompt sections: ${t}`}finally{this.loading=!1}}truncatePath(t){if(!(t.includes("/")||t.includes("\\")))return{display:t,full:t,isPath:!1};const s=t.replace(/\\/g,"/").split("/");return{display:s.length>3?"…/"+s.slice(-3).join("/"):t,full:t,isPath:!0}}toggleSection(t){const e=new Set(this.expandedSections);e.has(t)?e.delete(t):e.add(t),this.expandedSections=e}async copyAll(){const t=this.sections.map(e=>`# ${e.label}

${e.content}`).join(`

---

`);try{await navigator.clipboard.writeText(t),this.copied=!0,setTimeout(()=>{this.copied=!1},2e3)}catch{const e=document.createElement("textarea");e.value=t,document.body.appendChild(e),e.select(),document.execCommand("copy"),document.body.removeChild(e),this.copied=!0,setTimeout(()=>{this.copied=!1},2e3)}}renderSection(t,e){const n=this.expandedSections.has(e);return o`
			<div class="border border-border rounded-lg overflow-hidden">
				<button
					class="w-full flex items-center gap-2 p-3 text-left hover:bg-secondary/50 transition-colors"
					@click=${()=>this.toggleSection(e)}
				>
					<svg
						width="16"
						height="16"
						viewBox="0 0 24 24"
						fill="none"
						stroke="currentColor"
						stroke-width="2"
						class="shrink-0 transition-transform ${n?"rotate-90":""}"
					>
						<path d="m9 18 6-6-6-6"></path>
					</svg>
					<div class="flex-1 min-w-0 flex items-center gap-2">
						${(()=>{const s=this.truncatePath(t.source);return o`
						<span
							class="text-sm text-foreground truncate ${s.isPath?"font-mono":"font-medium"}"
							title="${s.full}"
							style="max-width: 70%"
						>${s.display}</span>
						<span class="text-[11px] px-1.5 py-0.5 rounded bg-secondary text-muted-foreground shrink-0">${t.label}</span>
						`})()}
					</div>
					<span class="text-xs text-muted-foreground shrink-0">${this.formatTokens(t.tokens)}</span>
				</button>
				${n?o`
							<div class="border-t border-border">
								<pre
									class="text-xs text-foreground p-3 m-0 overflow-y-auto"
									style="white-space: pre-wrap; word-wrap: break-word; max-height: 400px; background: var(--muted);"
								>${t.content}</pre>
							</div>
						`:c}
			</div>
		`}formatTokens(t){return t<1e3?`~${t} tokens`:`~${(t/1e3).toFixed(1)}k tokens`}renderContent(){return o`
			${m({className:"h-full flex flex-col",children:o`
					${u({title:"System Prompt Inspector",description:this.totalTokens>0?`Assembled prompt sections for this session — ~${this.formatTokens(this.totalTokens)} total`:"Assembled prompt sections for this session"})}

					<div class="flex-1 overflow-y-auto mt-4 space-y-2">
						${this.loading?o`<div class="text-center py-8 text-muted-foreground">Loading...</div>`:this.error?o`<div class="text-center py-8 text-destructive">${this.error}</div>`:this.sections.length===0?o`<div class="text-center py-8 text-muted-foreground">No prompt sections available</div>`:this.sections.map((t,e)=>this.renderSection(t,e))}
					</div>

					${!this.loading&&this.sections.length>0?o`
								<div class="mt-4 flex justify-end border-t border-border pt-3">
									${f({variant:"outline",size:"sm",onClick:()=>this.copyAll(),children:this.copied?"Copied!":"Copy All"})}
								</div>
							`:c}
				`})}
		`}};a([l()],i.prototype,"sections",2);a([l()],i.prototype,"totalTokens",2);a([l()],i.prototype,"loading",2);a([l()],i.prototype,"error",2);a([l()],i.prototype,"expandedSections",2);a([l()],i.prototype,"copied",2);i=a([x("system-prompt-dialog")],i);export{i as SystemPromptDialog};
