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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    farm_plot: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    crop: '',
    
    
    
    
    
    
    
    
    
    planted_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    estimated_harvest_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'planted',
    
    
    
    
    
    
    
    
    
    
    quantity_planted: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    watered_today: '',
    
    
    
    
    
    
    
    
    
    
    
}


const PlantingsNew = () => {
  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('/plantings/plantings-list')
  }
  return (
    <>
      <Head>
        <title>{getPageTitle('New Item')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="New Item" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            initialValues={
                
                
                
                dateRangeStart && dateRangeEnd ?
                {
                    ...initialValues,
                    planted_at: moment(dateRangeStart).format('YYYY-MM-DDTHH:mm'),
                    estimated_harvest_at: moment(dateRangeEnd).format('YYYY-MM-DDTHH:mm'),
                } : initialValues
                
            }
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>





















  <FormField label="FarmPlot" labelFor="farm_plot">
      <Field name="farm_plot" id="farm_plot" component={SelectField} options={[]} itemRef={'farm_plots'}></Field>
  </FormField>



























  <FormField label="Crop" labelFor="crop">
      <Field name="crop" id="crop" component={SelectField} options={[]} itemRef={'crops'}></Field>
  </FormField>



















  <FormField
      label="PlantedAt"
  >
      <Field
          type="datetime-local"
          name="planted_at"
          placeholder="PlantedAt"
      />
  </FormField>



























  <FormField
      label="EstimatedHarvestAt"
  >
      <Field
          type="datetime-local"
          name="estimated_harvest_at"
          placeholder="EstimatedHarvestAt"
      />
  </FormField>































  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="planted">planted</option>
      
        <option value="growing">growing</option>
      
        <option value="ready">ready</option>
      
        <option value="withered">withered</option>
      
        <option value="harvested">harvested</option>
      
      </Field>
  </FormField>



















    <FormField
        label="QuantityPlanted"
    >
        <Field
            type="number"
            name="quantity_planted"
            placeholder="QuantityPlanted"
        />
    </FormField>



























    <FormField
        label="WateredToday"
    >
        <Field
            type="number"
            name="watered_today"
            placeholder="WateredToday"
        />
    </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('/plantings/plantings-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default PlantingsNew
