// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import * as reselect from 'reselect';
import { getCallExists, getDeviceManager, getIsMuted, getIsScreenSharingOn, getLocalVideoStreams } from './baseSelectors';
import { getLocalParticipantReactionState } from './baseSelectors';
import { getCapabilities, getRole } from './baseSelectors';
import { getCallState } from './baseSelectors';
import { _isPreviewOn } from './utils/callUtils';
import { getLocalParticipantRaisedHand } from './baseSelectors';
/**
 * Selector for {@link MicrophoneButton} component.
 *
 * @public
 */
export const microphoneButtonSelector = reselect.createSelector([getCallExists, getIsMuted, getDeviceManager, getCapabilities, getRole, getCallState], (callExists, isMuted, deviceManager, capabilities, role, callState) => {
    const permission = deviceManager.deviceAccess ? deviceManager.deviceAccess.audio : true;
    const incapable = (capabilities === null || capabilities === void 0 ? void 0 : capabilities.unmuteMic.isPresent) === false && (capabilities === null || capabilities === void 0 ? void 0 : capabilities.unmuteMic.reason) !== 'NotInitialized' || role === 'Consumer';
    return {
        disabled: !callExists || !permission || incapable || callState === 'LocalHold',
        checked: callExists ? !isMuted : false,
        microphones: deviceManager.microphones,
        speakers: deviceManager.speakers,
        selectedMicrophone: deviceManager.selectedMicrophone,
        selectedSpeaker: deviceManager.selectedSpeaker
    };
});
/**
 * Selector for {@link CameraButton} component.
 *
 * @public
 */
export const cameraButtonSelector = reselect.createSelector([getLocalVideoStreams, getDeviceManager, getCapabilities, getRole, getCallState], (localVideoStreams, deviceManager, capabilities, role, callState) => {
    const previewOn = _isPreviewOn(deviceManager);
    const localVideoFromCall = localVideoStreams === null || localVideoStreams === void 0 ? void 0 : localVideoStreams.find(stream => stream.mediaStreamType === 'Video');
    const permission = deviceManager.deviceAccess ? deviceManager.deviceAccess.video : true;
    const incapable = (capabilities === null || capabilities === void 0 ? void 0 : capabilities.turnVideoOn.isPresent) === false && (capabilities === null || capabilities === void 0 ? void 0 : capabilities.turnVideoOn.reason) !== 'NotInitialized' || role === 'Consumer';
    return {
        disabled: !deviceManager.selectedCamera || !permission || !deviceManager.cameras.length || incapable || callState === 'LocalHold',
        checked: localVideoStreams !== undefined && localVideoStreams.length > 0 ? !!localVideoFromCall : previewOn,
        cameras: deviceManager.cameras,
        selectedCamera: deviceManager.selectedCamera
    };
});
/**
 * Selector for {@link RaiseHandButton} component.
 *
 * @public
 */
export const raiseHandButtonSelector = reselect.createSelector([getLocalParticipantRaisedHand, getCallState], (raisedHand, callState) => {
    return {
        checked: raisedHand ? true : false,
        disabled: callState === 'InLobby' ? true : callState === 'Connecting'
    };
});
/**
 * Selector for {@link ReactionButton} component.
 *
 * @public
 */
export const reactionButtonSelector = reselect.createSelector([getLocalParticipantReactionState, getCallState], (reaction, callState) => {
    return {
        checked: reaction ? true : false,
        disabled: callState !== 'Connected'
    };
});
/**
 * Selector for {@link ScreenShareButton} component.
 *
 * @public
 */
export const screenShareButtonSelector = reselect.createSelector([getIsScreenSharingOn, getCallState, getCapabilities, getRole], (isScreenSharingOn, callState, capabilities, role) => {
    let disabled = undefined;
    disabled = disabled || (capabilities === null || capabilities === void 0 ? void 0 : capabilities.shareScreen.isPresent) === false && (capabilities === null || capabilities === void 0 ? void 0 : capabilities.shareScreen.reason) !== 'NotInitialized' || role === 'Consumer' || role === 'Attendee';
    disabled = disabled || ['InLobby', 'Connecting', 'LocalHold'].includes(callState !== null && callState !== void 0 ? callState : 'None');
    return {
        checked: isScreenSharingOn,
        disabled
    };
});
/**
 * Selector for {@link DevicesButton} component.
 *
 * @public
 */
export const devicesButtonSelector = reselect.createSelector([getDeviceManager], deviceManager => {
    return {
        microphones: removeBlankNameDevices(deviceManager.microphones),
        speakers: removeBlankNameDevices(deviceManager.speakers),
        cameras: removeBlankNameDevices(deviceManager.cameras),
        selectedMicrophone: deviceManager.selectedMicrophone,
        selectedSpeaker: deviceManager.selectedSpeaker,
        selectedCamera: deviceManager.selectedCamera
    };
});
function removeBlankNameDevices(devices) {
    return devices.filter(device => device.name !== '');
}
/**
 * Selector for the {@link HoldButton} component.
 * @public
 */
export const holdButtonSelector = reselect.createSelector([getCallState], callState => {
    return {
        checked: callState === 'LocalHold'
    };
});
//# sourceMappingURL=callControlSelectors.js.map