import{Kr as e,fr as t,kn as n,x as r}from"./D-ctIW6J.js";import{n as i}from"./CYOuLF0m.js";import{t as a}from"./CUHMViAI.js";function o(){let o=i(),s=a(),{t:c}=n(),l=e([]),u=e(!1),d=t(()=>l.value.filter(e=>e.type!==`merge`&&e.type!==`script`)),f=t(()=>l.value.filter(e=>e.type===`merge`)),p=t(()=>l.value.filter(e=>e.type===`script`)),m=e(void 0),h=async()=>{u.value=!0;try{l.value=await o.listProfiles()}finally{u.value=!1}},g=async e=>{await o.createProfile(e),await h()},_=async e=>{await g({name:e,type:`merge`})},v=async e=>{await g({name:e,type:`script`})},y=async(e,t)=>{await o.duplicateProfile(e,t),await h()},b=async e=>{await o.deleteProfile(e),await h()},x=async(e,t)=>{await o.importProfile(e,t),await h()},S=async e=>{try{return await o.refreshProfile(e),await h(),r.success(c(`profilesRefreshed`)),!0}catch(e){return r.error(c(`profilesRefreshFailed`),{description:e instanceof Error?e.message:String(e)}),!1}},C=async(e,t)=>{await o.updateProfile(e,{content:t}),await h()},w=e=>o.getProfile(e),T=e=>o.validateProfile(e),E=async e=>{let t=await o.activateProfile(e);return m.value=e,await h(),await s.closeAllConnections(),t},D=async()=>{if(!m.value){r.info(c(`profilesMergeNoActiveBase`));return}await o.activateProfile(m.value)};return{profiles:l,baseProfiles:d,mergeProfiles:f,scriptProfiles:p,activeBaseId:m,loading:u,refresh:h,create:g,createMerge:_,createScript:v,duplicate:y,remove:b,importUrl:x,refreshRemote:S,save:C,saveMerge:async(e,t)=>{try{await o.updateProfile(e,{content:t}),await h(),await D()}catch(e){r.error(c(`profilesMergeUpdateFailed`),{description:e instanceof Error?e.message:String(e)})}},saveScript:async(e,t)=>{try{await o.updateProfile(e,{content:t}),await h(),await D()}catch(e){r.error(c(`profilesScriptUpdateFailed`),{description:e instanceof Error?e.message:String(e)})}},setEnabled:async(e,t)=>{try{await o.updateProfile(e,{enabled:t}),await h(),await D()}catch(e){r.error(c(`profilesMergeUpdateFailed`),{description:e instanceof Error?e.message:String(e)})}},setScriptEnabled:async(e,t)=>{try{await o.updateProfile(e,{enabled:t}),await h(),await D()}catch(e){r.error(c(`profilesScriptUpdateFailed`),{description:e instanceof Error?e.message:String(e)})}},load:w,validate:T,activate:E}}export{o as t};