// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { toFlatCommunicationIdentifier } from "../../../../../acs-ui-common/src";
import * as reselect from 'reselect';
import { getRemoteParticipants, getSpotlightedParticipants } from './baseSelectors';
/**
 * Get the first remote participant that is spotlighted if any
 *
 * @private
 */
export const getFirstSpotlightedRemoteParticipant = reselect.createSelector([getRemoteParticipants, getSpotlightedParticipants], (remoteParticipants, spotlightedParticipants) => {
    const spotlightedParticipantUserIds = spotlightedParticipants ? spotlightedParticipants.map(p => toFlatCommunicationIdentifier(p.identifier)) : [];
    const firstSpotlightedRemoteParticipant = remoteParticipants ? findFirstSpotlightedRemoteParticipant(remoteParticipants, spotlightedParticipantUserIds) : undefined;
    return firstSpotlightedRemoteParticipant;
});
const findFirstSpotlightedRemoteParticipant = (remoteParticipants, spotlightedParticipantUserIds) => {
    const remoteParticipantIds = Object.keys(remoteParticipants);
    const spotlightedRemoteParticipantUserIds = spotlightedParticipantUserIds.filter(p => remoteParticipantIds.includes(p));
    return spotlightedRemoteParticipantUserIds[0] ? remoteParticipants[spotlightedRemoteParticipantUserIds[0]] : undefined;
};
//# sourceMappingURL=getFirstSpotlightedRemoteParticipantSelector.js.map