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 = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    merchant: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    receipt: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    category: 'rent',
    
    
    
    
    
    
    
    description: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    expense_date: '',
    
    
    
    
    
    
    
    
    
    
    amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    tax_treatment: 'deductible',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'draft',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    entered_by: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    reviewed_by: '',
    
    
    
    
    
    
    
    
    
    reviewed_at: '',
    
    
    
    
    
    
    
    
    
    
    
    review_notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


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="Merchant" labelFor="merchant">
      <Field name="merchant" id="merchant" component={SelectField} options={[]} itemRef={'merchants'}></Field>
  </FormField>



























  <FormField label="Receipt" labelFor="receipt">
      <Field name="receipt" id="receipt" component={SelectField} options={[]} itemRef={'receipts'}></Field>
  </FormField>























  <FormField label="Category" labelFor="category">
      <Field name="category" id="category" component="select">
      
        <option value="rent">rent</option>
      
        <option value="utilities">utilities</option>
      
        <option value="salary">salary</option>
      
        <option value="transport">transport</option>
      
        <option value="office">office</option>
      
        <option value="marketing">marketing</option>
      
        <option value="maintenance">maintenance</option>
      
        <option value="bank_fees">bank_fees</option>
      
        <option value="other">other</option>
      
      </Field>
  </FormField>













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





































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























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



































  <FormField label="TaxTreatment" labelFor="tax_treatment">
      <Field name="tax_treatment" id="tax_treatment" component="select">
      
        <option value="deductible">deductible</option>
      
        <option value="non_deductible">non_deductible</option>
      
        <option value="capitalizable">capitalizable</option>
      
        <option value="unknown">unknown</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="approved">approved</option>
      
        <option value="rejected">rejected</option>
      
      </Field>
  </FormField>































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



























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



















  <FormField
      label="ReviewedAt"
  >
      <Field
          type="datetime-local"
          name="reviewed_at"
          placeholder="ReviewedAt"
      />
  </FormField>



















    <FormField label="ReviewNotes" hasTextareaHeight>
        <Field name="review_notes" as="textarea" placeholder="ReviewNotes" />
    </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('/expenses/expenses-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default ExpensesNew
