1import{r as l,j as e}from"../chunks/vendor-react-DdEP1kCQ.js";import{u as F}from"../chunks/use-piano-auth-sync-token-DqoBG9VW.js";import{g as R,L as k,e as D,u as M}from"../chunks/data-BmhhWP9E.js";import{z as p,d as r,k as E,p as w}from"../chunks/core-Bpuic6mr.js";import{F as U}from"../chunks/index-CsyIcmAv.js";import{D as Y}from"../chunks/DefaultLayout-B4mESSua.js";import"../chunks/sciam-CvuG93yt.js";import"../chunks/vendor-shared-ShLQKC4n.js";import"../chunks/Header-DuP3RNUx.js";import"../chunks/sciam-B_IQ-Vo8.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},o=new t.Error().stack;o&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[o]="3783bea3-0f87-487c-a0aa-1247d708767b",t._sentryDebugIdIdentifier="sentry-dbid-3783bea3-0f87-487c-a0aa-1247d708767b")}catch{}})();function q(){const{env:t,token:o}=F(),[n,i]=l.useState(null),[d,a]=l.useState(!1);return l.useEffect(()=>{o&&(a(!0),R(o,t).then(u=>{i(c=>({...c,...u}))}).catch(u=>{console.error("[useEmailPreferences] error:",u),i({global_suppression:!1,lists:[]})}).finally(()=>a(!1)))},[o]),{loading:d,preferences:n}}const B="pane-MFhq6",G="form-Rx0g0",H="form__header-4UgPe",A="form__header-4UgPe",W="form__section-1kDOF",K="form__section-1kDOF",Q="description--IC4j",V="form__footer-eYyyd",z="form__footer-eYyyd",J="sticky-9UHZ-",Z="loading-xKn7f",X="title-pWvTP",$="label-h5Be7",ee="fieldset-WyY3t",se="input_field-MY1Kb",te="input_field-MY1Kb",oe="disabled-yMKJa",ne="toggle_field-uCgIY",re="toggle_field-uCgIY",ie="toggle-kh83-",ae="toggle__primary-aObTN",le="toggle__primary-aObTN",ce="toggle__warning-U2Q-s",de="toggle__warning-U2Q-s",ue="toggle__slider-R9ofb",me="toggle__slider-R9ofb",_e="disclaimer-SYncU",ge="button__small-3j-rL",fe="button__small-3j-rL",pe="actions-mgsC-",be="button-pIRyE",he="button__primary--q2Fr",ye="button__primary--q2Fr",xe="button__secondary-GILSP",je="button__secondary-GILSP",ve="button__opt_out-HuqRf",Se="button__opt_out-HuqRf",Ne="button__text-Rdqr1",Pe="button__text-Rdqr1",we="divider-bNzrs",Ie="status_message-ccr-r",Fe="status_message-ccr-r",ke="status_message__error-ZQJR6",Ee="status_message__error-ZQJR6",s={pane:B,form:G,form__header:H,formHeader:A,form__section:W,formSection:K,description:Q,form__footer:V,formFooter:z,sticky:J,loading:Z,title:X,label:$,fieldset:ee,input_field:se,inputField:te,disabled:oe,toggle_field:ne,toggleField:re,toggle:ie,toggle__primary:ae,togglePrimary:le,toggle__warning:ce,toggleWarning:de,toggle__slider:ue,toggleSlider:me,disclaimer:_e,button__small:ge,buttonSmall:fe,actions:pe,button:be,button__primary:he,buttonPrimary:ye,button__secondary:xe,buttonSecondary:je,button__opt_out:ve,buttonOptOut:Se,button__text:Ne,buttonText:Pe,divider:we,status_message:Ie,statusMessage:Fe,status_message__error:ke,statusMessageError:Ee},Ce=Object.values(k).reduce((t,o)=>(t[o.type]||(t[o.type]=[]),t[o.type].push(o),t),{}),Le=[{type:"digest",title:"Digests",description:"Curated stories and exclusive content delivered periodically"},{type:"topic",title:"Topics",description:"Weekly updates on topics you care about"},{type:"issue",title:"New Issue Alerts",description:"Get notified when a new issue is published"},{type:"marketing",title:"Marketing",description:"Receive emails about products and services"}];function Te({lists:t,global_suppression:o}){if(o)w({event:"newsletter-opt-out",user:{newsletters:""}});else{let n=[];for(const[i,d]of Object.entries(t))d===!0&&n.push(i);w({event:"newsletter-sign-up",user:{newsletters:n.join(",")}})}}function Oe(t,o){const n=p(t?.global_suppression),i=p(o?.global_suppression),[d,a]=l.useState(n),[u,c]=l.useState(!1),[_,f]=l.useState(!1);return l.useEffect(()=>{if(!_)return f(!0);a(u?i:n)},[t,o]),{value:d,includeInPayload:n||i,onChange:()=>{_&&!u&&c(!0)}}}const Re=(t,o)=>{let n=!1,i=!1;const d={};return{lists:Object.keys(k).reduce((u,c)=>{const _=p(t[c]),f=_!==o?.lists?.[c],j=_&&p(o?.lists?.[c]);return n||=_,i||=f,(f||j)&&(u[c]=_),u},d),hasOptIn:n,hasDiff:i}};function De({defaultValues:t}){const[o,n]=l.useState(t),{env:i,token:d}=F(),[a,u]=l.useState({}),{value:c,includeInPayload:_,onChange:f}=Oe(o,a),[j,P]=l.useState([]),[b,N]=l.useState(null),h=b==="confirmed",y=b==="submitted"||!o?.lists;l.useEffect(()=>{h||n(t)},[t]);const C=g=>{u(g),N(null),f()},L=g=>{if(b)return;const{lists:S}=Re(g,o),x=p(g.global_suppression),m=_?{lists:{},global_suppression:x}:{lists:S};M(m,d,i).then(()=>{N("confirmed"),n({lists:S,global_suppression:x}),Te(m),P([])}).catch(O=>P([O?.message||"Something went wrong. Please try again."])),requestAnimationFrame(()=>N("submitted"))},T=l.useRef(),v=l.useId();return e.jsx("div",{className:s.pane,children:e.jsxs(U,{className:s.form,onFormData:C,onFormSubmit:L,action:D,method:"post",ref:T,children:[e.jsx(Me,{errors:j,suppressed:c}),Le.map(({type:g,title:S,description:x})=>e.jsxs("fieldset",{className:r(s.form__section,s.fieldset),children:[e.jsx("legend",{children:S}),x&&e.jsx("p",{children:x}),e.jsx("ul",{children:Ce[g]?.map?.(m=>e.jsxs("li",{className:r(s.input_field,s.toggle_field,c&&s.disabled),children:[e.jsxs("label",{htmlFor:v+m.field,className:s.label,children:[e.jsx("h3",{children:m.title}),m.description&&e.jsx("p",{className:s.description,children:m.description})]}),e.jsx(I,{id:v+m.field,name:m.field,defaultChecked:p(o?.lists?.[m.field]),tabIndex:"0",disabled:y||c})]},m.field))})]},g)),e.jsx("hr",{className:r(s.divider)}),e.jsxs("fieldset",{className:r(s.form__section,s.fieldset),id:"opt-out",children:[e.jsx("legend",{children:"Global Opt Out"}),e.jsxs("div",{className:r(s.input_field,s.toggle_field),children:[e.jsxs("label",{htmlFor:v+"global_suppression",className:s.label,children:[e.jsx("h3",{children:"Unsubscribe from all emails"}),e.jsx("p",{className:s.description,children:"You will still receive important account related emails."})]}),e.jsx(I,{id:v+"global_suppression",name:"global_suppression",type:"warning",defaultChecked:o?.global_suppression,tabIndex:"0",disabled:y})]})]}),e.jsx("div",{className:r(s.form__section,s.disclaimer),children:e.jsxs("p",{children:["By updating your preferences, you agree to our"," ",e.jsx("a",{href:"/page/terms-of-use/",children:"Terms of Use"})," and"," ",e.jsx("a",{href:"/page/privacy-policy",children:"Privacy Policy"}),"."]})}),e.jsxs(Ue,{loading:y,children:[e.jsx("button",{type:"reset",className:r(s.button,s.button__text),children:"Reset"}),e.jsx("div",{className:r(s.status_message),children:j.length?e.jsx("div",{className:r(s.status_message__error),children:e.jsx("p",{children:"There was an error saving your preferences."})}):b?e.jsx("div",{className:r(s.status_message__success),children:h&&e.jsx("p",{children:"Your preferences have been updated."})}):null}),e.jsx("button",{type:"submit",className:r(s.button,s.button__primary,y&&s.button__disabled||"",h&&s.button__success||""),disabled:y||h,children:b?h?"Saved":"Saving":"Save"})]})]})})}const I=({className:t="",type:o="primary",disabled:n,...i})=>e.jsxs("label",{className:r(s.toggle,s["toggle__"+o],t,n?s.disabled:""),children:[e.jsx("input",{type:"checkbox",...i,disabled:!!n||void 0}),e.jsx("div",{className:s.toggle__slider})]}),Me=({errors:t=[],suppressed:o=!1})=>{const{isLoggedIn:n,login:i}=E(),d=a=>{a.preventDefault(),i()};return e.jsxs("div",{className:s.form__header,children:[e.jsx("h2",{className:r(s.title),children:"Email Preferences"}),t.length>0&&e.jsx("div",{className:s.errors,children:e.jsx("ul",{children:t.map(a=>e.jsx("li",{children:a},a))})}),n?o?e.jsxs("p",{className:r(s.description),children:["Before setting email preferences you must first"," ",e.jsx("a",{href:"#opt-out",className:r(s.button,s.button__text),onClick:a=>{a.preventDefault(),document.getElementById("opt-out")?.scrollIntoView({behavior:"smooth"})},children:"disable Global Opt Out"})," ","below."]}):e.jsx("p",{className:r(s.description),children:"Customize your email preferences below."}):e.jsxs("p",{className:r(s.description,n===!1&&s.box),children:[e.jsx("button",{className:r(s.button,s.button__text),onClick:d,children:"Sign In"}
1)," ","in to update your email preferences."]})]})},Ue=({errors:t=[],loading:o=!1,children:n})=>{const{isLoggedIn:i}=E();return e.jsxs("div",{className:r(s.form__footer,i&&!t.length&&s.sticky||""),children:[o&&e.jsx("div",{className:s.loading}),e.jsx("div",{className:s.actions,children:n})]})};function ze(){const{preferences:t}=q();return e.jsx(Y,{children:e.jsx(De,{defaultValues:t})})}export{ze as default};
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.