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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    plant: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    inspection_type: 'incoming',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    inspection_plan: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    item: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    lot: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    work_order: '',
    
    
    
    
    
    
    
    
    
    scheduled_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    started_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    completed_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'planned',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    overall_result: 'pass',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    inspector_user: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    attachments: [],
    
    
    
    
    
    
    
    notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


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





















  <FormField label="Plant" labelFor="plant">
      <Field name="plant" id="plant" component={SelectField} options={[]} itemRef={'plants'}></Field>
  </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>
      
      </Field>
  </FormField>































  <FormField label="InspectionPlan" labelFor="inspection_plan">
      <Field name="inspection_plan" id="inspection_plan" component={SelectField} options={[]} itemRef={'qa_inspection_plans'}></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="WorkOrder" labelFor="work_order">
      <Field name="work_order" id="work_order" component={SelectField} options={[]} itemRef={'work_orders'}></Field>
  </FormField>



















  <FormField
      label="ScheduledAt"
  >
      <Field
          type="datetime-local"
          name="scheduled_at"
          placeholder="ScheduledAt"
      />
  </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="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="planned">planned</option>
      
        <option value="in_progress">in_progress</option>
      
        <option value="completed">completed</option>
      
        <option value="void">void</option>
      
      </Field>
  </FormField>



























  <FormField label="OverallResult" labelFor="overall_result">
      <Field name="overall_result" id="overall_result" component="select">
      
        <option value="pass">pass</option>
      
        <option value="fail">fail</option>
      
        <option value="conditional">conditional</option>
      
        <option value="pending">pending</option>
      
      </Field>
  </FormField>































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
































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






    <FormField label="Notes" hasTextareaHeight>
        <Field name="notes" as="textarea" placeholder="Notes" />
    </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('/qa_inspections/qa_inspections-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default Qa_inspectionsNew
