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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    product: '',
    
    
    
    
    risk_file_name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    risk_file_code: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    methodology: 'iso_14971',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'draft',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    owner: '',
    
    
    
    
    
    
    
    
    
    created_on: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    review_due_at: '',
    
    
    
    
    
    
    
    
    
    
    
    scope: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    risk_files: [],
    
    
    
    
    
}


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

    
    

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









  <FormField
      label="RiskFileName"
  >
      <Field
          name="risk_file_name"
          placeholder="RiskFileName"
      />
  </FormField>



























  <FormField
      label="RiskFileCode"
  >
      <Field
          name="risk_file_code"
          placeholder="RiskFileCode"
      />
  </FormField>









































  <FormField label="Methodology" labelFor="methodology">
      <Field name="methodology" id="methodology" component="select">
      
        <option value="iso_14971">iso_14971</option>
      
        <option value="fmea">fmea</option>
      
        <option value="fta">fta</option>
      
        <option value="hazop">hazop</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="in_review">in_review</option>
      
        <option value="approved">approved</option>
      
        <option value="effective">effective</option>
      
        <option value="superseded">superseded</option>
      
        <option value="archived">archived</option>
      
      </Field>
  </FormField>































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



















  <FormField
      label="CreatedOn"
  >
      <Field
          type="datetime-local"
          name="created_on"
          placeholder="CreatedOn"
      />
  </FormField>



























  <FormField
      label="ReviewDueAt"
  >
      <Field
          type="datetime-local"
          name="review_due_at"
          placeholder="ReviewDueAt"
      />
  </FormField>



















    <FormField label="Scope" hasTextareaHeight>
        <Field name="scope" as="textarea" placeholder="Scope" />
    </FormField>
















































  <FormField>
      <Field
          label='RiskFiles'
          color='info'
          icon={mdiUpload}
          path={'risk_assessments/risk_files'}
          name='risk_files'
          id='risk_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_assessments/risk_assessments-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default Risk_assessmentsNew
