1import{R as de,j as e}from"./vendor-tiptap-CRdka2py.js";import{u as B,b as u}from"./vendor-i18n-Do9jGewF.js";import{T as V}from"./TagInput-C6v0_muM.js";import{aN as ae,r as me,a6 as ue,H as xe}from"./index-Dm1QE6j5.js";import{S as pe}from"./StartAutomationModal-BwibZo4D.js";import"./vendor-firebase-B7FTlnjY.js";import{l as ge,g as he,i as be,a as J,d as ve,u as Q}from"./messaging-CWIwYPol.js";import{S as O}from"./StatCard-26Grmr5x.js";import{G as fe,E as X}from"./EmptyState-Dh8d_QZo.js";import"./tagColors-B3Slt5VI.js";import"./tags-DHsATbOI.js";import"./useSegments-uVnVdJgp.js";import"./segments-ByZz70px.js";const ke=()=>`step-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,je=[0,30,60,180,1440,2880,4320,7200,10080,20160],ye={0:"automationList.delayImmediate",30:"emailAutomationEditor.delay30Min",60:"emailAutomationEditor.delay1Hour",180:"emailAutomationEditor.delay3Hours",1440:"emailAutomationEditor.delay1Day",2880:"emailAutomationEditor.delay2Days",4320:"emailAutomationEditor.delay3Days",7200:"emailAutomationEditor.delay5Days",10080:"emailAutomationEditor.delay7Days",20160:"emailAutomationEditor.delay14Days"},ze=[{value:"lead_created",labelKey:"emailAutomationEditor.triggerLeadCreatedFull"},{value:"tag_added",labelKey:"emailAutomationEditor.triggerTagAddedFull"}],Se=[{value:"member_created",labelKey:"emailAutomationEditor.triggerMemberCreatedFull"},{value:"tag_added",labelKey:"emailAutomationEditor.triggerTagAddedFull"},{value:"payment_received",labelKey:"automationList.triggerPaymentReceived"},{value:"trial_ending",labelKey:"emailAutomationEditor.triggerTrialEndingFull"}],we=[{value:"paymentStatus",labelKey:"emailAutomationEditor.fieldPaymentStatus"},{value:"subscriptionStatus",labelKey:"emailAutomationEditor.fieldSubscriptionStatus"},{value:"membershipType",labelKey:"emailAutomationEditor.fieldMembershipType"},{value:"tags",labelKey:"tagManagerPanel.pageTitle"}],Ne=[{value:"equals",labelKey:"emailAutomationEditor.opEquals"},{value:"not_equals",labelKey:"emailAutomationEditor.opNotEquals"},{value:"contains",labelKey:"emailAutomationEditor.opContains"},{value:"not_contains",labelKey:"emailAutomationEditor.opNotContains"}],Ae=[14,7,3,1],Z=()=>({id:ke(),action:"send_email",delayMinutes:0,templateId:"",subject:""}),Le=({automation:s,templates:l,campaigns:m,onSave:N,onClose:n})=>{const{t:i}=B(),z=je.map(t=>({value:t,label:i(ye[t])})),k=ze.map(t=>({value:t.value,label:i(t.labelKey)})),h=Se.map(t=>({value:t.value,label:i(t.labelKey)})),S=we.map(t=>({value:t.value,label:i(t.labelKey)})),g=Ne.map(t=>({value:t.value,label:i(t.labelKey)})),A=Ae.map(t=>({value:t,label:i("emailAutomationEditor.trialDaysBeforeOption",{count:t})})),[j,b]=u.useState(s?.name||""),[f,D]=u.useState(s?.recipientType||"lead"),[v,T]=u.useState(s?.trigger||"lead_created"),[r,a]=u.useState(s?.triggerConfig?.campaignIds||[]),[c,d]=u.useState(s?.triggerConfig?.tags||[]),[p,M]=u.useState(s?.triggerConfig?.trialDaysBefore||7),[L,ie]=u.useState(s?.isActive??!0),[C,F]=u.useState(s?.steps?.map(t=>({...t,action:t.action||"send_email"}))||[Z()]),[H,W]=u.useState(!1),ne=f==="lead"?k:h,K=t=>{D(t);const x=t==="lead"?k:h;x.find(y=>y.value===v)||T(x[0].value)},P=t=>{switch(t.action){case"send_email":return!!t.templateId;case"update_tags":return(t.addTags?.length||0)>0||(t.removeTags?.length||0)>0;case"condition":return!!t.conditionField&&!!t.conditionOperator&&!!t.conditionValue;default:return!1}},se=async()=>{if(!(!j.trim()||C.some(t=>!P(t)))&&!(v==="trial_ending"&&!p)){W(!0);try{await N({name:j.trim(),trigger:v,recipientType:f,triggerConfig:{campaignIds:r.length>0?r:void 0,tags:c.length>0?c:void 0,trialDaysBefore:v==="trial_ending"?p:void 0},isActive:L,steps:C})}finally{W(!1)}}},re=()=>{F(t=>[...t,{...Z(),delayMinutes:1440}])},oe=t=>{C.length<=1||F(x=>x.filter((y,o)=>o!==t))},E=(t,x)=>{F(y=>y.map((o,w)=>w===t?{...o,...x}:o))},le=(t,x)=>{F(y=>y.map((o,w)=>w!==t?o:{id:o.id,action:x,delayMinutes:o.delayMinutes,templateId:x==="send_email"?"":void 0,subject:x==="send_email"?"":void 0,addTags:x==="update_tags"?[]:void 0,removeTags:x==="update_tags"?[]:void 0,conditionField:x==="condition"?"paymentStatus":void 0,conditionOperator:x==="condition"?"equals":void 0,conditionValue:x==="condition"?"":void 0,falseStepIndex:x==="condition"?null:void 0}))},G=t=>{switch(t){case"send_email":return e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21.75 6.75v10.5a2.25 2.25 0 01-2.25 2.25h-15a2.25 2.25 0 01-2.25-2.25V6.75m19.5 0A2.25 2.25 0 0019.5 4.5h-15a2.25 2.25 0 00-2.25 2.25m19.5 0v.243a2.25 2.25 0 01-1.07 1.916l-7.5 4.615a2.25 2.25 0 01-2.36 0L3.32 8.91a2.25 2.25 0 01-1.07-1.916V6.75"})});case"update_tags":return e.jsxs("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9.568 3H5.25A2.25 2.25 0 003 5.25v4.318c0 .597.237 1.17.659 1.591l9.581 9.581c.699.699 1.78.872 2.607.33a18.095 18.095 0 005.223-5.223c.542-.827.369-1.908-.33-2.607L11.16 3.66A2.25 2.25 0 009.568 3z"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 6h.008v.008H6V6z"})]});case"condition":return e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M7.5 21L3 16.5m0 0L7.5 12M3 16.5h13.5m0-13.5L21 7.5m0 0L16.5 12M21 7.5H7.5"})})}},ce=t=>
1{if(!P(t))return"bg-zinc-200 dark:bg-zinc-700 text-zinc-500";switch(t.action){case"send_email":return"bg-primary text-white";case"update_tags":return"bg-violet-500 text-white";case"condition":return"bg-amber-500 text-white";default:return"bg-zinc-200 text-zinc-500"}},I="block text-[10px] font-black text-zinc-400 uppercase tracking-widest mb-2 ml-1",_="w-full px-4 py-3 rounded-xl bg-zinc-50 dark:bg-zinc-900 border border-zinc-200 dark:border-zinc-700 font-bold text-sm focus:ring-2 focus:ring-primary outline-none appearance-none",Y="px-4 py-2 rounded-xl text-[10px] font-black uppercase tracking-widest transition-all",U="bg-primary text-white shadow-lg shadow-red-600/20",q="bg-zinc-100 dark:bg-zinc-800 text-zinc-500 hover:text-zinc-900 dark:hover:text-white";return de.createPortal(e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm z-[170] flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-white dark:bg-dark-surface rounded-[2.5rem] shadow-2xl w-full max-w-2xl max-h-[90vh] overflow-hidden flex flex-col border border-zinc-200 dark:border-zinc-800",children:[e.jsxs("div",{className:"px-8 pt-6 pb-4 flex items-center justify-between border-b border-zinc-100 dark:border-zinc-800 shrink-0",children:[e.jsx("h2",{className:"text-2xl font-black text-zinc-900 dark:text-white uppercase tracking-tighter",children:i(s?"emailAutomationEditor.editTitle":"emailAutomationEditor.newTitle")}),e.jsx("button",{type:"button",onClick:n,className:"p-2 rounded-xl hover:bg-zinc-100 dark:hover:bg-zinc-800 transition-colors",children:e.jsx("svg",{className:"w-5 h-5 text-zinc-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2.5",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-8 py-6 space-y-6",children:[e.jsxs("div",{className:"flex gap-4 items-end",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{className:I,children:i("emailAutomationEditor.nameLabel")}),e.jsx("input",{value:j,onChange:t=>b(t.target.value),placeholder:i("emailAutomationEditor.namePlaceholder"),className:_})]}),e.jsx("button",{type:"button",onClick:()=>ie(!L),className:`px-5 py-3 rounded-xl font-black text-[10px] uppercase tracking-widest transition-all ${L?"bg-emerald-500 text-white shadow-lg shadow-emerald-500/20":"bg-zinc-200 dark:bg-zinc-800 text-zinc-500"}`,children:i(L?"automationList.activeBadge":"automationList.inactiveBadge")})]}),e.jsxs("div",{children:[e.jsx("label",{className:I,children:i("emailAutomationEditor.audienceLabel")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:()=>K("lead"),className:`${Y} ${f==="lead"?U:q}`,children:i("tagManagerPanel.statLeads")}),e.jsx("button",{type:"button",onClick:()=>K("user"),className:`${Y} ${f==="user"?U:q}`,children:i("tagManagerPanel.statMembers")})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:I,children:i("automationList.guideBannerTrigger")}),e.jsx("select",{value:v,onChange:t=>T(t.target.value),className:_,children:ne.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))})]}),v==="tag_added"&&e.jsxs("div",{children:[e.jsx("label",{className:I,children:i("emailAutomationEditor.tagFilterLabel")}),e.jsx(V,{tags:c,onChange:d,placeholder:i("emailAutomationEditor.tagFilterPlaceholder"),helpText:i("emailAutomationEditor.tagFilterHelpText",{subject:i(f==="lead"?"emailAutomationEditor.subjectLead":"emailAutomationEditor.subjectMember")}),inputClassName:_})]}),v==="lead_created"&&m.length>0&&e.jsxs("div",{children:[e.jsx("label",{className:I,children:i("emailAutomationEditor.campaignFilterLabel")}),e.jsx("p",{className:"text-[9px] text-zinc-400 mb-2 ml-1",children:i("emailAutomationEditor.campaignFilterHint")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:m.map(t=>{const x=r.includes(t.id);return e.jsx("button",{type:"button",onClick:()=>{a(y=>x?y.filter(o=>o!==t.id):[...y,t.id])},className:`px-3 py-1.5 rounded-lg text-[10px] font-bold uppercase tracking-wider transition-all ${x?"bg-primary text-white":"bg-zinc-100 dark:bg-zinc-800 text-zinc-500 hover:text-zinc-900 dark:hover:text-white"}`,children:t.name},t.id)})})]}),v==="trial_ending"&&e.jsxs("div",{children:[e.jsx("label",{className:I,children:i("emailAutomationEditor.triggerAutomationLabel")}),e.jsx("select",{value:p,onChange:t=>M(Number(t.target.value)),className:_,children:A.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))})]}),e.jsxs("div",{children:[e.jsx("label",{className:I,children:i("emailAutomationEditor.flowLabel")}),e.jsxs("div",{className:"space-y-4 relative",children:[C.length>1&&e.jsx("div",{className:"absolute left-[18px] top-6 bottom-6 w-0.5 bg-zinc-200 dark:bg-zinc-700"}),C.map((t,x)=>{const y=t.action||"send_email";return e.jsxs("div",{className:"relative flex gap-4 items-start",children:[e.jsx("div",{className:`w-9 h-9 rounded-full flex items-center justify-center shrink-0 z-10 ${ce(t)}`,children:G(y)}),e.jsxs("div",{className:"flex-1 bg-zinc-50 dark:bg-zinc-900/50 rounded-2xl border border-zinc-200 dark:border-zinc-800 p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("select",{value:t.delayMinutes,onChange:o=>E(x,{delayMinutes:Number(o.target.value)}),className:"px-3 py-1.5 rounded-lg bg-white dark:bg-zinc-800 border border-zinc-200 dark:border-zinc-700 text-[10px] font-bold uppercase tracking-wider outline-none appearance-none",children:z.map(o=>e.jsx("option",{value:o.value,children:o.label},o.value))}),e.jsx("span",{className:"text-[9px] text-zinc-400 font-bold uppercase tracking-widest",children:x===0?i("emailAutomationEditor.afterTrigger"):i("emailAutomationEditor.afterStep",{count:x})})]}),C.length>1&&e.jsx("button",{type:"button",onClick:()=>oe(x),className:"p-1.5 rounded-lg hover:bg-red-100 dark:hover:bg-red-900/20 text-red-400 hover:text-red-600 transition-colors",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2.5",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0"})})})]}),e.jsx("div",{className:"flex gap-1.5",children:["send_email","update_tags","condition"].map(o=>e.jsxs("button",{type:"button",onClick:()=>le(x,o),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[9px] font-black uppercase tracking-widest transition-all ${y===o?o==="send_email"?"bg-primary/10 text-primary":o==="update_tags"?"bg-violet-500/10 text-violet-600 dar
1k:text-violet-400":"bg-amber-500/10 text-amber-600 dark:text-amber-400":"bg-zinc-100 dark:bg-zinc-800 text-zinc-400 hover:text-zinc-600 dark:hover:text-zinc-300"}`,children:[G(o),i(o==="send_email"?"automationList.stepEmail":o==="update_tags"?"tagManagerPanel.pageTitle":"automationList.stepCondition")]},o))}),y==="send_email"&&e.jsxs(e.Fragment,{children:[e.jsxs("select",{value:t.templateId||"",onChange:o=>E(x,{templateId:o.target.value}),className:`${_} ${t.templateId?"":"text-zinc-400"}`,children:[e.jsx("option",{value:"",children:i("emailAutomationEditor.selectTemplateOption")}),l.map(o=>e.jsxs("option",{value:o.id,children:[o.name," â ",o.subject]},o.id))]}),e.jsx("input",{value:t.subject||"",onChange:o=>E(x,{subject:o.target.value}),placeholder:t.templateId?i("emailAutomationEditor.subjectOverridePlaceholder"):i("emailAutomationEditor.subjectOptionalPlaceholder"),className:"w-full px-4 py-2 rounded-xl bg-white dark:bg-zinc-800 border border-zinc-200 dark:border-zinc-700 text-xs font-bold outline-none focus:ring-2 focus:ring-primary"})]}),y==="update_tags"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-[9px] font-black text-emerald-600 uppercase tracking-widest mb-1 ml-1",children:i("emailAutomationEditor.addTagsLabel")}),e.jsx(V,{tags:t.addTags||[],onChange:o=>E(x,{addTags:o}),placeholder:i("emailAutomationEditor.addTagsPlaceholder"),inputClassName:"w-full px-4 py-2 rounded-xl bg-white dark:bg-zinc-800 border border-zinc-200 dark:border-zinc-700 text-xs font-bold outline-none focus:ring-2 focus:ring-violet-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[9px] font-black text-red-500 uppercase tracking-widest mb-1 ml-1",children:i("emailAutomationEditor.removeTagsLabel")}),e.jsx(V,{tags:t.removeTags||[],onChange:o=>E(x,{removeTags:o}),placeholder:i("emailAutomationEditor.removeTagsPlaceholder"),inputClassName:"w-full px-4 py-2 rounded-xl bg-white dark:bg-zinc-800 border border-zinc-200 dark:border-zinc-700 text-xs font-bold outline-none focus:ring-2 focus:ring-violet-500"})]})]}),y==="condition"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsx("select",{value:t.conditionField||"paymentStatus",onChange:o=>E(x,{conditionField:o.target.value}),className:"px-3 py-2 rounded-xl bg-white dark:bg-zinc-800 border border-zinc-200 dark:border-zinc-700 text-xs font-bold outline-none appearance-none",children:S.map(o=>e.jsx("option",{value:o.value,children:o.label},o.value))}),e.jsx("select",{value:t.conditionOperator||"equals",onChange:o=>E(x,{conditionOperator:o.target.value}),className:"px-3 py-2 rounded-xl bg-white dark:bg-zinc-800 border border-zinc-200 dark:border-zinc-700 text-xs font-bold outline-none appearance-none",children:g.map(o=>e.jsx("option",{value:o.value,children:o.label},o.value))}),e.jsx("input",{value:t.conditionValue||"",onChange:o=>E(x,{conditionValue:o.target.value}),placeholder:i("emailAutomationEditor.conditionValuePlaceholder"),className:"px-3 py-2 rounded-xl bg-white dark:bg-zinc-800 border border-zinc-200 dark:border-zinc-700 text-xs font-bold outline-none focus:ring-2 focus:ring-amber-500"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[9px] text-zinc-500 font-bold uppercase tracking-widest",children:i("emailAutomationEditor.ifFalseLabel")}),e.jsxs("select",{value:t.falseStepIndex===null||t.falseStepIndex===void 0?"stop":String(t.falseStepIndex),onChange:o=>{const w=o.target.value;E(x,{falseStepIndex:w==="stop"?null:Number(w)})},className:"px-3 py-1.5 rounded-lg bg-white dark:bg-zinc-800 border border-zinc-200 dark:border-zinc-700 text-[10px] font-bold outline-none appearance-none",children:[e.jsx("option",{value:"stop",children:i("emailAutomationEditor.stopAutomationOption")}),C.map((o,w)=>w!==x&&e.jsx("option",{value:w,children:i("emailAutomationEditor.jumpToStepOption",{count:w+1})},w))]})]}),e.jsx("p",{className:"text-[8px] text-zinc-400 italic ml-1",children:i("emailAutomationEditor.ifTrueHint")})]})]})]},t.id)}),e.jsxs("div",{className:"relative flex gap-4 items-center",children:[e.jsx("div",{className:"w-9 h-9 rounded-full flex items-center justify-center shrink-0 z-10 border-2 border-dashed border-zinc-300 dark:border-zinc-700",children:e.jsx("svg",{className:"w-4 h-4 text-zinc-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"3",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 4v16m8-8H4"})})}),e.jsx("button",{type:"button",onClick:re,className:"text-[10px] font-black text-primary uppercase tracking-widest hover:underline",children:i("emailAutomationEditor.addStepButton")})]})]})]})]}),e.jsxs("div",{className:"px-8 py-4 border-t border-zinc-100 dark:border-zinc-800 flex justify-between items-center shrink-0",children:[e.jsx("button",{type:"button",onClick:n,className:"px-6 py-3 rounded-xl text-zinc-500 font-black text-[10px] uppercase tracking-widest hover:text-zinc-900 dark:hover:text-white transition-colors",children:i("common.cancel")}),e.jsx("button",{type:"button",onClick:se,disabled:H||!j.trim()||C.some(t=>!P(t))||v==="trial_ending"&&!p,className:"px-8 py-3 rounded-xl bg-primary text-white font-black text-[10px] uppercase tracking-widest shadow-lg shadow-red-600/20 disabled:opacity-40 active:scale-95 transition-all",children:i(H?"common.saving":"emailAutomationEditor.saveAutomationBtn")})]})]})}),document.body)},Ee=[14,30,60,90],R=s=>`relative inline-flex h-7 w-12 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none ${s?"bg-green-600":"bg-zinc-300 dark:bg-zinc-700"}`,$=s=>`pointer-events-none inline-block h-6 w-6 transform rounded-full bg-white shadow-lg ring-0 transition duration-200 ease-in-out ${s?"translate-x-5":"translate-x-0"}`,Ce=({initialSettings:s,onSave:l})=>{const{t:m}=B(),{addToast:N}=ae(),[n,i]=u.useState(s),[z,k]=u.useState(!1);u.useEffect(()=>{i(s)},[s]);const h=(g,A)=>i(j=>({...j,[g]:A})),S=async()=>{k(!0);try{await l(n)}catch{N(m("smsAutomationSection.toastSaveError"),"error")}finally{k(!1)}};return e.jsxs("div",{className:"bg-white dark:bg-dark-surface p-6 md:p-10 rounded-[3rem] shadow-soft border border-zinc-200 dark:border-zinc-800",children:[e.jsxs("div",{className:"flex items-start gap-4 mb-8 border-b border-zinc-100 dark:border-zinc-800 pb-8",children:[e.jsx("div",{className:"w-2 h-8 bg-primary rounded-full shrink-0 mt-1"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-black text-zinc-900 dark:text-white uppercase tracking-tighter",children:m("smsAutomationSection.title")}),e.jsx("p",{className:"text-xs text-zinc-500 font-bold uppercase tracking-widest mt-1",children:m("smsAutomationSection.subtitle")})]})]}),e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"bg-zinc-50 dark:bg-zinc-900/50 rounded-2xl p-6 border border-zinc-200 dark:border-zinc-800",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-lg",children:"ð"}),e.jsx("h4",{className:"text-sm font-black text-zinc-900 dark:text-white uppercase tracking-tight",children:m("smsAutomationSection.birthdaySmsTitle")})]}),e.jsx("p",{className:"text-xs text-zinc-500 mt-1 ml-8",children:m("smsAutomationSection.birthdaySmsDesc")})]}),e.jsx("button",{type:"button",onClick:()=>h("birthdaySmsEnabled",!n.birthdaySmsEnabled),className:R(n.birthdaySmsEnabled),children:e.jsx("span",{className:$(n.birthdaySmsEnabled)})})]}),n.birthdaySmsEnabled&&e.jsxs("div",{className:"mt-5 pt-5 border-t border-zinc-200 dark:border-zinc-800 space-y-3",children:[e.jsx("label",{className:"block text-[10px] font-black text-zinc-500 uppercase tracking-widest",children:m("smsAutomationSection.messageTemplateLabel")}),e.jsx("textarea",{value:n.birthdaySmsTemplate,onChange:g=>h("birthdaySmsTemplate",g.target.value),rows:3,maxLength:160,className:"w-full rounded-xl border border-zinc-200 dark:border-zinc-700 bg-white dark:bg-zinc-900 px-4 py-3 text-sm text-zinc-900 dark:text-white focus:ring-2 focus:ring-primary/30 focus:border-primary transition-all resize-none"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"text-[10px] text-zinc-400 font-medium",children:[e.jsx("code",{className:"bg-zinc-200 dark:bg-zinc-800 px-1.5 py-0.5 rounded text-[9px]",children:"{firstName}"})," ",m("smsAutomationSection.firstNameVarHint")]}),e.jsxs("span",{className:"text-[10px] text-zinc-400 font-bold",children:[n.birthdaySmsTemplate.length,"/160"]})]})]})]}),e.jsxs("div",{className:"bg-zinc-50 dark:bg-zinc-900/50 rounded-2xl p-6 border border-zinc-200 dark:border-zinc-800",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-lg",children:"â°"}),e.jsx("h4",{className:"text-sm font-black text-zinc-900 dark:text-white uppercase tracking-tight",children:m("smsAutomationSection.inactivitySmsTitle")})]}),e.jsx("p",{className:"text-xs text-zinc-500 mt-1 ml-8",children:m("smsAutomationSection.inactivitySmsDesc")})]}),e.jsx("button",{type:"button",onClick:()=>h("inactivitySmsEnabled",!n.inactivitySmsEnabled),className:R(n.inactivitySmsEnabled),children:e.jsx("span",{className:$(n.inactivitySmsEnabled)})})]}),n.inactivitySmsEnabled&&e.jsxs("div",{className:"mt-5 pt-5 border-t border-zinc-200 dark:border-zinc-800 space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] font-black text-zinc-500 uppercase tracking-widest mb-2",children:m("smsAutomationSection.inactivityThresholdLabel")}),e.jsx("select",{value:n.inactivitySmsDays,onChange:g=>h("inactivitySmsDays",Number(g.target.value)),className:"rounded-xl border border-zinc-200 dark:border-zinc-700 bg-white dark:bg-zinc-900 px-4 py-3 text-sm text-zinc-900 dark:text-white focus:ring-2 focus:ring-primary/30 focus:border-primary transition-all",children:Ee.map(g=>e.jsx("option",{value:g,children:m("smsAutomationSection.daysOption",{count:g})},g))})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-[10px] font-black text-zinc-500 uppercase tracking-widest",children:m("smsAutomationSection.messageTemplateLabel")}),e.jsx("textarea",{value:n.inactivitySmsTemplate,onChange:g=>h("inactivitySmsTemplate",g.target.value),rows:3,maxLength:160,className:"w-full rounded-xl border border-zinc-200 dark:border-zinc-700 bg-white dark:bg-zinc-900 px-4 py-3 text-sm text-zinc-900 dark:text-white focus:ring-2 focus:ring-primary/30 focus:border-primary transition-all resize-none"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"text-[10px] text-zinc-400 font-medium",children:[e.jsx("code",{className:"bg-zinc-200 dark:bg-zinc-800 px-1.5 py-0.5 rounded text-[9px]",children:"{firstName}"})," ",m("smsAutomationSection.firstNameVarHint")]}),e.jsxs("span",{className:"text-[10px] text-zinc-400 font-bold",children:[n.inactivitySmsTemplate.length,"/160"]})]})]})]})]}),e.jsxs("div",{className:"bg-zinc-50 dark:bg-zinc-900/50 rounded-2xl p-6 border border-zinc-200 dark:border-zinc-800",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[e.jsx("span",{className:"text-lg",children:"ð"}),e.jsx("h4",{className:"text-sm font-black text-zinc-900 dark:text-white uppercase tracking-tight",children:m("smsAutomationSection.overdueInvoicesTitle")})]}),e.jsx("p",{className:"text-xs text-zinc-500 mb-5 ml-8",children:m("smsAutomationSection.overdueInvoicesDesc")}),e.jsxs("div",{className:"mt-5 pt-5 border-t border-zinc-200 dark:border-zinc-800 space-y-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-bold text-zinc-700 dark:text-zinc-200",children:m("smsAutomationSection.smsReminderToMemberTitle")}),e.jsx("p",{className:"text-[10px] text-zinc-400 mt-0.5",children:m("smsAutomationSection.smsReminderToMemberDesc")})]}),e.jsx("button",{type:"button",onClick:()=>h("overdueInvoiceSmsEnabled",!n.overdueInvoiceSmsEnabled),className:R(n.overdueInvoiceSmsEnabled),children:e.jsx("span",{className:$(n.overdueInvoiceSmsEnabled)})})]}),n.overdueInvoiceSmsEnabled&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-[10px] font-black text-zinc-500 uppercase tracking-widest",children:m("smsAutomationSection.messageTemplateLabel")}),e.jsx("textarea",{value:n.overdueInvoiceSmsTemplate,onChange:g=>h("overdueInvoiceSmsTemplate",g.target.value),rows:3,maxLength:160,className:"w-full rounded-xl border border-zinc-200 dark:border-zinc-700 bg-white dark:bg-zinc-900 px-4 py-3 text-sm text-zinc-900 dark:text-white focus:ring-2 focus:ring-primary/30 focus:border-primary transition-all resize-none"}),e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("p",{className:"text-[10px] text-zinc-400 font-medium leading-relaxed",children:[m("smsAutomationSection.variablesLabel"),["{firstName}","{invoiceNumber}","{amount}","{dueDate}","{clubName}"].map(g=>e.jsx("code",{className:"bg-zinc-200 dark:bg-zinc-800 px-1.5 py-0.5 rounded text-[9px] mr-1",children:g},g))]}),e.jsxs("span",{className:"text-[10px] text-zinc-400 font-bold shrink-0",children:[n.overdueInvoiceSmsTemplate.length,"/160"]})]})]}),e.jsxs("div",{className:"flex items-start justify-between gap-4 pt-3 border-t border-zinc-100 dark:border-zinc-800",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-bold text-zinc-700 dark:text-zinc-200",children:m("smsAutomationSection.adminSummaryTitle")}),e.jsx("p",{className:"text-[10px] text-zinc-400 mt-0.5",children:m("smsAutomationSection.adminSummaryDesc")})]}),e.jsx("button",{type:"button",onClick:()=>h("overdueInvoiceAdminEmailEnabled",!n.overdueInvoiceAdminEmailEnabled),className:R(n.overdueInvoiceAdminEmailEnabled),children:e.jsx("span",{className:$(n.overdueInvoiceAdminEmailEnabled)})})]})]})]})]}),e.jsx("div",{className:"mt-8 flex justify-end",children:e.jsxs("button",{onClick:S,disabled:z,className:"flex items-center gap-3 px-8 py-4 bg-primary text-white rounded-2xl font-black text-[10px] uppercase tracking-[0.2em] shadow-lg shadow-primary/20 hover:shadow-xl hover:shadow-
1primary/30 active:scale-95 transition-all disabled:opacity-50",children:[z?e.jsx("div",{className:"w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin"}):e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4.5 12.75l6 6 9-13.5"})}),m("smsAutomationSection.saveSmsSettingsBtn")]})})]})},ee={"7d":7,"30d":30,"90d":90},Te=e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5.25 5.653c0-.856.917-1.398 1.667-.986l11.54 6.347a1.125 1.125 0 010 1.972l-11.54 6.347a1.125 1.125 0 01-1.667-.986V5.653z"})}),Ie=e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 12.75l6-6M9 12.75l6 6M4.5 12a7.5 7.5 0 1115 0 7.5 7.5 0 01-15 0z"})}),De=e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126zM12 15.75h.007v.008H12v-.008z"})}),Me=e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})}),_e=(s,l)=>{try{return new Date(s).toLocaleDateString(l,{month:"short",day:"numeric"})}catch{return s}},Be=(s,l)=>{try{return new Date(s).toLocaleString(l,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}catch{return s}},Fe=({automations:s})=>{const{t:l,i18n:m}=B(),N=m.language==="en"?"en-US":"sv-SE",[n,i]=u.useState([]),[z,k]=u.useState(!0),[h,S]=u.useState("30d"),[g,A]=u.useState(null);u.useEffect(()=>{let a=!1;return k(!0),ge(90).then(c=>{a||(i(c),k(!1))}).catch(()=>{a||k(!1)}),()=>{a=!0}},[]);const j=u.useMemo(()=>{const a=new Map(s.map(c=>[c.id,c.name]));return c=>a.get(c)||l("automationStatsSection.deletedAutomationFallback")},[s,l]),b=u.useMemo(()=>{const a=new Date;a.setDate(a.getDate()-ee[h]);const c=a.toISOString();let d=n.filter(p=>p.createdAt>=c);return g&&(d=d.filter(p=>p.automationId===g)),d},[n,h,g]),f=u.useMemo(()=>{const a=b.filter(L=>L.status==="active").length,c=b.filter(L=>L.status==="completed").length,d=b.filter(L=>L.status==="failed").length,p=c+d,M=p>0?Math.round(c/p*100):0;return{total:b.length,active:a,completed:c,failed:d,rate:M}},[b]),D=u.useMemo(()=>{const a=new Map;for(const c of b){a.has(c.automationId)||a.set(c.automationId,{active:0,completed:0,failed:0,total:0});const d=a.get(c.automationId);d.total++,c.status==="active"?d.active++:c.status==="completed"?d.completed++:c.status==="failed"&&d.failed++}return Array.from(a.entries()).sort((c,d)=>d[1].total-c[1].total)},[b]),v=u.useMemo(()=>{const a=ee[h],c={};for(let d=a-1;d>=0;d--){const p=new Date;p.setDate(p.getDate()-d),c[p.toISOString().slice(0,10)]=0}for(const d of b){const p=d.createdAt.slice(0,10);p in c&&c[p]++}return Object.entries(c).sort(([d],[p])=>d.localeCompare(p)).map(([d,p])=>({date:d,count:p}))},[b,h]),T=u.useMemo(()=>Math.max(...v.map(a=>a.count),1),[v]),r=u.useMemo(()=>b.filter(a=>a.status==="failed").slice(0,10),[b]);return z?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx("div",{className:"animate-spin w-6 h-6 border-3 border-primary border-t-transparent rounded-full"})}):n.length===0?null:e.jsxs("div",{className:"mb-10 pb-8 border-b border-zinc-100 dark:border-zinc-800",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 mb-4",children:[e.jsx("h4",{className:"text-xs font-black text-zinc-500 uppercase tracking-widest",children:l("automationStatsSection.title")}),e.jsx("div",{className:"flex gap-2",children:["7d","30d","90d"].map(a=>e.jsx("button",{onClick:()=>S(a),className:`px-3 py-1.5 rounded-lg text-[9px] font-black uppercase tracking-widest transition-all ${h===a?"bg-primary text-white shadow-sm":"bg-zinc-100 dark:bg-zinc-800 text-zinc-500 hover:text-zinc-900 dark:hover:text-white"}`,children:l(a==="7d"?"emailStatsView.period7d":a==="30d"?"emailStatsView.period30d":"emailStatsView.period90d")},a))})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3 mb-4",children:[e.jsx(O,{label:l("automationList.filterActive"),value:f.active,valueColor:"text-blue-600 dar
1k:text-blue-400",icon:Te}),e.jsx(O,{label:l("automationStatsSection.statCompleted"),value:f.completed,valueColor:"text-emerald-600 dark:text-emerald-400",icon:Ie}),e.jsx(O,{label:l("emailStatsView.kpiFailed"),value:f.failed,valueColor:f.failed>0?"text-red-600 dark:text-red-400":void 0,icon:De}),e.jsx(O,{label:l("automationStatsSection.statCompletionRate"),value:`${f.rate}%`,valueColor:f.rate>=90?"text-emerald-600 dark:text-emerald-400":f.rate>=70?"text-amber-600 dark:text-amber-400":"text-red-600 dark:text-red-400",icon:Me})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"lg:col-span-2 bg-white dark:bg-dark-surface rounded-2xl border border-zinc-200 dark:border-zinc-800 p-4",children:[e.jsx("h5",{className:"text-[10px] font-black text-zinc-400 uppercase tracking-widest mb-3",children:l("automationStatsSection.runsPerDayTitle")}),e.jsx("div",{className:"overflow-x-auto",children:e.jsx("div",{className:"flex items-end gap-[2px]",style:{minWidth:`${v.length*10}px`,height:"120px"},children:v.map((a,c)=>{const p=Math.max(Math.round(a.count/T*100),a.count>0?2:0),M=v.length<=14||c%Math.ceil(v.length/10)===0;return e.jsxs("div",{className:"flex flex-col items-center justify-end flex-1 min-w-[6px] h-full",title:l("automationStatsSection.chartTooltip",{date:a.date,count:a.count}),children:[e.jsx("div",{className:"w-full rounded-t bg-violet-400 dark:bg-violet-500/70",style:{height:`${p}px`}}),e.jsx("span",{className:"text-[7px] text-zinc-400 mt-1 whitespace-nowrap leading-none",children:M?_e(a.date,N):" "})]},a.date)})})})]}),e.jsxs("div",{className:"bg-white dark:bg-dark-surface rounded-2xl border border-zinc-200 dark:border-zinc-800 p-4",children:[e.jsx("h5",{className:"text-[10px] font-black text-zinc-400 uppercase tracking-widest mb-3",children:l("automationStatsSection.perAutomationTitle")}),e.jsxs("div",{className:"space-y-1.5 max-h-48 overflow-y-auto",children:[e.jsxs("button",{onClick:()=>A(null),className:`w-full flex items-center justify-between p-2 rounded-lg transition-all text-left ${g?"hover:bg-zinc-50 dark:hover:bg-zinc-800/50":"bg-primary/10 dark:bg-primary/20 ring-1 ring-primary/30"}`,children:[e.jsx("span",{className:"text-[11px] font-bold text-zinc-700 dark:text-zinc-300",children:l("segmentSection.typeAll")}),e.jsx("span",{className:"text-xs font-black text-zinc-900 dark:text-white",children:f.total})]}),D.map(([a,c])=>e.jsxs("button",{onClick:()=>A(g===a?null:a),className:`w-full flex items-center justify-between p-2 rounded-lg transition-all text-left ${g===a?"bg-primary/10 dark:bg-primary/20 ring-1 ring-primary/30":"hover:bg-zinc-50 dark:hover:bg-zinc-800/50"}`,children:[e.jsx("span",{className:"text-[11px] font-bold text-zinc-700 dark:text-zinc-300 truncate mr-2",children:j(a)}),e.jsxs("span",{className:"text-xs font-black text-zinc-900 dark:text-white shrink-0",children:[c.total,c.failed>0&&e.jsx("span",{className:"text-red-500 ml-1",children:l("automationStatsSection.errorsCountSuffix",{count:c.failed})})]})]},a))]})]})]}),r.length>0&&e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/10 border border-red-200 dark:border-red-800/40 rounded-2xl p-4 mt-4",children:[e.jsx("h5",{className:"text-[10px] font-black text-red-500 uppercase tracking-widest mb-2",children:l("automationStatsSection.recentFailedTitle")}),e.jsx("div",{className:"space-y-1.5",children:r.map(a=>e.jsxs("div",{className:"flex items-center justify-between text-[11px]",children:[e.jsxs("span",{className:"text-zinc-700 dark:text-zinc-300 font-bold truncate mr-2",children:[j(a.automationId)," · ",a.recipientEmail]}),e.jsx("span",{className:"text-zinc-400 shrink-0",children:Be(a.failedAt||a.createdAt,N)})]},a.id))})]})]})},Oe=s=>({birthdaySmsEnabled:!1,birthdaySmsTemplate:s("smsAutomationSection.defaultBirthdaySmsTemplate"),inactivitySmsEnabled:!1,inactivitySmsTemplate:s("smsAutomationSection.defaultInactivitySmsTemplate"),inactivitySmsDays:30,overdueInvoiceSmsEnabled:!1,overdueInvoiceSmsTemplate:s("smsAutomationSection.defaultOverdueInvoiceSmsTemplate"),overdueInvoiceAdminEmailEnabled:!1});function Re(){const{t:s}=B(),{addToast:l}=ae(),m=Oe(s),[N,n]=u.useState([]),[i,z]=u.useState([]),[k,h]=u.useState(!0),[S,g]=u.useState(null),[A,j]=u.useState(m),b=async()=>{h(!0);try{const[a,c]=await Promise.all([he(),be()]);n(a.sort((d,p)=>p.createdAt.localeCompare(d.createdAt))),z(c)}catch{l(s("automationList.toastLoadError"),"error")}finally{h(!1)}};return u.useEffect(()=>{b(),me().then(a=>{a&&j({birthdaySmsEnabled:!!a.birthdaySmsEnabled,birthdaySmsTemplate:a.birthdaySmsTemplate??m.birthdaySmsTemplate,inactivitySmsEnabled:!!a.inactivitySmsEnabled,inactivitySmsTemplate:a.inactivitySmsTemplate??m.inactivitySmsTemplate,inactivitySmsDays:a.inactivitySmsDays??m.inactivitySmsDays,overdueInvoiceSmsEnabled:!!a.overdueInvoiceSmsEnabled,overdueInvoiceSmsTemplate:a.overdueInvoiceSmsTemplate??m.overdueInvoiceSmsTemplate,overdueInvoiceAdminEmailEnabled:!!a.overdueInvoiceAdminEmailEnabled})}).catch(()=>{})},[]),{automations:N,templates:i,loading:k,editingAutomation:S,setEditingAutomation:g,initialSmsSettings:A,handleSaveSmsSettings:async a=>{await ue(a),xe(),l(s("smsAutomationSection.toastSettingsSaved"),"success")},handleSave:async a=>{try{S&&S!=="new"?(await Q(S.id,a),l(s("automationList.toastAutomationUpdated"),"success")):(await J({...a,createdAt:new Date().toISOString()}),l(s("automationList.toastAutomationCreated"),"success")),g(null),b()}catch{l(s("automationList.toastSaveError"),"error")}},handleToggleActive:async a=>{try{await Q(a.id,{isActive:!a.isActive}),n(c=>c.map(d=>d.id===a.id?{...d,isActive:!d.isActive}:d)),l(a.isActive?s("automationList.toastDeactivated"):s("automationList.toastActivated"),"success")}catch{l(s("automationList.toastToggleError"),"error")}},handleDelete:async a=>{if(confirm(s("automationList.deleteConfirmAlert")))try{await ve(a),l(s("automationList.toastDeleted"),"success"),b()}catch{l(s("automationList.toastDeleteError"),"error")}},handleDuplicate:async a=>{try{const{id:c,createdAt:d,...p}=a;await J({...p,name:`${a.name}${s("emailTemplateList.duplicateSuffix")}`,isActive:!1,createdAt:new Date().toISOString()}),l(s("automationList.toastDuplicated"),"success"),b()}catch{l(s("automationList.toastDuplicateError"),"error")}}}}const te=(s,l)=>{switch(s){case"lead_created":return l("automationList.triggerLeadCreated");case"tag_added":return l("automationList.triggerTagAdded");case"member_created":return l("automationList.triggerMemberCreated");case"payment_received":return l("automationList.triggerPaymentReceived");case"trial_ending":return l("automationList.triggerTrialEnding");default:return s}},$e=(s,l)=>s===0?l("automationList.delayImmediate"):s<60?`${s} min`:s<1440?`${Math.round(s/60)}h`:`${Math.round(s/1440)}d`,Pe=s=>{switch(s){case"send_email":return e.jsx("svg",{className:"w-4 h-4 text-primary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21.75 6.75v10.5a2.25 2.25 0 01-2.25 2.25h-15a2.25 2.25 0 01-2.25-2.25V6.75m19.5 0A2.25 2.25 0 0019.5 4.5h-15a2.25 2.25 0 00-2.25 2.25m19.5 0v.243a2.25 2.25 0 01-1.07 1.916l-7.5 4.615a2.25 2.25 0 01-2.36 0L3.32 8.91a2.25 2.25 0 01-1.07-1.916V6.75"})});case"update_tags":return e.jsxs("svg",{className:"w-4 h-4 text-violet-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9.568 3H5.25A2.25 2.25 0 003 5.25v4.318c0 .597.237 1.17.659 1.591l9.581 9.581c.699.699 1.78.872 2.607.33a18.095 18.095 0 005.223-5.223c.542-.827.369-1.908-.33-2.607L11.16 3.66A2.25 2.25 0 009.568 3z"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 6h.008v.008H6V6z"})]});case"condition":return e.jsx("svg",{className:"w-4 h-4 text-amber-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M7.5 21L3 16.5m0 0L7.5 12M3 16.5h13.5m0-13.5L21 7.5m0 0L16.5 12M21 7.5H7.5"})});default:return e.jsx("svg",{className:"w-4 h-4 text-primary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21.75 6.75v10.5a2.25 2.25 0 01-2.25 2.25h-15a2.25 2.25 0 01-2.25-2.25V6.75m19.5 0A2.25 2.25 0 0019.5 4.5h-15a2.25 2.25 0 00-2.25 2.25m19.5 0v.243a2.25 2.25 0 01-1.07 1.916l-7.5 4.615a2.25 2.25 0 01-2.36 0L3.32 8.91a2.25 2.25 0 01-1.07-1.916V6.75"})})}},Ve=s=>{switch(s){case"send_email":return"bg-primary/10";case"update_tags":return"bg-violet-500/10";case"condition":return"bg-amber-500/10";default:return"bg-primary/10"}},at=({campaigns:s,users:l,leads:m,groups:N})=>{const{t:n}=B(),i=Re(),[z,k]=u.useState(null),[h,S]=u.useState(""),[g,A]=u.useState("all"),[j,b]=u.useState("all"),[f,D]=u.useState("all"),v=i.automations.filter(r=>{if(h.trim()&&!r.name.toLowerCase().includes(h.trim().toLowerCase())||g!=="all"&&r.trigger!==g||j==="active"&&!r.isActive||j==="inactive"&&r.isActive)return!1;const a=r.recipientType||"lead";return!(f!=="all"&&a!==f)}),T=Array.from(new Set(i.automations.map(r=>r.trigger)));return e.jsxs("div",{className:"space-y-8 max-w-7xl mx-auto pb-20 animate-in fade-in duration-500",children:[e.jsxs("div",{className:"bg-white dark:bg-dark-surface p-6 md:p-10 rounded-[3rem] shadow-soft border border-zinc-200 dark:border-zinc-800",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between items-start md:items-center mb-10 gap-6 border-b border-zinc-100 dark:border-zinc-800 pb-8",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-4xl font-black text-zinc-900 dark:text-white uppercase tracking-tighter",children:n("automationList.pageTitle")}
1),e.jsx("p",{className:"text-sm text-zinc-500 font-medium mt-1.5 ml-1",children:n("automationList.subtitle")})]}),e.jsxs("button",{onClick:()=>i.setEditingAutomation("new"),className:"flex items-center gap-3 px-6 py-4 bg-primary text-white rounded-2xl font-black text-[10px] uppercase tracking-[0.2em] shadow-lg shadow-primary/20 active:scale-95 transition-all",children:[e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"3",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 4v16m8-8H4"})}),n("automationList.newAutomationButton")]})]}),e.jsxs(fe,{children:[e.jsx("strong",{className:"font-bold text-zinc-700 dark:text-zinc-200",children:n("automationList.guideBannerTrigger")})," ",n("automationList.guideBannerTriggerDesc")," ",e.jsx("strong",{className:"font-bold text-zinc-700 dark:text-zinc-200",children:n("automationList.guideBannerStep")})," ",n("automationList.guideBannerStepDesc")," ",e.jsx("strong",{className:"font-bold text-zinc-700 dark:text-zinc-200",children:n("automationList.guideBannerSegment")})," ",n("automationList.guideBannerSegmentSuffix")]}),!i.loading&&e.jsx(Fe,{automations:i.automations}),!i.loading&&i.automations.length>0&&e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 mb-6",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx("svg",{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-zinc-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),e.jsx("input",{type:"text",value:h,onChange:r=>S(r.target.value),placeholder:n("automationList.searchPlaceholder"),className:"w-full pl-10 pr-4 py-2.5 rounded-xl bg-zinc-50 dark:bg-zinc-900 border border-zinc-200 dark:border-zinc-800 text-sm text-zinc-900 dark:text-white font-medium outline-none focus:border-primary"})]}),e.jsxs("select",{value:g,onChange:r=>A(r.target.value),className:"px-3 py-2.5 rounded-xl bg-zinc-100 dark:bg-zinc-800 border border-zinc-200/50 dark:border-zinc-700/50 text-[10px] font-black uppercase tracking-widest text-zinc-500 dark:text-zinc-400 outline-none appearance-none cursor-pointer",children:[e.jsx("option",{value:"all",children:n("automationList.allTriggersOption")}),T.map(r=>e.jsx("option",{value:r,children:te(r,n)},r))]}),e.jsx("div",{className:"flex gap-1 p-1 bg-zinc-100 dark:bg-zinc-800 rounded-xl border border-zinc-200/50 dark:border-zinc-700/50 shadow-inner",children:["all","active","inactive"].map(r=>e.jsx("button",{onClick:()=>b(r),className:`px-3 py-1.5 rounded-lg text-[9px] font-black uppercase tracking-widest transition-all ${j===r?"bg-primary text-white shadow-md":"text-zinc-500 hover:text-zinc-900 dark:hover:text-white"}`,children:n(r==="all"?"segmentSection.typeAll":r==="active"?"automationList.filterActive":"automationList.filterInactive")},r))}),e.jsx("div",{className:"flex gap-1 p-1 bg-zinc-100 dark:bg-zinc-800 rounded-xl border border-zinc-200/50 dark:border-zinc-700/50 shadow-inner",children:["all","user","lead"].map(r=>e.jsx("button",{onClick:()=>D(r),className:`px-3 py-1.5 rounded-lg text-[9px] font-black uppercase tracking-widest transition-all ${f===r?"bg-primary text-white shadow-md":"text-zinc-500 hover:text-zinc-900 dark:hover:text-white"}`,children:n(r==="all"?"segmentSection.typeAll":r==="user"?"automationList.filterMember":"automationList.filterLead")},r))})]}),i.loading?e.jsx("div",{className:"py-20 flex justify-center",children:e.jsx("div",{className:"w-8 h-8 border-3 border-zinc-200 border-t-primary rounded-full animate-spin"})}):i.automations.length===0?e.jsx(X,{icon:e.jsx("svg",{className:"w-6 h-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M3.75 13.5l10.5-11.25L12 10.5h8.25L9.75 21.75 12 13.5H3.75z"})}),title:n("automationList.noAutomationsYetTitle"),description:n("automationList.noAutomationsYetDesc"),action:{label:n("automationList.newAutomationActionLabel"),onClick:()=>i.setEditingAutomation("new")}}):v.length===0?e.jsx(X,{icon:e.jsx("svg",{className:"w-6 h-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),title:n("automationList.noMatchTitle"),description:n("automationList.noMatchDesc")}):e.jsx("div",{className:"space-y-4",children:v.map(r=>{const a=r.recipientType||"lead";return e.jsx("div",{className:"bg-zinc-50 dark:bg-zinc-900/50 rounded-2xl border border-zinc-200 dark:border-zinc-800 overflow-hidden hover:border-zinc-300 dark:hover:border-zinc-700 transition-all",children:e.jsxs("div",{className:"p-5 flex items-center justify-between",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsx("h4",{className:"font-black text-sm text-zinc-900 dark:text-white truncate uppercase tracking-tight",children:r.name}),e.jsx("span",{className:`px-2 py-0.5 rounded-lg text-[8px] font-black uppercase tracking-widest ${r.isActive?"bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-400":"bg-zinc-200 text-zinc-500 dark:bg-zinc-700 dark:text-zinc-400"}`,children:r.isActive?n("automationList.activeBadge"):n("automationList.inactiveBadge")}),e.jsx("span",{className:`px-2 py-0.5 rounded-lg text-[8px] font-black uppercase tracking-widest ${a==="user"?"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400":"bg-orange-100 text-orange-700 dark:bg-orange-900/30 dark:text-orange-400"}`,children:n(a==="user"?"automationList.filterMember":"automationList.filterLead")})]}),e.jsxs("p",{className:"text-[10px] text-zinc-500 font-bold mt-1",children:[n("automationList.triggerPrefix",{label:te(r.trigger,n)}),r.triggerConfig?.campaignIds&&r.triggerConfig.campaignIds.length>0&&e.jsxs(e.Fragment,{children:[" · ",n("automationList.campaignCount",{count:r.triggerConfig.campaignIds.length})]}),r.triggerConfig?.tags&&r.triggerConfig.tags.length>0&&e.jsxs(e.Fragment,{children:[" · ",n("automationList.tagsPrefix",{tags:r.triggerConfig.tags.join(", ")})]}),r.trigger==="trial_ending"&&r.triggerConfig?.trialDaysBefore&&e.jsxs(e.Fragment,{children:[" · ",n("automationList.daysBeforeSuffix",{count:r.triggerConfig.trialDaysBefore})]})]})]}),e.jsx("div",{className:"flex items-center gap-1 mx-4 shrink-0",children:r.steps.map((c,d)=>{const p=c.action||"send_email";return e.jsxs("div",{className:"flex items-center gap-1",children:[d>0&&e.jsx("span",{className:"text-[8px] text-zinc-400 font-bold px-1",children:$e(c.delayMinutes,n)}),e.jsx("div",{className:`w-8 h-8 rounded-lg ${Ve(p)}
1 flex items-center justify-center`,title:n(p==="send_email"?"automationList.stepEmail":p==="update_tags"?"tagManagerPanel.pageTitle":"automationList.stepCondition"),children:Pe(p)})]},c.id)})}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("button",{onClick:()=>k(r),disabled:!r.isActive,title:r.isActive?n("automationList.startManuallyTitle"):n("automationList.activateToStartTitle"),className:"p-2 rounded-xl bg-violet-100 dark:bg-violet-900/30 text-violet-600 dark:text-violet-400 hover:bg-violet-200 dark:hover:bg-violet-900/50 transition-colors disabled:opacity-40",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M3.75 13.5l10.5-11.25L12 10.5h8.25L9.75 21.75 12 13.5H3.75z"})})}),e.jsx("button",{onClick:()=>i.handleToggleActive(r),className:`relative w-12 h-6 rounded-full transition-all ${r.isActive?"bg-emerald-500":"bg-zinc-300 dark:bg-zinc-700"}`,children:e.jsx("div",{className:`absolute top-0.5 w-5 h-5 rounded-full bg-white shadow-md transition-all ${r.isActive?"left-6":"left-0.5"}`})}),e.jsx("button",{onClick:()=>i.setEditingAutomation(r),className:"p-2 rounded-xl bg-zinc-200 dark:bg-zinc-800 text-zinc-600 dark:text-zinc-400 hover:text-zinc-900 dark:hover:text-white transition-colors",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M16.862 4.487l1.687-1.688a1.875 1.875 0 112.652 2.652L10.582 16.07a4.5 4.5 0 01-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 011.13-1.897l8.932-8.931zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0115.75 21H5.25A2.25 2.25 0 013 18.75V8.25A2.25 2.25 0 015.25 6H10"})})}),e.jsx("button",{onClick:()=>i.handleDuplicate(r),title:n("automationList.duplicateTitle"),className:"p-2 rounded-xl bg-zinc-200 dark:bg-zinc-800 text-zinc-600 dark:text-zinc-400 hover:text-zinc-900 dark:hover:text-white transition-colors",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15.75 17.25v3.375c0 .621-.504 1.125-1.125 1.125h-9.75a1.125 1.125 0 01-1.125-1.125V7.875c0-.621.504-1.125 1.125-1.125H6.75a9.06 9.06 0 011.5.124m7.5 10.376h3.375c.621 0 1.125-.504 1.125-1.125V11.25c0-4.46-3.243-8.161-7.5-8.876a9.06 9.06 0 00-1.5-.124H9.375c-.621 0-1.125.504-1.125 1.125v3.5m7.5 10.375H9.375a1.125 1.125 0 01-1.125-1.125v-9.25m12 6.625v-1.875a3.375 3.375 0 00-3.375-3.375h-1.5a1.125 1.125 0 01-1.125-1.125v-1.5a3.375 3.375 0 00-3.375-3.375H9.75"})})}),e.jsx("button",{onClick:()=>i.handleDelete(r.id),className:"p-2 rounded-xl bg-zinc-200 dark:bg-zinc-800 text-red-400 hover:text-red-600 hover:bg-red-50 dark:hover:bg-red-900/20 transition-colors",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0"})})})]})]})},r.id)})})]}),e.jsx(Ce,{initialSettings:i.initialSmsSettings,onSave:i.handleSaveSmsSettings}),i.editingAutomation&&e.jsx(Le,{automation:i.editingAutomation==="new"?void 0:i.editingAutomation,templates:i.templates,campaigns:s,onSave:i.handleSave,onClose:()=>i.setEditingAutomation(null)}),z&&e.jsx(pe,{automations:[z],lockedAutomationId:z.id,users:l,leads:m,groups:N,onClose:()=>k(null),onStarted:()=>k(null)})]})};export{at as AutomationList};
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.