"use strict";(()=>{var e={};e.id=9533,e.ids=[9533],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")},3902:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>x,patchFetch:()=>y,requestAsyncStorage:()=>h,routeModule:()=>g,serverHooks:()=>f,staticGenerationAsyncStorage:()=>m});var s={};r.r(s),r.d(s,{DELETE:()=>d,GET:()=>l,PATCH:()=>c});var o=r(9303),n=r(8716),a=r(670),i=r(7070),u=r(5655),p=r(987);async function l(e){let t=(0,u.e)(),{data:{user:r}}=await t.auth.getUser();if(!r)return i.NextResponse.json({error:"Unauthorized"},{status:401});let{searchParams:s}=new URL(e.url),o=s.get("type"),n=s.get("platform"),a="true"===s.get("favorites"),p=Math.max(1,parseInt(s.get("page")??"1")),l=Math.min(100,Math.max(1,parseInt(s.get("limit")??"20"))),c=(p-1)*l;if("ugc"===o){let e="true"===s.get("favorites"),o=t.from("ugc_history").select("*",{count:"exact"}).eq("user_id",r.id).order("created_at",{ascending:!1}).range(c,c+l-1);n&&(o=o.eq("platform",n)),e&&(o=o.eq("is_favorite",!0));let{data:a,error:u,count:d}=await o;return u?i.NextResponse.json({error:u.message},{status:500}):i.NextResponse.json({data:a,count:d,page:p,limit:l})}let d=t.from("prompt_history").select("*",{count:"exact"}).eq("user_id",r.id).order("created_at",{ascending:!1}).range(c,c+l-1);n&&(d=d.eq("platform",n)),a&&(d=d.eq("is_favorite",!0));let{data:g,error:h,count:m}=await d;return h?i.NextResponse.json({error:h.message},{status:500}):i.NextResponse.json({data:g,count:m,page:p,limit:l})}async function c(e){if(!(0,p._)(e))return i.NextResponse.json((0,p.E)(),{status:403});let t=(0,u.e)(),{data:{user:r}}=await t.auth.getUser();if(!r)return i.NextResponse.json({error:"Unauthorized"},{status:401});let s=await e.json();if(!s.id)return i.NextResponse.json({error:"ID required"},{status:400});let o={};if(void 0!==s.is_favorite&&(o.is_favorite=s.is_favorite),void 0!==s.title&&(o.title=s.title||null),void 0!==s.tags&&(o.tags=s.tags??null),0===Object.keys(o).length)return i.NextResponse.json({error:"Tidak ada field yang diupdate"},{status:400});let n="ugc"===s.type?"ugc_history":"prompt_history",{data:a,error:l}=await t.from(n).update(o).eq("id",s.id).eq("user_id",r.id).select().single();return l?i.NextResponse.json({error:l.message},{status:500}):i.NextResponse.json({data:a})}async function d(e){if(!(0,p._)(e))return i.NextResponse.json((0,p.E)(),{status:403});let t=(0,u.e)(),{data:{user:r}}=await t.auth.getUser();if(!r)return i.NextResponse.json({error:"Unauthorized"},{status:401});let{searchParams:s}=new URL(e.url),o=s.get("id"),n=s.get("type");if(!o)return i.NextResponse.json({error:"ID required"},{status:400});let{error:a}=await t.from("ugc"===n?"ugc_history":"prompt_history").delete().eq("id",o).eq("user_id",r.id);return a?i.NextResponse.json({error:a.message},{status:500}):i.NextResponse.json({success:!0})}let g=new o.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/history/route",pathname:"/api/history",filename:"route",bundlePath:"app/api/history/route"},resolvedPagePath:"/home/user/.workspace/projects/promptmotion-ai/src/app/api/history/route.ts",nextConfigOutput:"",userland:s}),{requestAsyncStorage:h,staticGenerationAsyncStorage:m,serverHooks:f}=g,x="/api/history/route";function y(){return(0,a.patchFetch)({serverHooks:f,staticGenerationAsyncStorage:m})}},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 o(){return{success:!1,error:"Forbidden: invalid request origin"}}r.d(t,{E:()=>o,_:()=>s})},5655:(e,t,r)=>{r.d(t,{e:()=>n});var s=r(5238),o=r(1615);function n(){let e=(0,o.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(3902));module.exports=s})();