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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    merchant: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    uploaded_by: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    receipt_kind: 'sales',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    receipt_images: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    receipt_files: [],
    
    
    
    
    
    
    source_channel: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    captured_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    ocr_status: 'pending',
    
    
    
    
    
    
    
    ocr_confidence: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    needs_review: false,
    
    
    
    
    
    
    
    
    
    
    notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


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

    
    

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























  <FormField label="ReceiptKind" labelFor="receipt_kind">
      <Field name="receipt_kind" id="receipt_kind" component="select">
      
        <option value="sales">sales</option>
      
        <option value="purchase">purchase</option>
      
        <option value="expense">expense</option>
      
        <option value="other">other</option>
      
      </Field>
  </FormField>



































  <FormField>
      <Field
          label='ReceiptImages'
          color='info'
          icon={mdiUpload}
          path={'receipts/receipt_images'}
          name='receipt_images'
          id='receipt_images'
          schema={{
            size: undefined,
            formats: undefined,
          }}
          component={FormImagePicker}
      ></Field>
  </FormField>




























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




  <FormField
      label="SourceChannel"
  >
      <Field
          name="source_channel"
          placeholder="SourceChannel"
      />
  </FormField>





































  <FormField
      label="CapturedAt"
  >
      <Field
          type="datetime-local"
          name="captured_at"
          placeholder="CapturedAt"
      />
  </FormField>































  <FormField label="OCRStatus" labelFor="ocr_status">
      <Field name="ocr_status" id="ocr_status" component="select">
      
        <option value="pending">pending</option>
      
        <option value="processing">processing</option>
      
        <option value="completed">completed</option>
      
        <option value="failed">failed</option>
      
      </Field>
  </FormField>



















    <FormField
        label="OCRConfidence"
    >
        <Field
            type="number"
            name="ocr_confidence"
            placeholder="OCRConfidence"
        />
    </FormField>





































  <FormField label='NeedsReview' labelFor='needs_review'>
      <Field
          name='needs_review'
          id='needs_review'
          component={SwitchField}
      ></Field>
  </FormField>













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

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

export default ReceiptsNew
