import{j as t,S as E,h as R,H as x,s as F,v as C,R as p,r as I}from"./vendor-ClLR6ncd.js";import{j as f,i as y,f as h,L as g,b as j,a2 as L,ax as k,a as w}from"./index-OtVJl4GC.js";import{H as B}from"./index-D0mM6sVf.js";import{Q as O}from"./ui-B-JwMxCO.js";import{u as T}from"./model-Ci5wTidX.js";import{u as A}from"./useNamespaces-B-2wwTCG.js";import{S as D}from"./SmallStandardSelect-7k6-Wr8Q.js";import{q as H}from"./lodash-ZyeDnt0e.js";import{B as N}from"./Box-Co2WcNPC.js";import"./Divider-DZzUGEvZ.js";import"./dividerClasses-DvO85-mA.js";import"./Search-BYaM2U5J.js";import"./Warning-DsmyDRzF.js";import"./pluralize-BF8NJH6e.js";import"./_commonjs-dynamic-modules-TDtrdbi3.js";import"./highlightSearch-BTHB3jgf.js";import"./WithMeasure-BDk9QPMF.js";import"./TableRow-CGDSOtFZ.js";import"./TableSortLabel-BJFq2axQ.js";import"./Tabs-dk9tYIBM.js";import"./model-DgFcCvKB.js";import"./MenuItem-CCerWMyq.js";const c=" ";function P(){const e=f(["text-indexes"],a=>y({url:h(a,"freetext/indices")})),r=[{label:"All indexes",value:c},...(e.data||[]).map(a=>({label:a,value:a}))],s=!Array.isArray(e.data)||e.data.length===0;return{isLoading:e.isLoading,disabled:s,indexes:r}}const z={width:"300px"};function J({indexes:e,value:r,onChange:s}){return t.jsx(D,{items:e,value:r,onChange:s,fullWidth:!1,sx:z,label:"Text indexes to use"})}function M({currentFreeTextIndex:e,setCurrentFreeTextIndex:r,setQueryText:s,queryText:a,execQuery:i}){const{isLoading:u,disabled:n,indexes:o}=P();return u?t.jsx(g,{}):n?t.jsxs(E,{justifyContent:"center",alignItems:"center",sx:{p:2,height:1},spacing:2,children:[t.jsx(R,{align:"center",children:"There are currently no free-text indices defined in this repository, so your query won't yield results!"}),t.jsx(x,{component:F,to:"../../control/free-text/new",relative:!0,variant:"contained",children:"Create free-text index"})]}):t.jsxs(N,{sx:{height:1,display:"flex",flexDirection:"column",gap:2,p:2},children:[t.jsx(J,{value:e,onChange:l=>r(l.target.value),indexes:o}),t.jsx(C,{disabled:n,value:a,onChange:l=>s(l.target.value),label:"Search",helperText:"Multiple words mean 'all of these terms'. Double-quote text to mean 'literally this'. The '|' character signifies 'or', and parentheses group terms.",variant:"standard"}),t.jsx(x,{disabled:n,onClick:i,children:"Execute query"})]})}class m extends Error{}function V(e){const{currentQuery:r}=j(),s=T(),{queryOptions:a}=L();return f([r],async i=>({values:await y({url:h(i,"freetext"),params:{pattern:s,...e!==c?{index:e}:{},...H(a,["infer","limit"])}},n=>{var o;return((o=n==null?void 0:n.response)==null?void 0:o.status)===400?m:Error}),names:["Subject","Predicate","Object"]}),{enabled:!1,retry:(i,u)=>k(u)||u instanceof m?!1:i<3})}function pe(){const{catalogId:e,repositoryId:r,currentQuery:s}=j(),a=T(),[i,u]=p.useState(c),{addOpenedFreetextQuery:n}=w(),o=I.useCallback(d=>{n(r,{id:s,freetext:!0,...d!==void 0?{local:d}:{}})},[n,r,s]);p.useEffect(()=>{o()},[o]);const{data:l,error:Q,isFetching:b,refetch:v}=V(i),{data:S,isLoading:q}=A();return!r||!e?t.jsx(g,{}):t.jsx(B,{Top:t.jsx(M,{currentFreeTextIndex:i,setCurrentFreeTextIndex:u,setQueryText:o,queryText:a,execQuery:v}),Bottom:t.jsx(O,{queryResult:l,queryResultError:Q,isTableFetching:b,namespaces:S,isLoadingNamespaces:q})})}export{pe as default};
