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 = {
    
    
    order_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    user: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    shipping_address: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'pending_payment',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    payment_status: 'unpaid',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    fulfillment_status: 'unfulfilled',
    
    
    
    
    
    
    
    subtotal_iqd: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    discount_total_iqd: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    shipping_total_iqd: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    grand_total_iqd: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    customer_note: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    placed_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    paid_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    applied_coupon: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    items: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    shipments: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    payments: [],
    
    
}


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="OrderNumber"
  >
      <Field
          name="order_number"
          placeholder="OrderNumber"
      />
  </FormField>













































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



























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























  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="pending_payment">pending_payment</option>
      
        <option value="confirmed">confirmed</option>
      
        <option value="processing">processing</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="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="partially_refunded">partially_refunded</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="partially_fulfilled">partially_fulfilled</option>
      
        <option value="fulfilled">fulfilled</option>
      
      </Field>
  </FormField>



















    <FormField
        label="Subtotal(IQD)"
    >
        <Field
            type="number"
            name="subtotal_iqd"
            placeholder="Subtotal(IQD)"
        />
    </FormField>



























    <FormField
        label="DiscountTotal(IQD)"
    >
        <Field
            type="number"
            name="discount_total_iqd"
            placeholder="DiscountTotal(IQD)"
        />
    </FormField>



























    <FormField
        label="ShippingTotal(IQD)"
    >
        <Field
            type="number"
            name="shipping_total_iqd"
            placeholder="ShippingTotal(IQD)"
        />
    </FormField>



























    <FormField
        label="GrandTotal(IQD)"
    >
        <Field
            type="number"
            name="grand_total_iqd"
            placeholder="GrandTotal(IQD)"
        />
    </FormField>























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



































  <FormField
      label="PlacedAt"
  >
      <Field
          type="datetime-local"
          name="placed_at"
          placeholder="PlacedAt"
      />
  </FormField>



























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



































  <FormField label="AppliedCoupon" labelFor="applied_coupon">
      <Field name="applied_coupon" id="applied_coupon" component={SelectField} options={[]} itemRef={'coupons'}></Field>
  </FormField>





























    <FormField label='Items' labelFor='items'>
        <Field
            name='items'
            id='items'
            itemRef={'order_items'}
            options={[]}
            component={SelectFieldMany}>
        </Field>
    </FormField>



























    <FormField label='Shipments' labelFor='shipments'>
        <Field
            name='shipments'
            id='shipments'
            itemRef={'shipments'}
            options={[]}
            component={SelectFieldMany}>
        </Field>
    </FormField>



























    <FormField label='Payments' labelFor='payments'>
        <Field
            name='payments'
            id='payments'
            itemRef={'payments'}
            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('/orders/orders-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default OrdersNew
