import{Dr as e,Er as t,Hi as n,Qt as r,fi as i,in as a,t as o,wn as s}from"./CWa6_HoJ.js";import{t as c}from"./CTSjSKt2.js";function l(){let l=s(),u=t(),d=r(),{t:f}=e(),p=n([]),m=n(!1),h=i(()=>p.value.filter(e=>e.type!==`merge`&&e.type!==`script`)),g=i(()=>p.value.filter(e=>e.type===`merge`)),_=i(()=>p.value.filter(e=>e.type===`script`)),v=n(void 0),y=async()=>{m.value=!0;try{p.value=await l.listProfiles()}finally{m.value=!1}},b=async e=>{await l.createProfile(e),await y()},x=async e=>{await b({name:e,type:`merge`})},S=async e=>{await b({name:e,type:`script`})},C=async(e,t)=>{await l.duplicateProfile(e,t),await y()},w=async e=>{await l.deleteProfile(e),await y()},T=async(e,t)=>{await l.importProfile(e,t),await y()},E=async e=>{try{return await l.refreshProfile(e),await y(),o.success(f(`profilesRefreshed`)),!0}catch(e){return o.error(f(`profilesRefreshFailed`),{description:c(e)}),!1}},D=async e=>{try{return await l.refreshAndActivateProfile(e),await u.invalidateQueries({queryKey:a.config}),await y(),o.success(f(`profilesRefreshed`)),!0}catch(e){return o.error(f(`profilesRefreshFailed`),{description:c(e)}),!1}},O=async(e,t)=>{await l.updateProfile(e,{content:t}),await y()},k=async(e,t)=>{await l.updateProfile(e,{updateInterval:t}),await y()},A=e=>l.getProfile(e),j=e=>l.validateProfile(e),M=async e=>{let t=await l.activateProfile(e);return v.value=e,await u.invalidateQueries({queryKey:a.config}),await y(),await d.closeAllConnections(),t},N=async()=>{if(!v.value){o.info(f(`profilesMergeNoActiveBase`));return}await l.activateProfile(v.value),await u.invalidateQueries({queryKey:a.config})};return{profiles:p,baseProfiles:h,mergeProfiles:g,scriptProfiles:_,activeBaseId:v,loading:m,refresh:y,create:b,createMerge:x,createScript:S,duplicate:C,remove:w,importUrl:T,refreshRemote:E,refreshAndApply:D,save:O,saveMerge:async(e,t)=>{try{await l.updateProfile(e,{content:t}),await y(),await N()}catch(e){o.error(f(`profilesMergeUpdateFailed`),{description:c(e)})}},saveScript:async(e,t)=>{try{await l.updateProfile(e,{content:t}),await y(),await N()}catch(e){o.error(f(`profilesScriptUpdateFailed`),{description:c(e)})}},setEnabled:async(e,t)=>{try{await l.updateProfile(e,{enabled:t}),await y(),await N()}catch(e){o.error(f(`profilesMergeUpdateFailed`),{description:c(e)})}},setScriptEnabled:async(e,t)=>{try{await l.updateProfile(e,{enabled:t}),await y(),await N()}catch(e){o.error(f(`profilesScriptUpdateFailed`),{description:c(e)})}},setUpdateInterval:k,load:A,validate:j,activate:M}}export{l as t};