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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    tenant: '',
    
    
    
    
    order_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    order_channel: 'admin',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    order_status: 'draft',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    customer: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    seller_user: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    warehouse: '',
    
    
    
    
    subtotal_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    discount_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    shipping_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    tax_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    total_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    payment_status: 'unpaid',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    fulfillment_status: 'unfulfilled',
    
    
    
    
    
    
    
    shipping_courier: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    shipping_service: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    tracking_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    ordered_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    paid_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    shipped_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    delivered_at: '',
    
    
    
    
    
    
    
    
    
    
    
    shipping_address: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    customer_note: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    internal_note: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


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

    
    

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









  <FormField
      label="OrderNumber"
  >
      <Field
          name="order_number"
          placeholder="OrderNumber"
      />
  </FormField>









































  <FormField label="OrderChannel" labelFor="order_channel">
      <Field name="order_channel" id="order_channel" component="select">
      
        <option value="admin">admin</option>
      
        <option value="reseller_storefront">reseller_storefront</option>
      
        <option value="affiliate_link">affiliate_link</option>
      
        <option value="manual_import">manual_import</option>
      
        <option value="api">api</option>
      
      </Field>
  </FormField>



























  <FormField label="OrderStatus" labelFor="order_status">
      <Field name="order_status" id="order_status" component="select">
      
        <option value="draft">draft</option>
      
        <option value="pending_payment">pending_payment</option>
      
        <option value="paid">paid</option>
      
        <option value="processing">processing</option>
      
        <option value="packed">packed</option>
      
        <option value="shipped">shipped</option>
      
        <option value="delivered">delivered</option>
      
        <option value="cancelled">cancelled</option>
      
        <option value="refunded">refunded</option>
      
      </Field>
  </FormField>































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



























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



























  <FormField label="Warehouse" labelFor="warehouse">
      <Field name="warehouse" id="warehouse" component={SelectField} options={[]} itemRef={'warehouses'}></Field>
  </FormField>















    <FormField
        label="SubtotalAmount"
    >
        <Field
            type="number"
            name="subtotal_amount"
            placeholder="SubtotalAmount"
        />
    </FormField>



























    <FormField
        label="DiscountAmount"
    >
        <Field
            type="number"
            name="discount_amount"
            placeholder="DiscountAmount"
        />
    </FormField>



























    <FormField
        label="ShippingAmount"
    >
        <Field
            type="number"
            name="shipping_amount"
            placeholder="ShippingAmount"
        />
    </FormField>



























    <FormField
        label="TaxAmount"
    >
        <Field
            type="number"
            name="tax_amount"
            placeholder="TaxAmount"
        />
    </FormField>



























    <FormField
        label="TotalAmount"
    >
        <Field
            type="number"
            name="total_amount"
            placeholder="TotalAmount"
        />
    </FormField>



































  <FormField label="PaymentStatus" labelFor="payment_status">
      <Field name="payment_status" id="payment_status" component="select">
      
        <option value="unpaid">unpaid</option>
      
        <option value="paid">paid</option>
      
        <option value="partial">partial</option>
      
        <option value="refunded">refunded</option>
      
      </Field>
  </FormField>



























  <FormField label="FulfillmentStatus" labelFor="fulfillment_status">
      <Field name="fulfillment_status" id="fulfillment_status" component="select">
      
        <option value="unfulfilled">unfulfilled</option>
      
        <option value="partial">partial</option>
      
        <option value="fulfilled">fulfilled</option>
      
        <option value="returned">returned</option>
      
      </Field>
  </FormField>













  <FormField
      label="ShippingCourier"
  >
      <Field
          name="shipping_courier"
          placeholder="ShippingCourier"
      />
  </FormField>



























  <FormField
      label="ShippingService"
  >
      <Field
          name="shipping_service"
          placeholder="ShippingService"
      />
  </FormField>



























  <FormField
      label="TrackingNumber"
  >
      <Field
          name="tracking_number"
          placeholder="TrackingNumber"
      />
  </FormField>





































  <FormField
      label="OrderedAt"
  >
      <Field
          type="datetime-local"
          name="ordered_at"
          placeholder="OrderedAt"
      />
  </FormField>



























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



























  <FormField
      label="ShippedAt"
  >
      <Field
          type="datetime-local"
          name="shipped_at"
          placeholder="ShippedAt"
      />
  </FormField>



























  <FormField
      label="DeliveredAt"
  >
      <Field
          type="datetime-local"
          name="delivered_at"
          placeholder="DeliveredAt"
      />
  </FormField>



















    <FormField label="ShippingAddress" hasTextareaHeight>
        <Field name="shipping_address" as="textarea" placeholder="ShippingAddress" />
    </FormField>



























    <FormField label="CustomerNote" hasTextareaHeight>
        <Field name="customer_note" as="textarea" placeholder="CustomerNote" />
    </FormField>



























    <FormField label="InternalNote" hasTextareaHeight>
        <Field name="internal_note" as="textarea" placeholder="InternalNote" />
    </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('/orders/orders-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default OrdersNew
