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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    risk_assessment: '',
    
    
    
    
    hazard_id: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    hazard_description: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    sequence_of_events: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    severity: 'negligible',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    occurrence: 'remote',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    detectability: 'high',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    risk_level_initial: 'low',
    
    
    
    
    
    
    
    
    risk_controls: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    risk_level_residual: 'low',
    
    
    
    
    
    
    
    
    verification_of_controls: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'open',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    evidence_files: [],
    
    
    
    
    
}


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

    
    

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/risk_items/risk_items-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="RiskAssessment" labelFor="risk_assessment">
      <Field name="risk_assessment" id="risk_assessment" component={SelectField} options={[]} itemRef={'risk_assessments'}></Field>
  </FormField>









  <FormField
      label="HazardID"
  >
      <Field
          name="hazard_id"
          placeholder="HazardID"
      />
  </FormField>





























    <FormField label="HazardDescription" hasTextareaHeight>
        <Field name="hazard_description" as="textarea" placeholder="HazardDescription" />
    </FormField>



























    <FormField label="SequenceOfEvents" hasTextareaHeight>
        <Field name="sequence_of_events" as="textarea" placeholder="SequenceOfEvents" />
    </FormField>







































  <FormField label="Severity" labelFor="severity">
      <Field name="severity" id="severity" component="select">
      
        <option value="negligible">negligible</option>
      
        <option value="minor">minor</option>
      
        <option value="serious">serious</option>
      
        <option value="critical">critical</option>
      
        <option value="catastrophic">catastrophic</option>
      
      </Field>
  </FormField>



























  <FormField label="Occurrence" labelFor="occurrence">
      <Field name="occurrence" id="occurrence" component="select">
      
        <option value="remote">remote</option>
      
        <option value="unlikely">unlikely</option>
      
        <option value="possible">possible</option>
      
        <option value="likely">likely</option>
      
        <option value="frequent">frequent</option>
      
      </Field>
  </FormField>



























  <FormField label="Detectability" labelFor="detectability">
      <Field name="detectability" id="detectability" component="select">
      
        <option value="high">high</option>
      
        <option value="medium">medium</option>
      
        <option value="low">low</option>
      
        <option value="unknown">unknown</option>
      
      </Field>
  </FormField>



























  <FormField label="RiskLevelInitial" labelFor="risk_level_initial">
      <Field name="risk_level_initial" id="risk_level_initial" component="select">
      
        <option value="low">low</option>
      
        <option value="medium">medium</option>
      
        <option value="high">high</option>
      
        <option value="unacceptable">unacceptable</option>
      
      </Field>
  </FormField>















    <FormField label="RiskControls" hasTextareaHeight>
        <Field name="risk_controls" as="textarea" placeholder="RiskControls" />
    </FormField>







































  <FormField label="RiskLevelResidual" labelFor="risk_level_residual">
      <Field name="risk_level_residual" id="risk_level_residual" component="select">
      
        <option value="low">low</option>
      
        <option value="medium">medium</option>
      
        <option value="high">high</option>
      
        <option value="unacceptable">unacceptable</option>
      
      </Field>
  </FormField>















    <FormField label="VerificationOfControls" hasTextareaHeight>
        <Field name="verification_of_controls" as="textarea" placeholder="VerificationOfControls" />
    </FormField>







































  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="open">open</option>
      
        <option value="mitigating">mitigating</option>
      
        <option value="verified">verified</option>
      
        <option value="accepted">accepted</option>
      
        <option value="closed">closed</option>
      
      </Field>
  </FormField>




































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

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

export default Risk_itemsNew
