!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="59b5b5da-1e39-5244-b1e6-26ce1d28710d")}catch(e){}}(); import{j as e}from"./jsx-runtime-D_zvdyIk.js";import{r as d,c as A}from"./index-DwaoyV61.js";import{z as R}from"./index-zIQsbCyv.js";import{P as H}from"./PoweredByBeehiiv-Dj1YMx8i.js";import{a as y,u as T}from"./local_storage-DRhS2b1Z.js";import{u as B}from"./usePublication-D2CqPMl0.js";import{u as W}from"./useSignupRedirects-DHtV1InQ.js";import{B as b}from"./index-BnR0jK-Y.js";import{u as p}from"./useTranslation-CqXWvxCZ.js";import{e as G,c as I}from"./components-DhFN5rxT.js";import{q as f}from"./transition-DutcVzwb.js";import{_ as C}from"./dialog-DVHYVfVa.js";import{I as J}from"./Image-DpT3Wxag.js";import{c as K}from"./index-Bc72ctNv.js";const Q=({children:s,handleRedirect:t})=>{const{t:n}=p(),l=G();return d.useEffect(()=>{l?.status==="success"&&(l?.toast?.message&&R.success(l?.toast?.message),t())},[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(b,{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:t,className:"text-gray-900",children:n("shared.cta.maybe_later")})})]})]})};function U(s){const{t}=p(),[n]=y();return e.jsx("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-left text-xl font-bold text-gray-900",children:n?`${t("recommendations.suggestion")}`:t("recommendations.title")}),s.isSignupFlowInProgess?e.jsx("p",{className:"text-sm text-left 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-sm text-left text-gray-700",children:[s.publication.name," also recommends these newsletters."]})]})})}function X(s){const{t}=p();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?`${t("shared.actions.loading")}...`:t("shared.cta.load_more")})}):null}function Y(s){const t=B(),n=A(),{visitToken:l}=T(),[h,r]=y(),{t:c}=p(),m=n.state==="submitting",u=n.submission?.formData.get("email"),g=I();return d.useEffect(()=>{m&&r(u?String(u):"")},[m,r,u]),e.jsx(f.Root,{show:s.isOpen,as:d.Fragment,children:e.jsx(C,{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(f.Child,{as:d.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(C.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(f.Child,{as:d.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(g.Form,{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_subscribe_form",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:t.id}),s.recommendation_ids.map(i=>e.jsx("input",{type:"hidden",name:"recommendation_ids[]",value:i},i)),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:`${c("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:c("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:c("recommendations.opt_in_text",{name:t.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(b,{type:"button",className:"mx-2",onClick:s.onClose,variant:"ghost",disabled:m,children:c("shared.cta.cancel")}),e.jsx(b,{variant:"primary",type:"submit",isLoading:m,children:c("shared.cta.subscribe")})]})]})})]})})})}function E({boost:s=!1,recommendation:t,selected:n,onToggle:l}){return e.jsx("li",{className:"",children:e.jsx("div",{className:"space-y-4",children:e.jsxs("button",{type:"button",className:"relative flex rounded-lg border border-[#E5E7EB] bg-[#F9FAFB] p-4 cursor-pointer transition-all hover:bg-gray-50 hover:border-gray-300 w-full text-left",onClick:()=>l(t.id),children:[e.jsx("div",{className:`absolute top-4 right-4 rounded-md px-2 py-1 font-medium border shadow-sm pointer-events-none ${n?"bg-wt-primary text-wt-text-on-primary border-wt-primary":"bg-gray-100 text-gray-700 border-gray-300"}`,children:n?"Selected":"Select"}),e.jsxs("div",{className:"w-full pr-20",children:[e.jsx("div",{className:"mb-4 flex-shrink-0",children:e.jsx("div",{className:"h-14 w-14 overflow-hidden rounded border border-gray-300 bg-white",children:e.jsx(J,{maxWidth:128,aspectRatio:"square",src:t.publication.thumbnail_image_url,alt:t.publication.name})})}),e.jsxs("div",{className:"w-full 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:t.publication.name}),e.jsx("p",{className:"line-clamp-2 text-sm text-gray-700",children:t.publication.description})]}),t.reason&&e.jsxs("span",{className:"text-xs italic text-gray-700",children:['"',t.reason,'"']})]})]})]})]})})})}function Z({children:s}){return e.jsx("ul",{className:K("flex flex-col gap-4"),children:s})}function ge({isLoading:s,recommendations:t,boostedRecommendations:n,hasNextPage:l,loadNextPage:h}){const{t:r}=p(),c=B(),m=I(),u=m.data,g=u?.toast?.status==="success",[i,j]=d.useState([]),[_]=y(),[P,v]=d.useState(!1),{visitToken:D}=T(),{nextPage:N,progress:M}=W(c);d.useEffect(()=>{g&&(N(),R.success(u.toast.message))},[g]);const w=a=>{if(i.includes(a))return j(i.filter(o=>o!==a));j([...i,a])},F=[...t.filter(a=>i.includes(a.id)),...n.filter(a=>i.includes(a.id))].some(a=>a.double_opt_required),q=r(F?"recommendations.toast.success_one_double_opt":"recommendations.toast.success_one"),z=F?r("recommendations.toast.success_other_double_opt",{count:i.length}):r("recommendations.toast.success_other",{count:i.length}),S=i.length>1?z:q,L=a=>{if(a.preventDefault(),_){const o=new FormData;o.append("email",_),i.length>0?i.forEach(k=>{o.append("recommendation_ids[]",k)}):t.map(x=>x.id).concat(n.map(x=>x.id)).forEach(x=>{o.append("recommendation_ids[]",x)}),o.append("include_current_publication","false"),o.append("visit_token",D||""),o.append("publication_id",c.id);const V=r("errors.default");o.append("recommendations_error_message",V),o.append("recommendations_success_message",S),m.submit(o,{method:"post",action:"/recommendations_subscribe_form"})}else v(!0)},O=i.length===0,$=r(O?"recommendations.subscribe_to_all":"meta.titles.subscribe");return e.jsxs(e.Fragment,{children:[e.jsxs(m.Form,{className:"relative mx-auto w-full max-w-3xl p-6",onSubmit:L,children:[e.jsx(U,{isSignupFlowInProgess:!!M,publication:c}),e.jsxs(Z,{children:[n?.map(a=>e.jsx(E,{boost:!0,selected:i.includes(a.id),onToggle:w,recommendation:a},a.id)),t.map(a=>e.jsx(E,{selected:i.includes(a.id),onToggle:w,recommendation:a},a.id))]}),l&&e.jsx(X,{hasNextPage:l,isLoading:s,loadNextPage:h}),e.jsx(Q,{handleRedirect:N,children:$}),e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(H,{publication:c})})]}),e.jsx(Y,{isOpen:P,onClose:()=>v(!1),recommendation_ids:i,successMessage:S})]})}export{ge as R}; //# sourceMappingURL=RecommendationsForm-BhhxVxGV.js.map //# debugId=59b5b5da-1e39-5244-b1e6-26ce1d28710d