"use strict";(()=>{var e={};e.id=1765,e.ids=[1765],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")},57147:e=>{e.exports=require("fs")},13685:e=>{e.exports=require("http")},95687:e=>{e.exports=require("https")},87561:e=>{e.exports=require("node:fs")},84492:e=>{e.exports=require("node:stream")},72477:e=>{e.exports=require("node:stream/web")},71017:e=>{e.exports=require("path")},85477:e=>{e.exports=require("punycode")},63477:e=>{e.exports=require("querystring")},12781:e=>{e.exports=require("stream")},57310:e=>{e.exports=require("url")},73837:e=>{e.exports=require("util")},71267:e=>{e.exports=require("worker_threads")},59796:e=>{e.exports=require("zlib")},92736:(e,r,t)=>{t.r(r),t.d(r,{headerHooks:()=>x,originalPathname:()=>q,patchFetch:()=>f,requestAsyncStorage:()=>m,routeModule:()=>d,serverHooks:()=>g,staticGenerationAsyncStorage:()=>w,staticGenerationBailout:()=>h});var s={};t.r(s),t.d(s,{POST:()=>c});var a=t(95419),i=t(69108),o=t(99678),n=t(78070),u=t(81355),l=t(82002),p=t(36168);async function c(e){if(!await (0,u.getServerSession)(l.Lz))return n.Z.json({error:"Unauthorized"},{status:401});try{let{model:r,apiKey:t}=await e.json();if(!t)return n.Z.json({error:"API key is required"},{status:400});let s=new p.ZP({baseURL:"https://openrouter.ai/api/v1",apiKey:t}),a=await s.chat.completions.create({model:r||"google/gemini-2.0-flash-001",messages:[{role:"user",content:"Hi"}],max_tokens:5});if(a.choices?.[0]?.message)return n.Z.json({ok:!0});return n.Z.json({error:"No response"},{status:400})}catch(r){let e=r instanceof Error?r.message:"Connection failed";return n.Z.json({error:e},{status:400})}}let d=new a.AppRouteRouteModule({definition:{kind:i.x.APP_ROUTE,page:"/api/admin/settings/test-ai/route",pathname:"/api/admin/settings/test-ai",filename:"route",bundlePath:"app/api/admin/settings/test-ai/route"},resolvedPagePath:"C:\\test2\\pagecraft-ai\\src\\app\\api\\admin\\settings\\test-ai\\route.ts",nextConfigOutput:"standalone",userland:s}),{requestAsyncStorage:m,staticGenerationAsyncStorage:w,serverHooks:g,headerHooks:x,staticGenerationBailout:h}=d,q="/api/admin/settings/test-ai/route";function f(){return(0,o.patchFetch)({serverHooks:g,staticGenerationAsyncStorage:w})}},82002:(e,r,t)=>{t.d(r,{Lz:()=>d});var s=t(65822),a=t(86485),i=t(10375),o=t(6521),n=t.n(o),u=t(34490),l=t(6632);let p=new Map;async function c(e){let r=await (0,l.FE)("security_config"),t=r?.maxLoginAttempts??5;if(0===t)return;let s=p.get(e);if(s){if(Date.now()-s.lastAttempt>36e5){p.delete(e);return}s.count>=t?await new Promise(e=>setTimeout(e,3e4)):s.count>=Math.floor(t/2)&&await new Promise(e=>setTimeout(e,2e3))}}let d={adapter:(0,s.N)(u.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 r;await c(e.email);let t=await u.prisma.user.findUnique({where:{email:e.email}});if(!t||!t.password||!await n().compare(e.password,t.password))throw function(e){let r=p.get(e);r?(r.count+=1,r.lastAttempt=Date.now()):p.set(e,{count:1,lastAttempt:Date.now()})}(e.email),Error("Invalid email or password");return r=e.email,p.delete(r),{id:t.id,email:t.email,name:t.name,image:t.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:r})=>(r&&e.user&&(e.user.id=r.sub,e.user.role=r.role),e),async jwt({token:e,user:r}){if(r){e.sub=r.id;try{let t=await u.prisma.user.findUnique({where:{id:r.id},select:{role:!0}});e.role=t?.role??null}catch(r){console.warn("[auth] DB error in JWT callback, defaulting role to null"),e.role=null}}return e}}}}};var r=require("../../../../../webpack-runtime.js");r.C(e);var t=e=>r(r.s=e),s=r.X(0,[1638,6206,6521,244,6168,6632],()=>t(92736));module.exports=s})();