/*! For license information please see 2667.050bc694.js.LICENSE.txt */ "use strict";(self.webpackChunksubstack=self.webpackChunksubstack||[]).push([["2667"],{7073:function(e,t,r){r.d(t,{Z:()=>n});let n=(0,r(36150).Z)("CircleAlert",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]])},18693:function(e,t,r){r.d(t,{Z:()=>n});let n=(0,r(36150).Z)("CircleCheckBig",[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]])},84422:function(e,t,r){r.r(t),r.d(t,{DmComposerModal:()=>C});var n=r(7409),i=r(99282),l=r(16584),s=r(30396),a=r(12048),d=r(18693),o=r(7073),c=r(71375),u=r(25380),h=r(68833),g=r(48980),p=r(63018),f=r(94874),y=r(80026),Z=r(98248),m=r(40225),k=r(70379),v=r(55533),x=r(33451),_=r(37759),w=r(12120),S=r(62515),b=r(63651);function C(e){let{onClose:t,linkAttachmentUrl:r}=e,[u,p]=(0,s.eJ)(new Set),f=(0,k.pm)(),Z=(0,s.sO)(null),m=async e=>{if(!u.has(e.user.id)){e.trackingParameters&&(0,h.j)(h.FP.DIRECT_MESSAGE_SEARCH_RESULT_CLICKED,(0,n._)({},e.trackingParameters)),p(t=>(0,w.oR)(t,e.user.id));try{var t,s,a;let o=await (0,g.rd)("/api/v1/messages/dm",{method:"POST",json:{user_id:e.user.id,link:r,body:null!==(a=null===(s=Z.current)||void 0===s?void 0:null===(t=s.value)||void 0===t?void 0:t.trim())&&void 0!==a?a:""}});f.popToast(e=>(0,l.tZ)(k.FN,(0,i._)((0,n._)({},e),{text:"Message sent",Icon:d.Z,cta:"View now",href:(0,S.Rm)(o.thread.id)})))}catch(t){f.popToast(e=>(0,l.tZ)(k.FN,(0,i._)((0,n._)({},e),{text:"Message failed to send",Icon:o.Z}))),p(t=>(0,w.zu)(t,e.user.id))}}};return(0,l.BX)(y.sg,{style:{height:720,maxHeight:"calc(100vh - 32px)"},flex:"grow",children:[(0,l.BX)(y.X2,{position:"relative",padding:12,justifyContent:"space-between",alignItems:"center",borderBottom:"detail",children:[(0,l.tZ)(y.xu,{width:32}),(0,l.tZ)(a.V.Title,{className:(0,y.oB)((0,i._)((0,n._)({},y.et),{fontWeight:"bold"})),children:"Send as message"}),(0,l.tZ)(y.hU,{onClick:t,priority:"tertiary",size:"sm",children:(0,l.tZ)(c.Z,{})})]}),(0,l.BX)(y.sg,{padding:16,gap:16,children:[r&&(0,l.tZ)(E,{url:r}),(0,l.tZ)("textarea",{ref:Z,style:{border:"none",background:"none",resize:"none"},className:(0,y.oB)((0,i._)((0,n._)({},y.et),{minHeight:24,height:24,display:"flex",color:"primary"})),placeholder:"Add a message...",onInput:e=>{let t=e.currentTarget;t.style.height="auto",t.style.height="".concat(t.scrollHeight,"px")}})]}),(0,l.tZ)(B,{onSelect:m,selectedIds:u})]})}function E(e){let{url:t}=e,{data:r,isLoading:n,isValidating:i}=(0,p._I)("/api/v1/link-metadata",{query:{url:t},deps:[t]});return(0,l.tZ)(y.sg,{radius:"lg",bg:"secondary",overflow:"hidden",children:n||i?(0,l.tZ)(x.Gt,{}):r?(0,l.tZ)(x.bO,{metadata:r}):(0,l.tZ)(x.Ii,{})})}function B(e){var t,r;let{onSelect:n,selectedIds:i}=e,{query:a,handleSearch:d,data:o,isLoading:c,error:u}=(0,_.C)(),g=[...null!==(t=null==o?void 0:o.users)&&void 0!==t?t:[],...null!==(r=null==o?void 0:o.otherUsers)&&void 0!==r?r:[]],p=(0,s.sO)(!1);return(0,s.d4)(()=>{a||!(g.length>0)||p.current||(p.current=!0,(0,h.j)(h.FP.DIRECT_MESSAGE_SEARCH_VIEWED,{suggested_user_ids:g.map(e=>e.user.id),suggested_users:g.length}))},[g.length,a]),(0,l.BX)(y.sg,{gap:8,flex:"grow",children:[(0,l.tZ)(y.sg,{paddingX:16,children:(0,l.tZ)(m.M,{placeholder:"Search people",onChange:d})}),(0,l.tZ)(y.sg,{padding:8,flex:"grow",overflowY:"auto",children:u?(0,l.tZ)(v.vJ,{title:"Error performing search",body:"Please try again"}):c?(0,l.tZ)(y.sg,{flex:"grow",children:(0,l.tZ)(Z.$j,{})}):0===g.length?""===a.trim()?(0,l.tZ)(v.vJ,{title:"Search people on Substack",body:"Start typing to find someone you know"}):(0,l.tZ)(v.vJ,{title:"No results for “".concat(a,"”"),body:"Please try a different search"}):g.map(e=>(0,l.tZ)(I,{user:e.user,onClick:()=>n(e),hasClicked:i.has(e.user.id)},e.user.id))})]})}function I(e){let{user:t,onClick:r,hasClicked:n}=e;return(0,l.BX)(y.X2,{padding:8,gap:12,alignItems:"center",children:[(0,l.tZ)(f.qE,{user:t,size:40}),(0,l.BX)(y.sg,{flex:"grow",children:[(0,l.tZ)(y.xv.B3,{weight:"bold",ellipsis:!0,children:(0,l.tZ)(y.hh,{href:(0,b.NNq)(t),target:"_blank",decoration:"hover-underline",rel:"noopener",children:t.name})}),t.handle&&(0,l.BX)(y.xv.B4,{color:"secondary",ellipsis:!0,children:["@",t.handle]})]}),n?(0,l.tZ)(y.zx,{size:"sm",priority:"tertiary",disabled:!0,leading:(0,l.tZ)(u.Z,{size:20}),children:"Sent"}):(0,l.tZ)(y.zx,{size:"sm",onClick:r,children:"Send"})]})}},12120:function(e,t,r){function n(e,t){let r=new Set(e);return r.add(t),r}function i(e,t){let r=new Set(e);return r.delete(t),r}function l(e,t){return new Set([...e].filter(e=>!t.has(e)))}r.d(t,{e5:()=>l,oR:()=>n,zu:()=>i})}}]);