import React, { useEffect, useState } from 'react';
import { useMedia } from 'react-use';
import { DefaultConferencingScreen_Elements } from '@100mslive/types-prebuilt';
import { match } from 'ts-pattern';
import { selectPeerCount, useHMSStore } from '@100mslive/react-sdk';
import { CrossIcon } from '@100mslive/react-icons';
import { Chat } from './Chat/Chat';
import { PaginatedParticipants } from './Footer/PaginatedParticipants';
import { ParticipantList } from './Footer/ParticipantList';
import { Box, config as cssConfig, Flex, IconButton, Tabs, Text } from '../..';
import { Tooltip } from '../../Tooltip';
import { ChatSettings } from './ChatSettings';
import { useRoomLayoutConferencingScreen } from '../provider/roomLayoutProvider/hooks/useRoomLayoutScreen';
// @ts-ignore: No implicit Any
import { useIsSidepaneTypeOpen, useSidepaneReset, useSidepaneToggle } from './AppData/useSidepane';
// @ts-ignore: No implicit Any
import { getFormattedCount } from '../common/utils';
import { SIDE_PANE_OPTIONS } from '../common/constants';
const tabTriggerCSS = {
color: '$on_surface_low',
p: '$4',
fontWeight: '$semiBold',
fontSize: '$sm',
w: '100%',
justifyContent: 'center',
'&[data-state="active"]': {
color: '$on_surface_high',
},
};
const ParticipantCount = ({ count }: { count: number }) => {
return count < 1000 ? (
({count})
) : (
({getFormattedCount(count)})
);
};
export const SidePaneTabs = React.memo<{
active: 'Participants | Chat';
hideTab?: boolean;
}>(({ active = SIDE_PANE_OPTIONS.CHAT, hideTab = false }) => {
const toggleChat = useSidepaneToggle(SIDE_PANE_OPTIONS.CHAT);
const toggleParticipants = useSidepaneToggle(SIDE_PANE_OPTIONS.PARTICIPANTS);
const resetSidePane = useSidepaneReset();
const [activeTab, setActiveTab] = useState(active);
const [activeRole, setActiveRole] = useState('');
const peerCount = useHMSStore(selectPeerCount);
const { elements, screenType } = useRoomLayoutConferencingScreen();
const chat_title = elements?.chat?.chat_title || 'Chat';
const showChat = !!elements?.chat;
const showParticipants = !!elements?.participant_list;
const hideTabs = !(showChat && showParticipants) || hideTab;
const isMobile = useMedia(cssConfig.media.md);
const isOverlayChat = !!elements?.chat?.is_overlay && isMobile;
const { off_stage_roles = [] } = (elements as DefaultConferencingScreen_Elements)?.on_stage_exp || {};
const isChatOpen = useIsSidepaneTypeOpen(SIDE_PANE_OPTIONS.CHAT);
const showChatSettings = showChat && isChatOpen && (!isMobile || !isOverlayChat);
useEffect(() => {
match({ activeTab, showChat, showParticipants })
.with({ activeTab: SIDE_PANE_OPTIONS.CHAT, showChat: false, showParticipants: true }, () => {
setActiveTab(SIDE_PANE_OPTIONS.PARTICIPANTS);
})
.with({ activeTab: SIDE_PANE_OPTIONS.PARTICIPANTS, showChat: true, showParticipants: false }, () => {
setActiveTab(SIDE_PANE_OPTIONS.CHAT);
})
.with({ showChat: false, showParticipants: false }, () => {
resetSidePane();
});
}, [showChat, activeTab, showParticipants, resetSidePane]);
useEffect(() => {
setActiveTab(active);
}, [active]);
if (activeRole) {
return (
setActiveRole('')} />
);
}
return (
{match({ isOverlayChat, isChatOpen, showChat, hideTabs })
.with({ isOverlayChat: true, isChatOpen: true, showChat: true }, () => )
.with({ hideTabs: true }, () => {
return (
<>
{activeTab === SIDE_PANE_OPTIONS.CHAT ? (
screenType !== 'hls_live_streaming' && chat_title
) : (
Participants
)}
{showChatSettings ? : null}
{isOverlayChat && isChatOpen ? null : (
{
e.stopPropagation();
if (activeTab === SIDE_PANE_OPTIONS.CHAT) {
toggleChat();
} else {
toggleParticipants();
}
}}
data-testid="close_chat"
>
{screenType === 'hls_live_streaming' && isChatOpen ? null : }
)}
{activeTab === SIDE_PANE_OPTIONS.CHAT ? (
) : (
)}
>
);
})
.otherwise(() => {
return (
{chat_title}
Participants
{showChatSettings ? : null}
{isOverlayChat && isChatOpen ? null : (
{
e.stopPropagation();
if (activeTab === SIDE_PANE_OPTIONS.CHAT) {
toggleChat();
} else {
toggleParticipants();
}
}}
data-testid="close_chat"
>
)}
);
})}
);
});