(()=>{var e={};e.id=202,e.ids=[202],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")},63761:(e,t,r)=>{"use strict";r.r(t),r.d(t,{patchFetch:()=>A,routeModule:()=>x,serverHooks:()=>v,workAsyncStorage:()=>g,workUnitAsyncStorage:()=>b});var s={};r.r(s),r.d(s,{GET:()=>h});var i=r(42706),o=r(28203),n=r(45994),u=r(93292),a=r(27914),c=r(39187);let p=process.env.YOUTUBE_API_KEY,d="https://www.googleapis.com/youtube/v3",l=[/amzn\.to/i,/amazon\.com/i,/bit\.ly/i,/goo\.gl/i,/tinyurl/i,/patreon\.com/i,/merch/i,/shop\./i,/discord\.gg/i,/affiliate/i,/sponsored/i,/promo/i,/code:/i,/discount/i,/link in bio/i,/click here/i,/buy now/i,/get \d+% off/i,/use code/i];async function h(e){let{searchParams:t}=new URL(e.url),r=t.get("q");if(!r)return c.NextResponse.json({error:'Query parameter "q" is required.'},{status:400});try{let e=(await u.A.get(`${d}/search`,{params:{part:"snippet",q:r,type:"channel",maxResults:50,key:p}})).data.items;if(!e||0===e.length)return c.NextResponse.json({channels:[],opportunityZone:null});let t=e.map(e=>e.id.channelId).join(","),s=(await u.A.get(`${d}/channels`,{params:{part:"snippet,statistics",id:t,key:p}})).data.items||[],i=t.split(","),o=i.map(()=>"?").join(","),[n]=await a.A.query(`SELECT
        w.channel_id AS id,
        s.viewCount AS viewCount2dAgo, s.subscriberCount AS subscriberCount2dAgo,
        s7.viewCount AS viewCount7dAgo, s7.subscriberCount AS subscriberCount7dAgo
       FROM watchlist w
       LEFT JOIN channel_stats s ON w.channel_id = s.channel_id AND s.date = DATE_SUB(CURDATE(), INTERVAL 2 DAY)
       LEFT JOIN channel_stats s7 ON w.channel_id = s7.channel_id AND s7.date = DATE_SUB(CURDATE(), INTERVAL 7 DAY)
       WHERE w.channel_id IN (${o})`,i),h={};for(let e of n)h[e.id]=e;let x=s.map(e=>{let t=parseInt(e.statistics.viewCount||"0",10),r=parseInt(e.statistics.subscriberCount||"0",10),s=parseInt(e.statistics.videoCount||"0",10),i=h[e.id],o=r>0?parseFloat((t/r).toFixed(1)):0,n=s>0?t/s:0,u=(!(s>=5)||!(n<t/s*.1))&&s>=10&&n<.05*t/s,a=i?.subscriberCount7dAgo||0,c=i?.viewCount7dAgo||0,p=a>0?(r-a)/a*100:0,d=c>0?(t-c)/c*100:0,x=parseFloat((.6*p+.4*d).toFixed(2)),g=function(e,t,r){let s=e>=1e3;return s&&t>=24e4?{isMonetized:!0,confidence:"High",reason:`${(e/1e3).toFixed(1)}K subs + high watchtime`}:s&&(r>0?t/r:0)>1e3?{isMonetized:!0,confidence:"Medium",reason:"Meets sub threshold, moderate views"}:{isMonetized:!1,confidence:"Low",reason:"Below YPP thresholds"}}(r,t,s),b=function(e){let t=[];for(let r of l){let s=e.match(r);s&&t.push(s[0])}return{hasSponsor:t.length>0,signals:t}}(e.snippet.description||"");return{id:e.id,title:e.snippet.title,description:e.snippet.description||"",thumbnail:e.snippet.thumbnails?.default?.url||"",publishedAt:e.snippet.publishedAt,viewCount:e.statistics.viewCount||"0",subscriberCount:e.statistics.subscriberCount||"0",videoCount:e.statistics.videoCount||"0",multiplier:o,engagementProxy:parseFloat((n/Math.max(r,1)*100).toFixed(2)),monetization:g,sponsorship:b,isOneHitWonder:u,velocityScore:isNaN(x)?0:x,viewCount2dAgo:i?.viewCount2dAgo||null,subscriberCount2dAgo:i?.subscriberCount2dAgo||null,viewCount7dAgo:i?.viewCount7dAgo||null,subscriberCount7dAgo:i?.subscriberCount7dAgo||null}}),g=x.slice(0,10),b=g.reduce((e,t)=>e+parseInt(t.viewCount,10),0)/g.length,v=g.reduce((e,t)=>e+parseInt(t.subscriberCount,10),0)/g.length,A=v>0?b/v:0,w={isOpportunity:A>50,demandRatio:parseFloat(A.toFixed(1)),avgViews:Math.round(b),avgSubs:Math.round(v),channelCount:x.length};return x.sort((e,t)=>parseInt(t.viewCount,10)-parseInt(e.viewCount,10)),c.NextResponse.json({channels:x,opportunityZone:w})}catch(e){return console.error("Search API error:",e?.response?.data||e.message),c.NextResponse.json({error:"Internal server error while fetching channels."},{status:500})}}let x=new i.AppRouteRouteModule({definition:{kind:o.RouteKind.APP_ROUTE,page:"/api/search/route",pathname:"/api/search",filename:"route",bundlePath:"app/api/search/route"},resolvedPagePath:"C:\\Users\\HP\\Desktop\\youtubenichefinder\\src\\app\\api\\search\\route.ts",nextConfigOutput:"",userland:s}),{workAsyncStorage:g,workUnitAsyncStorage:b,serverHooks:v}=x;function A(){return(0,n.patchFetch)({workAsyncStorage:g,workUnitAsyncStorage:b})}},96487:()=>{},78335:()=>{},27914:(e,t,r)=>{"use strict";r.d(t,{A:()=>s});let s=r(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 r=e=>t(t.s=e),s=t.X(0,[638,452,820,292],()=>r(63761));module.exports=s})();