"use strict";(()=>{var e={};e.id=6111,e.ids=[6111],e.modules={2934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},4580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},5869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},6113:e=>{e.exports=require("crypto")},7147:e=>{e.exports=require("fs")},1017:e=>{e.exports=require("path")},4158:(e,t,r)=>{r.r(t),r.d(t,{headerHooks:()=>f,originalPathname:()=>y,patchFetch:()=>x,requestAsyncStorage:()=>h,routeModule:()=>p,serverHooks:()=>g,staticGenerationAsyncStorage:()=>v,staticGenerationBailout:()=>m});var o={};r.r(o),r.d(o,{POST:()=>l});var n=r(5419),s=r(9108),i=r(9678),a=r(8070),c=r(784);let d=(0,r(2509).createAdminClient)();async function u(e,t,r,o){try{let r={};try{r=await e.json()}catch{}let{visitor_id:o,conversation_id:n,type:s,payload:i}=r;if(!o||!s)return a.Z.json({error:{code:"MISSING_REQUIRED_FIELD",message:"visitor_id and type are required"}},{status:400});let c=["view","click","add_to_cart"];if(!c.includes(s))return a.Z.json({error:{code:"INVALID_FORMAT",message:`type must be one of: ${c.join(", ")}`}},{status:400});let{data:u}=await d.from("visitors").select("id").eq("site_id",t).eq("visitor_id",o).single();if(!u)return a.Z.json({error:{code:"VISITOR_NOT_FOUND",message:"Visitor not found"}},{status:404});let l=null;if(n){let{data:e}=await d.from("conversations").select("id").eq("site_id",t).eq("conversation_id",n).single();e&&(l=e.id)}let{error:p}=await d.from("chat_events").insert({site_id:t,visitor_id:u.id,conversation_id:l,event_type:s,payload:i||{},created_at:new Date().toISOString()});if(p)throw Error(`Failed to log event: ${p.message}`);return a.Z.json({status:"recorded"})}catch(e){return console.error("Events error:",e),a.Z.json({error:{code:"INTERNAL_ERROR",message:"Failed to record event"}},{status:500})}}let l=(0,c.Y)(u),p=new n.AppRouteRouteModule({definition:{kind:s.x.APP_ROUTE,page:"/api/chat/events/route",pathname:"/api/chat/events",filename:"route",bundlePath:"app/api/chat/events/route"},resolvedPagePath:"C:\\xampp\\htdocs\\AI Woo Chat\\src\\app\\api\\chat\\events\\route.ts",nextConfigOutput:"standalone",userland:o}),{requestAsyncStorage:h,staticGenerationAsyncStorage:v,serverHooks:g,headerHooks:f,staticGenerationBailout:m}=p,y="/api/chat/events/route";function x(){return(0,i.patchFetch)({serverHooks:g,staticGenerationAsyncStorage:v})}},8397:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),function(e,t){for(var r in t)Object.defineProperty(e,r,{enumerable:!0,get:t[r]})}(t,{PageSignatureError:function(){return r},RemovedPageError:function(){return o},RemovedUAError:function(){return n}});class r extends Error{constructor({page:e}){super(`The middleware "${e}" accepts an async API directly with the form:
  
  export function middleware(request, event) {
    return NextResponse.redirect('/new-location')
  }
  
  Read more: https://nextjs.org/docs/messages/middleware-new-signature
  `)}}class o extends Error{constructor(){super(`The request.page has been deprecated in favour of \`URLPattern\`.
  Read more: https://nextjs.org/docs/messages/middleware-request-page
  `)}}class n extends Error{constructor(){super(`The request.ua has been removed in favour of \`userAgent\` function.
  Read more: https://nextjs.org/docs/messages/middleware-parse-user-agent
  `)}}},424:(e,t,r)=>{Object.defineProperty(t,"Z",{enumerable:!0,get:function(){return o.NextRequest}});let o=r(1868)},1868:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),function(e,t){for(var r in t)Object.defineProperty(e,r,{enumerable:!0,get:t[r]})}(t,{INTERNALS:function(){return a},NextRequest:function(){return c}});let o=r(514),n=r(8670),s=r(8397),i=r(3608),a=Symbol("internal request");class c extends Request{constructor(e,t={}){let r="string"!=typeof e&&"url"in e?e.url:String(e);(0,n.validateURL)(r),e instanceof Request?super(e,t):super(r,t);let s=new o.NextURL(r,{headers:(0,n.toNodeOutgoingHttpHeaders)(this.headers),nextConfig:t.nextConfig});this[a]={cookies:new i.RequestCookies(this.headers),geo:t.geo||{},ip:t.ip,nextUrl:s,url:s.toString()}}[Symbol.for("edge-runtime.inspect.custom")](){return{cookies:this.cookies,geo:this.geo,ip:this.ip,nextUrl:this.nextUrl,url:this.url,bodyUsed:this.bodyUsed,cache:this.cache,credentials:this.credentials,destination:this.destination,headers:Object.fromEntries(this.headers),integrity:this.integrity,keepalive:this.keepalive,method:this.method,mode:this.mode,redirect:this.redirect,referrer:this.referrer,referrerPolicy:this.referrerPolicy,signal:this.signal}}get cookies(){return this[a].cookies}get geo(){return this[a].geo}get ip(){return this[a].ip}get nextUrl(){return this[a].nextUrl}get page(){throw new s.RemovedPageError}get ua(){throw new s.RemovedUAError}get url(){return this[a].url}}},2509:(e,t,r)=>{r.d(t,{createAdminClient:()=>a,e:()=>i});var o=r(6874),n=r(7439),s=r(3950);async function i(){let e=await (0,n.cookies)();return(0,o.lx)("https://drmuwsxyvvfivdfsyydy.supabase.co","eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImRybXV3c3h5dnZmaXZkZnN5eWR5Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njg0NjAwMDgsImV4cCI6MjA4NDAzNjAwOH0.kMsFG-VLNqwzIgl3cFW-owiRCWHcB47M6V6Ti4O4alY",{cookies:{get:t=>e.get(t)?.value,set(t,r,o){try{e.set({name:t,value:r,...o})}catch(e){}},remove(t,r){try{e.set({name:t,value:"",...r})}catch(e){}}}})}function a(){return(0,s.eI)("https://drmuwsxyvvfivdfsyydy.supabase.co",process.env.SUPABASE_SERVICE_ROLE_KEY,{auth:{autoRefreshToken:!1,persistSession:!1}})}(0,r(4113).C)()},4113:(e,t,r)=>{r.d(t,{C:()=>i});var o=r(7147),n=r(1017);let s=!1;function i(){if(!s)try{let e=process.cwd(),t=[(0,n.join)(e,".env.production"),(0,n.join)(e,"..",".env.production"),(0,n.join)(e,"..","..",".env.production"),(0,n.join)(e,"app",".env.production")],r=null,i=null;for(let e of t)try{i=(0,o.readFileSync)(e,"utf-8"),r=e,console.log("[EnvLoader] Found .env.production at:",e);break}catch{continue}if(!i||!r)throw Error(`Could not find .env.production. Tried: ${t.join(", ")}`);for(let e of i.split("\n")){let t=e.trim();if(!t||t.startsWith("#"))continue;let r=t.match(/^([^=]+)=(.*)$/);if(r){let e=r[1].trim(),t=r[2].trim();(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'"))&&(t=t.slice(1,-1)),process.env[e]||(process.env[e]=t)}}s=!0,console.log("[EnvLoader] Loaded environment variables from .env.production"),console.log("[EnvLoader] SUPABASE_DB_URL:",process.env.SUPABASE_DB_URL?"SET":"NOT SET")}catch(e){"ENOENT"===e.code?console.warn("[EnvLoader] .env.production file not found at:",envPath):console.warn("[EnvLoader] Could not load .env.production:",e.message)}}}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),o=t.X(0,[1638,9989,6206,784],()=>r(4158));module.exports=o})();