import AlcoholLogCardComponent from './tabs/alcohol-logs/alcohol-log.component'
import DepressionLogCardComponent from './tabs/depression-logs/depression-log.component'
import SmokeLogCardComponent from './tabs/smoke-logs/smoke-log.component'
import ErectileLogCardComponent from './tabs/erectile-logs/erectile-log.component'
import MedicalLogCardComponent from './tabs/medical-logs/medical-logs.component'
import { bmiCalculation } from '../utility/Utils'
import {initialValues as medicalLogsInitialValues} from './tabs/medical-logs/medical-logs.initial-values'
import {initialValues as alcoholLogsInitialValues} from './tabs/alcohol-logs/alcohol-logs.initial-values'
import {initialValues as depressionLogsInitialValues} from './tabs/depression-logs/depression-logs.initial-values'
import {initialValues as erectileLogsInitialValues} from './tabs/erectile-logs/erectile-log.initial-values'
import {initialValues as smokeLogsInitialValues} from './tabs/smoke-logs/smoke-log.initial-values'


import {validationSchema as medicalLogsValidationSchema} from './tabs/medical-logs/medical-logs.validation.rules'
import {validationSchema as alcoholLogsValidationSchema} from './tabs/alcohol-logs/alcohol-log.validation.rules'
import {validationSchema as depressionLogsValidationSchema} from './tabs/depression-logs/depression-log.validation.rules'
import {validationSchema as erectileLogsValidationSchema} from './tabs/erectile-logs/erectile-log.validation.rules'
import {validationSchema as smokeLogsValidationSchema} from './tabs/smoke-logs/smoke-log.validation.rules'


export const availableCards = [{
    element: MedicalLogCardComponent ,
    title: 'Medical Logs',
    id: 'medical',
    showParameter: 'showMedicalLogForm',
    index: 1,
    initialValue: medicalLogsInitialValues,
    validationSchema: medicalLogsValidationSchema,
    transformData: ({medicalLog}, currentUserId) => ({
        ...medicalLog,        
        createdBy: currentUserId,
        patientId: currentUserId,
        bmi: bmiCalculation(medicalLog.weightInKgs, medicalLog.heightInMeter)
    }),
    rootKeyInInitialValues: 'medicalLog'
},{
    element: SmokeLogCardComponent,    
    title: 'Smoke',
    id: 'smoke',
    showParameter: 'showSmokingForm',
    index: 2,
    initialValue: smokeLogsInitialValues,
    validationSchema: smokeLogsValidationSchema,
    transformData: ({smokeLog}, currentUserId) => {
        const targetObject =    {...smokeLog,total: Object.keys(smokeLog).reduce( (sum, key) => sum + parseInt(smokeLog[key]), 0)}
            
        return {
            modifiedBy: currentUserId,
            patientId: currentUserId,
            smokeLog: JSON.stringify(targetObject)
        }
    },
    rootKeyInInitialValues: 'smokeLog'
},{
    element: AlcoholLogCardComponent,    
    title: 'Alcohol',
    id: 'alcohol',
    showParameter: 'showAlcoholForm',
    index: 3 ,
    initialValue: alcoholLogsInitialValues,
    validationSchema: alcoholLogsValidationSchema,
    transformData: ({alcoholLog}, currentUserId) => {
        const targetObject =    {...alcoholLog,total: Object.keys(alcoholLog).reduce( (sum, key) => sum + parseInt(alcoholLog[key]), 0)}

        return {
            modifiedBy: currentUserId,
            patientId: currentUserId,
            alcoholLog: JSON.stringify(targetObject) 
        }
    },

    rootKeyInInitialValues: 'alcoholLog'
   
},{
    element: DepressionLogCardComponent,    
    title: 'Depression',
    id: 'depression',
    showParameter: 'showDepressionForm',
    index: 4,
    initialValue: depressionLogsInitialValues,
    validationSchema: depressionLogsValidationSchema,
    transformData: ({depressionLog}, currentUserId) => {
        const targetObject =    {...depressionLog,total: Object.keys(depressionLog).reduce( (sum, key) => sum + parseInt(depressionLog[key]), 0)}

        return {
            modifiedBy: currentUserId,
            patientId: currentUserId,
            depressionLog: JSON.stringify(targetObject)
        }
    },

    rootKeyInInitialValues: 'depressionLog'

}, {
    element: ErectileLogCardComponent,    
    title: 'Erectile Dysfunction',
    id: 'erectile',
    showParameter: 'showErectileForm',
    index: 5,
    initialValue: erectileLogsInitialValues,
    validationSchema: erectileLogsValidationSchema,
    transformData: ({erectileLog}, currentUserId) => {
        const targetObject =    {...erectileLog,total: Object.keys(erectileLog).reduce( (sum, key) => sum + parseInt(erectileLog[key]), 0)}

        return {
            modifiedBy: currentUserId,
            patientId: currentUserId,
            erectileLog: JSON.stringify(targetObject)
        }
    },

    rootKeyInInitialValues: 'erectileLog'
}]
