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