import{a as te}from"./chunk-YEESETR2.js";import{c as $,d as J,e as Q,f as K,g as X,h as Y,p as Z,t as ee}from"./chunk-UDFQV3WY.js";import{e as q}from"./chunk-ZEULGWAI.js";import"./chunk-MBEC6LK4.js";import{Ba as P,Eb as s,Fa as a,Fb as C,Gb as w,Jb as M,Kb as k,Lb as E,Oa as T,Ob as I,R as m,Rb as H,S as u,T as _,Ta as D,U as S,Ya as y,ca as v,db as x,fb as h,hb as F,ib as j,jb as g,kb as i,lb as n,mb as f,nb as B,ob as L,pc as z,qb as b,qc as G,rb as p,rc as O,sb as c,sc as W,xc as U,zb as R}from"./chunk-TVKQFRWX.js";import{a as V,b as A}from"./chunk-DAQOROHW.js";var ne=()=>({"background-color":"#00843B","border-color":"#00843B"}),re=()=>({}),oe=(l,t,e)=>({"bg-green-50 border-green-500 text-green-700":l,"bg-red-50 border-red-500 text-red-700":t,"bg-blue-50 border-blue-500 text-blue-700":e}),le=(l,t)=>t.id;function ae(l,t){l&1&&(i(0,"div",10),f(1,"div",15),n())}function se(l,t){l&1&&(i(0,"div",10),_(),i(1,"svg",16),f(2,"path",17),n(),S(),i(3,"p",5),s(4,"Aucun service pour le moment"),n()())}function ce(l,t){if(l&1){let e=b();i(0,"tr")(1,"td")(2,"div",24)(3,"p",25),s(4),n(),i(5,"p",26),s(6),n()()(),i(7,"td")(8,"a",27),s(9),n()(),i(10,"td",28)(11,"div",29)(12,"button",30),p("click",function(){let r=m(e).$implicit,d=c(2);return u(d.viewArticle(r))}),_(),i(13,"svg",31),f(14,"path",32)(15,"path",33),n()(),S(),i(16,"button",34),p("click",function(){let r=m(e).$implicit,d=c(2);return u(d.editArticle(r))}),_(),i(17,"svg",35),f(18,"path",36),n()(),S(),i(19,"button",37),p("click",function(){let r=m(e).$implicit,d=c(2);return u(d.deleteArticle(r))}),_(),i(20,"svg",38),f(21,"path",39),n()()()()()}if(l&2){let e=t.$implicit;a(4),C(e.name),a(2),C(e.description),a(2),g("href",e.url,P),a(),w(" ",e.url," ")}}function de(l,t){if(l&1){let e=b();B(0),i(1,"button",40),p("click",function(){let r=m(e).$implicit,d=c(2);return u(d.goToPage(r))}),s(2),n(),L()}if(l&2){let e=t.$implicit,o=c(2);a(),g("ngClass",o.currentPage()===e?"px-3 py-1 border rounded text-white":"px-3 py-1 border border-gray-300 rounded hover:bg-gray-100 transition-colors")("ngStyle",o.currentPage()===e?I(3,ne):I(4,re)),a(),w(" ",e," ")}}function me(l,t){if(l&1){let e=b();i(0,"div",11)(1,"table",18)(2,"thead")(3,"tr")(4,"th",19),s(5,"Nom"),n(),i(6,"th",19),s(7,"Url"),n(),i(8,"th",20),s(9,"Actions"),n()()(),i(10,"tbody"),F(11,ce,22,4,"tr",null,le),n()(),i(13,"div",21)(14,"button",22),p("click",function(){m(e);let r=c();return u(r.prevPage())}),s(15," \xAB Pr\xE9c\xE9dent "),n(),y(16,de,3,5,"ng-container",23),i(17,"button",22),p("click",function(){m(e);let r=c();return u(r.nextPage())}),s(18," Suivant \xBB "),n()()()}if(l&2){let e=c();a(11),j(e.articles()),a(3),g("disabled",e.currentPage()===1),a(2),g("ngForOf",e.pages()),a(),g("disabled",e.currentPage()===e.totalPages())}}function ue(l,t){l&1&&(i(0,"p",56),s(1," Le nom est obligatoire "),n())}function pe(l,t){l&1&&f(0,"div",55)}function ge(l,t){if(l&1){let e=b();i(0,"div",12)(1,"div",41)(2,"div",42)(3,"h2",43),s(4),n()(),i(5,"form",44,0),p("ngSubmit",function(){m(e);let r=c();return u(r.saveArticle())}),i(7,"div")(8,"label",45),s(9,"Titre "),i(10,"span",46),s(11,"*"),n()(),i(12,"input",47,1),E("ngModelChange",function(r){m(e);let d=c();return k(d.form.name,r)||(d.form.name=r),u(r)}),n(),y(14,ue,2,0,"p",48),n(),i(15,"div")(16,"label",45),s(17,"Description"),n(),i(18,"textarea",49),E("ngModelChange",function(r){m(e);let d=c();return k(d.form.description,r)||(d.form.description=r),u(r)}),n()(),i(19,"div")(20,"label",45),s(21,"Url"),n(),i(22,"input",50,1),E("ngModelChange",function(r){m(e);let d=c();return k(d.form.url,r)||(d.form.url=r),u(r)}),n()(),i(24,"div")(25,"label",45),s(26,"Image mise en avant "),i(27,"span",46),s(28,"*"),n()(),i(29,"input",51),p("change",function(r){m(e);let d=c();return u(d.onFileSelected(r))}),n()(),i(30,"div",52)(31,"button",53),p("click",function(){m(e);let r=c();return u(r.closeModal())}),s(32,"Annuler"),n(),i(33,"button",54),x(34,pe,1,0,"div",55),s(35),n()()()()()}if(l&2){let e=R(13),o=c();a(4),w(" ",o.editingArticle()?"Modifier l'article":"Nouvel article"," "),a(8),M("ngModel",o.form.name),a(2),g("ngIf",e.invalid&&e.touched),a(4),M("ngModel",o.form.description),a(4),M("ngModel",o.form.url),a(11),g("disabled",o.saving()),a(),h(o.saving()?34:-1),a(),w(" ",o.editingArticle()?"Mettre \xE0 jour":"Cr\xE9er"," ")}}function fe(l,t){l&1&&(_(),i(0,"svg",60),f(1,"path",61),n())}function ve(l,t){l&1&&(_(),i(0,"svg",60),f(1,"path",62),n())}function _e(l,t){l&1&&(_(),i(0,"svg",60),f(1,"path",63),n())}function xe(l,t){if(l&1&&(i(0,"div",13)(1,"div",57),y(2,fe,2,0,"svg",58)(3,ve,2,0,"svg",58)(4,_e,2,0,"svg",58),i(5,"span",59),s(6),n()()()),l&2){let e=c();a(),g("ngClass",H(5,oe,e.notification().type==="success",e.notification().type==="error",e.notification().type==="info")),a(),g("ngIf",e.notification().type==="success"),a(),g("ngIf",e.notification().type==="error"),a(),g("ngIf",e.notification().type==="info"),a(2),C(e.notification().message)}}function he(l,t){if(l&1){let e=b();i(0,"div",14)(1,"div",64)(2,"h3",65),s(3,"Confirmation"),n(),i(4,"p",66),s(5),n(),i(6,"div",67)(7,"button",68),p("click",function(){m(e);let r=c();return u(r.closeConfirmModal())}),s(8," Annuler "),n(),i(9,"button",69),p("click",function(){m(e);let r=c();return u(r.confirmModal().onConfirm())}),s(10," Supprimer "),n()()()()}if(l&2){let e=c();a(5),C(e.confirmModal().message)}}var ie=class l{constructor(t,e){this.apiService=t;this.router=e}notification=v({show:!1,message:"",type:"success"});articles=v([]);loading=v(!0);showModal=v(!1);editingArticle=v(null);saving=v(!1);selectedImage=null;fileError=!1;currentPage=v(1);pageSize=7;totalPages=v(1);form={name:"",description:"",url:""};ngOnInit(){this.loadArticles()}loadArticles(t=0){this.loading.set(!0),this.apiService.getAllService(t,this.pageSize).subscribe({next:e=>{e.success&&(console.log(e),this.articles.set(e.data.content),this.totalPages.set(e.data.totalPages),this.currentPage.set(t+1)),this.loading.set(!1)},error:()=>{this.loading.set(!1)}})}nextPage(){this.currentPage()1&&this.loadArticles(this.currentPage()-2)}goToPage(t){this.loadArticles(t-1)}pages(){return Array.from({length:this.totalPages()},(t,e)=>e+1)}openModal(){this.form={name:"",description:"",url:""},this.selectedImage=null,this.fileError=!1,this.editingArticle.set(null),this.showModal.set(!0)}closeModal(t){this.showModal.set(!1),this.editingArticle.set(null),this.selectedImage=null,this.fileError=!1,t?.resetForm()}onFileSelected(t){let e=t.target;if(!e.files||e.files.length===0){this.selectedImage=null;return}let o=e.files[0];if(!o.type.startsWith("image/")){e.value="",this.selectedImage=null;return}this.selectedImage=o,this.fileError=!1}viewArticle(t){}editArticle(t){this.form={name:t.name,description:t.description||"",url:t.url},this.editingArticle.set(t),this.showModal.set(!0)}saveArticle(t){if(!this.form.name||!this.form.description)return;this.saving.set(!0);let e=this.editingArticle(),o={name:this.form.name,description:this.form.description,url:this.form.url},r=new FormData;r.append("service",new Blob([JSON.stringify(o)],{type:"application/json"})),r.append("authorId","1"),this.selectedImage&&r.append("logo",this.selectedImage),(e?this.apiService.updateServices(e.id,r):this.apiService.createServices(r)).subscribe({next:N=>{this.loadArticles(),this.closeModal(t),this.saving.set(!1),this.showNotification(e?"Service mis \xE0 jour avec succ\xE8s":"Service cr\xE9\xE9 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")}})}deleteArticle1(t){confirm(`Supprimer l'article "${t.name}" ?`)&&this.apiService.deleteServices(t.id).subscribe({next:()=>this.loadArticles()})}getCategoryLabel(t){return{ACTUALITE:"Actualit\xE9",COMMUNIQUE:"Communiqu\xE9",EVENEMENT:"\xC9v\xE9nement",PROJET:"Projet",RAPPORT:"Rapport",DISCOURS:"Discours"}[t]||t}getStatusLabel(t){return{DRAFT:"Brouillon",PENDING:"En attente",PUBLISHED:"Publi\xE9",ARCHIVED:"Archiv\xE9"}[t]||t}getStatusBadgeClass(t){return{DRAFT:"badge bg-neutral-100 text-neutral-700 ring-1 ring-neutral-300",PENDING:"badge bg-yellow-50 text-yellow-700 ring-1 ring-yellow-200",PUBLISHED:"badge bg-green-50 text-green-700 ring-1 ring-green-200",ARCHIVED:"badge bg-red-50 text-red-700 ring-1 ring-red-200"}[t]||"badge bg-neutral-100 text-neutral-600"}formatDate(t){return t?new Date(t).toLocaleDateString("fr-FR"):""}trackByArticleId(t,e){return e.id}showNotification(t,e="success",o=2e3){this.notification.set({show:!0,message:t,type:e}),setTimeout(()=>this.notification.update(r=>A(V({},r),{show:!1})),o)}confirmModal=v({show:!1,message:"",onConfirm:()=>{}});openConfirmModal(t,e){this.confirmModal.set({show:!0,message:t,onConfirm:e})}closeConfirmModal(){this.confirmModal.update(t=>A(V({},t),{show:!1}))}deleteArticle(t){this.openConfirmModal(`Voulez-vous vraiment supprimer le service "${t.name}" ?`,()=>{this.apiService.deleteServices(t.id).subscribe({next:()=>{this.loadArticles(),this.closeConfirmModal(),this.showNotification("Service supprim\xE9 avec succ\xE8s","success")},error:()=>{this.showNotification("Erreur lors de la suppression","error"),this.closeConfirmModal()}})})}static \u0275fac=function(e){return new(e||l)(T(te),T(q))};static \u0275cmp=D({type:l,selectors:[["app-services"]],decls:18,vars:4,consts:[["articleForm","ngForm"],["title","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,"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,"card","p-0"],[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,"table"],[1,"py-3","text-left"],[1,"px-6","py-3","text-right","whitespace-nowrap"],[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,"max-w-xs"],[1,"font-medium","text-neutral-900","truncate"],[1,"text-xs","text-neutral-400","truncate"],["target","_blank",1,"text-[#006B30]","underline","hover:text-green-800",3,"href"],[1,"px-6","py-4","text-right","whitespace-nowrap"],[1,"flex","justify-end","gap-2"],["title","Voir l'article",1,"flex","items-center","justify-center","p-2","border-2","border-blue-500","rounded-full","bg-white","hover:bg-blue-50","transition-colors",3,"click"],["fill","none","stroke","currentColor","viewBox","0 0 24 24",1,"w-4","h-4","text-blue-500"],["stroke-linecap","round","stroke-linejoin","round","stroke-width","2","d","M15 12a3 3 0 11-6 0 3 3 0 016 0z"],["stroke-linecap","round","stroke-linejoin","round","stroke-width","2","d","M2.458 12C3.732 7.943 7.523 5 12 5c4.477 0 8.268 2.943 9.542 7-1.274 4.057-5.065 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"],["title","Modifier",1,"flex","items-center","justify-center","p-2","border-2","border-green-500","rounded-full","bg-white","hover:bg-green-50","transition-colors",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,"flex","items-center","justify-center","p-2","border-2","border-red-500","rounded-full","bg-white","hover:bg-red-50","transition-colors",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"],["novalidate","",1,"p-6","space-y-5",3,"ngSubmit"],[1,"label"],[1,"text-red-500"],["type","text","name","name","required","",1,"input",3,"ngModelChange","ngModel"],["class","text-sm text-red-500 mt-1",4,"ngIf"],["name","description","rows","2",1,"input","resize-none",3,"ngModelChange","ngModel"],["type","text","name","url","required","",1,"input",3,"ngModelChange","ngModel"],["type","file","accept","image/*",1,"input",3,"change"],[1,"flex","justify-end","gap-3","pt-4","border-t","border-neutral-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","mr-2"],[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,o){e&1&&(i(0,"div",2)(1,"div",3)(2,"div")(3,"h1",4),s(4,"Services Publics"),n(),i(5,"p",5),s(6,"G\xE9rez les services publics en ligne"),n()(),i(7,"button",6),p("click",function(){return o.openModal()}),_(),i(8,"svg",7),f(9,"path",8),n(),s(10," Nouvel Service "),n()(),S(),i(11,"div",9),x(12,ae,2,0,"div",10)(13,se,5,0,"div",10)(14,me,19,3,"div",11),n(),x(15,ge,36,8,"div",12),n(),x(16,xe,7,9,"div",13),x(17,he,11,1,"div",14)),e&2&&(a(12),h(o.loading()?12:o.articles().length===0?13:14),a(3),h(o.showModal()?15:-1),a(),h(o.notification().show?16:-1),a(),h(o.confirmModal().show?17:-1))},dependencies:[U,z,G,O,W,ee,Y,$,J,Q,Z,X,K],encapsulation:2})};export{ie as ServicesComponent};