PageSourceSearch

https://atzuma.co.il/assets/ScheduledCampaigns-Z1F5i11J.js

js atzuma.co.il collected 2026-09-24 21:10:47 UTC 93,096 bytes, 2 lines download raw bytes

1import{j as e}from"./index-BtgGoHYl.js";import{u as $t,r as s}from"./router-BXL9ASSk.js";import{h as Ot}from"./httpClient-B4llTHmd.js";import"./vendor-BNcAc9ko.js";import"./index-BqDtoUCL.js";(function(){try{var d=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};d.SENTRY_RELEASE={id:"[email protected]"}}catch{}})();try{(function(){var d=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},b=new d.Error().stack;b&&(d._sentryDebugIds=d._sentryDebugIds||{},d._sentryDebugIds[b]="d8ca3a75-29a7-4d9a-991e-94d28f7cd938",d._sentryDebugIdIdentifier="sentry-dbid-d8ca3a75-29a7-4d9a-991e-94d28f7cd938")})()}catch{}const Je=()=>({enabled:!1,axisSubject:!1,axisPreheader:!1,bSubject:"",bPreheader:"",split:50});function ie(d){return d.enabled?!d.axisSubject&&!d.axisPreheader?"Pick at least one axis to test (subject or preheader).":d.axisSubject&&!d.bSubject.trim()?"Enter a Variant B subject.":d.axisPreheader&&!d.bPreheader.trim()?"Enter a Variant B preheader.":null:null}function Mt(d){if(!d.enabled)return null;const b=[];d.axisSubject&&b.push("subject"),d.axisPreheader&&b.push("preheader");const k={key:"B"};d.axisSubject&&(k.subject=d.bSubject),d.axisPreheader&&(k.preheader=d.bPreheader);const m=Math.max(0,Math.min(100,d.split));return{enabled:!0,axes:b,variants:[{key:"A",is_control:!0},k],split:{A:m,B:100-m}}}const Ut=({value:d,onChange:b})=>{const k=ie(d);return e.jsxs("div",{style:{marginBottom:"16px",border:"1px solid #e5e7eb",borderRadius:"6px",padding:"12px"},children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"8px",fontWeight:600,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox","data-testid":"ab-toggle",checked:d.enabled,onChange:m=>b({...d,enabled:m.target.checked})}),"A/B Test"]}),d.enabled&&e.jsxs("div",{style:{marginTop:"12px"},"data-testid":"ab-panel",children:[e.jsx("div",{style:{marginBottom:"8px",fontSize:"13px",color:"#6b7280"},children:"Variant A uses the Subject / Preheader above (control). Choose what to test and enter Variant B."}),e.jsxs("div",{style:{display:"flex",gap:"16px",marginBottom:"10px"},children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx("input",{type:"checkbox","data-testid":"ab-axis-subject",checked:d.axisSubject,onChange:m=>b({...d,axisSubject:m.target.checked})}),"Subject"]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx("input",{type:"checkbox","data-testid":"ab-axis-preheader",checked:d.axisPreheader,onChange:m=>b({...d,axisPreheader:m.target.checked})}),"Preheader"]})]}),d.axisSubject&&e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsx("label",{style:{display:"block",marginBottom:"4px",fontSize:"13px"},children:"Variant B — Subject"}),e.jsx("input",{type:"text","data-testid":"ab-b-subject",value:d.bSubject,onChange:m=>b({...d,bSubject:m.target.value}),style:{width:"100%",padding:"8px",border:"1px solid #d1d5db",borderRadius:"6px"}})]}),d.axisPreheader&&e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsx("label",{style:{display:"block",marginBottom:"4px",fontSize:"13px"},children:"Variant B — Preheader"}),e.jsx("input",{type:"text","data-testid":"ab-b-preheader",value:d.bPreheader,onChange:m=>b({...d,bPreheader:m.target.value}),style:{width:"100%",padding:"8px",border:"1px solid #d1d5db",borderRadius:"6px"}})]}),e.jsxs("div",{style:{marginBottom:"4px"},children:[e.jsxs("label",{style:{display:"block",marginBottom:"4px",fontSize:"13px"},children:["Split — A ",d.split,"% / B ",100-d.split,"%"]}),e.jsx("input",{type:"range",min:1,max:99,"data-testid":"ab-split",value:d.split,onChange:m=>b({...d,split:Number(m.target.value)}),style:{width:"100%"}})]}),k&&e.jsx("div",{"data-testid":"ab-error",style:{color:"#dc2626",fontSize:"13px",marginTop:"6px"},children:k})]})]})},Ht=(d,b)=>b?d.find(k=>k.id===b):void 0,Gt=()=>{const d=$t(),[b,k]=s.useState([]),[m,Ye]=s.useState(!1),[ne,Xe]=s.useState([]),[N,Ge]=s.useState([]),[ve,Qe]=s.useState([]),[H,Se]=s.useState(null),[K,re]=s.useState(null),[Ze,et]=s.useState(!0),[tt,se]=s.useState(!1),[it,ke]=s.useState(!1),[we,nt]=s.useState(null),[ae,Ce]=s.useState(null),[p,f]=s.useState(null),[V,o]=s.useState(null),[rt,oe]=s.useState(!1),[st,de]=s.useState(!1),[c,le]=s.useState(null),[pe,Be]=s.useState(!1),[$,at]=s.useState(null),[O,ot]=s.useState(null),[J,dt]=s.useState(null),[ce,Ae]=s.useState(!1),[Y,ze]=s.useState(!1),[Re,lt]=s.useState(null),[xe,Te]=s.useState(!1),[E,pt]=s.useState(null),[ue,We]=s.useState(!1),[Pe,X]=s.useState(null),[he,ct]=s.useState("all"),[S,ge]=s.useState(null),[a,y]=s.useState({name:"",subject:"",preheader:"",daily_limit:2e5,start_hour:11,end_hour:21,date_from:"",date_to:"",expires_at:"",email_content:{body:""},template_alias:"",audience_type:"email_opened",segment_id:null,audie
1nce_quality_filters:[]}),[L,xt]=s.useState([]),[Ie,be]=s.useState(!0),[n,h]=s.useState({name:"",postmark_template_id:"",template_alias:"",subject:"",preheader:"",audience_type:"email_opened",segment_id:null,audience_quality_filters:[],date_from:"",date_to:"",expires_at:"",daily_limit:2e5,start_hour:10,end_hour:21,one_click_enabled:!1,embed_promoted_petitions:!1,embed_petition_count:6}),[M,Ne]=s.useState(Je()),[j,me]=s.useState(null),[Ee,Le]=s.useState(!1),[T,G]=s.useState(null),[ye,qe]=s.useState(!1),[I,w]=s.useState(""),[C,B]=s.useState([]),[u,_]=s.useState(null),[q,Q]=s.useState(null),[Z,fe]=s.useState({subject:"",body:""}),[A,Fe]=s.useState(!1),[je,ee]=s.useState(!1);s.useEffect(()=>{je&&He()},[je]);const[De,ut]=s.useState([]),[ht,$e]=s.useState(!1),[W,U]=s.useState(null),[R,P]=s.useState({name:"",postmark_template_id:"",postmark_tag:"Newsletter",is_active:!0});s.useEffect(()=>{window.scrollTo(0,0)},[]),s.useEffect(()=>{v(),jt(),_t(),gt()},[]);const gt=async()=>{try{const t=await fetch("/api/v1/admin/scheduled-campaigns/postmark-templates",{credentials:"include",headers:{Accept:"application/json",Authorization:`Bearer ${localStorage.getItem("auth_token")}`}});if(t.ok){const i=await t.json();xt(i.templates||[]),be(i.available!==!1)}else be(!1)}catch(t){console.error("Failed to fetch Postmark templates:",t),be(!1)}};s.useEffect(()=>{const t=["newsletter","segment"].includes(n.audience_type);if(!n.embed_promoted_petitions||!t){G(null);return}(async()=>{qe(!0);try{const r=await Ot.get("/admin/scheduled-campaigns/preview-embed",{params:{count:n.embed_petition_count,...u?.id?{exclude_petition_id:u.id}:{}}});G(r.data)}catch{G({success:!1,petitions:[],note:"Preview failed to load."})}finally{qe(!1)}})()},[n.embed_promoted_petitions,n.embed_petition_count,n.audience_type,u?.id]);const v=async(t=m)=>{try{const i=await fetch(`/api/v1/admin/scheduled-campaigns${t?"?archived=1":""}`,{credentials:"include",headers:{Accept:"application/json",Authorization:`Bearer ${localStorage.getItem("auth_token")}`}});if(i.ok){const r=await i.json();k(r)}}catch(i){console.error("Failed to fetch campaigns:",i)}finally{et(!1)}},bt=t=>t.sent_count===0&&["draft","building","ready"].includes(t.status),mt=t=>t.status==="completed"&&!t.archived,yt=async t=>{if(confirm('Archive this campaign? It is hidden from the default list but history and stats are kept — the "Show archived" toggle brings it back.'))try{const r=await(await fetch(`/api/v1/admin/scheduled-campaigns/${t}/archive`,{method:"POST",credentials:"include",headers:{Accept:"application/json",Authorization:`Bearer ${localStorage.getItem("auth_token")}`}})).json();o({type:r.success?"success":"error",text:r.message}),r.success&&v()}catch{o({type:"error",text:"Archive failed."})}},ft=async t=>{try{const r=await(await fetch(`/api/v1/admin/scheduled-campaigns/${t}/unarchive`,{method:"POST",credentials:"include",headers:{Accept:"application/json",Authorization:`Bearer ${localStorage.getItem("auth_token")}`}})).json();o({type:r.success?"success":"error",text:r.message}),r.success&&v()}catch{o({type:"error",text:"Unarchive failed."})}},jt=async()=>{try{const t=await fetch("/api/v1/admin/scheduled-campaigns/audience-types",{credentials:"include",headers:{Accept:"application/json",Authorization:`Bearer ${localStorage.getItem("auth_token")}`}});if(t.ok){const i=await t.json();Xe(i)}}catch(t){console.error("Failed to fetch audience types:",t)}},_t=async()=>{try{const t=await fetch("/api/v1/admin/email-segments",{credentials:"include",headers:{Accept:"application/json",Authorization:`Bearer ${localStorage.getItem("auth_token")}`}});if(t.ok){const i=await t.json();Ge(i.segments??[]),Qe(i.categories??[])}}catch(t){console.error("Failed to fetch email segments:",t)}},Oe=async()=>{Ae(!0);try{const i=await(await fetch("/api/v1/admin/scheduled-campaigns/active-stats",{credentials:"include",headers:{Accept:"application/json",Authorization:`Bearer ${localStorage.getItem("auth_token")}`}})).json();at(i.data??[])}catch(t){console.error("Failed to load active stats:",t)}finally{Ae(!1)}},Me=async()=>{ze(!0);try{const i=await(await fetch("/api/v1/admin/scheduled-campaigns/audience-availability",{credentials:"include",headers:{Accept:"application/json",Authorization:`Bearer ${localStorage.getItem("auth_token")}`}})).json();ot(i.data??[]),dt(i.blocked_breakdown??null),lt(i.cached_at??null)}catch(t){console.error("Failed to load audience stats:",t)}finally{ze(!1)}},Ue=async()=>{We(!0),X(null);try{const t=await fetch("/api/v1/admin/campaign-performance-stats?from=2026-01-01",{credentials:"include",headers:{Accept:"application/json",Authorization:`Bearer ${localStorage.getItem("auth_token")}`}});if(!t.ok){X(`API error ${t.status} — try clearing the route cache (php artisan route:clear)`);return}const i=await t.json();if(!Array.isArray(i)){X("Unexpected response format from API");return}const r=i.map(x=>({...x,total_sent:parseInt(String(x.total_sent),10),total_delivered:parseInt(String(x.total_delivered),10),total_opened:parseInt(String(x.total_opened),10),total_human_opened:parseInt(String(x.total_human_opened),10),total_bounced:
1parseInt(String(x.total_bounced),10),total_unsubscribed:parseInt(String(x.total_unsubscribed),10),total_spam_complaints:parseInt(String(x.total_spam_complaints),10),open_rate:parseFloat(String(x.open_rate)),click_rate:parseFloat(String(x.click_rate)),unsub_rate:parseFloat(String(x.unsub_rate)),bounce_rate:parseFloat(String(x.bounce_rate)),spam_rate:parseFloat(String(x.spam_rate))})).sort((x,g)=>g.campaign_id-x.campaign_id);pt(r)}catch(t){console.error("Failed to load performance stats:",t),X("Network error — could not reach the API")}finally{We(!1)}},vt=async()=>{await fetch("/api/v1/admin/scheduled-campaigns/audience-availability/refresh",{method:"POST",credentials:"include",headers:{Accept:"application/json",Authorization:`Bearer ${localStorage.getItem("auth_token")}`}}),Me()},He=async()=>{$e(!0);try{const t=await fetch("/api/v1/admin/scheduled-campaigns/email-templates",{credentials:"include",headers:{Accept:"application/json",Authorization:`Bearer ${localStorage.getItem("auth_token")}`}});if(t.ok){const i=await t.json();ut(i)}}catch(t){console.error("Failed to fetch templates:",t)}finally{$e(!1)}},St=async t=>{t.preventDefault();try{const i=W?`/api/v1/admin/scheduled-campaigns/email-templates/${W.id}`:"/api/v1/admin/scheduled-campaigns/email-templates",g=await(await fetch(i,{method:W?"PUT":"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json",Authorization:`Bearer ${localStorage.getItem("auth_token")}`},body:JSON.stringify(R)})).json();g.success?(o({type:"success",text:g.message}),ee(!1),U(null),P({name:"",postmark_template_id:"",postmark_tag:"Newsletter",is_active:!0}),He()):o({type:"error",text:g.message})}catch{o({type:"error",text:"Failed to save template"})}},kt=t=>{U(t),P({name:t.name,postmark_template_id:t.postmark_template_id,postmark_tag:t.postmark_tag||"Newsletter",is_active:t.is_active===1}),ee(!0)},wt=async t=>{try{const i=await fetch(`/api/v1/admin/scheduled-campaigns/${t}`,{credentials:"include",headers:{Accept:"application/json",Authorization:`Bearer ${localStorage.getItem("auth_token")}`}});if(i.ok){const r=await i.json();Ce(r)}}catch(i){console.error("Failed to fetch campaign details:",i)}},z=async()=>{if(I.trim()){Fe(!0);try{const t=await fetch(`/api/v1/admin/campaign-petitions/search?q=${encodeURIComponent(I)}`,{credentials:"include",headers:{Accept:"application/json",Authorization:`Bearer ${localStorage.getItem("auth_token")}`}});if(t.ok){const i=await t.json();B(i)}}catch(t){console.error("Failed to search petitions:",t)}finally{Fe(!1)}}},Ct=async t=>{_(t),B([]),w("");try{const i=await fetch(`/api/v1/admin/campaign-petitions/${t.id}/latest-update`,{credentials:"include",headers:{Accept:"application/json",Authorization:`Bearer ${localStorage.getItem("auth_token")}`}});if(i.ok){const r=await i.json();r.update?Q(r.update):(Q(null),o({type:"error",text:"No unsent update found for this petition"}))}}catch(i){console.error("Failed to fetch petition update:",i)}},Bt=async()=>{if(!n.date_from||!n.date_to){o({type:"error",text:"Please select date range first"});return}if(n.audience_type==="newsletter"&&!u?.id){o({type:"error",text:"Please select a petition first"});return}if(n.audience_type==="newsletter"&&!n.template_alias){o({type:"error",text:"Please enter a template alias first"});return}Le(!0),me(null);try{const t=await fetch("/api/v1/admin/scheduled-campaigns/audience-preview",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json",Authorization:`Bearer ${localStorage.getItem("auth_token")}`},body:JSON.stringify({template_alias:n.template_alias,petition_id:u?.id,date_from:n.date_from,date_to:n.date_to,audience_quality_filters:n.audience_quality_filters.length>0?n.audience_quality_filters:void 0})});if(t.ok){const i=await t.json();me(i)}else{const i=await t.json();o({type:"error",text:i.message??"Preview failed"})}}catch(t){console.error("Failed to preview audience:",t)}finally{Le(!1)}},At=async t=>{if(t.preventDefault(),n.audience_type==="petition_update"){if(!u){o({type:"error",text:"Please select a petition"});return}if(!q){o({type:"error",text:"No unsent update found for this petition"});return}if(!Z.body.trim()){o({type:"error",text:"Please enter email content"});return}}if(n.audience_type==="newsletter"){if(!u){o({type:"error",text:"Please select a target petition to promote"});return}if(n.audience_quality_filters.length===0){o({type:"error",text:"Please select at least one audience quality filter"});return}}if(n.audience_type==="segment"&&!n.segment_id){o({type:"error",text:"אנא בחר קבוצת מנויים"});return}if(n.audience_type==="segment"&&!u){o({type:"error",text:"אנא בחר עצומה לקידום"});return}const i=ie(M);if(i){o({type:"error",text:i});return}f(-1);try{const r={...n,expires_at:n.expires_at||null,ab_config:Mt(M)};n.audience_type==="petition_update"&&(r.petition_id=u?.id,r.petition_update_id=q?.update_id,r.email_content=Z),(n.audience_type==="newsletter"||n.audience_type==="segment")&&(r.petition_id=u?.id,r.embed_promoted_petitions=n.embed_promoted_petitions,r.embed_petition_count=n.embed_promoted_petitions?n.embed_petition_count:null);const g=await(await fetch("/api/v1/admin/scheduled-campaigns",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json",Authorization:`Bearer ${localStorage.getItem("auth_token")}`},body:JSON.stringify(r)})).json();g.success?(o({type:"success",text:"Campaign created successfully!"}),se(!1),v(),Ke()):o({type:"error",text:g.message||"Failed to create campaign"})}catch{o({type:"error",text:"Failed to create campaign"})}finally{f(null)}},zt=async t=>{f(t);try{const r=await(await fetch(`/api/v1/admin/scheduled-campaigns/${t}/build-recipients`,{method:"POST",credentials:"include",headers:{Accept:"application/json",Authorization:`Bearer ${localStorage.getItem("auth_token")}`}})).json();r.success?(o({type:"success",text:r.message||"Build started in background"}),v()):o({type:"error",text:r.message})}catch{o({type:"error",text:"Failed to build recipients"})}finally{f(null)}},Rt=async t=>{f(t);try{const r=await(await fetch(`/api/v1/admin/scheduled-campaigns/${t}/activate`,{method:"POST",credentials:"include",headers:{Accept:"application/json",Authorization:`Bearer ${localStorage.getItem("auth_token")}`}})).json();r.success?(o({type:"success",text:"Campaign activated!"}),v()):o({type:"error",text:r.message})}catch{o({type:"error",text:"Failed to activate campaign"})}finally{f(null)}}
1,Tt=async t=>{f(t);try{const r=await(await fetch(`/api/v1/admin/scheduled-campaigns/${t}/pause`,{method:"POST",credentials:"include",headers:{Accept:"application/json",Authorization:`Bearer ${localStorage.getItem("auth_token")}`}})).json();r.success?(o({type:"success",text:"Campaign paused"}),v()):o({type:"error",text:r.message})}catch{o({type:"error",text:"Failed to pause campaign"})}finally{f(null)}},Wt=async t=>{if(confirm("Are you sure you want to delete this campaign?")){f(t);try{const r=await(await fetch(`/api/v1/admin/scheduled-campaigns/${t}`,{method:"DELETE",credentials:"include",headers:{Accept:"application/json",Authorization:`Bearer ${localStorage.getItem("auth_token")}`}})).json();r.success?(o({type:"success",text:"Campaign deleted"}),v()):o({type:"error",text:r.message})}catch{o({type:"error",text:"Failed to delete campaign"})}finally{f(null)}}},Pt="[email protected], [email protected]",It=async t=>{const i=prompt("Send test email to (comma-separated addresses):",Pt);if(i===null)return;const r=i.split(",").map(x=>x.trim()).filter(Boolean);if(r.length===0){o({type:"error",text:"No recipients given"});return}f(t);try{const g=await(await fetch(`/api/v1/admin/scheduled-campaigns/${t}/send-test`,{method:"POST",credentials:"include",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("auth_token")}`},body:JSON.stringify({recipients:r.map(F=>({email:F,name:""}))})})).json();if(g.success)o({type:"success",text:`${g.message} → ${(g.recipients||[]).join(", ")}`});else{const F=(g.errors||[]).join(" | ");o({type:"error",text:(g.message||"Test failed")+(F?` — ${F}`:"")})}}catch{o({type:"error",text:"Failed to send test emails"})}finally{f(null)}},Nt=async t=>{if(confirm("Are you sure you want to STOP this campaign? This will cancel all pending emails and cannot be undone.")){f(t);try{const r=await(await fetch(`/api/v1/admin/scheduled-campaigns/${t}/stop`,{method:"POST",credentials:"include",headers:{Accept:"application/json",Authorization:`Bearer ${localStorage.getItem("auth_token")}`}})).json();r.success?(o({type:"success",text:r.message}),v()):o({type:"error",text:r.message})}catch{o({type:"error",text:"Failed to stop campaign"})}finally{f(null)}}},Et=async t=>{if(confirm("Create a copy of this campaign as a new draft?")){f(t);try{const r=await(await fetch(`/api/v1/admin/scheduled-campaigns/${t}/duplicate`,{method:"POST",credentials:"include",headers:{Accept:"application/json",Authorization:`Bearer ${localStorage.getItem("auth_token")}`}})).json();r.success?(o({type:"success",text:"Campaign duplicated"}),v()):o({type:"error",text:r.message||"Failed to duplicate campaign"})}catch{o({type:"error",text:"Failed to duplicate campaign"})}finally{f(null)}}},Lt=t=>{le(t),de(!0)},qt=t=>{if(ge(t),y({name:t.name,subject:t.subject||"",preheader:t.preheader||"",template_alias:t.template_alias||"",daily_limit:t.daily_limit,start_hour:t.start_hour,end_hour:t.end_hour,date_from:t.date_from,date_to:t.date_to,expires_at:t.expires_at||"",email_content:t.email_content||{body:""},audience_type:t.audience_type,segment_id:t.segment_id??null,audience_quality_filters:t.audience_quality_filters??[]}),t.segment_id){const i=N.find(r=>r.id===t.segment_id);re(i?i.category:null)}else re(null);t.petition_id?_({id:t.petition_id,title:t.petition_title||`Petition #${t.petition_id}`,slug:""}):_(null),w(""),B([]),oe(!0)},Ft=async t=>{if(t.preventDefault(),!!S){f(S.id);try{const i=S.status==="draft",r={...a,expires_at:a.expires_at||null};i?r.petition_id=u?.id??null:(delete r.audience_type,delete r.segment_id,delete r.audience_quality_filters);const g=await(await fetch(`/api/v1/admin/scheduled-campaigns/${S.id}`,{method:"PUT",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json",Authorization:`Bearer ${localStorage.getItem("auth_token")}`},body:JSON.stringify(r)})).json();g.success?(o({type:"success",text:"Campaign updated successfully!"}),oe(!1),ge(null),_(null),B([]),w(""),v()):o({type:"error",text:g.message||"Failed to update campaign"})}catch{o({type:"error",text:"Failed to update campaign"})}finally{f(null)}}},Ke=()=>{h({name:"",postmark_template_id:"",template_alias:"",subject:"",preheader:"",audience_type:"email_opened",segment_id:null,audie
1nce_quality_filters:[],date_from:"",date_to:"",expires_at:"",daily_limit:2e5,start_hour:10,end_hour:21,one_click_enabled:!1,embed_promoted_petitions:!1,embed_petition_count:6}),Ne(Je()),me(null),G(null),_(null),Q(null),fe({subject:"",body:""}),w(""),B([]),Se(null)},_e=t=>{const i={draft:{bg:"#e5e7eb",color:"#374151"},building:{bg:"#fef3c7",color:"#92400e"},ready:{bg:"#dbeafe",color:"#1e40af"},active:{bg:"#d1fae5",color:"#065f46"},paused:{bg:"#fed7aa",color:"#9a3412"},completed:{bg:"#e0e7ff",color:"#3730a3"}},r=i[t]||i.draft;return e.jsx("span",{style:{padding:"4px 12px",borderRadius:"12px",fontSize:"12px",fontWeight:600,background:r.bg,color:r.color},children:t.toUpperCase()})},Ve=t=>ne.find(r=>r.value===t)?.label||t;return e.jsx("div",{style:{minHeight:"100vh",background:"#f3f4f6",padding:"20px"},children:e.jsxs("div",{style:{maxWidth:"1200px",margin:"0 auto"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px"},children:[e.jsx("h1",{style:{fontSize:"28px",fontWeight:"bold",color:"#111827"},children:"📧 Scheduled Campaigns"}),e.jsxs("div",{style:{display:"flex",gap:"12px"},children:[e.jsx("button",{onClick:()=>se(!0),style:{padding:"10px 20px",background:"#059669",color:"white",border:"none",borderRadius:"8px",cursor:"pointer",fontWeight:600},children:"+ New Campaign"}),e.jsx("button",{onClick:()=>{U(null),P({name:"",postmark_template_id:"",postmark_tag:"Newsletter",is_active:!0}),ee(!0)},style:{padding:"10px 20px",background:"#1d4ed8",color:"white",border:"none",borderRadius:"8px",cursor:"pointer",fontWeight:600},children:"📋 Templates"}),e.jsx("button",{onClick:()=>{const t=!pe;Be(t),t&&!$&&Oe()},style:{padding:"10px 20px",background:pe?"#7c3aed":"#6d28d9",color:"white",border:"none",borderRadius:"8px",cursor:"pointer",fontWeight:600},children:"📊 Intelligence"}),e.jsx("button",{onClick:()=>{const t=!xe;Te(t),t&&!E&&Ue()},style:{padding:"10px 20px",background:xe?"#0e7490":"#0891b2",color:"white",border:"none",borderRadius:"8px",cursor:"pointer",fontWeight:600},children:"📈 Performance"}),e.jsx("button",{onClick:()=>{const t=!m;Ye(t),v(t)},style:{padding:"10px 20px",background:m?"#4f46e5":"#e5e7eb",color:m?"white":"#374151",border:"none",borderRadius:"8px",cursor:"pointer",fontWeight:600},children:m?"📁 Showing archived":"📁 Show archived"}),e.jsx("button",{onClick:()=>d("/admin/main"),style:{padding:"10px 20px",background:"#6b7280",color:"white",border:"none",borderRadius:"8px",cursor:"pointer",fontWeight:600},children:"← Back to Admin"})]})]}),V&&e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",marginBottom:"20px",background:V.type==="success"?"#d1fae5":"#fee2e2",color:V.type==="success"?"#065f46":"#991b1b"},children:[V.text,e.jsx("button",{onClick:()=>o(null),style:{float:"right",background:"none",border:"none",cursor:"pointer",fontWeight:"bold"},children:"✕"})]}),pe&&e.jsxs("div",{style:{background:"white",borderRadius:"12px",boxShadow:"0 2px 10px rgba(0,0,0,0.1)",marginBottom:"24px",overflow:"hidden"},children:[e.jsxs("div",{style:{padding:"20px 24px",borderBottom:"1px solid #e5e7eb",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("h2",{style:{margin:0,fontSize:"18px",fontWeight:700},children:"📊 Sending Intelligence Panel"}),e.jsx("button",{onClick:()=>Be(!1),style:{background:"none",border:"none",fontSize:"20px",cursor:"pointer",color:"#6b7280"},children:"✕"})]}),e.jsxs("div",{style:{padding:"20px 24px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px"},children:[e.jsx("h3",{style:{margin:0,fontSize:"15px",fontWeight:600},children:"Active Campaigns Status"}),e.jsx("button",{onClick:Oe,disabled:ce,style:{padding:"4px 12px",fontSize:"12px",background:"#f3f4f6",border:"1px solid #d1d5db",borderRadius:"6px",cursor:"pointer"},children:ce?"⏳ Loading...":"🔄 Refresh"})]}),ce?e.jsx("div",{style:{padding:"20px",textAlign:"center",color:"#6b7280"},children:"Loading..."}):$&&$.length===0?e.jsx("div",{style:{padding:"16px",background:"#f9fafb",borderRadius:"8px",color:"#6b7280",fontSize:"14px"},children:"No active campaigns right now."}):$?e.jsx("div",{style:{overflowX:"auto",marginBottom:"24px"},children:e.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:"13px"},children:[e.jsx("thead",{children:e.jsx("tr",{style:{background:"#f9fafb"},children:["#","Campaign","Sent Today","Remaining","Will Send Tomorrow","Throttle Opens","Window"].map(t=>e.jsx("th",{style:{padding:"8px 12px",textAlign:"left",fontWeight:600,color:"#374151",borderBottom:"1px solid #e5e7eb",whiteSpace:"nowrap"},children:t},t))})}),e.jsx("tbody",{children:$.map(t=>e.jsxs("tr",{style:{borderBottom:"1px solid #f3f4f6"},children:[e.jsxs("td",{style:{padding:"8px 12px",color:"#6b7280"},children:["#",t.id]}),e.jsx("td",{style:{padding:"8px 12px",fontWeight:500,maxWidth:"220px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.name}),e.jsx("td",{style:{padding:"8px 12px"}
1,children:Number(t.sent_today).toLocaleString()}),e.jsx("td",{style:{padding:"8px 12px"},children:Number(t.truly_remaining).toLocaleString()}),e.jsx("td",{style:{padding:"8px 12px",fontWeight:600,color:"#059669"},children:Number(t.will_send_tomorrow).toLocaleString()}),e.jsx("td",{style:{padding:"8px 12px"},children:Number(t.hours_until_throttle_clears)===-1?e.jsx("span",{style:{color:"#6b7280"},children:"⏳ Pending schedule"}):Number(t.hours_until_throttle_clears)===0?e.jsx("span",{style:{color:"#059669",fontWeight:600},children:"✅ Open now"}):e.jsxs("span",{style:{color:"#d97706"},children:["🔒 ",t.hours_until_throttle_clears,"h"]})}),e.jsx("td",{style:{padding:"8px 12px",color:"#6b7280",whiteSpace:"nowrap"},children:t.sending_window})]},t.id))})]})}):null,e.jsxs("div",{style:{borderTop:"1px solid #e5e7eb",paddingTop:"20px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px"},children:[e.jsx("h3",{style:{margin:0,fontSize:"15px",fontWeight:600},children:"Audience Availability (daily throttle)"}),O&&e.jsx("button",{onClick:vt,disabled:Y,style:{padding:"4px 12px",fontSize:"12px",background:"#f3f4f6",border:"1px solid #d1d5db",borderRadius:"6px",cursor:"pointer"},children:Y?"⏳ Recalculating...":"🔄 Refresh Cache"})]}),!O&&!Y?e.jsxs("div",{style:{background:"#fffbeb",border:"1px solid #fde68a",borderRadius:"8px",padding:"16px"},children:[e.jsx("p",{style:{margin:"0 0 12px",fontSize:"13px",color:"#92400e"},children:"⚠️ This query scans the full email audience — first load takes ~20 seconds, then cached for 1 hour."}),e.jsx("button",{onClick:Me,style:{padding:"8px 16px",background:"#d97706",color:"white",border:"none",borderRadius:"6px",cursor:"pointer",fontWeight:600,fontSize:"13px"},children:"📊 Load Audience Data"})]}):Y?e.jsx("div",{style:{padding:"20px",textAlign:"center",color:"#6b7280"},children:"⏳ Loading (~20s on first load)..."}):O?e.jsxs("div",{children:[e.jsx("div",{style:{overflowX:"auto"},children:e.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:"13px"},children:[e.jsx("thead",{children:e.jsx("tr",{style:{background:"#f9fafb"},children:["Audience Group","Total","Available Now","Blocked (today)"].map(t=>e.jsx("th",{style:{padding:"8px 12px",textAlign:"left",fontWeight:600,color:"#374151",borderBottom:"1px solid #e5e7eb"},children:t},t))})}),e.jsxs("tbody",{children:[O.filter(t=>t.grp!=="Total Unique").map(t=>e.jsxs("tr",{style:{borderBottom:"1px solid #f3f4f6"},children:[e.jsx("td",{style:{padding:"8px 12px",fontWeight:500},children:t.grp}),e.jsx("td",{style:{padding:"8px 12px"},children:Number(t.total).toLocaleString()}),e.jsxs("td",{style:{padding:"8px 12px",color:"#059669",fontWeight:600},children:["✅ ",Number(t.available_now).toLocaleString()]}),e.jsxs("td",{style:{padding:"8px 12px",color:"#dc2626"},children:["🔒 ",Number(t.blocked_now).toLocaleString()]})]},t.grp)),O.filter(t=>t.grp==="Total Unique").map(t=>e.jsxs("tr",{style:{borderTop:"2px solid #e5e7eb",background:"#f9fafb"},children:[e.jsx("td",{style:{padding:"8px 12px",fontWeight:700},children:t.grp}),e.jsx("td",{style:{padding:"8px 12px",fontWeight:700},children:Number(t.total).toLocaleString()}),e.jsxs("td",{style:{padding:"8px 12px",color:"#059669",fontWeight:700},children:["✅ ",Number(t.available_now).toLocaleString()]}),e.jsxs("td",{style:{padding:"8px 12px",color:"#dc2626",fontWeight:700},children:["🔒 ",Number(t.blocked_now).toLocaleString()]})]},t.grp))]})]})}),J&&e.jsxs("div",{style:{marginTop:"16px",background:"#f9fafb",border:"1px solid #e5e7eb",borderRadius:"8px",padding:"12px 16px"},children:[e.jsx("p",{style:{margin:"0 0 8px",fontSize:"12px",fontWeight:600,color:"#374151"},children:"Why blocked from sending:"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px",fontSize:"12px",color:"#6b7280"},children:[e.jsxs("span",{children:["🚫 Unsubscribed: ",e.jsx("strong",{style:{color:"#374151"},children:Number(J.unsubscribed).toLocaleString()})]}),e.jsxs("span",{children:["⛔ Hard bounce: ",e.jsx("strong",{style:{color:"#374151"}
1,children:Number(J.hard_bounced).toLocaleString()})]}),e.jsxs("span",{children:["📛 Blocked (spam/bounce): ",e.jsx("strong",{style:{color:"#374151"},children:Number(J.blocked_emails).toLocaleString()})]})]})]}),Re&&e.jsxs("p",{style:{margin:"8px 0 0",fontSize:"11px",color:"#9ca3af"},children:["Cached at: ",new Date(Re).toLocaleString()]})]}):null]})]})]}),xe&&e.jsxs("div",{style:{background:"white",borderRadius:"12px",boxShadow:"0 2px 10px rgba(0,0,0,0.1)",marginBottom:"24px",overflow:"hidden"},children:[e.jsxs("div",{style:{padding:"20px 24px",borderBottom:"1px solid #e5e7eb",display:"flex",justifyContent:"space-between",alignItems:"center",flexWrap:"wrap",gap:"12px"},children:[e.jsx("h2",{style:{margin:0,fontSize:"18px",fontWeight:700},children:"📈 Campaign Performance"}),e.jsxs("div",{style:{display:"flex",gap:"10px",alignItems:"center",flexWrap:"wrap"},children:[e.jsxs("select",{value:he,onChange:t=>ct(t.target.value),style:{padding:"6px 10px",fontSize:"13px",border:"1px solid #d1d5db",borderRadius:"6px",background:"white",cursor:"pointer"},children:[e.jsx("option",{value:"all",children:"All types"}),e.jsx("option",{value:"regular",children:"Regular"}),e.jsx("option",{value:"unopened",children:"Unopened"}),e.jsx("option",{value:"signclick",children:"Signclick"}),e.jsx("option",{value:"re-engagement",children:"Re-engagement"})]}),e.jsx("button",{onClick:Ue,disabled:ue,style:{padding:"6px 14px",fontSize:"12px",background:"#f3f4f6",border:"1px solid #d1d5db",borderRadius:"6px",cursor:"pointer"},children:ue?"⏳ Loading…":"🔄 Refresh"}),e.jsx("button",{onClick:()=>Te(!1),style:{background:"none",border:"none",fontSize:"20px",cursor:"pointer",color:"#6b7280"},children:"✕"})]})]}),e.jsx("div",{style:{padding:"20px 24px"},children:ue?e.jsx("div",{style:{padding:"30px",textAlign:"center",color:"#6b7280"},children:"Loading…"}):Pe?e.jsxs("div",{style:{padding:"16px",background:"#fee2e2",borderRadius:"8px",color:"#991b1b",fontSize:"14px"},children:["⚠️ ",Pe]}
1):!E||E.length===0?e.jsx("div",{style:{padding:"20px",background:"#f9fafb",borderRadius:"8px",color:"#6b7280",fontSize:"14px"},children:"No performance data found."}):(()=>{const t=he==="all"?E:E.filter(l=>l.campaign_type===he),i=l=>l<2?"#059669":l<3?"#d97706":"#dc2626",r=l=>l<.5?"#059669":"#dc2626",x=l=>l<.05?"#059669":l<.1?"#d97706":"#dc2626",g=(l,te,D)=>e.jsxs("div",{style:{textAlign:"center"},children:[e.jsxs("span",{style:{display:"inline-block",padding:"2px 7px",borderRadius:"10px",fontSize:"12px",fontWeight:600,background:D==="#059669"?"#d1fae5":D==="#d97706"?"#fef3c7":"#fee2e2",color:D},children:[l.toFixed(2),"%"]}),e.jsxs("div",{style:{fontSize:"11px",color:"#6b7280",marginTop:"2px"},children:["(",te.toLocaleString(),")"]})]}),F=l=>{const D={regular:{bg:"#e0f2fe",color:"#0369a1"},unopened:{bg:"#fef9c3",color:"#854d0e"},signclick:{bg:"#ede9fe",color:"#5b21b6"},"re-engagement":{bg:"#fce7f3",color:"#9d174d"}}[l]??{bg:"#f3f4f6",color:"#374151"};return e.jsx("span",{style:{display:"inline-block",padding:"2px 7px",borderRadius:"10px",fontSize:"11px",fontWeight:600,background:D.bg,color:D.color},children:l})},Dt=new Set(["#","Sent","Human%","All Opens%","Click%","Unsubs","Bounces","Spam"]);return e.jsxs(e.Fragment,{children:[e.jsxs("p",{style:{margin:"0 0 14px",fontSize:"13px",color:"#6b7280"},children:["Showing ",t.length," of ",E.length," campaigns"]}),e.jsx("div",{style:{overflowX:"auto"},children:e.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:"13px"},children:[e.jsx("thead",{children:e.jsx("tr",{style:{background:"#f9fafb"},children:["#","Campaign","Petition","Type","Date","Sent","Human%","All Opens%","Click%","Unsubs","Bounces","Spam"].map(l=>e.jsx("th",{style:{padding:"8px 12px",textAlign:Dt.has(l)?"center":"left",fontWeight:600,color:"#374151",borderBottom:"1px solid #e5e7eb",whiteSpace:"nowrap"},children:l},l))})}),e.jsx("tbody",{children:t.map(l=>{const te=l.total_delivered>0?l.total_opened/l.total_delivered*100:0;return e.jsxs("tr",{style:{borderBottom:"1px solid #f3f4f6"},children:[e.jsxs("td",{style:{padding:"8px 12px",color:"#6b7280",textAlign:"center",whiteSpace:"nowrap"},children:["#",l.campaign_id]}),e.jsx("td",{style:{padding:"8px 12px",fontWeight:500,maxWidth:"220px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:l.name,children:l.name}),e.jsx("td",{style:{padding:"8px 12px",color:"#374151",maxWidth:"180px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"12px"},title:l.petition_name??"",children:l.petition_name??e.jsx("span",{style:{color:"#9ca3af"},children:"—"})}),e.jsx("td",{style:{padding:"8px 12px"},children:F(l.campaign_type)}),e.jsx("td",{style:{padding:"8px 12px",color:"#6b7280",whiteSpace:"nowrap"},children:l.sent_date??"—"}),e.jsx("td",{style:{padding:"8px 12px",textAlign:"center",whiteSpace:"nowrap"},children:l.total_sent.toLocaleString()}),e.jsx("td",{style:{padding:"8px 12px",textAlign:"center"},children:e.jsxs("span",{style:{fontWeight:600,color:"#111827"},children:[l.open_rate.toFixed(1),"%"]})}),e.jsx("td",{style:{padding:"8px 12px",textAlign:"center"},children:e.jsxs("span",{style:{color:"#6b7280"},children:[te.toFixed(1),"%"]})}),e.jsx("td",{style:{padding:"8px 12px",textAlign:"center"},children:e.jsxs("span",{style:{fontWeight:600,color:"#111827"},children:[l.click_rate.toFixed(1),"%"]})}),e.jsx("td",{style:{padding:"8px 12px"},children:g(l.unsub_rate,l.total_unsubscribed,i(l.unsub_rate))}),e.jsx("td",{style:{padding:"8px 12px"},children:g(l.bounce_rate,l.total_bounced,r(l.bounce_rate))}),e.jsx("td",{style:{padding:"8px 12px"},children:g(l.spam_rate,l.total_spam_complaints,x(l.spam_rate))})]},l.campaign_id)})})]})})]})})()})]}),e.jsx("div",{style:{background:"white",borderRadius:"12px",boxShadow:"0 2px 10px rgba(0,0,0,0.1)",overflow:"hidden"},children:Ze?e.jsx("div",{style:{padding:"40px",textAlign:"center",color:"#6b7280"},children:"Loading..."}):b.length===0?e.jsx("div",{style:{padding:"40px",textAlign:"center",color:"#6b7280"},children:"No campaigns yet. Create your first campaign!"}):e.jsxs("table",{style:{width:"100%",borderCollapse:"collapse"},children:[e.jsx("thead",{children:e.jsxs("tr",{style:{background:"#f9fafb",borderBottom:"2px s
1olid #e5e7eb"},children:[e.jsx("th",{style:{padding:"12px 16px",textAlign:"left",fontWeight:600},children:"Campaign"}),e.jsx("th",{style:{padding:"12px 16px",textAlign:"left",fontWeight:600},children:"Audience"}),e.jsx("th",{style:{padding:"12px 16px",textAlign:"center",fontWeight:600},children:"Status"}),e.jsx("th",{style:{padding:"12px 16px",textAlign:"center",fontWeight:600},children:"Progress"}),e.jsx("th",{style:{padding:"12px 16px",textAlign:"center",fontWeight:600},children:"Daily Limit"}),e.jsx("th",{style:{padding:"12px 16px",textAlign:"center",fontWeight:600},children:"Actions"})]})}),e.jsx("tbody",{children:b.map(t=>e.jsxs("tr",{style:{borderBottom:"1px solid #e5e7eb"},children:[e.jsxs("td",{style:{padding:"16px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"4px"},children:[e.jsxs("span",{style:{fontSize:"11px",fontWeight:700,color:"white",background:"#6b7280",borderRadius:"4px",padding:"1px 6px",flexShrink:0},children:["#",t.id]}),e.jsx("span",{style:{fontWeight:600},children:t.name})]}),e.jsx("div",{style:{fontSize:"12px",color:"#6b7280"},children:t.template_alias}),e.jsxs("div",{style:{fontSize:"11px",color:"#9ca3af"},children:["Audience: ",t.date_from," → ",t.date_to]}),t.expires_at&&e.jsxs("div",{style:{fontSize:"11px",color:"#dc2626",marginTop:"2px"},children:["Expires: ",t.expires_at]})]}),e.jsxs("td",{style:{padding:"16px"},children:[e.jsx("div",{style:{fontSize:"13px"},children:Ve(t.audience_type)}),e.jsxs("div",{style:{fontSize:"12px",color:"#6b7280"},children:[t.total_recipients," recipients"]})]}),e.jsx("td",{style:{padding:"16px",textAlign:"center"},children:_e(t.status)}),e.jsxs("td",{style:{padding:"16px",textAlign:"center"},children:[e.jsxs("div",{style:{marginBottom:"4px",fontSize:"13px"},children:[t.sent_count," / ",t.total_recipients]}),e.jsx("div",{style:{width:"100px",height:"8px",background:"#e5e7eb",borderRadius:"4px",overflow:"hidden",margin:"0 auto"},children:e.jsx("div",{style:{width:`${t.progress_percent}%`,height:"100%",background:"#059669",transition:"width 0.3s"}})}),e.jsxs("div",{style:{fontSize:"11px",color:"#6b7280",marginTop:"2px"},children:[t.progress_percent,"%"]})]}),e.jsx("td",{style:{padding:"16px",textAlign:"center"},children:t.daily_limit}),e.jsx("td",{style:{padding:"16px",textAlign:"center"},children:e.jsxs("div",{style:{display:"flex",gap:"6px",justifyContent:"center",flexWrap:"wrap",maxWidth:"300px",margin:"0 auto"},children:[e.jsx("button",{onClick:()=>Lt(t),style:{padding:"5px 8px",background:"#6b7280",color:"white",border:"none",borderRadius:"6px",cursor:"pointer",fontSize:"12px"},children:"ℹ️ Info"}),e.jsx("button",{onClick:()=>{nt(t),wt(t.id),ke(!0)},style:{padding:"5px 8px",background:"#3b82f6",color:"white",border:"none",borderRadius:"6px",cursor:"pointer",fontSize:"12px"},children:"📊 Stats"}),t.status!=="completed"&&e.jsx("button",{onClick:()=>qt(t),style:{padding:"5px 8px",background:"#6366f1",color:"white",border:"none",borderRadius:"6px",cursor:"pointer",fontSize:"12px"},children:"✏️ Edit"}),e.jsx("button",{onClick:()=>Et(t.id),disabled:p===t.id,style:{padding:"5px 8px",background:"#0d9488",color:"white",border:"none",borderRadius:"6px",cursor:"pointer",fontSize:"12px",opacity:p===t.id?.7:1},children:p===t.id?"...":"📋 Copy"}),e.jsx("button",{onClick:()=>It(t.id),disabled:p===t.id,style:{padding:"5px 8px",background:"#f97316",color:"white",border:"none",borderRadius:"6px",cursor:"pointer",fontSize:"12px",opacity:p===t.id?.7:1},children:p===t.id?"...":"🧪 Test"}),t.status==="draft"&&e.jsx("button",{onClick:()=>zt(t.id),disabled:p===t.id,style:{padding:"5px 8px",background:"#8b5cf6",color:"white",border:"none",borderRadius:"6px",cursor:"pointer",fontSize:"12px",opacity:p===t.id?.7:1},children:p===t.id?"...":"Build"}),(t.status==="ready"||t.status==="paused")&&e.jsx("button",{onClick:()=>Rt(t.id),disabled:p===t.id,style:{padding:"5px 8px",background:"#059669",color:"white",border:"none",borderRadius:"6px",cursor:"pointer",fontSize:"12px",opacity:p===t.id?.7:1},children:p===t.id?"...":"Activate"}),t.status==="active"&&e.jsx("button",{onClick:()=>Tt(t.id),disabled:p===t.id,style:{padding:"5px 8px",background:"#f59e0b",color:"white",border:"none",borderRadius:"6px",cursor:"pointer",fontSize:"12px",opacity:p===t.id?.7:1},children:p===t.id?"...":"Pause"}),(t.status==="active"||t.status==="paused"||t.status==="ready")&&e.jsx("button",{onClick:()=>Nt(t.id),disabled:p===t.id,style:{padding:"5px 8px",background:"#dc2626",color:"white",border:"none",borderRadius:"6px",cursor:"pointer",fontSize:"12px",opacity:p===t.id?.7:1},children:p===t.id?"...":"🛑 Stop"}),bt(t)&&e.jsx("button",{onClick:()=>Wt(t.id),disabled:p===t.id,style:{padding:"5px 8px",background:"#ef4444",color:"white",border:"none",borderRadius:"6px",cursor:"pointer",fontSize:"12px",opacity:p===t.id?.7:1},children:"Delete"}),mt(t)&&e.jsx("button",{onClick:()=>yt(t.id),disabled:p===t.id,style:{padding:"5px 8px",background:"#6b7280",color:"white",border:"none",borderRadius:"6px",cursor:"pointer",fontSize:"12px"},children:"Archive"}),t.archived&&e.jsx("button",{onClick:()=>ft(t.id),disabled:p===t.id,style:{padding:"5px 8px",background:"#4f46e5",color:"white",border:"none",borderRadius:"6px",cursor:"pointer",fontSize:"12px"},children:"Unarchive"}),(t.status==="active"||t.status==="paused")&&t.sent_count>0&&e.jsx("span",{style:{fontSize:"11px",color:"#9ca3af",alignSelf:"center"},children:"Stop first, then Archive"})]})})]},t.id))})]})}),tt&&e.jsx("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},children:e.jsxs("div",{style:{background:"white",borderRadius:"12px",padding:"24px",width:"90%",maxWidth:"600px",maxHeight:"90vh",overflow:"auto"},children:[e.jsx("h2",{style:{marginTop:0,marginBottom:"20px"},children:"Create New Campaign"}),e.jsxs("form",{onSubmit:At,children:[e.jsxs("div",{style:{marginBottom:"16
1px"},children:[e.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:600},children:"Campaign Name"}),e.jsx("input",{type:"text",value:n.name,onChange:t=>h({...n,name:t.target.value}),required:!0,placeholder:"e.g., January Survey 2026",style:{width:"100%",padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"}})]}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr",gap:"16px",marginBottom:"16px"},children:e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:600},children:"Template"}),e.jsxs("select",{value:n.template_alias,onChange:t=>{const i=L.find(r=>r.alias===t.target.value);h({...n,template_alias:t.target.value,postmark_template_id:i?String(i.id):n.postmark_template_id})},required:!0,style:{width:"100%",padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"},children:[e.jsx("option",{value:"",children:"— select a template —"}),L.map(t=>e.jsxs("option",{value:t.alias,children:[t.name," (",t.alias,")"]},t.alias)),n.template_alias&&!L.some(t=>t.alias===n.template_alias)&&e.jsxs("option",{value:n.template_alias,children:[n.template_alias," — not a valid Postmark alias"]})]}),!Ie&&e.jsx("div",{style:{fontSize:"12px",color:"#b45309",marginTop:"4px"},children:"Could not reach Postmark — the list may be incomplete. Existing value kept."})]})}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:600},children:"Subject"}),e.jsx("input",{type:"text",value:n.subject,onChange:t=>h({...n,subject:t.target.value}),required:!0,style:{width:"100%",padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"}})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",marginBottom:"4px",fontWeight:600},children:["Preheader ",e.jsx("span",{style:{color:"#9ca3af",fontWeight:400},children:"(optional)"})]}),e.jsx("input",{type:"text",value:n.preheader,onChange:t=>h({...n,preheader:t.target.value}),placeholder:"Preview text shown in inbox...",style:{width:"100%",padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"}})]}),e.jsx(Ut,{value:M,onChange:Ne}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:600},children:"Audience Type"}),e.jsx("select",{value:n.audience_type,onChange:t=>{const i=t.target.value;h({...n,audience_type:i,audience_quality_filters:[]}),i!=="petition_update"&&i!=="newsletter"&&_(null),i!=="petition_update"&&(Q(null),fe({subject:"",body:""}))},style:{width:"100%",padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"},children:ne.map(t=>e.jsxs("option",{value:t.value,children:[t.label," - ",t.description]},t.value))})]}),n.audience_type==="segment"&&e.jsxs("div",{style:{marginBottom:"16px",padding:"16px",background:"#f5f3ff",borderRadius:"8px",border:"1px solid #ddd6fe"},children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:600,color:"#5b21b6"},children:"Search Target Petition"}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:I,onChange:t=>w(t.target.value),onKeyPress:t=>t.key==="Enter"&&(t.preventDefault(),z()),placeholder:"Enter petition name...",style:{flex:1,padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"}}),e.jsx("button",{type:"button",onClick:z,disabled:A,style:{padding:"10px 16px",background:"#5b21b6",color:"white",border:"none",borderRadius:"6px",cursor:"pointer"},children:A?"...":"🔍"})]}),C.length>0&&e.jsx("div",{style:{marginTop:"8px",border:"1px solid #d1d5db",borderRadius:"6px",maxHeight:"150px",overflow:"auto"},children:C.map(t=>e.jsx("div",{onClick:()=>{_(t),B([])},style:{padding:"10px",cursor:"pointer",borderBottom:"1px solid #e5e7eb",background:"white"},onMouseOver:i=>i.currentTarget.style.background="#f3f4f6",onMouseOut:i=>i.currentTarget.style.background="white",children:t.title},t.id))}),u&&e.jsxs("div",{style:{marginTop:"8px",padding:"10px",background:"white",borderRadius:"6px",border:"1px solid #d1d5db"},children:[e.jsxs("div",{style:{fontWeight:600},children:["✅ Promoting: ",u.title]}),e.jsx("div",{style:{fontSize:"13px",color:"#6b7280",marginTop:"4px"},children:"Users who haven't signed this petition will receive the campaign"})]})]}),e.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:600,color:"#5b21b6"},children:"🗂️ בחר קטגוריה"}),e.jsxs("select",{value:H??"",onChange:t=>{const i=t.target.value||null;Se(i),h({...n,segment_id:null})},style:{width:"100%",padding:"10px",border:"1px solid #ddd6fe",borderRadius:"6px",background:"#f5f3ff"},children:[e.jsx("option",{value:"",children:"— בחר קטגוריה —"}),ve.map(t=>e.jsx("option",{value:t.key,children:t.display},t.key))]}),H&&e.jsxs(e.Fragment,{children:[e.jsx("label",{style:{display:"block",margin:"12px 0 4px",fontWeight:600,color:"#5b21b6"},children:"👥 בחר קבוצת מנויים"}),e.jsxs("select",{value:n.segment_id??"",onChange:t=>h({...n,segment_id:t.target.value?Number(t.target.value):null}),style:{width:"100%",padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"},children:[e.jsx("option",{value:"",children:"— בחר קבוצה —"}),N.filter(t=>t.category===H).map(t=>e.jsxs("option",{value:t.id,children:[t.display_name," (",t.member_count.toLocaleStr
1ing("he-IL")," תומכים)"]},t.id))]}),N.filter(t=>t.category===H).length===0&&e.jsx("div",{style:{fontSize:"13px",color:"#9ca3af",marginTop:"6px"},children:"לא נמצאו קבוצות בקטגוריה זו"})]})]}),n.audience_type==="newsletter"&&e.jsxs("div",{style:{marginBottom:"16px",padding:"16px",background:"#eff6ff",borderRadius:"8px",border:"1px solid #bfdbfe"},children:[e.jsx("h4",{style:{margin:"0 0 12px 0",color:"#1e40af"},children:"📰 Newsletter Settings - Select Petition to Promote"}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:600},children:"Search Target Petition"}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:I,onChange:t=>w(t.target.value),onKeyPress:t=>t.key==="Enter"&&(t.preventDefault(),z()),placeholder:"Enter petition name...",style:{flex:1,padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"}}),e.jsx("button",{type:"button",onClick:z,disabled:A,style:{padding:"10px 16px",background:"#1e40af",color:"white",border:"none",borderRadius:"6px",cursor:"pointer"},children:A?"...":"🔍"})]}),C.length>0&&e.jsx("div",{style:{marginTop:"8px",border:"1px solid #d1d5db",borderRadius:"6px",maxHeight:"150px",overflow:"auto"},children:C.map(t=>e.jsx("div",{onClick:()=>{_(t),B([])},style:{padding:"10px",cursor:"pointer",borderBottom:"1px solid #e5e7eb",background:"white"},onMouseOver:i=>i.currentTarget.style.background="#f3f4f6",onMouseOut:i=>i.currentTarget.style.background="white",children:t.title},t.id))})]}),u&&e.jsxs("div",{style:{padding:"10px",background:"white",borderRadius:"6px",border:"1px solid #d1d5db"},children:[e.jsxs("div",{style:{fontWeight:600},children:["✅ Promoting: ",u.title]}),e.jsx("div",{style:{fontSize:"13px",color:"#6b7280",marginTop:"4px"},children:"Users who haven't signed this petition will receive the newsletter"})]}),e.jsxs("div",{style:{marginTop:"16px"},children:[e.jsx("label",{style:{display:"block",marginBottom:"8px",fontWeight:600,fontSize:"14px"},children:"Audience Quality Filter"}),e.jsx("p",{style:{fontSize:"12px",color:"#6b7280",marginBottom:"12px"},children:"Select which audience groups to include (at least one required)"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"8px",cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:n.audience_quality_filters.includes("human_openers"),onChange:t=>{const i=t.target.checked?[...n.audience_quality_filters,"human_openers"]:n.audience_quality_filters.filter(r=>r!=="human_openers");h({...n,audience_quality_filters:i})},style:{width:"16px",height:"16px"}}),e.jsx("span",{style:{fontWeight:500},children:"Human Openers"}),e.jsx("span",{style:{fontSize:"12px",color:"#6b7280"},children:"— Authenticity score ≥ 40 (best quality)"})]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"8px",cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:n.audience_quality_filters.includes("moderate_openers"),onChange:t=>{const i=t.target.checked?[...n.audience_quality_filters,"moderate_openers"]:n.audience_quality_filters.filter(r=>r!=="moderate_openers");h({...n,audience_quality_filters:i})},style:{width:"16px",height:"16px"}}),e.jsx("span",{style:{fontWeight:500},children:"Moderate Openers"}),e.jsx("span",{style:{fontSize:"12px",color:"#6b7280"},children:"— Authenticity score 20-40 (uncertain)"})]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"8px",cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:n.audience_quality_filters.includes("engaged_users"),onChange:t=>{const i=t.target.checked?[...n.audience_quality_filters,"engaged_users"]:n.audience_quality_filters.filter(r=>r!=="engaged_users");h({...n,audience_quality_filters:i})},style:{width:"16px",height:"16px"}}),e.jsx("span",{style:{fontWeight:500},children:"Engaged Users"}),e.jsx("span",{style:{fontSize:"12px",color:"#6b7280"},children:"— Engagement score ≥ 20 (clicks, multiple signs, payments)"})]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"8px",cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:n.audience_quality_filters.includes("re_engagement"),onChange:t=>{const i=t.target.checked?[...n.audience_quality_filters,"re_engagement"]:n.audience_quality_filters.filter(r=>r!=="re_engagement");h({...n,audience_quality_filters:i})},style:{width:"16px",height:"16px"}}),e.jsx("span",{style:{fontWeight:500},children:"Re-engagement"}),e.jsx("span",{style:{fontSize:"12px",color:"#6b7280"},children:"— Authenticity score < 20 (low confidence)"})]})]}),n.audience_quality_filters.length===0&&e.jsx("p",{style:{color:"#dc2626",fontSize:"12px",marginTop:"8px"},children:"⚠️ At least one filter must be selected"})]}),e.jsxs("div",{style:{marginTop:"16px",paddingTop:"16px",borderTop:"1px solid #bfdbfe"},children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:n.one_click_enabled,onChange:t=>h({...n,one_click_enabled:t.target.checked}),style:{width:"16px",height:"16px"}}),e.jsx("span",{style:{fontWeight:600},children:"Enable one-click signing"})]}),e.jsx("p",{style:{fontSize:"12px",color:"#6b7280",marginTop:"4px",marginLeft:"26px"},children:"Recipients can sign with a single click from the email. Requires a matching Postmark template."})]})]}),["newsletter","segment"].includes(n.audience_type)&&e.jsxs("div",{style:{marginBottom:"16
1px",padding:"16px",background:"#eff6ff",borderRadius:"8px",border:"1px solid #bfdbfe"},children:[e.jsxs("label",{className:"flex cursor-pointer items-center gap-2.5",children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4",checked:n.embed_promoted_petitions,onChange:t=>h({...n,embed_promoted_petitions:t.target.checked})}),e.jsx("span",{className:"font-semibold",children:"Attach promoted petitions to bottom of email"})]}),e.jsx("p",{className:"ml-7 mt-1 text-xs text-gray-500",children:"Adds a section of promoted petition cards at the bottom of the newsletter. Selection runs at dispatch time (highest remaining first, excluding this campaign's main petition)."}),n.embed_promoted_petitions&&e.jsxs("div",{className:"ml-7 mt-3 space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-semibold text-gray-700",children:"How many cards"}),e.jsxs("select",{className:"rounded-md border border-gray-300 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500",value:n.embed_petition_count,onChange:t=>h({...n,embed_petition_count:Number(t.target.value)}),children:[e.jsx("option",{value:6,children:"6 petitions"}),e.jsx("option",{value:7,children:"7 petitions"}),e.jsx("option",{value:8,children:"8 petitions"})]})]}),e.jsxs("div",{className:"rounded-md border border-gray-200 bg-white p-3",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-gray-500",children:"Preview — as of now"}),ye&&e.jsx("span",{className:"text-xs text-gray-400",children:"Loading…"})]}),!ye&&T&&T.petitions.length===0&&e.jsx("p",{className:"text-xs text-gray-500",children:T.note??"No inventory available right now."}),!ye&&T&&T.petitions.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("ol",{className:"space-y-2",children:T.petitions.map(t=>e.jsxs("li",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"w-5 shrink-0 text-right text-xs font-semibold text-gray-400",children:[t.position,"."]}),t.image_url?e.jsx("img",{src:t.image_url,alt:"",className:"h-9 w-9 shrink-0 rounded object-cover"}):e.jsx("div",{className:"h-9 w-9 shrink-0 rounded bg-gray-100"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm font-medium text-gray-800",children:t.title}),e.jsxs("p",{className:"text-xs text-gray-500",children:[t.current_signatures_count.toLocaleString()," signed"]})]})]},t.petition_id))}),T.note&&e.jsx("p",{className:"mt-3 text-xs italic text-gray-400",children:T.note})]})]})]})]}),n.audience_type==="petition_update"&&e.jsxs("div",{style:{marginBottom:"16px",padding:"16px",background:"#f0fdf4",borderRadius:"8px",border:"1px solid #bbf7d0"},children:[e.jsx("h4",{style:{margin:"0 0 12px 0",color:"#166534"},children:"📋 Petition Update Settings"}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:600},children:"Search Petition"}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:I,onChange:t=>w(t.target.value),onKeyPress:t=>t.key==="Enter"&&(t.preventDefault(),z()),placeholder:"Enter petition name...",style:{flex:1,padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"}}),e.jsx("button",{type:"button",onClick:z,disabled:A,style:{padding:"10px 16px",background:"#059669",color:"white",border:"none",borderRadius:"6px",cursor:"pointer"},children:A?"...":"🔍"})]}),C.length>0&&e.jsx("div",{style:{marginTop:"8px",border:"1px solid #d1d5db",borderRadius:"6px",maxHeight:"150px",overflow:"auto"},children:C.map(t=>e.jsx("div",{onClick:()=>Ct(t),style:{padding:"10px",cursor:"pointer",borderBottom:"1px solid #e5e7eb",background:"white"},onMouseOver:i=>i.currentTarget.style.background="#f3f4f6",onMouseOut:i=>i.currentTarget.style.background="white",children:t.title},t.id))})]}),u&&e.jsxs("div",{style:{marginBottom:"12px",padding:"10px",background:"white",borderRadius:"6px",border:"1px solid #d1d5db"},children:[e.jsxs("div",{style:{fontWeight:600,marginBottom:"4px"},children:["✅ Selected: ",u.title]}),q?e.jsxs("div",{style:{fontSize:"13px",color:"#059669"}
1,children:["📝 Update: ",q.title," (",new Date(q.created_at).toLocaleDateString(),")"]}):e.jsx("div",{style:{fontSize:"13px",color:"#dc2626"},children:"⚠️ No unsent update found"})]}),u&&q&&e.jsx(e.Fragment,{children:e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsxs("label",{style:{display:"block",marginBottom:"4px",fontWeight:600},children:["Email Body ",e.jsx("span",{style:{color:"#dc2626"},children:"*"})]}),e.jsx("textarea",{value:Z.body,onChange:t=>fe({...Z,body:t.target.value}),placeholder:"Enter the email content...",rows:6,style:{width:"100%",padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px",resize:"vertical"}}),e.jsx("div",{style:{fontSize:"12px",color:"#6b7280",marginTop:"4px"},children:"This content will be sent to all petition signers"})]})})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"16px",marginBottom:"16px"},children:[e.jsxs("div",{children:[e.jsxs("label",{style:{display:"block",marginBottom:"4px",fontWeight:600},children:["Signature Date From",e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"#6b7280",marginLeft:"6px"},children:"(optional — leave empty for all users)"})]}),e.jsx("input",{type:"date",value:n.date_from,onChange:t=>h({...n,date_from:t.target.value}),required:!0,style:{width:"100%",padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"}})]}),e.jsxs("div",{children:[e.jsxs("label",{style:{display:"block",marginBottom:"4px",fontWeight:600},children:["Signature Date To",e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"#6b7280",marginLeft:"6px"},children:"(optional — leave empty for all users)"})]}),e.jsx("input",{type:"date",value:n.date_to,onChange:t=>h({...n,date_to:t.target.value}),required:!0,style:{width:"100%",padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"}})]})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",marginBottom:"4px",fontWeight:600},children:["Campaign Expiry Date",e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"#6b7280",marginLeft:"8px"},children:"(optional — campaign stops sending after this date)"})]}),e.jsx("input",{type:"date",value:n.expires_at,onChange:t=>h({...n,expires_at:t.target.value}),style:{width:"100%",padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"}}),e.jsx("div",{style:{fontSize:"11px",color:"#6b7280",marginTop:"4px"},children:"Leave empty for no expiry. Campaign will continue until manually stopped."})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("button",{type:"button",onClick:Bt,disabled:Ee,style:{padding:"8px 16px",background:"#6366f1",color:"white",border:"none",borderRadius:"6px",cursor:"pointer",fontSize:"13px"},children:Ee?"Loading...":"🔍 Preview Audience"}),j&&e.jsxs("div",{style:{marginTop:"12px",padding:"14px",background:"#f3f4f6",borderRadius:"8px",fontSize:"13px"},children:[e.jsxs("div",{style:{fontWeight:700,marginBottom:"10px",fontSize:"14px"},children:["Audience Preview — ",j.petition_title]}),j.throttle_warning==="red"&&e.jsxs("div",{style:{background:"#fee2e2",border:"1px solid #fca5a5",borderRadius:"6px",padding:"8px 10px",marginBottom:"10px",color:"#991b1b"},children:["🔴 ",e.jsx("strong",{children:"High throttle risk:"})," ",j.active_campaigns," newsletter campaigns active. Recipients shared across campaigns will only receive 1 email per day — actual reach may be ~",Math.round(j.breakdown.final_estimate/j.active_campaigns).toLocaleString()," per campaign."]}),j.throttle_warning==="yellow"&&e.jsxs("div",{style:{background:"#fef9c3",border:"1px solid #fde047",borderRadius:"6px",padding:"8px 10px",marginBottom:"10px",color:"#854d0e"},children:["⚠️ ",e.jsx("strong",{children:"Throttle warning:"})," ",j.active_campaigns," newsletter campaigns active. Shared audience will receive only 1 per day."]}),e.jsx("table",{style:{width:"100%",borderCollapse:"collapse"},children:e.jsxs("tbody",{children:[e.jsxs("tr",{children:[e.jsx("td",{style:{padding:"4px 0",color:"#374151"},children:"Total eligible (quality + date)"}),e.jsx("td",{style:{textAlign:"right",fontWeight:600}
1,children:j.breakdown.total_eligible.toLocaleString()})]}),e.jsxs("tr",{style:{color:"#6b7280"},children:[e.jsx("td",{style:{padding:"4px 0 4px 12px"},children:"− Already received this template"}),e.jsxs("td",{style:{textAlign:"right"},children:["−",j.breakdown.removed_template.toLocaleString()]})]}),e.jsxs("tr",{style:{color:"#6b7280"},children:[e.jsx("td",{style:{padding:"4px 0 4px 12px"},children:"− Already signed target petition"}),e.jsxs("td",{style:{textAlign:"right"},children:["−",j.breakdown.removed_signed.toLocaleString()]})]}),e.jsxs("tr",{style:{color:"#6b7280"},children:[e.jsx("td",{style:{padding:"4px 0 4px 12px"},children:"− Unsubscribed / Blocked"}),e.jsxs("td",{style:{textAlign:"right"},children:["−",(j.breakdown.removed_blocked+j.breakdown.removed_unsubscribed).toLocaleString()]})]}),e.jsxs("tr",{style:{color:"#6b7280"},children:[e.jsx("td",{style:{padding:"4px 0 4px 12px"},children:"− Email validation failures (~5.5%)"}),e.jsxs("td",{style:{textAlign:"right"},children:["−",j.breakdown.validation_skip_est.toLocaleString()]})]}),e.jsxs("tr",{style:{borderTop:"2px solid #d1d5db"},children:[e.jsx("td",{style:{padding:"8px 0 4px",fontWeight:700,fontSize:"14px",color:"#059669"},children:"✅ Estimated recipients"}),e.jsx("td",{style:{textAlign:"right",fontWeight:700,fontSize:"15px",color:"#059669"},children:j.breakdown.final_estimate.toLocaleString()})]})]})}),e.jsx("div",{style:{marginTop:"10px",padding:"8px",background:"#e0f2fe",borderRadius:"6px",color:"#0369a1",fontSize:"12px"},children:j.active_campaigns<=1?`1 campaign/day: ~${j.breakdown.final_estimate.toLocaleString()} sent in 1 day`:`Running alongside ${j.active_campaigns-1} other active campaign(s) — throttle will reduce per-campaign reach`})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:"16px",marginBottom:"24px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:600},children:"Daily Limit"}),e.jsx("input",{type:"number",value:n.daily_limit,onChange:t=>h({...n,daily_limit:parseInt(t.target.value)}),min:1,max:2e5,style:{width:"100%",padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"}})]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:600},children:"Start Hour (NY)"}),e.jsx("input",{type:"number",value:n.start_hour,onChange:t=>h({...n,start_hour:parseInt(t.target.value)}),min:0,max:23,style:{width:"100%",padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"}})]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:600},children:"End Hour (NY)"}),e.jsx("input",{type:"number",value:n.end_hour,onChange:t=>h({...n,end_hour:parseInt(t.target.value)}),min:0,max:23,style:{width:"100%",padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"}})]})]}),e.jsxs("div",{style:{display:"flex",gap:"12px",justifyContent:"flex-end"},children:[e.jsx("button",{type:"button",onClick:()=>{se(!1),Ke()},style:{padding:"10px 20px",background:"#e5e7eb",color:"#374151",border:"none",borderRadius:"6px",cursor:"pointer"},children:"Cancel"}),e.jsx("button",{type:"submit","data-testid":"create-submit",disabled:p===-1||ie(M)!==null,style:{padding:"10px 20px",background:"#059669",color:"white",border:"none",borderRadius:"6px",cursor:"pointer",opacity:p===-1||ie(M)!==null?.7:1},children:p===-1?"Creating...":"Create Campaign"})]})]})]})}),it&&we&&e.jsx("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},children:e.jsxs("div",{style:{background:"white",borderRadius:"12px",padding:"24px",width:"90%",maxWidth:"800px",maxHeight:"90vh",overflow:"auto"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"20px"},children:[e.jsx("h2",{style:{margin:0},children:we.name}),e.jsx("button",{onClick:()=>{ke(!1),Ce(null)},style:{background:"none",border:"none",fontSize:"24px",cursor:"pointer"},children:"✕"})]}),ae?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(5, 1fr)",gap:"12px",marginBottom:"24px"},children:Object.entries(ae.recipient_stats).map(([t,i])=>e.jsxs("div",{style:{padding:"16px",background:"#f9fafb",borderRadius:"8px",textAlign:"center"},children:[e.jsx("div",{style:{fontSize:"24px",fontWeight:"bold",color:"#111827"},children:i}),e.jsx("div",{style:{fontSize:"12px",color:"#6b7280",textTransform:"capitalize"},children:t})]},t))}),e.jsx("h3",{style:{marginBottom:"12px"},children:"Recent Recipients"}),e.jsx("div",{style:{maxHeight:"300px",overflow:"auto",border:"1px solid #e5e7eb",borderRadius:"8px"},children:e.jsxs("table",{style:{width:"100%",borderCollapse:"collapse"},children:[e.jsx("thead",{children:e.jsxs("tr",{style:{background:"#f9fafb"},children:[e.jsx("th",{style:{padding:"8px 12px",textAlign:"left",fontSize:"12px"},children:"Email"}),e.jsx("th",{style:{padding:"8px 12px",textAlign:"center",fontSize:"12px"},children:"Status"}),e.jsx("th",{style:{padding:"8px 12px",textAlign:"left",fontSize:"12px"},children:"Scheduled"}),e.jsx("th",{style:{padding:"8px 12px",textAlign:"left",fontSize:"12px"},children:"Sent"})]})}),e.jsx("tbody",{children:ae.recent_recipients.map(t=>e.jsxs("tr",{style:{borderTop:"1px solid #e5e7eb"},children:[e.jsx("td",{style:{padding:"8px 12px",fontSize:"13px"},children:t.email}),e.jsx("td",{style:{padding:"8px 12px",textAlign:"center"},children:_e(t.status)}),e.jsx("td",{style:{padding:"8px 12px",fontSize:"12px",color:"#6b7280"},children:t.scheduled_at||"-"}),e.jsx("td",{style:{padding:"8px 12px",fontSize:"12px",color:"#6b7280"},children:t.sent_at||"-"})]},t.id))})]})})]}):e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"#6b7280"},children:"Loading..."})]})}),st&&c&&e.jsx("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},children:e.jsxs("div",{style:{background:"white",borderRadius:"12px",padding:"24px",width:"90%",maxWidth:"600px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"20px"},children:[e.jsx("h2",{style:{margin:0},children:"ℹ️ Campaign Info"}),e.jsx("button",{onClick:()=>{de(!1),le(null)},style:{background:"none",border:"none",fontSize:"24px",cursor:"pointer"},children:"✕"})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"16px"},children:[e.jsxs("div",{style:{padding:"12px",background:"#f9fafb",borderRadius:"8px"},children:[e.jsx("div",{style:{fontSize:"12px",color:"#6b7280",marginBottom:"4px"},children:"Campaign Name"}),e.jsx("div",{style:{fontWeight:600},children:c.name})]}),e.jsxs("div",{style:{padding:"12px",background:"#f9fafb",borderRadius:"8px"},children:[e.jsx("div",{style:{fontSize:"12px",color:"#6b7280",marginBottom:"4px"},children:"Status"}),e.jsx("div",{style:{fontWeight:600},children:_e(c.status)})]}),e.jsxs("div",{style:{padding:"12px",background:"#f9fafb",borderRadius:"8px"},children:[e.jsx("div",{style:{fontSize:"12px",color:"#6b7280",marginBottom:"4px"},children:"Template Alias"}),e.jsx("div",{style:{fontWeight:600},children:c.template_alias})]}),e.jsxs("div",{style:{padding:"12px",background:"#f9fafb",borderRadius:"8px"},children:[e.jsx("div",{style:{fontSize:"12px",color:"#6b7280",marginBottom:"4px"},children:"Subject"}),e.jsx("div",{style:{fontWeight:600},children:c.subject})]}),e.jsxs("div",{style:{padding:"12px",background:"#f9fafb",borderRadius:"8px"},children:[e.jsx("div",{style:{fontSize:"12px",color:"#6b7280",marginBottom:"4px"},children:"Audience Type"}),e.jsx("div",{style:{fontWeight:600},children:Ve(c.audience_type)})]}),c.audience_type==="segment"&&c.segment_id&&(()=>{const t=Ht(N,c.segment_id);return t?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{padding:"12px",background:"#f9fafb",borderRadius:"8px"},children:[e.jsx("div",{style:{fontSize:"12px",color:"#6b7280",marginBottom:"4px"},children:"Segment Category"}),e.jsx("div",{style:{fontWeight:600},children:t.category_display||t.category})]}),e.jsxs("div",{style:{padding:"12px",background:"#f9fafb",borderRadius:"8px"},children:[e.jsx("div",{style:{fontSize:"12px",color:"#6b7280",marginBottom:"4px"},children:"Segment Group"}),e.jsxs("div",{style:{fontWeight:600}
1,children:[t.display_name," (",(t.member_count??0).toLocaleString("he-IL")," תומכים)"]})]})]}):null})(),e.jsxs("div",{style:{padding:"12px",background:"#f9fafb",borderRadius:"8px"},children:[e.jsx("div",{style:{fontSize:"12px",color:"#6b7280",marginBottom:"4px"},children:"Total Recipients"}),e.jsx("div",{style:{fontWeight:600},children:c.total_recipients})]}),e.jsxs("div",{style:{padding:"12px",background:"#f9fafb",borderRadius:"8px"},children:[e.jsx("div",{style:{fontSize:"12px",color:"#6b7280",marginBottom:"4px"},children:"Signature Date Range"}),e.jsxs("div",{style:{fontWeight:600},children:[c.date_from," → ",c.date_to]})]}),e.jsxs("div",{style:{padding:"12px",background:"#f9fafb",borderRadius:"8px"},children:[e.jsx("div",{style:{fontSize:"12px",color:"#6b7280",marginBottom:"4px"},children:"Campaign Expiry"}),e.jsx("div",{style:{fontWeight:600,color:c.expires_at?"#dc2626":"#6b7280"},children:c.expires_at||"No expiry set"})]}),e.jsxs("div",{style:{padding:"12px",background:"#f9fafb",borderRadius:"8px"},children:[e.jsx("div",{style:{fontSize:"12px",color:"#6b7280",marginBottom:"4px"},children:"Daily Limit"}),e.jsx("div",{style:{fontWeight:600},children:c.daily_limit})]}),e.jsxs("div",{style:{padding:"12px",background:"#f9fafb",borderRadius:"8px"},children:[e.jsx("div",{style:{fontSize:"12px",color:"#6b7280",marginBottom:"4px"},children:"Created At"}),e.jsx("div",{style:{fontWeight:600},children:c.created_at})]}),e.jsxs("div",{style:{padding:"12px",background:"#f9fafb",borderRadius:"8px"},children:[e.jsx("div",{style:{fontSize:"12px",color:"#6b7280",marginBottom:"4px"},children:"Started At"}),e.jsx("div",{style:{fontWeight:600},children:c.started_at||"Not started"})]}),c.preheader&&e.jsxs("div",{style:{padding:"12px",background:"#f9fafb",borderRadius:"8px",gridColumn:"1 / -1"},children:[e.jsx("div",{style:{fontSize:"12px",color:"#6b7280",marginBottom:"4px"},children:"Preheader"}),e.jsx("div",{style:{fontWeight:600},children:c.preheader})]})]}),c.audience_type==="petition_update"&&c.email_content&&e.jsxs("div",{style:{marginTop:"16px",padding:"16px",background:"#f0fdf4",borderRadius:"8px",border:"1px solid #bbf7d0"},children:[e.jsx("h4",{style:{margin:"0 0 12px 0",color:"#166534"},children:"📋 Petition Update Details"}),c.petition_title&&e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsx("div",{style:{fontSize:"12px",color:"#6b7280"},children:"Petition"}),e.jsx("div",{style:{fontWeight:600},children:c.petition_title})]}),e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsx("div",{style:{fontSize:"12px",color:"#6b7280"},children:"Email Body"}),e.jsx("div",{style:{fontWeight:500,whiteSpace:"pre-wrap",background:"white",padding:"10px",borderRadius:"6px",marginTop:"4px"},children:c.email_content.body})]})]}),e.jsx("div",{style:{marginTop:"20px",textAlign:"right"},children:e.jsx("button",{onClick:()=>{de(!1),le(null)},style:{padding:"10px 20px",background:"#e5e7eb",color:"#374151",border:"none",borderRadius:"6px",cursor:"pointer"},children:"Close"})})]})}),rt&&S&&e.jsx("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},children:e.jsxs("div",{style:{background:"white",borderRadius:"12px",padding:"24px",width:"90%",maxWidth:"500px"},children:[e.jsxs("h2",{style:{marginTop:0,marginBottom:"20px"},children:["Edit Campaign: ",S.name]}),e.jsxs("form",{onSubmit:Ft,children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:600},children:"Campaign Name"}),e.jsx("input",{type:"text",value:a.name,onChange:t=>y({...a,name:t.target.value}),required:!0,style:{width:"100%",padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"}})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:600},children:"Subject"}),e.jsx("input",{type:"text",value:a.subject||"",onChange:t=>y({...a,subject:t.target.value}),required:!0,style:{width:"100%",padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"}})]}
1),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",marginBottom:"4px",fontWeight:600},children:["Preheader ",e.jsx("span",{style:{color:"#9ca3af",fontWeight:400},children:"(optional)"})]}),e.jsx("input",{type:"text",value:a.preheader||"",onChange:t=>y({...a,preheader:t.target.value}),placeholder:"Preview text shown in inbox...",style:{width:"100%",padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"}})]}),e.jsx("div",{style:{marginBottom:"16px"},children:e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:600},children:"Template"}),e.jsxs("select",{value:a.template_alias,onChange:t=>{L.find(i=>i.alias===t.target.value),y({...a,template_alias:t.target.value})},required:!0,style:{width:"100%",padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"},children:[e.jsx("option",{value:"",children:"— select a template —"}),L.map(t=>e.jsxs("option",{value:t.alias,children:[t.name," (",t.alias,")"]},t.alias)),a.template_alias&&!L.some(t=>t.alias===a.template_alias)&&e.jsxs("option",{value:a.template_alias,children:[a.template_alias," — not a valid Postmark alias"]})]}),!Ie&&e.jsx("div",{style:{fontSize:"12px",color:"#b45309",marginTop:"4px"},children:"Could not reach Postmark — the list may be incomplete. Existing value kept."})]})}),S?.status==="draft"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:600},children:"Audience Type"}),e.jsx("select",{value:a.audience_type,onChange:t=>{const i=t.target.value;y({...a,audience_type:i,audience_quality_filters:[],segment_id:i==="segment"?a.segment_id:null}),i!=="petition_update"&&i!=="newsletter"&&i!=="segment"&&_(null)},style:{width:"100%",padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"},children:ne.map(t=>e.jsxs("option",{value:t.value,children:[t.label," - ",t.description]},t.value))})]}),a.audience_type==="segment"&&e.jsxs("div",{style:{marginBottom:"16px",padding:"16px",background:"#f5f3ff",borderRadius:"8px",border:"1px solid #ddd6fe"},children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:600,color:"#5b21b6"},children:"Search Target Petition"}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:I,onChange:t=>w(t.target.value),onKeyPress:t=>t.key==="Enter"&&(t.preventDefault(),z()),placeholder:"Enter petition name...",style:{flex:1,padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"}}),e.jsx("button",{type:"button",onClick:z,disabled:A,style:{padding:"10px 16px",background:"#5b21b6",color:"white",border:"none",borderRadius:"6px",cursor:"pointer"},children:A?"...":"🔍"})]}),C.length>0&&e.jsx("div",{style:{marginTop:"8px",border:"1px solid #d1d5db",borderRadius:"6px",maxHeight:"150px",overflow:"auto"},children:C.map(t=>e.jsx("div",{onClick:()=>{_(t),B([])},style:{padding:"10px",cursor:"pointer",borderBottom:"1px solid #e5e7eb",background:"white"},onMouseOver:i=>i.currentTarget.style.background="#f3f4f6",onMouseOut:i=>i.currentTarget.style.background="white",children:t.title},t.id))}),u&&e.jsxs("div",{style:{marginTop:"8px",padding:"10px",background:"white",borderRadius:"6px",border:"1px solid #d1d5db"},children:[e.jsxs("div",{style:{fontWeight:600},children:["✅ Promoting: ",u.title]}),e.jsx("div",{style:{fontSize:"13px",color:"#6b7280",marginTop:"4px"},children:"Users who haven't signed this petition will receive the campaign"})]})]}),e.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:600,color:"#5b21b6"},children:"🗂️ בחר קטגוריה"}),e.jsxs("select",{value:K??"",onChange:t=>{const i=t.target.value||null;re(i),y({...a,segment_id:null})},style:{width:"100%",padding:"10px",border:"1px solid #ddd6fe",borderRadius:"6px",background:"#f5f3ff"},children:[e.jsx("option",{value:"",children:"— בחר קטגוריה —"}),ve.map(t=>e.jsx("option",{value:t.key,children:t.display},t.key))]}),K&&e.jsxs(e.Fragment,{children:[e.jsx("label",{style:{display:"block",margin:"12px 0 4px",fontWeight:600,color:"#5b21b6"},children:"👥 בחר קבוצת מנויים"}),e.jsxs("select",{value:a.segment_id??"",onChange:t=>y({...a,segment_id:t.target.value?Number(t.target.value):null}),style:{width:"100%",padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"},children:[e.jsx("option",{value:"",children:"— בחר קבוצה —"}),N.filter(t=>t.category===K).map(t=>e.jsxs("option",{value:t.id,children:[t.display_name," (",t.member_count.toLocaleStr
1ing("he-IL")," תומכים)"]},t.id))]}),N.filter(t=>t.category===K).length===0&&e.jsx("div",{style:{fontSize:"13px",color:"#9ca3af",marginTop:"6px"},children:"לא נמצאו קבוצות בקטגוריה זו"})]})]}),a.audience_type==="newsletter"&&e.jsxs("div",{style:{marginBottom:"16px",padding:"16px",background:"#eff6ff",borderRadius:"8px",border:"1px solid #bfdbfe"},children:[e.jsx("h4",{style:{margin:"0 0 12px 0",color:"#1e40af"},children:"📰 Newsletter Settings - Select Petition to Promote"}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:600},children:"Search Target Petition"}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:I,onChange:t=>w(t.target.value),onKeyPress:t=>t.key==="Enter"&&(t.preventDefault(),z()),placeholder:"Enter petition name...",style:{flex:1,padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"}}),e.jsx("button",{type:"button",onClick:z,disabled:A,style:{padding:"10px 16px",background:"#1e40af",color:"white",border:"none",borderRadius:"6px",cursor:"pointer"},children:A?"...":"🔍"})]}),C.length>0&&e.jsx("div",{style:{marginTop:"8px",border:"1px solid #d1d5db",borderRadius:"6px",maxHeight:"150px",overflow:"auto"},children:C.map(t=>e.jsx("div",{onClick:()=>{_(t),B([])},style:{padding:"10px",cursor:"pointer",borderBottom:"1px solid #e5e7eb",background:"white"},onMouseOver:i=>i.currentTarget.style.background="#f3f4f6",onMouseOut:i=>i.currentTarget.style.background="white",children:t.title},t.id))})]}),u&&e.jsxs("div",{style:{padding:"10px",background:"white",borderRadius:"6px",border:"1px solid #d1d5db"},children:[e.jsxs("div",{style:{fontWeight:600},children:["✅ Promoting: ",u.title]}),e.jsx("div",{style:{fontSize:"13px",color:"#6b7280",marginTop:"4px"},children:"Users who haven't signed this petition will receive the newsletter"})]}),e.jsxs("div",{style:{marginTop:"16px"},children:[e.jsx("label",{style:{display:"block",marginBottom:"8px",fontWeight:600,fontSize:"14px"},children:"Audience Quality Filter"}),e.jsx("p",{style:{fontSize:"12px",color:"#6b7280",marginBottom:"12px"},children:"Select which audience groups to include (at least one required)"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"8px",cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:a.audience_quality_filters.includes("human_openers"),onChange:t=>{const i=t.target.checked?[...a.audience_quality_filters,"human_openers"]:a.audience_quality_filters.filter(r=>r!=="human_openers");y({...a,audience_quality_filters:i})},style:{width:"16px",height:"16px"}}),e.jsx("span",{style:{fontWeight:500},children:"Human Openers"}),e.jsx("span",{style:{fontSize:"12px",color:"#6b7280"},children:"— Authenticity score ≥ 40 (best quality)"})]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"8px",cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:a.audience_quality_filters.includes("moderate_openers"),onChange:t=>{const i=t.target.checked?[...a.audience_quality_filters,"moderate_openers"]:a.audience_quality_filters.filter(r=>r!=="moderate_openers");y({...a,audience_quality_filters:i})},style:{width:"16px",height:"16px"}}),e.jsx("span",{style:{fontWeight:500},children:"Moderate Openers"}),e.jsx("span",{style:{fontSize:"12px",color:"#6b7280"},children:"— Authenticity score 20-40 (uncertain)"})]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"8px",cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:a.audience_quality_filters.includes("engaged_users"),onChange:t=>{const i=t.target.checked?[...a.audience_quality_filters,"engaged_users"]:a.audience_quality_filters.filter(r=>r!=="engaged_users");y({...a,audience_quality_filters:i})},style:{width:"16px",height:"16px"}}),e.jsx("span",{style:{fontWeight:500},children:"Engaged Users"}),e.jsx("span",{style:{fontSize:"12px",color:"#6b7280"},children:"— Engagement score ≥ 20 (clicks, multiple signs, payments)"})]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"8px",cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:a.audience_quality_filters.includes("re_engagement"),onChange:t=>{const i=t.target.checked?[...a.audience_quality_filters,"re_engagement"]:a.audience_quality_filters.filter(r=>r!=="re_engagement");y({...a,audience_quality_filters:i})},style:{width:"16px",height:"16px"}}),e.jsx("span",{style:{fontWeight:500},children:"Re-engagement"}),e.jsx("span",{style:{fontSize:"12px",color:"#6b7280"},children:"— Authenticity score < 20 (low confidence)"})]})]}),a.audience_quality_filters.length===0&&e.jsx("p",{style:{color:"#dc2626",fontSize:"12px",marginTop:"8px"},children:"⚠️ At least one filter must be selected"})]})]})]}),S?.audience_type==="petition_update"&&e.jsxs("div",{style:{marginBottom:"16
1px"},children:[e.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:600},children:"Email Body"}),e.jsx("textarea",{value:a.email_content?.body||"",onChange:t=>y({...a,email_content:{body:t.target.value}}),rows:5,style:{width:"100%",padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px",resize:"vertical"}})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"16px",marginBottom:"16px"},children:[e.jsxs("div",{children:[e.jsxs("label",{style:{display:"block",marginBottom:"4px",fontWeight:600},children:["Signature Date From",e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"#6b7280",marginLeft:"6px"},children:"(optional)"})]}),e.jsx("input",{type:"date",value:a.date_from,onChange:t=>y({...a,date_from:t.target.value}),required:!0,style:{width:"100%",padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"}})]}),e.jsxs("div",{children:[e.jsxs("label",{style:{display:"block",marginBottom:"4px",fontWeight:600},children:["Signature Date To",e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"#6b7280",marginLeft:"6px"},children:"(optional)"})]}),e.jsx("input",{type:"date",value:a.date_to,onChange:t=>y({...a,date_to:t.target.value}),required:!0,style:{width:"100%",padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"}})]})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",marginBottom:"4px",fontWeight:600},children:["Campaign Expiry Date",e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"#6b7280",marginLeft:"8px"},children:"(optional — campaign stops sending after this date)"})]}),e.jsx("input",{type:"date",value:a.expires_at,onChange:t=>y({...a,expires_at:t.target.value}),style:{width:"100%",padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"}}),e.jsx("div",{style:{fontSize:"11px",color:"#6b7280",marginTop:"4px"},children:"Leave empty for no expiry. Campaign will continue until manually stopped."})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:"16px",marginBottom:"24px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:600},children:"Daily Limit"}),e.jsx("input",{type:"number",value:a.daily_limit,onChange:t=>y({...a,daily_limit:parseInt(t.target.value)}),min:1,max:2e5,style:{width:"100%",padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"}})]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:600},children:"Start Hour (NY)"}),e.jsx("input",{type:"number",value:a.start_hour,onChange:t=>y({...a,start_hour:parseInt(t.target.value)}),min:0,max:23,style:{width:"100%",padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"}})]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:600},children:"End Hour (NY)"}),e.jsx("input",{type:"number",value:a.end_hour,onChange:t=>y({...a,end_hour:parseInt(t.target.value)}),min:0,max:23,style:{width:"100%",padding:"10px",border:"1px solid #d1d5db",borderRadius:"6px"}})]})]}),e.jsxs("div",{style:{display:"flex",gap:"12px",justifyContent:"flex-end"},children:[e.jsx("button",{type:"button",onClick:()=>{oe(!1),ge(null),_(null),B([]),w("")},style:{padding:"10px 20px",background:"#e5e7eb",color:"#374151",border:"none",borderRadius:"6px",cursor:"pointer"},children:"Cancel"}),e.jsx("button",{type:"submit",disabled:p===S.id,style:{padding:"10px 20px",background:"#059669",color:"white",border:"none",borderRadius:"6px",cursor:"pointer",opacity:p===S.id?.7:1},children:p===S.id?"Saving...":"Save Changes"})]})]})]})}),je&&e.jsx("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},children:e.jsxs("div",{style:{background:"white",borderRadius:"12px",padding:"24px",width:"90%",maxWidth:"1100px",maxHeight:"90vh",overflow:"auto"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"20px"},children:[e.jsx("h2",{style:{margin:0},children:"📋 Newsletter Email Templates"}),e.jsx("button",{onClick:()=>{ee(!1),U(null)},style:{background:"none",border:"none",fontSize:"24px",cursor:"pointer"},children:"✕"})]}),e.jsxs("div",{style:{padding:"16px",background:"#eff6ff",borderRadius:"8px",marginBottom:"20px",border:"1px solid #bfdbfe"},children:[e.jsx("h3",{style:{margin:"0 0 12px 0",color:"#1d4ed8"},children:W?`✏️ Edit: ${W.slug}`:"➕ New Template"}),e.jsxs("form",{onSubmit:St,children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"2fr 1fr 1fr",gap:"12px",marginBottom:"12px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:600,fontSize:"13px"},children:"Name (description only)"}),e.jsx("input",{type:"text",value:R.name,onChange:t=>P({...R,name:t.target.value}),required:!0,placeholder:"Newsletter Campaign - Stop Koala Killing",style:{width:"100%",padding:"8px",border:"1px solid #d1d5db",borderRadius:"6px",fontSize:"13px"}})]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:600,fontSize:"13px"},children:"Postmark Template Alias ⭐"}),e.jsx("input",{type:"text",value:R.postmark_template_id,onChange:t=>P({...R,postmark_template_id:t.target.value}),required:!0,placeholder:"koala-heli",style:{width:"100%",padding:"8px",border:"1px solid #1d4ed8",borderRadius:"6px",fontSize:"13px",fontFamily:"monospace"}}),e.jsx("div",{style:{fontSize:"11px",color:"#6b7280",marginTop:"2px"},children:"זה הקובע — חייב להתאים ל-Postmark"})]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",marginBottom:"4px",fontWeight:600,fontSize:"13px"},children:"Postmark Tag"}),e.jsx("input",{type:"text",value:R.postmark_tag,onChange:t=>P({...R,postmark_tag:t.target.value}),placeholder:"Newsletter",style:{width:"100%",padding:"8px",border:"1px solid #d1d5db",borderRadius:"6px",fontSize:"13px"}})]})]}),W&&e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"12px",cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:R.is_active,onChange:t=>P({...R,is_active:t.target.checked})}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600},children:"Active"})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("button",{type:"submit",style:{padding:"8px 20px",background:"#1d4ed8",color:"white",border:"none",borderRadius:"6px",cursor:"pointer",fontWeight:600},children:W?"Update Template":"Add Template"}),W&&e.jsx("button",{type:"button",onClick:()=>{U(null),P({name:"",postmark_template_id:"",postmark_tag:"Newsletter",is_active:!0})},style:{padding:"8px 16px",background:"#e5e7eb",color:"#374151",border:"none",borderRadius:"6px",cursor:"pointer"},children:"Cancel Edit"})]})]})]}),e.jsx("div",{style:{border:"1px solid #e5e7eb",borderRadius:"8px",overflow:"hidden"},children:e.jsxs("table",{style:{width:"100%",borderCollapse:"collapse"},children:[e.jsx("thead",{children:e.jsx("tr",{style:{background:"#f9fafb"},children:["ID","Name","Postmark Alias ⭐","Tag","Status","Created","Actions"].map(t=>e.jsx("th",{style:{padding:"10px 12px",textAlign:"left",fontSize:"12px",fontWeight:600,borderBottom:"2px s
1olid #e5e7eb"},children:t},t))})}),e.jsx("tbody",{children:ht?e.jsx("tr",{children:e.jsx("td",{colSpan:7,style:{padding:"20px",textAlign:"center",color:"#6b7280"},children:"Loading..."})}):De.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:7,style:{padding:"20px",textAlign:"center",color:"#6b7280"},children:"No newsletter templates found"})}):De.map((t,i)=>e.jsxs("tr",{style:{borderBottom:"1px solid #e5e7eb",background:i%2===0?"white":"#fafafa"},children:[e.jsx("td",{style:{padding:"10px 12px",fontSize:"13px",color:"#6b7280"},children:t.id}),e.jsx("td",{style:{padding:"10px 12px",fontSize:"13px",maxWidth:"380px"},children:e.jsx("div",{style:{whiteSpace:"normal",wordBreak:"break-word"},children:t.name})}),e.jsx("td",{style:{padding:"10px 12px"},children:e.jsx("code",{style:{background:"#dbeafe",padding:"2px 8px",borderRadius:"4px",fontSize:"12px",color:"#1d4ed8",fontWeight:600},children:t.postmark_template_id})}),e.jsx("td",{style:{padding:"10px 12px",fontSize:"12px",color:"#6b7280"},children:t.postmark_tag||"—"}),e.jsx("td",{style:{padding:"10px 12px"},children:e.jsx("span",{style:{padding:"2px 10px",borderRadius:"10px",fontSize:"11px",fontWeight:600,background:t.is_active?"#d1fae5":"#fee2e2",color:t.is_active?"#065f46":"#991b1b"},children:t.is_active?"Active":"Inactive"})}),e.jsx("td",{style:{padding:"10px 12px",fontSize:"11px",color:"#9ca3af"},children:new Date(t.created_at).toLocaleDateString()}),e.jsx("td",{style:{padding:"10px 12px"},children:e.jsx("button",{onClick:()=>kt(t),style:{padding:"4px 12px",background:"#6366f1",color:"white",border:"none",borderRadius:"6px",cursor:"pointer",fontSize:"12px"},children:"✏️ Edit"})})]},t.id))})]})}),e.jsx("div",{style:{marginTop:"16px",padding:"12px",background:"#fffbeb",borderRadius:"8px",border:"1px solid #fde68a"},children:e.jsxs("div",{style:{fontSize:"12px",color:"#92400e"},children:["⭐ ",e.jsx("strong",{children:"Postmark Template Alias"})," הוא הקובע — חייב להתאים בדיוק לשם ב-Postmark. שדה ה-Subject בטבלה אינו משפיע על השליחה — ה-Subject מוגדר ב-Postmark template."]})})]})})]})})};export{Gt as default};
2//# sourceMappingURL=ScheduledCampaigns-Z1F5i11J.js.map

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.