"use strict";(self.webpackChunksubstack=self.webpackChunksubstack||[]).push([["2667"],{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),o=r(18693),d=r(7073),c=r(71375),u=r(25380),h=r(68833),g=r(48980),p=r(63018),f=r(94874),Z=r(80026),m=r(98248),v=r(40225),y=r(70379),_=r(55533),w=r(33451),S=r(37759),b=r(12120),k=r(62515),x=r(63651);function C(e){let{onClose:t,linkAttachmentUrl:r}=e,[u,p]=(0,s.eJ)(new Set),f=(0,y.pm)(),m=(0,s.sO)(null),v=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,b.oR)(t,e.user.id));try{var t,s,a;let d=await (0,g.rd)("/api/v1/messages/dm",{method:"POST",json:{user_id:e.user.id,link:r,body:null!==(a=null===(s=m.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)(y.FN,(0,i._)((0,n._)({},e),{text:"Message sent",Icon:o.Z,cta:"View now",href:(0,k.Rm)(d.thread.id)})))}catch(t){f.popToast(e=>(0,l.tZ)(y.FN,(0,i._)((0,n._)({},e),{text:"Message failed to send",Icon:d.Z}))),p(t=>(0,b.zu)(t,e.user.id))}}};return(0,l.BX)(Z.sg,{style:{height:720,maxHeight:"calc(100vh - 32px)"},flex:"grow",children:[(0,l.BX)(Z.X2,{position:"relative",padding:12,justifyContent:"space-between",alignItems:"center",borderBottom:"detail",children:[(0,l.tZ)(Z.xu,{width:32}),(0,l.tZ)(a.V.Title,{className:(0,Z.oB)((0,i._)((0,n._)({},Z.et),{fontWeight:"bold"})),children:"Send as message"}),(0,l.tZ)(Z.hU,{onClick:t,priority:"tertiary",size:"sm",children:(0,l.tZ)(c.Z,{})})]}),(0,l.BX)(Z.sg,{padding:16,gap:16,children:[r&&(0,l.tZ)(E,{url:r}),(0,l.tZ)("textarea",{ref:m,style:{border:"none",background:"none",resize:"none"},className:(0,Z.oB)((0,i._)((0,n._)({},Z.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:v,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)(Z.sg,{radius:"lg",bg:"secondary",overflow:"hidden",children:n||i?(0,l.tZ)(w.Gt,{}):r?(0,l.tZ)(w.bO,{metadata:r}):(0,l.tZ)(w.Ii,{})})}function B(e){var t,r;let{onSelect:n,selectedIds:i}=e,{query:a,handleSearch:o,data:d,isLoading:c,error:u}=(0,S.C)(),g=[...null!==(t=null==d?void 0:d.users)&&void 0!==t?t:[],...null!==(r=null==d?void 0:d.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)(Z.sg,{gap:8,flex:"grow",children:[(0,l.tZ)(Z.sg,{paddingX:16,children:(0,l.tZ)(v.M,{placeholder:"Search people",onChange:o})}),(0,l.tZ)(Z.sg,{padding:8,flex:"grow",overflowY:"auto",children:u?(0,l.tZ)(_.vJ,{title:"Error performing search",body:"Please try again"}):c?(0,l.tZ)(Z.sg,{flex:"grow",children:(0,l.tZ)(m.$j,{})}):0===g.length?""===a.trim()?(0,l.tZ)(_.vJ,{title:"Search people on Substack",body:"Start typing to find someone you know"}):(0,l.tZ)(_.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)(Z.X2,{padding:8,gap:12,alignItems:"center",children:[(0,l.tZ)(f.qE,{user:t,size:40}),(0,l.BX)(Z.sg,{flex:"grow",children:[(0,l.tZ)(Z.xv.B3,{weight:"bold",ellipsis:!0,children:(0,l.tZ)(Z.hh,{href:(0,x.NNq)(t),target:"_blank",decoration:"hover-underline",rel:"noopener",children:t.name})}),t.handle&&(0,l.BX)(Z.xv.B4,{color:"secondary",ellipsis:!0,children:["@",t.handle]})]}),n?(0,l.tZ)(Z.zx,{size:"sm",priority:"tertiary",disabled:!0,leading:(0,l.tZ)(u.Z,{size:20}),children:"Sent"}):(0,l.tZ)(Z.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})}}]);