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/sun_exposure_logs/sun_exposure_logsSlice'
import { useAppDispatch } from '../../stores/hooks'
import { useRouter } from 'next/router'
import moment from 'moment';

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    user: '',
    
    
    
    
    
    
    
    
    
    started_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    ended_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    uv_index: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    time_outdoors_minutes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    spf_used: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    coverage_level: 'covered',
    
    
    
    
    
    
    
    vitamin_d_estimate_iu: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    sunburn_occurred: false,
    
    
    
    
    
    
    
    
    
    
    notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
}


const Sun_exposure_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('/sun_exposure_logs/sun_exposure_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,
                    started_at: moment(dateRangeStart).format('YYYY-MM-DDTHH:mm'),
                    ended_at: 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="StartedAt"
  >
      <Field
          type="datetime-local"
          name="started_at"
          placeholder="StartedAt"
      />
  </FormField>



























  <FormField
      label="EndedAt"
  >
      <Field
          type="datetime-local"
          name="ended_at"
          placeholder="EndedAt"
      />
  </FormField>























    <FormField
        label="UVIndex"
    >
        <Field
            type="number"
            name="uv_index"
            placeholder="UVIndex"
        />
    </FormField>



























    <FormField
        label="TimeOutdoors(minutes)"
    >
        <Field
            type="number"
            name="time_outdoors_minutes"
            placeholder="TimeOutdoors(minutes)"
        />
    </FormField>



























    <FormField
        label="SPFUsed"
    >
        <Field
            type="number"
            name="spf_used"
            placeholder="SPFUsed"
        />
    </FormField>



































  <FormField label="CoverageLevel" labelFor="coverage_level">
      <Field name="coverage_level" id="coverage_level" component="select">
      
        <option value="covered">covered</option>
      
        <option value="partly_covered">partly_covered</option>
      
        <option value="uncovered">uncovered</option>
      
        <option value="unknown">unknown</option>
      
      </Field>
  </FormField>



















    <FormField
        label="VitaminDEstimate(IU)"
    >
        <Field
            type="number"
            name="vitamin_d_estimate_iu"
            placeholder="VitaminDEstimate(IU)"
        />
    </FormField>





































  <FormField label='SunburnOccurred' labelFor='sunburn_occurred'>
      <Field
          name='sunburn_occurred'
          id='sunburn_occurred'
          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('/sun_exposure_logs/sun_exposure_logs-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default Sun_exposure_logsNew
