!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"substack@c84c234"};var t=(new e.Error).stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="4d880c34-1031-4070-bf0d-5334ef71b123",e._sentryDebugIdIdentifier="sentry-dbid-4d880c34-1031-4070-bf0d-5334ef71b123")}catch(e){}}();"use strict";(self.webpackChunksubstack=self.webpackChunksubstack||[]).push([["74282"],{31793:function(e,t,a){a.d(t,{E:()=>P});var i=a(69277),s=a(70408),n=a(4006),l=a(83673),o=a.n(l),r=a(38970),d=a.n(r),u=a(17402),c=a(15734),m=a.n(c),p=a(89160),f=a(79796),b=a(27428),v=a(95691),y=a(84605),w=a(25006),g=a(46271),_=a(12501),h=a(68349),S=a(36372),I=a(56458),k=a(4016),T=a(96301),C=a(77124),E=a(39318);let P=()=>{let e=(0,g.Jd)(),t=(0,w.df)(),a=(0,S.d)(),{iString:l}=(0,y.GO)(),[r,c]=(0,u.useState)((null==e?void 0:e.name)||""),[P,F]=(0,u.useState)((null==e?void 0:e.email)||""),[A,O]=(0,u.useState)(!1),[Y,x]=(0,u.useState)(!1),[M,j]=(0,u.useState)(null),[D,G]=(0,u.useState)(null),[R,X]=(0,u.useState)(!1),[J,L]=(0,u.useState)(!1),[N]=(0,u.useState)(0),[B,U]=(0,u.useState)(new Set),{ids:V}=(0,f.i)({pub:t}),{ids:q}=(0,f.i)({pub:t,pubSetting:"fp_primary_column_section_ids"}),{ids:H}=(0,C.q)({pub:null!=t?t:void 0}),{ids:W}=(0,v.P)({pub:null!=t?t:void 0}),{ids:K}=(0,b.M)({pub:null!=t?t:void 0}),{ids:Z}=(0,p.G)({pub:null!=t?t:void 0}),{result:z,isLoading:Q,refetch:$}=(0,_.st)({pathname:"/api/v1/subscription",auto:!0}),{refetch:ee,isLoading:et}=(0,_.st)({pathname:"/api/v1/subscription/sections/email",auto:!1,method:"PATCH"}),{refetch:ea}=(0,_.st)({pathname:"/api/v1/subscription/email",auto:!1,method:"POST"});(0,u.useEffect)(()=>{!Q&&(null==z?void 0:z.email_settings)&&U(new Set(Object.keys(z.email_settings).filter(e=>{var t;return"individual"===(null==(t=z.email_settings)?void 0:t[e])}).map(e=>Number(e))))},[Q,z]);let ei=(0,u.useCallback)(async e=>{if(e&&e!==r){O(!0),j(null);try{await m().put("/api/v1/user/profile").send({name:e}),c(e)}catch(e){j((0,h.uX)(e)),console.error("Name update failed:",e)}finally{O(!1)}}},[r]),es=(0,u.useCallback)(async()=>{if(!(null==e?void 0:e.email))return{success:!1};X(!0);try{return await m().post("/api/v1/forgot").send({email:e.email,for_pub:null==t?void 0:t.subdomain,redirect:window.location.pathname}),a.popToast(()=>(0,n.Y)(S.y,{text:"Password reset email sent. Please check your inbox."})),{success:!0}}catch(e){return console.error("Password reset failed:",e),a.popToast(()=>(0,n.Y)(S.y,{text:(0,h.uX)(e)})),{success:!1}}finally{X(!1)}},[null==e?void 0:e.email,a]),en=(0,u.useCallback)(async(e,a)=>{if(e&&e!==P){if(e!==a)return void G("Email addresses do not match");x(!0),G(null);try{await m().put("/api/v1/user/email").send({email:e,email_doublecheck:a}),F(e),(0,h.V2)((0,E.bgT)({redirect:"/subscribe?isSignInAttempt=true",for_pub:null==t?void 0:t.subdomain}))}catch(e){var i;(null==(i=e.response)?void 0:i.status)===403?G("This email is already associated with another account"):G((0,h.uX)(e)),console.error("Email update failed:",e)}finally{x(!1)}}},[P]),el=(0,u.useMemo)(()=>t?(0,I.Jh)({pub:t,includeMainPub:!(0,k.lu)({pub:t})}):[],[t]),eo=(0,u.useMemo)(()=>el.filter(e=>{var t,a,i,s;return!H.includes(null!=(t=e.sectionId)?t:-1)&&!W.includes(null!=(a=e.sectionId)?a:-1)&&!K.includes(null!=(i=e.sectionId)?i:-1)&&!Z.includes(null!=(s=e.sectionId)?s:-1)}),[el,H,W,K,Z]),er=(0,u.useMemo)(()=>{let e=d()(el,"sectionId"),t=[...H,...W].filter(e=>!Z.includes(e));return o()(t.map(t=>e[t]))},[el,H,W,Z]),ed=(0,u.useCallback)(async(e,a)=>{if(!e||!t)return;let i=new Set(B);a?i.add(e):i.delete(e);try{await ee({json:eo.reduce((t,i)=>(i.sectionId===e&&(t[i.sectionId]={setting:a?"individual":"disabled"}),t),{})}),a&&(null==z?void 0:z.email_disabled)&&(await ea({json:{publication_id:t.id,email_disabled:!1,receive_podcast_emails:!0,source:"account_settings"}}),await $()),U(i)}catch(e){console.error("Failed to update newsletter subscription:",e)}},[t,B,eo,ee,ea,z,$]),eu=(0,u.useCallback)(async(e,a)=>{if(!t)return;let i=[];"fromTheFreePress"===e?i=q:"featured"===e?i=V.filter(e=>!q.includes(e)):"topic"===e?i=eo.filter(e=>!q.includes(e.sectionId||0)&&!V.includes(e.sectionId||0)).map(e=>e.sectionId||0):"video"===e&&(i=er.map(e=>e.sectionId).filter(e=>null!=e));let s=new Set(B);i.forEach(e=>{a?s.add(e):s.delete(e)});try{let e=i.reduce((e,t)=>(e[t]={setting:a?"individual":"disabled"},e),{});await ee({json:e}),a&&(null==z?void 0:z.email_disabled)&&(await ea({json:{publication_id:t.id,email_disabled:!1,receive_podcast_emails:!0,source:"account_settings"}}),await $()),U(s)}catch(e){console.error("Failed to update newsletter group:",e)}},[t,q,V,B,ee,ea,z,$]),ec=(0,u.useCallback)(async()=>{if(t&&e)try{let e=eo.filter(e=>e.sectionId).map(e=>e.sectionId);if(e.length>0){let t=e.reduce((e,t)=>(e[t]={setting:"disabled"},e),{});await ee({json:t})}await ea({json:{publication_id:t.id,email_disabled:!0,receive_podcast_emails:!1,source:"account_settings"}}),await $(),U(new Set),a.popToast(()=>(0,n.Y)(S.y,{text:"Successfully unsubscribed from all emails."}))}catch(e){console.error("Failed to unsubscribe from all emails:",e),a.popToast(()=>(0,n.Y)(S.y,{text:(0,h.uX)(e)}))}},[t,e,eo,ee,ea,$,a]),em=(0,u.useCallback)(async()=>{if(confirm(l("Are you sure? Time paid will not be refunded")))try{await m().del("/api/v1/subscription").send({force_now:!0}),a.popToast(()=>(0,n.Y)(S.y,{text:"Subscription cancelled successfully."})),setTimeout(()=>{window.location.reload()},1e3)}catch(e){console.error("Failed to delete subscription:",e),a.popToast(()=>(0,n.Y)(S.y,{text:(0,h.uX)(e)}))}},[l,a]),ep=(0,u.useCallback)(async()=>{L(!0);try{await m().post("/api/v1/subscription/reactivate").send({}),a.popToast(()=>(0,n.Y)(S.y,{text:"Your subscription is set to renew."})),await $()}catch(e){console.error("Failed to set to renew:",e),a.popToast(()=>(0,n.Y)(S.y,{text:(0,h.uX)(e)}))}finally{L(!1)}},[a,$]),ef=d()(eo,"sectionId"),eb=t&&q?{name:"From The Free Press",newsletters:o()(q.map(e=>ef[e])).map(e=>(0,s._)((0,i._)({},e),{selected:B.has(e.sectionId||0),onToggle:t=>ed(e.sectionId||0,t)}))}:{name:"From The Free Press",newsletters:[]},ev=t&&q?{name:"All",newsletters:o()(eo.filter(e=>e.sectionId).map(e=>(0,s._)((0,i._)({},e),{selected:B.has(e.sectionId||0),onToggle:t=>ed(e.sectionId||0,t)})))}:{name:"All",newsletters:[]},ey=t&&V?{name:"Featured",newsletters:o()(V.filter(e=>!q.includes(e)).map(e=>ef[e])).map(e=>(0,s._)((0,i._)({},e),{selected:B.has(e.sectionId||0),onToggle:t=>ed(e.sectionId||0,t)}))}:{name:"Featured",newsletters:[]},ew=t&&eo?{name:"Topic Alerts",newsletters:o()(eo.filter(e=>!!e.sectionId&&!q.includes(e.sectionId)&&!V.includes(e.sectionId)).map(e=>(0,s._)((0,i._)({},e),{selected:B.has(e.sectionId||0),onToggle:t=>ed(e.sectionId||0,t)})))}:{name:"Topic Alerts",newsletters:[]},eg=t&&eo?{name:"Podcast and Video Alerts",newsletters:o()(er.map(e=>(0,s._)((0,i._)({},e),{selected:B.has(e.sectionId||0),onToggle:t=>ed(e.sectionId||0,t)})))}:{name:"Podcast and Video Alerts",newsletters:[]},e_=(null==z?void 0:z.status)==="trialing",eh=null;return e_&&(z.current_period_end?eh=new Date(1e3*z.current_period_end):z.expiry&&(eh=new Date(z.expiry))),{name:r,email:P,updateName:ei,updateEmail:en,isUpdatingName:A,isUpdatingEmail:Y,nameError:M,emailError:D,isSendingReset:R,handlePasswordChange:es,newsletters:{isLoading:Q||et,fromTheFreePress:eb,all:ev,featured:ey,topic:ew,video:eg,updateNewsletter:ed,updateNewsletterGroup:eu,unsubscribeFromAllEmails:ec,pubEmailsDisabled:!!(null==z?void 0:z.email_disabled)},plan:null==z?void 0:z.plan,totalAmount:null==z?void 0:z.totalAmount,currency:null==z?void 0:z.currency,isLifetime:(null==z?void 0:z.type)==="lifetime"||(null==z?void 0:z.never_ends)||!1,isComped:(null==z?void 0:z.is_comped)||!1,isTrial:e_,giftCount:N,trialEnd:eh,canChangeSubscription:!!z&&(0,T.GU)(z),subscription:null!=z?z:void 0,renewing:J,onSetToRenew:ep,onUnsubscribeNow:em}}},89160:function(e,t,a){a.d(t,{G:()=>o});var i=a(38970),s=a.n(i),n=a(17402),l=a(13770);let o=e=>{let{pub:t}=e,a=s()(null==t?void 0:t.sections,"id"),{setting:i,save:o}=(0,l.E)({key:"archived_section_ids",fallback:[]}),[r,d]=(0,n.useState)(i),[u,c]=(0,n.useState)(!1),m=async()=>{c(!0),await o({setting:r})};return{isSaving:u,ids:r,onChange:e=>{let{ids:t}=e;d(t.filter(e=>a[e]))},onSave:m}}},79796:function(e,t,a){a.d(t,{i:()=>d});var i=a(38970),s=a.n(i),n=a(44383),l=a.n(n),o=a(17402),r=a(13770);let d=e=>{let{pub:t,pubSetting:a="column_section_ids"}=e,i=s()(null==t?void 0:t.sections,"id"),{setting:n,save:d}=(0,r.E)({key:a,fallback:{metadata:{},order:[]}}),[u,c]=(0,o.useState)(n.order),[m,p]=(0,o.useState)(n.metadata),[f,b]=(0,o.useState)(!1),v=async()=>{b(!0),await d({setting:{order:u,metadata:l()(m,u)}})};return{isSaving:f,metadata:m,ids:u,onChangeMetadata:e=>{let{metadata:t}=e;p(t)},onChangeOrder:e=>{let{ids:t}=e;c(t.filter(e=>i[e]))},onSave:v}}},27428:function(e,t,a){a.d(t,{M:()=>d});var i=a(83673),s=a.n(i),n=a(38970),l=a.n(n),o=a(17402),r=a(13770);let d=e=>{let{pub:t}=e,a=l()(null==t?void 0:t.sections,"id"),{setting:i,save:n}=(0,r.E)({key:"event_section_ids",fallback:[]}),[d,u]=(0,o.useState)(i),[c,m]=(0,o.useState)(!1),p=async()=>{m(!0),await n({setting:d})};return{initialSections:s()(i.map(e=>a[e])),isSaving:c,ids:d,sections:s()(d.map(e=>a[e])),onChange:e=>{let{ids:t}=e;u(t.filter(e=>a[e]))},onSave:p}}},13770:function(e,t,a){a.d(t,{E:()=>s});var i=a(53989);let s=e=>{let t,{key:a,fallback:s}=e,{getSettingFor:n,changeSetting:l}=(0,i.Pu)(),o=n(a);try{t=o?JSON.parse(o):s}catch(e){t=s}return{setting:t,save:async e=>{let{setting:t}=e;await l({[a]:JSON.stringify(t)})}}}},77124:function(e,t,a){a.d(t,{q:()=>m});var i=a(69277),s=a(70408),n=a(44383),l=a.n(n),o=a(17402),r=a(13770),d=a(74894);let u={"Honestly with Bari Weiss":"darkGreen","The Witch Trials of J.K. Rowling":"mediumOrange","Raising Parents with Emily Oster":"brightBlue"},c=["mediumYellow","darkGreen","mediumRed","darkOrange","mediumPurple","mediumBlue"],m=e=>{let{pub:t}=e,a=t?(0,d.Zu)(t):[],n=a.map(e=>{var t;return null!=(t=e.sectionId)?t:-1}),m=a.reduce((e,t,a)=>{var n,l,o;return(0,s._)((0,i._)({},e),{[null!=(n=t.sectionId)?n:-1]:{carouselColor:null!=(o=null!=(l=u[t.podcastTitle])?l:c[a%c.length])?o:"mediumRed"}})},{}),{setting:p,save:f}=(0,r.E)({key:"podcasts_metadata",fallback:{order:n,metadata:m}}),[b,v]=(0,o.useState)(p.order),[y,w]=(0,o.useState)(p.metadata),g=async()=>{await f({setting:{order:b,metadata:l()(y,b)}})};return{ids:b,metadata:y,onChangeOrder:e=>{let{ids:t}=e;v(t)},onChangeMetadata:e=>{let{metadata:t}=e;w(t)},onSave:g}}},95691:function(e,t,a){a.d(t,{P:()=>m});var i=a(83673),s=a.n(i),n=a(38970),l=a.n(n),o=a(44383),r=a.n(o),d=a(17402),u=a(13770);let c=["mediumYellow","darkGreen","mediumRed","darkOrange","mediumPurple","mediumBlue"],m=e=>{let{pub:t}=e,a=l()(null==t?void 0:t.sections,"id"),{setting:i,save:n}=(0,u.E)({key:"video_section_ids",fallback:{metadata:{},order:[]}});for(let e=0;e{g(!0),await n({setting:{order:f,metadata:r()(v,f)}}),window.location.reload()};return{initialSections:s()(i.order.map(e=>a[e])),isSaving:w,metadata:v,ids:f,sections:s()(f.map(e=>a[e])),onChangeMetadata:e=>{let{metadata:t}=e;y(t)},onChangeOrder:e=>{let{ids:t}=e;b(t.filter(e=>a[e]))},onSave:_}}}}]);