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

export const dateFormatters = {displayFormat : "DD MMM YYYY", computeFormat : "YYYY-MM-DD"}
export const momentObjects = {today : moment(), todayMinus1: moment().add(-1, 'days'), todayMinus2:moment().add(-2, 'days')}

export const rowformatter = (data, onImageTap) =>{
    
    return [
        (rowIndex, fieldName)=>{
            const obj = data[rowIndex]
            const value = obj[fieldName]
            return <span >{value}</span>
        },
        (rowIndex, fieldName)=>{
            const obj = data[rowIndex]            
            const logtype = obj[fieldName]
            return (logtype === DailyLog_Enums.DailyLogsCTEnum.InsulinUnit ? <span>{obj["Details"]}</span>: null)
        },        
        (rowIndex, fieldName)=>{
            const obj = data[rowIndex]            
            const logtype = obj[fieldName]
            return (logtype === DailyLog_Enums.DailyLogsCTEnum.SugarValue ? <span>{obj["Details"]}</span>: null)
        },        
        (rowIndex, fieldName)=>{
            const obj = data[rowIndex]            
            const logtype = obj[fieldName]
            return (logtype === DailyLog_Enums.DailyLogsCTEnum.Exercise ? <span>{obj["Details"]}</span>: null)
        },        
        (rowIndex, fieldName)=>{
            const obj = data[rowIndex]            
            const logtype = obj[fieldName]
            return (logtype === DailyLog_Enums.DailyLogsCTEnum.Medication ? <span>{obj["Details"]}</span>: null)
        },        
        (rowIndex, fieldName)=>{
            const obj = data[rowIndex]            
            const logtype = obj[fieldName]
            return (logtype === DailyLog_Enums.DailyLogsCTEnum.BloodPressure ? <span>{obj["Details"]}</span>: null)
        },        
        (rowIndex, fieldName)=>{
            const obj = data[rowIndex]            
            const logtype = obj[fieldName]
            return (
                logtype === DailyLog_Enums.DailyLogsCTEnum.Food ? 
                    <div className="food-img" onClick={() => { 
                            if(!!obj["photo_uploaded"]){

                                onImageTap(obj["photo_uploaded"])
                            } 
                        }
                    }>
                        <img src={obj["photo_uploaded"]} className="" />
                    </div>: 
                null)
        },        
        (rowIndex, fieldName)=>{
            const obj = data[rowIndex]            
            const value = obj[fieldName]
            return <span >{value}</span>
        },        
        (rowIndex, fieldName)=>{
            const obj = data[rowIndex]            
            const value = obj[fieldName]
            return ( value === DailyLog_Enums.CriticalityStatusEnum.Danger ? <span className="d-flex justify-content-center color-dot text-danger">
                <i className="fa fa-long-arrow-left"></i>
            </span>: null)
        },        
        
    ]
}

export const headers = [
    { name: "Time", field: "LogTime", sortable: false },
    { name: "Insulin (units)", field: "LogType", sortable: true },
    { name: "Sugar (mg/dl)", field: "LogType", sortable: true },
    { name: "Exercise", field: "LogType", sortable: true },
    { name: "Medication", field: "LogType", sortable: true },
    { name: "BP", field: "LogType", sortable: true },
    { name: "Food", field: "LogType", sortable: false },
    { name: "Comments", field: "Comments", sortable: false },
    { name: "Criticality", field: "CriticalityStatus", sortable: false }
]

const utilityStatusToVariant = (status) => {
    if(0 == status.toLocaleLowerCase().localeCompare('severe') ){
        return 'danger'
    }else if(0 == status.toLocaleLowerCase().localeCompare('normal') ){
        return 'success'
        
    }else{
        return 'warning'
    }
}