1import{ak as A,r as t,K as y,j as e,ao as Qe,ap as ze,aq as Oe,ar as Te,g as Fe,a6 as $e,z as R,X as Be,D as L,p as Re,c as ue,l as X,aL as Ke,c2 as He,at as be,y as v,U as Ie,F as Ve,u as G,E as J,b as Ue,S as he,T as Ge,J as Je,aj as Xe}from"./index-CnCJxQdF.js";import{W as Y}from"./channelConfig-BN72e-Rv.js";import{u as Ye}from"./useMutation-BLdTeo2I.js";import{o as Ze,i as es,t as ge}from"./massBroadcastOptions-D9eKk7wh.js";import{B as ss,W as as,u as ts,a as ns,b as rs}from"./useBroadcastActions-DYpf3AZs.js";import{E as is}from"./eye-CgnyzcaQ.js";import{I as ls}from"./info-vsGEV1Yh.js";import{B as os}from"./BroadcastPaymentNotice-BZUZ7CTD.js";import{W as cs}from"./WhatsAppPaymentSetupNotice-uEei9Kb9.js";import{P as ds}from"./plus-DWmrtCpE.js";import{H as ms}from"./history-B-izEQFJ.js";import"./sourceOptions-D3hWObK1.js";import"./alert-dialog-Dy9lW_5T.js";import"./trash-2-su6ZzX0s.js";import"./chevron-up-jeRhXS2F.js";const ps=1440*60*1e3;function xs(b,o){const g=A({queryKey:["mass-leads",o],queryFn:()=>y.entities.Lead.filter(b,"-created_date",1e3),enabled:!!o}),h=A({queryKey:["mass-quotes",o],queryFn:()=>y.entities.Quote.filter(b,"-created_date",500),enabled:!!o,select:n=>new Set(n.map(u=>u.lead_id).filter(Boolean))}),m=A({queryKey:["mass-appointments",o],queryFn:()=>y.entities.Appointment.filter(b,"-created_date",500),enabled:!!o,select:n=>new Set(n.map(u=>u.lead_id).filter(Boolean))}),r=A({queryKey:["mass-pipelines",o],queryFn:()=>y.entities.Pipeline.filter(b,"-created_date",50),enabled:!!o}),f=A({queryKey:["mass-sellers",o],queryFn:()=>y.entities.SellerProfile.filter(b,"-created_date",200),enabled:!!o}),N=A({queryKey:["mass-conversations",o],queryFn:()=>y.entities.Conversation.filter(b,"-updated_date",1e3),enabled:!!o}),x=t.useMemo(()=>{const n=[];return(r.data||[]).forEach(u=>{(u.stages||[]).forEach(l=>n.push({id:l.id,name:l.name,pipelineName:u.name}))}),n},[r.data]),p=t.useMemo(()=>{const n=new Map,u=Date.now();return(N.data||[]).forEach(l=>{if(!l.lead_id)return;const c=l.last_message_at?new Date(l.last_message_at).getTime():0,a=c>0&&u-c<ps,d=n.get(l.lead_id);(!d||c>d.lastAt)&&n.set(l.lead_id,{open:a,lastAt:c})}),n},[N.data]),j=n=>{const u=h.data||new Set,l=m.data||new Set;return(g.data||[]).filter(c=>{if(n.stage&&c.stage!==n.stage||n.interestLevel&&c.interest_level!==n.interestLevel)return!1;if(n.sellerEmail){if(n.sellerEmail==="__unassigned__"){if(c.assigned_to)return!1}else if(c.assigned_to!==n.sellerEmail)return!1}if(n.marketingSource&&c.marketing_source!==n.marketingSource||n.hasQuote==="yes"&&!u.has(c.id)||n.hasQuote==="no"&&u.has(c.id)||n.hasAppointment==="yes"&&!l.has(c.id)||n.hasAppointment==="no"&&l.has(c.id))return!1;if(n.conversationWindow){const a=p.get(c.id);if(n.conversationWindow==="open"&&!(a&&a.open)||n.conversationWindow==="closed"&&a&&a.open)return!1}return!0})};return{isLoading:g.isLoading||h.isLoading||m.isLoading,leads:g.data||[],stages:x,sellers:f.data||[],applyFilters:j,convWindowByLead:p}}function us({open:b,onOpenChange:o,leads:g=[],convWindowByLead:h,selectedIds:m=[],onChange:r}){const[f,N]=t.useState(""),x=t.useMemo(()=>g.filter(a=>(a.phone||"").toString().trim()),[g]),p=t.useMemo(()=>{const a=f.trim().toLowerCase();return a?x.filter(d=>(d.full_name||d.name||"").toLowerCase().includes(a)||(d.phone||"").toString().includes(a)):x},[x,f]),j=t.useMemo(()=>new Set(m),[m]),n=p.length>0&&p.every(a=>j.has(a.id)),u=a=>{r(j.has(a)?m.filter(d=>d!==a):[...m,a])},l=()=>{if(n){const a=new Set(p.map(d=>d.id));r(m.filter(d=>!a.has(d)))}else{const a=new Set([...m,...p.map(d=>d.id)]);r([...a])}},c=()=>r([]);return e.jsx(Qe,{open:b,onOpenChange:o,children:e.jsxs(ze,{className:"max-w-lg left-0 top-0 translate-x-0 translate-y-0 w-full h-[100dvh] max-h-[100dvh] rounded-none p-0 gap-0 flex flex-col overflow-hidden sm:left-[50%] sm:top-[50%] sm:translate-x-[-50%] sm:translate-y-[-50%] sm:w-[calc(100%-2rem)] sm:h-auto sm:max-h-[85vh] sm:rou
1nded-lg sm:p-6 sm:gap-4 safe-area-inset-top",children:[e.jsxs(Oe,{className:"shrink-0 px-4 pt-4 sm:pt-0 sm:px-0 pb-3 border-b border-border/60 sm:border-0",children:[e.jsxs(Te,{className:"flex items-center gap-2 text-base sm:text-lg",children:[e.jsx(Fe,{className:"w-5 h-5 text-primary"})," Seleccionar clientes especÃficos"]}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground mt-1",children:"Elige a quién enviar la difusión. Solo verás contactos con WhatsApp."})]}),e.jsxs("div",{className:"shrink-0 px-4 sm:px-0 py-2 space-y-2 border-b border-border/40 sm:border-0",children:[e.jsxs("div",{className:"relative",children:[e.jsx($e,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(R,{value:f,onChange:a=>N(a.target.value),placeholder:"Buscar por nombre o teléfonoâ¦",className:"pl-8 h-9 text-base sm:text-sm"}),f&&e.jsx("button",{onClick:()=>N(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:e.jsx(Be,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:[p.length," de ",x.length," contactos · ",m.length," seleccionados"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(L,{size:"sm",variant:"ghost",className:"h-7 text-xs",onClick:l,disabled:p.length===0,children:n?"Quitar visibles":"Marcar visibles"}),e.jsx(L,{size:"sm",variant:"ghost",className:"h-7 text-xs",onClick:c,disabled:m.length===0,children:"Limpiar"})]})]})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto overscroll-contain px-2 sm:px-0 py-2",children:p.length===0?e.jsx("div",{className:"text-center py-10 text-sm text-muted-foreground",children:x.length===0?"No tienes contactos con WhatsApp todavÃa.":"Sin resultados para tu búsqueda."}):e.jsx("ul",{className:"space-y-1",children:p.map(a=>{var O;const d=j.has(a.id),W=(O=h==null?void 0:h.get(a.id))==null?void 0:O.open;return e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>u(a.id),className:ue("w-full text-left rounded-xl border p-2.5 flex items-center gap-2.5 transition active:scale-[0.99]",d?"border-primary bg-primary/5":"border-border hover:bg-secondary/50"),children:[e.jsx("span",{className:ue("w-5 h-5 rounded-md border flex items-center justify-center shrink-0",d?"bg-primary border-primary":"border-input"),children:d&&e.jsx(Re,{className:"w-3.5 h-3.5 text-primary-foreground"})}),e.jsx("span",{className:"w-9 h-9 rounded-full bg-secondary flex items-center justify-center shrink-0 overflow-hidden",children:e.jsx(Y,{size:18})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-sm font-medium truncate",children:a.full_name||a.name||"Sin nombre"}),W&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[10px] text-emerald-600 dark:text-emerald-400 shrink-0",children:[e.jsx(X,{className:"w-2.5 h-2.5"})," 24h"]})]}),e.jsx("span",{className:"text-xs text-muted-foreground block truncate",children:a.phone})]})]})},a.id)})})}),e.jsxs(Ke,{className:"shrink-0 flex-row gap-2 px-4 py-3 border-t border-border/60 bg-background safe-area-inset-bottom sm:border-0 sm:px-0 sm:py-0 sm:bg-transparent",children:[e.jsx(L,{type:"button",variant:"outline",className:"flex-1 sm:flex-none h-10",onClick:()=>o(!1),children:"Cerrar"}),e.jsxs(L,{type:"button",className:"flex-1 sm:flex-none h-10 gap-1.5",onClick:()=>o(!1),disabled:m.length===0,children:[e.jsx(He,{className:"w-4 h-4"})," ",m.length>0?`Listo · ${m.length} seleccionados`:"Selecciona al menos uno"]})]})]})})}const M="w-full h-9 rounded-md border border-input bg-transparent px-2 text-sm focus:outline-none focus:ring-1 focus:ring-ring";function hs({onSubmit:b,submitting:o}){var pe;const{workspaceFilter:g,workspaceId:h}=be(),{isLoading:m,stages:r,sellers:f,applyFilters:N,convWindowByLead:x,leads:p}=xs(g,h),{data:j=[]}=A({queryKey:["broadcast-whatsapp-connections",h],queryFn:()=>y.entities.ChannelConnection.filter(g,"-updated_date",50),enabled:!!h,select:s=>s.filter(i=>i.channel_type==="whatsapp"&&i.provider==="meta"&&["connected","active"].includes(i.status))}),[n,u]=t.useState(""),l=n||((pe=j.find(s=>s.is_primary)||j[0])==null?void 0:pe.id)||"",{data:c=[]}=A({queryKey:["broadcast-approved-templates",l],queryFn:()=>
1y.entities.WhatsAppTemplate.filter({channel_connection_id:l,status:"approved"},"-updated_date",100),enabled:!!l,select:s=>(s||[]).filter(i=>!(i.variables||[]).length)}),[a,d]=t.useState(""),[W,O]=t.useState(""),[K,fe]=t.useState(""),[H,je]=t.useState(""),[I,ve]=t.useState(""),[V,Ne]=t.useState("all"),[U,ye]=t.useState("all"),[P,Z]=t.useState("all"),[we,ee]=t.useState(!1),[Se,se]=t.useState(!1),[_e,ae]=t.useState(!1),[Q,te]=t.useState("filters"),[S,Ce]=t.useState([]),[E,ne]=t.useState("now"),[z,ke]=t.useState(""),[_,re]=t.useState("template"),[T,Me]=t.useState(""),[F,ie]=t.useState(""),[le,Ae]=t.useState(""),[$,oe]=t.useState(!1),ce={marketingSource:W,stage:K,interestLevel:H,sellerEmail:I,hasQuote:V,hasAppointment:U,conversationWindow:""},Ee=t.useMemo(()=>N(ce),[N,W,K,H,I,V,U]),qe=t.useMemo(()=>{const s=new Set(S);return p.filter(i=>s.has(i.id))},[p,S]),B=Q==="specific"?qe:Ee,w=t.useMemo(()=>{const s=B.filter(i=>(i.phone||"").toString().trim());return P==="open"?s.filter(i=>{var k;return(k=x.get(i.id))==null?void 0:k.open}):s},[B,x,P]),q=t.useMemo(()=>{const s=B.filter(D=>(D.phone||"").toString().trim());let i=0,k=0;return s.forEach(D=>{var xe;(xe=x.get(D.id))!=null&&xe.open?i++:k++}),{open:i,closed:k}},[B,x]),De=t.useMemo(()=>{const s=new Map;return p.forEach(i=>{i.stage&&s.set(i.stage,(s.get(i.stage)||0)+1)}),s},[p]),C=c.find(s=>s.id===T),Le=Ye({mutationFn:async s=>await y.integrations.Core.InvokeLLM({prompt:`Redacta un mensaje de WhatsApp de difusión masiva en español mexicano, cálido y profesional, máximo 350 caracteres, sin emojis excesivos (máximo 2). Objetivo: ${s}. Audiencia: ${w.length} contactos. NO uses variables de personalización ({nombre}, {telefono}, {email}, {empresa}, {ciudad}): Meta rechaza las plantillas con variables. Escribe un mensaje genérico sin variables. Responde solo con el mensaje.`})}),Pe=async()=>{oe(!0);try{const s=await Le.mutateAsync(le.trim()||"Recordar mi servicio e invitar a responder si interesa");ie(typeof s=="string"?s:(s==null?void 0:s.text)||(s==null?void 0:s.response)||"")}catch{}finally{oe(!1)}},de=E==="now"||!!z&&new Date(z).getTime()>Date.now()+6e4,me=!o&&l&&w.length>0&&a.trim()&&(_==="template"?!!T:F.trim().length>0)&&de,We=()=>{var i,k;if(!me)return;const s=Q==="specific"?{mode:"specific",selected_lead_ids:S}:{mode:"filters",...ce};b({name:a.trim(),channel_connection_id:l,channel_phone:((i=j.find(D=>D.id===l))==null?void 0:i.display_phone_number)||((k=j.find(D=>D.id===l))==null?void 0:k.phone_number)||"",message_type:_,template_key:_==="template"?C==null?void 0:C.internal_key:"",template_instance_id:_==="template"?T:"",message_body:_==="template"?(C==null?void 0:C.content)||"":F,audience_filters:s,recipient_count:w.length,window_open_count:q.open,window_closed_count:q.closed,window_target:P,scheduled_send_at:E==="later"?new Date(z).toISOString():""})};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("section",{className:"space-y-2",children:[e.jsx(v,{className:"text-xs font-semibold",children:"¿Con qué número de WhatsApp enviamos el mensaje?"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-8 h-8 rounded-lg bg-[#25D366]/10 flex items-center justify-center shrink-0",children:e.jsx(Y,{size:20})}),e.jsxs("select",{className:M,value:l,onChange:s=>u(s.target.value),children:[j.length===0&&e.jsx("option",{value:"",children:"Sin números conectados"}),j.map(s=>e.jsxs("option",{value:s.id,children:[s.display_phone_number||s.phone_number||"Número",s.is_primary?" (principal)":"",s.label?` · ${s.label}`:""]},s.id))]})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx(v,{className:"text-xs font-semibold",children:"Nombre de esta difusión"}),e.jsx(R,{className:"h-9 text-sm",placeholder:"ej. Reactivación de clientes inactivos",value:a,onChange:s=>d(s.target.value)})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold",children:[e.jsx(Ie,{className:"w-4 h-4 text-primary"})," Audiencia"]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("button",{onClick:()=>te("filters"),className:`rounded-xl border p-3 text-left transition ${Q==="filters"?"border-primary bg-primary/5":"border-input hover:bg-accent"}`,children:[e.jsxs("p",{className:"text-sm font-semibold flex items-center gap-1.5",children:[e.jsx(Ve,{className:"w-4 h-4"})," Filtrar audiencia"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Por origen, etapa, interésâ¦"})]}),e.jsxs("button",{onClick:()=>te("specific"),className:`rounded-xl border p-3 text-left transition ${Q==="specific"?"border-primary bg-primary/5":"border-input hover:bg-accent"}`,children:[e.jsxs("p",{className:"text-sm font-semibold flex items-center gap-1.5",children:[e.jsx(G,{className:"w-4 h-4"})," Seleccionar clientes especÃficos"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Elige conversaciones una por una"})]})]}),Q==="filters"?e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(v,{className:"text-xs",children:"Origen del contacto"}),e.jsx("select",{className:M,value:W,onChange:s=>O(s.target.value),children:Ze.map(s=>e.jsx("option",{value:s.value,children:s.label},s.value))})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(v,{className:"text-xs",children:"Etapa del embudo (con contactos)"}),e.jsxs("select",{className:M,value:K,onChange:s=>fe(s.target.value),children:[e.jsx("option",{value:"",children:"Todas las etapas"}),r.map(s=>e.jsxs("option",{value:s.id,children:[s.name," · ",s.pipelineName," (",De.get(s.id)||0,")"]},s.id))]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(v,{className:"text-xs",children:"Nivel de interés"}),e.jsx("select",{className:M,value:H,onChange:s=>je(s.target.value),children:es.map(s=>e.jsx("option",{value:s.value,children:s.label},s.value))})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(v,{className:"text-xs",children:"Vendedor asignado"}),e.jsxs("select",{className:M,value:I,onChange:s=>ve(s.target.value),children:[e.jsx("option",{value:"",children:"Todos"}),e.jsx("option",{value:"__unassigned__",children:"Sin asignar"}),f.map(s=>e.jsx("option",{value:s.email,children:s.full_name},s.id))]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(v,{className:"text-xs",children:"¿Tiene cotización?"}),e.jsx("select",{className:M,value:V,onChange:s=>Ne(s.target.value),children:ge.map(s=>e.jsx("option",{value:s.value,children:s.label},s.value))})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(v,{className:"text-xs",children:"¿Tiene cita agendada?"}),e.jsx("select",{className:M,value:U,onChange:s=>ye(s.target.value),children:ge.map(s=>e.jsx("option",{value:s.value,children:s.label},s.value))})]})]}):e.jsxs("div",{className:"rounded-xl border border-input p-3 space-y-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(G,{className:"w-4 h-4 text-primary"}),e.jsxs("span",{children:[S.length>0?e.jsx("span",{className:"font-semibold text-primary",children:S.length}):"Sin"," clientes seleccionados"]})]}),e.jsxs(L,{size:"sm",variant:"outline",onClick:()=>ae(!0),className:"gap-1.5",children:[e.jsx(G,{className:"w-3.5 h-3.5"}
1)," ",S.length>0?"Editar selección":"Elegir clientes"]})]}),S.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Abre la lista de conversaciones y marca a quién enviar la difusión."})]}),e.jsx("div",{className:"rounded-xl bg-primary/5 border border-primary/20 px-3 py-2.5 space-y-1",children:e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[m?e.jsx(J,{className:"w-4 h-4 animate-spin text-primary"}):e.jsx(Ue,{className:"w-4 h-4 text-primary"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-bold text-primary",children:w.length})," contactos con WhatsApp cumplirán los filtros"]}),e.jsxs("button",{onClick:()=>se(!0),disabled:m||w.length===0,className:"ml-auto inline-flex items-center gap-1 text-xs text-primary hover:underline disabled:opacity-50",children:[e.jsx(is,{className:"w-3.5 h-3.5"})," Ver lista"]})]})})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(v,{className:"text-xs font-semibold",children:"Ventana de 24 horas"}),e.jsxs("button",{onClick:()=>ee(!0),className:"inline-flex items-center gap-1 text-xs text-primary hover:underline",children:[e.jsx(ls,{className:"w-3.5 h-3.5"})," Más información"]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("button",{onClick:()=>Z("all"),className:`rounded-xl border p-3 text-left transition ${P==="all"?"border-primary bg-primary/5":"border-input hover:bg-accent"}`,children:[e.jsx("p",{className:"text-sm font-semibold",children:"A todos"}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:[q.open," abierta · ",q.closed," cerrada"]})]}),e.jsxs("button",{onClick:()=>Z("open"),className:`rounded-xl border p-3 text-left transition ${P==="open"?"border-primary bg-primary/5":"border-input hover:bg-accent"}`,children:[e.jsx("p",{className:"text-sm font-semibold",children:"Solo ventana abierta"}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:[q.open," contactos"]})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:P==="all"?"Todos los contactos recibirán la plantilla aprobada, que funciona tanto para ventanas abiertas como cerradas.":"Solo se enviará a contactos que escribieron en las últimas 24h (ventana abierta)."})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold",children:[e.jsx(he,{className:"w-4 h-4 text-primary"})," Mensaje"]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("button",{onClick:()=>re("template"),className:`rounded-xl border p-3 text-left transition ${_==="template"?"border-primary bg-primary/5":"border-input hover:bg-accent"}`,children:[e.jsx("p",{className:"text-sm font-semibold",children:"Plantilla aprobada"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Elige una ya aprobada por Meta"})]}),e.jsxs("button",{onClick:()=>re("custom"),className:`rounded-xl border p-3 text-left transition ${_==="custom"?"border-primary bg-primary/5":"border-input hover:bg-accent"}`,children:[e.jsx("p",{className:"text-sm font-semibold",children:"Escribir mi mensaje"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Se somete a aprobación de Meta"})]})]}),_==="template"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{className:"text-xs",children:"Plantilla aprobada"}),e.jsxs("select",{className:M,value:T,onChange:s=>Me(s.target.value),children:[e.jsx("option",{value:"",children:"Selecciona una plantillaâ¦"}),c.length===0&&e.jsx("option",{value:"",disabled:!0,children:"No tienes plantillas aprobadas todavÃa"}),c.map(s=>e.jsx("option",{value:s.id,children:s.name},s.id))]}),C&&e.jsx("div",{className:"rounded-xl border bg-muted/30 p-3 text-sm whitespace-pre-wrap",children:C.content}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Las plantillas se envÃan tal cual Meta las aprobó (con variables ya resueltas)."})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{className:"text-xs",children:"¿Qué quieres lograr? (opcional)"}),e.jsx(R,{className:"h-9 text-sm",placeholder:"ej. Invitar a una cita, recordar ofertaâ¦",value:le,onChange:s=>Ae(s.target.value),disabled:$}),e.jsxs(L,{size:"sm",variant:"outline",onClick:Pe,disabled:$||w.length===0,className:"gap-2",children:[$?e.jsx(J,{className:"w-4 h-4 animate-spin"}):e.jsx(he,{className:"w-4 h-4"})," Generar con IA"]}),e.jsx(Ge,{rows:5,value:F,onChange:s=>ie(s.target.value),placeholder:"Escribe tu mensaje. No uses variables de personalización ({nombre}, etc.): Meta las rechaza.",disabled:$}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[F.length," caracteres"]}),e.jsx("div",{className:"rounded-xl border border-amber-200 bg-amber-50 dark:bg-amber-900/20 p-3 text-xs text-amber-700 dark:text-amber-300",children:"Al enviar, este mensaje se somete a aprobación de Meta (promedio de unas horas). Una vez aprobado, se envÃa automáticamente a tu audiencia."})]})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold",children:[e.jsx(X,{className:"w-4 h-4 text-primary"}
1)," ¿Cuándo enviar?"]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("button",{onClick:()=>ne("now"),className:`rounded-xl border p-3 text-left transition ${E==="now"?"border-primary bg-primary/5":"border-input hover:bg-accent"}`,children:[e.jsx("p",{className:"text-sm font-semibold",children:"Ahora mismo"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Se envÃa en cuanto esté listo"})]}),e.jsxs("button",{onClick:()=>ne("later"),className:`rounded-xl border p-3 text-left transition ${E==="later"?"border-primary bg-primary/5":"border-input hover:bg-accent"}`,children:[e.jsx("p",{className:"text-sm font-semibold",children:"Programar"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Mandar más tarde"})]})]}),E==="later"&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(v,{className:"text-xs",children:"Fecha y hora de envÃo"}),e.jsx(R,{type:"datetime-local",className:"h-9 text-sm",value:z,onChange:s=>ke(s.target.value),min:new Date(Date.now()+6e4).toISOString().slice(0,16)}),z&&!de&&e.jsx("p",{className:"text-xs text-red-500",children:"Elige una fecha al menos un minuto en el futuro."})]})]}),e.jsx("div",{className:"flex items-center justify-end gap-2 pt-2 border-t",children:e.jsxs(L,{onClick:We,disabled:!me,className:"gap-2",children:[o?e.jsx(J,{className:"w-4 h-4 animate-spin"}):E==="later"?e.jsx(X,{className:"w-4 h-4"}):e.jsx(Je,{className:"w-4 h-4"}),E==="later"?"Programar envÃo":"Enviar"," a ",w.length]})}),e.jsx(ss,{open:Se,onOpenChange:se,recipients:w.map(s=>{var i;return{name:s.full_name||s.name||"Sin nombre",phone:s.phone,window_open:(i=x.get(s.id))==null?void 0:i.open}}),count:w.length,windowOpen:q.open,windowClosed:q.closed}),e.jsx(us,{open:_e,onOpenChange:ae,leads:p,convWindowByLead:x,selectedIds:S,onChange:Ce}),e.jsx(as,{open:we,onOpenChange:ee})]})}function qs(){const{workspaceId:b}=be(),o=Xe(),[g,h]=t.useState("new"),r=ts({invoke:(f,N={})=>y.functions.invoke("manageBroadcast",{action:f,...N}).then(x=>x.data),onChanged:()=>o.invalidateQueries({queryKey:["whatsapp-broadcasts",b]}),onDone:()=>h("history")});return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-11 h-11 rounded-2xl bg-gradient-to-br from-[#25D366] to-[#128C7E] flex items-center justify-center shrink-0 shadow-md",children:e.jsx(Y,{size:26})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl sm:text-2xl font-bold tracking-tight",children:"Difusión Masiva por WhatsApp"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Crea campañas, filtra tu audiencia y haz seguimiento masivo con plantillas aprobadas."})]})]}),e.jsx(cs,{}),r.paymentAlert&&e.jsx(os,{billingUrl:r.paymentAlert.meta_billing_url,message:r.paymentAlert.message,onDismiss:()=>r.setPaymentAlert(null)}),e.jsxs("div",{className:"flex items-center gap-2 border-b",children:[e.jsxs("button",{onClick:()=>h("new"),className:`inline-flex items-center gap-1.5 px-4 py-2 text-sm font-medium border-b-2 -mb-px transition ${g==="new"?"border-primary text-primary":"border-transparent text-muted-foreground hover:text-foreground"}`,children:[e.jsx(ds,{className:"w-4 h-4"})," Nueva difusión"]}),e.jsxs("button",{onClick:()=>h("history"),className:`inline-flex items-center gap-1.5 px-4 py-2 text-sm font-medium border-b-2 -mb-px transition ${g==="history"?"border-primary text-primary":"border-transparent text-muted-foreground hover:text-foreground"}`,children:[e.jsx(ms,{className:"w-4 h-4"})," Historial"]})]}),e.jsx("div",{className:"max-w-3xl",children:g==="new"?e.jsx(hs,{onSubmit:r.handleCreate,submitting:r.submitting}):e.jsx(ns,{onRetry:r.handleRetry,onEdit:r.setEditing,onDelete:r.handleDelete,retrying:r.submitting,deletingId:r.deletingId})}),e.jsx(rs,{broadcast:r.editing,open:!!r.editing,onOpenChange:f=>!f&&r.setEditing(null),onConfirm:r.handleEditResend,submitting:r.submitting})]})}export{qs 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.