(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[185],{52787:function(e,t,o){Promise.resolve().then(o.t.bind(o,58877,23)),Promise.resolve().then(o.bind(o,39239)),Promise.resolve().then(o.bind(o,96879)),Promise.resolve().then(o.bind(o,33717)),Promise.resolve().then(o.bind(o,32862)),Promise.resolve().then(o.bind(o,96669)),Promise.resolve().then(o.bind(o,70088)),Promise.resolve().then(o.bind(o,18645)),Promise.resolve().then(o.bind(o,28680)),Promise.resolve().then(o.bind(o,8265)),Promise.resolve().then(o.bind(o,97495)),Promise.resolve().then(o.bind(o,30684)),Promise.resolve().then(o.bind(o,29937)),Promise.resolve().then(o.bind(o,97590)),Promise.resolve().then(o.bind(o,38822)),Promise.resolve().then(o.bind(o,62289)),Promise.resolve().then(o.bind(o,91423)),Promise.resolve().then(o.bind(o,24516)),Promise.resolve().then(o.bind(o,16769)),Promise.resolve().then(o.bind(o,31751)),Promise.resolve().then(o.bind(o,21104)),Promise.resolve().then(o.bind(o,8537)),Promise.resolve().then(o.bind(o,51930)),Promise.resolve().then(o.bind(o,72214)),Promise.resolve().then(o.bind(o,58648)),Promise.resolve().then(o.bind(o,71675)),Promise.resolve().then(o.bind(o,26375)),Promise.resolve().then(o.bind(o,2357)),Promise.resolve().then(o.bind(o,29958)),Promise.resolve().then(o.bind(o,79309)),Promise.resolve().then(o.bind(o,37109)),Promise.resolve().then(o.bind(o,36260)),Promise.resolve().then(o.bind(o,45660)),Promise.resolve().then(o.bind(o,48668)),Promise.resolve().then(o.bind(o,68976)),Promise.resolve().then(o.bind(o,47797)),Promise.resolve().then(o.bind(o,84789)),Promise.resolve().then(o.bind(o,46001)),Promise.resolve().then(o.bind(o,79889)),Promise.resolve().then(o.bind(o,90720)),Promise.resolve().then(o.bind(o,115)),Promise.resolve().then(o.bind(o,65336)),Promise.resolve().then(o.bind(o,57034)),Promise.resolve().then(o.bind(o,96592))},39239:function(e,t,o){"use strict";o.d(t,{YoutubeProvider:function(){return a},h:function(){return l}});var s=o(57437),r=o(2265),i=o(16463),n=o(38472);let l=(0,r.createContext)({loading:!1,setLoading:()=>{},searchResult:[],selectedType:"",setSelectedType:()=>{},selectedCategory:{id:0,name:"New"},setSelectedCategory:()=>{},mobileMenu:!0,setMobileMenu:()=>{},subcategories:{},setSubcategories:()=>{},addPlaylist:!1,setAddPlaylist:()=>{},playlist:null,setPlaylist:()=>{},token:"",setToken:()=>{},userData:{},setUserData:()=>{}}),a=e=>{let{children:t}=e,[o,a]=(0,r.useState)(!1),[d,c]=(0,r.useState)([]),[m,h]=(0,r.useState)({name:"New"}),[u,b]=(0,r.useState)(""),[v,P]=(0,r.useState)(!1),[y,g]=(0,r.useState)({}),[f,p]=(0,r.useState)(!1),[S,I]=(0,r.useState)(null),k=(0,i.usePathname)(),[w,N]=(0,r.useState)(""),[E,T]=(0,r.useState)({});return(0,r.useEffect)(()=>{(async()=>{try{let e="/api/categories";S&&(e="/api/playlists/".concat(S.id,"/categories"));let t=await fetch(e),o=await t.json();g(o.categories);let s=k.replace(/^\/|\/$/g,"").split("/"),r=o.categories[s[0]];if(s.length&&r){b(s[0]);let e=r.findIndex(e=>e.category_id===parseInt(s[1]));h({id:r[e].category_id,name:r[e].category})}}catch(e){console.error("Error fetching subcategories:",e)}})()},[S]),(0,r.useEffect)(()=>{E.id||(async()=>{let e=localStorage.getItem("userData"),t=localStorage.getItem("userToken");if(e&&t===w){T(JSON.parse(e));return}if(w)try{let e=await fetch("/api/verifytoken",{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(w)}});if(e.ok){let t=await e.json();T(t),localStorage.setItem("userData",JSON.stringify(t)),localStorage.setItem("userToken",w)}else console.error("Failed to fetch user data"),localStorage.removeItem("userData"),localStorage.removeItem("userToken")}catch(e){console.error("Error fetching user data:",e),localStorage.removeItem("userData"),localStorage.removeItem("userToken")}})()},[w,E.id]),(0,r.useEffect)(()=>{let e=localStorage.getItem("userToken")||function(e){if("undefined"==typeof document)return"";let t=document.cookie.split("; ").find(t=>t.startsWith("".concat(encodeURIComponent(e),"=")));return t?decodeURIComponent(t.split("=").slice(1).join("=")):""}("token");e&&N(e)},[]),(0,r.useEffect)(()=>{let e=async()=>{let e=window.location.href.match(/playlists\/(\d+)/);if(e&&e[1]){let o=e[1];try{var t;let e=w?await n.Z.get("/api/playlists/".concat(o,"/info"),{headers:{Authorization:"Bearer ".concat(w)}}):await n.Z.get("/api/public-playlists?id=".concat(o));if(I(e.data.playlist),localStorage.setItem("selectedPlaylistId","".concat(e.data.playlist.id)),(null===(t=e.data.playlist)||void 0===t?void 0:t.source)==="web"&&e.data.playlist.editKey){let t=JSON.parse(localStorage.getItem("publicPlaylistIds")||"[]");localStorage.setItem("publicPlaylistIds",JSON.stringify(Array.from(new Set([...t,e.data.playlist.id]))));let o=JSON.parse(localStorage.getItem("publicPlaylistKeys")||"{}");localStorage.setItem("publicPlaylistKeys",JSON.stringify({...o,[e.data.playlist.id]:e.data.playlist.editKey}))}}catch(e){console.error("Error fetching playlist:",e)}}};S||e()},[w]),(0,s.jsx)(l.Provider,{value:{loading:o,setLoading:a,searchResult:d,selectedType:u,setSelectedType:b,selectedCategory:m,setSelectedCategory:h,mobileMenu:v,setMobileMenu:P,subcategories:y,setSubcategories:g,addPlaylist:f,setAddPlaylist:p,playlist:S,setPlaylist:I,token:w,setToken:N,userData:E,setUserData:T},children:t})}},58877:function(){}},function(e){e.O(0,[404,429,947,592,533,714,754,971,23,744],function(){return e(e.s=52787)}),_N_E=e.O()}]);