!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@9a5020d"};var t=(new e.Error).stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="66f1ddce-c2bf-47e1-9aae-6a202b4cf138",e._sentryDebugIdIdentifier="sentry-dbid-66f1ddce-c2bf-47e1-9aae-6a202b4cf138")}catch(e){}}();"use strict";(self.webpackChunksubstack=self.webpackChunksubstack||[]).push([["60297"],{30193:function(e,t,n){n.d(t,{A:()=>s});var r=n(69277),o=n(70408),i=n(32641),a=n(4006),l=n(97731);let s=e=>{var{size:t=24,stroke:n="var(--color-fg-primary)",strokeWidth:s=1.5,className:u,isStatic:d,style:c}=e,p=(0,i._)(e,["size","stroke","strokeWidth","className","isStatic","style"]);return(0,a.Y)(l.A,(0,o._)((0,r._)({},p),{name:"notes__NoteCommentIcon",svgParams:{viewBox:"0 0 20 20"},width:t,height:t,stroke:n,strokeWidth:s,strokeLinecap:"round",strokeLinejoin:"round",className:u,isStatic:d,style:c,children:(0,a.Y)("path",{d:"M18.7502 11V7.50097C18.7502 4.73917 16.5131 2.50033 13.7513 2.50042L6.25021 2.50044C3.48848 2.5004 1.25017 4.73875 1.2502 7.50048L1.25021 10.9971C1.2502 13.749 3.47395 15.9836 6.22586 15.9971L6.82888 16V19.0182L12.1067 16H13.7502C16.5116 16 18.7502 13.7614 18.7502 11Z"})}))}},68611:function(e,t,n){n.d(t,{A:()=>s});var r=n(69277),o=n(70408),i=n(32641),a=n(4006),l=n(97731);let s=e=>{var{size:t=24,stroke:n="var(--color-fg-primary)",strokeWidth:s=1.5,className:u,isStatic:d,style:c}=e,p=(0,i._)(e,["size","stroke","strokeWidth","className","isStatic","style"]);return(0,a.Y)(l.A,(0,o._)((0,r._)({},p),{name:"notes__NoteRestackIcon",svgParams:{viewBox:"0 0 20 20"},width:t,height:t,stroke:n,strokeWidth:s,strokeLinecap:"round",strokeLinejoin:"round",className:u,isStatic:d,style:c,children:(0,a.Y)("path",{d:"M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"})}))}},5109:function(e,t,n){n.d(t,{QL:()=>M,dx:()=>U});var r=n(69277),o=n(70408),i=n(32641),a=n(79785),l=n(4006),s=n(32485),u=n.n(s),d=n(69843),c=n.n(d),p=n(17402),m=n(38217),h=n(52820),f=n(84605),g=n(92905),b=n(86500),v=n(94729),y=n(12501),Y=n(35369),_=n(33727),w=n(60322),S=n(85329),C=n(76977),k=n(20500),I=n(88762),N=n(16993),E=n(45974),F=n(94996),D=n(63136),A=n(11587),T=n(65842),P=n(61554),x=n(96400),O=n(39318),L=n(46058),R=n(16722);function B(){let e=(0,a._)([""," on Substack"]);return B=function(){return e},e}let U=(0,h.WR)((0,f.wr)(function(e){let{className:t,user:n,numVisibleSubscriptions:r,numSubscriptions:o,freeSignup:i,freeSignupEmail:a,needsPhoto:s,optionalPhoto:d,showHandle:h=!0,token:f,text:N,onSuccess:O,prepareData:U,pageTitle:M,primaryEligiblePublications:W,isPostInvite:H,complete:j,profileExists:G,onSkip:q,onEditReadVisibility:z,barebones:V,onEditRecommendations:J,numRecommendationsToMake:K,noSubscribeCta:Q,style:X,iString:Z,iPlural:$,iTemplate:ee,showSocialHandle:et,pub:en,autoSubmit:er,onAutoSubmitFailed:eo}=e,[ei,ea]=(0,p.useState)(null),[el,es]=(0,p.useState)(null),[eu,ed]=(0,p.useState)(null),[ec,ep]=(0,p.useState)(n&&n.is_magic?n.email:null),[em,eh]=(0,p.useState)("instagram"),[ef,eg]=(0,p.useState)(!!H&&!(null==n?void 0:n.has_publication)),[eb,ev]=(0,p.useState)(void 0),[ey,eY]=(0,p.useState)(!1),[e_,ew]=(0,p.useState)(!1),[eS,eC]=(0,p.useState)(!1),[ek,eI]=(0,p.useState)(void 0),[eN,eE]=(0,p.useState)(!!H||!!G),[eF,eD]=(0,p.useState)(!0),[eA,eT]=(0,p.useState)(!1),eP=(0,p.useRef)(null),ex=(0,p.useRef)(!1),{isLoading:eO,error:eL,refetch:eR,clearError:eB}=(0,y.st)({pathname:"/api/v1/user/profile",method:"PUT",auto:!1,deps:[]}),{trackInputFilled:eU,trackSubmitPressed:eM,trackError:eW}=(0,g.a)("Signup Profile Form"),eH=eb||(0,L.w3)(n,{}),ej=ei||n&&n.name||"",eG=el||(null==n?void 0:n.handle)||"",eq="string"==typeof eu?eu:n&&n.bio||"",ez=()=>n&&!n.is_magic&&n.name&&(!s||n.photo_url),eV=async(e,t)=>{try{let n=await (0,v.x6)("/api/v1/publication/suggestion"),r=t||ee(B(),e);await (0,v.x6)("/api/v1/publication",{method:"post",json:{name:e,subdomain:n.subdomain,hero_text:r,tos:!0}})}catch(e){(0,b.u4)(b.qY.DEFAULT_PUBLICATION_CREATION_FAILED),console.warn("couldn't set up a default publication",e)}},eJ=async()=>{let e=ec||a;if(!eA&&e){eT(!0);try{await (0,v.x6)("/api/v1/email-login",{method:"post",json:{email:e,redirect:document.location.href}}),ew(!0)}catch(e){console.error("Failed send login email:",e)}eT(!1)}},eK=async e=>{if(null==e||e.preventDefault(),eM(),eB(),!eP.current)return;let t=Object.fromEntries(new FormData(eP.current).entries());U&&U(t,e);let n=await eR({json:t});if(n instanceof Error){var r;eW(n),er&&!ey&&(eY(!0),null==eo||eo()),ew(!1),n instanceof v.fk&&(null==(r=n.response)?void 0:r.status)===401&&eJ()}else{if(n.emailConfirmationRequired)return void eC(!0);ef&&await eV(ej,eq),O({body:n},t)}};(0,p.useEffect)(()=>{er&&!ex.current&&(ex.current=!0,ez()?eK():null==eo||eo())},[]);let eQ="string"==typeof M||null===M?M:Z(ez()?"Update your profile":"Create your profile"),eX=(!n||n.is_magic)&&!a&&!H,eZ=!G&&!!J&&!c()(K)&&K>0,e$=H&&W&&(null==n?void 0:n.has_publication)&&W.length>1,e0="number"==typeof r&&!c()(o)&&o>0&&z,e1=!Q&&!(n&&(n.is_subscribed||n.is_free_subscribed)||i),e2=H&&!(null==n?void 0:n.has_publication),e7=eO||eA;return(0,l.FD)("div",{className:u()("profile-updater",t),style:X,children:[eQ&&(0,l.Y)(D.EY.H4,{align:"left",paddingBottom:20,children:eQ}),(eH||s||d)&&(0,l.Y)(C.fI,{flex:"grow",justifyContent:"center",alignItems:"center",children:(0,l.Y)(m.U,{user:{photo_url:eb||(null==n?void 0:n.photo_url)||null},onChangePhoto:e=>{let{photo_url:t}=e;return ev(t)}})}),(0,l.FD)("form",{ref:eP,className:"form",onSubmit:eK,noValidate:!0,children:[(0,l.FD)(C.VP,{gap:20,children:[(0,l.FD)(T.A0,{children:[(0,l.Y)(I.sb,{htmlFor:"name",children:Z("Name")}),en?(0,l.Y)("input",{type:"hidden",name:"pub_id",value:en.id}):null,(0,l.Y)(T.ks,{autoFocus:!0,className:"profile-name",placeholder:Z("Type your name..."),name:"name",id:"name",value:ej,disabled:e7,onInput:e=>{ea(e.currentTarget.value)},onBlur:eU})]}),eX&&(0,l.FD)(T.A0,{children:[(0,l.Y)(I.sb,{htmlFor:"email",children:Z("Email")}),(0,l.Y)(S.j,{placeholder:Z("Enter your email address..."),name:"email",value:null!=ec?ec:void 0,disabled:e7,onInput:e=>{ep(e.currentTarget.value)}})]}),h&&(0,l.FD)(T.A0,{children:[(0,l.Y)(I.JU,{htmlFor:"handle",children:Z("Handle")}),(0,l.Y)(T.ks,{className:"profile-name",placeholder:Z("Type your handle..."),name:"handle",id:"handle",value:eG,disabled:e7,onInput:e=>{es(e.currentTarget.value)}})]}),!V&&(0,l.FD)(T.A0,{children:[(0,l.Y)(I.JU,{htmlFor:"bio",children:Z("Bio")}),(0,l.Y)(A.T,{placeholder:Z("Say something about yourself..."),name:"bio",id:"bio",value:eq,disabled:e7,onInput:e=>{ed(e.currentTarget.value)}}),H&&(0,l.Y)(k.EE,{align:"left",children:Z("Tip: this will be shown at the bottom of your guest post")})]}),H&&(0,l.Y)("input",{type:"hidden",name:"needs_bio",value:"true"}),et&&(0,l.FD)(T.A0,{children:[(0,l.Y)(I.Sy,{htmlFor:"social",hint:Z("Optional"),children:Z("Where else can you be found?")}),(0,l.FD)(C.fI,{gap:8,wrap:"wrap",children:[(0,l.Y)(C.fI,{flex:"grow",minWidth:200,children:(0,l.FD)(F.I,{flex:"grow",name:"social",value:em,disabled:e7,onChange:e=>{eh(e.currentTarget.value)},children:[(0,l.Y)(F.K,{children:Z("Select a social network")}),(0,l.Y)("option",{value:"twitter",children:Z("Twitter")}),(0,l.Y)("option",{value:"instagram",children:Z("Instagram")}),(0,l.Y)("option",{value:"tiktok",children:Z("Tiktok")}),(0,l.Y)("option",{value:"linkedin",children:Z("LinkedIn")}),(0,l.Y)("option",{value:"youtube",children:Z("Youtube")})]})}),(0,l.Y)(C.fI,{flex:"grow",minWidth:200,children:(0,l.Y)(T.ks,{flex:"grow",placeholder:Z("@yourhandle"),name:"socialHandle",value:ek,disabled:e7,onInput:e=>{eI(e.currentTarget.value)}})})]})]}),e$&&(0,l.FD)(T.A0,{children:[(0,l.Y)(I.JU,{children:Z("Publication to display")}),(0,l.Y)(_.Z,{padding:12,gap:12,children:W.map((e,t)=>{var n,r;return(0,l.Y)(I.JU,{htmlFor:"primary-radio-".concat(e.id),children:(0,l.FD)(C.fI,{gap:12,alignItems:"center",children:[(0,l.Y)("input",{id:"primary-radio-".concat(e.id),type:"radio",name:"primary_publication_user_id",value:e.id,defaultChecked:0===t,disabled:e7}),(0,l.Y)(E.Nq,{pub:e.publication,size:24}),(0,l.Y)(D.EY.B3,{as:"span",children:null!=(r=null==(n=e.publication)?void 0:n.name)?r:""})]})},e.id)})})]}),e1&&(0,l.FD)(C.Ye,{as:"label",className:R.A.checkbox,gap:8,children:[(0,l.Y)(w.S,{size:"sm",name:"free_signup",defaultChecked:!0,checked:eF,onChange:e=>eD(e)}),(0,l.Y)(D.EY.B3,{as:"span",children:Z("Subscribe to the newsletter")})]}),e2&&(0,l.FD)(C.Ye,{as:"label",className:R.A.checkbox,gap:8,children:[(0,l.Y)(w.S,{name:"create_publication",id:"create-publication-checkbox",checked:ef,onChange:e=>{eg(e)}}),(0,l.Y)(D.EY.B3,{as:"span",children:Z("Create a Substack publication for me")})]}),(0,l.Y)("input",{type:"hidden",name:"confirmation_redirect_pathname",value:document.location.pathname}),(0,l.Y)("input",{type:"hidden",name:"photo_url",value:null!=eH?eH:void 0}),(0,l.Y)("input",{type:"hidden",name:"user_id",value:(null==n?void 0:n.id)||""}),(0,l.Y)("input",{type:"hidden",name:"needs_photo",value:!!s}),(0,l.Y)("input",{type:"hidden",name:"token",value:f}),j&&(0,l.Y)("input",{type:"hidden",name:"complete",value:!0}),(0,l.FD)("div",{children:[eL&&!e_&&(0,l.Y)("div",{className:"error other-error",children:(()=>{if(!eL)return null;if(eL instanceof v.fk){var e,t,n,r;return(null==(n=eL.body)||null==(t=n.errors)||null==(e=t[0])?void 0:e.msg)||(null==(r=eL.body)?void 0:r.error)||"Something went wrong"}return"Something went wrong"})()}),e_&&(0,l.FD)(D.EY,{as:"div",translated:!0,className:"error other-error",children:["If you have an account with us, we've sent an email to ",(0,l.Y)("b",{children:x.TH.p(null!=ec?ec:"")})," with a link that you can use to sign in."]}),eS&&(0,l.Y)("div",{className:"error other-error",children:Z("We have sent you a confirmation email. Please check your inbox before continuing.")})]}),e0&&(0,l.FD)(D.EY.B3,{as:"span",children:[(0,l.Y)(D.Yq,{cursor:"pointer",decoration:"underline",onClick:z,children:$("1 subscription","%1 subscriptions",r)})," ",Z("will be displayed on your profile.")]}),eZ&&(0,l.FD)(D.EY.B3,{as:"span",children:[(0,l.Y)(D.Yq,{cursor:"pointer",decoration:"underline",onClick:J,children:$("1 recommendation","%1 recommendations",K)})," ",Z("will be made on your publication.")]})]}),(0,l.FD)(C.VP,{gap:8,children:[!n&&(0,l.Y)(C.VP,{className:R.A.tosCheckboxContainer,paddingBottom:12,children:(0,l.Y)(P.U,{checked:eN,onCheckboxChange:e=>eE(e),style:{display:"flex"}})}),(0,l.Y)(Y.$n,{priority:"primary",disabled:!n&&!eN||e7,loading:e7,type:"submit",children:N||Z("Save")}),q&&(0,l.Y)(Y.$n,{priority:"secondary",onClick:q||(()=>{}),disabled:e7,children:Z("Skip")})]})]})]})}));function M(e){var{isOpen:t,onClose:n,contributor:a}=e,s=(0,i._)(e,["isOpen","onClose","contributor"]);return(0,l.FD)(N.aF,{isOpen:t,onClose:()=>n(),width:490,children:[(0,l.Y)(N.rQ,{onClose:()=>n()}),(0,l.Y)(N.cw,{children:a?(0,l.Y)(W,(0,o._)((0,r._)({},s),{user:s.user,pub:s.pub,profile:s.profile,onSuccess:()=>n()})):(0,l.Y)(U,(0,o._)((0,r._)({},s),{onSuccess:()=>n()}))})]})}let W=e=>{let{profile:t,user:n,pub:r,onSuccess:o,isOwnProfile:i}=e,{iString:a}=(0,f.GO)(),[s,u]=(0,p.useState)(null),d=s||t&&t.photo_url,[c,h]=(0,p.useState)(t.name),[g,b]=(0,p.useState)(t.bio),{isLoading:_,error:w,refetch:S,clearError:C}=(0,y.st)({pathname:"/api/v1/publication/users/".concat(t.id),method:"PATCH",auto:!1,deps:[t.id]}),k=async e=>{e.preventDefault(),C();let t=Object.fromEntries(new FormData(e.currentTarget).entries());await S({json:t}) instanceof Error||null==o||o()};return(0,l.FD)("div",{className:"profile-updater",children:[(0,l.Y)("h2",{className:"page-title profile-updater-title",children:"Edit contributor profile"}),(0,l.Y)("div",{className:"profile-photo-wrap",children:(0,l.Y)(m.U,{user:{photo_url:s||(null==t?void 0:t.photo_url)||null},onChangePhoto:e=>{let{photo_url:t}=e;return u(t)}})}),(0,l.FD)("form",{className:"form",onSubmit:k,noValidate:!0,children:[(0,l.Y)("input",{type:"text",className:"profile-name",placeholder:"Contributor's name…",name:"name",value:c,disabled:_,onInput:e=>{h(e.target.value)}}),(0,l.Y)("textarea",{className:"profile-bio",placeholder:"Contributor's bio…",name:"bio",value:g,disabled:_,onInput:e=>{b(e.target.value)}}),(0,l.Y)("input",{type:"hidden",name:"photo_url",value:d}),w&&(0,l.Y)("div",{className:"error other-error",children:(()=>{if(!w)return null;if(w instanceof v.fk){var e,t,n,r;return(null==(n=w.body)||null==(t=n.errors)||null==(e=t[0])?void 0:e.msg)||(null==(r=w.body)?void 0:r.error)||"Something went wrong"}return"Something went wrong"})()}),(0,l.FD)("span",{className:"notice",children:[(0,l.FD)(D.EY,{translated:!0,as:"p",children:[(0,l.Y)("b",{children:"Note:"})," This is a contributor profile, viewable by ",x.TH.p(r.name),"'s readers."]}),i&&(0,l.FD)(D.EY,{translated:!0,as:"p",children:["You may also edit your"," ",(0,l.Y)("a",{"data-native":!0,href:"".concat((0,O.gYq)(n)),children:"personal profile"}),"."]})]}),(0,l.Y)(Y.$n,{priority:"primary",type:"submit",loading:_,disabled:_,children:a("Update profile")})]})]})}},70145:function(e,t,n){n.d(t,{ct:()=>c,ey:()=>d,jN:()=>p});var r=n(69277),o=n(70408),i=n(4006),a=n(17402),l=n(15734),s=n.n(l);let u=(0,a.createContext)({oauthAccessToken:null,isOAuthProvider:!1}),d=()=>(0,a.useContext)(u);function c(e){let t=t=>{let{oauthAccessToken:n}=d();return(0,i.Y)(e,(0,o._)((0,r._)({},t),{oauthAccessToken:n}))};return t.displayName="WithOAuthEmbed(".concat(e.displayName||e.name||"Component",")"),t}let p=()=>{let{oauthAccessToken:e}=d();return(0,a.useMemo)(()=>{let t=t=>(e&&t.set("Authorization","Bearer ".concat(e)),t);return{get:e=>t(s().get(e)),post:e=>t(s().post(e)),put:e=>t(s().put(e)),delete:e=>t(s().delete(e)),patch:e=>t(s().patch(e))}},[e])}},62578:function(e,t,n){n.d(t,{N:()=>l});var r=n(17402),o=n(46271),i=n(13022),a=n(12501);function l(e){let{editingCommentUserId:t,postPublicationId:n}=e,l=(0,o.Jd)(),s=!!(0,i.Ay)("enable_notes_admins"),[u,d]=(0,r.useState)(null),{result:c}=(0,a.st)({pathname:"/api/v1/publication_user/notes_permissions",auto:s}),p=(0,r.useRef)(null!=t?t:null);function m(e){var t;p.current=null!=(t=null==e?void 0:e.id)?t:null,d(e)}(0,r.useEffect)(()=>{if(p.current&&!u&&c&&c.length>1){let e=c.find(e=>e.id===p.current);m(null!=e?e:null)}},[c,u]);let h=null!=c?c:[];return{postAsUserId:p,enableUserSwitcher:s,eligiblePostAsUsers:n?h.filter(e=>{var t;return(null==(t=e.primary_publication)?void 0:t.id)===n||e.id===(null==l?void 0:l.id)}):h,postAsUser:u,handleUpdatePostAsUser:m}}},56878:function(e,t,n){n.d(t,{g:()=>X});var r=n(69277),o=n(70408),i=n(79785),a=n(4006),l=n(32485),s=n.n(l),u=n(75107),d=n(17402),c=n(15734),p=n.n(c),m=n(34746),h=n(5109),f=n(84605),g=n(70145),b=n(58292),v=n(62578),y=n(86500),Y=n(53928),_=n(94729),w=n(68349),S=n(57023),C=n(43954),k=n(25859),I=n(38093),N=n(16993),E=n(84843),F=n(63136),D=n(39318);function A(){let e=(0,i._)(["We've sent an email to ",". Click the magic link or enter the code below:"]);return A=function(){return e},e}function T(){let e=(0,i._)(["We've sent an email to ",". Click the magic link inside to continue."]);return T=function(){return e},e}function P(e){var t,n;let{isOpen:r,onClose:o,user:i,pub:l,otpLoginEnabled:s,onboardingRedirect:u}=e,{iString:d,iTemplate:c}=(0,f.GO)();return(0,a.FD)(N.aF,{isOpen:r,onClose:o,className:"finish-magic-login-modal",children:[(0,a.Y)(N.rQ,{icon:(0,a.Y)(E.qx,{icon:(0,a.Y)(C.A,{size:20})}),title:d("Check your email to continue"),description:s?(0,a.Y)(F.EY,{children:c(A(),null!=(t=null==i?void 0:i.email)?t:"your email address")}):(0,a.Y)(F.EY,{children:c(T(),null!=(n=null==i?void 0:i.email)?n:"your email address")}),alignItems:"center",onClose:o}),(0,a.Y)(N.cw,{children:s?(0,a.Y)(I.Z,{email:null==i?void 0:i.email,redirect:u||document.location.href}):(0,a.Y)(F.EY.B4,{align:"center",color:"secondary",decoration:"underline",children:(0,a.Y)(k.Yq,{href:(0,D.a7q)({for_pub:l.subdomain,with_password:!0}),children:d("Sign in with password instead")})})})]})}var x=n(87087),O=n(89490),L=n(35369),R=n(60322),B=n(8149),U=n(76977),M=n(45859),W=n(81929),H=n(47784),j=n(36372),G=n(56689),q=n(56262),z=n(18947),V=n(49807),J=n(82776);function K(){let e=(0,i._)(["Only "," subscribers can comment on this post"]);return K=function(){return e},e}let Q="commentInput",X=(0,d.forwardRef)((e,t)=>{let{commentBeingEdited:n,parent:i,post:l,autoFocus:u,formClassName:c,saveEdit:m,onCancel:h,onSuccess:b,user:S,freeSignup:C,freeSignupEmail:k,pub:I,token:N,bannedFromNotes:E,alwaysShowButtons:F,mediaClipId:A}=e,{iString:T}=(0,f.GO)(),O=(0,j.d)(),L=(0,g.jN)(),{isOAuthProvider:R,oauthAccessToken:B}=(0,g.ey)(),[M,W]=(0,d.useState)(!1),[H,q]=(0,d.useState)(null),[K,X]=(0,d.useState)(!1),[Z,$]=(0,d.useState)(!1),{enableUserSwitcher:ee,eligiblePostAsUsers:et,postAsUser:en,handleUpdatePostAsUser:er}=(0,v.N)({editingCommentUserId:null==n?void 0:n.user_id,postPublicationId:l.publication_id}),eo=(0,d.useMemo)(()=>{if("undefined"!=typeof localStorage){let e=JSON.parse(localStorage.getItem(Q)||"{}");if(e.postId===l.id)return{value:e.value,alsoShareToNotes:!!e.alsoShareToNotes};localStorage.removeItem(Q)}},[]),el=(0,r._)({value:null==n?void 0:n.body,alsoShareToNotes:!1,loading:!1,error:null},eo),[{value:es,alsoShareToNotes:eu,loading:ed,error:ec},ep]=(0,d.useState)(el),em=e=>ep(t=>(0,o._)((0,r._)({},t),{value:e})),eh=(0,d.useRef)(null),ef=(0,d.useRef)(null);(0,d.useImperativeHandle)(t,()=>({focus(){var e;null==(e=eh.current)||e.focus()},getTextareaRef:()=>eh}),[]),(0,d.useEffect)(()=>{if(u){var e;null==(e=eh.current)||e.focus()}},[]);let eg=!(null==S?void 0:S.name),[eb,ev]=(0,d.useState)(!1),ey=async()=>{(0,y.u4)(y.qY.COMMENT_PAYWALL_SHOWN,{post_id:l.id,post_type:l.type,parent_id:null==i?void 0:i.id}),(0,Y.jN)(Y.ti.TRACK_PAYWALL_SHOWN),ev(!0)},eY=async()=>{(0,y.u4)(y.qY.FINISH_MAGIC_LOGIN_MODAL_SHOWN,{post_id:l.id,post_type:l.type,parent_id:null==i?void 0:i.id}),await ek(),$(!0)},[e_,ew]=(0,d.useState)(!1),eS=async()=>{(0,y.u4)(y.qY.PROFILE_UPDATER_SHOWN,{post_id:l.id,parent_id:null==i?void 0:i.id}),ew(!0)},eC=(0,d.useRef)(!1),ek=async()=>{if(!S)return void console.error("cannot sendLoginEmail, user not defined");if(!eC.current){eC.current=!0;try{var e;let t=await (0,_.x6)("/api/v1/email-login",{method:"POST",json:{email:S.email,redirect:null==(e=document.location.href.split("?")[0])?void 0:e.split("#")[0]}});"optional"===t.verification_code&&(W(!0),t.onboarding_redirect&&q(t.onboarding_redirect))}catch(e){alert((0,w.uX)(e))}}},eI=()=>{localStorage.setItem(Q,JSON.stringify({postId:l.id,value:es,alsoShareToNotes:eu}))},eN=async()=>{if(n){ep(e=>(0,o._)((0,r._)({},e),{loading:!0}));try{let e=await (null==m?void 0:m(es));eF(e)}catch(e){ep(t=>(0,o._)((0,r._)({},t),{loading:!1,error:e}))}}else eE()},eE=async function(){var e;let{profileUpdated:t}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(ed)return;if(!(0,J.canPostComments)(S,l,I).canReply){eI(),await ey(),await (0,G.c)(600),ep(e=>(0,o._)((0,r._)({},e),{error:T("Please sign in.")}));return}if(eg&&!t){eI(),R?(X(!0),ep(e=>(0,o._)((0,r._)({},e),{loading:!1,error:T("Please set your profile name to comment.")}))):(X(!1),await eS(),await (0,G.c)(600),ep(e=>(0,o._)((0,r._)({},e),{error:T("Please update your profile.")})));return}ep(e=>(0,o._)((0,r._)({},e),{loading:!0}));let n={body:null==(e=eh.current)?void 0:e.value,token:N,postAsUserId:null==en?void 0:en.id};A&&(n.mediaClipId=A);try{let e;if(eu){let t=await L.post("/api/v1/comment/attachment").send({type:"link",url:i?(0,z.XB)(l,i,I):(0,D.wu9)(I,l)}),o=null==t?void 0:t.body;if(o){let t=(0,r._)({},n);t.attachmentIds=[o.id],e=await L.post("/api/v1/comment/feed").send(t)}else console.warn("Error creating attachment")}i&&(n.parent_id=i.id);let t=await L.post("/api/v1/post/".concat(l.id,"/comment")).send(n);if(localStorage.removeItem(Q),!(null==S?void 0:S.profile_set_up_at)&&!R){let{body:{count:e}}=await p().get("/api/v1/user/profile_role_count");if(e>=2){let e=(0,D.yRP)("".concat((0,D.Ewe)(),"/profile/start"),{commentProfileFlow:!0,next:(0,z.XB)(l,t.body,I)});return(0,w.V2)(e,{local_navigation:!1}),!1}}eF({notesComment:e,res:t})}catch(e){e.response&&403===e.response.statusCode&&(S&&S.is_magic?await eY():await ey()),ep(t=>(0,o._)((0,r._)({},t),{loading:!1,error:e}))}},eF=e=>{let{res:t,notesComment:n}=e;if(!1!==t){if(b&&!eg){if(eu&&n){let e=(0,V.Zgx)(n.body);O.popToast(()=>(0,a.Y)(j.y,{text:T("Shared to Notes"),cta:T("View now"),href:e}))}em(""),b(t.body)}else{let e=(0,x.PG)(l,I);R?(0,w.V2)((0,x.EQ)(l,I,null!=B?B:"")):window.location.pathname===e?window.location.reload():(0,w.V2)((0,x.PG)(l,I,eu?{feedCommentUrl:(0,V.Zgx)(t.body)}:{}))}ep(e=>(0,o._)((0,r._)({},e),{loading:!1}))}};return(0,a.FD)(U.pT,{"data-test-id":"comment-input",flex:"grow",className:s()({comment:n}),children:[(0,a.Y)("form",{className:s()("form-CkZ7Kt",c),onSubmit:e=>{e.preventDefault(),eN()},ref:ef,children:(0,a.Y)(ea,{user:S,commentBeingEdited:n,post:l,pub:I,value:es,bodyInputRef:eh,onInput:e=>{let t=e.currentTarget.value;if(!(0,J.canPostComments)(S,l,I).canReply){e.preventDefault(),ey();return}em(t)},onKeyDown:e=>{var t,n;if(null==S?void 0:S.is_magic){e&&e.preventDefault(),eY();return}if(!(0,J.canPostComments)(S,l,I).canReply){e.preventDefault(),ey();return}"Escape"===e.key&&(null==(t=eh.current)?void 0:t.value.trim())===""?(null==(n=eh.current)||n.blur(),null==h||h()):"Enter"===e.key&&e.metaKey&&eN()},bannedFromNotes:E,alsoShareToNotes:eu,onShareToNotesChange:()=>ep(e=>(0,o._)((0,r._)({},e),{alsoShareToNotes:!eu})),onCancel:()=>{h?h():em("")},error:ec,loading:ed,alwaysShowButtons:F,isReplying:!!i,showProfileSetupLinkOnError:K,enableUserSwitcher:ee,eligiblePostAsUsers:null!=et?et:[],postAsUser:en,handleUpdatePostAsUser:er})}),(0,a.Y)(ei,{user:S,freeSignup:C,freeSignupEmail:k,pub:I,post:l,token:N,isProfileUpdateModalOpen:e_,setIsProfileUpdateModalOpen:ew,isPaywallModalOpen:eb,setIsPaywallModalOpen:ev,onProfileUpdaterSuccess:e=>"boolean"!=typeof e||!!(e&&eE({profileUpdated:e}))}),(0,a.Y)(P,{isOpen:Z,onClose:()=>$(!1),user:S,pub:I,otpLoginEnabled:M,onboardingRedirect:H})]})}),Z=e=>{let{error:t,showProfileSetupLinkOnError:n}=e,{iString:r}=(0,f.GO)();if(!t)return null;let o="string"==typeof t?t:(0,w.uX)(t,"Something went wrong.");return(0,a.FD)(U.pT,{direction:"column",gap:4,children:[(0,a.Y)(W.vw,{priority:"secondary",theme:"error",flex:"auto",children:o}),n&&(0,a.Y)(F.EY.B3,{children:(0,a.Y)("a",{href:"".concat((0,D.Ewe)(),"/profile/edit"),target:"_blank",children:r("Set up profile")})})]})},$=e=>{let{alsoShareToNotes:t,onChange:n}=e,{iString:r}=(0,f.GO)();return(0,a.FD)(U.pT,{as:"label",gap:12,alignItems:"center",justifyContent:"center",children:[(0,a.Y)(R.S,{name:"also_feed",checked:t,onChange:n}),(0,a.Y)(F.EY.B3,{color:"secondary",children:r("Also share to Notes")})]})},ee=e=>{let{bodyInputRef:t,value:n,onInput:r,onKeyDown:o,iString:i,disabled:l}=e;return(0,a.Y)(H.A,{ref:t,name:"body",placeholder:i("Write a comment..."),defaultRows:4,maxRows:24,value:n||"",onInput:r,onKeyDown:o,className:"input-qHk4bN",disabled:l,"aria-label":i("Write a comment...")})},et=e=>{let{isEditing:t,isReplying:n,bannedFromNotes:r,alsoShareToNotes:o,onShareToNotesChange:i,onCancel:l,loading:s,disableSubmit:u}=e;return(0,a.FD)(U.fI,{alignItems:"center",justifyContent:"space-between",children:[!t&&!r&&(0,a.Y)($,{alsoShareToNotes:o,onChange:i}),(0,a.FD)(en,{children:[(0,a.Y)(er,{onCancel:l}),(0,a.Y)(eo,{isEditing:t,isReplying:n,loading:s,disabled:u})]})]})},en=e=>{let{children:t}=e;return(0,a.Y)(U.fI,{gap:8,justifyContent:"end",flex:"grow",children:t})},er=e=>{let{onCancel:t}=e,{iString:n}=(0,f.GO)();return(0,a.Y)(L.$n,{priority:"secondary",onClick:t,children:n("Cancel")})},eo=e=>{let{isEditing:t,isReplying:n,loading:r,disabled:o}=e,{iString:i}=(0,f.GO)();return(0,a.Y)(L.$n,{priority:"primary",type:"submit",loading:r,disabled:o,children:i(t?"Save":n?"Reply":"Post")})},ei=e=>{let{user:t,freeSignup:n,freeSignupEmail:r,pub:o,post:i,token:l,isProfileUpdateModalOpen:s,setIsProfileUpdateModalOpen:u,isPaywallModalOpen:d,setIsPaywallModalOpen:c,onProfileUpdaterSuccess:p}=e,{iString:g,iTemplate:b}=(0,f.GO)();return(0,a.FD)(a.FK,{children:[(0,a.Y)(h.QL,{isOpen:s,onClose:e=>{u(!1),p(e)},user:t,freeSignup:n,freeSignupEmail:r,optionalPhoto:!0,token:l,text:g("Save and post comment")}),(0,a.Y)(m.EH,{isOpen:d,onClose:()=>c(!1),user:t,freeSignup:n,freeSignupEmail:r,publication:o,post:i,title:b(K(),(0,q.isFoundingAudience)(i.audience)?"founding":"paid"),reauthenticationTitle:g("To post a comment, please re-authenticate.")})]})},ea=e=>{let{user:t,commentBeingEdited:n,post:r,pub:o,value:i,bodyInputRef:l,onInput:s,onKeyDown:u,bannedFromNotes:d,alsoShareToNotes:c,onShareToNotesChange:p,onCancel:m,error:h,loading:g,alwaysShowButtons:v,isReplying:y,showProfileSetupLinkOnError:Y,enableUserSwitcher:_,eligiblePostAsUsers:w,postAsUser:C,handleUpdatePostAsUser:k}=e,{iString:I}=(0,f.GO)(),N=!(null==i?void 0:i.trim());return(0,a.FD)(a.FK,{children:[_&&w&&w.length>1?(0,a.Y)(el,{user:null!=C?C:t,eligiblePostAsUsers:w,handleUpdatePostAsUser:k}):(0,a.Y)(b.bB,{size:32,user:t}),(0,a.FD)(U.I1,{flex:"grow",gap:8,children:[n&&(0,a.Y)(S.P,{comment:n,post:r,pub:o,isCollapsed:!0,userBanned:!1,hideContextMenu:!0,onChange:()=>{},startEdit:()=>{},startReport:()=>{},openBan:()=>{}}),(0,a.Y)(ee,{bodyInputRef:l,value:i,onInput:s,onKeyDown:u,iString:I,disabled:g}),(0,a.Y)(Z,{error:h,showProfileSetupLinkOnError:Y}),(0,a.Y)(B.N,{open:!N||!!v,children:(0,a.Y)(et,{isReplying:y,isEditing:!!n,bannedFromNotes:d,alsoShareToNotes:c,onShareToNotesChange:p,onCancel:m,loading:g,disableSubmit:N})})]})]})};function el(e){let{user:t,eligiblePostAsUsers:n,handleUpdatePostAsUser:r}=e;return(0,a.Y)(M.W1,{trigger:(0,a.FD)(O.az,{className:"postAsUserSwitcher-IPqxbX",children:[(0,a.Y)(b.bB,{size:32,user:t}),(0,a.Y)(u.A,{size:12,className:"postAsUserSwitcherIcon-Q4hhV0"})]}),children:n.map(e=>(0,a.Y)(M.Dr,{onClick:()=>r(e),children:e.name},e.id))})}},57023:function(e,t,n){n.d(t,{P:()=>N});var r=n(79785),o=n(4006),i=n(69843),a=n.n(i),l=n(17402),s=n(84777),u=n(84605),d=n(46271),c=n(27332),p=n(25859),m=n(58292),h=n(1124),f=n(42774),g=n(87087),b=n(89490),v=n(35369),y=n(76977),Y=n(63136),_=n(16291),w=n(18947),S=n(82776),C=n(57324),k=n(70515);function I(){let e=(0,r._)(["Edited"]);return I=function(){return e},e}function N(e){let{post:t,pub:n,comment:r,isCollapsed:i,onProfileClick:a,userBanned:l,toggleCollapse:s,userPendingApproval:u,onChange:p,startEdit:m,startReport:f,openBan:g,hideContextMenu:b}=e,v=(0,d.Jd)();return(0,o.FD)(y.Ye,{children:[(0,o.FD)(O,{children:[(0,o.Y)(c.X6,{children:(0,o.FD)(c.qv,{children:[(0,o.Y)(E,{comment:r,onClick:a}),(0,o.Y)(F,{comment:r}),(0,o.Y)(A,{comment:r,post:t,pub:n}),(0,o.Y)(T,{comment:r})]})}),!i&&(0,o.Y)(x,{comment:r,userBanned:l,userPendingApproval:u}),(0,o.Y)(P,{comment:r,isCollapsed:i,toggleCollapse:s})]}),(0,o.Y)(L,{onClick:s}),!b&&(0,o.Y)(h.f,{comment:r,pub:n,post:t,user:v,onChange:p,startEdit:m,startReport:f,openBan:g,isCollapsed:i,toggleCollapse:s})]})}function E(e){let{comment:t,onClick:n}=e,{iString:r}=(0,u.GO)();if(t.name&&!a()(t.user_id))return(0,o.Y)(Y.EY.B4,{color:"primary",display:"flex",gap:6,children:(0,o.Y)(c.wF,{user:(0,g.DH)(t),onClick:n?()=>n(t):void 0})});let i=r(t.hidden?"Comment hidden":t.deleted?"Comment deleted":(0,k.Pp)(t)?"Anonymous":"Comment removed");return(0,o.Y)(Y.EY.B4,{color:"secondary",children:i})}function F(e){var t,n,r,i,a;let{comment:l}=e,u=(null==(t=l.metadata)?void 0:t.author_on_other_pub)&&!l.metadata.is_author,d=(null==(r=l.metadata)||null==(n=r.author_on_other_pub)?void 0:n.id)&&!l.hidden;return u?d?(0,o.Y)(s.m,{pubId:null!=(a=null==(i=l.metadata.author_on_other_pub)?void 0:i.id)?a:0,trigger:(0,o.Y)(D,{comment:l})}):(0,o.Y)(D,{comment:l}):null}function D(e){var t;let{comment:n}=e,r=(0,d.Jd)();return n.metadata.author_on_other_pub&&r?(0,o.Y)(Y.EY.B4,{as:"span",color:"secondary",weight:"regular",children:(0,o.Y)(p.RC,{publication:n.metadata.author_on_other_pub,utm_source:C.VU.substackFeedItem,utm_content:C.fL.commentMetadata,user:r,children:(0,o.FD)("span",{children:[(0,S.truncateText)(null==(t=n.metadata.author_on_other_pub)?void 0:t.name,32)," "]})})}):null}function A(e){let{comment:t,post:n,pub:r}=e;return(0,o.Y)(Y.Yq,{href:(0,w.XB)(n,t,r),onClick:e=>null===this||void 0===this?void 0:this.onDateClick(e),rel:"nofollow","data-native":!0,color:"secondary",title:c.M6.format((0,_.A)(t.date).toDate()),children:(0,o.Y)(m.iE,{timestamp:t.date})})}function T(e){let{comment:t}=e,{iTemplate:n}=(0,u.GO)();return t.edited_at?(0,o.Y)(Y.EY.B4,{as:"span",fontStyle:"italic",decoration:"hover-underline",cursor:"pointer",color:"tertiary",title:c.M6.format((0,_.A)(t.edited_at).toDate()),children:n(I())}):null}function P(e){let{comment:t,toggleCollapse:n,isCollapsed:r}=e,{iString:i}=(0,u.GO)(),[a,s]=(0,l.useState)(!1);if(!r||!n)return null;let d=e=>{var t,n;return(null!=(t=e.children)?t:[]).length+(null!=(n=e.children)?n:[]).reduce((e,t)=>e+d(t),0)},c=d(t),p=i(a?"Loading":c>0?"Show replies":"Show comment");return(0,o.Y)(y.fI,{children:(0,o.Y)(v.$n,{size:"sm",flex:"auto",priority:"secondary-outline",maxHeight:28,onClick:()=>{s(!0),setTimeout(()=>{n(),s(!1)},0)},children:p})})}function x(e){let{comment:t,userBanned:n,userPendingApproval:r}=e,i=(0,f.Ud)({comment:t}),a=(0,f.Q0)({comment:t,userBanned:n}),l=(0,f.GL)({comment:t,userPendingApproval:r});return i||a||l?(0,o.FD)(f.FS,{children:[i,a,l]}):null}let O=(0,b.I4)({display:"flex",direction:"column",gap:4}),L=(0,b.I4)({display:"flex",direction:"column",flex:"grow"})},47784:function(e,t,n){n.d(t,{A:()=>m});var r=n(69277),o=n(70408),i=n(32641),a=n(4006),l=n(32485),s=n.n(l),u=n(17402),d=n(11587),c=n(65842),p=n(24311);let m=(0,u.forwardRef)((e,t)=>{var{className:n,error:l=!1,defaultRows:m=4,maxRows:h,value:f,onChange:g}=e,b=(0,i._)(e,["className","error","defaultRows","maxRows","value","onChange"]);let{innerRef:v,combinedRef:y}=(0,c.N)(t),{value:Y,handleChange:_}=(0,d.u)({value:f,onChange:g}),w=(0,u.useCallback)(()=>{let e=v.current;if(!e)return;let t=window.getComputedStyle(e),n=parseInt(t.borderTopWidth)+parseInt(t.borderBottomWidth),r=parseInt(t.paddingTop)+parseInt(t.paddingBottom),o=parseInt(t.lineHeight);e.style.height="auto";let i=h?o*h+n+r:1/0,a=o*m+n+r,l=Math.min(Math.max(e.scrollHeight+n,a),i);e.style.height="".concat(l,"px")},[m,h]);return(0,u.useEffect)(()=>{w(),document.fonts&&"loaded"!==document.fonts.status&&document.fonts.ready.then(w)},[w,f]),(0,u.useEffect)(()=>(window.addEventListener("resize",w),()=>window.removeEventListener("resize",w)),[w]),(0,a.Y)(d.T,(0,o._)((0,r._)({},b),{value:Y,onChange:e=>{_(e),w()},rows:m,className:s()(n,p.A.autogrowing),ref:y,error:l}))})}}]);