import { createSelector } from 'reselect'
import { MettaSvr_Common } from '../../helpers/action-enums'

export const getCurrentUser = state => state.user.currentUser
export const getPatientList = state => state.patientList.result
export const getPatientListIsFetching = state => state.patientList.inProgress
export const getErrorMessage = state => state.patientList.errorMessages
export const getGetIsDoctor = state => state.user.currentUser.userType === MettaSvr_Common.UserTypeEnum.Doctor
export const getGetIsEducator = state => state.user.currentUser.userType === MettaSvr_Common.UserTypeEnum.Educator
export const getSavedResult = state => state.patientList.saveResult
export const getIsSaving = state => state.patientList.submissionInProgress
export const getTotalItems = state => state.patientList.recordCount
export const getUpdateIndex = state => state.patientList.updateIndex
export const getTargetPatient = state => state.patientList.targetPatientId

export const getAccessToken = createSelector(
    getCurrentUser,
    user => user.accessToken
)
export const getCurrentUserId = createSelector(
    getCurrentUser,
    user => user.userId
)

export const getPatientsAsKeyValue  = createSelector(
    getPatientList,
    ( patientList ) => [
        {key: 'Select Patient', value: ''},
        ...patientList.map((patient, i) => ({ key: `${patient.PatientName}_${i}`, value: patient.PatientId}))
    ],
    
)