1import{A as e,E as t,I as n,T as r,j as i}from"./chunk-KS7C4IRE-DIkipulk.js";import{t as a}from"./jsx-runtime-CsaOnxTR.js";import{l as o}from"./components-JSzoenoU.js";import{Aa as s,C as c,Fi as l,Ia as u,Ii as d,Li as f,Na as p,O as m,Rn as h,T as g,Vi as _,Wi as v,Xi as y,Xr as b,Yi as x,Yr as S,Zi as C,Zr as w,b as T,d as E,da as D,f as O,h as k,ji as A,jr as j,k as M,la as N,nn as P,p as F,qi as I,sa as L,v as R,w as z,yn as B,zn as V}from"./Elements-C-xYWSPQ.js";import{n as H,t as U}from"./ssr-CJ2n4bG3.js";import{t as W}from"./PageLayout-CMR1o20j.js";import{n as G}from"./MetaTags-BxzFdyK8.js";import{t as K}from"./StatusHandler-Bh1ghBjk.js";import{r as q,t as J}from"./adsHelper-DZxrkyG4.js";var Y=n(i(),1),X=a();function Z({showSelectAll:e=!1,selectAllTitle:t=`Select your newsletters`,className:n,toastHandler:r,testId:i=`newsletter-signup-list-test-id`}){let{userInfo:a}=V(),{isAuthenticated:c}=h(),[m,v]=(0,Y.useState)(!1),[S,D]=(0,Y.useState)(!1),[A,N]=(0,Y.useState)([]),[P,F]=(0,Y.useState)([]),[I,z]=(0,Y.useState)(!1),B=a?.email;(0,Y.useEffect)(()=>{m?(N(Array.from(new Set(Object.values(g).map(e=>e.id)))),D(!0)):(N([]),D(!1))},[m]),(0,Y.useEffect)(()=>{L(A)?D(!0):D(!1)},[A]),(0,Y.useEffect)(()=>{o&&(S?document.body.classList.toggle(`hide-mobile-ads`,S):document.body.classList.remove(`hide-mobile-ads`))},[S]);let H=async(e,t=!0)=>{try{if((await j(`consent/sync`,`POST`,{email:B,consents:k(e)},!1)).success){let n=k(e);if(Array.isArray(n)){let e=n.map(e=>e.name);F(t=>Array.from(new Set([...t,...e])))}s({eventCategory:p.NEWSLETTER_SIGN_UP,eventAction:t?`select +`:`click`,eventLabel:R(e)}),r&&typeof r==`function`&&r(b.SUCCESS)}else r&&typeof r==`function`&&r(b.ERROR);W()}catch{r&&typeof r==`function`&&r(b.ERROR),W()}},U=async()=>{await j(`consent/fetch`,`POST`,{email:a?.email},!1).then(e=>{e.success?F(T(e.data.consents)):r&&typeof r==`function`&&r(b.ERROR)})},W=()=>{N([]),v(!1)};(0,Y.useEffect)(()=>{c&&a&&a.email&&U()},[c,a?.email]);let G=Object.values(g).filter(e=>P.includes(e.consent_name)).length<Object.values(g).length;return(0,X.jsx)(X.Fragment,{children:(0,X.jsx)(`div`,{"data-testid":i,className:u(`newsletter-signup-list-container`,n),children:(0,X.jsxs)(X.Fragment,{children:[e&&(0,X.jsxs)(`div`,{className:`flex flex-row content-start justify-between gap-32 w-full items-center mobile:pb-10 tablet:pb-13 desktop:pb-16`,children:[(0,X.jsx)(_,{category:x.TITLE,size:y.SM,style:C.BOLD,testId:`newsletter-signup-into-test-id`,className:`shrink-1 `,children:t}),G&&c&&(0,X.jsx)(w,{type:f.TEXT_ONLY,fill:l.OUTLINE,size:d.SMALL,className:`shrink-0`,text:`Subscribe all`,textClassName:`font-secondary-label-md-semibold`,handler:()=>{H(Object.values(g).filter(e=>e.id).map(e=>e.id),!1)}})]}),(0,X.jsx)(`div`,{className:`newsletter-grid`,children:M().map(e=>(0,X.jsx)(O,{newsletter:e,button:E({active:P.includes(e.consent_name),id:e.id,handler:H,isLoading:I,setIsLoading:z}),className:`newsletter-card`},e.id))})]})})})}var Q=!1,$=e(function(){let{isAuthenticated:e}=h(),{pathname:n}=t(),i=q(P.DEFAULT,D(n)),a=L(i)?i[0]:void 0;Q||=(J(i),!0);let[l,d]=(0,Y.useState)(`DEFAULT`);(0,Y.useEffect)(()=>{N(`newsletter-toast`)},[]),(0,Y.useEffect)(()=>{l!==`DEFAULT`&&s({eventCategory:p.NEWSLETTER_SIGN_UP,eventAction:`visible`,eventLabel:l===b.SUCCESS?`you're subscribed`:l===b.ERROR?`sign-up failed`:`no internet connection`})},[l]);let f=r();return f.type===U.CLIENT_ERROR||f.type===U.SERVER_ERROR?(0,X.jsx)(K,{response:f}):(0,X.jsxs)(W,{lb1Ad:a,children:[(0,X.jsx)(`div`,{className:u(`container sticky top-72 mt-10 right-00 h-00 z-1000`,l===`DEFAULT`?`hidden`:`block`),id:`newsletter-toast`,children:(0,X.jsx)(S,{type:l===b.SUCCESS?b.SUCCESS:l===b.ERROR?b.ERROR:b.INFORMATION,message:l===b.SUCCESS?z.TOAST_SUCCESS:l===b.ERROR?z.TOAST_FAILED:z.TOAST_NO_INTERNET,descriptionMessage:l===b.SUCCESS?z.TOAST_SUCCESS_DESCRIPTION:l===b.ERROR?z.TOAST_FAILED_DESCRIPTION:z.TOAST_NO_INTERNET_DESCRIPTION,duration:3e3,className:`absolute right-00 w-full tablet:w-fit tablet:mt-10`,handler:()=>{d(`DEFAULT`)}})}),(0,X.jsx)(B,{title:`Newsletters`,url:`/newsletter-signup`,navigationItems:e?[{title:`Manage newsletters`,url:`/newsletter-manage`}]:[]}),(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`container`,children:(0,X.jsx)(v,{size:y.XXSCURATOR,type:I.CONTAINER,testId:`newsletter-signup-into-test-id`,className:`dynamic-padding-y`,children:m.introContent})}),(0,X.jsx)(Z,{className:`container`,showSelectAll:!0,toastHandler:d}),(0,X.jsx)(A,{className:`mx-00`}),(0,X.jsxs)(`div`,{className:`newsletter-signup-list-container container`,children:[(0,X.jsxs)(`div`,{className:`pt-24 pb-16 flex flex-col gap-04`,children:[(0,X.jsx)(_,{category:x.TITLE,size:y.SM,style:C.BOLD,className:`text-secondary`,children:`More newsletters`}),(0,X.jsx)(_,{category:x.LABEL,size:y.SM,style:C.REGULAR,className:`text-tertiary`,children:`Discover newsletters from our journalists on LinkedIn and Substack`})]}),(0,X.jsx)(`div`,{className:`newsletter-grid`,"data-testid":`external-newsletter-test-id`,children:Object.values(c).map(e=>(0,X.jsx)(F,{id:e.id,title:e.title,thumbnail:e.thumbnail,description:e.description,frequency:e.frequency,titleIcon:e.icon,showButton:!0,className:`newsletter-card`,type:`EXTERNAL`,handler:()=>{o&&window.open(e.target,`_blank`)}},e.id))})]})]})]})}),ee=e=>{let t=e.loaderData;if(t.type===U.SUCCESS){let e=t.payload.metaData;return G(e)}};async function te(e){let t=await H(e);if(!t.context)return console.error(`Error occured during client-side routing for newsletter, returning server Loader Data`),await e.serverLoader();let n=t.context;return(!n||typeof n!=`object`||!(`payload`in n)||typeof n.payload!=`object`)&&console.error(`Client Loader: fetchContext() returned an invali
1d payload for newsletter`),n}export{te as clientLoader,$ as default,ee as meta};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.