import{a as ee}from"./chunk-CQKJN64S.js";import{c as W,d as $,e as J,f as K,g as Q,h as X,p as Y,t as Z}from"./chunk-UDFQV3WY.js";import{a as F}from"./chunk-MBEC6LK4.js";import{Eb as l,Fa as s,Fb as w,Gb as E,Hc as U,Jb as V,Kb as T,Lb as N,Oa as j,Ob as y,R as u,Rb as B,S as g,T as _,Ta as I,U as S,Ya as C,ca as f,db as h,fb as v,hb as q,ib as L,jb as p,kb as i,lb as o,mb as x,nb as D,ob as z,pc as H,qb as b,qc as R,rb as c,rc as A,sb as d,sc as G,xc as O,zb as P}from"./chunk-TVKQFRWX.js";import{a as M,b as k}from"./chunk-DAQOROHW.js";var ie=()=>[],ne=()=>({"background-color":"#00843B","border-color":"#00843B"}),oe=()=>({}),re=(a,t,e)=>({"bg-green-50 border-green-500 text-green-700":a,"bg-red-50 border-red-500 text-red-700":t,"bg-blue-50 border-blue-500 text-blue-700":e}),ae=(a,t)=>t.id;function le(a,t){a&1&&(i(0,"div",20),x(1,"div",25),o())}function se(a,t){a&1&&(i(0,"div",20),_(),i(1,"svg",26),x(2,"path",27),o(),S(),i(3,"p",5),l(4,"Aucune statistique pour le moment"),o()())}function de(a,t){if(a&1){let e=b();i(0,"tr",33)(1,"td",37)(2,"p",38),l(3),o()(),i(4,"td"),l(5),o(),i(6,"td",39)(7,"div",40)(8,"button",41),c("click",function(){let r=u(e).$implicit,m=d(2);return g(m.editProject(r))}),_(),i(9,"svg",42),x(10,"path",43),o()(),S(),i(11,"button",44),c("click",function(){let r=u(e).$implicit,m=d(2);return g(m.deleteProject(r))}),_(),i(12,"svg",45),x(13,"path",46),o()()()()()}if(a&2){let e=t.$implicit;s(3),w(e.nom),s(2),w(e.valeur)}}function ce(a,t){if(a&1){let e=b();D(0),i(1,"button",47),c("click",function(){let r=u(e).index,m=d(2);return g(m.currentPage.set(r+1))}),l(2),o(),z()}if(a&2){let e=t.index,n=d(2);s(),p("ngClass",n.currentPage()===e+1?"px-3 py-1 border rounded text-white":"px-3 py-1 border border-gray-300 rounded hover:bg-gray-100 transition-colors")("ngStyle",n.currentPage()===e+1?y(3,ne):y(4,oe)),s(),E(" ",e+1," ")}}function me(a,t){if(a&1){let e=b();i(0,"div",21)(1,"table",28)(2,"thead")(3,"tr",29)(4,"th",30),l(5,"Nom"),o(),i(6,"th",30),l(7,"Valeur"),o(),i(8,"th",31),l(9,"Actions"),o()()(),i(10,"tbody",32),q(11,de,14,2,"tr",33,ae),o()(),i(13,"div",34)(14,"button",35),c("click",function(){u(e);let r=d();return g(r.prevPage())}),l(15," \xAB Pr\xE9c\xE9dent "),o(),C(16,ce,3,5,"ng-container",36),i(17,"button",35),c("click",function(){u(e);let r=d();return g(r.nextPage())}),l(18," Suivant \xBB "),o()()()}if(a&2){let e=d();s(11),L(e.paginatedProjects()),s(3),p("disabled",e.currentPage()===1),s(2),p("ngForOf",y(3,ie).constructor(e.totalPages())),s(),p("disabled",e.currentPage()===e.totalPages())}}function pe(a,t){a&1&&(i(0,"p",61),l(1," Le nom est obligatoire. "),o())}function ue(a,t){a&1&&(i(0,"p",61),l(1," Le nom est obligatoire. "),o())}function ge(a,t){a&1&&x(0,"div",60)}function fe(a,t){if(a&1){let e=b();i(0,"div",22)(1,"div",48)(2,"div",49)(3,"h2",50),l(4),o()(),i(5,"form",51,0),c("ngSubmit",function(){u(e);let r=d();return g(r.saveProject())}),i(7,"div")(8,"label",52),l(9,"Nom "),i(10,"span",53),l(11,"*"),o()(),i(12,"input",54,1),N("ngModelChange",function(r){u(e);let m=d();return T(m.form.nom,r)||(m.form.nom=r),g(r)}),o(),C(14,pe,2,0,"p",55),o(),i(15,"div")(16,"label",52),l(17,"Valeur "),i(18,"span",53),l(19,"*"),o()(),i(20,"input",56,1),N("ngModelChange",function(r){u(e);let m=d();return T(m.form.valeur,r)||(m.form.valeur=r),g(r)}),o(),C(22,ue,2,0,"p",55),o(),i(23,"div",57)(24,"button",58),c("click",function(){u(e);let r=d();return g(r.closeModal())}),l(25," Annuler "),o(),i(26,"button",59),h(27,ge,1,0,"div",60),l(28),o()()()()()}if(a&2){let e=P(6),n=P(13),r=d();s(4),E(" ",r.editingProject()?"Modifier la statistique":"Nouvelle statistique"," "),s(8),V("ngModel",r.form.nom),s(2),p("ngIf",n.invalid&&e.submitted),s(6),V("ngModel",r.form.valeur),s(2),p("ngIf",n.invalid&&e.submitted),s(4),p("disabled",r.saving()),s(),v(r.saving()?27:-1),s(),E(" ",r.editingProject()?"Mettre \xE0 jour":"Enr\xE9gistrer"," ")}}function xe(a,t){a&1&&(_(),i(0,"svg",65),x(1,"path",66),o())}function _e(a,t){a&1&&(_(),i(0,"svg",65),x(1,"path",67),o())}function he(a,t){a&1&&(_(),i(0,"svg",65),x(1,"path",68),o())}function ve(a,t){if(a&1&&(i(0,"div",23)(1,"div",62),C(2,xe,2,0,"svg",63)(3,_e,2,0,"svg",63)(4,he,2,0,"svg",63),i(5,"span",64),l(6),o()()()),a&2){let e=d();s(),p("ngClass",B(5,re,e.notification().type==="success",e.notification().type==="error",e.notification().type==="info")),s(),p("ngIf",e.notification().type==="success"),s(),p("ngIf",e.notification().type==="error"),s(),p("ngIf",e.notification().type==="info"),s(2),w(e.notification().message)}}function be(a,t){if(a&1){let e=b();i(0,"div",24)(1,"div",69)(2,"h3",70),l(3,"Confirmation"),o(),i(4,"p",71),l(5),o(),i(6,"div",72)(7,"button",73),c("click",function(){u(e);let r=d();return g(r.closeConfirmModal())}),l(8," Annuler "),o(),i(9,"button",74),c("click",function(){u(e);let r=d();return g(r.confirmModal().onConfirm())}),l(10," Supprimer "),o()()()()}if(a&2){let e=d();s(5),w(e.confirmModal().message)}}var te=class a{constructor(t,e){this.apiService=t;this.http=e}notification=f({show:!1,message:"",type:"success"});projects=f([]);loading=f(!0);showModal=f(!1);editingProject=f(null);saving=f(!1);importing=f(!1);selectedExcelFile=f(null);currentPage=f(1);pageSize=7;totalPages=f(1);form={nom:"",valeur:""};ngOnInit(){this.loadProjects()}loadProjects(){this.loading.set(!0),this.apiService.getAllEtats().subscribe({next:t=>{console.log("RESPONSE =",t),this.projects.set(t.data.content),console.log("PROJECTS =",this.projects()),this.totalPages.set(Math.ceil(t.data.content.length/this.pageSize)),this.currentPage.set(1),this.loading.set(!1)},error:t=>{console.error("Erreur API",t),this.loading.set(!1)}})}selectExcelFile(t){let e=t.target;this.selectedExcelFile.set(e.files?.[0]??null)}importExcel(){let t=this.selectedExcelFile();if(!t){this.showNotification("Veuillez s\xE9lectionner un fichier Excel.","error",3500);return}let e=new FormData;e.append("file",t),this.importing.set(!0),this.http.post(`${F.apiUrl}/statistiques/import`,e).subscribe({next:n=>{this.importing.set(!1),this.selectedExcelFile.set(null),this.loadProjects(),this.showNotification(`${n.processedRows} ligne(s) trait\xE9e(s) : ${n.updatedStatistics} mise(s) \xE0 jour et ${n.createdStatistics} ajout(s).`,"success",5500)},error:n=>{this.importing.set(!1);let r=n?.error?.message||n?.error?.error||"L\u2019import Excel a \xE9chou\xE9. V\xE9rifiez les colonnes Nom et Valeur.";this.showNotification(r,"error",5500)}})}downloadExcelTemplate(){this.http.get(`${F.apiUrl}/statistiques/import-template`,{responseType:"blob"}).subscribe({next:t=>{let e=URL.createObjectURL(t),n=document.createElement("a");n.href=e,n.download="modele-statistiques-rsu.xlsx",n.click(),URL.revokeObjectURL(e)},error:()=>this.showNotification("Impossible de t\xE9l\xE9charger le mod\xE8le Excel.","error",4e3)})}paginatedProjects(){let t=this.projects(),e=(this.currentPage()-1)*this.pageSize;return t.slice(e,e+this.pageSize)}nextPage(){this.currentPage()t+1)}prevPage(){this.currentPage()>1&&this.currentPage.update(t=>t-1)}openModal(){this.form={nom:"",valeur:""},this.editingProject.set(null),this.showModal.set(!0)}closeModal(){this.showModal.set(!1),this.editingProject.set(null)}editProject(t){this.form={nom:t.nom,valeur:t.valeur},this.editingProject.set(t),this.showModal.set(!0)}saveProject(){if(!this.form.nom)return;this.saving.set(!0);let t=this.editingProject();(t?this.apiService.updateEtats(t.id,this.form):this.apiService.createEtat(this.form)).subscribe({next:n=>{console.log("API response =",n),this.loadProjects(),this.closeModal(),this.saving.set(!1),this.showNotification(t?"Statistique mise \xE0 jour avec succ\xE8s":"Statistique cr\xE9\xE9e avec succ\xE8s","success")},error:n=>{console.error("Erreur lors de la sauvegarde",n),this.saving.set(!1),this.showNotification("Erreur lors de la sauvegarde","error")}})}showNotification(t,e="success",n=2e3){this.notification.set({show:!0,message:t,type:e}),setTimeout(()=>this.notification.update(r=>k(M({},r),{show:!1})),n)}confirmModal=f({show:!1,message:"",onConfirm:()=>{}});openConfirmModal(t,e){this.confirmModal.set({show:!0,message:t,onConfirm:e})}closeConfirmModal(){this.confirmModal.update(t=>k(M({},t),{show:!1}))}deleteProject(t){console.log("fvfv"),this.openConfirmModal(`Voulez-vous vraiment supprimer la statistique "${t.nom}" ?`,()=>{this.apiService.deleteEtats(t.id).subscribe({next:()=>{this.loadProjects(),this.closeConfirmModal(),this.showNotification("Statistique supprim\xE9e avec succ\xE8s","success")},error:()=>{this.showNotification("Erreur lors de la suppression","error"),this.closeConfirmModal()}})})}static \u0275fac=function(e){return new(e||a)(j(ee),j(U))};static \u0275cmp=I({type:a,selectors:[["app-etats"]],decls:40,vars:7,consts:[["projectForm","ngForm"],["nameField","ngModel"],[1,"space-y-6"],[1,"flex","flex-col","sm:flex-row","sm:items-center","sm:justify-between","gap-4"],[1,"text-2xl","font-bold","text-neutral-900"],[1,"text-neutral-500"],[1,"flex","flex-wrap","gap-3"],["type","button",1,"rounded-lg","border","border-primary-700","px-4","py-2.5","font-semibold","text-primary-700","transition","hover:bg-primary-50",3,"click"],[1,"btn-primary",2,"background-color","#00843B",3,"click"],["fill","none","stroke","currentColor","viewBox","0 0 24 24",1,"w-5","h-5","mr-2"],["stroke-linecap","round","stroke-linejoin","round","stroke-width","2","d","M12 6v6m0 0v6m0-6h6m-6 0H6"],[1,"rounded-2xl","border","border-blue-200","bg-blue-50","p-5"],[1,"flex","flex-col","gap-4","lg:flex-row","lg:items-center","lg:justify-between"],[1,"font-bold","text-slate-900"],[1,"mt-1","text-sm","text-slate-600"],[1,"flex","flex-col","gap-3","sm:flex-row","sm:items-center"],[1,"cursor-pointer","rounded-lg","border","border-slate-300","bg-white","px-4","py-2.5","text-sm","font-semibold","text-slate-700","transition","hover:border-primary-500"],["type","file","accept",".xlsx,.xls",1,"hidden",3,"change"],["type","button",1,"rounded-lg","bg-primary-700","px-5","py-2.5","text-sm","font-bold","text-white","transition","hover:bg-primary-800","disabled:cursor-not-allowed","disabled:opacity-50",3,"click","disabled"],[1,"card","p-0","shadow-lg","rounded-lg","overflow-hidden"],[1,"p-8","text-center"],[1,"table-container"],[1,"fixed","inset-0","bg-black/50","flex","items-center","justify-center","z-50","p-4"],[1,"fixed","top-4","right-4","z-50","pointer-events-none"],[1,"fixed","inset-0","bg-black/30","flex","items-center","justify-center","z-50","p-4"],[1,"spinner","w-8","h-8","mx-auto"],["fill","none","stroke","currentColor","viewBox","0 0 24 24",1,"w-12","h-12","text-neutral-300","mx-auto","mb-4"],["stroke-linecap","round","stroke-linejoin","round","stroke-width","2","d","M19 20H5a2 2 0 01-2-2V6a2 2 0 012-2h10a2 2 0 012 2v1m2 13a2 2 0 01-2-2V7m2 13a2 2 0 002-2V9a2 2 0 00-2-2h-2m-4-3H9M7 16h6M7 8h6v4H7V8z"],[1,"w-full","table-auto"],[1,"bg-gray-50"],[1,"px-6","py-3","text-left"],[1,"px-6","py-3","text-right","whitespace-nowrap"],[1,"bg-white","divide-y","divide-gray-200"],[1,"hover:bg-gray-50","transition"],[1,"flex","justify-end","items-center","mt-2","px-6","py-2","gap-2","border-t","border-gray-200","bg-gray-50","rounded-b-lg"],[1,"px-3","py-1","border","border-gray-300","rounded","hover:bg-gray-100","disabled:opacity-50","transition-colors",3,"click","disabled"],[4,"ngFor","ngForOf"],[1,"px-6","py-4"],[1,"font-semibold","text-gray-900","truncate"],[1,"px-6","py-4","text-right","whitespace-nowrap"],[1,"flex","justify-end","gap-2"],["title","Modifier",1,"p-2","border-2","border-green-500","rounded-full","bg-white","hover:bg-green-50","transition",3,"click"],["fill","none","stroke","currentColor","viewBox","0 0 24 24",1,"w-4","h-4","text-green-500"],["stroke-linecap","round","stroke-linejoin","round","stroke-width","2","d","M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"],["title","Supprimer",1,"p-2","border-2","border-red-500","rounded-full","bg-white","hover:bg-red-50","transition",3,"click"],["fill","none","stroke","currentColor","viewBox","0 0 24 24",1,"w-4","h-4","text-red-500"],["stroke-linecap","round","stroke-linejoin","round","stroke-width","2","d","M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"],[3,"click","ngClass","ngStyle"],[1,"bg-white","rounded-2xl","shadow-xl","w-full","max-w-2xl","max-h-[90vh]","overflow-y-auto"],[1,"p-6","border-b","border-neutral-200"],[1,"text-xl","font-semibold","text-neutral-900"],[1,"p-6","space-y-5",3,"ngSubmit"],[1,"label"],[1,"text-danger-500"],["type","text","name","nom","required","",1,"input",3,"ngModelChange","ngModel"],["class","text-sm text-red-500 mt-1",4,"ngIf"],["type","text","name","valeur","required","",1,"input",3,"ngModelChange","ngModel"],[1,"flex","justify-end","gap-3","pt-4","border-t","border-gray-200"],["type","button",1,"px-4","py-2","rounded-lg","border","border-red-500","text-red-500","hover:bg-red-50","transition-colors","font-medium",3,"click"],["type","submit",1,"px-4","py-2","rounded-lg","bg-[#00843B]","text-white","hover:bg-[#006830]","transition-colors","font-medium","flex","items-center","justify-center","gap-2",3,"disabled"],[1,"spinner","w-4","h-4","border-2","border-t-white","border-gray-200","rounded-full","animate-spin"],[1,"text-sm","text-red-500","mt-1"],[1,"pointer-events-auto","border-l-4","rounded-lg","shadow-lg","p-6","max-w-sm","w-full","flex","items-center","gap-4","animate-fade-in",3,"ngClass"],["class","w-6 h-6 flex-shrink-0","fill","none","stroke","currentColor","viewBox","0 0 24 24",4,"ngIf"],[1,"text-sm","font-medium"],["fill","none","stroke","currentColor","viewBox","0 0 24 24",1,"w-6","h-6","flex-shrink-0"],["stroke-linecap","round","stroke-linejoin","round","stroke-width","2","d","M5 13l4 4L19 7"],["stroke-linecap","round","stroke-linejoin","round","stroke-width","2","d","M6 18L18 6M6 6l12 12"],["stroke-linecap","round","stroke-linejoin","round","stroke-width","2","d","M13 16h-1v-4h-1m1-4h.01M12 20a8 8 0 100-16 8 8 0 000 16z"],[1,"bg-white","rounded-2xl","shadow-xl","w-full","max-w-md","p-6","space-y-4"],[1,"text-lg","font-semibold","text-neutral-900"],[1,"text-neutral-700"],[1,"flex","justify-end","gap-3","mt-4"],[1,"px-4","py-2","rounded-lg","border","border-gray-300","text-gray-700","hover:bg-gray-100","transition-colors","font-medium",3,"click"],[1,"px-4","py-2","rounded-lg","bg-red-600","text-white","hover:bg-red-700","transition-colors","font-medium",3,"click"]],template:function(e,n){if(e&1&&(i(0,"div",2)(1,"div",3)(2,"div")(3,"h1",4),l(4,"Statistiques du RSU"),o(),i(5,"p",5),l(6,"Modifiez les chiffres qui d\xE9filent sur la page d'accueil"),o()(),i(7,"div",6)(8,"button",7),c("click",function(){return n.downloadExcelTemplate()}),l(9," T\xE9l\xE9charger le mod\xE8le Excel "),o(),i(10,"button",8),c("click",function(){return n.openModal()}),_(),i(11,"svg",9),x(12,"path",10),o(),l(13," Nouveau chiffre "),o()()(),S(),i(14,"div",11)(15,"div",12)(16,"div")(17,"h2",13),l(18,"Mise \xE0 jour par fichier Excel"),o(),i(19,"p",14),l(20,"Utilisez les colonnes "),i(21,"strong"),l(22,"Nom"),o(),l(23," et "),i(24,"strong"),l(25,"Valeur"),o(),l(26,". Les statistiques existantes sont mises \xE0 jour par leur nom et les nouvelles sont ajout\xE9es."),o()(),i(27,"div",15)(28,"label",16),l(29),i(30,"input",17),c("change",function(m){return n.selectExcelFile(m)}),o()(),i(31,"button",18),c("click",function(){return n.importExcel()}),l(32),o()()()(),i(33,"div",19),h(34,le,2,0,"div",20)(35,se,5,0,"div",20)(36,me,19,4,"div",21),h(37,fe,29,8,"div",22),o(),h(38,ve,7,9,"div",23),h(39,be,11,1,"div",24),o()),e&2){let r;s(29),E(" ",((r=n.selectedExcelFile())==null?null:r.name)||"Choisir un fichier"," "),s(2),p("disabled",!n.selectedExcelFile()||n.importing()),s(),E(" ",n.importing()?"Importation\u2026":"Importer et mettre \xE0 jour"," "),s(2),v(n.loading()?34:n.projects().length===0?35:36),s(3),v(n.showModal()?37:-1),s(),v(n.notification().show?38:-1),s(),v(n.confirmModal().show?39:-1)}},dependencies:[O,H,R,A,G,Z,X,W,$,J,Y,Q,K],encapsulation:2})};export{te as EtatsComponent};