(()=>{var e={};e.id=695,e.ids=[695],e.modules={28303:e=>{function t(e){var t=Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}t.keys=()=>[],t.resolve=t,t.id=28303,e.exports=t},10846:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},44870:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},3295:e=>{"use strict";e.exports=require("next/dist/server/app-render/after-task-async-storage.external.js")},29294:e=>{"use strict";e.exports=require("next/dist/server/app-render/work-async-storage.external.js")},63033:e=>{"use strict";e.exports=require("next/dist/server/app-render/work-unit-async-storage.external.js")},12412:e=>{"use strict";e.exports=require("assert")},79428:e=>{"use strict";e.exports=require("buffer")},55511:e=>{"use strict";e.exports=require("crypto")},94735:e=>{"use strict";e.exports=require("events")},29021:e=>{"use strict";e.exports=require("fs")},81630:e=>{"use strict";e.exports=require("http")},73496:e=>{"use strict";e.exports=require("http2")},55591:e=>{"use strict";e.exports=require("https")},91645:e=>{"use strict";e.exports=require("net")},21820:e=>{"use strict";e.exports=require("os")},33873:e=>{"use strict";e.exports=require("path")},19771:e=>{"use strict";e.exports=require("process")},27910:e=>{"use strict";e.exports=require("stream")},41204:e=>{"use strict";e.exports=require("string_decoder")},66136:e=>{"use strict";e.exports=require("timers")},34631:e=>{"use strict";e.exports=require("tls")},83997:e=>{"use strict";e.exports=require("tty")},79551:e=>{"use strict";e.exports=require("url")},28354:e=>{"use strict";e.exports=require("util")},74075:e=>{"use strict";e.exports=require("zlib")},4573:e=>{"use strict";e.exports=require("node:buffer")},8727:(e,t,s)=>{"use strict";s.r(t),s.d(t,{patchFetch:()=>x,routeModule:()=>A,serverHooks:()=>_,workAsyncStorage:()=>E,workUnitAsyncStorage:()=>w});var r={};s.r(r),s.d(r,{DELETE:()=>h,GET:()=>d,POST:()=>p});var n=s(42706),i=s(28203),o=s(45994),a=s(27914),u=s(93292),c=s(39187);let l=process.env.YOUTUBE_API_KEY;async function d(){try{let[e]=await a.A.query(`SELECT
        w.channel_id AS id,
        w.channel_title AS title,
        w.channel_thumbnail AS thumbnail,
        w.channel_description AS description,
        w.publishedAt,
        w.added_at AS addedAt,
        s.viewCount, s.subscriberCount, s.videoCount,
        s_2d.viewCount AS viewCount2dAgo,
        s_2d.subscriberCount AS subscriberCount2dAgo,
        s_7d.viewCount AS viewCount7dAgo,
        s_7d.subscriberCount AS subscriberCount7dAgo
      FROM watchlist w
      LEFT JOIN channel_stats s ON w.channel_id = s.channel_id
        AND s.date = (SELECT MAX(date) FROM channel_stats WHERE channel_id = w.channel_id)
      LEFT JOIN channel_stats s_2d ON w.channel_id = s_2d.channel_id
        AND s_2d.date = DATE_SUB(CURDATE(), INTERVAL 2 DAY)
      LEFT JOIN channel_stats s_7d ON w.channel_id = s_7d.channel_id
        AND s_7d.date = DATE_SUB(CURDATE(), INTERVAL 7 DAY)
      ORDER BY w.added_at DESC`);return c.NextResponse.json({watchlist:e})}catch(e){return console.error("Watchlist GET error:",e.message),c.NextResponse.json({error:e.message},{status:500})}}async function p(e){try{let{id:t,title:s,thumbnail:r,description:n,publishedAt:i,viewCount:o,subscriberCount:d,videoCount:p}=await e.json();if(!t||!s)return c.NextResponse.json({error:"Missing channel id or title"},{status:400});await a.A.query(`INSERT INTO channels (id, title, description, customUrl, publishedAt, thumbnailUrl, country)
       VALUES (?, ?, ?, '', ?, ?, '')
       ON DUPLICATE KEY UPDATE title=VALUES(title), description=VALUES(description), thumbnailUrl=VALUES(thumbnailUrl)`,[t,s,n||"",i?new Date(i):new Date,r||""]);let h=new Date().toISOString().split("T")[0];await a.A.query(`INSERT INTO channel_stats (channel_id, date, viewCount, subscriberCount, videoCount)
       VALUES (?, ?, ?, ?, ?)
       ON DUPLICATE KEY UPDATE viewCount=VALUES(viewCount), subscriberCount=VALUES(subscriberCount), videoCount=VALUES(videoCount)`,[t,h,parseInt(o||"0",10),parseInt(d||"0",10),parseInt(p||"0",10)]),await a.A.query(`INSERT INTO watchlist (channel_id, channel_title, channel_thumbnail, channel_description, publishedAt)
       VALUES (?, ?, ?, ?, ?)
       ON DUPLICATE KEY UPDATE channel_title=VALUES(channel_title), channel_thumbnail=VALUES(channel_thumbnail)`,[t,s,r||"",n||"",i?new Date(i):new Date]);try{let e=await u.A.get("https://www.googleapis.com/youtube/v3/channels",{params:{part:"statistics",id:t,key:l}}),s=e.data.items?.[0]?.statistics;s&&await a.A.query(`INSERT INTO channel_stats (channel_id, date, viewCount, subscriberCount, videoCount)
           VALUES (?, ?, ?, ?, ?)
           ON DUPLICATE KEY UPDATE viewCount=VALUES(viewCount), subscriberCount=VALUES(subscriberCount), videoCount=VALUES(videoCount)`,[t,h,parseInt(s.viewCount||"0",10),parseInt(s.subscriberCount||"0",10),parseInt(s.videoCount||"0",10)])}catch{}return c.NextResponse.json({success:!0})}catch(e){return console.error("Watchlist POST error:",e.message),c.NextResponse.json({error:e.message},{status:500})}}async function h(e){try{let{searchParams:t}=new URL(e.url),s=t.get("id");if(!s)return c.NextResponse.json({error:"Missing id"},{status:400});return await a.A.query("DELETE FROM watchlist WHERE channel_id = ?",[s]),c.NextResponse.json({success:!0})}catch(e){return console.error("Watchlist DELETE error:",e.message),c.NextResponse.json({error:e.message},{status:500})}}let A=new n.AppRouteRouteModule({definition:{kind:i.RouteKind.APP_ROUTE,page:"/api/watchlist/route",pathname:"/api/watchlist",filename:"route",bundlePath:"app/api/watchlist/route"},resolvedPagePath:"C:\\Users\\HP\\Desktop\\youtubenichefinder\\src\\app\\api\\watchlist\\route.ts",nextConfigOutput:"",userland:r}),{workAsyncStorage:E,workUnitAsyncStorage:w,serverHooks:_}=A;function x(){return(0,o.patchFetch)({workAsyncStorage:E,workUnitAsyncStorage:w})}},96487:()=>{},78335:()=>{},27914:(e,t,s)=>{"use strict";s.d(t,{A:()=>r});let r=s(60820).createPool({host:process.env.DB_HOST||"localhost",user:process.env.DB_USER||"root",password:process.env.DB_PASSWORD||"",database:process.env.DB_NAME||"youtube",waitForConnections:!0,connectionLimit:10,maxIdle:10,idleTimeout:6e4,queueLimit:0,enableKeepAlive:!0,keepAliveInitialDelay:0})}};var t=require("../../../webpack-runtime.js");t.C(e);var s=e=>t(t.s=e),r=t.X(0,[638,452,820,292],()=>s(8727));module.exports=r})();