import{c as e,n as t,s as n,z as r}from"./useRouterState-DyVgzXuA.js";import{Ct as i,t as a}from"./button-cdxnqcgzwko8ooha-DePtDphh.js";import{s as o}from"./preload-helper-DVdLIjcg.js";import{a as s,i as c,n as l,r as u,t as d}from"./TableSelect-CfhTton7.js";import"./api-CJ3Zq7MY.js";import{t as f}from"./Pencil.es-DFYQ2b5f.js";import"./sqlite-Cw873T5t.js";import{n as p}from"./dialog-oqh8l3l3zutpibxx-C3V2uifQ.js";import{n as m,t as h}from"./Breadcrumbs-PAPh5eEw.js";import{_ as g,n as _,r as v}from"./index-DO0z1AkS.js";var y=r(n()),b=e();function x(){let e=_.useParams(),n=_.useLoaderData(),{namespaceId:r,objectId:x,objectName:S}=n,C=_.useSearch(),w=o(),T=t(),E=(0,y.useRef)(C.table),D=(0,y.useRef)(null),[O,k]=(0,y.useState)(C.table),[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(null),P=(0,y.useMemo)(()=>new v(r,x,S),[r,x,S]),F=(0,y.useMemo)(()=>({namespaceId:r,objectId:e.objectId,type:`do`}),[r,e.objectId]),I=(0,y.useCallback)(e=>{k(e),E.current!==e&&(E.current=e,w({replace:!0,search:t=>({...t,table:e}),to:`.`}))},[w]),L=(0,y.useCallback)(async()=>{j(!0);try{await Promise.all([T.invalidate(),D.current?.refreshSchema(),new Promise(e=>setTimeout(e,250))])}finally{j(!1)}},[T]),R=(0,y.useCallback)(async()=>{await L(),w({replace:!0,search:e=>({...e,table:void 0}),to:`.`})},[L,w]),z=(0,y.useCallback)(()=>{O&&N({schemaName:`main`,tableName:O})},[O]),B=(0,y.useCallback)(()=>{N(null)},[]),V=(0,y.useCallback)(()=>{M&&(D.current?.closeTableTabs(M.schemaName,M.tableName),R())},[M,R]),H=e.objectId.length>16?`${e.objectId.slice(0,8)}...${e.objectId.slice(-8)}`:e.objectId;return(0,b.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,b.jsxs)(h,{icon:g,items:[(0,b.jsx)(i,{className:`flex items-center gap-1.5`,params:{className:e.className},to:`/do/$className`,children:e.className},`class-name`),(0,b.jsxs)(`span`,{className:`flex items-center gap-1 font-mono text-xs [&_button]:opacity-100`,title:e.objectId,children:[H,(0,b.jsx)(m.Clipboard,{text:e.objectId})]},`object-id`),(0,b.jsx)(d,{selectedTable:C.table,studioRef:D,tables:n.tables},`table-selector`)],title:`Durable Objects`,children:[(0,b.jsx)(`div`,{className:`flex-1`}),(0,b.jsx)(a,{"aria-label":`Refresh tables`,className:`disabled:cursor-progress`,disabled:A,onClick:L,shape:`square`,children:(0,b.jsx)(s,{className:A?`animate-spin`:void 0,size:14})}),(0,b.jsx)(l,{currentTable:O,driver:P}),(0,b.jsx)(a,{"aria-label":`Edit table schema`,disabled:!O,icon:f,onClick:()=>{O&&D.current?.openEditTableTab(`main`,O)},children:`Edit Schema`}),(0,b.jsx)(a,{"aria-label":`Delete table`,disabled:!O,icon:p,onClick:z,variant:`secondary-destructive`,children:`Delete Table`})]}),M&&(0,b.jsx)(u,{closeModal:B,driver:P,isOpen:!0,onSuccess:V,schemaName:M.schemaName,tableName:M.tableName}),(0,b.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,b.jsx)(c,{driver:P,initialTable:C.table,onTableChange:I,ref:D,resource:F},`${r}-${e.objectId}`)})]})}export{x as component};