import fs from 'node:fs';
import {headers} from 'next/headers';
import {NextRequest} from 'next/server';
import {notFound} from 'next/navigation';
import {isStudioAdmin,getStudioTemplates} from '@/lib/studio-store';
import path from 'node:path';
import {AppAssetBrowser,type CapturedAssetInfo} from '@/components/platform/app-asset-browser';
export const dynamic='force-dynamic';
export default async function AppAssets(){
 const h=await headers();
 const req=new NextRequest(process.env.APP_URL||'http://localhost:3000/app-assets',{headers:h});
 if(!isStudioAdmin(req))notFound();
 let m:Record<string,CapturedAssetInfo>={};
 try{m=JSON.parse(fs.readFileSync(path.join(process.cwd(),'app-uis','capture-manifest.json'),'utf8')) as typeof m}catch{}
 const catalog=getStudioTemplates();
 const assets=catalog.map(t=>({template:t,capture:m[t.slug]||{name:t.name,devices:{phone:false,desktop:false},media:{phone:[],desktop:[]},sourceFolders:[]}}));
 return <AppAssetBrowser assets={assets}/>;
}
