'use client'

import AgoraRTC, { AgoraRTCProvider } from 'agora-rtc-react';
import { Session } from '../../../types/sessions';
import { Agora } from './Agora';

export const AgoraClient = ({ session, stopCalling, isCoach }: { session?: Session, stopCalling: () => void, isCoach: boolean }) => {
    const remoteUser = isCoach ? (session?.clients?.length ? session?.clients[0] : undefined) : session?.coach;

    return session ? (
        <AgoraRTCProvider client={AgoraRTC.createClient({ mode: "rtc", codec: "vp8" })}>
            {session && (
                <Agora
                    sessionId={session.id}
                    secret={session.secret}
                    stopCalling={stopCalling}
                    remoteUser={remoteUser}
                />
            )}
        </AgoraRTCProvider>
    ) : null;
};
