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: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    severity: 'minor',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'open',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    inspection: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    owner: '',
    
    
    
    
    
    
    description: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    root_cause: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    corrective_action: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    due_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    closed_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    attachments: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    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('Yeni Kayıt')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="Yeni Kayıt" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            initialValues={
                
                initialValues
                
            }
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>



  <FormField
      label="Uygunsuzluk No"
  >
      <Field
          name="ncr_number"
          placeholder="Uygunsuzluk No"
      />
  </FormField>









































  <FormField label="Şiddet" 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="Durum" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="open">open</option>
      
        <option value="contained">contained</option>
      
        <option value="corrective_action">corrective_action</option>
      
        <option value="closed">closed</option>
      
      </Field>
  </FormField>































  <FormField label="Kontrol" labelFor="inspection">
      <Field name="inspection" id="inspection" component={SelectField} options={[]} itemRef={'quality_inspections'}></Field>
  </FormField>



























  <FormField label="Sorumlu Kişi" labelFor="owner">
      <Field name="owner" id="owner" component={SelectField} options={[]} itemRef={'users'}></Field>
  </FormField>













      <FormField label='Açıklama' hasTextareaHeight>
          <Field
              name='description'
              id='description'
              component={RichTextField}
          ></Field>
      </FormField>



























      <FormField label='Kök Neden' hasTextareaHeight>
          <Field
              name='root_cause'
              id='root_cause'
              component={RichTextField}
          ></Field>
      </FormField>



























      <FormField label='Düzeltici Faaliyet' hasTextareaHeight>
          <Field
              name='corrective_action'
              id='corrective_action'
              component={RichTextField}
          ></Field>
      </FormField>

































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



























  <FormField
      label="Kapanış Tarihi"
  >
      <Field
          type="datetime-local"
          name="closed_at"
          placeholder="Kapanış Tarihi"
      />
  </FormField>








































  <FormField>
      <Field
          label='Ekler'
          color='info'
          icon={mdiUpload}
          path={'nonconformances/attachments'}
          name='attachments'
          id='attachments'
          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="Kaydet" />
                <BaseButton type="reset" color="info" outline label="Sıfırla" />
                <BaseButton type='reset' color='danger' outline label='İptal' 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
