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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    organization: '',
    
    
    
    
    invoice_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    customer: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    sales_order: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'draft',
    
    
    
    
    
    
    
    
    
    
    
    
    issue_date: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    due_date: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    paid_at: '',
    
    
    
    
    
    
    
    
    
    
    subtotal: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    tax_total: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    total: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    balance_due: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    billing_address: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    attachments: [],
    
    
    
    
    
    
    
    notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    invoice_lines: [],
    
    
}


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

    
    

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









  <FormField
      label="Invoicenumber"
  >
      <Field
          name="invoice_number"
          placeholder="Invoicenumber"
      />
  </FormField>













































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



























  <FormField label="Salesorder" labelFor="sales_order">
      <Field name="sales_order" id="sales_order" component={SelectField} options={[]} itemRef={'sales_orders'}></Field>
  </FormField>























  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="draft">draft</option>
      
        <option value="issued">issued</option>
      
        <option value="partially_paid">partially_paid</option>
      
        <option value="paid">paid</option>
      
        <option value="voided">voided</option>
      
        <option value="overdue">overdue</option>
      
      </Field>
  </FormField>























  <FormField
      label="Issuedate"
  >
      <Field
          type="datetime-local"
          name="issue_date"
          placeholder="Issuedate"
      />
  </FormField>



























  <FormField
      label="Duedate"
  >
      <Field
          type="datetime-local"
          name="due_date"
          placeholder="Duedate"
      />
  </FormField>



























  <FormField
      label="Paidat"
  >
      <Field
          type="datetime-local"
          name="paid_at"
          placeholder="Paidat"
      />
  </FormField>























    <FormField
        label="Subtotal"
    >
        <Field
            type="number"
            name="subtotal"
            placeholder="Subtotal"
        />
    </FormField>



























    <FormField
        label="Taxtotal"
    >
        <Field
            type="number"
            name="tax_total"
            placeholder="Taxtotal"
        />
    </FormField>



























    <FormField
        label="Total"
    >
        <Field
            type="number"
            name="total"
            placeholder="Total"
        />
    </FormField>



























    <FormField
        label="Balancedue"
    >
        <Field
            type="number"
            name="balance_due"
            placeholder="Balancedue"
        />
    </FormField>







































  <FormField label="Billingaddress" labelFor="billing_address">
      <Field name="billing_address" id="billing_address" component={SelectField} options={[]} itemRef={'addresses'}></Field>
  </FormField>
































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






    <FormField label="Notes" hasTextareaHeight>
        <Field name="notes" as="textarea" placeholder="Notes" />
    </FormField>













































    <FormField label='Invoicelines' labelFor='invoice_lines'>
        <Field
            name='invoice_lines'
            id='invoice_lines'
            itemRef={'invoice_lines'}
            options={[]}
            component={SelectFieldMany}>
        </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('/invoices/invoices-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default InvoicesNew
