import{H as a}from"./p-b06e2bef.js";import{d as t}from"./p-2f569553.js";import{S as e}from"./p-8b56f734.js";const{state:p,onChange:s}=t({goals:[],goalsLoading:!1,goalLoading:!1}),r={state:p,onChange:s};class n{constructor(){}static getInstance(){return n.instance||(n.instance=new n),n.instance}async getAllAppData(t){return await a.http.get(`api/v1/AppData/${t}`)}async createAppData(t){return await a.http.post("api/v1/AppData/",t)}async updateAppData(t){return await a.http.put(`api/v1/AppData/${t.Id}`,t)}async getAllGoals(){r.state.goalsLoading=!0;let a=await this.getAllAppData(e.MY_GOALS_APP_ID);return a&&(r.state.goals=a.Data.map((a=>Object.assign(Object.assign({},a),{AppData:JSON.parse(a.AppJsonData)}))),r.state.goalsLoading=!1),a}async createGoal(a){r.state.goalLoading=!0;let t=await this.createAppData(a);return t&&(t.Data.AppData=JSON.parse(t.Data.AppJsonData),r.state.goals=[...r.state.goals,t.Data],r.state.goalLoading=!1),t}async updateGoal(a){r.state.goalLoading=!0;let t=await this.updateAppData(a);return t&&(t.Data.AppData=JSON.parse(t.Data.AppJsonData),r.state.goals=r.state.goals.map((a=>a.Id==t.Data.Id?Object.assign(Object.assign({},t.Data),{AppData:JSON.parse(t.Data.AppJsonData)}):a)),r.state.goalLoading=!1),t}}export{n as A,r as g}