!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@538433c"};var t=(new e.Error).stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="67704cf4-577a-4eb3-a71e-4ea046da6a3f",e._sentryDebugIdIdentifier="sentry-dbid-67704cf4-577a-4eb3-a71e-4ea046da6a3f")}catch(e){}}();"use strict";(self.webpackChunksubstack=self.webpackChunksubstack||[]).push([["75326"],{90117:function(e,t,n){n.d(t,{A:()=>i});let i={outer:"outer-cgmpdg",blur:"blur-gBxOTe",visible:"visible-noUyc6",icon:"icon-mx19LD"}},45897:function(e,t,n){n.d(t,{A:()=>i});let i={composer:"composer-ENKUUa",inputBox:"inputBox-GGEKcH",modalContext:"modalContext-f9yafG",submit:"submit-Y_w6uo"}},10168:function(e,t,n){n.d(t,{A:()=>d});var i=n(69277),l=n(70408),r=n(32641),o=n(4006),a=n(97731);let d=e=>{var{size:t=24,color:n="var(--color-fg-primary)"}=e,d=(0,r._)(e,["size","color"]);return(0,o.Y)(a.A,(0,l._)((0,i._)({},d),{name:"FilledReplyIcon",svgParams:{viewBox:"0 0 24 24"},stroke:"none",width:t,height:t,fill:n,children:(0,o.Y)("path",{d:"M10.2977 21.9891C11.0145 21.9891 11.5309 21.4441 11.5309 20.7139V16.5504H11.8367C15.9262 16.5504 18.498 17.6186 20.3426 21.1826C20.7114 21.8801 21.1963 21.9891 21.639 21.9891C22.1976 21.9891 22.7246 21.466 22.7246 20.5286C22.7246 12.4741 19.4256 7.4496 11.8367 7.4496H11.5309V3.3297C11.5309 2.59945 11.0145 2 10.2767 2C9.76024 2 9.41234 2.22888 8.85375 2.77384L0.537549 10.8174C0.126482 11.2207 0 11.624 0 11.9946C0 12.3542 0.137023 12.7684 0.537549 13.1608L8.85375 21.2807C9.35964 21.7711 9.78129 21.9891 10.2977 21.9891Z"})}))}},59085:function(e,t,n){n.d(t,{A:()=>d});var i=n(69277),l=n(70408),r=n(32641),o=n(4006),a=n(97731);let d=e=>{var{size:t=24,color:n="var(--color-fg-primary)"}=e,d=(0,r._)(e,["size","color"]);return(0,o.Y)(a.A,(0,l._)((0,i._)({},d),{name:"SkinnyPinIcon",svgParams:{viewBox:"0 0 24 24"},stroke:"none",width:t,height:t,fill:n,children:(0,o.Y)("path",{d:"M4 14.8571C4 15.7323 4.58687 16.3089 5.51351 16.3089H11.0836V21.117C11.0836 22.6924 11.7426 24 12 24C12.2471 24 12.906 22.6924 12.906 21.117V16.3089H18.4762C19.4028 16.3089 19.9896 15.7323 19.9896 14.8571C19.9896 12.6847 18.2497 10.3887 15.3565 9.33849L15.0167 4.6126C16.5199 3.75804 17.7554 2.79021 18.2908 2.10038C18.5585 1.75032 18.6924 1.40025 18.6924 1.09137C18.6924 0.463323 18.2085 0 17.4878 0H6.51222C5.7812 0 5.30759 0.463323 5.30759 1.09137C5.30759 1.40025 5.43115 1.75032 5.69883 2.10038C6.23423 2.79021 7.46975 3.75804 8.97296 4.6126L8.6332 9.33849C5.74002 10.3887 4 12.6847 4 14.8571Z"})}))}},74546:function(e,t,n){n.d(t,{n:()=>a});var i=n(4006),l=n(50802),r=n(17402),o=n(35369);function a(e){let{mediaUpload:t,selectedFile:n,onInputChange:a}=e,d=(0,r.useRef)();return t||n?null:(0,i.FD)(o.K0,{priority:"tertiary",size:"md",onClick:()=>{var e;null==(e=d.current)||e.click()},children:[(0,i.Y)(l.A,{size:20}),(0,i.Y)("input",{type:"file",accept:"video/*",multiple:!0,onChange:a,ref:d,style:{display:"none"}})]})}},73724:function(e,t,n){n.d(t,{E:()=>o});var i=n(32641),l=n(33325),r=n(94729);function o(e,t){var{pathname:n,getPageKey:o,getPageInit:a}=e,d=(0,i._)(e,["pathname","getPageKey","getPageInit"]);return(0,l.Ay)((e,t)=>o({page:e,lastPage:t,init:d}),e=>{let t=a({key:e,init:d});return(0,r.x6)(n,t)},t)}},2991:function(e,t,n){n.d(t,{J:()=>a});var i=n(69277),l=n(70408),r=n(4006),o=n(21398);function a(e){return(0,r.Y)(o.Ic,(0,l._)((0,i._)({},e),{module:"./ChatTextEditor",resolve:e=>e.ChatTextEditor,onRequest:()=>n.e("86308").then(n.bind(n,95375))}))}},79515:function(e,t,n){n.d(t,{Qi:()=>C,iC:()=>f,sl:()=>g});var i=n(69277),l=n(70408),r=n(32641),o=n(4006),a=n(17402),d=n(91461),c=n(84605),s=n(89490),u=n(35369),p=n(76977),m=n(63136),h=n(49807),y=n(57324);function f(e){var{hasLeftChat:t,isPaywallPreview:n,publication:a,isFounding:d,isFreeSubscribed:c,footerMessage:s,footerIcon:u,handleJoinChat:h}=e,y=(0,r._)(e,["hasLeftChat","isPaywallPreview","publication","isFounding","isFreeSubscribed","footerMessage","footerIcon","handleJoinChat"]);return(0,o.Y)(b,{children:(0,o.Y)(_,{children:(0,o.FD)(p.I1,{gap:20,alignItems:"center",children:[(0,o.FD)(p.Ye,{gap:8,alignItems:"center",children:[u,(0,o.Y)(m.EY.B3,{weight:"medium",color:"primary",align:"center",children:s})]}),(0,o.Y)(v,(0,l._)((0,i._)({},y),{hasLeftChat:t,isPaywallPreview:n,publication:a,isFounding:d,isFreeSubscribed:c,pubSettings:null==a?void 0:a.threads_v2_settings,handleJoinChat:h}))]})})})}function g(){return(0,o.Y)(b,{children:(0,o.Y)(_,{children:(0,o.Y)(u.$n,{priority:"secondary",loading:!0,minWidth:320,children:(0,o.Y)(a.Fragment,{})})})})}let b=(0,s.I4)({display:"flex",paddingX:20,paddingBottom:20,justifyContent:"center"}),_=(0,s.I4)({display:"flex",flex:"grow",radius:"md",justifyContent:"center",alignItems:"center",padding:20,bg:"primary-hover",gap:12});function v(e){let{hasLeftChat:t,isPaywallPreview:n,publication:i,isFounding:l,isFreeSubscribed:r,pubSettings:a,hasPaidPaywall:d,hasFoundingPaywall:s,handleJoinChat:p}=e,{iString:m}=(0,c.GO)();if(t)return(0,o.Y)(u.$n,{priority:"primary",onClick:p,children:m("Join chat")});if(n&&i)switch(i.paywall_chat){case"free":return(0,o.Y)(w,{planType:"free",publication:i,children:m("Subscribe")});case"paid":case"founding":return(0,o.Y)(Y,{publication:i,buttonText:m("Subscribe"),planType:i.paywall_chat});default:return null}return((null==a?void 0:a.create_thread_minimum_role)==="founding"||s)&&!l&&i?(0,o.Y)(Y,{publication:i,buttonText:m("Upgrade"),planType:"founding"}):((null==a?void 0:a.create_thread_minimum_role)==="paid"||d)&&r&&i?(0,o.Y)(Y,{publication:i,buttonText:m("Upgrade"),planType:"paid"}):null}function Y(e){var t,n,i;let l,r,{publication:d,buttonText:s,planType:u}=e,{iString:p}=(0,c.GO)(),m=null!=(n=null==(t=d.plans)?void 0:t.filter(e=>e.active))?n:[],h="founding"===u?m.find(e=>{var t;return null==(t=e.metadata)?void 0:t.founding}):null!=(i=m.find(e=>"month"===e.interval))?i:m[0],y=p("Subscribe"),f=(0,a.useMemo)(()=>{var e;return new Intl.NumberFormat(void 0,{style:"currency",currency:null!=(e=null==h?void 0:h.currency)?e:"USD",trailingZeroDisplay:"stripIfInteger"})},[null==h?void 0:h.currency]);return(0,o.FD)(w,{publication:d,planType:u,children:[s||y,h?" ∙ ".concat((l="".concat(f.format(h.amount/100)," "),r="year"===h.interval?"a year":"a month","".concat(l).concat(r))):null]})}function w(e){let{publication:t,planType:n,children:l}=e;return(0,o.Y)(p.I1,{width:320,children:(0,o.Y)(u.$n,{priority:"primary",href:(0,h.eV6)(t,{addBase:!0,params:(0,i._)({utm_source:y.VU.substack,utm_medium:y.Jn.web,utm_content:y.fL.chat,next:window.location.href},"founding"===n?{plan:"founding"}:{})}),children:l})})}function C(){return(0,o.Y)(d.A,{size:14,color:"var(--color-fg-primary)"})}},20394:function(e,t,n){n.d(t,{G:()=>w});var i=n(69277),l=n(70408),r=n(4006),o=n(46271),a=n(89490),d=n(97515),c=n(63175),s=n(594),u=n(3046),p=n(46647),m=n(35369),h=n(76977);function y(e){let{onClick:t}=e;return(0,r.Y)(h.pT,{justifyContent:"center",padding:8,children:(0,r.Y)(m.$n,{priority:"tertiary",onClick:t,children:"Load more"})})}var f=n(87782),g=n(18464),b=n(167),_=n(87545),v=n(99051),Y=n(57324);function w(e){let{chatItem:t,onSelectPost:n,isPaid:m,isFounding:h,isFreeSubscribed:w,pub:P,isReadOnly:F,onBack:D,isPreview:T,index:I}=e,k=(0,o.Jd)();if("day-marker"===t.type)return(0,r.Y)(a.az,{paddingTop:16*(0===I),children:(0,r.Y)(p.D,{timestamp:t.item.timestamp},t.id)});if("new-marker"===t.type)return(0,r.Y)(f.F,{},t.id);if("community-post"===t.type){let{item:e}=t;return n?(0,r.Y)(a.az,{paddingX:16,paddingBottom:16,children:(0,r.Y)(_.AJ,{item:e.isNew&&k?(0,l._)((0,i._)({},e),{user:k}):e,onSelect:n,isPaid:m,isFounding:h,isFreeSubscribed:w,pub:P,isReadOnly:F},e.communityPost.id)}):null}if("parent-post"===t.type){let{item:e}=t;return(0,r.FD)(c.DF,{children:[(0,r.Y)(_.AJ,{item:e,pub:P,isPaid:m,isFounding:h,isFreeSubscribed:w,isReadOnly:!1,onSelect:()=>{},showReply:!1,onDelete:()=>null==D?void 0:D()}),T?(0,r.Y)(g.r9,{}):null]})}if("message-group"===t.type)return(0,r.Y)(a.az,{paddingX:16,paddingBottom:16,children:(0,r.Y)(u.$4,{group:t.item,direction:t.item.author.id===(null==k?void 0:k.id)?"outgoing":"incoming",isPending:!1,showName:!0},t.id)});if("load-more"===t.type)return(0,r.Y)(y,{onClick:t.item.onClick},t.id);if("loading"===t.type)return(0,r.Y)(s.W,{},t.id);if("chat-zero"===t.type){let{title:e,description:n,includeUpsell:i}=t.item;return(0,r.Y)(d.p,{title:e,description:n,button:i&&P?(0,r.Y)(v.no,{pub:P,utm_source:Y.VU.webChatPaywall}):void 0},t.id)}if("divider"===t.type){let{replyCount:e,parentPost:n,parentReply:i}=t.item;return(0,r.Y)(a.az,{paddingX:16,children:(0,r.Y)(b.wG,{replyCount:e,parentPost:n,parentReply:i})})}if("error"===t.type)return(0,r.Y)(b.v0,{});if("parent-reply"===t.type)return(0,r.Y)(c.DF,{children:(0,r.Y)(b.Wf,{reply:t.item.parentReply,author:t.item.author})});if("paywall"===t.type&&P){let{item:e}=t;return"communityPost"in e?(0,r.Y)(C,{children:(0,r.Y)(_.AJ,{item:e,pub:P,isPaid:m,isFounding:h,isFreeSubscribed:w,isReadOnly:!0,onSelect:()=>{},showReply:!1})}):(0,r.Y)(C,{css:{paddingTop:32},children:(0,r.Y)(b.pU,{user:e.user,showReply:!1,analyticsParams:{publication_id:P.id,community_post_id:e.postId},audience:e.audience,pub:P})})}return null}let C=(0,a.I4)({padding:16})},65228:function(e,t,n){n.d(t,{L:()=>b});var i=n(4006),l=n(84605),r=n(46271),o=n(86500),a=n(24078),d=n(17028),c=n(81929),s=n(31679),u=n(8665),p=n(62488),m=n(93427),h=n(49095),y=n(16291),f=n(15567),g=n(35407);function b(e){var t,n,l,c;let{item:b,onSelect:v,isSelected:Y,isUnread:w,tab:C}=e,P=(0,p.Z)(),F=(0,r.Jd)(),D=null==(t=b.messageThread.members.find(e=>e.user_id!==(null==F?void 0:F.id)))?void 0:t.user;if(!D)return console.error("No member for DM conversation ".concat(b.messageThread.id)),null;let{recentMessage:T}=b,I=T&&(null==(n=b.messageThread.members.find(e=>T.comment.user_id===e.user_id))?void 0:n.user);return(0,i.FD)(s._h,{isSelected:Y,onClick:e=>{let t=b.messageThread.id;(0,o.u4)(o.qY.CHAT_INBOX_CONVERSATION_CLICKED,{surface:P,tab:C,type:"dm",conversation_id:t}),v(t,e)},href:(0,f.tv)(b.messageThread.id),children:[w&&(0,i.Y)(m.XV,{className:g.A.unreadDot}),(0,i.Y)(a.eu,{user:D,size:56}),(0,i.FD)(s.Ru,{children:[(0,i.FD)(d.fI,{alignItems:"center",gap:8,children:[(0,i.FD)(d.fI,{gap:12,flex:"grow",children:[(0,i.Y)(d.EY.B3,{weight:"medium",ellipsis:!0,children:D.name}),D.bestseller_tier||(null==(l=D.status)?void 0:l.badge)?(0,i.Y)(h.UserStatusSymbols,{inline:!0,status:D.status,size:"sm",userId:D.id}):null,"requests"===C&&(0,i.Y)(_,{item:b})]}),(null==T?void 0:T.comment)&&(0,i.Y)(d.EY.B5,{color:"secondary",children:(0,y.A)(T.comment.created_at).chatTime()}),b.isPinned&&(0,i.Y)(u.Q,{})]}),T&&(0,i.Y)(s.C4,{unread:w,children:(0,i.Y)(s.YP,{comment:T.comment,link:null==(c=T.link_metadata)?void 0:c.title,outgoing:(null==I?void 0:I.id)===(null==F?void 0:F.id),fallbackText:b.subtitleBody})})]})]})}function _(e){let{item:t}=e,{iString:n}=(0,l.GO)(),{subscriberContext:r}=t,o=null==r?void 0:r.membershipState,a=o&&["free_signup","subscribed"].includes(o);return r&&a?(0,i.Y)(c.vw,{theme:"subscribed"===o?"paid":"default",children:n(r.isFounding?"Founding":"subscribed"===o?"Paid":"Free")}):null}},31679:function(e,t,n){n.d(t,{C4:()=>y,Ru:()=>h,S:()=>g,YP:()=>f,_h:()=>m});var i=n(69277),l=n(32641),r=n(4006),o=n(32485),a=n.n(o),d=n(89490),c=n(17028),s=n(76977),u=n(22602),p=n(35407);function m(e){var{isSelected:t,className:n}=e,o=(0,l._)(e,["isSelected","className"]);return(0,r.Y)(s.VP,{children:(0,r.Y)(s.Ye,(0,i._)({className:a()(p.A.chatPublication,n,t&&p.A.selected),as:"a",alignItems:"center",position:"relative",gap:12,paddingY:12,paddingX:16,href:o.href,target:"_blank",rel:"noopener noreferrer",hover:!0,userSelect:"none"},o))})}let h=(0,d.yw)({display:"flex",direction:"column",flex:"grow",minWidth:0,gap:2,alignSelf:"start",justifyContent:"start"});function y(e){let{unread:t,children:n}=e;return(0,r.Y)(c.EY.B4,{display:"flex",color:t?"primary":"secondary",children:(0,r.Y)(c.EY,{as:"span",ellipsis:!0,minWidth:0,children:n})})}function f(e){var t;let{comment:n,outgoing:i,link:l,fallbackText:o}=e;if(n.reported_by_user)return(0,r.Y)("em",{children:"You reported this thread."});let{media_uploads:a}=n,d=(null==a?void 0:a.length)||0,c=null!=(t=null==n?void 0:n.body)?t:void 0,s=i?"You: ":"";return n||(s="New conversation"),l&&(c?s+="\uD83D\uDD17 ".concat(c):l?s+="\uD83D\uDD17 ".concat(l):s+="\uD83D\uDD17 Link"),a&&(c?s+="\uD83D\uDCF8 ".concat(c):d>1?s+="\uD83D\uDCF8 ".concat(d," Images"):s+="\uD83D\uDCF8 Image"),a||l||(c?s+=c:s+=o),(0,r.Y)(r.FK,{children:s})}function g(){return(0,r.Y)(s.VP,{padding:12,gap:8,children:Array(8).fill(0).map(()=>(0,r.Y)(b,{}))})}function b(){return(0,r.FD)(s.fI,{gap:12,padding:8,alignItems:"center",children:[(0,r.Y)(u.O,{radius:"full",width:48,height:48}),(0,r.FD)(s.VP,{gap:8,flex:"grow",children:[(0,r.Y)(u.O,{maxWidth:"".concat(50*Math.random()+50,"%")}),(0,r.Y)(u.O,{maxWidth:"".concat(25*Math.random()+25,"%")})]})]})}},506:function(e,t,n){n.d(t,{HD:()=>j,sv:()=>X,et:()=>K,D1:()=>J,J6:()=>H,Xp:()=>M,rK:()=>$,TO:()=>V});var i=n(69277),l=n(70408),r=n(32641),o=n(4006),a=n(48697),d=n(59612),c=n(17402),s=n(18993),u=n(97731);let p=e=>{var{size:t=24,color:n="var(--color-fg-primary)"}=e,a=(0,r._)(e,["size","color"]);return(0,o.Y)(u.A,(0,l._)((0,i._)({},a),{name:"MessageIconFilled",svgParams:{viewBox:"0 0 24 24"},stroke:"none",width:t,height:t,fill:n,style:{display:"block"},children:(0,o.Y)("path",{d:"M4.84127 22.0503C6.0053 22.0503 8.90565 20.7796 10.5547 19.5962C10.7196 19.4798 10.8553 19.4313 10.9912 19.4313C11.1173 19.4409 11.2434 19.4507 11.3695 19.4507C18.3634 19.4507 23 15.4736 23 10.6429C23 5.76371 18.1111 1.82544 12 1.82544C5.88889 1.82544 1 5.76371 1 10.6429C1 13.7469 2.91093 16.4727 6.02469 18.1411C6.1702 18.2188 6.2187 18.3643 6.1411 18.5097C5.59789 19.4022 4.62787 20.4692 4.25926 20.9542C3.88096 21.4392 4.09436 22.0503 4.84127 22.0503Z"})}))};var m=n(84605),h=n(27332),y=n(74546),f=n(86998),g=n(86500),b=n(24078),_=n(35369),v=n(76977),Y=n(28911),w=n(36372),C=n(45773),P=n(82519),F=n(45859);function D(e){let{visibilityOptions:t,currentVisibility:n,onPick:i}=e,{iString:l}=(0,m.GO)(),r="all_subscribers"===n,a=["only_paid","only_paid_replies"].includes(n),d=["only_founding","only_founding_replies"].includes(n),c=["only_paid","only_founding"].includes(n);return(0,o.FD)(F.W1,{trigger:(0,o.Y)(_.$n,{priority:"secondary",size:"sm",trailing:(0,o.Y)(P.A,{}),children:(0,o.Y)(T,{currentVisibility:n})}),children:[(0,o.Y)(F.j,{children:l("Who is this thread for?")}),t.hasFree&&(0,o.Y)(F.Dr,{onClick:()=>{i("all_subscribers")},trailing:r?(0,o.Y)(C.A,{size:20}):null,children:(0,o.Y)(T,{currentVisibility:"all_subscribers"})}),t.hasPaid&&(0,o.Y)(F.Dr,{onClick:()=>{i(c?"only_paid":"only_paid_replies")},trailing:a?(0,o.Y)(C.A,{size:20}):null,children:(0,o.Y)(T,{currentVisibility:"only_paid"})}),t.hasFounding&&(0,o.Y)(F.Dr,{onClick:()=>{i(c?"only_founding":"only_founding_replies")},trailing:d?(0,o.Y)(C.A,{size:20}):null,children:(0,o.Y)(T,{currentVisibility:"only_founding"})})]})}function T(e){let{currentVisibility:t}=e,{iString:n}=(0,m.GO)();switch(t){case"only_paid":case"only_paid_replies":return(0,o.Y)(o.FK,{children:n("Paid subscribers")});case"only_founding":case"only_founding_replies":return(0,o.Y)(o.FK,{children:n("Founding members")});default:return(0,o.Y)(o.FK,{children:n("Everyone")})}}var I=n(91461);function k(e){let{currentVisibility:t,onPick:n}=e,{iString:i}=(0,m.GO)(),l=["only_founding","only_founding_replies"].includes(t),r=["only_paid_replies","only_founding_replies"].includes(t),a=["only_paid","only_founding"].includes(t);return(0,o.FD)(F.W1,{trigger:(0,o.Y)(_.$n,{priority:"secondary",size:"sm",trailing:(0,o.Y)(P.A,{}),leading:(0,o.Y)(I.A,{size:12}),children:(0,o.Y)(S,{currentVisibility:t})}),children:[(0,o.Y)(F.j,{children:i("Which parts should be paywalled?")}),(0,o.Y)(F.Dr,{onClick:()=>{n(l?"only_founding_replies":"only_paid_replies")},trailing:r?(0,o.Y)(C.A,{size:20}):null,children:(0,o.Y)(S,{currentVisibility:l?"only_founding_replies":"only_paid_replies"})}),(0,o.Y)(F.Dr,{onClick:()=>{n(l?"only_founding":"only_paid")},trailing:a?(0,o.Y)(C.A,{size:20}):null,children:(0,o.Y)(S,{currentVisibility:l?"only_founding":"only_paid"})})]})}function S(e){let{currentVisibility:t}=e,{iString:n}=(0,m.GO)();switch(t){case"only_paid_replies":case"only_founding_replies":return(0,o.Y)(o.FK,{children:n("Paywall replies")});case"only_paid":case"only_founding":return(0,o.Y)(o.FK,{children:n("Paywall everything")});default:return(0,o.Y)(o.FK,{children:n("Unknown")})}}var A=n(34389),E=n(60322),x=n(88762);function O(e){let{options:t,setOption:n}=e,{iString:i}=(0,m.GO)();return(0,o.FD)(v.ov,{gap:8,alignItems:"center",children:[(0,o.Y)(E.S,{size:"xs",checked:t.sendAsEmail,onChange:()=>n("sendAsEmail",!t.sendAsEmail)}),(0,o.Y)(x.JU,{children:i("Send as email")})]})}function N(e){let{options:t,setOption:n}=e,{iString:i}=(0,m.GO)();return(0,o.FD)(v.ov,{gap:8,alignItems:"center",children:[(0,o.Y)(E.S,{size:"xs",checked:t.sendPush,onChange:()=>n("sendPush",!t.sendPush)}),(0,o.Y)(x.JU,{children:i("Send as push")})]})}var R=n(45458),U=n(2991),z=n(99715),L=n(3843),B=n(35407);let M=6;function V(e){let{publication:t,publicationId:n,placeholder:i,maxImagesToUpload:l,publishOptionsEnabled:r,visibilityOptions:a,photosEnabled:d=!1,videoEnabled:s=!1,disabled:u,onSubmit:m,initialFiles:h,handleModalClose:y,handleModalOpen:f,isModalOpen:b,videoPlayerProps:Y,editingPost:w}=e;return(0,c.useEffect)(()=>{b&&(0,g.u4)(g.qY.THREADS_COMPOSER_SCREEN_VIEWED,{publication_id:n})},[b]),(0,o.FD)(o.FK,{children:[(0,o.Y)(v.VP,{justifyContent:"center",paddingX:20,paddingBottom:20,className:B.A.footer,children:(0,o.Y)(v.VP,{radius:"md",justifyContent:"center",alignItems:"center",padding:20,bg:"secondary",gap:12,children:(0,o.Y)(v.VP,{width:320,children:(0,o.Y)(_.$n,{priority:"primary",onClick:()=>f(!0),disabled:u,leading:(0,o.Y)(p,{size:16,color:"var(--color-button-fg)"}),children:i})})})}),t&&(0,o.Y)(j,{isModalOpen:b,publication:t,maxImagesToUpload:l,publishOptionsEnabled:r,visibilityOptions:a,photosEnabled:d,videoEnabled:s,onSubmit:m,handleModalClose:y,initialFiles:h,videoPlayerProps:Y,editingPost:w})]})}function j(e){let{isModalOpen:t,publication:n,maxImagesToUpload:i,publishOptionsEnabled:l,visibilityOptions:r,photosEnabled:a,videoEnabled:d,onSubmit:c,handleModalClose:s,initialFiles:u,videoPlayerProps:p,editingPost:m}=e;return(0,o.Y)(Y.aF,{isOpen:t,onClose:s,fullscreenMobile:!0,width:600,children:(0,o.Y)(G,{publication:n,maxImagesToUpload:i,publishOptionsEnabled:l,visibilityOptions:r,photosEnabled:a,videoEnabled:d,onSubmit:c,handleModalClose:s,initialFiles:u,videoPlayerProps:p,editingPost:m})})}function G(e){var t,n,i,l,r;let{publication:a,maxImagesToUpload:d,publishOptionsEnabled:s,visibilityOptions:u,photosEnabled:p,videoEnabled:m,onSubmit:y,handleModalClose:g,initialFiles:w,videoPlayerProps:C,editingPost:P}=e,F=null==P||null==(n=P.threadMediaUploads)||null==(t=n[0])?void 0:t.mediaUpload,{user:T,files:I,handleSubmit:S,inputFile:E,removeFile:x,onChangeFile:M,onImageButtonClick:V,addFiles:j,textValue:G,setTextValue:K,options:W,setOption:q,postAudienceHandler:Q,canSubmit:Z,linkUrl:ee,setLinkUrl:et,getContentRef:en,selectedVideoFile:ei,setSelectedVideoFile:el,mediaUpload:er,setMediaUpload:eo}=(0,A.o)({defaultValue:null!=(l=null==P?void 0:P.body)?l:void 0,maxImagesToUpload:d,onSubmit:y,defaultPostAudience:P?P.audience:u.hasFree?"all_subscribers":u.hasPaid?"only_paid":"only_founding",initialMediaAssets:null!=(r=null==P?void 0:P.media_assets)?r:void 0,initialMediaUpload:F,editingPostId:null==P?void 0:P.id}),ea=(0,f.Qk)({onAddFiles:e=>{let t=e.filter(e=>(0,f.St)({fileType:e.type}));if(t.length>0&&t[0]){eo(null),el(t[0]);return}el(null),eo(null),j(e)},acceptFile:e=>{let{fileType:t}=e;return(0,f.um)({fileType:t})||!!(m&&(0,f.St)({fileType:t}))}}),ed=(0,c.useCallback)(e=>{K(e)},[K]);(0,c.useEffect)(()=>{w&&w.length>0&&j(w)},[w]);let ec="free"===a.paywall_chat,es="paid"===a.paywall_chat,eu="founding"===a.paywall_chat,ep=u.hasPaid,em=u.hasFounding,eh=ec&&!ep,ey=es&&!em,ef="all_subscribers"===Q.value,eg="only_founding"===Q.value||"only_founding_replies"===Q.value,eb=ec&&ep||es&&em,e_=eb&&ec&&!ef||eb&&es&&eg,ev=s&&!eh&&!ey&&!eu;return T?(0,o.FD)(o.FK,{children:[(0,o.FD)(Y.cw,{children:[(0,o.FD)(v.VP,{gap:16,children:[ev?(0,o.FD)(v.fI,{gap:8,children:[eb&&(0,o.Y)(D,{visibilityOptions:u,currentVisibility:Q.value,onPick:e=>{Q.set(e)}}),e_&&(0,o.Y)(k,{currentVisibility:Q.value,onPick:e=>{Q.set(e)}})]}):null,(0,o.FD)(v.fI,{gap:12,minWidth:0,children:[(0,o.Y)(b.eu,{size:36,user:T}),(0,o.FD)(v.VP,{gap:2,flex:"fill",children:[(0,o.Y)(h.l8,{user:T}),(0,o.Y)(v.fI,{gap:12,minWidth:0,className:B.A.inputBox,flex:"grow",paddingRight:8,overflowY:"auto",children:(0,o.Y)(U.J,{defaultValue:G,placeholder:"Write something...",autoFocus:!0,onChange:ed,onReturn:S,onAddFiles:j,onDrop:ea.props.onDrop,className:B.A.modalChatEditor,getContentRef:en})})]})]}),I.length>0&&(0,o.Y)(X,{files:I,deleteFile:x}),(!I.length&&ei||F)&&(0,o.Y)(v.pT,{children:(0,o.Y)(z.S,{file:ei,initialMediaUpload:null!=F?F:null,maxVideoDurationSeconds:L.F$,onCancel:()=>{el(null),eo(null)},onRemoveVideo:()=>{el(null),eo(null)},onComplete:async e=>{let{mediaUpload:t}=e;t&&eo(t)},videoPlayerProps:C})}),ee&&(0,o.Y)($,{linkUrl:ee,deleteLink:()=>et(null)}),s&&!P&&(0,o.FD)(v.fI,{gap:20,alignItems:"center",justifyContent:"end",children:[(null==(i=a.threads_v2_settings)?void 0:i.push_suppression_enabled)&&(0,o.Y)(N,{options:W,setOption:q}),(0,o.Y)(O,{options:W,setOption:q})]})]}),(0,o.Y)(R.Y,{visible:ea.isDragging})]}),(0,o.Y)(Y.jl,{primaryButton:(0,o.Y)(_.$n,{priority:"primary",disabled:!Z,onClick:e=>{S(e),g()},children:P?"Save":"Send"}),secondaryButton:(0,o.Y)(_.$n,{priority:"secondary",onClick:g,children:"Cancel"}),tertiaryButton:(0,o.FD)(v.fI,{gap:4,flex:"grow",justifyContent:"start",children:[p&&!ei&&!er&&(0,o.Y)(H,{onClick:V}),m&&!I.length&&(0,o.Y)(J,{selectedFile:ei,setSelectedFile:el})]})}),(0,o.Y)("input",{type:"file",accept:"image/*",id:"file",ref:E,style:{display:"none"},onChange:M,"aria-label":"Add image",multiple:!0})]}):null}function J(e){let{selectedFile:t,setSelectedFile:n}=e,i=(0,w.d)(),{iString:l}=(0,m.GO)(),r=()=>{i.popToast(()=>(0,o.Y)(w.y,{text:l("Something went wrong. Please try again.")}))};return(0,o.Y)(y.n,{mediaUpload:null,selectedFile:t,onInputChange:e=>{if(!e.currentTarget){console.warn("input change event had no currentTarget"),r();return}if(!(e.currentTarget instanceof HTMLInputElement)){console.warn("input change event currentTarget was not an input"),r();return}let t=e.currentTarget,{files:i}=t;if(!i){console.warn("input change event had no files"),r();return}if(i.length>1&&console.error("selected multiple files, at most 1 file allowed"),0===i.length){console.error("must select exactly one file"),r();return}n(i[0]),t.value=""}})}function K(e){let{onDelete:t,className:n,size:i="sm",xSize:l=20}=e;return(0,o.Y)(_.mZ,{className:n,size:i,rounded:!0,onClick:t,children:(0,o.Y)(a.A,{size:l})})}function W(e){var t;let{file:n,deleteFile:i}=e;return(0,o.FD)(v.fI,{className:B.A.imageBox,children:[(0,o.Y)("img",{className:B.A.image,src:n.url,alt:null==(t=n.file)?void 0:t.name}),(0,o.Y)(K,{onDelete:()=>i(n),className:B.A.deleteFile})]})}function H(e){let{onClick:t}=e;return(0,o.Y)(_.K0,{onClick:t,priority:"tertiary",children:(0,o.Y)(d.A,{size:20})})}function $(e){let{linkUrl:t,deleteLink:n}=e;return(0,o.FD)(v.VP,{className:B.A.composerLinkPreview,radius:"lg",overflow:"hidden",alignSelf:"start",children:[(0,o.Y)(s.ZT,{linkUrl:t}),(0,o.Y)(K,{onDelete:n,className:B.A.deleteFile})]})}function X(e){var{files:t,deleteFile:n}=e,a=(0,r._)(e,["files","deleteFile"]);return(0,o.Y)(v.pT,(0,l._)((0,i._)({},a),{gap:8,wrap:"wrap",children:t.map(e=>(0,o.Y)(W,{file:e,deleteFile:n},e.url))}))}},18464:function(e,t,n){n.d(t,{z6:()=>l,XC:()=>o,r9:()=>r});var i=n(75303);let l=(0,i.I4)({className:"grayscaleFilter-zoT7iO",position:"absolute",inset:0}),r=(0,i.I4)({className:"paywallPreviewFilter-SG6InP",position:"absolute",inset:0}),o=(0,i.I4)({className:"reversed-BbEkyU"},r)},75485:function(e,t,n){n.d(t,{O:()=>d});var i=n(4006),l=n(84605),r=n(76977),o=n(63136),a=n(39318);function d(e){let{errorMessage:t}=e,{iString:n}=(0,l.GO)();return(0,i.Y)(r.pT,{paddingX:16,style:{position:"relative",zIndex:10},children:(0,i.FD)(o.EY.B5,{color:"error",style:{opacity:1},children:[t||"Phone verification required to continue with chat.",(0,i.Y)("br",{}),"Please verify your phone number using the"," ",(0,i.Y)("a",{href:(0,a.wHz)(),target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"underline"},"aria-label":n("Open the Substack app"),children:"Substack app"}),"."]})})}},167:function(e,t,n){n.d(t,{v0:()=>ef,z9:()=>ev,wG:()=>ew,Wf:()=>eP,pU:()=>e_,lG:()=>ey});var i=n(69277),l=n(70408),r=n(32641),o=n(4006),a=n(32485),d=n.n(a),c=n(68090),s=n.n(c),u=n(54718),p=n(48587),m=n(99862),h=n(17402),y=n(12550),f=n.n(y),g=n(61284),b=n(18993),_=n(84605),v=n(46271),Y=n(86998),w=n(86500),C=n(94729),P=n(56804),F=n(35369),D=n(16074),T=n(97515),I=n(76977),k=n(45859),S=n(63136),A=n(79515),E=n(20394),x=n(63175),O=n(31268),N=n(31117),R=n(594),U=n(3046),z=n(506),L=n(46647),B=n(18464),M=n(75485),V=n(36319),j=n(87545),G=n(99051),J=n(21006),K=n(70486),W=n(75303);function H(){let e=(0,h.useMemo)(()=>Array(10).fill(null).map(()=>Math.ceil(4*Math.random())),[]);return(0,o.FD)($,{children:[(0,o.Y)(X,{children:e.map((e,t)=>t%2==0?(0,o.Y)(q,{length:e}):(0,o.Y)(Q,{length:e}))}),(0,o.Y)(B.XC,{})]})}let $=(0,W.I4)({position:"relative",flex:"grow",padding:16},W.VP),X=(0,W.I4)({gap:12,flex:"grow",overflow:"hidden"},W.VP);function q(e){let{length:t}=e;return(0,o.FD)(Z,{children:[(0,o.Y)(et,{}),(0,o.Y)(en,{children:Array(t).fill(null).map(()=>(0,o.Y)(ei,{}))})]})}function Q(e){let{length:t}=e;return(0,o.Y)(ee,{children:(0,o.Y)(en,{children:Array(t).fill(null).map(()=>(0,o.Y)(ei,{}))})})}let Z=(0,W.I4)({display:"flex",gap:8,alignItems:"end"}),ee=(0,W.I4)({justifyContent:"end"},Z),et=(0,W.I4)({width:32,height:32,radius:"full",bg:"secondary"}),en=(0,W.I4)({bg:"secondary",radius:"lg",flex:"grow",maxWidth:400},W.VP),ei=(0,W.I4)({height:32});var el=n(49520),er=n(66093),eo=n(42831),ea=n(74470),ed=n(45458),ec=n(26095),es=n(32848),eu=n(43296),ep=n(49807),em=n(36083),eh=n(35407);function ey(e){var t,n,r,a,c,y,_,P,D,L,W,$,X,q,Q,Z,ee,et,en,ei,ey,ef,e_,ev;let{postId:eP,pubId:eF,parentCommentId:eD,onBack:eT,isAutoSelected:eI,state:ek,navigateToChat:eS,targetReplyId:eA,showTarget:eE,isCustomerSupportMode:ex,hideHeader:eO}=e,eN=(0,v.Jd)(),eR=eD?null!=(Q=ek.replies.get(eD))?Q:V.h0:null!=(Z=ek.comments.get(eP))?Z:V.h0,eU=null==(t=ek.chats.get(eF))?void 0:t.muteStatus,ez=(null==eU?void 0:eU.type)==="leave",eL=ek.communityPosts.get(eP),eB=eD?ek.communityComments.get(eD):null,eM=ek.inbox.resources.all.isLoading&&0===ek.inbox.threadList.length,eV=ek.chats.get(eF),ej=null!=(ee=eL&&ek.users.get(eL.communityPost.user_id))?ee:null,eG=null!=(et=eB&&ek.users.get(eB.comment.user_id))?et:null,eJ=null==eV?void 0:eV.publication,{listRef:eK,scrollToBottom:eW,observeScrollPosition:eH,isScrolledToBottom:e$,listLengthRef:eX}=(0,ea.F)({preferredStart:"top"}),eq=(0,h.useRef)(!1),eQ=(0,es.n7)(),eZ=eN&&(null==ej?void 0:ej.id)==eN.id,{isPaid:e0,isAuthor:e1,isFreeSubscribed:e4,isFounding:e2,isSubscribed:e6,subscription:e7}=(0,es.NL)(eF),e9=e1||null!=(en=null==eV||null==(r=eV.publication)||null==(n=r.threads_v2_settings)?void 0:n.photo_replies_enabled)&&en,e8=!!ek.editingPost,[e3,e5]=(0,h.useState)(null),te=(0,h.useMemo)(()=>{let{quoteReply:e}=eR;if(e){let t=ek.communityComments.get(e);if(t){let e=t&&ek.users.get(t.comment.user_id);return{comment:t.comment,user:e}}}},[eR.quoteReply]),tt=e=>ta({type:"comments-quote_set",payload:(0,l._)((0,i._)({},tu),{commentId:e})}),tn=(0,h.useMemo)(()=>null==eR?void 0:eR.lastViewedAt,[eR.isLoaded]),ti="".concat(eD?"replies-".concat(eD):"comments-".concat(eP),"-").concat(eR.comments.length).concat((null==te?void 0:te.comment)?"-".concat(te.comment.id):""),tl=(0,N.B)({publication:eJ,isAuthor:e1,isSubscribed:e6,isFounding:e2,isPaid:e0})&&!ex,tr=e1||null!=(ei=null==eV||null==(c=eV.publication)||null==(a=c.threads_v2_settings)?void 0:a.photo_replies_enabled)&&ei,to=e1||tr;(0,h.useEffect)(()=>{eD?eB&&(0,V.PO)(eB)&&(0,w.u4)(w.qY.THREAD_REPLY_PERMALINK_VIEWED,{publication_id:eF,community_post_id:eP,community_comment_id:eD,isAutoSelected:eI}):eL&&(0,V.Tv)(eL)&&(0,w.u4)(w.qY.THREAD_PERMALINK_VIEWED,{publication_id:eF,community_post_id:eP,type:eL.communityPost.type,audience:eL.communityPost.audience,isAutoSelected:eI})},[eD,eP,eF,!!eL,!!eB]);let ta=(0,K.wA)(),[td,tc]=(0,h.useState)(null),[ts,tu]=eD?["replies",{parentCommentId:eD}]:["comments",{postId:eP}],tp=eR.isLoaded&&0===eR.comments.length,tm=null==(y=ek.communityComments.get(eR.comments[0]))?void 0:y.comment.created_at;(0,h.useEffect)(()=>{let e=()=>{let{visibilityState:e="visible"}=document;if("hidden"!==e&&(t(),tm&&(!eR.lastViewedAt||tm>eR.lastViewedAt))){let e=new Date().toISOString();(0,C.x6)("/api/v1/community/chat/".concat(eF,"/view"),{method:"POST",json:{community_comment_id:eD,community_post_id:eP,last_viewed_timestamp:e}}).catch(()=>{console.warn("Failed to mark post as viewed.")}),ta({type:"".concat(ts,"-mark_viewed"),payload:(0,l._)((0,i._)({},tu),{lastViewedAt:e})})}},t=(0,ec.x)(e);return e(),t},[eP,eD,tm,eR.lastViewedAt]);let th=null!=eD?"/api/v1/community/comments/".concat(eD,"/comments"):"/api/v1/community/posts/".concat(eP,"/comments"),ty=null!=eD?eD:eP,tf=async(e,t)=>{tw||ta({type:"".concat(ts,"-request_initial"),payload:(0,l._)((0,i._)({},tu),{order:e,target:t})});let n="desc"===e?"before":"after";try{var r;let o=await (0,C.x6)(th,{query:{order:e,targetReplyId:null!=(r=null==t?void 0:t.id)?r:void 0,initial:"true"}});ta({type:"".concat(ts,"-load_edge"),payload:(0,l._)((0,i._)({},tu),{edge:n,result:o})}),"desc"===e&&eW()}catch(t){return ta({type:"".concat(ts,"-error"),payload:(0,l._)((0,i._)({},tu),{edge:n,error:t})}),"desc"===e&&eW(),t}return null},tg={before:!1,after:!1},tb=(e,t)=>{if(!tg[e]&&!eR[e].isLoading)return tg[e]=!0,t_(e,t)},t_=async(e,t)=>{var n,r;ta({type:"".concat(ts,"-request_edge"),payload:(0,l._)((0,i._)({},tu),{edge:e})});let o=s()(eR.comments),a=eR.comments[0],d="before"===e?{order:"desc",before:o&&(null==(n=ek.communityComments.get(o))?void 0:n.comment.created_at)}:{order:"asc",after:a&&(null==(r=ek.communityComments.get(a))?void 0:r.comment.created_at)};try{let n=await (0,C.x6)(th,(0,l._)((0,i._)({},t),{query:d})),{current:r}=eK;ta({type:"".concat(ts,"-load_edge"),payload:(0,l._)((0,i._)({},tu),{edge:e,result:n})}),"desc"===eR.order&&r&&e$&&eW()}catch(t){console.warn(t),ta({type:"".concat(ts,"-error"),payload:(0,l._)((0,i._)({},tu),{edge:e,error:t})})}},tv=e=>{eR[e].hasMore&&tb(e)};(0,h.useEffect)(()=>{tf("asc",eA?{id:eA,show:!!eE}:void 0).then(e=>{e&&tc(e)})},[ty,eA]);let{target:tY,isLoaded:tw}=eR,tC=tw&&!eM;(0,h.useLayoutEffect)(()=>{let e,t=eK.current;t&&tC&&((e=eA?t$.findIndex(e=>e.id===eA):t$.findIndex(e=>"new-marker"===e.type))>=0&&t.scrollToIndex(e),eR.lastViewedAt&&!eR.after.hasMore&&t.scrollToIndex(t$.length-1))},[ty,tC,!!eK.current]);let tP=eR.comments[0];(0,h.useLayoutEffect)(()=>{tP&&"desc"===eR.order&&e$&&eW()},[tP]),(0,h.useEffect)(()=>()=>{ta({type:"".concat(ts,"-target"),payload:(0,l._)((0,i._)({},tu),{target:null})})},[]);let tF=(0,eu.$P)();(0,er.a)({pubId:eF,handleReconnect:()=>t_("after")});let tD=(0,h.useRef)(t_);tD.current=t_,(0,el.z)(e=>td||!eR.isLoaded?Promise.resolve():tD.current("after",{signal:e}),"open"===tF?6e4:1e4,[ty,td,eR.isLoaded]);let tT=(0,h.useRef)(null),tI=(0,Y.zj)({onAddFiles:e=>{var t;null==(t=tT.current)||t.call(tT,e)},acceptFile:Y.um}),tk=async(e,t,n)=>{await eb(e,t,"video",n.id)},tS=async(e,t,n)=>{let i=await Promise.all(e.map(e=>eg(t,n,e.contentType))),l=[],r=[];for(let[t,n]of i.entries())n instanceof Error?l.push(n):r.push({asset:e[t],url:n.url,id:n.id});let o=await Promise.all(r.map(e=>{let{asset:t,id:n}=e;return eC(t,n)})),a=[];for(let e of o)e instanceof Error&&a.push(e);let d=l.length+a.length;d&&(d===e.length?alert("We failed to upload your media. Please try again later."):alert("We failed to upload some of your media. Please try again later."))},tA=async e=>{var t,n,r,o,a;let{value:d,mediaAssets:c,mentions:s,mediaUpload:u}=e;e5(null);let p=null!=d?d:"",m=null!=(o=null==(t=(n=crypto).randomUUID)?void 0:t.call(n))?o:f()();"asc"===eR.order&&tf("asc");let h=null;c&&(h=c.map(e=>({id:f()(),url:e.url,content_type:e.contentType,type:"image",file:e.file})));let y={is_founding:!!e2,membership_state:e0?"subscribed":"free_signup",role:e1?"admin":null,created_at:new Date(null!=(a=null==e7?void 0:e7.created_at)?a:new Date)};ta({type:"".concat(ts,"-new"),payload:(0,l._)((0,i._)({},tu),{id:m,body:p,postId:eP,mediaUploads:h,quoteReply:te,mentions:s,pubRoles:y,mediaAttachments:u?[{type:"video",thumb_url:"",url:"",explicit:!1,mediaUpload:u}]:[]})});let g=null==te||null==(r=te.comment)?void 0:r.id;te&&tt(null),eW(),u&&await tk(m,eF,u),c&&await tS(c,m,eF);try{await ta((0,b.lg)(eP,{id:m,body:p,parent_id:eD,quote_id:g,mentions:s}))}catch(e){e5(e)}},{update:tE}=(0,j.$y)({state:ek}),tx=async e=>{let{value:t,mediaAssets:n,sendAsEmail:i,sendPush:l,audience:r,linkUrl:o,mediaUpload:a,editingPostId:d}=e;if(d)return await tE({value:t,mediaAssets:n,sendAsEmail:i,sendPush:l,audience:r,linkUrl:o,mediaUpload:a,editingPostId:d})};eq.current=eR.before.isLoading;let tO=null==td||null==(_=td.body)?void 0:_.status,tN="FREE_SUBSCRIPTION_REQUIRED"===tO||tl&&(null==eJ?void 0:eJ.paywall_chat)==="free",tR="PAID_SUBSCRIPTION_REQUIRED"===tO||tl&&(null==eJ?void 0:eJ.paywall_chat)==="paid",tU="FOUNDING_SUBSCRIPTION_REQUIRED"===tO||tl&&(null==eJ?void 0:eJ.paywall_chat)==="founding",tz=tN||tR||tU,tL=eL&&(0,V.Tv)(eL)&&eL.communityPost.is_locked,tB=eD&&eB&&(0,V.PO)(eB)&&eB.comment.is_locked,tM=e1||!tz&&!tL&&!ez&&(!eD||eB&&(0,V.PO)(eB)&&!eB.comment.is_locked),tV=(null==td||null==(P=td.body)?void 0:P.status)==="PUBLICATION_NOT_FOUND",tj=td&&(null==(D=td.body)?void 0:D.status)==="POST_NOT_FOUND",tG=td&&(null==(L=td.body)?void 0:L.status)==="COMMENT_NOT_FOUND",tJ=eA&&td&&(null==(W=td.body)?void 0:W.status)==="COMMENT_NOT_FOUND",tK=(0,h.useCallback)(e=>t=>{if(!e)return;t.stopPropagation(),t.preventDefault();let n=e.comment.id,i=eR.comments.includes(n),l=-1;for(let[e,t]of t$.entries())if("message-group"===t.type)for(let i of t.item.messages)i.comment.id===n&&(l=e);if(i&&l>=0){var r;null==(r=eK.current)||r.scrollToIndex(l,{align:"start",smooth:!0}),setTimeout(()=>{let t=document.getElementById((0,U.fd)(e.comment));if(t){var n;t.classList.remove(null!=(n=em.A.highlight)?n:""),setTimeout(()=>{var e;t.classList.add(null!=(e=em.A.highlight)?e:"")},100)}},100)}else{if(n===eA)return;ta({type:"".concat(ts,"-clear"),payload:tu}),(0,m.route)((0,ep.yRP)(location.pathname,{targetReplyId:n,showTarget:!0}),!0)}},[tu,ts,ta,eR.comments,eA]),tW=(0,h.useMemo)(()=>tV||!eV&&!eM||(null==eV?void 0:eV.before.error)||tj||tG||tJ,[eV,tj,tV,tG,eM,tJ]),tH=!eQ.hasLoadedOnce,t$=(0,h.useMemo)(()=>{var e,t,n;let r=[];if(tW)return r;if(!eR.before.hasMore)if((tH||eM)&&!tz)r.push({type:"loading",id:"loading-initial"});else if(!tl&&tz){let t=null!=(e=null!=eG?eG:ej)?e:null==eL?void 0:eL.communityPost.user;r.push({type:"paywall",id:"paywall",item:(0,l._)((0,i._)({},t?eL:{}),{audience:tR?"only_paid":tU?"only_founding":"all_subscribers",user:null!=t?t:null,postId:eP})})}else if(eB&&!eB.isNew&&eG)r.push({type:"parent-reply",item:{parentReply:eB,author:eG},id:"parent-reply"});else if(eL&&!eL.isNew&&ej)r.push({type:"parent-post",item:(0,l._)((0,i._)({},eL),{user:ej}),id:eL.communityPost.id});else if(tz){let e=null!=(t=null!=eG?eG:ej)?t:null==eL?void 0:eL.communityPost.user;r.push({type:"paywall",id:"paywall",item:(0,l._)((0,i._)({},e?eL:{}),{audience:tR?"only_paid":tU?"only_founding":"all_subscribers",user:null!=e?e:null,postId:eP})})}else r.push({type:"loading",id:"loading-header"});if(r.push({type:"divider",item:{replyCount:(null==eL?void 0:eL.communityPost)&&"comment_count"in(null==eL?void 0:eL.communityPost)&&(null==eL?void 0:eL.communityPost.comment_count)?null==eL?void 0:eL.communityPost.comment_count:eR.comments.length,parentPost:null!=eL?eL:void 0,parentReply:null!=eB?eB:void 0},id:"divider"}),tH||eM)r.push({type:"loading",id:"loader-body"});else{let e={type:"chat-zero",id:"chat-zero"};tN?r.push((0,l._)((0,i._)({},e),{item:{title:"Only subscribers can access this chat",description:"Once you subscribe, you’ll be able to reply here.",includeUpsell:!0}})):tR?r.push((0,l._)((0,i._)({},e),{item:{title:"Only paid subscribers can read comments",description:"Upgrade to a paid subscription to access the chat",includeUpsell:!0}})):tU?r.push((0,l._)((0,i._)({},e),{item:{title:"Only founding members can read comments",description:"Upgrade to a founding membership to access the chat",includeUpsell:!0}})):tp&&r.push((0,l._)((0,i._)({},e),{item:{title:"No replies yet",description:"Be the first to add a reply below"}}))}eR.before.error&&!tz&&r.push({type:"error",id:"error-before"}),eR.before.isLoading&&r.push({type:"loading",id:"loading-before"}),eR.before.hasMore&&!eR.before.isLoading&&r.push({type:"load-more",id:"load-more-before",item:{onClick:()=>tb("before")}});let o=eR.comments.slice().reverse(),a=(0,U.ew)(ek,o,null!=(n=null==eV?void 0:eV.publication)?n:void 0,{onQuoteClick:tK,target:(null==tY?void 0:tY.show)?tY.id:void 0,lastViewedAt:null!=tn?tn:void 0});return a[0]&&(a[0].timestamp=null),a.forEach(e=>{r.push({type:"message-group",item:e,id:e.key})}),eR.after.error&&!tz&&r.push({type:"error",id:"error-after"}),eR.after.isLoading&&"asc"===eR.order&&!tz&&r.push({type:"loading",id:"loading-after"}),eR.after.hasMore&&!eR.after.isLoading&&r.push({type:"load-more",id:"load-more-after",item:{onClick:()=>tb("after")}}),r},[ek,eP,tK,tl,tU,tN,tR,tz,tp,tn,tb,null==eV?void 0:eV.publication,eL,ej,eB,eG,eM,tW,eR.after.error,eR.after.hasMore,eR.after.isLoading,eR.before.error,eR.before.hasMore,eR.before.isLoading,eR.comments,eR.order,null==tY?void 0:tY.id,null==tY?void 0:tY.show,tH]);eX.current=t$.length;let tX=(0,eo.d)({entityType:eB?"communityComment":"communityPost",publication:eJ});if(tV)return(0,o.Y)(T.p,{title:"We could not find this publication.",description:"Please select another publication and try again.",flex:"grow"});if(!eV&&!eM)return(0,o.Y)(T.p,{title:"Something went wrong",description:"Navigate back to the publication chat by clicking the button below",flex:"grow",button:(0,o.Y)(F.$n,{onClick:eS,children:"Back to chat"})});let tq=null==eV?void 0:eV.before.error;if(tq)return(0,o.Y)(G._Y,{error:tq});if(tj)return(0,o.Y)(T.p,{title:"We could not find the parent post",description:"Navigate back to the publication chat by clicking the button below",flex:"grow",button:(0,o.Y)(F.$n,{onClick:eS,children:"Back to chat"})});if(tJ)return(0,o.Y)(T.p,{title:"We could not find this reply",description:"Navigate back by clicking the button below",flex:"grow",button:(0,o.Y)(F.$n,{onClick:eT,children:"Go back"})});if(tG)return(0,o.Y)(T.p,{title:"We could not find the parent comment",description:"Navigate back by clicking the button below",flex:"grow",button:(0,o.Y)(F.$n,{onClick:eT,children:"Go back"})});if(eL&&eL.isNew||eB&&eB.isNew)return(0,o.Y)(T.p,{title:"You cannot comment on this post yet",description:"Navigate back by clicking the button below",flex:"grow",button:(0,o.Y)(F.$n,{onClick:eT,children:"Go back"})});if(eL&&eL.communityPost.publication_id!==eF)return(0,o.Y)(T.p,{title:"This post does not belong to this publication",description:"Navigate back to the publication chat by clicking the button below",flex:"grow",button:(0,o.Y)(F.$n,{onClick:eS,children:"Back to chat"})});if(eB&&eB.comment.post_id!==eP)return(0,o.Y)(T.p,{title:"This comment does not belong to this post",description:"Navigate back to the publication chat by clicking the button below",flex:"grow",button:(0,o.Y)(F.$n,{onClick:eS,children:"Back to chat"})});let tQ={isPaid:e0||e2||e1,isFounding:e2||e1,isFreeSubscribed:e4},tZ=null!=(ey=null==eB?void 0:eB.comment)?ey:null==eL?void 0:eL.communityPost;return(0,o.FD)(I.I1,(0,l._)((0,i._)({},tI.props),{flex:"grow",position:"relative",children:[!eO&&(0,o.Y)(J.Mj,{onBack:eT,menu:tZ&&(0,o.Y)(k.W1,{trigger:(0,o.Y)(F.K0,{"aria-label":"Options",priority:"tertiary",children:(0,o.Y)(u.A,{})}),children:(0,o.Y)(b.Wy,{communityEntity:tZ,publicationId:eF,isFlagged:tZ.reported_by_user,onReport:tX,isBanned:null==eB?void 0:eB.is_banned})})}),(0,o.FD)(I.I1,{flex:"grow",position:"relative",children:[tl||tz?(0,o.FD)(I.I1,{flex:"grow",children:[ej&&eL&&(0,o.FD)(x.DF,{children:[(0,o.Y)(j.AJ,(0,l._)((0,i._)({item:(0,l._)((0,i._)({},eL),{user:ej}),pub:eJ},tQ),{isReadOnly:!0,showReply:!1,onSelect:()=>void 0})),(0,o.Y)(B.z6,{})]}),(0,o.Y)(I.I1,{paddingX:16,children:(0,o.Y)(ew,{replyCount:null!=(ef=null==eL||null==($=eL.communityPost)?void 0:$.comment_count)?ef:0,parentPost:eL})}),(0,o.Y)(H,{}),eJ&&(0,o.Y)(A.iC,{publication:eJ,isPaywallPreview:tl,isFounding:e2,isFreeSubscribed:e4,hasLeftChat:ez,hasFoundingPaywall:tU,hasPaidPaywall:tR,footerMessage:tU?"founding"===eJ.paywall_chat?"This chat is for founding members only.":"Only founding members can see the replies.":tR?"paid"===eJ.paywall_chat?"This chat is for paid subscribers only.":"Only paid subscribers can see the replies.":"Subscribe to ".concat(eJ.name," to see the replies."),footerIcon:(0,o.Y)(A.Qi,{})})]}):(0,o.FD)(o.FK,{children:[(0,o.Y)(x.NW,{fullWidth:!0,padding:0,itemGap:0,children:(0,o.Y)(g.x8,{ref:eK,onScroll:e=>{if(!eK.current)return;eH(e);let{scrollSize:t,scrollOffset:n,viewportSize:i}=eK.current;e<400?tv("before"):n>t-i-400&&tv("after")},shift:eq.current,children:t$.map((e,t)=>(0,o.Y)(E.G,(0,l._)((0,i._)({chatItem:e,onBack:eT},tQ),{pub:null==eV?void 0:eV.publication,isReadOnly:ez,isPreview:tl,index:t})))})}),(null==e3||null==(X=e3.body)?void 0:X.type)==="verify_phone"&&(0,o.Y)(M.O,{errorMessage:e3.body.error})]}),!tl&&(0,o.Y)(j.qt,{isNearBottom:e$,onClick:()=>eR.after.hasMore?tf("asc"):eW()})]}),tM?eM?(0,o.Y)(R.J,{}):(0,o.Y)(O.r,{stateChangeKey:ti,placeholder:"Add a reply...",maxImagesToUpload:6,photosEnabled:tr,videoEnabled:to,onSubmit:tA,quoteHandler:{quoteReply:te,cancelQuoteReply:()=>tt(null)},mentionsContext:{publication_id:eF,community_post_id:eP,community_comment_id:eD},addFilesRef:tT,dropZone:tI,chatType:"chat"}):(tL||tB)&&(0,o.Y)(I.pT,{justifyContent:"center",alignItems:"center",paddingX:20,borderTop:"detail",className:d()(eh.A.footer,eh.A.disabled),children:(0,o.FD)(I.Ye,{gap:12,alignItems:"center",children:[(0,o.Y)(p.A,{size:20,stroke:"var(--color-fg-secondary)"}),(0,o.Y)(S.EY.B4,{color:"secondary",children:"Replies are disabled"})]})}),ez&&(0,o.Y)(eY,{pubId:eF}),(0,o.Y)(ed.Y,{visible:tI.isDragging,className:eh.A.dropzone}),eZ&&eJ&&(0,o.Y)(z.HD,{publication:eJ,maxImagesToUpload:z.Xp,photosEnabled:e9,videoEnabled:to,onSubmit:tx,publishOptionsEnabled:e1,handleModalClose:()=>ta({type:"posts-edit_post",payload:{post:null}}),isModalOpen:e8,visibilityOptions:{hasFree:(null==eJ?void 0:eJ.paywall_chat)==="free",hasPaid:(null==eJ?void 0:eJ.paywall_chat)==="paid"||!!(null==eJ?void 0:eJ.plans)&&(null==eJ?void 0:eJ.paywall_chat)!=="founding",hasFounding:(null==eJ?void 0:eJ.paywall_chat)==="founding"||!!(null==eJ||null==(q=eJ.plans)?void 0:q.find(e=>{var t;return null==(t=e.metadata)?void 0:t.founding}))},videoPlayerProps:{surface:"chat_inbox",contentType:"communityPost",entityType:"community_post",entityKey:null!=(e_=null==eL?void 0:eL.communityPost.id)?e_:"unknown"},editingPost:null!=(ev=ek.editingPost)?ev:void 0})]}))}function ef(){return(0,o.Y)(I.pT,{alignItems:"center",justifyContent:"center",padding:12,children:(0,o.Y)(S.EY.B3,{color:"error",children:"Error loading chats"})})}async function eg(e,t,n){try{return await (0,C.x6)("/api/v1/thread_media_uploads",{method:"POST",json:{publication_id:t,comment_id:e,content_type:n}})}catch(e){return e}}async function eb(e,t,n,i){try{return await (0,C.x6)("/api/v1/thread_media_uploads",{method:"POST",json:{publication_id:t,comment_id:e,content_type:n,media_upload_id:i}})}catch(e){return e}}function e_(e){var{user:t,showReply:n=!0,pub:a}=e,d=(0,r._)(e,["user","showReply","pub"]);let c=(0,v.Jd)(),s=a?e=>{ev({event:e,user:c,pub:a})}:void 0;return(0,o.Y)(I.pT,{children:(0,o.Y)(I.I1,{className:eh.A.paywall,children:(0,o.Y)(b.I8,(0,l._)((0,i._)({},d),{onClick:s,author:t,showReply:n}))})})}function ev(e){let{event:t,user:n,pub:i}=e;(0,P.o)(t,(0,ep.eV6)(i,{user:n,addBase:!0,params:{next:window.location.href}}),{native:!0,newTab:!0})}function eY(e){let{pubId:t}=e,{handleJoinChat:n,confirmJoinModal:i}=(0,J.sE)({pubId:t});return(0,o.FD)(o.FK,{children:[(0,o.Y)(I.I1,{className:d()(eh.A.footer,eh.A.disabled),borderTop:"detail",alignSelf:"stretch",gap:16,alignItems:"center",justifyContent:"center",children:(0,o.FD)(I.Ye,{alignItems:"center",gap:16,children:[(0,o.Y)(S.EY.B3,{color:"secondary",children:"Join the chat to react and reply"}),(0,o.Y)(F.$n,{priority:"primary-mono",onClick:n,children:"Join"})]})}),i]})}function ew(e){let{replyCount:t,parentPost:n,parentReply:i}=e,{iPlural:l}=(0,_.GO)(),r=i?i.comment.created_at:n?n.communityPost.created_at:null;return(0,o.FD)(I.Ye,{gap:12,alignItems:"center",paddingY:8,children:[(0,o.Y)(S.EY.B4,{color:"secondary",children:l("%1 Reply","%1 Replies",t)}),(0,o.Y)(D.c,{flex:"grow"}),r&&(0,o.Y)(L.D,{conjunction:!0,timestamp:r})]})}async function eC(e,t){try{var n;return await fetch("/api/v1/thread_media_upload/".concat(t),{method:"PUT",headers:{"Content-Type":null!=(n=e.contentType)?n:""},body:e.file})}catch(e){return e}}function eP(e){let{reply:t,author:n}=e;return(0,o.Y)(U.$4,{group:{key:t.comment.id,author:n,timestamp:null,replyCount:0,isNew:!1,messages:[(0,l._)((0,i._)({},t),{user:n})]},isPending:!1,direction:"incoming",showName:!0})}},21006:function(e,t,n){n.d(t,{Mj:()=>B,sE:()=>j,vA:()=>L});var i=n(69277),l=n(70408),r=n(32641),o=n(79785),a=n(4006),d=n(98445),c=n(90232),s=n(54718),u=n(82853),p=n(45773),m=n(6896),h=n(13838),y=n(91461),f=n(86404),g=n(84605),b=n(94729),_=n(72569),v=n(44333),Y=n(17028),w=n(45859),C=n(45974),P=n(36372),F=n(63175),D=n(89919),T=n(8665),I=n(52145),k=n(36319),S=n(70486),A=n(58395),E=n(90554),x=n(45846),O=n(29611),N=n(39318),R=n(15567),U=n(35407);function z(){let e=(0,o._)(["You can rejoin later from the "," publication page."]);return z=function(){return e},e}function L(e){var t;let{pub:n,isPinned:i,isPaywallPreview:l}=e,{open:r}=(0,A.NR)(),o=(0,S.Pk)(),c=(0,k.iT)(o,n.id),s=()=>r(n.id,n.name);(0,E.y)({name:"search",action:s});let u="free"!==n.paywall_chat,p="founding"===n.paywall_chat,m=null==c||null==(t=c.paywallStatus)?void 0:t.is_allowed_access,{iString:h}=(0,g.GO)();return(0,a.Y)(F.ep,{children:(0,a.FD)(Y.Ye,{flex:"grow",justifyContent:"space-between",alignItems:"center",children:[(0,a.FD)(Y.pT,{flex:"grow",gap:12,children:[(0,a.Y)(M,{pub:n,className:U.A.headerPubLink,children:(0,a.Y)(C.Nq,{className:U.A.headerPubAvatar,pub:n,size:32})}),(0,a.FD)(Y.I1,{justifyContent:"center",children:[(0,a.Y)(M,{pub:n,className:U.A.headerPubLink,children:(0,a.Y)(Y.EY.B3,{weight:"semibold",decoration:"none",children:n.display_name_for_chat})}),i?(0,a.FD)(Y.Ye,{gap:4,alignItems:"center",children:[(0,a.Y)(T.Q,{}),(0,a.Y)(Y.EY.B5,{color:"secondary",children:"Pinned"})]}):u&&(0,a.FD)(Y.Ye,{gap:4,alignItems:"center",children:[m?(0,a.Y)(f.A,{size:12,color:"var(--color-fg-secondary)"}):(0,a.Y)(y.A,{size:12,color:"var(--color-fg-secondary)"}),(0,a.Y)(Y.EY.B5,{color:"secondary",children:h(p?"Founding members only":"Paid subscribers only")})]})]})]}),(0,a.FD)(Y.pT,{gap:8,children:[!l&&(0,a.FD)(Y.K0,{priority:"tertiary",onClick:s,children:[(0,a.Y)(d.A,{size:20})," "]}),!l&&(0,a.Y)(I.PN,{pubId:n.id}),(0,a.Y)(V,{pub:n})]})]})})}function B(e){let{onBack:t,menu:n}=e;return(0,a.FD)(F.ep,{children:[t&&(0,a.Y)(Y.K0,{onClick:t,priority:"tertiary",children:(0,a.Y)(c.A,{size:20})}),(0,a.FD)(Y.Ye,{flex:"grow",alignItems:"center",children:[(0,a.Y)(Y.pT,{flex:"grow",gap:12,children:(0,a.Y)(Y.EY.B3,{weight:"semibold",children:"Replies"})}),n]})]})}function M(e){var{pub:t,children:n,className:o}=e,d=(0,r._)(e,["pub","children","className"]);return(0,a.Y)(Y.pT,(0,l._)((0,i._)({},d),{alignItems:"center",as:"a",target:"_blank",href:(0,N.fOI)(t,{signedIn:!0}),className:o,children:n}))}function V(e){let{pub:t}=e,{element:n,menuItems:i}=function(e){var t,n,i;let l=(0,x.SC)(),{iString:r,iTemplate:o}=(0,g.GO)(),d=(0,S.Pk)(),c=(0,k.iT)(d,e.id),s=(null==(t=e.threads_v2_settings)?void 0:t.boost_free_subscriber_chat_preview_enabled)&&!(null==c||null==(n=c.paywallStatus)?void 0:n.is_allowed_access),p=d.chats.get(e.id),m=(null==p||null==(i=p.muteStatus)?void 0:i.type)==="leave",h=(0,_.c)();return{element:(0,a.Y)(x.uo,{modal:l,title:r("Leave chat?"),body:o(z(),e.name),cancelLabel:r("Cancel"),confirmLabel:r("Leave")}),menuItems:(0,a.FD)(a.FK,{children:[(0,a.Y)(w.Dr,{leading:(0,a.Y)(u.A,{}),onClick:()=>h((0,R.p6)(e.id)),children:r("Copy link")}),!m&&(0,a.FD)(w.H9,{children:[(0,a.Y)(J,{pubId:e.id}),!s&&(0,a.Y)(K,{pubId:e.id})]}),(0,a.Y)(G,{pub:e,confirmModal:l})]})}}(t);return(0,a.FD)(a.FK,{children:[n,(0,a.Y)(w.W1,{trigger:(0,a.Y)(Y.K0,{priority:"tertiary","aria-label":"Options",children:(0,a.Y)(s.A,{size:20})}),children:i})]})}let j=e=>{let{pubId:t}=e,n=(0,S.wA)(),i=(0,x.SC)(),l=(0,P.d)(),r=(0,O.v)(),{iString:o}=(0,g.GO)();return{handleJoinChat:async e=>{if(e.preventDefault(),!i.isConfirming&&await i.confirm())try{let e=(await (0,b.x6)("/api/v1/publication/public/".concat(t))).pub;await (0,b.x6)("/api/v1/community/publications/".concat(e.id,"/mute"),{method:"POST",json:{is_muted:!1}}),l.popToast(()=>(0,a.Y)(P.y,{text:o("Chat joined"),Icon:p.A})),n({type:"pub_chat-join",payload:e})}catch(e){r(e,o("Failed to join chat"))}},confirmJoinModal:(0,a.Y)(x.uo,{modal:i,title:o("Join the chat?"),body:o("Chat members can react and reply to every thread."),cancelLabel:o("Cancel"),confirmLabel:o("Join chat")})}};function G(e){let{pub:t,confirmModal:n}=e,i=(0,S.Pk)(),l=(0,S.wA)(),r=(0,P.d)(),{iString:o}=(0,g.GO)(),{handleJoinChat:d,confirmJoinModal:c}=j({pubId:t.id}),s=(0,v.lq)(),u=i.chats.get(t.id),p=null==u?void 0:u.muteStatus,y=async e=>{if(e.preventDefault(),!n.isConfirming&&await n.confirm())try{await (0,b.x6)("/api/v1/community/publications/".concat(t.id,"/mute"),{method:"POST",json:{is_muted:!0,type:"leave"}}),r.popToast(()=>(0,a.Y)(P.y,{text:o("You left the chat")})),l({type:"pub_chat-leave",payload:t}),s("/chat")}catch(t){console.error(t);let e="PUB_AUTHOR_CANNOT_LEAVE_CHAT"===t.body.status?o("Publication authors cannot leave their own chats"):o("Failed to leave chat");r.popToast(()=>(0,a.Y)(P.y,{text:e}))}};return(0,a.FD)(a.FK,{children:[(0,a.Y)(w.H9,{children:(null==p?void 0:p.type)==="leave"?(0,a.Y)(w.Dr,{leading:(0,a.Y)(m.A,{}),onClick:d,children:o("Join chat")}):(0,a.Y)(w.Dr,{leading:(0,a.Y)(h.A,{}),priority:"destructive",onClick:y,children:o("Leave")})}),c]})}function J(e){var t;let{pubId:n}=e,i=(0,S.Pk)(),l=(0,O.v)(),r=(0,S.wA)(),o=(0,P.d)(),{iString:d}=(0,g.GO)(),c=(0,k.NH)(n),s=null==(t=i.inbox.threads.get(c))?void 0:t.isPinned,u=async e=>{try{r({type:"inbox-pin",payload:{itemId:c,isPinned:e}}),await (0,b.x6)("/api/v1/community/chat/".concat(n,"/pin"),{method:e?"POST":"DELETE"}),o.popToast(()=>(0,a.Y)(P.y,{text:e?"Chat pinned":"Chat unpinned"}))}catch(t){console.error(t),l(t,e?d("Failed to pin chat"):d("Failed to unpin chat"))}};return(0,a.Y)(D.Sm,{isPinned:!!s,onClick:u})}function K(e){let{pubId:t}=e,{isMuted:n,handleUnmute:i,handleMute:l}=(0,I.H2)({pubId:t});return n?(0,a.Y)(I.MI,{onClick:i}):(0,a.Y)(I.DE,{onMute:l})}},34389:function(e,t,n){n.d(t,{o:()=>m});var i=n(69277),l=n(70408),r=n(83673),o=n.n(r),a=n(17402),d=n(46271),c=n(94729),s=n(68349),u=n(53457),p=n(463);function m(e){let{defaultValue:t="",maxImagesToUpload:n,onSubmit:r,defaultPostAudience:m="all_subscribers",initialMediaAssets:h,initialMediaUpload:y,editingPostId:f}=e,g=(0,d.Jd)(),[b,_]=(0,a.useState)({sendAsEmail:!1,sendPush:!0}),[v,Y]=(0,a.useState)(m),[w,C]=(0,a.useState)(t),[P,F]=(0,a.useState)(),[D,T]=(0,a.useState)(null),I=(0,a.useRef)(null),{files:k,clearFiles:S,addFiles:A,removeFile:E}=function(){let{initialFiles:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(e){let{resolve:t,initialFiles:n}=e,[r,o]=(0,a.useState)(null!=n?n:[]);return{files:r,clearFiles:()=>{o([])},addFiles:e=>{let n=e.map(e=>{let n={file:e,url:URL.createObjectURL(e)};return n.promise=t(e).then(e=>(0,l._)((0,i._)({},n),{result:e})).catch(e=>(0,l._)((0,i._)({},n),{error:e})).then(e=>(o(t=>t.map(t=>t===n?e:t)),e)),n});o(e=>[...e,...n])},removeFile:e=>{o(t=>t.filter(t=>t!==e))}}}({resolve:async e=>{let t=await (0,s.YK)(e);return(0,c.x6)("/api/v1/image",{method:"POST",json:{image:t}})},initialFiles:e})}({initialFiles:(null!=h?h:[]).map(e=>{let{url:t}=e;return{url:t}})}),[x,O]=(0,a.useState)(null),{mediaUpload:N,setMediaUpload:R}=function(){let{initialMediaUpload:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},[t,n]=(0,a.useState)(null!=e?e:null);return{mediaUpload:t,setMediaUpload:n}}({initialMediaUpload:y}),U=x&&!N,z="You can only upload ".concat(n," ").concat(n>1?"images":"image"," at a time."),L=(0,u.B)(D,{auto:!0});(0,a.useEffect)(()=>{N||O(null)},[N]);let B=!U&&(""!==w.trim()||k.length>0||N||null!=D&&L.data),[M,V]=(0,a.useState)(!1),j=(0,a.useRef)(),G=(0,a.useRef)(!1),J=async e=>{let t,n;if(null==e||e.preventDefault(),!M&&!G.current){if(G.current=!0,j.current){let{text:e,mentionMap:i}=j.current();n=e.trim(),t=i.size>0?Object.fromEntries(i):void 0}else n=w.trim(),t=P?(0,i._)({},P):void 0;if(""!==n||k.length>0||N||null!=D&&L.data){let e=o()(await Promise.all(k.map(e=>e.promise)));if(e.some(e=>e.error)){alert("Some of your files failed to upload."),G.current=!1;return}C(""),S(),V(!0),F(void 0),T(null),O(null),R(null);let a=[...k.filter(e=>{let{promise:t}=e;return!t}).map(e=>{let{url:t}=e;return{url:t}}),...o()(e.map(e=>{let{file:t,result:n}=e;return t&&n?(0,l._)((0,i._)({},n),{file:t}):null}))];setTimeout(()=>{r((0,l._)((0,i._)({},b),{value:n,audience:v,mediaAssets:a,mentions:t,linkUrl:L.data?D:null,linkMetadata:L.data,mediaUpload:N,editingPostId:f})),G.current=!1},0)}else G.current=!1}},K=(0,a.useRef)(null);return(0,a.useEffect)(()=>(I.current&&clearTimeout(I.current),I.current=setTimeout(()=>{let e=(0,p.P2)(w);T(t=>e.length>0?e[0].href:t)},500),()=>{I.current&&clearTimeout(I.current)}),[w,T]),{user:g,canSubmit:B,files:k,addFiles:A,linkUrl:D,setLinkUrl:T,linkMetadata:L.data,handleSubmit:J,inputFile:K,removeFile:E,onChangeFile:e=>{e.stopPropagation(),e.preventDefault();let t=[...e.target.files];t.length+k.length>n?alert("".concat(z," Please try again.")):A(t),(null==K?void 0:K.current)&&(K.current.value="")},onImageButtonClick:()=>{if(k.length>=n)alert(z);else{var e;null==(e=K.current)||e.click()}},textValue:w,setTextValue:C,setMentionMap:F,handleKeyDown:function(e){let t=!(arguments.length>1)||void 0===arguments[1]||arguments[1];B&&(!t||"Enter"!==e.key||e.shiftKey||e.altKey||J(e))},setOptions:_,setOption:(e,t)=>_(n=>(0,l._)((0,i._)({},n),{[e]:t})),options:b,postAudienceHandler:{value:v,set:Y},submissionTracker:{isSubmitting:M,clearSubmission:()=>V(!1)},getContentRef:j,selectedVideoFile:x,setSelectedVideoFile:O,mediaUpload:N,setMediaUpload:R}}},31117:function(e,t,n){n.d(t,{B:()=>i});function i(e){var t;let{publication:n,isAuthor:i,isSubscribed:l,isFounding:r,isPaid:o}=e;return!!(n&&("free"===n.paywall_chat||(null==(t=n.threads_v2_settings)?void 0:t.boost_free_subscriber_chat_preview_enabled))&&("free"===n.paywall_chat&&!l||"paid"===n.paywall_chat&&!(o||i)||"founding"===n.paywall_chat&&!(r||i)))}},66093:function(e,t,n){n.d(t,{a:()=>d});var i=n(17402),l=n(36319),r=n(70486),o=n(32848),a=n(43296);function d(e){let{pubId:t,handleReconnect:n}=e,d=(0,r.wA)(),{isAuthor:c,isFounding:s,isPaid:u,isSubscribed:p}=(0,o.NL)(t),m=(0,i.useRef)(!1),h=(0,a.XW)();(0,i.useEffect)(()=>{if(h&&n)return h.onConnectivityChange(e=>{"open"===e&&(m.current?n():m.current=!0)})},[n,t,h]);let y=c||s?"only_founding":u?"only_paid":p?"all_subscribers":null;(0,i.useEffect)(()=>{if(h&&y)return h.listen({["chat:".concat(t,":").concat(y)]:e=>{let{data:t}=e,n=null==t?void 0:t.message;(null==n?void 0:n.type)==="chat:updated-post"?d((0,l.QC)(n)):(null==n?void 0:n.type)==="chat:new-post"?d((0,l.jg)(n)):(null==n?void 0:n.type)==="chat:new-comment"?d((0,l.EM)(n)):(null==n?void 0:n.type)==="chat:updated-comment"&&d((0,l.Dv)(n))}})},[t,y,h])}},74470:function(e,t,n){n.d(t,{F:()=>l});var i=n(17402);let l=e=>{let{preferredStart:t}=e,n=(0,i.useRef)(null),[l,r]=(0,i.useState)("bottom"===t),o=(0,i.useRef)("bottom"===t),a=(0,i.useRef)(0);return{isScrolledToBottom:l,listRef:n,observeScrollPosition:e=>{if(!n.current)return!1;let t=e-n.current.scrollSize+n.current.viewportSize>=-1.5;return t!==l&&r(t),o.current=t,t},scrollToBottom:()=>{setTimeout(()=>{var e,t;null==(e=n.current)||e.scrollToIndex((null!=(t=a.current)?t:0)-1,{align:"end"})},0)},scrollToOffset:e=>{var t;o.current=!1,null==(t=n.current)||t.scrollTo(e)},shouldStickToBottom:o,listLengthRef:a}}},99715:function(e,t,n){n.d(t,{S:()=>y});var i=n(69277),l=n(4006),r=n(45994),o=n(48697),a=n(95032),d=n(68349),c=n(68410),s=n(17028),u=n(57820),p=n(36372),m=n(20437),h=n(97555);function y(e){let{file:t,initialMediaUpload:n,onCancel:i,onRemoveVideo:y,onComplete:g,maxVideoDurationSeconds:b,videoPlayerProps:_,postAsUserId:v}=e,Y=(0,r.li)(null),{isMobile:w}=(0,c.sM)(),[C,P]=(0,r.J0)(!1),[F,D]=(0,r.J0)(null!=n?n:null),[T,I]=(0,r.J0)(null),k=(0,p.d)(),S=(0,h.Q)({onComplete:e=>{let{mediaUpload:t}=e;D(t),g({mediaUpload:t})},onError:e=>{console.error("something went wrong",e),D(null),P(!1),I(null),k.popToast(()=>{var t;return(0,l.Y)(p.y,{text:null!=(t=(0,d.uX)(e))?t:"Something went wrong. Please try again."})})}});if((0,r.vJ)(()=>{if(!t)return;let e=Y.current;return e?(e.src=URL.createObjectURL(t),()=>{URL.revokeObjectURL(e.src)}):void console.error("Video not found")},[t]),(0,r.vJ)(()=>{D(n)},[n]),!t&&!F)return null;let A=()=>{S.cancel(),D(null),P(!1),I(null),i()};if(!t&&F&&"uploaded"===F.state)return(0,l.Y)(f,{mediaUpload:F});if(F&&"transcoded"===F.state)return(0,l.Y)(s.Ye,{wrap:"wrap",children:(0,l.FD)(s.Ye,{position:"relative",children:[(0,l.Y)(m.R8,{mediaUpload:F,videoPlayerProps:_,composing:!0}),(0,l.Y)(s.mZ,{onClick:()=>{S.cancel(),D(null),P(!1),I(null),y()},priority:"primary",position:"absolute",className:"remove-Gneeir",rounded:!0,size:"sm",children:(0,l.Y)(o.A,{size:"20"})})]})});let E=w?m.PH:m.di;return(0,l.FD)(s.Ye,{wrap:"wrap",position:"relative",children:[(0,l.Y)(a.V,{initialFile:t,maxVideoDurationSeconds:b,postAsUserId:v,onVideoTooLong:()=>{k.popToast(()=>(0,l.Y)(p.y,{text:"Video is too long. Maximum duration is ".concat(b," seconds.")})),A()},videoFeature:"hero",mediaType:"video",onProgress:e=>{let{percentComplete:t}=e;I(t)},onUpload:e=>{P(!0);let t=e.mediaUpload;D(t),S.startPolling({mediaUpload:t})},setPostId:null,onUploadCanceled:()=>{A()}}),(0,l.FD)(s.Ye,{position:"relative",radius:"md",outline:"detail",bg:"secondary",overflow:"hidden",children:[(0,l.Y)("video",{ref:Y,className:"videoPlaceholder-Z0QT3t",style:{maxHeight:"".concat(E,"px"),maxWidth:"".concat(E,"px")}}),(0,l.FD)(s.I1,{position:"absolute",inset:0,justifyContent:"center",alignItems:"center",children:[(0,l.Y)(s.mZ,{priority:"primary",rounded:!0,size:"lg",onClick:()=>{A()},children:(0,l.Y)(o.A,{size:20})}),(0,l.Y)(s.az,{position:"absolute",style:{pointerEvents:"none"},children:C||T&&T>=1?(0,l.Y)(u.y$,{size:40,theme:"media"}):(0,l.Y)(u.t4,{percent:null!=T?T:0,size:40,theme:"media"})})]})]})]})}let f=e=>{var t,n;let{mediaUpload:r}=e,a=null!=(t=r.width)?t:640,d=null!=(n=r.height)?n:360,c=d>a;return(0,l.FD)(s.Ye,{alignItems:"center",bg:"secondary",justifyContent:"center",radius:"md",position:"relative",style:(0,i._)({aspectRatio:"".concat(a," / ").concat(d)},c?{height:400,alignSelf:"flex-start"}:{width:"100%"}),children:[(0,l.Y)(s.mZ,{priority:"primary",rounded:!0,size:"lg",disabled:!0,children:(0,l.Y)(o.A,{size:20})}),(0,l.Y)(s.az,{position:"absolute",style:{pointerEvents:"none"},children:(0,l.Y)(u.y$,{size:40,theme:"media"})})]})}},97555:function(e,t,n){n.d(t,{Q:()=>r});var i=n(45994),l=n(94729);function r(e){let{onComplete:t,onError:n}=e,[r,o]=(0,i.J0)({mediaState:"waitingForUpload",mediaUpload:null}),a=(0,i.hb)(async()=>{"polling"===r.mediaState&&r.pollTranscodeTimer&&clearTimeout(r.pollTranscodeTimer)},[r]),d=async()=>{if("polling"!==r.mediaState){console.warn("pollForCompletion called, state must be uploaded|polling but was",r.mediaState);let e=Error("pollForCompletion called, state must be uploaded|polling but was [".concat(r.mediaState,"]"));o({mediaState:"error",mediaUpload:r.mediaUpload,error:e}),n({err:e});return}try{let e=await (0,l.x6)("/api/v1/video/upload/".concat(r.mediaUpload.id),{method:"GET"});switch(e.state){case"error":{let t=Error("media upload was in error state");o({mediaState:"error",mediaUpload:e,error:t}),n({err:t});break}case"cancelled":{let t=Error("media upload was in canceled state");o({mediaState:"error",mediaUpload:e,error:t}),n({err:t});break}case"transcoded":o({mediaState:"complete",mediaUpload:e}),t({mediaUpload:e});break;case"created":case"uploaded":{let e=window.setTimeout(()=>{d()},5e3);o(t=>"polling"!==t.mediaState?(console.warn("in pollForCompletion, prev.mediaState should be polling but was ",t.mediaState),t):{mediaState:"polling",mediaUpload:t.mediaUpload,pollTranscodeTimer:e});break}default:console.error("unhandled state for media upload",e)}}catch(e){console.error("Failed to load media upload:",e),o({mediaState:"error",error:e,mediaUpload:r.mediaUpload}),n({err:e})}};return(0,i.vJ)(()=>("polling"===r.mediaState&&null===r.pollTranscodeTimer&&d(),()=>{"polling"===r.mediaState&&r.pollTranscodeTimer&&clearTimeout(r.pollTranscodeTimer)}),[r]),{mediaUpload:r.mediaUpload,mediaState:r.mediaState,cancel:a,startPolling:e=>{let{mediaUpload:t}=e;"uploaded"!==t.state&&console.warn("startPolling called, but mediaUpload was not in state uploaded, was [".concat(t.state,"]")),o({mediaState:"polling",mediaUpload:t,pollTranscodeTimer:null})}}}}}]);