import{d as l}from"./vendor-pinia-BSPefQhS.js";import{F as c}from"./admin-BM775jCq.js";import{l as o}from"./vendor-vue3-toastify-DBGjcIyK.js";const p=l("flow_store",{state:()=>({calculators:[],templates:[],categories:[],params:{limit:10,page:1,sortBy:"id",direction:"desc"},admin_email:"",pro_active:!1,unlock:!1,favorites:[],total:0,getFirstLoadCalculatorsCount:10,firstLoad:!0,selectedIds:[],viewType:"list"}),getters:{getCalculators:e=>e.calculators,getTemplates:e=>e.templates,getCategories:e=>e.categories,getAdminEmail:e=>e.admin_email,getProActive:e=>e.pro_active,getUnlock:e=>e.unlock,getFavorites:e=>e.favorites,getTotal:e=>e.total,getSelectedIds:e=>e.selectedIds,getViewType:e=>e.viewType},actions:{setCalculators(e){this.calculators=e},setTemplates(e){this.templates=e},setCategories(e){this.categories=e},setAdminEmail(e){this.admin_email=e},setProActive(e){this.pro_active=e},setUnlock(e){this.unlock=e},setFavorites(e){this.favorites=e},setTotal(e){this.total=e},setSelectedIds(e){this.selectedIds=e},setViewType(e){this.viewType=e},async fetchCalculators(){var a;this.setSelectedIds([]);const e=parseInt(localStorage.getItem("flow_page_size")||"10",10),t=parseInt(localStorage.getItem("flow_current_page")||"1",10);this.params.limit=e,this.params.page=t;const s=await c.fetchCalculators({action:"ccb_fetch_calculators",nonce:((a=window==null?void 0:window.ccb_nonces)==null?void 0:a.ccb_fetch_calculators)||"",params:this.params});s.success?(this.setCalculators(s.data.calculators),this.setTotal(Number(s.data.total)||0),this.firstLoad&&s.data.calculators&&(this.firstLoad=!1,this.getFirstLoadCalculatorsCount=s.data.calculators.length)):console.error(s.message)},async fetchTemplates(){var t,s;const e=await c.fetchTemplates({action:"ccb_fetch_templates",nonce:((t=window==null?void 0:window.ccb_nonces)==null?void 0:t.ccb_fetch_templates)||""});e.success?(this.setTemplates(e.data.templates),this.setCategories(e.data.categories),this.setAdminEmail(e.data.admin_email),this.setProActive(e.data.pro_active),this.setUnlock(e.data.unlock),this.setFavorites(((s=e.data.favorites)==null?void 0:s.map(a=>Number(a)))||[])):console.error(e.message)},async addFavoriteTemplate(e){var s,a;const t=await c.addFavoriteTemplate({action:"calc_toggle_favorite",nonce:((s=window==null?void 0:window.ccb_nonces)==null?void 0:s.ccb_toggle_favorite)||"",template_id:e});t.success?(this.setFavorites(((a=t.data.favorites)==null?void 0:a.map(i=>Number(i)))||[]),o(t.message,{type:"success"})):o(t.message,{type:"error"})},async deleteTemplate(e){var s;const t=await c.deleteTemplate({action:"calc_delete_templates",nonce:((s=window==null?void 0:window.ccb_nonces)==null?void 0:s.ccb_delete_template)||"",id:e});t.success?(t.templates&&this.setTemplates(Object.values(t.templates)),o(t.message,{type:"success"})):o(t.message,{type:"error"})}}});export{p as u};
//# sourceMappingURL=useFlowStore-BY5s8sLu.js.map
