(()=>{var e={};e.id=5694,e.ids=[5694],e.modules={3295:e=>{"use strict";e.exports=require("next/dist/server/app-render/after-task-async-storage.external.js")},10846:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},27910:e=>{"use strict";e.exports=require("stream")},28354:e=>{"use strict";e.exports=require("util")},29294:e=>{"use strict";e.exports=require("next/dist/server/app-render/work-async-storage.external.js")},44870:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},54728:(e,t,r)=>{"use strict";r.r(t),r.d(t,{patchFetch:()=>x,routeModule:()=>m,serverHooks:()=>h,workAsyncStorage:()=>w,workUnitAsyncStorage:()=>f});var a={};r.r(a),r.d(a,{GET:()=>y});var s=r(96559),o=r(48088),n=r(37719),i=r(32190),c=r(96330),d=r(43205),p=r.n(d);let u=new c.PrismaClient,l=process.env.JWT_SECRET||"your-secret-key";async function y(e){try{let t,r=e.headers.get("authorization");if(!r||!r.startsWith("Bearer "))return i.NextResponse.json({error:"Unauthorized"},{status:401});let a=r.substring(7);try{t=p().verify(a,l)}catch(e){return i.NextResponse.json({error:"Invalid token"},{status:401})}if(!t||!t.userId)return i.NextResponse.json({error:"Invalid token"},{status:401});let{searchParams:s}=new URL(e.url),o=s.get("companyMarketplaceId"),n=await u.user.findUnique({where:{id:t.userId},include:{company:!0}});if(!n||!n.company)return i.NextResponse.json({error:"User or company not found"},{status:404});let c=await u.product.count({where:{companyId:n.companyId}}),d=0;d=o?await u.productMarketplace.count({where:{companyMarketplaceId:parseInt(o),isActive:!0,product:{companyId:n.companyId}}}):await u.productMarketplace.count({where:{isActive:!0,product:{companyId:n.companyId}}});let y=0;if(o)for(let e of(await u.productMarketplace.findMany({where:{companyMarketplaceId:parseInt(o),isActive:!0,product:{companyId:n.companyId}},select:{id:!0}})))await u.productAnalysis.findFirst({where:{productMarketplaceId:e.id,buyboxRank:1},orderBy:{createdAt:"desc"}})&&y++;else for(let e of(await u.productMarketplace.findMany({where:{isActive:!0,product:{companyId:n.companyId}},select:{id:!0}})))await u.productAnalysis.findFirst({where:{productMarketplaceId:e.id,buyboxRank:1},orderBy:{createdAt:"desc"}})&&y++;let m=new Date,w=new Date(m.getTime()-864e5),f=new Date(m.getTime()-6048e5),h=async(e,t)=>{let r=0;if(t)for(let a of(await u.productMarketplace.findMany({where:{companyMarketplaceId:parseInt(t),isActive:!0,product:{companyId:n.companyId}},select:{id:!0}})))await u.productAnalysis.findFirst({where:{productMarketplaceId:a.id,buyboxRank:1,createdAt:{lte:e}},orderBy:{createdAt:"desc"}})&&r++;else for(let t of(await u.productMarketplace.findMany({where:{isActive:!0,product:{companyId:n.companyId}},select:{id:!0}})))await u.productAnalysis.findFirst({where:{productMarketplaceId:t.id,buyboxRank:1,createdAt:{lte:e}},orderBy:{createdAt:"desc"}})&&r++;return r},x=await h(w,o),I=await h(f,o);return i.NextResponse.json({totalProducts:c,activeProductsInMarketplace:d,buyboxFirstRankCount:y,buyboxComparison:{current:y,oneDayAgo:x,sevenDaysAgo:I},companyMarketplaceId:o?parseInt(o):null})}catch(e){return console.error("Error fetching dashboard stats:",e),i.NextResponse.json({error:"Failed to fetch dashboard stats"},{status:500})}finally{await u.$disconnect()}}let m=new s.AppRouteRouteModule({definition:{kind:o.RouteKind.APP_ROUTE,page:"/api/dashboard/stats/route",pathname:"/api/dashboard/stats",filename:"route",bundlePath:"app/api/dashboard/stats/route"},resolvedPagePath:"/Users/mustafaseyhan/Project/PazarAnalist/src/app/api/dashboard/stats/route.ts",nextConfigOutput:"standalone",userland:a}),{workAsyncStorage:w,workUnitAsyncStorage:f,serverHooks:h}=m;function x(){return(0,n.patchFetch)({workAsyncStorage:w,workUnitAsyncStorage:f})}},55511:e=>{"use strict";e.exports=require("crypto")},63033:e=>{"use strict";e.exports=require("next/dist/server/app-render/work-unit-async-storage.external.js")},78335:()=>{},79428:e=>{"use strict";e.exports=require("buffer")},96330:e=>{"use strict";e.exports=require("@prisma/client")},96487:()=>{}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),a=t.X(0,[4447,580,3205],()=>r(54728));module.exports=a})();