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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    organization: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    bank_account: '',
    
    
    
    
    
    
    
    
    
    transaction_date: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    posted_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    direction: 'inflow',
    
    
    
    
    
    
    
    amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    currency: '',
    
    
    
    
    
    description: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    reference: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    match_status: 'unmatched',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    import_source_file: [],
    
    
    
    
    
}


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

    
    
    // get from url params
    const { dateRangeStart, dateRangeEnd } = router.query
    

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/bank_transactions/bank_transactions-list')
  }
  return (
    <>
      <Head>
        <title>{getPageTitle('New Item')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="New Item" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            initialValues={
                
                
                
                dateRangeStart && dateRangeEnd ?
                {
                    ...initialValues,
                    transaction_date: moment(dateRangeStart).format('YYYY-MM-DDTHH:mm'),
                    posted_at: moment(dateRangeEnd).format('YYYY-MM-DDTHH:mm'),
                } : initialValues
                
            }
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>





















  <FormField label="Organization" labelFor="organization">
      <Field name="organization" id="organization" component={SelectField} options={[]} itemRef={'organizations'}></Field>
  </FormField>



























  <FormField label="BankAccount" labelFor="bank_account">
      <Field name="bank_account" id="bank_account" component={SelectField} options={[]} itemRef={'bank_accounts'}></Field>
  </FormField>



















  <FormField
      label="TransactionDate"
  >
      <Field
          type="datetime-local"
          name="transaction_date"
          placeholder="TransactionDate"
      />
  </FormField>



























  <FormField
      label="PostedAt"
  >
      <Field
          type="datetime-local"
          name="posted_at"
          placeholder="PostedAt"
      />
  </FormField>































  <FormField label="Direction" labelFor="direction">
      <Field name="direction" id="direction" component="select">
      
        <option value="inflow">inflow</option>
      
        <option value="outflow">outflow</option>
      
      </Field>
  </FormField>



















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







































  <FormField label="Currency" labelFor="currency">
      <Field name="currency" id="currency" component={SelectField} options={[]} itemRef={'currencies'}></Field>
  </FormField>











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

























  <FormField
      label="Reference"
  >
      <Field
          name="reference"
          placeholder="Reference"
      />
  </FormField>









































  <FormField label="MatchStatus" labelFor="match_status">
      <Field name="match_status" id="match_status" component="select">
      
        <option value="unmatched">unmatched</option>
      
        <option value="suggested">suggested</option>
      
        <option value="matched">matched</option>
      
        <option value="excluded">excluded</option>
      
      </Field>
  </FormField>




































  <FormField>
      <Field
          label='ImportSourceFile'
          color='info'
          icon={mdiUpload}
          path={'bank_transactions/import_source_file'}
          name='import_source_file'
          id='import_source_file'
          schema={{
            size: undefined,
            formats: undefined,
          }}
          component={FormFilePicker}
      ></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('/bank_transactions/bank_transactions-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default Bank_transactionsNew
