"use strict";(()=>{var e={};e.id=1607,e.ids=[1607],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")},6005:e=>{e.exports=require("node:crypto")},5267:(e,t,s)=>{s.r(t),s.d(t,{originalPathname:()=>y,patchFetch:()=>g,requestAsyncStorage:()=>l,routeModule:()=>p,serverHooks:()=>h,staticGenerationAsyncStorage:()=>m});var a={};s.r(a),s.d(a,{POST:()=>u});var o=s(49303),n=s(88716),r=s(60670),i=s(87070),d=s(70446),c=s(90455);async function u(e){let t=await (0,d.Gg)(),s=(0,c.LP)(t)||(0,c.I2)(),a=await e.json(),o=t.user?.id??-1,n=a.latitude||t.storageLatitude||41.327546,r=a.longitude||t.storageLongitude||19.818698,u=t.langCode||"al";try{let e=null,d=process.env.BABOON_API_MOBILE_URL,c={"Content-Type":"application/json",langCode:u||"sq"};if(s&&(c.Authorization=s),!e){let s={customer:{id:o},business:{restaurantID:a.restaurantId},address:{id:a.addressId||1,latitude:n,longitude:r,addressStreet:a.address||t.primaryAddress?.address||"",addressDetails:a.addressDetails||"",city:{id:t.cityId||1}},zone:{zoneNumber:1,minimumOrder:a.minimumOrder||0,transportcost:a.takeAwayPointId?0:a.transportCost||0,deliveryTime:a.deliveryTime||50},discount:{id:a.discount?.id||0,couponCode:a.discount?.couponCode||""},items:a.items},u=await fetch(`${d}/carts/v1/create`,{method:"POST",headers:c,body:JSON.stringify(s),cache:"no-store"}),p=await u.json();if(!(e=p.data?.id))return i.NextResponse.json({success:!1,message:p.statusMessage?.message||"Failed to create cart"},{status:400})}let p=0;if(o>0)try{let t=await fetch(`${d}/carts/v1/${e}/service-fee/${o}`,{headers:c,cache:"no-store"}),s=await t.json();p="number"==typeof s.data?s.data:s.data?.serviceFee??s.data?.amount??0}catch(e){console.warn("[checkout] service fee fetch failed, continuing with 0:",e)}let l={total:(a.total||0)+p,description:a.note||"",serviceFee:p};"card"===a.paymentMethod&&a.creditCardReference?l.paymentMethod={paymentType:"CREDIT_CARD",creditCardReference:a.creditCardReference}:"card"===a.paymentMethod&&(l.paymentMethod={paymentType:"CREDIT_CARD"}),a.scheduledTime&&(l.scheduled=a.scheduledTime),a.takeAwayPointId&&(l.takeAwayPoint={id:a.takeAwayPointId}),a.discount?.id&&(l.discount={discount:a.discount.discount||0,id:a.discount.id,couponCode:a.discount.couponCode||""},l.total-=a.discount.discount||0);let m={"Content-Type":"application/json"};s&&(m.Authorization=s);let h=JSON.stringify(l);m["Content-Length"]=String(Buffer.byteLength(h));let y=await fetch(`${d}/carts/v1/${e}/order`,{method:"POST",headers:m,body:h,cache:"no-store"}),g=await y.json();if(g.statusMessage?.status===200||g.statusMessage?.success){let e={success:!0,data:g.data,message:"Porosia u krye."};return"card"===a.paymentMethod&&g.data&&(e.paymentId=g.data.paymentId||g.data.paymentMethod?.paymentId,e.isCardPayment=!0),i.NextResponse.json(e)}return i.NextResponse.json({success:!1,message:g.statusMessage?.notes||g.statusMessage?.message||"Order failed"},{status:400})}catch(e){return console.error("[checkout] ERROR:",e?.message||e,"status:",e?.statusCode),i.NextResponse.json({success:!1,message:e.message||"Checkout failed",detail:String(e)},{status:500})}}let p=new o.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/checkout/route",pathname:"/api/checkout",filename:"route",bundlePath:"app/api/checkout/route"},resolvedPagePath:"/Users/ferlando/Desktop/baboon-nextjs/app/api/checkout/route.ts",nextConfigOutput:"standalone",userland:a}),{requestAsyncStorage:l,staticGenerationAsyncStorage:m,serverHooks:h}=p,y="/api/checkout/route";function g(){return(0,r.patchFetch)({serverHooks:h,staticGenerationAsyncStorage:m})}},90455:(e,t,s)=>{function a(e){return e.token?e.token:e.user?.token?e.user.token:process.env.BABOON_APP_BUSINESS_TOKEN||""}function o(){return process.env.BABOON_APP_BUSINESS_TOKEN||""}s.d(t,{I2:()=>o,LP:()=>a})},70446:(e,t,s)=>{s.d(t,{Gg:()=>i,dx:()=>n,l7:()=>r,yK:()=>d});var a=s(78632),o=s(71615);let n={password:process.env.SESSION_SECRET,cookieName:"baboon-session",cookieOptions:{secure:!0,httpOnly:!0,sameSite:"lax",maxAge:604800}},r={...n,cookieName:"baboon-admin-session"};async function i(){let e=await (0,o.cookies)();return(0,a.iW)(e,n)}async function d(){let e=await (0,o.cookies)();return(0,a.iW)(e,r)}}};var t=require("../../../webpack-runtime.js");t.C(e);var s=e=>t(t.s=e),a=t.X(0,[8948,3314,8632,5972],()=>s(5267));module.exports=a})();