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

const initialValues = {
    
    
    account_name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    account_type: 'restaurant',
    
    
    
    
    
    
    
    account_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    tax_exempt_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    is_tax_exempt: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    credit_status: 'good',
    
    
    
    
    
    
    
    credit_limit: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    default_price_list: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    assigned_sales_rep: '',
    
    
    
    
    
    notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    is_active: false,
    
    
    
    
    
    
    
    
}


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

    
    

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/accounts/accounts-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="Accountname"
  >
      <Field
          name="account_name"
          placeholder="Accountname"
      />
  </FormField>









































  <FormField label="Accounttype" labelFor="account_type">
      <Field name="account_type" id="account_type" component="select">
      
        <option value="restaurant">restaurant</option>
      
        <option value="caterer">caterer</option>
      
        <option value="hotel">hotel</option>
      
        <option value="corporate">corporate</option>
      
        <option value="other">other</option>
      
      </Field>
  </FormField>













  <FormField
      label="Accountnumber"
  >
      <Field
          name="account_number"
          placeholder="Accountnumber"
      />
  </FormField>



























  <FormField
      label="Taxexemptnumber"
  >
      <Field
          name="tax_exempt_number"
          placeholder="Taxexemptnumber"
      />
  </FormField>











































  <FormField label='Taxexempt' labelFor='is_tax_exempt'>
      <Field
          name='is_tax_exempt'
          id='is_tax_exempt'
          component={SwitchField}
      ></Field>
  </FormField>

























  <FormField label="Creditstatus" labelFor="credit_status">
      <Field name="credit_status" id="credit_status" component="select">
      
        <option value="good">good</option>
      
        <option value="hold">hold</option>
      
        <option value="delinquent">delinquent</option>
      
      </Field>
  </FormField>



















    <FormField
        label="Creditlimit"
    >
        <Field
            type="number"
            name="credit_limit"
            placeholder="Creditlimit"
        />
    </FormField>







































  <FormField label="Defaultpricelist" labelFor="default_price_list">
      <Field name="default_price_list" id="default_price_list" component={SelectField} options={[]} itemRef={'price_lists'}></Field>
  </FormField>



























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











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









































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

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

export default AccountsNew
