'use client';
import useSWR from 'swr';
const fetcher = (u:string)=>fetch(u).then(r=>r.json());
export default function AdSlot({ position }:{ position:string }){
  const { data } = useSWR(`/api/v1/ads/slots?position=${position}`, fetcher);
  if (!data?.creative) return null;
  const c = data.creative as { html?: string; imageUrl?: string; linkUrl?: string; title?: string };
  if (c.html) return <div dangerouslySetInnerHTML={{ __html: c.html }} />;
  if (c.imageUrl) return <a href={c.linkUrl ?? '#'} target="_blank"><img src={c.imageUrl} alt={c.title ?? 'ad'} /></a>;
  return null;
}
