1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1274],{19240:(e,t,r)=>{r.d(t,{A:()=>o});var i=r(11498),a=r(41142),s=r(66609);let o=(0,i.vt)((e,t)=>({watchlistItems:new Map,loadedUserId:null,isLoading:!1,fetchWatchlist:async t=>{e({isLoading:!0});try{let{data:r,error:i}=await a.N.from("watchlist").select("*").eq("user_id",t).order("added_at",{ascending:!1});if(i)throw i;let s=new Map(r.map(e=>[e.media_id,e]));e({watchlistItems:s,loadedUserId:t})}catch(e){s.oR.error("Error fetching watchlist"),console.error("Error fetching watchlist:",e)}finally{e({isLoading:!1})}},clearWatchlist:()=>{e({watchlistItems:new Map,loadedUserId:null,isLoading:!1})},addToWatchlist:async(r,i)=>{let o=i.id.toString(),n={media_id:o,user_id:r,media_type:i.type,title:i.title,image:i.image,added_at:new Date().toISOString(),type:i.type,release_date:"release_date"in i?i.release_date:void 0};try{let{watchlistItems:r}=t(),i=new Map(r);i.set(o,n),e({watchlistItems:i});let{error:l}=await a.N.from("watchlist").insert(n);if(l)throw i.delete(o),e({watchlistItems:i}),l;s.oR.success("Added to watchlist")}catch(e){s.oR.error("Error adding to watchlist"),console.error("Error adding to watchlist:",e)}},removeFromWatchlist:async(r,i)=>{try{let{watchlistItems:o}=t(),n=new Map(o);if(!n.has(i))return;n.delete(i),e({watchlistItems:new Map(n)});let{error:l}=await a.N.from("watchlist").delete().eq("media_id",i).eq("user_id",r);if(l)throw e({watchlistItems:new Map(o)}),l;s.oR.success("Removed from watchlist")}catch(e){s.oR.error("Error removing from watchlist"),console.error("Error removing from watchlist:",e)}},isInWatchlist:e=>{let{watchlistItems:r}=t();return r.has(e)}}))},19783:(e,t,r)=>{r.d(t,{t:()=>l});var i=r(12115),a=r(84269),s=r(66609),o=r(41142),n=r(60927);let l=e=>{let{subscribe:t=!0,fetch:r=!0}=e||{},{user:l}=(0,a.A)(),[c,u]=(0,i.useState)([]),d=(0,i.useRef)(!1);(0,i.useEffect)(()=>{if(!r||!l||d.current)return;d.current=!0;let e=async()=>{let{data:e,error:t}=await o.N.from("watch_history").select("*").eq("user_id",l.id).order("last_watched_at",{ascending:!1});t?(s.oR.error("Error fetching watch history"),console.error("Error fetching watch history:",t)):u(e)};e();let i=null;if(t){let t=Math.random().toString(36).substring(2,9);i=o.N.channel(`watch-history-${t}`).on("postgres_changes",{event:"*",schema:"public",table:"watch_history"},t=>{("UPDATE"!==t.eventType||t.new!==t.old)&&e()}).subscribe()}return()=>{d.current=!1,i&&i.unsubscribe()}},[l,t,r]);let h=(0,i.useCallback)(async e=>{if(l)try{let t={id:e.id.replace(/\//g,"-"),user_id:l.id,current_time:e.current_time,duration:e.duration,image:e.image,last_watched_at:e.last_watched_at,media_type:e.media_type,release_date:e.release_date,runtime:e.runtime,title:e.title,type:e.type,url:e.url},r=e.media_type===n.f.TV?{episode_number:e.episode_number,season_number:e.season_number}:{episode_number:null,season_number:null},i={...t,...r},{data:a,error:s}=await o.N.from("watch_history").select("id").eq("id",i.id).eq("user_id",l.id).maybeSingle();if(s)throw s;if(a){let{error:e}=await o.N.from("watch_history").update(i).eq("id",i.id).eq("user_id",l.id);if(e)throw e}else{let{error:e}=await o.N.from("watch_history").insert(i);if(e)throw e}}catch(e){s.oR.error("Error updating watch history"),console.error("Error adding/updating document: ",e)}},[l]),m=(0,i.useCallback)(async e=>{if(l)try{let{error:t}=await o.N.from("watch_history").delete().eq("id",e.replace(/\//g,"-")).eq("user_id",l.id);if(t)throw t}catch(e){s.oR.error("Error removing watch history"),console.error("Error removing document: ",e)}},[l]),w=(0,i.useCallback)(async e=>{if(!l)return null;try{let{data:t,error:r}=await o.N.from("watch_history").select("*").eq("id",e.replace(/\//g,"-")).eq("user_id",l.id).maybeSingle();if(r)throw r;return t}catch(e){return s.oR.error("Error fetching watch history"),console.error("Error getting document: ",e),null}},[l]);return{supabaseHistories:c,addOrUpdateSupabaseHistory:h,removeSupabaseHistory:m,clearAllSupabaseHistory:(0,i.useCallback)(async()=>{if(!l)return!1;try{let{error:e}=await o.N.from("watch_history").delete().eq("user_id",l.id);if(e)throw e;return u([]),!0}catch(e){return s.oR.error("Error clearing watch history from server"),console.error("Error clearing all history from Supabase: ",e),!1}},[l]),getSupabaseHistory:w}}},41142:(e,t,r)=>{r.d(t,{N:()=>s});var i=r(8171);let a=null,s=new Proxy({},{get(e,t,r){let s=(()=>
1{if(a)return a;let e="https://lcyfnxvpnnhubwzcvuno.supabase.co",t="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImxjeWZueHZwbm5odWJ3emN2dW5vIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MjkxODYzMjAsImV4cCI6MjA0NDc2MjMyMH0.m1nD51Knz2TlgQDb5dEAe3gHLCJZ8k9wH-mRVzzYqAc";return e&&t?a=(0,i.UU)(e,t):(0,i.UU)("https://placeholder.supabase.co","placeholder-anon-key",{auth:{persistSession:!1,autoRefreshToken:!1}})})(),o=Reflect.get(s,t,r);return"function"==typeof o?o.bind(s):o}})},84269:(e,t,r)=>{r.d(t,{A:()=>c,AuthProvider:()=>l});var i=r(95155),a=r(12115),s=r(41142),o=r(19240);let n=(0,a.createContext)(null);n.displayName="AuthContext";let l=({children:e})=>{let[t,r]=(0,a.useState)(null),[l,c]=(0,a.useState)(!0),[u,d]=(0,a.useState)(!1),[h,m]=(0,a.useState)(!1),{fetchWatchlist:w,clearWatchlist:f,loadedUserId:y,isLoading:_}=(0,o.A)(),p=(0,a.useRef)({userId:null,at:0}),g=(0,a.useRef)(null);g.current=async(e,t=!1)=>{try{if(!e){d(!1),m(!1);return}let r=Date.now(),i=p.current.userId===e&&r-p.current.at<6e4;if(!t&&i)return;p.current={userId:e,at:r};let a=await fetch("/api/auth/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({userId:e})});if(a.ok){let e=await a.json();d(e.isPremium),m(e.isAdmin)}else d(!1),m(!1)}catch(e){d(!1),m(!1)}};let b=(0,a.useCallback)(async()=>{t?.id&&g.current&&await g.current(t.id,!0)},[t?.id]);(0,a.useEffect)(()=>{(async()=>{let{data:e}=await s.N.auth.getSession(),t=e.session;t?.user?(r(e=>e?.id===t.user.id?e:t.user),await g.current?.(t.user.id,!0)):(r(e=>null===e?e:null),d(!1),m(!1)),c(!1)})();let{data:e}=s.N.auth.onAuthStateChange(async(e,t)=>{t?.user?(r(e=>e?.id===t.user.id?e:t.user),"USER_UPDATED"===e?await g.current?.(t.user.id,!0):"SIGNED_IN"===e&&await g.current?.(t.user.id)):(r(e=>null===e?e:null),d(!1),m(!1))});return()=>{e.subscription.unsubscribe()}},[]),(0,a.useEffect)(()=>{if(!l){if(!t?.id){(null!==y||_)&&f();return}y===t.id||_||w(t.id)}},[t?.id,l,y,_,w,f]);let v=(0,a.useMemo)(()=>({user:t,loading:l,isPremium:u,isAdmin:h}),[t,l,u,h]),I=(0,a.useMemo)(()=>({refreshUserStatus:b}),[b]),E=(0,a.useMemo)(()=>({...v,...I}),[v,I]);return(0,i.jsx)(n.Provider,{value:E,children:e})},c=()=>{let e=(0,a.useContext)(n);if(null===e)throw Error("useAuth must be used within an AuthProvider");return e}},94496:(e,t,r)=>{r.d(t,{WatchHistoryStoreProvider:()=>d,M:()=>h});var i=r(95155),a=r(12115),s=r(11498),o=r(60927),n=r(35867),l=r(31692);let c={histories:[]},u=(0,a.createContext)(void 0),d=({children:e})=>{let t=(0,a.useRef)(null);return t.current||(t.current=((e=c)=>(0,n.y)()((0,l.Zr)((t,r)=>({...e,addOrUpdateHistory:(e,r,i,a,s,n)=>t(t=>{let l=Date.now(),c=t.histories.findIndex(t=>t.id===e.id&&t.media_type===a),u=a===o.f.Movie?{...e,last_watched_at:l,runtime:i,current_time:r,media_type:o.f.Movie}:{...e,last_watched_at:l,runtime:i,current_time:r,media_type:o.f.TV,season_number:Number(s),episode_number:Number(n)};if(!(c>-1))return{histories:[u,...t.histories.slice(0,99)]};{let e=[...t.histories];return e[c]=u,e.unshift(e.splice(c,1)[0]),{histories:e}}}),getHistory:e=>r().histories.find(t=>t.id===e),removeHistory:e=>t(t=>({histories:t.histories.filter(t=>t.id!==e)})),clearHistories:()=>t({histories:[]})}),{name:"watch-history-storage",storage:(0,l.KU)(()=>localStorage)})))({histories:[]})),(0,i.jsx)(u.Provider,{value:t.current,children:e})},h=e=>{let t=(0,a.useContext)(u);if(!t)throw Error("useWatchHistoryStore must be used within WatchHistoryStoreProvider");return(0,s.Pj)(t,e)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.