import{r as c,e as tt,v as Se,j as t,u as rt,K as st,g as nt}from"./index-CgQG7qql.js";import{b as ot}from"./babel-CO2_o974.js";import{r as it}from"./index-DQh7GDfj.js";import we from"./manifest-2B7RT76f.js";let xe=null;function at(){if(xe)return xe;if(typeof Bun<"u"&&Bun.Transpiler){const o=new Bun.Transpiler({loader:"tsx"});return xe=(n,l)=>o.transformSync(n),xe}throw new Error("No transpiler available. Pass a custom transpile function or run in Bun/browser.")}let He=null;function lt(o){He=o}function ct(){return He??at()}function dt(o){const n=[],l=/import\s+(?:(\*\s+as\s+(\w+))|(?:\{([^}]+)\})|(\w+)(?:\s*,\s*\{([^}]+)\})?)\s+from\s+["']([^"']+)["']/g;let h;for(;(h=l.exec(o))!==null;){const x=h[6],b=[];let g=!1;if(h[1]&&b.push({imported:"*",local:h[2]}),h[3])for(const d of h[3].split(",")){const u=d.trim().split(/\s+as\s+/);u[0]&&b.push({imported:u[0].trim(),local:(u[1]||u[0]).trim()})}if(h[4]&&(b.push({imported:"default",local:h[4]}),g=!0),h[5])for(const d of h[5].split(",")){const u=d.trim().split(/\s+as\s+/);u[0]&&b.push({imported:u[0].trim(),local:(u[1]||u[0]).trim()})}n.push({source:x,specifiers:b,isDefault:g})}return n}function ut(o){let n=o;return n=n.replace(/import\s+(?:[\s\S]*?)\s+from\s+["'][^"']+["'];?\n?/g,""),n=n.replace(/import\s+type\s+[\s\S]*?from\s+["'][^"']+["'];?\n?/g,""),n=n.replace(/export\s+const\s+(\w+)/g,"__exports.$1"),n=n.replace(/export\s+function\s+(\w+)/g,"__exports.$1 = function $1"),n=n.replace(/export\s+class\s+(\w+)/g,"__exports.$1 = class $1"),n=n.replace(/export\s+default\s+/g,"__exports.default = "),n=n.replace(/export\s+\{([^}]+)\};?/g,(l,h)=>h.split(",").map(x=>{const b=x.trim().split(/\s+as\s+/),g=b[0]?.trim(),d=(b[1]||b[0])?.trim();return g&&d?`__exports.${d} = ${g};`:""}).join(`
`)),n}const ft=new Set(["gridboard","react","react/jsx-runtime"]);function pt(o,n,l){const h=dt(o),x=[];for(const p of h)if(ft.has(p.source)||p.source in l){const P=`__ext_${p.source.replace(/[^a-zA-Z0-9]/g,"_")}`;x.push(`var ${P} = __externals["${p.source}"];`);for(const D of p.specifiers)D.imported==="*"?x.push(`var ${D.local} = ${P};`):D.imported==="default"?x.push(`var ${D.local} = ${P}.default ?? ${P};`):x.push(`var ${D.local} = ${P}["${D.imported}"];`)}else if(!p.source.startsWith("."))throw new Error(`[${n}] Unknown import "${p.source}". Only gridboard, react, and react/jsx-runtime are supported in tile preview.`);l.react&&!x.some(p=>p.includes("var React"))&&x.unshift('var React = __externals["react"];');const g=ct()(o,n),d=ut(g),u=`${x.join(`
`)}
var __exports = {};
${d}
return __exports;`;let S;try{S=new Function("__externals",u)(l)}catch(p){throw new Error(`[${n}] Runtime error: ${p.message}`)}const j=S.default;if(!j||typeof j.render!="function")throw new Error(`[${n}] Tile must export a defineTile() result as default export with a render function.`);return j}function ht(o,n,l){const h=new Map,x=[],b=new Map(o.map(g=>[g.path,g.content]));for(const[g,d]of Object.entries(n.tiles)){const u=d.component,S=b.get(u)??b.get(u.replace(/^\//,""))??b.get(`/${u}`);if(S===void 0){const j=`Tile component file not found: ${u}`;x.push({tileId:g,message:j}),h.set(g,{definition:null,error:j});continue}try{const j=pt(S,u,l);h.set(g,{definition:j})}catch(j){const p=j.message;x.push({tileId:g,message:p}),h.set(g,{definition:null,error:p})}}return{tiles:h,errors:x}}function gt(o){let n=0;for(let l=0;l<o.length;l++)n=(n<<5)-n+o.charCodeAt(l)|0;return n.toString(36)}lt((o,n)=>ot.transform(o,{presets:["react","typescript"],filename:n,sourceType:"module"}).code??"");function mt(o){const[n,l]=c.useState({tiles:new Map,errors:[]}),h=c.useRef(),x=c.useRef(""),b=c.useMemo(()=>o.filter(g=>/\.(tsx?|jsx?)$/.test(g.path)||g.path.endsWith("board.json")).map(g=>`${g.path}:${g.content.length}:${gt(g.content)}`).join("|"),[o]);return c.useEffect(()=>{if(o.length!==0&&b!==x.current)return h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{x.current=b;try{const g=o.find(p=>p.path==="board.json"||p.path.endsWith("/board.json"));if(!g){l({tiles:new Map,errors:[{tileId:"board",message:"board.json not found"}]});return}let d;try{d=JSON.parse(g.content)}catch(p){l({tiles:new Map,errors:[{tileId:"board",message:`Failed to parse board.json: ${p.message}`}]});return}if(!d.tiles||typeof d.tiles!="object"){l({tiles:new Map,errors:[{tileId:"board",message:"board.json has no tiles section"}]});return}const u={react:Se,"react/jsx-runtime":tt,gridboard:{defineTile:p=>p}},S=o.map(p=>({path:p.path,content:p.content})),j=ht(S,d,u);l(j)}catch(g){l({tiles:new Map,errors:[{tileId:"compiler",message:g.message}]})}},800),()=>{h.current&&clearTimeout(h.current)}},[b,o]),n}class xt extends Se.Component{state={error:null};static getDerivedStateFromError(n){return{error:n}}componentDidCatch(n){this.props.onError?.(this.props.tileId,n)}render(){return this.state.error?t.jsxs("div",{style:{padding:16,color:"var(--error, #ef4444)",fontSize:12,fontFamily:"var(--font-mono, monospace)",background:"var(--tile-bg, rgba(24,24,27,0.85))",width:"100%",height:"100%",overflow:"auto"},children:[t.jsx("div",{style:{fontWeight:600,marginBottom:8},children:"Render Error"}),this.state.error.message]}):this.props.children}}const bt=[{dir:"n",cursor:"n-resize",style:{top:-4,left:"10%",width:"80%",height:8}},{dir:"s",cursor:"s-resize",style:{bottom:-4,left:"10%",width:"80%",height:8}},{dir:"e",cursor:"e-resize",style:{right:-4,top:"10%",width:8,height:"80%"}},{dir:"w",cursor:"w-resize",style:{left:-4,top:"10%",width:8,height:"80%"}},{dir:"ne",cursor:"ne-resize",style:{top:-4,right:-4,width:12,height:12}},{dir:"nw",cursor:"nw-resize",style:{top:-4,left:-4,width:12,height:12}},{dir:"se",cursor:"se-resize",style:{bottom:-4,right:-4,width:12,height:12}},{dir:"sw",cursor:"sw-resize",style:{bottom:-4,left:-4,width:12,height:12}}];function yt({tileId:o,definition:n,compilationError:l,data:h,loading:x,error:b,width:g,height:d,themeCSS:u,isSelected:S,isResizing:j,onSelect:p,onRenderError:P,onRemove:D}){const f=g,y=d-32,k=c.useRef(0),C=c.useRef(n);n!==C.current&&(k.current++,C.current=n);const r=c.useRef(null),[G,T]=c.useState(null),U=c.useRef(null),N=c.useRef(null);c.useEffect(()=>{const z=r.current;if(!z||U.current)return;const W=z.attachShadow({mode:"open"});U.current=W;const B=document.createElement("style");B.textContent=`
      @keyframes spin { to { transform: rotate(360deg); } }
      @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
    `,W.appendChild(B);const K=document.createElement("style");K.dataset.role="theme",W.appendChild(K),N.current=K;const de=document.createElement("div");de.style.cssText="width:100%;height:100%;overflow:hidden;position:relative;",W.appendChild(de),T(de)},[]),c.useEffect(()=>{N.current&&(N.current.textContent=u)},[u]);let V=null;if(!n)V=t.jsx("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted, #52525b)",fontSize:12,fontFamily:"var(--font-family, sans-serif)",background:"var(--tile-bg, rgba(24,24,27,0.85))"},children:t.jsxs("div",{style:{textAlign:"center",display:"flex",flexDirection:"column",alignItems:"center",gap:8},children:[t.jsx("div",{style:{width:20,height:20,border:"2px solid rgba(255,255,255,0.2)",borderTopColor:"var(--accent, #f97316)",borderRadius:"50%",animation:"spin 0.8s linear infinite"}}),t.jsx("span",{children:"Compiling…"})]})});else{const z={};if(n.params)for(const[B,K]of Object.entries(n.params))z[B]=K.default;const W=n.render;V=t.jsx(xt,{tileId:o,onError:P,children:t.jsx(W,{data:h,width:f,height:y,loading:x,error:b,params:z})},k.current)}const ce=S?"#f97316":l?"var(--error, #ef4444)":"var(--tile-border, rgba(255,255,255,0.08))";return t.jsxs("div",{style:{position:"absolute",inset:0,borderRadius:"var(--tile-radius, 10px)",border:`1.5px solid ${ce}`,background:"var(--tile-bg, rgba(24,24,27,0.85))",boxSizing:"border-box",overflow:"hidden",display:"flex",flexDirection:"column",userSelect:"none",transition:"border-color 0.15s ease"},onClick:()=>p(o),onMouseEnter:z=>{!S&&!l&&(z.currentTarget.style.borderColor="var(--tile-border-hover, rgba(249,115,22,0.4))")},onMouseLeave:z=>{!S&&!l&&(z.currentTarget.style.borderColor="var(--tile-border, rgba(255,255,255,0.08))")},children:[t.jsxs("div",{"data-drag-handle":!0,style:{height:32,minHeight:32,display:"flex",alignItems:"center",paddingLeft:12,paddingRight:8,cursor:"grab",borderBottom:"1px solid var(--tile-border, rgba(255,255,255,0.08))",background:"rgba(9,9,11,0.4)",flexShrink:0},children:[t.jsx("span",{style:{marginRight:8,color:"var(--text-muted, #52525b)",fontSize:10,letterSpacing:1,lineHeight:1},children:"⠿"}),t.jsx("span",{style:{fontSize:12,fontFamily:"var(--font-family, -apple-system, sans-serif)",color:"var(--text-secondary, #a1a1aa)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:n?.label??o}),x&&t.jsx("span",{style:{marginLeft:6,width:6,height:6,borderRadius:"50%",background:"var(--accent, #f97316)",display:"inline-block",animation:"pulse 1.2s ease-in-out infinite"}}),S&&D&&t.jsx("button",{onClick:z=>{z.stopPropagation(),D(o)},style:{marginLeft:4,width:20,height:20,borderRadius:4,border:"none",background:"transparent",color:"var(--text-muted, #52525b)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",fontSize:14,lineHeight:1,padding:0},onMouseEnter:z=>{z.target.style.color="var(--error, #ef4444)"},onMouseLeave:z=>{z.target.style.color="var(--text-muted, #52525b)"},title:"Remove from board",children:"✕"})]}),t.jsx("div",{ref:r,style:{flex:1,overflow:"hidden",position:"relative"}}),G&&it.createPortal(V,G),l&&t.jsxs("div",{style:{position:"absolute",inset:0,top:32,background:"rgba(9,9,11,0.88)",display:"flex",flexDirection:"column",padding:14,gap:8,overflow:"auto"},onClick:z=>z.stopPropagation(),children:[t.jsx("div",{style:{fontSize:11,fontWeight:600,color:"var(--error, #ef4444)",fontFamily:"var(--font-family, sans-serif)",textTransform:"uppercase",letterSpacing:"0.06em"},children:"Compilation Error"}),t.jsx("pre",{style:{fontSize:11,fontFamily:"var(--font-mono, monospace)",color:"rgba(239,68,68,0.85)",margin:0,whiteSpace:"pre-wrap",wordBreak:"break-word",lineHeight:1.5},children:l})]}),j&&t.jsxs("div",{style:{position:"absolute",inset:0,background:"var(--overlay-bg, rgba(9,9,11,0.72))",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:10,pointerEvents:"none"},children:[t.jsx("div",{style:{width:20,height:20,border:"2px solid rgba(255,255,255,0.2)",borderTopColor:"var(--accent, #f97316)",borderRadius:"50%",animation:"spin 0.8s linear infinite"}}),t.jsx("span",{style:{fontSize:12,color:"var(--text-secondary, #a1a1aa)",fontFamily:"var(--font-family, sans-serif)"},children:"Resizing…"})]}),S&&bt.map(({dir:z,style:W,cursor:B})=>t.jsx("div",{"data-resize-handle":!0,"data-resize-direction":z,style:{position:"absolute",...W,cursor:B,background:"var(--accent, #f97316)",borderRadius:2,opacity:.85,zIndex:10,pointerEvents:"all"}},z)),t.jsx("style",{children:`
        @keyframes pulse {
          0%, 100% { opacity: 1; }
          50% { opacity: 0.3; }
        }
        @keyframes spin {
          to { transform: rotate(360deg); }
        }
      `})]})}const je={width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"},wt=()=>t.jsxs("svg",{...je,children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),Fe=()=>t.jsxs("svg",{...je,children:[t.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),De=()=>t.jsxs("svg",{...je,children:[t.jsx("rect",{x:"3",y:"3",width:"7",height:"7"}),t.jsx("rect",{x:"14",y:"3",width:"7",height:"7"}),t.jsx("rect",{x:"3",y:"14",width:"7",height:"7"}),t.jsx("rect",{x:"14",y:"14",width:"7",height:"7"})]}),vt=o=>({width:280,minWidth:280,height:"100%",background:"rgba(24, 24, 27, 0.97)",borderLeft:"1px solid #27272a",display:"flex",flexDirection:"column",overflow:"hidden",flexShrink:0,marginRight:o?0:-280,transition:"margin-right 0.25s cubic-bezier(0.4, 0, 0.2, 1)"}),St={display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 14px",borderBottom:"1px solid #27272a",flexShrink:0},jt={display:"flex",alignItems:"center",gap:8,color:"#fafafa",fontSize:13,fontWeight:600,letterSpacing:"0.01em"},zt={background:"none",border:"none",cursor:"pointer",color:"#71717a",padding:4,borderRadius:4,display:"flex",alignItems:"center",justifyContent:"center",transition:"color 0.15s"},kt={flex:1,overflowY:"auto",padding:"12px",display:"flex",flexDirection:"column",gap:8},$t={display:"flex",alignItems:"center",justifyContent:"center",gap:6,width:"100%",padding:"8px 12px",background:"#f97316",border:"none",borderRadius:6,color:"#fff",fontSize:12,fontWeight:600,cursor:"pointer",letterSpacing:"0.02em",transition:"background 0.15s",marginBottom:4},_e={color:"#52525b",fontSize:10,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase",padding:"4px 2px 2px"},Ct={flex:1,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:8,color:"#52525b",fontSize:12,textAlign:"center",padding:"32px 16px"};function Oe({tile:o,onAdd:n}){const l={background:"#27272a",border:"1px solid #3f3f46",borderRadius:8,padding:12,display:"flex",flexDirection:"column",gap:6,transition:"border-color 0.15s, background 0.15s"},h={display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},x={color:"#fafafa",fontSize:13,fontWeight:600,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},b={display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},g={fontSize:10,fontWeight:600,color:"#a1a1aa",background:"#3f3f46",borderRadius:4,padding:"2px 6px",letterSpacing:"0.05em",textTransform:"uppercase"},d={fontSize:10,fontWeight:500,color:"#71717a",background:"#1c1c1f",borderRadius:4,padding:"2px 6px",border:"1px solid #3f3f46"},u={color:"#a1a1aa",fontSize:11,lineHeight:1.5},S={alignSelf:"flex-start",display:"flex",alignItems:"center",gap:4,padding:"5px 10px",background:"transparent",border:"1px solid #f97316",borderRadius:5,color:"#f97316",fontSize:11,fontWeight:600,cursor:"pointer",letterSpacing:"0.02em",transition:"background 0.15s, color 0.15s",marginTop:2},j=o.definition?.render;return t.jsxs("div",{style:l,children:[j&&t.jsx("div",{style:{width:"100%",height:80,borderRadius:6,overflow:"hidden",background:"#18181b",border:"1px solid #27272a",pointerEvents:"none",position:"relative"},children:t.jsx(Et,{children:t.jsx(j,{data:null,width:256,height:80,loading:!1,error:null,params:o.definition?.params?Object.fromEntries(Object.entries(o.definition.params).map(([p,P])=>[p,P.default])):{}})})}),t.jsxs("div",{style:h,children:[t.jsx("span",{style:x,children:o.label}),t.jsxs("div",{style:b,children:[o.status==="disabled"&&t.jsx("span",{style:g,children:"disabled"}),o.minSize&&t.jsxs("span",{style:d,children:[o.minSize.cols,"×",o.minSize.rows]})]})]}),o.description&&t.jsx("p",{style:u,children:o.description}),t.jsxs("button",{style:S,onClick:()=>n(o.tileId),onMouseEnter:p=>{p.currentTarget.style.background="#f97316",p.currentTarget.style.color="#fff"},onMouseLeave:p=>{p.currentTarget.style.background="transparent",p.currentTarget.style.color="#f97316"},children:[t.jsx(Fe,{}),"Add to Board"]})]})}function Tt({isOpen:o,onClose:n,tiles:l,onAddTile:h,onCreateTile:x}){const b=Array.from(l.values()),g=b.filter(f=>f.status==="available"),d=b.filter(f=>f.status==="disabled"),u=b.length===0,[S,j]=c.useState(!1),[p,P]=c.useState(""),D=c.useRef(null);c.useEffect(()=>{S&&D.current?.focus()},[S]);const X=()=>{const f=p.trim();f&&(x(f),P(""),j(!1))};return t.jsxs("div",{style:vt(o),"aria-hidden":!o,children:[t.jsxs("div",{style:St,children:[t.jsxs("div",{style:jt,children:[t.jsx(De,{}),"Tile Gallery"]}),t.jsx("button",{style:zt,onClick:n,"aria-label":"Close gallery",onMouseEnter:f=>{f.currentTarget.style.color="#fafafa"},onMouseLeave:f=>{f.currentTarget.style.color="#71717a"},children:t.jsx(wt,{})})]}),t.jsxs("div",{style:kt,children:[S?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6,background:"#27272a",border:"1px solid #f97316",borderRadius:8,padding:10},children:[t.jsx("textarea",{ref:D,value:p,onChange:f=>P(f.target.value),onKeyDown:f=>{f.key==="Enter"&&!f.shiftKey&&(f.preventDefault(),X()),f.key==="Escape"&&(j(!1),P(""))},placeholder:"Describe the tile you want...",rows:2,style:{width:"100%",resize:"none",background:"#18181b",color:"#fafafa",border:"1px solid #3f3f46",borderRadius:6,padding:"8px 10px",fontSize:12,lineHeight:1.5,fontFamily:"inherit",outline:"none"}}),t.jsxs("div",{style:{display:"flex",gap:6,justifyContent:"flex-end"},children:[t.jsx("button",{onClick:()=>{j(!1),P("")},style:{padding:"5px 10px",background:"transparent",border:"1px solid #3f3f46",borderRadius:5,color:"#71717a",fontSize:11,fontWeight:500,cursor:"pointer"},children:"Cancel"}),t.jsx("button",{onClick:X,disabled:!p.trim(),style:{padding:"5px 10px",background:p.trim()?"#f97316":"#3f3f46",border:"none",borderRadius:5,color:"#fff",fontSize:11,fontWeight:600,cursor:p.trim()?"pointer":"default",transition:"background 0.15s"},children:"Create"})]})]}):t.jsxs("button",{style:$t,onClick:()=>j(!0),onMouseEnter:f=>{f.currentTarget.style.background="#ea6c0a"},onMouseLeave:f=>{f.currentTarget.style.background="#f97316"},children:[t.jsx(Fe,{}),"Create New Tile"]}),u&&t.jsxs("div",{style:Ct,children:[t.jsx(De,{}),t.jsx("span",{children:"No tiles available."}),t.jsx("span",{style:{color:"#71717a"},children:"Create one to get started!"})]}),g.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{style:_e,children:"Available"}),g.map(f=>t.jsx(Oe,{tile:f,onAdd:h},f.tileId))]}),d.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{..._e,marginTop:g.length>0?8:0},children:"Disabled"}),d.map(f=>t.jsx(Oe,{tile:f,onAdd:h},f.tileId))]})]})]})}class Et extends Se.Component{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}render(){return this.state.hasError?t.jsx("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#52525b",fontSize:10},children:"Preview unavailable"}):this.props.children}}const Le={width:13,height:13,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"},It=()=>t.jsxs("svg",{...Le,children:[t.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"1"}),t.jsx("line",{x1:"3",y1:"9",x2:"21",y2:"9"}),t.jsx("line",{x1:"3",y1:"15",x2:"21",y2:"15"}),t.jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"}),t.jsx("line",{x1:"15",y1:"3",x2:"15",y2:"21"})]}),Mt=()=>t.jsxs("svg",{...Le,children:[t.jsx("rect",{x:"3",y:"3",width:"7",height:"7"}),t.jsx("rect",{x:"14",y:"3",width:"7",height:"7"}),t.jsx("rect",{x:"3",y:"14",width:"7",height:"7"}),t.jsx("rect",{x:"14",y:"14",width:"7",height:"7"})]});function We(o){return{display:"flex",alignItems:"center",gap:5,padding:"4px 8px",background:o?"rgba(249,115,22,0.1)":"transparent",border:o?"1px solid rgba(249,115,22,0.4)":"1px solid transparent",borderRadius:5,color:o?"#f97316":"#71717a",fontSize:11,fontWeight:o?600:400,cursor:"pointer",transition:"background 0.15s, color 0.15s"}}function Rt({onToggleGallery:o,isGalleryOpen:n,onToggleGrid:l,showGrid:h,boardInfo:x}){const{width:b,height:g,columns:d,rows:u,activeTiles:S}=x;return t.jsxs("div",{style:{height:36,background:"rgba(24,24,27,0.92)",backdropFilter:"blur(8px)",borderTop:"1px solid #27272a",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"0 12px",flexShrink:0,userSelect:"none"},children:[t.jsxs("div",{style:{color:"#52525b",fontSize:11,display:"flex",alignItems:"center",gap:4},children:[t.jsxs("span",{children:[b,"×",g]}),t.jsx("span",{style:{color:"#3f3f46"},children:"·"}),t.jsxs("span",{children:[d,"×",u," grid"]}),t.jsx("span",{style:{color:"#3f3f46"},children:"·"}),t.jsxs("span",{children:[S," ",S===1?"tile":"tiles"]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:2},children:[t.jsxs("button",{onClick:l,"aria-pressed":h,style:We(h),children:[t.jsx(It,{}),"Grid"]}),t.jsxs("button",{onClick:o,"aria-pressed":n,style:We(n),children:[t.jsx(Mt,{}),"Gallery"]})]})]})}async function ve(o){try{const n=await st(o,{embedFonts:!1});if(!n)return null;const x=(await n.toPng({scale:.5})).src.match(/^data:([^;]+);base64,(.+)$/);return x?{media_type:x[1],data:x[2]}:null}catch{return null}}function Be(o){const n=o.find(l=>l.path==="board.json"||l.path.endsWith("/board.json"));if(!n)return null;try{return JSON.parse(n.content)}catch{return null}}function Pt(o){return o.find(l=>l.path==="theme.css"||l.path.endsWith("/theme.css"))?.content||""}function Dt(o){const n=o.board.width/o.board.columns,l=o.board.height/o.board.rows;return[`repeating-linear-gradient(90deg, var(--board-grid-line, rgba(255,255,255,0.04)) 0px, var(--board-grid-line, rgba(255,255,255,0.04)) 1px, transparent 1px, transparent ${n}px)`,`repeating-linear-gradient(0deg, var(--board-grid-line, rgba(255,255,255,0.04)) 0px, var(--board-grid-line, rgba(255,255,255,0.04)) 1px, transparent 1px, transparent ${l}px)`].join(", ")}function fe(o,n,l,h,x,b){for(const[g,d]of Object.entries(o)){if(g===b||d.status!=="active")continue;const u=d.position.col,S=d.position.row,j=d.size.cols,p=d.size.rows;if(n<u+j&&n+h>u&&l<S+p&&l+x>S)return!0}return!1}function _t(o,n,l,h){for(let x=0;x<=n.rows-h;x++)for(let b=0;b<=n.columns-l;b++)if(!fe(o,b,x,l,h,""))return{col:b,row:x};return null}async function le(o,n){const l=nt();await fetch(`${l}/api/files`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:o,content:n})})}const Ot={board:{width:800,height:800,columns:8,rows:8},tiles:{}};function Wt({files:o,selection:n,onSelect:l,mode:h,imageVersion:x,initParams:b,onActiveFileChange:g,actionRequest:d,onActionResult:u,onNotifyAgent:S,navigateRequest:j,onNavigateComplete:p,commands:P,readonly:D,editing:X}){const f=!D&&X===!1,y=D||f,k=y?(()=>{}):l,C=y?void 0:S,r=c.useMemo(()=>Be(o)??Ot,[o]),G=c.useMemo(()=>Pt(o),[o]),T=mt(o),[U,N]=c.useState(!1),[V,ce]=c.useState(!0),[z,W]=c.useState(null),[B,K]=c.useState(new Set);c.useEffect(()=>{!n&&z&&W(null)},[n,z]);const[de,be]=c.useState(new Map),[E,pe]=c.useState(null),[v,ue]=c.useState(null),[ze,ke]=c.useState(new Map),[$e,Ce]=c.useState(new Map),Z=c.useRef(null),Ne=c.useRef(null),[he,Te]=c.useState(new Set);c.useEffect(()=>{he.size!==0&&Te(e=>{const i=new Set(e);for(const s of e){const a=r.tiles[s];(!a||a.status!=="active")&&i.delete(s)}return i.size===e.size?e:i})},[r,he]);const se=c.useMemo(()=>Object.entries(r.tiles).filter(([e,i])=>i.status==="active"&&!he.has(e)),[r,he]),ne=c.useRef(new Set);c.useEffect(()=>{if(!C)return;const e=[];for(const s of T.errors)B.has(s.tileId)||e.push({key:`compile:${s.tileId}:${s.message}`,message:`Compilation error in tile "${s.tileId}": ${s.message}
Please fix the tile component and save.`,summary:`Tile "${s.tileId}" failed to compile`});for(const[s,a]of T.tiles)a.error&&(B.has(s)||e.push({key:`compile:${s}:${a.error}`,message:`Compilation error in tile "${s}": ${a.error}
Please fix the tile component and save.`,summary:`Tile "${s}" failed to compile`}));const i=new Set(e.map(s=>s.key));for(const s of ne.current)i.has(s)||ne.current.delete(s);for(const s of e)ne.current.has(s.key)||(ne.current.add(s.key),C({type:"tile_error",message:s.message,severity:"warning",summary:s.summary}))},[T,C,B]);const Ae=c.useCallback((e,i)=>{if(!C||B.has(e))return;const s=`render:${e}:${i.message}`;if(ne.current.has(s))return;ne.current.add(s);const a=r.tiles[e];C({type:"tile_error",message:`Runtime render error in tile "${e}" (${a?.component??"unknown"}):
${i.message}
Please fix the tile component and save.`,severity:"warning",summary:`Tile "${e}" render error`})},[C,r,B]),ye=c.useRef(T.tiles);ye.current=T.tiles;const Ee=c.useMemo(()=>{if(!r)return"";const e=[];for(const[i,s]of T.tiles){const a=s.definition;if(!a?.dataSource)continue;const m=r.tiles[i];!m||m.status!=="active"||e.push(`${i}:${a.dataSource.refreshInterval}`)}return e.sort().join(",")},[T.tiles,r]);c.useEffect(()=>{if(!r||!Ee)return;const e=new Map,i=new Map;for(const[s,a]of ye.current){const m=a.definition;if(!m?.dataSource)continue;const w=r.tiles[s];if(!w||w.status!=="active")continue;const I=async()=>{const H=ye.current.get(s)?.definition,A=H?.dataSource??m.dataSource;if(!A)return;const R=new AbortController;e.set(s,R),be(_=>{const $=new Map(_);return $.set(s,{data:$.get(s)?.data??null,loading:!0,error:null}),$});try{const _={},$=H?.params??m.params;if($)for(const[O,L]of Object.entries($))_[O]=L.default;const F=await A.fetch({signal:R.signal,params:_});be(O=>{const L=new Map(O);return L.set(s,{data:F,loading:!1,error:null}),L})}catch(_){_?.name!=="AbortError"&&be($=>{const F=new Map($);return F.set(s,{data:F.get(s)?.data??null,loading:!1,error:_}),F})}};I();const M=Math.max(30,m.dataSource.refreshInterval)*1e3;i.set(s,setInterval(I,M))}return()=>{e.forEach(s=>s.abort()),i.forEach(s=>clearInterval(s))}},[Ee,r]);const Ge=c.useCallback(e=>{if(y)return;W(e);const i=r.tiles[e];i&&k({type:"tile",content:e,file:i.component})},[r,k,y]),Ie=c.useCallback(e=>{e.target.closest("[data-tile-id]")||(W(null),k(null))},[k]),Je=c.useCallback(e=>{if(y)return;const i=e.target.closest("[data-drag-handle]");if(!i)return;const s=i.closest("[data-tile-id]");if(!s)return;const a=s.getAttribute("data-tile-id");if(!a)return;const m=r.tiles[a];m&&(e.preventDefault(),pe({tileId:a,startMouse:{x:e.clientX,y:e.clientY},startPos:{...m.position},currentPos:{...m.position}}))},[r,y]);c.useEffect(()=>{if(!E)return;const e=r.board.width/r.board.columns,i=r.board.height/r.board.rows,s=r.tiles[E.tileId];if(!s)return;const a=w=>{const I=Z.current;if(!I)return;const M=w.clientX-E.startMouse.x,H=w.clientY-E.startMouse.y,A=I.getBoundingClientRect(),R=r.board.width/A.width,_=r.board.height/A.height,$=Math.round(M*R/e),F=Math.round(H*_/i);let O=E.startPos.col+$,L=E.startPos.row+F;O=Math.max(0,Math.min(r.board.columns-s.size.cols,O)),L=Math.max(0,Math.min(r.board.rows-s.size.rows,L)),pe(oe=>oe?{...oe,currentPos:{col:O,row:L}}:null)},m=async()=>{if(!E)return;const{tileId:w,startPos:I,currentPos:M}=E;if(M.col!==I.col||M.row!==I.row){const H=r.tiles[w];if(!fe(r.tiles,M.col,M.row,H.size.cols,H.size.rows,w)){ke(R=>new Map(R).set(w,M));const A=JSON.parse(JSON.stringify(r));A.tiles[w].position=M,pe(null),await le("board.json",JSON.stringify(A,null,2));return}}pe(null)};return window.addEventListener("mousemove",a),window.addEventListener("mouseup",m),()=>{window.removeEventListener("mousemove",a),window.removeEventListener("mouseup",m)}},[E,r]);const Ve=c.useCallback(e=>{if(y)return;const i=e.target.closest("[data-resize-handle]");if(!i)return;const s=i.getAttribute("data-resize-direction");if(!s)return;const a=i.closest("[data-tile-id]");if(!a)return;const m=a.getAttribute("data-tile-id");if(!m)return;const w=r.tiles[m];w&&(e.preventDefault(),e.stopPropagation(),ue({tileId:m,direction:s,startMouse:{x:e.clientX,y:e.clientY},startSize:{...w.size},startPos:{...w.position},currentSize:{...w.size},currentPos:{...w.position}}))},[r,y]);c.useEffect(()=>{if(!v)return;const e=r.board.width/r.board.columns,i=r.board.height/r.board.rows,a=T.tiles.get(v.tileId)?.definition,m=a?.minSize?.cols??1,w=a?.minSize?.rows??1,I=a?.maxSize?.cols??r.board.columns,M=a?.maxSize?.rows??r.board.rows,H=R=>{const _=Z.current;if(!_)return;const $=R.clientX-v.startMouse.x,F=R.clientY-v.startMouse.y,O=_.getBoundingClientRect(),L=r.board.width/O.width,oe=r.board.height/O.height,ee=Math.round($*L/e),ge=Math.round(F*oe/i);let J=v.startSize.cols,Y=v.startSize.rows,ie=v.startPos.col,te=v.startPos.row;const re=v.direction;re.includes("e")&&(J=v.startSize.cols+ee),re.includes("w")&&(J=v.startSize.cols-ee,ie=v.startPos.col+ee),re.includes("s")&&(Y=v.startSize.rows+ge),re.includes("n")&&(Y=v.startSize.rows-ge,te=v.startPos.row+ge),J=Math.max(m,Math.min(I,J)),Y=Math.max(w,Math.min(M,Y)),ie=Math.max(0,Math.min(r.board.columns-J,ie)),te=Math.max(0,Math.min(r.board.rows-Y,te)),ue(ae=>ae?{...ae,currentSize:{cols:J,rows:Y},currentPos:{col:ie,row:te}}:null)},A=async()=>{if(!v)return;const{tileId:R,startSize:_,currentSize:$,startPos:F,currentPos:O}=v;ue(null);const L=$.cols!==_.cols||$.rows!==_.rows,oe=O.col!==F.col||O.row!==F.row;if((L||oe)&&!fe(r.tiles,O.col,O.row,$.cols,$.rows,R)){Ce(me=>new Map(me).set(R,{...$,...O}));const ee=JSON.parse(JSON.stringify(r));ee.tiles[R].size=$,ee.tiles[R].position=O,ue(null),await le("board.json",JSON.stringify(ee,null,2));const J=T.tiles.get(R)?.definition,Y=r.board.width/r.board.columns,ie=r.board.height/r.board.rows,te=$.cols*Y,re=$.rows*ie;if(J?.isOptimizedFor&&J.isOptimizedFor(te,re))return;let ae;try{const me=Z.current?.querySelector(`[data-tile-id="${R}"]`);if(me){const Pe=await ve(me);Pe&&(ae=[Pe])}}catch{}const et=[`Tile "${R}" was resized from ${_.cols}×${_.rows} to ${$.cols}×${$.rows} (${Math.round(te)}×${Math.round(re)}px).`,"This tile has NOT been optimized for this size yet.",ae?.length?"A screenshot of the tile at its current size is attached — review it to assess layout quality.":"(Screenshot capture failed — read the component to assess layout.)","If the layout needs work: call lock-tile, update the component's render breakpoints, then call unlock-tile.","If acceptable: acknowledge, no changes needed.",`Component: ${r.tiles[R].component}`].join(`
`);rt.getState().addPendingNotification({type:"tile_resize_needs_optimization",message:et,severity:"warning",summary:`Tile "${R}" needs size optimization (${$.cols}×${$.rows})`},ae);return}ue(null)};return window.addEventListener("mousemove",H),window.addEventListener("mouseup",A),()=>{window.removeEventListener("mousemove",H),window.removeEventListener("mouseup",A)}},[v,r,T.tiles,C]),c.useEffect(()=>{if(d)switch(d.actionId){case"navigate-to":{const e=d.params?.tileId;e&&r.tiles[e]?(W(e),Me(e),u?.(d.requestId,{success:!0})):u?.(d.requestId,{success:!1,message:`Tile "${e}" not found`});break}case"open-gallery":{N(!0),u?.(d.requestId,{success:!0});break}case"capture-tile":{const e=d.params?.tileId,i=Z.current?.querySelector(`[data-tile-id="${e}"]`);if(!i){u?.(d.requestId,{success:!1,message:`Tile "${e}" not found`});break}ve(i).then(async s=>{if(!s){u?.(d.requestId,{success:!1,message:"Screenshot capture failed"});return}const m=`.pneuma/captures/${`tile-${e}-${Date.now()}.png`}`;await le(m,`data:${s.media_type};base64,${s.data}`),u?.(d.requestId,{success:!0,message:m,data:{path:m}})});break}case"capture-board":{const e=Z.current;if(!e){u?.(d.requestId,{success:!1,message:"Board element not found"});break}ve(e).then(async i=>{if(!i){u?.(d.requestId,{success:!1,message:"Screenshot capture failed"});return}const a=`.pneuma/captures/${`board-${Date.now()}.png`}`;await le(a,`data:${i.media_type};base64,${i.data}`),u?.(d.requestId,{success:!0,message:a,data:{path:a}})});break}case"lock-tile":{const e=d.params?.tileId;e?(K(i=>new Set(i).add(e)),u?.(d.requestId,{success:!0,message:`Tile "${e}" locked`})):u?.(d.requestId,{success:!1,message:"tileId required"});break}case"unlock-tile":{const e=d.params?.tileId;e?(K(i=>{const s=new Set(i);return s.delete(e),s}),u?.(d.requestId,{success:!0,message:`Tile "${e}" unlocked`})):u?.(d.requestId,{success:!1,message:"tileId required"});break}default:u?.(d.requestId,{success:!1,message:`Unknown action: ${d.actionId}`})}},[d]),c.useEffect(()=>{if(!j)return;const{data:e}=j;if(e.tileId){const i=e.tileId;r.tiles[i]&&(W(i),Me(i))}else e.action==="open-gallery"&&N(!0);p?.()},[j]);const Me=c.useCallback(e=>{const i=Z.current,s=i?.querySelector(`[data-tile-id="${e}"]`),a=i?.parentElement;if(!s||!a)return;const m=a.getBoundingClientRect(),w=s.getBoundingClientRect(),I=a.scrollTop+(w.top-m.top)-(m.height-w.height)/2,M=a.scrollLeft+(w.left-m.left)-(m.width-w.width)/2;a.scrollTo({top:Math.max(0,I),left:Math.max(0,M),behavior:"smooth"})},[]),Ke=c.useCallback(async e=>{if(y||!r.tiles[e])return;Te(a=>new Set(a).add(e)),z===e&&(W(null),k(null));const s=JSON.parse(JSON.stringify(r));s.tiles[e].status="available",delete s.tiles[e].position,delete s.tiles[e].size,await le("board.json",JSON.stringify(s,null,2))},[r,y,z,k]),Ye=c.useMemo(()=>{const e=new Map;for(const[i,s]of Object.entries(r.tiles)){const a=s;if(a.status==="active")continue;const w=T.tiles.get(i)?.definition;e.set(i,{tileId:i,label:w?.label??a.label??i,description:w?.description??"",status:a.status==="disabled"?"disabled":"available",minSize:w?.minSize,component:a.component,definition:w??null})}return e},[r,T]),Xe=c.useCallback(async e=>{if(y||!r.tiles[e])return;const a=T.tiles.get(e)?.definition,m=a?.minSize?.cols??2,w=a?.minSize?.rows??2,I=_t(r.tiles,r.board,m,w);if(!I){C?.({type:"gallery_add_failed",message:`Could not find empty space on the board for tile "${e}" (needs ${m}x${w} grid cells). Consider removing or resizing existing tiles.`,severity:"warning"});return}const M=JSON.parse(JSON.stringify(r));M.tiles[e]={...M.tiles[e],status:"active",position:I,size:{cols:m,rows:w}},await le("board.json",JSON.stringify(M,null,2))},[r,T,y,C]),Ue=c.useCallback(e=>{y||(C?.({type:"create-tile",message:`The user wants to create a new tile: "${e}". Generate a tile component in tiles/<id>/Tile.tsx using defineTile() and register it in board.json. Pick a short, descriptive ID based on their description.`,severity:"warning",summary:`Create tile: ${e}`}),N(!1))},[y,C]);c.useEffect(()=>{ze.size>0&&ke(e=>{const i=new Map(e);for(const[s,a]of e){const m=r.tiles[s];m&&m.position.col===a.col&&m.position.row===a.row&&i.delete(s)}return i.size===e.size?e:i}),$e.size>0&&Ce(e=>{const i=new Map(e);for(const[s]of e)r.tiles[s]&&i.delete(s);return i.size===e.size?e:i})},[r]);const Ze=c.useMemo(()=>{const e=new Map;for(const[i,s]of se){let a=s.position,m=s.size;const w=ze.get(i);w&&(a=w);const I=$e.get(i);I&&(a={col:I.col,row:I.row},m={cols:I.cols,rows:I.rows}),E?.tileId===i&&(a=E.currentPos),v?.tileId===i&&(a=v.currentPos,m=v.currentSize);const M=r.board.width/r.board.columns,H=r.board.height/r.board.rows;e.set(i,{x:a.col*M,y:a.row*H,width:m.cols*M,height:m.rows*H})}return e},[se,r,E,v]),Qe=c.useMemo(()=>({width:r.board.width,height:r.board.height,columns:r.board.columns,rows:r.board.rows,activeTiles:se.length,totalTiles:Object.keys(r.tiles).length}),[r,se]),Q=c.useMemo(()=>{if(!E)return null;const e=r.tiles[E.tileId];if(!e)return null;const i=r.board.width/r.board.columns,s=r.board.height/r.board.rows,a=!fe(r.tiles,E.currentPos.col,E.currentPos.row,e.size.cols,e.size.rows,E.tileId);return{x:E.currentPos.col*i,y:E.currentPos.row*s,width:e.size.cols*i,height:e.size.rows*s,isValid:a}},[E,r]),q=c.useMemo(()=>{if(!v)return null;const e=r.board.width/r.board.columns,i=r.board.height/r.board.rows,s=!fe(r.tiles,v.currentPos.col,v.currentPos.row,v.currentSize.cols,v.currentSize.rows,v.tileId);return{x:v.currentPos.col*e,y:v.currentPos.row*i,width:v.currentSize.cols*e,height:v.currentSize.rows*i,isValid:s}},[v,r]),Re=!Be(o),qe=se.length===0;return t.jsxs("div",{ref:Ne,onClick:Ie,style:{width:"100%",height:"100%",display:"flex",flexDirection:"column",background:"var(--board-bg, #09090b)",overflow:"hidden",position:"relative",fontFamily:"var(--font-family, -apple-system, BlinkMacSystemFont, sans-serif)"},children:[G&&t.jsx("style",{children:G}),t.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[t.jsx("div",{style:{flex:1,overflow:f?"hidden":"auto",display:"flex",alignItems:f?void 0:"center",justifyContent:f?void 0:"center",padding:f?0:24},children:Re?t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:12,color:"var(--text-muted, #52525b)",fontSize:14,textAlign:"center"},children:[t.jsxs("svg",{width:48,height:48,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),t.jsx("line",{x1:"3",y1:"9",x2:"21",y2:"9"}),t.jsx("line",{x1:"3",y1:"15",x2:"21",y2:"15"}),t.jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"}),t.jsx("line",{x1:"15",y1:"3",x2:"15",y2:"21"})]}),t.jsx("span",{style:{color:"var(--text-secondary, #a1a1aa)"},children:"Waiting for board.json..."}),t.jsx("span",{style:{fontSize:12},children:"The agent will create the board configuration."})]}):t.jsxs("div",{ref:Z,style:{width:f?"100%":r.board.width,height:f?"100%":r.board.height,minWidth:f?void 0:r.board.width,minHeight:f?void 0:r.board.height,position:"relative",background:"var(--board-bg, #09090b)",backgroundImage:V&&!f?Dt(r):void 0,borderRadius:f?0:8,border:f?"none":"1px solid rgba(255,255,255,0.06)",boxSizing:"border-box"},onClick:Ie,onMouseDown:e=>{Je(e),Ve(e)},children:[qe&&!Re&&t.jsxs("div",{style:{position:"absolute",inset:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:8,color:"var(--text-muted, #52525b)",fontSize:13,pointerEvents:"none"},children:[t.jsx("span",{children:"No active tiles"}),!y&&t.jsx("span",{style:{fontSize:11},children:"Open the Gallery to add tiles"})]}),se.map(([e])=>{const i=Ze.get(e);if(!i)return null;const s=T.tiles.get(e),a=de.get(e);return t.jsx("div",{"data-tile-id":e,style:{position:"absolute",left:i.x,top:i.y,width:i.width,height:i.height,transition:E?.tileId===e||v?.tileId===e?"none":"left 0.2s ease, top 0.2s ease, width 0.2s ease, height 0.2s ease"},children:t.jsx(yt,{tileId:e,definition:s?.definition??null,compilationError:s?.error,data:a?.data??null,loading:a?.loading??!1,error:a?.error??null,width:i.width,height:i.height,themeCSS:G,isSelected:z===e,isResizing:B.has(e),onSelect:Ge,onRenderError:Ae,onRemove:Ke})},e)}),Q&&t.jsx("div",{style:{position:"absolute",left:Q.x,top:Q.y,width:Q.width,height:Q.height,borderRadius:"var(--tile-radius, 10px)",border:`2px dashed ${Q.isValid?"var(--accent, #f97316)":"var(--error, #ef4444)"}`,background:Q.isValid?"rgba(249, 115, 22, 0.08)":"rgba(239, 68, 68, 0.08)",pointerEvents:"none",zIndex:20,transition:"left 0.1s ease, top 0.1s ease"}}),q&&t.jsx("div",{style:{position:"absolute",left:q.x,top:q.y,width:q.width,height:q.height,borderRadius:"var(--tile-radius, 10px)",border:`2px dashed ${q.isValid?"var(--accent, #f97316)":"var(--error, #ef4444)"}`,background:q.isValid?"rgba(249, 115, 22, 0.08)":"rgba(239, 68, 68, 0.08)",pointerEvents:"none",zIndex:20}})]})}),!y&&t.jsx(Tt,{isOpen:U,onClose:()=>N(!1),tiles:Ye,onAddTile:Xe,onCreateTile:Ue})]}),!f&&t.jsx(Rt,{onToggleGallery:()=>N(e=>!e),isGalleryOpen:U,onToggleGrid:()=>ce(e=>!e),showGrid:V,boardInfo:Qe}),T.errors.length>0&&t.jsxs("div",{style:{position:"absolute",bottom:44,left:12,maxWidth:320,display:"flex",flexDirection:"column",gap:4,zIndex:30},children:[T.errors.slice(0,3).map((e,i)=>t.jsxs("div",{style:{background:"rgba(239, 68, 68, 0.12)",border:"1px solid rgba(239, 68, 68, 0.3)",borderRadius:6,padding:"6px 10px",fontSize:11,color:"var(--error, #ef4444)",fontFamily:"var(--font-mono, monospace)",lineHeight:1.4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e.message,children:[e.tileId,": ",e.message.length>60?e.message.slice(0,60)+"...":e.message]},i)),T.errors.length>3&&t.jsxs("div",{style:{fontSize:10,color:"var(--text-muted, #52525b)",paddingLeft:4},children:["+",T.errors.length-3," more errors"]})]})]})}function Bt(o){const n=o.find(l=>l.path==="board.json"||l.path.endsWith("/board.json"));if(!n)return null;try{return JSON.parse(n.content)}catch{return null}}const At={manifest:we,viewer:{PreviewComponent:Wt,workspace:{type:"all",multiFile:!0,ordered:!1,hasActiveFile:!1,resolveItems(o){return o.filter(n=>n.path==="board.json"||n.path.endsWith("/board.json")||/tiles\/.*\.tsx$/.test(n.path)).map((n,l)=>({path:n.path,label:n.path,index:l}))}},actions:we.viewerApi?.actions,extractContext(o,n){const l=Bt(n);if(!l)return"";const{width:h,height:x,columns:b,rows:g}=l.board,d=l.tiles??{};if(o?.type==="tile"&&o.content){const y=o.content,k=d[y];if(k){const C=k.size?.cols??1,r=k.size?.rows??1,G=k.position?.col??0,T=k.position?.row??0,U=k.label??y,N=k.status??"active",V=k.component??`tiles/${y}/Tile.tsx`,ce=['mode="gridboard"',`tile="${y}"`,`size="${C}x${r}"`,`status="${N}"`],z=[`Tile: ${U} (${C}×${r} at col ${G}, row ${T})`,`Component: ${V}`];return`<viewer-context ${ce.join(" ")}>
${z.join(`
`)}
</viewer-context>`}}const u=Object.entries(d),S=u.filter(([,y])=>y.status==="active"),j=u.filter(([,y])=>y.status==="disabled"),p=u.filter(([,y])=>y.status==="available");let P=0;for(const[,y]of S){const k=y.size?.cols??1,C=y.size?.rows??1;P+=k*C}const D=b*g,X=D-P,f=[`Board: ${h}×${x}, ${b}×${g} grid`];if(S.length>0){const y=S.map(([k,C])=>{const r=C.size?.cols??1,G=C.size?.rows??1;return`${C.label??k} (${r}×${G})`}).join(", ");f.push(`Active tiles: ${y}`)}else f.push("Active tiles: none");return j.length>0&&f.push(`Disabled: ${j.map(([y,k])=>k.label??y).join(", ")}`),p.length>0&&f.push(`Available: ${p.map(([y,k])=>k.label??y).join(", ")}`),f.push(`Empty cells: ${X}/${D}`),`<viewer-context mode="gridboard">
${f.join(`
`)}
</viewer-context>`},updateStrategy:"full-reload",locatorDescription:we.viewerApi?.locatorDescription}};export{At as default};
