import { Alert, } from 'react-native';
import React from 'react';
import { Flex, VStack, Text, Box, } from '../../../themes/components';
import borderRadius from '../../../themes/foundations/borderRadius';
import PollOptionView from '../../../components/StageSidebar/PollsTab/PollsOptions';
export default function (props) {
    const { selfPeer, mediaRoom, poll } = props;
    const votePoll = (index) => {
        try {
            mediaRoom.votePoll({
                index,
                pollId: poll.id,
            });
        }
        catch (error) {
            Alert.alert('Error', 'Error: Problem casting your vote', [
                { text: 'OK' },
            ]);
        }
    };
    if (poll) {
        const { id } = poll;
        const maxVotes = Math.max(...poll.options.map((p) => p.votes.length), 0);
        return (<VStack spacing={2} direction="row" bg="secondary.800" p={12} mt={8} borderRadius={borderRadius.medium}>
				<Text textAlign="left">{poll.question}</Text>
				<Box mt={8}>
					{poll.options.map((option, index) => (<Flex onClick={() => votePoll(index)} mb={4}>
							<PollOptionView active={option.votes.length === maxVotes && option.votes.length > 0} option={option} index={index} selfId={selfPeer.userId} onChange={() => votePoll(index)}/>
						</Flex>))}
				</Box>
			</VStack>);
    }
    return (<Text fontStyle="italic">Poll wasn&apos;t found or has been deleted</Text>);
}
//# sourceMappingURL=PollsCard.js.map