import * as _ from 'lodash-es';
export const getAudioState = (src, restrictedAudioId) => (state) => {
    const { nowPlaying } = state.audio;
    return nowPlaying == null
        ? 'stopped'
        : nowPlaying.audio.restrictedAudioId === restrictedAudioId && nowPlaying.audio.src === src
            ? 'playing'
            : 'other-playing';
};
export const getAudioPlaybackError = (src, restrictedAudioId) => (state) => state.audio.errors[restrictedAudioId != null ? restrictedAudioId : src];
export const getDurationRemaining = (src, restrictedAudioId) => (state) => getAudioState(src, restrictedAudioId)(state) === 'playing' ? state.audio.nowPlaying.durationRemaining : undefined;
export const getPlaybackTimes = (restrictedAudioId) => (state) => _.get(state.audio.playbackTimes, restrictedAudioId, 0);
export const getPlaybackTimesRemaining = (restrictedAudioId, times) => (state) => times - getPlaybackTimes(restrictedAudioId)(state);
export const getSaveState = (state) => {
    const { serverQuestionIds, savedQuestionIds, answersById } = state.answers;
    if (serverQuestionIds.size === 0) {
        return 'initial';
    }
    else if (serverQuestionIds.size !== savedQuestionIds.size ||
        containsAnswerNotYetSavedInServer(serverQuestionIds, answersById)) {
        return 'saving';
    }
    else {
        return 'saved';
    }
};
function containsAnswerNotYetSavedInServer(serverIds, answersById) {
    for (const questionId in answersById) {
        if (!serverIds.has(Number(questionId))) {
            return true;
        }
    }
    return false;
}
//# sourceMappingURL=selectors.js.map