"use strict";(()=>{var e={};e.id=4594,e.ids=[4594],e.modules={72934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},54580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},45869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},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")},78893:e=>{e.exports=require("buffer")},84770:e=>{e.exports=require("crypto")},76162:e=>{e.exports=require("stream")},21764:e=>{e.exports=require("util")},61792:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>f,patchFetch:()=>h,requestAsyncStorage:()=>m,routeModule:()=>p,serverHooks:()=>x,staticGenerationAsyncStorage:()=>g});var s={};r.r(s),r.d(s,{GET:()=>d,POST:()=>l});var a=r(49303),n=r(88716),i=r(60670),u=r(87070),o=r(8194),c=r(95456);async function d(e){try{let t=await (0,c.ts)();if(!t)return u.NextResponse.json({error:"Anda belum login"},{status:401});let r=parseInt(e.nextUrl.searchParams.get("page")||"1"),s=parseInt(e.nextUrl.searchParams.get("limit")||"20"),a=(r-1)*s,n={tenantId:t.tenantId},[i,d]=await Promise.all([o._.ticket.findMany({where:n,include:{user:{select:{id:!0,name:!0,email:!0}},_count:{select:{messages:!0}}},orderBy:{createdAt:"desc"},take:s,skip:a}),o._.ticket.count({where:n})]),l=i.map(e=>({id:e.id,subject:e.subject,status:e.status,priority:e.priority,category:e.category,createdAt:e.createdAt,updatedAt:e.updatedAt,user:e.user,messageCount:e._count.messages}));return u.NextResponse.json({tickets:l,pagination:{page:r,limit:s,total:d,totalPages:Math.ceil(d/s)}})}catch{return u.NextResponse.json({error:"Terjadi kesalahan server"},{status:500})}}async function l(e){try{let t=await (0,c.ts)();if(!t)return u.NextResponse.json({error:"Anda belum login"},{status:401});let{subject:r,category:s,priority:a,message:n}=await e.json();if(!r||!r.trim())return u.NextResponse.json({error:"Subjek tiket wajib diisi"},{status:400});if(!n||!n.trim())return u.NextResponse.json({error:"Pesan tiket wajib diisi"},{status:400});if(a&&!["low","medium","high","urgent"].includes(a))return u.NextResponse.json({error:"Prioritas tidak valid. Gunakan: low, medium, high, atau urgent"},{status:400});if(s&&!["general","billing","technical","feature_request","bug_report"].includes(s))return u.NextResponse.json({error:"Kategori tidak valid. Gunakan: general, billing, technical, feature_request, atau bug_report"},{status:400});let i=await o._.ticket.create({data:{tenantId:t.tenantId,userId:t.id,subject:r.trim(),status:"open",priority:a||"medium",category:s||"general",messages:{create:{userId:t.id,senderType:"tenant_user",message:n.trim()}}},include:{user:{select:{id:!0,name:!0,email:!0}},messages:!0,_count:{select:{messages:!0}}}});return u.NextResponse.json({message:"Tiket berhasil dibuat",ticket:{id:i.id,subject:i.subject,status:i.status,priority:i.priority,category:i.category,createdAt:i.createdAt,updatedAt:i.updatedAt,user:i.user,messages:i.messages,messageCount:i._count.messages}},{status:201})}catch{return u.NextResponse.json({error:"Terjadi kesalahan server"},{status:500})}}let p=new a.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/tickets/route",pathname:"/api/tickets",filename:"route",bundlePath:"app/api/tickets/route"},resolvedPagePath:"D:\\PROJECT\\resto-saas\\src\\app\\api\\tickets\\route.ts",nextConfigOutput:"",userland:s}),{requestAsyncStorage:m,staticGenerationAsyncStorage:g,serverHooks:x}=p,f="/api/tickets/route";function h(){return(0,i.patchFetch)({serverHooks:x,staticGenerationAsyncStorage:g})}},95456:(e,t,r)=>{r.d(t,{Gv:()=>l,MH:()=>x,PT:()=>f,RA:()=>p,WX:()=>m,c_:()=>d,ts:()=>g});var s=r(41482),a=r.n(s),n=r(42023),i=r.n(n),u=r(71615),o=r(8194);let c=process.env.JWT_SECRET||"fallback-secret-change-me";async function d(e){return i().hash(e,12)}async function l(e,t){return i().compare(e,t)}function p(e){return a().sign(e,c,{expiresIn:"7d"})}function m(e){try{return a().verify(e,c)}catch{return null}}async function g(){let e=await (0,u.cookies)(),t=e.get("token")?.value;if(!t)return null;let r=m(t);return r?await o._.user.findUnique({where:{id:r.userId},include:{tenant:!0,store:!0}}):null}function x(e,t){return t.includes(e)}function f(e){return!["owner","admin"].includes(e.role)&&!!e.storeId&&!!e.store&&!e.store.isActive}},8194:(e,t,r)=>{r.d(t,{_:()=>a});let s=require("@prisma/client"),a=globalThis.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,4261,2023],()=>r(61792));module.exports=s})();