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