import{s as b}from"./chunk-LvLJmgfZ.js";import"./useEvent-D91BmmQi.js";import{t as y}from"./react-Bj1aDYRI.js";import"./react-dom-CSu739Rf.js";import"./compiler-runtime-B3qBwwSJ.js";import{t as P}from"./ErrorBoundary-DzTD8LVq.js";import{t as $}from"./jsx-runtime-Blw4afVn.js";import"./fullscreen-CTDqNQr6.js";import{r as z}from"./requests-9-v2bhoi.js";import{t as N}from"./spinner-D-V4psAa.js";import{dt as L,r as M}from"./input-JxFwu-3G.js";import{n as c,t as R}from"./paths-BKO-pHK6.js";import{c as v,t as I}from"./session-BmukRjSi.js";import{a as A}from"./errors-PgHhDa-M.js";import{t as f}from"./error-banner-BSxEOIn2.js";import{n as D}from"./useAsyncData-Bg5iAViP.js";import{n as W,t as _}from"./card-P_NJTnTd.js";var p=b(y(),1),e=b($(),1),B=a=>a.charAt(0).toUpperCase()+a.slice(1).toLowerCase(),w=a=>{let o=R.guessDeliminator(a).deliminator;return a.replace(/\.[^./]+$/,"").split(o).filter(Boolean).map(d=>d.split(/[_-]/).map(B).join(" ")).join(" > ")},F=a=>`${I()}-${encodeURIComponent(a)}`,Y=a=>{try{return new URL(a).protocol==="https:"}catch{return!1}},q=10,E=()=>{let{getWorkspaceFiles:a}=z(),[o,d]=(0,p.useState)(""),n=D(()=>a({includeMarkdown:!1}),[]),t=n.data,m=(0,p.useMemo)(()=>{let r=(t==null?void 0:t.files)??[],l=(t==null?void 0:t.root)??"";return r.filter(s=>!s.isDirectory).map(s=>{var g,x,j;let i=l&&c.isAbsolute(s.path)&&s.path.startsWith(l)?c.rest(s.path,l):s.path,C=((g=s.opengraph)==null?void 0:g.title)??w(c.basename(i)),S=w(c.dirname(i)),U=((x=s.opengraph)==null?void 0:x.description)??"",h=(j=s.opengraph)==null?void 0:j.image,k=h&&Y(h)?h:v(`og/thumbnail?file=${encodeURIComponent(i)}`).toString();return{...s,relativePath:i,title:C,subtitle:S,description:U,thumbnailUrl:k}}).toSorted((s,i)=>s.relativePath.localeCompare(i.relativePath))},[t==null?void 0:t.files,t==null?void 0:t.root]),u=(0,p.useMemo)(()=>{if(!o)return m;let r=o.toLowerCase();return m.filter(l=>l.title.toLowerCase().includes(r))},[m,o]);return n.isPending?(0,e.jsx)(N,{centered:!0,size:"xlarge",className:"mt-6"}):n.error?(0,e.jsx)(f,{kind:"danger",className:"rounded p-4",children:A(n.error)}):t?(0,e.jsx)(p.Suspense,{children:(0,e.jsxs)("div",{className:"flex flex-col gap-6 max-w-6xl container pt-5 pb-20 z-10",children:[(0,e.jsx)("img",{src:"logo.png",alt:"marimo logo",className:"w-48 mb-2"}),(0,e.jsx)(P,{children:(0,e.jsxs)("div",{className:"flex flex-col gap-2",children:[t.hasMore&&(0,e.jsxs)(f,{kind:"warn",className:"rounded p-4",children:["Showing first ",t.fileCount," files. Your workspace has more files."]}),m.length>q&&(0,e.jsx)(M,{id:"search",value:o,icon:(0,e.jsx)(L,{className:"h-4 w-4"}),onChange:r=>d(r.target.value),placeholder:"Search",rootClassName:"mb-3",className:"mb-0 border-border"}),u.length===0?(0,e.jsx)(f,{kind:"warn",className:"rounded p-4",children:"No marimo apps found."}):(0,e.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:u.map(r=>(0,e.jsx)("a",{href:v(`?file=${encodeURIComponent(r.relativePath)}`).toString(),target:F(r.path),className:"no-underline",children:(0,e.jsxs)(_,{className:"h-full overflow-hidden hover:bg-accent/20 transition-colors",children:[(0,e.jsx)("img",{src:r.thumbnailUrl,alt:r.title,loading:"lazy",className:"w-full aspect-1200/630 object-cover border-b border-border/60"}),(0,e.jsx)(W,{className:"p-6 pt-4",children:(0,e.jsxs)("div",{className:"flex flex-col gap-1",children:[r.subtitle&&(0,e.jsx)("div",{className:"text-sm font-semibold text-muted-foreground",children:r.subtitle}),(0,e.jsx)("div",{className:"text-lg font-medium",children:r.title}),r.description&&(0,e.jsx)("div",{className:"text-sm text-muted-foreground line-clamp-3 mt-1",children:r.description})]})})]})},r.path))})]})})]})}):(0,e.jsx)(N,{centered:!0,size:"xlarge",className:"mt-6"})};export{E as default};
