import React, { useState } from 'react' import { router } from '@inertiajs/react' /** * ProfileHero * Cover banner + avatar + identity block + action buttons */ export default function ProfileHero({ user, profile, isOwner, viewerIsFollowing, followerCount, heroBgUrl, countryName }) { const [following, setFollowing] = useState(viewerIsFollowing) const [count, setCount] = useState(followerCount) const [loading, setLoading] = useState(false) const [hovering, setHovering] = useState(false) 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 toggleFollow = async () => { if (loading) return setLoading(true) try { const res = await fetch(`/@${uname.toLowerCase()}/follow`, { method: 'POST', headers: { 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]')?.content ?? '', 'Accept': 'application/json', }, }) if (res.ok) { const data = await res.json() setFollowing(data.following) setCount(data.follower_count) } } catch (_) {} setLoading(false) } return (
{/* Cover / hero background */}
{/* Overlay */}
{/* Nebula grain decoration */}
{/* Identity block – overlaps cover at bottom */}
{/* Avatar */}
{`${uname}'s
{/* Name + meta */}

{displayName}

@{uname}

{countryName && ( {profile?.country_code && ( {countryName} { e.target.style.display = 'none' }} /> )} {countryName} )} {joinDate && ( Joined {joinDate} )} {profile?.website && ( {(() => { try { const url = profile.website.startsWith('http') ? profile.website : `https://${profile.website}` return new URL(url).hostname } catch { return profile.website } })()} )}
{/* Action buttons */}
{isOwner ? ( <> Edit Profile Studio ) : ( <> {/* Follow button */} {/* Share */} )}
) }