'use client'; import { useEffect } from 'react'; import Link from 'next/link'; import Image from 'next/image'; import type { ShareType, SongShareContent, PlaylistShareContent, AlbumShareContent } from '@/types/api-types'; interface SharedContentDisplayProps { type: ShareType; content: SongShareContent | PlaylistShareContent | AlbumShareContent; token: string; } export function SharedContentDisplay({ type, content, token }: SharedContentDisplayProps) { // Track click on mount useEffect(() => { fetch(`/api/share/${token}/click`, { method: 'POST' }).catch(() => {}); }, [token]); const getCoverUrl = () => { if (type === 'SONG') return (content as SongShareContent).coverArtUrl; if (type === 'PLAYLIST') return (content as PlaylistShareContent).coverImageUrl; return (content as AlbumShareContent).coverArtUrl; }; const getTitle = () => { if (type === 'SONG') return (content as SongShareContent).title; if (type === 'PLAYLIST') return (content as PlaylistShareContent).name; return (content as AlbumShareContent).title; }; const getSubtitle = () => { if (type === 'SONG') return (content as SongShareContent).artist.stage_name; if (type === 'PLAYLIST') return `by ${(content as PlaylistShareContent).curator.name}`; return (content as AlbumShareContent).artist.stage_name; }; const getLink = () => { if (type === 'SONG') return `/song/${content.id}`; if (type === 'PLAYLIST') return `/playlist/${content.id}`; return `/album/${content.id}`; }; const typeLabel = type === 'SONG' ? 'Song' : type === 'PLAYLIST' ? 'Playlist' : 'Album'; const coverUrl = getCoverUrl(); return (
{/* Cover Art */}
{coverUrl ? ( {getTitle()} ) : (
)}
{/* Type Badge */} {typeLabel} {/* Title */}

{getTitle()}

{/* Subtitle */}

{getSubtitle()}

{/* Song count for playlists/albums */} {type !== 'SONG' && (

{type === 'PLAYLIST' ? `${(content as PlaylistShareContent).songCount} songs` : `${(content as AlbumShareContent).songs?.length || 0} tracks` }

)} {/* CTA Button */} Listen on Sonic Cloud {/* Sign up CTA */}

Don't have an account?{' '} Sign up free

); }