import{j as i,a1 as j}from"./vendor-ClLR6ncd.js";import{d as U}from"./lodash-ZyeDnt0e.js";import{q as N,f as o,ao as m,i as b}from"./index-OtVJl4GC.js";import{u as x,g as c,a as D}from"./useNamespaces-B-2wwTCG.js";import{P as S}from"./ui-CsX5tAWu.js";import{s as C,T as B}from"./ScopeCell-COF_9pDA.js";import{S as E,E as F,d as l,a as I,n as O}from"./index-GjHpFX-6.js";import{d as K}from"./Edit-Bg-98YAB.js";import"./model-DgFcCvKB.js";import"./Messages-BRmQDxrZ.js";import"./TableRow-CGDSOtFZ.js";import"./ui-DWck426r.js";import"./Person-UulRDhfg.js";import"./Storage-DvymGqui.js";import"./MenuItem-CCerWMyq.js";import"./dividerClasses-DvO85-mA.js";import"./pluralize-BF8NJH6e.js";import"./_commonjs-dynamic-modules-TDtrdbi3.js";import"./OptionallyDenseMuiTable-D7b58l1V.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";const d="prefix",T="namespace",p="namespaces";function M(t){return i.jsx(B,{entityKind:"namespace",...t})}const k={columns:[{key:d,label:"Prefix",sx:{width:"150px"}},{key:T,label:"URI"},C,{key:"table-actions",type:"actions",label:"",isEditable:!1,render:({row:t,onEditRow:s})=>i.jsx(j,{className:"action-button",size:"small",disabled:t.disabled,onClick:e=>{e.stopPropagation(),s==null||s(t)},children:i.jsx(K,{fontSize:"small"})})}],RowComponent:M},W=[k.columns[1].label];function ce(){const{username:t}=N(),{data:s}=x();return i.jsx(S,{title:"Namespaces",children:i.jsx(E,{Toolbar:F,useData:x,entityName:"namespace",cellsInfo:k,newDataMutationObj:O({validation:(e,a)=>e.filter(r=>U(r,a,"").trim()===""),urlBuilder:({urlEnd:e,...a})=>{var r;return((r=s==null?void 0:s.find(({prefix:n})=>n===e))==null?void 0:r.backendType)===c?o(m({username:t}),"gruff-namespaces",e):l({urlEnd:e,...a})}})({urlSuffix:p,labelKeys:W,keyForUrlEnd:d,keyForData:T,capitalizedEntitiesName:"Namespaces"}),deleteDataMutationObj:I({urlSuffix:p,keyForUrlEnd:d,urlBuilder:({urlEnd:e,backendType:a,...r})=>{if(a===c)return o(m({username:t}),"gruff-namespaces",e);if(a===D)return l({urlEnd:e,...r});throw new Error(`Unknown backendType: ${a}`)}}),editableRow:{enabled:!0,getRowId:e=>e.prefix,mapRowToFormData:e=>({prefix:e.prefix,namespace:e.namespace,type:e.type,backendType:e.backendType}),mapOriginalRowToDeleteRow:e=>({prefix:e.prefix,type:e.type,backendType:e.backendType}),mapFormDataToCreateRow:e=>({prefix:e.prefix,namespace:e.namespace,type:e.type,backendType:e.backendType})},editRowMutationObj:{validation:e=>Object.keys(e).some(a=>!e[a]),queryFn:async({originalRow:e,newRow:a},r,n)=>{const u=e.backendType===c,f=e.prefix,y=a.prefix,h=u?o(m({username:t}),"gruff-namespaces",f):l({urlPrefix:n,urlSuffix:p,urlEnd:f}),g=u?o(m({username:t}),"gruff-namespaces",y):l({urlPrefix:n,urlSuffix:p,urlEnd:y});await b({method:"delete",url:h,params:{type:e.type}}),await b({method:"put",url:g,params:{type:a.type},data:a.namespace})},invalidateRepoKeysOnSuccess:[p]}})})}export{ce as default};
