import React from 'react';
import { observer } from 'mobx-react-lite';
import cn from 'classnames';
import Tab from './Tab';
import { PlayerContext } from 'Components/Session/playerContext';
import { useModal } from 'Components/Modal';
interface Props {
tabs: { tab: string; idx: number }[];
currentTab: string;
changeTab: (tab: string) => void;
hideModal: () => void;
}
function Modal({ tabs, currentTab, changeTab, hideModal }: Props) {
return (
{tabs.length} Tabs
{tabs.map((tab, i) => (
{
changeTab(tab.tab);
hideModal();
}}
className={cn(
currentTab === tab.tab ? 'font-semibold ' : 'text-disabled-text',
'cursor-pointer border-b p-4 hover:bg-active-blue'
)}
>
Tab {i + 1}
))}
);
}
function SessionTabs({ isLive }: { isLive?: boolean }) {
const { showModal, hideModal } = useModal();
const { player, store } = React.useContext(PlayerContext);
const { tabs = new Set('back-compat'), currentTab } = store.get();
const tabsArr = Array.from(tabs).map((tab, idx) => ({ tab, idx }));
const shouldTruncate = tabsArr.length > 10;
const actualTabs = shouldTruncate ? tabsArr.slice(0, 10) : tabsArr;
const shownTabs =
actualTabs.findIndex((el) => el.tab === currentTab) !== -1
? actualTabs
: actualTabs.concat({
tab: currentTab,
idx: tabsArr.findIndex((tEl) => tEl.tab === currentTab),
});
const changeTab = (tab: string) => {
if (isLive) return;
player.changeTab(tab);
};
const openModal = () => {
showModal(
,
{
right: true,
}
);
};
return (
<>
{shownTabs.map((tab, i) => (
))}
{shouldTruncate ? (
<>
{tabsArr.length > 11 ? (
+{tabsArr.length - 11} More
) : null}
>
) : null}
>
);
}
export default observer(SessionTabs);