import{c as l}from"./config2.js";import{e as m}from"./main.js";const g={dataId:"",groupName:"",appName:"",configTags:"",configType:"",searchMode:"blur",configDetail:""},y=m((r,f)=>({configs:[],loading:!1,total:0,pageNo:1,pageSize:10,...g,selectedIds:new Set,currentConfig:null,detailLoading:!1,error:null,fetchConfigs:async a=>{r({loading:!0,error:null});try{const{dataId:e,groupName:o,appName:t,configTags:s,configType:n,searchMode:p,configDetail:c,pageNo:u,pageSize:S}=f(),i={dataId:e||void 0,groupName:o||void 0,appName:t||void 0,configTags:s||void 0,type:n||void 0,search:p,configDetail:c||void 0,pageNo:u,pageSize:S,namespaceId:a},d=(c?await l.searchDetail(i):await l.list(i)).data;r({configs:d.pageItems||[],total:d.totalCount||0,loading:!1})}catch(e){const t=e.response?.data?.message||"Failed to fetch configs";r({loading:!1,error:t,configs:[],total:0})}},setSearchParams:a=>{r(e=>({...e,...a,pageNo:1}))},setPage:(a,e)=>{r(o=>({pageNo:a,pageSize:e??o.pageSize,selectedIds:new Set}))},fetchConfig:async(a,e,o)=>{r({detailLoading:!0,error:null});try{const s=await l.get({dataId:a,groupName:e,namespaceId:o});r({currentConfig:s.data,detailLoading:!1})}catch(t){const n=t.response?.data?.message||"Failed to fetch config";r({detailLoading:!1,error:n,currentConfig:null})}},deleteConfig:async(a,e,o)=>{try{return await l.delete({dataId:a,groupName:e,namespaceId:o}),!0}catch(t){const n=t.response?.data?.message||"Failed to delete config";return r({error:n}),!1}},resetSearch:()=>{r({...g,pageNo:1,selectedIds:new Set})},clearCurrentConfig:()=>{r({currentConfig:null})},clearError:()=>{r({error:null})},toggleSelect:a=>{r(e=>{const o=new Set(e.selectedIds);return o.has(a)?o.delete(a):o.add(a),{selectedIds:o}})},selectAll:()=>{r(a=>{const e=a.configs.filter(t=>t.id).map(t=>t.id);return{selectedIds:e.length>0&&e.every(t=>a.selectedIds.has(t))?new Set:new Set(e)}})},clearSelection:()=>{r({selectedIds:new Set})}}));export{y as u};
