1import{a as xe,b as ve}from"./chunk-6I2IYBDR.js";import{b as fe}from"./chunk-2DRLWINX.js";import{a as _e,b as he}from"./chunk-N2NJ3SC5.js";import{b as we}from"./chunk-EI74KAEO.js";import{b as me,c as de,h as ce,m as pe,n as ge,o as ue}from"./chunk-2JJSDHJQ.js";import"./chunk-EIW4GEY6.js";import"./chunk-VQMX3SJ2.js";import"./chunk-J33ZPMFB.js";import{a as K}from"./chunk-IQMTFNUD.js";import{a as oe,b as re}from"./chunk-RMFHGOWT.js";import{a as se,b as le}from"./chunk-HOET22UW.js";import"./chunk-BVFTSP5L.js";import{c as X,f as Y,i as Z,r as $,u as ee,v as te}from"./chunk-O6HZDVIK.js";import{Ea as ie,Fa as ne,Ga as ae,V as F,Z as O,ba as Q}from"./chunk-QLOM5JUS.js";import"./chunk-QBDSPJMG.js";import{a as J}from"./chunk-NFUKOZRB.js";import"./chunk-AGZ7EOI7.js";import{Ab as x,Bb as p,Dc as q,Ga as V,Ic as U,Kc as j,La as m,Mb as s,Nb as E,Ob as R,Qa as M,Rb as b,Sb as C,Tb as y,Ub as z,Vb as S,Xa as B,Y as w,Z as _,bb as f,dc as G,fc as H,ib as g,lb as P,mb as L,sb as n,tb as i,ub as T,yb as D}from"./chunk-J7BKRFH2.js";import{a as W,g as A}from"./chunk-GAL4ENT6.js";var Ce=()=>({width:"450px"}),ye=()=>({"min-width":"50rem"}),Se=()=>["title","author_name"],Me=()=>({width:"70vw"}),Ee=()=>({height:"320px"});function Ie(o,t){o&1&&(n(0,"tr")(1,"th",10),s(2,"ID"),i(),n(3,"th",11),s(4,"Imagen"),i(),n(5,"th",12),s(6,"T\xEDtulo"),i(),n(7,"th",11),s(8,"Autor"),i(),n(9,"th",11),s(10,"Fecha"),i(),n(11,"th",13),s(12,"Estado"),i(),n(13,"th",12),s(14,"Acci\xF3n"),i()())}function Pe(o,t){if(o&1&&T(0,"img",18),o&2){let e=p().$implicit;g("src",e.image_data,V)}}function Te(o,t){o&1&&(n(0,"span"),s(1,"Sin imagen"),i())}function De(o,t){if(o&1){let e=D();n(0,"tr")(1,"td"),s(2),i(),n(3,"td"),f(4,Pe,1,1,"img",14)(5,Te,2,0,"span",15),i(),n(6,"td"),s(7),i(),n(8,"td"),s(9),i(),n(10,"td"),s(11),G(12,"date"),i(),n(13,"td")(14,"span"),s(15),i()(),n(16,"td")(17,"button",16),x("click",function(){let a=w(e).$implicit,l=p();return _(l.editNews(a))}),i(),n(18,"button",17),x("click",function(){let a=w(e).$implicit,l=p();return _(l.deleteNews(a))}),i()()()}if(o&2){let e=t.$implicit;m(2),E(e.id),m(2),g("ngIf",e.image_data),m(),g("ngIf",!e.image_data),m(2),E(e.title),m(2),E(e.author_name),m(2),E(H(12,9,e.created_at,"dd/MM/yyyy")),m(3),L(e.status===1?"status-badge status-active":"status-badge status-inactive"),m(),R(" ",e.status===1?"Activo":"Inactivo"," ")}}function Fe(o,t){o&1&&(n(0,"tr")(1,"td",19),s(2,"No hay noticias disponibles."),i()())}function Oe(o,t){o&1&&(n(0,"small",37),s(1,"El t\xEDtulo es obligatorio."),i())}function ke(o,t){o&1&&(n(0,"small",37),s(1,"El autor es obligatorio."),i())}function Ve(o,t){if(o&1&&(n(0,"div",38),T(1,"img",39),i()),o&2){let e=p(2);m(),g("src",e.previewImage,V)}}function We(o,t){o&1&&(n(0,"small",37),s(1,"La fecha es obligatoria."),i())}function Ae(o,t){o&1&&(n(0,"small",37),s(1,"El contenido es obligatorio."),i())}function Be(o,t){if(o&1){let e=D();n(0,"div",20)(1,"label",21),s(2,"T\xEDtulo*"),i(),n(3,"input",22),y("ngModelChange",function(a){w(e);let l=p();return C(l.newNews.title,a)||(l.newNews.title=a),_(a)}),i(),f(4,Oe,2,0,"small",23),i(),n(5,"div",20)(6,"label",24),s(7,"Autor*"),i(),n(8,"input",25),y("ngModelChange",function(a){w(e);let l=p();return C(l.newNews.author_name,a)||(l.newNews.author_name=a),_(a)}),i(),f(9,ke,2,0,"small",23),i(),n(10,"div",20)(11,"label",26),s(12,"Imagen de la Noticia"),i(),n(13,"div",27)(14,"input",28),x("change",function(a){w(e);let l=p();return _(l.onFileSelect(a))}),i()(),f(15,Ve,2,1,"div",29),i(),n(16,"div",20)(17,"label",30),s(18,"Fecha*"),i(),n(19,"input",31),y("ngModelChange",function(a){w(e);let l=p();return C(l.newNews.date,a)||(l.newNews.date=a),_(a)}),i(),f(20,We,2,0,"small",23),i(),n(21,"div",20)(22,"label",32),s(23,"Contenido*"),i(),n(24,"p-editor",33),y("ngModelChange",function(a){w(e);let l=p();return C(l.newNews.content,a)||(l.newNews.content=a),_(a)}),i(),f(25,Ae,2,0,"small",23),i(),n(26,"div",20)(27,"label",34),s(28,"Estado"),i(),n(29,"div",27)(30,"p-checkbox",35),x("ngModelChange",function(a){w(e);let l=p();return _(l.newNews.status=a?1:0)}),i(),n(31,"label",36),s(32,"Activo"),i()()()}if(o&2){let e=p();m(3),b("ngModel",e.newNews.title),m(),g("ngIf",e.submitted&&!e.newNews.title),m(4),b("ngModel",e.newNews.author_name),m(),g("ngIf",e.submitted&&!e.newNews.author_name),m(6),g("ngIf",e.previewImage),m(4),b("ngModel",e.newNews.date),m(),g("ngIf",e.submitted&&!e.newNews.date),m(4),P(S(13,Ee)),b("ngModel",e.newNews.content),m(),g("ngIf",e.submitted&&!e.newNews.content),m(5),g("ngModel",e.newNews.status===1)("binary",!0)}}function Le(o,t){if(o&1){let e=D();n(0,"button",40),x("click",function(){w(e);let a=p();return _(a.hideDialog())}),i(),n(1,"button",41),x("click",function(){w(e);let a=p();return _(a.saveNews())}),i()}}var Ne=class o{constructor(t,e,r,a){this.newsService=t;this.authService=e;this.messageService=r;this.confirmationService=a}news=[];selectedNews=null;newsDialog=!1;submitted=!1;statuses=[{label:"Activo",value:1},{label:"Inactivo",value:0}];newNews={title:"",content:"",author_name:"",date:"",status:1};selectedFile=null;previewImage=null;maxImageWidth=800;maxImageHeight=600;imageQuality=.6;ngOnInit(){this.loadNews(),this.newNews.author_name="Admin"}loadNews(){this.newsService.getAllNews().subscribe({next:t=>{this.news=t},error:t=>{this.messageService.add({severity:"error",summary:"Error",detail:"No se pudieron cargar las noticias"})}})}
1openNew(){this.newNews={title:"",content:"",author_name:"Admin",date:"",status:1},this.selectedFile=null,this.previewImage=null,this.submitted=!1,this.newsDialog=!0}editNews(t){this.newNews={id:t.id,title:t.title,content:t.content,author_name:t.author_name,date:t.date||"",status:t.status},this.selectedFile=null,this.previewImage=t.image_data||null,this.newsDialog=!0}deleteNews(t){this.confirmationService.confirm({message:"\xBFEst\xE1 seguro que desea eliminar esta noticia?",header:"Confirmar",icon:"pi pi-exclamation-triangle",accept:()=>{t.id&&this.newsService.deleteNews(t.id).subscribe({next:()=>{this.news=this.news.filter(e=>e.id!==t.id),this.messageService.add({severity:"success",summary:"\xC9xito",detail:"Noticia eliminada",life:3e3})},error:e=>{this.messageService.add({severity:"error",summary:"Error",detail:"No se pudo eliminar la noticia"})}})}})}hideDialog(){this.newsDialog=!1,this.submitted=!1}saveNews(){return A(this,null,function*(){if(this.submitted=!0,this.newNews.title.trim()&&this.newNews.content.trim()&&this.newNews.author_name.trim()&&this.newNews.date?.trim())try{let t={title:this.newNews.title,content:this.newNews.content,author_name:this.newNews.author_name,date:this.newNews.date,status:typeof this.newNews.status=="boolean"?this.newNews.status?1:0:this.newNews.status||0};if(this.newNews.id&&(t.id=this.newNews.id),this.selectedFile)try{t.image_data=yield this.compressImage(this.selectedFile)}catch{this.messageService.add({severity:"error",summary:"Error",detail:"Error al procesar la imagen"});return}else this.previewImage&&this.newNews.id&&this.previewImage.startsWith("data:image")&&(t.image_data=this.previewImage);this.newNews.id?this.newsService.updateNews(this.newNews.id,t).subscribe({next:e=>{let r=this.news.findIndex(a=>a.id===this.newNews.id);r!==-1&&(this.news[r]=W({},e)),this.messageService.add({severity:"success",summary:"\xC9xito",detail:"Noticia actualizada",life:3e3}),this.newsDialog=!1,this.loadNews()},error:e=>{this.messageService.add({severity:"error",summary:"Error",detail:"No se pudo actualizar la noticia: "+(e.error?.message||e.message||"Error desconocido")})}}):this.newsService.createNews(t).subscribe({next:e=>{this.news.push(e),this.messageService.add({severity:"success",summary:"\xC9xito",detail:"Noticia creada",life:3e3}),this.newsDialog=!1,this.loadNews()},error:e=>{this.messageService.add({severity:"error",summary:"Error",detail:"No se pudo crear la noticia: "+(e.error?.message||e.message||"Error desconocido")})}})}catch{this.messageService.add({severity:"error",summary:"Error",detail:"Ocurri\xF3 un error inesperado"})}else this.messageService.add({severity:"warn",summary:"Advertencia",detail:"Por favor complete todos los campos requeridos"})})}onFileSelect(t){let e=t.target;if(e.files&&e.files.length>0){this.selectedFile=e.files[0];let r=this.selectedFile.size/(1024*1024);r>10&&this.messageService.add({severity:"warn",summary:"Advertencia",detail:"La imagen es muy grande ("+r.toFixed(2)+" MB). Se comprimir\xE1 autom\xE1ticamente."}),this.previewSelectedImage()}}previewSelectedImage(){if(this.selectedFile){let t=new FileReader;t.onload=e=>{this.previewImage=e.target?.result},t.readAsDataURL(this.selectedFile)}}compressImage(t){return new Promise((e,r)=>{let a=new FileReader;a.onload=l=>{let v=new Image;v.onload=()=>{let be=t.type==="image/png"||t.name.toLowerCase().endsWith(".png"),d=v.width,c=v.height;if(be){if(d>2400){let u=2400/d;d=2400,c=c*u}if(c>1800){let u=1800/c;c=1800,d=d*u}let h=document.createElement("canvas");h.width=d,h.height=c;let N=h.getContext("2d");if(N){N.imageSmoothingEnabled=!0,N.imageSmoothingQuality="high",N.drawImage(v,0,0,d,c);let u=h.toDataURL("image/png",1);e(u)}else r(new Error("No se pudo crear el contexto del canvas"))}else{let I=this.imageQuality,k=t.size/(1024*1024);if(k>5?I=.4:k>2&&(I=.5),d>this.maxImageWidth){let u=this.maxImageWidth/d;d=this.maxImageWidth,c=c*u}if(c>this.maxImageHeight){let u=this.maxImageHeight/c;c=this.maxImageHeight,d=d*u}let h=document.createElement("canvas");h.width=d,h.height=c;let N=h.getContext("2d");if(N){N.drawImage(v,0,0,d,c);let u=h.toDataURL("image/jpeg",I),Re=u.length*3/4;e(u)}else r(new Error("No se pudo crear el contexto del canvas"))}},v.onerror=()=>
1{r(new Error("Error al cargar la imagen"))},v.src=l.target.result},a.onerror=()=>{r(new Error("Error al leer el archivo"))},a.readAsDataURL(t)})}static \u0275fac=function(e){return new(e||o)(M(K),M(J),M(O),M(F))};static \u0275cmp=B({type:o,selectors:[["app-news"]],features:[z([O,F])],decls:14,vars:15,consts:[[1,"card"],[1,"card-header"],["label","Nueva Noticia","icon","pi pi-plus","styleClass","p-button-success",3,"onClick"],["styleClass","p-datatable-sm",3,"value","tableStyle","paginator","rows","globalFilterFields"],["pTemplate","header"],["pTemplate","body"],["pTemplate","emptymessage"],["header","Detalles de Noticia","styleClass","p-fluid",3,"visibleChange","visible","modal"],["pTemplate","content"],["pTemplate","footer"],[2,"width","5%"],[2,"width","15%"],[2,"width","20%"],[2,"width","10%"],["alt","Imagen de noticia","width","100","class","shadow-4",3,"src",4,"ngIf"],[4,"ngIf"],["pButton","","pRipple","","icon","pi pi-pencil",1,"p-button-rounded","p-button-success","mr-2",3,"click"],["pButton","","pRipple","","icon","pi pi-trash",1,"p-button-rounded","p-button-danger",3,"click"],["alt","Imagen de noticia","width","100",1,"shadow-4",3,"src"],["colspan","7"],[1,"p-field","mt-3"],["for","title"],["type","text","pInputText","","id","title","required","","autofocus","",1,"w-full",3,"ngModelChange","ngModel"],["class","p-error",4,"ngIf"],["for","author_name"],["type","text","pInputText","","id","author_name","required","",1,"w-full",3,"ngModelChange","ngModel"],["for","image"],[1,"flex","align-items-center"],["type","file","accept","image/*",1,"w-full",3,"change"],["class","image-preview mt-2",4,"ngIf"],["for","date"],["type","date","pInputText","","id","date","required","",1,"w-full",3,"ngModelChange","ngModel"],["for","content"],["placeholder","Escribe el contenido de la noticia aqu\xED",3,"ngModelChange","ngModel"],["for","status"],["inputId","status",3,"ngModelChange","ngModel","binary"],["for","status",1,"ml-2"],[1,"p-error"],[1,"image-preview","mt-2"],["alt","Vista previa",2,"max-width","300px","max-height","200px",3,"src"],["pButton","","pRipple","","label","Cancelar","icon","pi pi-times",1,"p-button-text",3,"click"],["pButton","","pRipple","","label","Guardar","icon","pi pi-check",1,"p-button-text",3,"click"]],template:function(e,r){e&1&&(n(0,"div",0),T(1,"p-toast")(2,"p-confirmDialog"),n(3,"div",1)(4,"h2"),s(5,"Gesti\xF3n de Noticias"),i(),n(6,"p-button",2),x("onClick",function(){return r.openNew()}),i()(),n(7,"p-table",3),f(8,Ie,15,0,"ng-template",4)(9,De,19,12,"ng-template",5)(10,Fe,3,0,"ng-template",6),i()(),n(11,"p-dialog",7),y("visibleChange",function(l){return C(r.newsDialog,l)||(r.newsDialog=l),l}),f(12,Be,33,14,"ng-template",8)(13,Le,2,0,"ng-template",9),i()),e&2&&(m(2),P(S(11,Ce)),m(5),g("value",r.news)("tableStyle",S(12,ye))("paginator",!0)("rows",10)("globalFilterFields",S(13,Se)),m(4),P(S(14,Me)),b("visible",r.newsDialog),g("modal",!0))},dependencies:[j,q,U,ee,X,Y,$,Z,te,pe,ce,Q,ae,ie,ne,ue,ge,re,oe,we,le,se,he,_e,de,me,fe,ve,xe],styles:[".card[_ngcontent-%COMP%]{background:#fff;padding:1.5rem;border-radius:10px;box-shadow:0 2px 8px #0000001a;margin-bottom:1.5rem}.card-header[_ngcontent-%COMP%]{display:flex;justify-content:space-between;align-items:center;margin-bottom:1.5rem}.card-header[_ngcontent-%COMP%] h2[_ngcontent-%COMP%]{margin:0;font-size:1.5rem;font-weight:600;color:#333}.status-badge[_ngcontent-%COMP%]{padding:.25rem .75rem;border-radius:4px;font-size:.875rem;font-weight:500;display:inline-block}.status-active[_ngcontent-%COMP%]{background-color:#dcfce7;color:#166534}.status-inactive[_ngcontent-%COMP%]{background-color:#fee2e2;color:#991b1b}.image-preview[_ngcontent-%COMP%]{position:relative;margin-bottom:1rem;border:1px solid #ced4da;border-radius:4px;padding:4px;background-color:#f8f9fa}.p-editor-container[_ngcontent-%COMP%] .p-editor-content[_ngcontent-%COMP%]{min-height:200px}@media (max-width: 576px){.p-dialog[_ngcontent-%COMP%]{width:95%!important}.p-dialog[_ngcontent-%COMP%] .p-dialog-content[_ngcontent-%COMP%]{padding:1rem}}[_nghost-%COMP%] .p-datatable .p-datatable-tbody>tr>td img{display:block;margin:0 auto}button[_ngcontent-%COMP%]:disabled{opacity:.6;cursor:not-allowed}.p-dialog-content[_ngcontent-%COMP%]{padding:1.5rem}.p-field[_ngcontent-%COMP%]{margin-bottom:1rem}.p-field[_ngcontent-%COMP%] label[_ngcontent-%COMP%]{display:block;margin-bottom:.5rem;font-weight:500}.p-field[_ngcontent-%COMP%] small.p-error[_ngcontent-%COMP%]{color:#ef4444;margin-top:.25rem;display:block}.text-red-500[_ngcontent-%COMP%]{color:#ef4444}.text-gray-500[_ngcontent-%COMP%]{color:#6b7280}
1.mr-2[_ngcontent-%COMP%]{margin-right:.5rem}.mt-2[_ngcontent-%COMP%]{margin-top:.5rem}.mt-3[_ngcontent-%COMP%]{margin-top:.75rem}.ml-2[_ngcontent-%COMP%]{margin-left:.5rem}.w-full[_ngcontent-%COMP%]{width:100%}.flex[_ngcontent-%COMP%]{display:flex}.align-items-center[_ngcontent-%COMP%]{align-items:center}"]})};export{Ne as NewsComponent};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.