"use strict";(()=>{var e={};e.id=5998,e.ids=[5998],e.modules={72934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},54580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},45869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},78893:e=>{e.exports=require("buffer")},84770:e=>{e.exports=require("crypto")},76162:e=>{e.exports=require("stream")},21764:e=>{e.exports=require("util")},2727:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>P,patchFetch:()=>S,requestAsyncStorage:()=>v,routeModule:()=>y,serverHooks:()=>q,staticGenerationAsyncStorage:()=>w});var n={};r.r(n),r.d(n,{POST:()=>h});var s=r(49303),i=r(88716),a=r(60670),o=r(87070),u=r(95456);let p=require("@aws-sdk/client-s3"),c=new p.S3Client({region:process.env.S3_REGION||"idn",endpoint:process.env.S3_ENDPOINT,credentials:{accessKeyId:process.env.S3_ACCESS_KEY||"",secretAccessKey:process.env.S3_SECRET_KEY||""},forcePathStyle:!0}),l=process.env.S3_BUCKET||"restomenu",d=process.env.S3_PUBLIC_URL||"https://nos.wjv-1.neo.id/restomenu";async function m(e,t,r){let n=new p.PutObjectCommand({Bucket:l,Key:t,Body:e,ContentType:r,ACL:"public-read"});return await c.send(n),`${d}/${t}`}let f=require("sharp");var g=r.n(f);let x={maxWidth:800,maxHeight:800,quality:80};async function h(e){try{let t=await (0,u.ts)();if(!t)return o.NextResponse.json({error:"Unauthorized"},{status:401});let r=(await e.formData()).get("file");if(!r)return o.NextResponse.json({error:"File tidak ditemukan"},{status:400});if(!["image/jpeg","image/png","image/webp","image/gif"].includes(r.type))return o.NextResponse.json({error:"Tipe file tidak didukung. Gunakan JPG, PNG, WebP, atau GIF."},{status:400});if(r.size>5242880)return o.NextResponse.json({error:"Ukuran file melebihi 5MB"},{status:400});let n=await r.arrayBuffer(),s=Buffer.from(n),i=await g()(s).resize(x.maxWidth,x.maxHeight,{fit:"inside",withoutEnlargement:!0}).webp({quality:x.quality}).toBuffer(),a=`${Date.now()}-${Math.random().toString(36).substring(2,8)}.webp`,p=`${t.tenantId}/foto_produk/${a}`,c=await m(i,p,"image/webp");return o.NextResponse.json({url:c,optimized:{originalSize:r.size,optimizedSize:i.length,savedPercent:Math.round((1-i.length/r.size)*100)}})}catch(e){return console.error("Upload error:",e),o.NextResponse.json({error:"Gagal mengupload file"},{status:500})}}let y=new s.AppRouteRouteModule({definition:{kind:i.x.APP_ROUTE,page:"/api/upload/route",pathname:"/api/upload",filename:"route",bundlePath:"app/api/upload/route"},resolvedPagePath:"D:\\PROJECT\\resto-saas\\src\\app\\api\\upload\\route.ts",nextConfigOutput:"",userland:n}),{requestAsyncStorage:v,staticGenerationAsyncStorage:w,serverHooks:q}=y,P="/api/upload/route";function S(){return(0,a.patchFetch)({serverHooks:q,staticGenerationAsyncStorage:w})}},95456:(e,t,r)=>{r.d(t,{Gv:()=>l,MH:()=>g,PT:()=>x,RA:()=>d,WX:()=>m,c_:()=>c,ts:()=>f});var n=r(41482),s=r.n(n),i=r(42023),a=r.n(i),o=r(71615),u=r(8194);let p=process.env.JWT_SECRET||"fallback-secret-change-me";async function c(e){return a().hash(e,12)}async function l(e,t){return a().compare(e,t)}function d(e){return s().sign(e,p,{expiresIn:"7d"})}function m(e){try{return s().verify(e,p)}catch{return null}}async function f(){let e=await (0,o.cookies)(),t=e.get("token")?.value;if(!t)return null;let r=m(t);return r?await u._.user.findUnique({where:{id:r.userId},include:{tenant:!0,store:!0}}):null}function g(e,t){return t.includes(e)}function x(e){return!["owner","admin"].includes(e.role)&&!!e.storeId&&!!e.store&&!e.store.isActive}},8194:(e,t,r)=>{r.d(t,{_:()=>s});let n=require("@prisma/client"),s=globalThis.prisma??new n.PrismaClient}};var t=require("../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),n=t.X(0,[8948,5972,4261,2023],()=>r(2727));module.exports=n})();