import{a5 as m,Y as y,Z as R,r as a,a6 as $,j as e,a4 as O,a0 as P,a1 as E}from"./index-CULuikBf.js";import{y as g,r as L,S as M,D as V,a as _,b as z,c as B,d as q,e as A,f as W,g as Y,h as Z,i as F,j as G,k as H,l as J,m as K}from"./ActionsDropdown-q-9MDOpc.js";import{a6 as Q,a7 as U,a4 as X}from"./getPseudoElementBounds-BYLHjZjA.js";import{B as ee}from"./Breadcrumbs--TWNuJCy.js";function ne(){const s=m.useParams(),u=m.useLoaderData(),i=m.useSearch(),n=y(),h=R(),d=a.useRef(i.table),c=a.useRef(null),[r,l]=a.useState(i.table),[x,f]=a.useState(!1),[o,N]=a.useState(null),{namespaceId:b}=u,p=a.useMemo(()=>new $(b,s.objectId),[b,s.objectId]),S=a.useMemo(()=>({namespaceId:b,objectId:s.objectId,type:"do"}),[b,s.objectId]),T=a.useCallback(t=>{l(t),d.current!==t&&(d.current=t,n({replace:!0,search:{table:t},to:"."}))},[n]),j=a.useCallback(async()=>{var t;f(!0);try{await Promise.all([h.invalidate(),(t=c.current)==null?void 0:t.refreshSchema(),new Promise(D=>setTimeout(D,250))])}finally{f(!1)}},[h]),v=a.useCallback(async()=>{await j(),n({replace:!0,search:{table:void 0},to:"."})},[j,n]),C=a.useCallback(()=>{r&&N({schemaName:"main",tableName:r})},[r]),I=a.useCallback(()=>{N(null)},[]),w=a.useCallback(()=>{var t;o&&((t=c.current)==null||t.closeTableTabs(o.schemaName,o.tableName),v())},[o,v]),k=s.objectId.length>16?`${s.objectId.slice(0,8)}...${s.objectId.slice(-8)}`:s.objectId;return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs(ee,{icon:O,items:[e.jsx(P,{className:"flex items-center gap-1.5",params:{className:s.className},to:"/do/$className",children:s.className},"class-name"),e.jsx("span",{className:"flex items-center gap-1.5 font-mono text-xs",title:s.objectId,children:k},"object-id"),e.jsx(ae,{studioRef:c},"table-selector")],title:"Durable Objects",children:[e.jsx("div",{className:"flex-1"}),e.jsx(g,{"aria-label":"Refresh tables",className:"disabled:cursor-progress",disabled:x,onClick:j,shape:"square",children:e.jsx(L,{className:x?"animate-spin":void 0,size:14})}),e.jsx(M,{currentTable:r,driver:p}),e.jsx(g,{"aria-label":"Edit table schema",disabled:!r,icon:Q,onClick:()=>{var t;r&&((t=c.current)==null||t.openEditTableTab("main",r))},children:"Edit Schema"}),e.jsx(g,{"aria-label":"Delete table",disabled:!r,icon:U,onClick:C,variant:"secondary-destructive",children:"Delete Table"})]}),o&&e.jsx(V,{closeModal:I,driver:p,isOpen:!0,onSuccess:w,schemaName:o.schemaName,tableName:o.tableName}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx(_,{driver:p,initialTable:i.table,onTableChange:T,ref:c,resource:S},`${b}-${s.objectId}`)})]})}function ae({studioRef:s}){const u=m.useLoaderData(),i=y(),n=m.useSearch(),[h,d]=a.useState(!1),c=a.useCallback(l=>{l!==null&&i({search:{table:l},to:"."})},[i]),r=a.useCallback(()=>{var l;d(!1),(l=s.current)==null||l.openCreateTableTab()},[s]);return e.jsxs(z,{onOpenChange:d,onValueChange:c,open:h,value:n.table??null,children:[e.jsxs(B,{className:"inline-flex items-center gap-1 p-2 -mx-1.5 rounded-md bg-transparent text-sm text-text cursor-pointer border-none transition-colors hover:bg-border/50 data-popup-open:bg-border/50",children:[e.jsx(q,{placeholder:"Select table"}),e.jsx(A,{children:e.jsx(W,{className:"w-3.5 h-3.5 text-text-secondary"})})]}),e.jsx(Y,{children:e.jsx(Z,{align:"start",alignItemWithTrigger:!1,side:"bottom",sideOffset:4,children:e.jsxs(F,{className:"min-w-36 max-h-72 bg-bg border border-border rounded-lg shadow-[0_4px_12px_rgba(0,0,0,0.15)] z-100 overflow-hidden transition-[opacity,transform] duration-150 data-starting-style:opacity-0 data-starting-style:-translate-y-1 data-ending-style:opacity-0 data-ending-style:-translate-y-1",children:[e.jsx("div",{className:"p-1",children:e.jsxs("button",{className:"flex items-center gap-2 w-full py-1.5 px-2 rounded-md text-sm text-text cursor-pointer transition-colors select-none outline-none hover:bg-bg-secondary dark:hover:bg-bg-tertiary",onClick:r,type:"button",children:[e.jsx("span",{className:"flex items-center w-4",children:e.jsx(G,{className:"w-3.5 h-3.5"})}),"Create table"]})}),e.jsx("div",{className:"mx-1 border-t border-border"}),e.jsx(H,{className:"p-1",children:u.tables.length>0?u.tables.map(l=>{const x=n.table===l.value?X:E;return e.jsxs(J,{className:"flex items-center gap-2 w-full py-1.5 px-2 rounded-md text-sm text-text cursor-pointer transition-colors select-none outline-none data-highlighted:bg-bg-secondary dark:data-highlighted:bg-bg-tertiary",value:l.value,children:[e.jsx("span",{className:"flex items-center w-4",children:e.jsx(x,{className:"w-3.5 h-3.5"})}),e.jsx(K,{children:l.label})]},l.value)}):e.jsx("span",{className:"flex justify-center items-center gap-2 w-full py-1.5 px-2 text-sm text-text-secondary",children:"No tables"})})]})})})]},"table-select")}export{ne as component};
