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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    company: '',
    
    
    
    
    
    
    
    
    
    date: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    driver: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    vehicle: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    agreement: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    invoice: '',
    
    
    
    
    expense_category: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    description: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    expense_account: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    payment_account: '',
    
    
    
    
    
    
    
    
    
    
    charge_to_driver_flag: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    billable_to_driver_flag: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'draft',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    attachment: [],
    
    
    
    
    
    
    
    
    
    
    
    created_on: '',
    
    
    
    
    
    
    
    
    
}


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

    
    

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



















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



































  <FormField label="Driver" labelFor="driver">
      <Field name="driver" id="driver" component={SelectField} options={[]} itemRef={'drivers'}></Field>
  </FormField>



























  <FormField label="Vehicle" labelFor="vehicle">
      <Field name="vehicle" id="vehicle" component={SelectField} options={[]} itemRef={'vehicles'}></Field>
  </FormField>



























  <FormField label="Agreement" labelFor="agreement">
      <Field name="agreement" id="agreement" component={SelectField} options={[]} itemRef={'agreements'}></Field>
  </FormField>



























  <FormField label="Invoice" labelFor="invoice">
      <Field name="invoice" id="invoice" component={SelectField} options={[]} itemRef={'invoices'}></Field>
  </FormField>









  <FormField
      label="ExpenseCategory"
  >
      <Field
          name="expense_category"
          placeholder="ExpenseCategory"
      />
  </FormField>





























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































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







































  <FormField label="ExpenseAccount" labelFor="expense_account">
      <Field name="expense_account" id="expense_account" component={SelectField} options={[]} itemRef={'chart_of_accounts'}></Field>
  </FormField>



























  <FormField label="PaymentAccount" labelFor="payment_account">
      <Field name="payment_account" id="payment_account" component={SelectField} options={[]} itemRef={'chart_of_accounts'}></Field>
  </FormField>

























  <FormField label='ChargeToDriver' labelFor='charge_to_driver_flag'>
      <Field
          name='charge_to_driver_flag'
          id='charge_to_driver_flag'
          component={SwitchField}
      ></Field>
  </FormField>



























  <FormField label='BillableToDriver' labelFor='billable_to_driver_flag'>
      <Field
          name='billable_to_driver_flag'
          id='billable_to_driver_flag'
          component={SwitchField}
      ></Field>
  </FormField>

























  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="draft">draft</option>
      
        <option value="approved">approved</option>
      
        <option value="posted">posted</option>
      
        <option value="voided">voided</option>
      
        <option value="reversed">reversed</option>
      
      </Field>
  </FormField>




































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














  <FormField
      label="CreatedOn"
  >
      <Field
          type="datetime-local"
          name="created_on"
          placeholder="CreatedOn"
      />
  </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('/driver_expenses/driver_expenses-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default Driver_expensesNew
