import React, {Component} from "react";
import {connect} from "react-redux";
import {
  isParticipantVideoTurnedOn,
  isScreenShare,
  isVideoCall,
  sortCallParticipantsBy
} from "../utils/helpers";


//strings
import {CHAT_CALL_STATUS_INCOMING, CHAT_CALL_STATUS_OUTGOING} from "../constants/callModes";


//actions

//components
import CallBoxScenePersonVideo from "./CallBoxScenePersonVideo";
import CallBoxScenePersonAudio from "./CallBoxScenePersonAudio";

//styling

//statics

//functions


@connect(store => {
  return {
    user: store.user.user,
    chatCallParticipantList: sortCallParticipantsBy(store.chatCallParticipantList.participants, "id")
  };
})
export default class CallBoxScenePerson extends Component {

  constructor(props) {
    super(props);
  }

  render() {
    const {chatCallStatus, chatCallBoxShowing, user, chatCallParticipantList} = this.props;
    const {status, call} = chatCallStatus;
    const isVideoCalling = isVideoCall(call);
    const isScreenSharing = isScreenShare(call);
    const isVideoIncluded = isParticipantVideoTurnedOn(call, chatCallParticipantList);
    const incomingCondition = status === CHAT_CALL_STATUS_INCOMING;
    const outgoingCondition = status === CHAT_CALL_STATUS_OUTGOING;
    const commonArgs = {
      chatCallStatus,
      chatCallBoxShowing,
      user,
      chatCallParticipantList,
      isVideoIncluded,
      isVideoCall: isVideoCalling
    };
    return (isScreenSharing || isVideoIncluded) && !incomingCondition && !outgoingCondition ?
      <CallBoxScenePersonVideo {...commonArgs}/> :
      <CallBoxScenePersonAudio {...commonArgs}/>;
  }
}