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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    tenant: '',
    
    
    
    
    req_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    requester: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    department: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    project: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    budget_line: '',
    
    
    
    
    title: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    description: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    quantity: '',
    
    
    
    
    
    
    
    
    
    
    
    
    estimated_budget_usd: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    currency: 'USD',
    
    
    
    
    
    
    
    estimated_budget_original: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    fx_rate_to_usd: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'draft',
    
    
    
    
    
    
    
    
    
    
    
    
    submitted_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    approved_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    closed_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    attachments: [],
    
    
    
    
    
    
    
    return_reason: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    reject_reason: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    is_high_value: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


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

    
    

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









  <FormField
      label="Numerorequisition"
  >
      <Field
          name="req_number"
          placeholder="Numerorequisition"
      />
  </FormField>













































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



























  <FormField label="Departement" labelFor="department">
      <Field name="department" id="department" component={SelectField} options={[]} itemRef={'departments'}></Field>
  </FormField>



























  <FormField label="Projet" labelFor="project">
      <Field name="project" id="project" component={SelectField} options={[]} itemRef={'projects'}></Field>
  </FormField>



























  <FormField label="Lignebudgetaire" labelFor="budget_line">
      <Field name="budget_line" id="budget_line" component={SelectField} options={[]} itemRef={'budget_lines'}></Field>
  </FormField>









  <FormField
      label="Titre"
  >
      <Field
          name="title"
          placeholder="Titre"
      />
  </FormField>































      <FormField label='Description' hasTextareaHeight>
          <Field
              name='description'
              id='description'
              component={RichTextField}
          ></Field>
      </FormField>





























    <FormField
        label="Quantite"
    >
        <Field
            type="number"
            name="quantity"
            placeholder="Quantite"
        />
    </FormField>



























    <FormField
        label="BudgetestimeUSD"
    >
        <Field
            type="number"
            name="estimated_budget_usd"
            placeholder="BudgetestimeUSD"
        />
    </FormField>



































  <FormField label="Devise" labelFor="currency">
      <Field name="currency" id="currency" component="select">
      
        <option value="USD">USD</option>
      
        <option value="CDF">CDF</option>
      
        <option value="EUR">EUR</option>
      
        <option value="GBP">GBP</option>
      
      </Field>
  </FormField>



















    <FormField
        label="Budgetestimedevise"
    >
        <Field
            type="number"
            name="estimated_budget_original"
            placeholder="Budgetestimedevise"
        />
    </FormField>



























    <FormField
        label="TauxversUSD"
    >
        <Field
            type="number"
            name="fx_rate_to_usd"
            placeholder="TauxversUSD"
        />
    </FormField>



































  <FormField label="Statut" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="draft">draft</option>
      
        <option value="submitted">submitted</option>
      
        <option value="in_approval">in_approval</option>
      
        <option value="approved">approved</option>
      
        <option value="rejected">rejected</option>
      
        <option value="in_procurement">in_procurement</option>
      
        <option value="awarded">awarded</option>
      
        <option value="in_delivery">in_delivery</option>
      
        <option value="received">received</option>
      
        <option value="closed">closed</option>
      
        <option value="returned">returned</option>
      
      </Field>
  </FormField>























  <FormField
      label="Datesoumission"
  >
      <Field
          type="datetime-local"
          name="submitted_at"
          placeholder="Datesoumission"
      />
  </FormField>



























  <FormField
      label="Dateapprobation"
  >
      <Field
          type="datetime-local"
          name="approved_at"
          placeholder="Dateapprobation"
      />
  </FormField>



























  <FormField
      label="Datecloture"
  >
      <Field
          type="datetime-local"
          name="closed_at"
          placeholder="Datecloture"
      />
  </FormField>








































  <FormField>
      <Field
          label='Piecesjointes'
          color='info'
          icon={mdiUpload}
          path={'requisitions/attachments'}
          name='attachments'
          id='attachments'
          schema={{
            size: undefined,
            formats: undefined,
          }}
          component={FormFilePicker}
      ></Field>
  </FormField>






    <FormField label="Motifderetour" hasTextareaHeight>
        <Field name="return_reason" as="textarea" placeholder="Motifderetour" />
    </FormField>



























    <FormField label="Motifderejet" hasTextareaHeight>
        <Field name="reject_reason" as="textarea" placeholder="Motifderejet" />
    </FormField>









































  <FormField label='Transactionelevee' labelFor='is_high_value'>
      <Field
          name='is_high_value'
          id='is_high_value'
          component={SwitchField}
      ></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('/requisitions/requisitions-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default RequisitionsNew
