import"./chunk-JGH6I3KN.js";import{a as oe}from"./chunk-YEESETR2.js";import{c as $,d as J,e as K,f as Q,g as X,h as Y,k as Z,l as ee,n as te,p as ne,t as ie}from"./chunk-UDFQV3WY.js";import{a as q}from"./chunk-MBEC6LK4.js";import{Ba as P,Eb as a,Fa as s,Fb as h,Gb as F,Jb as w,Kb as S,Lb as E,Oa as I,Ob as N,R as m,Rb as O,S as u,T as x,Ta as A,U as D,Ya as b,ca as f,db as v,fb as C,hb as L,ib as j,jb as p,kb as n,lb as i,mb as _,nb as R,ob as B,pc as z,qb as y,qc as U,rb as g,rc as W,sb as c,sc as G,xc as H,zb as k}from"./chunk-TVKQFRWX.js";import{a as M,b as T}from"./chunk-DAQOROHW.js";var ae=()=>({"background-color":"#00843B","border-color":"#00843B"}),le=()=>({}),se=(r,t,e)=>({"bg-green-50 border-green-500 text-green-700":r,"bg-red-50 border-red-500 text-red-700":t,"bg-blue-50 border-blue-500 text-blue-700":e}),ce=(r,t)=>t.id;function de(r,t){r&1&&(n(0,"div",10),_(1,"div",15),i())}function me(r,t){r&1&&(n(0,"div",10),x(),n(1,"svg",16),_(2,"path",17),i(),D(),n(3,"p",5),a(4,"Aucun document pour le moment"),i()())}function ue(r,t){r&1&&(n(0,"span",28),a(1,"Oui"),i())}function pe(r,t){r&1&&(n(0,"span",29),a(1,"Non"),i())}function ge(r,t){if(r&1){let e=y();n(0,"tr")(1,"td")(2,"div",23)(3,"a",24)(4,"p",25),a(5),i(),n(6,"p",26),a(7),i()()()(),n(8,"td")(9,"span",27),a(10),i()(),n(11,"td"),v(12,ue,2,0,"span",28)(13,pe,2,0,"span",29),i(),n(14,"td",30),a(15),i(),n(16,"td",19)(17,"div",31)(18,"button",32),g("click",function(){let o=m(e).$implicit,d=c(2);return u(d.editDocument(o))}),x(),n(19,"svg",33),_(20,"path",34),i()(),D(),n(21,"button",35),g("click",function(){let o=m(e).$implicit,d=c(2);return u(d.deleteDocument(o))}),x(),n(22,"svg",36),_(23,"path",37),i()()()()()}if(r&2){let e=t.$implicit,l=c(2);s(3),p("href",l.getImageUrl(e.filePath),P),s(2),h(e.title),s(2),h(e.description),s(3),h(l.documentSectionLabel(e)),s(2),C(e.isPublic?12:13),s(3),h(l.formatDate(e.createdAt))}}function fe(r,t){if(r&1){let e=y();R(0),n(1,"button",38),g("click",function(){let o=m(e).$implicit,d=c(2);return u(d.goToPage(o))}),a(2),i(),B()}if(r&2){let e=t.$implicit,l=c(2);s(),p("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,ae):N(4,le)),s(),F(" ",e," ")}}function _e(r,t){if(r&1){let e=y();n(0,"div",11)(1,"table",18)(2,"thead")(3,"tr")(4,"th"),a(5,"Titre"),i(),n(6,"th"),a(7,"Cat\xE9gorie"),i(),n(8,"th"),a(9,"Public"),i(),n(10,"th"),a(11,"Date"),i(),n(12,"th",19),a(13,"Actions"),i()()(),n(14,"tbody"),L(15,ge,24,6,"tr",null,ce),i()(),n(17,"div",20)(18,"button",21),g("click",function(){m(e);let o=c();return u(o.prevPage())}),a(19," \xAB Pr\xE9c\xE9dent "),i(),b(20,fe,3,5,"ng-container",22),n(21,"button",21),g("click",function(){m(e);let o=c();return u(o.nextPage())}),a(22," Suivant \xBB "),i()()()}if(r&2){let e=c();s(15),j(e.documents()),s(3),p("disabled",e.currentPage()===1),s(2),p("ngForOf",e.pages()),s(),p("disabled",e.currentPage()===e.totalPages())}}function xe(r,t){r&1&&(n(0,"p",58),a(1," Le titre est obligatoire. "),i())}function he(r,t){r&1&&(n(0,"span",59),a(1,"*"),i())}function ve(r,t){r&1&&(n(0,"p",60),a(1,"Laissez vide pour conserver le fichier actuel."),i())}function Ce(r,t){r&1&&_(0,"div",57)}function be(r,t){if(r&1){let e=y();n(0,"div",12)(1,"div",39)(2,"div",40)(3,"h2",41),a(4),i()(),n(5,"form",42,0),g("ngSubmit",function(){m(e);let o=c();return u(o.saveDocument())}),n(7,"div")(8,"label",43),a(9,"Titre "),n(10,"span",44),a(11,"*"),i()(),n(12,"input",45,1),E("ngModelChange",function(o){m(e);let d=c();return S(d.form.title,o)||(d.form.title=o),u(o)}),i(),b(14,xe,2,0,"p",46),i(),n(15,"div")(16,"label",43),a(17,"Description"),i(),n(18,"textarea",47),E("ngModelChange",function(o){m(e);let d=c();return S(d.form.description,o)||(d.form.description=o),u(o)}),i()(),n(19,"div")(20,"label",43),a(21,"Type de document "),n(22,"span",44),a(23,"*"),i()(),n(24,"select",48),E("ngModelChange",function(o){m(e);let d=c();return S(d.form.section,o)||(d.form.section=o),u(o)}),n(25,"option",49),a(26,"Textes fondamentaux"),i(),n(27,"option",50),a(28,"Rapports et autres textes"),i()()(),n(29,"div")(30,"label",43),a(31,"Fichier PDF "),b(32,he,2,0,"span",51),i(),n(33,"input",52),g("change",function(o){m(e);let d=c();return u(d.onFileSelected(o))}),i(),b(34,ve,2,0,"p",53),i(),n(35,"div",54)(36,"button",55),g("click",function(){m(e);let o=c();return u(o.closeModal())}),a(37,"Annuler"),i(),n(38,"button",56),v(39,Ce,1,0,"div",57),a(40),i()()()()()}if(r&2){let e=k(6),l=k(13),o=c();s(4),h(o.editingDocument()?"Modifier le document":"Nouveau document"),s(8),w("ngModel",o.form.title),s(2),p("ngIf",l.invalid&&e.submitted),s(4),w("ngModel",o.form.description),s(6),w("ngModel",o.form.section),s(8),p("ngIf",!o.editingDocument()),s(2),p("ngIf",o.editingDocument()),s(4),p("disabled",o.saving()),s(),C(o.saving()?39:-1),s(),F(" ",o.editingDocument()?"Mettre \xE0 jour":"Cr\xE9er"," ")}}function ye(r,t){r&1&&(x(),n(0,"svg",64),_(1,"path",65),i())}function De(r,t){r&1&&(x(),n(0,"svg",64),_(1,"path",66),i())}function we(r,t){r&1&&(x(),n(0,"svg",64),_(1,"path",67),i())}function Se(r,t){if(r&1&&(n(0,"div",13)(1,"div",61),b(2,ye,2,0,"svg",62)(3,De,2,0,"svg",62)(4,we,2,0,"svg",62),n(5,"span",63),a(6),i()()()),r&2){let e=c();s(),p("ngClass",O(5,se,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),h(e.notification().message)}}function Ee(r,t){if(r&1){let e=y();n(0,"div",14)(1,"div",68)(2,"h3",69),a(3,"Confirmation"),i(),n(4,"p",70),a(5),i(),n(6,"div",71)(7,"button",72),g("click",function(){m(e);let o=c();return u(o.closeConfirmModal())}),a(8," Annuler "),i(),n(9,"button",73),g("click",function(){m(e);let o=c();return u(o.confirmModal().onConfirm())}),a(10," Supprimer "),i()()()()}if(r&2){let e=c();s(5),h(e.confirmModal().message)}}var re=class r{constructor(t){this.apiService=t}fileBaseUrl=q.FileUrl;documents=f([]);documentTypes=f([]);loading=f(!0);showModal=f(!1);editingDocument=f(null);saving=f(!1);currentPage=f(1);totalPages=f(1);notification=f({show:!1,message:"",type:"success"});confirmModal=f({show:!1,message:"",onConfirm:()=>{}});pageSize=7;selectedFile=null;form=this.emptyForm();ngOnInit(){this.loadDocuments(),this.loadDocumentTypes()}loadDocuments(t=0){this.loading.set(!0),this.apiService.getAllDocuments(t,this.pageSize).subscribe({next:e=>{e.success&&(this.documents.set(e.data.content),this.totalPages.set(e.data.totalPages),this.currentPage.set(t+1)),this.loading.set(!1)},error:()=>{this.loading.set(!1),this.showNotification("Impossible de charger les documents.","error")}})}loadDocumentTypes(){this.apiService.getAllTypes().subscribe({next:t=>this.documentTypes.set(t),error:()=>this.showNotification("La configuration des documents est indisponible.","error")})}nextPage(){this.currentPage()1&&this.loadDocuments(this.currentPage()-2)}goToPage(t){this.loadDocuments(t-1)}pages(){return Array.from({length:this.totalPages()},(t,e)=>e+1)}openModal(){this.form=this.emptyForm(),this.selectedFile=null,this.editingDocument.set(null),this.showModal.set(!0)}editDocument(t){this.form={title:t.title,description:t.description||"",section:this.isFundamentalCategory(t.category)?"FUNDAMENTAL":"REPORTS"},this.selectedFile=null,this.editingDocument.set(t),this.showModal.set(!0)}closeModal(){this.showModal.set(!1),this.editingDocument.set(null),this.selectedFile=null}onFileSelected(t){let e=t.target,l=e.files?.[0]??null;if(!l){this.selectedFile=null;return}if(l.type!=="application/pdf"){this.showNotification("Veuillez s\xE9lectionner un fichier PDF.","error"),e.value="",this.selectedFile=null;return}this.selectedFile=l}saveDocument(){let t=this.editingDocument();if(!this.form.title.trim())return;if(!t&&!this.selectedFile){this.showNotification("Le fichier PDF est obligatoire.","error");return}let e=t?.typeId||this.documentTypes()[0]?.id;if(!e){this.showNotification("La configuration interne des documents est indisponible.","error");return}let l={title:this.form.title.trim(),description:this.form.description.trim(),category:this.form.section==="FUNDAMENTAL"?"DECRET":"RAPPORT",typeDocument:"DOCUMENT SIMPLE",typeId:e,isPublic:!0},o=new FormData;o.append("document",new Blob([JSON.stringify(l)],{type:"application/json"})),this.selectedFile&&o.append("file",this.selectedFile),this.saving.set(!0),(t?this.apiService.updateDocument(t.id,o):this.apiService.createDocument(o)).subscribe({next:V=>{if(this.saving.set(!1),!V.success){this.showNotification(V.message||"La sauvegarde a \xE9chou\xE9.","error");return}this.loadDocuments(),this.closeModal(),this.showNotification(t?"Document mis \xE0 jour avec succ\xE8s.":"Document cr\xE9\xE9 avec succ\xE8s.")},error:()=>{this.saving.set(!1),this.showNotification("Erreur lors de la sauvegarde du document.","error")}})}deleteDocument(t){this.openConfirmModal(`Voulez-vous vraiment supprimer le document \xAB ${t.title} \xBB ?`,()=>{this.apiService.deleteDocument(t.id).subscribe({next:()=>{this.loadDocuments(),this.closeConfirmModal(),this.showNotification("Document supprim\xE9 avec succ\xE8s.")},error:()=>{this.closeConfirmModal(),this.showNotification("Erreur lors de la suppression.","error")}})})}documentSectionLabel(t){return this.isFundamentalCategory(t.category)?"Textes fondamentaux":"Rapports et autres textes"}formatDate(t){return t?new Date(t).toLocaleDateString("fr-FR"):""}getImageUrl(t){return t?/^(https?:\/\/|assets\/)/i.test(t)?t:`${this.fileBaseUrl}${t.startsWith("/")?"":"/"}${t}`:null}showNotification(t,e="success",l=3e3){this.notification.set({show:!0,message:t,type:e}),setTimeout(()=>this.notification.update(o=>T(M({},o),{show:!1})),l)}openConfirmModal(t,e){this.confirmModal.set({show:!0,message:t,onConfirm:e})}closeConfirmModal(){this.confirmModal.update(t=>T(M({},t),{show:!1}))}emptyForm(){return{title:"",description:"",section:"REPORTS"}}isFundamentalCategory(t){return["DECRET","ARRETE","LOI","CIRCULAIRE"].includes(t)}static \u0275fac=function(e){return new(e||r)(I(oe))};static \u0275cmp=A({type:r,selectors:[["app-documents"]],decls:18,vars:4,consts:[["documentForm","ngForm"],["titleField","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","M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"],[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"],["target","_blank",3,"href"],[1,"font-medium","text-neutral-900","truncate"],[1,"text-xs","text-neutral-400","truncate"],[1,"badge-primary"],[1,"badge-success"],[1,"badge","bg-neutral-100","text-neutral-600"],[1,"text-sm","text-neutral-500"],[1,"flex","justify-end","gap-2"],["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-lg","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","title","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"],["name","section","required","",1,"input",3,"ngModelChange","ngModel"],["value","FUNDAMENTAL"],["value","REPORTS"],["class","text-red-500",4,"ngIf"],["type","file","accept","application/pdf",1,"input",3,"change"],["class","mt-1 text-xs text-neutral-500",4,"ngIf"],[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,"btn-primary",3,"disabled"],[1,"spinner","w-4","h-4","mr-2"],[1,"text-sm","text-red-500","mt-1"],[1,"text-red-500"],[1,"mt-1","text-xs","text-neutral-500"],[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&&(n(0,"div",2)(1,"div",3)(2,"div")(3,"h1",4),a(4,"Documents"),i(),n(5,"p",5),a(6,"G\xE9rez les ressources documentaires"),i()(),n(7,"button",6),g("click",function(){return l.openModal()}),x(),n(8,"svg",7),_(9,"path",8),i(),a(10," Nouveau document "),i()(),D(),n(11,"div",9),v(12,de,2,0,"div",10)(13,me,5,0,"div",10)(14,_e,23,3,"div",11),i(),v(15,be,41,10,"div",12),i(),v(16,Se,7,9,"div",13),v(17,Ee,11,1,"div",14)),e&2&&(s(12),C(l.loading()?12:l.documents().length===0?13:14),s(3),C(l.showModal()?15:-1),s(),C(l.notification().show?16:-1),s(),C(l.confirmModal().show?17:-1))},dependencies:[H,z,U,W,G,ie,Y,ee,te,$,Z,J,K,ne,X,Q],encapsulation:2})};export{re as DocumentsComponent};