import {SubscriptionCode_Type_Enum} from '../../../redux/helpers/action-enums'
const menuItemsForPatient = (data, submitAction) => {
    return {
        firstMenuItem: {
            iconName: 'bolt',
            menuId: 'main-1', //random generated unique id
            additionalClass: (index) => {
                const obj = data[index]
                const commonClasses = obj.RenewalActive ? 'btn-action btn-default' : 'invisible'
                return commonClasses
            },
            menuTarget: '#',
            handler: (index, evt) => {
                const obj = data[index]
                 /**
                 * SubscriptionId, Action type
                 */
                  const postEntity = {
                    SubscriptionId: obj.SubscriptionId,
                    subsCode: obj.SubsCode,
                    // EducatorId: "",
                    indexOfRecord: index,
                    type: subscriptionActionType.RENEW
                }
                submitAction(postEntity) 
                
            }
        },
        dropDownItems:[]
    }
}

const menuItems = (data, submitAction, popoverContent) => {
    return {
        firstMenuItem: {
            showInPopover: true,
            popoverContent: popoverContent,
            popoverTitle: "Available Educator",
            iconName: 'user-tag',
            menuId: 'main-1', //random generated unique id
            additionalClass: (index) => {
                const obj = data[index]
                const commonClasses = 'btn-action btn-default'
                return parseInt(obj.State) !== SubscriptionCode_Type_Enum.Processing && SubscriptionCode_Type_Enum.Deactivated  ? commonClasses : `invisible ${commonClasses}`
            },
            menuTarget: '#',
            handler: (index, evt, targetEducatorId ) => {
                const obj = data[index]
                console.log(`🦋 ${index} ${targetEducatorId}`);
                 /**
                 * SubscriptionId, Action type
                 
                  */
                const postEntity = {
                    SubscriptionId: obj.SubscriptionId,
                    EducatorId: targetEducatorId,
                    indexOfRecord: index,
                    type: subscriptionActionType.CHANGE_EDUCATOR
                }
                submitAction(postEntity) 
            }
        },
        secondMenuItem: {
            iconName: 'trash-alt',
            menuId: 'main-2', //random generated unique id
            additionalClass: (index) => { 
                const obj = data[index]
                const commonClasses = 'btn-action btn-default'
                return parseInt(obj.State) === SubscriptionCode_Type_Enum.Created ? commonClasses : `invisible ${commonClasses}`

            },
            menuTarget: '#' ,
            handler: index => {
                const obj = data[index]
                /**
                 * SubscriptionId, Action type
                 */
                 const postEntity = {
                    SubscriptionId: obj.SubscriptionId,
                    // EducatorId: "",
                    State: SubscriptionCode_Type_Enum.Deactivated,
                    indexOfRecord: index,
                    type: subscriptionActionType.DEACTIVATE
                }
                submitAction(postEntity)
            }
            
        },
        dropDownItems:[]
    }
}

const subscriptionActionType = {
    DEACTIVATE: 1001,
    CHANGE_EDUCATOR: 1002,
    RENEW:1003
}

export {menuItems, menuItemsForPatient, subscriptionActionType}