'use client';
import {useState} from 'react';
import {Smartphone,Monitor,ExternalLink} from 'lucide-react';
import Link from 'next/link';
import type {LarpTemplate} from '@/lib/catalog';
import {AppUiFrame} from '@/components/app-ui-frame';
import {Button} from '@/components/ui/button';
/** Project-specific viewer: the saved app UI, never a generic placeholder. */
export function LiveProjectViewer({template,projectId}:{template:LarpTemplate;projectId:string}){
 const [device,setDevice]=useState<'phone'|'desktop'>('phone');
 return <section className="rounded-2xl border bg-muted/20 p-3 md:p-5 space-y-4">
  <div className="flex flex-wrap gap-2 items-center justify-between">
   <div><h2 className="font-bold">Your saved {template.name} LARP</h2><p className="text-xs text-muted-foreground">Private view tied to your account · edits are managed in Settings</p></div>
   <div className="flex gap-2 flex-wrap items-center"><Button size="sm" asChild><Link href={`/preview/${template.slug}?device=${device}&project=${encodeURIComponent(projectId)}`} target="_blank" rel="noopener noreferrer"><ExternalLink size={14}/> Pop out full tab</Link></Button>{template.slug==='cash-app'&&<div className="flex gap-2"><Button size="sm" variant={device==='phone'?'gradient':'outline'} onClick={()=>setDevice('phone')}><Smartphone size={15}/>Phone</Button><Button size="sm" variant={device==='desktop'?'gradient':'outline'} onClick={()=>setDevice('desktop')}><Monitor size={15}/>Desktop</Button></div>}</div>
  </div>
  <AppUiFrame template={template} projectId={projectId} phone={device==='phone'}/>
 </section>;
}
