import{a as e,i as t,n,r,t as i}from"./TableSelect-DD9asiuX.js";import{t as a}from"./Pencil.es-CzCcQnsk.js";import{n as o}from"./dialog-oqh8l3l3zutpibxx-CQxG7a37.js";import{n as s,t as c}from"./Breadcrumbs-CaGSlxI5.js";import{Bn as l,Gn as u,Hn as d,Jn as f,Kn as p,Tt as m,Wn as h,n as g,ot as _,r as v}from"./index-DUQaQqLX.js";var y=f(u()),b=p();function x(){let u=g.useParams(),f=g.useLoaderData(),{namespaceId:p,objectId:x,objectName:S}=f,C=g.useSearch(),w=d(),T=h(),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(p,x,S),[p,x,S]),F=(0,y.useMemo)(()=>({namespaceId:p,objectId:u.objectId,type:`do`}),[p,u.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=u.objectId.length>16?`${u.objectId.slice(0,8)}...${u.objectId.slice(-8)}`:u.objectId;return(0,b.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,b.jsxs)(c,{icon:_,items:[(0,b.jsx)(l,{className:`flex items-center gap-1.5`,params:{className:u.className},to:`/do/$className`,children:u.className},`class-name`),(0,b.jsxs)(`span`,{className:`flex items-center gap-1 font-mono text-xs [&_button]:opacity-100`,title:u.objectId,children:[H,(0,b.jsx)(s.Clipboard,{text:u.objectId})]},`object-id`),(0,b.jsx)(i,{selectedTable:C.table,studioRef:D,tables:f.tables},`table-selector`)],title:`Durable Objects`,children:[(0,b.jsx)(`div`,{className:`flex-1`}),(0,b.jsx)(m,{"aria-label":`Refresh tables`,className:`disabled:cursor-progress`,disabled:A,onClick:L,shape:`square`,children:(0,b.jsx)(e,{className:A?`animate-spin`:void 0,size:14})}),(0,b.jsx)(n,{currentTable:O,driver:P}),(0,b.jsx)(m,{"aria-label":`Edit table schema`,disabled:!O,icon:a,onClick:()=>{O&&D.current?.openEditTableTab(`main`,O)},children:`Edit Schema`}),(0,b.jsx)(m,{"aria-label":`Delete table`,disabled:!O,icon:o,onClick:z,variant:`secondary-destructive`,children:`Delete Table`})]}),M&&(0,b.jsx)(r,{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)(t,{driver:P,initialTable:C.table,onTableChange:I,ref:D,resource:F},`${p}-${u.objectId}`)})]})}export{x as component};