import moment from 'moment'
import { Badge } from 'react-bootstrap'
import { SubscriptionCode_Type_Enum } from '../../../redux/helpers/action-enums'

const dateFormat = "MMMM Do YYYY"
const utilityStatusToVariant = (statusCode) => {
    if(SubscriptionCode_Type_Enum.Created === parseInt(statusCode)){
        return 'primary'
    }else if(SubscriptionCode_Type_Enum.Activated === parseInt(statusCode) ){
        return 'success'
    }else if(SubscriptionCode_Type_Enum.Processing === parseInt(statusCode) ){
        return 'warning'
        
    }else if(SubscriptionCode_Type_Enum.Deactivated === parseInt(statusCode) ){
        return 'secondary'        
    }else if(SubscriptionCode_Type_Enum.Renewed === parseInt(statusCode) ){
        return 'info'        
    }else{
        return 'dark'
    }
}

const  convertToStatusName = (statusCode) => {
    if(SubscriptionCode_Type_Enum.Created === parseInt(statusCode)){
        return 'Created'
    }else if(SubscriptionCode_Type_Enum.Activated === parseInt(statusCode) ){
        return 'Active'
    }else if(SubscriptionCode_Type_Enum.Processing === parseInt(statusCode) ){
        return 'In Process'
        
    }else if(SubscriptionCode_Type_Enum.Deactivated === parseInt(statusCode) ){
        return 'In-active'        
    }
    else if(SubscriptionCode_Type_Enum.Renewed === parseInt(statusCode) ){
        return 'Renewed'        
    }
    else{
        return 'Unknown'
    }
}

const rowformatter = (subscriptionEntities) => {
    return [
        (rowIndex, fieldName)=>{
            const subscription = subscriptionEntities[rowIndex]
            const value = subscription[fieldName]
            return (<span>{value}</span>)

        },
        (rowIndex, fieldName)=>{
            const subscription = subscriptionEntities[rowIndex]
            const value = subscription[fieldName]
            return (<span>{value}</span>)
        },
        (rowIndex, fieldName)=>{
            const subscription = subscriptionEntities[rowIndex]
            const value = subscription[fieldName]
            return (<span>{value}</span>)
        },
        (rowIndex, fieldName)=>{
            const subscription = subscriptionEntities[rowIndex]
            const value = subscription[fieldName]
            return (<span>{value}</span>)
        },
        (rowIndex, fieldName)=>{
            const subscription = subscriptionEntities[rowIndex]
            const value = subscription[fieldName] 
            const finalValue =  !!value ? moment(value).format(dateFormat) : "-"

            return (<span>{finalValue}</span>)

        },
        (rowIndex, fieldName)=>{
            const subscription = subscriptionEntities[rowIndex]
            const value = subscription[fieldName] 
            const finalValue =  !!value ? moment(value).format(dateFormat) : "-"

            return (<span>{finalValue}</span>)
        },
        (rowIndex, fieldName)=>{
            const subscription = subscriptionEntities[rowIndex]
            const value = subscription[fieldName]
            return (<Badge variant={`${utilityStatusToVariant(value)}`}>{convertToStatusName(value)}</Badge>)
        }
    ]
}

const headers= [
    { name: "Subscription Code", field: "SubsCode", sortable: false },
    { name: "Doctor", field: "DoctorDisplayName", sortable: false },
    { name: "Educator", field: "EducatorDisplayName", sortable: false },
    { name: "Patient", field: "PatientDisplayName", sortable: false },
    { name: "Start date", field: "StartDate", sortable: false },
    { name: "End date", field: "EndDate", sortable: false },
    { name: "Status", field: "State", sortable: false },    
]

export { rowformatter, headers }
