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

const initialValues = {
    
    
    reference: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    category: 'feed',
    
    
    
    
    
    
    
    
    
    
    
    
    expense_date: '',
    
    
    
    
    
    
    
    
    
    
    amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    payment_method: 'cash',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    supplier: '',
    
    
    
    
    
    description: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    receipt_files: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    created_by_user: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'draft',
    
    
    
    
    
    
}


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

    
    

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/expenses/expenses-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="Référencedépense"
  >
      <Field
          name="reference"
          placeholder="Référencedépense"
      />
  </FormField>









































  <FormField label="Catégorie" labelFor="category">
      <Field name="category" id="category" component="select">
      
        <option value="feed">feed</option>
      
        <option value="medication">medication</option>
      
        <option value="utilities">utilities</option>
      
        <option value="transport">transport</option>
      
        <option value="salary">salary</option>
      
        <option value="maintenance">maintenance</option>
      
        <option value="rent">rent</option>
      
        <option value="taxes">taxes</option>
      
        <option value="equipment">equipment</option>
      
        <option value="other">other</option>
      
      </Field>
  </FormField>























  <FormField
      label="Date"
  >
      <Field
          type="datetime-local"
          name="expense_date"
          placeholder="Date"
      />
  </FormField>























    <FormField
        label="Montant"
    >
        <Field
            type="number"
            name="amount"
            placeholder="Montant"
        />
    </FormField>



































  <FormField label="Modedepaiement" labelFor="payment_method">
      <Field name="payment_method" id="payment_method" component="select">
      
        <option value="cash">cash</option>
      
        <option value="bank_transfer">bank_transfer</option>
      
        <option value="orange_money">orange_money</option>
      
        <option value="wave">wave</option>
      
        <option value="cheque">cheque</option>
      
        <option value="card">card</option>
      
        <option value="other">other</option>
      
      </Field>
  </FormField>































  <FormField label="Fournisseur" labelFor="supplier">
      <Field name="supplier" id="supplier" component={SelectField} options={[]} itemRef={'suppliers'}></Field>
  </FormField>











    <FormField label="Description" hasTextareaHeight>
        <Field name="description" as="textarea" placeholder="Description" />
    </FormField>
















































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






















  <FormField label="Créépar" labelFor="created_by_user">
      <Field name="created_by_user" id="created_by_user" component={SelectField} options={[]} itemRef={'users'}></Field>
  </FormField>























  <FormField label="Statut" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="draft">draft</option>
      
        <option value="approved">approved</option>
      
        <option value="paid">paid</option>
      
        <option value="rejected">rejected</option>
      
      </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('/expenses/expenses-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default ExpensesNew
