"use strict";(()=>{var e={};e.id=374,e.ids=[374],e.modules={846:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},4870:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},3295:e=>{e.exports=require("next/dist/server/app-render/after-task-async-storage.external.js")},9294:e=>{e.exports=require("next/dist/server/app-render/work-async-storage.external.js")},3033:e=>{e.exports=require("next/dist/server/app-render/work-unit-async-storage.external.js")},9646:e=>{e.exports=require("child_process")},9748:e=>{e.exports=require("fs/promises")},1820:e=>{e.exports=require("os")},3873:e=>{e.exports=require("path")},8354:e=>{e.exports=require("util")},4250:(e,r,t)=>{t.r(r),t.d(r,{patchFetch:()=>w,routeModule:()=>g,serverHooks:()=>j,workAsyncStorage:()=>f,workUnitAsyncStorage:()=>m});var s={};t.r(s),t.d(s,{GET:()=>d,POST:()=>x});var a=t(2706),n=t(8203),o=t(5994),i=t(9187),p=t(9269),u=t(9748),c=t(3873),l=t(1820);async function d(e){let r=e.nextUrl.searchParams,t=r.get("deviceId"),s=r.get("packageName"),a=r.get("mode");if(!t)return i.NextResponse.json({error:"Device ID is required"},{status:400});try{let e=p.J.getInstance();if(s){let r=await e.getAppInfo(t,s);return i.NextResponse.json({details:r})}let r="basic"===a?await e.getBasicAppList(t):await e.getInstalledApps(t);return i.NextResponse.json({apps:r})}catch(e){return console.error("Error fetching apps:",e),i.NextResponse.json({error:e instanceof Error?e.message:"Failed to fetch apps"},{status:500})}}async function x(e){let r=await e.formData(),t=r.get("deviceId"),s=r.get("action");if(!t)return i.NextResponse.json({error:"Device ID is required"},{status:400});let a=p.J.getInstance();try{switch(s){case"install":{let e=r.get("apkFile");if(!e)return i.NextResponse.json({error:"APK file is required"},{status:400});let s=Buffer.from(await e.arrayBuffer()),n=(0,c.join)((0,l.tmpdir)(),e.name);return await (0,u.writeFile)(n,s),await a.installApp(t,n),await (0,u.unlink)(n),i.NextResponse.json({success:!0})}case"uninstall":{let e=r.get("packageName");if(!e)return i.NextResponse.json({error:"Package name is required"},{status:400});return await a.uninstallApp(t,e),i.NextResponse.json({success:!0})}case"clear":{let e=r.get("packageName");if(!e)return i.NextResponse.json({error:"Package name is required"},{status:400});return await a.clearAppData(t,e),i.NextResponse.json({success:!0})}case"force-stop":{let e=r.get("packageName");if(!e)return i.NextResponse.json({error:"Package name is required"},{status:400});return await a.forceStopApp(t,e),i.NextResponse.json({success:!0})}default:return i.NextResponse.json({error:"Invalid action specified"},{status:400})}}catch(e){return console.error("Error handling app operation:",e),i.NextResponse.json({error:e instanceof Error?e.message:"Operation failed"},{status:500})}}let g=new a.AppRouteRouteModule({definition:{kind:n.RouteKind.APP_ROUTE,page:"/api/apps/route",pathname:"/api/apps",filename:"route",bundlePath:"app/api/apps/route"},resolvedPagePath:"/Users/saleeh/codes/appmaker/adb-web/src/app/api/apps/route.ts",nextConfigOutput:"",userland:s}),{workAsyncStorage:f,workUnitAsyncStorage:m,serverHooks:j}=g;function w(){return(0,o.patchFetch)({workAsyncStorage:f,workUnitAsyncStorage:m})}}};var r=require("../../../webpack-runtime.js");r.C(e);var t=e=>r(r.s=e),s=r.X(0,[994,452,577],()=>t(4250));module.exports=s})();