"use strict";(()=>{var e={};e.id=8873,e.ids=[8873],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")},11606:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>_,patchFetch:()=>h,requestAsyncStorage:()=>m,routeModule:()=>p,serverHooks:()=>x,staticGenerationAsyncStorage:()=>f});var n={};r.r(n),r.d(n,{POST:()=>d});var a=r(49303),i=r(88716),s=r(60670),o=r(87070),u=r(8194),l=r(95456),c=r(56811);async function d(e){try{let{email:t,password:r}=await e.json();if(!t||!r)return o.NextResponse.json({error:"Email dan password wajib diisi"},{status:400});let n=await u._.user.findFirst({where:{email:t,isActive:!0},include:{tenant:!0,store:!0}});if(!n||!await (0,l.Gv)(r,n.password))return o.NextResponse.json({error:"Email atau password salah"},{status:401});let a=await (0,c.Km)("email_verification_enabled");if("true"===a&&!1===n.emailVerified&&null!==n.verificationToken)return o.NextResponse.json({error:"Email belum diverifikasi. Silakan cek inbox Anda.",requiresVerification:!0},{status:403});if(!n.tenant.isActive)return o.NextResponse.json({error:"Akun restoran tidak aktif"},{status:403});if(n.storeId&&n.store&&!n.store.isActive&&!["owner","admin"].includes(n.role))return o.NextResponse.json({error:"Cabang Anda sedang tidak aktif. Hubungi admin."},{status:403});let i=(0,l.RA)({userId:n.id,tenantId:n.tenantId,email:n.email,role:n.role,storeId:n.storeId}),s=o.NextResponse.json({user:{id:n.id,name:n.name,email:n.email,role:n.role,tenantId:n.tenantId,storeId:n.storeId,tenant:{id:n.tenant.id,name:n.tenant.name,slug:n.tenant.slug}},token:i});return s.cookies.set("token",i,{httpOnly:!0,secure:!0,sameSite:"lax",maxAge:604800,path:"/"}),s}catch(e){return console.error("Login error:",e),o.NextResponse.json({error:"Terjadi kesalahan server"},{status:500})}}let p=new a.AppRouteRouteModule({definition:{kind:i.x.APP_ROUTE,page:"/api/auth/login/route",pathname:"/api/auth/login",filename:"route",bundlePath:"app/api/auth/login/route"},resolvedPagePath:"D:\\PROJECT\\resto-saas\\src\\app\\api\\auth\\login\\route.ts",nextConfigOutput:"",userland:n}),{requestAsyncStorage:m,staticGenerationAsyncStorage:f,serverHooks:x}=p,_="/api/auth/login/route";function h(){return(0,s.patchFetch)({serverHooks:x,staticGenerationAsyncStorage:f})}},95456:(e,t,r)=>{r.d(t,{Gv:()=>d,MH:()=>x,PT:()=>_,RA:()=>p,WX:()=>m,c_:()=>c,ts:()=>f});var n=r(41482),a=r.n(n),i=r(42023),s=r.n(i),o=r(71615),u=r(8194);let l=process.env.JWT_SECRET||"fallback-secret-change-me";async function c(e){return s().hash(e,12)}async function d(e,t){return s().compare(e,t)}function p(e){return a().sign(e,l,{expiresIn:"7d"})}function m(e){try{return a().verify(e,l)}catch{return null}}async function f(){let e=await (0,o.cookies)(),t=e.get("token")?.value;if(!t)return null;let r=m(t);return r?await u._.user.findUnique({where:{id:r.userId},include:{tenant:!0,store:!0}}):null}function x(e,t){return t.includes(e)}function _(e){return!["owner","admin"].includes(e.role)&&!!e.storeId&&!!e.store&&!e.store.isActive}},8194:(e,t,r)=>{r.d(t,{_:()=>a});let n=require("@prisma/client"),a=globalThis.prisma??new n.PrismaClient},56811:(e,t,r)=>{r.d(t,{$X:()=>s,Km:()=>i,Rx:()=>o,ks:()=>u});var n=r(8194);let a={payment_fee_mode:"percentage",payment_fee_amount:"2.5",payment_enabled:"true",min_withdrawal:"50000",affiliate_commission_rate:"10",affiliate_enabled:"true",affiliate_min_withdrawal:"50000",email_verification_enabled:"false",smtp_host:"",smtp_port:"587",smtp_user:"",smtp_pass:"",smtp_from_email:"",smtp_from_name:"RestoMenu",smtp_secure:"false"};async function i(e){let t=await n._.platformSetting.findUnique({where:{key:e}});return t?.value??a[e]??""}async function s(){let e=await n._.platformSetting.findMany(),t={...a};for(let r of e)t[r.key]=r.value;return t}async function o(e){let t=Object.entries(e).map(([e,t])=>n._.platformSetting.upsert({where:{key:e},update:{value:t},create:{key:e,value:t}}));await n._.$transaction(t)}function u(e,t,r){let n=parseFloat(r)||0,a=0;a=Math.min(a="percentage"===t?Math.round(e*n/100):Math.round(n),e);let i=e-a;return{fee:a,tenantAmount:i}}}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),n=t.X(0,[8948,5972,4261,2023],()=>r(11606));module.exports=n})();