'use client'; import { useMemo, useCallback } from 'react'; import { CheckCircle, Circle, ArrowRight } from '@phosphor-icons/react'; import { Progress } from '@/components/ui/progress'; import { useProfileEdit } from '@/components/profile-edit-provider'; import type { Profile } from '@/lib/types'; interface CompletionItem { key: string; label: string; completed: boolean; /** Hash anchor for scroll-to-section items. */ scrollTo?: string; /** Edit request key for items that open a dialog. */ editKey?: string; } function getCompletionItems(profile: Profile): CompletionItem[] { return [ { key: 'avatar', label: 'Add a profile photo', completed: Boolean(profile.avatar), editKey: 'identity', }, { key: 'headline', label: 'Write a headline', completed: Boolean(profile.headline), editKey: 'identity', }, { key: 'about', label: 'Add a professional summary', completed: Boolean(profile.about), scrollTo: '#about', }, { key: 'current-position', label: 'Add your current position', completed: profile.positions.some((p) => !p.endedAt), scrollTo: '#career', }, { key: 'past-position', label: 'Add a past position', completed: profile.positions.filter((p) => p.endedAt).length > 0, scrollTo: '#career', }, { key: 'skills', label: 'Add 3+ skills', completed: profile.skills.length >= 3, scrollTo: '#skills', }, { key: 'education', label: 'Add education', completed: profile.education.length > 0, scrollTo: '#education', }, { key: 'website', label: 'Add a website or verification', completed: Boolean(profile.website) || (profile.externalAccounts ?? []).length > 0, editKey: 'externalAccounts', }, ]; } interface CompletionBarProps { profile: Profile; } export function CompletionBar({ profile }: CompletionBarProps) { const { requestEdit } = useProfileEdit(); const items = useMemo(() => getCompletionItems(profile), [profile]); const completedCount = items.filter((i) => i.completed).length; const percentage = Math.round((completedCount / items.length) * 100); const handleAction = useCallback( (item: CompletionItem) => { if (item.editKey) { requestEdit(item.editKey); } }, [requestEdit], ); if (!profile.isOwnProfile || percentage === 100) return null; const nextItem = items.find((i) => !i.completed); return (