"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 });
/* eslint-disable no-underscore-dangle */
const react_1 = __importStar(require("react"));
const react_redux_1 = require("react-redux");
const Stage_1 = __importDefault(require("../Stage"));
const MediaRoomService_1 = require("../../services/MediaRoomService");
const roomSlice_1 = require("../../store/roomSlice");
const LoadingScreen_1 = __importDefault(require("../../components/LoadingScreen"));
const react_native_1 = require("react-native");
const ConfigProvider_1 = require("../../utils/ConfigProvider");
const components_1 = require("../../themes/components");
function default_1(props) {
    const { mediaRoom, } = react_1.useContext(MediaRoomService_1.MediaRoomContext);
    const displayName = react_redux_1.useSelector((state) => state.participant.displayName);
    const audioMuted = react_redux_1.useSelector((state) => state.participant.audioMuted);
    const routerState = react_redux_1.useSelector((state) => state.room.routerState);
    const joined = react_redux_1.useSelector((state) => state.room.joined);
    const waitingState = react_redux_1.useSelector((state) => state.room.waitingState);
    const { roomName } = props;
    const { sessionConfig, meeting } = react_1.useContext(ConfigProvider_1.ConfigServiceContext);
    const windowDimensions = react_native_1.useWindowDimensions();
    const { height, width } = sessionConfig.theme.dimensions || windowDimensions;
    // console.log(routerState,MediaStates.LOADED);
    react_1.useEffect(() => {
        if (routerState === roomSlice_1.MediaStates.LOADED && mediaRoom) {
            mediaRoom.joinRoom(displayName, audioMuted);
        }
    }, [routerState]);
    react_1.useEffect(() => {
        if (waitingState === roomSlice_1.WaitingState.ACCEPTED && mediaRoom) {
            mediaRoom.joinRoom(displayName, audioMuted);
        }
    }, [waitingState]);
    react_1.useEffect(() => {
        if (joined && meeting) {
            meeting.emit(meeting.Events.meetingJoined);
        }
    }, [joined]);
    if (!joined) {
        return react_1.default.createElement(LoadingScreen_1.default, { text: "This seems to be taking too long...", showTextAfter: 10 });
    }
    /* if (waitingState === WaitingState.WAITING) {
        return <WaitingRoom />;
    } */
    if (waitingState === roomSlice_1.WaitingState.REJECTED) {
        return (react_1.default.createElement(components_1.Stack, { height: height, width: width, backgroundColor: "#202124", justify: "center", align: "center" },
            react_1.default.createElement(components_1.Text, { color: "textPrimary.100", className: "dyte-client-noSelect" }, "Host rejected you request")));
    }
    return react_1.default.createElement(Stage_1.default, { roomName: roomName });
}
exports.default = default_1;
//# sourceMappingURL=JoinStage.js.map