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',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    item: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    lot: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    serial: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    work_order: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    inspection: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    reported_by: '',
    
    
    
    
    
    
    
    
    
    reported_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    problem_description: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    disposition_code: '',
    
    
    
    
    
    
    containment_actions: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    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="internal_audit">internal_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="under_review">under_review</option>
      
        <option value="containment">containment</option>
      
        <option value="capa_required">capa_required</option>
      
        <option value="closed">closed</option>
      
        <option value="void">void</option>
      
      </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={'lots'}></Field>
  </FormField>



























  <FormField label="Serial" labelFor="serial">
      <Field name="serial" id="serial" component={SelectField} options={[]} itemRef={'serials'}></Field>
  </FormField>



























  <FormField label="WorkOrder" labelFor="work_order">
      <Field name="work_order" id="work_order" component={SelectField} options={[]} itemRef={'work_orders'}></Field>
  </FormField>



























  <FormField label="Inspection" labelFor="inspection">
      <Field name="inspection" id="inspection" component={SelectField} options={[]} itemRef={'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="ReportedAt"
  >
      <Field
          type="datetime-local"
          name="reported_at"
          placeholder="ReportedAt"
      />
  </FormField>





















      <FormField label='ProblemDescription' hasTextareaHeight>
          <Field
              name='problem_description'
              id='problem_description'
              component={RichTextField}
          ></Field>
      </FormField>









































  <FormField label="DispositionCode" labelFor="disposition_code">
      <Field name="disposition_code" id="disposition_code" component={SelectField} options={[]} itemRef={'disposition_codes'}></Field>
  </FormField>













      <FormField label='ContainmentActions' hasTextareaHeight>
          <Field
              name='containment_actions'
              id='containment_actions'
              component={RichTextField}
          ></Field>
      </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
