"use strict";(()=>{var e={};e.id=6553,e.ids=[6553],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")},399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},8867:(e,t,a)=>{a.r(t),a.d(t,{originalPathname:()=>g,patchFetch:()=>h,requestAsyncStorage:()=>u,routeModule:()=>d,serverHooks:()=>f,staticGenerationAsyncStorage:()=>m});var r={};a.r(r),a.d(r,{GET:()=>p});var o=a(9303),s=a(8716),n=a(670),i=a(7070),c=a(5655);async function l(e){let{data:{user:t},error:a}=await e.auth.getUser();if(a||!t)return null;let{data:r}=await e.from("profiles").select("role").eq("id",t.id).single();return r?.role!=="admin"?null:t}async function p(){let e=(0,c.e)();if(!await l(e))return i.NextResponse.json({error:"Forbidden"},{status:403});let t=new Date,a=new Date(t.getFullYear(),t.getMonth(),t.getDate()).toISOString(),r=new Date(t.getTime()-6048e5).toISOString(),o=new Date(t.getTime()-12096e5).toISOString(),[{count:s},{count:n},{count:p},{count:d},{count:u},{count:m},{data:f},{data:g},{data:h}]=await Promise.all([e.from("profiles").select("id",{count:"exact",head:!0}),e.from("profiles").select("id",{count:"exact",head:!0}).gte("created_at",a),e.from("profiles").select("id",{count:"exact",head:!0}).gte("created_at",r),e.from("prompt_history").select("id",{count:"exact",head:!0}),e.from("prompt_history").select("id",{count:"exact",head:!0}).gte("created_at",a),e.from("prompt_history").select("id",{count:"exact",head:!0}).gte("created_at",r),e.from("prompt_history").select("platform"),e.from("prompt_history").select("created_at, platform").gte("created_at",o).order("created_at",{ascending:!0}),e.from("profiles").select("id, email, full_name, usage_count, plan, role").order("usage_count",{ascending:!1}).limit(5)]),x={};(f??[]).forEach(e=>{x[e.platform]=(x[e.platform]??0)+1});let _={};(g??[]).forEach(e=>{let t=e.created_at.slice(0,10);_[t]||(_[t]={date:t,count:0,platforms:{}}),_[t].count++,_[t].platforms[e.platform]=(_[t].platforms[e.platform]??0)+1});let y=[];for(let e=13;e>=0;e--){let a=new Date(t.getTime()-864e5*e).toISOString().slice(0,10);y.push(_[a]??{date:a,count:0,platforms:{}})}return i.NextResponse.json({users:{total:s??0,new_today:n??0,new_7d:p??0},generations:{total:d??0,today:u??0,last_7d:m??0},per_platform:x,chart:y,top_users:h??[],fetched_at:new Date().toISOString()})}let d=new o.AppRouteRouteModule({definition:{kind:s.x.APP_ROUTE,page:"/api/admin/stats/route",pathname:"/api/admin/stats",filename:"route",bundlePath:"app/api/admin/stats/route"},resolvedPagePath:"/home/user/.workspace/projects/promptmotion-ai/src/app/api/admin/stats/route.ts",nextConfigOutput:"",userland:r}),{requestAsyncStorage:u,staticGenerationAsyncStorage:m,serverHooks:f}=d,g="/api/admin/stats/route";function h(){return(0,n.patchFetch)({serverHooks:f,staticGenerationAsyncStorage:m})}},5655:(e,t,a)=>{a.d(t,{e:()=>s});var r=a(5238),o=a(1615);function s(){let e=(0,o.cookies)();return(0,r.l)("https://dummy.supabase.co","eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.dummy",{cookies:{getAll:()=>e.getAll(),setAll(t){try{t.forEach(({name:t,value:a,options:r})=>e.set(t,a,r))}catch{}}}})}}};var t=require("../../../../webpack-runtime.js");t.C(e);var a=e=>t(t.s=e),r=t.X(0,[9276,6164,5972],()=>a(8867));module.exports=r})();