import{p as n}from"./prompt-CozkN53S.js";import{y as d}from"./main.js";const h=d((t,i)=>({prompts:[],loading:!1,total:0,pageNo:1,pageSize:12,searchKey:"",searchMode:"blur",selectedKeys:new Set,currentMeta:null,currentVersion:null,detailLoading:!1,versionList:[],versionsTotal:0,versionsPageNo:1,versionsPageSize:10,error:null,fetchPrompts:async r=>{const o=i().prompts.length>0;t({loading:!o,error:null});try{const{searchKey:e,searchMode:a,pageNo:c,pageSize:l}=i(),p=(await n.listPrompts({promptKey:e||void 0,namespaceId:r,search:a,pageNo:c,pageSize:l})).data;t({prompts:p.pageItems||[],total:p.totalCount||0,loading:!1})}catch(e){t({loading:!1,error:e.response?.data?.message||"Failed to fetch prompts",prompts:[],total:0})}},fetchPromptMetadata:async(r,o)=>{try{const a=await n.getPromptMetadata({promptKey:o,namespaceId:r});t({currentMeta:a.data})}catch(e){t({error:e.response?.data?.message||"Failed to fetch prompt metadata"})}},fetchPromptDetail:async(r,o,e,a)=>{const c=i().currentVersion!==null;t({detailLoading:!c,error:null});try{const s=await n.getPromptDetail({promptKey:o,version:e,label:a,namespaceId:r});t({currentVersion:s.data,detailLoading:!1})}catch(l){t({detailLoading:!1,error:l.response?.data?.message||"Failed to fetch prompt detail",currentVersion:null})}},fetchVersionList:async(r,o)=>{try{const{versionsPageNo:e,versionsPageSize:a}=i(),s=(await n.listVersions({promptKey:o,namespaceId:r,pageNo:e,pageSize:a})).data;t({versionList:s.pageItems||[],versionsTotal:s.totalCount||0})}catch{t({versionList:[],versionsTotal:0})}},deletePrompt:async(r,o)=>{try{return await n.deletePrompt({promptKey:o,namespaceId:r}),!0}catch(e){return t({error:e.response?.data?.message||"Failed to delete prompt"}),!1}},batchDelete:async(r,o)=>{let e=!0;for(const a of o)try{await n.deletePrompt({promptKey:a,namespaceId:r})}catch{e=!1}return t({selectedKeys:new Set}),e},setSearchParams:r=>{t(o=>({...o,...r,pageNo:1}))},setPage:(r,o)=>{t(e=>({pageNo:r,pageSize:o??e.pageSize}))},setVersionsPage:(r,o)=>{t(e=>({versionsPageNo:r,versionsPageSize:o??e.versionsPageSize}))},resetSearch:()=>{t({searchKey:"",searchMode:"blur",pageNo:1})},toggleSelect:r=>{t(o=>{const e=new Set(o.selectedKeys);return e.has(r)?e.delete(r):e.add(r),{selectedKeys:e}})},selectAll:r=>{t({selectedKeys:new Set(r)})},clearSelection:()=>{t({selectedKeys:new Set})},clearCurrentPrompt:()=>{t({currentMeta:null,currentVersion:null,versionList:[],versionsTotal:0,versionsPageNo:1})},clearError:()=>{t({error:null})}}));export{h as u};
