import{a as i}from"./languageTemplateApi-DtS3Soe6.js";import{a8 as o,ai as l,ab as s,ak as c}from"./main-CJbVOHh0.js";const u=o("languageTemplates",{state:()=>({templates:[],template:null,readiness:null,loading:!1,saving:!1,checking:!1,error:null,total:0}),actions:{async fetchOccupiedLanguageCodes(){var r,a,t;try{const e=await i.fetchOccupiedLanguageCodes();return(r=e.data)!=null&&r.status&&Array.isArray((t=(a=e.data)==null?void 0:a.data)==null?void 0:t.language_codes)?e.data.data.language_codes.map(n=>String(n).toLowerCase().trim()):[]}catch(e){return this.error=l(e),s("error","Error",this.error),[]}},async fetchTemplates({page:r=1,rows:a=10,search:t=""}={}){this.loading=!0,this.error=null;try{const e=await i.fetchTemplates({page:r,per_page:a,search:t});e.data.status&&(this.templates=e.data.data.data,this.total=e.data.data.total)}catch(e){this.error=l(e),s("error","Error",this.error)}finally{this.loading=!1}},async addTemplate(r){this.saving=!0;try{const a=await i.createTemplate(r);return a.data.status&&s("success","Success",a.data.message||"Template created successfully"),a.data}catch(a){throw this.error=l(a),s("error","Error",this.error),a}finally{this.saving=!1}},async fetchTemplateById(r,a={}){this.loading=!0,this.error=null;try{const t=await i.fetchTemplateById(r,a);return t.data.status&&(this.template=t.data.data.template,this.readiness=t.data.data.readiness),t.data.data}catch(t){this.error=l(t),s("error","Error",this.error)}finally{this.loading=!1}},async updateTemplate(r,a){this.saving=!0;try{const t=await i.updateTemplate(r,a);return t.data.status&&s("success","Success",t.data.message||"Template updated successfully"),t.data}catch(t){throw this.error=l(t),s("error","Error",this.error),t}finally{this.saving=!1}},async deleteTemplate(r){this.loading=!0;try{const a=await i.deleteTemplate(r);return a.data.status&&(this.templates=c(this.templates,r),this.total--,s("success","Deleted","Template deleted successfully")),a.data}catch(a){return this.error=l(a),s("error","Error",this.error),{status:!1,message:this.error}}finally{this.loading=!1}},async updateStatus(r,a,t=null){this.saving=!0;try{const e=await i.updateTemplateStatus(r,{status:a,franchisee_id:t});return e.data.status&&(this.template=e.data.data.template||this.template,e.data.data.readiness&&(this.readiness=e.data.data.readiness),s("success","Success",e.data.message||`Status updated to ${a}`)),e.data}catch(e){return this.error=l(e),s("warn","Readiness Warning",this.error),{status:!1,message:this.error}}finally{this.saving=!1}},async checkPageTranslation(r){this.checking=!0;try{return(await i.checkPageTranslation(r)).data}catch(a){return this.error=l(a),{status:!1,message:this.error}}finally{this.checking=!1}},async refreshReadiness(r,a=null){this.checking=!0;try{const t=await i.checkReadiness(r,{franchisee_id:a});return t.data.status&&(this.template=t.data.data.template,this.readiness=t.data.data.readiness),t.data}catch(t){this.error=l(t),s("error","Error",this.error)}finally{this.checking=!1}}}});export{u};
