import{y as j,b as D,f as F}from"./primevue-CfIk0_DY.js";import{u as U,b as g,s,S as w}from"./index-BxIwIJfy.js";import{o as B,b as T,c as z,v as l,l as p,d as t,t as y,F as L,E as N,a as m,y as I}from"./vue-core-Di3IuVqe.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";const M={class:"flex items-end gap-4"},H={class:"flex flex-col gap-1"},O={style:{width:"150px"}},P={class:"flex items-center text-gray-600"},W={class:"flex items-center gap-3"},q={class:"flex flex-col gap-3"},Z={__name:"supprimerExercice",setup(G){const{showError:v,showWarn:x,showSuccess:_}=U(),r=m(!1),A=()=>{r.value=!1,w("supprimerExercice")},o=m(null),d=m([]),c=m(!1),f=m(!1),h=I(()=>{switch(s.state.moduleActif){case 1:return"Commercial";case 2:return"Comptabilité";case 3:return"Paie";default:return"Non défini"}}),n=N({lecture:!1,ajout:!1,modif:!1,supp:!1,devalidation:!1,validation:!1}),$=async()=>{try{const e=(await g.post(`${s.lienApi}/verifierDroit/${s.state.dbCommun6}`,{id_utilisateur:s.userId,id_page:112,mail:s.state.userCloud.mail},{headers:{"Content-Type":"application/json"}})).data;e&&Object.keys(e).length>0&&(n.lecture=e.lecture,n.ajout=e.ajout,n.modif=e.modif,n.supp=e.supp,n.devalidation=e.devalidation,n.validation=e.validation),n.lecture||(x("Vous n'avez pas le droit, veuillez consulter l'administrateur"),w("supprimerExercice"))}catch(a){v("Une erreur est survenue : "+(a.response?.data?.message||a.message))}finally{s.state.afficher_in_progress=!1}},C=async()=>{try{const a=await g.post(`${s.lienApi}/exercices/${s.db}`,{},{headers:{"Content-Type":"application/json"}});d.value=a.data||[]}catch{v("Erreur lors du chargement des années")}},k=()=>{if(!o.value){x("Veuillez sélectionner une année");return}c.value=!0},E=()=>{c.value=!1,f.value=!0},S=async()=>{f.value=!1;try{s.state.afficher_in_progress=!0;const a=await g.post(`${s.lienApi}/supprimerExercice/${s.db}`,{annee:o.value,moduleActif:s.state.moduleActif},{headers:{"Content-Type":"application/json"}});a.data.success?(_(a.data.message),await C(),s.state.Annees=d.value,d.value.length>0&&(s.state.annee_fiscale=d.value[0].Annee),r.value=!1):x(a.data.message)}catch(a){v("Erreur : "+(a.response?.data?.message||a.message))}finally{s.state.afficher_in_progress=!1}};return B(async()=>{await $(),n.lecture&&(r.value=!0),await C()}),(a,e)=>{const V=j,u=D,b=F;return T(),z(L,null,[l(b,{visible:r.value,"onUpdate:visible":e[2]||(e[2]=i=>r.value=i),modal:"",draggable:!1,header:"Supprimer un exercice",style:{width:"480px"},breakpoints:{"640px":"95vw"},onHide:A},{footer:p(()=>[l(u,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[1]||(e[1]=i=>r.value=!1)}),l(u,{icon:"pi pi-trash",label:"Supprimer",severity:"danger",onClick:k,disabled:!n.supp||!o.value},null,8,["disabled"])]),default:p(()=>[t("div",M,[t("div",H,[e[7]||(e[7]=t("label",{for:"annee"},"Année à supprimer",-1)),t("div",O,[l(V,{id:"annee",modelValue:o.value,"onUpdate:modelValue":e[0]||(e[0]=i=>o.value=i),options:d.value,optionLabel:"Annee",optionValue:"Annee",placeholder:"Sélectionner",fluid:""},null,8,["modelValue","options"])])]),t("div",P,[e[8]||(e[8]=t("span",{class:"font-semibold mr-2"},"Module :",-1)),t("span",null,y(h.value),1)])])]),_:1},8,["visible"]),l(b,{visible:c.value,"onUpdate:visible":e[4]||(e[4]=i=>c.value=i),header:"Confirmation de suppression",modal:!0,closable:!0,style:{width:"400px"}},{footer:p(()=>[l(u,{label:"Annuler",icon:"pi pi-times",onClick:e[3]||(e[3]=i=>c.value=!1),text:""}),l(u,{label:"Continuer",icon:"pi pi-arrow-right",severity:"danger",onClick:E})]),default:p(()=>[t("div",W,[e[9]||(e[9]=t("i",{class:"pi pi-exclamation-triangle text-4xl text-orange-500"},null,-1)),t("span",null,"Êtes-vous sûr de vouloir supprimer l'exercice "+y(o.value)+" ?",1)])]),_:1},8,["visible"]),l(b,{visible:f.value,"onUpdate:visible":e[6]||(e[6]=i=>f.value=i),header:"⚠️ Confirmation finale",modal:!0,closable:!0,style:{width:"450px"}},{footer:p(()=>[l(u,{label:"Annuler",icon:"pi pi-times",onClick:e[5]||(e[5]=i=>f.value=!1),text:""}),l(u,{label:"Supprimer définitivement",icon:"pi pi-trash",severity:"danger",onClick:S})]),default:p(()=>[t("div",q,[e[10]||(e[10]=t("div",{class:"flex items-center gap-3"},[t("i",{class:"pi pi-exclamation-circle text-4xl text-red-500"}),t("span",{class:"font-bold"},"Cette action est irréversible !")],-1)),t("p",null,"L'exercice "+y(o.value)+" sera définitivement supprimé.",1)])]),_:1},8,["visible"])],64)}}};export{Z as default};
