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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    workflow: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    step: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    subject_type: 'document',
    
    
    
    
    
    
    
    subject_reference: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    assignee: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'pending',
    
    
    
    
    
    
    
    
    
    
    
    
    assigned_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    completed_at: '',
    
    
    
    
    
    
    
    
    
    
    
    decision_comment: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    evidence_files: [],
    
    
    
    
    
}


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

    
    

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



























  <FormField label="Step" labelFor="step">
      <Field name="step" id="step" component={SelectField} options={[]} itemRef={'approval_steps'}></Field>
  </FormField>























  <FormField label="SubjectType" labelFor="subject_type">
      <Field name="subject_type" id="subject_type" component="select">
      
        <option value="document">document</option>
      
        <option value="document_version">document_version</option>
      
        <option value="change_request">change_request</option>
      
        <option value="training_assignment">training_assignment</option>
      
        <option value="record_batch">record_batch</option>
      
        <option value="risk_assessment">risk_assessment</option>
      
        <option value="capa">capa</option>
      
        <option value="nonconformance">nonconformance</option>
      
        <option value="audit">audit</option>
      
      </Field>
  </FormField>













  <FormField
      label="SubjectReference"
  >
      <Field
          name="subject_reference"
          placeholder="SubjectReference"
      />
  </FormField>













































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























  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="pending">pending</option>
      
        <option value="in_progress">in_progress</option>
      
        <option value="approved">approved</option>
      
        <option value="rejected">rejected</option>
      
        <option value="cancelled">cancelled</option>
      
      </Field>
  </FormField>























  <FormField
      label="AssignedAt"
  >
      <Field
          type="datetime-local"
          name="assigned_at"
          placeholder="AssignedAt"
      />
  </FormField>



























  <FormField
      label="CompletedAt"
  >
      <Field
          type="datetime-local"
          name="completed_at"
          placeholder="CompletedAt"
      />
  </FormField>



















    <FormField label="DecisionComment" hasTextareaHeight>
        <Field name="decision_comment" as="textarea" placeholder="DecisionComment" />
    </FormField>
















































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

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

export default Approval_tasksNew
