import { Badge } from 'react-bootstrap'
import { MettaSvr_Common, MedicalLog_Enums} from "../../../redux/helpers/action-enums";
import { utilityStatusToVariant } from "../all-educators/datatable.intializers";
const rowformatterForDoctor = (patients) => {
    return [
        (rowIndex, fieldName)=>{
            const patient = patients[rowIndex]
            const value = patient[fieldName]
            return (<span>{value}</span>)
        },
        (rowIndex, fieldName)=>{
            const patient = patients[rowIndex]
            const value = patient[fieldName]
            return (<Badge variant={`${PatientListUtilityStatusToVariant(value)}`}>{PatientListConvertToStatusName(value)}</Badge>)
        },
        (rowIndex, fieldName)=>{
            const patient = patients[rowIndex]
            const value = patient[fieldName]
            return (<span>{value}</span>)
        },
        (rowIndex, fieldName)=>{
            const patient = patients[rowIndex]
            const value = patient[fieldName]
            return (<span>{value.trim()}</span>)
        },
        (rowIndex, fieldName)=>{
            const patient = patients[rowIndex]
            const value = patient[fieldName]
            return (<span>{value}</span>)
        },
        (rowIndex, fieldName)=>{
            const patient = patients[rowIndex]
            const value = patient[fieldName]
            return (<span>{value}</span>)
        },
        (rowIndex, fieldName)=>{
            const patient = patients[rowIndex]
            const values = JSON.parse(patient[fieldName])
            const diseases = values.map(val => {
                for (const key in MedicalLog_Enums.MedicalHistoryCTEnum) {
                    if (MedicalLog_Enums.MedicalHistoryCTEnum[key] === val) {
                        return MedicalLog_Enums.MedicalHistoryCTEnumToText[key]                        
                    }
                }
                return '' 
            })
            return (<span>{diseases.join()}</span>)
        },
        (rowIndex, fieldName)=>{
            const patient = patients[rowIndex]
            const value = patient[fieldName]
            return (<Badge pill variant={`${utilityStatusToVariant(value)}`}>&nbsp;</Badge>)
        }
    ]
}

const rowformatterForEducator = (patients) => {
    return [
    (rowIndex, fieldName)=>{
        const patient = patients[rowIndex]
        const value = patient[fieldName]
        return (<span>{value}</span>)
    },
    (rowIndex, fieldName)=>{
        const patient = patients[rowIndex]
        const value = patient[fieldName]
        return (<Badge variant={`${PatientListUtilityStatusToVariant(value)}`}>{PatientListConvertToStatusName(value)}</Badge>)
    },
    (rowIndex, fieldName)=>{
        const patient = patients[rowIndex]
        const value = patient[fieldName]
        return (<span>{value}</span>)
    },
    (rowIndex, fieldName)=>{
        const patient = patients[rowIndex]
        const value = patient[fieldName]
        return (<span>{value}</span>)
    }
    ]
}

const headersDoctor = [
    { name: "Subscription Code", field: "SubsCode", sortable: false },
    { name: "Color Code", field: "CriticalityStatus", sortable: false },
    { name: "Patient Name", field: "PatientName", sortable: false },
    { name: "Patient Contact No.", field: "PatientContact", sortable: false },
    { name: "Patient Email Id", field: "PatientEmail", sortable: false },
    { name: "Educator Name", field: "EducatorName", sortable: false },
    { name: "Disease Type", field: "diseaseType", sortable: false },
    { name: "Status", field: "Status", sortable: false },
]

const headersEducator = [
    { name: "Subscription Code", field: "SubsCode", sortable: false },
    { name: "Color Code", field: "CriticalityStatus", sortable: false },
    { name: "Patient Name", field: "PatientName", sortable: false },
    { name: "Educator Name", field: "EducatorName", sortable: false },
]

export { headersDoctor, headersEducator, rowformatterForDoctor, rowformatterForEducator}

const PatientListConvertToStatusName = (statusCode) => {
    if(MettaSvr_Common.PatientStatusEnum.Severe === parseInt(statusCode)){
        return 'Severe'
    }else if(MettaSvr_Common.PatientStatusEnum.Normal === parseInt(statusCode) ){
        return 'Normal'
        
    }else{
        return 'Moderate'
    }
}

export const PatientListUtilityStatusToVariant = (statusCode) => {
    if(MettaSvr_Common.PatientStatusEnum.Severe === parseInt(statusCode)){
        return 'danger'
    }else if(MettaSvr_Common.PatientStatusEnum.Normal === parseInt(statusCode) ){
        return 'success'
        
    }else{
        return 'warning'
    }
}