"use strict";(()=>{var e={};e.id=2628,e.ids=[2628],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")},4341:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>x,patchFetch:()=>j,requestAsyncStorage:()=>g,routeModule:()=>m,serverHooks:()=>h,staticGenerationAsyncStorage:()=>f});var s={};r.r(s),r.d(s,{GET:()=>d,PATCH:()=>c});var n=r(9303),a=r(8716),i=r(670),o=r(7070),u=r(5655),l=r(987);async function p(e){let{data:{user:t},error:r}=await e.auth.getUser();if(r||!t)return null;let{data:s}=await e.from("profiles").select("role").eq("id",t.id).single();return s?.role!=="admin"?null:t}async function d(e){let t=(0,u.e)();if(!await p(t))return o.NextResponse.json({error:"Forbidden"},{status:403});let{searchParams:r}=new URL(e.url),s=parseInt(r.get("page")??"1"),n=parseInt(r.get("limit")??"50"),a=r.get("search")??"",i=(s-1)*n,l=t.from("profiles").select("*",{count:"exact"}).order("created_at",{ascending:!1}).range(i,i+n-1);a&&(l=l.or(`email.ilike.%${a}%,full_name.ilike.%${a}%`));let{data:d,error:c,count:m}=await l;if(c)return o.NextResponse.json({error:c.message},{status:500});let g=(d??[]).map(e=>e.id),f={};if(g.length>0){let{data:e}=await t.from("prompt_history").select("user_id").in("user_id",g);f=(e??[]).reduce((e,t)=>(e[t.user_id]=(e[t.user_id]??0)+1,e),{})}let h=(d??[]).map(e=>({...e,total_generations:f[e.id]??0}));return o.NextResponse.json({data:h,count:m,page:s,limit:n})}async function c(e){if(!(0,l._)(e))return o.NextResponse.json((0,l.E)(),{status:403});let t=(0,u.e)();if(!await p(t))return o.NextResponse.json({error:"Forbidden"},{status:403});let r=await e.json();if(!r.id)return o.NextResponse.json({error:"User ID required"},{status:400});let s={};if(void 0!==r.role&&(s.role=r.role),void 0!==r.plan&&(s.plan=r.plan),void 0!==r.usage_limit&&(s.usage_limit=r.usage_limit),0===Object.keys(s).length)return o.NextResponse.json({error:"No fields to update"},{status:400});let{data:n,error:a}=await t.from("profiles").update(s).eq("id",r.id).select().single();return a?o.NextResponse.json({error:a.message},{status:500}):o.NextResponse.json({data:n})}let m=new n.AppRouteRouteModule({definition:{kind:a.x.APP_ROUTE,page:"/api/admin/users/route",pathname:"/api/admin/users",filename:"route",bundlePath:"app/api/admin/users/route"},resolvedPagePath:"/home/user/.workspace/projects/promptmotion-ai/src/app/api/admin/users/route.ts",nextConfigOutput:"",userland:s}),{requestAsyncStorage:g,staticGenerationAsyncStorage:f,serverHooks:h}=m,x="/api/admin/users/route";function j(){return(0,i.patchFetch)({serverHooks:h,staticGenerationAsyncStorage:f})}},987:(e,t,r)=>{function s(e){let t=e.headers.get("origin");if(!t)return!0;let r="http://localhost:3000";if(new Set([r,"http://localhost:3000","http://localhost:3001","http://127.0.0.1:3000"].filter(Boolean)).has(t))return!0;try{let e=new URL(t).hostname,s=r?new URL(r).hostname:"";if(s&&(e===s||e.endsWith(`.${s}`)))return!0}catch{}return!1}function n(){return{success:!1,error:"Forbidden: invalid request origin"}}r.d(t,{E:()=>n,_:()=>s})},5655:(e,t,r)=>{r.d(t,{e:()=>a});var s=r(5238),n=r(1615);function a(){let e=(0,n.cookies)();return(0,s.l)("https://dummy.supabase.co","eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.dummy",{cookies:{getAll:()=>e.getAll(),setAll(t){try{t.forEach(({name:t,value:r,options:s})=>e.set(t,r,s))}catch{}}}})}}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),s=t.X(0,[9276,6164,5972],()=>r(4341));module.exports=s})();