"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[142],{68142:function(e,t,a){a.d(t,{Z:function(){return U}});var s=a(57437),r=a(2265),l=a(16463),n=a(87138),c=a(24630),i=a(39239),o=a(27227),d=a(91652),h=a(7847),x=a(35769),m=a(2428),f=a(84447),u=a(39303),g=a(50731),p=a(69824),b=()=>{var e;let{playlist:t,selectedType:a,token:n}=(0,r.useContext)(i.h),c=(0,l.usePathname)(),o=(0,l.useRouter)(),[d,h]=(0,r.useState)(""),[x,m]=(0,r.useState)([]),[f,b]=(0,r.useState)(""),[k,v]=(0,r.useState)(!1),[w,y]=(0,r.useState)(-1),j=(0,r.useRef)(null),N=(0,r.useRef)(null),C=async e=>{let s;b(e),y(-1),N.current&&N.current.abort(),N.current=new AbortController;let r=N.current.signal;try{if(t){let l={"Content-Type":"application/json"};n&&(l.Authorization="Bearer ".concat(n)),s=await fetch("/api/playlists/".concat(t.id,"/streams?search=").concat(encodeURIComponent(e),"&type=").concat(a||"movie"),{method:"GET",headers:l,signal:r})}else s=await fetch("/api/videos?search=".concat(e),{signal:r});if(!s.ok)throw Error("Failed to fetch: ".concat(s.status));let l=await s.json();m(l.streams)}catch(e){"AbortError"===e.name?console.log("Fetch aborted"):console.error("Fetch error:",e)}},S=(e,s)=>{let r=new URL(window.location.href);return(null==s?void 0:s.trim())?r.searchParams.set("searchQuery",s.trim()):r.searchParams.delete("searchQuery"),t?(r.pathname="/playlists/".concat(t.id,"/").concat((0,u.lV)(t.name)),(e||a)&&r.searchParams.set("type",e||a)):(e?r.searchParams.set("type",e):r.searchParams.delete("type"),"/"!==r.pathname&&(r.pathname="/")),r.toString()},P=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1?arguments[1]:void 0;o.push(S(e,t))},_=e=>{((null==e?void 0:e.key)==="Enter"||"searchButton"===e)&&P(null,f)},L=e=>{b(e),h(e),P(null,e)};return(0,r.useEffect)(()=>{new URL(window.location.href).searchParams.get("searchQuery")||h("")},[c]),(0,r.useEffect)(()=>{j.current&&j.current.scrollIntoView({block:"end"})},[w]),(0,s.jsxs)("div",{className:"flex flex-col relative z-50",children:[(0,s.jsxs)("div",{className:"group flex items-center my-1 w-auto",children:[(0,s.jsxs)("div",{tabIndex:1,onKeyDown:e=>{let{key:t}=e;"ArrowDown"===t&&x.length>0&&""!==f&&y((w+1)%x.length),"ArrowUp"===t&&x.length>0&&""!==f&&y((w+x.length-1)%x.length),"Enter"===t&&""!==f&&w>=0&&w