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

const initialValues = {
    
    
    receipt_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    store: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    register: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    cashier: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    customer: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    cash_drawer_session: '',
    
    
    
    
    
    
    
    
    
    sold_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'draft',
    
    
    
    
    
    
    
    subtotal: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    discount_total: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    vat_total: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    grand_total: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    amount_paid: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    change_given: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    receipt_delivery: 'print',
    
    
    
    
    
    
    
    customer_email: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


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

    
    

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













































  <FormField label="Store" labelFor="store">
      <Field name="store" id="store" component={SelectField} options={[]} itemRef={'stores'}></Field>
  </FormField>



























  <FormField label="Register" labelFor="register">
      <Field name="register" id="register" component={SelectField} options={[]} itemRef={'registers'}></Field>
  </FormField>



























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



























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



























  <FormField label="CashDrawerSession" labelFor="cash_drawer_session">
      <Field name="cash_drawer_session" id="cash_drawer_session" component={SelectField} options={[]} itemRef={'cash_drawer_sessions'}></Field>
  </FormField>



















  <FormField
      label="SoldAt"
  >
      <Field
          type="datetime-local"
          name="sold_at"
          placeholder="SoldAt"
      />
  </FormField>































  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="draft">draft</option>
      
        <option value="completed">completed</option>
      
        <option value="voided">voided</option>
      
        <option value="refunded">refunded</option>
      
        <option value="partially_refunded">partially_refunded</option>
      
      </Field>
  </FormField>



















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



























    <FormField
        label="DiscountTotal"
    >
        <Field
            type="number"
            name="discount_total"
            placeholder="DiscountTotal"
        />
    </FormField>



























    <FormField
        label="VATTotal"
    >
        <Field
            type="number"
            name="vat_total"
            placeholder="VATTotal"
        />
    </FormField>



























    <FormField
        label="GrandTotal"
    >
        <Field
            type="number"
            name="grand_total"
            placeholder="GrandTotal"
        />
    </FormField>



























    <FormField
        label="AmountPaid"
    >
        <Field
            type="number"
            name="amount_paid"
            placeholder="AmountPaid"
        />
    </FormField>



























    <FormField
        label="ChangeGiven"
    >
        <Field
            type="number"
            name="change_given"
            placeholder="ChangeGiven"
        />
    </FormField>



































  <FormField label="ReceiptDelivery" labelFor="receipt_delivery">
      <Field name="receipt_delivery" id="receipt_delivery" component="select">
      
        <option value="print">print</option>
      
        <option value="email">email</option>
      
        <option value="sms">sms</option>
      
        <option value="none">none</option>
      
      </Field>
  </FormField>













  <FormField
      label="CustomerEmail"
  >
      <Field
          name="customer_email"
          placeholder="CustomerEmail"
      />
  </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('/sales/sales-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default SalesNew
