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

const initialValues = {
    
    
    change_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    change_type: 'document_change',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'draft',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    requester: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    document: '',
    
    
    
    
    
    reason_for_change: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    impact_assessment: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    requires_validation: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    requires_regulatory_notification: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    requested_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    due_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    closed_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    supporting_files: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    assigned_to: '',
    
    
    
}


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

    
    

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









































  <FormField label="ChangeType" labelFor="change_type">
      <Field name="change_type" id="change_type" component="select">
      
        <option value="document_change">document_change</option>
      
        <option value="process_change">process_change</option>
      
        <option value="form_change">form_change</option>
      
        <option value="software_change">software_change</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="submitted">submitted</option>
      
        <option value="in_assessment">in_assessment</option>
      
        <option value="approved">approved</option>
      
        <option value="implemented">implemented</option>
      
        <option value="verified">verified</option>
      
        <option value="closed">closed</option>
      
        <option value="rejected">rejected</option>
      
      </Field>
  </FormField>































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



























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











    <FormField label="ReasonForChange" hasTextareaHeight>
        <Field name="reason_for_change" as="textarea" placeholder="ReasonForChange" />
    </FormField>



























    <FormField label="ImpactAssessment" hasTextareaHeight>
        <Field name="impact_assessment" as="textarea" placeholder="ImpactAssessment" />
    </FormField>









































  <FormField label='RequiresValidation' labelFor='requires_validation'>
      <Field
          name='requires_validation'
          id='requires_validation'
          component={SwitchField}
      ></Field>
  </FormField>



























  <FormField label='RequiresRegulatoryNotification' labelFor='requires_regulatory_notification'>
      <Field
          name='requires_regulatory_notification'
          id='requires_regulatory_notification'
          component={SwitchField}
      ></Field>
  </FormField>





















  <FormField
      label="RequestedAt"
  >
      <Field
          type="datetime-local"
          name="requested_at"
          placeholder="RequestedAt"
      />
  </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='SupportingFiles'
          color='info'
          icon={mdiUpload}
          path={'change_requests/supporting_files'}
          name='supporting_files'
          id='supporting_files'
          schema={{
            size: undefined,
            formats: undefined,
          }}
          component={FormFilePicker}
      ></Field>
  </FormField>






















  <FormField label="AssignedTo" labelFor="assigned_to">
      <Field name="assigned_to" id="assigned_to" component={SelectField} options={[]} itemRef={'users'}></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('/change_requests/change_requests-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default Change_requestsNew
