import{r as p,g as I,ay as V,F as i,a3 as x,j as s}from"./vendor-CT-JknSv.chunk.js";import{bL as P,bM as L,b as z,I as G,C as v,ar as O,P as C,G as j,l as N,i as E,a3 as f,ah as S,ae as D,a6 as $,bD as k}from"./index-DDZqnj79.js";import{H as h}from"./Header-CcAYibhJ.chunk.js";const M={channelsSearch:e=>["video_channels","search",{query:e}],episodesSearch:e=>["video_episodes","search",{query:e}],podcastChannelsSearch:e=>["podcast_channels","search",{query:e}],classesSearch:e=>["classes","search",{query:e}]},u={channelsSearch:e=>"video_channels/search/?"+new URLSearchParams({q:e}),episodesSearch:e=>"video_episodes/search/?"+new URLSearchParams({q:e}),podcastChannelsSearch:e=>"podcast_channels/search/?"+new URLSearchParams({q:e}),classesSearch:e=>"classes/search/?"+new URLSearchParams({q:e})};function Y({query:e}){const a=P(M.channelsSearch(e!=null?e:""),u.channelsSearch(e!=null?e:""),{enabled:!!e,meta:{wildcardPlaceholder:"paginated"}});return{channels:L(a.data),error:a.error,isInitialLoading:a.isInitialLoading,hasMore:a.hasNextPage,loadMore:async()=>a.fetchNextPage(),isLoadingMore:a.isFetchingNextPage}}function K({query:e}){const a=P(M.episodesSearch(e!=null?e:""),u.episodesSearch(e!=null?e:""),{enabled:!!e,meta:{wildcardPlaceholder:"paginated"}});return{episodes:L(a.data),error:a.error,isInitialLoading:a.isInitialLoading,hasMore:a.hasNextPage,loadMore:async()=>a.fetchNextPage(),isLoadingMore:a.isFetchingNextPage}}function X({query:e}){const a=P(M.podcastChannelsSearch(e!=null?e:""),u.podcastChannelsSearch(e!=null?e:""),{enabled:!!e,meta:{wildcardPlaceholder:"paginated"}});return{channels:L(a.data),error:a.error,isInitialLoading:a.isInitialLoading,hasMore:a.hasNextPage,loadMore:async()=>a.fetchNextPage(),isLoadingMore:a.isFetchingNextPage}}function J({query:e}){const a=P(M.classesSearch(e!=null?e:""),u.classesSearch(e!=null?e:""),{enabled:!!e,meta:{wildcardPlaceholder:"paginated"}});return{classes:L(a.data),error:a.error,isInitialLoading:a.isInitialLoading,hasMore:a.hasNextPage,loadMore:async()=>a.fetchNextPage(),isLoadingMore:a.isFetchingNextPage}}const Z=["q"];function ae(){var T,A,B,H;const[e]=z("q"),a=Y({query:e}),r=J({query:e}),t=X({query:e}),m=K({query:e}),[U,F]=p.useState("");p.useEffect(()=>{!a.isInitialLoading&&!a.isLoadingMore&&a.hasMore&&a.loadMore().catch(n=>{I(n)})},[a]),p.useEffect(()=>{!r.isInitialLoading&&!r.isLoadingMore&&r.hasMore&&r.loadMore().catch(n=>{I(n)})},[r]),p.useEffect(()=>{!t.isInitialLoading&&!t.isLoadingMore&&t.hasMore&&t.loadMore().catch(n=>{I(n)})},[t]);const{channels:o}=a,{classes:d}=r,{channels:c}=t,{episodes:l}=m,w=((T=o==null?void 0:o.length)!=null?T:0)>0||((A=d==null?void 0:d.length)!=null?A:0)>0||((B=c==null?void 0:c.length)!=null?B:0)>0||((H=l==null?void 0:l.length)!=null?H:0)>0;p.useEffect(()=>{w&&V(()=>{F(`Search results for: ${e} were loaded.`)},0)},[w,e]);const b=G({title:"Search",url:e?`/search?${new URLSearchParams({q:e})}`:"/search",canonicalQueryParams:Z}),_=a.error||r.error||t.error||m.error;if(_)return i(C,{children:[s(x,{defer:!1,children:s("title",{children:"Error"})}),s(j,{error:_})]});const W=a.isInitialLoading||r.isInitialLoading||t.isInitialLoading||m.isInitialLoading,R=e?`Search results for: "${e}"`:"Search",g={fontSize:"20px",fontWeight:N.weight.medium,margin:"0",padding:"0",lineHeight:"1.28",marginBottom:50,color:E.label};return e?i(C,{children:[i(x,{defer:!1,children:[s("title",{children:R}),b]}),i(v,{as:"main",css:{paddingTop:30,paddingBottom:30},children:[i(h,{as:"h1",css:g,children:["Search: “",e,"â€"]}),o&&o.length>0&&i("div",{css:{marginBottom:60},children:[s(h,{as:"h2",css:g,children:"Channels"}),s(S,{render:()=>o.map(n=>s(f,{role:"listitem",item:n,engagementUI:"followButton"},n.slug))})]}),d&&d.length>0&&i("div",{css:{marginBottom:60},children:[s(h,{as:"h2",css:g,children:"Classes"}),s(S,{render:()=>d.map(n=>s(f,{role:"listitem",item:n},n.slug))})]}),c&&c.length>0&&i("div",{css:{marginBottom:60},children:[s(h,{as:"h2",css:g,children:"Podcasts"}),s(S,{render:()=>c.map(n=>s(f,{role:"listitem",item:n},n.slug))})]}),l&&l.length>0&&i("div",{css:{marginBottom:60},children:[s(h,{as:"h2",css:g,children:"Videos"}),s(S,{render:()=>l.map((n,Q)=>n?s(f,{role:"listitem",item:n,showDate:!0},n.slug):s(D,{index:Q,heightToWidthRatio:$},Q))}),s(O,{hasMore:m.hasMore,loadMore:m.loadMore})]}),!W&&(!o||o.length===0)&&(!c||c.length===0)&&(!l||l.length===0)&&s(h,{role:"alert",as:"h2",css:{fontSize:"14px",fontWeight:N.weight.book,padding:"0",lineHeight:"20px",color:E.label400,marginTop:-20},children:"No results."}),s("div",{role:"status",css:k,children:U})]})]}):i(C,{children:[i(x,{defer:!1,children:[s("title",{children:R}),b]}),i(v,{css:{paddingTop:30,paddingBottom:30},children:[s(h,{as:"h2",css:g,children:"Search"}),s(h,{as:"h2",role:"alert",css:{fontSize:"14px",fontWeight:N.weight.book,padding:"0",lineHeight:"20px",color:E.label400},children:"Please provide a search term."})]})]})}export{ae as default};