"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 ConfigProvider_1 = require("../utils/ConfigProvider");
const components_1 = require("../themes/components");
const styled_components_1 = require("styled-components");
const react_native_1 = require("react-native");
const borderRadius_1 = __importDefault(require("../themes/foundations/borderRadius"));
const SelfPreview_1 = __importDefault(require("./SelfPreview"));
const OrientationContext_1 = require("../services/OrientationContext");
function StartPresentingModal() {
    var _a;
    const roomViewType = react_redux_1.useSelector((state) => state.room.roomViewType);
    const presentingState = react_redux_1.useSelector((state) => state.participant.presentingState);
    const { mediaRoom } = react_1.useContext(MediaRoomService_1.MediaRoomContext);
    const { sessionConfig } = react_1.useContext(ConfigProvider_1.ConfigServiceContext);
    const requestToJoinTypeValue = react_redux_1.useSelector((state) => state.participant.requestToJoinType);
    const { orientation } = react_1.default.useContext(OrientationContext_1.OrientationContext);
    const mobileLandscape = orientation === 'LANDSCAPE';
    const dispatch = react_redux_1.useDispatch();
    const windowDimensions = react_native_1.useWindowDimensions();
    const { height, width } = sessionConfig.theme.dimensions || windowDimensions;
    const { colors } = react_1.useContext(styled_components_1.ThemeContext);
    const isOpen = roomViewType === newTypes_1.DyteViewTypes.webinar
        && presentingState === participantSlice_1.PresentingState.INITIATED;
    const acceptRequest = () => {
        mediaRoom.startPresenting();
    };
    const rejectRequest = () => {
        var _a;
        if ((_a = sessionConfig.permissions) === null || _a === void 0 ? void 0 : _a.accept_present_requests) {
            dispatch(participantSlice_1.stoppedPresenting());
        }
        else {
            mediaRoom.removePeerFromStage(mediaRoom.peerid, newTypes_1.WebinarAcceptRequestType.REQUESTED_BY_PARTICIPANT);
        }
    };
    const isModerator = (_a = sessionConfig.permissions) === null || _a === void 0 ? void 0 : _a.accept_present_requests;
    const confirmText = () => (participantSlice_1.RequestToJoinType.present ? 'Start Presenting' : 'Start Asking');
    const renderLandscape = () => (react_1.default.createElement(components_1.HStack, null,
        react_1.default.createElement(components_1.Flex, { width: "50%" },
            react_1.default.createElement(SelfPreview_1.default, null)),
        react_1.default.createElement(components_1.Flex, { width: "50%", px: 25, direction: "column", justify: "center" },
            react_1.default.createElement(components_1.Button, { width: "100%", onClick: rejectRequest },
                react_1.default.createElement(components_1.Box, { bg: "danger.500", py: 15, px: 20, borderRadius: borderRadius_1.default.small, align: "center" },
                    react_1.default.createElement(components_1.Text, null, "Cancel"))),
            react_1.default.createElement(components_1.Button, { width: "100%", onClick: acceptRequest },
                react_1.default.createElement(components_1.Box, { bg: "primary.500", py: 15, px: 20, mt: 20, borderRadius: borderRadius_1.default.small, align: "center" },
                    react_1.default.createElement(components_1.Text, null, confirmText()))))));
    const renderPotrait = () => (react_1.default.createElement(components_1.VStack, null,
        react_1.default.createElement(SelfPreview_1.default, null),
        react_1.default.createElement(components_1.Flex, { direction: "column", justifyContent: "space-between" },
            react_1.default.createElement(components_1.Button, { width: "100%", onClick: rejectRequest },
                react_1.default.createElement(components_1.Box, { bg: "danger.500", py: 12, px: 20, mt: 10, borderRadius: borderRadius_1.default.small, align: "center" },
                    react_1.default.createElement(components_1.Text, null, "Cancel"))),
            react_1.default.createElement(components_1.Button, { width: "100%", onClick: acceptRequest },
                react_1.default.createElement(components_1.Box, { bg: "primary.500", py: 12, px: 20, mt: 10, borderRadius: borderRadius_1.default.small, align: "center" },
                    react_1.default.createElement(components_1.Text, null, confirmText()))))));
    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, { py: 25 },
                react_1.default.createElement(components_1.Flex, { display: "flex", py: 20 }, mobileLandscape ? renderLandscape() : renderPotrait())))));
}
exports.default = StartPresentingModal;
//# sourceMappingURL=StartPresentingModal.js.map