"use strict";(()=>{var e={};e.id=744,e.ids=[744],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")},78880:(e,t,n)=>{n.r(t),n.d(t,{originalPathname:()=>f,patchFetch:()=>O,requestAsyncStorage:()=>y,routeModule:()=>m,serverHooks:()=>g,staticGenerationAsyncStorage:()=>x});var o={};n.r(o),n.d(o,{POST:()=>h});var a=n(49303),s=n(88716),r=n(60670),i=n(87070),c=n(70446),u=n(90455),p=n(19191);async function d(e,t,n,o){try{let a=await (0,p.q)(`/customerchats/v1/channels/${e}/customers/${t}/orders/${n}/chats`,{apiBase:"mobile",token:o,method:"POST"});return a.data?.key??a.data??null}catch{return null}}async function l(e,t,n,o,a){try{return await (0,p.q)(`/customerchats/v1/channels/${e}/customers/${t}/chats/${n}/messages`,{apiBase:"mobile",token:a,method:"POST",body:{text:o.text,entityType:0,cDate:new Date().toISOString(),readStatus:0,imageJson:o.imageJson}}),!0}catch{return!1}}async function h(e){let t=await (0,c.Gg)(),n=(0,u.LP)(t);if(!t.authenticated||!t.user)return i.NextResponse.json({error:"Unauthorized"},{status:401});let o=await e.json(),a=String(t.user.id),s=o.channel??"support";if("open"===o.action){let e=o.orderCode??"0",t=await d(s,a,e,n);return t?i.NextResponse.json({success:!0,chatKey:t}):i.NextResponse.json({error:"Failed to open chat"},{status:500})}if("send"===o.action){let e=await l(s,a,o.chatKey,{text:o.text,imageJson:o.imageJson},n);return i.NextResponse.json({success:e})}return i.NextResponse.json({error:"Invalid action"},{status:400})}let m=new a.AppRouteRouteModule({definition:{kind:s.x.APP_ROUTE,page:"/api/chat/route",pathname:"/api/chat",filename:"route",bundlePath:"app/api/chat/route"},resolvedPagePath:"/Users/ferlando/Desktop/baboon-nextjs/app/api/chat/route.ts",nextConfigOutput:"standalone",userland:o}),{requestAsyncStorage:y,staticGenerationAsyncStorage:x,serverHooks:g}=m,f="/api/chat/route";function O(){return(0,r.patchFetch)({serverHooks:g,staticGenerationAsyncStorage:x})}},19191:(e,t,n)=>{n.d(t,{F:()=>r,q:()=>s});var o=n(47090),a=n(70446);async function s(e,t={}){let{apiBase:n="mobile",method:s="GET",body:r,token:i,langCode:c,notificationToken:u,headers:p={},revalidate:d,cache:l}=t,h=o.Y8[n],m=`${h}${e.startsWith("/")?e:"/"+e}`,y={"Content-Type":"application/json","User-Agent":"BaboonWeb",...p};i&&(y.Authorization=i),c&&(y.langCode=c);let x=u;if(!x)try{x=(await (0,a.Gg)()).fcmToken}catch{}x&&(y.notificationToken=x);let g={method:s,headers:y};r&&"GET"!==s&&(g.body=JSON.stringify(r)),void 0!==d&&(g.next={revalidate:d}),l&&(g.cache=l);let f=await fetch(m,g);if(!f.ok)throw Error(`API request failed: ${f.status} ${f.statusText}`);return f.json()}async function r(e,t={}){let{apiBase:n="mobile",method:s="GET",body:r,token:i,langCode:c,notificationToken:u,headers:p={}}=t,d=o.Y8[n],l=`${d}${e.startsWith("/")?e:"/"+e}`,h={"Content-Type":"application/json","User-Agent":"BaboonWeb",...p};i&&(h.Authorization=i),c&&(h.langCode=c);let m=u;if(!m)try{m=(await (0,a.Gg)()).fcmToken}catch{}m&&(h.notificationToken=m);let y={method:s,headers:h};return r&&"GET"!==s&&(y.body=JSON.stringify(r)),fetch(l,y)}},90455:(e,t,n)=>{function o(e){return e.token?e.token:e.user?.token?e.user.token:process.env.BABOON_APP_BUSINESS_TOKEN||""}function a(){return process.env.BABOON_APP_BUSINESS_TOKEN||""}n.d(t,{I2:()=>a,LP:()=>o})},47090:(e,t,n)=>{n.d(t,{RF:()=>o,Y8:()=>s,pH:()=>a});let o=["al","en","it"],a={AL:{latitude:41.327546,longitude:19.818698,cityId:1,countryId:1},XK:{latitude:42.662914,longitude:21.165503,cityId:2,countryId:2}},s={mobile:process.env.BABOON_API_MOBILE_URL,legacy:process.env.BABOON_API_URL,sysadmin:process.env.BABOON_API_SYSADMIN_URL,payment:process.env.BABOON_API_PAYMENT_URL}},70446:(e,t,n)=>{n.d(t,{Gg:()=>i,dx:()=>s,l7:()=>r,yK:()=>c});var o=n(78632),a=n(71615);let s={password:process.env.SESSION_SECRET,cookieName:"baboon-session",cookieOptions:{secure:!0,httpOnly:!0,sameSite:"lax",maxAge:604800}},r={...s,cookieName:"baboon-admin-session"};async function i(){let e=await (0,a.cookies)();return(0,o.iW)(e,s)}async function c(){let e=await (0,a.cookies)();return(0,o.iW)(e,r)}}};var t=require("../../../webpack-runtime.js");t.C(e);var n=e=>t(t.s=e),o=t.X(0,[8948,3314,8632,5972],()=>n(78880));module.exports=o})();