"use strict";(()=>{var e={};e.id=1996,e.ids=[1996],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")},5453:(e,t,i)=>{i.r(t),i.d(t,{headerHooks:()=>m,originalPathname:()=>h,patchFetch:()=>y,requestAsyncStorage:()=>u,routeModule:()=>c,serverHooks:()=>p,staticGenerationAsyncStorage:()=>_,staticGenerationBailout:()=>g});var s={};i.r(s),i.d(s,{GET:()=>d});var a=i(5419),r=i(9108),n=i(9678),o=i(8070),l=i(2509);async function d(){try{let e=await (0,l.e)(),{data:{user:t},error:i}=await e.auth.getUser();if(i||!t)return o.Z.json({error:{code:"UNAUTHORIZED",message:"Authentication required"}},{status:401});let{data:s,error:a}=await e.from("user_tenants").select("tenant_id").eq("user_id",t.id).limit(1).single();if(a||!s)return o.Z.json({notifications:[]});let r=(0,l.createAdminClient)(),n=[],{data:d,error:c}=await r.from("sites").select(`
        id,
        site_url,
        site_name,
        status,
        last_paired_at,
        license:licenses (
          id,
          license_key,
          status,
          expires_at,
          plan_limits
        )
      `).eq("tenant_id",s.tenant_id);if(c)throw c;let u=new Date,_=new Date(u.getTime()+2592e6);for(let e of d||[]){let t=e.license;if(t?.expires_at){let i=new Date(t.expires_at);if(i<u)n.push({id:`license_expired_${e.id}`,type:"license_expired",severity:"error",title:"License Expired",message:`License for ${e.site_name||e.site_url} has expired. Please renew to continue service.`,action_url:"/dashboard/sites",action_label:"View Sites",created_at:i.toISOString()});else if(i<_){let t=Math.ceil((i.getTime()-u.getTime())/864e5);n.push({id:`license_expiring_${e.id}`,type:"license_expiring",severity:"warning",title:"License Expiring Soon",message:`License for ${e.site_name||e.site_url} expires in ${t} day${1!==t?"s":""}.`,action_url:"/dashboard/sites",action_label:"View Sites",created_at:u.toISOString()})}}if((t?.status==="expired"||t?.status==="revoked")&&n.push({id:`license_status_${e.id}`,type:"expired"===t.status?"license_expired":"license_expiring",severity:"error",title:`License ${"expired"===t.status?"Expired":"Revoked"}`,message:`License for ${e.site_name||e.site_url} is ${t.status}.`,action_url:"/dashboard/sites",action_label:"View Sites",created_at:u.toISOString()}),"disabled"===e.status&&n.push({id:`site_disabled_${e.id}`,type:"site_disabled",severity:"warning",title:"Site Disabled",message:`${e.site_name||e.site_url} is currently disabled.`,action_url:"/dashboard/sites",action_label:"View Sites",created_at:u.toISOString()}),"active"===e.status&&e.last_paired_at){let t=new Date(e.last_paired_at),i=new Date(u.getTime()-6048e5);t<i&&n.push({id:`site_inactive_${e.id}`,type:"site_inactive",severity:"info",title:"Site Inactive",message:`${e.site_name||e.site_url} has had no activity in the last 7 days.`,action_url:"/dashboard/sites",action_label:"View Sites",created_at:u.toISOString()})}if(t?.plan_limits){let i=t.plan_limits,s=new Date;if(s.setHours(0,0,0,0),s.toISOString(),i.max_tokens_per_day){let{data:t,error:a}=await r.from("usage_daily").select("total_tokens").eq("site_id",e.id).eq("date",s.toISOString().split("T")[0]).single();if(!a&&t){let s=t.total_tokens||0,a=i.max_tokens_per_day,r=s/a*100;r>=100?n.push({id:`usage_limit_tokens_${e.id}`,type:"usage_limit",severity:"error",title:"Token Limit Reached",message:`${e.site_name||e.site_url} has reached its daily token limit (${a.toLocaleString()}).`,action_url:`/dashboard/analytics?site_id=${e.id}`,action_label:"View Analytics",created_at:u.toISOString()}):r>=80&&n.push({id:`usage_warning_tokens_${e.id}`,type:"usage_limit",severity:"warning",title:"Token Limit Warning",message:`${e.site_name||e.site_url} has used ${r.toFixed(0)}% of its daily token limit.`,action_url:`/dashboard/analytics?site_id=${e.id}`,action_label:"View Analytics",created_at:u.toISOString()})}}if(i.max_chat_requests_per_day){let{data:t,error:a}=await r.from("usage_daily").select("chat_requests").eq("site_id",e.id).eq("date",s.toISOString().split("T")[0]).single();if(!a&&t){let s=t.chat_requests||0,a=i.max_chat_requests_per_day,r=s/a*100;r>=100?n.push({id:`usage_limit_requests_${e.id}`,type:"usage_limit",severity:"error",title:"Request Limit Reached",message:`${e.site_name||e.site_url} has reached its daily request limit (${a.toLocaleString()}).`,action_url:`/dashboard/analytics?site_id=${e.id}`,action_label:"View Analytics",created_at:u.toISOString()}):r>=80&&n.push({id:`usage_warning_requests_${e.id}`,type:"usage_limit",severity:"warning",title:"Request Limit Warning",message:`${e.site_name||e.site_url} has used ${r.toFixed(0)}% of its daily request limit.`,action_url:`/dashboard/analytics?site_id=${e.id}`,action_label:"View Analytics",created_at:u.toISOString()})}}}}return n.sort((e,t)=>{let i={error:0,warning:1,info:2},s=i[e.severity]-i[t.severity];return 0!==s?s:new Date(t.created_at).getTime()-new Date(e.created_at).getTime()}),o.Z.json({notifications:n,unread_count:n.length})}catch(e){return console.error("Notifications GET error:",e),o.Z.json({error:{code:"INTERNAL_ERROR",message:e instanceof Error?e.message:"Failed to fetch notifications"}},{status:500})}}let c=new a.AppRouteRouteModule({definition:{kind:r.x.APP_ROUTE,page:"/api/notifications/route",pathname:"/api/notifications",filename:"route",bundlePath:"app/api/notifications/route"},resolvedPagePath:"C:\\xampp\\htdocs\\AI Woo Chat\\src\\app\\api\\notifications\\route.ts",nextConfigOutput:"standalone",userland:s}),{requestAsyncStorage:u,staticGenerationAsyncStorage:_,serverHooks:p,headerHooks:m,staticGenerationBailout:g}=c,h="/api/notifications/route";function y(){return(0,n.patchFetch)({serverHooks:p,staticGenerationAsyncStorage:_})}},2509:(e,t,i)=>{i.d(t,{createAdminClient:()=>o,e:()=>n});var s=i(6874),a=i(7439),r=i(3950);async function n(){let e=await (0,a.cookies)();return(0,s.lx)("https://drmuwsxyvvfivdfsyydy.supabase.co","eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImRybXV3c3h5dnZmaXZkZnN5eWR5Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njg0NjAwMDgsImV4cCI6MjA4NDAzNjAwOH0.kMsFG-VLNqwzIgl3cFW-owiRCWHcB47M6V6Ti4O4alY",{cookies:{get:t=>e.get(t)?.value,set(t,i,s){try{e.set({name:t,value:i,...s})}catch(e){}},remove(t,i){try{e.set({name:t,value:"",...i})}catch(e){}}}})}function o(){return(0,r.eI)("https://drmuwsxyvvfivdfsyydy.supabase.co",process.env.SUPABASE_SERVICE_ROLE_KEY,{auth:{autoRefreshToken:!1,persistSession:!1}})}(0,i(4113).C)()},4113:(e,t,i)=>{i.d(t,{C:()=>n});var s=i(7147),a=i(1017);let r=!1;function n(){if(!r)try{let e=process.cwd(),t=[(0,a.join)(e,".env.production"),(0,a.join)(e,"..",".env.production"),(0,a.join)(e,"..","..",".env.production"),(0,a.join)(e,"app",".env.production")],i=null,n=null;for(let e of t)try{n=(0,s.readFileSync)(e,"utf-8"),i=e,console.log("[EnvLoader] Found .env.production at:",e);break}catch{continue}if(!n||!i)throw Error(`Could not find .env.production. Tried: ${t.join(", ")}`);for(let e of n.split("\n")){let t=e.trim();if(!t||t.startsWith("#"))continue;let i=t.match(/^([^=]+)=(.*)$/);if(i){let e=i[1].trim(),t=i[2].trim();(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'"))&&(t=t.slice(1,-1)),process.env[e]||(process.env[e]=t)}}r=!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 i=e=>t(t.s=e),s=t.X(0,[1638,9989,6206],()=>i(5453));module.exports=s})();