'use client'; /* EngagementProfileHeader — phase 08 (D-05, D-06, D-07). * Purpose: Identity header card — avatar (photo or initials), display name, jobTitle, * department, email mailto: link, and last-active row. * Avatar: photo from /api/mobile/engagement/user/[userId]/photo; on error → initials. * Last-active: relative (≤7d via date-fns) or absolute (>7d via formatInUserTimezone). */ import { useState } from 'react'; import { formatDistanceToNow } from 'date-fns'; import { Card, CardContent } from '@/components/ui/card'; import { getInitials } from '@/components/mobile/EngagementUserRow'; import { useUserTimezone, formatInUserTimezone } from '@/lib/hooks/use-user-timezone'; export interface EngagementProfileHeaderProps { displayName: string; email: string; jobTitle: string | null; department: string | null; // Last-active source: caller derives from response (most recent of recentEntries[0].entry_date, // or the most-recent snapshots[].period_end). null if no signal at all. lastActiveAt: string | null; // ISO date string or null (D-06) // Used to build the photo URL — userId is the same value as the route segment userId: string; } export function EngagementProfileHeader({ displayName, email, jobTitle, department, lastActiveAt, userId, }: EngagementProfileHeaderProps) { const [photoFailed, setPhotoFailed] = useState(false); const tz = useUserTimezone(); // Compute last-active label (D-06) let lastActiveLabel: string | null = null; if (lastActiveAt) { const ms = Date.now() - new Date(lastActiveAt).getTime(); if (ms <= 7 * 24 * 60 * 60 * 1000) { // Relative — ≤7d lastActiveLabel = `Active ${formatDistanceToNow(new Date(lastActiveAt), { addSuffix: true })}`; } else { // Absolute — >7d const formatted = formatInUserTimezone(lastActiveAt, tz, { month: 'short', day: 'numeric', year: 'numeric' }); lastActiveLabel = `Last active ${formatted}`; } } return ( {/* Avatar — photo or initials fallback */} {!photoFailed ? ( {displayName} setPhotoFailed(true)} /> ) : ( )} {/* Identity stack */}

{displayName}

{jobTitle && (

{jobTitle}

)} {department && (

{department}

)} {email} {lastActiveLabel && (

{lastActiveLabel}

)}
); }