
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="d640efe4-b6c9-5dad-8610-9f2654dcfd9e")}catch(e){}}();
import{j as e}from"./jsx-runtime-BjG_zV1W.js";import{r as m,d as K}from"./index-D6da9p6-.js";import{_ as C}from"./index-CqJN8iQq.js";import{P as Q}from"./PoweredByBeehiiv-BmLCj73J.js";import{u as y,a as E}from"./PageProvider-BtoiiMvA.js";import{u as B}from"./usePublication-eitEkj_L.js";import{u as U}from"./useSignupRedirects-DisM_e3n.js";import{B as j}from"./index-DFtJ8-cK.js";import{u as g}from"./useTranslation-CfKJAmGY.js";import{f as X,F as Y,c as Z}from"./components-1fH5YjVo.js";import{T as A}from"./Toggle-CqH9SOb_.js";import{q as b}from"./transition-jWlQb9Jg.js";import{_ as k}from"./dialog-Bw_il7y1.js";import{I as ee}from"./Image-ycA_AFLr.js";import{c as se}from"./index-x2da_zcv.js";const te=({children:s,handleRedirect:a})=>{const{t:n}=g(),l=X();return m.useEffect(()=>{l?.status==="success"&&(l?.toast?.message&&C.success(l?.toast?.message),a())},[l]),e.jsxs("div",{className:"sticky bottom-0 left-0 right-0 mx-auto mt-4 w-full max-w-3xl bg-white pb-8 pt-4",children:[e.jsx("div",{className:"absolute -top-8 right-0 -z-10 h-8 w-full bg-white blur-lg"}),e.jsx("div",{className:"absolute -top-4 right-0 -z-10 h-8 w-full bg-white blur"}),e.jsxs("div",{className:"space-y-4 bg-white",children:[e.jsx("div",{children:e.jsx(j,{variant:"primary",className:"!rounded-md text-lg",type:"submit",block:!0,children:s})}),e.jsx("div",{className:"text-center text-sm text-gray-900",children:e.jsx("button",{type:"button",onClick:a,className:"text-gray-900",children:n("shared.cta.maybe_later")})})]})]})};function ae(s){const{t:a}=g(),[n]=y();return e.jsxs("div",{className:"flex flex-col space-y-4",suppressHydrationWarning:!0,children:[e.jsxs("div",{className:"mb-4 flex flex-col space-y-1",children:[e.jsx("h1",{className:"text-center text-2xl font-bold text-gray-900",children:n?`${a("recommendations.suggestion")}`:a("recommendations.title")}),s.isSignupFlowInProgess?e.jsx("p",{className:"text-md text-center text-gray-700",children:s.publication.web_template.signup_flow_messaging.recommendations_message?s.publication.web_template.signup_flow_messaging.recommendations_message:`${s.publication.name} also recommends these newsletters`}):e.jsxs("p",{className:"text-md text-center text-gray-700",children:[s.publication.name," also recommends these newsletters"]})]}),e.jsxs("div",{className:"mt-5 flex justify-end gap-3 px-4",children:[e.jsx("span",{className:"text-sm text-gray-700",children:s.isAllSelected?a("shared.cta.deselect_all"):a("shared.cta.select_all")}),e.jsx(A,{enabled:!!s.isAllSelected,onToggle:s.onToggle})]})]})}function ie(s){const{t:a}=g();return s.hasNextPage?e.jsx("div",{className:"flex justify-center",children:e.jsx("button",{onClick:s.loadNextPage,disabled:s.isLoading,className:"inline-flex items-center rounded-md border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700 shadow-sm hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-wt-primary focus:ring-offset-2",children:s.isLoading?`${a("shared.actions.loading")}...`:a("shared.cta.load_more")})}):null}function ne(s){const a=B(),n=K(),{visitToken:l}=E(),[h,c]=y(),{t:o}=g(),d=n.state==="submitting",u=n.submission?.formData.get("email");return m.useEffect(()=>{d&&c(u?String(u):"")},[d,c,u]),e.jsx(b.Root,{show:s.isOpen,as:m.Fragment,children:e.jsx(k,{as:"div",className:"fixed inset-0 z-10 overflow-y-auto",onClose:s.onClose,children:e.jsxs("div",{className:"flex items-end justify-center px-4 pb-20 pt-4 text-center sm:block sm:p-0",children:[e.jsx(b.Child,{as:m.Fragment,enter:"ease-out duration-300",enterFrom:"opacity-0",enterTo:"opacity-100",leave:"ease-in duration-200",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:e.jsx(k.Overlay,{className:"fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity"})}),e.jsx("span",{className:"hidden sm:inline-block sm:h-screen sm:align-middle","aria-hidden":"true",children:"​"}),e.jsx(b.Child,{as:m.Fragment,enter:"ease-out duration-300",enterFrom:"opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95",enterTo:"opacity-100 translate-y-0 sm:scale-100",leave:"ease-in duration-200",leaveFrom:"opacity-100 translate-y-0 sm:scale-100",leaveTo:"opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95",children:e.jsxs(Y,{className:"inline-block transform rounded-lg bg-white text-left align-bottom shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-lg sm:align-middle",action:"/recommendations?index",method:"post",children:[e.jsx("input",{type:"hidden",name:"visit_token",defaultValue:l}),e.jsx("input",{name:"recommendations_success_message",type:"hidden",defaultValue:s.successMessage}),e.jsx("input",{type:"hidden",name:"publication_id",defaultValue:a.id}),s.recommendation_ids.map(x=>e.jsx("input",{type:"hidden",name:"recommendation_ids[]",value:x},x)),e.jsxs("div",{className:"space-y-6 rounded-t-lg bg-white px-4 py-6 sm:p-6",children:[e.jsx("div",{children:e.jsx("h3",{className:"text-lg font-medium leading-6 text-gray-900",children:`${o("recommendations.one_last_thing")}...`})}),e.jsx("div",{className:"space-y-6",children:e.jsx("div",{children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("input",{type:"email",name:"email",autoComplete:"email",placeholder:o("subscribe.email_placeholder")||"",className:"block w-full rounded-wt border-2 border-wt-primary bg-white px-5 py-3 text-base font-light text-black placeholder-gray-400 focus:border-wt-primary focus:outline-none",required:!0,defaultValue:h}),e.jsxs("div",{className:"relative flex items-start",children:[e.jsx("div",{className:"flex h-5 items-center",children:e.jsx("input",{name:"include_current_publication",id:"include_current_publication",type:"checkbox",className:"h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500",defaultChecked:!0})}),e.jsx("div",{className:"ml-3 text-sm",children:e.jsx("label",{htmlFor:"include_current_publication",className:"font-medium text-gray-700",children:o("recommendations.opt_in_text",{name:a.name})})})]})]})})})]}),e.jsxs("div",{className:"align-items-center flex justify-end rounded-b-lg bg-gray-50 px-4 py-3 text-right sm:px-6",children:[e.jsx(j,{type:"button",className:"mx-2",onClick:s.onClose,variant:"ghost",disabled:d,children:o("shared.cta.cancel")}),e.jsx(j,{variant:"primary",type:"submit",isLoading:d,children:o("shared.cta.subscribe")})]})]})})]})})})}function T({boost:s=!1,recommendation:a,selected:n,onToggle:l}){return e.jsx("li",{className:"",children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"flex rounded-lg border border-[#E5E7EB] bg-[#F9FAFB] p-4",children:[e.jsxs("div",{className:"w-full sm:flex",children:[e.jsx("div",{className:"mb-4 flex-shrink-0 sm:mb-0 sm:mr-4",children:e.jsx("div",{className:"h-10 w-10 overflow-hidden rounded border border-gray-300 bg-white",children:e.jsx(ee,{maxWidth:128,aspectRatio:"square",src:a.publication.thumbnail_image_url,alt:a.publication.name})})}),e.jsxs("div",{className:"w-full max-w-md space-y-0.5",children:[s&&e.jsx("p",{className:"text-xs text-gray-700",children:"Sponsored"}),e.jsxs("div",{className:"flex flex-col space-y-2",children:[e.jsxs("div",{className:"flex flex-col space-y-0",children:[e.jsx("h4",{className:"text-lg font-medium text-gray-900",children:a.publication.name}),e.jsx("p",{className:"line-clamp-2 text-sm text-gray-700",children:a.publication.description})]}),a.reason&&e.jsxs("span",{className:"text-xs italic text-gray-700",children:['"',a.reason,'"']})]})]})]}),e.jsx("div",{children:e.jsx(A,{enabled:n,onToggle:()=>l(a.id)})})]})})})}function le({children:s}){return e.jsx("ul",{className:se("mt-5 flex flex-col gap-5"),children:s})}function Ne({isLoading:s,recommendations:a,boostedRecommendations:n,hasNextPage:l,loadNextPage:h}){const{t:c}=g(),o=B(),d=Z(),u=d.data,x=u?.toast?.status==="success",[i,p]=m.useState([]),[v]=y(),[P,_]=m.useState(!1),{visitToken:D}=E(),M=()=>{p(a.map(t=>t.id).concat(n.map(t=>t.id)))},R=()=>p([]),{nextPage:f,progress:I}=U(o);m.useEffect(()=>{x&&(f(),C.success(u.toast.message))},[x]);const N=t=>{if(i.includes(t))return p(i.filter(r=>r!==t));p([...i,t])},w=[...a.filter(t=>i.includes(t.id)),...n.filter(t=>i.includes(t.id))].some(t=>t.double_opt_required),q=c(w?"recommendations.toast.success_one_double_opt":"recommendations.toast.success_one"),L=w?c("recommendations.toast.success_other_double_opt",{count:i.length}):c("recommendations.toast.success_other",{count:i.length}),S=i.length>1?L:q,O=()=>{if(F)return R();M()},$=t=>{if(t.preventDefault(),i.length===0)return f();if(v){const r=new FormData;r.append("email",v),i.forEach(J=>r.append("recommendation_ids[]",J)),r.append("include_current_publication","false"),r.append("visit_token",D||""),r.append("publication_id",o.id);const G=c("errors.default");r.append("recommendations_error_message",G),r.append("recommendations_success_message",S),d.submit(r,{method:"post",action:"/recommendations?index"})}else _(!0)},V=a.every(t=>i.includes(t.id)),z=n&&n.every(t=>i.includes(t.id)),F=V&&z,H=i.length===0,W=c(H?"shared.cta.continue":"meta.titles.subscribe");return e.jsxs(e.Fragment,{children:[e.jsxs(d.Form,{className:"relative mx-auto my-4 w-full max-w-3xl p-4",onSubmit:$,children:[e.jsx(ae,{onToggle:O,isAllSelected:F,isSignupFlowInProgess:!!I,publication:o}),e.jsxs(le,{children:[n&&n.map(t=>e.jsx(T,{boost:!0,selected:i.includes(t.id),onToggle:N,recommendation:t},t.id)),a.map(t=>e.jsx(T,{selected:i.includes(t.id),onToggle:N,recommendation:t},t.id))]}),l&&e.jsx(ie,{hasNextPage:l,isLoading:s,loadNextPage:h}),e.jsx(te,{handleRedirect:f,children:W}),e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(Q,{publication:o})})]}),e.jsx(ne,{isOpen:P,onClose:()=>_(!1),recommendation_ids:i,successMessage:S})]})}export{Ne as R};
//# sourceMappingURL=RecommendationsForm-CCaEmJXs.js.map

//# debugId=d640efe4-b6c9-5dad-8610-9f2654dcfd9e
