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

export const getCurrentUser = state => state.user.currentUser
export const getEducatorList = state => state.educatorList.result
export const getGetIsDoctor = state => state.user.currentUser.userType === MettaSvr_Common.UserTypeEnum.Doctor
export const getSubscriptionCoderFetchInProgress = state => state.subscriptionCoder.inProgress
export const getSubscriptionCoderFetchingErrorMessages = state => state.subscriptionCoder.errorMessages
export const getSubscriptionCodeResult = state => state.subscriptionCoder.result

export const getDoctors  = createSelector(
    getCurrentUser,
    getGetIsDoctor,
    ( user , doctor) => doctor ? [
            { key: user.doctorName, value: user.userId}
            // Let the super admin user see doctor name instead of self
            // { key: user.loginUserName, value: user.userId}
        ]:[
            { key: user.doctorName, value: user.doctorUserId}
        ],
    
)

export const getEducators  = createSelector(
    getCurrentUser,
    getEducatorList,
    getGetIsDoctor,
    ( user , educators, doctor) => doctor ? [
            {key: 'Select educator', value: ''},
            ...educators.map((educator) => ({ key: `${educator.FirstName} ${educator.LastName} (${educator.EducatorPublicId})`, value: educator.UserId}))
        ]:[
            { key: user.loginUserName, value: user.userId}

        ]    
)