"use strict";(()=>{var e={};e.id=4537,e.ids=[4537],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")},4494:(e,r,t)=>{t.r(r),t.d(r,{headerHooks:()=>y,originalPathname:()=>b,patchFetch:()=>q,requestAsyncStorage:()=>w,routeModule:()=>g,serverHooks:()=>h,staticGenerationAsyncStorage:()=>f,staticGenerationBailout:()=>x});var a={};t.r(a),t.d(a,{GET:()=>p,POST:()=>m});var s=t(95419),o=t(69108),i=t(99678),n=t(78070),l=t(81355),u=t(82002),c=t(34490);async function d(){let e=await (0,l.getServerSession)(u.Lz);return e?.user?.id&&"ADMIN"===e.user.role?e:null}async function p(){if(!await d())return n.Z.json({error:"Forbidden"},{status:403});try{let e=await c.prisma.blogCategory.findMany({orderBy:{order:"asc"}});return n.Z.json(e)}catch(e){return console.error("[admin/blog/categories] GET error:",e),n.Z.json({error:"Failed to fetch categories"},{status:500})}}async function m(e){if(!await d())return n.Z.json({error:"Forbidden"},{status:403});try{let{nameEn:r,nameAr:t,color:a}=await e.json();if(!r||!t)return n.Z.json({error:"nameEn and nameAr are required"},{status:400});let s=r.toLowerCase().replace(/[^a-z0-9\s-]/g,"").replace(/\s+/g,"-").replace(/-+/g,"-").trim();await c.prisma.blogCategory.findUnique({where:{slug:s}})&&(s=`${s}-${Math.random().toString(36).substring(2,8)}`);let o=await c.prisma.blogCategory.create({data:{slug:s,nameEn:r,nameAr:t,color:a??"indigo"}});return n.Z.json(o,{status:201})}catch(e){return console.error("[admin/blog/categories] POST error:",e),n.Z.json({error:"Failed to create category"},{status:500})}}let g=new s.AppRouteRouteModule({definition:{kind:o.x.APP_ROUTE,page:"/api/admin/blog/categories/route",pathname:"/api/admin/blog/categories",filename:"route",bundlePath:"app/api/admin/blog/categories/route"},resolvedPagePath:"C:\\test2\\pagecraft-ai\\src\\app\\api\\admin\\blog\\categories\\route.ts",nextConfigOutput:"standalone",userland:a}),{requestAsyncStorage:w,staticGenerationAsyncStorage:f,serverHooks:h,headerHooks:y,staticGenerationBailout:x}=g,b="/api/admin/blog/categories/route";function q(){return(0,i.patchFetch)({serverHooks:h,staticGenerationAsyncStorage:f})}},82002:(e,r,t)=>{t.d(r,{Lz:()=>p});var a=t(65822),s=t(86485),o=t(10375),i=t(6521),n=t.n(i),l=t(34490),u=t(6632);let c=new Map;async function d(e){let r=await (0,u.FE)("security_config"),t=r?.maxLoginAttempts??5;if(0===t)return;let a=c.get(e);if(a){if(Date.now()-a.lastAttempt>36e5){c.delete(e);return}a.count>=t?await new Promise(e=>setTimeout(e,3e4)):a.count>=Math.floor(t/2)&&await new Promise(e=>setTimeout(e,2e3))}}let p={adapter:(0,a.N)(l.prisma),session:{strategy:"jwt"},pages:{signIn:"/login",newUser:"/dashboard"},providers:[(0,s.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 d(e.email);let t=await l.prisma.user.findUnique({where:{email:e.email}});if(!t||!t.password||!await n().compare(e.password,t.password))throw function(e){let r=c.get(e);r?(r.count+=1,r.lastAttempt=Date.now()):c.set(e,{count:1,lastAttempt:Date.now()})}(e.email),Error("Invalid email or password");return r=e.email,c.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,o.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 l.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),a=r.X(0,[1638,6206,6521,244,6632],()=>t(4494));module.exports=a})();