import{r as _,d as L,a as o,y as T,u as $,L as q,x as j,a6 as I,c as U,b as N,e as O,w,f as d,G as z,S as G,g as p,i as H,O as Q,h as V,a8 as W,ct as J,D as K,T as R}from"./index-OSKNspXo.js";import{Q as X}from"./QForm-PGP8CIo6.js";class Y{async upload(n,e){let i=new FormData;return i.append("file",n),i.append("type",e),(await _.post("/api/acced/settings/messages/importdefault",i,{headers:{"Content-Type":"multipart/form-data"}})).data.data}async count(n,e){return(await _.post("/api/acced/settings/messages/count",e,{})).data.count}async getAll(n,e){return(await _.post("/api/acced/settings/messages",e,{})).data.list}async update(n,e){return(await _.put("/api/acced/settings/messages",e,{})).data.list}}const Z=L("SettingAccedMessagesStore",()=>{const f=new Y,n=o([]),e=o(!1),i=o(!1),m=new AbortController,l=o(null),c=o(!1),g=o(!1),S=o(0),v=o([]),y=o({age:0,rowsPerPage:30}),r=o(null),u=o([]),s=o([]),a=o(""),b=[{code:"ACCED_V2",label:"setting.messages.acced.v2.label"},{code:"ACCED_V3",label:"setting.messages.acced.v3.label"}],k=[{code:0,label:"setting.messages.default.information"},{code:1,label:"setting.messages.default.alert"}];T(g,()=>{g.value&&(r.value={pk:l.value.pk,duration:l.value.duration})});function x(){v.value=[],u.value=[...b],s.value=[...k],u.value.forEach(t=>t.isSelected=!1),s.value.forEach(t=>t.isSelected=!1),y.value={age:0,rowsPerPage:30},a.value=""}async function h(){y.value={page:0,rowsPerPage:30},n.value=[],c.value=!0,await Promise.all([C(),D()])}async function C(){try{let t=await f.getAll(m.value,P());n.value.push(...t)}finally{c.value=!1}}async function D(){try{S.value=await f.count(m.value,P())}finally{c.value=!1}}async function F(t,A){await f.upload(t,A.code),await h()}function M(){l.value=null,e.value=null,g.value=!1}function B(){g.value=!1}async function E(){await f.update(m.value,r.value),l.value.duration=r.value.duration;let t=n.value.find(A=>A.pk===r.value.pk);t&&(t.duration=r.value.duration)}function P(){return{pagination:y.value,criterias:v.value,type_machines:u.value.filter(t=>t.isSelected).map(t=>t.code),default_lvl:s.value.filter(t=>t.isSelected).map(t=>t.code)}}return{list:n,drawer:e,openImport:i,selected:l,isLoading:c,isEditMode:g,accedTypes:b,pagination:y,search:a,total:S,criterias:v,accedTypeFilter:u,defaultFilter:s,form:r,upload:F,closeWindow:M,applyFilter:h,getAll:C,count:D,resetFilter:x,close:B,update:E}}),ee={class:"form-group"},ae={class:"form-group"},te={class:"row justify-center"},oe={__name:"modalImportComponent",props:{open:{type:Boolean}},emits:["update:open"],setup(f,{emit:n}){const{t:e}=$({useScope:"parent"});q();const i=j(),m=Z(),l=I({typeAcced:null,file:null}),c=o(!1),g=f,S=n,v=U({get:()=>g.open,set:function(u){S("update:open",u)}});function y(){l.file=null,l.typeAcced=null,v.value=!1}async function r(){var u,s;try{c.value=!0,await m.upload(l.file,l.typeAcced),i.notify({message:e("setting.messages.acced.import.success"),type:"positive"}),y()}catch(a){console.error(a);let b=(s=(u=a.response)==null?void 0:u.data)==null?void 0:s.message;i.notify({message:e(b||"ui.generic.error"),type:"negative"})}finally{c.value=!1}}return(u,s)=>(O(),N(R,{class:"text-primary",modelValue:v.value,"onUpdate:modelValue":s[2]||(s[2]=a=>v.value=a)},{default:w(()=>[d(z,{style:{width:"500px","max-width":"80vw"}},{default:w(()=>[d(G,{title:p(e)("setting.messages.acced.import.title"),click:y},null,8,["title"]),d(X,{onSubmit:H(r,["prevent","stop"]),greedy:"",class:"q-pl-md q-pr-md"},{default:w(()=>[d(Q,{style:{"padding-right":"0","padding-left":"0"}},{default:w(()=>[V("div",ee,[d(W,{filled:"",label:p(e)("setting.messages.acced.import.type"),rules:[a=>a!==null||p(e)("setting.messages.acced.import.type.empty")],options:p(m).accedTypes,"option-value":"code",disable:c.value,"option-label":a=>Object(a)===a&&"label"in a?p(e)(a.label):"","lazy-rules":"",modelValue:l.typeAcced,"onUpdate:modelValue":s[0]||(s[0]=a=>l.typeAcced=a)},null,8,["label","rules","options","disable","option-label","modelValue"])]),V("div",ae,[d(J,{modelValue:l.file,"onUpdate:modelValue":s[1]||(s[1]=a=>l.file=a),label:p(e)("setting.messages.acced.import.file"),rules:[a=>a!==null||p(e)("setting.messages.acced.import.file.empty")],filled:"",counter:"",accept:".csv"},null,8,["modelValue","label","rules"])])]),_:1}),d(Q,null,{default:w(()=>[V("div",te,[d(K,{type:"submit",loading:c.value,label:p(e)("setting.messages.acced.import.generate")},null,8,["loading","label"])])]),_:1})]),_:1})]),_:1})]),_:1},8,["modelValue"]))}};export{oe as _,Z as u};
//# sourceMappingURL=modalImportComponent-d-CaOEYM.js.map
