admin.js
| 1 | /*! For license information please see admin.js.LICENSE.txt */ |
| 2 | (globalThis.webpackChunk=globalThis.webpackChunk||[]).push([[884],{4945(e,t,a){"use strict";var i={};a.r(i),a.d(i,{hideProductDiscovery:()=>R,hideTaskList:()=>P,hideUpsell:()=>D});var s={};a.r(s),a.d(s,{getCanDisplayUpsell:()=>Q,getCanImportWooCommerceSubscribers:()=>L,getCurrentTask:()=>Z,getGlobalSubscriberStatsChange:()=>H,getHasForms:()=>q,getHasImportedSubscribers:()=>$,getIsFreeMailUser:()=>W,getIsNewUserForSenderDomainAuth:()=>B,getIsProductDiscoveryDone:()=>Y,getIsProductDiscoveryHidden:()=>z,getIsTaskListHidden:()=>F,getIsUpsellHidden:()=>J,getIsWooCommerceActive:()=>K,getListsSubscriberStatsChange:()=>G,getMssActive:()=>V,getProductDiscoveryTasksStatus:()=>M,getTasksStatus:()=>O}),(0,a(21344).md)();var n=a(79124),r=a(7378),o=a(75245),l=a(68350),d=a(3354),c=a(38465),m=a(16725),u=a(79922),p=a(69139),h=a(36635),g=a(86106);function _({mailpoetInstalledDaysAgo:e,sendTransactionalEmails:t,mtaMethod:a,noticeDismissed:i,apiVersion:s}){const[n,o]=(0,r.useState)(!1),l=()=>{m.U.Ajax.post({api_version:s,endpoint:"UserFlags",action:"set",data:{transactional_emails_opt_in_notice_dismissed:"1"}})};return e<30||t||"PHPMail"===a||i||n?null:(0,g.jsxs)(h.$,{type:"success",timeout:!1,onClose:l,children:[(0,g.jsx)("h3",{children:(0,p.__)("Good news! MailPoet can now send your website’s emails too","mailpoet")}),(0,g.jsxs)("p",{children:[(0,p.__)("All of your WordPress and WooCommerce emails are sent with your hosting company, unless you have an SMTP plugin. Would you like such emails to be delivered with MailPoet’s active sending method for better deliverability?","mailpoet")," ",(0,g.jsx)("a",{href:"https://kb.mailpoet.com/article/292-choose-how-to-send-your-wordpress-websites-emails",target:"_blank",rel:"noopener noreferrer",children:(0,p.__)("Read more.","mailpoet")})]}),(0,g.jsx)("p",{children:(0,g.jsx)("button",{type:"button",className:"button",onClick:()=>{o(!0),m.U.Ajax.post({api_version:s,endpoint:"settings",action:"set",data:{send_transactional_emails:"1"}}),l()},children:(0,p._x)("Enable","verb","mailpoet")})})]})}_.displayName="TransactionalEmailsProposeOptInNotice";var f=a(2726),b=a.n(f),x=a(3698),v=a.n(x);const y=()=>m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"mailer",action:"resumeSending"}).done(()=>{m.U.Notice.success((0,p.__)("Sending has been resumed.","mailpoet"))}).fail(e=>{e.errors.length>0&&m.U.Notice.showApiErrorNotice(e,{scroll:!0})});function w(){return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("p",{children:(0,p.__)("Please check your sending method configuration, you may need to consult with your hosting company.","mailpoet")}),(0,g.jsx)("br",{}),(0,g.jsx)("p",{children:b()((0,p.__)("The easy alternative is to <b>send emails with MailPoet Sending Service</b> instead, like thousands of other users do.","mailpoet"),/<b>(.*?)<\/b>/g,(e,t)=>(0,g.jsx)("b",{children:e},t))}),(0,g.jsx)("p",{children:(0,g.jsx)("a",{href:m.U.MailPoetComUrlFactory.getFreePlanUrl({utm_campaign:"sending-error"}),target:"_blank",rel:"noopener noreferrer",children:(0,p.__)("Sign up for free in minutes","mailpoet")})}),(0,g.jsx)("br",{})]})}function j(){return(0,g.jsx)("p",{children:b()((0,p.__)("Check your [link]sending method settings[/link].","mailpoet"),/\[link\](.*?)\[\/link\]/g,e=>(0,g.jsx)("a",{href:"?page=mailpoet-settings#mta",children:e},"check-sending"))})}function S({mtaLog:e,mtaMethod:t,isInline:a=!1}){const[i,s]=(0,r.useState)(!1);if(i||!e?.error||"paused"!==e.status||"authorization"===e.error.operation)return null;if("send"===e.error.operation&&"MailPoet"===t&&m.U.hasInvalidMssApiKey)return null;if("MailPoet"===t&&"email_limit_reached"===e.error.operation&&m.U.emailVolumeLimitReached)return null;if("MailPoet"===t&&"subscriber_limit_reached"===e.error.operation&&m.U.subscribersLimitReached)return null;if("migration"===e.error.operation){const t=v()("mailpoet_notice notice notice-warning",{inline:a});return(0,g.jsx)("div",{className:t,children:(0,g.jsx)("p",{children:e.error.error_message})})}let n=e.error.error_message;const o=e.error.error_code,l=v()("mailpoet_notice notice notice-error",{inline:a});o&&(n+=n?", ":"",n+=(0,p.__)("Error code: %1$s","mailpoet").replace("%1$s",o));const d=[];n=n.replace(/<a.*?>.*?<\/a>/g,e=>(d.push(e),`[link-${d.length-1}]`)),n=b()(n,/\[link-(\d+)\]/g,e=>{const t=d[e],a=(new DOMParser).parseFromString(t,"text/xml").firstChild,i=a.getAttributeNames(),s=["target","rel","class","data-email","data-type"],n=i.reduce((e,t)=>s.includes(t)?{...e,["class"===t?"className":t]:a.getAttribute(t)}:e,{});return(0,g.jsx)("a",{href:a.getAttribute("href"),...n,children:a.textContent},`a-${e}`)});let c=0;if(n=b()(n,/(<br\s*\/?>)/g,()=>(0,g.jsx)("br",{},"br-"+c++)),"pending_approval"===e.error.operation)return(0,g.jsx)("div",{className:l,children:(0,g.jsx)("p",{children:n})});if("insufficient_privileges"===e.error.operation||"subscriber_limit_reached"===e.error.operation||"email_limit_reached"===e.error.operation)return(0,g.jsxs)("div",{className:l,children:[(0,g.jsx)("p",{children:n}),(0,g.jsx)("p",{children:(0,g.jsx)("a",{href:"#",className:"button button-primary",onClick:e=>{e.preventDefault(),y().then(()=>s(!0)).catch(()=>{})},children:(0,p.__)("I have upgraded my subscription, resume sending","mailpoet")})})]});let u=null;return"PHPMail"===t?u=(0,g.jsx)(w,{}):"MailPoet"!==t&&(u=(0,g.jsx)(j,{})),(0,g.jsxs)("div",{className:l,children:[(0,g.jsxs)("p",{children:["send"===e.error.operation?(0,p.__)("Sending has been paused due to a technical issue with %1$s","mailpoet").replace("%1$s",t):(0,p.__)("Sending is paused because the following connection issue prevents MailPoet from delivering emails","mailpoet"),": ",(0,g.jsx)("i",{children:n})]}),u,(0,g.jsx)("p",{children:(0,g.jsx)("a",{href:"#",className:"button button-primary",onClick:e=>{e.preventDefault(),y().then(()=>s(!0)).catch(()=>{})},children:(0,p.__)("Resume sending","mailpoet")})})]})}var k=a(23094);function N(){return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(u.q,{}),(0,g.jsx)(k.D,{}),(0,g.jsx)(_,{mailpoetInstalledDaysAgo:m.U.installedDaysAgo,sendTransactionalEmails:m.U.transactionalEmailsEnabled,mtaMethod:m.U.mtaMethod,apiVersion:m.U.apiVersion,noticeDismissed:m.U.transactionalEmailsOptInNoticeDismissed}),(0,g.jsx)(S,{mtaLog:m.U.mtaLog,mtaMethod:m.U.mtaMethod,isInline:!0})]})}var C=a(55210),E=a(90194),I=a(39173),A=a(89074),U=a(5191),T=a(50367);function*P(){return yield(0,T.p)({endpoint:"settings",action:"set",method:"POST",data:{"homepage.task_list_dismissed":!0}}),{type:"SET_TASK_LIST_HIDDEN"}}function*R(){return yield(0,T.p)({endpoint:"settings",action:"set",method:"POST",data:{"homepage.product_discovery_dismissed":!0}}),{type:"SET_PRODUCT_DISCOVERY_HIDDEN"}}function*D(){return yield(0,T.p)({endpoint:"settings",action:"set",method:"POST",data:{"homepage.upsell_dismissed":!0}}),{type:"SET_UPSELL_HIDDEN"}}function F(e){return e.taskList.isTaskListHidden}function O(e){return e.taskList.tasksStatus}function M(e){return e.productDiscovery.tasksStatus}function L(e){return e.taskList.canImportWooCommerceSubscribers}function $(e){return e.taskList.hasImportedSubscribers}function B(e){return e.taskList.isNewUserForSenderDomainAuth}function W(e){return e.taskList.isFreeMailUser}function V(e){return e.taskList.mssActive}function q(e){return e.formsCount>0}function z(e){return e.productDiscovery.isHidden}function H(e){return e.subscribersStats.global}function G(e){return e.subscribersStats.lists}function Y(e){const t=e.productDiscovery.tasksStatus;return e.isWooCommerceActive?t.addSubscriptionForm&&t.setUpWelcomeCampaign&&t.setUpAbandonedCartEmail&&t.brandWooEmails:t.setUpWelcomeCampaign&&t.addSubscriptionForm&&t.sendFirstNewsletter}function K(e){return e.isWooCommerceActive}function Z(e){return e.taskList.tasksStatus.senderSet?e.taskList.tasksStatus.mssConnected?!e.taskList.tasksStatus.wooSubscribersImported&&e.taskList.canImportWooCommerceSubscribers?"wooSubscribersImported":e.taskList.tasksStatus.subscribersAdded?null:"subscribersAdded":"mssConnected":"senderSet"}function J(e){return e.upsell.isHidden}function Q(e){return e.upsell.upsellStatus?.canDisplay}function X(e,t){switch(t.type){case"SET_TASK_LIST_HIDDEN":return{...e,taskList:{...e.taskList,isTaskListHidden:!0}};case"SET_PRODUCT_DISCOVERY_HIDDEN":return{...e,productDiscovery:{...e.productDiscovery,isHidden:!0}};case"SET_UPSELL_HIDDEN":return{...e,upsell:{...e.upsell,isHidden:!0}};default:return e}}const ee="mailpoet/homepage",te={};var ae=a(87452),ie=a(13387);function se(e,t,a){m.U.trackEvent(e,{ctaLabel:t},{send_immediately:!0},()=>{window.location.href=a})}function ne({title:e,titleCompleted:t="",slug:a,link:i,order:s,isCompleted:n,isActive:r,children:o=null}){const l=v()("mailpoet-task-list__task",{"mailpoet-task-list__task--completed":n,"mailpoet-task-list__task--active":r}),d=()=>{se("Home Page Task",a,i)};return(0,g.jsxs)("li",{className:l,role:"row",onClick:n?void 0:d,tabIndex:n?void 0:0,onKeyDown:n?void 0:e=>"Enter"===e.key&&d(),children:[(0,g.jsx)("div",{className:"mailpoet-task-list__task-before",children:(0,g.jsx)("div",{className:"mailpoet-task-list__task-icon",children:n?(0,g.jsx)(ae.A,{icon:ie.A}):s})}),(0,g.jsxs)("div",{className:"mailpoet-task-list__task-content",children:[(0,g.jsx)("div",{className:"mailpoet-task-list__task-title",children:n&&t?t:e}),o]})]})}function re({onHide:e}){const{tasksStatus:t,currentTask:a,hasImportedSubscribers:i,canImportWooCommerceSubscribers:s,isNewUserForSenderDomainAuth:n,isFreeMailUser:r,mssActive:l}=(0,C.A)(e=>({tasksStatus:e(ee).getTasksStatus(),currentTask:e(ee).getCurrentTask(),hasImportedSubscribers:e(ee).getHasImportedSubscribers(),canImportWooCommerceSubscribers:e(ee).getCanImportWooCommerceSubscribers(),isNewUserForSenderDomainAuth:e(ee).getIsNewUserForSenderDomainAuth(),isFreeMailUser:e(ee).getIsFreeMailUser(),mssActive:e(ee).getMssActive()}),[]),d=[];if(d.push((0,g.jsx)(ne,{slug:"set sender",title:m.U.I18n.t("senderSetTask"),titleCompleted:m.U.I18n.t("senderSetTaskDone"),link:"admin.php?page=mailpoet-settings#/basics",order:1,isCompleted:t.senderSet,isActive:"senderSet"===a},"senderSet")),d.push((0,g.jsx)(ne,{slug:"connect mss",title:m.U.I18n.t("mssConnectedTask"),titleCompleted:m.U.I18n.t("mssConnectedTaskDone"),link:"admin.php?page=mailpoet-settings#/premium",order:2,isCompleted:t.mssConnected,isActive:"mssConnected"===a},"mssConnected")),s&&d.push((0,g.jsx)(ne,{slug:"import woocommerce subscribers",title:m.U.I18n.t("wooSubscribersImportedTask"),titleCompleted:m.U.I18n.t("wooSubscribersImportedTaskDone"),link:"admin.php?page=mailpoet-woocommerce-setup",order:3,isCompleted:t.wooSubscribersImported,isActive:"wooSubscribersImported"===a},"wooSubscribersImported")),d.push((0,g.jsxs)(ne,{slug:"add subscribers",title:m.U.I18n.t("subscribersAddedTask"),titleCompleted:i?m.U.I18n.t("subscribersAddedTaskDoneByImport"):m.U.I18n.t("subscribersAddedTaskDoneByForm"),link:"admin.php?page=mailpoet-import",order:s?4:3,isCompleted:t.subscribersAdded,isActive:"subscribersAdded"===a,children:[!t.subscribersAdded&&(0,g.jsxs)("p",{children:[m.U.I18n.t("noSubscribersQuestion")," ",(0,g.jsx)("a",{href:"admin.php?page=mailpoet-form-editor-template-selection",onClick:o.stopLinkPropagation,children:m.U.I18n.t("setUpForm")})]}),t.subscribersAdded&&!i&&(0,g.jsxs)("p",{children:[m.U.I18n.t("haveSubscribersQuestion")," ",(0,g.jsx)("a",{href:"admin.php?page=mailpoet-import",children:m.U.I18n.t("import")})]})]},"subscribersAdded")),n&&l){let e="admin.php?page=mailpoet-settings#/basics";r||(e="admin.php?page=mailpoet-settings#/basics/authorizedEmailModal"),d.push((0,g.jsx)(ne,{slug:"authenticate sender domain",title:m.U.I18n.t("senderDomainAuthenticatedTask"),titleCompleted:m.U.I18n.t("senderDomainAuthenticatedTaskDone"),link:e,order:s?5:4,isCompleted:t.senderDomainAuthenticated,isActive:"senderDomainAuthenticated"===a,children:!t.senderDomainAuthenticated&&(0,g.jsx)("p",{children:m.U.I18n.t("improveDeliveryRates")})},"senderDomainAuthenticated"))}return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)("div",{className:"mailpoet-task-list__heading",children:[(0,g.jsx)("h1",{children:m.U.I18n.t("welcomeToMailPoet")}),(0,g.jsx)("p",{children:m.U.I18n.t("beginByCompletingSetup")}),(0,g.jsx)(E.A,{label:m.U.I18n.t("hideList"),icon:I.A,controls:[{title:m.U.I18n.t("hideList"),onClick:e,icon:null}]})]}),(0,g.jsx)("ul",{children:d.map(e=>e)}),!a&&(0,g.jsxs)("p",{className:"mailpoet-task-list__all-set",children:[m.U.I18n.t("youAreSet")," ",(0,g.jsx)("a",{href:"#",onClick:t=>{t.preventDefault(),e()},children:m.U.I18n.t("dismissList")})]})]})}function oe({title:e,slug:t,link:a,description:i,doneMessage:s,imgSrc:n,isDone:r}){const o=()=>{se("Home Page Task",t,a)};return(0,g.jsxs)("li",{className:v()("mailpoet-product-discovery__task",{"mailpoet-product-discovery__task--completed":r}),role:"row",onClick:r?void 0:o,tabIndex:r?void 0:0,onKeyDown:r?void 0:e=>"Enter"===e.key&&o(),children:[(0,g.jsx)("img",{src:n,alt:e,width:124,height:72}),(0,g.jsx)("div",{className:"mailpoet-product-discovery__task-content",children:r?(0,g.jsx)("h3",{children:s}):(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("h3",{children:`${e} →`}),i&&(0,g.jsx)("p",{children:i})]})}),(0,g.jsx)("div",{className:"mailpoet-product-discovery__task-after",children:r&&(0,g.jsx)("div",{className:"mailpoet-task-list__task-icon",children:(0,g.jsx)(ae.A,{icon:ie.A})})})]})}function le({heading:e,description:t,children:a,headingAfter:i,className:s=""}){return(0,g.jsxs)("section",{className:v()("mailpoet-homepage-section__container",s),children:[(0,g.jsxs)("header",{className:"mailpoet-homepage-section__heading",children:[(0,g.jsxs)("h2",{children:[e,t&&(0,g.jsx)("span",{children:t})]}),(0,g.jsx)("div",{className:"mailpoet-homepage-section__heading-after",children:i})]}),a]})}function de({onHide:e}){const{tasksStatus:t,isWooCommerceActive:a,isDiscoveryDone:i}=(0,C.A)(e=>({tasksStatus:e(ee).getProductDiscoveryTasksStatus(),isWooCommerceActive:e(ee).getIsWooCommerceActive(),isDiscoveryDone:e(ee).getIsProductDiscoveryDone()}),[]),s=[];return s.push((0,g.jsx)(oe,{slug:"set up welcome campaign",title:m.U.I18n.t("setUpWelcomeCampaign"),description:m.U.I18n.t("setUpWelcomeCampaignDesc"),link:"admin.php?page=mailpoet-automation-templates&initialTab=welcome",imgSrc:`${m.U.cdnUrl}homepage/welcome-email-illustration.png`,isDone:t.setUpWelcomeCampaign,doneMessage:m.U.I18n.t("setUpWelcomeCampaignDone")},"setUpWelcomeCampaign"),(0,g.jsx)(oe,{slug:"add subscription form",title:m.U.I18n.t("addSubscriptionForm"),description:m.U.I18n.t("addSubscriptionFormDesc"),link:"admin.php?page=mailpoet-form-editor-template-selection",imgSrc:`${m.U.cdnUrl}homepage/subscription-form-illustration.png`,isDone:t.addSubscriptionForm,doneMessage:m.U.I18n.t("addSubscriptionFormDone")},"addSubscriptionForm")),a?s.push((0,g.jsx)(oe,{slug:"set up abandoned cart email",title:m.U.I18n.t("setUpAbandonedCartEmail"),description:m.U.I18n.t("setUpAbandonedCartEmailDesc"),link:"admin.php?page=mailpoet-automation-templates&initialTab=abandoned-cart",imgSrc:`${m.U.cdnUrl}homepage/woo-cart-email-illustration.png`,isDone:t.setUpAbandonedCartEmail,doneMessage:m.U.I18n.t("setUpAbandonedCartEmailDone")},"setUpAbandonedCartEmail"),(0,g.jsx)(oe,{slug:"brand woocommerce emails",title:m.U.I18n.t("brandWooEmails"),description:m.U.I18n.t("brandWooEmailsDesc"),link:"admin.php?page=mailpoet-settings#/woocommerce",imgSrc:`${m.U.cdnUrl}homepage/woo-transactional-email-illustration.20241219.png`,isDone:t.brandWooEmails,doneMessage:m.U.I18n.t("brandWooEmailsDone")},"brandWooEmails")):s.push((0,g.jsx)(oe,{slug:"send first newsletter",title:m.U.I18n.t("sendFirstNewsletter"),description:m.U.I18n.t("sendFirstNewsletterDesc"),link:"admin.php?page=mailpoet-newsletters#/new",imgSrc:`${m.U.cdnUrl}homepage/newsletter-illustration.png`,isDone:t.sendFirstNewsletter,doneMessage:m.U.I18n.t("sendFirstNewsletterDone")},"sendFirstNewsletter")),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(le,{className:"mailpoet-homepage-product-discovery",heading:m.U.I18n.t("startEngagingWithYourCustomers"),headingAfter:(0,g.jsx)(E.A,{label:m.U.I18n.t("hideList"),icon:I.A,controls:[{title:m.U.I18n.t("hideList"),onClick:e,icon:null}]}),children:(0,g.jsx)("ul",{children:s.map(e=>e)})}),i&&(0,g.jsxs)("p",{className:"mailpoet-task-list__all-set",children:[m.U.I18n.t("allDone")," ",(0,g.jsx)("a",{href:"#",onClick:t=>{t.preventDefault(),e()},children:m.U.I18n.t("dismissTasks")})]})]})}var ce=a(35061),me=a(58768),ue=a(59068),pe=a(19453),he=a(8254),ge=a(69611);function _e({closable:e,onHide:t}){return(0,g.jsx)(le,{className:"mailpoet-homepage-upsell",heading:m.U.I18n.t("accelerateYourGrowth"),headingAfter:e&&t?(0,g.jsx)(ge.Ay,{icon:ce.A,onClick:t,label:m.U.I18n.t("close")}):null,children:(0,g.jsxs)("div",{className:"mailpoet-homepage-upsell__content",children:[(0,g.jsxs)("ul",{children:[(0,g.jsxs)("li",{children:[(0,g.jsx)(ae.A,{icon:me.A}),(0,g.jsx)("span",{children:m.U.I18n.t("detailedAnalytics")})]}),(0,g.jsxs)("li",{children:[(0,g.jsx)(ae.A,{icon:ue.A}),(0,g.jsx)("span",{children:m.U.I18n.t("advancedSubscriberSegmentation")})]}),(0,g.jsxs)("li",{children:[(0,g.jsx)(ae.A,{icon:pe.A}),(0,g.jsx)("span",{children:m.U.I18n.t("emailMarketingAutomations")})]}),(0,g.jsxs)("li",{children:[(0,g.jsx)(ae.A,{icon:he.A}),(0,g.jsx)("span",{children:m.U.I18n.t("prioritySupport")})]})]}),(0,g.jsx)(ge.Ay,{variant:"primary",href:m.U.MailPoetComUrlFactory.getPurchasePlanUrl(m.U.subscribersCount,m.U.currentWpUserEmail,"business",{utm_source:"plugin",utm_medium:"homepage",utm_campaign:"upsell"}),children:m.U.I18n.t("upgradePlan")})]})})}var fe=a(59717),be=a(19774);function xe(e,t){switch(t){case"unknown":case"dormant":case"good":case"excellent":return t;case"low":return"average"}return null==e?"unknown":e<20?"average":e<50?"good":"excellent"}function ve({id:e,engagementScore:t,engagementScoreType:a}){const i={unknown:{name:m.U.I18n.t("unknownBadgeName"),type:"unknown",tooltipTitle:m.U.I18n.t("unknownBadgeTooltip"),tooltipText:m.U.I18n.t("tooltipUnknown")},dormant:{name:m.U.I18n.t("dormantBadgeName"),type:"dormant",tooltipTitle:m.U.I18n.t("dormantBadgeTooltip"),tooltipText:m.U.I18n.t("tooltipDormant")},excellent:{name:m.U.I18n.t("excellentBadgeName"),type:"excellent",tooltipTitle:m.U.I18n.t("excellentBadgeTooltip"),tooltipText:m.U.I18n.t("tooltipExcellent")},good:{name:m.U.I18n.t("goodBadgeName"),type:"good",tooltipTitle:m.U.I18n.t("goodBadgeTooltip"),tooltipText:m.U.I18n.t("tooltipGood")},average:{name:m.U.I18n.t("averageBadgeName"),type:"average",tooltipTitle:m.U.I18n.t("averageBadgeTooltip"),tooltipText:m.U.I18n.t("tooltipAverage")}},s=`badge-${e}`,n=i[xe(t,a)],r=(0,g.jsxs)("div",{children:[(0,g.jsx)("div",{className:"mailpoet-listing-stats-tooltip-title",children:n.tooltipTitle.toUpperCase()}),(0,g.jsx)("div",{className:"mailpoet-listing-stats-tooltip-description",children:m.U.I18n.t("engagementScoreDescription")}),(0,g.jsxs)("div",{className:"mailpoet-listing-stats-tooltip-content",children:[(0,g.jsx)(be.E,{type:"unknown",name:m.U.I18n.t("unknownBadgeName")})," : ",i.unknown.tooltipText,(0,g.jsx)("br",{}),(0,g.jsx)(be.E,{type:"dormant",name:m.U.I18n.t("dormantBadgeName")})," : ",i.dormant.tooltipText,(0,g.jsx)("br",{}),(0,g.jsx)(be.E,{type:"excellent",name:m.U.I18n.t("excellentBadgeName")})," : ",i.excellent.tooltipText,(0,g.jsx)("br",{}),(0,g.jsx)(be.E,{type:"good",name:m.U.I18n.t("goodBadgeName")})," : ",i.good.tooltipText,(0,g.jsx)("br",{}),(0,g.jsx)(be.E,{type:"average",name:m.U.I18n.t("averageBadgeName")})," : ",i.average.tooltipText]})]},`tooltip-${s}`);return(0,g.jsxs)("div",{className:"mailpoet-listing-stats-opened-clicked",children:[null!=t&&(0,g.jsxs)("div",{className:"mailpoet-listing-stats-percentages",children:[t.toLocaleString(void 0,{minimumFractionDigits:1,maximumFractionDigits:1}),"%"]}),(0,g.jsx)("div",{children:(0,g.jsx)(be.E,{isInverted:!0,type:n.type,name:n.name,tooltip:r,tooltipId:s,tooltipPlace:"top"})})]})}const ye=(e,t,a)=>{e.preventDefault(),se("Home Page Statistics Click",t,a)};function we(){const{globalChange:e,listsChange:t,hasForms:a}=(0,C.A)(e=>({globalChange:e(ee).getGlobalSubscriberStatsChange(),listsChange:e(ee).getListsSubscriberStatsChange(),hasForms:e(ee).getHasForms()}),[]),i=0===t.length&&0===e.subscribed&&0===e.unsubscribed;return(0,g.jsx)(le,{className:"mailpoet-subscribers-stats",heading:m.U.I18n.t("subscribersHeading"),description:m.U.I18n.t("subscribersSectionDescription"),headingAfter:!i&&(0,g.jsxs)("span",{className:v()({"mailpoet-decrease":e.changePercent<0}),children:[(0,g.jsx)(ae.A,{icon:me.A}),e.changePercent<0&&"-",Math.abs(e.changePercent)>1e3?"∞%":`${Math.abs(e.changePercent)}%`]}),children:i?(0,g.jsxs)("div",{className:"mailpoet-subscribers-stats-empty",children:[(0,g.jsx)(ae.A,{icon:me.A,viewBox:"-4 -4 32 32"}),a?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("p",{children:m.U.I18n.t("subscriberCountHasNotChangeLongTime")}),(0,g.jsx)("a",{href:"admin.php?page=mailpoet-newsletters#/new",onClick:e=>ye(e,"campaigns","admin.php?page=mailpoet-newsletters#/new"),children:m.U.I18n.t("exploreCampaigns")})]}):(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)("p",{children:[m.U.I18n.t("changesWillAppear"),(0,g.jsx)("br",{}),m.U.I18n.t("starBySettingUpForm")]}),(0,g.jsx)("a",{href:"admin.php?page=mailpoet-form-editor-template-selection",onClick:e=>ye(e,"new form","admin.php?page=mailpoet-form-editor-template-selection"),children:m.U.I18n.t("createForm")})]})]}):(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)("div",{className:"mailpoet-subscribers-stats-global-change",children:[(0,g.jsxs)("div",{children:[m.U.I18n.t("newSubscribers"),(0,g.jsx)("br",{}),(0,g.jsx)("span",{children:e.subscribed})]}),(0,g.jsxs)("div",{children:[m.U.I18n.t("unsubscribedSubscribers"),(0,g.jsx)("br",{}),(0,g.jsx)("span",{children:e.unsubscribed})]})]}),!!t.length&&(0,g.jsxs)("table",{className:"mailpoet-subscribers-stats-list-change-table",children:[(0,g.jsx)("thead",{children:(0,g.jsxs)("tr",{children:[(0,g.jsx)("th",{children:m.U.I18n.t("listName")}),(0,g.jsx)("th",{children:m.U.I18n.t("listScore")}),(0,g.jsx)("th",{children:m.U.I18n.t("subscribedSubscribers")}),(0,g.jsx)("th",{children:m.U.I18n.t("unsubscribedSubscribers")})]})}),(0,g.jsx)("tbody",{children:t.map(e=>(0,g.jsxs)("tr",{children:[(0,g.jsx)("td",{children:(0,g.jsx)("a",{href:`admin.php?page=mailpoet-subscribers#/page[1]/sort_by[created_at]/sort_order[desc]/group[all]/filter[segment=${e.id}]`,children:e.name})}),(0,g.jsx)("td",{children:(0,g.jsx)("div",{className:"mailpoet-listing-stats",children:(0,g.jsx)(ve,{id:e.id,engagementScore:e.averageEngagementScore})})}),(0,g.jsx)("td",{children:e.subscribed}),(0,g.jsx)("td",{children:e.unsubscribed})]},e.id))})]})]})})}var je=a(56828),Se=a(24671);function ke({link:e,abstract:t,title:a,imgSrc:i}){return(0,g.jsxs)("a",{className:"mailpoet-resource-post",href:e,target:"_blank",rel:"noreferrer",children:[(0,g.jsx)("img",{src:i,alt:a,width:"292",height:"166"}),(0,g.jsx)("h3",{children:a}),(0,g.jsx)("p",{children:t})]})}function Ne(){const[e,t]=(0,r.useState)(1),a=[(0,g.jsx)(ke,{link:"https://kb.mailpoet.com/article/141-create-an-email-types-of-campaigns",abstract:m.U.I18n.t("createAnEmailAbstract"),title:m.U.I18n.t("createAnEmailTitle"),imgSrc:`${m.U.cdnUrl}homepage/resources/add_email.20241219.png`},"createAnEmail"),(0,g.jsx)(ke,{link:"https://kb.mailpoet.com/article/297-create-a-subscription-form-with-our-editor",abstract:m.U.I18n.t("createAFormAbstract"),title:m.U.I18n.t("createAFormTitle"),imgSrc:`${m.U.cdnUrl}homepage/resources/add_form.png`},"createAForm"),(0,g.jsx)(ke,{link:"https://www.mailpoet.com/blog/email-segmentation/?utm_source=plugin&utm_medium=homepage&utm_campaign=resources",abstract:m.U.I18n.t("segmentationGuideAbstract"),title:m.U.I18n.t("segmentationGuideTitle"),imgSrc:`${m.U.cdnUrl}homepage/resources/segmentation.png`},"segmentationGuide"),(0,g.jsx)(ke,{link:"https://www.mailpoet.com/blog/re-engagement-emails/?utm_source=plugin&utm_medium=homepage&utm_campaign=resources",abstract:m.U.I18n.t("reEngagementAbstract"),title:m.U.I18n.t("reEngagementTitle"),imgSrc:`${m.U.cdnUrl}homepage/resources/reengagement.png`},"reEngagement"),(0,g.jsx)(ke,{link:"https://www.mailpoet.com/blog/newsletter-marketing-strategy/?utm_source=plugin&utm_medium=homepage&utm_campaign=resources",abstract:m.U.I18n.t("marketingStrategyAbstract"),title:m.U.I18n.t("marketingStrategyTitle"),imgSrc:`${m.U.cdnUrl}homepage/resources/marketing.png`},"marketingStrategy"),(0,g.jsx)(ke,{link:"https://www.mailpoet.com/blog/how-to-promote-your-sales-with-email-marketing-mailpoet-woocommerce-segmentation/?utm_source=plugin&utm_medium=homepage&utm_campaign=resources",abstract:m.U.I18n.t("promotingSalesAbstract"),title:m.U.I18n.t("promotingSalesTitle"),imgSrc:`${m.U.cdnUrl}homepage/resources/sales.png`},"promotingSales")],i=(0,r.useCallback)(a=>{a.preventDefault(),t(e+1)},[e]),s=(0,r.useCallback)(a=>{a.preventDefault(),t(e-1)},[e]);return(0,g.jsxs)(le,{className:"mailpoet-homepage-resources",heading:m.U.I18n.t("learnMoreAboutEmailMarketing"),children:[(0,g.jsx)("div",{className:"mailpoet-homepage-resources__posts",children:a.filter((t,a)=>a+1===2*e||a+1===2*e-1).map(e=>e)}),(0,g.jsxs)("div",{className:"mailpoet-homepage-resources__pagination",children:[m.U.I18n.t("pageOf").replace("%1$d",e.toString()).replace("%2$d",Math.ceil(a.length/2).toString()),e>1?(0,g.jsx)("a",{href:"#",onClick:s,title:m.U.I18n.t("previousPostsPage"),children:(0,g.jsx)(ae.A,{icon:je.A})}):(0,g.jsx)(ae.A,{icon:je.A}),e<Math.ceil(a.length/2)?(0,g.jsx)("a",{href:"#",onClick:i,title:m.U.I18n.t("nextPostsPage"),children:(0,g.jsx)(ae.A,{icon:Se.A})}):(0,g.jsx)(ae.A,{icon:Se.A})]})]})}function Ce(){const{isTaskListHidden:e,isProductDiscoveryHidden:t,isUpsellHidden:a,canDisplayUpsell:i}=(0,C.A)(e=>({isTaskListHidden:e(ee).getIsTaskListHidden(),isProductDiscoveryHidden:e(ee).getIsProductDiscoveryHidden(),isUpsellHidden:e(ee).getIsUpsellHidden(),canDisplayUpsell:e(ee).getCanDisplayUpsell()}),[]),{hideTaskList:s}=(0,fe.A)(ee),{hideProductDiscovery:n}=(0,fe.A)(ee),{hideUpsell:r}=(0,fe.A)(ee);return(0,g.jsxs)("div",{className:"mailpoet-homepage__container",children:[!e&&(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(re,{onHide:s})}),!t&&(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(de,{onHide:n})}),e&&t&&i&&!a&&(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(_e,{closable:!0,onHide:r})}),(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(we,{})}),(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(Ne,{})})]})}function Ee(){const[e,t]=(0,r.useState)(!1);return(0,r.useEffect)(()=>{(()=>{const e=(0,A.A)(ee,{actions:i,controls:te,selectors:s,reducer:X,initialState:{taskList:{isTaskListHidden:window.mailpoet_homepage_data.taskListDismissed,tasksStatus:window.mailpoet_homepage_data.taskListStatus,canImportWooCommerceSubscribers:window.mailpoet_homepage_data.wooCustomersCount>0,hasImportedSubscribers:window.mailpoet_homepage_data.subscribersCount>10,isNewUserForSenderDomainAuth:window.mailpoet_homepage_data.isNewUserForSenderDomainAuth,mssActive:window.mailpoet_mss_active,isFreeMailUser:window.mailpoet_homepage_data.isFreeMailUser},productDiscovery:{isHidden:window.mailpoet_homepage_data.productDiscoveryDismissed,tasksStatus:window.mailpoet_homepage_data.productDiscoveryStatus},upsell:{isHidden:window.mailpoet_homepage_data.upsellDismissed,upsellStatus:window.mailpoet_homepage_data.upsellStatus},isWooCommerceActive:m.U.isWoocommerceActive,subscribersStats:window.mailpoet_homepage_data.subscribersStats,formsCount:window.mailpoet_homepage_data.formsCount}});(0,U.register)(e)})(),t(!0)},[]),(0,g.jsxs)(l.F.Provider,{value:(0,l.f)(window),children:[(0,g.jsx)(d.x,{}),(0,g.jsx)(c.D,{}),(0,g.jsx)(N,{}),e?(0,g.jsx)(Ce,{}):null]})}const Ie=document.getElementById("mailpoet_homepage_container");Ie&&((0,o.registerTranslations)(),(0,n.H)(Ie).render((0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(Ee,{})})));var Ae=a(34662),Ue=a(93062),Te=a(45187),Pe=a(54312),Re=a(93691),De=a(15172),Fe=a(14755),Oe=a(27314),Me=a(35635),Le=a(90708),$e=a(60505),Be=a(89971),We=a(97103),Ve=a(8782),qe=a(35011),ze=a(5588);function He({subscribersInPlan:e,subscribersInPlanLimit:t}){return!1===e?null:(0,g.jsxs)("span",{className:"mailpoet-segment-subscriber-count-message",children:[(0,g.jsx)("b",{children:t?(0,p.sprintf)((0,p._n)("%1$s / %2$s subscriber","%1$s / %2$s subscribers",e,"mailpoet"),e.toLocaleString(),t.toLocaleString()):(0,p.sprintf)((0,p._n)("%s subscriber","%s subscribers",e,"mailpoet"),e.toLocaleString())}),(0,g.jsx)(ze.Tooltip,{tooltip:(0,p.__)("This is the total of subscribed, unconfirmed and inactive subscribers we count when you are sending with MailPoet Sending Service. The count excludes unsubscribed and bounced (invalid) email addresses.","mailpoet"),place:"right"})]})}var Ge=a(76272);function Ye({cacheCalculation:e}){const[t,a]=(0,r.useState)(!1),[i,s]=(0,r.useState)([]),n=(new Date).getTime()-new Date(e).getTime(),o=Math.floor(n/1e3/60);return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("span",{className:"mailpoet-segment-subscriber-cache",children:(0,p.sprintf)((0,p._n)("Calculated %s min ago","Calculated %s mins ago",o,"mailpoet"),o.toLocaleString())}),(0,g.jsx)(Ge.$,{variant:"tertiary",onClick:()=>{a(!0),m.U.Ajax.post({api_version:m.U.apiVersion,endpoint:"settings",action:"recalculateSubscribersCountsCache"}).done(()=>{window.location.reload()}).fail(e=>{a(!1),e&&e.errors&&e.errors.length&&(JSON.stringify(e.errors).includes("reinstall_plugin")?m.U.Notice.showApiErrorNotice(e,{static:!0,scroll:!0}):s(e.errors.map(e=>e.message)))})},withSpinner:t,children:(0,p.__)("Recalculate","mailpoet")}),i.length>0&&(0,g.jsx)(h.$,{type:"error",children:i.map(e=>(0,g.jsx)("p",{children:e},e))})]})}function Ke(){return(0,g.jsx)("style",{dangerouslySetInnerHTML:{__html:"\n #screen-meta-links { margin-bottom: -22px; }\n "}})}function Ze(){const e=(0,Ue.zy)();return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(Ke,{}),(0,g.jsx)(d.x,{}),(0,g.jsx)(qe.z,{className:"mailpoet-subscribers-page-header",heading:(0,p.__)("Subscribers","mailpoet"),children:(0,g.jsxs)("span",{className:"mailpoet-subscribers-heading-actions",children:[(0,g.jsxs)("span",{className:"mailpoet-subscribers-heading-primary-actions",children:[(0,g.jsx)(Ae.Link,{className:"page-title-action",to:{pathname:"/new",state:{backUrl:e?.pathname}},children:(0,g.jsx)("span",{"data-automation-id":"add-new-subscribers-button",children:(0,p.__)("Add new subscriber","mailpoet")})}),(0,g.jsx)("a",{className:"page-title-action",href:"?page=mailpoet-import","data-automation-id":"import-subscribers-button",children:(0,p.__)("Import","mailpoet")}),(0,g.jsx)("a",{id:"mailpoet_export_button",className:"page-title-action",href:"?page=mailpoet-export",children:(0,p.__)("Export","mailpoet")})]}),(0,g.jsxs)("span",{className:"mailpoet-subscribers-heading-management-actions",children:[(0,g.jsx)("a",{className:"page-title-action",href:"?page=mailpoet-tags","data-automation-id":"manage-tags-button",children:(0,p.__)("Tags","mailpoet")}),(0,g.jsx)("a",{className:"page-title-action",href:"?page=mailpoet-custom-fields","data-automation-id":"manage-custom-fields-button",children:(0,p.__)("Custom fields","mailpoet")})]})]})}),(0,g.jsxs)("div",{className:"mailpoet-segment-subscriber-count",children:[(0,g.jsx)(He,{subscribersInPlan:m.U.subscribersCount,subscribersInPlanLimit:m.U.subscribersLimit}),(0,g.jsx)(Ye,{cacheCalculation:window.mailpoet_subscribers_counts_cache_created_at})]})]})}const Je=m.U.trackingConfig.emailTrackingEnabled;function Qe(e){switch(e){case"subscribed":return(0,p.__)("Subscribed","mailpoet");case"unconfirmed":return(0,p.__)("Unconfirmed","mailpoet");case"unsubscribed":return(0,p.__)("Unsubscribed","mailpoet");case"inactive":return(0,p.__)("Inactive","mailpoet");case"bounced":return(0,p.__)("Bounced","mailpoet");default:return"Invalid"}}const Xe=new Map((window.mailpoet_segments??[]).map(e=>[String(e.id),e]));function et(e){return e?(0,g.jsxs)(g.Fragment,{children:[m.U.Date.short(e),(0,g.jsx)("br",{}),m.U.Date.time(e)]}):null}function tt(e){const t=Je?[{id:"statistics",label:(0,p.__)("Score","mailpoet"),enableSorting:!1,enableGlobalSearch:!1,render:({item:t})=>(0,g.jsx)("div",{className:"mailpoet-listing-stats",children:(0,g.jsx)(Ae.Link,{to:`/stats/${String(t.id)}`,state:{backUrl:e()},children:(0,g.jsx)(ve,{id:Number(t.id),engagementScore:t.engagement_score,engagementScoreType:t.engagement_score_type})})})}]:[];return[{id:"email",label:(0,p.__)("Subscriber","mailpoet"),type:"text",enableSorting:!1,enableGlobalSearch:!0,render:({item:t})=>(0,g.jsxs)("div",{children:[(0,g.jsx)(Ae.Link,{className:"mailpoet-listing-title","data-automation-id":`listing_item_${t.id}`,to:`/edit/${t.id}`,state:{backUrl:e()},children:t.email}),(0,g.jsxs)("div",{className:"mailpoet-listing-subtitle",children:[t.first_name," ",t.last_name]})]})},{id:"status",label:(0,p.__)("Status","mailpoet"),type:"text",enableSorting:!1,enableGlobalSearch:!1,render:({item:e})=>(0,g.jsx)("span",{children:Qe(e.status)})},{id:"segments",label:(0,p.__)("Lists","mailpoet"),enableSorting:!1,enableGlobalSearch:!1,render:({item:e})=>{return(0,g.jsx)(o.SegmentTags,{segments:(t=e,t.subscriptions.reduce((e,t)=>{if("subscribed"!==t.status)return e;const a=Xe.get(String(t.segment_id));return a&&e.push(a),e},[])),dimension:"large"});var t}},{id:"tags",label:(0,p.__)("Tags","mailpoet"),enableSorting:!1,enableGlobalSearch:!1,render:({item:e})=>(0,g.jsx)(o.SubscriberTags,{subscribers:e.tags,variant:"wordpress",isInverted:!0})},...t,{id:"last_subscribed_at",label:(0,p.__)("Subscribed on","mailpoet"),type:"datetime",enableSorting:!1,enableGlobalSearch:!1,render:({item:e})=>(0,g.jsx)("span",{children:et(e.last_subscribed_at)})},{id:"created_at",label:(0,p.__)("Created on","mailpoet"),type:"datetime",enableSorting:!0,enableGlobalSearch:!1,render:({item:e})=>(0,g.jsx)("span",{children:et(e.created_at)})}].map(e=>({...e,filterBy:!1}))}function at(e){return e.toLocaleString()}function it({mode:e,totalCount:t,pageItemCount:a,onSelectAll:i,onClear:s}){return"hidden"===e?null:"active"===e?(0,g.jsxs)("div",{className:"mailpoet-subscribers-select-all-banner","data-automation-id":"subscribers_select_all_banner",children:[(0,g.jsx)("span",{children:(0,p.__)("All %s subscribers matching this view are selected.","mailpoet").replace("%s",at(t))})," ",(0,g.jsx)(ge.Ay,{variant:"link","data-automation-id":"subscribers_select_all_clear",onClick:s,children:(0,p.__)("Clear selection","mailpoet")})]}):(0,g.jsxs)("div",{className:"mailpoet-subscribers-select-all-banner","data-automation-id":"subscribers_select_all_banner",children:[(0,g.jsx)("span",{children:(0,p.__)("All %s subscribers on this page are selected.","mailpoet").replace("%s",at(a))})," ",(0,g.jsx)(ge.Ay,{variant:"link","data-automation-id":"subscribers_select_all_offer",onClick:i,children:(0,p.__)("Select all %s subscribers matching this view","mailpoet").replace("%s",at(t))})]})}it.displayName="SelectAllBanner";const st=new Set(["moveToList","addToList","addTag","removeTag"]);function nt(e){return st.has(e)}(0,$e.tN)(window.mailpoet_subscribers_api);const rt=(0,$e.gU)("/mailpoet/v1/subscribers");const ot=["trash","restore","delete","removeFromAllLists"],lt=m.U.trackingConfig.emailTrackingEnabled,dt=window.mailpoet_bulk_confirmation_resend_limit,ct="bulk-resend-confirmation-checkbox-input",mt=Number(window.mailpoet_listing_per_page),ut="created_at",pt={type:"table",perPage:mt,page:1,sort:{field:ut,direction:"desc"},fields:["status","segments","tags",...lt?["statistics"]:[],"last_subscribed_at","created_at"],titleField:"email",showTitle:!0};function ht(e){const t=new URLSearchParams(e);return Array.from(t.entries()).reduce((e,[t,a])=>a?{...e,[t]:a}:e,{})}function gt(e){try{return decodeURIComponent(e)}catch{return e}}function _t(){return window.location.hash.split("/").map(e=>(e.endsWith("]")?e.slice(0,-1):e).split("[")).reduce((e,[t,a])=>a?"group"===t&&["all","subscribed","unconfirmed","unsubscribed","inactive","bounced","trash"].includes(a)?{...e,group:a}:("page"===t||"paged"===t)&&Number(a)>0?{...e,page:Number(a)}:("per_page"===t||"limit"===t)&&Number(a)>0?{...e,perPage:Number(a)}:"sort_order"!==t&&"order"!==t||"asc"!==a&&"desc"!==a?"search"===t?{...e,search:gt(a)}:"filter"===t?{...e,filter:ht(a)}:e:{...e,order:a}:e,{})}function ft(e,t,a,i){return[["group",e],["filter",new URLSearchParams(a).toString()||void 0],["search",t.search?encodeURIComponent(t.search):void 0],["page",t.page&&1!==t.page?t.page:void 0],["limit",t.perPage&&t.perPage!==(i.perPage??mt)?t.perPage:void 0],["sort_order",t.sort?.direction&&t.sort.direction!==(i.sort?.direction??"desc")?t.sort.direction:void 0]].reduce((e,[t,a])=>a?`${e}/${t}[${a}]`:e,"")||"/"}function bt(e){return 0===Number(e.wp_user_id)&&0===Number(e.is_woocommerce_user)}function xt(e){return e.toLocaleString()}const vt={moveToList:{kind:"segment",fieldId:"move_to_segment",endpoint:"segments",filter:e=>!(e.deleted_at||"default"!==e.type)},addToList:{kind:"segment",fieldId:"add_to_segment",endpoint:"segments",filter:e=>!(e.deleted_at||"default"!==e.type)},removeFromList:{kind:"segment",fieldId:"remove_from_segment",endpoint:"segments",filter:e=>"default"===e.type},addTag:{kind:"tag",fieldId:"add_tag",endpoint:"tags"},removeTag:{kind:"tag",fieldId:"remove_tag",endpoint:"tags"}};function yt(e){return{moveToList:(0,p.__)("Move to list...","mailpoet"),addToList:(0,p.__)("Add to list...","mailpoet"),removeFromList:(0,p.__)("Remove from list...","mailpoet"),addTag:(0,p.__)("Add tag...","mailpoet"),removeTag:(0,p.__)("Remove tag...","mailpoet"),unsubscribe:(0,p.__)("Unsubscribe","mailpoet"),resendConfirmationEmails:(0,p.__)("Resend confirmation emails","mailpoet")}[e]}function wt({submitModal:e,closeModal:t,count:a}){const[i,s]=(0,r.useState)(!1),[n,o]=(0,r.useState)(!1);return(0,r.useEffect)(()=>{document.getElementById(ct)?.focus()},[]),(0,g.jsx)(Te.A,{title:(0,p.__)("Resend confirmation emails","mailpoet"),onRequestClose:t,children:(0,g.jsxs)(Pe.A,{spacing:3,children:[(0,g.jsx)(Re.A,{as:"p",children:(0,p.sprintf)((0,p.__)("You selected %1$s subscribers. MailPoet can resend confirmation emails to up to %2$s of them at a time.","mailpoet"),Number(a).toLocaleString(),dt.toLocaleString())}),(0,g.jsx)(Re.A,{as:"p",children:(0,p.__)("Some subscribers may be skipped if they already received too many confirmation emails, got one recently, or were added too long ago.","mailpoet")}),(0,g.jsx)("div",{"data-automation-id":"bulk-resend-confirmation-checkbox",children:(0,g.jsx)(De.A,{id:ct,label:(0,p.__)("I confirm these subscribers asked to join my list.","mailpoet"),checked:i,disabled:n,onChange:e=>s(e)})}),(0,g.jsx)("div",{children:(0,g.jsx)(ge.Ay,{variant:"primary",onClick:()=>{i&&!n&&(o(!0),e())},disabled:!i||n,isBusy:n,"data-automation-id":"bulk-resend-confirmation-confirm",children:(0,p.__)("Resend emails","mailpoet")})})]})})}function jt({title:e,config:t,caveat:a,selectionNotice:i,requireChoice:s,showAutomationOptIn:n,onApply:l,onClose:d}){const[c,m]=(0,r.useState)(()=>s?0:function(e){if("segments"===e.endpoint){const t=window.mailpoet_segments??[],a=e.filter?t.filter(e.filter):t;return a.length?Number(a[0].id):0}const t=window.mailpoet_tags??[];return t.length?Number(t[0].id):0}(t)),[u,h]=(0,r.useState)(!1),_=(0,r.useMemo)(()=>({id:t.fieldId,name:t.fieldId,endpoint:t.endpoint,filter:t.filter,forceSelect2:!0,placeholder:"segment"===t.kind?(0,p.__)("Select a list...","mailpoet"):(0,p.__)("Select a tag...","mailpoet")}),[t]);return(0,g.jsxs)(We.a,{title:e,onRequestClose:d,isDismissible:!0,contentClassName:"mailpoet-subscribers-picker-modal",children:[a,i,(0,g.jsx)(Ve.L,{field:_,width:"100%",onValueChange:e=>{const t=Number(e.target.value);m(Number.isFinite(t)?t:0)}}),n&&(0,g.jsx)("div",{"data-automation-id":"bulk-trigger-automations-checkbox",children:(0,g.jsx)(De.A,{label:(0,p.__)("Trigger automations","mailpoet"),help:(0,p.__)("Matching automations may send emails to these subscribers.","mailpoet"),checked:u,onChange:h})}),(0,g.jsx)("div",{className:"mailpoet-subscribers-bulk-confirm-actions",children:(0,g.jsx)(o.Button,{onClick:()=>{c&&l(c,u)},isDisabled:!c,children:(0,p.__)("Apply","mailpoet")})})]})}function St({filters:e,filter:t,group:a,onSelectFilter:i,onEmptyTrash:s}){const n=Object.keys(e).filter(t=>!(0===e[t].length||1===e[t].length&&!e[t][0].value));return(0,g.jsxs)("div",{className:"mailpoet-listing-filters",children:[n.map(a=>(0,g.jsx)(Be.Select,{isMinWidth:!0,dimension:"small",name:a,value:t[a]??"",automationId:`listing_filter_${a}`,onChange:e=>i(a,e.currentTarget.value),children:e[a].map(e=>(0,g.jsx)("option",{value:e.value,children:e.label},`filter-option-${e.value}`))},`filter-${a}`)),"trash"===a&&(0,g.jsx)("span",{className:"mailpoet-listing-filters-empty-trash",children:(0,g.jsx)(o.Button,{variant:"secondary",onClick:s,automationId:"empty_trash",children:(0,p.__)("Empty Trash","mailpoet")})})]})}function kt({group:e,search:t,onCheckTrash:a}){return"bounced"!==e||window.mailpoet_premium_active||window.mailpoet_mss_active?"trash"!==e&&t?(0,g.jsxs)("p",{children:[(0,p.__)("No items found.","mailpoet")," ",(0,g.jsx)("a",{href:`#/group[trash]/search[${encodeURIComponent(t)}]`,className:"button button-link",onClick:e=>{e.preventDefault(),a()},children:(0,p.__)("Have you checked the Trash?","mailpoet")})]}):(0,g.jsx)("div",{children:(0,p.__)("No items found.","mailpoet")}):(0,g.jsxs)("div",{children:[(0,g.jsx)("p",{children:(0,p.__)("Email addresses that are invalid or don't exist anymore are called \"bounced addresses\". It's a good practice not to send emails to bounced addresses to keep a good reputation with spam filters. Send your emails with MailPoet and we'll automatically ensure to keep a list of bounced addresses without any setup.","mailpoet")}),(0,g.jsx)("p",{children:(0,g.jsx)("a",{href:"admin.php?page=mailpoet-upgrade",className:"button-primary",children:(0,p.__)("Get premium version!","mailpoet")})})]})}function Nt(){const e=(0,Ue.Zp)(),{notices:t}=(0,r.useContext)(l.F),a=_t(),[i,s]=(0,r.useState)(a.group??"all"),[n,d]=(0,r.useState)(a.filter??{}),[c,u]=(0,r.useState)([]),[h,_]=(0,r.useState)(!1),[f,b]=(0,r.useState)(null),x=(0,r.useRef)(null),y=(0,r.useRef)(!1),[w]=(0,r.useState)(()=>(0,$e.Aq)("subscribers",pt,tt(()=>""))),[j]=(0,r.useState)(()=>({...w,page:a.page??w.page,perPage:a.perPage??w.perPage,search:a.search,sort:{field:ut,direction:a.order??w.sort?.direction??"desc"}})),S=(0,r.useCallback)((e,t)=>function(e,t){return rt(e,t)}({...e,group:i,filter:n},t),[n,i]),{view:N,setView:C,items:E,meta:I,filters:A,groups:U,isLoading:T,error:P,clearError:R,refresh:D}=(0,$e.i7)({initialView:j,load:S}),F=(0,r.useCallback)(()=>(0,$e.Aq)("subscribers",pt,tt(()=>"")),[]);(0,r.useEffect)(()=>{!function(e,t,a,i){const s=`#${ft(e,t,a,i)}`;window.location.hash!==s&&window.history.replaceState(null,"",s)}(i,N,n,F())},[n,i,N,F]),(0,r.useEffect)(()=>{const e=function(e,t){if(!t)return null;const a={...e};let i=!1;return Object.entries(e).forEach(([e,s])=>{if(!s)return;const n=t[e];Array.isArray(n)&&0!==n.length&&(n.some(e=>String(e.value)===String(s))||(delete a[e],i=!0))}),i?a:null}(n,A);e&&(d(e),u([]),_(!1),C(e=>({...e,page:1})))},[n,A,C]),(0,r.useEffect)(()=>{const e=()=>{const e=_t();s(t=>e.group??t),d(e.filter??{}),u([]),_(!1),R();const t=F();C(a=>({...a,page:e.page??1,perPage:e.perPage??t.perPage,search:e.search??"",sort:{field:ut,direction:e.order??t.sort?.direction??"desc"}}))};return window.addEventListener("hashchange",e),()=>window.removeEventListener("hashchange",e)},[R,F,C]);const O=(0,r.useMemo)(()=>ft(i,N,n,F()),[n,i,N,F]),M=(0,r.useRef)(O);M.current=O;const L=(0,r.useCallback)(()=>M.current,[]),$=(0,r.useMemo)(()=>{const e={all:null,subscribed:null,unconfirmed:null,unsubscribed:null,inactive:null,bounced:null,trash:null};return(U??[]).forEach(t=>{t.name in e&&(e[t.name]=t.count)}),e},[U]);(0,r.useEffect)(()=>{"trash"!==i||T||P||0!==$.trash||N.search||0!==Object.keys(n).length||(s("all"),u([]),_(!1),C(e=>({...e,page:1})))},[n,i,$.trash,T,P,C,N.search]);const B=(0,r.useCallback)(()=>{const e=x.current;x.current=null,e&&document.contains(e)&&e.focus()},[]),W=(0,r.useCallback)(()=>{b(null),window.setTimeout(B)},[B]),V=(0,r.useCallback)((e,t)=>{x.current=document.activeElement;const a=t.map(e=>Number(e.id));b({action:e,selectAll:h,count:h?I.count:t.length,scope:{group:i,filter:{...n},search:N.search||"",selection:h?[]:a,...h?{selectAll:!0}:{}}})},[n,i,I.count,h,N.search]),q=(0,r.useCallback)(e=>{_(!1),u(e)},[]),z=(0,r.useCallback)(e=>{_(!1),u([]),C(e)},[C]),H=(0,$e.wh)("subscribers",N,z),G=(0,r.useCallback)((e,a)=>{if("resendConfirmationEmails"===a&&"mailpoet_subscribers_confirmation_disabled"===e.code)return void t.error((0,g.jsx)("p",{children:(0,Oe.A)((0,p.__)("Sign-up confirmation is disabled in your <link>MailPoet settings</link>. Please enable it to resend confirmation emails or update your subscriber’s status manually.","mailpoet"),{link:(0,g.jsx)("a",{href:"admin.php?page=mailpoet-settings#/signup",children:" "})})}),{scroll:!0});const i=e.message||(0,p.__)("The bulk action could not be completed. Please try again.","mailpoet");t.error((0,g.jsx)("p",{children:i}),{scroll:!0})},[t]),Y=(0,r.useCallback)(async(e,t,a)=>{try{const i=(await function(e,t,a={}){return(0,$e.J8)("/mailpoet/v1/subscribers/bulk-action",function(e,t,a={}){const i=Boolean(t.selectAll),{trigger_automations:s,...n}=a;return{action:e,selection:i?[]:t.selection,select_all:i,group:t.group,search:t.search,filter:t.filter,...n,...nt(e)&&"boolean"==typeof s?{trigger_automations:s}:{}}}(e,t,a))}(e,t,a)).data;u([]),_(!1),"resendConfirmationEmails"===e?function(e){const t=e.queue;if(!t)return void m.U.Notice.success((0,p.__)("Confirmation emails are being resent.","mailpoet"));const a=Number(t.queued_count),i=Number(t.skipped_count);if(0===a)return void m.U.Notice.success((0,p.__)("No confirmation emails were resent. The selected subscribers could not receive another confirmation email right now.","mailpoet"));const s=[String((0,p.sprintf)((0,p._n)("MailPoet is resending confirmation emails to %d subscriber.","MailPoet is resending confirmation emails to %d subscribers.",a,"mailpoet"),a))];i>0&&s.push(String((0,p.sprintf)((0,p._n)("%d selected subscriber was skipped.","%d selected subscribers were skipped.",i,"mailpoet"),i))),m.U.Notice.success(s.join(" "),{onOpen:e=>{e.attr("role","status"),e.attr("aria-live","polite")}})}(i):function(e,t){const a=Number(t.count??0),i=(0,Me.Zn)(t.segment?.name??""),s=(0,Me.Zn)(t.tag?.name??"");"trash"===e?m.U.Notice.success(1===a?(0,p.__)("1 subscriber was moved to the trash.","mailpoet"):(0,p.__)("%1$d subscribers were moved to the trash.","mailpoet").replace("%1$d",xt(a))):"delete"===e?m.U.Notice.success(1===a?(0,p.__)("1 subscriber was permanently deleted.","mailpoet"):(0,p.__)("%1$d subscribers were permanently deleted.","mailpoet").replace("%1$d",xt(a))):"restore"===e?m.U.Notice.success(1===a?(0,p.__)("1 subscriber has been restored from the trash.","mailpoet"):(0,p.__)("%1$d subscribers have been restored from the trash.","mailpoet").replace("%1$d",xt(a))):"moveToList"===e?m.U.Notice.success((0,p.__)("%1$d subscribers were moved to list <strong>%2$s</strong>.","mailpoet").replace("%1$d",xt(a)).replace("%2$s",i)):"addToList"===e?m.U.Notice.success((0,p.__)("%1$d subscribers were added to list <strong>%2$s</strong>.","mailpoet").replace("%1$d",xt(a)).replace("%2$s",i)):"removeFromList"===e?m.U.Notice.success((0,p.__)("%1$d subscribers were removed from list <strong>%2$s</strong>.","mailpoet").replace("%1$d",xt(a)).replace("%2$s",i)):"removeFromAllLists"===e?m.U.Notice.success((0,p.__)("%1$d subscribers were removed from all lists.","mailpoet").replace("%1$d",xt(a))):"unsubscribe"===e?m.U.Notice.success(1===a?(0,p.__)("1 subscriber was unsubscribed from all lists.","mailpoet"):(0,p.__)("%1$d subscribers were unsubscribed from all lists.","mailpoet").replace("%1$d",xt(a))):"addTag"===e?m.U.Notice.success((0,p.__)("Tag <strong>%1$s</strong> was added to %2$d subscribers.","mailpoet").replace("%1$s",s).replace("%2$d",xt(a))):"removeTag"===e&&m.U.Notice.success((0,p.__)("Tag <strong>%1$s</strong> was removed from %2$d subscribers.","mailpoet").replace("%1$s",s).replace("%2$d",xt(a)))}(e,i),D()}catch(t){G(t,e)}},[G,D]),K=(0,r.useCallback)(async(e,t,a={})=>{if(h)return void await Y(e,{group:i,filter:n,search:N.search||"",selection:[],selectAll:!0},a);if(0===t.length)return;const s=t.map(e=>Number(e.id));await Y(e,{group:i,filter:n,search:N.search||"",selection:s},a)},[n,i,Y,h,N.search]),Z=(0,r.useCallback)(async()=>{"trash"===i&&await Y("delete",{group:"trash",filter:n,search:N.search||"",selection:[],selectAll:!0},{})},[n,i,Y,N.search]),J=(0,r.useCallback)(async(e={})=>{if(!f||y.current)return;y.current=!0;const{action:t,scope:a}=f;try{await Y(t,a,e)}finally{y.current=!1,b(null),window.setTimeout(B)}},[f,B,Y]),Q=(0,r.useCallback)(async e=>{try{await async function(e){await(0,$e.J8)((e=>`/mailpoet/v1/subscribers/${e}/resend-confirmation-email`)(e),{})}(Number(e.id)),m.U.Notice.success((0,p.__)("1 confirmation email has been sent.","mailpoet"))}catch(e){G(e,"resendConfirmationEmails")}},[G]),X=(0,r.useMemo)(()=>[{id:"statistics",label:(0,p.__)("Statistics","mailpoet"),context:"single",supportsBulk:!1,isEligible:()=>"trash"!==i,callback:t=>{const a=t[0];a&&e(`/stats/${a.id}`,{state:{backUrl:L()}})}},{id:"edit",label:(0,p.__)("Edit","mailpoet"),context:"single",isPrimary:!0,supportsBulk:!1,isEligible:()=>"trash"!==i,callback:t=>{const a=t[0];a&&e(`/edit/${a.id}`,{state:{backUrl:L()}})}},{id:"sendConfirmationEmail",label:(0,p.__)("Resend confirmation email","mailpoet"),context:"single",supportsBulk:!1,isEligible:e=>"trash"!==i&&"unconfirmed"===e.status&&window.mailpoet_signup_confirmation_enabled,callback:e=>{e[0]&&Q(e[0])}},{id:"trash",label:(0,p.__)("Move to trash","mailpoet"),supportsBulk:!0,isEligible:()=>"trash"!==i,callback:e=>{h?V("trash",e):K("trash",e)}},{id:"restore",label:(0,p.__)("Restore","mailpoet"),supportsBulk:!0,isEligible:()=>"trash"===i,callback:e=>{h?V("restore",e):K("restore",e)}},{id:"delete",label:(0,p.__)("Delete permanently","mailpoet"),supportsBulk:!0,isDestructive:!0,isEligible:e=>"trash"===i&&bt(e),callback:e=>{h?V("delete",e):K("delete",e.filter(bt))}},{id:"moveToList",label:(0,p.__)("Move to list...","mailpoet"),context:"list",supportsBulk:!0,isEligible:()=>"trash"!==i,callback:e=>V("moveToList",e)},{id:"addToList",label:(0,p.__)("Add to list...","mailpoet"),context:"list",supportsBulk:!0,isEligible:()=>"trash"!==i,callback:e=>V("addToList",e)},{id:"removeFromList",label:(0,p.__)("Remove from list...","mailpoet"),context:"list",supportsBulk:!0,isEligible:()=>"trash"!==i,callback:e=>V("removeFromList",e)},{id:"removeFromAllLists",label:(0,p.__)("Remove from all lists","mailpoet"),context:"list",supportsBulk:!0,isEligible:()=>"trash"!==i,callback:e=>{h?V("removeFromAllLists",e):K("removeFromAllLists",e)}},{id:"unsubscribe",label:(0,p.__)("Unsubscribe","mailpoet"),context:"list",supportsBulk:!0,isEligible:()=>"trash"!==i&&"unsubscribed"!==i,callback:e=>V("unsubscribe",e)},{id:"resendConfirmationEmails",label:(0,p.__)("Resend confirmation emails","mailpoet"),context:"list",supportsBulk:!0,isEligible:()=>"unconfirmed"===i&&window.mailpoet_signup_confirmation_enabled,callback:e=>V("resendConfirmationEmails",e)},{id:"addTag",label:(0,p.__)("Add tag...","mailpoet"),context:"list",supportsBulk:!0,isEligible:()=>"trash"!==i,callback:e=>V("addTag",e)},{id:"removeTag",label:(0,p.__)("Remove tag...","mailpoet"),context:"list",supportsBulk:!0,isEligible:()=>"trash"!==i,callback:e=>V("removeTag",e)}],[L,i,K,Q,e,V,h]),ee=(0,r.useMemo)(()=>(U??[]).filter(e=>!("trash"===e.name&&0===e.count&&"trash"!==i)).filter(e=>e.name in $),[i,$,U]),te=(0,r.useMemo)(()=>tt(L),[L]),ae=(0,r.useMemo)(()=>({totalItems:I.count,totalPages:I.pages}),[I]),ie=E.length>0&&c.length===E.length,se=function(e){const{pageItemCount:t,totalCount:a,totalPages:i,isPageFullySelected:s,isSelectAll:n}=e;return a<=0||i<=1?"hidden":n?"active":s&&t>0?"offer":"hidden"}({pageItemCount:E.length,totalCount:I.count,totalPages:I.pages,isPageFullySelected:ie,isSelectAll:h});return(0,g.jsxs)("div",{children:[(0,g.jsx)(Ze,{}),(0,g.jsx)(k.D,{}),P&&(0,g.jsx)(Fe.A,{status:"error",onRemove:R,children:"Failed to load data."===P?(0,p.__)("Failed to load subscribers.","mailpoet"):P}),(0,g.jsx)("div",{className:"mailpoet-categories mailpoet-dataviews__tabs mailpoet-subscribers-dataviews__tabs",children:(0,g.jsx)("div",{className:"components-tab-panel__tabs",role:"tablist",children:ee.map(e=>{const t=v()("components-button","components-tab-panel__tabs-item",`mailpoet-dataviews-group-${e.name}`,{"is-active":e.name===i});return(0,g.jsxs)("a",{href:"#",className:t,"data-automation-id":`filters_${e.name}`,onClick:t=>{var a;t.preventDefault(),(a=e.name)!==i&&(s(a),u([]),_(!1),R(),C(e=>({...e,page:1})))},children:[(0,g.jsx)("span",{"data-title":e.label,children:e.label}),Number(e.count)>0&&(0,g.jsx)("span",{className:"count",children:Number(e.count).toLocaleString()})]},e.name)})})}),(0,g.jsx)(it,{mode:se,totalCount:I.count,pageItemCount:E.length,onSelectAll:()=>_(!0),onClear:()=>{_(!1),u([])}}),(0,g.jsx)("div",{className:"mailpoet-dataviews mailpoet-subscribers-dataviews","data-automation-id":"subscribers_listing",children:(0,g.jsxs)(Le.A,{data:E,fields:te,view:N,onChangeView:H,actions:X,paginationInfo:ae,defaultLayouts:{table:{}},getItemId:e=>String(e.id),selection:c,onChangeSelection:q,isLoading:T,empty:(0,g.jsx)(kt,{group:i,search:N.search,onCheckTrash:()=>{s("trash"),u([]),_(!1),R(),C(e=>({...e,page:1}))}}),children:[(0,g.jsxs)("div",{className:"mailpoet-dataviews__toolbar mailpoet-subscribers-dataviews__toolbar",children:[(0,g.jsx)(Le.A.Search,{label:(0,p.__)("Search","mailpoet")}),(0,g.jsx)(St,{filters:A,filter:n,group:i,onSelectFilter:(e,t)=>{d(a=>{const i={...a};return t?i[e]=t:delete i[e],i}),u([]),_(!1),C(e=>({...e,page:1}))},onEmptyTrash:()=>{Z()}}),(0,g.jsx)("div",{className:"mailpoet-dataviews__toolbar-end",children:(0,g.jsx)(Le.A.ViewConfig,{})})]}),(0,g.jsx)(Le.A.Layout,{}),(0,g.jsx)(Le.A.Footer,{})]})}),(()=>{if(!f)return null;const{action:e,count:t,selectAll:a}=f,i=a&&function(e,t=1e4){return e>t}(t)?(0,g.jsx)(Fe.A,{status:"warning",isDismissible:!1,className:"mailpoet-subscribers-select-all-warning",children:(0,p.__)("Large operations may take a while and could time out on very large lists!","mailpoet")}):null,s=a&&"delete"===e?(0,g.jsx)("p",{className:"mailpoet-subscribers-select-all-caveat",children:(0,p.__)("WordPress users and WooCommerce customers are kept and will not be permanently deleted.","mailpoet")}):null;if(ot.includes(e))return(0,g.jsxs)(We.a,{title:(0,p.__)("Confirm bulk action","mailpoet"),onRequestClose:W,isDismissible:!0,children:[i,(0,g.jsx)("p",{children:(0,p.__)("This action will be applied to all %s subscribers matching the current view.","mailpoet").replace("%s",xt(t))}),s,(0,g.jsx)("div",{className:"mailpoet-subscribers-bulk-confirm-actions",children:(0,g.jsx)(o.Button,{onClick:()=>J(),className:"delete"===e?"mailpoet-subscribers-confirm-destructive":void 0,automationId:"bulk-select-all-confirm",children:(0,p.__)("Apply","mailpoet")})})]});if("unsubscribe"===e)return(0,g.jsxs)(We.a,{title:(0,p.__)("Unsubscribe","mailpoet"),onRequestClose:W,isDismissible:!0,children:[i,(0,g.jsx)("p",{children:(0,p.__)("This action will unsubscribe %s subscribers from all lists. This action cannot be undone. Are you sure, you want to continue?","mailpoet").replace("%s",xt(t))}),(0,g.jsx)("div",{className:"mailpoet-subscribers-bulk-confirm-actions",children:(0,g.jsx)(o.Button,{onClick:()=>J(),automationId:"bulk-unsubscribe-confirm",children:(0,p.__)("Apply","mailpoet")})})]});if("resendConfirmationEmails"===e)return(0,g.jsx)(wt,{submitModal:()=>J(),closeModal:W,count:t});if(!function(e){return e in vt}(e))return null;const n=vt[e],r=nt(e),l=a?(0,g.jsx)("p",{children:(0,p.__)("This action will be applied to all %s subscribers matching the current view.","mailpoet").replace("%s",xt(t))}):null;return(0,g.jsx)(jt,{title:yt(e),config:n,caveat:i,selectionNotice:l,requireChoice:a,showAutomationOptIn:r,onApply:(e,t)=>{const a="segment"===n.kind?{segment_id:e}:{tag_id:e};J({...a,trigger_automations:t})},onClose:W})})()]})}Nt.displayName="SubscriberList";var Ct=a(36637),Et=a.n(Ct),It=a(70390),At=a.n(It),Ut=a(41669),Tt=a.n(Ut),Pt=a(23108),Rt=a.n(Pt),Dt=a(26721);class Ft extends r.Component{render(){const{onValueChange:e=()=>{},onBlurEvent:t=()=>{}}=this.props,a=this.props.field.name||null,i=this.props.item||{};let s,n;e instanceof Function&&(s=i[this.props.field.name],s=void 0===s?this.props.field.defaultValue||"":s),!s&&this.props.field.defaultValue&&(n=this.props.field.defaultValue);let r=this.props.field.id||null;!r&&this.props.field.name&&(r=`field_${this.props.field.name}`);let o,l=this.props.field.className||null;return l||this.props.field.size||(l="regular-text"),o="function"==typeof this.props.field.disabled?this.props.field.disabled(this.props.item):"boolean"==typeof this.props.field.disabled&&this.props.field.disabled,(0,g.jsx)(Dt.p,{type:"text",disabled:o,className:l,size:"auto"!==this.props.field.size&&this.props.field.size>0?this.props.field.size:null,name:a,id:r,value:s,defaultValue:n,placeholder:this.props.field.placeholder,onChange:e,onBlur:t,customLabel:this.props.field.customLabel,tooltip:this.props.field.tooltip,...this.props.field.validation})}}Ft.propTypes={onValueChange:Rt().func,onBlurEvent:Rt().func,field:Rt().shape({name:Rt().string.isRequired,defaultValue:Rt().string,id:Rt().string,className:Rt().string,size:Rt().oneOfType([Rt().string,Rt().number]),disabled:Rt().oneOfType([Rt().bool,Rt().func]),placeholder:Rt().string,validation:Rt().shape({"data-parsley-required":Rt().bool,"data-parsley-required-message":Rt().string,"data-parsley-type":Rt().string,"data-parsley-errors-container":Rt().string,maxLength:Rt().number}),customLabel:Rt().string,tooltip:Rt().string}).isRequired,item:Rt().object.isRequired};var Ot=a(39523);function Mt(e){return(0,g.jsx)(Ot.T,{type:"text",name:e.field.name,id:`field_${e.field.name}`,value:e.item[e.field.name],placeholder:e.field.placeholder,defaultValue:e.field.defaultValue,onChange:e.onValueChange,className:e.field.className,customLabel:e.field.customLabel,tooltip:e.field.tooltip,...e.field.validation})}Mt.propTypes={item:Rt().object.isRequired,field:Rt().shape({name:Rt().string,placeholder:Rt().string,defaultValue:Rt().string,validation:Rt().shape({"data-parsley-required":Rt().bool,"data-parsley-required-message":Rt().string,"data-parsley-type":Rt().string,"data-parsley-errors-container":Rt().string,maxLength:Rt().number}),className:Rt().string,customLabel:Rt().string,tooltip:Rt().string}).isRequired,onValueChange:Rt().func.isRequired};var Lt=a(95338);class $t extends r.Component{render(){if(void 0===this.props.field.values)return!1;const{automationId:e="",onValueChange:t=()=>{}}=this.props;let a,i=!1,s=!1,n=!1;void 0!==this.props.field.placeholder&&(s=(0,g.jsx)("option",{value:"",children:this.props.field.placeholder})),void 0!==this.props.field.filter&&(i=this.props.field.filter),Lt.default.isFunction(this.props.field.sortBy)&&(n=this.props.field.sortBy),a=n?Lt.default.map(Lt.default.sortBy(Lt.default.pairs(this.props.field.values),e=>n(e[0],e[1])),e=>e[0]):Object.keys(this.props.field.values);const r=a.filter(e=>!1===i||i(this.props.item,e)).map(e=>(0,g.jsx)("option",{value:e,children:this.props.field.values[e]},`option-${e}`));return(0,g.jsxs)(Be.Select,{name:this.props.field.name,id:`field_${this.props.field.name}`,value:this.props.item[this.props.field.name]||"",onChange:t,automationId:e,...this.props.field.validation,children:[s,r]})}}$t.propTypes={onValueChange:Rt().func,field:Rt().shape({name:Rt().string.isRequired,values:Rt().objectOf(Rt().string),placeholder:Rt().string,filter:Rt().func,sortBy:Rt().func,validation:Rt().shape({"data-parsley-required":Rt().bool,"data-parsley-required-message":Rt().string,"data-parsley-type":Rt().string,"data-parsley-errors-container":Rt().string,maxLength:Rt().number})}).isRequired,item:Rt().object.isRequired,automationId:Rt().string};var Bt=a(67505);class Wt extends r.Component{constructor(e){super(e),this.onValueChange=this.onValueChange.bind(this)}onValueChange=(e,t)=>{const{onValueChange:a=()=>{}}=this.props;a(t)};render(){if(void 0===this.props.field.values)return!1;const e=this.props.item[this.props.field.name],t=Object.keys(this.props.field.values).map(t=>(0,g.jsx)("p",{children:(0,g.jsx)(Bt.s,{checked:e===t,value:t,onCheck:this.onValueChange,name:this.props.field.name,children:this.props.field.values[t]})},`radio-${t}`));return(0,g.jsx)("div",{children:t})}}Wt.propTypes={onValueChange:Rt().func,field:Rt().shape({name:Rt().string.isRequired,values:Rt().objectOf(Rt().string)}).isRequired,item:Rt().object.isRequired};var Vt=a(22505);class qt extends r.Component{constructor(e){super(e),this.onValueChange=this.onValueChange.bind(this)}onValueChange=(e,t)=>(t.target.value=e?"1":"0",this.props.onValueChange(t));render(){if(void 0===this.props.field.values)return!1;const e=!!Number(this.props.item[this.props.field.name]),t=Object.keys(this.props.field.values).map(t=>(0,g.jsx)("p",{children:(0,g.jsx)(Vt.S,{value:"1",checked:e,name:this.props.field.name,onCheck:this.onValueChange,children:this.props.field.values[t]})},`checkbox-${t}`));return(0,g.jsx)("div",{children:t})}}function zt(e){const t=[];void 0!==e.placeholder&&t.push((0,g.jsx)("option",{value:"",children:e.placeholder},0));const a=Et()().year();for(let e=a;e>=a-100;e-=1)t.push((0,g.jsx)("option",{value:e,children:e},e));return(0,g.jsx)(o.Select,{isMinWidth:!0,name:`${e.name}[year]`,value:e.year,onChange:e.onValueChange,children:t})}function Ht(e){const t=[];void 0!==e.placeholder&&t.push((0,g.jsx)("option",{value:"",children:e.placeholder},0));for(let a=1;a<=12;a+=1)t.push((0,g.jsx)("option",{value:a,children:e.monthNames[a-1]},a));return(0,g.jsx)(o.Select,{isMinWidth:!0,name:`${e.name}[month]`,value:e.month,onChange:e.onValueChange,children:t})}function Gt(e){const t=[];void 0!==e.placeholder&&t.push((0,g.jsx)("option",{value:"",children:e.placeholder},0));for(let e=1;e<=31;e+=1)t.push((0,g.jsx)("option",{value:e,children:e},e));return(0,g.jsx)(o.Select,{isMinWidth:!0,name:`${e.name}[day]`,value:e.day,onChange:e.onValueChange,children:t})}qt.propTypes={onValueChange:Rt().func.isRequired,field:Rt().shape({name:Rt().string.isRequired,values:Rt().objectOf(Rt().string)}).isRequired,item:Rt().object.isRequired},zt.propTypes={name:Rt().string.isRequired,placeholder:Rt().string.isRequired,onValueChange:Rt().func.isRequired,year:Rt().oneOfType([Rt().string,Rt().number]).isRequired},Ht.propTypes={name:Rt().string.isRequired,placeholder:Rt().string.isRequired,onValueChange:Rt().func.isRequired,month:Rt().oneOfType([Rt().string,Rt().number]).isRequired,monthNames:Rt().arrayOf(Rt().string).isRequired},Gt.propTypes={name:Rt().string.isRequired,placeholder:Rt().string.isRequired,onValueChange:Rt().func.isRequired,day:Rt().oneOfType([Rt().string,Rt().number]).isRequired};class Yt extends r.Component{constructor(e){super(e),this.state={year:"",month:"",day:""},this.onValueChange=this.onValueChange.bind(this)}componentDidMount(){this.extractDateParts()}componentDidUpdate(e){void 0!==this.props.item&&void 0!==e.item&&this.props.item.id!==e.item.id&&this.extractDateParts()}onValueChange(e){const t=e.target.name.match(/(.*?)\[(.*?)\]/);let a=null,i=null;if(null!==t&&3===t.length){[,a,i]=t;const s=Number(e.target.value);this.setState({[`${i}`]:s},()=>{this.props.onValueChange({target:{name:a,value:this.formatValue()}})})}}formatValue(){let e;switch(this.props.field.params.date_type){case"year_month_day":e={year:this.state.year,month:this.state.month,day:this.state.day};break;case"year_month":e={year:this.state.year,month:this.state.month};break;case"month":e={month:this.state.month};break;case"year":e={year:this.state.year};break;default:e={value:"invalid type"}}return e}extractDateParts(){const e=void 0!==this.props.item[this.props.field.name]?this.props.item[this.props.field.name].trim():"";if(""===e)return;const t=Et()(e);this.setState({year:t.format("YYYY"),month:t.format("M"),day:t.format("D")})}render(){const e=window.mailpoet_month_names||[];let t=(window.mailpoet_date_formats||{})[this.props.field.params.date_type][0];this.props.field.params.date_format&&(t=this.props.field.params.date_format);const a=t.split("/").map(t=>{switch(t){case"YYYY":return(0,g.jsx)(zt,{onValueChange:this.onValueChange,name:this.props.field.name,year:this.state.year,placeholder:this.props.field.year_placeholder},"year");case"MM":return(0,g.jsx)(Ht,{onValueChange:this.onValueChange,name:this.props.field.name,month:this.state.month,monthNames:e,placeholder:this.props.field.month_placeholder},"month");case"DD":return(0,g.jsx)(Gt,{onValueChange:this.onValueChange,name:this.props.field.name,day:this.state.day,placeholder:this.props.field.day_placeholder},"day");default:return(0,g.jsx)("div",{children:"Invalid date type"})}});return(0,g.jsx)("div",{children:a})}}Yt.propTypes={item:Rt().object.isRequired,field:Rt().shape({name:Rt().string,day_placeholder:Rt().string,month_placeholder:Rt().string,year_placeholder:Rt().string,params:Rt().object}).isRequired,onValueChange:Rt().func.isRequired};var Kt=a(76944),Zt=a(16819),Jt=a(35558),Qt=a.n(Jt);function Xt({id:e,label:t,name:a,placeholder:i,selectedValues:s,suggestedValues:n,onChange:r}){const o={id:e,label:t,name:a,placeholder:i,className:"mailpoet-form-token-field"};return(0,g.jsx)(Zt.A,{...o,value:s,suggestions:n,tokenizeOnBlur:!0,onChange:e=>((e,t)=>{const i=(0,Jt.slice)(e,0,e.length-1),s=(0,Jt.last)(e),n=s?s.toString():"",r=(0,Jt.find)(i,e=>e.toLowerCase()===n.toLowerCase());n&&!r&&i.push(s),t({value:i,name:a})})(e,r),__experimentalShowHowTo:!1})}function ea(e){const t=Array.isArray(e.item[e.field.name])?e.field.name&&e.item[e.field.name].map(t=>e.field.getName(t)):[];let a=[];return e.field.endpoint?a=function(e){let t=[];return void 0!==window[`mailpoet_${e}`]&&(t=window[`mailpoet_${e}`]),t}(String(e.field.endpoint)).map(t=>e.field.getName(t)):e.field.suggestedValues&&(a=e.field.suggestedValues),(0,g.jsx)(Xt,{label:e.field.label,name:e.field.name,placeholder:e.field.placeholder,selectedValues:t,suggestedValues:a,onChange:e.onValueChange})}class ta extends r.Component{renderField=e=>{let t,a=!1;e.field.description&&(a=(0,g.jsx)("p",{className:"description",children:e.field.description}));let i=e.field;switch(void 0!==e.field.field&&(i=Tt().merge(i,e.field.field)),i.type){case"text":t=(0,g.jsx)(Ft,{onValueChange:e.onValueChange,field:e.field,item:e.item,automationId:e.automationId,inline:e.inline,description:e.description});break;case"textarea":t=(0,g.jsx)(Mt,{onValueChange:e.onValueChange,field:e.field,item:e.item,automationId:e.automationId,inline:e.inline,description:e.description});break;case"select":t=(0,g.jsx)($t,{onValueChange:e.onValueChange,field:e.field,item:e.item,automationId:e.automationId,inline:e.inline,description:e.description});break;case"radio":t=(0,g.jsx)(Wt,{onValueChange:e.onValueChange,field:e.field,item:e.item,automationId:e.automationId,inline:e.inline,description:e.description});break;case"checkbox":t=(0,g.jsx)(qt,{onValueChange:e.onValueChange,field:e.field,item:e.item,automationId:e.automationId,inline:e.inline,description:e.description});break;case"selection":t=(0,g.jsx)(Ve.L,{onValueChange:e.onValueChange,field:e.field,automationId:e.automationId,inline:e.inline,description:e.description,item:e.item},`selection-field-${i.name}`);break;case"date":t=(0,g.jsx)(Yt,{onValueChange:e.onValueChange,field:e.field,item:e.item,automationId:e.automationId,inline:e.inline,description:e.description});break;case"reactComponent":t=(0,g.jsx)(e.field.component,{onValueChange:e.onValueChange,field:e.field,item:e.item,automationId:e.automationId,inline:e.inline,description:e.description});break;case"tokenField":t=(0,g.jsx)(ea,{onValueChange:e.onValueChange,field:e.field,item:e.item,automationId:e.automationId,description:e.description});break;case"empty":break;default:t="invalid"}const s="function"==typeof i.disabled?i.disabled(e.field):i.disabled,n={...i.onWrapperClick?{onClick:i.onWrapperClick}:{}};return(0,g.jsxs)("div",{className:v()("mailpoet-form-field",{"mailpoet-form-field-disabled":s}),...n,children:[t,a]},`field-${e.index||0}`)};render(){let e=!1;const{onValueChange:t=()=>{}}=this.props;e=void 0!==this.props.field.fields?this.props.field.fields.map((e,a)=>this.renderField({index:a,field:e,item:this.props.item,onValueChange:t||!1})):this.renderField(this.props);let a=!1;this.props.field.label&&(a=(0,g.jsx)(Kt.D,{level:4,children:(0,g.jsx)("label",{htmlFor:`field_${this.props.field.name}`,children:this.props.field.label})}));let i=!1;return this.props.field.tip&&(i=(0,g.jsx)("p",{className:"mailpoet-form-description",children:this.props.field.tip})),(0,g.jsxs)("div",{className:`mailpoet-form-field-${this.props.field.name} form-field-row-${this.props.field.name}`,children:[a,i,e]})}}ta.propTypes={onValueChange:Rt().func,field:Rt().shape({name:Rt().string.isRequired,values:Rt().objectOf(Rt().string),tip:Rt().oneOfType([Rt().array,Rt().string]),label:Rt().string,fields:Rt().arrayOf(Rt().object),description:Rt().string,onWrapperClick:Rt().func,disabled:Rt().oneOfType([Rt().func,Rt().bool])}).isRequired,item:Rt().object.isRequired},(0,o.registerTranslations)();class aa extends r.Component{constructor(e){super(e),this.formRef=(0,r.createRef)(),this.state={loading:!1,errors:[],item:{}}}componentDidMount(){const{fields:e,params:t={}}=this.props;void 0!==t.id?this.loadItem(t.id):At()(()=>{const t=Tt()(".mailpoet_form").mailpoetSerializeObject(),a=Array.isArray(e)&&e.length>0&&e.find(e=>"checkbox"===e?.type&&e?.isChecked);a&&a.name&&(t[a.name]="1"),this.setState({item:t})})}componentDidUpdate(e){const{item:t,location:a={},params:i={}}=this.props;void 0===i.id&&e.location?.pathname!==a.pathname&&(At()(()=>{this.setState({loading:!1,item:{}})}),void 0===t&&this.formRef.current.reset())}getValues=()=>this.props.item||this.state.item;getErrors=()=>this.props.errors||this.state.errors;loadItem=e=>{const{navigate:t,endpoint:a,onItemLoad:i}=this.props;this.setState({loading:!0}),a&&m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:a,action:"get",data:{id:e}}).done(e=>{this.setState({loading:!1,item:e.data}),"function"==typeof i&&i(e.data)}).fail(()=>{this.setState({loading:!1,item:{}},()=>{t("/lists")})})};handleSubmit=e=>{e.preventDefault();const{navigate:t,endpoint:a,fields:i=[],isValid:s,messages:n={onUpdate:()=>{},onCreate:()=>{}},onSuccess:r,params:o={}}=this.props;if("function"==typeof s&&!1===s())return;this.setState({loading:!0});const l={};i.forEach(e=>{void 0!==e.fields?e.fields.forEach(e=>{l[e.name]=this.state.item[e.name]}):l[e.name]=this.state.item[e.name]}),void 0!==o.id&&(l.id=o.id),a&&m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:a,action:"save",data:l}).always(()=>{this.setState({loading:!1})}).done(()=>{"function"==typeof r?r():t("/"),void 0!==o.id?n.onUpdate():n.onCreate()}).fail(e=>{e&&e.errors&&e.errors.length&&(JSON.stringify(e.errors).includes("reinstall_plugin")?m.U.Notice.showApiErrorNotice(e):this.setState({errors:e.errors}))})};handleValueChange=e=>{const{onChange:t}=this.props,{name:a,value:i}=Object.prototype.hasOwnProperty.call(e,"target")?e.target:e;return"function"==typeof t?t(e):(this.setState(e=>{const t=e.item;return t[a]=i,{item:t}}),!0)};render(){const{children:e,afterFormContent:t,beforeFormContent:a,onSubmit:i,fields:s=[],id:n=""}=this.props;let r;void 0!==this.getErrors()&&(r=this.getErrors().map(e=>(0,g.jsx)("div",{className:"mailpoet_notice notice inline error is-dismissible",children:(0,g.jsx)("p",{children:e.message})},`error-${e.message}`)));const l=v()("mailpoet_form",{mailpoet_form_loading:this.state.loading||this.props.loading});let d=!1,c=!1;"function"==typeof a&&(d=a(this.getValues())),"function"==typeof t&&(c=t(this.getValues()));const m=s.map(e=>{let t=this.handleValueChange;return e.onBeforeChange&&(t=t=>(e.onBeforeChange(t),this.handleValueChange(t))),(0,g.jsx)(ta,{field:e,item:this.getValues(),onValueChange:t,automationId:e.automationId},`field-${e.name}`)});let u=!1;return u=e||(0,g.jsx)(o.Button,{type:"submit",isDisabled:this.state.loading,children:(0,p.__)("Save","mailpoet")}),(0,g.jsxs)("div",{children:[(0,g.jsx)("div",{className:"mailpoet-form-content-around",children:d}),(0,g.jsxs)("form",{id:n,ref:this.formRef,className:l,onSubmit:"function"==typeof i?i:this.handleSubmit,"data-automation-id":this.props.automationId,children:[r,(0,g.jsxs)("div",{className:"mailpoet-form-grid",children:[m,(0,g.jsx)("div",{className:"mailpoet-form-actions",children:u})]})]}),(0,g.jsx)("div",{className:"mailpoet-form-content-around",children:c})]})}}function ia(e){const t=(0,Ue.Zp)();return(0,g.jsx)(aa,{...e,navigate:t})}aa.propTypes={params:Rt().shape({id:Rt().string}),location:Rt().shape({pathname:Rt().string}),item:Rt().object,errors:Rt().arrayOf(Rt().object),endpoint:Rt().string,fields:Rt().arrayOf(Rt().object),messages:Rt().shape({onUpdate:Rt().func,onCreate:Rt().func}),loading:Rt().bool,children:Rt().array,id:Rt().string,automationId:Rt().string,beforeFormContent:Rt().func,afterFormContent:Rt().func,onItemLoad:Rt().func,isValid:Rt().func,onChange:Rt().func,onSubmit:Rt().func,onSuccess:Rt().func,navigate:Rt().func.isRequired};var sa=a(89619);const na=[{name:"email",label:m.U.I18n.t("email"),type:"text",disabled:function(e){return Boolean(Number(e.wp_user_id>0)||1===Number(e.is_woocommerce_user))}},{name:"first_name",label:m.U.I18n.t("firstname"),type:"text",disabled:function(e){return Boolean(Number(e.wp_user_id>0)||1===Number(e.is_woocommerce_user))}},{name:"last_name",label:m.U.I18n.t("lastname"),type:"text",disabled:function(e){return Boolean(Number(e.wp_user_id>0)||1===Number(e.is_woocommerce_user))}},{name:"status",label:m.U.I18n.t("status"),type:"select",automationId:"subscriber-status",values:{subscribed:m.U.I18n.t("subscribed"),unconfirmed:m.U.I18n.t("unconfirmed"),unsubscribed:m.U.I18n.t("unsubscribed"),inactive:m.U.I18n.t("inactive"),bounced:m.U.I18n.t("bounced")}},{name:"timezone",label:(0,p.__)("Timezone","mailpoet"),type:"select",automationId:"subscriber-timezone",placeholder:(0,p.__)("Not set","mailpoet"),values:Object.fromEntries((window.mailpoet_timezone_list||[]).map(e=>[e,e.replaceAll("_"," ")]))},{name:"segments",label:m.U.I18n.t("lists"),type:"selection",placeholder:m.U.I18n.t("selectList"),tip:m.U.I18n.t("welcomeEmailTip"),api_version:window.mailpoet_api_version,endpoint:"segments",multiple:!0,selected:function(e){return!1===Array.isArray(e.subscriptions)?null:e.subscriptions.filter(e=>"subscribed"===e.status).map(e=>e.segment_id)},filter:function(e){return!e?.deleted_at&&"default"===e?.type},getLabel:function(e){return e?.name||""},getCount:function(e){return e?.subscribers||0},getSearchLabel:function(e,t){let a="";return void 0!==t.subscriptions&&t.subscriptions.forEach(t=>{if(e?.id===t.segment_id&&(a=e?.name||"","unsubscribed"===t.status)){const e=m.U.Date.format(t.updated_at);a+=" (%1$s)".replace("%1$s",m.U.I18n.t("unsubscribedOn").replace("%1$s",e))}}),a}},{name:"tags",label:m.U.I18n.t("tags"),type:"tokenField",placeholder:m.U.I18n.t("addNewTag"),suggestedValues:[],endpoint:"tags",getName:function(e){return Object.prototype.hasOwnProperty.call(e,"name")?e.name:String(e)}}];(window.mailpoet_custom_fields||[]).forEach(e=>{const t={name:`cf_${e.id}`,label:e.name,type:e.type};switch(e.params&&(t.params=e.params,e.params.values&&(t.values=e.params.values)),e.type){case"date":t.year_placeholder=m.U.I18n.t("year"),t.month_placeholder=m.U.I18n.t("month"),t.day_placeholder=m.U.I18n.t("day");break;case"select":t.placeholder="-";break;default:t.placeholder=""}na.push(t)});const ra={onUpdate:function(){m.U.Notice.success(m.U.I18n.t("subscriberUpdated"))},onCreate:function(){m.U.Notice.success(m.U.I18n.t("subscriberAdded")),m.U.trackEvent("Subscribers > Add new")}};function oa(e){if(Number(e.wp_user_id)>0)return(0,g.jsx)("p",{className:"description",children:b()(m.U.I18n.t("WPUserEditNotice"),/\[link\](.*?)\[\/link\]/g,(t,a)=>(0,g.jsx)("a",{href:`user-edit.php?user_id=${e.wp_user_id}`,children:t},a))})}function la(e){return(0,g.jsxs)(g.Fragment,{children:[e?.unsubscribes?.map(e=>{const t=Et()(e.createdAt.date).format("dddd MMMM Do YYYY [at] h:mm:ss a");let a;a="admin"===e.source?m.U.I18n.t("unsubscribedAdmin").replace("%1$d",t).replace("%2$d",e.meta||""):"manage"===e.source?m.U.I18n.t("unsubscribedManage").replace("%1$d",t):"newsletter"===e.source?b()(m.U.I18n.t("unsubscribedNewsletter").replace("%1$d",t),/\[link\]/g,(t,a)=>(0,g.jsx)("a",{href:`admin.php?page=mailpoet-newsletter-editor&id=${e.newsletterId||""}`,children:e.newsletterSubject||""},a)):"mp_api"===e.source?m.U.I18n.t("unsubscribedMpApi").replace("%1$d",t):m.U.I18n.t("unsubscribedUnknown").replace("%1$d",t);const i=e.reasonLabel?m.U.I18n.t(e.reasonText?"unsubscribeReasonWithDetails":"unsubscribeReason").replace("%1$s",e.reasonLabel).replace("%2$s",e.reasonText||""):null;return(0,g.jsxs)("div",{className:"description",children:[(0,g.jsx)("p",{children:a}),i&&(0,g.jsx)("p",{children:i})]},`${e.source}-${t}-${e.newsletterId||""}`)}),(0,g.jsxs)("p",{className:"description",children:[(0,g.jsx)("strong",{children:m.U.I18n.t("tip")})," ",m.U.I18n.t("customFieldsTip")]})]})}function da(){const e=(0,Ue.zy)(),t=(0,Ue.g)(),a=(0,Ue.Zp)(),i=e.state?.backUrl||"/";return(0,g.jsxs)("div",{className:"mailpoet-main-container",children:[(0,g.jsx)(d.x,{hideScreenOptions:!0}),(0,g.jsx)(qe.z,{heading:t.id?(0,p.__)("Edit subscriber","mailpoet"):(0,p.__)("Add new subscriber","mailpoet"),headingPrefix:(0,g.jsx)(qe.o,{onClick:()=>a(i),label:m.U.I18n.t("backToList")})}),(0,g.jsx)(sa.X,{}),(0,g.jsx)(ia,{automationId:"subscriber_edit_form",endpoint:"subscribers",fields:na,params:t,messages:ra,beforeFormContent:oa,afterFormContent:la,onSuccess:()=>a(i)})]})}da.displayName="SubscriberForm";var ca=a(6433),ma=a(37059),ua=a(64929),pa=a(1452);function ha({email:e,avatarUrl:t,subscribedAt:a,sourceLabel:i}){const s=(0,Ue.zy)(),n=(0,Ue.Zp)(),r=s.state?.backUrl||"/",o=function(e,t){if(!e)return null;const a=m.U.Date.short(e);return t?(0,p.sprintf)((0,p.__)("Subscribed on %1$s / via %2$s","mailpoet"),a,t):(0,p.sprintf)((0,p.__)("Subscribed on %s","mailpoet"),a)}(a,i);return(0,g.jsxs)(ma.A,{className:"mailpoet-subscriber-stats-heading",align:"center",gap:4,children:[(0,g.jsx)(ua.A,{children:(0,g.jsx)(qe.o,{onClick:()=>n(r),label:m.U.I18n.t("backToList")})}),t?(0,g.jsx)(ua.A,{children:(0,g.jsx)("img",{className:"mailpoet-subscriber-stats-heading-avatar",src:t,alt:"",width:48,height:48})}):null,(0,g.jsxs)(pa.A,{children:[(0,g.jsx)("div",{className:"mailpoet-subscriber-stats-heading-email",children:e}),o?(0,g.jsx)("div",{className:"mailpoet-subscriber-stats-heading-subtitle",children:o}):null]})]})}ha.displayName="StatsHeading";var ga=a(16325),_a=a(36370);function fa({stats:e}){const t=e.woocommerce_overview;if(!t)return null;const a=[{label:(0,p.__)("Orders placed","mailpoet"),value:(0,g.jsx)("a",{href:t.orders_url,children:t.orders_count.toLocaleString()})},{label:(0,p.__)("Lifetime value","mailpoet"),value:t.total_revenue_formatted},{label:(0,p.__)("Average order value","mailpoet"),value:t.average_order_value_formatted}];return(0,g.jsx)(ma.A,{className:"mailpoet-subscriber-stats-woocommerce-overview",align:"stretch",gap:4,children:a.map(e=>(0,g.jsx)(pa.A,{children:(0,g.jsx)(ga.A,{size:"medium",children:(0,g.jsxs)(_a.A,{children:[(0,g.jsx)("div",{className:"mailpoet-subscriber-stats-woocommerce-overview-label",children:e.label}),(0,g.jsx)("div",{className:"mailpoet-subscriber-stats-woocommerce-overview-value",children:e.value})]})})},e.label))})}fa.displayName="WoocommerceOverview";var ba=a(58642),xa=a(88603),va=a(68798),ya=a(93862);const wa=[{label:(0,p.__)("7 days","mailpoet"),value:"7_days"},{label:(0,p.__)("30 days","mailpoet"),value:"30_days"},{label:(0,p.__)("3 months","mailpoet"),value:"3_months"},{label:(0,p.__)("12 months","mailpoet"),value:"12_months"}];function ja(e,t){return e.find(e=>e.key===t)}function Sa(e){return Intl.NumberFormat(void 0,{maximumFractionDigits:1,notation:"compact"}).format(e)}function ka({stats:e,type:t}){if("sent"===t)return(0,g.jsx)(g.Fragment,{children:Sa(e.total_sent)});const a=function(e,t){return t<=0?0:e/t*100}("opened"===t?e.open:e.click,e.total_sent),i=function(e){const t=Math.round(10*e)/10,a=Number.isInteger(t)?0:1;return`${t.toLocaleString(void 0,{minimumFractionDigits:a,maximumFractionDigits:1})}%`}(a);return"clicked"===t?(0,g.jsxs)("span",{className:"mailpoet-subscriber-stats-engagement-value-with-badge",children:[(0,g.jsx)(ya.f,{stat:"clicked",rate:a,tooltipId:`subscriber-stats-clicked-${e.key}`}),(0,g.jsx)("span",{children:i})]}):(0,g.jsx)(g.Fragment,{children:i})}function Na({stats:e}){const[t,a]=(0,r.useState)("30_days"),i=(0,r.useMemo)(()=>ja(e.periodic_stats,"lifetime"),[e.periodic_stats]),s=(0,r.useMemo)(()=>ja(e.periodic_stats,t)||ja(e.periodic_stats,"30_days")||e.periodic_stats[0],[t,e.periodic_stats]);if(!s||!i)return null;const n=xe(e.engagement_score,e.engagement_score_type),o=[{label:(0,p.__)("Emails sent","mailpoet"),type:"sent"},{label:(0,p.__)("Opened","mailpoet"),type:"opened"},{label:(0,p.__)("Clicked","mailpoet"),type:"clicked"}];return(0,g.jsxs)(ga.A,{className:"mailpoet-subscriber-stats-card",size:"medium",children:[(0,g.jsx)(ba.A,{className:"mailpoet-subscriber-stats-card-header",children:(0,g.jsxs)(ma.A,{align:"center",gap:3,children:[(0,g.jsx)(pa.A,{children:(0,g.jsxs)("div",{className:"mailpoet-subscriber-stats-card-title-row",children:[(0,g.jsx)("h2",{className:"mailpoet-subscriber-stats-card-title",children:(0,p.__)("Engagement","mailpoet")}),(0,g.jsx)(va.vw,{className:"mailpoet-subscriber-stats-engagement-badge",variant:n,children:(l=n,{unknown:(0,p.__)("Unknown","mailpoet"),dormant:(0,p.__)("Dormant","mailpoet"),average:(0,p.__)("Average","mailpoet"),good:(0,p.__)("Good","mailpoet"),excellent:(0,p.__)("Excellent","mailpoet")}[l])})]})}),(0,g.jsx)(xa.A,{className:"mailpoet-subscriber-stats-period-control",hideLabelFromVision:!0,label:(0,p.__)("Engagement period","mailpoet"),onChange:e=>a(e),options:wa,value:t})]})}),(0,g.jsx)(_a.A,{children:(0,g.jsxs)("table",{className:"mailpoet-subscriber-stats-engagement-table",children:[(0,g.jsx)("thead",{children:(0,g.jsxs)("tr",{children:[(0,g.jsx)("th",{children:(0,g.jsx)("span",{className:"screen-reader-text",children:(0,p.__)("Engagement metric","mailpoet")})}),(0,g.jsx)("th",{children:s.timeframe}),(0,g.jsx)("th",{children:i.timeframe})]})}),(0,g.jsx)("tbody",{children:o.map(e=>(0,g.jsxs)("tr",{children:[(0,g.jsx)("th",{scope:"row",children:e.label}),(0,g.jsx)("td",{children:(0,g.jsx)(ka,{stats:s,type:e.type})}),(0,g.jsx)("td",{children:(0,g.jsx)(ka,{stats:i,type:e.type})})]},e.type))})]})})]});var l}function Ca(){return(0,g.jsx)("span",{className:"mailpoet-subscriber-stats-empty-value",children:"-"})}function Ea({value:e}){return e?(0,g.jsx)(g.Fragment,{children:e}):(0,g.jsx)(Ca,{})}function Ia(e){switch(e){case"subscribed":return(0,p.__)("Subscribed","mailpoet");case"unconfirmed":return(0,p.__)("Unconfirmed","mailpoet");case"unsubscribed":return(0,p.__)("Unsubscribed","mailpoet");case"inactive":return(0,p.__)("Inactive","mailpoet");case"bounced":return(0,p.__)("Bounced","mailpoet");default:return e}}function Aa({label:e,children:t}){return(0,g.jsxs)("div",{className:"mailpoet-subscriber-stats-profile-row",children:[(0,g.jsx)("dt",{children:e}),(0,g.jsx)("dd",{children:t})]})}function Ua({profile:e,subscriberId:t}){const a=(0,Ue.zy)(),i=(0,Ue.Zp)();return(0,g.jsxs)(ga.A,{className:"mailpoet-subscriber-stats-card",size:"medium",children:[(0,g.jsx)(ba.A,{className:"mailpoet-subscriber-stats-card-header",children:(0,g.jsxs)(ma.A,{align:"center",justify:"space-between",children:[(0,g.jsx)("h2",{className:"mailpoet-subscriber-stats-card-title",children:(0,p.__)("Profile information","mailpoet")}),(0,g.jsx)(ge.Ay,{variant:"secondary",onClick:()=>i(`/edit/${t}`,{state:{backUrl:a.pathname}}),children:(0,p.__)("Edit","mailpoet")})]})}),(0,g.jsx)(_a.A,{children:(0,g.jsxs)("dl",{className:"mailpoet-subscriber-stats-profile-list",children:[(0,g.jsx)(Aa,{label:(0,p.__)("Status","mailpoet"),children:(0,g.jsx)(Ea,{value:Ia(e.status)})}),"unsubscribed"===e.status&&(0,g.jsx)(Aa,{label:(0,p.__)("Unsubscribe reason","mailpoet"),children:(0,g.jsx)(Ea,{value:e.unsubscribe_reason??void 0})}),(0,g.jsx)(Aa,{label:(0,p.__)("First name","mailpoet"),children:(0,g.jsx)(Ea,{value:e.first_name})}),(0,g.jsx)(Aa,{label:(0,p.__)("Last name","mailpoet"),children:(0,g.jsx)(Ea,{value:e.last_name})}),(0,g.jsx)(Aa,{label:(0,p.__)("Email address","mailpoet"),children:(0,g.jsx)(Ea,{value:e.email})}),e.shipping_address.length>0&&(0,g.jsx)(Aa,{label:(0,p.__)("Shipping","mailpoet"),children:(0,g.jsx)("div",{className:"mailpoet-subscriber-stats-shipping-address",children:e.shipping_address.join("\n")})}),e.custom_fields.map(e=>(0,g.jsx)(Aa,{label:e.name,children:(0,g.jsx)(Ea,{value:e.value})},e.id)),(0,g.jsx)(Aa,{label:(0,p.__)("Tags","mailpoet"),children:e.tags.length>0?(0,g.jsx)(o.SubscriberTags,{subscribers:e.tags,variant:"wordpress",isInverted:!0}):(0,g.jsx)(Ca,{})}),(0,g.jsx)(Aa,{label:(0,p.__)("Lists","mailpoet"),children:e.segments.length>0?(0,g.jsx)(o.SegmentTags,{segments:e.segments}):(0,g.jsx)(Ca,{})})]})})]})}Na.displayName="EngagementCard",Ua.displayName="ProfileInformation";var Ta=a(58633),Pa=a(79616),Ra=a(25557),Da=a(48547),Fa=a(2297),Oa=a(99276);const{subscribersLimitReached:Ma,subscribersLimit:La,subscribersCount:$a,premiumActive:Ba,hasValidApiKey:Wa,hasValidPremiumKey:Va,isPremiumPluginInstalled:qa,pluginPartialKey:za}=m.U,Ha=Wa||Va,Ga=e=>(0,g.jsx)("p",{children:b()(e,/(\[subscribersCount]|\[subscribersLimit])/g,e=>"[subscribersCount]"===e?$a:La)}),Ya=(e,t,a="_blank")=>(0,g.jsx)(Ge.$,{href:t,target:a,rel:"noopener noreferrer",children:e});function Ka({message:e,actionButton:t,capabilities:a={}}){let i,s,n=(0,p.__)("This is a Premium feature","mailpoet");if(!Va||qa&&Ba)if(Ma){i=Ga((0,p.__)("Congratulations, you now have [subscribersCount] subscribers! Your plan is limited to [subscribersLimit] subscribers. You need to upgrade now to be able to continue using MailPoet.","mailpoet"));const e=Ha?m.U.MailPoetComUrlFactory.getUpgradeUrl(za):m.U.MailPoetComUrlFactory.getPurchasePlanUrl(+$a+1,null,null,null);s=Ya((0,p.__)("Upgrade your plan","mailpoet"),e)}else if(Wa&&!Va||Va&&Object.keys(a).some(e=>m.U.capabilities[e].isRestricted)){n=(0,p.__)("Upgrade your plan","mailpoet"),i=e;const t=m.U.MailPoetComUrlFactory.getUpgradeUrl(za,{s:$a,capabilities:a});s=Ya((0,p.__)("Upgrade","mailpoet"),t)}else i=e,s=t;else i=Ga((0,p.__)("Your current MailPoet plan includes advanced features, but they require the MailPoet Premium plugin to be installed and activated.","mailpoet")),r=qa?(0,p.__)("Activate MailPoet Premium plugin","mailpoet"):(0,p.__)("Download MailPoet Premium plugin","mailpoet"),s=(0,g.jsx)(Oa.Wr,{buttonText:r});var r;return(0,g.jsx)(Fa.P,{title:n,message:i,actionButton:s})}function Za(e,t=0){const a=new Date;return a.setDate(a.getDate()-e),a.setHours(Math.max(0,a.getHours()-t)),a}function Ja(e){return m.U.Date.format(e,{format:"Y-m-d"})}function Qa(e){const t=new Date,a=new Date;a.setDate(t.getDate()-1);const i=Ja(e);return i===Ja(t)?(0,p.__)("Today","mailpoet"):i===Ja(a)?(0,p.__)("Yesterday","mailpoet"):m.U.Date.short(e)}function Xa({item:e}){return(0,g.jsxs)("li",{className:"mailpoet-subscriber-stats-activity-item",children:[(0,g.jsx)("span",{className:"mailpoet-subscriber-stats-activity-icon","aria-hidden":"true",children:(0,g.jsx)(ae.A,{icon:e.icon})}),(0,g.jsx)("div",{className:"mailpoet-subscriber-stats-activity-item-content",children:(0,g.jsxs)("div",{className:"mailpoet-subscriber-stats-activity-item-main",children:[(0,g.jsxs)("div",{children:[(0,g.jsx)("div",{className:"mailpoet-subscriber-stats-activity-item-title",children:e.title}),(0,g.jsx)("div",{className:"mailpoet-subscriber-stats-activity-item-description",children:e.description})]}),(0,g.jsx)("time",{className:"mailpoet-subscriber-stats-activity-item-date",dateTime:e.date.toISOString(),children:m.U.Date.full(e.date)})]})})]})}function ei({group:e}){return(0,g.jsxs)("li",{className:"mailpoet-subscriber-stats-activity-day",children:[(0,g.jsx)("h3",{className:"mailpoet-subscriber-stats-activity-day-title",children:e.label}),(0,g.jsx)("ul",{className:"mailpoet-subscriber-stats-activity-list",children:e.items.map(e=>(0,g.jsx)(Xa,{item:e},e.key))})]})}function ti({eventType:e}){const t=[{key:"opened",eventType:"open",icon:Pa.A,title:(0,p.__)("Opened email “Spring sale newsletter”","mailpoet"),description:(0,p.__)("Opened the email on desktop.","mailpoet"),date:Za(0,2)},{key:"clicked",eventType:"click",icon:Ra.A,title:(0,p.__)("Clicked a link in email “Spring sale newsletter”","mailpoet"),description:(0,p.__)("https://example.com/spring-collection","mailpoet"),date:Za(0,3)},{key:"purchased",eventType:"purchase",icon:Da.A,title:(0,p.__)("Completed purchase","mailpoet"),description:(0,p.__)("Revenue tracked from an email click.","mailpoet"),date:Za(1)},{key:"unsubscribed",eventType:"unsubscribe",icon:ce.A,title:(0,p.__)("Unsubscribed","mailpoet"),description:(0,p.__)("Reason: No reason provided","mailpoet"),date:Za(1,2)}].filter(t=>"all"===e||t.eventType===e).sort((e,t)=>t.date.getTime()-e.date.getTime()).reduce((e,t)=>{const a=Ja(t.date),i=e.find(e=>e.key===a);return i?(i.items.push(t),e):(e.push({key:a,label:Qa(t.date),items:[t]}),e)},[]);return(0,g.jsxs)("div",{className:"mailpoet-subscriber-stats-locked-activity","data-automation-id":"subscriber-stats-no-access",children:[(0,g.jsx)("ul",{className:"mailpoet-subscriber-stats-activity-days mailpoet-subscriber-stats-activity-list-sample","aria-label":(0,p.__)("Sample subscriber activity","mailpoet"),children:t.map(e=>(0,g.jsx)(ei,{group:e},e.key))}),(0,g.jsx)("div",{className:"mailpoet-subscriber-stats-no-access-content",children:(0,g.jsx)(Ka,{message:(()=>{const e=(0,p.__)("Learn more about how each of your subscribers is engaging with your emails. See which emails they’ve opened, the links they clicked. If you’re a WooCommerce store owner, you’ll also see any purchases made as a result of your emails. [link]Learn more[/link].","mailpoet");return(0,g.jsx)("p",{children:b()(e,/\[link](.*?)\[\/link]/g,e=>(0,g.jsx)("a",{href:m.U.premiumLink,target:"_blank",rel:"noopener noreferrer",children:e},e))})})(),actionButton:(0,g.jsx)(Ge.$,{href:m.U.MailPoetComUrlFactory.getPurchasePlanUrl(m.U.subscribersCount,m.U.currentWpUserEmail,null,{utm_medium:"stats",utm_campaign:"signup"}),target:"_blank",rel:"noopener noreferrer",children:(0,p.__)("Upgrade","mailpoet")}),capabilities:{detailedAnalytics:!0}})})]})}function ai({eventType:e,params:t,location:a}){const i=(0,r.useMemo)(()=>Ta.Hooks.applyFilters("mailpoet_subscribers_opened_emails_stats",()=>(0,g.jsx)(ti,{eventType:e}),t,a,e),[e,a,t]);return(0,g.jsx)(i,{})}const ii=[{label:(0,p.__)("All events","mailpoet"),value:"all"},{label:(0,p.__)("Email opens","mailpoet"),value:"open"},{label:(0,p.__)("Link clicks","mailpoet"),value:"click"},{label:(0,p.__)("Purchases","mailpoet"),value:"purchase"},{label:(0,p.__)("Unsubscribes","mailpoet"),value:"unsubscribe"}];function si({lastEngagementAt:e,location:t,params:a}){const[i,s]=(0,r.useState)("all"),n=function(){const e=m.U.capabilities?.detailedAnalytics;return!e||e.isRestricted}(),o=e?(0,p.sprintf)((0,p.__)("Last seen on %s","mailpoet"),m.U.Date.full(e)):(0,p.__)("Last seen: never","mailpoet");return(0,g.jsxs)(ga.A,{className:"mailpoet-subscriber-stats-card mailpoet-subscriber-stats-activity",size:"medium",children:[(0,g.jsx)(ba.A,{className:"mailpoet-subscriber-stats-card-header",children:(0,g.jsxs)(ma.A,{align:"center",gap:3,children:[(0,g.jsx)(pa.A,{children:(0,g.jsxs)("div",{children:[(0,g.jsx)("h2",{className:"mailpoet-subscriber-stats-card-title",children:(0,p.__)("Activity","mailpoet")}),(0,g.jsx)("div",{className:"mailpoet-subscriber-stats-card-subtitle",children:o})]})}),n&&(0,g.jsx)(xa.A,{className:"mailpoet-subscriber-stats-activity-filter",hideLabelFromVision:!0,label:(0,p.__)("Activity event type","mailpoet"),onChange:e=>s(e),options:ii,value:i})]})}),(0,g.jsx)(_a.A,{className:"mailpoet-subscriber-stats-activity-body",children:(0,g.jsx)(ai,{eventType:i,params:a,location:t})})]})}function ni(){const e=(0,Ue.g)(),t=(0,Ue.zy)(),[a,i]=(0,r.useState)(null),[s,n]=(0,r.useState)(!0);return(0,r.useEffect)(()=>{m.U.Ajax.post({api_version:m.U.apiVersion,endpoint:"subscriberStats",action:"get",data:{subscriber_id:e.id}}).done(e=>{i(e.data),n(!1)}).fail(e=>{n(!1),e.errors.length>0&&m.U.Notice.showApiErrorNotice(e,{scroll:!0})})},[e.id]),s?(0,g.jsx)(ca.R,{}):a?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(d.x,{hideScreenOptions:!0}),(0,g.jsxs)("div",{className:"mailpoet-subscriber-stats",children:[(0,g.jsx)(ha,{email:a.email,avatarUrl:a.avatar_url,subscribedAt:a.subscribed_at,sourceLabel:a.source_label}),a.is_woo_active&&a.is_woocommerce_user&&(0,g.jsx)(fa,{stats:a}),(0,g.jsxs)("div",{className:"mailpoet-subscriber-stats-content",children:[(0,g.jsxs)("div",{className:"mailpoet-subscriber-stats-primary-column",children:[(0,g.jsx)(Na,{stats:a}),(0,g.jsx)(Ua,{profile:a.profile,subscriberId:Number(e.id)})]}),(0,g.jsx)(si,{lastEngagementAt:a.last_engagement,params:e,location:t})]})]})]}):null}function ri(){return(0,g.jsx)(l.F.Provider,{value:(0,l.f)(window),children:(0,g.jsxs)(Ae.HashRouter,{children:[(0,g.jsx)(c.D,{}),(0,g.jsx)(u.q,{}),(0,g.jsxs)(Ue.BV,{children:[(0,g.jsx)(Ue.qh,{path:"/new",element:(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(da,{})})}),(0,g.jsx)(Ue.qh,{path:"/edit/:id",element:(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(da,{})})}),(0,g.jsx)(Ue.qh,{path:"/stats/:id/*",element:(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(ni,{})})}),(0,g.jsx)(Ue.qh,{path:"*",element:(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(Nt,{})})})]})]})})}si.displayName="ActivityShell",ni.displayName="SubscriberStats";const oi=document.getElementById("subscribers_container");oi&&((0,o.registerTranslations)(),(0,n.H)(oi).render((0,g.jsx)(ri,{})));var li=a(95776),di=a(66177),ci=a(5296),mi=a(75847),ui=a(45919);function pi({isModalOpen:e,onClose:t}){const[a,i]=(0,r.useState)(!1),{notices:s}=(0,r.useContext)(l.F),n=(0,r.useCallback)(()=>{i(!0),m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"newsletters",action:"create",data:{type:"standard",subject:(0,p.__)("Subject","mailpoet"),new_editor:!0}}).done(e=>{window.location.href=m.U.getBlockEmailEditorUrl(e.data.wp_post_id)}).fail(e=>{i(!1),t(),e.errors.length>0&&s.apiError(e,{scroll:!0})})},[s,t]);return e?(m.U.trackEvent("New Email Editor > try new email editor modal opened",{},{send_immediately:!0}),(0,g.jsxs)(Te.A,{title:(0,p.__)("Try the new email editor","mailpoet"),onRequestClose:()=>{m.U.trackEvent("New Email Editor > try new email editor modal closed"),t()},className:"mailpoet-new-editor-modal",children:[(0,g.jsxs)("div",{className:"mailpoet-new-editor-modal-image",children:[(0,g.jsx)("span",{className:"mailpoet-new-editor-modal-image__beta_label",children:(0,p.__)("Alpha version","mailpoet")}),(0,g.jsx)("img",{src:`${m.U.cdnUrl}email-editor/new-editor-modal-header.png`,alt:(0,p.__)("Try the new email editor","mailpoet"),width:"324",height:"130"})]}),(0,g.jsx)("p",{children:(0,p.__)("Take a first look at our new email editor. It introduces a more flexible, modern way to design your emails. This version is still evolving, and your feedback will help guide what comes next.","mailpoet")}),(0,g.jsx)("p",{className:"mailpoet-new-editor-modal-note",children:(0,p.__)("Note: Emails created here can't be opened in the legacy editor.","mailpoet")}),(0,g.jsxs)("div",{className:"mailpoet-new-editor-modal-footer",children:[(0,g.jsx)(ge.Ay,{type:"button",variant:"tertiary",onClick:()=>{m.U.trackEvent("New Email Editor > try new email editor modal cancel button clicked",{},{send_immediately:!0},t)},children:(0,p.__)("Cancel","mailpoet")}),(0,g.jsx)(ge.Ay,{type:"button",variant:"primary",isBusy:a,onClick:()=>{m.U.trackEvent("New Email Editor > try new email editor modal create with new editor button clicked",{},{send_immediately:!0},n)},children:(0,p.__)("Try it now","mailpoet")})]})]})):null}var hi=a(48218);function gi({errors:e}){return e.length<1?null:(0,g.jsx)(h.$,{type:"error",closable:!1,children:e.map(e=>(0,g.jsx)("p",{children:e.message},e.message))})}var _i=a(43987),fi=a(60713);const bi=_i.Ay;function xi({children:e}){return(0,g.jsx)(bi,{delay:0,text:(0,g.jsx)("div",{className:"mailpoet-newsletter-type-info-tooltip",children:e}),children:(0,g.jsx)("div",{className:"mailpoet-newsletter-type-info",children:(0,g.jsx)(mi.A,{icon:fi.A,size:20})})})}const vi=li.A;function yi({filter:e=null,hideScreenOptions:t=!0}){const a=(0,Ue.Zp)(),[i,s]=(0,r.useState)(null),[n,o]=(0,r.useState)(!1),l=window.mailpoet_block_email_editor_enabled,d=e=>{void 0!==e&&(a(`/new/${e}`),m.U.trackEvent("Emails > Type selected",{"Email type":e}))},c=Lt.default.partial(e=>{s(e),m.U.trackEvent("Emails > Type selected",{"Email type":e}),m.U.Ajax.post({api_version:m.U.apiVersion,endpoint:"newsletters",action:"create",data:{type:e,subject:(0,p.__)("Subject","mailpoet")}}).done(e=>{a(`/template/${e.data.id}`)}).fail(e=>(s(null),e.errors.length>0?(0,g.jsx)(gi,{errors:e.errors}):null))},"standard"),u=Lt.default.partial(d,"notification"),h=Lt.default.partial(d,"re-engagement"),_=l?(0,g.jsxs)(di.A,{className:"mailpoet-dropdown-button-group",children:[(0,g.jsx)(ge.Ay,{variant:"secondary",onClick:c,isBusy:"standard"===i,disabled:null!==i,"aria-label":(0,p.__)("Create Newsletter","mailpoet"),"data-automation-id":"create_standard",children:(0,p.__)("Create","mailpoet")}),(0,g.jsx)(ci.A,{className:"mailpoet-dropdown-button",contentClassName:"mailpoet-dropdown-button-content",popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:e,onToggle:t})=>(0,g.jsx)(ge.Ay,{variant:"secondary",className:"mailpoet-button-with-wordpress-icon",onClick:t,isBusy:"standard"===i,disabled:null!==i,"aria-expanded":e,"aria-label":(0,p.__)("Choose editor version","mailpoet"),"data-automation-id":"create_standard_email_dropdown",children:(0,g.jsx)(mi.A,{icon:ui.A,size:24})}),onToggle:e=>e&&m.U.trackEvent("New Email Editor > create email icon clicked"),renderContent:()=>(0,g.jsx)(vi,{variant:"tertiary",onClick:()=>{o(!0),m.U.trackEvent("New Email Editor > creating using new email editor button clicked")},children:(0,p.__)("Create using the new email editor (Alpha)","mailpoet")})})]}):(0,g.jsx)(ge.Ay,{variant:"secondary",onClick:c,isBusy:i,"data-automation-id":"create_standard",children:(0,p.__)("Create","mailpoet")}),f=[{slug:"standard",title:(0,p.__)("Newsletter","mailpoet"),description:(0,p.__)("Send a newsletter with images, buttons, dividers, and social bookmarks. Or, just send a basic text email.","mailpoet"),action:_},{slug:"automations",title:(0,g.jsxs)(g.Fragment,{children:[(0,p.__)("Automations","mailpoet")," ",(0,g.jsx)(xi,{children:(0,p.__)("Automations such as Welcome emails and WooCommerce emails can be found here, alongside more automation templates powered by our new editor.","mailpoet")})]}),description:(0,p.__)("Set up automated emails like welcome emails, abandoned cart reminders or one of our many automation templates to inform, engage and reward your audience.","mailpoet"),action:(0,g.jsx)(ge.Ay,{variant:"secondary",onClick:()=>{s("automation"),window.location.href="admin.php?page=mailpoet-automation-templates"},isBusy:"automation"===i,disabled:null!==i,"aria-label":(0,p.__)("Create Automation","mailpoet"),"data-automation-id":"create_automation",children:(0,p.__)("Create","mailpoet")})},{slug:"notification",title:(0,p.__)("Latest Post Notifications","mailpoet"),description:(0,p.__)("Let MailPoet email your subscribers with your latest content. You can send daily, weekly, monthly, or even immediately after publication.","mailpoet"),videoGuide:"https://kb.mailpoet.com/article/210-video-guide-to-post-notifications",action:(0,g.jsx)(ge.Ay,{variant:"secondary",onClick:u,isBusy:"notification"===i,disabled:null!==i,"aria-label":(0,p.__)("Create Latest Post Notification","mailpoet"),"data-automation-id":"create_notification",children:(0,p.__)("Create","mailpoet")})},{slug:"re_engagement",title:(0,p.__)("Re-engagement Emails","mailpoet"),description:(0,p.__)("Automatically email and win back subscribers who have recently lost interest and stopped engaging with your emails.","mailpoet"),action:(0,g.jsx)(ge.Ay,{variant:"secondary",onClick:h,isBusy:"re_engagement"===i,disabled:null!==i,"aria-label":(0,p.__)("Create Re-engagement Email","mailpoet"),"data-automation-id":"create_re_engagement",children:(0,p.__)("Create","mailpoet")})}];let b=Ta.Hooks.applyFilters("mailpoet_newsletters_types",[...f],this);e&&(b=b.filter(e));const x=m.U.Ajax.constructGetUrl({api_version:m.U.apiVersion,endpoint:"newsletterTemplates",action:"getAll"});return(0,g.jsxs)(g.Fragment,{children:[t&&(0,g.jsx)(hi.x,{}),(0,g.jsx)("link",{rel:"prefetch",href:window.mailpoet_editor_javascript_url,as:"script"}),(0,g.jsx)("div",{className:"mailpoet-newsletter-types",children:b.map(e=>(e=>(0,g.jsxs)("div",{"data-type":e.slug,className:"mailpoet-newsletter-type",children:[(0,g.jsx)("div",{className:"mailpoet-newsletter-type-image"}),(0,g.jsxs)("div",{className:"mailpoet-newsletter-type-content",children:[(0,g.jsxs)(Kt.D,{level:4,children:[e.title," ",e.beta?`(${(0,p.__)("Beta","mailpoet")})`:""]}),(0,g.jsx)("p",{children:e.description}),(0,g.jsx)("div",{className:"mailpoet-flex-grow"}),(0,g.jsx)("div",{className:"mailpoet-newsletter-type-action",children:e.action})]})]},e.slug))(e),this)}),(0,g.jsx)("link",{rel:"prefetch",href:x,as:"fetch"}),(0,g.jsx)(pi,{onClose:()=>o(!1),isModalOpen:n})]})}function wi({onSelect:e,name:t,label:a,count:i,automationId:s,active:n}){const r=v()("components-button","components-tab-panel__tabs-item",{"is-active":!!n});return(0,g.jsxs)("a",{href:"#",className:r,onClick:a=>{a.preventDefault(),e(t)},"data-automation-id":s,children:[(0,g.jsx)("span",{"data-title":a,children:a}),Number(i)>0&&(0,g.jsx)("span",{className:"count",children:parseInt(i.toString(),10).toLocaleString()})]},t)}function ji({onSelect:e,categories:t,active:a}){const i=t.map(t=>(0,r.createElement)(wi,{...t,key:t.name,onSelect:e,active:t.name===a}));return(0,g.jsx)("div",{className:"mailpoet-categories",children:(0,g.jsx)("div",{className:"components-tab-panel__tabs",children:i})})}ji.displayName="Categories";var Si=a(59396);function ki(e){const t=(0,Ue.zy)();return(0,g.jsx)(Si.Y,{...e,location:t})}function Ni({label:e,onSelect:t,children:a,onDelete:i,automationId:s,className:n}){return(0,g.jsxs)("div",{className:`mailpoet-template ${n}`,"data-automation-id":"select_template_box",children:[a,(0,g.jsxs)("div",{className:"mailpoet-template-info",children:[(0,g.jsx)(Kt.D,{level:5,title:e,children:e}),(0,g.jsxs)("div",{children:[i&&(0,g.jsx)(Ge.$,{variant:"destructive",onClick:i,children:(0,p.__)("Delete","mailpoet")}),(0,g.jsx)(Ge.$,{automationId:s,onClick:t,children:(0,p.__)("Select","mailpoet")})]})]})]})}var Ci=a(34720);class Ei extends r.Component{constructor(e){super(e),this.onPreview=this.onPreview.bind(this),this.onDelete=this.onDelete.bind(this),this.onSelect=this.onSelect.bind(this)}onDelete(){const{id:e,name:t,beforeDelete:a,afterDelete:i}=this.props;(0,Ci.Z)({message:(0,p.__)('You are about to delete the template named "%1$s".',"mailpoet").replace("%1$s",t),onConfirm:()=>{a(),m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"newsletterTemplates",action:"delete",data:{id:e}}).done(()=>{i(!0,e)}).fail(e=>{e.errors.length>0&&this.context.notices.apiError(e,{scroll:!0}),i(!1)})}})}onPreview(){m.U.Modal.popup({title:this.props.name,template:'<img class="mailpoet-template-preview-image" src="{{ thumbnail }}" />',data:this.props})}onSelect(){const{newsletterId:e,name:t,beforeSelect:a,afterSelect:i}=this.props;a(),m.U.trackEvent("Emails > Template selected",{"Email name":t}),m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"newsletters",action:"save",data:{id:e,template_id:this.props.id}}).done(e=>{i(!0,e.data.id)}).fail(e=>{e.errors.length>0&&this.context.notices.apiError(e,{scroll:!0}),i(!1)})}render(){const{index:e,name:t,readonly:a,thumbnail:i=null}=this.props;let s="";return"string"==typeof i&&i.length>0&&(s=(0,g.jsxs)("a",{className:"mailpoet-template-preview",href:"#",onClick:e=>{e.preventDefault(),this.onPreview(e)},children:[(0,g.jsx)("div",{className:"mailpoet-template-thumbnail",children:i?(0,g.jsx)("img",{src:i,alt:(0,p.__)("Template preview","mailpoet"),loading:"lazy"}):""}),(0,g.jsx)("div",{className:"mailpoet-template-preview-overlay",children:(0,g.jsx)(Ge.$,{children:(0,p.__)("Preview","mailpoet")})})]})),(0,g.jsx)(Ni,{label:t,onSelect:this.onSelect,onDelete:!1===a?this.onDelete:void 0,automationId:`select_template_${e}`,className:"mailpoet-template-two-lines",children:s})}}Ei.contextType=l.F,Ei.propTypes={index:Rt().number.isRequired,id:Rt().number.isRequired,newsletterId:Rt().string.isRequired,name:Rt().string.isRequired,thumbnail:Rt().string,readonly:Rt().bool.isRequired,beforeDelete:Rt().func.isRequired,afterDelete:Rt().func.isRequired,beforeSelect:Rt().func.isRequired,afterSelect:Rt().func.isRequired},Ei.displayName="TemplateBox";class Ii extends r.Component{constructor(e){super(e),this.fileRef=(0,r.createRef)(),this.handleSubmit=this.handleSubmit.bind(this)}handleSubmit(e){if(e.preventDefault(),Lt.default.size(this.fileRef.current.files)<=0)return!1;const t=Lt.default.first(this.fileRef.current.files),a=new FileReader;return a.onload=e=>{try{this.saveTemplate(JSON.parse(e.target.result)),m.U.trackEvent("Emails > Template imported")}catch(e){this.context.notices.error((0,g.jsx)("p",{children:(0,p.__)("This template file appears to be damaged. Please try another one.","mailpoet")}))}},a.readAsText(t),!0}saveTemplate(e){const t=e,{beforeImport:a,afterImport:i}=this.props;Lt.default.isUndefined(t.body)||(t.body=JSON.stringify(t.body));try{t.categories=JSON.parse(t.categories)}catch(e){t.categories=[]}-1===t.categories.indexOf("saved")&&t.categories.push("saved"),-1===t.categories.indexOf("standard")&&-1===t.categories.indexOf("welcome")&&-1===t.categories.indexOf("notification")&&t.categories.push("standard"),t.categories=JSON.stringify(t.categories),a(),m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"newsletterTemplates",action:"save",data:t}).done(e=>{i(!0,e.data)}).fail(e=>{e.errors.length>0&&this.context.notices.apiError(e,{scroll:!0}),i(!1)})}render(){return(0,g.jsxs)("div",{className:"mailpoet-template-import",children:[(0,g.jsxs)("h4",{children:[(0,p.__)("Import a template","mailpoet"),(0,g.jsx)(ze.Tooltip,{tooltip:(0,p.__)("You can only upload .json templates that were originally created with MailPoet.","mailpoet"),place:"right",className:"tooltip-help-import-template"})]}),(0,g.jsxs)("form",{onSubmit:this.handleSubmit,children:[(0,g.jsx)("input",{type:"file",placeholder:(0,p.__)("Select a .json file to upload","mailpoet"),ref:this.fileRef}),(0,g.jsx)("p",{className:"submit",children:(0,g.jsx)("input",{className:"button button-primary",type:"submit",value:(0,p.__)("Upload","mailpoet")})})]})]})}}Ii.contextType=l.F,Ii.propTypes={beforeImport:Rt().func.isRequired,afterImport:Rt().func.isRequired};var Ai=a(45685);const Ui=[];window.mailpoet_newsletters_templates_recently_sent_count&&Ui.push({name:"recent",label:(0,p.__)("Recently sent","mailpoet")}),Ui.push({name:"standard",label:(0,p.__)("Newsletters","mailpoet")},{name:"welcome",label:(0,p.__)("Welcome Emails","mailpoet")},{name:"notification",label:(0,p.__)("Post Notifications","mailpoet")},{name:"re_engagement",label:(0,p.__)("Re-engagement Emails","mailpoet")},{name:"blank",label:(0,p.__)("Simple text","mailpoet")}),window.mailpoet_woocommerce_active&&Ui.push({name:"woocommerce",label:(0,p.__)("WooCommerce Emails","mailpoet")}),Ui.push({name:"saved",label:(0,p.__)("Your saved templates","mailpoet")});class Ti extends r.Component{constructor(e){super(e),this.state={loading:!0,templates:{},emailType:null,emailOptions:{},selectedTab:""},this.templates={},this.addTemplate=this.addTemplate.bind(this),this.afterTemplateDelete=this.afterTemplateDelete.bind(this),this.afterTemplateSelect=this.afterTemplateSelect.bind(this),this.afterTemplateImport=this.afterTemplateImport.bind(this)}componentDidMount(){m.U.Ajax.get({api_version:window.mailpoet_api_version,endpoint:"newsletterTemplates",action:"getAll"}).done(e=>{0===e.data.length&&(e.data=[{name:(0,p.__)("MailPoet's Guide","mailpoet"),categories:'["welcome", "notification", "standard", "woocommerce"]',readonly:!0}]),e.data.forEach(this.addTemplate),this.sortTemplates()}).fail(e=>{e.errors.length>0&&this.context.notices.apiError(e,{scroll:!0})}).always(()=>{this.selectInitialTab()})}addTemplate(e){const t=Ui.map(e=>e.name);let a;-1===t.indexOf("woocommerce")&&t.push("woocommerce");try{a=JSON.parse(e.categories).filter(e=>-1!==t.indexOf(e))}catch(e){a=[]}0===a.length&&a.push("saved"),a.forEach(t=>{void 0===this.templates[t]&&(this.templates[t]=[]),this.templates[t].unshift(e)})}sortTemplates(){const e=["welcome","notification","standard"];Object.keys(this.templates).forEach(t=>{this.templates[t].sort((a,i)=>{if(e.includes(t)){if(a.categories.includes('"blank"')&&!i.categories.includes('"blank"'))return-1;if(!a.categories.includes('"blank"')&&i.categories.includes('"blank"'))return 1}return a.id<i.id?1:-1})})}selectInitialTab(){let e,t,a="standard";m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"newsletters",action:"get",data:{id:this.props.params.id}}).done(i=>{e=i.data.type,t=i.data.options,"automatic"===e&&(e=i.data.options.group||e),window.mailpoet_newsletters_templates_recently_sent_count?a="recent":Lt.default.findWhere(Ui,{name:i.data.type})?a=i.data.type:"automatic"===i.data.type&&Lt.default.findWhere(Ui,{name:i.data.options.group})&&(a=i.data.options.group)}).fail(e=>{e.errors.length>0&&this.context.notices.apiError(e,{scroll:!0})}).always(()=>{this.setState({templates:this.templates,emailType:e,emailOptions:t,selectedTab:a,loading:!1})})}afterTemplateDelete(e,t){e&&Object.keys(this.templates).forEach(e=>{this.templates[e]=this.templates[e].filter(e=>e.id!==t)}),this.setState({templates:this.templates,loading:!1})}afterTemplateSelect(e,t){e?window.location=(e=>{const t=new URLSearchParams(window.location.search).get("context"),a=`admin.php?page=mailpoet-newsletter-editor&id=${e}`;return t?`${a}&context=${t}`:a})(t):this.setState({loading:!1})}afterTemplateImport(e,t){e&&this.addTemplate(t),this.setState({templates:this.templates,selectedTab:e?"saved":"import",loading:!1})}render(){if(this.state.loading)return(0,g.jsx)(ca.R,{});const e=Ui.concat({name:"import",label:(0,p._x)("Import","Importing template tab title","mailpoet")}).map(e=>Object.assign(e,{automationId:`templates-${e.name.replace(/\s+/g,"-").toLowerCase()}`}));let t=null;if("import"===this.state.selectedTab)t=(0,g.jsx)(Ii,{beforeImport:()=>this.setState({loading:!0}),afterImport:this.afterTemplateImport});else{let e=this.state.templates[this.state.selectedTab]||[];e=0===e.length?this.state.loading?null:(0,g.jsx)("p",{children:(0,p.__)("This category does not contain any template yet!","mailpoet")}):e.map((e,t)=>(0,g.jsx)(Ei,{index:t,newsletterId:this.props.params.id,beforeDelete:()=>this.setState({loading:!0}),afterDelete:this.afterTemplateDelete,beforeSelect:()=>this.setState({loading:!0}),afterSelect:this.afterTemplateSelect,id:e.id,name:e.name,thumbnail:e.thumbnail,readonly:e.readonly},e.id)),t=e}let a,i=null;if(Ai.Ls.includes(this.state.emailType)){const e=this.state.emailOptions?.automationId,t=e?`admin.php?page=mailpoet-automation-editor&id=${e}`:"admin.php?page=mailpoet-automation";a=()=>{window.location=t},i=(0,g.jsx)("input",{type:"button",className:"button link-button",onClick:a,value:"Cancel"})}return(0,g.jsxs)("div",{children:[(0,g.jsx)(ki,{emailType:this.state.emailType,automationId:"email_template_selection_heading",buttons:i,onLogoClick:a}),(0,g.jsxs)("div",{className:"mailpoet-templates",children:[(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(ji,{categories:e,active:this.state.selectedTab,onSelect:e=>this.setState({selectedTab:e})})}),(0,g.jsx)(o.ErrorBoundary,{children:t})]})]})}}Ti.contextType=l.F,Ti.propTypes={params:Rt().shape({id:Rt().string}).isRequired};var Pi=a(29065),Ri=a.n(Pi),Di=a(77297),Fi=a(76056);const Oi={lessThanXSeconds:{one:"less than a second",other:"less than {{count}} seconds"},xSeconds:{one:"1 second",other:"{{count}} seconds"},halfAMinute:"half a minute",lessThanXMinutes:{one:"less than a minute",other:"less than {{count}} minutes"},xMinutes:{one:"1 minute",other:"{{count}} minutes"},aboutXHours:{one:"about 1 hour",other:"about {{count}} hours"},xHours:{one:"1 hour",other:"{{count}} hours"},xDays:{one:"1 day",other:"{{count}} days"},aboutXWeeks:{one:"about 1 week",other:"about {{count}} weeks"},xWeeks:{one:"1 week",other:"{{count}} weeks"},aboutXMonths:{one:"about 1 month",other:"about {{count}} months"},xMonths:{one:"1 month",other:"{{count}} months"},aboutXYears:{one:"about 1 year",other:"about {{count}} years"},xYears:{one:"1 year",other:"{{count}} years"},overXYears:{one:"over 1 year",other:"over {{count}} years"},almostXYears:{one:"almost 1 year",other:"almost {{count}} years"}};function Mi(e){return(t={})=>{const a=t.width?String(t.width):e.defaultWidth;return e.formats[a]||e.formats[e.defaultWidth]}}const Li={date:Mi({formats:{full:"EEEE, MMMM do, y",long:"MMMM do, y",medium:"MMM d, y",short:"MM/dd/yyyy"},defaultWidth:"full"}),time:Mi({formats:{full:"h:mm:ss a zzzz",long:"h:mm:ss a z",medium:"h:mm:ss a",short:"h:mm a"},defaultWidth:"full"}),dateTime:Mi({formats:{full:"{{date}} 'at' {{time}}",long:"{{date}} 'at' {{time}}",medium:"{{date}}, {{time}}",short:"{{date}}, {{time}}"},defaultWidth:"full"})},$i={lastWeek:"'last' eeee 'at' p",yesterday:"'yesterday at' p",today:"'today at' p",tomorrow:"'tomorrow at' p",nextWeek:"eeee 'at' p",other:"P"};function Bi(e){return(t,a)=>{let i;if("formatting"===(a?.context?String(a.context):"standalone")&&e.formattingValues){const t=e.defaultFormattingWidth||e.defaultWidth,s=a?.width?String(a.width):t;i=e.formattingValues[s]||e.formattingValues[t]}else{const t=e.defaultWidth,s=a?.width?String(a.width):e.defaultWidth;i=e.values[s]||e.values[t]}return i[e.argumentCallback?e.argumentCallback(t):t]}}function Wi(e){return(t,a={})=>{const i=a.width,s=i&&e.matchPatterns[i]||e.matchPatterns[e.defaultMatchWidth],n=t.match(s);if(!n)return null;const r=n[0],o=i&&e.parsePatterns[i]||e.parsePatterns[e.defaultParseWidth],l=Array.isArray(o)?function(e,t){for(let a=0;a<e.length;a++)if(t(e[a]))return a}(o,e=>e.test(r)):function(e,t){for(const a in e)if(Object.prototype.hasOwnProperty.call(e,a)&&t(e[a]))return a}(o,e=>e.test(r));let d;return d=e.valueCallback?e.valueCallback(l):l,d=a.valueCallback?a.valueCallback(d):d,{value:d,rest:t.slice(r.length)}}}var Vi;const qi={code:"en-US",formatDistance:(e,t,a)=>{let i;const s=Oi[e];return i="string"==typeof s?s:1===t?s.one:s.other.replace("{{count}}",t.toString()),a?.addSuffix?a.comparison&&a.comparison>0?"in "+i:i+" ago":i},formatLong:Li,formatRelative:(e,t,a,i)=>$i[e],localize:{ordinalNumber:(e,t)=>{const a=Number(e),i=a%100;if(i>20||i<10)switch(i%10){case 1:return a+"st";case 2:return a+"nd";case 3:return a+"rd"}return a+"th"},era:Bi({values:{narrow:["B","A"],abbreviated:["BC","AD"],wide:["Before Christ","Anno Domini"]},defaultWidth:"wide"}),quarter:Bi({values:{narrow:["1","2","3","4"],abbreviated:["Q1","Q2","Q3","Q4"],wide:["1st quarter","2nd quarter","3rd quarter","4th quarter"]},defaultWidth:"wide",argumentCallback:e=>e-1}),month:Bi({values:{narrow:["J","F","M","A","M","J","J","A","S","O","N","D"],abbreviated:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],wide:["January","February","March","April","May","June","July","August","September","October","November","December"]},defaultWidth:"wide"}),day:Bi({values:{narrow:["S","M","T","W","T","F","S"],short:["Su","Mo","Tu","We","Th","Fr","Sa"],abbreviated:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],wide:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},defaultWidth:"wide"}),dayPeriod:Bi({values:{narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"}},defaultWidth:"wide",formattingValues:{narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"}},defaultFormattingWidth:"wide"})},match:{ordinalNumber:(Vi={matchPattern:/^(\d+)(th|st|nd|rd)?/i,parsePattern:/\d+/i,valueCallback:e=>parseInt(e,10)},(e,t={})=>{const a=e.match(Vi.matchPattern);if(!a)return null;const i=a[0],s=e.match(Vi.parsePattern);if(!s)return null;let n=Vi.valueCallback?Vi.valueCallback(s[0]):s[0];return n=t.valueCallback?t.valueCallback(n):n,{value:n,rest:e.slice(i.length)}}),era:Wi({matchPatterns:{narrow:/^(b|a)/i,abbreviated:/^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,wide:/^(before christ|before common era|anno domini|common era)/i},defaultMatchWidth:"wide",parsePatterns:{any:[/^b/i,/^(a|c)/i]},defaultParseWidth:"any"}),quarter:Wi({matchPatterns:{narrow:/^[1234]/i,abbreviated:/^q[1234]/i,wide:/^[1234](th|st|nd|rd)? quarter/i},defaultMatchWidth:"wide",parsePatterns:{any:[/1/i,/2/i,/3/i,/4/i]},defaultParseWidth:"any",valueCallback:e=>e+1}),month:Wi({matchPatterns:{narrow:/^[jfmasond]/i,abbreviated:/^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,wide:/^(january|february|march|april|may|june|july|august|september|october|november|december)/i},defaultMatchWidth:"wide",parsePatterns:{narrow:[/^j/i,/^f/i,/^m/i,/^a/i,/^m/i,/^j/i,/^j/i,/^a/i,/^s/i,/^o/i,/^n/i,/^d/i],any:[/^ja/i,/^f/i,/^mar/i,/^ap/i,/^may/i,/^jun/i,/^jul/i,/^au/i,/^s/i,/^o/i,/^n/i,/^d/i]},defaultParseWidth:"any"}),day:Wi({matchPatterns:{narrow:/^[smtwf]/i,short:/^(su|mo|tu|we|th|fr|sa)/i,abbreviated:/^(sun|mon|tue|wed|thu|fri|sat)/i,wide:/^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i},defaultMatchWidth:"wide",parsePatterns:{narrow:[/^s/i,/^m/i,/^t/i,/^w/i,/^t/i,/^f/i,/^s/i],any:[/^su/i,/^m/i,/^tu/i,/^w/i,/^th/i,/^f/i,/^sa/i]},defaultParseWidth:"any"}),dayPeriod:Wi({matchPatterns:{narrow:/^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,any:/^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i},defaultMatchWidth:"any",parsePatterns:{any:{am:/^a/i,pm:/^p/i,midnight:/^mi/i,noon:/^no/i,morning:/morning/i,afternoon:/afternoon/i,evening:/evening/i,night:/night/i}},defaultParseWidth:"any"})},options:{weekStartsOn:0,firstWeekContainsDate:1}},zi=qi;var Hi=a(34168);function Gi(e){return(t,a)=>{let i;if("formatting"===(a?.context?String(a.context):"standalone")&&e.formattingValues){const t=e.defaultFormattingWidth||e.defaultWidth,s=a?.width?String(a.width):t;i=e.formattingValues[s]||e.formattingValues[t]}else{const t=e.defaultWidth,s=a?.width?String(a.width):e.defaultWidth;i=e.values[s]||e.values[t]}return i[e.argumentCallback?e.argumentCallback(t):t]}}const Yi={abbreviated:[(0,p.__)("Jan","mailpoet"),(0,p.__)("Feb","mailpoet"),(0,p.__)("Mar","mailpoet"),(0,p.__)("Apr","mailpoet"),(0,p.__)("May","mailpoet"),(0,p.__)("Jun","mailpoet"),(0,p.__)("Jul","mailpoet"),(0,p.__)("Aug","mailpoet"),(0,p.__)("Sep","mailpoet"),(0,p.__)("Oct","mailpoet"),(0,p.__)("Nov","mailpoet"),(0,p.__)("Dec","mailpoet")],wide:[(0,p.__)("January","mailpoet"),(0,p.__)("February","mailpoet"),(0,p.__)("March","mailpoet"),(0,p.__)("April","mailpoet"),(0,p.__)("May","mailpoet"),(0,p.__)("June","mailpoet"),(0,p.__)("July","mailpoet"),(0,p.__)("August","mailpoet"),(0,p.__)("September","mailpoet"),(0,p.__)("October","mailpoet"),(0,p.__)("November","mailpoet"),(0,p.__)("December","mailpoet")]},Ki={narrow:[(0,p._x)("S","Sunday - one letter abbreviation","mailpoet"),(0,p._x)("M","Monday - one letter abbreviation","mailpoet"),(0,p._x)("T","Tuesday - one letter abbreviation","mailpoet"),(0,p._x)("W","Wednesday - one letter abbreviation","mailpoet"),(0,p._x)("T","Thursday - one letter abbreviation","mailpoet"),(0,p._x)("F","Friday - one letter abbreviation","mailpoet"),(0,p._x)("S","Saturday - one letter abbreviation","mailpoet")],abbreviated:[(0,p.__)("Sun","mailpoet"),(0,p.__)("Mon","mailpoet"),(0,p.__)("Tue","mailpoet"),(0,p.__)("Wed","mailpoet"),(0,p.__)("Thu","mailpoet"),(0,p.__)("Fri","mailpoet"),(0,p.__)("Sat","mailpoet")],wide:[(0,p.__)("Sunday","mailpoet"),(0,p.__)("Monday","mailpoet"),(0,p.__)("Tuesday","mailpoet"),(0,p.__)("Wednesday","mailpoet"),(0,p.__)("Thursday","mailpoet"),(0,p.__)("Friday","mailpoet"),(0,p.__)("Saturday","mailpoet")]};zi.localize.month=Gi({values:Yi,defaultWidth:"wide"}),zi.localize.day=Gi({values:Ki,defaultWidth:"wide"}),zi.options.weekStartsOn=void 0!==m.U.wpWeekStartsOn?m.U.wpWeekStartsOn:1,(0,Fi.registerLocale)("mailpoet",zi);class Zi extends r.Component{onChange=(e,t)=>{const a=t,i=this.getAsStringInFormat(e);a.target.name=this.getFieldName(),a.target.value=i,this.props.onChange(a)};getFieldName=()=>this.props.name||"date";getDisplayDateFormat=e=>m.U.Date.convertFormat(e).replace(/D/g,"d").replace(/Y/g,"y").replace(/A/g,"a").replace(/o/g,"Y").replace(/\[/g,"").replace(/\]/g,"");getDate=e=>Et()(e).toDate();getAsStringInFormat=e=>Et()(e).format(m.U.Date.convertFormat(this.props.storageFormat));render(){return(0,g.jsx)(Hi.t,{name:this.getFieldName(),selected:this.getDate(this.props.value),dateFormat:this.getDisplayDateFormat(this.props.displayFormat),disabled:this.props.disabled,onChange:this.onChange,minDate:this.getDate(window.mailpoet_current_date),maxDate:this.props.maxDate,locale:"mailpoet",...this.props.validation})}}class Ji extends r.Component{render(){const{onChange:e,timeOfDayItems:t,value:a,disabled:i=!1,name:s="time",validation:n={}}=this.props,r=Object.keys(t).map(e=>(0,g.jsx)("option",{value:e,children:t[e]},`option-${t[e]}`)),o=Object.keys(t),l=a&&!o.includes(a),d=a.lastIndexOf(":"),c=d>0?a.slice(0,d):a,m=l?(0,g.jsx)("option",{value:a,children:c}):null;return(0,g.jsxs)(Be.Select,{name:s||"time",value:a,disabled:i,onChange:e,isMinWidth:!0,...n,children:[m,r]})}}Ji.propTypes={timeOfDayItems:Rt().objectOf(Rt().string).isRequired,name:Rt().string,value:Rt().string.isRequired,disabled:Rt().bool,onChange:Rt().func.isRequired,validation:Rt().object},Ji.displayName="TimeSelect";class Qi extends r.Component{DATE_TIME_SEPARATOR=" ";constructor(e){super(e),this.state=this.buildStateFromProps(e)}componentDidUpdate(e){this.props.value===e.value&&this.props.defaultDateTime===e.defaultDateTime||At()(()=>{this.setState(this.buildStateFromProps(this.props))})}getDateTime=()=>{const e=[this.state.date,this.state.time].join(this.DATE_TIME_SEPARATOR);return m.U.Date.toGmtDatetimeString(e)};buildStateFromProps=e=>{const t=e.value||this.props.defaultDateTime,a=m.U.Date.datetimeString(t),[i,s]=a.split(this.DATE_TIME_SEPARATOR);return{date:i,time:s}};handleChange=e=>{const t={};t[e.target.name]=e.target.value,this.setState(t,this.propagateChange)};propagateChange=()=>{this.props.onChange&&this.props.onChange({target:{name:this.props.name||"",value:this.getDateTime()}})};render(){return(0,g.jsx)(Di.Grid.Column,{className:"mailpoet-datetime-container",children:(0,g.jsxs)(o.ErrorBoundary,{children:[(0,g.jsx)(Zi,{name:"date",value:this.state.date,onChange:this.handleChange,displayFormat:this.props.dateDisplayFormat,storageFormat:this.props.dateStorageFormat,disabled:this.props.disabled,validation:this.props.dateValidation,maxDate:this.props.maxDate}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)(Ji,{name:"time",value:this.state.time,onChange:this.handleChange,disabled:this.props.disabled,timeOfDayItems:this.props.timeOfDayItems})]})})}}var Xi=a(35383),es=a(81294),ts=a(57382);class as extends r.Component{constructor(e){super(e);const t=(0,ts.Y8)(e.item.sender_address);this.state={emailAddress:e.item.sender_address,showSenderDomainWarning:!window.mailpoet_sender_restrictions?.skipAuthorization&&!window.mailpoet_verified_sender_domains.includes(t),isPartiallyVerifiedDomain:window.mailpoet_partially_verified_sender_domains.includes(t),showAuthEmailsError:!1},this.onChange=this.onChange.bind(this),this.onBlur=this.onBlur.bind(this),window.mailpoet_sender_address_field_blur=this.onBlur;const a=e.field.id||`field_${e.field.name}`;this.domElementSelector=`#${a}`,this.parsleyFieldName="invalidFromAddress"}componentDidMount(){this.validateEmailAddress()}onChange(e){const{onValueChange:t=()=>{}}=this.props,a=e.target.value.toLowerCase();this.setState({emailAddress:a}),t({...e,target:{...e.target,name:e.target.name,value:a}}),this.setState({showAuthEmailsError:!1,showSenderDomainWarning:!1}),(0,es.SB)(this.domElementSelector,this.parsleyFieldName)}onBlur(){this.validateEmailAddress()}isEmailAddressAuthorized=e=>(window.mailpoet_authorized_emails||[]).includes(e);showInvalidFromAddressError=()=>{(0,es.oI)(this.domElementSelector,this.parsleyFieldName," "),this.setState({showAuthEmailsError:!0})};showSenderFieldError=(e,t)=>{window.mailpoet_mss_active&&((0,es.SB)(this.domElementSelector,this.parsleyFieldName),(0,es.vg)(this.domElementSelector)?e?this.showSenderDomainError(!0):this.showInvalidFromAddressError(t):(0,es.jr)(this.domElementSelector))};showSenderDomainError=e=>{e&&this.setState({showSenderDomainWarning:!0})};validateEmailAddress(){if(!window.mailpoet_mss_active)return;if(window.mailpoet_sender_restrictions?.skipAuthorization)return;const e=this.state.emailAddress,t=(0,ts.Y8)(e);if(window.mailpoet_verified_sender_domains.includes(t))return;const a=this.isEmailAddressAuthorized(e);this.showSenderFieldError(a,e),this.setState({isPartiallyVerifiedDomain:window.mailpoet_partially_verified_sender_domains.includes(t)})}render(){return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(Ft,{item:{...this.props.item,sender_address:this.state.emailAddress},field:this.props.field,onValueChange:this.onChange,onBlurEvent:this.onBlur}),(0,g.jsx)("div",{className:"regular-text regular-text-full-width",children:(0,g.jsx)(Xi.Y,{emailAddress:this.state.emailAddress,mssActive:window.mailpoet_mss_active,isEmailAuthorized:!this.state.showAuthEmailsError,showSenderDomainWarning:this.state.showSenderDomainWarning&&!this.state.showAuthEmailsError,isPartiallyVerifiedDomain:this.state.isPartiallyVerifiedDomain,senderRestrictions:window.mailpoet_sender_restrictions,onSuccessfulEmailOrDomainAuthorization:e=>{"email"===e.type&&(this.setState({showAuthEmailsError:!1}),m.U.trackEvent("MSS in plugin authorize email",{"authorized email source":"newsletter",wasSuccessful:"yes"})),"domain"===e.type&&(this.setState({showSenderDomainWarning:!1}),this.setState({isPartiallyVerifiedDomain:!1}),m.U.trackEvent("MSS in plugin verify sender domain",{"verify sender domain source":"newsletter",wasSuccessful:"yes"})),(0,es.SB)(this.domElementSelector,this.parsleyFieldName)}})})]})}}as.propTypes={field:Rt().object.isRequired,item:Rt().shape({sender_address:Rt().string.isRequired}).isRequired,onValueChange:Rt().func},as.displayName="SenderField";const is=Lt.default.once(()=>m.U.trackEvent("User has typed a GA campaign name")),ss=b()((0,p.__)("For example, “Spring email”. [link]Read the guide.[/link]","mailpoet"),/\[link\](.*?)\[\/link\]/g,(e,t)=>(0,g.jsxs)("span",{children:[(0,g.jsx)("br",{}),(0,g.jsx)("a",{href:"https://kb.mailpoet.com/article/187-track-newsletters-subscribers-in-google-analytics",target:"_blank",rel:"noopener noreferrer",className:"mailpoet-link",children:e})]},t)),ns={name:"ga_campaign",label:(0,p.__)("Google Analytics Campaign","mailpoet"),tip:ss,type:"text",onBeforeChange:is};var rs=a(76091),os=a(91494);const ls="website_time",ds="subscriber_timezone",cs="08:00:00";function ms(e){return e===ds?ds:ls}function us(e,t,a){return e===ds?{scheduleMode:ds,scheduledLocalDate:t.scheduledLocalDate||a,scheduledLocalTime:t.scheduledLocalTime||cs}:{scheduleMode:ls,scheduledLocalDate:"",scheduledLocalTime:""}}var ps=a(50117),hs=a(55985),gs=a(97337),_s=a(66880);const fs={saveDraftNewsletter:()=>Promise.resolve()},bs=r.createContext(fs);var xs=a(58270);function vs(e,t){return`segments:${e.join(",")}|filterSegmentId:${t}`}const ys=[{name:"segments",label:(0,p.__)("Send to","mailpoet"),type:"selection",placeholder:(0,p.__)("Choose","mailpoet"),id:"mailpoet_segments",api_version:window.mailpoet_api_version,endpoint:"segments",multiple:!0,filter:function(e){return!e?.deleted_at},getLabel:function(e){return e.name},getCount:function(e){return parseInt(e.subscribers,10).toLocaleString()},transformChangedValue:function(e){const t=this.getItems()||[];return e.map(e=>t.find(t=>t.id===e))},validation:{"data-parsley-required":!0,"data-parsley-required-message":(0,p.__)("Please select a list","mailpoet"),"data-parsley-segments-with-subscribers":(0,p.__)("Please select a list with subscribers.","mailpoet")}},{name:"filter-segment-toggle",type:"reactComponent",component:(0,o.withBoundary)(function({item:e,onValueChange:t,field:a}){const i=e?.options.filterSegmentId,[s,n]=(0,r.useState)(ps.d&&!!i),l=(0,r.useCallback)(a=>{t({target:{name:"options",value:{...e?.options??{},filterSegmentId:a}}})},[e,t]),d=(0,r.useContext)(bs);(0,r.useEffect)(()=>{ps.d||""===i||l("")},[l,i]);const c=(0,r.useCallback)(i=>{t({target:{name:a.name,value:i}}),i||l(""),n(i),m.U.trackEvent("Emails > Filter by segment toggled",{"Email type":e.type})},[a,t,l,e]);let u;if(s){const t={name:"filter-segment",type:"selection",placeholder:(0,p.__)("Choose","mailpoet"),id:"mailpoetFilterSegment",api_version:window.mailpoet_api_version,endpoint:"segments",multiple:!1,forceSelect2:!0,selected:e=>e.options.filterSegmentId,filter:function(e){return!e.deleted_at&&"dynamic"===e.type},getLabel:function(e){return e.name},getCount:function(e){return parseInt(e.subscribers,10).toLocaleString()},validation:{"data-parsley-required":!0,"data-parsley-required-message":(0,p.__)("Please select a filter segment","mailpoet")}};u=(0,g.jsx)(Ve.L,{item:e,field:t,onValueChange:t=>{l(t.target.value),m.U.trackEvent("Emails > Filter by segment selected",{"Email type":e.type})}})}const h=`admin.php?page=mailpoet-segments#/new-segment?newsletterId=${e.id}`;return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(o.Toggle,{checked:s,disabled:a.disabled,name:"isFilterSegmentEnabled",onCheck:c,automationId:"filter-segment-toggle"}),(0,g.jsxs)("span",{className:"mailpoet-form-toggle-text",children:[(0,p.__)("Filter by segment","mailpoet"),(0,g.jsx)(mi.A,{"data-tip":!0,"data-tooltip-id":"filter-segment-tooltip",className:"filter-segment-tooltip",icon:_s.A})]}),(0,g.jsx)(gs.m,{place:"right",id:"filter-segment-tooltip",children:(0,g.jsx)("div",{children:(0,p.__)("Subscribers selected in 'Send to' will only receive an email if they also belong to this segment.","mailpoet")})}),(0,g.jsx)("div",{className:"mailpoet-gap"}),u,s&&(0,g.jsx)("p",{children:b()((0,p.__)("Can't find the segment you're looking for? [link]Create new[/link]","mailpoet"),/\[link\](.*?)\[\/link\]/g,(t,a)=>(0,g.jsx)("a",{className:"mailpoet-link",rel:"noopener noreferrer",onClick:async t=>{t.preventDefault(),m.U.trackEvent("Emails > Create new segment clicked",{"Email type":e.type}),await d.saveDraftNewsletter(),window.location.href=h},href:h,children:t},a))})]})})}],ws={name:"recipient-count",type:"reactComponent",component:(0,o.withBoundary)(function(e){const[t,a]=(0,r.useState)(!0),[i,s]=(0,r.useState)(0),n=(0,r.useMemo)(()=>(e.item.segments||[]).map(e=>e.id),[e.item.segments]),o=(0,r.useMemo)(()=>e.item.options?.filterSegmentId||null,[e.item.options?.filterSegmentId]),l=(0,r.useRef)(""),d=(0,r.useRef)({});return(0,r.useEffect)(()=>{const e=vs(n,o);return l.current=e,n.length<1?(s(0),void a(!1)):e in d.current?(s(d.current[e]),void a(!1)):(a(!0),void m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"segments",action:"subscriberCount",data:{segmentIds:n,filterSegmentId:o}}).done(t=>{const a=t.data.count;d.current[e]=a;const i=vs(n,o);l.current===i&&s(a)}).always(()=>a(!1)))},[n,o]),(0,g.jsxs)("div",{children:[(0,p.__)("Estimated recipients","mailpoet"),":",t&&(0,g.jsx)(xs.Ay,{className:"mailpoet-recipient-count-spinner"}),!t&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(gs.m,{place:"right",id:"estimated-count-tooltip",children:(0,p.__)("This count may change at the time of sending.","mailpoet")}),(0,g.jsx)("span",{"data-tip":!0,"data-tooltip-id":"estimated-count-tooltip",className:"estimated-recipient-count",children:i.toLocaleString()})]})]})})},js={name:"send-to",label:(0,p.__)("Send to","mailpoet"),tip:(0,p.__)("Subscribers in multiple lists will only receive one email.","mailpoet"),fields:ys},Ss={name:"send-to",label:(0,p.__)("Send to","mailpoet"),tip:(0,p.__)("Subscribers in multiple lists will only receive one email.","mailpoet"),fields:[...ys,ws]},ks=`${window.mailpoet_tomorrow_date} 08:00:00`,Ns=m.U.Date.toGmtDatetimeString(ks),Cs=window.mailpoet_schedule_time_of_day,Es=window.mailpoet_date_format,Is=window.mailpoet_date_storage_format;class As extends r.Component{constructor(e){super(e),this.state={showPremiumModal:!1}}getCurrentValue=()=>({isScheduled:"0",scheduledAt:Ns,...this.props.item?.[this.props.field.name]??{}});getDateValidation=()=>({"data-parsley-required":!0,"data-parsley-required-message":(0,p.__)("Please enter the scheduled date.","mailpoet"),"data-parsley-errors-container":"#mailpoet_scheduling"});isScheduled=()=>"1"===this.getCurrentValue().isScheduled;isTimezoneSchedulingAvailable=()=>m.U.FeaturesController.isSupported(m.U.FeaturesController.FEATURE_SEND_BY_TIMEZONE);isSubscriberTimezoneRestricted=()=>!m.U.capabilities?.sendByTimezone||m.U.capabilities.sendByTimezone.isRestricted;handleScheduleModeChange=e=>{if(e===ds&&this.isSubscriberTimezoneRestricted())return void this.setState({showPremiumModal:!0});const t=this.getCurrentValue();this.props.onValueChange({target:{name:this.props.field.name,value:{...t,...us(e,t,window.mailpoet_tomorrow_date)}}})};handleCheckboxChange=(e,t)=>{const a={...t};a.target.value=t.target.checked?"1":"0",this.handleValueChange(a)};handleValueChange=e=>{const t=this.getCurrentValue(),a={};a[e.target.name]=e.target.value,this.props.onValueChange({target:{name:this.props.field.name,value:{...t,...a}}})};renderScheduleModeSelector=e=>(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)("div",{className:"mailpoet-settings-inputs-row",children:[(0,g.jsx)(Bt.s,{id:"mailpoet-schedule-mode-website-time",value:ls,checked:!e,onCheck:()=>this.handleScheduleModeChange(ls),disabled:this.props.field.disabled,name:"scheduleMode",automationId:"email-schedule-mode-website-time"}),(0,g.jsx)("label",{htmlFor:"mailpoet-schedule-mode-website-time",children:(0,p.__)("Website time","mailpoet")})]}),(0,g.jsxs)("div",{className:"mailpoet-settings-inputs-row",children:[(0,g.jsx)(Bt.s,{id:"mailpoet-schedule-mode-subscriber-timezone",value:ds,checked:e,onCheck:()=>this.handleScheduleModeChange(ds),disabled:this.props.field.disabled,name:"scheduleMode",automationId:"email-schedule-mode-subscriber-timezone"}),(0,g.jsxs)("label",{htmlFor:"mailpoet-schedule-mode-subscriber-timezone",children:[(0,p.__)("Subscriber’s time zone","mailpoet")," ",this.isSubscriberTimezoneRestricted()&&(0,g.jsx)(hs.S,{text:(0,p.__)("Premium","mailpoet")})]})]}),(0,g.jsx)("div",{className:"mailpoet-gap"})]});renderSubscriberTimezoneScheduling=()=>{const e=this.getCurrentValue(),t=new Date;return t.setFullYear(t.getFullYear()+5),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("div",{children:(0,p.sprintf)((0,p.__)("Emails will arrive at the selected time in each subscriber’s time zone — or your website’s time zone if unknown. Schedule at least %d hours ahead.","mailpoet"),24)}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)("div",{id:"mailpoet_scheduling",children:(0,g.jsxs)(Di.Grid.Column,{className:"mailpoet-datetime-container",children:[(0,g.jsx)(Zi,{name:"scheduledLocalDate",value:e.scheduledLocalDate||window.mailpoet_tomorrow_date,onChange:this.handleValueChange,displayFormat:Es,storageFormat:Is,disabled:this.props.field.disabled,validation:this.getDateValidation(),maxDate:t}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)(Ji,{name:"scheduledLocalTime",value:e.scheduledLocalTime||cs,onChange:this.handleValueChange,disabled:this.props.field.disabled,timeOfDayItems:Cs})]})})]})};renderWebsiteTimeScheduling=()=>{const e=new Date;return e.setFullYear(e.getFullYear()+5),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)("div",{children:[(0,p.__)("Your website’s time is","mailpoet")," ",m.U.Date.time(new Date)]}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)("div",{id:"mailpoet_scheduling",children:(0,g.jsx)(Qi,{name:"scheduledAt",value:this.getCurrentValue().scheduledAt,onChange:this.handleValueChange,disabled:this.props.field.disabled,dateValidation:this.getDateValidation(),defaultDateTime:Ns,timeOfDayItems:Cs,dateDisplayFormat:Es,dateStorageFormat:Is,maxDate:e})})]})};render(){let e;if(this.isScheduled()){const t=this.isTimezoneSchedulingAvailable()&&ms(this.getCurrentValue().scheduleMode)===ds;e=(0,g.jsxs)(g.Fragment,{children:[this.isTimezoneSchedulingAvailable()&&this.renderScheduleModeSelector(t),t?this.renderSubscriberTimezoneScheduling():this.renderWebsiteTimeScheduling()]})}return(0,g.jsxs)("div",{children:[(0,g.jsx)(rs.l,{checked:this.isScheduled(),disabled:this.props.field.disabled,name:"isScheduled",onCheck:this.handleCheckboxChange,automationId:"email-schedule-checkbox"}),e,this.state.showPremiumModal&&(0,g.jsx)(ps.D,{onRequestClose:()=>this.setState({showPremiumModal:!1}),data:{capabilities:{sendByTimezone:!0}},tracking:{utm_medium:"upsell_modal",utm_campaign:"send_by_timezone"},children:(0,p.__)("Sending emails in each subscriber’s time zone is a premium feature.","mailpoet")})]})}}function Us({item:e,field:t,onValueChange:a}){const i=e?.options??{},s=i.shareVisibility,n="public"===s||"private"===s?s:e?.effective_share_visibility||"private",o=e=>{a({target:{name:t.name,value:{...i,shareVisibility:e}}})};return(0,r.useEffect)(()=>{s||a({target:{name:t.name,value:{...i,shareVisibility:n}}})},[]),(0,g.jsxs)("div",{children:[(0,g.jsx)("p",{className:"mailpoet-form-description",children:(0,p.__)("Choose whether this email can be opened from a public share link after it is sent.","mailpoet")}),(0,g.jsxs)("div",{className:"mailpoet-settings-inputs-row",children:[(0,g.jsx)(Bt.s,{id:"mailpoet-share-visibility-public",value:"public",checked:"public"===n,onCheck:o,name:"shareVisibility"}),(0,g.jsx)("label",{htmlFor:"mailpoet-share-visibility-public",children:(0,p.__)("Public","mailpoet")})]}),(0,g.jsxs)("div",{className:"mailpoet-settings-inputs-row",children:[(0,g.jsx)(Bt.s,{id:"mailpoet-share-visibility-private",value:"private",checked:"private"===n,onCheck:o,name:"shareVisibility"}),(0,g.jsx)("label",{htmlFor:"mailpoet-share-visibility-private",children:(0,p.__)("Private","mailpoet")})]})]})}let Ts=[{name:"email-header",label:null,tip:null,fields:[{name:"subject",customLabel:(0,p.__)("Subject","mailpoet"),className:"mailpoet-form-field-subject",placeholder:(0,p.__)("Type newsletter subject","mailpoet"),tooltip:(0,p.__)("Be creative! It's the first thing that your subscribers see. Tempt them to open your email.","mailpoet"),type:"text",validation:{"data-parsley-required":!0,"data-parsley-required-message":(0,p.__)("Please specify a subject","mailpoet"),maxLength:250}},{name:"preheader",customLabel:(0,p.__)("Preview text","mailpoet"),className:"mailpoet-form-field-preheader",placeholder:(0,p.__)("Type preview text (usually displayed underneath the subject line in the inbox)","mailpoet"),tooltip:`${(0,p.__)("This optional text will appear in your subscribers' inboxes, beside the subject line. Write something enticing!","mailpoet")} ${(0,p.__)("Max length is 250 characters, however, we recommend 80 characters on a single line.","mailpoet")}`,type:"textarea",validation:{maxLength:250}}]},Ss,{name:"options",label:(0,p.__)("Schedule it","mailpoet"),type:"reactComponent",component:(0,o.withBoundary)(function(e){return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(As,{...e}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)("h4",{className:"mailpoet-h4",children:(0,p.__)("Sharing visibility","mailpoet")}),(0,g.jsx)(Us,{...e})]})})},{name:"archive-visibility",label:(0,p.__)("Archive","mailpoet"),type:"reactComponent",component:(0,o.withBoundary)(function({item:e,onValueChange:t,field:a}){const i=e?.options??{},s="mailpoet-archive-visibility-help",n=(0,p.__)("Show this newsletter in the archive","mailpoet");return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(rs.l,{checked:(r=i.excludeFromArchive,"1"!==r&&!0!==r),disabled:a.disabled,name:"excludeFromArchive",onCheck:e=>{var a;t({target:{name:"options",value:{...i,excludeFromArchive:(a=e,a?"0":"1")}}})},automationId:"archive-visibility-toggle","aria-label":n,"aria-describedby":s}),(0,g.jsx)("span",{className:"mailpoet-form-toggle-text",children:n}),(0,g.jsx)("p",{id:s,className:"mailpoet-form-field-description",children:(0,p.__)("Shown on pages using the MailPoet archive shortcode.","mailpoet")})]});var r})},{name:"sender",label:(0,p.__)("Sender","mailpoet"),tip:(0,p.__)("Your name and email","mailpoet"),fields:[{name:"sender_name",type:"text",placeholder:(0,p.__)("John Doe","mailpoet"),validation:{"data-parsley-required":!0}},{name:"sender_address",type:"reactComponent",component:(0,o.withBoundary)(as),placeholder:(0,p.__)("john.doe@email.com","mailpoet"),validation:{"data-parsley-required":!0,"data-parsley-type":"email"}}]},ns,{name:"reply-to",label:(0,p.__)("Reply-to","mailpoet"),tip:(0,p.__)("When your subscribers reply to your emails, their emails will go to this address.","mailpoet"),inline:!0,fields:[{name:"reply_to_name",type:"text",placeholder:(0,p.__)("John Doe","mailpoet")},{name:"reply_to_address",type:"text",placeholder:(0,p.__)("john.doe@email.com","mailpoet"),validation:{"data-parsley-type":"email"}}]}];Ts=Ta.Hooks.applyFilters("mailpoet_newsletters_3rd_step_fields",Ts);const Ps={getFields:()=>Ts,getSendButtonOptions:(e={})=>{const t=m.U.FeaturesController.isSupported(m.U.FeaturesController.FEATURE_SEND_BY_TIMEZONE)&&ms(e.options?.scheduleMode)===ds,a={value:"object"==typeof e.options&&"1"===e.options?.isScheduled&&(t||m.U.Date.isInFuture(e.options?.scheduledAt,new Date))?(0,p.__)("Schedule","mailpoet"):(0,p.__)("Send","mailpoet")};return e.status!==os.um.Sent&&e.status!==os.um.Sending||(a.disabled="disabled"),a}},Rs=window.mailpoet_time_format||"H:i",Ds={immediate:(0,p.__)("immediately","mailpoet"),minutes:(0,p.__)("minute(s) later","mailpoet"),hours:(0,p.__)("hour(s) later","mailpoet"),days:(0,p.__)("day(s) later","mailpoet"),weeks:(0,p.__)("week(s) later","mailpoet")},Fs={daily:(0,p.__)("Once a day at...","mailpoet"),weekly:(0,p.__)("Weekly on...","mailpoet"),monthly:(0,p.__)("Monthly on the...","mailpoet"),nthWeekDay:(0,p.__)("Monthly every...","mailpoet"),immediately:(0,p.__)("Immediately","mailpoet")},Os=Lt.default.object(Lt.default.map(Lt.default.times(96,e=>900*e),e=>{const t=new Date(null);return t.setSeconds(e),[e,m.U.Date.format(t,{format:Rs,offset:0})]})),Ms={0:(0,p.__)("Sunday","mailpoet"),1:(0,p.__)("Monday","mailpoet"),2:(0,p.__)("Tuesday","mailpoet"),3:(0,p.__)("Wednesday","mailpoet"),4:(0,p.__)("Thursday","mailpoet"),5:(0,p.__)("Friday","mailpoet"),6:(0,p.__)("Saturday","mailpoet")},Ls=Lt.default.object(Lt.default.map(Lt.default.times(28,e=>e),e=>{const t={0:(0,p.__)("1st","mailpoet"),1:(0,p.__)("2nd","mailpoet"),2:(0,p.__)("3rd","mailpoet")};let a;return a=void 0!==t[e]?t[e]:(0,p.__)("%1$dth","mailpoet").replace("%1$d",e+1),[e+1,a]})),$s={1:(0,p.__)("1st","mailpoet"),2:(0,p.__)("2nd","mailpoet"),3:(0,p.__)("3rd","mailpoet"),4:(0,p.__)("4th","mailpoet"),L:(0,p._x)("last","e.g. monthly every last Monday","mailpoet")},Bs="1",Ws=["0","1","2","3","4","5","6"],Vs=e=>[...e].sort((e,t)=>Number(e)-Number(t)),qs=e=>null==e?"":String(e).trim(),zs=e=>{const t=qs(e);return Ws.includes(t)?t:Bs},Hs=e=>{const t=zs(e),a=Ws.indexOf(t);return[...Ws.slice(a),...Ws.slice(0,a)]},Gs=(e,t,a)=>{const i=Object.keys(a),s=qs(e).split(",").map(e=>e.trim()).filter(e=>i.includes(e));return 0===s.length?[t]:Vs([...new Set(s)])},Ys=e=>Vs(e).join(","),Ks=(e,t,a,i=Vs(Object.keys(t)))=>((e,t)=>[...e].sort((e,a)=>{const i=t.indexOf(e),s=t.indexOf(a);return-1===i||-1===s?Number(e)-Number(a):i-s}))(Gs(e,a,t),i).map(e=>t[e]).join(", "),Zs={name:"intervalType",values:Fs},Js={name:"timeOfDay",values:Os},Qs={name:"weekDay",values:Ms},Xs={name:"nthWeekDay",values:$s},en=e=>4===e?"mailpoet-grid-four-columns":"mailpoet-grid-three-columns";function tn({name:e,values:t,selectedValues:a,onValueChange:i,automationId:s,columns:n,valueOrder:r}){const o=a.map(e=>`${e}`),l=r||Object.keys(t);return(0,g.jsx)("div",{className:en(n),children:l.map(a=>(0,g.jsx)("span",{children:(0,g.jsx)(Vt.S,{name:e,value:a,checked:o.includes(a),onCheck:e=>{let t=o;e?t=[...o,a]:o.length>1&&(t=o.filter(e=>e!==a)),i(Ys(t))},automationId:`${s}_${a}`,children:t[a]})},`${e}-${a}`))})}tn.propTypes={name:Rt().string.isRequired,values:Rt().objectOf(Rt().string).isRequired,selectedValues:Rt().arrayOf(Rt().string).isRequired,onValueChange:Rt().func.isRequired,automationId:Rt().string.isRequired,columns:Rt().oneOf([3,4]).isRequired,valueOrder:Rt().arrayOf(Rt().string)};class an extends r.Component{getCurrentValue=()=>this.props.item[this.props.field.name]||{};getDefaultWeekDay=()=>zs(m.U.wpWeekStartsOn);getOrderedWeekDayKeys=()=>Hs(m.U.wpWeekStartsOn);handleValueChanges=e=>{const t=this.getCurrentValue();return this.props.onValueChange({target:{name:this.props.field.name,value:Lt.default.extend({},t,e)}})};handleIntervalChange=e=>{const t=e.target.value,a=this.getCurrentValue(),i={};i.intervalType=t,"monthly"===t&&(i.monthDay=Ys(Gs(a.monthDay,Bs,Ls))),"weekly"===t&&(i.weekDay=Ys(Gs(a.weekDay,this.getDefaultWeekDay(),Ms))),"nthWeekDay"===t&&(i.weekDay=((e,t)=>Gs(e,t,Ms)[0])(a.weekDay,this.getDefaultWeekDay()),i.nthWeekDay=a.nthWeekDay||Bs),this.handleValueChanges(i)};handleTimeOfDayChange=e=>this.handleValueChanges({timeOfDay:e.target.value});handleWeekDayChange=e=>this.handleValueChanges({weekDay:e.target.value});handleWeekDaysChange=e=>this.handleValueChanges({weekDay:e});handleMonthDaysChange=e=>this.handleValueChanges({monthDay:e});handleNthWeekDayChange=e=>this.handleValueChanges({nthWeekDay:e.target.value});render(){const e=this.getCurrentValue(),t=this.getDefaultWeekDay(),a=this.getOrderedWeekDayKeys(),i={...Qs,sortBy:e=>a.indexOf(e)};let s,n,r,o;return"immediately"!==e.intervalType&&(n=(0,g.jsx)($t,{field:Js,item:this.getCurrentValue(),onValueChange:this.handleTimeOfDayChange})),"weekly"===e.intervalType&&(s=(0,g.jsx)(tn,{name:"weekDay",values:Ms,selectedValues:Gs(e.weekDay,t,Ms),onValueChange:this.handleWeekDaysChange,automationId:"newsletter_week_day",columns:3,valueOrder:a})),"nthWeekDay"===e.intervalType&&(r=(0,g.jsx)($t,{field:i,item:this.getCurrentValue(),onValueChange:this.handleWeekDayChange})),"monthly"===e.intervalType&&(s=(0,g.jsx)(tn,{name:"monthDay",values:Ls,selectedValues:Gs(e.monthDay,Bs,Ls),onValueChange:this.handleMonthDaysChange,automationId:"newsletter_month_day",columns:4})),"nthWeekDay"===e.intervalType&&(o=(0,g.jsx)($t,{field:Xs,item:this.getCurrentValue(),onValueChange:this.handleNthWeekDayChange})),(0,g.jsxs)("div",{children:[(0,g.jsxs)(Di.Grid.CenteredRow,{children:[(0,g.jsx)($t,{field:Zs,item:this.getCurrentValue(),onValueChange:this.handleIntervalChange,automationId:"newsletter_interval_type"}),"immediately"===e.intervalType&&(0,g.jsx)("div",{children:(0,g.jsx)("p",{children:(0,p.__)("after publishing a post","mailpoet")})})]}),(0,g.jsx)("div",{className:"mailpoet-gap"}),s&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("div",{className:"mailpoet-grid-column",children:s}),(0,g.jsx)("div",{className:"mailpoet-gap"})]}),(0,g.jsxs)("div",{className:"mailpoet-grid-column mailpoet-flex",children:[o,r,n]}),"immediately"!==e.intervalType&&(0,g.jsx)("div",{className:"mailpoet-gap"})]})}}an.propTypes={item:Rt().object.isRequired,field:Rt().shape({name:Rt().string}).isRequired,onValueChange:Rt().func.isRequired};let sn=[{name:"email-header",label:null,tip:null,fields:[{name:"subject",customLabel:(0,p.__)("Subject","mailpoet"),className:"mailpoet-form-field-subject",placeholder:(0,p.__)("Type newsletter subject","mailpoet"),tooltip:(0,p.__)("Be creative! It's the first thing that your subscribers see. Tempt them to open your email.","mailpoet"),type:"text",validation:{"data-parsley-required":!0,"data-parsley-required-message":(0,p.__)("Please specify a subject","mailpoet"),maxLength:250}},{name:"preheader",customLabel:(0,p.__)("Preview text","mailpoet"),className:"mailpoet-form-field-preheader",placeholder:(0,p.__)("Type preview text (usually displayed underneath the subject line in the inbox)","mailpoet"),tooltip:`${(0,p.__)("This optional text will appear in your subscribers' inboxes, beside the subject line. Write something enticing!","mailpoet")} ${(0,p.__)("Max length is 250 characters, however, we recommend 80 characters on a single line.","mailpoet")}`,type:"textarea",validation:{maxLength:250}}]},{name:"options",label:(0,p.__)("Select a frequency","mailpoet"),type:"reactComponent",component:an},Ss,{name:"sender",label:(0,p.__)("Sender","mailpoet"),tip:(0,p.__)("Your name and email","mailpoet"),fields:[{name:"sender_name",type:"text",placeholder:(0,p.__)("John Doe","mailpoet"),validation:{"data-parsley-required":!0}},{name:"sender_address",type:"reactComponent",component:(0,o.withBoundary)(as),placeholder:(0,p.__)("john.doe@email.com","mailpoet"),validation:{"data-parsley-required":!0,"data-parsley-type":"email"}}]},ns,{name:"reply-to",label:(0,p.__)("Reply-to","mailpoet"),tip:(0,p.__)("When your subscribers reply to your emails, their emails will go to this address.","mailpoet"),inline:!0,fields:[{name:"reply_to_name",type:"text",placeholder:(0,p.__)("John Doe","mailpoet")},{name:"reply_to_address",type:"text",placeholder:(0,p.__)("john.doe@email.com","mailpoet"),validation:{"data-parsley-type":"email"}}]}];sn=Ta.Hooks.applyFilters("mailpoet_newsletters_3rd_step_fields",sn);const nn={getFields:function(){return sn},getSendButtonOptions:function(){return{value:(0,p.__)("Activate","mailpoet")}}},rn=window.mailpoet_roles||{},on=Lt.default.filter(window.mailpoet_segments||[],e=>"default"===e.type),ln={name:"event",values:{segment:(0,p.__)("When someone subscribes to the list...","mailpoet"),user:(0,p.__)("When a new WordPress user is added to your site...","mailpoet")}},dn={name:"segment",placeholder:(0,p.__)("Select a list","mailpoet"),forceSelect2:!0,values:on,getCount:e=>parseInt(e.subscribers,10).toLocaleString(),getLabel:e=>e.name,getValue:e=>e.id},cn={name:"role",values:rn},mn={name:"afterTimeNumber",size:3,validation:{"data-parsley-required":!0,"data-parsley-errors-container":".mailpoet-form-errors","data-parsley-scheduled-at":(0,p.__)("An email can only be scheduled up to 5 years in the future. Please choose a shorter period.","mailpoet")}},un={name:"afterTimeType",values:Ds};class pn extends r.Component{getCurrentValue=()=>this.props.item[this.props.field.name]||{};handleValueChange=(e,t)=>{const a=this.getCurrentValue(),i={};let s=t;return"afterTimeNumber"===e&&(s=parseInt(t,10),s=Number.isNaN(s)?"":s),i[e]=s,this.props.onValueChange({target:{name:this.props.field.name,value:Lt.default.extend({},a,i)}})};handleEventChange=e=>this.handleValueChange("event",e.target.value);handleSegmentChange=e=>this.handleValueChange("segment",e.target.value);handleRoleChange=e=>this.handleValueChange("role",e.target.value);handleAfterTimeNumberChange=e=>this.handleValueChange("afterTimeNumber",e.target.value);handleAfterTimeTypeChange=e=>this.handleValueChange("afterTimeType",e.target.value);render(){const e=this.getCurrentValue();let t,a;return t="user"===e.event?(0,g.jsx)($t,{field:cn,item:this.getCurrentValue(),onValueChange:this.handleRoleChange}):(0,g.jsx)(Ve.L,{field:dn,item:this.getCurrentValue(),onValueChange:this.handleSegmentChange}),"immediate"!==e.afterTimeType&&(a=(0,g.jsx)(Ft,{field:mn,item:this.getCurrentValue(),onValueChange:this.handleAfterTimeNumberChange})),(0,g.jsxs)("div",{children:[(0,g.jsx)($t,{field:ln,item:this.getCurrentValue(),onValueChange:this.handleEventChange}),(0,g.jsx)("div",{className:"mailpoet-gap"}),t,(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsxs)("div",{className:"mailpoet-grid-column mailpoet-flex",children:[a,(0,g.jsx)($t,{field:un,item:this.getCurrentValue(),onValueChange:this.handleAfterTimeTypeChange})]}),(0,g.jsx)("div",{className:"mailpoet-form-errors"}),(0,g.jsx)("div",{className:"mailpoet-gap"})]})}}pn.propTypes={item:Rt().object.isRequired,field:Rt().shape({name:Rt().string}).isRequired,onValueChange:Rt().func.isRequired},pn.displayName="WelcomeScheduling";let hn=[{name:"email-header",label:null,tip:null,fields:[{name:"subject",customLabel:(0,p.__)("Subject","mailpoet"),className:"mailpoet-form-field-subject",placeholder:(0,p.__)("Type newsletter subject","mailpoet"),tooltip:(0,p.__)("Be creative! It's the first thing that your subscribers see. Tempt them to open your email.","mailpoet"),type:"text",validation:{"data-parsley-required":!0,"data-parsley-required-message":(0,p.__)("Please specify a subject","mailpoet"),maxLength:250}},{name:"preheader",customLabel:(0,p.__)("Preview text","mailpoet"),className:"mailpoet-form-field-preheader",placeholder:(0,p.__)("Type preview text (usually displayed underneath the subject line in the inbox)","mailpoet"),tooltip:`${(0,p.__)("This optional text will appear in your subscribers' inboxes, beside the subject line. Write something enticing!","mailpoet")} ${(0,p.__)("Max length is 250 characters, however, we recommend 80 characters on a single line.","mailpoet")}`,type:"textarea",validation:{maxLength:250}}]},{name:"options",label:(0,p.__)("When to send this welcome email?","mailpoet"),type:"reactComponent",component:(0,o.withBoundary)(pn)},ns,{name:"sender",label:(0,p.__)("Sender","mailpoet"),tip:(0,p.__)("Your name and email","mailpoet"),fields:[{name:"sender_name",type:"text",placeholder:(0,p.__)("John Doe","mailpoet"),validation:{"data-parsley-required":!0}},{name:"sender_address",type:"reactComponent",component:(0,o.withBoundary)(as),placeholder:(0,p.__)("john.doe@email.com","mailpoet"),validation:{"data-parsley-required":!0,"data-parsley-type":"email"}}]},{name:"empty",type:"empty"},{name:"reply-to",label:(0,p.__)("Reply-to","mailpoet"),tip:(0,p.__)("When your subscribers reply to your emails, their emails will go to this address.","mailpoet"),inline:!0,fields:[{name:"reply_to_name",type:"text",placeholder:(0,p.__)("John Doe","mailpoet")},{name:"reply_to_address",type:"text",placeholder:(0,p.__)("john.doe@email.com","mailpoet"),validation:{"data-parsley-type":"email"}}]}];hn=Ta.Hooks.applyFilters("mailpoet_newsletters_3rd_step_fields",hn);const gn={getFields:function(){return hn},getSendButtonOptions:function(){return{value:(0,p.__)("Activate","mailpoet")}}},_n=3;class fn extends r.Component{constructor(e){super(e);const{item:t,event:a}=this.props;this.handleChange=this.handleChange.bind(this);const i=t.afterTimeType||a.defaultAfterTimeType||"immediate",s="minutes"===i?30:1,n=t.afterTimeNumber||s;this.state={afterTimeType:i,afterTimeNumber:n},t.afterTimeNumber===n&&t.afterTimeType===i||this.propagateChange(this.state)}handleChange(e,t){let{value:a}=e.target;"afterTimeNumber"===t&&(a=parseInt(e.target.value,10),a=Number.isNaN(a)?null:a);const i={[t]:a},{afterTimeType:s}=this.state;"afterTimeType"===t&&s!==a&&("minutes"===s&&(i.afterTimeNumber=1),"minutes"===a&&(i.afterTimeNumber=30)),this.setState(i,this.propagateChange(i))}displayAfterTimeTypeOptions(){const{event:e}=this.props;let t=Ds;e.timeDelayValues&&(t=Object.entries(e.timeDelayValues).reduce((e,[t,a])=>(e[t]=a.text,e),{}));const{afterTimeType:a}=this.state,i={field:{id:"scheduling_time_interval",name:"scheduling_time_interval",forceSelect2:!0,values:Lt.default.map(t,(e,t)=>({name:e,id:t})),extendSelect2Options:{minimumResultsForSearch:1/0},selected:()=>a},onValueChange:Lt.default.partial(this.handleChange,Lt.default,"afterTimeType")};return(0,g.jsx)(Ve.L,{field:i.field,onValueChange:i.onValueChange})}displayAfterTimeNumberField(){const{event:e,afterTimeNumberSize:t=_n}=this.props,{afterTimeType:a,afterTimeNumber:i}=this.state;if("immediate"===a)return null;if(e.timeDelayValues&&e.timeDelayValues[a]&&!e.timeDelayValues[a].displayAfterTimeNumberField)return null;const s={field:{id:"scheduling_time_duration",name:"scheduling_time_duration",className:"mailpoet-form-input-small",defaultValue:i?i.toString():"",size:t,validation:{"data-parsley-required":!0,"data-parsley-errors-container":".mailpoet-form-errors","data-parsley-scheduled-at":(0,p.__)("An email can only be scheduled up to 5 years in the future. Please choose a shorter period.","mailpoet")}},item:{},onValueChange:Lt.default.partial(this.handleChange,Lt.default,"afterTimeNumber")};return(0,g.jsx)(Ft,{field:s.field,item:s.item,onValueChange:s.onValueChange})}propagateChange(e){const{onValueChange:t=null}=this.props;t&&t(e)}render(){const{event:e}=this.props;return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)("h4",{children:[" ",(0,p.__)("When to send this email?","mailpoet")," "]}),(0,g.jsxs)(Di.Grid.CenteredRow,{className:"mailpoet-re-engagement-scheduling",children:[this.displayAfterTimeNumberField(),this.displayAfterTimeTypeOptions(),e.afterDelayText&&(0,g.jsx)("p",{children:e.afterDelayText})]}),(0,g.jsx)("div",{className:"mailpoet-form-errors"}),(0,g.jsx)("div",{className:"mailpoet-gap"}),e.schedulingReadMoreLink&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("a",{href:e.schedulingReadMoreLink.link,target:"_blank",rel:"noopener noreferrer",className:"event-scheduling-read-more-link",children:e.schedulingReadMoreLink.text}),(0,g.jsx)("div",{className:"mailpoet-gap"})]})]})}}function bn(e){const t=e&&e.values?e.values:[];return t?t.map(e=>({id:e.id,name:e.name})):t}function xn({eventOptions:e,eventSlug:t,selected:a,onValueChange:i}){function s(e){i&&i({eventOptionValue:e.target.value})}return(0,g.jsx)("div",{children:(0,g.jsx)("div",{className:"event-option-selection",children:function(){if(!e)return null;const i={field:{name:`event_options_${t}`,forceSelect2:!0,endpoint:e.endpoint,resetSelect2OnUpdate:!0,values:bn(e),multiple:e.multiple||!1,placeholder:e.placeholder||!1,transformChangedValue:(e,t)=>Lt.default.map(t,e=>({id:e.id,name:e.text})),selected:()=>a,getLabel:Lt.default.property("name"),getValue:Lt.default.property("id"),validation:{"data-parsley-required":!0}},onValueChange:s,item:{action:""}};return"product_categories"===e.endpoint&&(i.field.name="category_ids",i.item={action:"purchasedCategory"}),"products"===e.endpoint&&(i.field.name="product_ids",i.item={action:"purchasedProduct"}),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(Ve.L,{field:i.field,onValueChange:i.onValueChange,item:i.item}),(0,g.jsx)("div",{className:"mailpoet-gap"})]})}()})})}fn.propTypes={item:Rt().shape({afterTimeType:Rt().string.isRequired,afterTimeNumber:Rt().number}).isRequired,afterTimeNumberSize:Rt().number,onValueChange:Rt().func,event:Rt().shape({defaultAfterTimeType:Rt().string,afterDelayText:Rt().string,timeDelayValues:Rt().objectOf(Rt().shape({text:Rt().string,displayAfterTimeNumberField:Rt().bool})),schedulingReadMoreLink:Rt().shape({link:Rt().string.isRequired,text:Rt().string.isRequired})}).isRequired},fn.displayName="EventScheduling",xn.displayName="EventOptions";const vn=(0,o.withBoundary)(xn);class yn extends r.Component{constructor(e){super(e);const{field:t}=e;this.handleChange=this.handleChange.bind(this),this.email=t.email,this.emailOptions=t.emailOptions,this.events=Lt.default.indexBy(this.email.events,"slug"),this.segments=Lt.default.filter(window.mailpoet_segments,e=>null===e.deleted_at);const a=this.events[this.emailOptions.event],i=this.emailOptions.afterTimeType||a.defaultAfterTimeType||"immediate";this.state={event:a,afterTimeType:i,eventSlug:this.emailOptions.event,eventOptionValue:null,afterTimeNumber:this.emailOptions.afterTimeNumber||1,segment:this.emailOptions.segment?this.emailOptions.segment:null}}handleChange(e){const{afterTimeNumber:t}=this.state,a=e;a.afterTimeType&&"immediate"===a.afterTimeType?a.afterTimeNumber=null:!a.afterTimeType||a.afterTimeNumber||t||(a.afterTimeNumber=1),this.setState(e,this.propagateChange)}displayScheduling(){const{afterTimeNumber:e,afterTimeType:t,event:a}=this.state,i={item:{afterTimeNumber:e,afterTimeType:t},event:a,onValueChange:this.handleChange};return(0,g.jsx)(fn,{item:i.item,event:i.event,onValueChange:i.onValueChange})}displaySegments(){const{segment:e}=this.state;if("user"===this.emailOptions.sendTo)return null;const t={field:{id:"segments",forceSelect2:!0,values:this.segments,extendSelect2Options:{minimumResultsForSearch:1/0},selected:()=>e},onValueChange:e=>this.handleChange({segment:e.target.value})};return(0,g.jsx)("div",{className:"event-segment-selection",children:(0,g.jsx)(Ve.L,{field:t.field,onValueChange:t.onValueChange})})}displayEventOptions(){const{event:e,eventSlug:t}=this.state;let a;try{a=JSON.parse(this.emailOptions.meta||null)}catch(e){a=this.emailOptions.meta||null}const i={emailSlug:this.email.slug,eventSlug:t,onValueChange:this.handleChange,eventOptions:e.options||null};return a&&a.option&&("remote"===i.eventOptions.type&&(i.eventOptions.values=a.option),i.selected=Lt.default.map(a.option,e=>e.id)),(0,g.jsx)(vn,{emailSlug:i.emailSlug,eventSlug:i.eventSlug,eventOptions:i.eventOptions,onValueChange:i.onValueChange,selected:i.selected})}displayHeader(){const{event:e}=this.state;return e.title}propagateChange(){const{eventSlug:e,afterTimeType:t,afterTimeNumber:a,segment:i,eventOptionValue:s}=this.state,{onValueChange:n=null}=this.props;if(!n)return;const r={group:this.email.slug,event:e,afterTimeType:t};a&&(r.afterTimeNumber=a),i&&(r.segment=i),s&&(r.meta=JSON.stringify({option:this.state.eventOptionValue})),n({target:{name:"options",value:r}})}render(){return(0,g.jsxs)("div",{children:[(0,g.jsx)(Kt.D,{level:5,children:this.displayHeader()}),this.displayEventOptions(),this.displaySegments(),this.displayScheduling()]})}}yn.propTypes={field:Rt().shape({email:Rt().shape({events:Rt().object.isRequired}).isRequired,emailOptions:Rt().object.isRequired}).isRequired,onValueChange:Rt().func},yn.displayName="SendEventConditions";const wn=window.mailpoet_woocommerce_automatic_emails||[],jn={getFields:function(e){return(e=>{const t=wn[e.options.group];if(!t)return!1;const a=e.options;return[{name:"email-header",label:null,tip:null,fields:[{name:"subject",customLabel:(0,p.__)("Subject","mailpoet"),className:"mailpoet-form-field-subject",placeholder:(0,p.__)("Type newsletter subject","mailpoet"),tooltip:(0,p.__)("Be creative! It's the first thing that your subscribers see. Tempt them to open your email.","mailpoet"),type:"text",validation:{"data-parsley-required":!0,"data-parsley-required-message":(0,p.__)("Please specify a subject","mailpoet"),maxLength:250}},{name:"preheader",customLabel:(0,p.__)("Preview text","mailpoet"),className:"mailpoet-form-field-preheader",placeholder:(0,p.__)("Type preview text (usually displayed underneath the subject line in the inbox)","mailpoet"),tooltip:`${(0,p.__)("This optional text will appear in your subscribers' inboxes, beside the subject line. Write something enticing!","mailpoet")} ${(0,p.__)("Max length is 250 characters, however, we recommend 80 characters on a single line.","mailpoet")}`,type:"textarea",validation:{maxLength:250}}]},{name:"options",label:(0,p.__)("Send this %1s Automatic Email when...","mailpoet").replace("%1s",t.title),type:"reactComponent",component:(0,o.withBoundary)(yn),email:t,emailOptions:a},ns,{name:"sender",label:(0,p.__)("Sender","mailpoet"),tip:(0,p.__)("Your name and email","mailpoet"),fields:[{name:"sender_name",type:"text",placeholder:(0,p.__)("John Doe","mailpoet"),validation:{"data-parsley-required":!0}},{name:"sender_address",type:"text",placeholder:(0,p.__)("john.doe@email.com","mailpoet"),validation:{"data-parsley-required":!0,"data-parsley-type":"email"}}]},{name:"empty",type:"empty"},{name:"reply-to",label:(0,p.__)("Reply-to","mailpoet"),tip:(0,p.__)("When your subscribers reply to your emails, their emails will go to this address.","mailpoet"),inline:!0,fields:[{name:"reply_to_name",type:"text",placeholder:(0,p.__)("John Doe","mailpoet")},{name:"reply_to_address",type:"text",placeholder:(0,p.__)("john.doe@email.com","mailpoet"),validation:{"data-parsley-type":"email"}}]}]})(e)},getSendButtonOptions:function(){return{value:(0,p.__)("Activate","mailpoet")}}};var Sn=a(39429);function kn({afterTimeNumber:e,afterTimeType:t,updateAfterTimeNumber:a,updateAfterTimeType:i,inactiveSubscribersPeriod:s}){const n="weeks"===t?7:30,r=Number(e)*n;let o=s;return 365===s&&(o=360),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(Kt.D,{level:4,children:(0,p.__)("When to send this re-engagement email?","mailpoet")}),(0,g.jsx)("p",{children:(0,p.__)("After no activity for","mailpoet")}),(0,g.jsxs)(Di.Grid.TwoColumns,{children:[(0,g.jsx)("div",{children:(0,g.jsx)(Dt.p,{type:"number",placeholder:(0,p.__)("count","mailpoet"),value:e,min:1,onChange:(0,ts.k9)(a),required:!0})}),(0,g.jsx)("div",{children:(0,g.jsxs)(Be.Select,{value:t,onChange:(0,ts.k9)(i),children:[(0,g.jsx)("option",{value:"weeks",children:(0,p.__)("weeks","mailpoet")}),(0,g.jsx)("option",{value:"months",children:(0,p.__)("months","mailpoet")})]})})]}),(!s||o>r)&&(0,g.jsx)("div",{className:"mailpoet-gap"}),!!s&&o<=r&&(0,g.jsx)("p",{className:"mailpoet-re-engagement-scheduling-note",children:b()((0,p.__)("Disengaged subscribers will [link]become inactive[/link] after {$months} months and won’t receive this email. Please select a shorter period.","mailpoet").replace("{$months}",`${Math.floor(s/30)}`),/\[link\](.*?)\[\/link\]/g,e=>(0,g.jsx)("a",{href:"https://kb.mailpoet.com/article/264-inactive-subscribers",target:"_blank",rel:"noopener noreferrer",children:e},"link"))})]})}const Nn=[{name:"email-header",label:null,tip:null,fields:[{name:"subject",customLabel:(0,p.__)("Subject","mailpoet"),className:"mailpoet-form-field-subject",placeholder:(0,p.__)("Type newsletter subject","mailpoet"),tooltip:(0,p.__)("Be creative! It's the first thing that your subscribers see. Tempt them to open your email.","mailpoet"),type:"text",validation:{"data-parsley-required":!0,"data-parsley-required-message":(0,p.__)("Please specify a subject","mailpoet"),maxLength:250}},{name:"preheader",customLabel:(0,p.__)("Preview text","mailpoet"),className:"mailpoet-form-field-preheader",placeholder:(0,p.__)("Type preview text (usually displayed underneath the subject line in the inbox)","mailpoet"),tooltip:`${(0,p.__)("This optional text will appear in your subscribers' inboxes, beside the subject line. Write something enticing!","mailpoet")} ${(0,p.__)("Max length is 250 characters, however, we recommend 80 characters on a single line.","mailpoet")}`,type:"textarea",validation:{maxLength:250}}]},{name:"options",type:"reactComponent",component:function(e){return(0,g.jsx)(kn,{afterTimeNumber:e.item.options.afterTimeNumber.toString(),afterTimeType:e.item.options.afterTimeType,inactiveSubscribersPeriod:Number(m.U.deactivateSubscriberAfterInactiveDays),updateAfterTimeNumber:t=>{e.onValueChange({target:{name:"options",value:(0,Sn.assoc)("afterTimeNumber",t,e.item.options)}})},updateAfterTimeType:t=>{e.onValueChange({target:{name:"options",value:(0,Sn.assoc)("afterTimeType",t,e.item.options)}})}})}},js,{name:"sender",label:(0,p.__)("Sender","mailpoet"),tip:(0,p.__)("Your name and email","mailpoet"),fields:[{name:"sender_name",type:"text",placeholder:(0,p.__)("John Doe","mailpoet"),validation:{"data-parsley-required":!0}},{name:"sender_address",type:"reactComponent",component:as,placeholder:(0,p.__)("john.doe@email.com","mailpoet"),validation:{"data-parsley-required":!0,"data-parsley-type":"email"}}]},{name:"reply-to",label:(0,p.__)("Reply-to","mailpoet"),tip:(0,p.__)("When your subscribers reply to your emails, their emails will go to this address.","mailpoet"),inline:!0,fields:[{name:"reply_to_name",type:"text",placeholder:(0,p.__)("John Doe","mailpoet")},{name:"reply_to_address",type:"text",placeholder:(0,p.__)("john.doe@email.com","mailpoet"),validation:{"data-parsley-type":"email"}}]},ns],Cn={getFields:()=>Nn,getSendButtonOptions:()=>({value:(0,p.__)("Activate","mailpoet")})};var En=a(69449);let In=null;var An=a(13300),Un=a(51895);function Tn({toggleLoadingState:e,updatePendingState:t}){const a=(0,r.useCallback)(async()=>{try{const{success:e,res:a}=await(0,o.callApi)({endpoint:"services",action:"refreshMSSKeyStatus"});!0===e?t(!(0,o.isTruthy)(a.data.result.data.is_approved)):m.U.Notice.showApiErrorNotice(a)}catch(e){m.U.Notice.showApiErrorNotice(e)}},[t]),[i,s]=(0,r.useState)(!0);return(0,g.jsxs)("div",{className:"mailpoet_error",children:[(0,g.jsx)(Un.wk,{}),i&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("br",{}),(0,g.jsx)("br",{}),(0,g.jsx)(Un.Tr,{onRefreshClick:async t=>{t.preventDefault(),e(!0),await a(),s(!1),e(!1)}})]})]})}Tn.displayName="PendingNewsletterMessage";const Pn=(0,o.withBoundary)(Tn),Rn=window.mailpoet_woocommerce_automatic_emails||{},Dn=(e,t)=>`${Ri()(t,{strict:!0,lower:!0})||"email"}-${e}`,Fn=e=>"immediate"===e.afterTimeType?"immediate":`${e.afterTimeNumber} ${e.afterTimeType}`;function On(e){let t,a;if(null===e.wp_post_id)return e&&e.body&&e.body.content&&(a=e.body.content,t=JSON.stringify(e.body.content),!a.blocks||!Array.isArray(a.blocks)||0===a.blocks.length)?(0,p.__)("Poet, please add prose to your masterpiece before you send it to your followers.","mailpoet"):window.mailpoet_mss_active&&t.indexOf("[link:subscription_unsubscribe_url]")<0&&t.indexOf("[link:subscription_unsubscribe]")<0?(0,p.__)('All emails must include an "Unsubscribe" link. Add a footer widget to your email to continue.',"mailpoet"):"re_engagement"===e.type&&t.indexOf("[link:subscription_re_engage_url]")<0?(0,p.__)("A re-engagement email must include a link with [link:subscription_re_engage_url] shortcode.","mailpoet"):"notification"===e.type&&t.indexOf('"type":"automatedLatestContent"')<0&&t.indexOf('"type":"automatedLatestContentLayout"')<0?(0,p._x)("Please add an “Automatic Latest Content” widget to the email from the right sidebar.","(Please reuse the current translation used for the string “Automatic Latest Content”) This Error message is displayed when a user tries to send a “Post Notification” email without any “Automatic Latest Content” widget inside","mailpoet"):"standard"===e.type&&"sent"===e.status?(0,p.__)("This email has already been sent. It can be edited, but not sent again. Duplicate this email if you want to send it again.","mailpoet"):"re_engagement"!==e.type||m.U.trackingConfig.emailTrackingEnabled?void 0:(0,g.jsx)("span",{style:{pointerEvents:"all"},children:b()((0,p.__)("Re-engagement emails are disabled because [link]open and click tracking[/link] is disabled.","mailpoet"),/\[link\](.*?)\[\/link\]/g,e=>(0,g.jsx)("a",{href:"?page=mailpoet-settings#/advanced",rel:"noopener noreferrer",children:e},"advancedSettingsTabLink"))})}class Mn extends r.Component{constructor(e){super(e),this.saveDraftNewsletter=this.saveDraftNewsletter.bind(this),this.state={fields:[],item:{},loading:!0,thumbnailPromise:null,showPremiumModal:!1,mssKeyPendingApproval:window.mailpoet_mss_key_pending_approval,sendContextValue:{saveDraftNewsletter:this.saveDraftNewsletter}}}componentDidMount(){this.loadItem(this.props.params.id).always(()=>{this.setState({loading:!1})}),Tt()("#mailpoet_newsletter").parsley({successClass:""})}componentDidUpdate(e){this.props.params.id!==e.params.id&&this.loadItem(this.props.params.id).always(()=>{this.setState({loading:!1})})}getFieldsByNewsletter=e=>this.getSubtype(e).getFields(e);getSendButtonOptions=()=>this.getSubtype(this.state.item).getSendButtonOptions(this.state.item);getSubtype=e=>{if(e.type===os.Gn.Automatic&&Rn[e.options.group])return jn;switch(e.type){case"notification":return nn;case"welcome":return gn;case"re_engagement":return Cn;default:return Ps}};getThumbnailPromise=e=>this.state?.thumbnailPromise??(0,En.uz)(e);isValid=()=>Tt()("#mailpoet_newsletter").parsley().isValid();isCampaign=()=>(window.mailpoet_sender_restrictions?.campaignTypes??[]).includes(this.state?.item?.type);isAuthorizedDomainRequired=()=>{const e=window.mailpoet_sender_restrictions?.isAuthorizedDomainRequiredForNewCampaigns||!1;return this.isCampaign()&&e};isValidFromAddress=async()=>{if("MailPoet"!==window.mailpoet_mta_method)return!0;if(window.mailpoet_sender_restrictions?.skipAuthorization)return!0;const e=await this.loadVerifiedSenderDomains(),t=(0,ts.Y8)(this.state.item.sender_address);if(-1!==e.indexOf(t))return!0;const a=await this.loadAuthorizedEmailAddresses(),i=this.state.item.sender_address;return-1!==a.indexOf(i)&&!this.isAuthorizedDomainRequired()};loadItem=e=>(this.setState({loading:!0}),m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"newsletters",action:"get",data:{id:e}}).done(e=>{const t="draft"===e.data.status?this.getThumbnailPromise(e.meta.preview_url):null,a=e.data;if(a.type===os.Gn.Automation){const e=a.options?.automationId,t=e?`admin.php?page=mailpoet-automation-editor&id=${e}`:"/new";return this.setState({item:{}},()=>{this.props.navigate(t)})}!a.ga_campaign&&ps.d&&(a.ga_campaign=Dn(a.id,a.subject));const i=new URLSearchParams(this.props.location.search).get("filterSegmentId");return i&&(e.data.options.filterSegmentId=i),this.setState({item:e.data,fields:this.getFieldsByNewsletter(e.data),thumbnailPromise:t,validationError:On(e.data)}),e.data?.wp_post_id&&m.U.trackEvent("New Email Editor > Send page opened-Newsletter created by BlockEmailEditor"),!0}).fail(()=>{this.setState({item:{}},()=>{this.props.navigate("/new")})}));saveTemplate=(e,t)=>{this.getThumbnailPromise(e.meta.preview_url).then(a=>{m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"newsletterTemplates",action:"save",data:{newsletter_id:e.data.id,name:e.data.subject,thumbnail_data:a,body:JSON.stringify(e.data.body),categories:'["recent"]'}}).then(()=>t()).fail(e=>{this.showError(e),this.setState({loading:!1}),m.U.Modal.loading(!1)})}).catch(e=>{this.showError({errors:[e]})})};loadAuthorizedEmailAddresses=async()=>{if("MailPoet"!==window.mailpoet_mta_method)return[];const e=(await m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"mailer",action:"getAuthorizedEmailAddresses"})).data||[];return window.mailpoet_authorized_emails=e,e};loadVerifiedSenderDomains=async()=>"MailPoet"!==window.mailpoet_mta_method?[]:(await m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"mailer",action:"getVerifiedSenderDomains"})).data||[];handleSend=e=>(e.preventDefault(),this.isValid()?(m.U.Modal.loading(!0),this.isValidFromAddress().then(e=>{e?this.saveNewsletter().done(()=>{this.setState({loading:!0})}).done(e=>{switch(e.data.type){case"notification":case"welcome":case"automatic":case"re_engagement":this.activateNewsletter(e);break;default:this.sendNewsletter(e)}}).fail(e=>{this.showError(e),this.setState({loading:!1}),m.U.Modal.loading(!1)}):(window.mailpoet_sender_address_field_blur(),m.U.Modal.loading(!1))})):Tt()("#mailpoet_newsletter").parsley().validate());sendNewsletter=e=>m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"sendingQueue",action:"add",data:{newsletter_id:this.state.item.id}}).done(t=>{this.saveTemplate(e,()=>{if(window.mailpoet_show_congratulate_after_first_newsletter)return m.U.Modal.loading(!1),void this.props.navigate(`/send/congratulate/${this.state.item.id}`);this.redirectToListing("activated");let a=[];e.data.segments.map(e=>a.push(...e.filters)),a=Qt().uniqWith(a,(e,t)=>e.action===t.action&&e.type===t.type);const i=a.map(e=>function(e){const t=e.action,a=e.type;if("automations"===a)switch(t){case"enteredAutomation":return"entered automation";case"exitedAutomation":return"exited automation";default:return""}if("email"===a)switch(t){case"machineOpensAbsoluteCount":return"number of machine-opens";case"opensAbsoluteCount":return"number of opens";case"clicked":return"clicked";case"clickedAny":return"clicked any email";case"opened":return"opened";case"machineOpened":return"machine-opened";case"wasSent":return"was sent";case"numberReceived":return"number of emails received";case"numberOfClicks":return"number of clicks";default:return""}if("userRole"===a)switch(t){case"subscriberTag":return"subscriber tags";case"subscribedToList":return"subscribed to list";case"subscriberScore":return"score";case"wordpressRole":return"WordPress user role";case"lastEngagementDate":return"last engagement date";case"lastClickDate":return"last click date";case"lastPurchaseDate":return"last purchase date";case"lastOpenDate":return"last open date";case"lastPageViewDate":return"last page view date";case"lastSendingDate":return"last sending date";case"subscriberFirstName":return"first name";case"subscriberLastName":return"last name";case"subscriberEmail":return"email";case"subscribedViaForm":return"subscribed via form";default:return""}if("woocommerce"===a)switch(t){case"customerInCountry":return"is in country";case"customerInPostalCode":return"postal code";case"customerInCity":return"city";case"purchasedCategory":return"purchased in category";case"purchasedTag":return"purchased with tag";case"purchasedProduct":return"purchased product";case"subscribedDate":return"subscribed date";case"totalSpent":return"total spent";case"firstOrder":return"first order";case"purchaseDate":return"purchase date";case"averageSpent":return"average order value";case"singleOrderValue":return"single order value";case"usedPaymentMethod":return"used payment method";case"usedShippingMethod":return"used shipping method";case"numberOfReviews":return"number of reviews";case"usedCouponCode":return"used coupon code";case"numberOfOrders":return"number of orders";case"purchasedWithAttribute":return"purchased with attribute";default:return""}return"woocommerceSubscription"===a&&"hasActiveSubscription"===t?"has an active subscription":"woocommerceMembership"===a&&"isMemberOf"===t?"is active member of":""}(e)).join(", "),s="scheduled"===t.data.status;m.U.trackEvent("Emails > Newsletter sent",{scheduled:s,"Segment Applied":!!this.state.item.options.filterSegmentId,segments:i,editor:this.state.item.wp_post_id?"BlockEmailEditor":"legacyEditor"}),s?this.context.notices.success((0,g.jsx)("p",{children:(0,p.__)("The newsletter has been scheduled.","mailpoet")})):this.context.notices.success((0,g.jsx)("p",{children:(0,p.__)("The newsletter is being sent...","mailpoet")}),{id:"mailpoet_notice_being_sent"}),m.U.Modal.loading(!1)})}).fail(e=>{this.showError(e),this.setState({loading:!1}),m.U.Modal.loading(!1)});activateNewsletter=e=>(0,An.M4)(Number(this.props.params.id),"active").then(t=>{this.saveTemplate(e,()=>{if(window.mailpoet_show_congratulate_after_first_newsletter)return m.U.Modal.loading(!1),void this.props.navigate(`/send/congratulate/${this.state.item.id}`);this.redirectToListing("activated");const e=this.state.item.options;"automatic"===this.state.item.type&&Rn[e.group]?m.U.trackEvent("Emails > Automatic email activated",{Type:Ri()(`${e.group}-${e.event}`),Delay:Fn(e)}):"welcome"===t.data.type?m.U.trackEvent("Emails > Welcome email activated",{"List type":e.event,Delay:Fn(e)}):"re_engagement"===t.data.type?(this.context.notices.success((0,g.jsx)("p",{children:(0,p.__)("Your Re-engagement Email is now activated!","mailpoet")})),m.U.trackEvent("Emails > Re-engagement email activated",{Inactivity:Fn(e),"Segment Applied":!!this.state.item.options.filterSegmentId})):"notification"===t.data.type&&(this.context.notices.success((0,g.jsx)("p",{children:(0,p.__)("Your post notification is now active!","mailpoet")})),m.U.trackEvent("Emails > Post notifications activated",{Frequency:e.intervalType,"Segment Applied":!!this.state.item.options.filterSegmentId})),m.U.Modal.loading(!1)})}).catch(e=>{this.showError({errors:[{message:e.message}]}),this.setState({loading:!1}),m.U.Modal.loading(!1)});handleResume=e=>(e.preventDefault(),this.isValid()?this.saveNewsletter().done(()=>{this.setState({loading:!0})}).done(()=>{m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"sendingQueue",action:"resume",data:{newsletter_id:this.state.item.id}}).done(()=>{this.redirectToListing("activated"),this.context.notices.success((0,g.jsx)("p",{children:(0,p.__)("The newsletter sending has been resumed.","mailpoet")}))}).fail(e=>{this.showError(e)})}).fail(e=>{this.showError(e)}).always(()=>{this.setState({loading:!1})}):Tt()("#mailpoet_newsletter").parsley().validate(),!1);handleSave=e=>{e.preventDefault(),this.saveNewsletter().done(()=>{this.context.notices.success((0,g.jsx)("p",{children:(0,p.__)("Email was updated successfully!","mailpoet")}))}).done(()=>{this.redirectToListing("saved")}).fail(e=>{this.showError(e)})};redirectToListing=e=>{["automatic","welcome"].includes(this.state.item.type)?window.location.href=`admin.php?page=mailpoet-automation¬ice=${e}`:this.props.navigate(`/${this.state.item.type}`)};handleRedirectToDesign=e=>{e.preventDefault();const t=e.target.href;this.saveNewsletter().done(()=>{this.context.notices.success((0,g.jsx)("p",{children:(0,p.__)("Email was updated successfully!","mailpoet")}))}).done(()=>{window.location=t}).fail(e=>{this.showError(e)})};saveNewsletter=()=>{const e=this.state.item;e.queue=void 0,this.setState({loading:!0});const t=Qt().omit(e,["body","created_at","deleted_at","hash","status","updated_at","type"]);return m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"newsletters",action:"save",data:t})};showError=e=>{e.errors.length>0&&this.context.notices.apiError(e,{scroll:!0,timeout:!1})};handleFormChange=e=>{const t=e.target.name,a=e.target.value;return this.setState(e=>{const i={...e.item},s=i.subject,n=i.ga_campaign;return i[t]=a,"subject"===t&&n===Dn(i.id,s)&&(i.ga_campaign=Dn(i.id,a)),"reply_to_address"===t&&(i[t]=a.toLowerCase()),{item:i}}),!0};handleSaveDraft=()=>{Tt()("#mailpoet_newsletter").parsley().destroy()};disableSegmentsSelectorWhenPaused=e=>t=>"segments"===t.name||"options"===t.name?{...t,disabled:e}:t;disableGAIfPremiumInactive=()=>e=>ps.d||"ga_campaign"!==e.name?e:{...e,disabled:!0,onWrapperClick:()=>this.setState({showPremiumModal:!0,premiumModalMessage:(0,p.__)("Google Analytics tracking is not available in the free version of the MailPoet plugin.","mailpoet")})};disableFilterSegmentToggleIfPremiumInactive=()=>e=>{if(!Array.isArray(e.fields))return e;const t={...e};return t.fields=t.fields.map(e=>"filter-segment-toggle"!==e.name||ps.d?e:{...e,disabled:!0,onWrapperClick:e=>{e.preventDefault(),this.setState({showPremiumModal:!0,premiumModalMessage:(0,p.__)("Filtering by segment is not available in the free version of the MailPoet plugin.","mailpoet")})}}),t};getPreparedFields=e=>Array.isArray(this.state.fields)?this.state.fields.map(this.disableSegmentsSelectorWhenPaused(e)).map(this.disableGAIfPremiumInactive()).map(this.disableFilterSegmentToggleIfPremiumInactive()):[];closePremiumModal=()=>this.setState({showPremiumModal:!1});toggleLoadingState=e=>this.setState({loading:e});updatePendingApprovalState=e=>this.setState({mssKeyPendingApproval:e});saveDraftNewsletter=async()=>{this.handleSaveDraft(),await this.saveNewsletter()};render(){const{showPremiumModal:e,item:{status:t,queue:a,type:i,options:s,wp_post_id:n},mssKeyPendingApproval:r}=this.state,l="sending"===t&&a&&"paused"===a.status,d=this.getSendButtonOptions(),c=this.getPreparedFields(l),u=!(!window.mailpoet_subscribers_limit_reached&&!r&&void 0===this.state.validationError);let h=i;return h===os.Gn.Automatic&&(h=s.group||h),(0,g.jsxs)("div",{className:"mailpoet-form-send-email",children:[(0,g.jsx)(ki,{emailType:h,automationId:"newsletter_send_heading"}),(0,g.jsxs)(o.ErrorBoundary,{children:[this.state.item.campaign_name?(0,g.jsx)("div",{className:"mailpoet-form-grid mailpoet-send-campaign-name",children:(0,g.jsx)("h1",{children:this.state.item.campaign_name})}):null,(0,g.jsx)(bs.Provider,{value:this.state.sendContextValue,children:(0,g.jsxs)(ia,{id:"mailpoet_newsletter",fields:c,automationId:"newsletter_send_form",item:this.state.item,loading:this.state.loading,onChange:this.handleFormChange,onSubmit:this.handleSave,children:[(0,g.jsxs)(Di.Grid.CenteredRow,{className:"send-newsletter-buttons",children:[(0,g.jsx)(o.Button,{variant:"secondary",type:"submit",automationId:"email-save-draft",onClick:this.handleSaveDraft,isDisabled:this.state.loading,children:(0,p.__)("Save as draft and close","mailpoet")}),l?(0,g.jsx)(o.Button,{type:"button",onClick:this.handleResume,isDisabled:u||this.state.loading,automationId:"email-resume",children:(0,p.__)("Resume","mailpoet")}):(0,g.jsx)(o.Button,{type:"button",onClick:this.handleSend,...d,isDisabled:u||this.state.loading,automationId:"email-submit",children:d.value||(0,p.__)("Send","mailpoet")}),void 0!==this.state.validationError&&(0,g.jsx)(ze.Tooltip,{tooltip:(0,g.jsx)("div",{children:this.state.validationError}),tooltipId:"helpTooltipSendEmail"})]}),(0,g.jsxs)("p",{children:[(0,p.__)("or simply","mailpoet")," ",(0,g.jsx)("a",{className:"mailpoet-link",href:n?m.U.getBlockEmailEditorUrl(Number(n)):`?page=mailpoet-newsletter-editor&id=${Number(this.props.params.id)}`,onClick:this.handleRedirectToDesign,children:(0,p.__)("go back to the Design page","mailpoet")}),"."]}),r&&(0,g.jsx)(Pn,{toggleLoadingState:this.toggleLoadingState,updatePendingState:this.updatePendingApprovalState}),e&&(0,g.jsx)(ps.D,{onRequestClose:this.closePremiumModal,children:this.state.premiumModalMessage})]})})]})]})}}function Ln(e){const[t,a]=(0,r.useState)(!1);return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(Kt.D,{level:0,children:(0,p.__)("Congratulations!","mailpoet")}),(0,g.jsx)(Kt.D,{level:3,children:(i=e.newsletter,"welcome"===i.type?(0,p.__)("Your Welcome Email is now active.","mailpoet"):"notification"===i.type?(0,p.__)("Your Post Notification is now active.","mailpoet"):"automatic"===i.type?(0,p.__)("Your WooCommerce email has been activated.","mailpoet"):"scheduled"===i.status?(0,p.__)("Your newsletter is scheduled to be sent.","mailpoet"):(0,p.__)("Your newsletter is being sent!","mailpoet"))}),(0,g.jsx)("div",{className:"mailpoet-gap-large"}),(0,g.jsx)("div",{className:"mailpoet-gap-large"}),(0,g.jsx)("img",{src:e.illustrationImageUrl,alt:"",width:"500"}),(0,g.jsx)("div",{className:"mailpoet-gap-large"}),(0,g.jsx)(o.Button,{type:"button",dimension:"small",onClick:()=>{e.successClicked(),a(!0)},withSpinner:t,children:(0,p.__)("Close","mailpoet")})]});var i}function $n(e){return(0,g.jsxs)("div",{className:"mailpoet-wizard-step",children:[(0,g.jsx)("div",{className:"mailpoet-wizard-step-illustration",children:(0,g.jsx)("img",{src:e.illustrationUrl,alt:""})}),(0,g.jsx)("div",{className:"mailpoet-wizard-step-content",children:e.children})]})}function Bn(){return(0,g.jsxs)(o.List,{children:[(0,g.jsx)("li",{children:(0,p.__)("Reliable marketing and transactional email delivery. Reach inboxes, not spam boxes","mailpoet")}),(0,g.jsx)("li",{children:(0,p.__)("Send your emails super fast (up to 50,000 emails per hour)","mailpoet")}),(0,g.jsx)("li",{children:(0,p.__)("Maintain your sender reputation and improve engagement levels with automated bounce and complaint handling. Stop sending to non-deliverable and complaining addresses, automatically","mailpoet")}),(0,g.jsx)("li",{children:(0,p.__)("Authenticate your emails (with SPF and DKIM) to improve deliverability and avoid spam boxes","mailpoet")})]})}function Wn(e){const[t,a]=(0,r.useState)(!1),i=()=>{e.onFinish(),a(!0)};return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(o.Heading,{level:1,children:(s=e.newsletter.type,{standard:(0,p.__)("Your email has been sent!","mailpoet"),welcome:(0,p.__)("You are all set up and ready to go!","mailpoet"),notification:(0,p.__)("You are all set up and ready to go!","mailpoet"),woocommerce:(0,p.__)("You are all set up and ready to go!","mailpoet")}[s]||(0,p.__)("You are all set up and ready to go!","mailpoet"))}),(0,g.jsx)($n,{illustrationUrl:e.MSSPitchIllustrationUrl,children:(0,g.jsxs)("div",{className:"mailpoet-welcome-wizard-step-content",children:[(0,g.jsx)(o.Heading,{level:4,children:(0,p.__)("What’s next? Sign up to the MailPoet Starter plan for fast and reliable email delivery","mailpoet")}),(0,g.jsx)("p",{children:e.subscribersCount<500?(0,p._x)("Did you know? Users with 500 subscribers or less get the Starter plan for free.","Promotion for our email sending service: Paragraph","mailpoet"):(0,p._x)("Starting at only $10 per month, MailPoet Business offers the following features","Promotion for our email sending service: Paragraph","mailpoet")}),(0,g.jsxs)(o.Heading,{level:5,children:[(0,p._x)("You’ll get","Promotion for our email sending service: Paragraph","mailpoet"),":"]}),(0,g.jsx)(Bn,{}),(0,g.jsx)("p",{children:b()((0,p.__)("Please enter your key in [link]the Settings[/link] if you have already purchased it.","mailpoet"),/\[link\](.*?)\[\/link\]/g,(e,t)=>(0,g.jsx)("a",{href:"admin.php?page=mailpoet-settings#/premium",children:e},t))}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)(o.Button,{isFullWidth:!0,href:e.purchaseUrl,target:"_blank",rel:"noopener noreferrer",onClick:t=>{t.preventDefault(),window.open(e.purchaseUrl),i()},children:(0,p._x)("Sign up for free","Promotion for our email sending service: Button","mailpoet")}),(0,g.jsx)(o.Button,{isFullWidth:!0,variant:"tertiary",onClick:i,onKeyDown:e=>{["keydown","keypress"].includes(e.type)&&["Enter"," "].includes(e.key)&&(e.preventDefault(),i())},withSpinner:t,children:(0,p._x)("No thanks!","Promotion for our email sending service: Skip link","mailpoet")})]})})]});var s}function Vn(e){return window.has_mss_key_specified?(0,g.jsx)(Ln,{successClicked:e.successClicked,illustrationImageUrl:e.illustrationImageUrl,newsletter:e.newsletter}):(0,g.jsx)(Wn,{MSSPitchIllustrationUrl:e.MSSPitchIllustrationUrl,onFinish:e.successClicked,subscribersCount:e.subscribersCount,purchaseUrl:e.purchaseUrl,newsletter:e.newsletter})}function qn(e){const[t,a]=(0,r.useState)(!1);return(0,g.jsxs)("div",{children:[(0,g.jsx)(Kt.D,{level:1,children:(0,p.__)("Oops! We can’t send your newsletter","mailpoet")}),(0,g.jsx)(Kt.D,{level:3,children:b()((0,p.__)("Rest assured, this is fairly common and is usually fixed quickly. [link]See our quick guide[/link] to help you solve this and get your website sending.","mailpoet"),/\[link\](.*?)\[\/link\]/g,(e,t)=>(0,g.jsx)("a",{target:"_blank",rel:"noopener noreferrer",href:"https://kb.mailpoet.com/article/231-sending-does-not-work",children:e},t))}),(0,g.jsx)("div",{className:"mailpoet-gap-large"}),(0,g.jsx)("div",{className:"mailpoet-gap-large"}),(0,g.jsx)("img",{src:window.mailpoet_congratulations_error_image,alt:"",width:"500"}),(0,g.jsx)("div",{className:"mailpoet-gap-large"}),(0,g.jsx)(o.Button,{dimension:"small",type:"button",onClick:()=>{e.failClicked(),a(!0)},withSpinner:t,children:(0,p.__)("Close","mailpoet")})]})}Mn.contextType=l.F,Ln.propTypes={successClicked:Rt().func.isRequired,illustrationImageUrl:Rt().string.isRequired,newsletter:Rt().shape({status:Rt().string.isRequired,type:Rt().string.isRequired}).isRequired},$n.propTypes={illustrationUrl:Rt().string.isRequired,children:Rt().oneOfType([Rt().arrayOf(Rt().node),Rt().node]).isRequired},Vn.propTypes={successClicked:Rt().func.isRequired,illustrationImageUrl:Rt().string.isRequired,MSSPitchIllustrationUrl:Rt().string.isRequired,newsletter:Rt().shape({status:Rt().string.isRequired,type:Rt().string.isRequired}).isRequired,subscribersCount:Rt().number.isRequired,purchaseUrl:Rt().string.isRequired},qn.propTypes={failClicked:Rt().func.isRequired};var zn=a(92230);function Hn(e){return(0,g.jsx)("div",{className:"mailpoet-congratulate-loading",children:e.showRichLoadingScreen&&(0,g.jsxs)("div",{children:[(0,g.jsx)(Kt.D,{level:0,children:(0,p.__)("Verification","mailpoet")}),(0,g.jsx)(Kt.D,{level:3,children:(0,p.__)("Congrats, you’re sending your first newsletter! We’re doing a quick verification to make sure everything works fine.","mailpoet")}),(0,g.jsx)("div",{className:"mailpoet-gap-large"}),(0,g.jsx)("div",{className:"mailpoet-gap-large"}),(0,g.jsx)(zn.a,{size:64})]})})}Hn.propTypes={showRichLoadingScreen:Rt().bool.isRequired};const Gn=Math.floor(4*Math.random());function Yn(){return m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"settings",action:"set",data:{show_congratulate_after_first_newsletter:!1}}).always(()=>{window.location=window.mailpoet_emails_page})}class Kn extends r.Component{constructor(e){super(e),this.state={loading:!0,newsletter:null,testingPassed:!1,timeStart:Et()(),minimumLoadingTimePassed:!1},this.tick=this.tick.bind(this)}componentDidMount(){this.loadNewsletter(this.props.params.id),this.tick()}componentDidUpdate(e){e.params.id!==this.props.params.id&&this.loadNewsletter(this.props.params.id)}tick(){Et()().subtract(20,"second").isAfter(this.state.timeStart)&&this.setState({error:!0,loading:!1}),this.state.loading&&this.loadNewsletter(this.props.params.id),Et()().subtract(6,"seconds").isAfter(this.state.timeStart)&&this.setState({minimumLoadingTimePassed:!0}),!this.state.loading&&this.state.minimumLoadingTimePassed||setTimeout(this.tick,2e3)}loadNewsletter(e){m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"newsletters",action:"get",data:{id:e}}).done(e=>this.newsletterLoaded(e.data))}newsletterLoaded(e){"standard"!==e.type||"scheduled"===e.status?this.setState({newsletter:e,loading:!1,minimumLoadingTimePassed:!0}):"sent"===e.status||"sending"===e.status?this.setState({newsletter:e,loading:!1,testingPassed:!0}):this.setState({newsletter:e})}renderContent(){return this.state.loading||!this.state.minimumLoadingTimePassed?(e=!this.state.newsletter,(0,g.jsx)(Hn,{illustrationImageUrl:window.mailpoet_congratulations_loading_image,successClicked:Yn,showRichLoadingScreen:e})):this.state.error?(m.U.trackEvent("Cron testing done",{"Cron is working":"false"}),(0,g.jsx)(qn,{failClicked:()=>{window.location=window.mailpoet_emails_page}})):(t=this.state.newsletter,this.state.testingPassed&&m.U.trackEvent("Cron testing done",{"Cron is working":"true"}),(0,g.jsx)(Vn,{illustrationImageUrl:window.mailpoet_congratulations_success_images[Gn],MSSPitchIllustrationUrl:window.mailpoet_congratulations_success_images[Gn],successClicked:Yn,newsletter:t,isWoocommerceActive:window.mailpoet_woocommerce_active,subscribersCount:window.mailpoet_subscribers_count,purchaseUrl:m.U.MailPoetComUrlFactory.getPurchasePlanUrl(m.U.subscribersCount,m.U.currentWpUserEmail,"starter",{utm_medium:"first-newsletter-congratulations",utm_campaign:"purchase"})}));var e,t}render(){return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("style",{dangerouslySetInnerHTML:{__html:"body { background: #fff; overflow-x: hidden; }"}}),(0,g.jsxs)("div",{className:"mailpoet-congratulate",children:[(0,g.jsx)("div",{className:"mailpoet-gap-large"}),this.renderContent()]})]})}}Kn.propTypes={params:Rt().shape({id:Rt().string}).isRequired},Kn.displayName="Congratulate";class Zn extends r.Component{componentDidMount(){m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"newsletters",action:"create",data:{type:"standard",subject:(0,p.__)("Subject","mailpoet")}}).done(e=>{window.location.search.includes("loadedvia=woo_multichannel_dashboard")&&window.MailPoet.trackEvent("MailPoet - WooCommerce Multichannel Marketing dashboard > Newsletter template selection page",{"WooCommerce version":window.mailpoet_woocommerce_version}),this.showTemplateSelection(e.data.id)}).fail(e=>{e.errors.length>0&&this.context.notices.apiError(e,{scroll:!0})})}showTemplateSelection=e=>{this.props.navigate(`/template/${e}`)};render(){return(0,g.jsx)("div",{children:(0,g.jsx)(ki,{emailType:"standard",automationId:"standard_newsletter_creation_heading"})})}}Zn.contextType=l.F,Zn.propTypes={navigate:Rt().func.isRequired},Zn.displayName="NewsletterStandard";const Jn={name:"options",type:"reactComponent",component:an};class Qn extends r.Component{constructor(e){super(e),this.state={options:{intervalType:"daily",timeOfDay:0,weekDay:zs(m.U.wpWeekStartsOn),monthDay:"1",nthWeekDay:"1"}}}componentDidMount(){window.location.search.includes("loadedvia=woo_multichannel_dashboard")&&window.MailPoet.trackEvent("MailPoet - WooCommerce Multichannel Marketing dashboard > Create post notification page",{"WooCommerce version":window.mailpoet_woocommerce_version})}handleValueChange=e=>{const t=this.state;t[e.target.name]=e.target.value,this.setState(t)};handleNext=()=>{m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"newsletters",action:"create",data:Lt.default.extend({},this.state,{type:"notification",subject:(0,p.__)("The last [newsletter:total] posts from our blog","mailpoet")})}).done(e=>{this.showTemplateSelection(e.data.id)}).fail(e=>{e.errors.length>0&&this.context.notices.apiError(e,{scroll:!0})})};showTemplateSelection=e=>{this.props.navigate(`/template/${e}`)};render(){return(0,g.jsxs)("div",{children:[(0,g.jsx)(ki,{emailType:"notification",automationId:"post_notification_creation_heading"}),(0,g.jsxs)(Di.Grid.Column,{align:"center",className:"mailpoet-schedule-email",children:[(0,g.jsx)(Kt.D,{level:4,children:(0,p.__)("When to send this post notification email?","mailpoet")}),(0,g.jsx)(an,{item:this.state,field:Jn,onValueChange:this.handleValueChange}),(0,g.jsx)(Ge.$,{isFullWidth:!0,onClick:this.handleNext,type:"button",children:(0,p.__)("Next","mailpoet")})]})]})}}function Xn(){let e="11";m.U.deactivateSubscriberAfterInactiveDays&&(e=(Math.floor(Number(m.U.deactivateSubscriberAfterInactiveDays)/30)-1).toString());const[t,a]=(0,r.useState)({afterTimeNumber:e,afterTimeType:"months"}),[i,s]=(0,r.useState)([]),[n,o]=(0,r.useState)(!1),l=(0,Ue.Zp)();return(0,g.jsxs)("div",{children:[i&&(0,g.jsx)(gi,{errors:i}),(0,g.jsx)(ki,{emailType:"re_engagement",automationId:"re_engagement_heading_creation_heading"}),(0,g.jsxs)(Di.Grid.Column,{align:"center",className:"mailpoet-schedule-email",children:[(0,g.jsx)(kn,{afterTimeNumber:t.afterTimeNumber,afterTimeType:t.afterTimeType,inactiveSubscribersPeriod:Number(m.U.deactivateSubscriberAfterInactiveDays),updateAfterTimeNumber:(0,Sn.compose)([a,(0,Sn.assoc)("afterTimeNumber",Sn.__,t)]),updateAfterTimeType:(0,Sn.compose)([a,(0,Sn.assoc)("afterTimeType",Sn.__,t)])}),(0,g.jsx)(Ge.$,{isFullWidth:!0,onClick:()=>(s([]),o(!0),void m.U.Ajax.post({api_version:m.U.apiVersion,endpoint:"newsletters",action:"create",data:{type:"re_engagement",subject:(0,p.__)("Subject","mailpoet"),options:t}}).done(e=>{var t;t=e.data.id,l(`/template/${t}`)}).fail(e=>{o(!1),e.errors&&s(e.errors)})),type:"button",isDisabled:!t.afterTimeNumber||n,withSpinner:n,children:(0,p.__)("Next","mailpoet")})]})]})}Qn.contextType=l.F,Xn.displayName="NewsletterTypeReEngagement";var er=a(23391),tr=a(86363),ar=a(72456);function ir({newsletter:e}){const[t,a]=(0,r.useState)("paused"===e.queue.status),[i,s]=(0,r.useState)([]),n=async()=>{s([]),await(async()=>{await m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"sendingQueue",action:"resume",data:{newsletter_id:e.id}}).done(()=>a(!1)).fail(e=>s(e.errors))})()};return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(gi,{errors:i}),t&&(0,g.jsx)(Ge.$,{dimension:"small",onClick:e.status===os.um.Corrupt?async()=>{(0,o.confirmAlert)({message:(0,p.__)("There was an issue sending this email before. Please confirm the problems are fixed to proceed.","mailpoet"),onConfirm:n})}:n,children:(0,p.__)("Resume","mailpoet")}),!t&&(0,g.jsx)(Ge.$,{dimension:"small",onClick:async()=>{s([]),await m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"sendingQueue",action:"pause",data:{newsletter_id:e.id}}).done(()=>a(!0)).fail(e=>s(e.errors))},children:(0,p.__)("Pause","mailpoet")})]})}function sr(){return(0,g.jsx)("div",{className:"mailpoet-listing-stats-too-early",children:(0,g.jsx)("a",{href:"admin.php?page=mailpoet-help#/systemStatus",className:"mailpoet-tag mailpoet-tag-inverted mailpoet-tag-unknown",children:(0,p.__)("Cancelled","mailpoet")})})}function nr({newsletter:e,mailerLog:t}){const a=(0,ar.nO)(e.queue),i=parseInt(e.queue.count_processed,10)>0||e.status===os.um.Sending,s=a&&(null===e.queue.status||"scheduled"===e.queue.status&&i),n=s?e.sent_at:e.sent_at||e.queue.scheduled_at,r=e.queue&&"cancelled"===e.queue.status,o=e.queue&&("scheduled"!==e.queue.status||s),l="paused"===t.status,d=(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(Ae.Link,{to:`/sending-status/${e.id}`,"data-automation-id":`sending_status_${e.id}`,children:(0,g.jsx)(tr.um,{processed:parseInt(e.queue.count_processed,10),scheduledFor:n,total:parseInt(e.queue.count_total,10),isPaused:l,status:e.status,logs:e.logs})}),r&&(0,g.jsx)(sr,{}),"completed"!==e.queue.status&&!r&&!l&&(0,g.jsx)(ir,{newsletter:e})]}),c=(0,g.jsx)(tr.um,{scheduledFor:n,isPaused:"scheduled"===e.queue.status&&l,status:e.status,logs:e.logs});return(0,g.jsxs)(g.Fragment,{children:[o&&d,!o&&c]})}nr.displayName="QueueStatus";const rr=(0,o.withBoundary)(nr);var or=a(16376);function lr({newsletterId:e,sent:t}){const a=`timezone-campaign-${e}`;return(0,g.jsxs)("span",{"data-tip":!0,"data-tooltip-id":a,"data-automation-id":`timezone_campaign_status_${e}`,style:{marginLeft:"4px"},children:[(0,g.jsx)(mi.A,{icon:or.A,size:20,style:{fill:"currentColor",verticalAlign:"middle"}}),(0,g.jsx)(gs.m,{place:"right",id:a,children:t?(0,p.__)("Sent in subscriber's time zone","mailpoet"):(0,p.__)("Sends in subscriber's time zone","mailpoet")})]})}lr.displayName="TimezoneCampaignIcon";var dr=a(46666);function cr({newsletter:e,isSent:t,currentTime:a}){let i=t;if(void 0===i&&(i=e.statistics&&e.queue&&"scheduled"!==e.queue.status),!i)return null;const s={link:`/stats/${e.id}`,onClick:Ta.Hooks.applyFilters("mailpoet_newsletters_listing_stats_tracking",Ai.cp)},n=Number(e.total_sent||e.queue.count_processed),r=e.queue&&"cancelled"===e.queue.status;if(r&&0===n)return null;let l,d,c,m,u,h=0,_=0,f=null;n>0&&(h=100*e.statistics.clicked/n,_=100*e.statistics.opened/n,f=e.statistics.revenue),r||void 0===a?(m=!1,u=!1):(l=6,d=e.queue.scheduled_at||e.queue.created_at,c=Et()(a).diff(Et()(d),"hours"),m=c<l,u=!0);const b=n>=20&&e.statistics.opened>=5&&!m,x=m&&"completed"===e.queue.status,v=(t,a)=>((e,t,a,i)=>i<=0||!t.link?e:t.externalLink?(0,g.jsx)("a",{href:t.link,onClick:t.onClick||null,children:e},`stats-${a}`):(0,g.jsx)(Ae.Link,{to:t.link,onClick:t.onClick||null,children:e},`stats-${a}`))(t,s,`${a}-${e.id}`,n),y=(0,g.jsx)(dr.j,{opened:_,clicked:h,revenues:f&&f.value>0?f.formatted:null,hideBadges:!b,newsletterId:e.id,wrapContentInLink:v}),w=(0,g.jsxs)(g.Fragment,{children:[y,x&&v((0,g.jsx)(o.Tag,{className:"mailpoet-listing-stats-too-early",dimension:"large",variant:"excellent",isInverted:!0,children:(0,p.__)("Nice job! Check back in %1$d hour(s) for more stats.","mailpoet").replace("%1$d",l-c)}),"check-back")]});let j;return u&&_<5&&c>=24&&n>=10&&(j=(0,g.jsx)("div",{children:(0,g.jsx)("a",{href:"https://kb.mailpoet.com/article/191-how-to-improve-my-open-and-click-rates",target:"_blank",rel:"noopener noreferrer",className:"mailpoet_stat_link_small",children:(0,p.__)("What can I do to improve this?","mailpoet")})})),(0,g.jsxs)(g.Fragment,{children:[w,j]})}const mr=Rt().shape({clicked:Rt().number,opened:Rt().number,unsubscribed:Rt().number,revenue:Rt().shape({count:Rt().number,currency:Rt().string,formatted:Rt().string,value:Rt().number})}),ur=Rt().shape({status:Rt().string,count_processed:Rt().string.isRequired,count_total:Rt().string.isRequired,created_at:Rt().string,scheduled_at:Rt().string});cr.propTypes={newsletter:Rt().shape({id:Rt().oneOfType([Rt().number,Rt().string]).isRequired,queue:Rt().oneOfType([ur,Rt().bool]),total_sent:Rt().number,statistics:Rt().oneOfType([mr,Rt().bool])}).isRequired,isSent:Rt().bool,currentTime:Rt().string},cr.displayName="NewsletterStatistics";const pr=(0,o.withBoundary)(cr);var hr=a(19718),gr=a(16674),_r=a(628),fr=a(79358),br=a(4362);function xr(e,t=""){const a=encodeURIComponent(e),i=encodeURIComponent(t);return[{name:"facebook",url:`https://www.facebook.com/sharer/sharer.php?u=${a}`},{name:"x",url:`https://twitter.com/intent/tweet?url=${a}&text=${i}`},{name:"whatsapp",url:`https://wa.me/?text=${i}%20${a}`},{name:"email",url:`mailto:?subject=${i}&body=${a}`}]}const vr="public",yr={facebook:(0,p.__)("Facebook","mailpoet"),x:(0,p.__)("X","mailpoet"),whatsapp:(0,p.__)("WhatsApp","mailpoet"),email:(0,p.__)("Email","mailpoet")},wr={idle:(0,p.__)("Copy to clipboard","mailpoet"),copied:(0,p.__)("Copied to clipboard","mailpoet"),failed:(0,p.__)("Could not copy to clipboard","mailpoet")},jr={idle:gr.A,copied:ie.A,failed:_r.A};function Sr(){return(0,g.jsx)("svg",{"aria-hidden":"true",focusable:"false",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,g.jsx)("path",{fill:"currentColor",d:"M13.5 21v-7.2h2.4l.5-3h-2.9V8.9c0-.8.4-1.6 1.7-1.6h1.3V4.7c-.2 0-1.2-.2-2.3-.2-2.4 0-4 1.5-4 4.1v2.2H7.5v3h2.7V21h3.3Z"})})}function kr(){return(0,g.jsx)("svg",{"aria-hidden":"true",focusable:"false",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,g.jsx)("path",{fill:"currentColor",d:"M14.2 10.4 21 3h-1.6l-5.9 6.4L8.8 3H3.3l7.1 9.6L3.3 21H5l6.2-7.3 5 7.3h5.5l-7.5-10.6Zm-2.2 2.5-.7-1-5.7-7.6H8l4.6 6.2.7 1 6 8.1h-2.4L12 12.9Z"})})}function Nr(){return(0,g.jsx)("svg",{"aria-hidden":"true",focusable:"false",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,g.jsx)("path",{fill:"currentColor",d:"M12 3.5a8.3 8.3 0 0 0-7.2 12.4L4 20.5l4.7-1.2A8.5 8.5 0 1 0 12 3.5Zm0 15.3c-1.1 0-2.2-.3-3.2-.8l-.3-.2-2.7.7.7-2.6-.2-.3A6.8 6.8 0 1 1 12 18.8Zm3.8-5.1c-.2-.1-1.2-.6-1.4-.7-.2 0-.3-.1-.5.1l-.6.8c-.1.2-.3.2-.5.1-.2-.1-1-.4-1.9-1.1-.7-.6-1.1-1.3-1.3-1.5-.1-.2 0-.4.1-.5l.4-.4.2-.4c.1-.1 0-.3 0-.4 0-.1-.5-1.2-.7-1.6-.2-.4-.4-.4-.5-.4h-.5c-.2 0-.4.1-.6.3-.2.2-.8.8-.8 1.9s.8 2.2.9 2.3c.1.2 1.6 2.5 3.9 3.5.5.2 1 .4 1.3.5.5.2 1 .1 1.4.1.4-.1 1.2-.5 1.4-1 .2-.5.2-.9.2-1 0-.1-.2-.2-.4-.3Z"})})}function Cr(){return(0,g.jsx)("svg",{"aria-hidden":"true",focusable:"false",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,g.jsx)("path",{fill:"currentColor",d:"M4.8 6h14.4c1 0 1.8.8 1.8 1.8v8.4c0 1-.8 1.8-1.8 1.8H4.8c-1 0-1.8-.8-1.8-1.8V7.8C3 6.8 3.8 6 4.8 6Zm7.2 6.4 7.1-4.9H4.9l7.1 4.9Zm-7.5 3.8c0 .2.1.3.3.3h14.4c.2 0 .3-.1.3-.3V8.9l-7.1 4.9a.8.8 0 0 1-.8 0L4.5 8.9v7.3Z"})})}const Er={facebook:(0,g.jsx)(Sr,{}),x:(0,g.jsx)(kr,{}),whatsapp:(0,g.jsx)(Nr,{}),email:(0,g.jsx)(Cr,{})};function Ir({newsletter:e,onClose:t,onMakePublic:a}){const[i,s]=(0,r.useState)("idle"),n=`mailpoet-share-url-${e.id}`,o=e.campaign_name||e.subject||"",l=e.can_share&&e.share_url,d=e.is_share_supported,c="undefined"!=typeof navigator&&"function"==typeof navigator.share;return(0,g.jsx)(Te.A,{title:(0,p.__)("Share email","mailpoet"),onRequestClose:t,className:"mailpoet-share-email-modal",size:"medium",children:(0,g.jsxs)("div",{className:"mailpoet-share-email-modal__content","data-automation-id":"newsletter-share-modal",children:[(0,g.jsx)("p",{className:"mailpoet-share-email-modal__intro",children:(0,p.sprintf)((0,p.__)('Share "%s" using its public email page.',"mailpoet"),o)}),l?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)("div",{className:"mailpoet-share-email-modal__url-row",children:[(0,g.jsx)(hr.A,{id:n,className:"mailpoet-share-email-modal__url-control",type:"url",label:(0,p.__)("Public share link","mailpoet"),readOnly:!0,value:e.share_url||"",onChange:()=>{},onFocus:e=>e.target.select(),"data-automation-id":"newsletter-share-url",__next40pxDefaultSize:!0}),(0,g.jsx)(ge.Ay,{type:"button",variant:"secondary",icon:jr[i],disabled:"copied"===i,accessibleWhenDisabled:!0,onClick:()=>{(async()=>{await(0,br.l)(n,e=>{e?(s("copied"),window.setTimeout(()=>s("idle"),3e3)):s("failed")},!0)})()},"data-automation-id":"newsletter-share-copy",__next40pxDefaultSize:!0,children:wr[i]})]}),(0,g.jsxs)("div",{className:"mailpoet-share-email-modal__actions",children:[c&&(0,g.jsx)(ge.Ay,{type:"button",variant:"secondary",icon:fr.A,onClick:()=>{(async()=>{navigator.share&&e.share_url&&await navigator.share({title:o,url:e.share_url})})()},"data-automation-id":"newsletter-share-native",__next40pxDefaultSize:!0,children:(0,p.__)("Share","mailpoet")}),xr(e.share_url,o).map(e=>(0,g.jsx)(ge.Ay,{href:e.url,target:"_blank",rel:"noopener noreferrer",className:`mailpoet-share-email-modal__social-button mailpoet-share-email-modal__social-button--${e.name}`,icon:Er[e.name],"data-automation-id":`newsletter-share-${e.name}`,__next40pxDefaultSize:!0,children:yr[e.name]},e.name))]})]}):(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(Fe.A,{status:"warning",isDismissible:!1,className:"mailpoet-share-email-modal__notice","data-automation-id":"newsletter-share-unavailable",children:e.share_unavailable_reason||(0,p.__)("This email cannot be shared yet.","mailpoet")}),d&&(0,g.jsx)("div",{className:"mailpoet-share-email-modal__footer",children:(0,g.jsx)(ge.Ay,{type:"button",variant:"primary",onClick:()=>a(e),"data-automation-id":"newsletter-share-make-public",__next40pxDefaultSize:!0,children:(0,p.__)("Make public and share","mailpoet")})})]})]})})}function Ar(e,t){let a=null,i=!1,s=0;const n=Date.now(),r=()=>{i||(Date.now()-n>3e5?t.onError((0,p.__)("The export is taking longer than expected. Please try again later.","mailpoet")):(e=>m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"statisticsExport",action:"getStatus",data:{task_id:e}}).then(e=>e.data))(e).then(e=>{i||(s=0,e.error?t.onError(e.error):e.exportFileURL?t.onComplete(e):a=window.setTimeout(r,2500))}).catch(e=>{if(!i){if(s+=1,s>=3){const a=e?.errors?.[0]?.message??(0,p.__)("Could not check the export status.","mailpoet");return void t.onError(a)}a=window.setTimeout(r,2500)}}))};return r(),{cancel:()=>{i=!0,null!==a&&(window.clearTimeout(a),a=null)}}}function Ur(e){const t=new URLSearchParams(e);return Array.from(t.entries()).reduce((e,[t,a])=>a?{...e,[t]:a}:e,{})}function Tr(e){try{return decodeURIComponent(e)}catch{return e}}function Pr(e,t,a){const i=`#/${t}`;return e.startsWith(i)?e.slice(i.length).replace(/^\//,"").split("/").map(e=>(e.endsWith("]")?e.slice(0,-1):e).split("[")).reduce((e,[t,i])=>i?"group"===t&&a.includes(i)?{...e,group:i}:("page"===t||"paged"===t)&&Number(i)>0?{...e,page:Number(i)}:("per_page"===t||"limit"===t)&&Number(i)>0?{...e,perPage:Number(i)}:"sort_by"===t||"orderby"===t?{...e,orderby:i}:"sort_order"!==t&&"order"!==t||"asc"!==i&&"desc"!==i?"search"===t?{...e,search:Tr(i)}:"filter"===t?{...e,filter:Ur(i)}:e:{...e,order:i}:e,{}):{}}function Rr(e,t,a,i,s){return`#/${e}${[["group","all"!==t?t:void 0],["filter",new URLSearchParams(i).toString()||void 0],["search",a.search?encodeURIComponent(a.search):void 0],["page",a.page&&1!==a.page?a.page:void 0],["limit",a.perPage&&a.perPage!==s.perPage?a.perPage:void 0],["sort_by",a.sort?.field&&a.sort.field!==s.sort?a.sort.field:void 0],["sort_order",a.sort?.direction&&a.sort.direction!==s.order?a.sort.direction:void 0]].reduce((e,[t,a])=>a?`${e}/${t}[${a}]`:e,"")}`}const Dr=Number(window.mailpoet_listing_per_page),Fr=["all","trash"],Or=["all","draft","scheduled","sending","sent","trash"],Mr=["all","active","draft","trash"],Lr=["all","sending","sent","trash"];function $r(e){if(e&&"object"==typeof e){const t=e;return{...t,status:"string"==typeof t.status?t.status:""}}return{status:""}}const Br={one:(0,p.__)("1 email was moved to the trash.","mailpoet"),many:(0,p.__)("%1$d emails were moved to the trash.","mailpoet")},Wr={one:(0,p.__)("1 email was permanently deleted.","mailpoet"),many:(0,p.__)("%1$d emails were permanently deleted.","mailpoet")},Vr={one:(0,p.__)("1 email has been restored from the Trash.","mailpoet"),many:(0,p.__)("%1$d emails have been restored from the Trash.","mailpoet")};function qr({type:e,baseUrl:t,parentId:a,fields:i,defaultFields:s,itemActions:n,defaultSort:o,emptyState:l,supportsExportStats:d=!1,supportedGroups:c=Fr,getItemId:u,onItemsLoaded:h}){const _=(0,Ue.zy)(),f=(0,Ue.Zp)(),b=(0,r.useMemo)(()=>Pr(window.location.hash,t,[...c]),[t,c]),[x,y]=(0,r.useState)(b.group??"all"),[w,j]=(0,r.useState)(b.filter??{}),[k,N]=(0,r.useState)([]),[C,E]=(0,r.useState)({method:null,log:{status:""}}),[I]=(0,r.useState)(()=>({type:"table",perPage:Dr,page:1,sort:o,fields:s,titleField:i[0]?.id,showTitle:!0})),A=(0,r.useCallback)(()=>(0,$e.Aq)(`newsletters-${e}`,I,i),[I,i,e]),[U]=(0,r.useState)(()=>{const e=A();return{...e,perPage:b.perPage??e.perPage,page:b.page??1,search:b.search,sort:{field:b.orderby??e.sort?.field??o.field,direction:b.order??e.sort?.direction??o.direction}}}),T=(0,r.useCallback)((t,i)=>{const s={...t,group:x,filter:w,type:e};return void 0!==a&&(s.parent_id=a),(0,An.bL)(s,i)},[w,x,a,e]),{view:P,setView:R,onChangeView:D,items:F,meta:O,filters:M,groups:L,isLoading:$,error:B,clearError:W,refresh:V}=(0,$e.i7)({initialView:U,load:T});(0,r.useEffect)(()=>(0,An.$0)(e=>{const t=$r(e.mta_log),a={meta:{...e,mta_log:t}};(0,Ai.DP)(a),(0,Ai.tQ)(a),E({method:e.mta_method??null,log:t})}),[]),(0,r.useEffect)(()=>{h?.(F)},[F,h]),(0,r.useEffect)(()=>{const e=()=>{0===k.length&&V()};return Tt()(document).on("heartbeat-tick.mailpoet-listing",e),()=>{Tt()(document).off("heartbeat-tick.mailpoet-listing",e)}},[V,k.length]),(0,r.useEffect)(()=>{const e=A(),a=Rr(t,x,P,w,{sort:e.sort?.field??o.field,order:e.sort?.direction??o.direction,perPage:e.perPage??Dr});window.location.hash!==a&&window.history.replaceState(null,"",a)},[t,o.direction,o.field,w,A,x,P]),(0,r.useEffect)(()=>{const e=()=>{const e=Pr(window.location.hash,t,[...c]);y(e.group??"all"),j(e.filter??{}),N([]),W();const a=A();R(t=>({...t,page:e.page??1,perPage:e.perPage??a.perPage,search:e.search??"",sort:{field:e.orderby??a.sort?.field??o.field,direction:e.order??a.sort?.direction??o.direction}}))};return window.addEventListener("hashchange",e),()=>window.removeEventListener("hashchange",e)},[t,W,o.direction,o.field,A,R,c]);const q=(0,r.useMemo)(()=>({type:e,group:x,filter:w,search:P.search??"",parent_id:a}),[w,x,a,e,P.search]),z=(0,r.useCallback)(e=>{m.U.Notice.error(e.message||(0,p.__)("The action could not be completed. Please try again.","mailpoet"),{scroll:!0})},[]),H=(0,r.useCallback)(async(e,t,a=!1,i={},s=q)=>{if(0!==t.length||a)try{const n=await(0,An.XE)(e,{...s,selection:t,select_all:a},i);if(N([]),"export_stats"===e){const e="string"==typeof i.format?i.format:"csv";return void function(e,t){e.task_id?(m.U.Notice.success((0,p.__)("Export queued. The download will start automatically when it is ready.","mailpoet"),{timeout:6e3}),Ar(e.task_id,{onComplete:e=>{e.exportFileURL?(m.U.trackEvent("Email statistics export completed",{"File Format":t,"Export Type":"bulk"}),window.location.href=e.exportFileURL):m.U.Notice.error((0,p.__)("The export file could not be generated.","mailpoet"),{scroll:!0})},onError:e=>{m.U.Notice.error(e,{scroll:!0})}})):m.U.Notice.error((0,p.__)("Could not start the export.","mailpoet"),{scroll:!0})}(n.data,e)}!function(e,t){const a=function(e){return e.toLocaleString()}(t);"trash"===e?m.U.Notice.success(1===t?Br.one:Br.many.replace("%1$d",a)):"delete"===e?m.U.Notice.success(1===t?Wr.one:Wr.many.replace("%1$d",a)):"restore"===e&&m.U.Notice.success(1===t?Vr.one:Vr.many.replace("%1$d",a))}(e,n.data.count),V()}catch(e){z(e)}},[z,q,V]),G=(0,r.useCallback)(async(e,t,a={})=>{const i=t.map(e=>Number(e.id)).filter(e=>Number.isFinite(e));await H(e,i,!1,a)},[H]),Y=(0,r.useCallback)(e=>{N([]),D(e)},[D]),K=(0,$e.wh)(`newsletters-${e}`,P,Y),Z=(0,r.useCallback)(e=>{N(e)},[]),J=(0,r.useCallback)(e=>{e!==x&&(y(e),N([]),W(),R(e=>({...e,page:1})))},[W,x,R]),Q=(0,r.useCallback)((e,t)=>{j(a=>{const i={...a};return t?i[e]=t:delete i[e],i}),N([]),R(e=>({...e,page:1}))},[R]),X=(0,r.useMemo)(()=>{const e={all:null,trash:null};return c.forEach(t=>{e[t]=null}),(L??[]).forEach(t=>{t.name in e&&(e[t.name]=t.count)}),e},[L,c]);(0,r.useEffect)(()=>{"trash"!==x||$||B||0!==X.trash||P.search||0!==Object.keys(w).length||(y("all"),N([]),R(e=>({...e,page:1})))},[w,x,X.trash,$,B,R,P.search]);const ee=(0,r.useMemo)(()=>(L??[]).filter(e=>e.name in X&&!("trash"===e.name&&0===e.count&&"trash"!==x)),[x,X,L]),te=(0,r.useMemo)(()=>({refresh:V,navigate:e=>f(e),location:{pathname:_.pathname}}),[_.pathname,f,V]),ae=(0,r.useMemo)(()=>{const e=[{id:"trash",label:(0,p.__)("Move to trash","mailpoet"),context:"list",supportsBulk:!0,isEligible:()=>"trash"!==x,callback:e=>{G("trash",e)}},{id:"restore",label:(0,p.__)("Restore","mailpoet"),context:"list",supportsBulk:!0,isEligible:()=>"trash"===x,callback:e=>{G("restore",e)}},{id:"delete",label:(0,p.__)("Delete permanently","mailpoet"),context:"list",supportsBulk:!0,isEligible:()=>"trash"===x,callback:e=>{G("delete",e)}}];return d&&e.push({id:"export_stats",label:(0,p.__)("Export statistics","mailpoet"),context:"list",supportsBulk:!0,isEligible:e=>"trash"!==x&&"sent"===e.status,callback:e=>{G("export_stats",e,{format:"csv"})}}),e},[x,G,d]),ie=(0,r.useMemo)(()=>[...n?n(te):[],...ae],[te,ae,n]),se=(0,r.useMemo)(()=>({totalItems:O.count,totalPages:O.pages}),[O]),ne=(0,r.useCallback)(()=>{H("delete",[],!0,{},{type:e,group:"trash",parent_id:a})},[H,a,e]),re=(0,r.useMemo)(()=>Object.keys(M).filter(e=>{const t=M[e]??[];return!(0===t.length||1===t.length&&!t[0].value)}),[M]);return(0,r.useMemo)(()=>{const{all:e,trash:t}=X;return null!==e&&null!==t&&0===e&&0===t},[X])&&l?(0,g.jsx)(g.Fragment,{children:l(0)}):(0,g.jsxs)("div",{children:[C.method&&(0,g.jsx)(S,{mtaMethod:C.method,mtaLog:C.log}),B&&(0,g.jsx)(Fe.A,{status:"error",onRemove:W,children:"Failed to load data."===B?(0,p.__)("Failed to load emails.","mailpoet"):B}),(0,g.jsx)("div",{className:"mailpoet-categories mailpoet-dataviews__tabs mailpoet-newsletters-dataviews__tabs",children:(0,g.jsx)("div",{className:"components-tab-panel__tabs",role:"tablist",children:ee.map(e=>{const t=v()("components-button","components-tab-panel__tabs-item",`mailpoet-dataviews-group-${e.name}`,{"is-active":e.name===x});return(0,g.jsxs)("a",{href:"#",role:"tab","aria-selected":e.name===x,className:t,"data-automation-id":`filters_${e.name}`,onClick:t=>{t.preventDefault(),J(e.name)},children:[(0,g.jsx)("span",{"data-title":e.label,children:e.label}),Number(e.count)>0&&(0,g.jsx)("span",{className:"count",children:Number(e.count).toLocaleString()})]},e.name)})})}),(0,g.jsx)("div",{className:"mailpoet-dataviews mailpoet-newsletters-dataviews mailpoet-listing","data-automation-id":`newsletters_listing_${e}`,children:(0,g.jsxs)(Le.A,{data:F,fields:i,view:P,onChangeView:K,actions:ie,paginationInfo:se,defaultLayouts:{table:{}},getItemId:e=>u?u(e):String(e.id),selection:k,onChangeSelection:Z,isLoading:$,empty:(0,g.jsx)("p",{children:P.search?(0,p.__)("No emails found.","mailpoet"):(0,p.__)("Nothing here yet! But, don't fret - there's no reason to get upset. Pretty soon, you’ll be sending emails faster than a turbo-jet.","mailpoet")}),children:[(0,g.jsxs)("div",{className:"mailpoet-dataviews__toolbar mailpoet-newsletters-dataviews__toolbar",children:[(0,g.jsx)(Le.A.Search,{label:(0,p.__)("Search","mailpoet")}),(re.length>0||"trash"===x)&&(0,g.jsxs)("div",{className:"mailpoet-listing-filters",children:[re.map(e=>(0,g.jsx)(Be.Select,{isMinWidth:!0,dimension:"small",name:e,value:w[e]??"",automationId:`listing_filter_${e}`,onChange:t=>Q(e,t.currentTarget.value),children:M[e].map(e=>(0,g.jsx)("option",{value:e.value,children:e.label},`filter-option-${e.value}`))},`filter-${e}`)),"trash"===x&&(0,g.jsx)(ge.Ay,{variant:"secondary",size:"compact","data-automation-id":"empty_trash",onClick:ne,children:(0,p.__)("Empty Trash","mailpoet")})]}),(0,g.jsx)("div",{className:"mailpoet-dataviews__toolbar-end",children:(0,g.jsx)(Le.A.ViewConfig,{})})]}),(0,g.jsx)(Le.A.Layout,{}),(0,g.jsx)(Le.A.Footer,{})]})})]})}const zr=m.U.trackingConfig.emailTrackingEnabled;function Hr(){const[e,t]=(0,r.useState)(null),a=(0,r.useRef)(null),i=(0,r.useCallback)(e=>{t(e),m.U.trackEvent("Emails > Share modal opened")},[]),s=(0,r.useCallback)(()=>t(null),[]),n=(0,r.useCallback)(async e=>{try{const i=await m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"newsletters",action:"updateShareVisibility",data:{id:e.id,share_visibility:vr}});t(i.data),a.current?.(),m.U.trackEvent("Emails > Share email made public")}catch(e){const t=e;t.errors&&t.errors.length>0&&m.U.Notice.showApiErrorNotice(t,{scroll:!0})}},[]),l=(0,r.useCallback)(async(e,t)=>{try{await m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"newsletters",action:"updateShareVisibility",data:{id:e.id,share_visibility:"private"}}),t(),m.U.Notice.success((0,p.__)('Email "%1$s" is now private.',"mailpoet").replace("%1$s",(0,Me.Zn)(e.campaign_name||e.subject))),m.U.trackEvent("Emails > Share email made private")}catch(e){const t=e;t.errors&&t.errors.length>0&&m.U.Notice.showApiErrorNotice(t,{scroll:!0})}},[]),[d,c]=(0,r.useState)(void 0),[u,h]=(0,r.useState)({status:""});(0,r.useEffect)(()=>(0,An.$0)(e=>{c(e.current_time||void 0),h($r(e.mta_log))}),[]);const _=(0,r.useMemo)(()=>function(e,t={status:""}){return[{id:"name",label:(0,p.__)("Subject","mailpoet"),type:"text",enableSorting:!0,enableGlobalSearch:!0,getValue:({item:e})=>e.campaign_name||e.subject,render:({item:e})=>{const t=e.queue&&e.queue.newsletter_rendered_subject||e.subject;return(0,g.jsx)("a",{className:"mailpoet-listing-title",href:"#","data-automation-id":`listing_item_${e.id}`,onClick:t=>{t.preventDefault(),(0,Ai.$U)(e)},children:e.campaign_name?(0,g.jsxs)(g.Fragment,{children:[e.campaign_name,(0,g.jsx)("br",{}),(0,g.jsx)("span",{className:"mailpoet-listing-subtitle",children:t})]}):t})}},{id:"status",label:(0,p.__)("Status","mailpoet"),enableSorting:!1,enableGlobalSearch:!1,render:({item:e})=>(0,g.jsx)(rr,{newsletter:e,mailerLog:t})},{id:"segments",label:(0,p.__)("Lists","mailpoet"),enableSorting:!1,enableGlobalSearch:!1,render:({item:e})=>(0,g.jsxs)(o.ErrorBoundary,{children:[(0,g.jsx)(er.vC,{segments:e.segments,dimension:"large"}),(0,g.jsx)(er.y,{newsletter:e,dimension:"large"})]})},...zr?[{id:"statistics",label:(0,p.__)("Clicked, Opened","mailpoet"),enableSorting:!1,enableGlobalSearch:!1,render:({item:t})=>(0,g.jsx)(pr,{newsletter:t,currentTime:e})}]:[],{id:"sent_at",label:(0,p.__)("Sent on","mailpoet"),type:"datetime",enableSorting:!0,enableGlobalSearch:!1,render:({item:e})=>{const t=(0,ar.nO)(e.queue);return e.sent_at||t?(0,g.jsxs)(g.Fragment,{children:[e.sent_at&&(0,g.jsxs)(g.Fragment,{children:[m.U.Date.short(e.sent_at),(0,g.jsx)("br",{}),m.U.Date.time(e.sent_at)]}),t&&(0,g.jsx)(lr,{newsletterId:e.id,sent:"sent"===e.status})]}):null}}]}(d,u),[d,u]),f=(0,r.useCallback)(e=>(0,Ai.pE)([{id:"preview",label:(0,p.__)("Preview","mailpoet"),context:"single",supportsBulk:!1,callback:e=>{const t=e[0];t?.preview_url&&window.open(String(t.preview_url),"_blank","noopener,noreferrer")}},{id:"edit",label:(0,p.__)("Edit","mailpoet"),context:"single",isPrimary:!0,supportsBulk:!1,callback:e=>{e[0]&&(0,Ai.$U)(e[0])}},{id:"share",label:(0,p.__)("Share","mailpoet"),context:"single",isPrimary:!0,supportsBulk:!1,isEligible:e=>Boolean(e.is_share_supported),callback:t=>{t[0]&&(a.current=e.refresh,i(t[0]))}},{id:"make-private",label:(0,p.__)("Make private","mailpoet"),context:"single",supportsBulk:!1,isEligible:e=>Boolean(e.can_share)&&e.effective_share_visibility===vr,callback:t=>{t[0]&&l(t[0],e.refresh)}},{id:"duplicate",label:(0,p.__)("Duplicate","mailpoet"),context:"single",supportsBulk:!1,callback:t=>{const a=t[0];a&&(async()=>{try{const t=await(0,An.r3)(Number(a.id));m.U.Notice.success((0,p.__)('Email "%1$s" has been duplicated.',"mailpoet").replace("%1$s",(0,Me.Zn)(t.data.subject))),e.refresh()}catch(e){const t=e;m.U.Notice.error(t.message||(0,p.__)("The action could not be completed.","mailpoet"),{scroll:!0})}})()}}],e.navigate),[l,i]),b=zr&&!function(){const e=m.U.capabilities?.detailedAnalytics;return!e||e.isRestricted}();return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(qr,{type:"standard",baseUrl:"standard",fields:_,defaultFields:["status","segments",...zr?["statistics"]:[],"sent_at"],defaultSort:{field:"sent_at",direction:"desc"},itemActions:f,supportsExportStats:b,supportedGroups:Or,emptyState:()=>(0,g.jsx)(yi,{filter:e=>"standard"===e.slug,hideScreenOptions:!1})}),e&&(0,g.jsx)(Ir,{newsletter:e,onClose:s,onMakePublic:()=>{n(e)}})]})}Hr.displayName="NewsletterListStandard";const Gr=(0,o.withBoundary)(Hr);var Yr=a(76074);function Kr(){const[e,t]=(0,r.useState)({}),a=(0,r.useRef)(null),i=(0,r.useCallback)((e,i)=>{const s=String(e.id),n=i?"active":"draft";t(e=>({...e,[s]:n})),(async()=>{try{"active"===(await(0,An.M4)(Number(e.id),n)).data.status&&m.U.Notice.success((0,p.__)("Your post notification is now active!","mailpoet")),a.current?.()}catch(a){t(t=>({...t,[s]:"active"===e.status?"active":"draft"})),m.U.Notice.error(a.message||(0,p.__)("Could not update the post notification status.","mailpoet"))}})()},[]),s=(0,r.useCallback)(e=>{t(t=>{const a=Object.keys(t);if(0===a.length)return t;const i={};return a.forEach(a=>{const s=e.find(e=>String(e.id)===a);s&&s.status===t[a]||(i[a]=t[a])}),Object.keys(i).length===a.length?t:i})},[]),n=(0,r.useMemo)(()=>function(e,t){return[{id:"subject",label:(0,p.__)("Subject","mailpoet"),type:"text",enableSorting:!0,enableGlobalSearch:!0,render:({item:e})=>(0,g.jsx)("a",{className:"mailpoet-listing-title",href:m.U.getActiveEmailEditorUrl(e),"data-automation-id":`listing_item_${e.id}`,onClick:t=>{t.preventDefault(),(0,Ai.$U)(e)},children:e.subject})},{id:"settings",label:(0,p.__)("Settings","mailpoet"),enableSorting:!1,enableGlobalSearch:!1,render:({item:e})=>function(e){if(!e.segments||0===e.segments.length)return(0,g.jsx)(Ae.Link,{className:"mailpoet-listing-error",to:`/send/${e.id}`,children:(0,p.__)("You need to select a list to send to.","mailpoet")});const t=b()((0,p.__)("Send to %1$s","mailpoet"),"%1$s",(t,a)=>(0,g.jsxs)(r.Fragment,{children:[(0,g.jsx)(er.vC,{segments:e.segments},`segment-${a}`),(0,g.jsx)(er.y,{newsletter:e},`filter-segment-${a}`)]},a)),a=e.options??{},i=(e,t)=>{if(!e||void 0===t)return"";const a=e[t];return null!=a?String(a):""},s=zs(m.U.wpWeekStartsOn),n=Hs(m.U.wpWeekStartsOn);let o="";switch(a.intervalType){case"daily":o=(0,p.__)("Daily at %1$s","mailpoet").replace("%1$s",i(Os,a.timeOfDay));break;case"weekly":o=(0,p.__)("Weekly on %1$s at %2$s","mailpoet").replace("%1$s",Ks(a.weekDay??"",Ms,s,n)).replace("%2$s",i(Os,a.timeOfDay));break;case"monthly":o=(0,p.__)("Monthly on the %1$s at %2$s","mailpoet").replace("%1$s",Ks(a.monthDay??"",Ls,Bs)).replace("%2$s",i(Os,a.timeOfDay));break;case"nthWeekDay":o=(0,p.__)("Every %1$s %2$s of the month at %3$s","mailpoet").replace("%1$s",i($s,a.nthWeekDay)).replace("%2$s",i(Ms,a.weekDay)).replace("%3$s",i(Os,a.timeOfDay));break;case"immediately":o=(0,p.__)("Immediately","mailpoet");break;default:o="Invalid sending frequency"}return(0,g.jsxs)("span",{children:[t,(0,g.jsxs)("div",{className:"mailpoet-listing-schedule",children:[(0,g.jsx)("div",{className:"mailpoet-listing-schedule-icon",children:(0,g.jsx)(Yr.x,{})}),o]})]})}(e)},{id:"history",label:(0,p.__)("History","mailpoet"),enableSorting:!1,enableGlobalSearch:!1,render:({item:e})=>0===Number(e.children_count??0)?(0,g.jsx)("span",{className:"mailpoet-listing-status-unknown mailpoet-font-extra-small mailpoet-listing-notification-status",children:(0,p.__)("Not sent yet","mailpoet")}):(0,g.jsx)(Ae.Link,{className:"mailpoet-nowrap","data-automation-id":`history-${e.id}`,to:`/notification/history/${e.id}`,children:(0,g.jsx)(Ge.$,{className:"mailpoet-hide-on-mobile",dimension:"small",children:(0,p.__)("View history","mailpoet")})})},{id:"status",label:(0,p.__)("Status","mailpoet"),enableSorting:!1,enableGlobalSearch:!1,render:({item:a})=>{const i=t[String(a.id)]??a.status;return(0,g.jsx)(rs.l,{className:"mailpoet-listing-status-toggle",onCheck:t=>{e(a,t)},"data-id":a.id,dimension:"small",checked:"active"===i})}},{id:"updated_at",label:(0,p.__)("Last modified on","mailpoet"),type:"datetime",enableSorting:!0,enableGlobalSearch:!1,render:({item:e})=>e.updated_at?(0,g.jsxs)(g.Fragment,{children:[m.U.Date.short(e.updated_at),(0,g.jsx)("br",{}),m.U.Date.time(e.updated_at)]}):null}]}(i,e),[i,e]),o=(0,r.useCallback)(e=>(a.current=e.refresh,[{id:"preview",label:(0,p.__)("Preview","mailpoet"),context:"single",supportsBulk:!1,callback:e=>{const t=e[0];t?.preview_url&&window.open(String(t.preview_url),"_blank","noopener,noreferrer")}},{id:"edit",label:(0,p.__)("Edit","mailpoet"),context:"single",isPrimary:!0,supportsBulk:!1,callback:e=>{e[0]&&(0,Ai.$U)(e[0])}},{id:"duplicate",label:(0,p.__)("Duplicate","mailpoet"),context:"single",supportsBulk:!1,callback:t=>{const a=t[0];a&&(async()=>{try{const t=await(0,An.r3)(Number(a.id));m.U.Notice.success((0,p.__)('Email "%1$s" has been duplicated.',"mailpoet").replace("%1$s",(0,Me.Zn)(t.data.subject))),e.refresh()}catch(e){const t=e;m.U.Notice.error(t.message||(0,p.__)("The action could not be completed.","mailpoet"),{scroll:!0})}})()}}]),[]);return(0,g.jsx)(qr,{type:"notification",baseUrl:"notification",fields:n,defaultFields:["settings","history","status","updated_at"],defaultSort:{field:"updated_at",direction:"desc"},itemActions:o,onItemsLoaded:s,supportedGroups:Mr,emptyState:()=>(0,g.jsx)(yi,{filter:e=>"notification"===e.slug,hideScreenOptions:!1})})}Kr.displayName="NewsletterListNotification";const Zr=(0,o.withBoundary)(Kr),Jr=m.U.trackingConfig.emailTrackingEnabled;function Qr(){const[e,t]=(0,r.useState)({}),a=(0,r.useRef)(null),i=(0,r.useCallback)((e,i)=>{const s=String(e.id),n=i?"active":"draft";t(e=>({...e,[s]:n})),(async()=>{try{"active"===(await(0,An.M4)(Number(e.id),n)).data.status&&m.U.Notice.success((0,p.__)("Your Re-engagement Email is now activated!","mailpoet")),a.current?.()}catch(a){t(t=>({...t,[s]:"active"===e.status?"active":"draft"})),m.U.Notice.error(a.message||(0,p.__)("Could not update the re-engagement email status.","mailpoet"))}})()},[]),s=(0,r.useCallback)(e=>{t(t=>{const a=Object.keys(t);if(0===a.length)return t;const i={};return a.forEach(a=>{const s=e.find(e=>String(e.id)===a);s&&s.status===t[a]||(i[a]=t[a])}),Object.keys(i).length===a.length?t:i})},[]),n=(0,r.useMemo)(()=>function(e,t){return[{id:"subject",label:(0,p.__)("Subject","mailpoet"),type:"text",enableSorting:!0,enableGlobalSearch:!0,render:({item:e})=>(0,g.jsx)("a",{className:"mailpoet-listing-title",href:m.U.getActiveEmailEditorUrl(e),"data-automation-id":`listing_item_${e.id}`,onClick:t=>{t.preventDefault(),(0,Ai.$U)(e)},children:e.subject})},{id:"settings",label:(0,p.__)("Settings","mailpoet"),enableSorting:!1,enableGlobalSearch:!1,render:({item:e})=>function(e){if(!e.segments||0===e.segments.length)return(0,g.jsx)(Ae.Link,{className:"mailpoet-listing-error",to:`/send/${e.id}`,children:(0,p.__)("You need to select a list to send to.","mailpoet")});const t=b()((0,p.__)("Send to %1$s","mailpoet"),"%1$s",(t,a)=>(0,g.jsxs)(r.Fragment,{children:[(0,g.jsx)(er.vC,{segments:e.segments},`segment-${a}`),(0,g.jsx)(er.y,{newsletter:e},`filter-segment-${a}`)]},a)),a=e.options??{},i=Number(a.afterTimeNumber??0),s="weeks"!==a.afterTimeType;let n=s?(0,p._x)("month",'month in the sentence "1 month after inactivity"',"mailpoet"):(0,p._x)("week",'week in the sentence "1 week after inactivity"',"mailpoet");i>1&&(n=s?(0,p._x)("months",'months in the sentence "5 months after inactivity"',"mailpoet"):(0,p._x)("weeks",'weeks in the sentence "5 weeks after inactivity"',"mailpoet"));const o=(0,p._x)("{$count} {$frequency} after inactivity",'example: "5 months after inactivity"',"mailpoet").replace("{$count}",String(i)).replace("{$frequency}",n);return(0,g.jsxs)("span",{children:[t,(0,g.jsxs)("div",{className:"mailpoet-listing-schedule",children:[(0,g.jsx)("div",{className:"mailpoet-listing-schedule-icon",children:(0,g.jsx)(Yr.x,{})}),o]})]})}(e)},...Jr?[{id:"statistics",label:(0,p.__)("Clicked, Opened","mailpoet"),enableSorting:!1,enableGlobalSearch:!1,render:({item:e})=>{const t=Number(e.total_sent??0);return(0,g.jsx)(pr,{newsletter:e,isSent:t>0&&!!e.statistics})}}]:[],{id:"status",label:(0,p.__)("Status","mailpoet"),enableSorting:!1,enableGlobalSearch:!1,render:({item:a})=>{const i=Number(a.total_sent??0),s=(0,p._x)("%1$d sent","number of welcome emails sent","mailpoet").replace("%1$d",i.toLocaleString()),n=t[String(a.id)]??a.status;return(0,g.jsxs)("div",{children:[(0,g.jsx)(rs.l,{className:"mailpoet-listing-status-toggle",onCheck:t=>{e(a,t)},"data-id":a.id,dimension:"small",checked:"active"===n}),(0,g.jsx)("p",{className:"mailpoet-listing-stats-description",children:(0,g.jsx)(Ae.Link,{to:`/sending-status/${a.id}`,"data-automation-id":`sending_status_${a.id}`,children:s})})]})}},{id:"updated_at",label:(0,p.__)("Last modified on","mailpoet"),type:"datetime",enableSorting:!0,enableGlobalSearch:!1,render:({item:e})=>e.updated_at?(0,g.jsxs)(g.Fragment,{children:[m.U.Date.short(e.updated_at),(0,g.jsx)("br",{}),m.U.Date.time(e.updated_at)]}):null}]}(i,e),[i,e]),o=(0,r.useCallback)(e=>(a.current=e.refresh,(0,Ai.pE)([{id:"preview",label:(0,p.__)("Preview","mailpoet"),context:"single",supportsBulk:!1,callback:e=>{const t=e[0];t?.preview_url&&window.open(String(t.preview_url),"_blank","noopener,noreferrer")}},{id:"duplicate",label:(0,p.__)("Duplicate","mailpoet"),context:"single",supportsBulk:!1,callback:t=>{const a=t[0];a&&(async()=>{try{const t=await(0,An.r3)(Number(a.id));m.U.Notice.success((0,p.__)('Email "%1$s" has been duplicated.',"mailpoet").replace("%1$s",(0,Me.Zn)(t.data.subject))),e.refresh()}catch(e){m.U.Notice.error(e.message||(0,p.__)("The action could not be completed.","mailpoet"),{scroll:!0})}})()}},{id:"edit",label:(0,p.__)("Edit","mailpoet"),context:"single",isPrimary:!0,supportsBulk:!1,callback:e=>{e[0]&&(0,Ai.$U)(e[0])}}],e.navigate)),[]);return(0,g.jsx)(qr,{type:"re_engagement",baseUrl:"re_engagement",fields:n,defaultFields:["settings",...Jr?["statistics"]:[],"status","updated_at"],defaultSort:{field:"updated_at",direction:"desc"},itemActions:o,onItemsLoaded:s,supportedGroups:Mr,emptyState:()=>(0,g.jsx)(yi,{filter:e=>"re_engagement"===e.slug,hideScreenOptions:!1})})}Qr.displayName="NewsletterListReEngagement";const Xr=(0,o.withBoundary)(Qr),eo=m.U.trackingConfig.emailTrackingEnabled;function to({parentId:e}){const[t,a]=(0,r.useState)(void 0),[i,s]=(0,r.useState)({status:""});(0,r.useEffect)(()=>(0,An.$0)(e=>{a(e.current_time||void 0),s($r(e.mta_log))}),[]);const n=(0,r.useMemo)(()=>function(e,t={status:""}){return[{id:"subject",label:(0,p.__)("Subject","mailpoet"),enableSorting:!1,enableGlobalSearch:!0,render:({item:e})=>{const t=e.queue&&e.queue.newsletter_rendered_subject||e.subject;return(0,g.jsx)("a",{className:"mailpoet-listing-title",href:e.preview_url,target:"_blank",rel:"noopener noreferrer","data-automation-id":`listing_item_${e.id}`,children:t})}},{id:"status",label:(0,p.__)("Status","mailpoet"),enableSorting:!1,enableGlobalSearch:!1,render:({item:e})=>(0,g.jsx)(rr,{newsletter:e,mailerLog:t})},{id:"segments",label:(0,p.__)("Lists","mailpoet"),enableSorting:!1,enableGlobalSearch:!1,render:({item:e})=>(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(er.vC,{segments:e.segments,dimension:"large"}),(0,g.jsx)(er.y,{newsletter:e,dimension:"large"})]})},...eo?[{id:"statistics",label:(0,p.__)("Clicked, Opened","mailpoet"),enableSorting:!1,enableGlobalSearch:!1,render:({item:t})=>(0,g.jsx)(pr,{newsletter:t,currentTime:e})}]:[],{id:"sent_at",label:(0,p.__)("Sent on","mailpoet"),type:"datetime",enableSorting:!0,enableGlobalSearch:!1,render:({item:e})=>e.sent_at?(0,g.jsxs)(g.Fragment,{children:[m.U.Date.short(e.sent_at),(0,g.jsx)("br",{}),m.U.Date.time(e.sent_at)]}):null}]}(t,i),[t,i]),o=(0,r.useMemo)(()=>e=>(0,Ai.pE)([{id:"preview",label:(0,p.__)("Preview","mailpoet"),context:"single",supportsBulk:!1,callback:e=>{const t=e[0];t?.preview_url&&window.open(String(t.preview_url),"_blank","noopener,noreferrer")}}],e.navigate),[]);return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("p",{children:(0,g.jsx)(Ae.Link,{className:"mailpoet-button button button-secondary button-small",to:"/notification",children:(0,p.__)("Back to Post notifications","mailpoet")})}),(0,g.jsx)(qr,{type:"notification_history",baseUrl:`notification/history/${e}`,parentId:Number(e),fields:n,defaultFields:["status","segments",...eo?["statistics"]:[],"sent_at"],defaultSort:{field:"sent_at",direction:"desc"},itemActions:o,supportedGroups:Lr})]})}to.displayName="NewsletterListNotificationHistory";const ao=(0,o.withBoundary)(to);(0,$e.tN)(window.mailpoet_newsletters_api);const io=new Map;const so=Number(window.mailpoet_listing_per_page),no=["all","sent","failed","unprocessed"],ro={field:"failed",direction:"desc"},oo={unprocessed:(0,p.__)("Unprocessed","mailpoet"),sent:(0,p.__)("Sent","mailpoet"),failed:(0,p.__)("Failed","mailpoet")},lo=(0,p.__)("Sending status","mailpoet");function co({newsletter:e}){return e.id&&e.subject&&e.sent?(0,g.jsx)("p",{children:(0,g.jsx)(Ae.Link,{to:`/stats/${e.id}`,children:e.subject})}):null}function mo(){const e=(0,Ue.g)(),t=Number(e.id),a=`sending-status/${e.id}`,[i,s]=(0,r.useState)({id:e.id??"",subject:"",sent:!1});(0,r.useEffect)(()=>{m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"newsletters",action:"get",data:{id:t}}).done(t=>s({id:e.id??"",subject:t.data.subject,sent:null!==t.data.sent_at})).fail(e=>m.U.Notice.showApiErrorNotice(e))},[t,e.id]);const n=(0,r.useMemo)(()=>Pr(window.location.hash,a,[...no]),[a]),[o,l]=(0,r.useState)(n.group??"all"),[d,c]=(0,r.useState)(!1),u=(0,r.useMemo)(()=>function(e){return[{id:"subscriberId",label:(0,p.__)("Subscriber","mailpoet"),type:"text",enableSorting:!0,enableGlobalSearch:!0,getValue:({item:e})=>e.email,render:({item:e})=>(0,g.jsxs)("div",{"data-automation-id":`name_${e.taskId}_${e.subscriberId}`,children:[(0,g.jsx)("a",{className:"mailpoet-listing-title",href:`admin.php?page=mailpoet-subscribers#/edit/${e.subscriberId}`,children:e.email}),(0,g.jsx)("div",{className:"mailpoet-listing-subtitle",children:`${e.firstName} ${e.lastName}`})]})},{id:"failed",label:lo,enableSorting:!0,enableGlobalSearch:!1,render:({item:e})=>{let t=oo.unprocessed;return e.processed&&(t=e.failed?oo.failed:oo.sent),(0,g.jsx)("span",{"data-automation-id":`status_${e.taskId}_${e.subscriberId}`,children:t})}},...e?[{id:"timezone",label:(0,p.__)("Time zone","mailpoet"),enableSorting:!1,enableGlobalSearch:!1,render:({item:e})=>(0,g.jsx)("span",{"data-automation-id":`timezone_${e.taskId}_${e.subscriberId}`,children:null!==e.timezone?(0,ar.ZW)(e.timezone,e.timezoneFallbackUsed):""})}]:[],{id:"error",label:(0,p.__)("Failure reason (if applicable)","mailpoet"),enableSorting:!1,enableGlobalSearch:!1,render:({item:e})=>(0,g.jsx)("span",{"data-automation-id":`error_${e.taskId}_${e.subscriberId}`,children:e.error??""})}]}(d),[d]),h=(0,r.useCallback)(()=>(0,$e.Aq)("sending-status",{type:"table",perPage:so,page:1,sort:ro,fields:["failed","error"],titleField:"subscriberId",showTitle:!0},u),[u]),[_]=(0,r.useState)(()=>{const e=h();return{...e,perPage:n.perPage??e.perPage,page:n.page??1,search:n.search,sort:{field:n.orderby??e.sort?.field??ro.field,direction:n.order??e.sort?.direction??ro.direction}}}),f=(0,r.useCallback)(async(e,a)=>{const i=await function(e,t,a){return function(e){let t=io.get(e);return t||(t=(0,$e.gU)((e=>`/mailpoet/v1/newsletters/${e}/sending-status`)(e)),io.set(e,t)),t}(e)(t,a)}(t,{...e,group:o},a),s={meta:{mta_log:i.mta_log&&"object"==typeof i.mta_log?i.mta_log:{},cron_accessible:i.cron_accessible}};return(0,Ai.DP)(s),(0,Ai.tQ)(s),i},[o,t]),{view:b,setView:x,onChangeView:y,items:w,meta:j,groups:S,isLoading:k,error:N,clearError:C,refresh:E}=(0,$e.i7)({initialView:_,load:f}),I=(0,$e.wh)("sending-status",b,y),A=(0,r.useRef)(!1);(0,r.useEffect)(()=>{A.current=!1,c(!1),x(e=>e.fields?.includes("timezone")?{...e,fields:e.fields.filter(e=>"timezone"!==e)}:e)},[t,x]),(0,r.useEffect)(()=>{if(A.current)return;if(!w.some(e=>null!==e.timezone))return;A.current=!0,c(!0);const e=(0,$e.yC)("sending-status");x(t=>{const a=t.fields??[];if(a.includes("timezone"))return t;if(e){if(!e.includes("timezone"))return t;const i=new Set([...a,"timezone"]);return{...t,fields:e.filter(e=>i.has(e))}}const i=a.indexOf("failed"),s=[...a];return s.splice(i>=0?i+1:s.length,0,"timezone"),{...t,fields:s}})},[w,x]),(0,r.useEffect)(()=>{const e=h(),t=Rr(a,o,b,{},{sort:e.sort?.field??ro.field,order:e.sort?.direction??ro.direction,perPage:e.perPage??so});window.location.hash!==t&&window.history.replaceState(null,"",t)},[a,h,o,b]),(0,r.useEffect)(()=>{const e=()=>{const e=Pr(window.location.hash,a,[...no]);l(e.group??"all"),C();const t=h();x(a=>({...a,page:e.page??1,perPage:e.perPage??t.perPage,search:e.search??"",sort:{field:e.orderby??t.sort?.field??ro.field,direction:e.order??t.sort?.direction??ro.direction}}))};return window.addEventListener("hashchange",e),()=>window.removeEventListener("hashchange",e)},[a,C,h,x]),(0,r.useEffect)(()=>{const e=()=>E();return Tt()(document).on("heartbeat-tick.mailpoet-sending-status",e),()=>{Tt()(document).off("heartbeat-tick.mailpoet-sending-status",e)}},[E]);const U=(0,r.useCallback)(e=>{e!==o&&(l(e),C(),x(e=>({...e,page:1})))},[C,o,x]),T=(0,r.useCallback)(e=>{(function(e,t,a){return(0,$e.J8)((e=>`/mailpoet/v1/newsletters/${e}/sending-status/resend`)(e),{task_id:t,subscriber_id:a})})(t,e.taskId,e.subscriberId).then(()=>E()).catch(e=>{m.U.Notice.error(e.message||(0,p.__)("The email could not be resent. Please try again.","mailpoet"),{scroll:!0})})},[t,E]),P=(0,r.useMemo)(()=>[{id:"resend",label:(0,p.__)("Resend","mailpoet"),context:"single",isPrimary:!0,supportsBulk:!1,isEligible:e=>Boolean(e.failed),callback:e=>{e[0]&&T(e[0])}}],[T]),R=(0,r.useMemo)(()=>(S??[]).filter(e=>no.includes(e.name)),[S]),D=(0,r.useMemo)(()=>({totalItems:j.count,totalPages:j.pages}),[j]),F=i.sent&&!k&&!N&&"all"===o&&!b.search&&0===j.count;return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("h1",{children:(0,p.__)("Sending status","mailpoet")}),(0,g.jsx)(co,{newsletter:i}),F&&(0,g.jsx)("p",{className:"mailpoet-notice mailpoet-notice-info",children:(0,Oe.A)((0,p.__)("Sending status data is no longer available. Per-subscriber records for this newsletter have been cleaned up. You can adjust the retention period in <link>Advanced settings</link>.","mailpoet"),{link:(0,g.jsx)("a",{href:"admin.php?page=mailpoet-settings#/advanced",children:" "})})}),N&&(0,g.jsx)(Fe.A,{status:"error",onRemove:C,children:"Failed to load data."===N?(0,p.__)("Failed to load the sending status.","mailpoet"):N}),(0,g.jsx)("div",{className:"mailpoet-categories mailpoet-dataviews__tabs",children:(0,g.jsx)("div",{className:"components-tab-panel__tabs",role:"tablist",children:R.map(e=>{const t=v()("components-button","components-tab-panel__tabs-item",`mailpoet-dataviews-group-${e.name}`,{"is-active":e.name===o});return(0,g.jsxs)("a",{href:"#",role:"tab","aria-selected":e.name===o,className:t,"data-automation-id":`filters_${e.name}`,onClick:t=>{t.preventDefault(),U(e.name)},children:[(0,g.jsx)("span",{"data-title":e.label,children:e.label}),Number(e.count)>0&&(0,g.jsx)("span",{className:"count",children:Number(e.count).toLocaleString()})]},e.name)})})}),(0,g.jsx)("div",{className:"mailpoet-dataviews mailpoet-listing","data-automation-id":"sending_status_listing",children:(0,g.jsxs)(Le.A,{data:w,fields:u,view:b,onChangeView:I,actions:P,paginationInfo:D,defaultLayouts:{table:{}},getItemId:e=>`${e.taskId}-${e.subscriberId}`,isLoading:k,empty:(0,g.jsx)("p",{children:(0,p.__)("No sending task found.","mailpoet")}),children:[(0,g.jsxs)("div",{className:"mailpoet-dataviews__toolbar",children:[(0,g.jsx)(Le.A.Search,{label:(0,p.__)("Search","mailpoet")}),(0,g.jsx)("div",{className:"mailpoet-dataviews__toolbar-end",children:(0,g.jsx)(Le.A.ViewConfig,{})})]}),(0,g.jsx)(Le.A.Layout,{}),(0,g.jsx)(Le.A.Footer,{})]})})]})}mo.displayName="SendingStatus";var uo=a(18488),po=a(65270),ho=a(38255),go=a.n(ho);function _o({installedDaysAgo:e,reviewRequestIllustrationUrl:t,username:a}){const i=Math.round(e/30),s=e>30?(0,p.sprintf)((0,p._n)("You’ve been using MailPoet for %d month now, and we would love to read your own review.","You’ve been using MailPoet for %d months now, and we would love to read your own review.",i,"mailpoet"),i):(0,p.sprintf)((0,p._n)("You’ve been using MailPoet for %d day now, and we would love to read your own review.","You’ve been using MailPoet for %d days now, and we would love to read your own review.",e,"mailpoet"),e);return(0,g.jsxs)("div",{className:"mailpoet_review_request",children:[(0,g.jsx)("img",{src:t,height:"280",width:"280",alt:""}),(0,g.jsx)("h2",{children:(0,p.__)("Thank you! Time to tell the world?","mailpoet")}),(0,g.jsx)("p",{children:(0,p.sprintf)((0,p.__)("%s, did you know that hundreds of WordPress users read the reviews on the plugin repository? They’re also a source of inspiration for our team.","mailpoet"),(0,Me.Zn)(a))}),(0,g.jsx)("p",{children:s}),(0,g.jsx)("p",{children:(0,g.jsx)("a",{href:"http://bit.ly/2Bi124o",target:"_blank",rel:"noopener noreferrer",className:"button button-primary",children:(0,p.__)("Rate us now","mailpoet")})}),(0,g.jsx)("p",{children:(0,g.jsx)("a",{id:"mailpoet_review_request_not_now",children:(0,p.__)("Not now")})})]})}const fo=(e=null)=>new Promise((t,a)=>{window.mailpoet_display_nps_poll&&window.mailpoet_3rd_party_libs_enabled?(In||(In=m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"analytics",action:"getTrackingData"})),In).then(({data:a})=>{((e,t)=>{let a;a=t||(window.mailpoet_display_nps_form?"EqOgKsgZd832Sz9w":window.mailpoet_is_new_user?"6L479eVPXk7pBn6S":"k0aJAsQAWI2ERyGv");const i={name:window.mailpoet_current_wp_user.user_nicename,email:window.mailpoet_current_wp_user.user_email,mailpoetVersion:window.mailpoet_version,mailpoetPremiumIsActive:window.mailpoet_premium_active,createdAt:e.installedAtIso,newslettersSent:e.newslettersSent,welcomeEmails:e.welcomeEmails,postnotificationEmails:e.postnotificationEmails,woocommerceEmails:e.woocommerceEmails,subscribers:e.subscribers,lists:e.lists,sendingMethod:e.sendingMethod,woocommerceIsInstalled:e.woocommerceIsInstalled,woocommerceVersion:e.woocommerceVersion,WordPressVersion:e.WordPressVersion,blockTheme:e.blockTheme,themeVersion:e.themeVersion,theme:e.theme};e.gutenbergVersion&&(i.gutenbergVersion=e.gutenbergVersion),e.wooCommerceVersion&&(i.wooCommerceVersion=e.wooCommerceVersion),go()({writeKey:a,userId:window.mailpoet_current_wp_user.ID+window.mailpoet_site_url,traits:i,events:{submit:e=>{e.rating>=9&&e.completed&&m.U.Modal.popup({width:800,template:po.renderToString(_o({username:window.mailpoet_current_wp_user_firstname||window.mailpoet_current_wp_user.user_login,reviewRequestIllustrationUrl:window.mailpoet_review_request_illustration_url,installedDaysAgo:window.mailpoet_installed_days_ago})),onInit:()=>{document.getElementById("mailpoet_review_request_not_now").addEventListener("click",()=>m.U.Modal.close())}})}}})})(a,e),t()}):a()}),bo=e=>function(t){return(0,r.useLayoutEffect)(()=>{fo().catch(()=>{})},[]),(0,g.jsx)(e,{...t})};function xo(){return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(Ke,{}),(0,g.jsx)(d.x,{}),(0,g.jsx)(qe.z,{heading:(0,p.__)("Emails","mailpoet"),children:(0,g.jsx)(Ae.Link,{id:"mailpoet-new-email",className:"page-title-action",to:"/new",onClick:()=>{m.U.trackEvent("Emails > Add New")},"data-automation-id":"new_email",children:(0,p.__)("Add new email","mailpoet")})})]})}function vo({children:e}){const t=(0,Ue.zy)();return null!==(0,Si.S)(t)||(e=>e.hash.match(/^#\/new/)||e.pathname.match(/^\/new/))(t)?null:e}function yo(){return(0,g.jsx)("style",{dangerouslySetInnerHTML:{__html:".wrap { margin: 0 !important; }"}})}vo.propTypes={children:Rt().node.isRequired};var wo=a(24836),jo=a(60879);const So=e=>{const t=e<.1?2:1;return m.U.Num.toLocaleFixed(e,t)},ko=e=>+(+e).toFixed(1);function No({newsletter:e,isWoocommerceActive:t}){const a=e.total_sent||0;let i=0,s=0,n=0,r=0,o=0;a>0&&(i=100*e.statistics.clicked/a,s=100*e.statistics.opened/a,n=100*e.statistics.machineOpened/a,r=100*e.statistics.unsubscribed/a,o=100*e.statistics.bounced/a);const l=So(i),d=So(s),c=So(n),u=So(r),h=So(o),_=a>=20&&e.statistics.opened>=5,f=e.statistics.unsubscribed>=5&&a>=100,x=e.statistics.bounced>=5&&a>=100,v=(0,ya.u)("opened",s)||"",y=(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)("div",{className:"mailpoet-statistics-value-small",children:[(0,g.jsxs)("span",{className:`mailpoet-statistics-value-number mailpoet-statistics-value-number-${v}`,children:[d,"% "]}),(0,p._x)("opened","Percentage of subscribers that opened a newsletter link","mailpoet")]}),_&&(0,g.jsx)(ya.f,{isInverted:!1,stat:"opened",rate:s,tooltipId:`opened-${e.id||"0"}`,tooltipPlace:"right"})]}),w=(0,g.jsxs)("div",{className:"mailpoet-statistics-value-small",children:[(0,g.jsxs)("span",{className:"mailpoet-statistics-value-number",children:[c,"% "]}),(0,p._x)("machine-opened","Percentage of newsletters that were opened by a machine","mailpoet"),(0,g.jsx)(ze.Tooltip,{tooltip:b()((0,p.__)("A machine-opened email is an email opened by a computer in the background without the user’s explicit request or knowledge. [link]Read more[/link]","mailpoet"),/\[link](.*?)\[\/link]/,e=>(0,g.jsx)("span",{style:{pointerEvents:"all"},children:(0,g.jsx)("a",{href:"https://kb.mailpoet.com/article/368-what-are-machine-opens",target:"_blank",rel:"noopener noreferrer",children:e},"kb-link")},"machine-opened-tooltip"))})]}),j=ko(r),S=f?(0,ya.u)("unsubscribed",j):"",k=(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)("div",{className:"mailpoet-statistics-value-small",children:[(0,g.jsxs)("span",{className:`mailpoet-statistics-value-number mailpoet-statistics-value-number-${S}`,children:[u,"% "]}),(0,p._x)("unsubscribed","Percentage of subscribers that unsubscribed from a newsletter","mailpoet")]}),f&&(0,g.jsx)(ya.f,{isInverted:!1,stat:"unsubscribed",rate:j,tooltipId:`unsubscribed-${e.id||"0"}`,tooltipPlace:"right"})]}),N=ko(o),C=x?(0,ya.u)("bounced",N):"",E=(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)("div",{className:"mailpoet-statistics-value-small",children:[(0,g.jsxs)("span",{className:`mailpoet-statistics-value-number mailpoet-statistics-value-number-${C}`,children:[h,"% "]}),(0,p._x)("bounced","Percentage of subscribers that bounced from a newsletter","mailpoet")]}),x&&(0,g.jsx)(ya.f,{isInverted:!1,stat:"bounced",rate:N,tooltipId:`bounced-${e.id||"0"}`,tooltipPlace:"right"})]}),I=(0,ya.u)("clicked",i),A=(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)("div",{className:"mailpoet-statistics-value",children:[(0,g.jsxs)("span",{className:`mailpoet-statistics-value-number mailpoet-statistics-value-number-${I}`,children:[l,"% "]}),(0,p._x)("clicked","Percentage of subscribers that clicked a newsletter link","mailpoet")]}),_&&(0,g.jsx)(ya.f,{isInverted:!1,stat:"clicked",rate:i,tooltipId:`clicked-${e.id||"0"}`,tooltipPlace:"right"})]});return(0,g.jsxs)("div",{className:"mailpoet-stats-general",children:[(0,g.jsxs)(Di.Grid.ThreeColumns,{className:"mailpoet-stats-general-top-row",children:[(0,g.jsx)("div",{children:(0,g.jsxs)("div",{className:"mailpoet-statistics-value-small",children:[(0,p.__)("Sent to","mailpoet"),": ",(0,g.jsx)("span",{className:"mailpoet-statistics-value-number",children:a.toLocaleString()})]})}),(0,g.jsx)("div",{className:"mailpoet-statistics-with-left-separator",children:k}),(0,g.jsx)("div",{className:"mailpoet-statistics-with-left-separator",children:E})]}),(0,g.jsxs)(Di.Grid.ThreeColumns,{children:[(0,g.jsx)("div",{children:A}),(0,g.jsxs)("div",{className:"mailpoet-statistics-with-left-separator",children:[y,m.U.trackingConfig.opensSeparated&&w]}),t&&(0,g.jsx)("div",{className:"mailpoet-statistics-with-left-separator",children:Ta.Hooks.applyFilters("mailpoet_newsletters_revenues_stats",null,e.statistics.revenue)}),!t&&(0,g.jsx)("div",{})]}),(0,g.jsxs)("div",{className:"mailpoet-stats-general-read-more",children:[(0,g.jsx)("p",{className:"mailpoet-stats-has-margin-left",children:(0,g.jsx)("a",{href:"https://kb.mailpoet.com/article/190-whats-a-good-email-open-rate",target:"_blank",rel:"noopener noreferrer",children:(0,p.__)("Read more on stats.","mailpoet")})}),(0,g.jsx)("p",{children:(0,g.jsx)("a",{href:`admin.php?page=mailpoet-newsletters#/sending-status/${e.id}`,children:(0,p.__)("Sending status","mailpoet")})})]})]})}No.displayName="NewsletterGeneralStats";var Co=a(81692);function Eo(e,t){m.U.Modal.loading(!0),m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"statisticsExport",action:"exportCampaign",data:{id:e,format:t}}).always(()=>{m.U.Modal.loading(!1)}).done(e=>{const a=e.data?.exportFileURL;a?(m.U.trackEvent("Email statistics export completed",{"File Format":t,"Export Type":"aggregate"}),window.location.href=a):m.U.Notice.error((0,p.__)("The export file could not be generated.","mailpoet"),{scroll:!0})}).fail(e=>{e.errors.length>0&&m.U.Notice.showApiErrorNotice(e,{scroll:!0})})}function Io({newsletter:e}){const[t,a]=(0,r.useState)(!1),{start:i,isExporting:s}=(e=>{const[t,a]=(0,r.useState)(!1),i=(0,r.useRef)(null),s=(0,r.useCallback)(()=>{null!==i.current&&(i.current(),i.current=null)},[]);(0,r.useEffect)(()=>s,[s]);const n=(0,r.useCallback)((e,t)=>{a(!1),e.exportFileURL?(m.U.trackEvent("Email statistics export completed",{"File Format":t,"Export Type":"recipients"}),window.location.href=e.exportFileURL):m.U.Notice.error((0,p.__)("The export file could not be generated.","mailpoet"),{scroll:!0})},[]),o=(0,r.useCallback)(e=>{a(!1),m.U.Notice.error(e,{scroll:!0})},[]),l=(0,r.useCallback)(s=>{t||(a(!0),m.U.Notice.success((0,p.__)("Export queued. The download will start automatically when it is ready.","mailpoet"),{timeout:6e3}),((e,t)=>m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"statisticsExport",action:"exportRecipients",data:{id:e,format:t}}).then(e=>e.data))(e,s).then(e=>{if(e.exportFileURL)return void n(e,s);const t=Ar(e.taskId,{onComplete:e=>n(e,s),onError:o});i.current=t.cancel}).catch(e=>{const t=e?.errors?.[0]?.message??(0,p.__)("Could not start the export.","mailpoet");o(t)}))},[o,n,t,e]);return{start:l,isExporting:t}})(e.id);if(!m.U.trackingConfig.emailTrackingEnabled)return null;const n=!m.U.capabilities.detailedAnalytics||m.U.capabilities.detailedAnalytics.isRestricted,o=(e,t)=>{t(),n?a(!0):i(e)};return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(ci.A,{className:"mailpoet-stats-export-dropdown",focusOnMount:!1,popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:e,onToggle:t})=>(0,g.jsxs)(ge.Ay,{variant:"secondary",onClick:t,"aria-expanded":e,"aria-label":(0,p.__)("Export","mailpoet"),isBusy:s,disabled:s,children:[(0,p.__)("Export","mailpoet"),(0,g.jsx)(mi.A,{icon:ui.A,size:18})]}),renderContent:({onClose:t})=>(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(Co.A,{label:(0,p.__)("Campaign summary","mailpoet"),children:[(0,g.jsx)(li.A,{className:"mailpoet-no-box-shadow",onClick:()=>{Eo(e.id,"csv"),t()},children:(0,p.__)("Export as CSV","mailpoet")}),(0,g.jsx)(li.A,{className:"mailpoet-no-box-shadow",onClick:()=>{Eo(e.id,"xlsx"),t()},children:(0,p.__)("Export as Excel (XLSX)","mailpoet")})]}),(0,g.jsxs)(Co.A,{label:(0,p.__)("Per recipient","mailpoet"),children:[(0,g.jsx)(li.A,{className:"mailpoet-no-box-shadow",onClick:()=>o("csv",t),children:(0,p.__)("Recipients as CSV","mailpoet")}),(0,g.jsx)(li.A,{className:"mailpoet-no-box-shadow",onClick:()=>o("xlsx",t),children:(0,p.__)("Recipients as Excel (XLSX)","mailpoet")})]})]})}),t&&(0,g.jsx)(ps.D,{onRequestClose:()=>a(!1),data:{capabilities:{detailedAnalytics:!0}},tracking:{utm_medium:"upsell_modal",utm_campaign:"stats_recipients_export"},children:(0,p.__)("Per-recipient statistics export is available with detailed analytics.","mailpoet")})]})}Io.displayName="ExportButton";const Ao=li.A;function Uo({newsletter:e,onClose:t}){const a=(0,p.sprintf)((0,p.__)("Re: %s","mailpoet"),e.subject),[i,s]=(0,r.useState)(a),[n,o]=(0,r.useState)(!1);return(0,g.jsxs)(Te.A,{title:(0,p.__)("Resend to non-openers","mailpoet"),onRequestClose:t,children:[(0,g.jsx)("p",{children:(0,p.__)("This will send a copy of this email to subscribers who haven’t opened it. A different subject line is required.","mailpoet")}),(0,g.jsx)(hr.A,{label:(0,p.__)("New subject line","mailpoet"),value:i,onChange:s,help:(0,p.__)("Must be different from the original subject.","mailpoet")}),(0,g.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px",marginTop:"16px"},children:[(0,g.jsx)(ge.Ay,{variant:"tertiary",onClick:t,disabled:n,children:(0,p.__)("Cancel","mailpoet")}),(0,g.jsx)(ge.Ay,{variant:"primary",onClick:()=>{i.trim()&&(o(!0),m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"newsletters",action:"resendToNonOpeners",data:{id:e.id,subject:i.trim()}}).done(()=>{m.U.Notice.success((0,p.__)("A copy of this email is being sent to non-openers.","mailpoet"),{static:!0}),t()}).fail(e=>{e?.errors?.length>0&&m.U.Notice.showApiErrorNotice(e,{scroll:!0})}).always(()=>{o(!1)}))},isBusy:n,disabled:!i.trim()||n,children:(0,p.__)("Resend","mailpoet")})]})]})}function To({newsletter:e}){const[t,a]=(0,r.useState)(!1),[i,s]=(0,r.useState)(!1),n=function(e){if("standard"!==e.type||"sent"!==e.status)return{eligible:!1};const t=e.sent_at;if(!t)return{eligible:!1,reason:(0,p.__)("No send date available.","mailpoet")};const a=(Date.now()-new Date(t).getTime())/36e5;if(a<24){const e=Math.ceil(24-a);return{eligible:!1,reason:(0,p.sprintf)((0,p._n)("Available in %d hour.","Available in %d hours.",e,"mailpoet"),e)}}return a>72?{eligible:!1,reason:(0,p.__)("Resend window expired (3 days).","mailpoet")}:{eligible:!0}}(e),l=e?.queue?.scheduled_at||e?.queue?.created_at||e?.created_at;return(0,g.jsxs)(Di.Grid.ThreeColumns,{className:"mailpoet-stats-info",children:[(0,g.jsxs)("div",{children:[(0,g.jsxs)(Kt.D,{level:1,children:[e.campaign_name?e.campaign_name:e.subject,e.campaign_name&&(0,g.jsx)("span",{children:` (${e.subject})`})]}),(0,g.jsxs)("div",{children:[(0,g.jsx)(o.Tag,{isInverted:!1,children:(0,o.getNewsletterStatusString)(e.status)})," ",(0,g.jsxs)("b",{children:[m.U.Date.short(l)," • ",m.U.Date.time(l)]}),(0,ar.nO)(e.queue)&&(0,g.jsx)(lr,{newsletterId:e.id,sent:"sent"===e.status})]}),Array.isArray(e.segments)&&e.segments.length&&(0,g.jsxs)("div",{children:[(0,g.jsx)("span",{className:"mailpoet-stats-info-key",children:(0,p.__)("To","mailpoet")}),": ",(0,g.jsx)(o.SegmentTags,{dimension:"large",segments:e.segments}),(0,g.jsx)(o.FilterSegmentTag,{newsletter:e,dimension:"large"})]})]}),(0,g.jsx)("div",{className:"mailpoet-stats-info-sender-preview",children:(0,g.jsxs)("div",{children:[(0,g.jsxs)("div",{className:"mailpoet-stats-info-key-value",children:[(0,g.jsxs)("span",{className:"mailpoet-stats-info-key",children:[(0,p.__)("From","mailpoet"),": "]}),e.sender_address?e.sender_address:"-"]}),(0,g.jsxs)("div",{className:"mailpoet-stats-info-key-value",children:[(0,g.jsxs)("span",{className:"mailpoet-stats-info-key",children:[(0,p.__)("Reply-to","mailpoet"),": "]}),e.reply_to_address?e.reply_to_address:"-"]}),(0,g.jsxs)("div",{className:"mailpoet-stats-info-key-value",children:[(0,g.jsxs)("span",{className:"mailpoet-stats-info-key",children:[(0,p.__)("GA campaign","mailpoet"),": "]}),e.ga_campaign?e.ga_campaign:"-"]})]})}),(0,g.jsx)("div",{className:"mailpoet-stats-button-group",children:(0,g.jsxs)(di.A,{children:[(0,g.jsx)(Io,{newsletter:e}),(0,g.jsx)(ge.Ay,{href:e.preview_url,target:"_blank",rel:"noopener noreferrer",variant:"secondary",children:(0,p.__)("Preview","mailpoet")}),(0,g.jsx)(ci.A,{className:"mailpoet-stats-has-margin-left",focusOnMount:!1,popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:t,onToggle:a})=>(0,g.jsxs)(di.A,{children:[(0,g.jsx)(ge.Ay,{disabled:"standard"!==e.type,onClick:()=>{(0,Ai.$U)(e)},variant:"primary",children:(0,p.__)("Edit","mailpoet")}),(0,g.jsxs)(ge.Ay,{onClick:a,"aria-expanded":t,variant:"primary",children:[" ",(0,g.jsx)(mi.A,{icon:ui.A,size:18})]})]}),renderContent:()=>(0,g.jsxs)(Co.A,{children:[(0,g.jsx)(Ao,{isBusy:t,className:"mailpoet-no-box-shadow",variant:"tertiary",disabled:"standard"!==e.type,onClick:()=>{a(!0),((e,t=()=>{})=>{(0,An.r3)(Number(e.id)).then(t=>{const a=t.data,i=(e=>m.U.getActiveEmailEditorUrl(e))(a);m.U.Notice.success((0,p.sprintf)((0,p.__)('Email "%s" has been duplicated. New email: <a href="%s"> %s </a>',"mailpoet"),e.subject,i,a.subject),{static:!0})}).catch(e=>{m.U.Notice.error(e.message,{scroll:!0})}).finally(()=>{t()})})(e,()=>{a(!1)})},children:(0,p.__)("Duplicate","mailpoet")}),"standard"===e.type&&"sent"===e.status&&(0,g.jsx)(Ao,{className:"mailpoet-no-box-shadow",variant:"tertiary",disabled:!n.eligible,onClick:()=>{n.eligible&&s(!0)},info:n.reason,children:(0,p.__)("Resend to non-openers","mailpoet")}),(0,g.jsx)(Ao,{isBusy:t,isDestructive:!0,onClick:()=>{a(!0),((e,t=()=>{})=>{m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"newsletters",action:"trash",data:{id:e.id}}).done(()=>{m.U.Notice.success((0,p.__)("1 email was moved to the trash.","mailpoet")),window.location.href="?page=mailpoet-newsletters"}).fail(e=>{e.errors.length>0&&m.U.Notice.showApiErrorNotice(e,{scroll:!0})}).always(()=>{t()})})(e,()=>{a(!1)})},children:(0,p.__)("Move to Trash","mailpoet")})]})})]})}),i&&(0,g.jsx)(Uo,{newsletter:e,onClose:()=>s(!1)})]})}function Po(){const e=(0,g.jsx)(Ge.$,{href:m.U.MailPoetComUrlFactory.getPurchasePlanUrl(m.U.subscribersCount,m.U.currentWpUserEmail,"starter",{utm_medium:"stats",utm_campaign:"signup"}),target:"_blank",rel:"noopener noreferrer",children:(0,p.__)("Upgrade","mailpoet")}),t=(0,g.jsxs)("p",{children:[(0,p.__)("Learn more about your subscribers and optimize your campaigns. See who opened your emails, which links they clicked, and then use the data to make your emails even better. And if you run a WooCommerce store, you’ll also see the revenue earned per email.","mailpoet")," ",(0,g.jsx)("a",{href:"admin.php?page=mailpoet-upgrade",children:(0,p.__)("Learn more","mailpoet")}),"."]});return(0,g.jsx)("div",{className:"mailpoet-stats-premium-required",children:(0,g.jsx)(Ka,{message:t,actionButton:e,capabilities:{detailedAnalytics:!0}})})}function Ro(){return window.mailpoet_display_detailed_stats?null:(0,g.jsx)(Po,{})}To.displayName="NewsletterStatsInfo",Ro.displayName="PremiumBanner";const Do=(0,o.withBoundary)(Ro);var Fo=a(58295);const Oo={type:"table",page:1,perPage:25,sort:{field:"scheduledAt",direction:"asc"},fields:["scheduledAt","status","sent"],titleField:"timezone",showTitle:!0};function Mo(e){return`${m.U.Date.short(e)} ${m.U.Date.time(e)}`}const Lo=[{id:"timezone",label:(0,p.__)("Time zone","mailpoet"),type:"text",enableSorting:!0,enableGlobalSearch:!1,getValue:({item:e})=>(0,ar.ZW)(e.timezone,e.fallbackUsed),render:({item:e})=>(0,g.jsx)("span",{"data-automation-id":`timezone_schedule_zone_${e.id}`,children:(0,ar.ZW)(e.timezone,e.fallbackUsed)})},{id:"scheduledAt",label:(0,p.__)("Scheduled for","mailpoet"),type:"datetime",enableSorting:!0,enableGlobalSearch:!1,getValue:({item:e})=>e.scheduledAt??"",render:({item:e})=>e.scheduledAt?function(e,t){if(t)try{return new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short",timeZone:t}).format(new Date(`${e.replace(" ","T")}Z`))}catch{}return Mo(e)}(e.scheduledAt,e.timezone):"—"},{id:"status",label:(0,p.__)("Status","mailpoet"),type:"text",enableSorting:!0,enableGlobalSearch:!1,getValue:({item:e})=>(0,ar.zi)(e.status),render:({item:e})=>(0,ar.zi)(e.status)},{id:"sent",label:(0,p.__)("Sent","mailpoet"),enableSorting:!0,enableGlobalSearch:!1,getValue:({item:e})=>e.countProcessed,render:({item:e})=>`${m.U.Num.toLocaleFixed(e.countProcessed)} / ${m.U.Num.toLocaleFixed(e.countTotal)}`}];function $o({newsletter:e}){const[t,a]=(0,r.useState)(Oo),i=(0,r.useMemo)(()=>(0,ar.$w)(e.queue).map((e,t)=>({...e,id:t})),[e.queue]),{data:s,paginationInfo:n}=(0,r.useMemo)(()=>(0,Fo.A)(i,t,Lo),[i,t]),o=(0,ar.e$)(e.queue);return(0,g.jsxs)("div",{className:"mailpoet-stats-timezone-schedule","data-automation-id":"timezone-schedule-stats",children:[o&&(0,g.jsx)("p",{children:(0,p.__)("Sends from %1$s to %2$s","mailpoet").replace("%1$s",Mo(o.first)).replace("%2$s",Mo(o.last))}),(0,g.jsx)("div",{className:"mailpoet-dataviews mailpoet-listing",children:(0,g.jsxs)(Le.A,{data:s,fields:Lo,view:t,onChangeView:a,paginationInfo:n,defaultLayouts:{table:{}},getItemId:e=>String(e.id),empty:(0,g.jsx)("p",{children:(0,p.__)("No time zone batches found.","mailpoet")}),children:[(0,g.jsx)(Le.A.Layout,{}),(0,g.jsx)(Le.A.Footer,{})]})})]})}$o.displayName="TimezoneSchedule";const Bo=["clicked","products","engagement","bounces","unsubscribe-reasons","timezones"],Wo=["group","filter","search","page","sort_by","sort_order"];function Vo(e,t){return"clicked"===t?`/stats/${e}`:`/stats/${e}/${t}`}function qo(){const[e,t]=(0,r.useState)({item:void 0,loading:!0}),a=(0,Ue.zy)(),i=(0,Ue.Zp)(),s=(0,Ue.g)(),n=(0,r.useCallback)(a=>{t({loading:!0,item:e.item}),m.U.Modal.loading(!0),m.U.Ajax.post({api_version:m.U.apiVersion,endpoint:window.mailpoet_display_detailed_stats?"stats":"newsletters",action:window.mailpoet_display_detailed_stats?"get":"getWithStats",data:{id:a,accept:"all"}}).always(()=>{m.U.Modal.loading(!1)}).done(e=>{t({loading:!1,item:e.data})}).fail(e=>{m.U.Notice.showApiErrorNotice(e,{scroll:!0}),t({loading:!1}),i("/")})},[i,e.item]);(0,r.useEffect)(()=>{window.scrollTo(0,0),e.item?.id!==s.id&&n(s.id)},[s.id,n,e.item]);const{item:l,loading:c}=e,u=l,h=function(e){const t=(e||"").split("/").filter(Boolean)[0];return Bo.includes(t)?t:Wo.some(e=>t?.startsWith(`${e}[`))?"engagement":"clicked"}(s["*"]);let _=h;return(0,r.useEffect)(()=>{!c&&u&&("products"===h&&!m.U.isWoocommerceActive||"timezones"===h&&!(0,ar.nO)(u.queue))&&i(Vo(u.id,"clicked"),{replace:!0})},[c,i,u,h]),c?null:u?("products"!==_||m.U.isWoocommerceActive||(_="clicked"),"timezones"!==_||(0,ar.nO)(u.queue)||(_="clicked"),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(yo,{}),(0,g.jsx)(d.x,{hideScreenOptions:!0}),(0,g.jsxs)("div",{className:"mailpoet-stats-page",children:[(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(To,{newsletter:u})}),(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(No,{newsletter:u,isWoocommerceActive:m.U.isWoocommerceActive})}),(0,g.jsxs)(wo.t,{activeKey:_,onSwitch:e=>{i(Vo(u.id,e))},children:[(0,g.jsx)(jo.o,{title:(0,p.__)("Clicked Links","mailpoet"),children:Ta.Hooks.applyFilters("mailpoet_newsletters_clicked_links_table",(0,g.jsx)(Do,{}),u.clicked_links,u)},"clicked"),m.U.isWoocommerceActive&&(0,g.jsx)(jo.o,{title:(0,p.__)("Products Sold","mailpoet"),automationId:"products-sold-tab",children:Ta.Hooks.applyFilters("mailpoet_newsletters_purchased_products",(0,g.jsx)(Do,{}),u)},"products"),(0,g.jsx)(jo.o,{title:(0,p.__)("Subscriber Engagement","mailpoet"),automationId:"engagement-tab",children:Ta.Hooks.applyFilters("mailpoet_newsletters_subscriber_engagement",(0,g.jsx)(Do,{}),a,s,u)},"engagement"),(0,g.jsx)(jo.o,{title:(0,p._x)("Bounces","A tab title for the list of bounces (w.wiki/45Qc)","mailpoet"),automationId:"bounces-tab",children:Ta.Hooks.applyFilters("mailpoet_newsletters_bounces",(0,g.jsx)(Do,{}),a,s)},"bounces"),(0,g.jsx)(jo.o,{title:(0,p.__)("Unsubscribe reasons","mailpoet"),automationId:"unsubscribe-reasons-tab",children:Ta.Hooks.applyFilters("mailpoet_newsletters_unsubscribe_reasons",(0,g.jsx)(Do,{}),u.statistics.unsubscribeReasons,u)},"unsubscribe-reasons"),(0,ar.nO)(u.queue)&&(0,g.jsx)(jo.o,{title:(0,p.__)("Time zones","mailpoet"),automationId:"timezones-tab",children:(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)($o,{newsletter:u})})},"timezones")]})]})]})):(0,g.jsxs)("h3",{children:[" ",(0,p.__)("This email does not exist.","mailpoet")," "]})}function zo({newsletters:e}){return(0,g.jsxs)(h.$,{type:"error",timeout:!1,closable:!1,renderInPlace:!0,children:[(0,g.jsx)("h3",{children:(0,p.__)("Paused emails","mailpoet")}),(0,g.jsx)("p",{children:(0,p.__)("There was problem sending the following email(s), please fix the issues described for each email and resume.","mailpoet")}),(0,g.jsx)("ul",{children:e.map(({id:e,subject:t})=>(0,g.jsx)("li",{children:t},e))})]})}qo.displayName="CampaignStatsPage",zo.displayName="CorruptEmailNotice";var Ho=a(7058);function Go(){const e=(0,r.useCallback)(()=>{(0,Ho.k)({endpoint:"UserFlags",method:"set","data[legacy_automatic_emails_notice_dismissed]":"1"})},[]);return(0,g.jsx)(h.$,{type:"info",timeout:!1,closable:!0,renderInPlace:!0,onClose:e,children:(0,g.jsx)("p",{children:(0,Oe.A)((0,p.__)("We moved your existing Welcome and WooCommerce emails to Automations. Rest assured, all your automations are still actively running. <link>View automations</link>","mailpoet"),{link:(0,g.jsx)("a",{href:"admin.php?page=mailpoet-automation"})})})})}const Yo=bo(()=>{const{parentId:e}=(0,Ue.g)();return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(vo,{children:(0,g.jsx)(xo,{})}),window.mailpoet_legacy_automatic_emails_count>0&&!window.mailpoet_legacy_automatic_emails_notice_dismissed&&(0,g.jsx)(Go,{}),m.U.corrupt_newsletters.length>0&&(0,g.jsx)(zo,{newsletters:m.U.corrupt_newsletters}),(0,g.jsxs)(uo.k,{activeKey:"standard",routerType:"switch-only",onSwitch:e=>(e=>{m.U.trackEvent(`Tab Emails > ${e} clicked`)})(e),automationId:"newsletters_listing_tabs",children:[(0,g.jsx)(o.Tab,{route:"standard/*",title:(0,p.__)("Newsletters","mailpoet"),automationId:`tab-${(0,p.__)("Newsletters","mailpoet")}`,children:(0,g.jsx)(Gr,{})},"standard"),(0,g.jsx)(o.Tab,{route:"notification/*",title:(0,p.__)("Post Notifications","mailpoet"),automationId:`tab-${(0,p.__)("Post Notifications","mailpoet")}`,children:e?(0,g.jsx)(ao,{parentId:e}):(0,g.jsx)(Zr,{})},"notification"),(0,g.jsx)(o.Tab,{route:"re_engagement/*",title:(0,p.__)("Re-engagement Emails","mailpoet"),automationId:`tab-${(0,p.__)("Re-engagement Emails","mailpoet")}`,children:(0,g.jsx)(Xr,{})},"re_engagement")]})]})}),Ko=[{path:"/notification/history/:parentId/*",children:(0,o.withBoundary)(Yo)},{path:"/standard/*",children:(0,o.withBoundary)(Yo)},{path:"/notification/*",children:(0,o.withBoundary)(Yo)},{path:"/re_engagement/*",children:(0,o.withBoundary)(Yo)},{path:"/new/standard",children:(0,o.withBoundary)(function(e){const t=(0,Ue.Zp)();return(0,g.jsx)(Zn,{...e,navigate:t})})},{path:"/new/notification",children:(0,o.withBoundary)(function(){const e=(0,Ue.Zp)();return(0,g.jsx)(Qn,{navigate:e})})},{path:"/new/re-engagement",children:(0,o.withBoundary)(Xn)},{path:"/new",children:(0,o.withBoundary)(function(){return(0,g.jsxs)(o.ErrorBoundary,{children:[(0,g.jsx)(d.x,{}),(0,g.jsxs)("div",{className:"mailpoet-main-container",children:[(0,g.jsx)(qe.z,{heading:(0,p.__)("What would you like to create?","mailpoet"),headingPrefix:(0,g.jsx)(qe.o,{href:"#/",label:(0,p.__)("Listing","mailpoet"),"aria-label":(0,p.__)("Go back to email listing page","mailpoet")})}),(0,g.jsx)(yi,{})]})]})})},{name:"template",path:"/template/:id",children:(0,o.withBoundary)(function(e){const t=(0,Ue.g)();return(0,g.jsx)(Ti,{...e,params:t})})},{path:"/send/congratulate/:id",children:(0,o.withBoundary)(function(e){const t=(0,Ue.g)();return(0,g.jsx)(Kn,{...e,params:t})})},{path:"/send/:id",children:(0,o.withBoundary)(function(e){const t=(0,Ue.zy)(),a=(0,Ue.Zp)(),i=(0,Ue.g)();return(0,g.jsx)(Mn,{...e,location:t,navigate:a,params:i})})},{path:"/sending-status/:id/*",children:(0,o.withBoundary)(mo)},{path:"/stats/:id/*",children:(0,o.withBoundary)(qo)}];function Zo(){return(0,g.jsx)(l.F.Provider,{value:(0,l.f)(window),children:(0,g.jsxs)(Ae.HashRouter,{children:[(0,g.jsx)(c.D,{}),(0,g.jsx)(u.q,{}),(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(_,{mailpoetInstalledDaysAgo:m.U.installedDaysAgo,sendTransactionalEmails:m.U.transactionalEmailsEnabled,mtaMethod:m.U.mtaMethod,apiVersion:m.U.apiVersion,noticeDismissed:m.U.transactionalEmailsOptInNoticeDismissed})}),(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(k.D,{})}),(0,g.jsxs)(Ue.BV,{children:[(0,g.jsx)(Ue.qh,{path:"/",element:(0,g.jsx)(Ue.C5,{to:0===window.mailpoet_newsletters_count?"/new":"/standard"})}),Ko.map(e=>(0,g.jsx)(Ue.qh,{path:e.path,element:(0,g.jsx)(e.children,{})},e.path))]})]})})}const Jo=document.getElementById("newsletters_container");Jo&&((0,o.registerTranslations)(),(0,n.H)(Jo).render((0,g.jsx)(Zo,{})));var Qo=a(94779),Xo=a(53169);function el(){return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(d.x,{}),(0,g.jsx)(qe.z,{heading:(0,p.__)("Lists","mailpoet"),children:(0,g.jsx)(Ae.Link,{className:"page-title-action",to:"/new","data-automation-id":"new-list",children:(0,p.__)("Add new list","mailpoet")})}),(0,g.jsxs)("div",{className:"mailpoet-segment-subscriber-count",children:[(0,g.jsx)(He,{subscribersInPlan:m.U.subscribersCount,subscribersInPlanLimit:m.U.subscribersLimit}),(0,g.jsx)(Ye,{cacheCalculation:window.mailpoet_subscribers_counts_cache_created_at})]}),(0,g.jsx)(k.D,{})]})}var tl=a(80502),al=a(85123);let il=!1;function sl(){if(il)return;const e=window.mailpoet_segments_api;tl.default.use(tl.default.createRootURLMiddleware(`${e.root}/`)),tl.default.use(tl.default.createNonceMiddleware(e.nonce)),il=!0}function nl(e,t){return(0,r.createElement)("span",{"data-automation-id":`listing_item_${e.id}_${t}_count`},Number(e.subscribers_count[t]??0).toLocaleString())}const rl=m.U.trackingConfig.emailTrackingEnabled?[{id:"average_engagement_score",label:m.U.I18n.t("listScore"),type:"integer",enableSorting:!0,enableGlobalSearch:!1,filterBy:{operators:["lessThan","greaterThan","between"]},render:({item:e})=>(0,r.createElement)(ve,{id:Number(e.id),engagementScore:e.average_engagement_score})}]:[],ol=[{id:"name",label:(0,p.__)("Name","mailpoet"),type:"text",enableSorting:!0,enableGlobalSearch:!1,filterBy:!1,render:({item:e})=>{const t=0===Number(e.show_in_manage_subscription_page)?(0,r.createElement)("span",{className:"mailpoet-listing-title-private-label"},` ${m.U.I18n.t("privateListLabel")}`):null,a=[e.name,t].filter(Boolean),i={className:"mailpoet-listing-title","data-automation-id":`listing_item_${e.id}`},s=t=>(0,r.createElement)("span",{"data-automation-id":`segment_name_${e.name}`},t);return"wp_users"===e.type||"woocommerce_users"===e.type?(0,r.createElement)("div",null,s((0,r.createElement)("span",i,...a))):(0,r.createElement)("div",null,s((0,r.createElement)("a",{...i,href:`#/edit/${e.id}`},...a)))}},{id:"description",label:(0,p.__)("Description","mailpoet"),enableSorting:!1,enableGlobalSearch:!1},...rl,{id:"subscribed",label:m.U.I18n.t("subscribed"),enableSorting:!1,enableGlobalSearch:!1,render:({item:e})=>nl(e,"subscribed")},{id:"unconfirmed",label:m.U.I18n.t("unconfirmed"),enableSorting:!1,enableGlobalSearch:!1,render:({item:e})=>nl(e,"unconfirmed")},{id:"unsubscribed",label:m.U.I18n.t("unsubscribed"),enableSorting:!1,enableGlobalSearch:!1,render:({item:e})=>nl(e,"unsubscribed")},{id:"inactive",label:m.U.I18n.t("inactive"),enableSorting:!1,enableGlobalSearch:!1,render:({item:e})=>nl(e,"inactive")},{id:"bounced",label:m.U.I18n.t("bounced"),enableSorting:!1,enableGlobalSearch:!1,render:({item:e})=>nl(e,"bounced")},{id:"created_at",label:m.U.I18n.t("createdOn"),type:"date",enableSorting:!0,enableGlobalSearch:!1,filterBy:{operators:["on","beforeInc","afterInc","between"]},render:({item:e})=>{return(t=e.created_at)?(0,r.createElement)("span",null,(0,r.createElement)("span",null,m.U.Date.short(t)),(0,r.createElement)("br",null),(0,r.createElement)("span",null,m.U.Date.time(t))):(0,r.createElement)("span",null,"—");var t}}];function ll(e){if("number"==typeof e)return Number.isFinite(e)?e:void 0;if("string"==typeof e){const t=e.trim();if(""===t)return;const a=Number(t);return Number.isFinite(a)?a:void 0}}const dl=Number(window.mailpoet_listing_per_page),cl={type:"table",perPage:dl,page:1,sort:{field:"name",direction:"asc"},fields:["description",...m.U.trackingConfig.emailTrackingEnabled?["average_engagement_score"]:[],"subscribed","unconfirmed","unsubscribed","inactive","bounced","created_at"],titleField:"name",showTitle:!0};function ml(e){return"wp_users"===e.type}function ul(e){return"woocommerce_users"===e.type}function pl(e){return ml(e)||ul(e)}function hl(){const e=window.location.hash.split("/").map(e=>e.replace(/\]$/,"").split("[")).reduce((e,[t,a])=>a?"group"!==t||"all"!==a&&"trash"!==a?("page"===t||"paged"===t)&&Number(a)>0?{...e,page:Number(a)}:("per_page"===t||"limit"===t)&&Number(a)>0?{...e,perPage:Number(a)}:"sort_by"===t||"orderby"===t?{...e,orderby:a}:"sort_order"!==t&&"order"!==t||"asc"!==a&&"desc"!==a?e:{...e,order:a}:{...e,group:a}:e,{}),[t,a]=(0,r.useState)(e.group??"all"),[i,s]=(0,r.useState)([]),[n,o]=(0,r.useState)(null),[l,d]=(0,r.useState)(null),[c,u]=(0,r.useState)(null),[h]=(0,r.useState)(()=>(0,$e.Aq)("static-segments",cl,ol)),[_]=(0,r.useState)(()=>({...h,page:e.page??h.page,perPage:e.perPage??h.perPage,sort:{field:e.orderby??h.sort?.field??"name",direction:e.order??h.sort?.direction??"asc"}})),f=(0,r.useCallback)(e=>async function(e){return sl(),(await(0,tl.default)({path:(0,al.F)("/mailpoet/v1/segments",e),method:"GET"})).data}({...e,group:t}),[t]),{view:b,setView:x,items:v,meta:y,groups:w,isLoading:j,error:S,onChangeView:k,clearError:N,refresh:C}=(0,$e.i7)({initialView:_,load:f,extraParams:e=>(0,$e.Y4)(function(e){const t={};return(e??[]).forEach(e=>{if("created_at"===e.field){const{from:a,to:i}=(0,$e._O)(e.operator,e.value);a&&(t.created_from=a),i&&(t.created_to=i)}else"average_engagement_score"===e.field&&Object.assign(t,function(e,t){if("between"===e){const e=Array.isArray(t)?t:[],a=ll(e[0]),i=ll(e[1]);return{...void 0!==a?{score_min:a}:{},...void 0!==i?{score_max:i}:{}}}const a=ll(t);return void 0===a?{}:"greaterThan"===e?{score_min:a}:"lessThan"===e?{score_max:a}:{}}(e.operator,e.value))}),t}(e.filters))}),E=(0,$e.wh)("static-segments",b,k);(0,r.useEffect)(()=>{!function(e,t,a){const i=[["group",e],["page",t.page&&1!==t.page?t.page:void 0],["limit",t.perPage&&t.perPage!==(a.perPage??dl)?t.perPage:void 0],["sort_by",t.sort?.field&&t.sort.field!==(a.sort?.field??"name")?t.sort.field:void 0],["sort_order",t.sort?.direction&&t.sort.direction!==(a.sort?.direction??"asc")?t.sort.direction:void 0]].reduce((e,[t,a])=>a?`${e}/${t}[${a}]`:e,"");window.history.replaceState(null,"",`#/lists${i}`)}(t,b,(0,$e.Aq)("static-segments",cl,ol))},[t,b]);const I=(0,r.useCallback)(async(e,t,a)=>{const i=t.map(e=>Number(e.id));if(a?.select_all||"empty_trash"===e||0!==i.length)try{const n=await async function(e,t,a){return sl(),(await(0,tl.default)({path:"/mailpoet/v1/segments/bulk-action",method:"POST",data:{action:e,ids:t,...a}})).data}(e,i,a),r=function(e,t){return"delete"===e||"empty_trash"===e?t.deleted:t.updated}(e,n);s([]),o(n.errors.length?n.errors.map(e=>e.message).join("\n"):null),d(r>0?function(e,t,a=!1){return"trash"===e?`${a?(0,p.__)("1 list was moved to the trash.","mailpoet"):(0,p.sprintf)((0,p._n)("%d list was moved to the trash.","%d lists were moved to the trash.",t,"mailpoet"),t)} ${(0,p.__)("Note that deleting a list does not delete its subscribers.","mailpoet")}`:"restore"===e?1===t?(0,p.__)("1 list has been restored from the Trash.","mailpoet"):(0,p.sprintf)((0,p._n)("%d list has been restored from the Trash.","%d lists have been restored from the Trash.",t,"mailpoet"),t):`${(0,p.sprintf)((0,p._n)("%d list was permanently deleted.","%d lists were permanently deleted.",t,"mailpoet"),t)} ${(0,p.__)("Note that deleting a list does not delete its subscribers.","mailpoet")}`}(e,r,t.some(ml)):null),C()}catch(e){const t=e;d(null),o(t?.message||(0,p.__)("The bulk action could not be completed.","mailpoet"))}},[C]),A=(0,r.useCallback)(e=>{m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"segments",action:"duplicate",data:{id:e.id}}).done(e=>{m.U.Notice.success(m.U.I18n.t("listDuplicated").replace("%1$s",(0,Me.Zn)(e.data.name))),C()}).fail(e=>{m.U.Notice.showApiErrorNotice(e,{scroll:!0})})},[C]),U=(0,r.useCallback)(e=>{m.U.Modal.loading(!0),m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"segments",action:"synchronize",data:{type:e.type}}).done(()=>{const t="woocommerce_users"===e.type?m.U.I18n.t("listSynchronizationWasScheduled").replace("%1$s",e.name):m.U.I18n.t("listSynchronized").replace("%1$s",e.name);m.U.Modal.loading(!1),m.U.Notice.success(t),C()}).fail(e=>{m.U.Modal.loading(!1),e.errors.length>0&&m.U.Notice.showApiErrorNotice(e,{scroll:!0})})},[C]),T=(0,r.useMemo)(()=>[{id:"edit",label:(0,p.__)("Edit","mailpoet"),isPrimary:!0,supportsBulk:!1,isEligible:e=>!e.deleted_at&&!pl(e),callback:e=>{const t=e[0];t&&(window.location.hash=`/edit/${t.id}`)}},{id:"duplicate",label:m.U.I18n.t("duplicate"),supportsBulk:!1,isEligible:e=>!e.deleted_at&&!pl(e),callback:e=>{e[0]&&A(e[0])}},{id:"read_more",label:m.U.I18n.t("readMore"),supportsBulk:!1,isEligible:e=>ml(e),callback:()=>{window.open("https://kb.mailpoet.com/article/133-the-wordpress-users-list","_blank","noopener,noreferrer")}},{id:"synchronize",label:m.U.I18n.t("forceSync"),supportsBulk:!1,isEligible:e=>ml(e)||ul(e),callback:e=>{e[0]&&U(e[0])}},{id:"view_subscribers",label:m.U.I18n.t("viewSubscribers"),supportsBulk:!1,callback:e=>{const t=e[0];t&&(window.location.href=t.subscribers_url)}},{id:"trash_wp_users",label:(0,p.__)("Trash and disable","mailpoet"),supportsBulk:!1,isEligible:e=>!e.deleted_at&&ml(e),callback:e=>{I("trash",e)}},{id:"trash",label:m.U.I18n.t("moveToTrash"),supportsBulk:!0,isEligible:e=>!e.deleted_at&&!ml(e)&&!ul(e),callback:e=>{I("trash",e)}},{id:"restore_wp_users",label:(0,p.__)("Restore and enable","mailpoet"),supportsBulk:!1,isEligible:e=>!!e.deleted_at&&ml(e),callback:e=>{I("restore",e)}},{id:"restore",label:(0,p.__)("Restore","mailpoet"),supportsBulk:!0,isEligible:e=>!!e.deleted_at&&!ml(e),callback:e=>{I("restore",e)}},{id:"delete",label:(0,p.__)("Delete permanently","mailpoet"),supportsBulk:!0,isDestructive:!0,isEligible:e=>!!e.deleted_at&&!pl(e),callback:e=>{u({action:"delete",targets:e,count:e.length})}}],[I,A,U]),P=(0,r.useMemo)(()=>({totalItems:y.count,totalPages:y.pages}),[y]),R=(0,r.useMemo)(()=>{const e={all:null,trash:null};return(w??[]).forEach(t=>{"all"!==t.name&&"trash"!==t.name||(e[t.name]=t.count)}),e},[w]),D=(0,r.useMemo)(()=>{const e=(e,t)=>null===t?e:`${e} (${t})`;return[{name:"all",title:e((0,p.__)("All","mailpoet"),R.all),className:"mailpoet-dataviews-group-all"},..."trash"===t||(R.trash??0)>0?[{name:"trash",title:e((0,p.__)("Trash","mailpoet"),R.trash),className:"mailpoet-dataviews-group-trash"}]:[]]},[t,R]);(0,r.useEffect)(()=>{"trash"!==t||j||S||0!==R.trash||(a("all"),s([]),x(e=>({...e,page:1})))},[t,R.trash,j,S,x]);const F=e=>{s(e)},O="trash"===t?(0,p.__)("Trash is empty.","mailpoet"):(0,p.__)("No lists found.","mailpoet"),M=function(e){if(!e)return{title:"",message:"",confirmText:""};const{action:t,count:a}=e;return"empty_trash"===t?{title:(0,p.__)("Empty Trash","mailpoet"),message:(0,g.jsxs)(g.Fragment,{children:[(0,p.sprintf)((0,p._n)("Are you sure you want to permanently delete %d list from the Trash?","Are you sure you want to permanently delete %d lists from the Trash?",a,"mailpoet"),a)," ",(0,g.jsx)("strong",{children:(0,p.__)("This action can not be reversed.","mailpoet")})]}),confirmText:(0,p.__)("Empty Trash","mailpoet")}:{title:(0,p._n)("Delete selected list permanently","Delete selected lists permanently",a,"mailpoet"),message:(0,g.jsxs)(g.Fragment,{children:[(0,p.sprintf)((0,p._n)("Are you sure you want to permanently delete %d selected list?","Are you sure you want to permanently delete %d selected lists?",a,"mailpoet"),a)," ",(0,g.jsx)("strong",{children:(0,p.__)("This action can not be reversed.","mailpoet")})]}),confirmText:(0,p.__)("Delete permanently","mailpoet")}}(c);return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(hi.x,{}),(0,g.jsx)(el,{}),S&&(0,g.jsx)(Fe.A,{status:"error",onRemove:N,children:S}),n&&(0,g.jsx)(Fe.A,{status:"error",onRemove:()=>o(null),children:n}),l&&(0,g.jsx)(Fe.A,{status:"success",onRemove:()=>d(null),children:l}),(0,g.jsx)(Qo.A,{className:"mailpoet-segments-dataviews__tabs",activeClass:"is-active",tabs:D,initialTabName:t,onSelect:e=>{"all"!==e&&"trash"!==e||e!==t&&(a(e),s([]),o(null),d(null),N(),x(e=>({...e,page:1})))},children:()=>(0,g.jsx)("div",{className:"mailpoet-dataviews mailpoet-segments-dataviews mailpoet-segments-listing","data-automation-id":"segments_listing",children:(0,g.jsxs)(Le.A,{data:v,fields:ol,view:b,onChangeView:E,actions:T,paginationInfo:P,defaultLayouts:{table:{}},getItemId:e=>String(e.id),selection:i,onChangeSelection:F,isLoading:j,empty:(0,g.jsx)("div",{children:O}),children:[(0,g.jsxs)("div",{className:"mailpoet-segments-dataviews__toolbar",children:[(0,g.jsx)(Le.A.Search,{label:(0,p.__)("Search","mailpoet")}),(0,g.jsx)(Le.A.FiltersToggle,{}),(0,g.jsx)("div",{className:"mailpoet-dataviews__toolbar-end",children:(0,g.jsx)(Le.A.ViewConfig,{})})]}),(0,g.jsx)(Le.A.Filters,{}),"trash"===t&&(R.trash??0)>0&&(0,g.jsx)("div",{className:"mailpoet-segments-dataviews__toolbar",children:(0,g.jsx)("button",{type:"button",className:"button","data-automation-id":"empty_trash",onClick:()=>{u({action:"empty_trash",targets:[],count:R.trash??0,params:{select_all:!0,group:"trash",page:b.page??1,per_page:b.perPage??dl,orderby:b.sort?.field,order:b.sort?.direction}})},children:(0,p.__)("Empty Trash","mailpoet")})}),(0,g.jsx)(Le.A.Layout,{}),(0,g.jsx)(Le.A.Footer,{})]},t)})},t),(0,g.jsx)(Xo.A,{className:"mailpoet-confirm-dialog",isOpen:!!c,title:M.title,confirmButtonText:M.confirmText,__experimentalHideHeader:!1,onConfirm:()=>{c&&I(c.action,c.targets,c.params),u(null)},onCancel:()=>u(null),children:(0,g.jsx)("p",{children:M.message})})]})}const gl=window.mailpoet_confirmation_emails||[],_l=window.mailpoet_pages||[],fl={0:(0,p.__)("Use global default","mailpoet")};_l.forEach(e=>{fl[String(e.id)]=e.title});const bl=[{name:"name",label:m.U.I18n.t("segmentFormName"),type:"text",tip:m.U.I18n.t("segmentFormNameTip")},{name:"show_in_manage_subscription_page",label:m.U.I18n.t("showInManageSubscriptionPage"),type:"checkbox",values:{show_in_manage_subscription_page:m.U.I18n.t("showInManageSubscriptionPageTip")},isChecked:!0},{name:"public_description",label:m.U.I18n.t("publicDescription"),type:"textarea",tip:m.U.I18n.t("publicDescriptionTip")},{name:"description",label:m.U.I18n.t("description"),type:"textarea",tip:m.U.I18n.t("segmentDescriptionTip")},{name:"confirmation_email_id",label:(0,p.__)("Confirmation email","mailpoet"),type:"reactComponent",component:function({onValueChange:e,item:t}){const[a,i]=(0,r.useState)(gl),[s,n]=(0,r.useState)(!1),o=t.confirmation_email_id||"0",l=(0,r.useCallback)(async()=>{n(!0);try{const t=(await m.U.Ajax.post({api_version:m.U.apiVersion,endpoint:"newsletters",action:"createConfirmationEmail"})).data;i(e=>[...e,t]),e({target:{name:"confirmation_email_id",value:String(t.id)}});const a=`admin.php?page=mailpoet-newsletter-editor&id=${t.id}`;m.U.Notice.success(`${(0,p.__)("Confirmation email created.","mailpoet")} <a href="${a}" target="_blank" rel="noopener noreferrer">${(0,p.__)("Edit it now","mailpoet")}</a>`)}catch(e){m.U.Notice.showApiErrorNotice(e,{scroll:!0})}finally{n(!1)}},[e]);return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(Be.Select,{name:"confirmation_email_id",id:"field_confirmation_email_id",value:o,onChange:e,children:[(0,g.jsx)("option",{value:"0",children:(0,p.__)("Use global default","mailpoet")}),a.map(e=>(0,g.jsx)("option",{value:String(e.id),children:e.subject},e.id))]}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)(Ge.$,{type:"button",variant:"secondary",dimension:"small",onClick:l,isDisabled:s,children:s?(0,p.__)("Creating…","mailpoet"):(0,p.__)("Create new","mailpoet")}),"0"!==o&&(0,g.jsx)(Ge.$,{variant:"secondary",dimension:"small",href:`admin.php?page=mailpoet-newsletter-editor&id=${o}`,target:"_blank",rel:"noopener noreferrer",children:(0,p.__)("Edit","mailpoet")})]})},tip:(0,p.__)("Choose a custom confirmation email for subscribers joining this list. If not set, the global default is used.","mailpoet")},{name:"confirmation_page_id",label:(0,p.__)("Confirmation page","mailpoet"),type:"select",values:fl,tip:(0,p.__)("Choose a custom confirmation page for subscribers joining this list. If not set, the global default is used.","mailpoet")}],xl={onUpdate:function(){m.U.Notice.success(m.U.I18n.t("segmentUpdated"))},onCreate:function(){m.U.Notice.success(m.U.I18n.t("segmentAdded")),m.U.trackEvent("Lists > Add new")}};function vl(){const e=(0,Ue.g)();return(0,g.jsxs)("div",{className:"mailpoet-main-container",children:[(0,g.jsx)(d.x,{hideScreenOptions:!0}),(0,g.jsx)(qe.z,{heading:e.id?(0,p.__)("Edit list","mailpoet"):(0,p.__)("Add new list","mailpoet"),headingPrefix:(0,g.jsx)(qe.o,{href:"#/",label:(0,p.__)("Lists","mailpoet"),"aria-label":(0,p.__)("Navigate to the lists page","mailpoet")})}),(0,g.jsx)(sa.X,{}),(0,g.jsx)(ia,{endpoint:"segments",fields:bl,params:e,messages:xl})]})}vl.displayName="SegmentForm";const yl=document.getElementById("static_segments_container"),wl=(0,o.withBoundary)(vl),jl=(0,o.withBoundary)(function(){return(0,g.jsx)(hl,{})});function Sl(){return(0,g.jsx)(l.F.Provider,{value:(0,l.f)(window),children:(0,g.jsxs)(Ae.HashRouter,{children:[(0,g.jsx)(c.D,{}),(0,g.jsx)(u.q,{}),(0,g.jsxs)(Ue.BV,{children:[(0,g.jsx)(Ue.qh,{path:"/new",element:(0,g.jsx)(wl,{})}),(0,g.jsx)(Ue.qh,{path:"/edit/:id",element:(0,g.jsx)(wl,{})}),(0,g.jsx)(Ue.qh,{path:"*",element:(0,g.jsx)(jl,{})})]})]})})}yl&&((0,o.registerTranslations)(),(0,n.H)(yl).render((0,g.jsx)(Sl,{})));var kl=a(25656),Nl=a(93558);function Cl({children:e,title:t,description:a}){return(0,g.jsxs)("div",{className:"mailpoet-admin-fields",children:[(0,g.jsxs)("div",{className:"mailpoet-admin-fields-title",children:[(0,g.jsx)(Nl.D,{level:4,children:t}),(0,g.jsx)("p",{children:a})]}),(0,g.jsx)(ga.A,{children:(0,g.jsx)(_a.A,{children:e})})]})}function El({children:e,slug:t,title:a,description:i}){return(0,g.jsxs)("div",{className:"mailpoet-admin-field",children:[a&&(0,g.jsx)("p",{children:(0,g.jsx)("label",{htmlFor:`field_${t}`,children:a})}),(0,g.jsx)("div",{children:e}),i&&(0,g.jsx)("p",{className:"mailpoet-admin-field-description",children:i})]})}var Il=a(24193),Al=a(32171),Ul=a(60441);function Tl({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),a=(0,C.A)(e=>e(Al.Hz).getAutomations(),[]),{updateSegmentFilter:i,updateSegmentFilterFromEvent:s}=(0,fe.A)(Al.Hz);(0,r.useEffect)(()=>{t.operator!==Il.dP.ANY&&t.operator!==Il.dP.ALL&&t.operator!==Il.dP.NONE&&i({operator:Il.dP.ANY},e)},[i,t,e]);const n=a.map(e=>({value:e.id,label:e.name}));return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(Be.Select,{value:t.operator,onChange:t=>{s("operator",e,t)},isMinWidth:!0,children:[(0,g.jsx)("option",{value:Il.dP.ANY,children:m.U.I18n.t("anyOf")}),(0,g.jsx)("option",{value:Il.dP.ALL,children:m.U.I18n.t("allOf")}),(0,g.jsx)("option",{value:Il.dP.NONE,children:m.U.I18n.t("noneOf")})]},"select"),(0,g.jsx)(kl.ReactSelect,{dimension:"small",isMulti:!0,placeholder:m.U.I18n.t("searchAutomations"),options:n,value:n.filter(e=>{if(!t.automation_ids)return;const a=e.value;return-1!==t.automation_ids.indexOf(a)}),onChange:t=>{i({automation_ids:t.map(e=>e.value)},e)}})]})}const Pl={[Ul.g.ENTERED_AUTOMATION]:Tl,[Ul.g.EXITED_AUTOMATION]:Tl};var Rl=a(4143);const Dl=["automation","automation_transactional"],Fl=e=>Rl.s.format(e);function Ol(e,t=Fl){const a=e??[],i=a.filter(({type:e})=>"standard"===e).map(e=>function(e,t){return{label:e.name,tag:e.sent_at?t(e.sent_at):(0,p.__)("Not sent yet","mailpoet"),value:Number(e.id)}}(e,t)),s=a.filter(({type:e})=>function(e){return Dl.includes(e)}(e)).map(e=>function(e){return{label:e.name,value:Number(e.id)}}(e)),n=[];return i.length>0&&n.push({label:(0,p.__)("Standard emails","mailpoet"),options:i}),s.length>0&&n.push({label:(0,p.__)("Automation emails","mailpoet"),options:s}),{flatOptions:[...i,...s],groupedOptions:n}}function Ml({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilter:a,updateSegmentFilterFromEvent:i}=(0,fe.A)(Al.Hz),s=(0,C.A)(e=>e(Al.Hz).getNewslettersList(),[]),{flatOptions:n,groupedOptions:o}=Ol(s);return(0,r.useEffect)(()=>{t.operator!==Il.dP.ANY&&t.operator!==Il.dP.ALL&&t.operator!==Il.dP.NONE&&a({operator:Il.dP.ANY},e),t.action===Il._R.MACHINE_OPENED&&t.operator===Il.dP.NONE&&a({operator:Il.dP.ANY},e)},[t.action,t.operator,e,a]),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(Be.Select,{isMinWidth:!0,automationId:"segment-email-opens-condition",value:t.operator,onChange:t=>{i("operator",e,t)},children:[(0,g.jsx)("option",{value:Il.dP.ANY,children:m.U.I18n.t("anyOf")}),(0,g.jsx)("option",{value:Il.dP.ALL,children:m.U.I18n.t("allOf")}),t.action!==Il._R.MACHINE_OPENED?(0,g.jsx)("option",{value:Il.dP.NONE,children:m.U.I18n.t("noneOf")}):null]},"select"),(0,g.jsx)(kl.ReactSelect,{dimension:"small",isMulti:!0,placeholder:m.U.I18n.t("selectNewsletterPlaceholder"),options:o,automationId:"segment-email",value:n.filter(({value:e})=>t.newsletters?.includes(e)),onChange:t=>{a({newsletters:(t||[]).map(({value:e})=>e)},e)}})]})}const Ll=e=>!!e;var $l=a(89011);function Bl(e,t){const a=t?.additionalDigits??2,i=function(e){const t={},a=e.split(Wl.dateTimeDelimiter);let i;if(a.length>2)return t;if(/:/.test(a[0])?i=a[0]:(t.date=a[0],i=a[1],Wl.timeZoneDelimiter.test(t.date)&&(t.date=e.split(Wl.timeZoneDelimiter)[0],i=e.substr(t.date.length,e.length))),i){const e=Wl.timezone.exec(i);e?(t.time=i.replace(e[1],""),t.timezone=e[1]):t.time=i}return t}(e);let s;if(i.date){const e=function(e,t){const a=new RegExp("^(?:(\\d{4}|[+-]\\d{"+(4+t)+"})|(\\d{2}|[+-]\\d{"+(2+t)+"})$)"),i=e.match(a);if(!i)return{year:NaN,restDateString:""};const s=i[1]?parseInt(i[1]):null,n=i[2]?parseInt(i[2]):null;return{year:null===n?s:100*n,restDateString:e.slice((i[1]||i[2]).length)}}(i.date,a);s=function(e,t){if(null===t)return new Date(NaN);const a=e.match(Vl);if(!a)return new Date(NaN);const i=!!a[4],s=Hl(a[1]),n=Hl(a[2])-1,r=Hl(a[3]),o=Hl(a[4]),l=Hl(a[5])-1;if(i)return function(e,t,a){return t>=1&&t<=53&&a>=0&&a<=6}(0,o,l)?function(e,t,a){const i=new Date(0);i.setUTCFullYear(e,0,4);const s=7*(t-1)+a+1-(i.getUTCDay()||7);return i.setUTCDate(i.getUTCDate()+s),i}(t,o,l):new Date(NaN);{const e=new Date(0);return function(e,t,a){return t>=0&&t<=11&&a>=1&&a<=(Yl[t]||(Kl(e)?29:28))}(t,n,r)&&function(e,t){return t>=1&&t<=(Kl(e)?366:365)}(t,s)?(e.setUTCFullYear(t,n,Math.max(s,r)),e):new Date(NaN)}}(e.restDateString,e.year)}if(!s||isNaN(s.getTime()))return new Date(NaN);const n=s.getTime();let r,o=0;if(i.time&&(o=function(e){const t=e.match(ql);if(!t)return NaN;const a=Gl(t[1]),i=Gl(t[2]),s=Gl(t[3]);return function(e,t,a){return 24===e?0===t&&0===a:a>=0&&a<60&&t>=0&&t<60&&e>=0&&e<25}(a,i,s)?a*$l.s0+i*$l.Cg+1e3*s:NaN}(i.time),isNaN(o)))return new Date(NaN);if(!i.timezone){const e=new Date(n+o),t=new Date(0);return t.setFullYear(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate()),t.setHours(e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds()),t}return r=function(e){if("Z"===e)return 0;const t=e.match(zl);if(!t)return 0;const a="+"===t[1]?-1:1,i=parseInt(t[2]),s=t[3]&&parseInt(t[3])||0;return function(e,t){return t>=0&&t<=59}(0,s)?a*(i*$l.s0+s*$l.Cg):NaN}(i.timezone),isNaN(r)?new Date(NaN):new Date(n+o+r)}const Wl={dateTimeDelimiter:/[T ]/,timeZoneDelimiter:/[Z ]/i,timezone:/([Z+-].*)$/},Vl=/^-?(?:(\d{3})|(\d{2})(?:-?(\d{2}))?|W(\d{2})(?:-?(\d{1}))?|)$/,ql=/^(\d{2}(?:[.,]\d*)?)(?::?(\d{2}(?:[.,]\d*)?))?(?::?(\d{2}(?:[.,]\d*)?))?$/,zl=/^([+-])(\d{2})(?::?(\d{2}))?$/;function Hl(e){return e?parseInt(e):1}function Gl(e){return e&&parseFloat(e.replace(",","."))||0}const Yl=[31,null,31,30,31,30,31,31,30,31,30,31];function Kl(e){return e%400==0||e%4==0&&e%100!=0}var Zl=a(85963);function Jl(e){if(!(t=e,t instanceof Date||"object"==typeof t&&"[object Date]"===Object.prototype.toString.call(t)||"number"==typeof e))return!1;var t;const a=(0,Zl.a)(e);return!isNaN(Number(a))}const Ql=e=>{if(null!==e){if(Array.isArray(e))throw new Error("convertDateToString can process only single date array given");return m.U.Date.format(e,{format:"Y-m-d"})}},Xl=e=>{if(!e)return;const t=Bl(e);return Jl(t)?t:void 0};function ed({filterIndex:e,defaultTimeframe:t=Il.VE.IN_THE_LAST}){const a=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilterFromEvent:i,updateSegmentFilter:s}=(0,fe.A)(Al.Hz);(0,r.useEffect)(()=>{(0,br.J)(a.timeframe,Il.VE)||s({timeframe:t},e),a.timeframe!==Il.VE.IN_THE_LAST||"string"!=typeof a.days||/^\d*$/.exec(a.days)||s({days:""},e),![Il.VE.BEFORE,Il.VE.AFTER,Il.VE.ON,Il.VE.BETWEEN].some(e=>e===a.timeframe)||void 0!==Xl(a.value||"")&&/^\d+-\d+-\d+$/.test(a.value||"")||s({value:Ql(new Date)},e),a.timeframe!==Il.VE.BETWEEN||void 0!==Xl(a.value2||"")&&/^\d+-\d+-\d+$/.test(a.value2||"")||s({value2:Ql(new Date)},e)},[a,s,e,t]);const n=a.timeframe===Il.VE.IN_THE_LAST,l=a.timeframe===Il.VE.BEFORE||a.timeframe===Il.VE.AFTER||a.timeframe===Il.VE.ON;return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(Be.Select,{value:a.timeframe,onChange:t=>{i("timeframe",e,t)},children:[(0,g.jsx)("option",{value:Il.VE.ALL_TIME,children:m.U.I18n.t("overAllTime")}),(0,g.jsx)("option",{value:Il.VE.IN_THE_LAST,children:m.U.I18n.t("inTheLast")}),(0,g.jsx)("option",{value:Il.VE.BEFORE,children:m.U.I18n.t("before")}),(0,g.jsx)("option",{value:Il.VE.AFTER,children:m.U.I18n.t("after")}),(0,g.jsx)("option",{value:Il.VE.ON,children:m.U.I18n.t("on")}),(0,g.jsx)("option",{value:Il.VE.BETWEEN,children:m.U.I18n.t("between")})]},"timeframe-select"),n&&(0,g.jsxs)("div",{className:"mailpoet-segments-date-period-controls",children:[(0,g.jsx)(o.Input,{className:"mailpoet-segments-input-small",type:"number",value:a.days||"","data-automation-id":"segment-number-of-days",onChange:t=>{i("days",e,t)},min:1,step:1,placeholder:m.U.I18n.t("daysPlaceholder")},"input"),(0,g.jsx)("span",{children:m.U.I18n.t("daysPlaceholder")})]}),l&&(0,g.jsx)("div",{className:"mailpoet-segments-date-period-controls",children:(0,g.jsx)(Hi.t,{className:"mailpoet-segments-datepicker-small",dateFormat:"MMM d, yyyy",onChange:t=>{s({value:Ql(t)},e)},selected:a.value?Xl(a.value):void 0})}),a.timeframe===Il.VE.BETWEEN&&(0,g.jsxs)("div",{className:"mailpoet-segments-date-period-controls",children:[(0,g.jsx)(Hi.t,{className:"mailpoet-segments-datepicker-small",dateFormat:"MMM d, yyyy",onChange:t=>{s({value:Ql(t)},e)},selected:a.value?Xl(a.value):void 0}),(0,g.jsx)(Hi.t,{className:"mailpoet-segments-datepicker-small",dateFormat:"MMM d, yyyy",onChange:t=>{s({value2:Ql(t)},e)},selected:a.value2?Xl(a.value2):void 0})]})]})}function td(e){return e.timeframe===Il.VE.ALL_TIME||([Il.VE.BEFORE,Il.VE.AFTER,Il.VE.ON].some(t=>t===e.timeframe)?/^\d+-\d+-\d+$/.test(e.value||""):e.timeframe===Il.VE.BETWEEN?/^\d+-\d+-\d+$/.test(e.value||"")&&/^\d+-\d+-\d+$/.test(e.value2||""):parseInt(e.days,10)>=1)}function ad({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilter:a,updateSegmentFilterFromEvent:i}=(0,fe.A)(Al.Hz);return(0,r.useEffect)(()=>{void 0===t.operator&&a({operator:"more"},e)},[a,t,e]),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(Di.Grid.CenteredRow,{children:(s=a=>"{condition}"===a?(0,g.jsxs)(Be.Select,{value:t.operator,onChange:t=>{i("operator",e,t)},children:[(0,g.jsx)("option",{value:"more",children:m.U.I18n.t("moreThan")}),(0,g.jsx)("option",{value:"less",children:m.U.I18n.t("lessThan")}),(0,g.jsx)("option",{value:"equals",children:m.U.I18n.t("equals")}),(0,g.jsx)("option",{value:"not_equals",children:m.U.I18n.t("notEquals")})]},"select"):"{opens}"===a?(0,g.jsx)(Dt.p,{type:"number",value:t.opens||"","data-automation-id":"segment-number-of-opens",onChange:t=>{i("opens",e,t)},min:"0",placeholder:m.U.I18n.t("emailActionOpens")},"input"):"string"==typeof a&&a.trim().length>1?(0,g.jsx)("div",{children:a},"opens"):null,m.U.I18n.t("emailActionOpensSentence").split(/({condition})|({opens})|(\b[a-zA-Z]+\b)/gim).map(s))}),(0,g.jsx)(ed,{filterIndex:e})]});var s}const id={[Il._R.OPENS_ABSOLUTE_COUNT]:ad,[Il._R.MACHINE_OPENS_ABSOLUTE_COUNT]:ad,[Il._R.CLICKED]:function({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilter:a,updateSegmentFilterFromEvent:i}=(0,fe.A)(Al.Hz),s=(0,C.A)(e=>e(Al.Hz).getNewslettersList(),[]),[n,o]=(0,r.useState)([]),[l,d]=(0,r.useState)([]),[c,u]=(0,r.useState)(!1),{flatOptions:p,groupedOptions:h}=Ol(s),_=(0,r.useCallback)(()=>{var e;Ll(t.newsletter_id)&&(d([]),e=t.newsletter_id,o([]),u(!0),m.U.Ajax.post({api_version:m.U.apiVersion,endpoint:"newsletter_links",action:"get",data:{newsletterId:e}}).then(e=>{const{data:t}=e,a=t.map(e=>({value:e.id,label:e.url}));u(!1),d(a)}).fail(e=>{o(e.errors)}))},[t.newsletter_id]);return(0,r.useEffect)(()=>{_()},[_,t.newsletter_id]),(0,r.useEffect)(()=>{t.operator!==Il.dP.ANY&&t.operator!==Il.dP.ALL&&t.operator!==Il.dP.NONE&&a({operator:Il.dP.ANY},e)},[t.operator,e,a]),(0,g.jsxs)(g.Fragment,{children:[n.length>0&&(0,g.jsx)(gi,{errors:n}),(0,g.jsx)(kl.ReactSelect,{placeholder:m.U.I18n.t("selectNewsletterPlaceholder"),options:h,value:p.find(({value:e})=>e===Number(t.newsletter_id)),onChange:t=>{a({newsletter_id:t.value,link_ids:[]},e)},automationId:"segment-email"}),(0,g.jsxs)(Be.Select,{isMinWidth:!0,value:t.operator,onChange:t=>{i("operator",e,t)},automationId:"select-operator",children:[(0,g.jsx)("option",{value:Il.dP.ANY,children:m.U.I18n.t("anyOf")}),(0,g.jsx)("option",{value:Il.dP.ALL,children:m.U.I18n.t("allOf")}),(0,g.jsx)("option",{value:Il.dP.NONE,children:m.U.I18n.t("noneOf")})]},"select-operator"),c&&(0,g.jsx)("span",{children:m.U.I18n.t("loadingDynamicSegmentItems")}),!c&&Ll(t.newsletter_id)&&(0,g.jsx)(kl.ReactSelect,{isMulti:!0,automationId:"segment-link-select",placeholder:m.U.I18n.t("allLinksPlaceholder"),options:l.length?l:[{value:0,label:m.U.I18n.t("noLinksHint"),isDisabled:!0}],value:(0,Sn.filter)(e=>!!t.link_ids&&-1!==t.link_ids.indexOf(e.value),l),onChange:t=>{a({link_ids:(t||[]).map(e=>e.value)},e)}})]})},[Il._R.OPENED]:Ml,[Il._R.WAS_SENT]:Ml,[Il._R.MACHINE_OPENED]:Ml,[Il._R.CLICKED_ANY]:null,[Il._R.NUMBER_RECEIVED]:function({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilter:a,updateSegmentFilterFromEvent:i}=(0,fe.A)(Al.Hz);return(0,r.useEffect)(()=>{["more","less","equals","not_equals"].includes(t.operator)||a({operator:"more"},e)},[a,t,e]),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(Di.Grid.CenteredRow,{children:(s=a=>"{condition}"===a?(0,g.jsxs)(Be.Select,{value:t.operator,onChange:t=>{i("operator",e,t)},children:[(0,g.jsx)("option",{value:"more",children:m.U.I18n.t("moreThan")}),(0,g.jsx)("option",{value:"less",children:m.U.I18n.t("lessThan")}),(0,g.jsx)("option",{value:"equals",children:m.U.I18n.t("equals")}),(0,g.jsx)("option",{value:"not_equals",children:m.U.I18n.t("notEquals")})]},"select"):"{emails}"===a?(0,g.jsx)(Dt.p,{type:"number",value:t.emails||"","data-automation-id":"segment-number-emails-received",onChange:t=>{i("emails",e,t)},min:"0",placeholder:(0,p.__)("emails","mailpoet")},"input"):"string"==typeof a&&a.trim().length>1?(0,g.jsx)("div",{children:a},"emails"):null,(0,p.__)("{condition} {emails} emails","mailpoet").split(/({condition})|({emails})|(\b[a-zA-Z]+\b)/gim).map(s))}),(0,g.jsx)(ed,{filterIndex:e})]});var s},[Il._R.NUMBER_OF_CLICKS]:function({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilter:a,updateSegmentFilterFromEvent:i}=(0,fe.A)(Al.Hz);return(0,r.useEffect)(()=>{["more","less","equals","not_equals"].includes(t.operator)||a({operator:"more"},e)},[a,t,e]),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(Di.Grid.CenteredRow,{children:(s=a=>"{condition}"===a?(0,g.jsxs)(Be.Select,{value:t.operator,onChange:t=>{i("operator",e,t)},children:[(0,g.jsx)("option",{value:"more",children:m.U.I18n.t("moreThan")}),(0,g.jsx)("option",{value:"less",children:m.U.I18n.t("lessThan")}),(0,g.jsx)("option",{value:"equals",children:m.U.I18n.t("equals")}),(0,g.jsx)("option",{value:"not_equals",children:m.U.I18n.t("notEquals")})]},"select"):"{clicks}"===a?(0,g.jsx)(Dt.p,{type:"number",value:t.clicks||"","data-automation-id":"segment-number-of-clicks",onChange:t=>{i("clicks",e,t)},min:"0",placeholder:(0,p.__)("clicks","mailpoet")},"input"):"string"==typeof a&&a.trim().length>1?(0,g.jsx)("div",{children:a},"clicks"):null,(0,p.__)("{condition} {clicks} clicks","mailpoet").split(/({condition})|({clicks})|(\b[a-zA-Z]+\b)/gim).map(s))}),(0,g.jsx)(ed,{filterIndex:e})]});var s}};let sd=function(e){return e.BEFORE="before",e.AFTER="after",e.ON="on",e.ON_OR_BEFORE="onOrBefore",e.ON_OR_AFTER="onOrAfter",e.NOT_ON="notOn",e.BETWEEN="between",e.IN_THE_LAST="inTheLast",e.NOT_IN_THE_LAST="notInTheLast",e}({});const nd=[sd.BEFORE,sd.AFTER,sd.ON,sd.ON_OR_AFTER,sd.ON_OR_BEFORE,sd.NOT_ON,sd.BETWEEN,sd.IN_THE_LAST,sd.NOT_IN_THE_LAST];function rd({filterIndex:e,defaultOperator:t}){const a=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilter:i,updateSegmentFilterFromEvent:s}=(0,fe.A)(Al.Hz);return(0,r.useEffect)(()=>{nd.includes(a.operator)||i({operator:t},e),a.operator!==sd.BEFORE&&a.operator!==sd.AFTER&&a.operator!==sd.ON&&a.operator!==sd.ON_OR_AFTER&&a.operator!==sd.ON_OR_BEFORE&&a.operator!==sd.BETWEEN&&a.operator!==sd.NOT_ON||void 0!==Xl(a.value)&&/^\d+-\d+-\d+$/.test(a.value)||i({value:Ql(new Date)},e),a.operator!==sd.BETWEEN||void 0!==Xl(a.value2||"")&&/^\d+-\d+-\d+$/.test(a.value2||"")||i({value2:Ql(new Date)},e),a.operator!==sd.IN_THE_LAST&&a.operator!==sd.NOT_IN_THE_LAST||"string"!=typeof a.value||/^\d*$/.exec(a.value)||i({value:""},e)},[i,a,e,t]),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(Be.Select,{value:a.operator,isMinWidth:!0,onChange:t=>{s("operator",e,t)},children:[(0,g.jsx)("option",{value:sd.BEFORE,children:m.U.I18n.t("before")}),(0,g.jsx)("option",{value:sd.ON_OR_BEFORE,children:m.U.I18n.t("onOrBefore")}),(0,g.jsx)("option",{value:sd.ON,children:m.U.I18n.t("on")}),(0,g.jsx)("option",{value:sd.NOT_ON,children:m.U.I18n.t("notOn")}),(0,g.jsx)("option",{value:sd.BETWEEN,children:m.U.I18n.t("between")}),(0,g.jsx)("option",{value:sd.ON_OR_AFTER,children:m.U.I18n.t("onOrAfter")}),(0,g.jsx)("option",{value:sd.AFTER,children:m.U.I18n.t("after")}),(0,g.jsx)("option",{value:sd.IN_THE_LAST,children:m.U.I18n.t("inTheLast")}),(0,g.jsx)("option",{value:sd.NOT_IN_THE_LAST,children:m.U.I18n.t("notInTheLast")})]},"select"),(a.operator===sd.BEFORE||a.operator===sd.AFTER||a.operator===sd.ON||a.operator===sd.ON_OR_AFTER||a.operator===sd.ON_OR_BEFORE||a.operator===sd.NOT_ON)&&(0,g.jsx)(Hi.t,{className:"mailpoet-segments-datepicker-small",dateFormat:"MMM d, yyyy",onChange:t=>{i({value:Ql(t)},e)},selected:a.value?Xl(a.value):void 0}),a.operator===sd.BETWEEN&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(Hi.t,{className:"mailpoet-segments-datepicker-small",dateFormat:"MMM d, yyyy",onChange:t=>{i({value:Ql(t)},e)},selected:a.value?Xl(a.value):void 0}),(0,g.jsx)(Hi.t,{className:"mailpoet-segments-datepicker-small",dateFormat:"MMM d, yyyy",onChange:t=>{i({value2:Ql(t)},e)},selected:a.value2?Xl(a.value2):void 0})]}),(a.operator===sd.IN_THE_LAST||a.operator===sd.NOT_IN_THE_LAST)&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(Dt.p,{className:"mailpoet-segments-input-small",type:"number",value:a.value||"",onChange:t=>{s("value",e,t)},min:"1",placeholder:m.U.I18n.t("daysPlaceholder")},"input"),(0,g.jsx)("span",{children:m.U.I18n.t("daysPlaceholder")})]})]})}function od(e){if(!e.operator||!e.value)return!1;if([sd.BEFORE,sd.AFTER,sd.ON,sd.NOT_ON,sd.ON_OR_BEFORE,sd.ON_OR_AFTER].includes(e.operator))return/^\d+-\d+-\d+$/.test(e.value);if([sd.IN_THE_LAST,sd.NOT_IN_THE_LAST].includes(e.operator))return/^\d+$/.test(e.value)&&Number(e.value)>0;if(e.operator===sd.BETWEEN){const t=/^\d+-\d+-\d+$/;return t.test(e.value)&&t.test(e.value2||"")}return!1}function ld(e){return function(t){return(0,g.jsx)(rd,{...t,defaultOperator:e})}}const dd=ld(sd.BEFORE),cd=ld(sd.IN_THE_LAST);var md=a(40658);function ud({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilter:a,updateSegmentFilterFromEvent:i}=(0,fe.A)(Al.Hz);return(0,r.useEffect)(()=>{void 0===t.number_of_orders_type&&a({number_of_orders_type:"="},e)},[a,t,e]),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(Di.Grid.CenteredRow,{children:[(0,g.jsxs)(o.Select,{value:t.number_of_orders_type,onChange:t=>{i("number_of_orders_type",e,t)},automationId:"select-number-of-orders-type",children:[(0,g.jsx)("option",{value:"=",children:m.U.I18n.t("equals")}),(0,g.jsx)("option",{value:"!=",children:m.U.I18n.t("notEquals")}),(0,g.jsx)("option",{value:">",children:m.U.I18n.t("moreThan")}),(0,g.jsx)("option",{value:"<",children:m.U.I18n.t("lessThan")})]},"select"),(0,g.jsx)(o.Input,{"data-automation-id":"input-number-of-orders-count",type:"number",min:0,value:t.number_of_orders_count||"",placeholder:m.U.I18n.t("wooNumberOfOrdersCount"),onChange:t=>{i("number_of_orders_count",e,t)}}),(0,g.jsx)("div",{children:m.U.I18n.t("wooNumberOfOrdersOrders")})]}),(0,g.jsx)(ed,{filterIndex:e})]})}const pd=["is","isNot","contains","notContains","startsWith","notStartsWith","endsWith","notEndsWith"];function hd(e){return!!pd.includes(e.operator)&&"string"==typeof e.value&&e.value.length>0}function gd({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilterFromEvent:a,updateSegmentFilter:i}=(0,fe.A)(Al.Hz);return(0,r.useEffect)(()=>{pd.includes(t.operator)||i({operator:"is",value:""},e)},[i,t,e]),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(Be.Select,{automationId:"subscriber-text-field-select",value:t.operator,isMinWidth:!0,onChange:t=>{a("operator",e,t)},children:[(0,g.jsx)("option",{value:"is",children:m.U.I18n.t("is")}),(0,g.jsx)("option",{value:"isNot",children:m.U.I18n.t("isNot")}),(0,g.jsx)("option",{value:"contains",children:m.U.I18n.t("contains")}),(0,g.jsx)("option",{value:"notContains",children:m.U.I18n.t("notContains")}),(0,g.jsx)("option",{value:"startsWith",children:m.U.I18n.t("startsWith")}),(0,g.jsx)("option",{value:"notStartsWith",children:m.U.I18n.t("notStartsWith")}),(0,g.jsx)("option",{value:"endsWith",children:m.U.I18n.t("endsWith")}),(0,g.jsx)("option",{value:"notEndsWith",children:m.U.I18n.t("notEndsWith")})]},"select"),(0,g.jsx)(Dt.p,{className:"mailpoet-segments-input-medium","data-automation-id":"text-custom-field-value",value:t.value||"",onChange:t=>{a("value",e,t)},placeholder:m.U.I18n.t("value")},"input")]})}const _d={[md.Ag.CUSTOMER_IN_COUNTRY]:function({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilter:a}=(0,fe.A)(Al.Hz),i=(0,C.A)(e=>e(Al.Hz).getWooCommerceCountries(),[]).map(e=>({value:e.code,label:e.name}));return(0,r.useEffect)(()=>{t.operator!==Il.dP.ANY&&t.operator!==Il.dP.NONE&&a({operator:Il.dP.ANY},e)},[a,t,e]),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(Be.Select,{value:t.operator,isMinWidth:!0,onChange:t=>{a({operator:t.target.value},e)},automationId:"select-operator-country",children:[(0,g.jsx)("option",{value:Il.dP.ANY,children:m.U.I18n.t("anyOf")}),(0,g.jsx)("option",{value:Il.dP.NONE,children:m.U.I18n.t("noneOf")})]},"select-operator-country"),(0,g.jsx)(kl.ReactSelect,{dimension:"small",isMulti:!0,placeholder:m.U.I18n.t("selectWooCountry"),options:i,value:(0,Sn.filter)(e=>{if(t.country_code)return-1!==t.country_code.indexOf(e.value)},i),onChange:t=>{a({country_code:(t||[]).map(e=>e.value)},e)},automationId:"select-segment-country"},"select-segment-country")]})},[md.Ag.CUSTOMER_IN_CITY]:gd,[md.Ag.CUSTOMER_IN_POSTAL_CODE]:gd,[md.Ag.NUMBER_OF_ORDERS]:ud,[md.Ag.NUMBER_OF_ORDERS_WITH_COUPON]:ud,[md.Ag.NUMBER_OF_REVIEWS]:function({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilter:a,updateSegmentFilterFromEvent:i}=(0,fe.A)(Al.Hz);return(0,r.useEffect)(()=>{(0,br.J)(t.count_type,Il.YR)||a({count_type:Il.YR.EQUALS},e),(0,br.J)(t.rating,Il.Un)||a({rating:Il.Un.ANY},e),(0,br.J)(t.timeframe,Il.VE)||a({timeframe:Il.VE.IN_THE_LAST},e)},[a,t,e]),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(o.Select,{value:t.rating,isMinWidth:!0,onChange:t=>{i("rating",e,t)},children:[(0,g.jsx)("option",{value:Il.Un.ANY,children:m.U.I18n.t("wooAnyStarRating")}),(0,g.jsx)("option",{value:Il.Un.ONE,children:m.U.I18n.t("wooOneStarRating")}),(0,g.jsx)("option",{value:Il.Un.TWO,children:m.U.I18n.t("wooTwoStarRating")}),(0,g.jsx)("option",{value:Il.Un.THREE,children:m.U.I18n.t("wooThreeStarRating")}),(0,g.jsx)("option",{value:Il.Un.FOUR,children:m.U.I18n.t("wooFourStarRating")}),(0,g.jsx)("option",{value:Il.Un.FIVE,children:m.U.I18n.t("wooFiveStarRating")})]},"rating-select"),(0,g.jsxs)(o.Select,{value:t.count_type,isMinWidth:!0,onChange:t=>{i("count_type",e,t)},automationId:"select-number-of-reviews-type",children:[(0,g.jsx)("option",{value:Il.YR.EQUALS,children:m.U.I18n.t("equals")}),(0,g.jsx)("option",{value:Il.YR.NOT_EQUALS,children:m.U.I18n.t("notEquals")}),(0,g.jsx)("option",{value:Il.YR.MORE_THAN,children:m.U.I18n.t("moreThan")}),(0,g.jsx)("option",{value:Il.YR.LESS_THAN,children:m.U.I18n.t("lessThan")})]},"select"),(0,g.jsx)(o.Input,{className:"mailpoet-segments-input-small","data-automation-id":"input-number-of-reviews-count",type:"number",min:0,value:t.count||"",placeholder:m.U.I18n.t("wooNumberOfOrdersCount"),onChange:t=>{i("count",e,t)}}),(0,g.jsx)("div",{children:m.U.I18n.t("wooNumberOfReviewsReviews")}),(0,g.jsx)(ed,{filterIndex:e})]})},[md.Ag.PURCHASE_DATE]:dd,[md.Ag.PURCHASED_PRODUCT]:function({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilter:a}=(0,fe.A)(Al.Hz),i=(0,C.A)(e=>e(Al.Hz).getProducts(),[]).map(e=>({value:e.id,label:e.name}));return(0,r.useEffect)(()=>{t.operator!==Il.dP.ALL&&t.operator!==Il.dP.ANY&&t.operator!==Il.dP.NONE&&a({operator:Il.dP.ANY},e)},[a,t,e]),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(Be.Select,{value:t.operator,isMinWidth:!0,onChange:t=>{a({operator:t.target.value},e)},automationId:"select-operator",children:[(0,g.jsx)("option",{value:Il.dP.ANY,children:m.U.I18n.t("anyOf")}),(0,g.jsx)("option",{value:Il.dP.ALL,children:m.U.I18n.t("allOf")}),(0,g.jsx)("option",{value:Il.dP.NONE,children:m.U.I18n.t("noneOf")})]},"select-operator"),(0,g.jsx)(kl.ReactSelect,{isMulti:!0,dimension:"small",placeholder:m.U.I18n.t("selectWooPurchasedProduct"),options:i,value:(0,Sn.filter)(e=>{if(void 0!==t.product_ids&&0!==t.product_ids.length)return-1!==t.product_ids.indexOf(e.value)},i),onChange:t=>{a({product_ids:(t||[]).map(e=>e.value)},e)},automationId:"select-segment-products"},"select-segment-products"),(0,g.jsx)(ed,{filterIndex:e,defaultTimeframe:Il.VE.ALL_TIME})]})},[md.Ag.PURCHASED_PRODUCT_VARIATION]:function({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilter:a}=(0,fe.A)(Al.Hz),i=(0,C.A)(e=>e(Al.Hz).getVariableProducts(),[]),s=(0,r.useMemo)(()=>i.map(e=>({value:e.id,label:e.name})),[i]),[n,o]=(0,r.useState)(void 0),[l,d]=(0,r.useState)([]),[c,u]=(0,r.useState)(!1),[h,_]=(0,r.useState)(!1),f=(0,r.useRef)(0),b=(0,r.useCallback)(e=>{f.current+=1;const t=f.current;u(!0),m.U.Ajax.post({api_version:m.U.apiVersion,endpoint:"woocommerce_product_variations",action:"getVariations",data:{product_id:e}}).then(e=>{t===f.current&&d(e.data.variations.map(e=>({value:e.id,label:e.name})))}).always(()=>{t===f.current&&u(!1)})},[]),x=(0,r.useCallback)(e=>{f.current+=1;const t=f.current;u(!0),m.U.Ajax.post({api_version:m.U.apiVersion,endpoint:"woocommerce_product_variations",action:"getVariations",data:{variation_id:e}}).then(e=>{t===f.current&&(e.data.product&&o(e.data.product.id),d(e.data.variations.map(e=>({value:e.id,label:e.name}))))}).always(()=>{t===f.current&&u(!1)})},[]);(0,r.useEffect)(()=>{t.operator!==Il.dP.ALL&&t.operator!==Il.dP.ANY&&t.operator!==Il.dP.NONE&&a({operator:Il.dP.ANY},e)},[a,t.operator,e]),(0,r.useEffect)(()=>{h||(_(!0),Array.isArray(t.variation_ids)&&t.variation_ids.length>0&&x(t.variation_ids[0]))},[h,t.variation_ids,x]);const v=(0,Sn.filter)(e=>!(!Array.isArray(t.variation_ids)||0===t.variation_ids.length)&&-1!==t.variation_ids.indexOf(e.value),l),y=n&&s.find(e=>e.value===n)||null;return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(Be.Select,{value:t.operator,isMinWidth:!0,onChange:t=>{a({operator:t.target.value},e)},automationId:"select-operator",children:[(0,g.jsx)("option",{value:Il.dP.ANY,children:m.U.I18n.t("anyOf")}),(0,g.jsx)("option",{value:Il.dP.ALL,children:m.U.I18n.t("allOf")}),(0,g.jsx)("option",{value:Il.dP.NONE,children:m.U.I18n.t("noneOf")})]},"select-operator"),(0,g.jsx)(kl.ReactSelect,{dimension:"small",isClearable:!0,placeholder:m.U.I18n.t("selectWooVariableProduct"),options:s,value:y,onChange:t=>(t=>{const i=t?t.value:void 0;o(i),d([]),a({variation_ids:[]},e),i&&b(i)})(t),automationId:"select-variable-product"},"select-variable-product"),(0,g.jsx)(kl.ReactSelect,{isMulti:!0,dimension:"small",placeholder:c?(0,p.__)("Loading variations…","mailpoet"):m.U.I18n.t("selectWooPurchasedProductVariation"),isDisabled:!n||c,options:l,value:v,onChange:t=>{a({variation_ids:(t||[]).map(e=>e.value)},e)},automationId:"select-product-variations"},"select-product-variations"),(0,g.jsx)(ed,{filterIndex:e,defaultTimeframe:Il.VE.ALL_TIME})]})},[md.Ag.PURCHASED_CATEGORY]:function({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilter:a}=(0,fe.A)(Al.Hz),i=(0,C.A)(e=>e(Al.Hz).getProductCategories(),[]).map(e=>({value:e.id,label:e.name}));return(0,r.useEffect)(()=>{t.operator!==Il.dP.ALL&&t.operator!==Il.dP.ANY&&t.operator!==Il.dP.NONE&&a({operator:Il.dP.ANY},e)},[a,t,e]),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(Be.Select,{value:t.operator,isMinWidth:!0,onChange:t=>{a({operator:t.target.value},e)},automationId:"select-operator",children:[(0,g.jsx)("option",{value:Il.dP.ANY,children:m.U.I18n.t("anyOf")}),(0,g.jsx)("option",{value:Il.dP.ALL,children:m.U.I18n.t("allOf")}),(0,g.jsx)("option",{value:Il.dP.NONE,children:m.U.I18n.t("noneOf")})]},"select-operator"),(0,g.jsx)(kl.ReactSelect,{isMulti:!0,dimension:"small",placeholder:m.U.I18n.t("selectWooPurchasedCategory"),options:i,value:(0,Sn.filter)(e=>{if(void 0!==t.category_ids&&0!==t.category_ids.length)return-1!==t.category_ids.indexOf(e.value)},i),onChange:t=>{a({category_ids:(t||[]).map(e=>e.value)},e)},automationId:"select-segment-category"},"select-segment-category"),(0,g.jsx)(ed,{filterIndex:e,defaultTimeframe:Il.VE.ALL_TIME})]})},[md.Ag.PURCHASED_WITH_ATTRIBUTE]:function({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilter:a}=(0,fe.A)(Al.Hz),i=(0,C.A)(e=>e(Al.Hz).getProductAttributes(),[]),s=(0,r.useMemo)(()=>Object.values(i).filter(e=>e.terms.length>0).map(e=>({value:e.taxonomy,label:e.label})),[i]),n=(0,C.A)(e=>e(Al.Hz).getLocalProductAttributes(),[]),o=(0,r.useMemo)(()=>Object.values(n).filter(e=>e.values.length>0).map(e=>({value:`${e.name}@local`,label:e.name})),[n]),l=(0,r.useMemo)(()=>Object.values(o).map(e=>e.value),[o]),d=(0,r.useMemo)(()=>[...s,...o],[s,o]),c=(0,r.useMemo)(()=>"taxonomy"===t.attribute_type?i[t.attribute_taxonomy_slug].terms.map(e=>({value:e.term_id.toString(),label:e.name})):"local"===t.attribute_type?n[t.attribute_local_name].values.map(e=>({value:e,label:e})):[],[t.attribute_type,t.attribute_taxonomy_slug,t.attribute_local_name,i,n]);(0,r.useEffect)(()=>{t.operator!==Il.dP.ALL&&t.operator!==Il.dP.ANY&&t.operator!==Il.dP.NONE&&a({operator:Il.dP.ANY},e)},[a,t,e]);const m=(0,r.useCallback)(t=>{l.includes(t.value)?a({attribute_type:"local",attribute_local_name:t.value.replace(/@local$/,""),attribute_local_values:[],attribute_taxonomy_slug:null,attribute_term_ids:null},e):a({attribute_type:"taxonomy",attribute_local_name:null,attribute_local_values:null,attribute_taxonomy_slug:t.value,attribute_term_ids:[]},e)},[e,l,a]),u=(0,r.useMemo)(()=>"local"===t.attribute_type?(0,Sn.filter)(e=>{if(t.attribute_local_name)return`${t.attribute_local_name}@local`===e.value},o):(0,Sn.filter)(e=>{if(void 0!==t.attribute_taxonomy_slug)return t.attribute_taxonomy_slug===e.value},s),[t.attribute_type,t.attribute_local_name,t.attribute_taxonomy_slug,o,s]),h=(0,r.useMemo)(()=>(0,Sn.filter)(e=>t.attribute_local_values?-1!==t.attribute_local_values.indexOf(e.value):t.attribute_term_ids?-1!==t.attribute_term_ids.indexOf(e.value):void 0,c),[t.attribute_local_values,t.attribute_term_ids,c]),_=(0,r.useCallback)(i=>{"local"===t.attribute_type?a({attribute_term_ids:null,attribute_local_values:(i||[]).map(e=>e.value)},e):a({attribute_term_ids:(i||[]).map(e=>e.value),attribute_local_values:null},e)},[t.attribute_type,a,e]);return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(Be.Select,{value:t.operator,isMinWidth:!0,onChange:t=>{a({operator:t.target.value},e)},children:[(0,g.jsx)("option",{value:Il.dP.ANY,children:(0,p.__)("any of","mailpoet")}),(0,g.jsx)("option",{value:Il.dP.ALL,children:(0,p.__)("all of","mailpoet")}),(0,g.jsx)("option",{value:Il.dP.NONE,children:(0,p.__)("none of","mailpoet")})]},"select-operator"),(0,g.jsx)(kl.ReactSelect,{dimension:"small",placeholder:(0,p.__)("Search attributes","mailpoet"),options:d,value:u,onChange:m},"select-segment-product-attribute"),c.length>0&&(0,g.jsx)(kl.ReactSelect,{dimension:"small",isMulti:!0,placeholder:(0,p.__)("Search attributes terms","mailpoet"),options:c,value:h,onChange:_},"select-segment-product-attribute-terms"),(0,g.jsx)(ed,{filterIndex:e,defaultTimeframe:Il.VE.ALL_TIME})]})},[md.Ag.PURCHASED_TAG]:function({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilter:a}=(0,fe.A)(Al.Hz),i=(0,C.A)(e=>e(Al.Hz).getProductTags(),[]).map(e=>({value:e.id,label:e.name}));return(0,r.useEffect)(()=>{t.operator!==Il.dP.ALL&&t.operator!==Il.dP.ANY&&t.operator!==Il.dP.NONE&&a({operator:Il.dP.ANY},e)},[a,t,e]),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(Be.Select,{value:t.operator,isMinWidth:!0,onChange:t=>{a({operator:t.target.value},e)},automationId:"select-operator",children:[(0,g.jsx)("option",{value:Il.dP.ANY,children:m.U.I18n.t("anyOf")}),(0,g.jsx)("option",{value:Il.dP.ALL,children:m.U.I18n.t("allOf")}),(0,g.jsx)("option",{value:Il.dP.NONE,children:m.U.I18n.t("noneOf")})]},"select-operator"),(0,g.jsx)(kl.ReactSelect,{isMulti:!0,dimension:"small",placeholder:(0,p.__)("Search tags","mailpoet"),options:i,value:(0,Sn.filter)(e=>{if(void 0!==t.tag_ids&&0!==t.tag_ids.length)return-1!==t.tag_ids.indexOf(e.value)},i),onChange:t=>{a({tag_ids:(t||[]).map(e=>e.value)},e)},automationId:"select-segment-tags"},"select-segment-tag"),(0,g.jsx)(ed,{filterIndex:e,defaultTimeframe:Il.VE.ALL_TIME})]})},[md.Ag.SINGLE_ORDER_VALUE]:function({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilter:a,updateSegmentFilterFromEvent:i}=(0,fe.A)(Al.Hz),s=(0,C.A)(e=>e(Al.Hz).getWooCommerceCurrencySymbol(),[]);return(0,r.useEffect)(()=>{void 0===t.single_order_value_type&&a({single_order_value_type:">"},e)},[a,t,e]),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(Di.Grid.CenteredRow,{children:[(0,g.jsxs)(o.Select,{value:t.single_order_value_type,onChange:t=>{i("single_order_value_type",e,t)},automationId:"select-single-order-value-type",children:[(0,g.jsx)("option",{value:">",children:m.U.I18n.t("moreThan")}),(0,g.jsx)("option",{value:">=",children:m.U.I18n.t("moreThanOrEqual")}),(0,g.jsx)("option",{value:"=",children:m.U.I18n.t("equals")}),(0,g.jsx)("option",{value:"!=",children:m.U.I18n.t("notEquals")}),(0,g.jsx)("option",{value:"<=",children:m.U.I18n.t("lessThanOrEqual")}),(0,g.jsx)("option",{value:"<",children:m.U.I18n.t("lessThan")})]},"select"),(0,g.jsx)(o.Input,{"data-automation-id":"input-single-order-value-amount",type:"number",min:0,step:.01,value:t.single_order_value_amount||"",placeholder:m.U.I18n.t("wooSpentAmount"),onChange:t=>{i("single_order_value_amount",e,t)}}),(0,g.jsx)("div",{children:s})]}),(0,g.jsx)(ed,{filterIndex:e})]})},[md.Ag.TOTAL_SPENT]:function({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilter:a,updateSegmentFilterFromEvent:i}=(0,fe.A)(Al.Hz),s=(0,C.A)(e=>e(Al.Hz).getWooCommerceCurrencySymbol(),[]);return(0,r.useEffect)(()=>{void 0===t.total_spent_type&&a({total_spent_type:">"},e)},[a,t,e]),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(Di.Grid.CenteredRow,{children:[(0,g.jsxs)(o.Select,{value:t.total_spent_type,onChange:t=>{i("total_spent_type",e,t)},automationId:"select-total-spent-type",children:[(0,g.jsx)("option",{value:"=",children:m.U.I18n.t("equals")}),(0,g.jsx)("option",{value:"!=",children:m.U.I18n.t("notEquals")}),(0,g.jsx)("option",{value:">",children:m.U.I18n.t("moreThan")}),(0,g.jsx)("option",{value:"<",children:m.U.I18n.t("lessThan")})]},"select"),(0,g.jsx)(o.Input,{"data-automation-id":"input-total-spent-amount",type:"number",min:0,step:.01,value:t.total_spent_amount||"",placeholder:m.U.I18n.t("wooSpentAmount"),onChange:t=>{i("total_spent_amount",e,t)}}),(0,g.jsx)("div",{children:s})]}),(0,g.jsx)(ed,{filterIndex:e})]})},[md.Ag.AVERAGE_SPENT]:function({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilter:a,updateSegmentFilterFromEvent:i}=(0,fe.A)(Al.Hz),s=(0,C.A)(e=>e(Al.Hz).getWooCommerceCurrencySymbol(),[]);return(0,r.useEffect)(()=>{[">",">=","=","!=","<=","<"].includes(t.average_spent_type)||a({average_spent_type:">"},e)},[a,t,e]),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(o.Select,{value:t.average_spent_type,isMinWidth:!0,onChange:t=>{i("average_spent_type",e,t)},automationId:"select-average-spent-type",children:[(0,g.jsx)("option",{value:">",children:m.U.I18n.t("moreThan")}),(0,g.jsx)("option",{value:">=",children:m.U.I18n.t("moreThanOrEqual")}),(0,g.jsx)("option",{value:"=",children:m.U.I18n.t("equals")}),(0,g.jsx)("option",{value:"!=",children:m.U.I18n.t("notEquals")}),(0,g.jsx)("option",{value:"<=",children:m.U.I18n.t("lessThanOrEqual")}),(0,g.jsx)("option",{value:"<",children:m.U.I18n.t("lessThan")})]},"select"),(0,g.jsx)(o.Input,{className:"mailpoet-segments-input-small","data-automation-id":"input-average-spent-amount",type:"number",min:0,step:.01,value:t.average_spent_amount||"",placeholder:m.U.I18n.t("wooSpentAmount"),onChange:t=>{i("average_spent_amount",e,t)}}),(0,g.jsx)("div",{children:s}),(0,g.jsx)(ed,{filterIndex:e})]})},[md.Ag.USED_COUPON_CODE]:function({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilter:a}=(0,fe.A)(Al.Hz),[i,s]=(0,r.useState)(!1),[n,l]=(0,r.useState)([]),[d,c]=(0,r.useState)(!1),[u,h]=(0,r.useState)(1),[_,f]=(0,r.useState)(!0),[b,x]=(0,r.useState)(""),[v,y]=(0,r.useState)([]),w=(0,r.useCallback)((e,a,i,s)=>{s&&(e||c(!0),m.U.Ajax.post({api_version:m.U.apiVersion,endpoint:"coupons",action:"getCoupons",data:{page_number:a,page_size:1e3,include_coupon_ids:t.coupon_code_ids,search:i}}).then(t=>{const{data:i}=t,s=i.map(e=>({value:e.id.toString(),label:e.text})),n=a+1;0===s.length?f(!1):(l(e=>(0,Sn.uniqBy)(e=>e.value,[...e,...s])),h(n)),e||c(!1)}).fail(e=>{y(e.errors)}))},[t.coupon_code_ids]),j=(0,Sn.debounce)(300,e=>{const t=b;x(e),!d&&(_&&e||t&&!e)&&(h(1),w(!1,1,e,_))});return(0,r.useEffect)(()=>{i||(w(!0,u,b,_),s(!0))},[i,u,b,w,_]),(0,r.useEffect)(()=>{Array.isArray(t.coupon_code_ids)||a({coupon_code_ids:[]},e),(0,br.J)(t.operator,Il.dP)||a({operator:Il.dP.ANY},e)},[a,t,e]),(0,g.jsxs)(g.Fragment,{children:[v.length>0&&(0,g.jsx)(gi,{errors:v}),i?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(Di.Grid.CenteredRow,{children:[(0,g.jsxs)(o.Select,{isMaxContentWidth:!0,value:t.operator,onChange:t=>{a({operator:t.target.value},e)},automationId:"select-operator-used-coupon-code",children:[(0,g.jsx)("option",{value:Il.dP.ANY,children:m.U.I18n.t("anyOf")}),(0,g.jsx)("option",{value:Il.dP.ALL,children:m.U.I18n.t("allOf")}),(0,g.jsx)("option",{value:Il.dP.NONE,children:m.U.I18n.t("noneOf")})]},"select-operator-used-coupon-codes"),(0,g.jsx)(kl.ReactSelect,{isFullWidth:!0,isMulti:!0,isLoadingMore:d,placeholder:m.U.I18n.t("selectWooCouponCodes"),options:n,value:(0,Sn.filter)(e=>{if(t.coupon_code_ids)return-1!==t.coupon_code_ids.indexOf(e.value)},n),onInputChange:e=>{j(e)},onChange:t=>{a({coupon_code_ids:(t||[]).map(e=>e.value)},e)},automationId:"select-shipping-methods",onMenuScrollToBottom:()=>{!d&&_&&w(!1,u,b,_)}},"select-coupon-codes")]}),(0,g.jsx)(ed,{filterIndex:e})]}):(0,g.jsx)(Di.Grid.CenteredRow,{children:(0,p.__)("Loading coupon codes...","mailpoet")})]})},[md.Ag.USED_PAYMENT_METHOD]:function({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilter:a}=(0,fe.A)(Al.Hz),i=(0,C.A)(e=>e(Al.Hz).getPaymentMethods(),[]).map(e=>({value:e.id,label:e.name}));return(0,r.useEffect)(()=>{t.operator!==Il.dP.ANY&&t.operator!==Il.dP.ALL&&t.operator!==Il.dP.NONE&&a({operator:Il.dP.ANY},e)},[a,t,e]),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(Di.Grid.CenteredRow,{children:[(0,g.jsxs)(o.Select,{isMaxContentWidth:!0,value:t.operator,onChange:t=>{a({operator:t.target.value},e)},automationId:"select-operator-used-payment-methods",children:[(0,g.jsx)("option",{value:Il.dP.ANY,children:m.U.I18n.t("anyOf")}),(0,g.jsx)("option",{value:Il.dP.ALL,children:m.U.I18n.t("allOf")}),(0,g.jsx)("option",{value:Il.dP.NONE,children:m.U.I18n.t("noneOf")})]},"select-operator-used-payment-methods"),(0,g.jsx)(kl.ReactSelect,{isFullWidth:!0,isMulti:!0,placeholder:m.U.I18n.t("selectWooPaymentMethods"),options:i,value:(0,Sn.filter)(e=>{if(t.payment_methods)return-1!==t.payment_methods.indexOf(e.value)},i),onChange:t=>{a({payment_methods:(t||[]).map(e=>e.value)},e)},automationId:"select-payment-methods"},"select-payment-methods")]}),(0,g.jsx)(ed,{filterIndex:e})]})},[md.Ag.USED_SHIPPING_METHOD]:function({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilter:a}=(0,fe.A)(Al.Hz),i=(0,C.A)(e=>e(Al.Hz).getShippingMethods(),[]).map(e=>({value:e.instanceId,label:e.name}));return(0,r.useEffect)(()=>{t.operator!==Il.dP.ANY&&t.operator!==Il.dP.ALL&&t.operator!==Il.dP.NONE&&a({operator:Il.dP.ANY},e)},[a,t,e]),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(Di.Grid.CenteredRow,{children:[(0,g.jsxs)(o.Select,{isMaxContentWidth:!0,value:t.operator,onChange:t=>{a({operator:t.target.value},e)},automationId:"select-operator-used-shipping-methods",children:[(0,g.jsx)("option",{value:Il.dP.ANY,children:m.U.I18n.t("anyOf")}),(0,g.jsx)("option",{value:Il.dP.ALL,children:m.U.I18n.t("allOf")}),(0,g.jsx)("option",{value:Il.dP.NONE,children:m.U.I18n.t("noneOf")})]},"select-operator-used-shipping-methods"),(0,g.jsx)(kl.ReactSelect,{isFullWidth:!0,isMulti:!0,placeholder:m.U.I18n.t("selectWooShippingMethods"),options:i,value:(0,Sn.filter)(e=>{if(t.shipping_methods)return-1!==t.shipping_methods.indexOf(e.value)},i),onChange:t=>{a({shipping_methods:(t||[]).map(e=>e.value)},e)},automationId:"select-shipping-methods"},"select-shipping-methods")]}),(0,g.jsx)(ed,{filterIndex:e})]})},[md.Ag.FIRST_ORDER]:dd};function fd({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilter:a,updateSegmentFilterFromEvent:i}=(0,fe.A)(Al.Hz);(0,r.useEffect)(()=>{t.action===Il.gw.WORDPRESS_ROLE&&t.operator!==Il.dP.ANY&&t.operator!==Il.dP.ALL&&t.operator!==Il.dP.NONE&&a({operator:Il.dP.ANY},e)},[a,t,e]);const s=(0,C.A)(e=>e(Al.Hz).getWordpressRoles(),[]).map(e=>({value:e.role_id,label:e.role_name}));return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(Di.Grid.CenteredRow,{children:(0,g.jsxs)(Be.Select,{isFullWidth:!0,automationId:"segment-wordpress-role-condition",value:t.operator,onChange:t=>{i("operator",e,t)},children:[(0,g.jsx)("option",{value:Il.dP.ANY,children:m.U.I18n.t("anyOf")}),(0,g.jsx)("option",{value:Il.dP.ALL,children:m.U.I18n.t("allOf")}),(0,g.jsx)("option",{value:Il.dP.NONE,children:m.U.I18n.t("noneOf")})]},"select")}),(0,g.jsx)(Di.Grid.CenteredRow,{children:(0,g.jsx)(kl.ReactSelect,{dimension:"small",isMulti:!0,automationId:"segment-wordpress-role",placeholder:m.U.I18n.t("selectUserRolePlaceholder"),options:s,value:(0,Sn.filter)(e=>{if(t.wordpressRole)return-1!==t.wordpressRole.indexOf(e.value)},s),onChange:t=>{a({wordpressRole:(0,Sn.map)("value",t)},e)}})})]})}let bd=function(e){return e.HIGHER_THAN="higherThan",e.LOWER_THAN="lowerThan",e.EQUALS="equals",e.NOT_EQUALS="not_equals",e.UNKNOWN="unknown",e.NOT_UNKNOWN="not_unknown",e.DORMANT="dormant",e.NOT_DORMANT="not_dormant",e}({});const xd=[bd.HIGHER_THAN,bd.LOWER_THAN,bd.EQUALS,bd.NOT_EQUALS,bd.UNKNOWN,bd.NOT_UNKNOWN,bd.DORMANT,bd.NOT_DORMANT];function vd(e){return!!(0,Il.uA)(e.operator)||"string"==typeof e.value&&e.value.length>0&&("equals"===e.operator||"contains"===e.operator||"not_contains"===e.operator||"not_equals"===e.operator||"more_than"===e.operator||"less_than"===e.operator)}function yd({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilterFromEvent:a,updateSegmentFilter:i}=(0,fe.A)(Al.Hz);return(0,r.useEffect)(()=>{void 0===t.operator&&i({operator:"equals",value:""},e)},[i,t,e]),(0,g.jsxs)(Di.Grid.CenteredRow,{children:[(0,g.jsxs)(Be.Select,{automationId:"text-custom-field-operator",value:t.operator,onChange:t=>{a("operator",e,t)},children:[(0,g.jsx)("option",{value:"equals",children:m.U.I18n.t("is")}),(0,g.jsx)("option",{value:"not_equals",children:m.U.I18n.t("isNot")}),(0,g.jsx)("option",{value:"contains",children:m.U.I18n.t("contains")}),(0,g.jsx)("option",{value:"not_contains",children:m.U.I18n.t("notContains")}),(0,g.jsx)("option",{value:"more_than",children:m.U.I18n.t("moreThan")}),(0,g.jsx)("option",{value:"less_than",children:m.U.I18n.t("lessThan")}),(0,g.jsx)("option",{value:"is_blank",children:m.U.I18n.t("isBlank")}),(0,g.jsx)("option",{value:"is_not_blank",children:m.U.I18n.t("isNotBlank")})]},"select"),!(0,Il.uA)(t.operator)&&(0,g.jsx)(Dt.p,{"data-automation-id":"text-custom-field-value",value:t.value||"",onChange:t=>{a("value",e,t)},placeholder:m.U.I18n.t("value")},"input")]})}function wd(e){return!!(0,Il.uA)(e.operator)||"string"==typeof e.value&&e.value.length>0}function jd({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilter:a,updateSegmentFilterFromEvent:i}=(0,fe.A)(Al.Hz),s=(0,C.A)(e=>e(Al.Hz).getCustomFieldsList(),[]),n=(0,Sn.find)({id:Number(t.custom_field_id)},s);if(!n)return null;const r=n.params;if(!r||!Array.isArray(r.values))return null;const o=r.values.map(e=>({value:e.value,label:e.value})),l=o.find(e=>e.value===t.value)?.label;return(0,g.jsxs)(Di.Grid.CenteredRow,{children:[(0,g.jsxs)(Be.Select,{automationId:"text-custom-field-operator",value:t.operator,onChange:t=>{i("operator",e,t)},children:[(0,g.jsx)("option",{value:"equals",children:m.U.I18n.t("is")}),(0,g.jsx)("option",{value:Il.FI.BLANK,children:m.U.I18n.t("isBlank")}),(0,g.jsx)("option",{value:Il.FI.NOT_BLANK,children:m.U.I18n.t("isNotBlank")})]},"select"),!(0,Il.uA)(t.operator)&&(0,g.jsx)(kl.ReactSelect,{dimension:"small",placeholder:m.U.I18n.t("selectValue"),options:o,value:t.value&&l?{value:t.value,label:l}:null,onChange:t=>{a({value:t.value},e)},automationId:"segment-wordpress-role"})]})}var Sd=a(86452),kd=a(16519),Nd=a(51831);function Cd(e){const t=(0,Zl.a)(e);return(0,kd.m)(t,function(e){const t=(0,Zl.a)(e),a=(0,Nd.w)(e,0);return a.setFullYear(t.getFullYear(),0,1),a.setHours(0,0,0,0),a}(t))+1}var Ed=a(98491);function Id(e){return(0,Ed.k)(e,{weekStartsOn:1})}function Ad(e){const t=(0,Zl.a)(e),a=t.getFullYear(),i=(0,Nd.w)(e,0);i.setFullYear(a+1,0,4),i.setHours(0,0,0,0);const s=Id(i),n=(0,Nd.w)(e,0);n.setFullYear(a,0,4),n.setHours(0,0,0,0);const r=Id(n);return t.getTime()>=s.getTime()?a+1:t.getTime()>=r.getTime()?a:a-1}function Ud(e){const t=(0,Zl.a)(e),a=+Id(t)-+function(e){const t=Ad(e),a=(0,Nd.w)(e,0);return a.setFullYear(t,0,4),a.setHours(0,0,0,0),Id(a)}(t);return Math.round(a/$l.my)+1}function Td(e,t){const a=(0,Zl.a)(e),i=a.getFullYear(),s=(0,Sd.q)(),n=t?.firstWeekContainsDate??t?.locale?.options?.firstWeekContainsDate??s.firstWeekContainsDate??s.locale?.options?.firstWeekContainsDate??1,r=(0,Nd.w)(e,0);r.setFullYear(i+1,0,n),r.setHours(0,0,0,0);const o=(0,Ed.k)(r,t),l=(0,Nd.w)(e,0);l.setFullYear(i,0,n),l.setHours(0,0,0,0);const d=(0,Ed.k)(l,t);return a.getTime()>=o.getTime()?i+1:a.getTime()>=d.getTime()?i:i-1}function Pd(e,t){const a=(0,Zl.a)(e),i=+(0,Ed.k)(a,t)-+function(e,t){const a=(0,Sd.q)(),i=t?.firstWeekContainsDate??t?.locale?.options?.firstWeekContainsDate??a.firstWeekContainsDate??a.locale?.options?.firstWeekContainsDate??1,s=Td(e,t),n=(0,Nd.w)(e,0);return n.setFullYear(s,0,i),n.setHours(0,0,0,0),(0,Ed.k)(n,t)}(a,t);return Math.round(i/$l.my)+1}function Rd(e,t){return(e<0?"-":"")+Math.abs(e).toString().padStart(t,"0")}const Dd={y(e,t){const a=e.getFullYear(),i=a>0?a:1-a;return Rd("yy"===t?i%100:i,t.length)},M(e,t){const a=e.getMonth();return"M"===t?String(a+1):Rd(a+1,2)},d:(e,t)=>Rd(e.getDate(),t.length),a(e,t){const a=e.getHours()/12>=1?"pm":"am";switch(t){case"a":case"aa":return a.toUpperCase();case"aaa":return a;case"aaaaa":return a[0];default:return"am"===a?"a.m.":"p.m."}},h:(e,t)=>Rd(e.getHours()%12||12,t.length),H:(e,t)=>Rd(e.getHours(),t.length),m:(e,t)=>Rd(e.getMinutes(),t.length),s:(e,t)=>Rd(e.getSeconds(),t.length),S(e,t){const a=t.length,i=e.getMilliseconds();return Rd(Math.trunc(i*Math.pow(10,a-3)),t.length)}},Fd={G:function(e,t,a){const i=e.getFullYear()>0?1:0;switch(t){case"G":case"GG":case"GGG":return a.era(i,{width:"abbreviated"});case"GGGGG":return a.era(i,{width:"narrow"});default:return a.era(i,{width:"wide"})}},y:function(e,t,a){if("yo"===t){const t=e.getFullYear(),i=t>0?t:1-t;return a.ordinalNumber(i,{unit:"year"})}return Dd.y(e,t)},Y:function(e,t,a,i){const s=Td(e,i),n=s>0?s:1-s;return"YY"===t?Rd(n%100,2):"Yo"===t?a.ordinalNumber(n,{unit:"year"}):Rd(n,t.length)},R:function(e,t){return Rd(Ad(e),t.length)},u:function(e,t){return Rd(e.getFullYear(),t.length)},Q:function(e,t,a){const i=Math.ceil((e.getMonth()+1)/3);switch(t){case"Q":return String(i);case"QQ":return Rd(i,2);case"Qo":return a.ordinalNumber(i,{unit:"quarter"});case"QQQ":return a.quarter(i,{width:"abbreviated",context:"formatting"});case"QQQQQ":return a.quarter(i,{width:"narrow",context:"formatting"});default:return a.quarter(i,{width:"wide",context:"formatting"})}},q:function(e,t,a){const i=Math.ceil((e.getMonth()+1)/3);switch(t){case"q":return String(i);case"qq":return Rd(i,2);case"qo":return a.ordinalNumber(i,{unit:"quarter"});case"qqq":return a.quarter(i,{width:"abbreviated",context:"standalone"});case"qqqqq":return a.quarter(i,{width:"narrow",context:"standalone"});default:return a.quarter(i,{width:"wide",context:"standalone"})}},M:function(e,t,a){const i=e.getMonth();switch(t){case"M":case"MM":return Dd.M(e,t);case"Mo":return a.ordinalNumber(i+1,{unit:"month"});case"MMM":return a.month(i,{width:"abbreviated",context:"formatting"});case"MMMMM":return a.month(i,{width:"narrow",context:"formatting"});default:return a.month(i,{width:"wide",context:"formatting"})}},L:function(e,t,a){const i=e.getMonth();switch(t){case"L":return String(i+1);case"LL":return Rd(i+1,2);case"Lo":return a.ordinalNumber(i+1,{unit:"month"});case"LLL":return a.month(i,{width:"abbreviated",context:"standalone"});case"LLLLL":return a.month(i,{width:"narrow",context:"standalone"});default:return a.month(i,{width:"wide",context:"standalone"})}},w:function(e,t,a,i){const s=Pd(e,i);return"wo"===t?a.ordinalNumber(s,{unit:"week"}):Rd(s,t.length)},I:function(e,t,a){const i=Ud(e);return"Io"===t?a.ordinalNumber(i,{unit:"week"}):Rd(i,t.length)},d:function(e,t,a){return"do"===t?a.ordinalNumber(e.getDate(),{unit:"date"}):Dd.d(e,t)},D:function(e,t,a){const i=Cd(e);return"Do"===t?a.ordinalNumber(i,{unit:"dayOfYear"}):Rd(i,t.length)},E:function(e,t,a){const i=e.getDay();switch(t){case"E":case"EE":case"EEE":return a.day(i,{width:"abbreviated",context:"formatting"});case"EEEEE":return a.day(i,{width:"narrow",context:"formatting"});case"EEEEEE":return a.day(i,{width:"short",context:"formatting"});default:return a.day(i,{width:"wide",context:"formatting"})}},e:function(e,t,a,i){const s=e.getDay(),n=(s-i.weekStartsOn+8)%7||7;switch(t){case"e":return String(n);case"ee":return Rd(n,2);case"eo":return a.ordinalNumber(n,{unit:"day"});case"eee":return a.day(s,{width:"abbreviated",context:"formatting"});case"eeeee":return a.day(s,{width:"narrow",context:"formatting"});case"eeeeee":return a.day(s,{width:"short",context:"formatting"});default:return a.day(s,{width:"wide",context:"formatting"})}},c:function(e,t,a,i){const s=e.getDay(),n=(s-i.weekStartsOn+8)%7||7;switch(t){case"c":return String(n);case"cc":return Rd(n,t.length);case"co":return a.ordinalNumber(n,{unit:"day"});case"ccc":return a.day(s,{width:"abbreviated",context:"standalone"});case"ccccc":return a.day(s,{width:"narrow",context:"standalone"});case"cccccc":return a.day(s,{width:"short",context:"standalone"});default:return a.day(s,{width:"wide",context:"standalone"})}},i:function(e,t,a){const i=e.getDay(),s=0===i?7:i;switch(t){case"i":return String(s);case"ii":return Rd(s,t.length);case"io":return a.ordinalNumber(s,{unit:"day"});case"iii":return a.day(i,{width:"abbreviated",context:"formatting"});case"iiiii":return a.day(i,{width:"narrow",context:"formatting"});case"iiiiii":return a.day(i,{width:"short",context:"formatting"});default:return a.day(i,{width:"wide",context:"formatting"})}},a:function(e,t,a){const i=e.getHours()/12>=1?"pm":"am";switch(t){case"a":case"aa":return a.dayPeriod(i,{width:"abbreviated",context:"formatting"});case"aaa":return a.dayPeriod(i,{width:"abbreviated",context:"formatting"}).toLowerCase();case"aaaaa":return a.dayPeriod(i,{width:"narrow",context:"formatting"});default:return a.dayPeriod(i,{width:"wide",context:"formatting"})}},b:function(e,t,a){const i=e.getHours();let s;switch(s=12===i?"noon":0===i?"midnight":i/12>=1?"pm":"am",t){case"b":case"bb":return a.dayPeriod(s,{width:"abbreviated",context:"formatting"});case"bbb":return a.dayPeriod(s,{width:"abbreviated",context:"formatting"}).toLowerCase();case"bbbbb":return a.dayPeriod(s,{width:"narrow",context:"formatting"});default:return a.dayPeriod(s,{width:"wide",context:"formatting"})}},B:function(e,t,a){const i=e.getHours();let s;switch(s=i>=17?"evening":i>=12?"afternoon":i>=4?"morning":"night",t){case"B":case"BB":case"BBB":return a.dayPeriod(s,{width:"abbreviated",context:"formatting"});case"BBBBB":return a.dayPeriod(s,{width:"narrow",context:"formatting"});default:return a.dayPeriod(s,{width:"wide",context:"formatting"})}},h:function(e,t,a){if("ho"===t){let t=e.getHours()%12;return 0===t&&(t=12),a.ordinalNumber(t,{unit:"hour"})}return Dd.h(e,t)},H:function(e,t,a){return"Ho"===t?a.ordinalNumber(e.getHours(),{unit:"hour"}):Dd.H(e,t)},K:function(e,t,a){const i=e.getHours()%12;return"Ko"===t?a.ordinalNumber(i,{unit:"hour"}):Rd(i,t.length)},k:function(e,t,a){let i=e.getHours();return 0===i&&(i=24),"ko"===t?a.ordinalNumber(i,{unit:"hour"}):Rd(i,t.length)},m:function(e,t,a){return"mo"===t?a.ordinalNumber(e.getMinutes(),{unit:"minute"}):Dd.m(e,t)},s:function(e,t,a){return"so"===t?a.ordinalNumber(e.getSeconds(),{unit:"second"}):Dd.s(e,t)},S:function(e,t){return Dd.S(e,t)},X:function(e,t,a){const i=e.getTimezoneOffset();if(0===i)return"Z";switch(t){case"X":return Md(i);case"XXXX":case"XX":return Ld(i);default:return Ld(i,":")}},x:function(e,t,a){const i=e.getTimezoneOffset();switch(t){case"x":return Md(i);case"xxxx":case"xx":return Ld(i);default:return Ld(i,":")}},O:function(e,t,a){const i=e.getTimezoneOffset();switch(t){case"O":case"OO":case"OOO":return"GMT"+Od(i,":");default:return"GMT"+Ld(i,":")}},z:function(e,t,a){const i=e.getTimezoneOffset();switch(t){case"z":case"zz":case"zzz":return"GMT"+Od(i,":");default:return"GMT"+Ld(i,":")}},t:function(e,t,a){return Rd(Math.trunc(e.getTime()/1e3),t.length)},T:function(e,t,a){return Rd(e.getTime(),t.length)}};function Od(e,t=""){const a=e>0?"-":"+",i=Math.abs(e),s=Math.trunc(i/60),n=i%60;return 0===n?a+String(s):a+String(s)+t+Rd(n,2)}function Md(e,t){return e%60==0?(e>0?"-":"+")+Rd(Math.abs(e)/60,2):Ld(e,t)}function Ld(e,t=""){const a=e>0?"-":"+",i=Math.abs(e);return a+Rd(Math.trunc(i/60),2)+t+Rd(i%60,2)}const $d=(e,t)=>{switch(e){case"P":return t.date({width:"short"});case"PP":return t.date({width:"medium"});case"PPP":return t.date({width:"long"});default:return t.date({width:"full"})}},Bd=(e,t)=>{switch(e){case"p":return t.time({width:"short"});case"pp":return t.time({width:"medium"});case"ppp":return t.time({width:"long"});default:return t.time({width:"full"})}},Wd={p:Bd,P:(e,t)=>{const a=e.match(/(P+)(p+)?/)||[],i=a[1],s=a[2];if(!s)return $d(e,t);let n;switch(i){case"P":n=t.dateTime({width:"short"});break;case"PP":n=t.dateTime({width:"medium"});break;case"PPP":n=t.dateTime({width:"long"});break;default:n=t.dateTime({width:"full"})}return n.replace("{{date}}",$d(i,t)).replace("{{time}}",Bd(s,t))}},Vd=/^D+$/,qd=/^Y+$/,zd=["D","DD","YY","YYYY"],Hd=/[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g,Gd=/P+p+|P+|p+|''|'(''|[^'])+('|$)|./g,Yd=/^'([^]*?)'?$/,Kd=/''/g,Zd=/[a-zA-Z]/;function Jd(e,t,a){const i=(0,Sd.q)(),s=a?.locale??i.locale??qi,n=a?.firstWeekContainsDate??a?.locale?.options?.firstWeekContainsDate??i.firstWeekContainsDate??i.locale?.options?.firstWeekContainsDate??1,r=a?.weekStartsOn??a?.locale?.options?.weekStartsOn??i.weekStartsOn??i.locale?.options?.weekStartsOn??0,o=(0,Zl.a)(e);if(!Jl(o))throw new RangeError("Invalid time value");let l=t.match(Gd).map(e=>{const t=e[0];return"p"===t||"P"===t?(0,Wd[t])(e,s.formatLong):e}).join("").match(Hd).map(e=>{if("''"===e)return{isToken:!1,value:"'"};const t=e[0];if("'"===t)return{isToken:!1,value:Qd(e)};if(Fd[t])return{isToken:!0,value:e};if(t.match(Zd))throw new RangeError("Format string contains an unescaped latin alphabet character `"+t+"`");return{isToken:!1,value:e}});s.localize.preprocessor&&(l=s.localize.preprocessor(o,l));const d={firstWeekContainsDate:n,weekStartsOn:r,locale:s};return l.map(i=>{if(!i.isToken)return i.value;const n=i.value;return(!a?.useAdditionalWeekYearTokens&&function(e){return qd.test(e)}(n)||!a?.useAdditionalDayOfYearTokens&&function(e){return Vd.test(e)}(n))&&function(e,t,a){const i=function(e,t,a){const i="Y"===e[0]?"years":"days of the month";return`Use \`${e.toLowerCase()}\` instead of \`${e}\` (in \`${t}\`) for formatting ${i} to the input \`${a}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`}(e,t,a);if(console.warn(i),zd.includes(e))throw new RangeError(i)}(n,t,String(e)),(0,Fd[n[0]])(o,n,s.localize,d)}).join("")}function Qd(e){const t=e.match(Yd);return t?t[1].replace(Kd,"'"):e}function Xd(e){return!!(0,Il.uA)(e.operator)||("month"===e.date_type||!("string"!=typeof e.operator||e.operator.length<1))&&"string"==typeof e.value&&e.value.length>1}const ec=e=>{if(null!==e){if(Array.isArray(e))throw new Error("convertDateToString can process only single date array given");return Jd(e,"yyyy-MM-dd 00:00:00")}},tc=e=>{const t=Bl(e);if(Jl(t))return t},ac={month:function({onChange:e,item:t,filterIndex:a}){return(0,r.useEffect)(()=>{Xd(t)||e((0,Sn.assign)(t,{value:"2017-01-01 00:00:00"}),a),void 0===t.operator&&e((0,Sn.assign)(t,{operator:"equals"}),a)},[e,t,a]),(0,g.jsxs)(Di.Grid.CenteredRow,{children:[(0,g.jsxs)(Be.Select,{value:t.operator,onChange:i=>{e((0,Sn.assign)(t,{operator:i.target.value}),a)},children:[(0,g.jsx)("option",{value:"equals",children:(0,p.__)("is","mailpoet")}),(0,g.jsx)("option",{value:Il.FI.BLANK,children:(0,p.__)("is blank","mailpoet")}),(0,g.jsx)("option",{value:Il.FI.NOT_BLANK,children:(0,p.__)("is not blank","mailpoet")})]},"select-operator"),!(0,Il.uA)(t.operator)&&(0,g.jsxs)(Be.Select,{value:t.value,onChange:i=>{e((0,Sn.assign)(t,{value:i.target.value}),a)},children:[(0,g.jsx)("option",{value:"2017-01-01 00:00:00",children:(0,p.__)("january","mailpoet")}),(0,g.jsx)("option",{value:"2017-02-01 00:00:00",children:(0,p.__)("february","mailpoet")}),(0,g.jsx)("option",{value:"2017-03-01 00:00:00",children:(0,p.__)("march","mailpoet")}),(0,g.jsx)("option",{value:"2017-04-01 00:00:00",children:(0,p.__)("april","mailpoet")}),(0,g.jsx)("option",{value:"2017-05-01 00:00:00",children:(0,p.__)("may","mailpoet")}),(0,g.jsx)("option",{value:"2017-06-01 00:00:00",children:(0,p.__)("june","mailpoet")}),(0,g.jsx)("option",{value:"2017-07-01 00:00:00",children:(0,p.__)("july","mailpoet")}),(0,g.jsx)("option",{value:"2017-08-01 00:00:00",children:(0,p.__)("august","mailpoet")}),(0,g.jsx)("option",{value:"2017-09-01 00:00:00",children:(0,p.__)("september","mailpoet")}),(0,g.jsx)("option",{value:"2017-10-01 00:00:00",children:(0,p.__)("october","mailpoet")}),(0,g.jsx)("option",{value:"2017-11-01 00:00:00",children:(0,p.__)("november","mailpoet")}),(0,g.jsx)("option",{value:"2017-12-01 00:00:00",children:(0,p.__)("december","mailpoet")})]},"select")]})},year:function({onChange:e,item:t,filterIndex:a}){const i=(s=new Date,(0,Zl.a)(s).getFullYear());var s;return(0,r.useEffect)(()=>{Xd(t)||e((0,Sn.assign)(t,{value:`${i}-01-01 00:00:00`,operator:"equals"}),a)},[i,e,t,a]),(0,g.jsxs)(Di.Grid.CenteredRow,{children:[(0,g.jsxs)(Be.Select,{value:t.operator,onChange:i=>{e((0,Sn.assign)(t,{operator:i.target.value}),a)},children:[(0,g.jsx)("option",{value:"equals",children:(0,p.__)("is","mailpoet")}),(0,g.jsx)("option",{value:"before",children:(0,p._x)("before",'Meaning: "Subscriber subscribed before April"',"mailpoet")}),(0,g.jsx)("option",{value:"after",children:(0,p._x)("after",'Meaning: "Subscriber subscribed after April',"mailpoet")}),(0,g.jsx)("option",{value:Il.FI.BLANK,children:(0,p.__)("is blank","mailpoet")}),(0,g.jsx)("option",{value:Il.FI.NOT_BLANK,children:(0,p.__)("is not blank","mailpoet")})]},"select-operator"),(0,g.jsx)(Be.Select,{value:t.value,onChange:i=>{e((0,Sn.assign)(t,{value:i.target.value}),a)},children:(0,Sn.range)(0,100).map(e=>(0,g.jsx)("option",{value:i-e+"-01-01 00:00:00",children:i-e},i-e))},"select-year")]})},year_month:function({onChange:e,item:t,filterIndex:a}){return(0,r.useEffect)(()=>{void 0!==t.value&&""!==t.value||e((0,Sn.assign)(t,{value:`${Jd(new Date,"yyyy-MM-dd")} 00:00:00`,operator:"equals"}),a)},[e,t,a]),(0,g.jsxs)(Di.Grid.CenteredRow,{children:[(0,g.jsxs)(Be.Select,{value:t.operator,onChange:i=>{e((0,Sn.assign)(t,{operator:i.target.value}),a)},children:[(0,g.jsx)("option",{value:"equals",children:(0,p.__)("is","mailpoet")}),(0,g.jsx)("option",{value:"before",children:(0,p._x)("before",'Meaning: "Subscriber subscribed before April"',"mailpoet")}),(0,g.jsx)("option",{value:"after",children:(0,p._x)("after",'Meaning: "Subscriber subscribed after April',"mailpoet")}),(0,g.jsx)("option",{value:Il.FI.BLANK,children:(0,p.__)("is blank","mailpoet")}),(0,g.jsx)("option",{value:Il.FI.NOT_BLANK,children:(0,p.__)("is not blank","mailpoet")})]},"select-operator"),!(0,Il.uA)(t.operator)&&(0,g.jsx)(Hi.t,{onChange:i=>e((0,Sn.assign)(t,{value:ec(i)}),a),selected:t.value?tc(t.value):void 0,dateFormat:"MM/yyyy",showMonthYearPicker:!0})]})},year_month_day:function({onChange:e,item:t,filterIndex:a}){return(0,r.useEffect)(()=>{Xd(t)||e((0,Sn.assign)(t,{value:`${Jd(new Date,"yyyy-MM-dd")} 00:00:00`,operator:"equals"}),a)},[e,t,a]),(0,g.jsxs)(Di.Grid.CenteredRow,{children:[(0,g.jsxs)(Be.Select,{value:t.operator,onChange:i=>{e((0,Sn.assign)(t,{operator:i.target.value}),a)},children:[(0,g.jsx)("option",{value:"equals",children:(0,p.__)("is","mailpoet")}),(0,g.jsx)("option",{value:"before",children:(0,p._x)("before",'Meaning: "Subscriber subscribed before April"',"mailpoet")}),(0,g.jsx)("option",{value:"after",children:(0,p._x)("after",'Meaning: "Subscriber subscribed after April',"mailpoet")}),(0,g.jsx)("option",{value:Il.FI.BLANK,children:(0,p.__)("is blank","mailpoet")}),(0,g.jsx)("option",{value:Il.FI.NOT_BLANK,children:(0,p.__)("is not blank","mailpoet")})]},"select-operator"),!(0,Il.uA)(t.operator)&&(0,g.jsx)(Hi.t,{dateFormat:"MMM d, yyyy",onChange:i=>e((0,Sn.assign)(t,{value:ec(i)}),a),selected:t.value?tc(t.value):void 0})]})}};var ic=function(e){return e.DATE="date",e.TEXT="text",e.TEXTAREA="textarea",e.RADIO="radio",e.CHECKBOX="checkbox",e.SELECT="select",e}(ic||{});const sc={[ic.TEXT]:vd,[ic.TEXTAREA]:vd,[ic.RADIO]:wd,[ic.SELECT]:wd,[ic.CHECKBOX]:function(e){return!!(0,Il.uA)(e.operator)||["1","0"].includes(e.value)},[ic.DATE]:Xd},nc={[ic.TEXT]:yd,[ic.TEXTAREA]:yd,[ic.RADIO]:jd,[ic.SELECT]:jd,[ic.CHECKBOX]:function({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilterFromEvent:a,updateSegmentFilter:i}=(0,fe.A)(Al.Hz);return(0,r.useEffect)(()=>{void 0===t.operator?i({operator:"equals",value:"1"},e):"equals"!==t.operator||["1","0"].includes(t.value)||i({value:"1"},e)},[i,t,e]),(0,g.jsxs)(Di.Grid.CenteredRow,{children:[(0,g.jsxs)(Be.Select,{value:t.operator,onChange:t=>{a("operator",e,t)},children:[(0,g.jsx)("option",{value:"equals",children:(0,p.__)("is","mailpoet")}),(0,g.jsx)("option",{value:Il.FI.BLANK,children:(0,p.__)("is blank","mailpoet")}),(0,g.jsx)("option",{value:Il.FI.NOT_BLANK,children:(0,p.__)("is not blank","mailpoet")})]},"select-operator"),!(0,Il.uA)(t.operator)&&(0,g.jsxs)(Be.Select,{value:t.value,onChange:t=>{a("value",e,t)},children:[(0,g.jsx)("option",{value:"1",children:(0,p.__)("checked","mailpoet")}),(0,g.jsx)("option",{value:"0",children:(0,p.__)("unchecked","mailpoet")})]},"select")]})},[ic.DATE]:function({customField:e,filterIndex:t}){const a=(0,C.A)(e=>e(Al.Hz).getSegmentFilter(t),[t]),{updateSegmentFilter:i}=(0,fe.A)(Al.Hz);(0,r.useEffect)(()=>{a.date_type!==e.params.date_type&&i({date_type:e.params.date_type,value:""},t)},[a.date_type,i,e.params.date_type,t]);const s=ac[e.params.date_type];return s?(0,g.jsx)(s,{item:a,onChange:i,filterIndex:t}):null}};function rc(){return(0,g.jsx)(Ka,{message:(()=>{const e=m.U.I18n.t("premiumFeatureMultipleConditions");return(0,g.jsx)("p",{children:b()(e,/\[link](.*?)\[\/link]/g,e=>(0,g.jsx)("a",{href:m.U.premiumLink,target:"_blank",rel:"noopener noreferrer",children:e},e))})})(),actionButton:(0,g.jsx)(Ge.$,{href:m.U.MailPoetComUrlFactory.getPurchasePlanUrl(m.U.subscribersCount,m.U.currentWpUserEmail,null,{utm_medium:"segments",utm_campaign:"signup"}),target:"_blank",rel:"noopener noreferrer",children:m.U.I18n.t("premiumBannerCtaFree")})})}const oc={[Il.gw.WORDPRESS_ROLE]:fd,[Il.gw.SUBSCRIBER_SCORE]:function({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilter:a,updateSegmentFilterFromEvent:i}=(0,fe.A)(Al.Hz);return(0,r.useEffect)(()=>{xd.includes(t.operator)||a({operator:bd.HIGHER_THAN},e),t.operator!==bd.HIGHER_THAN&&t.operator!==bd.LOWER_THAN&&t.operator!==bd.EQUALS&&t.operator!==bd.NOT_EQUALS||void 0!==t.value||a({value:""},e),t.operator!==bd.UNKNOWN&&t.operator!==bd.NOT_UNKNOWN&&t.operator!==bd.DORMANT&&t.operator!==bd.NOT_DORMANT||a({value:null},e)},[a,t,e]),(0,g.jsx)(Di.Grid.CenteredRow,{children:(s=a=>"{condition}"===a?(0,g.jsxs)(Be.Select,{value:t.operator,automationId:"segment-subscriber-score-operator",onChange:t=>{i("operator",e,t)},children:[(0,g.jsx)("option",{value:bd.HIGHER_THAN,children:m.U.I18n.t("higherThan")}),(0,g.jsx)("option",{value:bd.LOWER_THAN,children:m.U.I18n.t("lowerThan")}),(0,g.jsx)("option",{value:bd.EQUALS,children:m.U.I18n.t("equals")}),(0,g.jsx)("option",{value:bd.NOT_EQUALS,children:m.U.I18n.t("notEquals")}),(0,g.jsx)("option",{value:bd.UNKNOWN,children:m.U.I18n.t("unknown")}),(0,g.jsx)("option",{value:bd.NOT_UNKNOWN,children:m.U.I18n.t("notUnknown")}),(0,g.jsx)("option",{value:bd.DORMANT,children:m.U.I18n.t("dormant")}),(0,g.jsx)("option",{value:bd.NOT_DORMANT,children:m.U.I18n.t("notDormant")})]},"select"):"{score}"===a?(t.operator===bd.HIGHER_THAN||t.operator===bd.LOWER_THAN||t.operator===bd.EQUALS||t.operator===bd.NOT_EQUALS)&&(0,g.jsx)(Dt.p,{type:"number",value:t.value||"","data-automation-id":"segment-subscriber-score-value",onChange:t=>{i("value",e,t)},min:"0",placeholder:m.U.I18n.t("subscriberScorePlaceholder")},"input"):"string"==typeof a&&a.trim().length>0?t.operator!==bd.UNKNOWN&&t.operator!==bd.NOT_UNKNOWN&&t.operator!==bd.DORMANT&&t.operator!==bd.NOT_DORMANT&&(0,g.jsx)("div",{children:a},"score"):null,m.U.I18n.t("subscriberScoreSentence").split(/({condition})|({score})|(\b%\b)/gim).map(s))});var s},[Il.gw.SUBSCRIBED_DATE]:dd,[Il.gw.MAILPOET_CUSTOM_FIELD]:function({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilter:a}=(0,fe.A)(Al.Hz),i=(0,C.A)(e=>e(Al.Hz).getCustomFieldsList(),[]),s=(0,Sn.find)({id:Number(t.custom_field_id)},i),n=i.map(e=>({value:e.id.toString(),label:e.name})),r=nc[t.custom_field_type];return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("div",{children:(0,g.jsx)(kl.ReactSelect,{dimension:"small",isFullWidth:!0,placeholder:m.U.I18n.t("selectCustomFieldPlaceholder"),options:n,automationId:"select-custom-field",value:(0,Sn.find)(e=>{if(t.custom_field_id)return t.custom_field_id===e.value},n),onChange:t=>{const s=(0,Sn.find)({id:Number(t.value)},i);s&&a({custom_field_id:t.value,custom_field_type:s.type,operator:void 0,value:void 0},e)}})}),(0,g.jsx)("div",{children:r&&(0,g.jsx)(r,{customField:s,filterIndex:e})})]})},[Il.gw.SUBSCRIBED_TO_LIST]:function({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),a=(0,C.A)(e=>e(Al.Hz).getStaticSegmentsList(),[]),{updateSegmentFilter:i,updateSegmentFilterFromEvent:s}=(0,fe.A)(Al.Hz);(0,r.useEffect)(()=>{t.operator!==Il.dP.ANY&&t.operator!==Il.dP.ALL&&t.operator!==Il.dP.NONE&&i({operator:Il.dP.ANY},e)},[i,t,e]);const n=a.map(e=>({value:e.id,label:e.name}));return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(Be.Select,{isMinWidth:!0,value:t.operator,onChange:t=>{s("operator",e,t)},children:[(0,g.jsx)("option",{value:Il.dP.ANY,children:m.U.I18n.t("anyOf")}),(0,g.jsx)("option",{value:Il.dP.ALL,children:m.U.I18n.t("allOf")}),(0,g.jsx)("option",{value:Il.dP.NONE,children:m.U.I18n.t("noneOf")})]},"select"),(0,g.jsx)(kl.ReactSelect,{dimension:"small",isMulti:!0,placeholder:m.U.I18n.t("searchLists"),options:n,value:(0,Sn.filter)(e=>{if(!t.segments)return;const a=e.value;return-1!==t.segments.indexOf(a)},n),onChange:t=>{i({segments:(0,Sn.map)((0,Sn.parseInt)(10),(0,Sn.map)("value",t))},e)}})]})},[Il.gw.SUBSCRIBER_TAG]:function({filterIndex:e}){return Ta.Hooks.applyFilters("mailpoet_dynamic_segments_filter_subscriber_tag",(0,g.jsx)(rc,{}),e)},[Il.gw.SUBSCRIBER_FIRST_NAME]:gd,[Il.gw.SUBSCRIBER_LAST_NAME]:gd,[Il.gw.SUBSCRIBER_EMAIL]:gd,[Il.gw.SUBSCRIBED_VIA_FORM]:function({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),a=(0,C.A)(e=>e(Al.Hz).getSignupForms(),[]),{updateSegmentFilter:i,updateSegmentFilterFromEvent:s}=(0,fe.A)(Al.Hz);(0,r.useEffect)(()=>{t.operator!==Il.dP.ANY&&t.operator!==Il.dP.NONE&&i({operator:Il.dP.ANY},e)},[i,t,e]);const n=a.map(e=>({value:e.id,label:e.name}));return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(Be.Select,{isMinWidth:!0,value:t.operator,onChange:t=>{s("operator",e,t)},children:[(0,g.jsx)("option",{value:Il.dP.ANY,children:m.U.I18n.t("anyOf")}),(0,g.jsx)("option",{value:Il.dP.NONE,children:m.U.I18n.t("noneOf")})]},"select"),(0,g.jsx)(kl.ReactSelect,{dimension:"small",isMulti:!0,placeholder:m.U.I18n.t("searchForms"),options:n,value:n.filter(e=>{if(!t.form_ids)return;const a=e.value;return-1!==t.form_ids.indexOf(a)}),onChange:t=>{i({form_ids:t.map(e=>e.value)},e)}})]})},[Il.gw.SUBSCRIBER_LAST_ENGAGEMENT_DATE]:cd,[Il.gw.SUBSCRIBER_LAST_PURCHASE_DATE]:cd,[Il.gw.SUBSCRIBER_LAST_OPEN_DATE]:cd,[Il.gw.SUBSCRIBER_LAST_CLICK_DATE]:cd,[Il.gw.SUBSCRIBER_LAST_PAGE_VIEW_DATE]:cd,[Il.gw.SUBSCRIBER_LAST_SENDING_DATE]:cd},lc={[Il.dx.Automations]:function(e){return!!Object.values(Ul.g).some(t=>t===e.action)&&(e.action!==Ul.g.ENTERED_AUTOMATION||function(e){return(e.operator===Il.dP.ANY||e.operator===Il.dP.NONE||e.operator===Il.dP.ALL)&&Array.isArray(e.automation_ids)&&e.automation_ids.length>0}(e))},[Il.dx.Email]:function(e){return!!Object.values(Il._R).some(t=>t===e.action)&&(e.action===Il._R.CLICKED_ANY||(e.action===Il._R.CLICKED?!!e.newsletter_id:[Il._R.OPENED,Il._R.MACHINE_OPENED,Il._R.WAS_SENT].includes(e.action)?Array.isArray(e.newsletters)&&e.newsletters.length>0:[Il._R.OPENS_ABSOLUTE_COUNT,Il._R.MACHINE_OPENS_ABSOLUTE_COUNT].includes(e.action)?td(e)&&!!e.opens&&!!e.operator:Il._R.NUMBER_RECEIVED===e.action?td(e)&&!!e.emails&&!!e.operator:e.action===Il._R.NUMBER_OF_CLICKS&&td(e)&&!!e.clicks&&!!e.operator))},[Il.dx.WooCommerce]:function(e){return!!Object.values(md.Ag).some(t=>t===e.action)&&(e.action===md.Ag.PURCHASED_CATEGORY?function(e){return!(void 0===e.category_ids||0===e.category_ids.length||!e.operator||!td(e))}(e):e.action===md.Ag.PURCHASED_PRODUCT?function(e){return!(void 0===e.product_ids||0===e.product_ids.length||!e.operator||!td(e))}(e):e.action===md.Ag.PURCHASED_PRODUCT_VARIATION?function(e){return Array.isArray(e.variation_ids)&&e.variation_ids.length>0&&!!e.operator&&td(e)}(e):e.action===md.Ag.CUSTOMER_IN_COUNTRY?function(e){return!(void 0===e.country_code||0===e.country_code.length)}(e):[md.Ag.NUMBER_OF_ORDERS,md.Ag.NUMBER_OF_ORDERS_WITH_COUPON].includes(e.action)?function(e){return!(!e.number_of_orders_count||!td(e)||!e.number_of_orders_type)}(e):e.action===md.Ag.TOTAL_SPENT?function(e){return!(!e.total_spent_amount||!td(e)||!e.total_spent_type)}(e):e.action===md.Ag.SINGLE_ORDER_VALUE?function(e){return!(!e.single_order_value_amount||!td(e)||!e.single_order_value_type)}(e):e.action===md.Ag.AVERAGE_SPENT?function(e){return!(!e.average_spent_amount||!e.average_spent_type||!td(e))}(e):e.action===md.Ag.USED_PAYMENT_METHOD?function(e){return!(!e.payment_methods||e.payment_methods.length<1||!e.operator||!td(e))}(e):e.action===md.Ag.USED_SHIPPING_METHOD?function(e){return!(!e.shipping_methods||e.shipping_methods.length<1||!e.operator||!td(e))}(e):e.action===md.Ag.PURCHASE_DATE?od(e):e.action===md.Ag.NUMBER_OF_REVIEWS?function(e){return!!(e.count&&e.count_type&&e.rating&&td(e))}(e):e.action===md.Ag.USED_COUPON_CODE?function(e){return!(!e.coupon_code_ids||e.coupon_code_ids.length<1||!(0,br.J)(e.operator,Il.dP)||!td(e))}(e):e.action===md.Ag.FIRST_ORDER?od(e):e.action===md.Ag.PURCHASED_WITH_ATTRIBUTE?function(e){return!!(e.operator&&e.attribute_type&&("taxonomy"!==e.attribute_type||void 0!==e.attribute_taxonomy_slug&&Array.isArray(e.attribute_term_ids)&&0!==e.attribute_term_ids.length)&&("local"!==e.attribute_type||e.attribute_local_name&&0!==e.attribute_local_name.length&&Array.isArray(e.attribute_local_values)&&0!==e.attribute_local_values.length)&&td(e))}(e):[md.Ag.CUSTOMER_IN_POSTAL_CODE,md.Ag.CUSTOMER_IN_CITY].includes(e.action)?hd(e):e.action!==md.Ag.PURCHASED_TAG||function(e){return!(void 0===e.tag_ids||0===e.tag_ids.length||!e.operator||!td(e))}(e))},[Il.dx.WordPressRole]:function(e){return e.action&&e.action!==Il.gw.WORDPRESS_ROLE?e.action===Il.gw.MAILPOET_CUSTOM_FIELD?function(e){const t=sc[e.custom_field_type];return!!t&&t(e)}(e):e.action===Il.gw.SUBSCRIBER_SCORE?function(e){if(e.operator===bd.HIGHER_THAN||e.operator===bd.LOWER_THAN||e.operator===bd.EQUALS||e.operator===bd.NOT_EQUALS){const t=Number(e.value),a=Number(parseFloat(e.value));return!Number.isNaN(t)&&!Number.isNaN(a)&&t>=0&&t<=100}return e.operator===bd.UNKNOWN||e.operator===bd.NOT_UNKNOWN||e.operator===bd.DORMANT||e.operator===bd.NOT_DORMANT}(e):e.action===Il.gw.SUBSCRIBED_TO_LIST?function(e){return(e.operator===Il.dP.ANY||e.operator===Il.dP.ALL||e.operator===Il.dP.NONE)&&Array.isArray(e.segments)&&e.segments.length>0}(e):e.action===Il.gw.SUBSCRIBER_TAG?function(e){return Ta.Hooks.applyFilters("mailpoet_dynamic_segments_filter_subscriber_tag_validate",!1,e)}(e):[Il.gw.SUBSCRIBER_FIRST_NAME,Il.gw.SUBSCRIBER_LAST_NAME,Il.gw.SUBSCRIBER_EMAIL].includes(e.action)?hd(e):[Il.gw.SUBSCRIBER_LAST_ENGAGEMENT_DATE,Il.gw.SUBSCRIBER_LAST_PURCHASE_DATE,Il.gw.SUBSCRIBER_LAST_OPEN_DATE,Il.gw.SUBSCRIBER_LAST_CLICK_DATE,Il.gw.SUBSCRIBER_LAST_PAGE_VIEW_DATE,Il.gw.SUBSCRIBER_LAST_SENDING_DATE].includes(e.action)?od(e):e.action===Il.gw.SUBSCRIBED_VIA_FORM?function(e){return(e.operator===Il.dP.ANY||e.operator===Il.dP.NONE)&&Array.isArray(e.form_ids)&&e.form_ids.length>0}(e):!(!e.operator||!e.value)&&!!Object.values(sd).includes(e.operator)&&od(e):Array.isArray(e.wordpressRole)&&e.wordpressRole.length>0},[Il.dx.WooCommerceMembership]:function(e){const t=!e.plan_ids||!e.plan_ids.length||!e.operator;return e.action!==md.HM.MEMBER_OF||!t},[Il.dx.WooCommerceSubscription]:function(e){const t=!e.product_ids||!e.product_ids.length||!e.operator;return e.action!==md.IC.ACTIVE_SUBSCRIPTIONS||!t}};function dc(e){return!(e.length<1)&&0===e.map(e=>void 0!==lc[e.segmentType]&&lc[e.segmentType](e)).filter(e=>!1===e).length}let cc,mc;function uc(){const e=(0,C.A)(e=>e(Al.Hz).getSegment(),[]),t=(0,C.A)(e=>e(Al.Hz).getSubscriberCount(),[]),{updateSubscriberCount:a}=(0,fe.A)(Al.Hz),i=JSON.stringify(e),s=(0,r.useRef)(1),n=(0,r.useRef)(null),o=(0,r.useRef)(!1),l=(0,r.useRef)((0,Jt.debounce)(function e(t){if(o.current)return void(n.current=t);n.current=null,s.current+=1;const i=s.current;o.current=!0,function(e){const t={filters:e.filters,filters_connect:e.filters_connect};return Qt().isEqual(t,cc)?Promise.resolve(mc):(cc={filters:[...e.filters],filters_connect:e.filters_connect},m.U.Ajax.post({api_version:m.U.apiVersion,endpoint:"dynamic_segments",action:"getCount",data:e,timeout:2e4}).then(e=>{const{data:t}=e;return mc={count:t.count,errors:void 0},mc}))}(t).then(t=>{if(o.current=!1,n.current)return void e(n.current);if(i!==s.current)return;const r={loading:!1};t&&(r.count=t.count,r.errors=t.errors),a(r)},e=>{o.current=!1;const t={},i=e.errors.map(e=>e.message);t.loading=!1,t.count=void 0,t.errors=i,a(t)})},2e3,{trailing:!0}));return(0,r.useEffect)(()=>{dc(e.filters)?(a({loading:!0,count:void 0,errors:void 0}),(0,l.current)(e)):a({count:void 0,loading:!1})},[e,i,a]),t.errors?(0,g.jsx)("div",{className:"mailpoet-form-field",children:(0,g.jsxs)("span",{className:"mailpoet-form-error-message",children:[m.U.I18n.t("dynamicSegmentSizeCalculatingTimeout")," ",(0,g.jsx)("a",{href:"https://kb.mailpoet.com/article/237-guide-to-subscriber-segmentation",target:"_blank",className:"mailpoet-form-error-message",rel:"noopener noreferrer",children:m.U.I18n.t("learnMore")})]})}):t.loading||void 0!==t.count?t.loading?(0,g.jsx)("div",{className:"mailpoet-form-field",children:(0,g.jsx)("span",{className:"mailpoet-form-notice-message",children:m.U.I18n.t("dynamicSegmentSizeIsCalculated")})}):(0,g.jsx)("div",{className:"mailpoet-form-field",children:(0,g.jsx)("span",{className:"mailpoet-form-notice-message",children:m.U.I18n.t("dynamicSegmentSize").replace("%1$d",t.count.toLocaleString())})}):(0,g.jsx)("span",{})}const pc={[Il.dx.Automations]:function({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),a=Pl[t.action];return a?(0,g.jsx)(a,{filterIndex:e}):null},[Il.dx.Email]:function({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),a=id[t.action];return a?(0,g.jsx)(a,{filterIndex:e}):null},[Il.dx.WooCommerce]:function({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),a=_d[t.action];return a?(0,g.jsx)(a,{filterIndex:e}):null},[Il.dx.WordPressRole]:function({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]);let a;return a=t.action?oc[t.action]:fd,a?(0,g.jsx)(a,{filterIndex:e}):null},[Il.dx.WooCommerceMembership]:function({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilter:a,updateSegmentFilterFromEvent:i}=(0,fe.A)(Al.Hz),s=(0,C.A)(e=>e(Al.Hz).getMembershipPlans(),[]).map(e=>({value:e.id,label:e.name}));return(0,r.useEffect)(()=>{t.action===md.HM.MEMBER_OF&&t.operator!==Il.dP.ANY&&t.operator!==Il.dP.ALL&&t.operator!==Il.dP.NONE&&a({operator:Il.dP.ANY},e)},[a,t,e]),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(Di.Grid.CenteredRow,{children:(0,g.jsxs)(Be.Select,{value:t.operator,onChange:t=>{i("operator",e,t)},automationId:"select-operator",children:[(0,g.jsx)("option",{value:Il.dP.ANY,children:m.U.I18n.t("anyOf")}),(0,g.jsx)("option",{value:Il.dP.ALL,children:m.U.I18n.t("allOf")}),(0,g.jsx)("option",{value:Il.dP.NONE,children:m.U.I18n.t("noneOf")})]},"select-operator")}),(0,g.jsx)(Di.Grid.CenteredRow,{children:(0,g.jsx)(kl.ReactSelect,{isMulti:!0,dimension:"small",isFullWidth:!0,placeholder:m.U.I18n.t("selectWooMembership"),options:s,value:(0,Sn.filter)(e=>!!t.plan_ids&&-1!==t.plan_ids.indexOf(e.value),s),onChange:t=>{a({plan_ids:(t||[]).map(e=>e.value)},e)},automationId:"select-segment-plans"},"select-segment-membership-plan")})]})},[Il.dx.WooCommerceSubscription]:function({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]),{updateSegmentFilter:a,updateSegmentFilterFromEvent:i}=(0,fe.A)(Al.Hz),s=(0,C.A)(e=>e(Al.Hz).getSubscriptionProducts(),[]).map(e=>({value:e.id,label:e.name}));return(0,r.useEffect)(()=>{t.action===md.IC.ACTIVE_SUBSCRIPTIONS&&t.operator!==Il.dP.ANY&&t.operator!==Il.dP.ALL&&t.operator!==Il.dP.NONE&&a({operator:Il.dP.ANY},e)},[a,t,e]),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(Di.Grid.CenteredRow,{children:(0,g.jsxs)(Be.Select,{value:t.operator,onChange:t=>{i("operator",e,t)},automationId:"select-operator",children:[(0,g.jsx)("option",{value:Il.dP.ANY,children:m.U.I18n.t("anyOf")}),(0,g.jsx)("option",{value:Il.dP.ALL,children:m.U.I18n.t("allOf")}),(0,g.jsx)("option",{value:Il.dP.NONE,children:m.U.I18n.t("noneOf")})]},"select-operator")}),(0,g.jsx)(Di.Grid.CenteredRow,{children:(0,g.jsx)(kl.ReactSelect,{isMulti:!0,dimension:"small",isFullWidth:!0,placeholder:m.U.I18n.t("selectWooSubscription"),options:s,value:(0,Sn.filter)(e=>!!t.product_ids&&-1!==t.product_ids.indexOf(e.value),s),onChange:t=>{a({product_ids:(t||[]).map(e=>e.value)},e)},automationId:"select-segment-products"},"select-segment-category")})]})}};function hc({filterIndex:e}){const t=(0,C.A)(t=>t(Al.Hz).getSegmentFilter(e),[e]);if(void 0===t||void 0===pc[t.segmentType])return null;const a=pc[t.segmentType];return(0,g.jsx)(a,{filterIndex:e})}function gc(){const e=(0,C.A)(e=>e(Al.Hz).getSegment(),[]),t=[Il._R.OPENED,Il._R.OPENS_ABSOLUTE_COUNT,Il._R.MACHINE_OPENED,Il._R.MACHINE_OPENS_ABSOLUTE_COUNT];let a=!1;return e.filters.forEach(e=>{t.includes(e.action)&&(a=!0)}),a?(0,g.jsx)("div",{className:"mailpoet-form-field",children:(0,g.jsx)("span",{className:"mailpoet-form-notice-message",children:m.U.I18n.t("privacyProtectionNotice")})}):(0,g.jsx)("span",{})}const _c=Ta.Hooks.applyFilters("mailpoet_dynamic_segments_form_filters_before",()=>null),fc=Ta.Hooks.applyFilters("mailpoet_dynamic_filters_filter_before",()=>null),bc=Ta.Hooks.applyFilters("mailpoet_dynamic_filters_filter_after",()=>(0,g.jsx)("div",{className:"mailpoet-gap"})),xc=Ta.Hooks.applyFilters("mailpoet_dynamic_segments_form_conditions_bottom",()=>null),vc=Ta.Hooks.applyFilters("mailpoet_dynamic_segments_filter_group_before",()=>null);function yc({isNewSegment:e,newsletterId:t}){const{segment:a,segmentFilters:i,subscriberCount:s,filterRows:n,errors:o}=(0,C.A)(e=>{const t=e(Al.Hz).getSegment();return{segment:t,segmentFilters:e(Al.Hz).getAvailableFilters(),subscriberCount:e(Al.Hz).getSubscriberCount(),filterRows:e(Al.Hz).findFiltersValueForSegment(t),errors:e(Al.Hz).getErrors()}},[]),l=a.filters.length,d=m.U.capabilities.segmentFilters.value>0&&l>=m.U.capabilities.segmentFilters.value,{updateSegment:c,updateSegmentFilter:u,handleSave:h}=(0,fe.A)(Al.Hz),[_,f]=(0,r.useState)(!1),b=Ta.Hooks.applyFilters("mailpoet_dynamic_segments_form_add_condition_action",()=>{f(!0)}),x=Array.isArray(n)?((e,t)=>e.reduce((e,a)=>{const i=t.filters[a.index]?.group_id??0,s=e.find(e=>e.groupId===i);return s?s.rows.push(a):e.push({groupId:i,rows:[a]}),e},[]))(n,a):[],v=x.length>1;return(0,g.jsx)("div",{className:"mailpoet-form-container",children:(0,g.jsxs)("form",{children:[o.length>0&&(0,g.jsx)(gi,{errors:o.map(e=>({message:e}))}),(0,g.jsxs)(Cl,{title:(0,p.__)("Details","mailpoet"),description:(0,p.__)("What do you want to call this segment?","mailpoet"),children:[(0,g.jsx)(El,{slug:"name",title:(0,p.__)("Name","mailpoet"),children:(0,g.jsx)(Dt.p,{isFullWidth:!0,type:"text",name:"name",id:"field_name",value:a.name||"","data-automation-id":"input-name",onChange:e=>{c({name:e.target.value})},placeholder:(0,p.__)("Enter name","mailpoet")})}),(0,g.jsx)(El,{slug:"description",title:(0,p.__)("Description","mailpoet"),description:(0,p.__)("This text box is for your own use and is never shown to your subscribers.","mailpoet"),children:(0,g.jsx)(Dt.p,{isFullWidth:!0,name:"description",id:"field_description",value:a.description||"","data-automation-id":"input-description",onChange:e=>{c({description:e.target.value})},placeholder:(0,p.__)("Enter description","mailpoet")})})]}),(0,g.jsx)(Cl,{title:(0,p.__)("Conditions","mailpoet"),description:(0,p.__)("Set your segment constraints","mailpoet"),children:(0,g.jsx)(El,{children:(0,g.jsxs)("div",{className:"mailpoet-segments-segments-section",children:[(0,g.jsx)(_c,{}),x.map((e,t)=>(0,g.jsxs)(r.Fragment,{children:[(0,g.jsxs)("div",{className:"mailpoet-segments-filter-group"+(v?" mailpoet-segments-filter-group-is-separated":""),"data-automation-id":`filter-group-${e.groupId}`,children:[(0,g.jsx)(vc,{groupFilterRows:e.rows,groupId:e.groupId}),e.rows.map((t,a)=>(0,g.jsxs)(r.Fragment,{children:[(0,g.jsxs)("div",{className:"mailpoet-segments-grid","data-automation-id":`filter-row-${t.index}`,children:[(0,g.jsx)(fc,{filterRows:n,groupFilterRows:e.rows,groupId:e.groupId,index:t.index}),(0,g.jsx)("div",{className:"mailpoet-segments-filter-selector",children:(0,g.jsx)(kl.ReactSelect,{dimension:"small",placeholder:(0,p.__)("Select action","mailpoet"),options:i,value:t.filterValue,onChange:e=>{u({segmentType:e.group,action:e.value},t.index)},automationId:"select-segment-action",isFullWidth:!0})}),void 0!==t.index&&(0,g.jsx)(hc,{filterIndex:t.index})]}),a<e.rows.length-1&&(0,g.jsx)(bc,{index:t.index})]},t.index)),(0,g.jsx)("div",{className:"mailpoet-segments-filter-group-actions",children:(0,g.jsx)(ge.Ay,{type:"button",variant:"secondary",onClick:t=>{t.preventDefault(),b(a,c,e.groupId)},children:(0,p.__)("Add a condition","mailpoet")})})]}),t<x.length-1&&(0,g.jsx)(bc,{index:e.rows[e.rows.length-1].index})]},e.groupId)),(0,g.jsxs)("div",{className:"mailpoet-segments-conditions-bottom",children:[(0,g.jsx)(xc,{}),(!m.U.premiumActive||!m.U.hasValidPremiumKey||m.U.subscribersLimitReached||d)&&(0,g.jsx)(hs.S,{text:(0,p.__)("UPGRADE","mailpoet")}),_&&(0,g.jsx)(ps.D,{onRequestClose:()=>{f(!1)},data:{capabilities:{segmentFilters:0}},children:(0,p.__)("Multiple conditions per segment are not available in the free version of the MailPoet plugin.","mailpoet")})]})]})})}),(0,g.jsxs)("div",{className:"mailpoet-admin-fields-footer",children:[(0,g.jsxs)("div",{className:"mailpoet-segments-counter-section",children:[(0,g.jsx)(uc,{}),(0,g.jsx)(gc,{})]}),(0,g.jsx)("div",{className:"mailpoet-form-actions",children:(0,g.jsx)(ge.Ay,{variant:"primary",type:"submit",onClick:a=>{a.preventDefault(),h(e,t)},disabled:!dc(a.filters)||void 0===s.count,children:t?(0,p.__)("Save and return","mailpoet"):(0,p.__)("Save","mailpoet")})})]})]})})}function wc(){const e=(0,Ue.g)(),{pageLoaded:t,pageUnloaded:a}=(0,fe.A)(Al.Hz),i=(0,C.A)(e=>e(Al.Hz).getPreviousPage())||"/",s=(0,Ue.zy)(),n=new URLSearchParams(s.search).get("newsletterId")||null;(0,r.useEffect)(()=>(t(e.id),()=>{a()}),[e.id,t,a]);const o=void 0===e.id||Number.isNaN(Number(e.id));return(0,g.jsxs)("div",{className:"mailpoet-main-container",children:[(0,g.jsx)(d.x,{hideScreenOptions:!0}),(0,g.jsx)(qe.z,{heading:e.id?(0,p.__)("Edit segment","mailpoet"):(0,p.__)("Add new segment","mailpoet"),headingPrefix:(0,g.jsx)(qe.o,{id:"mailpoet-segments-back-button",href:`#${i}`,label:(0,p.__)("Return to previous page","mailpoet"),onClick:e=>{n&&(e.preventDefault(),window.location.href=`admin.php?page=mailpoet-newsletters#/send/${n}`)}})}),(0,g.jsx)(yc,{isNewSegment:o,newsletterId:n})]})}function jc(e,t,a,i){const{from:s,to:n}=(0,$e._O)(a,i);return{...s?{[e]:s}:{},...n?{[t]:n}:{}}}wc.displayName="SegmentEditor";var Sc=a(62623);function kc(){const{notices:e}=(0,C.A)(e=>({notices:e(Sc.store).getNotices()}),[]),{removeNotice:t}=(0,fe.A)(Sc.store),a=e.filter(({isDismissible:e,type:t})=>e&&"default"===t),i=e.filter(({isDismissible:e,type:t})=>!e&&"default"===t);return(0,g.jsxs)(g.Fragment,{children:[i.reverse().map(({id:e,status:t,content:a,__unstableHTML:i})=>(0,g.jsx)(h.$,{renderInPlace:!0,type:t,timeout:!1,children:i??(0,g.jsx)("p",{children:a})},e)),a.reverse().map(({id:e,status:a,content:i,__unstableHTML:s})=>(0,g.jsx)(h.$,{type:a,renderInPlace:!0,timeout:!1,closable:!0,onClose:()=>t(e),children:s??(0,g.jsx)("p",{children:i})},e))]})}const Nc={offset:0,limit:25,search:"",sort_by:"updated_at",sort_order:"desc",group:"all"};function Cc(e){return e.split("/").map(e=>e.replace(/\]$/,"").split("[")).map(([e,t])=>[e,"number"==typeof Nc[e]?parseInt(t,10):t]).reduce((e,[t,a])=>({...e,[t]:a}),{})}function Ec(e=window.location.hash,t={}){return{...Nc,...t,...Cc(e)}}var Ic=a(85750);let Ac=!1;function Uc(){if(Ac)return;const e=window.mailpoet_segments_api;tl.default.use(tl.default.createRootURLMiddleware(`${e.root}/`)),tl.default.use(tl.default.createNonceMiddleware(e.nonce)),Ac=!0}function Tc(e){return Object.entries(e).reduce((e,[t,a])=>void 0!==a?{...e,[t]:a}:e,{})}function Pc(e,t){return e?(0,r.createElement)("span",{"data-automation-id":t?`mailpoet_dynamic_segment_updated_at_${t}`:"mailpoet_dynamic_segment_updated_at"},(0,r.createElement)("span",null,m.U.Date.short(e)),(0,r.createElement)("br",null),(0,r.createElement)("span",null,m.U.Date.time(e))):(0,r.createElement)("span",null,"—")}const Rc=[{id:"name",label:(0,p.__)("Segment","mailpoet"),type:"text",enableSorting:!0,enableGlobalSearch:!0,filterBy:!1,render:({item:e})=>(0,r.createElement)("div",{"data-automation-id":`mailpoet_dynamic_segment_name_${e.id}`},e.is_plugin_missing?(0,r.createElement)("span",null,e.name):(0,r.createElement)("a",{href:`#${Ic.r$}/${e.id}`},e.name),e.description?(0,r.createElement)("div",null,e.description):null,e.is_plugin_missing?(0,r.createElement)("div",{className:"mailpoet-segments-dataviews__row-note","data-automation-id":`mailpoet_dynamic_segment_plugin_missing_message_${e.id}`},function(e){return(0,p.sprintf)((0,p.__)("Edit unavailable: %s","mailpoet"),e.missing_plugin_message?.message??(0,p.__)("Required plugin is inactive.","mailpoet"))}(e)):null)},{id:"subscribers",label:(0,p.__)("Number of subscribers","mailpoet"),enableSorting:!1,enableGlobalSearch:!1,render:({item:e})=>e.is_plugin_missing?(0,r.createElement)("span",null,"—"):(0,r.createElement)("div",{"data-automation-id":`mailpoet_dynamic_segment_count_all_${e.id}`},e.count_all)},{id:"subscribed",label:(0,p.__)("Subscribed","mailpoet"),enableSorting:!1,enableGlobalSearch:!1,render:({item:e})=>e.is_plugin_missing?null:"0"===e.count_subscribed?(0,r.createElement)("span",null,e.count_subscribed):(0,r.createElement)("a",{"data-automation-id":`mailpoet_dynamic_segment_count_subscribed_${e.id}`,className:"components-button is-link mailpoet-listing-text-right-align",href:e.subscribers_url},e.count_subscribed)},{id:"created_at",label:(0,p.__)("Created","mailpoet"),type:"date",enableSorting:!0,enableGlobalSearch:!1,filterBy:{operators:["on","beforeInc","afterInc","between"]},render:({item:e})=>Pc(e.created_at)},{id:"updated_at",label:(0,p.__)("Modified","mailpoet"),type:"date",enableSorting:!0,enableGlobalSearch:!1,filterBy:{operators:["on","beforeInc","afterInc","between"]},render:({item:e})=>Pc(e.updated_at,e.id)}];var Dc=a(70609);const Fc={type:"table",fields:["subscribers","subscribed","updated_at"],titleField:"name",showTitle:!0};function Oc(e,t=Fc){return{...t,perPage:e.limit,page:Math.floor(e.offset/e.limit)+1,search:e.search,sort:{field:e.sort_by,direction:"asc"===e.sort_order?"asc":"desc"}}}function Mc(e,t){return(e.perPage??25)===t.limit&&(e.page??1)===Math.floor(t.offset/t.limit)+1&&(e.search??"")===t.search&&(e.sort?.field??"updated_at")===t.sort_by&&(e.sort?.direction??"desc")===t.sort_order}function Lc(e){return e.limit>0&&e.offset%e.limit!==0}var $c=a(87691);const Bc=[{name:(0,p.__)("Recently Subscribed","mailpoet"),slug:"recently-subscribed",category:Il.eu.ENGAGEMENT,description:(0,p.__)("Contacts who have subscribed to your emails within the last 30 days.","mailpoet"),isEssential:!0,filters:[{segmentType:"userRole",action:"subscribedDate",operator:"inTheLast",value:"30"}]},{name:(0,p.__)("Engaged Subscribers (30 days)","mailpoet"),slug:"engaged-subscribers-30-days",category:Il.eu.ENGAGEMENT,description:(0,p.__)("Contacts who have interacted with your emails or made at least one purchase, and received emails from you in the last 30 days.","mailpoet"),isEssential:!0,filters:[{segmentType:"userRole",action:"lastEngagementDate",operator:"inTheLast",value:"30"}]},{name:(0,p.__)("Engaged Subscribers (3 months)","mailpoet"),slug:"engaged-subscribers-3-months",category:Il.eu.ENGAGEMENT,description:(0,p.__)("Contacts who have interacted with your emails or made at least one purchase, and received emails from you in the last 3 months.","mailpoet"),isEssential:!0,filters:[{segmentType:"userRole",action:"lastEngagementDate",operator:"inTheLast",value:"90"}]},{name:(0,p.__)("Engaged Subscribers (6 months)","mailpoet"),slug:"engaged-subscribers-6-months",category:Il.eu.ENGAGEMENT,description:(0,p.__)("Contacts who have interacted with your emails or made at least one purchase, and received emails from you in the last 6 months.","mailpoet"),isEssential:!0,filters:[{segmentType:"userRole",action:"lastEngagementDate",operator:"inTheLast",value:"180"}],filtersConnect:Il.Z2.OR},{name:(0,p.__)("Unengaged Subscribers","mailpoet"),slug:"unengaged-subscribers",category:Il.eu.ENGAGEMENT,description:(0,p.__)("Contacts who haven’t interacted with your emails, haven’t made a purchase, or haven’t visited your page in the last 6 months.","mailpoet"),filters:[{segmentType:"userRole",action:"lastEngagementDate",operator:"notInTheLast",value:"180"},{segmentType:"userRole",action:"subscribedDate",operator:"notInTheLast",value:"210"},{segmentType:"email",action:"numberReceived",operator:"more",emails:"9",timeframe:Il.VE.ALL_TIME}],isEssential:!0},{name:(0,p.__)("First-Time Buyers","mailpoet"),slug:"first-time-buyers",category:Il.eu.PURCHASE_HISTORY,description:(0,p.__)("Customers who have made their first purchase in the last 30 days.","mailpoet"),filters:[{segmentType:"woocommerce",action:"firstOrder",operator:sd.IN_THE_LAST,value:"30"}],isEssential:!0},{name:(0,p.__)("Recent Buyers","mailpoet"),slug:"recent-buyers",category:Il.eu.PURCHASE_HISTORY,description:(0,p.__)("Customers who have made a purchase within the last 30 days. ","mailpoet"),isEssential:!0,filters:[{segmentType:"woocommerce",action:"numberOfOrders",timeframe:Il.VE.IN_THE_LAST,number_of_orders_type:">",number_of_orders_count:0,days:"30"}]},{name:(0,p.__)("Repeat Buyers","mailpoet"),slug:"repeat-buyers",category:Il.eu.PURCHASE_HISTORY,description:(0,p.__)("Customers who have made at least two purchases in the last 6 months.","mailpoet"),isEssential:!0,filters:[{segmentType:"woocommerce",action:"numberOfOrders",timeframe:Il.VE.IN_THE_LAST,number_of_orders_type:">",number_of_orders_count:1,days:"180"}]},{name:(0,p.__)("Loyal Buyers","mailpoet"),slug:"loyal-buyers",category:Il.eu.PURCHASE_HISTORY,description:(0,p.__)("Customers who have made at least five purchases in the last 12 months.","mailpoet"),isEssential:!0,filters:[{segmentType:"woocommerce",action:"numberOfOrders",timeframe:Il.VE.IN_THE_LAST,number_of_orders_type:">",number_of_orders_count:4,days:"365"}]},{name:(0,p.__)("Win-Back","mailpoet"),slug:"win-back",category:Il.eu.PURCHASE_HISTORY,description:(0,p.__)("Customers who have previously purchased, but haven’t made a purchase in the last 6 months.","mailpoet"),isEssential:!0,filters:[{segmentType:"userRole",action:"lastPurchaseDate",operator:"notInTheLast",value:"180"}]},{name:(0,p.__)("Lapsed Customers","mailpoet"),slug:"lapsed-customers",category:Il.eu.PURCHASE_HISTORY,description:(0,p.__)("Customers who haven’t made a purchase in the last 9 months.","mailpoet"),isEssential:!1,filters:[{segmentType:"userRole",action:"lastPurchaseDate",operator:"notInTheLast",value:"270"}]},{name:(0,p.__)("Clickers","mailpoet"),slug:"clickers",category:Il.eu.ENGAGEMENT,description:(0,p.__)("Contacts who regularly click on your emails in the last 90 days.","mailpoet"),filters:[{segmentType:"email",action:"numberOfClicks",operator:"more",timeframe:Il.VE.IN_THE_LAST,clicks:"2",days:"90"}],isEssential:!1},{name:(0,p.__)("Non-Openers","mailpoet"),slug:"non-openers",category:Il.eu.ENGAGEMENT,description:(0,p.__)("Contacts who have received but haven’t opened an email in the last 90 days.","mailpoet"),isEssential:!1,filters:[{segmentType:"email",action:"numberReceived",operator:"more",timeframe:Il.VE.IN_THE_LAST,emails:"0",days:"90"},{segmentType:"email",action:"opensAbsoluteCount",operator:"equals",timeframe:Il.VE.IN_THE_LAST,opens:"0",days:"90"}]},{name:(0,p.__)("Recent Clickers","mailpoet"),slug:"recent-clickers",category:Il.eu.ENGAGEMENT,description:(0,p.__)("Contacts who have clicked on an email in the last 7 days.","mailpoet"),filters:[{segmentType:"email",action:"numberOfClicks",operator:"more",timeframe:Il.VE.IN_THE_LAST,clicks:"0",days:"7"}],isEssential:!1},{name:(0,p.__)("Recent Openers","mailpoet"),slug:"recent-openers",category:Il.eu.ENGAGEMENT,description:(0,p.__)("Contacts who have opened an email in the last 7 days.","mailpoet"),isEssential:!1,filters:[{segmentType:"email",action:"opensAbsoluteCount",operator:"more",timeframe:Il.VE.IN_THE_LAST,opens:"0",days:"7"}]},{name:(0,p.__)("Big Spenders","mailpoet"),slug:"big-spenders",category:Il.eu.SHOPPING_BEHAVIOR,description:(0,p.__)("Customers who have completed $100 or more worth of orders in the last 12 months.","mailpoet"),isEssential:!1,filters:[{segmentType:"woocommerce",action:"totalSpent",timeframe:Il.VE.IN_THE_LAST,total_spent_type:">",total_spent_amount:100,days:"365"}]},{name:(0,p.__)("Used a discount code","mailpoet"),slug:"used-a-discount-code",category:Il.eu.SHOPPING_BEHAVIOR,description:(0,p.__)("Customers who made a purchase with a coupon code in the last 30 days.","mailpoet"),filters:[{segmentType:"woocommerce",action:md.Ag.NUMBER_OF_ORDERS_WITH_COUPON,number_of_orders_type:">",number_of_orders_count:0,timeframe:Il.VE.IN_THE_LAST,days:"30"}],isEssential:!1},{name:(0,p.__)("Frequently uses discounts","mailpoet"),slug:"frequently-uses-discounts",category:Il.eu.SHOPPING_BEHAVIOR,description:(0,p.__)("Customers who have regularly used coupons in the last 90 days.","mailpoet"),filters:[{segmentType:"woocommerce",action:md.Ag.NUMBER_OF_ORDERS_WITH_COUPON,number_of_orders_type:">",number_of_orders_count:2,timeframe:Il.VE.IN_THE_LAST,days:"90"}],isEssential:!1}],Wc=[{slug:Il.eu.ENGAGEMENT,name:(0,p.__)("Engagement","mailpoet")},{slug:Il.eu.PURCHASE_HISTORY,name:(0,p.__)("Purchase History","mailpoet")},{slug:Il.eu.SHOPPING_BEHAVIOR,name:(0,p.__)("Shopping Behavior","mailpoet")}];function Vc(e){const t=Wc.find(t=>t.slug===e);return t?t.name:null}var qc=a(60078);const zc=[{name:"all",title:(0,g.jsx)(qc.Ic,{title:(0,p.__)("All","mailpoet"),count:Bc.length})}];Wc.forEach(e=>{const t=Bc.filter(t=>t.category===e.slug).length;zc.push({name:e.slug,title:(0,g.jsx)(qc.Ic,{title:e.name,count:t})})});const Hc=document.getElementById("dynamic_segments_container");function Gc(){const{setPreviousPage:e}=(0,fe.A)(Al.Hz),t=(0,Ue.zy)(),a=(0,r.useRef)(t.pathname);return(0,r.useEffect)(()=>{e(a.current),a.current=t.pathname},[t,e]),null}const Yc=(0,o.withBoundary)(wc),Kc=(0,o.withBoundary)(function(){const e=(0,C.A)(e=>e(Al.Hz).getErrors(),[]),{createFromTemplate:t}=(0,fe.A)(Al.Hz),a=()=>{m.U.trackEvent("Segments > New empty segment")};return(0,g.jsxs)("div",{className:"mailpoet-main-container",children:[(0,g.jsx)(d.x,{hideScreenOptions:!0}),(0,g.jsxs)(qe.z,{className:"mailpoet-templates-header",heading:(0,p.__)("Start with a pre-built segment","mailpoet"),headingPrefix:(0,g.jsx)(qe.o,{href:"#/",label:(0,p.__)("Segments list","mailpoet"),"aria-label":(0,p.__)("Navigate to the segments list page","mailpoet")}),children:[(0,g.jsx)($c.A,{label:(0,p.__)("Search segment templates","mailpoet"),onChange:()=>null}),(0,g.jsx)("a",{href:`#${Ic.LX}`,"data-automation-id":"new-custom-segment",onClick:()=>{a()},className:"page-title-action",children:(0,p.__)("Or, create custom segment","mailpoet")})]}),e.length>0&&(0,g.jsx)(gi,{errors:e.map(e=>({message:e}))}),(0,g.jsx)(qc.Kp,{tabs:zc,children:e=>(0,g.jsx)(qc.xA,{children:Bc.filter(t=>"all"===e.name||t.category===e.name).map(e=>(0,g.jsx)(qc.q7,{name:e.name,description:e.description,category:Vc(e.category),badge:e.isEssential?"essential":void 0,onClick:()=>{t(e)}},e.slug))})}),(0,g.jsxs)(qc.wi,{children:[(0,g.jsx)("p",{children:(0,p.__)("Want to set your own conditions?","mailpoet")}),(0,g.jsx)(ge.Ay,{variant:"link",href:`#${Ic.LX}`,onClick:()=>{a()},children:(0,p.__)("Create custom segment","mailpoet")})]})]})}),Zc=(0,o.withBoundary)(function(){const e=(0,r.useCallback)(()=>function(e){return{limit:e.perPage??25,sort_by:e.sort?.field??"updated_at",sort_order:e.sort?.direction??"desc"}}((0,$e.Aq)("dynamic-segments",Fc,Rc)),[]),t=(0,r.useMemo)(()=>(0,$e.Aq)("dynamic-segments",Fc,Rc),[]),[a]=(0,r.useState)(()=>Ec(window.location.hash,e())),[i,s]=(0,r.useState)(a.group),[n,o]=(0,r.useState)([]),[l,c]=(0,r.useState)(null),[u,h]=(0,r.useState)(null),[_,f]=(0,r.useState)(null),b=(0,r.useRef)(Lc(a)?a.offset:null),x=(0,r.useRef)(Oc(a,t)),v=(0,r.useRef)(a.group),y=(0,r.useCallback)(e=>async function(e){return Uc(),(await(0,tl.default)({path:(0,al.F)("/mailpoet/v1/dynamic-segments",Tc(e)),method:"GET",signal:void 0})).data}({...e,group:i}),[i]),{view:w,setView:j,items:S,meta:N,groups:C,isLoading:E,error:I,onChangeView:A,clearError:U,refresh:T}=(0,$e.i7)({initialView:Oc(a,t),load:y,extraParams:e=>{const t=(0,$e.Y4)(function(e){const t={};return(e??[]).forEach(e=>{"created_at"===e.field?Object.assign(t,jc("created_from","created_to",e.operator,e.value)):"updated_at"===e.field&&Object.assign(t,jc("updated_from","updated_to",e.operator,e.value))}),t}(e.filters));return null!==b.current&&Mc(e,{...a,offset:b.current})?{page:void 0,per_page:void 0,offset:b.current,limit:e.perPage??a.limit,sort_by:e.sort?.field??"updated_at",sort_order:e.sort?.direction??"desc",...t}:t}});(0,r.useEffect)(()=>{x.current=w,v.current=i},[i,w]),(0,r.useEffect)(()=>{null!==b.current&&Mc(w,{...a,offset:b.current})||function(e,t={}){const a={...Nc,...t},i=Object.entries({...Cc(window.location.hash),...e}).filter(([e,t])=>t!==a[e]).sort(([e],[t])=>e.localeCompare(t)).reduce((e,[t,a])=>a?`${e}/${t}[${a}]`:e,"");window.location.hash=`/segments${i}`}({group:i,limit:w.perPage??25,offset:((w.page??1)-1)*(w.perPage??25),search:w.search??"",sort_by:w.sort?.field??"updated_at",sort_order:w.sort?.direction??"desc"},e())},[e,i,a,w]),(0,r.useEffect)(()=>{const t=()=>{const t=Ec(window.location.hash,e()),a=t.group;b.current=Lc(t)?t.offset:null,a!==v.current&&s(a),Mc(x.current,t)||j(e=>Mc(e,t)?e:Oc(t,e)),o([]),c(null),h(null),U()};return window.addEventListener("hashchange",t),()=>window.removeEventListener("hashchange",t)},[U,e,j]);const P=(0,r.useCallback)(e=>{b.current=null,A(e)},[A]),R=(0,$e.wh)("dynamic-segments",w,P),D=(0,r.useCallback)(async(e,t)=>{if(0!==t.length)try{const a=await async function(e,t){return Uc(),(await(0,tl.default)({path:"/mailpoet/v1/dynamic-segments/bulk-action",method:"POST",data:{action:e,ids:t}})).data}(e,t.map(e=>Number(e.id))),i=function(e,t){return"delete"===e?t.deleted:t.updated}(e,a);o([]),c(a.errors.length?a.errors.map(e=>e.message).join("\n"):null),h(i>0?function(e,t){return"trash"===e?(0,p.sprintf)((0,p._n)("Segment moved to trash.","%d segments moved to trash.",t,"mailpoet"),t):"restore"===e?(0,p.sprintf)((0,p._n)("Segment restored.","%d segments restored.",t,"mailpoet"),t):(0,p.sprintf)((0,p._n)("Segment permanently deleted.","%d segments permanently deleted.",t,"mailpoet"),t)}(e,i):null),T()}catch(e){const t=e;h(null),c(t?.message||(0,p.__)("The bulk action could not be completed.","mailpoet"))}},[T]),F=(0,r.useCallback)(async e=>{try{const t=(await m.U.Ajax.post({api_version:"v1",endpoint:"dynamic_segments",action:"duplicate",data:{id:e.id}})).data;m.U.Notice.success((0,p.sprintf)((0,p.__)('Segment "%s" has been duplicated.',"mailpoet"),(0,Me.Zn)(t.name))),T()}catch(e){(0,Dc.C)(e)&&m.U.Notice.showApiErrorNotice(e)}},[T]),O=(0,r.useMemo)(()=>[{id:"view_subscribers",label:(0,p.__)("View subscribers","mailpoet"),supportsBulk:!1,callback:e=>{const t=e[0];t&&(window.location.href=t.subscribers_url)}},{id:"edit",label:(0,p.__)("Edit","mailpoet"),isPrimary:!0,supportsBulk:!1,isEligible:e=>!e.deleted_at&&!e.is_plugin_missing,callback:e=>{const t=e[0];t&&(window.location.hash=`${Ic.r$}/${t.id}`)}},{id:"edit_missing_plugin",label:(0,p.__)("Edit unavailable","mailpoet"),disabled:!0,supportsBulk:!1,isEligible:e=>!e.deleted_at&&e.is_plugin_missing,callback:()=>{}},{id:"duplicate",label:(0,p.__)("Duplicate","mailpoet"),supportsBulk:!1,isEligible:e=>!e.deleted_at,callback:e=>{e[0]&&F(e[0])}},{id:"trash",label:(0,p.__)("Move to trash","mailpoet"),supportsBulk:!0,isEligible:e=>!e.deleted_at,callback:e=>{f({action:"trash",selected:e})}},{id:"restore",label:(0,p.__)("Restore","mailpoet"),supportsBulk:!0,isEligible:e=>!!e.deleted_at,callback:e=>{f({action:"restore",selected:e})}},{id:"delete",label:(0,p.__)("Delete permanently","mailpoet"),supportsBulk:!0,isDestructive:!0,isEligible:e=>!!e.deleted_at,callback:e=>{f({action:"delete",selected:e})}}],[F]),M=(0,r.useMemo)(()=>({totalItems:N.count,totalPages:N.pages}),[N]),L=(0,r.useMemo)(()=>{const e={all:null,trash:null};(C??[]).forEach(t=>{"all"!==t.name&&"trash"!==t.name||(e[t.name]=t.count)});const t=(e,t)=>null===t?e:`${e} (${t})`;return[{name:"all",title:t((0,p.__)("All","mailpoet"),e.all),className:"mailpoet-dataviews-group-all mailpoet-tab-all"},{name:"trash",title:t((0,p.__)("Trash","mailpoet"),e.trash),className:"mailpoet-dataviews-group-trash mailpoet-tab-trash"}]},[C]),$=function(e){if(!e)return{title:"",message:"",confirmText:""};const{action:t,selected:a}=e,i=a.map(({name:e})=>`"${e}"`).join(", ");return"trash"===t?{title:(0,p._n)("Trash selected segment","Trash selected segments",a.length,"mailpoet"),message:(0,p.sprintf)((0,p._n)("Are you sure you want to trash the selected segment %s?","Are you sure you want to trash the selected segments %s?",a.length,"mailpoet"),i),confirmText:(0,p.__)("Trash","mailpoet")}:"restore"===t?{title:(0,p._n)("Restore selected segment","Restore selected segments",a.length,"mailpoet"),message:(0,p.sprintf)((0,p._n)("Are you sure you want to restore the selected segment %s?","Are you sure you want to restore segments %s?",a.length,"mailpoet"),i),confirmText:(0,p.__)("Restore","mailpoet")}:{title:(0,p._n)("Delete selected segment permanently","Delete selected segments permanently",a.length,"mailpoet"),message:(0,g.jsxs)(g.Fragment,{children:[(0,p.sprintf)((0,p._n)("Are you sure you want to delete the selected segment %s permanently?","Are you sure you want to delete the selected segments %s permanently?",a.length,"mailpoet"),i)," ",(0,g.jsx)("strong",{children:(0,p.__)("This action can not be reversed.","mailpoet")})]}),confirmText:(0,p.__)("Delete permanently","mailpoet")}}(_);return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(d.x,{hideScreenOptions:!0}),(0,g.jsx)(kc,{}),(0,g.jsx)(qe.z,{heading:(0,p.__)("Segments","mailpoet"),children:(0,g.jsx)("a",{href:`#${Ic.WA}`,"data-automation-id":"new-segment",className:"page-title-action",children:(0,p.__)("Add new segment","mailpoet")})}),(0,g.jsxs)("div",{className:"mailpoet-segment-subscriber-count",children:[(0,g.jsx)(He,{subscribersInPlan:m.U.subscribersCount,subscribersInPlanLimit:m.U.subscribersLimit}),(0,g.jsx)(Ye,{cacheCalculation:window.mailpoet_subscribers_counts_cache_created_at})]}),(0,g.jsx)(k.D,{}),I&&(0,g.jsx)(Fe.A,{status:"error",onRemove:U,children:I}),l&&(0,g.jsx)(Fe.A,{status:"error",onRemove:()=>c(null),children:l}),u&&(0,g.jsx)(Fe.A,{status:"success",onRemove:()=>h(null),children:u}),(0,g.jsx)(Qo.A,{className:"mailpoet-segments-dataviews__tabs",activeClass:"is-active",tabs:L,initialTabName:i,onSelect:e=>{"all"!==e&&"trash"!==e||e!==i&&(b.current=null,s(e),o([]),c(null),h(null),U(),j({...w,page:1}))},children:()=>(0,g.jsx)("div",{className:"mailpoet-dataviews mailpoet-segments-dataviews mailpoet-segments-listing","data-automation-id":"dynamic_segments_listing",children:(0,g.jsxs)(Le.A,{data:S,fields:Rc,view:w,onChangeView:R,actions:O,paginationInfo:M,defaultLayouts:{table:{}},getItemId:e=>String(e.id),selection:n,onChangeSelection:o,isLoading:E,empty:(0,g.jsx)("div",{children:(0,p.__)("No data to display","mailpoet")}),children:[(0,g.jsxs)("div",{className:"mailpoet-segments-dataviews__toolbar",children:[(0,g.jsx)(Le.A.Search,{label:(0,p.__)("Search","mailpoet")}),(0,g.jsx)(Le.A.FiltersToggle,{}),(0,g.jsx)("div",{className:"mailpoet-dataviews__toolbar-end",children:(0,g.jsx)(Le.A.ViewConfig,{})})]}),(0,g.jsx)(Le.A.Filters,{}),(0,g.jsx)(Le.A.Layout,{}),(0,g.jsx)(Le.A.Footer,{})]})})},i),(0,g.jsx)(Xo.A,{className:"mailpoet-confirm-dialog",isOpen:!!_,title:$.title,confirmButtonText:$.confirmText,__experimentalHideHeader:!1,onConfirm:()=>{_&&D(_.action,_.selected),f(null)},onCancel:()=>f(null),children:(0,g.jsx)("p",{children:$.message})})]})});function Jc(){return(0,g.jsx)(l.F.Provider,{value:(0,l.f)(window),children:(0,g.jsxs)(Ae.HashRouter,{children:[(0,g.jsx)(Gc,{}),(0,g.jsx)(c.D,{}),(0,g.jsx)(u.q,{}),(0,g.jsxs)(Ue.BV,{children:[(0,g.jsx)(Ue.qh,{path:Ic.LX,element:(0,g.jsx)(Yc,{})}),(0,g.jsx)(Ue.qh,{path:`${Ic.r$}/:id`,element:(0,g.jsx)(Yc,{})}),(0,g.jsx)(Ue.qh,{path:Ic.WA,element:(0,g.jsx)(Kc,{})}),(0,g.jsx)(Ue.qh,{path:"*",element:(0,g.jsx)(Zc,{})})]})]})})}Hc&&((0,o.registerTranslations)(),(0,Al.y$)(),(0,n.H)(Hc).render((0,g.jsx)(Jc,{})));const Qc=()=>{m.U.trackEvent("Forms > Add New"),setTimeout(()=>{window.location.href=window.mailpoet_form_template_selection_url},200)};function Xc(){const[e,t]=(0,r.useState)(!1);return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(Ke,{}),(0,g.jsx)(d.x,{}),(0,g.jsx)(qe.z,{heading:(0,p.__)("Forms","mailpoet"),children:(0,g.jsx)("button",{onClick:()=>{t(!0),Qc()},"data-automation-id":"create_new_form",className:"page-title-action "+(e?"mailpoet-button-with-spinner":""),type:"button",children:(0,p.__)("Add new form","mailpoet")})})]})}function em({form:e}){const[t,a]=(0,r.useState)("enabled"===e.status),[i,s]=(0,r.useState)(!1);return(0,g.jsxs)("div",{children:[(0,g.jsx)(rs.l,{onCheck:(i,n)=>{n.persist();const r=t;a(i),s(!0),m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"forms",action:"setStatus",data:{id:Number(e.id),status:i?"enabled":"disabled"}}).done(e=>{"enabled"===e.data.status&&m.U.Notice.success((0,p.__)("Your Form is now activated!","mailpoet"))}).fail(e=>{m.U.Notice.showApiErrorNotice(e),a(r)}).always(()=>s(!1))},"data-id":e.id,dimension:"small",checked:t,disabled:i}),(0,g.jsxs)("p",{children:[(0,p.__)("Sign-ups","mailpoet"),": ",e.signups.toLocaleString()]})]})}function tm(e){if(!e)return(0,r.createElement)("span",null,"—");const t=m.U.Date.short(e),a=m.U.Date.time(e);return(0,r.createElement)("span",null,(0,r.createElement)("span",null,t),(0,r.createElement)("br",null),(0,r.createElement)("span",null,a))}Xc.displayName="FormsHeading",em.displayName="FormStatusToggle";const am=[{id:"name",label:(0,p.__)("Name","mailpoet"),type:"text",enableSorting:!0,enableGlobalSearch:!1,filterBy:!1,render:({item:e})=>(0,r.createElement)("a",{className:"mailpoet-listing-title",href:`admin.php?page=mailpoet-form-editor&id=${e.id}`},e.name?e.name:`(${(0,p.__)("no name","mailpoet")})`)},{id:"segments",label:(0,p.__)("Lists","mailpoet"),enableSorting:!1,enableGlobalSearch:!1,render:({item:e})=>{const t=new Set(e.segments.map(e=>String(e))),a=window.mailpoet_segments.filter(e=>t.has(String(e.id)));return(0,r.createElement)(er.vC,{segments:a,dimension:"large"},"user"===e.settings?.segments_selected_by?(0,r.createElement)("span",{className:"mailpoet-tags-prefix"},(0,p.__)("User choice:","mailpoet")):null)}},{id:"type",label:(0,p.__)("Type","mailpoet"),enableSorting:!1,enableGlobalSearch:!1,render:({item:e})=>(0,r.createElement)("span",null,function(e){const t=[],a=e?.form_placement;return"1"===a?.fixed_bar?.enabled&&t.push((0,p.__)("Fixed bar","mailpoet")),"1"===a?.below_posts?.enabled&&t.push((0,p.__)("Below pages","mailpoet")),"1"===a?.popup?.enabled&&t.push((0,p.__)("Pop-up","mailpoet")),"1"===a?.slide_in?.enabled&&t.push((0,p.__)("Slide–in","mailpoet")),t.length>0?t.join(", "):(0,p.__)("Others (widget)","mailpoet")}(e.settings))},{id:"status",label:(0,p.__)("Status","mailpoet"),enableSorting:!1,enableGlobalSearch:!1,elements:[{value:"enabled",label:(0,p.__)("Enabled","mailpoet")},{value:"disabled",label:(0,p.__)("Disabled","mailpoet")}],filterBy:{operators:["isAny"]},render:({item:e})=>(0,r.createElement)(em,{form:e})},{id:"created_at",label:(0,p.__)("Created date","mailpoet"),type:"date",enableSorting:!0,enableGlobalSearch:!1,filterBy:{operators:["on","beforeInc","afterInc","between"]},render:({item:e})=>tm(e.created_at)},{id:"updated_at",label:(0,p.__)("Modified date","mailpoet"),type:"date",enableSorting:!0,enableGlobalSearch:!1,filterBy:{operators:["on","beforeInc","afterInc","between"]},render:({item:e})=>tm(e.updated_at)}];function im(e,t,a,i){const{from:s,to:n}=(0,$e._O)(a,i);return{...s?{[e]:s}:{},...n?{[t]:n}:{}}}let sm=!1;function nm(){if(sm)return;const e=window.mailpoet_forms_api;tl.default.use(tl.default.createRootURLMiddleware(`${e.root}/`)),tl.default.use(tl.default.createNonceMiddleware(e.nonce)),sm=!0}const rm={type:"table",perPage:20,page:1,sort:{field:"updated_at",direction:"desc"},fields:["segments","type","status","created_at","updated_at"],titleField:"name",showTitle:!0};function om(){const[e,t]=(0,r.useState)("all"),[a,i]=(0,r.useState)([]),[s,n]=(0,r.useState)(null),[l,d]=(0,r.useState)(null),[c]=(0,r.useState)(()=>(0,$e.Aq)("forms",rm,am)),u=(0,r.useCallback)(t=>async function(e){return nm(),(await(0,tl.default)({path:(0,al.F)("/mailpoet/v1/forms",e),method:"GET"})).data}({...t,group:e}),[e]),{view:h,setView:_,items:f,meta:b,groups:x,isLoading:v,error:y,onChangeView:w,clearError:j,refresh:S}=(0,$e.i7)({initialView:c,load:u,extraParams:e=>(0,$e.Y4)(function(e){const t={};return(e??[]).forEach(e=>{if("status"===e.field){const i=(a=e.value,(Array.isArray(a)?a:[a]).map(e=>String(e)).filter(e=>"enabled"===e||"disabled"===e));i.length>0&&(t.status=i)}else"created_at"===e.field?Object.assign(t,im("created_from","created_to",e.operator,e.value)):"updated_at"===e.field&&Object.assign(t,im("updated_from","updated_to",e.operator,e.value));var a}),t}(e.filters))}),k=(0,$e.wh)("forms",h,w),N=(0,r.useRef)(new Set);(0,r.useEffect)(()=>{f.forEach(e=>{null===e.settings&&(N.current.has(e.id)||(N.current.add(e.id),m.U.Notice.error((0,p.__)('Form settings of "%1$s" form are corrupted. Please [link]reconfigure the form in the editor[/link].',"mailpoet").replace("%1$s",(0,Me.Zn)(e.name)).replace("[link]",`<a class="mailpoet-link" href="admin.php?page=mailpoet-form-editor&id=${parseInt(e.id,10)}">`).replace("[/link]","</a>"))))})},[f]);const C=(0,r.useCallback)(async(e,t)=>{const a=t.map(e=>Number(e.id));if(0!==a.length){if("delete"===e){const e=1===a.length?(0,p.__)("Delete this form permanently?","mailpoet"):(0,p.sprintf)((0,p._n)("Delete %d form permanently?","Delete %d forms permanently?",a.length,"mailpoet"),a.length);if(!window.confirm(e))return}try{const t=await async function(e,t){return nm(),(await(0,tl.default)({path:"/mailpoet/v1/forms/bulk-action",method:"POST",data:{action:e,ids:t}})).data.count}(e,a);i([]),d(function(e,t){return"trash"===e?1===t?(0,p.__)("1 form was moved to the trash.","mailpoet"):(0,p.sprintf)((0,p._n)("%d form was moved to the trash.","%d forms were moved to the trash.",t,"mailpoet"),t):"restore"===e?1===t?(0,p.__)("1 form has been restored from the trash.","mailpoet"):(0,p.sprintf)((0,p._n)("%d form has been restored from the trash.","%d forms have been restored from the trash.",t,"mailpoet"),t):1===t?(0,p.__)("1 form was permanently deleted.","mailpoet"):(0,p.sprintf)((0,p._n)("%d form was permanently deleted.","%d forms were permanently deleted.",t,"mailpoet"),t)}(e,t)),S()}catch(e){const t=e;n(t?.message||(0,p.__)("The bulk action could not be completed.","mailpoet"))}}},[S]),E=(0,r.useCallback)(e=>{m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"forms",action:"duplicate",data:{id:Number(e.id)}}).done(e=>{const t=e.data.name?e.data.name:(0,p.__)("no name","mailpoet");m.U.Notice.success((0,p.__)('Form "%1$s" has been duplicated.',"mailpoet").replace("%1$s",(0,Me.Zn)(t))),S()}).fail(e=>{e.errors&&e.errors.length>0&&m.U.Notice.showApiErrorNotice(e,{scroll:!0})})},[S]),I=(0,r.useMemo)(()=>[{id:"edit",label:(0,p.__)("Edit","mailpoet"),icon:"edit",isPrimary:!0,supportsBulk:!1,isEligible:e=>!e.deleted_at,callback:e=>{const t=e[0];t&&(window.location.href=`admin.php?page=mailpoet-form-editor&id=${t.id}`)}},{id:"duplicate",label:(0,p.__)("Duplicate","mailpoet"),supportsBulk:!1,isEligible:e=>!e.deleted_at,callback:e=>{e[0]&&E(e[0])}},{id:"trash",label:(0,p.__)("Move to trash","mailpoet"),supportsBulk:!0,isEligible:e=>!e.deleted_at,callback:e=>{C("trash",e)}},{id:"restore",label:(0,p.__)("Restore","mailpoet"),supportsBulk:!0,isEligible:e=>!!e.deleted_at,callback:e=>{C("restore",e)}},{id:"delete",label:(0,p.__)("Delete permanently","mailpoet"),supportsBulk:!0,isDestructive:!0,isEligible:e=>!!e.deleted_at,callback:e=>{C("delete",e)}}],[C,E]),A=(0,r.useMemo)(()=>({totalItems:b.count,totalPages:b.pages}),[b]),U=(0,r.useMemo)(()=>{const e={all:null,trash:null};(x??[]).forEach(t=>{"all"!==t.name&&"trash"!==t.name||(e[t.name]=t.count)});const t=(e,t)=>null===t?e:`${e} (${t})`;return[{name:"all",title:t((0,p.__)("All","mailpoet"),e.all),className:"mailpoet-dataviews-group-all"},{name:"trash",title:t((0,p.__)("Trash","mailpoet"),e.trash),className:"mailpoet-dataviews-group-trash"}]},[x]),T="trash"===e?(0,p.__)("Trash is empty.","mailpoet"):(0,p.__)("No forms were found. Why not create a new one?","mailpoet");return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(Xc,{}),y&&(0,g.jsx)(Fe.A,{status:"error",onRemove:j,children:y}),s&&(0,g.jsx)(Fe.A,{status:"error",onRemove:()=>n(null),children:s}),l&&(0,g.jsx)(Fe.A,{status:"success",onRemove:()=>d(null),children:l}),(0,g.jsx)(Qo.A,{className:"mailpoet-forms-dataviews__tabs",activeClass:"is-active",tabs:U,initialTabName:e,onSelect:a=>{"all"!==a&&"trash"!==a||a!==e&&(t(a),i([]),n(null),d(null),j(),_({...h,page:1}))},children:()=>(0,g.jsx)("div",{className:"mailpoet-dataviews mailpoet-forms-dataviews","data-automation-id":"forms_listing",children:(0,g.jsxs)(Le.A,{data:f,fields:am,view:h,onChangeView:k,actions:I,paginationInfo:A,defaultLayouts:{table:{}},getItemId:e=>String(e.id),selection:a,onChangeSelection:i,isLoading:v,empty:"trash"===e?(0,g.jsx)("div",{children:T}):(0,g.jsxs)("div",{className:"mailpoet-forms-add-new-row",children:[(0,g.jsx)("p",{children:T}),(0,g.jsx)(o.Button,{onClick:Qc,automationId:"add_new_form",children:(0,p.__)("Add new form","mailpoet")})]}),children:[(0,g.jsxs)("div",{className:"mailpoet-forms-dataviews__toolbar",children:[(0,g.jsx)(Le.A.Search,{label:(0,p.__)("Search forms","mailpoet")}),(0,g.jsx)(Le.A.FiltersToggle,{}),(0,g.jsx)("div",{className:"mailpoet-dataviews__toolbar-end",children:(0,g.jsx)(Le.A.ViewConfig,{})})]}),(0,g.jsx)(Le.A.Filters,{}),(0,g.jsx)(Le.A.Layout,{}),(0,g.jsx)(Le.A.Footer,{})]})})})]})}om.displayName="FormList";const lm=bo(om);function dm(){return(0,g.jsx)(lm,{})}function cm(){return(0,g.jsx)(l.F.Provider,{value:(0,l.f)(window),children:(0,g.jsxs)(Ae.HashRouter,{children:[(0,g.jsx)(c.D,{}),(0,g.jsx)(u.q,{}),(0,g.jsx)(k.D,{}),(0,g.jsx)(Ue.BV,{children:(0,g.jsx)(Ue.qh,{path:"*",element:(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(dm,{})})})})]})})}const mm=document.getElementById("forms_container");function um(){return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("p",{children:m.U.I18n.t("knowledgeBaseIntro")}),(0,g.jsxs)("ul",{className:"mailpoet-text-links",children:[(0,g.jsx)("li",{children:(0,g.jsx)("a",{target:"_blank",rel:"noreferrer noopener",href:"https://kb.mailpoet.com/category/116-common-problems",children:"Common Problems"})}),(0,g.jsx)("li",{children:(0,g.jsx)("a",{target:"_blank",rel:"noreferrer noopener",href:"https://kb.mailpoet.com/category/165-guides-tips",children:"Newsletters"})}),(0,g.jsx)("li",{children:(0,g.jsx)("a",{target:"_blank",rel:"noreferrer noopener",href:"https://kb.mailpoet.com/category/156-migration-questions",children:"Migration Questions"})}),(0,g.jsx)("li",{children:(0,g.jsx)("a",{target:"_blank",rel:"noreferrer noopener",href:"https://kb.mailpoet.com/category/149-other-sending-methods",children:"Sending Methods"})}),(0,g.jsx)("li",{children:(0,g.jsx)("a",{target:"_blank",rel:"noreferrer noopener",href:"https://kb.mailpoet.com/category/139-subscription-forms",children:"Subscription Forms"})}),(0,g.jsx)("li",{children:(0,g.jsx)("a",{target:"_blank",rel:"noreferrer noopener",href:"https://kb.mailpoet.com/category/114-getting-started",children:"Getting Started"})}),(0,g.jsx)("li",{children:(0,g.jsx)("a",{target:"_blank",rel:"noreferrer noopener",href:"https://kb.mailpoet.com/category/123-newsletter-editor-designer",children:"Newsletter Designer"})}),(0,g.jsx)("li",{children:(0,g.jsx)("a",{target:"_blank",rel:"noreferrer noopener",href:"https://kb.mailpoet.com/category/121-subscribers-and-lists",children:"Subscribers and Lists"})})]}),(0,g.jsx)(Ge.$,{target:"_blank",rel:"noreferrer noopener",href:"https://kb.mailpoet.com/",children:m.U.I18n.t("knowledgeBaseButton")})]})}mm&&((0,o.registerTranslations)(),(0,n.H)(mm).render((0,g.jsx)(cm,{})));var pm=a(71527);function hm(e){e.target.select()}function gm(e,t){if(Lt.default.isObject(e)){const a=Object.keys(e).map(t=>`${t}: ${e[t]}`);return(0,g.jsx)("textarea",{readOnly:!0,id:t,onFocus:hm,value:a.join("\n"),style:{width:"100%",height:"400px"}})}return(0,g.jsx)("p",{children:m.U.I18n.t("systemInfoDataError")})}function _m(){const e="mailpoet-system-info",t=window.systemInfoData;return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("div",{className:"mailpoet_notice notice inline",children:(0,g.jsx)("p",{children:m.U.I18n.t("systemInfoIntro")})}),gm(t,e),(0,g.jsx)(pm.T,{variant:"secondary",targetId:e})]})}function fm({rows:e,max_width:t="auto",is_fixed:a=!0}){return(0,g.jsx)("table",{className:v()("widefat",{fixed:a}),style:{maxWidth:t},children:(0,g.jsx)("tbody",{children:e.map(e=>(0,g.jsxs)("tr",{children:[(0,g.jsx)("td",{className:"row-title",children:e.key}),(0,g.jsx)("td",{children:e.value}),e.action?(0,g.jsx)("td",{children:e.action}):null]},`row_${e.key}`))})})}function bm({truthy:e=(0,p.__)("Yes","mailpoet"),falsy:t=(0,p.__)("No","mailpoet"),unknown:a=(0,p.__)("Unknown","mailpoet"),children:i=null}){return(0,g.jsx)("span",{children:!0===i&&e||!1===i&&t||a})}function xm(e){const t=e.status_data,a={active:m.U.I18n.t("running"),inactive:m.U.I18n.t("cronWaiting")},i=Array.isArray(t.last_error)?(0,g.jsx)(g.Fragment,{children:t.last_error.map(e=>(0,g.jsxs)("div",{children:[e.worker,": ",(0,g.jsx)("i",{children:e.message})]},e.worker))}):t.last_error;return(0,g.jsxs)("div",{children:[(0,g.jsx)("h4",{children:m.U.I18n.t("systemStatusCronStatusTitle")}),(0,g.jsx)(fm,{max_width:"400px",rows:[{key:m.U.I18n.t("accessible"),value:(0,g.jsx)(bm,{children:t.accessible})},{key:m.U.I18n.t("status"),value:a[t.status]?a[t.status]:m.U.I18n.t("unknown")},{key:m.U.I18n.t("lastUpdated"),value:t.updated_at?m.U.Date.full(1e3*t.updated_at):m.U.I18n.t("unknown")},{key:m.U.I18n.t("lastRunStarted"),value:t.run_started_at?m.U.Date.full(1e3*t.run_started_at):m.U.I18n.t("unknown")},{key:m.U.I18n.t("lastRunCompleted"),value:t.run_completed_at?m.U.Date.full(1e3*t.run_completed_at):m.U.I18n.t("unknown")},{key:m.U.I18n.t("lastSeenError"),value:i||m.U.I18n.t("none")},{key:m.U.I18n.t("lastSeenErrorDate"),value:t.last_error_date?m.U.Date.full(1e3*t.last_error_date):m.U.I18n.t("unknown")}]})]})}function vm({task:e,type:t}){const[a,i]=(0,r.useState)(!1),[s,n]=(0,r.useState)(null),o="cancel"===t,l="reschedule"===t,d=e.scheduledAt,c=m.U.Date.isInPast(d,new Date);return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(Xo.A,{className:"mailpoet-help-modal",isOpen:a,title:o?(0,p.__)("Cancel task","mailpoet"):(0,p.__)("Reschedule task","mailpoet"),cancelButtonText:(0,p.__)("Not now","mailpoet"),confirmButtonText:o?(0,p.__)("Yes, cancel task","mailpoet"):(0,p.__)("Yes, reschedule task","mailpoet"),onConfirm:async()=>{await m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"help",action:o?"cancelTask":"rescheduleTask",data:{id:e.id}}).done(()=>{n(null),i(!1),window.location.reload()}).catch(e=>{n(e.errors.map(e=>e.message).join(" "))})},onCancel:()=>i(!1),__experimentalHideHeader:!1,children:[s&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(Fe.A,{status:"error",isDismissible:!1,children:s}),(0,g.jsx)("br",{})]}),o&&(0,p.sprintf)((0,p.__)('Are you sure you want to cancel the task with ID %1$s for the email "%2$s"? Once cancelled, the email will not be sent.',"mailpoet"),e.id.toString(),e.newsletter.subject||(0,p.__)("(no subject)","mailpoet")),l&&(0,p.sprintf)((0,p.__)('Are you sure you want to reschedule the task with ID %1$s for the email "%2$s"?',"mailpoet"),e.id.toString(),e.newsletter.subject||(0,p.__)("(no subject)","mailpoet"))," ",l&&c&&(0,p.__)("The email will be sent immediately.","mailpoet"),l&&!c&&(0,p.sprintf)((0,p.__)("The task will be scheduled for sending on %s.","mailpoet"),`${m.U.Date.short(d)} ${m.U.Date.time(d)}`)]}),(0,g.jsx)(ge.Ay,{variant:"secondary",size:"small",isDestructive:o,onClick:()=>i(!0),children:o?(0,p.__)("Cancel task","mailpoet"):(0,p.__)("Reschedule task","mailpoet")})]})}function ym({task:e}){return(0,g.jsx)(vm,{task:e,type:"cancel"})}function wm({task:e}){return(0,g.jsx)(vm,{task:e,type:"reschedule"})}function jm({type:e,task:t}){const a="scheduled"===e,i="cancelled"===e,s="scheduled"===e||"running"===e,n="cancelled"===e;return(0,g.jsxs)("tr",{children:[(0,g.jsx)("td",{className:"column column-primary",children:t.id}),(0,g.jsx)("td",{className:"column",children:t.newsletter?(0,g.jsx)("a",{href:t.newsletter.previewUrl,"data-newsletter-id":t.newsletter.newsletterId,"data-queue-id":t.newsletter.queueId,target:"_blank",rel:"noopener noreferrer",children:t.newsletter.subject||m.U.I18n.t("preview")}):m.U.I18n.t("none")}),(0,g.jsx)("td",{className:"column",children:t.subscriberEmail?(0,g.jsx)("a",{href:`admin.php?page=mailpoet-subscribers#/search[${t.subscriberEmail}]`,children:t.subscriberEmail}):(0,g.jsx)("i",{children:m.U.I18n.t("multipleSubscribers")})}),(0,g.jsx)("td",{className:"column",children:t.priority}),a?(0,g.jsx)("td",{className:"column-date",children:(0,g.jsx)("abbr",{children:`${m.U.Date.short(t.scheduledAt)} ${m.U.Date.time(t.scheduledAt)}`})}):null,i?(0,g.jsx)("td",{className:"column-date",children:(0,g.jsx)("abbr",{children:`${m.U.Date.short(t.cancelledAt)} ${m.U.Date.time(t.cancelledAt)}`})}):null,(0,g.jsx)("td",{className:"column-date",children:(0,g.jsx)("abbr",{children:`${m.U.Date.short(t.updatedAt)} ${m.U.Date.time(t.updatedAt)}`})}),s?(0,g.jsx)("td",{children:(0,g.jsx)(ym,{task:t})}):null,n?(0,g.jsx)("td",{children:(0,g.jsx)(wm,{task:t})}):null]})}function Sm({type:e}){const t=["scheduled","running","cancelled"].includes(e);return(0,g.jsxs)("tr",{children:[(0,g.jsx)("th",{className:"row-title",children:"Id"}),(0,g.jsx)("th",{className:"row-title",children:m.U.I18n.t("email")}),(0,g.jsx)("th",{className:"row-title",children:m.U.I18n.t("subscriber")}),(0,g.jsx)("th",{className:"row-title",children:m.U.I18n.t("priority")}),"scheduled"===e?(0,g.jsx)("th",{className:"row-title",children:m.U.I18n.t("scheduledAt")}):null,"cancelled"===e?(0,g.jsx)("th",{className:"row-title",children:m.U.I18n.t("cancelledAt")}):null,(0,g.jsx)("th",{className:"row-title",children:m.U.I18n.t("updatedAt")}),t?(0,g.jsx)("th",{className:"row-title",children:m.U.I18n.t("action")}):null]})}function km({tasks:e,type:t}){let a=5;return"running"===t&&(a+=1),"scheduled"!==t&&"cancelled"!==t||(a+=2),(0,g.jsxs)("table",{className:"widefat fixed striped",children:[(0,g.jsx)("thead",{children:(0,g.jsx)(Sm,{type:t})}),(0,g.jsx)("tbody",{children:e.length?e.map(e=>(0,g.jsx)(jm,{task:e,type:t},e.id)):(0,g.jsx)("tr",{className:"mailpoet-listing-no-items",children:(0,g.jsx)("td",{colSpan:a,children:m.U.I18n.t("nothingToShow")})})}),(0,g.jsx)("tfoot",{children:(0,g.jsx)(Sm,{type:t})})]})}function Nm({statusData:e}){const t=e;return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("h4",{children:m.U.I18n.t("systemStatusQueueTitle")}),(0,g.jsx)(fm,{max_width:"400px",rows:[{key:m.U.I18n.t("status"),value:"paused"===t.status?m.U.I18n.t("paused"):m.U.I18n.t("running")},{key:m.U.I18n.t("startedAt"),value:t.started?m.U.Date.full(1e3*t.started):m.U.I18n.t("unknown")},{key:m.U.I18n.t("sentEmails"),value:t.sent||0},{key:m.U.I18n.t("retryAttempt"),value:t.retryAttempt||m.U.I18n.t("none")},{key:m.U.I18n.t("retryAt"),value:t.retryAt?m.U.Date.full(1e3*t.retryAt):m.U.I18n.t("none")},{key:m.U.I18n.t("error"),value:t.error?t.error.errorMessage:m.U.I18n.t("none")},{key:m.U.I18n.t("totalCompletedTasks"),value:t.tasksStatusCounts.completed},{key:m.U.I18n.t("totalRunningTasks"),value:t.tasksStatusCounts.running},{key:m.U.I18n.t("totalPausedTasks"),value:t.tasksStatusCounts.paused},{key:m.U.I18n.t("totalCancelledTasks"),value:t.tasksStatusCounts.cancelled},{key:m.U.I18n.t("totalScheduledTasks"),value:t.tasksStatusCounts.scheduled}]}),(0,g.jsx)("h5",{children:m.U.I18n.t("scheduledTasks")}),(0,g.jsx)(km,{type:"scheduled",tasks:t.latestTasks.filter(e=>"scheduled"===e.status)}),(0,g.jsx)("h5",{children:m.U.I18n.t("cancelledTasks")}),(0,g.jsx)(km,{type:"cancelled",tasks:t.latestTasks.filter(e=>"cancelled"===e.status)}),(0,g.jsx)("h5",{children:m.U.I18n.t("runningTasks")}),(0,g.jsx)(km,{type:"running",tasks:t.latestTasks.filter(e=>null===e.status)}),(0,g.jsx)("h5",{children:m.U.I18n.t("pausedTasks")}),(0,g.jsx)(km,{type:"paused",tasks:t.latestTasks.filter(e=>"paused"===e.status)}),(0,g.jsx)("h5",{children:m.U.I18n.t("completedTasks")}),(0,g.jsx)(km,{type:"completed",tasks:t.latestTasks.filter(e=>"completed"===e.status)})]})}function Cm({version:e,storage:t,latestTrigger:a,latestCompletedTrigger:i,latestCompletedRun:s}){return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("h4",{children:m.U.I18n.t("actionSchedulerStatus")}),(0,g.jsx)(fm,{max_width:"400px",rows:[{key:m.U.I18n.t("version"),value:e},{key:m.U.I18n.t("storage"),value:t},{key:m.U.I18n.t("latestActionSchedulerTrigger"),value:m.U.Date.full(a)},{key:m.U.I18n.t("latestActionSchedulerCompletedTrigger"),value:m.U.Date.full(i)},{key:m.U.I18n.t("latestActionSchedulerCompletedRun"),value:m.U.Date.full(s)}]})]})}function Em(){const[e,t]=(0,r.useState)({total:0}),[a,i]=(0,r.useState)("");(0,r.useEffect)(()=>{m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"help",action:"getInconsistentDataStatus"}).done(e=>{t(e.data||null)}).catch(e=>{m.U.Notice.show({type:"error",message:e.errors.map(e=>e.message).join(" "),scroll:!0})})},[]);const s=(0,r.useMemo)(()=>({orphaned_sending_tasks:(0,p.__)("Orphaned Sending Tasks","mailpoet"),orphaned_sending_task_subscribers:(0,p.__)("Orphaned Sending Task Subscribers","mailpoet"),sending_queue_without_newsletter:(0,p.__)("Sending Queues without Newsletter","mailpoet"),orphaned_subscriptions:(0,p.__)("Orphaned Subscriptions","mailpoet"),orphaned_subscriber_custom_fields:(0,p.__)("Orphaned Subscriber Custom Fields","mailpoet"),orphaned_subscriber_tags:(0,p.__)("Orphaned Subscriber Tags","mailpoet"),orphaned_links:(0,p.__)("Orphaned Links","mailpoet"),orphaned_newsletter_posts:(0,p.__)("Orphaned Newsletter Posts","mailpoet")}),[]),n=(0,r.useCallback)(e=>{i(e),m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"help",action:"fixInconsistentData",data:{inconsistency:e}}).done(e=>{i(""),t(e.data||null),m.U.Notice.show({message:(0,p.__)("Inconsistency fixed!","mailpoet"),scroll:!0})}).catch(e=>{i(""),m.U.Notice.show({type:"error",message:e.errors.map(e=>e.message).join(" "),scroll:!0})})},[]);if(!e||0===e.total)return null;const o=Object.entries(e).filter(([e,t])=>"total"!==e&&t>0).map(([e,t])=>({key:s[e],value:t,action:(0,g.jsx)(ge.Ay,{variant:"primary",size:"small",label:(0,p.__)("Clean","mailpoet"),onClick:()=>n(e),isBusy:a===e,disabled:!!a,children:(0,p.__)("Fix","mailpoet")})}));return(0,g.jsxs)("div",{children:[(0,g.jsx)("h2",{children:(0,p.__)("Data Inconsistencies","mailpoet")}),(0,g.jsx)("p",{children:(0,p.__)('We found the following data inconsistencies in your DB. Click the "Fix" button to clean them.',"mailpoet")}),(0,g.jsx)(fm,{rows:o,max_width:"400px",is_fixed:!1})]})}function Im(e){return null==e||""===e?m.U.I18n.t("none"):"boolean"==typeof e?e?m.U.I18n.t("yes"):m.U.I18n.t("no"):Array.isArray(e)?0===e.length?m.U.I18n.t("none"):e.map(e=>e&&e.worker&&e.message?`${e.worker}: ${e.message}`:`${e}`).join("; "):"object"==typeof e?JSON.stringify(e):`${e}`}function Am(e){return e?m.U.Date.full(1e3*e):m.U.I18n.t("unknown")}function Um(e,t){e.push(""),e.push(`### ${t} ###`)}function Tm(e,t,a){e.push(` - ${t}: ${Im(a)}`)}function Pm(e){return null==e||""===e?m.U.I18n.t("none"):e}function Rm(e){if("boolean"==typeof e)return e?m.U.I18n.t("yes"):m.U.I18n.t("no");const t=`${e||""}`.trim().toLowerCase();return"yes"===t||"no"===t?m.U.I18n.t(t):Im(e)}function Dm(e,t){const a={};if(!e||"string"!=typeof e)return a;if(t&&t.length>0){const i=[...t].sort((e,t)=>t.length-e.length).map(e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")),s=new RegExp(`(?:^| - )(?<key>${i.join("|")}): `,"g"),n=[...e.matchAll(s)];return n.forEach((t,i)=>{const s=t.index+t[0].length,r=n[i+1]?n[i+1].index:e.length;a[t.groups.key]=e.slice(s,r).trim()}),a}return e.split(" - ").forEach(e=>{const t=e.indexOf(": ");-1!==t&&(a[e.slice(0,t).trim()]=e.slice(t+2).trim())}),a}function Fm(e,t,a,i,s){const n=e?"success":"error";let r=e?t:a;return i&&(r=b()(r,/\[link\](.*?)\[\/link\]/g,e=>(0,g.jsx)("a",{className:"mailpoet-text-link",href:i,children:e},"kb-link"))),(0,g.jsxs)("div",{className:`mailpoet_notice notice inline notice-${n}`,children:[(0,g.jsx)("p",{children:r}),s?(0,g.jsx)("p",{children:(0,g.jsx)("i",{children:s})}):null]})}function Om(e){const t=e.cron.isReachable,a=e.cron.url,i=`${m.U.I18n.t("systemStatusConnectionUnsuccessful")} ${m.U.I18n.t("systemStatusCronConnectionUnsuccessfulInfo")}`,s=m.U.I18n.t("systemStatusConnectionSuccessful"),n=t?null:e.cron.pingResponse;return(0,g.jsxs)("div",{children:[(0,g.jsx)("h4",{children:m.U.I18n.t("systemStatusCronTitle")}),(0,g.jsx)("p",{children:(0,g.jsx)("a",{className:"mailpoet-text-link",href:a,target:"_blank",rel:"noopener noreferrer",children:a})}),Fm(t,s,i,"https://kb.mailpoet.com/article/231-sending-does-not-work",n)]})}function Mm(e){const t=e.mss.enabled?`${m.U.I18n.t("systemStatusConnectionUnsuccessful")} ${m.U.I18n.t("systemStatusMSSConnectionUnsuccessfulInfo")}`:m.U.I18n.t("systemStatusMSSConnectionCanNotConnect"),a=e.mss.enabled?m.U.I18n.t("systemStatusConnectionSuccessful"):m.U.I18n.t("systemStatusMSSConnectionCanConnect");return(0,g.jsxs)("div",{children:[(0,g.jsx)("h4",{children:m.U.I18n.t("systemStatusMSSTitle")}),Fm(e.mss.isReachable,a,t,"https://kb.mailpoet.com/article/319-known-errors-when-validating-a-mailpoet-key",null)]})}function Lm(){const e="mailpoet-system-status-report",t=window.systemInfoData,a=window.systemStatusData,i=window.actionSchedulerData,[s,n]=(0,r.useState)(!1),[o,l]=(0,r.useState)(m.U.I18n.t("systemStatusCopyForSupport")),d=(0,r.useMemo)(()=>function(e,t,a){const i=[],s=t.queueStatus||{},n=e||{},r=Dm(n["WP info"],["WP_MEMORY_LIMIT","WP_MAX_MEMORY_LIMIT","WP_DEBUG","WordPress language","WordPress timezone"]),o=Dm(n["PHP info"],["PHP max_execution_time","PHP memory_limit","PHP upload_max_filesize","PHP post_max_size"]),l=Dm(n["MailPoet Sending Service"],["Is reachable","Ping response","API key state","Premium key state"]),d=Dm(n["MailPoet sending info"],["Send all site's emails with","Task Scheduler method","Default FROM address","Default Reply-To address","Bounce Email Address"]),c=Dm(n["Data inconsistency status"]),u=[l["API key state"],l["Premium key state"]?`premium: ${l["Premium key state"]}`:null].filter(Boolean).join("; "),p=u?`${n["MailPoet Premium/MSS key"]} (${u})`:n["MailPoet Premium/MSS key"],h=t.cronStatus||{},g=Array.isArray(h.last_error)?h.last_error.map(e=>`${e.worker}: ${e.message}`).join("; "):h.last_error,_=a?.version||m.U.I18n.t("none"),f=a?.storage||m.U.I18n.t("none"),b=a?.latestTrigger?m.U.Date.full(a.latestTrigger):m.U.I18n.t("unknown"),x=a?.latestCompletedTrigger?m.U.Date.full(a.latestCompletedTrigger):m.U.I18n.t("unknown"),v=a?.latestCompletedRun?m.U.Date.full(a.latestCompletedRun):m.U.I18n.t("unknown");let y=m.U.I18n.t("unknown");"paused"===s.status?y=m.U.I18n.t("paused"):void 0!==s.status&&(y=m.U.I18n.t("running"));const w=void 0!==s.retryAttempt&&null!==s.retryAttempt?s.retryAttempt:m.U.I18n.t("none"),j=s.retryAt?Am(s.retryAt):m.U.I18n.t("unknown"),S=s.error?.errorMessage||m.U.I18n.t("none"),k=s.tasksStatusCounts||{},N=Array.isArray(t.activePlugins)?t.activePlugins.map(e=>({name:`${e?.name||""}`.trim(),author:`${e?.author||""}`.trim(),version:`${e?.version||""}`.trim(),versionLatest:e?.versionLatest?`${e.versionLatest}`.trim():null})).filter(e=>e.name&&e.author&&e.version):[];return i.push("### MailPoet System Status Report ###"),i.push(`Generated: ${(new Date).toISOString()}`),Um(i,"Site & Account"),Tm(i,"Site name",n.name),Tm(i,"Email",n.email),Tm(i,"MailPoet Premium/MSS key",p),Tm(i,"Plugin installed at",n["Plugin installed at"]),Tm(i,"Installed via WooCommerce onboarding wizard",Rm(n["Installed via WooCommerce onboarding wizard"])),Tm(i,"Total subscribers",n["Total number of subscribers"]),Um(i,"Versions"),Tm(i,"MailPoet Free",n["MailPoet Free version"]),Tm(i,"MailPoet Premium",n["MailPoet Premium version"]),Tm(i,"WordPress",n["WordPress version"]),Tm(i,"PHP",n["PHP version"]),Tm(i,"Database",n["Database version"]),Tm(i,"Action Scheduler",_),Um(i,"Environment"),Tm(i,"Web server",n["Web server"]),Tm(i,"Server OS",n["Server OS"]),Tm(i,"Multisite",n["Multisite environment?"]),Tm(i,"Current theme",n["Current Theme"]),Tm(i,"WordPress language",r["WordPress language"]),Tm(i,"WordPress timezone",r["WordPress timezone"]),Um(i,"WordPress & PHP Config"),Tm(i,"WP_MEMORY_LIMIT",r.WP_MEMORY_LIMIT),Tm(i,"WP_MAX_MEMORY_LIMIT",r.WP_MAX_MEMORY_LIMIT),Tm(i,"WP_DEBUG",r.WP_DEBUG),Tm(i,"PHP max_execution_time",o["PHP max_execution_time"]),Tm(i,"PHP memory_limit",o["PHP memory_limit"]),Tm(i,"PHP upload_max_filesize",o["PHP upload_max_filesize"]),Tm(i,"PHP post_max_size",o["PHP post_max_size"]),Um(i,`Active Plugins (${N.length})`),function(e,t){const a=(t||[]).filter(Boolean);a.length?a.forEach(t=>{const a=t.versionLatest?` (update to version ${t.versionLatest} is available)`:"";e.push(` - ${t.name}: by ${t.author} - ${t.version}${a}`)}):e.push(` - ${m.U.I18n.t("none")}`)}(i,N),Um(i,"Sending Configuration"),Tm(i,"Sending method",n["Sending Method"]),Tm(i,"Send all site's emails with",d["Send all site's emails with"]),Tm(i,"Sending frequency",n["Sending Frequency"]),Tm(i,"Default FROM address",Pm(d["Default FROM address"])),Tm(i,"Default Reply-To address",Pm(d["Default Reply-To address"])),Tm(i,"Bounce email address",Pm(d["Bounce Email Address"])),Um(i,"Connection to MailPoet Sending Service"),Tm(i,"Enabled",Rm(t.mss?.enabled)),Tm(i,"Reachable",Rm(t.mss?.isReachable)),Tm(i,"Ping response",l["Ping response"]),Tm(i,"API key state",l["API key state"]),Tm(i,"Premium key state",l["Premium key state"]),Um(i,"Task Scheduler / Cron"),Tm(i,"Status",h.status||m.U.I18n.t("unknown")),Tm(i,"Task Scheduler method",d["Task Scheduler method"]),Tm(i,"Ping URL",t.cron?.url),Tm(i,"Accessible",Rm(h.accessible)),Tm(i,"Ping response",t.cron?.pingResponse),Tm(i,"Last updated",Am(h.updated_at)),Tm(i,"Last run started",Am(h.run_started_at)),Tm(i,"Last run completed",Am(h.run_completed_at)),Tm(i,"Last seen error",g||m.U.I18n.t("none")),Um(i,"Action Scheduler Status"),Tm(i,"Storage type",f),Tm(i,"Next trigger run",b),Tm(i,"Last trigger run",x),Tm(i,"Last worker run",v),Um(i,"Sending Queue"),Tm(i,"Status",y),Tm(i,"Started at",Am(s.started)),Tm(i,"Sent emails",s.sent||0),Tm(i,"Retry attempt",w),Tm(i,"Retry at",j),Tm(i,"Error",S),Tm(i,"Total completed tasks",k.completed||0),Tm(i,"Total running tasks",k.running||0),Tm(i,"Total paused tasks",k.paused||0),Tm(i,"Total cancelled tasks",k.cancelled||0),Tm(i,"Total scheduled tasks",k.scheduled||0),Um(i,"Data Inconsistency"),Tm(i,"Orphaned sending tasks",c["Orphaned sending tasks"]),Tm(i,"Orphaned sending task subscribers",c["Orphaned sending task subscribers"]),Tm(i,"Sending queue without newsletter",c["Sending queue without newsletter"]),Tm(i,"Orphaned subscriptions",c["Orphaned subscriptions"]),Tm(i,"Orphaned links",c["Orphaned links"]),Tm(i,"Orphaned newsletter posts",c["Orphaned newsletter posts"]),i.push(""),i.join("\n")}(t,a,i),[]);return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("div",{className:"mailpoet_notice notice inline",children:(0,g.jsx)("p",{children:a.mss.enabled?m.U.I18n.t("systemStatusIntroCronMSS"):m.U.I18n.t("systemStatusIntroCron")})}),(0,g.jsxs)("div",{className:"updated mailpoet-system-status-report inline",children:[(0,g.jsx)("p",{children:m.U.I18n.t("systemStatusGetReportIntro")}),(0,g.jsxs)("p",{className:"submit",children:[(0,g.jsx)("button",{type:"button",className:"button button-primary",onClick:()=>n(!0),children:m.U.I18n.t("systemStatusGetReportTitle")}),(0,g.jsx)("a",{className:"button button-secondary",href:"https://kb.mailpoet.com/article/understanding-the-mailpoet-system-status-page",target:"_blank",rel:"noopener noreferrer",children:m.U.I18n.t("systemStatusUnderstandingReport")})]}),s?(0,g.jsxs)("div",{className:"mailpoet-debug-report",children:[(0,g.jsx)("textarea",{readOnly:!0,id:e,value:d}),(0,g.jsxs)("p",{className:"submit",children:[(0,g.jsx)("button",{type:"button",className:"button button-primary",onClick:()=>function(e){const t=`mailpoet-system-status-${(new Date).toISOString().slice(0,10)}.txt`,a=new Blob([e],{type:"text/plain;charset=utf-8"}),i=window.URL.createObjectURL(a),s=document.createElement("a");s.href=i,s.download=t,document.body.appendChild(s),s.click(),document.body.removeChild(s),window.URL.revokeObjectURL(i)}(d),children:m.U.I18n.t("systemStatusDownloadReport")}),(0,g.jsx)("button",{type:"button",className:"button",onClick:async()=>{try{await(0,br.l)(e,e=>{e?(l(m.U.I18n.t("copyToClipboardSuccess")),window.setTimeout(()=>{l(m.U.I18n.t("systemStatusCopyForSupport"))},3e3)):l(m.U.I18n.t("copyToClipboardFailure"))},!0)}catch{l(m.U.I18n.t("copyToClipboardFailure"))}},children:o})]})]}):null]}),Om(a),Mm(a),(0,g.jsx)(xm,{status_data:a.cronStatus}),(0,g.jsx)(Cm,{...i}),i?(0,g.jsx)(Nm,{statusData:a.queueStatus}):null,(0,g.jsx)(Em,{})]})}function $m(){return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("p",{children:m.U.I18n.t("yourPrivacyContent1")}),(0,g.jsx)("p",{children:m.U.I18n.t("yourPrivacyContent2")}),(0,g.jsx)("p",{children:m.U.I18n.t("yourPrivacyContent3")}),(0,g.jsx)(Ge.$,{target:"_blank",rel:"noreferrer noopener",href:"https://www.mailpoet.com/privacy-notice/",children:m.U.I18n.t("yourPrivacyButton")})]})}bm.propTypes={truthy:Rt().string,falsy:Rt().string,unknown:Rt().string,children:Rt().bool},xm.propTypes={status_data:Rt().shape({accessible:Rt().bool,last_error_date:Rt().string,status:Rt().string,updated_at:Rt().number,run_accessed_at:Rt().number,run_completed_at:Rt().number,run_started_at:Rt().number,last_error:Rt().oneOfType([Rt().string,Rt().array])}).isRequired};var Bm=a(34142);function Wm(){return(0,g.jsxs)(l.F.Provider,{value:(0,l.f)(window),children:[(0,g.jsx)(d.V,{}),(0,g.jsx)(c.D,{}),(0,g.jsx)(u.q,{}),(0,g.jsx)(Bm.z,{heading:(0,p.__)("Help","mailpoet")}),(0,g.jsx)(k.D,{}),(0,g.jsxs)(uo.k,{activeKey:"knowledgeBase",children:[(0,g.jsx)(o.Tab,{title:m.U.I18n.t("tabKnowledgeBaseTitle"),children:(0,g.jsx)(um,{})},"knowledgeBase"),(0,g.jsx)(o.Tab,{title:m.U.I18n.t("tabSystemStatusTitle"),children:(0,g.jsx)(Lm,{})},"systemStatus"),(0,g.jsx)(o.Tab,{title:m.U.I18n.t("tabSystemInfoTitle"),children:(0,g.jsx)(_m,{})},"systemInfo"),(0,g.jsx)(o.Tab,{title:m.U.I18n.t("tabYourPrivacyTitle"),children:(0,g.jsx)($m,{})},"yourPrivacy")]})]})}const Vm=document.getElementById("help_container");Vm&&((0,o.registerTranslations)(),(0,n.H)(Vm).render((0,g.jsx)(Wm,{})));var qm=a(48456);function zm({children:e}){const t=(0,Ue.zy)();return(0,r.useEffect)(()=>{window.scrollTo(0,0)},[t.pathname]),e||null}zm.propTypes={children:Rt().node.isRequired},zm.displayName="ScrollToTopComponent";const Hm=(0,qm.fk)(zm);var Gm=a(38818);function Ym({onMethodChange:e,activeMethod:t}){return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)("div",{className:"mailpoet-settings-label",children:[(0,g.jsx)("span",{className:"mailpoet_import_heading",children:m.U.I18n.t("methodSelectionHead")}),(0,g.jsx)("div",{className:"mailpoet-settings-inputs-row",children:(0,g.jsx)("a",{href:"https://kb.mailpoet.com/article/242-video-guide-importing-subscribers-using-a-csv-file",target:"_blank",rel:"noopener noreferrer",children:(0,g.jsx)(Gm.v,{dimension:"large",variant:"excellent",isInverted:!0,children:m.U.I18n.t("seeVideo")})})})]}),(0,g.jsxs)("div",{className:"mailpoet-settings-inputs",children:[(0,g.jsxs)("div",{className:"mailpoet-settings-inputs-row",children:[(0,g.jsx)(Bt.s,{name:"select_method",automationId:"import-paste-method",id:"import-paste-method",checked:"paste-method"===t,value:"paste-method",onCheck:e}),(0,g.jsx)("label",{htmlFor:"import-paste-method",children:m.U.I18n.t("methodPaste")})]}),(0,g.jsxs)("div",{className:"mailpoet-settings-inputs-row",children:[(0,g.jsx)(Bt.s,{name:"select_method",automationId:"import-csv-method",id:"import-csv-method",checked:"file-method"===t,value:"file-method",onCheck:e}),(0,g.jsx)("label",{htmlFor:"import-csv-method",children:m.U.I18n.t("methodUpload")})]}),(0,g.jsxs)("div",{className:"mailpoet-settings-inputs-row",children:[(0,g.jsx)(Bt.s,{name:"select_method",automationId:"import-mailchimp-method",id:"import-mailchimp-method",checked:"mailchimp-method"===t,value:"mailchimp-method",onCheck:e}),(0,g.jsx)("label",{htmlFor:"import-mailchimp-method",children:m.U.I18n.t("methodMailChimp")})]})]})]})}function Km({hidePrevious:e=!1,isLastStep:t=!1,canGoNext:a=!0,onPreviousAction:i=()=>{},onNextAction:s=()=>{}}){return(0,g.jsxs)("div",{className:"mailpoet-settings-save",children:[!e&&(0,g.jsx)(Ge.$,{type:"button",variant:"secondary",onClick:i,children:m.U.I18n.t("previousStep")}),(0,g.jsx)(Ge.$,{type:"button",automationId:"import-next-step",isDisabled:!a,onClick:()=>{a&&s()},children:m.U.I18n.t(t?"import":"nextStep")})]})}function Zm({canFinish:e,onValueChange:t,data:a="",onFinish:i=()=>{},onPrevious:s=()=>{}}){return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)("div",{className:"mailpoet-settings-label",children:[(0,g.jsx)("label",{htmlFor:"paste_input",children:m.U.I18n.t("pasteLabel")}),(0,g.jsx)("p",{className:"description",children:b()(m.U.I18n.t("pasteDescription"),/\[link\](.*?)\[\/link\]/,e=>(0,g.jsx)("a",{className:"mailpoet-link",href:"https://kb.mailpoet.com/article/126-importing-subscribers-with-csv-files",target:"_blank",rel:"noopener noreferrer",children:e},"kb-link"))})]}),(0,g.jsx)("div",{className:"mailpoet-settings-inputs",children:(0,g.jsx)(Ot.T,{id:"paste_input",rows:"15",placeholder:"Email, First Name, Last Name\njohn@doe.com, John, Doe\nmary@smith.com, Mary, Smith\njohnny@walker.com, Johnny, Walker",isCode:!0,onChange:e=>{t(e.target.value)},defaultValue:a})}),(0,g.jsx)(Km,{canGoNext:e,onPreviousAction:s,onNextAction:i})]})}function Jm({onValueChange:e,canFinish:t,onFinish:a=()=>{},onPrevious:i=()=>{}}){return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)("div",{className:"mailpoet-settings-label",children:[(0,g.jsx)("label",{htmlFor:"file_local",children:m.U.I18n.t("methodUpload")}),(0,g.jsx)("p",{className:"description",children:b()(m.U.I18n.t("pasteDescription"),/\[link\](.*?)\[\/link\]/,e=>(0,g.jsx)("a",{className:"mailpoet-link",href:"https://kb.mailpoet.com/article/126-importing-subscribers-with-csv-files",target:"_blank",rel:"noopener noreferrer",children:e},"kb-link"))})]}),(0,g.jsx)("div",{className:"mailpoet-settings-inputs",children:(0,g.jsx)(Dt.p,{type:"file",id:"file_local",accept:".csv","data-automation-id":"import-file-upload-input",onChange:t=>{const a=t.target.value.match(/[^.]+$/);m.U.Notice.hide(),null===a||"csv"!==a[0].toLowerCase()?(m.U.Notice.error(m.U.I18n.t("wrongFileFormat")),e("")):e(t.target.files[0])}})}),(0,g.jsx)(Km,{canGoNext:t,onPreviousAction:i,onNextAction:a})]})}function Qm({onFinish:e=()=>{},onPrevious:t=()=>{}}){const[a,i]=(0,r.useState)(""),[s,n]=(0,r.useState)(void 0),[o,l]=(0,r.useState)([]);return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("div",{className:"mailpoet-settings-label",children:(0,g.jsxs)("label",{htmlFor:"mailpoet_mailchimp_key_input",children:[(0,g.jsx)("span",{className:"mailpoet_import_heading",children:m.U.I18n.t("methodMailChimpLabel")}),(0,g.jsx)("p",{className:"description",children:b()(m.U.I18n.t("methodMailChimpDescription"),/\[link\](.*?)\[\/link\]/,e=>(0,g.jsx)("a",{className:"mailpoet-link",href:"https://kb.mailpoet.com/article/255-migrating-from-mailchimp-to-mailpoet#api",target:"_blank",rel:"noopener noreferrer",children:e},"kb-link"))})]})}),(0,g.jsx)("div",{className:"mailpoet-settings-inputs",children:(0,g.jsxs)("div",{className:"mailpoet-settings-inputs-row mailpoet-settings-inputs-row-centered",children:[(0,g.jsx)(Dt.p,{dimension:"small",id:"mailpoet_mailchimp_key_input",type:"text",onChange:e=>{i(e.target.value),""===e.target.value.trim()&&n(void 0)}}),(0,g.jsx)("span",{className:"mailpoet-gap"}),(0,g.jsx)(Ge.$,{type:"button",dimension:"small",onClick:()=>{m.U.Modal.loading(!0),m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"importExport",action:"getMailChimpLists",data:{api_key:a}}).always(()=>{m.U.Modal.loading(!1)}).done(e=>n(e.data)).fail(e=>{e.errors.length>0&&m.U.Notice.showApiErrorNotice(e,{scroll:!0})})},children:m.U.I18n.t("methodMailChimpVerify")}),(0,g.jsx)("span",{className:"mailpoet-gap"}),(0,g.jsx)("span",{children:Array.isArray(s)&&0===s.length?m.U.I18n.t("noMailChimpLists"):null})]})}),s?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("div",{className:"mailpoet-settings-label",children:m.U.I18n.t("methodMailChimpSelectList")}),(0,g.jsx)("div",{className:"mailpoet-settings-inputs",children:(0,g.jsx)(Ve.L,{field:{id:"segments",name:"list-selection",multiple:!0,placeholder:m.U.I18n.t("methodMailChimpSelectPlaceholder"),forceSelect2:!0,values:s},onValueChange:e=>l(e.target.value)})})]}):null,(0,g.jsx)(Km,{canGoNext:Array.isArray(o)&&o.length>0,onPreviousAction:t,onNextAction:()=>{m.U.Modal.loading(!0),m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"importExport",action:"getMailChimpSubscribers",data:{api_key:a,lists:o}}).always(()=>{m.U.Modal.loading(!1)}).done(t=>e(t.data)).fail(e=>{e.errors.length>0&&m.U.Notice.showApiErrorNotice(e,{scroll:!0})})}})]})}Ym.propTypes={activeMethod:Rt().string,onMethodChange:Rt().func.isRequired},Ym.displayName="SelectImportMethod",Km.propTypes={canGoNext:Rt().bool,hidePrevious:Rt().bool,isLastStep:Rt().bool,onPreviousAction:Rt().func,onNextAction:Rt().func},Km.displayName="PreviousNextStepButtons",Zm.propTypes={onFinish:Rt().func,onPrevious:Rt().func,canFinish:Rt().bool.isRequired,onValueChange:Rt().func.isRequired,data:Rt().string},Zm.displayName="MethodPaste",Jm.propTypes={canFinish:Rt().bool.isRequired,onFinish:Rt().func,onPrevious:Rt().func,onValueChange:Rt().func.isRequired},Jm.displayName="MethodUpload",Qm.propTypes={onFinish:Rt().func,onPrevious:Rt().func},Qm.displayName="MethodMailChimp";var Xm=a(87714),eu=a.n(Xm);const tu=e=>{if("string"!=typeof e)return!1;const t=e.toLowerCase();return window.roleBasedEmails.findIndex(e=>t.startsWith(`${e}@`))>=0},au=e=>{let t,a=Lt.default.unescape(e);return a=a.toLowerCase().replace(/^["';.,\s]+|[^\x20-\x7E]+$|["';.,_\s]+$/g,"").replace(/\s+|%\d+|,+/g,""),t=/<(.*?)>/.exec(a),t&&(a=t[1].trim()),t=/mailto:(?:\s+)?(.*)/.exec(a),t&&(a=t[1].trim()),!!window.mailpoet_email_regex.test(a)&&a};function iu({setStepMethodSelectionData:e,subscribersLimitForValidation:t}){const a=(0,Ue.Zp)(),[i,s]=(0,r.useState)(void 0),[n,l]=(0,r.useState)(""),[d,c]=(0,r.useState)(void 0),u=s=>{e(s),a(((e,t,a)=>void 0===e||void 0===e.subscribersCount||e.subscribersCount<t||"mailchimp-method"===a?"/step_data_manipulation":"/step_input_validation")(s,t,i))},p=()=>{a("/step_clean_list")},h=()=>{(e=>{const t=encodeURI(e).split(/%..|./).length-1;m.U.Notice.hide(),t>window.maxPostSizeBytes?m.U.Notice.error(m.U.I18n.t("maxPostSizeNotice")):(m.U.Modal.loading(!0),eu().parse(e,function(e){return{skipEmptyLines:!0,error(){m.U.Notice.hide(),m.U.Notice.error(m.U.I18n.t("dataProcessingError"))},complete(t){const a=function(e){let t=[];const a=[],i=[],s=[],n=[];let r,o,l,d,c=0,m=0,u=0,p=null,h=null,g=!1;return Object.keys(e).forEach(_=>{if(l=e[_].map(e=>e.trim()),d=l.length,null===h&&(h=d),d===h)if(null===p){let e=null;if(Object.keys(l).forEach(i=>{o=au(l[i]),null===p&&window.mailpoet_email_regex.test(o)&&(tu(o)?null===e&&(e=i):(p=i,a[o]=!0,l[i]=o,t[o]=l))}),null===p&&null!==e){p=e;const t=au(l[e]);a[t]=!0,n.push(l[e]),u+=1}null===p&&0===parseInt(_,10)&&(g=!0,t[0]=l)}else""!==l[p]&&(r=au(l[p]),Lt.default.has(a,r)?(i.push(r),c+=1):tu(r)?(a[r]=!0,n.push(l[p]),u+=1):window.mailpoet_email_regex.test(r)?(a[r]=!0,l[p]=r,t[r]=l):(s.push(l[p]),m+=1))}),t=Lt.default.values(t),t&&(g&&t.length>=2||!g&&t.length>=1)?{header:window.mailpoet_email_regex.test(t[0][p])?null:t.shift(),subscribers:t,subscribersCount:t.length,duplicate:Lt.default.uniq(i),invalid:Lt.default.uniq(s),role:Lt.default.uniq(n),duplicateRowsCount:c,invalidRowsCount:m,roleRowsCount:u}:null}(t.data);if(a)e(a);else{let e=m.U.I18n.t("noValidRecords");e=e.replace("[link]",'<a href="https://kb.mailpoet.com/article/126-importing-subscribers-with-csv-files">'),e=e.replace("[/link]","</a>"),m.U.Notice.error(e)}m.U.Modal.loading(!1)}}}(e=>{m.U.trackEvent("Subscribers import started",{source:"file-method"===i?"file upload":"pasted data"}),u(e)})))})("paste-method"===i?n:d)};return(0,g.jsxs)("div",{className:"mailpoet-settings-grid",children:[(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(Ym,{activeMethod:i,onMethodChange:s})}),"paste-method"===i&&(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(Zm,{onPrevious:p,onValueChange:l,onFinish:h,canFinish:!!n.trim(),data:n})}),"file-method"===i&&(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(Jm,{onPrevious:p,onValueChange:c,onFinish:h,canFinish:!!d,data:d})}),"mailchimp-method"===i&&(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(Qm,{onPrevious:p,onFinish:e=>{m.U.trackEvent("Subscribers import started",{source:"MailChimp"}),u(e)}})}),void 0===i&&(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(Km,{canGoNext:!1,onPreviousAction:p})})]})}function su({onProceed:e,iHaveCleanedList:t}){return(0,g.jsxs)("div",{className:"mailpoet-clean-list-step-container",children:[(0,g.jsx)("p",{children:m.U.I18n.t("cleanListText1")}),(0,g.jsx)("p",{children:m.U.I18n.t("cleanListText2")}),(0,g.jsxs)("p",{children:[e&&(0,g.jsx)(Ge.$,{onClick:e,variant:"tertiary",children:m.U.I18n.t("listCleaningGotIt")}),(0,g.jsx)(Ge.$,{target:"_blank",href:"https://kb.mailpoet.com/article/287-list-cleaning-services",children:m.U.I18n.t("tryListCleaning")}),t&&(0,g.jsx)(Ge.$,{onClick:t,variant:"secondary",children:m.U.I18n.t("cleanedList")})]})]})}function nu({onSubmit:e}){const t=(0,Ue.Zp)(),[a,i]=(0,r.useState)(void 0);return(0,g.jsxs)("div",{className:"mailpoet-settings-grid",children:[(0,g.jsx)("div",{className:"mailpoet-settings-label",children:m.U.I18n.t("validationStepHeading")}),(0,g.jsxs)("div",{className:"mailpoet-settings-inputs",children:[(0,g.jsxs)("div",{className:"mailpoet-settings-inputs-row",children:[(0,g.jsx)(Bt.s,{automationId:"mailpoet_import_validation_step_option1",id:"existing-list",checked:"existing-list"===a,value:"existing-list",onCheck:i}),(0,g.jsx)("label",{htmlFor:"existing-list",children:m.U.I18n.t("validationStepRadio1")})]}),(0,g.jsxs)("div",{className:"mailpoet-settings-inputs-row",children:[(0,g.jsx)(Bt.s,{automationId:"mailpoet_import_validation_step_option2",id:"address-book",checked:"address-book"===a,value:"address-book",onCheck:i}),(0,g.jsx)("label",{htmlFor:"address-book",children:m.U.I18n.t("validationStepRadio2")})]})]}),(0,g.jsx)(Km,{canGoNext:void 0!==a,onPreviousAction:()=>t("/step_method_selection"),onNextAction:()=>e(a)})]})}function ru(){return(0,g.jsxs)("div",{className:"mailpoet-clean-list-step-container","data-automation-id":"import_wrong_source_block",children:[(0,g.jsx)("p",{children:m.U.I18n.t("validationStepBlock1")}),(0,g.jsx)("p",{children:m.U.I18n.t("validationStepBlock2")}),(0,g.jsx)("p",{children:(0,g.jsx)(Ge.$,{href:"https://kb.mailpoet.com/article/269-reconfirm-subscribers-to-your-list",target:"_blank",rel:"noopener noreferrer",children:m.U.I18n.t("validationStepBlockButton")})})]})}function ou({onSubmit:e}){const[t,a]=(0,r.useState)("over2years"),i=(0,r.useCallback)(e=>{a(e.target.value)},[a]),s=(0,r.useCallback)(()=>{e("over2years"===t||"1to2years"===t?"notRecently":"recently")},[e,t]);return(0,g.jsxs)("div",{className:"mailpoet-settings-grid",children:[(0,g.jsx)("div",{className:"mailpoet-settings-label",children:m.U.I18n.t("validationStepLastSentHeading")}),(0,g.jsx)("div",{className:"mailpoet-settings-inputs",children:(0,g.jsxs)(Be.Select,{defaultValue:t,onChange:i,automationId:"last_sent_to_list",children:[(0,g.jsx)("option",{value:"over2years",children:m.U.I18n.t("validationStepLastSentOption1")}),(0,g.jsx)("option",{value:"1to2years",children:m.U.I18n.t("validationStepLastSentOption2")}),(0,g.jsx)("option",{value:"less1year",children:m.U.I18n.t("validationStepLastSentOption3")}),(0,g.jsx)("option",{value:"less3months",children:m.U.I18n.t("validationStepLastSentOption4")})]})}),(0,g.jsx)("div",{className:"mailpoet-settings-save",children:(0,g.jsx)(Ge.$,{type:"button",automationId:"last_sent_to_list_next",onClick:s,children:m.U.I18n.t("validationStepLastSentNext")})})]})}function lu({stepMethodSelectionData:e}){const t=(0,Ue.Zp)(),[a,i]=(0,r.useState)(void 0),[s,n]=(0,r.useState)(void 0);(0,r.useEffect)(()=>{void 0===e&&t("/step_method_selection",{replace:!0})},[e,t]);const l=(0,r.useCallback)(e=>{n(e),"recently"===e&&t("/step_data_manipulation")},[t,n]);return(0,g.jsxs)(g.Fragment,{children:[void 0===a&&(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(nu,{onSubmit:i})}),"address-book"===a&&(0,g.jsx)(ru,{}),"existing-list"===a&&void 0===s&&(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(ou,{onSubmit:l})}),"existing-list"===a&&"notRecently"===s&&(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(su,{iHaveCleanedList:()=>l("recently")})})]})}function du({translation:e,subscribers:t}){let a="";return t.length&&(a=b()(e.replace("%2$s",t.join(", ")),"%1$s",()=>(0,g.jsx)("strong",{children:t.length.toLocaleString()},e)),a=(0,g.jsx)("p",{children:a})),a}function cu({stepMethodSelectionData:e={invalid:[],duplicate:[],role:[]}}){const{invalid:t,duplicate:a,role:i}=e,[s,n]=(0,r.useState)(!1),o=v()("mailpoet_subscribers_data_parse_results_details",{mailpoet_hidden:!s}),l=(0,g.jsx)(du,{translation:m.U.I18n.t("importNoticeInvalid"),subscribers:t}),d=(0,g.jsx)(du,{translation:m.U.I18n.t("importNoticeDuplicate"),subscribers:a});let c="";if(i.length&&(c=b()(m.U.I18n.t("importNoticeRoleBased"),/(%1\$s|\[link\].*\[\/link\]|%2\$s)/,e=>"%1$s"===e?(0,g.jsx)("strong",{children:i.length.toLocaleString()},"role-length"):"%2$s"===e?i.join(", "):(0,g.jsx)("a",{href:"https://kb.mailpoet.com/article/270-sending-to-role-based-email-addresses-is-not-allowed",target:"_blank",rel:"noopener noreferrer",children:e.replace("[link]","").replace("[/link]","")},e)),c=(0,g.jsx)("p",{children:c})),t.length||a.length||i.length){const e=t.length+a.length+i.length;return(0,g.jsxs)("div",{className:"error",children:[(0,g.jsxs)("p",{children:[b()(m.U.I18n.t("importNoticeSkipped"),"%1$s",()=>(0,g.jsx)("strong",{children:e.toLocaleString()},"lengths"))," ",(0,g.jsx)("a",{className:"mailpoet_subscribers_data_parse_results_details_show","data-automation-id":"show-more-details",onClick:()=>n(!s),role:"button",tabIndex:0,onKeyDown:e=>{["keydown","keypress"].includes(e.type)&&["Enter"," "].includes(e.key)&&(e.preventDefault(),n(!s))},children:m.U.I18n.t("showMoreDetails")})]}),(0,g.jsxs)("div",{className:o,children:[(0,g.jsx)("hr",{}),l,d,c]})]})}return null}iu.propTypes={setStepMethodSelectionData:Rt().func.isRequired,subscribersLimitForValidation:Rt().number.isRequired},iu.diplayName="StepMethodSelection",su.displayName="CleanList",nu.propTypes={onSubmit:Rt().func.isRequired},nu.displayName="InitialQuestion",ou.propTypes={onSubmit:Rt().func.isRequired},ou.displayName="LastSentQuestion",lu.displayName="StepInputValidation",du.propTypes={translation:Rt().string.isRequired,subscribers:Rt().arrayOf(Rt().string).isRequired},cu.propTypes={stepMethodSelectionData:Rt().shape({duplicate:Rt().arrayOf(Rt().string),invalid:Rt().arrayOf(Rt().string),role:Rt().arrayOf(Rt().string)})};const mu=["first","first name","firstname","given name","fname"],uu=["last","last name","lastname","surname","family name","lname"];function pu({header:e=[],subscribers:t}){const a=((e,t)=>{const a=[],i=[];let s,n,r,o;return Object.keys(e[0]).forEach(l=>{s=e[0][l],n="ignore",s%1!=0&&window.mailpoet_email_regex.test(s)?n="email":t&&(r=t[l],o=window.mailpoetColumns.map(e=>e.name).indexOf(r),-1!==o?n=window.mailpoetColumns[o].id:r&&(n=(e=>{const t=(e=>String(e).trim().toLowerCase().replaceAll("_"," ").replaceAll("-"," ").replaceAll("."," ").split(" ").filter(Boolean).join(" "))(e);return mu.includes(t)?"first_name":uu.includes(t)?"last_name":"ignore"})(r))),n="ignore"!==n&&-1===i.indexOf(n)?n:"ignore",a[l]={column_id:n},i.push(n)}),a})(t,e);return(0,g.jsxs)("tr",{children:[(0,g.jsx)("th",{children:m.U.I18n.t("matchData")}),a.map((e,t)=>(0,g.jsx)("th",{children:(0,g.jsx)("select",{className:"mailpoet_subscribers_column_data_match","data-column-id":e.column_id,"data-column-index":t,id:`column_${t}`})},t))]})}function hu({header:e}){return(0,g.jsxs)("tr",{className:"mailpoet_header",children:[(0,g.jsx)("td",{}),e.map(e=>(0,g.jsx)("td",{children:e},e))]})}function gu({subscriber:e,index:t}){return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("td",{children:t}),e.map((e,a)=>(0,g.jsx)("td",{children:e},`${e}-${t}-${a}`))]})}function _u({subscribers:e,subscribersCount:t}){const a=". . .",i=Array(e[0].length).fill(a);return(0,g.jsxs)(g.Fragment,{children:[e.slice(0,10).map((e,t)=>(0,g.jsx)("tr",{children:(0,g.jsx)(gu,{subscriber:e,index:t+1})},`${e[0]}-${t}`)),t>11?(0,g.jsx)("tr",{children:(0,g.jsx)(gu,{subscriber:i,index:a})},"filler"):null,t>10?(0,g.jsx)("tr",{children:(0,g.jsx)(gu,{subscriber:e[t-1],index:t})},e[t-1][0]):null]})}function fu({subscribersCount:e=0,subscribers:t=[],header:a=[],onCreateCustomField:i}){return(0,r.useLayoutEffect)(()=>{(e=>{const t={data:window.mailpoetColumnsSelect2,width:"15em"};Tt()("select.mailpoet_subscribers_column_data_match").select2(t).on("select2:selecting",t=>{const a=t.currentTarget,i=t.params.args.data.id;"create"===i?(t.preventDefault(),Tt()(a).select2("close"),e(a)):Tt()("select.mailpoet_subscribers_column_data_match").each((e,s)=>{if(s===a)return;const n=Tt()(s).val();n===i&&"ignore"!==n&&(confirm(`${m.U.I18n.t("selectedValueAlreadyMatched")} ${m.U.I18n.t("confirmCorrespondingColumn")}`)?Tt()(s).data("column-id","ignore"):(t.preventDefault(),Tt()(a).select2("close")))})}).on("select2:select",e=>{const t=e.currentTarget,a=e.params.data.id;Tt()(t).data("column-id",a)}).on("select2:open",()=>{const e=document.querySelectorAll(".select2-search__field[aria-controls]");0!==e.length&&e[e.length-1].focus()}),Tt().map(Tt()(".mailpoet_subscribers_column_data_match"),e=>{const t=Tt()(e).data("column-id");Tt()(e).val(t).trigger("change")})})(i)},[i]),(0,g.jsx)("div",{className:"subscribers_data",children:(0,g.jsxs)("table",{className:"mailpoet_subscribers widefat fixed",children:[(0,g.jsx)("thead",{children:(0,g.jsx)(pu,{header:a,subscribers:t})}),(0,g.jsxs)("tbody",{children:[a?(0,g.jsx)(hu,{header:a}):null,(0,g.jsx)(_u,{subscribers:t,subscribersCount:e})]})]})})}function bu({setSelectedSegments:e}){const{segments:t}=(0,r.useContext)(l.F),{all:a,updateAll:i}=t,[s,n]=(0,r.useState)(a);(0,r.useLayoutEffect)(()=>{!function(t){const a=Tt()("select#mailpoet_segments_select");if(a.data("select2"))return;const i=e=>{let t=`<span class="mailpoet-form-select2-text"><span>${e.name}</span></span>`;return e.count&&(t+=`<span class="mailpoet-form-select2-count">${e.count}</span>`),t};a.html(""),a.select2({data:t.map(e=>({...e,text:e.name})),dropdownCssClass:"mailpoet-form-select2-dropdown",escapeMarkup:e=>e,templateResult:i,templateSelection:i}).on("change",t=>{const i=Tt()('[data-id="notice_segmentSelection"]');t.currentTarget.value?Tt()('[data-id="notice_segmentSelection"]').remove():i.length||m.U.Notice.error(m.U.I18n.t("segmentSelectionRequired"),{static:!0,scroll:!0,id:"notice_segmentSelection",hideClose:!0});(t=>{e(t)})(Lt.default.pluck(a.select2("data"),"id"))})}(s)},[s,e]);const o=t=>{!function(){const e=Tt()("select#mailpoet_segments_select");e.data("select2")&&(e.select2("destroy"),e.find("option").remove(),e.off("select2:unselecting").off("change").off("select2:opening"))}(),e([]),n([...s,t]),i([...s,t])};return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("div",{className:"mailpoet-settings-label",children:(0,g.jsxs)("label",{htmlFor:"mailpoet_segments_select",children:[m.U.I18n.t("pickLists"),(0,g.jsx)("p",{className:"description",children:m.U.I18n.t("pickListsDescription")})]})}),(0,g.jsx)("div",{className:"mailpoet-settings-inputs",children:(0,g.jsxs)("div",{className:"mailpoet-settings-inputs-row mailpoet-settings-inputs-row-centered",children:[(0,g.jsx)("div",{className:"mailpoet-form-select mailpoet-form-input",children:(0,g.jsx)("select",{id:"mailpoet_segments_select","data-placeholder":m.U.I18n.t("select"),multiple:"multiple",children:(0,g.jsx)("option",{})})}),(0,g.jsx)(Ge.$,{variant:"tertiary",onClick:()=>{return e=o,m.U.Modal.popup({title:m.U.I18n.t("addNewList"),template:Tt()("#new_segment_template").html()}),Tt()("#new_segment_name").on("keypress",e=>{13===e.which&&Tt()("#new_segment_process").trigger("click")}),Tt()("#new_segment_process").on("click",()=>{const t=Tt()("#new_segment_name").val()?.toString().trim()||"",a=Tt()("#new_segment_description").val()?.toString().trim()||"";m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"ImportExport",action:"addSegment",data:{name:t,description:a}}).done(t=>{e({id:t.data.id,name:t.data.name,text:t.data.name,subscriberCount:0}),m.U.Modal.close()}).fail(e=>{e.errors.length>0&&(m.U.Notice.hide(),m.U.Notice.showApiErrorNotice(e,{positionAfter:"#new_segment_error_message"}))}).catch(()=>{})}),void Tt()("#new_segment_cancel").on("click",()=>{m.U.Modal.close()});var e},children:m.U.I18n.t("createANewList")})]})})]})}function xu(){return(0,g.jsx)("p",{className:"description",children:b()(m.U.I18n.t("consentSubscribed"),/\[link](.*?)\[\/link]/,e=>(0,g.jsx)("a",{className:"mailpoet-link",href:"https://kb.mailpoet.com/article/357-why-express-consent-is-important",target:"_blank",rel:"noopener noreferrer",children:e},"kb-link"))})}function vu({newSubscribersStatus:e,setNewSubscribersStatus:t}){const a=(0,r.useCallback)(e=>{t(e.target.value)},[t]);return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)("div",{className:"mailpoet-settings-label",children:[(0,g.jsx)("label",{htmlFor:"new_subscribers_status",children:m.U.I18n.t("newSubscribersStatus")}),(0,g.jsx)(xu,{})]}),(0,g.jsx)("div",{className:"mailpoet-settings-inputs",children:(0,g.jsxs)(Be.Select,{id:"new_subscribers_status",placeholder:m.U.I18n.t("select"),name:"new_subscribers_status",onChange:a,defaultValue:e,children:[(0,g.jsx)("option",{value:"subscribed",children:m.U.I18n.t("subscribed")}),(0,g.jsx)("option",{value:"inactive",children:m.U.I18n.t("inactive")}),(0,g.jsx)("option",{value:"unsubscribed",children:m.U.I18n.t("unsubscribed")})]})})]})}function yu({existingSubscribersStatus:e,setExistingSubscribersStatus:t}){const a=(0,r.useCallback)(e=>{t(e.target.value)},[t]);return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)("div",{className:"mailpoet-settings-label",children:[(0,g.jsx)("label",{htmlFor:"existing_subscribers_status",children:m.U.I18n.t("existingSubscribersStatus")}),(0,g.jsx)(xu,{})]}),(0,g.jsx)("div",{className:"mailpoet-settings-inputs",children:(0,g.jsxs)(Be.Select,{id:"existing_subscribers_status",placeholder:m.U.I18n.t("select"),name:"existing_subscribers_status",onChange:a,defaultValue:e,children:[(0,g.jsx)("option",{value:"dont_update",children:m.U.I18n.t("dontUpdate")}),(0,g.jsx)("option",{value:"subscribed",children:m.U.I18n.t("subscribed")}),(0,g.jsx)("option",{value:"inactive",children:m.U.I18n.t("inactive")}),(0,g.jsx)("option",{value:"unsubscribed",children:m.U.I18n.t("unsubscribed")})]})})]})}function wu({updateExistingSubscribers:e,setUpdateExistingSubscribers:t}){return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("div",{className:"mailpoet-settings-label",children:m.U.I18n.t("updateExistingSubscribers")}),(0,g.jsxs)("div",{className:"mailpoet-settings-inputs",children:[(0,g.jsx)(Bt.s,{id:"update_existing_subscribers",name:"update_existing_subscribers",value:"1",checked:e,onCheck:()=>t(!0)}),(0,g.jsx)("label",{htmlFor:"update_existing_subscribers",children:m.U.I18n.t("updateExistingSubscribersYes")}),(0,g.jsx)("span",{className:"mailpoet-gap"}),(0,g.jsx)(Bt.s,{id:"dont_update_existing_subscribers",name:"update_existing_subscribers",value:"",checked:!e,onCheck:()=>t(!1)}),(0,g.jsx)("label",{htmlFor:"dont_update_existing_subscribers",children:m.U.I18n.t("updateExistingSubscribersNo")})]})]})}pu.propTypes={subscribers:Rt().arrayOf(Rt().arrayOf(Rt().oneOfType([Rt().string,Rt().number]))).isRequired,header:Rt().arrayOf(Rt().string)},hu.propTypes={header:Rt().arrayOf(Rt().string).isRequired},gu.propTypes={subscriber:Rt().arrayOf(Rt().oneOfType([Rt().string,Rt().number])).isRequired,index:Rt().node.isRequired},_u.propTypes={subscribersCount:Rt().number.isRequired,subscribers:Rt().arrayOf(Rt().arrayOf(Rt().oneOfType([Rt().string,Rt().number]))).isRequired},fu.propTypes={subscribersCount:Rt().number,subscribers:Rt().arrayOf(Rt().arrayOf(Rt().oneOfType([Rt().string,Rt().number]))),header:Rt().arrayOf(Rt().string),onCreateCustomField:Rt().func.isRequired},bu.propTypes={setSelectedSegments:Rt().func.isRequired},wu.propTypes={setUpdateExistingSubscribers:Rt().func.isRequired,updateExistingSubscribers:Rt().bool.isRequired},a(36202);function ju({selectedTags:e,setSelectedTags:t}){const a=(0,r.useCallback)(({value:e})=>{t(e)},[t]),i=m.U.tags.map(e=>e.name);return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)("div",{className:"mailpoet-settings-label",children:[m.U.I18n.t("assignTagsLabel"),(0,g.jsx)("p",{className:"description",children:m.U.I18n.t("assignTagsDescription")})]}),(0,g.jsx)("div",{className:"mailpoet-settings-inputs mailpoet-import-tags",children:(0,g.jsx)(Xt,{name:"tags",onChange:a,suggestedValues:i,selectedValues:e,placeholder:m.U.I18n.t("addNewTag")})})]})}var Su=a(13911),ku=a(96563),Nu=a(5272);function Cu({dateSettings:e,onClose:t,onSuccess:a}){const[i,s]=(0,r.useState)(()=>(0,Nu.uS)(e)),[n,o]=(0,r.useState)(!1),[l,d]=(0,r.useState)(null);return(0,g.jsx)(Te.A,{title:m.U.I18n.t("addNewField"),onRequestClose:t,className:"mailpoet-custom-fields-form-modal",focusOnMount:!0,children:(0,g.jsxs)("form",{onSubmit:async function(e){e.preventDefault();const t=(0,Nu._J)(i);if(t)d(t);else{o(!0),d(null);try{a(await(0,ku.AA)((0,Nu.WD)(i)))}catch(e){d(function(e){return e?.message||m.U.I18n.t("customFieldCreateError")||(0,p.__)("Custom field could not be created","mailpoet")}(e))}finally{o(!1)}}},"data-automation-id":"create_custom_field_form",children:[(0,g.jsx)(Nu.bV,{data:i,dateSettings:e,disabled:n,onChange:s}),l&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(Su.A,{marginTop:4}),(0,g.jsx)("div",{className:"mailpoet-custom-fields-form-error",role:"alert",children:l})]}),(0,g.jsx)(Su.A,{marginTop:6}),(0,g.jsxs)(ma.A,{justify:"flex-end",gap:3,children:[(0,g.jsx)(ua.A,{children:(0,g.jsx)(ge.Ay,{variant:"tertiary",onClick:t,disabled:n,__next40pxDefaultSize:!0,children:(0,p.__)("Cancel","mailpoet")})}),(0,g.jsx)(ua.A,{children:(0,g.jsx)(ge.Ay,{variant:"primary",type:"submit",isBusy:n,disabled:n,__next40pxDefaultSize:!0,children:(0,p.__)("Create custom field","mailpoet")})})]})]})})}function Eu({subscribersLimitForValidation:e,setStepDataManipulationData:t,stepMethodSelectionData:a}){const i=(0,Ue.Zp)(),[s,n]=(0,r.useState)([]),[o,l]=(0,r.useState)(!0),[d,c]=(0,r.useState)("subscribed"),[u,p]=(0,r.useState)("dontUpdate"),[h,_]=(0,r.useState)([]),[f,b]=(0,r.useState)(null),x=(0,r.useMemo)(()=>({dateTypes:window.mailpoet_import_custom_fields_date_types??[],dateFormats:window.mailpoet_import_custom_fields_date_formats??{}}),[]),v=(0,r.useCallback)(e=>{b(e)},[]);(0,r.useEffect)(()=>{void 0===a&&i("/step_method_selection",{replace:!0})},[a,i]);const y=(0,r.useMemo)(()=>({duplicate:a?.duplicateRowsCount??a?.duplicate?.length??0,invalid:a?.invalidRowsCount??a?.invalid?.length??0,role:a?.roleRowsCount??a?.role?.length??0}),[a]);return void 0===a?null:(0,g.jsxs)("div",{"data-automation-id":"import_data_manipulation_step",children:[(0,g.jsx)(cu,{stepMethodSelectionData:a}),(0,g.jsx)(fu,{subscribersCount:a.subscribersCount,subscribers:a.subscribers,header:a.header,onCreateCustomField:v}),(0,g.jsxs)("div",{className:"mailpoet-settings-grid",children:[(0,g.jsx)(bu,{setSelectedSegments:n}),(0,g.jsx)(vu,{newSubscribersStatus:d,setNewSubscribersStatus:c}),(0,g.jsx)(yu,{existingSubscribersStatus:u,setExistingSubscribersStatus:p}),(0,g.jsx)(wu,{setUpdateExistingSubscribers:l,updateExistingSubscribers:o}),(0,g.jsx)(ju,{selectedTags:h,setSelectedTags:_}),(0,g.jsx)(Km,{canGoNext:s.length>0,onPreviousAction:()=>i(function(e,t){return void 0===e||void 0===e.subscribersCount||e.subscribersCount<t?"/step_method_selection":"/step_input_validation"}(a,e)),onNextAction:()=>{((e,t,a,i,s,n,r)=>{const o={},l=new(Tt().AsyncQueue);let d=0;const c=Date.now()/1e3,u={created:0,updated:0,errors:[],segments:[],tags:[]};m.U.Modal.progress(!0);const p=e.reduce((e,t,a)=>(a%2e3==0&&e.push([]),e[e.length-1].push(t),e),[]);Lt.default.each(Tt()("select.mailpoet_subscribers_column_data_match"),(e,t)=>{const a=Tt()(e).data("column-id");"ignore"!==a&&(o[a]={index:t})}),Lt.default.each(p,()=>{l.add(r=>{r.pause(),m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"ImportExport",action:"processImport",data:JSON.stringify({columns:o,subscribers:p[d],timestamp:c,segments:t,newSubscribersStatus:a,existingSubscribersStatus:i,updateSubscribers:s,tags:n})}).done(t=>{const a=t.data.added_to_segment_with_welcome_notification;var i,s;u.created+=t.data.created,u.updated+=t.data.updated,u.segments=t.data.segments,u.added_to_segment_with_welcome_notification=a,m.U.Modal.setProgress((i=u,s=e,Math.floor((i.created+i.updated)/s.length*100))),r.run()}).fail(e=>{m.U.Modal.progress(!1),e.errors.length>0&&m.U.Notice.showApiErrorNotice(e,{scroll:!0})}),d+=1})}),l.run(),l.onComplete(()=>{m.U.Modal.progress(!1),u.errors.length>0&&!u.updated&&!u.created?m.U.Notice.error(Lt.default.flatten(u.errors)):(u.segments=Lt.default.map(Lt.default.filter(u.segments,e=>t.includes(e.id)),e=>e.name),r(u))})})(a.subscribers,s,d,u,o,h,e=>{t({...e,skipped_duplicate:y.duplicate,skipped_invalid:y.invalid,skipped_role:y.role}),i("/step_results")})},isLastStep:!0})]}),f&&(0,g.jsx)(Cu,{dateSettings:x,onClose:()=>b(null),onSuccess:e=>{f&&(((e,t)=>{const a=(e=>({id:e.id,name:e.name,text:e.name,type:e.type,params:e.params,custom:!0}))(t);(()=>{let e=window.mailpoetColumnsSelect2.find(e=>e.name===m.U.I18n.t("userColumns"));if(!e){const t=m.U.I18n.t("userColumns");e={name:t,text:t,children:[]},window.mailpoetColumnsSelect2.push(e)}return e})().children.push(a),window.mailpoetColumns.push(a);const i=`${a.id}`,s={data:window.mailpoetColumnsSelect2,width:"15em"};Tt()("select.mailpoet_subscribers_column_data_match").each((t,n)=>{const r=Tt()(n);if(n===e)return r.find(`option[value="${i}"]`).remove(),r.append(new Option(a.text,i,!0,!0)),r.data("column-id",a.id),r.attr("data-column-id",a.id),r.val(i).trigger("change"),r.trigger({type:"select2:select",params:{data:{...a,id:i}}}),void r.next(".select2-container").find(".select2-selection__rendered").text(a.text).attr("title",a.text);const o=r.data("column-id");r.html("").select2("destroy").select2(s),r.data("column-id",o),r.attr("data-column-id",o),r.val(`${o}`).trigger("change")})})(f,e),b(null))}})]})}function Iu({subscribersCount:e=0,segments:t=[],initialMessage:a=""}){if(e){let i=b()(a,"%1$s",()=>(0,g.jsx)("strong",{children:e.toLocaleString()},"%1$s"));return i=b()(i,"%2$s",()=>`"${t.join('", "')}"`),(0,g.jsx)("p",{children:i})}return null}function Au({createdSubscribers:e=0,updatedSubscribers:t=0}){return e||t?null:(0,g.jsx)("p",{children:m.U.I18n.t("importNoAction")})}function Uu({createdSubscribers:e=0,updatedSubscribers:t=0}){return e||t?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("p",{children:(0,g.jsx)("b",{children:m.U.I18n.t("congratulationResult")})}),(0,g.jsx)("p",{children:b()(m.U.I18n.t("suppressionListReminder"),/\[link](.*?)\[\/link]/,e=>(0,g.jsx)("a",{className:"mailpoet-link",href:"https://kb.mailpoet.com/article/359-how-to-import-a-suppression-list",target:"_blank",rel:"noopener noreferrer",children:e},"kb-link"))})]}):null}function Tu({addedToSegmentWithWelcomeNotification:e=!1}){return e?(0,g.jsx)("p",{children:m.U.I18n.t("importNoWelcomeEmail")}):null}function Pu({errors:e=[],createdSubscribers:t,updatedSubscribers:a,skippedDuplicateSubscribers:i,skippedInvalidSubscribers:s,skippedRoleSubscribers:n,segments:l,addedToSegmentWithWelcomeNotification:d}){const c=(0,Ue.Zp)();return(0,r.useEffect)(()=>{void 0===l&&0===e.length&&void 0===t&&void 0===i&&void 0===s&&void 0===n&&void 0===a&&c("/step_method_selection",{replace:!0})},[l,t,e.length,c,i,s,n,a]),e.length&&m.U.Notice.error(Lt.default.flatten(e)),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsxs)("div",{className:"updated",children:[(0,g.jsx)(Iu,{subscribersCount:t,segments:l,initialMessage:m.U.I18n.t("subscribersCreated")}),(0,g.jsx)(Iu,{subscribersCount:a,segments:l,initialMessage:m.U.I18n.t("subscribersUpdated")}),(0,g.jsx)(Iu,{subscribersCount:s,initialMessage:m.U.I18n.t("importSkippedInvalid")}),(0,g.jsx)(Iu,{subscribersCount:i,initialMessage:m.U.I18n.t("importSkippedDuplicate")}),(0,g.jsx)(Iu,{subscribersCount:n,initialMessage:m.U.I18n.t("importSkippedRoleBased")}),(0,g.jsx)(Au,{createdSubscribers:t,updatedSubscribers:a}),(0,g.jsx)(Tu,{addedToSegmentWithWelcomeNotification:d})]})}),(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(Uu,{createdSubscribers:t,updatedSubscribers:a})}),(0,g.jsx)("div",{className:"mailpoet-settings-grid",children:(0,g.jsxs)("div",{className:"mailpoet-settings-save",children:[(0,g.jsx)(Ge.$,{variant:"secondary",type:"button",onClick:()=>{window.location.href=`${window.location.pathname}${window.location.search}#/step_method_selection`},children:m.U.I18n.t("importAgain")}),(0,g.jsx)(Ge.$,{type:"button",onClick:()=>{window.location.href="admin.php?page=mailpoet-subscribers"},children:m.U.I18n.t("viewSubscribers")})]})})]})}function Ru(){const e=(0,Ue.Zp)();return(0,g.jsx)(su,{onProceed:()=>e("/step_method_selection")})}Eu.propTypes={stepMethodSelectionData:Rt().shape({duplicate:Rt().arrayOf(Rt().string),duplicateRowsCount:Rt().number,header:Rt().arrayOf(Rt().string),invalid:Rt().arrayOf(Rt().string),invalidRowsCount:Rt().number,role:Rt().arrayOf(Rt().string),roleRowsCount:Rt().number,subscribersCount:Rt().number,subscribers:Rt().arrayOf(Rt().arrayOf(Rt().oneOfType([Rt().string,Rt().number])))}),subscribersLimitForValidation:Rt().number.isRequired,setStepDataManipulationData:Rt().func.isRequired},Iu.propTypes={segments:Rt().arrayOf(Rt().string.isRequired),subscribersCount:Rt().number,initialMessage:Rt().string},Iu.displayName="ResultMessage",Au.propTypes={createdSubscribers:Rt().number,updatedSubscribers:Rt().number},Au.displayName="NoAction",Uu.propTypes={createdSubscribers:Rt().number,updatedSubscribers:Rt().number},Uu.displayName="SuppressionListReminder",Tu.propTypes={addedToSegmentWithWelcomeNotification:Rt().bool},Tu.diplayName="NoWelcomeEmail",Pu.propTypes={errors:Rt().arrayOf(Rt().string.isRequired),segments:Rt().arrayOf(Rt().string.isRequired),createdSubscribers:Rt().number,updatedSubscribers:Rt().number,skippedDuplicateSubscribers:Rt().number,skippedInvalidSubscribers:Rt().number,skippedRoleSubscribers:Rt().number,addedToSegmentWithWelcomeNotification:Rt().bool},Pu.displayName="StepResults",Ru.displayName="StepCleanList";const Du=document.getElementById("import_container");function Fu(){const[e,t]=(0,r.useState)(void 0),[a,i]=(0,r.useState)({}),s=(0,l.f)(window);return(0,g.jsx)(l.F.Provider,{value:s,children:(0,g.jsxs)(Ae.HashRouter,{children:[(0,g.jsx)(u.q,{}),(0,g.jsx)(Hm,{children:(0,g.jsxs)(Ue.BV,{children:[(0,g.jsx)(Ue.qh,{path:"/step_clean_list",element:(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(Ru,{})})}),(0,g.jsx)(Ue.qh,{path:"/step_method_selection",element:(0,g.jsx)(iu,{setStepMethodSelectionData:t,subscribersLimitForValidation:100})}),(0,g.jsx)(Ue.qh,{path:"/step_input_validation",element:(0,g.jsx)(lu,{stepMethodSelectionData:e})}),(0,g.jsx)(Ue.qh,{path:"/step_data_manipulation",element:(0,g.jsx)(Eu,{stepMethodSelectionData:e,subscribersLimitForValidation:100,setStepDataManipulationData:i})}),(0,g.jsx)(Ue.qh,{path:"/step_results",element:(0,g.jsx)(Pu,{errors:a.errors,createdSubscribers:a.created,updatedSubscribers:a.updated,skippedDuplicateSubscribers:a.skipped_duplicate,skippedInvalidSubscribers:a.skipped_invalid,skippedRoleSubscribers:a.skipped_role,segments:a.segments,addedToSegmentWithWelcomeNotification:a.added_to_segment_with_welcome_notification})}),(0,g.jsx)(Ue.qh,{path:"*",element:(0,g.jsx)(Ue.C5,{to:"/step_clean_list"})})]})})]})})}Du&&((0,o.registerTranslations)(),(0,n.H)(Du).render((0,g.jsx)(Fu,{})));var Ou=a(75370),Mu=a.n(Ou);Tt()(document).ready(()=>{let e;if(!Tt()("#mailpoet_subscribers_export").length)return;if(!window.exportData.segments)return;const t=Mu().compile(Tt()("#mailpoet_subscribers_export_template").html());function a(t){const a="mailpoet-disabled";"on"===t?e.removeClass(a):e.addClass(a)}Tt()("#mailpoet-export").html(t(window.exportData));const i=Tt()("#export_lists"),s=Tt()("#export_columns");function n(e){let t=`<span class="mailpoet-form-select2-text"><span>${e.name}</span></span>`;return void 0!==e.count&&(t+=`<span class="mailpoet-form-select2-count">${e.count}</span>`),t}function r(e,t){e.data("select2")&&e.html("").select2("destroy"),e.select2({data:t,width:"20em",dropdownCssClass:"mailpoet-form-select2-dropdown",escapeMarkup:e=>e,templateResult:n,templateSelection:n}).on("select2:selecting",t=>{const a=t.params.args.data.id,i=["select","deselect"];let s;Lt.default.contains(i,a)&&(t.preventDefault(),"deselect"===a?Tt()(t.target).val("").trigger("change"):(s=[],Lt.default.each(e.find("option"),e=>{const t=e.value;Lt.default.contains(i,t)||s.push(t)}),Tt()(t.target).val(s).trigger("change")),Tt()(t.target).select2("close"))}).on("change",()=>{window.exportData.segments&&i.select2("data").length&&s.select2("data").length||!window.exportData.segments&&s.select2("data").length?a("on"):a("off")})}e=Tt()("#mailpoet-export-button"),window.segments.forEach(e=>{i.append(Tt()("<option></option>").attr("value",e.id).text(e.name))}),window.subscriberFieldsSelect2.forEach(e=>{e.text=e.name,e.children.forEach(e=>{e.name=(0,Me.Zn)(e.name),e.text=(0,Me.Zn)(e.name)})}),r(i,window.segments),r(s,window.subscriberFieldsSelect2),s.val(["email","first_name","last_name","list_status","global_status","created_at","confirmed_at"]).trigger("change"),e.on("click",e=>{if(Tt()(e.target).hasClass("mailpoet-disabled"))return;m.U.Modal.loading(!0);const t=Tt()(':radio[name="option_format"]:checked').val();m.U.Ajax.post({api_version:m.U.apiVersion,endpoint:"ImportExport",action:"processExport",data:JSON.stringify({export_format_option:t,segments:!!window.exportData.segments&&i.val(),subscriber_fields:s.val()})}).always(()=>{m.U.Modal.loading(!1)}).done(e=>{const a=m.U.I18n.t("exportMessage").replace("%1$s",`<strong>${parseInt(e.data.totalExported,10).toLocaleString()}</strong>`).replace("[link]",`<a href="${e.data.exportFileURL}" target="_blank" >`).replace("[/link]","</a>");Tt()("#export_result_notice").html(`<p>${a}</p>`).show(),window.location.href=e.data.exportFileURL,m.U.trackEvent("Subscribers export completed",{"Total exported":e.data.totalExported,"File Format":t})}).fail(e=>{e.errors.length>0&&m.U.Notice.showApiErrorNotice(e,{scroll:!0})})})});var Lu=a(83564),$u=a(9261);function Bu({children:e}){return(0,g.jsx)("div",{className:"mailpoet-steps-content",children:e})}const Wu=(0,g.jsx)("svg",{width:"13",height:"11",viewBox:"0 0 13 11",children:(0,g.jsx)("path",{fill:"currentColor",d:"M9.967.638c.483-.698 1.405-.846 2.06-.33.654.515.793 1.499.31 2.197l-5.44 7.857c-.55.794-1.64.857-2.267.132l-3.4-3.928c-.552-.638-.515-1.632.083-2.22.598-.59 1.53-.55 2.082.088l2.19 2.532L9.968.638z"})}),Vu=(0,g.jsx)("svg",{width:"17",height:"16",viewBox:"0 0 17 16",children:(0,g.jsx)("path",{fill:"currentColor",d:"M12.407 3.31c.576.576.576 1.509 0 2.084L9.914 7.888l2.411 2.412c.586.585.586 1.535 0 2.121-.585.586-1.535.586-2.12 0l-2.413-2.412L5.3 12.503c-.576.575-1.509.575-2.084 0-.575-.575-.575-1.508 0-2.083l2.493-2.495-2.41-2.41c-.587-.587-.587-1.536 0-2.122.585-.586 1.535-.586 2.12 0L7.83 5.804l2.494-2.493c.575-.576 1.508-.576 2.083 0z"})});function qu({onCheck:e,showError:t,checked:a,automationId:i,...s}){return(0,g.jsxs)("div",{className:v()({"mailpoet-form-yesno":!0,"mailpoet-form-yesno-error":t,"mailpoet-disabled":s.disabled}),"data-automation-id":i,children:[(0,g.jsxs)("label",{children:[(0,g.jsx)("input",{"aria-label":(0,p.__)("Yes","mailpoet"),type:"radio",checked:!0===a,onChange:()=>e(!0),...s}),(0,g.jsx)("span",{className:"mailpoet-form-yesno-control mailpoet-form-yesno-yes",children:Wu})]}),(0,g.jsxs)("label",{children:[(0,g.jsx)("input",{"aria-label":(0,p.__)("No","mailpoet"),type:"radio",checked:!1===a,onChange:()=>e(!1),...s}),(0,g.jsx)("span",{className:"mailpoet-form-yesno-control mailpoet-form-yesno-no",children:Vu})]})]})}function zu({submitForm:e,loading:t,showCustomersImportSetting:a,isWizardStep:i=!1}){const[s,n]=(0,r.useState)(null),[l,d]=(0,r.useState)(!1===a?"unsubscribed":null),[c,m]=(0,r.useState)(!1),u=i?(0,p._x)("Continue","A label on a button","mailpoet"):(0,p._x)("Start using WooCommerce features","Submit button caption on the standalone WooCommerce setup page","mailpoet");let h;return"subscribed"===l&&(h=!0),"unsubscribed"===l&&(h=!1),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(o.TypographyHeading,{level:1,children:(0,p._x)("Power up your WooCommerce store","Title on the WooCommerce setup page","mailpoet")}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)("p",{children:(0,p.__)("MailPoet comes with powerful features for WooCommerce. Select features that you would like to use with your store.","mailpoet")}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsxs)("form",{onSubmit:t=>(t.preventDefault(),m(!0),null===l||null===s||e(l,s),!1),children:[(0,g.jsxs)("div",{children:[a?(0,g.jsxs)("div",{className:"mailpoet-wizard-woocommerce-option",children:[(0,g.jsxs)("div",{children:[(0,g.jsx)("p",{children:b()((0,p.__)("Do you want to import your WooCommerce customers as subscribed? [link]Learn more[/link].","mailpoet"),/\[link\](.*?)\[\/link\]/,e=>(0,g.jsx)("a",{href:"https://kb.mailpoet.com/article/284-import-old-customers-to-the-woocommerce-customers-list",rel:"noopener noreferrer",target:"_blank",children:e},e))}),(0,g.jsxs)("div",{className:"mailpoet-wizard-note",children:[(0,g.jsx)("span",{children:"GDPR"}),(0,p._x)("To be compliant with privacy regulations, your customers must have explicitly accepted to receive your marketing emails.","GDPR compliance information","mailpoet")]})]}),(0,g.jsx)("div",{className:"mailpoet-wizard-woocommerce-toggle",children:(0,g.jsx)(qu,{showError:c&&null===l,checked:h,onCheck:e=>d(e?"subscribed":"unsubscribed"),name:"mailpoet_woocommerce_import_type",automationId:"woocommerce_import_type"})})]}):null,(0,g.jsxs)("div",{className:"mailpoet-wizard-woocommerce-option",children:[(0,g.jsxs)("div",{children:[(0,g.jsx)("p",{children:b()((0,p.__)("Collect more precise email and site engagement, and e-commerce metrics by enabling cookie tracking. [link]Learn more[/link].","mailpoet"),/\[link\](.*?)\[\/link\]/,e=>(0,g.jsx)("a",{href:"https://kb.mailpoet.com/article/280-woocommerce-cookie-tracking",rel:"noopener noreferrer",target:"_blank",children:e},e))}),(0,g.jsxs)("div",{className:"mailpoet-wizard-note",children:[(0,g.jsx)("span",{children:"GDPR"}),(0,p._x)("To be compliant, you should display a cookie tracking banner on your website.","GDPR compliance information","mailpoet")]})]}),(0,g.jsx)("div",{className:"mailpoet-wizard-woocommerce-toggle",children:(0,g.jsx)(qu,{showError:c&&null===s,checked:s,onCheck:e=>n(e),name:"mailpoet_woocommerce_tracking",automationId:"woocommerce_tracking"})})]})]}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)(o.Button,{className:"mailpoet-wizard-continue-button",isFullWidth:!0,type:"submit",withSpinner:t,disabled:t,automationId:"submit_woocommerce_setup",children:u})]})]})}function Hu(e){return(0,g.jsx)($n,{illustrationUrl:e.illustrationUrl,children:e.children})}function Gu({isWizardStep:e=!1,redirectToNextStep:t=null}){const[a,i]=(0,r.useState)(!1),[s,n]=(0,$u.iK)("woocommerce"),l=(0,$u.iK)("tracking")[1],d=(0,$u.iK)("woocommerce_import_screen_displayed")[1],c=(0,$u.iK)("mailpoet_subscribe_old_woocommerce_customers")[1],u=e=>{i(!1),m.U.Notice.showApiErrorNotice(e,{scroll:!0})},p=e=>m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"settings",action:"set",data:e}).fail(u),h=(0,g.jsx)(Hu,{illustrationUrl:window.wizard_woocommerce_illustration_url,children:(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(zu,{loading:a,submitForm:async(a,r)=>{i(!0);const o="basic"===m.U.trackingConfig.level?"basic":"partial",h={level:r?"full":o,opens:"merged"},g={enabled:"subscribed"===a?"1":""},_={woocommerce_import_screen_displayed:1,"mailpoet_subscribe_old_woocommerce_customers.enabled":g.enabled,"tracking.level":h.level,"woocommerce.accept_cookie_revenue_tracking.set":"1","tracking.opens":h.opens};await p(_),l(h),c(g),n({...s,accept_cookie_revenue_tracking:{...s.accept_cookie_revenue_tracking||{},set:"1"}}),d("1"),await m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"importExport",action:"setupWooCommerceInitialImport"}).fail(u),e?t():await(async()=>{e?await p({version:window.mailpoet_version}).then(()=>{window.location.href=window.finish_wizard_url}):window.location.href=window.finish_wizard_url})()},isWizardStep:e,showCustomersImportSetting:window.mailpoet_show_customers_import})})});return e?h:(0,g.jsx)(Bu,{children:h})}function Yu({skipStep:e,loading:t,update_sender:a,submit_sender:i,sender:s=null}){return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(Kt.D,{level:1,children:(0,p.__)("Start by configuring your sender information","mailpoet")}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsxs)("p",{children:[(0,g.jsx)("b",{children:(0,p.__)("Default sender","mailpoet")}),(0,g.jsx)("br",{}),(0,p.__)("Enter details of the person or brand your subscribers expect to receive emails from","mailpoet")]}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsxs)("form",{id:"mailpoet_sender_form",onSubmit:e=>{e.preventDefault(),Tt()("#mailpoet_sender_form").parsley().validate()&&i()},children:[(0,g.jsxs)(Di.Grid.TwoColumns,{children:[(0,g.jsxs)("label",{htmlFor:"senderName",children:[(0,g.jsx)("span",{className:"mailpoet-wizard-label",children:(0,p._x)("From Name","A form field label","mailpoet")}),(0,g.jsx)(o.Input,{isFullWidth:!0,name:"senderName",type:"text",placeholder:"John Doe",value:s?s.name:"","data-parsley-required":!0,onChange:e=>a({name:e.target.value})})]}),(0,g.jsxs)("label",{htmlFor:"senderAddress",children:[(0,g.jsx)("span",{className:"mailpoet-wizard-label",children:(0,p._x)("From Address","A form field label","mailpoet")}),(0,g.jsx)(o.Input,{isFullWidth:!0,name:"senderAddress",type:"text",placeholder:"john@doe.com",value:s?s.address:"","data-parsley-required":!0,"data-parsley-type":"email",onChange:e=>a({address:e.target.value})})]})]}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)(o.Button,{className:"mailpoet-wizard-continue-button",isFullWidth:!0,type:"submit",withSpinner:t,children:(0,p._x)("Continue","A label on a button","mailpoet")}),(0,g.jsx)(o.Button,{href:"#skipStep",isDisabled:t,isFullWidth:!0,onClick:e,variant:"tertiary",children:(0,p._x)("Skip this step","A label on a skip button","mailpoet")})]})]})}Hu.propTypes={illustrationUrl:Rt().string.isRequired,children:Rt().oneOfType([Rt().arrayOf(Rt().node),Rt().node]).isRequired},Gu.displayName="WooCommerceController",Yu.displayName="WelcomeWizardSenderStep";const Ku=e=>null==e;function Zu({loading:e,submitForm:t}){const[a,i]=(0,r.useState)({tracking:void 0,libs3rdParty:void 0}),[s,n]=(0,r.useState)(!1);return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(Kt.D,{level:1,children:(0,p.__)("Confirm privacy and data settings","mailpoet")}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsxs)("form",{onSubmit:function(e){return e.preventDefault(),n(!0),Ku(a.libs3rdParty)||Ku(a.tracking)||t(a.tracking,a.libs3rdParty),!1},children:[(0,g.jsxs)("div",{children:[(0,g.jsxs)("div",{id:"mailpoet-wizard-3rd-party-libs",className:"mailpoet-wizard-woocommerce-option",children:[(0,g.jsxs)("div",{children:[(0,g.jsx)("p",{children:(0,p.__)("Enable modern text fonts in emails and show contextual help articles in MailPoet","mailpoet")}),(0,g.jsx)("div",{className:"mailpoet-wizard-note",children:b()((0,p.__)("MailPoet may load Google Fonts, WordPress.com and other [link]3rd party libraries[/link].","mailpoet"),/\[link\](.*?)\[\/link\]/g,(e,t)=>(0,g.jsx)("a",{href:"https://kb.mailpoet.com/article/338-enabledisable-3rd-party-libraries",target:"_blank",rel:"noopener noreferrer",children:e},t))})]}),(0,g.jsx)("div",{className:"mailpoet-wizard-woocommerce-toggle",children:(0,g.jsx)(qu,{showError:s&&Ku(a.libs3rdParty),onCheck:e=>{const t={libs3rdParty:e};i(e=>({...e,...t}))},checked:a.libs3rdParty,name:"mailpoet_libs_3rdParty"})})]}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsxs)("div",{id:"mailpoet-wizard-tracking",className:"mailpoet-wizard-woocommerce-option",children:[(0,g.jsxs)("div",{children:[(0,g.jsx)("p",{children:(0,p.__)("Help improve MailPoet","mailpoet")}),(0,g.jsx)("div",{className:"mailpoet-wizard-note",children:b()((0,p.__)("Get improved features and fixes faster by sharing with us [link]non-sensitive data about how you use MailPoet[/link]. No personal data is tracked or stored.","mailpoet"),/\[link\](.*?)\[\/link\]/g,(e,t)=>(0,g.jsx)("a",{href:"https://kb.mailpoet.com/article/130-sharing-your-data-with-us",target:"_blank",rel:"noopener noreferrer",children:e},t))})]}),(0,g.jsx)("div",{className:"mailpoet-wizard-woocommerce-toggle",children:(0,g.jsx)(qu,{showError:s&&Ku(a.tracking),onCheck:e=>{const t={tracking:e};i(e=>({...e,...t}))},checked:a.tracking,name:"mailpoet_tracking"})})]})]}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)(Ge.$,{className:"mailpoet-wizard-continue-button",isFullWidth:!0,type:"submit",withSpinner:e,disabled:e,children:(0,p._x)("Continue","A label on a button","mailpoet")})]})]})}Zu.propTypes={loading:Rt().bool.isRequired,submitForm:Rt().func.isRequired},Zu.displayName="WelcomeWizardUsageTrackingStep";var Ju=a(69472);async function Qu(e){await m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"settings",action:"set",data:e}).fail(e=>{e.errors.length>0&&m.U.Notice.showApiErrorNotice(e,{scroll:!0})})}async function Xu(e=null){await Qu({version:window.mailpoet_version,installed_after_new_domain_restrictions:1,welcome_wizard_current_step:""}),window.location.href=e||window.finish_wizard_url}function ep(){const[e,t]=(0,r.useState)(!1),a=e=>{e.preventDefault(),t(!0)},i=()=>t(!1);return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("p",{children:b()(m.U.I18n.t("welcomeWizardMSSAdvancedUsers"),/\[link](.*?)\[\/link]/g,(e,t)=>(0,g.jsx)("a",{onClick:a,href:"#",children:e},t))}),e&&(0,g.jsxs)(Te.A,{className:"mailpoet-welcome-wizard-confirmation-modal",title:m.U.I18n.t("welcomeWizardMSSConfirmationModalTitle"),onRequestClose:i,children:[(0,g.jsx)("p",{children:m.U.mailFunctionEnabled?m.U.I18n.t("welcomeWizardMSSConfirmationModalFirstParagraph"):m.U.I18n.t("welcomeWizardMSSConfirmationModalFirstParagraphWithoutMailFunction")}),(0,g.jsx)("p",{children:m.U.I18n.t("welcomeWizardMSSConfirmationModalSecondParagraph")}),(0,g.jsxs)("div",{className:"mailpoet-welcome-wizard-confirmation-modal-buttons",children:[(0,g.jsx)(o.Button,{variant:"secondary",onClick:i,children:m.U.I18n.t("welcomeWizardMSSConfirmationModalGoBackButton")}),(0,g.jsx)(o.Button,{onClick:async e=>{e.preventDefault(),await Xu("admin.php?page=mailpoet-settings#/mta/other")},children:m.U.I18n.t("welcomeWizardMSSConfirmationModalOkButton")})]})]})]})}const tp=(e,t,a=!1)=>{Qu({welcome_wizard_current_step:t}),a?e(t,{replace:!0}):e(t)},ap="https://account.mailpoet.com/?ref=plugin-wizard&utm_source=plugin&utm_medium=onboarding&utm_campaign=purchase";function ip(){const e=(0,Ue.Zp)(),{step:t}=(0,Ue.g)(),a=(0,$u.d4)("getKeyActivationState");return(0,r.useEffect)(()=>{!0===a.isKeyValid&&tp(e,`/steps/${t}/part/3`,!0)},[a.isKeyValid,e,t]),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(Kt.D,{level:1,children:m.U.I18n.t("welcomeWizardMSSFirstPartTitle")}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)("p",{children:m.U.I18n.t("welcomeWizardMSSFirstPartSubtitle")}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)("div",{className:"mailpoet-welcome-wizard-mss-list",children:(0,g.jsxs)(o.List,{children:[(0,g.jsx)("li",{children:m.U.I18n.t("welcomeWizardMSSList1")}),(0,g.jsx)("li",{children:m.U.I18n.t("welcomeWizardMSSList2")}),m.U.subscribersCount<500?(0,g.jsx)("li",{children:m.U.I18n.t("welcomeWizardMSSList3Free")}):(0,g.jsx)("li",{children:m.U.I18n.t("welcomeWizardMSSList3Paid")})]})}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)(o.Button,{className:"mailpoet-wizard-continue-button",isFullWidth:!0,href:ap,target:"_blank",rel:"noopener noreferrer",onClick:a=>function(e,t,a){e.preventDefault(),window.open(ap),tp(t,`/steps/${a}/part/2`)}(a,e,t),iconEnd:(0,g.jsx)(mi.A,{icon:Ju.A}),children:m.U.I18n.t("welcomeWizardMSSFirstPartButton")}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)(ep,{})]})}var sp=a(39502),np=a(25633);function rp(){const e=(0,Ue.Zp)(),{step:t}=(0,Ue.g)(),a=(0,$u.d4)("getKeyActivationState");return(0,r.useEffect)(()=>{!0===a.isKeyValid&&tp(e,`/steps/${t}/part/3`,!0)},[a.isKeyValid,e,t]),(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(o.Heading,{level:1,children:m.U.I18n.t("welcomeWizardMSSSecondPartTitle")}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)("p",{children:m.U.I18n.t("welcomeWizardMSSSecondPartEnterKey")}),(0,g.jsx)("p",{children:b()(m.U.I18n.t("welcomeWizardMSSSecondPartNoAccount"),/\[link](.*?)\[\/link]/g,(e,t)=>(0,g.jsx)("a",{target:"_blank",rel:"noreferrer",href:"https://account.mailpoet.com/?ref=plugin-wizard&utm_source=plugin&utm_medium=onboarding&utm_campaign=purchase",children:e},t))}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsxs)("label",{htmlFor:"mailpoet_premium_key",children:[(0,g.jsx)("span",{className:"mailpoet-wizard-label",children:m.U.I18n.t("welcomeWizardMSSSecondPartInputLabel")}),(0,g.jsx)(np.M,{placeholder:m.U.I18n.t("welcomeWizardMSSSecondPartInputPlaceholder"),isFullWidth:!0,forceRevealed:!0})]}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)(sp.y,{label:m.U.I18n.t("welcomeWizardMSSSecondPartButton"),isFullWidth:!0}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)(ep,{})]})}function op(){return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(Kt.D,{level:1,children:m.U.I18n.t("welcomeWizardMSSThirdPartTitle")}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)("p",{children:m.U.I18n.t("welcomeWizardMSSThirdPartFirstParagraph")}),(0,g.jsx)("p",{children:m.U.I18n.t("welcomeWizardMSSThirdPartSecondParagraph")}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)(o.Button,{className:"mailpoet-wizard-continue-button",type:"button",onClick:()=>Xu(),isFullWidth:!0,children:m.U.I18n.t("welcomeWizardMSSThirdPartButton")})]})}function lp(){const{pathname:e}=(0,Ue.zy)(),{step:t}=(0,Ue.g)(),a=(0,Ue.Zp)(),i=(0,Ue.zy)();return(0,r.useEffect)(()=>{i.pathname.includes("part")||tp(a,`/steps/${t}/part/1`,!0)},[t,e,a,i]),(0,g.jsxs)(Ue.BV,{children:[(0,g.jsx)(Ue.qh,{path:"part/1",element:(0,g.jsx)(ip,{})}),(0,g.jsx)(Ue.qh,{path:"part/2",element:(0,g.jsx)(rp,{})}),(0,g.jsx)(Ue.qh,{path:"part/3",element:(0,g.jsx)(op,{})})]})}const dp=()=>{const e=["WelcomeWizardSenderStep"];return window.mailpoet_is_dotcom||e.push("WelcomeWizardUsageTrackingStep"),window.mailpoet_woocommerce_active&&e.push("WizardWooCommerceStep"),window.mailpoet_has_valid_api_key||e.push("WelcomeWizardPitchMSSStep"),e},cp=()=>dp().length,mp=async(e,t,a)=>{a<cp()?tp(e,`/steps/${a+1}`):t()};var up=a(87802);function pp(){const e=(0,Ue.g)(),t=(0,Ue.Zp)(),a=cp(),i=parseInt(e.step,10),[s,n]=(0,r.useState)(!1),[l,c]=(0,$u.iK)("sender"),m=(0,$u.iK)("analytics")[1],u=(0,$u.iK)("3rd_party_libs")[1];(0,r.useEffect)(()=>{(i>a||i<1)&&tp(t,"/steps/1")},[i,a,t]);const p=(0,Lt.partial)(mp,t,Xu),h=(0,r.useCallback)(async(e,t)=>{const a={enabled:e?"1":""},i={enabled:t?"1":""},s={analytics:a,"3rd_party_libs":i};await Qu(s),m(a),u(i)},[m,u]),_=(0,r.useCallback)(async(e,t)=>{n(!0),await h(e,t),p(i),n(!1)},[p,i,h]),f=(0,r.useCallback)(e=>{c({...l,...e})},[l,c]),b=(0,r.useCallback)(async()=>{n(!0),window.mailpoet_is_dotcom&&!window.wizard_has_tracking_settings&&await h(!0,!0),await Qu((({name:e,address:t})=>{const a=t.split("@").pop().toLowerCase();return window.mailpoet_free_domains.indexOf(a)>-1?(({name:e,address:t})=>{const a=`wordpress@${window.location.hostname.replace("www.","")}`;return{sender:{name:e,address:a},reply_to:{name:e,address:t},"signup_confirmation.from.address":a,"signup_confirmation.from.name":e,"signup_confirmation.reply_to.address":t,"signup_confirmation.reply_to.name":e}})({name:e,address:t}):(({name:e,address:t})=>({sender:{name:e,address:t},reply_to:{name:e,address:t},"signup_confirmation.from.address":t,"signup_confirmation.from.name":e,"signup_confirmation.reply_to.address":t,"signup_confirmation.reply_to.name":e}))({name:e,address:t})})(l)).then(()=>p(i)),n(!1)},[p,l,i,h]),x=(0,r.useCallback)(async e=>{e.preventDefault(),n(!0),window.mailpoet_is_dotcom&&!window.wizard_has_tracking_settings&&await h(!0,!0),p(i),n(!1)},[p,i,h]),v=(y=i,dp()[y-1]||null);var y;return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(d.V,{hideScreenOptions:!0,logoWithLink:!1,children:(0,g.jsx)(up.g,{count:a,current:i,doneCallback:e=>{tp(t,`/steps/${e}`)}})}),(0,g.jsxs)(Bu,{children:["WelcomeWizardSenderStep"===v?(0,g.jsx)(Hu,{illustrationUrl:window.wizard_sender_illustration_url,children:(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(Yu,{update_sender:f,submit_sender:b,skipStep:x,loading:s,sender:l})})}):null,"WelcomeWizardUsageTrackingStep"===v?(0,g.jsx)(Hu,{illustrationUrl:window.wizard_tracking_illustration_url,children:(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(Zu,{loading:s,submitForm:_})})}):null,"WelcomeWizardPitchMSSStep"===v?(0,g.jsx)(Hu,{illustrationUrl:window.wizard_MSS_pitch_illustration_url,children:(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(lp,{})})}):null,"WizardWooCommerceStep"===v?(0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(Gu,{isWizardStep:!0,redirectToNextStep:()=>p(i)})}):null]})]})}pp.displayName="WelcomeWizardStepsController";const hp=(0,o.withBoundary)(pp),gp=(0,o.withBoundary)(Gu);function _p(){let e="/steps/1";const t=window.mailpoet_welcome_wizard_current_step;"string"==typeof t&&t.startsWith("/steps")&&(e=t),window.location.search.includes("woocommerce-setup")&&(e="/woocommerce");const a=(0,l.f)(window);return(0,g.jsx)(l.F.Provider,{value:a,children:(0,g.jsxs)(Ae.HashRouter,{children:[(0,g.jsx)(u.q,{}),(0,g.jsxs)(Ue.BV,{children:[(0,g.jsx)(Ue.qh,{path:"/steps/:step/*",element:(0,g.jsx)(hp,{})}),(0,g.jsx)(Ue.qh,{path:"/woocommerce",element:(0,g.jsx)(gp,{})}),(0,g.jsx)(Ue.qh,{path:"*",element:(0,g.jsx)(Ue.C5,{to:e})})]})]})})}const fp=document.getElementById("mailpoet-wizard-container");function bp(){const[e,t]=(0,r.useState)(null),a=(0,l.f)(window),i=a.notices.error;function s(s){const n=s.target.name,r=s.target.checked;m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"featureFlags",action:"set",data:{[n]:r?1:0}}).done(()=>{const i=e[n];i.value=r,t({...e,[n]:i});const s=`Feature '${n}' was ${r?"enabled":"disabled"}.`;a.notices.success((0,g.jsx)("p",{children:s}))}).fail(e=>{e&&e.errors&&e.errors.length&&(JSON.stringify(e.errors).includes("reinstall_plugin")?m.U.Notice.showApiErrorNotice(e):i(e.errors.map(e=>(0,g.jsx)("p",{children:e.message},e.message)),{scroll:!0}))})}return(0,r.useEffect)(()=>{m.U.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"featureFlags",action:"getAll"}).done(e=>{const a=e.data.reduce((e,t)=>({...e,[t.name]:t}),{});t(a)}).fail(e=>{e&&e.errors&&e.errors.length&&(JSON.stringify(e.errors).includes("reinstall_plugin")?m.U.Notice.showApiErrorNotice(e):i((0,g.jsx)(g.Fragment,{children:e.errors.map(e=>(0,g.jsx)("p",{children:e.message}))}),{scroll:!0}))})},[i]),null===e?(0,g.jsx)("p",{children:"Loading experimental features..."}):0===Object.values(e).length?(0,g.jsx)("p",{children:"There are no experimental features at the moment."}):(0,g.jsx)(l.F.Provider,{value:a,children:(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(u.q,{}),Object.values(e).map(e=>{const t=`experimental-feature-${e.name}`;return(0,g.jsx)("div",{children:(0,g.jsxs)("label",{htmlFor:t,children:[(0,g.jsx)("input",{id:t,type:"checkbox",name:e.name,defaultChecked:e.value,onChange:s})," ",e.name]})},e.name)})]})})}fp&&((0,o.registerTranslations)(),(0,Lu.k)(),(0,n.H)(fp).render((0,g.jsx)(_p,{})));const xp=document.getElementById("experimental_features_container");bp.displayName="ExperimentalFeatures",xp&&((0,o.registerTranslations)(),(0,n.H)(xp).render((0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(bp,{})})));let vp=!1;function yp(){if(vp)return;const e=window.mailpoet_logs_api;tl.default.use(tl.default.createRootURLMiddleware(`${e.root}/`)),tl.default.use(tl.default.createNonceMiddleware(e.nonce)),vp=!0}function wp({count:e,filter:t,search:a,isUnrestricted:i,onClose:s,onDeleted:n}){const[l,d]=(0,r.useState)(!1),[c,m]=(0,r.useState)(null),u=e.toLocaleString(),h=i?(0,p.sprintf)((0,p._n)("This permanently deletes the only log. This cannot be undone.","This permanently deletes all %s logs. This cannot be undone.",e,"mailpoet"),u):(0,p.sprintf)((0,p._n)("This permanently deletes %s log matching the current filters. This cannot be undone.","This permanently deletes %s logs matching the current filters. This cannot be undone.",e,"mailpoet"),u),_=(0,r.useCallback)(async()=>{d(!0),m(null);try{const e=await async function(e,t,a){return yp(),(await(0,tl.default)({path:"/mailpoet/v1/logs/delete",method:"POST",data:{filter:e,search:t?.trim()||void 0,all:a}})).data.deleted}(t,a,i);n(e),s()}catch(e){m(function(e){return"object"==typeof e&&null!==e&&"message"in e&&"string"==typeof e.message?e.message:(0,p.__)("Something went wrong. Please try again.","mailpoet")}(e)),d(!1)}},[t,a,i,s,n]);return(0,g.jsxs)(Te.A,{className:"mailpoet-logs-delete-modal",title:(0,p.__)("Delete logs","mailpoet"),onRequestClose:s,isDismissible:!l,children:[c&&(0,g.jsx)(Fe.A,{status:"error",isDismissible:!1,children:c}),(0,g.jsx)("p",{children:h}),(0,g.jsxs)("div",{className:"mailpoet-logs-delete-modal__actions",children:[(0,g.jsx)(o.Button,{dimension:"small",variant:"secondary",onClick:s,isDisabled:l,children:(0,p.__)("Cancel","mailpoet")}),(0,g.jsx)(o.Button,{dimension:"small",variant:"destructive",onClick:_,isDisabled:l,withSpinner:l,children:(0,p.sprintf)((0,p._n)("Delete %s log","Delete %s logs",e,"mailpoet"),u)})]})]})}function jp({count:e,filter:t,search:a,isUnrestricted:i,downloadConfig:s,onClose:n}){const l=e.toLocaleString(),d=i?(0,p.sprintf)((0,p._n)("This downloads the only log as a .txt file.","This downloads all %s logs as a .txt file.",e,"mailpoet"),l):(0,p.sprintf)((0,p._n)("This downloads %s log matching the current filters as a .txt file.","This downloads %s logs matching the current filters as a .txt file.",e,"mailpoet"),l),c=(0,r.useCallback)(()=>{window.location.assign(function(e,t,a){const i=new URLSearchParams({action:"mailpoet_download_logs",_wpnonce:e.nonce});return t.from&&i.set("from",t.from),t.to&&i.set("to",t.to),(t.name??[]).forEach(e=>i.append("name[]",e)),(t.level??[]).forEach(e=>i.append("level[]",String(e))),a&&i.set("search",a),`${e.action_url}?${i.toString()}`}(s,t,a)),n()},[s,t,a,n]);return(0,g.jsxs)(Te.A,{className:"mailpoet-logs-download-modal",title:(0,p.__)("Download logs","mailpoet"),onRequestClose:n,children:[e>5e4&&(0,g.jsx)(Fe.A,{status:"warning",isDismissible:!1,children:(0,p.sprintf)((0,p.__)("Only the most recent %s logs will be downloaded.","mailpoet"),5e4.toLocaleString())}),(0,g.jsx)("p",{children:d}),(0,g.jsxs)("div",{className:"mailpoet-logs-download-modal__actions",children:[(0,g.jsx)(o.Button,{dimension:"small",variant:"secondary",onClick:n,children:(0,p.__)("Cancel","mailpoet")}),(0,g.jsx)(o.Button,{dimension:"small",onClick:c,children:(0,p.sprintf)((0,p._n)("Download %s log","Download %s logs",e,"mailpoet"),l)})]})]})}const Sp="created_at",kp="name",Np="level",Cp={100:(0,p.__)("Debug","mailpoet"),200:(0,p.__)("Info","mailpoet"),250:(0,p.__)("Notice","mailpoet"),300:(0,p.__)("Warning","mailpoet"),400:(0,p.__)("Error","mailpoet"),500:(0,p.__)("Critical","mailpoet"),550:(0,p.__)("Alert","mailpoet"),600:(0,p.__)("Emergency","mailpoet")};function Ep(){const e=window.mailpoet_logs_filter_options;return{names:Array.isArray(e?.names)?e.names:[]}}function Ip(e){const t={};return(e??[]).forEach(e=>{if(e.field===Sp)Object.assign(t,(0,$e._O)(e.operator,e.value));else if(e.field===kp){const i=(a=e.value,Array.isArray(a)?a.map(e=>String(e).trim()).filter(e=>""!==e):[]);i.length>0&&(t.name=i)}else if(e.field===Np){const a=function(e){return Array.isArray(e)?e.map(e=>Number(e)).filter(e=>Number.isInteger(e)):[]}(e.value);a.length>0&&(t.level=a)}var a}),t}function Ap(e){const t=[],a=(i=e.from,s=e.to,i&&s?i===s?{field:Sp,operator:"on",value:i}:{field:Sp,operator:"between",value:[i,s]}:i?{field:Sp,operator:"afterInc",value:i}:s?{field:Sp,operator:"beforeInc",value:s}:null);var i,s;return a&&t.push(a),e.name&&e.name.length>0&&t.push({field:kp,operator:"isAny",value:e.name}),e.level&&e.level.length>0&&t.push({field:Np,operator:"isAny",value:e.level}),t}function Up(e,t=Ep()){return[{id:"name",label:(0,p.__)("Name","mailpoet"),type:"text",enableSorting:!0,enableGlobalSearch:!1,elements:t.names.map(e=>({value:e,label:e})),filterBy:{operators:["isAny"]},render:({item:e})=>(0,r.createElement)("span",{className:"mailpoet-logs-min-width"},e.name)},{id:"level",label:(0,p.__)("Severity","mailpoet"),type:"text",enableSorting:!1,enableGlobalSearch:!1,elements:Object.keys(Cp).map(e=>({value:Number(e),label:Cp[Number(e)]})),filterBy:{operators:["isAny"]},render:({item:e})=>{return(0,r.createElement)("span",null,null===e.level?"—":(t=e.level,Cp[t]??String(t)));var t}},{id:"message",label:(0,p.__)("Message","mailpoet"),type:"text",enableSorting:!1,enableGlobalSearch:!1,filterBy:!1,render:({item:t})=>{const a=e.has(t.id);return(0,r.createElement)("pre",{id:`mailpoet-log-message-${t.id}`,className:"mailpoet-logs-message "+(a?"mailpoet-logs-message-full":"")},t.message)}},{id:"created_at",label:(0,p.__)("Created On","mailpoet"),type:"date",enableSorting:!0,enableGlobalSearch:!1,filterBy:{operators:["on","beforeInc","afterInc","between"]},render:({item:e})=>{return(0,r.createElement)("span",{className:"mailpoet-logs-min-width"},(t=e.created_at)?Rl.s.full(t):"—");var t}}]}const Tp=new Set;function Pp(e){if(!e)return;const t=Number(e);return!Number.isInteger(t)||t<1?void 0:t}function Rp(e){return e?Math.min(e,100):20}function Dp(e){const t=e.get("search")?.trim();return t||void 0}function Fp(e,t){const a=e.get("from"),i=e.get("to"),s={};(0,$e.bx)(a)?s.from=a??void 0:(0,$e.bx)(t)&&(s.from=t),(0,$e.bx)(i)&&(s.to=i??void 0);const n=function(e){const t=e.getAll("log_name").map(e=>e.trim()).filter(e=>""!==e);return t.length>0?t:void 0}(e);n&&(s.name=n);const r=function(e){const t=e.getAll("log_level").map(e=>Number(e)).filter(e=>Number.isInteger(e));return t.length>0?t:void 0}(e);return r&&(s.level=r),s}function Op(e,t){const a=Pp(e.get("logs_page"));if(a)return a;const i=function(e){if(null===e||""===e.trim())return;const t=Number(e);return!Number.isInteger(t)||t<0?void 0:t}(e.get("offset"));return void 0!==i?Math.floor(i/t)+1:1}function Mp(e){return e.from&&e.to&&e.from>e.to?(0,p.__)("The start date must be before or equal to the end date.","mailpoet"):null}const Lp={type:"table",perPage:20,page:1,sort:{field:"created_at",direction:"desc"},fields:["message","created_at"],titleField:"name",showTitle:!0};function $p(e){const t=window.location.href,a=function(e,t){const a=new URL(e).searchParams,i=function(e){return Rp(Pp(e.get("per_page"))||Pp(e.get("limit")))}(a);return{page:Op(a,i),perPage:i,search:Dp(a),filters:Fp(a,t)}}(t,e),i=new URL(t).searchParams,s=i.has("per_page")||i.has("limit"),n=(0,$e.Aq)("logs",Lp,function(e=Ep()){return Up(Tp,e)}());return{...n,page:a.page,perPage:s?a.perPage:n.perPage,search:a.search,filters:Ap(a.filters)}}function Bp({defaultFrom:e,downloadConfig:t}){const a=(0,r.useMemo)(()=>$p(e),[e]),[i,s]=(0,r.useState)(()=>new Set),[n,l]=(0,r.useState)(!1),[d,c]=(0,r.useState)(!1),[m,u]=(0,r.useState)(null),h=(0,r.useRef)(!1),_=(0,r.useCallback)((e,t)=>Mp(e.filter??{})?Promise.resolve({items:[],meta:{count:0,pages:0}}):async function(e,t){return yp(),(await(0,tl.default)({path:(0,al.F)("/mailpoet/v1/logs",e),method:"GET",signal:t})).data}({...e,search:e.search?.trim()||void 0},t),[]),{view:f,items:b,meta:x,isLoading:v,error:y,onChangeView:w,clearError:j,refresh:S}=(0,$e.i7)({initialView:a,load:_,extraParams:e=>(0,$e.Y4)(Ip(e.filters))}),k=Ip(f.filters),N=Mp(k),C=y||N?null:(0,g.jsx)("div",{children:(0,p.__)("No logs found.","mailpoet")}),E=f.search?.trim()||void 0,I=0===Object.keys(k).length&&!E,A=!v&&!N&&x.count>0,U=A,T=(0,$e.wh)("logs",f,w);(0,r.useEffect)(()=>{if(!h.current)return void(h.current=!0);const e=function(e,t,a){const i=new URL(e),s=t.search?.trim();return i.searchParams.set("page","mailpoet-logs"),i.searchParams.delete("offset"),i.searchParams.delete("limit"),i.searchParams.delete("search"),i.searchParams.delete("from"),i.searchParams.delete("to"),i.searchParams.delete("log_name"),i.searchParams.delete("log_level"),s&&i.searchParams.set("search",s),a.from&&i.searchParams.set("from",a.from),a.to&&i.searchParams.set("to",a.to),(a.name??[]).forEach(e=>{i.searchParams.append("log_name",e)}),(a.level??[]).forEach(e=>{i.searchParams.append("log_level",String(e))}),i.searchParams.set("logs_page",String(t.page??1)),i.searchParams.set("per_page",String(Rp(t.perPage??20))),i.href}(window.location.href,f,Ip(f.filters));window.history.replaceState({},"",e)},[f]);const P=function(e){return JSON.stringify(e.filters??[])}(f);(0,r.useEffect)(()=>{s(e=>e.size>0?new Set:e)},[P,f.page,f.perPage,f.search]);const R=(0,r.useCallback)(e=>{s(t=>{const a=new Set(t);return a.has(e)?a.delete(e):a.add(e),a})},[]),D=(0,r.useMemo)(()=>Up(i,Ep()),[i]),F=(0,r.useMemo)(()=>function(e,t){return[{id:"toggle-message",isPrimary:!0,label:t=>t[0]&&e.has(t[0].id)?(0,p.__)("Show less","mailpoet"):(0,p.__)("Show more","mailpoet"),callback:e=>{const a=e[0];a&&t(a.id)}}]}(i,R),[i,R]),O=(0,r.useMemo)(()=>({totalItems:x.count,totalPages:x.pages}),[x]),M=(0,r.useCallback)(()=>{j(),S()},[j,S]),L=(0,r.useCallback)(e=>{u((0,p.sprintf)((0,p._n)("%s log deleted.","%s logs deleted.",e,"mailpoet"),e.toLocaleString())),S()},[S]);return(0,g.jsxs)("div",{className:"mailpoet-listing mailpoet-logs mailpoet-dataviews mailpoet-logs-dataviews",children:[m&&(0,g.jsx)(Fe.A,{status:"success",onRemove:()=>u(null),children:m}),y&&(0,g.jsx)(Fe.A,{status:"error",isDismissible:!1,children:(0,g.jsxs)("div",{className:"mailpoet-logs-error",children:[(0,g.jsx)("span",{children:(0,p.__)("Logs could not be loaded.","mailpoet")}),(0,g.jsx)(o.Button,{dimension:"small",variant:"secondary",onClick:M,isDisabled:v,children:(0,p.__)("Retry","mailpoet")})]})}),N&&(0,g.jsx)(Fe.A,{status:"error",isDismissible:!1,children:(0,g.jsx)("div",{className:"mailpoet-logs-date-error",role:"alert",children:N})}),(0,g.jsxs)(Le.A,{data:b,fields:D,actions:F,view:f,onChangeView:T,paginationInfo:O,defaultLayouts:{table:{}},getItemId:e=>String(e.id),isLoading:v,empty:C,children:[(0,g.jsxs)("div",{className:"mailpoet-logs-dataviews__toolbar",children:[(0,g.jsx)(Le.A.Search,{label:(0,p.__)("Search logs","mailpoet")}),(0,g.jsx)(Le.A.FiltersToggle,{}),(0,g.jsxs)("div",{className:"mailpoet-dataviews__toolbar-end",children:[(0,g.jsx)(o.Button,{dimension:"small",variant:"destructive",onClick:()=>l(!0),isDisabled:!A,children:(0,p.__)("Delete logs...","mailpoet")}),t&&(0,g.jsx)(o.Button,{dimension:"small",variant:"tertiary",onClick:()=>c(!0),isDisabled:!U,children:(0,p.__)("Download...","mailpoet")}),(0,g.jsx)(Le.A.ViewConfig,{})]})]}),(0,g.jsx)(Le.A.Filters,{}),(0,g.jsx)(Le.A.Layout,{}),(0,g.jsx)(Le.A.Footer,{})]}),n&&(0,g.jsx)(wp,{count:x.count,filter:k,search:E,isUnrestricted:I,onClose:()=>l(!1),onDeleted:L}),d&&t&&(0,g.jsx)(jp,{count:x.count,filter:k,search:E,isUnrestricted:I,downloadConfig:t,onClose:()=>c(!1)})]})}Bp.displayName="LogsList";const Wp=document.getElementById("mailpoet_logs_container");Wp&&(0,n.H)(Wp).render((0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(Bp,{defaultFrom:window.mailpoet_logs_default_from,downloadConfig:window.mailpoet_logs_download})}));var Vp=a(91593);function qp({onRequestClose:e=Jt.noop}){const[t,a]=(0,r.useState)(!1);return Tt()(e=>{e(document).on("click",".notice .mailpoet-js-button-fix-this",()=>{a(!0)})}),(0,g.jsxs)(l.F.Provider,{value:(0,l.f)(window),children:[(0,g.jsx)(u.q,{}),t&&(0,g.jsx)(Vp.U,{onRequestClose:()=>{a(!1),e()}})]})}const zp=document.getElementById("mailpoet_set_from_address_modal");zp&&(0,n.H)(zp).render((0,g.jsx)(qp,{onRequestClose:()=>{window.location.href.includes("?page=mailpoet-settings")&&window.location.reload()}}));const Hp=e=>(async e=>{if("MailPoet"!==m.U.mtaMethod)return!0;if(window.mailpoet_sender_restrictions?.skipAuthorization)return!0;const t=await(async()=>"MailPoet"!==m.U.mtaMethod?[]:(await m.U.Ajax.post({api_version:m.U.apiVersion,endpoint:"mailer",action:"getVerifiedSenderDomains"})).data||[])(),a=(0,ts.Y8)(e);return-1!==t.indexOf(a)||-1!==(await(async()=>"MailPoet"!==m.U.mtaMethod?[]:(await m.U.Ajax.post({api_version:m.U.apiVersion,endpoint:"mailer",action:"getAuthorizedEmailAddresses"})).data||[])()).indexOf(e)})(e).then(e=>{if(!e)return m.U.Notice.error((0,p.__)("Failed to resume sending because the email address is unauthorized. Please authorize it and try again.","mailpoet"),{scroll:!0}),m.U.trackEvent("Unauthorized email used",{"Unauthorized email source":"send"}),!1;m.U.Ajax.post({api_version:m.U.apiVersion,endpoint:"mailer",action:"resumeSending"}).done(()=>{m.U.Notice.success((0,p.__)("Sending has been resumed.","mailpoet"))}).fail(e=>{e.errors.length>0&&m.U.Notice.showApiErrorNotice(e,{scroll:!0})})});Tt()(e=>{e(document).on("click",".notice .mailpoet-js-button-resume-sending",e=>{Hp(e.target.value)})});var Gp=a(95973);const Yp=e=>{const t=window.location.href.includes("?page=mailpoet-settings"),a=window.location.href.includes("?page=mailpoet-newsletters#/send");(e=>{const t=`${(0,ts.no)()||"some other"} page`;e&&e.type&&"email"===e.type?m.U.trackEvent("MSS in plugin authorize email",{"authorized email source":"modal","original page":t,wasSuccessful:"yes"}):e&&e.type&&"domain"===e.type&&m.U.trackEvent("MSS in plugin verify sender domain",{"verify sender domain source":"modal","original page":t,wasSuccessful:"yes"})})(e),(t||a)&&window.location.reload()};function Kp(){const[e,t]=(0,r.useState)(""),[a,i]=(0,r.useState)("email");return(0,r.useEffect)(()=>{const e=e=>{e.preventDefault();const a=String(e?.target?.dataset?.email||""),s=String(e?.target?.dataset?.type||"");i(s||"email"),t(a)};Tt()(t=>{t(document).on("click",".mailpoet-js-button-authorize-email-and-sender-domain",e)})},[]),(0,g.jsx)(g.Fragment,{children:e&&(0,g.jsx)(Gp.J,{senderEmail:e,onRequestClose:()=>{t("")},onSuccessAction:Yp,showSenderEmailTab:"email"===a,showSenderDomainTab:"domain"===a,initialTab:"domain"===a?"sender_domain":"sender_email"})})}const Zp=document.getElementById("mailpoet_authorize_sender_email_modal");function Jp({color:e}){return(0,g.jsx)("style",{dangerouslySetInnerHTML:{__html:`body { background: ${e}; }`}})}Zp&&(0,n.H)(Zp).render((0,g.jsx)(Kp,{}));const Qp=()=>{window.location.href=window.mailpoet_welcome_wizard_url};function Xp(){const e=window.mailpoet_welcome_wizard_current_step,t="string"==typeof e&&e.startsWith("/steps");return(0,g.jsx)(o.Button,{onClick:Qp,dimension:"hero",children:t?(0,p.__)("Continue setup","mailpoet"):(0,p.__)("Begin setup","mailpoet")})}function eh(){return(0,g.jsx)("section",{className:"landing-header",children:(0,g.jsxs)("div",{className:"mailpoet-content-center",children:[(0,g.jsx)(Kt.D,{level:0,children:(0,p.__)("Better email — without leaving WordPress","mailpoet")}),(0,g.jsx)("p",{children:(0,p.__)("Whether you’re just starting out or have already established your business, we’ve got the tools you need to reach customers where they are.","mailpoet")}),(0,g.jsx)(Xp,{})]})})}function th(){return(0,g.jsx)("section",{className:"landing-footer",children:(0,g.jsxs)("div",{className:"landing-footer-content mailpoet-content-center",children:[(0,g.jsxs)(Kt.D,{level:4,children:[" ",(0,p.__)("Ready to start using MailPoet?","mailpoet")," "]}),(0,g.jsx)(Xp,{})]})})}function ah(){const e=[{slug:"item-1",title:(0,p.__)("What types of campaigns can I create with MailPoet?","mailpoet"),text:(0,p.__)("MailPoet allows you to create five different types of campaigns: Newsletter, Welcome Email, Latest Post Notifications, Re-engagement Emails, and WooCommerce behavior-based emails.","mailpoet"),readMoreText:(0,p.__)("Read More","mailpoet"),readMoreLink:"https://kb.mailpoet.com/article/141-create-an-email-types-of-campaigns"},{slug:"item-2",title:(0,p.__)("How do I send a newsletter?","mailpoet"),text:(0,p.__)("You can manually create a standard newsletter to be sent immediately or scheduled to be sent at a later time. Simply go to MailPoet > Emails and click on the “+ New Email” button to select “Newsletter”.","mailpoet"),readMoreText:(0,p.__)("Read More","mailpoet"),readMoreLink:"https://kb.mailpoet.com/article/344-create-a-standard-newsletter"},{slug:"item-3",title:(0,p.__)("Do I need a paid plan?","mailpoet"),text:(0,p.__)("When you install the MailPoet plugin, you can use it for free up to 1,000 subscribers. If you have more than 1,000 subscribers, or want access to MailPoet’s advanced features, you'll need one of our paid plans: Creator, Business, or Agency. The best choice of plan type will depend on whether you want to send with our MailPoet Sending Service or your own sending method, as well as the number of sites you will be using MailPoet on.","mailpoet"),readMoreText:(0,p.__)("Read More","mailpoet"),readMoreLink:"https://kb.mailpoet.com/article/349-mailpoet-plans-and-limits-explained"},{slug:"item-4",title:(0,p.__)("How do I import my customers from WooCommerce?","mailpoet"),text:(0,p.__)('The WooCommerce Customers list is a list automatically created by MailPoet with all of your WooCommerce customers. It also includes “Guest" customers. If WooCommerce is active, users that installed or updated the plugin should have chosen if they wanted to add the customers as “Subscribed” or “Unsubscribed” to the WooCommerce Customers list.',"mailpoet"),readMoreText:(0,p.__)("Read More","mailpoet"),readMoreLink:"https://kb.mailpoet.com/article/284-import-old-customers-to-the-woocommerce-customers-list"},{slug:"item-5",title:(0,p.__)("How do I customize emails for my store?","mailpoet"),text:(0,p.__)("You can create and send the following four WooCommerce Automatic emails with MailPoet: Abandoned Shopping Cart, First Purchase, Purchased In This Category, Purchased This Product. You can read more about each in our article.","mailpoet"),readMoreText:(0,p.__)("Read More","mailpoet"),readMoreLink:"https://kb.mailpoet.com/article/277-woocommerce-automatic-emails"}];return(0,g.jsxs)("section",{className:"landing-faq",children:[(0,g.jsxs)("div",{className:"mailpoet-content-center landing-faq-header",children:[(0,g.jsxs)(Kt.D,{level:2,children:[" ",(0,p.__)("Frequently asked questions","mailpoet")," "]}),(0,g.jsx)("p",{children:b()((0,p.__)("Here are some common questions on getting started. Can't find what you're looking for? [link]View all resources[/link]","mailpoet"),/\[link\](.*?)\[\/link\]/,e=>(0,g.jsx)("a",{href:"https://kb.mailpoet.com/",rel:"noopener noreferrer",target:"_blank",children:e},e))})]}),(0,g.jsx)("div",{className:"mailpoet-content-center landing-faq-mobile",children:(0,g.jsx)(Kt.D,{level:2,children:(0,p.__)("FAQ","mailpoet")})}),(0,g.jsx)("div",{className:"mailpoet-faq-accordion",children:e.map(e=>(0,g.jsxs)("details",{children:[(0,g.jsxs)("summary",{children:[" ",(0,g.jsxs)("strong",{children:[" ",e.title," "]})," "]}),(0,g.jsxs)("div",{className:"content",children:[(0,g.jsx)("p",{children:e.text}),(0,g.jsx)("p",{children:(0,g.jsx)("a",{href:e.readMoreLink,rel:"noopener noreferrer",target:"_blank",children:e.readMoreText})})]})]},e.slug))}),(0,g.jsxs)("div",{className:"mailpoet-content-center landing-faq-mobile",children:[(0,g.jsx)("p",{children:(0,p.__)("Can’t find what you’re looking for?","mailpoet")}),(0,g.jsx)("p",{children:b()((0,p.__)("[link]View all resources[/link]","mailpoet"),/\[link\](.*?)\[\/link\]/,e=>(0,g.jsx)("a",{href:"https://kb.mailpoet.com/",rel:"noopener noreferrer",target:"_blank",children:e},e))})]})]})}eh.displayName="Landingpage Header",th.displayName="Landingpage Footer",ah.displayName="Landingpage FAQ";const ih={heroImage:`${m.U.cdnUrl}landingpage/landingpage-hero-image.png`,featureImages:{icon_1:`${m.U.cdnUrl}landingpage/feature_icon_1.png`,icon_2:`${m.U.cdnUrl}landingpage/feature_icon_2.png`,icon_3:`${m.U.cdnUrl}landingpage/feature_icon_3.png`,icon_4:`${m.U.cdnUrl}landingpage/feature_icon_4.png`},wooCommerceFeatureImages:{feature_1:`${m.U.cdnUrl}landingpage/woo_feature_automate_your_marketing.20241219.png`,feature_2:`${m.U.cdnUrl}landingpage/woo_feature_measure_revenue_per_email.png`,feature_3:`${m.U.cdnUrl}landingpage/woo_feature_let_your_brand_shine.png`,feature_4:`${m.U.cdnUrl}landingpage/woo_feature_rescue_abandoned_carts.png`}};function sh(){return(0,g.jsxs)("section",{className:"landing-content",children:[(0,g.jsxs)("div",{className:"hero-section mailpoet-content-center",children:[(0,g.jsx)("img",{src:ih.heroImage,alt:"",className:"hero-image landingpage-images"}),(0,g.jsx)("br",{}),(0,g.jsx)("br",{}),(0,g.jsx)(Kt.D,{level:4,children:(0,p.sprintf)((0,p.__)("Powerful email marketing, trusted by %s websites","mailpoet"),"600,000+")}),(0,g.jsx)("br",{}),(0,g.jsxs)(Di.Grid.FourColumns,{className:"landingpage-general-features",children:[(0,g.jsxs)("div",{children:[(0,g.jsx)("img",{src:ih.featureImages.icon_1,alt:"",className:"landingpage-feature-icon"}),(0,g.jsx)("strong",{children:(0,p.__)("Deliver beautiful emails","mailpoet")}),(0,g.jsx)("p",{children:(0,p.__)("Choose from our pre-built templates or create your own with our drag-and-drop email builder.","mailpoet")})]}),(0,g.jsxs)("div",{children:[(0,g.jsx)("img",{src:ih.featureImages.icon_2,alt:"",className:"landingpage-feature-icon"}),(0,g.jsx)("strong",{children:(0,p.__)("Grow your mailing list","mailpoet")}),(0,g.jsx)("p",{children:(0,p.__)("Use our custom sign-up forms to reach more subscribers while you deliver engaging content.","mailpoet")})]}),(0,g.jsxs)("div",{children:[(0,g.jsx)("img",{src:ih.featureImages.icon_3,alt:"",className:"landingpage-feature-icon"}),(0,g.jsx)("strong",{children:(0,p.__)("Reach the right people","mailpoet")}),(0,g.jsx)("p",{children:(0,p.__)("From the first hello to repeated purchases, send emails to the right people at the right time.","mailpoet")})]}),(0,g.jsxs)("div",{children:[(0,g.jsx)("img",{src:ih.featureImages.icon_4,alt:"",className:"landingpage-feature-icon"}),(0,g.jsx)("strong",{children:(0,p.__)("Save time with automations","mailpoet")}),(0,g.jsx)("p",{children:(0,p.__)("Set up smart triggers based on user behavior to automate list management, email sending, and more.","mailpoet")})]})]})]}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsxs)("div",{className:"landingpage-wooCommerce-features",children:[(0,g.jsxs)("div",{className:"mailpoet-content-center",children:[(0,g.jsx)(Kt.D,{level:2,children:(0,p.__)("MailPoet + WooCommerce","mailpoet")}),(0,g.jsx)("p",{children:(0,p.__)("Deliver hyper-relevant content at every stage of your customer’s journey","mailpoet")})]}),(0,g.jsx)("br",{}),(0,g.jsxs)(Di.Grid.TwoColumns,{className:"landingpage-wooCommerce-feature-item",children:[(0,g.jsx)("div",{children:(0,g.jsx)("img",{src:ih.wooCommerceFeatureImages.feature_1,alt:(0,p.__)("Automate customer communication feature Image","mailpoet"),className:"landingpage-images"})}),(0,g.jsxs)("div",{children:[(0,g.jsx)("strong",{children:(0,p.__)("Automate customer communication","mailpoet")}),(0,g.jsx)("p",{children:(0,p.__)("Drive sales and build loyalty through automated marketing messages that respond to your customer’s purchase data.","mailpoet")})]})]}),(0,g.jsxs)(Di.Grid.TwoColumns,{className:"landingpage-wooCommerce-feature-item",children:[(0,g.jsx)("div",{children:(0,g.jsx)("img",{src:ih.wooCommerceFeatureImages.feature_2,alt:(0,p.__)("Measure revenue per email feature Image","mailpoet"),className:"landingpage-images"})}),(0,g.jsxs)("div",{children:[(0,g.jsx)("strong",{children:(0,p.__)("Measure revenue per email","mailpoet")}),(0,g.jsx)("p",{children:(0,p.__)("See how much revenue your campaign is bringing and make improvements based on auto-generated email statistics.","mailpoet")})]})]}),(0,g.jsxs)(Di.Grid.TwoColumns,{className:"landingpage-wooCommerce-feature-item",children:[(0,g.jsx)("div",{children:(0,g.jsx)("img",{src:ih.wooCommerceFeatureImages.feature_3,alt:(0,p.__)("Let your brand shine feature Image","mailpoet"),className:"landingpage-images"})}),(0,g.jsxs)("div",{children:[(0,g.jsx)("strong",{children:(0,p.__)("Let your brand shine","mailpoet")}),(0,g.jsx)("p",{children:(0,p.__)("Use our inbuilt WooCommerce email customizer to design your store's transactional emails and build customer confidence.","mailpoet")})]})]}),(0,g.jsxs)(Di.Grid.TwoColumns,{className:"landingpage-wooCommerce-feature-item",children:[(0,g.jsx)("div",{children:(0,g.jsx)("img",{src:ih.wooCommerceFeatureImages.feature_4,alt:(0,p.__)("Rescue abandoned carts feature Image","mailpoet"),className:"landingpage-images"})}),(0,g.jsxs)("div",{children:[(0,g.jsx)("strong",{children:(0,p.__)("Rescue abandoned carts","mailpoet")}),(0,g.jsx)("p",{children:(0,p.__)("Set up automated abandoned cart emails to win customers back and recover lost revenue.","mailpoet")})]})]})]})]})}function nh(){return(0,g.jsx)(l.F.Provider,{value:(0,l.f)(window),children:(0,g.jsxs)("main",{children:[(0,g.jsx)(d.x,{hideScreenOptions:!0}),(0,g.jsx)(Jp,{color:"#fff"}),(0,g.jsx)(eh,{}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)(sh,{}),(0,g.jsx)("div",{className:"mailpoet-gap"}),(0,g.jsx)(ah,{}),(0,g.jsx)(th,{})]})})}sh.displayName="Landingpage Content",nh.displayName="Landingpage";const rh=document.getElementById("mailpoet_landingpage_container");rh&&((0,o.registerTranslations)(),(0,n.H)(rh).render((0,g.jsx)(o.ErrorBoundary,{children:(0,g.jsx)(nh,{})}))),a(74262)},74262(){document.addEventListener("DOMContentLoaded",function(){window.mailpoet_track_wizard_loaded_via_woocommerce&&(window.MailPoet.trackEvent("User opened the MailPoet setup task in WooCommerce > Home",{"WooCommerce version":window.mailpoet_woocommerce_version}),window.MailPoet.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"settings",action:"delete",data:"send_event_that_wizard_was_loaded_via_woocommerce"})),window.mailpoet_track_wizard_loaded_via_woocommerce_marketing_dashboard&&(window.MailPoet.trackEvent("User clicked on complete MailPoet setup in WooCommerce > Multichannel Marketing dashboard",{"WooCommerce version":window.mailpoet_woocommerce_version}),window.MailPoet.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"settings",action:"delete",data:"wizard_loaded_via_woocommerce_marketing_dashboard"}))})},87714(e,t){var a,i;a=function e(){"use strict";var t="undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0!==t?t:{},a=!t.document&&!!t.postMessage,i=t.IS_PAPA_WORKER||!1,s={},n=0,r={parse:function(a,i){var o=(i=i||{}).dynamicTyping||!1;if(y(o)&&(i.dynamicTypingFunction=o,o={}),i.dynamicTyping=o,i.transform=!!y(i.transform)&&i.transform,i.worker&&r.WORKERS_SUPPORTED){var l=function(){if(!r.WORKERS_SUPPORTED)return!1;var a,i,o=(a=t.URL||t.webkitURL||null,i=e.toString(),r.BLOB_URL||(r.BLOB_URL=a.createObjectURL(new Blob(["var global = (function() { if (typeof self !== 'undefined') { return self; } if (typeof window !== 'undefined') { return window; } if (typeof global !== 'undefined') { return global; } return {}; })(); global.IS_PAPA_WORKER=true; ","(",i,")();"],{type:"text/javascript"})))),l=new t.Worker(o);return l.onmessage=_,l.id=n++,s[l.id]=l}();return l.userStep=i.step,l.userChunk=i.chunk,l.userComplete=i.complete,l.userError=i.error,i.step=y(i.step),i.chunk=y(i.chunk),i.complete=y(i.complete),i.error=y(i.error),delete i.worker,void l.postMessage({input:a,config:i,workerId:l.id})}var p=null;return r.NODE_STREAM_INPUT,"string"==typeof a?(a=function(e){return 65279===e.charCodeAt(0)?e.slice(1):e}(a),p=i.download?new d(i):new m(i)):!0===a.readable&&y(a.read)&&y(a.on)?p=new u(i):(t.File&&a instanceof File||a instanceof Object)&&(p=new c(i)),p.stream(a)},unparse:function(e,t){var a=!1,i=!0,s=",",n="\r\n",o='"',l=o+o,d=!1,c=null,m=!1;!function(){if("object"==typeof t){if("string"!=typeof t.delimiter||r.BAD_DELIMITERS.filter(function(e){return-1!==t.delimiter.indexOf(e)}).length||(s=t.delimiter),("boolean"==typeof t.quotes||"function"==typeof t.quotes||Array.isArray(t.quotes))&&(a=t.quotes),"boolean"!=typeof t.skipEmptyLines&&"string"!=typeof t.skipEmptyLines||(d=t.skipEmptyLines),"string"==typeof t.newline&&(n=t.newline),"string"==typeof t.quoteChar&&(o=t.quoteChar),"boolean"==typeof t.header&&(i=t.header),Array.isArray(t.columns)){if(0===t.columns.length)throw new Error("Option columns is empty");c=t.columns}void 0!==t.escapeChar&&(l=t.escapeChar+o),("boolean"==typeof t.escapeFormulae||t.escapeFormulae instanceof RegExp)&&(m=t.escapeFormulae instanceof RegExp?t.escapeFormulae:/^[=+\-@\t\r].*$/)}}();var u=new RegExp(h(o),"g");if("string"==typeof e&&(e=JSON.parse(e)),Array.isArray(e)){if(!e.length||Array.isArray(e[0]))return p(null,e,d);if("object"==typeof e[0])return p(c||Object.keys(e[0]),e,d)}else if("object"==typeof e)return"string"==typeof e.data&&(e.data=JSON.parse(e.data)),Array.isArray(e.data)&&(e.fields||(e.fields=e.meta&&e.meta.fields||c),e.fields||(e.fields=Array.isArray(e.data[0])?e.fields:"object"==typeof e.data[0]?Object.keys(e.data[0]):[]),Array.isArray(e.data[0])||"object"==typeof e.data[0]||(e.data=[e.data])),p(e.fields||[],e.data||[],d);throw new Error("Unable to serialize unrecognized input");function p(e,t,a){var r="";"string"==typeof e&&(e=JSON.parse(e)),"string"==typeof t&&(t=JSON.parse(t));var o=Array.isArray(e)&&0<e.length,l=!Array.isArray(t[0]);if(o&&i){for(var d=0;d<e.length;d++)0<d&&(r+=s),r+=g(e[d],d);0<t.length&&(r+=n)}for(var c=0;c<t.length;c++){var m=o?e.length:t[c].length,u=!1,p=o?0===Object.keys(t[c]).length:0===t[c].length;if(a&&!o&&(u="greedy"===a?""===t[c].join("").trim():1===t[c].length&&0===t[c][0].length),"greedy"===a&&o){for(var h=[],_=0;_<m;_++){var f=l?e[_]:_;h.push(t[c][f])}u=""===h.join("").trim()}if(!u){for(var b=0;b<m;b++){0<b&&!p&&(r+=s);var x=o&&l?e[b]:b;r+=g(t[c][x],b)}c<t.length-1&&(!a||0<m&&!p)&&(r+=n)}}return r}function g(e,t){if(null==e)return"";if(e.constructor===Date)return JSON.stringify(e).slice(1,25);var i=!1;m&&"string"==typeof e&&m.test(e)&&(e="'"+e,i=!0);var n=e.toString().replace(u,l);return(i=i||!0===a||"function"==typeof a&&a(e,t)||Array.isArray(a)&&a[t]||function(e,t){for(var a=0;a<t.length;a++)if(-1<e.indexOf(t[a]))return!0;return!1}(n,r.BAD_DELIMITERS)||-1<n.indexOf(s)||" "===n.charAt(0)||" "===n.charAt(n.length-1))?o+n+o:n}}};if(r.RECORD_SEP=String.fromCharCode(30),r.UNIT_SEP=String.fromCharCode(31),r.BYTE_ORDER_MARK="\ufeff",r.BAD_DELIMITERS=["\r","\n",'"',r.BYTE_ORDER_MARK],r.WORKERS_SUPPORTED=!a&&!!t.Worker,r.NODE_STREAM_INPUT=1,r.LocalChunkSize=10485760,r.RemoteChunkSize=5242880,r.DefaultDelimiter=",",r.Parser=g,r.ParserHandle=p,r.NetworkStreamer=d,r.FileStreamer=c,r.StringStreamer=m,r.ReadableStreamStreamer=u,t.jQuery){var o=t.jQuery;o.fn.parse=function(e){var a=e.config||{},i=[];return this.each(function(e){if("INPUT"!==o(this).prop("tagName").toUpperCase()||"file"!==o(this).attr("type").toLowerCase()||!t.FileReader||!this.files||0===this.files.length)return!0;for(var s=0;s<this.files.length;s++)i.push({file:this.files[s],inputElem:this,instanceConfig:o.extend({},a)})}),s(),this;function s(){if(0!==i.length){var t,a,s,l=i[0];if(y(e.before)){var d=e.before(l.file,l.inputElem);if("object"==typeof d){if("abort"===d.action)return t=l.file,a=l.inputElem,s=d.reason,void(y(e.error)&&e.error({name:"AbortError"},t,a,s));if("skip"===d.action)return void n();"object"==typeof d.config&&(l.instanceConfig=o.extend(l.instanceConfig,d.config))}else if("skip"===d)return void n()}var c=l.instanceConfig.complete;l.instanceConfig.complete=function(e){y(c)&&c(e,l.file,l.inputElem),n()},r.parse(l.file,l.instanceConfig)}else y(e.complete)&&e.complete()}function n(){i.splice(0,1),s()}}}function l(e){this._handle=null,this._finished=!1,this._completed=!1,this._halted=!1,this._input=null,this._baseIndex=0,this._partialLine="",this._rowCount=0,this._start=0,this._nextChunk=null,this.isFirstChunk=!0,this._completeResults={data:[],errors:[],meta:{}},function(e){var t=x(e);t.chunkSize=parseInt(t.chunkSize),e.step||e.chunk||(t.chunkSize=null),this._handle=new p(t),(this._handle.streamer=this)._config=t}.call(this,e),this.parseChunk=function(e,a){if(this.isFirstChunk&&y(this._config.beforeFirstChunk)){var s=this._config.beforeFirstChunk(e);void 0!==s&&(e=s)}this.isFirstChunk=!1,this._halted=!1;var n=this._partialLine+e;this._partialLine="";var o=this._handle.parse(n,this._baseIndex,!this._finished);if(!this._handle.paused()&&!this._handle.aborted()){var l=o.meta.cursor;this._finished||(this._partialLine=n.substring(l-this._baseIndex),this._baseIndex=l),o&&o.data&&(this._rowCount+=o.data.length);var d=this._finished||this._config.preview&&this._rowCount>=this._config.preview;if(i)t.postMessage({results:o,workerId:r.WORKER_ID,finished:d});else if(y(this._config.chunk)&&!a){if(this._config.chunk(o,this._handle),this._handle.paused()||this._handle.aborted())return void(this._halted=!0);o=void 0,this._completeResults=void 0}return this._config.step||this._config.chunk||(this._completeResults.data=this._completeResults.data.concat(o.data),this._completeResults.errors=this._completeResults.errors.concat(o.errors),this._completeResults.meta=o.meta),this._completed||!d||!y(this._config.complete)||o&&o.meta.aborted||(this._config.complete(this._completeResults,this._input),this._completed=!0),d||o&&o.meta.paused||this._nextChunk(),o}this._halted=!0},this._sendError=function(e){y(this._config.error)?this._config.error(e):i&&this._config.error&&t.postMessage({workerId:r.WORKER_ID,error:e,finished:!1})}}function d(e){var t;(e=e||{}).chunkSize||(e.chunkSize=r.RemoteChunkSize),l.call(this,e),this._nextChunk=a?function(){this._readChunk(),this._chunkLoaded()}:function(){this._readChunk()},this.stream=function(e){this._input=e,this._nextChunk()},this._readChunk=function(){if(this._finished)this._chunkLoaded();else{if(t=new XMLHttpRequest,this._config.withCredentials&&(t.withCredentials=this._config.withCredentials),a||(t.onload=v(this._chunkLoaded,this),t.onerror=v(this._chunkError,this)),t.open(this._config.downloadRequestBody?"POST":"GET",this._input,!a),this._config.downloadRequestHeaders){var e=this._config.downloadRequestHeaders;for(var i in e)t.setRequestHeader(i,e[i])}if(this._config.chunkSize){var s=this._start+this._config.chunkSize-1;t.setRequestHeader("Range","bytes="+this._start+"-"+s)}try{t.send(this._config.downloadRequestBody)}catch(e){this._chunkError(e.message)}a&&0===t.status&&this._chunkError()}},this._chunkLoaded=function(){4===t.readyState&&(t.status<200||400<=t.status?this._chunkError():(this._start+=this._config.chunkSize?this._config.chunkSize:t.responseText.length,this._finished=!this._config.chunkSize||this._start>=function(e){var t=e.getResponseHeader("Content-Range");return null===t?-1:parseInt(t.substring(t.lastIndexOf("/")+1))}(t),this.parseChunk(t.responseText)))},this._chunkError=function(e){var a=t.statusText||e;this._sendError(new Error(a))}}function c(e){var t,a;(e=e||{}).chunkSize||(e.chunkSize=r.LocalChunkSize),l.call(this,e);var i="undefined"!=typeof FileReader;this.stream=function(e){this._input=e,a=e.slice||e.webkitSlice||e.mozSlice,i?((t=new FileReader).onload=v(this._chunkLoaded,this),t.onerror=v(this._chunkError,this)):t=new FileReaderSync,this._nextChunk()},this._nextChunk=function(){this._finished||this._config.preview&&!(this._rowCount<this._config.preview)||this._readChunk()},this._readChunk=function(){var e=this._input;if(this._config.chunkSize){var s=Math.min(this._start+this._config.chunkSize,this._input.size);e=a.call(e,this._start,s)}var n=t.readAsText(e,this._config.encoding);i||this._chunkLoaded({target:{result:n}})},this._chunkLoaded=function(e){this._start+=this._config.chunkSize,this._finished=!this._config.chunkSize||this._start>=this._input.size,this.parseChunk(e.target.result)},this._chunkError=function(){this._sendError(t.error)}}function m(e){var t;l.call(this,e=e||{}),this.stream=function(e){return t=e,this._nextChunk()},this._nextChunk=function(){if(!this._finished){var e,a=this._config.chunkSize;return a?(e=t.substring(0,a),t=t.substring(a)):(e=t,t=""),this._finished=!t,this.parseChunk(e)}}}function u(e){l.call(this,e=e||{});var t=[],a=!0,i=!1;this.pause=function(){l.prototype.pause.apply(this,arguments),this._input.pause()},this.resume=function(){l.prototype.resume.apply(this,arguments),this._input.resume()},this.stream=function(e){this._input=e,this._input.on("data",this._streamData),this._input.on("end",this._streamEnd),this._input.on("error",this._streamError)},this._checkIsFinished=function(){i&&1===t.length&&(this._finished=!0)},this._nextChunk=function(){this._checkIsFinished(),t.length?this.parseChunk(t.shift()):a=!0},this._streamData=v(function(e){try{t.push("string"==typeof e?e:e.toString(this._config.encoding)),a&&(a=!1,this._checkIsFinished(),this.parseChunk(t.shift()))}catch(e){this._streamError(e)}},this),this._streamError=v(function(e){this._streamCleanUp(),this._sendError(e)},this),this._streamEnd=v(function(){this._streamCleanUp(),i=!0,this._streamData("")},this),this._streamCleanUp=v(function(){this._input.removeListener("data",this._streamData),this._input.removeListener("end",this._streamEnd),this._input.removeListener("error",this._streamError)},this)}function p(e){var t,a,i,s=Math.pow(2,53),n=-s,o=/^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/,l=/^((\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)))$/,d=this,c=0,m=0,u=!1,p=!1,_=[],f={data:[],errors:[],meta:{}};if(y(e.step)){var b=e.step;e.step=function(t){if(f=t,j())w();else{if(w(),0===f.data.length)return;c+=t.data.length,e.preview&&c>e.preview?a.abort():(f.data=f.data[0],b(f,d))}}}function v(t){return"greedy"===e.skipEmptyLines?""===t.join("").trim():1===t.length&&0===t[0].length}function w(){return f&&i&&(k("Delimiter","UndetectableDelimiter","Unable to auto-detect delimiting character; defaulted to '"+r.DefaultDelimiter+"'"),i=!1),e.skipEmptyLines&&(f.data=f.data.filter(function(e){return!v(e)})),j()&&function(){if(f)if(Array.isArray(f.data[0])){for(var t=0;j()&&t<f.data.length;t++)f.data[t].forEach(a);f.data.splice(0,1)}else f.data.forEach(a);function a(t,a){y(e.transformHeader)&&(t=e.transformHeader(t,a)),_.push(t)}}(),function(){if(!f||!e.header&&!e.dynamicTyping&&!e.transform)return f;function t(t,a){var i,s=e.header?{}:[];for(i=0;i<t.length;i++){var n=i,r=t[i];e.header&&(n=i>=_.length?"__parsed_extra":_[i]),e.transform&&(r=e.transform(r,n)),r=S(n,r),"__parsed_extra"===n?(s[n]=s[n]||[],s[n].push(r)):s[n]=r}return e.header&&(i>_.length?k("FieldMismatch","TooManyFields","Too many fields: expected "+_.length+" fields but parsed "+i,m+a):i<_.length&&k("FieldMismatch","TooFewFields","Too few fields: expected "+_.length+" fields but parsed "+i,m+a)),s}var a=1;return!f.data.length||Array.isArray(f.data[0])?(f.data=f.data.map(t),a=f.data.length):f.data=t(f.data,0),e.header&&f.meta&&(f.meta.fields=_),m+=a,f}()}function j(){return e.header&&0===_.length}function S(t,a){return i=t,e.dynamicTypingFunction&&void 0===e.dynamicTyping[i]&&(e.dynamicTyping[i]=e.dynamicTypingFunction(i)),!0===(e.dynamicTyping[i]||e.dynamicTyping)?"true"===a||"TRUE"===a||"false"!==a&&"FALSE"!==a&&(function(e){if(o.test(e)){var t=parseFloat(e);if(n<t&&t<s)return!0}return!1}(a)?parseFloat(a):l.test(a)?new Date(a):""===a?null:a):a;var i}function k(e,t,a,i){var s={type:e,code:t,message:a};void 0!==i&&(s.row=i),f.errors.push(s)}this.parse=function(s,n,o){var l=e.quoteChar||'"';if(e.newline||(e.newline=function(e,t){e=e.substring(0,1048576);var a=new RegExp(h(t)+"([^]*?)"+h(t),"gm"),i=(e=e.replace(a,"")).split("\r"),s=e.split("\n"),n=1<s.length&&s[0].length<i[0].length;if(1===i.length||n)return"\n";for(var r=0,o=0;o<i.length;o++)"\n"===i[o][0]&&r++;return r>=i.length/2?"\r\n":"\r"}(s,l)),i=!1,e.delimiter)y(e.delimiter)&&(e.delimiter=e.delimiter(s),f.meta.delimiter=e.delimiter);else{var d=function(t,a,i,s,n){var o,l,d,c;n=n||[",","\t","|",";",r.RECORD_SEP,r.UNIT_SEP];for(var m=0;m<n.length;m++){var u=n[m],p=0,h=0,_=0;d=void 0;for(var f=new g({comments:s,delimiter:u,newline:a,preview:10}).parse(t),b=0;b<f.data.length;b++)if(i&&v(f.data[b]))_++;else{var x=f.data[b].length;h+=x,void 0!==d?0<x&&(p+=Math.abs(x-d),d=x):d=x}0<f.data.length&&(h/=f.data.length-_),(void 0===l||p<=l)&&(void 0===c||c<h)&&1.99<h&&(l=p,o=u,c=h)}return{successful:!!(e.delimiter=o),bestDelimiter:o}}(s,e.newline,e.skipEmptyLines,e.comments,e.delimitersToGuess);d.successful?e.delimiter=d.bestDelimiter:(i=!0,e.delimiter=r.DefaultDelimiter),f.meta.delimiter=e.delimiter}var c=x(e);return e.preview&&e.header&&c.preview++,t=s,a=new g(c),f=a.parse(t,n,o),w(),u?{meta:{paused:!0}}:f||{meta:{paused:!1}}},this.paused=function(){return u},this.pause=function(){u=!0,a.abort(),t=y(e.chunk)?"":t.substring(a.getCharIndex())},this.resume=function(){d.streamer._halted?(u=!1,d.streamer.parseChunk(t,!0)):setTimeout(d.resume,3)},this.aborted=function(){return p},this.abort=function(){p=!0,a.abort(),f.meta.aborted=!0,y(e.complete)&&e.complete(f),t=""}}function h(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function g(e){var t,a=(e=e||{}).delimiter,i=e.newline,s=e.comments,n=e.step,o=e.preview,l=e.fastMode,d=t=void 0===e.quoteChar||null===e.quoteChar?'"':e.quoteChar;if(void 0!==e.escapeChar&&(d=e.escapeChar),("string"!=typeof a||-1<r.BAD_DELIMITERS.indexOf(a))&&(a=","),s===a)throw new Error("Comment character same as delimiter");!0===s?s="#":("string"!=typeof s||-1<r.BAD_DELIMITERS.indexOf(s))&&(s=!1),"\n"!==i&&"\r"!==i&&"\r\n"!==i&&(i="\n");var c=0,m=!1;this.parse=function(r,u,p){if("string"!=typeof r)throw new Error("Input must be a string");var g=r.length,_=a.length,f=i.length,b=s.length,x=y(n),v=[],w=[],j=[],S=c=0;if(!r)return H();if(e.header&&!u){var k=r.split(i)[0].split(a),N=[],C={},E=!1;for(var I in k){var A=k[I];y(e.transformHeader)&&(A=e.transformHeader(A,I));var U=A,T=C[A]||0;for(0<T&&(E=!0,U=A+"_"+T),C[A]=T+1;N.includes(U);)U=U+"_"+T;N.push(U)}if(E){var P=r.split(i);P[0]=N.join(a),r=P.join(i)}}if(l||!1!==l&&-1===r.indexOf(t)){for(var R=r.split(i),D=0;D<R.length;D++){if(j=R[D],c+=j.length,D!==R.length-1)c+=i.length;else if(p)return H();if(!s||j.substring(0,b)!==s){if(x){if(v=[],W(j.split(a)),G(),m)return H()}else W(j.split(a));if(o&&o<=D)return v=v.slice(0,o),H(!0)}}return H()}for(var F=r.indexOf(a,c),O=r.indexOf(i,c),M=new RegExp(h(d)+h(t),"g"),L=r.indexOf(t,c);;)if(r[c]!==t)if(s&&0===j.length&&r.substring(c,c+b)===s){if(-1===O)return H();c=O+f,O=r.indexOf(i,c),F=r.indexOf(a,c)}else if(-1!==F&&(F<O||-1===O))j.push(r.substring(c,F)),c=F+_,F=r.indexOf(a,c);else{if(-1===O)break;if(j.push(r.substring(c,O)),z(O+f),x&&(G(),m))return H();if(o&&v.length>=o)return H(!0)}else for(L=c,c++;;){if(-1===(L=r.indexOf(t,L+1)))return p||w.push({type:"Quotes",code:"MissingQuotes",message:"Quoted field unterminated",row:v.length,index:c}),q();if(L===g-1)return q(r.substring(c,L).replace(M,t));if(t!==d||r[L+1]!==d){if(t===d||0===L||r[L-1]!==d){-1!==F&&F<L+1&&(F=r.indexOf(a,L+1)),-1!==O&&O<L+1&&(O=r.indexOf(i,L+1));var $=V(-1===O?F:Math.min(F,O));if(r.substr(L+1+$,_)===a){j.push(r.substring(c,L).replace(M,t)),r[c=L+1+$+_]!==t&&(L=r.indexOf(t,c)),F=r.indexOf(a,c),O=r.indexOf(i,c);break}var B=V(O);if(r.substring(L+1+B,L+1+B+f)===i){if(j.push(r.substring(c,L).replace(M,t)),z(L+1+B+f),F=r.indexOf(a,c),L=r.indexOf(t,c),x&&(G(),m))return H();if(o&&v.length>=o)return H(!0);break}w.push({type:"Quotes",code:"InvalidQuotes",message:"Trailing quote on quoted field is malformed",row:v.length,index:c}),L++}}else L++}return q();function W(e){v.push(e),S=c}function V(e){var t=0;if(-1!==e){var a=r.substring(L+1,e);a&&""===a.trim()&&(t=a.length)}return t}function q(e){return p||(void 0===e&&(e=r.substring(c)),j.push(e),c=g,W(j),x&&G()),H()}function z(e){c=e,W(j),j=[],O=r.indexOf(i,c)}function H(e){return{data:v,errors:w,meta:{delimiter:a,linebreak:i,aborted:m,truncated:!!e,cursor:S+(u||0)}}}function G(){n(H()),v=[],w=[]}},this.abort=function(){m=!0},this.getCharIndex=function(){return c}}function _(e){var t=e.data,a=s[t.workerId],i=!1;if(t.error)a.userError(t.error,t.file);else if(t.results&&t.results.data){var n={abort:function(){i=!0,f(t.workerId,{data:[],errors:[],meta:{aborted:!0}})},pause:b,resume:b};if(y(a.userStep)){for(var r=0;r<t.results.data.length&&(a.userStep({data:t.results.data[r],errors:t.results.errors,meta:t.results.meta},n),!i);r++);delete t.results}else y(a.userChunk)&&(a.userChunk(t.results,n,t.file),delete t.results)}t.finished&&!i&&f(t.workerId,t.results)}function f(e,t){var a=s[e];y(a.userComplete)&&a.userComplete(t),a.terminate(),delete s[e]}function b(){throw new Error("Not implemented.")}function x(e){if("object"!=typeof e||null===e)return e;var t=Array.isArray(e)?[]:{};for(var a in e)t[a]=x(e[a]);return t}function v(e,t){return function(){e.apply(t,arguments)}}function y(e){return"function"==typeof e}return i&&(t.onmessage=function(e){var a=e.data;if(void 0===r.WORKER_ID&&a&&(r.WORKER_ID=a.workerId),"string"==typeof a.input)t.postMessage({workerId:r.WORKER_ID,results:r.parse(a.input,a.config),finished:!0});else if(t.File&&a.input instanceof File||a.input instanceof Object){var i=r.parse(a.input,a.config);i&&t.postMessage({workerId:r.WORKER_ID,results:i,finished:!0})}}),(d.prototype=Object.create(l.prototype)).constructor=d,(c.prototype=Object.create(l.prototype)).constructor=c,(m.prototype=Object.create(m.prototype)).constructor=m,(u.prototype=Object.create(l.prototype)).constructor=u,r},void 0===(i=a.apply(t,[]))||(e.exports=i)},38255(e){e.exports=function(e){if(!window.satismeter){window.satismeter=function(){var e=[];function t(){e.push(arguments)}return t.q=e,t}();var t=document.createElement("script"),a=document.getElementsByTagName("script")[0].parentNode;t.async=1,t.src="https://app.satismeter.com/satismeter.js",a.appendChild(t)}return window.satismeter(e)}},36202(){jQuery.AsyncQueue=function(){var e,t,a,s,n=this,r=[],o=!1;return s=function(){var e=r.shift();e?(e.apply(n,[n]),!1===o&&s()):t&&t.apply(n)},this.onFailure=function(t){e=t},this.onComplete=function(e){t=e},this.add=function(e){return r.push(e),this},this.storeData=function(e){return a=e,this},this.lastCallbackData=function(){return a},this.run=function(){o=!1,s()},this.pause=function(){return o=!0,this},this.failure=function(){if(o=!0,e){var t=[n];for(i=0;i<arguments.length;i++)t.push(arguments[i]);e.apply(n,t)}},this}},41669(e){"use strict";e.exports=jQuery}},e=>{e.O(0,[223],()=>e(e.s=4945)),e.O()}]); |