
import { IImageButtonStyleProps, IStyledProps } from '../../../../common/types';
import React, { FunctionComponent } from 'react';
import { ImageSourcePropType } from 'react-native';
import { hideActiveCurrentConference } from '../../../../../store/conference/conferenceSlice';
import { IConference } from '../../../../../store/conference/types';
import { GoToChatButtonView } from './GoToChatButtonView';
import { ImageButton } from '../../../../common/ImageButton';
import { useAppDispatch } from '../../../../../store/hooks';
interface IProps extends IStyledProps<IImageButtonStyleProps> {
    call: IConference
    imageSource?: ImageSourcePropType;
    renderOnPress?: (call: IConference) => void;
}

export const GoToChatButton: FunctionComponent<IProps> = ({
    imageSource,
    renderOnPress,
    call,
    style
}) => {
    const dispatch = useAppDispatch()
    const goBackToBubbleChat = () => {
        if (renderOnPress) {
            renderOnPress(call);
            dispatch(hideActiveCurrentConference());
        }
    }

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