(self.webpackChunksubstack=self.webpackChunksubstack||[]).push([["3875"],{7739:function(e,t,r){var o=r(89465),n=r(55189),s=Object.prototype.hasOwnProperty,u=n(function(e,t,r){s.call(e,r)?e[r].push(t):o(e,r,[t])});e.exports=u},89724:function(e,t,r){"use strict";r.r(t),r.d(t,{searchIterator_forTests:()=>L,PublicationSearch:()=>x});var o=r(7409),n=r(99282),s=r(16584),u=r(30396),l=r(39693),a=r.n(l),i=r(7739),c=r.n(i),d=r(24840),p=r(71171),h=r.n(p),f=r(33804),g=r(53311),_=r(40647),b=r(68833),y=r(7882),m=r(63018),v=r(98914),S=r(80026),k=r(55533),P=r(64172),w=r(32071),I=r(60308),Z=r(47929);let C={noQueryZeroState:"noQueryZeroState-kIZZPN",noResultsZeroState:"noResultsZeroState-x7mQpE"};function*R(e,t){let r=t.toUpperCase().trim();if(!r||!e)return;let o=RegExp("\\b".concat(t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"\\b"),"i"),n=new Set,s=new Set,u=[e=>o.test(e.title),e=>o.test(e.subtitle),e=>(0,w.u)([e.title,e.subtitle,e.truncated_body]).some(e=>e.includes(r))];for(let t of[e=>o.test(e.name),e=>(0,w.u)([e.name]).some(e=>e.includes(r))])for(let r of e.authors)!n.has(r.user_id)&&t(r)&&(n.add(r.user_id),yield{type:"user",user:r});for(let t of u)for(let r of e.posts)!s.has(r.slug)&&t(r)&&(s.add(r.slug),yield{type:"post",post:r})}let L=R;function T(e){return(0,I.n1t)(e,{utm_source:Z.b3.publicationSearch})}function N(e,t,r,o,n){let s=r,u=[],l=c()(e,"type");for(let e of Object.keys(l)){let r=l[e];if(r&&0!==r.length){for(let l of(u.push({id:"header-".concat(e,"-").concat(t),type:"result-group-header",header:"user"===e?"People":"Posts",trackingParameters:{rank:s++,search_id:t,result_count:o,score:-1,result_id:"header-".concat(e),search_key:"publication_search",from_server:!1}}),r))if("post"===l.type)u.push({id:"post-".concat(l.post.slug,"-").concat(t),type:"post",trackingParameters:{rank:s++,result_count:o,score:-1,result_id:"post-".concat(l.post.slug),search_id:t,search_key:"publication_search",from_server:!1},post:{title:l.post.title,subtitle:l.post.subtitle,url:T(l.post.url),body:l.post.truncated_body,audience:l.post.audience,date:l.post.post_date,image:l.post.cover_image,highlights:l.highlights,is_paywalled:n.includes(l.post.audience)}});else if("user"===l.type){var a;u.push({id:"user-".concat(l.user.user_id,"-").concat(t),type:"user",trackingParameters:{rank:s++,result_count:o,score:-1,result_id:"user-".concat(l.user.user_id),search_id:t,search_key:"publication_search",from_server:!1},user:{id:l.user.user_id,name:l.user.name,handle:l.user.handle,bestseller_tier:l.user.bestseller_tier,photo_url:null!==(a=l.user.photo_url)&&void 0!==a?a:(0,I.I4e)(l.user.user_id),pub:l.user.pub,profile_url:T((0,I.GR3)(l.user.user_id,l.user.name)),is_pub_search:!0}})}}}return u}function x(e){let{isOpen:t,postsOnly:r,pub:l,zIndex:i,onClose:c,onSelectResult:p}=e,{getConfigFor:w}=(0,_.xR)(),Z=w("enable_author_pages"),{search:L,recentPosts:T,authors:x}=function(e){let{isOpen:t}=e,{data:r}=(0,m._I)("/api/v1/publication/client-search-cache",{auto:t,shouldRevalidate:!1}),o=null==r?void 0:r.recentPosts,n=(0,u.Ye)(()=>{var e;return null!==(e=null==o?void 0:o.map(e=>({type:"post",post:e})))&&void 0!==e?e:[]},[o]),s=null==r?void 0:r.authors;return{search:e=>R(r,e),get isLoaded(){return!!r},recentPosts:n,authors:(0,u.Ye)(()=>{var e;return null!==(e=null==s?void 0:s.map(e=>({type:"user",user:e})))&&void 0!==e?e:[]},[s])}}({isOpen:t}),{search:E}=function(e){let{refetch:t}=(0,y.ib)({pathname:"/api/v1/post/search",method:"GET",auto:!1});return{async search(r){let o=await t({query:{query:r,focusedPublicationId:e.id,page:0,numberFocused:10}});return o instanceof Error?(console.error(o),[]):o.results.map(t=>{var r,n,s,u,l,a,i;let c=null!==(n=null===(r=o.highlights)||void 0===r?void 0:r[t.id])&&void 0!==n?n:[];return s=t,u=e,l=c,{type:"post",post:{post_id:s.id,title:s.title,subtitle:s.subtitle,truncated_body:null!==(a=s.truncated_body_text)&&void 0!==a?a:void 0,audience:s.audience,url:(0,I.MoQ)(u,s.slug),post_date:s.post_date,cover_image:null!==(i=s.cover_image)&&void 0!==i?i:void 0,slug:s.slug,publication_id:s.publication_id},highlights:l}})}}}(l),[{results:O,isLoading:A},U]=(0,u.eJ)({results:[],isLoading:!1}),[j,Q]=(0,u.eJ)(""),B=(0,u.Ye)(()=>O.filter(e=>!r||"post"===e.type).map(e=>{if("user"===e.type&&Z){var t,r,s,u;let a=null!==(r=null===(t=l.authorPagesInfo)||void 0===t?void 0:t.find(t=>t.user_id===e.user.id))&&void 0!==r?r:null;return(0,n._)((0,o._)({},e),{user:(0,n._)((0,o._)({},e.user),{photo_url:null!==(s=null==a?void 0:a.photo_url)&&void 0!==s?s:e.user.photo_url,profile_url:null!==(u=(0,I.rfk)({userId:e.user.id,pub:l}))&&void 0!==u?u:e.user.profile_url})})}return e}),[O,Z,l]),{isPaid:J,isFounding:F}=(0,P.Y0)(l.id),H=a()([J?null:"only_paid",F?null:"founding"]),X=(0,u.sO)({abort:null}),Y=()=>{var e;(null===(e=X.current)||void 0===e?void 0:e.abort)&&(X.current.abort(),X.current.abort=null)};(0,u.d4)(()=>{t&&Q("")},[t]),(0,u.d4)(()=>{if(!j){var e,t;Y(),U({results:(e=null!=x?x:[],t=null!=T?T:[],N([...e.slice(0,3),...t],"defaults",0,t.length,H)),isLoading:!1});return}q(j)},[j,x,T]);let q=(0,y.Kt)(async e=>{U({results:[],isLoading:!0}),Y();let t=new AbortController;X.current.abort=()=>t.abort();let r=h()(),s=L(e),u=new Set,l=[],a=0;for(let e of s){if(t.signal.aborted||l.length>=30)break;"post"===e.type&&u.add(e.post.slug),l.push(e),++a%20==0&&await new Promise(e=>setTimeout(e,50))}if(t.signal.aborted)return;let i=l.length;l.length&&U({results:N(l,r,0,i,H),isLoading:!0});let c=await E(e);if(t.signal.aborted)return;l.push(...c.filter(e=>"post"!==e.type||!u.has(e.post.slug))),U({results:N(l,r,i,l.length,H),isLoading:!1});let d={query:e,results:l.length,search_id:r};(0,b.j)(b.FP.PUBLICATION_SEARCH_RESULTS_SHOWN,(0,n._)((0,o._)({},d),{clientsideResultCount:i}))},300,[]);return(0,s.tZ)(f.w,{children:(0,s.tZ)(g.s,{placeholder:r?"Search posts":"Search people and posts",results:B,isOpen:t,onClose:()=>{Y(),c()},onEnter:(e,t)=>{if(p){p({result:e,onClose:c});return}(0,b.j)(b.FP.PUBLICATION_SEARCH_RESULT_CLICKED,(0,n._)((0,o._)({},e.trackingParameters),{result_type:e.type})),c(),"post"===e.type?(0,v.uX)(e.post.url,{newTab:t}):"user"===e.type&&(0,v.uX)(e.user.profile_url,{local_navigation:!1,newTab:t})},onQueryChange:e=>Q(e),noQueryZeroState:T.length>0?null:(0,s.BX)(S.sg,{className:C.noQueryZeroState,justifyContent:"center",alignItems:"center",padding:8,flex:"grow",gap:12,children:[(0,s.tZ)(d.Z,{}),(0,s.tZ)(k.vJ,{title:"Search ".concat(l?l.name:"this publication"),body:"Find people and posts in this publication",flex:"auto",padding:0})]}),noResultsZeroState:A?void 0:e=>(0,s.BX)(S.sg,{justifyContent:"center",alignItems:"center",padding:8,gap:12,flex:"grow",className:C.noResultsZeroState,children:[(0,s.tZ)(k.vJ,{title:"No results for ".concat(e),body:"Search across all of Substack instead?",padding:0,flex:"auto"}),(0,s.tZ)(S.zx,{priority:"primary-mono",href:e?"".concat((0,I.ZJn)(),"/search/").concat(e,"?searching=all_posts"):"/search",children:"Search all of Substack"})]}),isLoading:A,zIndex:i})})}},32071:function(e,t,r){"use strict";r.d(t,{u:()=>s});var o=r(39693),n=r.n(o);let s=e=>n()(e).map(e=>e.toUpperCase())},57319:function(e,t,r){"use strict";r.d(t,{q:()=>s});var o=r(98661),n=r(76396);function s(e,t,r){let[s,u]=(0,o.useState)(r),l=void 0!==e,a=(0,o.useRef)(l),i=(0,o.useRef)(!1),c=(0,o.useRef)(!1);return!l||a.current||i.current?l||!a.current||c.current||(c.current=!0,a.current=l,console.error("A component is changing from controlled to uncontrolled. This may be caused by the value changing from a defined value to undefined, which should not happen.")):(i.current=!0,a.current=l,console.error("A component is changing from uncontrolled to controlled. This may be caused by the value changing from undefined to a defined value, which should not happen.")),[l?e:s,(0,n.z)(e=>(l||u(e),null==t?void 0:t(e)))]}},45514:function(e,t,r){"use strict";r.d(t,{f:()=>u});var o=r(98661),n=r(98790);function s(e){var t;if(e.type)return e.type;let r=null!=(t=e.as)?t:"button";if("string"==typeof r&&"button"===r.toLowerCase())return"button"}function u(e,t){let[r,u]=(0,o.useState)(()=>s(e));return(0,n.e)(()=>{u(s(e))},[e.type,e.as]),(0,n.e)(()=>{r||t.current&&t.current instanceof HTMLButtonElement&&!t.current.hasAttribute("type")&&u("button")},[r,t]),r}},42800:function(e,t,r){"use strict";function o(e,t){return e?e+"["+t+"]":t}function n(e){var t,r;let o=null!=(t=null==e?void 0:e.form)?t:e.closest("form");if(o){for(let t of o.elements)if(t!==e&&("INPUT"===t.tagName&&"submit"===t.type||"BUTTON"===t.tagName&&"submit"===t.type||"INPUT"===t.nodeName&&"image"===t.type)){t.click();return}null==(r=o.requestSubmit)||r.call(o)}}r.d(t,{g:()=>n,t:()=>function e(t={},r=null,n=[]){for(let[s,u]of Object.entries(t))!function t(r,n,s){if(Array.isArray(s))for(let[e,u]of s.entries())t(r,o(n,e.toString()),u);else s instanceof Date?r.push([n,s.toISOString()]):"boolean"==typeof s?r.push([n,s?"1":"0"]):"string"==typeof s?r.push([n,s]):"number"==typeof s?r.push([n,`${s}`]):null==s?r.push([n,""]):e(s,n,r)}(n,o(r,s),u);return n}})}}]);