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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    workspace: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    financial_account: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    data_connection: '',
    
    
    
    
    
    
    
    
    
    posted_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    effective_at: '',
    
    
    
    
    
    
    
    
    
    
    amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    currency: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    description: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    merchant_name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    direction: 'inflow',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    category: 'revenue',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    classification_status: 'unreviewed',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    vendor: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    customer: '',
    
    
    
    
    external_reference: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    is_recurring_candidate: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


const 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('/transactions/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,
                    posted_at: moment(dateRangeStart).format('YYYY-MM-DDTHH:mm'),
                    effective_at: moment(dateRangeEnd).format('YYYY-MM-DDTHH:mm'),
                } : initialValues
                
            }
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>





















  <FormField label="Workspace" labelFor="workspace">
      <Field name="workspace" id="workspace" component={SelectField} options={[]} itemRef={'workspaces'}></Field>
  </FormField>



























  <FormField label="FinancialAccount" labelFor="financial_account">
      <Field name="financial_account" id="financial_account" component={SelectField} options={[]} itemRef={'financial_accounts'}></Field>
  </FormField>



























  <FormField label="DataConnection" labelFor="data_connection">
      <Field name="data_connection" id="data_connection" component={SelectField} options={[]} itemRef={'data_connections'}></Field>
  </FormField>



















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



























  <FormField
      label="EffectiveAt"
  >
      <Field
          type="datetime-local"
          name="effective_at"
          placeholder="EffectiveAt"
      />
  </FormField>























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





















  <FormField
      label="Currency"
  >
      <Field
          name="currency"
          placeholder="Currency"
      />
  </FormField>





























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

























  <FormField
      label="MerchantName"
  >
      <Field
          name="merchant_name"
          placeholder="MerchantName"
      />
  </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="Category" labelFor="category">
      <Field name="category" id="category" component="select">
      
        <option value="revenue">revenue</option>
      
        <option value="cogs">cogs</option>
      
        <option value="payroll">payroll</option>
      
        <option value="rent">rent</option>
      
        <option value="software">software</option>
      
        <option value="marketing">marketing</option>
      
        <option value="travel">travel</option>
      
        <option value="tax">tax</option>
      
        <option value="interest">interest</option>
      
        <option value="other_expense">other_expense</option>
      
        <option value="other_income">other_income</option>
      
      </Field>
  </FormField>



























  <FormField label="ClassificationStatus" labelFor="classification_status">
      <Field name="classification_status" id="classification_status" component="select">
      
        <option value="unreviewed">unreviewed</option>
      
        <option value="auto_classified">auto_classified</option>
      
        <option value="confirmed">confirmed</option>
      
        <option value="needs_attention">needs_attention</option>
      
      </Field>
  </FormField>































  <FormField label="Vendor" labelFor="vendor">
      <Field name="vendor" id="vendor" component={SelectField} options={[]} itemRef={'vendors'}></Field>
  </FormField>



























  <FormField label="Customer" labelFor="customer">
      <Field name="customer" id="customer" component={SelectField} options={[]} itemRef={'customers'}></Field>
  </FormField>









  <FormField
      label="ExternalReference"
  >
      <Field
          name="external_reference"
          placeholder="ExternalReference"
      />
  </FormField>











































  <FormField label='IsRecurringCandidate' labelFor='is_recurring_candidate'>
      <Field
          name='is_recurring_candidate'
          id='is_recurring_candidate'
          component={SwitchField}
      ></Field>
  </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('/transactions/transactions-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default TransactionsNew
