const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/event-DYHy0FJb.js","assets/core-BEOw45JP.js"])))=>i.map(i=>d[i]);
import{_ as p}from"./mermaid-C0IQv4mH.js";import{r as m,j as t}from"./markdown-9_JKOUHQ.js";import{c as E}from"./index-Z_QI94Zg.js";import{X as k}from"./x-AprddF_b.js";import{R as T}from"./refresh-cw-Svvcff2v.js";import{E as R}from"./external-link-Dg0Hq511.js";import"./createLucideIcon-CsWFljth.js";const h=!!window.__TAURI_INTERNALS__;function D(){const[i,u]=m.useState([]),[d,l]=m.useState(null),[w,f]=m.useState(0),s=i.find(e=>e.commandId===d);m.useEffect(()=>{if(!h)return;const e=[];return(async()=>{const{listen:r,emit:c}=await p(async()=>{const{listen:a,emit:o}=await import("./event-DYHy0FJb.js");return{listen:a,emit:o}},__vite__mapDeps([0,1])),I=await r("preview:add-tab",a=>{const o=a.payload;u(n=>n.some(x=>x.commandId===o.commandId)?n:[...n,o]),l(o.commandId)});e.push(I);const j=await r("preview:remove-tab",a=>{const{commandId:o}=a.payload;u(n=>n.filter(y=>y.commandId!==o)),l(n=>n===o?null:n)});e.push(j);const N=await r("preview:focus-tab",a=>{l(a.payload.commandId)});e.push(N);const _=await r("preview:refresh-tab",a=>{f(o=>o+1)});e.push(_),await c("preview:ready",{})})(),()=>{e.forEach(r=>r())}},[]),m.useEffect(()=>{d&&!i.some(e=>e.commandId===d)&&l(i[i.length-1]?.commandId??null)},[i,d]);const b=()=>f(e=>e+1),v=async e=>{if(u(r=>r.filter(c=>c.commandId!==e)),d===e){const r=i.filter(c=>c.commandId!==e);l(r[r.length-1]?.commandId??null)}if(h){const{emit:r}=await p(async()=>{const{emit:c}=await import("./event-DYHy0FJb.js");return{emit:c}},__vite__mapDeps([0,1]));r("preview:tab-closed",{commandId:e})}},g=()=>{s&&window.open(`http://localhost:${s.port}`,"_blank")};return t.jsxs("div",{className:"flex h-screen flex-col bg-background text-foreground",children:[t.jsxs("div",{className:"flex min-h-[36px] items-center border-b border-border bg-muted/30",children:[t.jsx("div",{className:"flex flex-1 items-center overflow-x-auto",children:i.map(e=>t.jsxs("div",{className:E("flex items-center gap-1.5 px-3 py-1.5 text-xs cursor-pointer border-r border-border min-w-0 max-w-[200px] group",e.commandId===d?"bg-background text-foreground":"text-muted-foreground hover:bg-accent/50"),onClick:()=>l(e.commandId),children:[t.jsx("span",{className:"truncate",children:e.label}),t.jsxs("span",{className:"flex-shrink-0 text-xs text-muted-foreground/60",children:[":",e.port]}),t.jsx("button",{onClick:r=>{r.stopPropagation(),v(e.commandId)},className:"ml-auto flex-shrink-0 opacity-0 transition-opacity hover:text-status-error group-hover:opacity-100",children:t.jsx(k,{className:"h-3 w-3"})})]},e.commandId))}),s&&t.jsxs("div",{className:"flex flex-shrink-0 items-center gap-1 px-2",children:[t.jsxs("span",{className:"mr-1 font-mono text-xs text-muted-foreground",children:["localhost:",s.port]}),t.jsx("button",{onClick:b,className:"rounded p-1 text-muted-foreground hover:text-foreground",title:"Refresh",children:t.jsx(T,{className:"h-3.5 w-3.5"})}),t.jsx("button",{onClick:g,className:"rounded p-1 text-muted-foreground hover:text-foreground",title:"Open in browser",children:t.jsx(R,{className:"h-3.5 w-3.5"})})]})]}),t.jsx("div",{className:"relative flex-1",children:s?t.jsx("iframe",{src:`http://localhost:${s.port}`,className:"h-full w-full border-0",title:`Preview: ${s.label}`},`${s.commandId}-${w}`):t.jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"No previews open. Start a command with a port to see it here."})})]})}export{D as PreviewBrowser};
