1import{u as l,j as e,R as Se,Y as Ye,q as Ke,X as Xe,L as ee,ec as We,ba as Ee,E as Ve,au as De,ed as Ie,ae as Ze,cV as Te,e2 as ke,d3 as Je,av as es,dR as ss}from"./vendor-ui-fc56ca80.js";import{r as t,e as as}from"./vendor-react-f9ccc48d.js";import{a as N}from"./adminNewsletterService-9135de76.js";import{bQ as ts,K as be,M as Ne,N as we,O as Ce,Q as ye,I as he,t as je,y as ve,am as rs,h as ls,v as Ae,w as Le,ae as qe,ag as Ue,ah as J,ai as Re,z as j,B as c,n as ze,an as is,D as ns,d as cs,e as os,f as Pe,U as ds,V as ms,W as me,X as Z,Y as us,Z as V,az as hs,a1 as _e,a2 as Me,a3 as Fe,a4 as He,a5 as Ge,a6 as $e,a7 as Be,a8 as xs,R as re}from"./index-90016d22.js";import{r as ps}from"./recipientListService-56a8618e.js";import{a as gs}from"./adminService-9c8edc1b.js";import{N as fs,a4 as js}from"./vendor-firebase-a557f106.js";import{R as vs,a as ue}from"./radio-group-d691b83e.js";import{C as bs}from"./CustomQuillEditor-03ab1b48.js";import{r as Oe}from"./resourceService-cdd57c83.js";import{ac as Ns,f as ws}from"./vendor-utils-323b9898.js";import"./vendor-charts-9af8b7c0.js";import"./quill.snow-2c352c31.js";function Cs({open:d,onOpenChange:G,onSelect:q}){const[S,D]=t.useState([]),[A,L]=t.useState([]),[R,$]=t.useState(!1),[w,v]=t.useState(!1),[i,B]=t.useState("");t.useEffect(()=>{d&&b()},[d]);const b=async()=>{try{$(!0);const r=await Oe.listResources();D(r),L(r)}catch(r){console.error("Failed to load resources:",r),l.error("Error al cargar los recursos")}finally{$(!1)}};t.useEffect(()=>{if(!i.trim())L(S);else{const r=i.toLowerCase();L(S.filter(g=>g.name.toLowerCase().includes(r)))}},[i,S]);const z=async r=>{if(r.length===0)return;v(!0);let g=0;for(const m of r)try{await Oe.uploadResource(m),g++}catch(f){console.error(`Error uploading ${m.name}:`,f),l.error(`Error al subir ${m.name}`)}g>0&&(l.success(`${g} archivo(s) subido(s).`),await b()),v(!1)},x=t.useCallback(r=>{z(r)},[]),{getRootProps:C,getInputProps:p,isDragActive:Q}=ts({onDrop:x,accept:{"image/*":[],"application/pdf":[]}});t.useEffect(()=>{if(!d)return;const r=g=>{var I;const m=(I=g.clipboardData)==null?void 0:I.items;if(!m)return;const f=[];for(let y=0;y<m.length;y++){const T=m[y];if(T.type.indexOf("image")!==-1){const k=T.getAsFile();if(k){const E=`pasted-image-${Date.now()}.png`,_=new File([k],E,{type:k.type});f.push(_)}}}f.length>0&&(l.info("Subiendo imagen del portapapeles..."),z(f))};return window.addEventListener("paste",r),()=>window.removeEventListener("paste",r)},[d]);const h=r=>{q(r.url),G(!1)},P=r=>{if(r===0)return"0 Bytes";const g=1024,m=["Bytes","KB","MB","GB"],f=Math.floor(Math.log(r)/Math.log(g));return parseFloat((r/Math.pow(g,f)).toFixed(2))+" "+m[f]};return e.jsx(be,{open:d,onOpenChange:G,children:e.jsxs(Ne,{className:"max-w-4xl max-h-[85vh] flex flex-col p-0 gap-0",children:[e.jsxs(we,{className:"px-6 py-4 border-b",children:[e.jsx(Ce,{children:"Seleccionar Recurso"}),e.jsx(ye,{children:"Sube o selecciona una imagen para insertar en tu newsletter."})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-6 space-y-6",children:[e.jsxs("div",{...C(),className:` 2 border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors 3 ${Q?"border-blue-500 bg-blue-50":"border-slate-300 hover:border-slate-400 bg-slate-50"} 4 ${w?"opacity-50 pointer-events-none":""} 5 `,children:[e.jsx("input",{...p()}),e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[w?e.jsx(Se,{className:"h-8 w-8 text-blue-500 animate-spin"}):e.jsx(Ye,{className:"h-8 w-8 text-slate-400"}),e.jsx("p",{className:"font-medium text-slate-900",children:w?"Subiendo...":"Arrastra imagen o pega (Ctrl+V)"})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(Ke,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-slate-500"}),e.jsx(he,{placeholder:"Buscar...",className:"pl-9",value:i,onChange:r=>B(r.target.value)})]}),R&&S.length===0?e.jsx("div",{className:"flex justify-center p-8",children:e.jsx(Se,{className:"h-8 w-8 animate-spin text-slate-400"})}):e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-4",children:A.map(r=>e.jsxs(je,{className:"cursor-pointer hover:ring-2 hover:ring-blue-500 transition-all group overflow-hidden",onClick:()=>h(r),children:[e.jsx("div",{className:"aspect-square bg-slate-100 relative flex items-center justify-center overflow-hidden",children:r.type==="image"?e.jsx("img",{src:r.url,alt:r.name,className:"object-cover w-full h-full group-hover:scale-105 transition-transform duration-300"}):e.jsx(Xe,{className:"h-10 w-10 text-slate-400"})}),e.jsxs(ve,{className:"p-2",children:[e.jsx("p",{className:"text-xs font-medium truncate",children:r.name}),e.jsxs("p",{className:"text-[10px] text-slate-500 mt-0.5",children:[P(r.size)," ⢠",Ns(r.createdAt,{addSuffix:!0,locale:rs})]})]})]},r.fullPath))}),!R&&A.length===0&&e.jsx("p",{className:"text-center text-slate-500 py-8",children:"No se encontraron archivos."})]})]})})}const ys=({newsletter:d,open:G,onOpenChange:q})=>
5{if(!d)return null;const S=d.content||"";return e.jsx(be,{open:G,onOpenChange:q,children:e.jsxs(Ne,{className:"max-w-5xl max-h-[90vh] overflow-hidden flex flex-col",children:[e.jsxs(we,{children:[e.jsxs(Ce,{children:["Vista Previa: ",d.subject||d.title]}),e.jsx(ye,{children:"Asà se verá el email en la bandeja de entrada de tus destinatarios"})]}),e.jsx("div",{className:"flex-1 overflow-auto bg-white",children:e.jsx("iframe",{srcDoc:S,className:"w-full h-full border-0",style:{minHeight:"700px"},title:"Newsletter Preview"})})]})})},Qe=ys;function Ss({newsletterId:d,initialCampaignId:G,onCancel:q,onSave:S}){const{user:D}=ls(),[A,L]=t.useState(""),[R,$]=t.useState(""),[w,v]=t.useState(""),[i,B]=t.useState("all_admins"),[b,z]=t.useState([]),[x,C]=t.useState(["admin","pastor"]),[p,Q]=t.useState(null),[h,P]=t.useState(!1),[r,g]=t.useState([]),[m,f]=t.useState([]),[I,y]=t.useState(""),[T,k]=t.useState(!1),[E,_]=t.useState(!1),[se,ae]=t.useState("content"),[le,Y]=t.useState(!1),[M,K]=t.useState(!1),[U,F]=t.useState(""),[O,te]=t.useState(!1),[xe,pe]=t.useState([]),[ie,ne]=t.useState(G||""),ge=a=>{if(M){const n=document.getElementById("html-editor");if(n&&(n.selectionStart||n.selectionStart===0)){const u=n.selectionStart,H=n.selectionEnd,X=U,oe=X.substring(0,u)+a+X.substring(H,X.length);F(oe)}else F(u=>u+a)}else{const n=`<img src="${a}" style="max-width: 100%;" />`;v(u=>u+n),l.success("Imagen insertada (Visual)")}};t.useEffect(()=>{Q(null)},[i,b,x]);const fe=async()=>{P(!0);try{const a=fs(),u=await js(a,"getAudiencePreview")({audienceType:i,targetRecipientListIds:i==="custom_list"&&I?[I]:[],targetChurchIds:i==="specific_churches"?b:[],targetRoles:i==="all_admins"||i==="specific_churches"?x:[]});Q(u.data),l.success("Estimación calculada")}catch(a){console.error("Error calculating audience:",a),l.error("Error calculando audiencia")}finally{P(!1)}};t.useEffect(()=>{ce()},[d]);const ce=async()=>{var a,n;k(!0);try{const[u,H,X]=await Promise.all([gs.getAllChurches({pageSize:1e3}),ps.getLists(),N.getCampaigns()]);f(H),pe(X);const oe=u,W=new Set,de=[];for(const o of oe.items)o.id&&!W.has(o.id)&&(W.add(o.id),de.push({id:o.id,name:o.name||"Sin nombre"}));if(g(de),d){const o=await N.getGlobalNewsletterById(d);o&&(L(o.title||""),$(o.subject||""),((a=o.content)==null?void 0:a.includes("<style>"))||((n=o.content)==null?void 0:n.includes("<!DOCTYPE"))?(K(!0),F(o.content||""),v("")):(K(!1),v(o.content||""),F("")),B(o.audienceType||"all_admins"),z(o.targetChurchIds||[]),C(o.targetRoles||["admin","pastor"]),ne(o.campaignId||""),o.targetRecipientListIds&&o.targetRecipientListIds.length>0&&y(o.targetRecipientListIds[0]))}}catch(u){console.error("Error loading editor data:",u),l.error("Error al cargar datos")}finally{k(!1)}},s=async()=>{if(!A||!R){l.error("TÃtulo y Asunto son requeridos");return}_(!0);try{const a={title:A,subject:R,content:M?U:w,audienceType:i,targetChurchIds:i==="specific_churches"?b:[],targetRecipientListIds:i==="custom_list"&&I?[I]:[],targetRoles:x,recipientSource:i==="custom_list"?"custom_list":"all",status:"draft",churchId:"global",campaignId:ie||null,createdBy:(D==null?void 0:D.uid)||"unknown"};d?(await N.updateGlobalNewsletter(d,a),l.success("Newsletter actualizado")):(await N.createGlobalNewsletter(a),l.success("Newsletter creado")),S()}catch(a){console.error("Error saving newsletter:",a),l.error("Error al guardar")}finally{_(!1)}};return T?e.jsxs("div",{className:"flex justify-center items-center h-64",children:[e.jsx(ee,{className:"h-8 w-8 animate-spin text-primary"}),e.jsx("p",{className:"ml-2",children:"Cargando..."})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs(je,{children:[e.jsx(Ae,{children:e.jsx(Le,{children:d?"Editar Comunicado Global":"Nuevo Comunicado Global"})}),e.jsxs(ve,{children:[e.jsxs(qe,{value:se,onValueChange:ae,className:"w-full",children:[e.jsxs(Ue,{className:"grid w-full grid-cols-2",children:[e.jsx(J,{value:"content",children:"Contenido"}),e.jsx(J,{value:"audience",children:"Audiencia"})]}),e.jsxs(Re,{value:"content",className:"space-y-4 pt-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{children:"TÃtulo Interno"}),e.jsx(he,{value:A,onChange:a=>L(a.target.value),placeholder:"Ej: Anuncio Mantenimiento Marzo"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{children:"Campaña (Opcional)"}),e.jsxs("select",{className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm r
5ing-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",value:ie,onChange:a=>ne(a.target.value),children:[e.jsx("option",{value:"",children:"Sin campaña"}),xe.map(a=>e.jsx("option",{value:a.id,children:a.name},a.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{children:"Asunto del Email"}),e.jsx(he,{value:R,onChange:a=>$(a.target.value),placeholder:"Ej: Importante: Actualización de Sistema"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{htmlFor:"content",children:"Contenido"}),e.jsxs("div",{className:"border rounded-md",style:{minHeight:"400px"},children:[M&&e.jsxs("div",{className:"mb-2 p-2 bg-blue-50 border border-blue-200 rounded text-sm",children:[e.jsx("strong",{children:"Modo Editor HTML:"})," Este newsletter usa HTML completo con estilos personalizados.",e.jsx(c,{variant:"link",size:"sm",onClick:()=>{confirm("¿Cambiar a editor visual? Se perderán los estilos personalizados.")&&(K(!1),v(U),F(""))},className:"ml-2",children:"Cambiar a Editor Visual"})]}),!M&&e.jsxs("div",{className:"mb-2 flex justify-between items-center",children:[e.jsxs(c,{variant:"outline",size:"sm",onClick:()=>{K(!0),F(w),v("")},children:[e.jsx(We,{className:"mr-2 h-4 w-4"}),"Cambiar a Editor HTML"]}),e.jsxs(c,{variant:"secondary",size:"sm",onClick:()=>te(!0),children:[e.jsx(Ee,{className:"mr-2 h-4 w-4"}),"Insertar Recurso"]})]}),M&&e.jsx("div",{className:"flex justify-end mb-2",children:e.jsxs(c,{variant:"secondary",size:"sm",onClick:()=>te(!0),children:[e.jsx(Ee,{className:"mr-2 h-4 w-4"}),"Insertar URL de Recurso"]})}),M?e.jsx("textarea",{id:"html-editor",value:U,onChange:a=>F(a.target.value),className:"w-full h-96 p-4 font-mono text-sm border rounded-lg focus:ring-2 focus:ring-blue-500",placeholder:"Ingresa tu HTML aquÃ...",spellCheck:!1}):e.jsx(bs,{value:w,onChange:v,placeholder:"Escriba su comunicado aquÃ...",height:"400px"})]})]})]}),e.jsxs(Re,{value:"audience",className:"space-y-4 pt-4",children:[e.jsxs(vs,{value:i,onValueChange:a=>B(a),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(ue,{value:"all_admins",id:"all_admins"}),e.jsx(j,{htmlFor:"all_admins",children:"Todos los Administradores de Iglesias (Recomendado)"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(ue,{value:"all_users",id:"all_users"}),e.jsx(j,{htmlFor:"all_users",children:"Todos los Usuarios (Precaución: Alto volumen)"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(ue,{value:"specific_churches",id:"specific_churches"}),e.jsx(j,{htmlFor:"specific_churches",children:"Iglesias EspecÃficas"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(ue,{value:"custom_list",id:"custom_list"}),e.jsx(j,{htmlFor:"custom_list",children:"Lista Personalizada (Externos)"})]})]}),i==="custom_list"&&e.jsxs("div",{className:"mt-4 p-4 border rounded-md bg-slate-50",children:[e.jsx(j,{className:"mb-2 block font-semibold",children:"Seleccionar Lista de Destinatarios"}),e.jsxs("select",{className:"w-full p-2 border rounded-md text-sm",value:I,onChange:a=>y(a.target.value),children:[e.jsx("option",{value:"",children:"Selecciona una lista..."}),m.map(a=>e.jsxs("option",{value:a.id,children:[a.name," (",a.recipientCount," miembros)"]},a.id))]}),m.length===0&&e.jsx("p",{className:"text-xs text-red-500 mt-2",children:'No hay listas creadas. Ve a "Listas de Destinatarios" para crear una.'})]}),(i==="all_admins"||i==="specific_churches")&&e.jsxs("div",{className:"mt-4 p-4 border rounded-md bg-gray-50",children:[e.jsx(j,{className:"mb-2 block font-semibold",children:"Roles Objetivo"}),e.jsx("div",{className:"flex gap-4 flex-wrap",children:["admin","pastor","editor","member"].map(a=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(ze,{id:`role-${a}`,checked:x.includes(a),onCheckedChange:n=>{C(n?[...x,a]:x.filter(u=>u!==a))}}),e.jsx(j,{htmlFor:`role-${a}`,className:"capitalize",children:a==="member"?"Miembro":a})]},a))}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:i==="all_admins"?"Selecciona qué roles administrativos recibirán el comunicado.":"Filtra destinatarios de
5ntro de las iglesias seleccionadas."})]}),i==="specific_churches"&&e.jsxs(je,{className:"mt-4",children:[e.jsx(Ae,{children:e.jsxs(Le,{className:"text-sm",children:["Seleccionar Iglesias (",b.length,")"]})}),e.jsx(ve,{children:e.jsx(is,{className:"h-[300px]",children:e.jsx("div",{className:"space-y-2",children:r.map(a=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(ze,{id:a.id,checked:b.includes(a.id),onCheckedChange:n=>{z(n?[...b,a.id]:b.filter(u=>u!==a.id))}}),e.jsx(j,{htmlFor:a.id,className:"text-sm cursor-pointer",children:a.name})]},a.id))})})})]}),e.jsxs("div",{className:"mt-6 border-t pt-4",children:[e.jsxs(c,{variant:"secondary",onClick:fe,disabled:h,className:"w-full sm:w-auto",children:[h&&e.jsx(ee,{className:"mr-2 h-4 w-4 animate-spin"}),"Calculary Previsualizar Audiencia"]}),p&&e.jsxs("div",{className:"mt-4 p-4 border rounded-md bg-green-50",children:[e.jsxs("p",{className:"font-semibold text-green-800",children:["Estimación de Destinatarios: ",p.count]}),p.sample&&p.sample.length>0&&e.jsxs("div",{className:"mt-2 text-sm text-green-700",children:[e.jsx("p",{className:"font-medium",children:"Muestra:"}),e.jsx("ul",{className:"list-disc list-inside",children:p.sample.map((a,n)=>e.jsxs("li",{children:[a.email," (",a.name,") - ",a.churchName]},n))}),p.count>p.sample.length&&e.jsxs("p",{className:"text-xs mt-1",children:["...y ",p.count-p.sample.length," más."]})]})]})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-6",children:[e.jsxs(c,{variant:"outline",onClick:()=>Y(!0),children:[e.jsx(Ve,{className:"mr-2 h-4 w-4"}),"Vista Previa"]}),e.jsx(c,{variant:"outline",onClick:q,disabled:E,children:"Cancelar"}),e.jsxs(c,{onClick:s,disabled:E,children:[E?e.jsx(ee,{className:"mr-2 h-4 w-4 animate-spin"}):null,"Guardar"]})]})]})]}),e.jsx(Qe,{newsletter:{title:A,subject:R,content:M?U:w},open:le,onOpenChange:Y}),e.jsx(Cs,{open:O,onOpenChange:te,onSelect:ge})]})}function Gs(){const d=as(),[G,q]=t.useState([]),[S,D]=t.useState("list"),[A,L]=t.useState(null),[R,$]=t.useState(!1),[w,v]=t.useState(null),[i,B]=t.useState(null),[b,z]=t.useState(null),[x,C]=t.useState(!1),[p,Q]=t.useState([]),[h,P]=t.useState("all"),[r,g]=t.useState("all"),[m,f]=t.useState(null),[I,y]=t.useState(!1),[T,k]=t.useState(null),[E,_]=t.useState(""),[se,ae]=t.useState("#3b82f6");t.useEffect(()=>{O(),Y()},[]);const le=async s=>{if(m)try{await N.updateGlobalNewsletter(m,{campaignId:s}),l.success("Newsletter movido de campaña"),O()}catch(a){console.error("Error moving newsletter",a),l.error("Error al mover newsletter")}finally{f(null)}},Y=async()=>{try{const s=await N.getCampaigns();Q(s)}catch(s){console.error("Error loading campaigns",s)}},M=async()=>{if(E.trim()){C(!0);try{T!=null&&T.id?(await N.updateCampaign(T.id,{name:E,color:se}),l.success("Campaña actualizada")):(await N.createCampaign({name:E,color:se}),l.success("Campaña creada")),y(!1),k(null),_(""),Y()}catch(s){console.error("Error saving campaign",s),l.error("Error al guardar campaña")}finally{C(!1)}}},K=async(s,a)=>{if(a.stopPropagation(),!!confirm("¿Eliminar esta campaña? Los newsletters no se borrarán, quedarán sin categorÃa."))try{await N.deleteCampaign(s),l.success("Campaña eliminada"),Y(),h===s&&P("all")}catch(n){console.error(n),l.error("Error al eliminar")}},U=()=>{k(null),_(""),ae("#3b82f6"),y(!0)},F=(s,a)=>{a.stopPropagation(),k(s),_(s.name),ae(s.color||"#3b82f6"),y(!0)},O=async()=>{$(!0);try{const s=await N.getGlobalNewsletters();q(s)}catch(s){console.error("Error loading newsletters:",s),l.error("Error al cargar newsletters")}finally{$(!1)}},te=()=>{L(null),D("create")},xe=s=>{L(s),D("edit")},pe=()=>{D("list"),O()},ie=async()=>{if(w){C(!0);try{await N.deleteGlobalNewsletter(w),l.success("Newsletter eliminado"),O()}catch(s){console.error("Error deleting:",s),l.error("Error al eliminar")}finally{C(!1),v(null)}}},ne=async s=>{try{const{id:a,createdAt:n,updatedAt:u,sentAt:H,stats:X,status:oe,...W}=s,de={...W,title:`${W.title} (Copia)`,subject:W.subject,status:"draft",campaignId:s.campaignId};await N.createGlobalNewsletter(de),l.success("Newsletter duplicado correctamente"),O()}catch(a){console.error("Error duplicating newsletter:",a),l.error("Error al duplicar el newsletter")}},ge=async()=>
5{if(i){C(!0);try{await N.sendGlobalNewsletter(i),l.success("EnvÃo iniciado correctamente"),O()}catch(s){console.error("Error sending:",s),l.error(s instanceof Error?s.message:"Error al iniciar el envÃo")}finally{C(!1),B(null)}}},fe=s=>{switch(s){case"sent":return e.jsx(re,{className:"bg-green-500",children:"Enviado"});case"sending":return e.jsx(re,{className:"bg-blue-500",children:"Enviando"});case"draft":return e.jsx(re,{variant:"secondary",children:"Borrador"});case"failed":return e.jsx(re,{variant:"destructive",children:"Fallido"});default:return e.jsx(re,{variant:"outline",children:s})}};if(S==="create"||S==="edit")return e.jsxs("div",{className:"container mx-auto p-6 max-w-[95%]",children:[e.jsx("div",{className:"flex justify-between items-center mb-6",children:e.jsx("h1",{className:"text-3xl font-bold",children:"Gestión de Comunicaciones Globales"})}),e.jsx(Ss,{newsletterId:A,initialCampaignId:h!=="all"&&h!=="uncategorized"?h:void 0,onCancel:()=>D("list"),onSave:pe})]});const ce=G.filter(s=>{const a=h==="all"?!0:h==="uncategorized"?!s.campaignId:s.campaignId===h,n=r==="all"?!0:r==="sent"?s.status==="sent"||s.status==="partially_sent":r==="draft"?s.status==="draft":r==="scheduled"?s.status==="scheduled"||s.status==="sending":!0;return a&&n});return e.jsxs("div",{className:"container mx-auto p-4 max-w-[95%] h-[calc(100vh-4rem)] flex flex-col",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6 shrink-0",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold tracking-tight",children:"Comunicaciones Globales"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Gestión de campañas y comunicados masivos."})]}),e.jsxs(c,{onClick:te,disabled:!1,children:[" ",e.jsx(De,{className:"mr-2 h-4 w-4"})," Nuevo Comunicado"]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-[260px_1fr] gap-6 grow overflow-hidden",children:[e.jsxs("div",{className:"flex flex-col gap-4 overflow-y-auto pr-2",children:[e.jsxs("div",{className:"flex items-center justify-between px-2",children:[e.jsx("span",{className:"text-sm font-semibold text-muted-foreground",children:"CAMPAÃAS"}),e.jsx(c,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:U,children:e.jsx(De,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs(c,{variant:h==="all"?"secondary":"ghost",className:`w-full justify-start ${m?"border-2 border-dashed border-transparent":""}`,onClick:()=>P("all"),children:[e.jsx(Ie,{className:"mr-2 h-4 w-4 text-muted-foreground"}),"Todas las campañas"]}),e.jsxs(c,{variant:h==="uncategorized"?"secondary":"ghost",className:`w-full justify-start transition-colors ${m?"border-2 border-dashed border-primary/50 bg-primary/5":""}`,onClick:()=>P("uncategorized"),onDragOver:s=>{s.preventDefault(),s.currentTarget.classList.add("bg-primary/20")},onDragLeave:s=>{s.currentTarget.classList.remove("bg-primary/20")},onDrop:s=>{s.preventDefault(),s.currentTarget.classList.remove("bg-primary/20"),le(null)},children:[e.jsx(Ie,{className:"mr-2 h-4 w-4 text-muted-foreground"}),"Sin campaña (Mover aquÃ)"]})]}),e.jsx("div",{className:"space-y-1 mt-2",children:p.map(s=>e.jsxs("div",{className:"group flex items-center relative",children:[e.jsxs(c,{variant:h===s.id?"secondary":"ghost",className:`w-full justify-start pr-8 transition-colors ${m?"border-2 border-dashed border-primary/50 bg-primary/5":""}`,onClick:()=>P(s.id),onDragOver:a=>{a.preventDefault(),a.currentTarget.classList.add("bg-primary/20")},onDragLeave:a=>{a.currentTarget.classList.remove("bg-primary/20")},onDrop:a=>{a.preventDefault(),a.currentTarget.classList.remove("bg-primary/20"),le(s.id)},children:[e.jsx("span",{className:"w-3 h-3 rounded-full mr-2 shrink-0",style:{backgroundColor:s.color}}),e.jsx("span",{className:"truncate",children:s.name})]}),e.jsxs(ns,{children:[e.jsx(cs,{asChild:!0,children:e.jsx(c,{variant:"ghost",size:"icon",className:"h-6 w-6 absolute right-1 opacity-0 group-hover:opacity-100 transition-opacity",children:e.jsx(Ze,{className:"h-3 w-3"})})}),e.jsxs(os,{align:"end",children:[e.jsxs(Pe,{onClick:a=>F(s,a),children:[e.jsx(Te,{className:"mr-2 h-4 w-4"})," Editar"]}),e.jsxs(Pe,{className:"text-destructive",onClick:a=>K(s.id,a),children:[e.jsx(ke,{className:"mr-2 h-4 w-4"})," Eliminar"]})]})]})]},s.id))})]}),e.jsxs("div",{className:"flex flex-col gap-4 overflow-hidden",children:[e.jsx("div",{className:"shrink-0",children:e.jsx(qe,{value:r,onValueChange:g,className:"w-full",children:e.jsxs(Ue,{children:[e.jsx(J,{value:"all",children:"Todos"}),e.jsx(J,{value:"draft",children:"Borradores"}),e.jsx(J,{value:"sent",children:"Enviados"}),e.jsx(J,{value:"scheduled",children:"Programados"})]})})}),e.jsx("div",{className:"border rounded-md grow overflow-y-auto bg-card",children:e.jsxs(ds,{children:[e.jsx(ms,{className:"sticky top-0 bg-card z-10",children:e.jsxs(me,{children:[e.jsx(Z,{children:"Asunto"}),e.jsx(Z,{children:"Campaña"}),e.jsx(Z,{children:"Estado"}),e.jsx(Z,{children:"Audiencia"}),e.jsx(Z,{children:"Fecha EnvÃo"}),e.jsx(Z,{className:"text-right",children:"Acciones"})]})}),e.jsx(us,{children:R?e.jsx(me,{children:e.jsx(V,{colSpan:6,className:"text-center h-24",children:e.jsx(ee,{className:"mx-auto h-6 w-6 animate-spin text-muted-foreground"})})}):ce.length===0?e.jsx(me,{children:e.jsx(V,{colSpan:6,className:"text-center h-24 text-muted-foreground",children:"No hay comunicaciones en esta vista."})}):ce.map(s=>{var n,u;const a=p.find(H=>H.id===s.campaignId);return e.jsxs(me,{draggable:!0,onDragStart:H=>{f(s.id),H.dataTransfer.setData("text/plain",s.id),H.dataTransfer.effectAllowed="move"},onDragEnd:()=>f(null),className:m===s.id?"opacity-50 bg-muted/50 cursor-grabbing":"cursor-grab hover:bg-muted/30",children:[e.jsx(V,{className:"font-medium",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:s.subject}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s.title})]})}),e.jsx(V,{children:a?e.jsxs("div",{className:"flex items-center text-xs px-2 py-1 rounded-full bg-secondary w-fit",children:[e.jsx("span",{className:"w-2 h-2 rounded-full mr-2",style:{backgroundColor:a.color}}),a.name]}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"-"})}),e.jsx(V,{children:fe(s.status)}),e.jsx(V,{className:"text-xs",children:s.audienceType==="all_admins"?`Todos (${((n=s.targetRoles)==null?void 0:n.join(", "))||"admins"})`:s.audienceType==="specific_churches"?`${((u=s.targetChurchIds)==null?void 0:u.length)||0} iglesia(s)`:"Personalizado"}),e.jsx(V,{children:s.sentAt?ws(s.sentAt.toDate(),"dd/MM/yyyy HH:mm"):"-"}),e.jsxs(V,{className:"text-right space-x-1",children:[(s.status==="draft"||s.status==="failed")&&e.jsxs(e.Fragment,{children:[e.jsx(c,{variant:"ghost",size:"icon",onClick:()=>xe(s.id),children:e.jsx(Te,{className:"h-4 w-4"})}),e.jsx(c,{variant:"ghost",size:"icon",onClick:()=>B(s.id),className:"text-blue-600 hover:text-blue-700",children:e.jsx(Je,{className:"h-4 w-4"})})]}),(s.status==="sent"||s.status==="partially_sent")&&e.jsxs(e.Fragment,{children:[e.jsx(c,{variant:"ghost",size:"icon",onClick:()=>ne(s),title:"Duplicar",children:e.jsx(es,{className:"h-4 w-4"})}),e.jsx(c,{variant:"ghost",size:"icon",onClick:()=>d(`/admin/newsletters/${s.id}/stats`),className:"text-purple-600 hover:text-purple-700",title:"Ver AnalÃticas",children:e.jsx(ss,{className:"h-4 w-4"})})]}),e.jsx(c,{variant:"ghost",size:"icon",onClick:()=>z(s),className:"text-blue-600 hover:text-blue-700",title:"Vista Previa",children:e.jsx(Ve,{className:"h-4 w-4"})}),e.jsx(c,{variant:"ghost",size:"icon",onClick:()=>v(s.id),className:"text-destructive hover:text-destructive/90",children:e.jsx(ke,{className:"h-4 w-4"})})]})]},s.id)})})]})})]})]}),e.jsx(be,{open:I,onOpenChange:y,children:e.jsxs(Ne,{children:[e.jsxs(we,{children:[e.jsx(Ce,{children:T?"Editar Campaña":"Nueva Campaña"}),e.jsx(ye,{children:"Agrupa tus newsletters por proyectos o temas."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{children:"Nombre de la campaña"}),e.jsx(he,{value:E,onChange:s=>_(s.target.value),placeholder:"Ej: Onboarding Nuevos Usuarios"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{children:"Color Identificativo"}),e.jsx("div",{className:"flex gap-2",children:["#3b82f6","#ef4444","#10b981","#f59e0b","#8b5cf6","#ec4899","#6366f1"].map(s=>e.jsx("button",{className:`w-8 h-8 rounded-full border-2 ${se===s?"border-black":"border-transparent"}`,style:{backgroundColor:s},onClick:()=>ae(s)},s))})]})]}),e.jsxs(hs,{children:[e.jsx(c,{variant:"outline",onClick:()=>y(!1),children:"Cancelar"}),e.jsx(c,{onClick:M,disabled:!E.trim()||x,children:x?e.jsx(ee,{className:"animate-spin h-4 w-4"}):"Guardar"})]})]})}),e.jsx(_e,{open:!!w,onOpenChange:s=>!s&&v(null),children:e.jsxs(Me,{"aria-describedby":"delete-description",children:[e.jsxs(Fe,{children:[e.jsx(He,{children:"¿Eliminar comunicado?"}),e.jsx(Ge,{id:"delete-description",children:"Esta acción no se puede deshacer."})]}),e.jsxs($e,{children:[e.jsx(Be,{children:"Cancelar"}),e.jsx(xs,{onClick:ie,className:"bg-destructive",disabled:x,children:x?"Eliminando...":"Eliminar"})]})]})}),e.jsx(_e,{open:!!i,onOpenChange:s=>!s&&B(null),children:e.jsxs(Me,{"aria-describedby":"send-description",children:[e.jsxs(Fe,{children:[e.jsx(He,{children:"¿Enviar comunicado masivo?"}),e.jsx(Ge,{id:"send-description",children:"Se enviará este correo a la audiencia seleccionad
5a. Asegúrate de que el contenido sea correcto."})]}),e.jsxs($e,{children:[e.jsx(Be,{disabled:x,children:"Cancelar"}),e.jsx(c,{onClick:s=>{s.preventDefault(),ge()},disabled:x,className:"bg-primary text-primary-foreground hover:bg-primary/90",children:x?e.jsxs(e.Fragment,{children:[e.jsx(ee,{className:"mr-2 h-4 w-4 animate-spin"}),"Enviando..."]}):"Enviar Ahora"})]})]})}),e.jsx(Qe,{newsletter:b,open:!!b,onOpenChange:s=>!s&&z(null)})]})}export{Gs as default};
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.