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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    user: '',
    
    
    
    
    recipe_name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    photo: [],
    
    
    
    
    
    
    
    
    prep_time_minutes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    cook_time_minutes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    servings: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    difficulty: 'beginner',
    
    
    
    
    
    
    
    tags_csv: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    ingredients_text: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    instructions_text: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    nutrition_per_serving_json: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    is_favourite: false,
    
    
    
    
    
    
    
    
    
    rating: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    source_url: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}


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

    
    

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/recipes/recipes-list')
  }
  return (
    <>
      <Head>
        <title>{getPageTitle('New Item')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="New Item" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            initialValues={
                
                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="RecipeName"
  >
      <Field
          name="recipe_name"
          placeholder="RecipeName"
      />
  </FormField>

















































  <FormField>
      <Field
          label='Photo'
          color='info'
          icon={mdiUpload}
          path={'recipes/photo'}
          name='photo'
          id='photo'
          schema={{
            size: undefined,
            formats: undefined,
          }}
          component={FormImagePicker}
      ></Field>
  </FormField>











    <FormField
        label="PrepTime(minutes)"
    >
        <Field
            type="number"
            name="prep_time_minutes"
            placeholder="PrepTime(minutes)"
        />
    </FormField>



























    <FormField
        label="CookTime(minutes)"
    >
        <Field
            type="number"
            name="cook_time_minutes"
            placeholder="CookTime(minutes)"
        />
    </FormField>



























    <FormField
        label="Servings"
    >
        <Field
            type="number"
            name="servings"
            placeholder="Servings"
        />
    </FormField>



































  <FormField label="Difficulty" labelFor="difficulty">
      <Field name="difficulty" id="difficulty" component="select">
      
        <option value="beginner">beginner</option>
      
        <option value="intermediate">intermediate</option>
      
        <option value="chef">chef</option>
      
      </Field>
  </FormField>













  <FormField
      label="Tags"
  >
      <Field
          name="tags_csv"
          placeholder="Tags"
      />
  </FormField>





























    <FormField label="Ingredients" hasTextareaHeight>
        <Field name="ingredients_text" as="textarea" placeholder="Ingredients" />
    </FormField>



























    <FormField label="Instructions" hasTextareaHeight>
        <Field name="instructions_text" as="textarea" placeholder="Instructions" />
    </FormField>



























    <FormField label="NutritionPerServingJSON" hasTextareaHeight>
        <Field name="nutrition_per_serving_json" as="textarea" placeholder="NutritionPerServingJSON" />
    </FormField>









































  <FormField label='Favourite' labelFor='is_favourite'>
      <Field
          name='is_favourite'
          id='is_favourite'
          component={SwitchField}
      ></Field>
  </FormField>

















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





















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

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

export default RecipesNew
