"use strict";(()=>{var e={};e.id=2718,e.ids=[2718],e.modules={53524:e=>{e.exports=require("@prisma/client")},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")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},39491:e=>{e.exports=require("assert")},14300:e=>{e.exports=require("buffer")},6113:e=>{e.exports=require("crypto")},82361:e=>{e.exports=require("events")},13685:e=>{e.exports=require("http")},95687:e=>{e.exports=require("https")},63477:e=>{e.exports=require("querystring")},57310:e=>{e.exports=require("url")},73837:e=>{e.exports=require("util")},59796:e=>{e.exports=require("zlib")},89348:(e,t,r)=>{r.r(t),r.d(t,{headerHooks:()=>x,originalPathname:()=>E,patchFetch:()=>y,requestAsyncStorage:()=>g,routeModule:()=>m,serverHooks:()=>h,staticGenerationAsyncStorage:()=>w,staticGenerationBailout:()=>f});var s={};r.r(s),r.d(s,{GET:()=>d});var a=r(95419),i=r(69108),n=r(99678),o=r(78070),l=r(81355),u=r(82002),c=r(34490);async function p(){let e=await (0,l.getServerSession)(u.Lz);return e?.user?.id&&"ADMIN"===e.user.role?e:null}async function d(e){if(!await p())return o.Z.json({error:"Forbidden"},{status:403});let{searchParams:t}=new URL(e.url),r=t.get("search")||"",s=t.get("status"),a=t.get("subject"),i=Math.max(1,parseInt(t.get("page")||"1",10)),n=Math.min(50,Math.max(1,parseInt(t.get("limit")||"20",10))),l={};r&&(l.OR=[{name:{contains:r,mode:"insensitive"}},{email:{contains:r,mode:"insensitive"}},{message:{contains:r,mode:"insensitive"}}]),s&&(l.status=s),a&&(l.subject=a);try{let[e,t,r]=await Promise.all([c.prisma.contactMessage.findMany({where:l,orderBy:{createdAt:"desc"},skip:(i-1)*n,take:n,include:{replier:{select:{name:!0,email:!0}}}}),c.prisma.contactMessage.count({where:l}),c.prisma.contactMessage.groupBy({by:["status"],_count:!0})]),s={total:0,NEW:0,READ:0,REPLIED:0,CLOSED:0};for(let e of r)s[e.status]=e._count,s.total+=e._count;return o.Z.json({messages:e,total:t,page:i,totalPages:Math.ceil(t/n),stats:s})}catch(e){return console.error("[admin/messages] GET error:",e),o.Z.json({error:"Failed to fetch messages"},{status:500})}}let m=new a.AppRouteRouteModule({definition:{kind:i.x.APP_ROUTE,page:"/api/admin/messages/route",pathname:"/api/admin/messages",filename:"route",bundlePath:"app/api/admin/messages/route"},resolvedPagePath:"C:\\test2\\pagecraft-ai\\src\\app\\api\\admin\\messages\\route.ts",nextConfigOutput:"standalone",userland:s}),{requestAsyncStorage:g,staticGenerationAsyncStorage:w,serverHooks:h,headerHooks:x,staticGenerationBailout:f}=m,E="/api/admin/messages/route";function y(){return(0,n.patchFetch)({serverHooks:h,staticGenerationAsyncStorage:w})}},82002:(e,t,r)=>{r.d(t,{Lz:()=>d});var s=r(65822),a=r(86485),i=r(10375),n=r(6521),o=r.n(n),l=r(34490),u=r(6632);let c=new Map;async function p(e){let t=await (0,u.FE)("security_config"),r=t?.maxLoginAttempts??5;if(0===r)return;let s=c.get(e);if(s){if(Date.now()-s.lastAttempt>36e5){c.delete(e);return}s.count>=r?await new Promise(e=>setTimeout(e,3e4)):s.count>=Math.floor(r/2)&&await new Promise(e=>setTimeout(e,2e3))}}let d={adapter:(0,s.N)(l.prisma),session:{strategy:"jwt"},pages:{signIn:"/login",newUser:"/dashboard"},providers:[(0,a.Z)({name:"credentials",credentials:{email:{label:"Email",type:"email"},password:{label:"Password",type:"password"}},async authorize(e){if(!e?.email||!e?.password)throw Error("Email and password are required");try{var t;await p(e.email);let r=await l.prisma.user.findUnique({where:{email:e.email}});if(!r||!r.password||!await o().compare(e.password,r.password))throw function(e){let t=c.get(e);t?(t.count+=1,t.lastAttempt=Date.now()):c.set(e,{count:1,lastAttempt:Date.now()})}(e.email),Error("Invalid email or password");return t=e.email,c.delete(t),{id:r.id,email:r.email,name:r.name,image:r.image}}catch(e){if(e?.message?.includes("Invalid")||e?.message?.includes("required"))throw e;throw console.error("[auth] DB error during login:",e),Error("Authentication service temporarily unavailable")}}}),...process.env.GOOGLE_CLIENT_ID&&process.env.GOOGLE_CLIENT_SECRET?[(0,i.Z)({clientId:process.env.GOOGLE_CLIENT_ID,clientSecret:process.env.GOOGLE_CLIENT_SECRET})]:[]],callbacks:{session:async({session:e,token:t})=>(t&&e.user&&(e.user.id=t.sub,e.user.role=t.role),e),async jwt({token:e,user:t}){if(t){e.sub=t.id;try{let r=await l.prisma.user.findUnique({where:{id:t.id},select:{role:!0}});e.role=r?.role??null}catch(t){console.warn("[auth] DB error in JWT callback, defaulting role to null"),e.role=null}}return e}}}}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),s=t.X(0,[1638,6206,6521,244,6632],()=>r(89348));module.exports=s})();