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

const initialValues = {
    
    
    inspection_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    inspection_type: 'incoming',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    inspection_plan: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    material: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    lot: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    production_order: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    work_order_operation: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    inspector_user: '',
    
    
    
    
    
    
    
    
    
    started_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    completed_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    result: 'pending',
    
    
    
    
    
    
    
    sample_size: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    summary: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    evidence_files: [],
    
    
    
    
    
}


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

    
    

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/inspections/inspections-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="InspectionNumber"
  >
      <Field
          name="inspection_number"
          placeholder="InspectionNumber"
      />
  </FormField>









































  <FormField label="InspectionType" labelFor="inspection_type">
      <Field name="inspection_type" id="inspection_type" component="select">
      
        <option value="incoming">incoming</option>
      
        <option value="in_process">in_process</option>
      
        <option value="final">final</option>
      
        <option value="audit">audit</option>
      
      </Field>
  </FormField>































  <FormField label="InspectionPlan" labelFor="inspection_plan">
      <Field name="inspection_plan" id="inspection_plan" component={SelectField} options={[]} itemRef={'inspection_plans'}></Field>
  </FormField>



























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



























  <FormField label="Lot" labelFor="lot">
      <Field name="lot" id="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="WorkOrderOperation" labelFor="work_order_operation">
      <Field name="work_order_operation" id="work_order_operation" component={SelectField} options={[]} itemRef={'work_order_operations'}></Field>
  </FormField>



























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



















  <FormField
      label="StartedAt"
  >
      <Field
          type="datetime-local"
          name="started_at"
          placeholder="StartedAt"
      />
  </FormField>



























  <FormField
      label="CompletedAt"
  >
      <Field
          type="datetime-local"
          name="completed_at"
          placeholder="CompletedAt"
      />
  </FormField>































  <FormField label="Result" labelFor="result">
      <Field name="result" id="result" component="select">
      
        <option value="pending">pending</option>
      
        <option value="pass">pass</option>
      
        <option value="fail">fail</option>
      
        <option value="conditional_pass">conditional_pass</option>
      
      </Field>
  </FormField>



















    <FormField
        label="SampleSize"
    >
        <Field
            type="number"
            name="sample_size"
            placeholder="SampleSize"
        />
    </FormField>

























      <FormField label='Summary' hasTextareaHeight>
          <Field
              name='summary'
              id='summary'
              component={RichTextField}
          ></Field>
      </FormField>














































  <FormField>
      <Field
          label='EvidenceFiles'
          color='info'
          icon={mdiUpload}
          path={'inspections/evidence_files'}
          name='evidence_files'
          id='evidence_files'
          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('/inspections/inspections-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default InspectionsNew
