import{j as o,h as I,a1 as k,r as p}from"./vendor-ClLR6ncd.js";import{d as q}from"./Edit-Bg-98YAB.js";import{S as D,E as F,d as v,a as V,b as g}from"./index-GjHpFX-6.js";import{s as Q,T as K}from"./ScopeCell-COF_9pDA.js";import{ap as M,i as h,T as c}from"./index-OtVJl4GC.js";import"./lodash-ZyeDnt0e.js";import{c as W}from"./model-BneMh0-t.js";import{o as d,u as U}from"./model-DboSfqIs.js";import{A as C}from"./Autocomplete-Cjt7Q9VV.js";import"./pluralize-BF8NJH6e.js";import"./_commonjs-dynamic-modules-TDtrdbi3.js";import"./ui-DWck426r.js";import"./Person-UulRDhfg.js";import"./Storage-DvymGqui.js";import"./MenuItem-CCerWMyq.js";import"./dividerClasses-DvO85-mA.js";import"./OptionallyDenseMuiTable-D7b58l1V.js";import"./TableRow-CGDSOtFZ.js";import"./TableContainer-CN5gAdqf.js";import"./Add-CLrXAvOx.js";import"./Box-Co2WcNPC.js";import"./Delete-BD9BsoWc.js";import"./ui-C5v50YHw.js";import"./index-DY-IkI-n.js";import"./DialogContent-DR8Wx7Lo.js";import"./DialogTitle-i0lt2jWQ.js";import"./Toolbar-Dprnudzf.js";import"./Divider-DZzUGEvZ.js";import"./model-DgFcCvKB.js";import"./model-C9Idzwgo.js";import"./model-DAvH-x8m.js";import"./Chip-DoCs8Smb.js";const A=d.map(({name:t})=>t),S=()=>{};function R({Context:t,children:a,row:e}){const s=(e==null?void 0:e.name)||"",r=(e==null?void 0:e.value)||"",[n,i]=p.useState(s),[l,b]=p.useState(r),x=p.useCallback(u=>{const m=d.find(({name:E})=>E===u)||{};i(u),e!=null&&e.name||b(m.defaultValue||"")},[e==null?void 0:e.name]),O=U(),T=p.useMemo(()=>{var u;return{optionName:n,setOptionName:x,optionValue:l,setOptionValue:b,valueOptions:O.current[n]||((u=d.find(({name:m})=>m===n))==null?void 0:u.options)}},[n,x,l,O]);return o.jsx(t.Provider,{value:T,children:a})}function z({label:t,setter:a,row:e}){const{optionName:s,setOptionName:r}=p.useContext(e.Context);return o.jsx(C,{freeSolo:!0,value:s,onInputChange:(n,i)=>{a(i),r(i)},options:A,renderInput:n=>o.jsx(c,{...n,label:t,setter:S})})}function B({row:t,...a}){const{setter:e}=a,{optionValue:s,setOptionValue:r,valueOptions:n}=p.useContext(t.Context);return Array.isArray(n)?o.jsx(C,{freeSolo:!0,value:s,onInputChange:(i,l)=>{r(l),e(l)},options:n,renderInput:i=>o.jsx(c,{...i,label:"Value",setter:S})}):o.jsx(c,{value:s,...a,setter:i=>{r(i),e(i)}})}const y="name",N="value",j="query-options";function P(t){return o.jsx(K,{entityKind:"query option",...t})}const f={columns:[{key:y,label:"Name",EditableComponent:z},{key:N,label:"Value",EditableComponent:B,sx:{width:"40%"}},Q,{key:"table-actions",type:"actions",label:"",isEditable:!1,render:({row:t,onEditRow:a})=>o.jsx(k,{className:"action-button",size:"small",disabled:t.disabled,onClick:e=>{e.stopPropagation(),a==null||a(t)},children:o.jsx(q,{fontSize:"small"})})}],RowContextProvider:R,RowComponent:P},_=[f.columns[0].label,f.columns[1].label];function St(){return o.jsxs(o.Fragment,{children:[o.jsx(I,{variant:"h4",children:"Query execution options"}),o.jsx(D,{Toolbar:F,useData:W,entityName:"query option",cellsInfo:f,newDataMutationObj:g({urlSuffix:j,labelKeys:_,keyForUrlEnd:y,keyForData:N,capitalizedEntitiesName:"Query options"}),deleteDataMutationObj:V({urlSuffix:j,keyForUrlEnd:y}),editableRow:{enabled:!0,getRowId:t=>t.name,mapRowToFormData:t=>({name:t.name,value:t.value,type:t.type}),mapOriginalRowToDeleteRow:t=>({name:t.name,type:t.type}),mapFormDataToCreateRow:t=>({name:t.name,value:t.value,type:t.type})},editRowMutationObj:{validation:t=>Object.keys(t).some(a=>!t[a]),queryFn:async({originalRow:t,newRow:a},e,s)=>{const r=t.name,n=a.name;await h({method:"delete",url:v({urlPrefix:s,urlSuffix:"query-options",urlEnd:r}),params:{type:t.type}}),await h({method:"put",url:v({urlPrefix:s,urlSuffix:"query-options",urlEnd:n}),params:{type:a.type},data:a.value})},invalidateRepoKeysOnSuccess:M()}})]})}export{St as default};
