76 lines
1.9 KiB
TypeScript
76 lines
1.9 KiB
TypeScript
"use client";
|
|
|
|
import { ExternalLink } from "lucide-react";
|
|
import { getMediaUrl } from "@/lib/media-url";
|
|
|
|
type AdCardAd = {
|
|
id: string;
|
|
title: string;
|
|
caption: string | null;
|
|
targetUrl: string | null;
|
|
imageKey: string | null;
|
|
};
|
|
|
|
export function AdCard({ ad }: { ad: AdCardAd }) {
|
|
const imageUrl = getMediaUrl(ad.imageKey);
|
|
|
|
const inner = (
|
|
<div className="rounded-2xl border border-orange-200/20 bg-card overflow-hidden">
|
|
{/* Image */}
|
|
{imageUrl && (
|
|
// eslint-disable-next-line @next/next/no-img-element
|
|
<img
|
|
src={imageUrl}
|
|
alt={ad.title}
|
|
className="w-full object-cover max-h-80"
|
|
/>
|
|
)}
|
|
|
|
{/* Text area */}
|
|
<div className="px-4 py-3 flex flex-col gap-1.5">
|
|
{/* Sponsored badge row */}
|
|
<div className="flex items-center justify-between">
|
|
<span className="text-[10px] font-semibold uppercase tracking-widest text-orange-400 bg-orange-400/10 px-2 py-0.5 rounded-full">
|
|
Sponsored
|
|
</span>
|
|
{ad.targetUrl && (
|
|
<ExternalLink className="h-3.5 w-3.5 text-muted-foreground" />
|
|
)}
|
|
</div>
|
|
|
|
<p className="text-sm font-semibold text-foreground leading-snug">
|
|
{ad.title}
|
|
</p>
|
|
|
|
{ad.caption && (
|
|
<p className="text-sm text-muted-foreground leading-relaxed">
|
|
{ad.caption}
|
|
</p>
|
|
)}
|
|
|
|
{ad.targetUrl && (
|
|
<p className="text-xs text-orange-400/70 truncate mt-0.5">
|
|
{ad.targetUrl.replace(/^https?:\/\//, "")}
|
|
</p>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
|
|
if (ad.targetUrl) {
|
|
return (
|
|
<a
|
|
href={ad.targetUrl}
|
|
target="_blank"
|
|
rel="noopener noreferrer sponsored"
|
|
className="block no-underline hover:opacity-90 transition-opacity"
|
|
aria-label={`Gesponsert: ${ad.title}`}
|
|
>
|
|
{inner}
|
|
</a>
|
|
);
|
|
}
|
|
|
|
return inner;
|
|
}
|