import { dashboardComponentRoutes } from "../all-routes"
import {encryptURIparams} from '../../utility/Utils'

export const menuItems = (data, submitAction) =>{
    return{

        firstMenuItem: {
            iconName: 'trash-alt',
            menuId: 'main-1', //random generated unique id
            additionalClass: (index) => { 
                const obj = data[index]
                const commonClasses = 'btn-action btn-default'
                return !obj.IsActive  ? `disabled ${commonClasses}` :commonClasses
                

            },
            menuTarget: '#' ,
            handler: index => {
                const obj = data[index]
                /**
                 * EducatorId, deactivate
                 */
                if(obj.IsActive)
                    submitAction(ActionType.DEACTIVATE_USER, obj.UserId, false, index)
            }
            
        },
        secondMenuItem: {
            iconName: 'play',
            menuId: 'main-2', //random generated unique id
            additionalClass: (index) => { 
                const obj = data[index]
                const commonClasses = 'btn-action btn-default'
                return obj.IsActive  ? `disabled ${commonClasses}` :commonClasses


            },
            menuTarget: '#' ,
            handler: index => {
                const obj = data[index]
                /**
                 * EducatorId, activate
                 */
                if(!obj.IsActive)
                    submitAction(ActionType.ACTIVATE_USER, obj.UserId, true, index)
            }
            
        },
        dropDownItems:[{
            iconName: 'eye',
            menuId: 'sub-1', //random generated unique id
            menuTitle: 'View Profile',
            menuTarget: (index) => { 
                const { UserId } = data[index]
                var ciphertext = encryptURIparams(UserId)
                return `/dashboard/${dashboardComponentRoutes.USER_PROFILE.route}/${ciphertext}`
            }                
            
        }]
    }
}

export const ActionType = {
    ACTIVATE_USER: 'ACTIVATE_USER',
    DEACTIVATE_USER: 'DE_ACTIVATE_USER',
    VIEW_PROFILE: 'VIEW_PROFILE',
}