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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    user: '',
    
    
    
    
    
    
    
    
    
    effective_from: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    effective_to: '',
    
    
    
    
    
    
    
    
    
    
    bmr: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    tdee: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    goal_mode: 'deficit',
    
    
    
    
    
    
    
    
    
    
    calorie_target: '',
    
    
    
    
    
    
    
    
    
    
    
    
    protein_target_g: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    carb_target_g: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    fat_target_g: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    macro_preset_name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}


const Nutrition_targetsNew = () => {
  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('/nutrition_targets/nutrition_targets-list')
  }
  return (
    <>
      <Head>
        <title>{getPageTitle('New Item')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="New Item" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            initialValues={
                
                
                
                dateRangeStart && dateRangeEnd ?
                {
                    ...initialValues,
                    effective_from: moment(dateRangeStart).format('YYYY-MM-DDTHH:mm'),
                    effective_to: 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="EffectiveFrom"
  >
      <Field
          type="datetime-local"
          name="effective_from"
          placeholder="EffectiveFrom"
      />
  </FormField>



























  <FormField
      label="EffectiveTo"
  >
      <Field
          type="datetime-local"
          name="effective_to"
          placeholder="EffectiveTo"
      />
  </FormField>























    <FormField
        label="BMR"
    >
        <Field
            type="number"
            name="bmr"
            placeholder="BMR"
        />
    </FormField>



























    <FormField
        label="TDEE"
    >
        <Field
            type="number"
            name="tdee"
            placeholder="TDEE"
        />
    </FormField>



































  <FormField label="GoalMode" labelFor="goal_mode">
      <Field name="goal_mode" id="goal_mode" component="select">
      
        <option value="deficit">deficit</option>
      
        <option value="maintenance">maintenance</option>
      
        <option value="surplus">surplus</option>
      
      </Field>
  </FormField>



















    <FormField
        label="CalorieTarget"
    >
        <Field
            type="number"
            name="calorie_target"
            placeholder="CalorieTarget"
        />
    </FormField>



























    <FormField
        label="ProteinTarget(g)"
    >
        <Field
            type="number"
            name="protein_target_g"
            placeholder="ProteinTarget(g)"
        />
    </FormField>



























    <FormField
        label="CarbTarget(g)"
    >
        <Field
            type="number"
            name="carb_target_g"
            placeholder="CarbTarget(g)"
        />
    </FormField>



























    <FormField
        label="FatTarget(g)"
    >
        <Field
            type="number"
            name="fat_target_g"
            placeholder="FatTarget(g)"
        />
    </FormField>





















  <FormField
      label="MacroPresetName"
  >
      <Field
          name="macro_preset_name"
          placeholder="MacroPresetName"
      />
  </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('/nutrition_targets/nutrition_targets-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default Nutrition_targetsNew
