import MasterLineData from '@nirvana/core/models/masterLineData.model';
import React, { useMemo, useCallback } from 'react';
import { Avatar, Tooltip } from 'antd';
import { FiActivity, FiSun, FiX } from 'react-icons/fi';
import useAuth from '../../../../providers/AuthProvider';
import LineIcon from '../../../../components/lineIcon';
import moment from 'moment';
import { useKeyPressEvent } from 'react-use';
import toast from 'react-hot-toast';
import { LineMemberState } from '@nirvana/core/models/line.model';
import useElectron from '../../../../providers/ElectronProvider';
export default React.memo(function LineRow({
index,
line,
handleSelectLine,
isSelected,
}: {
index: number; // the order of this one in the list (for this view to know the shortcut to register)
line: MasterLineData;
handleSelectLine: (newLineId: string) => void;
isSelected: boolean;
}) {
const { user } = useAuth();
const { desktopMode, isWindowFocused } = useElectron();
const isUserTunedIn = useMemo(
() => line.tunedInMemberIds?.includes(user._id.toString()),
[line.tunedInMemberIds, user],
);
const isUserToggleTuned = useMemo(
() => line?.currentUserMember?.state === LineMemberState.TUNED,
[line],
);
const handleActivateLine = useCallback(() => {
handleSelectLine(line.lineDetails._id.toString());
}, [handleSelectLine, line.lineDetails, index]);
const hotkeyActivateLine = useCallback(() => {
// TODO: disable for higher numbers? ehh maybe hidden easter egg to select more?
// if (isUserToggleTuned) handleActivateLine();
handleActivateLine();
}, [handleActivateLine]);
useKeyPressEvent((index + 1).toString(), hotkeyActivateLine);
const profilePictures = useMemo(() => {
const allMembers: string[] = [];
const tunedMembers: string[] = [];
const broadcastMembers: string[] = [];
const untunedMembers: string[] = [];
// ?don't add in my image as that's useless contextually?
if (user.picture) allMembers.push(user.picture);
line.otherUserObjects?.forEach((otherUser) => {
if (otherUser.picture) {
allMembers.push(otherUser.picture);
if (line.tunedInMemberIds?.includes(otherUser._id.toString())) {
tunedMembers.push(otherUser.picture);
return;
}
if (line.currentBroadcastersUserIds?.includes(otherUser._id.toString())) {
broadcastMembers.push(otherUser.picture);
return;
}
untunedMembers.push(otherUser.picture);
}
});
return {
untunedMembers,
allMembers,
tunedMembers,
broadcastMembers,
};
}, [line, user]);
const renderRightActivity = useMemo(() => {
if (isSelected) {
return (