import { mdiChartTimelineVariant, mdiUpload } from '@mdi/js'
import Head from 'next/head'
import React, { ReactElement, useEffect, useState } from 'react'
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";
import dayjs from "dayjs";

import CardBox from '../../components/CardBox'
import LayoutAuthenticated from '../../layouts/Authenticated'
import SectionMain from '../../components/SectionMain'
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton'
import { getPageTitle } from '../../config'

import { Field, Form, Formik } from 'formik'
import FormField from '../../components/FormField'
import BaseDivider from '../../components/BaseDivider'
import BaseButtons from '../../components/BaseButtons'
import BaseButton from '../../components/BaseButton'
import FormCheckRadio from '../../components/FormCheckRadio'
import FormCheckRadioGroup from '../../components/FormCheckRadioGroup'
import FormFilePicker from '../../components/FormFilePicker'
import FormImagePicker from '../../components/FormImagePicker'
import { SelectField } from "../../components/SelectField";
import { SelectFieldMany } from "../../components/SelectFieldMany";
import { SwitchField } from '../../components/SwitchField'
import {RichTextField} from "../../components/RichTextField";

import { update, fetch } from '../../stores/user_lifestyle_baselines/user_lifestyle_baselinesSlice'
import { useAppDispatch, useAppSelector } from '../../stores/hooks'
import { useRouter } from 'next/router'
import {saveFile} from "../../helpers/fileSaver";
import dataFormatter from '../../helpers/dataFormatter';
import ImageField from "../../components/ImageField";



const EditUser_lifestyle_baselinesPage = () => {
  const router = useRouter()
  const dispatch = useAppDispatch()
  const initVals = {
      
    

    

    

    

    

    

    

    

    

    

    

    
    user: null,
    

    
    
    
    'typical_bedtime': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    
    'typical_wake_time': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    

    

    

    

    

    

    

    

    
    alcohol_use: '',
    

    

    

    

    
    
    

    

    

    

    

    

    

    

    
    tobacco_nicotine_use: '',
    

    

    

    

    
    
    

    
    recreational_substance_use: '',
    

    

    

    

    

    

    

    

    

    

    

    
    
    

    

    

    
    caffeine_servings_per_day: '',
    

    

    

    

    

    

    

    

    

    
    
    

    

    

    
    typical_stress_level: '',
    

    

    

    

    

    

    

    

    

    
    
    

    

    

    

    

    

    

    

    
    occupation_type: '',
    

    

    

    

    
    
    

    

    

    
    avg_daily_steps_estimate: '',
    

    

    

    

    

    

    

    

    

    
    
    

    

    

    

    

    

    
    currently_exercises: false,
    

    

    

    

    

    

    
    
    

    
    exercise_types: '',
    

    

    

    

    

    

    

    

    

    

    

    
    
    

    

    

    

    

    

    

    

    
    diet_pattern: '',
    

    

    

    

    
    
    
    'diet_pattern_other': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    
  }
  const [initialValues, setInitialValues] = useState(initVals)

  const { user_lifestyle_baselines } = useAppSelector((state) => state.user_lifestyle_baselines)
  

  const { id } = router.query

  useEffect(() => {
    dispatch(fetch({ id: id }))
  }, [id])

  useEffect(() => {
    if (typeof user_lifestyle_baselines === 'object') {
      setInitialValues(user_lifestyle_baselines)
    }
  }, [user_lifestyle_baselines])

  useEffect(() => {
      if (typeof user_lifestyle_baselines === 'object') {
          const newInitialVal = {...initVals};
          Object.keys(initVals).forEach(el => newInitialVal[el] = (user_lifestyle_baselines)[el])
          setInitialValues(newInitialVal);
      }
  }, [user_lifestyle_baselines])

  const handleSubmit = async (data) => {
    await dispatch(update({ id: id, data }))
    await router.push('/user_lifestyle_baselines/user_lifestyle_baselines-list')
  }

  return (
    <>
      <Head>
        <title>{getPageTitle('Edit user_lifestyle_baselines')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title={'Edit user_lifestyle_baselines'} main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            enableReinitialize
            initialValues={initialValues}
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>


  

  

  

  

  

  

  

  

  

  
  
    <FormField label='User' labelFor='user'>
        <Field
            name='user'
            id='user'
            component={SelectField}
            options={initialValues.user}
            itemRef={'users'}
      
        
            showField={'firstName'}
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        ></Field>
    </FormField>
    

  

  

    

  



  
    <FormField
        label="TypicalBedtime"
    >
        <Field
            name="typical_bedtime"
            placeholder="TypicalBedtime"
        />
    </FormField>
  

  

  

  

  

  

  

  

  

  

  

    

  



  
    <FormField
        label="TypicalWakeTime"
    >
        <Field
            name="typical_wake_time"
            placeholder="TypicalWakeTime"
        />
    </FormField>
  

  

  

  

  

  

  

  

  

  

  

    

  



  

  

  

  

  

  

  

  
    <FormField label="AlcoholConsumption" labelFor="alcohol_use">
        <Field name="alcohol_use" id="alcohol_use" component="select">
          
            <option value="never">never</option>
          
            <option value="social">social</option>
          
            <option value="weekly">weekly</option>
          
            <option value="daily">daily</option>
          
            <option value="trying_to_quit">trying_to_quit</option>
          
        </Field>
    </FormField>
  

  

  

  

    

  



  

  

  

  

  

  

  

  
    <FormField label="TobaccoorNicotineUse" labelFor="tobacco_nicotine_use">
        <Field name="tobacco_nicotine_use" id="tobacco_nicotine_use" component="select">
          
            <option value="never">never</option>
          
            <option value="ex_smoker">ex_smoker</option>
          
            <option value="current_smoker">current_smoker</option>
          
            <option value="vaper">vaper</option>
          
            <option value="chewing_tobacco">chewing_tobacco</option>
          
        </Field>
    </FormField>
  

  

  

  

    

  



  

  
    <FormField label="RecreationalSubstanceUse" hasTextareaHeight>
        <Field name="recreational_substance_use" as="textarea" placeholder="RecreationalSubstanceUse" />
    </FormField>
  

  

  

  

  

  

  

  

  

  

    

  



  

  

  

  
    <FormField
        label="CaffeineServingsperDay"
    >
        <Field
            type="number"
            name="caffeine_servings_per_day"
            placeholder="CaffeineServingsperDay"
        />
    </FormField>
  

  

  

  

  

  

  

  

    

  



  

  

  

  
    <FormField
        label="TypicalStressLevel(1-10)"
    >
        <Field
            type="number"
            name="typical_stress_level"
            placeholder="TypicalStressLevel(1-10)"
        />
    </FormField>
  

  

  

  

  

  

  

  

    

  



  

  

  

  

  

  

  

  
    <FormField label="OccupationType" labelFor="occupation_type">
        <Field name="occupation_type" id="occupation_type" component="select">
          
            <option value="sedentary_desk_job">sedentary_desk_job</option>
          
            <option value="active_job">active_job</option>
          
            <option value="manual_labour">manual_labour</option>
          
            <option value="variable">variable</option>
          
            <option value="not_working">not_working</option>
          
            <option value="student">student</option>
          
            <option value="retired">retired</option>
          
        </Field>
    </FormField>
  

  

  

  

    

  



  

  

  

  
    <FormField
        label="AverageDailyStepsEstimate"
    >
        <Field
            type="number"
            name="avg_daily_steps_estimate"
            placeholder="AverageDailyStepsEstimate"
        />
    </FormField>
  

  

  

  

  

  

  

  

    

  



  

  

  

  

  

  

  

  

  
    <FormField label='CurrentlyExercises' labelFor='currently_exercises'>
        <Field
            name='currently_exercises'
            id='currently_exercises'
            component={SwitchField}
        ></Field>
    </FormField>
  

  

  

    

  



  

  
    <FormField label="ExerciseTypes" hasTextareaHeight>
        <Field name="exercise_types" as="textarea" placeholder="ExerciseTypes" />
    </FormField>
  

  

  

  

  

  

  

  

  

  

    

  



  

  

  

  

  

  

  

  
    <FormField label="DietPattern" labelFor="diet_pattern">
        <Field name="diet_pattern" id="diet_pattern" component="select">
          
            <option value="omnivore">omnivore</option>
          
            <option value="vegetarian">vegetarian</option>
          
            <option value="vegan">vegan</option>
          
            <option value="pescatarian">pescatarian</option>
          
            <option value="keto">keto</option>
          
            <option value="paleo">paleo</option>
          
            <option value="mediterranean">mediterranean</option>
          
            <option value="halal">halal</option>
          
            <option value="kosher">kosher</option>
          
            <option value="gluten_free">gluten_free</option>
          
            <option value="dairy_free">dairy_free</option>
          
            <option value="low_fodmap">low_fodmap</option>
          
            <option value="other">other</option>
          
        </Field>
    </FormField>
  

  

  

  

    

  



  
    <FormField
        label="DietPatternOther"
    >
        <Field
            name="diet_pattern_other"
            placeholder="DietPatternOther"
        />
    </FormField>
  

  

  

  

  

  

  

  

  

  

  

    

  


  

              <BaseDivider />
              <BaseButtons>
                <BaseButton type="submit" color="info" label="Submit" />
                <BaseButton type="reset" color="info" outline label="Reset" />
                <BaseButton type='reset' color='danger' outline label='Cancel' onClick={() => router.push('/user_lifestyle_baselines/user_lifestyle_baselines-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

EditUser_lifestyle_baselinesPage.getLayout = function getLayout(page: ReactElement) {
  return (
      <LayoutAuthenticated
        
          permission={'UPDATE_USER_LIFESTYLE_BASELINES'}
        
      >
          {page}
      </LayoutAuthenticated>
  )
}

export default EditUser_lifestyle_baselinesPage
