import{a as e,l as t}from"./preact.module-CNakwbc9.js";import{d as n,l as r,s as i}from"./hooks.module-BrXTvcfS.js";import{a}from"./i18n-BaLR3UdQ.js";import{t as o}from"./server-BXh06Wz_.js";import{t as s}from"./jsxRuntime.module-Cao1NCKs.js";import{J as c}from"./hooks-ClTXKdUl.js";import{t as l}from"./Dropdown-BUar6udP.js";import{t as u}from"./Button-Du0dYm4Z.js";import{t as d}from"./NoItems-ZA3b1X1n.js";import{_ as f,a as p,c as m,g as h,h as g,i as _,n as v,o as y,p as b,s as x,t as S,u as C,v as w}from"./tabulator-b-o0XW-j.js";import{n as T}from"./SplitEditor-Hd815xEd.js";n(),t();function E(e){return s(T,{noteType:`code`,...e,editorBefore:s(k,{...e}),previewContent:s(D,{...e},e.note.noteId),forceOrientation:`vertical`,splitOptions:{sizes:[70,30]}})}function D({ntxId:e}){let[t,n]=i();return c(`sqlQueryResults`,({ntxId:t,response:r})=>{t===e&&n(r)}),t===void 0?s(d,{icon:`bx bx-data`,text:a(`sql_result.not_executed`),children:s(u,{text:a(`sql_result.execute_now`),triggerCommand:`runActiveNote`})}):t&&!t.success?s(d,{icon:`bx bx-error`,text:a(`sql_result.failed`),children:s(`pre`,{className:`sql-error-message selectable-text`,children:t.error})}):t?.results.length===1&&Array.isArray(t.results[0])&&t.results[0].length===0?s(d,{icon:`bx bx-rectangle`,text:a(`sql_result.no_rows`)}):s(`div`,{className:`sql-result-widget`,children:s(`div`,{className:`sql-console-result-container selectable-text`,children:t?.results.map((e,t)=>typeof e==`object`&&!Array.isArray(e)?s(d,{icon:`bx bx-play`,text:a(`sql_result.statement_result`),children:s(`pre`,{children:JSON.stringify(e,null,`	`)},t)},t):s(O,{rows:e},t))})})}function O({rows:e}){if(e.length)return s(S,{layout:`fitDataFill`,modules:[g,w,h,v,C,_,p,f,x,m,y,b],selectableRange:!0,clipboard:`copy`,clipboardCopyRowRange:`range`,clipboardCopyConfig:{rowHeaders:!1,columnHeaders:!1},pagination:!0,paginationSize:15,paginationSizeSelector:!0,paginationCounter:`rows`,height:`100%`,columns:[{title:`#`,formatter:`rownum`,width:60,hozAlign:`right`,frozen:!0},...Object.keys(e[0]).map(e=>({title:e,field:e,width:250,minWidth:100,widthGrow:1,resizable:!0,headerFilter:!0}))],data:e})}function k({note:t}){let[n,c]=i();r(()=>{o.get(`sql/schema`).then(c)},[]);let u=t.isTriliumSqlite()&&n;return s(`div`,{className:`sql-table-schemas-widget ${u?``:`hidden-ext`}`,children:u&&s(e,{children:[a(`sql_table_schemas.tables`),`: `,s(`span`,{class:`sql-table-schemas`,children:n.map(({name:e,columns:t})=>s(l,{text:e,noSelectButtonStyle:!0,hideToggleArrow:!0,children:s(`table`,{className:`table-schema`,children:t.map(e=>s(`tr`,{children:[s(`td`,{children:e.name}),s(`td`,{children:e.type})]},e.name))})},e))})]})})}export{k as SqlTableSchemas,E as default};