import{b as g}from"./components-DUSFgsKA.js";import{b as c,d as h,c as x}from"./bootstrap-BsWQM_6D.js";import{_ as m}from"./currency-Dtag6qPd.js";import{_ as b}from"./_plugin-vue_export-helper-DlAUqK2U.js";import{r as y,o as i,c as l,a as s,t as r,e as a,g as _,w as f}from"./runtime-core.esm-bundler-VrNrzzXC.js";import"./ns-prompt-popup-CwRKP6Ip.js";import"./ns-avatar-image-Pigdi04i.js";import"./chart-CAYz1qzV.js";const w={name:"ns-database-update",data(){return{files:Update.files,returnLink:Update.returnLink,modules:Update.modules,updating:!1,xXsrfToken:null,updatingModule:!1,error:!1,lastErrorMessage:"",index:0}},computed:{totalModules(){return Object.values(this.modules).length}},mounted(){c.get("/sanctum/csrf-cookie").subscribe(n=>{try{this.xXsrfToken=c.response.config.headers["X-XSRF-TOKEN"],this.proceedUpdate()}catch(e){h.error(e.message).subscribe()}})},methods:{__:m,async proceedUpdate(){this.updating=!0;for(let n in this.files)try{this.index=parseInt(n)+1;const e=await new Promise((d,u)=>{c.post("/api/update",{file:this.files[n]},{headers:{"X-XSRF-TOKEN":this.xXsrfToken}}).subscribe({next:d,error:u})})}catch(e){return this.updating=!1,this.error=!0,this.lastErrorMessage=e.message||m("An unexpected error occurred"),h.error(e.message).subscribe()}if(this.index=0,Object.values(this.modules).length>0){this.updatingModule=!0;let n=0;for(let e in this.modules)try{n+=1,this.index=n;const d=await new Promise((u,t)=>{c.post("/api/update",{module:this.modules[e]},{headers:{"X-XSRF-TOKEN":this.xXsrfToken}}).subscribe({next:u,error:t})})}catch(d){return this.updating=!1,this.error=!0,this.lastErrorMessage=d.message||m("An unexpected error occurred"),h.error(d.message).subscribe()}}this.error=!1,this.updating=!1,document.location=this.returnLink}}},k={class:"container mx-auto flex-auto items-center justify-center flex"},v={id:"database-update",class:"w-full md:w-2/3 lg:w-1/3"},U={class:"my-3 rounded shadow ns-box"},M={class:"border-b ns-box-header py-4 flex items-center justify-center"},X={class:"text-xl font-bold"},E={class:"p-2 ns-box-body"},T={class:"text-center text-sm py-4"},j={key:0,class:"border-l-4 text-sm ns-notice error p-4"},N={class:"rounded whitespace-pre-wrap my-2 p-2"},O={class:"border-t ns-box-footer p-2 flex justify-between"},S={class:"ml-1"},C={class:"flex"},B={key:0},L={key:1,class:"mr-1"},P={key:2},A={key:3,class:"mr-1"},R={class:"ml-1"};function D(n,e,d,u,t,o){const p=y("ns-button");return i(),l("div",k,[s("div",v,[e[4]||(e[4]=s("div",{class:"flex justify-center items-center py-6"},[s("img",{class:"w-32",src:"/svg/nexopos-variant-1.svg",alt:"NexoPOS"})],-1)),s("div",U,[s("div",M,[s("h3",X,r(o.__("Database Update")),1)]),s("div",E,[s("p",T,r(o.__("In order to keep NexoPOS running smoothly with updates, we need to proceed to the database migration. In fact you don't need to do any action, just wait until the process is done and you'll be redirected.")),1),t.error?(i(),l("div",j,[s("p",null,r(o.__("Looks like an error has occurred during the update. Usually, giving another shot should fix that. However, if you still don't get any chance."))+" "+r(o.__("Please report this message to the support : ")),1),s("pre",N,r(t.lastErrorMessage),1)])):a("",!0)]),s("div",O,[s("div",null,[t.error?(i(),_(p,{key:0,onClick:e[0]||(e[0]=I=>o.proceedUpdate()),type:"error",class:"rounded shadow-inner"},{default:f(()=>[e[1]||(e[1]=s("i",{class:"las la-sync"},null,-1)),s("span",S,r(o.__("Try Again")),1)]),_:1})):a("",!0)]),s("div",C,[t.updating?(i(),_(p,{key:0,type:"info",class:"rounded shadow-inner"},{default:f(()=>[e[2]||(e[2]=s("i",{class:"las la-sync animate-spin"},null,-1)),t.updatingModule?a("",!0):(i(),l("span",B,r(o.__("Updating"))+"...",1)),t.updatingModule?a("",!0):(i(),l("span",L,r(t.index)+"/"+r(t.files.length),1)),t.updatingModule?(i(),l("span",P,r(o.__("Updating Modules"))+"...",1)):a("",!0),t.updatingModule?(i(),l("span",A,r(t.index)+"/"+r(o.totalModules),1)):a("",!0)]),_:1})):a("",!0),t.updating?a("",!0):(i(),_(p,{key:1,type:"info",href:t.returnLink,class:"rounded shadow-inner"},{default:f(()=>[e[3]||(e[3]=s("i",{class:"las la-undo"},null,-1)),s("span",R,r(o.__("Return")),1)]),_:1},8,["href"]))])])])])])}const F=b(w,[["render",D]]);window.nsUpdate=x({components:{nsDatabaseUpdate:F}});for(let n in g)window.nsUpdate.component(n,g[n]);window.nsUpdate.mount("#main-container");
