import{y as D,b as $,f as z}from"./primevue-CfIk0_DY.js";import{C as U}from"./ComboDynamique-BzWI4ISP.js";import{u as h,b as g,s as t,S as F}from"./index-BxIwIJfy.js";import{w as T,o as B,b as c,k as f,l as M,d as n,v as d,c as P,p as S,a as s}from"./vue-core-Di3IuVqe.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";const J={class:"flex flex-col gap-4"},N={key:0},Y={__name:"FusionDesCodesEtMiseJour",setup(q){const{showError:b,showSuccess:x,showWarn:u}=h(),i=s(!1),E=()=>{i.value=!1,F("FusionDesCodesEtMiseJour")},I=[{Id:"article",Libelle:"Article"},{Id:"client",Libelle:"Client"},{Id:"fournisseur",Libelle:"Fournisseur"}],o=s("article"),y=s(0),V=s(0),p=s(""),m=s("");T(o,()=>{y.value++,V.value++});const L=[{Id:"Fusion",Libelle:"Fusion des codes"},{Id:"Maj",Libelle:"Mise à jour libellé article"}],r=s("Fusion"),v=s(!0),R=()=>{r.value=="Fusion"?v.value=!0:v.value=!1};B(async()=>{await _()});const _=async()=>{try{const e=(await g.post(`${t.lienApi}/verifierDroit/${t.state.dbCommun6}`,{id_utilisateur:t.userId,id_page:1206,mail:t.state.userCloud.mail},{headers:{"Content-Type":"application/json"}})).data;if(e&&Object.keys(e).length>0&&!e.lecture){u("Vous n'avez pas le droit, veuillez consulter l'administrateur"),F("FusionDesCodesEtMiseJour");return}i.value=!0}catch(a){b("Une erreur est survenue : "+(a.response?.data?.message||a.message))}finally{t.state.afficher_in_progress=!1}},j=async()=>{if(o.value!="article"&&r.value=="Maj"){u("Veuillez sélectionner le type article et choisir l'article");return}if(m.value===""&&r.value=="Fusion"){u("Veuillez remplir le code remplaçant");return}if(p.value===""){u("Veuillez remplir le code à remplacer");return}try{const a=await g.post(`${t.lienApi}/FusionEtMaj/${t.db}`,{fusionMaj:r.value,typeElement:o.value,codeAremplacer:p.value,codeRemplacant:m.value});x(a.data.message)}catch(a){b(`Une erreur est survenue lors de l'opération
 ${a}`)}};return(a,e)=>{const C=D,k=U,w=$,A=z;return c(),f(A,{visible:i.value,"onUpdate:visible":e[5]||(e[5]=l=>i.value=l),modal:"",draggable:!1,header:"Fusion des codes / Mise à jour",style:{width:"480px"},breakpoints:{"640px":"95vw"},onHide:E},{footer:M(()=>[d(w,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[4]||(e[4]=l=>i.value=!1)}),d(w,{icon:"pi pi-refresh",label:"Remplacer",onClick:j})]),default:M(()=>[n("div",J,[n("div",null,[d(C,{size:"small",modelValue:o.value,"onUpdate:modelValue":e[0]||(e[0]=l=>o.value=l),options:I,optionLabel:"Libelle",optionValue:"Id",placeholder:"Élément",class:"w-full"},null,8,["modelValue"])]),n("div",null,[d(C,{size:"small",modelValue:r.value,"onUpdate:modelValue":e[1]||(e[1]=l=>r.value=l),options:L,optionLabel:"Libelle",optionValue:"Id",placeholder:"Type",class:"w-full",onChange:R},null,8,["modelValue"])]),n("div",null,[e[6]||(e[6]=n("label",{for:"keyAremplacer"},"à Remplacer...",-1)),(c(),f(k,{key:V.value,table:o.value,modelValue:p.value,"onUpdate:modelValue":e[2]||(e[2]=l=>p.value=l),class:"w-full"},null,8,["table","modelValue"]))]),v.value?(c(),P("div",N,[e[7]||(e[7]=n("label",{for:"keyRemplacant"},"Remplaçant...",-1)),(c(),f(k,{key:y.value,placeholder:"Remplaçant...",table:o.value,modelValue:m.value,"onUpdate:modelValue":e[3]||(e[3]=l=>m.value=l),class:"w-full"},null,8,["table","modelValue"]))])):S("",!0)])]),_:1},8,["visible"])}}};export{Y as default};
