import { PollOption } from '../types/poll.types'; import { VoteButton } from './VoteButton'; interface OptionListProps { options: PollOption[]; onVote: (optionId: string) => void; hasVoted?: (option: PollOption) => boolean; } export function OptionList({ options, onVote, hasVoted }: OptionListProps) { const totalVotes = options.reduce((sum, opt) => sum + opt.votes, 0); const sortedOptions = [...options].sort((a, b) => b.votes - a.votes); return (
{sortedOptions.length === 0 ? (
No options yet. Add one to get started!
) : ( sortedOptions.map((option) => { const percentage = totalVotes > 0 ? (option.votes / totalVotes) * 100 : 0; const userHasVoted = hasVoted ? hasVoted(option) : false; return (
{option.text} {userHasVoted && ✓ Voted}
by {option.createdBy} {percentage.toFixed(1)}%
); }) )}
); }