import { mdiAccount, mdiChartTimelineVariant, mdiMail, mdiUpload } from '@mdi/js'
import Head from 'next/head'
import React, { ReactElement } from 'react'
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 { SwitchField } from '../../components/SwitchField'

import { SelectField } from '../../components/SelectField'
import { SelectFieldMany } from "../../components/SelectFieldMany";
import {RichTextField} from "../../components/RichTextField";

import { create } from '../../stores/sleep_logs/sleep_logsSlice'
import { useAppDispatch } from '../../stores/hooks'
import { useRouter } from 'next/router'
import moment from 'moment';

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    user: '',
    
    
    
    
    
    
    
    
    
    bedtime: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    sleep_onset_time: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    awakenings_count: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    final_wake_time: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    out_of_bed_time: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    total_sleep_minutes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    sleep_quality: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    dream_recall: false,
    
    
    
    
    
    
    
    
    
    
    dream_notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    morning_energy: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    sleep_aids_used: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    disturbances: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
}


const Sleep_logsNew = () => {
  const router = useRouter()
  const dispatch = useAppDispatch()

    
    
    // get from url params
    const { dateRangeStart, dateRangeEnd } = router.query
    

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/sleep_logs/sleep_logs-list')
  }
  return (
    <>
      <Head>
        <title>{getPageTitle('New Item')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="New Item" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            initialValues={
                
                
                
                dateRangeStart && dateRangeEnd ?
                {
                    ...initialValues,
                    bedtime: moment(dateRangeStart).format('YYYY-MM-DDTHH:mm'),
                    out_of_bed_time: moment(dateRangeEnd).format('YYYY-MM-DDTHH:mm'),
                } : initialValues
                
            }
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>





















  <FormField label="User" labelFor="user">
      <Field name="user" id="user" component={SelectField} options={[]} itemRef={'users'}></Field>
  </FormField>



















  <FormField
      label="Bedtime"
  >
      <Field
          type="datetime-local"
          name="bedtime"
          placeholder="Bedtime"
      />
  </FormField>



























  <FormField
      label="SleepOnsetTime"
  >
      <Field
          type="datetime-local"
          name="sleep_onset_time"
          placeholder="SleepOnsetTime"
      />
  </FormField>























    <FormField
        label="AwakeningsCount"
    >
        <Field
            type="number"
            name="awakenings_count"
            placeholder="AwakeningsCount"
        />
    </FormField>































  <FormField
      label="FinalWakeTime"
  >
      <Field
          type="datetime-local"
          name="final_wake_time"
          placeholder="FinalWakeTime"
      />
  </FormField>



























  <FormField
      label="OutofBedTime"
  >
      <Field
          type="datetime-local"
          name="out_of_bed_time"
          placeholder="OutofBedTime"
      />
  </FormField>























    <FormField
        label="TotalSleepTime(minutes)"
    >
        <Field
            type="number"
            name="total_sleep_minutes"
            placeholder="TotalSleepTime(minutes)"
        />
    </FormField>



























    <FormField
        label="SleepQuality(1-5)"
    >
        <Field
            type="number"
            name="sleep_quality"
            placeholder="SleepQuality(1-5)"
        />
    </FormField>





































  <FormField label='DreamRecall' labelFor='dream_recall'>
      <Field
          name='dream_recall'
          id='dream_recall'
          component={SwitchField}
      ></Field>
  </FormField>













    <FormField label="DreamNotes" hasTextareaHeight>
        <Field name="dream_notes" as="textarea" placeholder="DreamNotes" />
    </FormField>































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























    <FormField label="SleepAidsUsed" hasTextareaHeight>
        <Field name="sleep_aids_used" as="textarea" placeholder="SleepAidsUsed" />
    </FormField>



























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

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

export default Sleep_logsNew
