import React from 'react';
import { View, Text, Pressable } from 'react-native';
import Svg, { Path } from 'react-native-svg';
import type { Poll as PollType, ComponentSize } from '../types/algorand';
import { formatRelativeTime } from '../utils/format';
import { SizeContainer } from '../ui/SizeContainer';
import { StatusBadge } from '../ui/StatusBadge';
import { ProgressBar } from '../ui/ProgressBar';
function VoteIcon({ size = 16, color = '#a1a1aa' }: { size?: number; color?: string }) {
return (
);
}
function UsersIcon({ size = 12, color = '#a1a1aa' }: { size?: number; color?: string }) {
return (
);
}
function TrendingUpIcon({ size = 12, color = '#34d399' }: { size?: number; color?: string }) {
return (
);
}
function ClockIcon({ size = 12, color = '#71717a' }: { size?: number; color?: string }) {
return (
);
}
function CalendarIcon({ size = 12, color = '#71717a' }: { size?: number; color?: string }) {
return (
);
}
interface PollProps {
data: PollType;
showVoteButton?: boolean;
compact?: boolean;
size?: ComponentSize;
className?: string;
onVote?: (pollId: string, optionId: string) => void;
}
export function PollComponent({
data: poll,
showVoteButton = true,
compact = false,
size = 'full',
className,
onVote,
}: PollProps) {
const isExpired = poll.expiresAt ? new Date() > poll.expiresAt : false;
const canVote = poll.status === 'active' && !isExpired;
const hasGating = poll.gating !== undefined;
const totalPower = poll.options.reduce((sum, opt) => sum + opt.votingPower, 0);
const isFullscreen = size === 'fullscreen';
return (
{/* Header */}
Poll
{hasGating && }
{isExpired && }
{poll.question}
{poll.totalVotes} votes
{!compact && (
{totalPower.toLocaleString()} power
)}
{poll.expiresAt && (
{canVote ? 'Ends' : 'Ended'} {formatRelativeTime(poll.expiresAt)}
)}
{/* Gating Info */}
{hasGating && poll.gating && !compact && (
Voting Requirements
{poll.gating.type === 'asset-holding' && 'Requires holding specified assets to participate'}
{poll.gating.type === 'nfd-verified' && 'Requires verified NFD to participate'}
)}
{/* Options */}
{poll.options.map((option, index) => {
const percentage = poll.totalVotes > 0 ? (option.votes / poll.totalVotes) * 100 : 0;
const powerPercentage =
totalPower > 0 ? (option.votingPower / totalPower) * 100 : 0;
return (
canVote && showVoteButton && onVote?.(poll.id, option.id)}
disabled={!canVote || !showVoteButton}
className={`rounded-lg border overflow-hidden ${
canVote && showVoteButton
? 'border-zinc-800 active:border-purple-500'
: 'border-zinc-800'
}`}
>
{/* Background fill */}
{option.text}
{index === 0 && poll.status === 'active' && (
Leading
)}
{percentage.toFixed(1)}%
{!compact && (
{option.votes} votes
)}
{!compact && (
Voting Power: {option.votingPower.toLocaleString()} ({powerPercentage.toFixed(1)}%)
)}
);
})}
{/* Vote CTA */}
{showVoteButton && canVote && !compact && (
Tap any option above to vote
)}
{/* Footer */}
{!compact && (
Created {formatRelativeTime(poll.createdAt)}
by {poll.creator.slice(0, 8)}...
)}
);
}