"use strict";(()=>{var e={};e.id=5318,e.ids=[5318],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")},7147:e=>{e.exports=require("fs")},1017:e=>{e.exports=require("path")},2366:(e,t,r)=>{r.r(t),r.d(t,{headerHooks:()=>_,originalPathname:()=>h,patchFetch:()=>g,requestAsyncStorage:()=>p,routeModule:()=>u,serverHooks:()=>v,staticGenerationAsyncStorage:()=>m,staticGenerationBailout:()=>f});var n={};r.r(n),r.d(n,{GET:()=>l});var s=r(5419),i=r(9108),o=r(9678),a=r(2509),c=r(9829),d=r(8070);async function l(e){try{let t=await (0,a.e)(),{data:{user:r}}=await t.auth.getUser();if(!r)return d.Z.json({error:"Unauthorized"},{status:401});if(!await (0,c.j)(r.id))return d.Z.json({error:"Forbidden"},{status:403});let{searchParams:n}=new URL(e.url),s=n.get("tenant_id"),i=n.get("search")||"";if(!s)return d.Z.json({error:"tenant_id is required"},{status:400});let o=(0,a.createAdminClient)(),{data:l}=await o.from("licenses").select("id").eq("tenant_id",s),u=l?.map(e=>e.id)||[];if(0===u.length)return d.Z.json({conversations:[]});let{data:p}=await o.from("sites").select("id").in("license_id",u),m=p?.map(e=>e.id)||[];if(0===m.length)return d.Z.json({conversations:[]});let v=o.from("conversations").select(`
        id,
        conversation_id,
        site_id,
        visitor_id,
        started_at,
        last_message_at,
        message_count,
        created_at,
        sites (
          id,
          site_url,
          site_name,
          license_id,
          licenses (
            id,
            license_key,
            customer_email
          )
        )
      `).in("site_id",m).order("last_message_at",{ascending:!1}).limit(1e3);i.trim()&&(v=v.ilike("conversation_id",`%${i.trim()}%`));let{data:_,error:f}=await v;if(f)return console.error("Error fetching conversations:",f),d.Z.json({error:"Failed to fetch conversations"},{status:500});let h=(_||[]).map(e=>{let t=Array.isArray(e.sites)?e.sites[0]:e.sites,r=Array.isArray(t?.licenses)?t.licenses[0]:t?.licenses;return{id:e.id,conversation_id:e.conversation_id,site_id:e.site_id,visitor_id:e.visitor_id,started_at:e.started_at,last_message_at:e.last_message_at,message_count:e.message_count,created_at:e.created_at,site:t?{id:t.id,site_url:t.site_url,site_name:t.site_name,license_id:t.license_id,license:r||null}:null}}).filter(e=>null!==e.site);return d.Z.json({conversations:h})}catch(e){return console.error("Error in GET /api/admin/conversations:",e),d.Z.json({error:"Internal server error"},{status:500})}}let u=new s.AppRouteRouteModule({definition:{kind:i.x.APP_ROUTE,page:"/api/admin/conversations/route",pathname:"/api/admin/conversations",filename:"route",bundlePath:"app/api/admin/conversations/route"},resolvedPagePath:"C:\\xampp\\htdocs\\AI Woo Chat\\src\\app\\api\\admin\\conversations\\route.ts",nextConfigOutput:"standalone",userland:n}),{requestAsyncStorage:p,staticGenerationAsyncStorage:m,serverHooks:v,headerHooks:_,staticGenerationBailout:f}=u,h="/api/admin/conversations/route";function g(){return(0,o.patchFetch)({serverHooks:v,staticGenerationAsyncStorage:m})}},9829:(e,t,r)=>{r.d(t,{j:()=>s});var n=r(2509);async function s(e){try{let t=(0,n.createAdminClient)(),{data:r,error:s}=await t.from("platform_users").select("role").eq("user_id",e).eq("role","super_admin").single();if(s||!r)return!1;return"super_admin"===r.role}catch(e){return console.error("Error checking super admin status:",e),!1}}},2509:(e,t,r)=>{r.d(t,{createAdminClient:()=>a,e:()=>o});var n=r(6874),s=r(7439),i=r(3950);async function o(){let e=await (0,s.cookies)();return(0,n.lx)("https://drmuwsxyvvfivdfsyydy.supabase.co","eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImRybXV3c3h5dnZmaXZkZnN5eWR5Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njg0NjAwMDgsImV4cCI6MjA4NDAzNjAwOH0.kMsFG-VLNqwzIgl3cFW-owiRCWHcB47M6V6Ti4O4alY",{cookies:{get:t=>e.get(t)?.value,set(t,r,n){try{e.set({name:t,value:r,...n})}catch(e){}},remove(t,r){try{e.set({name:t,value:"",...r})}catch(e){}}}})}function a(){return(0,i.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:()=>o});var n=r(7147),s=r(1017);let i=!1;function o(){if(!i)try{let e=process.cwd(),t=[(0,s.join)(e,".env.production"),(0,s.join)(e,"..",".env.production"),(0,s.join)(e,"..","..",".env.production"),(0,s.join)(e,"app",".env.production")],r=null,o=null;for(let e of t)try{o=(0,n.readFileSync)(e,"utf-8"),r=e,console.log("[EnvLoader] Found .env.production at:",e);break}catch{continue}if(!o||!r)throw Error(`Could not find .env.production. Tried: ${t.join(", ")}`);for(let e of o.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)}}i=!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),n=t.X(0,[1638,9989,6206],()=>r(2366));module.exports=n})();