import { NextResponse } from "next/server";

export async function POST(req:Request){
  const email=process.env.ADMIN_EMAIL;
  const password=process.env.ADMIN_PASSWORD;
  if(!email||!password){return NextResponse.json({error:"ADMIN_EMAIL / ADMIN_PASSWORD belum dikonfigurasi"},{status:500})}
  const body=await req.json().catch(()=>({}));
  if(body.email!==email||body.password!==password){return NextResponse.json({error:"Email atau password salah"},{status:401})}
  const res=NextResponse.json({ok:true});
  res.cookies.set('aljannah_admin','1',{httpOnly:true,secure:process.env.NODE_ENV==='production',sameSite:'lax',path:'/',maxAge:60*60*8});
  return res;
}
