import{r as L,R as g,f as F,j as r,S as I,h as S,q as P,t as q,l as b,m as T,e as O}from"./vendor-ClLR6ncd.js";import{d as E}from"./Check-zAjPzJBD.js";import{H as N}from"./index-D0mM6sVf.js";import{q as U,b as h,j as W,aj as A,a as Q,ab as B,u as D,L as H}from"./index-OtVJl4GC.js";import{M as z}from"./CodeEditor-8Y6Lt-05.js";import{Q as M}from"./ui-B-JwMxCO.js";import"./lodash-ZyeDnt0e.js";import{o as _}from"./useSaveAsQuery-DVU3wx0g.js";import{u as X}from"./useBlockingServerSyncIndicator-BOWZddDC.js";import{u as Y}from"./model-Ci5wTidX.js";import{u as C}from"./useRunQuery-DVb2VeLN.js";import{u as $}from"./useNamespaces-B-2wwTCG.js";import"./Box-Co2WcNPC.js";import"./Divider-DZzUGEvZ.js";import"./dividerClasses-DvO85-mA.js";import"./ui-BOPU8Yl4.js";import"./index-CQ79H_Lz.js";import"./OptionallyDenseCodeMirror-S3gxMpRM.js";import"./useDirtyStateInput-CLFyv7KP.js";import"./PlayArrow-C5BebwRO.js";import"./Stop-D8ZTRatE.js";import"./ui-DKzyPIqx.js";import"./WithMeasure-BDk9QPMF.js";import"./model-Dfrorm_S.js";import"./highlightSearch-BTHB3jgf.js";import"./TableRow-CGDSOtFZ.js";import"./TableSortLabel-BJFq2axQ.js";import"./TypographyWithTooltip-BFAG3Va9.js";import"./Link-BLwKPJFF.js";import"./Autocomplete-Cjt7Q9VV.js";import"./Chip-DoCs8Smb.js";import"./model-DboSfqIs.js";import"./model-BneMh0-t.js";import"./model-DgFcCvKB.js";import"./model-C9Idzwgo.js";import"./model-DAvH-x8m.js";import"./Search-BYaM2U5J.js";import"./Warning-DsmyDRzF.js";import"./pluralize-BF8NJH6e.js";import"./_commonjs-dynamic-modules-TDtrdbi3.js";import"./Tabs-dk9tYIBM.js";import"./CreateDialogContext-Buan56-U.js";import"./Person-UulRDhfg.js";import"./Storage-DvymGqui.js";import"./object_hash-DuPyIO4t.js";import"./model-Cx9iH8L7.js";function G(){const{addOpenedQuery:e}=Q(),{repoConnection:t,currentQuery:o,isAnonymous:c}=h();return L.useCallback(n=>{e(t,{id:o,fake:c,...n})},[e,t,o,c])}function J(){const{username:e}=U(),t=Y(),{catalogId:o,repositoryId:c,queryId:n,isAnonymous:i,sessionId:x,sessionPort:m,queryLanguage:u,queryText:l}=h(),f=G(),a=L.useCallback(({local:p,remote:y,language:d})=>{f({...d===void 0?{}:{language:d},...p===void 0?{}:{local:p},...y===void 0?{}:{remote:y}})},[f]);g.useEffect(()=>{i&&a(l?{local:l,language:u}:{})},[i,a,l,u]);const{isFetching:j,data:s}=W(["query",n],async(p,{signal:y})=>{const d=await _({username:e,catalogId:o,repositoryId:c,sessionId:x,sessionPort:m,queryId:n},{signal:y});return{queryId:n,...d}},{enabled:!!n});return g.useEffect(()=>{(s==null?void 0:s.query)!==void 0&&a({remote:s.query,language:A(s.language)})},[s==null?void 0:s.query,s==null?void 0:s.language,a]),{queryText:t,setQueryText:a,isFetching:j}}function K(){var u;const e=F(),t=h(),{queryLanguage:o,repoConnection:c,currentQuery:n}=t,{getOpenedQueries:i}=Q(),m=(u=i(c)[n])==null?void 0:u.language;g.useEffect(()=>{o!==m&&m&&e(B(t)({id:n,language:m}),{replace:!0})},[o,m,e,t,n])}const V=(e,t)=>{if(e===void 0)return{};if(!t[e])throw new Error(`unsupported type ${e}`);return t[e]};function Z(e){const t=O();g.useEffect(()=>{var o;e.isIdle&&((o=t.state)!=null&&o.execTemplateQuery)&&e.refetch()},[t.state,e])}function Ye(){const{repoConnection:e,currentQuery:t}=h(),{getOpenedQueries:o}=Q(),c=X(),{isFetching:n,queryText:i,setQueryText:x}=J(),[m,u]=g.useState("exec"),l=C(i,u,"exec"),f=C(i,u,"logQuery"),a=C(i,u,"returnPlan"),{data:j,error:s,isFetching:p}=V(m,{exec:l,logQuery:f,returnPlan:a});K();const{data:y,isLoading:d}=$(),k=L.useCallback(()=>{var v;(v=o(e)[t].abortController)==null||v.abort()},[o,e,t]);Z(l);const R=Q(),w=D();return e?r.jsx(N,{Top:t?r.jsx(z,{readOnly:c,isFetching:n,setQueryText:x,queryText:i,cancelQuery:p?k:void 0,execQuery:l.refetch,logQuery:f.refetch,planQuery:a.refetch}):r.jsx(I,{p:2,height:1,justifyContent:"center",onDoubleClick:()=>w(R.addUntitledQuery(e)),children:r.jsxs(I,{overflow:"auto",alignItems:"flex-start",children:[r.jsx(S,{variant:"h5",pl:7,children:"Here you can:"}),r.jsxs(P,{children:[r.jsxs(q,{children:[r.jsx(b,{children:r.jsx(E,{})}),r.jsx(T,{primary:"Write and execute new queries in tabs.",secondary:'To create a new tab double-click anywhere in this container or click on the "+ NEW QUERY" button in the upper right corner.'})]}),r.jsxs(q,{children:[r.jsx(b,{children:r.jsx(E,{})}),r.jsx(T,{primary:"Select and execute an existing query.",secondary:'Click on an item in "Saved Queries" or "Query Templates" menus in the right menu.'})]}),r.jsxs(q,{children:[r.jsx(b,{children:r.jsx(E,{})}),r.jsx(T,{primary:"Explore results in table views.",secondary:'To execute a query click on the "EXECUTE" button in the bottom right corner of the query editor. To explore related triples click on a cell in the result table view.'})]})]})]})}),Bottom:r.jsx(M,{queryResult:j,queryResultError:s,isTableFetching:p,namespaces:y,isLoadingNamespaces:d})}):r.jsx(H,{})}export{Ye as default};
