import React, { useState } from 'react' import ProfileCoverEditor from './ProfileCoverEditor' import LevelBadge from '../xp/LevelBadge' import XPProgressBar from '../xp/XPProgressBar' import FollowButton from '../social/FollowButton' export default function ProfileHero({ user, profile, isOwner, viewerIsFollowing, followerCount, heroBgUrl, countryName, leaderboardRank, extraActions = null }) { const [following, setFollowing] = useState(viewerIsFollowing) const [count, setCount] = useState(followerCount) const [editorOpen, setEditorOpen] = useState(false) const [coverUrl, setCoverUrl] = useState(user?.cover_url || heroBgUrl || null) const [coverPosition, setCoverPosition] = useState(Number.isFinite(user?.cover_position) ? user.cover_position : 50) const uname = user.username || user.name || 'Unknown' const displayName = user.name || uname const joinDate = user.created_at ? new Date(user.created_at).toLocaleDateString('en-US', { month: 'long', year: 'numeric' }) : null const bio = profile?.bio || profile?.about || '' return ( <>
{isOwner ? (
) : null}
{`${uname}'s

{displayName}

@{uname}

{leaderboardRank?.rank ? ( Rank #{leaderboardRank.rank} this week ) : null}
{countryName ? ( {profile?.country_code ? ( {countryName} { event.target.style.display = 'none' }} /> ) : null} {countryName} ) : null} {joinDate ? ( Joined {joinDate} ) : null} {profile?.website ? ( {(() => { try { const url = profile.website.startsWith('http') ? profile.website : `https://${profile.website}` return new URL(url).hostname } catch { return profile.website } })()} ) : null}
{bio ? (

{bio}

) : null}
{extraActions} {isOwner ? ( <> Edit Profile Studio ) : ( <> { setFollowing(nextFollowing) setCount(followersCount) }} /> )}
setEditorOpen(false)} currentCoverUrl={coverUrl} currentPosition={coverPosition} coverUrl={coverUrl} coverPosition={coverPosition} onCoverUpdated={(nextUrl, nextPosition) => { setCoverUrl(nextUrl) setCoverPosition(nextPosition) }} onCoverRemoved={() => { setCoverUrl(null) setCoverPosition(50) }} /> ) }