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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    batch: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    supplier: '',
    
    
    
    
    coa_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'draft',
    
    
    
    
    
    
    
    
    
    
    
    
    issued_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    expires_at: '',
    
    
    
    
    
    
    
    
    
    
    
    summary: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    coa_files: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    issued_by: '',
    
    
    
}


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





















  <FormField label="Batch" labelFor="batch">
      <Field name="batch" id="batch" component={SelectField} options={[]} itemRef={'batches'}></Field>
  </FormField>



























  <FormField label="Supplier" labelFor="supplier">
      <Field name="supplier" id="supplier" component={SelectField} options={[]} itemRef={'suppliers'}></Field>
  </FormField>









  <FormField
      label="COANumber"
  >
      <Field
          name="coa_number"
          placeholder="COANumber"
      />
  </FormField>









































  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="draft">draft</option>
      
        <option value="issued">issued</option>
      
        <option value="superseded">superseded</option>
      
        <option value="void">void</option>
      
      </Field>
  </FormField>























  <FormField
      label="IssuedAt"
  >
      <Field
          type="datetime-local"
          name="issued_at"
          placeholder="IssuedAt"
      />
  </FormField>



























  <FormField
      label="ExpiresAt"
  >
      <Field
          type="datetime-local"
          name="expires_at"
          placeholder="ExpiresAt"
      />
  </FormField>



















    <FormField label="Summary" hasTextareaHeight>
        <Field name="summary" as="textarea" placeholder="Summary" />
    </FormField>
















































  <FormField>
      <Field
          label='COAFiles'
          color='info'
          icon={mdiUpload}
          path={'certificates_of_analysis/coa_files'}
          name='coa_files'
          id='coa_files'
          schema={{
            size: undefined,
            formats: undefined,
          }}
          component={FormFilePicker}
      ></Field>
  </FormField>






















  <FormField label="IssuedBy" labelFor="issued_by">
      <Field name="issued_by" id="issued_by" component={SelectField} options={[]} itemRef={'users'}></Field>
  </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('/certificates_of_analysis/certificates_of_analysis-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default Certificates_of_analysisNew
