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 = {
    
    
    ncr_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    source: 'incoming',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    severity: 'minor',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'open',
    
    
    
    
    
    
    
    
    
    
    
    
    reported_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    reported_by: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    material: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    inventory_lot: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    production_order: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    production_lot: '',
    
    
    
    
    
    problem_statement: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    containment_action: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    root_cause: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    corrective_action: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    due_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    closed_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    attachments: [],
    
    
    
    
    
}


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="NCRNumber"
  >
      <Field
          name="ncr_number"
          placeholder="NCRNumber"
      />
  </FormField>









































  <FormField label="Source" labelFor="source">
      <Field name="source" id="source" component="select">
      
        <option value="incoming">incoming</option>
      
        <option value="in_process">in_process</option>
      
        <option value="final">final</option>
      
        <option value="customer">customer</option>
      
        <option value="audit">audit</option>
      
      </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="contained">contained</option>
      
        <option value="investigating">investigating</option>
      
        <option value="closed">closed</option>
      
        <option value="void">void</option>
      
      </Field>
  </FormField>























  <FormField
      label="ReportedAt"
  >
      <Field
          type="datetime-local"
          name="reported_at"
          placeholder="ReportedAt"
      />
  </FormField>



































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



























  <FormField label="Material" labelFor="material">
      <Field name="material" id="material" component={SelectField} options={[]} itemRef={'materials'}></Field>
  </FormField>



























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



























  <FormField label="ProductionOrder" labelFor="production_order">
      <Field name="production_order" id="production_order" component={SelectField} options={[]} itemRef={'production_orders'}></Field>
  </FormField>



























  <FormField label="ProductionLot" labelFor="production_lot">
      <Field name="production_lot" id="production_lot" component={SelectField} options={[]} itemRef={'production_lots'}></Field>
  </FormField>











    <FormField label="ProblemStatement" hasTextareaHeight>
        <Field name="problem_statement" as="textarea" placeholder="ProblemStatement" />
    </FormField>



























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



























    <FormField label="RootCause" hasTextareaHeight>
        <Field name="root_cause" as="textarea" placeholder="RootCause" />
    </FormField>



























    <FormField label="CorrectiveAction" hasTextareaHeight>
        <Field name="corrective_action" as="textarea" placeholder="CorrectiveAction" />
    </FormField>



































  <FormField
      label="DueAt"
  >
      <Field
          type="datetime-local"
          name="due_at"
          placeholder="DueAt"
      />
  </FormField>



























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








































  <FormField>
      <Field
          label='Attachments'
          color='info'
          icon={mdiUpload}
          path={'nonconformances/attachments'}
          name='attachments'
          id='attachments'
          schema={{
            size: undefined,
            formats: undefined,
          }}
          component={FormFilePicker}
      ></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
