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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    quality_inspection: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    reported_by: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    item: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    lot: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    severity: 'minor',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'open',
    
    
    
    
    
    
    
    title: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    description: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    containment_action: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    detected_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    closed_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    evidence_files: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


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

    
    

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/nonconformances/nonconformances-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="QualityInspection" labelFor="quality_inspection">
      <Field name="quality_inspection" id="quality_inspection" component={SelectField} options={[]} itemRef={'quality_inspections'}></Field>
  </FormField>



























  <FormField label="ReportedBy" labelFor="reported_by">
      <Field name="reported_by" id="reported_by" component={SelectField} options={[]} itemRef={'users'}></Field>
  </FormField>



























  <FormField label="Item" labelFor="item">
      <Field name="item" id="item" component={SelectField} options={[]} itemRef={'items'}></Field>
  </FormField>



























  <FormField label="Lot" labelFor="lot">
      <Field name="lot" id="lot" component={SelectField} options={[]} itemRef={'inventory_lots'}></Field>
  </FormField>























  <FormField label="Severity" labelFor="severity">
      <Field name="severity" id="severity" component="select">
      
        <option value="minor">minor</option>
      
        <option value="major">major</option>
      
        <option value="critical">critical</option>
      
      </Field>
  </FormField>



























  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="open">open</option>
      
        <option value="under_investigation">under_investigation</option>
      
        <option value="containment">containment</option>
      
        <option value="capa_in_progress">capa_in_progress</option>
      
        <option value="closed">closed</option>
      
        <option value="void">void</option>
      
      </Field>
  </FormField>













  <FormField
      label="Title"
  >
      <Field
          name="title"
          placeholder="Title"
      />
  </FormField>





























    <FormField label="Description" hasTextareaHeight>
        <Field name="description" as="textarea" placeholder="Description" />
    </FormField>



























    <FormField label="ContainmentAction" hasTextareaHeight>
        <Field name="containment_action" as="textarea" placeholder="ContainmentAction" />
    </FormField>



































  <FormField
      label="DetectedAt"
  >
      <Field
          type="datetime-local"
          name="detected_at"
          placeholder="DetectedAt"
      />
  </FormField>



























  <FormField
      label="ClosedAt"
  >
      <Field
          type="datetime-local"
          name="closed_at"
          placeholder="ClosedAt"
      />
  </FormField>








































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






















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

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

export default NonconformancesNew
