"use strict";(()=>{var e={};e.id=7186,e.ids=[7186],e.modules={53524:e=>{e.exports=require("@prisma/client")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},8825:(e,r,t)=>{t.r(r),t.d(r,{headerHooks:()=>f,originalPathname:()=>w,requestAsyncStorage:()=>p,routeModule:()=>c,serverHooks:()=>v,staticGenerationAsyncStorage:()=>m,staticGenerationBailout:()=>P});var i={};t.r(i),t.d(i,{GET:()=>u,POST:()=>d}),t(95655);var a=t(83323),s=t(54647),o=t(66886),n=t(30953);async function d(e){try{let r=await e.json(),{email:t,otp:i,productId:a,rating:s,title:d,content:u,image:l}=r;if(!t||!i||!a||!s||!u)return o.Z.json({error:"Missing required fields"},{status:400});let c=await n._.verificationToken.findFirst({where:{identifier:t,token:i,expires:{gt:new Date}}});if(!c)return o.Z.json({error:"Invalid or expired OTP"},{status:400});let p=await n._.order.findFirst({where:{OR:[{email:t},{user:{email:t}}],items:{some:{productId:a}}},select:{id:!0,userId:!0,email:!0}});if(!p)return o.Z.json({error:"Order not found for verification"},{status:400});let m=await n._.review.create({data:{rating:parseInt(s),title:d,content:u,image:l,productId:a,email:t,userId:p.userId,orderId:p.id,status:"PENDING",verified:!0}});return await n._.verificationToken.delete({where:{identifier_token:{identifier:t,token:i}}}),o.Z.json({message:"Review submitted successfully and is pending approval.",reviewId:m.id})}catch(e){return console.error("Error submitting review:",e),o.Z.json({error:"Internal Server Error"},{status:500})}}async function u(e){let{searchParams:r}=new URL(e.url),t=r.get("productId");if(!t)return o.Z.json({error:"Product ID is required"},{status:400});try{let e=await n._.review.findMany({where:{productId:t,status:"APPROVED"},orderBy:{createdAt:"desc"},select:{id:!0,rating:!0,title:!0,content:!0,image:!0,createdAt:!0,user:{select:{name:!0}},email:!0,order:{select:{customerName:!0}},verified:!0}}),r=e.map(e=>({...e,reviewerName:e.order?.customerName||e.user?.name||e.email.split("@")[0]||"Verified Customer",email:void 0,order:void 0}));return o.Z.json(r)}catch(e){return console.error("Error fetching reviews:",e),o.Z.json({error:"Internal Server Error"},{status:500})}}let l=a.AppRouteRouteModule,c=new l({definition:{kind:s.x.APP_ROUTE,page:"/api/reviews/route",pathname:"/api/reviews",filename:"route",bundlePath:"app/api/reviews/route"},resolvedPagePath:".\\app\\api\\reviews\\route.ts",nextConfigOutput:"standalone",userland:i}),{requestAsyncStorage:p,staticGenerationAsyncStorage:m,serverHooks:v,headerHooks:f,staticGenerationBailout:P}=c,w="/api/reviews/route"},30953:(e,r,t)=>{t.d(r,{_:()=>s});var i=t(53524);let a=globalThis,s=a.prisma??new i.PrismaClient},54647:(e,r)=>{var t;Object.defineProperty(r,"x",{enumerable:!0,get:function(){return t}}),function(e){e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE"}(t||(t={}))}};var r=require("../../../webpack-runtime.js");r.C(e);var t=e=>r(r.s=e),i=r.X(0,[9727,3497,6886],()=>t(8825));module.exports=i})();