"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_native_1 = require("react-native");
const react_1 = __importDefault(require("react"));
const components_1 = require("../../../themes/components");
const borderRadius_1 = __importDefault(require("../../../themes/foundations/borderRadius"));
const PollsOptions_1 = __importDefault(require("./PollsOptions"));
function default_1(props) {
    const { selfPeer, mediaRoom, poll } = props;
    const votePoll = (index) => {
        try {
            mediaRoom.votePoll({
                index,
                pollId: poll.id,
            });
        }
        catch (error) {
            react_native_1.Alert.alert('Error', 'Error: Problem casting your vote', [
                { text: 'OK' },
            ]);
        }
    };
    console.log('Poll', poll);
    if (poll) {
        const { id } = poll;
        const maxVotes = Math.max(...poll.options.map((p) => p.votes.length), 0);
        return (react_1.default.createElement(components_1.VStack, { spacing: 2, direction: "row", bg: "secondary.800", p: 12, mt: 8, borderRadius: borderRadius_1.default.medium },
            react_1.default.createElement(components_1.Text, { textAlign: "left" }, poll.question),
            react_1.default.createElement(components_1.Box, { mt: 8 }, poll.options.map((option, index) => (react_1.default.createElement(components_1.Flex, { onClick: () => votePoll(index), mb: 4 },
                react_1.default.createElement(PollsOptions_1.default, { active: option.votes.length === maxVotes &&
                        option.votes.length > 0, option: option, index: index, selfId: selfPeer.userId, onChange: () => votePoll(index) })))))));
    }
    return (react_1.default.createElement(components_1.Text, { fontStyle: "italic" }, "Poll wasn't found or has been deleted"));
}
exports.default = default_1;
//# sourceMappingURL=PollsCard.js.map