import moment from 'moment'
import { MettaSvr_Common } from "../../../../redux/helpers/action-enums"
import { getRandomColorGenerated } from '../../../utility/Utils'

const transformToChartData = (dataset=[]) => ({
    labels: dataset.map(ele => moment(ele.CreatedAt).format("DD/MM/YY")),
    datasets: [
      {
        label: 'Criticality Status',
        custom: dataset.map(ele => ele.CriticalityStatusStr),
        data: dataset.map(ele => ele.CriticalityStatus),
        backgroundColor: dataset.map(ele => {
          if(MettaSvr_Common.PatientStatusEnum.Severe === ele.CriticalityStatus){
            return '#ff3a5266'
          }else if(MettaSvr_Common.PatientStatusEnum.Normal === ele.CriticalityStatus ){
            return '#70bf5166'
            
          }else{
            return '#ffab0866'
          }
        }),
        borderColor: dataset.map(
          ele => {
            if(MettaSvr_Common.PatientStatusEnum.Severe === ele.CriticalityStatus){
              return '#ff3a52'
            }else if(MettaSvr_Common.PatientStatusEnum.Normal === ele.CriticalityStatus ){
              return '#70bf51'
              
            }else{
              return '#ffab08'
            }
          }
        ),
        borderWidth: 1,
      },
    ],
  })

const options = {
  indexAxis: 'x',
  plugins: {
    tooltip: {
        callbacks: {
            label: function(context) {
                return context.dataset.custom[context.dataIndex]                
            }
        }
    }
  }
}

export {  transformToChartData, options}
