// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { toFlatCommunicationIdentifier } from "../../acs-ui-common/src";
import { createSelector } from 'reselect';
import { getDisplayName, getDominantSpeakers, getIdentifier, getIsMuted, getIsScreenSharingOn, getLocalVideoStreams, getRole, getScreenShareRemoteParticipant } from './baseSelectors';
import { getTogetherModeCallFeature } from './baseSelectors';
import { isHideAttendeeNamesEnabled } from './baseSelectors';
import { getOptimalVideoCount } from './baseSelectors';
import { _updateUserDisplayNames } from './utils/callUtils';
import { checkIsSpeaking } from './utils/SelectorUtils';
import { _videoGalleryRemoteParticipantsMemo, _dominantSpeakersWithFlatId, convertRemoteParticipantToVideoGalleryRemoteParticipant, memoizeLocalParticipant, memoizeTogetherModeStreams, memoizeTogetherModeSeatingPositions } from './utils/videoGalleryUtils';
import { memoizeSpotlightedParticipantIds } from './utils/videoGalleryUtils';
import { getLocalParticipantRaisedHand } from './baseSelectors';
import { getLocalParticipantReactionState } from './baseSelectors';
import { memoizedConvertToVideoTileReaction } from './utils/participantListSelectorUtils';
import { getRemoteParticipantsExcludingConsumers } from './getRemoteParticipantsExcludingConsumers';
import { getSpotlightCallFeature, getCapabilities } from './baseSelectors';
/**
 * Provides data attributes to {@link VideoGallery} component.
 * @public
 */
export const videoGallerySelector = createSelector([getScreenShareRemoteParticipant, getRemoteParticipantsExcludingConsumers, getLocalVideoStreams, getIsMuted, getIsScreenSharingOn, getDisplayName, getIdentifier, getDominantSpeakers, getOptimalVideoCount, getRole, getLocalParticipantRaisedHand, isHideAttendeeNamesEnabled, getLocalParticipantReactionState, getSpotlightCallFeature, getCapabilities, getTogetherModeCallFeature], (screenShareRemoteParticipantId, remoteParticipants, localVideoStreams, isMuted, isScreenSharingOn, displayName, identifier, dominantSpeakers, optimalVideoCount, role, raisedHand, isHideAttendeeNamesEnabled, localParticipantReaction, spotlightCallFeature, capabilities, togetherModeCallFeature) => {
    const screenShareRemoteParticipant = screenShareRemoteParticipantId && remoteParticipants ? remoteParticipants[screenShareRemoteParticipantId] : undefined;
    const localVideoStream = localVideoStreams === null || localVideoStreams === void 0 ? void 0 : localVideoStreams.find(i => i.mediaStreamType === 'Video');
    const localScreenSharingStream = localVideoStreams === null || localVideoStreams === void 0 ? void 0 : localVideoStreams.find(i => i.mediaStreamType === 'ScreenSharing');
    const dominantSpeakerIds = _dominantSpeakersWithFlatId(dominantSpeakers);
    const dominantSpeakersMap = {};
    dominantSpeakerIds === null || dominantSpeakerIds === void 0 ? void 0 : dominantSpeakerIds.forEach((speaker, idx) => dominantSpeakersMap[speaker] = idx);
    const noRemoteParticipants = [];
    const localParticipantReactionState = memoizedConvertToVideoTileReaction(localParticipantReaction);
    const spotlightedParticipantIds = memoizeSpotlightedParticipantIds(spotlightCallFeature === null || spotlightCallFeature === void 0 ? void 0 : spotlightCallFeature.spotlightedParticipants);
    return {
        screenShareParticipant: screenShareRemoteParticipant ? convertRemoteParticipantToVideoGalleryRemoteParticipant(toFlatCommunicationIdentifier(screenShareRemoteParticipant.identifier), screenShareRemoteParticipant.isMuted, checkIsSpeaking(screenShareRemoteParticipant), screenShareRemoteParticipant.videoStreams, screenShareRemoteParticipant.state, screenShareRemoteParticipant.displayName, screenShareRemoteParticipant.raisedHand, screenShareRemoteParticipant.contentSharingStream, undefined, screenShareRemoteParticipant.spotlight, undefined, screenShareRemoteParticipant.mediaAccess, role) : undefined,
        localParticipant: memoizeLocalParticipant(identifier, displayName, isMuted, isScreenSharingOn, localVideoStream, localScreenSharingStream, role, raisedHand, localParticipantReactionState, spotlightCallFeature === null || spotlightCallFeature === void 0 ? void 0 : spotlightCallFeature.localParticipantSpotlight, capabilities),
        remoteParticipants: _videoGalleryRemoteParticipantsMemo(_updateUserDisplayNames(remoteParticipants ? Object.values(remoteParticipants) : noRemoteParticipants), isHideAttendeeNamesEnabled, role),
        dominantSpeakers: dominantSpeakerIds,
        maxRemoteVideoStreams: optimalVideoCount,
        spotlightedParticipants: spotlightedParticipantIds,
        maxParticipantsToSpotlight: spotlightCallFeature === null || spotlightCallFeature === void 0 ? void 0 : spotlightCallFeature.maxParticipantsToSpotlight,
        togetherModeStreams: memoizeTogetherModeStreams(togetherModeCallFeature === null || togetherModeCallFeature === void 0 ? void 0 : togetherModeCallFeature.streams),
        togetherModeSeatingCoordinates: memoizeTogetherModeSeatingPositions(togetherModeCallFeature === null || togetherModeCallFeature === void 0 ? void 0 : togetherModeCallFeature.seatingPositions),
        isTogetherModeActive: togetherModeCallFeature === null || togetherModeCallFeature === void 0 ? void 0 : togetherModeCallFeature.isActive,
        startTogetherModeEnabled: capabilities === null || capabilities === void 0 ? void 0 : capabilities.startTogetherMode.isPresent
    };
});
//# sourceMappingURL=videoGallerySelector.js.map