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

const initialValues = {
    
    
    capa_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    source: 'complaint',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'draft',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    owner: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    related_document: '',
    
    
    
    
    
    problem_statement: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    root_cause: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    corrective_actions: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    preventive_actions: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    opened_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    due_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    closed_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    capa_files: [],
    
    
    
    
    
}


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

    
    

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









































  <FormField label="Source" labelFor="source">
      <Field name="source" id="source" component="select">
      
        <option value="complaint">complaint</option>
      
        <option value="audit">audit</option>
      
        <option value="nonconformance">nonconformance</option>
      
        <option value="process_monitoring">process_monitoring</option>
      
        <option value="supplier">supplier</option>
      
        <option value="management_review">management_review</option>
      
        <option value="risk_management">risk_management</option>
      
        <option value="other">other</option>
      
      </Field>
  </FormField>



























  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="draft">draft</option>
      
        <option value="open">open</option>
      
        <option value="containment">containment</option>
      
        <option value="investigation">investigation</option>
      
        <option value="action_plan">action_plan</option>
      
        <option value="implementation">implementation</option>
      
        <option value="effectiveness_check">effectiveness_check</option>
      
        <option value="closed">closed</option>
      
        <option value="rejected">rejected</option>
      
      </Field>
  </FormField>































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



























  <FormField label="RelatedDocument" labelFor="related_document">
      <Field name="related_document" id="related_document" component={SelectField} options={[]} itemRef={'documents'}></Field>
  </FormField>











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



























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



























    <FormField label="CorrectiveActions" hasTextareaHeight>
        <Field name="corrective_actions" as="textarea" placeholder="CorrectiveActions" />
    </FormField>



























    <FormField label="PreventiveActions" hasTextareaHeight>
        <Field name="preventive_actions" as="textarea" placeholder="PreventiveActions" />
    </FormField>



































  <FormField
      label="OpenedAt"
  >
      <Field
          type="datetime-local"
          name="opened_at"
          placeholder="OpenedAt"
      />
  </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='CAPAFiles'
          color='info'
          icon={mdiUpload}
          path={'capas/capa_files'}
          name='capa_files'
          id='capa_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('/capas/capas-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default CapasNew
