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

export interface IAnswerCallBtnProps extends IStyledProps<IImageButtonStyleProps> {
    call: IP2PCall
    imageSource?: ImageSourcePropType;
    renderOnPress?: (call: IP2PCall) => void;
}

export const AnswerAudioCallButton: FunctionComponent<IAnswerCallBtnProps> = ({ imageSource, renderOnPress, call, style }) => {
    const dispatch = useAppDispatch();
    const AnswerAudioCall = () => {
        if (renderOnPress) {
            renderOnPress(call);
        } else {
            dispatch(takeCall(false))
        }
    };

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