"use strict";(()=>{var e={};e.id=608,e.ids=[608],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")},2963:(e,t,n)=>{n.r(t),n.d(t,{headerHooks:()=>f,originalPathname:()=>g,patchFetch:()=>y,requestAsyncStorage:()=>p,routeModule:()=>l,serverHooks:()=>v,staticGenerationAsyncStorage:()=>m,staticGenerationBailout:()=>h});var r={};n.r(r),n.d(r,{GET:()=>u});var o=n(5419),a=n(9108),s=n(9678),i=n(2509),c=n(9829),d=n(8070);async function u(){try{let e=await (0,i.e)(),{data:{user:t}}=await e.auth.getUser();if(!t)return d.Z.json({error:"Unauthorized"},{status:401});if(!await (0,c.j)(t.id))return d.Z.json({error:"Forbidden"},{status:403});let n=(0,i.createAdminClient)(),{data:r,error:o}=await n.from("tenants").select("id, name, slug, status").order("name",{ascending:!0});if(o)return console.error("Error fetching tenants:",o),d.Z.json({error:"Failed to fetch tenants"},{status:500});let a=await Promise.all((r||[]).map(async e=>{let{data:t}=await n.from("licenses").select("id").eq("tenant_id",e.id),r=t?.map(e=>e.id)||[];if(0===r.length)return{...e,conversation_count:0};let{data:o}=await n.from("sites").select("id").in("license_id",r),a=o?.map(e=>e.id)||[];if(0===a.length)return{...e,conversation_count:0};let{count:s}=await n.from("conversations").select("*",{count:"exact",head:!0}).in("site_id",a);return{...e,conversation_count:s||0}}));return d.Z.json({tenants:a})}catch(e){return console.error("Error in GET /api/admin/conversations/tenants:",e),d.Z.json({error:"Internal server error"},{status:500})}}let l=new o.AppRouteRouteModule({definition:{kind:a.x.APP_ROUTE,page:"/api/admin/conversations/tenants/route",pathname:"/api/admin/conversations/tenants",filename:"route",bundlePath:"app/api/admin/conversations/tenants/route"},resolvedPagePath:"C:\\xampp\\htdocs\\AI Woo Chat\\src\\app\\api\\admin\\conversations\\tenants\\route.ts",nextConfigOutput:"standalone",userland:r}),{requestAsyncStorage:p,staticGenerationAsyncStorage:m,serverHooks:v,headerHooks:f,staticGenerationBailout:h}=l,g="/api/admin/conversations/tenants/route";function y(){return(0,s.patchFetch)({serverHooks:v,staticGenerationAsyncStorage:m})}},9829:(e,t,n)=>{n.d(t,{j:()=>o});var r=n(2509);async function o(e){try{let t=(0,r.createAdminClient)(),{data:n,error:o}=await t.from("platform_users").select("role").eq("user_id",e).eq("role","super_admin").single();if(o||!n)return!1;return"super_admin"===n.role}catch(e){return console.error("Error checking super admin status:",e),!1}}},2509:(e,t,n)=>{n.d(t,{createAdminClient:()=>i,e:()=>s});var r=n(6874),o=n(7439),a=n(3950);async function s(){let e=await (0,o.cookies)();return(0,r.lx)("https://drmuwsxyvvfivdfsyydy.supabase.co","eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImRybXV3c3h5dnZmaXZkZnN5eWR5Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njg0NjAwMDgsImV4cCI6MjA4NDAzNjAwOH0.kMsFG-VLNqwzIgl3cFW-owiRCWHcB47M6V6Ti4O4alY",{cookies:{get:t=>e.get(t)?.value,set(t,n,r){try{e.set({name:t,value:n,...r})}catch(e){}},remove(t,n){try{e.set({name:t,value:"",...n})}catch(e){}}}})}function i(){return(0,a.eI)("https://drmuwsxyvvfivdfsyydy.supabase.co",process.env.SUPABASE_SERVICE_ROLE_KEY,{auth:{autoRefreshToken:!1,persistSession:!1}})}(0,n(4113).C)()},4113:(e,t,n)=>{n.d(t,{C:()=>s});var r=n(7147),o=n(1017);let a=!1;function s(){if(!a)try{let e=process.cwd(),t=[(0,o.join)(e,".env.production"),(0,o.join)(e,"..",".env.production"),(0,o.join)(e,"..","..",".env.production"),(0,o.join)(e,"app",".env.production")],n=null,s=null;for(let e of t)try{s=(0,r.readFileSync)(e,"utf-8"),n=e,console.log("[EnvLoader] Found .env.production at:",e);break}catch{continue}if(!s||!n)throw Error(`Could not find .env.production. Tried: ${t.join(", ")}`);for(let e of s.split("\n")){let t=e.trim();if(!t||t.startsWith("#"))continue;let n=t.match(/^([^=]+)=(.*)$/);if(n){let e=n[1].trim(),t=n[2].trim();(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'"))&&(t=t.slice(1,-1)),process.env[e]||(process.env[e]=t)}}a=!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 n=e=>t(t.s=e),r=t.X(0,[1638,9989,6206],()=>n(2963));module.exports=r})();