import React, { useMemo, useState } from 'react' import AuthorBioPopover from './AuthorBioPopover' import FollowButton from '../social/FollowButton' const AVATAR_FALLBACK = 'https://files.skinbase.org/default/missing_sq.webp' const NUMBER_FORMATTER = new Intl.NumberFormat('en-US') function formatCount(value) { const n = Number(value || 0) if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1).replace(/\.0$/, '')}M` if (n >= 1_000) return `${(n / 1_000).toFixed(1).replace(/\.0$/, '')}k` return `${n}` } function toCard(item) { return { id: item?.id || item?.slug || item?.url, title: item?.title, author: item?.author, authorId: Number(item?.author_id || 0), publisherType: item?.publisher_type || 'user', publisherId: Number(item?.publisher_id || 0), url: item?.url, thumb: item?.thumb, thumbSrcSet: item?.thumb_srcset, } } export default function CreatorSpotlight({ artwork, presentSq, related = [] }) { const publisher = artwork?.publisher || null const isGroupPublisher = publisher?.type === 'group' const [following, setFollowing] = useState(Boolean(isGroupPublisher ? artwork?.viewer?.is_following_group : artwork?.viewer?.is_following_author)) const [followersCount, setFollowersCount] = useState(Number(isGroupPublisher ? publisher?.followers_count || 0 : artwork?.user?.followers_count || 0)) const user = artwork?.credits?.primary_author || artwork?.user || {} const primaryAuthor = artwork?.credits?.primary_author || null const bioAuthor = isGroupPublisher ? primaryAuthor : user const isOwnArtwork = Number(artwork?.viewer?.id || 0) > 0 && Number(artwork?.viewer?.id) === Number(user.id || 0) const authorName = isGroupPublisher ? (publisher?.name || 'Group') : (user.name || user.username || 'Artist') const profileUrl = isGroupPublisher ? (publisher?.profile_url || '#') : (user.profile_url || (user.username ? `/@${user.username}` : '#')) const avatar = (isGroupPublisher ? publisher?.avatar_url : user.avatar_url) || presentSq?.url || AVATAR_FALLBACK const creatorItems = useMemo(() => { const currentAuthorId = Number(user?.id || 0) const currentPublisherId = Number(publisher?.id || user?.id || 0) const filtered = (Array.isArray(related) ? related : []).filter((item) => { const notCurrent = item?.url && item.url !== artwork?.canonical_url if (!notCurrent) { return false } if (isGroupPublisher) { return item?.publisher_type === 'group' && Number(item?.publisher_id || 0) === currentPublisherId } return Number(item?.author_id || 0) === currentAuthorId }) return filtered.slice(0, 12).map(toCard) }, [related, isGroupPublisher, publisher?.id, user?.id, artwork?.canonical_url]) return ( <>
{/* Avatar + info — stacked for sidebar */}
{authorName} { event.currentTarget.src = AVATAR_FALLBACK }} />
{authorName} {!isGroupPublisher && user.username ?

@{user.username}

: null} {isGroupPublisher && primaryAuthor ?

Primary author: {primaryAuthor.name || primaryAuthor.username}

: null} {bioAuthor?.username ? ( ) : null}

{NUMBER_FORMATTER.format(followersCount)} Followers

{/* Profile + Follow buttons */}
Profile {!isOwnArtwork && !isGroupPublisher ? ( { setFollowing(nextFollowing) setFollowersCount(nextFollowersCount) }} /> ) : null} {!isOwnArtwork && isGroupPublisher ? ( ) : null}
{/* More from creator rail */} {creatorItems.length > 0 && (

{isGroupPublisher ? 'More related works' : `More from ${authorName}`}

{creatorItems.slice(0, 3).map((item, idx) => (
{item.title
{item.likes ? formatCount(item.likes) : ''}
))}
)}
) }