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 = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    plant: '',
    
    
    
    
    capa_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    nonconformance: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'open',
    
    
    
    
    
    
    
    
    problem_statement: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    root_cause: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    corrective_action: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    preventive_action: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    due_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    closed_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    owner_user: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    attachments: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


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









  <FormField
      label="CAPANumber"
  >
      <Field
          name="capa_number"
          placeholder="CAPANumber"
      />
  </FormField>













































  <FormField label="Nonconformance" labelFor="nonconformance">
      <Field name="nonconformance" id="nonconformance" component={SelectField} options={[]} itemRef={'nonconformances'}></Field>
  </FormField>























  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="open">open</option>
      
        <option value="root_cause">root_cause</option>
      
        <option value="action_planning">action_planning</option>
      
        <option value="implementing">implementing</option>
      
        <option value="verifying">verifying</option>
      
        <option value="closed">closed</option>
      
        <option value="cancelled">cancelled</option>
      
      </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="CorrectiveAction" hasTextareaHeight>
        <Field name="corrective_action" as="textarea" placeholder="CorrectiveAction" />
    </FormField>



























    <FormField label="PreventiveAction" hasTextareaHeight>
        <Field name="preventive_action" as="textarea" placeholder="PreventiveAction" />
    </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 label="OwnerUser" labelFor="owner_user">
      <Field name="owner_user" id="owner_user" component={SelectField} options={[]} itemRef={'users'}></Field>
  </FormField>
































  <FormField>
      <Field
          label='Attachments'
          color='info'
          icon={mdiUpload}
          path={'capas/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="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
