"use strict";(()=>{var e={};e.id=2013,e.ids=[2013],e.modules={53524:e=>{e.exports=require("@prisma/client")},20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},2064:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>g,patchFetch:()=>h,requestAsyncStorage:()=>p,routeModule:()=>d,serverHooks:()=>k,staticGenerationAsyncStorage:()=>m});var s={};r.r(s),r.d(s,{GET:()=>l,POST:()=>c});var n=r(49303),o=r(88716),i=r(60670),a=r(87070),u=r(72331);async function l(e){let{searchParams:t}=new URL(e.url),r=t.get("dramaId"),s=t.get("source"),n=t.get("userId");if(!r)return a.NextResponse.json({error:"Drama ID is required"},{status:400});try{let e=(await u._.comment.findMany({where:{dramaId:r,parentId:null,...s?{source:s}:{}},include:{user:{select:{id:!0,username:!0,image:!0,role:!0}},_count:{select:{likes:!0,replies:!0}},likes:!!n&&{where:{userId:n},select:{userId:!0}},replies:{include:{user:{select:{id:!0,username:!0,image:!0,role:!0}},_count:{select:{likes:!0}},likes:!!n&&{where:{userId:n},select:{userId:!0}}},orderBy:{createdAt:"asc"}}},orderBy:{createdAt:"desc"},take:50})).map(e=>({...e,isLiked:e.likes?.length>0,likes:void 0,likeCount:e._count.likes,replyCount:e._count.replies,replies:e.replies.map(e=>({...e,isLiked:e.likes?.length>0,likes:void 0,likeCount:e._count.likes}))}));return a.NextResponse.json(e)}catch(e){return console.error("Fetch comments error:",e),a.NextResponse.json({error:"Failed to fetch comments"},{status:500})}}async function c(e){try{let{userId:t,dramaId:r,source:s,content:n,parentId:o}=await e.json();if(!t||!r||!n)return a.NextResponse.json({error:"Missing required fields"},{status:400});let i=await u._.comment.create({data:{userId:t,dramaId:r,source:s||"Unknown",content:n,parentId:o||null},include:{user:{select:{username:!0,image:!0}}}});return a.NextResponse.json(i)}catch(e){return console.error("Post comment error:",e),a.NextResponse.json({error:"Failed to post comment"},{status:500})}}let d=new n.AppRouteRouteModule({definition:{kind:o.x.APP_ROUTE,page:"/api/comments/route",pathname:"/api/comments",filename:"route",bundlePath:"app/api/comments/route"},resolvedPagePath:"C:\\Users\\MSI\\Downloads\\film\\app\\api\\comments\\route.ts",nextConfigOutput:"standalone",userland:s}),{requestAsyncStorage:p,staticGenerationAsyncStorage:m,serverHooks:k}=d,g="/api/comments/route";function h(){return(0,i.patchFetch)({serverHooks:k,staticGenerationAsyncStorage:m})}},72331:(e,t,r)=>{r.d(t,{_:()=>n});var s=r(53524);let n=global.prisma||new s.PrismaClient}};var t=require("../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),s=t.X(0,[8948,5972],()=>r(2064));module.exports=s})();