import{Mn as e,Yr as t,hr as n,x as r}from"./KXnyWfWg.js";import{x as i}from"./BPCoDq-Y.js";import{t as a}from"./DBD7V8pT.js";function o(){let o=i(),s=a(),{t:c}=e(),l=t([]),u=t(!1),d=n(()=>l.value.filter(e=>e.type!==`merge`&&e.type!==`script`)),f=n(()=>l.value.filter(e=>e.type===`merge`)),p=n(()=>l.value.filter(e=>e.type===`script`)),m=t(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=>{try{return await o.refreshAndActivateProfile(e),await h(),r.success(c(`profilesRefreshed`)),!0}catch(e){return r.error(c(`profilesRefreshFailed`),{description:e instanceof Error?e.message:String(e)}),!1}},w=async(e,t)=>{await o.updateProfile(e,{content:t}),await h()},T=async(e,t)=>{await o.updateProfile(e,{updateInterval:t}),await h()},E=e=>o.getProfile(e),D=e=>o.validateProfile(e),O=async e=>{let t=await o.activateProfile(e);return m.value=e,await h(),await s.closeAllConnections(),t},k=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,refreshAndApply:C,save:w,saveMerge:async(e,t)=>{try{await o.updateProfile(e,{content:t}),await h(),await k()}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 k()}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 k()}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 k()}catch(e){r.error(c(`profilesScriptUpdateFailed`),{description:e instanceof Error?e.message:String(e)})}},setUpdateInterval:T,load:E,validate:D,activate:O}}export{o as t};