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/menopause_symptom_logs/menopause_symptom_logsSlice'
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 EditMenopause_symptom_logs = () => {
  const router = useRouter()
  const dispatch = useAppDispatch()
  const initVals = {
      
    

    

    

    

    

    

    

    

    

    

    

    
    user: null,
    

    
    
    

    

    

    

    

    
    logged_at: new Date(),
    

    

    

    

    

    

    

    
    
    

    

    

    
    hot_flush_severity: '',
    

    

    

    

    

    

    

    

    

    
    
    

    

    

    
    hot_flush_duration_minutes: '',
    

    

    

    

    

    

    

    

    

    
    
    

    

    

    

    

    

    
    night_sweats: false,
    

    

    

    

    

    

    
    
    

    

    

    

    

    

    
    vaginal_dryness: false,
    

    

    

    

    

    

    
    
    

    

    

    

    

    

    
    brain_fog: false,
    

    

    

    

    

    

    
    
    

    

    

    

    

    

    
    sleep_disturbance: false,
    

    

    

    

    

    

    
    
    

    

    

    

    

    

    
    joint_pain: false,
    

    

    

    

    

    

    
    
    

    

    

    

    

    

    
    palpitations: false,
    

    

    

    

    

    

    
    
    

    

    

    

    

    

    
    headaches: false,
    

    

    

    

    

    

    
    
    

    

    

    

    

    

    
    urinary_symptoms: false,
    

    

    

    

    

    

    
    
    

    
    notes: '',
    

    

    

    

    

    

    

    

    

    

    

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

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

  const { menopause_symptom_logsId } = router.query

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

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

  useEffect(() => {
      if (typeof menopause_symptom_logs === 'object') {

          const newInitialVal = {...initVals};

          Object.keys(initVals).forEach(el => newInitialVal[el] = (menopause_symptom_logs)[el])

          setInitialValues(newInitialVal);
      }
  }, [menopause_symptom_logs])

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

  return (
    <>
      <Head>
        <title>{getPageTitle('Edit menopause_symptom_logs')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title={'Edit menopause_symptom_logs'} 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="LoggedAt"
      >
          <DatePicker
              dateFormat="yyyy-MM-dd hh:mm"
              showTimeSelect
              selected={initialValues.logged_at ?
                  new Date(
                      dayjs(initialValues.logged_at).format('YYYY-MM-DD hh:mm'),
                  ) : null
              }
              onChange={(date) => setInitialValues({...initialValues, 'logged_at': date})}
          />
      </FormField>
  

  

  

  

  

  

    

  



  

  

  

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

  

  

  

  

  

  

  

    

  



  

  

  

  
    <FormField
        label="HotFlushDuration(minutes)"
    >
        <Field
            type="number"
            name="hot_flush_duration_minutes"
            placeholder="HotFlushDuration(minutes)"
        />
    </FormField>
  

  

  

  

  

  

  

  

    

  



  

  

  

  

  

  

  

  

  
    <FormField label='NightSweats' labelFor='night_sweats'>
        <Field
            name='night_sweats'
            id='night_sweats'
            component={SwitchField}
        ></Field>
    </FormField>
  

  

  

    

  



  

  

  

  

  

  

  

  

  
    <FormField label='VaginalDryness' labelFor='vaginal_dryness'>
        <Field
            name='vaginal_dryness'
            id='vaginal_dryness'
            component={SwitchField}
        ></Field>
    </FormField>
  

  

  

    

  



  

  

  

  

  

  

  

  

  
    <FormField label='BrainFog' labelFor='brain_fog'>
        <Field
            name='brain_fog'
            id='brain_fog'
            component={SwitchField}
        ></Field>
    </FormField>
  

  

  

    

  



  

  

  

  

  

  

  

  

  
    <FormField label='SleepDisturbance' labelFor='sleep_disturbance'>
        <Field
            name='sleep_disturbance'
            id='sleep_disturbance'
            component={SwitchField}
        ></Field>
    </FormField>
  

  

  

    

  



  

  

  

  

  

  

  

  

  
    <FormField label='JointPain' labelFor='joint_pain'>
        <Field
            name='joint_pain'
            id='joint_pain'
            component={SwitchField}
        ></Field>
    </FormField>
  

  

  

    

  



  

  

  

  

  

  

  

  

  
    <FormField label='Palpitations' labelFor='palpitations'>
        <Field
            name='palpitations'
            id='palpitations'
            component={SwitchField}
        ></Field>
    </FormField>
  

  

  

    

  



  

  

  

  

  

  

  

  

  
    <FormField label='Headaches' labelFor='headaches'>
        <Field
            name='headaches'
            id='headaches'
            component={SwitchField}
        ></Field>
    </FormField>
  

  

  

    

  



  

  

  

  

  

  

  

  

  
    <FormField label='UrinarySymptoms' labelFor='urinary_symptoms'>
        <Field
            name='urinary_symptoms'
            id='urinary_symptoms'
            component={SwitchField}
        ></Field>
    </FormField>
  

  

  

    

  



  

  
    <FormField label="Notes" hasTextareaHeight>
        <Field name="notes" as="textarea" placeholder="Notes" />
    </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('/menopause_symptom_logs/menopause_symptom_logs-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default EditMenopause_symptom_logs
