"use strict";(()=>{var e={};e.id=2684,e.ids=[2684,2331],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")},2926:(e,a,t)=>{t.r(a),t.d(a,{originalPathname:()=>k,patchFetch:()=>h,requestAsyncStorage:()=>u,routeModule:()=>m,serverHooks:()=>g,staticGenerationAsyncStorage:()=>l});var r={};t.r(r),t.d(r,{GET:()=>c,POST:()=>d});var s=t(49303),i=t(88716),n=t(60670),o=t(87070),p=t(72331);async function c(e){try{let{searchParams:a}=new URL(e.url),t=parseInt(a.get("page")??"1"),r=parseInt(a.get("limit")??"50"),s=(t-1)*r,[i,n]=await Promise.all([p.prisma.marketplaceItem.findMany({orderBy:{displayOrder:"asc"},skip:s,take:r}),p.prisma.marketplaceItem.count()]),c=i.map(e=>e.id),d=await p.prisma.redemptionOrder.groupBy({by:["itemId"],where:{itemId:{in:c},status:"completed"},_count:{id:!0}}),m=new Map(d.map(e=>[e.itemId,e._count.id]));return o.NextResponse.json({success:!0,data:i.map(e=>({id:e.id,name:e.name,description:e.description,category:e.category,image_url:e.imageUrl,price_points:e.pricePoints,price_coins:e.priceCoins,stock_quantity:e.stockQuantity,is_active:e.isActive,display_order:e.displayOrder,total_redeemed:m.get(e.id)??0,created_at:e.createdAt,updated_at:e.updatedAt})),pagination:{page:t,limit:r,total:n,total_pages:Math.ceil(n/r)}})}catch(e){return console.error("Admin marketplace GET error:",e),o.NextResponse.json({success:!1,message:"Gagal memuat item marketplace"},{status:500})}}async function d(e){try{let{name:a,description:t,category:r,price_points:s,price_coins:i,stock_quantity:n,display_order:c}=await e.json();if(!a||!r)return o.NextResponse.json({success:!1,message:"Nama dan kategori wajib diisi"},{status:400});if(!s&&!i)return o.NextResponse.json({success:!1,message:"Minimal satu harga (poin atau koin) harus diisi"},{status:400});let d=await p.prisma.marketplaceItem.create({data:{name:a,description:t??"",category:r,pricePoints:s?parseInt(s):null,priceCoins:i?parseInt(i):null,stockQuantity:n?parseInt(n):null,displayOrder:c?parseInt(c):0,isActive:!0}});return o.NextResponse.json({success:!0,data:{id:d.id},message:"Item berhasil ditambahkan"})}catch(e){return console.error("Admin marketplace POST error:",e),o.NextResponse.json({success:!1,message:"Gagal menambah item"},{status:500})}}let m=new s.AppRouteRouteModule({definition:{kind:i.x.APP_ROUTE,page:"/api/admin/marketplace/route",pathname:"/api/admin/marketplace",filename:"route",bundlePath:"app/api/admin/marketplace/route"},resolvedPagePath:"C:\\xampp\\htdocs\\Bolafest\\app\\api\\admin\\marketplace\\route.ts",nextConfigOutput:"standalone",userland:r}),{requestAsyncStorage:u,staticGenerationAsyncStorage:l,serverHooks:g}=m,k="/api/admin/marketplace/route";function h(){return(0,n.patchFetch)({serverHooks:g,staticGenerationAsyncStorage:l})}},72331:(e,a,t)=>{t.d(a,{prisma:()=>s});var r=t(53524);let s=globalThis.prisma??new r.PrismaClient({log:["error"]})}};var a=require("../../../../webpack-runtime.js");a.C(e);var t=e=>a(a.s=e),r=a.X(0,[9276,5972],()=>t(2926));module.exports=r})();