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 = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    restaurant: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    client_user: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    table: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    order_channel: 'sur_place_qr',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    fulfillment_type: 'sur_place',
    
    
    
    
    
    
    
    
    delivery_address: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    delivery_latitude: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    delivery_longitude: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'brouillon',
    
    
    
    
    
    
    
    
    
    
    
    
    ordered_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    requested_for: '',
    
    
    
    
    
    
    
    
    
    
    
    customer_note: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    subtotal_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    total_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    is_paid: false,
    
    
    
    
    
    
    
    
}


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="Restaurant" labelFor="restaurant">
      <Field name="restaurant" id="restaurant" component={SelectField} options={[]} itemRef={'restaurants'}></Field>
  </FormField>



























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



























  <FormField label="Table" labelFor="table">
      <Field name="table" id="table" component={SelectField} options={[]} itemRef={'restaurant_tables'}></Field>
  </FormField>























  <FormField label="Canal" labelFor="order_channel">
      <Field name="order_channel" id="order_channel" component="select">
      
        <option value="sur_place_qr">sur_place_qr</option>
      
        <option value="a_distance">a_distance</option>
      
      </Field>
  </FormField>



























  <FormField label="Mode" labelFor="fulfillment_type">
      <Field name="fulfillment_type" id="fulfillment_type" component="select">
      
        <option value="sur_place">sur_place</option>
      
        <option value="emporter">emporter</option>
      
        <option value="livraison">livraison</option>
      
      </Field>
  </FormField>















    <FormField label="Adressedelivraison" hasTextareaHeight>
        <Field name="delivery_address" as="textarea" placeholder="Adressedelivraison" />
    </FormField>































    <FormField
        label="Latitudelivraison"
    >
        <Field
            type="number"
            name="delivery_latitude"
            placeholder="Latitudelivraison"
        />
    </FormField>



























    <FormField
        label="Longitudelivraison"
    >
        <Field
            type="number"
            name="delivery_longitude"
            placeholder="Longitudelivraison"
        />
    </FormField>



































  <FormField label="Statutcommande" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="brouillon">brouillon</option>
      
        <option value="validee">validee</option>
      
        <option value="en_preparation">en_preparation</option>
      
        <option value="prete">prete</option>
      
        <option value="servie">servie</option>
      
        <option value="annulee">annulee</option>
      
      </Field>
  </FormField>























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



























  <FormField
      label="Souhaitéepour"
  >
      <Field
          type="datetime-local"
          name="requested_for"
          placeholder="Souhaitéepour"
      />
  </FormField>



















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































    <FormField
        label="Sous-total"
    >
        <Field
            type="number"
            name="subtotal_amount"
            placeholder="Sous-total"
        />
    </FormField>



























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





































  <FormField label='Payée' labelFor='is_paid'>
      <Field
          name='is_paid'
          id='is_paid'
          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('/orders/orders-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default OrdersNew
