import React, { FunctionComponent } from 'react';
import { takeCall } from '../../../../../store/webrtc/webrtcSlice';
import { ImageSourcePropType } from 'react-native';
import { IP2PCall } from '../../../../../store/webrtc/types';
import { IImageButtonStyleProps, IStyledProps } from '../../../../common/types';
import { AnswerVideoCallButtonView } from './AnswerVideoCallButtonView';
import { ImageButton } from '../../../../common/ImageButton';
import { useAppDispatch } from '../../../../../store/hooks';

export interface IAnswerVideoBtnProps extends IStyledProps<IImageButtonStyleProps> {
    call: IP2PCall
    imageSource?: ImageSourcePropType;
    renderOnPress?: (call: IP2PCall) => void;
}
export const AnswerVideoCallButton: FunctionComponent<IAnswerVideoBtnProps> = ({ imageSource, call, renderOnPress, style }) => {
const dispatch = useAppDispatch();
    const AnswerVideoCall = () => {
        if (renderOnPress) {
            renderOnPress(call);
        } else {
            dispatch(takeCall(true));
        }
    };

    if (imageSource) {
        return <ImageButton imageSource={imageSource} style={style} onPress={AnswerVideoCall} />
    }
    else {
        return <AnswerVideoCallButtonView onPress={AnswerVideoCall} style={style} />;
    }
};