"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = __importStar(require("react"));
const MediaRoomService_1 = require("../services/MediaRoomService");
const react_redux_1 = require("react-redux");
const participantSlice_1 = require("../store/participantSlice");
const newTypes_1 = require("../types/newTypes");
const react_native_1 = require("react-native");
const components_1 = require("../themes/components");
const styled_components_1 = require("styled-components");
const ConfigProvider_1 = require("../utils/ConfigProvider");
const borderRadius_1 = __importDefault(require("../themes/foundations/borderRadius"));
function RequestToJoinStageModal({ isMobile }) {
    const roomViewType = react_redux_1.useSelector((state) => state.room.roomViewType);
    const joinToStageState = react_redux_1.useSelector((state) => state.participant.requestToJoinStageState);
    const { colors } = react_1.useContext(styled_components_1.ThemeContext);
    const { mediaRoom } = react_1.useContext(MediaRoomService_1.MediaRoomContext);
    const dispatch = react_redux_1.useDispatch();
    const { sessionConfig } = react_1.useContext(ConfigProvider_1.ConfigServiceContext);
    const windowDimensions = react_native_1.useWindowDimensions();
    const { height, width } = sessionConfig.theme.dimensions || windowDimensions;
    const isOpen = roomViewType === newTypes_1.DyteViewTypes.webinar
        && joinToStageState === participantSlice_1.RequestToJoinStageState.INITIATED;
    const acceptRequest = (selectedOption) => {
        dispatch(participantSlice_1.requestToJoinType(selectedOption));
        dispatch(participantSlice_1.requestedJoinToStageState(participantSlice_1.RequestToJoinStageState.WAITING));
        mediaRoom.requestToJoinStage(selectedOption);
        react_native_1.Alert.alert('Request Sent', `Request to ${selectedOption === participantSlice_1.RequestToJoinType.present ? 'present' : 'ask'} has been sent successfully to host`, [
            { text: 'OK', onPress: () => { } },
        ]);
    };
    const rejectRequest = () => {
        dispatch(participantSlice_1.requestedJoinToStageState(participantSlice_1.RequestToJoinStageState.NONE));
        dispatch(participantSlice_1.requestToJoinType(undefined));
    };
    return (react_1.default.createElement(components_1.Modal, { isVisible: isOpen, backdropOpacity: 0.8, backdropColor: colors.secondary[800] },
        react_1.default.createElement(components_1.Flex, { width: width * 0.9, bg: "secondary.1000", color: "textPrimary.100", px: 15, borderRadius: borderRadius_1.default.medium },
            react_1.default.createElement(components_1.Flex, { pt: 15 },
                react_1.default.createElement(components_1.Text, { fontSize: 28, fontWeight: "bold" }, "Request")),
            react_1.default.createElement(components_1.Flex, { display: "flex", pb: 20 },
                react_1.default.createElement(components_1.Flex, { direction: isMobile ? 'column' : 'row', justifyContent: "space-between" },
                    react_1.default.createElement(components_1.Button, { onClick: () => acceptRequest(participantSlice_1.RequestToJoinType.present) },
                        react_1.default.createElement(components_1.Box, { bg: "primary.500", py: 12, px: 20, mt: 20, borderRadius: borderRadius_1.default.small, align: "center" },
                            react_1.default.createElement(components_1.Text, null, "Request to Present"))),
                    react_1.default.createElement(components_1.Button, { onClick: rejectRequest },
                        react_1.default.createElement(components_1.Box, { bg: "danger.500", py: 12, px: 20, mt: 20, borderRadius: borderRadius_1.default.small, align: "center" },
                            react_1.default.createElement(components_1.Text, null, "Cancel"))))))));
}
exports.default = RequestToJoinStageModal;
//# sourceMappingURL=RequestToJoinStageModal.js.map