import"./chunk-JGH6I3KN.js";import{a as re}from"./chunk-YEESETR2.js";import{c as K,d as Q,e as X,f as Y,g as Z,h as $,k as ee,l as te,n as ie,p as ne,t as oe}from"./chunk-UDFQV3WY.js";import{e as U,i as J}from"./chunk-ZEULGWAI.js";import"./chunk-MBEC6LK4.js";import{Db as H,Eb as r,Fa as s,Fb as h,Gb as E,Jb as v,Kb as b,Lb as C,Oa as T,Ob as N,R as m,Rb as W,S as u,T as _,Ta as D,U as A,Ya as M,ca as x,db as w,fb as S,hb as B,ib as F,jb as g,kb as t,lb as o,mb as f,nb as j,ob as L,pc as R,qb as y,qc as z,rb as p,rc as G,sb as c,sc as O,xc as q,zb as I}from"./chunk-TVKQFRWX.js";import{a as V,b as P}from"./chunk-DAQOROHW.js";var le=()=>({"background-color":"#00843B","border-color":"#00843B"}),se=()=>({}),de=(a,n,e)=>({"bg-green-50 border-green-500 text-green-700":a,"bg-red-50 border-red-500 text-red-700":n,"bg-blue-50 border-blue-500 text-blue-700":e}),ce=(a,n)=>n.id;function me(a,n){a&1&&(t(0,"div",11),f(1,"div",16),o())}function ue(a,n){a&1&&(t(0,"div",11),_(),t(1,"svg",17),f(2,"path",18),o(),A(),t(3,"p",6),r(4,"Aucun agenda pour le moment"),o()())}function ge(a,n){if(a&1){let e=y();t(0,"tr")(1,"td")(2,"div",24)(3,"p",25),r(4),o(),t(5,"p",26),r(6),o()()(),t(7,"td")(8,"span"),r(9),o()(),t(10,"td",25),r(11),o(),t(12,"td",27),r(13),o(),t(14,"td",28)(15,"div",29)(16,"button",30),_(),t(17,"svg",31),f(18,"path",32)(19,"path",33),o()(),A(),t(20,"button",34),p("click",function(){let i=m(e).$implicit,d=c(2);return u(d.editArticle(i))}),_(),t(21,"svg",35),f(22,"path",36),o()(),A(),t(23,"button",37),p("click",function(){let i=m(e).$implicit,d=c(2);return u(d.deleteArticle(i))}),_(),t(24,"svg",38),f(25,"path",39),o()()()()()}if(a&2){let e=n.$implicit,l=c(2);s(4),h(e.title),s(2),h(e.summary),s(2),H(l.getStatusBadgeClass(e.status)),s(),h(l.getStatusLabel(e.status)),s(2),h(e.lieux),s(2),h(l.formatDate(e.createdAt))}}function pe(a,n){if(a&1){let e=y();j(0),t(1,"button",40),p("click",function(){let i=m(e).$implicit,d=c(2);return u(d.goToPage(i))}),r(2),o(),L()}if(a&2){let e=n.$implicit,l=c(2);s(),g("ngClass",l.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",l.currentPage()===e?N(3,le):N(4,se)),s(),E(" ",e," ")}}function fe(a,n){if(a&1){let e=y();t(0,"div",12)(1,"table",19)(2,"thead")(3,"tr")(4,"th"),r(5,"Titre"),o(),t(6,"th"),r(7,"Statut"),o(),t(8,"th"),r(9,"Lieu"),o(),t(10,"th"),r(11,"Date"),o(),t(12,"th",20),r(13,"Actions"),o()()(),t(14,"tbody"),B(15,ge,26,7,"tr",null,ce),o()(),t(17,"div",21)(18,"button",22),p("click",function(){m(e);let i=c();return u(i.prevPage())}),r(19," \xAB Pr\xE9c\xE9dent "),o(),M(20,pe,3,5,"ng-container",23),t(21,"button",22),p("click",function(){m(e);let i=c();return u(i.nextPage())}),r(22," Suivant \xBB "),o()()()}if(a&2){let e=c();s(15),F(e.articles()),s(3),g("disabled",e.currentPage()===1),s(2),g("ngForOf",e.pages()),s(),g("disabled",e.currentPage()===e.totalPages())}}function xe(a,n){a&1&&(t(0,"p",63),r(1," Le titre est obligatoire "),o())}function _e(a,n){a&1&&(t(0,"p",63),r(1," Le contenu est obligatoire "),o())}function he(a,n){a&1&&f(0,"div",62)}function ve(a,n){if(a&1){let e=y();t(0,"div",13)(1,"div",41)(2,"div",42)(3,"h2",43),r(4),o()(),t(5,"form",44,0),p("ngSubmit",function(){m(e);let i=c();return u(i.saveArticle())}),t(7,"div")(8,"label",45),r(9,"Titre "),t(10,"span",46),r(11,"*"),o()(),t(12,"input",47,1),C("ngModelChange",function(i){m(e);let d=c();return b(d.form.title,i)||(d.form.title=i),u(i)}),o(),M(14,xe,2,0,"p",48),o(),t(15,"div")(16,"label",45),r(17,"R\xE9sum\xE9"),o(),t(18,"textarea",49),C("ngModelChange",function(i){m(e);let d=c();return b(d.form.summary,i)||(d.form.summary=i),u(i)}),o()(),t(19,"div")(20,"label",45),r(21,"Contenu "),t(22,"span",46),r(23,"*"),o()(),t(24,"textarea",50,2),C("ngModelChange",function(i){m(e);let d=c();return b(d.form.content,i)||(d.form.content=i),u(i)}),o(),M(26,_e,2,0,"p",48),o(),t(27,"div",51)(28,"div")(29,"label",45),r(30,"Date"),o(),t(31,"input",52),C("ngModelChange",function(i){m(e);let d=c();return b(d.form.datePublication,i)||(d.form.datePublication=i),u(i)}),o()(),t(32,"div")(33,"label",45),r(34,"Lieu"),o(),t(35,"input",47,1),C("ngModelChange",function(i){m(e);let d=c();return b(d.form.lieux,i)||(d.form.lieux=i),u(i)}),o()()(),t(37,"div")(38,"label",45),r(39,"Statut"),t(40,"span",46),r(41,"*"),o()(),t(42,"select",53),C("ngModelChange",function(i){m(e);let d=c();return b(d.form.status,i)||(d.form.status=i),u(i)}),t(43,"option",54),r(44,"Brouillon"),o(),t(45,"option",55),r(46,"En attente"),o(),t(47,"option",56),r(48,"Publi\xE9"),o(),t(49,"option",57),r(50,"Archiv\xE9"),o()()(),t(51,"div")(52,"label",45),r(53,"Image mise en avant "),t(54,"span",46),r(55,"*"),o()(),t(56,"input",58),p("change",function(i){m(e);let d=c();return u(d.onFileSelected(i))}),o()(),t(57,"div",59)(58,"button",60),p("click",function(){m(e);let i=c();return u(i.closeModal())}),r(59,"Annuler"),o(),t(60,"button",61),w(61,he,1,0,"div",62),r(62),o()()()()()}if(a&2){let e=I(13),l=I(25),i=c();s(4),E(" ",i.editingArticle()?"Modifier l'agenda":"Nouvel agenda"," "),s(8),v("ngModel",i.form.title),s(2),g("ngIf",e.invalid&&e.touched),s(4),v("ngModel",i.form.summary),s(6),v("ngModel",i.form.content),s(2),g("ngIf",l.invalid&&l.touched),s(5),v("ngModel",i.form.datePublication),s(4),v("ngModel",i.form.lieux),s(7),v("ngModel",i.form.status),s(18),g("disabled",i.saving()),s(),S(i.saving()?61:-1),s(),E(" ",i.editingArticle()?"Mettre \xE0 jour":"Cr\xE9er"," ")}}function be(a,n){a&1&&(_(),t(0,"svg",67),f(1,"path",68),o())}function Ce(a,n){a&1&&(_(),t(0,"svg",67),f(1,"path",69),o())}function we(a,n){a&1&&(_(),t(0,"svg",67),f(1,"path",70),o())}function Se(a,n){if(a&1&&(t(0,"div",14)(1,"div",64),M(2,be,2,0,"svg",65)(3,Ce,2,0,"svg",65)(4,we,2,0,"svg",65),t(5,"span",66),r(6),o()()()),a&2){let e=c();s(),g("ngClass",W(5,de,e.notification().type==="success",e.notification().type==="error",e.notification().type==="info")),s(),g("ngIf",e.notification().type==="success"),s(),g("ngIf",e.notification().type==="error"),s(),g("ngIf",e.notification().type==="info"),s(2),h(e.notification().message)}}function ye(a,n){if(a&1){let e=y();t(0,"div",15)(1,"div",71)(2,"h3",72),r(3,"Confirmation"),o(),t(4,"p",73),r(5),o(),t(6,"div",74)(7,"button",75),p("click",function(){m(e);let i=c();return u(i.closeConfirmModal())}),r(8," Annuler "),o(),t(9,"button",76),p("click",function(){m(e);let i=c();return u(i.confirmModal().onConfirm())}),r(10," Supprimer "),o()()()()}if(a&2){let e=c();s(5),h(e.confirmModal().message)}}var ae=class a{constructor(n,e){this.apiService=n;this.router=e}notification=x({show:!1,message:"",type:"success"});articles=x([]);loading=x(!0);showModal=x(!1);editingArticle=x(null);saving=x(!1);selectedImages=[];fileError=!1;currentPage=x(1);pageSize=7;totalPages=x(1);form={title:"",summary:"",content:"",lieux:"",datePublication:new Date,status:"DRAFT",images:[]};ngOnInit(){this.loadArticles()}loadArticles(n=0){this.loading.set(!0),this.apiService.getAllAgendas(n,this.pageSize).subscribe({next:e=>{e.success&&(this.articles.set(e.data.content),this.totalPages.set(e.data.totalPages),this.currentPage.set(n+1)),this.loading.set(!1)},error:()=>{this.loading.set(!1)}})}nextPage(){this.currentPage()1&&this.loadArticles(this.currentPage()-2)}goToPage(n){this.loadArticles(n-1)}pages(){return Array.from({length:this.totalPages()},(n,e)=>e+1)}openModal(){this.form={title:"",summary:"",content:"",lieux:"",datePublication:new Date,status:"DRAFT",images:[]},this.selectedImages=[],this.fileError=!1,this.editingArticle.set(null),this.showModal.set(!0)}closeModal(n){this.showModal.set(!1),this.editingArticle.set(null),this.selectedImages=[],this.fileError=!1,n?.resetForm()}onFileSelected(n){let e=n.target;if(!e.files||e.files.length===0){this.selectedImages=[];return}this.selectedImages=Array.from(e.files),this.fileError=!1}editArticle(n){this.form={title:n.title,summary:n.summary||"",content:n.content,status:n.status,lieux:n.lieux,datePublication:n.datePublication,images:n.images||[]},this.selectedImages=[],this.editingArticle.set(n),this.showModal.set(!0)}saveArticle(n){if(console.log(this.form),!this.form.title||!this.form.content)return;if(!this.editingArticle()&&(!this.selectedImages||this.selectedImages.length===0)){this.fileError=!0;return}this.saving.set(!0);let e=this.editingArticle(),l={title:this.form.title,summary:this.form.summary,content:this.form.content,status:this.form.status,lieux:this.form.lieux,datePublication:this.form.datePublication},i=new FormData;i.append("agenda",new Blob([JSON.stringify(l)],{type:"application/json"})),i.append("authorId","1"),this.selectedImages.forEach(k=>{i.append("files",k)}),(e?this.apiService.updateAgendas(e.id,i):this.apiService.createAgendas(i)).subscribe({next:()=>{this.loadArticles(),this.closeModal(n),this.saving.set(!1),this.showNotification(e?"Article mis \xE0 jour avec succ\xE8s":"Article cr\xE9\xE9 avec succ\xE8s","success")},error:k=>{console.error("Erreur lors de la sauvegarde",k),this.saving.set(!1),this.showNotification("Erreur lors de la sauvegarde","error")}})}getStatusLabel(n){return{DRAFT:"Brouillon",PENDING:"En attente",PUBLISHED:"Publi\xE9",ARCHIVED:"Archiv\xE9"}[n]||n}getStatusBadgeClass(n){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"}[n]||"badge bg-neutral-100 text-neutral-600"}formatDate(n){return n?new Date(n).toLocaleDateString("fr-FR"):""}trackByArticleId(n,e){return e.id}showNotification(n,e="success",l=2e3){this.notification.set({show:!0,message:n,type:e}),setTimeout(()=>this.notification.update(i=>P(V({},i),{show:!1})),l)}confirmModal=x({show:!1,message:"",onConfirm:()=>{}});openConfirmModal(n,e){this.confirmModal.set({show:!0,message:n,onConfirm:e})}closeConfirmModal(){this.confirmModal.update(n=>P(V({},n),{show:!1}))}deleteArticle(n){this.openConfirmModal(`Voulez-vous vraiment supprimer l'article "${n.title}" ?`,()=>{this.apiService.deleteAgendas(n.id).subscribe({next:()=>{this.loadArticles(),this.closeConfirmModal(),this.showNotification("Article supprim\xE9 avec succ\xE8s","success")},error:()=>{this.showNotification("Erreur lors de la suppression","error"),this.closeConfirmModal()}})})}static \u0275fac=function(e){return new(e||a)(T(re),T(U))};static \u0275cmp=D({type:a,selectors:[["app-agenda"]],decls:18,vars:4,consts:[["articleForm","ngForm"],["title","ngModel"],["content","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,"text-right"],[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"],[1,"text-sm","text-neutral-500"],[1,"px-6","py-4","text-right"],[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"],["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","title","required","",1,"input",3,"ngModelChange","ngModel"],["class","text-sm text-red-500 mt-1",4,"ngIf"],["name","summary","rows","2",1,"input","resize-none",3,"ngModelChange","ngModel"],["name","content","rows","6","required","",1,"input","resize-none",3,"ngModelChange","ngModel"],[1,"grid","grid-cols-2","gap-4"],["type","date","name","publishedAt",1,"input",3,"ngModelChange","ngModel"],["name","status",1,"input",3,"ngModelChange","ngModel"],["value","DRAFT"],["value","PENDING"],["value","PUBLISHED"],["value","ARCHIVED"],["type","file","multiple","","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,l){e&1&&(t(0,"div",3)(1,"div",4)(2,"div")(3,"h1",5),r(4,"Agendas"),o(),t(5,"p",6),r(6,"G\xE9rez l'agenda du ministre"),o()(),t(7,"button",7),p("click",function(){return l.openModal()}),_(),t(8,"svg",8),f(9,"path",9),o(),r(10," Nouvel agenda "),o()(),A(),t(11,"div",10),w(12,me,2,0,"div",11)(13,ue,5,0,"div",11)(14,fe,23,3,"div",12),o(),w(15,ve,63,12,"div",13),o(),w(16,Se,7,9,"div",14),w(17,ye,11,1,"div",15)),e&2&&(s(12),S(l.loading()?12:l.articles().length===0?13:14),s(3),S(l.showModal()?15:-1),s(),S(l.notification().show?16:-1),s(),S(l.confirmModal().show?17:-1))},dependencies:[q,R,z,G,O,oe,$,te,ie,K,ee,Q,X,ne,Z,Y,J],encapsulation:2})};export{ae as AgendaComponent};